From 591c1153a4fc48ebc33b990ec482b973db6b9742 Mon Sep 17 00:00:00 2001 From: macronova Date: Sun, 22 Jun 2025 15:33:55 -0500 Subject: [PATCH] Blink --- xiao-esp32c6/src/bin/main.rs | 46 ++----------------------------- xiao-esp32c6/src/lib.rs | 52 +++++++++++++++++++++++++++++++++++ xiao-esp32c6/src/tasks/mod.rs | 1 + 3 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 xiao-esp32c6/src/tasks/mod.rs diff --git a/xiao-esp32c6/src/bin/main.rs b/xiao-esp32c6/src/bin/main.rs index 8c10f66..1b4dc0e 100644 --- a/xiao-esp32c6/src/bin/main.rs +++ b/xiao-esp32c6/src/bin/main.rs @@ -6,17 +6,9 @@ holding buffers for the duration of a data transfer." )] -use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::clock::CpuClock; -use esp_hal::timer::systimer::SystemTimer; -use esp_hal::timer::timg::TimerGroup; -use esp_wifi::ble::controller::BleConnector; -use log::info; - -extern crate alloc; +use xiao_esp32c6::entrypoint; // This creates a default app-descriptor required by the esp-idf bootloader. // For more information see: @@ -24,39 +16,5 @@ esp_bootloader_esp_idf::esp_app_desc!(); #[esp_hal_embassy::main] async fn main(spawner: Spawner) { - // generator version: 0.4.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); - - esp_alloc::heap_allocator!(size: 64 * 1024); - // COEX needs more RAM - so we've added some more - esp_alloc::heap_allocator!(#[unsafe(link_section = ".dram2_uninit")] size: 64 * 1024); - - let timer0 = SystemTimer::new(peripherals.SYSTIMER); - esp_hal_embassy::init(timer0.alarm0); - - info!("Embassy initialized!"); - - let rng = esp_hal::rng::Rng::new(peripherals.RNG); - let timer1 = TimerGroup::new(peripherals.TIMG0); - let wifi_init = esp_wifi::init(timer1.timer0, rng, peripherals.RADIO_CLK) - .expect("Failed to initialize WIFI/BLE controller"); - let (mut _wifi_controller, _interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI) - .expect("Failed to initialize WIFI controller"); - // find more examples https://github.com/embassy-rs/trouble/tree/main/examples/esp32 - let transport = BleConnector::new(&wifi_init, peripherals.BT); - let _ble_controller = ExternalController::<_, 20>::new(transport); - - // TODO: Spawn some tasks - let _ = spawner; - - loop { - info!("Hello world!"); - Timer::after(Duration::from_secs(1)).await; - } - - // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-beta.1/examples/src/bin + entrypoint(spawner).await } diff --git a/xiao-esp32c6/src/lib.rs b/xiao-esp32c6/src/lib.rs index 0c9ac1a..a4d4287 100644 --- a/xiao-esp32c6/src/lib.rs +++ b/xiao-esp32c6/src/lib.rs @@ -1 +1,53 @@ #![no_std] + +use bt_hci::controller::ExternalController; +use embassy_executor::Spawner; +use embassy_time::{Duration, Timer}; +use esp_hal::{ + clock::CpuClock, + gpio::{Level, Output, OutputConfig}, + timer::{systimer::SystemTimer, timg::TimerGroup}, +}; +use esp_wifi::ble::controller::BleConnector; + +pub mod tasks; + +pub async fn entrypoint(spawner: Spawner) { + // generator version: 0.4.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); + + esp_alloc::heap_allocator!(size: 64 * 1024); + // COEX needs more RAM - so we've added some more + esp_alloc::heap_allocator!(#[unsafe(link_section = ".dram2_uninit")] size: 64 * 1024); + + let timer0 = SystemTimer::new(peripherals.SYSTIMER); + esp_hal_embassy::init(timer0.alarm0); + + log::info!("Embassy initialized!"); + + let rng = esp_hal::rng::Rng::new(peripherals.RNG); + let timer1 = TimerGroup::new(peripherals.TIMG0); + let wifi_init = esp_wifi::init(timer1.timer0, rng, peripherals.RADIO_CLK) + .expect("Failed to initialize WIFI/BLE controller"); + let (mut _wifi_controller, _interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI) + .expect("Failed to initialize WIFI controller"); + // find more examples https://github.com/embassy-rs/trouble/tree/main/examples/esp32 + let transport = BleConnector::new(&wifi_init, peripherals.BT); + let _ble_controller = ExternalController::<_, 20>::new(transport); + + // TODO: Spawn some tasks + let _ = spawner; + let mut led = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default()); + + loop { + log::info!("Blink!"); + led.toggle(); + Timer::after(Duration::from_secs(1)).await; + } + + // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-beta.1/examples/src/bin +} diff --git a/xiao-esp32c6/src/tasks/mod.rs b/xiao-esp32c6/src/tasks/mod.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/xiao-esp32c6/src/tasks/mod.rs @@ -0,0 +1 @@ +