Fix doc path
[opentx.git] / radio / src / sdcard.h
blob6ab26d0901b99b658b5cfdf97c1941788b222c24
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _SDCARD_H_
22 #define _SDCARD_H_
24 #if !defined(SIMU)
25 #include "ff.h"
26 #endif
28 #include "opentx.h"
30 #define ROOT_PATH "/"
31 #define MODELS_PATH ROOT_PATH "MODELS" // no trailing slash = important
32 #define RADIO_PATH ROOT_PATH "RADIO" // no trailing slash = important
33 #define LOGS_PATH ROOT_PATH "LOGS"
34 #define SCREENSHOTS_PATH ROOT_PATH "SCREENSHOTS"
35 #define SOUNDS_PATH ROOT_PATH "SOUNDS/en"
36 #define SOUNDS_PATH_LNG_OFS (sizeof(SOUNDS_PATH)-3)
37 #define SYSTEM_SUBDIR "SYSTEM"
38 #define BITMAPS_PATH ROOT_PATH "IMAGES"
39 #define FIRMWARES_PATH ROOT_PATH "FIRMWARE"
40 #define EEPROMS_PATH ROOT_PATH "EEPROM"
41 #define SCRIPTS_PATH ROOT_PATH "SCRIPTS"
42 #define WIZARD_PATH SCRIPTS_PATH "/WIZARD"
43 #define THEMES_PATH ROOT_PATH "THEMES"
44 #define LAYOUTS_PATH ROOT_PATH "LAYOUTS"
45 #define WIDGETS_PATH ROOT_PATH "WIDGETS"
46 #define WIZARD_NAME "wizard.lua"
47 #define SCRIPTS_MIXES_PATH SCRIPTS_PATH "/MIXES"
48 #define SCRIPTS_FUNCS_PATH SCRIPTS_PATH "/FUNCTIONS"
49 #define SCRIPTS_TELEM_PATH SCRIPTS_PATH "/TELEMETRY"
51 #define LEN_FILE_PATH_MAX (sizeof(SCRIPTS_TELEM_PATH)+1) // longest + "/"
53 #if defined(COLORLCD)
54 const char RADIO_MODELSLIST_PATH[] = RADIO_PATH "/models.txt";
55 const char RADIO_SETTINGS_PATH[] = RADIO_PATH "/radio.bin";
56 #define SPLASH_FILE "splash.png"
57 #endif
59 #define MODELS_EXT ".bin"
60 #define LOGS_EXT ".csv"
61 #define SOUNDS_EXT ".wav"
62 #define BMP_EXT ".bmp"
63 #define PNG_EXT ".png"
64 #define JPG_EXT ".jpg"
65 #define SCRIPT_EXT ".lua"
66 #define SCRIPT_BIN_EXT ".luac"
67 #define TEXT_EXT ".txt"
68 #define FIRMWARE_EXT ".bin"
69 #define EEPROM_EXT ".bin"
70 #define SPORT_FIRMWARE_EXT ".frk"
72 #define LEN_FILE_EXTENSION_MAX 5 // longest used, including the dot, excluding null term.
74 #if defined(PCBHORUS)
75 #define BITMAPS_EXT BMP_EXT JPG_EXT PNG_EXT
76 #define LEN_BITMAPS_EXT 4
77 #else
78 #define BITMAPS_EXT BMP_EXT
79 #endif
81 #ifdef LUA_COMPILER
82 #define SCRIPTS_EXT SCRIPT_BIN_EXT SCRIPT_EXT
83 #else
84 #define SCRIPTS_EXT SCRIPT_EXT
85 #endif
87 #define GET_FILENAME(filename, path, var, ext) \
88 char filename[sizeof(path) + sizeof(var) + sizeof(ext)]; \
89 memcpy(filename, path, sizeof(path) - 1); \
90 filename[sizeof(path) - 1] = '/'; \
91 memcpy(&filename[sizeof(path)], var, sizeof(var)); \
92 filename[sizeof(path)+sizeof(var)] = '\0'; \
93 strcat(&filename[sizeof(path)], ext)
95 extern FATFS g_FATFS_Obj;
96 extern FIL g_oLogFile;
98 extern uint8_t logDelay;
99 void logsInit();
100 void logsClose();
101 void logsWrite();
103 bool sdCardFormat();
104 uint32_t sdGetNoSectors();
105 uint32_t sdGetSize();
106 uint32_t sdGetFreeSectors();
107 const char * sdCheckAndCreateDirectory(const char * path);
109 #if !defined(BOOT)
110 inline const pm_char * SDCARD_ERROR(FRESULT result)
112 if (result == FR_NOT_READY)
113 return STR_NO_SDCARD;
114 else
115 return STR_SDCARD_ERROR;
117 #endif
119 // NOTE: 'size' must = 0 or be a valid character position within 'filename' array -- it is NOT validated
120 const char * getFileExtension(const char * filename, uint8_t size=0, uint8_t extMaxLen=0, uint8_t *fnlen=NULL, uint8_t *extlen=NULL);
122 // TODO REMOVE THE O9X FOURCC in 2.3
123 #if defined(PCBX12S)
124 #define OTX_FOURCC 0x3478746F // otx for X12S
125 #define O9X_FOURCC 0x3178396F // we forgot it in 2.2 RC ..
126 #elif defined(PCBX10)
127 #define OTX_FOURCC 0x3778746F // otx for X10
128 #define O9X_FOURCC 0x3478746F // match X12S, we forgot OTX_FOURCC before 2.2.1 RC2
129 #elif defined(PCBX9E)
130 #define OTX_FOURCC 0x3578746F // otx for Taranis X9E
131 #define O9X_FOURCC 0x3378396F // o9x for Taranis X9E
132 #elif defined(PCBXLITE)
133 #define OTX_FOURCC 0x3978746F // otx for Taranis X-Lite
134 #define O9X_FOURCC 0x3978396F // o9x for Taranis X-Lite
135 #elif defined(PCBX7)
136 #define OTX_FOURCC 0x3678746F // otx for Taranis X7
137 #define O9X_FOURCC 0x3378396F // o9x for Taranis X7
138 #elif defined(PCBX9D) || defined(PCBX9DP)
139 #define OTX_FOURCC 0x3378746F // otx for Taranis X9D
140 #define O9X_FOURCC 0x3378396F // o9x for Taranis X9D
141 #elif defined(PCBSKY9X)
142 #define OTX_FOURCC 0x3278746F // otx for sky9x
143 #define O9X_FOURCC 0x3278396F // o9x for sky9x
144 #elif defined(PCBGRUVIN9X) || defined(PCBMEGA2560)
145 #define OTX_FOURCC 0x3178746F // otx for gruvin9x/MEGA2560
146 #define O9X_FOURCC 0x3178396F // o9x for gruvin9x/MEGA2560
147 #endif
149 bool isFileAvailable(const char * filename, bool exclDir = false);
150 int findNextFileIndex(char * filename, uint8_t size, const char * directory);
151 bool isExtensionMatching(const char * extension, const char * pattern, char * match = NULL);
153 const char * sdCopyFile(const char * src, const char * dest);
154 const char * sdCopyFile(const char * srcFilename, const char * srcDir, const char * destFilename, const char * destDir);
156 #define LIST_NONE_SD_FILE 1
157 #define LIST_SD_FILE_EXT 2
158 bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen, const char * selection, uint8_t flags=0);
160 bool isCwdAtRoot();
161 FRESULT sdReadDir(DIR * dir, FILINFO * fno, bool & firstTime);
163 #endif // _SDCARD_H_