From e49ce1e6d726ba7d3e6f80a9608d80cab316df32 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 6 Dec 2017 13:49:32 +0100 Subject: Add support for arduino-like loop function + blinky on esp8266 --- src/arch/esp8266/Makefile.inc | 2 +- src/arch/esp8266/arch.cc | 21 ++++++++++++++++++++- src/arch/esp8266/driver/gpio.cc | 2 +- src/os/main.cc | 7 ++++++- 4 files changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc index 3f7f9ff..b0fc4ce 100644 --- a/src/arch/esp8266/Makefile.inc +++ b/src/arch/esp8266/Makefile.inc @@ -11,7 +11,7 @@ AR = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-ar LD = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc INCLUDES += -Iinclude/esp8266 -I${SDK_BASE}/include -COMMON_FLAGS += -nostdlib -mlongcalls +COMMON_FLAGS += -nostdlib -mlongcalls -D__ets__ -DICACHE_FLASH CXXFLAGS = -std=c++11 LDFLAGS += -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static diff --git a/src/arch/esp8266/arch.cc b/src/arch/esp8266/arch.cc index 634cf40..3542423 100644 --- a/src/arch/esp8266/arch.cc +++ b/src/arch/esp8266/arch.cc @@ -7,15 +7,34 @@ extern "C" { #include "user_interface.h" #include "gpio.h" #include "mem.h" +void ets_timer_arm_new(os_timer_t *ptimer, uint32_t milliseconds, bool repeat_flag, bool us_flag); +void ets_timer_disarm(os_timer_t *ptimer); +void ets_timer_setfn(os_timer_t *ptimer, os_timer_func_t *pfunction, void *parg); } #define user_procTaskPrio 0 #define user_procTaskQueueLen 1 +#ifdef WITH_LOOP +LOCAL os_timer_t loop_timer; + +extern void loop(void); +static void ICACHE_FLASH_ATTR jump_to_loop(void *arg) +{ + loop(); +} + +#endif + extern int main(void); -static void ICACHE_FLASH_ATTR jump_to_main(void) +void ICACHE_FLASH_ATTR jump_to_main(void) { +#ifdef WITH_LOOP + os_timer_disarm(&loop_timer); + os_timer_setfn(&loop_timer, (os_timer_func_t *)jump_to_loop, (void *)0); + os_timer_arm(&loop_timer, 1000, 1); +#endif main(); } diff --git a/src/arch/esp8266/driver/gpio.cc b/src/arch/esp8266/driver/gpio.cc index bc236a9..6e995fc 100644 --- a/src/arch/esp8266/driver/gpio.cc +++ b/src/arch/esp8266/driver/gpio.cc @@ -30,7 +30,7 @@ void ICACHE_FLASH_ATTR GPIO::led_off(unsigned char id) void ICACHE_FLASH_ATTR GPIO::led_toggle(unsigned char id) { - if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2) { + if (gpio_input_get() & BIT2) { led_on(0); } else { led_off(0); diff --git a/src/os/main.cc b/src/os/main.cc index fff8aec..b080185 100644 --- a/src/os/main.cc +++ b/src/os/main.cc @@ -84,11 +84,16 @@ void check_command(unsigned char argc, char** argv) } */ +void loop(void) +{ + gpio.led_toggle(1); +} + int main(void) { arch.setup(); gpio.setup(); - gpio.led_on(1); + gpio.led_on(0); arch.idle_loop(); //uart_setup(); -- cgit v1.2.3