@@ -4,7 +4,7 @@ use core::ops::{Deref, DerefMut};
4
4
use crate :: dma:: traits:: { DMASet , PeriAddress } ;
5
5
use crate :: dma:: { MemoryToPeripheral , PeripheralToMemory } ;
6
6
use crate :: gpio:: { self , NoPin } ;
7
- use crate :: { pac, ClearFlags , ReadFlags } ;
7
+ use crate :: { pac, ReadFlags } ;
8
8
9
9
/// Clock polarity
10
10
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
@@ -67,7 +67,7 @@ pub type NoMosi = NoPin;
67
67
#[ enumflags2:: bitflags]
68
68
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
69
69
#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
70
- #[ repr( u8 ) ]
70
+ #[ repr( u32 ) ]
71
71
pub enum Event {
72
72
/// An error occurred.
73
73
///
@@ -90,7 +90,7 @@ pub enum Event {
90
90
#[ enumflags2:: bitflags]
91
91
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
92
92
#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
93
- #[ repr( u16 ) ]
93
+ #[ repr( u32 ) ]
94
94
pub enum Flag {
95
95
/// Receive buffer not empty
96
96
RxNotEmpty = 1 << 0 ,
@@ -112,7 +112,7 @@ pub enum Flag {
112
112
#[ enumflags2:: bitflags]
113
113
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
114
114
#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
115
- #[ repr( u16 ) ]
115
+ #[ repr( u32 ) ]
116
116
pub enum CFlag {
117
117
/// CRC error flag
118
118
CrcError = 1 << 4 ,
@@ -788,7 +788,7 @@ impl<SPI: Instance> Inner<SPI> {
788
788
Error :: ModeFault . into ( )
789
789
} else if flags. contains ( Flag :: CrcError ) {
790
790
// Clear the CRCERR bit
791
- self . clear_flags ( CFlag :: CrcError ) ;
791
+ self . spi . sr . modify ( |_r , w| w . crcerr ( ) . clear_bit ( ) ) ;
792
792
Error :: Crc . into ( )
793
793
} else if flags. contains ( Flag :: TxEmpty ) {
794
794
self . write_data_reg ( byte) ;
@@ -802,10 +802,10 @@ impl<SPI: Instance> Inner<SPI> {
802
802
w. bits ( {
803
803
let mut bits = r. bits ( ) ;
804
804
if let Some ( d) = disable {
805
- bits &= !( d. bits ( ) as u32 )
805
+ bits &= !d. bits ( ) ;
806
806
}
807
807
if let Some ( e) = enable {
808
- bits |= e. bits ( ) as u32 ;
808
+ bits |= e. bits ( ) ;
809
809
}
810
810
bits
811
811
} )
@@ -831,18 +831,19 @@ impl<SPI: Instance> crate::Listen for Inner<SPI> {
831
831
832
832
impl < SPI : Instance > crate :: ClearFlags for Inner < SPI > {
833
833
type Flag = CFlag ;
834
- fn clear_flags ( & mut self , event : impl Into < BitFlags < Self :: Flag > > ) {
835
- // TODO: check
836
- self . spi
837
- . sr
838
- . write ( |w| unsafe { w. bits ( 0xffff & !( event. into ( ) . bits ( ) as u32 ) ) } ) ;
834
+ fn clear_flags ( & mut self , flags : impl Into < BitFlags < Self :: Flag > > ) {
835
+ if flags. into ( ) . contains ( CFlag :: CrcError ) {
836
+ self . spi
837
+ . sr
838
+ . write ( |w| unsafe { w. bits ( 0xffff ) . crcerr ( ) . clear_bit ( ) } )
839
+ }
839
840
}
840
841
}
841
842
842
843
impl < SPI : Instance > crate :: ReadFlags for Inner < SPI > {
843
844
type Flag = Flag ;
844
845
fn flags ( & self ) -> BitFlags < Self :: Flag > {
845
- BitFlags :: from_bits_truncate ( self . spi . sr . read ( ) . bits ( ) as u16 )
846
+ BitFlags :: from_bits_truncate ( self . spi . sr . read ( ) . bits ( ) )
846
847
}
847
848
}
848
849
0 commit comments