mics.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * Copyright (c) 2020 Nordic Semiconductor ASA
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_MICS_H_
  7. #define ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_MICS_H_
  8. /**
  9. * @brief Microphone Input Control Service (Microphone Input Control Service)
  10. *
  11. * @defgroup bt_gatt_mics Microphone Input Control Service (Microphone Input Control Service)
  12. *
  13. * @ingroup bluetooth
  14. * @{
  15. *
  16. * [Experimental] Users should note that the APIs can change
  17. * as a part of ongoing development.
  18. */
  19. #include <zephyr/types.h>
  20. #include <bluetooth/audio/aics.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if defined(CONFIG_BT_MICS)
  25. #define BT_MICS_AICS_CNT CONFIG_BT_MICS_AICS_INSTANCE_COUNT
  26. #else
  27. #define BT_MICS_AICS_CNT 0
  28. #endif /* CONFIG_BT_MICS */
  29. /** Application error codes */
  30. #define BT_MICS_ERR_MUTE_DISABLED 0x80
  31. #define BT_MICS_ERR_VAL_OUT_OF_RANGE 0x81
  32. /** Microphone Input Control Service mute states */
  33. #define BT_MICS_MUTE_UNMUTED 0x00
  34. #define BT_MICS_MUTE_MUTED 0x01
  35. #define BT_MICS_MUTE_DISABLED 0x02
  36. /** @brief Opaque Microphone Input Control Service instance. */
  37. struct bt_mics;
  38. /** @brief Register parameters structure for Microphone Input Control Service */
  39. struct bt_mics_register_param {
  40. /** Register parameter structure for Audio Input Control Services */
  41. struct bt_aics_register_param aics_param[BT_MICS_AICS_CNT];
  42. /** Microphone Input Control Service callback structure. */
  43. struct bt_mics_cb *cb;
  44. };
  45. /**
  46. * @brief Microphone Input Control Service included services
  47. *
  48. * Used for to represent the Microphone Input Control Service included service
  49. * instances, for either a client or a server instance. The instance pointers
  50. * either represent local server instances, or remote service instances.
  51. */
  52. struct bt_mics_included {
  53. /** Number of Audio Input Control Service instances */
  54. uint8_t aics_cnt;
  55. /** Array of pointers to Audio Input Control Service instances */
  56. struct bt_aics **aics;
  57. };
  58. /**
  59. * @brief Initialize the Microphone Input Control Service
  60. *
  61. * This will enable the service and make it discoverable by clients.
  62. * This can only be done as the server.
  63. *
  64. * @param param Pointer to an initialization structure.
  65. * @param[out] mics Pointer to the registered Microphone Input Control Service.
  66. * This will still be valid if the return value is -EALREADY.
  67. *
  68. * @return 0 if success, errno on failure.
  69. */
  70. int bt_mics_register(struct bt_mics_register_param *param,
  71. struct bt_mics **mics);
  72. /**
  73. * @brief Get Microphone Input Control Service included services
  74. *
  75. * Returns a pointer to a struct that contains information about the
  76. * Microphone Input Control Service included services instances, such as
  77. * pointers to the Audio Input Control Service instances.
  78. *
  79. * @param mics Microphone Input Control Service instance pointer.
  80. * @param[out] included Pointer to store the result in.
  81. *
  82. * @return 0 if success, errno on failure.
  83. */
  84. int bt_mics_included_get(struct bt_mics *mics,
  85. struct bt_mics_included *included);
  86. /**
  87. * @brief Get the connection pointer of a client instance
  88. *
  89. * Get the Bluetooth connection pointer of a Microphone Input Control Service
  90. * client instance.
  91. *
  92. * @param mics Microphone Input Control Service client instance pointer.
  93. * @param conn Connection pointer.
  94. *
  95. * @return 0 if success, errno on failure.
  96. */
  97. int bt_mics_client_conn_get(const struct bt_mics *mics, struct bt_conn **conn);
  98. /**
  99. * @brief Callback function for @ref bt_mics_discover.
  100. *
  101. * This callback is only used for the client.
  102. *
  103. * @param mics Microphone Input Control Service instance pointer.
  104. * @param err Error value. 0 on success, GATT error or errno on fail.
  105. * @param aics_count Number of Audio Input Control Service instances on
  106. * peer device.
  107. */
  108. typedef void (*bt_mics_discover_cb)(struct bt_mics *mics, int err,
  109. uint8_t aics_count);
  110. /**
  111. * @brief Callback function for Microphone Input Control Service mute.
  112. *
  113. * Called when the value is read,
  114. * or if the value is changed by either the server or client.
  115. *
  116. * @param mics Microphone Input Control Service instance pointer.
  117. * @param err Error value. 0 on success, GATT error or errno on fail.
  118. * For notifications, this will always be 0.
  119. * @param mute The mute setting of the Microphone Input Control Service.
  120. */
  121. typedef void (*bt_mics_mute_read_cb)(struct bt_mics *mics, int err,
  122. uint8_t mute);
  123. /**
  124. * @brief Callback function for Microphone Input Control Service mute/unmute.
  125. *
  126. * @param mics Microphone Input Control Service instance pointer.
  127. * @param err Error value. 0 on success, GATT error or errno on fail.
  128. */
  129. typedef void (*bt_mics_mute_write_cb)(struct bt_mics *mics, int err);
  130. struct bt_mics_cb {
  131. bt_mics_mute_read_cb mute;
  132. #if defined(CONFIG_BT_MICS_CLIENT)
  133. bt_mics_discover_cb discover;
  134. bt_mics_mute_write_cb mute_write;
  135. bt_mics_mute_write_cb unmute_write;
  136. /** Audio Input Control Service client callback */
  137. struct bt_aics_cb aics_cb;
  138. #endif /* CONFIG_BT_MICS_CLIENT */
  139. };
  140. /**
  141. * @brief Discover Microphone Input Control Service
  142. *
  143. * This will start a GATT discovery and setup handles and subscriptions.
  144. * This shall be called once before any other actions can be executed for the
  145. * peer device, and the @ref bt_mics_discover_cb callback will notify when it
  146. * is possible to start remote operations.
  147. *
  148. * This shall only be done as the client.
  149. *
  150. * @param conn The connection to initialize the profile for.
  151. * @param[out] mics Valid remote instance object on success.
  152. *
  153. * @return 0 on success, GATT error value on fail.
  154. */
  155. int bt_mics_discover(struct bt_conn *conn, struct bt_mics **mics);
  156. /**
  157. * @brief Unmute the server.
  158. *
  159. * @param mics Microphone Input Control Service instance pointer.
  160. *
  161. * @return 0 on success, GATT error value on fail.
  162. */
  163. int bt_mics_unmute(struct bt_mics *mics);
  164. /**
  165. * @brief Mute the server.
  166. *
  167. * @param mics Microphone Input Control Service instance pointer.
  168. *
  169. * @return 0 on success, GATT error value on fail.
  170. */
  171. int bt_mics_mute(struct bt_mics *mics);
  172. /**
  173. * @brief Disable the mute functionality.
  174. *
  175. * Can be reenabled by called @ref bt_mics_mute or @ref bt_mics_unmute.
  176. * This can only be done as the server.
  177. *
  178. * @param mics Microphone Input Control Service instance pointer.
  179. *
  180. * @return 0 on success, GATT error value on fail.
  181. */
  182. int bt_mics_mute_disable(struct bt_mics *mics);
  183. /**
  184. * @brief Read the mute state of a Microphone Input Control Service.
  185. *
  186. * @param mics Microphone Input Control Service instance pointer.
  187. *
  188. * @return 0 on success, GATT error value on fail.
  189. */
  190. int bt_mics_mute_get(struct bt_mics *mics);
  191. /**
  192. * @brief Read the Audio Input Control Service input state.
  193. *
  194. * @param mics Microphone Input Control Service instance pointer.
  195. * @param inst Pointer to the Audio Input Control Service instance.
  196. *
  197. * @return 0 on success, GATT error value on fail.
  198. */
  199. int bt_mics_aics_state_get(struct bt_mics *mics, struct bt_aics *inst);
  200. /**
  201. * @brief Read the Audio Input Control Service gain settings.
  202. *
  203. * @param mics Microphone Input Control Service instance pointer.
  204. * @param inst Pointer to the Audio Input Control Service instance.
  205. *
  206. * @return 0 on success, GATT error value on fail.
  207. */
  208. int bt_mics_aics_gain_setting_get(struct bt_mics *mics, struct bt_aics *inst);
  209. /**
  210. * @brief Read the Audio Input Control Service input type.
  211. *
  212. * @param mics Microphone Input Control Service instance pointer.
  213. * @param inst Pointer to the Audio Input Control Service instance.
  214. *
  215. * @return 0 on success, GATT error value on fail.
  216. */
  217. int bt_mics_aics_type_get(struct bt_mics *mics, struct bt_aics *inst);
  218. /**
  219. * @brief Read the Audio Input Control Service input status.
  220. *
  221. * @param mics Microphone Input Control Service instance pointer.
  222. * @param inst Pointer to the Audio Input Control Service instance.
  223. *
  224. * @return 0 on success, GATT error value on fail.
  225. */
  226. int bt_mics_aics_status_get(struct bt_mics *mics, struct bt_aics *inst);
  227. /**
  228. * @brief Unmute the Audio Input Control Service input.
  229. *
  230. * @param mics Microphone Input Control Service instance pointer.
  231. * @param inst Pointer to the Audio Input Control Service instance.
  232. *
  233. * @return 0 on success, GATT error value on fail.
  234. */
  235. int bt_mics_aics_unmute(struct bt_mics *mics, struct bt_aics *inst);
  236. /**
  237. * @brief Mute the Audio Input Control Service input.
  238. *
  239. * @param mics Microphone Input Control Service instance pointer.
  240. * @param inst Pointer to the Audio Input Control Service instance.
  241. *
  242. * @return 0 on success, GATT error value on fail.
  243. */
  244. int bt_mics_aics_mute(struct bt_mics *mics, struct bt_aics *inst);
  245. /**
  246. * @brief Set Audio Input Control Service gain mode to manual.
  247. *
  248. * @param mics Microphone Input Control Service instance pointer.
  249. * @param inst Pointer to the Audio Input Control Service instance.
  250. *
  251. * @return 0 on success, GATT error value on fail.
  252. */
  253. int bt_mics_aics_manual_gain_set(struct bt_mics *mics, struct bt_aics *inst);
  254. /**
  255. * @brief Set Audio Input Control Service gain mode to automatic.
  256. *
  257. * @param mics Microphone Input Control Service instance pointer.
  258. * @param inst Pointer to the Audio Input Control Service instance.
  259. *
  260. * @return 0 on success, GATT error value on fail.
  261. */
  262. int bt_mics_aics_automatic_gain_set(struct bt_mics *mics, struct bt_aics *inst);
  263. /**
  264. * @brief Set Audio Input Control Service input gain.
  265. *
  266. * @param mics Microphone Input Control Service instance pointer.
  267. * @param inst Pointer to the Audio Input Control Service instance.
  268. * @param gain The gain in dB to set (-128 to 127).
  269. *
  270. * @return 0 on success, GATT error value on fail.
  271. */
  272. int bt_mics_aics_gain_set(struct bt_mics *mics, struct bt_aics *inst,
  273. int8_t gain);
  274. /**
  275. * @brief Read the Audio Input Control Service description.
  276. *
  277. * @param mics Microphone Input Control Service instance pointer.
  278. * @param inst Pointer to the Audio Input Control Service instance.
  279. *
  280. * @return 0 on success, GATT error value on fail.
  281. */
  282. int bt_mics_aics_description_get(struct bt_mics *mics, struct bt_aics *inst);
  283. /**
  284. * @brief Set the Audio Input Control Service description.
  285. *
  286. * @param mics Microphone Input Control Service instance pointer.
  287. * @param inst Pointer to the Audio Input Control Service instance.
  288. * @param description The description to set.
  289. *
  290. * @return 0 on success, GATT error value on fail.
  291. */
  292. int bt_mics_aics_description_set(struct bt_mics *mics, struct bt_aics *inst,
  293. const char *description);
  294. /**
  295. * @brief Deactivates a Audio Input Control Service instance.
  296. *
  297. * Audio Input Control Services are activated by default, but this will allow
  298. * the server to deactivate a Audio Input Control Service.
  299. * This can only be done as the server.
  300. *
  301. * @param mics Microphone Input Control Service instance pointer.
  302. * @param inst Pointer to the Audio Input Control Service instance.
  303. *
  304. * @return 0 if success, errno on failure.
  305. */
  306. int bt_mics_aics_deactivate(struct bt_mics *mics, struct bt_aics *inst);
  307. /**
  308. * @brief Activates a Audio Input Control Service instance.
  309. *
  310. * Audio Input Control Services are activated by default, but this will allow
  311. * the server to reactivate a Audio Input Control Service instance after it has
  312. * been deactivated with @ref bt_mics_aics_deactivate.
  313. * This can only be done as the server.
  314. *
  315. * @param mics Microphone Input Control Service instance pointer.
  316. * @param inst Pointer to the Audio Input Control Service instance.
  317. *
  318. * @return 0 if success, errno on failure.
  319. */
  320. int bt_mics_aics_activate(struct bt_mics *mics, struct bt_aics *inst);
  321. /**
  322. * @brief Registers the callbacks used by Microphone Input Control Service client.
  323. *
  324. * This can only be done as the client.
  325. *
  326. * @param cb The callback structure.
  327. *
  328. * @return 0 if success, errno on failure.
  329. */
  330. int bt_mics_client_cb_register(struct bt_mics_cb *cb);
  331. #ifdef __cplusplus
  332. }
  333. #endif
  334. /**
  335. * @}
  336. */
  337. #endif /* ZEPHYR_INCLUDE_BLUETOOTH_SERVICES_MICS_H_ */