2019-12-18 01:32:44 -05:00
|
|
|
/**
|
|
|
|
* This source file is under General Public License version 3.
|
|
|
|
*
|
|
|
|
* This verision uses a built-in Si5351 library
|
|
|
|
* Most source code are meant to be understood by the compilers and the computers.
|
|
|
|
* Code that has to be hackable needs to be well understood and properly documented.
|
|
|
|
* Donald Knuth coined the term Literate Programming to indicate code that is written be
|
|
|
|
* easily read and understood.
|
|
|
|
*
|
|
|
|
* The Raduino is a small board that includes the Arduin Nano, a TFT display and
|
|
|
|
* an Si5351a frequency synthesizer. This board is manufactured by HF Signals Electronics Pvt Ltd
|
|
|
|
*
|
|
|
|
* To learn more about Arduino you may visit www.arduino.cc.
|
|
|
|
*
|
|
|
|
* The Arduino works by starts executing the code in a function called setup() and then it
|
|
|
|
* repeatedly keeps calling loop() forever. All the initialization code is kept in setup()
|
|
|
|
* and code to continuously sense the tuning knob, the function button, transmit/receive,
|
|
|
|
* etc is all in the loop() function. If you wish to study the code top down, then scroll
|
|
|
|
* to the bottom of this file and read your way up.
|
|
|
|
*
|
|
|
|
* Below are the libraries to be included for building the Raduino
|
|
|
|
* The EEPROM library is used to store settings like the frequency memory, caliberation data, etc.
|
|
|
|
*
|
|
|
|
* The main chip which generates upto three oscillators of various frequencies in the
|
|
|
|
* Raduino is the Si5351a. To learn more about Si5351a you can download the datasheet
|
|
|
|
* from www.silabs.com although, strictly speaking it is not a requirment to understand this code.
|
|
|
|
* Instead, you can look up the Si5351 library written by xxx, yyy. You can download and
|
|
|
|
* install it from www.url.com to complile this file.
|
|
|
|
* The Wire.h library is used to talk to the Si5351 and we also declare an instance of
|
|
|
|
* Si5351 object to control the clocks.
|
|
|
|
*/
|
|
|
|
#include <Wire.h>
|
2020-04-25 14:47:11 -04:00
|
|
|
#include "encoder.h"
|
2020-02-09 20:59:58 -05:00
|
|
|
#include "menu.h"
|
|
|
|
#include "menu_main.h"
|
2020-01-22 02:19:00 -05:00
|
|
|
#include "morse.h"
|
2020-04-22 00:16:10 -04:00
|
|
|
#include "pin_definitions.h"
|
2020-04-25 14:47:11 -04:00
|
|
|
#include "push_button.h"
|
2020-01-22 02:19:00 -05:00
|
|
|
#include "nano_gui.h"
|
2020-01-04 02:11:55 -05:00
|
|
|
#include "settings.h"
|
2020-01-19 21:40:11 -05:00
|
|
|
#include "setup.h"
|
2020-02-09 21:41:47 -05:00
|
|
|
#include "touch.h"
|
2020-04-22 00:16:10 -04:00
|
|
|
#include "tuner.h"
|
2020-02-09 21:44:17 -05:00
|
|
|
#include "ui_touch.h"
|
2019-12-18 01:32:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Arduino, unlike C/C++ on a regular computer with gigabytes of RAM, has very little memory.
|
|
|
|
* We have to be very careful with variables that are declared inside the functions as they are
|
|
|
|
* created in a memory region called the stack. The stack has just a few bytes of space on the Arduino
|
|
|
|
* if you declare large strings inside functions, they can easily exceed the capacity of the stack
|
|
|
|
* and mess up your programs.
|
2020-01-19 21:40:11 -05:00
|
|
|
* We circumvent this by declaring a few global buffers as kitchen counters where we can
|
2019-12-18 01:32:44 -05:00
|
|
|
* slice and dice our strings. These strings are mostly used to control the display or handle
|
|
|
|
* the input and output from the USB port. We must keep a count of the bytes used while reading
|
|
|
|
* the serial port as we can easily run out of buffer space. This is done in the serial_in_count variable.
|
|
|
|
*/
|
2020-01-19 21:41:36 -05:00
|
|
|
char b[128];
|
2020-01-19 21:40:11 -05:00
|
|
|
char c[30];
|
2019-12-18 01:32:44 -05:00
|
|
|
|
|
|
|
//during CAT commands, we will freeeze the display until CAT is disengaged
|
|
|
|
unsigned char doingCAT = 0;
|
2020-01-04 02:11:55 -05:00
|
|
|
|
2019-12-18 01:32:44 -05:00
|
|
|
/**
|
|
|
|
* Basic User Interface Routines. These check the front panel for any activity
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The PTT is checked only if we are not already in a cw transmit session
|
|
|
|
* If the PTT is pressed, we shift to the ritbase if the rit was on
|
|
|
|
* flip the T/R line to T and update the display to denote transmission
|
|
|
|
*/
|
|
|
|
|
2020-01-04 02:11:55 -05:00
|
|
|
void checkPTT(){
|
2019-12-18 01:32:44 -05:00
|
|
|
//we don't check for ptt when transmitting cw
|
2020-01-04 02:11:55 -05:00
|
|
|
if (globalSettings.cwExpirationTimeMs > 0){
|
2019-12-18 01:32:44 -05:00
|
|
|
return;
|
2020-01-04 02:11:55 -05:00
|
|
|
}
|
2019-12-18 01:32:44 -05:00
|
|
|
|
2020-04-22 00:16:10 -04:00
|
|
|
if(digitalRead(PIN_PTT) == 0 && !globalSettings.txActive){
|
2020-01-04 02:11:55 -05:00
|
|
|
startTx(TuningMode_e::TUNE_SSB);
|
2020-02-15 20:10:27 -05:00
|
|
|
delay(50); //debounce the PTT
|
2019-12-18 01:32:44 -05:00
|
|
|
}
|
|
|
|
|
2020-04-22 00:16:10 -04:00
|
|
|
if (digitalRead(PIN_PTT) == 1 && globalSettings.txActive)
|
2019-12-18 01:32:44 -05:00
|
|
|
stopTx();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The settings are read from EEPROM. The first time around, the values may not be
|
|
|
|
* present or out of range, in this case, some intelligent defaults are copied into the
|
|
|
|
* variables.
|
|
|
|
*/
|
|
|
|
void initSettings(){
|
2020-01-14 02:38:12 -05:00
|
|
|
LoadDefaultSettings();
|
2020-01-04 02:11:55 -05:00
|
|
|
LoadSettingsFromEeprom();
|
2019-12-18 01:32:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void initPorts(){
|
|
|
|
|
|
|
|
analogReference(DEFAULT);
|
|
|
|
|
|
|
|
//??
|
2020-04-22 00:16:10 -04:00
|
|
|
pinMode(PIN_ENC_A, INPUT_PULLUP);
|
|
|
|
pinMode(PIN_ENC_B, INPUT_PULLUP);
|
|
|
|
pinMode(PIN_ENC_PUSH_BUTTON, INPUT_PULLUP);
|
2020-01-11 14:00:44 -05:00
|
|
|
enc_setup();
|
2019-12-18 01:32:44 -05:00
|
|
|
|
|
|
|
//configure the function button to use the external pull-up
|
2020-04-22 00:16:10 -04:00
|
|
|
// pinMode(PIN_ENC_PUSH_BUTTON, INPUT);
|
|
|
|
// digitalWrite(PIN_ENC_PUSH_BUTTON, HIGH);
|
2019-12-18 01:32:44 -05:00
|
|
|
|
2020-04-22 00:16:10 -04:00
|
|
|
pinMode(PIN_PTT, INPUT_PULLUP);
|
|
|
|
// pinMode(PIN_ANALOG_KEYER, INPUT_PULLUP);
|
2019-12-18 01:32:44 -05:00
|
|
|
|
2020-04-22 00:16:10 -04:00
|
|
|
pinMode(PIN_CW_TONE, OUTPUT);
|
|
|
|
digitalWrite(PIN_CW_TONE, 0);
|
2019-12-18 01:32:44 -05:00
|
|
|
|
2020-04-22 00:16:10 -04:00
|
|
|
pinMode(PIN_TX_RXn,OUTPUT);
|
|
|
|
digitalWrite(PIN_TX_RXn, 0);
|
|
|
|
|
|
|
|
pinMode(PIN_TX_LPF_A, OUTPUT);
|
|
|
|
pinMode(PIN_TX_LPF_B, OUTPUT);
|
|
|
|
pinMode(PIN_TX_LPF_C, OUTPUT);
|
|
|
|
digitalWrite(PIN_TX_LPF_A, 0);
|
|
|
|
digitalWrite(PIN_TX_LPF_B, 0);
|
|
|
|
digitalWrite(PIN_TX_LPF_C, 0);
|
|
|
|
|
|
|
|
pinMode(PIN_CW_KEY, OUTPUT);
|
|
|
|
digitalWrite(PIN_CW_KEY, 0);
|
2019-12-18 01:32:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(38400);
|
2020-01-19 21:40:11 -05:00
|
|
|
Serial.flush();
|
2019-12-18 01:32:44 -05:00
|
|
|
|
|
|
|
initSettings();
|
2020-01-14 02:38:12 -05:00
|
|
|
displayInit();
|
2020-02-09 21:41:47 -05:00
|
|
|
initTouch();
|
2020-01-04 02:11:55 -05:00
|
|
|
initPorts();
|
2019-12-18 01:32:44 -05:00
|
|
|
initOscillators();
|
2020-01-04 02:11:55 -05:00
|
|
|
setFrequency(globalSettings.vfoA.frequency);
|
2019-12-18 01:32:44 -05:00
|
|
|
|
2020-01-04 02:11:55 -05:00
|
|
|
//Run initial calibration routine if button is pressed during power up
|
2020-04-25 15:00:19 -04:00
|
|
|
if(ButtonPress_e::NotPressed != CheckTunerButton()){
|
2020-01-18 02:10:38 -05:00
|
|
|
LoadDefaultSettings();
|
2019-12-18 02:01:01 -05:00
|
|
|
setupTouch();
|
2020-01-04 02:11:55 -05:00
|
|
|
SetActiveVfoMode(VfoMode_e::VFO_MODE_USB);
|
2020-01-18 02:10:38 -05:00
|
|
|
setFrequency(10000000L);
|
2020-01-19 21:40:11 -05:00
|
|
|
runLocalOscSetting();
|
2020-01-04 02:11:55 -05:00
|
|
|
SetActiveVfoMode(VfoMode_e::VFO_MODE_LSB);
|
2020-01-18 02:10:38 -05:00
|
|
|
setFrequency(7100000L);
|
2020-01-19 22:24:26 -05:00
|
|
|
runBfoSetting();
|
2019-12-18 01:32:44 -05:00
|
|
|
}
|
|
|
|
|
2020-02-10 01:01:19 -05:00
|
|
|
rootMenu->initMenu();
|
2019-12-18 01:32:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The loop checks for keydown, ptt, function button and tuning.
|
|
|
|
*/
|
|
|
|
|
2020-01-04 02:11:55 -05:00
|
|
|
void loop(){
|
|
|
|
if(TuningMode_e::TUNE_CW == globalSettings.tuningMode){
|
|
|
|
cwKeyer();
|
|
|
|
}
|
|
|
|
else if(!globalSettings.txCatActive){
|
2019-12-18 01:32:44 -05:00
|
|
|
checkPTT();
|
2020-01-04 02:11:55 -05:00
|
|
|
}
|
2019-12-18 01:32:44 -05:00
|
|
|
|
|
|
|
checkCAT();
|
2020-02-09 20:59:58 -05:00
|
|
|
|
|
|
|
if(globalSettings.txActive){
|
|
|
|
//Don't run menus when transmitting
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-25 15:00:19 -04:00
|
|
|
ButtonPress_e tuner_button = CheckTunerButton();
|
2020-02-09 20:59:58 -05:00
|
|
|
Point touch_point;
|
|
|
|
ButtonPress_e touch_button = checkTouch(&touch_point);
|
|
|
|
int16_t knob = enc_read();
|
2020-02-15 17:43:05 -05:00
|
|
|
runActiveMenu(tuner_button,touch_button,touch_point,knob);
|
2019-12-18 01:32:44 -05:00
|
|
|
}
|