Core
Loading...
Searching...
No Matches
usart.h
Go to the documentation of this file.
1
21#ifndef CORE_USART_H
22#define CORE_USART_H
23
24#include <stdint.h>
25#include <stdbool.h>
26#include <stm32g4xx_hal.h>
27#include "core_config.h"
28
29#define CORE_USART1_UPDATE 0x01
30#define CORE_USART2_UPDATE 0x02
31#define CORE_USART3_UPDATE 0x04
32
33typedef struct core_USART_module_s {
34 UART_HandleTypeDef husart;
35 uint8_t rxbuf_int[CORE_USART_RXBUFLEN];
36 uint32_t rxbuflen_int;
37 void (*callback)(uint8_t *, uint32_t);
39
48bool core_USART_init(USART_TypeDef *usart, uint32_t baud);
49
60bool core_USART_transmit(USART_TypeDef *usart, uint8_t *txbuf, uint8_t txbuflen);
61
71bool core_USART_register_callback(USART_TypeDef *usart, void (*callback)(uint8_t *, uint32_t));
72
83uint32_t core_USART_receive(USART_TypeDef *usart, uint8_t *rxbuf, uint32_t rxbuflen, uint32_t timeout);
84
85#if (CORE_USART_UPRINTF != 0) || defined(DOXYGEN)
97int uprintf(USART_TypeDef *usart, const char *format, ...);
98#endif
99
100#endif
Configuration file for the core library.
#define CORE_USART_RXBUFLEN
Size of the internal RX buffer. One buffer will be created for each USART module.
Definition core_config.h:226
Definition usart.h:33
bool core_USART_init(USART_TypeDef *usart, uint32_t baud)
Initialize a USART module in asynchronous mode with the given baud rate.
Definition usart.c:54
bool core_USART_transmit(USART_TypeDef *usart, uint8_t *txbuf, uint8_t txbuflen)
Transmit data from a USART.
Definition usart.c:184
bool core_USART_register_callback(USART_TypeDef *usart, void(*callback)(uint8_t *, uint32_t))
Set the RX callback and start the receiver for the given USART module.
Definition usart.c:128
int uprintf(USART_TypeDef *usart, const char *format,...)
Print a formatted string to a USART.
Definition usart.c:193
uint32_t core_USART_receive(USART_TypeDef *usart, uint8_t *rxbuf, uint32_t rxbuflen, uint32_t timeout)
Synchronously receive data from a USART.
Definition usart.c:203