bt_drv.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2020 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief Public API for BT driver
  9. */
  10. #ifndef __BT_DRV_H__
  11. #define __BT_DRV_H__
  12. #define HCI_CMD 0x01
  13. #define HCI_ACL 0x02
  14. #define HCI_SCO 0x03
  15. #define HCI_EVT 0x04
  16. #define HCI_ISO 0x05
  17. #define HCI_CMD_HDR_SIZE 3
  18. #define HCI_ACL_HDR_SIZE 4
  19. #define HCI_SCO_HDR_SIZE 3
  20. #define HCI_EVT_HDR_SIZE 2
  21. #define HCI_ISO_HDR_SIZE 4
  22. #define HCI_L2CAP_HEAD_SIZE 4
  23. #define BT_ACL_HDL_FLAG_START 0x02
  24. #define L2CAP_BR_MAX_MTU_A2DP_AAC 895 /* Value same as define in L2cap.h */
  25. #ifdef CONFIG_BT_RX_BUF_LEN
  26. #define BT_MAX_RX_ACL_LEN CONFIG_BT_RX_BUF_LEN
  27. #else
  28. #define BT_MAX_RX_ACL_LEN 0
  29. #endif
  30. #define BT_TWS_0 0
  31. #define BT_TWS_1 1
  32. typedef struct btdrv_init_param {
  33. uint8_t set_hosc_cap:1;
  34. uint8_t set_max_rf_power:1;
  35. uint8_t set_ble_rf_power:1;
  36. uint8_t hosc_capacity;
  37. uint8_t bt_max_rf_tx_power;
  38. uint8_t ble_rf_tx_power;
  39. } btdrv_init_param_t;
  40. typedef void (*btdrv_tws_cb_t)(void);
  41. typedef struct btdrv_hci_cb {
  42. /**
  43. * @brief get buffer to receive hci data.
  44. * @param type hci data type.
  45. * @param evt hci event code.
  46. * @param exp_len, 0 default buffer lengh, other: expect buffer length.
  47. * @return buffer to receive hci data.
  48. */
  49. uint8_t * (*get_buf)(uint8_t type, uint8_t evt, uint16_t exp_len);
  50. /**
  51. * @brief recv hci data callback.
  52. * @param len length of hci data.
  53. * @return 0 for success, non-zero otherwise.
  54. */
  55. int (*recv)(uint16_t len);
  56. } btdrv_hci_cb_t;
  57. /**
  58. * @brief initialize bt controller init parameter, call before btdrv_init.
  59. * @param param Initialize paramter.
  60. * @return 0 on success, no-zero otherwise.
  61. */
  62. int btdrv_set_init_param(btdrv_init_param_t *param);
  63. /**
  64. * @brief initialize bt controller.
  65. * @param cb callback structure to receive hci data.
  66. * @return 0 on success, no-zero otherwise.
  67. */
  68. int btdrv_init(btdrv_hci_cb_t *cb);
  69. /**
  70. * @brief send hci data to bt controller.
  71. * @param type hci data type.
  72. * @param data hci data.
  73. * @param len length of hci data.
  74. * @return 0 on success, no-zero otherwise.
  75. */
  76. int btdrv_send(uint8_t type, uint8_t *data, uint16_t len);
  77. int btdrv_tws_irq_enable(uint8_t index);
  78. int btdrv_tws_irq_disable(uint8_t index);
  79. int btdrv_tws_irq_cb_set(uint8_t index, btdrv_tws_cb_t cb);
  80. int btdrv_tws_set_mode(uint8_t index, uint8_t mode);
  81. #endif