esp_avrc_api.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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_REWIND = 0x48, /*!< rewind */
  39. ESP_AVRC_PT_CMD_FAST_FORWARD = 0x49 /*!< fast forward */
  40. } esp_avrc_pt_cmd_t;
  41. /// AVRC passthrough command state
  42. typedef enum {
  43. ESP_AVRC_PT_CMD_STATE_PRESSED = 0, /*!< key pressed */
  44. ESP_AVRC_PT_CMD_STATE_RELEASED = 1 /*!< key released */
  45. } esp_avrc_pt_cmd_state_t;
  46. /// AVRC Controller callback events
  47. typedef enum {
  48. ESP_AVRC_CT_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */
  49. ESP_AVRC_CT_PASSTHROUGH_RSP_EVT = 1, /*!< passthrough response event */
  50. ESP_AVRC_CT_METADATA_RSP_EVT = 2, /*!< metadata response event */
  51. ESP_AVRC_CT_PLAY_STATUS_RSP_EVT = 3, /*!< play status response event */
  52. ESP_AVRC_CT_CHANGE_NOTIFY_EVT = 4, /*!< notification event */
  53. ESP_AVRC_CT_MAX_EVT
  54. } esp_avrc_ct_cb_event_t;
  55. //AVRC metadata attribute mask
  56. typedef enum {
  57. ESP_AVRC_MD_ATTR_TITLE = 0x1, /*!< title of the playing track */
  58. ESP_AVRC_MD_ATTR_ARTIST = 0x2, /*!< track artist */
  59. ESP_AVRC_MD_ATTR_ALBUM = 0x4, /*!< album name */
  60. ESP_AVRC_MD_ATTR_TRACK_NUM = 0x8, /*!< track position on the album */
  61. ESP_AVRC_MD_ATTR_NUM_TRACKS = 0x10, /*!< number of tracks on the album */
  62. ESP_AVRC_MD_ATTR_GENRE = 0x20, /*!< track genre */
  63. ESP_AVRC_MD_ATTR_PLAYING_TIME = 0x40 /*!< total album playing time in miliseconds */
  64. } esp_avrc_md_attr_mask_t;
  65. //AVRC event notification ids
  66. typedef enum {
  67. ESP_AVRC_RN_PLAY_STATUS_CHANGE = 0x01, /*!< track status change, eg. from playing to paused */
  68. ESP_AVRC_RN_TRACK_CHANGE = 0x02, /*!< new track is loaded */
  69. ESP_AVRC_RN_TRACK_REACHED_END = 0x03, /*!< current track reached end */
  70. ESP_AVRC_RN_TRACK_REACHED_START = 0x04, /*!< current track reached start position */
  71. ESP_AVRC_RN_PLAY_POS_CHANGED = 0x05, /*!< track playing position changed */
  72. ESP_AVRC_RN_BATTERY_STATUS_CHANGE = 0x06, /*!< battery status changed */
  73. ESP_AVRC_RN_SYSTEM_STATUS_CHANGE = 0x07, /*!< system status changed */
  74. ESP_AVRC_RN_APP_SETTING_CHANGE = 0x08, /*!< application settings changed */
  75. ESP_AVRC_RN_MAX_EVT
  76. } esp_avrc_rn_event_ids_t;
  77. //AVRC player setting ids
  78. typedef enum {
  79. ESP_AVRC_PS_EQUALIZER = 0x01, /*!< equalizer, on or off */
  80. ESP_AVRC_PS_REPEAT_MODE = 0x02, /*!< repeat mode */
  81. ESP_AVRC_PS_SHUFFLE_MODE = 0x03, /*!< shuffle mode */
  82. ESP_AVRC_PS_SCAN_MODE = 0x04, /*!< scan mode on or off */
  83. ESP_AVRC_PS_MAX_ATTR
  84. } esp_avrc_ps_attr_ids_t;
  85. //AVRC equalizer modes
  86. typedef enum {
  87. ESP_AVRC_PS_EQUALIZER_OFF = 0x1,
  88. ESP_AVRC_PS_EQUALIZER_ON = 0x2
  89. } esp_avrc_ps_eq_value_ids_t;
  90. //AVRC repeat modes
  91. typedef enum {
  92. ESP_AVRC_PS_REPEAT_OFF = 0x1,
  93. ESP_AVRC_PS_REPEAT_SINGLE = 0x2,
  94. ESP_AVRC_PS_REPEAT_GROUP = 0x3
  95. } esp_avrc_ps_rpt_value_ids_t;
  96. //AVRC shuffle modes
  97. typedef enum {
  98. ESP_AVRC_PS_SHUFFLE_OFF = 0x1,
  99. ESP_AVRC_PS_SHUFFLE_ALL = 0x2,
  100. ESP_AVRC_PS_SHUFFLE_GROUP = 0x3
  101. } esp_avrc_ps_shf_value_ids_t;
  102. //AVRC scan modes
  103. typedef enum {
  104. ESP_AVRC_PS_SCAN_OFF = 0x1,
  105. ESP_AVRC_PS_SCAN_ALL = 0x2,
  106. ESP_AVRC_PS_SCAN_GROUP = 0x3
  107. } esp_avrc_ps_scn_value_ids_t;
  108. /// AVRC controller callback parameters
  109. typedef union {
  110. /**
  111. * @brief ESP_AVRC_CT_CONNECTION_STATE_EVT
  112. */
  113. struct avrc_ct_conn_stat_param {
  114. bool connected; /*!< whether AVRC connection is set up */
  115. uint32_t feat_mask; /*!< AVRC feature mask of remote device */
  116. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  117. } conn_stat; /*!< AVRC connection status */
  118. /**
  119. * @brief ESP_AVRC_CT_PASSTHROUGH_RSP_EVT
  120. */
  121. struct avrc_ct_psth_rsp_param {
  122. uint8_t tl; /*!< transaction label, 0 to 15 */
  123. uint8_t key_code; /*!< passthrough command code */
  124. uint8_t key_state; /*!< 0 for PRESSED, 1 for RELEASED */
  125. } psth_rsp; /*!< passthrough command response */
  126. /**
  127. * @brief ESP_AVRC_CT_METADATA_RSP_EVT
  128. */
  129. struct avrc_ct_meta_rsp_param {
  130. uint8_t attr_id; /*!< id of metadata attribute */
  131. uint8_t *attr_text; /*!< attribute itself */
  132. int attr_length; /*!< attribute character length */
  133. } meta_rsp; /*!< metadata attributes response */
  134. /**
  135. * @brief ESP_AVRC_CT_CHANGE_NOTIFY_EVT
  136. */
  137. struct avrc_ct_change_notify_param {
  138. uint8_t event_id; /*!< id of AVRC event notification */
  139. uint32_t event_parameter; /*!< event notification parameter */
  140. } change_ntf; /*!< notifications */
  141. } esp_avrc_ct_cb_param_t;
  142. /**
  143. * @brief AVRCP controller callback function type
  144. * @param event : Event type
  145. * @param param : Pointer to callback parameter union
  146. */
  147. typedef void (* esp_avrc_ct_cb_t)(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
  148. /**
  149. * @brief Register application callbacks to AVRCP module; for now only AVRCP Controller
  150. * role is supported. This function should be called after esp_bluedroid_enable()
  151. * completes successfully
  152. *
  153. * @param[in] callback: AVRCP controller callback function
  154. *
  155. * @return
  156. * - ESP_OK: success
  157. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  158. * - ESP_FAIL: others
  159. *
  160. */
  161. esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback);
  162. /**
  163. *
  164. * @brief Initialize the bluetooth AVRCP controller module, This function should be called
  165. * after esp_bluedroid_enable() completes successfully
  166. *
  167. * @return
  168. * - ESP_OK: success
  169. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  170. * - ESP_FAIL: others
  171. *
  172. */
  173. esp_err_t esp_avrc_ct_init(void);
  174. /**
  175. *
  176. * @brief De-initialize AVRCP controller module. This function should be called after
  177. * after esp_bluedroid_enable() completes successfully
  178. *
  179. * @return
  180. * - ESP_OK: success
  181. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  182. * - ESP_FAIL: others
  183. */
  184. esp_err_t esp_avrc_ct_deinit(void);
  185. /* add description */
  186. esp_err_t esp_avrc_ct_send_set_player_value_cmd(uint8_t tl, uint8_t attr_id, uint8_t value_id);
  187. /**
  188. * @brief Send register notification command to AVRCP target, This function should be called after
  189. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established
  190. *
  191. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  192. * @param[in] event_id : id of events, e.g. ESP_AVRC_RN_PLAY_STATUS_CHANGE, ESP_AVRC_RN_TRACK_CHANGE, etc.
  193. * @param[in] event_parameter : special parameters, eg. playback interval for ESP_AVRC_RN_PLAY_POS_CHANGED
  194. * @return
  195. * - ESP_OK: success
  196. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  197. * - ESP_FAIL: others
  198. */
  199. esp_err_t esp_avrc_ct_send_register_notification_cmd(uint8_t tl, uint8_t event_id, uint32_t event_parameter);
  200. /**
  201. * @brief Send metadata command to AVRCP target, This function should be called after
  202. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established
  203. *
  204. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  205. * @param[in] attr_mask : mask of attributes, e.g. ESP_AVRC_MD_ATTR_ID_TITLE | ESP_AVRC_MD_ATTR_ID_ARTIST.
  206. *
  207. * @return
  208. * - ESP_OK: success
  209. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  210. * - ESP_FAIL: others
  211. */
  212. esp_err_t esp_avrc_ct_send_metadata_cmd(uint8_t tl, uint8_t attr_mask);
  213. /**
  214. * @brief Send passthrough command to AVRCP target, This function should be called after
  215. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established
  216. *
  217. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  218. * @param[in] key_code : passthrough command code, e.g. ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STOP, etc.
  219. * @param[in] key_state : passthrough command key state, ESP_AVRC_PT_CMD_STATE_PRESSED or
  220. * ESP_AVRC_PT_CMD_STATE_RELEASED
  221. *
  222. * @return
  223. * - ESP_OK: success
  224. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  225. * - ESP_FAIL: others
  226. */
  227. esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state);
  228. #ifdef __cplusplus
  229. }
  230. #endif
  231. #endif /* __ESP_AVRC_API_H__ */