diff --git a/nyx/Makefile b/nyx/Makefile index 649cba51..e1529547 100644 --- a/nyx/Makefile +++ b/nyx/Makefile @@ -41,7 +41,7 @@ OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \ bm92t36.o bq24193.o max17050.o max7762x.o max77620-rtc.o regulator_5v.o \ touch.o joycon.o tmp451.o fan.o \ usbd.o xusbd.o usb_descriptors.o usb_gadget_ums.o usb_gadget_hid.o \ - hw_init.o boot_storage.o \ + hw_init.o boot_storage.o sfd.o\ ) # Utilities. diff --git a/nyx/nyx_gui/libs/fatfs/diskio.c b/nyx/nyx_gui/libs/fatfs/diskio.c index 8bbab46c..206bc363 100644 --- a/nyx/nyx_gui/libs/fatfs/diskio.c +++ b/nyx/nyx_gui/libs/fatfs/diskio.c @@ -16,6 +16,7 @@ #include /* FatFs lower layer API */ #include +#include "../../storage/sfd.h" static u32 sd_rsvd_sectors = 0; static u32 ramdisk_sectors = 0; @@ -35,6 +36,7 @@ static bool ensure_partition(BYTE pdrv){ case DRIVE_RAM: case DRIVE_BIS: case DRIVE_EMU: + case DRIVE_SFD: return true; default: return false; @@ -96,6 +98,8 @@ DRESULT disk_read ( return sdmmc_storage_read(&emmc_storage, sector + (0x100000 / 512), count, buff) ? RES_OK : RES_ERROR; case DRIVE_BOOT1: return sdmmc_storage_read(&emmc_storage, sector, count, buff) ? RES_OK : RES_ERROR; + case DRIVE_SFD: + return sfd_read(sector, count ,buff) ? RES_OK : RES_ERROR; } return RES_ERROR; @@ -130,6 +134,8 @@ DRESULT disk_write ( return sdmmc_storage_write(&emmc_storage, sector + (0x100000 / 512), count, (void*)buff) ? RES_OK : RES_ERROR; case DRIVE_BOOT1: return sdmmc_storage_write(&emmc_storage, sector, count, (void*)buff) ? RES_OK : RES_ERROR; + case DRIVE_SFD: + return sfd_write(sector, count, (void*)buff) ? RES_OK : RES_ERROR; } return RES_ERROR; diff --git a/nyx/nyx_gui/libs/fatfs/ffconf.h b/nyx/nyx_gui/libs/fatfs/ffconf.h index 039975df..a96fbf40 100644 --- a/nyx/nyx_gui/libs/fatfs/ffconf.h +++ b/nyx/nyx_gui/libs/fatfs/ffconf.h @@ -179,13 +179,13 @@ / Drive/Volume Configurations /---------------------------------------------------------------------------*/ -#define FF_VOLUMES 7 +#define FF_VOLUMES 8 /* Number of volumes (logical drives) to be used. (1-10) */ #define FF_STR_VOLUME_ID 1 // Order is important. Any change to order, must also be reflected to diskio drive enum. -#define FF_VOLUME_STRS "sd","ram","emmc","bis","emu", "boot1", "boot1_1mb" +#define FF_VOLUME_STRS "sd","ram","emmc","bis","emu", "boot1", "boot1_1mb", "sfd" /* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. / When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive / number in the path name. FF_VOLUME_STRS defines the volume ID strings for each @@ -309,6 +309,7 @@ typedef enum { DRIVE_EMU = 4, DRIVE_BOOT1 = 5, DRIVE_BOOT1_1MB = 6, + DRIVE_SFD = 7, } DDRIVE; /*--- End of configuration options ---*/ diff --git a/nyx/nyx_gui/storage/sfd.c b/nyx/nyx_gui/storage/sfd.c new file mode 100644 index 00000000..dac617d9 --- /dev/null +++ b/nyx/nyx_gui/storage/sfd.c @@ -0,0 +1,42 @@ +#include "sfd.h" +#include +#include + +static sdmmc_storage_t *_storage; +static u32 _offset; +static u32 _size; + +static void ensure_partition(){ + if(_storage == &emmc_storage){ + emmc_set_partition(EMMC_GPP); + } +} + +int sfd_read(u32 sector, u32 count, void *buff){ + if(sector + _offset + count > _offset + _size){ + return 0; + } + ensure_partition(); + return sdmmc_storage_read(_storage, sector + _offset, count, buff); +} + +int sfd_write(u32 sector, u32 count, void *buff){ + if(sector + _offset + count > _offset + _size){ + return 0; + } + ensure_partition(); + return sdmmc_storage_write(_storage, sector + _offset, count, buff); +} + +bool sfd_init(sdmmc_storage_t *storage, u32 offset, u32 size){ + _storage = storage; + _offset = offset; + _size = size; + return true; +} + +void sfd_end(){ + _storage = NULL; + _offset = 0; + _size = 0; +} \ No newline at end of file diff --git a/nyx/nyx_gui/storage/sfd.h b/nyx/nyx_gui/storage/sfd.h new file mode 100644 index 00000000..28a1f683 --- /dev/null +++ b/nyx/nyx_gui/storage/sfd.h @@ -0,0 +1,14 @@ +#ifndef _SFD_H +#define _SFD_H + +#include +#include + +int sfd_read(u32 sector, u32 count, void *buff); +int sfd_write(u32 sector, u32 count, void *buff); + +bool sfd_init(sdmmc_storage_t *storage, u32 offset, u32 size); +void sfd_end(); + + +#endif \ No newline at end of file