@@ -223,61 +223,40 @@ where
223
223
type Error = Error < E > ;
224
224
}
225
225
226
- impl < Device , E > eh1:: spi:: SpiBusFlush for Spi < Device >
227
- where
228
- Device : MpsseCmdExecutor < Error = E > ,
229
- E : std:: error:: Error ,
230
- Error < E > : From < E > ,
231
- {
232
- fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
233
- Ok ( ( ) )
234
- }
235
- }
236
-
237
- impl < Device , E > eh1:: spi:: SpiBusWrite < u8 > for Spi < Device >
226
+ impl < Device , E > eh1:: spi:: SpiBus < u8 > for Spi < Device >
238
227
where
239
228
Device : MpsseCmdExecutor < Error = E > ,
240
229
E : std:: error:: Error ,
241
230
Error < E > : From < E > ,
242
231
{
243
- fn write ( & mut self , words : & [ u8 ] ) -> Result < ( ) , Error < E > > {
232
+ fn read ( & mut self , words : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
233
+ let data_out: Vec < u8 > = vec ! [ 0 ; words. len( ) ] ;
244
234
let cmd: MpsseCmdBuilder = MpsseCmdBuilder :: new ( )
245
- . clock_data_out ( self . pol . clk_out , words )
235
+ . clock_data ( self . pol . clk , & data_out )
246
236
. send_immediate ( ) ;
247
237
248
238
let mut lock = self . mtx . lock ( ) . expect ( "Failed to aquire FTDI mutex" ) ;
249
239
lock. ft . send ( cmd. as_slice ( ) ) ?;
240
+ lock. ft . recv ( words) ?;
250
241
251
242
Ok ( ( ) )
252
243
}
253
- }
254
244
255
- impl < Device , E > eh1:: spi:: SpiBusRead < u8 > for Spi < Device >
256
- where
257
- Device : MpsseCmdExecutor < Error = E > ,
258
- E : std:: error:: Error ,
259
- Error < E > : From < E > ,
260
- {
261
- fn read ( & mut self , words : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
262
- let data_out: Vec < u8 > = vec ! [ 0 ; words. len( ) ] ;
245
+ fn write ( & mut self , words : & [ u8 ] ) -> Result < ( ) , Error < E > > {
263
246
let cmd: MpsseCmdBuilder = MpsseCmdBuilder :: new ( )
264
- . clock_data ( self . pol . clk , & data_out )
247
+ . clock_data_out ( self . pol . clk_out , words )
265
248
. send_immediate ( ) ;
266
249
267
250
let mut lock = self . mtx . lock ( ) . expect ( "Failed to aquire FTDI mutex" ) ;
268
251
lock. ft . send ( cmd. as_slice ( ) ) ?;
269
- lock. ft . recv ( words) ?;
270
252
271
253
Ok ( ( ) )
272
254
}
273
- }
274
255
275
- impl < Device , E > eh1:: spi:: SpiBus < u8 > for Spi < Device >
276
- where
277
- Device : MpsseCmdExecutor < Error = E > ,
278
- E : std:: error:: Error ,
279
- Error < E > : From < E > ,
280
- {
256
+ fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
257
+ Ok ( ( ) )
258
+ }
259
+
281
260
fn transfer_in_place ( & mut self , words : & mut [ u8 ] ) -> Result < ( ) , Error < E > > {
282
261
let cmd: MpsseCmdBuilder = MpsseCmdBuilder :: new ( )
283
262
. clock_data ( self . pol . clk , words)
@@ -350,18 +329,7 @@ where
350
329
type Error = Error < E > ;
351
330
}
352
331
353
- impl < ' a , Device , E > eh1:: spi:: SpiBusFlush for SpiDeviceBus < ' a , Device >
354
- where
355
- Device : MpsseCmdExecutor < Error = E > ,
356
- E : std:: error:: Error ,
357
- Error < E > : From < E > ,
358
- {
359
- fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
360
- Ok ( ( ) )
361
- }
362
- }
363
-
364
- impl < ' a , Device , E > eh1:: spi:: SpiBusRead < u8 > for SpiDeviceBus < ' a , Device >
332
+ impl < ' a , Device , E > eh1:: spi:: SpiBus < u8 > for SpiDeviceBus < ' a , Device >
365
333
where
366
334
Device : MpsseCmdExecutor < Error = E > ,
367
335
E : std:: error:: Error ,
@@ -377,14 +345,7 @@ where
377
345
) ?;
378
346
Ok ( ( ) )
379
347
}
380
- }
381
348
382
- impl < ' a , Device , E > eh1:: spi:: SpiBusWrite < u8 > for SpiDeviceBus < ' a , Device >
383
- where
384
- Device : MpsseCmdExecutor < Error = E > ,
385
- E : std:: error:: Error ,
386
- Error < E > : From < E > ,
387
- {
388
349
fn write ( & mut self , words : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
389
350
self . lock . ft . send (
390
351
MpsseCmdBuilder :: new ( )
@@ -394,14 +355,11 @@ where
394
355
) ?;
395
356
Ok ( ( ) )
396
357
}
397
- }
398
358
399
- impl < ' a , Device , E > eh1:: spi:: SpiBus < u8 > for SpiDeviceBus < ' a , Device >
400
- where
401
- Device : MpsseCmdExecutor < Error = E > ,
402
- E : std:: error:: Error ,
403
- Error < E > : From < E > ,
404
- {
359
+ fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
360
+ Ok ( ( ) )
361
+ }
362
+
405
363
fn transfer ( & mut self , read : & mut [ u8 ] , write : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
406
364
self . lock . ft . xfer (
407
365
MpsseCmdBuilder :: new ( )
@@ -519,48 +477,6 @@ where
519
477
type Error = Error < E > ;
520
478
}
521
479
522
- impl < ' a , Device , E > eh1:: spi:: SpiDeviceRead for & ' a SpiDevice < Device >
523
- where
524
- Device : MpsseCmdExecutor < Error = E > ,
525
- E : std:: error:: Error ,
526
- Error < E > : From < E > ,
527
- {
528
- fn read_transaction ( & mut self , operations : & mut [ & mut [ u8 ] ] ) -> Result < ( ) , Self :: Error > {
529
- // lock the bus
530
- let lock: MutexGuard < FtInner < Device > > =
531
- self . mtx . lock ( ) . expect ( "Failed to aquire FTDI mutex" ) ;
532
- let mut bus: SpiDeviceBus < ' a , Device > = SpiDeviceBus {
533
- lock,
534
- pol : self . pol ,
535
- } ;
536
- for op in operations {
537
- eh1:: spi:: SpiBusRead :: read ( & mut bus, op) ?;
538
- }
539
- Ok ( ( ) )
540
- }
541
- }
542
-
543
- impl < ' a , Device , E > eh1:: spi:: SpiDeviceWrite for & ' a SpiDevice < Device >
544
- where
545
- Device : MpsseCmdExecutor < Error = E > ,
546
- E : std:: error:: Error ,
547
- Error < E > : From < E > ,
548
- {
549
- fn write_transaction ( & mut self , operations : & [ & [ u8 ] ] ) -> Result < ( ) , Self :: Error > {
550
- // lock the bus
551
- let lock: MutexGuard < FtInner < Device > > =
552
- self . mtx . lock ( ) . expect ( "Failed to aquire FTDI mutex" ) ;
553
- let mut bus: SpiDeviceBus < ' a , Device > = SpiDeviceBus {
554
- lock,
555
- pol : self . pol ,
556
- } ;
557
- for op in operations {
558
- eh1:: spi:: SpiBusWrite :: write ( & mut bus, op) ?;
559
- }
560
- Ok ( ( ) )
561
- }
562
- }
563
-
564
480
impl < ' a , Device , E > eh1:: spi:: SpiDevice for & ' a SpiDevice < Device >
565
481
where
566
482
Device : MpsseCmdExecutor < Error = E > ,
@@ -593,23 +509,26 @@ where
593
509
for op in operations {
594
510
match op {
595
511
eh1:: spi:: Operation :: Read ( buffer) => {
596
- eh1:: spi:: SpiBusRead :: read ( & mut bus, buffer) ?;
512
+ eh1:: spi:: SpiBus :: read ( & mut bus, buffer) ?;
597
513
}
598
514
eh1:: spi:: Operation :: Write ( buffer) => {
599
- eh1:: spi:: SpiBusWrite :: write ( & mut bus, buffer) ?;
515
+ eh1:: spi:: SpiBus :: write ( & mut bus, buffer) ?;
600
516
}
601
517
eh1:: spi:: Operation :: Transfer ( read, write) => {
602
518
eh1:: spi:: SpiBus :: transfer ( & mut bus, read, write) ?;
603
519
}
604
520
eh1:: spi:: Operation :: TransferInPlace ( buffer) => {
605
521
eh1:: spi:: SpiBus :: transfer_in_place ( & mut bus, buffer) ?;
606
522
}
523
+ eh1:: spi:: Operation :: DelayUs ( micros) => {
524
+ std:: thread:: sleep ( std:: time:: Duration :: from_micros ( ( * micros) . into ( ) ) ) ;
525
+ }
607
526
}
608
527
}
609
528
610
529
// flush the bus
611
530
{
612
- use eh1:: spi:: SpiBusFlush ;
531
+ use eh1:: spi:: SpiBus ;
613
532
bus. flush ( ) ?;
614
533
}
615
534
0 commit comments