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

😭 #169

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

😭 #169

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
24 changes: 11 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ 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-embassy = { version = "0.5.0" }
esp-hal = { version = "0.22.0", features = ["unstable"] }
esp-hal-embassy = { version = "0.5.0", features = ["integrated-timers"] }
esp-backtrace = { version = "0.14.2", optional = true, features = [
"panic-handler",
"exception-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 @@ -122,14 +122,14 @@ smoltcp.workspace = true
crc = "3.0.1"
enumset = "1.1.3"

# [patch.crates-io]
# esp-hal = { git = "https://github.com/jessebraham/esp-hal.git", rev = "a80385a20a85592a0466311da24f4d5ec8c7ea71" }
# esp-hal-embassy = { git = "https://github.com/jessebraham/esp-hal.git", rev = "a80385a20a85592a0466311da24f4d5ec8c7ea71" }
# esp-wifi = { git = "https://github.com/jessebraham/esp-hal.git", rev = "a80385a20a85592a0466311da24f4d5ec8c7ea71" }
# esp-backtrace = { git = "https://github.com/jessebraham/esp-hal.git", rev = "a80385a20a85592a0466311da24f4d5ec8c7ea71" }
# esp-println = { git = "https://github.com/jessebraham/esp-hal.git", rev = "a80385a20a85592a0466311da24f4d5ec8c7ea71" }
# esp-alloc = { git = "https://github.com/jessebraham/esp-hal.git", rev = "a80385a20a85592a0466311da24f4d5ec8c7ea71" }
# xtensa-lx-rt = { git = "https://github.com/jessebraham/esp-hal.git", rev = "a80385a20a85592a0466311da24f4d5ec8c7ea71" }
[patch.crates-io]
esp-hal = { git = "https://github.com/bugadani/esp-hal.git", branch = "gpio" }
esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", branch = "gpio" }
esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", branch = "gpio" }
esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", branch = "gpio" }
esp-println = { git = "https://github.com/bugadani/esp-hal.git", branch = "gpio" }
esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", branch = "gpio" }
xtensa-lx-rt = { git = "https://github.com/bugadani/esp-hal.git", branch = "gpio" }

[features]
default = ["defmt", "rtt"]
Expand All @@ -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
17 changes: 14 additions & 3 deletions macros/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,21 @@ pub fn run(args: Args, f: syn::ItemFn) -> TokenStream {

let mut task_outer: ItemFn = parse_quote! {
#visibility fn #task_ident(#fargs) -> ::embassy_executor::SpawnToken<impl Sized> {
type Fut = impl ::core::future::Future + 'static;
trait _EmbassyInternalTaskTrait {
type Fut: ::core::future::Future + 'static;
fn construct(#fargs) -> Self::Fut;
}

impl _EmbassyInternalTaskTrait for () {
type Fut = impl core::future::Future + 'static;
fn construct(#fargs) -> Self::Fut {
#task_inner_ident(#(#arg_names,)*)
}
}

const POOL_SIZE: usize = #pool_size;
static POOL: embassy_alloc_taskpool::AllocTaskPool<Fut, POOL_SIZE> = embassy_alloc_taskpool::AllocTaskPool::new();
unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) }
static POOL: embassy_alloc_taskpool::AllocTaskPool<<() as _EmbassyInternalTaskTrait>::Fut, POOL_SIZE> = embassy_alloc_taskpool::AllocTaskPool::new();
unsafe { POOL._spawn_async_fn(move || <() as _EmbassyInternalTaskTrait>::construct(#(#arg_names,)*)) }
}
};

Expand Down
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
Loading