Skip to content

Commit

Permalink
drv/ioport_lpf2: fix improper device detection
Browse files Browse the repository at this point in the history
Occasionally, I/O devices would be improperly detected when plugged in
while the hub is already turned on. For example, a medium motor (id 1)
would be detected as a light (id 8). This points to a pull down resistor
on the ID2 pin not being properly detected. This could be due to some
internal capacitance causing it to take longer than 2 ms for the voltage
to drop low enough to be detected as logic low after voltage is changed
from high to low on the pin. By driving the detection pin low, we give
it a boost in the right direction to improve the chances of proper
detection.

Fixes: pybricks/support#500
  • Loading branch information
dlech committed Nov 18, 2021
1 parent 0a120b8 commit a6ef025
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
- Fixed `brake()`/`light.off()` not working on Move hub I/O port C ([support#501]).
- Fixed `Remote()` failing to connect when hub is connected to 2019 or newer
MacBooks ([support#397]).
- Fixed intermittent improper detection of hot-plugged I/O devices ([support#500]).

[support#366]: https://github.com/pybricks/support/issues/366
[support#397]: https://github.com/pybricks/support/issues/397
[support#500]: https://github.com/pybricks/support/issues/500
[support#501]: https://github.com/pybricks/support/issues/501

## [3.1.0b1] - 2021-09-21
Expand Down
7 changes: 7 additions & 0 deletions lib/pbio/drv/ioport/ioport_lpf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ static PT_THREAD(poll_dcm(ioport_dev_t * ioport)) {
// set ID2 low
pbdrv_gpio_out_low(&pdata.id2);

// There must be some capacitance in the circuit because the
// uart_rx pin seems to need some extra help being driven low.
// Otherwise, pbdrv_gpio_input(&pdata.uart_rx) below can
// sometimes read the wrong value, resulting in improper
// detection.
pbdrv_gpio_out_low(&pdata.uart_rx);

PT_YIELD(pt);

// if ID2 is low
Expand Down

0 comments on commit a6ef025

Please sign in to comment.