Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / LightRing_1-2 / module.c @ 98949060

History | View | Annotate | Download (21.797 KB)

1 9ae7c4f3 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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 034cb15a Thomas Schöpping
 * @brief   Structures and constant for the LightRing v1.2 module.
22 9ae7c4f3 Thomas Schöpping
 *
23
 * @addtogroup lightring_module
24
 * @{
25
 */
26
27 c53ef0b1 Thomas Schöpping
#include <amiroos.h>
28
29
#include <string.h>
30 9ae7c4f3 Thomas Schöpping
31
/*===========================================================================*/
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 ee884101 Thomas Schöpping
I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig = {
53 9ae7c4f3 Thomas Schöpping
  /* 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
  /* circular buffer mode        */ false,
67
  /* callback function pointer   */ NULL,
68 3106e8cc Thomas Schöpping
  /* chip select line port       */ PAL_PORT(LINE_LIGHT_XLAT),
69
  /* chip select line pad number */ PAL_PAD(LINE_LIGHT_XLAT),
70 9ae7c4f3 Thomas Schöpping
  /* CR1                         */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
71
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
72
};
73
74 f606f432 Thomas Schöpping
#if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
75 0b989911 Cung Sang
76
SPIConfig moduleHalSpiUwbHsConfig = {
77
  /* circular buffer mode        */ false,
78
  /* callback function pointer   */ NULL,
79
  /* chip select line port       */ PAL_PORT(LINE_SPI_SS_N),
80
  /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
81
  /* CR1                         */ 0,                                  // 36/2 Mbps
82
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,  // 0
83
};
84 f606f432 Thomas Schöpping
85 0b989911 Cung Sang
SPIConfig moduleHalSpiUwbLsConfig = {
86
  /* circular buffer mode        */ false,
87
  /* callback function pointer   */ NULL,
88
  /* chip select line port       */ PAL_PORT(LINE_SPI_SS_N),
89
  /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
90
  /* CR1                         */ SPI_CR1_BR_1 | SPI_CR1_BR_0,        // 36/16 Mbps
91
  /* CR2                         */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,  // 0
92
};
93
94 f606f432 Thomas Schöpping
#endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */
95 9ae7c4f3 Thomas Schöpping
96
/*===========================================================================*/
97
/**
98
 * @name GPIO definitions
99
 * @{
100
 */
101
/*===========================================================================*/
102
103
/**
104
 * @brief   LIGHT_BANK output signal GPIO.
105
 */
106
static apalGpio_t _gpioLightBlank = {
107 3106e8cc Thomas Schöpping
  /* line */ LINE_LIGHT_BLANK,
108 9ae7c4f3 Thomas Schöpping
};
109
ROMCONST apalControlGpio_t moduleGpioLightBlank = {
110
  /* GPIO */ &_gpioLightBlank,
111
  /* meta */ {
112
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
113
    /* active state   */ TLC5947_LLD_BLANK_ACTIVE_STATE,
114
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
115
  },
116
};
117
118
/**
119
 * @brief   RS232_R_EN_N output signal GPIO.
120
 */
121
static apalGpio_t _gpioRs232En = {
122 3106e8cc Thomas Schöpping
  /* line */ LINE_RS232_R_EN_N,
123 9ae7c4f3 Thomas Schöpping
};
124
ROMCONST apalControlGpio_t moduleGpioRs232En = {
125
  /* GPIO */ &_gpioRs232En,
126
  /* meta */ {
127
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
128
    /* active state   */ APAL_GPIO_ACTIVE_LOW, //TODO
129
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
130
  },
131
};
132
133
/**
134
 * @brief   SW_V33_EN output signal GPIO.
135
 */
136
static apalGpio_t _gpioSwV33En = {
137 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_V33_EN,
138 9ae7c4f3 Thomas Schöpping
};
139
ROMCONST apalControlGpio_t moduleGpioSwV33En = {
140
  /* GPIO */ &_gpioSwV33En,
141
  /* meta */ {
142
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
143 ee884101 Thomas Schöpping
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
144 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
145
  },
146
};
147
148 9acb8326 Thomas Schöpping
// The 4.2V switch is disabled due to a hardware bug.
149
///**
150
// * @brief   SW_V42_EN output signal GPIO.
151
// */
152
//static apalGpio_t _gpioSwV42En = {
153
//  /* line */ LINE_SW_V42_EN,
154
//};
155
//ROMCONST apalControlGpio_t moduleGpioSwV42En = {
156
//  /* GPIO */ &_gpioSwV42En,
157
//  /* meta */ {
158
//    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
159
//    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
160
//    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
161
//  },
162
//};
163 9ae7c4f3 Thomas Schöpping
164
/**
165
 * @brief   SW_V50_EN output signal GPIO.
166
 */
167
static apalGpio_t _gpioSwV50En = {
168 3106e8cc Thomas Schöpping
  /* line */ LINE_SW_V50_EN,
169 9ae7c4f3 Thomas Schöpping
};
170
ROMCONST apalControlGpio_t moduleGpioSwV50En = {
171
  /* GPIO */ &_gpioSwV50En,
172
  /* meta */ {
173
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
174 ee884101 Thomas Schöpping
    /* active state   */ MIC9404x_LLD_EN_ACTIVE_STATE,
175 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
176
  },
177
};
178
179
/**
180 f606f432 Thomas Schöpping
 * @brief   SYS_UART_DN bidirectional signal GPIO.
181 9ae7c4f3 Thomas Schöpping
 */
182 f606f432 Thomas Schöpping
static apalGpio_t _gpioSysUartDn = {
183
  /* line */ LINE_SYS_UART_DN,
184 9ae7c4f3 Thomas Schöpping
};
185 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
186
  /* GPIO */ &_gpioSysUartDn,
187 9ae7c4f3 Thomas Schöpping
  /* meta */ {
188 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
189 9ae7c4f3 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
190 f606f432 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
191 9ae7c4f3 Thomas Schöpping
  },
192
};
193
194
/**
195 f606f432 Thomas Schöpping
 * @brief   LED output signal GPIO.
196 9ae7c4f3 Thomas Schöpping
 */
197 f606f432 Thomas Schöpping
static apalGpio_t _gpioLed = {
198
  /* line */ LINE_LED,
199 9ae7c4f3 Thomas Schöpping
};
200 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
201
  /* GPIO */ &_gpioLed,
202 9ae7c4f3 Thomas Schöpping
  /* meta */ {
203 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
204 9ae7c4f3 Thomas Schöpping
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
205
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
206
  },
207
};
208
209
/**
210 f606f432 Thomas Schöpping
 * @brief   LIGHT_XLAT output signal GPIO.
211 9ae7c4f3 Thomas Schöpping
 */
212 f606f432 Thomas Schöpping
static apalGpio_t _gpioLightXlat = {
213
  /* line */ LINE_LIGHT_XLAT,
214 9ae7c4f3 Thomas Schöpping
};
215 f606f432 Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLightXlat = {
216
  /* GPIO */ &_gpioLightXlat,
217 9ae7c4f3 Thomas Schöpping
  /* meta */ {
218 f606f432 Thomas Schöpping
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
219
    /* active state   */ (TLC5947_LLD_XLAT_UPDATE_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
220 9ae7c4f3 Thomas Schöpping
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
221
  },
222
};
223
224
/**
225 f606f432 Thomas