aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/spim.rs
diff options
context:
space:
mode:
authorNBonaparte <[email protected]>2024-02-19 17:46:25 -0800
committerNBonaparte <[email protected]>2024-02-19 17:46:25 -0800
commitba2b4aad81c37727e05d2ddfbcc77ce247787b35 (patch)
treeac11a4a768e43288088b3074248731ee8b44d216 /embassy-nrf/src/spim.rs
parent6ecac3bc950212eba68d579c83ce5b52a17b8806 (diff)
fix(nrf/spim): use `OutputDrive` to set pin drives
Diffstat (limited to 'embassy-nrf/src/spim.rs')
-rw-r--r--embassy-nrf/src/spim.rs53
1 files changed, 16 insertions, 37 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index 0de35490b..a4ab7e9da 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -15,7 +15,7 @@ pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
15 15
16use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; 16use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
17use crate::gpio::sealed::Pin as _; 17use crate::gpio::sealed::Pin as _;
18use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; 18use crate::gpio::{self, convert_drive, AnyPin, OutputDrive, Pin as GpioPin, PselBits};
19use crate::interrupt::typelevel::Interrupt; 19use crate::interrupt::typelevel::Interrupt;
20use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; 20use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut};
21use crate::{interrupt, pac, Peripheral}; 21use crate::{interrupt, pac, Peripheral};
@@ -51,14 +51,14 @@ pub struct Config {
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 53
54 /// Enable high drive for the SCK line. 54 /// Drive strength for the SCK line.
55 pub sck_high_drive: bool, 55 pub sck_drive: OutputDrive,
56 56
57 /// Enable high drive for the MOSI line. 57 /// Drive strength for the MOSI line.
58 pub mosi_high_drive: bool, 58 pub mosi_drive: OutputDrive,
59 59
60 /// Enable high drive for the MISO line. 60 /// Drive strength for the MISO line.
61 pub miso_high_drive: bool, 61 pub miso_drive: OutputDrive,
62} 62}
63 63
64impl Default for Config { 64impl Default for Config {
@@ -68,9 +68,9 @@ impl Default for Config {
68 mode: MODE_0, 68 mode: MODE_0,
69 bit_order: BitOrder::MSB_FIRST, 69 bit_order: BitOrder::MSB_FIRST,
70 orc: 0x00, 70 orc: 0x00,
71 sck_high_drive: false, 71 sck_drive: OutputDrive::HighDrive,
72 mosi_high_drive: false, 72 mosi_drive: OutputDrive::HighDrive,
73 miso_high_drive: false, 73 miso_drive: OutputDrive::HighDrive,
74 } 74 }
75 } 75 }
76} 76}
@@ -171,37 +171,16 @@ impl<'d, T: Instance> Spim<'d, T> {
171 171
172 // Configure pins 172 // Configure pins
173 if let Some(sck) = &sck { 173 if let Some(sck) = &sck {
174 sck.conf().write(|w| { 174 sck.conf()
175 w.dir().output(); 175 .write(|w| w.dir().output().drive().variant(convert_drive(config.sck_drive)));
176 if config.sck_high_drive {
177 w.drive().h0h1();
178 } else {
179 w.drive().s0s1();
180 }
181 w
182 });
183 } 176 }
184 if let Some(mosi) = &mosi { 177 if let Some(mosi) = &mosi {
185 mosi.conf().write(|w| { 178 mosi.conf()
186 w.dir().output(); 179 .write(|w| w.dir().output().drive().variant(convert_drive(config.mosi_drive)));
187 if config.mosi_high_drive {
188 w.drive().h0h1();
189 } else {
190 w.drive().s0s1();
191 }
192 w
193 });
194 } 180 }
195 if let Some(miso) = &miso { 181 if let Some(miso) = &miso {
196 miso.conf().write(|w| { 182 miso.conf()
197 w.input().connect(); 183 .write(|w| w.input().connect().drive().variant(convert_drive(config.miso_drive)));
198 if config.miso_high_drive {
199 w.drive().h0h1();
200 } else {
201 w.drive().s0s1();
202 }
203 w
204 });
205 } 184 }
206 185
207 match config.mode.polarity { 186 match config.mode.polarity {