Skip to content

Commit 3a5cb51

Browse files
committed
chore: update esp-hal version
1 parent cf6f011 commit 3a5cb51

File tree

9 files changed

+403
-267
lines changed

9 files changed

+403
-267
lines changed

Cargo.lock

Lines changed: 311 additions & 220 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ authors = ["filipton <filipton12@gmail.com>"]
55
edition = "2024"
66

77
[dependencies]
8-
esp-backtrace = { version = "0.17.0", features = [ "exception-handler", "panic-handler", "println", "custom-pre-backtrace", "custom-halt", "esp32c3" ] }
9-
esp-hal = { version = "1.0.0-rc.0", features = [ "esp32c3" ] }
10-
esp-println = { version = "0.15.0", features = ["log-04", "esp32c3"] }
8+
esp-backtrace = { version = "0.18.0", features = [ "panic-handler", "println", "custom-pre-backtrace", "custom-halt", "esp32c3" ] }
9+
esp-hal = { version = "1.0.0-rc.1", features = [ "esp32c3" ] }
10+
esp-println = { version = "0.16.0", features = ["log-04", "esp32c3"] }
1111
log = { version = "0.4.28" }
12-
esp-wifi = { version = "0.15.0", features = ["coex", "esp32c3"] }
13-
esp-hal-embassy = { version = "0.9.0", features = ["esp32c3"] }
14-
embassy-executor = { version = "0.7.0", features = ["arch-riscv32", "nightly"] }
12+
esp-radio = { version = "0.16.0", features = ["coex", "esp32c3"] }
13+
esp-rtos = { version = "0.1.0", features = ["esp32c3", "embassy", "esp-radio"] }
14+
embassy-executor = { version = "0.9.1", features = ["arch-riscv32", "nightly"] }
1515
embassy-net = { version = "0.7.1", features = ["tcp", "udp", "multicast", "dhcpv4", "medium-ethernet", "proto-ipv4", "dns"] }
1616
embassy-time = { version = "0.5.0" }
17-
esp-storage = { version = "0.7.0", features = ["esp32c3"] }
17+
esp-storage = { version = "0.8.0", features = ["esp32c3"] }
1818
embedded-storage = "0.3.1"
1919
static_cell = { version = "2.1.1", features = ["nightly"] }
20-
heapless = { version = "0.8.0", default-features = false }
21-
esp-alloc = "0.8.0"
22-
esp-hal-wifimanager = { version = "0.1.2", default-features = false, features = ["ap", "ble", "esp32c3"] }
20+
heapless = { version = "0.9.1", default-features = false }
21+
esp-alloc = "0.9.0"
22+
esp-hal-wifimanager = { version = "0.2.0", default-features = false, features = ["ap", "ble", "esp32c3"] }
2323
serde = { version = "1.0.228", features = ["alloc", "derive"], default-features = false }
2424
serde_json = { version = "1.0.145", default-features = false, features = ["alloc"] }
2525
adv-shift-registers = "0.2.5"
2626
embedded-hal = "1.0.0"
27-
esp-hal-mdns = "0.1.2"
28-
embedded-io-async = "0.6.1"
27+
esp-hal-mdns = "0.1.3"
28+
embedded-io-async = "0.7.0"
2929
macros = { path = "./macros" }
3030
nb = "1.1.0"
3131
embassy-futures = "0.1.2"
@@ -37,20 +37,20 @@ critical-section = "1.2.0"
3737
getrandom = { version = "=0.2.15", features = ["custom"] }
3838
uuid = { version = "=1.12.1", default-features = false, features = ["v4"] }
3939
dyn-smooth = "0.2.0"
40-
esp-hal-ota = { version = "0.4.4", features = ["esp32c3"] }
41-
esp32c3 = { version = "0.30.0" }
40+
esp-hal-ota = { version = "0.4.5", features = ["esp32c3"] }
41+
esp32c3 = { version = "0.31.0" }
4242
anyhow = { version = "1.0.100", default-features = false }
4343
embedded-hal-bus = { version = "0.3.0", features = ["async"] }
4444
embedded-tls = { git = "https://github.com/drogue-iot/embedded-tls.git", rev="fbd486c4ee0c1f14bbc762976896afc9e2d708c8", default-features = false, features = ["alloc", "embedded-io-adapters", "log"] }
4545
rand_core = { version = "0.6.4", features = ["getrandom"] }
4646
ag-lcd-async = { git = "https://github.com/filipton/ag-lcd-async", features = [] }
4747
esp-hal-mfrc522 = { version = "0.3.2", features = ["embassy-time"] }
48-
esp-bootloader-esp-idf = { version = "0.2.0", features = ["log-04", "esp32c3"] }
49-
trouble-host = { version = "0.2.4", features = ["scan"] }
48+
esp-bootloader-esp-idf = { version = "0.3.0", features = ["log-04", "esp32c3"] }
49+
trouble-host = { version = "0.4.0", features = ["scan"] }
5050

5151
[features]
5252
default = ["sleep"]
53-
esp_now = ["esp-wifi/esp-now"]
53+
esp_now = ["esp-radio/esp-now"]
5454
gen_version = []
5555
bat_dev_lcd = []
5656
release_build = ["sleep"]

src/bluetooth.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
use core::cell::RefCell;
22
use embassy_futures::join::join;
33
use embassy_time::{Duration, Timer};
4-
use esp_wifi::{EspWifiController, ble::controller::BleConnector};
4+
use esp_radio::{Controller as RadioController, ble::controller::BleConnector};
55
use trouble_host::prelude::*;
66

77
#[embassy_executor::task]
88
pub async fn bluetooth_timer_task(
9-
init: &'static EspWifiController<'static>,
9+
init: &'static RadioController<'static>,
1010
bt: esp_hal::peripherals::BT<'static>,
1111
) {
12-
let connector = BleConnector::new(init, bt);
12+
let Ok(connector) = BleConnector::new(init, bt, esp_radio::ble::Config::default()) else {
13+
log::error!("Cannot init ble connector");
14+
return;
15+
};
16+
1317
let controller: ExternalController<_, 20> = ExternalController::new(connector);
1418

1519
let address: Address = Address::random(esp_hal::efuse::Efuse::mac_address());

src/board.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use adv_shift_registers::wrappers::ShifterValueRange;
33
use anyhow::Result;
44
use esp_hal::{
55
gpio::{AnyPin, Input, InputConfig, Level, Output, Pin, Pull},
6-
peripherals::{ADC1, AES, BT, Peripherals, SPI2, TIMG0, TIMG1, UART1, WIFI},
6+
peripherals::{
7+
ADC1, AES, BT, FLASH, Peripherals, SPI2, SW_INTERRUPT, TIMG0, TIMG1, UART1, WIFI,
8+
},
79
rng::Rng,
810
timer::timg::TimerGroup,
911
};
@@ -21,6 +23,8 @@ pub struct Board {
2123
pub bt: BT<'static>,
2224
pub spi_dma: esp_hal::peripherals::DMA_CH0<'static>,
2325
pub aes: AES<'static>,
26+
pub flash: FLASH<'static>,
27+
pub sw_interrupt: SW_INTERRUPT<'static>,
2428

2529
// spi
2630
pub miso: AnyPin<'static>,
@@ -48,14 +52,16 @@ impl Board {
4852

4953
let timg0 = TimerGroup::new(peripherals.TIMG0);
5054
let timg1 = TimerGroup::new(peripherals.TIMG1);
51-
let rng = Rng::new(peripherals.RNG);
55+
let rng = Rng::new();
5256
let uart1 = peripherals.UART1;
5357
let spi2 = peripherals.SPI2;
5458
let spi_dma = peripherals.DMA_CH0;
5559
let adc1 = peripherals.ADC1;
5660
let wifi = peripherals.WIFI;
5761
let bt = peripherals.BT;
5862
let aes = peripherals.AES;
63+
let flash = peripherals.FLASH;
64+
let sw_interrupt = peripherals.SW_INTERRUPT;
5965

6066
let sck = peripherals.GPIO4.degrade();
6167
let miso = peripherals.GPIO5.degrade();
@@ -105,6 +111,8 @@ impl Board {
105111
wifi,
106112
bt,
107113
aes,
114+
flash,
115+
sw_interrupt,
108116

109117
miso,
110118
mosi,

src/buttons.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub async fn buttons_task(
3636
ButtonTrigger::HoldOnce(1000),
3737
inspection_hold_stop(),
3838
);
39+
handler.add_handler(
40+
Button::First,
41+
ButtonTrigger::HoldOnce(15000),
42+
connect_bluetooth_display(),
43+
);
3944

4045
handler.add_handler(Button::Fourth, ButtonTrigger::Down, room_right());
4146
handler.add_handler(Button::Fourth, ButtonTrigger::HoldOnce(1000), dnf_button());
@@ -244,6 +249,16 @@ async fn inspection_hold_stop(
244249
Ok(false)
245250
}
246251

252+
#[macros::button_handler]
253+
async fn connect_bluetooth_display(
254+
_triggered: &ButtonTrigger,
255+
_hold_time: u64,
256+
state: &GlobalState,
257+
) -> Result<bool, ()> {
258+
_ = state;
259+
Ok(false)
260+
}
261+
247262
#[macros::button_handler]
248263
async fn dnf_button(
249264
_triggered: &ButtonTrigger,

src/main.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use embassy_executor::Spawner;
1212
use embassy_sync::signal::Signal;
1313
use embassy_time::{Instant, Timer};
1414
use esp_backtrace as _;
15+
use esp_hal::interrupt::software::SoftwareInterruptControl;
1516
use esp_hal_wifimanager::{Nvs, WIFI_NVS_KEY};
1617
use esp_storage::FlashStorage;
1718
use state::{GlobalState, GlobalStateInner, SavedGlobalState, Scene, ota_state, sleep_state};
@@ -20,7 +21,7 @@ use utils::{logger::FkmLogger, set_brownout_detection};
2021
use ws_framer::{WsUrl, WsUrlOwned};
2122

2223
#[cfg(feature = "esp_now")]
23-
use esp_wifi::esp_now::{EspNowManager, EspNowSender};
24+
use esp_radio::esp_now::{EspNowManager, EspNowSender};
2425

2526
mod battery;
2627
mod bluetooth;
@@ -70,7 +71,7 @@ macro_rules! mk_static {
7071

7172
esp_bootloader_esp_idf::esp_app_desc!();
7273

73-
#[esp_hal_embassy::main]
74+
#[esp_rtos::main]
7475
async fn main(spawner: Spawner) {
7576
let peripherals = esp_hal::init({
7677
let mut config = esp_hal::Config::default();
@@ -99,7 +100,8 @@ async fn main(spawner: Spawner) {
99100

100101
set_brownout_detection(false);
101102
let board = Board::init(peripherals).expect("Board init error");
102-
esp_hal_embassy::init(board.timg1.timer0);
103+
let software_interrupt = SoftwareInterruptControl::new(board.sw_interrupt);
104+
esp_rtos::start(board.timg1.timer0, software_interrupt.software_interrupt0);
103105
FkmLogger::set_logger();
104106

105107
log::info!("Version: {}", version::VERSION);
@@ -112,7 +114,8 @@ async fn main(spawner: Spawner) {
112114
#[cfg(feature = "qa")]
113115
log::info!("This firmware is in QA mode!");
114116

115-
let nvs = Nvs::new_from_part_table().expect("Wrong partition configuration!");
117+
let nvs = Nvs::new_from_part_table(unsafe { board.flash.clone_unchecked() })
118+
.expect("Wrong partition configuration!");
116119
let global_state = Rc::new(GlobalStateInner::new(&nvs, board.aes));
117120
let wifi_setup_sig = Rc::new(Signal::new());
118121

@@ -171,7 +174,9 @@ async fn main(spawner: Spawner) {
171174

172175
// mark ota as valid
173176
{
174-
if let Ok(mut ota) = esp_hal_ota::Ota::new(FlashStorage::new()) {
177+
if let Ok(mut ota) =
178+
esp_hal_ota::Ota::new(FlashStorage::new(unsafe { board.flash.clone_unchecked() }))
179+
{
175180
let res = ota.ota_mark_app_valid();
176181
if let Err(e) = res {
177182
log::error!("Ota mark app valid failed: {e:?}");
@@ -226,7 +231,6 @@ async fn main(spawner: Spawner) {
226231
#[cfg(not(feature = "qa"))]
227232
Some(&nvs),
228233
board.rng,
229-
board.timg0.timer0,
230234
board.wifi,
231235
unsafe { board.bt.clone_unchecked() },
232236
Some(wifi_setup_sig),

src/utils/backtrace_store.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const MAX_BACKTRACE_ADDRESSES: usize = 10;
44
const RA_OFFSET: usize = 4;
55

66
pub async fn read_saved_backtrace() {
7-
if let Some(nvs_part) = esp_hal_wifimanager::Nvs::read_nvs_partition_offset() {
8-
let mut flash = FlashStorage::new();
7+
if let Some(nvs_part) = esp_hal_wifimanager::Nvs::read_nvs_partition_offset(unsafe {
8+
esp_hal::peripherals::FLASH::steal()
9+
}) {
10+
let mut flash = FlashStorage::new(unsafe { esp_hal::peripherals::FLASH::steal() });
911

1012
let mut buf = [0; 1024];
1113
let res = embedded_storage::ReadStorage::read(
@@ -124,8 +126,10 @@ pub extern "Rust" fn custom_pre_backtrace() {
124126
tmp.push_str(&alloc::format!("0x{:x}\n", addr - RA_OFFSET));
125127
}
126128

127-
if let Some(nvs_part) = esp_hal_wifimanager::Nvs::read_nvs_partition_offset() {
128-
let mut flash = FlashStorage::new();
129+
if let Some(nvs_part) = esp_hal_wifimanager::Nvs::read_nvs_partition_offset(unsafe {
130+
esp_hal::peripherals::FLASH::steal()
131+
}) {
132+
let mut flash = FlashStorage::new(unsafe { esp_hal::peripherals::FLASH::steal() });
129133
_ = embedded_storage::Storage::write(
130134
&mut flash,
131135
(nvs_part.0 + nvs_part.1 - 2) as u32,

src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ fn esp32c3_rtc_apb_freq_update() {
8484

8585
rtc_cntl
8686
.store5()
87-
.modify(|_, w| unsafe { w.scratch5().bits(value) });
87+
.modify(|_, w| unsafe { w.data().bits(value) });
8888
}

src/ws.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use embassy_sync::{
1111
signal::Signal,
1212
};
1313
use embassy_time::{Duration, Instant, Timer, WithTimeout};
14-
use embedded_io_async::Write;
1514
use embedded_tls::{Aes128GcmSha256, NoVerify, TlsConfig, TlsConnection, TlsContext};
1615
use esp_hal_ota::Ota;
1716
use esp_storage::FlashStorage;
@@ -208,11 +207,11 @@ async fn ws_loop(
208207
let mut block = [0; 16];
209208
block.copy_from_slice(&random_signed.to_be_bytes());
210209

211-
global_state.aes.lock().await.process(
212-
&mut block,
213-
esp_hal::aes::Mode::Decryption128,
214-
esp_hal::aes::Key::Key16(key),
215-
);
210+
global_state
211+
.aes
212+
.lock()
213+
.await
214+
.decrypt(&mut block, esp_hal::aes::Key::Key128(key));
216215

217216
let recv_random = u64::from_be_bytes(block[..8].try_into().expect(""));
218217
let fkm_token = i32::from_be_bytes(block[8..12].try_into().expect(""));
@@ -291,7 +290,10 @@ async fn ws_rw(
291290
global_state: GlobalState,
292291
socket: &mut WsSocket<'_, '_>,
293292
) -> Result<(), WsRwError> {
294-
let mut ota = Ota::new(FlashStorage::new()).map_err(WsRwError::OtaError)?;
293+
let mut ota = Ota::new(FlashStorage::new(unsafe {
294+
esp_hal::peripherals::FLASH::steal()
295+
}))
296+
.map_err(WsRwError::OtaError)?;
295297
let tagged_publisher = TAGGED_RETURN
296298
.publisher()
297299
.map_err(|_| WsRwError::TaggedPublisherError)?;
@@ -610,17 +612,25 @@ impl WsSocket<'_, '_> {
610612
}
611613

612614
pub async fn write_all(&mut self, buf: &[u8]) -> Result<(), ()> {
613-
match self {
615+
let mut written = 0;
616+
while written < buf.len() {
617+
written += self.write(&buf[written..]).await?;
618+
}
619+
620+
Ok(())
621+
}
622+
623+
pub async fn write(&mut self, buf: &[u8]) -> Result<usize, ()> {
624+
let n = match self {
614625
WsSocket::Tls(tls_connection) => {
615-
tls_connection.write_all(buf).await.map_err(|_| ())?;
626+
let n = tls_connection.write(buf).await.map_err(|_| ())?;
616627
tls_connection.flush().await.map_err(|_| ())?;
628+
n
617629
}
618-
WsSocket::Raw(tcp_socket) => {
619-
tcp_socket.write_all(buf).await.map_err(|_| ())?;
620-
}
621-
}
630+
WsSocket::Raw(tcp_socket) => tcp_socket.write(buf).await.map_err(|_| ())?,
631+
};
622632

623-
Ok(())
633+
Ok(n)
624634
}
625635
}
626636

0 commit comments

Comments
 (0)