rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
board_configuration.cpp
Go to the documentation of this file.
1/**
2 * @file boards/subaru_eg33/board_configuration.h
3 *
4 * @brief In this file we can override engine_configuration.cpp.
5 *
6 * @date Feb 06, 2021
7 * @author Andrey Gusakov, 2021
8 */
9
10#include "pch.h"
11#include "smart_gpio.h"
13#include "device_mpu_util.h"
14#include "board_overrides.h"
15
17 return Gpio::G6; /* LD1 - green */
18}
19
21 return Gpio::G8; /* LD3 - yellow */
22}
23
25 // this board has no warning led
26 return Gpio::Unassigned;
27}
28
32 /* actually Bluetooth/WiFi interface */
33 //engineConfiguration->consoleSerialTxPin = Gpio::C10;
34 //engineConfiguration->consoleSerialRxPin = Gpio::C11;
37}
38
39/**
40 * @brief Board-specific configuration defaults.
41
42 */
45
46 /* Battery voltage */
48 /* Vbat divider: 10K + 1K */
49 engineConfiguration->vbattDividerCoeff = (1.0 + 10.0) / 1.0;
50
51 /* Throttle position */
53
54 /* MAP: stock car does not have MAP
55 * but EFI_ADC_10 is reserved for this purpose */
57
58 /* MAF */
60
61 /* coolant t */
63 /* 1K pull-up plus 20K pull-down to get ~4.75V when no sensor connected */
65
66 /* No IAT sensor on stock engine */
67 engineConfiguration->iat.adcChannel = EFI_ADC_NONE;
68 //sengineConfiguration->iat.config.bias_resistor = 2700;
69
70 /* TODO: add both narrow sensors */
71 engineConfiguration->afr.hwChannel = EFI_ADC_NONE;
72
73 engineConfiguration->adcVcc = ADC_VCC;
74
75 /* No barro */
77
78 /* No pedal position */
80
81 /* Injectors */
88 /* Additional, not used for EG33 */
91
92 /* Ignition */
99 /* Additional, not used for EG33 */
102 //engineConfiguration->ignitionPinMode = OM_INVERTED;
103
104 // Idle configuration
109
110 /* IF you have BOTH camshaft position sensor and crankshaft position sensor
111 * camshaft is always trigger#1 input and then crankshaft is trigger#2. */
113 engineConfiguration->triggerInputPins[1] = Gpio::H10; /* crank pos #1 */
115
116 /* SPI devices: mess of board and engine configurations */
117 /* TLE6240 */
119 // todo: hard-code SPI4 pins into spi4mosiPin etc!
120 engineConfiguration->tle6240_cs = Gpio::E15; /* SPI4_NSS0 */
122 /* MC33972 */
124 engineConfiguration->mc33972_cs = Gpio::E10; /* SPI4_NSS2 */
126
127 /* TLE6240 - OUT3, also PG2 through 3.3V-> 5.0V level translator - not installed */
130
131 /* spi driven - TLE6240 - OUT5 */
134
135 /* Self shutdown ouput:
136 * High level on this pin will keep Main Relay enabled in any position of ignition key
137 * This cause inability to stop engine by key.
138 * From other side main relay is powered from key position "IGN" OR this output (through diodes)
139 * So ECU does not need to drive this signal.
140 * The only puprose of this output is to keep ECU powered to finish some stuff before power off itself
141 * To support this we need to sense ING input from key switch */
142 //engineConfiguration->mainRelayPin = Gpio::H7;
143 //engineConfiguration->mainRelayPinMode = OM_DEFAULT;
144
145 /* spi driven - TLE6240 - OUT1, OUT2 */
147 engineConfiguration->fanPinMode = OM_DEFAULT;
148 /* TODO: second fan */
149 //engineConfiguration->fanPin[1] = Gpio::TLE6240_2;
150 //engineConfiguration->fanPinMode[1] = OM_DEFAULT;
151 /* spi driven - TLE6240 - OUT8 */
154
155 /* not used */
161
162 /* SPIs */
163 /* SPI4, 5 are always enabled and its configuration is set in setBoardConfigOverrides() */
176 /* Use PP mode as default for optional display SPI bus */
177 engineConfiguration->spi2SckMode = PO_DEFAULT;
178 engineConfiguration->spi2MosiMode = PO_DEFAULT;
179 engineConfiguration->spi2MisoMode = PO_DEFAULT;
180 /* User can disable this bus */
182
183 /* SD card is located on SDIO interface */
186
188
189 /* Cylinder to knock bank mapping */
196
197 /* Misc settings */
199 engineConfiguration->acSwitchMode = PI_DEFAULT;
200
201 /* This board also has AC clutch output: */
203
204 /* CAN */
207
208 /* not used pins with testpads */
211
212 if (engineConfiguration->fuelAlgorithm == engine_load_mode_e::LM_REAL_MAF)
213 setAlgorithm(engine_load_mode_e::LM_SPEED_DENSITY);
214 if (engineConfiguration->fuelAlgorithm == engine_load_mode_e::LM_ALPHA_N)
215 setAlgorithm(engine_load_mode_e::LM_ALPHA_N);
216}
217
219 /* Optional SPI display */
223 /* User can disable this bus and change pin mode, but not pins itself */
224
225 /* Smart chip */
229 engineConfiguration->spi4SckMode = PO_DEFAULT;
230 engineConfiguration->spi4MosiMode = PO_OPENDRAIN;
231 engineConfiguration->spi4MisoMode = PO_DEFAULT;
232 /* This is mandatory to have this bus enabled */
234
235 /* Smart ignition chips */
239 engineConfiguration->spi5SckMode = PO_DEFAULT;
240 engineConfiguration->spi5MosiMode = PO_DEFAULT;
241 engineConfiguration->spi5MisoMode = PO_DEFAULT;
242 /* This is mandatory to have this bus enabled */
244
245}
246
247/* Schematic RefDef DA3 */
248static const struct mc33810_config mc33810_odd = {
249 .spi_bus = &SPID5,
250 .spi_config = {
251 .circular = false,
252#ifdef _CHIBIOS_RT_CONF_VER_6_1_
253 .end_cb = nullptr,
254#else
255 .slave = false,
256 .data_cb = nullptr,
257 .error_cb = nullptr,
258#endif
259 .ssport = GPIOF,
260 .sspad = 1,
261 .cr1 =
262 //SPI_CR1_16BIT_MODE |
263 SPI_CR1_SSM |
264 SPI_CR1_SSI |
265 ((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | /* div = 16 */
266 SPI_CR1_MSTR |
267 /* SPI_CR1_CPOL | */ // = 0
268 /*
269 https://github.com/rusefi/rusefi/issues/6538 says that should be zero
270 SPI_CR1_CPHA | // = 1
271 */
272 0,
273 .cr2 = //SPI_CR2_16BIT_MODE |
274 SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
275 },
276 .direct_io = {
277 /* injector drivers */
278 [0] = {.port = GPIOI, .pad = 6}, /* INJ 1 */
279 [1] = {.port = GPIOI, .pad = 5}, /* INJ 3 */
280 [2] = {.port = GPIOI, .pad = 4}, /* INJ 5 */
281 [3] = {.port = GPIOB, .pad = 9}, /* INJ 7 */
282 /* ignition pre-drivers */
283 [4] = {.port = GPIOB, .pad = 3}, /* IGN 4 */
284 [5] = {.port = GPIOB, .pad = 4}, /* IGN 3 */
285 [6] = {.port = GPIOB, .pad = 5}, /* IGN 7 */
286 [7] = {.port = GPIOB, .pad = 8}, /* IGN 5 */
287 },
288 /* en shared between two chips */
289 .en = {.port = GPIOI, .pad = 7},
290 // TODO: pick from engineConfiguration->spi5sckPin or whatever SPI is used
291 .sck = {.port = GPIOF, .pad = 7},
292 /* TODO: */
293 .spkdur = Gpio::Unassigned,
294 .nomi = Gpio::Unassigned,
295 .maxi = Gpio::Unassigned
296};
297
298/* Schematic RefDef DA22 */
299static const struct mc33810_config mc33810_even = {
300 .spi_bus = &SPID5,
301 .spi_config = {
302 .circular = false,
303#ifdef _CHIBIOS_RT_CONF_VER_6_1_
304 .end_cb = nullptr,
305#else
306 .slave = false,
307 .data_cb = nullptr,
308 .error_cb = nullptr,
309#endif
310 .ssport = GPIOF,
311 .sspad = 2,
312 .cr1 =
313 SPI_CR1_16BIT_MODE |
314 SPI_CR1_SSM |
315 SPI_CR1_SSI |
316 ((3 << SPI_CR1_BR_Pos) & SPI_CR1_BR) | /* div = 16 */
317 SPI_CR1_MSTR |
318 /* SPI_CR1_CPOL | */ // = 0
319 /*
320 https://github.com/rusefi/rusefi/issues/6538 says that should be zero
321 SPI_CR1_CPHA | // = 1
322 */
323 0,
324 .cr2 = SPI_CR2_16BIT_MODE
325 },
326 .direct_io = {
327 /* injector drivers */
328 [0] = {.port = GPIOE, .pad = 3}, /* INJ 2 */
329 [1] = {.port = GPIOE, .pad = 4}, /* INJ 4 */
330 [2] = {.port = GPIOE, .pad = 5}, /* INJ 6 */
331 [3] = {.port = GPIOE, .pad = 6}, /* INJ 8 */
332 /* ignition pre-drivers */
333 [4] = {.port = GPIOI, .pad = 9}, /* IGN 8 */
334 [5] = {.port = GPIOC, .pad = 15}, /* IGN 6 */
335 [6] = {.port = GPIOC, .pad = 14}, /* IGN 2 */
336 [7] = {.port = GPIOC, .pad = 13}, /* IGN 1 */
337 },
338 /* en shared between two chips */
339 .en = {.port = nullptr, .pad = 0},
340 // TODO: pick from engineConfiguration->spi5sckPin or whatever SPI is used
341 .sck = {.port = GPIOF, .pad = 7},
342 /* TODO: */
343 .spkdur = Gpio::Unassigned,
344 .nomi = Gpio::Unassigned,
345 .maxi = Gpio::Unassigned
346};
347
349{
350#ifndef EFI_BOOTLOADER
351 int ret;
352
354 if (ret < 0) {
355 /* error */
356 }
358 if (ret < 0) {
359 /* error */
360 }
361#endif // EFI_BOOTLOADER
362}
363
364/**
365 * @brief Board-specific initialization code.
366 */
367void boardInit() {
369}
370
Gpio getWarningLedPin()
Gpio getCommsLedPin()
Gpio getRunningLedPin()
void setup_custom_board_overrides()
@ MC33810_0_GD_3
@ MC33810_0_OUT_2
@ MC33810_1_OUT_1
@ MC33810_1_GD_3
@ MC33810_1_GD_0
@ Unassigned
@ MC33810_1_OUT_0
@ MC33810_1_OUT_2
@ MC33810_0_OUT_0
@ MC33810_0_OUT_3
@ TLE6240_PIN_1
@ MC33972_PIN_22
@ MC33810_1_GD_1
@ TLE6240_PIN_7
@ TLE6240_PIN_5
@ MC33810_1_OUT_3
@ MC33810_0_GD_2
@ MC33810_0_OUT_1
@ MC33810_1_GD_2
@ TLE6240_PIN_11
@ TLE6240_PIN_15
@ MC33810_0_GD_1
@ MC33810_0_GD_0
@ TLE6240_PIN_2
@ TLE6240_PIN_12
std::optional< setup_custom_board_overrides_type > custom_board_ConfigOverrides
std::optional< setup_custom_board_overrides_type > custom_board_DefaultConfiguration
static constexpr engine_configuration_s * engineConfiguration
void setAlgorithm(engine_load_mode_e algo)
void boardInit()
Board-specific initialization code.
static void board_init_ext_gpios()
static void setSerialConfigurationOverrides()
int mc33810_add(brain_pin_e base, unsigned int index, const mc33810_config *cfg)
MC33810 driver add.
Definition mc33810.cpp:946
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
SPIDriver * spi_bus
Definition mc33810.h:30
static void subaru_eg33_boardConfigOverrides()
static const struct mc33810_config mc33810_even
static const struct mc33810_config mc33810_odd
static void subaru_eg33_boardDefaultConfiguration()
Board-specific configuration defaults.