roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
gpio.h
Go to the documentation of this file.
1#pragma once
2
3#include "driver/gpio.h"
5#include "soc/gpio_struct.h"
6
7#ifdef ARDUINO
8// Support possible pin remapping in Arduino framework.
9#include "Arduino.h"
10#if defined(BOARD_HAS_PIN_REMAP) && !defined(BOARD_USES_HW_GPIO_NUMBERS)
11#define ROO_DISPLAY_GPIO_PIN_REMAP(pin) digitalPinToGPIONumber(pin)
12#endif
13#endif // ARDUINO
14
15#ifndef ROO_DISPLAY_GPIO_PIN_REMAP
16#define ROO_DISPLAY_GPIO_PIN_REMAP(pin) (pin)
17#endif
18
19// Variant-specific register access and output bank support.
20#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || \
21 CONFIG_IDF_TARGET_ESP32S3
22
23#define ROO_DISPLAY_GPIO_ESP32_SET(pin) \
24 do { \
25 const auto gpio = ROO_DISPLAY_GPIO_PIN_REMAP(pin); \
26 if (gpio < 32) { \
27 GPIO.out_w1ts = (1UL << gpio); \
28 } else { \
29 GPIO.out1_w1ts.val = (1UL << (gpio - 32)); \
30 } \
31 } while (0)
32
33#define ROO_DISPLAY_GPIO_ESP32_CLR(pin) \
34 do { \
35 const auto gpio = ROO_DISPLAY_GPIO_PIN_REMAP(pin); \
36 if (gpio < 32) { \
37 GPIO.out_w1tc = (1UL << gpio); \
38 } else { \
39 GPIO.out1_w1tc.val = (1UL << (gpio - 32)); \
40 } \
41 } while (0)
42
43#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 || \
44 CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
45
46#define ROO_DISPLAY_GPIO_ESP32_SET(pin) \
47 do { \
48 const auto gpio = ROO_DISPLAY_GPIO_PIN_REMAP(pin); \
49 GPIO.out_w1ts.val = (1UL << gpio); \
50 } while (0)
51
52#define ROO_DISPLAY_GPIO_ESP32_CLR(pin) \
53 do { \
54 const auto gpio = ROO_DISPLAY_GPIO_PIN_REMAP(pin); \
55 GPIO.out_w1tc.val = (1UL << gpio); \
56 } while (0)
57
58#else
59#error "Unsupported ESP32 variant"
60#endif
61
62namespace roo_display {
63namespace esp32 {
64
65struct Gpio {
71
72 // Templated setLow will be inlined to a single register write with a
73 // constant.
74 template <int pin>
75 static void setLow() {
77 }
78
79 // Templated setHigh will be inlined to a single register write with a
80 // constant.
81 template <int pin>
82 static void setHigh() {
84 }
85
86 // Non-templated versions as well, for when pin numbers are not fixed at
87 // compile time.
90};
91
92} // namespace esp32
93
95
96} // namespace roo_display
#define ROO_DISPLAY_GPIO_PIN_REMAP(pin)
Definition gpio.h:16
Defines 140 opaque HTML named colors.
static void setLow(int pin)
Definition gpio.h:88
static void setHigh()
Definition gpio.h:82
static void setOutput(int pin)
Definition gpio.h:66
static void setHigh(int pin)
Definition gpio.h:89
static void setLow()
Definition gpio.h:75