diff --git a/cores/esp32/USBMSC.cpp b/cores/esp32/USBMSC.cpp index 6d36117b886..eeaf3026535 100644 --- a/cores/esp32/USBMSC.cpp +++ b/cores/esp32/USBMSC.cpp @@ -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; } diff --git a/cores/esp32/USBMSC.h b/cores/esp32/USBMSC.h index e9d41e0b7f3..454aca3520a 100644 --- a/cores/esp32/USBMSC.h +++ b/cores/esp32/USBMSC.h @@ -44,6 +44,7 @@ class USBMSC { 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); diff --git a/cores/esp32/esp32-hal-tinyusb.c b/cores/esp32/esp32-hal-tinyusb.c index d3b55bf907f..bab17a3980f 100644 --- a/cores/esp32/esp32-hal-tinyusb.c +++ b/cores/esp32/esp32-hal-tinyusb.c @@ -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 /* diff --git a/libraries/USB/examples/USBMSC/USBMSC.ino b/libraries/USB/examples/USBMSC/USBMSC.ino index 47c6084580d..532691ba63d 100644 --- a/libraries/USB/examples/USBMSC/USBMSC.ino +++ b/libraries/USB/examples/USBMSC/USBMSC.ino @@ -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(); }