amiro-os / modules / LightRing_1-0 / module.c @ 0963cf6c
History | View | Annotate | Download (9.395 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 | e545e620 | Thomas Schöpping | |
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 | #include "module.h" |
||
20 | |||
21 | 1e5f7648 | Thomas Schöpping | #include <amiroos.h> |
22 | |||
23 | e545e620 | Thomas Schöpping | /*===========================================================================*/
|
24 | /**
|
||
25 | * @name Module specific functions
|
||
26 | * @{
|
||
27 | */
|
||
28 | /*===========================================================================*/
|
||
29 | |||
30 | /** @} */
|
||
31 | |||
32 | /*===========================================================================*/
|
||
33 | /**
|
||
34 | * @name ChibiOS/HAL configuration
|
||
35 | * @{
|
||
36 | */
|
||
37 | /*===========================================================================*/
|
||
38 | |||
39 | CANConfig moduleHalCanConfig = { |
||
40 | /* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||
41 | /* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
||
42 | }; |
||
43 | |||
44 | I2CConfig moduleHalI2cEepromConfig = { |
||
45 | /* I²C mode */ OPMODE_I2C,
|
||
46 | /* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
||
47 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
48 | }; |
||
49 | |||
50 | SerialConfig moduleHalProgIfConfig = { |
||
51 | /* bit rate */ 115200, |
||
52 | /* CR1 */ 0, |
||
53 | /* CR1 */ 0, |
||
54 | /* CR1 */ 0, |
||
55 | }; |
||
56 | |||
57 | SPIConfig moduleHalSpiLightConfig = { |
||
58 | 0128be0f | Marc Rothmann | /* circular buffer mode */ false, |
59 | e545e620 | Thomas Schöpping | /* callback function pointer */ NULL, |
60 | /* chip select line port */ GPIOC,
|
||
61 | /* chip select line pad number */ GPIOC_LIGHT_XLAT,
|
||
62 | /* CR1 */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
|
||
63 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
||
64 | 22be62dc | Thomas Schöpping | }; |
65 | |||
66 | 02c29a8f | Thomas Schöpping | SPIConfig moduleHalSpiWlConfig = { |
67 | 22be62dc | Thomas Schöpping | /* circular buffer mode */ false, |
68 | /* callback function pointer */ NULL, |
||
69 | /* chip select line port */ GPIOB,
|
||
70 | /* chip select line pad number */ GPIOB_WL_SS_N,
|
||
71 | 02c29a8f | Thomas Schöpping | /* CR1 */ SPI_CR1_BR_0,
|
72 | 22be62dc | Thomas Schöpping | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
73 | e545e620 | Thomas Schöpping | }; |
74 | |||
75 | /*===========================================================================*/
|
||
76 | /**
|
||
77 | * @name GPIO definitions
|
||
78 | * @{
|
||
79 | */
|
||
80 | /*===========================================================================*/
|
||
81 | |||
82 | 1e5f7648 | Thomas Schöpping | /**
|
83 | * @brief LIGHT_BANK output signal GPIO.
|
||
84 | */
|
||
85 | static apalGpio_t _gpioLightBlank = {
|
||
86 | e545e620 | Thomas Schöpping | /* port */ GPIOA,
|
87 | /* pad */ GPIOA_LIGHT_BLANK,
|
||
88 | }; |
||
89 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLightBlank = { |
90 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLightBlank,
|
91 | /* meta */ {
|
||
92 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
93 | /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
||
94 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
95 | }, |
||
96 | }; |
||
97 | e545e620 | Thomas Schöpping | |
98 | 1e5f7648 | Thomas Schöpping | /**
|
99 | * @brief LASER_EN output signal GPIO.
|
||
100 | */
|
||
101 | static apalGpio_t _gpioLaserEn = {
|
||
102 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
103 | /* pad */ GPIOB_LASER_EN,
|
||
104 | }; |
||
105 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLaserEn = { |
106 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLaserEn,
|
107 | /* meta */ {
|
||
108 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
109 | /* active state */ TPS2051B_LLD_ENABLE_ACTIVE_STATE,
|
||
110 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
111 | }, |
||
112 | }; |
||
113 | e545e620 | Thomas Schöpping | |
114 | 1e5f7648 | Thomas Schöpping | /**
|
115 | * @brief LASER_OC input signal GPIO.
|
||
116 | */
|
||
117 | static apalGpio_t _gpioLaserOc = {
|
||
118 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
119 | /* pad */ GPIOB_LASER_OC_N,
|
||
120 | }; |
||
121 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLaserOc = { |
122 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLaserOc,
|
123 | /* meta */ {
|
||
124 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
125 | /* active state */ TPS2051B_LLD_OVERCURRENT_ACTIVE_STATE,
|
||
126 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
127 | }, |
||
128 | }; |
||
129 | e545e620 | Thomas Schöpping | |
130 | 1e5f7648 | Thomas Schöpping | /**
|
131 | * @brief SYS_UART_DN bidirectional signal GPIO.
|
||
132 | */
|
||
133 | static apalGpio_t _gpioSysUartDn = {
|
||
134 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
135 | /* pad */ GPIOB_SYS_UART_DN,
|
||
136 | }; |
||
137 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartDn = { |
138 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysUartDn,
|
139 | /* meta */ {
|
||
140 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
141 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
142 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
143 | }, |
||
144 | }; |
||
145 | e545e620 | Thomas Schöpping | |
146 | 1e5f7648 | Thomas Schöpping | /**
|
147 | * @brief WL_GDO2 input signal GPIO.
|
||
148 | */
|
||
149 | static apalGpio_t _gpioWlGdo2 = {
|
||
150 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
151 | /* pad */ GPIOB_WL_GDO2,
|
||
152 | }; |
||
153 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo2 = { |
154 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo2,
|
155 | /* meta */ {
|
||
156 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
157 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
158 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
159 | }, |
||
160 | }; |
||
161 | e545e620 | Thomas Schöpping | |
162 | 1e5f7648 | Thomas Schöpping | /**
|
163 | * @brief WL_GDO0 input signal GPIO.
|
||
164 | */
|
||
165 | static apalGpio_t _gpioWlGdo0= {
|
||
166 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
167 | /* pad */ GPIOB_WL_GDO0,
|
||
168 | }; |
||
169 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo0 = { |
170 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo0,
|
171 | /* meta */ {
|
||
172 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
173 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
174 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
175 | }, |
||
176 | }; |
||
177 | e545e620 | Thomas Schöpping | |
178 | 1e5f7648 | Thomas Schöpping | /**
|
179 | * @brief LIGHT_XLAT output signal GPIO.
|
||
180 | */
|
||
181 | static apalGpio_t _gpioLightXlat = {
|
||
182 | e545e620 | Thomas Schöpping | /* port */ GPIOC,
|
183 | /* pad */ GPIOC_LIGHT_XLAT,
|
||
184 | }; |
||
185 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLightXlat = { |
186 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLightXlat,
|
187 | /* meta */ {
|
||
188 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
189 | /* active state */ TLC5947_LLD_XLAT_ACTIVE_STATE,
|
||
190 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
191 | }, |
||
192 | }; |
||
193 | e545e620 | Thomas Schöpping | |
194 | 1e5f7648 | Thomas Schöpping | /**
|
195 | * @brief SYS_PD bidirectional signal GPIO.
|
||
196 | */
|
||
197 | static apalGpio_t _gpioSysPd = {
|
||
198 | e545e620 | Thomas Schöpping | /* port */ GPIOC,
|
199 | /* pad */ GPIOC_SYS_PD_N,
|
||
200 | }; |
||
201 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysPd = { |
202 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysPd,
|
203 | /* meta */ {
|
||
204 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
205 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
206 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
207 | }, |
||
208 | }; |
||
209 | e545e620 | Thomas Schöpping | |
210 | 1e5f7648 | Thomas Schöpping | /**
|
211 | * @brief SYS_SYNC bidirectional signal GPIO.
|
||
212 | */
|
||
213 | static apalGpio_t _gpioSysSync = {
|
||
214 | e545e620 | Thomas Schöpping | /* port */ GPIOD,
|
215 | /* pad */ GPIOD_SYS_INT_N,
|
||
216 | }; |
||
217 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysSync = { |
218 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysSync,
|
219 | /* meta */ {
|
||
220 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
221 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
222 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
223 | }, |
||
224 | }; |
||
225 | e545e620 | Thomas Schöpping | |
226 | /** @} */
|
||
227 | |||
228 | /*===========================================================================*/
|
||
229 | /**
|
||
230 | * @name AMiRo-OS core configurations
|
||
231 | * @{
|
||
232 | */
|
||
233 | /*===========================================================================*/
|
||
234 | |||
235 | 6b53f6bf | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
236 | acc97cbf | Thomas Schöpping | ROMCONST char* moduleShellPrompt = "LightRing"; |
237 | 6b53f6bf | Thomas Schöpping | #endif
|
238 | |||
239 | /** @} */
|
||
240 | |||
241 | /*===========================================================================*/
|
||
242 | /**
|
||
243 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
244 | * @{
|
||
245 | */
|
||
246 | /*===========================================================================*/
|
||
247 | |||
248 | e545e620 | Thomas Schöpping | /** @} */
|
249 | |||
250 | /*===========================================================================*/
|
||
251 | /**
|
||
252 | * @name Low-level drivers
|
||
253 | * @{
|
||
254 | */
|
||
255 | /*===========================================================================*/
|
||
256 | |||
257 | AT24C01BNDriver moduleLldEeprom = { |
||
258 | /* I2C driver */ &MODULE_HAL_I2C_EEPROM,
|
||
259 | /* I2C address */ 0x00u, |
||
260 | }; |
||
261 | |||
262 | TLC5947Driver moduleLldLedPwm = { |
||
263 | /* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
||
264 | 1e5f7648 | Thomas Schöpping | /* BLANK signal GPIO */ &moduleGpioLightBlank,
|
265 | /* XLAT signal GPIO */ &moduleGpioLightXlat,
|
||
266 | e545e620 | Thomas Schöpping | }; |
267 | |||
268 | TPS2051BDriver moduleLldPowerSwitchLaser = { |
||
269 | 1e5f7648 | Thomas Schöpping | /* laser enable GPIO */ &moduleGpioLaserEn,
|
270 | /* laser overcurrent GPIO */ &moduleGpioLaserOc,
|
||
271 | e545e620 | Thomas Schöpping | }; |
272 | |||
273 | /** @} */
|
||
274 | |||
275 | /*===========================================================================*/
|
||
276 | /**
|
||
277 | * @name Unit tests (UT)
|
||
278 | * @{
|
||
279 | */
|
||
280 | /*===========================================================================*/
|
||
281 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
282 | |||
283 | 8be006e0 | Thomas Schöpping | /*
|
284 | * EEPROM (AT24C01BN)
|
||
285 | */
|
||
286 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
287 | { |
||
288 | (void)argc;
|
||
289 | (void)argv;
|
||
290 | aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
||
291 | return AOS_OK;
|
||
292 | } |
||
293 | static ut_at24c01bndata_t _utAt24c01bnData = {
|
||
294 | /* driver */ &moduleLldEeprom,
|
||
295 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
296 | }; |
||
297 | aos_unittest_t moduleUtAlldAt24c01bn = { |
||
298 | /* name */ "AT24C01BN-SH-B", |
||
299 | /* info */ "1kbit EEPROM", |
||
300 | /* test function */ utAlldAt24c01bnFunc,
|
||
301 | /* shell command */ {
|
||
302 | /* name */ "unittest:EEPROM", |
||
303 | /* callback */ _utShellCmdCb_AlldAt24c01bn,
|
||
304 | /* next */ NULL, |
||
305 | }, |
||
306 | /* data */ &_utAt24c01bnData,
|
||
307 | }; |
||
308 | |||
309 | 8be006e0 | Thomas Schöpping | /*
|
310 | * LED PWM driver (TLD5947)
|
||
311 | */
|
||
312 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[]) |
313 | { |
||
314 | (void)argc;
|
||
315 | (void)argv;
|
||
316 | aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
|
||
317 | return AOS_OK;
|
||
318 | } |
||
319 | aos_unittest_t moduleUtAlldTlc5947 = { |
||
320 | /* info */ "TLC5947", |
||
321 | /* name */ "LED PWM driver", |
||
322 | /* test function */ utAlldTlc5947Func,
|
||
323 | /* shell command */ {
|
||
324 | /* name */ "unittest:Lights", |
||
325 | /* callback */ _utShellCmdCb_Tlc5947,
|
||
326 | /* next */ NULL, |
||
327 | }, |
||
328 | /* data */ &moduleLldLedPwm,
|
||
329 | }; |
||
330 | |||
331 | 8be006e0 | Thomas Schöpping | /*
|
332 | * power switch (Laser)
|
||
333 | */
|
||
334 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[]) |
335 | { |
||
336 | (void)argc;
|
||
337 | (void)argv;
|
||
338 | aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
|
||
339 | return AOS_OK;
|
||
340 | } |
||
341 | aos_unittest_t moduleUtAlldTps2051bdbv = { |
||
342 | /* info */ "TPS2051BDBV", |
||
343 | /* name */ "current-limited power switch", |
||
344 | /* test function */ utAlldTps2051bdbvFunc,
|
||
345 | /* shell command */ {
|
||
346 | /* name */ "unittest:PowerSwitch", |
||
347 | /* callback */ _utShellCmdCb_Tps2051bdbv,
|
||
348 | /* next */ NULL, |
||
349 | }, |
||
350 | /* data */ &moduleLldPowerSwitchLaser,
|
||
351 | }; |
||
352 | |||
353 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
354 | |||
355 | /** @} */ |