battservice.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * @file
  3. * @author chipsea
  4. * @brief
  5. * @version 0.1
  6. * @date 2020-11-30
  7. * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
  8. * @note
  9. */
  10. #ifndef BATTSERVICE_H
  11. #define BATTSERVICE_H
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /*********************************************************************
  17. * INCLUDES
  18. */
  19. /*********************************************************************
  20. * CONSTANTS
  21. */
  22. // Battery Service Get/Set Parameters
  23. #define BATT_PARAM_LEVEL 0
  24. #define BATT_PARAM_CRITICAL_LEVEL 1
  25. #define BATT_PARAM_SERVICE_HANDLE 2
  26. #define BATT_PARAM_BATT_LEVEL_IN_REPORT 3
  27. // Callback events
  28. #define BATT_LEVEL_NOTI_ENABLED 1
  29. #define BATT_LEVEL_NOTI_DISABLED 2
  30. // HID Report IDs for the service
  31. #define HID_RPT_ID_BATT_LEVEL_IN 4 // Battery Level input report ID
  32. #ifdef HID_VOICE_SPEC
  33. #define GATT_DESC_LENGTH_UUID 0x3111 // Used with Unit percent
  34. #endif
  35. /*********************************************************************
  36. * TYPEDEFS
  37. */
  38. // Battery Service callback function
  39. typedef void (*battServiceCB_t)(uint8 event);
  40. // Battery measure HW setup function
  41. typedef void (*battServiceSetupCB_t)(void);
  42. // Battery measure percentage calculation function
  43. typedef uint8 (*battServiceCalcCB_t)(uint16 adcVal);
  44. // Battery measure HW teardown function
  45. typedef void (*battServiceTeardownCB_t)(void);
  46. /*********************************************************************
  47. * MACROS
  48. */
  49. /*********************************************************************
  50. * Profile Callbacks
  51. */
  52. /*********************************************************************
  53. * API FUNCTIONS
  54. */
  55. /*********************************************************************
  56. * @fn Batt_AddService
  57. *
  58. * @brief Initializes the Battery service by registering
  59. * GATT attributes with the GATT server.
  60. *
  61. * @return Success or Failure
  62. */
  63. extern bStatus_t Batt_AddService( void );
  64. /*********************************************************************
  65. * @fn Batt_Register
  66. *
  67. * @brief Register a callback function with the Battery Service.
  68. *
  69. * @param pfnServiceCB - Callback function.
  70. *
  71. * @return None.
  72. */
  73. extern void Batt_Register( battServiceCB_t pfnServiceCB );
  74. /*********************************************************************
  75. * @fn Batt_SetParameter
  76. *
  77. * @brief Set a Battery Service parameter.
  78. *
  79. * @param param - Profile parameter ID
  80. * @param len - length of data to right
  81. * @param value - pointer to data to write. This is dependent on
  82. * the parameter ID and WILL be cast to the appropriate
  83. * data type (example: data type of uint16 will be cast to
  84. * uint16 pointer).
  85. *
  86. * @return bStatus_t
  87. */
  88. extern bStatus_t Batt_SetParameter( uint8 param, uint8 len, void *value );
  89. /*********************************************************************
  90. * @fn Batt_GetParameter
  91. *
  92. * @brief Get a Battery parameter.
  93. *
  94. * @param param - Profile parameter ID
  95. * @param value - pointer to data to get. This is dependent on
  96. * the parameter ID and WILL be cast to the appropriate
  97. * data type (example: data type of uint16 will be cast to
  98. * uint16 pointer).
  99. *
  100. * @return bStatus_t
  101. */
  102. extern bStatus_t Batt_GetParameter( uint8 param, void *value );
  103. /*********************************************************************
  104. * @fn Batt_MeasLevel
  105. *
  106. * @brief Measure the battery level and update the battery
  107. * level value in the service characteristics. If
  108. * the battery level-state characteristic is configured
  109. * for notification and the battery level has changed
  110. * since the last measurement, then a notification
  111. * will be sent.
  112. *
  113. * @return Success or Failure
  114. */
  115. extern bStatus_t Batt_MeasLevel( void );
  116. /*********************************************************************
  117. * @fn Batt_Setup
  118. *
  119. * @brief Set up which ADC source is to be used. Defaults to VDD/3.
  120. *
  121. * @param adc_ch - ADC Channel, e.g. HAL_ADC_CHN_AIN6
  122. * @param minVal - max battery level
  123. * @param maxVal - min battery level
  124. * @param sCB - HW setup callback
  125. * @param tCB - HW tear down callback
  126. * @param cCB - percentage calculation callback
  127. *
  128. * @return none.
  129. */
  130. extern void Batt_Setup( uint8 adc_ch, uint16 minVal, uint16 maxVal,
  131. battServiceSetupCB_t sCB, battServiceTeardownCB_t tCB,
  132. battServiceCalcCB_t cCB );
  133. /*********************************************************************
  134. * @fn Batt_HandleConnStatusCB
  135. *
  136. * @brief Battery Service link status change handler function.
  137. *
  138. * @param connHandle - connection handle
  139. * @param changeType - type of change
  140. *
  141. * @return none
  142. */
  143. void Batt_HandleConnStatusCB( uint16 connHandle, uint8 changeType );
  144. /*********************************************************************
  145. *********************************************************************/
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* BATTSERVICE_H */