Skip to content

Commit d3def20

Browse files
committed
clean up fix for esp32
1 parent 3336e16 commit d3def20

File tree

13 files changed

+51
-182
lines changed

13 files changed

+51
-182
lines changed

src/class/audio/audio_device.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,8 @@
6262

6363
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
6464
#define tu_static static
65-
66-
// This is a backport of memset_s from c11
67-
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
68-
{
69-
// TODO may check if desst and src is not NULL
70-
if (count > destsz) {
71-
return -1;
72-
}
73-
memset(dest, ch, count);
74-
return 0;
75-
}
76-
77-
// This is a backport of memcpy_s from c11
78-
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
79-
{
80-
// TODO may check if desst and src is not NULL
81-
if (count > destsz) {
82-
return -1;
83-
}
84-
memcpy(dest, src, count);
85-
return 0;
86-
}
87-
88-
extern bool usbd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep);
65+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
66+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
8967
#endif
9068

9169
//--------------------------------------------------------------------+

src/class/cdc/cdc_device.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
3737
#define tu_static static
38+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
39+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
3840
#endif
3941

4042

src/class/cdc/cdc_host.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ bool tuh_cdc_set_control_line_state(uint8_t idx, uint16_t line_state, tuh_xfer_c
323323
.user_data = user_data
324324
};
325325

326-
return tuh_control_xfer(&xfer);
326+
TU_ASSERT(tuh_control_xfer(&xfer));
327+
return true;
327328
}
328329

329330
bool tuh_cdc_set_line_coding(uint8_t idx, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
@@ -363,7 +364,8 @@ bool tuh_cdc_set_line_coding(uint8_t idx, cdc_line_coding_t const* line_coding,
363364
.user_data = user_data
364365
};
365366

366-
return tuh_control_xfer(&xfer);
367+
TU_ASSERT(tuh_control_xfer(&xfer));
368+
return true;
367369
}
368370

369371
//--------------------------------------------------------------------+
@@ -543,26 +545,31 @@ static void process_cdc_config(tuh_xfer_t* xfer)
543545
uintptr_t const state = xfer->user_data;
544546
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
545547
uint8_t const idx = tuh_cdc_itf_get_index(xfer->daddr, itf_num);
546-
TU_ASSERT(idx != TUSB_INDEX_INVALID_8, );
548+
cdch_interface_t * p_cdc = get_itf(idx);
549+
TU_ASSERT(p_cdc, );
547550

548551
switch(state)
549552
{
550553
case CONFIG_SET_CONTROL_LINE_STATE:
551-
#if CFG_TUH_CDC_LINE_CONTROL_ON_ENUM
552-
TU_ASSERT( tuh_cdc_set_control_line_state(idx, CFG_TUH_CDC_LINE_CONTROL_ON_ENUM, process_cdc_config, CONFIG_SET_LINE_CODING), );
553-
break;
554-
#endif
555-
TU_ATTR_FALLTHROUGH;
554+
#if CFG_TUH_CDC_LINE_CONTROL_ON_ENUM
555+
if (p_cdc->acm_capability.support_line_request)
556+
{
557+
TU_ASSERT( tuh_cdc_set_control_line_state(idx, CFG_TUH_CDC_LINE_CONTROL_ON_ENUM, process_cdc_config, CONFIG_SET_LINE_CODING), );
558+
break;
559+
}
560+
#endif
561+
TU_ATTR_FALLTHROUGH;
556562

557563
case CONFIG_SET_LINE_CODING:
558-
#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
559-
{
560-
cdc_line_coding_t line_coding = CFG_TUH_CDC_LINE_CODING_ON_ENUM;
561-
TU_ASSERT( tuh_cdc_set_line_coding(idx, &line_coding, process_cdc_config, CONFIG_COMPLETE), );
562-
break;
563-
}
564-
#endif
565-
TU_ATTR_FALLTHROUGH;
564+
#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
565+
if (p_cdc->acm_capability.support_line_request)
566+
{
567+
cdc_line_coding_t line_coding = CFG_TUH_CDC_LINE_CODING_ON_ENUM;
568+
TU_ASSERT( tuh_cdc_set_line_coding(idx, &line_coding, process_cdc_config, CONFIG_COMPLETE), );
569+
break;
570+
}
571+
#endif
572+
TU_ATTR_FALLTHROUGH;
566573

567574
case CONFIG_COMPLETE:
568575
if (tuh_cdc_mount_cb) tuh_cdc_mount_cb(idx);

src/class/dfu/dfu_device.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@
3333

3434
#include "dfu_device.h"
3535

36-
//--------------------------------------------------------------------+
37-
// MACRO CONSTANT TYPEDEF
38-
//--------------------------------------------------------------------+
39-
4036
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
4137
#define tu_static static
38+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
39+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
4240
#endif
4341

42+
//--------------------------------------------------------------------+
43+
// MACRO CONSTANT TYPEDEF
44+
//--------------------------------------------------------------------+
45+
4446
//--------------------------------------------------------------------+
4547
// INTERNAL OBJECT & FUNCTION DECLARATION
4648
//--------------------------------------------------------------------+

src/class/dfu/dfu_rt_device.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,8 @@
3535

3636
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
3737
#define tu_static static
38-
39-
// This is a backport of memset_s from c11
40-
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
41-
{
42-
// TODO may check if desst and src is not NULL
43-
if (count > destsz) {
44-
return -1;
45-
}
46-
memset(dest, ch, count);
47-
return 0;
48-
}
49-
50-
// This is a backport of memcpy_s from c11
51-
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
52-
{
53-
// TODO may check if desst and src is not NULL
54-
if (count > destsz) {
55-
return -1;
56-
}
57-
memcpy(dest, src, count);
58-
return 0;
59-
}
38+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
39+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
6040
#endif
6141

6242
//--------------------------------------------------------------------+

src/class/hid/hid_device.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,8 @@
3838

3939
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
4040
#define tu_static static
41-
42-
// This is a backport of memset_s from c11
43-
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
44-
{
45-
// TODO may check if desst and src is not NULL
46-
if (count > destsz) {
47-
return -1;
48-
}
49-
memset(dest, ch, count);
50-
return 0;
51-
}
52-
53-
// This is a backport of memcpy_s from c11
54-
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
55-
{
56-
// TODO may check if desst and src is not NULL
57-
if (count > destsz) {
58-
return -1;
59-
}
60-
memcpy(dest, src, count);
61-
return 0;
62-
}
63-
41+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
42+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
6443
#endif
6544

6645
//--------------------------------------------------------------------+

src/class/hid/hid_host.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
3737
#define tu_static static
38+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
39+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
3840
#endif
3941

4042
//--------------------------------------------------------------------+

src/class/midi/midi_device.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,8 @@
3838

3939
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
4040
#define tu_static static
41-
42-
// This is a backport of memset_s from c11
43-
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
44-
{
45-
// TODO may check if desst and src is not NULL
46-
if (count > destsz) {
47-
return -1;
48-
}
49-
memset(dest, ch, count);
50-
return 0;
51-
}
52-
53-
// This is a backport of memcpy_s from c11
54-
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
55-
{
56-
// TODO may check if desst and src is not NULL
57-
if (count > destsz) {
58-
return -1;
59-
}
60-
memcpy(dest, src, count);
61-
return 0;
62-
}
63-
41+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
42+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
6443
#endif
6544

6645
//--------------------------------------------------------------------+

src/class/msc/msc_device.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,8 @@
3636

3737
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
3838
#define tu_static static
39-
40-
// This is a backport of memset_s from c11
41-
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
42-
{
43-
// TODO may check if desst and src is not NULL
44-
if (count > destsz) {
45-
return -1;
46-
}
47-
memset(dest, ch, count);
48-
return 0;
49-
}
50-
51-
// This is a backport of memcpy_s from c11
52-
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
53-
{
54-
// TODO may check if desst and src is not NULL
55-
if (count > destsz) {
56-
return -1;
57-
}
58-
memcpy(dest, src, count);
59-
return 0;
60-
}
61-
39+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
40+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
6241
#endif
6342

6443
//--------------------------------------------------------------------+

src/class/vendor/vendor_device.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535

3636
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
3737
#define tu_static static
38+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
39+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
3840
#endif
39-
4041
//--------------------------------------------------------------------+
4142
// MACRO CONSTANT TYPEDEF
4243
//--------------------------------------------------------------------+

src/class/video/video_device.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
3838
#define tu_static static
39+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
40+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
3941
#endif
4042

4143
//--------------------------------------------------------------------+

src/device/usbd_control.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,8 @@
3434

3535
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
3636
#define tu_static static
37-
38-
// This is a backport of memset_s from c11
39-
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
40-
{
41-
// TODO may check if desst and src is not NULL
42-
if (count > destsz) {
43-
return -1;
44-
}
45-
memset(dest, ch, count);
46-
return 0;
47-
}
48-
49-
// This is a backport of memcpy_s from c11
50-
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
51-
{
52-
// TODO may check if desst and src is not NULL
53-
if (count > destsz) {
54-
return -1;
55-
}
56-
memcpy(dest, src, count);
57-
return 0;
58-
}
59-
37+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
38+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
6039
#endif
6140

6241
#if CFG_TUSB_DEBUG >= 2

src/tusb.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,8 @@
4141

4242
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
4343
#define tu_static static
44-
45-
// This is a backport of memset_s from c11
46-
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
47-
{
48-
// TODO may check if desst and src is not NULL
49-
if (count > destsz) {
50-
return -1;
51-
}
52-
memset(dest, ch, count);
53-
return 0;
54-
}
55-
56-
// This is a backport of memcpy_s from c11
57-
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
58-
{
59-
// TODO may check if desst and src is not NULL
60-
if (count > destsz) {
61-
return -1;
62-
}
63-
memcpy(dest, src, count);
64-
return 0;
65-
}
66-
44+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
45+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
6746
#endif
6847

6948
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)