aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorMatthew Tran <[email protected]>2024-01-26 22:38:03 -0600
committerMatthew Tran <[email protected]>2024-01-26 22:38:03 -0600
commit6efb5fd28425876ad72faa8bbc34facd7f3e3f81 (patch)
tree0633d30ae2c1c3863f968217de97ea30f75bd21b /embassy-nrf/src
parentc37e483b3b5acbb9bd42b950024c35c24ce34519 (diff)
nrf/spi: add bit order config
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/spim.rs13
-rw-r--r--embassy-nrf/src/spis.rs13
2 files changed, 18 insertions, 8 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index b0723d495..6b6f79188 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -10,6 +10,7 @@ use core::task::Poll;
10use embassy_embedded_hal::SetConfig; 10use embassy_embedded_hal::SetConfig;
11use embassy_hal_internal::{into_ref, PeripheralRef}; 11use embassy_hal_internal::{into_ref, PeripheralRef};
12pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 12pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
13pub use pac::spim0::config::ORDER_A as BitOrder;
13pub use pac::spim0::frequency::FREQUENCY_A as Frequency; 14pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
14 15
15use crate::chip::FORCE_COPY_BUFFER_SIZE; 16use crate::chip::FORCE_COPY_BUFFER_SIZE;
@@ -41,6 +42,9 @@ pub struct Config {
41 /// SPI mode 42 /// SPI mode
42 pub mode: Mode, 43 pub mode: Mode,
43 44
45 /// Bit order
46 pub bit_order: BitOrder,
47
44 /// Overread character. 48 /// Overread character.
45 /// 49 ///
46 /// 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,
@@ -53,6 +57,7 @@ impl Default for Config {
53 Self { 57 Self {
54 frequency: Frequency::M1, 58 frequency: Frequency::M1,
55 mode: MODE_0, 59 mode: MODE_0,
60 bit_order: BitOrder::MSB_FIRST,
56 orc: 0x00, 61 orc: 0x00,
57 } 62 }
58 } 63 }
@@ -580,22 +585,22 @@ impl<'d, T: Instance> SetConfig for Spim<'d, T> {
580 r.config.write(|w| { 585 r.config.write(|w| {
581 match mode { 586 match mode {
582 MODE_0 => { 587 MODE_0 => {
583 w.order().msb_first(); 588 w.order().variant(config.bit_order);
584 w.cpol().active_high(); 589 w.cpol().active_high();
585 w.cpha().leading(); 590 w.cpha().leading();
586 } 591 }
587 MODE_1 => { 592 MODE_1 => {
588 w.order().msb_first(); 593 w.order().variant(config.bit_order);
589 w.cpol().active_high(); 594 w.cpol().active_high();
590 w.cpha().trailing(); 595 w.cpha().trailing();
591 } 596 }
592 MODE_2 => { 597 MODE_2 => {
593 w.order().msb_first(); 598 w.order().variant(config.bit_order);
594 w.cpol().active_low(); 599 w.cpol().active_low();
595 w.cpha().leading(); 600 w.cpha().leading();
596 } 601 }
597 MODE_3 => { 602 MODE_3 => {
598 w.order().msb_first(); 603 w.order().variant(config.bit_order);
599 w.cpol().active_low(); 604 w.cpol().active_low();
600 w.cpha().trailing(); 605 w.cpha().trailing();
601 } 606 }
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs
index 3aad25298..60f4c9865 100644
--- a/embassy-nrf/src/spis.rs
+++ b/embassy-nrf/src/spis.rs
@@ -9,6 +9,7 @@ use core::task::Poll;
9use embassy_embedded_hal::SetConfig; 9use embassy_embedded_hal::SetConfig;
10use embassy_hal_internal::{into_ref, PeripheralRef}; 10use embassy_hal_internal::{into_ref, PeripheralRef};
11pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 11pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
12pub use pac::spis0::config::ORDER_A as BitOrder;
12 13
13use crate::chip::FORCE_COPY_BUFFER_SIZE; 14use crate::chip::FORCE_COPY_BUFFER_SIZE;
14use crate::gpio::sealed::Pin as _; 15use crate::gpio::sealed::Pin as _;
@@ -36,6 +37,9 @@ pub struct Config {
36 /// SPI mode 37 /// SPI mode
37 pub mode: Mode, 38 pub mode: Mode,
38 39
40 /// Bit order
41 pub bit_order: BitOrder,
42
39 /// Overread character. 43 /// Overread character.
40 /// 44 ///
41 /// If the master keeps clocking the bus after all the bytes in the TX buffer have 45 /// If the master keeps clocking the bus after all the bytes in the TX buffer have
@@ -56,6 +60,7 @@ impl Default for Config {
56 fn default() -> Self { 60 fn default() -> Self {
57 Self { 61 Self {
58 mode: MODE_0, 62 mode: MODE_0,
63 bit_order: BitOrder::MSB_FIRST,
59 orc: 0x00, 64 orc: 0x00,
60 def: 0x00, 65 def: 0x00,
61 auto_acquire: true, 66 auto_acquire: true,
@@ -503,22 +508,22 @@ impl<'d, T: Instance> SetConfig for Spis<'d, T> {
503 r.config.write(|w| { 508 r.config.write(|w| {
504 match mode { 509 match mode {
505 MODE_0 => { 510 MODE_0 => {
506 w.order().msb_first(); 511 w.order().variant(config.bit_order);
507 w.cpol().active_high(); 512 w.cpol().active_high();
508 w.cpha().leading(); 513 w.cpha().leading();
509 } 514 }
510 MODE_1 => { 515 MODE_1 => {
511 w.order().msb_first(); 516 w.order().variant(config.bit_order);
512 w.cpol().active_high(); 517 w.cpol().active_high();
513 w.cpha().trailing(); 518 w.cpha().trailing();
514 } 519 }
515 MODE_2 => { 520 MODE_2 => {
516 w.order().msb_first(); 521 w.order().variant(config.bit_order);
517 w.cpol().active_low(); 522 w.cpol().active_low();
518 w.cpha().leading(); 523 w.cpha().leading();
519 } 524 }
520 MODE_3 => { 525 MODE_3 => {
521 w.order().msb_first(); 526 w.order().variant(config.bit_order);
522 w.cpol().active_low(); 527 w.cpol().active_low();
523 w.cpha().trailing(); 528 w.cpha().trailing();
524 } 529 }