Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and Test check
jobs:
builds:
name: Build checks
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
matrix:
mode: ["", "--release"]
Expand Down Expand Up @@ -40,9 +40,12 @@ jobs:
target: thumbv6m-none-eabi
override: true
profile: minimal
- name: Check unused deps
uses: aig787/cargo-udeps-action@v1
with:
version: latest
args: ${{ matrix.mode }}
- name: Install cargo-hack
run: |
curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin
- name: Install cargo-udeps
run: |
curl -sSL https://github.com/est31/cargo-udeps/releases/download/v0.1.55/cargo-udeps-v0.1.55-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - --strip-components=2 -C ~/.cargo/bin ./cargo-udeps-v0.1.55-x86_64-unknown-linux-gnu/cargo-udeps
- name: Run cargo-udeps
run: cargo hack udeps --optional-deps --each-feature

20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,36 @@ fugit = "0.3.5"
defmt = { version = "0.3.0", optional = true }
either = { version = "1.10.0", default-features = false }
heapless = { version = "0.8.0", default-features = false }
futures = { version = "0.3.30", default-features = false, features = [
"async-await",
] }
embedded-hal-async = "1.0.0"
i2c-write-iter = { version = "1.0.0", features = ["async"], optional = true }

[profile.dev]
codegen-units = 1
incremental = false
lto = 'fat'
opt-level = 's'
debug = 2

[profile.test]
codegen-units = 1
incremental = false
lto = 'fat'
opt-level = 2
debug = 2

[profile.release]
codegen-units = 1
incremental = false
lto = 'fat'
opt-level = 's'
debug = 2

[features]
defmt = ["dep:defmt", "heapless/defmt-03", "embedded-hal-async/defmt-03"]
i2c-write-iter = ["dep:i2c-write-iter"]

[patch.crates-io]
rp2040-hal = { git = "https://github.com/ithinuel/rp-hal", branch = "async-pio" }
15 changes: 14 additions & 1 deletion on-target-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ publish = false
name = "i2c_loopback"
harness = false

[[test]]
name = "i2c_loopback_async"
harness = false

[dependencies]
i2c-pio = { path = "../", features = ["defmt"] }
i2c-pio = { path = "../", features = ["defmt", "i2c-write-iter"] }

cortex-m = "0.7"
cortex-m-rt = "0.7"
Expand Down Expand Up @@ -38,3 +42,12 @@ heapless = { version = "0.8.0", features = [
"defmt-03",
] }
itertools = { version = "0.12.0", default-features = false }
tinywake = { version = "0.2.2", features = ["cortex-m"] }
futures = { version = "0.3.30", default-features = false, features = [
"async-await",
] }

i2c-write-iter = { version = "1.0.0", features = [
"async",
"embedded-hal-async",
] }
100 changes: 100 additions & 0 deletions on-target-tests/tests/i2c_loopback_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//! This test needs a connection between:
//!
//! | from GPIO (pico Pin) | to GPIO (pico Pin) |
//! | -------------------- | ------------------ |
//! | 0 (1) | 2 (4) |
//! | 1 (2) | 3 (5) |

#![no_std]
#![no_main]
#![cfg(test)]

use defmt_rtt as _; // defmt transport
use defmt_test as _;
use panic_probe as _;
use rp2040_hal as hal; // memory layout // panic handler

use hal::{async_utils::AsyncPeripheral, pac::interrupt};

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
/// Note: This boot block is not necessary when using a rp-hal based BSP
/// as the BSPs already perform this step.
#[link_section = ".boot2"]
#[used]
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H;

/// External high-speed crystal on the Raspberry Pi Pico board is 12 MHz. Adjust
/// if your board has a different frequency
const XTAL_FREQ_HZ: u32 = 12_000_000u32;

pub mod i2c_tests;

#[interrupt]
unsafe fn PIO0_IRQ_0() {
rp2040_hal::pio::Rx::<rp2040_hal::pio::PIO0SM0>::on_interrupt(rp2040_hal::pio::PioIRQ::Irq0);
rp2040_hal::pio::Tx::<rp2040_hal::pio::PIO0SM0>::on_interrupt(rp2040_hal::pio::PioIRQ::Irq0);
rp2040_hal::pio::Interrupt::<'_, rp2040_hal::pac::PIO0, 0>::on_interrupt();
}

#[interrupt]
unsafe fn I2C1_IRQ() {
i2c_tests::Target::on_interrupt();
}

#[defmt_test::tests]
mod tests {
use crate::i2c_tests::{
non_blocking::{self, run_test, State},
ADDR_10BIT, ADDR_7BIT,
};

#[init]
fn setup() -> State {
non_blocking::system_setup(super::XTAL_FREQ_HZ, ADDR_7BIT)
}

#[test]
fn embedded_hal(state: &mut State) {
run_test(non_blocking::embedded_hal(state, ADDR_7BIT, 2..=2));
run_test(non_blocking::embedded_hal(state, ADDR_10BIT, 2..=7));
}

#[test]
fn transactions_iter(state: &mut State) {
run_test(non_blocking::transaction(state, ADDR_7BIT, 7..=9));
run_test(non_blocking::transaction(state, ADDR_10BIT, 7..=14));
}

#[test]
fn i2c_write_iter(state: &mut State) {
run_test(non_blocking::transaction_iter(state, ADDR_7BIT));
run_test(non_blocking::transaction_iter(state, ADDR_10BIT));
}

#[test]
fn transaction_iter(state: &mut State) {
run_test(non_blocking::transaction_iter(state, ADDR_7BIT));
run_test(non_blocking::transaction_iter(state, ADDR_10BIT));
}

// Sad paths:
// invalid tx buf on write
// invalid rx buf on read
//
// invalid (rx/tx) buf in transactions
//
// Peripheral Nack
#[test]
fn nak_on_addr(state: &mut State) {
run_test(non_blocking::nak_on_addr(state, ADDR_7BIT, ADDR_7BIT + 1));
run_test(non_blocking::nak_on_addr(state, ADDR_10BIT, ADDR_10BIT + 1));
run_test(non_blocking::nak_on_addr(
state,
ADDR_10BIT,
ADDR_10BIT + 0x100,
));
}
//
// Arbritration conflict
}
2 changes: 1 addition & 1 deletion on-target-tests/tests/i2c_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rp2040_hal::{
};

pub mod blocking;
//pub mod non_blocking;
pub mod non_blocking;

pub const ADDR_7BIT: u8 = 0x2c;
pub const ADDR_10BIT: u16 = 0x12c;
Expand Down
Loading
Loading