esp_avrc_api.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __ESP_AVRC_API_H__
  7. #define __ESP_AVRC_API_H__
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include "esp_err.h"
  11. #include "esp_bt_defs.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #define ESP_AVRC_TRANS_LABEL_MAX 15 /*!< max transaction label */
  16. /// AVRC feature bit mask
  17. typedef enum {
  18. ESP_AVRC_FEAT_RCTG = 0x0001, /*!< remote control target */
  19. ESP_AVRC_FEAT_RCCT = 0x0002, /*!< remote control controller */
  20. ESP_AVRC_FEAT_VENDOR = 0x0008, /*!< remote control vendor dependent commands */
  21. ESP_AVRC_FEAT_BROWSE = 0x0010, /*!< use browsing channel */
  22. ESP_AVRC_FEAT_META_DATA = 0x0040, /*!< remote control metadata transfer command/response */
  23. ESP_AVRC_FEAT_ADV_CTRL = 0x0200, /*!< remote control advanced control command/response */
  24. } esp_avrc_features_t;
  25. /// AVRC supported features flag retrieved in SDP record
  26. typedef enum {
  27. ESP_AVRC_FEAT_FLAG_CAT1 = 0x0001, /*!< category 1 */
  28. ESP_AVRC_FEAT_FLAG_CAT2 = 0x0002, /*!< category 2 */
  29. ESP_AVRC_FEAT_FLAG_CAT3 = 0x0004, /*!< category 3 */
  30. ESP_AVRC_FEAT_FLAG_CAT4 = 0x0008, /*!< category 4 */
  31. ESP_AVRC_FEAT_FLAG_BROWSING = 0x0040, /*!< browsing */
  32. ESP_AVRC_FEAT_FLAG_COVER_ART_GET_IMAGE_PROP = 0x0080, /*!< Cover Art GetImageProperties */
  33. ESP_AVRC_FEAT_FLAG_COVER_ART_GET_IMAGE = 0x0100, /*!< Cover Art GetImage */
  34. ESP_AVRC_FEAT_FLAG_COVER_ART_GET_LINKED_THUMBNAIL = 0x0200, /*!< Cover Art GetLinkedThumbnail */
  35. } esp_avrc_feature_flag_t;
  36. /// AVRC passthrough command code
  37. typedef enum {
  38. ESP_AVRC_PT_CMD_SELECT = 0x00, /*!< select */
  39. ESP_AVRC_PT_CMD_UP = 0x01, /*!< up */
  40. ESP_AVRC_PT_CMD_DOWN = 0x02, /*!< down */
  41. ESP_AVRC_PT_CMD_LEFT = 0x03, /*!< left */
  42. ESP_AVRC_PT_CMD_RIGHT = 0x04, /*!< right */
  43. ESP_AVRC_PT_CMD_RIGHT_UP = 0x05, /*!< right-up */
  44. ESP_AVRC_PT_CMD_RIGHT_DOWN = 0x06, /*!< right-down */
  45. ESP_AVRC_PT_CMD_LEFT_UP = 0x07, /*!< left-up */
  46. ESP_AVRC_PT_CMD_LEFT_DOWN = 0x08, /*!< left-down */
  47. ESP_AVRC_PT_CMD_ROOT_MENU = 0x09, /*!< root menu */
  48. ESP_AVRC_PT_CMD_SETUP_MENU = 0x0A, /*!< setup menu */
  49. ESP_AVRC_PT_CMD_CONT_MENU = 0x0B, /*!< contents menu */
  50. ESP_AVRC_PT_CMD_FAV_MENU = 0x0C, /*!< favorite menu */
  51. ESP_AVRC_PT_CMD_EXIT = 0x0D, /*!< exit */
  52. ESP_AVRC_PT_CMD_0 = 0x20, /*!< 0 */
  53. ESP_AVRC_PT_CMD_1 = 0x21, /*!< 1 */
  54. ESP_AVRC_PT_CMD_2 = 0x22, /*!< 2 */
  55. ESP_AVRC_PT_CMD_3 = 0x23, /*!< 3 */
  56. ESP_AVRC_PT_CMD_4 = 0x24, /*!< 4 */
  57. ESP_AVRC_PT_CMD_5 = 0x25, /*!< 5 */
  58. ESP_AVRC_PT_CMD_6 = 0x26, /*!< 6 */
  59. ESP_AVRC_PT_CMD_7 = 0x27, /*!< 7 */
  60. ESP_AVRC_PT_CMD_8 = 0x28, /*!< 8 */
  61. ESP_AVRC_PT_CMD_9 = 0x29, /*!< 9 */
  62. ESP_AVRC_PT_CMD_DOT = 0x2A, /*!< dot */
  63. ESP_AVRC_PT_CMD_ENTER = 0x2B, /*!< enter */
  64. ESP_AVRC_PT_CMD_CLEAR = 0x2C, /*!< clear */
  65. ESP_AVRC_PT_CMD_CHAN_UP = 0x30, /*!< channel up */
  66. ESP_AVRC_PT_CMD_CHAN_DOWN = 0x31, /*!< channel down */
  67. ESP_AVRC_PT_CMD_PREV_CHAN = 0x32, /*!< previous channel */
  68. ESP_AVRC_PT_CMD_SOUND_SEL = 0x33, /*!< sound select */
  69. ESP_AVRC_PT_CMD_INPUT_SEL = 0x34, /*!< input select */
  70. ESP_AVRC_PT_CMD_DISP_INFO = 0x35, /*!< display information */
  71. ESP_AVRC_PT_CMD_HELP = 0x36, /*!< help */
  72. ESP_AVRC_PT_CMD_PAGE_UP = 0x37, /*!< page up */
  73. ESP_AVRC_PT_CMD_PAGE_DOWN = 0x38, /*!< page down */
  74. ESP_AVRC_PT_CMD_POWER = 0x40, /*!< power */
  75. ESP_AVRC_PT_CMD_VOL_UP = 0x41, /*!< volume up */
  76. ESP_AVRC_PT_CMD_VOL_DOWN = 0x42, /*!< volume down */
  77. ESP_AVRC_PT_CMD_MUTE = 0x43, /*!< mute */
  78. ESP_AVRC_PT_CMD_PLAY = 0x44, /*!< play */
  79. ESP_AVRC_PT_CMD_STOP = 0x45, /*!< stop */
  80. ESP_AVRC_PT_CMD_PAUSE = 0x46, /*!< pause */
  81. ESP_AVRC_PT_CMD_RECORD = 0x47, /*!< record */
  82. ESP_AVRC_PT_CMD_REWIND = 0x48, /*!< rewind */
  83. ESP_AVRC_PT_CMD_FAST_FORWARD = 0x49, /*!< fast forward */
  84. ESP_AVRC_PT_CMD_EJECT = 0x4A, /*!< eject */
  85. ESP_AVRC_PT_CMD_FORWARD = 0x4B, /*!< forward */
  86. ESP_AVRC_PT_CMD_BACKWARD = 0x4C, /*!< backward */
  87. ESP_AVRC_PT_CMD_ANGLE = 0x50, /*!< angle */
  88. ESP_AVRC_PT_CMD_SUBPICT = 0x51, /*!< subpicture */
  89. ESP_AVRC_PT_CMD_F1 = 0x71, /*!< F1 */
  90. ESP_AVRC_PT_CMD_F2 = 0x72, /*!< F2 */
  91. ESP_AVRC_PT_CMD_F3 = 0x73, /*!< F3 */
  92. ESP_AVRC_PT_CMD_F4 = 0x74, /*!< F4 */
  93. ESP_AVRC_PT_CMD_F5 = 0x75, /*!< F5 */
  94. ESP_AVRC_PT_CMD_VENDOR = 0x7E, /*!< vendor unique */
  95. } esp_avrc_pt_cmd_t;
  96. /// AVRC passthrough command filter
  97. typedef enum {
  98. ESP_AVRC_PSTH_FILTER_ALLOWED_CMD = 0, /*!< all of the PASSTHROUGH commands that can possibly be used, immutable */
  99. ESP_AVRC_PSTH_FILTER_SUPPORTED_CMD = 1, /*!< PASSTHROUGH commands selectively supported according to the current configuration */
  100. ESP_AVRC_PSTH_FILTER_SUPPORT_MAX,
  101. } esp_avrc_psth_filter_t;
  102. /// AVRC passthrough command bit mask
  103. typedef struct {
  104. uint16_t bits[8]; /*!< bit mask representation of PASSTHROUGH commands */
  105. } esp_avrc_psth_bit_mask_t;
  106. typedef enum {
  107. ESP_AVRC_BIT_MASK_OP_TEST = 0, /*!< operation code to test a specific bit */
  108. ESP_AVRC_BIT_MASK_OP_SET = 1, /*!< operation code to set a specific bit */
  109. ESP_AVRC_BIT_MASK_OP_CLEAR = 2, /*!< operation code to clear a specific bit */
  110. } esp_avrc_bit_mask_op_t;
  111. /// AVRC passthrough command state
  112. typedef enum {
  113. ESP_AVRC_PT_CMD_STATE_PRESSED = 0, /*!< key pressed */
  114. ESP_AVRC_PT_CMD_STATE_RELEASED = 1 /*!< key released */
  115. } esp_avrc_pt_cmd_state_t;
  116. /// AVRC Controller callback events
  117. typedef enum {
  118. ESP_AVRC_CT_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */
  119. ESP_AVRC_CT_PASSTHROUGH_RSP_EVT = 1, /*!< passthrough response event */
  120. ESP_AVRC_CT_METADATA_RSP_EVT = 2, /*!< metadata response event */
  121. ESP_AVRC_CT_PLAY_STATUS_RSP_EVT = 3, /*!< play status response event */
  122. ESP_AVRC_CT_CHANGE_NOTIFY_EVT = 4, /*!< notification event */
  123. ESP_AVRC_CT_REMOTE_FEATURES_EVT = 5, /*!< feature of remote device indication event */
  124. ESP_AVRC_CT_GET_RN_CAPABILITIES_RSP_EVT = 6, /*!< supported notification events capability of peer device */
  125. ESP_AVRC_CT_SET_ABSOLUTE_VOLUME_RSP_EVT = 7, /*!< set absolute volume response event */
  126. } esp_avrc_ct_cb_event_t;
  127. /// AVRC Target callback events
  128. typedef enum {
  129. ESP_AVRC_TG_CONNECTION_STATE_EVT = 0, /*!< connection state changed event */
  130. ESP_AVRC_TG_REMOTE_FEATURES_EVT = 1, /*!< feature of remote device indication event */
  131. ESP_AVRC_TG_PASSTHROUGH_CMD_EVT = 2, /*!< passthrough command event */
  132. ESP_AVRC_TG_SET_ABSOLUTE_VOLUME_CMD_EVT = 3, /*!< set absolute volume command from remote device */
  133. ESP_AVRC_TG_REGISTER_NOTIFICATION_EVT = 4, /*!< register notification event */
  134. ESP_AVRC_TG_SET_PLAYER_APP_VALUE_EVT = 5, /*!< set application attribute value, attribute refer to esp_avrc_ps_attr_ids_t */
  135. } esp_avrc_tg_cb_event_t;
  136. /// AVRC metadata attribute mask
  137. typedef enum {
  138. ESP_AVRC_MD_ATTR_TITLE = 0x1, /*!< title of the playing track */
  139. ESP_AVRC_MD_ATTR_ARTIST = 0x2, /*!< track artist */
  140. ESP_AVRC_MD_ATTR_ALBUM = 0x4, /*!< album name */
  141. ESP_AVRC_MD_ATTR_TRACK_NUM = 0x8, /*!< track position on the album */
  142. ESP_AVRC_MD_ATTR_NUM_TRACKS = 0x10, /*!< number of tracks on the album */
  143. ESP_AVRC_MD_ATTR_GENRE = 0x20, /*!< track genre */
  144. ESP_AVRC_MD_ATTR_PLAYING_TIME = 0x40 /*!< total album playing time in miliseconds */
  145. } esp_avrc_md_attr_mask_t;
  146. /// AVRC event notification ids
  147. typedef enum {
  148. ESP_AVRC_RN_PLAY_STATUS_CHANGE = 0x01, /*!< track status change, eg. from playing to paused */
  149. ESP_AVRC_RN_TRACK_CHANGE = 0x02, /*!< new track is loaded */
  150. ESP_AVRC_RN_TRACK_REACHED_END = 0x03, /*!< current track reached end */
  151. ESP_AVRC_RN_TRACK_REACHED_START = 0x04, /*!< current track reached start position */
  152. ESP_AVRC_RN_PLAY_POS_CHANGED = 0x05, /*!< track playing position changed */
  153. ESP_AVRC_RN_BATTERY_STATUS_CHANGE = 0x06, /*!< battery status changed */
  154. ESP_AVRC_RN_SYSTEM_STATUS_CHANGE = 0x07, /*!< system status changed */
  155. ESP_AVRC_RN_APP_SETTING_CHANGE = 0x08, /*!< application settings changed */
  156. ESP_AVRC_RN_NOW_PLAYING_CHANGE = 0x09, /*!< now playing content changed */
  157. ESP_AVRC_RN_AVAILABLE_PLAYERS_CHANGE = 0x0a, /*!< available players changed */
  158. ESP_AVRC_RN_ADDRESSED_PLAYER_CHANGE = 0x0b, /*!< the addressed player changed */
  159. ESP_AVRC_RN_UIDS_CHANGE = 0x0c, /*!< UIDs changed */
  160. ESP_AVRC_RN_VOLUME_CHANGE = 0x0d, /*!< volume changed locally on TG */
  161. ESP_AVRC_RN_MAX_EVT
  162. } esp_avrc_rn_event_ids_t;
  163. /// AVRC target notification event notification capability
  164. typedef enum {
  165. ESP_AVRC_RN_CAP_ALLOWED_EVT = 0, /*!< all of the notification events that can possibly be supported, immutable */
  166. ESP_AVRC_RN_CAP_SUPPORTED_EVT = 1, /*!< notification events selectively supported according to the current configuration */
  167. ESP_AVRC_RN_CAP_MAX,
  168. } esp_avrc_rn_evt_cap_t;
  169. /// AVRC target notification event capability bit mask
  170. typedef struct {
  171. uint16_t bits; /*!< bit mask representation of PASSTHROUGH commands */
  172. } esp_avrc_rn_evt_cap_mask_t;
  173. /// AVRC notification response type
  174. typedef enum {
  175. ESP_AVRC_RN_RSP_INTERIM = 13, /*!< initial response to RegisterNotification, should be sent T_mtp(1000ms) from receiving the command */
  176. ESP_AVRC_RN_RSP_CHANGED = 15, /*!< final response to RegisterNotification command */
  177. } esp_avrc_rn_rsp_t;
  178. /// AVRC player setting ids
  179. typedef enum {
  180. ESP_AVRC_PS_EQUALIZER = 0x01, /*!< equalizer, on or off */
  181. ESP_AVRC_PS_REPEAT_MODE = 0x02, /*!< repeat mode */
  182. ESP_AVRC_PS_SHUFFLE_MODE = 0x03, /*!< shuffle mode */
  183. ESP_AVRC_PS_SCAN_MODE = 0x04, /*!< scan mode on or off */
  184. ESP_AVRC_PS_MAX_ATTR
  185. } esp_avrc_ps_attr_ids_t;
  186. /// AVRC equalizer modes
  187. typedef enum {
  188. ESP_AVRC_PS_EQUALIZER_OFF = 0x1, /*!< equalizer OFF */
  189. ESP_AVRC_PS_EQUALIZER_ON = 0x2 /*!< equalizer ON */
  190. } esp_avrc_ps_eq_value_ids_t;
  191. /// AVRC repeat modes
  192. typedef enum {
  193. ESP_AVRC_PS_REPEAT_OFF = 0x1, /*!< repeat mode off */
  194. ESP_AVRC_PS_REPEAT_SINGLE = 0x2, /*!< single track repeat */
  195. ESP_AVRC_PS_REPEAT_GROUP = 0x3 /*!< group repeat */
  196. } esp_avrc_ps_rpt_value_ids_t;
  197. /// AVRC shuffle modes
  198. typedef enum {
  199. ESP_AVRC_PS_SHUFFLE_OFF = 0x1, /*<! shuffle off */
  200. ESP_AVRC_PS_SHUFFLE_ALL = 0x2, /*<! shuffle all tracks */
  201. ESP_AVRC_PS_SHUFFLE_GROUP = 0x3 /*<! group shuffle */
  202. } esp_avrc_ps_shf_value_ids_t;
  203. /// AVRC scan modes
  204. typedef enum {
  205. ESP_AVRC_PS_SCAN_OFF = 0x1, /*!< scan off */
  206. ESP_AVRC_PS_SCAN_ALL = 0x2, /*!< all tracks scan */
  207. ESP_AVRC_PS_SCAN_GROUP = 0x3 /*!< group scan */
  208. } esp_avrc_ps_scn_value_ids_t;
  209. /// AVCTP response codes
  210. typedef enum {
  211. ESP_AVRC_RSP_NOT_IMPL = 8, /*!< not implemented */
  212. ESP_AVRC_RSP_ACCEPT = 9, /*!< accept */
  213. ESP_AVRC_RSP_REJECT = 10, /*!< reject */
  214. ESP_AVRC_RSP_IN_TRANS = 11, /*!< in transition */
  215. ESP_AVRC_RSP_IMPL_STBL = 12, /*!< implemented/stable */
  216. ESP_AVRC_RSP_CHANGED = 13, /*!< changed */
  217. ESP_AVRC_RSP_INTERIM = 15, /*!< interim */
  218. } esp_avrc_rsp_t;
  219. /// AVRCP battery status
  220. typedef enum {
  221. ESP_AVRC_BATT_NORMAL = 0, /*!< normal state */
  222. ESP_AVRC_BATT_WARNING = 1, /*!< unable to operate soon */
  223. ESP_AVRC_BATT_CRITICAL = 2, /*!< cannot operate any more */
  224. ESP_AVRC_BATT_EXTERNAL = 3, /*!< plugged to external power supply */
  225. ESP_AVRC_BATT_FULL_CHARGE = 4, /*!< when completely charged from external power supply */
  226. } esp_avrc_batt_stat_t;
  227. /// AVRCP current status of playback
  228. typedef enum {
  229. ESP_AVRC_PLAYBACK_STOPPED = 0, /*!< stopped */
  230. ESP_AVRC_PLAYBACK_PLAYING = 1, /*!< playing */
  231. ESP_AVRC_PLAYBACK_PAUSED = 2, /*!< paused */
  232. ESP_AVRC_PLAYBACK_FWD_SEEK = 3, /*!< forward seek */
  233. ESP_AVRC_PLAYBACK_REV_SEEK = 4, /*!< reverse seek */
  234. ESP_AVRC_PLAYBACK_ERROR = 0xFF, /*!< error */
  235. } esp_avrc_playback_stat_t;
  236. /// AVRCP notification parameters
  237. typedef union
  238. {
  239. uint8_t volume; /*!< response data for ESP_AVRC_RN_VOLUME_CHANGE, ranges 0..127 */
  240. esp_avrc_playback_stat_t playback; /*!< response data for ESP_AVRC_RN_PLAY_STATUS_CHANGE */
  241. uint8_t elm_id[8]; /*!< response data for ESP_AVRC_RN_TRACK_CHANGE */
  242. uint32_t play_pos; /*!< response data for ESP_AVRC_RN_PLAY_POS_CHANGED, in millisecond */
  243. esp_avrc_batt_stat_t batt; /*!< response data for ESP_AVRC_RN_BATTERY_STATUS_CHANGE */
  244. } esp_avrc_rn_param_t;
  245. /// AVRCP set app value parameters
  246. typedef struct {
  247. uint8_t attr_id; /*!< player application attribute id */
  248. uint8_t attr_val; /*!< player application attribute value */
  249. } esp_avrc_set_app_value_param_t;
  250. /// AVRC controller callback parameters
  251. typedef union {
  252. /**
  253. * @brief ESP_AVRC_CT_CONNECTION_STATE_EVT
  254. */
  255. struct avrc_ct_conn_stat_param {
  256. bool connected; /*!< whether AVRC connection is set up */
  257. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  258. } conn_stat; /*!< AVRC connection status */
  259. /**
  260. * @brief ESP_AVRC_CT_PASSTHROUGH_RSP_EVT
  261. */
  262. struct avrc_ct_psth_rsp_param {
  263. uint8_t tl; /*!< transaction label, 0 to 15 */
  264. uint8_t key_code; /*!< passthrough command code */
  265. uint8_t key_state; /*!< 0 for PRESSED, 1 for RELEASED */
  266. esp_avrc_rsp_t rsp_code; /*!< response code */
  267. } psth_rsp; /*!< passthrough command response */
  268. /**
  269. * @brief ESP_AVRC_CT_METADATA_RSP_EVT
  270. */
  271. struct avrc_ct_meta_rsp_param {
  272. uint8_t attr_id; /*!< id of metadata attribute */
  273. uint8_t *attr_text; /*!< attribute itself */
  274. int attr_length; /*!< attribute character length */
  275. } meta_rsp; /*!< metadata attributes response */
  276. /**
  277. * @brief ESP_AVRC_CT_CHANGE_NOTIFY_EVT
  278. */
  279. struct avrc_ct_change_notify_param {
  280. uint8_t event_id; /*!< id of AVRC event notification */
  281. esp_avrc_rn_param_t event_parameter; /*!< event notification parameter */
  282. } change_ntf; /*!< notifications */
  283. /**
  284. * @brief ESP_AVRC_CT_REMOTE_FEATURES_EVT
  285. */
  286. struct avrc_ct_rmt_feats_param {
  287. uint32_t feat_mask; /*!< AVRC feature mask of remote device */
  288. uint16_t tg_feat_flag; /*!< feature flag of remote device as TG */
  289. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  290. } rmt_feats; /*!< AVRC features discovered from remote SDP server */
  291. /**
  292. * @brief ESP_AVRC_CT_GET_RN_CAPABILITIES_RSP_EVT
  293. */
  294. struct avrc_ct_get_rn_caps_rsp_param {
  295. uint8_t cap_count; /*!< number of items provided in event or company_id according to cap_id used */
  296. esp_avrc_rn_evt_cap_mask_t evt_set; /*!< supported event_ids represented in bit-mask */
  297. } get_rn_caps_rsp; /*!< get supported event capabilities response from AVRCP target */
  298. /**
  299. * @brief ESP_AVRC_CT_SET_ABSOLUTE_VOLUME_RSP_EVT
  300. */
  301. struct avrc_ct_set_volume_rsp_param {
  302. uint8_t volume; /*!< the volume which has actually been set, range is 0 to 0x7f, means 0% to 100% */
  303. } set_volume_rsp; /*!< set absolute volume response event */
  304. } esp_avrc_ct_cb_param_t;
  305. /// AVRC target callback parameters
  306. typedef union {
  307. /**
  308. * @brief ESP_AVRC_TG_CONNECTION_STATE_EVT
  309. */
  310. struct avrc_tg_conn_stat_param {
  311. bool connected; /*!< whether AVRC connection is set up */
  312. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  313. } conn_stat; /*!< AVRC connection status */
  314. /**
  315. * @brief ESP_AVRC_TG_REMOTE_FEATURES_EVT
  316. */
  317. struct avrc_tg_rmt_feats_param {
  318. uint32_t feat_mask; /*!< AVRC feature mask of remote device */
  319. uint16_t ct_feat_flag; /*!< feature flag of remote device as CT */
  320. esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */
  321. } rmt_feats; /*!< AVRC features discovered through SDP */
  322. /**
  323. * @brief ESP_AVRC_TG_PASSTHROUGH_CMD_EVT
  324. */
  325. struct avrc_tg_psth_cmd_param {
  326. uint8_t key_code; /*!< passthrough command code */
  327. uint8_t key_state; /*!< 0 for PRESSED, 1 for RELEASED */
  328. } psth_cmd; /*!< passthrough command */
  329. /**
  330. * @brief ESP_AVRC_TG_SET_ABSOLUTE_VOLUME_CMD_EVT
  331. */
  332. struct avrc_tg_set_abs_vol_param {
  333. uint8_t volume; /*!< volume ranges from 0 to 127 */
  334. } set_abs_vol; /*!< set absolute volume command targeted on audio sink */
  335. /**
  336. * @brief ESP_AVRC_TG_REGISTER_NOTIFICATION_EVT
  337. */
  338. struct avrc_tg_reg_ntf_param {
  339. uint8_t event_id; /*!< event id of AVRC RegisterNotification */
  340. uint32_t event_parameter; /*!< event notification parameter */
  341. } reg_ntf; /*!< register notification */
  342. /**
  343. * @brief ESP_AVRC_TG_SET_PLAYER_APP_VALUE_EVT
  344. */
  345. struct avrc_tg_set_app_value_param {
  346. uint8_t num_val; /*!< attribute num */
  347. esp_avrc_set_app_value_param_t *p_vals; /*!< point to the id and value of player application attribute */
  348. } set_app_value; /*!< set player application value */
  349. } esp_avrc_tg_cb_param_t;
  350. /**
  351. * @brief AVRCP controller callback function type
  352. *
  353. * @param event : Event type
  354. *
  355. * @param param : Pointer to callback parameter union
  356. */
  357. typedef void (* esp_avrc_ct_cb_t)(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
  358. /**
  359. * @brief AVRCP target callback function type
  360. *
  361. * @param event : Event type
  362. *
  363. * @param param : Pointer to callback parameter union
  364. */
  365. typedef void (* esp_avrc_tg_cb_t)(esp_avrc_tg_cb_event_t event, esp_avrc_tg_cb_param_t *param);
  366. /**
  367. * @brief Register application callbacks to AVRCP module. This function should be
  368. * called after esp_bluedroid_enable() completes successfully.
  369. *
  370. * @param[in] callback: AVRCP controller callback function
  371. *
  372. * @return
  373. * - ESP_OK: success
  374. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  375. * - ESP_FAIL: others
  376. *
  377. */
  378. esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback);
  379. /**
  380. *
  381. * @brief Initialize the bluetooth AVRCP controller module, This function should be called
  382. * after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
  383. * AVRC should be used along with A2DP and AVRC should be initialized before A2DP.
  384. *
  385. * @return
  386. * - ESP_OK: success
  387. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  388. * - ESP_FAIL: others
  389. *
  390. */
  391. esp_err_t esp_avrc_ct_init(void);
  392. /**
  393. *
  394. * @brief De-initialize AVRCP controller module. This function should be called after
  395. * after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
  396. * AVRC should be used along with A2DP and AVRC should be deinitialized before A2DP.
  397. *
  398. * @return
  399. * - ESP_OK: success
  400. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  401. * - ESP_FAIL: others
  402. */
  403. esp_err_t esp_avrc_ct_deinit(void);
  404. /**
  405. *
  406. * @brief Send player application settings command to AVRCP target. This function should be called
  407. * after ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established.
  408. *
  409. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values
  410. *
  411. * @param[in] attr_id : player application setting attribute IDs from one of esp_avrc_ps_attr_ids_t
  412. *
  413. * @param[in] value_id : attribute value defined for the specific player application setting attribute
  414. *
  415. * @return
  416. * - ESP_OK: success
  417. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  418. * - ESP_FAIL: others
  419. */
  420. esp_err_t esp_avrc_ct_send_set_player_value_cmd(uint8_t tl, uint8_t attr_id, uint8_t value_id);
  421. /**
  422. * @brief Send GetCapabilities PDU to AVRCP target to retrieve remote device's supported
  423. * notification event_ids. This function should be called after
  424. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established.
  425. *
  426. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values
  427. *
  428. * @return
  429. * - ESP_OK: success
  430. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  431. * - ESP_FAIL: others
  432. */
  433. esp_err_t esp_avrc_ct_send_get_rn_capabilities_cmd(uint8_t tl);
  434. /**
  435. * @brief Send register notification command to AVRCP target. This function should be called after
  436. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established.
  437. *
  438. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  439. *
  440. * @param[in] event_id : id of events, e.g. ESP_AVRC_RN_PLAY_STATUS_CHANGE, ESP_AVRC_RN_TRACK_CHANGE, etc.
  441. *
  442. * @param[in] event_parameter : playback interval for ESP_AVRC_RN_PLAY_POS_CHANGED;
  443. * For other events , value of this parameter is ignored.
  444. * @return
  445. * - ESP_OK: success
  446. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  447. * - ESP_ERR_NOT_SUPPORTED: if the event_id is not supported in current implementation
  448. * - ESP_FAIL: others
  449. */
  450. esp_err_t esp_avrc_ct_send_register_notification_cmd(uint8_t tl, uint8_t event_id, uint32_t event_parameter);
  451. /**
  452. * @brief Send set absolute volume command to AVRCP target. This function should be called after
  453. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established.
  454. *
  455. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values
  456. *
  457. * @param[in] volume : volume, 0 to 0x7f, means 0% to 100%
  458. *
  459. * @return
  460. * - ESP_OK: success
  461. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  462. * - ESP_ERR_NOT_SUPPORTED: if the event_id is not supported in current implementation
  463. * - ESP_FAIL: others
  464. */
  465. esp_err_t esp_avrc_ct_send_set_absolute_volume_cmd(uint8_t tl, uint8_t volume);
  466. /**
  467. * @brief Send metadata command to AVRCP target. This function should be called after
  468. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established.
  469. *
  470. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  471. *
  472. * @param[in] attr_mask : mask of attributes, e.g. ESP_AVRC_MD_ATTR_ID_TITLE | ESP_AVRC_MD_ATTR_ID_ARTIST.
  473. *
  474. * @return
  475. * - ESP_OK: success
  476. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  477. * - ESP_FAIL: others
  478. */
  479. esp_err_t esp_avrc_ct_send_metadata_cmd(uint8_t tl, uint8_t attr_mask);
  480. /**
  481. * @brief Send passthrough command to AVRCP target. This function should be called after
  482. * ESP_AVRC_CT_CONNECTION_STATE_EVT is received and AVRCP connection is established.
  483. *
  484. * @param[in] tl : transaction label, 0 to 15, consecutive commands should use different values.
  485. *
  486. * @param[in] key_code : passthrough command code, e.g. ESP_AVRC_PT_CMD_PLAY, ESP_AVRC_PT_CMD_STOP, etc.
  487. *
  488. * @param[in] key_state : passthrough command key state, ESP_AVRC_PT_CMD_STATE_PRESSED or
  489. * ESP_AVRC_PT_CMD_STATE_RELEASED
  490. *
  491. * @return
  492. * - ESP_OK: success
  493. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  494. * - ESP_FAIL: others
  495. */
  496. esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state);
  497. /**
  498. * @brief Register application callbacks to AVRCP target module. This function should be
  499. * called after esp_bluedroid_enable() completes successfully.
  500. *
  501. * @param[in] callback: AVRCP target callback function
  502. *
  503. * @return
  504. * - ESP_OK: success
  505. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  506. * - ESP_FAIL: others
  507. *
  508. */
  509. esp_err_t esp_avrc_tg_register_callback(esp_avrc_tg_cb_t callback);
  510. /**
  511. *
  512. * @brief Initialize the bluetooth AVRCP target module, This function should be called
  513. * after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
  514. * AVRC should be used along with A2DP and AVRC should be initialized before A2DP.
  515. *
  516. * @return
  517. * - ESP_OK: success
  518. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  519. * - ESP_FAIL: others
  520. *
  521. */
  522. esp_err_t esp_avrc_tg_init(void);
  523. /**
  524. *
  525. * @brief De-initialize AVRCP target module. This function should be called after
  526. * after esp_bluedroid_enable() completes successfully. Note: AVRC cannot work independently,
  527. * AVRC should be used along with A2DP and AVRC should be deinitialized before A2DP.
  528. *
  529. * @return
  530. * - ESP_OK: success
  531. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
  532. * - ESP_FAIL: others
  533. */
  534. esp_err_t esp_avrc_tg_deinit(void);
  535. /**
  536. *
  537. * @brief Get the current filter of remote passthrough commands on AVRC target. Filter is given by
  538. * filter type and bit mask for the passthrough commands. This function should be called
  539. * after esp_avrc_tg_init().
  540. * For filter type ESP_AVRC_PSTH_FILTER_ALLOWED_CMD, the retrieved command set is constant and
  541. * it covers all of the passthrough commands that can possibly be supported.
  542. * For filter type ESP_AVRC_PSTH_FILTER_SUPPORT_COMMANDS, the retrieved command set covers the
  543. * passthrough commands selected to be supported according to current configuration. The
  544. * configuration can be changed using esp_avrc_tg_set_psth_cmd_filter().
  545. *
  546. * @return
  547. * - ESP_OK: success
  548. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not enabled or AVRC TG is not initialized
  549. * - ESP_ERR_INVALID_ARG: if filter type is invalid or cmd_set is NULL
  550. * - ESP_FAIL: otherwise
  551. */
  552. esp_err_t esp_avrc_tg_get_psth_cmd_filter(esp_avrc_psth_filter_t filter, esp_avrc_psth_bit_mask_t *cmd_set);
  553. /**
  554. *
  555. * @brief Set the filter of remote passthrough commands on AVRC target. Filter is given by
  556. * filter type and bit mask for the passthrough commands. This function should be called
  557. * after esp_avrc_tg_init().
  558. *
  559. * If filter type is ESP_AVRC_PSTH_FILTER_SUPPORT_CMD, the passthrough commands which
  560. * are set "1" as given in cmd_set will generate ESP_AVRC_CT_PASSTHROUGH_RSP_EVT callback
  561. * event and are auto-accepted in the protocol stack, other commands are replied with response
  562. * type "NOT IMPLEMENTED" (8). The set of supported commands should be a subset of allowed
  563. * command set. The allowed command set can be retrieved using esp_avrc_tg_get_psth_cmd_filter()
  564. * with filter type "ESP_AVRC_PSTH_FILTER_ALLOWED_CMD".
  565. *
  566. * Filter type "ESP_AVRC_PSTH_FILTER_ALLOWED_CMD" does not apply to this function.
  567. *
  568. * @return
  569. * - ESP_OK: success
  570. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not enabled
  571. * - ESP_ERR_INVALID_ARG: if filter type is invalid or cmd_set is NULL
  572. * - ESP_ERR_NOT_SUPPORTED:: if filter type is ESP_AVRC_PSTH_FILTER_ALLOWED_CMD, or cmd_set
  573. * includes commands that are not allowed
  574. *
  575. */
  576. esp_err_t esp_avrc_tg_set_psth_cmd_filter(esp_avrc_psth_filter_t filter, const esp_avrc_psth_bit_mask_t *cmd_set);
  577. /**
  578. * @brief Operate on the type esp_avrc_psth_bit_mask_t with regard to a specific PASSTHROUGH command.
  579. *
  580. * @param[in] op: operation requested on the bit mask field
  581. *
  582. * @param[in] psth: pointer to passthrough command bit mask structure
  583. *
  584. * @param[in] cmd: passthrough command code
  585. *
  586. * @return For operation ESP_AVRC_BIT_MASK_OP_SET or ESP_AVRC_BIT_MASK_OP_CLEAR, return
  587. * true for a successful operation, otherwise return false.
  588. * For operation ESP_AVRC_BIT_MASK_OP_TEST, return true if the corresponding bit
  589. * is set, otherwise false.
  590. *
  591. */
  592. bool esp_avrc_psth_bit_mask_operation(esp_avrc_bit_mask_op_t op, esp_avrc_psth_bit_mask_t *psth, esp_avrc_pt_cmd_t cmd);
  593. /**
  594. *
  595. * @brief Get the requested event notification capabilies on local AVRC target. The capability is returned
  596. * in a bit mask representation in evt_set. This function should be called after esp_avrc_tg_init().
  597. *
  598. * For capability type "ESP_AVRC_RN_CAP_ALLOWED_EVT, the retrieved event set is constant and
  599. * it covers all of the notifcation events that can possibly be supported with current
  600. * implementation.
  601. *
  602. * For capability type ESP_AVRC_RN_CAP_SUPPORTED_EVT, the event set covers the notification
  603. * events selected to be supported under current configuration, The configuration can be
  604. * changed using esp_avrc_tg_set_rn_evt_cap().
  605. *
  606. * @return
  607. * - ESP_OK: success
  608. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not enabled or AVRC TG is not initialized
  609. * - ESP_ERR_INVALID_ARG: if cap is invalid or evt_set is NULL
  610. * - ESP_FAIL: otherwise
  611. */
  612. esp_err_t esp_avrc_tg_get_rn_evt_cap(esp_avrc_rn_evt_cap_t cap, esp_avrc_rn_evt_cap_mask_t *evt_set);
  613. /**
  614. *
  615. * @brief Set the event notification capabilities on local AVRCP target. The capability is given in a
  616. * bit mask representation in evt_set and must be a subset of allowed event IDs with current
  617. * implementation. This function should be called after esp_avrc_tg_init().
  618. *
  619. * @return
  620. * - ESP_OK: success
  621. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not enabled
  622. * - ESP_ERR_INVALID_ARG: if evt_set is NULL
  623. *
  624. */
  625. esp_err_t esp_avrc_tg_set_rn_evt_cap(const esp_avrc_rn_evt_cap_mask_t *evt_set);
  626. /**
  627. * @brief Operate on the type esp_avrc_rn_evt_cap_mask_t with regard to a specific event.
  628. *
  629. * @param[in] op: operation requested on the bit mask field
  630. *
  631. * @param[in] events: pointer to event notification capability bit mask structure
  632. *
  633. * @param[in] event_id: notification event code
  634. *
  635. * @return For operation ESP_AVRC_BIT_MASK_OP_SET or ESP_AVRC_BIT_MASK_OP_CLEAR, return
  636. * true for a successful operation, otherwise return false.
  637. *
  638. * For operation ESP_AVRC_BIT_MASK_OP_TEST, return true if the corresponding bit
  639. * is set, otherwise false.
  640. *
  641. */
  642. bool esp_avrc_rn_evt_bit_mask_operation(esp_avrc_bit_mask_op_t op, esp_avrc_rn_evt_cap_mask_t *events,
  643. esp_avrc_rn_event_ids_t event_id);
  644. /**
  645. *
  646. * @brief Send RegisterNotification Response to remote AVRCP controller. Local event notification
  647. * capability can be set using esp_avrc_tg_set_rn_evt_cap(), in a bit mask representation
  648. * in evt_set. This function should be called after esp_avrc_tg_init().
  649. *
  650. * @param[in] event_id: notification event ID that remote AVRCP CT registers
  651. *
  652. * @param[in] rsp: notification response code
  653. *
  654. * @param[in] param: parameters included in the specific notification
  655. *
  656. * @return
  657. * - ESP_OK: success
  658. * - ESP_ERR_INVALID_STATE: if bluetooth stack is not enabled or AVRC TG is not initialized
  659. * - ESP_ERR_INVALID_ARG: if evt_set is NULL
  660. *
  661. */
  662. esp_err_t esp_avrc_tg_send_rn_rsp(esp_avrc_rn_event_ids_t event_id, esp_avrc_rn_rsp_t rsp,
  663. esp_avrc_rn_param_t *param);
  664. #ifdef __cplusplus
  665. }
  666. #endif
  667. #endif /* __ESP_AVRC_API_H__ */