* Create the `hil-test` package * Add a simple integration test to verify basic GPIO functionality * WIP * feat: Update with esp-hal unification * build: Update dependencies * feat: Add a simple CI workflow test * ci: Avoid using a gh-hosted-runner to build * ci: Remove building bins in gh-hosted-runner * ci: Remove HIL Gpio CI test * ci: Test all the available tests * test: Add spi_full_duplex test * docs: Add documentation * test: Add uart test * style: Remove unused imports * docs: Update wiring, document H2 VM * ci: Enable H2 tests * ci: Add rust-cache action * docs: Document H2 vm * test: Add timeout * ci: Enable ESP32-C3 tests * feat: Add timeouts * feat: Add aes test * ci: Avoid running CI workflow when we change hil-test stuff * test: Remove warnings * feat: Address feedback * feat: Update features names and spi methods * ci: Remove rust-cache action * Update HIL to probe-rs#2292 (#1307) * feat: Update probe-rs/embedded-test to probe-rs#2292 * feat: Remove lib * ci: Use a matrix * ci: Enable ESP32C3 * feat: Add a way to cfg away test for unsuported peripherals * ci: Update trigger conditions * feat: Update pins to make it work on s3 * feat: Changes enabling S3 * feat: Remove log feature * feat: Adapt for rebase * feat: Remove env * feat: enable S3 * chore: Remove todo * build: Pin dependencies * feat: Add target alias * docs: Update readme * fix: Fix traits imports after rebase. Use debug * build: Remove lto * feat: Build tests on release mode --------- Co-authored-by: Jesse Braham <jesse@beta7.io>
73 lines
1.8 KiB
Rust
73 lines
1.8 KiB
Rust
//! GPIO Test
|
|
//!
|
|
//! Folowing pins are used:
|
|
//! GPIO2
|
|
//! GPIO4
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use defmt_rtt as _;
|
|
use embedded_hal::digital::{InputPin as _, OutputPin as _, StatefulOutputPin as _};
|
|
use esp_hal::{
|
|
gpio::{GpioPin, Input, Output, PullDown, PushPull, IO},
|
|
peripherals::Peripherals,
|
|
};
|
|
|
|
struct Context {
|
|
io2: GpioPin<Input<PullDown>, 2>,
|
|
io4: GpioPin<Output<PushPull>, 4>,
|
|
}
|
|
|
|
impl Context {
|
|
pub fn init() -> Self {
|
|
let peripherals = Peripherals::take();
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
|
|
Context {
|
|
io2: io.pins.gpio2.into_pull_down_input(),
|
|
io4: io.pins.gpio4.into_push_pull_output(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[embedded_test::tests]
|
|
mod tests {
|
|
use defmt::assert_eq;
|
|
|
|
use super::*;
|
|
|
|
#[init]
|
|
fn init() -> Context {
|
|
Context::init()
|
|
}
|
|
|
|
#[test]
|
|
fn test_gpio_input(mut ctx: Context) {
|
|
// `InputPin`:
|
|
assert_eq!(ctx.io2.is_low(), Ok(true));
|
|
assert_eq!(ctx.io2.is_high(), Ok(false));
|
|
}
|
|
|
|
#[test]
|
|
fn test_gpio_output(mut ctx: Context) {
|
|
// `StatefulOutputPin`:
|
|
assert_eq!(ctx.io4.is_set_low(), Ok(true));
|
|
assert_eq!(ctx.io4.is_set_high(), Ok(false));
|
|
assert!(ctx.io4.set_high().is_ok());
|
|
assert_eq!(ctx.io4.is_set_low(), Ok(false));
|
|
assert_eq!(ctx.io4.is_set_high(), Ok(true));
|
|
|
|
// `ToggleableOutputPin`:
|
|
assert!(ctx.io4.toggle().is_ok());
|
|
assert_eq!(ctx.io4.is_set_low(), Ok(true));
|
|
assert_eq!(ctx.io4.is_set_high(), Ok(false));
|
|
assert!(ctx.io4.toggle().is_ok());
|
|
assert_eq!(ctx.io4.is_set_low(), Ok(false));
|
|
assert_eq!(ctx.io4.is_set_high(), Ok(true));
|
|
// Leave in initial state for next test
|
|
assert!(ctx.io4.toggle().is_ok());
|
|
}
|
|
}
|