You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
4 months ago
|
#ifndef POWER_SOURCE_H
|
||
|
#define POWER_SOURCE_H
|
||
|
|
||
|
#include <stdint.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <stddef.h>
|
||
|
#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 */
|