Skip to content

Commit

Permalink
drv/ioport_lpf2: add boot power quirk
Browse files Browse the repository at this point in the history
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: pybricks/support#747
  • Loading branch information
dlech committed Jun 2, 2023
1 parent 961f2b4 commit 53d3869
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/pbio/drv/ioport/ioport_lpf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions lib/pbio/platform/city_hub/pbdrvconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 53d3869

Please sign in to comment.