diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-12-15 09:20:30 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-12-15 09:20:30 +0100 |
commit | bfcfa4cf67bad25ccba5ff735967d4c6abff899c (patch) | |
tree | ef153eb55f025f31fdb8abddb57d33e3131624d4 /src | |
parent | 62bb7da1740d7d4aaef3cbcc1261fc5ab62960ae (diff) |
Add support for ESP8266 secondary LED
Diffstat (limited to 'src')
-rw-r--r-- | src/app/ledblink/main.cc | 5 | ||||
-rw-r--r-- | src/arch/esp8266/Makefile.inc | 4 | ||||
-rw-r--r-- | src/arch/esp8266/driver/gpio.cc | 38 |
3 files changed, 41 insertions, 6 deletions
diff --git a/src/app/ledblink/main.cc b/src/app/ledblink/main.cc index 75c9116..8b0fe87 100644 --- a/src/app/ledblink/main.cc +++ b/src/app/ledblink/main.cc @@ -6,9 +6,6 @@ #ifndef TIMER_CYCLES #error makeflag timer_cycles=1 required #endif -#ifndef TIMER_S -#error makeflag timer_s=1 required -#endif /* void check_command(unsigned char argc, char** argv) @@ -96,7 +93,9 @@ void check_command(unsigned char argc, char** argv) void loop(void) { gpio.led_toggle(1); +#ifdef TIMER_S kout << dec << uptime.get_s() << endl; +#endif } int main(void) diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc index 0484985..a4b9831 100644 --- a/src/arch/esp8266/Makefile.inc +++ b/src/arch/esp8266/Makefile.inc @@ -21,6 +21,10 @@ TARGETS += src/arch/esp8266/driver/stdout.cc src/arch/esp8266/driver/uptime.cc OBJECTS = ${TARGETS:.cc=.o} +ifeq (${esp8266_led2}, 1) + COMMON_FLAGS += -DLED_ON_GPIO16 +endif + .cc.o: ${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc} ${OBJCOPY} --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal $@ diff --git a/src/arch/esp8266/driver/gpio.cc b/src/arch/esp8266/driver/gpio.cc index 6e995fc..d06130d 100644 --- a/src/arch/esp8266/driver/gpio.cc +++ b/src/arch/esp8266/driver/gpio.cc @@ -12,29 +12,61 @@ void ICACHE_FLASH_ATTR GPIO::setup() // Enable GPIO2 (ESP8266 on-board LED) as output PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); +#ifdef LED_ON_GPIO16 // Enable GPIO16 (RTC out / NodeMCU on-board LED) as output - //WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); - //WRITE_PERI_REG(RTC_GPIO_CONF, (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); - //WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); + WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); + WRITE_PERI_REG(RTC_GPIO_CONF, (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); + WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); + // Turn the GPIO on to make sure the LED is off by default + WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(1)); +#endif } void ICACHE_FLASH_ATTR GPIO::led_on(unsigned char id) { +#ifdef LED_ON_GPIO16 + if (id == 0) { + gpio_output_set(0, BIT2, BIT2, 0); + } else { + WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(0)); + } +#else gpio_output_set(0, BIT2, BIT2, 0); +#endif } void ICACHE_FLASH_ATTR GPIO::led_off(unsigned char id) { +#ifdef LED_ON_GPIO16 + if (id == 0) { + gpio_output_set(BIT2, 0, BIT2, 0); + } else { + WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(0)); + } +#else gpio_output_set(BIT2, 0, BIT2, 0); +#endif } void ICACHE_FLASH_ATTR GPIO::led_toggle(unsigned char id) { +#ifdef LED_ON_GPIO16 + if (id == 0) { + if (gpio_input_get() & BIT2) { + led_on(0); + } else { + led_off(0); + } + } else { + WRITE_PERI_REG(RTC_GPIO_OUT, (READ_PERI_REG(RTC_GPIO_OUT) ^ BIT0)); + } +#else if (gpio_input_get() & BIT2) { led_on(0); } else { led_off(0); } +#endif } GPIO gpio; |