amiro-os / modules / LightRing_1-0 / module.c @ 53710ca3
History | View | Annotate | Download (9.1 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 | }; |
||
73 | |||
74 | /*===========================================================================*/
|
||
75 | /**
|
||
76 | * @name GPIO definitions
|
||
77 | * @{
|
||
78 | */
|
||
79 | /*===========================================================================*/
|
||
80 | |||
81 | 1e5f7648 | Thomas Schöpping | /**
|
82 | * @brief LIGHT_BANK output signal GPIO.
|
||
83 | */
|
||
84 | static apalGpio_t _gpioLightBlank = {
|
||
85 | e545e620 | Thomas Schöpping | /* port */ GPIOA,
|
86 | /* pad */ GPIOA_LIGHT_BLANK,
|
||
87 | }; |
||
88 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioLightBlank = { |
89 | /* GPIO */ &_gpioLightBlank,
|
||
90 | /* meta */ {
|
||
91 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
92 | /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
||
93 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
94 | }, |
||
95 | }; |
||
96 | e545e620 | Thomas Schöpping | |
97 | 1e5f7648 | Thomas Schöpping | /**
|
98 | * @brief LASER_EN output signal GPIO.
|
||
99 | */
|
||
100 | static apalGpio_t _gpioLaserEn = {
|
||
101 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
102 | /* pad */ GPIOB_LASER_EN,
|
||
103 | }; |
||
104 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioLaserEn = { |
105 | /* GPIO */ &_gpioLaserEn,
|
||
106 | /* meta */ {
|
||
107 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
108 | /* active state */ TPS2051B_LLD_ENABLE_ACTIVE_STATE,
|
||
109 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
110 | }, |
||
111 | }; |
||
112 | e545e620 | Thomas Schöpping | |
113 | 1e5f7648 | Thomas Schöpping | /**
|
114 | * @brief LASER_OC input signal GPIO.
|
||
115 | */
|
||
116 | static apalGpio_t _gpioLaserOc = {
|
||
117 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
118 | /* pad */ GPIOB_LASER_OC_N,
|
||
119 | }; |
||
120 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioLaserOc = { |
121 | /* GPIO */ &_gpioLaserOc,
|
||
122 | /* meta */ {
|
||
123 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
124 | /* active state */ TPS2051B_LLD_OVERCURRENT_ACTIVE_STATE,
|
||
125 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
126 | }, |
||
127 | }; |
||
128 | e545e620 | Thomas Schöpping | |
129 | 1e5f7648 | Thomas Schöpping | /**
|
130 | * @brief SYS_UART_DN bidirectional signal GPIO.
|
||
131 | */
|
||
132 | static apalGpio_t _gpioSysUartDn = {
|
||
133 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
134 | /* pad */ GPIOB_SYS_UART_DN,
|
||
135 | }; |
||
136 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioSysUartDn = { |
137 | /* GPIO */ &_gpioSysUartDn,
|
||
138 | /* meta */ {
|
||
139 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
140 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
141 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
142 | }, |
||
143 | }; |
||
144 | e545e620 | Thomas Schöpping | |
145 | 1e5f7648 | Thomas Schöpping | /**
|
146 | * @brief WL_GDO2 input signal GPIO.
|
||
147 | */
|
||
148 | static apalGpio_t _gpioWlGdo2 = {
|
||
149 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
150 | /* pad */ GPIOB_WL_GDO2,
|
||
151 | }; |
||
152 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioWlGdo2 = { |
153 | /* GPIO */ &_gpioWlGdo2,
|
||
154 | /* meta */ {
|
||
155 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
156 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
157 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
158 | }, |
||
159 | }; |
||
160 | e545e620 | Thomas Schöpping | |
161 | 1e5f7648 | Thomas Schöpping | /**
|
162 | * @brief WL_GDO0 input signal GPIO.
|
||
163 | */
|
||
164 | static apalGpio_t _gpioWlGdo0= {
|
||
165 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
166 | /* pad */ GPIOB_WL_GDO0,
|
||
167 | }; |
||
168 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioWlGdo0 = { |
169 | /* GPIO */ &_gpioWlGdo0,
|
||
170 | /* meta */ {
|
||
171 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
172 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
173 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
174 | }, |
||
175 | }; |
||
176 | e545e620 | Thomas Schöpping | |
177 | 1e5f7648 | Thomas Schöpping | /**
|
178 | * @brief LIGHT_XLAT output signal GPIO.
|
||
179 | */
|
||
180 | static apalGpio_t _gpioLightXlat = {
|
||
181 | e545e620 | Thomas Schöpping | /* port */ GPIOC,
|
182 | /* pad */ GPIOC_LIGHT_XLAT,
|
||
183 | }; |
||
184 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioLightXlat = { |
185 | /* GPIO */ &_gpioLightXlat,
|
||
186 | /* meta */ {
|
||
187 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
188 | /* active state */ TLC5947_LLD_XLAT_ACTIVE_STATE,
|
||
189 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
190 | }, |
||
191 | }; |
||
192 | e545e620 | Thomas Schöpping | |
193 | 1e5f7648 | Thomas Schöpping | /**
|
194 | * @brief SYS_PD bidirectional signal GPIO.
|
||
195 | */
|
||
196 | static apalGpio_t _gpioSysPd = {
|
||
197 | e545e620 | Thomas Schöpping | /* port */ GPIOC,
|
198 | /* pad */ GPIOC_SYS_PD_N,
|
||
199 | }; |
||
200 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioSysPd = { |
201 | /* GPIO */ &_gpioSysPd,
|
||
202 | /* meta */ {
|
||
203 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
204 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
205 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
206 | }, |
||
207 | }; |
||
208 | e545e620 | Thomas Schöpping | |
209 | 1e5f7648 | Thomas Schöpping | /**
|
210 | * @brief SYS_SYNC bidirectional signal GPIO.
|
||
211 | */
|
||
212 | static apalGpio_t _gpioSysSync = {
|
||
213 | e545e620 | Thomas Schöpping | /* port */ GPIOD,
|
214 | /* pad */ GPIOD_SYS_INT_N,
|
||
215 | }; |
||
216 | 1e5f7648 | Thomas Schöpping | apalControlGpio_t moduleGpioSysSync = { |
217 | /* GPIO */ &_gpioSysSync,
|
||
218 | /* meta */ {
|
||
219 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
220 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
221 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
222 | }, |
||
223 | }; |
||
224 | e545e620 | Thomas Schöpping | |
225 | /** @} */
|
||
226 | |||
227 | /*===========================================================================*/
|
||
228 | /**
|
||
229 | * @name AMiRo-OS core configurations
|
||
230 | * @{
|
||
231 | */
|
||
232 | /*===========================================================================*/
|
||
233 | |||
234 | 6b53f6bf | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
235 | const char* moduleShellPrompt = "LightRing"; |
||
236 | #endif
|
||
237 | |||
238 | /** @} */
|
||
239 | |||
240 | /*===========================================================================*/
|
||
241 | /**
|
||
242 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
243 | * @{
|
||
244 | */
|
||
245 | /*===========================================================================*/
|
||
246 | |||
247 | e545e620 | Thomas Schöpping | /** @} */
|
248 | |||
249 | /*===========================================================================*/
|
||
250 | /**
|
||
251 | * @name Low-level drivers
|
||
252 | * @{
|
||
253 | */
|
||
254 | /*===========================================================================*/
|
||
255 | |||
256 | AT24C01BNDriver moduleLldEeprom = { |
||
257 | /* I2C driver */ &MODULE_HAL_I2C_EEPROM,
|
||
258 | /* I2C address */ 0x00u, |
||
259 | }; |
||
260 | |||
261 | TLC5947Driver moduleLldLedPwm = { |
||
262 | /* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
||
263 | 1e5f7648 | Thomas Schöpping | /* BLANK signal GPIO */ &moduleGpioLightBlank,
|
264 | /* XLAT signal GPIO */ &moduleGpioLightXlat,
|
||
265 | e545e620 | Thomas Schöpping | }; |
266 | |||
267 | TPS2051BDriver moduleLldPowerSwitchLaser = { |
||
268 | 1e5f7648 | Thomas Schöpping | /* laser enable GPIO */ &moduleGpioLaserEn,
|
269 | /* laser overcurrent GPIO */ &moduleGpioLaserOc,
|
||
270 | e545e620 | Thomas Schöpping | }; |
271 | |||
272 | /** @} */
|
||
273 | |||
274 | /*===========================================================================*/
|
||
275 | /**
|
||
276 | * @name Unit tests (UT)
|
||
277 | * @{
|
||
278 | */
|
||
279 | /*===========================================================================*/
|
||
280 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
281 | |||
282 | /* EEPROM (AT24C01BN) */
|
||
283 | static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
||
284 | { |
||
285 | (void)argc;
|
||
286 | (void)argv;
|
||
287 | aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
||
288 | return AOS_OK;
|
||
289 | } |
||
290 | static ut_at24c01bndata_t _utAt24c01bnData = {
|
||
291 | /* driver */ &moduleLldEeprom,
|
||
292 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
293 | }; |
||
294 | aos_unittest_t moduleUtAlldAt24c01bn = { |
||
295 | /* name */ "AT24C01BN-SH-B", |
||
296 | /* info */ "1kbit EEPROM", |
||
297 | /* test function */ utAlldAt24c01bnFunc,
|
||
298 | /* shell command */ {
|
||
299 | /* name */ "unittest:EEPROM", |
||
300 | /* callback */ _utShellCmdCb_AlldAt24c01bn,
|
||
301 | /* next */ NULL, |
||
302 | }, |
||
303 | /* data */ &_utAt24c01bnData,
|
||
304 | }; |
||
305 | |||
306 | /* LED PWM driver (TLD5947) */
|
||
307 | static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[]) |
||
308 | { |
||
309 | (void)argc;
|
||
310 | (void)argv;
|
||
311 | aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
|
||
312 | return AOS_OK;
|
||
313 | } |
||
314 | aos_unittest_t moduleUtAlldTlc5947 = { |
||
315 | /* info */ "TLC5947", |
||
316 | /* name */ "LED PWM driver", |
||
317 | /* test function */ utAlldTlc5947Func,
|
||
318 | /* shell command */ {
|
||
319 | /* name */ "unittest:Lights", |
||
320 | /* callback */ _utShellCmdCb_Tlc5947,
|
||
321 | /* next */ NULL, |
||
322 | }, |
||
323 | /* data */ &moduleLldLedPwm,
|
||
324 | }; |
||
325 | |||
326 | /* power switch (Laser) */
|
||
327 | static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[]) |
||
328 | { |
||
329 | (void)argc;
|
||
330 | (void)argv;
|
||
331 | aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
|
||
332 | return AOS_OK;
|
||
333 | } |
||
334 | aos_unittest_t moduleUtAlldTps2051bdbv = { |
||
335 | /* info */ "TPS2051BDBV", |
||
336 | /* name */ "current-limited power switch", |
||
337 | /* test function */ utAlldTps2051bdbvFunc,
|
||
338 | /* shell command */ {
|
||
339 | /* name */ "unittest:PowerSwitch", |
||
340 | /* callback */ _utShellCmdCb_Tps2051bdbv,
|
||
341 | /* next */ NULL, |
||
342 | }, |
||
343 | /* data */ &moduleLldPowerSwitchLaser,
|
||
344 | }; |
||
345 | |||
346 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
347 | |||
348 | /** @} */
|
||
349 | 53710ca3 | Marc Rothmann | /** @} */ |