1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __BTC_AVRC_H__ 18 #define __BTC_AVRC_H__ 19 20 #include <stdint.h> 21 #include <stdbool.h> 22 #include "common/bt_defs.h" 23 #include "stack/bt_types.h" 24 #include "bta/bta_av_api.h" 25 #include "btc/btc_task.h" 26 #include "esp_avrc_api.h" 27 28 #if (BTC_AV_INCLUDED == TRUE) 29 #ifndef BTC_AVRC_TGT_INCLUDED 30 #define BTC_AVRC_TGT_INCLUDED FALSE 31 #endif 32 33 typedef enum { 34 BTC_AVRC_CT_API_INIT_EVT = 0, 35 BTC_AVRC_CT_API_DEINIT_EVT, 36 BTC_AVRC_CTRL_API_SND_PTCMD_EVT, 37 BTC_AVRC_STATUS_API_SND_META_EVT, 38 BTC_AVRC_STATUS_API_SND_PLAY_STATUS_EVT, 39 BTC_AVRC_STATUS_API_SND_GET_RN_CAPS_EVT, 40 BTC_AVRC_NOTIFY_API_SND_REG_NOTIFY_EVT, 41 BTC_AVRC_CTRL_API_SND_SET_PLAYER_SETTING_EVT, 42 BTC_AVRC_CTRL_API_SND_SET_ABSOLUTE_VOLUME_EVT 43 } btc_avrc_act_t; 44 45 typedef struct { 46 uint8_t tl; /* transaction label */ 47 uint8_t key_code; 48 uint8_t key_state; 49 } pt_cmd_t; 50 51 typedef struct { 52 uint8_t tl; 53 uint8_t attr_mask; 54 } md_cmd_t; 55 56 typedef struct { 57 uint8_t tl; 58 uint8_t event_id; 59 uint32_t event_parameter; 60 } rn_cmd_t; 61 62 typedef struct { 63 uint8_t tl; 64 uint8_t attr_id; 65 uint8_t value_id; 66 } ps_cmd_t; 67 68 typedef struct { 69 uint8_t tl; 70 } get_caps_cmd_t; 71 72 #define BTC_AVRC_MIN_VOLUME 0x00 73 #define BTC_AVRC_MAX_VOLUME 0x7f 74 75 typedef struct { 76 uint8_t tl; 77 uint8_t volume; 78 } set_abs_vol_cmd_t; 79 80 /* btc_avrc_args_t */ 81 typedef union { 82 pt_cmd_t pt_cmd; 83 md_cmd_t md_cmd; 84 rn_cmd_t rn_cmd; 85 ps_cmd_t ps_cmd; 86 get_caps_cmd_t get_caps_cmd; 87 set_abs_vol_cmd_t set_abs_vol_cmd; 88 } btc_avrc_args_t; 89 90 /* btc_avrc_tg_act_t */ 91 typedef enum { 92 BTC_AVRC_TG_API_INIT_EVT = 0, 93 BTC_AVRC_TG_API_DEINIT_EVT, 94 BTC_AVRC_TG_API_SET_RN_SUPPORTED_EVT, 95 BTC_AVRC_TG_API_SET_PSTH_SUPPORTED_CMD_EVT, 96 BTC_AVRC_TG_API_SEND_RN_RSP_EVT, 97 } btc_avrc_tg_act_t; 98 99 /***************************************************************************** 100 ** Constants & Macros 101 ******************************************************************************/ 102 /* for AVRC 1.4 need to change this */ 103 #define BTC_RC_CT_INIT_MAGIC 0x20181128 104 #define BTC_RC_TG_INIT_MAGIC 0x20181129 105 106 #define MAX_RC_NOTIFICATIONS (13) // refer to ESP_AVRC_RN_MAX_EVT 107 108 109 #define CHECK_ESP_RC_CONNECTED do { \ 110 BTC_TRACE_DEBUG("## %s ##", __FUNCTION__); \ 111 if (btc_rc_cb.rc_connected == FALSE) { \ 112 BTC_TRACE_WARNING("Function %s() called when RC is not connected", __FUNCTION__); \ 113 return ESP_ERR_INVALID_STATE; \ 114 } \ 115 } while (0) 116 117 /***************************************************************************** 118 ** Local type definitions 119 ******************************************************************************/ 120 typedef struct { 121 BOOLEAN registered; 122 UINT8 label; 123 } btc_rc_reg_ntf_t; 124 125 typedef struct { 126 BOOLEAN rc_connected; 127 UINT8 rc_handle; 128 tBTA_AV_FEAT rc_features; 129 UINT16 rc_ct_features; 130 UINT16 rc_tg_features; 131 BD_ADDR rc_addr; 132 btc_rc_reg_ntf_t rc_ntf[MAX_RC_NOTIFICATIONS]; 133 } btc_rc_cb_t; 134 135 /***************************************************************************** 136 ** Static variables 137 ******************************************************************************/ 138 #if AVRC_DYNAMIC_MEMORY == TRUE 139 extern btc_rc_cb_t *btc_rc_cb_ptr; 140 #define btc_rc_cb (*btc_rc_cb_ptr) 141 #endif ///AVRC_DYNAMIC_MEMORY == FALSE 142 143 typedef struct { 144 esp_avrc_rn_event_ids_t event_id; 145 esp_avrc_rn_rsp_t rsp; 146 esp_avrc_rn_param_t param; 147 } rn_rsp_t; 148 149 /* btc_avrc_tg_args_t */ 150 typedef union { 151 rn_rsp_t rn_rsp; /* BTC_AVRC_TG_API_SEND_RN_RSP_EVT */ 152 uint16_t set_rn_evt; /* BTC_AVRC_TG_API_SET_RN_SUPPORTED_EVT */ 153 uint16_t *set_psth_cmd; /* BTC_AVRC_TG_API_SET_PSTH_SUPPORTED_CMD_EVT */ 154 } btc_avrc_tg_args_t; 155 156 void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data); 157 158 BOOLEAN btc_rc_get_connected_peer(BD_ADDR peer_addr); 159 160 /******************************************************************************* 161 ** BTC AVRC API 162 ********************************************************************************/ 163 void btc_avrc_ct_call_handler(btc_msg_t *msg); 164 void btc_avrc_tg_call_handler(btc_msg_t *msg); 165 void btc_avrc_tg_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); 166 167 bool btc_avrc_tg_init_p(void); 168 bool btc_avrc_ct_init_p(void); 169 bool btc_avrc_tg_connected_p(void); 170 bool btc_avrc_ct_connected_p(void); 171 172 const uint16_t *btc_avrc_tg_get_supported_command(void); 173 const uint16_t *btc_avrc_tg_get_allowed_command(void); 174 bool btc_avrc_tg_check_supported_command(const uint16_t *cmd_set); 175 176 uint16_t btc_avrc_tg_get_rn_allowed_evt(void); 177 uint16_t btc_avrc_tg_get_rn_supported_evt(void); 178 bool btc_avrc_tg_check_rn_supported_evt(uint16_t evt_set); 179 bool btc_avrc_tg_rn_evt_supported(uint8_t event_id); 180 bool btc_avrc_ct_rn_evt_supported(uint8_t event_id); 181 182 #endif ///BTC_AV_INCLUDED == TRUE 183 184 #endif /* __BTC_AVRC_H__ */ 185