Smart gpios fixes - now without cleanup of smart_gpio.cpp (#758)

* smart_gpio.cpp: check _add return values

And occupy gpiochip's pin range if disabled of failed. So base will
align with enum.

* TLE8888: cleanup, move high level code to smart_gpio.cpp

* smart_gpio.cpp: fix compilation when BOARD_EXT_GPIOCHIPS == 0

* board-subaru: fix compilation after latest smart_gpio updates

* tle8888: now we have all 28 pins supported
This commit is contained in:
dron0gus 2019-04-16 16:23:24 +03:00 committed by rusefi
parent b4f87ee4a9
commit ec75c47b73
6 changed files with 70 additions and 86 deletions

View File

@ -27,13 +27,15 @@
*/ */
#define BOARD_NAME "Subaru EJ20G/STM32F765 for RusEFI" #define BOARD_NAME "Subaru EJ20G/STM32F765 for RusEFI"
#undef BOARD_TLE6240_COUNT
#define BOARD_TLE6240_COUNT 1 #define BOARD_TLE6240_COUNT 1
#undef BOARD_MC33972_COUNT
#define BOARD_MC33972_COUNT 1 #define BOARD_MC33972_COUNT 1
#undef BOARD_TLE8888_COUNT
#define BOARD_TLE8888_COUNT 0
#define BOARD_EXT_GPIOCHIPS (BOARD_TLE6240_COUNT + BOARD_MC33972_COUNT) #undef BOARD_EXT_GPIOCHIPS
#define BOARD_EXT_GPIOCHIPS (BOARD_TLE6240_COUNT + BOARD_MC33972_COUNT + BOARD_TLE8888_COUNT)
/* additional space for pins on gpioext */
#define BOARD_EXT_PINREPOPINS (16 + 22)
/* /*
* Board oscillators-related settings. * Board oscillators-related settings.

View File

@ -25,6 +25,10 @@
/* do not use serial device for console */ /* do not use serial device for console */
#undef TS_SERIAL_DEVICE #undef TS_SERIAL_DEVICE
/* additional space for pins on gpioext */
#undef BOARD_EXT_PINREPOPINS
#define BOARD_EXT_PINREPOPINS (16 + 22)
#undef EFI_RTC #undef EFI_RTC
#define EFI_RTC FALSE #define EFI_RTC FALSE

View File

@ -317,9 +317,11 @@ const char *gpiochips_getPinName(unsigned int pin)
return NULL; return NULL;
} }
/** void gpiochip_use_gpio_base(int size)
* @return result code {
*/ (void)size;
}
int gpiochip_register(const char *name, struct gpiochip_ops *ops, size_t size, void *priv) int gpiochip_register(const char *name, struct gpiochip_ops *ops, size_t size, void *priv)
{ {
(void)name; (void)ops; (void)size; (void)priv; (void)name; (void)ops; (void)size; (void)priv;

View File

@ -14,29 +14,20 @@
#include "global.h" #include "global.h"
#include "gpio/tle8888.h"
#if (BOARD_TLE8888_COUNT > 0) #if (BOARD_TLE8888_COUNT > 0)
/* to be moved to smart_gpio.cpp */
#include "engine_configuration.h"
/* to be moved to smart_gpio.cpp */
EXTERN_CONFIG;
#include "smart_gpio.h"
#include "hardware.h" #include "hardware.h"
#include "efi_gpio.h"
#include "gpio/gpio_ext.h" #include "gpio/gpio_ext.h"
#include "gpio/tle8888.h"
#include "pin_repository.h" #include "pin_repository.h"
#include "rfiutil.h" #include "rfiutil.h"
#include "mpu_util.h"
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
#include "tunerstudio.h" #include "tunerstudio.h"
extern TunerStudioOutputChannels tsOutputChannels; extern TunerStudioOutputChannels tsOutputChannels;
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
#if (BOARD_TLE8888_COUNT > 0)
/* /*
* TODO list: * TODO list:
*/ */
@ -526,57 +517,4 @@ int tle8888_add(unsigned int index, const struct tle8888_config *cfg)
return -1; return -1;
} }
#endif /* BOARD_TLE8888_COUNT */
/*********TO BE REMOVED FROM THIS FILE***************/
/* this should be in board file */
static struct tle8888_config tle8888_cfg = {
.spi_bus = NULL,
.spi_config = {
.circular = false,
.end_cb = NULL,
.ssport = GPIOF,
.sspad = 0U,
.cr1 =
SPI_CR1_16BIT_MODE |
SPI_CR1_SSM |
SPI_CR1_SSI |
SPI_CR1_LSBFIRST | //LSB first
((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | // div = 16
SPI_CR1_MSTR |
SPI_CR1_CPHA |
0,
.cr2 = SPI_CR2_16BIT_MODE
},
.direct_io = {
[0] = {.port = NULL, .pad = 0, .output = 9},
[1] = {.port = NULL, .pad = 0, .output = 10},
[2] = {.port = NULL, .pad = 0, .output = 11},
[3] = {.port = NULL, .pad = 0, .output = 12},
},
};
void initTle8888(DECLARE_ENGINE_PARAMETER_SIGNATURE)
{
if (engineConfiguration->tle8888_cs == GPIO_UNASSIGNED) {
return;
}
// todo: reuse initSpiCs method?
tle8888_cfg.spi_config.ssport = getHwPort(DRIVER_NAME " CS", engineConfiguration->tle8888_cs);
tle8888_cfg.spi_config.sspad = getHwPin(DRIVER_NAME " CS", engineConfiguration->tle8888_cs);
tle8888_cfg.spi_bus = getSpiDevice(engineConfiguration->tle8888spiDevice);
if (tle8888_cfg.spi_bus == NULL) {
// error already reported
return;
}
int chipBase = tle8888_add(0, &tle8888_cfg);
efiAssertVoid(OBD_PCM_Processor_Fault, chipBase == TLE8888_PIN_1, "tle8888");
}
/*********TO BE REMOVED FROM THIS FILE ENDS***********/
#endif /* (BOARD_TLE8888_COUNT > 0) */ #endif /* (BOARD_TLE8888_COUNT > 0) */

View File

@ -13,8 +13,7 @@
#include <hal.h> #include <hal.h>
#include "efifeatures.h" #include "efifeatures.h"
// todo: did we forget some outputs? should it be 28? #define TLE8888_OUTPUTS 28
#define TLE8888_OUTPUTS 24
/* 4 misc channels */ /* 4 misc channels */
#define TLE8888_DIRECT_MISC 4 #define TLE8888_DIRECT_MISC 4
/* 4 IGN channels - INJ1..4 - IN1..4 /* 4 IGN channels - INJ1..4 - IN1..4
@ -47,9 +46,6 @@ extern "C"
{ {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* cleanup !!!! */
void initTle8888(DECLARE_ENGINE_PARAMETER_SIGNATURE);
/** /**
* @return return gpio chip base * @return return gpio chip base
*/ */

View File

@ -100,34 +100,76 @@ struct mc33972_config mc33972 = {
}; };
#endif /* (BOARD_MC33972_COUNT > 0) */ #endif /* (BOARD_MC33972_COUNT > 0) */
#if (BOARD_TLE8888_COUNT > 0)
/* this is homeless tle8888, please find better place for it */
static struct tle8888_config tle8888_cfg = {
.spi_bus = NULL,
.spi_config = {
.circular = false,
.end_cb = NULL,
.ssport = GPIOF,
.sspad = 0U,
.cr1 =
SPI_CR1_16BIT_MODE |
SPI_CR1_SSM |
SPI_CR1_SSI |
SPI_CR1_LSBFIRST | //LSB first
((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | // div = 16
SPI_CR1_MSTR |
SPI_CR1_CPHA |
0,
.cr2 = SPI_CR2_16BIT_MODE
},
.direct_io = {
[0] = {.port = NULL, .pad = 0, .output = 9},
[1] = {.port = NULL, .pad = 0, .output = 10},
[2] = {.port = NULL, .pad = 0, .output = 11},
[3] = {.port = NULL, .pad = 0, .output = 12},
},
};
#endif
void initSmartGpio() { void initSmartGpio() {
int ret;
#if (BOARD_TLE6240_COUNT > 0) #if (BOARD_TLE6240_COUNT > 0)
tle6240.spi_bus = getSpiDevice(engineConfiguration->tle6240spiDevice); tle6240.spi_bus = getSpiDevice(engineConfiguration->tle6240spiDevice);
tle6240_add(0, &tle6240); ret = tle6240_add(0, &tle6240);
#elif (BOARD_EXT_GPIOCHIPS > 0) if (ret < 0)
gpiochip_use_gpio_base(TLE6240_OUTPUTS);
#endif /* (BOARD_TLE6240_COUNT > 0) */ #endif /* (BOARD_TLE6240_COUNT > 0) */
/* whenever chip is disabled or error returned - occupy its gpio range */
gpiochip_use_gpio_base(TLE6240_OUTPUTS);
#if (BOARD_MC33972_COUNT > 0) #if (BOARD_MC33972_COUNT > 0)
mc33972.spi_bus = getSpiDevice(engineConfiguration->mc33972spiDevice); mc33972.spi_bus = getSpiDevice(engineConfiguration->mc33972spiDevice);
// todo: propogate 'basePinOffset' parameter // todo: propogate 'basePinOffset' parameter
mc33972_add(0, &mc33972); ret = mc33972_add(0, &mc33972);
#elif (BOARD_EXT_GPIOCHIPS > 0) if (ret < 0)
gpiochip_use_gpio_base(MC33972_INPUTS);
#endif /* (BOARD_MC33972_COUNT > 0) */ #endif /* (BOARD_MC33972_COUNT > 0) */
/* whenever chip is disabled or error returned - occupy its gpio range */
gpiochip_use_gpio_base(MC33972_INPUTS);
#if (BOARD_TLE8888_COUNT > 0) #if (BOARD_TLE8888_COUNT > 0)
if (engineConfiguration->tle8888_cs != GPIO_UNASSIGNED) { if (engineConfiguration->tle8888_cs != GPIO_UNASSIGNED) {
static OutputPin tle8888Cs; static OutputPin tle8888Cs;
// // SPI pins are enabled in initSpiModules() // SPI pins are enabled in initSpiModules()
tle8888Cs.initPin("tle8888 CS", engineConfiguration->tle8888_cs, tle8888Cs.initPin("tle8888 CS", engineConfiguration->tle8888_cs,
&engineConfiguration->tle8888_csPinMode); &engineConfiguration->tle8888_csPinMode);
}
initTle8888(PASS_ENGINE_PARAMETER_SIGNATURE); // todo: reuse initSpiCs method?
tle8888_cfg.spi_config.ssport = getHwPort("tle8888 CS", engineConfiguration->tle8888_cs);
tle8888_cfg.spi_config.sspad = getHwPin("tle8888 CS", engineConfiguration->tle8888_cs);
tle8888_cfg.spi_bus = getSpiDevice(engineConfiguration->tle8888spiDevice);
/* spi_bus == null checked in _add function */
ret = tle8888_add(0, &tle8888_cfg);
efiAssertVoid(OBD_PCM_Processor_Fault, ret == TLE8888_PIN_1, "tle8888");
}
if (ret < 0)
#endif /* (BOARD_TLE6240_COUNT > 0) */ #endif /* (BOARD_TLE6240_COUNT > 0) */
/* whenever chip is disabled or error returned - occupy its gpio range */
gpiochip_use_gpio_base(TLE8888_OUTPUTS);
#if (BOARD_EXT_GPIOCHIPS > 0) #if (BOARD_EXT_GPIOCHIPS > 0)
/* external chip init */ /* external chip init */