Skip to content

Commit 008de7f

Browse files
authored
Merge pull request #286 from adafruit/update-tinyusb-0871238cacddb1802e5ce88a8e407d55a7fa34af
update tinyusb
2 parents 6546b4c + c4d4a0a commit 008de7f

File tree

17 files changed

+82
-117
lines changed

17 files changed

+82
-117
lines changed

src/class/audio/audio_device.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060

6161
#include "audio_device.h"
6262

63-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
64-
#define tu_static static
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; }
67-
#endif
68-
6963
//--------------------------------------------------------------------+
7064
// MACRO CONSTANT TYPEDEF
7165
//--------------------------------------------------------------------+

src/class/cdc/cdc_device.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333

3434
#include "cdc_device.h"
3535

36-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
37-
#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; }
40-
#endif
41-
42-
4336
//--------------------------------------------------------------------+
4437
// MACRO CONSTANT TYPEDEF
4538
//--------------------------------------------------------------------+

src/class/dfu/dfu_device.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333

3434
#include "dfu_device.h"
3535

36-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
37-
#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; }
40-
#endif
41-
4236
//--------------------------------------------------------------------+
4337
// MACRO CONSTANT TYPEDEF
4438
//--------------------------------------------------------------------+

src/class/dfu/dfu_rt_device.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333

3434
#include "dfu_rt_device.h"
3535

36-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
37-
#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; }
40-
#endif
41-
4236
//--------------------------------------------------------------------+
4337
// MACRO CONSTANT TYPEDEF
4438
//--------------------------------------------------------------------+

src/class/hid/hid_device.c

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

3737
#include "hid_device.h"
3838

39-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
40-
#define tu_static static
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; }
43-
#endif
44-
4539
//--------------------------------------------------------------------+
4640
// MACRO CONSTANT TYPEDEF
4741
//--------------------------------------------------------------------+

src/class/hid/hid_host.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333

3434
#include "hid_host.h"
3535

36-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
37-
#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; }
40-
#endif
41-
4236
//--------------------------------------------------------------------+
4337
// MACRO CONSTANT TYPEDEF
4438
//--------------------------------------------------------------------+

src/class/midi/midi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ typedef enum
7171
MIDI_CIN_SYSEX_END_1BYTE = 5, // SysEx ends with 1 data, or 1 byte system common message
7272
MIDI_CIN_SYSEX_END_2BYTE = 6, // SysEx ends with 2 data
7373
MIDI_CIN_SYSEX_END_3BYTE = 7, // SysEx ends with 3 data
74-
MIDI_CIN_NOTE_ON = 8,
75-
MIDI_CIN_NOTE_OFF = 9,
74+
MIDI_CIN_NOTE_OFF = 8,
75+
MIDI_CIN_NOTE_ON = 9,
7676
MIDI_CIN_POLY_KEYPRESS = 10,
7777
MIDI_CIN_CONTROL_CHANGE = 11,
7878
MIDI_CIN_PROGRAM_CHANGE = 12,

src/class/midi/midi_device.c

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

3737
#include "midi_device.h"
3838

39-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
40-
#define tu_static static
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; }
43-
#endif
44-
4539
//--------------------------------------------------------------------+
4640
// MACRO CONSTANT TYPEDEF
4741
//--------------------------------------------------------------------+

src/class/msc/msc_device.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434

3535
#include "msc_device.h"
3636

37-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
38-
#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; }
41-
#endif
42-
4337
//--------------------------------------------------------------------+
4438
// MACRO CONSTANT TYPEDEF
4539
//--------------------------------------------------------------------+

src/class/vendor/vendor_device.c

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333

3434
#include "vendor_device.h"
3535

36-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
37-
#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; }
40-
#endif
4136
//--------------------------------------------------------------------+
4237
// MACRO CONSTANT TYPEDEF
4338
//--------------------------------------------------------------------+
@@ -91,15 +86,20 @@ static void _prep_out_transaction (vendord_interface_t* p_itf)
9186
{
9287
uint8_t const rhport = 0;
9388

94-
// skip if previous transfer not complete
95-
if ( usbd_edpt_busy(rhport, p_itf->ep_out) ) return;
89+
// claim endpoint
90+
TU_VERIFY(usbd_edpt_claim(rhport, p_itf->ep_out), );
9691

9792
// Prepare for incoming data but only allow what we can store in the ring buffer.
9893
uint16_t max_read = tu_fifo_remaining(&p_itf->rx_ff);
9994
if ( max_read >= CFG_TUD_VENDOR_EPSIZE )
10095
{
10196
usbd_edpt_xfer(rhport, p_itf->ep_out, p_itf->epout_buf, CFG_TUD_VENDOR_EPSIZE);
10297
}
98+
else
99+
{
100+
// Release endpoint since we don't make any transfer
101+
usbd_edpt_release(rhport, p_itf->ep_out);
102+
}
103103
}
104104

105105
uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize)
@@ -120,37 +120,47 @@ void tud_vendor_n_read_flush (uint8_t itf)
120120
//--------------------------------------------------------------------+
121121
// Write API
122122
//--------------------------------------------------------------------+
123-
static uint16_t maybe_transmit(vendord_interface_t* p_itf)
124-
{
125-
uint8_t const rhport = 0;
126-
127-
// skip if previous transfer not complete
128-
TU_VERIFY( !usbd_edpt_busy(rhport, p_itf->ep_in) );
129-
130-
uint16_t count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, CFG_TUD_VENDOR_EPSIZE);
131-
if (count > 0)
132-
{
133-
TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_in, p_itf->epin_buf, count) );
134-
}
135-
return count;
136-
}
137-
138123
uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize)
139124
{
140125
vendord_interface_t* p_itf = &_vendord_itf[itf];
141126
uint16_t ret = tu_fifo_write_n(&p_itf->tx_ff, buffer, (uint16_t) bufsize);
127+
128+
// flush if queue more than packet size
142129
if (tu_fifo_count(&p_itf->tx_ff) >= CFG_TUD_VENDOR_EPSIZE) {
143-
maybe_transmit(p_itf);
130+
tud_vendor_n_write_flush(itf);
144131
}
145132
return ret;
146133
}
147134

148-
uint32_t tud_vendor_n_flush (uint8_t itf)
135+
uint32_t tud_vendor_n_write_flush (uint8_t itf)
149136
{
150137
vendord_interface_t* p_itf = &_vendord_itf[itf];
151-
uint32_t ret = maybe_transmit(p_itf);
152138

153-
return ret;
139+
// Skip if usb is not ready yet
140+
TU_VERIFY( tud_ready(), 0 );
141+
142+
// No data to send
143+
if ( !tu_fifo_count(&p_itf->tx_ff) ) return 0;
144+
145+
uint8_t const rhport = 0;
146+
147+
// Claim the endpoint
148+
TU_VERIFY( usbd_edpt_claim(rhport, p_itf->ep_in), 0 );
149+
150+
// Pull data from FIFO
151+
uint16_t const count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, sizeof(p_itf->epin_buf));
152+
153+
if ( count )
154+
{
155+
TU_ASSERT( usbd_edpt_xfer(rhport, p_itf->ep_in, p_itf->epin_buf, count), 0 );
156+
return count;
157+
}else
158+
{
159+
// Release endpoint since we don't make any transfer
160+
// Note: data is dropped if terminal is not connected
161+
usbd_edpt_release(rhport, p_itf->ep_in);
162+
return 0;
163+
}
154164
}
155165

156166
uint32_t tud_vendor_n_write_available (uint8_t itf)
@@ -230,10 +240,10 @@ uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, ui
230240
// Prepare for incoming data
231241
if ( p_vendor->ep_out )
232242
{
233-
TU_ASSERT(usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)), 0);
243+
_prep_out_transaction(p_vendor);
234244
}
235245

236-
if ( p_vendor->ep_in ) maybe_transmit(p_vendor);
246+
if ( p_vendor->ep_in ) tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
237247
}
238248

239249
return (uint16_t) ((uintptr_t) p_desc - (uintptr_t) desc_itf);
@@ -268,7 +278,7 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
268278
{
269279
if (tud_vendor_tx_cb) tud_vendor_tx_cb(itf, (uint16_t) xferred_bytes);
270280
// Send complete, try to send more if possible
271-
maybe_transmit(p_itf);
281+
tud_vendor_n_write_flush(itf);
272282
}
273283

274284
return true;

0 commit comments

Comments
 (0)