forked from espressif/arduino-esp32
Some CDC and BTSerial compatibility fixes
This commit is contained in:
@ -477,7 +477,7 @@ static bool _init_bt(const char *deviceName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!_spp_task_handle){
|
if(!_spp_task_handle){
|
||||||
xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, 2, &_spp_task_handle, 0);
|
xTaskCreatePinnedToCore(_spp_tx_task, "spp_tx", 4096, NULL, 10, &_spp_task_handle, 0);
|
||||||
if(!_spp_task_handle){
|
if(!_spp_task_handle){
|
||||||
log_e("Network Event Task Start Failed!");
|
log_e("Network Event Task Start Failed!");
|
||||||
return false;
|
return false;
|
||||||
@ -815,4 +815,9 @@ bool BluetoothSerial::isReady(bool checkMaster, int timeout) {
|
|||||||
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
|
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
|
||||||
return (xEventGroupWaitBits(_spp_event_group, SPP_RUNNING, pdFALSE, pdTRUE, xTicksToWait) & SPP_RUNNING) != 0;
|
return (xEventGroupWaitBits(_spp_event_group, SPP_RUNNING, pdFALSE, pdTRUE, xTicksToWait) & SPP_RUNNING) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BluetoothSerial::operator bool() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -34,6 +34,9 @@ class BluetoothSerial: public Stream
|
|||||||
~BluetoothSerial(void);
|
~BluetoothSerial(void);
|
||||||
|
|
||||||
bool begin(String localName=String(), bool isMaster=false);
|
bool begin(String localName=String(), bool isMaster=false);
|
||||||
|
bool begin(unsigned long baud){//compatibility
|
||||||
|
return begin();
|
||||||
|
}
|
||||||
int available(void);
|
int available(void);
|
||||||
int peek(void);
|
int peek(void);
|
||||||
bool hasClient(void);
|
bool hasClient(void);
|
||||||
@ -55,6 +58,7 @@ class BluetoothSerial: public Stream
|
|||||||
bool disconnect();
|
bool disconnect();
|
||||||
bool unpairDevice(uint8_t remoteAddress[]);
|
bool unpairDevice(uint8_t remoteAddress[]);
|
||||||
|
|
||||||
|
operator bool() const;
|
||||||
private:
|
private:
|
||||||
String local_name;
|
String local_name;
|
||||||
|
|
||||||
|
@ -112,17 +112,9 @@ ESPUSB::ESPUSB(size_t task_stack_size, uint8_t event_task_priority)
|
|||||||
,webusb_enabled(false)
|
,webusb_enabled(false)
|
||||||
,webusb_url("espressif.github.io/arduino-esp32/webusb.html")
|
,webusb_url("espressif.github.io/arduino-esp32/webusb.html")
|
||||||
,_started(false)
|
,_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(){
|
ESPUSB::~ESPUSB(){
|
||||||
@ -133,6 +125,18 @@ ESPUSB::~ESPUSB(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ESPUSB::begin(){
|
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){
|
if(!_started){
|
||||||
tinyusb_device_config_t tinyusb_device_config = {
|
tinyusb_device_config_t tinyusb_device_config = {
|
||||||
.vid = vid,
|
.vid = vid,
|
||||||
|
@ -109,6 +109,8 @@ class ESPUSB {
|
|||||||
String webusb_url;
|
String webusb_url;
|
||||||
|
|
||||||
bool _started;
|
bool _started;
|
||||||
|
size_t _task_stack_size;
|
||||||
|
uint8_t _event_task_priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ESPUSB USB;
|
extern ESPUSB USB;
|
||||||
|
@ -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);
|
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){
|
if(rx_queue){
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
|
rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
|
||||||
if(!rx_queue){
|
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()
|
void USBCDC::end()
|
||||||
@ -292,15 +297,13 @@ int USBCDC::availableForWrite(void)
|
|||||||
return tud_cdc_n_write_available(itf);
|
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);
|
return tinyusb_cdc_write(itf, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t USBCDC::write(uint8_t c)
|
size_t USBCDC::write(uint8_t c)
|
||||||
{
|
{
|
||||||
if(itf >= MAX_USB_CDC_DEVICES){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return write(&c, 1);
|
return write(&c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,8 @@ public:
|
|||||||
void onEvent(esp_event_handler_t callback);
|
void onEvent(esp_event_handler_t callback);
|
||||||
void onEvent(arduino_usb_cdc_event_t event, 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();
|
void end();
|
||||||
|
|
||||||
int available(void);
|
int available(void);
|
||||||
|
Reference in New Issue
Block a user