From b278a06fd4eee2b9fcfdb17f606b495e4081cee0 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 23 May 2021 18:56:03 +0300 Subject: [PATCH] Use defines in header for SD card buffers --- main.c | 4 ---- nanovna.h | 11 +++++++++++ ui.c | 13 ------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 5ee8256..df21572 100644 --- a/main.c +++ b/main.c @@ -762,10 +762,6 @@ void send_buffer(uint8_t * buf, int s) #ifndef __USE_SD_CARD__ #error "Need enable SD card support __USE_SD_CARD__ in nanovna.h, for use ENABLE_SD_CARD_CMD" #endif -// Fat file system work area (at the end of spi_buffer) -static FATFS *fs_volume = (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)); -// FatFS file object (at the end of spi_buffer) -static FIL *fs_file = ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)); static FRESULT cmd_sd_card_mount(void){ const FRESULT res = f_mount(fs_volume, "", 1); diff --git a/nanovna.h b/nanovna.h index d9384a4..d182f17 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1322,6 +1322,17 @@ void rtc_set_time(uint32_t dr, uint32_t tr); #include "../FatFs/ff.h" #include "../FatFs/diskio.h" bool SD_Inserted(void); +// Buffers for SD card use spi_buffer +#if SPI_BUFFER_SIZE < 2048 +#error "SPI_BUFFER_SIZE for SD card support need size >= 2048" +#else +// Fat file system work area (at the end of spi_buffer) +#define fs_volume (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)) +// FatFS file object (at the end of spi_buffer) +#define fs_file ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)) +// Filename object (at the end of spi_buffer) +#define fs_filename ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4) +#endif void testLog(void); // debug log #endif diff --git a/ui.c b/ui.c index 92f2b81..1a71816 100644 --- a/ui.c +++ b/ui.c @@ -71,19 +71,6 @@ volatile uint8_t operation_requested = OP_NONE; int8_t previous_marker = MARKER_INVALID; -#ifdef __USE_SD_CARD__ -#if SPI_BUFFER_SIZE < 2048 -#error "SPI_BUFFER_SIZE for SD card support need size >= 2048" -#else -// Fat file system work area (at the end of spi_buffer) -static FATFS *fs_volume = (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)); -// FatFS file object (at the end of spi_buffer) -static FIL *fs_file = ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)); -// Filename object (at the end of spi_buffer) -static char *fs_filename = ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4); -#endif -#endif - enum { UI_NORMAL, UI_MENU, UI_KEYPAD };