amiro-os / modules / NUCLEO-L476RG / module.h @ ded1ded7
History | View | Annotate | Download (13 KB)
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 |
* @file
|
21 |
* @brief Structures and constant for the NUCLEO-L476RG module.
|
22 |
*
|
23 |
* @addtogroup NUCLEO-L476RG_module
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef AMIROOS_MODULE_H
|
28 |
#define AMIROOS_MODULE_H
|
29 |
|
30 |
#include <amiroos.h> |
31 |
|
32 |
#if (BOARD_MPU6050_CONNECTED == true) |
33 |
#include <math.h> |
34 |
#endif /* BOARD_MPU6050_CONNECTED == true */ |
35 |
|
36 |
/*===========================================================================*/
|
37 |
/**
|
38 |
* @name Module specific functions
|
39 |
* @{
|
40 |
*/
|
41 |
/*===========================================================================*/
|
42 |
|
43 |
/** @} */
|
44 |
|
45 |
/*===========================================================================*/
|
46 |
/**
|
47 |
* @name ChibiOS/HAL configuration
|
48 |
* @{
|
49 |
*/
|
50 |
/*===========================================================================*/
|
51 |
|
52 |
/**
|
53 |
* @brief Serial driver of the programmer interface.
|
54 |
*/
|
55 |
#define MODULE_HAL_PROGIF SD2
|
56 |
|
57 |
/**
|
58 |
* @brief Configuration for the programmer serial interface driver.
|
59 |
*/
|
60 |
extern SerialConfig moduleHalProgIfConfig;
|
61 |
|
62 |
/**
|
63 |
* @brief Real-Time Clock driver.
|
64 |
*/
|
65 |
#define MODULE_HAL_RTC RTCD1
|
66 |
|
67 |
/**
|
68 |
* @brief Default I2C interface for the NUCLEO I/O.
|
69 |
*/
|
70 |
#define MODULE_HAL_I2C I2CD1
|
71 |
|
72 |
/**
|
73 |
* @brief Configuration for the I2C driver #1.
|
74 |
*/
|
75 |
extern I2CConfig moduleHalI2cConfig;
|
76 |
|
77 |
/** @} */
|
78 |
|
79 |
/*===========================================================================*/
|
80 |
/**
|
81 |
* @name GPIO definitions
|
82 |
* @{
|
83 |
*/
|
84 |
/*===========================================================================*/
|
85 |
|
86 |
/**
|
87 |
* @brief LED output signal GPIO.
|
88 |
*/
|
89 |
extern ROMCONST apalControlGpio_t moduleGpioLed;
|
90 |
|
91 |
/**
|
92 |
* @brief User button input signal.
|
93 |
*/
|
94 |
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
|
95 |
|
96 |
#if (BOARD_VL53L1X_CONNECTED == true) |
97 |
|
98 |
/**
|
99 |
* @brief VL53L1X interrupt signal (GPIO1).
|
100 |
*/
|
101 |
extern ROMCONST apalControlGpio_t moduleGpioVl53l1xINT;
|
102 |
|
103 |
/**
|
104 |
* @brief VL53L1X XSHUT signal.
|
105 |
*/
|
106 |
extern ROMCONST apalControlGpio_t moduleGpioVl53l1xXSHUT;
|
107 |
|
108 |
#endif /* (BOARD_VL53L1X_CONNECTED == true) */ |
109 |
|
110 |
/** @} */
|
111 |
|
112 |
/*===========================================================================*/
|
113 |
/**
|
114 |
* @name AMiRo-OS core configurations
|
115 |
* @{
|
116 |
*/
|
117 |
/*===========================================================================*/
|
118 |
|
119 |
/**
|
120 |
* @brief Event flag to be set on a USER_BUTTON interrupt.
|
121 |
*/
|
122 |
#define MODULE_OS_GPIOEVENTFLAG_USERBUTTON AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_BUTTON))
|
123 |
|
124 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
125 |
/**
|
126 |
* @brief Shell prompt text.
|
127 |
*/
|
128 |
extern ROMCONST char* moduleShellPrompt; |
129 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
130 |
|
131 |
/**
|
132 |
* @brief Interrupt initialization macro.
|
133 |
*/
|
134 |
#define MODULE_INIT_INTERRUPTS() { \
|
135 |
/* user button */ \
|
136 |
palSetLineCallback(moduleGpioUserButton.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioUserButton.gpio->line); \ |
137 |
palEnableLineEvent(moduleGpioUserButton.gpio->line, APAL2CH_EDGE(moduleGpioUserButton.meta.edge)); \ |
138 |
MODULE_INIT_INTERRUPTS_VL53L1X(); \ |
139 |
} |
140 |
|
141 |
|
142 |
#if (BOARD_VL53L1X_CONNECTED == true) |
143 |
#define MODULE_INIT_INTERRUPTS_VL53L1X() { \
|
144 |
palSetLineCallback(moduleGpioVl53l1xINT.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioVl53l1xINT.gpio->line); \ |
145 |
palEnableLineEvent(moduleGpioVl53l1xINT.gpio->line, APAL2CH_EDGE(moduleGpioVl53l1xINT.meta.edge)); \ |
146 |
} |
147 |
#else /* (BOARD_VL53L1X_CONNECTED == true) */ |
148 |
#define MODULE_INIT_INTERRUPTS_VL53L1X() {}
|
149 |
#endif /* (BOARD_VL53L1X_CONNECTED == true) */ |
150 |
|
151 |
/**
|
152 |
* @brief Test initialization hook.
|
153 |
*/
|
154 |
#define MODULE_INIT_TESTS() { \
|
155 |
/* add test commands to shell */ \
|
156 |
aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd); \ |
157 |
aosShellAddCommand(&aos.shell, &moduleTestButtonShellCmd); \ |
158 |
MODULE_INIT_TEST_MPU6050(); \ |
159 |
MODULE_INIT_TEST_VL53L1X(); \ |
160 |
aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd); \ |
161 |
} |
162 |
#if (BOARD_MPU6050_CONNECTED == true) |
163 |
#define MODULE_INIT_TEST_MPU6050() { \
|
164 |
aosShellAddCommand(&aos.shell, &moduleTestMpu6050ShellCmd); \ |
165 |
} |
166 |
#else /* (BOARD_MPU6050_CONNECTED == true) */ |
167 |
#define MODULE_INIT_TEST_MPU6050() {}
|
168 |
#endif /* (BOARD_MPU6050_CONNECTED == true) */ |
169 |
|
170 |
#if (BOARD_VL53L1X_CONNECTED == true) |
171 |
#define MODULE_INIT_TEST_VL53L1X() { \
|
172 |
aosShellAddCommand(&aos.shell, &moduleTestVL53L1XShellCmd); \ |
173 |
} |
174 |
#else /* (BOARD_VL53L1X_CONNECTED == true) */ |
175 |
#define MODULE_INIT_TEST_VL53L1X() {}
|
176 |
#endif /* (BOARD_VL53L1X_CONNECTED == true) */ |
177 |
|
178 |
/**
|
179 |
* @brief Periphery communication interfaces initialization hook.
|
180 |
*/
|
181 |
#define MODULE_INIT_PERIPHERY_IF() { \
|
182 |
/* serial driver */ \
|
183 |
sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \ |
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); \ |
198 |
} |
199 |
|
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)); \ |
231 |
chSysUnlock(); \ |
232 |
} |
233 |
#else
|
234 |
#define MODULE_INIT_PERIPHERY_IF_VL53L1X(freq) {}
|
235 |
#endif
|
236 |
|
237 |
/**
|
238 |
* @brief Periphery communication interface deinitialization hook.
|
239 |
*/
|
240 |
#define MODULE_SHUTDOWN_PERIPHERY_IF() { \
|
241 |
/* I2C */ \
|
242 |
i2cStop(&MODULE_HAL_I2C); \ |
243 |
/* don't stop the serial driver so messages can still be printed */ \
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* @brief HOOK to toggle the LEDs when the user button is pressed.
|
248 |
*/
|
249 |
#define MODULE_MAIN_LOOP_GPIOEVENT(eventflags) { \
|
250 |
if (eventflags & MODULE_OS_GPIOEVENTFLAG_USERBUTTON) { \
|
251 |
button_lld_state_t buttonstate; \ |
252 |
button_lld_get(&moduleLldUserButton, &buttonstate); \ |
253 |
led_lld_set(&moduleLldLed, (buttonstate == BUTTON_LLD_STATE_PRESSED) ? LED_LLD_STATE_ON : LED_LLD_STATE_OFF); \ |
254 |
} \ |
255 |
} |
256 |
|
257 |
/** @} */
|
258 |
|
259 |
/*===========================================================================*/
|
260 |
/**
|
261 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
262 |
* @{
|
263 |
*/
|
264 |
/*===========================================================================*/
|
265 |
|
266 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
267 |
#error "SSSP is not supported on this module." |
268 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
269 |
|
270 |
/** @} */
|
271 |
|
272 |
/*===========================================================================*/
|
273 |
/**
|
274 |
* @name Low-level drivers
|
275 |
* @{
|
276 |
*/
|
277 |
/*===========================================================================*/
|
278 |
#include <alld_LED.h> |
279 |
#include <alld_button.h> |
280 |
|
281 |
/**
|
282 |
* @brief LED driver.
|
283 |
*/
|
284 |
extern LEDDriver moduleLldLed;
|
285 |
|
286 |
/**
|
287 |
* @brief Button driver.
|
288 |
*/
|
289 |
extern ButtonDriver moduleLldUserButton;
|
290 |
|
291 |
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__) |
292 |
|
293 |
#include <alld_MPU6050.h> |
294 |
|
295 |
/**
|
296 |
* @brief Accelerometer (MPU6050) driver.
|
297 |
*/
|
298 |
extern MPU6050Driver moduleLldMpu6050;
|
299 |
|
300 |
#endif /* (BOARD_MPU6050_CONNECTED == true) */ |
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 |
|
313 |
/** @} */
|
314 |
|
315 |
/*===========================================================================*/
|
316 |
/**
|
317 |
* @name Tests
|
318 |
* @{
|
319 |
*/
|
320 |
/*===========================================================================*/
|
321 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
322 |
|
323 |
/**
|
324 |
* @brief LED test command.
|
325 |
*/
|
326 |
extern aos_shellcommand_t moduleTestLedShellCmd;
|
327 |
|
328 |
/**
|
329 |
* @brief User button test command.
|
330 |
*/
|
331 |
extern aos_shellcommand_t moduleTestButtonShellCmd;
|
332 |
|
333 |
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__) |
334 |
|
335 |
/**
|
336 |
* @brief MPU6050 (Accelerometer & Gyroscope) test command.
|
337 |
*/
|
338 |
extern aos_shellcommand_t moduleTestMpu6050ShellCmd;
|
339 |
|
340 |
#endif /* (BOARD_MPU6050_CONNECTED == true) */ |
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 |
/**
|
352 |
* @brief Entire module test command.
|
353 |
*/
|
354 |
extern aos_shellcommand_t moduleTestAllShellCmd;
|
355 |
|
356 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
357 |
|
358 |
/** @} */
|
359 |
|
360 |
#endif /* AMIROOS_MODULE_H */ |
361 |
|
362 |
/** @} */
|