objc

Typedefs | Enumerations | Functions

Power management detection of active power source, and approximate battery state. More...

Collaboration diagram for Power:

Typedefs

typedef void(* hw_power_callback_t) (hw_power_t *power, hw_power_flag_t flags, uint32_t value, void *user_data)
 Power status callback prototype. More...
 

Enumerations

enum  hw_power_flag_t { HW_POWER_UNKNOWN = 0, HW_POWER_USB = (1 << 0), HW_POWER_BATTERY = (1 << 1), HW_POWER_RESET = (1 << 2) }
 Power source capability / status flags. More...
 

Functions

hw_power_t * hw_power_init (uint8_t gpio_vsys, uint8_t gpio_vbus, hw_power_callback_t callback, void *user_data)
 Initialize power management. More...
 
bool hw_power_valid (hw_power_t *power)
 Determine if the power handle is initialized and usable. More...
 
void hw_power_finalize (hw_power_t *power)
 Finalize and release any resources. More...
 
uint8_t hw_power_battery_percent (hw_power_t *power)
 Approximate battery state of charge. More...
 
hw_power_flag_t hw_power_source (hw_power_t *power)
 Current detected power source(s). More...
 

Detailed Description

Power management detection of active power source, and approximate battery state.

The power management interface provides battery state of charge reporting (0–100%) when supported, and optional asynchronous callback notification on power changes.

In order to be notified of power changes, the user must provide a callback function when initializing the power management interface, and in the main event loop, call hw_poll().

In order to be notified of reset events, the watchdog must be initialized and the user must call hw_watchdog_reset() to initiate a reset event.

Typedef Documentation

◆ hw_power_callback_t

typedef void(* hw_power_callback_t) (hw_power_t *power, hw_power_flag_t flags, uint32_t value, void *user_data)

Power status callback prototype.

Parameters
powerPointer to the associated power handle
flagsBitmask of power flags that changed since the last callback. If HW_POWER_BATTERY flag is set, the callback may be invoked on battery level changes. If HW_POWER_RESET is set, the callback was invoked on a reset event.
valueIf flags includes HW_POWER_BATTERY then the value is a battery percentage (1-100) or zero if unknown. If HW_POWER_RESET is set, the value is the reset delay in milliseconds.
user_dataOptional user data pointer passed to the callback.

Definition at line 64 of file power.h.

Enumeration Type Documentation

◆ hw_power_flag_t

Power source capability / status flags.

Bitmask describing which power sources are currently present / can be detected. Implementations may return a combination (e.g. USB + BATTERY) if simultaneous presence is detectable; otherwise a single dominant source may be reported. When no information is available, HW_POWER_UNKNOWN is returned.

Enumerator
HW_POWER_UNKNOWN 

Unknown power source.

HW_POWER_USB 

USB (VBUS) power.

HW_POWER_BATTERY 

Battery power.

HW_POWER_RESET 

Hardware will reset.

Definition at line 44 of file power.h.

44  {
45  HW_POWER_UNKNOWN = 0,
46  HW_POWER_USB = (1 << 0),
47  HW_POWER_BATTERY = (1 << 1),
48  HW_POWER_RESET = (1 << 2),
Unknown power source.
Definition: power.h:45
Battery power.
Definition: power.h:47
USB (VBUS) power.
Definition: power.h:46
Hardware will reset.
Definition: power.h:48
hw_power_flag_t
Power source capability / status flags.
Definition: power.h:44

Function Documentation

◆ hw_power_battery_percent()

uint8_t hw_power_battery_percent ( hw_power_t *  power)

Approximate battery state of charge.

Parameters
powerPower handle
Returns
Integer percentage 0–100 inclusive.

If unsupported or indeterminable, returns 100

◆ hw_power_finalize()

void hw_power_finalize ( hw_power_t *  power)

Finalize and release any resources.

Parameters
powerPower handle

Safe to call on an already finalized or never‑initialized handle; in that case it is a no‑op. After finalization, hw_power_valid() returns false.

◆ hw_power_init()

hw_power_t* hw_power_init ( uint8_t  gpio_vsys,
uint8_t  gpio_vbus,
hw_power_callback_t  callback,
void *  user_data 
)

Initialize power management.

Parameters
gpio_vsysGPIO (or 0xFF for default) used for VSYS / battery sense (platform specific)
gpio_vbusGPIO (or 0xFF for default) used for VBUS / USB present detect
callbackOptional callback for asynchronous updates (may be NULL)
Returns
Pointer to a hw_power_t handle, or NULL

GPIO arguments are platform dependent; pass 0xFF to use default signals, or if unavailable. The returned handle is valid if hw_power_valid() subsequently reports true. Supplying a callback enables event driven notification when supported.

◆ hw_power_source()

hw_power_flag_t hw_power_source ( hw_power_t *  power)

Current detected power source(s).

Parameters
powerPower handle
Returns
Bitmask of hw_power_flag_t flags; HW_POWER_UNKNOWN if unknown.

◆ hw_power_valid()

bool hw_power_valid ( hw_power_t *  power)

Determine if the power handle is initialized and usable.

Parameters
powerPower handle
Returns
True if initialized and not finalized; false otherwise.