#include "project.h" static struct gpio { int id; uint32_t pin; uint32_t func; uint32_t bit; } gpios[] = { { 0, PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0, BIT0}, { 2, PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2, BIT2}, { 12, PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, BIT12}, { 13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, BIT13}, { 14, PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, BIT14}, { 15, PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, BIT15} }; #define N_GPIOS (sizeof(gpios)/sizeof(gpios[0])) static os_timer_t gpio_timer; static os_timer_t gpio_intr_timer; void ICACHE_FLASH_ATTR gpio_dispatch (void) { uint32_t v = gpio_input_get (); msg_send (v); } static void ICACHE_FLASH_ATTR gpio_intr_timer_cb (void *arg) { gpio_dispatch (); } static void ICACHE_FLASH_ATTR gpio_timer_cb (void *arg) { gpio_dispatch (); } /* Docs say you can't call os_timer_arm in an interrupt, yet the examples do */ static void gpio_intr_handler (void *arg) { int i; uint32 status = GPIO_REG_READ (GPIO_STATUS_ADDRESS); /* Clear any interrupts */ for (i = 0; i < N_GPIOS; ++i) if (status & gpios[i].bit) GPIO_REG_WRITE (GPIO_STATUS_W1TC_ADDRESS, status & gpios[i].bit); /*Arm the timer*/ os_timer_disarm (&gpio_intr_timer); os_timer_setfn (&gpio_intr_timer, gpio_intr_timer_cb, NULL); os_timer_arm (&gpio_intr_timer, 5, 0); } void ICACHE_FLASH_ATTR gpio_page (struct espconn *conn) { char *page = os_zalloc (1024); char *ptr = page; int i; uint32_t j, v; if (!page) { webserver_send_reply (conn, 400, "text/html", "
Out of memory", 0); return; } ptr += os_sprintf (ptr, ""); ptr += os_sprintf (ptr, ""); ptr += os_sprintf (ptr, ""); v = gpio_input_get (); ptr += os_sprintf (ptr, "%d | 0x%04x | %s |