@@ -18,9 +18,10 @@ use as_slice::{
18
18
use crate :: hal:: blocking:: i2c:: { Read , Write , WriteRead } ;
19
19
20
20
#[ cfg( feature = "stm32l0x2" ) ]
21
- use crate :: dma;
22
- #[ cfg( feature = "stm32l0x2" ) ]
23
- use crate :: dma:: Buffer ;
21
+ use crate :: dma:: {
22
+ self ,
23
+ Buffer
24
+ } ;
24
25
use crate :: gpio:: gpioa:: { PA10 , PA9 } ;
25
26
use crate :: gpio:: gpiob:: { PB6 , PB7 } ;
26
27
use crate :: gpio:: { AltMode , OpenDrain , Output } ;
@@ -209,7 +210,7 @@ where
209
210
}
210
211
211
212
#[ cfg( feature = "stm32l0x2" ) ]
212
- pub fn write_all < Channel , Buffer > ( mut self ,
213
+ pub fn write_all < Channel , Buffer > ( self ,
213
214
dma : & mut dma:: Handle ,
214
215
channel : Channel ,
215
216
address : u8 ,
@@ -222,44 +223,8 @@ where
222
223
Buffer : Deref + ' static ,
223
224
Buffer :: Target : AsSlice < Element =u8 > ,
224
225
{
225
- self . start_transfer ( address, buffer. as_slice ( ) . len ( ) , RD_WRNW :: WRITE ) ;
226
-
227
- // This token represents the transmission capability of I2C and this is
228
- // what the `dma::Target` trait is implemented for. It can't be
229
- // implemented for `I2c` itself, as that would allow for the user to
230
- // pass, for example, a channel that can do I2C RX to `write_all`.
231
- //
232
- // Theoretically, one could create both `Rx` and `Tx` at the same time,
233
- // or create multiple tokens of the same type, and use that to create
234
- // multiple simultaneous DMA transfers, which would be wrong and is not
235
- // supported by the I2C peripheral. We prevent that by only ever
236
- // creating an `Rx` or `Tx` token while we have ownership of `I2c`, and
237
- // dropping the token before returning ownership of `I2c` ot the user.
238
- let token = Tx ( PhantomData ) ;
239
-
240
- // Safe, because we're only taking the address of a register.
241
- let address = & unsafe { & * I :: ptr ( ) } . txdr as * const _ as u32 ;
242
-
243
226
let num_words = buffer. len ( ) ;
244
- // Safe, because the trait bounds of this method guarantee that the
245
- // buffer can be read from.
246
- let transfer = unsafe {
247
- dma:: Transfer :: new (
248
- dma,
249
- token,
250
- channel,
251
- buffer,
252
- num_words,
253
- address,
254
- dma:: Priority :: high ( ) ,
255
- dma:: Direction :: memory_to_peripheral ( ) ,
256
- )
257
- } ;
258
-
259
- Transfer {
260
- target : self ,
261
- inner : transfer,
262
- }
227
+ self . write_some ( dma, channel, address, buffer, num_words)
263
228
}
264
229
265
230
#[ cfg( feature = "stm32l0x2" ) ]
@@ -318,7 +283,7 @@ where
318
283
}
319
284
320
285
#[ cfg( feature = "stm32l0x2" ) ]
321
- pub fn read_all < Channel , Buffer > ( mut self ,
286
+ pub fn read_all < Channel , Buffer > ( self ,
322
287
dma : & mut dma:: Handle ,
323
288
channel : Channel ,
324
289
address : u8 ,
@@ -331,34 +296,8 @@ where
331
296
Buffer : DerefMut + ' static ,
332
297
Buffer :: Target : AsMutSlice < Element =u8 > ,
333
298
{
334
- self . start_transfer ( address, buffer. as_slice ( ) . len ( ) , RD_WRNW :: READ ) ;
335
-
336
- // See explanation of tokens in `write_all`.
337
- let token = Rx ( PhantomData ) ;
338
-
339
- // Safe, because we're only taking the address of a register.
340
- let address = & unsafe { & * I :: ptr ( ) } . rxdr as * const _ as u32 ;
341
-
342
299
let num_words = buffer. len ( ) ;
343
- // Safe, because the trait bounds of this method guarantee that the
344
- // buffer can be written to.
345
- let transfer = unsafe {
346
- dma:: Transfer :: new (
347
- dma,
348
- token,
349
- channel,
350
- buffer,
351
- num_words,
352
- address,
353
- dma:: Priority :: high ( ) ,
354
- dma:: Direction :: peripheral_to_memory ( ) ,
355
- )
356
- } ;
357
-
358
- Transfer {
359
- target : self ,
360
- inner : transfer,
361
- }
300
+ self . read_some ( dma, channel, address, buffer, num_words)
362
301
}
363
302
364
303
#[ cfg( feature = "stm32l0x2" ) ]
0 commit comments