amiro-os / modules / PowerManagement_1-1 / module.c @ 75d6970a
History | View | Annotate | Download (37.593 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 | 6b53f6bf | Thomas Schöpping | chEvtBroadcastFlagsI(&aos.events.io, (1 << channel));
|
40 | e545e620 | Thomas Schöpping | 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 | 6b53f6bf | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
359 | const char* moduleShellPrompt = "PowerManagement"; |
||
360 | #endif
|
||
361 | |||
362 | /** @} */
|
||
363 | |||
364 | /*===========================================================================*/
|
||
365 | /**
|
||
366 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
367 | * @{
|
||
368 | */
|
||
369 | /*===========================================================================*/
|
||
370 | |||
371 | apalControlGpio_t moduleSsspGpioPd = { |
||
372 | e545e620 | Thomas Schöpping | /* GPIO */ &moduleGpioSysPd,
|
373 | /* meta */ {
|
||
374 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
375 | /* edge */ APAL_GPIO_EDGE_FALLING,
|
||
376 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
377 | }, |
||
378 | }; |
||
379 | |||
380 | 6b53f6bf | Thomas Schöpping | apalControlGpio_t moduleSsspGpioSync = { |
381 | e545e620 | Thomas Schöpping | /* GPIO */ &moduleGpioSysSync,
|
382 | /* meta */ {
|
||
383 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
384 | /* edge */ APAL_GPIO_EDGE_FALLING,
|
||
385 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
386 | }, |
||
387 | }; |
||
388 | |||
389 | /** @} */
|
||
390 | |||
391 | /*===========================================================================*/
|
||
392 | /**
|
||
393 | * @name Low-level drivers
|
||
394 | * @{
|
||
395 | */
|
||
396 | /*===========================================================================*/
|
||
397 | |||
398 | AT24C01BNDriver moduleLldEeprom = { |
||
399 | /* I2C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
400 | /* I2C address */ AT24C01BN_LLD_I2C_ADDR_FIXED,
|
||
401 | }; |
||
402 | |||
403 | BQ24103ADriver moduleLldBatteryChargerFront = { |
||
404 | /* charge enable GPIO */ {
|
||
405 | /* GPIO */ &moduleGpioChargeEn1,
|
||
406 | /* meta */ {
|
||
407 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
408 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
409 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
410 | }, |
||
411 | }, |
||
412 | /* charge status GPIO */ {
|
||
413 | /* GPIO */ &moduleGpioChargeStat1A,
|
||
414 | /* meta */ {
|
||
415 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
416 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
417 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
418 | }, |
||
419 | }, |
||
420 | }; |
||
421 | |||
422 | BQ24103ADriver moduleLldBatteryChargerRear = { |
||
423 | /* charge enable GPIO */ {
|
||
424 | /* GPIO */ &moduleGpioChargeEn2,
|
||
425 | /* meta */ {
|
||
426 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
427 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
428 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
429 | }, |
||
430 | }, |
||
431 | /* charge status GPIO */ {
|
||
432 | /* GPIO */ &moduleGpioChargeStat2A,
|
||
433 | /* meta */ {
|
||
434 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
435 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
436 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
437 | }, |
||
438 | }, |
||
439 | }; |
||
440 | |||
441 | BQ27500Driver moduleLldFuelGaugeFront = { |
||
442 | /* I2C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
443 | /* battery low GPIO */ {
|
||
444 | /* GPIO */ &moduleGpioGaugeBatLow1,
|
||
445 | /* meta */ {
|
||
446 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
447 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
448 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
449 | }, |
||
450 | }, |
||
451 | /* battery good GPIO */ {
|
||
452 | /* GPIO */ &moduleGpioGaugeBatGd1,
|
||
453 | /* meta */ {
|
||
454 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
455 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
456 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
457 | }, |
||
458 | }, |
||
459 | }; |
||
460 | |||
461 | BQ27500Driver moduleLldFuelGaugeRear = { |
||
462 | /* I2C driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
463 | /* battery low GPIO */ {
|
||
464 | /* GPIO */ &moduleGpioGaugeBatLow2,
|
||
465 | /* meta */ {
|
||
466 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
467 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
468 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
469 | }, |
||
470 | }, |
||
471 | /* battery good GPIO */ {
|
||
472 | /* GPIO */ &moduleGpioGaugeBatGd2,
|
||
473 | /* meta */ {
|
||
474 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
475 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
476 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
477 | }, |
||
478 | }, |
||
479 | }; |
||
480 | |||
481 | INA219Driver moduleLldPowerMonitorVdd = { |
||
482 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
483 | /* I²C address */ INA219_LLD_I2C_ADDR_A0 | INA219_LLD_I2C_ADDR_A1,
|
||
484 | /* current LSB (uA) */ 0x00u, |
||
485 | /* configuration */ NULL, |
||
486 | }; |
||
487 | |||
488 | INA219Driver moduleLldPowerMonitorVio18 = { |
||
489 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
490 | /* I²C address */ INA219_LLD_I2C_ADDR_A1,
|
||
491 | /* current LSB (uA) */ 0x00u, |
||
492 | /* configuration */ NULL, |
||
493 | }; |
||
494 | |||
495 | INA219Driver moduleLldPowerMonitorVio33 = { |
||
496 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
497 | /* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
||
498 | /* current LSB (uA) */ 0x00u, |
||
499 | /* configuration */ NULL, |
||
500 | }; |
||
501 | |||
502 | INA219Driver moduleLldPowerMonitorVsys42 = { |
||
503 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
504 | /* I²C address */ INA219_LLD_I2C_ADDR_FIXED,
|
||
505 | /* current LSB (uA) */ 0x00u, |
||
506 | /* configuration */ NULL, |
||
507 | }; |
||
508 | |||
509 | INA219Driver moduleLldPowerMonitorVio50 = { |
||
510 | /* I2C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
511 | /* I²C address */ INA219_LLD_I2C_ADDR_A1,
|
||
512 | /* current LSB (uA) */ 0x00u, |
||
513 | /* configuration */ NULL, |
||
514 | }; |
||
515 | |||
516 | LEDDriver moduleLldStatusLed = { |
||
517 | /* LED GPIO */ {
|
||
518 | /* GPIO */ &moduleGpioLed,
|
||
519 | /* meta */ {
|
||
520 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
521 | /* edge */ APAL_GPIO_EDGE_NONE,
|
||
522 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
523 | }, |
||
524 | }, |
||
525 | }; |
||
526 | |||
527 | MPR121Driver moduleLldTouch = { |
||
528 | /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
529 | }; |
||
530 | |||
531 | PCA9544ADriver moduleLldI2cMultiplexer1 = { |
||
532 | /* I²C driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
533 | /* I²C address */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
||
534 | }; |
||
535 | |||
536 | PCA9544ADriver moduleLldI2cMultiplexer2 = { |
||
537 | /* I²C driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
538 | /* I²C address */ PCA9544A_LLD_I2C_ADDR_A0 | PCA9544A_LLD_I2C_ADDR_A1 | PCA9544A_LLD_I2C_ADDR_A2,
|
||
539 | }; |
||
540 | |||
541 | TPS62113Driver moduleLldStepDownConverter = { |
||
542 | /* Power enable GPIO */ {
|
||
543 | /* GPIO */ &moduleGpioPowerEn,
|
||
544 | /* GPIO meta */ {
|
||
545 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
546 | /* egde */ APAL_GPIO_EDGE_NONE,
|
||
547 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
548 | }, |
||
549 | }, |
||
550 | }; |
||
551 | |||
552 | VCNL4020Driver moduleLldProximity1 = { |
||
553 | /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM18_PM33_GAUGEREAR,
|
||
554 | }; |
||
555 | |||
556 | VCNL4020Driver moduleLldProximity2 = { |
||
557 | /* I²C Driver */ &MODULE_HAL_I2C_PROX_PM42_PM50_PMVDD_EEPROM_TOUCH_GAUGEFRONT,
|
||
558 | }; |
||
559 | |||
560 | /** @} */
|
||
561 | |||
562 | /*===========================================================================*/
|
||
563 | /**
|
||
564 | * @name Unit tests (UT)
|
||
565 | * @{
|
||
566 | */
|
||
567 | /*===========================================================================*/
|
||
568 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
569 | #include <string.h> |
||
570 | |||
571 | /* ADC */
|
||
572 | static int _utShellCmdCb_Adc(BaseSequentialStream* stream, int argc, char* argv[]) |
||
573 | { |
||
574 | (void)argc;
|
||
575 | (void)argv;
|
||
576 | aosUtRun(stream, &moduleUtAdcVsys, NULL);
|
||
577 | return AOS_OK;
|
||
578 | } |
||
579 | static ut_adcdata_t _utAdcVsysData = {
|
||
580 | /* driver */ &MODULE_HAL_ADC_VSYS,
|
||
581 | /* ADC conversion group */ &moduleHalAdcVsysConversionGroup,
|
||
582 | }; |
||
583 | aos_unittest_t moduleUtAdcVsys = { |
||
584 | /* name */ "ADC", |
||
585 | /* info */ "VSYS", |
||
586 | /* test function */ utAdcFunc,
|
||
587 | /* shell command */ {
|
||
588 | /* name */ "unittest:ADC", |
||
589 | /* callback */ _utShellCmdCb_Adc,
|
||
590 | /* next */ NULL, |
||
591 | }, |
||
592 | /* data */ &_utAdcVsysData,
|
||
593 | }; |
||
594 | |||
595 | /* AT24C01BN-SH-B (EEPROM) */
|
||
596 | static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
||
597 | { |
||
598 | (void)argc;
|
||
599 | (void)argv;
|
||
600 | aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
||
601 | return AOS_OK;
|
||
602 | } |
||
603 | static ut_at24c01bndata_t _utAlldAt24c01bnData = {
|
||
604 | /* driver */ &moduleLldEeprom,
|
||
605 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
606 | }; |
||
607 | aos_unittest_t moduleUtAlldAt24c01bn = { |
||
608 | /* name */ "AT24C01BN-SH-B", |
||
609 | /* info */ "1kbit EEPROM", |
||
610 | /* test function */ utAlldAt24c01bnFunc,
|
||
611 | /* shell command */ {
|
||
612 | /* name */ "unittest:EEPROM", |
||
613 | /* callback */ _utShellCmdCb_AlldAt24c01bn,
|
||
614 | /* next */ NULL, |
||
615 | }, |
||
616 | /* data */ &_utAlldAt24c01bnData,
|
||
617 | }; |
||
618 | |||
619 | /* BQ24103A (battery charger) */
|
||
620 | static int _utShellCmdCb_AlldBq24103a(BaseSequentialStream* stream, int argc, char* argv[]) |
||
621 | { |
||
622 | // local variables
|
||
623 | bool print_help = false; |
||
624 | |||
625 | // evaluate argument
|
||
626 | if (argc == 2) { |
||
627 | if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
||
628 | moduleUtAlldBq24103a.data = &moduleLldBatteryChargerFront; |
||
629 | aosUtRun(stream, &moduleUtAlldBq24103a, "front battery");
|
||
630 | moduleUtAlldBq24103a.data = NULL;
|
||
631 | } |
||
632 | else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
||
633 | moduleUtAlldBq24103a.data = &moduleLldBatteryChargerRear; |
||
634 | aosUtRun(stream, &moduleUtAlldBq24103a, "rear battery");
|
||
635 | moduleUtAlldBq24103a.data = NULL;
|
||
636 | } |
||
637 | else {
|
||
638 | print_help = true;
|
||
639 | } |
||
640 | } else {
|
||
641 | print_help = true;
|
||
642 | } |
||
643 | |||
644 | // print help or just return
|
||
645 | if (print_help) {
|
||
646 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
647 | chprintf(stream, "Options:\n");
|
||
648 | chprintf(stream, " --front, -f\n");
|
||
649 | chprintf(stream, " Test the front battery charger.\n");
|
||
650 | chprintf(stream, " --rear, -r\n");
|
||
651 | chprintf(stream, " Test the rear battery charger.\n");
|
||
652 | return AOS_INVALID_ARGUMENTS;
|
||
653 | } else {
|
||
654 | return AOS_OK;
|
||
655 | } |
||
656 | } |
||
657 | aos_unittest_t moduleUtAlldBq24103a = { |
||
658 | /* name */ "BQ24103A", |
||
659 | /* info */ "battery charger", |
||
660 | /* test function */ utAlldBq24103aFunc,
|
||
661 | /* shell command */ {
|
||
662 | /* name */ "unittest:BatteryCharger", |
||
663 | /* callback */ _utShellCmdCb_AlldBq24103a,
|
||
664 | /* next */ NULL, |
||
665 | }, |
||
666 | /* data */ NULL, |
||
667 | }; |
||
668 | |||
669 | /* BQ27500 (fuel gauge) */
|
||
670 | static int _utShellCmdCb_AlldBq27500(BaseSequentialStream* stream, int argc, char* argv[]) |
||
671 | { |
||
672 | // evaluate arguments
|
||
673 | if (argc == 2) { |
||
674 | if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
||
675 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeFront; |
||
676 | aosUtRun(stream, &moduleUtAlldBq27500, "front battery");
|
||
677 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
|
||
678 | return AOS_OK;
|
||
679 | } |
||
680 | else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
||
681 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = &moduleLldFuelGaugeRear; |
||
682 | aosUtRun(stream, &moduleUtAlldBq27500, "rear battery");
|
||
683 | ((ut_bq27500data_t*)moduleUtAlldBq27500.data)->driver = NULL;
|
||
684 | return AOS_OK;
|
||
685 | } |
||
686 | } |
||
687 | // print help
|
||
688 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
689 | chprintf(stream, "Options:\n");
|
||
690 | chprintf(stream, " --front, -f\n");
|
||
691 | chprintf(stream, " Test the front battery fuel gauge.\n");
|
||
692 | chprintf(stream, " --rear, -r\n");
|
||
693 | chprintf(stream, " Test the rear battery fuel gauge.\n");
|
||
694 | return AOS_INVALID_ARGUMENTS;
|
||
695 | } |
||
696 | static ut_bq27500data_t _utAlldBq27500Data = {
|
||
697 | /* driver */ NULL, |
||
698 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
699 | }; |
||
700 | aos_unittest_t moduleUtAlldBq27500 = { |
||
701 | /* name */ "BQ27500", |
||
702 | /* info */ "fuel gauge", |
||
703 | /* test function */ utAlldBq27500Func,
|
||
704 | /* shell command */ {
|
||
705 | /* name */ "unittest:FuelGauge", |
||
706 | /* callback */ _utShellCmdCb_AlldBq27500,
|
||
707 | /* next */ NULL, |
||
708 | }, |
||
709 | /* data */ &_utAlldBq27500Data,
|
||
710 | }; |
||
711 | |||
712 | /* BQ27500 (fuel gauge) in combination with BQ24103A (battery charger) */
|
||
713 | static int _utShellCmdCb_AlldBq27500Bq24103a(BaseSequentialStream* stream, int argc, char* argv[]) |
||
714 | { |
||
715 | // evaluate arguments
|
||
716 | if (argc == 2) { |
||
717 | if (strcmp(argv[1], "-f") == 0 || strcmp(argv[1], "--front") == 0) { |
||
718 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeFront; |
||
719 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerFront; |
||
720 | aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "front battery");
|
||
721 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
|
||
722 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
|
||
723 | return AOS_OK;
|
||
724 | } |
||
725 | else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--rear") == 0) { |
||
726 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = &moduleLldFuelGaugeRear; |
||
727 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = &moduleLldBatteryChargerRear; |
||
728 | aosUtRun(stream, &moduleUtAlldBq27500Bq24103a, "rear battery");
|
||
729 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq27500 = NULL;
|
||
730 | ((ut_bq27500bq24103adata_t*)moduleUtAlldBq27500Bq24103a.data)->bq24103a = NULL;
|
||
731 | return AOS_OK;
|
||
732 | } |
||
733 | } |
||
734 | // print help
|
||
735 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
736 | chprintf(stream, "Options:\n");
|
||
737 | chprintf(stream, " --front, -f\n");
|
||
738 | chprintf(stream, " Test the front battery fuel gauge and charger.\n");
|
||
739 | chprintf(stream, " --rear, -r\n");
|
||
740 | chprintf(stream, " Test the rear battery fuel gauge and charger.\n");
|
||
741 | return AOS_INVALID_ARGUMENTS;
|
||
742 | } |
||
743 | static ut_bq27500bq24103adata_t _utAlldBq27500Bq24103aData= {
|
||
744 | /* BQ27500 driver */ NULL, |
||
745 | /* BQ23203A driver */ NULL, |
||
746 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
747 | }; |
||
748 | aos_unittest_t moduleUtAlldBq27500Bq24103a = { |
||
749 | /* name */ "BQ27500 & BQ24103A", |
||
750 | /* info */ "fuel gauge & battery charger", |
||
751 | /* test function */ utAlldBq27500Bq24103aFunc,
|
||
752 | /* shell command */ {
|
||
753 | /* name */ "unittest:FuelGauge&BatteryCharger", |
||
754 | /* callback */ _utShellCmdCb_AlldBq27500Bq24103a,
|
||
755 | /* next */ NULL, |
||
756 | }, |
||
757 | /* data */ &_utAlldBq27500Bq24103aData,
|
||
758 | }; |
||
759 | |||
760 | /* INA219 (power monitor) */
|
||
761 | static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[]) |
||
762 | { |
||
763 | // evaluate arguments
|
||
764 | if (argc == 2) { |
||
765 | if (strcmp(argv[1], "VDD") == 0) { |
||
766 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVdd; |
||
767 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f; |
||
768 | aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
|
||
769 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
770 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
771 | return AOS_OK;
|
||
772 | } |
||
773 | else if (strcmp(argv[1], "VIO1.8") == 0) { |
||
774 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio18; |
||
775 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 1.8f; |
||
776 | aosUtRun(stream, &moduleUtAlldIna219, "VIO (1.8V)");
|
||
777 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
778 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
779 | return AOS_OK;
|
||
780 | } |
||
781 | else if (strcmp(argv[1], "VIO3.3") == 0) { |
||
782 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio33; |
||
783 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 3.3f; |
||
784 | aosUtRun(stream, &moduleUtAlldIna219, "VIO (3.3V)");
|
||
785 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
786 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
787 | return AOS_OK;
|
||
788 | } |
||
789 | else if (strcmp(argv[1], "VSYS4.2") == 0) { |
||
790 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVsys42; |
||
791 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 4.2f; |
||
792 | aosUtRun(stream, &moduleUtAlldIna219, "VSYS (4.2V)");
|
||
793 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
794 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
795 | return AOS_OK;
|
||
796 | } |
||
797 | else if (strcmp(argv[1], "VIO5.0") == 0) { |
||
798 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = &moduleLldPowerMonitorVio50; |
||
799 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 5.0f; |
||
800 | aosUtRun(stream, &moduleUtAlldIna219, "VIO (5.0V)");
|
||
801 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->inad = NULL;
|
||
802 | ((ut_ina219data_t*)moduleUtAlldIna219.data)->v_expected = 0.0f; |
||
803 | return AOS_OK;
|
||
804 | } |
||
805 | } |
||
806 | // print help
|
||
807 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
808 | chprintf(stream, "Options:\n");
|
||
809 | chprintf(stream, " VDD\n");
|
||
810 | chprintf(stream, " Test VDD (3.3V) power monitor.\n");
|
||
811 | chprintf(stream, " VIO1.8\n");
|
||
812 | chprintf(stream, " Test VIO 1.8V power monitor.\n");
|
||
813 | chprintf(stream, " VIO3.3\n");
|
||
814 | chprintf(stream, " Test VIO 3.3V power monitor.\n");
|
||
815 | chprintf(stream, " VSYS4.2\n");
|
||
816 | chprintf(stream, " Test VSYS 4.2V power monitor.\n");
|
||
817 | chprintf(stream, " VIO5.0\n");
|
||
818 | chprintf(stream, " Test VIO 5.0V power monitor.\n");
|
||
819 | return AOS_INVALID_ARGUMENTS;
|
||
820 | } |
||
821 | static ut_ina219data_t _utAlldIna219Data = {
|
||
822 | /* driver */ NULL, |
||
823 | /* expected voltage */ 0.0f, |
||
824 | /* tolerance */ 0.05f, |
||
825 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
826 | }; |
||
827 | aos_unittest_t moduleUtAlldIna219 = { |
||
828 | /* name */ "INA219", |
||
829 | /* info */ "power monitor", |
||
830 | /* test function */ utAlldIna219Func,
|
||
831 | /* shell command */ {
|
||
832 | /* name */ "unittest:PowerMonitor", |
||
833 | /* callback */ _utShellCmdCb_AlldIna219,
|
||
834 | /* next */ NULL, |
||
835 | }, |
||
836 | /* data */ &_utAlldIna219Data,
|
||
837 | }; |
||
838 | |||
839 | /* Status LED */
|
||
840 | static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[]) |
||
841 | { |
||
842 | (void)argc;
|
||
843 | (void)argv;
|
||
844 | aosUtRun(stream, &moduleUtAlldLed, NULL);
|
||
845 | return AOS_OK;
|
||
846 | } |
||
847 | aos_unittest_t moduleUtAlldLed = { |
||
848 | /* name */ "LED", |
||
849 | /* info */ NULL, |
||
850 | /* test function */ utAlldLedFunc,
|
||
851 | /* shell command */ {
|
||
852 | /* name */ "unittest:StatusLED", |
||
853 | /* callback */ _utShellCmdCb_AlldLed,
|
||
854 | /* next */ NULL, |
||
855 | }, |
||
856 | /* data */ &moduleLldStatusLed,
|
||
857 | }; |
||
858 | |||
859 | /* MPR121 (touch sensor) */
|
||
860 | static int _utShellCmdCb_AlldMpr121(BaseSequentialStream* stream, int argc, char* argv[]) |
||
861 | { |
||
862 | (void)argc;
|
||
863 | (void)argv;
|
||
864 | extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_TOUCHINT); |
||
865 | aosUtRun(stream, &moduleUtAlldMpr121, NULL);
|
||
866 | return AOS_OK;
|
||
867 | } |
||
868 | static ut_mpr121data_t _utAlldMpr121Data= {
|
||
869 | /* MPR121 driver */ &moduleLldTouch,
|
||
870 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
871 | 6b53f6bf | Thomas Schöpping | /* event source */ &aos.events.io,
|
872 | e545e620 | Thomas Schöpping | /* event flags */ (1 << MODULE_GPIO_EXTCHANNEL_TOUCHINT), |
873 | }; |
||
874 | aos_unittest_t moduleUtAlldMpr121 = { |
||
875 | /* name */ "MPR121", |
||
876 | /* info */ "touch sensor", |
||
877 | /* test function */ utAlldMpr121Func,
|
||
878 | /* shell command */ {
|
||
879 | /* name */ "unittest:Touch", |
||
880 | /* callback */ _utShellCmdCb_AlldMpr121,
|
||
881 | /* next */ NULL, |
||
882 | }, |
||
883 | /* data */ &_utAlldMpr121Data,
|
||
884 | }; |
||
885 | |||
886 | /* PCA9544A (I2C multiplexer) */
|
||
887 | static int _utShellCmdCb_AlldPca5944a(BaseSequentialStream* stream, int argc, char* argv[]) |
||
888 | { |
||
889 | // evaluate arguments
|
||
890 | if (argc == 2) { |
||
891 | if (strcmp(argv[1], "#1") == 0) { |
||
892 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer1; |
||
893 | aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #1");
|
||
894 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
|
||
895 | return AOS_OK;
|
||
896 | } |
||
897 | else if (strcmp(argv[1], "#2") == 0) { |
||
898 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = &moduleLldI2cMultiplexer2; |
||
899 | aosUtRun(stream, &moduleUtAlldPca9544a, "I2C bus #2");
|
||
900 | ((ut_pca9544adata_t*)moduleUtAlldPca9544a.data)->driver = NULL;
|
||
901 | return AOS_OK;
|
||
902 | } |
||
903 | } |
||
904 | // print help
|
||
905 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
906 | chprintf(stream, "Options:\n");
|
||
907 | chprintf(stream, " #1\n");
|
||
908 | chprintf(stream, " Test the multiplexer on the I2C bus #1.\n");
|
||
909 | chprintf(stream, " #2\n");
|
||
910 | chprintf(stream, " Test the multiplexer on the I2C bus #2.\n");
|
||
911 | return AOS_INVALID_ARGUMENTS;
|
||
912 | } |
||
913 | static ut_pca9544adata_t _utAlldPca9544aData = {
|
||
914 | /* driver */ NULL, |
||
915 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
916 | }; |
||
917 | aos_unittest_t moduleUtAlldPca9544a = { |
||
918 | /* name */ "PCA9544A", |
||
919 | /* info */ "I2C multiplexer", |
||
920 | /* test function */ utAlldPca9544aFunc,
|
||
921 | /* shell command */ {
|
||
922 | /* name */ "unittest:I2CMultiplexer", |
||
923 | /* callback */ _utShellCmdCb_AlldPca5944a,
|
||
924 | /* next */ NULL, |
||
925 | }, |
||
926 | /* data */ &_utAlldPca9544aData,
|
||
927 | }; |
||
928 | |||
929 | /* PKLCS1212E4001 (buzzer) */
|
||
930 | static int _utShellCmdCb_AlldPklcs1212e4001(BaseSequentialStream* stream, int argc, char* argv[]) |
||
931 | { |
||
932 | (void)argc;
|
||
933 | (void)argv;
|
||
934 | aosUtRun(stream, &moduleUtAlldPklcs1212e4001, NULL);
|
||
935 | return AOS_OK;
|
||
936 | } |
||
937 | static ut_pklcs1212e4001_t _utAlldPklcs1212e4001Data = {
|
||
938 | /* PWM driver */ &MODULE_HAL_PWM_BUZZER,
|
||
939 | /* PWM channel */ MODULE_HAL_PWM_BUZZER_CHANNEL
|
||
940 | }; |
||
941 | aos_unittest_t moduleUtAlldPklcs1212e4001 = { |
||
942 | /* name */ "PKLCS1212E4001", |
||
943 | /* info */ "buzzer", |
||
944 | /* test function */ utAlldPklcs1212e4001Func,
|
||
945 | /* shell command */ {
|
||
946 | /* name */ "unittest:Buzzer", |
||
947 | /* callback */ _utShellCmdCb_AlldPklcs1212e4001,
|
||
948 | /* next */ NULL, |
||
949 | }, |
||
950 | /* data */ &_utAlldPklcs1212e4001Data,
|
||
951 | }; |
||
952 | |||
953 | /* TPS62113 (stop-down converter) */
|
||
954 | static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[]) |
||
955 | { |
||
956 | // Although there are four TPS62113 on the PCB, they all share the same input signal.
|
||
957 | // A sa result, no additional shell arguments need to be evaluated.
|
||
958 | (void)argc;
|
||
959 | (void)argv;
|
||
960 | aosUtRun(stream, &moduleUtAlldTps62113, NULL);
|
||
961 | return AOS_OK;
|
||
962 | } |
||
963 | aos_unittest_t moduleUtAlldTps62113 = { |
||
964 | /* name */ "TPS62113", |
||
965 | /* info */ "step-down converter", |
||
966 | /* test function */ utAlldTps62113Func,
|
||
967 | /* shell command */ {
|
||
968 | /* name */ "unittest:StepDownConverter", |
||
969 | /* callback */ _utShellCmdCb_AlldTps62113,
|
||
970 | /* next */ NULL, |
||
971 | }, |
||
972 | /* data */ &moduleLldStepDownConverter,
|
||
973 | }; |
||
974 | |||
975 | /* TPS62113 (step-donw converter) in combination with INA219 (power monitor) */
|
||
976 | static int _utShellCmdCb_AlldTps62113Ina219(BaseSequentialStream* stream, int argc, char* argv[]) |
||
977 | { |
||
978 | (void)argc;
|
||
979 | (void)argv;
|
||
980 | aosUtRun(stream, &moduleUtAlldTps62113Ina219, "VSYS (4.2V)");
|
||
981 | return AOS_OK;
|
||
982 | } |
||
983 | ut_tps62113ina219data_t _utAlldTps62113Ina219Data = { |
||
984 | /* TPS62113 */ &moduleLldStepDownConverter,
|
||
985 | /* INA219 */ &moduleLldPowerMonitorVsys42,
|
||
986 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
987 | }; |
||
988 | aos_unittest_t moduleUtAlldTps62113Ina219 = { |
||
989 | /* name */ "TPS62113 & INA219", |
||
990 | /* info */ "step-down converter & power monitor", |
||
991 | /* test function */ utAlldTps62113Ina219Func,
|
||
992 | /* shell command */ {
|
||
993 | /* name */ "unittest:StepDownConverter&PowerMonitor", |
||
994 | /* callback */ _utShellCmdCb_AlldTps62113Ina219,
|
||
995 | /* next */ NULL, |
||
996 | }, |
||
997 | /* data */ &_utAlldTps62113Ina219Data,
|
||
998 | }; |
||
999 | |||
1000 | /* VCNL4020 (proximity sensor) */
|
||
1001 | static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl) |
||
1002 | { |
||
1003 | uint8_t intstatus; |
||
1004 | vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
|
||
1005 | vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1006 | if (intstatus) {
|
||
1007 | vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1008 | } |
||
1009 | return;
|
||
1010 | } |
||
1011 | static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[]) |
||
1012 | { |
||
1013 | enum {
|
||
1014 | UNKNOWN, |
||
1015 | NNE, ENE, ESE, SSE, SSW,WSW,WNW, NNW, |
||
1016 | } sensor = UNKNOWN; |
||
1017 | // evaluate arguments
|
||
1018 | if (argc == 2) { |
||
1019 | if (strcmp(argv[1], "-nne") == 0) { |
||
1020 | sensor = NNE; |
||
1021 | } else if (strcmp(argv[1], "-ene") == 0) { |
||
1022 | sensor = ENE; |
||
1023 | } else if (strcmp(argv[1], "-ese") == 0) { |
||
1024 | sensor = ESE; |
||
1025 | } else if (strcmp(argv[1], "-sse") == 0) { |
||
1026 | sensor = SSE; |
||
1027 | } else if (strcmp(argv[1], "-ssw") == 0) { |
||
1028 | sensor = SSW; |
||
1029 | } else if (strcmp(argv[1], "-wsw") == 0) { |
||
1030 | sensor = WSW; |
||
1031 | } else if (strcmp(argv[1], "-wnw") == 0) { |
||
1032 | sensor = WNW; |
||
1033 | } else if (strcmp(argv[1], "-nnw") == 0) { |
||
1034 | sensor = NNW; |
||
1035 | } |
||
1036 | } |
||
1037 | if (sensor != UNKNOWN) {
|
||
1038 | PCA9544ADriver* mux = NULL;
|
||
1039 | switch (sensor) {
|
||
1040 | case SSE:
|
||
1041 | case SSW:
|
||
1042 | case WSW:
|
||
1043 | case WNW:
|
||
1044 | mux = &moduleLldI2cMultiplexer1; |
||
1045 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity1; |
||
1046 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = (1 << MODULE_GPIO_EXTCHANNEL_IRINT2);
|
||
1047 | extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT2); |
||
1048 | break;
|
||
1049 | case NNW:
|
||
1050 | case NNE:
|
||
1051 | case ENE:
|
||
1052 | case ESE:
|
||
1053 | mux = &moduleLldI2cMultiplexer2; |
||
1054 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = &moduleLldProximity2; |
||
1055 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = (1 << MODULE_GPIO_EXTCHANNEL_IRINT1);
|
||
1056 | extChannelEnable(&MODULE_HAL_EXT, MODULE_GPIO_EXTCHANNEL_IRINT1); |
||
1057 | break;
|
||
1058 | default:
|
||
1059 | break;
|
||
1060 | } |
||
1061 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1062 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1063 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1064 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1065 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1066 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1067 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1068 | _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld); |
||
1069 | switch (sensor) {
|
||
1070 | case NNE:
|
||
1071 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1072 | aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northeast sensor");
|
||
1073 | break;
|
||
1074 | case ENE:
|
||
1075 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1076 | aosUtRun(stream, &moduleUtAlldVcnl4020, "east-northeast sensor");
|
||
1077 | break;
|
||
1078 | case ESE:
|
||
1079 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1080 | aosUtRun(stream, &moduleUtAlldVcnl4020, "north-southeast sensor");
|
||
1081 | break;
|
||
1082 | case SSE:
|
||
1083 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1084 | aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southeast sensor");
|
||
1085 | break;
|
||
1086 | case SSW:
|
||
1087 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1088 | aosUtRun(stream, &moduleUtAlldVcnl4020, "south-southwest sensor");
|
||
1089 | break;
|
||
1090 | case WSW:
|
||
1091 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1092 | aosUtRun(stream, &moduleUtAlldVcnl4020, "west-southwest sensor");
|
||
1093 | break;
|
||
1094 | case WNW:
|
||
1095 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1096 | aosUtRun(stream, &moduleUtAlldVcnl4020, "west-northwest sensor");
|
||
1097 | break;
|
||
1098 | case NNW:
|
||
1099 | pca9544a_lld_setchannel(mux, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout); |
||
1100 | aosUtRun(stream, &moduleUtAlldVcnl4020, "north-northwest sensor");
|
||
1101 | break;
|
||
1102 | default:
|
||
1103 | break;
|
||
1104 | } |
||
1105 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld = NULL;
|
||
1106 | ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->evtflags = 0;
|
||
1107 | return AOS_OK;
|
||
1108 | } |
||
1109 | // print help
|
||
1110 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
1111 | chprintf(stream, "Options:\n");
|
||
1112 | chprintf(stream, " -nne\n");
|
||
1113 | chprintf(stream, " Test north-northeast sensor.\n");
|
||
1114 | chprintf(stream, " -ene\n");
|
||
1115 | chprintf(stream, " Test east-northeast sensor.\n");
|
||
1116 | chprintf(stream, " -ese\n");
|
||
1117 | chprintf(stream, " Test east-southeast sensor.\n");
|
||
1118 | chprintf(stream, " -sse\n");
|
||
1119 | chprintf(stream, " Test south-southeast sensor.\n");
|
||
1120 | chprintf(stream, " -ssw\n");
|
||
1121 | chprintf(stream, " Test south-southwest sensor.\n");
|
||
1122 | chprintf(stream, " -wsw\n");
|
||
1123 | chprintf(stream, " Test west-southwest sensor.\n");
|
||
1124 | chprintf(stream, " -wnw\n");
|
||
1125 | chprintf(stream, " Test west-northwest sensor.\n");
|
||
1126 | chprintf(stream, " -nnw\n");
|
||
1127 | chprintf(stream, " Test north-northwest sensor.\n");
|
||
1128 | return AOS_INVALID_ARGUMENTS;
|
||
1129 | } |
||
1130 | static ut_vcnl4020data_t _utAlldVcnl4020Data = {
|
||
1131 | /* driver */ NULL, |
||
1132 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
1133 | 6b53f6bf | Thomas Schöpping | /* event source */ &aos.events.io,
|
1134 | e545e620 | Thomas Schöpping | /* event flags */ 0, |
1135 | }; |
||
1136 | aos_unittest_t moduleUtAlldVcnl4020 = { |
||
1137 | /* name */ "VCNL4020", |
||
1138 | /* info */ "proximity sensor", |
||
1139 | /* test function */ utAlldVcnl4020Func,
|
||
1140 | /* shell command */ {
|
||
1141 | /* name */ "unittest:Proximity", |
||
1142 | /* callback */ _utShellCmdCb_AlldVcnl4020,
|
||
1143 | /* next */ NULL, |
||
1144 | }, |
||
1145 | /* data */ &_utAlldVcnl4020Data,
|
||
1146 | }; |
||
1147 | |||
1148 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
1149 | |||
1150 | /** @} */ |