amiro-os / devices / PowerManagement / global.hpp @ ba75ee1d
History | View | Annotate | Download (6.936 KB)
1 |
#ifndef AMIRO_GLOBAL_HPP_
|
---|---|
2 |
#define AMIRO_GLOBAL_HPP_
|
3 |
|
4 |
#include <hal.h> |
5 |
|
6 |
#include <array> |
7 |
|
8 |
#include <amiro/power/adconverter.hpp> |
9 |
#include <amiro/bus/i2c/HWI2CDriver.hpp> |
10 |
#include <amiro/bus/i2c/VI2CDriver.hpp> |
11 |
#include <amiro/bus/i2c/mux/pca9544.hpp> |
12 |
#include <amiro/proximity/vcnl4020.hpp> |
13 |
#include <amiro/eeprom/at24.hpp> |
14 |
#include <amiro/FileSystemInputOutput/FSIOPowerManagement.hpp> |
15 |
#include <amiro/input/mpr121.hpp> |
16 |
#include <amiro/power/ltc4412.hpp> |
17 |
#include <amiro/power/ina219.hpp> |
18 |
#include <amiro/power/bq27500.hpp> |
19 |
#include <amiro/power/bq24103a.hpp> |
20 |
#include <amiro/power/tps62113.hpp> |
21 |
#include <amiro/bluetooth/bluetooth.hpp> |
22 |
#include <amiro/bluetooth/bluetooth-serial.hpp> |
23 |
#include <amiro/bluetooth/bluetooth-wiimote.hpp> |
24 |
#include <amiro/serial_reset/iwrap_can_mux.hpp> |
25 |
#include <amiro/serial_reset/serial_can_mux.hpp> |
26 |
#include <PowerManagement.h> |
27 |
#include <userthread.h> |
28 |
|
29 |
namespace amiro {
|
30 |
|
31 |
class Global final |
32 |
{ |
33 |
public:
|
34 |
|
35 |
SerialConfig sd1_config{ |
36 |
/* speed */ 115200, |
37 |
/* CR1 register */ 0, |
38 |
/* CR2 register */ 0, |
39 |
/* CR3 register */ 0 |
40 |
}; |
41 |
|
42 |
PWMConfig pwm3_config{ |
43 |
/* frequency [Hz] */ 10000, |
44 |
/* period [ticks] */ 100, |
45 |
/* callback */ NULL, |
46 |
/* channels */ {
|
47 |
{PWM_OUTPUT_DISABLED, NULL},
|
48 |
{PWM_OUTPUT_ACTIVE_HIGH, NULL},
|
49 |
{PWM_OUTPUT_DISABLED, NULL},
|
50 |
{PWM_OUTPUT_DISABLED, NULL}
|
51 |
}, |
52 |
/* CR2 register */ 0, |
53 |
/* break & dead time */ 0 |
54 |
}; |
55 |
|
56 |
I2CConfig i2c1_config{ |
57 |
/* I2C mode */ OPMODE_I2C,
|
58 |
/* frequency */ 100000, |
59 |
/* I2C fast mode duty cycle */ STD_DUTY_CYCLE
|
60 |
}; |
61 |
I2CConfig i2c2_config{ |
62 |
/* I2C mode */ OPMODE_I2C,
|
63 |
/* frequency */ 100000, |
64 |
/* I2C fast mode duty cycle */ STD_DUTY_CYCLE
|
65 |
}; |
66 |
|
67 |
VCNL4020::VCNL4020Config vcnl4020_config{ |
68 |
/* command */ VCNL4020::ALS_EN | VCNL4020::PROX_EN | VCNL4020::SELFTIMED_EN,
|
69 |
/* ambient parameter */ VCNL4020::AMBIENT_RATE_2 | VCNL4020::AMBIENT_AUTO_OFFSET | VCNL4020::AMBIENT_AVG_32,
|
70 |
/* IR LED current [mA] */ 200u, |
71 |
/* proximity rate */ VCNL4020::PROX_RATE_125
|
72 |
}; |
73 |
|
74 |
adcsample_t adc1_buffer[1];
|
75 |
ADCConversionGroup adc1_conversion_group{ |
76 |
/* buffer type */ TRUE, // TRUE=continuous; FALSE=linear |
77 |
/* number of channels */ 1, |
78 |
/* callback function */ NULL, |
79 |
/* error callback */ NULL, |
80 |
/* CR1 */ 0, |
81 |
/* CR2 */ ADC_CR2_SWSTART | ADC_CR2_CONT,
|
82 |
/* SMPR1 */ 0, |
83 |
/* SMPR2 */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
|
84 |
/* HTR */ ADC_HTR_HT,
|
85 |
/* LTR */ 0, |
86 |
/* SQR1 */ ADC_SQR1_NUM_CH(1), |
87 |
/* SQR2 */ 0, |
88 |
/* SQR3 */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9)
|
89 |
}; |
90 |
ADConverter adc1_vsys; |
91 |
|
92 |
HWI2CDriver HW_I2C1; |
93 |
HWI2CDriver HW_I2C2; |
94 |
|
95 |
AT24 at24c01; |
96 |
fileSystemIo::FSIOPowerManagement memory; |
97 |
|
98 |
LTC4412<(uintptr_t)GPIOC, GPIOC_PATH_DC> ltc4412; |
99 |
|
100 |
std::array<INA219::Driver,5> ina219;
|
101 |
|
102 |
std::array<BQ27500::Driver,2> bq27500;
|
103 |
|
104 |
private:
|
105 |
BQ24103A<(uintptr_t)GPIOC, GPIOC_CHARGE_EN1_N, (uintptr_t)GPIOC, GPIOC_CHARGE_STAT1A> bq24103a_p7; |
106 |
BQ24103A<(uintptr_t)GPIOD, GPIOD_CHARGE_EN2_N, (uintptr_t)GPIOB, GPIOB_CHARGE_STAT2A> bq24103a_p8; |
107 |
public:
|
108 |
std::array<BaseBQ24103A*,2> bq24103a;
|
109 |
|
110 |
TPS62113<(uintptr_t)GPIOA, GPIOA_SYS_REG_EN> tps62113_vio18_33_50; |
111 |
TPS62113<(uintptr_t)GPIOB, GPIOB_POWER_EN> tps62113_vsys42; |
112 |
|
113 |
BLUETOOTH wt12; |
114 |
|
115 |
std::array<PCA9544<true>, 2> HW_PCA9544; |
116 |
|
117 |
std::array<VI2CDriver, 4> V_I2C1;
|
118 |
std::array<VI2CDriver, 4> V_I2C2;
|
119 |
|
120 |
std::array<VCNL4020, 8> vcnl4020;
|
121 |
|
122 |
MPR121::MPR121Config mpr121_run_config{ |
123 |
/* global_config */ MPR121::CDT_1 | MPR121::SFI_10 | MPR121::ESI_32 | MPR121::FFI_18 | 16, |
124 |
/* ele_config */ MPR121::CL_ON_ALL | MPR121::ELEPROX_0 | 4, |
125 |
/* auto_config */ MPR121::FFI_18 | MPR121::RETRY_2 | MPR121::BVA_ON_ALL | MPR121::AC_RECONF_EN | MPR121::AC_ENABLE,
|
126 |
/* up_side_limit */ 0x96u, |
127 |
/* low_side_limit */ 0x58u, |
128 |
/* target_level */ 0x68u |
129 |
}; |
130 |
MPR121::MPR121Config mpr121_stdby_config{ |
131 |
/* global_config */ MPR121::CDT_1 | MPR121::SFI_10 | MPR121::ESI_32 | MPR121::FFI_18 | 0, |
132 |
/* ele_config */ MPR121::CL_ON_ALL | MPR121::ELEPROX_0 | 0, /* TODO: hack: turn buttons off for standby */ |
133 |
/* auto_config */ MPR121::FFI_18 | MPR121::RETRY_2 | MPR121::BVA_ON_ALL | MPR121::AC_RECONF_EN | MPR121::AC_ENABLE,
|
134 |
/* up_side_limit */ 0x96u, |
135 |
/* low_side_limit */ 0x58u, |
136 |
/* target_level */ 0x68u |
137 |
}; |
138 |
MPR121 mpr121; |
139 |
|
140 |
IwrapCanMux iwrapcanmux1; |
141 |
SerialCanMux sercanmux1; |
142 |
|
143 |
PowerManagement robot; |
144 |
|
145 |
UserThread userThread; |
146 |
|
147 |
uint8_t shellTermID; |
148 |
|
149 |
public:
|
150 |
Global() : |
151 |
adc1_vsys(ADCD1, adc1_conversion_group, 9000000),
|
152 |
HW_I2C1(&I2CD1), HW_I2C2(&I2CD2), |
153 |
at24c01(0x400u / 0x08u, 0x08u, 500u, &HW_I2C2), |
154 |
memory(at24c01, /*BMSV*/ 1, /*bmsv*/ 2, /*HMV*/ 1, /*hmv*/ 1), |
155 |
ina219{{/* VDD */ INA219::Driver(HW_I2C2, 0x45u), |
156 |
/* VIO 1.8V */ INA219::Driver(HW_I2C1, 0x44u), |
157 |
/* VIO 3.3V */ INA219::Driver(HW_I2C1, 0x40u), |
158 |
/* VIO 4.2V */ INA219::Driver(HW_I2C2, 0x40u), |
159 |
/* VIO 5.0V */ INA219::Driver(HW_I2C2, 0x44u)} |
160 |
}, |
161 |
bq27500{{/* connector P7 */ BQ27500::Driver(HW_I2C2, *GPIOC, GPIOC_GAUGE_BATGD1_N, *GPIOC, GPIOC_GAUGE_BATLOW1),
|
162 |
/* connector P8 */ BQ27500::Driver(HW_I2C1, *GPIOB, GPIOB_GAUGE_BATGD2_N, *GPIOB, GPIOB_GAUGE_BATLOW2)}
|
163 |
}, |
164 |
bq24103a_p7(), bq24103a_p8(), |
165 |
bq24103a{{&bq24103a_p7, |
166 |
&bq24103a_p8} |
167 |
}, |
168 |
tps62113_vio18_33_50(), tps62113_vsys42(), |
169 |
wt12(&UARTD3), |
170 |
HW_PCA9544{{PCA9544<true>(&HW_I2C1, 0x07u), |
171 |
PCA9544<true>(&HW_I2C2, 0x07u)} |
172 |
}, |
173 |
V_I2C1{{VI2CDriver(&HW_PCA9544[0], 0), |
174 |
VI2CDriver(&HW_PCA9544[0], 1), |
175 |
VI2CDriver(&HW_PCA9544[0], 2), |
176 |
VI2CDriver(&HW_PCA9544[0], 3)} |
177 |
}, |
178 |
V_I2C2{{VI2CDriver(&HW_PCA9544[1], 0), |
179 |
VI2CDriver(&HW_PCA9544[1], 1), |
180 |
VI2CDriver(&HW_PCA9544[1], 2), |
181 |
VI2CDriver(&HW_PCA9544[1], 3)} |
182 |
}, |
183 |
vcnl4020{{/* rear left */ VCNL4020(&V_I2C1[1], &vcnl4020_config), |
184 |
/* left side rear */ VCNL4020(&V_I2C1[3], &vcnl4020_config), |
185 |
/* left side front */ VCNL4020(&V_I2C1[2], &vcnl4020_config), |
186 |
/* front left */ VCNL4020(&V_I2C2[0], &vcnl4020_config), |
187 |
/* front right */ VCNL4020(&V_I2C2[1], &vcnl4020_config), |
188 |
/* right side front */ VCNL4020(&V_I2C2[3], &vcnl4020_config), |
189 |
/* right side rear */ VCNL4020(&V_I2C2[2], &vcnl4020_config), |
190 |
/* rear right */ VCNL4020(&V_I2C1[0], &vcnl4020_config)} |
191 |
}, |
192 |
mpr121(&HW_I2C2, 0),
|
193 |
iwrapcanmux1(&SD1, &CAND1, CAN::POWER_MANAGEMENT_ID), |
194 |
sercanmux1(&SD1, &CAND1, CAN::POWER_MANAGEMENT_ID), |
195 |
robot(&CAND1), |
196 |
userThread() |
197 |
{ |
198 |
memset(this->adc1_buffer, 0, sizeof(adc1_buffer)); |
199 |
|
200 |
return;
|
201 |
} |
202 |
|
203 |
~Global() |
204 |
{ |
205 |
return;
|
206 |
} |
207 |
|
208 |
}; |
209 |
|
210 |
} // end of namespace amiro
|
211 |
|
212 |
#endif /* AMIRO_GLOBAL_HPP_ */ |