amiro-os / modules / DiWheelDrive_1-1 / module.c @ 83e58975
History | View | Annotate | Download (17.709 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 | 3106e8cc | Thomas Schöpping | /* chip select line port */ PAL_PORT(LINE_ACCEL_SS_N),
|
| 115 | /* chip select line pad number */ PAL_PAD(LINE_ACCEL_SS_N),
|
||
| 116 | e545e620 | Thomas Schöpping | /* 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 | 3106e8cc | Thomas Schöpping | /* chip select line port */ PAL_PORT(LINE_GYRO_SS_N),
|
| 124 | /* chip select line pad number */ PAL_PAD(LINE_GYRO_SS_N),
|
||
| 125 | e545e620 | Thomas Schöpping | /* 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 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LED,
|
| 143 | e545e620 | Thomas Schöpping | }; |
| 144 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLed = {
|
| 145 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLed,
|
| 146 | /* meta */ {
|
||
| 147 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 148 | 4c72a54c | Thomas Schöpping | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
| 149 | 1e5f7648 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
| 150 | }, |
||
| 151 | }; |
||
| 152 | e545e620 | Thomas Schöpping | |
| 153 | 1e5f7648 | Thomas Schöpping | /**
|
| 154 | * @brief POWER_EN output signal GPIO.
|
||
| 155 | */
|
||
| 156 | static apalGpio_t _gpioPowerEn = {
|
||
| 157 | 3106e8cc | Thomas Schöpping | /* line */ LINE_POWER_EN,
|
| 158 | e545e620 | Thomas Schöpping | }; |
| 159 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioPowerEn = {
|
| 160 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioPowerEn,
|
| 161 | /* meta */ {
|
||
| 162 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 163 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 164 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 165 | }, |
||
| 166 | }; |
||
| 167 | e545e620 | Thomas Schöpping | |
| 168 | 1e5f7648 | Thomas Schöpping | /**
|
| 169 | * @brief COMPASS_DRDY output signal GPIO.
|
||
| 170 | */
|
||
| 171 | static apalGpio_t _gpioCompassDrdy = {
|
||
| 172 | 3106e8cc | Thomas Schöpping | /* line */ LINE_COMPASS_DRDY,
|
| 173 | e545e620 | Thomas Schöpping | }; |
| 174 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioCompassDrdy = {
|
| 175 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioCompassDrdy,
|
| 176 | /* meta */ {
|
||
| 177 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 178 | /* active state */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
| 179 | /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
|
||
| 180 | }, |
||
| 181 | }; |
||
| 182 | e545e620 | Thomas Schöpping | |
| 183 | 1e5f7648 | Thomas Schöpping | /**
|
| 184 | * @brief IR_INT input signal GPIO.
|
||
| 185 | */
|
||
| 186 | static apalGpio_t _gpioIrInt = {
|
||
| 187 | 3106e8cc | Thomas Schöpping | /* line */ LINE_IR_INT,
|
| 188 | e545e620 | Thomas Schöpping | }; |
| 189 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioIrInt = {
|
| 190 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioIrInt,
|
| 191 | /* meta */ {
|
||
| 192 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 193 | /* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
| 194 | /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
||
| 195 | }, |
||
| 196 | }; |
||
| 197 | e545e620 | Thomas Schöpping | |
| 198 | 1e5f7648 | Thomas Schöpping | /**
|
| 199 | * @brief GYRO_DRDY input signal GPIO.
|
||
| 200 | */
|
||
| 201 | static apalGpio_t _gpioGyroDrdy = {
|
||
| 202 | 3106e8cc | Thomas Schöpping | /* line */ LINE_GYRO_DRDY,
|
| 203 | e545e620 | Thomas Schöpping | }; |
| 204 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioGyroDrdy = {
|
| 205 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioGyroDrdy,
|
| 206 | /* meta */ {
|
||
| 207 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 208 | /* active state */ (L3G4200D_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
| 209 | /* interrupt edge */ L3G4200D_LLD_INT_EDGE,
|
||
| 210 | }, |
||
| 211 | }; |
||
| 212 | e545e620 | Thomas Schöpping | |
| 213 | 1e5f7648 | Thomas Schöpping | /**
|
| 214 | * @brief SYS_UART_UP bidirectional signal GPIO.
|
||
| 215 | */
|
||
| 216 | static apalGpio_t _gpioSysUartUp = {
|
||
| 217 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SYS_UART_UP,
|
| 218 | e545e620 | Thomas Schöpping | }; |
| 219 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartUp = {
|
| 220 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysUartUp,
|
| 221 | /* meta */ {
|
||
| 222 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
| 223 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 224 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 225 |