rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
board_configuration.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "hellen_meta.h"
3#include "defaults.h"
4#include "smart_gpio.h"
6#include "board_overrides.h"
7
8// Configurable 2.7K pull-ups to 5V
12
13// Configurable 750R pull-up to 5V or 220+750R to 12V
15
16// Configurable 4.470K pull-ups to 12V
23
34
35static void setIgnitionPins() {
36 engineConfiguration->ignitionPins[0] = Gpio::H144_IGN_1;
37 engineConfiguration->ignitionPins[1] = Gpio::H144_IGN_2;
38 engineConfiguration->ignitionPins[2] = Gpio::H144_IGN_3;
39 engineConfiguration->ignitionPins[3] = Gpio::H144_IGN_4;
40 engineConfiguration->ignitionPins[4] = Gpio::H144_IGN_5;
41 engineConfiguration->ignitionPins[5] = Gpio::H144_IGN_6;
42 engineConfiguration->ignitionPins[6] = Gpio::H144_IGN_7;
43 engineConfiguration->ignitionPins[7] = Gpio::H144_IGN_8;
44}
45
47 setTPS1Inputs(H144_IN_TPS, H144_IN_TPS2);
48 setPPSInputs(H144_IN_PPS, H144_IN_PPS2);
49
53 // default is 5V pull-up
61
62 engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH;
63 engineConfiguration->triggerInputPins[0] = Gpio::H144_IN_VSS; // VR Input 3 (MAX9924)
64 engineConfiguration->camInputs[0] = Gpio::H144_IN_MAP1_DIGITAL; // cannot be used simultaneously with VR1
65
66 // A18 + A22
67 setTPS1Inputs(H144_IN_TPS, H144_IN_TPS2);
68 // B19 + B20
69 setPPSInputs(H144_IN_PPS, H144_IN_PPS2);
70
71 engineConfiguration->map.sensor.hwChannel = H144_IN_O2S2; // external MAP
72// engineConfiguration->map.sensor.hwChannel = H144_IN_MAP2; // On-board MAP
73 engineConfiguration->map.sensor.type = MT_MPXH6400;
74
75 engineConfiguration->afr.hwChannel = EFI_ADC_NONE;
76 engineConfiguration->clt.adcChannel = H144_IN_CLT;
77 engineConfiguration->iat.adcChannel = H144_IN_IAT;
78}
79
82
86 setDefaultHellenAtPullUps(2700); // wow this board is unusual?!
87
88 /* Four TLE9104 */
90}
91
92static void setDefaultETBPins() {
93 // users would want to override those if using H-bridges for stepper idle control
94 setupTLE9201IncludingStepper(/*PWM controlPin*/Gpio::H144_OUT_PWM1, /*direction*/Gpio::H144_OUT_PWM6, /*disable*/Gpio::H144_OUT_PWM5, /*dcIndex*/0);
95 setupTLE9201IncludingStepper(/*PWM controlPin*/Gpio::H144_OUT_PWM2, /*direction*/Gpio::H144_OUT_PWM4, /*disable*/Gpio::H144_OUT_PWM3, /*dcIndex*/1);
96}
97
98/**
99 * @brief Board-specific configuration defaults.
100 *
101 * See also setDefaultEngineConfiguration
102 *
103 */
110
112 engineConfiguration->firingOrder = FO_1_8_7_2_6_5_4_3;
113
116
118
119 // Done in setBoardConfigOverrides() -> setHellenCan() ?
120 engineConfiguration->canTxPin = H144_CAN_TX;
121 engineConfiguration->canRxPin = H144_CAN_RX;
122
124
125 // Done in setBoardConfigOverrides() -> enableHellenSpi2() ?
126 // SPI2 for TLE9104 diagnostics
128 engineConfiguration->spi2mosiPin = H_SPI2_MOSI;
129 engineConfiguration->spi2misoPin = H_SPI2_MISO;
130 engineConfiguration->spi2sckPin = H_SPI2_SCK;
131
132 engineConfiguration->vrThreshold[0].pin = Gpio::H144_OUT_PWM7;
133 engineConfiguration->vrThreshold[1].pin = Gpio::H144_OUT_PWM8;
134}
135
136/*
137 * RESET and EN signals of both TLE9104 are driven by same gpios,
138 * Do not allow TLE driver to drive this pins as it will reset
139 * first chip while initing second.
140 * Set pins to proper state only once.
141 * TODO: improve?
142 */
143static const tle9104_config tle9104_cfg[BOARD_TLE9104_COUNT] = {
144 // INJ_LO
145 {
146 .spi_bus = &SPID2,
147 .spi_config = {
148 .circular = false,
149#ifdef _CHIBIOS_RT_CONF_VER_6_1_
150 .end_cb = nullptr,
151#else
152 .slave = false,
153 .data_cb = nullptr,
154 .error_cb = nullptr,
155#endif
156 .ssport = GPIOC,
157 .sspad = 10, // 9104_CSN_INJ_LO <- SPI3_SCK
158 .cr1 =
159 SPI_CR1_16BIT_MODE |
160 SPI_CR1_SSM |
161 SPI_CR1_SSI |
162 ((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | // div = 16
163 SPI_CR1_MSTR |
164 SPI_CR1_CPHA |
165 0,
166 .cr2 = SPI_CR2_16BIT_MODE
167 },
168 .direct_io = {
169 { .port = GPIOG, .pad = 7 }, // OUT_INJ1
170 { .port = GPIOG, .pad = 8 }, // OUT_INJ2
171 { .port = GPIOD, .pad = 11 }, // OUT_INJ3
172 { .port = GPIOD, .pad = 10 } // OUT_INJ4
173 },
174 .resn = Gpio::Unassigned, // Gpio::B12, // 9104_EN <- SPI2_CS/CAN2_RX
175 .en = Gpio::Unassigned // Gpio::A10 // 9104_RESN <- USBID
176 },
177 // INJ_HI
178 {
179 .spi_bus = &SPID2,
180 .spi_config = {
181 .circular = false,
182#ifdef _CHIBIOS_RT_CONF_VER_6_1_
183 .end_cb = nullptr,
184#else
185 .slave = false,
186 .data_cb = nullptr,
187 .error_cb = nullptr,
188#endif
189 .ssport = GPIOC,
190 .sspad = 11, // 9104_CSN_INJ_HI <- SPI3_MISO
191 .cr1 =
192 SPI_CR1_16BIT_MODE |
193 SPI_CR1_SSM |
194 SPI_CR1_SSI |
195 ((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | // div = 16
196 SPI_CR1_MSTR |
197 SPI_CR1_CPHA |
198 0,
199 .cr2 = SPI_CR2_16BIT_MODE
200 },
201 .direct_io = {
202 { .port = GPIOD, .pad = 9 }, // OUT_INJ5
203 { .port = GPIOF, .pad = 12 }, // OUT_INJ6
204 { .port = GPIOF, .pad = 13 }, // OUT_INJ7
205 { .port = GPIOF, .pad = 14 } // OUT_INJ8
206 },
207 .resn = Gpio::Unassigned, // Gpio::B12, // 9104_EN <- SPI2_CS/CAN2_RX
208 .en = Gpio::Unassigned // Gpio::A10 // 9104_RESN <- USBID
209 },
210 // AUX1-4
211 {
212 .spi_bus = &SPID2,
213 .spi_config = {
214 .circular = false,
215#ifdef _CHIBIOS_RT_CONF_VER_6_1_
216 .end_cb = nullptr,
217#else
218 .slave = false,
219 .data_cb = nullptr,
220 .error_cb = nullptr,
221#endif
222 .ssport = GPIOC,
223 .sspad = 12, // 9104_CSN_AUX1 <- SPI3_MOSI
224 .cr1 =
225 SPI_CR1_16BIT_MODE |
226 SPI_CR1_SSM |
227 SPI_CR1_SSI |
228 ((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | // div = 16
229 SPI_CR1_MSTR |
230 SPI_CR1_CPHA |
231 0,
232 .cr2 = SPI_CR2_16BIT_MODE
233 },
234 .direct_io = {
235 { .port = GPIOD, .pad = 3 }, // AUX_LS2 <- OUT_IO1
236 { .port = GPIOA, .pad = 9 }, // AUX_LS1 <- OUT_IO2
237 { .port = GPIOG, .pad = 14 }, // IO3 <- OUT_IO3
238 { .port = GPIOG, .pad = 5 } // TACH <- OUT_IO4
239 },
240 .resn = Gpio::Unassigned, // Gpio::B12, // 9104_EN <- SPI2_CS/CAN2_RX
241 .en = Gpio::Unassigned // Gpio::A10 // 9104_RESN <- USBID
242 },
243 // MISC
244 {
245 .spi_bus = &SPID2,
246 .spi_config = {
247 .circular = false,
248#ifdef _CHIBIOS_RT_CONF_VER_6_1_
249 .end_cb = nullptr,
250#else
251 .slave = false,
252 .data_cb = nullptr,
253 .error_cb = nullptr,
254#endif
255 .ssport = GPIOA,
256 .sspad = 15, // 9104_CSN_AUX2 <- SPI3_CS
257 .cr1 =
258 SPI_CR1_16BIT_MODE |
259 SPI_CR1_SSM |
260 SPI_CR1_SSI |
261 ((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | // div = 16
262 SPI_CR1_MSTR |
263 SPI_CR1_CPHA |
264 0,
265 .cr2 = SPI_CR2_16BIT_MODE
266 },
267 .direct_io = {
268 { .port = GPIOD, .pad = 2 }, // AUX_LS5 <- OUT_IO5
269 { .port = GPIOG, .pad = 11 }, // AUX_LS3 <- OUT_IO6
270 { .port = GPIOG, .pad = 3 }, // AUX_LS4 <- OUT_IO7
271 { .port = GPIOG, .pad = 4 } // MAIN_RELAY <- OUT_IO8
272 },
273 .resn = Gpio::Unassigned, // Gpio::B12, // 9104_EN <- SPI2_CS/CAN2_RX
274 .en = Gpio::Unassigned // Gpio::A10 // 9104_RESN <- USBID
275 }
276};
277
278static void board_init_ext_gpios() {
279 /* Waste of RAM, switch to palSetPadMode() and palSetPort() */
280 {
281 static OutputPin TleCs0;
282 TleCs0.initPin("TLE9104 CS0", Gpio::C10);
283 TleCs0.setValue(1);
284 }
285 {
286 static OutputPin TleCs1;
287 TleCs1.initPin("TLE9104 CS1", Gpio::C11);
288 TleCs1.setValue(1);
289 }
290 {
291 static OutputPin TleCs2;
292 TleCs2.initPin("TLE9104 CS2", Gpio::C12);
293 TleCs2.setValue(1);
294 }
295 {
296 static OutputPin TleCs3;
297 TleCs3.initPin("TLE9104 CS3", Gpio::A15);
298 TleCs3.setValue(1);
299 }
300
301 {
302 static OutputPin TleReset;
303 TleReset.initPin("TLE9104 Reset", Gpio::B12);
304 TleReset.setValue(1);
305
306 static OutputPin TleEn;
307 TleEn.initPin("TLE9104 En", Gpio::A10);
308 TleEn.setValue(1);
309 }
310
312}
313
314/**
315 * @brief Board-specific initialization code.
316 */
318 // TEMP_PULLUP
319 alphaTempPullUp.initPin("Temp PullUp", Gpio::H144_GP_IO3);
320 // IN_KNOCK1_PULLUP
321 alphaKnock1PullUp.initPin("Knock1 PullUp", Gpio::H144_GP_IO4);
322 // IN_KNOCK2_PULL
323 alphaKnock2PullUp.initPin("Knock2 PullUp", Gpio::H144_GP_IO5);
324 // TACH_PULLUP
325 alphaTachSelPullUp.initPin("Tach PullUp", Gpio::H144_OUT_IO9);
326 // VR_DISCRETE1+_PULLUP
327 alphaHall1PullUp.initPin("Hall 1 PullUp", Gpio::H144_OUT_IO10);
328 // VR_DISCRETE11_PULLUP
329 alphaHall2PullUp.initPin("Hall 2 PullUp", Gpio::H144_OUT_IO11);
330 // VR_DISCRETE2+_PULLUP
331 alphaHall3PullUp.initPin("Hall 3 PullUp", Gpio::H144_OUT_IO12);
332 // VR_DISCRETE2-_PULLUP
333 alphaHall4PullUp.initPin("Hall 4 PullUp", Gpio::H144_OUT_IO13);
334 // VR_9924+_PULLUP
335 alphaHall5PullUp.initPin("Hall 5 PullUp", Gpio::H144_GP_IO2);
336 // VR_9924+-_PULLUP
337 alphaHall6PullUp.initPin("Hall 6 PullUp", Gpio::H144_GP_IO1);
338
340}
341
354
355static Gpio OUTPUTS[] = {
356 Gpio::TLE9104_0_OUT_3, // 1B - Injector 4
357 Gpio::TLE9104_0_OUT_2, // 2B - Injector 3
358 Gpio::TLE9104_0_OUT_1, // 3B - Injector 2
359 Gpio::TLE9104_0_OUT_0, // 4B - Injector 1
360
361 Gpio::TLE9104_2_OUT_3, // 14B - OUT_TACH
362 Gpio::TLE9104_2_OUT_1, // 5B - OUT_AUX_LS1
363 Gpio::TLE9104_2_OUT_0, // 6B - OUT_AUX_LS2
364 // Gpio::TLE9104_2_OUT_2, // not testing P1
365
366 Gpio::TLE9104_1_OUT_3, // 1A - Injector 8
367 Gpio::TLE9104_1_OUT_2, // 2A - Injector 7
368 Gpio::TLE9104_1_OUT_1, // 3A - Injector 6
369 Gpio::TLE9104_1_OUT_0, // 4A - Injector 5
370
371 Gpio::TLE9104_3_OUT_3, // 5A - OUT_MAIN_RELAY
372 Gpio::TLE9104_3_OUT_1, // 6A - OUT_AUX_LS3
373 Gpio::TLE9104_3_OUT_2, // 7A - OUT_AUX_LS4
374 Gpio::TLE9104_3_OUT_0, // 8A - OUT_AUX_LS5
375 Gpio::H144_IGN_1, // 13B Coil 1
376 Gpio::H144_IGN_2, // 12B Coil 2
377 Gpio::H144_IGN_3, // 11B Coil 3
378 Gpio::H144_IGN_4, // 10B Coil 4
379 Gpio::H144_IGN_5, // 13A Coil 5
380 Gpio::H144_IGN_6, // 12A Coil 6
381 Gpio::H144_IGN_7, // 11A Coil 7
382 Gpio::H144_IGN_8, // 10A Coil 8
383};
384
386 return efi::size(OUTPUTS);
387}
388
392
394 return OUTPUTS;
395}
396
398 return 2;
399}
400
407
void setup_custom_board_overrides()
std::optional< setup_custom_board_overrides_type > custom_board_InitHardware
Definition hardware.cpp:77
Single output pin reference and state.
Definition efi_output.h:49
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e outputMode, bool forceInitWithFatalError=false)
Definition efi_gpio.cpp:711
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
@ Unassigned
@ TLE9104_0_OUT_0
@ TLE9104_0_OUT_2
@ TLE9104_0_OUT_3
@ TLE9104_2_OUT_0
@ TLE9104_1_OUT_0
@ TLE9104_1_OUT_2
@ TLE9104_1_OUT_1
@ TLE9104_0_OUT_1
@ TLE9104_3_OUT_3
@ TLE9104_2_OUT_3
@ TLE9104_3_OUT_2
@ TLE9104_3_OUT_0
@ TLE9104_2_OUT_1
@ TLE9104_1_OUT_3
@ TLE9104_3_OUT_1
void setPPSInputs(adc_channel_e pps1, adc_channel_e pps2)
void setTPS1Inputs(adc_channel_e tps1, adc_channel_e tps2)
void setupTLE9201IncludingStepper(Gpio controlPin, Gpio direction, Gpio disable, int dcIndex)
std::optional< setup_custom_board_overrides_type > custom_board_ConfigOverrides
std::optional< setup_custom_board_overrides_type > custom_board_DefaultConfiguration
std::optional< setup_custom_board_config_type > custom_board_OnConfigurationChange
static constexpr engine_configuration_s * engineConfiguration
SPIDriver SPID2
SPI1 driver identifier.
Definition hal_spi_lld.c:47
static Gpio OUTPUTS[]
static void setIgnitionPins()
static OutputPin alphaTempPullUp
int getBoardMetaOutputsCount()
Gpio * getBoardMetaOutputs()
static void setInjectorPins()
static const tle9104_config tle9104_cfg[BOARD_TLE9104_COUNT]
int getBoardMetaLowSideOutputsCount()
int getBoardMetaDcOutputsCount()
static void alphax_gold_boardDefaultConfiguration()
Board-specific configuration defaults.
static void setDefaultETBPins()
static OutputPin alphaHall1PullUp
static void alphax_gold_boardInitHardware()
Board-specific initialization code.
static void alphax_gold_boardConfigOverrides()
static void board_init_ext_gpios()
static OutputPin alphaKnock1PullUp
static OutputPin alphaHall5PullUp
static OutputPin alphaKnock2PullUp
static OutputPin alphaHall6PullUp
static void setDefaultSensorInputs()
static OutputPin alphaHall4PullUp
static OutputPin alphaTachSelPullUp
static void alphax_gold_OnConfigurationChange(engine_configuration_s *)
static OutputPin alphaHall3PullUp
static OutputPin alphaHall2PullUp
void hellenMegaSdWithAccelerometer()
void setHellenCan()
void setHellenVbatt()
void setHellenMegaEnPin(bool enableBoardOnStartUp)
void setHellenMMbaro()
static void enableHellenSpi2()
void setDefaultHellenAtPullUps(float pullup=HELLEN_DEFAULT_AT_PULLUP)
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
SPIDriver * spi_bus
Definition tle9104.h:12
void initAll9104(const tle9104_config *configs)
Definition tle9104.cpp:568