furi_hal_power.h 4.6 KB

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