Skip to content

Commit 8e9037a

Browse files
committed
spi: Optimize send_{command,data}_slice
1 parent 2cb4d64 commit 8e9037a

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

spi/src/lib.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,46 @@ where
106106

107107
err
108108
}
109+
110+
#[inline]
111+
fn send_command_slice(&mut self, slice: &[Self::Word]) -> Result<(), DisplayError> {
112+
// Assert chip select pin
113+
self.cs.set_low().map_err(|_| DisplayError::CSError)?;
114+
115+
// 1 = data, 0 = command
116+
self.dc.set_low().map_err(|_| DisplayError::DCError)?;
117+
118+
// Send words over SPI
119+
let err = self
120+
.spi
121+
.write(slice)
122+
.map_err(|_| DisplayError::BusWriteError);
123+
124+
// Deassert chip select pin
125+
self.cs.set_high().ok();
126+
127+
err
128+
}
129+
130+
#[inline]
131+
fn send_data_slice(&mut self, slice: &[Self::Word]) -> Result<(), DisplayError> {
132+
// Assert chip select pin
133+
self.cs.set_low().map_err(|_| DisplayError::CSError)?;
134+
135+
// 1 = data, 0 = command
136+
self.dc.set_high().map_err(|_| DisplayError::DCError)?;
137+
138+
// Send words over SPI
139+
let err = self
140+
.spi
141+
.write(slice)
142+
.map_err(|_| DisplayError::BusWriteError);
143+
144+
// Deassert chip select pin
145+
self.cs.set_high().ok();
146+
147+
err
148+
}
109149
}
110150

111151
/// SPI display interface.
@@ -163,4 +203,26 @@ where
163203
// Send words over SPI
164204
send_iter(&mut self.spi, iter)
165205
}
206+
207+
#[inline]
208+
fn send_command_slice(&mut self, slice: &[Self::Word]) -> Result<(), DisplayError> {
209+
// 1 = data, 0 = command
210+
self.dc.set_low().map_err(|_| DisplayError::DCError)?;
211+
212+
// Send words over SPI
213+
self.spi
214+
.write(slice)
215+
.map_err(|_| DisplayError::BusWriteError)
216+
}
217+
218+
#[inline]
219+
fn send_data_slice(&mut self, slice: &[Self::Word]) -> Result<(), DisplayError> {
220+
// 1 = data, 0 = command
221+
self.dc.set_high().map_err(|_| DisplayError::DCError)?;
222+
223+
// Send words over SPI
224+
self.spi
225+
.write(slice)
226+
.map_err(|_| DisplayError::BusWriteError)
227+
}
166228
}

0 commit comments

Comments
 (0)