Skip to content

Commit a5c6648

Browse files
committed
pbio/drv/usb: Disable work in progress in release builds.
USB is not finished yet, so we'll disable the work-in-progress developments until it is ready for beta testing. This lets us proceed with beta releases to test other functionality. Leaving it enabled without it actually working can cause unexpected lockups such as in lsusb or when writing stdout. Windows users may get notifications about Pybricks USB devices without it actually working or being documented yet.
1 parent 00b547b commit a5c6648

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

lib/pbio/drv/usb/usb_stm32.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ void pbdrv_usb_stm32_handle_vbus_irq(bool active) {
152152
* if this platform does not support USB.
153153
*/
154154
pbio_error_t pbdrv_usb_stdout_tx(const uint8_t *data, uint32_t *size) {
155+
#if PBDRV_CONFIG_USB_CHARGE_ONLY
156+
return PBIO_ERROR_NOT_IMPLEMENTED;
157+
#endif
158+
155159
uint8_t *ptr = usb_stdout_buf;
156160
uint32_t ptr_len = sizeof(usb_stdout_buf);
157161

@@ -258,7 +262,7 @@ static USBD_StatusTypeDef Pybricks_Itf_TransmitCplt(uint8_t *Buf, uint32_t Len,
258262
return ret;
259263
}
260264

261-
static USBD_Pybricks_ItfTypeDef USBD_Pybricks_fops = {
265+
USBD_Pybricks_ItfTypeDef USBD_Pybricks_fops = {
262266
.Init = Pybricks_Itf_Init,
263267
.DeInit = Pybricks_Itf_DeInit,
264268
.Receive = Pybricks_Itf_Receive,
@@ -272,11 +276,15 @@ void pbdrv_usb_init(void) {
272276
husbd.pData = &hpcd;
273277
hpcd.pData = &husbd;
274278

279+
#if PBDRV_CONFIG_USB_CHARGE_ONLY
280+
USBD_Init(&husbd, NULL, 0);
281+
#else
275282
USBD_Pybricks_Desc_Init();
276283
USBD_Init(&husbd, &USBD_Pybricks_Desc, 0);
277284
USBD_RegisterClass(&husbd, &USBD_Pybricks_ClassDriver);
278285
USBD_Pybricks_RegisterInterface(&husbd, &USBD_Pybricks_fops);
279286
USBD_Start(&husbd);
287+
#endif
280288

281289
process_start(&pbdrv_usb_process);
282290

@@ -332,6 +340,11 @@ PROCESS_THREAD(pbdrv_usb_process, ev, data) {
332340
}
333341
}
334342

343+
#if PBDRV_CONFIG_USB_CHARGE_ONLY
344+
// Communication logic skipped when charging only.
345+
continue;
346+
#endif
347+
335348
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_SHUTDOWN)) {
336349
if (pbio_oneshot(true, &pwrdn_oneshot)) {
337350
USBD_Stop(&husbd);

lib/pbio/platform/essential_hub/pbdrvconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
#define PBDRV_CONFIG_USB_MFG_STR LEGO_USB_MFG_STR
103103
#define PBDRV_CONFIG_USB_PROD_STR LEGO_USB_PROD_STR_TECHNIC_SMALL_HUB " + Pybricks"
104104
#define PBDRV_CONFIG_USB_STM32F4 (1)
105+
#define PBDRV_CONFIG_USB_CHARGE_ONLY (1)
105106

106107
#define PBDRV_CONFIG_STACK (1)
107108
#define PBDRV_CONFIG_STACK_EMBEDDED (1)

lib/pbio/platform/prime_hub/pbdrvconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
#define PBDRV_CONFIG_USB_PROD_STR LEGO_USB_PROD_STR_TECHNIC_LARGE_HUB " + Pybricks"
120120
#define PBDRV_CONFIG_USB_STM32F4 (1)
121121
#define PBDRV_CONFIG_USB_STM32F4_HUB_VARIANT_ADDR 0x08007d80
122+
#define PBDRV_CONFIG_USB_CHARGE_ONLY (1)
122123

123124
#define PBDRV_CONFIG_STACK (1)
124125
#define PBDRV_CONFIG_STACK_EMBEDDED (1)

0 commit comments

Comments
 (0)