USB composite device example program, drag-and-drop flash writer.
Dependencies: SWD USBDevice mbed BaseDAP
RomDisk.cpp
00001 // RomDisk.cpp 2013/9/26 00002 #include "mbed.h" 00003 #include "RomDisk.h" 00004 00005 RomDisk::RomDisk() 00006 { 00007 _sectors = 128; // 64KB(512*128) 00008 } 00009 00010 int RomDisk::read(uint8_t * data, uint32_t block) 00011 { 00012 SectorIndex* p = const_cast<SectorIndex*>(sector_index); 00013 while(p->data) { 00014 if (p->block == block) { 00015 memcpy(data, p->data, 512); 00016 return 0; 00017 } 00018 p++; 00019 } 00020 memset(data, 0x00, 512); 00021 return 0; 00022 } 00023 00024 int RomDisk::write(const uint8_t * data, uint32_t block) 00025 { 00026 return 0; 00027 } 00028 00029 uint32_t RomDisk::sectors() 00030 { 00031 return _sectors; 00032 } 00033 00034 bool RomDisk::is_fat(uint32_t sector) 00035 { 00036 return sector >= 6 && sector <= 7; 00037 } 00038 00039 bool RomDisk::is_rootdir(uint32_t sector) 00040 { 00041 return sector >= 8 && sector <= 15; 00042 } 00043 00044 int RomDisk::dir_count(uint32_t sector) 00045 { 00046 if (!is_rootdir(sector)) { 00047 return -1; 00048 } 00049 return sector - 8; 00050 } 00051 00052 uint32_t RomDisk::cluster_to_sector(uint32_t cluster) 00053 { 00054 return cluster + 38; 00055 }
Generated on Wed Jul 13 2022 08:08:25 by 1.7.2