1#![macro_use]
3use core::convert::Infallible;
4use core::future::Future;
5use core::pin::Pin as FuturePin;
6use core::task::{Context, Poll};
7
8use embassy_hal_internal::{impl_peripheral, into_ref, PeripheralRef};
9use embassy_sync::waitqueue::AtomicWaker;
10use hpsys::HpsysPin;
11
12use crate::interrupt::InterruptExt;
13use crate::{interrupt, peripherals, Peripheral};
14use crate::utils::BitIter64;
15
16#[cfg(any(feature = "sf32lb52x"))]
18pub(crate) const PA_PIN_COUNT: usize = 44;
19
20pub mod hpsys;
21
22static PA_WAKERS: [AtomicWaker; PA_PIN_COUNT] = [const { AtomicWaker::new() }; PA_PIN_COUNT];
23
24#[derive(Debug, Eq, PartialEq, Clone, Copy)]
26pub enum Level {
27 Low,
29 High,
31}
32
33impl From<bool> for Level {
34 fn from(val: bool) -> Self {
35 match val {
36 true => Self::High,
37 false => Self::Low,
38 }
39 }
40}
41
42impl From<Level> for bool {
43 fn from(level: Level) -> bool {
44 match level {
45 Level::Low => false,
46 Level::High => true,
47 }
48 }
49}
50
51impl core::ops::Not for Level {
52 type Output = Self;
53
54 fn not(self) -> Self::Output {
55 (!bool::from(self)).into()
56 }
57}
58
59#[derive(Debug, Clone, Copy, Eq, PartialEq)]
61pub enum Pull {
62 None,
64 Up,
66 Down,
68}
69
70#[derive(Debug, Eq, PartialEq)]
72pub enum Drive {
73 Drive0,
75 Drive1,
77 Drive2,
79 Drive3,
81}
82#[derive(Debug, Eq, PartialEq)]
84pub enum SlewRate {
85 Fast,
87 Slow,
89}
90
91pub struct Input<'d> {
93 pin: Flex<'d>,
94}
95
96impl<'d> Input<'d> {
97 #[inline]
99 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, pull: Pull) -> Self {
100 let mut pin = Flex::new(pin);
101 pin.set_pull(pull);
102 pin.set_as_input();
103
104 Self { pin }
105 }
106
107 #[inline]
109 pub fn set_schmitt(&mut self, enable: bool) {
110 self.pin.set_schmitt(enable)
111 }
112
113 #[inline]
115 pub fn is_high(&self) -> bool {
116 self.pin.is_high()
117 }
118
119 #[inline]
121 pub fn is_low(&self) -> bool {
122 self.pin.is_low()
123 }
124
125 #[inline]
127 pub fn get_level(&self) -> Level {
128 self.pin.get_level()
129 }
130
131 #[inline]
133 pub async fn wait_for_high(&mut self) {
134 self.pin.wait_for_high().await;
135 }
136
137 #[inline]
139 pub async fn wait_for_low(&mut self) {
140 self.pin.wait_for_low().await;
141 }
142
143 #[inline]
145 pub async fn wait_for_rising_edge(&mut self) {
146 self.pin.wait_for_rising_edge().await;
147 }
148
149 #[inline]
151 pub async fn wait_for_falling_edge(&mut self) {
152 self.pin.wait_for_falling_edge().await;
153 }
154
155 #[inline]
157 pub async fn wait_for_any_edge(&mut self) {
158 self.pin.wait_for_any_edge().await;
159 }
160}
161
162#[derive(Debug, Eq, PartialEq, Copy, Clone)]
164#[cfg_attr(feature = "defmt", derive(defmt::Format))]
165pub enum InterruptTrigger {
166 LevelLow,
168 LevelHigh,
170 EdgeLow,
172 EdgeHigh,
174 AnyEdge,
176}
177
178pub(crate) unsafe fn init(gpio1_it_priority: interrupt::Priority) {
179 unsafe {
180 interrupt::GPIO1.disable();
181 interrupt::GPIO1.set_priority(gpio1_it_priority);
182 interrupt::GPIO1.enable();
183 }
184 crate::rcc::enable::<peripherals::HPSYS_GPIO>();
185
186 }
190
191#[cfg(feature = "rt")]
192fn irq_handler<const N: usize>(wakers: &[AtomicWaker; N]) {
193 let gpio = crate::pac::HPSYS_GPIO;
194
195 let isr0 = gpio.isr0().read().0;
197 let isr1 = gpio.isr1().read().0;
198 let status = (isr1 as u64) << 32 | isr0 as u64;
202
203 if status == 0 {
204 return;
205 }
206
207 for pin_idx in BitIter64(status) {
208 let mut pin = HpsysPin::new(pin_idx);
209
210 pin.disable_interrupt();
213
214 pin.clear_interrupt();
216
217 wakers[pin_idx as usize].wake();
228 }
229}
230
231#[cfg(feature = "rt")]
232#[interrupt]
233fn GPIO1() {
234 irq_handler(&PA_WAKERS);
235}
236
237#[must_use = "futures do nothing unless you `.await` or poll them"]
238struct InputFuture<'d> {
239 pin: PeripheralRef<'d, AnyPin>,
240}
241
242impl<'d> InputFuture<'d> {
243 fn new(pin: PeripheralRef<'d, AnyPin>, trigger: InterruptTrigger) -> Self {
244 let mut hpsys_pin = HpsysPin::new(pin.pin_bank());
245 hpsys_pin.set_interrupt_trigger(trigger);
247 hpsys_pin.clear_interrupt();
249 hpsys_pin.enable_interrupt();
251
252 hpsys_pin.set_high();
254 Self { pin }
255 }
256}
257
258impl<'d> Drop for InputFuture<'d> {
259 fn drop(&mut self) {
260 }
266}
267
268impl<'d> Future for InputFuture<'d> {
269 type Output = ();
270
271 fn poll(self: FuturePin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
272 let pin_idx = self.pin.pin() as usize;
273 let hpsys_pin = HpsysPin::new(self.pin.pin_bank());
274
275 PA_WAKERS[pin_idx].register(cx.waker());
277
278 if hpsys_pin.is_interrupt_disabled() {
281 Poll::Ready(())
282 } else {
283 Poll::Pending
284 }
285 }
286}
287
288pub struct Output<'d> {
290 pin: Flex<'d>,
291}
292
293impl<'d> Output<'d> {
294 #[inline]
296 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level) -> Self {
297 let mut pin = Flex::new(pin);
298 pin.set_level(initial_output);
299
300 pin.set_as_output();
301 Self { pin }
302 }
303
304 #[inline]
306 pub fn set_drive_strength(&mut self, strength: Drive) {
307 self.pin.set_drive_strength(strength)
308 }
309
310 #[inline]
312 pub fn set_slew_rate(&mut self, slew_rate: SlewRate) {
313 self.pin.set_slew_rate(slew_rate)
314 }
315
316 #[inline]
318 pub fn set_high(&mut self) {
319 self.pin.set_high()
320 }
321
322 #[inline]
324 pub fn set_low(&mut self) {
325 self.pin.set_low()
326 }
327
328 #[inline]
330 pub fn set_level(&mut self, level: Level) {
331 self.pin.set_level(level)
332 }
333
334 #[inline]
336 pub fn is_set_high(&self) -> bool {
337 self.pin.is_set_high()
338 }
339
340 #[inline]
342 pub fn is_set_low(&self) -> bool {
343 self.pin.is_set_low()
344 }
345
346 #[inline]
348 pub fn get_output_level(&self) -> Level {
349 self.pin.get_output_level()
350 }
351
352 #[inline]
354 pub fn toggle(&mut self) {
355 self.pin.toggle()
356 }
357}
358
359pub struct OutputOpenDrain<'d> {
361 pin: Flex<'d>,
362}
363
364impl<'d> OutputOpenDrain<'d> {
365 #[inline]
367 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd, initial_output: Level) -> Self {
368 let mut pin = Flex::new(pin);
369 pin.set_low();
371
372 pin.set_as_output_od();
373
374 pin.set_level(initial_output);
375 Self { pin }
376 }
377
378 #[inline]
380 pub fn set_pullup(&mut self, enable: bool) {
381 if enable {
382 self.pin.set_pull(Pull::Up);
383 } else {
384 self.pin.set_pull(Pull::None);
385 }
386 }
387
388 #[inline]
390 pub fn set_drive_strength(&mut self, strength: Drive) {
391 self.pin.set_drive_strength(strength)
392 }
393
394 #[inline]
396 pub fn set_slew_rate(&mut self, slew_rate: SlewRate) {
397 self.pin.set_slew_rate(slew_rate)
398 }
399
400 #[inline]
402 pub fn set_high(&mut self) {
403 self.pin.set_as_input()
405 }
406
407 #[inline]
409 pub fn set_low(&mut self) {
410 self.pin.set_as_output()
412 }
413
414 #[inline]
416 pub fn set_level(&mut self, level: Level) {
417 match level {
418 Level::Low => self.set_low(),
419 Level::High => self.set_high(),
420 }
421 }
422
423 #[inline]
425 pub fn is_set_high(&self) -> bool {
426 !self.is_set_low()
427 }
428
429 #[inline]
431 pub fn is_set_low(&self) -> bool {
432 self.pin.is_set_as_output()
433 }
434
435 #[inline]
437 pub fn get_output_level(&self) -> Level {
438 self.is_set_high().into()
439 }
440
441 #[inline]
443 pub fn toggle(&mut self) {
444 self.pin.toggle()
445 }
446
447 #[inline]
449 pub fn is_high(&self) -> bool {
450 self.pin.is_high()
451 }
452
453 #[inline]
455 pub fn is_low(&self) -> bool {
456 self.pin.is_low()
457 }
458
459 #[inline]
461 pub fn get_level(&self) -> Level {
462 self.is_high().into()
463 }
464
465 #[inline]
467 pub async fn wait_for_high(&mut self) {
468 self.pin.wait_for_high().await;
469 }
470
471 #[inline]
473 pub async fn wait_for_low(&mut self) {
474 self.pin.wait_for_low().await;
475 }
476
477 #[inline]
479 pub async fn wait_for_rising_edge(&mut self) {
480 self.pin.wait_for_rising_edge().await;
481 }
482
483 #[inline]
485 pub async fn wait_for_falling_edge(&mut self) {
486 self.pin.wait_for_falling_edge().await;
487 }
488
489 #[inline]
491 pub async fn wait_for_any_edge(&mut self) {
492 self.pin.wait_for_any_edge().await;
493 }
494}
495
496pub struct Analog<'d> {
497 _pin: Flex<'d>,
498}
499
500impl<'d> Analog<'d> {
501 #[inline]
503 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self {
504 let mut pin = Flex::new(pin);
505 pin.set_as_analog();
506 Self { _pin: pin}
507 }
508}
509
510
511
512pub struct Flex<'d> {
518 pub(crate) pin: PeripheralRef<'d, AnyPin>,
519 inner: HpsysPin,
520}
521
522impl<'d> Flex<'d> {
523 pub fn new(pin: impl Peripheral<P = impl Pin> + 'd) -> Self {
525 into_ref!(pin);
526 let mut flex = Self {
527 inner: HpsysPin::new(pin.pin_bank()),
528 pin: pin.map_into(),
529 };
530 flex.disable_interrupt();
531 unsafe { flex.inner.set_fsel_unchecked(0) };
532 flex
533 }
534
535 pub fn new_without_init(pin: impl Peripheral<P = impl Pin> + 'd) -> Self {
536 into_ref!(pin);
537 Self {
538 inner: HpsysPin::new(pin.pin_bank()),
539 pin: pin.map_into(),
540 }
541 }
542
543 pub fn disable_interrupt(&mut self) {
544 self.inner.disable_interrupt();
545 self.inner.clear_interrupt();
546 }
547
548 pub fn set_as_output(&mut self) {
550 self.inner.set_as_output();
551 }
552
553 pub fn set_as_input(&mut self) {
555 self.inner.set_as_input();
556 }
557
558 pub fn set_as_output_od(&mut self) {
560 self.inner.set_as_output_od();
561 }
562
563 pub fn set_as_analog(&mut self) {
565 self.inner.set_as_analog();
566 }
567
568 pub fn is_set_as_output(&self) -> bool {
570 self.inner.is_set_as_output()
571 }
572
573 pub fn set_high(&mut self) {
575 self.inner.set_high();
576 }
577
578 pub fn set_low(&mut self) {
580 self.inner.set_low();
581 }
582
583 pub fn toggle(&mut self) {
585 self.inner.toggle();
586 }
587
588 pub fn get_output_level(&self) -> Level {
590 self.inner.get_output_level()
591 }
592
593 pub fn get_level(&self) -> Level {
595 self.inner.get_level()
596 }
597
598 pub fn set_level(&mut self, level: Level) {
600 self.inner.set_level(level)
601 }
602
603 pub fn is_high(&self) -> bool {
605 self.inner.is_high()
606 }
607
608 pub fn is_low(&self) -> bool {
610 self.inner.is_low()
611 }
612
613 pub fn is_set_high(&self) -> bool {
615 self.inner.is_set_high()
616 }
617
618 pub fn is_set_low(&self) -> bool {
620 self.inner.is_set_low()
621 }
622
623 pub fn set_pull(&mut self, pull: Pull) {
625 self.inner.set_pull(pull);
626 }
627
628 pub fn set_drive_strength(&mut self, drive: Drive) {
630 self.inner.set_drive_strength(drive);
631 }
632
633 pub fn set_slew_rate(&mut self, slew_rate: SlewRate) {
635 self.inner.set_slew_rate(slew_rate);
636 }
637
638 pub fn set_schmitt(&mut self, enable: bool) {
640 self.inner.set_schmitt(enable);
641 }
642
643 pub fn set_function(&mut self, fsel: u8, af_type: crate::gpio::AfType) {
645 self.inner.set_function(fsel, af_type);
646 }
647
648 #[inline]
650 pub async fn wait_for_high(&mut self) {
651 if self.is_high() {
652 return;
653 }
654 InputFuture::new(self.pin.reborrow(), InterruptTrigger::LevelHigh).await;
655 }
656
657 #[inline]
659 pub async fn wait_for_low(&mut self) {
660 if self.is_low() {
661 return;
662 }
663 InputFuture::new(self.pin.reborrow(), InterruptTrigger::LevelLow).await;
664 }
665
666 #[inline]
668 pub async fn wait_for_rising_edge(&mut self) {
669 InputFuture::new(self.pin.reborrow(), InterruptTrigger::EdgeHigh).await;
670 }
671
672 #[inline]
674 pub async fn wait_for_falling_edge(&mut self) {
675 InputFuture::new(self.pin.reborrow(), InterruptTrigger::EdgeLow).await;
676 }
677
678 #[inline]
680 pub async fn wait_for_any_edge(&mut self) {
681 InputFuture::new(self.pin.reborrow(), InterruptTrigger::AnyEdge).await;
682 }
683}
684
685impl<'d> Drop for Flex<'d> {
686 #[inline]
687 fn drop(&mut self) {
688 self.pin.set_as_disconnected();
690 }
691}
692
693pub struct AfType {
694 pub(crate) pull: Pull,
695}
696
697impl AfType {
698 pub(crate) fn new(pull: Pull) -> Self {
699 Self { pull }
700 }
701}
702
703pub(crate) trait SealedPin: Sized {
704 fn pin_bank(&self) -> u8;
705
706 #[inline]
707 fn _pin(&self) -> u8 {
708 self.pin_bank() & 0x7f
709 }
710
711 #[inline]
712 fn _bank(&self) -> u8 {
713 self.pin_bank() >> 7
714 }
715
716 #[inline]
727 fn set_as_disconnected(&self) {
728 let mut pin = HpsysPin::new(self.pin_bank());
729 pin.disable_interrupt();
730 pin.clear_interrupt();
731 pin.set_ipr(false, false);
732 unsafe { pin.set_fsel_unchecked(0) };
733 pin.set_drive_strength(Drive::Drive0);
735 pin.set_pull(Pull::None);
736 }
737
738 #[inline]
739 fn set_function(&self, fsel: u8, af_type: AfType) {
740 let mut pin = HpsysPin::new(self.pin_bank());
741 pin.set_function(fsel, af_type);
742 }
743}
744
745#[allow(private_bounds)]
747pub trait Pin: Peripheral<P = Self> + Into<AnyPin> + SealedPin + Sized + 'static {
748 fn degrade(self) -> AnyPin {
750 AnyPin {
751 pin_bank: self.pin_bank(),
752 }
753 }
754
755 #[inline]
757 fn pin(&self) -> u8 {
758 self._pin()
759 }
760
761 #[inline]
763 fn bank(&self) -> u8 {
764 self._bank()
765 }
766}
767
768pub struct AnyPin {
770 pin_bank: u8,
771}
772
773impl AnyPin {
774 pub unsafe fn steal(pin_bank: u8) -> Self {
780 Self { pin_bank }
781 }
782}
783
784impl_peripheral!(AnyPin);
785
786impl Pin for AnyPin {}
787impl SealedPin for AnyPin {
788 fn pin_bank(&self) -> u8 {
789 self.pin_bank
790 }
791}
792
793macro_rules! impl_pin {
796 ($name:ident, $bank:expr, $pin_num:expr) => {
797 impl Pin for peripherals::$name {}
798 impl SealedPin for peripherals::$name {
799 #[inline]
800 fn pin_bank(&self) -> u8 {
801 ($bank as u8) * 128 + $pin_num
802 }
803 }
804
805 impl From<peripherals::$name> for crate::gpio::AnyPin {
806 fn from(val: peripherals::$name) -> Self {
807 crate::gpio::Pin::degrade(val)
808 }
809 }
810 };
811}
812
813mod eh02 {
816 use super::*;
817
818 impl<'d> embedded_hal_02::digital::v2::InputPin for Input<'d> {
819 type Error = Infallible;
820
821 fn is_high(&self) -> Result<bool, Self::Error> {
822 Ok(self.is_high())
823 }
824
825 fn is_low(&self) -> Result<bool, Self::Error> {
826 Ok(self.is_low())
827 }
828 }
829
830 impl<'d> embedded_hal_02::digital::v2::OutputPin for Output<'d> {
831 type Error = Infallible;
832
833 fn set_high(&mut self) -> Result<(), Self::Error> {
834 Ok(self.set_high())
835 }
836
837 fn set_low(&mut self) -> Result<(), Self::Error> {
838 Ok(self.set_low())
839 }
840 }
841
842 impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d> {
843 fn is_set_high(&self) -> Result<bool, Self::Error> {
844 Ok(self.is_set_high())
845 }
846
847 fn is_set_low(&self) -> Result<bool, Self::Error> {
848 Ok(self.is_set_low())
849 }
850 }
851
852 impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d> {
853 type Error = Infallible;
854 #[inline]
855 fn toggle(&mut self) -> Result<(), Self::Error> {
856 Ok(self.toggle())
857 }
858 }
859
860 impl<'d> embedded_hal_02::digital::v2::InputPin for OutputOpenDrain<'d> {
861 type Error = Infallible;
862
863 fn is_high(&self) -> Result<bool, Self::Error> {
864 Ok(self.is_high())
865 }
866
867 fn is_low(&self) -> Result<bool, Self::Error> {
868 Ok(self.is_low())
869 }
870 }
871
872 impl<'d> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d> {
873 type Error = Infallible;
874
875 #[inline]
876 fn set_high(&mut self) -> Result<(), Self::Error> {
877 Ok(self.set_high())
878 }
879
880 #[inline]
881 fn set_low(&mut self) -> Result<(), Self::Error> {
882 Ok(self.set_low())
883 }
884 }
885
886 impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d> {
887 fn is_set_high(&self) -> Result<bool, Self::Error> {
888 Ok(self.is_set_high())
889 }
890
891 fn is_set_low(&self) -> Result<bool, Self::Error> {
892 Ok(self.is_set_low())
893 }
894 }
895
896 impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpenDrain<'d> {
897 type Error = Infallible;
898 #[inline]
899 fn toggle(&mut self) -> Result<(), Self::Error> {
900 Ok(self.toggle())
901 }
902 }
903
904 impl<'d> embedded_hal_02::digital::v2::InputPin for Flex<'d> {
905 type Error = Infallible;
906
907 fn is_high(&self) -> Result<bool, Self::Error> {
908 Ok(self.is_high())
909 }
910
911 fn is_low(&self) -> Result<bool, Self::Error> {
912 Ok(self.is_low())
913 }
914 }
915
916 impl<'d> embedded_hal_02::digital::v2::OutputPin for Flex<'d> {
917 type Error = Infallible;
918
919 fn set_high(&mut self) -> Result<(), Self::Error> {
920 Ok(self.set_high())
921 }
922
923 fn set_low(&mut self) -> Result<(), Self::Error> {
924 Ok(self.set_low())
925 }
926 }
927
928 impl<'d> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d> {
929 fn is_set_high(&self) -> Result<bool, Self::Error> {
930 Ok(self.is_set_high())
931 }
932
933 fn is_set_low(&self) -> Result<bool, Self::Error> {
934 Ok(self.is_set_low())
935 }
936 }
937
938 impl<'d> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d> {
939 type Error = Infallible;
940 #[inline]
941 fn toggle(&mut self) -> Result<(), Self::Error> {
942 Ok(self.toggle())
943 }
944 }
945}
946
947impl<'d> embedded_hal_1::digital::ErrorType for Input<'d> {
948 type Error = Infallible;
949}
950
951impl<'d> embedded_hal_1::digital::InputPin for Input<'d> {
952 fn is_high(&mut self) -> Result<bool, Self::Error> {
953 Ok((*self).is_high())
954 }
955
956 fn is_low(&mut self) -> Result<bool, Self::Error> {
957 Ok((*self).is_low())
958 }
959}
960
961impl<'d> embedded_hal_1::digital::ErrorType for Output<'d> {
962 type Error = Infallible;
963}
964
965impl<'d> embedded_hal_1::digital::OutputPin for Output<'d> {
966 fn set_high(&mut self) -> Result<(), Self::Error> {
967 Ok(self.set_high())
968 }
969
970 fn set_low(&mut self) -> Result<(), Self::Error> {
971 Ok(self.set_low())
972 }
973}
974
975impl<'d> embedded_hal_1::digital::StatefulOutputPin for Output<'d> {
976 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
977 Ok((*self).is_set_high())
978 }
979
980 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
981 Ok((*self).is_set_low())
982 }
983}
984
985impl<'d> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d> {
986 type Error = Infallible;
987}
988
989impl<'d> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d> {
990 fn set_high(&mut self) -> Result<(), Self::Error> {
991 Ok(self.set_high())
992 }
993
994 fn set_low(&mut self) -> Result<(), Self::Error> {
995 Ok(self.set_low())
996 }
997}
998
999impl<'d> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d> {
1000 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
1001 Ok((*self).is_set_high())
1002 }
1003
1004 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
1005 Ok((*self).is_set_low())
1006 }
1007}
1008
1009impl<'d> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d> {
1010 fn is_high(&mut self) -> Result<bool, Self::Error> {
1011 Ok((*self).is_high())
1012 }
1013
1014 fn is_low(&mut self) -> Result<bool, Self::Error> {
1015 Ok((*self).is_low())
1016 }
1017}
1018
1019impl<'d> embedded_hal_1::digital::ErrorType for Flex<'d> {
1020 type Error = Infallible;
1021}
1022
1023impl<'d> embedded_hal_1::digital::InputPin for Flex<'d> {
1024 fn is_high(&mut self) -> Result<bool, Self::Error> {
1025 Ok((*self).is_high())
1026 }
1027
1028 fn is_low(&mut self) -> Result<bool, Self::Error> {
1029 Ok((*self).is_low())
1030 }
1031}
1032
1033impl<'d> embedded_hal_1::digital::OutputPin for Flex<'d> {
1034 fn set_high(&mut self) -> Result<(), Self::Error> {
1035 Ok(self.set_high())
1036 }
1037
1038 fn set_low(&mut self) -> Result<(), Self::Error> {
1039 Ok(self.set_low())
1040 }
1041}
1042
1043impl<'d> embedded_hal_1::digital::StatefulOutputPin for Flex<'d> {
1044 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
1045 Ok((*self).is_set_high())
1046 }
1047
1048 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
1049 Ok((*self).is_set_low())
1050 }
1051}
1052
1053impl<'d> embedded_hal_async::digital::Wait for Flex<'d> {
1054 async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
1055 self.wait_for_high().await;
1056 Ok(())
1057 }
1058
1059 async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
1060 self.wait_for_low().await;
1061 Ok(())
1062 }
1063
1064 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
1065 self.wait_for_rising_edge().await;
1066 Ok(())
1067 }
1068
1069 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
1070 self.wait_for_falling_edge().await;
1071 Ok(())
1072 }
1073
1074 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
1075 self.wait_for_any_edge().await;
1076 Ok(())
1077 }
1078}
1079
1080impl<'d> embedded_hal_async::digital::Wait for Input<'d> {
1081 async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
1082 self.wait_for_high().await;
1083 Ok(())
1084 }
1085
1086 async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
1087 self.wait_for_low().await;
1088 Ok(())
1089 }
1090
1091 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
1092 self.wait_for_rising_edge().await;
1093 Ok(())
1094 }
1095
1096 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
1097 self.wait_for_falling_edge().await;
1098 Ok(())
1099 }
1100
1101 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
1102 self.wait_for_any_edge().await;
1103 Ok(())
1104 }
1105}
1106
1107impl<'d> embedded_hal_async::digital::Wait for OutputOpenDrain<'d> {
1108 async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
1109 self.wait_for_high().await;
1110 Ok(())
1111 }
1112
1113 async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
1114 self.wait_for_low().await;
1115 Ok(())
1116 }
1117
1118 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
1119 self.wait_for_rising_edge().await;
1120 Ok(())
1121 }
1122
1123 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
1124 self.wait_for_falling_edge().await;
1125 Ok(())
1126 }
1127
1128 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
1129 self.wait_for_any_edge().await;
1130 Ok(())
1131 }
1132}
1133