Doc fixes and SPI block mode support
- Various smaller fixes for documentation - Added support for SPI blockmode
This commit is contained in:
@ -31,11 +31,11 @@ pub enum SpiBusSelect {
|
||||
SpiBPortB,
|
||||
}
|
||||
|
||||
const EXAMPLE_SEL: ExampleSelect = ExampleSelect::Loopback;
|
||||
const EXAMPLE_SEL: ExampleSelect = ExampleSelect::TestBuffer;
|
||||
const SPI_BUS_SEL: SpiBusSelect = SpiBusSelect::SpiBPortB;
|
||||
const SPI_SPEED_KHZ: u32 = 1000;
|
||||
const SPI_MODE: Mode = MODE_0;
|
||||
const BLOCKMODE: bool = false;
|
||||
const BLOCKMODE: bool = true;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@ -45,14 +45,17 @@ fn main() -> ! {
|
||||
|
||||
let spia_ref: RefCell<Option<SpiBase<SPIA, u8>>> = RefCell::new(None);
|
||||
let spib_ref: RefCell<Option<SpiBase<SPIB, u8>>> = RefCell::new(None);
|
||||
let pinsa = PinsA::new(&mut dp.SYSCONFIG, None, dp.PORTA);
|
||||
let pinsb = PinsB::new(&mut dp.SYSCONFIG, Some(dp.IOCONFIG), dp.PORTB);
|
||||
|
||||
let mut spi_cfg = spi::SpiConfig::default();
|
||||
if EXAMPLE_SEL == ExampleSelect::Loopback {
|
||||
spi_cfg = spi_cfg.loopback(true)
|
||||
}
|
||||
|
||||
// Set up the SPI peripheral
|
||||
match SPI_BUS_SEL {
|
||||
SpiBusSelect::SpiAPortA => {
|
||||
let pinsa = PinsA::new(&mut dp.SYSCONFIG, None, dp.PORTA);
|
||||
let (sck, mosi, miso) = (
|
||||
pinsa.pa31.into_funsel_1(),
|
||||
pinsa.pa30.into_funsel_1(),
|
||||
@ -71,7 +74,6 @@ fn main() -> ! {
|
||||
);
|
||||
}
|
||||
SpiBusSelect::SpiAPortB => {
|
||||
let pinsb = PinsB::new(&mut dp.SYSCONFIG, Some(dp.IOCONFIG), dp.PORTB);
|
||||
let (sck, mosi, miso) = (
|
||||
pinsb.pb9.into_funsel_2(),
|
||||
pinsb.pb8.into_funsel_2(),
|
||||
@ -90,7 +92,6 @@ fn main() -> ! {
|
||||
);
|
||||
}
|
||||
SpiBusSelect::SpiBPortB => {
|
||||
let pinsb = PinsB::new(&mut dp.SYSCONFIG, Some(dp.IOCONFIG), dp.PORTB);
|
||||
let (sck, mosi, miso) = (
|
||||
pinsb.pb5.into_funsel_1(),
|
||||
pinsb.pb4.into_funsel_1(),
|
||||
@ -109,19 +110,41 @@ fn main() -> ! {
|
||||
);
|
||||
}
|
||||
}
|
||||
// Configure transfer specific properties here
|
||||
match SPI_BUS_SEL {
|
||||
SpiBusSelect::SpiAPortA | SpiBusSelect::SpiAPortB => {
|
||||
if let Some(ref mut spi) = *spia_ref.borrow_mut() {
|
||||
let transfer_cfg = TransferConfig::<NoneT>::new(
|
||||
SPI_SPEED_KHZ.khz().into(),
|
||||
SPI_MODE,
|
||||
None,
|
||||
BLOCKMODE,
|
||||
false,
|
||||
);
|
||||
spi.cfg_transfer(&transfer_cfg);
|
||||
}
|
||||
}
|
||||
SpiBusSelect::SpiBPortB => {
|
||||
if let Some(ref mut spi) = *spib_ref.borrow_mut() {
|
||||
let hw_cs_pin = pinsb.pb2.into_funsel_1();
|
||||
let transfer_cfg = TransferConfig::new(
|
||||
SPI_SPEED_KHZ.khz().into(),
|
||||
SPI_MODE,
|
||||
Some(hw_cs_pin),
|
||||
BLOCKMODE,
|
||||
false,
|
||||
);
|
||||
spi.cfg_transfer(&transfer_cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Application logic
|
||||
let mut delay_tim = CountDownTimer::tim1(&mut dp.SYSCONFIG, 50.mhz().into(), dp.TIM1);
|
||||
loop {
|
||||
match SPI_BUS_SEL {
|
||||
SpiBusSelect::SpiAPortA | SpiBusSelect::SpiAPortB => {
|
||||
if let Some(ref mut spi) = *spia_ref.borrow_mut() {
|
||||
let transfer_cfg: TransferConfig<NoneT> = TransferConfig {
|
||||
spi_clk: SPI_SPEED_KHZ.khz().into(),
|
||||
blockmode: BLOCKMODE,
|
||||
hw_cs: None,
|
||||
mode: SPI_MODE,
|
||||
sod: false,
|
||||
};
|
||||
spi.cfg_transfer(&transfer_cfg);
|
||||
if EXAMPLE_SEL == ExampleSelect::Loopback {
|
||||
nb::block!(spi.send(0x42_u8)).unwrap();
|
||||
let word = nb::block!(spi.read()).unwrap();
|
||||
@ -134,7 +157,7 @@ fn main() -> ! {
|
||||
assert_eq!(reply, &[0x03, 0x02, 0x01]);
|
||||
delay_tim.delay_ms(500_u32);
|
||||
} else {
|
||||
let mut send_buf: [u8; 3] = [0x00, 0x01, 0x02];
|
||||
let mut send_buf: [u8; 3] = [0x01, 0x02, 0x03];
|
||||
let reply = spi.transfer(&mut send_buf).unwrap();
|
||||
rprintln!("Received reply: {}, {}, {}", reply[0], reply[1], reply[2]);
|
||||
delay_tim.delay_ms(1000_u32);
|
||||
@ -143,14 +166,6 @@ fn main() -> ! {
|
||||
}
|
||||
SpiBusSelect::SpiBPortB => {
|
||||
if let Some(ref mut spi) = *spib_ref.borrow_mut() {
|
||||
let transfer_cfg: TransferConfig<NoneT> = TransferConfig {
|
||||
spi_clk: SPI_SPEED_KHZ.khz().into(),
|
||||
blockmode: BLOCKMODE,
|
||||
hw_cs: None,
|
||||
mode: SPI_MODE,
|
||||
sod: false,
|
||||
};
|
||||
spi.cfg_transfer(&transfer_cfg);
|
||||
if EXAMPLE_SEL == ExampleSelect::Loopback {
|
||||
nb::block!(spi.send(0x42_u8)).unwrap();
|
||||
let word = nb::block!(spi.read()).unwrap();
|
||||
@ -163,7 +178,7 @@ fn main() -> ! {
|
||||
assert_eq!(reply, &[0x03, 0x02, 0x01]);
|
||||
delay_tim.delay_ms(500_u32);
|
||||
} else {
|
||||
let mut send_buf: [u8; 3] = [0x00, 0x01, 0x02];
|
||||
let mut send_buf: [u8; 3] = [0x01, 0x02, 0x03];
|
||||
let reply = spi.transfer(&mut send_buf).unwrap();
|
||||
rprintln!("Received reply: {}, {}, {}", reply[0], reply[1], reply[2]);
|
||||
delay_tim.delay_ms(1000_u32);
|
||||
|
Reference in New Issue
Block a user