From c3b67ba88a2f6e3cbb440b57fd1f6012d70fea54 Mon Sep 17 00:00:00 2001 From: Scott Gibb <44235263+ScottGibb@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:14:08 +0000 Subject: [PATCH] Add PicoW test suite (#53) * cold start tests are now generic * setting register tests now generic * updated CI to use Linux Tests * fixed markdown lint issue * refactored into test crate * updated CI and tests documentation * restructured tests and now use common folder. Paths work and can call tests from the top folder * added breaking changes. Cant seem to get the i2c shared bus to work investigating changing traits * reverted change * fixed bus mutex example * fixed readme links * added first stab at esp test harness * Attempting to pass i2c * rearranging dependencies * cargo test runs but cant link rust-lld * Start from scratch * removed old workspace * test framework works using cargo test inside the esp32c3 tests folder * removed unecessary log feature * removed extra dependancies * doc changes * added first esp32 i2c test * removed unused aliases * restructured tests to make reusable tests * Seperated workspaces as the MCU environemnts might have different lock files * removed them from library workspace * removed unecessary noise * Updated docs * updated examples * cold_start_tests confirmed working * added setting_register_tests * added CI updated tests * Fixed broken links * updated lint checks for new tests directory * moved esp32c3 example * fixed workflows * fixed rust analyser * Fixed Links * addressing clippy warning * Updated docs * added probe-rs to pipeline * [MegaLinter] Apply linters automatic fixes (#49) * fixing install * Added missing dependencies * removing bininstall * debugging * adding probe-rs * Added back in tests * [MegaLinter] Apply linters automatic fixes (#50) * fixed apt in workflow and changed imports back to original * fixed mut and imports * fixed public * added probe specifics * added probe reset * updating probe-rs install * fixing cmd * cahnging runner to use debian instead of ubuntu * swapping to bookworm * tagging bookworm docker version * tagged version * added missing installs * Splitting tests up * adding missing source * correcting order * disabled faulty test * fixed comment string * removed duplicated project * added config variable * fixed double quoting * formatting * Attempt at adding rp pico * cant seem to clear up i2c generics * added working rp pico example!! * tested and runs * updated workflow * update cargo dependencies * added missing toolchain * added short readme * updating structure and readme docs * Added docs updates * clippy issues and adding it to the CI * fixing names * Fixed names * investigate this * getting rid of probe resets * updated broken link * fixed rust analyser issue * minor tidying * further tidy up * removed todos * fixed docs * add space * spelling fix * added H * removing import * Bug Fix for naming * reducing boiler plate * fixing clippy issue * reduced boiler plate * adding target for clippy * making clippy happy * fixed clippy warning * agreed removed :) * fixed extra # * removed unecessary comments --- .github/workflows/continuous_build.yaml | 14 +- .github/workflows/continuous_integration.yaml | 27 ++- .github/workflows/mega-linter.yaml | 7 + .gitignore | 3 +- .vscode/settings.json | 3 +- docs/ci pipeline diagram.drawio.svg | 216 +++++++++++++++--- examples/esp32c3/Cargo.toml | 4 +- tests-common/Cargo.toml | 2 +- tests-common/src/generic_cold_start_tests.rs | 3 +- .../src/generic_setting_registers_tests.rs | 1 - tests/README.md | 15 +- tests/esp32c3/Cargo.toml | 3 +- tests/linux.rs | 1 - tests/linux/cold_start_tests.rs | 22 +- tests/linux/setting_registers_tests.rs | 18 +- tests/pipico/.cargo/config.toml | 40 ++++ tests/pipico/Cargo.toml | 32 +++ tests/pipico/README.md | 7 + tests/pipico/build.rs | 6 + tests/pipico/memory.x | 15 ++ tests/pipico/src/lib.rs | 66 ++++++ tests/pipico/tests/cold_start_tests.rs | 69 ++++++ tests/pipico/tests/setting_register_tests.rs | 52 +++++ 23 files changed, 544 insertions(+), 82 deletions(-) create mode 100644 tests/pipico/.cargo/config.toml create mode 100644 tests/pipico/Cargo.toml create mode 100644 tests/pipico/README.md create mode 100644 tests/pipico/build.rs create mode 100644 tests/pipico/memory.x create mode 100644 tests/pipico/src/lib.rs create mode 100644 tests/pipico/tests/cold_start_tests.rs create mode 100644 tests/pipico/tests/setting_register_tests.rs diff --git a/.github/workflows/continuous_build.yaml b/.github/workflows/continuous_build.yaml index 741313cd..dc82de23 100644 --- a/.github/workflows/continuous_build.yaml +++ b/.github/workflows/continuous_build.yaml @@ -64,9 +64,9 @@ jobs: source "$HOME"/.cargo/env cargo build -p utils --features=rpi - # Due to issues around installing windows driver in CI, we are not compiling the FTDI examples on Windows - FTDI_Examples: - name: FTDI Examples + # Due to issues around installing windows driver in CI, we are not compiling the FT232 examples on Windows + FT232_Examples: + name: FT232 Examples runs-on: ${{ matrix.os }} strategy: matrix: @@ -82,19 +82,19 @@ jobs: if: runner.os == 'MacOS' run: | brew install libftdi - - name: Building FTDI Example 1 + - name: Building FT232 Example 1 run: | echo "Building Example 1" cargo build --example example_1_basic_readings --features=std - - name: Building FTDI Example 2 + - name: Building FT232 Example 2 run: | echo "Building Example 2" cargo build --example example_2_interrupts --features=std - - name: Building FTDI Example 3 + - name: Building FT232 Example 3 run: | echo "Building Example 3" cargo build --example example_3_angle_calculations --features=std - - name: Building FTDI Example 4 + - name: Building FT232 Example 4 run: | echo "Building Example 4" cargo build --example example_4_i2c_settings --features=std diff --git a/.github/workflows/continuous_integration.yaml b/.github/workflows/continuous_integration.yaml index 636551bc..ae6dc375 100644 --- a/.github/workflows/continuous_integration.yaml +++ b/.github/workflows/continuous_integration.yaml @@ -6,9 +6,6 @@ on: - main workflow_call: -env: - ESP32C3_UUID: 303a:1001:A0:76:4E:17:0B:90 - jobs: Linux_Tests: name: Linux Tests @@ -25,7 +22,7 @@ jobs: echo "Running FT232H Tests" source "$HOME"/.cargo/env cd tests - cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FTD232 + cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FT232H Raspberry_Pi_Tests: name: Raspberry Pi Tests @@ -62,5 +59,25 @@ jobs: echo "Running ESP32C3 Tests" source "$HOME"/.cargo/env cd tests/esp32c3 - probe-rs reset --probe="$ESP32C3_UUID" + cargo test # Probe UUID defined in .cargo/config.toml + + PiPico_Tests: + name: RP2040W Pico Tests + runs-on: self-hosted + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Rust and probe-rs + run: | + apt-get install --yes clang curl git libudev-dev libssl-dev pkg-config python3-pip + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + curl --proto '=https' --tlsv1.2 -LsSf https://github.com/probe-rs/probe-rs/releases/latest/download/probe-rs-tools-installer.sh | sh + source "$HOME"/.cargo/env + rustup toolchain install nightly --component rust-src + rustup target add thumbv6m-none-eabi + - name: RP2040W Pi Pico Tests + run: | + echo "Running RP2040W Pi Pico Tests" + source "$HOME"/.cargo/env + cd tests/pipico cargo test # Probe UUID defined in .cargo/config.toml diff --git a/.github/workflows/mega-linter.yaml b/.github/workflows/mega-linter.yaml index ca73e526..23763cf5 100644 --- a/.github/workflows/mega-linter.yaml +++ b/.github/workflows/mega-linter.yaml @@ -173,6 +173,8 @@ jobs: run: cargo fmt --manifest-path examples/esp32c3/Cargo.toml -- --check - name: Rustfmt check on esp32 tests run: cargo fmt --manifest-path tests/esp32c3/Cargo.toml -- --check + - name: Rustfmt check on pipico tests + run: cargo fmt --manifest-path tests/pipico/Cargo.toml -- --check cargo_clippy: name: Cargo Clippy @@ -188,3 +190,8 @@ jobs: run: | cd tests/esp32c3/ cargo clippy -- -D warnings + - name: Clippy on Pi Pico Tests + run: | + rustup target add thumbv6m-none-eabi + cd tests/pipico + cargo clippy -- -D warnings diff --git a/.gitignore b/.gitignore index a0d916d7..2d5a3d5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Compiled files -/target/ -utils/target/ +target # Dependency directories Cargo.lock diff --git a/.vscode/settings.json b/.vscode/settings.json index fd2a670f..296bb4eb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,8 @@ "rust-analyzer.linkedProjects": [ "utils/Cargo.toml", "examples/esp32c3/Cargo.toml", - "tests/esp32c3/Cargo.toml" + "tests/esp32c3/Cargo.toml", + "tests/pipico/Cargo.toml" ], "[rust]": { "editor.formatOnSave": true diff --git a/docs/ci pipeline diagram.drawio.svg b/docs/ci pipeline diagram.drawio.svg index f08573c2..ca041b5c 100644 --- a/docs/ci pipeline diagram.drawio.svg +++ b/docs/ci pipeline diagram.drawio.svg @@ -1,40 +1,46 @@ - + - + - + - + - + + + + + + + - - - - + + + + - + - + - - - + + + @@ -53,10 +59,12 @@ - + - - + + + + @@ -79,8 +87,8 @@ - - + + @@ -98,7 +106,7 @@ - + @@ -118,7 +126,7 @@ - + @@ -136,10 +144,10 @@ - + - - + + @@ -158,8 +166,8 @@ - - + + @@ -177,12 +185,12 @@ - + - - - + + + @@ -200,8 +208,8 @@ - - + + @@ -219,11 +227,11 @@ - + - - - + + + @@ -241,6 +249,142 @@ + + + + +
+
+
+ FT232H Breakout Board +
+
+
+
+ + FT232H Breakout... + +
+
+ + + + +
+
+
+ Adafruit +
+ QT Py ESP32C3 +
+
+
+
+ + Adafruit... + +
+
+ + + + + + + + + +
+
+
+ Pi Debug +
+ Probe +
+
+
+
+ + Pi Debug... + +
+
+ + + + + + + + +
+
+
+ USB +
+
+
+
+ + USB + +
+
+ + + + +
+
+
+ RP2040W +
+
+
+
+ + RP2040W + +
+
+ + + + + + +
+
+
+ I2C +
+
+
+
+ + I2C + +
+
+ + + + + + +
+
+
+ GP2 -> INT +
+
+
+
+ + GP2 -> INT + +
+
diff --git a/examples/esp32c3/Cargo.toml b/examples/esp32c3/Cargo.toml index 04b4d473..c4269ff9 100644 --- a/examples/esp32c3/Cargo.toml +++ b/examples/esp32c3/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "esp32-c3-example" +name = "esp32c3-example" version = "0.1.0" authors = [ "Scott Gibb (i2c: I2C) diff --git a/tests-common/src/generic_setting_registers_tests.rs b/tests-common/src/generic_setting_registers_tests.rs index 5d5fec45..c80ddceb 100644 --- a/tests-common/src/generic_setting_registers_tests.rs +++ b/tests-common/src/generic_setting_registers_tests.rs @@ -1,4 +1,3 @@ -use core::assert_eq; use core::cell::RefCell; use embedded_hal_bus::i2c::RefCellDevice; use registers::*; diff --git a/tests/README.md b/tests/README.md index b1e3d0c0..d5f9129b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -11,19 +11,28 @@ interacting with the hardware. As such we must run our tests with one thread: ```bash cargo test -- --test-threads=1 # Run all tests (Will need to be on a Pi with MCUs and others plugged in) -cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FTD232 -cargo test --test linux --features=rpi -- --test-threads=1 #Run Linux Tests using Raspberry Pi I2C +cargo test --test linux --features=std -- --test-threads=1 # Run Linux Tests using FT232H +cargo test --test linux --features=rpi -- --test-threads=1 # Run Linux Tests using Raspberry Pi I2C ``` ### ESP32C3 Tests -Since we are using an MCU target we require a seperate cargo workspace in order to set up the embedded test suite. More on this can be found in the following [README](./esp32c3/README.md). To run the tests on the ESP32C3 use the following code snippet: +Since we are using an MCU target we require a separate cargo workspace in order to set up the embedded test suite. More on this can be found in the following [README](./esp32c3/README.md). To run the tests on the ESP32C3 use the following code snippet: ```bash cd tests/esp32c3 cargo test # Will run all tests one after the other ``` +### Pi Pico + +The same setup as the ESP32C3 is also applied to the Pi Pico. More information on this can be found in the following [README](./pipico/README.md) You can run the tests using the [Pico Probe](https://thepihut.com/products/raspberry-pi-debug-probe) like so: + +```bash +cd tests/pipico +cargo test # Will run all tests one after the other +``` + ## Test Environments Currently we support testing on the following environments: diff --git a/tests/esp32c3/Cargo.toml b/tests/esp32c3/Cargo.toml index 5a1b5b28..7c977f98 100644 --- a/tests/esp32c3/Cargo.toml +++ b/tests/esp32c3/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] -# # dependencies for defmt +# Dependencies for defmt defmt = { version = "0.3.8"} defmt-rtt = { version = "0.4.1"} @@ -25,6 +25,7 @@ tmag5273 = { path = "../../" } [dev-dependencies] embedded-test = { version = "0.5.0", features =["defmt"] } tests-common = { path = "../../tests-common" } + # Test Files [[test]] name = "cold_start_tests" diff --git a/tests/linux.rs b/tests/linux.rs index 2d834bbb..5df33c5a 100644 --- a/tests/linux.rs +++ b/tests/linux.rs @@ -2,7 +2,6 @@ use tests_common as common; #[cfg(test)] pub mod linux { - // Reference the correct path to the test files pub mod cold_start_tests; pub mod setting_registers_tests; } diff --git a/tests/linux/cold_start_tests.rs b/tests/linux/cold_start_tests.rs index 9838bb89..78261ca2 100644 --- a/tests/linux/cold_start_tests.rs +++ b/tests/linux/cold_start_tests.rs @@ -3,65 +3,65 @@ use utils::setup_i2c; #[test] pub fn test_device_id() { let i2c = setup_i2c().unwrap(); - generic_test_device_id(i2c); // Pass the i2c variable to the inner test function + generic_test_device_id(i2c); } #[test] fn test_manufacturer_id() { let i2c = setup_i2c().unwrap(); - generic_test_manufacturer_id(i2c); // Pass the i2c variable to the inner test function + generic_test_manufacturer_id(i2c); } #[test] fn test_registers() { let i2c = setup_i2c().unwrap(); - generic_test_registers(i2c); // Pass the i2c variable to the inner test function + generic_test_registers(i2c); } #[test] fn test_default_i2c_address() { let i2c = setup_i2c().unwrap(); - generic_test_default_i2c_address(i2c); // Pass the i2c variable to the inner test function + generic_test_default_i2c_address(i2c); } #[test] fn test_get_magnitude_first_boot() { let i2c = setup_i2c().unwrap(); - generic_test_get_magnitude_first_boot(i2c); // Pass the i2c variable to the inner test function + generic_test_get_magnitude_first_boot(i2c); } #[test] fn test_get_xyz_thresholds_first_boot() { let i2c = setup_i2c().unwrap(); - generic_test_get_xyz_thresholds_first_boot(i2c); // Pass the i2c variable to the inner test function + generic_test_get_xyz_thresholds_first_boot(i2c); } #[test] fn test_magnetic_gain() { let i2c = setup_i2c().unwrap(); - generic_test_magnetic_gain(i2c); // Pass the i2c variable to the inner test function + generic_test_magnetic_gain(i2c); } #[test] fn test_magnetic_offset_invalid_at_boot() { let i2c = setup_i2c().unwrap(); - generic_test_magnetic_offset_invalid_at_boot(i2c); // Pass the i2c variable to the inner test function + generic_test_magnetic_offset_invalid_at_boot(i2c); } #[test] fn test_temperature_invalid_at_boot() { let i2c = setup_i2c().unwrap(); - generic_test_temperature_invalid_at_boot(i2c); // Pass the i2c variable to the inner test function + generic_test_temperature_invalid_at_boot(i2c); } #[test] fn test_get_data_methods() { let i2c = setup_i2c().unwrap(); - generic_test_get_data_methods(i2c); // Pass the i2c variable to the inner test function + generic_test_get_data_methods(i2c); } #[test] fn test_get_angle() { let i2c = setup_i2c().unwrap(); - generic_test_get_angle(i2c); // Pass the i2c variable to the inner test function + generic_test_get_angle(i2c); } diff --git a/tests/linux/setting_registers_tests.rs b/tests/linux/setting_registers_tests.rs index 1fc5ed47..1eff3e83 100644 --- a/tests/linux/setting_registers_tests.rs +++ b/tests/linux/setting_registers_tests.rs @@ -10,53 +10,53 @@ pub fn test_i2c_setup_success() { #[test] fn test_is_connected() { let i2c = setup_i2c().unwrap(); - generic_test_is_connected(i2c); // Pass the i2c variable to the inner test function + generic_test_is_connected(i2c); } #[test] fn test_create_tmag5273() { let i2c = setup_i2c().unwrap(); - generic_test_create_tmag5273(i2c); // Pass the i2c variable to the inner test function + generic_test_create_tmag5273(i2c); } #[test] fn test_set_reset_device_config_1_register() { let i2c = setup_i2c().unwrap(); - generic_test_set_reset_device_config_1_register(i2c); // Pass the i2c variable to the inner test function + generic_test_set_reset_device_config_1_register(i2c); } #[test] fn test_set_reset_device_config_2_register() { let i2c = setup_i2c().unwrap(); - generic_test_reset_device_config_2_register(i2c); // Pass the i2c variable to the inner test function + generic_test_reset_device_config_2_register(i2c); } #[test] fn test_set_reset_i2c_address_register() { let i2c = setup_i2c().unwrap(); - generic_test_set_reset_i2c_address_register(i2c); // Pass the i2c variable to the inner test function + generic_test_set_reset_i2c_address_register(i2c); } #[test] fn test_set_reset_int_config_1_register() { let i2c = setup_i2c().unwrap(); - generic_test_set_reset_int_config_1_register(i2c); // Pass the i2c variable to the inner test function + generic_test_set_reset_int_config_1_register(i2c); } #[test] fn test_set_reset_sensor_config_1_register() { let i2c = setup_i2c().unwrap(); - generic_test_set_reset_sensor_config_1_register(i2c); // Pass the i2c variable to the inner test function + generic_test_set_reset_sensor_config_1_register(i2c); } #[test] fn test_set_reset_sensor_config_2_register() { let i2c = setup_i2c().unwrap(); - generic_test_set_reset_sensor_config_2_register(i2c); // Pass the i2c variable to the inner test function + generic_test_set_reset_sensor_config_2_register(i2c); } #[test] fn test_set_reset_t_config_register() { let i2c = setup_i2c().unwrap(); - generic_test_set_reset_t_config_register(i2c); // Pass the i2c variable to the inner test function + generic_test_set_reset_t_config_register(i2c); } diff --git a/tests/pipico/.cargo/config.toml b/tests/pipico/.cargo/config.toml new file mode 100644 index 00000000..45abaa23 --- /dev/null +++ b/tests/pipico/.cargo/config.toml @@ -0,0 +1,40 @@ +# +# Cargo Configuration for the https://github.com/rp-rs/rp-hal.git repository. +# +# Copyright (c) The RP-RS Developers, 2021 +# +# You might want to make a similar file in your own repository if you are +# writing programs for Raspberry Silicon microcontrollers. +# +# This file is MIT or Apache-2.0 as per the repository README.md file +# + +[build] +# Set the default target to match the Cortex-M0+ in the RP2040 +target = "thumbv6m-none-eabi" + +# Target specific options +[target.thumbv6m-none-eabi] +# Pass some extra options to rustc, some of which get passed on to the linker. +# +# * linker argument --nmagic turns off page alignment of sections (which saves +# flash space) +# * linker argument -Tlink.x tells the linker to use link.x as the linker +# script. This is usually provided by the cortex-m-rt crate, and by default +# the version in that crate will include a file called `memory.x` which +# describes the particular memory layout for your specific chip. +# * no-vectorize-loops turns off the loop vectorizer (seeing as the M0+ doesn't +# have SIMD) +rustflags = [ + "-C", "link-arg=--nmagic", + "-C", "link-arg=-Tlink.x", + "-C", "no-vectorize-loops", +] + +# This runner will make a UF2 file and then copy it to a mounted RP2040 in USB +# Bootloader mode: +# runner = "elf2uf2-rs -d" + +# This runner will find a supported SWD debug probe and flash your RP2040 over +# SWD: +runner = "probe-rs run --chip RP2040 --probe=2e8a:000c:E6633861A323542C" \ No newline at end of file diff --git a/tests/pipico/Cargo.toml b/tests/pipico/Cargo.toml new file mode 100644 index 00000000..6e8d5281 --- /dev/null +++ b/tests/pipico/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "pipico" +version = "0.1.0" +edition = "2021" + +[dependencies] +rp-pico = "0.9.0" +# dependencies for defmt +defmt = { version = "0.3.8"} +defmt-rtt = { version = "0.4.1"} +fugit = "0.3.7" +portable-atomic = {version = "1.7.0", features = ["critical-section"]} + + +[dev-dependencies] +embedded-test = { version = "0.5.0", features =["defmt"] } +tests-common = { path = "../../tests-common" } + +# Test Files +[[test]] +name = "cold_start_tests" +harness = false + +[[test]] +name = "setting_register_tests" +harness = false + +[lib] +test = false +bench = false + +[workspace] # Required so that its not attached to main workspace diff --git a/tests/pipico/README.md b/tests/pipico/README.md new file mode 100644 index 00000000..3d724f18 --- /dev/null +++ b/tests/pipico/README.md @@ -0,0 +1,7 @@ +# RP2040/W Test Suite + +## Summary + +This project is a very simple barebone test suite that uses [embedded-test](https://github.com/probe-rs/embedded-test) alongside the common tests crate found [here](../../tests-common/README.md). This allows us to test our driver on Rapsberry Pi Pico hardware using [probe-rs](https://github.com/probe-rs/probe-rs) and be able to run the regular `#[test]` statements as we would with `std` rust. + +At the moment, this codebase is being used on an [RP2040W](https://thepihut.com/products/raspberry-pi-pico-w?variant=41952994754755&country=GB¤cy=GBP&utm_medium=product_sync&utm_source=google&utm_content=sag_organic&utm_campaign=sag_organic&gad_source=1&gclid=Cj0KCQiAvvO7BhC-ARIsAGFyToWZjO2Q7E8yjbjFcBXdCe_0-jxRHtMKFWu4GxeYN51qq3B6_Bx4aTUaAlYKEALw_wcB), it should however work with the RP2040 as well. diff --git a/tests/pipico/build.rs b/tests/pipico/build.rs new file mode 100644 index 00000000..e72887a7 --- /dev/null +++ b/tests/pipico/build.rs @@ -0,0 +1,6 @@ +fn main() { + // add linker script for embedded-test!! + println!("cargo::rustc-link-arg-tests=-Tembedded-test.x"); + //link the defmt linker script + println!("cargo:rustc-link-arg=-Tdefmt.x"); +} diff --git a/tests/pipico/memory.x b/tests/pipico/memory.x new file mode 100644 index 00000000..070eac78 --- /dev/null +++ b/tests/pipico/memory.x @@ -0,0 +1,15 @@ +MEMORY { + BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} + +EXTERN(BOOT2_FIRMWARE) + +SECTIONS { + /* ### Boot loader */ + .boot2 ORIGIN(BOOT2) : + { + KEEP(*(.boot2)); + } > BOOT2 +} INSERT BEFORE .text; \ No newline at end of file diff --git a/tests/pipico/src/lib.rs b/tests/pipico/src/lib.rs new file mode 100644 index 00000000..3e50d590 --- /dev/null +++ b/tests/pipico/src/lib.rs @@ -0,0 +1,66 @@ +#![no_std] +/// This module is a simple setup method and type declarations that can be shared across the tests, reducing boiler plate code. +pub mod initialise { + use defmt_rtt as _; + use fugit::RateExtU32; + use rp_pico::{ + hal::{ + self, + clocks::ClockSource, + gpio::{ + self, + bank0::{Gpio18, Gpio19}, + FunctionI2c, Pin, PullUp, + }, + i2c::I2C, + }, + pac::{self, I2C1}, + }; + pub type PicoI2c = I2C< + I2C1, + ( + Pin, + Pin, + ), + >; + pub fn initialise() -> PicoI2c { + let mut pac = pac::Peripherals::take().unwrap(); + let mut watchdog = hal::watchdog::Watchdog::new(pac.WATCHDOG); + + // Configure the clocks + let clocks = hal::clocks::init_clocks_and_plls( + rp_pico::XOSC_CRYSTAL_FREQ, + pac.XOSC, + pac.CLOCKS, + pac.PLL_SYS, + pac.PLL_USB, + &mut pac.RESETS, + &mut watchdog, + ) + .unwrap(); + + // The single-cycle I/O block controls our GPIO pins + let sio = hal::sio::Sio::new(pac.SIO); + + // Set the pins to their default state + let pins = gpio::Pins::new( + pac.IO_BANK0, + pac.PADS_BANK0, + sio.gpio_bank0, + &mut pac.RESETS, + ); + + // Create the I²C driver, using the two pre-configured pins. This will fail + // at compile time if the pins are in the wrong mode, or if this I²C + // peripheral isn't available on these pins! + + hal::i2c::I2C::new_controller( + pac.I2C1, + pins.gpio18.reconfigure(), + pins.gpio19.reconfigure(), + 400.kHz(), + &mut pac.RESETS, + clocks.system_clock.get_freq(), + ) + } +} diff --git a/tests/pipico/tests/cold_start_tests.rs b/tests/pipico/tests/cold_start_tests.rs new file mode 100644 index 00000000..25923096 --- /dev/null +++ b/tests/pipico/tests/cold_start_tests.rs @@ -0,0 +1,69 @@ +#![no_std] +#![no_main] + +#[cfg(test)] +#[embedded_test::tests] +mod cold_start_tests { + use pipico::initialise::*; + use tests_common::generic_cold_start_tests::*; + + #[init] + fn init() -> PicoI2c { + initialise() + } + + #[test] + fn test_device_id(i2c: PicoI2c) { + generic_test_device_id(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_manufacturer_id(i2c: PicoI2c) { + generic_test_manufacturer_id(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_registers(i2c: PicoI2c) { + generic_test_registers(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_default_i2c_address(i2c: PicoI2c) { + generic_test_default_i2c_address(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_get_magnitude_first_boot(i2c: PicoI2c) { + generic_test_get_magnitude_first_boot(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_get_xyz_thresholds_first_boot(i2c: PicoI2c) { + generic_test_get_xyz_thresholds_first_boot(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_magnetic_gain(i2c: PicoI2c) { + generic_test_magnetic_gain(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_magnetic_offset_invalid_at_boot(i2c: PicoI2c) { + generic_test_magnetic_offset_invalid_at_boot(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_temperature_invalid_at_boot(i2c: PicoI2c) { + generic_test_temperature_invalid_at_boot(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_get_data_methods(i2c: PicoI2c) { + generic_test_get_data_methods(i2c); // Pass the i2c variable to the inner test function + } + + #[test] + fn test_get_angle(i2c: PicoI2c) { + generic_test_get_angle(i2c); // Pass the i2c variable to the inner test function + } +} diff --git a/tests/pipico/tests/setting_register_tests.rs b/tests/pipico/tests/setting_register_tests.rs new file mode 100644 index 00000000..87437d36 --- /dev/null +++ b/tests/pipico/tests/setting_register_tests.rs @@ -0,0 +1,52 @@ +#![no_std] +#![no_main] + +#[cfg(test)] +#[embedded_test::tests] + +mod setting_register_tests { + use pipico::initialise::*; + use tests_common::generic_setting_registers_tests::*; + + #[init] + fn init() -> PicoI2c { + initialise() + } + + #[test] + fn test_is_connected(i2c: PicoI2c) { + generic_test_is_connected(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_create_tmag5273(i2c: PicoI2c) { + generic_test_create_tmag5273(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_set_reset_device_config_1_register(i2c: PicoI2c) { + generic_test_set_reset_device_config_1_register(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_set_reset_device_config_2_register(i2c: PicoI2c) { + generic_test_reset_device_config_2_register(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_set_reset_i2c_address_register(i2c: PicoI2c) { + generic_test_set_reset_i2c_address_register(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_set_reset_int_config_1_register(i2c: PicoI2c) { + generic_test_set_reset_int_config_1_register(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_set_reset_sensor_config_1_register(i2c: PicoI2c) { + generic_test_set_reset_sensor_config_1_register(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_set_reset_sensor_config_2_register(i2c: PicoI2c) { + generic_test_set_reset_sensor_config_2_register(i2c); // Pass the i2c variable to the inner test function + } + #[test] + fn test_set_reset_t_config_register(i2c: PicoI2c) { + generic_test_set_reset_t_config_register(i2c); // Pass the i2c variable to the inner test function + } +}