diff options
Diffstat (limited to 'extmod/vfs_fat_diskio.c')
-rw-r--r-- | extmod/vfs_fat_diskio.c | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 3f1902b2e0..24c00ffba1 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -28,7 +28,7 @@ */ #include "py/mpconfig.h" -#if MICROPY_FSUSERMOUNT +#if MICROPY_VFS && MICROPY_VFS_FAT #include <stdint.h> #include <stdio.h> @@ -36,9 +36,9 @@ #include "py/mphal.h" #include "py/runtime.h" -#include "lib/fatfs/ff.h" /* FatFs lower layer API */ -#include "lib/fatfs/diskio.h" /* FatFs lower layer API */ -#include "extmod/fsusermount.h" +#include "lib/oofatfs/ff.h" +#include "lib/oofatfs/diskio.h" +#include "extmod/vfs_fat.h" #if _MAX_SS == _MIN_SS #define SECSIZE(fs) (_MIN_SS) @@ -46,20 +46,18 @@ #define SECSIZE(fs) ((fs)->ssize) #endif -STATIC fs_user_mount_t *disk_get_device(uint id) { - if (id < MP_ARRAY_SIZE(MP_STATE_PORT(fs_user_mount))) { - return MP_STATE_PORT(fs_user_mount)[id]; - } else { - return NULL; - } +typedef void *bdev_t; +STATIC fs_user_mount_t *disk_get_device(void *bdev) { + return (fs_user_mount_t*)bdev; } /*-----------------------------------------------------------------------*/ /* Initialize a Drive */ /*-----------------------------------------------------------------------*/ +STATIC DSTATUS disk_initialize ( - BYTE pdrv /* Physical drive nmuber (0..) */ + bdev_t pdrv /* Physical drive nmuber (0..) */ ) { fs_user_mount_t *vfs = disk_get_device(pdrv); @@ -89,8 +87,9 @@ DSTATUS disk_initialize ( /* Get Disk Status */ /*-----------------------------------------------------------------------*/ +STATIC DSTATUS disk_status ( - BYTE pdrv /* Physical drive nmuber (0..) */ + bdev_t pdrv /* Physical drive nmuber (0..) */ ) { fs_user_mount_t *vfs = disk_get_device(pdrv); @@ -110,7 +109,7 @@ DSTATUS disk_status ( /*-----------------------------------------------------------------------*/ DRESULT disk_read ( - BYTE pdrv, /* Physical drive nmuber (0..) */ + bdev_t pdrv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ UINT count /* Number of sectors to read (1..128) */ @@ -140,9 +139,8 @@ DRESULT disk_read ( /* Write Sector(s) */ /*-----------------------------------------------------------------------*/ -#if _USE_WRITE DRESULT disk_write ( - BYTE pdrv, /* Physical drive nmuber (0..) */ + bdev_t pdrv, /* Physical drive nmuber (0..) */ const BYTE *buff, /* Data to be written */ DWORD sector, /* Sector address (LBA) */ UINT count /* Number of sectors to write (1..128) */ @@ -172,16 +170,14 @@ DRESULT disk_write ( return RES_OK; } -#endif /*-----------------------------------------------------------------------*/ /* Miscellaneous Functions */ /*-----------------------------------------------------------------------*/ -#if _USE_IOCTL DRESULT disk_ioctl ( - BYTE pdrv, /* Physical drive nmuber (0..) */ + bdev_t pdrv, /* Physical drive nmuber (0..) */ BYTE cmd, /* Control code */ void *buff /* Buffer to send/receive control data */ ) @@ -218,6 +214,10 @@ DRESULT disk_ioctl ( } else { *((WORD*)buff) = mp_obj_get_int(ret); } + #if _MAX_SS != _MIN_SS + // need to store ssize because we use it in disk_read/disk_write + vfs->fatfs.ssize = *((WORD*)buff); + #endif return RES_OK; } @@ -225,6 +225,14 @@ DRESULT disk_ioctl ( *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; + case IOCTL_INIT: + *((DSTATUS*)buff) = disk_initialize(pdrv); + return RES_OK; + + case IOCTL_STATUS: + *((DSTATUS*)buff) = disk_status(pdrv); + return RES_OK; + default: return RES_PARERR; } @@ -245,17 +253,28 @@ DRESULT disk_ioctl ( case GET_SECTOR_SIZE: *((WORD*)buff) = 512; // old protocol had fixed sector size + #if _MAX_SS != _MIN_SS + // need to store ssize because we use it in disk_read/disk_write + vfs->fatfs.ssize = 512; + #endif return RES_OK; case GET_BLOCK_SIZE: *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; + case IOCTL_INIT: + *((DSTATUS*)buff) = disk_initialize(pdrv); + return RES_OK; + + case IOCTL_STATUS: + *((DSTATUS*)buff) = disk_status(pdrv); + return RES_OK; + default: return RES_PARERR; } } } -#endif -#endif // MICROPY_FSUSERMOUNT +#endif // MICROPY_VFS && MICROPY_VFS_FAT |