3636#include "py/mphal.h"
3737
3838#include "py/runtime.h"
39- #if MICROPY_FATFS_OO
4039#include "lib/oofatfs/ff.h"
4140#include "lib/oofatfs/diskio.h"
42- #else
43- #include "lib/fatfs/ff.h" /* FatFs lower layer API */
44- #include "lib/fatfs/diskio.h" /* FatFs lower layer API */
45- #endif
4641#include "extmod/fsusermount.h"
4742
4843#if _MAX_SS == _MIN_SS
5146#define SECSIZE (fs ) ((fs)->ssize)
5247#endif
5348
54- #if MICROPY_FATFS_OO
5549typedef void * bdev_t ;
5650STATIC fs_user_mount_t * disk_get_device (void * bdev ) {
5751 return (fs_user_mount_t * )bdev ;
5852}
59- #else
60- typedef BYTE bdev_t ;
61- STATIC fs_user_mount_t * disk_get_device (uint id ) {
62- if (id < MP_ARRAY_SIZE (MP_STATE_PORT (fs_user_mount ))) {
63- return MP_STATE_PORT (fs_user_mount )[id ];
64- } else {
65- return NULL ;
66- }
67- }
68- #endif
6953
7054/*-----------------------------------------------------------------------*/
7155/* Initialize a Drive */
7256/*-----------------------------------------------------------------------*/
7357
74- #if MICROPY_FATFS_OO
7558STATIC
76- #endif
7759DSTATUS disk_initialize (
7860 bdev_t pdrv /* Physical drive nmuber (0..) */
7961)
@@ -105,9 +87,7 @@ DSTATUS disk_initialize (
10587/* Get Disk Status */
10688/*-----------------------------------------------------------------------*/
10789
108- #if MICROPY_FATFS_OO
10990STATIC
110- #endif
11191DSTATUS disk_status (
11292 bdev_t pdrv /* Physical drive nmuber (0..) */
11393)
@@ -159,7 +139,6 @@ DRESULT disk_read (
159139/* Write Sector(s) */
160140/*-----------------------------------------------------------------------*/
161141
162- #if MICROPY_FATFS_OO || _USE_WRITE
163142DRESULT disk_write (
164143 bdev_t pdrv , /* Physical drive nmuber (0..) */
165144 const BYTE * buff , /* Data to be written */
@@ -191,14 +170,12 @@ DRESULT disk_write (
191170
192171 return RES_OK ;
193172}
194- #endif
195173
196174
197175/*-----------------------------------------------------------------------*/
198176/* Miscellaneous Functions */
199177/*-----------------------------------------------------------------------*/
200178
201- #if MICROPY_FATFS_OO || _USE_IOCTL
202179DRESULT disk_ioctl (
203180 bdev_t pdrv , /* Physical drive nmuber (0..) */
204181 BYTE cmd , /* Control code */
@@ -237,7 +214,7 @@ DRESULT disk_ioctl (
237214 } else {
238215 * ((WORD * )buff ) = mp_obj_get_int (ret );
239216 }
240- #if MICROPY_FATFS_OO && _MAX_SS != _MIN_SS
217+ #if _MAX_SS != _MIN_SS
241218 // need to store ssize because we use it in disk_read/disk_write
242219 vfs -> fatfs .ssize = * ((WORD * )buff );
243220 #endif
@@ -248,15 +225,13 @@ DRESULT disk_ioctl (
248225 * ((DWORD * )buff ) = 1 ; // erase block size in units of sector size
249226 return RES_OK ;
250227
251- #if MICROPY_FATFS_OO
252228 case IOCTL_INIT :
253229 * ((DSTATUS * )buff ) = disk_initialize (pdrv );
254230 return RES_OK ;
255231
256232 case IOCTL_STATUS :
257233 * ((DSTATUS * )buff ) = disk_status (pdrv );
258234 return RES_OK ;
259- #endif
260235
261236 default :
262237 return RES_PARERR ;
@@ -278,7 +253,7 @@ DRESULT disk_ioctl (
278253
279254 case GET_SECTOR_SIZE :
280255 * ((WORD * )buff ) = 512 ; // old protocol had fixed sector size
281- #if MICROPY_FATFS_OO && _MAX_SS != _MIN_SS
256+ #if _MAX_SS != _MIN_SS
282257 // need to store ssize because we use it in disk_read/disk_write
283258 vfs -> fatfs .ssize = 512 ;
284259 #endif
@@ -288,21 +263,18 @@ DRESULT disk_ioctl (
288263 * ((DWORD * )buff ) = 1 ; // erase block size in units of sector size
289264 return RES_OK ;
290265
291- #if MICROPY_FATFS_OO
292266 case IOCTL_INIT :
293267 * ((DSTATUS * )buff ) = disk_initialize (pdrv );
294268 return RES_OK ;
295269
296270 case IOCTL_STATUS :
297271 * ((DSTATUS * )buff ) = disk_status (pdrv );
298272 return RES_OK ;
299- #endif
300273
301274 default :
302275 return RES_PARERR ;
303276 }
304277 }
305278}
306- #endif
307279
308280#endif // MICROPY_VFS
0 commit comments