forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart.h
100 lines (80 loc) · 2.58 KB
/
uart.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
uart.h - UART HAL
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ESP_UART_H
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#if defined (__cplusplus)
extern "C" {
#endif
#define UART0 0
#define UART1 1
#define UART_NO -1
// Options for `config` argument of uart_init
#define UART_5N1 0x10
#define UART_6N1 0x14
#define UART_7N1 0x18
#define UART_8N1 0x1c
#define UART_5N2 0x30
#define UART_6N2 0x34
#define UART_7N2 0x38
#define UART_8N2 0x3c
#define UART_5E1 0x12
#define UART_6E1 0x16
#define UART_7E1 0x1a
#define UART_8E1 0x1e
#define UART_5E2 0x32
#define UART_6E2 0x36
#define UART_7E2 0x3a
#define UART_8E2 0x3e
#define UART_5O1 0x13
#define UART_6O1 0x17
#define UART_7O1 0x1b
#define UART_8O1 0x1f
#define UART_5O2 0x33
#define UART_6O2 0x37
#define UART_7O2 0x3b
#define UART_8O2 0x3f
// Options for `mode` argument of uart_init
#define UART_FULL 0
#define UART_RX_ONLY 1
#define UART_TX_ONLY 2
#define UART_TX_FIFO_SIZE 0x80
struct uart_;
typedef struct uart_ uart_t;
uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin);
void uart_uninit(uart_t* uart);
void uart_swap(uart_t* uart, int tx_pin);
void uart_set_tx(uart_t* uart, int tx_pin);
void uart_set_pins(uart_t* uart, int tx, int rx);
bool uart_tx_enabled(uart_t* uart);
bool uart_rx_enabled(uart_t* uart);
void uart_set_baudrate(uart_t* uart, int baud_rate);
int uart_get_baudrate(uart_t* uart);
void uart_write_char(uart_t* uart, char c);
void uart_write(uart_t* uart, const char* buf, size_t size);
int uart_read_char(uart_t* uart);
size_t uart_rx_available(uart_t* uart);
size_t uart_tx_free(uart_t* uart);
void uart_wait_tx_empty(uart_t* uart);
void uart_flush(uart_t* uart);
void uart_set_debug(int uart_nr);
int uart_get_debug();
#if defined (__cplusplus)
} // extern "C"
#endif
#endif // ESP_UART_H