furi_hal_power.h 4.6 KB

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