Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.871 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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
#include <amiroos.h>
28

    
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
#if (BOARD_MPU6050_CONNECTED == true)
53

    
54
I2CConfig moduleHalI2c3Config = {
55
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF_MPU6050() hook
56
  /* CR1        */ 0,
57
  /* CR2        */ 0,
58
};
59

    
60
#endif /* (BOARD_MPU6050_CONNECTED == true) */
61

    
62
#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
/** @} */
73

    
74
/*===========================================================================*/
75
/**
76
 * @name GPIO definitions
77
 * @{
78
 */
79
/*===========================================================================*/
80

    
81
/**
82
 * @brief   LED output signal GPIO.
83
 */
84
static apalGpio_t _gpioLed = {
85
  /* line */ LINE_LED_GREEN,
86
};
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
  /* line */ LINE_BUTTON,
101
};
102
ROMCONST apalControlGpio_t moduleGpioUserButton = {
103
  /* GPIO */ &_gpioUserButton,
104
  /* meta */ {
105
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
106
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
107
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
108
  },
109
};
110

    
111

    
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
/** @} */
137

    
138
/*===========================================================================*/
139
/**
140
 * @name AMiRo-OS core configurations
141
 * @{
142
 */
143
/*===========================================================================*/
144

    
145
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
146
ROMCONST char* moduleShellPrompt = "NUCLEO-L476RG";
147
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
148

    
149
/** @} */
150

    
151
/*===========================================================================*/
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
LEDDriver moduleLldLed = {
168
  /* LED enable Gpio */ &moduleGpioLed,
169
};
170

    
171
ButtonDriver moduleLldUserButton = {
172
  /* Button Gpio  */ &moduleGpioUserButton,
173
};
174

    
175

    
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
#if (BOARD_MPU6050_CONNECTED == true)
187

    
188
MPU6050Driver moduleLldMpu6050 = {
189
  /* I2C Driver       */ &MODULE_HAL_I2C3,
190
  /* I²C address      */ MPU6050_LLD_I2C_ADDR_FIXED,
191
};
192

    
193

    
194

    
195
#endif /* (BOARD_MPU6050_CONNECTED == true) */
196

    
197
/** @} */
198

    
199
/*===========================================================================*/
200
/**
201
 * @name Tests
202
 * @{
203
 */
204
/*===========================================================================*/
205
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
206

    
207
/*
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
 * 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
 * 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

    
257
/*
258
 * entire module
259
 */
260
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
261
{
262
  (void)argc;
263
  (void)argv;
264

    
265
  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

    
292
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
293

    
294
/** @} */
295
/** @} */