2015-11-30 22:56:40 +00:00
|
|
|
/* GPIO management functions
|
|
|
|
*
|
|
|
|
* Part of esp-open-rtos
|
|
|
|
* Copyright (C) 2015 Angus Gratton
|
|
|
|
* BSD Licensed as described in the file LICENSE
|
|
|
|
*/
|
|
|
|
#include <esp/gpio.h>
|
2016-08-30 11:22:05 +00:00
|
|
|
#include <esp/rtc_regs.h>
|
2015-11-30 22:56:40 +00:00
|
|
|
|
|
|
|
void gpio_enable(const uint8_t gpio_num, const gpio_direction_t direction)
|
|
|
|
{
|
2016-08-30 11:22:05 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-22 02:34:11 +00:00
|
|
|
switch (direction) {
|
2015-11-30 22:56:40 +00:00
|
|
|
case GPIO_INPUT:
|
2016-02-22 02:34:11 +00:00
|
|
|
GPIO.ENABLE_OUT_CLEAR = BIT(gpio_num);
|
|
|
|
iomux_set_gpio_function(gpio_num, false);
|
2015-11-30 22:56:40 +00:00
|
|
|
break;
|
|
|
|
case GPIO_OUTPUT:
|
2016-02-22 02:34:11 +00:00
|
|
|
GPIO.CONF[gpio_num] &= ~GPIO_CONF_OPEN_DRAIN;
|
|
|
|
GPIO.ENABLE_OUT_SET = BIT(gpio_num);
|
|
|
|
iomux_set_gpio_function(gpio_num, true);
|
2015-11-30 22:56:40 +00:00
|
|
|
break;
|
|
|
|
case GPIO_OUT_OPEN_DRAIN:
|
|
|
|
GPIO.CONF[gpio_num] |= GPIO_CONF_OPEN_DRAIN;
|
|
|
|
GPIO.ENABLE_OUT_SET = BIT(gpio_num);
|
2016-02-22 02:34:11 +00:00
|
|
|
iomux_set_gpio_function(gpio_num, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_set_pullup(uint8_t gpio_num, bool enabled, bool enabled_during_sleep)
|
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
flags |= IOMUX_PIN_PULLUP;
|
|
|
|
}
|
|
|
|
if (enabled_during_sleep) {
|
|
|
|
flags |= IOMUX_PIN_PULLUP_SLEEP;
|
|
|
|
}
|
|
|
|
iomux_set_pullup_flags(gpio_to_iomux(gpio_num), flags);
|
2015-11-30 22:56:40 +00:00
|
|
|
}
|
|
|
|
|