Skip to content

Commit ceed1f8

Browse files
committed
(feat)usbmsc: Add is_writable function
Add is_writable function to the USBMSC class. Allows USBMSC to be mounted in read-only mode.
1 parent cf44890 commit ceed1f8

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

cores/esp32/USBMSC.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C" uint16_t tusb_msc_load_descriptor(uint8_t *dst, uint8_t *itf) {
3333

3434
typedef struct {
3535
bool media_present;
36+
bool is_writable;
3637
uint8_t vendor_id[8];
3738
uint8_t product_id[16];
3839
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
179180
return resplen;
180181
}
181182

183+
bool tud_msc_is_writable_cb(uint8_t lun) {
184+
log_v("[%u]: %u", lun, msc_luns[lun].is_writable);
185+
return msc_luns[lun].is_writable; // RAM disk is always ready
186+
}
187+
182188
USBMSC::USBMSC() {
183189
if (MSC_ACTIVE_LUN < MSC_MAX_LUN) {
184190
_lun = MSC_ACTIVE_LUN;
185191
MSC_ACTIVE_LUN++;
186192
msc_luns[_lun].media_present = false;
193+
msc_luns[_lun].is_writable = true;
187194
msc_luns[_lun].vendor_id[0] = 0;
188195
msc_luns[_lun].product_id[0] = 0;
189196
msc_luns[_lun].product_rev[0] = 0;
@@ -213,6 +220,7 @@ bool USBMSC::begin(uint32_t block_count, uint16_t block_size) {
213220

214221
void USBMSC::end() {
215222
msc_luns[_lun].media_present = false;
223+
msc_luns[_lun].is_writable = false;
216224
msc_luns[_lun].vendor_id[0] = 0;
217225
msc_luns[_lun].product_id[0] = 0;
218226
msc_luns[_lun].product_rev[0] = 0;
@@ -247,6 +255,10 @@ void USBMSC::onWrite(msc_write_cb cb) {
247255
msc_luns[_lun].write = cb;
248256
}
249257

258+
void USBMSC::isWritable(bool is_writable) {
259+
msc_luns[_lun].is_writable = is_writable;
260+
}
261+
250262
void USBMSC::mediaPresent(bool media_present) {
251263
msc_luns[_lun].media_present = media_present;
252264
}

cores/esp32/USBMSC.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class USBMSC {
4444
void productID(const char *pid); //max 16 chars
4545
void productRevision(const char *ver); //max 4 chars
4646
void mediaPresent(bool media_present);
47+
void isWritable(bool is_writable);
4748
void onStartStop(msc_start_stop_cb cb);
4849
void onRead(msc_read_cb cb);
4950
void onWrite(msc_write_cb cb);

cores/esp32/esp32-hal-tinyusb.c

+4
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ __attribute__((weak)) int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint
390390
__attribute__((weak)) int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) {
391391
return -1;
392392
}
393+
__attribute__ ((weak)) bool tud_msc_is_writable_cb (uint8_t lun){
394+
return false;
395+
}
396+
393397
#endif
394398

395399
/*

0 commit comments

Comments
 (0)