esp_avrc_api.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #include "common/bt_target.h"
  14. #include <string.h>
  15. #include "esp_err.h"
  16. #include "esp_avrc_api.h"
  17. #include "esp_bt_main.h"
  18. #include "btc/btc_manage.h"
  19. #include "btc_avrc.h"
  20. #if BTC_AV_INCLUDED
  21. esp_err_t esp_avrc_ct_register_callback(esp_avrc_ct_cb_t callback)
  22. {
  23. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  24. return ESP_ERR_INVALID_STATE;
  25. }
  26. if (callback == NULL) {
  27. return ESP_FAIL;
  28. }
  29. btc_profile_cb_set(BTC_PID_AVRC, callback);
  30. return ESP_OK;
  31. }
  32. esp_err_t esp_avrc_ct_init(void)
  33. {
  34. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  35. return ESP_ERR_INVALID_STATE;
  36. }
  37. btc_msg_t msg;
  38. msg.sig = BTC_SIG_API_CALL;
  39. msg.pid = BTC_PID_AVRC;
  40. msg.act = BTC_AVRC_CTRL_API_INIT_EVT;
  41. /* Switch to BTC context */
  42. bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
  43. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  44. }
  45. esp_err_t esp_avrc_ct_deinit(void)
  46. {
  47. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  48. return ESP_ERR_INVALID_STATE;
  49. }
  50. btc_msg_t msg;
  51. msg.sig = BTC_SIG_API_CALL;
  52. msg.pid = BTC_PID_AVRC;
  53. msg.act = BTC_AVRC_CTRL_API_DEINIT_EVT;
  54. /* Switch to BTC context */
  55. bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL);
  56. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  57. }
  58. esp_err_t esp_avrc_ct_send_set_player_value_cmd(uint8_t tl, uint8_t attr_id, uint8_t value_id)
  59. {
  60. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  61. return ESP_ERR_INVALID_STATE;
  62. }
  63. if (tl >= 16 || attr_id > ESP_AVRC_PS_MAX_ATTR - 1) {
  64. return ESP_FAIL;
  65. }
  66. btc_msg_t msg;
  67. msg.sig = BTC_SIG_API_CALL;
  68. msg.pid = BTC_PID_AVRC;
  69. msg.act = BTC_AVRC_CTRL_API_SET_PLAYER_SETTING_EVT;
  70. btc_avrc_args_t arg;
  71. memset(&arg, 0, sizeof(btc_avrc_args_t));
  72. arg.ps_cmd.tl = tl;
  73. arg.ps_cmd.attr_id = attr_id;
  74. arg.ps_cmd.value_id = value_id;
  75. /* Switch to BTC context */
  76. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_avrc_args_t), NULL);
  77. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  78. }
  79. esp_err_t esp_avrc_ct_send_register_notification_cmd(uint8_t tl, uint8_t event_id, uint32_t event_parameter)
  80. {
  81. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  82. return ESP_ERR_INVALID_STATE;
  83. }
  84. if (tl >= 16 || event_id > ESP_AVRC_RN_MAX_EVT - 1) {
  85. return ESP_FAIL;
  86. }
  87. btc_msg_t msg;
  88. msg.sig = BTC_SIG_API_CALL;
  89. msg.pid = BTC_PID_AVRC;
  90. msg.act = BTC_AVRC_NOTIFY_API_SND_REG_NOTIFY_EVT;
  91. btc_avrc_args_t arg;
  92. memset(&arg, 0, sizeof(btc_avrc_args_t));
  93. arg.rn_cmd.tl = tl;
  94. arg.rn_cmd.event_id = event_id;
  95. arg.rn_cmd.event_parameter = event_parameter;
  96. /* Switch to BTC context */
  97. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_avrc_args_t), NULL);
  98. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  99. }
  100. esp_err_t esp_avrc_ct_send_metadata_cmd(uint8_t tl, uint8_t attr_mask)
  101. {
  102. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  103. return ESP_ERR_INVALID_STATE;
  104. }
  105. if (tl >= 16) {
  106. return ESP_FAIL;
  107. }
  108. btc_msg_t msg;
  109. msg.sig = BTC_SIG_API_CALL;
  110. msg.pid = BTC_PID_AVRC;
  111. msg.act = BTC_AVRC_STATUS_API_SND_META_EVT;
  112. btc_avrc_args_t arg;
  113. memset(&arg, 0, sizeof(btc_avrc_args_t));
  114. arg.md_cmd.tl = tl;
  115. arg.md_cmd.attr_mask = attr_mask;
  116. /* Switch to BTC context */
  117. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_avrc_args_t), NULL);
  118. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  119. }
  120. esp_err_t esp_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state)
  121. {
  122. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  123. return ESP_ERR_INVALID_STATE;
  124. }
  125. if (tl >= 16 || key_state > ESP_AVRC_PT_CMD_STATE_RELEASED) {
  126. return ESP_FAIL;
  127. }
  128. btc_msg_t msg;
  129. msg.sig = BTC_SIG_API_CALL;
  130. msg.pid = BTC_PID_AVRC;
  131. msg.act = BTC_AVRC_CTRL_API_SND_PTCMD_EVT;
  132. btc_avrc_args_t arg;
  133. memset(&arg, 0, sizeof(btc_avrc_args_t));
  134. arg.pt_cmd.tl = tl;
  135. arg.pt_cmd.key_code = key_code;
  136. arg.pt_cmd.key_state = key_state;
  137. /* Switch to BTC context */
  138. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_avrc_args_t), NULL);
  139. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  140. }
  141. #endif /* #if BTC_AV_INCLUDED */