Try jj
This commit is contained in:
parent
591c1153a4
commit
681d7410a4
8 changed files with 168 additions and 181 deletions
|
|
@ -1,53 +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},
|
||||
timer::systimer::SystemTimer,
|
||||
};
|
||||
use esp_wifi::ble::controller::BleConnector;
|
||||
|
||||
pub mod tasks;
|
||||
|
||||
pub async fn entrypoint(spawner: Spawner) {
|
||||
// generator version: 0.4.0
|
||||
|
||||
pub async fn entrypoint(spawner: Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
|
||||
log::info!("Initialized peripherals");
|
||||
|
||||
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);
|
||||
let system_timer = SystemTimer::new(peripherals.SYSTIMER);
|
||||
esp_hal_embassy::init(system_timer.alarm0);
|
||||
|
||||
log::info!("Embassy initialized!");
|
||||
log::info!("Initialized embassy");
|
||||
|
||||
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;
|
||||
log::info!("Initialized drivers");
|
||||
|
||||
spawner
|
||||
.spawn(tasks::wireless::setup_wireless(
|
||||
system_timer.alarm1,
|
||||
peripherals.BT,
|
||||
peripherals.RADIO_CLK,
|
||||
rng.clone(),
|
||||
peripherals.WIFI,
|
||||
))
|
||||
.expect("Failed to spawn task to setup wireless connections");
|
||||
|
||||
log::info!("Initializing wireless connections in background");
|
||||
|
||||
let mut led = Output::new(peripherals.GPIO15, Level::High, OutputConfig::default());
|
||||
|
||||
loop {
|
||||
log::info!("Blink!");
|
||||
log::info!("Slow blink!");
|
||||
led.toggle();
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
Timer::after(Duration::from_secs(2)).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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
|
||||
pub mod wireless;
|
||||
|
|
|
|||
31
xiao-esp32c6/src/tasks/wireless.rs
Normal file
31
xiao-esp32c6/src/tasks/wireless.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use bt_hci::controller::ExternalController;
|
||||
use embassy_executor::task;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use esp_hal::{
|
||||
peripherals::{BT, RADIO_CLK, WIFI},
|
||||
rng::Rng,
|
||||
timer::systimer::Alarm,
|
||||
};
|
||||
use esp_wifi::ble::controller::BleConnector;
|
||||
|
||||
#[task]
|
||||
pub async fn setup_wireless(
|
||||
alarm: Alarm<'static>,
|
||||
bt: BT<'static>,
|
||||
radio_clk: RADIO_CLK<'static>,
|
||||
rng: Rng,
|
||||
wifi: WIFI<'static>,
|
||||
) -> ! {
|
||||
let wifi_init =
|
||||
esp_wifi::init(alarm, rng, radio_clk).expect("Failed to initialize wireless module");
|
||||
// TODO: Use wifi controller
|
||||
let (_wifi_controller, _interfaces) =
|
||||
esp_wifi::wifi::new(&wifi_init, wifi).expect("Failed to initialize WIFI controller");
|
||||
let ble_connector = BleConnector::new(&wifi_init, bt);
|
||||
// TODO: Use bluetooth controller
|
||||
let _ble_controller = ExternalController::<_, 20>::new(ble_connector);
|
||||
loop {
|
||||
log::info!("No-op connection");
|
||||
Timer::after(Duration::from_secs(1)).await
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue