btif_avrcp.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2016 Actions Semi Co., Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief bt avrcp interface
  9. */
  10. #define SYS_LOG_DOMAIN "btif_avrcp"
  11. #include "btsrv_os_common.h"
  12. #include "btsrv_inner.h"
  13. int btif_avrcp_register_processer(void)
  14. {
  15. return btsrv_register_msg_processer(MSG_BTSRV_AVRCP, &btsrv_avrcp_process);
  16. }
  17. int btif_avrcp_start(btsrv_avrcp_callback_t *cb)
  18. {
  19. return btsrv_function_call(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_START, (void *)cb);
  20. }
  21. int btif_avrcp_stop(void)
  22. {
  23. return btsrv_function_call(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_STOP, (void *)NULL);
  24. }
  25. int btif_avrcp_connect(bd_address_t *addr)
  26. {
  27. return btsrv_function_call_malloc(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_CONNECT_TO, (void *)addr, sizeof(bd_address_t), 0);
  28. }
  29. int btif_avrcp_disconnect(bd_address_t *addr)
  30. {
  31. return btsrv_function_call_malloc(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_DISCONNECT, (void *)addr, sizeof(bd_address_t), 0);
  32. }
  33. int btif_avrcp_send_command(int command)
  34. {
  35. return btsrv_function_call(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_SEND_CMD, (void *)command);
  36. }
  37. int btif_avrcp_sync_vol(uint32_t volume)
  38. {
  39. return btsrv_function_call(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_SYNC_VOLUME, (void *)volume);
  40. }
  41. int btif_avrcp_get_id3_info()
  42. {
  43. return btsrv_function_call(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_GET_ID3_INFO, (void *)NULL);
  44. }
  45. bool btif_avrcp_is_support_get_playback_pos()
  46. {
  47. bool ret;
  48. int flags;
  49. flags = btsrv_set_negative_prio();
  50. ret = btsrv_avrcp_is_support_get_playback_pos();
  51. btsrv_revert_prio(flags);
  52. return ret;
  53. }
  54. int btif_avrcp_get_playback_pos()
  55. {
  56. return btsrv_function_call(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_GET_PLAYBACK_POS, (void *)NULL);
  57. }
  58. int btif_avrcp_set_absolute_volume(uint8_t dev_type, uint8_t *data, uint8_t len)
  59. {
  60. union {
  61. uint8_t c_param[4]; /* 0:dev_type, 1:len, 2~3:data */
  62. int32_t i_param;
  63. } param;
  64. if (len < 1 || len > 2) {
  65. return -EINVAL;
  66. }
  67. param.c_param[0] = dev_type;
  68. param.c_param[1] = len;
  69. param.c_param[2] = data[0];
  70. param.c_param[3] = (len == 2) ? data[1] : 0;
  71. return btsrv_event_notify_value(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_SET_ABSOLUTE_VOLUME, param.i_param);
  72. }
  73. int btif_avrcp_get_play_status(void)
  74. {
  75. return btsrv_function_call(MSG_BTSRV_AVRCP, MSG_BTSRV_AVRCP_GET_PLAY_STATE, (void *)NULL);
  76. }