Ejemplo n.º 1
0
// Perform the onewire reset function.  We will wait up to 250uS for
// the bus to come high, if it doesn't then it is broken or shorted
// and we return a 0;
// Returns 1 if a device asserted a presence pulse, 0 otherwise.
uint32 ICACHE_FLASH_ATTR onewire_reset() {
	uint32 result;
	uint8 retries = 125;

	// Disable output on the pin.
	GPIO_DIS_OUTPUT(ONEWIRE_PIN);

	// Wait for the bus to get high (which it should because of the pull-up resistor).
	do {
		if (--retries == 0) {
			return 0;
		}
		os_delay_us(2);
	} while (!GPIO_INPUT_GET(ONEWIRE_PIN));

	// Transmit the reset pulse by pulling the bus low for at least 480 us.
	GPIO_OUTPUT_SET(ONEWIRE_PIN, 0);
	os_delay_us(500);

	// Release the bus, and wait, then check for a presence pulse, which should start 15-60 us after the reset, and will last 60-240 us.
	// So 65us after the reset the bus must be high.
	GPIO_DIS_OUTPUT(ONEWIRE_PIN);
	os_delay_us(65);
	result = !GPIO_INPUT_GET(ONEWIRE_PIN);

	// After sending the reset pulse, the master (we) must wait at least another 480 us.
	os_delay_us(490);
	return result;
}
Ejemplo n.º 2
0
void restoreFactorySettings() {
	wifi_station_disconnect();
	wifi_set_opmode(0x3); //reset to STA+AP mode

	struct softap_config apConfig;
	wifi_softap_get_config(&apConfig);
	os_strncpy((char*)apConfig.ssid, "smartswitch", 18);
	apConfig.authmode = 0; //Disable security
	wifi_softap_set_config(&apConfig);

	struct station_config stconf;
	os_strncpy((char*)stconf.ssid, "", 2);
	os_strncpy((char*)stconf.password, "", 2);
	wifi_station_set_config(&stconf);

	OLED_CLS();
	OLED_Print(2, 0, "RESET", 1);
	os_printf("Reset completed. Restarting system...\n");

	ioOutput(0, GPIO_OUTPUT1);
	ioOutput(0, GPIO_OUTPUT2);

	while (!GPIO_INPUT_GET(GPIO_BUTTON1)) { os_printf("."); };
	while (!GPIO_INPUT_GET(GPIO_BUTTON2)) { os_printf("."); };

	system_restart();
}
Ejemplo n.º 3
0
LOCAL void ICACHE_FLASH_ATTR handle_pin_press() {
console_printf("TIMER EXECUTED\n");
if(button_counter==1){
	if(!GPIO_INPUT_GET(PIN_GPIO13)){  // button is pressed once and is still pressed after the timeout
		MQTT_Publish(&mqttClient,BR_MODE,"2",1,0,0); // Set overall MODE to OFF
		GPIO_OUTPUT_SET(PIN_GPIO5, 0);
		MQTT_Publish(&mqttClient,PIN_GPIO5_TOPIC,"OFF",3,0,0);
		GPIO_OUTPUT_SET(PIN_GPIO12, 0);
		MQTT_Publish(&mqttClient,PIN_GPIO12_TOPIC,"OFF",3,0,0);
		GPIO_OUTPUT_SET(PIN_GPIO14, 0);
		MQTT_Publish(&mqttClient,PIN_GPIO14_TOPIC,"OFF",3,0,0);
		button_counter=0;
	}
}
	switch(button_counter){
	case 1:
		if(!GPIO_INPUT_GET(PIN_GPIO5)){
			console_printf("FAN STARTED BY BUTTON. Only 1 press detected\n");
			GPIO_OUTPUT_SET(PIN_GPIO5, 1);
			MQTT_Publish(&mqttClient,PIN_GPIO5_TOPIC,"ON",2,0,0);
			MQTT_Publish(&mqttClient,BR_MODE,"4",1,0,0);
		} else {
			console_printf("FAN STOPPED BY BUTTON. Only 1 press detected\n");
			GPIO_OUTPUT_SET(PIN_GPIO5, 0);
			MQTT_Publish(&mqttClient,PIN_GPIO5_TOPIC,"OFF",3,0,0);
		}
		break;
/*		GPIO_OUTPUT_SET(PIN_GPIO5, curr_input_pin_state);
		MQTT_Publish(&mqttClient,PIN_GPIO13_TOPIC,"ON",2,0,0);
		MQTT_Publish(&mqttClient,PIN_GPIO5_TOPIC,"ON",2,0,0);/**/
	case 2:
		if(!GPIO_INPUT_GET(PIN_GPIO14)){
			console_printf("BOILER STARTED BY BUTTON. 2 presses detected\n");
			GPIO_OUTPUT_SET(PIN_GPIO14, 1);
			MQTT_Publish(&mqttClient,PIN_GPIO14_TOPIC,"ON",2,0,0);
		} else {
			console_printf("BOILER STOPPED BY BUTTON. 2 presses detected\n");
			GPIO_OUTPUT_SET(PIN_GPIO14, 0);
			MQTT_Publish(&mqttClient,PIN_GPIO14_TOPIC,"OFF",3,0,0);
			MQTT_Publish(&mqttClient,BR_MODE,"2",1,0,0);
		}
		break;
/*	case 3:
		if(!GPIO_INPUT_GET(PIN_GPIO12)){
			console_printf("HEATING STARTED BY BUTTON. 3 presses detected\n");
			GPIO_OUTPUT_SET(PIN_GPIO12, 1);
			MQTT_Publish(&mqttClient,PIN_GPIO12_TOPIC,"OFF",3,0,0);
		} else {
			console_printf("HEATING STOPPED BY BUTTON. 3 presses detected\n");
			GPIO_OUTPUT_SET(PIN_GPIO12, 0);
			MQTT_Publish(&mqttClient,PIN_GPIO12_TOPIC,"OFF",3,0,0);
		}
		break;/**/
	}
	button_counter=0; // zero the counter
	os_timer_disarm(&input_pin_timer); // Disarm input pin timer
}
Ejemplo n.º 4
0
void
supla_esp_gpio_check_switch_cfgbtn(void *timer_arg) {

	char v = GPIO_INPUT_GET(GPIO_ID_PIN((int)timer_arg));

	if ( v != switch_cfgbtn_last_state ) {

		if ( switch_cfgbtn_counter == 0 ) {

			os_timer_disarm(&supla_gpio_timer5);
			os_timer_setfn(&supla_gpio_timer5, supla_esp_gpio_reset_cfg_counter, NULL);
			os_timer_arm (&supla_gpio_timer5, 10000, false);

		}

		switch_cfgbtn_counter++;

		supla_log(LOG_DEBUG, "Switch counter: %i", switch_cfgbtn_counter);

		if ( switch_cfgbtn_counter >= 10 ) {
			supla_esg_gpio_cfg_pressed();
		} else {
			supla_esg_gpio_manual_pressed();
		}

		switch_cfgbtn_last_state = v;
	}

	switch_cfgbtn_state_check = 0;

}
/******************************************************************************
 * FunctionName : user_sensor_init
 * Description  : init sensor function, include key and mvh3004
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR user_sensor_init(uint8 active) {
    user_link_led_init();
    wifi_status_led_install(SENSOR_WIFI_LED_IO_NUM, SENSOR_WIFI_LED_IO_MUX, SENSOR_WIFI_LED_IO_FUNC);

    if (wifi_get_opmode() != SOFTAP_MODE) {
        single_key[0] = key_init_single(SENSOR_KEY_IO_NUM, SENSOR_KEY_IO_MUX, SENSOR_KEY_IO_FUNC,
                                        user_sensor_long_press, NULL);

        keys.key_num = SENSOR_KEY_NUM;
        keys.single_key = single_key;
        key_init(&keys);

        if (GPIO_INPUT_GET(GPIO_ID_PIN(SENSOR_KEY_IO_NUM)) == 0) {
            user_sensor_long_press();
        }
    }

    if (wifi_get_opmode() != STATIONAP_MODE) {
        if (active == 1) {
            user_sensor_deep_sleep_init(SENSOR_CONNECT_TIME / 1000);//exceed SENSOR_CONNECT_TIME,sleep directly
        } else {
        user_sensor_deep_sleep_init(SENSOR_CONNECT_TIME / 1000);//exceed SENSOR_CONNECT_TIME,sleep directly
        }
    }
}
Ejemplo n.º 6
0
static void ICACHE_RAM_ATTR platform_gpio_intr_dispatcher (void *dummy){
  uint32 j=0;
  uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
  uint32 now = system_get_time();
  UNUSED(dummy);

#ifdef GPIO_INTERRUPT_HOOK_ENABLE
  if (gpio_status & platform_gpio_hook.all_bits) {
    for (j = 0; j < platform_gpio_hook.count; j++) {
       if (gpio_status & platform_gpio_hook.entry[j].bits)
         gpio_status = (platform_gpio_hook.entry[j].func)(gpio_status);
    }
  }
#endif
  /*
   * gpio_status is a bit map where bit 0 is set if unmapped gpio pin 0 (pin3) has
   * triggered the ISR. bit 1 if unmapped gpio pin 1 (pin10=U0TXD), etc.  Since this
   * is the ISR, it makes sense to optimize this by doing a fast scan of the status
   * and reverse mapping any set bits.
   */
   for (j = 0; gpio_status>0; j++, gpio_status >>= 1) {
    if (gpio_status&1) {
      int i = pin_num_inv[j];
      if (pin_int_type[i]) {
        //disable interrupt
        gpio_pin_intr_state_set(GPIO_ID_PIN(j), GPIO_PIN_INTR_DISABLE);
        //clear interrupt status
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(j));
        uint32 level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(j));
	task_post_high (gpio_task_handle, (now << 8) + (i<<1) + level);
	// We re-enable the interrupt when we execute the callback
      }
    }
  }
}
Ejemplo n.º 7
0
static void ICACHE_FLASH_ATTR resetButtonTimerCallback(void *data)
{
    static int previousState = 1;
    static int matchingSampleCount = 0;
    static int buttonPressCount = 0;
    static uint32_t lastButtonTime;
    int newState = GPIO_INPUT_GET(RESET_BUTTON_PIN);
    if (newState != previousState)
        matchingSampleCount = 0;
    else if (matchingSampleCount < RESET_BUTTON_THRESHOLD) {
        if (++matchingSampleCount == RESET_BUTTON_THRESHOLD) {
            if (newState != resetButtonState) {
                resetButtonState = newState;
                if (resetButtonState == 0) {
                    uint32_t buttonTime = system_get_time() / 1000;
                    //os_printf("Reset button press: count %d, last %u, this %u\n", buttonPressCount, (unsigned)lastButtonTime, (unsigned)buttonTime);
                    if (buttonPressCount == 0 || buttonTime - lastButtonTime > RESET_BUTTON_PRESS_DELTA)
                        buttonPressCount = 1;
                    else if (++buttonPressCount == RESET_BUTTON_PRESS_COUNT) {
                        os_printf("Entering STA+AP mode\n");
                        wifi_set_opmode(STATIONAP_MODE);
                        buttonPressCount = 0;
                    }
                    lastButtonTime = buttonTime;
                }
            }
        }
    }
    previousState = newState;
}
Ejemplo n.º 8
0
static void ICACHE_FLASH_ATTR on_timeout(void *arg)
{
	static uint8_t lastPin0 = 0xFF, lastPin1 = 0xFF;
	uint8_t pin0 = GPIO_INPUT_GET(PIN0);
	uint8_t pin1 = GPIO_INPUT_GET(PIN1);

	if ((pin0 != lastPin0 || pin1 != lastPin1) && client != NULL) {
		uint8_t data[2];
		data[0] = pin0 ? '1' : '0';
		data[1] = pin1 ? '1' : '0';

		MQTT_Publish(client, settings.mqttTopic, data, 2, 0, 1);
		lastPin0 = pin0;
		lastPin1 = pin1;
	}
}
Ejemplo n.º 9
0
/******************************************************************************
 * FunctionName : i2c_master_getDC
 * Description  : Internal used function -
 *                    get i2c SDA bit value
 * Parameters   : NONE
 * Returns      : uint8 - SDA bit value
*******************************************************************************/
LOCAL uint8 ICACHE_FLASH_ATTR
i2c_master_getDC(void)
{
    uint8 sda_out;
    sda_out = GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO));
    return sda_out;
}
// digitalRead([pin])
void ICACHE_FLASH_ATTR
at_setupReadPinCmd(uint8_t id, char *pPara)
{
    int result = 0, err = 0, flag = 0;
    uint8 buffer[32] = {0};
    pPara++; // skip '='

    //get the first parameter (uint8_t)
    // digit
    flag = at_get_next_int_dec(&pPara, &result, &err);

    // flag must be true because there are more parameters
    //if ((flag == FALSE) && (result > 0) )
	if (err > 0)
	{
		at_port_print("Bad input");
        at_response_error();
        return;
    }
	
	uint8_t pin = result;
	
	// Don't go any further if the pin is un-usable or non-existant
	if (!pinValid(pin))
	{
		at_response_error();
		return;
	}
	
	uint8_t value = GPIO_INPUT_GET(pin);
	os_sprintf(buffer, "%d\r\n", value);
	
	at_port_print(buffer);
	at_response_ok();
}
Ejemplo n.º 11
0
LOCAL void ICACHE_FLASH_ATTR dht22_cb(void *arg)
{
	struct dht_sensor_data* r = DHTRead();
	int tempLength=0;
	int humLength=0;
	float lastTemp = r->temperature;
	float lastHum = r->humidity;
	if(r->success&&lastTemp>-30&&lastHum>0)
	{
		//TRANSFORMATION HERE
		console_printf("DHT22/Temperature: %d.%d *C, Humidity: %d.%d %%\r\n", (int)(lastTemp),(int)((lastTemp - (int)lastTemp)*100), (int)(lastHum),(int)((lastHum - (int)lastHum)*100));
		os_sprintf(DHT22_Temperature,"%d.%d", (int)(lastTemp),(int)((lastTemp - (int)lastTemp)*100));
		os_sprintf(DHT22_Humidity,"%d.%d", (int)(lastHum),(int)((lastHum - (int)lastHum)*100));
		if(lastTemp>=0) {
			if(lastTemp>9)
				tempLength=4;
			 else
				tempLength=3;
		} else tempLength=5; // assumption - bathroom temperature should not fall under -9 :P
		if(lastHum>9) humLength=2;
			else if (lastHum==100) humLength=3;
				else humLength=1;
		// MQTT PUBLISH HERE
		MQTT_Publish(&mqttClient,DHT22_MQTT_Temperature,DHT22_Temperature,tempLength,0,0);
		MQTT_Publish(&mqttClient,DHT22_MQTT_Humidity,DHT22_Humidity,humLength,0,0);
		// MANUAL MODE LOGICS HERE
		if (dDEVICE_MODE){
			// maintain currently set humidity
			if(lastHum<dBR_HUMIDITY_SET&&GPIO_INPUT_GET(PIN_GPIO5)&&!GPIO_INPUT_GET(PIN_GPIO13)) {
				GPIO_OUTPUT_SET(PIN_GPIO5, 0);
			} else if ((lastHum>dBR_HUMIDITY_SET+7)&&!GPIO_INPUT_GET(PIN_GPIO5)) {
				GPIO_OUTPUT_SET(PIN_GPIO5,1);
			}
			// maintain currently set bathroom temperature
			if(lastTemp>=dBR_TEMP_ROOM_SET&&GPIO_INPUT_GET(PIN_GPIO12)){
				GPIO_OUTPUT_SET(PIN_GPIO12,0);
			} else if ((lastTemp<dBR_TEMP_ROOM_SET-1)&&!GPIO_INPUT_GET(PIN_GPIO12)) {
				GPIO_OUTPUT_SET(PIN_GPIO12,1);
			}
		}
	}
	else
	{
		console_printf("Error reading temperature and humidity\r\n");
	}
}
Ejemplo n.º 12
0
void ICACHE_FLASH_ATTR user_btn_short_press()
{
	os_printf("ON SHORT PRESS\n");
	uint32 iRet = 100;

	iRet = GPIO_INPUT_GET(14);
	os_printf("OUT: [%d]\n", iRet);
}
Ejemplo n.º 13
0
esp_comm_gpio_hold_t bootloader_common_check_long_hold_gpio(uint32_t num_pin, uint32_t delay_sec)
{
    gpio_pad_select_gpio(num_pin);
    if (GPIO_PIN_MUX_REG[num_pin]) {
        PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[num_pin]);
    }
    gpio_pad_pullup(num_pin);
    uint32_t tm_start = esp_log_early_timestamp();
    if (GPIO_INPUT_GET(num_pin) == 1) {
        return GPIO_NOT_HOLD;
    }
    do {
        if (GPIO_INPUT_GET(num_pin) != 0) {
            return GPIO_SHORT_HOLD;
        }
    } while (delay_sec > ((esp_log_early_timestamp() - tm_start) / 1000L));
    return GPIO_LONG_HOLD;
}
Ejemplo n.º 14
0
void
supla_esp_gpio_check_inputs(void *timer_arg) {

    #ifdef INPUT_PORT1
		char i1 = GPIO_INPUT_GET(GPIO_ID_PIN(INPUT_PORT1));

		if ( i1 != input1_last_state ) {

			char _input1_last_state = input1_last_state;
			input1_last_state = i1;

			#ifdef RELAY1_ELLOCK_MEM

			    if (  i1 == 1 && _input1_last_state == 0 ) {
			    	ellock_input1_state = 1;
				}

			    if ( i1 == 1 ) {
			    	i1 = ellock_input1_state;
			    };

			#endif

			#if defined(__BOARD_rs_module) || defined(__BOARD_rs_module_wroom) || defined(__BOARD_jangoe_rs)
			supla_esp_channel_value_changed(1, i1 == 1 ? 1 : 0);
			#else
			supla_esp_channel_value_changed(2, i1 == 1 ? 1 : 0);
			#endif

		}

    #endif

	#ifdef INPUT_PORT2
		char i2 = GPIO_INPUT_GET(GPIO_ID_PIN(INPUT_PORT2));

		if ( i2 != input2_last_state ) {
			input2_last_state = i2;

			supla_esp_channel_value_changed(3, i2 == 1 ? 1 : 0);
		}
	#endif
}
Ejemplo n.º 15
0
void pb1Transmit(){
	char tempreg[200];
	os_sprintf(tempreg, MQTT_TOPICIN, system_get_chip_id());

	if(GPIO_INPUT_GET(4)){
		MQTT_Publish(&mqttClient, tempreg, "1-1", strlen("1-1"), 0, 0);
	} else {
		MQTT_Publish(&mqttClient, tempreg, "1-0", strlen("1-0"), 0, 0);
	}
}
Ejemplo n.º 16
0
//
// Read a bit. Port and bit is used to cut lookup time and provide
// more certain timing.
//
uint32 ICACHE_FLASH_ATTR onewire_read_bit(void) {
	uint32 r;
	GPIO_OUTPUT_SET(ONEWIRE_PIN, 0);
	os_delay_us(3);
	GPIO_DIS_OUTPUT(ONEWIRE_PIN);
	os_delay_us(10);
	r = GPIO_INPUT_GET(ONEWIRE_PIN);
	os_delay_us(53);
	return r;
}
Ejemplo n.º 17
0
int supla_ds18b20_read_bit(void)
{
    int r;
    GPIO_OUTPUT_SET( supla_w1_pin, 0 );
    os_delay_us(3);
    GPIO_DIS_OUTPUT( supla_w1_pin );
    os_delay_us(10);
    r = GPIO_INPUT_GET( supla_w1_pin );
    os_delay_us(53);
    return r;
}
Ejemplo n.º 18
0
int ICACHE_FLASH_ATTR gpio_read(unsigned pin)
{
	if (pin >= GPIO_PIN_NUM)
		return -1;
	if(pin == 0){
		// gpio16_input_conf();
		return 0x1 & gpio16_input_get();
	}
	// GPIO_DIS_OUTPUT(pin_num[pin]);
	return 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[pin]));
}
//Template code for the counter on the index page.
int ICACHE_FLASH_ATTR tplCounter(HttpdConnData *connData, char *token, void **arg) {
	char buff[128];
	if (token==NULL) return HTTPD_CGI_DONE;

	if (os_strcmp(token, "counter")==0) {
		hitCounter++;
		os_sprintf(buff, "%s", GPIO_INPUT_GET(PIRGPIO) == 0 ? "no" : "some" );
	}
	httpdSend(connData, buff, -1);
	return HTTPD_CGI_DONE;
}
Ejemplo n.º 20
0
Archivo: key.c Proyecto: lvjh/ESP8266
/******************************************************************************
 * FunctionName : key_5s_cb
 * Description  : long press 5s timer callback
 * Parameters   : single_key_param *single_key - single key parameter
 * Returns	  : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR key_5s_cb(struct single_key_param *single_key) {
    os_timer_disarm(&single_key->key_5s);

    // low, then restart
    if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) {
        single_key->is_long = 1;
        if (single_key->long_press) {
            single_key->long_press();
        }
    }
}
Ejemplo n.º 21
0
void ICACHE_FLASH_ATTR BtnTimer(void *arg) {
	static int resetCnt=0;
	if (GPIO_INPUT_GET(BTNGPIO)) {
		resetCnt++;
	}
	if (resetCnt>=3) { //3 sec pressed
			os_printf("\nAlarm Went off");
			os_timer_arm(&Alarmtimer, 250, 1);
			alarmstate = 0;
			resetCnt=0;
	}
}
Ejemplo n.º 22
0
/******************************************************************************
 * FunctionName : key_5s_cb
 * Description  : long press 5s timer callback
 * Parameters   : single_key_param *single_key - single key parameter
 * Returns      : none
*******************************************************************************/
LOCAL void  
key_5s_cb(struct single_key_param *single_key)
{
    os_timer_disarm(&single_key->key_5s);
   //check this gpio pin state
    if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) {
        //this gpio has been in low state for 5s, then call long_press function
        if (single_key->long_press) {
            single_key->long_press();
        }
    }
}
Ejemplo n.º 23
0
void dcf_read_timer_cb(void)
{
	// Inverted signal, add to low count (lc) when pin is true
	if (GPIO_INPUT_GET(2)) {
		dcf_lc++;
		if (dcf_decoder_readjust) {
			dcf_decode_timer_adjust();
			dcf_decoder_readjust = false;
		}
	} else
		dcf_hc++;
}
Ejemplo n.º 24
0
/**
 * Uniform way of getting GPIO input value. Handles GPIO 0-16.
 * The pin must be initiated with easygpio_pinMode() so that the pin mux is setup as a gpio in the first place.
 * If you know that you won't be using GPIO16 then you'd better off by just using GPIO_INPUT_GET().
 */
uint8_t
easygpio_inputGet(uint8_t gpio_pin) {
  if (16==gpio_pin) {
    return (READ_PERI_REG(RTC_GPIO_IN_DATA) & 1UL);
  } else {
#ifdef EASYGPIO_USE_GPIO_INPUT_GET
    return GPIO_INPUT_GET(GPIO_ID_PIN(gpio_pin));
#else
  // this does *not* work, maybe GPIO_IN_ADDRESS is the wrong address
  return ((GPIO_REG_READ(GPIO_IN_ADDRESS) > gpio_pin)  & 1UL);
#endif
  }
}
Ejemplo n.º 25
0
/******************************************************************************
 * FunctionName : key_5s_cb
 * Description  : long press 5s timer callback
 * Parameters   : single_key_param *single_key - single key parameter
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
key_5s_cb(struct single_key_param *single_key)
{
    os_printf("-%s-%s \r\n", __FILE__, __func__);
    os_timer_disarm(&single_key->key_long);

    // low, then restart
    if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) {
        if (single_key->long_press) {
            single_key->long_press();
        }
    }
}
Ejemplo n.º 26
0
static void ICACHE_RAM_ATTR platform_gpio_intr_dispatcher (void *dummy){
  uint32 j=0;
  uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
  uint32 now = system_get_time();
  UNUSED(dummy);

#ifdef GPIO_INTERRUPT_HOOK_ENABLE
  if (gpio_status & platform_gpio_hook.all_bits) {
    for (j = 0; j < platform_gpio_hook.count; j++) {
       if (gpio_status & platform_gpio_hook.entry[j].bits)
         gpio_status = (platform_gpio_hook.entry[j].func)(gpio_status);
    }
  }
#endif
  /*
   * gpio_status is a bit map where bit 0 is set if unmapped gpio pin 0 (pin3) has
   * triggered the ISR. bit 1 if unmapped gpio pin 1 (pin10=U0TXD), etc.  Since this
   * is the ISR, it makes sense to optimize this by doing a fast scan of the status
   * and reverse mapping any set bits.
   */
   for (j = 0; gpio_status>0; j++, gpio_status >>= 1) {
    if (gpio_status&1) {
      int i = pin_num_inv[j];
      if (pin_int_type[i]) {
        uint16_t diff = pin_counter[i].seen ^ pin_counter[i].reported;

        pin_counter[i].seen = 0x7fff & (pin_counter[i].seen + 1);

        if (INTERRUPT_TYPE_IS_LEVEL(pin_int_type[i])) {
          //disable interrupt
          gpio_pin_intr_state_set(GPIO_ID_PIN(j), GPIO_PIN_INTR_DISABLE);
        }
        //clear interrupt status
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(j));

        if (diff == 0 || diff & 0x8000) {
          uint32 level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(j));
	  if (!task_post_high (gpio_task_handle, (now << 8) + (i<<1) + level)) {
            // If we fail to post, then try on the next interrupt
            pin_counter[i].seen |= 0x8000;
          }
          // We re-enable the interrupt when we execute the callback (if level)
        }
      } else {
        // this is an unexpected interrupt so shut it off for now
        gpio_pin_intr_state_set(GPIO_ID_PIN(j), GPIO_PIN_INTR_DISABLE);
        GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(j));
      }
    }
  }
}
Ejemplo n.º 27
0
Archivo: io.c Proyecto: bacl/WiFiPhot0
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) {
	static int resetCnt=0;
	if (!GPIO_INPUT_GET(BTNGPIO)) {
		resetCnt++;
	} else {
		if (resetCnt>=6) { //3 sec pressed
			wifi_station_disconnect();
			wifi_set_opmode(0x3); //reset to AP+STA mode
			os_printf("Reset to AP mode. Restarting system...\n");
			system_restart();
		}
		resetCnt=0;
	}
}
Ejemplo n.º 28
0
int platform_gpio_read( unsigned pin )
{
  // NODE_DBG("Function platform_gpio_read() is called. pin:%d\n",GPIO_ID_PIN(pin_num[pin]));
  if (pin >= NUM_GPIO)
    return -1;

  if(pin == 0){
    // gpio16_input_conf();
    return 0x1 & gpio16_input_get();
  }

  // GPIO_DIS_OUTPUT(pin_num[pin]);
  return 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[pin]));
}
Ejemplo n.º 29
0
void supla_ds18b20_reset(void)
{
    uint8_t retries = 125;
    GPIO_DIS_OUTPUT( supla_w1_pin );
    do {
        if (--retries == 0) return;
        os_delay_us(2);
    } while ( !GPIO_INPUT_GET( supla_w1_pin ));

    GPIO_OUTPUT_SET( supla_w1_pin, 0 );
    os_delay_us(480);
    GPIO_DIS_OUTPUT( supla_w1_pin );
    os_delay_us(480);
}
Ejemplo n.º 30
0
FUN_ATTRIBUTE
char * get_plug_state(void)
{
#define MSG "(state \"power\" 256 \"timer\" 4294967296 \"timertodo\" 256\")"
	uint8 state = GPIO_INPUT_GET(GPIO_ID_PIN(PLUG_POWR_PIN));
	char *msg = (char *)os_zalloc(sizeof(MSG));
	if (msg == NULL)
	{
		return NULL;
	}
	sprintf(msg, "(state \"power\" %u \"timer\" 0 \"timertodo\" 0)", state);

	return msg;
}