9 static constexpr int POWER_GD = 0;
10 static constexpr int VECON = 1;
11 static constexpr int ISENSE = 2;
12 static constexpr int MARGSEL = 3;
13 static constexpr int MARGTOL = 4;
14 static constexpr int VTUNE0 = 5;
15 static constexpr int VTUNE1 = 6;
16 static constexpr int VTUNE2 = 7;
20 : regctl_(path, 0x11) {
21 regctl_.setup_gpi(POWER_GD);
22 regctl_.setup_adc(VECON);
23 regctl_.setup_adc(ISENSE);
26 regctl_.setup_gpi(MARGSEL);
28 regctl_.setup_gpi(MARGTOL);
30 regctl_.setup_gpo(VTUNE2, 0);
31 regctl_.setup_gpo(VTUNE1, 1);
32 regctl_.setup_gpo(VTUNE0, 1);
37 void vtune(
int ibit,
int val) {
38 const int pinmap[] = {VTUNE0, VTUNE1, VTUNE2};
39 if (ibit < 0 || ibit > 2)
return;
40 int pin = pinmap[ibit];
42 regctl_.setup_gpi(pin,
false);
44 regctl_.setup_gpo(pin, (val > 0));
49 void set_volts(
float voltage) {
50 int ivolts = int((voltage + 0.02) / 50e-3) - (16);
51 const int maptable[15][3] = {
52 {0, 0, 0}, {0, 0, -1}, {0, 0, 1}, {0, -1, 0}, {0, -1, -1},
53 {0, -1, 1}, {0, 1, 0}, {0, 1, -1}, {0, 1, 1}, {-1, 0, 0},
54 {-1, 0, -1}, {-1, 0, 1}, {-1, -1, 0}, {-1, -1, -1}, {-1, -1, 1}};
56 if (ivolts >= 0 && ivolts < 15) {
57 vtune(0, maptable[ivolts][2]);
58 vtune(1, maptable[ivolts][1]);
59 vtune(2, maptable[ivolts][0]);
64 const int pinmap[] = {VTUNE2, VTUNE1, VTUNE0};
66 for (
int i = 0; i < 3; i++) {
69 if (regctl_.is_gpo(pin)) {
70 if (regctl_.gpo_get_value(pin)) index = index + 2;
74 return ((index + 16) * 50e-3);
77 float econ_volts() {
return regctl_.adc_volts(VECON); }
79 float econ_current_mA() {
80 float deltaV = regctl_.adc_volts(ISENSE) - regctl_.adc_volts(VECON);
81 return deltaV / 50e-3 * 1000;