Merge pull request #2485 from 0e4ef622/nrf-spi-bitorder
nrf/spi: add bit order config
This commit is contained in:
commit
702007f68b
2 changed files with 18 additions and 8 deletions
|
@ -10,6 +10,7 @@ use core::task::Poll;
|
||||||
use embassy_embedded_hal::SetConfig;
|
use embassy_embedded_hal::SetConfig;
|
||||||
use embassy_hal_internal::{into_ref, PeripheralRef};
|
use embassy_hal_internal::{into_ref, PeripheralRef};
|
||||||
pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
||||||
|
pub use pac::spim0::config::ORDER_A as BitOrder;
|
||||||
pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
|
pub use pac::spim0::frequency::FREQUENCY_A as Frequency;
|
||||||
|
|
||||||
use crate::chip::FORCE_COPY_BUFFER_SIZE;
|
use crate::chip::FORCE_COPY_BUFFER_SIZE;
|
||||||
|
@ -41,6 +42,9 @@ pub struct Config {
|
||||||
/// SPI mode
|
/// SPI mode
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
|
|
||||||
|
/// Bit order
|
||||||
|
pub bit_order: BitOrder,
|
||||||
|
|
||||||
/// Overread character.
|
/// Overread character.
|
||||||
///
|
///
|
||||||
/// When doing bidirectional transfers, if the TX buffer is shorter than the RX buffer,
|
/// When doing bidirectional transfers, if the TX buffer is shorter than the RX buffer,
|
||||||
|
@ -53,6 +57,7 @@ impl Default for Config {
|
||||||
Self {
|
Self {
|
||||||
frequency: Frequency::M1,
|
frequency: Frequency::M1,
|
||||||
mode: MODE_0,
|
mode: MODE_0,
|
||||||
|
bit_order: BitOrder::MSB_FIRST,
|
||||||
orc: 0x00,
|
orc: 0x00,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -580,22 +585,22 @@ impl<'d, T: Instance> SetConfig for Spim<'d, T> {
|
||||||
r.config.write(|w| {
|
r.config.write(|w| {
|
||||||
match mode {
|
match mode {
|
||||||
MODE_0 => {
|
MODE_0 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_high();
|
w.cpol().active_high();
|
||||||
w.cpha().leading();
|
w.cpha().leading();
|
||||||
}
|
}
|
||||||
MODE_1 => {
|
MODE_1 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_high();
|
w.cpol().active_high();
|
||||||
w.cpha().trailing();
|
w.cpha().trailing();
|
||||||
}
|
}
|
||||||
MODE_2 => {
|
MODE_2 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_low();
|
w.cpol().active_low();
|
||||||
w.cpha().leading();
|
w.cpha().leading();
|
||||||
}
|
}
|
||||||
MODE_3 => {
|
MODE_3 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_low();
|
w.cpol().active_low();
|
||||||
w.cpha().trailing();
|
w.cpha().trailing();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use core::task::Poll;
|
||||||
use embassy_embedded_hal::SetConfig;
|
use embassy_embedded_hal::SetConfig;
|
||||||
use embassy_hal_internal::{into_ref, PeripheralRef};
|
use embassy_hal_internal::{into_ref, PeripheralRef};
|
||||||
pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
||||||
|
pub use pac::spis0::config::ORDER_A as BitOrder;
|
||||||
|
|
||||||
use crate::chip::FORCE_COPY_BUFFER_SIZE;
|
use crate::chip::FORCE_COPY_BUFFER_SIZE;
|
||||||
use crate::gpio::sealed::Pin as _;
|
use crate::gpio::sealed::Pin as _;
|
||||||
|
@ -36,6 +37,9 @@ pub struct Config {
|
||||||
/// SPI mode
|
/// SPI mode
|
||||||
pub mode: Mode,
|
pub mode: Mode,
|
||||||
|
|
||||||
|
/// Bit order
|
||||||
|
pub bit_order: BitOrder,
|
||||||
|
|
||||||
/// Overread character.
|
/// Overread character.
|
||||||
///
|
///
|
||||||
/// If the master keeps clocking the bus after all the bytes in the TX buffer have
|
/// If the master keeps clocking the bus after all the bytes in the TX buffer have
|
||||||
|
@ -56,6 +60,7 @@ impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
mode: MODE_0,
|
mode: MODE_0,
|
||||||
|
bit_order: BitOrder::MSB_FIRST,
|
||||||
orc: 0x00,
|
orc: 0x00,
|
||||||
def: 0x00,
|
def: 0x00,
|
||||||
auto_acquire: true,
|
auto_acquire: true,
|
||||||
|
@ -503,22 +508,22 @@ impl<'d, T: Instance> SetConfig for Spis<'d, T> {
|
||||||
r.config.write(|w| {
|
r.config.write(|w| {
|
||||||
match mode {
|
match mode {
|
||||||
MODE_0 => {
|
MODE_0 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_high();
|
w.cpol().active_high();
|
||||||
w.cpha().leading();
|
w.cpha().leading();
|
||||||
}
|
}
|
||||||
MODE_1 => {
|
MODE_1 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_high();
|
w.cpol().active_high();
|
||||||
w.cpha().trailing();
|
w.cpha().trailing();
|
||||||
}
|
}
|
||||||
MODE_2 => {
|
MODE_2 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_low();
|
w.cpol().active_low();
|
||||||
w.cpha().leading();
|
w.cpha().leading();
|
||||||
}
|
}
|
||||||
MODE_3 => {
|
MODE_3 => {
|
||||||
w.order().msb_first();
|
w.order().variant(config.bit_order);
|
||||||
w.cpol().active_low();
|
w.cpol().active_low();
|
||||||
w.cpha().trailing();
|
w.cpha().trailing();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue