Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-L476RG / module.h @ 7de0cc90

History | View | Annotate | Download (9.04 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 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
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 7de0cc90 Thomas Schöpping
#else /* defined(AMIROLLD_CFG_MPU6050) */
141 126ace3c Thomas Schöpping
  #define MODULE_INIT_TEST_MPU6050() {}
142 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_MPU6050) */
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 97017dbb Thomas Schöpping
    chSysLock();                                                              \
173
    palSetPadMode(GPIOC, GPIOC_ARD_A4, PAL_MODE_ALTERNATE(4));                \
174
    palSetPadMode(GPIOC, GPIOC_ARD_A5, PAL_MODE_ALTERNATE(4));                \
175
    chSysUnlock();                                                            \
176 126ace3c Thomas Schöpping
    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
177
  }
178 7de0cc90 Thomas Schöpping
#else /* defined(AMIROLLD_CFG_MPU6050) */
179 126ace3c Thomas Schöpping
  #define MODULE_INIT_PERIPHERY_COMM_MPU6050() {}
180 7de0cc90 Thomas Schöpping
#endif /* defined(AMIROLLD_CFG_MPU6050) */
181 27d0378b Simon Welzel
182
/**
183 8543d0d9 Thomas Schöpping
 * @brief   Periphery communication interface deinitialization hook.
184 27d0378b Simon Welzel
 */
185 8543d0d9 Thomas Schöpping
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
186
}
187 27d0378b Simon Welzel
188
/**
189 8543d0d9 Thomas Schöpping
 * @brief   HOOK to toggle the LEDs when the user button is pressed.
190 27d0378b Simon Welzel
 */
191 a0301104 Thomas Schöpping
#define MODULE_MAIN_LOOP_IO_EVENT(eventflags) {                               \
192 8543d0d9 Thomas Schöpping
  if (eventflags & MODULE_OS_IOEVENTFLAGS_USERBUTTON) {                       \
193
    apalControlGpioState_t buttonstate;                                       \
194
    apalControlGpioGet(&moduleGpioUserButton, &buttonstate);                  \
195
    apalControlGpioSet(&moduleGpioLed, buttonstate);                          \
196
  }                                                                           \
197
}
198 27d0378b Simon Welzel
199
/** @} */
200
201
/*===========================================================================*/
202
/**
203 8543d0d9 Thomas Schöpping
 * @name Startup Shutdown Synchronization Protocol (SSSP)
204 27d0378b Simon Welzel
 * @{
205
 */
206
/*===========================================================================*/
207
208 8543d0d9 Thomas Schöpping
/** @} */
209 27d0378b Simon Welzel
210 8543d0d9 Thomas Schöpping
/*===========================================================================*/
211 27d0378b Simon Welzel
/**
212 8543d0d9 Thomas Schöpping
 * @name Low-level drivers
213
 * @{
214 27d0378b Simon Welzel
 */
215 8543d0d9 Thomas Schöpping
/*===========================================================================*/
216 27d0378b Simon Welzel
217 126ace3c Thomas Schöpping
#if defined(AMIROLLD_CFG_MPU6050)
218
219
#include <alld_MPU6050.h>
220
221
/**
222
 * @brief   Accelerometer (MPU6050) driver.
223
 */
224
extern MPU6050Driver moduleLldMpu6050;
225
226
#endif /* defined(AMIROLLD_CFG_MPU6050) */
227
228 8543d0d9 Thomas Schöpping
/** @} */
229 1678f270 Simon Welzel
230 8543d0d9 Thomas Schöpping
/*===========================================================================*/
231 1678f270 Simon Welzel
/**
232 8543d0d9 Thomas Schöpping
 * @name Unit tests (UT)
233
 * @{
234 1678f270 Simon Welzel
 */
235 8543d0d9 Thomas Schöpping
/*===========================================================================*/
236
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
237 1678f270 Simon Welzel
238 126ace3c Thomas Schöpping
#if defined(AMIROLLD_CFG_MPU6050)
239
240
#include <ut_alld_MPU6050_v1.h>
241
242
/**
243
 * @brief   MPU6050 unit test object.
244
 */
245
extern aos_unittest_t moduleUtAlldMpu6050;
246
247
#endif /* defined(AMIROLLD_CFG_MPU6050) */
248
249 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
250 8543d0d9 Thomas Schöpping
251
/** @} */
252
253 6ff06bbf Thomas Schöpping
#endif /* AMIROOS_MODULE_H */
254 27d0378b Simon Welzel
255
/** @} */