35#ifndef _DRIVERS_ESP8266_ESP8266GPIO_HXX_
36#define _DRIVERS_ESP8266_ESP8266GPIO_HXX_
73 PERIPHS_IO_MUX_GPIO0_U,
74 PERIPHS_IO_MUX_U0TXD_U,
75 PERIPHS_IO_MUX_GPIO2_U,
76 PERIPHS_IO_MUX_U0RXD_U,
77 PERIPHS_IO_MUX_GPIO4_U,
78 PERIPHS_IO_MUX_GPIO5_U,
79 PERIPHS_IO_MUX_SD_CLK_U,
80 PERIPHS_IO_MUX_SD_DATA0_U,
81 PERIPHS_IO_MUX_SD_DATA1_U,
82 PERIPHS_IO_MUX_SD_DATA2_U,
83 PERIPHS_IO_MUX_SD_DATA3_U,
84 PERIPHS_IO_MUX_SD_CMD_U,
85 PERIPHS_IO_MUX_MTDI_U,
86 PERIPHS_IO_MUX_MTCK_U,
87 PERIPHS_IO_MUX_MTMS_U,
88 PERIPHS_IO_MUX_MTDO_U,
108template <
int PIN_NUM, u
int32_t MUXREG, u
int32_t FUNC_GPIO>
113 static constexpr const uint32_t
PIN = PIN_NUM;
115 static constexpr const uint32_t
PIN_BIT = (1 << PIN_NUM);
130 GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS,
PIN_BIT);
136 GPIO_REG_WRITE(GPIO_ENABLE_W1TC_ADDRESS,
PIN_BIT);
142 CLEAR_PERI_REG_MASK(
PIN_MUX_REG, PERIPHS_IO_MUX_PULLUP2 | PERIPHS_IO_MUX_SLEEP_PULLUP | PERIPHS_IO_MUX_SLEEP_PULLUP2);
143 SET_PERI_REG_MASK(
PIN_MUX_REG, PERIPHS_IO_MUX_PULLUP);
150 PIN_MUX_REG, PERIPHS_IO_MUX_PULLUP | PERIPHS_IO_MUX_PULLUP2);
156 CLEAR_PERI_REG_MASK(
PIN_MUX_REG, PERIPHS_IO_MUX_PULLUP | PERIPHS_IO_MUX_SLEEP_PULLUP | PERIPHS_IO_MUX_SLEEP_PULLUP2);
157 SET_PERI_REG_MASK(
PIN_MUX_REG, PERIPHS_IO_MUX_PULLUP2);
164 PIN_MUX_REG, PERIPHS_IO_MUX_PULLUP | PERIPHS_IO_MUX_PULLUP2);
170 GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS,
PIN_BIT);
176 GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS,
PIN_BIT);
182 return (GPIO_REG_READ(GPIO_IN_ADDRESS) &
PIN_BIT) != 0;
186 static void set(
bool value)
207 return GPIO_REG_READ(GPIO_ENABLE_ADDRESS) &
PIN_BIT;
211template <
class Base,
bool SAFE_VALUE,
bool INVERT = false>
218 Base::set(SAFE_VALUE);
221 Base::set(SAFE_VALUE);
226 Base::set(SAFE_VALUE);
230 static void set(
bool value)
256 Base::set_pullup_on();
261 Base::set_pullup_on();
265 static void set(
bool value)
268 Base::set_pullup_on();
270 Base::set_pulldown_on();
275 Base::set_pullup_on();
279 Base::set_pulldown_on();
321template <
class Base,
bool PUEN>
struct GpioInputPar :
public Base
330 Base::set_pullup_on();
334 Base::set_pullup_off();
375#define GPIO_PIN(NAME, BaseClass, NUM) \
376 typedef BaseClass<Esp8266StaticGpio<NUM, gpio_num_to_pinmux_reg(NUM), \
377 FUNC_GPIO##NUM>> NAME##_Pin
uint8 gpio16_input_get(void)
Sample the value of GPIO16 input.
constexpr uint32_t gpio_num_to_pinmux_reg(int gpio_pin_num)
Constexpr function that takes a GPIO number and converts it to the pinmux register address.
void gpio16_output_set(uint8 value)
Set GPIO16 output level.
constexpr uint32_t pinmux_to_gpio_arr[]
Static map from gpio number to pinmux register address.
void gpio16_input_conf(void)
Enable GPIO16 pin intput.
void gpio16_output_conf(void)
Enable GPIO16 pin output.
Defines a GPIO output pin.
static constexpr const uint32_t PIN_BIT
Bit in a 16-bit register that is assigned to this pin.
static void toggle()
Toggles output pin value.
static constexpr const uint32_t PIN
Number of pin (0..15).
static constexpr const uint32_t PIN_MUX_FUNC_GPIO
Number of the GPIO function in this specific pinmux register.
static void set_pulldown_off()
Turns off pulldown (does not work).
static void set_off()
Sets output to LOW.
static constexpr const uint32_t PIN_MUX_REG
Address of the pinmux register that belongs to this pin.
static void set_gpio()
Chooses GPIO on the pinmux.
static void set_input()
Sets pin to input.
static void set_on()
Sets output to HIGH.
static void set_output()
Sets pin to output.
static void set_pullup_off()
Turns off pullup.
static void set_pullup_on()
Turns on pullup.
static void set(bool value)
Set output pin level.
static void set_pulldown_on()
Turns on pulldown (does not work).
Parametric GPIO output class.
static void hw_init()
Initializes the hardware pin.
static void set(bool value)
Sets the output pinm.
static void hw_set_to_safe()
Sets the hardware pin to a safe value.
Defines a GPIO output pin, initialized to be an output pin with high level.
Defines a GPIO output pin, initialized to be an output pin with high level.
Defines a GPIO output pin, initialized to be an output pin with low level.
Defines a GPIO output pin, initialized to be an output pin with low level.
Output pin that switches between high and low state by turning on pullup and pulldowns.
static void set_on()
Sets the output pin to HIGH.
static void set_off()
Sets the output pin to LOW.
static void hw_init()
Initializes the hardware pin.
static void hw_set_to_safe()
Sets the hardware pin to a safe state.
static void set(bool value)
Sets the value of an output pin to a specific state;.