Skip to content

Commit

Permalink
USB Mode popups optimise
Browse files Browse the repository at this point in the history
  • Loading branch information
jmamma committed Oct 23, 2024
1 parent 26823c2 commit 67e793d
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions avr/cores/megacommand/MCL/MCLSysConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
#include "MCL_impl.h"

void usb_wait() {
// Consolidated display function to reduce code duplication
static void show_message(const char* line1) {
oled_display.clearDisplay();
oled_display.textbox("PLEASE WAIT", "");
oled_display.textbox(line1, "");
oled_display.display();
}

// Common wait routine
static inline void usb_wait() {
show_message("PLEASE WAIT");
delay(4000);
}

bool megacmd_check() {
// Simplified megacmd check
static inline bool megacmd_check() {
if (!IS_MEGACMD()) {
oled_display.textbox("MODE ", "N/A");
oled_display.display();
show_message("MODE N/A");
return false;
}
return true;
}

void usb_os_update() {
// Combined USB mode change function
static void enter_usb_mode(uint8_t mode, const char* line1) {
usb_wait();
change_usb_mode(USB_SERIAL);
oled_display.clearDisplay();
oled_display.textbox("OS UPDATE", "");
oled_display.display();
while (1)
;
show_message(line1);

if (mode == USB_STORAGE) {
LOCAL_SPI_DISABLE();
EXTERNAL_SPI_ENABLE();
}

change_usb_mode(mode);
while (1); // Infinite loop
}

// Optimized public functions
void usb_os_update() {
enter_usb_mode(USB_SERIAL, "OS UPDATE");
}

void usb_dfu_mode() {
usb_wait();
oled_display.clearDisplay();
oled_display.textbox("DFU ", "MODE");
oled_display.display();
//DFU mode is activated via datalines between CPUs
SET_USB_MODE(USB_DFU);
while (1)
;
enter_usb_mode(USB_DFU, "DFU MODE");
}

void usb_disk_mode() {
if (!megacmd_check()) {
return;
if (megacmd_check()) {
enter_usb_mode(USB_STORAGE, "USB DISK");
}
usb_wait();
oled_display.clearDisplay();

oled_display.textbox("USB ", "DISK");
oled_display.display();

LOCAL_SPI_DISABLE();
EXTERNAL_SPI_ENABLE();
change_usb_mode(USB_STORAGE);
while (1)
;
}


void mclsys_apply_config() {
DEBUG_PRINT_FN();
GUI.display_mirror = mcl_cfg.display_mirror;
Expand Down

0 comments on commit 67e793d

Please sign in to comment.