Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-L476RG / module.h @ 56dc4779

History | View | Annotate | Download (9.84 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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
/*===========================================================================*/
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
 * @brief   Serial driver of the programmer interface.
50
 */
51
#define MODULE_HAL_PROGIF                       SD2
52

    
53
/**
54
 * @brief   Configuration for the programmer serial interface driver.
55
 */
56
extern SerialConfig moduleHalProgIfConfig;
57

    
58
/**
59
 * @brief   Real-Time Clock driver.
60
 */
61
#define MODULE_HAL_RTC                          RTCD1
62

    
63
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
64

    
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
#endif /* (BOARD_MPU6050_CONNECTED == true) */
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
/** @} */
97

    
98
/*===========================================================================*/
99
/**
100
 * @name AMiRo-OS core configurations
101
 * @{
102
 */
103
/*===========================================================================*/
104

    
105
/**
106
 * @brief   Event flag to be set on a USER_BUTTON interrupt.
107
 */
108
#define MODULE_OS_IOEVENTFLAGS_USERBUTTON       AOS_IOEVENT_FLAG(PAL_PAD(LINE_BUTTON))
109

    
110
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
111
/**
112
 * @brief   Shell prompt text.
113
 */
114
extern ROMCONST char* moduleShellPrompt;
115
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
116

    
117
/**
118
 * @brief   Interrupt initialization macro.
119
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
120
 */
121
#define MODULE_INIT_INTERRUPTS() {                                            \
122
  /* user button */                                                           \
123
  palSetLineCallback(moduleGpioUserButton.gpio->line, aosSysGetStdExtiCallback(), &moduleGpioUserButton.gpio->line);  \
124
  palEnableLineEvent(moduleGpioUserButton.gpio->line, APAL2CH_EDGE(moduleGpioUserButton.meta.edge));                  \
125
}
126

    
127
/**
128
 * @brief   Test initialization hook.
129
 */
130
#define MODULE_INIT_TESTS() {                                                 \
131
  /* initialize tests and add to shell */                                     \
132
  aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd);                     \
133
  aosShellAddCommand(&aos.shell, &moduleTestButtonShellCmd);                  \
134
  MODULE_INIT_TEST_MPU6050();                                                 \
135
  aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd);                     \
136
}
137
#if (BOARD_MPU6050_CONNECTED == true)
138
  #define MODULE_INIT_TEST_MPU6050() {                                        \
139
    /* add unit-test shell commands */                                        \
140
    aosShellAddCommand(&aos.shell, &moduleTestMpu6050ShellCmd);               \
141
  }
142
#else /* (BOARD_MPU6050_CONNECTED == true) */
143
  #define MODULE_INIT_TEST_MPU6050() {}
144
#endif /* (BOARD_MPU6050_CONNECTED == true) */
145

    
146
/**
147
 * @brief   Periphery communication interfaces initialization hook.
148
 */
149
#define MODULE_INIT_PERIPHERY_IF() {                                          \
150
  /* serial driver */                                                         \
151
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
152
  /* MPU6050 demo */                                                          \
153
  MODULE_INIT_PERIPHERY_IF_MPU6050();                                         \
154
}
155
#if (BOARD_MPU6050_CONNECTED == true)
156
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {                                \
157
    /* maximum I2C frequency is 1MHz for this MCU */                          \
158
    uint32_t i2c3_freq = 1000000;                                             \
159
    /* find minimum amon all devices connected to this bus */                 \
160
    i2c3_freq = (MPU6050_LLD_I2C_MAXFREQUENCY < i2c3_freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : i2c3_freq;  \
161
    /* calculate PRESC (prescaler):                                           \
162
     *   target is 1/(I2CXCLK * (PRESC + 1)) = 125ns                          \
163
     */                                                                       \
164
    moduleHalI2c3Config.timingr = ((uint8_t)((0.000000125f * STM32_I2C3CLK) - 1)) << I2C_TIMINGR_PRESC_Pos; \
165
    /* SCL shall be low half of the time. */                                  \
166
    moduleHalI2c3Config.timingr |= ((uint8_t)((1.f / i2c3_freq / 2 / 0.000000125f) - 1)) << I2C_TIMINGR_SCLL_Pos; \
167
    /* SCL shall be high half the time of low or slightly longer. */          \
168
    moduleHalI2c3Config.timingr |= (uint8_t)(ceilf(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) / 2.f)) << I2C_TIMINGR_SCLH_Pos;  \
169
    /* SDA shall be delayed 1/10 of SCL low, or shorter */                    \
170
    moduleHalI2c3Config.timingr |= (uint8_t)(((moduleHalI2c3Config.timingr & I2C_TIMINGR_SCLL_Msk) >> I2C_TIMINGR_SCLL_Pos) * 0.1f) << I2C_TIMINGR_SDADEL_Pos;  \
171
    /* SCL shall be delyed twice as long as SDA, but longer than 0. */        \
172
    moduleHalI2c3Config.timingr |= ((((moduleHalI2c3Config.timingr & I2C_TIMINGR_SDADEL_Msk) >> I2C_TIMINGR_SDADEL_Pos) * 2) + 1) << I2C_TIMINGR_SCLDEL_Pos;  \
173
    /* now we can start the I2C driver */                                     \
174
    chSysLock();                                                              \
175
    palSetLineMode(LINE_ARD_A4, PAL_MODE_ALTERNATE(4));                       \
176
    palSetLineMode(LINE_ARD_A5, PAL_MODE_ALTERNATE(4));                       \
177
    chSysUnlock();                                                            \
178
    i2cStart(&MODULE_HAL_I2C3, &moduleHalI2c3Config);                         \
179
  }
180
#else /* (BOARD_MPU6050_CONNECTED == true) */
181
  #define MODULE_INIT_PERIPHERY_IF_MPU6050() {}
182
#endif /* (BOARD_MPU6050_CONNECTED == true) */
183

    
184
/**
185
 * @brief   Periphery communication interface deinitialization hook.
186
 */
187
#define MODULE_SHUTDOWN_PERIPHERY_IF() {                                      \
188
}
189

    
190
/**
191
 * @brief   HOOK to toggle the LEDs when the user button is pressed.
192
 */
193
#define MODULE_MAIN_LOOP_IO_EVENT(eventflags) {                               \
194
  if (eventflags & MODULE_OS_IOEVENTFLAGS_USERBUTTON) {                       \
195
    button_lld_state_t buttonstate;                                           \
196
    button_lld_get(&moduleLldUserButton, &buttonstate);                       \
197
    led_lld_set(&moduleLldLed, (buttonstate == BUTTON_LLD_STATE_PRESSED) ? LED_LLD_STATE_ON : LED_LLD_STATE_OFF); \
198
  }                                                                           \
199
}
200

    
201
/** @} */
202

    
203
/*===========================================================================*/
204
/**
205
 * @name Startup Shutdown Synchronization Protocol (SSSP)
206
 * @{
207
 */
208
/*===========================================================================*/
209

    
210
/** @} */
211

    
212
/*===========================================================================*/
213
/**
214
 * @name Low-level drivers
215
 * @{
216
 */
217
/*===========================================================================*/
218
#include <alld_LED.h>
219
#include <alld_button.h>
220

    
221
/**
222
 * @brief   LED driver.
223
 */
224
extern LEDDriver moduleLldLed;
225

    
226
/**
227
 * @brief   Button driver.
228
 */
229
extern ButtonDriver moduleLldUserButton;
230

    
231
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
232

    
233
#include <alld_MPU6050.h>
234

    
235
/**
236
 * @brief   Accelerometer (MPU6050) driver.
237
 */
238
extern MPU6050Driver moduleLldMpu6050;
239

    
240
#endif /* (BOARD_MPU6050_CONNECTED == true) */
241

    
242
/** @} */
243

    
244
/*===========================================================================*/
245
/**
246
 * @name Tests
247
 * @{
248
 */
249
/*===========================================================================*/
250
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
251

    
252
/**
253
 * @brief   LED test command.
254
 */
255
extern aos_shellcommand_t moduleTestLedShellCmd;
256

    
257
/**
258
 * @brief   User button test command.
259
 */
260
extern aos_shellcommand_t moduleTestButtonShellCmd;
261

    
262
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
263

    
264
/**
265
 * @brief   MPU6050 (Accelerometer & Gyroscope) test command.
266
 */
267
extern aos_shellcommand_t moduleTestMpu6050ShellCmd;
268

    
269
#endif /* (BOARD_MPU6050_CONNECTED == true) */
270

    
271
/**
272
 * @brief   Entire module test command.
273
 */
274
extern aos_shellcommand_t moduleTestAllShellCmd;
275

    
276
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
277

    
278
/** @} */
279

    
280
#endif /* AMIROOS_MODULE_H */
281

    
282
/** @} */