Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / NUCLEO-L476RG / module.c @ ded1ded7

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