Skip to content

Commit cc5d573

Browse files
committed
Clean up espflash functions, add unchecked bootloader command
1 parent b50a0f0 commit cc5d573

4 files changed

Lines changed: 292 additions & 393 deletions

File tree

src/app.rs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use crate::{
6363
#[cfg(feature = "espflash")]
6464
use crate::keybinds::esp_methods::*;
6565
#[cfg(feature = "espflash")]
66-
use crate::serial::esp::EspEvent;
66+
use crate::serial::esp::{EspEvent, EspRestartType};
6767
#[cfg(feature = "espflash")]
6868
use crate::tui::esp::espflash_buttons;
6969
#[cfg(feature = "espflash")]
@@ -1045,12 +1045,21 @@ impl App {
10451045

10461046
#[cfg(feature = "espflash")]
10471047
_ if m == ESP_HARD_RESET => {
1048-
self.serial.esp_restart(false).unwrap();
1048+
self.serial.esp_restart(EspRestartType::UserCode).unwrap();
10491049
}
10501050

10511051
#[cfg(feature = "espflash")]
10521052
_ if m == ESP_BOOTLOADER => {
1053-
self.serial.esp_restart(true).unwrap();
1053+
self.serial
1054+
.esp_restart(EspRestartType::Bootloader { active: true })
1055+
.unwrap();
1056+
}
1057+
1058+
#[cfg(feature = "espflash")]
1059+
_ if m == ESP_BOOTLOADER_UNCHECKED => {
1060+
self.serial
1061+
.esp_restart(EspRestartType::Bootloader { active: false })
1062+
.unwrap();
10541063
}
10551064

10561065
#[cfg(feature = "espflash")]
@@ -1601,6 +1610,9 @@ impl App {
16011610
} else {
16021611
match selected {
16031612
0 => self.run_method_from_string(ESP_HARD_RESET).unwrap(),
1613+
1 if ctrl_pressed || shift_pressed => self
1614+
.run_method_from_string(ESP_BOOTLOADER_UNCHECKED)
1615+
.unwrap(),
16041616
1 => self.run_method_from_string(ESP_BOOTLOADER).unwrap(),
16051617
2 => self.run_method_from_string(ESP_DEVICE_INFO).unwrap(),
16061618
3 => {
@@ -2281,6 +2293,26 @@ impl App {
22812293
bins_area,
22822294
&mut self.popup_table_state,
22832295
);
2296+
2297+
if let Some(profile) = self
2298+
.popup_table_state
2299+
.selected()
2300+
.and_then(|idx| self.espflash.profile_from_index(idx))
2301+
{
2302+
let hint_text = match profile {
2303+
esp::EspProfile::Bins(_) => "Flash profile binaries to ESP Flash.",
2304+
esp::EspProfile::Elf(profile) if profile.ram => {
2305+
"Load profile ELF into RAM."
2306+
}
2307+
esp::EspProfile::Elf(_) => "Flash profile ELF to ESP Flash.",
2308+
};
2309+
render_scrolling_line(
2310+
hint_text,
2311+
frame,
2312+
scrolling_text_area,
2313+
&mut self.popup_desc_scroll,
2314+
);
2315+
}
22842316
} else {
22852317
frame.render_stateful_widget(
22862318
esp::espflash_buttons(&mut self.popup_table_state),
@@ -2292,6 +2324,23 @@ impl App {
22922324
self.espflash.profiles_table(&mut self.popup_table_state),
22932325
bins_area,
22942326
);
2327+
2328+
let hints = [
2329+
"Attempt to remotely reset the chip.",
2330+
"Attempt to reboot into bootloader. Shift/Ctrl to skip check.",
2331+
"Query ESP for Flash Size, MAC Address, etc.",
2332+
"Erase all flash contents.",
2333+
];
2334+
if let Some(idx) = self.popup_table_state.selected() {
2335+
if let Some(&hint_text) = hints.get(idx) {
2336+
render_scrolling_line(
2337+
hint_text,
2338+
frame,
2339+
scrolling_text_area,
2340+
&mut self.popup_desc_scroll,
2341+
);
2342+
}
2343+
}
22952344
}
22962345
frame.render_widget(
22972346
Line::raw("Flash Profiles | Ctrl+R: Reload")

src/keybinds.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub mod esp_methods {
2929
pub const RELOAD_ESPFLASH: &str = "reload-espflash";
3030
pub const ESP_HARD_RESET: &str = "esp-hard-reset";
3131
pub const ESP_BOOTLOADER: &str = "esp-bootloader";
32+
pub const ESP_BOOTLOADER_UNCHECKED: &str = "esp-bootloader-unchecked";
3233
pub const ESP_DEVICE_INFO: &str = "esp-device-info";
3334
pub const ESP_ERASE_FLASH: &str = "esp-erase-flash";
3435
}
@@ -49,6 +50,7 @@ ctrl-d = "toggle-indices"
4950
ctrl-f = "reload-colors"
5051
F20 = "esp-hard-reset"
5152
F21 = "esp-bootloader"
53+
ctrl-z = "esp-bootloader-unchecked"
5254
5355
[macros]
5456
F19 = "Restart"

src/serial/esp.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,26 @@ use crate::{
2020
pub enum EspCommand {
2121
EraseFlash,
2222
FlashProfile(EspProfile),
23-
Restart { bootloader: bool },
23+
Restart(EspRestartType),
2424
DeviceInfo,
2525
}
2626

27+
#[derive(Debug)]
28+
pub enum EspRestartType {
29+
Bootloader { active: bool },
30+
UserCode,
31+
}
32+
2733
impl From<EspCommand> for SerialWorkerCommand {
2834
fn from(value: EspCommand) -> Self {
2935
SerialWorkerCommand::PortCommand(PortCommand::Esp(value))
3036
}
3137
}
3238

3339
impl SerialHandle {
34-
pub fn esp_restart(&self, bootloader: bool) -> YapResult<()> {
40+
pub fn esp_restart(&self, restart_type: EspRestartType) -> YapResult<()> {
3541
self.command_tx
36-
.send(EspCommand::Restart { bootloader }.into())
42+
.send(EspCommand::Restart(restart_type).into())
3743
.map_err(|_| YapError::NoSerialWorker)
3844
}
3945

0 commit comments

Comments
 (0)