Esp32/Components/driver/include/driver/uart.h File Reference
#include <esp_systemapi.h>
Include dependency graph for Esp32/Components/driver/include/driver/uart.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  smg_uart_
 
struct  smg_uart_config
 

Macros

#define UART0   0
 
#define UART1   1
 
#define UART2   2
 Virtualised UART0. More...
 
#define UART_NO   -1
 No UART specified. More...
 
#define UART_PHYSICAL_COUNT   UART_NUM_MAX
 Number of physical UARTs on the system. More...
 
#define UART_COUNT   UART_NUM_MAX
 Number of UARTs on the system, virtual or otherwise. More...
 
#define UART_NB_BIT_MASK   0B00001100
 
#define UART_NB_BIT_5   0B00000000
 
#define UART_NB_BIT_6   0B00000100
 
#define UART_NB_BIT_7   0B00001000
 
#define UART_NB_BIT_8   0B00001100
 
#define UART_PARITY_MASK   0B00000011
 
#define UART_PARITY_NONE   0B00000000
 
#define UART_PARITY_EVEN   0B00000010
 
#define UART_PARITY_ODD   0B00000011
 
#define UART_NB_STOP_BIT_MASK   0B00110000
 
#define UART_NB_STOP_BIT_0   0B00000000
 
#define UART_NB_STOP_BIT_1   0B00010000
 
#define UART_NB_STOP_BIT_15   0B00100000
 
#define UART_NB_STOP_BIT_2   0B00110000
 
#define UART_5N1   ( UART_NB_BIT_5 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 )
 
#define UART_6N1   ( UART_NB_BIT_6 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 )
 
#define UART_7N1   ( UART_NB_BIT_7 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 )
 
#define UART_8N1   ( UART_NB_BIT_8 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 )
 
#define UART_5N2   ( UART_NB_BIT_5 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 )
 
#define UART_6N2   ( UART_NB_BIT_6 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 )
 
#define UART_7N2   ( UART_NB_BIT_7 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 )
 
#define UART_8N2   ( UART_NB_BIT_8 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 )
 
#define UART_5E1   ( UART_NB_BIT_5 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 )
 
#define UART_6E1   ( UART_NB_BIT_6 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 )
 
#define UART_7E1   ( UART_NB_BIT_7 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 )
 
#define UART_8E1   ( UART_NB_BIT_8 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 )
 
#define UART_5E2   ( UART_NB_BIT_5 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 )
 
#define UART_6E2   ( UART_NB_BIT_6 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 )
 
#define UART_7E2   ( UART_NB_BIT_7 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 )
 
#define UART_8E2   ( UART_NB_BIT_8 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 )
 
#define UART_5O1   ( UART_NB_BIT_5 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 )
 
#define UART_6O1   ( UART_NB_BIT_6 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 )
 
#define UART_7O1   ( UART_NB_BIT_7 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 )
 
#define UART_8O1   ( UART_NB_BIT_8 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 )
 
#define UART_5O2   ( UART_NB_BIT_5 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 )
 
#define UART_6O2   ( UART_NB_BIT_6 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 )
 
#define UART_7O2   ( UART_NB_BIT_7 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 )
 
#define UART_8O2   ( UART_NB_BIT_8 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 )
 
#define UART_RX_FIFO_SIZE   0x80
 
#define UART_TX_FIFO_SIZE   0x80
 

Typedefs

typedef enum smg_uart_mode_ smg_uart_mode_t
 
typedef uint8_t uart_options_t
 
typedef struct smg_uart_ smg_uart_t
 
typedef void(* smg_uart_callback_t) (smg_uart_t *uart, uint32_t status)
 callback invoked directly from ISR More...
 
typedef void(* smg_uart_notify_callback_t) (smg_uart_t *uart, smg_uart_notify_code_t code)
 Port notification callback function type. More...
 

Enumerations

enum  smg_uart_mode_ {
  UART_FULL, UART_RX_ONLY, UART_TX_ONLY, UART_FULL,
  UART_RX_ONLY, UART_TX_ONLY
}
 values for mode argument of uart_init More...
 
enum  smg_uart_option_bits_t { UART_OPT_TXWAIT, UART_OPT_CALLBACK_RAW, UART_OPT_TXWAIT, UART_OPT_CALLBACK_RAW }
 bit values for options argument of uart_init More...
 
enum  smg_uart_notify_code_t {
  UART_NOTIFY_AFTER_OPEN, UART_NOTIFY_BEFORE_CLOSE, UART_NOTIFY_AFTER_WRITE, UART_NOTIFY_BEFORE_READ,
  UART_NOTIFY_WAIT_TX, UART_NOTIFY_AFTER_OPEN, UART_NOTIFY_BEFORE_CLOSE, UART_NOTIFY_AFTER_WRITE,
  UART_NOTIFY_BEFORE_READ, UART_NOTIFY_WAIT_TX
}
 Indicates notification, parameters refer to uart_notify_info_t structure. More...
 

Functions

bool smg_uart_set_notify (unsigned uart_nr, smg_uart_notify_callback_t callback)
 Set the notification callback function. More...
 
smg_uart_tsmg_uart_init (uint8_t uart_nr, uint32_t baudrate, uint32_t config, smg_uart_mode_t mode, uint8_t tx_pin, size_t rx_size, size_t tx_size=0)
 
smg_uart_tsmg_uart_init_ex (const smg_uart_config &cfg)
 
void smg_uart_uninit (smg_uart_t *uart)
 
int smg_uart_get_nr (smg_uart_t *uart)
 
smg_uart_tsmg_uart_get_uart (uint8_t uart_nr)
 Get the uart structure for the given number. More...
 
void smg_uart_set_callback (smg_uart_t *uart, smg_uart_callback_t callback, void *param)
 Set callback handler for serial port. More...
 
void * smg_uart_get_callback_param (smg_uart_t *uart)
 Get the callback parameter specified by uart_set_callback() More...
 
static void smg_uart_set_options (smg_uart_t *uart, uart_options_t options)
 Set option flags. More...
 
uint8_t smg_uart_get_status (smg_uart_t *uart)
 Get error flags and clear them. More...
 
static uart_options_t smg_uart_get_options (smg_uart_t *uart)
 
void smg_uart_set_tx (smg_uart_t *uart, int tx_pin)
 
void smg_uart_set_pins (smg_uart_t *uart, int tx, int rx)
 
void smg_uart_swap (smg_uart_t *uart, int tx_pin)
 
bool smg_uart_tx_enabled (smg_uart_t *uart)
 
bool smg_uart_rx_enabled (smg_uart_t *uart)
 
uint32_t smg_uart_set_baudrate_reg (int uart_nr, uint32_t baud_rate)
 set UART baud rate, given the UART number More...
 
uint32_t smg_uart_set_baudrate (smg_uart_t *uart, uint32_t baud_rate)
 set UART baud rate More...
 
uint32_t smg_uart_get_baudrate (smg_uart_t *uart)
 get the actual baud rate in use More...
 
size_t smg_uart_resize_rx_buffer (smg_uart_t *uart, size_t new_size)
 
size_t smg_uart_rx_buffer_size (smg_uart_t *uart)
 
size_t smg_uart_resize_tx_buffer (smg_uart_t *uart, size_t new_size)
 
size_t smg_uart_tx_buffer_size (smg_uart_t *uart)
 
size_t smg_uart_write (smg_uart_t *uart, const void *buffer, size_t size)
 write a block of data More...
 
static size_t smg_uart_write_char (smg_uart_t *uart, char c)
 queue a single character for output More...
 
size_t smg_uart_read (smg_uart_t *uart, void *buffer, size_t size)
 read a block of data More...
 
static int smg_uart_read_char (smg_uart_t *uart)
 read a received character More...
 
int smg_uart_peek_char (smg_uart_t *uart)
 see what the next character in the rx buffer is More...
 
int smg_uart_peek_last_char (smg_uart_t *uart)
 fetch last character read out of FIFO More...
 
int smg_uart_rx_find (smg_uart_t *uart, char c)
 
size_t smg_uart_rx_available (smg_uart_t *uart)
 determine available data which can be read More...
 
size_t smg_uart_tx_free (smg_uart_t *uart)
 return free space in transmit buffer More...
 
void smg_uart_wait_tx_empty (smg_uart_t *uart)
 
void smg_uart_set_break (smg_uart_t *uart, bool state)
 Set or clear a break condition on the TX line. More...
 
void smg_uart_flush (smg_uart_t *uart, smg_uart_mode_t mode=UART_FULL)
 discard any buffered data and reset hardware FIFOs More...
 
void smg_uart_set_debug (int uart_nr)
 
int smg_uart_get_debug ()
 
uint8_t smg_uart_disable_interrupts ()
 disable interrupts and return current interrupt state More...
 
void smg_uart_restore_interrupts ()
 re-enable interrupts after calling uart_disable_interrupts() More...
 

Function Documentation

◆ smg_uart_get_options()

static uart_options_t smg_uart_get_options ( smg_uart_t uart)
inlinestatic

◆ smg_uart_read_char()

static int smg_uart_read_char ( smg_uart_t uart)
inlinestatic

read a received character

Parameters
uart
Return values
thecharacter, -1 on failure

◆ smg_uart_set_options()

static void smg_uart_set_options ( smg_uart_t uart,
uart_options_t  options 
)
inlinestatic

Set option flags.

Parameters
uart
optionsThe option(s) to set

◆ smg_uart_write_char()

static size_t smg_uart_write_char ( smg_uart_t uart,
char  c 
)
inlinestatic

queue a single character for output

Parameters
uart
c
Return values
size_t1 if character was written, 0 on failure