esp_avrc_api.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "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_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_passthrough_cmd(uint8_t tl, uint8_t key_code, uint8_t key_state)
  59. {
  60. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  61. return ESP_ERR_INVALID_STATE;
  62. }
  63. btc_msg_t msg;
  64. msg.sig = BTC_SIG_API_CALL;
  65. msg.pid = BTC_PID_AVRC;
  66. msg.act = BTC_AVRC_CTRL_API_SND_PTCMD_EVT;
  67. btc_avrc_args_t arg;
  68. memset(&arg, 0, sizeof(btc_avrc_args_t));
  69. arg.pt_cmd.tl = tl;
  70. arg.pt_cmd.key_code = key_code;
  71. arg.pt_cmd.key_state = key_state;
  72. /* Switch to BTC context */
  73. bt_status_t stat = btc_transfer_context(&msg, &arg, sizeof(btc_avrc_args_t), NULL);
  74. return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
  75. }
  76. #endif /* #if BTC_AV_INCLUDED */