Skip to content

Commit a3a5a41

Browse files
authored
Merge pull request #3339 from hathach/cdc-edpt-stream
migrate cdc device to edpt stream API
2 parents 8b8f1f8 + c9a9e94 commit a3a5a41

File tree

12 files changed

+264
-310
lines changed

12 files changed

+264
-310
lines changed

.clang-format

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
Language: Cpp
33
BasedOnStyle: LLVM
4-
AlignAfterOpenBracket: AlwaysBreak
4+
AlignAfterOpenBracket: Align
55
AlignConsecutiveAssignments:
66
Enabled: true
77
AcrossEmptyLines: false
@@ -38,6 +38,7 @@ AllowShortEnumsOnASingleLine: false
3838
AllowShortFunctionsOnASingleLine: None
3939
AllowShortIfStatementsOnASingleLine: Never
4040
AlwaysBreakTemplateDeclarations: Yes
41+
BinPackArguments: true
4142
BreakBeforeBraces: Custom
4243
BraceWrapping:
4344
AfterCaseLabel: false
@@ -57,11 +58,14 @@ BraceWrapping:
5758
SplitEmptyRecord: true
5859
SplitEmptyNamespace: true
5960
BracedInitializerIndentWidth: 2
61+
BreakBeforeBinaryOperators: None
6062
BreakConstructorInitializers: AfterColon
6163
BreakConstructorInitializersBeforeComma: false
64+
ContinuationIndentWidth: 2
6265
ColumnLimit: 120
6366
ConstructorInitializerAllOnOneLineOrOnePerLine: false
6467
Cpp11BracedListStyle: true
68+
IncludeBlocks: Preserve
6569
IncludeCategories:
6670
- Regex: '^<.*'
6771
Priority: 1
@@ -78,6 +82,8 @@ MacroBlockBegin: ''
7882
MacroBlockEnd: ''
7983
MaxEmptyLinesToKeep: 2
8084
NamespaceIndentation: All
85+
PenaltyBreakBeforeFirstCallParameter: 1000000
86+
PenaltyBreakOpenParenthesis: 1000000
8187
QualifierAlignment: Custom
8288
QualifierOrder: ['static', 'const', 'volatile', 'restrict', 'type']
8389
ReflowComments: false

examples/device/net_lwip_webserver/src/usb_descriptors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_contro
270270

271271
switch (request->bmRequestType_bit.type) {
272272
case TUSB_REQ_TYPE_VENDOR:
273-
switch (request->bRequest) { //-V2520 //-V2659
273+
switch (request->bRequest) {
274274
case 1:
275275
if (request->wIndex == 7) {
276276
// Get Microsoft OS 2.0 compatible descriptor

examples/dual/host_info_to_device_cdc/src/main.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ enum {
6969

7070
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
7171

72-
static bool is_print[CFG_TUH_DEVICE_MAX+1] = { 0 };
72+
static bool is_printable[CFG_TUH_DEVICE_MAX + 1] = {0};
7373
static tusb_desc_device_t descriptor_device[CFG_TUH_DEVICE_MAX+1];
7474

7575
static void print_utf16(uint16_t *temp_buf, size_t buf_len);
@@ -106,6 +106,10 @@ static void usb_device_init(void) {
106106
.speed = TUSB_SPEED_AUTO
107107
};
108108
tusb_init(BOARD_TUD_RHPORT, &dev_init);
109+
tud_cdc_configure_t cdc_cfg = TUD_CDC_CONFIGURE_DEFAULT();
110+
cdc_cfg.tx_persistent = true;
111+
cdc_cfg.tx_overwritabe_if_not_connected = false;
112+
tud_cdc_configure(&cdc_cfg);
109113
board_init_after_tusb();
110114
}
111115

@@ -206,17 +210,23 @@ void tud_resume_cb(void) {
206210
}
207211

208212
void cdc_task(void) {
213+
static uint32_t connected_ms = 0;
214+
209215
if (!tud_cdc_connected()) {
210-
// delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding.
211-
// If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop
212-
tusb_time_delay_ms_api(20);
216+
connected_ms = board_millis();
213217
return;
214218
}
215219

220+
// delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding.
221+
// If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop
222+
if (board_millis() - connected_ms < 100) {
223+
return; // wait for stable connection
224+
}
225+
216226
for (uint8_t daddr = 1; daddr <= CFG_TUH_DEVICE_MAX; daddr++) {
217227
if (tuh_mounted(daddr)) {
218-
if (is_print[daddr]) {
219-
is_print[daddr] = false;
228+
if (is_printable[daddr]) {
229+
is_printable[daddr] = false;
220230
print_device_info(daddr, &descriptor_device[daddr]);
221231
tud_cdc_write_flush();
222232
}
@@ -283,13 +293,13 @@ void tuh_enum_descriptor_device_cb(uint8_t daddr, tusb_desc_device_t const* desc
283293
void tuh_mount_cb(uint8_t daddr) {
284294
cdc_printf("mounted device %u\r\n", daddr);
285295
tud_cdc_write_flush();
286-
is_print[daddr] = true;
296+
is_printable[daddr] = true;
287297
}
288298

289299
void tuh_umount_cb(uint8_t daddr) {
290300
cdc_printf("unmounted device %u\r\n", daddr);
291301
tud_cdc_write_flush();
292-
is_print[daddr] = false;
302+
is_printable[daddr] = false;
293303
}
294304

295305
//--------------------------------------------------------------------+

examples/dual/host_info_to_device_cdc/src/tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112

113113
// CDC FIFO size of TX and RX
114114
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
115-
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
115+
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
116116

117117
// CDC Endpoint transfer buffer size, more is faster
118118
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

0 commit comments

Comments
 (0)