amiro-os / modules / NUCLEO-L476RG / module.h @ 126ace3c
History | View | Annotate | Download (8.512 KB)
1 | 27d0378b | Simon Welzel | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | 8543d0d9 | Thomas Schöpping | Copyright (C) 2016..2019 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 | 126ace3c | Thomas Schöpping | #include <math.h> |
32 | 8543d0d9 | Thomas Schöpping | |
33 | 27d0378b | Simon Welzel | /*===========================================================================*/
|
34 | /**
|
||
35 | * @name Module specific functions
|
||
36 | * @{
|
||
37 | */
|
||
38 | /*===========================================================================*/
|
||
39 | |||
40 | /** @} */
|
||
41 | |||
42 | /*===========================================================================*/
|
||
43 | /**
|
||
44 | * @name ChibiOS/HAL configuration
|
||
45 | * @{
|
||
46 | */
|
||
47 | /*===========================================================================*/
|
||
48 | |||
49 | /**
|
||
50 | 8543d0d9 | Thomas Schöpping | * @brief Serial driver of the programmer interface.
|
51 | 27d0378b | Simon Welzel | */
|
52 | 8543d0d9 | Thomas Schöpping | #define MODULE_HAL_PROGIF SD2
|
53 | 27d0378b | Simon Welzel | |
54 | /**
|
||
55 | 8543d0d9 | Thomas Schöpping | * @brief Configuration for the programmer serial interface driver.
|
56 | 27d0378b | Simon Welzel | */
|
57 | 8543d0d9 | Thomas Schöpping | extern SerialConfig moduleHalProgIfConfig;
|
58 | 27d0378b | Simon Welzel | |
59 | /**
|
||
60 | * @brief Real-Time Clock driver.
|
||
61 | */
|
||
62 | #define MODULE_HAL_RTC RTCD1
|
||
63 | |||
64 | 126ace3c | Thomas Schöpping | #if defined(AMIROLLD_CFG_MPU6050)
|
65 | |||
66 | /**
|
||
67 | * @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 | */
|
||
69 | #define MODULE_HAL_I2C3 I2CD3
|
||
70 | |||
71 | /**
|
||
72 | * @brief Configuration for the I2C driver #3.
|
||
73 | */
|
||
74 | extern I2CConfig moduleHalI2c3Config;
|
||
75 | |||
76 | #endif /* defined(AMIROLLD_CFG_MPU6050) */ |
||
77 | |||
78 | 27d0378b | Simon Welzel | /** @} */
|
79 | |||
80 | /*===========================================================================*/
|
||
81 | /**
|
||
82 | * @name GPIO definitions
|
||
83 | * @{
|
||
84 | */
|
||
85 | /*===========================================================================*/
|
||
86 | |||
87 | /**
|
||
88 | * @brief LED output signal GPIO.
|
||
89 | */
|
||
90 | extern ROMCONST apalControlGpio_t moduleGpioLed;
|
||
91 | |||
92 | /**
|
||
93 | 8543d0d9 | Thomas Schöpping | * @brief User button input signal.
|
94 | 27d0378b | Simon Welzel | */
|
95 | 8543d0d9 | Thomas Schöpping | extern ROMCONST apalControlGpio_t moduleGpioUserButton;
|
96 | 27d0378b | Simon Welzel | |
97 | 8543d0d9 | Thomas Schöpping | /** @} */
|
98 | 27d0378b | Simon Welzel | |
99 | 8543d0d9 | Thomas Schöpping | /*===========================================================================*/
|
100 | 27d0378b | Simon Welzel | /**
|
101 | 8543d0d9 | Thomas Schöpping | * @name AMiRo-OS core configurations
|
102 | * @{
|
||
103 | 27d0378b | Simon Welzel | */
|
104 | 8543d0d9 | Thomas Schöpping | /*===========================================================================*/
|
105 | 27d0378b | Simon Welzel | |
106 | /**
|
||
107 | 8543d0d9 | Thomas Schöpping | * @brief Event flag to be set on a USER_BUTTON interrupt.
|
108 | 27d0378b | Simon Welzel | */
|
109 | 8543d0d9 | Thomas Schöpping | #define MODULE_OS_IOEVENTFLAGS_USERBUTTON AOS_IOEVENT_FLAG(GPIOC_BUTTON)
|
110 | 27d0378b | Simon Welzel | |
111 | 8543d0d9 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
112 | 27d0378b | Simon Welzel | /**
|
113 | 8543d0d9 | Thomas Schöpping | * @brief Shell prompt text.
|
114 | 27d0378b | Simon Welzel | */
|
115 | 8543d0d9 | Thomas Schöpping | extern ROMCONST char* moduleShellPrompt; |
116 | #endif
|
||
117 | 27d0378b | Simon Welzel | |
118 | /**
|
||
119 | 8543d0d9 | Thomas Schöpping | * @brief Interrupt initialization macro.
|
120 | * @note SSSP related interrupt signals are already initialized in 'aos_system.c'.
|
||
121 | 27d0378b | Simon Welzel | */
|
122 | 8543d0d9 | Thomas Schöpping | #define MODULE_INIT_INTERRUPTS() { \
|
123 | /* user button */ \
|
||
124 | palSetPadCallback(moduleGpioUserButton.gpio->port, moduleGpioUserButton.gpio->pad, _intCallback, &moduleGpioUserButton.gpio->pad); \ |
||
125 | palEnablePadEvent(moduleGpioUserButton.gpio->port, moduleGpioUserButton.gpio->pad, APAL2CH_EDGE(moduleGpioUserButton.meta.edge)); \ |
||
126 | } |
||
127 | 27d0378b | Simon Welzel | |
128 | /**
|
||
129 | 8543d0d9 | Thomas Schöpping | * @brief Unit test initialization hook.
|
130 | 27d0378b | Simon Welzel | */
|
131 | 8543d0d9 | Thomas Schöpping | #define MODULE_INIT_TESTS() { \
|
132 | /* add unit-test shell commands */ \
|
||
133 | 126ace3c | Thomas Schöpping | MODULE_INIT_TEST_MPU6050(); \ |
134 | 8543d0d9 | Thomas Schöpping | } |
135 | 126ace3c | Thomas Schöpping | #if defined(AMIROLLD_CFG_MPU6050)
|
136 | #define MODULE_INIT_TEST_MPU6050() { \
|
||
137 | /* add unit-test shell commands */ \
|
||
138 | aosShellAddCommand(&aos.shell, &moduleUtAlldMpu6050.shellcmd); \ |
||
139 | } |
||
140 | #else
|
||
141 | #define MODULE_INIT_TEST_MPU6050() {}
|
||
142 | #endif
|
||
143 | 27d0378b | Simon Welzel | |
144 | /**
|
||
145 | 8543d0d9 | Thomas Schöpping | * @brief Periphery communication interfaces initialization hook.
|
146 | 27d0378b | Simon Welzel | */
|
147 | 8543d0d9 | Thomas Schöpping | #define MODULE_INIT_PERIPHERY_COMM() { \
|
148 | /* serial driver */ \
|
||
149 | sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \ |
||
150 | 126ace3c | Thomas Schöpping | /* MPU6050 demo */ \
|
151 | MODULE_INIT_PERIPHERY_COMM_MPU6050(); \ |
||
152 | 8543d0d9 | Thomas Schöpping | } |
153 | 126ace3c | Thomas Schöpping | #if defined(AMIROLLD_CFG_MPU6050)
|
154 | #define MODULE_INIT_PERIPHERY_COMM_MPU6050() { \
|
||
155 | /* 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 | i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config); \ |
||
173 | } |
||
174 | #else
|
||
175 | #define MODULE_INIT_PERIPHERY_COMM_MPU6050() {}
|
||
176 | #endif
|
||
177 | 27d0378b | Simon Welzel | |
178 | /**
|
||
179 | 8543d0d9 | Thomas Schöpping | * @brief Periphery communication interface deinitialization hook.
|
180 | 27d0378b | Simon Welzel | */
|
181 | 8543d0d9 | Thomas Schöpping | #define MODULE_SHUTDOWN_PERIPHERY_COMM() { \
|
182 | } |
||
183 | 27d0378b | Simon Welzel | |
184 | /**
|
||
185 | 8543d0d9 | Thomas Schöpping | * @brief HOOK to toggle the LEDs when the user button is pressed.
|
186 | 27d0378b | Simon Welzel | */
|
187 | a0301104 | Thomas Schöpping | #define MODULE_MAIN_LOOP_IO_EVENT(eventflags) { \
|
188 | 8543d0d9 | Thomas Schöpping | if (eventflags & MODULE_OS_IOEVENTFLAGS_USERBUTTON) { \
|
189 | apalControlGpioState_t buttonstate; \ |
||
190 | apalControlGpioGet(&moduleGpioUserButton, &buttonstate); \ |
||
191 | apalControlGpioSet(&moduleGpioLed, buttonstate); \ |
||
192 | } \ |
||
193 | } |
||
194 | 27d0378b | Simon Welzel | |
195 | /** @} */
|
||
196 | |||
197 | /*===========================================================================*/
|
||
198 | /**
|
||
199 | 8543d0d9 | Thomas Schöpping | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
200 | 27d0378b | Simon Welzel | * @{
|
201 | */
|
||
202 | /*===========================================================================*/
|
||
203 | |||
204 | 8543d0d9 | Thomas Schöpping | /** @} */
|
205 | 27d0378b | Simon Welzel | |
206 | 8543d0d9 | Thomas Schöpping | /*===========================================================================*/
|
207 | 27d0378b | Simon Welzel | /**
|
208 | 8543d0d9 | Thomas Schöpping | * @name Low-level drivers
|
209 | * @{
|
||
210 | 27d0378b | Simon Welzel | */
|
211 | 8543d0d9 | Thomas Schöpping | /*===========================================================================*/
|
212 | 27d0378b | Simon Welzel | |
213 | 126ace3c | Thomas Schöpping | #if defined(AMIROLLD_CFG_MPU6050)
|
214 | |||
215 | #include <alld_MPU6050.h> |
||
216 | |||
217 | /**
|
||
218 | * @brief Accelerometer (MPU6050) driver.
|
||
219 | */
|
||
220 | extern MPU6050Driver moduleLldMpu6050;
|
||
221 | |||
222 | #endif /* defined(AMIROLLD_CFG_MPU6050) */ |
||
223 | |||
224 | 8543d0d9 | Thomas Schöpping | /** @} */
|
225 | 1678f270 | Simon Welzel | |
226 | 8543d0d9 | Thomas Schöpping | /*===========================================================================*/
|
227 | 1678f270 | Simon Welzel | /**
|
228 | 8543d0d9 | Thomas Schöpping | * @name Unit tests (UT)
|
229 | * @{
|
||
230 | 1678f270 | Simon Welzel | */
|
231 | 8543d0d9 | Thomas Schöpping | /*===========================================================================*/
|
232 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
233 | 1678f270 | Simon Welzel | |
234 | 126ace3c | Thomas Schöpping | #if defined(AMIROLLD_CFG_MPU6050)
|
235 | |||
236 | #include <ut_alld_MPU6050_v1.h> |
||
237 | |||
238 | /**
|
||
239 | * @brief MPU6050 unit test object.
|
||
240 | */
|
||
241 | extern aos_unittest_t moduleUtAlldMpu6050;
|
||
242 | |||
243 | #endif /* defined(AMIROLLD_CFG_MPU6050) */ |
||
244 | |||
245 | 8543d0d9 | Thomas Schöpping | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
246 | |||
247 | /** @} */
|
||
248 | |||
249 | 6ff06bbf | Thomas Schöpping | #endif /* AMIROOS_MODULE_H */ |
250 | 27d0378b | Simon Welzel | |
251 | /** @} */ |