Skip to content

Commit 2fdd5c5

Browse files
authored
Merge pull request #282 from adafruit/develop
Enhance Serial.available() and bool()
2 parents a964803 + d87536b commit 2fdd5c5

File tree

29 files changed

+131
-197
lines changed

29 files changed

+131
-197
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,24 @@ void Adafruit_USBD_CDC::end(void)
6464

6565
Adafruit_USBD_CDC::operator bool()
6666
{
67-
return tud_cdc_connected();
67+
bool ret = tud_cdc_connected();
68+
69+
// Add an yield to run usb background in case sketch block wait as follows
70+
// while( !Serial ) {}
71+
if ( !ret ) yield();
72+
73+
return ret;
6874
}
6975

7076
int Adafruit_USBD_CDC::available(void)
7177
{
72-
return tud_cdc_available();
78+
uint32_t count = tud_cdc_available();
79+
80+
// Add an yield to run usb background in case sketch block wait as follows
81+
// while( !Serial.available() ) {}
82+
if (!count) yield();
83+
84+
return count;
7385
}
7486

7587
int Adafruit_USBD_CDC::peek(void)

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ typedef enum
212212
// FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE)
213213
//--------------------------------------------------------------------+
214214
/// Header Functional Descriptor (Communication Interface)
215-
typedef struct ATTR_PACKED
215+
typedef struct TU_ATTR_PACKED
216216
{
217217
uint8_t bLength ; ///< Size of this descriptor in bytes.
218218
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -221,7 +221,7 @@ typedef struct ATTR_PACKED
221221
}cdc_desc_func_header_t;
222222

223223
/// Union Functional Descriptor (Communication Interface)
224-
typedef struct ATTR_PACKED
224+
typedef struct TU_ATTR_PACKED
225225
{
226226
uint8_t bLength ; ///< Size of this descriptor in bytes.
227227
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -231,7 +231,7 @@ typedef struct ATTR_PACKED
231231
}cdc_desc_func_union_t;
232232

233233
#define cdc_desc_func_union_n_t(no_slave)\
234-
struct ATTR_PACKED { \
234+
struct TU_ATTR_PACKED { \
235235
uint8_t bLength ;\
236236
uint8_t bDescriptorType ;\
237237
uint8_t bDescriptorSubType ;\
@@ -240,7 +240,7 @@ typedef struct ATTR_PACKED
240240
}
241241

242242
/// Country Selection Functional Descriptor (Communication Interface)
243-
typedef struct ATTR_PACKED
243+
typedef struct TU_ATTR_PACKED
244244
{
245245
uint8_t bLength ; ///< Size of this descriptor in bytes.
246246
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -250,7 +250,7 @@ typedef struct ATTR_PACKED
250250
}cdc_desc_func_country_selection_t;
251251

252252
#define cdc_desc_func_country_selection_n_t(no_country) \
253-
struct ATTR_PACKED {\
253+
struct TU_ATTR_PACKED {\
254254
uint8_t bLength ;\
255255
uint8_t bDescriptorType ;\
256256
uint8_t bDescriptorSubType ;\
@@ -264,7 +264,7 @@ typedef struct ATTR_PACKED
264264

265265
/// \brief Call Management Functional Descriptor
266266
/// \details This functional descriptor describes the processing of calls for the Communications Class interface.
267-
typedef struct ATTR_PACKED
267+
typedef struct TU_ATTR_PACKED
268268
{
269269
uint8_t bLength ; ///< Size of this descriptor in bytes.
270270
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -280,7 +280,7 @@ typedef struct ATTR_PACKED
280280
}cdc_desc_func_call_management_t;
281281

282282

283-
typedef struct ATTR_PACKED
283+
typedef struct TU_ATTR_PACKED
284284
{
285285
uint8_t support_comm_request : 1; ///< Device supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and Get_Comm_Feature.
286286
uint8_t support_line_request : 1; ///< Device supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.
@@ -293,7 +293,7 @@ TU_VERIFY_STATIC(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compile
293293

294294
/// \brief Abstract Control Management Functional Descriptor
295295
/// \details This functional descriptor describes the commands supported by by the Communications Class interface with SubClass code of \ref CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL
296-
typedef struct ATTR_PACKED
296+
typedef struct TU_ATTR_PACKED
297297
{
298298
uint8_t bLength ; ///< Size of this descriptor in bytes.
299299
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -303,7 +303,7 @@ typedef struct ATTR_PACKED
303303

304304
/// \brief Direct Line Management Functional Descriptor
305305
/// \details This functional descriptor describes the commands supported by the Communications Class interface with SubClass code of \ref CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT
306-
typedef struct ATTR_PACKED
306+
typedef struct TU_ATTR_PACKED
307307
{
308308
uint8_t bLength ; ///< Size of this descriptor in bytes.
309309
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -319,7 +319,7 @@ typedef struct ATTR_PACKED
319319
/// \brief Telephone Ringer Functional Descriptor
320320
/// \details The Telephone Ringer functional descriptor describes the ringer capabilities supported by the Communications Class interface,
321321
/// with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
322-
typedef struct ATTR_PACKED
322+
typedef struct TU_ATTR_PACKED
323323
{
324324
uint8_t bLength ; ///< Size of this descriptor in bytes.
325325
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -331,7 +331,7 @@ typedef struct ATTR_PACKED
331331
/// \brief Telephone Operational Modes Functional Descriptor
332332
/// \details The Telephone Operational Modes functional descriptor describes the operational modes supported by
333333
/// the Communications Class interface, with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
334-
typedef struct ATTR_PACKED
334+
typedef struct TU_ATTR_PACKED
335335
{
336336
uint8_t bLength ; ///< Size of this descriptor in bytes.
337337
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -347,7 +347,7 @@ typedef struct ATTR_PACKED
347347
/// \brief Telephone Call and Line State Reporting Capabilities Descriptor
348348
/// \details The Telephone Call and Line State Reporting Capabilities functional descriptor describes the abilities of a
349349
/// telephone device to report optional call and line states.
350-
typedef struct ATTR_PACKED
350+
typedef struct TU_ATTR_PACKED
351351
{
352352
uint8_t bLength ; ///< Size of this descriptor in bytes.
353353
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -371,7 +371,7 @@ static inline uint8_t cdc_functional_desc_typeof(uint8_t const * p_desc)
371371
//--------------------------------------------------------------------+
372372
// Requests
373373
//--------------------------------------------------------------------+
374-
typedef struct ATTR_PACKED
374+
typedef struct TU_ATTR_PACKED
375375
{
376376
uint32_t bit_rate;
377377
uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits
@@ -381,7 +381,7 @@ typedef struct ATTR_PACKED
381381

382382
TU_VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct");
383383

384-
typedef struct ATTR_PACKED
384+
typedef struct TU_ATTR_PACKED
385385
{
386386
uint16_t dte_is_present : 1; ///< Indicates to DCE if DTE is presentor not. This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR.
387387
uint16_t half_duplex_carrier_control : 1;

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ static inline bool tud_cdc_write_flush (void)
9191
//--------------------------------------------------------------------+
9292

9393
// Invoked when received new data
94-
ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
94+
TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
9595

9696
// Invoked when received `wanted_char`
97-
ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
97+
TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
9898

9999
// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
100-
ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
100+
TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
101101

102102
// Invoked when line coding is change via SET_LINE_CODING
103-
ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
103+
TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
104104

105105
/** @} */
106106
/** @} */

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* @{ */
4545

4646
/// USB HID Descriptor
47-
typedef struct ATTR_PACKED
47+
typedef struct TU_ATTR_PACKED
4848
{
4949
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
5050
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
@@ -150,7 +150,7 @@ typedef enum
150150
* @{ */
151151

152152
/// Standard HID Boot Protocol Mouse Report.
153-
typedef struct ATTR_PACKED
153+
typedef struct TU_ATTR_PACKED
154154
{
155155
uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */
156156
int8_t x; /**< Current delta x movement of the mouse. */
@@ -178,7 +178,7 @@ typedef enum
178178
* @{ */
179179

180180
/// Standard HID Boot Protocol Keyboard Report.
181-
typedef struct ATTR_PACKED
181+
typedef struct TU_ATTR_PACKED
182182
{
183183
uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFER_* masks). */
184184
uint8_t reserved; /**< Reserved for OEM use, always set to 0. */

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid_device.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,24 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y
7070

7171
// Invoked when received GET HID REPORT DESCRIPTOR request
7272
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
73-
ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(void);
73+
TU_ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(void);
7474

7575
// Invoked when received GET_REPORT control request
7676
// Application must fill buffer report's content and return its length.
7777
// Return zero will cause the stack to STALL request
78-
ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
78+
TU_ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
7979

8080
// Invoked when received SET_REPORT control request or
8181
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
82-
ATTR_WEAK void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
82+
TU_ATTR_WEAK void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
8383

8484
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
85-
ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
85+
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
8686

8787
// Invoked when received SET_IDLE request. return false will stall the request
8888
// - Idle Rate = 0 : only send report if there is changes, i.e skip duplication
8989
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
90-
ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
90+
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
9191

9292
/* --------------------------------------------------------------------+
9393
* HID Report Descriptor Template

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// FUNCTIONAL DESCRIPTOR (COMMUNICATION INTERFACE)
4343
//--------------------------------------------------------------------+
4444
/// Header Functional Descriptor (Communication Interface)
45-
typedef struct ATTR_PACKED
45+
typedef struct TU_ATTR_PACKED
4646
{
4747
uint8_t bLength ; ///< Size of this descriptor in bytes.
4848
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
@@ -52,7 +52,7 @@ typedef struct ATTR_PACKED
5252
}midi_desc_func_header_t;
5353

5454
/// Union Functional Descriptor (Communication Interface)
55-
typedef struct ATTR_PACKED
55+
typedef struct TU_ATTR_PACKED
5656
{
5757
uint8_t bLength ; ///< Size of this descriptor in bytes.
5858
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/midi/midi_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static inline bool tud_midi_write_flush (void)
8282
//--------------------------------------------------------------------+
8383
// APPLICATION CALLBACK API (WEAK is optional)
8484
//--------------------------------------------------------------------+
85-
ATTR_WEAK void tud_midi_rx_cb(uint8_t itf);
85+
TU_ATTR_WEAK void tud_midi_rx_cb(uint8_t itf);
8686

8787
//--------------------------------------------------------------------+
8888
// Internal Class Driver API

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef enum
8686
}msc_csw_status_t;
8787

8888
/// Command Block Wrapper
89-
typedef struct ATTR_PACKED
89+
typedef struct TU_ATTR_PACKED
9090
{
9191
uint32_t signature; ///< Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
9292
uint32_t tag; ///< Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTagfield of the associated CSW. The dCSWTagpositively associates a CSW with the corresponding CBW.
@@ -100,7 +100,7 @@ typedef struct ATTR_PACKED
100100
TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct");
101101

102102
/// Command Status Wrapper
103-
typedef struct ATTR_PACKED
103+
typedef struct TU_ATTR_PACKED
104104
{
105105
uint32_t signature ; ///< Signature that helps identify this data packet as a CSW. The signature field shall contain the value 53425355h (little endian), indicating CSW.
106106
uint32_t tag ; ///< The device shall set this field to the value received in the dCBWTag of the associated CBW.
@@ -153,7 +153,7 @@ typedef enum
153153
//--------------------------------------------------------------------+
154154

155155
/// SCSI Test Unit Ready Command
156-
typedef struct ATTR_PACKED
156+
typedef struct TU_ATTR_PACKED
157157
{
158158
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_TEST_UNIT_READY
159159
uint8_t lun ; ///< Logical Unit
@@ -164,7 +164,7 @@ typedef struct ATTR_PACKED
164164
TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
165165

166166
/// SCSI Inquiry Command
167-
typedef struct ATTR_PACKED
167+
typedef struct TU_ATTR_PACKED
168168
{
169169
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_INQUIRY
170170
uint8_t reserved1 ;
@@ -177,7 +177,7 @@ typedef struct ATTR_PACKED
177177
TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct");
178178

179179
/// SCSI Inquiry Response Data
180-
typedef struct ATTR_PACKED
180+
typedef struct TU_ATTR_PACKED
181181
{
182182
uint8_t peripheral_device_type : 5;
183183
uint8_t peripheral_qualifier : 3;
@@ -223,7 +223,7 @@ typedef struct ATTR_PACKED
223223
TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct");
224224

225225

226-
typedef struct ATTR_PACKED
226+
typedef struct TU_ATTR_PACKED
227227
{
228228
uint8_t response_code : 7; ///< 70h - current errors, Fixed Format 71h - deferred errors, Fixed Format
229229
uint8_t valid : 1;
@@ -249,7 +249,7 @@ typedef struct ATTR_PACKED
249249

250250
TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct");
251251

252-
typedef struct ATTR_PACKED
252+
typedef struct TU_ATTR_PACKED
253253
{
254254
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_MODE_SENSE_6
255255

@@ -268,7 +268,7 @@ typedef struct ATTR_PACKED
268268
TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct");
269269

270270
// This is only a Mode parameter header(6).
271-
typedef struct ATTR_PACKED
271+
typedef struct TU_ATTR_PACKED
272272
{
273273
uint8_t data_len;
274274
uint8_t medium_type;
@@ -281,7 +281,7 @@ typedef struct ATTR_PACKED
281281

282282
TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct");
283283

284-
typedef struct ATTR_PACKED
284+
typedef struct TU_ATTR_PACKED
285285
{
286286
uint8_t cmd_code; ///< SCSI OpCode for \ref SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL
287287
uint8_t reserved[3];
@@ -291,7 +291,7 @@ typedef struct ATTR_PACKED
291291

292292
TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
293293

294-
typedef struct ATTR_PACKED
294+
typedef struct TU_ATTR_PACKED
295295
{
296296
uint8_t cmd_code;
297297

@@ -318,7 +318,7 @@ TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct");
318318
// SCSI MMC
319319
//--------------------------------------------------------------------+
320320
/// SCSI Read Format Capacity: Write Capacity
321-
typedef struct ATTR_PACKED
321+
typedef struct TU_ATTR_PACKED
322322
{
323323
uint8_t cmd_code;
324324
uint8_t reserved[6];
@@ -328,7 +328,7 @@ typedef struct ATTR_PACKED
328328

329329
TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
330330

331-
typedef struct ATTR_PACKED{
331+
typedef struct TU_ATTR_PACKED{
332332
uint8_t reserved[3];
333333
uint8_t list_length; /// must be 8*n, length in bytes of formattable capacity descriptor followed it.
334334

@@ -348,7 +348,7 @@ TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not c
348348
//--------------------------------------------------------------------+
349349

350350
/// SCSI Read Capacity 10 Command: Read Capacity
351-
typedef struct ATTR_PACKED
351+
typedef struct TU_ATTR_PACKED
352352
{
353353
uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_READ_CAPACITY_10
354354
uint8_t reserved1 ;
@@ -369,7 +369,7 @@ typedef struct {
369369
TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct");
370370

371371
/// SCSI Read 10 Command
372-
typedef struct ATTR_PACKED
372+
typedef struct TU_ATTR_PACKED
373373
{
374374
uint8_t cmd_code ; ///< SCSI OpCode
375375
uint8_t reserved ; // has LUN according to wiki

0 commit comments

Comments
 (0)