objc

power.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include <runtime-sys/sys.h>
23 #include <stdbool.h>
24 #include <stdint.h>
25 
27 // TYPES
28 
29 #define HW_POWER_CTX_SIZE 64
30 
31 // Opaque power management handle
32 typedef struct hw_power_t hw_power_t;
33 
44 typedef enum {
46  HW_POWER_USB = (1 << 0),
47  HW_POWER_BATTERY = (1 << 1),
48  HW_POWER_RESET = (1 << 2),
50 
64 typedef void (*hw_power_callback_t)(hw_power_t *power, hw_power_flag_t flags,
65  uint32_t value, void *user_data);
66 
68 // LIFECYCLE
69 
85 hw_power_t *hw_power_init(uint8_t gpio_vsys, uint8_t gpio_vbus,
86  hw_power_callback_t callback, void *user_data);
87 
94 bool hw_power_valid(hw_power_t *power);
95 
104 void hw_power_finalize(hw_power_t *power);
105 
114 uint8_t hw_power_battery_percent(hw_power_t *power);
115 
122 hw_power_flag_t hw_power_source(hw_power_t *power);
Unknown power source.
Definition: power.h:45
Battery power.
Definition: power.h:47
void hw_power_finalize(hw_power_t *power)
Finalize and release any resources.
System management functions.
USB (VBUS) power.
Definition: power.h:46
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.
bool hw_power_valid(hw_power_t *power)
Determine if the power handle is initialized and usable.
void(* hw_power_callback_t)(hw_power_t *power, hw_power_flag_t flags, uint32_t value, void *user_data)
Power status callback prototype.
Definition: power.h:64
Hardware will reset.
Definition: power.h:48
hw_power_flag_t
Power source capability / status flags.
Definition: power.h:44
uint8_t hw_power_battery_percent(hw_power_t *power)
Approximate battery state of charge.
hw_power_flag_t hw_power_source(hw_power_t *power)
Current detected power source(s).