Skip to content

UART

A universal asynchronous receiver-transmitter (UART) is a peripheral device for asynchronous serial communication.

MiraOS currently only supports using one UART.

Defines

MIRA_IODEF_UART0

#define MIRA_IODEF_UART0

MIRA_IODEF_UART1

#define MIRA_IODEF_UART1

MIRA_IODEF_UART2

#define MIRA_IODEF_UART2

MIRA_IODEF_UART

#define MIRA_IODEF_UART(_ID)

Types

mira_uart_input_callback_t

typedef int(* mira_uart_input_callback_t) (uint8_t c, void *storage);

Enums

mira_uart_parity_t

Name Description
MIRA_UART_PARITY_NONE
MIRA_UART_PARITY_EVEN
MIRA_UART_PARITY_ODD

Structs

mira_uart_config_t

Name Type Description
baudrate int32_t
tx_pin mira_gpio_pin_t Pin to use as TXD
rx_pin mira_gpio_pin_t Pin to use as RXD
parity mira_uart_parity_t Please note: Parity is not yet supported

Functions

mira_uart_init

mira_status_t mira_uart_init(uint8_t uart_id, const mira_uart_config_t *config);

Initialize a UART module.

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. Only UART 0 is supported.

Parameters

Name Description
uart_id The index of the UART peripheral.
config Pointer to a configuration to setup.

Return value

Name 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

Name 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 value

Name Description
MIRA_SUCCESS The callback was successfully set.