Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-L476RG / module.h @ 126ace3c

History | View | Annotate | Download (8.51 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
#include <math.h>
32

    
33
/*===========================================================================*/
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
 * @brief   Serial driver of the programmer interface.
51
 */
52
#define MODULE_HAL_PROGIF                       SD2
53

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

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

    
64
#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
/** @} */
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
 * @brief   User button input signal.
94
 */
95
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
96

    
97
/** @} */
98

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

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

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

    
118
/**
119
 * @brief   Interrupt initialization macro.
120
 * @note    SSSP related interrupt signals are already initialized in 'aos_system.c'.
121
 */
122
#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

    
128
/**
129
 * @brief   Unit test initialization hook.
130
 */
131
#define MODULE_INIT_TESTS() {                                                 \
132
  /* add unit-test shell commands */                                          \
133
  MODULE_INIT_TEST_MPU6050();                                                 \
134
}
135
#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

    
144
/**
145
 * @brief   Periphery communication interfaces initialization hook.
146
 */
147
#define MODULE_INIT_PERIPHERY_COMM() {                                        \
148
  /* serial driver */                                                         \
149
  sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig);                        \
150
  /* MPU6050 demo */                                                          \
151
  MODULE_INIT_PERIPHERY_COMM_MPU6050();                                       \
152
}
153
#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

    
178
/**
179
 * @brief   Periphery communication interface deinitialization hook.
180
 */
181
#define MODULE_SHUTDOWN_PERIPHERY_COMM() {                                    \
182
}
183

    
184
/**
185
 * @brief   HOOK to toggle the LEDs when the user button is pressed.
186
 */
187
#define MODULE_MAIN_LOOP_IO_EVENT(eventflags) {                               \
188
  if (eventflags & MODULE_OS_IOEVENTFLAGS_USERBUTTON) {                       \
189
    apalControlGpioState_t buttonstate;                                       \
190
    apalControlGpioGet(&moduleGpioUserButton, &buttonstate);                  \
191
    apalControlGpioSet(&moduleGpioLed, buttonstate);                          \
192
  }                                                                           \
193
}
194

    
195
/** @} */
196

    
197
/*===========================================================================*/
198
/**
199
 * @name Startup Shutdown Synchronization Protocol (SSSP)
200
 * @{
201
 */
202
/*===========================================================================*/
203

    
204
/** @} */
205

    
206
/*===========================================================================*/
207
/**
208
 * @name Low-level drivers
209
 * @{
210
 */
211
/*===========================================================================*/
212

    
213
#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
/** @} */
225

    
226
/*===========================================================================*/
227
/**
228
 * @name Unit tests (UT)
229
 * @{
230
 */
231
/*===========================================================================*/
232
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
233

    
234
#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
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
246

    
247
/** @} */
248

    
249
#endif /* AMIROOS_MODULE_H */
250

    
251
/** @} */