From c52890eed7680f9249909977e3bd26785aa3bd5a Mon Sep 17 00:00:00 2001 From: ourairquality Date: Tue, 30 Aug 2016 21:22:05 +1000 Subject: [PATCH] GPIO16 support. --- core/esp_gpio.c | 17 +++++++++++++++++ core/include/esp/gpio.h | 14 ++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/core/esp_gpio.c b/core/esp_gpio.c index 8d12be1..f6db1ef 100644 --- a/core/esp_gpio.c +++ b/core/esp_gpio.c @@ -5,9 +5,26 @@ * BSD Licensed as described in the file LICENSE */ #include +#include void gpio_enable(const uint8_t gpio_num, const gpio_direction_t direction) { + if (gpio_num == 16) { + RTC.GPIO_CFG[3] = (RTC.GPIO_CFG[3] & 0xffffffbc) | 1; + RTC.GPIO_CONF = (RTC.GPIO_CONF & 0xfffffffe) | 0; + switch (direction) { + case GPIO_INPUT: + RTC.GPIO_ENABLE = (RTC.GPIO_OUT & 0xfffffffe); + break; + case GPIO_OUTPUT: + case GPIO_OUT_OPEN_DRAIN: + /* TODO open drain? */ + RTC.GPIO_ENABLE = (RTC.GPIO_OUT & 0xfffffffe) | 1; + break; + } + return; + } + switch (direction) { case GPIO_INPUT: GPIO.ENABLE_OUT_CLEAR = BIT(gpio_num); diff --git a/core/include/esp/gpio.h b/core/include/esp/gpio.h index 80fd43f..f3f6308 100644 --- a/core/include/esp/gpio.h +++ b/core/include/esp/gpio.h @@ -10,6 +10,7 @@ #define _ESP_GPIO_H #include #include "esp/gpio_regs.h" +#include "esp/rtc_regs.h" #include "esp/iomux.h" #include "esp/interrupts.h" @@ -23,7 +24,7 @@ typedef enum { GPIO_OUT_OPEN_DRAIN, /* Open drain output */ } gpio_direction_t; -/* Enable GPIO on the specified pin, and set it to input or output mode +/* Enable GPIO on the specified pin, and set it to input or output mode. */ void gpio_enable(const uint8_t gpio_num, const gpio_direction_t direction); @@ -80,7 +81,9 @@ static inline void gpio_set_output_on_sleep(const uint8_t gpio_num, bool enabled */ static inline void gpio_write(const uint8_t gpio_num, const bool set) { - if (set) + if (gpio_num == 16) { + RTC.GPIO_OUT = (RTC.GPIO_OUT & 0xfffffffe) | (set ? 1 : 0); + } else if (set) GPIO.OUT_SET = BIT(gpio_num) & GPIO_OUT_PIN_MASK; else GPIO.OUT_CLEAR = BIT(gpio_num) & GPIO_OUT_PIN_MASK; @@ -101,7 +104,7 @@ static inline void gpio_toggle(const uint8_t gpio_num) get an invalid value. Prevents one task from clobbering another task's pins, without needing to disable/enable interrupts. */ - if(GPIO.OUT & BIT(gpio_num)) + if (GPIO.OUT & BIT(gpio_num)) GPIO.OUT_CLEAR = BIT(gpio_num) & GPIO_OUT_PIN_MASK; else GPIO.OUT_SET = BIT(gpio_num) & GPIO_OUT_PIN_MASK; @@ -118,7 +121,10 @@ static inline void gpio_toggle(const uint8_t gpio_num) */ static inline bool gpio_read(const uint8_t gpio_num) { - return GPIO.IN & BIT(gpio_num); + if (gpio_num == 16) + return RTC.GPIO_IN & 1; + else + return GPIO.IN & BIT(gpio_num); } extern void gpio_interrupt_handler(void);