diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 7cb2221..25405c1 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/ili9341.c b/ili9341.c index 2db68b4..c20a882 100644 --- a/ili9341.c +++ b/ili9341.c @@ -1456,7 +1456,7 @@ static void SD_PowerOn(void) { } // Power off SD -static inline void SD_PowerOff(void) { +void SD_PowerOff(void) { Stat &= ~STA_POWER_ON; } @@ -1477,6 +1477,8 @@ DWORD get_fattime (void) { // diskio.c - Initialize SD DSTATUS disk_initialize(BYTE pdrv) { + if (CardType && (Stat & STA_POWER_ON)) + return 0; // Debug counters #if DEBUG == 1 w_cnt = 0; diff --git a/main.c b/main.c index ead3953..5268458 100644 --- a/main.c +++ b/main.c @@ -73,7 +73,9 @@ static volatile vna_shellcmd_t shell_function = 0; #endif #ifdef __USE_SD_CARD__ +#ifdef __DISABLE_HOT_INSERT__ uint16_t sd_card_inserted_at_boot = false; +#endif // Enable SD card console command #define ENABLE_SD_CARD_CMD #endif @@ -2620,8 +2622,9 @@ int main(void) PULSE ili9341_drawstring("Starting...", 0,0); PULSE - +#ifdef __DISABLE_HOT_INSERT__ sd_card_inserted_at_boot = SD_Inserted(); +#endif disk_initialize(0); PULSE // SD_PowerOn(); diff --git a/nanovna.h b/nanovna.h index efd0d9a..7900aef 100644 --- a/nanovna.h +++ b/nanovna.h @@ -47,6 +47,7 @@ #define __SI4432__ #endif #ifdef TINYSA4 +//#define __DISABLE_HOT_INSERT__ #define __SI4463__ #define __SI4468__ #define __ADF4351__ @@ -1570,6 +1571,7 @@ void rtc_set_time(uint32_t dr, uint32_t tr); #include "../FatFs/diskio.h" extern uint16_t sd_card_inserted_at_boot; bool SD_Inserted(void); +void SD_PowerOff(void); // Buffers for SD card use spi_buffer #if SPI_BUFFER_SIZE < 2048 #error "SPI_BUFFER_SIZE for SD card support need size >= 2048" diff --git a/plot.c b/plot.c index d77f2f4..eef5fb0 100644 --- a/plot.c +++ b/plot.c @@ -1841,11 +1841,12 @@ draw_frequencies(void) // } ili9341_drawstring(buf2, p2, FREQUENCIES_YPOS); ili9341_drawstring(buf1, FREQUENCIES_XPOS1, FREQUENCIES_YPOS); + ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); #ifdef TINYSA4 if (get_sweep_frequency(ST_STOP) > 2000000000ULL && setting.attenuate_x2 >= 16 ) { - ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); ili9341_drawstring("REDUCED LINEARITY", p2 - 18*7, FREQUENCIES_YPOS); - } + } else + ili9341_drawstring(" ", p2 - 18*7, FREQUENCIES_YPOS); #endif } @@ -1884,7 +1885,10 @@ static const uint8_t sd_icon [] = { else{ ili9341_set_background(LCD_BG_COLOR); ili9341_fill(4, SD_CARD_START, 16, 16); + SD_PowerOff(); +#ifdef __DISABLE_HOT_INSERT__ sd_card_inserted_at_boot = false; +#endif } #endif int16_t vbat = adc_vbat_read(); diff --git a/ui.c b/ui.c index 99865a1..1cbf51f 100644 --- a/ui.c +++ b/ui.c @@ -2101,11 +2101,12 @@ static const uint8_t bmp_header_v4[14+56] = { FRESULT open_file(char *ext) { +#ifdef __DISABLE_HOT_INSERT__ if (!sd_card_inserted_at_boot) { drawMessageBox("Warning:", "Restart tinySA to use SD card", 2000); return FR_NOT_READY; } - +#endif FRESULT res = f_mount(fs_volume, "", 1); // fs_volume, fs_file and fs_filename stored at end of spi_buffer!!!!! // shell_printf("Mount = %d\r\n", res); @@ -2141,10 +2142,12 @@ made_screenshot(int touch_x, int touch_y) ili9341_set_background(LCD_BG_COLOR); ili9341_fill(4, SD_CARD_START, 16, 16); touch_wait_release(); +#ifdef __DISABLE_HOT_INSERT__ if (!sd_card_inserted_at_boot) { drawMessageBox("Warning:", "Restart tinySA to use SD card", 2000); return FALSE; } +#endif // uint32_t time = chVTGetSystemTimeX(); // shell_printf("Screenshot\r\n"); FRESULT res = open_file("bmp"); @@ -2339,7 +2342,11 @@ static void extcb1(EXTDriver *extp, expchannel_t channel) { (void)extp; (void)channel; - if (channel != 9) +#ifdef __USE_SD_CARD__ + if (channel == 12) + SD_PowerOff(); +#endif + if (channel < 9) operation_requested|=OP_LEVER; // cur_button = READ_PORT() & BUTTON_MASK; } @@ -2362,7 +2369,11 @@ static const EXTConfig extcfg = { #endif {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, +#ifdef __USE_SD_CARD__ + {EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOB, extcb1}, +#else {EXT_CH_MODE_DISABLED, NULL}, +#endif {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL}, diff --git a/ui_sa.c b/ui_sa.c index a2eb578..13455b2 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -603,13 +603,13 @@ static UI_FUNCTION_ADV_CALLBACK(menu_internals_acb) if (b){ return; } - if (unlock_internals != 4321) { + if (unlock_internals != 5432) { kp_help_text = "Internals access code"; ui_mode_keypad(KM_CODE); - if (uistat.value != 4321) { + if (uistat.value != 5432) { return; } - unlock_internals = 4321; + unlock_internals = 5432; } menu_push_submenu(menu_settings2); }