@@ -689,12 +689,23 @@ where
689689 #[ rustfmt:: skip]
690690 pub fn channel_sequence ( & self , sequence : config:: Sequence ) -> Option < channel:: Id > {
691691 // Set the channel in the right sequence field
692- let index = channel % 4 ;
693- match channel {
694- 0 ..=3 => self . reg . sqr1 ( ) . read ( ) . sq ( index) . bits ( ) . try_into ( ) . ok ( ) ,
695- 4 ..=7 => self . reg . sqr2 ( ) . read ( ) . sq ( index) . bits ( ) . try_into ( ) . ok ( ) ,
696- 8 ..=11 => self . reg . sqr3 ( ) . read ( ) . sq ( index) . bits ( ) . try_into ( ) . ok ( ) ,
697- 12 .. => self . reg . sqr4 ( ) . read ( ) . sq ( index) . bits ( ) . try_into ( ) . ok ( ) ,
692+ match sequence {
693+ config:: Sequence :: One => self . reg . sqr1 ( ) . read ( ) . sq1 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
694+ config:: Sequence :: Two => self . reg . sqr1 ( ) . read ( ) . sq2 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
695+ config:: Sequence :: Three => self . reg . sqr1 ( ) . read ( ) . sq3 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
696+ config:: Sequence :: Four => self . reg . sqr1 ( ) . read ( ) . sq4 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
697+ config:: Sequence :: Five => self . reg . sqr2 ( ) . read ( ) . sq5 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
698+ config:: Sequence :: Six => self . reg . sqr2 ( ) . read ( ) . sq6 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
699+ config:: Sequence :: Seven => self . reg . sqr2 ( ) . read ( ) . sq7 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
700+ config:: Sequence :: Eight => self . reg . sqr2 ( ) . read ( ) . sq8 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
701+ config:: Sequence :: Nine => self . reg . sqr2 ( ) . read ( ) . sq9 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
702+ config:: Sequence :: Ten => self . reg . sqr3 ( ) . read ( ) . sq10 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
703+ config:: Sequence :: Eleven => self . reg . sqr3 ( ) . read ( ) . sq11 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
704+ config:: Sequence :: Twelve => self . reg . sqr3 ( ) . read ( ) . sq12 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
705+ config:: Sequence :: Thirteen => self . reg . sqr3 ( ) . read ( ) . sq13 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
706+ config:: Sequence :: Fourteen => self . reg . sqr3 ( ) . read ( ) . sq14 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
707+ config:: Sequence :: Fifteen => self . reg . sqr4 ( ) . read ( ) . sq15 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
708+ config:: Sequence :: Sixteen => self . reg . sqr4 ( ) . read ( ) . sq16 ( ) . bits ( ) . try_into ( ) . ok ( ) ,
698709 }
699710 }
700711
@@ -704,11 +715,32 @@ where
704715 where
705716 Pin : Channel < ADC , ID = channel:: Id > ,
706717 {
707- let channel = Pin :: channel ( ) as u8 ;
708- let index = channel % 10 ;
718+ let channel = Pin :: channel ( ) ;
719+ // Set the sample time for the channel
709720 match channel {
710- 0 ..=9 => self . reg . smpr1 ( ) . read ( ) . smp ( index) . variant ( ) . into ( ) ,
711- 10 .. => self . reg . smpr2 ( ) . read ( ) . smp ( index) . variant ( ) . into ( ) ,
721+ #[ cfg( feature = "gpio-f373" ) ]
722+ channel:: Id :: Zero => self . adc . smpr1 ( ) . read ( ) . smp0 ( ) . variant ( ) . into ( ) ,
723+ channel:: Id :: One => self . reg . smpr1 ( ) . read ( ) . smp1 ( ) . variant ( ) . into ( ) ,
724+ channel:: Id :: Two => self . reg . smpr1 ( ) . read ( ) . smp2 ( ) . variant ( ) . into ( ) ,
725+ channel:: Id :: Three => self . reg . smpr1 ( ) . read ( ) . smp3 ( ) . variant ( ) . into ( ) ,
726+ channel:: Id :: Four => self . reg . smpr1 ( ) . read ( ) . smp4 ( ) . variant ( ) . into ( ) ,
727+ channel:: Id :: Five => self . reg . smpr1 ( ) . read ( ) . smp5 ( ) . variant ( ) . into ( ) ,
728+ channel:: Id :: Six => self . reg . smpr1 ( ) . read ( ) . smp6 ( ) . variant ( ) . into ( ) ,
729+ channel:: Id :: Seven => self . reg . smpr1 ( ) . read ( ) . smp7 ( ) . variant ( ) . into ( ) ,
730+ channel:: Id :: Eight => self . reg . smpr1 ( ) . read ( ) . smp8 ( ) . variant ( ) . into ( ) ,
731+ channel:: Id :: Nine => self . reg . smpr1 ( ) . read ( ) . smp9 ( ) . variant ( ) . into ( ) ,
732+ channel:: Id :: Ten => self . reg . smpr2 ( ) . read ( ) . smp10 ( ) . variant ( ) . into ( ) ,
733+ channel:: Id :: Eleven => self . reg . smpr2 ( ) . read ( ) . smp11 ( ) . variant ( ) . into ( ) ,
734+ channel:: Id :: Twelve => self . reg . smpr2 ( ) . read ( ) . smp12 ( ) . variant ( ) . into ( ) ,
735+ channel:: Id :: Thirteen => self . reg . smpr2 ( ) . read ( ) . smp13 ( ) . variant ( ) . into ( ) ,
736+ channel:: Id :: Fourteen => self . reg . smpr2 ( ) . read ( ) . smp14 ( ) . variant ( ) . into ( ) ,
737+ channel:: Id :: Fifteen => self . reg . smpr2 ( ) . read ( ) . smp15 ( ) . variant ( ) . into ( ) ,
738+ channel:: Id :: Sixteen => self . reg . smpr2 ( ) . read ( ) . smp16 ( ) . variant ( ) . into ( ) ,
739+ channel:: Id :: Seventeen => self . reg . smpr2 ( ) . read ( ) . smp17 ( ) . variant ( ) . into ( ) ,
740+ channel:: Id :: Eighteen => self . reg . smpr2 ( ) . read ( ) . smp18 ( ) . variant ( ) . into ( ) ,
741+ // #[cfg(not(feature = "gpio-f373"))]
742+ // // SAFETY: We know, that channel IDs will not exceed 18, see [`crate::adc::channel`]
743+ // _ => unsafe { unreachable_unchecked() },
712744 }
713745 }
714746
@@ -999,12 +1031,23 @@ where
9991031 // Set the channel in the right sequence field
10001032 // SAFETY: the channel.into() implementation ensures that those are valid values
10011033 unsafe {
1002- let index = channel % 4 ;
1003- match channel {
1004- 0 ..=3 => self . reg . sqr1 ( ) . modify ( |_, w| w. sq ( index) . set ( channel. into ( ) ) ) ,
1005- 4 ..=7 => self . reg . sqr2 ( ) . modify ( |_, w| w. sq ( index) . set ( channel. into ( ) ) ) ,
1006- 8 ..=11 => self . reg . sqr3 ( ) . modify ( |_, w| w. sq ( index) . set ( channel. into ( ) ) ) ,
1007- 12 .. => self . reg . sqr4 ( ) . modify ( |_, w| w. sq ( index) . set ( channel. into ( ) ) ) ,
1034+ match sequence {
1035+ config:: Sequence :: One => self . reg . sqr1 ( ) . modify ( |_, w| w. sq1 ( ) . bits ( channel. into ( ) ) ) ,
1036+ config:: Sequence :: Two => self . reg . sqr1 ( ) . modify ( |_, w| w. sq2 ( ) . bits ( channel. into ( ) ) ) ,
1037+ config:: Sequence :: Three => self . reg . sqr1 ( ) . modify ( |_, w| w. sq3 ( ) . bits ( channel. into ( ) ) ) ,
1038+ config:: Sequence :: Four => self . reg . sqr1 ( ) . modify ( |_, w| w. sq4 ( ) . bits ( channel. into ( ) ) ) ,
1039+ config:: Sequence :: Five => self . reg . sqr2 ( ) . modify ( |_, w| w. sq5 ( ) . bits ( channel. into ( ) ) ) ,
1040+ config:: Sequence :: Six => self . reg . sqr2 ( ) . modify ( |_, w| w. sq6 ( ) . bits ( channel. into ( ) ) ) ,
1041+ config:: Sequence :: Seven => self . reg . sqr2 ( ) . modify ( |_, w| w. sq7 ( ) . bits ( channel. into ( ) ) ) ,
1042+ config:: Sequence :: Eight => self . reg . sqr2 ( ) . modify ( |_, w| w. sq8 ( ) . bits ( channel. into ( ) ) ) ,
1043+ config:: Sequence :: Nine => self . reg . sqr2 ( ) . modify ( |_, w| w. sq9 ( ) . bits ( channel. into ( ) ) ) ,
1044+ config:: Sequence :: Ten => self . reg . sqr3 ( ) . modify ( |_, w| w. sq10 ( ) . bits ( channel. into ( ) ) ) ,
1045+ config:: Sequence :: Eleven => self . reg . sqr3 ( ) . modify ( |_, w| w. sq11 ( ) . bits ( channel. into ( ) ) ) ,
1046+ config:: Sequence :: Twelve => self . reg . sqr3 ( ) . modify ( |_, w| w. sq12 ( ) . bits ( channel. into ( ) ) ) ,
1047+ config:: Sequence :: Thirteen => self . reg . sqr3 ( ) . modify ( |_, w| w. sq13 ( ) . bits ( channel. into ( ) ) ) ,
1048+ config:: Sequence :: Fourteen => self . reg . sqr3 ( ) . modify ( |_, w| w. sq14 ( ) . bits ( channel. into ( ) ) ) ,
1049+ config:: Sequence :: Fifteen => self . reg . sqr4 ( ) . modify ( |_, w| w. sq15 ( ) . bits ( channel. into ( ) ) ) ,
1050+ config:: Sequence :: Sixteen => self . reg . sqr4 ( ) . modify ( |_, w| w. sq16 ( ) . bits ( channel. into ( ) ) ) ,
10081051 } ;
10091052 }
10101053 }
@@ -1023,12 +1066,30 @@ where
10231066 Pin : Channel < ADC , ID = channel:: Id > ,
10241067 {
10251068 let channel = Pin :: channel ( ) ;
1026-
1027- let index = channel % 10 ;
10281069 // Set the sample time for the channel
10291070 match channel {
1030- 0 ..=9 => self . reg . smpr1 ( ) . modify ( |_, w| w. smp ( index) . variant ( sample_time. into ( ) ) ) ,
1031- 10 .. => self . reg . smpr2 ( ) . modify ( |_, w| w. smp ( index) . variant ( sample_time. into ( ) ) ) ,
1071+ #[ cfg( feature = "gpio-f373" ) ]
1072+ channel:: Id :: Zero => self . adc . smpr1 ( ) . modify ( |_, w| w. smp0 ( ) . variant ( sample_time. into ( ) ) ) ,
1073+ channel:: Id :: One => self . reg . smpr1 ( ) . modify ( |_, w| w. smp1 ( ) . variant ( sample_time. into ( ) ) ) ,
1074+ channel:: Id :: Two => self . reg . smpr1 ( ) . modify ( |_, w| w. smp2 ( ) . variant ( sample_time. into ( ) ) ) ,
1075+ channel:: Id :: Three => self . reg . smpr1 ( ) . modify ( |_, w| w. smp3 ( ) . variant ( sample_time. into ( ) ) ) ,
1076+ channel:: Id :: Four => self . reg . smpr1 ( ) . modify ( |_, w| w. smp4 ( ) . variant ( sample_time. into ( ) ) ) ,
1077+ channel:: Id :: Five => self . reg . smpr1 ( ) . modify ( |_, w| w. smp5 ( ) . variant ( sample_time. into ( ) ) ) ,
1078+ channel:: Id :: Six => self . reg . smpr1 ( ) . modify ( |_, w| w. smp6 ( ) . variant ( sample_time. into ( ) ) ) ,
1079+ channel:: Id :: Seven => self . reg . smpr1 ( ) . modify ( |_, w| w. smp7 ( ) . variant ( sample_time. into ( ) ) ) ,
1080+ channel:: Id :: Eight => self . reg . smpr1 ( ) . modify ( |_, w| w. smp8 ( ) . variant ( sample_time. into ( ) ) ) ,
1081+ channel:: Id :: Nine => self . reg . smpr1 ( ) . modify ( |_, w| w. smp9 ( ) . variant ( sample_time. into ( ) ) ) ,
1082+ channel:: Id :: Ten => self . reg . smpr2 ( ) . modify ( |_, w| w. smp10 ( ) . variant ( sample_time. into ( ) ) ) ,
1083+ channel:: Id :: Eleven => self . reg . smpr2 ( ) . modify ( |_, w| w. smp11 ( ) . variant ( sample_time. into ( ) ) ) ,
1084+ channel:: Id :: Twelve => self . reg . smpr2 ( ) . modify ( |_, w| w. smp12 ( ) . variant ( sample_time. into ( ) ) ) ,
1085+ channel:: Id :: Thirteen => self . reg . smpr2 ( ) . modify ( |_, w| w. smp13 ( ) . variant ( sample_time. into ( ) ) ) ,
1086+ channel:: Id :: Fourteen => self . reg . smpr2 ( ) . modify ( |_, w| w. smp14 ( ) . variant ( sample_time. into ( ) ) ) ,
1087+ channel:: Id :: Fifteen => self . reg . smpr2 ( ) . modify ( |_, w| w. smp15 ( ) . variant ( sample_time. into ( ) ) ) ,
1088+ channel:: Id :: Sixteen => self . reg . smpr2 ( ) . modify ( |_, w| w. smp16 ( ) . variant ( sample_time. into ( ) ) ) ,
1089+ channel:: Id :: Seventeen => self . reg . smpr2 ( ) . modify ( |_, w| w. smp17 ( ) . variant ( sample_time. into ( ) ) ) ,
1090+ channel:: Id :: Eighteen => self . reg . smpr2 ( ) . modify ( |_, w| w. smp18 ( ) . variant ( sample_time. into ( ) ) ) ,
1091+ // #[cfg(not(feature = "gpio-f373"))]
1092+ // _ => () // Make it a no-op for channels which are not available.
10321093 } ;
10331094 }
10341095
0 commit comments