idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
gpio.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
21#include <idfxx/error>
22#include <idfxx/flags>
23#include <idfxx/intr_alloc>
24
25#include <esp_idf_version.h>
26#include <functional>
27#include <hal/gpio_types.h>
28#include <soc/gpio_num.h>
29#include <soc/soc_caps.h>
30#include <string>
31#include <utility>
32
33namespace idfxx {
34
36template<int N>
37struct gpio_constant;
62class gpio {
63 template<int N>
64 friend struct gpio_constant;
65
66public:
68 enum class level : int {
69 low = 0,
70 high = 1,
71 };
72
82
90
99
109
110#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
112 enum class hys_ctrl_mode : int {
113#if SOC_GPIO_SUPPORT_PIN_HYS_CTRL_BY_EFUSE
115#endif
118 };
119#endif
120
121 class unique_isr_handle;
122
133 friend class gpio;
134 friend class unique_isr_handle;
135 constexpr isr_handle(gpio_num_t num, uint32_t id)
136 : _num(num)
137 , _id(id) {}
138 gpio_num_t _num;
139 uint32_t _id;
140 };
141
152 public:
159 : _num(GPIO_NUM_NC)
160 , _id(0) {}
161
167 : _num(handle._num)
168 , _id(handle._id) {}
169
175 : _num(std::exchange(other._num, GPIO_NUM_NC))
176 , _id(other._id) {}
177
184 if (this != &other) {
185 if (_num != GPIO_NUM_NC) {
186 gpio{_num}.try_isr_handler_remove(isr_handle{_num, _id});
187 }
188 _num = std::exchange(other._num, GPIO_NUM_NC);
189 _id = other._id;
190 }
191 return *this;
192 }
193
196
201 if (_num != GPIO_NUM_NC) {
202 // Removing the ISR handler will not fail, so we can ignore the result
203 gpio{_num}.try_isr_handler_remove(isr_handle{_num, _id});
204 }
205 }
206
212 auto handle = isr_handle{_num, _id};
213 _num = GPIO_NUM_NC;
214 return handle;
215 }
216
217 private:
218 gpio_num_t _num;
219 uint32_t _id;
220 };
221
231
232public:
234 constexpr gpio()
235 : _num(GPIO_NUM_NC) {}
236
243
244#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
251 [[nodiscard]] explicit gpio(int num);
252#endif
253
255 [[nodiscard]] static constexpr gpio nc() { return gpio{GPIO_NUM_NC}; }
256
258 [[nodiscard]] static constexpr gpio max() { return gpio{static_cast<gpio_num_t>(GPIO_NUM_MAX - 1)}; }
259
260 // Copyable and movable
261 gpio(const gpio&) = default;
262 gpio(gpio&&) = default;
263 gpio& operator=(const gpio&) = default;
264 gpio& operator=(gpio&&) = default;
265
267 [[nodiscard]] constexpr bool operator==(const gpio&) const noexcept = default;
268
270 [[nodiscard]] constexpr bool is_connected() const { return _num != GPIO_NUM_NC && _is_valid_gpio_num(_num); }
271
273 [[nodiscard]] constexpr bool is_output_capable() const { return _is_valid_output_gpio_num(_num); }
274
276 [[nodiscard]] constexpr bool is_digital_io_pin_capable() const { return _is_valid_digital_io_gpio_num(_num); }
277
279 [[nodiscard]] constexpr int num() const { return static_cast<int>(_num); }
280
282 [[nodiscard]] constexpr gpio_num_t idf_num() const { return _num; }
283
291 void reset();
292
293 // Direction and pull configuration
294#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
334#endif
347
348#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
354
360
365 void od_enable();
366
372#endif
373
383
392
425
426 // Level (input/output)
439 [[nodiscard]] enum level get_level() const;
450
451 // Drive capability
452#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
465#endif
478
479 // ISR service (must be installed before adding handlers)
480#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
505#endif
514 [[nodiscard]] static result<void>
533
534 // ISR handlers
535#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
554 isr_handle isr_handler_add(std::move_only_function<void() const> handler) {
555 return unwrap(try_isr_handler_add(std::move(handler)));
556 }
570 isr_handle isr_handler_add(void (*fn)(void*), void* arg) { return unwrap(try_isr_handler_add(fn, arg)); }
577#endif
594 result<isr_handle> try_isr_handler_add(std::move_only_function<void() const> handler);
619
620 // Interrupt configuration
636
637 // Wakeup configuration
638#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
652#endif
666
667 // Hold configuration (maintains state during sleep/reset)
668#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
691#endif
714#if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
733#endif
734
735 // Sleep mode configuration
746#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
753#endif
767
768private:
769 constexpr gpio(gpio_num_t num)
770 : _num(num) {}
771
772 static constexpr bool _is_valid_gpio_num(int num) {
773 return num >= 0 && num < GPIO_NUM_MAX && (SOC_GPIO_VALID_GPIO_MASK & (1ULL << num));
774 }
775 static constexpr bool _is_valid_output_gpio_num(int num) {
776 return num >= 0 && num < GPIO_NUM_MAX && (SOC_GPIO_VALID_OUTPUT_GPIO_MASK & (1ULL << num));
777 }
778 static constexpr bool _is_valid_digital_io_gpio_num(int num) {
779 return num >= 0 && num < GPIO_NUM_MAX && (SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK & (1ULL << num));
780 }
781
782 gpio_num_t _num;
783};
784
804template<typename... Gpios>
806 return try_configure_gpios(cfg, std::vector<gpio>{std::forward<Gpios>(gpios)...});
807}
808#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
818inline void configure_gpios(const gpio::config& cfg, std::vector<gpio> gpios) {
819 unwrap(try_configure_gpios(cfg, std::move(gpios)));
820}
830template<typename... Gpios>
832 unwrap(try_configure_gpios(cfg, std::vector<gpio>{std::forward<Gpios>(gpios)...}));
833}
834#endif
835
836#if SOC_GPIO_SUPPORT_FORCE_HOLD
850
856#endif // SOC_GPIO_SUPPORT_FORCE_HOLD
857
859/* Validates at compile time that the GPIO number is valid.
860 * Used internally to create the predefined GPIO constants.
861 */
862template<int N>
863struct gpio_constant {
864 static_assert(N == GPIO_NUM_NC || gpio::_is_valid_gpio_num(N), "Invalid GPIO number");
865 static constexpr gpio value{static_cast<gpio_num_t>(N)};
866};
878inline constexpr gpio gpio_nc = gpio_constant<GPIO_NUM_NC>::value;
879#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 0))
880inline constexpr gpio gpio_0 = gpio_constant<0>::value;
881#endif
882#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 1))
883inline constexpr gpio gpio_1 = gpio_constant<1>::value;
884#endif
885#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 2))
886inline constexpr gpio gpio_2 = gpio_constant<2>::value;
887#endif
888#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 3))
889inline constexpr gpio gpio_3 = gpio_constant<3>::value;
890#endif
891#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 4))
892inline constexpr gpio gpio_4 = gpio_constant<4>::value;
893#endif
894#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 5))
895inline constexpr gpio gpio_5 = gpio_constant<5>::value;
896#endif
897#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 6))
898inline constexpr gpio gpio_6 = gpio_constant<6>::value;
899#endif
900#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 7))
901inline constexpr gpio gpio_7 = gpio_constant<7>::value;
902#endif
903#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 8))
904inline constexpr gpio gpio_8 = gpio_constant<8>::value;
905#endif
906#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 9))
907inline constexpr gpio gpio_9 = gpio_constant<9>::value;
908#endif
909#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 10))
910inline constexpr gpio gpio_10 = gpio_constant<10>::value;
911#endif
912#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 11))
913inline constexpr gpio gpio_11 = gpio_constant<11>::value;
914#endif
915#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 12))
916inline constexpr gpio gpio_12 = gpio_constant<12>::value;
917#endif
918#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 13))
919inline constexpr gpio gpio_13 = gpio_constant<13>::value;
920#endif
921#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 14))
922inline constexpr gpio gpio_14 = gpio_constant<14>::value;
923#endif
924#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 15))
925inline constexpr gpio gpio_15 = gpio_constant<15>::value;
926#endif
927#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 16))
928inline constexpr gpio gpio_16 = gpio_constant<16>::value;
929#endif
930#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 17))
931inline constexpr gpio gpio_17 = gpio_constant<17>::value;
932#endif
933#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 18))
934inline constexpr gpio gpio_18 = gpio_constant<18>::value;
935#endif
936#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 19))
937inline constexpr gpio gpio_19 = gpio_constant<19>::value;
938#endif
939#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 20))
940inline constexpr gpio gpio_20 = gpio_constant<20>::value;
941#endif
942#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 21))
943inline constexpr gpio gpio_21 = gpio_constant<21>::value;
944#endif
945#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 22))
946inline constexpr gpio gpio_22 = gpio_constant<22>::value;
947#endif
948#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 23))
949inline constexpr gpio gpio_23 = gpio_constant<23>::value;
950#endif
951#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 24))
952inline constexpr gpio gpio_24 = gpio_constant<24>::value;
953#endif
954#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 25))
955inline constexpr gpio gpio_25 = gpio_constant<25>::value;
956#endif
957#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 26))
958inline constexpr gpio gpio_26 = gpio_constant<26>::value;
959#endif
960#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 27))
961inline constexpr gpio gpio_27 = gpio_constant<27>::value;
962#endif
963#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 28))
964inline constexpr gpio gpio_28 = gpio_constant<28>::value;
965#endif
966#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 29))
967inline constexpr gpio gpio_29 = gpio_constant<29>::value;
968#endif
969#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 30))
970inline constexpr gpio gpio_30 = gpio_constant<30>::value;
971#endif
972#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 31))
973inline constexpr gpio gpio_31 = gpio_constant<31>::value;
974#endif
975#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 32))
976inline constexpr gpio gpio_32 = gpio_constant<32>::value;
977#endif
978#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 33))
979inline constexpr gpio gpio_33 = gpio_constant<33>::value;
980#endif
981#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 34))
982inline constexpr gpio gpio_34 = gpio_constant<34>::value;
983#endif
984#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 35))
985inline constexpr gpio gpio_35 = gpio_constant<35>::value;
986#endif
987#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 36))
988inline constexpr gpio gpio_36 = gpio_constant<36>::value;
989#endif
990#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 37))
991inline constexpr gpio gpio_37 = gpio_constant<37>::value;
992#endif
993#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 38))
994inline constexpr gpio gpio_38 = gpio_constant<38>::value;
995#endif
996#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 39))
997inline constexpr gpio gpio_39 = gpio_constant<39>::value;
998#endif
999#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 40))
1000inline constexpr gpio gpio_40 = gpio_constant<40>::value;
1001#endif
1002#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 41))
1003inline constexpr gpio gpio_41 = gpio_constant<41>::value;
1004#endif
1005#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 42))
1006inline constexpr gpio gpio_42 = gpio_constant<42>::value;
1007#endif
1008#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 43))
1009inline constexpr gpio gpio_43 = gpio_constant<43>::value;
1010#endif
1011#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 44))
1012inline constexpr gpio gpio_44 = gpio_constant<44>::value;
1013#endif
1014#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 45))
1015inline constexpr gpio gpio_45 = gpio_constant<45>::value;
1016#endif
1017#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 46))
1018inline constexpr gpio gpio_46 = gpio_constant<46>::value;
1019#endif
1020#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 47))
1021inline constexpr gpio gpio_47 = gpio_constant<47>::value;
1022#endif
1023#if (SOC_GPIO_VALID_GPIO_MASK & (1ULL << 48))
1024inline constexpr gpio gpio_48 = gpio_constant<48>::value;
1025#endif
1026
// end of GPIO Constants
1028
1036[[nodiscard]] inline std::string to_string(gpio g) {
1037 if (!g.is_connected()) {
1038 return "GPIO_NC";
1039 }
1040 return "GPIO_" + std::to_string(g.num());
1041}
1042
1050[[nodiscard]] inline std::string to_string(gpio::level l) {
1051 return l == gpio::level::high ? "high" : "low";
1052}
1053
1064
// end of idfxx_gpio
1066
1067} // namespace idfxx
1068
1069#include "sdkconfig.h"
1070#ifdef CONFIG_IDFXX_STD_FORMAT
1072#include <algorithm>
1073#include <format>
1074namespace std {
1075template<>
1076struct formatter<idfxx::gpio> {
1077 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
1078
1079 template<typename FormatContext>
1080 auto format(idfxx::gpio g, FormatContext& ctx) const {
1081 auto s = to_string(g);
1082 return std::copy(s.begin(), s.end(), ctx.out());
1083 }
1084};
1085template<>
1086struct formatter<idfxx::gpio::level> {
1087 constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
1088
1089 template<typename FormatContext>
1090 auto format(idfxx::gpio::level l, FormatContext& ctx) const {
1091 auto s = to_string(l);
1092 return std::copy(s.begin(), s.end(), ctx.out());
1093 }
1094};
1095} // namespace std
1097#endif // CONFIG_IDFXX_STD_FORMAT
Handle to a registered ISR handler.
Definition gpio.hpp:132
RAII handle for ISR registration that removes the handler on destruction.
Definition gpio.hpp:151
unique_isr_handle & operator=(unique_isr_handle &&other) noexcept
Move assignment operator.
Definition gpio.hpp:183
unique_isr_handle() noexcept
Constructs an empty unique_isr_handle.
Definition gpio.hpp:158
unique_isr_handle(unique_isr_handle &&other) noexcept
Move constructor.
Definition gpio.hpp:174
~unique_isr_handle()
Destructor.
Definition gpio.hpp:200
unique_isr_handle & operator=(const unique_isr_handle &)=delete
unique_isr_handle(const unique_isr_handle &)=delete
unique_isr_handle(isr_handle handle) noexcept
Constructs from an isr_handle, taking ownership.
Definition gpio.hpp:166
isr_handle release() noexcept
Releases ownership of the handle without removing the ISR.
Definition gpio.hpp:211
A GPIO pin.
Definition gpio.hpp:62
static result< gpio > make(int num)
Creates a validated GPIO pin.
static void uninstall_isr_service()
Uninstalls the GPIO ISR service, freeing related resources.
void set_drive_capability(enum drive_cap strength)
Sets the gpio drive capability.
Definition gpio.hpp:458
result< void > try_pulldown_disable()
Disables the internal pull-down resistor.
void intr_enable()
Enables interrupts for this gpio.
result< void > try_sleep_set_direction(enum mode mode)
Sets GPIO direction at sleep.
result< void > try_wakeup_enable(enum intr_type intr_type)
Enables GPIO wake-up from light sleep.
result< void > try_set_pull_mode(enum pull_mode mode)
Sets the pull resistor mode.
result< void > try_wakeup_disable()
Disables GPIO wake-up.
static result< void > try_install_isr_service(idfxx::intr_levels levels=intr_level_lowmed, idfxx::flags< intr_flag > flags={})
Installs the GPIO ISR service for per-gpio interrupt handlers.
static result< void > try_install_isr_service(idfxx::flags< intr_flag > flags)
Installs the GPIO ISR service with default priority levels.
Definition gpio.hpp:524
void pulldown_enable()
Enables the internal pull-down resistor.
Definition gpio.hpp:327
constexpr bool is_digital_io_pin_capable() const
Returns true if this gpio is a valid digital I/O pin.
Definition gpio.hpp:276
void input_enable()
Enables input on this gpio.
static void deep_sleep_hold_disable()
Disables hold for all digital GPIOs during deep sleep.
void sleep_set_direction(enum mode mode)
Sets GPIO direction at sleep.
Definition gpio.hpp:752
void output_disable()
Disables output on this gpio.
constexpr int num() const
Returns the underlying GPIO pin number.
Definition gpio.hpp:279
void set_intr_type(enum intr_type intr_type)
Sets the interrupt trigger type.
result< drive_cap > try_get_drive_capability() const
Gets the current drive capability.
result< void > try_set_direction(enum mode mode)
Sets the GPIO direction mode.
void sleep_sel_disable()
Disables SLP_SEL to change GPIO status automatically in light sleep.
result< void > try_pullup_enable()
Enables the internal pull-up resistor.
gpio & operator=(const gpio &)=default
enum level get_level() const
Reads the current input level.
void wakeup_disable()
Disables GPIO wake-up.
Definition gpio.hpp:651
friend struct gpio_constant
Definition gpio.hpp:64
result< void > try_isr_handler_remove(isr_handle handle)
Removes a specific ISR handler.
result< void > try_set_drive_capability(enum drive_cap strength)
Sets the gpio drive capability.
void set_pull_mode(enum pull_mode mode)
Sets the pull resistor mode.
Definition gpio.hpp:309
void pulldown_disable()
Disables the internal pull-down resistor.
Definition gpio.hpp:333
void od_enable()
Enables open-drain mode on this gpio.
static constexpr gpio max()
Returns a GPIO for the highest valid pin number.
Definition gpio.hpp:258
gpio & operator=(gpio &&)=default
void sleep_set_pull_mode(enum pull_mode pull)
Sets pull resistor mode at sleep.
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Definition gpio.hpp:255
result< void > try_hold_disable()
Disables gpio hold function.
void output_enable()
Enables output on this gpio.
void set_level(enum level level)
Sets the output level.
void toggle_level()
Toggles the output level.
void reset()
Resets the gpio to default state.
mode
GPIO direction mode.
Definition gpio.hpp:74
@ disable
Disable input and output.
@ output
Output only.
@ input
Input only.
@ input_output_od
Input and output with open-drain mode.
@ input_output
Input and output.
@ output_od
Output only with open-drain mode.
isr_handle isr_handler_add(std::move_only_function< void() const > handler)
Adds an ISR handler for this gpio.
Definition gpio.hpp:554
constexpr gpio_num_t idf_num() const
Returns the underlying ESP-IDF GPIO number.
Definition gpio.hpp:282
gpio(const gpio &)=default
constexpr gpio()
Constructs a GPIO representing "not connected".
Definition gpio.hpp:234
pull_mode
Pull resistor configuration.
Definition gpio.hpp:84
@ floating
Pin floating.
@ pullup_pulldown
Pin pull up + pull down.
@ pullup
Pin pull up.
@ pulldown
Pin pull down.
result< void > try_hold_enable()
Enables gpio hold function.
static void install_isr_service(idfxx::intr_levels levels=intr_level_lowmed, idfxx::flags< intr_flag > flags={})
Installs the GPIO ISR service for per-gpio interrupt handlers.
Definition gpio.hpp:491
static void install_isr_service(idfxx::flags< intr_flag > flags)
Installs the GPIO ISR service with default priority levels.
Definition gpio.hpp:504
void od_disable()
Disables open-drain mode on this gpio.
void intr_disable()
Disables interrupts for this gpio.
level
GPIO output/input level.
Definition gpio.hpp:68
@ low
Logic low (0)
@ high
Logic high (1)
void hold_enable()
Enables gpio hold function.
Definition gpio.hpp:681
gpio(int num)
Constructs a validated GPIO pin.
result< isr_handle > try_isr_handler_add(std::move_only_function< void() const > handler)
Adds an ISR handler for this gpio.
void isr_handler_remove_all()
Removes all ISR handlers for this gpio.
constexpr bool operator==(const gpio &) const noexcept=default
Compares two GPIO pins for equality.
constexpr bool is_output_capable() const
Returns true if this gpio supports output mode.
Definition gpio.hpp:273
isr_handle isr_handler_add(void(*fn)(void *), void *arg)
Adds an ISR handler for this gpio.
Definition gpio.hpp:570
gpio(gpio &&)=default
state get_state() const
Returns the current configuration state of this GPIO.
drive_cap
Pin drive capability (output strength).
Definition gpio.hpp:92
@ cap_0
Weak drive capability.
@ cap_default
Medium drive capability.
@ cap_1
Stronger drive capability.
@ cap_2
Medium drive capability.
@ cap_3
Strongest drive capability.
constexpr bool is_connected() const
Returns true if this is a valid GPIO pin.
Definition gpio.hpp:270
void hold_disable()
Disables gpio hold function.
Definition gpio.hpp:690
result< void > try_pullup_disable()
Disables the internal pull-up resistor.
result< isr_handle > try_isr_handler_add(void(*fn)(void *), void *arg)
Adds an ISR handler for this gpio.
void set_direction(enum mode mode)
Sets the GPIO direction mode.
Definition gpio.hpp:301
void wakeup_enable(enum intr_type intr_type)
Enables GPIO wake-up from light sleep.
Definition gpio.hpp:645
result< void > try_pulldown_enable()
Enables the internal pull-down resistor.
void sleep_sel_enable()
Enables SLP_SEL to change GPIO status automatically in light sleep.
enum drive_cap get_drive_capability() const
Gets the current drive capability.
Definition gpio.hpp:464
hys_ctrl_mode
Hysteresis control mode.
Definition gpio.hpp:112
@ soft_enable
Pin input hysteresis enable by software.
@ soft_disable
Pin input hysteresis disable by software.
void pullup_enable()
Enables the internal pull-up resistor.
Definition gpio.hpp:315
void pullup_disable()
Disables the internal pull-up resistor.
Definition gpio.hpp:321
intr_type
Interrupt trigger type.
Definition gpio.hpp:101
@ disable
Disable GPIO interrupt.
@ low_level
Input low level trigger.
@ high_level
Input high level trigger.
@ anyedge
Both rising and falling edge.
@ negedge
Falling edge.
@ posedge
Rising edge.
static void deep_sleep_hold_enable()
Enables hold for all digital GPIOs during deep sleep.
void isr_handler_remove(isr_handle handle)
Removes a specific ISR handler.
Definition gpio.hpp:576
@ efuse
Reset due to efuse error.
std::string to_string(core_id c)
Returns a string representation of a CPU core identifier.
Definition cpu.hpp:52
constexpr gpio gpio_36
Definition gpio.hpp:988
constexpr gpio gpio_11
Definition gpio.hpp:913
void configure_gpios(const gpio::config &cfg, std::vector< gpio > gpios)
Configures multiple GPIOs with the same settings.
Definition gpio.hpp:818
constexpr gpio gpio_33
Definition gpio.hpp:979
constexpr gpio gpio_47
Definition gpio.hpp:1021
constexpr gpio gpio_23
Definition gpio.hpp:949
constexpr gpio gpio_8
Definition gpio.hpp:904
constexpr gpio gpio_20
Definition gpio.hpp:940
constexpr gpio gpio_38
Definition gpio.hpp:994
constexpr gpio gpio_39
Definition gpio.hpp:997
constexpr gpio gpio_46
Definition gpio.hpp:1018
constexpr gpio gpio_3
Definition gpio.hpp:889
constexpr gpio gpio_16
Definition gpio.hpp:928
constexpr gpio gpio_35
Definition gpio.hpp:985
constexpr gpio gpio_0
Definition gpio.hpp:880
constexpr gpio gpio_4
Definition gpio.hpp:892
constexpr gpio gpio_7
Definition gpio.hpp:901
constexpr gpio gpio_12
Definition gpio.hpp:916
constexpr gpio gpio_13
Definition gpio.hpp:919
constexpr gpio gpio_17
Definition gpio.hpp:931
constexpr gpio gpio_2
Definition gpio.hpp:886
constexpr gpio gpio_29
Definition gpio.hpp:967
constexpr gpio gpio_14
Definition gpio.hpp:922
result< void > try_configure_gpios(const gpio::config &cfg, std::vector< gpio > gpios)
Configures multiple GPIOs with the same settings.
constexpr gpio gpio_21
Definition gpio.hpp:943
constexpr gpio gpio_34
Definition gpio.hpp:982
constexpr gpio gpio_44
Definition gpio.hpp:1012
constexpr gpio gpio_18
Definition gpio.hpp:934
constexpr gpio gpio_31
Definition gpio.hpp:973
constexpr gpio gpio_9
Definition gpio.hpp:907
constexpr gpio gpio_41
Definition gpio.hpp:1003
constexpr gpio gpio_26
Definition gpio.hpp:958
constexpr gpio gpio_43
Definition gpio.hpp:1009
constexpr gpio gpio_25
Definition gpio.hpp:955
constexpr gpio gpio_nc
Definition gpio.hpp:878
constexpr gpio::level operator~(gpio::level l) noexcept
Inverts a GPIO level.
Definition gpio.hpp:1061
constexpr gpio gpio_1
Definition gpio.hpp:883
constexpr gpio gpio_10
Definition gpio.hpp:910
constexpr gpio gpio_30
Definition gpio.hpp:970
constexpr gpio gpio_48
Definition gpio.hpp:1024
constexpr gpio gpio_6
Definition gpio.hpp:898
constexpr gpio gpio_22
Definition gpio.hpp:946
constexpr gpio gpio_32
Definition gpio.hpp:976
constexpr gpio gpio_19
Definition gpio.hpp:937
constexpr gpio gpio_5
Definition gpio.hpp:895
constexpr gpio gpio_40
Definition gpio.hpp:1000
constexpr gpio gpio_28
Definition gpio.hpp:964
constexpr gpio gpio_24
Definition gpio.hpp:952
constexpr gpio gpio_27
Definition gpio.hpp:961
constexpr gpio gpio_37
Definition gpio.hpp:991
constexpr gpio gpio_45
Definition gpio.hpp:1015
constexpr gpio gpio_42
Definition gpio.hpp:1006
constexpr gpio gpio_15
Definition gpio.hpp:925
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
Definition error.hpp:307
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
constexpr intr_levels intr_level_lowmed
Low and medium priority levels (1-3). These can be handled in C / C++.
Configuration parameters for idfxx::gpio_config.
Definition gpio.hpp:223
Current configuration state of a GPIO pin.
Definition gpio.hpp:375
bool input_enabled
Input is enabled.
Definition gpio.hpp:376
bool output_enabled
Output is enabled.
Definition gpio.hpp:377
bool pulldown_enabled
Internal pull-down is enabled.
Definition gpio.hpp:380
enum drive_cap drive_strength
Drive strength.
Definition gpio.hpp:381
bool open_drain
Open-drain mode is enabled.
Definition gpio.hpp:378
bool pullup_enabled
Internal pull-up is enabled.
Definition gpio.hpp:379