-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pbio/drv/uart: Refactor async read and write #275
base: master
Are you sure you want to change the base?
Changes from all commits
f7e5bf1
e04f9b1
046af37
12d1bc4
da71e11
ffb60af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2024 The Pybricks Authors | ||
|
||
// Internal common adc functions. | ||
|
||
#ifndef _INTERNAL_PBDRV_ADC_H_ | ||
#define _INTERNAL_PBDRV_ADC_H_ | ||
|
||
#include <pbdrv/config.h> | ||
|
||
#if PBDRV_CONFIG_ADC | ||
|
||
void pbdrv_adc_init(void); | ||
|
||
#else // PBDRV_CONFIG_ADC | ||
|
||
#define pbdrv_adc_init() | ||
|
||
#endif // PBDRV_CONFIG_ADC | ||
|
||
#endif // _INTERNAL_PBDRV_ADC_H_ |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#include <contiki.h> | ||
|
||
#include <pbdrv/gpio.h> | ||
#include <pbdrv/uart.h> | ||
|
||
#include <pbsys/status.h> | ||
|
||
|
@@ -107,6 +108,11 @@ static void legodev_pup_enable_uart(const pbdrv_ioport_pup_pins_t *pins) { | |
pbdrv_gpio_out_low(&pins->uart_buf); | ||
} | ||
|
||
static void legodev_pup_disable_uart(const pbdrv_ioport_pup_pins_t *pins) { | ||
// REVISIT: Move to ioport. | ||
pbdrv_gpio_out_high(&pins->uart_buf); | ||
} | ||
|
||
// This is the device connection manager (dcm). It monitors the ID1 and ID2 pins | ||
// on the port to see when devices are connected or disconnected. | ||
// It is expected for there to be a 2ms delay between calls to this function. | ||
|
@@ -343,6 +349,7 @@ static PT_THREAD(pbdrv_legodev_pup_thread(ext_dev_t * dev)) { | |
while (true) { | ||
|
||
// Initially assume nothing is connected. | ||
legodev_pup_disable_uart(dev->pins); | ||
dev->dcm.connected_type_id = PBDRV_LEGODEV_TYPE_ID_NONE; | ||
dev->dcm.dev_id_match_count = 0; | ||
|
||
|
@@ -369,6 +376,7 @@ static PT_THREAD(pbdrv_legodev_pup_thread(ext_dev_t * dev)) { | |
// disconnects, as observed by the UART process not getting valid data. | ||
legodev_pup_enable_uart(dev->pins); | ||
PT_SPAWN(&dev->pt, &dev->child, pbdrv_legodev_pup_uart_thread(&dev->child, dev->uart_dev)); | ||
|
||
} | ||
PT_END(&dev->pt); | ||
} | ||
|
@@ -405,6 +413,14 @@ PROCESS_THREAD(pbio_legodev_pup_process, ev, data) { | |
PROCESS_END(); | ||
} | ||
|
||
/** | ||
* We get notified when the uart driver has completed sending or receiving data. | ||
*/ | ||
static void uart_poll_callback(pbdrv_uart_dev_t *uart) { | ||
// REVISIT: Only need to poll the specified uart device. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a flag that gets set here so that we only poke the uart instances that need it in the poll handler. |
||
process_poll(&pbio_legodev_pup_process); | ||
} | ||
|
||
void pbdrv_legodev_init(void) { | ||
#if PBDRV_CONFIG_LEGODEV_PUP_NUM_INT_DEV > 0 | ||
for (uint8_t i = 0; i < PBDRV_CONFIG_LEGODEV_PUP_NUM_INT_DEV; i++) { | ||
|
@@ -431,7 +447,15 @@ void pbdrv_legodev_init(void) { | |
pbio_dcmotor_get_dcmotor(legodev, &dcmotor); | ||
legodev->ext_dev->uart_dev = pbdrv_legodev_pup_uart_configure(legodev_data->ioport_index, port_data->uart_driver_index, dcmotor); | ||
|
||
// legodev driver is started after all other drivers, so we | ||
// assume that we do not need to wait for this to be ready. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add an assert statement here so that we could at least catch this in debug builds to catch future changes that might break this assumption. |
||
pbdrv_uart_dev_t *uart; | ||
pbdrv_uart_get(port_data->uart_driver_index, &uart); | ||
|
||
// Set callback for uart driver. | ||
pbdrv_uart_set_poll_callback(uart, uart_poll_callback); | ||
} | ||
|
||
process_start(&pbio_legodev_pup_process); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't dig into it, but this looks suspect to me. It seems like this could interfere with the device detection code that expects pins to be in a certain state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the behavior is/was:
I think the uart (buffer) is disabled initially, so in the current case the second pass was not the same as the first. Setting it back to disabled was intended to take care of your suspicion 😄
On closer look, it seems that the DCM immediately sets the buffer state again so it doesn't currently seem to make any difference.
The goal is to eventually get this into a multimodal port interface, where
legodev
is one of several options.