mikroSDK Reference Manual
drv_uart.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2023 MikroElektronika d.o.o.
4 ** Contact: https://www.mikroe.com/contact
5 **
6 ** This file is part of the mikroSDK package
7 **
8 ** Commercial License Usage
9 **
10 ** Licensees holding valid commercial NECTO compilers AI licenses may use this
11 ** file in accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The MikroElektronika Company.
14 ** For licensing terms and conditions see
15 ** https://www.mikroe.com/legal/software-license-agreement.
16 ** For further information use the contact form at
17 ** https://www.mikroe.com/contact.
18 **
19 **
20 ** GNU Lesser General Public License Usage
21 **
22 ** Alternatively, this file may be used for
23 ** non-commercial projects under the terms of the GNU Lesser
24 ** General Public License version 3 as published by the Free Software
25 ** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** The above copyright notice and this permission notice shall be
28 ** included in all copies or substantial portions of the Software.
29 **
30 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 ** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32 ** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 **
38 ****************************************************************************/
44 #ifndef _DRV_UART_H_
45 #define _DRV_UART_H_
46 
47 #ifdef __cplusplus
48 extern "C"{
49 #endif
50 
51 #include "drv_name.h"
52 #include "hal_uart.h"
53 #include "ring.h"
54 
58 typedef enum
59 {
61  UART_ERROR = (-1)
62 } uart_err_t;
63 
67 typedef enum
68 {
75 
79 typedef enum
80 {
87 
91 typedef enum
92 {
100 
137 typedef struct
138 {
139  pin_name_t tx_pin;
140  pin_name_t rx_pin;
142  uint32_t baud;
143  uart_data_bits_t data_bits;
144  uart_parity_t parity;
145  uart_stop_bits_t stop_bits;
147  ring_buf8_t tx_buf;
148  ring_buf8_t rx_buf;
150  size_t tx_ring_size;
151  size_t rx_ring_size;
152 } uart_config_t;
153 
164 typedef struct
165 {
166  handle_t handle;
168  uart_config_t config;
170  uint8_t *tx_ring_buffer;
171  uint8_t *rx_ring_buffer;
173  bool is_tx_irq_enabled;
174  bool is_rx_irq_enabled;
176  bool is_blocking;
177 } uart_t;
178 
232 void uart_configure_default( uart_config_t *config );
233 
286 err_t uart_open( uart_t *obj, uart_config_t *config );
287 
312 err_t uart_set_baud( uart_t *obj, uint32_t baud );
313 
339 err_t uart_set_parity( uart_t *obj, uart_parity_t parity );
340 
367 
394 
412 void uart_set_blocking( uart_t *obj, bool blocking );
413 
446 err_t uart_write( uart_t *obj, uint8_t *buffer, size_t size );
447 
476 err_t uart_print( uart_t *obj, char *text );
477 
506 err_t uart_println( uart_t *obj, char *text );
507 
540 err_t uart_read( uart_t *obj, uint8_t *buffer, size_t size );
541 
560 size_t uart_bytes_available( uart_t *obj );
561 
578 void uart_clear( uart_t *obj );
579 
604 err_t uart_close( uart_t *obj );
605  // drvuartgroup // drvgroup // pergroup
609 
610 #ifdef __cplusplus
611 }
612 #endif
613 
614 #endif // _DRV_UART_H_
615 // ------------------------------------------------------------------------- END
UART_ERROR
Definition: drv_uart.h:60
drv_name.h
Pin and port name type definitions.
uart_clear
void uart_clear(uart_t *obj)
Discard all characters from UART buffers.
UART_PARITY_EVEN
Definition: drv_uart.h:81
UART_PARITY_ODD
Definition: drv_uart.h:82
uart_set_blocking
void uart_set_blocking(uart_t *obj, bool blocking)
Set UART Driver in blocking/non-blocking mode.
uart_print
err_t uart_print(uart_t *obj, char *text)
Print the string to UART.
uart_data_bits_t
uart_data_bits_t
Definition: drv_uart.h:66
UART_PARITY_DEFAULT
Definition: drv_uart.h:84
uart_parity_t
uart_parity_t
Definition: drv_uart.h:78
uart_open
err_t uart_open(uart_t *obj, uart_config_t *config)
Open the UART Driver object.
UART_DATA_BITS_8
Definition: drv_uart.h:69
uart_stop_bits_t
uart_stop_bits_t
Definition: drv_uart.h:90
uart_println
err_t uart_println(uart_t *obj, char *text)
Print the string to UART and append new line.
UART_STOP_BITS_DEFAULT
Definition: drv_uart.h:97
uart_close
err_t uart_close(uart_t *obj)
Close UART Driver object.
UART_STOP_BITS_ONE_AND_A_HALF
Definition: drv_uart.h:94
uart_err_t
uart_err_t
Definition: drv_uart.h:57
uart_set_stop_bits
err_t uart_set_stop_bits(uart_t *obj, uart_stop_bits_t stop)
Set the number of UART stop bits.
uart_set_parity
err_t uart_set_parity(uart_t *obj, uart_parity_t parity)
Set the UART parity.
uart_t
UART driver context structure, consisted of the following fields :
Definition: drv_uart.h:163
UART_SUCCESS
Definition: drv_uart.h:59
UART_DATA_BITS_DEFAULT
Definition: drv_uart.h:72
uart_set_data_bits
err_t uart_set_data_bits(uart_t *obj, uart_data_bits_t bits)
Set the number of UART data bits.
uart_write
err_t uart_write(uart_t *obj, uint8_t *buffer, size_t size)
Write data to UART.
UART_STOP_BITS_TWO
Definition: drv_uart.h:95
UART_PARITY_NONE
Definition: drv_uart.h:80
uart_read
err_t uart_read(uart_t *obj, uint8_t *buffer, size_t size)
Read data from UART.
UART_DATA_BITS_9
Definition: drv_uart.h:70
UART_DATA_BITS_7
Definition: drv_uart.h:68
uart_bytes_available
size_t uart_bytes_available(uart_t *obj)
Check number of bytes available to read from UART.
uart_config_t
UART init configuration structure, consisted of the following fields :
Definition: drv_uart.h:136
uart_set_baud
err_t uart_set_baud(uart_t *obj, uint32_t baud)
Set the UART baud rate.
pin_name_t
hal_pin_name_t pin_name_t
Definition: drv_name.h:73
hal_uart.h
API for UART HAL level.
err_t
int32_t err_t
Definition: hal_target.h:63
uart_configure_default
void uart_configure_default(uart_config_t *config)
Configure UART Driver configuration structure.
UART_STOP_BITS_HALF
Definition: drv_uart.h:92
UART_STOP_BITS_ONE
Definition: drv_uart.h:93