~ruther/uni-mam-arm

ref: 54e9f8d2af25b11710e86886f09b07975bd3e9cc uni-mam-arm/arm07/include/uart.h -rw-r--r-- 1.3 KiB
54e9f8d2 — Rutherther feat(arm07): implement most 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef UART_H
#define UART_H

#include <stm32f4xx.h>
#include <stdint.h>
#include <stdbool.h>

typedef enum {
  USART_WORD_8_BITS = 0,
  USART_WORD_9_BITS = 1,
} usart_word_length_t;

typedef enum {
  USART_PARITY_EVEN = 0,
  USART_PARITY_ODD = 1,
} usart_parity_t;

typedef enum {
  USART_STOP_BIT_ONE = 0,
  USART_STOP_BIT_HALF = 1,
  USART_STOP_BIT_TWO = 2,
} usart_stop_bits_t;

typedef struct {
  USART_TypeDef* periph;
  uint8_t idx;
} uart_t;

void usart_init(uart_t* uart, USART_TypeDef* peripheral, uint8_t idx);

void usart_configure_speed(uart_t *uart,
                           uint32_t clock_speed_hz,
                           uint32_t baud);

void usart_configure_uart(uart_t* uart, bool enable,
                          usart_word_length_t length, bool parity_control,
                          usart_parity_t parity,
                          usart_stop_bits_t stop_bits);

void usart_configure_receiver(uart_t* uart, bool enable);
void usart_configure_transmitter(uart_t* uart, bool enable);

uint16_t usart_transmit(uart_t* uart, char* data, uint16_t size);
uint16_t usart_receive(uart_t* uart, char* buffer, uint16_t max_size);

bool usart_can_transmit(uart_t* uart);
uint16_t usart_can_receive(uart_t* uart);

void usart_enable_interrupt(uart_t* uart, bool tx, bool rx);

#endif // UART_H
Do not follow this link