~ruther/uni-mam-arm

ref: 42e96cdb93e56e04b33e2522e077e74013a4604c uni-mam-arm/arm04/include/uart.h -rw-r--r-- 1.0 KiB
42e96cdb — Rutherther feat(arm07): implement uploading images 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
#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);

uint16_t usart_receive(uart_t* uart, char* buffer, uint16_t max_size, char separator);

#endif // UART_H
Do not follow this link