Smart gpios fixes 3 (#795)

* pin_repository: provide readable pin names in error cases

* io_pins: remove getBrain_pin_eExt

We have getBrain_pin_eExt in io_pins.cpp and hwPortname in
pin_repository.cpp.
First uses auto-generated enums, second one uses runtime data to
provide name of hw pin.
Removing first saves us about 2K of flash couse big auto-generated
switch with pin names no more used by anyone and gets optimized out.

* gpios: mc33972: CS pin is now requested at smart_gpios.pcc

* getSpiDevice: support SPI4

* smart_gpios.cpp: startSmartCsPins set CSs to inactive state

OutputPin:initPin initializes pin with false value. This is active
state for SPI Chip Selects. Set to 1 to deselect all chips.
This commit is contained in:
dron0gus 2019-05-10 01:09:24 +03:00 committed by rusefi
parent dd6e7642bd
commit 04ee37548b
6 changed files with 22 additions and 26 deletions

View File

@ -112,8 +112,6 @@ const char *gpiochips_getPinName(unsigned int pin)
offset = pin - chip->base;
if ((chip->gpio_names) && (chip->gpio_names[offset]))
return chip->gpio_names[offset];
else
return chip->name;
}
return NULL;

View File

@ -294,13 +294,8 @@ int mc33972_init(void * data)
{
int ret;
struct mc33972_priv *chip;
const struct mc33972_config *cfg;
chip = (struct mc33972_priv *)data;
cfg = chip->cfg;
/* mark pins used */
ret = gpio_pin_markUsed(cfg->spi_config.ssport, cfg->spi_config.sspad, DRIVER_NAME " CS");
ret = mc33972_chip_init(chip);
if (ret)

View File

@ -135,6 +135,11 @@ SPIDriver * getSpiDevice(spi_device_e spiDevice) {
if (spiDevice == SPI_DEVICE_3) {
return &SPID3;
}
#endif
#if STM32_SPI_USE_SPI4
if (spiDevice == SPI_DEVICE_4) {
return &SPID4;
}
#endif
firmwareError(CUSTOM_ERR_UNEXPECTED_SPI, "Unexpected SPI device: %d", spiDevice);
return NULL;

View File

@ -52,18 +52,6 @@ bool efiReadPin(brain_pin_e pin) {
return false;
}
static const char *getBrain_pin_eExt(brain_pin_e value){
const char * result = getBrain_pin_e(value);
if (result != NULL)
return result;
#if (BOARD_EXT_GPIOCHIPS > 0)
/* gpichips */
return gpiochips_getPinName(value);
#else
return NULL;
#endif
}
/**
* This method would set an error condition if pin is already used
*/
@ -73,10 +61,6 @@ void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
//efiAssertVoid(OBD_PCM_Processor_Fault, pin != EFI_ERROR_CODE, "pin_error");
#if ! EFI_BOOTLOADER
scheduleMsg(&logger, "%s on %s", msg, getBrain_pin_eExt(brainPin));
#endif
wasUsed = brain_pin_markUsed(brainPin, msg);
if (!wasUsed) {

View File

@ -195,8 +195,15 @@ const char *hwPortname(brain_pin_e brainPin) {
}
#if (BOARD_EXT_GPIOCHIPS > 0)
else {
chprintf((BaseSequentialStream *) &portNameStream, "ext:%s.%d (%s)",
gpiochips_getChipName(brainPin), gpiochips_getPinOffset(brainPin), gpiochips_getPinName(brainPin));
const char *pin_name = gpiochips_getPinName(brainPin);
if (pin_name) {
chprintf((BaseSequentialStream *) &portNameStream, "ext:%s",
pin_name);
} else {
chprintf((BaseSequentialStream *) &portNameStream, "ext:%s.%d",
gpiochips_getChipName(brainPin), gpiochips_getPinOffset(brainPin));
}
}
#endif
portNameStream.buffer[portNameStream.eos] = 0; // need to terminate explicitly
@ -253,6 +260,10 @@ bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg)
return false;
}
#if ! EFI_BOOTLOADER
scheduleMsg(&logger, "%s on %s", msg, hwPortname(brainPin));
#endif
index = brainPin_to_index(brainPin);
if (index < 0)
return true;
@ -264,7 +275,7 @@ bool brain_pin_markUsed(brain_pin_e brainPin, const char *msg)
* connected, so the warning is never displayed on the console and that's quite a problem!
*/
// warning(OBD_PCM_Processor_Fault, "brain pin %d req by %s used by %s", brainPin, msg, PIN_USED[index]);
firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_1, "brain pin %d req by %s used by %s", brainPin, msg, PIN_USED[index]);
firmwareError(CUSTOM_ERR_PIN_ALREADY_USED_1, "brain pin %s req by %s used by %s", hwPortname(brainPin), msg, PIN_USED[index]);
return true;
}

View File

@ -205,14 +205,17 @@ void startSmartCsPins() {
#if (BOARD_TLE8888_COUNT > 0)
tle8888Cs.initPin("tle8888 CS", engineConfiguration->tle8888_cs,
&engineConfiguration->tle8888_csPinMode);
tle8888Cs.setValue(true);
#endif /* BOARD_TLE8888_COUNT */
#if (BOARD_TLE6240_COUNT > 0)
tle6240Cs.initPin("tle6240 CS", engineConfiguration->tle6240_cs,
&engineConfiguration->tle6240_csPinMode);
tle6240Cs.setValue(true);
#endif /* BOARD_TLE6240_COUNT */
#if (BOARD_MC33972_COUNT > 0)
mc33972Cs.initPin("mc33972 CS", boardConfiguration->mc33972_cs,
&boardConfiguration->mc33972_csPinMode);
mc33972Cs.setValue(true);
#endif /* BOARD_MC33972_COUNT */
}
#endif /* (BOARD_EXT_GPIOCHIPS > 0) */