Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test
  • Loading branch information
playfulFence committed Sep 4, 2024
commit 1ba2e65880c6cfd5b5cdc9f9cc12ac5aa1eccba1
2 changes: 1 addition & 1 deletion hil-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Our self-hosted runners have the following setup:
- ESP32-C6 (`esp32c6-usb`):
- Devkit: `ESP32-C6-DevKitC-1 V1.2` connected via USB-Serial-JTAG (`USB` port).
- `GPIO2` and `GPIO3` are connected.
- `GPIO5` and `GPIO6` are connected.
- `GPIO4` and `GPIO5` are connected.
- RPi: Raspbian 12 configured with the following [setup]
- ESP32-H2 (`esp32h2-usb`):
- Devkit: `ESP32-H2-DevKitM-1` connected via USB-Serial-JTAG (`USB` port).
Expand Down
42 changes: 42 additions & 0 deletions hil-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,45 @@ unsafe impl defmt::Logger for Logger {
use defmt_rtt as _;
// Make sure esp_backtrace is not removed.
use esp_backtrace as _;

use cfg_if::cfg_if;
// Define type aliases and macros for conditional pin assignments
cfg_if! {
if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
// Type alias for I2C pin configuration on S2 and S3 using GPIOs 2 and 3
pub type I2C_SCL_Pin = esp_hal::gpio::Gpio2;
pub type I2C_SDA_Pin = esp_hal::gpio::Gpio3;

// SPI pin aliases for avoiding conflicts with I2C on S2 and S3
pub type MFU_Pin1 = esp_hal::gpio::Gpio9;
pub type MFU_Pin2 = esp_hal::gpio::Gpio10;
} else if #[cfg(any(feature = "esp32c6"))] {
// Type alias for I2C pin configuration on C6 using GPIOs 6 and 7
pub type I2C_SCL_Pin = esp_hal::gpio::Gpio7;
pub type I2C_SDA_Pin = esp_hal::gpio::Gpio6;

/// SPI_MISO pin alias for avoiding conflicts with I2C on C6
pub type SPI_MISO_Pin = esp_hal::gpio::Gpio4;
/// SPI_MOSI pin alias for avoiding conflicts with I2C on C6
pub type SPI_MOSI_Pin = esp_hal::gpio::Gpio5;

/// Most
pub type MFU_Pin1 = esp_hal::gpio::Gpio2;
pub type MFU_Pin2 = esp_hal::gpio::Gpio3;
} else if #[cfg(any(feature = "esp32h2"))] {
// Type alias for I2C pin configuration on H2 using GPIOs 6 and 7
pub type I2C_SCL_Pin = esp_hal::gpio::Gpio6;
pub type I2C_SDA_Pin = esp_hal::gpio::Gpio7;

pub type MFU_Pin1 = esp_hal::gpio::Gpio2;
pub type MFU_Pin2 = esp_hal::gpio::Gpio3;
// No special pin assignments needed for SPI on H2
} else {
// Default case for other chips
pub type I2C_SCL_Pin = esp_hal::gpio::Gpio4;
pub type I2C_SDA_Pin = esp_hal::gpio::Gpio5;

pub type MFU_Pin1 = esp_hal::gpio::Gpio2;
pub type MFU_Pin2 = esp_hal::gpio::Gpio3;
}
}
34 changes: 15 additions & 19 deletions hil-test/tests/i2c.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! TWAI test
//! I2C test
//!
//! Folowing pins are used:
//! SCL GPIO4
Expand All @@ -24,44 +24,40 @@ use nb::block;
struct Context {
i2c: I2C<'static, I2C0, Blocking>,
}
#[cfg(test)]
#[embedded_test::tests]
mod tests {
use defmt::assert_ne;

use super::*;

impl Context {
pub fn init() -> Self {
#[init]
fn init() -> Context {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

let scl = unsafe { hil_test::I2C_SCL_Pin::steal() };
let sda = unsafe { hil_test::I2C_SDA_Pin::steal() };

// Create a new peripheral object with the described wiring and standard
// I2C clock speed:
let mut i2c = I2C::new(
peripherals.I2C0,
io.pins.gpio4,
io.pins.gpio7,
sda,
scl,
100.kHz(),
&clocks,
);

Context { i2c }
}
}

#[cfg(test)]
#[embedded_test::tests]
mod tests {
use defmt::assert_ne;

use super::*;

#[init]
fn init() -> Context {
Context::init()
}

#[test]
#[timeout(3)]
fn test_measures(mut ctx: Context) {
fn test_read_cali(mut ctx: Context) {
let mut read_data = [0u8; 22];

ctx.i2c.write_read(0x77, &[0xaa], &mut read_data).ok();
Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/spi_full_duplex_dma_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mod tests {
let sclk = io.pins.gpio0;
let mosi_mirror = io.pins.gpio2;
let mosi = io.pins.gpio3;
let miso = io.pins.gpio6;
let miso = unsafe { hil_test::SPI_MISO_Pin::steal() };
let cs = io.pins.gpio8;

let mut out_pin = Output::new(io.pins.gpio5, Level::Low);
Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/spi_full_duplex_dma_pcnt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod tests {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio0;
let mosi = io.pins.gpio3;
let miso = io.pins.gpio6;
let miso = unsafe { hil_test::SPI_MISO_Pin::steal() };
let cs = io.pins.gpio8;

let dma = Dma::new(peripherals.DMA);
Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/uart.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! UART Test
//!
//! Folowing pins are used:
//! TX GPIP2
//! TX GPIO2
//! RX GPIO3
//!
//! Connect TX (GPIO2) and RX (GPIO3) pins.
Expand Down