@@ -31,11 +31,6 @@ constexpr std::array<uint32_t, 0> INVALID_GPIOS = {};
3131#error "No GPIOs defined for the current target"
3232#endif
3333
34- gpio_num_t gpio_to_driver_type (const GPIONum &gpio_num)
35- {
36- return static_cast <gpio_num_t >(gpio_num.get_num ());
37- }
38-
3934}
4035
4136GPIOException::GPIOException (esp_err_t error) : ESPException(error) { }
@@ -117,55 +112,55 @@ GPIODriveStrength GPIODriveStrength::STRONGEST()
117112
118113GPIOBase::GPIOBase (GPIONum num) : gpio_num(num)
119114{
120- GPIO_CHECK_THROW (gpio_reset_pin (gpio_to_driver_type ( gpio_num)));
115+ GPIO_CHECK_THROW (gpio_reset_pin (gpio_num. get_value < gpio_num_t >( )));
121116}
122117
123118void GPIOBase::hold_en ()
124119{
125- GPIO_CHECK_THROW (gpio_hold_en (gpio_to_driver_type ( gpio_num)));
120+ GPIO_CHECK_THROW (gpio_hold_en (gpio_num. get_value < gpio_num_t >( )));
126121}
127122
128123void GPIOBase::hold_dis ()
129124{
130- GPIO_CHECK_THROW (gpio_hold_dis (gpio_to_driver_type ( gpio_num)));
125+ GPIO_CHECK_THROW (gpio_hold_dis (gpio_num. get_value < gpio_num_t >( )));
131126}
132127
133128void GPIOBase::set_drive_strength (GPIODriveStrength strength)
134129{
135- GPIO_CHECK_THROW (gpio_set_drive_capability (gpio_to_driver_type ( gpio_num),
136- static_cast <gpio_drive_cap_t >(strength. get_strength () )));
130+ GPIO_CHECK_THROW (gpio_set_drive_capability (gpio_num. get_value < gpio_num_t >( ),
131+ strength. get_value <gpio_drive_cap_t >()));
137132}
138133
139134GPIO_Output::GPIO_Output (GPIONum num) : GPIOBase(num)
140135{
141- GPIO_CHECK_THROW (gpio_set_direction (gpio_to_driver_type ( gpio_num), GPIO_MODE_OUTPUT));
136+ GPIO_CHECK_THROW (gpio_set_direction (gpio_num. get_value < gpio_num_t >( ), GPIO_MODE_OUTPUT));
142137}
143138
144139void GPIO_Output::set_high ()
145140{
146- GPIO_CHECK_THROW (gpio_set_level (gpio_to_driver_type ( gpio_num), 1 ));
141+ GPIO_CHECK_THROW (gpio_set_level (gpio_num. get_value < gpio_num_t >( ), 1 ));
147142}
148143
149144void GPIO_Output::set_low ()
150145{
151- GPIO_CHECK_THROW (gpio_set_level (gpio_to_driver_type ( gpio_num), 0 ));
146+ GPIO_CHECK_THROW (gpio_set_level (gpio_num. get_value < gpio_num_t >( ), 0 ));
152147}
153148
154149GPIODriveStrength GPIOBase::get_drive_strength ()
155150{
156151 gpio_drive_cap_t strength;
157- GPIO_CHECK_THROW (gpio_get_drive_capability (gpio_to_driver_type ( gpio_num), &strength));
152+ GPIO_CHECK_THROW (gpio_get_drive_capability (gpio_num. get_value < gpio_num_t >( ), &strength));
158153 return GPIODriveStrength (static_cast <uint32_t >(strength));
159154}
160155
161156GPIOInput::GPIOInput (GPIONum num) : GPIOBase(num)
162157{
163- GPIO_CHECK_THROW (gpio_set_direction (gpio_to_driver_type ( gpio_num), GPIO_MODE_INPUT));
158+ GPIO_CHECK_THROW (gpio_set_direction (gpio_num. get_value < gpio_num_t >( ), GPIO_MODE_INPUT));
164159}
165160
166161GPIOLevel GPIOInput::get_level () const noexcept
167162{
168- int level = gpio_get_level (gpio_to_driver_type ( gpio_num));
163+ int level = gpio_get_level (gpio_num. get_value < gpio_num_t >( ));
169164 if (level) {
170165 return GPIOLevel::HIGH;
171166 } else {
@@ -175,34 +170,34 @@ GPIOLevel GPIOInput::get_level() const noexcept
175170
176171void GPIOInput::set_pull_mode (GPIOPullMode mode)
177172{
178- GPIO_CHECK_THROW (gpio_set_pull_mode (gpio_to_driver_type ( gpio_num),
179- static_cast <gpio_pull_mode_t >(mode. get_pull_mode () )));
173+ GPIO_CHECK_THROW (gpio_set_pull_mode (gpio_num. get_value < gpio_num_t >( ),
174+ mode. get_value <gpio_pull_mode_t >()));
180175}
181176
182177void GPIOInput::wakeup_enable (GPIOWakeupIntrType interrupt_type)
183178{
184- GPIO_CHECK_THROW (gpio_wakeup_enable (gpio_to_driver_type ( gpio_num),
185- static_cast <gpio_int_type_t >(interrupt_type. get_level () )));
179+ GPIO_CHECK_THROW (gpio_wakeup_enable (gpio_num. get_value < gpio_num_t >( ),
180+ interrupt_type. get_value <gpio_int_type_t >()));
186181}
187182
188183void GPIOInput::wakeup_disable ()
189184{
190- GPIO_CHECK_THROW (gpio_wakeup_disable (gpio_to_driver_type ( gpio_num)));
185+ GPIO_CHECK_THROW (gpio_wakeup_disable (gpio_num. get_value < gpio_num_t >( )));
191186}
192187
193188GPIO_OpenDrain::GPIO_OpenDrain (GPIONum num) : GPIOInput(num)
194189{
195- GPIO_CHECK_THROW (gpio_set_direction (gpio_to_driver_type ( gpio_num), GPIO_MODE_INPUT_OUTPUT_OD));
190+ GPIO_CHECK_THROW (gpio_set_direction (gpio_num. get_value < gpio_num_t >( ), GPIO_MODE_INPUT_OUTPUT_OD));
196191}
197192
198193void GPIO_OpenDrain::set_floating ()
199194{
200- GPIO_CHECK_THROW (gpio_set_level (gpio_to_driver_type ( gpio_num), 1 ));
195+ GPIO_CHECK_THROW (gpio_set_level (gpio_num. get_value < gpio_num_t >( ), 1 ));
201196}
202197
203198void GPIO_OpenDrain::set_low ()
204199{
205- GPIO_CHECK_THROW (gpio_set_level (gpio_to_driver_type ( gpio_num), 0 ));
200+ GPIO_CHECK_THROW (gpio_set_level (gpio_num. get_value < gpio_num_t >( ), 0 ));
206201}
207202
208203}
0 commit comments