1
- void beginBoard ()
1
+
2
+ #define MAX_ADC_VOLTAGE 3300 // Millivolts
3
+
4
+ // Testing shows the combined ADC+resistors is under a 1% window
5
+ #define TOLERANCE 5.20 // Percent: 94.8% - 105.2%
6
+
7
+ // ----------------------------------------
8
+ // Hardware initialization functions
9
+ // ----------------------------------------
10
+ // Determine if the measured value matches the product ID value
11
+ // idWithAdc applies resistor tolerance using worst-case tolerances:
12
+ // Upper threshold: R1 down by TOLERANCE, R2 up by TOLERANCE
13
+ // Lower threshold: R1 up by TOLERANCE, R2 down by TOLERANCE
14
+ bool idWithAdc (uint16_t mvMeasured, float r1, float r2)
2
15
{
3
- // Use ADC to check 50% resistor divider
4
- int pin_adc_rtk_facet = 35 ;
5
- uint16_t idValue = analogReadMilliVolts (pin_adc_rtk_facet);
6
- log_d (" Board ADC ID: %d" , idValue);
16
+ float lowerThreshold;
17
+ float upperThreshold;
7
18
8
- if (idValue > (3300 / 2 * 0.9 ) && idValue < (3300 / 2 * 1.1 ))
9
- {
10
- productVariant = RTK_FACET;
11
- }
12
- else if (idValue > (3300 * 2 / 3 * 0.9 ) && idValue < (3300 * 2 / 3 * 1.1 ))
19
+ // ADC input
20
+ // r1 KOhms | r2 KOhms
21
+ // MAX_ADC_VOLTAGE -----/\/\/\/\-----+-----/\/\/\/\----- Ground
22
+
23
+ // Return true if the mvMeasured value is within the tolerance range
24
+ // of the mvProduct value
25
+ upperThreshold = ceil (MAX_ADC_VOLTAGE * (r2 * (1.0 + (TOLERANCE / 100.0 ))) /
26
+ ((r1 * (1.0 - (TOLERANCE / 100.0 ))) + (r2 * (1.0 + (TOLERANCE / 100.0 )))));
27
+ lowerThreshold = floor (MAX_ADC_VOLTAGE * (r2 * (1.0 - (TOLERANCE / 100.0 ))) /
28
+ ((r1 * (1.0 + (TOLERANCE / 100.0 ))) + (r2 * (1.0 - (TOLERANCE / 100.0 )))));
29
+
30
+ // Serial.printf("r1: %0.2f r2: %0.2f lowerThreshold: %0.0f mvMeasured: %d upperThreshold: %0.0f\r\n", r1, r2,
31
+ // lowerThreshold, mvMeasured, upperThreshold);
32
+
33
+ return (upperThreshold > mvMeasured) && (mvMeasured > lowerThreshold);
34
+ }
35
+
36
+ // Use a pair of resistors on pin 35 to ID the board type
37
+ // If the ID resistors are not available then use a variety of other methods
38
+ // (I2C, GPIO test, etc) to ID the board.
39
+ // Assume no hardware interfaces have been started so we need to start/stop any hardware
40
+ // used in tests accordingly.
41
+ void identifyBoard ()
42
+ {
43
+ // Use ADC to check the resistor divider
44
+ int pin_deviceID = 35 ;
45
+ uint16_t idValue = analogReadMilliVolts (pin_deviceID);
46
+ Serial.printf (" Board ADC ID (mV): %d\r\n " , idValue);
47
+
48
+ // Order the following ID checks, by millivolt values high to low
49
+
50
+ // Facet L-Band Direct: 4.7/1 --> 534mV < 579mV < 626mV
51
+ if (idWithAdc (idValue, 4.7 , 1 ))
13
52
{
14
- productVariant = RTK_FACET_LBAND;
53
+ Serial.println (" Found LBand Direct" );
54
+ productVariant = RTK_FACET_LBAND_DIRECT;
15
55
}
16
- else if (idValue > (3300 * 3.3 / 13.3 * 0.9 ) && idValue < (3300 * 3.3 / 13.3 * 1.1 ))
56
+
57
+ // Express: 10/3.3 --> 761mV < 819mV < 879mV
58
+ else if (idWithAdc (idValue, 10 , 3.3 ))
17
59
{
60
+ Serial.println (" Found Express" );
18
61
productVariant = RTK_EXPRESS;
19
62
}
20
- else if (idValue > (3300 * 10 / 13.3 * 0.9 ) && idValue < (3300 * 10 / 13.3 * 1.1 ))
63
+
64
+ // Reference Station: 20/10 --> 1031mV < 1100mV < 1171mV
65
+ else if (idWithAdc (idValue, 20 , 10 ))
21
66
{
22
- productVariant = RTK_EXPRESS_PLUS;
67
+ productVariant = REFERENCE_STATION;
68
+ // We can't auto-detect the ZED version if the firmware is in configViaEthernet mode,
69
+ // so fake it here - otherwise messageSupported always returns false
70
+ zedFirmwareVersionInt = 112 ;
23
71
}
24
- else if (isConnected (0x19 ) == true ) // Check for accelerometer
72
+ // Facet: 10/10 --> 1571mV < 1650mV < 1729mV
73
+ else if (idWithAdc (idValue, 10 , 10 ))
74
+ productVariant = RTK_FACET;
75
+
76
+ // Facet L-Band: 10/20 --> 2129mV < 2200mV < 2269mV
77
+ else if (idWithAdc (idValue, 10 , 20 ))
78
+ productVariant = RTK_FACET_LBAND;
79
+
80
+ // Express+: 3.3/10 --> 2421mV < 2481mV < 2539mV
81
+ else if (idWithAdc (idValue, 3.3 , 10 ))
82
+ productVariant = RTK_EXPRESS_PLUS;
83
+
84
+ // ID resistors do not exist for the following:
85
+ // Surveyor
86
+ // Unknown
87
+ else
25
88
{
26
- if (zedModuleType == PLATFORM_F9P) productVariant = RTK_EXPRESS ;
27
- else if (zedModuleType == PLATFORM_F9R) productVariant = RTK_EXPRESS_PLUS;
89
+ Serial. println ( " Out of band or nonexistent resistor IDs " ) ;
90
+ productVariant = RTK_UNKNOWN; // Need to wait until the GNSS and Accel have been initialized
28
91
}
29
- else
92
+ }
93
+
94
+ void beginBoard ()
95
+ {
96
+ if (productVariant == RTK_UNKNOWN)
30
97
{
31
- productVariant = RTK_SURVEYOR;
98
+ if (isConnected (0x19 ) == true ) // Check for accelerometer
99
+ {
100
+ if (zedModuleType == PLATFORM_F9P)
101
+ productVariant = RTK_EXPRESS;
102
+ else if (zedModuleType == PLATFORM_F9R)
103
+ productVariant = RTK_EXPRESS_PLUS;
104
+ }
105
+ else
106
+ {
107
+ // Detect RTK Expresses (v1.3 and below) that do not have an accel or device ID resistors
108
+
109
+ // On a Surveyor, pin 34 is not connected. On Express, 34 is connected to ZED_TX_READY
110
+ const int pin_ZedTxReady = 34 ;
111
+ uint16_t pinValue = analogReadMilliVolts (pin_ZedTxReady);
112
+ log_d (" Alternate ID pinValue (mV): %d\r\n " , pinValue); // Surveyor = 142 to 152, //Express = 3129
113
+ if (pinValue > 3000 )
114
+ {
115
+ if (zedModuleType == PLATFORM_F9P)
116
+ productVariant = RTK_EXPRESS;
117
+ else if (zedModuleType == PLATFORM_F9R)
118
+ productVariant = RTK_EXPRESS_PLUS;
119
+ }
120
+ else
121
+ productVariant = RTK_SURVEYOR;
122
+ }
32
123
}
33
124
34
- // Setup hardware pins
125
+ // Setup hardware pins
35
126
if (productVariant == RTK_SURVEYOR)
36
127
{
37
128
pin_batteryLevelLED_Red = 32 ;
@@ -46,13 +137,10 @@ void beginBoard()
46
137
pin_zed_tx_ready = 26 ;
47
138
pin_zed_reset = 27 ;
48
139
pin_batteryLevel_alert = 36 ;
49
- //
50
- // //Bug in ZED-F9P v1.13 firmware causes RTK LED to not light when RTK Floating with SBAS on.
51
- // //The following changes the POR default but will be overwritten by settings in NVM or settings file
52
- // settings.ubxConstellations[1].enabled = false;
53
140
54
- strcpy (platformFilePrefix, " SFE_Surveyor" );
55
- strcpy (platformPrefix, " Surveyor" );
141
+ // Bug in ZED-F9P v1.13 firmware causes RTK LED to not light when RTK Floating with SBAS on.
142
+ // The following changes the POR default but will be overwritten by settings in NVM or settings file
143
+ settings.ubxConstellations [1 ].enabled = false ;
56
144
}
57
145
else if (productVariant == RTK_EXPRESS || productVariant == RTK_EXPRESS_PLUS)
58
146
{
@@ -67,30 +155,20 @@ void beginBoard()
67
155
68
156
pinMode (pin_powerSenseAndControl, INPUT_PULLUP);
69
157
pinMode (pin_powerFastOff, INPUT);
70
- //
158
+
71
159
// if (esp_reset_reason() == ESP_RST_POWERON)
72
160
// {
73
- // powerOnCheck(); //Only do check if we POR start
161
+ // powerOnCheck(); // Only do check if we POR start
74
162
// }
75
- //
76
- // pinMode(pin_setupButton, INPUT_PULLUP);
77
- //
78
- // setMuxport(settings.dataPortChannel); //Set mux to user's choice: NMEA, I2C, PPS, or DAC
79
163
80
- if (productVariant == RTK_EXPRESS)
81
- {
82
- strcpy (platformFilePrefix, " SFE_Express" );
83
- strcpy (platformPrefix, " Express" );
84
- }
85
- else if (productVariant == RTK_EXPRESS_PLUS)
86
- {
87
- strcpy (platformFilePrefix, " SFE_Express_Plus" );
88
- strcpy (platformPrefix, " Express Plus" );
89
- }
164
+ pinMode (pin_setupButton, INPUT_PULLUP);
165
+
166
+ // setMuxport(settings.dataPortChannel); // Set mux to user's choice: NMEA, I2C, PPS, or DAC
90
167
}
91
- else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND)
168
+ else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND ||
169
+ productVariant == RTK_FACET_LBAND_DIRECT)
92
170
{
93
- // // v11
171
+ // v11
94
172
pin_muxA = 2 ;
95
173
pin_muxB = 0 ;
96
174
pin_powerSenseAndControl = 13 ;
@@ -105,81 +183,113 @@ void beginBoard()
105
183
pin_radio_rst = 15 ;
106
184
pin_radio_pwr = 4 ;
107
185
pin_radio_cts = 5 ;
108
- // pin_radio_rts = 255; //Not implemented
186
+ // pin_radio_rts = 255; //Not implemented
109
187
110
188
pinMode (pin_powerSenseAndControl, INPUT_PULLUP);
111
189
pinMode (pin_powerFastOff, INPUT);
112
190
113
191
// if (esp_reset_reason() == ESP_RST_POWERON)
114
192
// {
115
- // powerOnCheck(); //Only do check if we POR start
193
+ // powerOnCheck(); // Only do check if we POR start
116
194
// }
117
- //
118
- // pinMode(pin_peripheralPowerControl, OUTPUT);
119
- // digitalWrite(pin_peripheralPowerControl, HIGH); //Turn on SD, ZED, etc
120
- //
121
- // setMuxport(settings.dataPortChannel); //Set mux to user's choice: NMEA, I2C, PPS, or DAC
122
- //
123
- // //CTS is active low. ESP32 pin 5 has pullup at POR. We must drive it low.
124
- // pinMode(pin_radio_cts, OUTPUT);
125
- // digitalWrite(pin_radio_cts, LOW);
126
195
127
- if (productVariant == RTK_FACET)
196
+ pinMode (pin_peripheralPowerControl, OUTPUT);
197
+ digitalWrite (pin_peripheralPowerControl, HIGH); // Turn on SD, ZED, etc
198
+
199
+ // setMuxport(settings.dataPortChannel); // Set mux to user's choice: NMEA, I2C, PPS, or DAC
200
+
201
+ // CTS is active low. ESP32 pin 5 has pullup at POR. We must drive it low.
202
+ pinMode (pin_radio_cts, OUTPUT);
203
+ digitalWrite (pin_radio_cts, LOW);
204
+
205
+ if (productVariant == RTK_FACET_LBAND_DIRECT)
128
206
{
129
- strcpy (platformFilePrefix, " SFE_Facet" );
130
- strcpy (platformPrefix, " Facet" );
207
+ // Override the default setting if a user has not explicitly configured the setting
208
+ // if (settings.useI2cForLbandCorrectionsConfigured == false)
209
+ // settings.useI2cForLbandCorrections = false;
131
210
}
132
- else if (productVariant == RTK_FACET_LBAND)
211
+ }
212
+ else if (productVariant == REFERENCE_STATION)
213
+ {
214
+ // No powerOnCheck
215
+
216
+ // settings.enablePrintBatteryMessages = false; // No pesky battery messages
217
+ }
218
+
219
+ char versionString[21 ];
220
+ getFirmwareVersion (versionString, sizeof (versionString), true );
221
+ Serial.printf (" SparkFun RTK %s %s\r\n " , platformPrefix, versionString);
222
+
223
+ // Get unit MAC address
224
+ esp_read_mac (wifiMACAddress, ESP_MAC_WIFI_STA);
225
+ memcpy (btMACAddress, wifiMACAddress, sizeof (wifiMACAddress));
226
+ btMACAddress[5 ] +=
227
+ 2 ; // Convert MAC address to Bluetooth MAC (add 2):
228
+ // https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
229
+ memcpy (ethernetMACAddress, wifiMACAddress, sizeof (wifiMACAddress));
230
+ ethernetMACAddress[5 ] += 3 ; // Convert MAC address to Ethernet MAC (add 3)
231
+
232
+ // For all boards, check reset reason. If reset was due to wdt or panic, append last log
233
+ // loadSettingsPartial(); // Loads settings from LFS
234
+ if ((esp_reset_reason () == ESP_RST_POWERON) || (esp_reset_reason () == ESP_RST_SW))
235
+ {
236
+ // reuseLastLog = false; // Start new log
237
+
238
+ if (settings.enableResetDisplay == true )
133
239
{
134
- strcpy (platformFilePrefix, " SFE_Facet_LBand " ) ;
135
- strcpy (platformPrefix, " Facet L-Band " );
240
+ settings. resetCount = 0 ;
241
+ // recordSystemSettingsToFileLFS(settingsFileName); // Avoid overwriting LittleFS settings onto SD
136
242
}
243
+ settings.resetCount = 0 ;
137
244
}
245
+ else
246
+ {
247
+ // reuseLastLog = true; // Attempt to reuse previous log
248
+
249
+ if (settings.enableResetDisplay == true )
250
+ {
251
+ settings.resetCount ++;
252
+ Serial.printf (" resetCount: %d\r\n " , settings.resetCount );
253
+ // recordSystemSettingsToFileLFS(settingsFileName); // Avoid overwriting LittleFS settings onto SD
254
+ }
138
255
139
- // Get unit MAC address
140
- esp_read_mac (unitMACAddress, ESP_MAC_WIFI_STA);
141
- unitMACAddress[5 ] += 2 ; // Convert MAC address to Bluetooth MAC (add 2): https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#mac-address
142
-
143
- // //For all boards, check reset reason. If reset was due to wdt or panic, append last log
144
- // if (esp_reset_reason() == ESP_RST_POWERON)
145
- // {
146
- // reuseLastLog = false; //Start new log
147
- //
148
- // loadSettingsPartial();
149
- // if (settings.enableResetDisplay == true)
150
- // {
151
- // settings.resetCount = 0;
152
- // recordSystemSettings(); //Record to NVM
153
- // }
154
- // }
155
- // else
156
- // {
157
- // reuseLastLog = true; //Attempt to reuse previous log
158
- //
159
- // loadSettingsPartial();
160
- // if (settings.enableResetDisplay == true)
161
- // {
162
- // settings.resetCount++;
163
- // Serial.printf("resetCount: %d\n\r", settings.resetCount);
164
- // recordSystemSettings(); //Record to NVM
165
- // }
166
- //
167
- // Serial.print("Reset reason: ");
168
- // switch (esp_reset_reason())
169
- // {
170
- // case ESP_RST_UNKNOWN: Serial.println(F("ESP_RST_UNKNOWN")); break;
171
- // case ESP_RST_POWERON : Serial.println(F("ESP_RST_POWERON")); break;
172
- // case ESP_RST_SW : Serial.println(F("ESP_RST_SW")); break;
173
- // case ESP_RST_PANIC : Serial.println(F("ESP_RST_PANIC")); break;
174
- // case ESP_RST_INT_WDT : Serial.println(F("ESP_RST_INT_WDT")); break;
175
- // case ESP_RST_TASK_WDT : Serial.println(F("ESP_RST_TASK_WDT")); break;
176
- // case ESP_RST_WDT : Serial.println(F("ESP_RST_WDT")); break;
177
- // case ESP_RST_DEEPSLEEP : Serial.println(F("ESP_RST_DEEPSLEEP")); break;
178
- // case ESP_RST_BROWNOUT : Serial.println(F("ESP_RST_BROWNOUT")); break;
179
- // case ESP_RST_SDIO : Serial.println(F("ESP_RST_SDIO")); break;
180
- // default : Serial.println(F("Unknown"));
181
- // }
182
- // }
256
+ Serial.print (" Reset reason: " );
257
+ switch (esp_reset_reason ())
258
+ {
259
+ case ESP_RST_UNKNOWN:
260
+ Serial.println (" ESP_RST_UNKNOWN" );
261
+ break ;
262
+ case ESP_RST_POWERON:
263
+ Serial.println (" ESP_RST_POWERON" );
264
+ break ;
265
+ case ESP_RST_SW:
266
+ Serial.println (" ESP_RST_SW" );
267
+ break ;
268
+ case ESP_RST_PANIC:
269
+ Serial.println (" ESP_RST_PANIC" );
270
+ break ;
271
+ case ESP_RST_INT_WDT:
272
+ Serial.println (" ESP_RST_INT_WDT" );
273
+ break ;
274
+ case ESP_RST_TASK_WDT:
275
+ Serial.println (" ESP_RST_TASK_WDT" );
276
+ break ;
277
+ case ESP_RST_WDT:
278
+ Serial.println (" ESP_RST_WDT" );
279
+ break ;
280
+ case ESP_RST_DEEPSLEEP:
281
+ Serial.println (" ESP_RST_DEEPSLEEP" );
282
+ break ;
283
+ case ESP_RST_BROWNOUT:
284
+ Serial.println (" ESP_RST_BROWNOUT" );
285
+ break ;
286
+ case ESP_RST_SDIO:
287
+ Serial.println (" ESP_RST_SDIO" );
288
+ break ;
289
+ default :
290
+ Serial.println (" Unknown" );
291
+ }
292
+ }
183
293
}
184
294
185
295
0 commit comments