amiro-os / modules / LightRing_1-2 / module.c @ 510b93cc
History | View | Annotate | Download (19.942 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 | #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 | ee884101 | Thomas Schöpping | I2CConfig moduleHalI2cEepromPwrmtrBreakoutConfig = {
|
| 51 | 9ae7c4f3 | Thomas Schöpping | /* I²C mode */ OPMODE_I2C,
|
| 52 | /* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
||
| 53 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
| 54 | }; |
||
| 55 | |||
| 56 | SerialConfig moduleHalProgIfConfig = {
|
||
| 57 | /* bit rate */ 115200, |
||
| 58 | /* CR1 */ 0, |
||
| 59 | /* CR1 */ 0, |
||
| 60 | /* CR1 */ 0, |
||
| 61 | }; |
||
| 62 | |||
| 63 | SPIConfig moduleHalSpiLightConfig = {
|
||
| 64 | /* circular buffer mode */ false, |
||
| 65 | /* callback function pointer */ NULL, |
||
| 66 | 3106e8cc | Thomas Schöpping | /* chip select line port */ PAL_PORT(LINE_LIGHT_XLAT),
|
| 67 | /* chip select line pad number */ PAL_PAD(LINE_LIGHT_XLAT),
|
||
| 68 | 9ae7c4f3 | Thomas Schöpping | /* CR1 */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
|
| 69 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
||
| 70 | }; |
||
| 71 | |||
| 72 | f606f432 | Thomas Schöpping | #if (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10)
|
| 73 | 0b989911 | Cung Sang | |
| 74 | SPIConfig moduleHalSpiUwbHsConfig = {
|
||
| 75 | /* circular buffer mode */ false, |
||
| 76 | /* callback function pointer */ NULL, |
||
| 77 | /* chip select line port */ PAL_PORT(LINE_SPI_SS_N),
|
||
| 78 | /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
|
||
| 79 | /* CR1 */ 0, // 36/2 Mbps |
||
| 80 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN, // 0 |
||
| 81 | }; |
||
| 82 | f606f432 | Thomas Schöpping | |
| 83 | 0b989911 | Cung Sang | SPIConfig moduleHalSpiUwbLsConfig = {
|
| 84 | /* circular buffer mode */ false, |
||
| 85 | /* callback function pointer */ NULL, |
||
| 86 | /* chip select line port */ PAL_PORT(LINE_SPI_SS_N),
|
||
| 87 | /* chip select line pad number */ PAL_PAD(LINE_SPI_SS_N),
|
||
| 88 | /* CR1 */ SPI_CR1_BR_1 | SPI_CR1_BR_0, // 36/16 Mbps |
||
| 89 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN, // 0 |
||
| 90 | }; |
||
| 91 | |||
| 92 | f606f432 | Thomas Schöpping | #endif /* (BOARD_BREAKOUT_MODULE == BOARD_BREAKOUT_UWBv10) */ |
| 93 | 9ae7c4f3 | Thomas Schöpping | |
| 94 | /*===========================================================================*/
|
||
| 95 | /**
|
||
| 96 | * @name GPIO definitions
|
||
| 97 | * @{
|
||
| 98 | */
|
||
| 99 | /*===========================================================================*/
|
||
| 100 | |||
| 101 | /**
|
||
| 102 | * @brief LIGHT_BANK output signal GPIO.
|
||
| 103 | */
|
||
| 104 | static apalGpio_t _gpioLightBlank = {
|
||
| 105 | 3106e8cc | Thomas Schöpping | /* line */ LINE_LIGHT_BLANK,
|
| 106 | 9ae7c4f3 | Thomas Schöpping | }; |
| 107 | ROMCONST apalControlGpio_t moduleGpioLightBlank = {
|
||
| 108 | /* GPIO */ &_gpioLightBlank,
|
||
| 109 | /* meta */ {
|
||
| 110 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 111 | /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
||
| 112 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 113 | }, |
||
| 114 | }; |
||
| 115 | |||
| 116 | /**
|
||
| 117 | * @brief RS232_R_EN_N output signal GPIO.
|
||
| 118 | */
|
||
| 119 | static apalGpio_t _gpioRs232En = {
|
||
| 120 | 3106e8cc | Thomas Schöpping | /* line */ LINE_RS232_R_EN_N,
|
| 121 | 9ae7c4f3 | Thomas Schöpping | }; |
| 122 | ROMCONST apalControlGpio_t moduleGpioRs232En = {
|
||
| 123 | /* GPIO */ &_gpioRs232En,
|
||
| 124 | /* meta */ {
|
||
| 125 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 126 | /* active state */ APAL_GPIO_ACTIVE_LOW, //TODO |
||
| 127 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 128 | }, |
||
| 129 | }; |
||
| 130 | |||
| 131 | /**
|
||
| 132 | * @brief SW_V33_EN output signal GPIO.
|
||
| 133 | */
|
||
| 134 | static apalGpio_t _gpioSwV33En = {
|
||
| 135 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SW_V33_EN,
|
| 136 | 9ae7c4f3 | Thomas Schöpping | }; |
| 137 | ROMCONST apalControlGpio_t moduleGpioSwV33En = {
|
||
| 138 | /* GPIO */ &_gpioSwV33En,
|
||
| 139 | /* meta */ {
|
||
| 140 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 141 | ee884101 | Thomas Schöpping | /* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
| 142 | 9ae7c4f3 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
| 143 | }, |
||
| 144 | }; |
||
| 145 | |||
| 146 | 9acb8326 | Thomas Schöpping | // The 4.2V switch is disabled due to a hardware bug.
|
| 147 | ///**
|
||
| 148 | // * @brief SW_V42_EN output signal GPIO.
|
||
| 149 | // */
|
||
| 150 | //static apalGpio_t _gpioSwV42En = {
|
||
| 151 | // /* line */ LINE_SW_V42_EN,
|
||
| 152 | //};
|
||
| 153 | //ROMCONST apalControlGpio_t moduleGpioSwV42En = {
|
||
| 154 | // /* GPIO */ &_gpioSwV42En,
|
||
| 155 | // /* meta */ {
|
||
| 156 | // /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 157 | // /* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
||
| 158 | // /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 159 | // },
|
||
| 160 | //};
|
||
| 161 | 9ae7c4f3 | Thomas Schöpping | |
| 162 | /**
|
||
| 163 | * @brief SW_V50_EN output signal GPIO.
|
||
| 164 | */
|
||
| 165 | static apalGpio_t _gpioSwV50En = {
|
||
| 166 | 3106e8cc | Thomas Schöpping | /* line */ LINE_SW_V50_EN,
|
| 167 | 9ae7c4f3 | Thomas Schöpping | }; |
| 168 | ROMCONST apalControlGpio_t moduleGpioSwV50En = {
|
||
| 169 | /* GPIO */ &_gpioSwV50En,
|
||
| 170 | /* meta */ {
|
||
| 171 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 172 | ee884101 | Thomas Schöpping | /* active state */ MIC9404x_LLD_EN_ACTIVE_STATE,
|
| 173 | 9ae7c4f3 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
| 174 | }, |
||
| 175 | }; |
||
| 176 | |||
| 177 | /**
|
||
| 178 | f606f432 | Thomas Schöpping | * @brief SYS_UART_DN bidirectional signal GPIO.
|
| 179 | 9ae7c4f3 | Thomas Schöpping | */
|
| 180 | f606f432 | Thomas Schöpping | static apalGpio_t _gpioSysUartDn = {
|
| 181 | /* line */ LINE_SYS_UART_DN,
|
||
| 182 | 9ae7c4f3 | Thomas Schöpping | }; |
| 183 | f606f432 | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
|
| 184 | /* GPIO */ &_gpioSysUartDn,
|
||
| 185 | 9ae7c4f3 | Thomas Schöpping | /* meta */ {
|
| 186 | f606f432 | Thomas Schöpping | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
| 187 | 9ae7c4f3 | Thomas Schöpping | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
| 188 | f606f432 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
| 189 | 9ae7c4f3 | Thomas Schöpping | }, |
| 190 | }; |
||
| 191 | |||
| 192 | /**
|
||
| 193 | f606f432 | Thomas Schöpping | * @brief LED output signal GPIO.
|
| 194 | 9ae7c4f3 | Thomas Schöpping | */
|
| 195 | f606f432 | Thomas Schöpping | static apalGpio_t _gpioLed = {
|
| 196 | /* line */ LINE_LED,
|
||
| 197 | 9ae7c4f3 | Thomas Schöpping | }; |
| 198 | f606f432 | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLed = {
|
| 199 | /* GPIO */ &_gpioLed,
|
||
| 200 | 9ae7c4f3 | Thomas Schöpping | /* meta */ {
|
| 201 | f606f432 | Thomas Schöpping | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
| 202 | 9ae7c4f3 | Thomas Schöpping | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
| 203 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 204 | }, |
||
| 205 | }; |
||
| 206 | |||
| 207 | /**
|
||
| 208 | f606f432 | Thomas Schöpping | * @brief LIGHT_XLAT output signal GPIO.
|
| 209 | 9ae7c4f3 | Thomas Schöpping | */
|
| 210 | f606f432 | Thomas Schöpping | static apalGpio_t _gpioLightXlat = {
|
| 211 | /* line */ LINE_LIGHT_XLAT,
|
||
| 212 | 9ae7c4f3 | Thomas Schöpping | }; |
| 213 | f606f432 | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLightXlat = {
|
| 214 | /* GPIO */ &_gpioLightXlat,
|
||
| 215 | 9ae7c4f3 | Thomas Schöpping | /* meta */ {
|
| 216 | f606f432 | Thomas Schöpping | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
| 217 | /* active state */ (TLC5947_LLD_XLAT_UPDATE_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
| 218 | 9ae7c4f3 | Thomas Schöpping | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
| 219 | }, |
||
| 220 | }; |
||
| 221 | |||
| 222 | /**
|
||
| 223 | f606f432 | Thomas Schöpping | * @brief SW_V18_EN output signal GPIO.
|
| 224 | 9ae7c4f3 | Thomas Schöpping | */
|