Loading...
Searching...
No Matches
uart.h
1
8
9#ifndef _UART_H
10#define _UART_H
11
12#include "stdbool.h"
13#include "stm32f439xx.h"
14#include "string.h"
15
16#include "devices.h"
17#include "gpio.h"
18
19#define UART_PARITY_DISABLE 0x400
20#define UART_SYNC_DISABLE 0xE00
21#define UART_FLOW_DISABLE 0x300
22#define UART_ENABLE 0x2000
23#define UART_RX_ENABLE 0x0004
24#define UART_TX_ENABLE 0x0008
25#define UART_AF7 0x07
26#define UART_AF8 0x08
27
28#define SIGINT 0x03
29#define BACKSPACE 0x08
30#define LINE_FEED 0x0A
31#define CARRIAGE_RETURN 0x0D
32
39
40typedef enum {
41 OVER8,
42 OVER16
43} OversampleMode;
44
45typedef struct UART_Pins {
46 uint8_t TX;
47 uint8_t RX;
48} UART_Pins;
49
53typedef struct UART {
54 USART_TypeDef *interface;
55 GPIO_TypeDef *port;
56 UART_Pins pins;
57 uint32_t baud;
58 OversampleMode over8;
59 void (*setBaud)(struct UART *, uint32_t);
60 void (*send)(struct UART *, uint8_t);
61 void (*sendBytes)(struct UART *, uint8_t *, int);
62 void (*print)(struct UART *, char *);
63 uint8_t (*receive)(struct UART *);
64} UART;
65
66DeviceHandle_t UART_init(UART *, char[DEVICE_NAME_LENGTH], USART_TypeDef *, GPIO_TypeDef *, UART_Pins, uint32_t, OversampleMode);
68void UART_setBaud(UART *, uint32_t);
69
70void UART_send(UART *, uint8_t data);
71void UART_sendBytes(UART *, uint8_t *data, int length);
72void UART_print(UART *, char *data);
73uint8_t UART_receive(UART *);
74
76#endif
void(* print)(struct UART *, char *)
UART print string method.
Definition uart.h:62
void(* sendBytes)(struct UART *, uint8_t *, int)
UART send multiple bytes method.
Definition uart.h:61
void(* send)(struct UART *, uint8_t)
UART send method.
Definition uart.h:60
uint8_t(* receive)(struct UART *)
UART receive method.
Definition uart.h:63
void UART_send(UART *, uint8_t data)
Sends a single byte of data over the UART interface.
Definition uart.c:128
void UART_print(UART *, char *data)
Sends a string of characters over the UART interface.
Definition uart.c:160
void _UART_setup(UART *, UART_Pins)
Configures the UART interface for communication.
Definition uart.c:66
DeviceHandle_t UART_init(UART *, char[DEVICE_NAME_LENGTH], USART_TypeDef *, GPIO_TypeDef *, UART_Pins, uint32_t, OversampleMode)
Initialiser for a UART device interface.
Definition uart.c:26
void UART_sendBytes(UART *, uint8_t *data, int length)
Sends an array of bytes over the UART interface.
Definition uart.c:145
uint8_t UART_receive(UART *)
Receives a single byte of data from the UART interface.
Definition uart.c:174
Struct definition for UART interface.
Definition uart.h:53