Some CDC and BTSerial compatibility fixes

This commit is contained in:
me-no-dev
2020-07-14 18:21:21 +03:00
parent 8cc9e955dc
commit e687951c0f
6 changed files with 41 additions and 22 deletions

View File

@ -112,17 +112,9 @@ ESPUSB::ESPUSB(size_t task_stack_size, uint8_t event_task_priority)
,webusb_enabled(false)
,webusb_url("espressif.github.io/arduino-esp32/webusb.html")
,_started(false)
,_task_stack_size(task_stack_size)
,_event_task_priority(event_task_priority)
{
esp_event_loop_args_t event_task_args = {
.queue_size = 5,
.task_name = "arduino_usb_events",
.task_priority = event_task_priority,
.task_stack_size = task_stack_size,
.task_core_id = tskNO_AFFINITY
};
if (esp_event_loop_create(&event_task_args, &arduino_usb_event_loop_handle) != ESP_OK) {
log_e("esp_event_loop_create failed");
}
}
ESPUSB::~ESPUSB(){
@ -133,6 +125,18 @@ ESPUSB::~ESPUSB(){
}
bool ESPUSB::begin(){
if (!arduino_usb_event_loop_handle) {
esp_event_loop_args_t event_task_args = {
.queue_size = 5,
.task_name = "arduino_usb_events",
.task_priority = _event_task_priority,
.task_stack_size = _task_stack_size,
.task_core_id = tskNO_AFFINITY
};
if (esp_event_loop_create(&event_task_args, &arduino_usb_event_loop_handle) != ESP_OK) {
log_e("esp_event_loop_create failed");
}
}
if(!_started){
tinyusb_device_config_t tinyusb_device_config = {
.vid = vid,

View File

@ -109,6 +109,8 @@ class ESPUSB {
String webusb_url;
bool _started;
size_t _task_stack_size;
uint8_t _event_task_priority;
};
extern ESPUSB USB;

View File

@ -119,15 +119,20 @@ void USBCDC::onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback
arduino_usb_event_handler_register_with(ARDUINO_USB_CDC_EVENTS, event, callback, this);
}
void USBCDC::begin(size_t rx_queue_len)
{
size_t USBCDC::setRxBufferSize(size_t rx_queue_len){
if(rx_queue){
return;
return 0;
}
rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
if(!rx_queue){
return;
return 0;
}
return rx_queue_len;
}
void USBCDC::begin(unsigned long baud)
{
setRxBufferSize(256);//default if not preset
}
void USBCDC::end()
@ -292,15 +297,13 @@ int USBCDC::availableForWrite(void)
return tud_cdc_n_write_available(itf);
}
size_t USBCDC::write(const uint8_t *buffer, size_t size){
size_t USBCDC::write(const uint8_t *buffer, size_t size)
{
return tinyusb_cdc_write(itf, buffer, size);
}
size_t USBCDC::write(uint8_t c)
{
if(itf >= MAX_USB_CDC_DEVICES){
return 0;
}
return write(&c, 1);
}

View File

@ -56,8 +56,9 @@ public:
void onEvent(esp_event_handler_t callback);
void onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback);
void begin(size_t rx_queue_len=256);
size_t setRxBufferSize(size_t);
void begin(unsigned long baud=0);
void end();
int available(void);