summaryrefslogtreecommitdiff
path: root/src/arch/esp8266/driver/gpio.cc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-12-05 16:00:05 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-12-05 16:00:05 +0100
commit6bdfa059a45b8b0dffc392e994827467463f0103 (patch)
tree9d2a7ff61dafbb2522a0a70f16179592e7c64096 /src/arch/esp8266/driver/gpio.cc
parent7b5284023070b841293d0c5a6be0c6c345372cde (diff)
Add basic ESP8266 support
Diffstat (limited to 'src/arch/esp8266/driver/gpio.cc')
-rw-r--r--src/arch/esp8266/driver/gpio.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/arch/esp8266/driver/gpio.cc b/src/arch/esp8266/driver/gpio.cc
new file mode 100644
index 0000000..bc236a9
--- /dev/null
+++ b/src/arch/esp8266/driver/gpio.cc
@@ -0,0 +1,40 @@
+#include "driver/gpio.h"
+extern "C" {
+#include "osapi.h"
+#include "user_interface.h"
+#include "gpio.h"
+}
+
+void ICACHE_FLASH_ATTR GPIO::setup()
+{
+ gpio_init();
+
+ // Enable GPIO2 (ESP8266 on-board LED) as output
+ PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
+
+ // 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);
+}
+
+void ICACHE_FLASH_ATTR GPIO::led_on(unsigned char id)
+{
+ gpio_output_set(0, BIT2, BIT2, 0);
+}
+
+void ICACHE_FLASH_ATTR GPIO::led_off(unsigned char id)
+{
+ gpio_output_set(BIT2, 0, BIT2, 0);
+}
+
+void ICACHE_FLASH_ATTR GPIO::led_toggle(unsigned char id)
+{
+ if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2) {
+ led_on(0);
+ } else {
+ led_off(0);
+ }
+}
+
+GPIO gpio;