From 53d38690686883d924bd6d21324174ba2f168a2e Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 1 Jun 2023 11:44:25 -0500 Subject: [PATCH] drv/ioport_lpf2: add boot power quirk The city hub powers on the I/O ports (pin 4) during boot, so by the time the device connection manager detected a UART device, in many cases, it was too late to catch the device on the first sync. In the case of the BOOST color distance sensor, this meant waiting 10 seconds instead of 5 for the sensor to be ready. This adds an option to enable a workaround for the quirk that cycles power to the I/O ports immediately after boot. This is faster than waiting for the next sync cycle. Issue: https://github.com/pybricks/support/issues/747 --- lib/pbio/drv/ioport/ioport_lpf2.c | 14 ++++++++++++-- lib/pbio/platform/city_hub/pbdrvconfig.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/pbio/drv/ioport/ioport_lpf2.c b/lib/pbio/drv/ioport/ioport_lpf2.c index e609e0b51..d2c2be652 100644 --- a/lib/pbio/drv/ioport/ioport_lpf2.c +++ b/lib/pbio/drv/ioport/ioport_lpf2.c @@ -466,15 +466,25 @@ PROCESS_THREAD(pbdrv_ioport_lpf2_process, ev, data) { PROCESS_BEGIN(); - etimer_set(&timer, 2); - for (int i = 0; i < PBDRV_CONFIG_IOPORT_LPF2_NUM_PORTS; i++) { init_one(i); } + // Some hubs turn on power to the I/O ports in the bootloader. This causes + // UART sync delays after boot. It is faster to power cycle the I/O devices + // than it is to wait for long sync in most cases. + #if PBDRV_CONFIG_IOPORT_LPF2_BOOT_POWER_QUIRK + pbdrv_gpio_out_low(&pbdrv_ioport_lpf2_platform_data.port_vcc); + + etimer_set(&timer, 500); + PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)); + #endif + // Turn on power on pin 4 on all ports pbdrv_gpio_out_high(&pbdrv_ioport_lpf2_platform_data.port_vcc); + etimer_set(&timer, 2); + for (;;) { PROCESS_WAIT_EVENT(); diff --git a/lib/pbio/platform/city_hub/pbdrvconfig.h b/lib/pbio/platform/city_hub/pbdrvconfig.h index bc1de204a..3a3327e90 100644 --- a/lib/pbio/platform/city_hub/pbdrvconfig.h +++ b/lib/pbio/platform/city_hub/pbdrvconfig.h @@ -48,6 +48,7 @@ #define PBDRV_CONFIG_IOPORT (1) #define PBDRV_CONFIG_IOPORT_LPF2 (1) #define PBDRV_CONFIG_IOPORT_LPF2_NUM_PORTS (2) +#define PBDRV_CONFIG_IOPORT_LPF2_BOOT_POWER_QUIRK (1) #define PBDRV_CONFIG_IOPORT_LPF2_FIRST_PORT PBIO_PORT_ID_A #define PBDRV_CONFIG_IOPORT_LPF2_LAST_PORT PBIO_PORT_ID_B