Skip to content

Commit

Permalink
Update to arduino-esp32 master branch,
Browse files Browse the repository at this point in the history
added guards to prevent failures in case arduino library sdkconfig is broken
  • Loading branch information
chegewara committed Jun 27, 2021
1 parent 365a36e commit 7eba91d
Show file tree
Hide file tree
Showing 46 changed files with 188 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"mscusb.h": "c"
}
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ device.deviceID(uint16_t* VID, uint16_t* PID);

# Contributions
Issues and PRs are welcome.

## Known issue
Currently library is not working with vanila arduino-esp32. It is due some tinyusb callbacks cant be overriden and are used by arduino-esp32. To make it works it is required to add `__attribute__ ((weak)) ` in 3 lines in local arduino file:
https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-tinyusb.c#L266
https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-tinyusb.c#L275
https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-tinyusb.c#L284

There is also issue with MIDI example/class. Its because it is not enabled in arduino-esp32 master branch.

4 changes: 1 addition & 3 deletions examples/all_in_one/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
*
*/

// #include "bsp/board.h"
#include "tusb.h"

#include "mscusb.h"
#if CFG_TUD_MSC

// Some MCU doesn't have enough 8KB SRAM to store the whole disk
Expand Down
5 changes: 3 additions & 2 deletions examples/cdc/cdc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* Serial - used only for logging
* Serial1 - can be used to control GPS or any other device, may be replaced with Serial
*/
#include "Arduino.h"
#include "cdcusb.h"

#if CFG_TUD_CDC
CDCusb USBSerial;

class MyUSBCallbacks : public CDCCallbacks {
Expand Down Expand Up @@ -61,3 +60,5 @@ void loop()
int a = USBSerial.write((uint8_t*)buf1, len);
}
}

#endif
3 changes: 2 additions & 1 deletion examples/dfu/dfu.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* also CDC class is active, but does nothing
* author: chegewara
*/
#include "Arduino.h"
#include "cdcusb.h"
#include "dfuusb.h"
#if CFG_TUD_DFU_RUNTIME

// CDCusb USBSerial;
DFUusb dev;
Expand All @@ -30,3 +30,4 @@ void loop() {

}

#endif
5 changes: 4 additions & 1 deletion examples/hid/composite/composite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Simple HID mouse and keyboard composite
* author: chegewara
*/
#include "Arduino.h"
#if CFG_TUD_HID

#include "hidcomposite.h"

HIDcomposite device;
Expand Down Expand Up @@ -36,3 +37,5 @@ void loop()
delay(1000);
Serial.println(device.sendString(String("abcdefghijklmnopqrst Uvwxyz\n"))?"OK":"FAIL");
}

#endif
4 changes: 4 additions & 0 deletions examples/hid/gamepad/gamepad.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Simple HID gamepad
* author: chegewara
*/
#if CFG_TUD_HID

#include "hidgamepad.h"

HIDgamepad gamepad;
Expand Down Expand Up @@ -29,3 +31,5 @@ void loop()
gamepad.sendAll(0xffff, 0, 0, 0, 0);
delay(1000);
}

#endif
5 changes: 4 additions & 1 deletion examples/hid/generic/generic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Simple vendor In/Out HID device
* author: chegewara
*/
#include "Arduino.h"
#if CFG_TUD_HID

#include "hidgeneric.h"

HIDgeneric dev;
Expand Down Expand Up @@ -30,3 +31,5 @@ void loop()
delay(1000);
dev.write("test", 4);
}

#endif
3 changes: 3 additions & 0 deletions examples/hid/keyboard/keyboard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Simple HID keyboard
* author: chegewara
*/
#if CFG_TUD_HID

#include "hidkeyboard.h"
#include "Wire.h"
Expand All @@ -28,3 +29,5 @@ void loop()
}
}
}

#endif
5 changes: 4 additions & 1 deletion examples/hid/keyboard2/keyboard2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Simple HID keyboard
* author: chegewara
*/
#include "Arduino.h"
#if CFG_TUD_HID

#include "hidkeyboard.h"

HIDkeyboard dev;
Expand Down Expand Up @@ -43,3 +44,5 @@ void loop()
delay(1000);
Serial.println(dev.sendString(String("abcdefghijklmnopqrst Uvwxyz\n"))?"OK":"FAIL");
}

#endif
5 changes: 4 additions & 1 deletion examples/hid/mouse/mouse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Simple HID mouse
* author: chegewara
*/
#include "Arduino.h"
#if CFG_TUD_HID

#include "hidmouse.h"

HIDmouse mouse;
Expand All @@ -29,3 +30,5 @@ void loop()
mouse.scrollDown(1);
delay(1000);
}

#endif
4 changes: 3 additions & 1 deletion examples/midi/midi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Simple example MIDI class
* author: chegewara
*/
#include "Arduino.h"
#include "midiusb.h"
#include "song.h"
// #ifdef CFG_TUD_MIDI

MIDIusb midi;

Expand Down Expand Up @@ -62,3 +62,5 @@ void loop() {
// midi_task();
// midi.playSong();
}

// #endif
4 changes: 3 additions & 1 deletion examples/msc/ramdisk/ramdisk.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Simple MSC device, use as ram disk
* author: chegewara
*/
#include "Arduino.h"
#include "ramdisk.h"
//#define AUTO_ALLOCATE_DISK
#define BLOCK_COUNT 2 * 100
#define BLOCK_SIZE 512
#if CFG_TUD_MSC

USBramdisk dev;

Expand All @@ -30,3 +30,5 @@ void loop()
{
delay(1000);
}

#endif
4 changes: 3 additions & 1 deletion examples/msc/sd_msc/sd_msc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Simple MSC device with SD card
* author: chegewara
*/
#include "Arduino.h"
#include "sdusb.h"
#if CFG_TUD_MSC

#define SD_MISO 37
#define SD_MOSI 39
Expand All @@ -30,3 +30,5 @@ void loop()
{
delay(1000);
}

#endif
3 changes: 2 additions & 1 deletion examples/webusb/webusb.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* VID = 0xcafe to match filter on website
* author: chegewara
*/
#include "Arduino.h"
#include "webusb.h"
#if CFG_TUD_VENDOR
WebUSB USBSerial;

class MyWebUSBCallbacks : public WebUSBCallbacks{
Expand Down Expand Up @@ -42,3 +42,4 @@ void loop() {
}
}

#endif
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name=ESP32TinyUSB
version=1.2.0
version=1.3.0
author=Dariusz Krempa <[email protected]>
maintainer=Dariusz Krempa <[email protected]>
sentence=USB functions for ESP32-S2
paragraph=This library provides an implementation of tinyusb for the ESP32-S2 for Arduino.
category=Communication
architectures=esp32
includes=cdcusb.h dfuusb.h hidusb.h midiusb.h mscusb.h webusb.h ramdisk.h sdusb.h hidmouse.h hidkeyboard.h hidgeneric.h hidcomposite.h hidgamepad.h
includes=
depends=
url=https://github.com/chegewara/EspTinyUSB
6 changes: 5 additions & 1 deletion src/cdcusb.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "esptinyusb.h"
#if CFG_TUD_CDC

#pragma once
#include "class/cdc/cdc.h"

class CDCCallbacks : public USBCallbacks {
public:
Expand Down Expand Up @@ -43,3 +45,5 @@ class CDCusb : public EspTinyUSB
cdc_line_coding_t coding;

};

#endif
6 changes: 5 additions & 1 deletion src/classes/cdc/cdcusb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "esptinyusb.h"
#include "cdcusb.h"

#if CFG_TUD_CDC

#define EPNUM_CDC 0x02

static CDCusb* _CDCusb[2] = {};
Expand Down Expand Up @@ -43,7 +45,7 @@ int CDCusb::peek()
if (tud_cdc_n_connected(_itf))
{
uint8_t buffer;
tud_cdc_n_peek(_itf, 0, &buffer);
tud_cdc_n_peek(_itf, &buffer);
return buffer;
}
else
Expand Down Expand Up @@ -213,3 +215,5 @@ void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding)
if(_CDCusb[itf]->m_callbacks)
_CDCusb[itf]->m_callbacks->onCodingChange(p_line_coding);
}

#endif
4 changes: 3 additions & 1 deletion src/classes/dfu/dfuusb.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Arduino.h"
#include "tusb.h"
#include "soc/rtc_cntl_reg.h"

#include "dfuusb.h"
#if CFG_TUD_DFU_RUNTIME

DFUusb* _DFU = NULL;

Expand Down Expand Up @@ -30,3 +30,5 @@ void tud_dfu_rt_reboot_to_dfu(void)
{
_DFU->persistentReset(RESTART_BOOTLOADER_DFU);
}

#endif
10 changes: 5 additions & 5 deletions src/classes/hid/hidcomposite.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "Arduino.h"
#include "tusb.h"

#include "hidcomposite.h"
#define EPNUM_HID 0x03
#if CFG_TUD_HID

HIDcomposite::HIDcomposite(uint8_t id)
{
Expand All @@ -19,7 +17,7 @@ bool HIDcomposite::begin(char *str)
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID((uint8_t)(report_keyboard)))
};
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
uint8_t hid[] = {TUD_HID_DESCRIPTOR(ifIdx++, 6, HID_PROTOCOL_NONE, sizeof(desc_hid_report), (uint8_t)(_EPNUM_HID | 0x80), CFG_TUD_HID_BUFSIZE, 1)};
uint8_t hid[] = {TUD_HID_DESCRIPTOR(ifIdx++, 6, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), (uint8_t)(_EPNUM_HID | 0x80), CFG_TUD_HID_BUFSIZE, 1)};
memcpy(&desc_configuration[total], hid, sizeof(hid));
total += sizeof(hid);
count++;
Expand Down Expand Up @@ -162,4 +160,6 @@ bool HIDcomposite::sendString(String text)
{
return sendString(text.c_str());
}
/*------------- Keyboard -------------*/
/*------------- Keyboard -------------*/

#endif
6 changes: 3 additions & 3 deletions src/classes/hid/hidgamepad.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "tusb.h"

#include "hidgamepad.h"
#define EPNUM_HID 0x03
#if CFG_TUD_HID

HIDgamepad::HIDgamepad(uint8_t id)
{
Expand All @@ -14,7 +13,7 @@ bool HIDgamepad::begin(char* str)
{
uint8_t const desc_hid_report[] = {TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(report_id))};
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
uint8_t hid[] = {TUD_HID_DESCRIPTOR(ifIdx++, 6, HID_PROTOCOL_NONE, sizeof(desc_hid_report), (uint8_t)(_EPNUM_HID | 0x80), CFG_TUD_HID_BUFSIZE, 10)};
uint8_t hid[] = {TUD_HID_DESCRIPTOR(ifIdx++, 6, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), (uint8_t)(_EPNUM_HID | 0x80), CFG_TUD_HID_BUFSIZE, 10)};
memcpy(&desc_configuration[total], hid, sizeof(hid));
total += sizeof(hid);
count++;
Expand Down Expand Up @@ -64,3 +63,4 @@ void HIDgamepad::sendAll(uint16_t bt, int8_t x, int8_t y, int8_t z, int8_t rz)
sendReport();
}

#endif
9 changes: 4 additions & 5 deletions src/classes/hid/hidgeneric.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "Arduino.h"
#include "tusb.h"
#include "soc/rtc_cntl_reg.h"

#include "hidgeneric.h"
#define EPNUM_HID 0x03
#define REPORT_ID 1
#if CFG_TUD_HID

HIDgeneric::HIDgeneric(uint8_t reportid)
{
Expand All @@ -17,7 +14,7 @@ bool HIDgeneric::begin(char* str)
{
uint8_t const desc_hid_report[] = {TUD_HID_REPORT_DESC_GENERIC_INOUT(CFG_TUD_HID_BUFSIZE, HID_REPORT_ID(report_id))};
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
uint8_t hid[] = {TUD_HID_INOUT_DESCRIPTOR(ifIdx++, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), _EPNUM_HID, (uint8_t)(0x80 | _EPNUM_HID), CFG_TUD_HID_BUFSIZE, 10)};
uint8_t hid[] = {TUD_HID_INOUT_DESCRIPTOR(ifIdx++, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), _EPNUM_HID, (uint8_t)(0x80 | _EPNUM_HID), CFG_TUD_HID_BUFSIZE, 10)};
memcpy(&desc_configuration[total], hid, sizeof(hid));
total += sizeof(hid);
count++;
Expand All @@ -29,3 +26,5 @@ bool HIDgeneric::begin(char* str)
report_id = REPORT_ID;
return EspTinyUSB::begin(str, 6);
}

#endif
8 changes: 4 additions & 4 deletions src/classes/hid/hidkeyboard.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "Arduino.h"
#include "tusb.h"

#include "hidkeyboard.h"
#define EPNUM_HID 0x02
#if CFG_TUD_HID

HIDkeyboard::HIDkeyboard(uint8_t reportid)
{
Expand All @@ -15,7 +13,7 @@ bool HIDkeyboard::begin(char *str)
{
uint8_t const desc_hid_report[] = {TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(report_id))};
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
uint8_t hid[] = {TUD_HID_DESCRIPTOR(ifIdx++, 6, HID_PROTOCOL_KEYBOARD, sizeof(desc_hid_report), (uint8_t)(_EPNUM_HID | 0x80), CFG_TUD_HID_BUFSIZE, 1)};
uint8_t hid[] = {TUD_HID_DESCRIPTOR(ifIdx++, 6, HID_ITF_PROTOCOL_KEYBOARD, sizeof(desc_hid_report), (uint8_t)(_EPNUM_HID | 0x80), CFG_TUD_HID_BUFSIZE, 1)};
memcpy(&desc_configuration[total], hid, sizeof(hid));
total += sizeof(hid);
count++;
Expand Down Expand Up @@ -76,3 +74,5 @@ bool HIDkeyboard::sendString(String text)
{
return sendString(text.c_str());
}

#endif
Loading

0 comments on commit 7eba91d

Please sign in to comment.