Make code work with ESP32 boards as well #11

Open
W1CDN wants to merge 1 commits from esp32-devkit-doit into main
2 changed files with 53 additions and 10 deletions

View File

@ -8,7 +8,10 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio]
[env:metro] [env:metro]
build_flags = -D ARDUINO1
platform = atmelavr platform = atmelavr
board = metro board = metro
framework = arduino framework = arduino
@ -17,3 +20,16 @@ lib_deps =
paulstoffregen/Encoder@^1.4.4 paulstoffregen/Encoder@^1.4.4
adafruit/Adafruit GFX Library@^1.11.9 adafruit/Adafruit GFX Library@^1.11.9
adafruit/Adafruit SSD1306@^2.5.9 adafruit/Adafruit SSD1306@^2.5.9
[env:esp32doit-devkit-v1]
build_flags = -D ESP32DOIT
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
upload_speed = 921600
monitor_speed = 115200
lib_deps =
etherkit/Etherkit Si5351@^2.1.4
adafruit/Adafruit GFX Library@^1.11.9
adafruit/Adafruit SSD1306@^2.5.9
igorantolic/Ai Esp32 Rotary Encoder@^1.6

View File

@ -13,6 +13,23 @@
//User preferences //User preferences
//------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------
#ifdef ESP32DOIT //use the ESP32 DEVKIT DOIT environment
#pragma "ESP32DOIT" //show in console on build
#define board 1 //Define board
#define IF 0 //Enter your IF frequency, ex: 455 = 455kHz, 10700 = 10.7MHz, 0 = to direct convert receiver or RF generator, + will add and - will subtract IF offfset.
#define BAND_INIT 7 //Enter your initial Band (1-21) at startup, ex: 1 = Freq Generator, 2 = 800kHz (MW), 7 = 7.2MHz (40m), 11 = 14.1MHz (20m).
#define XT_CAL_F 33000 //Si5351 calibration factor, adjust to get exatcly 10MHz. Increasing this value will decreases the frequency and vice versa.
#define S_GAIN 303 //Adjust the sensitivity of Signal Meter A/D input: 101 = 500mv; 202 = 1v; 303 = 1.5v; 404 = 2v; 505 = 2.5v; 1010 = 5v (max).
#define tunestep 32 //The pin used by tune step push button.
#define band 33 //The pin used by band selector push button.
#define rx_tx 5 //The pin used by RX / TX selector switch, RX = switch open, TX = switch closed to GND. When in TX, the IF value is not considered.
#define adc 4 //The pin used by Signal Meter A/D input.
#define rotary1 34 //First pin for rotary encoder.
#define rotary2 35 //Second pin for rotary encoder.
#else // use the ARDUINO1 environment
#pragma "ARDUINO1" //show in console on build
#define board 0 //Define board
#define IF 0 //Enter your IF frequency, ex: 455 = 455kHz, 10700 = 10.7MHz, 0 = to direct convert receiver or RF generator, + will add and - will subtract IF offfset. #define IF 0 //Enter your IF frequency, ex: 455 = 455kHz, 10700 = 10.7MHz, 0 = to direct convert receiver or RF generator, + will add and - will subtract IF offfset.
#define BAND_INIT 7 //Enter your initial Band (1-21) at startup, ex: 1 = Freq Generator, 2 = 800kHz (MW), 7 = 7.2MHz (40m), 11 = 14.1MHz (20m). #define BAND_INIT 7 //Enter your initial Band (1-21) at startup, ex: 1 = Freq Generator, 2 = 800kHz (MW), 7 = 7.2MHz (40m), 11 = 14.1MHz (20m).
#define XT_CAL_F 33000 //Si5351 calibration factor, adjust to get exatcly 10MHz. Increasing this value will decreases the frequency and vice versa. #define XT_CAL_F 33000 //Si5351 calibration factor, adjust to get exatcly 10MHz. Increasing this value will decreases the frequency and vice versa.
@ -23,6 +40,8 @@
#define adc A3 //The pin used by Signal Meter A/D input. #define adc A3 //The pin used by Signal Meter A/D input.
#define rotary1 2 //First pin for rotary encoder. #define rotary1 2 //First pin for rotary encoder.
#define rotary2 3 //Second pin for rotary encoder. #define rotary2 3 //Second pin for rotary encoder.
#endif
//------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------
Rotary r = Rotary(rotary1, rotary2); Rotary r = Rotary(rotary1, rotary2);
@ -56,11 +75,15 @@ void set_frequency(short dir) {
} }
} }
ISR(PCINT2_vect) { #ifdef ESP32DOIT //use the ESP32 DEVKIT DOIT environment
//TODO
#else
ISR(PCINT2_vect) {
char result = r.process(); char result = r.process();
if (result == DIR_CW) set_frequency(1); if (result == DIR_CW) set_frequency(1);
else if (result == DIR_CCW) set_frequency(-1); else if (result == DIR_CCW) set_frequency(-1);
} }
#endif
void tunegen() { void tunegen() {
si5351.set_freq((freq + (interfreq * 1000ULL)) * 100ULL, SI5351_CLK0); si5351.set_freq((freq + (interfreq * 1000ULL)) * 100ULL, SI5351_CLK0);
@ -257,9 +280,13 @@ void setup() {
si5351.output_enable(SI5351_CLK1, 0); si5351.output_enable(SI5351_CLK1, 0);
si5351.output_enable(SI5351_CLK2, 0); si5351.output_enable(SI5351_CLK2, 0);
#ifdef ESP32DOIT
//TODO
#else
PCICR |= (1 << PCIE2); PCICR |= (1 << PCIE2);
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19); PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
sei(); sei();
#endif
count = BAND_INIT; count = BAND_INIT;
bandpresets(); bandpresets();