Ejemplo n.º 1
0
static void ICACHE_FLASH_ATTR flowTimerCb(void) { // 1 second

	if (flowOverridden) {
		ETS_GPIO_INTR_DISABLE();
		flowCount = 0;
		ETS_GPIO_INTR_ENABLE();
	} else {
		ETS_GPIO_INTR_DISABLE();
		oneSecFlowCount = flowCount;
		flowCount = 0;
		ETS_GPIO_INTR_ENABLE();
	}

	flowSetAverage(oneSecFlowCount);
	if (flowAverage == 0) { // Use average to deal with any timing issues when demand oscillates
		INFOP("!");
		secondsNotFlowingCount++;
	} else {
		INFOP(">");
		secondsNotFlowingCount = 0;
	}
	flowCountPerReading += oneSecFlowCount;
	if (oneSecFlowCount < flowMin) {
		flowMin = oneSecFlowCount;
	}
	if (oneSecFlowCount > flowMax) {
		flowMax = oneSecFlowCount;
	}
	calcFlows();
}
Ejemplo n.º 2
0
/******************************************************************************
 * FunctionName : i2c_master_gpio_init
 * Description  : config SDA and SCL gpio to open-drain output mode,
 *                mux and gpio num defined in i2c_master.h
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_gpio_init(uint8 scl, uint8 sda, uint32 bitrate)
{
    pinSCL = scl;
    pinSDA = sda;

#if 0
    ETS_GPIO_INTR_DISABLE();
//    ETS_INTR_LOCK();

    // Assume the pin mux is set before calling this function
    //PIN_FUNC_SELECT(I2C_MASTER_SDA_MUX, I2C_MASTER_SDA_FUNC);
    //PIN_FUNC_SELECT(I2C_MASTER_SCL_MUX, I2C_MASTER_SCL_FUNC);

    GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(sda)),
        GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(sda))) |
        GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
    GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS,
        GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << sda));

    GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(scl)),
        GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(scl))) |
        GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
    GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS,
        GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << scl));

    I2C_MASTER_SDA_SCL(1, 1);

    ETS_GPIO_INTR_ENABLE() ;
//    ETS_INTR_UNLOCK();
#endif

    I2C_MASTER_SDA_SCL(1, 1);
    i2c_master_init();
}
Ejemplo n.º 3
0
static void spi(uint8 c) {
	uint8 mask = 0x80;
	ETS_GPIO_INTR_DISABLE();
	while (mask != 0) {
		if (mask & c) {
//			stdoutPutchar('1');
//			easygpio_outputSet(LCD_Data, 1);
			GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, (1 << LCD_Data));
		} else {
//			stdoutPutchar('0');
//			easygpio_outputSet(LCD_Data, 0);
			GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, (1 << LCD_Data));
		}
		mask >>= 1;
		asm volatile (
			"NOP;NOP;NOP;NOP;NOP;"
		);
		GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, (1 << LCD_clk));
		asm volatile (
			"NOP;NOP;NOP;NOP;NOP;"
			"NOP;NOP;NOP;NOP;NOP;"
		);
		GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, (1 << LCD_clk));
	}
	ETS_GPIO_INTR_ENABLE();
//	stdoutPutchar(' ');
}
Ejemplo n.º 4
0
// initialization
void IRrecv::enableIRIn() {
	
  // initialize state machine variables
  irparams.rcvstate = STATE_IDLE;
  irparams.rawlen = 0;

  // set pin modes  
  //PIN_FUNC_SELECT(IR_IN_MUX, IR_IN_FUNC);
  GPIO_DIS_OUTPUT(irparams.recvpin);
  
  // Initialize timer
  os_timer_disarm(&timer);
  os_timer_setfn(&timer, (os_timer_func_t *)read_timeout, &timer);
  
  // ESP Attach Interrupt
  ETS_GPIO_INTR_DISABLE();
  ETS_GPIO_INTR_ATTACH(gpio_intr, NULL);
  gpio_pin_intr_state_set(GPIO_ID_PIN(irparams.recvpin), GPIO_PIN_INTR_ANYEDGE);
  ETS_GPIO_INTR_ENABLE();
  //ETS_INTR_UNLOCK();  
  
  //attachInterrupt(irparams.recvpin, readIR, CHANGE);  
  //irReadTimer.initializeUs(USECPERTICK, readIR).start();
  //os_timer_arm_us(&irReadTimer, USECPERTICK, 1);
  //ets_timer_arm_new(&irReadTimer, USECPERTICK, 1, 0);
}
Ejemplo n.º 5
0
/******************************************************************************
 * FunctionName : key_init
 * Description  : init keys
 * Parameters   : key_param *keys - keys parameter, which inited by key_init_single
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
key_init(struct keys_param *keys)
{
    uint8 i;
    os_printf("-%s-%s \r\n", __FILE__, __func__);

    ETS_GPIO_INTR_ATTACH(key_intr_handler, keys);

    ETS_GPIO_INTR_DISABLE();

    for (i = 0; i < keys->key_num; i++) {
        keys->single_key[i]->key_level = 1;

        PIN_FUNC_SELECT(keys->single_key[i]->gpio_name, keys->single_key[i]->gpio_func);

        gpio_output_set(0, 0, 0, GPIO_ID_PIN(keys->single_key[i]->gpio_id));

        gpio_register_set(GPIO_PIN_ADDR(keys->single_key[i]->gpio_id), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
                          | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
                          | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));

        //clear gpio14 status
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(keys->single_key[i]->gpio_id));

        //enable interrupt
        gpio_pin_intr_state_set(GPIO_ID_PIN(keys->single_key[i]->gpio_id), GPIO_PIN_INTR_ANYEGDE);
    }

    ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 6
0
/**
 * Sets the 'gpio_pin' pin as a GPIO and sets the interrupt to trigger on that pin.
 * The 'interruptArg' is the function argument that will be sent to your interruptHandler
 */
bool ICACHE_FLASH_ATTR
easygpio_attachInterrupt(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, void (*interruptHandler)(void *arg), void *interruptArg) {
  uint32_t gpio_name;
  uint8_t gpio_func;

  if (gpio_pin == 16) {
    os_printf("easygpio_setupInterrupt Error: GPIO16 does not have interrupts\n");
    return false;
  }
  if (!easygpio_getGPIONameFunc(gpio_pin, &gpio_name, &gpio_func) ) {
    return false;
  }

  ETS_GPIO_INTR_ATTACH(interruptHandler, interruptArg);
  ETS_GPIO_INTR_DISABLE();

  PIN_FUNC_SELECT(gpio_name, gpio_func);

  easygpio_setupPullsByName(gpio_name, pullStatus);

  // disable output
  GPIO_DIS_OUTPUT(gpio_pin);

  gpio_register_set(GPIO_PIN_ADDR(gpio_pin), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
                    | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
                    | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));

  //clear gpio14 status
  GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(gpio_pin));
  ETS_GPIO_INTR_ENABLE();

  return true;
}
Ejemplo n.º 7
0
Archivo: key.c Proyecto: lvjh/ESP8266
/******************************************************************************
 * FunctionName : key_init
 * Description  : init keys
 * Parameters   : key_param *keys - keys parameter, which inited by key_init_single
 * Returns	  : none
*******************************************************************************/
void ICACHE_FLASH_ATTR key_init() {
    uint8 i;

    ETS_GPIO_INTR_ATTACH(key_intr_handler, &key_parameters);

    ETS_GPIO_INTR_DISABLE();

    for (i = 0; i < key_parameters.key_num; i++) {
        key_parameters.single_key[i]->key_level = 1;
        key_parameters.single_key[i]->is_long = 0;

        PIN_FUNC_SELECT(key_parameters.single_key[i]->gpio_name, key_parameters.single_key[i]->gpio_func);

        // Set GPIO as input
        gpio_output_set(0, 0, 0, GPIO_ID_PIN(key_parameters.single_key[i]->gpio_id));

        gpio_register_set(
            GPIO_PIN_ADDR(key_parameters.single_key[i]->gpio_id),
            GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) |
            GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) |
            GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)
        );

        //clear gpio14 status
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(key_parameters.single_key[i]->gpio_id));

        //enable interrupt
        gpio_pin_intr_state_set(GPIO_ID_PIN(key_parameters.single_key[i]->gpio_id), GPIO_PIN_INTR_NEGEDGE);
    }

    ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 8
0
/**
 * I2C init function
 * This sets up the GPIO io
 */
void ICACHE_FLASH_ATTR
i2c_init(void)
{
    //Disable interrupts
    ETS_GPIO_INTR_DISABLE();

    //Set pin functions
    PIN_FUNC_SELECT(I2C_SDA_MUX, I2C_SDA_FUNC);
    PIN_FUNC_SELECT(I2C_SCK_MUX, I2C_SCK_FUNC);

    //Set SDA as open drain
    GPIO_REG_WRITE(
        GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SDA_PIN)), 
        GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SDA_PIN))) | 
        GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)
    );

    GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_SDA_PIN));

    //Set SCK as open drain
    GPIO_REG_WRITE(
        GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SCK_PIN)), 
        GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_SCK_PIN))) | 
        GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)
    );

    GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_SCK_PIN));

    //Turn interrupt back on
    ETS_GPIO_INTR_ENABLE();

    i2c_sda(1);
    i2c_sck(1);
    return;
}
Ejemplo n.º 9
0
/******************************************************************************
 * FunctionName : i2c_master_gpio_init
 * Description  : config SDA and SCL gpio to open-drain output mode,
 *				mux and gpio num defined in i2c_master.h
 * Parameters   : uint8 sda and scl pin numbers
 * Returns	  : bool, true if init okay
*******************************************************************************/
bool i2c_master_gpio_init(uint8 sda, uint8 scl)
{
	if((sda > GPIO_PIN_NUM) || (pin_func[sda] == GPIO_PIN_FUNC_INVALID)){
		return false;
	}

	if((scl > GPIO_PIN_NUM) || (pin_func[scl] == GPIO_PIN_FUNC_INVALID)){
		return false;
	}

	pinSDA = sda;
	pinSCL = scl;

	ETS_GPIO_INTR_DISABLE() ;
//	ETS_INTR_LOCK();

	PIN_FUNC_SELECT(pin_mux[sda], pin_func[sda]);
	PIN_FUNC_SELECT(pin_mux[scl], pin_func[scl]);

	GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(sda)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(sda))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
	GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << sda));
	GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(scl)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(scl))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
	GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << scl));

	i2c_master_setDC(1, 1);

	ETS_GPIO_INTR_ENABLE() ;
//	ETS_INTR_UNLOCK();

	i2c_master_init();
	return true;
}
Ejemplo n.º 10
0
/*
 * Set GPIO mode to output. Optionally in RAM helper because interrupts are dsabled
 */
static void NO_INTR_CODE set_gpio_no_interrupt(uint8 pin, uint8_t push_pull) {
  unsigned pnum = pin_num[pin];
  ETS_GPIO_INTR_DISABLE();
#ifdef GPIO_INTERRUPT_ENABLE
  pin_int_type[pin] = GPIO_PIN_INTR_DISABLE;
#endif
  PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]);
  //disable interrupt
  gpio_pin_intr_state_set(GPIO_ID_PIN(pnum), GPIO_PIN_INTR_DISABLE);
  //clear interrupt status
  GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pnum));

  // configure push-pull vs open-drain
  if (push_pull) {
    GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pnum)),
                   GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pnum))) &
                   (~ GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)));  //disable open drain;
  } else {
    GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pnum)),
                   GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pnum))) |
                   GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE));      //enable open drain;
  }

  ETS_GPIO_INTR_ENABLE();
}
void ICACHE_FLASH_ATTR
button_press() {
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts

	// Button interrupt received
	INFO("BUTTON: Button pressed\r\n");

	// Button pressed, flip switch
	if (GPIO_REG_READ(BUTTON_GPIO) & BIT2) {
		INFO("BUTTON: Switch off\r\n");
		GPIO_OUTPUT_SET(SWITCH03_GPIO, 0);
	} else  {
		INFO("BUTTON: Switch on\r\n");
		GPIO_OUTPUT_SET(SWITCH03_GPIO, 1);
	}

	// Send new status to the MQTT broker
	char *json_buf = NULL;
	json_buf = (char *)os_zalloc(jsonSize);
	json_ws_send((struct jsontree_value *)&device_tree, "device", json_buf);
	INFO("BUTTON: Sending current switch status\r\n");
	MQTT_Publish(&mqttClient, config.mqtt_topic_s01, json_buf, strlen(json_buf), 0, 0);
	os_free(json_buf);
	json_buf = NULL;

	// Debounce
	os_delay_us(200000);

	// Clear interrupt status
	uint32 gpio_status;
	gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);

	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
}
Ejemplo n.º 12
0
void  supla_esp_gpio_init_led(void) {

	ETS_GPIO_INTR_DISABLE();

	#ifdef LED_RED_PORT
		#if LED_RED_PORT != 16
			GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(LED_RED_PORT));
			gpio_pin_intr_state_set(GPIO_ID_PIN(LED_RED_PORT), GPIO_PIN_INTR_DISABLE);
			gpio_output_set(0, GPIO_ID_PIN(LED_RED_PORT), GPIO_ID_PIN(LED_RED_PORT), 0);
		#endif
	#endif

	#ifdef LED_GREEN_PORT
		GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(LED_GREEN_PORT));
		gpio_pin_intr_state_set(GPIO_ID_PIN(LED_GREEN_PORT), GPIO_PIN_INTR_DISABLE);
		gpio_output_set(0, GPIO_ID_PIN(LED_GREEN_PORT), GPIO_ID_PIN(LED_GREEN_PORT), 0);
	#endif

	#ifdef LED_BLUE_PORT
		GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(LED_BLUE_PORT));
		gpio_pin_intr_state_set(GPIO_ID_PIN(LED_BLUE_PORT), GPIO_PIN_INTR_DISABLE);
		gpio_output_set(0, GPIO_ID_PIN(LED_BLUE_PORT), GPIO_ID_PIN(LED_BLUE_PORT), 0);
	#endif

    ETS_GPIO_INTR_ENABLE();

}
Ejemplo n.º 13
0
void ICACHE_FLASH_ATTR user_init()
{
    // Initialize the GPIO subsystem.
    //UART_init(BIT_RATE_115200, BIT_RATE_115200, 0);
    //UART_SetPrintPort(UART0);
    stdout_init();

    i2c_master_gpio_init();

    user_set_station_config();

    pcf8754_i2c_write_byte(I2C_INPUT_ADDRESS, 0);
    // =================================================
    // Initialize GPIO2 and GPIO0 as GPIO
    // =================================================
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);
    PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0RXD_U);

    gpio_output_set(0, 0, 0, GPIO_ID_PIN(3)); // set set gpio 0 as input

    ETS_GPIO_INTR_DISABLE();
    // Attach interrupt handle to gpio interrupts.
    ETS_GPIO_INTR_ATTACH(gpio_intr_handler, NULL);
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(3)); // clear gpio status
    gpio_pin_intr_state_set(GPIO_ID_PIN(3), GPIO_PIN_INTR_ANYEDGE); // clear gpio status.
    ETS_GPIO_INTR_ENABLE(); // Enable interrupts by GPIO


	// register a callback function to let user code know that system
	// initialization is complete
	system_init_done_cb(&post_user_init_func);

    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
Ejemplo n.º 14
0
static void NO_INTR_CODE set_gpio_interrupt(uint8 pin) {
  ETS_GPIO_INTR_DISABLE();
  PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]);
  GPIO_DIS_OUTPUT(pin_num[pin]);
  gpio_register_set(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])),
                    GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
                    | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
                    | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));
  ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 15
0
/******************************************************************************
 * FunctionName : user_plug_set_status
 * Description  : set plug's status, 0x00 or 0x01
 * Parameters   : uint8 - status
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_plug_set_status(bool status)
{
//    if (status != plug_param.status) {
//        if (status > 1) {
//            os_printf("error status input!\n");
//            return;
//        }
//
//        plug_param.status = status;
//        PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, status);
//    }
    if (status != plug_param.status) {
        if (status > 1) {
            os_printf("error status input!\n");
            return;
        }

        plug_param.status = status;
        //PLUG_STATUS_OUTPUT(PLUG_RELAY_LED_IO_NUM, status);

		ETS_GPIO_INTR_DISABLE();
		PIN_FUNC_SELECT(pin_mux[pin], pin_func[pin]);
		GPIO_DIS_OUTPUT(pin_num[pin]);
		gpio_register_set(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[pin])), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
                    | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
                    | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));
		ETS_GPIO_INTR_ENABLE();

		//disable global interrupt
		ETS_GPIO_INTR_DISABLE();
		//clear interrupt status
		GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin]));
		pin_int_type[pin] = type;
		//enable interrupt
		gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), type);
		//enable global interrupt
		ETS_GPIO_INTR_ENABLE();

		ETS_GPIO_INTR_ATTACH(func, arg)
    }
}
void ICACHE_FLASH_ATTR
gpio_init() {
	// Configure switch (relays)
	INFO("Configure Switch 1 %d\n", SWITCH01_GPIO );
	PIN_FUNC_SELECT(SWITCH01_GPIO_MUX, SWITCH01_GPIO_FUNC);
	set_switch(SWITCH01_GPIO, 0);
	//GPIO_OUTPUT_SET(SWITCH01_GPIO, 0);

	INFO("Configure Switch 2 %d\n", SWITCH02_GPIO );
	PIN_FUNC_SELECT(SWITCH02_GPIO_MUX, SWITCH02_GPIO_FUNC);
	set_switch(SWITCH02_GPIO, 0);
	//GPIO_OUTPUT_SET(SWITCH02_GPIO, 0);

	INFO("Configure Switch 3 %d\n", SWITCH03_GPIO );
	PIN_FUNC_SELECT(SWITCH03_GPIO_MUX, SWITCH03_GPIO_FUNC);
	set_switch(SWITCH03_GPIO, 0);
	//GPIO_OUTPUT_SET(SWITCH03_GPIO, 0);

	//Configure Toggle switches
	INFO("Configure Toggle 1 %d\n", TOGGLE01_GPIO );
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	ETS_GPIO_INTR_ATTACH(toggle_changed, 0);  // GPIO interrupt handler
	PIN_FUNC_SELECT(TOGGLE01_GPIO_MUX, TOGGLE01_GPIO_FUNC); // Set function
	GPIO_DIS_OUTPUT(TOGGLE01_GPIO); // Set as input
	gpio_pin_intr_state_set(GPIO_ID_PIN(TOGGLE01_GPIO), GPIO_PIN_INTR_ANYEDGE); // Interrupt on any edge
	//ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts

	INFO("Configure Toggle 2 %d\n", TOGGLE02_GPIO );
	//ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	//ETS_GPIO_INTR_ATTACH(toggle_changed);  // GPIO interrupt handler
	PIN_FUNC_SELECT(TOGGLE02_GPIO_MUX, TOGGLE02_GPIO_FUNC); // Set function
	GPIO_DIS_OUTPUT(TOGGLE02_GPIO); // Set as input
	gpio_pin_intr_state_set(GPIO_ID_PIN(TOGGLE02_GPIO), GPIO_PIN_INTR_ANYEDGE); // Interrupt on any edge
	//ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts


	INFO("Configure Toggle 3 %d\n", TOGGLE03_GPIO );
	//ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	//ETS_GPIO_INTR_ATTACH(toggle_changed);  // GPIO interrupt handler
	PIN_FUNC_SELECT(TOGGLE03_GPIO_MUX, TOGGLE03_GPIO_FUNC); // Set function
	GPIO_DIS_OUTPUT(TOGGLE03_GPIO); // Set as input
	gpio_pin_intr_state_set(GPIO_ID_PIN(TOGGLE03_GPIO), GPIO_PIN_INTR_ANYEDGE); // Interrupt on any edge
	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts


	// Configure push button
//	INFO("Confgiure push button %d\n", BUTTON_GPIO );
//	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
//	ETS_GPIO_INTR_ATTACH(button_press, BUTTON_GPIO);  // GPIO0 interrupt handler
//	PIN_FUNC_SELECT(BUTTON_GPIO_MUX, BUTTON_GPIO_FUNC); // Set function
//	GPIO_DIS_OUTPUT(BUTTON_GPIO); // Set as input
//	gpio_pin_intr_state_set(GPIO_ID_PIN(BUTTON_GPIO), 2); // Interrupt on negative edge
//	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
}
Ejemplo n.º 17
0
void pin_init0(void) {
    ETS_GPIO_INTR_DISABLE();
    ETS_GPIO_INTR_ATTACH(pin_intr_handler_iram, NULL);
    // disable all interrupts
    memset(&MP_STATE_PORT(pin_irq_handler)[0], 0, 16 * sizeof(mp_obj_t));
    for (int p = 0; p < 16; ++p) {
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << p);
        SET_TRIGGER(p, 0);
    }
    ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 18
0
// Decodes the received IR message
// Returns 0 if no data ready, 1 if data ready.
// Results of decoding are stored in results
bool IRrecv::decode(decode_results *results) {
  if(false==irparams.isValueReady)return false;
  ETS_GPIO_INTR_DISABLE();
  irparams.isValueReady=false;
  results->bits = NEC_BITS;
  results->value = irparams.Value;
  results->decode_type = NEC;

  ETS_GPIO_INTR_ENABLE();

  return true;
}
Ejemplo n.º 19
0
/*
 * Initialise GPIO interrupt mode. Optionally in RAM because interrupts are disabled
 */
void NO_INTR_CODE platform_gpio_intr_init( unsigned pin, GPIO_INT_TYPE type )
{
  if (platform_gpio_exists(pin)) {
    ETS_GPIO_INTR_DISABLE();
    //clear interrupt status
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin]));
    pin_int_type[pin] = type;
    //enable interrupt
    gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), type);
    ETS_GPIO_INTR_ENABLE();
  }
}
Ejemplo n.º 20
0
int ICACHE_FLASH_ATTR gpio_intr_init(unsigned pin, GPIO_INT_TYPE type)
{
	if (pin >= GPIO_PIN_NUM)
		return -1;
	//disable global interrupt
	ETS_GPIO_INTR_DISABLE();
	//clear interrupt status
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(pin_num[pin]));
	pin_int_type[pin] = type;
	//enable interrupt
	gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[pin]), type);
	//enable global interrupt
	ETS_GPIO_INTR_ENABLE();
	return 1;
}
Ejemplo n.º 21
0
void ICACHE_FLASH_ATTR
buttons_init()
{
    //Attach the interrupt thing
    ETS_GPIO_INTR_ATTACH(rotary_intr_handler,12);

    //Disable interrupts
    ETS_GPIO_INTR_DISABLE();

    //Set GPIO to IO
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13);
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);

    //Set the GPIO to input
    gpio_output_set(0, 0, 0, GPIO_ID_PIN(12));
    gpio_output_set(0, 0, 0, GPIO_ID_PIN(13));
    gpio_output_set(0, 0, 0, GPIO_ID_PIN(0));

    //Not sure what this does
    gpio_register_set(GPIO_PIN_ADDR(12), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
          | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
          | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));

    gpio_register_set(GPIO_PIN_ADDR(13), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
          | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
          | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));

    gpio_register_set(GPIO_PIN_ADDR(0), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)
          | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)
          | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));

    //clear gpio status
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(12));
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13));
    GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(0));

    //re-enable gpio0 interrupt
    gpio_pin_intr_state_set(GPIO_ID_PIN(12), GPIO_PIN_INTR_ANYEDGE);

    //Global re-enable interrupts
    ETS_GPIO_INTR_ENABLE();

    os_timer_disarm(&button_timer);
    os_timer_setfn(&button_timer, (os_timer_func_t *)button_push, 1);
    os_timer_arm(&button_timer, 50, 1);
}
Ejemplo n.º 22
0
void interrupt_test(){
	// disable interrupts
	ETS_GPIO_INTR_DISABLE();

	uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);

	// publish that button has been pressed
	INFO("Button pressed!!");

	pb1Transmit();

	//gpio_pin_intr_state_set(GPIO_ID_PIN(4), GPIO_PIN_INTR_POSEDGE);

	// enable interrupts
	ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 23
0
void user_init(void)
{
	uart_init(BIT_RATE_230400, BIT_RATE_230400);
	system_set_os_print(1); // enable/disable operating system printout

	os_sprintf(topic_temp, MQTT_TOPICTEMP, system_get_chip_id());
	os_sprintf(topic_hum, MQTT_TOPICHUM, system_get_chip_id());

	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13);


	   ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	   ETS_GPIO_INTR_ATTACH(interrupt_test, 4);
	   PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
	   gpio_output_set(0, 0, 0, GPIO_ID_PIN(4)); // Set GPIO12 as input
	   GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(4));
	   gpio_pin_intr_state_set(GPIO_ID_PIN(4), GPIO_PIN_INTR_ANYEDGE);
	   ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts

	config_load();

	DHTInit(DHT11);

	MQTT_InitConnection(&mqttClient, config.mqtt_host, config.mqtt_port, config.security);
	MQTT_InitClient(&mqttClient, config.device_id, config.mqtt_user, config.mqtt_pass, config.mqtt_keepalive, 1);
	MQTT_InitLWT(&mqttClient, "lwt/", "offline", 0, 0);
	MQTT_OnConnected(&mqttClient, mqtt_connected_cb);
	MQTT_OnDisconnected(&mqttClient, mqtt_disconnected_cb);
	MQTT_OnPublished(&mqttClient, mqtt_published_cb);
	MQTT_OnData(&mqttClient, mqtt_data_cb);

	WIFI_Connect(config.sta_ssid, config.sta_pwd, wifi_connect_cb);

	os_timer_disarm(&dhtTimer);
	os_timer_setfn(&dhtTimer, (os_timer_func_t *)dhtCb, (void *)0);
	os_timer_arm(&dhtTimer, DELAY, 1);

	os_timer_disarm(&hbTimer);
	os_timer_setfn(&hbTimer, (os_timer_func_t *)application_heartbeat, (void *)0);
	os_timer_arm(&hbTimer, 60000, 1);



	INFO("\r\nSystem started ...\r\n");
}
void ICACHE_RAM_ATTR SoftwareSerial::handle_interrupt(void *arg) {
   uint32_t gpioStatus = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
   // Clear the interrupt(s) otherwise we get called again
   GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpioStatus);
   ETS_GPIO_INTR_DISABLE();
   uint8_t pin = 0;
   while (gpioStatus) {
      while(!(gpioStatus & (1 << pin))) pin++;
      gpioStatus &= ~(1 << pin);
      if (InterruptList[pin]) {
         // For some reason there is always an interrupt directly after the
         // stop bit. Detect that by checking if we have a start bit
         if (digitalRead(pin) == InterruptList[pin]->m_invert)
            InterruptList[pin]->rxRead();
      }
   }
   ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 25
0
LOCAL void ICACHE_FLASH_ATTR read_input_pin(void *arg)
{
	uint32 gpio_status;
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	sleepms(15);
	if(!GPIO_INPUT_GET(PIN_GPIO13)) {
	button_counter++;
	console_printf("READ_INPUT_PIN executed...");
	console_printf("COUNTER:%d\n",button_counter);
	os_timer_disarm(&input_pin_timer); // Disarm input pin timer
	os_timer_setfn(&input_pin_timer, (os_timer_func_t *)handle_pin_press, NULL); // Setup input pin timer
	os_timer_arm(&input_pin_timer, button_timeout, 1); // Arm input pin timer, 0,5sec, repeat
	sleepms(button_debounce);  // debounce time
	}
	gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status); 	//clear interrupt status

	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts}
}
Ejemplo n.º 26
0
/******************************************************************************
 * FunctionName : i2c_master_gpio_init
 * Description  : config SDA and SCL gpio to open-drain output mode,
 *                mux and gpio num defined in i2c_master.h
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR i2c_master_gpio_init(void)
{
    ETS_GPIO_INTR_DISABLE() ;
//    ETS_INTR_LOCK();

    PIN_FUNC_SELECT(I2C_MASTER_SDA_MUX, I2C_MASTER_SDA_FUNC);
    PIN_FUNC_SELECT(I2C_MASTER_SCL_MUX, I2C_MASTER_SCL_FUNC);

    GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
    GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SDA_GPIO));
    GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
    GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SCL_GPIO));

    I2C_MASTER_SDA_HIGH_SCL_HIGH();

    ETS_GPIO_INTR_ENABLE() ;
//    ETS_INTR_UNLOCK();

    i2c_master_init();
}
Ejemplo n.º 27
0
void mp_hal_pin_config_od(mp_hal_pin_obj_t pin_id) {
    const pyb_pin_obj_t *pin = &pyb_pin_obj[pin_id];

    if (pin->phys_port == 16) {
        // configure GPIO16 as input with output register holding 0
        WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | 1);
        WRITE_PERI_REG(RTC_GPIO_CONF, READ_PERI_REG(RTC_GPIO_CONF) & ~1);
        WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & ~1)); // input
        WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & ~1)); // out=0
        return;
    }

    ETS_GPIO_INTR_DISABLE();
    PIN_FUNC_SELECT(pin->periph, pin->func);
    GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port)),
        GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port)))
        | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); // open drain
    GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS,
        GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << pin->phys_port));
    ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 28
0
/******************************************************************************
 * FunctionName : peri_key_init.
 * Description  : initialize key device.
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
peri_single_key_init(uint8 gpio_id,key_function long_press, key_function short_press)
{
    struct key_param *single_key = (struct key_param *)os_zalloc(sizeof(struct key_param));

    uint32 gpio_name=tisan_get_gpio_name(gpio_id);
    uint8 gpio_func=tisan_get_gpio_general_func(gpio_id);
    single_key->gpio_id = gpio_id;
    single_key->key_level = 1;
    single_key->long_press = long_press;
    single_key->short_press = short_press;

    ETS_GPIO_INTR_DISABLE();

    peri_vibrate_init_NULL();
    key_init(gpio_name, gpio_id, gpio_func);
    ETS_GPIO_INTR_ATTACH(gpio_intr_handler,single_key);


    ETS_GPIO_INTR_ENABLE();
}
Ejemplo n.º 29
0
/**
 * Initialize the ESP8266 hardware environment.
 *
 * TODO: we should move stuff from user_main.c here
 */
void jshInit() {
  // A call to jshInitDevices is architected as something we have to do.
  os_printf("> jshInit\n");

  // Initialize the ESP8266 GPIO subsystem.
  gpio_init();

  systemTimeInit();
  utilTimerInit();
  jshInitDevices();

  // sanity check for pin function enum to catch ordering changes
  if (JSHPINSTATE_I2C != 12 || JSHPINSTATE_GPIO_IN_PULLDOWN != 5 || JSHPINSTATE_MASK != 15) {
    jsError("JshPinState #defines have changed, please update pinStateToString()");
  }

  // Register a callback function to be called for a GPIO interrupt
  gpio_intr_handler_register(intrHandlerCB, NULL);

  ETS_GPIO_INTR_ENABLE();
  os_printf("< jshInit\n");
} // End of jshInit
Ejemplo n.º 30
0
void ICACHE_FLASH_ATTR gpio_intr_dispatcher(gpio_intr_handler cb)
{
	uint8 i, level;
	uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
	for (i = 0; i < GPIO_PIN_NUM; i++) {
		if (pin_int_type[i] && (gpio_status & BIT(pin_num[i])) ) {
			//disable global interrupt
			ETS_GPIO_INTR_DISABLE();
			//disable interrupt
			gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), GPIO_PIN_INTR_DISABLE);
			//clear interrupt status
			GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(pin_num[i]));
			level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[i]));
			if(cb){
				cb(i, level);
			}
			//enable interrupt
			gpio_pin_intr_state_set(GPIO_ID_PIN(pin_num[i]), pin_int_type[i]);
			//enable global interrupt
			ETS_GPIO_INTR_ENABLE();
		}
	}
}