Skip to content

Commit

Permalink
Configure e-hal-embassy, remove TAITs
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Dec 18, 2024
1 parent a4b09d2 commit 1c7d301
Show file tree
Hide file tree
Showing 15 changed files with 312 additions and 126 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ monitor = "xtask monitor"
[env]
DEFMT_LOG = "card_io_fw=debug,info"

ESP_HAL_EMBASSY_TIMER_QUEUE = "multiple-integrated"

ESP_WIFI_RX_QUEUE_SIZE = "16"
ESP_WIFI_STATIC_RX_BUF_NUM = "32"
ESP_WIFI_DYNAMIC_RX_BUF_NUM = "16"
Expand Down
20 changes: 16 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ embedded-hal-old = { package = "embedded-hal", version = "0.2.7" }
rtt-target = { version = "0.6.0", optional = true }
panic-rtt-target = { version = "0.2.0", optional = true }

esp-hal = { version = "0.22.0" }
esp-hal = { version = "0.22.0", features = ["unstable"] }
esp-hal-embassy = { version = "0.5.0" }
esp-backtrace = { version = "0.14.2", optional = true, features = [
"panic-handler",
Expand Down Expand Up @@ -87,7 +87,7 @@ signal-processing = { workspace = true, features = ["alloc"] }
replace_with = { version = "0.1", default-features = false, features = [
"nightly",
] }
static_cell = { version = "2.0.0", features = ["nightly"] }
static_cell = { version = "2.0.0" }
bad-server = { path = "bad-server", features = ["embassy"] }
embedded-tls = { version = "0.17.0", default-features = false }
reqwless = "0.12.1"
Expand Down Expand Up @@ -143,7 +143,6 @@ hw_v6 = ["battery_max17055"] # skipped v5, v6 has S3 and C6 options
# MCU options
esp32s3 = [
"esp-hal/esp32s3",
"embassy-executor/integrated-timers",
"dep:norfs-esp32s3",
"esp-backtrace?/esp32s3",
"esp-wifi/esp32s3",
Expand All @@ -152,7 +151,6 @@ esp32s3 = [
]
esp32c6 = [
"esp-hal/esp32c6",
"embassy-time/generic-queue-8",
"dep:norfs-esp32c6",
"esp-backtrace?/esp32c6",
"esp-wifi/esp32c6",
Expand Down Expand Up @@ -222,3 +220,17 @@ lto = "fat"
[profile.lto]
inherits = "release"
lto = "fat"

[patch.crates-io]
esp-alloc = { git = "https://github.com/bugadani/esp-hal", branch = "time-driver-redo" }
esp-hal = { git = "https://github.com/bugadani/esp-hal", branch = "time-driver-redo" }
esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal", branch = "time-driver-redo" }
esp-hal-procmacros = { git = "https://github.com/bugadani/esp-hal", branch = "time-driver-redo" }
esp-wifi = { git = "https://github.com/bugadani/esp-hal", branch = "time-driver-redo" }
xtensa-lx-rt = { git = "https://github.com/bugadani/esp-hal", branch = "time-driver-redo" }
xtensa-lx = { git = "https://github.com/bugadani/esp-hal", branch = "time-driver-redo" }

embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "0c245892c6812538f4f51b784ed8afa1ce47f25d" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "0c245892c6812538f4f51b784ed8afa1ce47f25d" }
embassy-time-driver = { git = "https://github.com/embassy-rs/embassy", rev = "0c245892c6812538f4f51b784ed8afa1ce47f25d" }
embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy", rev = "0c245892c6812538f4f51b784ed8afa1ce47f25d" }
21 changes: 12 additions & 9 deletions src/board/drivers/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ use ssd1306::{
mode::BufferedGraphicsModeAsync, prelude::*, rotation::DisplayRotation,
size::DisplaySize128x64, Ssd1306Async,
};
use static_cell::make_static;
use static_cell::StaticCell;

use crate::board::DisplayInterface;

type D = Ssd1306Async<
DisplayInterface<'static>,
DisplaySize128x64,
BufferedGraphicsModeAsync<DisplaySize128x64>,
>;

pub struct Display<RESET> {
display: &'static mut Ssd1306Async<
DisplayInterface<'static>,
DisplaySize128x64,
BufferedGraphicsModeAsync<DisplaySize128x64>,
>,
display: &'static mut D,
reset: RESET,
}

Expand All @@ -29,10 +31,11 @@ where
RESET: OutputPin,
{
pub fn new(spi: DisplayInterface<'static>, reset: RESET) -> Self {
let display = make_static! {
static DISPLAY: StaticCell<D> = StaticCell::new();
let display = DISPLAY.init(
Ssd1306Async::new(spi, DisplaySize128x64, DisplayRotation::Rotate0)
.into_buffered_graphics_mode()
};
.into_buffered_graphics_mode(),
);

Self { display, reset }
}
Expand Down
37 changes: 16 additions & 21 deletions src/board/hardware/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@ use esp_hal::{
interrupt::software::SoftwareInterruptControl,
rtc_cntl::Rtc,
spi::master::SpiDmaBus,
timer::{
systimer::{SystemTimer, Target},
timg::TimerGroup,
AnyTimer,
},
timer::{systimer::SystemTimer, timg::TimerGroup, AnyTimer},
Async,
};
use static_cell::StaticCell;

use display_interface_spi::SPIInterface;

pub type DisplayDmaChannel = ChannelCreator<0>;
pub type DisplayDmaChannel = DmaChannel0;

pub type DisplayInterface<'a> = SPIInterface<DisplaySpi<'a>, Output<'static>>;
pub type DisplaySpi<'d> = ExclusiveDevice<SpiDmaBus<'d, Async>, DummyOutputPin, Delay>;

pub type AdcDmaChannel = ChannelCreator<1>;
pub type AdcDmaChannel = DmaChannel1;

pub type AdcSpi = ExclusiveDevice<SpiDmaBus<'static, Async>, Output<'static>, Delay>;

Expand All @@ -53,16 +50,14 @@ impl super::startup::StartupResources {
pub async fn initialize() -> Self {
let peripherals = Self::common_init();

let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
let systimer = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init([
AnyTimer::from(systimer.alarm0),
AnyTimer::from(systimer.alarm1),
]);

let dma = Dma::new(peripherals.DMA);

let display = Self::create_display_driver(
dma.channel0,
peripherals.DMA_CH0,
peripherals.SPI2,
peripherals.GPIO12,
peripherals.GPIO13,
Expand All @@ -73,7 +68,7 @@ impl super::startup::StartupResources {

let adc = Self::create_frontend_driver(
Self::create_frontend_spi(
dma.channel1,
peripherals.DMA_CH1,
peripherals.SPI3,
peripherals.GPIO6,
peripherals.GPIO7,
Expand All @@ -98,19 +93,19 @@ impl super::startup::StartupResources {

let sw_int = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

static WIFI: StaticCell<WifiDriver> = StaticCell::new();
let wifi = WIFI.init(WifiDriver::new(
peripherals.WIFI,
AnyTimer::from(TimerGroup::new(peripherals.TIMG0).timer0),
peripherals.RNG,
peripherals.RADIO_CLK,
));

Self {
display,
frontend: adc,
battery_monitor,
wifi: static_cell::make_static! {
WifiDriver::new(
peripherals.WIFI,
AnyTimer::from(TimerGroup::new(peripherals.TIMG0)
.timer0),
peripherals.RNG,
peripherals.RADIO_CLK,
)
},
wifi,
rtc: Rtc::new(peripherals.LPWR),
software_interrupt1: sw_int.software_interrupt1,
}
Expand Down
32 changes: 14 additions & 18 deletions src/board/hardware/v6c6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ use esp_hal::{
prelude::*,
rtc_cntl::Rtc,
spi::master::SpiDmaBus,
timer::{
systimer::{SystemTimer, Target},
timg::TimerGroup,
AnyTimer,
},
timer::{systimer::SystemTimer, timg::TimerGroup, AnyTimer},
Async,
};
use static_cell::StaticCell;

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

pub type DisplayDmaChannel = ChannelCreator<0>;
pub type DisplayDmaChannel = DmaChannel0;

pub type DisplayInterface<'a> = SPIInterface<DisplaySpi<'a>, Output<'static>>;
pub type DisplaySpi<'d> = ExclusiveDevice<SpiDmaBus<'d, Async>, DummyOutputPin, Delay>;
Expand Down Expand Up @@ -57,16 +54,14 @@ impl super::startup::StartupResources {
pub async fn initialize() -> Self {
let peripherals = Self::common_init();

let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
let systimer = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init([
AnyTimer::from(systimer.alarm0),
AnyTimer::from(systimer.alarm1),
]);

let dma = Dma::new(peripherals.DMA);

let display = Self::create_display_driver(
dma.channel0,
peripherals.DMA_CH0,
peripherals.SPI2,
peripherals.GPIO10,
peripherals.GPIO8,
Expand Down Expand Up @@ -105,18 +100,19 @@ impl super::startup::StartupResources {

let sw_int = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

static WIFI: StaticCell<WifiDriver> = StaticCell::new();
let wifi = WIFI.init(WifiDriver::new(
peripherals.WIFI,
AnyTimer::from(systimer.alarm2),
peripherals.RNG,
peripherals.RADIO_CLK,
));

Self {
display,
frontend: adc,
battery_monitor,
wifi: static_cell::make_static! {
WifiDriver::new(
peripherals.WIFI,
AnyTimer::from(systimer.alarm2),
peripherals.RNG,
peripherals.RADIO_CLK,
)
},
wifi,
rtc: Rtc::new(peripherals.LPWR),
software_interrupt1: sw_int.software_interrupt1,
}
Expand Down
37 changes: 16 additions & 21 deletions src/board/hardware/v6s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ use esp_hal::{
interrupt::software::SoftwareInterruptControl,
rtc_cntl::Rtc,
spi::master::SpiDmaBus,
timer::{
systimer::{SystemTimer, Target},
timg::TimerGroup,
AnyTimer,
},
timer::{systimer::SystemTimer, timg::TimerGroup, AnyTimer},
Async,
};
use static_cell::StaticCell;

pub type DisplayDmaChannel = ChannelCreator<0>;
pub type DisplayDmaChannel = DmaChannel0;

pub type DisplayInterface<'a> = SPIInterface<DisplaySpi<'a>, Output<'static>>;
pub type DisplaySpi<'d> = ExclusiveDevice<SpiDmaBus<'d, Async>, DummyOutputPin, Delay>;

pub type AdcDmaChannel = ChannelCreator<1>;
pub type AdcDmaChannel = DmaChannel1;

pub type AdcSpi = ExclusiveDevice<SpiDmaBus<'static, Async>, Output<'static>, Delay>;

Expand All @@ -52,16 +49,14 @@ impl super::startup::StartupResources {
pub async fn initialize() -> Self {
let peripherals = Self::common_init();

let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
let systimer = SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init([
AnyTimer::from(systimer.alarm0),
AnyTimer::from(systimer.alarm1),
]);

let dma = Dma::new(peripherals.DMA);

let display = Self::create_display_driver(
dma.channel0,
peripherals.DMA_CH0,
peripherals.SPI2,
peripherals.GPIO18,
peripherals.GPIO17,
Expand All @@ -72,7 +67,7 @@ impl super::startup::StartupResources {

let adc = Self::create_frontend_driver(
Self::create_frontend_spi(
dma.channel1,
peripherals.DMA_CH1,
peripherals.SPI3,
peripherals.GPIO6,
peripherals.GPIO7,
Expand All @@ -97,19 +92,19 @@ impl super::startup::StartupResources {

let sw_int = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);

static WIFI: StaticCell<WifiDriver> = StaticCell::new();
let wifi = WIFI.init(WifiDriver::new(
peripherals.WIFI,
AnyTimer::from(TimerGroup::new(peripherals.TIMG0).timer0),
peripherals.RNG,
peripherals.RADIO_CLK,
));

Self {
display,
frontend: adc,
battery_monitor,
wifi: static_cell::make_static! {
WifiDriver::new(
peripherals.WIFI,
AnyTimer::from(TimerGroup::new(peripherals.TIMG0)
.timer0),
peripherals.RNG,
peripherals.RADIO_CLK,
)
},
wifi,
rtc: Rtc::new(peripherals.LPWR),
software_interrupt1: sw_int.software_interrupt1,
}
Expand Down
Loading

0 comments on commit 1c7d301

Please sign in to comment.