1 /***************************************************************************//**
\r
3 * @brief Universal synchronous/asynchronous receiver/transmitter (USART/UART)
\r
6 *******************************************************************************
\r
8 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
\r
9 *******************************************************************************
\r
11 * Permission is granted to anyone to use this software for any purpose,
\r
12 * including commercial applications, and to alter it and redistribute it
\r
13 * freely, subject to the following restrictions:
\r
15 * 1. The origin of this software must not be misrepresented; you must not
\r
16 * claim that you wrote the original software.
\r
17 * 2. Altered source versions must be plainly marked as such, and must not be
\r
18 * misrepresented as being the original software.
\r
19 * 3. This notice may not be removed or altered from any source distribution.
\r
21 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
\r
22 * obligation to support this Software. Silicon Labs is providing the
\r
23 * Software "AS IS", with no express or implied warranties of any kind,
\r
24 * including, but not limited to, any implied warranties of merchantability
\r
25 * or fitness for any particular purpose or warranties against infringement
\r
26 * of any proprietary rights of a third party.
\r
28 * Silicon Labs will not be liable for any consequential, incidental, or
\r
29 * special damages, or any other relief, or for any claim by any third party,
\r
30 * arising from your use of this Software.
\r
32 ******************************************************************************/
\r
35 #ifndef __SILICON_LABS_EM_USART_H_
\r
36 #define __SILICON_LABS_EM_USART_H_
\r
38 #include "em_device.h"
\r
39 #if defined(USART_COUNT) && (USART_COUNT > 0)
\r
41 #include <stdbool.h>
\r
47 /***************************************************************************//**
\r
48 * @addtogroup EM_Library
\r
50 ******************************************************************************/
\r
52 /***************************************************************************//**
\r
54 * @brief Universal Synchronous/Asynchronous Receiver/Transmitter (USART) peripheral API
\r
56 ******************************************************************************/
\r
58 /*******************************************************************************
\r
59 ******************************** ENUMS ************************************
\r
60 ******************************************************************************/
\r
62 /** Databit selection. */
\r
65 usartDatabits4 = USART_FRAME_DATABITS_FOUR, /**< 4 databits (not available for UART). */
\r
66 usartDatabits5 = USART_FRAME_DATABITS_FIVE, /**< 5 databits (not available for UART). */
\r
67 usartDatabits6 = USART_FRAME_DATABITS_SIX, /**< 6 databits (not available for UART). */
\r
68 usartDatabits7 = USART_FRAME_DATABITS_SEVEN, /**< 7 databits (not available for UART). */
\r
69 usartDatabits8 = USART_FRAME_DATABITS_EIGHT, /**< 8 databits. */
\r
70 usartDatabits9 = USART_FRAME_DATABITS_NINE, /**< 9 databits. */
\r
71 usartDatabits10 = USART_FRAME_DATABITS_TEN, /**< 10 databits (not available for UART). */
\r
72 usartDatabits11 = USART_FRAME_DATABITS_ELEVEN, /**< 11 databits (not available for UART). */
\r
73 usartDatabits12 = USART_FRAME_DATABITS_TWELVE, /**< 12 databits (not available for UART). */
\r
74 usartDatabits13 = USART_FRAME_DATABITS_THIRTEEN, /**< 13 databits (not available for UART). */
\r
75 usartDatabits14 = USART_FRAME_DATABITS_FOURTEEN, /**< 14 databits (not available for UART). */
\r
76 usartDatabits15 = USART_FRAME_DATABITS_FIFTEEN, /**< 15 databits (not available for UART). */
\r
77 usartDatabits16 = USART_FRAME_DATABITS_SIXTEEN /**< 16 databits (not available for UART). */
\r
78 } USART_Databits_TypeDef;
\r
81 /** Enable selection. */
\r
84 /** Disable both receiver and transmitter. */
\r
87 /** Enable receiver only, transmitter disabled. */
\r
88 usartEnableRx = USART_CMD_RXEN,
\r
90 /** Enable transmitter only, receiver disabled. */
\r
91 usartEnableTx = USART_CMD_TXEN,
\r
93 /** Enable both receiver and transmitter. */
\r
94 usartEnable = (USART_CMD_RXEN | USART_CMD_TXEN)
\r
95 } USART_Enable_TypeDef;
\r
98 /** Oversampling selection, used for asynchronous operation. */
\r
101 usartOVS16 = USART_CTRL_OVS_X16, /**< 16x oversampling (normal). */
\r
102 usartOVS8 = USART_CTRL_OVS_X8, /**< 8x oversampling. */
\r
103 usartOVS6 = USART_CTRL_OVS_X6, /**< 6x oversampling. */
\r
104 usartOVS4 = USART_CTRL_OVS_X4 /**< 4x oversampling. */
\r
105 } USART_OVS_TypeDef;
\r
108 /** Parity selection, mainly used for asynchronous operation. */
\r
111 usartNoParity = USART_FRAME_PARITY_NONE, /**< No parity. */
\r
112 usartEvenParity = USART_FRAME_PARITY_EVEN, /**< Even parity. */
\r
113 usartOddParity = USART_FRAME_PARITY_ODD /**< Odd parity. */
\r
114 } USART_Parity_TypeDef;
\r
117 /** Stopbits selection, used for asynchronous operation. */
\r
120 usartStopbits0p5 = USART_FRAME_STOPBITS_HALF, /**< 0.5 stopbits. */
\r
121 usartStopbits1 = USART_FRAME_STOPBITS_ONE, /**< 1 stopbits. */
\r
122 usartStopbits1p5 = USART_FRAME_STOPBITS_ONEANDAHALF, /**< 1.5 stopbits. */
\r
123 usartStopbits2 = USART_FRAME_STOPBITS_TWO /**< 2 stopbits. */
\r
124 } USART_Stopbits_TypeDef;
\r
127 /** Clock polarity/phase mode. */
\r
130 /** Clock idle low, sample on rising edge. */
\r
131 usartClockMode0 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLELEADING,
\r
133 /** Clock idle low, sample on falling edge. */
\r
134 usartClockMode1 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLETRAILING,
\r
136 /** Clock idle high, sample on falling edge. */
\r
137 usartClockMode2 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLELEADING,
\r
139 /** Clock idle high, sample on rising edge. */
\r
140 usartClockMode3 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLETRAILING
\r
141 } USART_ClockMode_TypeDef;
\r
144 /** Pulse width selection for IrDA mode. */
\r
147 /** IrDA pulse width is 1/16 for OVS=0 and 1/8 for OVS=1 */
\r
148 usartIrDAPwONE = USART_IRCTRL_IRPW_ONE,
\r
150 /** IrDA pulse width is 2/16 for OVS=0 and 2/8 for OVS=1 */
\r
151 usartIrDAPwTWO = USART_IRCTRL_IRPW_TWO,
\r
153 /** IrDA pulse width is 3/16 for OVS=0 and 3/8 for OVS=1 */
\r
154 usartIrDAPwTHREE = USART_IRCTRL_IRPW_THREE,
\r
156 /** IrDA pulse width is 4/16 for OVS=0 and 4/8 for OVS=1 */
\r
157 usartIrDAPwFOUR = USART_IRCTRL_IRPW_FOUR
\r
158 } USART_IrDAPw_Typedef;
\r
161 /** PRS channel selection for IrDA mode. */
\r
164 usartIrDAPrsCh0 = USART_IRCTRL_IRPRSSEL_PRSCH0, /**< PRS channel 0 */
\r
165 usartIrDAPrsCh1 = USART_IRCTRL_IRPRSSEL_PRSCH1, /**< PRS channel 1 */
\r
166 usartIrDAPrsCh2 = USART_IRCTRL_IRPRSSEL_PRSCH2, /**< PRS channel 2 */
\r
167 usartIrDAPrsCh3 = USART_IRCTRL_IRPRSSEL_PRSCH3, /**< PRS channel 3 */
\r
168 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH4 )
\r
169 usartIrDAPrsCh4 = USART_IRCTRL_IRPRSSEL_PRSCH4, /**< PRS channel 4 */
\r
171 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH5 )
\r
172 usartIrDAPrsCh5 = USART_IRCTRL_IRPRSSEL_PRSCH5, /**< PRS channel 5 */
\r
174 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH6 )
\r
175 usartIrDAPrsCh6 = USART_IRCTRL_IRPRSSEL_PRSCH6, /**< PRS channel 6 */
\r
177 #if defined( USART_IRCTRL_IRPRSSEL_PRSCH7 )
\r
178 usartIrDAPrsCh7 = USART_IRCTRL_IRPRSSEL_PRSCH7, /**< PRS channel 7 */
\r
180 } USART_IrDAPrsSel_Typedef;
\r
182 #if defined( _USART_I2SCTRL_MASK )
\r
183 /** I2S format selection. */
\r
186 usartI2sFormatW32D32 = USART_I2SCTRL_FORMAT_W32D32, /**< 32-bit word, 32-bit data */
\r
187 usartI2sFormatW32D24M = USART_I2SCTRL_FORMAT_W32D24M, /**< 32-bit word, 32-bit data with 8 lsb masked */
\r
188 usartI2sFormatW32D24 = USART_I2SCTRL_FORMAT_W32D24, /**< 32-bit word, 24-bit data */
\r
189 usartI2sFormatW32D16 = USART_I2SCTRL_FORMAT_W32D16, /**< 32-bit word, 16-bit data */
\r
190 usartI2sFormatW32D8 = USART_I2SCTRL_FORMAT_W32D8, /**< 32-bit word, 8-bit data */
\r
191 usartI2sFormatW16D16 = USART_I2SCTRL_FORMAT_W16D16, /**< 16-bit word, 16-bit data */
\r
192 usartI2sFormatW16D8 = USART_I2SCTRL_FORMAT_W16D8, /**< 16-bit word, 8-bit data */
\r
193 usartI2sFormatW8D8 = USART_I2SCTRL_FORMAT_W8D8 /**< 8-bit word, 8-bit data */
\r
194 } USART_I2sFormat_TypeDef;
\r
196 /** I2S frame data justify. */
\r
199 usartI2sJustifyLeft = USART_I2SCTRL_JUSTIFY_LEFT, /**< Data is left-justified within the frame */
\r
200 usartI2sJustifyRight = USART_I2SCTRL_JUSTIFY_RIGHT /**< Data is right-justified within the frame */
\r
201 } USART_I2sJustify_TypeDef;
\r
204 #if defined( _USART_INPUT_MASK )
\r
205 /** USART Rx input PRS selection. */
\r
208 usartPrsRxCh0 = USART_INPUT_RXPRSSEL_PRSCH0, /**< PRSCH0 selected as USART_INPUT */
\r
209 usartPrsRxCh1 = USART_INPUT_RXPRSSEL_PRSCH1, /**< PRSCH1 selected as USART_INPUT */
\r
210 usartPrsRxCh2 = USART_INPUT_RXPRSSEL_PRSCH2, /**< PRSCH2 selected as USART_INPUT */
\r
211 usartPrsRxCh3 = USART_INPUT_RXPRSSEL_PRSCH3, /**< PRSCH3 selected as USART_INPUT */
\r
213 #if defined( USART_INPUT_RXPRSSEL_PRSCH7 )
\r
214 usartPrsRxCh4 = USART_INPUT_RXPRSSEL_PRSCH4, /**< PRSCH4 selected as USART_INPUT */
\r
215 usartPrsRxCh5 = USART_INPUT_RXPRSSEL_PRSCH5, /**< PRSCH5 selected as USART_INPUT */
\r
216 usartPrsRxCh6 = USART_INPUT_RXPRSSEL_PRSCH6, /**< PRSCH6 selected as USART_INPUT */
\r
217 usartPrsRxCh7 = USART_INPUT_RXPRSSEL_PRSCH7, /**< PRSCH7 selected as USART_INPUT */
\r
220 #if defined( USART_INPUT_RXPRSSEL_PRSCH11 )
\r
221 usartPrsRxCh8 = USART_INPUT_RXPRSSEL_PRSCH8, /**< PRSCH8 selected as USART_INPUT */
\r
222 usartPrsRxCh9 = USART_INPUT_RXPRSSEL_PRSCH9, /**< PRSCH9 selected as USART_INPUT */
\r
223 usartPrsRxCh10 = USART_INPUT_RXPRSSEL_PRSCH10, /**< PRSCH10 selected as USART_INPUT */
\r
224 usartPrsRxCh11 = USART_INPUT_RXPRSSEL_PRSCH11 /**< PRSCH11 selected as USART_INPUT */
\r
226 } USART_PrsRxCh_TypeDef;
\r
229 /** USART PRS Transmit Trigger Channels */
\r
232 usartPrsTriggerCh0 = USART_TRIGCTRL_TSEL_PRSCH0, /**< PRSCH0 selected as USART Trigger */
\r
233 usartPrsTriggerCh1 = USART_TRIGCTRL_TSEL_PRSCH1, /**< PRSCH0 selected as USART Trigger */
\r
234 usartPrsTriggerCh2 = USART_TRIGCTRL_TSEL_PRSCH2, /**< PRSCH0 selected as USART Trigger */
\r
235 usartPrsTriggerCh3 = USART_TRIGCTRL_TSEL_PRSCH3, /**< PRSCH0 selected as USART Trigger */
\r
237 #if defined( USART_TRIGCTRL_TSEL_PRSCH7 )
\r
238 usartPrsTriggerCh4 = USART_TRIGCTRL_TSEL_PRSCH4, /**< PRSCH0 selected as USART Trigger */
\r
239 usartPrsTriggerCh5 = USART_TRIGCTRL_TSEL_PRSCH5, /**< PRSCH0 selected as USART Trigger */
\r
240 usartPrsTriggerCh6 = USART_TRIGCTRL_TSEL_PRSCH6, /**< PRSCH0 selected as USART Trigger */
\r
241 usartPrsTriggerCh7 = USART_TRIGCTRL_TSEL_PRSCH7, /**< PRSCH0 selected as USART Trigger */
\r
243 } USART_PrsTriggerCh_TypeDef;
\r
245 /*******************************************************************************
\r
246 ******************************* STRUCTS ***********************************
\r
247 ******************************************************************************/
\r
249 /** Asynchronous mode init structure. */
\r
252 /** Specifies whether TX and/or RX shall be enabled when init completed. */
\r
253 USART_Enable_TypeDef enable;
\r
256 * USART/UART reference clock assumed when configuring baudrate setup. Set
\r
257 * it to 0 if currently configurated reference clock shall be used.
\r
261 /** Desired baudrate. */
\r
264 /** Oversampling used. */
\r
265 USART_OVS_TypeDef oversampling;
\r
267 /** Number of databits in frame. Notice that UART modules only support 8 or
\r
269 USART_Databits_TypeDef databits;
\r
271 /** Parity mode to use. */
\r
272 USART_Parity_TypeDef parity;
\r
274 /** Number of stopbits to use. */
\r
275 USART_Stopbits_TypeDef stopbits;
\r
277 #if defined( USART_INPUT_RXPRS ) && defined( USART_CTRL_MVDIS )
\r
278 /** Majority Vote Disable for 16x, 8x and 6x oversampling modes. */
\r
281 /** Enable USART Rx via PRS. */
\r
284 /** Select PRS channel for USART Rx. (Only valid if prsRxEnable is true). */
\r
285 USART_PrsRxCh_TypeDef prsRxCh;
\r
287 } USART_InitAsync_TypeDef;
\r
289 /** USART PRS trigger enable */
\r
292 #if defined( USART_TRIGCTRL_AUTOTXTEN )
\r
293 /** Enable AUTOTX */
\r
294 bool autoTxTriggerEnable;
\r
296 /** Trigger receive via PRS channel */
\r
297 bool rxTriggerEnable;
\r
298 /** Trigger transmit via PRS channel */
\r
299 bool txTriggerEnable;
\r
300 /** PRS channel to be used to trigger auto transmission */
\r
301 USART_PrsTriggerCh_TypeDef prsTriggerChannel;
\r
302 } USART_PrsTriggerInit_TypeDef;
\r
304 /** Default config for USART async init structure. */
\r
305 #if defined( USART_INPUT_RXPRS ) && defined( USART_CTRL_MVDIS )
\r
306 #define USART_INITASYNC_DEFAULT \
\r
307 { usartEnable, /* Enable RX/TX when init completed. */ \
\r
308 0, /* Use current configured reference clock for configuring baudrate. */ \
\r
309 115200, /* 115200 bits/s. */ \
\r
310 usartOVS16, /* 16x oversampling. */ \
\r
311 usartDatabits8, /* 8 databits. */ \
\r
312 usartNoParity, /* No parity. */ \
\r
313 usartStopbits1, /* 1 stopbit. */ \
\r
314 false, /* Do not disable majority vote. */ \
\r
315 false, /* Not USART PRS input mode. */ \
\r
316 usartPrsRxCh0 /* PRS channel 0. */ \
\r
319 #define USART_INITASYNC_DEFAULT \
\r
320 { usartEnable, /* Enable RX/TX when init completed. */ \
\r
321 0, /* Use current configured reference clock for configuring baudrate. */ \
\r
322 115200, /* 115200 bits/s. */ \
\r
323 usartOVS16, /* 16x oversampling. */ \
\r
324 usartDatabits8, /* 8 databits. */ \
\r
325 usartNoParity, /* No parity. */ \
\r
326 usartStopbits1 /* 1 stopbit. */ \
\r
330 /** Default config for USART PRS triggering structure. */
\r
331 #if defined ( USART_TRIGCTRL_AUTOTXTEN )
\r
332 #define USART_INITPRSTRIGGER_DEFAULT \
\r
333 { false, /* Do not enable autoTX triggering. */ \
\r
334 false, /* Do not enable receive triggering. */ \
\r
335 false, /* Do not enable transmit triggering. */ \
\r
336 usartPrsTriggerCh0 /* Set default channel to zero. */ \
\r
339 #define USART_INITPRSTRIGGER_DEFAULT \
\r
340 { false, /* Do not enable receive triggering. */ \
\r
341 false, /* Do not enable transmit triggering. */ \
\r
342 usartPrsTriggerCh0 /* Set default channel to zero. */ \
\r
346 /** Synchronous mode init structure. */
\r
349 /** Specifies whether TX and/or RX shall be enabled when init completed. */
\r
350 USART_Enable_TypeDef enable;
\r
353 * USART/UART reference clock assumed when configuring baudrate setup. Set
\r
354 * it to 0 if currently configurated reference clock shall be used.
\r
358 /** Desired baudrate. */
\r
361 /** Number of databits in frame. */
\r
362 USART_Databits_TypeDef databits;
\r
364 /** Select if to operate in master or slave mode. */
\r
367 /** Select if to send most or least significant bit first. */
\r
370 /** Clock polarity/phase mode. */
\r
371 USART_ClockMode_TypeDef clockMode;
\r
373 #if defined( USART_INPUT_RXPRS ) && defined( USART_TRIGCTRL_AUTOTXTEN )
\r
374 /** Enable USART Rx via PRS. */
\r
377 /** Select PRS channel for USART Rx. (Only valid if prsRxEnable is true). */
\r
378 USART_PrsRxCh_TypeDef prsRxCh;
\r
380 /** Enable AUTOTX mode. Transmits as long as RX is not full.
\r
381 * If TX is empty, underflows are generated. */
\r
384 } USART_InitSync_TypeDef;
\r
386 /** Default config for USART sync init structure. */
\r
387 #if defined( USART_INPUT_RXPRS ) && defined( USART_TRIGCTRL_AUTOTXTEN )
\r
388 #define USART_INITSYNC_DEFAULT \
\r
389 { usartEnable, /* Enable RX/TX when init completed. */ \
\r
390 0, /* Use current configured reference clock for configuring baudrate. */ \
\r
391 1000000, /* 1 Mbits/s. */ \
\r
392 usartDatabits8, /* 8 databits. */ \
\r
393 true, /* Master mode. */ \
\r
394 false, /* Send least significant bit first. */ \
\r
395 usartClockMode0, /* Clock idle low, sample on rising edge. */ \
\r
396 false, /* Not USART PRS input mode. */ \
\r
397 usartPrsRxCh0, /* PRS channel 0. */ \
\r
398 false /* No AUTOTX mode. */ \
\r
401 #define USART_INITSYNC_DEFAULT \
\r
402 { usartEnable, /* Enable RX/TX when init completed. */ \
\r
403 0, /* Use current configured reference clock for configuring baudrate. */ \
\r
404 1000000, /* 1 Mbits/s. */ \
\r
405 usartDatabits8, /* 8 databits. */ \
\r
406 true, /* Master mode. */ \
\r
407 false, /* Send least significant bit first. */ \
\r
408 usartClockMode0 /* Clock idle low, sample on rising edge. */ \
\r
413 /** IrDA mode init structure. Inherited from asynchronous mode init structure */
\r
416 /** General Async initialization structure. */
\r
417 USART_InitAsync_TypeDef async;
\r
419 /** Set to invert Rx signal before IrDA demodulator. */
\r
422 /** Set to enable filter on IrDA demodulator. */
\r
425 /** Configure the pulse width generated by the IrDA modulator as a fraction
\r
426 * of the configured USART bit period. */
\r
427 USART_IrDAPw_Typedef irPw;
\r
429 /** Enable the PRS channel selected by irPrsSel as input to IrDA module
\r
430 * instead of TX. */
\r
433 /** A PRS can be used as input to the pulse modulator instead of TX.
\r
434 * This value selects the channel to use. */
\r
435 USART_IrDAPrsSel_Typedef irPrsSel;
\r
436 } USART_InitIrDA_TypeDef;
\r
439 /** Default config for IrDA mode init structure. */
\r
440 #define USART_INITIRDA_DEFAULT \
\r
442 { usartEnable, /* Enable RX/TX when init completed. */ \
\r
443 0, /* Use current configured reference clock for configuring baudrate. */ \
\r
444 115200, /* 115200 bits/s. */ \
\r
445 usartOVS16, /* 16x oversampling. */ \
\r
446 usartDatabits8, /* 8 databits. */ \
\r
447 usartEvenParity, /* Even parity. */ \
\r
448 usartStopbits1 /* 1 stopbit. */ \
\r
450 false, /* Rx invert disabled. */ \
\r
451 false, /* Filtering disabled. */ \
\r
452 usartIrDAPwTHREE, /* Pulse width is set to ONE. */ \
\r
453 false, /* Routing to PRS is disabled. */ \
\r
454 usartIrDAPrsCh0 /* PRS channel 0. */ \
\r
458 #if defined( _USART_I2SCTRL_MASK )
\r
459 /** I2S mode init structure. Inherited from synchronous mode init structure */
\r
462 /** General Sync initialization structure. */
\r
463 USART_InitSync_TypeDef sync;
\r
466 USART_I2sFormat_TypeDef format;
\r
468 /** Delay on I2S data. Set to add a one-cycle delay between a transition
\r
469 * on the word-clock and the start of the I2S word.
\r
470 * Should be set for standard I2S format. */
\r
473 /** Separate DMA Request For Left/Right Data. */
\r
476 /** Justification of I2S data within the frame */
\r
477 USART_I2sJustify_TypeDef justify;
\r
479 /** Stero or Mono, set to true for mono. */
\r
481 } USART_InitI2s_TypeDef;
\r
484 /** Default config for I2S mode init structure. */
\r
485 #define USART_INITI2S_DEFAULT \
\r
487 { usartEnableTx, /* Enable TX when init completed. */ \
\r
488 0, /* Use current configured reference clock for configuring baudrate. */ \
\r
489 1000000, /* Baudrate 1M bits/s. */ \
\r
490 usartDatabits16, /* 16 databits. */ \
\r
491 true, /* Operate as I2S master. */ \
\r
492 true, /* Most significant bit first. */ \
\r
493 usartClockMode0, /* Clock idle low, sample on rising edge. */ \
\r
494 false, /* Don't enable USARTRx via PRS. */ \
\r
495 usartPrsRxCh0, /* PRS channel selection (dummy). */ \
\r
496 false /* Disable AUTOTX mode. */ \
\r
498 usartI2sFormatW16D16, /* 16-bit word, 16-bit data */ \
\r
499 true, /* Delay on I2S data. */ \
\r
500 false, /* No DMA split. */ \
\r
501 usartI2sJustifyLeft, /* Data is left-justified within the frame */ \
\r
502 false /* Stereo mode. */ \
\r
506 /*******************************************************************************
\r
507 ***************************** PROTOTYPES **********************************
\r
508 ******************************************************************************/
\r
510 void USART_BaudrateAsyncSet(USART_TypeDef *usart,
\r
513 USART_OVS_TypeDef ovs);
\r
514 uint32_t USART_BaudrateCalc(uint32_t refFreq,
\r
517 USART_OVS_TypeDef ovs);
\r
518 uint32_t USART_BaudrateGet(USART_TypeDef *usart);
\r
519 void USART_BaudrateSyncSet(USART_TypeDef *usart,
\r
521 uint32_t baudrate);
\r
522 void USART_Enable(USART_TypeDef *usart, USART_Enable_TypeDef enable);
\r
524 void USART_InitAsync(USART_TypeDef *usart, const USART_InitAsync_TypeDef *init);
\r
525 void USART_InitSync(USART_TypeDef *usart, const USART_InitSync_TypeDef *init);
\r
526 #if defined(USART0) || ( (USART_COUNT == 1) && defined( USART1 ) )
\r
527 void USART_InitIrDA(const USART_InitIrDA_TypeDef *init);
\r
530 #if defined( _USART_I2SCTRL_MASK )
\r
531 void USART_InitI2s(USART_TypeDef *usart, USART_InitI2s_TypeDef *init);
\r
533 void USART_InitPrsTrigger(USART_TypeDef *usart, const USART_PrsTriggerInit_TypeDef *init);
\r
536 /***************************************************************************//**
\r
538 * Clear one or more pending USART interrupts.
\r
541 * Pointer to USART/UART peripheral register block.
\r
544 * Pending USART/UART interrupt source(s) to clear. Use one or more valid
\r
545 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
\r
546 ******************************************************************************/
\r
547 __STATIC_INLINE void USART_IntClear(USART_TypeDef *usart, uint32_t flags)
\r
549 usart->IFC = flags;
\r
553 /***************************************************************************//**
\r
555 * Disable one or more USART interrupts.
\r
558 * Pointer to USART/UART peripheral register block.
\r
561 * USART/UART interrupt source(s) to disable. Use one or more valid
\r
562 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
\r
563 ******************************************************************************/
\r
564 __STATIC_INLINE void USART_IntDisable(USART_TypeDef *usart, uint32_t flags)
\r
566 usart->IEN &= ~(flags);
\r
570 /***************************************************************************//**
\r
572 * Enable one or more USART interrupts.
\r
575 * Depending on the use, a pending interrupt may already be set prior to
\r
576 * enabling the interrupt. Consider using USART_IntClear() prior to enabling
\r
577 * if such a pending interrupt should be ignored.
\r
580 * Pointer to USART/UART peripheral register block.
\r
583 * USART/UART interrupt source(s) to enable. Use one or more valid
\r
584 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
\r
585 ******************************************************************************/
\r
586 __STATIC_INLINE void USART_IntEnable(USART_TypeDef *usart, uint32_t flags)
\r
588 usart->IEN |= flags;
\r
592 /***************************************************************************//**
\r
594 * Get pending USART interrupt flags.
\r
597 * The event bits are not cleared by the use of this function.
\r
600 * Pointer to USART/UART peripheral register block.
\r
603 * USART/UART interrupt source(s) pending. Returns one or more valid
\r
604 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
\r
605 ******************************************************************************/
\r
606 __STATIC_INLINE uint32_t USART_IntGet(USART_TypeDef *usart)
\r
612 /***************************************************************************//**
\r
614 * Get enabled and pending USART interrupt flags.
\r
615 * Useful for handling more interrupt sources in the same interrupt handler.
\r
618 * Pointer to USART/UART peripheral register block.
\r
621 * Interrupt flags are not cleared by the use of this function.
\r
624 * Pending and enabled USART interrupt sources.
\r
625 * The return value is the bitwise AND combination of
\r
626 * - the OR combination of enabled interrupt sources in USARTx_IEN_nnn
\r
627 * register (USARTx_IEN_nnn) and
\r
628 * - the OR combination of valid interrupt flags of the USART module
\r
630 ******************************************************************************/
\r
631 __STATIC_INLINE uint32_t USART_IntGetEnabled(USART_TypeDef *usart)
\r
635 /* Store USARTx->IEN in temporary variable in order to define explicit order
\r
636 * of volatile accesses. */
\r
639 /* Bitwise AND of pending and enabled interrupts */
\r
640 return usart->IF & tmp;
\r
644 /***************************************************************************//**
\r
646 * Set one or more pending USART interrupts from SW.
\r
649 * Pointer to USART/UART peripheral register block.
\r
652 * USART/UART interrupt source(s) to set to pending. Use one or more valid
\r
653 * interrupt flags for the USART module (USART_IF_nnn) OR'ed together.
\r
654 ******************************************************************************/
\r
655 __STATIC_INLINE void USART_IntSet(USART_TypeDef *usart, uint32_t flags)
\r
657 usart->IFS = flags;
\r
661 /***************************************************************************//**
\r
663 * Get USART STATUS register.
\r
666 * Pointer to USART/UART peripheral register block.
\r
669 * STATUS register value.
\r
671 ******************************************************************************/
\r
672 __STATIC_INLINE uint32_t USART_StatusGet(USART_TypeDef *usart)
\r
674 return usart->STATUS;
\r
677 void USART_Reset(USART_TypeDef *usart);
\r
678 uint8_t USART_Rx(USART_TypeDef *usart);
\r
679 uint16_t USART_RxDouble(USART_TypeDef *usart);
\r
680 uint32_t USART_RxDoubleExt(USART_TypeDef *usart);
\r
681 uint16_t USART_RxExt(USART_TypeDef *usart);
\r
684 /***************************************************************************//**
\r
686 * Receive one 4-8 bit frame, (or part of 10-16 bit frame).
\r
689 * This function is used to quickly receive one 4-8 bits frame by reading the
\r
690 * RXDATA register directly, without checking the STATUS register for the
\r
691 * RXDATAV flag. This can be useful from the RXDATAV interrupt handler,
\r
692 * i.e. waiting is superfluous, in order to quickly read the received data.
\r
693 * Please refer to @ref USART_RxDataXGet() for reception of 9 bit frames.
\r
696 * Since this function does not check whether the RXDATA register actually
\r
697 * holds valid data, it should only be used in situations when it is certain
\r
698 * that there is valid data, ensured by some external program routine, e.g.
\r
699 * like when handling an RXDATAV interrupt. The @ref USART_Rx() is normally a
\r
700 * better choice if the validity of the RXDATA register is not certain.
\r
703 * Notice that possible parity/stop bits in asynchronous mode are not
\r
704 * considered part of specified frame bit length.
\r
707 * Pointer to USART/UART peripheral register block.
\r
711 ******************************************************************************/
\r
712 __STATIC_INLINE uint8_t USART_RxDataGet(USART_TypeDef *usart)
\r
714 return (uint8_t) (usart->RXDATA);
\r
718 /***************************************************************************//**
\r
720 * Receive two 4-8 bit frames, or one 10-16 bit frame.
\r
723 * This function is used to quickly receive one 10-16 bits frame or two 4-8
\r
724 * bit frames by reading the RXDOUBLE register directly, without checking
\r
725 * the STATUS register for the RXDATAV flag. This can be useful from the
\r
726 * RXDATAV interrupt handler, i.e. waiting is superfluous, in order to
\r
727 * quickly read the received data.
\r
728 * This function is normally used to receive one frame when operating with
\r
729 * frame length 10-16 bits. Please refer to @ref USART_RxDoubleXGet()
\r
730 * for reception of two 9 bit frames.
\r
733 * Since this function does not check whether the RXDOUBLE register actually
\r
734 * holds valid data, it should only be used in situations when it is certain
\r
735 * that there is valid data, ensured by some external program routine, e.g.
\r
736 * like when handling an RXDATAV interrupt. The @ref USART_RxDouble() is
\r
737 * normally a better choice if the validity of the RXDOUBLE register is not
\r
741 * Notice that possible parity/stop bits in asynchronous mode are not
\r
742 * considered part of specified frame bit length.
\r
745 * Pointer to USART/UART peripheral register block.
\r
749 ******************************************************************************/
\r
750 __STATIC_INLINE uint16_t USART_RxDoubleGet(USART_TypeDef *usart)
\r
752 return (uint16_t) (usart->RXDOUBLE);
\r
756 /***************************************************************************//**
\r
758 * Receive two 4-9 bit frames, or one 10-16 bit frame with extended
\r
762 * This function is used to quickly receive one 10-16 bits frame or two 4-9
\r
763 * bit frames by reading the RXDOUBLEX register directly, without checking
\r
764 * the STATUS register for the RXDATAV flag. This can be useful from the
\r
765 * RXDATAV interrupt handler, i.e. waiting is superfluous, in order to
\r
766 * quickly read the received data.
\r
769 * Since this function does not check whether the RXDOUBLEX register actually
\r
770 * holds valid data, it should only be used in situations when it is certain
\r
771 * that there is valid data, ensured by some external program routine, e.g.
\r
772 * like when handling an RXDATAV interrupt. The @ref USART_RxDoubleExt() is
\r
773 * normally a better choice if the validity of the RXDOUBLEX register is not
\r
777 * Notice that possible parity/stop bits in asynchronous mode are not
\r
778 * considered part of specified frame bit length.
\r
781 * Pointer to USART/UART peripheral register block.
\r
785 ******************************************************************************/
\r
786 __STATIC_INLINE uint32_t USART_RxDoubleXGet(USART_TypeDef *usart)
\r
788 return usart->RXDOUBLEX;
\r
792 /***************************************************************************//**
\r
794 * Receive one 4-9 bit frame, (or part of 10-16 bit frame) with extended
\r
798 * This function is used to quickly receive one 4-9 bit frame, (or part of
\r
799 * 10-16 bit frame) with extended information by reading the RXDATAX register
\r
800 * directly, without checking the STATUS register for the RXDATAV flag. This
\r
801 * can be useful from the RXDATAV interrupt handler, i.e. waiting is
\r
802 * superfluous, in order to quickly read the received data.
\r
805 * Since this function does not check whether the RXDATAX register actually
\r
806 * holds valid data, it should only be used in situations when it is certain
\r
807 * that there is valid data, ensured by some external program routine, e.g.
\r
808 * like when handling an RXDATAV interrupt. The @ref USART_RxExt() is normally
\r
809 * a better choice if the validity of the RXDATAX register is not certain.
\r
812 * Notice that possible parity/stop bits in asynchronous mode are not
\r
813 * considered part of specified frame bit length.
\r
816 * Pointer to USART/UART peripheral register block.
\r
820 ******************************************************************************/
\r
821 __STATIC_INLINE uint16_t USART_RxDataXGet(USART_TypeDef *usart)
\r
823 return (uint16_t) (usart->RXDATAX);
\r
826 uint8_t USART_SpiTransfer(USART_TypeDef *usart, uint8_t data);
\r
827 void USART_Tx(USART_TypeDef *usart, uint8_t data);
\r
828 void USART_TxDouble(USART_TypeDef *usart, uint16_t data);
\r
829 void USART_TxDoubleExt(USART_TypeDef *usart, uint32_t data);
\r
830 void USART_TxExt(USART_TypeDef *usart, uint16_t data);
\r
833 /** @} (end addtogroup USART) */
\r
834 /** @} (end addtogroup EM_Library) */
\r
840 #endif /* defined(USART_COUNT) && (USART_COUNT > 0) */
\r
841 #endif /* __SILICON_LABS_EM_USART_H_ */
\r