Merge pull request #211 from ourairquality/gpio16

GPIO16 support.
This commit is contained in:
sheinz 2016-09-05 09:20:26 +03:00 committed by GitHub
commit ad8764b9c6
2 changed files with 27 additions and 4 deletions

View file

@ -5,9 +5,26 @@
* BSD Licensed as described in the file LICENSE
*/
#include <esp/gpio.h>
#include <esp/rtc_regs.h>
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);

View file

@ -10,6 +10,7 @@
#define _ESP_GPIO_H
#include <stdbool.h>
#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;
@ -118,6 +121,9 @@ static inline void gpio_toggle(const uint8_t gpio_num)
*/
static inline bool gpio_read(const uint8_t gpio_num)
{
if (gpio_num == 16)
return RTC.GPIO_IN & 1;
else
return GPIO.IN & BIT(gpio_num);
}