@@ -4,7 +4,7 @@ use core::ops::{Deref, DerefMut};
44use crate :: dma:: traits:: { DMASet , PeriAddress } ;
55use crate :: dma:: { MemoryToPeripheral , PeripheralToMemory } ;
66use crate :: gpio:: { self , NoPin } ;
7- use crate :: { pac, ClearFlags , ReadFlags } ;
7+ use crate :: { pac, ReadFlags } ;
88
99/// Clock polarity
1010#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
@@ -67,7 +67,7 @@ pub type NoMosi = NoPin;
6767#[ enumflags2:: bitflags]
6868#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
6969#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
70- #[ repr( u8 ) ]
70+ #[ repr( u32 ) ]
7171pub enum Event {
7272 /// An error occurred.
7373 ///
@@ -90,7 +90,7 @@ pub enum Event {
9090#[ enumflags2:: bitflags]
9191#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
9292#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
93- #[ repr( u16 ) ]
93+ #[ repr( u32 ) ]
9494pub enum Flag {
9595 /// Receive buffer not empty
9696 RxNotEmpty = 1 << 0 ,
@@ -112,7 +112,7 @@ pub enum Flag {
112112#[ enumflags2:: bitflags]
113113#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
114114#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
115- #[ repr( u16 ) ]
115+ #[ repr( u32 ) ]
116116pub enum CFlag {
117117 /// CRC error flag
118118 CrcError = 1 << 4 ,
@@ -788,7 +788,7 @@ impl<SPI: Instance> Inner<SPI> {
788788 Error :: ModeFault . into ( )
789789 } else if flags. contains ( Flag :: CrcError ) {
790790 // Clear the CRCERR bit
791- self . clear_flags ( CFlag :: CrcError ) ;
791+ self . spi . sr . modify ( |_r , w| w . crcerr ( ) . clear_bit ( ) ) ;
792792 Error :: Crc . into ( )
793793 } else if flags. contains ( Flag :: TxEmpty ) {
794794 self . write_data_reg ( byte) ;
@@ -802,10 +802,10 @@ impl<SPI: Instance> Inner<SPI> {
802802 w. bits ( {
803803 let mut bits = r. bits ( ) ;
804804 if let Some ( d) = disable {
805- bits &= !( d. bits ( ) as u32 )
805+ bits &= !d. bits ( ) ;
806806 }
807807 if let Some ( e) = enable {
808- bits |= e. bits ( ) as u32 ;
808+ bits |= e. bits ( ) ;
809809 }
810810 bits
811811 } )
@@ -831,18 +831,19 @@ impl<SPI: Instance> crate::Listen for Inner<SPI> {
831831
832832impl < SPI : Instance > crate :: ClearFlags for Inner < SPI > {
833833 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+ }
839840 }
840841}
841842
842843impl < SPI : Instance > crate :: ReadFlags for Inner < SPI > {
843844 type Flag = Flag ;
844845 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 ( ) )
846847 }
847848}
848849
0 commit comments