1 /* 2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. 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 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 **************************************************************************************** 18 * 19 * @file sonata_prf_bass_api.h 20 * 21 * @brief header file - Battery service server api 22 * 23 **************************************************************************************** 24 */ 25 26 #ifndef _SONATA_PRF_BASS_API_H_ 27 #define _SONATA_PRF_BASS_API_H_ 28 29 /** 30 * @defgroup SONATA_PRF_BASS_API PRF_BASS_API 31 * @{ 32 */ 33 34 /* 35 * INCLUDE FILES 36 **************************************************************************************** 37 */ 38 39 // #if (BLE_APP_BATT) 40 41 #include <stdint.h> // Standard Integer Definition 42 #include "sonata_ble_api.h" 43 44 /* 45 * STRUCTURES DEFINITION 46 **************************************************************************************** 47 */ 48 49 /* 50 * Type Definition 51 **************************************************************************************** 52 */ 53 54 /*! 55 * @brief Callback for diss value 56 */ 57 typedef struct prf_bas_callback { 58 // Callback for battery level request, if config==1, app should send battery level value use sonata_prf_bas_send_battery_level() 59 uint16_t (*prf_bass_value_req)(uint8_t conidx, uint8_t config); 60 // Callback for bass enabled 61 uint16_t (*prf_bass_enable)(uint8_t conidx, uint8_t status); 62 // Callback for battery level notifiyed 63 uint16_t (*prf_bass_level_updated)(uint8_t status); 64 65 } prf_bas_callback_t; 66 67 typedef enum { 68 // Start the Battery Server - at connection used to restore bond data 69 SONATA_PRF_BASS_ENABLE_REQ = SONATA_TASK_FIRST_MSG(SONATA_TASK_ID_BASS), 70 // Confirmation of the Battery Server start 71 SONATA_PRF_BASS_ENABLE_RSP, 72 // Battery Level Value Update Request 73 SONATA_PRF_BASS_BATT_LEVEL_UPD_REQ, 74 // Inform APP if Battery Level value has been notified or not 75 SONATA_PRF_BASS_BATT_LEVEL_UPD_RSP, 76 // Inform APP that Battery Level Notification Configuration has been changed - use to update bond data 77 SONATA_PRF_BASS_BATT_LEVEL_NTF_CFG_IND, 78 } sonata_bass_msg_id; 79 80 /* 81 * GLOBAL VARIABLES DECLARATIONS 82 **************************************************************************************** 83 */ 84 85 /* 86 * FUNCTIONS DECLARATION 87 **************************************************************************************** 88 */ 89 90 /*! 91 * @brief Init environment 92 */ 93 void sonata_prf_bass_init(void); 94 95 /*! 96 * @brief Add a Battery Service instance in the DB 97 */ 98 void sonata_prf_bas_add_bass(uint8_t bas_number, bool support_ntf); 99 100 /*! 101 * @brief Enable the Battery Service 102 * @param conidx connection index 103 * @param batt_lvl battery level value 104 */ 105 void sonata_prf_bas_enable_bass(uint8_t conidx, uint8_t batt_lvl); 106 107 /*! 108 * @brief Send a Battery level value 109 * @param batt_id For single battery, batt_id is 0 110 * @param batt_lvl battery level value (0~100) 111 * @return API_SUCCESS 112 */ 113 int sonata_prf_bas_send_battery_level(uint8_t batt_id, uint8_t batt_lvl); 114 115 /*! 116 * @brief Set callback function 117 * @param cb callback functions 118 * @return API_SUCCESS 119 */ 120 uint16_t sonata_prf_bas_register_callback(prf_bas_callback_t *cb); 121 122 // #endif // (BLE_APP_BATT) 123 124 /** @}*/ 125 126 extern const sonata_api_subtask_handlers_t prf_bass_api_ke_msg_handlers; 127 128 #endif // _SONATA_PRF_BASS_API_H_ 129