James Heavey / Mbed 2 deprecated 2665-Breakout-Game

Dependencies:   mbed

Committer:
jamesheavey
Date:
Tue Jan 05 01:14:11 2021 +0000
Revision:
0:92b180c8d407
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamesheavey 0:92b180c8d407 1 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */
jamesheavey 0:92b180c8d407 3 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 4 /* If a working storage control module is available, it should be */
jamesheavey 0:92b180c8d407 5 /* attached to the FatFs via a glue function rather than modifying it. */
jamesheavey 0:92b180c8d407 6 /* This is an example of glue functions to attach various exsisting */
jamesheavey 0:92b180c8d407 7 /* storage control modules to the FatFs module with a defined API. */
jamesheavey 0:92b180c8d407 8 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 9
jamesheavey 0:92b180c8d407 10 #include "diskio.h"
jamesheavey 0:92b180c8d407 11 #include "mbed_debug.h"
jamesheavey 0:92b180c8d407 12 #include "FATFileSystem.h"
jamesheavey 0:92b180c8d407 13
jamesheavey 0:92b180c8d407 14 using namespace mbed;
jamesheavey 0:92b180c8d407 15
jamesheavey 0:92b180c8d407 16 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 17 /* Get Drive Status */
jamesheavey 0:92b180c8d407 18 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 19
jamesheavey 0:92b180c8d407 20 DSTATUS disk_status (
jamesheavey 0:92b180c8d407 21 BYTE pdrv /* Physical drive nmuber to identify the drive */
jamesheavey 0:92b180c8d407 22 )
jamesheavey 0:92b180c8d407 23 {
jamesheavey 0:92b180c8d407 24 debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv);
jamesheavey 0:92b180c8d407 25 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status();
jamesheavey 0:92b180c8d407 26 }
jamesheavey 0:92b180c8d407 27
jamesheavey 0:92b180c8d407 28 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 29 /* Inidialize a Drive */
jamesheavey 0:92b180c8d407 30 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 31
jamesheavey 0:92b180c8d407 32 DSTATUS disk_initialize (
jamesheavey 0:92b180c8d407 33 BYTE pdrv /* Physical drive nmuber to identify the drive */
jamesheavey 0:92b180c8d407 34 )
jamesheavey 0:92b180c8d407 35 {
jamesheavey 0:92b180c8d407 36 debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv);
jamesheavey 0:92b180c8d407 37 return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize();
jamesheavey 0:92b180c8d407 38 }
jamesheavey 0:92b180c8d407 39
jamesheavey 0:92b180c8d407 40 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 41 /* Read Sector(s) */
jamesheavey 0:92b180c8d407 42 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 43
jamesheavey 0:92b180c8d407 44 DRESULT disk_read (
jamesheavey 0:92b180c8d407 45 BYTE pdrv, /* Physical drive nmuber to identify the drive */
jamesheavey 0:92b180c8d407 46 BYTE* buff, /* Data buffer to store read data */
jamesheavey 0:92b180c8d407 47 DWORD sector, /* Sector address in LBA */
jamesheavey 0:92b180c8d407 48 UINT count /* Number of sectors to read */
jamesheavey 0:92b180c8d407 49 )
jamesheavey 0:92b180c8d407 50 {
jamesheavey 0:92b180c8d407 51 debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
jamesheavey 0:92b180c8d407 52 if (FATFileSystem::_ffs[pdrv]->disk_read((uint8_t*)buff, sector, count))
jamesheavey 0:92b180c8d407 53 return RES_PARERR;
jamesheavey 0:92b180c8d407 54 else
jamesheavey 0:92b180c8d407 55 return RES_OK;
jamesheavey 0:92b180c8d407 56 }
jamesheavey 0:92b180c8d407 57
jamesheavey 0:92b180c8d407 58 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 59 /* Write Sector(s) */
jamesheavey 0:92b180c8d407 60 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 61
jamesheavey 0:92b180c8d407 62 #if _USE_WRITE
jamesheavey 0:92b180c8d407 63 DRESULT disk_write (
jamesheavey 0:92b180c8d407 64 BYTE pdrv, /* Physical drive nmuber to identify the drive */
jamesheavey 0:92b180c8d407 65 const BYTE* buff, /* Data to be written */
jamesheavey 0:92b180c8d407 66 DWORD sector, /* Sector address in LBA */
jamesheavey 0:92b180c8d407 67 UINT count /* Number of sectors to write */
jamesheavey 0:92b180c8d407 68 )
jamesheavey 0:92b180c8d407 69 {
jamesheavey 0:92b180c8d407 70 debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
jamesheavey 0:92b180c8d407 71 if (FATFileSystem::_ffs[pdrv]->disk_write((uint8_t*)buff, sector, count))
jamesheavey 0:92b180c8d407 72 return RES_PARERR;
jamesheavey 0:92b180c8d407 73 else
jamesheavey 0:92b180c8d407 74 return RES_OK;
jamesheavey 0:92b180c8d407 75 }
jamesheavey 0:92b180c8d407 76 #endif
jamesheavey 0:92b180c8d407 77
jamesheavey 0:92b180c8d407 78 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 79 /* Miscellaneous Functions */
jamesheavey 0:92b180c8d407 80 /*-----------------------------------------------------------------------*/
jamesheavey 0:92b180c8d407 81
jamesheavey 0:92b180c8d407 82 #if _USE_IOCTL
jamesheavey 0:92b180c8d407 83 DRESULT disk_ioctl (
jamesheavey 0:92b180c8d407 84 BYTE pdrv, /* Physical drive nmuber (0..) */
jamesheavey 0:92b180c8d407 85 BYTE cmd, /* Control code */
jamesheavey 0:92b180c8d407 86 void* buff /* Buffer to send/receive control data */
jamesheavey 0:92b180c8d407 87 )
jamesheavey 0:92b180c8d407 88 {
jamesheavey 0:92b180c8d407 89 debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd);
jamesheavey 0:92b180c8d407 90 switch(cmd) {
jamesheavey 0:92b180c8d407 91 case CTRL_SYNC:
jamesheavey 0:92b180c8d407 92 if(FATFileSystem::_ffs[pdrv] == NULL) {
jamesheavey 0:92b180c8d407 93 return RES_NOTRDY;
jamesheavey 0:92b180c8d407 94 } else if(FATFileSystem::_ffs[pdrv]->disk_sync()) {
jamesheavey 0:92b180c8d407 95 return RES_ERROR;
jamesheavey 0:92b180c8d407 96 }
jamesheavey 0:92b180c8d407 97 return RES_OK;
jamesheavey 0:92b180c8d407 98 case GET_SECTOR_COUNT:
jamesheavey 0:92b180c8d407 99 if(FATFileSystem::_ffs[pdrv] == NULL) {
jamesheavey 0:92b180c8d407 100 return RES_NOTRDY;
jamesheavey 0:92b180c8d407 101 } else {
jamesheavey 0:92b180c8d407 102 DWORD res = FATFileSystem::_ffs[pdrv]->disk_sectors();
jamesheavey 0:92b180c8d407 103 if(res > 0) {
jamesheavey 0:92b180c8d407 104 *((DWORD*)buff) = res; // minimum allowed
jamesheavey 0:92b180c8d407 105 return RES_OK;
jamesheavey 0:92b180c8d407 106 } else {
jamesheavey 0:92b180c8d407 107 return RES_ERROR;
jamesheavey 0:92b180c8d407 108 }
jamesheavey 0:92b180c8d407 109 }
jamesheavey 0:92b180c8d407 110 case GET_BLOCK_SIZE:
jamesheavey 0:92b180c8d407 111 *((DWORD*)buff) = 1; // default when not known
jamesheavey 0:92b180c8d407 112 return RES_OK;
jamesheavey 0:92b180c8d407 113
jamesheavey 0:92b180c8d407 114 }
jamesheavey 0:92b180c8d407 115 return RES_PARERR;
jamesheavey 0:92b180c8d407 116 }
jamesheavey 0:92b180c8d407 117 #endif