rusefi/firmware/hw_layer/smart_gpio.cpp

110 lines
2.4 KiB
C++
Raw Normal View History

2019-04-13 07:58:52 -07:00
/*
* @file smart_gpio.cpp
*
* @date Apr 13, 2019
* @author Andrey Belomutskiy, (c) 2012-2019
*/
#include "global.h"
#include "smart_gpio.h"
#include "efi_gpio.h"
#include "engine_configuration.h"
#include "gpio_ext.h"
#include "drivers/gpio/tle6240.h"
#include "drivers/gpio/mc33972.h"
#include "drivers/gpio/tle8888.h"
#if EFI_PROD_CODE
EXTERN_CONFIG;
const struct tle6240_config tle6240 = {
.spi_bus = NULL /* TODO software lookup &SPID4 */,
.spi_config = {
.circular = false,
.end_cb = NULL,
.ssport = GPIOF,
.sspad = 0U,
.cr1 =
SPI_CR1_SSM |
SPI_CR1_SSI |
/* SPI_CR1_LSBFIRST | */
((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | /* div = 16 */
SPI_CR1_MSTR |
/* SPI_CR1_CPOL | */ // = 0
SPI_CR1_CPHA | // = 1
0,
.cr2 = SPI_CR2_16BIT_MODE
},
.direct_io = {
/* IN1 - D_TACH_OUT */
[0] = {.port = GPIOG, .pad = 2},
/* IN2..4 grounded */
[1] = {.port = NULL},
[2] = {.port = NULL},
[3] = {.port = NULL},
/* IN9 - D_INJ_5 */
[4] = {.port = GPIOD, .pad = 15},
/* IN10 - D_WASTGATE */
[5] = {.port = GPIOD, .pad = 14},
/* IN11 - D_IDLE_OPEN */
[6] = {.port = GPIOC, .pad = 6},
/* IN12 - D_IDLE_CLOSE */
[7] = {.port = GPIOC, .pad = 7},
},
.reset = {.port = GPIOG, .pad = 3}
};
const struct mc33972_config mc33972 = {
.spi_bus = NULL /* TODO software lookup &SPID4 */,
.spi_config = {
.circular = false,
.end_cb = NULL,
.ssport = GPIOB,
.sspad = 4U,
.cr1 =
SPI_CR1_SSM |
SPI_CR1_SSI |
/* SPI_CR1_LSBFIRST | */
((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | /* div = 16 */
SPI_CR1_MSTR |
/* SPI_CR1_CPOL | */ /* = 0 */
SPI_CR1_CPHA | /* = 1 */
0,
.cr2 = SPI_CR2_24BIT_MODE
},
};
#endif /* EFI_PROD_CODE */
void initSmartGpio() {
#if (BOARD_TLE6240_COUNT > 0)
tle6240.spi_bus = getSpiDevice(engineConfiguration->tle6240spiDevice);
tle6240_add(0, &tle6240);
#else
gpiochip_use_gpio_base(TLE6240_OUTPUTS);
#endif
#if (BOARD_MC33972_COUNT > 0)
mc33972.spi_bus = getSpiDevice(engineConfiguration->mc33972spiDevice);
// todo: propogate 'basePinOffset' parameter
mc33972_add(0, &mc33972);
#else
gpiochip_use_gpio_base(MC33972_INPUTS);
#endif
#if EFI_TLE8888
if (engineConfiguration->tle8888_cs != GPIO_UNASSIGNED) {
static OutputPin tle8888Cs;
// // SPI pins are enabled in initSpiModules()
tle8888Cs.initPin("tle8888 CS", engineConfiguration->tle8888_cs,
&engineConfiguration->tle8888_csPinMode);
}
initTle8888(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_TLE8888 */
}