furi_hal_power.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. /** Go to sleep
  51. */
  52. void furi_hal_power_sleep();
  53. /** Get predicted remaining battery capacity in percents
  54. *
  55. * @return remaining battery capacity in percents
  56. */
  57. uint8_t furi_hal_power_get_pct();
  58. /** Get battery health state in percents
  59. *
  60. * @return health in percents
  61. */
  62. uint8_t furi_hal_power_get_bat_health_pct();
  63. /** Get charging status
  64. *
  65. * @return true if charging
  66. */
  67. bool furi_hal_power_is_charging();
  68. /** Get charge complete status
  69. *
  70. * @return true if done charging and connected to charger
  71. */
  72. bool furi_hal_power_is_charging_done();
  73. /** Switch MCU to SHUTDOWN */
  74. void furi_hal_power_shutdown();
  75. /** Poweroff device
  76. */
  77. void furi_hal_power_off();
  78. /** Reset device
  79. */
  80. void furi_hal_power_reset();
  81. /** OTG enable
  82. */
  83. void furi_hal_power_enable_otg();
  84. /** OTG disable
  85. */
  86. void furi_hal_power_disable_otg();
  87. /** Check OTG status and disable it if falt happened
  88. */
  89. void furi_hal_power_check_otg_status();
  90. /** Get OTG status
  91. *
  92. * @return true if enabled
  93. */
  94. bool furi_hal_power_is_otg_enabled();
  95. /** Get battery charge voltage limit in V
  96. *
  97. * @return voltage in V
  98. */
  99. float furi_hal_power_get_battery_charge_voltage_limit();
  100. /** Set battery charge voltage limit in V
  101. *
  102. * Invalid values will be clamped downward to the nearest valid value.
  103. *
  104. * @param voltage[in] voltage in V
  105. *
  106. * @return voltage in V
  107. */
  108. void furi_hal_power_set_battery_charge_voltage_limit(float voltage);
  109. /** Get remaining battery battery capacity in mAh
  110. *
  111. * @return capacity in mAh
  112. */
  113. uint32_t furi_hal_power_get_battery_remaining_capacity();
  114. /** Get full charge battery capacity in mAh
  115. *
  116. * @return capacity in mAh
  117. */
  118. uint32_t furi_hal_power_get_battery_full_capacity();
  119. /** Get battery capacity in mAh from battery profile
  120. *
  121. * @return capacity in mAh
  122. */
  123. uint32_t furi_hal_power_get_battery_design_capacity();
  124. /** Get battery voltage in V
  125. *
  126. * @param ic FuriHalPowerIc to get measurment
  127. *
  128. * @return voltage in V
  129. */
  130. float furi_hal_power_get_battery_voltage(FuriHalPowerIC ic);
  131. /** Get battery current in A
  132. *
  133. * @param ic FuriHalPowerIc to get measurment
  134. *
  135. * @return current in A
  136. */
  137. float furi_hal_power_get_battery_current(FuriHalPowerIC ic);
  138. /** Get temperature in C
  139. *
  140. * @param ic FuriHalPowerIc to get measurment
  141. *
  142. * @return temperature in C
  143. */
  144. float furi_hal_power_get_battery_temperature(FuriHalPowerIC ic);
  145. /** Get USB voltage in V
  146. *
  147. * @return voltage in V
  148. */
  149. float furi_hal_power_get_usb_voltage();
  150. /** Enable 3.3v on external gpio and sd card
  151. */
  152. void furi_hal_power_enable_external_3_3v();
  153. /** Disable 3.3v on external gpio and sd card
  154. */
  155. void furi_hal_power_disable_external_3_3v();
  156. /** Enter supress charge mode.
  157. *
  158. * Use this function when your application need clean power supply.
  159. */
  160. void furi_hal_power_suppress_charge_enter();
  161. /** Exit supress charge mode
  162. */
  163. void furi_hal_power_suppress_charge_exit();
  164. /** Get power information
  165. *
  166. * @param[in] callback callback to provide with new data
  167. * @param[in] sep category separator character
  168. * @param[in] context context to pass to callback
  169. */
  170. void furi_hal_power_info_get(PropertyValueCallback callback, char sep, void* context);
  171. /** Get power debug information
  172. *
  173. * @param[in] callback callback to provide with new data
  174. * @param[in] context context to pass to callback
  175. */
  176. void furi_hal_power_debug_get(PropertyValueCallback callback, void* context);
  177. #ifdef __cplusplus
  178. }
  179. #endif