aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/spi
diff options
context:
space:
mode:
authorJoël Schulz-Ansres <[email protected]>2024-05-15 12:54:30 +0200
committerJoël Schulz-Ansres <[email protected]>2024-05-15 12:54:30 +0200
commitdb56c4fe6fb919e89edda37fc5acb2fb05f45745 (patch)
tree63d0449b5423dd66dd6ad4fdb1a566470c1a2c11 /embassy-stm32/src/spi
parentea70b440cd1035f28c3f332a2f72d7fa42ac995d (diff)
Add miso pullup to spi configuration, add input as field for speed
Diffstat (limited to 'embassy-stm32/src/spi')
-rw-r--r--embassy-stm32/src/spi/mod.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index c39ef1913..bcd6b0bf4 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -50,6 +50,11 @@ pub struct Config {
50 pub bit_order: BitOrder, 50 pub bit_order: BitOrder,
51 /// Clock frequency. 51 /// Clock frequency.
52 pub frequency: Hertz, 52 pub frequency: Hertz,
53 /// Enable internal pullup on MISO.
54 ///
55 /// There are some ICs that require a pull-up on the MISO pin for some applications.
56 /// If you are unsure, you probably don't need this.
57 pub miso_pullup: bool,
53} 58}
54 59
55impl Default for Config { 60impl Default for Config {
@@ -58,6 +63,7 @@ impl Default for Config {
58 mode: MODE_0, 63 mode: MODE_0,
59 bit_order: BitOrder::MsbFirst, 64 bit_order: BitOrder::MsbFirst,
60 frequency: Hertz(1_000_000), 65 frequency: Hertz(1_000_000),
66 miso_pullup: false,
61 } 67 }
62 } 68 }
63} 69}
@@ -275,6 +281,16 @@ impl<'d, T: Instance, M: PeriMode> Spi<'d, T, M> {
275 BitOrder::MsbFirst 281 BitOrder::MsbFirst
276 }; 282 };
277 283
284 let miso_pullup = match &self.miso {
285 None => false,
286 Some(pin) =>
287 if pin.pull() == Pull::Up {
288 true
289 } else {
290 false
291 }
292 };
293
278 #[cfg(any(spi_v1, spi_f1, spi_v2))] 294 #[cfg(any(spi_v1, spi_f1, spi_v2))]
279 let br = cfg.br(); 295 let br = cfg.br();
280 #[cfg(any(spi_v3, spi_v4, spi_v5))] 296 #[cfg(any(spi_v3, spi_v4, spi_v5))]
@@ -287,6 +303,7 @@ impl<'d, T: Instance, M: PeriMode> Spi<'d, T, M> {
287 mode: Mode { polarity, phase }, 303 mode: Mode { polarity, phase },
288 bit_order, 304 bit_order,
289 frequency, 305 frequency,
306 miso_pullup,
290 } 307 }
291 } 308 }
292 309
@@ -409,7 +426,11 @@ impl<'d, T: Instance> Spi<'d, T, Blocking> {
409 peri, 426 peri,
410 new_pin!(sck, AFType::OutputPushPull, Speed::VeryHigh, config.sck_pull_mode()), 427 new_pin!(sck, AFType::OutputPushPull, Speed::VeryHigh, config.sck_pull_mode()),
411 new_pin!(mosi, AFType::OutputPushPull, Speed::VeryHigh), 428 new_pin!(mosi, AFType::OutputPushPull, Speed::VeryHigh),
412 new_pin!(miso, AFType::Input, Speed::VeryHigh), 429 new_pin!(miso, AFType::Input, Speed::Input,
430 match config.miso_pullup {
431 true => Pull::Up,
432 false => Pull::None,
433 }),
413 None, 434 None,
414 None, 435 None,
415 config, 436 config,
@@ -427,7 +448,11 @@ impl<'d, T: Instance> Spi<'d, T, Blocking> {
427 peri, 448 peri,
428 new_pin!(sck, AFType::OutputPushPull, Speed::VeryHigh, config.sck_pull_mode()), 449 new_pin!(sck, AFType::OutputPushPull, Speed::VeryHigh, config.sck_pull_mode()),
429 None, 450 None,
430 new_pin!(miso, AFType::Input, Speed::VeryHigh), 451 new_pin!(miso, AFType::Input, Speed::Input,
452 match config.miso_pullup {
453 true => Pull::Up,
454 false => Pull::None,
455 }),
431 None, 456 None,
432 None, 457 None,
433 config, 458 config,