@@ -4,7 +4,7 @@ pub use embedded_hal::spi::{
4
4
Error , ErrorKind , ErrorType , Mode , Operation , Phase , Polarity , MODE_0 , MODE_1 , MODE_2 , MODE_3 ,
5
5
} ;
6
6
7
- /// SPI device trait
7
+ /// SPI device trait.
8
8
///
9
9
/// `SpiDevice` represents ownership over a single SPI device on a (possibly shared) bus, selected
10
10
/// with a CS (Chip Select) pin.
@@ -36,6 +36,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
36
36
/// This is a convenience method equivalent to `device.read_transaction(&mut [buf])`.
37
37
///
38
38
/// See also: [`SpiDevice::transaction`], [`SpiDevice::read`]
39
+ #[ inline]
39
40
async fn read ( & mut self , buf : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
40
41
self . transaction ( & mut [ Operation :: Read ( buf) ] ) . await
41
42
}
@@ -45,6 +46,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
45
46
/// This is a convenience method equivalent to `device.write_transaction(&mut [buf])`.
46
47
///
47
48
/// See also: [`SpiDevice::transaction`], [`SpiDevice::write`]
49
+ #[ inline]
48
50
async fn write ( & mut self , buf : & [ Word ] ) -> Result < ( ) , Self :: Error > {
49
51
self . transaction ( & mut [ Operation :: Write ( buf) ] ) . await
50
52
}
@@ -54,6 +56,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
54
56
/// This is a convenience method equivalent to `device.transaction(|bus| bus.transfer(read, write))`.
55
57
///
56
58
/// See also: [`SpiDevice::transaction`], [`SpiBus::transfer`]
59
+ #[ inline]
57
60
async fn transfer ( & mut self , read : & mut [ Word ] , write : & [ Word ] ) -> Result < ( ) , Self :: Error > {
58
61
self . transaction ( & mut [ Operation :: Transfer ( read, write) ] )
59
62
. await
@@ -64,38 +67,44 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
64
67
/// This is a convenience method equivalent to `device.transaction(|bus| bus.transfer_in_place(buf))`.
65
68
///
66
69
/// See also: [`SpiDevice::transaction`], [`SpiBus::transfer_in_place`]
70
+ #[ inline]
67
71
async fn transfer_in_place ( & mut self , buf : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
68
72
self . transaction ( & mut [ Operation :: TransferInPlace ( buf) ] )
69
73
. await
70
74
}
71
75
}
72
76
73
77
impl < Word : Copy + ' static , T : SpiDevice < Word > + ?Sized > SpiDevice < Word > for & mut T {
78
+ #[ inline]
74
79
async fn transaction (
75
80
& mut self ,
76
81
operations : & mut [ Operation < ' _ , Word > ] ,
77
82
) -> Result < ( ) , Self :: Error > {
78
83
T :: transaction ( self , operations) . await
79
84
}
80
85
86
+ #[ inline]
81
87
async fn read ( & mut self , buf : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
82
88
T :: read ( self , buf) . await
83
89
}
84
90
91
+ #[ inline]
85
92
async fn write ( & mut self , buf : & [ Word ] ) -> Result < ( ) , Self :: Error > {
86
93
T :: write ( self , buf) . await
87
94
}
88
95
96
+ #[ inline]
89
97
async fn transfer ( & mut self , read : & mut [ Word ] , write : & [ Word ] ) -> Result < ( ) , Self :: Error > {
90
98
T :: transfer ( self , read, write) . await
91
99
}
92
100
101
+ #[ inline]
93
102
async fn transfer_in_place ( & mut self , buf : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
94
103
T :: transfer_in_place ( self , buf) . await
95
104
}
96
105
}
97
106
98
- /// SPI bus
107
+ /// SPI bus.
99
108
///
100
109
/// `SpiBus` represents **exclusive ownership** over the whole SPI bus, with SCK, MOSI and MISO pins.
101
110
///
@@ -110,7 +119,7 @@ pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
110
119
/// complete. See (the docs on embedded-hal)[embedded_hal::spi] for details on flushing.
111
120
async fn read ( & mut self , words : & mut [ Word ] ) -> Result < ( ) , Self :: Error > ;
112
121
113
- /// Write `words` to the slave, ignoring all the incoming words
122
+ /// Write `words` to the slave, ignoring all the incoming words.
114
123
///
115
124
/// Implementations are allowed to return before the operation is
116
125
/// complete. See (the docs on embedded-hal)[embedded_hal::spi] for details on flushing.
@@ -144,22 +153,27 @@ pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
144
153
}
145
154
146
155
impl < T : SpiBus < Word > + ?Sized , Word : ' static + Copy > SpiBus < Word > for & mut T {
156
+ #[ inline]
147
157
async fn read ( & mut self , words : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
148
158
T :: read ( self , words) . await
149
159
}
150
160
161
+ #[ inline]
151
162
async fn write ( & mut self , words : & [ Word ] ) -> Result < ( ) , Self :: Error > {
152
163
T :: write ( self , words) . await
153
164
}
154
165
166
+ #[ inline]
155
167
async fn transfer ( & mut self , read : & mut [ Word ] , write : & [ Word ] ) -> Result < ( ) , Self :: Error > {
156
168
T :: transfer ( self , read, write) . await
157
169
}
158
170
171
+ #[ inline]
159
172
async fn transfer_in_place ( & mut self , words : & mut [ Word ] ) -> Result < ( ) , Self :: Error > {
160
173
T :: transfer_in_place ( self , words) . await
161
174
}
162
175
176
+ #[ inline]
163
177
async fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
164
178
T :: flush ( self ) . await
165
179
}
0 commit comments