furi_hal_power.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * @file furi_hal_power.h
  3. * Power HAL API
  4. */
  5. #pragma once
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include <core/string.h>
  9. #include <toolbox/property.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /** Power IC type */
  14. typedef enum {
  15. FuriHalPowerICCharger,
  16. FuriHalPowerICFuelGauge,
  17. } FuriHalPowerIC;
  18. /** Initialize drivers */
  19. void furi_hal_power_init();
  20. /** Check if gauge is ok
  21. *
  22. * Verifies that:
  23. * - gauge is alive
  24. * - correct profile loaded
  25. * - self diagnostic status is good
  26. *
  27. * @return true if gauge is ok
  28. */
  29. bool furi_hal_power_gauge_is_ok();
  30. /** Get current insomnia level
  31. *
  32. * @return insomnia level: 0 - no insomnia, >0 - insomnia, bearer count.
  33. */
  34. uint16_t furi_hal_power_insomnia_level();
  35. /** Enter insomnia mode Prevents device from going to sleep
  36. * @warning Internally increases insomnia level Must be paired with
  37. * furi_hal_power_insomnia_exit
  38. */
  39. void furi_hal_power_insomnia_enter();
  40. /** Exit insomnia mode Allow device to go to sleep
  41. * @warning Internally decreases insomnia level. Must be paired with
  42. * furi_hal_power_insomnia_enter
  43. */
  44. void furi_hal_power_insomnia_exit();
  45. /** Check if sleep availble
  46. *
  47. * @return true if available
  48. */
  49. bool furi_hal_power_sleep_available();
  50. /** Check if deep sleep availble
  51. *
  52. * @return true if available
  53. */
  54. bool furi_hal_power_deep_sleep_available();
  55. /** Go to sleep
  56. */
  57. void furi_hal_power_sleep();
  58. /** Get predicted remaining battery capacity in percents
  59. *
  60. * @return remaining battery capacity in percents
  61. */
  62. uint8_t furi_hal_power_get_pct();
  63. /** Get battery health state in percents
  64. *
  65. * @return health in percents
  66. */
  67. uint8_t furi_hal_power_get_bat_health_pct();
  68. /** Get charging status
  69. *
  70. * @return true if charging
  71. */
  72. bool furi_hal_power_is_charging();
  73. /** Get charge complete status
  74. *
  75. * @return true if done charging and connected to charger
  76. */
  77. bool furi_hal_power_is_charging_done();
  78. /** Switch MCU to SHUTDOWN */
  79. void furi_hal_power_shutdown();
  80. /** Poweroff device
  81. */
  82. void furi_hal_power_off();
  83. /** Reset device
  84. */
  85. void furi_hal_power_reset();
  86. /** OTG enable
  87. */
  88. void furi_hal_power_enable_otg();
  89. /** OTG disable
  90. */
  91. void furi_hal_power_disable_otg();
  92. /** Check OTG status and disable it if falt happened
  93. */
  94. void furi_hal_power_check_otg_status();
  95. /** Get OTG status
  96. *
  97. * @return true if enabled
  98. */
  99. bool furi_hal_power_is_otg_enabled();
  100. /** Get battery charging voltage in V
  101. *
  102. * @return voltage in V
  103. */
  104. float furi_hal_power_get_battery_charging_voltage();
  105. /** Set battery charging voltage in V
  106. *
  107. * Invalid values will be clamped to the nearest valid value.
  108. *
  109. * @param voltage[in] voltage in V
  110. *
  111. * @return voltage in V
  112. */
  113. void furi_hal_power_set_battery_charging_voltage(float voltage);
  114. /** Get remaining battery battery capacity in mAh
  115. *
  116. * @return capacity in mAh
  117. */
  118. uint32_t furi_hal_power_get_battery_remaining_capacity();
  119. /** Get full charge battery capacity in mAh
  120. *
  121. * @return capacity in mAh
  122. */
  123. uint32_t furi_hal_power_get_battery_full_capacity();
  124. /** Get battery capacity in mAh from battery profile
  125. *
  126. * @return capacity in mAh
  127. */
  128. uint32_t furi_hal_power_get_battery_design_capacity();
  129. /** Get battery voltage in V
  130. *
  131. * @param ic FuriHalPowerIc to get measurment
  132. *
  133. * @return voltage in V
  134. */
  135. float furi_hal_power_get_battery_voltage(FuriHalPowerIC ic);
  136. /** Get battery current in A
  137. *
  138. * @param ic FuriHalPowerIc to get measurment
  139. *
  140. * @return current in A
  141. */
  142. float furi_hal_power_get_battery_current(FuriHalPowerIC ic);
  143. /** Get temperature in C
  144. *
  145. * @param ic FuriHalPowerIc to get measurment
  146. *
  147. * @return temperature in C
  148. */
  149. float furi_hal_power_get_battery_temperature(FuriHalPowerIC ic);
  150. /** Get USB voltage in V
  151. *
  152. * @return voltage in V
  153. */
  154. float furi_hal_power_get_usb_voltage();
  155. /** Enable 3.3v on external gpio and sd card
  156. */
  157. void furi_hal_power_enable_external_3_3v();
  158. /** Disable 3.3v on external gpio and sd card
  159. */
  160. void furi_hal_power_disable_external_3_3v();
  161. /** Enter supress charge mode.
  162. *
  163. * Use this function when your application need clean power supply.
  164. */
  165. void furi_hal_power_suppress_charge_enter();
  166. /** Exit supress charge mode
  167. */
  168. void furi_hal_power_suppress_charge_exit();
  169. /** Get power information
  170. *
  171. * @param[in] callback callback to provide with new data
  172. * @param[in] sep category separator character
  173. * @param[in] context context to pass to callback
  174. */
  175. void furi_hal_power_info_get(PropertyValueCallback callback, char sep, void* context);
  176. /** Get power debug information
  177. *
  178. * @param[in] callback callback to provide with new data
  179. * @param[in] context context to pass to callback
  180. */
  181. void furi_hal_power_debug_get(PropertyValueCallback callback, void* context);
  182. #ifdef __cplusplus
  183. }
  184. #endif