fixed GPIO interrupt handling

master
Martin Ger 2018-02-08 15:27:44 +01:00
rodzic 129476f2d7
commit c64651dd4f
5 zmienionych plików z 16 dodań i 14 usunięć

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -1,2 +1,2 @@
02d95626d108c50c19ec02713b22d6d198edae69 0x00000.bin
7baeec4d28782d8c97a82da9e3be163f641603a0 0x10000.bin
de8369a7f74fcd3ddd63201b4c3fe59bfa568628 0x00000.bin
5df5ec36d57ad423cdddb0f95121c01b529d1391 0x10000.bin

Wyświetl plik

@ -55,7 +55,7 @@ void config_load_default(sysconfig_p config) {
os_sprintf(config->mqtt_user, "%s", "none");
config->mqtt_password[0] = 0;
wifi_get_macaddr(0, mac);
os_sprintf(config->mqtt_id, "%s_%2x%2x%2x", MQTT_ID, mac[3], mac[4], mac[5]);
os_sprintf(config->mqtt_id, "%s_%02x%02x%02x", MQTT_ID, mac[3], mac[4], mac[5]);
#endif
#ifdef NTP
os_sprintf(config->ntp_server, "%s", "1.pool.ntp.org");

Wyświetl plik

@ -180,21 +180,22 @@ void ICACHE_FLASH_ATTR inttimer_func(void *arg){
// Interrupt handler - this function will be executed on any edge of a GPIO
LOCAL void gpio_intr_handler(void *arg)
{
gpio_entry_t *my_gpio_entry = (gpio_entry_t *)arg;
int i;
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
for (i = 0; i < gpio_counter; i++) {
if (gpio_status & BIT(gpios[i].no)) {
if (gpio_status & BIT(my_gpio_entry->no)) {
// Disable interrupt for GPIO
gpio_pin_intr_state_set(GPIO_ID_PIN(gpios[i].no), GPIO_PIN_INTR_DISABLE);
// Disable interrupt for GPIO
gpio_pin_intr_state_set(GPIO_ID_PIN(my_gpio_entry->no), GPIO_PIN_INTR_DISABLE);
// Clear interrupt status for GPIO
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(gpios[i].no));
// Clear interrupt status for GPIO
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(my_gpio_entry->no));
// Start the timer
os_timer_setfn(&my_gpio_entry->inttimer, inttimer_func, my_gpio_entry);
os_timer_arm(&my_gpio_entry->inttimer, 50, 0);
// Start the timer
os_timer_setfn(&gpios[i].inttimer, inttimer_func, &gpios[i]);
os_timer_arm(&gpios[i].inttimer, 50, 0);
}
}
}
@ -203,6 +204,7 @@ void ICACHE_FLASH_ATTR init_gpios() {
if (!script_enabled)
return;
for (i = 0; i < gpio_counter; i++) {
gpio_pin_intr_state_set(GPIO_ID_PIN(gpios[i].no), GPIO_PIN_INTR_ANYEDGE);
}
@ -622,7 +624,7 @@ int ICACHE_FLASH_ATTR parse_event(int next_token, bool * happend) {
return syntax_error(next_token, "too many gpio_interrupt");
gpios[gpio_counter].no = gpio_no;
easygpio_pinMode(gpio_no, pullup, EASYGPIO_INPUT);
easygpio_attachInterrupt(gpio_no, pullup, gpio_intr_handler, &gpios[gpio_counter]);
easygpio_attachInterrupt(gpio_no, pullup, gpio_intr_handler, NULL);
gpio_counter++;
}