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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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 */

0 commit comments

Comments
 (0)