Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-L476RG / module.h @ 9506caa7

History | View | Annotate | Download (9.835 KB)

1 27d0378b Simon Welzel
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 96621a83 Thomas Schöpping
Copyright (C) 2016..2020  Thomas Schöpping et al.
4 27d0378b Simon Welzel

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 126ace3c Thomas Schöpping
 * @brief   Structures and constant for the NUCLEO-L476RG module.
22 27d0378b Simon Welzel
 *
23 126ace3c Thomas Schöpping
 * @addtogroup NUCLEO-L476RG_module
24 27d0378b Simon Welzel
 * @{
25
 */
26
27 6ff06bbf Thomas Schöpping
#ifndef AMIROOS_MODULE_H
28
#define AMIROOS_MODULE_H
29 27d0378b Simon Welzel
30 8543d0d9 Thomas Schöpping
#include <amiroos.h>
31
32 27d0378b Simon Welzel
/*===========================================================================*/
33
/**
34
 * @name Module specific functions
35
 * @{
36
 */
37
/*===========================================================================*/
38
39
/** @} */
40
41
/*===========================================================================*/
42
/**
43
 * @name ChibiOS/HAL configuration
44
 * @{
45
 */
46
/*===========================================================================*/
47
48
/**
49 8543d0d9 Thomas Schöpping
 * @brief   Serial driver of the programmer interface.
50 27d0378b Simon Welzel
 */
51 8543d0d9 Thomas Schöpping
#define MODULE_HAL_PROGIF                       SD2
52 27d0378b Simon Welzel
53
/**
54 8543d0d9 Thomas Schöpping
 * @brief   Configuration for the programmer serial interface driver.
55 27d0378b Simon Welzel
 */
56 8543d0d9 Thomas Schöpping
extern SerialConfig moduleHalProgIfConfig;
57 27d0378b Simon Welzel
58
/**
59
 * @brief   Real-Time Clock driver.
60
 */
61
#define MODULE_HAL_RTC                          RTCD1
62
63 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
64 126ace3c Thomas Schöpping
65
/**
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).
67
 */
68
#define MODULE_HAL_I2C3                         I2CD3
69
70
/**
71
 * @brief   Configuration for the I2C driver #3.
72
 */
73
extern I2CConfig moduleHalI2c3Config;
74
75 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
76 126ace3c Thomas Schöpping
77 27d0378b Simon Welzel
/** @} */
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 8543d0d9 Thomas Schöpping
 * @brief   User button input signal.
93 27d0378b Simon Welzel
 */
94 8543d0d9 Thomas Schöpping
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
95 27d0378b Simon Welzel
96 8543d0d9 Thomas Schöpping
/** @} */
97 27d0378b Simon Welzel
98 8543d0d9 Thomas Schöpping
/*===========================================================================*/
99 27d0378b Simon Welzel
/**
100 8543d0d9 Thomas Schöpping
 * @name AMiRo-OS core configurations
101
 * @{
102 27d0378b Simon Welzel
 */
103 8543d0d9 Thomas Schöpping
/*===========================================================================*/
104 27d0378b Simon Welzel
105
/**
106 8543d0d9 Thomas Schöpping
 * @brief   Event flag to be set on a USER_BUTTON interrupt.
107 27d0378b Simon Welzel
 */
108 cda14729 Thomas Schöpping
#define MODULE_OS_GPIOEVENTFLAG_USERBUTTON      AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_BUTTON))
109 27d0378b Simon Welzel
110 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
111 27d0378b Simon Welzel
/**
112 8543d0d9 Thomas Schöpping
 * @brief   Shell prompt text.
113 27d0378b Simon Welzel
 */
114 8543d0d9 Thomas Schöpping
extern ROMCONST char* moduleShellPrompt;
115 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
116 27d0378b Simon Welzel
117
/**
118 8543d0d9 Thomas Schöpping
 * @brief   Interrupt initialization macro.
119 27d0378b Simon Welzel
 */
120 8543d0d9 Thomas Schöpping
#define MODULE_INIT_INTERRUPTS() {                                            \
121
  /* user button */                                                           \
122 cda14729 Thomas Schöpping
  palSetLineCallback(moduleGpioUserButton.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioUserButton.gpio->line);  \
123 56dc4779 Thomas Schöpping
  palEnableLineEvent(moduleGpioUserButton.gpio->line, APAL2CH_EDGE(moduleGpioUserButton.meta.edge));                  \
124 8543d0d9 Thomas Schöpping
}
125 27d0378b Simon Welzel
126
/**
127 4c72a54c Thomas Schöpping
 * @brief   Test initialization hook.
128 27d0378b Simon Welzel
 */
129 8543d0d9 Thomas Schöpping
#define MODULE_INIT_TESTS() {                                                 \
130 cda14729 Thomas Schöpping
  /* add test commands to shell */                                            \
131 4c72a54c Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
132
  aosShellAddCommand(&aos.shell, &moduleTestButtonShellCmd);                  \
133 126ace3c Thomas Schöpping
  MODULE_INIT_TEST_MPU6050();                                                 \
134 4c72a54c Thomas Schöpping
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
135 8543d0d9 Thomas Schöpping
}
136 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true)
137 126ace3c Thomas Schöpping
  #define MODULE_INIT_TEST_MPU6050() {                                        \
138 4c72a54c Thomas Schöpping
    aosShellAddCommand(&aos.shell, &moduleTestMpu6050ShellCmd);               \
139 126ace3c Thomas Schöpping
  }
140 4c72a54c Thomas Schöpping
#else /* (BOARD_MPU6050_CONNECTED == true) */
141 126ace3c Thomas Schöpping
  #define MODULE_INIT_TEST_MPU6050() {}
142 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
143 27d0378b Simon Welzel
144
/**
145 8543d0d9 Thomas Schöpping
 * @brief   Periphery communication interfaces initialization hook.
146 27d0378b Simon Welzel
 */
147 4c72a54c Thomas Schöpping
#define MODULE_INIT_PERIPHERY_IF() {                                          \
148 8543d0d9 Thomas Schöpping
  /* serial driver */                                                         \
149
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
150 126ace3c Thomas Schöpping
  /* MPU6050 demo */                                                          \
151 4c72a54c Thomas Schöpping
  MODULE_INIT_PERIPHERY_IF_MPU6050();                                         \
152 8543d0d9 Thomas Schöpping
}
153 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true)
154
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {                                \
155 126ace3c Thomas Schöpping
    /* maximum I2C frequency is 1MHz for this MCU */                          \
156
    uint32_t i2c3_freq = 1000000;                                             \
157
    /* find minimum amon all devices connected to this bus */                 \
158
    i2c3_freq = (MPU6050_LLD_I2C_MAXFREQUENCY < i2c3_freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : i2c3_freq;  \
159
    /* calculate PRESC (prescaler):                                           \
160
     *   target is 1/(I2CXCLK * (PRESC + 1)) = 125ns                          \
161
     */                                                                       \
162
    moduleHalI2c3Config.timingr = ((uint8_t)((0.000000125f * STM32_I2C3CLK) - 1)) << I2C_TIMINGR_PRESC_Pos; \
163
    /* SCL shall be low half of the time. */                                  \
164
    moduleHalI2c3Config.timingr |= ((uint8_t)((1.f / i2c3_freq / 2 / 0.000000125f) - 1)) << I2C_TIMINGR_SCLL_Pos; \
165
    /* SCL shall be high half the time of low or slightly longer. */          \
166
    moduleHalI2c3Config.timingr |= (uint8_t)(ceilf(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) / 2.f)) << I2C_TIMINGR_SCLH_Pos;  \
167
    /* SDA shall be delayed 1/10 of SCL low, or shorter */                    \
168
    moduleHalI2c3Config.timingr |= (uint8_t)(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) * 0.1f) << I2C_TIMINGR_SDADEL_Pos;  \
169
    /* SCL shall be delyed twice as long as SDA, but longer than 0. */        \
170
    moduleHalI2c3Config.timingr |= ((((moduleHalI2c3Config.timingr & I2C_TIMINGR_SDADEL_Msk) >> I2C_TIMINGR_SDADEL_Pos) * 2) + 1) << I2C_TIMINGR_SCLDEL_Pos;  \
171
    /* now we can start the I2C driver */                                     \
172 97017dbb Thomas Schöpping
    chSysLock();                                                              \
173 4c72a54c Thomas Schöpping
    palSetLineMode(LINE_ARD_A4, PAL_MODE_ALTERNATE(4));                       \
174
    palSetLineMode(LINE_ARD_A5, PAL_MODE_ALTERNATE(4));                       \
175 97017dbb Thomas Schöpping
    chSysUnlock();                                                            \
176 126ace3c Thomas Schöpping
    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
177
  }
178 4c72a54c Thomas Schöpping
#else /* (BOARD_MPU6050_CONNECTED == true) */
179
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {}
180
#endif /* (BOARD_MPU6050_CONNECTED == true) */
181 27d0378b Simon Welzel
182
/**
183 8543d0d9 Thomas Schöpping
 * @brief   Periphery communication interface deinitialization hook.
184 27d0378b Simon Welzel
 */
185 4c72a54c Thomas Schöpping
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
186 cda14729 Thomas Schöpping
  /* don't stop the serial driver so messages can still be printed */         \
187 8543d0d9 Thomas Schöpping
}
188 27d0378b Simon Welzel
189
/**
190 8543d0d9 Thomas Schöpping
 * @brief   HOOK to toggle the LEDs when the user button is pressed.
191 27d0378b Simon Welzel
 */
192 cda14729 Thomas Schöpping
#define MODULE_MAIN_LOOP_GPIOEVENT(eventflags) {                              \
193
  if (eventflags & MODULE_OS_GPIOEVENTFLAG_USERBUTTON) {                      \
194 4c72a54c Thomas Schöpping
    button_lld_state_t buttonstate;                                           \
195
    button_lld_get(&moduleLldUserButton, &buttonstate);                       \
196
    led_lld_set(&moduleLldLed, (buttonstate == BUTTON_LLD_STATE_PRESSED) ? LED_LLD_STATE_ON : LED_LLD_STATE_OFF); \
197 8543d0d9 Thomas Schöpping
  }                                                                           \
198
}
199 27d0378b Simon Welzel
200
/** @} */
201
202
/*===========================================================================*/
203
/**
204 8543d0d9 Thomas Schöpping
 * @name Startup Shutdown Synchronization Protocol (SSSP)
205 27d0378b Simon Welzel
 * @{
206
 */
207
/*===========================================================================*/
208
209 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
210 c53ef0b1 Thomas Schöpping
  #error "SSSP is not supported on this module."
211 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
212
213 8543d0d9 Thomas Schöpping
/** @} */
214 27d0378b Simon Welzel
215 8543d0d9 Thomas Schöpping
/*===========================================================================*/
216 27d0378b Simon Welzel
/**
217 8543d0d9 Thomas Schöpping
 * @name Low-level drivers
218
 * @{
219 27d0378b Simon Welzel
 */
220 8543d0d9 Thomas Schöpping
/*===========================================================================*/
221 4c72a54c Thomas Schöpping
#include <alld_LED.h>
222
#include <alld_button.h>
223 27d0378b Simon Welzel
224 4c72a54c Thomas Schöpping
/**
225
 * @brief   LED driver.
226
 */
227
extern LEDDriver moduleLldLed;
228
229
/**
230
 * @brief   Button driver.
231
 */
232
extern ButtonDriver moduleLldUserButton;
233
234
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
235 126ace3c Thomas Schöpping
236
#include <alld_MPU6050.h>
237
238
/**
239
 * @brief   Accelerometer (MPU6050) driver.
240
 */
241
extern MPU6050Driver moduleLldMpu6050;
242
243 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
244 126ace3c Thomas Schöpping
245 8543d0d9 Thomas Schöpping
/** @} */
246 1678f270 Simon Welzel
247 8543d0d9 Thomas Schöpping
/*===========================================================================*/
248 1678f270 Simon Welzel
/**
249 4c72a54c Thomas Schöpping
 * @name Tests
250 8543d0d9 Thomas Schöpping
 * @{
251 1678f270 Simon Welzel
 */
252 8543d0d9 Thomas Schöpping
/*===========================================================================*/
253
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
254 1678f270 Simon Welzel
255 4c72a54c Thomas Schöpping
/**
256
 * @brief   LED test command.
257
 */
258
extern aos_shellcommand_t moduleTestLedShellCmd;
259
260
/**
261
 * @brief   User button test command.
262
 */
263
extern aos_shellcommand_t moduleTestButtonShellCmd;
264 126ace3c Thomas Schöpping
265 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
266 126ace3c Thomas Schöpping
267
/**
268 4c72a54c Thomas Schöpping
 * @brief   MPU6050 (Accelerometer & Gyroscope) test command.
269 126ace3c Thomas Schöpping
 */
270 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestMpu6050ShellCmd;
271 126ace3c Thomas Schöpping
272 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
273
274
/**
275
 * @brief   Entire module test command.
276
 */
277
extern aos_shellcommand_t moduleTestAllShellCmd;
278 126ace3c Thomas Schöpping
279 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
280 8543d0d9 Thomas Schöpping
281
/** @} */
282
283 6ff06bbf Thomas Schöpping
#endif /* AMIROOS_MODULE_H */
284 27d0378b Simon Welzel
285
/** @} */