Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

diskio.cpp 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*-----------------------------------------------------------------------*/
  2. /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
  3. /*-----------------------------------------------------------------------*/
  4. /* This is a stub disk I/O module that acts as front end of the existing */
  5. /* disk I/O modules and attach it to FatFs module with common interface. */
  6. /*-----------------------------------------------------------------------*/
  7. #include "ffconf.h"
  8. #include "diskio.h"
  9. #include "mbed_debug.h"
  10. #include "FATFileSystem.h"
  11. using namespace mbed;
  12. DSTATUS disk_initialize (
  13. BYTE drv /* Physical drive nmuber (0..) */
  14. )
  15. {
  16. debug_if(FFS_DBG, "disk_initialize on drv [%d]\n", drv);
  17. return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize();
  18. }
  19. DSTATUS disk_status (
  20. BYTE drv /* Physical drive nmuber (0..) */
  21. )
  22. {
  23. debug_if(FFS_DBG, "disk_status on drv [%d]\n", drv);
  24. return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status();
  25. }
  26. DRESULT disk_read (
  27. BYTE drv, /* Physical drive nmuber (0..) */
  28. BYTE *buff, /* Data buffer to store read data */
  29. DWORD sector, /* Sector address (LBA) */
  30. BYTE count /* Number of sectors to read (1..255) */
  31. )
  32. {
  33. debug_if(FFS_DBG, "disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv);
  34. if (FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, sector, count))
  35. return RES_PARERR;
  36. else
  37. return RES_OK;
  38. }
  39. #if _READONLY == 0
  40. DRESULT disk_write (
  41. BYTE drv, /* Physical drive nmuber (0..) */
  42. const BYTE *buff, /* Data to be written */
  43. DWORD sector, /* Sector address (LBA) */
  44. BYTE count /* Number of sectors to write (1..255) */
  45. )
  46. {
  47. debug_if(FFS_DBG, "disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv);
  48. if (FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, sector, count))
  49. return RES_PARERR;
  50. else
  51. return RES_OK;
  52. }
  53. #endif /* _READONLY */
  54. DRESULT disk_ioctl (
  55. BYTE drv, /* Physical drive nmuber (0..) */
  56. BYTE ctrl, /* Control code */
  57. void *buff /* Buffer to send/receive control data */
  58. )
  59. {
  60. debug_if(FFS_DBG, "disk_ioctl(%d)\n", ctrl);
  61. switch(ctrl) {
  62. case CTRL_SYNC:
  63. if(FATFileSystem::_ffs[drv] == NULL) {
  64. return RES_NOTRDY;
  65. } else if(FATFileSystem::_ffs[drv]->disk_sync()) {
  66. return RES_ERROR;
  67. }
  68. return RES_OK;
  69. case GET_SECTOR_COUNT:
  70. if(FATFileSystem::_ffs[drv] == NULL) {
  71. return RES_NOTRDY;
  72. } else {
  73. DWORD res = FATFileSystem::_ffs[drv]->disk_sectors();
  74. if(res > 0) {
  75. *((DWORD*)buff) = res; // minimum allowed
  76. return RES_OK;
  77. } else {
  78. return RES_ERROR;
  79. }
  80. }
  81. case GET_BLOCK_SIZE:
  82. *((DWORD*)buff) = 1; // default when not known
  83. return RES_OK;
  84. }
  85. return RES_PARERR;
  86. }