Skip to content

Commit f39a6f4

Browse files
authored
Merge pull request #2009 from hathach/tinyusb-update
update tinyusb lib to 0.5.x
2 parents 82ab998 + 5d03cda commit f39a6f4

File tree

8 files changed

+89
-109
lines changed

8 files changed

+89
-109
lines changed

lib/tinyusb

Submodule tinyusb updated 496 files

ports/nrf/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ INC += -I./nrfx
8181
INC += -I./nrfx/hal
8282
INC += -I./nrfx/mdk
8383
INC += -I./nrfx/drivers/include
84+
INC += -I./nrfx/drivers/src
8485
INC += -I./bluetooth
8586
INC += -I./peripherals
8687
INC += -I../../lib/mp-readline

shared-module/usb_hid/Device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t*
4747

4848
// Wait until interface is ready, timeout = 2 seconds
4949
uint64_t end_ticks = ticks_ms + 2000;
50-
while ( (ticks_ms < end_ticks) && !tud_hid_generic_ready() ) { }
50+
while ( (ticks_ms < end_ticks) && !tud_hid_ready() ) { }
5151

52-
if ( !tud_hid_generic_ready() ) {
52+
if ( !tud_hid_ready() ) {
5353
mp_raise_msg(&mp_type_OSError, translate("USB Busy"));
5454
}
5555

5656
memcpy(self->report_buffer, report, len);
5757

58-
if ( !tud_hid_generic_report(self->report_id, self->report_buffer, len) ) {
58+
if ( !tud_hid_report(self->report_id, self->report_buffer, len) ) {
5959
mp_raise_msg(&mp_type_OSError, translate("USB Error"));
6060
}
6161
}
@@ -70,7 +70,7 @@ static usb_hid_device_obj_t* get_hid_device(uint8_t report_id) {
7070
}
7171

7272
// Callbacks invoked when receive Get_Report request through control endpoint
73-
uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
73+
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
7474
// only support Input Report
7575
if ( report_type != HID_REPORT_TYPE_INPUT ) return 0;
7676

@@ -80,7 +80,7 @@ uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t repo
8080
}
8181

8282
// Callbacks invoked when receive Set_Report request through control endpoint
83-
void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
83+
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
8484
usb_hid_device_obj_t* hid_device = get_hid_device(report_id);
8585

8686
if ( report_type == HID_REPORT_TYPE_OUTPUT ) {

shared-module/usb_midi/PortOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ size_t common_hal_usb_midi_portout_write(usb_midi_portout_obj_t *self, const uin
3333
}
3434

3535
bool common_hal_usb_midi_portout_ready_to_tx(usb_midi_portout_obj_t *self) {
36-
return tud_midi_connected();
36+
return tud_midi_mounted();
3737
}

supervisor/shared/usb/tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
// USB RAM PLACEMENT
108108
//--------------------------------------------------------------------+
109109
#define CFG_TUSB_ATTR_USBRAM
110-
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
110+
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
111111

112112

113113
#ifdef __cplusplus

supervisor/shared/usb/usb_desc.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,35 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "supervisor/shared/usb/usb_desc.h"
27+
#include "lib/tinyusb/src/tusb.h"
2828
#include "shared-module/usb_hid/Device.h"
2929

3030
#include "genhdr/autogen_usb_descriptor.h"
3131

32-
// tud_desc_set is required by tinyusb stack
33-
tud_desc_set_t tud_desc_set =
34-
{
35-
.device = &usb_desc_dev,
36-
.config = &usb_desc_cfg,
37-
.string_arr = (uint8_t const **) string_desc_arr,
38-
.string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]),
32+
// Invoked when received GET DEVICE DESCRIPTOR
33+
// Application return pointer to descriptor
34+
uint8_t const * tud_descriptor_device_cb(void) {
35+
return usb_desc_dev;
36+
}
3937

40-
.hid_report =
41-
{
42-
.generic = hid_report_descriptor,
43-
.boot_keyboard = NULL,
44-
.boot_mouse = NULL
45-
}
46-
};
38+
// Invoked when received GET CONFIGURATION DESCRIPTOR
39+
// Application return pointer to descriptor
40+
// Descriptor contents must exist long enough for transfer to complete
41+
uint8_t const * tud_descriptor_configuration_cb(uint8_t index) {
42+
(void) index; // for multiple configurations
43+
return usb_desc_cfg;
44+
}
45+
46+
// Invoked when received GET HID REPORT DESCRIPTOR
47+
// Application return pointer to descriptor
48+
// Descriptor contents must exist long enough for transfer to complete
49+
uint8_t const * tud_hid_descriptor_report_cb(void) {
50+
return hid_report_descriptor;
51+
}
52+
53+
// Invoked when received GET STRING DESCRIPTOR request
54+
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
55+
uint16_t const* tud_descriptor_string_cb(uint8_t index) {
56+
uint8_t const max_index = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]);
57+
return (index < max_index) ? string_desc_arr[index] : NULL;
58+
}

supervisor/shared/usb/usb_desc.h

Lines changed: 0 additions & 43 deletions
This file was deleted.

supervisor/shared/usb/usb_msc_flash.c

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -59,59 +59,18 @@ static fs_user_mount_t* get_vfs(int lun) {
5959
}
6060

6161
// Callback invoked when received an SCSI command not in built-in list below
62-
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
62+
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, TEST_UNIT_READY, START_STOP_UNIT, MODE_SENSE6, REQUEST_SENSE
6363
// - READ10 and WRITE10 have their own callbacks
6464
int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer, uint16_t bufsize) {
6565
const void* response = NULL;
6666
int32_t resplen = 0;
6767

6868
switch ( scsi_cmd[0] ) {
69-
case SCSI_CMD_TEST_UNIT_READY:
70-
// Command that host uses to check our readiness before sending other commands
71-
resplen = 0;
72-
if (lun > 1) {
73-
resplen = -1;
74-
} else {
75-
fs_user_mount_t* current_mount = get_vfs(lun);
76-
if (current_mount == NULL) {
77-
resplen = -1;
78-
}
79-
if (ejected[lun]) {
80-
resplen = -1;
81-
}
82-
}
83-
break;
84-
8569
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
8670
// Host is about to read/write etc ... better not to disconnect disk
8771
resplen = 0;
8872
break;
8973

90-
case SCSI_CMD_START_STOP_UNIT:
91-
{
92-
// Host try to eject/safe remove/poweroff us. We could safely disconnect with disk storage, or go into lower power
93-
const scsi_start_stop_unit_t* start_stop = (const scsi_start_stop_unit_t*) scsi_cmd;
94-
// Start bit = 0 : low power mode, if load_eject = 1 : unmount disk storage as well
95-
// Start bit = 1 : Ready mode, if load_eject = 1 : mount disk storage
96-
resplen = 0;
97-
if (start_stop->load_eject == 1) {
98-
if (lun > 1) {
99-
resplen = -1;
100-
} else {
101-
fs_user_mount_t* current_mount = get_vfs(lun);
102-
if (current_mount == NULL) {
103-
resplen = -1;
104-
}
105-
if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) {
106-
resplen = -1;
107-
} else {
108-
ejected[lun] = true;
109-
}
110-
}
111-
}
112-
}
113-
break;
114-
11574
default:
11675
// Set Sense = Invalid Command Operation
11776
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
@@ -127,7 +86,7 @@ int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer,
12786
}
12887

12988
// copy response to stack's buffer if any
130-
if ( response && resplen ) {
89+
if ( response && (resplen > 0) ) {
13190
memcpy(buffer, response, resplen);
13291
}
13392

@@ -206,3 +165,54 @@ void tud_msc_write10_complete_cb (uint8_t lun) {
206165
// This write is complete, start the autoreload clock.
207166
autoreload_start();
208167
}
168+
169+
// Invoked when received SCSI_CMD_INQUIRY
170+
// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
171+
void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) {
172+
(void) lun;
173+
174+
memcpy(vendor_id , CFG_TUD_MSC_VENDOR , strlen(CFG_TUD_MSC_VENDOR));
175+
memcpy(product_id , CFG_TUD_MSC_PRODUCT , strlen(CFG_TUD_MSC_PRODUCT));
176+
memcpy(product_rev, CFG_TUD_MSC_PRODUCT_REV, strlen(CFG_TUD_MSC_PRODUCT_REV));
177+
}
178+
179+
// Invoked when received Test Unit Ready command.
180+
// return true allowing host to read/write this LUN e.g SD card inserted
181+
bool tud_msc_test_unit_ready_cb(uint8_t lun) {
182+
if (lun > 1) {
183+
return false;
184+
}
185+
186+
fs_user_mount_t* current_mount = get_vfs(lun);
187+
if (current_mount == NULL) {
188+
return false;
189+
}
190+
if (ejected[lun]) {
191+
return false;
192+
}
193+
194+
return true;
195+
}
196+
197+
// Invoked when received Start Stop Unit command
198+
// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage
199+
// - Start = 1 : active mode, if load_eject = 1 : load disk storage
200+
bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) {
201+
if (load_eject) {
202+
if (lun > 1) {
203+
return false;
204+
} else {
205+
fs_user_mount_t* current_mount = get_vfs(lun);
206+
if (current_mount == NULL) {
207+
return false;
208+
}
209+
if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) {
210+
return false;
211+
} else {
212+
ejected[lun] = true;
213+
}
214+
}
215+
}
216+
217+
return true;
218+
}

0 commit comments

Comments
 (0)