Skip to content

Commit 05db6ee

Browse files
committed
fix bad xfer_result_t enum values
shared-module/usb/core/Device.c was using its own 0xff value for the xfer_result_t enum defined by tinyusb/src/common/tusb_types.h. The 0xff value served the same purpose as the already exisiting XFER_RESULT_INVALID enum value (a placeholder to mark in-progress transactions). This commit standardizes on XFER_RESULT_INVALID in usb.core.Device consistent with the usage in tinyusb. Making this change allows implementing `switch(result){...}` style result code checks without compiler errors about 0xff not being a valid value for the enum.
1 parent 17ea151 commit 05db6ee

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

shared-module/usb/core/Device.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t d
4545
}
4646
self->device_address = device_address;
4747
self->first_langid = 0;
48-
_xfer_result = 0xff;
48+
_xfer_result = XFER_RESULT_INVALID;
4949
return true;
5050
}
5151

@@ -91,13 +91,13 @@ static void _transfer_done_cb(tuh_xfer_t *xfer) {
9191

9292
static bool _wait_for_callback(void) {
9393
while (!mp_hal_is_interrupted() &&
94-
_xfer_result == 0xff) {
94+
_xfer_result == XFER_RESULT_INVALID) {
9595
// The background tasks include TinyUSB which will call the function
9696
// we provided above. In other words, the callback isn't in an interrupt.
9797
RUN_BACKGROUND_TASKS;
9898
}
9999
xfer_result_t result = _xfer_result;
100-
_xfer_result = 0xff;
100+
_xfer_result = XFER_RESULT_INVALID;
101101
return result == XFER_RESULT_SUCCESS;
102102
}
103103

@@ -225,7 +225,7 @@ void common_hal_usb_core_device_set_configuration(usb_core_device_obj_t *self, m
225225
}
226226

227227
static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) {
228-
_xfer_result = 0xff;
228+
_xfer_result = XFER_RESULT_INVALID;
229229
xfer->complete_cb = _transfer_done_cb;
230230
if (!tuh_edpt_xfer(xfer)) {
231231
mp_raise_usb_core_USBError(NULL);
@@ -234,7 +234,7 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) {
234234
uint32_t start_time = supervisor_ticks_ms32();
235235
while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) &&
236236
!mp_hal_is_interrupted() &&
237-
_xfer_result == 0xff) {
237+
_xfer_result == XFER_RESULT_INVALID) {
238238
// The background tasks include TinyUSB which will call the function
239239
// we provided above. In other words, the callback isn't in an interrupt.
240240
RUN_BACKGROUND_TASKS;
@@ -244,11 +244,11 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) {
244244
return 0;
245245
}
246246
xfer_result_t result = _xfer_result;
247-
_xfer_result = 0xff;
247+
_xfer_result = XFER_RESULT_INVALID;
248248
if (result == XFER_RESULT_STALLED) {
249249
mp_raise_usb_core_USBError(MP_ERROR_TEXT("Pipe error"));
250250
}
251-
if (result == 0xff) {
251+
if (result == XFER_RESULT_INVALID) {
252252
tuh_edpt_abort_xfer(xfer->daddr, xfer->ep_addr);
253253
mp_raise_usb_core_USBTimeoutError();
254254
}
@@ -355,7 +355,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
355355
.complete_cb = _transfer_done_cb,
356356
};
357357

358-
_xfer_result = 0xff;
358+
_xfer_result = XFER_RESULT_INVALID;
359359

360360
if (!tuh_control_xfer(&xfer)) {
361361
mp_raise_usb_core_USBError(NULL);
@@ -364,7 +364,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
364364
uint32_t start_time = supervisor_ticks_ms32();
365365
while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) &&
366366
!mp_hal_is_interrupted() &&
367-
_xfer_result == 0xff) {
367+
_xfer_result == XFER_RESULT_INVALID) {
368368
// The background tasks include TinyUSB which will call the function
369369
// we provided above. In other words, the callback isn't in an interrupt.
370370
RUN_BACKGROUND_TASKS;
@@ -374,11 +374,11 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
374374
return 0;
375375
}
376376
xfer_result_t result = _xfer_result;
377-
_xfer_result = 0xff;
377+
_xfer_result = XFER_RESULT_INVALID;
378378
if (result == XFER_RESULT_STALLED) {
379379
mp_raise_usb_core_USBError(MP_ERROR_TEXT("Pipe error"));
380380
}
381-
if (result == 0xff) {
381+
if (result == XFER_RESULT_INVALID) {
382382
tuh_edpt_abort_xfer(xfer.daddr, xfer.ep_addr);
383383
mp_raise_usb_core_USBTimeoutError();
384384
}

0 commit comments

Comments
 (0)