added examples

This commit is contained in:
2025-12-15 18:22:32 +01:00
parent df33b51d52
commit 0513506b98
16 changed files with 2888 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
#![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 as7265x::{AS7265X, AS7265XConfig, Channel};
use embassy_executor::Spawner;
use embassy_time::{Delay, Duration, Timer};
use esp_hal::clock::CpuClock;
use esp_hal::i2c::master::I2c;
use esp_hal::timer::timg::TimerGroup;
use esp_println::println;
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
esp_bootloader_esp_idf::esp_app_desc!();
#[esp_rtos::main]
async fn main(_spawner: Spawner) -> ! {
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
let timg0 = TimerGroup::new(peripherals.TIMG0);
let sw_interrupt =
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
let i2c_config = esp_hal::i2c::master::Config::default();
let device: I2c<'_, esp_hal::Async> =
esp_hal::i2c::master::I2c::new(peripherals.I2C0, i2c_config)
.unwrap()
.with_sda(peripherals.GPIO22)
.with_scl(peripherals.GPIO23)
.into_async();
let mut as7265x_device = AS7265X::new(device, AS7265XConfig::default(), Delay);
as7265x_device.init().await.expect("Failed to init device");
loop {
println!("Taking messurment...");
as7265x_device.mesure_with_bulb().await.unwrap();
println!(
"Channel A: {}",
as7265x_device
.read_calibrated_messurement(Channel::A)
.await
.expect("Failed to read value")
);
println!(
"Channel B: {}",
as7265x_device
.read_calibrated_messurement(Channel::B)
.await
.expect("Failed to read value")
);
println!(
"Channel F: {}",
as7265x_device
.read_calibrated_messurement(Channel::F)
.await
.expect("Failed to read value")
);
Timer::after(Duration::from_secs(1)).await;
}
}

View File

@@ -0,0 +1 @@
#![no_std]