use enum for drive numbers

This commit is contained in:
Christoph Baumann
2025-04-22 14:15:45 +02:00
parent 5798dcde0d
commit fe5e4dc40a
4 changed files with 39 additions and 43 deletions

View File

@@ -10,6 +10,7 @@ extern "C" {
#endif #endif
#include <utils/types.h> #include <utils/types.h>
#include <fatfs_cfg.h>
/* Status of Disk Functions */ /* Status of Disk Functions */
typedef BYTE DSTATUS; typedef BYTE DSTATUS;
@@ -23,14 +24,6 @@ typedef enum {
RES_PARERR /* 4: Invalid Parameter */ RES_PARERR /* 4: Invalid Parameter */
} DRESULT; } DRESULT;
typedef enum {
DRIVE_SD = 0,
DRIVE_RAM = 1,
DRIVE_EMMC = 2,
DRIVE_BIS = 3,
DRIVE_EMU = 4
} DDRIVE;
/*---------------------------------------*/ /*---------------------------------------*/
/* Prototypes for disk control functions */ /* Prototypes for disk control functions */

View File

@@ -14,18 +14,18 @@
#include <bdk.h> #include <bdk.h>
#include <libs/fatfs/diskio.h> /* FatFs lower layer API */ #include <libs/fatfs/diskio.h> /* FatFs lower layer API */
#include "ffconf.h" #include <fatfs_cfg.h>
static bool ensure_partition(BYTE pdrv){ static bool ensure_partition(BYTE pdrv){
u8 part; u8 part;
switch(pdrv){ switch(pdrv){
case FF_DEV_SD: case DRIVE_SD:
return true; return true;
case FF_DEV_BOOT1: case DRIVE_BOOT1:
case FF_DEV_BOOT1_1MB: case DRIVE_BOOT1_1MB:
part = EMMC_BOOT1; part = EMMC_BOOT1;
break; break;
case FF_DEV_GPP: case DRIVE_EMMC:
part = EMMC_GPP; part = EMMC_GPP;
break; break;
default: default:
@@ -72,13 +72,13 @@ DRESULT disk_read (
sdmmc_storage_t *storage = &sd_storage; sdmmc_storage_t *storage = &sd_storage;
u32 actual_sector = sector; u32 actual_sector = sector;
switch(pdrv){ switch(pdrv){
case FF_DEV_SD: case DRIVE_SD:
break; break;
case FF_DEV_BOOT1: case DRIVE_BOOT1:
case FF_DEV_GPP: case DRIVE_EMMC:
storage = &emmc_storage; storage = &emmc_storage;
break; break;
case FF_DEV_BOOT1_1MB: case DRIVE_BOOT1_1MB:
storage = &emmc_storage; storage = &emmc_storage;
actual_sector = sector + (0x100000 / 512); actual_sector = sector + (0x100000 / 512);
break; break;
@@ -105,13 +105,13 @@ DRESULT disk_write (
sdmmc_storage_t *storage = &sd_storage; sdmmc_storage_t *storage = &sd_storage;
u32 actual_sector = sector; u32 actual_sector = sector;
switch(pdrv){ switch(pdrv){
case FF_DEV_SD: case DRIVE_SD:
break; break;
case FF_DEV_BOOT1: case DRIVE_BOOT1:
case FF_DEV_GPP: case DRIVE_EMMC:
storage = &emmc_storage; storage = &emmc_storage;
break; break;
case FF_DEV_BOOT1_1MB: case DRIVE_BOOT1_1MB:
storage = &emmc_storage; storage = &emmc_storage;
actual_sector = sector + (0x100000 / 512); actual_sector = sector + (0x100000 / 512);
break; break;

View File

@@ -300,9 +300,12 @@
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be / SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
/ included somewhere in the scope of ff.h. */ / included somewhere in the scope of ff.h. */
#define FF_DEV_BOOT1 1
#define FF_DEV_BOOT1_1MB 2 typedef enum {
#define FF_DEV_SD 0 DRIVE_SD = 0,
#define FF_DEV_GPP 3 DRIVE_BOOT1 = 1,
DRIVE_BOOT1_1MB = 2,
DRIVE_EMMC = 3,
} DDRIVE;
/*--- End of configuration options ---*/ /*--- End of configuration options ---*/

View File

@@ -1,6 +1,6 @@
#include "boot_storage.h" #include "boot_storage.h"
#include <libs/fatfs/ff.h> #include <libs/fatfs/ff.h>
#include "../libs/fatfs/ffconf.h" #include <fatfs_cfg.h>
#include <storage/sd.h> #include <storage/sd.h>
#include <storage/emmc.h> #include <storage/emmc.h>
#include <utils/types.h> #include <utils/types.h>
@@ -11,10 +11,10 @@ static FATFS boot_storage_fs;
static BYTE drive = -1; static BYTE drive = -1;
static const char* drive_base_paths[] = { static const char* drive_base_paths[] = {
[FF_DEV_SD] = XSTR(FF_DEV_SD) ":", [DRIVE_SD] = XSTR(DRIVE_SD) ":",
[FF_DEV_BOOT1] = XSTR(FF_DEV_BOOT1) ":", [DRIVE_BOOT1] = XSTR(DRIVE_BOOT1) ":",
[FF_DEV_BOOT1_1MB] = XSTR(FF_DEV_BOOT1_1MB) ":", [DRIVE_BOOT1_1MB] = XSTR(DRIVE_BOOT1_1MB) ":",
[FF_DEV_GPP] = XSTR(FF_DEV_GPP) ":", [DRIVE_EMMC] = XSTR(DRIVE_EMMC) ":",
}; };
static bool _is_eligible(){ static bool _is_eligible(){
@@ -30,11 +30,11 @@ bool boot_storage_get_mounted(){
bool boot_storage_get_initialized(){ bool boot_storage_get_initialized(){
switch(drive){ switch(drive){
case FF_DEV_BOOT1: case DRIVE_BOOT1:
case FF_DEV_GPP: case DRIVE_EMMC:
case FF_DEV_BOOT1_1MB: case DRIVE_BOOT1_1MB:
return emmc_get_initialized(); return emmc_get_initialized();
case FF_DEV_SD: case DRIVE_SD:
return sd_get_card_initialized(); return sd_get_card_initialized();
} }
return false; return false;
@@ -42,11 +42,11 @@ bool boot_storage_get_initialized(){
static bool _boot_storage_initialize(){ static bool _boot_storage_initialize(){
switch(drive){ switch(drive){
case FF_DEV_BOOT1: case DRIVE_BOOT1:
case FF_DEV_GPP: case DRIVE_EMMC:
case FF_DEV_BOOT1_1MB: case DRIVE_BOOT1_1MB:
return emmc_initialize(false); return emmc_initialize(false);
case FF_DEV_SD: case DRIVE_SD:
return sd_initialize(false); return sd_initialize(false);
} }
return false; return false;
@@ -54,7 +54,7 @@ static bool _boot_storage_initialize(){
static void _boot_storage_end(bool deinit){ static void _boot_storage_end(bool deinit){
if(boot_storage_get_mounted()){ if(boot_storage_get_mounted()){
if(drive == FF_DEV_SD){ if(drive == DRIVE_SD){
sd_unmount(); sd_unmount();
}else{ }else{
f_mount(NULL, drive_base_paths[drive], false); f_mount(NULL, drive_base_paths[drive], false);
@@ -62,7 +62,7 @@ static void _boot_storage_end(bool deinit){
drive = DEV_INVALID; drive = DEV_INVALID;
} }
if(deinit){ if(deinit){
if(drive == FF_DEV_SD){ if(drive == DRIVE_SD){
sd_end(); sd_end();
}else{ }else{
emmc_end(); emmc_end();
@@ -87,7 +87,7 @@ static bool _boot_storage_mount(){
goto emmc_init_fail; goto emmc_init_fail;
} }
static const BYTE emmc_drives[] = {FF_DEV_BOOT1_1MB, FF_DEV_BOOT1, FF_DEV_GPP}; static const BYTE emmc_drives[] = {DRIVE_BOOT1_1MB, DRIVE_BOOT1, DRIVE_EMMC};
for(BYTE i = 0; i < ARRAY_SIZE(emmc_drives); i++){ for(BYTE i = 0; i < ARRAY_SIZE(emmc_drives); i++){
res = f_mount(&boot_storage_fs, drive_base_paths[i], true); res = f_mount(&boot_storage_fs, drive_base_paths[i], true);
@@ -121,10 +121,10 @@ emmc_init_fail:
goto out; goto out;
} }
res = f_chdrive(drive_base_paths[FF_DEV_SD]); res = f_chdrive(drive_base_paths[DRIVE_SD]);
if(res == FR_OK && _is_eligible()){ if(res == FR_OK && _is_eligible()){
drive = FF_DEV_SD; drive = DRIVE_SD;
return true; return true;
} }