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 "gpio.h"
17
18#define UART_PARITY_DISABLE 0x400
19#define UART_SYNC_DISABLE 0xE00
20#define UART_FLOW_DISABLE 0x300
21#define UART_ENABLE 0x2000
22#define UART_RX_ENABLE 0x0004
23#define UART_TX_ENABLE 0x0008
24#define UART_AF7 0x07
25#define UART_AF8 0x08
26
27#define SIGINT 0x03
28#define BACKSPACE 0x08
29#define LINE_FEED 0x0A
30#define CARRIAGE_RETURN 0x0D
31
38
39typedef enum {
40 OVER8,
41 OVER16
42} OversampleMode;
43
44typedef struct UART_Pins {
45 uint8_t TX;
46 uint8_t RX;
47} UART_Pins;
48
52typedef struct UART {
53 USART_TypeDef *interface;
54 GPIO_TypeDef *port;
55 UART_Pins pins;
56 uint32_t baud;
57 OversampleMode over8;
58 void (*setBaud)(struct UART *, uint32_t);
59 void (*send)(struct UART *, uint8_t);
60 void (*sendBytes)(struct UART *, uint8_t *, int);
61 void (*print)(struct UART *, char *);
62 uint8_t (*receive)(struct UART *);
63} UART_t;
64
65UART_t UART_init(UART_t *, USART_TypeDef *, GPIO_TypeDef *, UART_Pins, uint32_t, OversampleMode);
67void UART_setBaud(UART_t *, uint32_t);
68
69void UART_send(UART_t *, uint8_t data);
70void UART_sendBytes(UART_t *, uint8_t *data, int length);
71void UART_print(UART_t *, char *data);
72uint8_t UART_receive(UART_t *);
73
75#endif
General Purpose I/O.
Universal Synchronous Asynchronous Receiver Transmitter.
void(* print)(struct UART *, char *)
UART print string method.
Definition uart.h:61
void(* sendBytes)(struct UART *, uint8_t *, int)
UART send multiple bytes method.
Definition uart.h:60
void(* send)(struct UART *, uint8_t)
UART send method.
Definition uart.h:59
uint8_t(* receive)(struct UART *)
UART receive method.
Definition uart.h:62
void UART_send(UART_t *, uint8_t data)
Sends a single byte of data over the UART interface.
Definition uart.c:124
void UART_sendBytes(UART_t *, uint8_t *data, int length)
Sends an array of bytes over the UART interface.
Definition uart.c:141
void _UART_setup(UART_t *, UART_Pins)
Configures the UART interface for communication.
Definition uart.c:62
uint8_t UART_receive(UART_t *)
Receives a single byte of data from the UART interface.
Definition uart.c:170
UART_t UART_init(UART_t *, USART_TypeDef *, GPIO_TypeDef *, UART_Pins, uint32_t, OversampleMode)
Initialiser for a UART device interface.
Definition uart.c:26
void UART_print(UART_t *, char *data)
Sends a string of characters over the UART interface.
Definition uart.c:156
Struct definition for UART interface.
Definition uart.h:52
CMSIS STM32F439xx Device Peripheral Access Layer Header File.