hci_uart.h 2.4 KB

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