Skip to content

Commit

Permalink
Split SPI and CS pins in board subcrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Feb 24, 2024
1 parent 63a0927 commit bf5526e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
14 changes: 10 additions & 4 deletions board/src/imxrt1010evk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpiPins, 1>;
#[cfg(feature = "spi")]
pub type SpiCsPin = hal::gpio::Output<iomuxc::gpio_ad::GPIO_AD_05>; // 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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -247,6 +252,7 @@ impl Specifics {
ports: GpioPorts { gpio2 },
console,
spi,
spi_cs,
i2c,
pwm,
tp34: iomuxc.gpio_sd.p02,
Expand Down
14 changes: 10 additions & 4 deletions board/src/imxrt1060evk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpiPins, 1>;
#[cfg(feature = "spi")]
pub type SpiCsPin = hal::gpio::Output<iomuxc::gpio_sd_b0::GPIO_SD_B0_01>; // 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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -228,6 +233,7 @@ impl Specifics {
ports: GpioPorts { gpio5 },
console,
spi,
spi_cs,
i2c,
pwm,
trng,
Expand Down
15 changes: 11 additions & 4 deletions board/src/imxrt1170evk-cm7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpiPins, { SPI_INSTANCE }>;
#[cfg(feature = "spi")]
pub type SpiCsPin = hal::gpio::Output<iomuxc::gpio_ad::GPIO_AD_29>; // 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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down Expand Up @@ -259,6 +265,7 @@ impl Specifics {
tp1002: iomuxc.gpio_emc_b1.p40,
tp1003: iomuxc.gpio_emc_b1.p41,
spi,
spi_cs,
pwm,
i2c,
}
Expand Down
15 changes: 11 additions & 4 deletions board/src/teensy4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpiPins, 4>;
#[cfg(feature = "spi")]
pub type SpiCsPin = hal::gpio::Output<iomuxc::gpio_b0::GPIO_B0_00>; // PCS0, P10

pub type I2cPins = hal::lpi2c::Pins<
iomuxc::gpio_ad_b1::GPIO_AD_B1_07, // SCL, P16
Expand Down Expand Up @@ -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,
Expand All @@ -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 = ();

Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -201,6 +207,7 @@ impl Specifics {
ports: GpioPorts { gpio2 },
console,
spi,
spi_cs,
i2c,
pwm,
trng,
Expand Down

0 comments on commit bf5526e

Please sign in to comment.