CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
Power

Battery state, USB connection and charger status. More...

Macros

#define POWER_SRC_UNKNOWN   0
#define POWER_SRC_BATTERY   1
#define POWER_SRC_USB   2
#define CHARGE_NOT_CHARGING   0
#define CHARGE_PRE_CHARGE   1
#define CHARGE_FAST   2
#define CHARGE_DONE   3
#define CHARGE_FAULT   4

Functions

uint16_t host_battery_mv (void)
 Battery voltage in millivolts.
uint8_t host_battery_pct (void)
 Battery state of charge as 0..100 percent.
bool host_is_usb_connected (void)
 True when USB VBUS is detected.
uint8_t host_power_source (void)
 Active power source - one of POWER_SRC_*.
uint8_t host_charge_status (void)
 Charger state machine value - one of CHARGE_*.
bool host_is_battery_low (void)
 True when battery has crossed the low-warning threshold.
bool host_is_battery_critical (void)
 True when battery has crossed the critical-shutdown threshold.
void host_set_sleep_inhibit (uint32_t on)
 Hold or release a light-sleep inhibitor for the calling plugin. While any inhibitor is held the badge does not enter light sleep, so a background plugin keeps ticking. Keyed by the plugin id and released automatically when the plugin is unloaded.

Detailed Description

Battery state, USB connection and charger status.

Macro Definition Documentation

◆ CHARGE_DONE

#define CHARGE_DONE   3

Definition at line 122 of file host_api.h.

◆ CHARGE_FAST

#define CHARGE_FAST   2

Definition at line 121 of file host_api.h.

◆ CHARGE_FAULT

#define CHARGE_FAULT   4

Definition at line 123 of file host_api.h.

◆ CHARGE_NOT_CHARGING

#define CHARGE_NOT_CHARGING   0

Definition at line 119 of file host_api.h.

Referenced by host_charge_status().

◆ CHARGE_PRE_CHARGE

#define CHARGE_PRE_CHARGE   1

Definition at line 120 of file host_api.h.

◆ POWER_SRC_BATTERY

#define POWER_SRC_BATTERY   1

Definition at line 116 of file host_api.h.

Referenced by host_power_source().

◆ POWER_SRC_UNKNOWN

#define POWER_SRC_UNKNOWN   0

Definition at line 115 of file host_api.h.

Referenced by host_power_source().

◆ POWER_SRC_USB

#define POWER_SRC_USB   2

Definition at line 117 of file host_api.h.

Referenced by host_power_source().

Function Documentation

◆ host_battery_mv()

uint16_t host_battery_mv ( void )

Battery voltage in millivolts.

Definition at line 18 of file host_api_power.cpp.

References getPowerManagerInstance().

Referenced by cdc::plugin_manager::w_host_battery_mv().

◆ host_battery_pct()

uint8_t host_battery_pct ( void )

Battery state of charge as 0..100 percent.

Definition at line 24 of file host_api_power.cpp.

References getPowerManagerInstance().

Referenced by cdc::plugin_manager::w_host_battery_pct().

◆ host_charge_status()

uint8_t host_charge_status ( void )

Charger state machine value - one of CHARGE_*.

Definition at line 48 of file host_api_power.cpp.

References CHARGE_NOT_CHARGING, and getPowerManagerInstance().

Referenced by cdc::plugin_manager::w_host_charge_status().

◆ host_is_battery_critical()

bool host_is_battery_critical ( void )

True when battery has crossed the critical-shutdown threshold.

Definition at line 60 of file host_api_power.cpp.

References getPowerManagerInstance().

Referenced by cdc::plugin_manager::w_host_is_battery_critical().

◆ host_is_battery_low()

bool host_is_battery_low ( void )

True when battery has crossed the low-warning threshold.

Definition at line 54 of file host_api_power.cpp.

References getPowerManagerInstance().

Referenced by cdc::plugin_manager::w_host_is_battery_low().

◆ host_is_usb_connected()

bool host_is_usb_connected ( void )

True when USB VBUS is detected.

Definition at line 30 of file host_api_power.cpp.

References getPowerManagerInstance().

Referenced by cdc::plugin_manager::w_host_is_usb_connected().

◆ host_power_source()

uint8_t host_power_source ( void )

Active power source - one of POWER_SRC_*.

Definition at line 36 of file host_api_power.cpp.

References cdc::hal::BATTERY, getPowerManagerInstance(), POWER_SRC_BATTERY, POWER_SRC_UNKNOWN, POWER_SRC_USB, and cdc::hal::USB.

Referenced by cdc::plugin_manager::w_host_power_source().

◆ host_set_sleep_inhibit()

void host_set_sleep_inhibit ( uint32_t on)

Hold or release a light-sleep inhibitor for the calling plugin. While any inhibitor is held the badge does not enter light sleep, so a background plugin keeps ticking. Keyed by the plugin id and released automatically when the plugin is unloaded.

Parameters
onNon-zero to hold the inhibitor, zero to release it.

Definition at line 66 of file host_api_power.cpp.

References cdc::ui::SleepManager::instance(), and plg_get_active_plugin().

Referenced by cdc::plugin_manager::w_host_set_sleep_inhibit().