Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.88 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
I2CConfig moduleHalI2cConfig = {
53
  /* timing reg */ 0, // configured later in MODULE_INIT_PERIPHERY_IF hook
54
  /* CR1        */ 0,
55
  /* CR2        */ 0,
56
};
57

    
58
/** @} */
59

    
60
/*===========================================================================*/
61
/**
62
 * @name GPIO definitions
63
 * @{
64
 */
65
/*===========================================================================*/
66

    
67
/**
68
 * @brief   LED output signal GPIO.
69
 */
70
static apalGpio_t _gpioLed = {
71
  /* line */ LINE_LED_GREEN,
72
};
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
  /* line */ LINE_BUTTON,
87
};
88
ROMCONST apalControlGpio_t moduleGpioUserButton = {
89
  /* GPIO */ &_gpioUserButton,
90
  /* meta */ {
91
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
92
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
93
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
94
  },
95
};
96

    
97
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
98

    
99
/**
100
 * @brief   VL53L1X interrupt signal GPIO.
101
 */
102
static apalGpio_t _gpioVl53l1xINT = {
103
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN6),
104
};
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
/**
115
 * @brief   VL53L1X XSHUT signal GPIO.
116
 */
117
static apalGpio_t _gpioVl53l1xXSHUT = {
118
  /* line */ PAL_LINE(GPIOC, GPIOC_PIN5),
119
};
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
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
130

    
131
/** @} */
132

    
133
/*===========================================================================*/
134
/**
135
 * @name AMiRo-OS core configurations
136
 * @{
137
 */
138
/*===========================================================================*/
139

    
140
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
141
ROMCONST char* moduleShellPrompt = "NUCLEO-L476RG";
142
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
143

    
144
/** @} */
145

    
146
/*===========================================================================*/
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
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

    
172
MPU6050Driver moduleLldMpu6050 = {
173
  /* I2C Driver       */ &MODULE_HAL_I2C,
174
  /* I²C address      */ MPU6050_LLD_I2C_ADDR_FIXED,
175
};
176

    
177
#endif /* (BOARD_MPU6050_CONNECTED == true) */
178

    
179
#if (BOARD_VL53L1X_CONNECTED == true)
180

    
181
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

    
193
/** @} */
194

    
195
/*===========================================================================*/
196
/**
197
 * @name Tests
198
 * @{
199
 */
200
/*===========================================================================*/
201
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
202

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

    
235
#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
/*
248
 * entire module
249
 */
250
static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
251
{
252
  (void)argc;
253
  (void)argv;
254

    
255
  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
  /* MPU6050 (accelerometer & gyroscope) */
270
  status |= moduleTestMpu6050ShellCb(stream, 0, targv, &result_test);
271
  result_total = aosTestResultAdd(result_total, result_test);
272
#endif /* (BOARD_MPU6050_CONNECTED == true) */
273

    
274
#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
  // 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

    
288
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
289

    
290
/** @} */
291
/** @} */