Skip to content

[2.0.0] Add support to read/write raw sectors from/to sd card #4777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libraries/SD/src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,15 @@ uint64_t SDFS::usedBytes()
return size;
}

bool SDFS::readRAW(uint8_t* buffer, uint32_t sector)
{
return sd_read_raw(_pdrv, buffer, sector);
}

bool SDFS::writeRAW(uint8_t* buffer, uint32_t sector)
{
return sd_write_raw(_pdrv, buffer, sector);
}


SDFS SD = SDFS(FSImplPtr(new VFSImpl()));
2 changes: 2 additions & 0 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class SDFS : public FS
uint64_t cardSize();
uint64_t totalBytes();
uint64_t usedBytes();
bool readRAW(uint8_t* buffer, uint32_t sector);
bool writeRAW(uint8_t* buffer, uint32_t sector);
};

}
Expand Down
9 changes: 9 additions & 0 deletions libraries/SD/src/sd_diskio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,15 @@ DRESULT ff_sd_ioctl(uint8_t pdrv, uint8_t cmd, void* buff)
return RES_PARERR;
}

bool sd_read_raw(uint8_t pdrv, uint8_t* buffer, DWORD sector)
{
return ff_sd_read(pdrv, buffer, sector, 1) == ESP_OK;
}

bool sd_write_raw(uint8_t pdrv, uint8_t* buffer, DWORD sector)
{
return ff_sd_write(pdrv, buffer, sector, 1) == ESP_OK;
}

/*
* Public methods
Expand Down
3 changes: 3 additions & 0 deletions libraries/SD/src/sd_diskio.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Arduino.h"
#include "SPI.h"
#include "sd_defines.h"
// #include "diskio.h"

uint8_t sdcard_init(uint8_t cs, SPIClass * spi, int hz);
uint8_t sdcard_uninit(uint8_t pdrv);
Expand All @@ -27,5 +28,7 @@ uint8_t sdcard_unmount(uint8_t pdrv);
sdcard_type_t sdcard_type(uint8_t pdrv);
uint32_t sdcard_num_sectors(uint8_t pdrv);
uint32_t sdcard_sector_size(uint8_t pdrv);
bool sd_read_raw(uint8_t pdrv, uint8_t* buffer, uint32_t sector);
bool sd_write_raw(uint8_t pdrv, uint8_t* buffer, uint32_t sector);

#endif /* _SD_DISKIO_H_ */