embassy_nrf/
gpio.rs

1//! General purpose input/output (GPIO) driver.
2#![macro_use]
3
4use core::convert::Infallible;
5use core::hint::unreachable_unchecked;
6
7use cfg_if::cfg_if;
8use embassy_hal_internal::{impl_peripheral, Peri, PeripheralType};
9
10use crate::pac;
11use crate::pac::common::{Reg, RW};
12use crate::pac::gpio;
13use crate::pac::gpio::vals;
14#[cfg(not(feature = "_nrf51"))]
15use crate::pac::shared::{regs::Psel, vals::Connect};
16
17/// A GPIO port with up to 32 pins.
18#[derive(Debug, Eq, PartialEq)]
19pub enum Port {
20    /// Port 0, available on nRF9160 and all nRF52 and nRF51 MCUs.
21    Port0,
22
23    /// Port 1, only available on some MCUs.
24    #[cfg(feature = "_gpio-p1")]
25    Port1,
26
27    /// Port 2, only available on some MCUs.
28    #[cfg(feature = "_gpio-p2")]
29    Port2,
30}
31
32/// Pull setting for an input.
33#[derive(Clone, Copy, Debug, Eq, PartialEq)]
34#[cfg_attr(feature = "defmt", derive(defmt::Format))]
35pub enum Pull {
36    /// No pull.
37    None,
38    /// Internal pull-up resistor.
39    Up,
40    /// Internal pull-down resistor.
41    Down,
42}
43
44/// GPIO input driver.
45pub struct Input<'d> {
46    pub(crate) pin: Flex<'d>,
47}
48
49impl<'d> Input<'d> {
50    /// Create GPIO input driver for a [Pin] with the provided [Pull] configuration.
51    #[inline]
52    pub fn new(pin: Peri<'d, impl Pin>, pull: Pull) -> Self {
53        let mut pin = Flex::new(pin);
54        pin.set_as_input(pull);
55
56        Self { pin }
57    }
58
59    /// Get whether the pin input level is high.
60    #[inline]
61    pub fn is_high(&self) -> bool {
62        self.pin.is_high()
63    }
64
65    /// Get whether the pin input level is low.
66    #[inline]
67    pub fn is_low(&self) -> bool {
68        self.pin.is_low()
69    }
70
71    /// Get the pin input level.
72    #[inline]
73    pub fn get_level(&self) -> Level {
74        self.pin.get_level()
75    }
76}
77
78/// Digital input or output level.
79#[derive(Clone, Copy, Debug, Eq, PartialEq)]
80#[cfg_attr(feature = "defmt", derive(defmt::Format))]
81pub enum Level {
82    /// Logical low.
83    Low,
84    /// Logical high.
85    High,
86}
87
88impl From<bool> for Level {
89    fn from(val: bool) -> Self {
90        match val {
91            true => Self::High,
92            false => Self::Low,
93        }
94    }
95}
96
97impl From<Level> for bool {
98    fn from(level: Level) -> bool {
99        match level {
100            Level::Low => false,
101            Level::High => true,
102        }
103    }
104}
105
106/// Drive strength settings for a given output level.
107// These numbers match vals::Drive exactly so hopefully the compiler will unify them.
108#[cfg(feature = "_nrf54l")]
109#[derive(Clone, Copy, Debug, PartialEq)]
110#[cfg_attr(feature = "defmt", derive(defmt::Format))]
111#[repr(u8)]
112pub enum LevelDrive {
113    /// Disconnect (do not drive the output at all)
114    Disconnect = 2,
115    /// Standard
116    Standard = 0,
117    /// High drive
118    High = 1,
119    /// Extra high drive
120    ExtraHigh = 3,
121}
122
123/// Drive strength settings for an output pin.
124///
125/// This is a combination of two drive levels, used when the pin is set
126/// low and high respectively.
127#[cfg(feature = "_nrf54l")]
128#[derive(Clone, Copy, Debug, PartialEq)]
129#[cfg_attr(feature = "defmt", derive(defmt::Format))]
130pub struct OutputDrive {
131    low: LevelDrive,
132    high: LevelDrive,
133}
134
135#[cfg(feature = "_nrf54l")]
136#[allow(non_upper_case_globals)]
137impl OutputDrive {
138    /// Standard '0', standard '1'
139    pub const Standard: Self = Self {
140        low: LevelDrive::Standard,
141        high: LevelDrive::Standard,
142    };
143    /// High drive '0', standard '1'
144    pub const HighDrive0Standard1: Self = Self {
145        low: LevelDrive::High,
146        high: LevelDrive::Standard,
147    };
148    /// Standard '0', high drive '1'
149    pub const Standard0HighDrive1: Self = Self {
150        low: LevelDrive::Standard,
151        high: LevelDrive::High,
152    };
153    /// High drive '0', high 'drive '1'
154    pub const HighDrive: Self = Self {
155        low: LevelDrive::High,
156        high: LevelDrive::High,
157    };
158    /// Disconnect '0' standard '1' (normally used for wired-or connections)
159    pub const Disconnect0Standard1: Self = Self {
160        low: LevelDrive::Disconnect,
161        high: LevelDrive::Standard,
162    };
163    /// Disconnect '0', high drive '1' (normally used for wired-or connections)
164    pub const Disconnect0HighDrive1: Self = Self {
165        low: LevelDrive::Disconnect,
166        high: LevelDrive::High,
167    };
168    /// Standard '0'. disconnect '1' (also known as "open drain", normally used for wired-and connections)
169    pub const Standard0Disconnect1: Self = Self {
170        low: LevelDrive::Standard,
171        high: LevelDrive::Disconnect,
172    };
173    /// High drive '0', disconnect '1' (also known as "open drain", normally used for wired-and connections)
174    pub const HighDrive0Disconnect1: Self = Self {
175        low: LevelDrive::High,
176        high: LevelDrive::Disconnect,
177    };
178}
179
180/// Drive strength settings for an output pin.
181// These numbers match vals::Drive exactly so hopefully the compiler will unify them.
182#[cfg(not(feature = "_nrf54l"))]
183#[derive(Clone, Copy, Debug, PartialEq)]
184#[cfg_attr(feature = "defmt", derive(defmt::Format))]
185#[repr(u8)]
186pub enum OutputDrive {
187    /// Standard '0', standard '1'
188    Standard = 0,
189    /// High drive '0', standard '1'
190    HighDrive0Standard1 = 1,
191    /// Standard '0', high drive '1'
192    Standard0HighDrive1 = 2,
193    /// High drive '0', high 'drive '1'
194    HighDrive = 3,
195    /// Disconnect '0' standard '1' (normally used for wired-or connections)
196    Disconnect0Standard1 = 4,
197    /// Disconnect '0', high drive '1' (normally used for wired-or connections)
198    Disconnect0HighDrive1 = 5,
199    /// Standard '0'. disconnect '1' (also known as "open drain", normally used for wired-and connections)
200    Standard0Disconnect1 = 6,
201    /// High drive '0', disconnect '1' (also known as "open drain", normally used for wired-and connections)
202    HighDrive0Disconnect1 = 7,
203}
204
205/// GPIO output driver.
206pub struct Output<'d> {
207    pub(crate) pin: Flex<'d>,
208}
209
210impl<'d> Output<'d> {
211    /// Create GPIO output driver for a [Pin] with the provided [Level] and [OutputDriver] configuration.
212    #[inline]
213    pub fn new(pin: Peri<'d, impl Pin>, initial_output: Level, drive: OutputDrive) -> Self {
214        let mut pin = Flex::new(pin);
215        match initial_output {
216            Level::High => pin.set_high(),
217            Level::Low => pin.set_low(),
218        }
219        pin.set_as_output(drive);
220
221        Self { pin }
222    }
223
224    /// Set the output as high.
225    #[inline]
226    pub fn set_high(&mut self) {
227        self.pin.set_high()
228    }
229
230    /// Set the output as low.
231    #[inline]
232    pub fn set_low(&mut self) {
233        self.pin.set_low()
234    }
235
236    /// Toggle the output level.
237    #[inline]
238    pub fn toggle(&mut self) {
239        self.pin.toggle()
240    }
241
242    /// Set the output level.
243    #[inline]
244    pub fn set_level(&mut self, level: Level) {
245        self.pin.set_level(level)
246    }
247
248    /// Get whether the output level is set to high.
249    #[inline]
250    pub fn is_set_high(&self) -> bool {
251        self.pin.is_set_high()
252    }
253
254    /// Get whether the output level is set to low.
255    #[inline]
256    pub fn is_set_low(&self) -> bool {
257        self.pin.is_set_low()
258    }
259
260    /// Get the current output level.
261    #[inline]
262    pub fn get_output_level(&self) -> Level {
263        self.pin.get_output_level()
264    }
265}
266
267pub(crate) fn convert_drive(w: &mut pac::gpio::regs::PinCnf, drive: OutputDrive) {
268    #[cfg(not(feature = "_nrf54l"))]
269    {
270        let drive = match drive {
271            OutputDrive::Standard => vals::Drive::S0S1,
272            OutputDrive::HighDrive0Standard1 => vals::Drive::H0S1,
273            OutputDrive::Standard0HighDrive1 => vals::Drive::S0H1,
274            OutputDrive::HighDrive => vals::Drive::H0H1,
275            OutputDrive::Disconnect0Standard1 => vals::Drive::D0S1,
276            OutputDrive::Disconnect0HighDrive1 => vals::Drive::D0H1,
277            OutputDrive::Standard0Disconnect1 => vals::Drive::S0D1,
278            OutputDrive::HighDrive0Disconnect1 => vals::Drive::H0D1,
279        };
280        w.set_drive(drive);
281    }
282
283    #[cfg(feature = "_nrf54l")]
284    {
285        fn convert(d: LevelDrive) -> vals::Drive {
286            match d {
287                LevelDrive::Disconnect => vals::Drive::D,
288                LevelDrive::Standard => vals::Drive::S,
289                LevelDrive::High => vals::Drive::H,
290                LevelDrive::ExtraHigh => vals::Drive::E,
291            }
292        }
293
294        w.set_drive0(convert(drive.low));
295        w.set_drive1(convert(drive.high));
296    }
297}
298
299fn convert_pull(pull: Pull) -> vals::Pull {
300    match pull {
301        Pull::None => vals::Pull::DISABLED,
302        Pull::Up => vals::Pull::PULLUP,
303        Pull::Down => vals::Pull::PULLDOWN,
304    }
305}
306
307/// GPIO flexible pin.
308///
309/// This pin can either be a disconnected, input, or output pin, or both. The level register bit will remain
310/// set while not in output mode, so the pin's level will be 'remembered' when it is not in output
311/// mode.
312pub struct Flex<'d> {
313    pub(crate) pin: Peri<'d, AnyPin>,
314}
315
316impl<'d> Flex<'d> {
317    /// Wrap the pin in a `Flex`.
318    ///
319    /// The pin remains disconnected. The initial output level is unspecified, but can be changed
320    /// before the pin is put into output mode.
321    #[inline]
322    pub fn new(pin: Peri<'d, impl Pin>) -> Self {
323        // Pin will be in disconnected state.
324        Self { pin: pin.into() }
325    }
326
327    /// Put the pin into input mode.
328    #[inline]
329    pub fn set_as_input(&mut self, pull: Pull) {
330        self.pin.conf().write(|w| {
331            w.set_dir(vals::Dir::INPUT);
332            w.set_input(vals::Input::CONNECT);
333            w.set_pull(convert_pull(pull));
334            convert_drive(w, OutputDrive::Standard);
335            w.set_sense(vals::Sense::DISABLED);
336        });
337    }
338
339    /// Put the pin into output mode.
340    ///
341    /// The pin level will be whatever was set before (or low by default). If you want it to begin
342    /// at a specific level, call `set_high`/`set_low` on the pin first.
343    #[inline]
344    pub fn set_as_output(&mut self, drive: OutputDrive) {
345        self.pin.conf().write(|w| {
346            w.set_dir(vals::Dir::OUTPUT);
347            w.set_input(vals::Input::DISCONNECT);
348            w.set_pull(vals::Pull::DISABLED);
349            convert_drive(w, drive);
350            w.set_sense(vals::Sense::DISABLED);
351        });
352    }
353
354    /// Put the pin into input + output mode.
355    ///
356    /// This is commonly used for "open drain" mode. If you set `drive = Standard0Disconnect1`,
357    /// the hardware will drive the line low if you set it to low, and will leave it floating if you set
358    /// it to high, in which case you can read the input to figure out whether another device
359    /// is driving the line low.
360    ///
361    /// The pin level will be whatever was set before (or low by default). If you want it to begin
362    /// at a specific level, call `set_high`/`set_low` on the pin first.
363    #[inline]
364    pub fn set_as_input_output(&mut self, pull: Pull, drive: OutputDrive) {
365        self.pin.conf().write(|w| {
366            w.set_dir(vals::Dir::OUTPUT);
367            w.set_input(vals::Input::CONNECT);
368            w.set_pull(convert_pull(pull));
369            convert_drive(w, drive);
370            w.set_sense(vals::Sense::DISABLED);
371        });
372    }
373
374    /// Put the pin into disconnected mode.
375    #[inline]
376    pub fn set_as_disconnected(&mut self) {
377        self.pin.conf().write(|w| {
378            w.set_input(vals::Input::DISCONNECT);
379        });
380    }
381
382    /// Get whether the pin input level is high.
383    #[inline]
384    pub fn is_high(&self) -> bool {
385        self.pin.block().in_().read().pin(self.pin.pin() as _)
386    }
387
388    /// Get whether the pin input level is low.
389    #[inline]
390    pub fn is_low(&self) -> bool {
391        !self.is_high()
392    }
393
394    /// Get the pin input level.
395    #[inline]
396    pub fn get_level(&self) -> Level {
397        self.is_high().into()
398    }
399
400    /// Set the output as high.
401    #[inline]
402    pub fn set_high(&mut self) {
403        self.pin.set_high()
404    }
405
406    /// Set the output as low.
407    #[inline]
408    pub fn set_low(&mut self) {
409        self.pin.set_low()
410    }
411
412    /// Toggle the output level.
413    #[inline]
414    pub fn toggle(&mut self) {
415        if self.is_set_low() {
416            self.set_high()
417        } else {
418            self.set_low()
419        }
420    }
421
422    /// Set the output level.
423    #[inline]
424    pub fn set_level(&mut self, level: Level) {
425        match level {
426            Level::Low => self.pin.set_low(),
427            Level::High => self.pin.set_high(),
428        }
429    }
430
431    /// Get whether the output level is set to high.
432    #[inline]
433    pub fn is_set_high(&self) -> bool {
434        self.pin.block().out().read().pin(self.pin.pin() as _)
435    }
436
437    /// Get whether the output level is set to low.
438    #[inline]
439    pub fn is_set_low(&self) -> bool {
440        !self.is_set_high()
441    }
442
443    /// Get the current output level.
444    #[inline]
445    pub fn get_output_level(&self) -> Level {
446        self.is_set_high().into()
447    }
448}
449
450impl<'d> Drop for Flex<'d> {
451    fn drop(&mut self) {
452        self.set_as_disconnected();
453    }
454}
455
456pub(crate) trait SealedPin {
457    fn pin_port(&self) -> u8;
458
459    #[inline]
460    fn _pin(&self) -> u8 {
461        cfg_if! {
462            if #[cfg(feature = "_gpio-p1")] {
463                self.pin_port() % 32
464            } else {
465                self.pin_port()
466            }
467        }
468    }
469
470    #[inline]
471    fn block(&self) -> gpio::Gpio {
472        match self.pin_port() / 32 {
473            #[cfg(feature = "_nrf51")]
474            0 => pac::GPIO,
475            #[cfg(not(feature = "_nrf51"))]
476            0 => pac::P0,
477            #[cfg(feature = "_gpio-p1")]
478            1 => pac::P1,
479            #[cfg(feature = "_gpio-p2")]
480            2 => pac::P2,
481            _ => unsafe { unreachable_unchecked() },
482        }
483    }
484
485    #[inline]
486    fn conf(&self) -> Reg<gpio::regs::PinCnf, RW> {
487        self.block().pin_cnf(self._pin() as usize)
488    }
489
490    /// Set the output as high.
491    #[inline]
492    fn set_high(&self) {
493        self.block().outset().write(|w| w.set_pin(self._pin() as _, true))
494    }
495
496    /// Set the output as low.
497    #[inline]
498    fn set_low(&self) {
499        self.block().outclr().write(|w| w.set_pin(self._pin() as _, true))
500    }
501}
502
503/// Interface for a Pin that can be configured by an [Input] or [Output] driver, or converted to an [AnyPin].
504#[allow(private_bounds)]
505pub trait Pin: PeripheralType + Into<AnyPin> + SealedPin + Sized + 'static {
506    /// Number of the pin within the port (0..31)
507    #[inline]
508    fn pin(&self) -> u8 {
509        self._pin()
510    }
511
512    /// Port of the pin
513    #[inline]
514    fn port(&self) -> Port {
515        match self.pin_port() / 32 {
516            0 => Port::Port0,
517            #[cfg(feature = "_gpio-p1")]
518            1 => Port::Port1,
519            #[cfg(feature = "_gpio-p2")]
520            2 => Port::Port2,
521            _ => unsafe { unreachable_unchecked() },
522        }
523    }
524
525    /// Peripheral port register value
526    #[inline]
527    #[cfg(not(feature = "_nrf51"))]
528    fn psel_bits(&self) -> pac::shared::regs::Psel {
529        pac::shared::regs::Psel(self.pin_port() as u32)
530    }
531}
532
533/// Type-erased GPIO pin
534pub struct AnyPin {
535    pub(crate) pin_port: u8,
536}
537
538impl AnyPin {
539    /// Create an [AnyPin] for a specific pin.
540    ///
541    /// # Safety
542    /// - `pin_port` should not in use by another driver.
543    #[inline]
544    pub unsafe fn steal(pin_port: u8) -> Peri<'static, Self> {
545        Peri::new_unchecked(Self { pin_port })
546    }
547}
548
549impl_peripheral!(AnyPin);
550impl Pin for AnyPin {}
551impl SealedPin for AnyPin {
552    #[inline]
553    fn pin_port(&self) -> u8 {
554        self.pin_port
555    }
556}
557
558// ====================
559
560#[cfg(not(feature = "_nrf51"))]
561#[cfg_attr(feature = "_nrf54l", allow(unused))] // TODO
562pub(crate) trait PselBits {
563    fn psel_bits(&self) -> pac::shared::regs::Psel;
564}
565
566#[cfg(not(feature = "_nrf51"))]
567impl<'a, P: Pin> PselBits for Option<Peri<'a, P>> {
568    #[inline]
569    fn psel_bits(&self) -> pac::shared::regs::Psel {
570        match self {
571            Some(pin) => pin.psel_bits(),
572            None => DISCONNECTED,
573        }
574    }
575}
576
577#[cfg(not(feature = "_nrf51"))]
578#[cfg_attr(feature = "_nrf54l", allow(unused))] // TODO
579pub(crate) const DISCONNECTED: Psel = Psel(1 << 31);
580
581#[cfg(not(feature = "_nrf51"))]
582#[allow(dead_code)]
583pub(crate) fn deconfigure_pin(psel: Psel) {
584    if psel.connect() == Connect::DISCONNECTED {
585        return;
586    }
587    unsafe { AnyPin::steal(psel.0 as _) }.conf().write(|w| {
588        w.set_input(vals::Input::DISCONNECT);
589    })
590}
591
592// ====================
593
594macro_rules! impl_pin {
595    ($type:ident, $port_num:expr, $pin_num:expr) => {
596        impl crate::gpio::Pin for peripherals::$type {}
597        impl crate::gpio::SealedPin for peripherals::$type {
598            #[inline]
599            fn pin_port(&self) -> u8 {
600                $port_num * 32 + $pin_num
601            }
602        }
603
604        impl From<peripherals::$type> for crate::gpio::AnyPin {
605            fn from(_val: peripherals::$type) -> Self {
606                Self {
607                    pin_port: $port_num * 32 + $pin_num,
608                }
609            }
610        }
611    };
612}
613
614// ====================
615
616mod eh02 {
617    use super::*;
618
619    impl<'d> embedded_hal_02::digital::v2::InputPin for Input<'d> {
620        type Error = Infallible;
621
622        fn is_high(&self) -> Result<bool, Self::Error> {
623            Ok(self.is_high())
624        }
625
626        fn is_low(&self) -> Result<bool, Self::Error> {
627            Ok(self.is_low())
628        }
629    }
630
631    impl<'d> embedded_hal_02::digital::v2::OutputPin for Output<'d> {
632        type Error = Infallible;
633
634        fn set_high(&mut self) -> Result<(), Self::Error> {
635            self.set_high();
636            Ok(())
637        }
638
639        fn set_low(&mut self) -> Result<(), Self::Error> {
640            self.set_low();
641            Ok(())
642        }
643    }
644
645    impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d> {
646        fn is_set_high(&self) -> Result<bool, Self::Error> {
647            Ok(self.is_set_high())
648        }
649
650        fn is_set_low(&self) -> Result<bool, Self::Error> {
651            Ok(self.is_set_low())
652        }
653    }
654
655    impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d> {
656        type Error = Infallible;
657        #[inline]
658        fn toggle(&mut self) -> Result<(), Self::Error> {
659            self.toggle();
660            Ok(())
661        }
662    }
663
664    /// Implement [`embedded_hal_02::digital::v2::InputPin`] for [`Flex`];
665    ///
666    /// If the pin is not in input mode the result is unspecified.
667    impl<'d> embedded_hal_02::digital::v2::InputPin for Flex<'d> {
668        type Error = Infallible;
669
670        fn is_high(&self) -> Result<bool, Self::Error> {
671            Ok(self.is_high())
672        }
673
674        fn is_low(&self) -> Result<bool, Self::Error> {
675            Ok(self.is_low())
676        }
677    }
678
679    impl<'d> embedded_hal_02::digital::v2::OutputPin for Flex<'d> {
680        type Error = Infallible;
681
682        fn set_high(&mut self) -> Result<(), Self::Error> {
683            self.set_high();
684            Ok(())
685        }
686
687        fn set_low(&mut self) -> Result<(), Self::Error> {
688            self.set_low();
689            Ok(())
690        }
691    }
692
693    impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d> {
694        fn is_set_high(&self) -> Result<bool, Self::Error> {
695            Ok(self.is_set_high())
696        }
697
698        fn is_set_low(&self) -> Result<bool, Self::Error> {
699            Ok(self.is_set_low())
700        }
701    }
702
703    impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d> {
704        type Error = Infallible;
705        #[inline]
706        fn toggle(&mut self) -> Result<(), Self::Error> {
707            self.toggle();
708            Ok(())
709        }
710    }
711}
712
713impl<'d> embedded_hal_1::digital::ErrorType for Input<'d> {
714    type Error = Infallible;
715}
716
717impl<'d> embedded_hal_1::digital::InputPin for Input<'d> {
718    fn is_high(&mut self) -> Result<bool, Self::Error> {
719        Ok((*self).is_high())
720    }
721
722    fn is_low(&mut self) -> Result<bool, Self::Error> {
723        Ok((*self).is_low())
724    }
725}
726
727impl<'d> embedded_hal_1::digital::ErrorType for Output<'d> {
728    type Error = Infallible;
729}
730
731impl<'d> embedded_hal_1::digital::OutputPin for Output<'d> {
732    fn set_high(&mut self) -> Result<(), Self::Error> {
733        self.set_high();
734        Ok(())
735    }
736
737    fn set_low(&mut self) -> Result<(), Self::Error> {
738        self.set_low();
739        Ok(())
740    }
741}
742
743impl<'d> embedded_hal_1::digital::StatefulOutputPin for Output<'d> {
744    fn is_set_high(&mut self) -> Result<bool, Self::Error> {
745        Ok((*self).is_set_high())
746    }
747
748    fn is_set_low(&mut self) -> Result<bool, Self::Error> {
749        Ok((*self).is_set_low())
750    }
751}
752
753impl<'d> embedded_hal_1::digital::ErrorType for Flex<'d> {
754    type Error = Infallible;
755}
756
757/// Implement [`InputPin`] for [`Flex`];
758///
759/// If the pin is not in input mode the result is unspecified.
760impl<'d> embedded_hal_1::digital::InputPin for Flex<'d> {
761    fn is_high(&mut self) -> Result<bool, Self::Error> {
762        Ok((*self).is_high())
763    }
764
765    fn is_low(&mut self) -> Result<bool, Self::Error> {
766        Ok((*self).is_low())
767    }
768}
769
770impl<'d> embedded_hal_1::digital::OutputPin for Flex<'d> {
771    fn set_high(&mut self) -> Result<(), Self::Error> {
772        self.set_high();
773        Ok(())
774    }
775
776    fn set_low(&mut self) -> Result<(), Self::Error> {
777        self.set_low();
778        Ok(())
779    }
780}
781
782impl<'d> embedded_hal_1::digital::StatefulOutputPin for Flex<'d> {
783    fn is_set_high(&mut self) -> Result<bool, Self::Error> {
784        Ok((*self).is_set_high())
785    }
786
787    fn is_set_low(&mut self) -> Result<bool, Self::Error> {
788        Ok((*self).is_set_low())
789    }
790}