summaryrefslogtreecommitdiff
path: root/src/arch/esp8266/driver/gpio.cc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-12-15 09:20:30 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-12-15 09:20:30 +0100
commitbfcfa4cf67bad25ccba5ff735967d4c6abff899c (patch)
treeef153eb55f025f31fdb8abddb57d33e3131624d4 /src/arch/esp8266/driver/gpio.cc
parent62bb7da1740d7d4aaef3cbcc1261fc5ab62960ae (diff)
Add support for ESP8266 secondary LED
Diffstat (limited to 'src/arch/esp8266/driver/gpio.cc')
-rw-r--r--src/arch/esp8266/driver/gpio.cc38
1 files changed, 35 insertions, 3 deletions
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;