blob: 684689a0ecf82af9e98ac533b728e6d0ec39a76e [file] [log] [blame]
Alexander Steffen299bc622017-06-29 23:14:58 +02001#ifndef MICROPY_INCLUDED_ESP8266_UART_H
2#define MICROPY_INCLUDED_ESP8266_UART_H
Damien George075d5972014-11-27 20:30:33 +00003
daniel-kaa4ada92016-07-26 17:56:13 +02004#include <eagle_soc.h>
5
Damien George075d5972014-11-27 20:30:33 +00006#define UART0 (0)
7#define UART1 (1)
8
9typedef enum {
10 UART_FIVE_BITS = 0x0,
11 UART_SIX_BITS = 0x1,
12 UART_SEVEN_BITS = 0x2,
13 UART_EIGHT_BITS = 0x3
14} UartBitsNum4Char;
15
16typedef enum {
Ein Terakawaab2c64c2017-08-16 10:23:27 +000017 UART_ONE_STOP_BIT = 0x1,
18 UART_ONE_HALF_STOP_BIT = 0x2,
19 UART_TWO_STOP_BIT = 0x3
Damien George075d5972014-11-27 20:30:33 +000020} UartStopBitsNum;
21
22typedef enum {
daniel-kaa4ada92016-07-26 17:56:13 +020023 UART_NONE_BITS = 0,
24 UART_ODD_BITS = BIT0,
25 UART_EVEN_BITS = 0
Damien George075d5972014-11-27 20:30:33 +000026} UartParityMode;
27
28typedef enum {
29 UART_STICK_PARITY_DIS = 0,
daniel-kaa4ada92016-07-26 17:56:13 +020030 UART_STICK_PARITY_EN = BIT1
Damien George075d5972014-11-27 20:30:33 +000031} UartExistParity;
32
33typedef enum {
34 UART_BIT_RATE_9600 = 9600,
35 UART_BIT_RATE_19200 = 19200,
36 UART_BIT_RATE_38400 = 38400,
37 UART_BIT_RATE_57600 = 57600,
38 UART_BIT_RATE_74880 = 74880,
39 UART_BIT_RATE_115200 = 115200,
40 UART_BIT_RATE_230400 = 230400,
41 UART_BIT_RATE_256000 = 256000,
42 UART_BIT_RATE_460800 = 460800,
43 UART_BIT_RATE_921600 = 921600
44} UartBautRate;
45
46typedef enum {
47 UART_NONE_CTRL,
48 UART_HARDWARE_CTRL,
49 UART_XON_XOFF_CTRL
50} UartFlowCtrl;
51
52typedef enum {
53 UART_EMPTY,
54 UART_UNDER_WRITE,
55 UART_WRITE_OVER
56} RcvMsgBuffState;
57
58typedef struct {
59 uint32 RcvBuffSize;
60 uint8 *pRcvMsgBuff;
61 uint8 *pWritePos;
62 uint8 *pReadPos;
63 uint8 TrigLvl; //JLU: may need to pad
64 RcvMsgBuffState BuffState;
65} RcvMsgBuff;
66
67typedef struct {
68 uint32 TrxBuffSize;
69 uint8 *pTrxBuff;
70} TrxMsgBuff;
71
72typedef enum {
73 UART_BAUD_RATE_DET,
74 UART_WAIT_SYNC_FRM,
75 UART_SRCH_MSG_HEAD,
76 UART_RCV_MSG_BODY,
77 UART_RCV_ESC_CHAR,
78} RcvMsgState;
79
80typedef struct {
81 UartBautRate baut_rate;
82 UartBitsNum4Char data_bits;
83 UartExistParity exist_parity;
84 UartParityMode parity; // chip size in byte
85 UartStopBitsNum stop_bits;
86 UartFlowCtrl flow_ctrl;
87 RcvMsgBuff rcv_buff;
88 TrxMsgBuff trx_buff;
89 RcvMsgState rcv_state;
90 int received;
91 int buff_uart_no; //indicate which uart use tx/rx buffer
92} UartDevice;
93
94void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
95int uart0_rx(void);
Damien George7652ab72016-04-21 15:19:00 +010096bool uart_rx_wait(uint32_t timeout_us);
97int uart_rx_char(void);
Damien George075d5972014-11-27 20:30:33 +000098void uart_tx_one_char(uint8 uart, uint8 TxChar);
Paul Sokolovskyd9d4a722016-01-03 07:33:42 +020099void uart_flush(uint8 uart);
Damien George96eca222016-04-06 00:12:58 +0300100void uart_os_config(int uart);
Radomir Dopieralski35962ea2016-06-29 14:18:48 +0200101void uart_setup(uint8 uart);
marc hoffman91eb0152017-01-29 21:48:55 -0500102// check status of rx/tx
103int uart_rx_any(uint8 uart);
104int uart_tx_any_room(uint8 uart);
Damien George075d5972014-11-27 20:30:33 +0000105
Alexander Steffen299bc622017-06-29 23:14:58 +0200106#endif // MICROPY_INCLUDED_ESP8266_UART_H