@@ -84,7 +84,8 @@ boolean isTxCacheSatisfied = false; // Will be true when the DAC has enough cach
8484#define ADC_PIN 34 // If this is changed, you may need to manually edit adc1_config_channel_atten() below too.
8585#define PTT_PIN 18 // Keys up the radio module
8686#define PD_PIN 19
87- #define SQ_PIN 32
87+ // #define SQ_PIN 32
88+ uint8_t SQ_PIN = 32 ;
8889#define PHYS_PTT_PIN1 5 // Optional. Buttons may be attached to either or both of this and next pin. They behave the same.
8990#define PHYS_PTT_PIN2 33 // Optional. See above.
9091
@@ -129,6 +130,17 @@ bool lastSquelched = false;
129130#define ADC_ATTEN_DB_12 ADC_ATTEN_DB_11
130131#endif
131132
133+ // Hardware version detection
134+ #define HW_VER_PIN_0 39 // 0xF0
135+ #define HW_VER_PIN_1 36 // 0x0F
136+ typedef uint8_t hw_ver_t ; // This allows us to do a lot more in the future if we want.
137+ // LOW = 0, HIGH = F, 1 <= analog values <= E
138+ #define HW_VER_V1 (0x00 )
139+ #define HW_VER_V2_0C (0xFF )
140+ #define HW_VER_V2_0D (0xF0 )
141+ // #define HW_VER_?? (0x0F) // Unused
142+ hw_ver_t hardware_version = HW_VER_V1; // lowest common denominator
143+
132144// //////////////////////////////////////////////////////////////////////////////
133145// / Forward Declarations
134146// //////////////////////////////////////////////////////////////////////////////
@@ -139,13 +151,33 @@ void tuneTo(float freqTx, float freqRx, int tone, int squelch, String bandwidth)
139151void setMode (int newMode);
140152void processTxAudio (uint8_t tempBuffer[], int bytesRead);
141153void iir_lowpass_reset ();
154+ hw_ver_t get_hardware_version ();
142155
143156void setup () {
157+ // Used for setup, need to know early.
158+ hardware_version = get_hardware_version ();
159+
144160 // Communication with Android via USB cable
145161 Serial.setRxBufferSize (USB_BUFFER_SIZE);
146162 Serial.setTxBufferSize (USB_BUFFER_SIZE);
147163 Serial.begin (230400 );
148164
165+ // Hardware dependent pin assignments.
166+ switch (hardware_version) {
167+ case HW_VER_V1:
168+ SQ_PIN = 32 ;
169+ break ;
170+ case HW_VER_V2_0C:
171+ SQ_PIN = 4 ;
172+ break ;
173+ case HW_VER_V2_0D:
174+ SQ_PIN = 4 ;
175+ break ;
176+ default :
177+ // Unknown version detected. Indicate this some way?
178+ break ;
179+ }
180+
149181 // Configure watch dog timer (WDT), which will reset the system if it gets stuck somehow.
150182 esp_task_wdt_init (10 , true ); // Reboot if locked up for a bit
151183 esp_task_wdt_add (NULL ); // Add the current task to WDT watch
@@ -182,7 +214,12 @@ void initI2SRx() {
182214
183215 // Initialize ADC
184216 adc1_config_width (ADC_WIDTH_BIT_12);
185- adc1_config_channel_atten (ADC1_CHANNEL_6, ADC_ATTEN_DB_12);
217+ if (hardware_version == HW_VER_V2_0C) {
218+ // v2.0c has a lower input ADC range
219+ adc1_config_channel_atten (ADC1_CHANNEL_6, ADC_ATTEN_DB_0);
220+ } else {
221+ adc1_config_channel_atten (ADC1_CHANNEL_6, ADC_ATTEN_DB_12);
222+ }
186223
187224 static const i2s_config_t i2sRxConfig = {
188225 .mode = (i2s_mode_t ) (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),
@@ -336,7 +373,13 @@ void loop() {
336373 radioModuleStatus = RADIO_MODULE_FOUND;
337374 }
338375
339- result = dra->volume (8 );
376+ if (hardware_version == HW_VER_V2_0C) {
377+ // v2.0c has a lower input ADC range.
378+ result = dra->volume (4 );
379+ } else {
380+ result = dra->volume (8 );
381+ }
382+
340383 // Serial.println("volume: " + String(result));
341384 result = dra->filters (false , false , false );
342385 // Serial.println("filters: " + String(result));
@@ -771,3 +814,17 @@ void processTxAudio(uint8_t tempBuffer[], int bytesRead) {
771814void reportPhysPttState () {
772815 sendCmdToAndroid (isPhysPttDown ? COMMAND_PHYS_PTT_DOWN : COMMAND_PHYS_PTT_UP);
773816}
817+
818+ hw_ver_t get_hardware_version () {
819+ pinMode (HW_VER_PIN_0, INPUT);
820+ pinMode (HW_VER_PIN_1, INPUT);
821+
822+ hw_ver_t ver = 0x00 ;
823+ ver |= (digitalRead (HW_VER_PIN_0) == HIGH ? 0x0F : 0x00 );
824+ ver |= (digitalRead (HW_VER_PIN_1) == HIGH ? 0xF0 : 0x00 );
825+
826+ // In the future, we're replace these with analogRead()s and
827+ // use values between 0x0 and 0xF. For now, just binary.
828+
829+ return ver;
830+ }
0 commit comments