Skip to content

Commit

Permalink
tests: Add i2c test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Jan 21, 2024
1 parent e7035da commit 548197f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/i2c/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "riot-wrappers-test-i2c"
version = "0.1.0"
authors = ["Christian Amsüss <[email protected]>"]
edition = "2021"
publish = false

[lib]
crate-type = ["staticlib"]

[profile.release]
panic = "abort"

[dependencies]
riot-wrappers = { version = "*", features = [ "set_panic_handler", "panic_handler_format" ] }
riot-sys = "*"
embedded-hal = "0.2"
8 changes: 8 additions & 0 deletions tests/i2c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# name of your application
APPLICATION = riot-wrappers-test-i2c
APPLICATION_RUST_MODULE = riot_wrappers_test_i2c
BASELIBS += $(APPLICATION_RUST_MODULE).module
FEATURES_REQUIRED += rust_target
FEATURES_REQUIRED += periph_i2c

include $(RIOTBASE)/Makefile.include
25 changes: 25 additions & 0 deletions tests/i2c/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! This is a primitive I2C scanner, and should thus report *something* interesting if any I2C
//! device is connected. (And reading should be safe on any device / bus).
#![no_std]

use embedded_hal::blocking::i2c::Read;

use riot_wrappers::println;
use riot_wrappers::riot_main;

riot_main!(main);

fn main() {
let mut i2c = riot_wrappers::i2c::I2CDevice::new(0); // FIXME from_number?

let mut buf = [0];

loop {
for i in 0..=127 {
match i2c.read(i, &mut buf) {
Ok(()) => println!("From {i}, read bytes: {:?}", &buf),
Err(e) => println!("From {i}, error {e:?}"),
}
}
}
}

0 comments on commit 548197f

Please sign in to comment.