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