battservice.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. #ifndef BATTSERVICE_H
  29. #define BATTSERVICE_H
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /*********************************************************************
  35. * INCLUDES
  36. */
  37. /*********************************************************************
  38. * CONSTANTS
  39. */
  40. // Battery Service Get/Set Parameters
  41. #define BATT_PARAM_LEVEL 0
  42. #define BATT_PARAM_CRITICAL_LEVEL 1
  43. #define BATT_PARAM_SERVICE_HANDLE 2
  44. #define BATT_PARAM_BATT_LEVEL_IN_REPORT 3
  45. // Callback events
  46. #define BATT_LEVEL_NOTI_ENABLED 1
  47. #define BATT_LEVEL_NOTI_DISABLED 2
  48. // HID Report IDs for the service
  49. #define HID_RPT_ID_BATT_LEVEL_IN 4 // Battery Level input report ID
  50. #ifdef HID_VOICE_SPEC
  51. #define GATT_DESC_LENGTH_UUID 0x3111 // Used with Unit percent
  52. #endif
  53. /*********************************************************************
  54. * TYPEDEFS
  55. */
  56. // Battery Service callback function
  57. typedef void (*battServiceCB_t)(uint8 event);
  58. // Battery measure HW setup function
  59. typedef void (*battServiceSetupCB_t)(void);
  60. // Battery measure percentage calculation function
  61. typedef uint8 (*battServiceCalcCB_t)(uint16 adcVal);
  62. // Battery measure HW teardown function
  63. typedef void (*battServiceTeardownCB_t)(void);
  64. /*********************************************************************
  65. * MACROS
  66. */
  67. /*********************************************************************
  68. * Profile Callbacks
  69. */
  70. /*********************************************************************
  71. * API FUNCTIONS
  72. */
  73. /*********************************************************************
  74. * @fn Batt_AddService
  75. *
  76. * @brief Initializes the Battery service by registering
  77. * GATT attributes with the GATT server.
  78. *
  79. * @return Success or Failure
  80. */
  81. extern bStatus_t Batt_AddService( void );
  82. /*********************************************************************
  83. * @fn Batt_Register
  84. *
  85. * @brief Register a callback function with the Battery Service.
  86. *
  87. * @param pfnServiceCB - Callback function.
  88. *
  89. * @return None.
  90. */
  91. extern void Batt_Register( battServiceCB_t pfnServiceCB );
  92. /*********************************************************************
  93. * @fn Batt_SetParameter
  94. *
  95. * @brief Set a Battery Service parameter.
  96. *
  97. * @param param - Profile parameter ID
  98. * @param len - length of data to right
  99. * @param value - pointer to data to write. This is dependent on
  100. * the parameter ID and WILL be cast to the appropriate
  101. * data type (example: data type of uint16 will be cast to
  102. * uint16 pointer).
  103. *
  104. * @return bStatus_t
  105. */
  106. extern bStatus_t Batt_SetParameter( uint8 param, uint8 len, void *value );
  107. /*********************************************************************
  108. * @fn Batt_GetParameter
  109. *
  110. * @brief Get a Battery parameter.
  111. *
  112. * @param param - Profile parameter ID
  113. * @param value - pointer to data to get. This is dependent on
  114. * the parameter ID and WILL be cast to the appropriate
  115. * data type (example: data type of uint16 will be cast to
  116. * uint16 pointer).
  117. *
  118. * @return bStatus_t
  119. */
  120. extern bStatus_t Batt_GetParameter( uint8 param, void *value );
  121. /*********************************************************************
  122. * @fn Batt_MeasLevel
  123. *
  124. * @brief Measure the battery level and update the battery
  125. * level value in the service characteristics. If
  126. * the battery level-state characteristic is configured
  127. * for notification and the battery level has changed
  128. * since the last measurement, then a notification
  129. * will be sent.
  130. *
  131. * @return Success or Failure
  132. */
  133. extern bStatus_t Batt_MeasLevel( void );
  134. /*********************************************************************
  135. * @fn Batt_Setup
  136. *
  137. * @brief Set up which ADC source is to be used. Defaults to VDD/3.
  138. *
  139. * @param adc_ch - ADC Channel, e.g. HAL_ADC_CHN_AIN6
  140. * @param minVal - max battery level
  141. * @param maxVal - min battery level
  142. * @param sCB - HW setup callback
  143. * @param tCB - HW tear down callback
  144. * @param cCB - percentage calculation callback
  145. *
  146. * @return none.
  147. */
  148. extern void Batt_Setup( uint8 adc_ch, uint16 minVal, uint16 maxVal,
  149. battServiceSetupCB_t sCB, battServiceTeardownCB_t tCB,
  150. battServiceCalcCB_t cCB );
  151. /*********************************************************************
  152. * @fn Batt_HandleConnStatusCB
  153. *
  154. * @brief Battery Service link status change handler function.
  155. *
  156. * @param connHandle - connection handle
  157. * @param changeType - type of change
  158. *
  159. * @return none
  160. */
  161. void Batt_HandleConnStatusCB( uint16 connHandle, uint8 changeType );
  162. /*********************************************************************
  163. *********************************************************************/
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif /* BATTSERVICE_H */