Skip to content

Commit d74c03e

Browse files
authored
Merge pull request #578 from adafruit/update-tinyusb-commit-dcd2a4bd0f005835d3edc193309ef3484cd9c8b3
update tinyusb core to commit dcd2a4b
2 parents 3e0da82 + 1af12d5 commit d74c03e

52 files changed

Lines changed: 2578 additions & 1597 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/class/hid/hid_host.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,31 @@ static uint8_t _hidh_default_protocol = HID_PROTOCOL_BOOT;
7474
// Weak stubs: invoked if no strong implementation is available
7575
//--------------------------------------------------------------------+
7676
TU_ATTR_WEAK void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report_desc, uint16_t desc_len) {
77-
(void) dev_addr;
78-
(void) idx;
79-
(void) report_desc;
80-
(void) desc_len;
77+
(void) dev_addr; (void) idx; (void) report_desc; (void) desc_len;
8178
}
8279

8380
TU_ATTR_WEAK void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t idx) {
84-
(void) dev_addr;
85-
(void) idx;
81+
(void) dev_addr; (void) idx;
82+
}
83+
84+
TU_ATTR_WEAK void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t idx, const uint8_t *report, uint16_t len) {
85+
(void) dev_addr; (void) idx; (void) report; (void) len;
8686
}
8787

8888
TU_ATTR_WEAK void tuh_hid_report_sent_cb(uint8_t dev_addr, uint8_t idx, uint8_t const* report, uint16_t len) {
89-
(void) dev_addr;
90-
(void) idx;
91-
(void) report;
92-
(void) len;
89+
(void) dev_addr; (void) idx; (void) report; (void) len;
9390
}
9491

9592
TU_ATTR_WEAK void tuh_hid_get_report_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_t report_type, uint16_t len) {
96-
(void) dev_addr;
97-
(void) idx;
98-
(void) report_id;
99-
(void) report_type;
100-
(void) len;
93+
(void) dev_addr; (void) idx; (void) report_id; (void) report_type; (void) len;
10194
}
10295

10396
TU_ATTR_WEAK void tuh_hid_set_report_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_t report_type, uint16_t len) {
104-
(void) dev_addr;
105-
(void) idx;
106-
(void) report_id;
107-
(void) report_type;
108-
(void) len;
97+
(void) dev_addr; (void) idx; (void) report_id; (void) report_type; (void) len;
10998
}
11099

111100
TU_ATTR_WEAK void tuh_hid_set_protocol_complete_cb(uint8_t dev_addr, uint8_t idx, uint8_t protocol) {
112-
(void) dev_addr;
113-
(void) idx;
114-
(void) protocol;
101+
(void) dev_addr; (void) idx; (void) protocol;
115102
}
116103

117104
//--------------------------------------------------------------------+

src/class/hid/hid_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx);
140140
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, const void *report, uint16_t len);
141141

142142
//--------------------------------------------------------------------+
143-
// Callbacks (Weak is optional)
143+
// Callbacks (optional)
144144
//--------------------------------------------------------------------+
145145

146146
// Invoked when device with hid interface is mounted

src/class/midi/midi_host.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ uint32_t tuh_midi_stream_write(uint8_t idx, uint8_t cable_num, const uint8_t *p_
150150
// Note that this function ignores the CIN field of the MIDI packet
151151
// because a number of commercial devices out there do not encode
152152
// it properly.
153+
//
154+
// NOTE: this function terminates when it encounters an event whose cable
155+
// number differs from the one being returned. Applications should invoke
156+
// it in a loop until it returns 0 (or until tuh_midi_read_available()
157+
// returns 0) to guarantee the stream FIFO is fully drained per callback.
158+
// Leaving bytes in the FIFO across callbacks can prevent subsequent bulk
159+
// IN transfers from landing.
153160
uint32_t tuh_midi_stream_read(uint8_t idx, uint8_t *p_cable_num, uint8_t *p_buffer, uint16_t bufsize);
154161

155162
#endif

src/class/mtp/mtp.h

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -798,45 +798,65 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_array(mtp_contain
798798
}
799799

800800
TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_string(mtp_container_info_t* p_container, uint16_t* utf16) {
801-
uint8_t count = 0;
801+
uint32_t count = 0;
802802
while (utf16[count] != 0u) {
803803
count++;
804804
}
805-
const uint32_t added_len = 1u + (uint32_t) count * 2u;
806-
TU_ASSERT(p_container->header->len + added_len < CFG_TUD_MTP_EP_BUFSIZE, 0);
805+
// MTP strings store length in a single uint8_t, including trailing null.
806+
TU_ASSERT(count < UINT8_MAX, 0);
807+
count++;
808+
807809
uint8_t* buf = p_container->payload + p_container->header->len - sizeof(mtp_container_header_t);
808810

809-
*buf++ = count;
811+
if (count == 1) {
812+
// empty string (size only): single zero byte
813+
TU_ASSERT(p_container->header->len + 1 < CFG_TUD_MTP_EP_BUFSIZE, 0);
814+
*buf = 0;
815+
p_container->header->len++;
816+
return 1u;
817+
}
818+
819+
const uint32_t added_len = 1u + count * 2u;
820+
TU_ASSERT(p_container->header->len + added_len < CFG_TUD_MTP_EP_BUFSIZE, 0);
821+
822+
*buf++ = (uint8_t) count;
810823
p_container->header->len++;
811824

812-
memcpy(buf, utf16, 2u * (uint32_t) count);
825+
memcpy(buf, utf16, 2u * count);
813826
p_container->header->len += 2u * count;
814827

815828
return added_len;
816829
}
817830

818831
TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_cstring(mtp_container_info_t* p_container, const char* str) {
819-
const uint8_t len = (uint8_t) (strlen(str) + 1); // include null
820-
TU_ASSERT(p_container->header->len + 1 + 2 * len < CFG_TUD_MTP_EP_BUFSIZE, 0);
832+
const size_t cstr_len = strlen(str);
833+
// MTP strings store length in a single uint8_t, including trailing null.
834+
TU_ASSERT(cstr_len < UINT8_MAX, 0);
835+
836+
const uint32_t count = (uint32_t) cstr_len + 1u; // include null
821837
uint8_t* buf = p_container->payload + p_container->header->len - sizeof(mtp_container_header_t);
822838

823-
if (len == 1) {
824-
// empty string (null only): single zero byte
839+
if (count == 1u) {
840+
// empty string (size only): single zero byte
841+
TU_ASSERT(p_container->header->len + 1 < CFG_TUD_MTP_EP_BUFSIZE, 0);
825842
*buf = 0;
826843
p_container->header->len++;
827844
return 1u;
828-
} else {
829-
*buf++ = len;
830-
p_container->header->len++;
845+
}
831846

832-
for (uint8_t i = 0; i < len; i++) {
833-
buf[0] = str[i];
834-
buf[1] = 0;
835-
buf += 2;
836-
p_container->header->len += 2;
837-
}
838-
return 1u + 2u * len;
847+
const uint32_t added_len = 1u + 2u * count;
848+
TU_ASSERT(p_container->header->len + added_len < CFG_TUD_MTP_EP_BUFSIZE, 0);
849+
850+
*buf++ = (uint8_t) count;
851+
p_container->header->len++;
852+
853+
for (uint32_t i = 0; i < count; i++) {
854+
*buf++ = (uint8_t) str[i];
855+
*buf++ = 0;
839856
}
857+
p_container->header->len += 2u * count;
858+
859+
return added_len;
840860
}
841861

842862
TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_uint8(mtp_container_info_t* p_container, uint8_t data) {

src/class/mtp/mtp_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool mtpd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
321321
.session_id = p_mtp->session_id,
322322
.request = request,
323323
.buf = p_mtp->control_buf,
324-
.bufsize = tu_le16toh(request->wLength),
324+
.bufsize = request->wLength,
325325
};
326326

327327
switch (request->bRequest) {

src/class/mtp/mtp_device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ typedef struct {
7878
mtp_auint16_t(_capture_count) capture_formats; \
7979
mtp_auint16_t(_playback_count) playback_formats; \
8080
/* string fields will be added using append function */ \
81+
/* mtp_string_t() Manufacturer */ \
82+
/* mtp_string_t() Model */ \
83+
/* mtp_string_t() Device Version */ \
84+
/* mtp_string_t() Serial Number */ \
8185
}
8286

8387
typedef MTP_DEVICE_INFO_STRUCT( //-V2586 [MISRA-C-18.7] Flexible array members should not be declared

src/class/net/ecm_rndis_device.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ typedef struct {
4848
uint8_t itf_num; // Index number of Management Interface, +1 for Data Interface
4949
uint8_t itf_data_alt; // Alternate setting of Data Interface. 0 : inactive, 1 : active
5050

51-
uint8_t ep_notif;
5251
uint8_t ep_in;
5352
uint8_t ep_out;
53+
uint16_t ep_size; // bulk endpoint max packet size (IN and OUT assumed equal)
54+
uint8_t ep_notif;
5455

5556
bool ecm_mode;
5657

@@ -81,6 +82,13 @@ CFG_TUD_MEM_SECTION static netd_epbuf_t _netd_epbuf;
8182
static bool can_xmit;
8283
static bool ecm_link_is_up = true; // Store link state for ECM mode
8384

85+
//--------------------------------------------------------------------+
86+
// Weak stubs: invoked if no strong implementation is available
87+
//--------------------------------------------------------------------+
88+
TU_ATTR_WEAK void tud_network_set_packet_filter_cb(uint16_t packet_filter) {
89+
(void) packet_filter;
90+
}
91+
8492
void tud_network_recv_renew(void) {
8593
usbd_edpt_xfer(0, _netd_itf.ep_out, _netd_epbuf.rx, NETD_PACKET_SIZE, false);
8694
}
@@ -176,6 +184,9 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
176184
// Pair of endpoints
177185
TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc), 0);
178186

187+
// Save the actual bulk endpoint size (IN and OUT assumed equal)
188+
_netd_itf.ep_size = tu_edpt_packet_size((tusb_desc_endpoint_t const *) p_desc);
189+
179190
if (_netd_itf.ecm_mode) {
180191
// ECM by default is in-active, save the endpoint attribute
181192
// to open later when received setInterface
@@ -206,14 +217,15 @@ static void ecm_report(bool nc) {
206217
},
207218
};
208219

220+
const uint32_t link_bps = (tud_speed_get() == TUSB_SPEED_HIGH) ? 480000000U : 12000000U;
209221
const ecm_notify_t ecm_notify_csc = {
210222
.header = {
211223
.bmRequestType = 0xA1,
212224
.bRequest = 0x2A, /* CONNECTION_SPEED_CHANGE aka ConnectionSpeedChange */
213225
.wLength = 8,
214226
},
215-
.downlink = 9728000,
216-
.uplink = 9728000,
227+
.downlink = link_bps,
228+
.uplink = link_bps,
217229
};
218230

219231
ecm_notify_t notify = (nc) ? ecm_notify_nc : ecm_notify_csc;
@@ -285,6 +297,7 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
285297
if (_netd_itf.ecm_mode) {
286298
/* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
287299
if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest) {
300+
tud_network_set_packet_filter_cb(request->wValue);
288301
tud_control_xfer(rhport, request, NULL, 0);
289302
// Only send connection notification if link is up
290303
if (ecm_link_is_up) {
@@ -356,8 +369,7 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
356369
/* data transmission finished */
357370
if (ep_addr == _netd_itf.ep_in) {
358371
/* TinyUSB requires the class driver to implement ZLP (since ZLP usage is class-specific) */
359-
360-
if (xferred_bytes && (0 == (xferred_bytes % CFG_TUD_NET_ENDPOINT_SIZE))) {
372+
if (xferred_bytes > 0 && 0 == (xferred_bytes & (_netd_itf.ep_size-1))) {
361373
do_in_xfer(NULL, 0); /* a ZLP is needed */
362374
} else {
363375
/* we're finally finished */

src/class/net/ncm.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,18 @@ typedef struct {
161161
uint32_t uplink;
162162
} ncm_notify_t;
163163

164+
typedef struct TU_ATTR_PACKED {
165+
uint8_t bFunctionLength;
166+
uint8_t bDescriptorType;
167+
uint8_t bDescriptorSubType;
168+
uint16_t bcdNcmVersion;
169+
uint8_t bmCapabilities;
170+
} tusb_desc_cdc_ncm_func_t;
171+
172+
typedef struct TU_ATTR_PACKED {
173+
uint32_t dwNtbInMaxSize;
174+
uint16_t wNtbInMaxDatagrams;
175+
uint16_t wReserved;
176+
} ncm_ntb_input_size_t;
177+
164178
#endif

0 commit comments

Comments
 (0)