diff --git a/Makefile b/Makefile index 468b1537dcbb4d9d2387a3f091fb3ee638c1cee3..656686aadbc63e9911cc2a16de6e9b9559ae18dd 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,10 @@ CXXFLAGS = -std=c++14 TARGETS = src/os/main.cc +ifeq (${arduino}, 1) + COMMON_FLAGS += -DWITH_LOOP +endif + include src/arch/${arch}/Makefile.inc clean: arch_clean diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc index 3f7f9ffce49409e7962f591eafc9f248817fb765..b0fc4ce6a5aee609b7af62108bc4e56227b33f9b 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 634cf409c5523c2d81130bf9db4ead447aae49b5..3542423f60546d472e0d9891617eb1c921c3a590 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 bc236a93ed8fb3d973974fb1c745dbb457c67801..6e995fc0b981bd70dbc4e0468e74c346d401d1de 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 fff8aec144265492dbc44cd0dda7fffd5e400ce8..b08018598b19fa11ac81cc04b56ec81ed0a74434 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();