Main entry point of the power handling of the board. Responsible the main state of the power handling.
More...
|
|
void | power_loop () |
| | main loop of the power, running in another thread.
|
| |
| std::string | get_error_string () |
| | Return the error string if set, or "x".
|
| |
|
void | set_error_state_message (const std::string &errorMsg) |
| | Set the error message, if not already set.
|
| |
|
bool | is_output_mode_ready () |
| | Return true when the current state is OUTPUT_VOLTAGE_MODE, and the desired voltage are set and gates are ready. Basically, it returns true when the output is being powered.
|
| |
|
uint32_t | get_vbus_rail_voltage () |
| |
|
uint32_t | get_power_rail_voltage () |
| |
|
void | set_otg_parameters (uint16_t voltage_mV, uint16_t current_mA) |
| |
|
void | handle_clear_power_rails () |
| |
|
void | handle_charging_mode () |
| |
|
void | handle_output_voltage_mode () |
| |
|
void | handle_otg_mode () |
| |
|
void | handle_shutdown () |
| |
| void | handle_startup () |
| |
|
void | handle_error_state () |
| |
|
bool | is_in_error_state () |
| | Return true if the power handling is locked in an ERROR state. No power actions can be made.
|
| |
| bool | go_to_output_mode () |
| | Set the power handler to main OUTPUT_VOLTAGE_MODE.
|
| |
| bool | go_to_charger_mode () |
| | Set the power handler to battery CHARGING_MODE.
|
| |
| bool | go_to_otg_mode () |
| | Set the power handler to OTG_MODE (eg: external battery mode)
|
| |
| bool | go_to_idle () |
| | Set the power handler to IDLE mode (no power output/input)
|
| |
| bool | go_to_shutdown () |
| | Set the power handler to SHUTDOWN mode (last mode before shuting system down)
|
| |
| bool | go_to_error () |
| | Set the power handler to ERROR mode (locked safety state)
|
| |
| void | set_output_voltage_mv (const uint16_t outputVoltage_mV) |
| | Set the desired output voltage of the charger.
|
| |
| void | set_output_max_current_mA (const uint16_t outputCurrent_mA) |
| | Set the desired maximum output current of the charger. This is just an information, that will be used when the state machine reaches the OUTPUT_VOLTAGE_MODE state.
|
| |
| void | set_temporary_output (const uint16_t outputVoltage_mV, const uint16_t outputCurrent_mA, const uint16_t timeout_ms) |
| | Set a new output with a time limit, after wich the output will go back to the original values. It is canceled at any point by a call to set_output_voltage_mv. This is just an information, that will be used when the state machine reaches the OUTPUT_VOLTAGE_MODE state.
|
| |
| bool | enable_charge (const bool) |
| | Block or allow the charging of the battery. Note that the system can still be in CHARGING_MODE mode if you set this to false, but the battery just wont charge.
|
| |
|
std::string | get_state () |
| | Return the current state, as a string.
|
| |
|
bool | is_in_output_mode () |
| | Return true if the current state is OUTPUT_VOLTAGE_MODE.
|
| |
|
bool | is_in_otg_mode () |
| | Return true if the current state is OTG_MODE.
|
| |
|
bool | was_started_in_battery_recovery () |
| | Indicates if the charger tried the battery recovery system.
|
| |
| bool | is_setup () |
| | Return true if the power handler system is effectivly started.
|
| |
|
bool | is_started () |
| | Return true when power machine finally exits the STARTUP.
|
| |
| void | init () |
| | Call once at system startup. This can fail, and it would set the state to ERROR.
|
| |
|
|
bool | _isShutdownCompleted = false |
| | Set to true if the shutdown process is finished cleanly.
|
| |
|
static constexpr uint32_t | clearPowerRailMinDelay_ms = 10 |
| | Minimum allowed power rail clear delay.
|
| |
|
static constexpr uint32_t | clearPowerRailFailureDelay_ms = 3000 |
| | Minimum power rail clear delay after which a failure is signaled. In some rare case the rail can take up to 2 seconds to clear itself.
|
| |
|
static constexpr uint32_t | otgNoUseTimeToDisconnect_ms = 1000 |
| | Delay after which the OTG_MODE will auto disable if a disconnection is detected.
|
| |
|
static constexpr uint8_t | otgTurnOffTimeMinutes = 5 |
| | Delay after which the OTG_MODE will auto disable if not used.
|
| |
|
static constexpr uint32_t | otgNoUseExtBatTimeToDisconnect_ms = 1000 * 60 * otgTurnOffTimeMinutes |
| | Delay after which the OTG_MODE will auto disable if not used, in milliseconds.
|
| |
|
static constexpr uint32_t | startupFailTimeout_ms = 3000 |
| | Delay after which the STARTUP state will auto switch to error.
|
| |
|
static uint16_t | _outputVoltage_mV = 0 |
| | true voltage output
|
| |
|
static uint16_t | _outputCurrent_mA = 0 |
| | true current output limit
|
| |
|
static uint16_t | _temporaryOutputVoltage_mV = 0 |
| | temporary voltage
|
| |
|
static uint16_t | _temporaryOutputCurrent_mA = 0 |
| | temporary current limits
|
| |
|
static uint32_t | _temporaryOutputTimeOut = 0 |
| | temporary output timeout time
|
| |
|
static bool | _isChargeEnabled = false |
| | True if battery charging is allowed.
|
| |
|
static std::string | _errorStr = "" |
| | Store the state error description.
|
| |
|
static bool | _hasAutoSwitchedToOTG = false |
| | True if the state changed to OTG_MODE on it's own (via USB-PD requests).
|
| |
|
static bool | _isInBatteryRecoveryMode = false |
| | in this mode, the battery is too low to power the components. They will be powered through the vbus gate.
|
| |
|
static bool | _wasStartedInBatteryRecoveryMode = false |
| |
| const char *const | PowerStatesStr [] |
| | Name of the states as strings.
|
| |
|
static bool | s_isOutputModeReady = false |
| | True if the OUTPUT_MODE state is ready, ie if the mode is active, the power is as requested and the output gate is enabled.
|
| |
|
static uint32_t | timeSinceOTGNoCurrentUse = 0 |
| | time since no more current is used
|
| |
|
static uint32_t | timeSinceOTGCurrentUse = 0 |
| | track the first current use time
|
| |
| static uint32_t | voltageHighRaisedTime |
| | store the time at which the OTH mode detect high voltage on VBUS
|
| |
|
static bool | isInOtgModeForce = false |
| | Set to true when the PD machne was forced to source already.
|
| |
|
static bool | isSetup = false |
| |
Main entry point of the power handling of the board. Responsible the main state of the power handling.