UART¶
A universal asynchronous receiver-transmitter (UART) is a peripheral device for asynchronous serial communication.
MiraOS supports independent operation of multiple UARTs.
Defines¶
| Name | Value | Description | 
|---|---|---|
| MIRA_IODEF_UART0 | { miraint_uart_read, miraint_uart_write, 0 } | |
| MIRA_IODEF_UART1 | { miraint_uart_read, miraint_uart_write, 1 } | |
| MIRA_IODEF_UART2 | { miraint_uart_read, miraint_uart_write, 2 } | |
| MIRA_IODEF_UART(_ID) | { miraint_uart_read, miraint_uart_write, (_ID) } | 
Types¶
| Name | Type | Description | 
|---|---|---|
| mira_uart_input_callback_t | int(* )(uint8_t c, void *storage) | 
Enums¶
mira_uart_parity_t¶
| Name | Value | Description | 
|---|---|---|
| MIRA_UART_PARITY_NONE | ||
| MIRA_UART_PARITY_EVEN | ||
| MIRA_UART_PARITY_ODD | 
Structs¶
mira_uart_config_t¶
| Type | Name | Description | 
|---|---|---|
| int32_t | baudrate | |
| mira_gpio_pin_t | tx_pin | Pin to use as TXD | 
| mira_gpio_pin_t | rx_pin | Pin to use as RXD | 
| mira_uart_parity_t | parity | 
Functions¶
mira_uart_init¶
mira_status_t mira_uart_init( uint8_t uart_id, const mira_uart_config_t* config);
Initialize a UART module. Initializes the UART module of ID uart_id. The custom config is passed as a parameter (NULL for platform default).
Note: this might start a higher resolution clock in the CPU, which can significantly increase the power consumption until CPU is restarted.
Parameters
| Parameter | Description | 
|---|---|
| uart_id | The index of the UART peripheral. | 
| config | Pointer to a configuration to setup. | 
Return
See the enum definition.
| Value | Description | 
|---|---|
| MIRA_SUCCESS | UART was successfully initialized. | 
| MIRA_UART_ERROR_INIT | UART could not initialize. | 
| MIRA_ERROR_NOT_SUPPORTED | Invalid UART id. | 
mira_uart_set_input_callback¶
mira_status_t mira_uart_set_input_callback( uint8_t uart_id, mira_uart_input_callback_t cb, void* storage);
Set a callback to be called on uart byte input.
Parameters
| Parameter | Description | 
|---|---|
| uart_id | The index of the UART peripheral. | 
| cb | The callback to call. | 
| storage | Storage pointer which is used to store optional information to be used by the callback function. E.g. it could be used as an identifier or to pass on a configuration struct. | 
Return
See the enum definition.
| Value | Description | 
|---|---|
| MIRA_SUCCESS | The callback was successfully set. |