summaryrefslogtreecommitdiff
path: root/bsp/apm32/libraries/APM32F10x_Library/APM32F10x_StdPeriphDriver/inc/apm32f10x_usart.h
blob: 7d4434320cc8d56be746b26ab0560750c497e03b (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*!
 * @file        apm32f10x_usart.h
 *
 * @brief       This file contains all the functions prototypes for the USART firmware library
 *
 * @version     V1.0.4
 *
 * @date        2022-12-01
 *
 * @attention
 *
 *  Copyright (C) 2020-2022 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

/* Define to prevent recursive inclusion */
#ifndef __APM32F10X_USART_H
#define __APM32F10X_USART_H

/* Includes */
#include "apm32f10x.h"

#ifdef __cplusplus
extern "C" {
#endif

/** @addtogroup APM32F10x_StdPeriphDriver
  @{
*/

/** @addtogroup USART_Driver USART Driver
  @{
*/

/** @defgroup USART_Enumerations Enumerations
  @{
*/

/**
 * @brief   USART Word Length definition
 */
typedef enum
{
    USART_WORD_LEN_8B = 0,
    USART_WORD_LEN_9B = BIT12
} USART_WORD_LEN_T;

/**
 * @brief   USART Stop bits definition
 */
typedef enum
{
    USART_STOP_BIT_1   = 0,
    USART_STOP_BIT_0_5 = BIT12,
    USART_STOP_BIT_2   = BIT13,
    USART_STOP_BIT_1_5 = BIT12 | BIT13
} USART_STOP_BIT_T;

/**
 * @brief   USART Parity definition
 */
typedef enum
{
    USART_PARITY_NONE  = 0,
    USART_PARITY_EVEN  = BIT10,
    USART_PARITY_ODD   = BIT10 | BIT9
} USART_PARITY_T;

/**
 * @brief   USART mode definition
 */
typedef enum
{
    USART_MODE_RX      = BIT2,
    USART_MODE_TX      = BIT3,
    USART_MODE_TX_RX   = BIT2 | BIT3
} USART_MODE_T;

/**
 * @brief   USART hardware flow control definition
 */
typedef enum
{
    USART_HARDWARE_FLOW_NONE    = 0,
    USART_HARDWARE_FLOW_RTS     = BIT8,
    USART_HARDWARE_FLOW_CTS     = BIT9,
    USART_HARDWARE_FLOW_RTS_CTS = BIT8 | BIT9
} USART_HARDWARE_FLOW_T;

/**
 * @brief   USART Clock enable
 */
typedef enum
{
    USART_CLKEN_DISABLE,
    USART_CLKEN_ENABLE
} USART_CLKEN_T;

/**
 * @brief   USART Clock polarity definition
 */
typedef enum
{
    USART_CLKPOL_LOW,
    USART_CLKPOL_HIGH
} USART_CLKPOL_T;

/**
 * @brief   USART Clock phase definition
 */
typedef enum
{
    USART_CLKPHA_1EDGE,
    USART_CLKPHA_2EDGE
} USART_CLKPHA_T;

/**
 * @brief   USART Last bit clock pulse definition
 */
typedef enum
{
    USART_LBCP_DISABLE,
    USART_LBCP_ENABLE,
} USART_LBCP_T;

/**
 * @brief   USART Interrupt Source
 */
typedef enum
{
    USART_INT_PE     = 0x0010100,
    USART_INT_TXBE   = 0x7010080,
    USART_INT_TXC    = 0x6010040,
    USART_INT_RXBNE  = 0x5010020,
    USART_INT_IDLE   = 0x4010010,
    USART_INT_LBD    = 0x8020040,
    USART_INT_CTS    = 0x9040400,
    USART_INT_ERR    = 0x0040001,
    USART_INT_OVRE   = 0x3040001,
    USART_INT_NE     = 0x2040001,
    USART_INT_FE     = 0x1040001
} USART_INT_T;

/**
 * @brief   USART DMA enable
 */
typedef enum
{
    USART_DMA_TX    = BIT7,
    USART_DMA_RX    = BIT6,
    USART_DMA_TX_RX = BIT6 | BIT7
} USART_DMA_T;

/**
 * @brief   USART Wakeup method
 */
typedef enum
{
    USART_WAKEUP_IDLE_LINE,
    USART_WAKEUP_ADDRESS_MARK
} USART_WAKEUP_T;

/**
 * @brief   USART LIN break detection length
 */
typedef enum
{
    USART_LBDL_10B,
    USART_LBDL_11B
} USART_LBDL_T;

/**
 * @brief   USART IrDA low-power
 */
typedef enum
{
    USART_IRDALP_NORMAL,
    USART_IRDALP_LOWPOWER
} USART_IRDALP_T;

/**
 * @brief   USART flag definition
 */
typedef enum
{
    USART_FLAG_CTS       = 0x0200,
    USART_FLAG_LBD       = 0x0100,
    USART_FLAG_TXBE      = 0x0080,
    USART_FLAG_TXC       = 0x0040,
    USART_FLAG_RXBNE     = 0x0020,
    USART_FLAG_IDLE      = 0x0010,
    USART_FLAG_OVRE      = 0x0008,
    USART_FLAG_NE        = 0x0004,
    USART_FLAG_FE        = 0x0002,
    USART_FLAG_PE        = 0x0001
} USART_FLAG_T;

/**@} end of group USART_Enumerations */

/** @defgroup USART_Structures Structures
  @{
*/

/**
 * @brief   USART Configure structure definition
 */
typedef struct
{
    uint32_t                  baudRate;          /*!< Specifies the baud rate */
    USART_WORD_LEN_T          wordLength;        /*!< Specifies the word length */
    USART_STOP_BIT_T          stopBits;          /*!< Specifies the stop bits */
    USART_PARITY_T            parity;            /*!< Specifies the parity */
    USART_MODE_T              mode;              /*!< Specifies the mode */
    USART_HARDWARE_FLOW_T     hardwareFlow;      /*!< Specifies the hardware flow control */
} USART_Config_T;

/**
 * @brief   USART synchronous communication clock configure structure definition
 */
typedef struct
{
    USART_CLKEN_T             clock;             /*!< Enable or Disable Clock */
    USART_CLKPOL_T            polarity;          /*!< Specifies the clock polarity */
    USART_CLKPHA_T            phase;             /*!< Specifies the clock phase */
    USART_LBCP_T              lastBit;           /*!< Enable or Disable last bit clock */
} USART_ClockConfig_T;

/**@} end of group USART_Structures */

/** @defgroup USART_Functions Functions
  @{
*/

/* USART Reset and Configuration */
void USART_Reset(USART_T* usart);
void USART_Config(USART_T* uart, USART_Config_T* usartConfig);
void USART_ConfigStructInit(USART_Config_T* usartConfig);
void USART_Address(USART_T* usart, uint8_t address);
void USART_Enable(USART_T* usart);
void USART_Disable(USART_T* usart);

/* Clock communication */
void USART_ConfigClock(USART_T* usart, USART_ClockConfig_T* clockConfig);
void USART_ConfigClockStructInit(USART_ClockConfig_T* clockConfig);

/* DMA mode */
void USART_EnableDMA(USART_T* usart, USART_DMA_T dmaReq);
void USART_DisableDMA(USART_T* usart, USART_DMA_T dmaReq);

/* Mute mode */
void USART_ConfigWakeUp(USART_T* usart, USART_WAKEUP_T wakeup);
void USART_EnableMuteMode(USART_T* usart);
void USART_DisableMuteMode(USART_T* usart);

/* LIN mode */
void USART_ConfigLINBreakDetectLength(USART_T* usart, USART_LBDL_T length);
void USART_EnableLIN(USART_T* usart);
void USART_DisableLIN(USART_T* usart);

/* Transmit and receive */
void USART_EnableTx(USART_T* usart);
void USART_DisableTx(USART_T* usart);
void USART_EnableRx(USART_T* usart);
void USART_DisableRx(USART_T* usart);
void USART_TxData(USART_T* usart, uint16_t data);
uint16_t USART_RxData(USART_T* usart);
void USART_TxBreak(USART_T* usart);

/* Smartcard mode */
void USART_ConfigGuardTime(USART_T* usart, uint8_t guardTime);
void USART_ConfigPrescaler(USART_T* usart, uint8_t div);
void USART_EnableSmartCard(USART_T* usart);
void USART_DisableSmartCard(USART_T* usart);
void USART_EnableSmartCardNACK(USART_T* usart);
void USART_DisableSmartCardNACK(USART_T* usart);

/* Half-duplex mode  */
void USART_EnableHalfDuplex(USART_T* usart);
void USART_DisableHalfDuplex(USART_T* usart);

/* IrDA mode */
void USART_ConfigIrDA(USART_T* usart, USART_IRDALP_T IrDAMode);
void USART_EnableIrDA(USART_T* usart);
void USART_DisableIrDA(USART_T* usart);

/* Interrupt and flag */
void USART_EnableInterrupt(USART_T* usart, USART_INT_T interrupt);
void USART_DisableInterrupt(USART_T* usart, USART_INT_T interrupt);
uint8_t USART_ReadStatusFlag(USART_T* usart, USART_FLAG_T flag);
void USART_ClearStatusFlag(USART_T* usart, USART_FLAG_T flag);
uint8_t USART_ReadIntFlag(USART_T* usart, USART_INT_T flag);
void USART_ClearIntFlag(USART_T* usart, USART_INT_T flag);

/**@} end of group USART_Functions */
/**@} end of group USART_Driver */
/**@} end of group APM32F10x_StdPeriphDriver */

#ifdef __cplusplus
}
#endif

#endif /* __APM32F10X_USART_H */