esp_avrc_api.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_AVRC_API_H__
  14. #define __ESP_AVRC_API_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "esp_bt_defs.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /// AVRC feature bit mask
  23. typedef enum {
  24. ESP_AVRC_FEAT_RCTG = 0x0001, /*!< remote control target */
  25. ESP_AVRC_FEAT_RCCT = 0x0002, /*!< remote control controller */
  26. ESP_AVRC_FEAT_VENDOR = 0x0008, /*!< remote control vendor dependent commands */
  27. ESP_AVRC_FEAT_BROWSE = 0x0010, /*!< use browsing channel */
  28. ESP_AVRC_FEAT_META_DATA = 0x0040, /*!< remote control metadata transfer command/response */
  29. ESP_AVRC_FEAT_ADV_CTRL = 0x0200, /*!< remote control advanced control commmand/response */
  30. } esp_avrc_features_t;
  31. /// AVRC passthrough command code
  32. typedef enum {
  33. ESP_AVRC_PT_CMD_PLAY = 0x44, /*!< play */
  34. ESP_AVRC_PT_CMD_STOP = 0x45, /*!< stop */
  35. ESP_AVRC_PT_CMD_PAUSE = 0x46, /*!< pause */
  36. ESP_AVRC_PT_CMD_FORWARD = 0x4B, /*!< forward */
  37. ESP_AVRC_PT_CMD_BACKWARD = 0x4C /*!< backward */
  38. } esp_avrc_pt_cmd_t;
  39. /// AVRC passthrough command state
  40. typedef enum {
  41. ESP_AVRC_PT_CMD_STATE_PRESSED = 0, /*!< key pressed */
  42. ESP_AVRC_PT_CMD_STATE_RELEASED = 1 /*!< key released */
  43. } esp_avrc_pt_cmd_state_t;
  44. /// AVRC Controller callback events
  45. typedef enum {
  46. ESP_AVRC_CT_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */
  47. ESP_AVRC_CT_PASSTHROUGH_RSP_EVT = 1, /*!< passthrough response event */
  48. ESP_AVRC_CT_MAX_EVT
  49. } esp_avrc_ct_cb_event_t;
  50. /// AVRC controller callback parameters
  51. typedef union {
  52. /**
  53. * @brief ESP_AVRC_CT_CONNECTION_STATE_EVT
  54. */
  55. struct avrc_ct_conn_stat_param {
  56. bool connected; /*!< whether AVRC connection is set up */
  57. uint32_t feat_mask; /*!< AVRC feature mask of remote device */
  58. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  59. } conn_stat; /*!< AVRC connection status */
  60. /**
  61. * @brief ESP_AVRC_CT_PASSTHROUGH_RSP_EVT
  62. */
  63. struct avrc_ct_psth_rsp_param {
  64. uint8_t tl; /*!< transaction label, 0 to 15 */
  65. uint8_t key_code; /*!< passthrough command code */
  66. uint8_t key_state; /*!< 0 for PRESSED, 1 for RELEASED */
  67. } psth_rsp; /*!< passthrough command response */
  68. } esp_avrc_ct_cb_param_t;
  69. /**
  70. * @brief AVRCP controller callback function type
  71. * @param event : Event type
  72. * @param param : Pointer to callback parameter union
  73. */
  74. typedef void (* esp_avrc_ct_cb_t)(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
  75. /**
  76. * @brief Register application callbacks to AVRCP module; for now only AVRCP Controller
  77. * role is supported. This function should be called after esp_bluedroid_enable()
  78. * completes successfully
  79. *
  80. * @param[in] callback: AVRCP controller callback function
  81. *
  82. * @return
  83. * - ESP_OK: success
  84. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  85. * - ESP_FAIL: others
  86. *
  87. */
  88. esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback);
  89. /**
  90. *
  91. * @brief Initialize the bluetooth AVRCP controller module, This function should be called
  92. * after esp_bluedroid_enable() completes successfully
  93. *
  94. * @return
  95. * - ESP_OK: success
  96. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  97. * - ESP_FAIL: others
  98. *
  99. */
  100. esp_err_t esp_avrc_ct_init(void);
  101. /**
  102. *
  103. * @brief De-initialize AVRCP controller module. This function should be called after
  104. * after esp_bluedroid_enable() completes successfully
  105. *
  106. * @return
  107. * - ESP_OK: success
  108. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  109. * - ESP_FAIL: others
  110. */
  111. esp_err_t esp_avrc_ct_deinit(void);
  112. /**
  113. * @brief Send passthrough command to AVRCP target, This function should be called after
  114. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established
  115. *
  116. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  117. * @param[in] key_code : passthrough command code, e.g. ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STOP, etc.
  118. * @param[in] key_state : passthrough command key state, ESP_AVRC_PT_CMD_STATE_PRESSED or
  119. * ESP_AVRC_PT_CMD_STATE_PRESSED
  120. *
  121. * @return
  122. * - ESP_OK: success
  123. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  124. * - ESP_FAIL: others
  125. */
  126. esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state);
  127. #ifdef __cplusplus
  128. }
  129. #endif
  130. #endif /* __ESP_AVRC_API_H__ */