Skip to content

Commit f421a75

Browse files
committed
Add rough detection of Flex platform
This is a stand in until ID resistors are present
1 parent 1766327 commit f421a75

File tree

1 file changed

+170
-22
lines changed

1 file changed

+170
-22
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 170 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,42 @@ void identifyBoard()
9494
// 0x08 - HUSB238 - USB C PD Sink Controller
9595
bool husb238Present = i2cIsDevicePresent(i2c_0, 0x08);
9696

97+
// Flex has everything a Torch does and a display
98+
// 0x3C - SSD1306 OLED Driver
99+
// If a display is present, it's not a Torch
100+
// bool displayPresent = i2cIsDevicePresent(i2c_0, 0x3C);
101+
bool displayPresent = i2cIsDevicePresent(i2c_0, 0x10);
102+
97103
i2c_0->end();
98104

99-
if (bq40z50Present || mp2762aPresent || husb238Present)
100-
productVariant = RTK_TORCH;
105+
// Proceed with Torch ID only if display is absent
106+
if (displayPresent == false)
107+
{
108+
if (bq40z50Present || mp2762aPresent || husb238Present)
109+
{
110+
productVariant = RTK_TORCH;
111+
}
101112

102-
if (productVariant == RTK_TORCH && bq40z50Present == false)
103-
systemPrintln("Error: Torch ID'd with no BQ40Z50 present");
113+
if (productVariant == RTK_TORCH && bq40z50Present == false)
114+
systemPrintln("Error: Torch ID'd with no BQ40Z50 present");
104115

105-
if (productVariant == RTK_TORCH && mp2762aPresent == false)
106-
systemPrintln("Error: Torch ID'd with no MP2762A present");
116+
if (productVariant == RTK_TORCH && mp2762aPresent == false)
117+
systemPrintln("Error: Torch ID'd with no MP2762A present");
107118

108-
if (productVariant == RTK_TORCH && husb238Present == false)
109-
systemPrintln("Error: Torch ID'd with no HUSB238 present");
119+
if (productVariant == RTK_TORCH && husb238Present == false)
120+
systemPrintln("Error: Torch ID'd with no HUSB238 present");
121+
}
110122
}
111123

112124
if (productVariant == RTK_UNKNOWN)
113125
{
126+
// TODO remove once v1.1 Flex has ID resistors
127+
if (i2c_0 == nullptr)
128+
i2c_0 = new TwoWire(0);
129+
int pin_SDA = 15;
130+
int pin_SCL = 4;
131+
i2c_0->begin(pin_SDA, pin_SCL); // SDA, SCL
132+
114133
// Use ADC to check the resistor divider
115134
int pin_deviceID = 35;
116135
uint16_t idValue = analogReadMilliVolts(pin_deviceID);
@@ -139,13 +158,23 @@ void identifyBoard()
139158
else if (idWithAdc(idValue, 12.1, 1.5, 8.5))
140159
productVariant = RTK_FACET_V2_LBAND;
141160

142-
// Facet v2: 10.0/2.7 --> 612mV < 702mV < 801mV (8.5% tolerance)
143-
else if (idWithAdc(idValue, 10.0, 2.7, 8.5))
144-
productVariant = RTK_FACET_V2;
161+
// Facet Flex: 10.0/20.0 --> 2071mV < 2200mV < 2322mV (8.5% tolerance)
162+
else if (idWithAdc(idValue, 10.0, 20.0, 8.5))
163+
productVariant = RTK_FLEX;
164+
165+
// 0x3C - SSD1306 OLED Driver found in RTK Flex
166+
// TODO remove once v1.1 hardware has ID resistors
167+
// else if (i2cIsDevicePresent(i2c_0, 0x3C) == true || i2cIsDevicePresent(i2c_0, 0x10) == true)
168+
// productVariant = RTK_FLEX;
145169

146170
// Postcard: 3.3/10 --> 2371mV < 2481mV < 2582mV (8.5% tolerance)
147171
else if (idWithAdc(idValue, 3.3, 10, 8.5))
148172
productVariant = RTK_POSTCARD;
173+
174+
productVariant = RTK_FLEX; // TODO remove hard override
175+
176+
// TODO remove once v1.1 Flex has ID resistors
177+
i2c_0->end();
149178
}
150179

151180
if (ENABLE_DEVELOPER)
@@ -273,7 +302,7 @@ void beginBoard()
273302
pinMode(pin_GNSS_TimePulse, INPUT);
274303

275304
pinMode(pin_GNSS_DR_Reset, OUTPUT);
276-
um980Boot(); // Tell UM980 and DR to boot
305+
gnssBoot(); // Tell UM980 and DR to boot
277306

278307
pinMode(pin_powerAdapterDetect, INPUT); // Has 10k pullup
279308

@@ -699,7 +728,7 @@ void beginBoard()
699728
present.i2c0BusSpeed_400 = true; // Run display bus at higher speed
700729
present.display_type = DISPLAY_128x64;
701730
present.microSd = true;
702-
present.gpioExpander = true;
731+
present.gpioExpanderButtons = true;
703732
present.microSdCardDetectGpioExpanderHigh = true; // CD is on GPIO 5 of expander. High = SD in place.
704733

705734
// We can't enable here because we don't know if lg290pFirmwareVersion is >= v05
@@ -734,12 +763,92 @@ void beginBoard()
734763
pinMode(pin_GNSS_TimePulse, INPUT);
735764

736765
pinMode(pin_GNSS_Reset, OUTPUT);
737-
lg290pBoot(); // Tell LG290P to boot
766+
gnssBoot(); // Tell LG290P to boot
738767

739768
// Disable the microSD card
740769
pinMode(pin_microSD_CS, OUTPUT);
741770
sdDeselectCard();
742771
}
772+
773+
else if (productVariant == RTK_FLEX)
774+
{
775+
// #ifdef COMPILE_LG290P
776+
// gnss = (GNSS *)new GNSS_LG290P();
777+
// #else // COMPILE_LGP290P
778+
// gnss = (GNSS *)new GNSS_None();
779+
// systemPrintln("<<<<<<<<<< !!!!!!!!!! LG290P NOT COMPILED !!!!!!!!!! >>>>>>>>>>");
780+
// #endif // COMPILE_LGP290P
781+
782+
present.brand = BRAND_SPARKPNT;
783+
present.psram_2mb = true;
784+
785+
present.gnss_lg290p = true;
786+
787+
present.antennaPhaseCenter_mm = 42.0; // Default to SPK6618H APC, average of L1/L2
788+
present.radio_lora = true;
789+
present.fuelgauge_bq40z50 = true;
790+
present.charger_mp2762a = true;
791+
792+
// TODO Change to MFi present.encryption_atecc608a = true;
793+
794+
present.button_powerHigh = true; // Button is pressed when high
795+
present.beeper = true;
796+
present.gnss_to_uart = true;
797+
present.needsExternalPpl = true; // Uses the PointPerfect Library
798+
799+
// TODO this will need to be based on module ID
800+
present.minCno = true;
801+
present.minElevation = true;
802+
present.dynamicModel = true;
803+
804+
present.gpioExpanderSwitches = true;
805+
806+
present.display_i2c0 = true;
807+
//present.i2c0BusSpeed_400 = true; // Run display bus at higher speed
808+
present.display_type = DISPLAY_128x64_INVERTED;
809+
present.tiltPossible = true;
810+
811+
pin_I2C0_SDA = 15;
812+
pin_I2C0_SCL = 4;
813+
814+
pin_GnssUart_RX = 26;
815+
pin_GnssUart_TX = 27;
816+
817+
pin_powerButton = 34;
818+
819+
pin_IMU_RX = 14; // ESP32 UART2
820+
pin_IMU_TX = 17;
821+
822+
pin_powerAdapterDetect = 36; // Goes low when USB cable is plugged in
823+
824+
pin_bluetoothStatusLED = 32;
825+
pin_gnssStatusLED = 13;
826+
827+
pin_beeper = 33;
828+
829+
pin_gpioExpanderInterrupt = 2; // Not used since all GPIO expanded pins are outputs
830+
831+
DMW_if systemPrintf("pin_bluetoothStatusLED: %d\r\n", pin_bluetoothStatusLED);
832+
pinMode(pin_bluetoothStatusLED, OUTPUT);
833+
834+
DMW_if systemPrintf("pin_gnssStatusLED: %d\r\n", pin_gnssStatusLED);
835+
pinMode(pin_gnssStatusLED, OUTPUT);
836+
837+
// Turn on Bluetooth, GNSS, and Battery LEDs to indicate power on
838+
bluetoothLedOn();
839+
gnssStatusLedOn();
840+
841+
pinMode(pin_beeper, OUTPUT);
842+
beepOff();
843+
844+
pinMode(pin_powerButton, INPUT);
845+
846+
pinMode(pin_powerAdapterDetect, INPUT); // Has 10k pullup
847+
848+
// We don't disable peripherals (aka set pins on the GPIO expander) here because I2C has not yet been started
849+
850+
// GNSS receiver type is determined later in gnssDetectReceiverType()
851+
}
743852
}
744853

745854
void beginVersion()
@@ -1050,6 +1159,21 @@ void pinGnssUartTask(void *pvParameters)
10501159
// LG290P communicates at 460800bps.
10511160
platformGnssCommunicationRate = 115200 * 4;
10521161
}
1162+
else if (productVariant == RTK_FLEX)
1163+
{
1164+
Serial.println("Starting UART for flex");
1165+
if (settings.detectedGnssReceiver == GNSS_RECEIVER_LG290P)
1166+
{
1167+
Serial.println("Starting UART for LG290P");
1168+
// LG290P communicates at 460800bps.
1169+
platformGnssCommunicationRate = 115200 * 4;
1170+
}
1171+
else
1172+
{
1173+
// If we don't know the GNSS receiver, default to 115200
1174+
platformGnssCommunicationRate = 115200;
1175+
}
1176+
}
10531177

10541178
serialGNSS->begin(platformGnssCommunicationRate, SERIAL_8N1, pin_GnssUart_RX,
10551179
pin_GnssUart_TX); // Start UART on platform dependent pins for SPP. The GNSS will be
@@ -1283,7 +1407,7 @@ void beginCharger()
12831407
void beginButtons()
12841408
{
12851409
if (present.button_powerHigh == false && present.button_powerLow == false && present.button_mode == false &&
1286-
present.gpioExpander == false)
1410+
present.gpioExpanderButtons == false)
12871411
return;
12881412

12891413
TaskHandle_t taskHandle;
@@ -1296,16 +1420,16 @@ void beginButtons()
12961420
buttonCount++;
12971421
if (present.button_mode == true)
12981422
buttonCount++;
1299-
if (present.gpioExpander == true)
1423+
if (present.gpioExpanderButtons == true)
13001424
buttonCount++;
13011425
if (buttonCount > 1)
13021426
reportFatalError("Illegal button assignment.");
13031427

13041428
// Postcard button uses an I2C expander
13051429
// Avoid using the button library
1306-
if (present.gpioExpander == true)
1430+
if (present.gpioExpanderButtons == true)
13071431
{
1308-
if (beginGpioExpander(0x20) == false)
1432+
if (beginGpioExpanderButtons(0x20) == false)
13091433
{
13101434
systemPrintln("Directional pad not detected");
13111435
return;
@@ -1337,7 +1461,7 @@ void beginButtons()
13371461
online.button = true;
13381462
}
13391463

1340-
if (online.button == true || online.gpioExpander == true)
1464+
if (online.button == true || online.gpioExpanderButtons == true)
13411465
{
13421466
// Starts task for monitoring button presses
13431467
if (!task.buttonCheckTaskRunning)
@@ -1412,6 +1536,15 @@ void beginSystemState()
14121536
if (systemState == STATE_BASE_NOT_STARTED)
14131537
firstRoverStart = false;
14141538
}
1539+
else if (productVariant == RTK_FLEX)
1540+
{
1541+
// Return to either Rover or Base Not Started. The last state previous to power down.
1542+
systemState = settings.lastState;
1543+
1544+
firstRoverStart = true; // Allow user to enter test screen during first rover start
1545+
if (systemState == STATE_BASE_NOT_STARTED)
1546+
firstRoverStart = false;
1547+
}
14151548
else
14161549
{
14171550
systemPrintf("beginSystemState: Unknown product variant: %d\r\n", productVariant);
@@ -1592,6 +1725,11 @@ bool i2cBusInitialization(TwoWire *i2cBus, int sda, int scl, int clockKHz)
15921725
break;
15931726
}
15941727

1728+
case 0x10: {
1729+
systemPrintf(" 0x%02X - MFi Authentication Coprocessor\r\n", addr);
1730+
break;
1731+
}
1732+
15951733
case 0x18: {
15961734
systemPrintf(" 0x%02X - PCA9557 GPIO Expander with Reset\r\n", addr);
15971735
break;
@@ -1603,7 +1741,12 @@ bool i2cBusInitialization(TwoWire *i2cBus, int sda, int scl, int clockKHz)
16031741
}
16041742

16051743
case 0x20: {
1606-
systemPrintf(" 0x%02X - PCA9554 GPIO Expander with Interrupt\r\n", addr);
1744+
systemPrintf(" 0x%02X - PCA9554 GPIO Expander with Interrupt (Postcard)\r\n", addr);
1745+
break;
1746+
}
1747+
1748+
case 0x21: {
1749+
systemPrintf(" 0x%02X - PCA9554 GPIO Expander with Interrupt (Flex)\r\n", addr);
16071750
break;
16081751
}
16091752

@@ -1617,13 +1760,18 @@ bool i2cBusInitialization(TwoWire *i2cBus, int sda, int scl, int clockKHz)
16171760
break;
16181761
}
16191762

1763+
case 0x3C: {
1764+
systemPrintf(" 0x%02X - SSD1306 OLED Driver (Flex)\r\n", addr);
1765+
break;
1766+
}
1767+
16201768
case 0x3D: {
1621-
systemPrintf(" 0x%02X - SSD1306 OLED Driver\r\n", addr);
1769+
systemPrintf(" 0x%02X - SSD1306 OLED Driver (Postcard/EVK/mosaic)\r\n", addr);
16221770
break;
16231771
}
16241772

16251773
case 0x42: {
1626-
systemPrintf(" 0x%02X - u-blox ZED-F9P GNSS Receiver\r\n", addr);
1774+
systemPrintf(" 0x%02X - u-blox GNSS Receiver\r\n", addr);
16271775
break;
16281776
}
16291777

0 commit comments

Comments
 (0)