1 /* 2 * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #include <inttypes.h> 14 #include "driver/uart.h" 15 16 /** 17 * Function prototype for UART driver to ask for more data to send. 18 * Returns -1 if no more data is available for TX. 19 * Driver must call this with interrupts disabled. 20 */ 21 typedef int (*hci_uart_tx_char)(void *arg); 22 23 /** 24 * Function prototype for UART driver to report that transmission is 25 * complete. This should be called when transmission of last byte is 26 * finished. 27 * Driver must call this with interrupts disabled. 28 */ 29 typedef void (*hci_uart_tx_done)(void *arg); 30 31 /** 32 * Function prototype for UART driver to report incoming byte of data. 33 * Returns -1 if data was dropped. 34 * Driver must call this with interrupts disabled. 35 */ 36 typedef int (*hci_uart_rx_char)(void *arg, uint8_t byte); 37 38 39 /** 40 * Initializes given uart. Mapping of logical UART number to physical 41 * UART/GPIO pins is in BSP. 42 */ 43 int hci_uart_init_cbs(int uart, hci_uart_tx_char tx_func, 44 hci_uart_tx_done tx_done, hci_uart_rx_char rx_func, void *arg); 45 46 47 /** 48 * Applies given configuration to UART. 49 * 50 * @param port_num The UART number to configure 51 * @param speed The baudrate in bps to configure 52 * @param databits The number of databits to send per byte 53 * @param stopbits The number of stop bits to send 54 * @param parity The UART parity 55 * @param flow_ctl Flow control settings on the UART 56 * 57 * @return 0 on success, non-zero error code on failure 58 */ 59 int hci_uart_config(int port_num, int32_t baud_rate, uint8_t data_bits, uint8_t stop_bits, 60 uart_parity_t parity, uart_hw_flowcontrol_t flow_ctl); 61 62 /** 63 * Close UART port. Can call hal_uart_config() with different settings after 64 * calling this. 65 * 66 * @param port_num The UART number to close 67 */ 68 int hci_uart_close(int port_num); 69 70 /** 71 * More data queued for transmission. UART driver will start asking for that 72 * data. 73 * 74 * @param port_num The UART number to start TX on 75 */ 76 void hci_uart_start_tx(int port_num); 77 78 /** 79 * Upper layers have consumed some data, and are now ready to receive more. 80 * This is meaningful after uart_rx_char callback has returned -1 telling 81 * that no more data can be accepted. 82 * 83 * @param port_num The UART number to begin RX on 84 */ 85 void hci_uart_start_rx(int port_num); 86 87 /** 88 * @brief reconfig hci uart pin 89 * 90 * @param tx_pin The Tx pin 91 * @param rx_pin The Rx pin 92 * @param cts_pin The CTS pin 93 * @param rts_pin The RTS pin 94 * @return int 0 on success, non-zero error code on failure 95 */ 96 int hci_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin); 97 98 #ifdef __cplusplus 99 } 100 #endif 101