Esempio n. 1
0
void startTunerStudioConnectivity(void) {
	initLogging(&logger, "tuner studio");

	if (sizeof(engine_configuration_s) != getTunerStudioPageSize(0))
		firmwareError("TS page size mismatch: %d/%d", sizeof(engine_configuration_s), getTunerStudioPageSize(0));

	if (sizeof(TunerStudioOutputChannels) != TS_OUTPUT_SIZE)
		firmwareError("TS outputs size mismatch: %d/%d", sizeof(TunerStudioOutputChannels), TS_OUTPUT_SIZE);

	memset(&tsState, 0, sizeof(tsState));
#if EFI_PROD_CODE
	if (isSerialOverUart()) {
		print("TunerStudio over USB serial");
		usb_serial_start();
	} else {

		print("TunerStudio over USART");
		mySetPadMode("tunerstudio rx", TS_SERIAL_RX_PORT, TS_SERIAL_RX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
		mySetPadMode("tunerstudio tx", TS_SERIAL_TX_PORT, TS_SERIAL_TX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF));

		sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig);
	}
#endif /* EFI_PROD_CODE */
	syncTunerStudioCopy();

	addConsoleAction("tsinfo", printStats);

	chThdCreateStatic(TS_WORKING_AREA, sizeof(TS_WORKING_AREA), NORMALPRIO, tsThreadEntryPoint, NULL);
}
Esempio n. 2
0
static void initSpiModule(SPIDriver *driver, ioportid_t sckPort, ioportmask_t sckPin, ioportid_t misoPort,
		ioportmask_t misoPin, ioportid_t mosiPort, ioportmask_t mosiPin, int af) {
	mySetPadMode("SPI clock", sckPort, sckPin, PAL_MODE_ALTERNATE(af));

	mySetPadMode("SPI master out", mosiPort, mosiPin, PAL_MODE_ALTERNATE(af));
	mySetPadMode("SPI master in ", misoPort, misoPin, PAL_MODE_ALTERNATE(af));
}
Esempio n. 3
0
void initI2Cmodule(void) {
	print("Starting I2C module\r\n");
	i2cInit();
	i2cStart(&I2CD1, &i2cfg);

	mySetPadMode("I2C clock", EFI_I2C_SCL_PORT, EFI_I2C_SCL_PIN,
	PAL_MODE_ALTERNATE(EFI_I2C_AF) | PAL_STM32_OTYPE_OPENDRAIN);
	mySetPadMode("I2C data", EFI_I2C_SDA_PORT, EFI_I2C_SDA_PIN,
	PAL_MODE_ALTERNATE(EFI_I2C_AF) | PAL_STM32_OTYPE_OPENDRAIN);
}
Esempio n. 4
0
/**
 * @brief Initialize the hardware output pin while also assigning it a logical name
 */
void initOutputPinExt(char *msg, OutputPin *outputPin, GPIO_TypeDef *port, uint32_t pinNumber, iomode_t mode) {
	outputPin->currentLogicValue = -1;
	outputPin->port = port;
	outputPin->pin = pinNumber;

	mySetPadMode(msg, port, pinNumber, mode);
}
Esempio n. 5
0
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
	spiConfig->end_cb = NULL;
	ioportid_t port = getHwPort(csPin);
	ioportmask_t pin = getHwPin(csPin);
	spiConfig->ssport = port;
	spiConfig->sspad = pin;
	mySetPadMode("chip select", port, pin, PAL_STM32_MODE_OUTPUT);
}
Esempio n. 6
0
void initExt(void) {

//	if (1 == 1) {
//		return;
//	}

	extcfg.channels[8].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOD; // PD8
	extcfg.channels[8].cb = extCallback;
	extcfg.channels[9].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOD; // PD9
	extcfg.channels[9].cb = extCallback;
	extcfg.channels[10].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOD; // PD10
	extcfg.channels[10].cb = extCallback;
	extcfg.channels[11].mode = EXT_CH_MODE_BOTH_EDGES | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOD; // PD11
	extcfg.channels[11].cb = extCallback;

	mySetPadMode("joy A", GPIOD, 8, PAL_MODE_INPUT_PULLUP);
	mySetPadMode("joy A", GPIOD, 9, PAL_MODE_INPUT_PULLUP);
	mySetPadMode("joy A", GPIOD, 10, PAL_MODE_INPUT_PULLUP);
	mySetPadMode("joy A", GPIOD, 11, PAL_MODE_INPUT_PULLUP);
}
Esempio n. 7
0
static void initECUstimulator(void) {
	mySetPadMode("TEN", DIAG_PORT, DIAG_PIN,
	PAL_MODE_OUTPUT_PUSHPULL);

	addConsoleActionI("diag", setDiag);
	addConsoleAction("emu", startEmulator);
	addConsoleActionII("ad", printAdvance);

	setDiag(1);

	chThdCreateStatic(eeThreadStack, sizeof(eeThreadStack), NORMALPRIO, (tfunc_t) eeThread, NULL);
}
Esempio n. 8
0
/**
 * @brief Initialize the hardware output pin while also assigning it a logical name
 */
void initOutputPinExt(const char *msg, OutputPin *outputPin, ioportid_t port, uint32_t pinNumber, iomode_t mode) {
	if (outputPin->port != NULL && (outputPin->port != port || outputPin->pin != pinNumber)) {
		/**
		 * here we check if another physical pin is already assigned to this logical output
		 */
// todo: need to clear '&outputs' in io_pins.c
		firmwareError(OBD_PCM_Processor_Fault, "outputPin [%s] already assigned to %x%d", msg, outputPin->port, outputPin->pin);
		return;
	}
	outputPin->currentLogicValue = INITIAL_PIN_STATE;
	outputPin->port = port;
	outputPin->pin = pinNumber;

	mySetPadMode(msg, port, pinNumber, mode);
}
Esempio n. 9
0
void lcd_HD44780_init(void) {
	initLogging(&logger, "HD44780 driver");

	addConsoleAction("lcdinfo", lcdInfo);


	if (engineConfiguration->displayMode == DM_HD44780) {
		mySetPadMode("lcd RS", HD44780_PORT_RS, HD44780_PIN_RS, PAL_MODE_OUTPUT_PUSHPULL);
		mySetPadMode("lcd E", HD44780_PORT_E, HD44780_PIN_E, PAL_MODE_OUTPUT_PUSHPULL);
		mySetPadMode("lcd DB4", HD44780_PORT_DB4, HD44780_PIN_DB4, PAL_MODE_OUTPUT_PUSHPULL);
		mySetPadMode("lcd DB6", HD44780_PORT_DB5, HD44780_PIN_DB5, PAL_MODE_OUTPUT_PUSHPULL);
		mySetPadMode("lcd DB7", HD44780_PORT_DB6, HD44780_PIN_DB6, PAL_MODE_OUTPUT_PUSHPULL);
		mySetPadMode("lcd DB8", HD44780_PORT_DB7, HD44780_PIN_DB7, PAL_MODE_OUTPUT_PUSHPULL);

		palWritePad(HD44780_PORT_RS, HD44780_PIN_RS, 0);
		palWritePad(HD44780_PORT_E, HD44780_PIN_E, 0);
		palWritePad(HD44780_PORT_DB4, HD44780_PIN_DB4, 0);
		palWritePad(HD44780_PORT_DB5, HD44780_PIN_DB5, 0);
		palWritePad(HD44780_PORT_DB6, HD44780_PIN_DB6, 0);
		palWritePad(HD44780_PORT_DB7, HD44780_PIN_DB7, 0);
	}

	// LCD needs some time to wake up
	chThdSleepMilliseconds(50);

	lcd_HD44780_write(LCD_2X16_RESET);
	chThdSleepMilliseconds(1);

	lcd_HD44780_write(0x30);

	lcd_HD44780_write(LCD_2X16_4_BIT_BUS);	// 4 bit, 2 line
	chThdSleepMicroseconds(40);

	lcd_HD44780_write(LCD_2X16_4_BIT_BUS);	// 4 bit, 2 line
	lcd_HD44780_write(0x80);
	chThdSleepMicroseconds(40);

	lcd_HD44780_write(0x00);	// display and cursor control
	lcd_HD44780_write(0xC0);
	chThdSleepMicroseconds(40);

	lcd_HD44780_write(0x00);	// display clear
	lcd_HD44780_write(0x01);
	chThdSleepMilliseconds(2);

	lcd_HD44780_write(0x00);	// entry mode set
	lcd_HD44780_write(0x60);

	lcd_HD44780_set_position(0, 0);
	lcd_HD44780_print_string("rusefi here\n");
	lcd_HD44780_print_string(__DATE__);
}
Esempio n. 10
0
void startIdleThread() {
	initLogging(&logger, "Idle Valve Control");

	startSimplePwm(&idleValve, "Idle Valve",
			boardConfiguration->idleValvePin,
			0.5,
			IDLE_AIR_CONTROL_VALVE_PWM_FREQUENCY,
			IDLE_VALVE
			);

	idleInit(&idle);
	scheduleMsg(&logger, "initial idle %d", idle.value);

	chThdCreateStatic(ivThreadStack, sizeof(ivThreadStack), NORMALPRIO, (tfunc_t)ivThread, NULL);

	// this is idle switch INPUT - sometimes there is a switch on the throttle pedal
	// this switch is not used yet
	mySetPadMode("idle switch", getHwPort(boardConfiguration->idleSwitchPin), getHwPin(boardConfiguration->idleSwitchPin), PAL_MODE_INPUT);

	addConsoleActionI("set_idle_rpm", setIdleRpmAction);
	addConsoleActionI("set_idle_pwm", setIdleValvePwm);
	addConsoleActionI("set_idle_enabled", setIdleControlEnabled);
}
Esempio n. 11
0
static void initAdcPin(ioportid_t port, int pin, const char *msg) {
	print("adc %s\r\n", msg);
	mySetPadMode("adc input", port, pin, PAL_MODE_INPUT_ANALOG);
}