1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _USART_H_
18 #define _USART_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <gpio.h>
25 #include <stdint.h>
26 
27 struct usart;
28 
29 typedef uint8_t UsartPort;
30 
31 typedef enum
32 {
33     USART_DATA_BITS_8,
34     USART_DATA_BITS_9,
35 } UsartDataBitsCfg;
36 
37 typedef enum
38 {
39     USART_STOP_BITS_0_5,
40     USART_STOP_BITS_1_0,
41     USART_STOP_BITS_1_5,
42     USART_STOP_BITS_2_0,
43 } UsatStopBitsCfg;
44 
45 typedef enum
46 {
47     USART_PARITY_NONE,
48     USART_PARITY_EVEN,
49     USART_PARITY_ODD,
50 } UsartParityCfg;
51 
52 typedef enum
53 {
54     USART_FLOW_CONTROL_NONE,
55     USART_FLOW_CONTROL_RTS,
56     USART_FLOW_CONTROL_CTS,
57     USART_FLOW_CONTROL_RTS_CTS,
58 } UsartFlowControlCfg;
59 
60 void usartOpen(struct usart* __restrict usart, UsartPort port, /* port number is 1-based!!!!! */
61                 uint32_t txGpioNum, uint32_t rxGpioNum,
62                 uint32_t baud, UsartDataBitsCfg data_bits,
63                 UsatStopBitsCfg stop_bits, UsartParityCfg parity,
64                 UsartFlowControlCfg flow_control);
65 void usartClose(const struct usart* __restrict usart);
66 void usartPutchar(const struct usart* __restrict usart, char c);
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 
72 #endif
73 
74