furi_hal_power.h 4.3 KB

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