Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-L476RG / module.c @ 849b383a

History | View | Annotate | Download (7.871 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 126ace3c Thomas Schöpping
#include <amiroos.h>
28 27d0378b Simon Welzel
29
/*===========================================================================*/
30
/**
31
 * @name Module specific functions
32
 * @{
33
 */
34
/*===========================================================================*/
35
36
/** @} */
37
38
/*===========================================================================*/
39
/**
40
 * @name ChibiOS/HAL configuration
41
 * @{
42
 */
43
/*===========================================================================*/
44
45
SerialConfig moduleHalProgIfConfig = {
46
  /* bit rate */ 115200,
47
  /* CR1      */ 0,
48
  /* CR1      */ 0,
49
  /* CR1      */ 0,
50
};
51
52 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true)
53 126ace3c Thomas Schöpping
54
I2CConfig moduleHalI2c3Config = {
55 4c72a54c Thomas Schöpping
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook
56 126ace3c Thomas Schöpping
  /* CR1        */ 0,
57
  /* CR2        */ 0,
58
};
59
60 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
61 126ace3c Thomas Schöpping
62 849b383a galberding
#if (BOARD_VL53L1X_CONNECTED == true)
63
64
I2CConfig moduleHalI2c3Config = {
65
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook
66
  /* CR1        */ 0,
67
  /* CR2        */ 0,
68
};
69
70
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
71
72 27d0378b Simon Welzel
/** @} */
73
74 8543d0d9 Thomas Schöpping
/*===========================================================================*/
75
/**
76
 * @name GPIO definitions
77
 * @{
78
 */
79
/*===========================================================================*/
80
81
/**
82 a0301104 Thomas Schöpping
 * @brief   LED output signal GPIO.
83 8543d0d9 Thomas Schöpping
 */
84
static apalGpio_t _gpioLed = {
85 3106e8cc Thomas Schöpping
  /* line */ LINE_LED_GREEN,
86 8543d0d9 Thomas Schöpping
};
87
ROMCONST apalControlGpio_t moduleGpioLed = {
88
  /* GPIO */ &_gpioLed,
89
  /* meta */ {
90
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
91
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
92
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
93
  },
94
};
95
96
/**
97
 * @brief   User button input signal GPIO.
98
 */
99
static apalGpio_t _gpioUserButton = {
100 3106e8cc Thomas Schöpping
  /* line */ LINE_BUTTON,
101 8543d0d9 Thomas Schöpping
};
102
ROMCONST apalControlGpio_t moduleGpioUserButton = {
103
  /* GPIO */ &_gpioUserButton,
104
  /* meta */ {
105
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
106 83e94d4b Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
107 8543d0d9 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
108
  },
109
};
110
111 849b383a galberding
112
static apalGpio_t _gpioVl53l1xINT = {
113
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN2),
114
};
115
ROMCONST apalControlGpio_t moduleGpioVl53l1xINT = {
116
  /* GPIO */ &_gpioVl53l1xINT,
117
  /* meta */ {
118
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
119
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
120
    /* interrupt edge */ APAL_GPIO_EDGE_FALLING,
121
  },
122
};
123
124
static apalGpio_t _gpioVl53l1xXSHUT = {
125
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN3),
126
};
127
ROMCONST apalControlGpio_t moduleGpioVl53l1xXSHUT = {
128
  /* GPIO */ &_gpioVl53l1xXSHUT,
129
  /* meta */ {
130
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
131
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
132
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
133
  },
134
};
135
136 8543d0d9 Thomas Schöpping
/** @} */
137 27d0378b Simon Welzel
138
/*===========================================================================*/
139
/**
140
 * @name AMiRo-OS core configurations
141
 * @{
142
 */
143
/*===========================================================================*/
144
145 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
146 a0301104 Thomas Schöpping
ROMCONST char* moduleShellPrompt = "NUCLEO-L476RG";
147 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
148 27d0378b Simon Welzel
149 8543d0d9 Thomas Schöpping
/** @} */
150 27d0378b Simon Welzel
151 8543d0d9 Thomas Schöpping
/*===========================================================================*/
152
/**
153
 * @name Startup Shutdown Synchronization Protocol (SSSP)
154
 * @{
155
 */
156
/*===========================================================================*/
157
158
/** @} */
159
160
/*===========================================================================*/
161
/**
162
 * @name Low-level drivers
163
 * @{
164
 */
165
/*===========================================================================*/
166
167 4c72a54c Thomas Schöpping
LEDDriver moduleLldLed = {
168
  /* LED enable Gpio */ &moduleGpioLed,
169
};
170
171
ButtonDriver moduleLldUserButton = {
172
  /* Button Gpio  */ &moduleGpioUserButton,
173
};
174
175 849b383a galberding
176
#if (BOARD_VL53L1X_CONNECTED == true)
177
VL53L1XDriver moduleLldVl53l1x = {
178
   /* I2C Driver       */ &MODULE_HAL_I2C3,
179
  /* I²C address      */ VL53L1X_LLD_I2C_ADDR_DEFAULT,
180
  /* GPIO 1:INT pin */ &moduleGpioVl53l1xINT,
181
   /* Xshut  */        &moduleGpioVl53l1xXSHUT,
182
};
183
184
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
185
186 4c72a54c Thomas Schöpping
#if (BOARD_MPU6050_CONNECTED == true)
187 126ace3c Thomas Schöpping
188
MPU6050Driver moduleLldMpu6050 = {
189
  /* I2C Driver       */ &MODULE_HAL_I2C3,
190
  /* I²C address      */ MPU6050_LLD_I2C_ADDR_FIXED,
191
};
192
193 849b383a galberding
194
195 4c72a54c Thomas Schöpping
#endif /* (BOARD_MPU6050_CONNECTED == true) */
196 126ace3c Thomas Schöpping
197 8543d0d9 Thomas Schöpping
/** @} */
198
199
/*===========================================================================*/
200
/**
201 4c72a54c Thomas Schöpping
 * @name Tests
202 8543d0d9 Thomas Schöpping
 * @{
203
 */
204
/*===========================================================================*/
205
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
206 1678f270 Simon Welzel
207 4c72a54c Thomas Schöpping
/*
208
 * LED
209
 */
210
#include <module_test_LED.h>
211
static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
212
{
213
  return moduleTestLedShellCb(stream, argc, argv, NULL);
214
}
215
AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:LED", _testLedShellCmdCb);
216
217
/*
218 849b383a galberding
 * LED
219
 */
220
#include <module_test_VL53L1X.h>
221
static int _testShellVL53L1XCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
222
{
223
  return moduleTestVL53L1XShellCb(stream, argc, argv, NULL);
224
}
225
AOS_SHELL_COMMAND(moduleTestVL53L1XShellCmd, "test:VL53L1X", _testShellVL53L1XCmdCb);
226
227
static int _testShellVL53L1XInitCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
228
{
229
  return moduleTestVL53L1XInitShellCb(stream, argc, argv, NULL);
230
}
231
AOS_SHELL_COMMAND(moduleTestVL53L1XInitShellCmd, "test:VL53L1X:INIT", _testShellVL53L1XInitCmdCb);
232
233
/*
234 4c72a54c Thomas Schöpping
 * User button
235
 */
236
#include <module_test_button.h>
237
static int _testButtonShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
238
{
239
  return moduleTestButtonShellCb(stream, argc, argv, NULL);
240
}
241
AOS_SHELL_COMMAND(moduleTestButtonShellCmd, "test:button", _testButtonShellCmdCb);
242
243
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
244
245
/*
246
 * MPU6050 (accelerometer & gyroscope)
247
 */
248
#include <module_test_MPU6050.h>
249
static int _testMpu6050ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
250
{
251
  return moduleTestMpu6050ShellCb(stream, argc, argv, NULL);
252
}
253
AOS_SHELL_COMMAND(moduleTestMpu6050ShellCmd, "test:IMU", _testMpu6050ShellCmdCb);
254
255
#endif /* (BOARD_MPU6050_CONNECTED == true) */
256 126ace3c Thomas Schöpping
257 4c72a54c Thomas Schöpping
/*
258
 * entire module
259
 */
260
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
261 126ace3c Thomas Schöpping
{
262
  (void)argc;
263
  (void)argv;
264
265 4c72a54c Thomas Schöpping
  int status = AOS_OK;
266
  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
267
  aos_testresult_t result_test = {0, 0};
268
  aos_testresult_t result_total = {0, 0};
269
270
  /* LED */
271
  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
272
  result_total = aosTestResultAdd(result_total, result_test);
273
274
  /* User button */
275
  status |= moduleTestButtonShellCb(stream, 0, targv, &result_test);
276
  result_total = aosTestResultAdd(result_total, result_test);
277
278
  /* MPU6050 (accelerometer & gyroscope) */
279
#if (BOARD_MPU6050_CONNECTED == true)
280
  status |= moduleTestMpu6050ShellCb(stream, 0, targv, &result_test);
281
  result_total = aosTestResultAdd(result_total, result_test);
282
#endif /* (BOARD_MPU6050_CONNECTED == true) */
283
284
  // print total result
285
  chprintf(stream, "\n");
286
  aosTestResultPrintSummary(stream, &result_total, "entire module");
287
288
  return status;
289
}
290
AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
291 126ace3c Thomas Schöpping
292 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
293 8543d0d9 Thomas Schöpping
294
/** @} */
295 27d0378b Simon Welzel
/** @} */