forked from espressif/arduino-esp32
Add files to cmakelists and disconnect CDC if unplugged
This commit is contained in:
@ -17,6 +17,7 @@ set(CORE_SRCS
|
|||||||
cores/esp32/esp32-hal-timer.c
|
cores/esp32/esp32-hal-timer.c
|
||||||
cores/esp32/esp32-hal-touch.c
|
cores/esp32/esp32-hal-touch.c
|
||||||
cores/esp32/esp32-hal-uart.c
|
cores/esp32/esp32-hal-uart.c
|
||||||
|
cores/esp32/esp32-hal-usb.c
|
||||||
cores/esp32/esp32-hal-rmt.c
|
cores/esp32/esp32-hal-rmt.c
|
||||||
cores/esp32/Esp.cpp
|
cores/esp32/Esp.cpp
|
||||||
cores/esp32/FunctionalInterrupt.cpp
|
cores/esp32/FunctionalInterrupt.cpp
|
||||||
@ -61,6 +62,8 @@ set(LIBRARY_SRCS
|
|||||||
libraries/Ticker/src/Ticker.cpp
|
libraries/Ticker/src/Ticker.cpp
|
||||||
libraries/Update/src/Updater.cpp
|
libraries/Update/src/Updater.cpp
|
||||||
libraries/Update/src/HttpsOTAUpdate.cpp
|
libraries/Update/src/HttpsOTAUpdate.cpp
|
||||||
|
libraries/USB/src/USB.cpp
|
||||||
|
libraries/USB/src/USBCDC.cpp
|
||||||
libraries/WebServer/src/WebServer.cpp
|
libraries/WebServer/src/WebServer.cpp
|
||||||
libraries/WebServer/src/Parsing.cpp
|
libraries/WebServer/src/Parsing.cpp
|
||||||
libraries/WebServer/src/detail/mimetable.cpp
|
libraries/WebServer/src/detail/mimetable.cpp
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include "esp32-hal.h"
|
#include "esp32-hal.h"
|
||||||
#include "esp32-hal-tinyusb.h"
|
#include "esp32-hal-tinyusb.h"
|
||||||
|
#include "USB.h"
|
||||||
#include "USBCDC.h"
|
#include "USBCDC.h"
|
||||||
#if CONFIG_USB_ENABLED
|
#if CONFIG_USB_ENABLED
|
||||||
|
|
||||||
@ -99,11 +100,16 @@ void tud_cdc_rx_cb(uint8_t itf)
|
|||||||
|
|
||||||
//void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
|
//void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
|
||||||
|
|
||||||
|
static void usb_unplugged_cb(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){
|
||||||
|
((USBCDC*)arg)->_onUnplugged();
|
||||||
|
}
|
||||||
|
|
||||||
USBCDC::USBCDC(uint8_t itfn) : itf(itfn), bit_rate(0), stop_bits(0), parity(0), data_bits(0), dtr(false), rts(false), connected(false), reboot_enable(true), rx_queue(NULL) {
|
USBCDC::USBCDC(uint8_t itfn) : itf(itfn), bit_rate(0), stop_bits(0), parity(0), data_bits(0), dtr(false), rts(false), connected(false), reboot_enable(true), rx_queue(NULL) {
|
||||||
tinyusb_enable_interface(USB_INTERFACE_CDC);
|
tinyusb_enable_interface(USB_INTERFACE_CDC);
|
||||||
tinyusb_enable_interface(USB_INTERFACE_DFU);
|
tinyusb_enable_interface(USB_INTERFACE_DFU);
|
||||||
if(itf < MAX_USB_CDC_DEVICES){
|
if(itf < MAX_USB_CDC_DEVICES){
|
||||||
devices[itf] = this;
|
devices[itf] = this;
|
||||||
|
arduino_usb_event_handler_register_with(ARDUINO_USB_EVENTS, ARDUINO_USB_STOPPED_EVENT, usb_unplugged_cb, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +137,16 @@ void USBCDC::end()
|
|||||||
tinyusb_persist_set_mode(REBOOT_NO_PERSIST);
|
tinyusb_persist_set_mode(REBOOT_NO_PERSIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USBCDC::_onUnplugged(void){
|
||||||
|
if(connected){
|
||||||
|
connected = false;
|
||||||
|
dtr = false;
|
||||||
|
rts = false;
|
||||||
|
arduino_usb_cdc_event_data_t p = {0};
|
||||||
|
arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_DISCONNECTED_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void USBCDC::_onDFU(void){
|
void USBCDC::_onDFU(void){
|
||||||
if(reboot_enable){
|
if(reboot_enable){
|
||||||
tinyusb_persist_set_mode(REBOOT_BOOTLOADER_DFU);
|
tinyusb_persist_set_mode(REBOOT_BOOTLOADER_DFU);
|
||||||
|
@ -108,6 +108,7 @@ public:
|
|||||||
void _onLineState(bool _dtr, bool _rts);
|
void _onLineState(bool _dtr, bool _rts);
|
||||||
void _onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _parity, uint8_t _data_bits);
|
void _onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _parity, uint8_t _data_bits);
|
||||||
void _onRX(void);
|
void _onRX(void);
|
||||||
|
void _onUnplugged(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t itf;
|
uint8_t itf;
|
||||||
|
Reference in New Issue
Block a user