Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAL cleanups & remove example macros #261

Merged
merged 8 commits into from
Sep 7, 2023
Merged
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
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ jobs:
run: cd examples-${{ matrix.chip }} && cargo build --release --example=esp_now --features=esp-now
- name: check (embassy_esp_now)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=embassy_esp_now --features=async,esp-now
- name: check (esp_now_duplex)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=esp_now_duplex --features=async,esp-now
- name: check (esp_now_async_duplex)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=esp_now_async_duplex --features=async,esp-now
- name: check (embassy_esp_now_duplex)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=embassy_esp_now_duplex --features=async,esp-now
- name: check (embassy_dhcp)
run: cd examples-${{ matrix.chip }} && cargo build --release --example=embassy_dhcp --features=async,wifi,embassy-net
- name: check (embassy_access_point)
Expand All @@ -90,6 +88,9 @@ jobs:
- name: check (async_ble)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' }}
run: cd examples-${{ matrix.chip }} && cargo build --release --example=async_ble --features=async,ble
- name: check (coex)
if: ${{ matrix.chip == 'esp32' || matrix.chip == 'esp32s3' }}
run: cd examples-${{ matrix.chip }} && cargo build --release --example=coex --features=wifi,ble,coex

checks-riscv:
strategy:
Expand Down Expand Up @@ -120,10 +121,8 @@ jobs:
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=esp_now --features=esp-now
- name: check (embassy_esp_now)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=embassy_esp_now --features=async,esp-now
- name: check (esp_now_duplex)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=esp_now_duplex --features=async,esp-now
- name: check (esp_now_async_duplex)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=esp_now_async_duplex --features=async,esp-now
- name: check (embassy_esp_now_duplex)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=embassy_esp_now_duplex --features=async,esp-now
- name: check (embassy_dhcp)
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=embassy_dhcp --features=async,wifi,embassy-net
- name: check (embassy_access_point)
Expand All @@ -141,3 +140,6 @@ jobs:
- name: check (async_ble)
if: ${{ matrix.chip == 'esp32c2' || matrix.chip == 'esp32c3' }}
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=async_ble --features=async,ble
- name: check (coex)
if: ${{ matrix.chip == 'esp32c3' }}
run: cd examples-${{ matrix.chip }} && cargo +nightly-2023-05-16 build --release --example=coex --features=wifi,ble,coex
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ members = [
"esp-wifi",
"esp-wifi-sys",
"xtask",
"examples-util",
"examples-esp32c2",
"examples-esp32c3",
"examples-esp32c6",
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,11 @@ To build these ensure you are in the `examples-esp32XXX` directory matching your

`cargo run --example embassy_esp_now --release --features "async,esp-now"`

### esp_now_duplex

- broadcasts, sends and asynchronously receives messages via esp-now in multiple embassy tasks

`cargo run --example esp_now_duplex --release --features "async,esp-now"`

### esp_now_async_duplex
### embassy_esp_now_duplex

- asynchronously broadcasts, receives and sends messages via esp-now in multiple embassy tasks

`cargo run --example esp_now_async_duplex --release --features "async,esp-now"`
`cargo run --example embassy_esp_now_duplex --release --features "async,esp-now"`

### embassy_dhcp

Expand Down
21 changes: 2 additions & 19 deletions esp-wifi/src/timer_esp32c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::hal::interrupt::{self, TrapFrame};
use crate::hal::peripherals::{self, Interrupt};
use crate::hal::prelude::*;
use crate::hal::riscv;
use crate::hal::systimer::{Alarm, Periodic, Target};
use crate::hal::systimer::{Alarm, Periodic, SystemTimer, Target};
use critical_section::Mutex;

use crate::{binary, preempt::preempt::task_switch};
Expand Down Expand Up @@ -185,22 +185,5 @@ pub fn yield_task() {
/// Current systimer count value
/// A tick is 1 / 16_000_000 seconds
pub fn get_systimer_count() -> u64 {
critical_section::with(|_| unsafe {
let systimer = &(*peripherals::SYSTIMER::ptr());

systimer.unit0_op.write(|w| w.bits(1 << 30));

// wait for value available
loop {
let valid = (systimer.unit0_op.read().bits() >> 29) & 1;
if valid != 0 {
break;
}
}

let value_lo = systimer.unit0_value_lo.read().bits() as u64;
let value_hi = (systimer.unit0_value_hi.read().bits() as u64) << 32;

(value_lo | value_hi) as u64
})
SystemTimer::now()
}
21 changes: 2 additions & 19 deletions esp-wifi/src/timer_esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::hal::interrupt::{self, TrapFrame};
use crate::hal::peripherals::{self, Interrupt};
use crate::hal::prelude::*;
use crate::hal::riscv;
use crate::hal::systimer::{Alarm, Periodic, Target};
use crate::hal::systimer::{Alarm, Periodic, SystemTimer, Target};

use crate::{binary, preempt::preempt::task_switch};

Expand Down Expand Up @@ -197,22 +197,5 @@ pub fn yield_task() {
/// Current systimer count value
/// A tick is 1 / 16_000_000 seconds
pub fn get_systimer_count() -> u64 {
critical_section::with(|_| unsafe {
let systimer = &(*peripherals::SYSTIMER::ptr());

systimer.unit0_op.write(|w| w.bits(1 << 30));

// wait for value available
loop {
let valid = (systimer.unit0_op.read().bits() >> 29) & 1;
if valid != 0 {
break;
}
}

let value_lo = systimer.unit0_value_lo.read().bits() as u64;
let value_hi = (systimer.unit0_value_hi.read().bits() as u64) << 32;

(value_lo | value_hi) as u64
})
SystemTimer::now()
}
21 changes: 2 additions & 19 deletions esp-wifi/src/timer_esp32c6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::hal::interrupt::{self, TrapFrame};
use crate::hal::peripherals::{self, Interrupt};
use crate::hal::prelude::*;
use crate::hal::riscv;
use crate::hal::systimer::{Alarm, Periodic, Target};
use crate::hal::systimer::{Alarm, Periodic, SystemTimer, Target};

use crate::{binary, preempt::preempt::task_switch};

Expand Down Expand Up @@ -216,22 +216,5 @@ pub fn yield_task() {
/// Current systimer count value
/// A tick is 1 / 16_000_000 seconds
pub fn get_systimer_count() -> u64 {
critical_section::with(|_| unsafe {
let systimer = &(*peripherals::SYSTIMER::ptr());

systimer.unit0_op.write(|w| w.bits(1 << 30));

// wait for value available
loop {
let valid = (systimer.unit0_op.read().bits() >> 29) & 1;
if valid != 0 {
break;
}
}

let value_lo = systimer.unit0_value_lo.read().bits() as u64;
let value_hi = (systimer.unit0_value_hi.read().bits() as u64) << 32;

(value_lo | value_hi) as u64
})
SystemTimer::now()
}
1 change: 0 additions & 1 deletion examples-esp32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ embassy-net = { workspace = true, optional = true }
embassy-sync.workspace = true

esp32-hal.workspace = true
examples-util = { path = "../examples-util", features = ["esp32"] }
esp-backtrace = { workspace = true, features = ["esp32"] }
esp-wifi = { path = "../esp-wifi", default-features = false, features = ["esp32", "utils"] }
embedded-hal-async = { workspace = true, optional = true }
Expand Down
21 changes: 13 additions & 8 deletions examples-esp32/examples/access_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![feature(c_variadic)]
#![feature(const_mut_refs)]

#[path = "../../examples-util/util.rs"]
mod examples_util;
use examples_util::hal;

use embedded_io::blocking::*;
Expand All @@ -16,9 +18,9 @@ use esp_wifi::wifi::utils::create_network_interface;
use esp_wifi::wifi::WifiMode;
use esp_wifi::wifi_interface::WifiStack;
use esp_wifi::{current_millis, EspWifiInitFor};
use hal::clock::{ClockControl, CpuClock};
use hal::clock::ClockControl;
use hal::Rng;
use hal::{peripherals::Peripherals, prelude::*, Rtc};
use hal::{peripherals::Peripherals, prelude::*};

use smoltcp::iface::SocketStorage;

Expand All @@ -29,12 +31,15 @@ fn main() -> ! {

let peripherals = Peripherals::take();

let system = examples_util::system!(peripherals);
let mut peripheral_clock_control = system.peripheral_clock_control;
let clocks = examples_util::clocks!(system);
examples_util::rtc!(peripherals);
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::max(system.clock_control).freeze();

let timer = examples_util::timer!(peripherals, clocks, peripheral_clock_control);
let timer = esp32_hal::timer::TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
)
.timer0;
let init = initialize(
EspWifiInitFor::Wifi,
timer,
Expand All @@ -44,7 +49,7 @@ fn main() -> ! {
)
.unwrap();

let wifi = examples_util::get_wifi!(peripherals);
let (wifi, ..) = peripherals.RADIO.split();
let mut socket_set_entries: [SocketStorage; 3] = Default::default();
let (iface, device, mut controller, sockets) =
create_network_interface(&init, wifi, WifiMode::Ap, &mut socket_set_entries).unwrap();
Expand Down
35 changes: 20 additions & 15 deletions examples-esp32/examples/async_ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ use esp_println::println;
use esp_wifi::{
ble::controller::asynch::BleConnector, initialize, EspWifiInitFor, EspWifiInitialization,
};
#[path = "../../examples-util/util.rs"]
mod examples_util;
use examples_util::hal;
use examples_util::BootButton;
use hal::{
clock::{ClockControl, CpuClock},
embassy,
peripherals::*,
prelude::*,
radio::Bluetooth,
timer::TimerGroup,
Rng, Rtc, IO,
clock::ClockControl, embassy, peripherals::*, prelude::*, radio::Bluetooth, timer::TimerGroup,
Rng, IO,
};

#[embassy_executor::task]
Expand Down Expand Up @@ -134,12 +131,15 @@ fn main() -> ! {

let peripherals = Peripherals::take();

let system = examples_util::system!(peripherals);
let mut peripheral_clock_control = system.peripheral_clock_control;
let clocks = examples_util::clocks!(system);
examples_util::rtc!(peripherals);
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::max(system.clock_control).freeze();

let timer = examples_util::timer!(peripherals, clocks, peripheral_clock_control);
let timer = esp32_hal::timer::TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
)
.timer0;
let init = initialize(
EspWifiInitFor::Ble,
timer,
Expand All @@ -149,7 +149,8 @@ fn main() -> ! {
)
.unwrap();

let button = examples_util::boot_button!(peripherals);
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let button = io.pins.gpio0.into_pull_down_input();

// Async requires the GPIO interrupt to wake futures
hal::interrupt::enable(
Expand All @@ -158,9 +159,13 @@ fn main() -> ! {
)
.unwrap();

let bluetooth = examples_util::get_bluetooth!(peripherals);
let (_, bluetooth, ..) = peripherals.RADIO.split();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
embassy::init(&clocks, timer_group0.timer0);
let executor = EXECUTOR.init(Executor::new());
executor.run(|spawner| {
Expand Down
27 changes: 14 additions & 13 deletions examples-esp32/examples/ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ use bleps::{
use esp_backtrace as _;
use esp_println::println;
use esp_wifi::{ble::controller::BleConnector, initialize, EspWifiInitFor};
#[path = "../../examples-util/util.rs"]
mod examples_util;
use examples_util::hal;
use hal::{
clock::{ClockControl, CpuClock},
peripherals::*,
prelude::*,
Rng, Rtc, IO,
};
use hal::{clock::ClockControl, peripherals::*, prelude::*, Rng, IO};

#[entry]
fn main() -> ! {
Expand All @@ -26,12 +23,15 @@ fn main() -> ! {

let peripherals = Peripherals::take();

let system = examples_util::system!(peripherals);
let mut peripheral_clock_control = system.peripheral_clock_control;
let clocks = examples_util::clocks!(system);
examples_util::rtc!(peripherals);
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::max(system.clock_control).freeze();

let timer = examples_util::timer!(peripherals, clocks, peripheral_clock_control);
let timer = esp32_hal::timer::TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
)
.timer0;
let init = initialize(
EspWifiInitFor::Ble,
timer,
Expand All @@ -41,11 +41,12 @@ fn main() -> ! {
)
.unwrap();

let button = examples_util::boot_button!(peripherals);
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let button = io.pins.gpio0.into_pull_down_input();

let mut debounce_cnt = 500;

let mut bluetooth = examples_util::get_bluetooth!(peripherals);
let (_, mut bluetooth, ..) = peripherals.RADIO.split();

loop {
let connector = BleConnector::new(&init, &mut bluetooth);
Expand Down
Loading
Loading