Skip to content

Commit

Permalink
Merge pull request #166 from card-io-ecg/modernize
Browse files Browse the repository at this point in the history
Modernize
  • Loading branch information
bugadani committed Apr 21, 2024
2 parents b225078 + db4737a commit b1da449
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 115 deletions.
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
5 changes: 4 additions & 1 deletion src/board/drivers/battery_monitor/battery_fg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ use embedded_hal_async::{delay::DelayNs, i2c::I2c};
use max17055::Max17055;

#[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))]
use crate::hal::gpio::RTCPinWithResistors;
use crate::board::hal as esp_hal;

use crate::{task_control::TaskControlToken, Shared};
#[cfg(all(feature = "esp32s3", not(feature = "hw_v6")))]
use esp_hal::gpio::RTCPinWithResistors;

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand Down
3 changes: 2 additions & 1 deletion src/board/drivers/bitbang_spi.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use core::convert::Infallible;

use crate::hal::clock::Clocks;
use crate::board::hal as esp_hal;
use embassy_time::{Duration, Ticker};
use embedded_hal::{
digital::{InputPin, OutputPin, PinState},
spi::ErrorType,
};
use embedded_hal_async::spi::SpiBus;
use esp_hal::clock::Clocks;
use fugit::HertzU32;

pub struct BitbangSpi<MOSI, MISO, SCLK> {
Expand Down
34 changes: 17 additions & 17 deletions src/board/hardware/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ use crate::board::{
display::Display as DisplayType,
frontend::{Frontend, PoweredFrontend},
},
hal::{
self,
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
},
hal as esp_hal,
utils::DummyOutputPin,
wifi::WifiDriver,
};
use embassy_time::Delay;
use embedded_hal_bus::spi::ExclusiveDevice;
use esp_hal::{
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
};

use display_interface_spi::SPIInterface;

pub type DisplaySpiInstance = hal::peripherals::SPI2;
pub type DisplaySpiInstance = peripherals::SPI2;
pub type DisplayDmaChannel = ChannelCreator0;
pub type DisplayDataCommand = GpioPin<Output<PushPull>, 13>;
pub type DisplayChipSelect = GpioPin<Output<PushPull>, 11>;
Expand All @@ -42,7 +42,7 @@ pub type DisplaySpi<'d> = ExclusiveDevice<
>;

pub type AdcDmaChannel = ChannelCreator1;
pub type AdcSpiInstance = hal::peripherals::SPI3;
pub type AdcSpiInstance = peripherals::SPI3;
pub type AdcSclk = GpioPin<Output<PushPull>, 6>;
pub type AdcMosi = GpioPin<Output<PushPull>, 7>;
pub type AdcMiso = GpioPin<Input<Floating>, 5>;
Expand All @@ -67,7 +67,7 @@ pub type PoweredEcgFrontend =

pub type Display = DisplayType<DisplayReset>;

pub type BatteryFgI2cInstance = hal::peripherals::I2C0;
pub type BatteryFgI2cInstance = peripherals::I2C0;
pub type I2cSda = GpioPin<Unknown, 36>;
pub type I2cScl = GpioPin<Unknown, 35>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>;
Expand Down
32 changes: 16 additions & 16 deletions src/board/hardware/v6c6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ use crate::board::{
display::Display as DisplayType,
frontend::{Frontend, PoweredFrontend},
},
hal::{
self,
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
},
hal as esp_hal,
utils::DummyOutputPin,
wifi::WifiDriver,
};
use display_interface_spi::SPIInterface;
use embassy_time::Delay;
use embedded_hal_bus::spi::ExclusiveDevice;
use esp_hal::{
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
};

pub use crate::board::drivers::bitbang_spi::BitbangSpi;

pub type DisplaySpiInstance = hal::peripherals::SPI2;
pub type DisplaySpiInstance = peripherals::SPI2;
pub type DisplayDmaChannel = ChannelCreator0;
pub type DisplayDataCommand = GpioPin<Output<PushPull>, 8>;
pub type DisplayChipSelect = GpioPin<Output<PushPull>, 11>;
Expand Down Expand Up @@ -63,7 +63,7 @@ pub type PoweredEcgFrontend =

pub type Display = DisplayType<DisplayReset>;

pub type BatteryFgI2cInstance = hal::peripherals::I2C0;
pub type BatteryFgI2cInstance = peripherals::I2C0;
pub type I2cSda = GpioPin<Unknown, 19>;
pub type I2cScl = GpioPin<Unknown, 18>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>;
Expand Down
34 changes: 17 additions & 17 deletions src/board/hardware/v6s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ use crate::board::{
display::Display as DisplayType,
frontend::{Frontend, PoweredFrontend},
},
hal::{
self,
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
},
hal as esp_hal,
utils::DummyOutputPin,
wifi::WifiDriver,
};
use display_interface_spi::SPIInterface;
use embassy_time::Delay;
use embedded_hal_bus::spi::ExclusiveDevice;
use esp_hal::{
clock::ClockControl,
dma::*,
embassy,
gpio::{Floating, GpioPin, Input, Output, PullUp, PushPull, Unknown},
i2c::I2C,
peripherals::{self, Peripherals},
prelude::*,
spi::{master::dma::SpiDma, FullDuplexMode},
systimer::SystemTimer,
timer::TimerGroup,
Rtc, IO,
};

pub type DisplaySpiInstance = hal::peripherals::SPI2;
pub type DisplaySpiInstance = peripherals::SPI2;
pub type DisplayDmaChannel = ChannelCreator0;
pub type DisplayDataCommand = GpioPin<Output<PushPull>, 17>;
pub type DisplayChipSelect = GpioPin<Output<PushPull>, 8>;
Expand All @@ -41,7 +41,7 @@ pub type DisplaySpi<'d> = ExclusiveDevice<
>;

pub type AdcDmaChannel = ChannelCreator1;
pub type AdcSpiInstance = hal::peripherals::SPI3;
pub type AdcSpiInstance = peripherals::SPI3;
pub type AdcSclk = GpioPin<Output<PushPull>, 6>;
pub type AdcMosi = GpioPin<Output<PushPull>, 7>;
pub type AdcMiso = GpioPin<Input<Floating>, 5>;
Expand All @@ -63,7 +63,7 @@ pub type PoweredEcgFrontend =

pub type Display = DisplayType<DisplayReset>;

pub type BatteryFgI2cInstance = hal::peripherals::I2C0;
pub type BatteryFgI2cInstance = peripherals::I2C0;
pub type I2cSda = GpioPin<Unknown, 36>;
pub type I2cScl = GpioPin<Unknown, 35>;
pub type BatteryFgI2c = I2C<'static, BatteryFgI2cInstance>;
Expand Down
3 changes: 2 additions & 1 deletion src/board/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
board::{
config::Config,
drivers::battery_monitor::BatteryMonitor,
hal::clock::Clocks,
hal as esp_hal,
storage::FileSystem,
wifi::{ap::Ap, sta::Sta, WifiDriver},
ChargerStatus, Display, EcgFrontend, VbusDetect,
Expand All @@ -17,6 +17,7 @@ use embassy_executor::SendSpawner;
use embassy_net::{Config as NetConfig, Ipv4Address, Ipv4Cidr, StaticConfigV4};
use embassy_time::{Duration, Instant, Timer};
use embedded_graphics::{pixelcolor::BinaryColor, prelude::DrawTarget, Drawable};
use esp_hal::clock::Clocks;
use gui::{
screens::message::MessageScreen,
widgets::{
Expand Down
49 changes: 19 additions & 30 deletions src/board/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@ use static_cell::make_static;
use crate::{
board::{
drivers::{battery_monitor::BatteryMonitor, frontend::Frontend},
hal::{
clock::Clocks,
dma::{DmaDescriptor, DmaPriority},
gpio::OutputPin as _,
interrupt, peripherals,
spi::{
master::{dma::*, Instance, Spi},
SpiMode,
},
Rtc,
},
hal as esp_hal,
utils::DummyOutputPin,
wifi::WifiDriver,
AdcClockEnable, AdcDrdy, AdcReset, AdcSpi, ChargerStatus, Display, DisplayChipSelect,
Expand All @@ -25,16 +15,26 @@ use crate::{
},
heap::init_heap,
};
use esp_hal::{
clock::Clocks,
dma::{DmaDescriptor, DmaPriority},
gpio::OutputPin as _,
interrupt, peripherals,
spi::{
master::{dma::*, Instance, Spi},
SpiMode,
},
Rtc,
};

#[cfg(feature = "esp32s3")]
use crate::board::{AdcChipSelect, AdcDmaChannel, AdcMiso, AdcMosi, AdcSclk, AdcSpiInstance};

#[cfg(feature = "battery_max17055")]
use esp_hal::i2c::I2C;
#[cfg(feature = "battery_max17055")]
use {
crate::{
board::{BatteryAdcEnable, BatteryFg, BatteryFgI2cInstance, I2cScl, I2cSda},
hal::i2c::I2C,
},
crate::board::{BatteryAdcEnable, BatteryFg, BatteryFgI2cInstance, I2cScl, I2cSda},
max17055::{DesignData, Max17055},
};

Expand Down Expand Up @@ -118,18 +118,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(
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 @@ -172,21 +167,15 @@ impl StartupResources {

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];

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(
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
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
3 changes: 2 additions & 1 deletion src/board/wifi/ap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use gui::widgets::wifi_access_point::WifiAccessPointState;

use crate::{
board::{
hal::{peripherals::WIFI, Rng},
hal as esp_hal,
wifi::{ap_net_task, StackWrapper},
},
task_control::{TaskControlToken, TaskController},
};
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_net::{Config, Stack};
use esp_hal::{peripherals::WIFI, Rng};
use esp_wifi::{
wifi::{
AccessPointConfiguration, Configuration, WifiApDevice, WifiController, WifiDevice,
Expand Down
3 changes: 2 additions & 1 deletion src/board/wifi/ap_sta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use embassy_time::{with_timeout, Duration};

use crate::{
board::{
hal::{peripherals::WIFI, Rng},
hal as esp_hal,
wifi::{
ap::{Ap, ApConnectionState, ApController},
ap_net_task,
Expand All @@ -22,6 +22,7 @@ use embassy_futures::{
select::{select, Either},
};
use embassy_net::Config;
use esp_hal::{peripherals::WIFI, Rng};
use esp_wifi::{wifi::WifiController, EspWifiInitialization};
use macros as cardio;

Expand Down
Loading

0 comments on commit b1da449

Please sign in to comment.