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

Update esp-hal #168

Merged
merged 16 commits into from
Nov 20, 2024
10 changes: 4 additions & 6 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
[target.xtensa-esp32s3-none-elf]
runner = "probe-rs run --preverify"
#runner = "espflash flash -M --erase-parts=otadata --log-format=defmt -T partitions.csv -s 8mb"
rustflags = [
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Wl,-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",
"-C", "link-arg=-Tdefmt.x",
]

[target.riscv32imac-unknown-none-elf]
runner = "probe-rs run --preverify"
#runner = "espflash flash -M --erase-parts=otadata --log-format=defmt -T partitions.csv -s 8mb"
rustflags = [
"-C", "force-frame-pointers",
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",
"-C", "link-arg=-Tdefmt.x",
]

[alias]
Expand All @@ -38,8 +36,8 @@ ESP_WIFI_TX_QUEUE_SIZE = "16"
ESP_WIFI_STATIC_TX_BUF_NUM = "12"
ESP_WIFI_DYNAMIC_TX_BUF_NUM = "16"

ESP_WIFI_AMPDU_RX_ENABLE = "y"
ESP_WIFI_AMPDU_TX_ENABLE = "y"
ESP_WIFI_AMPDU_RX_ENABLE = "true"
ESP_WIFI_AMPDU_TX_ENABLE = "true"
ESP_WIFI_RX_BA_WIN = "8"
ESP_WIFI_MAX_BURST_SIZE = "0" # 0 means no limit
ESP_WIFI_TICK_RATE_HZ = "200"
53 changes: 27 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,24 @@ embassy-executor = { workspace = true, features = ["nightly"] }
embassy-time = { version = "0.3.0" }

embedded-hal-old = { package = "embedded-hal", version = "0.2.7" }
rtt-target = { version = "0.6.0", git = "https://github.com/probe-rs/rtt-target" }
rtt-target = { version = "0.6.0", git = "https://github.com/probe-rs/rtt-target", optional = true }

esp-hal = { version = "0.21.0" }
esp-hal-embassy = { version = "0.4.0" }
esp-hal = { version = "0.22.0" }
esp-hal-embassy = { version = "0.5.0" }
esp-backtrace = { version = "0.14.2", features = [
"panic-handler",
"exception-handler",
"defmt"
"exception-handler"
] }
esp-alloc = "0.5.0"
esp-wifi = { version = "0.10.1", default-features = false, features = [
"esp-alloc",
"phy-enable-usb",
"ps-max-modem",
"wifi",
"async",
"embassy-net",
"tcp",
"dns",
"ipv4",
"dhcpv4"
esp-println = { version = "0.12.0", default-features = false, optional = true, features = [
"critical-section",
] }
esp-alloc = "0.5.0"
esp-wifi = { version = "0.11.0", features = ["wifi"] }

display-interface = "0.5"
display-interface-spi = "0.5"
ssd1306 = { version = "0.9.0", features = ["async", "graphics"] }
maybe-async-cfg = "=0.2.4"

portable_atomic_enum = "0.3.1"
config-site = { path = "config-site", default-features = false, features = [
Expand Down Expand Up @@ -129,16 +121,18 @@ smoltcp.workspace = true
crc = "3.0.1"
enumset = "1.1.3"

#[patch.crates-io]
#esp-hal = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" }
#esp-hal-embassy = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" }
#esp-wifi = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" }
#esp-backtrace = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" }
#esp-println = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" }
#esp-alloc = { git = "https://github.com/bugadani/esp-hal.git", rev = "7ca1b4376fd48229c887018d7133ce317742ce4e" }
# [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" }

[features]
default = ["defmt"]
default = ["defmt", "rtt"]
#default = ["defmt", "esp-println"]

battery_max17055 = ["dep:max17055"]

Expand All @@ -153,6 +147,7 @@ esp32s3 = [
"esp-backtrace/esp32s3",
"esp-wifi/esp32s3",
"esp-hal-embassy/esp32s3",
"esp-println?/esp32s3",
]
esp32c6 = [
"esp-hal/esp32c6",
Expand All @@ -161,6 +156,7 @@ esp32c6 = [
"esp-backtrace/esp32c6",
"esp-wifi/esp32c6",
"esp-hal-embassy/esp32c6",
"esp-println?/esp32c6",
]

# Signal processing
Expand All @@ -172,6 +168,8 @@ defmt = [
"embedded-graphics/defmt",
"esp-wifi/defmt",
"esp-hal/defmt",
"esp-backtrace/defmt",
"esp-println?/defmt-espflash",

"logger/defmt",
"config-site/defmt",
Expand All @@ -185,9 +183,12 @@ defmt = [

"embassy-net/defmt",
"smoltcp/defmt",
"rtt-target/defmt",
"rtt-target?/defmt",
]

rtt = ["dep:rtt-target"]
esp-println = ["dep:esp-println", "esp-println/jtag-serial"]

[package.metadata.espflash]
partition_table = "partitions.csv"
format = "esp-bootloader"
Expand Down
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ fn main() {

let build_config = BuildConfig { mcu, hw_version };

if cfg!(feature = "defmt") {
println!("cargo:rustc-link-arg=-Tdefmt.x");
}

let pkg_version = env!("CARGO_PKG_VERSION");
let git_hash_bytes = std::process::Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
Expand Down
8 changes: 6 additions & 2 deletions src/board/drivers/bitbang_spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ where
}
}

pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
self.half_bit_delay = Self::frequency_to_duration(frequency);
pub fn apply_config(
&mut self,
config: &esp_hal::spi::master::Config,
) -> Result<(), esp_hal::spi::master::ConfigError> {
self.half_bit_delay = Self::frequency_to_duration(config.frequency);
Ok(())
}
}

Expand Down
67 changes: 28 additions & 39 deletions src/board/hardware/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ use embassy_time::Delay;
use embedded_hal_bus::spi::ExclusiveDevice;
use esp_hal::{
dma::*,
gpio::{Input, Io, Level, Output},
i2c::I2c,
gpio::{Input, Level, Output},
i2c::master::I2c,
interrupt::software::SoftwareInterruptControl,
peripherals,
rtc_cntl::Rtc,
spi::{master::SpiDmaBus, FullDuplexMode},
spi::master::SpiDmaBus,
timer::{
systimer::{SystemTimer, Target},
timg::TimerGroup,
Expand All @@ -27,24 +26,14 @@ use esp_hal::{

use display_interface_spi::SPIInterface;

pub type DisplaySpiInstance = peripherals::SPI2;
pub type DisplayDmaChannel = ChannelCreator<0>;

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

pub type AdcDmaChannel = ChannelCreator<1>;
pub type AdcSpiInstance = peripherals::SPI3;

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

pub type BatteryAdcEnablePin = Output<'static>;
pub type VbusDetectPin = Input<'static>;
Expand All @@ -57,53 +46,53 @@ pub type PoweredEcgFrontend =

pub type Display = DisplayType<Output<'static>>;

pub type BatteryFgI2cInstance = peripherals::I2C0;
pub type BatteryFgI2c = I2c<'static, BatteryFgI2cInstance, Async>;
pub type BatteryFgI2c = I2c<'static, Async>;
pub type BatteryFg = BatteryFgType<BatteryFgI2c, BatteryAdcEnablePin>;

impl super::startup::StartupResources {
pub async fn initialize() -> Self {
let peripherals = Self::common_init();

let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(systimer.alarm0);

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
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.SPI2,
io.pins.gpio12,
io.pins.gpio13,
io.pins.gpio11,
io.pins.gpio14,
io.pins.gpio21,
peripherals.GPIO12,
peripherals.GPIO13,
peripherals.GPIO11,
peripherals.GPIO14,
peripherals.GPIO21,
);

let adc = Self::create_frontend_driver(
Self::create_frontend_spi(
dma.channel1,
peripherals.SPI3,
io.pins.gpio6,
io.pins.gpio7,
io.pins.gpio5,
io.pins.gpio18,
peripherals.GPIO6,
peripherals.GPIO7,
peripherals.GPIO5,
peripherals.GPIO18,
),
io.pins.gpio4,
io.pins.gpio2,
io.pins.gpio38,
io.pins.gpio1,
peripherals.GPIO4,
peripherals.GPIO2,
peripherals.GPIO38,
peripherals.GPIO1,
);

let battery_monitor = Self::setup_battery_monitor_fg(
peripherals.I2C0,
io.pins.gpio36,
io.pins.gpio35,
io.pins.gpio17,
io.pins.gpio47,
Output::new(io.pins.gpio8, Level::Low),
peripherals.GPIO36,
peripherals.GPIO35,
peripherals.GPIO17,
peripherals.GPIO47,
Output::new(peripherals.GPIO8, Level::Low),
)
.await;

Expand Down
Loading
Loading