@@ -26,6 +26,52 @@ pub trait FullDuplex<Word> {
2626 fn send ( & mut self , word : Word ) -> nb:: Result < ( ) , Self :: Error > ;
2727}
2828
29+ /// Write (master mode)
30+ ///
31+ /// # Notes
32+ ///
33+ /// - It's the task of the user of this interface to manage the slave select lines
34+ #[ cfg( feature = "unproven" ) ]
35+ pub trait Send < Word > {
36+ /// An enumeration of SPI errors
37+ type Error ;
38+
39+ /// Sends a word to the slave
40+ fn send ( & mut self , word : Word ) -> nb:: Result < ( ) , Self :: Error > ;
41+ }
42+
43+ /// Write (master mode)
44+ #[ cfg( feature = "unproven" ) ]
45+ pub mod full_duplex {
46+ /// Default implementation of `spi::FullDuplex<W>` for implementers of
47+ /// `spi::Send<W>`
48+ ///
49+ /// Also needs a `send` method to return the byte read during the last send
50+ pub trait Default < W > : :: spi:: Send < W > {
51+ /// Reads the word stored in the shift register
52+ ///
53+ /// **NOTE** A word must be sent to the slave before attempting to call this
54+ /// method.
55+ fn read ( & mut self ) -> nb:: Result < W , Self :: Error > ;
56+ }
57+
58+ impl < W , S > :: spi:: FullDuplex < W > for S
59+ where
60+ S : Default < W > ,
61+ W : Clone ,
62+ {
63+ type Error = S :: Error ;
64+
65+ fn read ( & mut self ) -> nb:: Result < W , Self :: Error > {
66+ self . read ( )
67+ }
68+
69+ fn send ( & mut self , word : W ) -> nb:: Result < ( ) , Self :: Error > {
70+ self . send ( word)
71+ }
72+ }
73+ }
74+
2975/// Clock polarity
3076#[ derive( Clone , Copy , PartialEq ) ]
3177pub enum Polarity {
@@ -75,4 +121,4 @@ pub const MODE_2: Mode = Mode {
75121pub const MODE_3 : Mode = Mode {
76122 polarity : Polarity :: IdleHigh ,
77123 phase : Phase :: CaptureOnSecondTransition ,
78- } ;
124+ } ;
0 commit comments