From fa667dbc782f0930331fc698c78b12c608d94bfe Mon Sep 17 00:00:00 2001 From: bsongis Date: Sat, 23 Jun 2012 19:44:53 +0000 Subject: [PATCH] SD File Manager --- src/FatFs/ffconf.h | 2 +- src/Makefile | 3 +- src/board_ersky9x.h | 3 + src/general_menus.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++ src/open9x.h | 16 ++++++ src/simpgmspace.cpp | 36 +++++++++++- src/simpgmspace.h | 1 + 7 files changed, 187 insertions(+), 4 deletions(-) diff --git a/src/FatFs/ffconf.h b/src/FatFs/ffconf.h index 534122a2c..2e13e3420 100644 --- a/src/FatFs/ffconf.h +++ b/src/FatFs/ffconf.h @@ -110,7 +110,7 @@ / enable LFN feature and set _LFN_UNICODE to 1. */ -#define _FS_RPATH 0 /* 0 to 2 */ +#define _FS_RPATH 2 /* 0 to 2 */ /* The _FS_RPATH option configures relative path feature. / / 0: Disable relative path feature and remove related functions. diff --git a/src/Makefile b/src/Makefile index e2796347c..87597ca1f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -352,7 +352,8 @@ ifeq ($(PCB), V4) CPPSRC += stock/audio.cpp haptic.cpp ifeq ($(SDCARD), YES) - CPPSRC += gruvin9x/logs.cpp FatFs/fattime.c gruvin9x/rtc.cpp FatFs/ff.c FatFs/option/ccsbcs.c gruvin9x/diskio.cpp + CPPSRC += gruvin9x/logs.cpp FatFs/fattime.c gruvin9x/rtc.cpp gruvin9x/diskio.cpp + EXTRABOARDSRC += FatFs/ff.c FatFs/option/ccsbcs.c MODS:=${MODS}S endif diff --git a/src/board_ersky9x.h b/src/board_ersky9x.h index 7aa3c78c9..4464209af 100644 --- a/src/board_ersky9x.h +++ b/src/board_ersky9x.h @@ -70,4 +70,7 @@ uint16_t getCurrent(); extern uint16_t Temperature ; // Raw temp reading extern uint16_t maxTemperature ; // Raw temp reading +#define strcpy_P strcpy +#define strcat_P strcat + #endif diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 13d3a079f..af8246711 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -41,6 +41,9 @@ enum EnumTabDiag { e_Setup, #if defined(PCBV4) && defined(SDCARD) e_FrskyTime, +#endif +#if defined(SDCARD) + e_Sd, #endif e_Trainer, e_Vers, @@ -53,6 +56,9 @@ void menuProcSetup(uint8_t event); #if defined(PCBV4) && defined(SDCARD) void menuProcTime(uint8_t event); #endif +#if defined(SDCARD) +void menuProcSd(uint8_t event); +#endif void menuProcTrainer(uint8_t event); void menuProcDiagVers(uint8_t event); void menuProcDiagKeys(uint8_t event); @@ -63,6 +69,9 @@ const MenuFuncP_PROGMEM menuTabDiag[] PROGMEM = { menuProcSetup, #if defined(PCBV4) && defined(SDCARD) menuProcTime, +#endif +#if defined(SDCARD) + menuProcSd, #endif menuProcTrainer, menuProcDiagVers, @@ -504,6 +513,127 @@ void menuProcTime(uint8_t event) } #endif +#if defined(SDCARD) +#if defined(PCBARM) && !defined(SIMU) +// TODO rewrite this ... +extern uint32_t Cmd_A41_resp; +#define OCR_SD_CCS (1UL << 30) +#else +#define Cmd_A41_resp 0 +#define OCR_SD_CCS (0) +#endif + +const char STR_DELETE_FILE[] = "Delete"; +const char STR_COPY_FILE[] = "Copy"; +const char STR_RENAME_FILE[] = "Rename"; + +void menuProcSd(uint8_t event) +{ + FILINFO fno; + DIR dir; + char *fn; /* This function is assuming non-Unicode cfg. */ +#if _USE_LFN + TCHAR lfn[_MAX_LFN + 1]; + fno.lfname = lfn; + fno.lfsize = sizeof(lfn); +#endif + + uint8_t _event = event; + if (s_menu_count) { + event = 0; + } + + SIMPLE_MENU(Cmd_A41_resp & OCR_SD_CCS ? PSTR("SD-HC Card") : PSTR("SD Card"), menuTabDiag, e_Sd, 1+reusableBuffer.sd.count); + + s_editMode = 0; + + switch(event) { + case EVT_ENTRY: + reusableBuffer.sd.offset = 255; + break; + case EVT_KEY_FIRST(KEY_RIGHT): + case EVT_KEY_FIRST(KEY_MENU): + { + if (m_posVert > 0) { + uint8_t index = m_posVert-1-s_pgOfs; + if (reusableBuffer.sd.flags[index]) { + killEvents(event); + f_chdir(reusableBuffer.sd.lines[index]); + s_pgOfs = 0; + reusableBuffer.sd.offset = 255; + } + } + break; + } + case EVT_KEY_LONG(KEY_MENU): + killEvents(event); + s_menu[s_menu_count++] = STR_DELETE_FILE; + s_menu[s_menu_count++] = STR_RENAME_FILE; + s_menu[s_menu_count++] = STR_COPY_FILE; + break; + } + + if (reusableBuffer.sd.offset != s_pgOfs) { + memset(reusableBuffer.sd.lines, 0, sizeof(reusableBuffer.sd.lines)); + reusableBuffer.sd.offset = s_pgOfs; + reusableBuffer.sd.count = 0; + uint16_t offset = 0; + uint8_t count = 0; + FRESULT res = f_opendir(&dir, "."); /* Open the directory */ + if (res == FR_OK) { + for (;;) { + res = f_readdir(&dir, &fno); /* Read a directory item */ + if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ + if (fno.fname[0] == '.' && fno.fname[1] == '\0') continue; /* Ignore dot entry */ +#if _USE_LFN + fn = *fno.lfname ? fno.lfname : fno.fname; +#else + fn = fno.fname; +#endif + reusableBuffer.sd.count++; + if (offset < s_pgOfs) { + offset++; + continue; + } + + if (count < 7) { + reusableBuffer.sd.flags[count] = (fno.fattrib & AM_DIR); + char * line = reusableBuffer.sd.lines[count]; + memset(line, 0, SD_SCREEN_FILE_LENGTH); + for (uint8_t i=0; i #include #include +namespace simu { +#include +} volatile uint8_t pinb=0xff, pinc=0xff, pind, pine=0xff, ping=0xff, pinh=0xff, pinj=0xff, pinl=0; uint8_t portb, portc, porth=0, dummyport; @@ -306,13 +309,27 @@ FRESULT f_close (FIL*) return FR_OK; } -FRESULT f_opendir (DIR*, const TCHAR*) +FRESULT f_chdir (const TCHAR *name) { + chdir(name); return FR_OK; } -FRESULT f_readdir (DIR*, FILINFO*) +FRESULT f_opendir (DIR * rep, const TCHAR * name) { + rep->fs = (FATFS *)simu::opendir(name); + return FR_OK; +} + +FRESULT f_readdir (DIR * rep, FILINFO * fil) +{ + simu::dirent * ent = simu::readdir((simu::DIR *)rep->fs); + if (!ent) return FR_NO_FILE; + if(ent->d_type == simu::DT_DIR) fil->fattrib = AM_DIR; else fil->fattrib = 0; + memset(fil->fname, 0, 13); + memset(fil->lfname, 0, SD_SCREEN_FILE_LENGTH); + strncpy(fil->fname, ent->d_name, 13-1); + strcpy(fil->lfname, ent->d_name); return FR_OK; } @@ -321,5 +338,20 @@ FRESULT f_mkdir (const TCHAR*) return FR_OK; } +FRESULT f_unlink (const TCHAR*) +{ + return FR_OK; +} + +int f_puts (const TCHAR*, FIL*) +{ + return 0; /* Put a string to the file */ +} + +int f_printf (FIL*, const TCHAR*, ...) /* Put a formatted string to the file */ +{ + return 0; +} + uint32_t Card_state = 8; #endif diff --git a/src/simpgmspace.h b/src/simpgmspace.h index 1cf0224c3..7d2e98a0d 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -142,6 +142,7 @@ extern void rxPdcUsart( void (*pChProcess)(uint8_t x) ); #define cli() #define sei() #define strcpy_P strcpy +#define strcat_P strcat #define memcpy_P memcpy #define PORTA dummyport