aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNBonaparte <[email protected]>2024-02-15 22:33:23 -0800
committerNBonaparte <[email protected]>2024-02-18 19:37:35 -0800
commit6ecac3bc950212eba68d579c83ce5b52a17b8806 (patch)
treeb8623a87dbbb9c08275496fff70630e605dec1c8
parent5220453d85b1e0f279e94dc1627b7d2434132920 (diff)
feat(nrf/spim): allow specifying drive of SPI pins
-rw-r--r--embassy-nrf/src/spim.rs42
1 files changed, 39 insertions, 3 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index 8937159df..0de35490b 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -50,6 +50,15 @@ pub struct Config {
50 /// When doing bidirectional transfers, if the TX buffer is shorter than the RX buffer, 50 /// When doing bidirectional transfers, if the TX buffer is shorter than the RX buffer,
51 /// this byte will be transmitted in the MOSI line for the left-over bytes. 51 /// this byte will be transmitted in the MOSI line for the left-over bytes.
52 pub orc: u8, 52 pub orc: u8,
53
54 /// Enable high drive for the SCK line.
55 pub sck_high_drive: bool,
56
57 /// Enable high drive for the MOSI line.
58 pub mosi_high_drive: bool,
59
60 /// Enable high drive for the MISO line.
61 pub miso_high_drive: bool,
53} 62}
54 63
55impl Default for Config { 64impl Default for Config {
@@ -59,6 +68,9 @@ impl Default for Config {
59 mode: MODE_0, 68 mode: MODE_0,
60 bit_order: BitOrder::MSB_FIRST, 69 bit_order: BitOrder::MSB_FIRST,
61 orc: 0x00, 70 orc: 0x00,
71 sck_high_drive: false,
72 mosi_high_drive: false,
73 miso_high_drive: false,
62 } 74 }
63 } 75 }
64} 76}
@@ -159,13 +171,37 @@ impl<'d, T: Instance> Spim<'d, T> {
159 171
160 // Configure pins 172 // Configure pins
161 if let Some(sck) = &sck { 173 if let Some(sck) = &sck {
162 sck.conf().write(|w| w.dir().output().drive().h0h1()); 174 sck.conf().write(|w| {
175 w.dir().output();
176 if config.sck_high_drive {
177 w.drive().h0h1();
178 } else {
179 w.drive().s0s1();
180 }
181 w
182 });
163 } 183 }
164 if let Some(mosi) = &mosi { 184 if let Some(mosi) = &mosi {
165 mosi.conf().write(|w| w.dir().output().drive().h0h1()); 185 mosi.conf().write(|w| {
186 w.dir().output();
187 if config.mosi_high_drive {
188 w.drive().h0h1();
189 } else {
190 w.drive().s0s1();
191 }
192 w
193 });
166 } 194 }
167 if let Some(miso) = &miso { 195 if let Some(miso) = &miso {
168 miso.conf().write(|w| w.input().connect().drive().h0h1()); 196 miso.conf().write(|w| {
197 w.input().connect();
198 if config.miso_high_drive {
199 w.drive().h0h1();
200 } else {
201 w.drive().s0s1();
202 }
203 w
204 });
169 } 205 }
170 206
171 match config.mode.polarity { 207 match config.mode.polarity {