Skip to content

Commit fef7fb3

Browse files
committed
Add guard to USB examples
1 parent 521b2bd commit fef7fb3

File tree

19 files changed

+103
-3
lines changed

19 files changed

+103
-3
lines changed

.github/scripts/install-platformio-esp32.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ replace_script+="data['packages']['toolchain-xtensa-esp32']['version']='$TOOLCHA
3232
replace_script+="data['packages']['toolchain-xtensa-esp32s2']['version']='$TOOLCHAIN_VERSION';"
3333
replace_script+="data['packages']['toolchain-riscv32-esp']['version']='$TOOLCHAIN_VERSION';"
3434
# Add ESP32-S3 Toolchain
35-
replace_script+="data['packages'].append({'toolchain-xtensa-esp32s3':{'type':'toolchain','optional':true,'owner':'$ESPRESSIF_ORGANIZATION_NAME','version':'$TOOLCHAIN_VERSION'}});"
35+
replace_script+="data['packages'].update({'toolchain-xtensa-esp32s3':{'type':'toolchain','optional':true,'owner':'$ESPRESSIF_ORGANIZATION_NAME','version':'$TOOLCHAIN_VERSION'}});"
3636
# esptool.py may require an upstream version (for now platformio is the owner)
3737
replace_script+="data['packages']['tool-esptoolpy']['version']='$ESPTOOLPY_VERSION';"
3838
# Save results

cores/esp32/HWCDC.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,12 @@ void HWCDC::setDebugOutput(bool en)
381381
}
382382
}
383383

384-
#if ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE //Serial used for USB CDC
384+
#if ARDUINO_USB_MODE
385+
#if ARDUINO_USB_CDC_ON_BOOT//Serial used for USB CDC
385386
HWCDC Serial;
386387
#else
387388
HWCDC USBSerial;
388389
#endif
390+
#endif
389391

390392
#endif /* CONFIG_TINYUSB_CDC_ENABLED */

cores/esp32/HWCDC.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ class HWCDC: public Stream
9898

9999
};
100100

101-
#if ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE//Serial used for USB CDC
101+
#if ARDUINO_USB_MODE
102+
#if ARDUINO_USB_CDC_ON_BOOT//Serial used for USB CDC
102103
extern HWCDC Serial;
103104
#else
104105
extern HWCDC USBSerial;
105106
#endif
107+
#endif
106108

107109
#endif /* CONFIG_IDF_TARGET_ESP32C3 */

libraries/USB/examples/CompositeDevice/CompositeDevice.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBHIDMouse.h"
38
#include "USBHIDKeyboard.h"
@@ -211,3 +216,4 @@ void loop() {
211216
}
212217
}
213218
}
219+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/ConsumerControl/ConsumerControl.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBHIDConsumerControl.h"
38
USBHIDConsumerControl ConsumerControl;
@@ -19,3 +24,4 @@ void loop() {
1924
}
2025
previousButtonState = buttonState;
2126
}
27+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/CustomHIDDevice/CustomHIDDevice.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBHID.h"
38
USBHID HID;
@@ -50,6 +55,7 @@ public:
5055
};
5156

5257
CustomHIDDevice Device;
58+
#endif /* ARDUINO_USB_MODE */
5359

5460
const int buttonPin = 0;
5561
int previousButtonState = HIGH;

libraries/USB/examples/FirmwareMSC/FirmwareMSC.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "FirmwareMSC.h"
38

@@ -72,3 +77,4 @@ void setup() {
7277
void loop() {
7378
// put your main code here, to run repeatedly
7479
}
80+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/Gamepad/Gamepad.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBHIDGamepad.h"
38
USBHIDGamepad Gamepad;
@@ -19,3 +24,4 @@ void loop() {
1924
}
2025
previousButtonState = buttonState;
2126
}
27+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/HIDVendor/HIDVendor.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBHIDVendor.h"
38
USBHIDVendor Vendor;
@@ -50,3 +55,4 @@ void loop() {
5055
Serial.write(Vendor.read());
5156
}
5257
}
58+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/Keyboard/KeyboardLogout/KeyboardLogout.ino

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
2525
http://www.arduino.cc/en/Tutorial/KeyboardLogout
2626
*/
27+
#if ARDUINO_USB_MODE
28+
#warning This sketch should be used when USB is in OTG mode
29+
void setup(){}
30+
void loop(){}
31+
#else
2732

2833
#define OSX 0
2934
#define WINDOWS 1
@@ -90,3 +95,4 @@ void loop() {
9095
// do nothing:
9196
while (true) delay(1000);
9297
}
98+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/Keyboard/KeyboardMessage/KeyboardMessage.ino

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
2020
http://www.arduino.cc/en/Tutorial/KeyboardMessage
2121
*/
22+
#if ARDUINO_USB_MODE
23+
#warning This sketch should be used when USB is in OTG mode
24+
void setup(){}
25+
void loop(){}
26+
#else
2227

2328
#include "USB.h"
2429
#include "USBHIDKeyboard.h"
@@ -53,3 +58,4 @@ void loop() {
5358
// save the current button state for comparison next time:
5459
previousButtonState = buttonState;
5560
}
61+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/Keyboard/KeyboardReprogram/KeyboardReprogram.ino

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
2525
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
2626
*/
27+
#if ARDUINO_USB_MODE
28+
#warning This sketch should be used when USB is in OTG mode
29+
void setup(){}
30+
void loop(){}
31+
#else
2732

2833
#include "USB.h"
2934
#include "USBHIDKeyboard.h"
@@ -104,3 +109,4 @@ void loop() {
104109
// wait for the sweet oblivion of reprogramming:
105110
while (true)delay(1000);
106111
}
112+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/Keyboard/KeyboardSerial/KeyboardSerial.ino

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
1717
http://www.arduino.cc/en/Tutorial/KeyboardSerial
1818
*/
19+
#if ARDUINO_USB_MODE
20+
#warning This sketch should be used when USB is in OTG mode
21+
void setup(){}
22+
void loop(){}
23+
#else
1924

2025
#include "USB.h"
2126
#include "USBHIDKeyboard.h"
@@ -38,3 +43,4 @@ void loop() {
3843
Keyboard.write(inChar + 1);
3944
}
4045
}
46+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/KeyboardAndMouseControl/KeyboardAndMouseControl.ino

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
1919
http://www.arduino.cc/en/Tutorial/KeyboardAndMouseControl
2020
*/
21+
#if ARDUINO_USB_MODE
22+
#warning This sketch should be used when USB is in OTG mode
23+
void setup(){}
24+
void loop(){}
25+
#else
2126

2227
#include "USB.h"
2328
#include "USBHIDMouse.h"
@@ -93,3 +98,4 @@ void loop() {
9398
}
9499
delay(5);
95100
}
101+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/Mouse/ButtonMouseControl/ButtonMouseControl.ino

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
2121
http://www.arduino.cc/en/Tutorial/ButtonMouseControl
2222
*/
23+
#if ARDUINO_USB_MODE
24+
#warning This sketch should be used when USB is in OTG mode
25+
void setup(){}
26+
void loop(){}
27+
#else
2328

2429
#include "USB.h"
2530
#include "USBHIDMouse.h"
@@ -84,3 +89,4 @@ void loop() {
8489
// a delay so the mouse doesn't move too fast:
8590
delay(responseDelay);
8691
}
92+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/SystemControl/SystemControl.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBHIDSystemControl.h"
38
USBHIDSystemControl SystemControl;
@@ -19,3 +24,4 @@ void loop() {
1924
}
2025
previousButtonState = buttonState;
2126
}
27+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/USBMSC/USBMSC.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBMSC.h"
38

@@ -190,3 +195,4 @@ void setup() {
190195
void loop() {
191196
// put your main code here, to run repeatedly:
192197
}
198+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/USBSerial/USBSerial.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27

38
#if ARDUINO_USB_CDC_ON_BOOT
@@ -78,3 +83,4 @@ void loop() {
7883
USBSerial.write(b, l);
7984
}
8085
}
86+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/USBVendor/USBVendor.ino

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#if ARDUINO_USB_MODE
2+
#warning This sketch should be used when USB is in OTG mode
3+
void setup(){}
4+
void loop(){}
5+
#else
16
#include "USB.h"
27
#include "USBVendor.h"
38

@@ -189,3 +194,4 @@ void loop() {
189194
Vendor.write(b, l);
190195
}
191196
}
197+
#endif /* ARDUINO_USB_MODE */

0 commit comments

Comments
 (0)