Unverified Commit a04fceee authored by Happy Code Farm's avatar Happy Code Farm Committed by GitHub

feat(usbmsc): Add is_writable function to the USBMSC class. (#9569)

* (feat)usbmsc: Add is_writable function

Add is_writable function to the USBMSC class.
Allows USBMSC to be mounted in read-only mode.

* Update USBMSC.ino

Changes to USB Mass Storage (MSC) example code in Arduino USB library

* Added MSC.isWritable(true) line to set the disk as writable

* ci(pre-commit): Apply automatic fixes

---------
Co-authored-by: default avatarRodrigo Garcia <rodrigo.garcia@espressif.com>
Co-authored-by: default avatarpre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
parent e8e251ab
......@@ -33,6 +33,7 @@ extern "C" uint16_t tusb_msc_load_descriptor(uint8_t *dst, uint8_t *itf) {
typedef struct {
bool media_present;
bool is_writable;
uint8_t vendor_id[8];
uint8_t product_id[16];
uint8_t product_rev[4];
......@@ -179,11 +180,17 @@ int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, u
return resplen;
}
bool tud_msc_is_writable_cb(uint8_t lun) {
log_v("[%u]: %u", lun, msc_luns[lun].is_writable);
return msc_luns[lun].is_writable; // RAM disk is always ready
}
USBMSC::USBMSC() {
if (MSC_ACTIVE_LUN < MSC_MAX_LUN) {
_lun = MSC_ACTIVE_LUN;
MSC_ACTIVE_LUN++;
msc_luns[_lun].media_present = false;
msc_luns[_lun].is_writable = true;
msc_luns[_lun].vendor_id[0] = 0;
msc_luns[_lun].product_id[0] = 0;
msc_luns[_lun].product_rev[0] = 0;
......@@ -213,6 +220,7 @@ bool USBMSC::begin(uint32_t block_count, uint16_t block_size) {
void USBMSC::end() {
msc_luns[_lun].media_present = false;
msc_luns[_lun].is_writable = false;
msc_luns[_lun].vendor_id[0] = 0;
msc_luns[_lun].product_id[0] = 0;
msc_luns[_lun].product_rev[0] = 0;
......@@ -247,6 +255,10 @@ void USBMSC::onWrite(msc_write_cb cb) {
msc_luns[_lun].write = cb;
}
void USBMSC::isWritable(bool is_writable) {
msc_luns[_lun].is_writable = is_writable;
}
void USBMSC::mediaPresent(bool media_present) {
msc_luns[_lun].media_present = media_present;
}
......
......@@ -44,6 +44,7 @@ public:
void productID(const char *pid); //max 16 chars
void productRevision(const char *ver); //max 4 chars
void mediaPresent(bool media_present);
void isWritable(bool is_writable);
void onStartStop(msc_start_stop_cb cb);
void onRead(msc_read_cb cb);
void onWrite(msc_write_cb cb);
......
......@@ -390,6 +390,10 @@ __attribute__((weak)) int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint
__attribute__((weak)) int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) {
return -1;
}
__attribute__((weak)) bool tud_msc_is_writable_cb(uint8_t lun) {
return false;
}
#endif
/*
......
......@@ -152,7 +152,10 @@ void setup() {
MSC.onStartStop(onStartStop);
MSC.onRead(onRead);
MSC.onWrite(onWrite);
MSC.mediaPresent(true);
MSC.isWritable(true); // true if writable, false if read-only
MSC.begin(DISK_SECTOR_COUNT, DISK_SECTOR_SIZE);
USB.begin();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment