Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-1 / module.c @ 542939ea

History | View | Annotate | Download (24 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 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 e545e620 Thomas Schöpping
#include "module.h"
28
29
/*===========================================================================*/
30
/**
31
 * @name Module specific functions
32
 * @{
33
 */
34
/*===========================================================================*/
35
36
/** @} */
37
38
/*===========================================================================*/
39
/**
40
 * @name ChibiOS/HAL configuration
41
 * @{
42
 */
43
/*===========================================================================*/
44
45
CANConfig moduleHalCanConfig = {
46
  /* mcr  */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
47
  /* btr  */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1),
48
};
49
50
I2CConfig moduleHalI2cCompassConfig = {
51
  /* I²C mode   */ OPMODE_I2C,
52
  /* frequency  */ 400000,
53
  /* duty cycle */ FAST_DUTY_CYCLE_2,
54
};
55
56
I2CConfig moduleHalI2cProxEepromPwrmtrConfig = {
57
  /* I²C mode   */ OPMODE_I2C,
58
  /* frequency  */ 400000,
59
  /* duty cycle */ FAST_DUTY_CYCLE_2,
60
};
61
62
PWMConfig moduleHalPwmDriveConfig = {
63
  /* frequency              */ 7200000,
64
  /* period                 */ 360,
65
  /* callback               */ NULL,
66
  /* channel configurations */ {
67
    /* channel 0              */ {
68
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
69
      /* callback               */ NULL
70
    },
71
    /* channel 1              */ {
72
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
73
      /* callback               */ NULL
74
    },
75
    /* channel 2              */ {
76
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
77
      /* callback               */ NULL
78
    },
79
    /* channel 3              */ {
80
      /* mode                   */ PWM_OUTPUT_ACTIVE_HIGH,
81
      /* callback               */ NULL
82
    },
83
  },
84
  /* TIM CR2 register       */ 0,
85 7de0cc90 Thomas Schöpping
#if (STM32_PWM_USE_ADVANCED == TRUE)
86 e545e620 Thomas Schöpping
  /* TIM BDTR register      */ 0,
87 7de0cc90 Thomas Schöpping
#endif /* (STM32_PWM_USE_ADVANCED == TRUE) */
88 e545e620 Thomas Schöpping
  /* TIM DIER register      */ 0
89
};
90
91
QEIConfig moduleHalQeiConfig = {
92
  /* mode           */ QEI_COUNT_BOTH,
93
  /* channel config */ {
94
    /* channel 0 */ {
95
      /* input mode */ QEI_INPUT_NONINVERTED,
96
    },
97
    /* channel 1 */ {
98
      /* input mode */ QEI_INPUT_NONINVERTED,
99
    },
100
  },
101
  /* encoder range  */  0x10000u,
102
};
103
104
SerialConfig moduleHalProgIfConfig = {
105
  /* bit rate */ 115200,
106
  /* CR1      */ 0,
107
  /* CR1      */ 0,
108
  /* CR1      */ 0,
109
};
110
111
SPIConfig moduleHalSpiAccelerometerConfig = {
112 0128be0f Marc Rothmann
  /* circular buffer mode         */ false,
113 e545e620 Thomas Schöpping
  /* callback function pointer    */ NULL,
114
  /* chip select line port        */ GPIOC,
115
  /* chip select line pad number  */ GPIOC_ACCEL_SS_N,
116
  /* CR1                          */ SPI_CR1_BR_0,
117
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
118
};
119
120
SPIConfig moduleHalSpiGyroscopeConfig = {
121 0128be0f Marc Rothmann
  /* circular buffer mode         */ false,
122 e545e620 Thomas Schöpping
  /* callback function pointer    */ NULL,
123
  /* chip select line port        */ GPIOC,
124
  /* chip select line pad number  */ GPIOC_GYRO_SS_N,
125
  /* CR1                          */ SPI_CR1_BR_0,
126
  /* CR2                          */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
127
};
128
129
/** @} */
130
131
/*===========================================================================*/
132
/**
133
 * @name GPIO definitions
134
 * @{
135
 */
136
/*===========================================================================*/
137
138 1e5f7648 Thomas Schöpping
/**
139
 * @brief   LED output signal GPIO.
140
 */
141
static apalGpio_t _gpioLed = {
142 e545e620 Thomas Schöpping
  /* port */ GPIOA,
143
  /* pad  */ GPIOA_LED,
144
};
145 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
146 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioLed,
147
  /* meta */ {
148
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
149
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
150
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
151
  },
152
};
153 e545e620 Thomas Schöpping
154 1e5f7648 Thomas Schöpping
/**
155
 * @brief   POWER_EN output signal GPIO.
156
 */
157
static apalGpio_t _gpioPowerEn = {
158
  /* port */ GPIOB,
159 8547080b Thomas Schöpping
  /* pad  */ GPIOB_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 e545e620 Thomas Schöpping
  /* port */ GPIOB,
175
  /* pad  */ GPIOB_COMPASS_DRDY,
176
};
177 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioCompassDrdy = {
178 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioCompassDrdy,
179
  /* meta */ {
180
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
181
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
182
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
183
  },
184
};
185 e545e620 Thomas Schöpping
186 1e5f7648 Thomas Schöpping
/**
187
 * @brief   IR_INT input signal GPIO.
188
 */
189
static apalGpio_t _gpioIrInt = {
190 e545e620 Thomas Schöpping
  /* port */ GPIOB,
191
  /* pad  */ GPIOB_IR_INT,
192
};
193 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioIrInt = {
194 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioIrInt,
195
  /* meta */ {
196
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
197
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
198
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
199
  },
200
};
201 e545e620 Thomas Schöpping
202 1e5f7648 Thomas Schöpping
/**
203
 * @brief   GYRO_DRDY input signal GPIO.
204
 */
205
static apalGpio_t _gpioGyroDrdy = {
206 e545e620 Thomas Schöpping
  /* port */ GPIOB,
207
  /* pad  */ GPIOB_GYRO_DRDY,
208
};
209 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGyroDrdy = {
210 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGyroDrdy,
211
  /* meta */ {
212
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
213
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
214
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
215
  },
216
};
217 e545e620 Thomas Schöpping
218 1e5f7648 Thomas Schöpping
/**
219
 * @brief   SYS_UART_UP bidirectional signal GPIO.
220
 */
221
static apalGpio_t _gpioSysUartUp = {
222 e545e620 Thomas Schöpping
  /* port */ GPIOB,
223
  /* pad  */ GPIOB_SYS_UART_UP,
224
};
225 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
226 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysUartUp,
227
  /* meta */ {
228
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
229
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
230
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,