#ifndef POWER_SOURCE_H #define POWER_SOURCE_H #include #include #include #include "comp_config.h" struct power_source; typedef struct power_source power_source_s; typedef enum { PS_STATUS_SHUTDOWN = 0, PS_STATUS_READY, PS_STATUS_TRANSITION, PS_STATUS_STANDBY, } ps_status_e; typedef enum { PS_CFG_CABLE_COMP, PS_CFG_STATUS, PS_CFG_VSET, PS_CFG_ISET, PS_CFG_V_SAMPLE, PS_CFG_I_SAMPLE, } ps_cfg_type_e; typedef struct power_source_ops { void (*set_voltage)(power_source_s *ps, uint16_t mv); void (*set_current)(power_source_s *ps, uint16_t ma); void (*set_load_switch)(power_source_s *ps, bool en); int (*set)(power_source_s *ps, ps_cfg_type_e type, const void *data); int (*get)(power_source_s *ps, ps_cfg_type_e type, void *data); } power_source_ops_s; struct power_source { const power_source_ops_s *ops; }; static inline void power_source_set_voltage(power_source_s *ps, uint16_t mv) { ps->ops->set_voltage(ps, mv); } static inline void power_source_set_current(power_source_s *ps, uint16_t ma) { ps->ops->set_current(ps, ma); } int power_source_set(power_source_s *ps, ps_cfg_type_e type, const void *data); int power_source_get(power_source_s *ps, ps_cfg_type_e type, void *data); void power_source_set_load_switch(power_source_s *ps, bool en); #endif /* POWER_SOURCE_H */