Revision ded1ded7

View differences:

modules/NUCLEO-L476RG/Makefile
159 159
include $(MODULE_DIR)/test/MPU6050/module_test_MPU6050.mk
160 160
include $(MODULE_DIR)/test/VL53L1X/module_test_VL53L1X.mk
161 161

  
162

  
163 162
# C warning options.
164 163
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
165 164

  
modules/NUCLEO-L476RG/alldconf.h
33 33
 */
34 34
#include <aos_alldconf.h>
35 35

  
36
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
37

  
38
/**
39
 * @brief   VL53L1X I2C voltage level configuration.
40
 * @details VL53L1X assumes 1.8V I2C communication by default.
41
 *          This flag triggers the API to set the device to 2.8V mode.
42
 */
43
#define VL53L1X_LLD_I2C_2V8                     true
44

  
45
#endif
46

  
36 47
#endif /* ALLDCONF_H */
37 48

  
38 49
/** @} */
modules/NUCLEO-L476RG/board.h
62 62
/*
63 63
 * Identifiers for optional peripherals.
64 64
 */
65
#define BOARD_MPU6050_CONNECTED     false
66

  
65
#define BOARD_MPU6050_CONNECTED     true
67 66
#define BOARD_VL53L1X_CONNECTED     true
68 67

  
69 68

  
......
463 462
 * PB5  - ARD_D4                    (analog).
464 463
 * PB6  - ARD_D10                   (analog).
465 464
 * PB7  - PIN7                      (analog).
466
 * PB8  - ARD_D15                   (analog).
467
 * PB9  - ARD_D14                   (analog).
465
 * PB8  - ARD_D15                   (alternate 4).
466
 * PB9  - ARD_D14                   (alternate 4).
468 467
 * PB10 - ARD_D6                    (analog).
469 468
 * PB11 - PIN11                     (analog).
470 469
 * PB12 - PIN12                     (analog).
......
480 479
                                     PIN_MODE_ANALOG(GPIOB_ARD_D4) |        \
481 480
                                     PIN_MODE_ANALOG(GPIOB_ARD_D10) |       \
482 481
                                     PIN_MODE_ANALOG(GPIOB_PIN7) |          \
483
                                     PIN_MODE_ANALOG(GPIOB_ARD_D15) |       \
484
                                     PIN_MODE_ANALOG(GPIOB_ARD_D14) |       \
482
                                     PIN_MODE_ALTERNATE(GPIOB_ARD_D15) |    \
483
                                     PIN_MODE_ALTERNATE(GPIOB_ARD_D14) |    \
485 484
                                     PIN_MODE_ANALOG(GPIOB_ARD_D6) |        \
486 485
                                     PIN_MODE_ANALOG(GPIOB_PIN11) |         \
487 486
                                     PIN_MODE_ANALOG(GPIOB_PIN12) |         \
......
496 495
                                     PIN_OTYPE_PUSHPULL(GPIOB_ARD_D4) |     \
497 496
                                     PIN_OTYPE_PUSHPULL(GPIOB_ARD_D10) |    \
498 497
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN7) |       \
499
                                     PIN_OTYPE_PUSHPULL(GPIOB_ARD_D15) |    \
500
                                     PIN_OTYPE_PUSHPULL(GPIOB_ARD_D14) |    \
498
                                     PIN_OTYPE_OPENDRAIN(GPIOB_ARD_D15) |   \
499
                                     PIN_OTYPE_OPENDRAIN(GPIOB_ARD_D14) |   \
501 500
                                     PIN_OTYPE_PUSHPULL(GPIOB_ARD_D6) |     \
502 501
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN11) |      \
503 502
                                     PIN_OTYPE_PUSHPULL(GPIOB_PIN12) |      \
......
528 527
                                     PIN_PUPDR_FLOATING(GPIOB_ARD_D4) |     \
529 528
                                     PIN_PUPDR_FLOATING(GPIOB_ARD_D10) |    \
530 529
                                     PIN_PUPDR_FLOATING(GPIOB_PIN7) |       \
531
                                     PIN_PUPDR_FLOATING(GPIOB_ARD_D15) |    \
532
                                     PIN_PUPDR_FLOATING(GPIOB_ARD_D14) |    \
530
                                     PIN_PUPDR_PULLUP(GPIOB_ARD_D15) |      \
531
                                     PIN_PUPDR_PULLUP(GPIOB_ARD_D14) |      \
533 532
                                     PIN_PUPDR_FLOATING(GPIOB_ARD_D6) |     \
534 533
                                     PIN_PUPDR_FLOATING(GPIOB_PIN11) |      \
535 534
                                     PIN_PUPDR_FLOATING(GPIOB_PIN12) |      \
......
560 559
                                     PIN_AFIO_AF(GPIOB_ARD_D4, 0U) |        \
561 560
                                     PIN_AFIO_AF(GPIOB_ARD_D10, 0U) |       \
562 561
                                     PIN_AFIO_AF(GPIOB_PIN7, 0U))
563
#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_ARD_D15, 0U) |       \
564
                                     PIN_AFIO_AF(GPIOB_ARD_D14, 0U) |       \
562
#define VAL_GPIOB_AFRH              (PIN_AFIO_AF(GPIOB_ARD_D15, 4U) |       \
563
                                     PIN_AFIO_AF(GPIOB_ARD_D14, 4U) |       \
565 564
                                     PIN_AFIO_AF(GPIOB_ARD_D6, 0U) |        \
566 565
                                     PIN_AFIO_AF(GPIOB_PIN11, 0U) |         \
567 566
                                     PIN_AFIO_AF(GPIOB_PIN12, 0U) |         \
modules/NUCLEO-L476RG/mcuconf.h
181 181
/*
182 182
 * I2C driver system settings.
183 183
 */
184
#define STM32_I2C_USE_I2C1                  FALSE
184
#define STM32_I2C_USE_I2C1                  TRUE
185 185
#define STM32_I2C_USE_I2C2                  FALSE
186
#define STM32_I2C_USE_I2C3                  TRUE
186
#define STM32_I2C_USE_I2C3                  FALSE
187 187
#define STM32_I2C_BUSY_TIMEOUT              50
188 188
#define STM32_I2C_I2C1_RX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 7)
189 189
#define STM32_I2C_I2C1_TX_DMA_STREAM        STM32_DMA_STREAM_ID(1, 6)
modules/NUCLEO-L476RG/module.c
49 49
  /* CR1      */ 0,
50 50
};
51 51

  
52
#if (BOARD_MPU6050_CONNECTED == true)
53

  
54
I2CConfig moduleHalI2c3Config = {
55
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook
56
  /* CR1        */ 0,
57
  /* CR2        */ 0,
58
};
59

  
60
#endif /* (BOARD_MPU6050_CONNECTED == true) */
61

  
62
#if (BOARD_VL53L1X_CONNECTED == true)
63

  
64
I2CConfig moduleHalI2c3Config = {
65
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook
52
I2CConfig moduleHalI2cConfig = {
53
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF hook
66 54
  /* CR1        */ 0,
67 55
  /* CR2        */ 0,
68 56
};
69 57

  
70
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
71

  
72 58
/** @} */
73 59

  
74 60
/*===========================================================================*/
......
108 94
  },
109 95
};
110 96

  
97
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
111 98

  
99
/**
100
 * @brief   VL53L1X interrupt signal GPIO.
101
 */
112 102
static apalGpio_t _gpioVl53l1xINT = {
113
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN2),
103
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN6),
114 104
};
115 105
ROMCONST apalControlGpio_t moduleGpioVl53l1xINT = {
116 106
  /* GPIO */ &_gpioVl53l1xINT,
......
121 111
  },
122 112
};
123 113

  
114
/**
115
 * @brief   VL53L1X XSHUT signal GPIO.
116
 */
124 117
static apalGpio_t _gpioVl53l1xXSHUT = {
125
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN3),
118
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN5),
126 119
};
127 120
ROMCONST apalControlGpio_t moduleGpioVl53l1xXSHUT = {
128 121
  /* GPIO */ &_gpioVl53l1xXSHUT,
......
133 126
  },
134 127
};
135 128

  
129
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
130

  
136 131
/** @} */
137 132

  
138 133
/*===========================================================================*/
......
172 167
  /* Button Gpio  */ &moduleGpioUserButton,
173 168
};
174 169

  
175

  
176
#if (BOARD_VL53L1X_CONNECTED == true)
177
VL53L1XDriver moduleLldVl53l1x = {
178
   /* I2C Driver       */ &MODULE_HAL_I2C3,
179
  /* I²C address      */ VL53L1X_LLD_I2C_ADDR_DEFAULT,
180
  /* GPIO 1:INT pin */ &moduleGpioVl53l1xINT,
181
   /* Xshut  */        &moduleGpioVl53l1xXSHUT,
182
};
183

  
184
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
185

  
186 170
#if (BOARD_MPU6050_CONNECTED == true)
187 171

  
188 172
MPU6050Driver moduleLldMpu6050 = {
189
  /* I2C Driver       */ &MODULE_HAL_I2C3,
173
  /* I2C Driver       */ &MODULE_HAL_I2C,
190 174
  /* I²C address      */ MPU6050_LLD_I2C_ADDR_FIXED,
191 175
};
192 176

  
177
#endif /* (BOARD_MPU6050_CONNECTED == true) */
193 178

  
179
#if (BOARD_VL53L1X_CONNECTED == true)
194 180

  
195
#endif /* (BOARD_MPU6050_CONNECTED == true) */
181
VL53L1XDriver moduleLldVl53l1x = {
182
  /* device data    */ {},
183
  /* interface data */ {
184
    /* I2C Driver     */ &MODULE_HAL_I2C,
185
    /* I²C address    */ VL53L1X_LLD_I2C_ADDR_DEFAULT,
186
    /* GPIO 1:INT pin */ &moduleGpioVl53l1xINT,
187
    /* Xshut          */ &moduleGpioVl53l1xXSHUT,
188
  },
189
};
190

  
191
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
196 192

  
197 193
/** @} */
198 194

  
......
215 211
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:LED", _testLedShellCmdCb);
216 212

  
217 213
/*
218
 * LED
219
 */
220
#include <module_test_VL53L1X.h>
221
static int _testShellVL53L1XCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
222
{
223
  return moduleTestVL53L1XShellCb(stream, argc, argv, NULL);
224
}
225
AOS_SHELL_COMMAND(moduleTestVL53L1XShellCmd, "test:VL53L1X", _testShellVL53L1XCmdCb);
226

  
227
static int _testShellVL53L1XInitCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
228
{
229
  return moduleTestVL53L1XInitShellCb(stream, argc, argv, NULL);
230
}
231
AOS_SHELL_COMMAND(moduleTestVL53L1XInitShellCmd, "test:VL53L1X:INIT", _testShellVL53L1XInitCmdCb);
232

  
233
/*
234 214
 * User button
235 215
 */
236 216
#include <module_test_button.h>
......
241 221
AOS_SHELL_COMMAND(moduleTestButtonShellCmd, "test:button", _testButtonShellCmdCb);
242 222

  
243 223
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
244

  
245 224
/*
246 225
 * MPU6050 (accelerometer & gyroscope)
247 226
 */
......
251 230
  return moduleTestMpu6050ShellCb(stream, argc, argv, NULL);
252 231
}
253 232
AOS_SHELL_COMMAND(moduleTestMpu6050ShellCmd, "test:IMU", _testMpu6050ShellCmdCb);
254

  
255 233
#endif /* (BOARD_MPU6050_CONNECTED == true) */
256 234

  
235
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
236
/*
237
 * VL53L1X
238
 */
239
#include <module_test_VL53L1X.h>
240
static int _testShellVL53L1XCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
241
{
242
  return moduleTestVL53L1XShellCb(stream, argc, argv, NULL);
243
}
244
AOS_SHELL_COMMAND(moduleTestVL53L1XShellCmd, "test:VL53L1X", _testShellVL53L1XCmdCb);
245
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
246

  
257 247
/*
258 248
 * entire module
259 249
 */
......
275 265
  status |= moduleTestButtonShellCb(stream, 0, targv, &result_test);
276 266
  result_total = aosTestResultAdd(result_total, result_test);
277 267

  
278
  /* MPU6050 (accelerometer & gyroscope) */
279 268
#if (BOARD_MPU6050_CONNECTED == true)
269
  /* MPU6050 (accelerometer & gyroscope) */
280 270
  status |= moduleTestMpu6050ShellCb(stream, 0, targv, &result_test);
281 271
  result_total = aosTestResultAdd(result_total, result_test);
282 272
#endif /* (BOARD_MPU6050_CONNECTED == true) */
283 273

  
274
#if (BOARD_VL53L1X_CONNECTED == true)
275
  /* VL53L1X (ToF sensor) */
276
  status |= moduleTestVL53L1XShellCb(stream, 0, targv, &result_test);
277
  result_total = aosTestResultAdd(result_total, result_test);
278
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
279

  
284 280
  // print total result
285 281
  chprintf(stream, "\n");
286 282
  aosTestResultPrintSummary(stream, &result_total, "entire module");
modules/NUCLEO-L476RG/module.h
29 29

  
30 30
#include <amiroos.h>
31 31

  
32
#if (BOARD_MPU6050_CONNECTED == true)
33
#include <math.h>
34
#endif /* BOARD_MPU6050_CONNECTED == true */
35

  
32 36
/*===========================================================================*/
33 37
/**
34 38
 * @name Module specific functions
......
60 64
 */
61 65
#define MODULE_HAL_RTC                          RTCD1
62 66

  
63
#if (BOARD_MPU6050_CONNECTED == true || BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
64

  
65 67
/**
66
 * @brief   I2C driver to access multiplexer, proximity sensors 5 to 8, power monitors for VSYS4.2, VIO 5.0 and VDD, EEPROM, touch sensor, and fuel gauge (front battery).
68
 * @brief   Default I2C interface for the NUCLEO I/O.
67 69
 */
68
#define MODULE_HAL_I2C3                         I2CD3
70
#define MODULE_HAL_I2C                          I2CD1
69 71

  
70 72
/**
71
 * @brief   Configuration for the I2C driver #3.
73
 * @brief   Configuration for the I2C driver #1.
72 74
 */
73
extern I2CConfig moduleHalI2c3Config;
74

  
75
#endif /* (BOARD_MPU6050_CONNECTED == true || BOARD_VL53L1X_CONNECTED == true) */
75
extern I2CConfig moduleHalI2cConfig;
76 76

  
77 77
/** @} */
78 78

  
......
92 92
 * @brief   User button input signal.
93 93
 */
94 94
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
95

  
96
#if (BOARD_VL53L1X_CONNECTED == true)
97

  
98
/**
99
 * @brief   VL53L1X interrupt signal (GPIO1).
100
 */
95 101
extern ROMCONST apalControlGpio_t moduleGpioVl53l1xINT;
102

  
103
/**
104
 * @brief   VL53L1X XSHUT signal.
105
 */
96 106
extern ROMCONST apalControlGpio_t moduleGpioVl53l1xXSHUT;
97 107

  
108
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
109

  
98 110
/** @} */
99 111

  
100 112
/*===========================================================================*/
......
104 116
 */
105 117
/*===========================================================================*/
106 118

  
107
#include <math.h>
108

  
109 119
/**
110 120
 * @brief   Event flag to be set on a USER_BUTTON interrupt.
111 121
 */
......
160 170
#if (BOARD_VL53L1X_CONNECTED == true)
161 171
  #define MODULE_INIT_TEST_VL53L1X() {                                        \
162 172
    aosShellAddCommand(&aos.shell, &moduleTestVL53L1XShellCmd);               \
163
    aosShellAddCommand(&aos.shell, &moduleTestVL53L1XInitShellCmd);               \
164 173
  }
165 174
#else /* (BOARD_VL53L1X_CONNECTED == true) */
166 175
  #define MODULE_INIT_TEST_VL53L1X() {}
......
172 181
#define MODULE_INIT_PERIPHERY_IF() {                                          \
173 182
  /* serial driver */                                                         \
174 183
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
175
  /* MPU6050 demo */                                                          \
176
  MODULE_INIT_PERIPHERY_IF_MPU6050();                                         \
177
  MODULE_INIT_PERIPHERY_IF_VL53L1X();                                         \
184
  /* I2C */                                                                   \
185
  uint32_t i2c_freq = 1000000; /* maximum I2C frequency supported for this MCU */ \
186
  MODULE_INIT_PERIPHERY_IF_MPU6050(i2c_freq);                                 \
187
  MODULE_INIT_PERIPHERY_IF_VL53L1X(i2c_freq);                                 \
188
  if (i2c_freq == 100000) /* standard-mode @ 100 kHz */ {                     \
189
    moduleHalI2cConfig.timingr = 0x10909CEC; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
190
  } else if (i2c_freq == 400000) /* fast-mode @ 400 kHz */ {                  \
191
    moduleHalI2cConfig.timingr = 0x00702991; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
192
  } else if (i2c_freq == 1000000) /* fast-mode-plus @ 10000 kHz */ {          \
193
    moduleHalI2cConfig.timingr = 0x00300F33; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
194
  } else {                                                                    \
195
    aosDbgAssertMsg(false, "I2C frequency not supported");                    \
196
  }                                                                           \
197
  i2cStart(&MODULE_HAL_I2C, &moduleHalI2cConfig);                             \
178 198
}
179
#if (BOARD_MPU6050_CONNECTED == true)
180
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {                                \
181
    /* maximum I2C frequency is 1MHz for this MCU */                          \
182
    uint32_t i2c3_freq = 1000000;                                             \
183
    /* find minimum amon all devices connected to this bus */                 \
184
    i2c3_freq = (MPU6050_LLD_I2C_MAXFREQUENCY < i2c3_freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : i2c3_freq;  \
185
    /* calculate PRESC (prescaler):                                           \
186
     *   target is 1/(I2CXCLK * (PRESC + 1)) = 125ns                          \
187
     */                                                                       \
188
    moduleHalI2c3Config.timingr = ((uint8_t)((0.000000125f * STM32_I2C3CLK) - 1)) << I2C_TIMINGR_PRESC_Pos; \
189
    /* SCL shall be low half of the time. */                                  \
190
    moduleHalI2c3Config.timingr |= ((uint8_t)((1.f / i2c3_freq / 2 / 0.000000125f) - 1)) << I2C_TIMINGR_SCLL_Pos; \
191
    /* SCL shall be high half the time of low or slightly longer. */          \
192
    moduleHalI2c3Config.timingr |= (uint8_t)(ceilf(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) / 2.f)) << I2C_TIMINGR_SCLH_Pos;  \
193
    /* SDA shall be delayed 1/10 of SCL low, or shorter */                    \
194
    moduleHalI2c3Config.timingr |= (uint8_t)(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) * 0.1f) << I2C_TIMINGR_SDADEL_Pos;  \
195
    /* SCL shall be delyed twice as long as SDA, but longer than 0. */        \
196
    moduleHalI2c3Config.timingr |= ((((moduleHalI2c3Config.timingr & I2C_TIMINGR_SDADEL_Msk) >> I2C_TIMINGR_SDADEL_Pos) * 2) + 1) << I2C_TIMINGR_SCLDEL_Pos;  \
197
    /* now we can start the I2C driver */                                     \
198
    chSysLock();                                                              \
199
    palSetLineMode(LINE_ARD_A4, PAL_MODE_ALTERNATE(4));                       \
200
    palSetLineMode(LINE_ARD_A5, PAL_MODE_ALTERNATE(4));                       \
201
    chSysUnlock();                                                            \
202
    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
203
  }
204
#else /* (BOARD_MPU6050_CONNECTED == true) */
205
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {}
206
#endif /* (BOARD_MPU6050_CONNECTED == true) */
207 199

  
208
#if (BOARD_VL53L1X_CONNECTED == true)
209
  #define MODULE_INIT_PERIPHERY_IF_VL53L1X() {                                \
210
    /* maximum I2C frequency is 1MHz for this MCU */                          \
211
    uint32_t i2c3_freq = 1000000;                                             \
212
    /* find minimum amon all devices connected to this bus */                 \
213
    i2c3_freq = (VL53L1X_LLD_I2C_MAXFREQUENCY < i2c3_freq) ? VL53L1X_LLD_I2C_MAXFREQUENCY : i2c3_freq;  \
214
    /* calculate PRESC (prescaler):                                           \
215
     *   target is 1/(I2CXCLK * (PRESC + 1)) = 125ns                          \
216
     */                                                                       \
217
    moduleHalI2c3Config.timingr = ((uint8_t)((0.000000125f * STM32_I2C3CLK) - 1)) << I2C_TIMINGR_PRESC_Pos; \
218
    /* SCL shall be low half of the time. */                                  \
219
    moduleHalI2c3Config.timingr |= ((uint8_t)((1.f / i2c3_freq / 2 / 0.000000125f) - 1)) << I2C_TIMINGR_SCLL_Pos; \
220
    /* SCL shall be high half the time of low or slightly longer. */          \
221
    moduleHalI2c3Config.timingr |= (uint8_t)(ceilf(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) / 2.f)) << I2C_TIMINGR_SCLH_Pos;  \
222
    /* SDA shall be delayed 1/10 of SCL low, or shorter */                    \
223
    moduleHalI2c3Config.timingr |= (uint8_t)(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) * 0.1f) << I2C_TIMINGR_SDADEL_Pos;  \
224
    /* SCL shall be delyed twice as long as SDA, but longer than 0. */        \
225
    moduleHalI2c3Config.timingr |= ((((moduleHalI2c3Config.timingr & I2C_TIMINGR_SDADEL_Msk) >> I2C_TIMINGR_SDADEL_Pos) * 2) + 1) << I2C_TIMINGR_SCLDEL_Pos;  \
226
    /* setup the GPIO signals */                                              \
227
    moduleHalI2c3Config.timingr = 0x00702991; \
228
    chSysLock();                                \
229
    PAL_PORT(moduleLldVl53l1x.xshut->gpio->line)->PUPDR &= ~(3U << (PAL_PAD(moduleLldVl53l1x.xshut->gpio->line) * 2U)); \
230
    PAL_PORT(moduleLldVl53l1x.xshut->gpio->line)->PUPDR |= PIN_PUPDR_PULLUP(PAL_PAD(moduleLldVl53l1x.xshut->gpio->line)); \
231
    /* palSetLineMode(moduleLldVl53l1x.xshut->gpio->line, PAL_MODE_OUTPUT_OPENDRAIN); \*/ \
232
      palSetLineMode(moduleLldVl53l1x.xshut->gpio->line, PAL_MODE_OUTPUT_PUSHPULL); \
233
palSetLineMode(moduleLldVl53l1x.gpio1->gpio->line, PAL_MODE_INPUT_PULLUP); \
234
    palSetLineMode(LINE_ARD_A4, PAL_MODE_ALTERNATE(4));                       \
235
    palSetLineMode(LINE_ARD_A5, PAL_MODE_ALTERNATE(4));                       \
200

  
201
/**
202
 * @brief   Limits I2C frequency to maximum value supported by MPU6050.
203
 */
204
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
205
  #define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {freq = (MPU6050_LLD_I2C_MAXFREQUENCY < freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : freq;}
206
#else
207
  #define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {}
208
#endif
209

  
210
/**
211
 * @brief   Limits I2C frequency to maximum value supported by VL53L1X and configures required GPIOs.
212
 */
213
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
214
  #define MODULE_INIT_PERIPHERY_IF_VL53L1X(freq) {                            \
215
    freq = (VL53L1X_LLD_I2C_MAXFREQUENCY < freq) ? VL53L1X_LLD_I2C_MAXFREQUENCY : freq; \
216
    chSysLock();                                                              \
217
    /* set XSHUT GPIO as output in open-drain configuration with internal pull-up, but initially pulled-down signal */  \
218
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->OTYPER &= ~(1U << PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
219
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->OTYPER |= PIN_OTYPE_OPENDRAIN(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
220
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->PUPDR &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line) * 2U)); \
221
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->PUPDR |= PIN_PUPDR_PULLUP(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
222
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->ODR &= ~(1U << PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line));  \
223
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->ODR |= PIN_ODR_LOW(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line));  \
224
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->MODER &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line) * 2U)); \
225
    PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->MODER |= PIN_MODE_OUTPUT(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line));  \
226
    /* set GPIO1 (interrupt) GPIO as input with internal pull-up */           \
227
    PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->PUPDR &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line) * 2U)); \
228
    PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->PUPDR |= PIN_PUPDR_PULLUP(PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line)); \
229
    PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->MODER &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line) * 2U)); \
230
    PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->MODER |= PIN_MODE_INPUT(PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line)); \
236 231
    chSysUnlock();                                                            \
237
    apalControlGpioSet(moduleLldVl53l1x.xshut, APAL_GPIO_OFF);                \
238
    /* now we can start the I2C driver */                                     \
239
    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
240 232
  }
241
#else /* (BOARD_VL53L1X_CONNECTED == true) */
242
  #define MODULE_INIT_PERIPHERY_IF_VL53L1X() {}
243
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
233
#else
234
  #define MODULE_INIT_PERIPHERY_IF_VL53L1X(freq) {}
235
#endif
244 236

  
245 237
/**
246 238
 * @brief   Periphery communication interface deinitialization hook.
247 239
 */
248 240
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
241
  /* I2C */                                                                   \
242
  i2cStop(&MODULE_HAL_I2C);                                                   \
249 243
  /* don't stop the serial driver so messages can still be printed */         \
250 244
}
251 245

  
......
289 283
 */
290 284
extern LEDDriver moduleLldLed;
291 285

  
292
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
293

  
294
  #include <alld_VL53L1X.h>
295

  
296
  extern VL53L1XDriver moduleLldVl53l1x;
297

  
298
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
299

  
300 286
/**
301 287
 * @brief   Button driver.
302 288
 */
......
313 299

  
314 300
#endif /* (BOARD_MPU6050_CONNECTED == true) */
315 301

  
302
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
303

  
304
#include <alld_VL53L1X.h>
305

  
306
/**
307
 * @brief   ToF sensor (VL53L1X) driver.
308
 */
309
extern VL53L1XDriver moduleLldVl53l1x;
310

  
311
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
312

  
316 313
/** @} */
317 314

  
318 315
/*===========================================================================*/
......
329 326
extern aos_shellcommand_t moduleTestLedShellCmd;
330 327

  
331 328
/**
332
 * @brief   VL53L1X test command.
333
 */
334
extern aos_shellcommand_t moduleTestVL53L1XShellCmd;
335
extern aos_shellcommand_t moduleTestVL53L1XInitShellCmd;
336

  
337
/**
338 329
 * @brief   User button test command.
339 330
 */
340 331
extern aos_shellcommand_t moduleTestButtonShellCmd;
......
348 339

  
349 340
#endif /* (BOARD_MPU6050_CONNECTED == true) */
350 341

  
342
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
343

  
344
/**
345
 * @brief   VL53L1X (ToF sonsor) test command.
346
 */
347
extern aos_shellcommand_t moduleTestVL53L1XShellCmd;
348

  
349
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
350

  
351 351
/**
352 352
 * @brief   Entire module test command.
353 353
 */
modules/NUCLEO-L476RG/test/VL53L1X/module_test_VL53L1X.c
39 39
/* LOCAL VARIABLES                                                            */
40 40
/******************************************************************************/
41 41

  
42
static aos_test_vl53l1x_bus _data = {
42
static aos_test_vl53l1xdata_t _data = {
43 43
  /* pointer to VL53L1X driver  */ &moduleLldVl53l1x,
44 44
};
45 45

  
46 46
static AOS_TEST(_test, "VL53L1X", NULL, moduleTestVL53L1XShellCb, aosTestVL53L1XFunc, &_data);
47
static AOS_TEST(_test2, "VL53L1X:INIT", NULL, moduleTestVL53L1XInitShellCb, aosTestVL53L1Xi2cInit, &_data);
48 47

  
49 48
/******************************************************************************/
50 49
/* LOCAL FUNCTIONS                                                            */
......
59 58
  (void)argc;
60 59
  (void)argv;
61 60

  
62

  
63
  aosprintf("STM32_I2C3CLK: %u\n", STM32_I2C3CLK);
64
  aosprintf("Timing_: %08x\n", moduleHalI2c3Config.timingr);
65 61
  if (result != NULL) {
66 62
    *result = aosTestRun(stream, &_test, NULL);
67 63
  } else {
......
71 67
  return AOS_OK;
72 68
}
73 69

  
74
int moduleTestVL53L1XInitShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result)
75
{
76
  (void)argc;
77
  (void)argv;
78

  
79
  if (result != NULL) {
80
    *result = aosTestRun(stream, &_test2, NULL);
81
  } else {
82
    aosTestRun(stream, &_test2, NULL);
83
  }
84

  
85
  return AOS_OK;
86
}
87

  
88 70
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
modules/NUCLEO-L476RG/test/VL53L1X/module_test_VL53L1X.h
52 52
extern "C" {
53 53
#endif /* defined(__cplusplus) */
54 54
  int moduleTestVL53L1XShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result);
55
  int moduleTestVL53L1XInitShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result);
56 55
#if defined(__cplusplus)
57 56
}
58 57
#endif /* defined(__cplusplus) */
periphery-lld/AMiRo-LLD
1
Subproject commit 99ca7610753617020954f4c3abcf72c7ecf63f6a
1
Subproject commit 0aa71229314806120b2d2efe661c5d169dd0c166
periphery-lld/aos_periphAL.c
17 17
*/
18 18

  
19 19
#include <periphAL.h>
20
#include <amiroos.h>
20 21

  
21 22
/*============================================================================*/
22 23
/* DEBUG                                                                      */
23 24
/*============================================================================*/
24 25

  
25
#if (AMIROOS_CFG_DBG == true)
26
#if (AMIROLLD_CFG_DBG == true) && (AMIROOS_CFG_DBG == true)
26 27

  
27
#include <amiroos.h>
28 28
#include <chprintf.h>
29 29

  
30 30
void apalDbgAssertMsg(const bool c, const char* fmt, ...)
......
52 52
  return chars;
53 53
}
54 54

  
55
#endif /* (AMIROOS_CFG_DBG == true) */
55
#endif /* (AMIROLLD_CFG_DBG == true) && (AMIROOS_CFG_DBG == true) */
56 56

  
57 57
/*============================================================================*/
58 58
/* TIMING                                                                     */
......
76 76

  
77 77
#endif /* (AMIROOS_CFG_DBG == true) */
78 78

  
79
apalTime_t apalGetTime(void)
80
{
81
  aos_timestamp_t uptime;
82
  aosSysGetUptime(&uptime);
83

  
84
  return uptime & ~((apalTime_t)0);
85
}
86

  
79 87
/*============================================================================*/
80 88
/* GPIO                                                                       */
81 89
/*============================================================================*/
periphery-lld/aos_periphAL.h
24 24
/*============================================================================*/
25 25

  
26 26
#include <aosconf.h>
27
#include <alldconf.h>
27 28
#include <hal.h>
28 29

  
29 30
/*============================================================================*/
30 31
/* DEBUG                                                                      */
31 32
/*============================================================================*/
32 33

  
33
#if (AMIROOS_CFG_DBG != true)
34
#if (AMIROLLD_CFG_DBG == true) && (AMIROOS_CFG_DBG != true)
34 35

  
35
#define apalDbgAssert(condition)
36
#define apalDbgAssertMsg(condition, fmt, ...)
36 37

  
37 38
#define apalDbgPrintf(fmt, ...)                 0
38 39

  
39
#endif /* (AMIROOS_CFG_DBG == true) */
40
#endif /* (AMIROLLD_CFG_DBG == true) && (AMIROOS_CFG_DBG != true) */
40 41

  
41 42
/*============================================================================*/
42 43
/* TIMING                                                                     */
test/periphery-lld/MPU6050_v1/aos_test_MPU6050.c
54 54

  
55 55
  aosTestResultInit(&result);
56 56

  
57
    status = mpu6050_lld_read_register(((aos_test_mpu6050data_t*)test->data)->mpu, MPU6050_LLD_WHO_AM_I, data, 1, ((aos_test_mpu6050data_t*)test->data)->timeout);
58
    if (status == APAL_STATUS_OK && data[0] == MPU6050_I_AM) {
57
    status = mpu6050_lld_read_register(((aos_test_mpu6050data_t*)test->data)->mpu, MPU6050_LLD_REGISTER_WHO_AM_I, data, 1, ((aos_test_mpu6050data_t*)test->data)->timeout);
58
    if (status == APAL_STATUS_OK && data[0] == MPU6050_LLD_WHO_AM_I) {
59 59
      aosTestPassed(stream, &result);
60 60
    } else {
61
      aosTestFailedMsg(stream, &result, "0x%08X | 0x%02X\n", status, data[0]);
61
      aosTestFailedMsg(stream, &result, "0x%08X | 0x%02X (%u)\n", status, data[0], i2cGetErrors(((aos_test_mpu6050data_t*)test->data)->mpu->i2cd));
62 62
    }
63 63

  
64 64
  return result;
test/periphery-lld/VL53L1X_v1/aos_test_VL53L1X.c
56 56
 */
57 57
aos_testresult_t aosTestVL53L1XFunc(BaseSequentialStream* stream, const aos_test_t* test)
58 58
{
59
//   aosDbgCheck(test->data != NULL && ((aos_test_leddata_t*)test->data)->led != NULL);
60

  
61
chprintf(stream, "Peter Wurst\n");
59
  aosDbgCheck(test->data != NULL && ((aos_test_vl53l1xdata_t*)test->data)->vl53l1x != NULL);
62 60

  
63 61
  // local variables
64
  aos_testresult_t result = {0,0};
65
//   int32_t status;
66
//     chprintf(stream, "Hello World!\n");
67
// //   aosTestResultInit(&result);
68

  
69
//   VL53L1_Dev_t dev;
70
//   dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x);
71

  
72
//   chprintf(stream, "Toggle PC2...\n");
73
//   chprintf(stream, "On...\n");
74
  /* vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_ON); */
75
//   aosThdSSleep(5);
76
//   chprintf(stream, "off...\n");
77
//   status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_OFF);
78
//   aosThdSSleep(5);
79
//   chprintf(stream, "On...\n");
80
//   status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_ON);
81
//   aosThdSSleep(5);
82
//   chprintf(stream, "Off...\n");
83
//   status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_OFF);
84
//   // status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state);
85
//   if (status == APAL_STATUS_OK) {
86
//       aosTestPassed(stream, &result);
87
//   } else {
88
//     aosTestFailed(stream, &result);
89
//   }p
90

  
91
//   chprintf(stream, "turning off for two seconds...\n");
92
//   state = LED_LLD_STATE_OFF;
93
//   status = led_lld_set(((aos_test_leddata_t*)test->data)->led, state);
94
//   aosThdSSleep(2);
95
//   status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state);
96
//   if (status == APAL_STATUS_OK && state == LED_LLD_STATE_OFF) {
97
//     aosTestPassed(stream, &result);
98
//   } else {
99
//     aosTestFailed(stream, &result);
100
//   }
101

  
102
//   chprintf(stream, "toggling for two seconds...\n");
103
//   status = led_lld_set(((aos_test_leddata_t*)test->data)->led, LED_LLD_STATE_ON);
104
//   for (uint32_t i = 0; i < 2000/100; ++i) {
105
//     status |= led_lld_toggle(((aos_test_leddata_t*)test->data)->led);
106
//     status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state);
107
//     status |= ((uint8_t)state != (i & 0x01u)) ? APAL_STATUS_ERROR : APAL_STATUS_OK;
108
//     aosThdMSleep(100);
109
//   }
110
//   status = led_lld_set(((aos_test_leddata_t*)test->data)->led, LED_LLD_STATE_OFF);
111
//   if (status == APAL_STATUS_OK) {
112
//     aosTestPassed(stream, &result);
113
//   } else {
114
//     aosTestFailed(stream, &result);
115
//   }
116

  
117
//   aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(LEDDriver));
118

  
119
/*
120
  uint8_t byteData, sensorState=0;
121
  uint16_t wordData;
122
  uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right
123
  uint16_t Distance;
124
  uint16_t SignalRate;
125
  uint16_t AmbientRate;
126
  uint8_t RangeStatus;
127
  uint8_t dataReady;
62
  aos_testresult_t result;
128 63
  int32_t status;
129
  */
130

  
131
    
132
//   aosTestResultInit(&result);
133

  
134
  VL53L1_Dev_t dev;
135
  dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x);
136
  /* vl53l1x_GPIO1_set(&dev.vl53l1x, GPIO_LLD_STATE_ON); */
137

  
138
  // status = VL53L1_RdByte(&dev, 0x010F, &byteData);
139
  // printf("VL53L1X Model_ID: %X\n", byteData);
140
  // status = VL53L1_RdByte(&dev, 0x0110, &byteData);
141
  // printf("VL53L1X Module_Type: %X\n", byteData);
142
  // status = VL53L1_RdWord(&dev, 0x010F, &wordData);
143
  // printf("VL53L1X: %X\n", wordData);
144
  
145
  // activate device
146
  apalControlGpioState_t xshut_state;
147
  apalControlGpioState_t gpio_state;
148
  apalControlGpioGet(dev.vl53l1x.xshut, &xshut_state);
149
  apalControlGpioGet(dev.vl53l1x.gpio1, &gpio_state);
150
  if (xshut_state == APAL_GPIO_OFF) {
151
    chprintf(stream, "XSHUT OFF -> activating\n");
152
    apalControlGpioSet(dev.vl53l1x.xshut, APAL_GPIO_ON);
153
    aosThdSSleep(1);
154
    aosThdUSleep(2 * VL53L1X_LLD_BOOTDURATION);
155
  } else {
156
    chprintf(stream, "XSHUT ON\n");
157
  }
158
  chprintf(stream, "0x%08X | 0x%08X\n", (uint32_t)dev.vl53l1x.i2cd, (uint32_t)(&I2CD3));
159
  chprintf(stream, "0x%02X\n", dev.vl53l1x.xshut);
160
  if (gpio_state == APAL_GPIO_OFF) {
161
    chprintf(stream, "Gpio OFF \n");
64
  VL53L1_Error error;
65

  
66
  aosTestResultInit(&result);
67

  
68
  {
69
    chprintf(stream, "Checking XSHUT signal...\n");
70
    vl53l1x_lld_state_t device_state = VL53L1X_LLD_STATE_ON;
71
    status = vl53l1x_lld_getState(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x, &device_state);
72
    if (status == APAL_STATUS_OK) {
73
      chprintf(stream, "\tXSHUT signal is %s.\n", (device_state == VL53L1X_LLD_STATE_ON) ? "on" : "off");
74
      aosTestPassed(stream, &result);
75
    } else {
76
      aosTestFailed(stream, &result);
77
    }
78

  
79
    if (device_state != VL53L1X_LLD_STATE_ON) {
80
      chprintf(stream, "Initilaizing device...\n");
81
      status = vl53l1x_lld_init(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x);
82
      if (status == APAL_STATUS_OK) {
83
        aosTestPassed(stream, &result);
84
      } else {
85
        aosTestFailedMsg(stream, &result, "%d\t%u\n", status, i2cGetErrors(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x->Interface.i2cd));
86
      }
87
    }
162 88
  }
163 89

  
164
  uint8_t testBuf[49] = {0};
165
  // Reste device
166
  
167
  // printf("Resetting device! \n");
168
  /* chprintf(stream, "Testif broken!\n"); */
169
  
170
  uint8_t data[4] = {0};
171
  /* Status = VL53L1_RdByte(Dev, VL53L1_PAD_I2C_HV__EXTSUP_CONFIG, &i); */
172
  /* apalI2CMasterReceive(dev.vl53l1x.i2cd, dev.vl53l1x.addr, testBuf, 3, 10); */
173
  /* aosThdMSleep(1000); */
174
  /* chprintf(stream, "Start reset!\n"); */
175
  /* apalI2CMasterTransmit(dev.vl53l1x.i2cd, dev.vl53l1x.addr, data, 3, testBuf, 0, 10); */
176
  chprintf(stream, "Before sleep!\n");
177
  /* apalI2CMasterTransmit() */
178
  /* aosThdMSleep(1000); */
179
  aosThdUSleep(2 * VL53L1X_LLD_BOOTDURATION);
180
  /* 0x002E */
181

  
182
  data[0] =  0x01;
183
  data[1] =  0x0f;
184
  uint8_t stuff[4] = { 0 };
185
  /* data[3] = 0x01; */
186
  chprintf(stream, "End reset!\n");
187
  
188
  apalExitStatus_t res = apalI2CMasterTransmit(dev.vl53l1x.i2cd,  dev.vl53l1x.addr, data, 2, stuff , 0, 10);
189
  
190

  
191
  chprintf(stream, "Res: %d\n", res);
192
  aosThdMSleep(100);
193
  i2cflags_t err =  i2cGetErrors(dev.vl53l1x.i2cd);
194
  chprintf(stream, "Error: %08x\n", err);
195
  aosThdMSleep(100);
196
  /* apalI2CMasterReceive(dev.vl53l1x.i2cd,  dev.vl53l1x.addr, testBuf, 4, 10); */
197
  /* apalI2CMasterTransmit(dev.vl53l1x.i2cd, dev.vl53l1x.addr, data, 3, testBuf, 0, 10); */
198
  /* /\* VL53L1_RdByte(&dev, VL53L1_IDENTIFICATION__MODEL_ID, &data); *\/ */
199
  chprintf(stream, "0x%02\n", stuff[0]);
200
  chprintf(stream, "0x%02\n", stuff[1]);
201
  chprintf(stream, "0x%02\n", data[0]);
202
  chprintf(stream, "0x%02\n", data[1]);
203
  for(int i = 0; i < 49 ; i++){
204
    chprintf(stream, "0x%02 ", testBuf[i]);
90
  {
91
    chprintf(stream, "Read device info...\n");
92
    VL53L1_DeviceInfo_t device_info;
93
    error = VL53L1_GetDeviceInfo(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x, &device_info);
94
    if (error == VL53L1_ERROR_NONE) {
95
      chprintf(stream, "\tname:         %s\n", device_info.Name);
96
      chprintf(stream, "\ttype:         %s\n", device_info.Type);
97
      chprintf(stream, "\tproduct id:   %s\n", device_info.ProductId);
98
      chprintf(stream, "\tproduct tpye: %u\n", device_info.ProductType);
99
      chprintf(stream, "\trevision:     %u.%u\n", device_info.ProductRevisionMajor, device_info.ProductRevisionMinor);
100
      aosTestPassed(stream, &result);
101
    } else {
102
      aosTestFailedMsg(stream, &result, "%d", error);
103
    }
205 104
  }
206
  chprintf(stream, "\n");
207

  
208
  /* VL53L1_WrByte(&dev, 0x0000, 0x00); */
209
  /* aosThdSSleep(2); */
210
  /* vl53l1_WrByte(&dev, 0x0000, 0x01); */
211

  
212

  
213
  aosTestPassed(stream, &result);
214

  
215

  
216
  return result;
217
}
218

  
219

  
220

  
221
/**
222
 * @brief   Test if I2C was initialized correctly.
223
 *
224
 * @param[in] stream  Stream for input/output.
225
 * @param[in] test    Test object.
226
 *
227
 * @return            Test result value.
228
 */
229
aos_testresult_t aosTestVL53L1Xi2cInit(BaseSequentialStream* stream, const aos_test_t* test)
230
{
231
//   aosDbgCheck(test->data != NULL && ((aos_test_leddata_t*)test->data)->led != NULL);
232

  
233
  // local variables
234
  aos_testresult_t result = {0,0};
235
  uint8_t byteData, sensorState=0;
236
  uint16_t wordData;
237
  uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right
238
  uint16_t Distance;
239
  uint16_t SignalRate;
240
  uint16_t AmbientRate;
241
  uint8_t RangeStatus;
242
  uint8_t dataReady;
243
  int32_t status;
244
    chprintf(stream, "Hello World!\n");
245
//   aosTestResultInit(&result);
246

  
247
  VL53L1_Dev_t dev;
248
  dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x);
249
  // status = VL53L1_RdByte(&dev, 0x010F, &byteData);
250
  // printf("VL53L1X Model_ID: %X\n", byteData);
251
  // status = VL53L1_RdByte(&dev, 0x0110, &byteData);
252
  // printf("VL53L1X Module_Type: %X\n", byteData);
253
  // status = VL53L1_RdWord(&dev, 0x010F, &wordData);
254
  // printf("VL53L1X: %X\n", wordData);
255
  uint8_t testBuf[2] = {0};
256
  // Reste device
257
  printf("Resetting device! \n");
258
  VL53L1_WrByte(&dev, 0x0000, 0x00);
259
  aosThdSSleep(2);
260
  VL53L1_WrByte(&dev, 0x0000, 0x01);
261

  
262

  
263
  aosTestPassed(stream, &result);
264 105

  
265 106
  return result;
266 107
}
test/periphery-lld/VL53L1X_v1/aos_test_VL53L1X.h
21 21

  
22 22
#include <amiroos.h>
23 23

  
24

  
25 24
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
26 25

  
27 26
#include <alld_VL53L1X.h>
......
51 50
   */
52 51
  VL53L1XDriver* vl53l1x;
53 52

  
54
} aos_test_vl53l1x_bus;
53
} aos_test_vl53l1xdata_t;
55 54

  
56 55

  
57 56
/******************************************************************************/
......
66 65
extern "C" {
67 66
#endif /* defined(__cplusplus) */
68 67
  aos_testresult_t aosTestVL53L1XFunc(BaseSequentialStream* stream, const aos_test_t* test);
69
  aos_testresult_t aosTestVL53L1Xi2cInit(BaseSequentialStream* stream, const aos_test_t* test);
70 68
#if defined(__cplusplus)
71 69
}
72 70
#endif /* defined(__cplusplus) */

Also available in: Unified diff