Power: output setters return bool, add getPowerOutputCaps() - #374
Merged
Merged
Conversation
setExtOutput / setUsbOutput / setExtPortBusConfig / setVibration report whether the requested state was reached instead of discarding the I2C, IO expander and PMIC results. getPowerOutputCaps() tells a model without the path apart from a failed request, in the same shape as the charge setters. - false: model without the path, I2C failure, protection cancel (Core2 / Tough low battery, CoreS3 family without a battery), AW9523 lock not available or request superseded (CoreS3), unconfirmed PMIC identity, or a port_mask selecting none of the ports. - Multi-port models attempt every selected port and AND the results. - Core2 / Tough: the protection readings are checked reads; a reading that fails refuses the enable request. Units whose INA3221 did not respond keep the previous behaviour (current check skipped). - AXP192 / AXP2101 rail setters: every step is attempted so that a disable still reaches the enable bit; disable reports only the enable bit, enable reports both writes. - setVibration: a nonzero level is clamped to the rail minimum instead of silently switching the rail off. - Checked getters added: AXP192 getBatteryLevel(int8_t*), INA3221 getShuntMilliVoltage(ch, int32_t*), M5PM1 getGPIOOutputLatch(pin, bool*). - build_test exercises the new API. Breaking: return types void -> bool (rebuild dependants); ext_none is now a no-op returning false on every model; setVibration(1..109) on AXP192 drives the motor at the rail minimum instead of stopping it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Power_Class::setExtOutput,setUsbOutput,setExtPortBusConfigandsetVibrationreturnedvoidand discarded the result of the I2C / IO expander / PMIC operations behind them, so a caller could not tell whether the external 5 V, the USB output or the vibration motor were actually switched. This PR makes the four setters report whether the requested state was reached and addsgetPowerOutputCaps()to tell "this model has no such path" apart from "the request failed", in the same shape assetChargeCurrent/getChargeControlCaps().API
setExtOutput(enable, port_mask)voidbool– true when every selected port reached the requested statesetUsbOutput(enable)voidboolsetExtPortBusConfig(config)voidboolsetVibration(level)voidboolgetPowerOutputCaps()uint8_tbitmask ofpower_output_capability_t(cap_set_ext_output/cap_set_usb_output/cap_set_ext_port_bus/cap_set_vibration); 0 beforeM5.begin()completes and on the PC buildAXP192_Class::setEXTEN/setGPIO*/setLDO*,AXP2101_Class::set*LDO*voidboolAXP192_Class::getBatteryLevel(int8_t*),INA3221_Class::getShuntMilliVoltage(ch, int32_t*),M5PM1_Class::getGPIOOutputLatch(pin, bool*)Behaviour
getPowerOutputCaps()), an I2C failure, a protection check that cancelled the request (Core2 / Tough on a low battery, the CoreS3 family without a battery), the AW9523 mutex not being available or the request being superseded on CoreS3, an unconfirmed PMIC identity (same rule as the charge setters), and aport_maskthat selects none of the model's ports (ext_noneon every model).port_maskselects several ports (M5Station, PowerHub, Tab5 family, CoreP4X, ChainCaptain) every selected port is still attempted; false means at least one did not take effect. Models with a single output ignore the mask.setVibration: a non-zero level is clamped up to the lowest voltage the rail can produce (AXP192 LDO3 1800 mV, AXP2101 DLDO1 500 mV). Levels below it used to switch the rail off while the call looked successful.Breaking changes
setExtOutput(enable, ext_none)returns false and does nothing on every model (it used to switch the single output on models that ignore the mask).setVibration(1..109)on a Core2 with AXP192 (andsetVibration(1)with AXP2101) now drives the motor at the rail minimum instead of switching it off.setExtPowerwrapper staysvoid.Not changed (separate issue)
setExtOutput(false)clears BOOST_EN without looking at USB_EN, which stops an enabled USB output. This condition has been in place since the first CoreS3 implementation and is out of scope here.Verification
Build: ESP32 / ESP32-S3 (×2) / C6 / C5 / P4 Arduino, ESP32 ESP-IDF 6.0, native (PC build).