39 #if defined (__cplusplus) 43 #include <esp_systemapi.h> 55 #define UART_PHYSICAL_COUNT 2 59 #define UART_NB_BIT_MASK 0B00001100 60 #define UART_NB_BIT_5 0B00000000 61 #define UART_NB_BIT_6 0B00000100 62 #define UART_NB_BIT_7 0B00001000 63 #define UART_NB_BIT_8 0B00001100 65 #define UART_PARITY_MASK 0B00000011 66 #define UART_PARITY_NONE 0B00000000 67 #define UART_PARITY_EVEN 0B00000010 68 #define UART_PARITY_ODD 0B00000011 70 #define UART_NB_STOP_BIT_MASK 0B00110000 71 #define UART_NB_STOP_BIT_0 0B00000000 72 #define UART_NB_STOP_BIT_1 0B00010000 73 #define UART_NB_STOP_BIT_15 0B00100000 74 #define UART_NB_STOP_BIT_2 0B00110000 76 #define UART_5N1 ( UART_NB_BIT_5 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) 77 #define UART_6N1 ( UART_NB_BIT_6 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) 78 #define UART_7N1 ( UART_NB_BIT_7 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) 79 #define UART_8N1 ( UART_NB_BIT_8 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) 80 #define UART_5N2 ( UART_NB_BIT_5 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) 81 #define UART_6N2 ( UART_NB_BIT_6 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) 82 #define UART_7N2 ( UART_NB_BIT_7 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) 83 #define UART_8N2 ( UART_NB_BIT_8 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) 84 #define UART_5E1 ( UART_NB_BIT_5 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) 85 #define UART_6E1 ( UART_NB_BIT_6 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) 86 #define UART_7E1 ( UART_NB_BIT_7 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) 87 #define UART_8E1 ( UART_NB_BIT_8 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) 88 #define UART_5E2 ( UART_NB_BIT_5 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) 89 #define UART_6E2 ( UART_NB_BIT_6 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) 90 #define UART_7E2 ( UART_NB_BIT_7 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) 91 #define UART_8E2 ( UART_NB_BIT_8 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) 92 #define UART_5O1 ( UART_NB_BIT_5 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) 93 #define UART_6O1 ( UART_NB_BIT_6 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) 94 #define UART_7O1 ( UART_NB_BIT_7 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) 95 #define UART_8O1 ( UART_NB_BIT_8 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) 96 #define UART_5O2 ( UART_NB_BIT_5 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) 97 #define UART_6O2 ( UART_NB_BIT_6 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) 98 #define UART_7O2 ( UART_NB_BIT_7 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) 99 #define UART_8O2 ( UART_NB_BIT_8 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) 118 #define UART_RX_FIFO_SIZE 0x80 119 #define UART_TX_FIFO_SIZE 0x80 213 return uart ? uart->
uart_nr : -1;
235 return uart ? uart->
param :
nullptr;
263 return uart ? uart->
options : 0;
406 if (uart !=
nullptr) {
433 #if defined (__cplusplus) int uart_peek_last_char(uart_t *uart)
fetch last character read out of FIFO
void(* uart_callback_t)(uart_t *uart, uint32_t status)
callback invoked directly from ISR
Definition: uart.h:135
uint8_t tx_pin
Definition: uart.h:183
uint8_t rx_pin
Definition: uart.h:182
Called immediately before uart is closed and destroyed.
Definition: uart.h:149
void * uart_get_callback_param(uart_t *uart)
Get the callback parameter specified by uart_set_callback()
Definition: uart.h:233
#define __forceinline
Definition: sming_attr.h:13
size_t uart_rx_available(uart_t *uart)
determine available data which can be read
size_t uart_tx_free(uart_t *uart)
return free space in transmit buffer
If buffers are full then uart_write() will wait for free space.
Definition: uart.h:114
void uart_start_isr(uart_t *uart)
enable interrupts for a UART
Called when uart has been iniitialised successfully.
Definition: uart.h:146
Called before data is read from rx buffer.
Definition: uart.h:155
bool uart_rx_enabled(uart_t *uart)
Definition: uart.h:275
uint8_t uart_nr
Definition: uart.h:194
static uart_options_t uart_get_options(uart_t *uart)
Definition: uart.h:261
uint32_t uart_set_baudrate(uart_t *uart, uint32_t baud_rate)
set UART baud rate
uint16_t status
All status flags reported to callback since last uart_get_status() call.
Definition: uart.h:185
void uart_detach(int uart_nr)
detach a UART interrupt service routine
static size_t uart_write_char(uart_t *uart, char c)
queue a single character for output
Definition: uart.h:319
size_t uart_rx_buffer_size(uart_t *uart)
uint32_t uart_get_baudrate(uart_t *uart)
get the actual baud rate in use
void * param
User-supplied callback parameter.
Definition: uart.h:189
Both receive and transmit - will revert to TX only if RX not supported.
Definition: uart.h:103
uint32_t uart_set_baudrate_reg(int uart_nr, uint32_t baud_rate)
set UART baud rate, given the UART number
int uart_get_nr(uart_t *uart)
Definition: uart.h:211
uart_callback_t callback
Optional User callback routine.
Definition: uart.h:188
int uart_rx_find(uart_t *uart, char c)
void uart_swap(uart_t *uart, int tx_pin)
enum uart_mode_ uart_mode_t
Definition: uart.h:107
uint32_t baud_rate
Definition: uart.h:179
void uart_restore_interrupts()
re-enable interrupts after calling uart_disable_interrupts()
uart_options_t options
Definition: uart.h:197
size_t uart_resize_rx_buffer(uart_t *uart, size_t new_size)
static int uart_read_char(uart_t *uart)
read a received character
Definition: uart.h:336
int uart_peek_char(uart_t *uart)
see what the next character in the rx buffer is
void uart_detach_all()
detach all UART interrupt service routines
uint8_t uart_nr
Definition: uart.h:178
uint8_t uart_disable_interrupts()
disable interrupts and return current interrupt state
uint8_t rx_headroom
Callback when rx_buffer free space <= headroom.
Definition: uart.h:184
void uart_set_break(uart_t *uart, bool state)
Set or clear a break condition on the TX line.
ISR invokes user callback function with no pre-processing.
Definition: uart.h:115
size_t uart_write(uart_t *uart, const void *buffer, size_t size)
write a block of data
uart_t * uart_init_ex(const uart_config &cfg)
uart_t * uart_get_uart(uint8_t uart_nr)
Get the uart structure for the given number.
void uart_uninit(uart_t *uart)
size_t uart_read(uart_t *uart, void *buffer, size_t size)
read a block of data
bool uart_tx_enabled(uart_t *uart)
Definition: uart.h:270
Transmit only.
Definition: uart.h:105
void(* uart_notify_callback_t)(uart_t *uart, uart_notify_code_t code)
Port notification callback function type.
Definition: uart.h:165
uint32_t config
UART CONF0 register bits.
Definition: uart.h:199
void uart_set_pins(uart_t *uart, int tx, int rx)
size_t uart_resize_tx_buffer(uart_t *uart, size_t new_size)
static void uart_set_options(uart_t *uart, uart_options_t options)
Set option flags.
Definition: uart.h:242
Called after data has been written into tx buffer.
Definition: uart.h:152
uint32_t baudrate
Requested baudrate; actual baudrate may differ.
Definition: uart.h:198
bool uart_set_notify(unsigned uart_nr, uart_notify_callback_t callback)
Set the notification callback function.
Called to ensure all buffered data is output.
Definition: uart.h:158
uart_mode_t mode
Whether to enable receive, transmit or both.
Definition: uart.h:196
uart_option_bits_t
bit values for options argument of uart_init
Definition: uart.h:113
uart_t * uart_init(uint8_t uart_nr, uint32_t baudrate, uint32_t config, uart_mode_t mode, uint8_t tx_pin, size_t rx_size, size_t tx_size=0)
uint8_t tx_pin
Specify 2 for alternate pin, otherwise defaults to pin 1.
Definition: uart.h:195
void uart_set_debug(int uart_nr)
void uart_wait_tx_empty(uart_t *uart)
void uart_stop_isr(uart_t *uart)
disable interrupts for a UART
Definition: uart.h:403
uint8_t options
Definition: uart.h:181
uint8_t uart_get_status(uart_t *uart)
Get error flags and clear them.
uart_mode_t mode
Definition: uart.h:180
struct SerialBuffer * rx_buffer
Optional receive buffer.
Definition: uart.h:186
void uart_set_tx(uart_t *uart, int tx_pin)
uint8_t uart_options_t
Definition: uart.h:109
size_t rx_size
Definition: uart.h:200
uart_notify_code_t
Indicates notification, parameters refer to uart_notify_info_t structure.
Definition: uart.h:144
void uart_set_callback(uart_t *uart, uart_callback_t callback, void *param)
Set callback handler for serial port.
size_t tx_size
Definition: uart.h:201
uart_mode_
values for mode argument of uart_init
Definition: uart.h:102
Receive only.
Definition: uart.h:104
void uart_flush(uart_t *uart, uart_mode_t mode=UART_FULL)
discard any buffered data and reset hardware FIFOs
size_t uart_tx_buffer_size(uart_t *uart)
struct SerialBuffer * tx_buffer
Optional transmit buffer.
Definition: uart.h:187