esp_avrc_api.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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_REMOTE_FEATURES_EVT = 5, /*!< feature of remote device indication event */
  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, /*!< equalizer OFF */
  88. ESP_AVRC_PS_EQUALIZER_ON = 0x2 /*!< equalizer ON */
  89. } esp_avrc_ps_eq_value_ids_t;
  90. /// AVRC repeat modes
  91. typedef enum {
  92. ESP_AVRC_PS_REPEAT_OFF = 0x1, /*!< repeat mode off */
  93. ESP_AVRC_PS_REPEAT_SINGLE = 0x2, /*!< single track repeat */
  94. ESP_AVRC_PS_REPEAT_GROUP = 0x3 /*!< group repeat */
  95. } esp_avrc_ps_rpt_value_ids_t;
  96. /// AVRC shuffle modes
  97. typedef enum {
  98. ESP_AVRC_PS_SHUFFLE_OFF = 0x1, /*<! shuffle off */
  99. ESP_AVRC_PS_SHUFFLE_ALL = 0x2, /*<! all trackes shuffle */
  100. ESP_AVRC_PS_SHUFFLE_GROUP = 0x3 /*<! group shuffle */
  101. } esp_avrc_ps_shf_value_ids_t;
  102. /// AVRC scan modes
  103. typedef enum {
  104. ESP_AVRC_PS_SCAN_OFF = 0x1, /*!< scan off */
  105. ESP_AVRC_PS_SCAN_ALL = 0x2, /*!< all tracks scan */
  106. ESP_AVRC_PS_SCAN_GROUP = 0x3 /*!< group scan */
  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. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  116. } conn_stat; /*!< AVRC connection status */
  117. /**
  118. * @brief ESP_AVRC_CT_PASSTHROUGH_RSP_EVT
  119. */
  120. struct avrc_ct_psth_rsp_param {
  121. uint8_t tl; /*!< transaction label, 0 to 15 */
  122. uint8_t key_code; /*!< passthrough command code */
  123. uint8_t key_state; /*!< 0 for PRESSED, 1 for RELEASED */
  124. } psth_rsp; /*!< passthrough command response */
  125. /**
  126. * @brief ESP_AVRC_CT_METADATA_RSP_EVT
  127. */
  128. struct avrc_ct_meta_rsp_param {
  129. uint8_t attr_id; /*!< id of metadata attribute */
  130. uint8_t *attr_text; /*!< attribute itself */
  131. int attr_length; /*!< attribute character length */
  132. } meta_rsp; /*!< metadata attributes response */
  133. /**
  134. * @brief ESP_AVRC_CT_CHANGE_NOTIFY_EVT
  135. */
  136. struct avrc_ct_change_notify_param {
  137. uint8_t event_id; /*!< id of AVRC event notification */
  138. uint32_t event_parameter; /*!< event notification parameter */
  139. } change_ntf; /*!< notifications */
  140. /**
  141. * @brief ESP_AVRC_CT_REMOTE_FEATURES_EVT
  142. */
  143. struct avrc_ct_rmt_feats_param {
  144. uint32_t feat_mask; /*!< AVRC feature mask of remote device */
  145. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  146. } rmt_feats; /*!< AVRC features discovered from remote SDP server */
  147. } esp_avrc_ct_cb_param_t;
  148. /**
  149. * @brief AVRCP controller callback function type
  150. * @param event : Event type
  151. * @param param : Pointer to callback parameter union
  152. */
  153. typedef void (* esp_avrc_ct_cb_t)(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
  154. /**
  155. * @brief Register application callbacks to AVRCP module; for now only AVRCP Controller
  156. * role is supported. This function should be called after esp_bluedroid_enable()
  157. * completes successfully
  158. *
  159. * @param[in] callback: AVRCP controller callback function
  160. *
  161. * @return
  162. * - ESP_OK: success
  163. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  164. * - ESP_FAIL: others
  165. *
  166. */
  167. esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback);
  168. /**
  169. *
  170. * @brief Initialize the bluetooth AVRCP controller module, This function should be called
  171. * after esp_bluedroid_enable() completes successfully
  172. *
  173. * @return
  174. * - ESP_OK: success
  175. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  176. * - ESP_FAIL: others
  177. *
  178. */
  179. esp_err_t esp_avrc_ct_init(void);
  180. /**
  181. *
  182. * @brief De-initialize AVRCP controller module. This function should be called after
  183. * after esp_bluedroid_enable() completes successfully
  184. *
  185. * @return
  186. * - ESP_OK: success
  187. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  188. * - ESP_FAIL: others
  189. */
  190. esp_err_t esp_avrc_ct_deinit(void);
  191. /**
  192. *
  193. * @brief Send player application settings command to AVRCP target. This function should be called
  194. * after ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established.
  195. *
  196. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  197. * @param[in] attr_id : player application setting attribute IDs from one of esp_avrc_ps_attr_ids_t
  198. * @param[in] value_id : attribute value defined for the specific player application setting attribute
  199. * @return
  200. * - ESP_OK: success
  201. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  202. * - ESP_FAIL: others
  203. */
  204. esp_err_t esp_avrc_ct_send_set_player_value_cmd(uint8_t tl, uint8_t attr_id, uint8_t value_id);
  205. /**
  206. * @brief Send register notification command to AVRCP target, This function should be called after
  207. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established
  208. *
  209. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  210. * @param[in] event_id : id of events, e.g. ESP_AVRC_RN_PLAY_STATUS_CHANGE, ESP_AVRC_RN_TRACK_CHANGE, etc.
  211. * @param[in] event_parameter : special parameters, eg. playback interval for ESP_AVRC_RN_PLAY_POS_CHANGED
  212. * @return
  213. * - ESP_OK: success
  214. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  215. * - ESP_FAIL: others
  216. */
  217. esp_err_t esp_avrc_ct_send_register_notification_cmd(uint8_t tl, uint8_t event_id, uint32_t event_parameter);
  218. /**
  219. * @brief Send metadata command to AVRCP target, This function should be called after
  220. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established
  221. *
  222. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  223. * @param[in] attr_mask : mask of attributes, e.g. ESP_AVRC_MD_ATTR_ID_TITLE | ESP_AVRC_MD_ATTR_ID_ARTIST.
  224. *
  225. * @return
  226. * - ESP_OK: success
  227. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  228. * - ESP_FAIL: others
  229. */
  230. esp_err_t esp_avrc_ct_send_metadata_cmd(uint8_t tl, uint8_t attr_mask);
  231. /**
  232. * @brief Send passthrough command to AVRCP target, This function should be called after
  233. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established
  234. *
  235. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  236. * @param[in] key_code : passthrough command code, e.g. ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STOP, etc.
  237. * @param[in] key_state : passthrough command key state, ESP_AVRC_PT_CMD_STATE_PRESSED or
  238. * ESP_AVRC_PT_CMD_STATE_RELEASED
  239. *
  240. * @return
  241. * - ESP_OK: success
  242. * - ESP_INVALID_STATE: if bluetooth stack is not yet enabled
  243. * - ESP_FAIL: others
  244. */
  245. esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state);
  246. #ifdef __cplusplus
  247. }
  248. #endif
  249. #endif /* __ESP_AVRC_API_H__ */