@@ -152,6 +152,26 @@ pub enum Pcs {
152152 Pcs3 ,
153153}
154154
155+ /// The hardware chip select polarity.
156+ ///
157+ /// Use [`Disabled::set_chip_select_polarity`] to configure
158+ /// each chip select's polarity. Consult your peripheral's
159+ /// documentation to understand which polarity is expected.
160+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Default ) ]
161+ #[ repr( u32 ) ]
162+ pub enum PcsPolarity {
163+ /// The chip select is active low.
164+ ///
165+ /// When idle, the chip select is high. This is
166+ /// the default state.
167+ #[ default]
168+ ActiveLow ,
169+ /// The chip select is active high.
170+ ///
171+ /// When idle, the chip select is low.
172+ ActiveHigh ,
173+ }
174+
155175/// An LPSPI transaction definition.
156176///
157177/// The transaction defines how many bits the driver sends or recieves.
@@ -1214,6 +1234,21 @@ impl<'a, const N: u8> Disabled<'a, N> {
12141234 pub fn set_peripheral_enable ( & mut self , enable : bool ) {
12151235 ral:: modify_reg!( ral:: lpspi, self . lpspi, CFGR1 , MASTER : !enable as u32 ) ;
12161236 }
1237+
1238+ /// Set the polarity for the `pcs` hardware chip select.
1239+ ///
1240+ /// By default, all polarities are active low.
1241+ #[ inline]
1242+ pub fn set_chip_select_polarity ( & mut self , pcs : Pcs , polarity : PcsPolarity ) {
1243+ let pcspol = ral:: read_reg!( ral:: lpspi, self . lpspi, CFGR1 , PCSPOL ) ;
1244+ let mask = 1 << pcs as u32 ;
1245+ let pcspol = if polarity == PcsPolarity :: ActiveHigh {
1246+ pcspol | mask
1247+ } else {
1248+ pcspol & !mask
1249+ } ;
1250+ ral:: modify_reg!( ral:: lpspi, self . lpspi, CFGR1 , PCSPOL : pcspol) ;
1251+ }
12171252}
12181253
12191254impl < const N : u8 > Drop for Disabled < ' _ , N > {
0 commit comments