@@ -30,22 +30,18 @@ use crate::{debug, warn};
30
30
/// All the APIs take `&self` - mutability is handled using an inner `RefCell`.
31
31
pub struct SdCard < SPI , CS , DELAYER >
32
32
where
33
- SPI : embedded_hal:: blocking:: spi:: Transfer < u8 > + embedded_hal:: blocking:: spi:: Write < u8 > ,
34
- CS : embedded_hal:: digital:: v2:: OutputPin ,
35
- <SPI as embedded_hal:: blocking:: spi:: Transfer < u8 > >:: Error : core:: fmt:: Debug ,
36
- <SPI as embedded_hal:: blocking:: spi:: Write < u8 > >:: Error : core:: fmt:: Debug ,
37
- DELAYER : embedded_hal:: blocking:: delay:: DelayUs < u8 > ,
33
+ SPI : embedded_hal:: spi:: SpiDevice < u8 > ,
34
+ CS : embedded_hal:: digital:: OutputPin ,
35
+ DELAYER : embedded_hal:: delay:: DelayUs ,
38
36
{
39
37
inner : RefCell < SdCardInner < SPI , CS , DELAYER > > ,
40
38
}
41
39
42
40
impl < SPI , CS , DELAYER > SdCard < SPI , CS , DELAYER >
43
41
where
44
- SPI : embedded_hal:: blocking:: spi:: Transfer < u8 > + embedded_hal:: blocking:: spi:: Write < u8 > ,
45
- CS : embedded_hal:: digital:: v2:: OutputPin ,
46
- <SPI as embedded_hal:: blocking:: spi:: Transfer < u8 > >:: Error : core:: fmt:: Debug ,
47
- <SPI as embedded_hal:: blocking:: spi:: Write < u8 > >:: Error : core:: fmt:: Debug ,
48
- DELAYER : embedded_hal:: blocking:: delay:: DelayUs < u8 > ,
42
+ SPI : embedded_hal:: spi:: SpiDevice < u8 > + embedded_hal:: spi:: SpiDevice < u8 > ,
43
+ CS : embedded_hal:: digital:: OutputPin ,
44
+ DELAYER : embedded_hal:: delay:: DelayUs ,
49
45
{
50
46
/// Create a new SD/MMC Card driver using a raw SPI interface.
51
47
///
@@ -152,11 +148,9 @@ where
152
148
153
149
impl < SPI , CS , DELAYER > BlockDevice for SdCard < SPI , CS , DELAYER >
154
150
where
155
- SPI : embedded_hal:: blocking:: spi:: Transfer < u8 > + embedded_hal:: blocking:: spi:: Write < u8 > ,
156
- CS : embedded_hal:: digital:: v2:: OutputPin ,
157
- <SPI as embedded_hal:: blocking:: spi:: Transfer < u8 > >:: Error : core:: fmt:: Debug ,
158
- <SPI as embedded_hal:: blocking:: spi:: Write < u8 > >:: Error : core:: fmt:: Debug ,
159
- DELAYER : embedded_hal:: blocking:: delay:: DelayUs < u8 > ,
151
+ SPI : embedded_hal:: spi:: SpiDevice < u8 > + embedded_hal:: spi:: SpiDevice < u8 > ,
152
+ CS : embedded_hal:: digital:: OutputPin ,
153
+ DELAYER : embedded_hal:: delay:: DelayUs ,
160
154
{
161
155
type Error = Error ;
162
156
@@ -205,11 +199,9 @@ where
205
199
/// All the APIs required `&mut self`.
206
200
struct SdCardInner < SPI , CS , DELAYER >
207
201
where
208
- SPI : embedded_hal:: blocking:: spi:: Transfer < u8 > + embedded_hal:: blocking:: spi:: Write < u8 > ,
209
- CS : embedded_hal:: digital:: v2:: OutputPin ,
210
- <SPI as embedded_hal:: blocking:: spi:: Transfer < u8 > >:: Error : core:: fmt:: Debug ,
211
- <SPI as embedded_hal:: blocking:: spi:: Write < u8 > >:: Error : core:: fmt:: Debug ,
212
- DELAYER : embedded_hal:: blocking:: delay:: DelayUs < u8 > ,
202
+ SPI : embedded_hal:: spi:: SpiDevice < u8 > + embedded_hal:: spi:: SpiDevice < u8 > ,
203
+ CS : embedded_hal:: digital:: OutputPin ,
204
+ DELAYER : embedded_hal:: delay:: DelayUs ,
213
205
{
214
206
spi : SPI ,
215
207
cs : CS ,
@@ -220,11 +212,9 @@ where
220
212
221
213
impl < SPI , CS , DELAYER > SdCardInner < SPI , CS , DELAYER >
222
214
where
223
- SPI : embedded_hal:: blocking:: spi:: Transfer < u8 > + embedded_hal:: blocking:: spi:: Write < u8 > ,
224
- CS : embedded_hal:: digital:: v2:: OutputPin ,
225
- <SPI as embedded_hal:: blocking:: spi:: Transfer < u8 > >:: Error : core:: fmt:: Debug ,
226
- <SPI as embedded_hal:: blocking:: spi:: Write < u8 > >:: Error : core:: fmt:: Debug ,
227
- DELAYER : embedded_hal:: blocking:: delay:: DelayUs < u8 > ,
215
+ SPI : embedded_hal:: spi:: SpiDevice < u8 > + embedded_hal:: spi:: SpiDevice < u8 > ,
216
+ CS : embedded_hal:: digital:: OutputPin ,
217
+ DELAYER : embedded_hal:: delay:: DelayUs ,
228
218
{
229
219
/// Read one or more blocks, starting at the given block index.
230
220
fn read ( & mut self , blocks : & mut [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Error > {
@@ -583,21 +573,22 @@ where
583
573
584
574
/// Send one byte and receive one byte over the SPI bus.
585
575
fn transfer_byte ( & mut self , out : u8 ) -> Result < u8 , Error > {
576
+ let mut read_buf = [ 0u8 ; 1 ] ;
586
577
self . spi
587
- . transfer ( & mut [ out] )
588
- . map ( |b| b [ 0 ] )
589
- . map_err ( |_e| Error :: Transport )
578
+ . transfer ( & mut read_buf , & [ out] )
579
+ . map_err ( |_| Error :: Transport ) ? ;
580
+ Ok ( read_buf [ 0 ] )
590
581
}
591
582
592
- /// Send mutiple bytes and ignore what comes back over the SPI bus.
583
+ /// Send multiple bytes and ignore what comes back over the SPI bus.
593
584
fn write_bytes ( & mut self , out : & [ u8 ] ) -> Result < ( ) , Error > {
594
585
self . spi . write ( out) . map_err ( |_e| Error :: Transport ) ?;
595
586
Ok ( ( ) )
596
587
}
597
588
598
589
/// Send multiple bytes and replace them with what comes back over the SPI bus.
599
590
fn transfer_bytes ( & mut self , in_out : & mut [ u8 ] ) -> Result < ( ) , Error > {
600
- self . spi . transfer ( in_out) . map_err ( |_e| Error :: Transport ) ?;
591
+ self . spi . transfer_in_place ( in_out) . map_err ( |_e| Error :: Transport ) ?;
601
592
Ok ( ( ) )
602
593
}
603
594
@@ -753,7 +744,7 @@ impl Delay {
753
744
/// `Ok(())`.
754
745
fn delay < T > ( & mut self , delayer : & mut T , err : Error ) -> Result < ( ) , Error >
755
746
where
756
- T : embedded_hal:: blocking :: delay:: DelayUs < u8 > ,
747
+ T : embedded_hal:: delay:: DelayUs ,
757
748
{
758
749
if self . retries_left == 0 {
759
750
Err ( err)
0 commit comments