Revision 849b383a

View differences:

modules/NUCLEO-L476RG/Makefile
144 144
include $(AMIROLLD)/drivers/LED/v1/alld_LED.mk
145 145
include $(AMIROLLD)/drivers/button/v1/alld_button.mk
146 146
include $(AMIROLLD)/drivers/MPU6050/v1/alld_MPU6050.mk
147
include $(AMIROLLD)/drivers/VL53L1X/v1/alld_VL53L1X.mk
147 148

  
148 149
# Module specific inclusion directories
149 150
MODULE_INC = $(MODULE_DIR)
......
156 157
include $(MODULE_DIR)/test/button/module_test_button.mk
157 158
include $(MODULE_DIR)/test/LED/module_test_LED.mk
158 159
include $(MODULE_DIR)/test/MPU6050/module_test_MPU6050.mk
160
include $(MODULE_DIR)/test/VL53L1X/module_test_VL53L1X.mk
161

  
159 162

  
160 163
# C warning options.
161 164
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
modules/NUCLEO-L476RG/board.h
64 64
 */
65 65
#define BOARD_MPU6050_CONNECTED     false
66 66

  
67
#define BOARD_VL53L1X_CONNECTED     true
68

  
67 69

  
68 70
/*
69 71
 * IO pins assignments.
modules/NUCLEO-L476RG/module.c
59 59

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

  
62
#if (BOARD_VL53L1X_CONNECTED == true)
63

  
64
I2CConfig moduleHalI2c3Config = {
65
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook
66
  /* CR1        */ 0,
67
  /* CR2        */ 0,
68
};
69

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

  
62 72
/** @} */
63 73

  
64 74
/*===========================================================================*/
......
98 108
  },
99 109
};
100 110

  
111

  
112
static apalGpio_t _gpioVl53l1xINT = {
113
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN2),
114
};
115
ROMCONST apalControlGpio_t moduleGpioVl53l1xINT = {
116
  /* GPIO */ &_gpioVl53l1xINT,
117
  /* meta */ {
118
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
119
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
120
    /* interrupt edge */ APAL_GPIO_EDGE_FALLING,
121
  },
122
};
123

  
124
static apalGpio_t _gpioVl53l1xXSHUT = {
125
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN3),
126
};
127
ROMCONST apalControlGpio_t moduleGpioVl53l1xXSHUT = {
128
  /* GPIO */ &_gpioVl53l1xXSHUT,
129
  /* meta */ {
130
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
131
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
132
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
133
  },
134
};
135

  
101 136
/** @} */
102 137

  
103 138
/*===========================================================================*/
......
137 172
  /* Button Gpio  */ &moduleGpioUserButton,
138 173
};
139 174

  
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

  
140 186
#if (BOARD_MPU6050_CONNECTED == true)
141 187

  
142 188
MPU6050Driver moduleLldMpu6050 = {
......
144 190
  /* I²C address      */ MPU6050_LLD_I2C_ADDR_FIXED,
145 191
};
146 192

  
193

  
194

  
147 195
#endif /* (BOARD_MPU6050_CONNECTED == true) */
148 196

  
149 197
/** @} */
......
167 215
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:LED", _testLedShellCmdCb);
168 216

  
169 217
/*
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
/*
170 234
 * User button
171 235
 */
172 236
#include <module_test_button.h>
modules/NUCLEO-L476RG/module.h
60 60
 */
61 61
#define MODULE_HAL_RTC                          RTCD1
62 62

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

  
65 65
/**
66 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).
......
72 72
 */
73 73
extern I2CConfig moduleHalI2c3Config;
74 74

  
75
#endif /* (BOARD_MPU6050_CONNECTED == true) */
75
#endif /* (BOARD_MPU6050_CONNECTED == true || BOARD_VL53L1X_CONNECTED == true) */
76 76

  
77 77
/** @} */
78 78

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

  
96 98
/** @} */
97 99

  
......
102 104
 */
103 105
/*===========================================================================*/
104 106

  
107
#include <math.h>
108

  
105 109
/**
106 110
 * @brief   Event flag to be set on a USER_BUTTON interrupt.
107 111
 */
......
121 125
  /* user button */                                                           \
122 126
  palSetLineCallback(moduleGpioUserButton.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioUserButton.gpio->line);  \
123 127
  palEnableLineEvent(moduleGpioUserButton.gpio->line, APAL2CH_EDGE(moduleGpioUserButton.meta.edge));                  \
128
  MODULE_INIT_INTERRUPTS_VL53L1X();                                           \
124 129
}
125 130

  
131

  
132
#if (BOARD_VL53L1X_CONNECTED == true)
133
  #define MODULE_INIT_INTERRUPTS_VL53L1X() {                                  \
134
    palSetLineCallback(moduleGpioVl53l1xINT.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioVl53l1xINT.gpio->line);  \
135
    palEnableLineEvent(moduleGpioVl53l1xINT.gpio->line, APAL2CH_EDGE(moduleGpioVl53l1xINT.meta.edge));                  \
136
  }
137
#else /* (BOARD_VL53L1X_CONNECTED == true) */
138
  #define MODULE_INIT_INTERRUPTS_VL53L1X() {}
139
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
140

  
126 141
/**
127 142
 * @brief   Test initialization hook.
128 143
 */
......
131 146
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
132 147
  aosShellAddCommand(&aos.shell, &moduleTestButtonShellCmd);                  \
133 148
  MODULE_INIT_TEST_MPU6050();                                                 \
149
  MODULE_INIT_TEST_VL53L1X();                                                 \
134 150
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
135 151
}
136 152
#if (BOARD_MPU6050_CONNECTED == true)
......
141 157
  #define MODULE_INIT_TEST_MPU6050() {}
142 158
#endif /* (BOARD_MPU6050_CONNECTED == true) */
143 159

  
160
#if (BOARD_VL53L1X_CONNECTED == true)
161
  #define MODULE_INIT_TEST_VL53L1X() {                                        \
162
    aosShellAddCommand(&aos.shell, &moduleTestVL53L1XShellCmd);               \
163
    aosShellAddCommand(&aos.shell, &moduleTestVL53L1XInitShellCmd);               \
164
  }
165
#else /* (BOARD_VL53L1X_CONNECTED == true) */
166
  #define MODULE_INIT_TEST_VL53L1X() {}
167
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
168

  
144 169
/**
145 170
 * @brief   Periphery communication interfaces initialization hook.
146 171
 */
......
149 174
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
150 175
  /* MPU6050 demo */                                                          \
151 176
  MODULE_INIT_PERIPHERY_IF_MPU6050();                                         \
177
  MODULE_INIT_PERIPHERY_IF_VL53L1X();                                         \
152 178
}
153 179
#if (BOARD_MPU6050_CONNECTED == true)
154 180
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {                                \
......
179 205
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {}
180 206
#endif /* (BOARD_MPU6050_CONNECTED == true) */
181 207

  
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));                       \
236
    chSysUnlock();                                                            \
237
    apalControlGpioSet(moduleLldVl53l1x.xshut, APAL_GPIO_OFF);                \
238
    /* now we can start the I2C driver */                                     \
239
    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
240
  }
241
#else /* (BOARD_VL53L1X_CONNECTED == true) */
242
  #define MODULE_INIT_PERIPHERY_IF_VL53L1X() {}
243
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
244

  
182 245
/**
183 246
 * @brief   Periphery communication interface deinitialization hook.
184 247
 */
......
226 289
 */
227 290
extern LEDDriver moduleLldLed;
228 291

  
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

  
229 300
/**
230 301
 * @brief   Button driver.
231 302
 */
......
258 329
extern aos_shellcommand_t moduleTestLedShellCmd;
259 330

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

  
337
/**
261 338
 * @brief   User button test command.
262 339
 */
263 340
extern aos_shellcommand_t moduleTestButtonShellCmd;
modules/NUCLEO-L476RG/test/VL53L1X/module_test_VL53L1X.c
1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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 <amiroos.h>
20

  
21
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
22

  
23
#include <module_test_VL53L1X.h>
24
#include <aos_test_VL53L1X.h>
25

  
26
/******************************************************************************/
27
/* LOCAL DEFINITIONS                                                          */
28
/******************************************************************************/
29

  
30
/******************************************************************************/
31
/* EXPORTED VARIABLES                                                         */
32
/******************************************************************************/
33

  
34
/******************************************************************************/
35
/* LOCAL TYPES                                                                */
36
/******************************************************************************/
37

  
38
/******************************************************************************/
39
/* LOCAL VARIABLES                                                            */
40
/******************************************************************************/
41

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

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

  
49
/******************************************************************************/
50
/* LOCAL FUNCTIONS                                                            */
51
/******************************************************************************/
52

  
53
/******************************************************************************/
54
/* EXPORTED FUNCTIONS                                                         */
55
/******************************************************************************/
56

  
57
int moduleTestVL53L1XShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result)
58
{
59
  (void)argc;
60
  (void)argv;
61

  
62

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

  
71
  return AOS_OK;
72
}
73

  
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
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
modules/NUCLEO-L476RG/test/VL53L1X/module_test_VL53L1X.h
1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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

  
20
#ifndef MODULE_TEST_VL53L1X_H
21
#define MODULE_TEST_VL53L1X_H
22

  
23
#include <amiroos.h>
24

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

  
27
/******************************************************************************/
28
/* CONSTANTS                                                                  */
29
/******************************************************************************/
30

  
31
/******************************************************************************/
32
/* SETTINGS                                                                   */
33
/******************************************************************************/
34

  
35
/******************************************************************************/
36
/* CHECKS                                                                     */
37
/******************************************************************************/
38

  
39
/******************************************************************************/
40
/* DATA STRUCTURES AND TYPES                                                  */
41
/******************************************************************************/
42

  
43
/******************************************************************************/
44
/* MACROS                                                                     */
45
/******************************************************************************/
46

  
47
/******************************************************************************/
48
/* EXTERN DECLARATIONS                                                        */
49
/******************************************************************************/
50

  
51
#if defined(__cplusplus)
52
extern "C" {
53
#endif /* defined(__cplusplus) */
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
#if defined(__cplusplus)
57
}
58
#endif /* defined(__cplusplus) */
59

  
60
/******************************************************************************/
61
/* INLINE FUNCTIONS                                                           */
62
/******************************************************************************/
63

  
64
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
65

  
66
#endif /* MODULE_TEST_VL53L1X_H */
67

  
modules/NUCLEO-L476RG/test/VL53L1X/module_test_VL53L1X.mk
1
################################################################################
2
# AMiRo-OS is an operating system designed for the Autonomous Mini Robot       #
3
# (AMiRo) platform.                                                            #
4
# Copyright (C) 2016..2020  Thomas Schöpping et al.                            #
5
#                                                                              #
6
# This program is free software: you can redistribute it and/or modify         #
7
# it under the terms of the GNU General Public License as published by         #
8
# the Free Software Foundation, either version 3 of the License, or            #
9
# (at your option) any later version.                                          #
10
#                                                                              #
11
# This program is distributed in the hope that it will be useful,              #
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
14
# GNU General Public License for more details.                                 #
15
#                                                                              #
16
# You should have received a copy of the GNU General Public License            #
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.        #
18
#                                                                              #
19
# This research/work was supported by the Cluster of Excellence Cognitive      #
20
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is   #
21
# funded by the German Research Foundation (DFG).                              #
22
################################################################################
23

  
24

  
25

  
26
# path to this directory
27
MODULE_TEST_VL53L1X_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
28

  
29
include $(AMIROOS_TEST_DIR)periphery-lld/VL53L1X_v1/aos_test_VL53L1X.mk
30
# include paths
31
MODULE_INC += $(MODULE_TEST_VL53L1X_DIR:/=)
32

  
33
# C source files
34
MODULE_CSRC += $(MODULE_TEST_VL53L1X_DIR)module_test_VL53L1X.c
35

  
test/periphery-lld/VL53L1X_v1/aos_test_VL53L1X.c
1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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 <amiroos.h>
20
#include <aos_test_VL53L1X.h>
21

  
22
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23

  
24
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27

  
28
/******************************************************************************/
29
/* EXPORTED VARIABLES                                                         */
30
/******************************************************************************/
31

  
32
/******************************************************************************/
33
/* LOCAL TYPES                                                                */
34
/******************************************************************************/
35

  
36
/******************************************************************************/
37
/* LOCAL VARIABLES                                                            */
38
/******************************************************************************/
39

  
40
/******************************************************************************/
41
/* LOCAL FUNCTIONS                                                            */
42
/******************************************************************************/
43

  
44
/******************************************************************************/
45
/* EXPORTED FUNCTIONS                                                         */
46
/*****************************************************************************
47
*/
48

  
49
/**
50
 * @brief   LED test function.
51
 *
52
 * @param[in] stream  Stream for input/output.
53
 * @param[in] test    Test object.
54
 *
55
 * @return            Test result value.
56
 */
57
aos_testresult_t aosTestVL53L1XFunc(BaseSequentialStream* stream, const aos_test_t* test)
58
{
59
//   aosDbgCheck(test->data != NULL && ((aos_test_leddata_t*)test->data)->led != NULL);
60

  
61
chprintf(stream, "Peter Wurst\n");
62

  
63
  // 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;
128
  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");
162
  }
163

  
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]);
205
  }
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

  
265
  return result;
266
}
267

  
268
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
test/periphery-lld/VL53L1X_v1/aos_test_VL53L1X.h
1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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
#ifndef AMIROOS_TEST_VL53L1X
20
#define AMIROOS_TEST_VL53L1X
21

  
22
#include <amiroos.h>
23

  
24

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

  
27
#include <alld_VL53L1X.h>
28

  
29
/******************************************************************************/
30
/* CONSTANTS                                                                  */
31
/******************************************************************************/
32

  
33
/******************************************************************************/
34
/* SETTINGS                                                                   */
35
/******************************************************************************/
36

  
37
/******************************************************************************/
38
/* CHECKS                                                                     */
39
/******************************************************************************/
40

  
41
/******************************************************************************/
42
/* DATA STRUCTURES AND TYPES                                                  */
43
/******************************************************************************/
44

  
45
/**
46
 * @brief   Custom data structure for the test.
47
 */
48
typedef struct {
49
  /**
50
   * @brief   Pointer to the driver to use.
51
   */
52
  VL53L1XDriver* vl53l1x;
53

  
54
} aos_test_vl53l1x_bus;
55

  
56

  
57
/******************************************************************************/
58
/* MACROS                                                                     */
59
/******************************************************************************/
60

  
61
/******************************************************************************/
62
/* EXTERN DECLARATIONS                                                        */
63
/******************************************************************************/
64

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

  
74
/******************************************************************************/
75
/* INLINE FUNCTIONS                                                           */
76
/******************************************************************************/
77

  
78
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
79

  
80
#endif /* AMIROOS_TEST_VL53L1X */
test/periphery-lld/VL53L1X_v1/aos_test_VL53L1X.mk
1
################################################################################
2
# AMiRo-OS is an operating system designed for the Autonomous Mini Robot       #
3
# (AMiRo) platform.                                                            #
4
# Copyright (C) 2016..2020  Thomas Schöpping et al.                            #
5
#                                                                              #
6
# This program is free software: you can redistribute it and/or modify         #
7
# it under the terms of the GNU General Public License as published by         #
8
# the Free Software Foundation, either version 3 of the License, or            #
9
# (at your option) any later version.                                          #
10
#                                                                              #
11
# This program is distributed in the hope that it will be useful,              #
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
14
# GNU General Public License for more details.                                 #
15
#                                                                              #
16
# You should have received a copy of the GNU General Public License            #
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.        #
18
#                                                                              #
19
# This research/work was supported by the Cluster of Excellence Cognitive      #
20
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is   #
21
# funded by the German Research Foundation (DFG).                              #
22
################################################################################
23

  
24

  
25

  
26
# path to this directory
27
AMIROOS_TEST_VL53L1X_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
28

  
29
# include path
30
AMIROOS_TEST_INC += $(AMIROOS_TEST_VL53L1X_DIR)
31

  
32
# C sources
33
AMIROOS_TEST_CSRC += $(AMIROOS_TEST_VL53L1X_DIR)aos_test_VL53L1X.c
34

  

Also available in: Unified diff