mikroSDK Reference Manual
drv_uart.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2024 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
48extern "C"{
49#endif
50
51#include "drv_name.h"
52#include "hal_uart.h"
53#include "ring.h"
54
58typedef enum
59{
61 UART_ERROR = (-1)
63
75
87
100
153
178
233
287
312err_t uart_set_baud( uart_t *obj, uint32_t baud );
313
340
367
394
412void uart_set_blocking( uart_t *obj, bool blocking );
413
446err_t uart_write( uart_t *obj, uint8_t *buffer, size_t size );
447
476err_t uart_print( uart_t *obj, char *text );
477
506err_t uart_println( uart_t *obj, char *text );
507
540err_t uart_read( uart_t *obj, uint8_t *buffer, size_t size );
541
561
578void uart_clear( uart_t *obj );
579
605
606 // drvuartgroup
607 // drvgroup
608 // pergroup
609
610#ifdef __cplusplus
611}
612#endif
613
614#endif // _DRV_UART_H_
615// ------------------------------------------------------------------------- END
Pin and port name type definitions.
hal_pin_name_t pin_name_t
Definition drv_name.h:74
uart_parity_t
Definition drv_uart.h:80
@ UART_PARITY_DEFAULT
Definition drv_uart.h:85
@ UART_PARITY_NONE
Definition drv_uart.h:81
@ UART_PARITY_EVEN
Definition drv_uart.h:82
@ UART_PARITY_ODD
Definition drv_uart.h:83
uart_stop_bits_t
Definition drv_uart.h:92
@ UART_STOP_BITS_ONE_AND_A_HALF
Definition drv_uart.h:95
@ UART_STOP_BITS_HALF
Definition drv_uart.h:93
@ UART_STOP_BITS_ONE
Definition drv_uart.h:94
@ UART_STOP_BITS_DEFAULT
Definition drv_uart.h:98
@ UART_STOP_BITS_TWO
Definition drv_uart.h:96
uart_data_bits_t
Definition drv_uart.h:68
@ UART_DATA_BITS_7
Definition drv_uart.h:69
@ UART_DATA_BITS_9
Definition drv_uart.h:71
@ UART_DATA_BITS_8
Definition drv_uart.h:70
@ UART_DATA_BITS_DEFAULT
Definition drv_uart.h:73
uart_err_t
Definition drv_uart.h:59
@ UART_SUCCESS
Definition drv_uart.h:60
@ UART_ERROR
Definition drv_uart.h:61
void uart_configure_default(uart_config_t *config)
Configure UART Driver configuration structure.
err_t uart_close(uart_t *obj)
Close UART Driver object.
err_t uart_read(uart_t *obj, uint8_t *buffer, size_t size)
Read data from UART.
err_t uart_set_parity(uart_t *obj, uart_parity_t parity)
Set the UART parity.
err_t uart_print(uart_t *obj, char *text)
Print the string to UART.
err_t uart_write(uart_t *obj, uint8_t *buffer, size_t size)
Write data to UART.
err_t uart_set_baud(uart_t *obj, uint32_t baud)
Set the UART baud rate.
err_t uart_set_data_bits(uart_t *obj, uart_data_bits_t bits)
Set the number of UART data bits.
void uart_set_blocking(uart_t *obj, bool blocking)
Set UART Driver in blocking/non-blocking mode.
void uart_clear(uart_t *obj)
Discard all characters from UART buffers.
err_t uart_println(uart_t *obj, char *text)
Print the string to UART and append new line.
err_t uart_open(uart_t *obj, uart_config_t *config)
Open the UART Driver object.
err_t uart_set_stop_bits(uart_t *obj, uart_stop_bits_t stop)
Set the number of UART stop bits.
size_t uart_bytes_available(uart_t *obj)
Check number of bytes available to read from UART.
int32_t err_t
Definition hal_target.h:64
API for UART HAL level.
UART init configuration structure, consisted of the following fields :
Definition drv_uart.h:138
size_t tx_ring_size
Definition drv_uart.h:150
uint32_t baud
Definition drv_uart.h:142
uart_parity_t parity
Definition drv_uart.h:144
size_t rx_ring_size
Definition drv_uart.h:151
pin_name_t rx_pin
Definition drv_uart.h:140
ring_buf8_t rx_buf
Definition drv_uart.h:148
pin_name_t tx_pin
Definition drv_uart.h:139
ring_buf8_t tx_buf
Definition drv_uart.h:147
uart_stop_bits_t stop_bits
Definition drv_uart.h:145
uart_data_bits_t data_bits
Definition drv_uart.h:143
UART driver context structure, consisted of the following fields :
Definition drv_uart.h:165
handle_t handle
Definition drv_uart.h:166
uint8_t * tx_ring_buffer
Definition drv_uart.h:170
bool is_blocking
Definition drv_uart.h:176
bool is_rx_irq_enabled
Definition drv_uart.h:174
uart_config_t config
Definition drv_uart.h:168
bool is_tx_irq_enabled
Definition drv_uart.h:173
uint8_t * rx_ring_buffer
Definition drv_uart.h:171