Skip to content

Commit 274f66a

Browse files
committed
pbio/drv/usb_stm32: Simplify event loop and use pbio/os.
BCD and data handling happen separately, so we can have them chronologically in the process thread. Also fix a revisit note for not needing a timer to resend the status. Since we recently introduced status scheduling by the host module, we can just re-schedule the latest on subscribing. Also introduce shutting down via pbdrv_deinit rather than polling statuses from pbsys.
1 parent 76893f6 commit 274f66a

File tree

5 files changed

+184
-169
lines changed

5 files changed

+184
-169
lines changed

lib/pbio/drv/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ void pbdrv_deinit(void) {
9090
pbdrv_imu_deinit();
9191
pbdrv_bluetooth_deinit();
9292
pbdrv_button_deinit();
93+
pbdrv_usb_deinit();
9394

9495
while (pbio_busy_count_busy()) {
9596
pbio_os_run_processes_and_wait_for_event();

lib/pbio/drv/usb/usb.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
#if PBDRV_CONFIG_USB
1212

1313
/**
14-
* Initializes the USB driver.
14+
* Initializes the USB driver on boot.
1515
*/
1616
void pbdrv_usb_init(void);
1717

18+
/**
19+
* De-initializes the USB driver for data transfers on soft-poweroff. Keeps charging if supported.
20+
*/
21+
void pbdrv_usb_deinit(void);
22+
1823
#else // PBDRV_CONFIG_USB
1924

2025
#define pbdrv_usb_init()
26+
#define pbdrv_usb_deinit()
2127

2228
#endif // PBDRV_CONFIG_USB
2329

lib/pbio/drv/usb/usb_ev3.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ void pbdrv_usb_init(void) {
11101110
pbio_os_process_start(&pbdrv_usb_ev3_process, pbdrv_usb_ev3_process_thread, NULL);
11111111
}
11121112

1113+
void pbdrv_usb_deinit(void) {
1114+
// todo
1115+
}
1116+
11131117
pbdrv_usb_bcd_t pbdrv_usb_get_bcd(void) {
11141118
// This function is not used on EV3
11151119
return PBDRV_USB_BCD_NONE;

lib/pbio/drv/usb/usb_nxt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,10 @@ void pbdrv_usb_init(void) {
852852
*AT91C_PIOA_CODR = (1 << 16);
853853
}
854854

855+
void pbdrv_usb_deinit(void) {
856+
// todo
857+
}
858+
855859
bool nx_usb_can_write(void) {
856860
return pbdrv_usb_nxt_state.status == USB_READY;
857861
}

0 commit comments

Comments
 (0)