-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:?}"), | ||
} | ||
} | ||
} | ||
} |