@@ -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( u32 ) ]
70
+ #[ repr( u16 ) ]
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( u32 ) ]
93
+ #[ repr( u16 ) ]
94
94
pub enum Flag {
95
95
/// Receive buffer not empty
96
96
RxNotEmpty = 1 << 0 ,
@@ -127,14 +127,30 @@ pub const TransferModeBidi: bool = true;
127
127
128
128
pub trait FrameSize : Copy + Default {
129
129
const DFF : bool ;
130
+ #[ doc( hidden) ]
131
+ fn read_data ( spi : & spi1:: RegisterBlock ) -> Self ;
132
+ #[ doc( hidden) ]
133
+ fn write_data ( self , spi : & spi1:: RegisterBlock ) ;
130
134
}
131
135
132
136
impl FrameSize for u8 {
133
137
const DFF : bool = false ;
138
+ fn read_data ( spi : & spi1:: RegisterBlock ) -> Self {
139
+ spi. dr8 ( ) . read ( ) . dr ( ) . bits ( )
140
+ }
141
+ fn write_data ( self , spi : & spi1:: RegisterBlock ) {
142
+ spi. dr8 ( ) . write ( |w| w. dr ( ) . set ( self ) )
143
+ }
134
144
}
135
145
136
146
impl FrameSize for u16 {
137
147
const DFF : bool = true ;
148
+ fn read_data ( spi : & spi1:: RegisterBlock ) -> Self {
149
+ spi. dr ( ) . read ( ) . dr ( ) . bits ( )
150
+ }
151
+ fn write_data ( self , spi : & spi1:: RegisterBlock ) {
152
+ spi. dr ( ) . write ( |w| w. dr ( ) . set ( self ) )
153
+ }
138
154
}
139
155
140
156
/// The bit format to send the data in
@@ -747,16 +763,11 @@ impl<SPI: Instance> Inner<SPI> {
747
763
}
748
764
749
765
fn read_data_reg < W : FrameSize > ( & mut self ) -> W {
750
- // NOTE(read_volatile) read only 1 byte (the svd2rust API only allows
751
- // reading a half-word)
752
- unsafe { ( * ( self . spi . dr ( ) as * const pac:: spi1:: DR ) . cast :: < vcell:: VolatileCell < W > > ( ) ) . get ( ) }
766
+ W :: read_data ( & self . spi )
753
767
}
754
768
755
769
fn write_data_reg < W : FrameSize > ( & mut self , data : W ) {
756
- // NOTE(write_volatile) see note above
757
- unsafe {
758
- ( * ( self . spi . dr ( ) as * const pac:: spi1:: DR ) . cast :: < vcell:: VolatileCell < W > > ( ) ) . set ( data)
759
- }
770
+ data. write_data ( & self . spi )
760
771
}
761
772
762
773
#[ inline( always) ]
0 commit comments