@@ -19,6 +19,9 @@ pub trait SdCardDevice {
19
19
operations : & mut [ Operation < ' _ , u8 > ] ,
20
20
) -> Result < ( ) , SdCardDeviceError > ;
21
21
22
+ /// Send 80 clock pulses to the device with CS deasserted.
23
+ fn send_clock_pulses ( & mut self ) -> Result < ( ) , SdCardDeviceError > ;
24
+
22
25
/// Do a read within a transaction.
23
26
///
24
27
/// This is a convenience method equivalent to `device.transaction(&mut [Operation::Read(buf)])`.
84
87
let mut bus = bus. borrow_mut ( ) ;
85
88
bus_transaction ( & mut * bus, cs, operations)
86
89
}
90
+
91
+ fn send_clock_pulses ( & mut self ) -> Result < ( ) , SdCardDeviceError > {
92
+ let ( bus, cs) = self ;
93
+ let mut bus = bus. borrow_mut ( ) ;
94
+ send_clock_pulses ( & mut * bus, cs)
95
+ }
87
96
}
88
97
89
98
#[ cfg( feature = "embassy-sync-06" ) ]
@@ -103,6 +112,14 @@ where
103
112
bus_transaction ( & mut * bus, cs, operations)
104
113
} )
105
114
}
115
+
116
+ fn send_clock_pulses ( & mut self ) -> Result < ( ) , SdCardDeviceError > {
117
+ let ( bus, cs) = self ;
118
+ bus. lock ( |bus| {
119
+ let mut bus = bus. borrow_mut ( ) ;
120
+ send_clock_pulses ( & mut * bus, cs)
121
+ } )
122
+ }
106
123
}
107
124
108
125
// `ExclusiveDevice` represents exclusive access to the bus so there's no need to send the dummy
@@ -121,6 +138,21 @@ where
121
138
<Self as embedded_hal:: spi:: SpiDevice >:: transaction ( self , operations)
122
139
. map_err ( |_| SdCardDeviceError :: Spi )
123
140
}
141
+
142
+ fn send_clock_pulses ( & mut self ) -> Result < ( ) , SdCardDeviceError > {
143
+ let bus = self . bus_mut ( ) ;
144
+
145
+ // There's no way to access the CS pin here so we can't set it high. Most like it already high so this is probbaly fine(?)
146
+
147
+ let send_res = bus. write ( & [ 0xFF ; 10 ] ) ;
148
+
149
+ // On failure, it's important to still flush.
150
+ let flush_res = bus. flush ( ) . map_err ( |_| SdCardDeviceError :: Spi ) ;
151
+
152
+ send_res. map_err ( |_| SdCardDeviceError :: Spi ) ?;
153
+ flush_res. map_err ( |_| SdCardDeviceError :: Spi ) ?;
154
+ Ok ( ( ) )
155
+ }
124
156
}
125
157
126
158
fn bus_transaction < BUS , CS > (
@@ -162,3 +194,20 @@ where
162
194
163
195
Ok ( ( ) )
164
196
}
197
+
198
+ fn send_clock_pulses < BUS , CS > ( bus : & mut BUS , cs : & mut CS ) -> Result < ( ) , SdCardDeviceError >
199
+ where
200
+ BUS : SpiBus ,
201
+ CS : OutputPin ,
202
+ {
203
+ cs. set_high ( ) . map_err ( |_| SdCardDeviceError :: Cs ) ?;
204
+ let send_res = bus. write ( & [ 0xFF ; 10 ] ) ;
205
+
206
+ // On failure, it's important to still flush.
207
+ let flush_res = bus. flush ( ) . map_err ( |_| SdCardDeviceError :: Spi ) ;
208
+
209
+ send_res. map_err ( |_| SdCardDeviceError :: Spi ) ?;
210
+ flush_res. map_err ( |_| SdCardDeviceError :: Spi ) ?;
211
+
212
+ Ok ( ( ) )
213
+ }
0 commit comments