Skip to content

Commit

Permalink
Update esp-hal to 0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Apr 21, 2024
1 parent c7a96d0 commit 3b8b1d4
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 76 deletions.
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ embassy-time = { version = "0.3.0" }

embedded-hal-old = { package = "embedded-hal", version = "0.2.7" }

esp-hal = { version = "0.16.1", features = [
"rt",
esp-hal = { version = "0.17.0", features = [
"async",
"embassy",
"embassy-executor-thread",
"embassy-executor-interrupt",
"eh1",
"embedded-hal-02"
] }
esp-backtrace = { version = "0.11.1", features = [
"panic-handler",
Expand All @@ -67,7 +66,7 @@ esp-println = { version = "0.9.1", default-features = false, features = [
"critical-section",
] }
esp-alloc = "0.3.0"
esp-wifi = { version = "0.4.0", default-features = false, features = [
esp-wifi = { version = "0.5.0", default-features = false, features = [
"phy-enable-usb",
"ps-max-modem",
"wifi",
Expand Down
4 changes: 2 additions & 2 deletions gui/src/widgets/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ where
fn at(&self, _idx: usize) -> &dyn View {
match self {
Self::Hidden(_) => unsafe {
#[allow(static_mut_ref)]
#[allow(static_mut_refs)]
&EMPTY_VIEW_GROUP
},
Self::Visible(view) => view,
Expand All @@ -103,7 +103,7 @@ where
fn at_mut(&mut self, _idx: usize) -> &mut dyn View {
match self {
Self::Hidden(_) => unsafe {
#[allow(static_mut_ref)]
#[allow(static_mut_refs)]
&mut EMPTY_VIEW_GROUP
},
Self::Visible(view) => view,
Expand Down
18 changes: 10 additions & 8 deletions src/board/hardware/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ use esp_hal::{
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
rtc_cntl::Rtc,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
Async,
};

use display_interface_spi::SPIInterface;
Expand All @@ -35,7 +36,7 @@ pub type DisplayMosi = GpioPin<Output<PushPull>, 21>;

pub type DisplayInterface<'a> = SPIInterface<DisplaySpi<'a>, DisplayDataCommand>;
pub type DisplaySpi<'d> = ExclusiveDevice<
SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode>,
SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>,
DummyOutputPin,
Delay,
>;
Expand All @@ -51,7 +52,7 @@ pub type AdcDrdy = GpioPin<Input<Floating>, 4>;
pub type AdcReset = GpioPin<Output<PushPull>, 2>;
pub type TouchDetect = GpioPin<Input<Floating>, 1>;
pub type AdcSpi = ExclusiveDevice<
SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode>,
SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode, Async>,
AdcChipSelect,
Delay,
>;
Expand All @@ -69,7 +70,7 @@ pub type Display = DisplayType<DisplayReset>;
pub type BatteryFgI2cInstance = peripherals::I2C0;
pub type I2cSda = GpioPin<Unknown, 36>;
pub type I2cScl = GpioPin<Unknown, 35>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>;
pub type BatteryFg = BatteryFgType<BatteryFgI2c, BatteryAdcEnable>;

impl super::startup::StartupResources {
Expand All @@ -81,7 +82,7 @@ impl super::startup::StartupResources {
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::max(system.clock_control).freeze();

embassy::init(&clocks, SystemTimer::new(peripherals.SYSTIMER));
embassy::init(&clocks, SystemTimer::new_async(peripherals.SYSTIMER));

let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

Expand Down Expand Up @@ -137,13 +138,14 @@ impl super::startup::StartupResources {
wifi: static_cell::make_static! {
WifiDriver::new(
peripherals.WIFI,
TimerGroup::new(peripherals.TIMG1, &clocks).timer0,
TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0,
peripherals.RNG,
system.radio_clock_control,
)
},
clocks,
rtc: Rtc::new(peripherals.LPWR),
rtc: Rtc::new(peripherals.LPWR, None),
software_interrupt1: system.software_interrupt_control.software_interrupt1,
}
}
}
14 changes: 8 additions & 6 deletions src/board/hardware/v6c6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ use esp_hal::{
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
rtc_cntl::Rtc,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
Async,
};

pub use crate::board::drivers::bitbang_spi::BitbangSpi;
Expand All @@ -36,7 +37,7 @@ pub type DisplayMosi = GpioPin<Output<PushPull>, 21>;

pub type DisplayInterface<'a> = SPIInterface<DisplaySpi<'a>, DisplayDataCommand>;
pub type DisplaySpi<'d> = ExclusiveDevice<
SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode>,
SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>,
DummyOutputPin,
Delay,
>;
Expand Down Expand Up @@ -65,7 +66,7 @@ pub type Display = DisplayType<DisplayReset>;
pub type BatteryFgI2cInstance = peripherals::I2C0;
pub type I2cSda = GpioPin<Unknown, 19>;
pub type I2cScl = GpioPin<Unknown, 18>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>;
pub type BatteryFg = BatteryFgType<BatteryFgI2c, BatteryAdcEnable>;

impl super::startup::StartupResources {
Expand All @@ -77,7 +78,7 @@ impl super::startup::StartupResources {
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::max(system.clock_control).freeze();

embassy::init(&clocks, TimerGroup::new(peripherals.TIMG0, &clocks));
embassy::init(&clocks, TimerGroup::new_async(peripherals.TIMG0, &clocks));

let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

Expand Down Expand Up @@ -138,7 +139,8 @@ impl super::startup::StartupResources {
)
},
clocks,
rtc: Rtc::new(peripherals.LPWR),
rtc: Rtc::new(peripherals.LPWR, None),
software_interrupt1: system.software_interrupt_control.software_interrupt1,
}
}
}
18 changes: 10 additions & 8 deletions src/board/hardware/v6s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ use esp_hal::{
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown, IO},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
rtc_cntl::Rtc,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
Async,
};

pub type DisplaySpiInstance = peripherals::SPI2;
Expand All @@ -34,7 +35,7 @@ pub type DisplayMosi = GpioPin<Output<PushPull>, 38>;

pub type DisplayInterface<'a> = SPIInterface<DisplaySpi<'a>, DisplayDataCommand>;
pub type DisplaySpi<'d> = ExclusiveDevice<
SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode>,
SpiDma<'d, DisplaySpiInstance, Channel0, FullDuplexMode, Async>,
DummyOutputPin,
Delay,
>;
Expand All @@ -49,7 +50,7 @@ pub type AdcClockEnable = GpioPin<Output<PushPull>, 40>;
pub type AdcDrdy = GpioPin<Input<Floating>, 4>;
pub type AdcReset = GpioPin<Output<PushPull>, 42>;
pub type TouchDetect = GpioPin<Input<Floating>, 1>;
pub type AdcSpiBus = SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode>;
pub type AdcSpiBus = SpiDma<'static, AdcSpiInstance, Channel1, FullDuplexMode, Async>;
pub type AdcSpi = ExclusiveDevice<AdcSpiBus, AdcChipSelect, Delay>;

pub type BatteryAdcEnable = DummyOutputPin;
Expand All @@ -65,7 +66,7 @@ pub type Display = DisplayType<DisplayReset>;
pub type BatteryFgI2cInstance = peripherals::I2C0;
pub type I2cSda = GpioPin<Unknown, 36>;
pub type I2cScl = GpioPin<Unknown, 35>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance, Async>;
pub type BatteryFg = BatteryFgType<BatteryFgI2c, BatteryAdcEnable>;

impl super::startup::StartupResources {
Expand All @@ -77,7 +78,7 @@ impl super::startup::StartupResources {
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::max(system.clock_control).freeze();

embassy::init(&clocks, SystemTimer::new(peripherals.SYSTIMER));
embassy::init(&clocks, SystemTimer::new_async(peripherals.SYSTIMER));

let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

Expand Down Expand Up @@ -133,13 +134,14 @@ impl super::startup::StartupResources {
wifi: static_cell::make_static! {
WifiDriver::new(
peripherals.WIFI,
TimerGroup::new(peripherals.TIMG1, &clocks).timer0,
TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0,
peripherals.RNG,
system.radio_clock_control,
)
},
clocks,
rtc: Rtc::new(peripherals.LPWR),
rtc: Rtc::new(peripherals.LPWR, None),
software_interrupt1: system.software_interrupt_control.software_interrupt1,
}
}
}
34 changes: 12 additions & 22 deletions src/board/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ use esp_hal::{
dma::{DmaDescriptor, DmaPriority},
gpio::OutputPin as _,
interrupt, peripherals,
rtc_cntl::Rtc,
spi::{
master::{dma::*, Instance, Spi},
SpiMode,
},
Rtc,
system::SoftwareInterrupt,
};

#[cfg(feature = "esp32s3")]
Expand All @@ -50,6 +51,8 @@ pub struct StartupResources {

pub wifi: &'static mut WifiDriver,
pub rtc: Rtc<'static>,

pub software_interrupt1: SoftwareInterrupt<1>,
}

impl StartupResources {
Expand Down Expand Up @@ -117,18 +120,13 @@ impl StartupResources {

display_cs.connect_peripheral_to_output(display_spi.cs_signal());

const DESCR_SET_COUNT: usize = 1;
static mut DISP_SPI_DESCRIPTORS: [DmaDescriptor; DESCR_SET_COUNT] =
[DmaDescriptor::EMPTY; DESCR_SET_COUNT];
static mut DISP_SPI_RX_DESCRIPTORS: [DmaDescriptor; DESCR_SET_COUNT] =
[DmaDescriptor::EMPTY; DESCR_SET_COUNT];
let display_spi = Spi::new(display_spi, 40u32.MHz(), SpiMode::Mode0, clocks)
.with_sck(display_sclk.into())
.with_mosi(display_mosi.into())
.with_dma(display_dma_channel.configure(
.with_dma(display_dma_channel.configure_for_async(
false,
unsafe { &mut DISP_SPI_DESCRIPTORS },
unsafe { &mut DISP_SPI_RX_DESCRIPTORS },
make_static!([DmaDescriptor::EMPTY; 1]),
make_static!([DmaDescriptor::EMPTY; 1]),
DmaPriority::Priority0,
));

Expand Down Expand Up @@ -156,8 +154,6 @@ impl StartupResources {

clocks: &Clocks,
) -> AdcSpi {
use embedded_hal::digital::OutputPin;

unwrap!(interrupt::enable(
dma_in_interrupt,
interrupt::Priority::Priority1
Expand All @@ -169,23 +165,17 @@ impl StartupResources {

let mut adc_cs: AdcChipSelect = adc_cs.into();

unwrap!(adc_cs.set_high().ok());

const DESCR_SET_COUNT: usize = 1;
static mut ADC_SPI_DESCRIPTORS: [DmaDescriptor; DESCR_SET_COUNT] =
[DmaDescriptor::EMPTY; DESCR_SET_COUNT];
static mut ADC_SPI_RX_DESCRIPTORS: [DmaDescriptor; DESCR_SET_COUNT] =
[DmaDescriptor::EMPTY; DESCR_SET_COUNT];
adc_cs.set_high();

ExclusiveDevice::new(
Spi::new(adc_spi, 1u32.MHz(), SpiMode::Mode1, clocks)
.with_sck(adc_sclk.into())
.with_mosi(adc_mosi.into())
.with_miso(adc_miso.into())
.with_dma(adc_dma_channel.configure(
.with_dma(adc_dma_channel.configure_for_async(
false,
unsafe { &mut ADC_SPI_DESCRIPTORS },
unsafe { &mut ADC_SPI_RX_DESCRIPTORS },
make_static!([DmaDescriptor::EMPTY; 1]),
make_static!([DmaDescriptor::EMPTY; 1]),
DmaPriority::Priority1,
)),
adc_cs,
Expand Down Expand Up @@ -256,7 +246,7 @@ impl StartupResources {
charger_status.into(),
BatteryFg::new(
Max17055::new(
I2C::new(i2c, sda.into(), scl.into(), 100u32.kHz(), clocks),
I2C::new_async(i2c, sda.into(), scl.into(), 100u32.kHz(), clocks),
design,
),
fg_enable.into(),
Expand Down
11 changes: 8 additions & 3 deletions src/board/storage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use core::ops::{Deref, DerefMut};
use core::{
ops::{Deref, DerefMut},
ptr::addr_of_mut,
};

use macros::partition;
use norfs::{medium::cache::ReadCache, Storage, StorageError};
Expand Down Expand Up @@ -56,11 +59,13 @@ impl FileSystem {

unsafe { READ_CACHE = ReadCache::new(InternalDriver::new(ConfigPartition)) };

let storage = match Storage::mount(unsafe { &mut READ_CACHE }).await {
let cache = unsafe { addr_of_mut!(READ_CACHE).as_mut().unwrap_unchecked() };
let storage = match Storage::mount(cache).await {
Ok(storage) => Ok(storage),
Err(StorageError::NotFormatted) => {
info!("Formatting storage");
Storage::format_and_mount(unsafe { &mut READ_CACHE }).await
let cache = unsafe { addr_of_mut!(READ_CACHE).as_mut().unwrap_unchecked() };
Storage::format_and_mount(cache).await
}
e => e,
};
Expand Down
2 changes: 1 addition & 1 deletion src/board/wifi/ap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_net::{Config, Stack};
use esp_hal::{peripherals::WIFI, Rng};
use esp_hal::{peripherals::WIFI, rng::Rng};
use esp_wifi::{
wifi::{
AccessPointConfiguration, Configuration, WifiApDevice, WifiController, WifiDevice,
Expand Down
2 changes: 1 addition & 1 deletion src/board/wifi/ap_sta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use embassy_futures::{
select::{select, Either},
};
use embassy_net::Config;
use esp_hal::{peripherals::WIFI, Rng};
use esp_hal::{peripherals::WIFI, rng::Rng};
use esp_wifi::{wifi::WifiController, EspWifiInitialization};
use macros as cardio;

Expand Down
8 changes: 5 additions & 3 deletions src/board/wifi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use core::{hint::unreachable_unchecked, mem, ops::Deref, ptr::NonNull};

#[cfg(feature = "esp32s3")]
type WifiTimer = esp_hal::timer::Timer<esp_hal::timer::Timer0<esp_hal::peripherals::TIMG1>>;
type WifiTimer =
esp_hal::timer::Timer<esp_hal::timer::Timer0<esp_hal::peripherals::TIMG1>, Blocking>;
#[cfg(feature = "esp32c6")]
type WifiTimer = esp_hal::systimer::Alarm<esp_hal::systimer::Target, 0>;
type WifiTimer = esp_hal::systimer::Alarm<esp_hal::systimer::Target, Blocking, 0>;

use crate::{
board::wifi::{
Expand All @@ -19,8 +20,9 @@ use embassy_net::{Config, Stack, StackResources};
use esp_hal::{
clock::Clocks,
peripherals::{RNG, WIFI},
rng::Rng,
system::RadioClockControl,
Rng,
Blocking,
};
use esp_wifi::{
wifi::{WifiApDevice, WifiDevice, WifiDeviceMode, WifiStaDevice},
Expand Down
Loading

0 comments on commit 3b8b1d4

Please sign in to comment.