main/task_sdcard.c

changeset 1
ad2c8b13eb88
parent 0
b74b0e4902c3
child 4
6d1f512cd074
equal deleted inserted replaced
0:b74b0e4902c3 1:ad2c8b13eb88
18 18
19 #include "config.h" 19 #include "config.h"
20 20
21 21
22 22
23 SDCARD_State * sdcard_state; 23 SDCARD_State *sdcard_state; ///< SD card status
24 JSON_log * json_log; 24 JSON_log *json_log; ///< JSON log array
25 EventGroupHandle_t xEventGroupSDcard; ///< SD card events. 25 EventGroupHandle_t xEventGroupSDcard; ///< SD card events.
26 26
27 static const char *TAG = "task_sdcard"; 27 static const char *TAG = "task_sdcard";
28 static sdmmc_card_t* s_card = NULL; 28 static sdmmc_card_t* s_card = NULL;
29 static uint8_t s_pdrv = 0; 29 static uint8_t s_pdrv = 0;
31 31
32 BYTE pdrv = 0xFF; 32 BYTE pdrv = 0xFF;
33 33
34 34
35 #define SDCARD_HOST_SLOT VSPI_HOST ///< HSPI_HOST is used by the TFT 35 #define SDCARD_HOST_SLOT VSPI_HOST ///< HSPI_HOST is used by the TFT
36 #define SDCARD_PIN_NUM_MISO 2 36 #define SDCARD_PIN_NUM_MISO 2 ///< MISO pin
37 #define SDCARD_PIN_NUM_MOSI 15 37 #define SDCARD_PIN_NUM_MOSI 15 ///< MOSI pin
38 #define SDCARD_PIN_NUM_CLK 14 38 #define SDCARD_PIN_NUM_CLK 14 ///< CLOCK
39 #define SDCARD_PIN_NUM_CS 13 39 #define SDCARD_PIN_NUM_CS 13 ///< Chip select pin
40 #define SDCARD_DMA_CHANNEL 2 ///< Channel 1 is used by the TFT 40 #define SDCARD_DMA_CHANNEL 2 ///< Channel 1 is used by the TFT
41 41
42 42
43 const int TASK_SDCARD_LOG_CLEAN = BIT0; ///< Clean spiffs logfile directory 43 const int TASK_SDCARD_LOG_CLEAN = BIT0; ///< Clean spiffs logfile directory
44 const int TASK_SDCARD_LOG_CLOSE = BIT1; ///< Close the logfile. 44 const int TASK_SDCARD_LOG_CLOSE = BIT1; ///< Close the logfile.
189 } 189 }
190 } 190 }
191 191
192 192
193 193
194 /* 194 /**
195 * This is a local modified version of the esp_vfs_fat_sdmmc_mount() function in 195 * @brief This is a local modified version of the esp_vfs_fat_sdmmc_mount() function in
196 * the FreeRTOS components library. It is here so we can better handle errors 196 * the FreeRTOS components library. It is here so we can better handle errors
197 * for our application. 197 * for our application.
198 * @param base_path The mount path
199 * @param host_config SPI host configuration
200 * @param slot_config Slot configuration
201 * @return Error condition.
198 */ 202 */
199 esp_err_t my_vfs_fat_sdmmc_init(const char* base_path, const sdmmc_host_t* host_config, const void* slot_config) 203 esp_err_t my_vfs_fat_sdmmc_init(const char* base_path, const sdmmc_host_t* host_config, const void* slot_config)
200 { 204 {
201 if (s_card != NULL) { 205 if (s_card != NULL) {
202 return ESP_ERR_INVALID_STATE; 206 return ESP_ERR_INVALID_STATE;
246 return err; 250 return err;
247 } 251 }
248 252
249 253
250 254
255 /**
256 * @brief Mount SD card.
257 * @param base_path The mountpoint
258 * @param host_config SPI host configuration
259 * @param slot_config Slot configuration
260 * @param mount_config Mount configuration
261 * @param[out] out_card Card information
262 * @return Error condition
263 */
251 esp_err_t my_esp_vfs_fat_sdmmc_mount(const char* base_path, 264 esp_err_t my_esp_vfs_fat_sdmmc_mount(const char* base_path,
252 const sdmmc_host_t* host_config, 265 const sdmmc_host_t* host_config,
253 const void* slot_config, 266 const void* slot_config,
254 const esp_vfs_fat_mount_config_t* mount_config, 267 const esp_vfs_fat_mount_config_t* mount_config,
255 sdmmc_card_t** out_card) 268 sdmmc_card_t** out_card)
305 return err; 318 return err;
306 } 319 }
307 320
308 321
309 322
310 esp_err_t my_esp_vfs_fat_sdmmc_unmount() 323 /**
324 * @brief Unmount a mounted SD card,
325 * @return Error condition
326 */
327 esp_err_t my_esp_vfs_fat_sdmmc_unmount(void)
311 { 328 {
312 if (s_card == NULL) { 329 if (s_card == NULL) {
313 return ESP_ERR_INVALID_STATE; 330 return ESP_ERR_INVALID_STATE;
314 } 331 }
315 // unmount 332 // unmount
349 return 0; 366 return 0;
350 } 367 }
351 368
352 369
353 370
371 /**
372 * @brief Sync directories.
373 * @param fromdir Source directory
374 * @param todir Destination directory
375 */
354 void SyncDirs(char *fromdir, char *todir) 376 void SyncDirs(char *fromdir, char *todir)
355 { 377 {
356 char ff[64], tf[64]; 378 char ff[64], tf[64];
357 struct stat fs, ts; 379 struct stat fs, ts;
358 int rc; 380 int rc;

mercurial