@@ -596,6 +596,14 @@ impl Config {
596
596
fn raw_clock_reg_value ( & self ) -> Result < u32 , ConfigError > {
597
597
self . reg
598
598
}
599
+
600
+ fn validate ( & self ) -> Result < ( ) , ConfigError > {
601
+ // Max supported frequency is 80Mhz
602
+ if self . frequency > HertzU32 :: MHz ( 80 ) {
603
+ return Err ( ConfigError :: UnsupportedFrequency ) ;
604
+ }
605
+ Ok ( ( ) )
606
+ }
599
607
}
600
608
601
609
#[ derive( Debug ) ]
@@ -613,7 +621,22 @@ struct SpiPinGuard {
613
621
#[ non_exhaustive]
614
622
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
615
623
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
616
- pub enum ConfigError { }
624
+ pub enum ConfigError {
625
+ /// The requested frequency is not supported.
626
+ UnsupportedFrequency ,
627
+ }
628
+
629
+ impl core:: error:: Error for ConfigError { }
630
+
631
+ impl core:: fmt:: Display for ConfigError {
632
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
633
+ match self {
634
+ ConfigError :: UnsupportedFrequency => {
635
+ write ! ( f, " The requested frequency is not supported" )
636
+ }
637
+ }
638
+ }
639
+ }
617
640
618
641
/// SPI peripheral driver
619
642
///
@@ -994,6 +1017,10 @@ where
994
1017
}
995
1018
996
1019
/// Change the bus configuration.
1020
+ ///
1021
+ /// # Errors.
1022
+ /// If frequency passed in config exceeds 80Mhz, a corresponding
1023
+ /// [`ConfigError`] variant will be returned.
997
1024
pub fn apply_config ( & mut self , config : & Config ) -> Result < ( ) , ConfigError > {
998
1025
self . driver ( ) . apply_config ( config)
999
1026
}
@@ -1565,6 +1592,10 @@ mod dma {
1565
1592
}
1566
1593
1567
1594
/// Change the bus configuration.
1595
+ ///
1596
+ /// # Errors.
1597
+ /// If frequency passed in config exceeds 80Mhz, a corresponding
1598
+ /// [`ConfigError`] variant will be returned.
1568
1599
#[ instability:: unstable]
1569
1600
pub fn apply_config ( & mut self , config : & Config ) -> Result < ( ) , ConfigError > {
1570
1601
self . driver ( ) . apply_config ( config)
@@ -2027,6 +2058,10 @@ mod dma {
2027
2058
}
2028
2059
2029
2060
/// Change the bus configuration.
2061
+ ///
2062
+ /// # Errors.
2063
+ /// If frequency passed in config exceeds 80Mhz, a corresponding
2064
+ /// [`ConfigError`] variant will be returned.
2030
2065
#[ instability:: unstable]
2031
2066
pub fn apply_config ( & mut self , config : & Config ) -> Result < ( ) , ConfigError > {
2032
2067
self . spi_dma . apply_config ( config)
@@ -3073,6 +3108,7 @@ impl Driver {
3073
3108
}
3074
3109
3075
3110
fn apply_config ( & self , config : & Config ) -> Result < ( ) , ConfigError > {
3111
+ config. validate ( ) ?;
3076
3112
self . ch_bus_freq ( config) ?;
3077
3113
self . set_bit_order ( config. read_bit_order , config. write_bit_order ) ;
3078
3114
self . set_data_mode ( config. mode ) ;
0 commit comments