amiro-os / os / modules / PowerManagement_1-1 / module.c @ bdf72fa0
History | View | Annotate | Download (37.299 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2018 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | #include "module.h" |
||
20 | |||
21 | /*===========================================================================*/
|
||
22 | /**
|
||
23 | * @name Module specific functions
|
||
24 | * @{
|
||
25 | */
|
||
26 | /*===========================================================================*/
|
||
27 | #include <amiroos.h> |
||
28 | |||
29 | /**
|
||
30 | * @brief Interrupt service routine callback for I/O interrupt signals.
|
||
31 | *
|
||
32 | * @param extp EXT driver to handle the ISR.
|
||
33 | * @param channel Channel on which the interrupt was encountered.
|
||
34 | */
|
||
35 | static void _moduleIsrCallback(EXTDriver* extp, expchannel_t channel) { |
||
36 | (void)extp;
|
||
37 | |||
38 | chSysLockFromISR(); |
||
39 | chEvtBroadcastFlagsI(&aos.events.io.source, (1 << channel));
|
||
40 | chSysUnlockFromISR(); |
||
41 | |||
42 | return;
|
||
43 | } |
||
44 | |||
45 | /** @} */
|
||
46 | |||
47 | /*===========================================================================*/
|
||
48 | /**
|
||
49 | * @name ChibiOS/HAL configuration
|
||
50 | * @{
|
||
51 | */
|
||
52 | /*===========================================================================*/
|
||
53 | |||
54 | ADCConversionGroup moduleHalAdcVsysConversionGroup = { |
||
55 | /* buffer type */ true, |
||
56 | /* number of channels */ 1, |
||
57 | /* callback function */ NULL, |
||
58 | /* error callback */ NULL, |
||
59 | /* CR1 */ ADC_CR1_AWDEN | ADC_CR1_AWDIE,
|
||
60 | /* CR2 */ ADC_CR2_SWSTART | ADC_CR2_CONT,
|
||
61 | /* SMPR1 */ 0, |
||
62 | /* SMPR2 */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
|
||
63 | /* HTR */ ADC_HTR_HT,
|
||
64 | /* LTR */ 0, |
||
65 | /* SQR1 */ ADC_SQR1_NUM_CH(1), |
||
66 | /* SQR2 */ 0, |
||
67 | /* SQR3 */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9),
|
||
68 | }; |
||
69 | |||
70 | CANConfig moduleHalCanConfig = { |
||
71 | /* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||
72 | /* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
||
73 | }; |
||
74 | |||
75 | EXTConfig moduleHalExtConfig = { |
||
76 | /* channel configrations */ {
|
||
77 | /* channel 0 */ { // IR_INT1_N: must be enabled explicitely |
||
78 | /* mode */ EXT_MODE_GPIOB | APAL2CH_EDGE(VCNL4020_LLD_INT_EDGE),
|
||
79 | /* callback */ _moduleIsrCallback,
|
||
80 | }, |
||
81 | /* channel 1 */ { // GAUGE_BATLOW1: must be enabled explicitely |
||
82 | /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_RISING_EDGE,
|
||
83 | /* callback */ _moduleIsrCallback,
|
||
84 | }, |
||
85 | /* channel 2 */ { // GAUGE_BATDG1_N: must be enabled expliciety |
||
86 | /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_RISING_EDGE,
|
||
87 | /* callback */ _moduleIsrCallback,
|
||
88 | }, |
||
89 | /* channel 3 */ { // SYS_UART_DN: automatic interrupt on event |
||
90 | /* mode */ EXT_MODE_GPIOB | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
|
||
91 | /* callback */ _moduleIsrCallback,
|
||
92 | }, |
||
93 | /* channel 4 */ { // IR_INT2_N: must be enabled explicitely |
||
94 | /* mode */ EXT_MODE_GPIOC | APAL2CH_EDGE(VCNL4020_LLD_INT_EDGE),
|
||
95 | /* callback */ _moduleIsrCallback,
|
||
96 | }, |
||
97 | /* channel 5 */ { // TOUCH_INT: must be enabled explicitely |
||
98 | /* mode */ EXT_MODE_GPIOC | APAL2CH_EDGE(MPR121_LLD_INT_EDGE),
|
||
99 | /* callback */ _moduleIsrCallback,
|
||
100 | }, |
||
101 | /* channel 6 */ { // GAUGE_BATLOW2: must be enabled explicitely |
||
102 | /* mode */ EXT_MODE_GPIOB | EXT_CH_MODE_RISING_EDGE,
|
||
103 | /* callback */ _moduleIsrCallback,
|
||
104 | }, |
||
105 | /* channel 7 */ { // GAUGE_BATDG2_N: must be enabled expliciety |
||
106 | /* mode */ EXT_MODE_GPIOB | EXT_CH_MODE_RISING_EDGE,
|
||
107 | /* callback */ _moduleIsrCallback,
|
||
108 | }, |
||
109 | /* channel 8 */ { // PATH_DC: must be enabled explicitely |
||
110 | /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES,
|
||
111 | /* callback */ _moduleIsrCallback,
|
||
112 | }, |
||
113 | /* channel 9 */ { // SYS_SPI_DIR: must be enabled explicitely |
||
114 | /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES,
|
||
115 | /* callback */ _moduleIsrCallback,
|
||
116 | }, |
||
117 | /* channel 10 */ {
|
||
118 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
119 | /* callback */ NULL, |
||
120 | }, |
||
121 | /* channel 11 */ {
|
||
122 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
123 | /* callback */ NULL, |
||
124 | }, |
||
125 | /* channel 12 */ { // SYS_SYNC_N: automatic interrupt on event |
||
126 | /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
|
||
127 | /* callback */ _moduleIsrCallback,
|
||
128 | }, |
||
129 | /* channel 13 */ { // SYS_PD_N: automatic interrupt when activated |
||
130 | /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
|
||
131 | /* callback */ _moduleIsrCallback,
|
||
132 | }, |
||
133 | /* channel 14 */ { // SYS_WARMRST_N: automatic interrupt when activated |
||
134 | /* mode */ EXT_MODE_GPIOC | EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART,
|
||
135 | /* callback */ _moduleIsrCallback,
|
||
136 | }, |
||
137 | /* channel 15 */ { // SYS_UART_UP: automatic interrupt on event |
||
138 | /* mode */ EXT_MODE_GPIOB| EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART,
|
||
139 | /* callback */ _moduleIsrCallback,
|
||
140 | }, |
||
141 | /* channel 16 */ {
|
||
142 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
143 | /* callback */ NULL, |
||
144 | }, |
||
145 | /* channel 17 */ {
|
||
146 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
147 | /* callback */ NULL, |
||
148 | }, |
||
149 | /* channel 18 */ {
|
||
150 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
151 | /* callback */ NULL, |
||
152 | }, |
||
153 | /* channel 19 */ {
|
||
154 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
155 | /* callback */ NULL, |
||
156 | }, |
||
157 | /* channel 20 */ {
|
||
158 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
159 | /* callback */ NULL, |
||
160 | }, |
||
161 | /* channel 21 */ {
|
||
162 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
163 | /* callback */ NULL, |
||
164 | }, |
||
165 | /* channel 22 */ {
|
||
166 | /* mode */ EXT_CH_MODE_DISABLED,
|
||
167 | /* callback */ NULL, |
||
168 | }, |
||
169 | }, |
||
170 | }; |
||
171 | |||
172 | I2CConfig moduleHalI2cProxPm18Pm33GaugeRearConfig = { |
||
173 | /* I²C mode */ OPMODE_I2C,
|
||
174 | /* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
||
175 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
176 | }; |
||
177 | |||
178 | I2CConfig moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig = { |
||
179 | /* I²C mode */ OPMODE_I2C,
|
||
180 | /* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
||
181 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
182 | }; |
||
183 | |||
184 | PWMConfig moduleHalPwmBuzzerConfig = { |
||
185 | /* frequency */ 1000000, |
||
186 | /* period */ 0, |
||
187 | /* callback */ NULL, |
||
188 | /* channel configurations */ {
|
||
189 | /* channel 0 */ {
|
||
190 | /* mode */ PWM_OUTPUT_DISABLED,
|
||
191 | /* callback */ NULL |
||
192 | }, |
||
193 | /* channel 1 */ {
|
||
194 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
195 | /* callback */ NULL |
||
196 | }, |
||
197 | /* channel 2 */ {
|
||
198 | /* mode */ PWM_OUTPUT_DISABLED,
|
||
199 | /* callback */ NULL |
||
200 | }, |
||
201 | /* channel 3 */ {
|
||
202 | /* mode */ PWM_OUTPUT_DISABLED,
|
||
203 | /* callback */ NULL |
||
204 | }, |
||
205 | }, |
||
206 | /* TIM CR2 register */ 0, |
||
207 | #if STM32_PWM_USE_ADVANCED
|
||
208 | /* TIM BDTR register */ 0, |
||
209 | #endif
|
||
210 | /* TIM DIER register */ 0, |
||
211 | }; |
||
212 | |||
213 | SerialConfig moduleHalProgIfConfig = { |
||
214 | /* bit rate */ 115200, |
||
215 | /* CR1 */ 0, |
||
216 | /* CR1 */ 0, |
||
217 | /* CR1 */ 0, |
||
218 | }; |
||
219 | |||
220 | /** @} */
|
||
221 | |||
222 | /*===========================================================================*/
|
||
223 | /**
|
||
224 | * @name GPIO definitions
|
||
225 | * @{
|
||
226 | */
|
||
227 | /*===========================================================================*/
|
||
228 | |||
229 | apalGpio_t moduleGpioSysRegEn = { |
||
230 | /* port */ GPIOA,
|
||
231 | /* pad */ GPIOA_SYS_REG_EN,
|
||
232 | }; |
||
233 | |||
234 | apalGpio_t moduleGpioIrInt1 = { |
||
235 | /* port */ GPIOB,
|
||
236 | /* pad */ GPIOB_IR_INT1_N,
|
||
237 | }; |
||
238 | |||
239 | apalGpio_t moduleGpioPowerEn = { |
||
240 | /* port */ GPIOB,
|
||
241 | /* pad */ GPIOB_POWER_EN,
|
||
242 | }; |
||
243 | |||
244 | apalGpio_t moduleGpioSysUartDn = { |
||
245 | /* port */ GPIOB,
|
||
246 | /* pad */ GPIOB_SYS_UART_DN,
|
||
247 | }; |
||
248 | |||
249 | apalGpio_t moduleGpioChargeStat2A = { |
||
250 | /* port */ GPIOB,
|
||
251 | /* pad */ GPIOB_CHARGE_STAT2A,
|
||
252 | }; |
||
253 | |||
254 | apalGpio_t moduleGpioGaugeBatLow2 = { |
||
255 | /* port */ GPIOB,
|
||
256 | /* pad */ GPIOB_GAUGE_BATLOW2,
|
||
257 | }; |
||
258 | |||
259 | apalGpio_t moduleGpioGaugeBatGd2 = { |
||
260 | /* port */ GPIOB,
|
||
261 | /* pad */ GPIOB_GAUGE_BATGD2_N,
|
||
262 | }; |
||
263 | |||
264 | apalGpio_t moduleGpioLed = { |
||
265 | /* port */ GPIOB,
|
||
266 | /* pad */ GPIOB_LED,
|
||
267 | }; |
||
268 | |||
269 | apalGpio_t moduleGpioSysUartUp = { |
||
270 | /* port */ GPIOB,
|
||
271 | /* pad */ GPIOB_SYS_UART_UP,
|
||
272 | }; |
||
273 | |||
274 | apalGpio_t moduleGpioChargeStat1A = { |
||
275 | /* port */ GPIOC,
|
||
276 | /* pad */ GPIOC_CHARGE_STAT1A,
|
||
277 | }; |
||
278 | |||
279 | apalGpio_t moduleGpioGaugeBatLow1 = { |
||
280 | /* port */ GPIOC,
|
||
281 | /* pad */ GPIOC_GAUGE_BATLOW1,
|
||
282 | }; |
||
283 | |||
284 | apalGpio_t moduleGpioGaugeBatGd1 = { |
||
285 | /* port */ GPIOC,
|
||
286 | /* pad */ GPIOC_GAUGE_BATGD1_N,
|
||
287 | }; |
||
288 | |||
289 | apalGpio_t moduleGpioChargeEn1 = { |
||
290 | /* port */ GPIOC,
|
||
291 | /* pad */ GPIOC_CHARGE_EN1_N,
|
||
292 | }; |
||
293 | |||
294 | apalGpio_t moduleGpioIrInt2 = { |
||
295 | /* port */ GPIOC,
|
||
296 | /* pad */ GPIOC_IR_INT2_N,
|
||
297 | }; |
||
298 | |||
299 | apalGpio_t moduleGpioTouchInt = { |
||
300 | /* port */ GPIOC,
|
||
301 | /* pad */ GPIOC_TOUCH_INT_N,
|
||
302 | }; |
||
303 | |||
304 | apalGpio_t moduleGpioSysDone = { |
||
305 | /* port */ GPIOC,
|
||
306 | /* pad */ GPIOC_SYS_DONE,
|
||
307 | }; |
||
308 | |||
309 | apalGpio_t moduleGpioSysProg = { |
||
310 | /* port */ GPIOC,
|
||
311 | /* pad */ GPIOC_SYS_PROG_N,
|
||
312 | }; |
||
313 | |||
314 | apalGpio_t moduleGpioPathDc = { |
||
315 | /* port */ GPIOC,
|
||
316 | /* pad */ GPIOC_PATH_DC,
|
||
317 | }; |
||
318 | |||
319 | apalGpio_t moduleGpioSysSpiDir = { |
||
320 | /* port */ GPIOC,
|
||
321 | /* pad */ GPIOC_SYS_SPI_DIR,
|
||
322 | }; |
||
323 | |||
324 | apalGpio_t moduleGpioSysSync = { |
||
325 | /* port */ GPIOC,
|
||
326 | /* pad */ GPIOC_SYS_INT_N,
|
||
327 | }; |
||
328 | |||
329 | apalGpio_t moduleGpioSysPd = { |
||
330 | /* port */ GPIOC,
|
||
331 | /* pad */ GPIOC_SYS_PD_N,
|
||
332 | }; |
||
333 | |||
334 | apalGpio_t moduleGpioSysWarmrst = { |
||
335 | /* port */ GPIOC,
|
||
336 | /* pad */ GPIOC_SYS_WARMRST_N,
|
||
337 | }; |
||
338 | |||
339 | apalGpio_t moduleGpioBtRst = { |
||
340 | /* port */ GPIOC,
|
||
341 | /* pad */ GPIOC_BT_RST,
|
||
342 | }; |
||
343 | |||
344 | apalGpio_t moduleGpioChargeEn2 = { |
||
345 | /* port */ GPIOD,
|
||
346 | /* pad */ GPIOD_CHARGE_EN2_N,
|
||
347 | }; |
||
348 | |||
349 | /** @} */
|
||
350 | |||
351 | /*===========================================================================*/
|
||
352 | /**
|
||
353 | * @name AMiRo-OS core configurations
|
||
354 | * @{
|
||
355 | */
|
||
356 | /*===========================================================================*/
|
||
357 | |||
358 | apalControlGpio_t moduleSsspPd = { |
||
359 | /* GPIO */ &moduleGpioSysPd,
|
||
360 | /* meta */ {
|
||
361 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
362 | /* edge */ APAL_GPIO_EDGE_FALLING,
|
||
363 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
364 | }, |
||
365 | }; |
||
366 | |||
367 | apalControlGpio_t moduleSsspSync = { |
||
368 | /* GPIO */ &moduleGpioSysSync,
|
||
369 | /* meta */ {
|
||
370 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
371 | /* edge */ APAL_GPIO_EDGE_FALLING,
|
||
372 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
373 | }, |
||
374 | }; |
||
375 | |||
376 | const char* moduleShellPrompt = "PowerManagement"; |
||
377 | |||
378 | /** @} */
|
||
379 | |||
380 | /*===========================================================================*/
|
||
381 | /**
|
||
382 | * @name Low-level drivers
|
||
383 | * @{
|
||
384 | */
|
||
385 | /*===========================================================================*/
|
||
386 | |||
387 | AT24C01BNDriver moduleLldEeprom = { |
||
388 | /* I2C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
389 | /* I2C address */ AT24C01BN_LLD_I2C_ADDR_FIXED,
|
||
390 | }; |
||
391 | |||
392 | BQ24103ADriver moduleLldBatteryChargerFront = { |
||
393 | /* charge enable GPIO */ {
|
||
394 | /* GPIO */ &moduleGpioChargeEn1,
|
||
395 | /* meta */ {
|
||
396 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
397 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
398 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
399 | }, |
||
400 | }, |
||
401 | /* charge status GPIO */ {
|
||
402 | /* GPIO */ &moduleGpioChargeStat1A,
|
||
403 | /* meta */ {
|
||
404 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
405 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
406 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
407 | }, |
||
408 | }, |
||
409 | }; |
||
410 | |||
411 | BQ24103ADriver moduleLldBatteryChargerRear = { |
||
412 | /* charge enable GPIO */ {
|
||
413 | /* GPIO */ &moduleGpioChargeEn2,
|
||
414 | /* meta */ {
|
||
415 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
416 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
417 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
418 | }, |
||
419 | }, |
||
420 | /* charge status GPIO */ {
|
||
421 | /* GPIO */ &moduleGpioChargeStat2A,
|
||
422 | /* meta */ {
|
||
423 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
424 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
425 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
426 | }, |
||
427 | }, |
||
428 | }; |
||
429 | |||
430 | BQ27500Driver moduleLldFuelGaugeFront = { |
||
431 | /* I2C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
432 | /* battery low GPIO */ {
|
||
433 | /* GPIO */ &moduleGpioGaugeBatLow1,
|
||
434 | /* meta */ {
|
||
435 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
436 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
437 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
438 | }, |
||
439 | }, |
||
440 | /* battery good GPIO */ {
|
||
441 | /* GPIO */ &moduleGpioGaugeBatGd1,
|
||
442 | /* meta */ {
|
||
443 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
444 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
445 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
446 | }, |
||
447 | }, |
||
448 | }; |
||
449 | |||
450 | BQ27500Driver moduleLldFuelGaugeRear = { |
||
451 | /* I2C driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
452 | /* battery low GPIO */ {
|
||
453 | /* GPIO */ &moduleGpioGaugeBatLow2,
|
||
454 | /* meta */ {
|
||
455 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
456 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
457 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
458 | }, |
||
459 | }, |
||
460 | /* battery good GPIO */ {
|
||
461 | /* GPIO */ &moduleGpioGaugeBatGd2,
|
||
462 | /* meta */ {
|
||
463 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
464 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
465 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
466 | }, |
||
467 | }, |
||
468 | }; |
||
469 | |||
470 | INA219Driver moduleLldPowerMonitorVdd = { |
||
471 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
472 | /* I²C address */ INA219_LLD_I2C_ADDR_A0 | INA219_LLD_I2C_ADDR_A1,
|
||
473 | /* current LSB (uA) */ 0x00u, |
||
474 | /* configuration */ NULL, |
||
475 | }; |
||
476 | |||
477 | INA219Driver moduleLldPowerMonitorVio18 = { |
||
478 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
479 | /* I²C address */ INA219_LLD_I2C_ADDR_A1,
|
||
480 | /* current LSB (uA) */ 0x00u, |
||
481 | /* configuration */ NULL, |
||
482 | }; |
||
483 | |||
484 | INA219Driver moduleLldPowerMonitorVio33 = { |
||
485 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
486 | /* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
||
487 | /* current LSB (uA) */ 0x00u, |
||
488 | /* configuration */ NULL, |
||
489 | }; |
||
490 | |||
491 | INA219Driver moduleLldPowerMonitorVsys42 = { |
||
492 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
493 | /* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
||
494 | /* current LSB (uA) */ 0x00u, |
||
495 | /* configuration */ NULL, |
||
496 | }; |
||
497 | |||
498 | INA219Driver moduleLldPowerMonitorVio50 = { |
||
499 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
500 | /* I²C address */ INA219_LLD_I2C_ADDR_A1,
|
||
501 | /* current LSB (uA) */ 0x00u, |
||
502 | /* configuration */ NULL, |
||
503 | }; |
||
504 | |||
505 | LEDDriver moduleLldStatusLed = { |
||
506 | /* LED GPIO */ {
|
||
507 | /* GPIO */ &moduleGpioLed,
|
||
508 | /* meta */ {
|
||
509 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
510 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
511 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
512 | }, |
||
513 | }, |
||
514 | }; |
||
515 | |||
516 | MPR121Driver moduleLldTouch = { |
||
517 | /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
518 | }; |
||
519 | |||
520 | PCA9544ADriver moduleLldI2cMultiplexer1 = { |
||
521 | /* I²C driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
522 | /* I²C address */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
||
523 | }; |
||
524 | |||
525 | PCA9544ADriver moduleLldI2cMultiplexer2 = { |
||
526 | /* I²C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
527 | /* I²C address */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
||
528 | }; |
||
529 | |||
530 | TPS62113Driver moduleLldStepDownConverter = { |
||
531 | /* Power enable GPIO */ {
|
||
532 | /* GPIO */ &moduleGpioPowerEn,
|
||
533 | /* GPIO meta */ {
|
||
534 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
535 | /* egde */ APAL_GPIO_EDGE_NONE,
|
||
536 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
537 | }, |
||
538 | }, |
||
539 | }; |
||
540 | |||
541 | VCNL4020Driver moduleLldProximity1 = { |
||
542 | /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
543 | }; |
||
544 | |||
545 | VCNL4020Driver moduleLldProximity2 = { |
||
546 | /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
547 | }; |
||
548 | |||
549 | /** @} */
|
||
550 | |||
551 | /*===========================================================================*/
|
||
552 | /**
|
||
553 | * @name Unit tests (UT)
|
||
554 | * @{
|
||
555 | */
|
||
556 | /*===========================================================================*/
|
||
557 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
558 | #include <string.h> |
||
559 | |||
560 | /* ADC */
|
||
561 | static int _utShellCmdCb_Adc(BaseSequentialStream* stream, int argc, char* argv[]) |
||
562 | { |
||
563 | (void)argc;
|
||
564 | (void)argv;
|
||
565 | aosUtRun(stream, &moduleUtAdcVsys, NULL);
|
||
566 | return AOS_OK;
|
||
567 | } |
||
568 | static ut_adcdata_t _utAdcVsysData = {
|
||
569 | /* driver */ &MODULE_HAL_ADC_VSYS,
|
||
570 | /* ADC conversion group */ &moduleHalAdcVsysConversionGroup,
|
||
571 | }; |
||
572 | aos_unittest_t moduleUtAdcVsys = { |
||
573 | /* name */ "ADC", |
||
574 | /* info */ "VSYS", |
||
575 | /* test function */ utAdcFunc,
|
||
576 | /* shell command */ {
|
||
577 | /* name */ "unittest:ADC", |
||
578 | /* callback */ _utShellCmdCb_Adc,
|
||
579 | /* next */ NULL, |
||
580 | }, |
||
581 | /* data */ &_utAdcVsysData,
|
||
582 | }; |
||
583 | |||
584 | /* AT24C01BN-SH-B (EEPROM) */
|
||
585 | static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
||
586 | { |
||
587 | (void)argc;
|
||
588 | (void)argv;
|
||
589 | aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
||
590 | return AOS_OK;
|
||
591 | } |
||
592 | static ut_at24c01bndata_t _utAlldAt24c01bnData = {
|
||
593 | /* driver */ &moduleLldEeprom,
|
||
594 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
595 | }; |
||
596 | aos_unittest_t moduleUtAlldAt24c01bn = { |
||
597 | /* name */ "AT24C01BN-SH-B", |
||
598 | /* info */ "1kbit EEPROM", |
||
599 | /* test function */ utAlldAt24c01bnFunc,
|
||
600 | /* shell command */ {
|
||
601 | /* name */ "unittest:EEPROM", |
||
602 | /* callback */ _utShellCmdCb_AlldAt24c01bn,
|
||
603 | /* next */ NULL, |
||
604 | }, |
||
605 | /* data */ &_utAlldAt24c01bnData,
|
||
606 | }; |
||
607 | |||
608 | /* BQ24103A (battery charger) */
|
||
609 | static int _utShellCmdCb_AlldBq24103a(BaseSequentialStream* stream, int argc, char* argv[]) |
||
610 | { |
||
611 | // local variables
|
||
612 | bool print_help = false; |
||
613 | |||
614 | // evaluate argument
|
||
615 | if (argc == 2) { |
||
616 | if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
||
617 | moduleUtAlldBq24103a.data = &moduleLldBatteryChargerFront; |
||
618 | aosUtRun(stream, &moduleUtAlldBq24103a, "front battery");
|
||
619 | moduleUtAlldBq24103a.data = NULL;
|
||
620 | } |
||
621 | else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
||
622 | moduleUtAlldBq24103a.data = &moduleLldBatteryChargerRear; |
||
623 | aosUtRun(stream, &moduleUtAlldBq24103a, "rear battery");
|
||
624 | moduleUtAlldBq24103a.data = NULL;
|
||
625 | } |
||
626 | else {
|
||
627 | print_help = true;
|
||
628 | } |
||
629 | } else {
|
||
630 | print_help = true;
|
||
631 | } |
||
632 | |||
633 | // print help or just return
|
||
634 | if (print_help) {
|
||
635 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
636 | chprintf(stream, "Options:\n");
|
||
637 | chprintf(stream, " --front, -f\n");
|
||
638 | chprintf(stream, " Test the front battery charger.\n");
|
||
639 | chprintf(stream, " --rear, -r\n");
|
||
640 | chprintf(stream, " Test the rear battery charger.\n");
|
||
641 | return AOS_INVALID_ARGUMENTS;
|
||
642 | } else {
|
||
643 | return AOS_OK;
|
||
644 | } |
||
645 | } |
||
646 | aos_unittest_t moduleUtAlldBq24103a = { |
||
647 | /* name */ "BQ24103A", |
||
648 | /* info */ "battery charger", |
||
649 | /* test function */ utAlldBq24103aFunc,
|
||
650 | /* shell command */ {
|
||
651 | /* name */ "unittest:BatteryCharger", |
||
652 | /* callback */ _utShellCmdCb_AlldBq24103a,
|
||
653 | /* next */ NULL, |
||
654 | }, |
||
655 | /* data */ NULL, |
||
656 | }; |
||
657 | |||
658 | /* BQ27500 (fuel gauge) */
|
||
659 | static int _utShellCmdCb_AlldBq27500(BaseSequentialStream* stream, int argc, char* argv[]) |
||
660 | { |
||
661 | // evaluate arguments
|
||
662 | if (argc == 2) { |
||
663 | if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
||
664 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeFront; |
||
665 | aosUtRun(stream, &moduleUtAlldBq27500, "front battery");
|
||
666 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
|
||
667 | return AOS_OK;
|
||
668 | } |
||
669 | else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
||
670 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeRear; |
||
671 | aosUtRun(stream, &moduleUtAlldBq27500, "rear battery");
|
||
672 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
|
||
673 | return AOS_OK;
|
||
674 | } |
||
675 | } |
||
676 | // print help
|
||
677 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
678 | chprintf(stream, "Options:\n");
|
||
679 | chprintf(stream, " --front, -f\n");
|
||
680 | chprintf(stream, " Test the front battery fuel gauge.\n");
|
||
681 | chprintf(stream, " --rear, -r\n");
|
||
682 | chprintf(stream, " Test the rear battery fuel gauge.\n");
|
||
683 | return AOS_INVALID_ARGUMENTS;
|
||
684 | } |
||
685 | static ut_bq27500data_t _utAlldBq27500Data = {
|
||
686 | /* driver */ NULL, |
||
687 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
688 | }; |
||
689 | aos_unittest_t moduleUtAlldBq27500 = { |
||
690 | /* name */ "BQ27500", |
||
691 | /* info */ "fuel gauge", |
||
692 | /* test function */ utAlldBq27500Func,
|
||
693 | /* shell command */ {
|
||
694 | /* name */ "unittest:FuelGauge", |
||
695 | /* callback */ _utShellCmdCb_AlldBq27500,
|
||
696 | /* next */ NULL, |
||
697 | }, |
||
698 | /* data */ &_utAlldBq27500Data,
|
||
699 | }; |
||
700 | |||
701 | /* BQ27500 (fuel gauge) in combination with BQ24103A (battery charger) */
|
||
702 | static int _utShellCmdCb_AlldBq27500Bq24103a(BaseSequentialStream* stream, int argc, char* argv[]) |
||
703 | { |
||
704 | // evaluate arguments
|
||
705 | if (argc == 2) { |
||
706 | if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
||
707 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeFront; |
||
708 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerFront; |
||
709 | aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "front battery");
|
||
710 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
|
||
711 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
|
||
712 | return AOS_OK;
|
||
713 | } |
||
714 | else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
||
715 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeRear; |
||
716 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerRear; |
||
717 | aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "rear battery");
|
||
718 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
|
||
719 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
|
||
720 | return AOS_OK;
|
||
721 | } |
||
722 | } |
||
723 | // print help
|
||
724 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
725 | chprintf(stream, "Options:\n");
|
||
726 | chprintf(stream, " --front, -f\n");
|
||
727 | chprintf(stream, " Test the front battery fuel gauge and charger.\n");
|
||
728 | chprintf(stream, " --rear, -r\n");
|
||
729 | chprintf(stream, " Test the rear battery fuel gauge and charger.\n");
|
||
730 | return AOS_INVALID_ARGUMENTS;
|
||
731 | } |
||
732 | static ut_bq27500bq24103adata_t _utAlldBq27500Bq24103aData= {
|
||
733 | /* BQ27500 driver */ NULL, |
||
734 | /* BQ23203A driver */ NULL, |
||
735 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
736 | }; |
||
737 | aos_unittest_t moduleUtAlldBq27500Bq24103a = { |
||
738 | /* name */ "BQ27500 & BQ24103A", |
||
739 | /* info */ "fuel gauge & battery charger", |
||
740 | /* test function */ utAlldBq27500Bq24103aFunc,
|
||
741 | /* shell command */ {
|
||
742 | /* name */ "unittest:FuelGauge&BatteryCharger", |
||
743 | /* callback */ _utShellCmdCb_AlldBq27500Bq24103a,
|
||
744 | /* next */ NULL, |
||
745 | }, |
||
746 | /* data */ &_utAlldBq27500Bq24103aData,
|
||
747 | }; |
||
748 | |||
749 | /* INA219 (power monitor) */
|
||
750 | static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[]) |
||
751 | { |
||
752 | // evaluate arguments
|
||
753 | if (argc == 2) { |
||
754 | if (strcmp(argv[1], "VDD") == 0) { |
||
755 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVdd; |
||
756 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f; |
||
757 | aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
|
||
758 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
759 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
760 | return AOS_OK;
|
||
761 | } |
||
762 | else if (strcmp(argv[1], "VIO1.8") == 0) { |
||
763 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio18; |
||
764 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 1.8f; |
||
765 | aosUtRun(stream, &moduleUtAlldIna219, "VIO (1.8V)");
|
||
766 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
767 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
768 | return AOS_OK;
|
||
769 | } |
||
770 | else if (strcmp(argv[1], "VIO3.3") == 0) { |
||
771 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio33; |
||
772 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f; |
||
773 | aosUtRun(stream, &moduleUtAlldIna219, "VIO (3.3V)");
|
||
774 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
775 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
776 | return AOS_OK;
|
||
777 | } |
||
778 | else if (strcmp(argv[1], "VSYS4.2") == 0) { |
||
779 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVsys42; |
||
780 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 4.2f; |
||
781 | aosUtRun(stream, &moduleUtAlldIna219, "VSYS (4.2V)");
|
||
782 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
783 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
784 | return AOS_OK;
|
||
785 | } |
||
786 | else if (strcmp(argv[1], "VIO5.0") == 0) { |
||
787 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio50; |
||
788 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 5.0f; |
||
789 | aosUtRun(stream, &moduleUtAlldIna219, "VIO (5.0V)");
|
||
790 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
791 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
792 | return AOS_OK;
|
||
793 | } |
||
794 | } |
||
795 | // print help
|
||
796 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
797 | chprintf(stream, "Options:\n");
|
||
798 | chprintf(stream, " VDD\n");
|
||
799 | chprintf(stream, " Test VDD (3.3V) power monitor.\n");
|
||
800 | chprintf(stream, " VIO1.8\n");
|
||
801 | chprintf(stream, " Test VIO 1.8V power monitor.\n");
|
||
802 | chprintf(stream, " VIO3.3\n");
|
||
803 | chprintf(stream, " Test VIO 3.3V power monitor.\n");
|
||
804 | chprintf(stream, " VSYS4.2\n");
|
||
805 | chprintf(stream, " Test VSYS 4.2V power monitor.\n");
|
||
806 | chprintf(stream, " VIO5.0\n");
|
||
807 | chprintf(stream, " Test VIO 5.0V power monitor.\n");
|
||
808 | return AOS_INVALID_ARGUMENTS;
|
||
809 | } |
||
810 | static ut_ina219data_t _utAlldIna219Data = {
|
||
811 | /* driver */ NULL, |
||
812 | /* expected voltage */ 0.0f, |
||
813 | /* tolerance */ 0.05f, |
||
814 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
815 | }; |
||
816 | aos_unittest_t moduleUtAlldIna219 = { |
||
817 | /* name */ "INA219", |
||
818 | /* info */ "power monitor", |
||
819 | /* test function */ utAlldIna219Func,
|
||
820 | /* shell command */ {
|
||
821 | /* name */ "unittest:PowerMonitor", |
||
822 | /* callback */ _utShellCmdCb_AlldIna219,
|
||
823 | /* next */ NULL, |
||
824 | }, |
||
825 | /* data */ &_utAlldIna219Data,
|
||
826 | }; |
||
827 | |||
828 | /* Status LED */
|
||
829 | static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[]) |
||
830 | { |
||
831 | (void)argc;
|
||
832 | (void)argv;
|
||
833 | aosUtRun(stream, &moduleUtAlldLed, NULL);
|
||
834 | return AOS_OK;
|
||
835 | } |
||
836 | aos_unittest_t moduleUtAlldLed = { |
||
837 | /* name */ "LED", |
||
838 | /* info */ NULL, |
||
839 | /* test function */ utAlldLedFunc,
|
||
840 | /* shell command */ {
|
||
841 | /* name */ "unittest:StatusLED", |
||
842 | /* callback */ _utShellCmdCb_AlldLed,
|
||
843 | /* next */ NULL, |
||
844 | }, |
||
845 | /* data */ &moduleLldStatusLed,
|
||
846 | }; |
||
847 | |||
848 | /* MPR121 (touch sensor) */
|
||
849 | static int _utShellCmdCb_AlldMpr121(BaseSequentialStream* stream, int argc, char* argv[]) |
||
850 | { |
||
851 | (void)argc;
|
||
852 | (void)argv;
|
||
853 | extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_TOUCHINT); |
||
854 | aosUtRun(stream, &moduleUtAlldMpr121, NULL);
|
||
855 | return AOS_OK;
|
||
856 | } |
||
857 | static ut_mpr121data_t _utAlldMpr121Data= {
|
||
858 | /* MPR121 driver */ &moduleLldTouch,
|
||
859 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
860 | /* event source */ &aos.events.io.source,
|
||
861 | /* event flags */ (1 << MODULE_GPIO_EXTCHANNEL_TOUCHINT), |
||
862 | }; |
||
863 | aos_unittest_t moduleUtAlldMpr121 = { |
||
864 | /* name */ "MPR121", |
||
865 | /* info */ "touch sensor", |
||
866 | /* test function */ utAlldMpr121Func,
|
||
867 | /* shell command */ {
|
||
868 | /* name */ "unittest:Touch", |
||
869 | /* callback */ _utShellCmdCb_AlldMpr121,
|
||
870 | /* next */ NULL, |
||
871 | }, |
||
872 | /* data */ &_utAlldMpr121Data,
|
||
873 | }; |
||
874 | |||
875 | /* PCA9544A (I2C multiplexer) */
|
||
876 | static int _utShellCmdCb_AlldPca5944a(BaseSequentialStream* stream, int argc, char* argv[]) |
||
877 | { |
||
878 | // evaluate arguments
|
||
879 | if (argc == 2) { |
||
880 | if (strcmp(argv[1], "#1") == 0) { |
||
881 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer1; |
||
882 | aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #1");
|
||
883 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
|
||
884 | return AOS_OK;
|
||
885 | } |
||
886 | else if (strcmp(argv[1], "#2") == 0) { |
||
887 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer2; |
||
888 | aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #2");
|
||
889 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
|
||
890 | return AOS_OK;
|
||
891 | } |
||
892 | } |
||
893 | // print help
|
||
894 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
895 | chprintf(stream, "Options:\n");
|
||
896 | chprintf(stream, " #1\n");
|
||
897 | chprintf(stream, " Test the multiplexer on the I2C bus #1.\n");
|
||
898 | chprintf(stream, " #2\n");
|
||
899 | chprintf(stream, " Test the multiplexer on the I2C bus #2.\n");
|
||
900 | return AOS_INVALID_ARGUMENTS;
|
||
901 | } |
||
902 | static ut_pca9544adata_t _utAlldPca9544aData = {
|
||
903 | /* driver */ NULL, |
||
904 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
905 | }; |
||
906 | aos_unittest_t moduleUtAlldPca9544a = { |
||
907 | /* name */ "PCA9544A", |
||
908 | /* info */ "I2C multiplexer", |
||
909 | /* test function */ utAlldPca9544aFunc,
|
||
910 | /* shell command */ {
|
||
911 | /* name */ "unittest:I2CMultiplexer", |
||
912 | /* callback */ _utShellCmdCb_AlldPca5944a,
|
||
913 | /* next */ NULL, |
||
914 | }, |
||
915 | /* data */ &_utAlldPca9544aData,
|
||
916 | }; |
||
917 | |||
918 | /* PKLCS1212E4001 (buzzer) */
|
||
919 | static int _utShellCmdCb_AlldPklcs1212e4001(BaseSequentialStream* stream, int argc, char* argv[]) |
||
920 | { |
||
921 | (void)argc;
|
||
922 | (void)argv;
|
||
923 | aosUtRun(stream, &moduleUtAlldPklcs1212e4001, NULL);
|
||
924 | return AOS_OK;
|
||
925 | } |
||
926 | static ut_pklcs1212e4001_t _utAlldPklcs1212e4001Data = {
|
||
927 | /* PWM driver */ &MODULE_HAL_PWM_BUZZER,
|
||
928 | /* PWM channel */ MODULE_HAL_PWM_BUZZER_CHANNEL
|
||
929 | }; |
||
930 | aos_unittest_t moduleUtAlldPklcs1212e4001 = { |
||
931 | /* name */ "PKLCS1212E4001", |
||
932 | /* info */ "buzzer", |
||
933 | /* test function */ utAlldPklcs1212e4001Func,
|
||
934 | /* shell command */ {
|
||
935 | /* name */ "unittest:Buzzer", |
||
936 | /* callback */ _utShellCmdCb_AlldPklcs1212e4001,
|
||
937 | /* next */ NULL, |
||
938 | }, |
||
939 | /* data */ &_utAlldPklcs1212e4001Data,
|
||
940 | }; |
||
941 | |||
942 | /* TPS62113 (stop-down converter) */
|
||
943 | static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[]) |
||
944 | { |
||
945 | // Although there are four TPS62113 on the PCB, they all share the same input signal.
|
||
946 | // A sa result, no additional shell arguments need to be evaluated.
|
||
947 | (void)argc;
|
||
948 | (void)argv;
|
||
949 | aosUtRun(stream, &moduleUtAlldTps62113, NULL);
|
||
950 | return AOS_OK;
|
||
951 | } |
||
952 | aos_unittest_t moduleUtAlldTps62113 = { |
||
953 | /* name */ "TPS62113", |
||
954 | /* info */ "step-down converter", |
||
955 | /* test function */ utAlldTps62113Func,
|
||
956 | /* shell command */ {
|
||
957 | /* name */ "unittest:StepDownConverter", |
||
958 | /* callback */ _utShellCmdCb_AlldTps62113,
|
||
959 | /* next */ NULL, |
||
960 | }, |
||
961 | /* data */ &moduleLldStepDownConverter,
|
||
962 | }; |
||
963 | |||
964 | /* TPS62113 (step-donw converter) in combination with INA219 (power monitor) */
|
||
965 | static int _utShellCmdCb_AlldTps62113Ina219(BaseSequentialStream* stream, int argc, char* argv[]) |
||
966 | { |
||
967 | (void)argc;
|
||
968 | (void)argv;
|
||
969 | aosUtRun(stream, &moduleUtAlldTps62113Ina219, "VSYS (4.2V)");
|
||
970 | return AOS_OK;
|
||
971 | } |
||
972 | ut_tps62113ina219data_t _utAlldTps62113Ina219Data = { |
||
973 | /* TPS62113 */ &moduleLldStepDownConverter,
|
||
974 | /* INA219 */ &moduleLldPowerMonitorVsys42,
|
||
975 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
976 | }; |
||
977 | aos_unittest_t moduleUtAlldTps62113Ina219 = { |
||
978 | /* name */ "TPS62113 & INA219", |
||
979 | /* info */ "step-down converter & power monitor", |
||
980 | /* test function */ utAlldTps62113Ina219Func,
|
||
981 | /* shell command */ {
|
||
982 | /* name */ "unittest:StepDownConverter&PowerMonitor", |
||
983 | /* callback */ _utShellCmdCb_AlldTps62113Ina219,
|
||
984 | /* next */ NULL, |
||
985 | }, |
||
986 | /* data */ &_utAlldTps62113Ina219Data,
|
||
987 | }; |
||
988 | |||
989 | /* VCNL4020 (proximity sensor) */
|
||
990 | static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl) |
||
991 | { |
||
992 | uint8_t intstatus; |
||
993 | vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
|
||
994 | vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
995 | if (intstatus) {
|
||
996 | vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
997 | } |
||
998 | return;
|
||
999 | } |
||
1000 | static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[]) |
||
1001 | { |
||
1002 | enum {
|
||
1003 | UNKNOWN, |
||
1004 | NNE, ENE, ESE, SSE, SSW,WSW,WNW, NNW, |
||
1005 | } sensor = UNKNOWN; |
||
1006 | // evaluate arguments
|
||
1007 | if (argc == 2) { |
||
1008 | if (strcmp(argv[1], "-nne") == 0) { |
||
1009 | sensor = NNE; |
||
1010 | } else if (strcmp(argv[1], "-ene") == 0) { |
||
1011 | sensor = ENE; |
||
1012 | } else if (strcmp(argv[1], "-ese") == 0) { |
||
1013 | sensor = ESE; |
||
1014 | } else if (strcmp(argv[1], "-sse") == 0) { |
||
1015 | sensor = SSE; |
||
1016 | } else if (strcmp(argv[1], "-ssw") == 0) { |
||
1017 | sensor = SSW; |
||
1018 | } else if (strcmp(argv[1], "-wsw") == 0) { |
||
1019 | sensor = WSW; |
||
1020 | } else if (strcmp(argv[1], "-wnw") == 0) { |
||
1021 | sensor = WNW; |
||
1022 | } else if (strcmp(argv[1], "-nnw") == 0) { |
||
1023 | sensor = NNW; |
||
1024 | } |
||
1025 | } |
||
1026 | if (sensor != UNKNOWN) {
|
||
1027 | PCA9544ADriver* mux = NULL;
|
||
1028 | switch (sensor) {
|
||
1029 | case SSE:
|
||
1030 | case SSW:
|
||
1031 | case WSW:
|
||
1032 | case WNW:
|
||
1033 | mux = &moduleLldI2cMultiplexer1; |
||
1034 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity1; |
||
1035 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = (1 << MODULE_GPIO_EXTCHANNEL_IRINT2);
|
||
1036 | extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT2); |
||
1037 | break;
|
||
1038 | case NNW:
|
||
1039 | case NNE:
|
||
1040 | case ENE:
|
||
1041 | case ESE:
|
||
1042 | mux = &moduleLldI2cMultiplexer2; |
||
1043 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity2; |
||
1044 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = (1 << MODULE_GPIO_EXTCHANNEL_IRINT1);
|
||
1045 | extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT1); |
||
1046 | break;
|
||
1047 | default:
|
||
1048 | break;
|
||
1049 | } |
||
1050 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1051 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1052 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1053 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1054 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1055 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1056 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1057 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1058 | switch (sensor) {
|
||
1059 | case NNE:
|
||
1060 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1061 | aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northeast sensor");
|
||
1062 | break;
|
||
1063 | case ENE:
|
||
1064 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1065 | aosUtRun(stream, &moduleUtAlldVcnl4020, "east-northeast sensor");
|
||
1066 | break;
|
||
1067 | case ESE:
|
||
1068 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1069 | aosUtRun(stream, &moduleUtAlldVcnl4020, "north-southeast sensor");
|
||
1070 | break;
|
||
1071 | case SSE:
|
||
1072 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1073 | aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southeast sensor");
|
||
1074 | break;
|
||
1075 | case SSW:
|
||
1076 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1077 | aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southwest sensor");
|
||
1078 | break;
|
||
1079 | case WSW:
|
||
1080 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1081 | aosUtRun(stream, &moduleUtAlldVcnl4020, "west-southwest sensor");
|
||
1082 | break;
|
||
1083 | case WNW:
|
||
1084 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1085 | aosUtRun(stream, &moduleUtAlldVcnl4020, "west-northwest sensor");
|
||
1086 | break;
|
||
1087 | case NNW:
|
||
1088 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1089 | aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northwest sensor");
|
||
1090 | break;
|
||
1091 | default:
|
||
1092 | break;
|
||
1093 | } |
||
1094 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = NULL;
|
||
1095 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = 0;
|
||
1096 | return AOS_OK;
|
||
1097 | } |
||
1098 | // print help
|
||
1099 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
1100 | chprintf(stream, "Options:\n");
|
||
1101 | chprintf(stream, " -nne\n");
|
||
1102 | chprintf(stream, " Test north-northeast sensor.\n");
|
||
1103 | chprintf(stream, " -ene\n");
|
||
1104 | chprintf(stream, " Test east-northeast sensor.\n");
|
||
1105 | chprintf(stream, " -ese\n");
|
||
1106 | chprintf(stream, " Test east-southeast sensor.\n");
|
||
1107 | chprintf(stream, " -sse\n");
|
||
1108 | chprintf(stream, " Test south-southeast sensor.\n");
|
||
1109 | chprintf(stream, " -ssw\n");
|
||
1110 | chprintf(stream, " Test south-southwest sensor.\n");
|
||
1111 | chprintf(stream, " -wsw\n");
|
||
1112 | chprintf(stream, " Test west-southwest sensor.\n");
|
||
1113 | chprintf(stream, " -wnw\n");
|
||
1114 | chprintf(stream, " Test west-northwest sensor.\n");
|
||
1115 | chprintf(stream, " -nnw\n");
|
||
1116 | chprintf(stream, " Test north-northwest sensor.\n");
|
||
1117 | return AOS_INVALID_ARGUMENTS;
|
||
1118 | } |
||
1119 | static ut_vcnl4020data_t _utAlldVcnl4020Data = {
|
||
1120 | /* driver */ NULL, |
||
1121 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
1122 | /* event source */ &aos.events.io.source,
|
||
1123 | /* event flags */ 0, |
||
1124 | }; |
||
1125 | aos_unittest_t moduleUtAlldVcnl4020 = { |
||
1126 | /* name */ "VCNL4020", |
||
1127 | /* info */ "proximity sensor", |
||
1128 | /* test function */ utAlldVcnl4020Func,
|
||
1129 | /* shell command */ {
|
||
1130 | /* name */ "unittest:Proximity", |
||
1131 | /* callback */ _utShellCmdCb_AlldVcnl4020,
|
||
1132 | /* next */ NULL, |
||
1133 | }, |
||
1134 | /* data */ &_utAlldVcnl4020Data,
|
||
1135 | }; |
||
1136 | |||
1137 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
1138 | |||
1139 | /** @} */ |