2626
2727using namespace arduino ;
2828
29+ static rtos::EventFlags event;
30+
2931static void waitForPortClose () {
32+
33+ event.wait_any (0xFF );
3034 // wait for DTR be 0 (port closed) and timeout to be over
3135 long start = millis ();
3236 static const int WAIT_TIMEOUT = 200 ;
@@ -37,11 +41,9 @@ static void waitForPortClose() {
3741 _ontouch1200bps_ ();
3842}
3943
40- static events::EventQueue queue (2 * EVENTS_EVENT_SIZE);
41-
4244void usbPortChanged (int baud, int bits, int parity, int stop) {
4345 if (baud == 1200 ) {
44- queue. call (waitForPortClose );
46+ event. set ( 1 );
4547 }
4648}
4749
@@ -68,7 +70,9 @@ USBSerial::~USBSerial()
6870void USBSerial::begin (unsigned long ) {
6971 this ->attach (usbPortChanged);
7072 this ->attach (::mbed::callback (this , &USBSerial::onInterrupt));
71- t.start (callback (&queue, &::events::EventQueue::dispatch_forever));
73+ t = new rtos::Thread (osPriorityNormal, 256 , nullptr , " USBevt" );
74+ t->start (waitForPortClose);
75+ onInterrupt ();
7276}
7377
7478int USBSerial::_putc (int c)
@@ -104,13 +108,13 @@ void USBSerial::data_rx()
104108 }
105109}
106110
107- uint8_t USBSerial::_available ()
111+ uint32_t USBSerial::_available ()
108112{
109113 USBCDC::lock ();
110114
111- uint8_t size = 0 ;
115+ uint32_t size = 0 ;
112116 if (!_rx_in_progress) {
113- size = _rx_size > 0xFF ? 0xFF : _rx_size;
117+ size = _rx_size > CDC_MAX_PACKET_SIZE ? CDC_MAX_PACKET_SIZE : _rx_size;
114118 }
115119
116120 USBCDC::unlock ();
0 commit comments