Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-L476RG / module.h @ e375d633

History | View | Annotate | Download (8.731 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 33de2690 Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true)
33
#include <math.h>
34
#endif /* BOARD_MPU6050_CONNECTED == true */
35
36 27d0378b Simon Welzel
/*===========================================================================*/
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 8543d0d9 Thomas Schöpping
 * @brief   Serial driver of the programmer interface.
54 27d0378b Simon Welzel
 */
55 8543d0d9 Thomas Schöpping
#define MODULE_HAL_PROGIF                       SD2
56 27d0378b Simon Welzel
57
/**
58 8543d0d9 Thomas Schöpping
 * @brief   Configuration for the programmer serial interface driver.
59 27d0378b Simon Welzel
 */
60 8543d0d9 Thomas Schöpping
extern SerialConfig moduleHalProgIfConfig;
61 27d0378b Simon Welzel
62
/**
63
 * @brief   Real-Time Clock driver.
64
 */
65
#define MODULE_HAL_RTC                          RTCD1
66
67 126ace3c Thomas Schöpping
/**
68 db6bd9f8 Thomas Schöpping
 * @brief   Default I2C interface for the NUCLEO I/O.
69 126ace3c Thomas Schöpping
 */
70 db6bd9f8 Thomas Schöpping
#define MODULE_HAL_I2C                          I2CD1
71 126ace3c Thomas Schöpping
72
/**
73 db6bd9f8 Thomas Schöpping
 * @brief   Configuration for the I2C driver #1.
74 126ace3c Thomas Schöpping
 */
75 db6bd9f8 Thomas Schöpping
extern I2CConfig moduleHalI2cConfig;
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 db6bd9f8 Thomas Schöpping
  /* I2C */                                                                   \
151
  uint32_t i2c_freq = 1000000; /* maximum I2C frequency supported for this MCU */ \
152
  MODULE_INIT_PERIPHERY_IF_MPU6050(i2c_freq);                                 \
153
  if (i2c_freq == 100000) /* standard-mode @ 100 kHz */ {                     \
154
    moduleHalI2cConfig.timingr = 0x10909CEC; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
155
  } else if (i2c_freq == 400000) /* fast-mode @ 400 kHz */ {                  \
156
    moduleHalI2cConfig.timingr = 0x00702991; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
157
  } else if (i2c_freq == 1000000) /* fast-mode-plus @ 10000 kHz */ {          \
158
    moduleHalI2cConfig.timingr = 0x00300F33; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
159
  } else {                                                                    \
160
    aosDbgAssertMsg(false, "I2C frequency not supported");                    \
161
  }                                                                           \
162
  i2cStart(&MODULE_HAL_I2C, &moduleHalI2cConfig);                             \
163 8543d0d9 Thomas Schöpping
}
164 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true)
165 db6bd9f8 Thomas Schöpping
  #define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {freq = (MPU6050_LLD_I2C_MAXFREQUENCY < freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : freq;}
166
#else
167
  #define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {}
168
#endif
169 27d0378b Simon Welzel
170
/**
171 8543d0d9 Thomas Schöpping
 * @brief   Periphery communication interface deinitialization hook.
172 27d0378b Simon Welzel
 */
173 4c72a54c Thomas Schöpping
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
174 db6bd9f8 Thomas Schöpping
  /* I2C */                                                                   \
175
  i2cStop(&MODULE_HAL_I2C);                                                   \
176 cda14729 Thomas Schöpping
  /* don't stop the serial driver so messages can still be printed */         \
177 8543d0d9 Thomas Schöpping
}
178 27d0378b Simon Welzel
179
/**
180 8543d0d9 Thomas Schöpping
 * @brief   HOOK to toggle the LEDs when the user button is pressed.
181 27d0378b Simon Welzel
 */
182 cda14729 Thomas Schöpping
#define MODULE_MAIN_LOOP_GPIOEVENT(eventflags) {                              \
183
  if (eventflags & MODULE_OS_GPIOEVENTFLAG_USERBUTTON) {                      \
184 4c72a54c Thomas Schöpping
    button_lld_state_t buttonstate;                                           \
185
    button_lld_get(&moduleLldUserButton, &buttonstate);                       \
186
    led_lld_set(&moduleLldLed, (buttonstate == BUTTON_LLD_STATE_PRESSED) ? LED_LLD_STATE_ON : LED_LLD_STATE_OFF); \
187 8543d0d9 Thomas Schöpping
  }                                                                           \
188
}
189 27d0378b Simon Welzel
190
/** @} */
191
192
/*===========================================================================*/
193
/**
194 8543d0d9 Thomas Schöpping
 * @name Startup Shutdown Synchronization Protocol (SSSP)
195 27d0378b Simon Welzel
 * @{
196
 */
197
/*===========================================================================*/
198
199 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
200 c53ef0b1 Thomas Schöpping
  #error "SSSP is not supported on this module."
201 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
202
203 8543d0d9 Thomas Schöpping
/** @} */
204 27d0378b Simon Welzel
205 8543d0d9 Thomas Schöpping
/*===========================================================================*/
206 27d0378b Simon Welzel
/**
207 8543d0d9 Thomas Schöpping
 * @name Low-level drivers
208
 * @{
209 27d0378b Simon Welzel
 */
210 8543d0d9 Thomas Schöpping
/*===========================================================================*/
211 4c72a54c Thomas Schöpping
#include <alld_LED.h>
212
#include <alld_button.h>
213 27d0378b Simon Welzel
214 4c72a54c Thomas Schöpping
/**
215
 * @brief   LED driver.
216
 */
217
extern LEDDriver moduleLldLed;
218
219
/**
220
 * @brief   Button driver.
221
 */
222
extern ButtonDriver moduleLldUserButton;
223
224
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
225 126ace3c Thomas Schöpping
226
#include <alld_MPU6050.h>
227
228
/**
229
 * @brief   Accelerometer (MPU6050) driver.
230
 */
231
extern MPU6050Driver moduleLldMpu6050;
232
233 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
234 126ace3c Thomas Schöpping
235 8543d0d9 Thomas Schöpping
/** @} */
236 1678f270 Simon Welzel
237 8543d0d9 Thomas Schöpping
/*===========================================================================*/
238 1678f270 Simon Welzel
/**
239 4c72a54c Thomas Schöpping
 * @name Tests
240 8543d0d9 Thomas Schöpping
 * @{
241 1678f270 Simon Welzel
 */
242 8543d0d9 Thomas Schöpping
/*===========================================================================*/
243
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
244 1678f270 Simon Welzel
245 4c72a54c Thomas Schöpping
/**
246
 * @brief   LED test command.
247
 */
248
extern aos_shellcommand_t moduleTestLedShellCmd;
249
250
/**
251
 * @brief   User button test command.
252
 */
253
extern aos_shellcommand_t moduleTestButtonShellCmd;
254 126ace3c Thomas Schöpping
255 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
256 126ace3c Thomas Schöpping
257
/**
258 4c72a54c Thomas Schöpping
 * @brief   MPU6050 (Accelerometer & Gyroscope) test command.
259 126ace3c Thomas Schöpping
 */
260 4c72a54c Thomas Schöpping
extern aos_shellcommand_t moduleTestMpu6050ShellCmd;
261 126ace3c Thomas Schöpping
262 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
263
264
/**
265
 * @brief   Entire module test command.
266
 */
267
extern aos_shellcommand_t moduleTestAllShellCmd;
268 126ace3c Thomas Schöpping
269 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
270 8543d0d9 Thomas Schöpping
271
/** @} */
272
273 6ff06bbf Thomas Schöpping
#endif /* AMIROOS_MODULE_H */
274 27d0378b Simon Welzel
275
/** @} */