From bf5526e39974621113f8a927d8cfe24f65f6e357 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Sat, 24 Feb 2024 14:38:31 +0100 Subject: [PATCH] Split SPI and CS pins in board subcrate --- board/src/imxrt1010evk.rs | 14 ++++++++++---- board/src/imxrt1060evk.rs | 14 ++++++++++---- board/src/imxrt1170evk-cm7.rs | 15 +++++++++++---- board/src/teensy4.rs | 15 +++++++++++---- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/board/src/imxrt1010evk.rs b/board/src/imxrt1010evk.rs index eb3b3af2..81f46cf1 100644 --- a/board/src/imxrt1010evk.rs +++ b/board/src/imxrt1010evk.rs @@ -61,14 +61,17 @@ pub type SpiPins = hal::lpspi::Pins< iomuxc::gpio_ad::GPIO_AD_04, // SDO, J57_8 iomuxc::gpio_ad::GPIO_AD_03, // SDI, J57_10 iomuxc::gpio_ad::GPIO_AD_06, // SCK, J57_12 - iomuxc::gpio_ad::GPIO_AD_05, // PCS0, J57_6 >; #[cfg(feature = "spi")] pub type Spi = hal::lpspi::Lpspi; +#[cfg(feature = "spi")] +pub type SpiCsPin = hal::gpio::Output; // PCS0, J57_6 #[cfg(not(feature = "spi"))] pub type Spi = (); +#[cfg(not(feature = "spi"))] +pub type SpiCsPin = (); pub type I2cPins = hal::lpi2c::Pins< iomuxc::gpio::GPIO_02, // SCL, J57_20 @@ -145,6 +148,7 @@ pub struct Specifics { pub ports: GpioPorts, pub console: Console, pub spi: Spi, + pub spi_cs: SpiCsPin, pub i2c: I2c, pub pwm: Pwm, pub tp34: Tp34, @@ -181,7 +185,7 @@ impl Specifics { }); #[cfg(feature = "spi")] - let spi = { + let (spi, spi_cs) = { let lpspi1 = unsafe { ral::lpspi::LPSPI1::instance() }; let pins = SpiPins { sdo: iomuxc.gpio_ad.p04, @@ -193,12 +197,13 @@ impl Specifics { spi.disabled(|spi| { spi.set_clock_hz(super::LPSPI_CLK_FREQUENCY, super::SPI_BAUD_RATE_FREQUENCY); }); - spi + let spi_cs = todo!(); + (spi, spi_cs) }; #[cfg(not(feature = "spi"))] #[allow(clippy::let_unit_value)] - let spi = (); + let (spi, spi_cs) = ((), ()); let lpi2c1 = unsafe { ral::lpi2c::LPI2C1::instance() }; let i2c = I2c::new( @@ -247,6 +252,7 @@ impl Specifics { ports: GpioPorts { gpio2 }, console, spi, + spi_cs, i2c, pwm, tp34: iomuxc.gpio_sd.p02, diff --git a/board/src/imxrt1060evk.rs b/board/src/imxrt1060evk.rs index 042938dd..973a46e7 100644 --- a/board/src/imxrt1060evk.rs +++ b/board/src/imxrt1060evk.rs @@ -60,16 +60,19 @@ pub type SpiPins = hal::lpspi::Pins< iomuxc::gpio_sd_b0::GPIO_SD_B0_02, // SDO, J24_4 iomuxc::gpio_sd_b0::GPIO_SD_B0_03, // SDI, J24_5 iomuxc::gpio_sd_b0::GPIO_SD_B0_00, // SCK, J24_6 - iomuxc::gpio_sd_b0::GPIO_SD_B0_01, // PCS0, J24_3 >; #[cfg(not(feature = "spi"))] /// Activate the `"spi"` feature to configure the SPI peripheral. pub type Spi = (); +#[cfg(not(feature = "spi"))] +pub type SpiCsPin = (); #[cfg(feature = "spi")] /// SPI peripheral. pub type Spi = hal::lpspi::Lpspi; +#[cfg(feature = "spi")] +pub type SpiCsPin = hal::gpio::Output; // PCS0, J24_3 type I2cScl = iomuxc::gpio_ad_b1::GPIO_AD_B1_00; // J24_10 type I2cSda = iomuxc::gpio_ad_b1::GPIO_AD_B1_01; // J24_9 @@ -130,6 +133,7 @@ pub struct Specifics { pub ports: GpioPorts, pub console: Console, pub spi: Spi, + pub spi_cs: SpiCsPin, pub i2c: I2c, pub pwm: Pwm, pub trng: hal::trng::Trng, @@ -172,7 +176,7 @@ impl Specifics { }); #[cfg(feature = "spi")] - let spi = { + let (spi, spi_cs) = { let lpspi1 = unsafe { ral::lpspi::LPSPI1::instance() }; let pins = SpiPins { sdo: iomuxc.gpio_sd_b0.p02, @@ -184,11 +188,12 @@ impl Specifics { spi.disabled(|spi| { spi.set_clock_hz(super::LPSPI_CLK_FREQUENCY, super::SPI_BAUD_RATE_FREQUENCY); }); - spi + let spi_cs = todo!(); + (spi, spi_cs) }; #[cfg(not(feature = "spi"))] #[allow(clippy::let_unit_value)] - let spi = (); + let (spi, spi_cs) = ((), ()); let lpi2c1 = unsafe { ral::lpi2c::LPI2C1::instance() }; let i2c = I2c::new( @@ -228,6 +233,7 @@ impl Specifics { ports: GpioPorts { gpio5 }, console, spi, + spi_cs, i2c, pwm, trng, diff --git a/board/src/imxrt1170evk-cm7.rs b/board/src/imxrt1170evk-cm7.rs index 9a8246a8..f7ff57cb 100644 --- a/board/src/imxrt1170evk-cm7.rs +++ b/board/src/imxrt1170evk-cm7.rs @@ -92,14 +92,18 @@ pub type SpiPins = hal::lpspi::Pins< iomuxc::gpio_ad::GPIO_AD_30, // SDO, J10_8 iomuxc::gpio_ad::GPIO_AD_31, // SDI, J10_10 iomuxc::gpio_ad::GPIO_AD_28, // SCK, J10_12 - iomuxc::gpio_ad::GPIO_AD_29, // PCS0, J10_6 >; const SPI_INSTANCE: u8 = 1; #[cfg(feature = "spi")] pub type Spi = hal::lpspi::Lpspi; +#[cfg(feature = "spi")] +pub type SpiCsPin = hal::gpio::Output; // PCS0, J10_6 + #[cfg(not(feature = "spi"))] pub type Spi = (); +#[cfg(not(feature = "spi"))] +pub type SpiCsPin = (); pub type I2cPins = hal::lpi2c::Pins< iomuxc::gpio_lpsr::GPIO_LPSR_05, // SCL, J10_20 @@ -160,6 +164,7 @@ pub struct Specifics { pub tp1002: Tp1002, pub tp1003: Tp1003, pub spi: Spi, + pub spi_cs: SpiCsPin, pub pwm: Pwm, pub i2c: I2c, } @@ -201,7 +206,7 @@ impl Specifics { hal::usbphy::restart_pll(&mut common.usbphy1); #[cfg(feature = "spi")] - let spi = { + let (spi, spi_cs) = { let lpspi1 = unsafe { ral::lpspi::LPSPI1::instance() }; let pins = SpiPins { sdo: iomuxc.gpio_ad.p30, @@ -213,11 +218,12 @@ impl Specifics { spi.disabled(|spi| { spi.set_clock_hz(LPSPI_CLK_FREQUENCY, super::SPI_BAUD_RATE_FREQUENCY); }); - spi + let spi_cs = todo!(); + (spi, spi_cs) }; #[cfg(not(feature = "spi"))] #[allow(clippy::let_unit_value)] - let spi = (); + let (spi, spi_cs) = ((), ()); #[cfg(not(feature = "spi"))] let pwm = { @@ -259,6 +265,7 @@ impl Specifics { tp1002: iomuxc.gpio_emc_b1.p40, tp1003: iomuxc.gpio_emc_b1.p41, spi, + spi_cs, pwm, i2c, } diff --git a/board/src/teensy4.rs b/board/src/teensy4.rs index 2f50d6e0..9826cea7 100644 --- a/board/src/teensy4.rs +++ b/board/src/teensy4.rs @@ -54,10 +54,14 @@ pub type SpiPins = hal::lpspi::Pins< #[cfg(not(feature = "spi"))] /// Activate the `"spi"` feature to configure the SPI peripheral. pub type Spi = (); +#[cfg(not(feature = "spi"))] +pub type SpiCsPin = (); #[cfg(feature = "spi")] /// SPI peripheral. pub type Spi = hal::lpspi::Lpspi; +#[cfg(feature = "spi")] +pub type SpiCsPin = hal::gpio::Output; // PCS0, P10 pub type I2cPins = hal::lpi2c::Pins< iomuxc::gpio_ad_b1::GPIO_AD_B1_07, // SCL, P16 @@ -110,6 +114,7 @@ pub struct Specifics { pub ports: GpioPorts, pub console: Console, pub spi: Spi, + pub spi_cs: SpiCsPin, pub i2c: I2c, pub pwm: Pwm, pub trng: hal::trng::Trng, @@ -126,7 +131,7 @@ impl Specifics { let mut gpio2 = hal::gpio::Port::new(gpio2); #[cfg(not(feature = "spi"))] - let led = gpio2.output(iomuxc.gpio_b0.p03); + let led = gpio2.output(iomuxc.gpio_b0.p03, false); #[cfg(feature = "spi")] let led = (); @@ -146,7 +151,7 @@ impl Specifics { }); #[cfg(feature = "spi")] - let spi = { + let (spi, spi_cs) = { let lpspi4 = unsafe { ral::lpspi::LPSPI4::instance() }; let pins = SpiPins { sdo: iomuxc.gpio_b0.p02, @@ -157,11 +162,12 @@ impl Specifics { spi.disabled(|spi| { spi.set_clock_hz(super::LPSPI_CLK_FREQUENCY, super::SPI_BAUD_RATE_FREQUENCY); }); - spi + let spi_cs = gpio2.output(iomuxc.gpio_b0.p00, true); + (spi, spi_cs) }; #[cfg(not(feature = "spi"))] #[allow(clippy::let_unit_value)] - let spi = (); + let (spi, spi_cs) = ((), ()); let lpi2c3 = unsafe { ral::lpi2c::LPI2C3::instance() }; let i2c = I2c::new( @@ -201,6 +207,7 @@ impl Specifics { ports: GpioPorts { gpio2 }, console, spi, + spi_cs, i2c, pwm, trng,