@@ -529,3 +529,108 @@ where
529
529
Ok ( ( ) )
530
530
}
531
531
}
532
+
533
+ impl embedded_hal_1:: spi:: Error for Error {
534
+ fn kind ( & self ) -> embedded_hal_1:: spi:: ErrorKind {
535
+ match self {
536
+ Error :: Overrun => embedded_hal_1:: spi:: ErrorKind :: Overrun ,
537
+ Error :: ModeFault => embedded_hal_1:: spi:: ErrorKind :: ModeFault ,
538
+ Error :: Crc => embedded_hal_1:: spi:: ErrorKind :: Other ,
539
+ }
540
+ }
541
+ }
542
+ impl < SPI , SCKPIN , MISOPIN , MOSIPIN , WIDTH > embedded_hal_1:: spi:: ErrorType
543
+ for Spi < SPI , SCKPIN , MISOPIN , MOSIPIN , WIDTH >
544
+ where
545
+ SPI : Deref < Target = SpiRegisterBlock > ,
546
+ {
547
+ type Error = Error ;
548
+ }
549
+
550
+ impl < SPI , SCKPIN , MISOPIN , MOSIPIN > embedded_hal_1:: spi:: SpiBus < u8 >
551
+ for Spi < SPI , SCKPIN , MISOPIN , MOSIPIN , EightBit >
552
+ where
553
+ SPI : Deref < Target = SpiRegisterBlock > ,
554
+ {
555
+ fn read ( & mut self , words : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
556
+ // We want to transfer bidirectionally, make sure we're in the correct mode
557
+ self . set_bidi ( ) ;
558
+
559
+ for word in words. iter_mut ( ) {
560
+ nb:: block!( self . check_send( ) ) ?;
561
+ self . send_u8 ( 0 ) ; // FIXME is this necessary?
562
+ nb:: block!( self . check_read( ) ) ?;
563
+ * word = self . read_u8 ( ) ;
564
+ }
565
+ Ok ( ( ) )
566
+ }
567
+
568
+ fn write ( & mut self , words : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
569
+ embedded_hal:: blocking:: spi:: Write :: write ( self , words)
570
+ }
571
+
572
+ fn transfer ( & mut self , read : & mut [ u8 ] , write : & [ u8 ] ) -> Result < ( ) , Self :: Error > {
573
+ // We want to transfer bidirectionally, make sure we're in the correct mode
574
+ self . set_bidi ( ) ;
575
+
576
+ for ( w, r) in write. iter ( ) . zip ( read. iter_mut ( ) ) {
577
+ nb:: block!( self . check_send( ) ) ?;
578
+ self . send_u8 ( * w) ;
579
+ nb:: block!( self . check_read( ) ) ?;
580
+ * r = self . read_u8 ( ) ;
581
+ }
582
+ Ok ( ( ) )
583
+ }
584
+
585
+ fn transfer_in_place ( & mut self , words : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
586
+ embedded_hal:: blocking:: spi:: Transfer :: transfer ( self , words) . map ( |_| ( ) )
587
+ }
588
+
589
+ fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
590
+ Ok ( ( ) )
591
+ }
592
+ }
593
+
594
+ impl < SPI , SCKPIN , MISOPIN , MOSIPIN > embedded_hal_1:: spi:: SpiBus < u16 >
595
+ for Spi < SPI , SCKPIN , MISOPIN , MOSIPIN , SixteenBit >
596
+ where
597
+ SPI : Deref < Target = SpiRegisterBlock > ,
598
+ {
599
+ fn read ( & mut self , words : & mut [ u16 ] ) -> Result < ( ) , Self :: Error > {
600
+ // We want to transfer bidirectionally, make sure we're in the correct mode
601
+ self . set_bidi ( ) ;
602
+
603
+ for word in words. iter_mut ( ) {
604
+ nb:: block!( self . check_send( ) ) ?;
605
+ self . send_u16 ( 0 ) ; // FIXME is this necessary?
606
+ nb:: block!( self . check_read( ) ) ?;
607
+ * word = self . read_u16 ( ) ;
608
+ }
609
+ Ok ( ( ) )
610
+ }
611
+
612
+ fn write ( & mut self , words : & [ u16 ] ) -> Result < ( ) , Self :: Error > {
613
+ embedded_hal:: blocking:: spi:: Write :: write ( self , words)
614
+ }
615
+
616
+ fn transfer ( & mut self , read : & mut [ u16 ] , write : & [ u16 ] ) -> Result < ( ) , Self :: Error > {
617
+ // We want to transfer bidirectionally, make sure we're in the correct mode
618
+ self . set_bidi ( ) ;
619
+
620
+ for ( w, r) in write. iter ( ) . zip ( read. iter_mut ( ) ) {
621
+ nb:: block!( self . check_send( ) ) ?;
622
+ self . send_u16 ( * w) ;
623
+ nb:: block!( self . check_read( ) ) ?;
624
+ * r = self . read_u16 ( ) ;
625
+ }
626
+ Ok ( ( ) )
627
+ }
628
+
629
+ fn transfer_in_place ( & mut self , words : & mut [ u16 ] ) -> Result < ( ) , Self :: Error > {
630
+ embedded_hal:: blocking:: spi:: Transfer :: transfer ( self , words) . map ( |_| ( ) )
631
+ }
632
+
633
+ fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
634
+ Ok ( ( ) )
635
+ }
636
+ }
0 commit comments