making pca_board_id reusable

This commit is contained in:
Andrey 2024-07-15 23:00:39 -04:00
parent 63cc8f0829
commit d4a2304ec1
2 changed files with 45 additions and 40 deletions

View File

@ -5,8 +5,7 @@
#include "hellen_leds_100.cpp"
#include "smart_gpio.h"
#include "drivers/gpio/tle9104.h"
#define PCA9555_I2C_ADDR 0x20
#include "pca_board_id.h"
static OutputPin alphaTempPullUp;
@ -38,44 +37,6 @@ static void setupDefaultSensorInputs() {
engineConfiguration->iat.adcChannel = MM100_IN_IAT_ANALOG;
}
static uint32_t getBoardRevision() {
static bool isFirstInvocation = true;
static uint32_t variant;
if (isFirstInvocation) {
BitbangI2c m_i2c;
const uint8_t set_out[3] = {0x06, 0xff, 0xff};
const uint8_t read_inputs_cmd[1] = {0x00};
uint8_t rx[2] = {0xff, 0xff};
//same pins as for LPS25
m_i2c.init(Gpio::B10, Gpio::B11);
// configuration registers:
// after reset all IO pins should be configured as output, so ttis step can be skipped
m_i2c.write(PCA9555_I2C_ADDR, set_out, sizeof(set_out));
// read registers 0 and 1: Input port registers
m_i2c.writeRead(PCA9555_I2C_ADDR, read_inputs_cmd, sizeof(read_inputs_cmd), rx, sizeof(rx));
variant = (rx[1] << 8) | (rx[0] << 0);
efiPrintf("Board variant 0x%04x\n", (unsigned int)variant);
isFirstInvocation = false;
// release gpios for LPS25 driver
m_i2c.deinit();
}
return variant;
}
int hackHellenBoardId(int /* detectedId */) {
return getBoardRevision();
}
void setBoardConfigOverrides() {
/* Force PWR_EN as TLE9104s are powered from +5VA */
setHellenMegaEnPin();

View File

@ -0,0 +1,44 @@
#pragma once
#include "pch.h"
#include "hellen_meta.h"
#include "i2c_bb.h"
#define PCA9555_I2C_ADDR 0x20
static uint32_t getBoardRevision() {
static bool isFirstInvocation = true;
static uint32_t variant;
if (isFirstInvocation) {
BitbangI2c m_i2c;
const uint8_t set_out[3] = {0x06, 0xff, 0xff};
const uint8_t read_inputs_cmd[1] = {0x00};
uint8_t rx[2] = {0xff, 0xff};
//same pins as for baso LPS25
m_i2c.init(Gpio::B10, Gpio::B11);
// configuration registers:
// after reset all IO pins should be configured as output, so ttis step can be skipped
m_i2c.write(PCA9555_I2C_ADDR, set_out, sizeof(set_out));
// read registers 0 and 1: Input port registers
m_i2c.writeRead(PCA9555_I2C_ADDR, read_inputs_cmd, sizeof(read_inputs_cmd), rx, sizeof(rx));
variant = (rx[1] << 8) | (rx[0] << 0);
efiPrintf("Board variant 0x%04x\n", (unsigned int)variant);
isFirstInvocation = false;
// release gpios for baso LPS25 driver
m_i2c.deinit();
}
return variant;
}
int hackHellenBoardId(int /* detectedId */) {
return getBoardRevision();
}