You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
esp-link/user/io.c

44 lines
1.0 KiB

#include "c_types.h"
#include "user_interface.h"
#include "espconn.h"
#include "mem.h"
#include "osapi.h"
#include "gpio.h"
#define LEDGPIO 2
#define BTNGPIO 0
static ETSTimer resetBtntimer;
void ICACHE_FLASH_ATTR ioLed(int ena) {
//gpio_output_set is overkill. ToDo: use better mactos
if (ena) {
gpio_output_set((1<<LEDGPIO), 0, (1<<LEDGPIO), 0);
} else {
gpio_output_set(0, (1<<LEDGPIO), (1<<LEDGPIO), 0);
}
}
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void) {
static int resetCnt=0;
if (!GPIO_INPUT_GET(BTNGPIO)) {
resetCnt++;
} else {
if (resetCnt>=6) { //3 sec pressed
wifi_set_opmode(0x3); //reset to AP+STA mode
os_printf("Reset to AP mode. Restarting system...\n");
system_restart();
}
resetCnt=0;
}
}
void ioInit() {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
gpio_output_set(0, 0, (1<<LEDGPIO), (1<<BTNGPIO));
os_timer_disarm(&resetBtntimer);
os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL);
os_timer_arm(&resetBtntimer, 500, 1);
}