added examples
This commit is contained in:
16
examples/esp32c6-async/.cargo/config.toml
Normal file
16
examples/esp32c6-async/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.riscv32imac-unknown-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32c6"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
|
||||||
|
# NOTE: May negatively impact performance of produced code
|
||||||
|
"-C", "force-frame-pointers",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "riscv32imac-unknown-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["core"]
|
||||||
22
examples/esp32c6-async/.gitignore
vendored
Normal file
22
examples/esp32c6-async/.gitignore
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Editor configuration
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.nvim.lua
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1286
examples/esp32c6-async/Cargo.lock
generated
Normal file
1286
examples/esp32c6-async/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
examples/esp32c6-async/Cargo.toml
Normal file
39
examples/esp32c6-async/Cargo.toml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2024"
|
||||||
|
name = "esp32c6-async"
|
||||||
|
rust-version = "1.88"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "esp32c6-async"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-hal = { version = "1.0.0", features = ["esp32c6", "unstable"] }
|
||||||
|
|
||||||
|
esp-rtos = { version = "0.2.0", features = ["embassy", "esp32c6"] }
|
||||||
|
|
||||||
|
esp-bootloader-esp-idf = { version = "0.4.0", features = ["esp32c6"] }
|
||||||
|
|
||||||
|
embassy-executor = { version = "0.9.1", features = [] }
|
||||||
|
embassy-time = "0.5.0"
|
||||||
|
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
static_cell = "2.1.1"
|
||||||
|
|
||||||
|
as7265x = { path = "../..", features = ["async"] }
|
||||||
|
esp-println = { version = "0.16.1", features = ["esp32c6"] }
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
56
examples/esp32c6-async/build.rs
Normal file
56
examples/esp32c6-async/build.rs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
fn main() {
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!(
|
||||||
|
"💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"
|
||||||
|
);
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_rtos_initialized" | "esp_rtos_yield_task" | "esp_rtos_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!(
|
||||||
|
"💡 `esp-radio` has no scheduler enabled. Make sure you have initialized `esp-rtos` or provided an external scheduler."
|
||||||
|
);
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!(
|
||||||
|
"💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests"
|
||||||
|
);
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
4
examples/esp32c6-async/rust-toolchain.toml
Normal file
4
examples/esp32c6-async/rust-toolchain.toml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
|
components = ["rust-src"]
|
||||||
|
targets = ["riscv32imac-unknown-none-elf"]
|
||||||
77
examples/esp32c6-async/src/bin/main.rs
Normal file
77
examples/esp32c6-async/src/bin/main.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
examples/esp32c6-async/src/lib.rs
Normal file
1
examples/esp32c6-async/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#![no_std]
|
||||||
16
examples/esp32c6-sync/.cargo/config.toml
Normal file
16
examples/esp32c6-sync/.cargo/config.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[target.riscv32imac-unknown-none-elf]
|
||||||
|
runner = "espflash flash --monitor --chip esp32c6"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
|
||||||
|
# NOTE: May negatively impact performance of produced code
|
||||||
|
"-C", "force-frame-pointers",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "riscv32imac-unknown-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["core"]
|
||||||
22
examples/esp32c6-sync/.gitignore
vendored
Normal file
22
examples/esp32c6-sync/.gitignore
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Editor configuration
|
||||||
|
.vscode/
|
||||||
|
.zed/
|
||||||
|
.helix/
|
||||||
|
.nvim.lua
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# RustRover
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
1187
examples/esp32c6-sync/Cargo.lock
generated
Normal file
1187
examples/esp32c6-sync/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
examples/esp32c6-sync/Cargo.toml
Normal file
34
examples/esp32c6-sync/Cargo.toml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[package]
|
||||||
|
edition = "2024"
|
||||||
|
name = "esp32c6-sync"
|
||||||
|
rust-version = "1.88"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "esp32c6-sync"
|
||||||
|
path = "./src/bin/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
esp-hal = { version = "1.0.0", features = ["esp32c6","unstable"] }
|
||||||
|
|
||||||
|
esp-bootloader-esp-idf = { version = "0.4.0", features = ["esp32c6"] }
|
||||||
|
|
||||||
|
critical-section = "1.2.0"
|
||||||
|
|
||||||
|
as7265x = { path="../.." }
|
||||||
|
esp-println = { version = "0.16.1", features = ["esp32c6"] }
|
||||||
|
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
# Rust debug is too slow.
|
||||||
|
# For debug builds always builds with some optimization
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1 # LLVM can perform better optimizations using a single thread
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 's'
|
||||||
|
overflow-checks = false
|
||||||
56
examples/esp32c6-sync/build.rs
Normal file
56
examples/esp32c6-sync/build.rs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
fn main() {
|
||||||
|
linker_be_nice();
|
||||||
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
||||||
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn linker_be_nice() {
|
||||||
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
let kind = &args[1];
|
||||||
|
let what = &args[2];
|
||||||
|
|
||||||
|
match kind.as_str() {
|
||||||
|
"undefined-symbol" => match what.as_str() {
|
||||||
|
"_defmt_timestamp" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!(
|
||||||
|
"💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"
|
||||||
|
);
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"_stack_start" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"esp_rtos_initialized" | "esp_rtos_yield_task" | "esp_rtos_task_create" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!(
|
||||||
|
"💡 `esp-radio` has no scheduler enabled. Make sure you have initialized `esp-rtos` or provided an external scheduler."
|
||||||
|
);
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
||||||
|
eprintln!();
|
||||||
|
eprintln!(
|
||||||
|
"💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests"
|
||||||
|
);
|
||||||
|
eprintln!();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
// we don't have anything helpful for "missing-lib" yet
|
||||||
|
_ => {
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=--error-handling-script={}",
|
||||||
|
std::env::current_exe().unwrap().display()
|
||||||
|
);
|
||||||
|
}
|
||||||
4
examples/esp32c6-sync/rust-toolchain.toml
Normal file
4
examples/esp32c6-sync/rust-toolchain.toml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
|
components = ["rust-src"]
|
||||||
|
targets = ["riscv32imac-unknown-none-elf"]
|
||||||
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