Created
October 3, 2014 13:44
-
-
Save zarya/b7f6270b49beeb2a2f9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ets_sys.h" | |
#include "driver/uart.h" | |
#include "osapi.h" | |
#include "at.h" | |
#include "key.h" | |
#include "gpio.h" | |
static os_timer_t some_timer; | |
void some_timerfunc(void *arg) | |
{ | |
uart0_sendStr("Key press\r\n"); | |
//enable interrupt | |
gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_NEGEDGE); | |
} | |
LOCAL void | |
key_intr_handler(int8_t key) | |
{ | |
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); | |
//disable interrupt | |
gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_DISABLE); | |
//Arm the debounce timer | |
os_timer_disarm(&some_timer); | |
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL); | |
os_timer_arm(&some_timer, 50, 0); | |
//clear interrupt status | |
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(0)); | |
} | |
void ICACHE_FLASH_ATTR | |
key_init() | |
{ | |
uint8 i; | |
ETS_GPIO_INTR_ATTACH(key_intr_handler,0); | |
ETS_GPIO_INTR_DISABLE(); | |
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); | |
gpio_output_set(0, 0, 0, GPIO_ID_PIN(0)); | |
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(0)); | |
//enable interrupt | |
gpio_pin_intr_state_set(GPIO_ID_PIN(0), GPIO_PIN_INTR_NEGEDGE); | |
ETS_GPIO_INTR_ENABLE(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment