WIP
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
runner = "espflash flash --monitor --chip esp32"
|
||||
|
||||
[env]
|
||||
ESP_LOG = "info"
|
||||
|
||||
[build]
|
||||
rustflags = [
|
||||
|
||||
18
esp/rust/02_esp-gen-no-std/Cargo.lock
generated
18
esp/rust/02_esp-gen-no-std/Cargo.lock
generated
@@ -268,12 +268,15 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "esp-gen-test"
|
||||
name = "esp-gen-no-std"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"esp-bootloader-esp-idf",
|
||||
"esp-hal",
|
||||
"esp-println",
|
||||
"fugit",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -356,6 +359,19 @@ dependencies = [
|
||||
"esp-metadata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "esp-println"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e7e3ab41e96093d7fd307e93bfc88bd646a8ff23036ebf809e116b18869f719"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"document-features",
|
||||
"esp-metadata-generated",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "esp-riscv-rt"
|
||||
version = "0.12.0"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "esp-gen-test"
|
||||
name = "esp-gen-no-std"
|
||||
rust-version = "1.86"
|
||||
version = "0.1.0"
|
||||
|
||||
[[bin]]
|
||||
name = "esp-gen-test"
|
||||
name = "blinky-i2c-scanner"
|
||||
path = "./src/bin/main.rs"
|
||||
|
||||
[dependencies]
|
||||
@@ -13,6 +13,9 @@ esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||
esp-hal = { version = "=1.0.0-rc.0", features = ["esp32"] }
|
||||
|
||||
critical-section = "1.2.0"
|
||||
esp-println = { version = "0.15.0", features = ["esp32", "log-04"] }
|
||||
log = "0.4.28"
|
||||
fugit = "0.3.7"
|
||||
|
||||
|
||||
[profile.dev]
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
holding buffers for the duration of a data transfer."
|
||||
)]
|
||||
|
||||
use esp_hal::i2c::master::BusTimeout;
|
||||
use esp_hal::{
|
||||
clock::CpuClock,
|
||||
gpio::{Level, Output, OutputConfig},
|
||||
main,
|
||||
time::{Duration, Instant}
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use fugit::RateExtU32;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_: &core::panic::PanicInfo) -> ! {
|
||||
@@ -25,11 +27,29 @@ esp_bootloader_esp_idf::esp_app_desc!();
|
||||
#[main]
|
||||
fn main() -> ! {
|
||||
// generator version: 0.5.0
|
||||
esp_println::logger::init_logger_from_env();
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
let i2c_config = esp_hal::i2c::master::Config::default().with_timeout(BusTimeout::Maximum);
|
||||
let mut i2c = esp_hal::i2c::master::I2c::new(peripherals.I2C0, i2c_config)
|
||||
.unwrap()
|
||||
.with_sda(peripherals.GPIO21)
|
||||
.with_scl(peripherals.GPIO22);
|
||||
|
||||
let mut led = Output::new(peripherals.GPIO2, Level::High, OutputConfig::default());
|
||||
loop {
|
||||
log::info!("Scanning for I2C devices..");
|
||||
for i in 0..=127u8 {
|
||||
let res = i2c.read(i, &mut [0]);
|
||||
match res {
|
||||
Ok(_) => {
|
||||
log::info!("Device found at address: {}", i);
|
||||
}
|
||||
Err(err) => {
|
||||
log::warn!("Failed to read device address: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
led.toggle();
|
||||
let delay_start = Instant::now();
|
||||
while delay_start.elapsed() < Duration::from_millis(500) {}
|
||||
|
||||
Reference in New Issue
Block a user