diff --git a/firmware/Makefile b/firmware/Makefile index 06dbbe9317..f2891058fd 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -38,7 +38,7 @@ endif # C++ specific options here (added to USE_OPT). ifeq ($(USE_CPPOPT),) # constexpr float expf_taylor_impl probably needs just c++14 but why not go with 17? - USE_CPPOPT = -std=c++17 -Wno-register -fno-rtti -fno-exceptions -fno-use-cxa-atexit -Werror=write-strings -Werror=type-limits + USE_CPPOPT = -std=c++17 -Wno-register -fno-rtti -fno-threadsafe-statics -fno-exceptions -fno-use-cxa-atexit -Werror=write-strings -Werror=type-limits endif # Enable this if you want the linker to remove unused code and data diff --git a/firmware/controllers/system/efi_gpio.h b/firmware/controllers/system/efi_gpio.h index 91961886f8..f52e5c1a5a 100644 --- a/firmware/controllers/system/efi_gpio.h +++ b/firmware/controllers/system/efi_gpio.h @@ -21,6 +21,7 @@ void turnAllPinsOff(void); #define turnAllPinsOff() {} #endif /* EFI_GPIO_HARDWARE */ +#ifdef __cplusplus /** * @brief Single output pin reference and state */ @@ -143,6 +144,8 @@ public: NamedOutputPin auxValve[AUX_DIGITAL_VALVE_COUNT]; }; +#endif /* __cplusplus */ + /** * it's a macro to be sure that stack is not used * @return 0 for OM_DEFAULT and OM_OPENDRAIN @@ -161,8 +164,8 @@ public: #if EFI_GPIO_HARDWARE || defined(__DOXYGEN__) -ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin); -ioportid_t getHwPort(const char *msg, brain_pin_e brainPin); +EXTERNC ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin); +EXTERNC ioportid_t getHwPort(const char *msg, brain_pin_e brainPin); const char *portname(ioportid_t GPIOx); #endif /* EFI_GPIO_HARDWARE */ diff --git a/firmware/hw_layer/drivers/gpio/tle8888.c b/firmware/hw_layer/drivers/gpio/tle8888.c index 797fccdd13..81cb97c664 100644 --- a/firmware/hw_layer/drivers/gpio/tle8888.c +++ b/firmware/hw_layer/drivers/gpio/tle8888.c @@ -19,6 +19,7 @@ EXTERN_CONFIG; #include "hardware.h" +#include "efi_gpio.h" #include "gpio/gpio_ext.h" #include "gpio/tle8888.h" #include "pin_repository.h" @@ -261,7 +262,7 @@ int tle8888_add(unsigned int index, const struct tle8888_config *cfg) /* this should be in board file */ static struct tle8888_config tle8888_cfg = { - .spi_bus = NULL/*&SPID4*/, + .spi_bus = NULL, .spi_config = { .circular = false, .end_cb = NULL, @@ -291,7 +292,19 @@ static struct tle8888_config tle8888_cfg = { void initTle8888(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + if (engineConfiguration->tle8888_cs == GPIO_UNASSIGNED) { + return; + } + + // todo: reuse initSpiCs method? + tle8888_cfg.spi_config.ssport = getHwPort("tle8888", engineConfiguration->tle8888_cs); + tle8888_cfg.spi_config.sspad = getHwPin("tle8888", engineConfiguration->tle8888_cs); + tle8888_cfg.spi_bus = getSpiDevice(engineConfiguration->tle8888spiDevice); + if (tle8888_cfg.spi_bus == NULL) { + // error already reported + return; + } tle8888_add(0, &tle8888_cfg); } diff --git a/firmware/hw_layer/drivers/gpio/tle8888.h b/firmware/hw_layer/drivers/gpio/tle8888.h index 7df8dcbe03..62e7c4673d 100644 --- a/firmware/hw_layer/drivers/gpio/tle8888.h +++ b/firmware/hw_layer/drivers/gpio/tle8888.h @@ -25,7 +25,7 @@ /* note that spi transfer should be LSB first */ struct tle8888_config { SPIDriver *spi_bus; - const SPIConfig spi_config; + SPIConfig spi_config; /* bidirectional, check DS */ struct { ioportid_t port; diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index a0b67a7718..6aebcf4e7a 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -159,6 +159,8 @@ void initI2Cmodule(void) { //static char txbuf[1]; static void sendI2Cbyte(int addr, int data) { + (void)addr; + (void)data; // i2cAcquireBus(&I2CD1); // txbuf[0] = data; // i2cMasterTransmit(&I2CD1, addr, txbuf, 1, NULL, 0); @@ -458,6 +460,13 @@ void initHardware(Logging *l) { #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