Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
459 changes: 226 additions & 233 deletions examples/esp32/Cargo.lock

Large diffs are not rendered by default.

65 changes: 28 additions & 37 deletions examples/esp32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
embassy-executor = "0.9.0"
embassy-embedded-hal = "0.5"
esp-bootloader-esp-idf = "0.2.0"
esp-backtrace = { version = "0.17.0", features = [ "panic-handler", "println" ] }
esp-hal = { version = "1.0.0-rc.0", features = [ "unstable" ] }
esp-hal-embassy = { version = "0.9.0" }
esp-alloc = { version = "0.8.0" }
esp-storage = { version = "0.7.0" }
esp-println = { version = "0.15.0", features = ["log-04"] }
esp-radio = { version = "0.15.0", features = [ "unstable", "ble" ] }
esp-preempt = { version = "0.0.1", features = ["log-04"] }
embassy-executor = "0.9.1"
esp-bootloader-esp-idf = "0.3.0"
esp-backtrace = { version = "0.18.0", features = [ "panic-handler", "println" ] }
esp-hal = { version = "1.0.0-rc.1", features = [ "unstable" ] }
esp-alloc = { version = "0.9.0" }
esp-println = { version = "0.16.0", features = ["log-04"] }
esp-radio = { version = "0.16.0", features = ["ble", "log-04", "unstable"] }
esp-rtos = { version = "0.1.1", features = ["embassy", "esp-alloc", "esp-radio", "log-04"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the esp-alloc feature is needed. Likely works both with or without.

trouble-example-apps = { version = "0.1.0", path = "../apps", features = ["log"] }
trouble-host = { path = "../../host", features = ["default-packet-pool-mtu-255"] }
static_cell = "2"

# for 'ble_bas_storage'
embassy-embedded-hal = "0.5.0"
esp-storage = { version = "0.8.0" }

[features]
default = ["esp32c3"]

esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-hal-embassy/esp32", "esp-println/esp32", "esp-storage/esp32", "esp-radio/esp32", "esp-preempt/esp32", "esp-bootloader-esp-idf/esp32"]
esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-hal-embassy/esp32c2", "esp-println/esp32c2", "esp-storage/esp32c2", "esp-preempt/esp32c2", "esp-radio/esp32c2", "esp-bootloader-esp-idf/esp32c2"]
esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-hal-embassy/esp32c3", "esp-println/esp32c3", "esp-storage/esp32c3", "esp-preempt/esp32c3", "esp-radio/esp32c3", "esp-bootloader-esp-idf/esp32c3"]
esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-hal-embassy/esp32c6", "esp-println/esp32c6", "esp-storage/esp32c6", "esp-preempt/esp32c6", "esp-radio/esp32c6", "esp-bootloader-esp-idf/esp32c6"]
esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-hal-embassy/esp32h2", "esp-println/esp32h2", "esp-storage/esp32h2", "esp-preempt/esp32h2", "esp-radio/esp32h2", "esp-bootloader-esp-idf/esp32h2"]
esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-hal-embassy/esp32s3", "esp-println/esp32s3", "esp-storage/esp32s3", "esp-preempt/esp32s3", "esp-radio/esp32s3", "esp-bootloader-esp-idf/esp32s3"]
esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-println/esp32", "esp-radio/esp32", "esp-rtos/esp32", "esp-storage/esp32", "esp-bootloader-esp-idf/esp32"]
esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-println/esp32c2", "esp-radio/esp32c2", "esp-rtos/esp32c2", "esp-storage/esp32c2", "esp-bootloader-esp-idf/esp32c2"]
esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-println/esp32c3", "esp-radio/esp32c3", "esp-rtos/esp32c3", "esp-storage/esp32c3", "esp-bootloader-esp-idf/esp32c3"]
esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-println/esp32c6", "esp-radio/esp32c6", "esp-rtos/esp32c6", "esp-storage/esp32c6", "esp-bootloader-esp-idf/esp32c6"]
esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-println/esp32h2", "esp-radio/esp32h2", "esp-rtos/esp32h2", "esp-storage/esp32h2", "esp-bootloader-esp-idf/esp32h2"]
esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-println/esp32s3", "esp-radio/esp32s3", "esp-rtos/esp32s3", "esp-storage/esp32s3", "esp-bootloader-esp-idf/esp32s3"]

security = [
"trouble-example-apps/security",
Expand Down Expand Up @@ -60,22 +60,13 @@ required-features = ["security"]
name = "ble_bas_peripheral_bonding"
required-features = ["security"]

[patch.crates-io]
esp-radio = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-preempt = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-storage = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-backtrace = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-hal = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-bootloader-esp-idf = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-hal-embassy = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-alloc = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}
esp-println = {git = "https://github.com/lulf/esp-hal.git", branch = "bt-hci-fix"}

#esp-backtrace = { path = "../../../esp-hal/esp-backtrace" }
#esp-bootloader-esp-idf = { path = "../../../esp-hal/esp-bootloader-esp-idf" }
#esp-hal = { path = "../../../esp-hal/esp-hal" }
#esp-hal-embassy = { path = "../../../esp-hal/esp-hal-embassy" }
#esp-alloc = { path = "../../../esp-hal/esp-alloc" }
#esp-println = { path = "../../../esp-hal/esp-println" }
#esp-radio = { path = "../../../esp-hal/esp-radio" }
#esp-preempt = { path = "../../../esp-hal/esp-preempt" }
# Enable for using latest 'main'
#[patch.crates-io]
#esp-alloc = { git = "https://github.com/esp-rs/esp-hal.git" }
#esp-backtrace = { git = "https://github.com/esp-rs/esp-hal.git" }
#esp-bootloader-esp-idf ={ git = "https://github.com/esp-rs/esp-hal.git" }
#esp-hal = { git = "https://github.com/esp-rs/esp-hal.git" }
#esp-println = { git = "https://github.com/esp-rs/esp-hal.git" }
#esp-radio = { git = "https://github.com/esp-rs/esp-hal.git" }
#esp-rtos = { git = "https://github.com/esp-rs/esp-hal.git" }
#esp-storage = { git = "https://github.com/esp-rs/esp-hal.git" }
24 changes: 5 additions & 19 deletions examples/esp32/src/bin/ble_bas_central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ use embassy_executor::Spawner;
use esp_hal::clock::CpuClock;
use esp_hal::timer::timg::TimerGroup;
use esp_radio::ble::controller::BleConnector;
use esp_radio::Controller;
use static_cell::StaticCell;
use trouble_example_apps::ble_bas_central;
use trouble_host::prelude::ExternalController;
use {esp_alloc as _, esp_backtrace as _};
use esp_backtrace as _;

esp_bootloader_esp_idf::esp_app_desc!();

#[esp_hal_embassy::main]
#[esp_rtos::main]
async fn main(_s: Spawner) {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));
Expand All @@ -23,27 +21,15 @@ async fn main(_s: Spawner) {
#[cfg(target_arch = "riscv32")]
let software_interrupt = esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

esp_preempt::start(
esp_rtos::start(
timg0.timer0,
#[cfg(target_arch = "riscv32")]
software_interrupt.software_interrupt0,
);

static RADIO: StaticCell<Controller<'static>> = StaticCell::new();
let radio = RADIO.init(esp_radio::init().unwrap());

#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(systimer.alarm0);
}
#[cfg(feature = "esp32")]
{
esp_hal_embassy::init(timg0.timer1);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those blocks are no longer needed, due to the API change (esp_rtos).


let radio = esp_radio::init().unwrap();
let bluetooth = peripherals.BT;
let connector = BleConnector::new(radio, bluetooth);
let connector = BleConnector::new(&radio, bluetooth, Default::default()).unwrap();
let controller: ExternalController<_, 20> = ExternalController::new(connector);

ble_bas_central::run(controller).await;
Expand Down
21 changes: 4 additions & 17 deletions examples/esp32/src/bin/ble_bas_central_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
use embassy_executor::Spawner;
use esp_hal::clock::CpuClock;
use esp_hal::timer::timg::TimerGroup;
use esp_radio::Controller;
use esp_radio::ble::controller::BleConnector;
use static_cell::StaticCell;
use trouble_example_apps::ble_bas_central_multiple;
use trouble_host::prelude::ExternalController;
use {esp_alloc as _, esp_backtrace as _};

esp_bootloader_esp_idf::esp_app_desc!();

#[esp_hal_embassy::main]
#[esp_rtos::main]
async fn main(_s: Spawner) {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));
Expand All @@ -23,27 +21,16 @@ async fn main(_s: Spawner) {
#[cfg(target_arch = "riscv32")]
let software_interrupt = esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

esp_preempt::start(
esp_rtos::start(
timg0.timer0,
#[cfg(target_arch = "riscv32")]
software_interrupt.software_interrupt0,
);

static RADIO: StaticCell<Controller<'static>> = StaticCell::new();
let radio = RADIO.init(esp_radio::init().unwrap());

#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(systimer.alarm0);
}
#[cfg(feature = "esp32")]
{
esp_hal_embassy::init(timg0.timer1);
}
let radio = esp_radio::init().unwrap();

let bluetooth = peripherals.BT;
let connector = BleConnector::new(radio, bluetooth);
let connector = BleConnector::new(&radio, bluetooth, Default::default()).unwrap();
let controller: ExternalController<_, 20> = ExternalController::new(connector);

ble_bas_central_multiple::run(controller).await;
Expand Down
22 changes: 4 additions & 18 deletions examples/esp32/src/bin/ble_bas_central_sec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use esp_hal::clock::CpuClock;
use esp_hal::rng::{Trng, TrngSource};
use esp_hal::timer::timg::TimerGroup;
use esp_radio::ble::controller::BleConnector;
use esp_radio::Controller;
use static_cell::StaticCell;
use trouble_example_apps::ble_bas_central_sec;
use trouble_host::prelude::ExternalController;
use {esp_alloc as _, esp_backtrace as _};

esp_bootloader_esp_idf::esp_app_desc!();

#[esp_hal_embassy::main]
#[esp_rtos::main]
async fn main(_s: Spawner) {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));
Expand All @@ -23,7 +21,7 @@ async fn main(_s: Spawner) {
#[cfg(target_arch = "riscv32")]
let software_interrupt = esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

esp_preempt::start(
esp_rtos::start(
timg0.timer0,
#[cfg(target_arch = "riscv32")]
software_interrupt.software_interrupt0,
Expand All @@ -32,21 +30,9 @@ async fn main(_s: Spawner) {
let _trng_source = TrngSource::new(peripherals.RNG, peripherals.ADC1);
let mut trng = Trng::try_new().unwrap(); // Ok when there's a TrngSource accessible

static RADIO: StaticCell<Controller<'static>> = StaticCell::new();
let radio = RADIO.init(esp_radio::init().unwrap());

#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(systimer.alarm0);
}
#[cfg(feature = "esp32")]
{
esp_hal_embassy::init(timg0.timer1);
}

let radio = esp_radio::init().unwrap();
let bluetooth = peripherals.BT;
let connector = BleConnector::new(radio, bluetooth);
let connector = BleConnector::new(&radio, bluetooth, Default::default()).unwrap();
let controller: ExternalController<_, 20> = ExternalController::new(connector);

ble_bas_central_sec::run(controller, &mut trng).await;
Expand Down
24 changes: 5 additions & 19 deletions examples/esp32/src/bin/ble_bas_peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ use embassy_executor::Spawner;
use esp_hal::clock::CpuClock;
use esp_hal::timer::timg::TimerGroup;
use esp_radio::ble::controller::BleConnector;
use esp_radio::Controller;
use static_cell::StaticCell;
use trouble_example_apps::ble_bas_peripheral;
use trouble_host::prelude::ExternalController;
use {esp_alloc as _, esp_backtrace as _};
use esp_backtrace as _;

esp_bootloader_esp_idf::esp_app_desc!();

#[esp_hal_embassy::main]
#[esp_rtos::main]
async fn main(_s: Spawner) {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));
Expand All @@ -22,27 +20,15 @@ async fn main(_s: Spawner) {
#[cfg(target_arch = "riscv32")]
let software_interrupt = esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

esp_preempt::start(
esp_rtos::start(
timg0.timer0,
#[cfg(target_arch = "riscv32")]
software_interrupt.software_interrupt0,
);

static RADIO: StaticCell<Controller<'static>> = StaticCell::new();
let radio = RADIO.init(esp_radio::init().unwrap());

#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(systimer.alarm0);
}
#[cfg(feature = "esp32")]
{
esp_hal_embassy::init(timg0.timer1);
}

let radio = esp_radio::init().unwrap();
let bluetooth = peripherals.BT;
let connector = BleConnector::new(radio, bluetooth);
let connector = BleConnector::new(&radio, bluetooth, Default::default()).unwrap();
let controller: ExternalController<_, 20> = ExternalController::new(connector);

ble_bas_peripheral::run(controller).await;
Expand Down
25 changes: 5 additions & 20 deletions examples/esp32/src/bin/ble_bas_peripheral_bonding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ use embassy_executor::Spawner;
use esp_hal::clock::CpuClock;
use esp_hal::rng::{Trng, TrngSource};
use esp_hal::timer::timg::TimerGroup;
use esp_radio::Controller;
use esp_radio::ble::controller::BleConnector;
use esp_storage::FlashStorage;
use static_cell::StaticCell;
use trouble_example_apps::ble_bas_peripheral_bonding;
use trouble_host::prelude::ExternalController;
use {esp_alloc as _, esp_backtrace as _};

esp_bootloader_esp_idf::esp_app_desc!();

#[esp_hal_embassy::main]
#[esp_rtos::main]
async fn main(_s: Spawner) {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));
Expand All @@ -24,35 +22,22 @@ async fn main(_s: Spawner) {
#[cfg(target_arch = "riscv32")]
let software_interrupt = esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

esp_preempt::start(
esp_rtos::start(
timg0.timer0,
#[cfg(target_arch = "riscv32")]
software_interrupt.software_interrupt0,
);

let _trng_source = TrngSource::new(peripherals.RNG, peripherals.ADC1);
let mut trng = Trng::try_new().unwrap(); // Ok when there's a TrngSource accessible

static RADIO: StaticCell<Controller<'static>> = StaticCell::new();
let radio = RADIO.init(esp_radio::init().unwrap());

#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(systimer.alarm0);
}
#[cfg(feature = "esp32")]
{
esp_hal_embassy::init(timg0.timer1);
}
let mut trng = Trng::try_new().unwrap();

let radio = esp_radio::init().unwrap();
let bluetooth = peripherals.BT;
let connector = BleConnector::new(radio, bluetooth);
let connector = BleConnector::new(&radio, bluetooth, Default::default()).unwrap();
let controller: ExternalController<_, 20> = ExternalController::new(connector);

// Initialize the flash
let mut flash = embassy_embedded_hal::adapter::BlockingAsync::new(FlashStorage::new(peripherals.FLASH));

// ble_bas_peripheral_sec::run(controller, &mut trng).await;
ble_bas_peripheral_bonding::run(controller, &mut trng, &mut flash).await;
}
22 changes: 4 additions & 18 deletions examples/esp32/src/bin/ble_bas_peripheral_sec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use esp_hal::clock::CpuClock;
use esp_hal::rng::{Trng, TrngSource};
use esp_hal::timer::timg::TimerGroup;
use esp_radio::ble::controller::BleConnector;
use esp_radio::Controller;
use static_cell::StaticCell;
use trouble_example_apps::ble_bas_peripheral_sec;
use trouble_host::prelude::ExternalController;
use {esp_alloc as _, esp_backtrace as _};

esp_bootloader_esp_idf::esp_app_desc!();

#[esp_hal_embassy::main]
#[esp_rtos::main]
async fn main(_s: Spawner) {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(esp_hal::Config::default().with_cpu_clock(CpuClock::max()));
Expand All @@ -23,7 +21,7 @@ async fn main(_s: Spawner) {
#[cfg(target_arch = "riscv32")]
let software_interrupt = esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

esp_preempt::start(
esp_rtos::start(
timg0.timer0,
#[cfg(target_arch = "riscv32")]
software_interrupt.software_interrupt0,
Expand All @@ -32,21 +30,9 @@ async fn main(_s: Spawner) {
let _trng_source = TrngSource::new(peripherals.RNG, peripherals.ADC1);
let mut trng = Trng::try_new().unwrap(); // Ok when there's a TrngSource accessible

static RADIO: StaticCell<Controller<'static>> = StaticCell::new();
let radio = RADIO.init(esp_radio::init().unwrap());

#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(systimer.alarm0);
}
#[cfg(feature = "esp32")]
{
esp_hal_embassy::init(timg0.timer1);
}

let radio = esp_radio::init().unwrap();
let bluetooth = peripherals.BT;
let connector = BleConnector::new(radio, bluetooth);
let connector = BleConnector::new(&radio, bluetooth, Default::default()).unwrap();
let controller: ExternalController<_, 20> = ExternalController::new(connector);

ble_bas_peripheral_sec::run(controller, &mut trng).await;
Expand Down
Loading
Loading