Skip to content

Commit 5e827ca

Browse files
committed
update tinyusb to hathach/tinyusb@eb7d359
1 parent 49c2829 commit 5e827ca

File tree

6 files changed

+42
-55
lines changed

6 files changed

+42
-55
lines changed

src/device/usbd.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static usbd_class_driver_t const _usbd_driver[] =
9898
.open = cdcd_open,
9999
.control_xfer_cb = cdcd_control_xfer_cb,
100100
.xfer_cb = cdcd_xfer_cb,
101-
.sof_isr = NULL
101+
.sof = NULL
102102
},
103103
#endif
104104

@@ -110,7 +110,7 @@ static usbd_class_driver_t const _usbd_driver[] =
110110
.open = mscd_open,
111111
.control_xfer_cb = mscd_control_xfer_cb,
112112
.xfer_cb = mscd_xfer_cb,
113-
.sof_isr = NULL
113+
.sof = NULL
114114
},
115115
#endif
116116

@@ -122,7 +122,7 @@ static usbd_class_driver_t const _usbd_driver[] =
122122
.open = hidd_open,
123123
.control_xfer_cb = hidd_control_xfer_cb,
124124
.xfer_cb = hidd_xfer_cb,
125-
.sof_isr = NULL
125+
.sof = NULL
126126
},
127127
#endif
128128

@@ -134,7 +134,7 @@ static usbd_class_driver_t const _usbd_driver[] =
134134
.open = audiod_open,
135135
.control_xfer_cb = audiod_control_xfer_cb,
136136
.xfer_cb = audiod_xfer_cb,
137-
.sof_isr = audiod_sof_isr
137+
.sof = audiod_sof_isr
138138
},
139139
#endif
140140

@@ -146,7 +146,7 @@ static usbd_class_driver_t const _usbd_driver[] =
146146
.open = videod_open,
147147
.control_xfer_cb = videod_control_xfer_cb,
148148
.xfer_cb = videod_xfer_cb,
149-
.sof_isr = NULL
149+
.sof = NULL
150150
},
151151
#endif
152152

@@ -158,7 +158,7 @@ static usbd_class_driver_t const _usbd_driver[] =
158158
.reset = midid_reset,
159159
.control_xfer_cb = midid_control_xfer_cb,
160160
.xfer_cb = midid_xfer_cb,
161-
.sof_isr = NULL
161+
.sof = NULL
162162
},
163163
#endif
164164

@@ -170,7 +170,7 @@ static usbd_class_driver_t const _usbd_driver[] =
170170
.open = vendord_open,
171171
.control_xfer_cb = tud_vendor_control_xfer_cb,
172172
.xfer_cb = vendord_xfer_cb,
173-
.sof_isr = NULL
173+
.sof = NULL
174174
},
175175
#endif
176176

@@ -182,7 +182,7 @@ static usbd_class_driver_t const _usbd_driver[] =
182182
.open = usbtmcd_open_cb,
183183
.control_xfer_cb = usbtmcd_control_xfer_cb,
184184
.xfer_cb = usbtmcd_xfer_cb,
185-
.sof_isr = NULL
185+
.sof = NULL
186186
},
187187
#endif
188188

@@ -194,7 +194,7 @@ static usbd_class_driver_t const _usbd_driver[] =
194194
.open = dfu_rtd_open,
195195
.control_xfer_cb = dfu_rtd_control_xfer_cb,
196196
.xfer_cb = NULL,
197-
.sof_isr = NULL
197+
.sof = NULL
198198
},
199199
#endif
200200

@@ -206,7 +206,7 @@ static usbd_class_driver_t const _usbd_driver[] =
206206
.open = dfu_moded_open,
207207
.control_xfer_cb = dfu_moded_control_xfer_cb,
208208
.xfer_cb = NULL,
209-
.sof_isr = NULL
209+
.sof = NULL
210210
},
211211
#endif
212212

@@ -218,7 +218,7 @@ static usbd_class_driver_t const _usbd_driver[] =
218218
.open = netd_open,
219219
.control_xfer_cb = netd_control_xfer_cb,
220220
.xfer_cb = netd_xfer_cb,
221-
.sof_isr = NULL,
221+
.sof = NULL,
222222
},
223223
#endif
224224

@@ -230,7 +230,7 @@ static usbd_class_driver_t const _usbd_driver[] =
230230
.open = btd_open,
231231
.control_xfer_cb = btd_control_xfer_cb,
232232
.xfer_cb = btd_xfer_cb,
233-
.sof_isr = NULL
233+
.sof = NULL
234234
},
235235
#endif
236236
};
@@ -264,8 +264,6 @@ static inline usbd_class_driver_t const * get_driver(uint8_t drvid)
264264
// DCD Event
265265
//--------------------------------------------------------------------+
266266

267-
//static tud_sof_isr_t _sof_isr = NULL;
268-
269267
enum { RHPORT_INVALID = 0xFFu };
270268
static uint8_t _usbd_rhport = RHPORT_INVALID;
271269

@@ -373,12 +371,6 @@ bool tud_connect(void)
373371
return true;
374372
}
375373

376-
//void tud_sof_isr_set(tud_sof_isr_t sof_isr)
377-
//{
378-
// _sof_isr = sof_isr;
379-
// dcd_sof_enable(_usbd_rhport, _sof_isr != NULL);
380-
//}
381-
382374
//--------------------------------------------------------------------+
383375
// USBD Task
384376
//--------------------------------------------------------------------+
@@ -392,7 +384,7 @@ bool tud_init (uint8_t rhport)
392384
// skip if already initialized
393385
if ( tud_inited() ) return true;
394386

395-
TU_LOG2("USBD init rhport %u\r\n", rhport);
387+
TU_LOG2("USBD init on controller %u\r\n", rhport);
396388
TU_LOG2_INT(sizeof(usbd_device_t));
397389

398390
tu_varclr(&_usbd_dev);
@@ -422,7 +414,6 @@ bool tud_init (uint8_t rhport)
422414
}
423415

424416
_usbd_rhport = rhport;
425-
//_sof_isr = NULL;
426417

427418
// Init device controller driver
428419
dcd_init(rhport);
@@ -1110,15 +1101,12 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const * event, bool in_isr)
11101101
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
11111102
{
11121103
usbd_class_driver_t const * driver = get_driver(i);
1113-
if (driver->sof_isr)
1104+
if (driver->sof)
11141105
{
1115-
driver->sof_isr(event->rhport, event->sof.frame_count);
1106+
driver->sof(event->rhport, event->sof.frame_count);
11161107
}
11171108
}
11181109

1119-
// SOF user handler in ISR context
1120-
// if (_sof_isr) _sof_isr(event->sof.frame_count);
1121-
11221110
// Some MCUs after running dcd_remote_wakeup() does not have way to detect the end of remote wakeup
11231111
// which last 1-15 ms. DCD can use SOF as a clear indicator that bus is back to operational
11241112
if ( _usbd_dev.suspended )

src/device/usbd.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
extern "C" {
3434
#endif
3535

36-
// typedef void (*tud_sof_isr_t) (uint32_t frame_count);
37-
3836
//--------------------------------------------------------------------+
3937
// Application API
4038
//--------------------------------------------------------------------+
@@ -95,10 +93,6 @@ bool tud_disconnect(void);
9593
// Return false on unsupported MCUs
9694
bool tud_connect(void);
9795

98-
// Set Start-of-frame (1ms interval) IRQ handler
99-
// NULL means disabled, frame_count may not be supported on mcus
100-
// void tud_sof_isr_set(tud_sof_isr_t sof_isr);
101-
10296
// Carry out Data and Status stage of control transfer
10397
// - If len = 0, it is equivalent to sending status only
10498
// - If len > wLength : it will be truncated

src/device/usbd_pvt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct
4848
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
4949
bool (* control_xfer_cb ) (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
5050
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
51-
void (* sof_isr ) (uint8_t rhport, uint32_t frame_count); // optional
51+
void (* sof ) (uint8_t rhport, uint32_t frame_count); // optional
5252
} usbd_class_driver_t;
5353

5454
// Invoked when initializing device stack to get additional class drivers.

src/host/usbh.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ typedef struct {
125125
// Invalid driver ID in itf2drv[] ep2drv[][] mapping
126126
enum { DRVID_INVALID = 0xFFu };
127127
enum { ADDR_INVALID = 0xFFu };
128+
enum { CONTROLLER_INVALID = 0xFFu };
128129

129130
#if CFG_TUSB_DEBUG >= 2
130131
#define DRIVER_NAME(_name) .name = _name,
@@ -203,7 +204,7 @@ enum { CONFIG_NUM = 1 }; // default to use configuration 1
203204
// sum of end device + hub
204205
#define TOTAL_DEVICES (CFG_TUH_DEVICE_MAX + CFG_TUH_HUB)
205206

206-
static bool _usbh_initialized = false;
207+
static uint8_t _usbh_controller = CONTROLLER_INVALID;
207208

208209
// Device with address = 0 for enumeration
209210
static usbh_dev0_t _dev0;
@@ -280,8 +281,8 @@ void osal_task_delay(uint32_t msec)
280281
{
281282
(void) msec;
282283

283-
const uint32_t start = hcd_frame_number(TUH_OPT_RHPORT);
284-
while ( ( hcd_frame_number(TUH_OPT_RHPORT) - start ) < msec ) {}
284+
const uint32_t start = hcd_frame_number(_usbh_controller);
285+
while ( ( hcd_frame_number(_usbh_controller) - start ) < msec ) {}
285286
}
286287
#endif
287288

@@ -335,15 +336,15 @@ static void clear_device(usbh_device_t* dev)
335336

336337
bool tuh_inited(void)
337338
{
338-
return _usbh_initialized;
339+
return _usbh_controller != CONTROLLER_INVALID;
339340
}
340341

341-
bool tuh_init(uint8_t rhport)
342+
bool tuh_init(uint8_t controller_id)
342343
{
343344
// skip if already initialized
344-
if (_usbh_initialized) return _usbh_initialized;
345+
if ( tuh_inited() ) return true;
345346

346-
TU_LOG2("USBH init rhport %u\r\n", rhport);
347+
TU_LOG2("USBH init on controller %u\r\n", controller_id);
347348
TU_LOG2_INT(sizeof(usbh_device_t));
348349
TU_LOG2_INT(sizeof(hcd_event_t));
349350
TU_LOG2_INT(sizeof(_ctrl_xfer));
@@ -376,10 +377,11 @@ bool tuh_init(uint8_t rhport)
376377
usbh_class_drivers[drv_id].init();
377378
}
378379

379-
TU_ASSERT(hcd_init(rhport));
380-
hcd_int_enable(rhport);
380+
_usbh_controller = controller_id;;
381+
382+
TU_ASSERT(hcd_init(controller_id));
383+
hcd_int_enable(controller_id);
381384

382-
_usbh_initialized = true;
383385
return true;
384386
}
385387

@@ -721,13 +723,13 @@ uint8_t* usbh_get_enum_buf(void)
721723

722724
void usbh_int_set(bool enabled)
723725
{
724-
// TODO all host controller
726+
// TODO all host controller if multiple is used
725727
if (enabled)
726728
{
727-
hcd_int_enable(TUH_OPT_RHPORT);
729+
hcd_int_enable(_usbh_controller);
728730
}else
729731
{
730-
hcd_int_disable(TUH_OPT_RHPORT);
732+
hcd_int_disable(_usbh_controller);
731733
}
732734
}
733735

@@ -1238,14 +1240,15 @@ static void process_enumeration(tuh_xfer_t* xfer)
12381240

12391241
#if 0
12401242
case ENUM_RESET_2:
1241-
// XXX note used by now, but may be needed for some devices !?
1243+
// TODO not used by now, but may be needed for some devices !?
12421244
// Reset device again before Set Address
12431245
TU_LOG2("Port reset2 \r\n");
12441246
if (_dev0.hub_addr == 0)
12451247
{
12461248
// connected directly to roothub
12471249
hcd_port_reset( _dev0.rhport );
1248-
osal_task_delay(RESET_DELAY);
1250+
osal_task_delay(RESET_DELAY); // TODO may not work for no-OS on MCU that require reset_end() since
1251+
// sof of controller may not running while reseting
12491252
hcd_port_reset_end(_dev0.rhport);
12501253
// TODO: fall through to SET ADDRESS, refactor later
12511254
}
@@ -1364,7 +1367,8 @@ static bool enum_new_device(hcd_event_t* event)
13641367
// connected/disconnected directly with roothub
13651368
// wait until device is stable TODO non blocking
13661369
hcd_port_reset(_dev0.rhport);
1367-
osal_task_delay(RESET_DELAY);
1370+
osal_task_delay(RESET_DELAY); // TODO may not work for no-OS on MCU that require reset_end() since
1371+
// sof of controller may not running while reseting
13681372
hcd_port_reset_end( _dev0.rhport);
13691373

13701374
// device unplugged while delaying

src/host/usbh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr);
9595
// Should be called before tuh_init()
9696
// - cfg_id : configure ID (TBD)
9797
// - cfg_param: configure data, structure depends on the ID
98-
bool tuh_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param);
98+
bool tuh_configure(uint8_t controller_id, uint32_t cfg_id, const void* cfg_param);
9999

100100
// Init host stack
101-
bool tuh_init(uint8_t rhport);
101+
bool tuh_init(uint8_t controller_id);
102102

103103
// Check if host stack is already initialized
104104
bool tuh_inited(void);

src/tusb_option.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define _TUSB_OPTION_H_
2929

3030
// To avoid GCC compiler warnings when -pedantic option is used (strict ISO C)
31-
typedef int make_iso_compilers_happy ;
31+
typedef int make_iso_compilers_happy;
3232

3333
#include "common/tusb_compiler.h"
3434

@@ -217,6 +217,9 @@ typedef int make_iso_compilers_happy ;
217217
#define CFG_TUD_MAX_SPEED (TUD_RHPORT_MODE & OPT_MODE_SPEED_MASK)
218218
#endif
219219

220+
// For backward compatible
221+
#define TUSB_OPT_DEVICE_ENABLED CFG_TUD_ENABLED
222+
220223
// highspeed support indicator
221224
#define TUD_OPT_HIGH_SPEED (CFG_TUD_MAX_SPEED ? CFG_TUD_MAX_SPEED : TUP_RHPORT_HIGHSPEED)
222225

@@ -230,7 +233,6 @@ typedef int make_iso_compilers_happy ;
230233
#define TUH_OPT_RHPORT 1
231234
#else
232235
#define TUH_RHPORT_MODE OPT_MODE_NONE
233-
#define TUH_OPT_RHPORT -1
234236
#endif
235237

236238
#ifndef CFG_TUH_ENABLED
@@ -244,7 +246,6 @@ typedef int make_iso_compilers_happy ;
244246
#endif
245247

246248
// For backward compatible
247-
#define TUSB_OPT_DEVICE_ENABLED CFG_TUD_ENABLED
248249
#define TUSB_OPT_HOST_ENABLED CFG_TUH_ENABLED
249250

250251
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)