Out-of-office display, GFX
|
UART driver with a simple input parser. More...
Files | |
file | uartDriver.h |
Classes | |
struct | command |
Command that will execute a callback function when recongised. More... |
Macros | |
#define | UART_RX_RINGBUFFER_SIZE 20 |
Size of UART receive ring buffer. | |
#define | UART_ENABLE_INPUT_PARSER |
Enable the input parser. | |
#define | UART_CMD_ARG_LEN 10 |
Maximum argument length, including whitespace. |
Functions | |
void | uart_init (struct command *commands, size_t numCommands) |
Initialise the UART module and redirect stdout to it. | |
void | uart_runCmdCallbacks () |
Run command callbaks. | |
size_t | uart_copyBuffer (char *buffer, size_t len) |
Copy contents of receive buffer into supplied array. |
UART driver with a simple input parser.
This module performs a primitive hard-coded UART initialisation and optionally supports a string parser for received UART data. For every received newline, input is compared against a list of recognised commands. If a command is recognised, a callback is executed. The callback is given the sequence of characters between the recognised command string and terminating newline as an argument.
#define UART_RX_RINGBUFFER_SIZE 20 |
Size of UART receive ring buffer.
This buffer must be large enough to contain the longest command string, the optional argument and any allowed whitespace in between. It must also hold the newline character.
size_t uart_copyBuffer | ( | char * | buffer, |
size_t | len | ||
) |
Copy contents of receive buffer into supplied array.
buffer | array to copy data into. |
len | length of array. |
void uart_init | ( | struct command * | commands, |
size_t | numCommands | ||
) |
Initialise the UART module and redirect stdout to it.
This function initialises a specific UART module (already pin-assigned) with a hard-coded baud rate of 115,200. A list of commands that will be compared against received data can optionally be given. The list will be traversed, and all the command strings will be compared against the contents of the UART receive buffer every time a newline is read.
commands | array of valid commands, which triggers callback functions if the command is recongised. |
numCommands | number of items in commands array |
void uart_runCmdCallbacks | ( | ) |
Run command callbaks.
If a newline has been received since last time this function was called, the contents of the receive buffer will be compared against the registered commands. The first recongised command string will have its callback executed with arguments retrieved from the remaining characters in the buffer.
Call this function repeatedly to check whether a newline has entered the buffer.