-
-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
[Core] Split ChibiOS usart split driver in protocol and hardware driver part #16669
Conversation
This depends on the other prs mentioned, correct? |
Correct :-) |
55dcd56
to
6b2e599
Compare
6b2e599
to
469df31
Compare
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've used this PR for a "quick-and-dirty" implementation of an FDCAN-driver.
The given serial_protocol-
driver interface is simple and creating my own implementation worked just fine.
(see preisi@c91e6b5)
f8011bc
to
315fbd8
Compare
@preisi Thanks for the feedback and recommendations, I integrated those 👍 |
a6332ee
to
a070158
Compare
Two notable changes that might be missed in review:
from uint8_t dump[size];
return receive(dump, size); to uint8_t dump[64];
size_t bytes_left = size;
while (unlikely(bytes_left > 64)) {
if (unlikely(!receive(dump, 64))) {
return false;
}
bytes_left -= 64;
}
receive(dump, bytes_left); |
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.
Looks good to me
size_t bytes_left = size; | ||
|
||
while (unlikely(bytes_left > 64)) { | ||
if (unlikely(!receive(dump, 64))) { |
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.
Will need to #include "util.h"
if it's not already present.
if (unlikely(!receive(dump, 64))) { | |
if (unlikely(!receive(dump, MIN(bytes_left, 64)))) { |
Prevents reading extra if the slave just happens to respond within SERIAL_USART_TIMEOUT
.
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 don't think that change is correct? This branch will only be executed if bytes_left > 64
so we can safely always read 64 byte. But I could make the condition bytes_left >= 64
.
bool __attribute__((nonnull, hot)) receive(uint8_t* destination, const size_t size); | ||
|
||
/** | ||
* @brief Blocking receive of size * bytes with an implicitly defined timeout. | ||
* | ||
* @return true Receive success. | ||
* @return false Receive failed, e.g. by timeout or bit errors. | ||
*/ | ||
bool __attribute__((nonnull, hot)) receive_blocking(uint8_t* destination, const size_t size); | ||
|
||
/** | ||
* @brief Blocking send of buffer with timeout. | ||
* | ||
* @return true Send success. | ||
* @return false Send failed, e.g. by timeout or bit errors. | ||
*/ | ||
bool __attribute__((nonnull, hot)) send(const uint8_t* source, const size_t size); |
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.
Kiiiiiinda allergic to generic names like these.
What about:
receive
=>serial_transport_receive
receive_blocking
=>serial_transport_receive_blocking
send
=>serial_transport_send
......just don't get me started about the naming of serial.
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.
Ah yes, forgot about C-style namespacing. Will apply that.
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.
Done, applied the prefix to all public methods that are part of the protocol.
a070158
to
d3e5ff3
Compare
d3e5ff3
to
f3b24f7
Compare
0fa88da
to
fd34cdd
Compare
51832ee
to
293ecbf
Compare
This allows other means of split communication to be implemented by simply implementing the driver specific methods used in the serial protocol.
293ecbf
to
7d5cb5e
Compare
This PR builds upon #15907 and #16647 for review please ignore the commits belonging to these.
Description
Goal of this PR is to re-use the protocol logic of the existing ChibiOS usart driver for other means of transportation. Drivers implementing the protocol just need to provide the following methods to work:
The first successful use-case is the usage of the PIO peripheral on the RP2040 MCU to implement Half-duplex and Full-duplex UART split keyboard communication.
I have tested these changes successfully with both SIO, SERIAL and PIO drivers.
Types of Changes
Issues Fixed or Closed by This PR
Checklist