Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-1 / module.c @ 9a7e49d4

History | View | Annotate | Download (23.846 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 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 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 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
#if STM32_PWM_USE_ADVANCED
88
  /* TIM BDTR register      */ 0,
89
#endif
90
  /* 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
  /* chip select line port        */ GPIOC,
117
  /* chip select line pad number  */ GPIOC_ACCEL_SS_N,
118
  /* 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
  /* chip select line port        */ GPIOC,
126
  /* chip select line pad number  */ GPIOC_GYRO_SS_N,
127
  /* 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 e545e620 Thomas Schöpping
  /* port */ GPIOA,
145
  /* pad  */ GPIOA_LED,
146
};
147 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioLed = {
148 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioLed,
149
  /* meta */ {
150
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
151
    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
152
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
153
  },
154
};
155 e545e620 Thomas Schöpping
156 1e5f7648 Thomas Schöpping
/**
157
 * @brief   POWER_EN output signal GPIO.
158
 */
159
static apalGpio_t _gpioPowerEn = {
160
  /* port */ GPIOB,
161 e545e620 Thomas Schöpping
  /* pad  */  GPIOB_POWER_EN,
162
};
163 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioPowerEn = {
164 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioPowerEn,
165
  /* meta */ {
166
    /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
167
    /* active state   */ APAL_GPIO_ACTIVE_HIGH,
168
    /* interrupt edge */ APAL_GPIO_EDGE_NONE,
169
  },
170
};
171 e545e620 Thomas Schöpping
172 1e5f7648 Thomas Schöpping
/**
173
 * @brief   COMPASS_DRDY output signal GPIO.
174
 */
175
static apalGpio_t _gpioCompassDrdy = {
176 e545e620 Thomas Schöpping
  /* port */ GPIOB,
177
  /* pad  */ GPIOB_COMPASS_DRDY,
178
};
179 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioCompassDrdy = {
180 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioCompassDrdy,
181
  /* meta */ {
182
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
183
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
184
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
185
  },
186
};
187 e545e620 Thomas Schöpping
188 1e5f7648 Thomas Schöpping
/**
189
 * @brief   IR_INT input signal GPIO.
190
 */
191
static apalGpio_t _gpioIrInt = {
192 e545e620 Thomas Schöpping
  /* port */ GPIOB,
193
  /* pad  */ GPIOB_IR_INT,
194
};
195 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioIrInt = {
196 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioIrInt,
197
  /* meta */ {
198
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
199
    /* active state   */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
200
    /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
201
  },
202
};
203 e545e620 Thomas Schöpping
204 1e5f7648 Thomas Schöpping
/**
205
 * @brief   GYRO_DRDY input signal GPIO.
206
 */
207
static apalGpio_t _gpioGyroDrdy = {
208 e545e620 Thomas Schöpping
  /* port */ GPIOB,
209
  /* pad  */ GPIOB_GYRO_DRDY,
210
};
211 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioGyroDrdy = {
212 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioGyroDrdy,
213
  /* meta */ {
214
    /* direction      */ APAL_GPIO_DIRECTION_INPUT,
215
    /* active state   */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
216
    /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
217
  },
218
};
219 e545e620 Thomas Schöpping
220 1e5f7648 Thomas Schöpping
/**
221
 * @brief   SYS_UART_UP bidirectional signal GPIO.
222
 */
223
static apalGpio_t _gpioSysUartUp = {
224 e545e620 Thomas Schöpping
  /* port */ GPIOB,
225
  /* pad  */ GPIOB_SYS_UART_UP,
226
};
227 acc97cbf Thomas Schöpping
ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
228 1e5f7648 Thomas Schöpping
  /* GPIO */ &_gpioSysUartUp,
229
  /* meta */ {
230
    /* direction      */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
231
    /* active state   */ APAL_GPIO_ACTIVE_LOW,
232
    /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
233
  },
234