added examples
This commit is contained in:
67
examples/esp32c6-sync/src/bin/main.rs
Normal file
67
examples/esp32c6-sync/src/bin/main.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![deny(
|
||||
clippy::mem_forget,
|
||||
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
|
||||
holding buffers for the duration of a data transfer."
|
||||
)]
|
||||
|
||||
use esp_println::println;
|
||||
use as7265x::{AS7265XConfig, Channel, AS7265X};
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::{i2c, main};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
esp_bootloader_esp_idf::esp_app_desc!();
|
||||
|
||||
#[main]
|
||||
fn main() -> ! {
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
let device = esp_hal::i2c::master::I2c::new(peripherals.I2C0, i2c::master::Config::default())
|
||||
.unwrap()
|
||||
.with_sda(peripherals.GPIO22)
|
||||
.with_scl(peripherals.GPIO23);
|
||||
|
||||
let delay = esp_hal::delay::Delay::new();
|
||||
|
||||
let mut as7265x_device = AS7265X::new(device, AS7265XConfig::default(), delay);
|
||||
|
||||
as7265x_device.init().expect("Failed to init");
|
||||
|
||||
loop {
|
||||
println!("Taking messurment...");
|
||||
|
||||
as7265x_device
|
||||
.mesure_with_bulb()
|
||||
.expect("Failed to run messurment");
|
||||
|
||||
println!(
|
||||
"Channel A: {}",
|
||||
as7265x_device
|
||||
.read_calibrated_messurement(Channel::A)
|
||||
.expect("Failed to read value")
|
||||
);
|
||||
|
||||
println!(
|
||||
"Channel B: {}",
|
||||
as7265x_device
|
||||
.read_calibrated_messurement(Channel::B)
|
||||
.expect("Failed to read value")
|
||||
);
|
||||
|
||||
println!(
|
||||
"Channel F: {}",
|
||||
as7265x_device
|
||||
.read_calibrated_messurement(Channel::F)
|
||||
.expect("Failed to read value")
|
||||
);
|
||||
|
||||
delay.delay_millis(1000);
|
||||
}
|
||||
}
|
||||
1
examples/esp32c6-sync/src/lib.rs
Normal file
1
examples/esp32c6-sync/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
#![no_std]
|
||||
Reference in New Issue
Block a user