18
18
19
19
Adafruit_USBD_MSC usb_msc;
20
20
21
+ // Eject button to demonstrate medium is not ready e.g SDCard is not present
22
+ // whenever this button is pressed and hold, it will report to host as not ready
23
+ #if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY)
24
+ #define BTN_EJECT 4 // Left Button
25
+ bool activeState = true ;
26
+
27
+ #elif defined(ARDUINO_FUNHOUSE_ESP32S2)
28
+ #define BTN_EJECT BUTTON_DOWN
29
+ bool activeState = true ;
30
+
31
+ #elif defined PIN_BUTTON1
32
+ #define BTN_EJECT PIN_BUTTON1
33
+ bool activeState = false ;
34
+ #endif
35
+
36
+
21
37
// the setup function runs once when you press reset or power the board
22
38
void setup ()
23
39
{
@@ -39,6 +55,11 @@ void setup()
39
55
// Set Lun ready (RAM disk is always ready)
40
56
usb_msc.setUnitReady (true );
41
57
58
+ #ifdef BTN_EJECT
59
+ pinMode (BTN_EJECT, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
60
+ usb_msc.setReadyCallback (msc_ready_callback);
61
+ #endif
62
+
42
63
usb_msc.begin ();
43
64
44
65
Serial.begin (115200 );
@@ -49,9 +70,7 @@ void setup()
49
70
50
71
void loop ()
51
72
{
52
- // nothing to do
53
- Serial.println (" Adafruit TinyUSB Mass Storage RAM Disk example" );
54
- delay (1000 );
73
+
55
74
}
56
75
57
76
// Callback invoked when received READ10 command.
@@ -82,3 +101,14 @@ void msc_flush_callback (void)
82
101
{
83
102
// nothing to do
84
103
}
104
+
105
+
106
+ #ifdef BTN_EJECT
107
+ // Invoked when received Test Unit Ready command.
108
+ // return true allowing host to read/write this LUN e.g SD card inserted
109
+ bool msc_ready_callback (void )
110
+ {
111
+ // button not active --> medium ready
112
+ return digitalRead (BTN_EJECT) != activeState;
113
+ }
114
+ #endif
0 commit comments