amiro-os / modules / DiWheelDrive_1-1 / module.c @ e977b199
History | View | Annotate | Download (19.563 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | 96621a83 | Thomas Schöpping | Copyright (C) 2016..2020 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 | 53710ca3 | Marc Rothmann | /**
|
20 | acc97cbf | Thomas Schöpping | * @file
|
21 | 53710ca3 | Marc Rothmann | * @brief Structures and constant for the DiWheelDrive module.
|
22 | *
|
||
23 | * @addtogroup diwheeldrive_module
|
||
24 | * @{
|
||
25 | */
|
||
26 | |||
27 | c53ef0b1 | Thomas Schöpping | #include <amiroos.h> |
28 | |||
29 | #include <string.h> |
||
30 | e545e620 | 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 | I2CConfig moduleHalI2cCompassConfig = { |
||
53 | /* I²C mode */ OPMODE_I2C,
|
||
54 | /* frequency */ 400000, |
||
55 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
56 | }; |
||
57 | |||
58 | I2CConfig moduleHalI2cProxEepromPwrmtrConfig = { |
||
59 | /* I²C mode */ OPMODE_I2C,
|
||
60 | /* frequency */ 400000, |
||
61 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
62 | }; |
||
63 | |||
64 | PWMConfig moduleHalPwmDriveConfig = { |
||
65 | /* frequency */ 7200000, |
||
66 | /* period */ 360, |
||
67 | /* callback */ NULL, |
||
68 | /* channel configurations */ {
|
||
69 | /* channel 0 */ {
|
||
70 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
71 | /* callback */ NULL |
||
72 | }, |
||
73 | /* channel 1 */ {
|
||
74 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
75 | /* callback */ NULL |
||
76 | }, |
||
77 | /* channel 2 */ {
|
||
78 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
79 | /* callback */ NULL |
||
80 | }, |
||
81 | /* channel 3 */ {
|
||
82 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
83 | /* callback */ NULL |
||
84 | }, |
||
85 | }, |
||
86 | /* TIM CR2 register */ 0, |
||
87 | 7de0cc90 | Thomas Schöpping | #if (STM32_PWM_USE_ADVANCED == TRUE)
|
88 | e545e620 | Thomas Schöpping | /* TIM BDTR register */ 0, |
89 | 7de0cc90 | Thomas Schöpping | #endif /* (STM32_PWM_USE_ADVANCED == TRUE) */ |
90 | e545e620 | Thomas Schöpping | /* TIM DIER register */ 0 |
91 | }; |
||
92 | |||
93 | QEIConfig moduleHalQeiConfig = { |
||
94 | /* mode */ QEI_COUNT_BOTH,
|
||
95 | /* channel config */ {
|
||
96 | /* channel 0 */ {
|
||
97 | /* input mode */ QEI_INPUT_NONINVERTED,
|
||
98 | }, |
||
99 | /* channel 1 */ {
|
||
100 | /* input mode */ QEI_INPUT_NONINVERTED,
|
||
101 | }, |
||
102 | }, |
||
103 | /* encoder range */ 0x10000u, |
||
104 | }; |
||
105 | |||
106 | SerialConfig moduleHalProgIfConfig = { |
||
107 | /* bit rate */ 115200, |
||
108 | /* CR1 */ 0, |
||
109 | /* CR1 */ 0, |
||
110 | /* CR1 */ 0, |
||
111 | }; |
||
112 | |||
113 | SPIConfig moduleHalSpiAccelerometerConfig = { |
||
114 | 0128be0f | Marc Rothmann | /* circular buffer mode */ false, |
115 | e545e620 | Thomas Schöpping | /* callback function pointer */ NULL, |
116 | 3106e8cc | Thomas Schöpping | /* chip select line port */ PAL_PORT(LINE_ACCEL_SS_N),
|
117 | /* chip select line pad number */ PAL_PAD(LINE_ACCEL_SS_N),
|
||
118 | e545e620 | Thomas Schöpping | /* CR1 */ SPI_CR1_BR_0,
|
119 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
||
120 | }; |
||
121 | |||
122 | SPIConfig moduleHalSpiGyroscopeConfig = { |
||
123 | 0128be0f | Marc Rothmann | /* circular buffer mode */ false, |
124 | e545e620 | Thomas Schöpping | /* callback function pointer */ NULL, |
125 | 3106e8cc | Thomas Schöpping | /* chip select line port */ PAL_PORT(LINE_GYRO_SS_N),
|
126 | /* chip select line pad number */ PAL_PAD(LINE_GYRO_SS_N),
|
||
127 | e545e620 | Thomas Schöpping | /* CR1 */ SPI_CR1_BR_0,
|
128 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
||
129 | }; |
||
130 | |||
131 | /** @} */
|
||
132 | |||
133 | /*===========================================================================*/
|
||
134 | /**
|
||
135 | * @name GPIO definitions
|
||
136 | * @{
|
||
137 | */
|
||
138 | /*===========================================================================*/
|
||
139 | |||
140 | 1e5f7648 | Thomas Schöpping | /**
|
141 | * @brief LED output signal GPIO.
|
||
142 | */
|
||
143 | static apalGpio_t _gpioLed = {
|
||
144 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LED,
|
145 | e545e620 | Thomas Schöpping | }; |
146 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLed = { |
147 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLed,
|
148 | /* meta */ {
|
||
149 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
150 | 4c72a54c | Thomas Schöpping | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
151 | 1e5f7648 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
152 | }, |
||
153 | }; |
||
154 | e545e620 | Thomas Schöpping | |
155 | 1e5f7648 | Thomas Schöpping | /**
|
156 | * @brief POWER_EN output signal GPIO.
|
||
157 | */
|
||
158 | static apalGpio_t _gpioPowerEn = {
|
||
159 | 3106e8cc | Thomas Schöpping | /* line */ LINE_POWER_EN,
|
160 | e545e620 | Thomas Schöpping | }; |
161 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioPowerEn = { |
162 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioPowerEn,
|
163 | /* meta */ {
|
||
164 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
165 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
166 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
167 | }, |
||
168 | }; |
||
169 | e545e620 | Thomas Schöpping | |
170 | 1e5f7648 | Thomas Schöpping | /**
|
171 | * @brief COMPASS_DRDY output signal GPIO.
|
||
172 | */
|
||
173 | static apalGpio_t _gpioCompassDrdy = {
|
||
174 | 3106e8cc | Thomas Schöpping | /* line */ LINE_COMPASS_DRDY,
|
175 | e545e620 | Thomas Schöpping | }; |
176 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioCompassDrdy = { |
177 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioCompassDrdy,
|
178 | /* meta */ {
|
||
179 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
180 | /* active state */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
181 | /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
|
||
182 | }, |
||
183 | }; |
||
184 | e545e620 | Thomas Schöpping | |
185 | 1e5f7648 | Thomas Schöpping | /**
|
186 | * @brief IR_INT input signal GPIO.
|
||
187 | */
|
||
188 | static apalGpio_t _gpioIrInt = {
|
||
189 | 3106e8cc | Thomas Schöpping | /* line */ LINE_IR_INT,
|
190 | e545e620 | Thomas Schöpping | }; |
191 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioIrInt = { |
192 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioIrInt,
|
193 | /* meta */ {
|
||
194 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
195 | /* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
196 | /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
||
197 | }, |
||
198 | }; |
||
199 | e545e620 | Thomas Schöpping | |
200 | 1e5f7648 | Thomas Schöpping | /**
|
201 | * @brief GYRO_DRDY input signal GPIO.
|
||
202 | */
|
||
203 | static apalGpio_t _gpioGyroDrdy = {
|
||
204 | 3106e8cc | Thomas Schöpping | /* line */ LINE_GYRO_DRDY,
|
205 | e545e620 | Thomas Schöpping | }; |
206 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioGyroDrdy = { |
207 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioGyroDrdy,
|
208 | /* meta */ {
|
||
209 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
210 | /* active state */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
211 | /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
|
||
212 | }, |
||
213 | }; |
||
214 | e545e620 | Thomas Schöpping | |
215 | 1e5f7648 | Thomas Schöpping | /**
|
216 | * @brief SYS_UART_UP bidirectional signal GPIO.
|
||
217 | */
|
||
218 | static apalGpio_t _gpioSysUartUp = {
|
||
219 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_UART_UP,
|
220 | e545e620 | Thomas Schöpping | }; |
221 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartUp = { |
222 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysUartUp,
|
223 | /* meta */ {
|
||
224 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||