fix SPI examples
Some checks failed
Rust/va416xx-rs/pipeline/pr-main There was a failure building this commit

This commit is contained in:
Robin Müller 2024-09-20 11:39:59 +02:00
parent 3f98fe7d93
commit ca580c88be
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 33 additions and 15 deletions

View File

@ -8,7 +8,7 @@ use embedded_hal::spi::{Mode, SpiBus, MODE_0};
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use simple_examples::peb1; use simple_examples::peb1;
use va416xx_hal::spi::{Spi, SpiClkConfig, TransferConfigWithHwcs}; use va416xx_hal::spi::{Spi, SpiClkConfig};
use va416xx_hal::{ use va416xx_hal::{
gpio::{PinsB, PinsC}, gpio::{PinsB, PinsC},
pac, pac,
@ -55,14 +55,16 @@ fn main() -> ! {
pins_c.pc1.into_funsel_1(), pins_c.pc1.into_funsel_1(),
); );
let mut spi_cfg = SpiConfig::default().clk_cfg( let mut spi_cfg = SpiConfig::default()
SpiClkConfig::from_clk(Hertz::from_raw(SPI_SPEED_KHZ), &clocks) .clk_cfg(
.expect("invalid target clock"), SpiClkConfig::from_clk(Hertz::from_raw(SPI_SPEED_KHZ), &clocks)
); .expect("invalid target clock"),
)
.mode(SPI_MODE)
.blockmode(BLOCKMODE);
if EXAMPLE_SEL == ExampleSelect::Loopback { if EXAMPLE_SEL == ExampleSelect::Loopback {
spi_cfg = spi_cfg.loopback(true) spi_cfg = spi_cfg.loopback(true)
} }
let transfer_cfg = TransferConfigWithHwcs::new_no_hw_cs(None, Some(SPI_MODE), BLOCKMODE, false);
// Create SPI peripheral. // Create SPI peripheral.
let mut spi0 = Spi::new( let mut spi0 = Spi::new(
&mut dp.sysconfig, &mut dp.sysconfig,
@ -70,9 +72,7 @@ fn main() -> ! {
dp.spi0, dp.spi0,
(sck, miso, mosi), (sck, miso, mosi),
spi_cfg, spi_cfg,
Some(&transfer_cfg.downgrade()), );
)
.expect("creating SPI peripheral failed");
spi0.set_fill_word(FILL_WORD); spi0.set_fill_word(FILL_WORD);
loop { loop {
let tx_buf: [u8; 4] = [1, 2, 3, 0]; let tx_buf: [u8; 4] = [1, 2, 3, 0];

View File

@ -255,6 +255,9 @@ pub struct TransferConfig {
/// the BMSTOP bit is set on a dataword. A frame is defined as CSn being active for the /// the BMSTOP bit is set on a dataword. A frame is defined as CSn being active for the
/// duration of multiple data words /// duration of multiple data words
pub blockmode: bool, pub blockmode: bool,
/// Only used when blockmode is used. The SCK will be stalled until an explicit stop bit
/// is set on a written word.
pub bmstall: bool,
pub hw_cs: HwChipSelectId, pub hw_cs: HwChipSelectId,
} }
@ -263,6 +266,7 @@ impl TransferConfigWithHwcs<NoneT> {
clk_cfg: Option<SpiClkConfig>, clk_cfg: Option<SpiClkConfig>,
mode: Option<Mode>, mode: Option<Mode>,
blockmode: bool, blockmode: bool,
bmstall: bool,
sod: bool, sod: bool,
) -> Self { ) -> Self {
TransferConfigWithHwcs { TransferConfigWithHwcs {
@ -272,6 +276,7 @@ impl TransferConfigWithHwcs<NoneT> {
mode, mode,
sod, sod,
blockmode, blockmode,
bmstall,
hw_cs: HwChipSelectId::Invalid, hw_cs: HwChipSelectId::Invalid,
}, },
} }
@ -284,6 +289,7 @@ impl<HwCs: HwCsProvider> TransferConfigWithHwcs<HwCs> {
mode: Option<Mode>, mode: Option<Mode>,
hw_cs: Option<HwCs>, hw_cs: Option<HwCs>,
blockmode: bool, blockmode: bool,
bmstall: bool,
sod: bool, sod: bool,
) -> Self { ) -> Self {
TransferConfigWithHwcs { TransferConfigWithHwcs {
@ -293,6 +299,7 @@ impl<HwCs: HwCsProvider> TransferConfigWithHwcs<HwCs> {
mode, mode,
sod, sod,
blockmode, blockmode,
bmstall,
hw_cs: HwCs::CS_ID, hw_cs: HwCs::CS_ID,
}, },
} }
@ -370,6 +377,21 @@ impl SpiConfig {
self self
} }
pub fn blockmode(mut self, enable: bool) -> Self {
self.blockmode = enable;
self
}
pub fn bmstall(mut self, enable: bool) -> Self {
self.bmstall = enable;
self
}
pub fn mode(mut self, mode: Mode) -> Self {
self.init_mode = mode;
self
}
pub fn clk_cfg(mut self, clk_cfg: SpiClkConfig) -> Self { pub fn clk_cfg(mut self, clk_cfg: SpiClkConfig) -> Self {
self.clk = clk_cfg; self.clk = clk_cfg;
self self
@ -719,12 +741,8 @@ where
} else { } else {
w.sod().clear_bit(); w.sod().clear_bit();
} }
if transfer_cfg.cfg.blockmode { w.blockmode().bit(transfer_cfg.cfg.blockmode);
w.blockmode().set_bit(); w.bmstall().bit(transfer_cfg.cfg.bmstall)
} else {
w.blockmode().clear_bit();
}
w
}); });
} }