├── .gitignore ├── history.txt ├── Doc ├── dislpay_edit.jpg ├── dislpay_freq.jpg ├── Schematic_Nano-VFO.pdf └── Schematic_Nano-VFO.png ├── NanoVFO ├── Encoder.h ├── disp_MAX7219.h ├── disp_OLED128x32.h ├── disp_OLED128x64.h ├── disp_OLED_SH1106_128x64.h ├── disp_1602.h ├── TRX.h ├── pins.h ├── config_hw.h ├── config_sw.h ├── disp_OLED128x64.cpp ├── disp_OLED_SH1106_128x64.cpp ├── fonts │ ├── lcdnums12x16mod.h │ └── lcdnums14x24mod.h ├── disp_MAX7219.cpp ├── disp_OLED128x32.cpp ├── TRX.cpp ├── Encoder.cpp ├── LCD1602_I2C.h ├── config.h ├── disp_1602.cpp ├── pins.cpp ├── freq_calc.h ├── LCD1602_I2C.cpp └── NanoVFO.ino ├── README.md └── license.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /2do.txt 2 | NanoVFO.pio 3 | -------------------------------------------------------------------------------- /history.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-belokon/NanoVFO/HEAD/history.txt -------------------------------------------------------------------------------- /Doc/dislpay_edit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-belokon/NanoVFO/HEAD/Doc/dislpay_edit.jpg -------------------------------------------------------------------------------- /Doc/dislpay_freq.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-belokon/NanoVFO/HEAD/Doc/dislpay_freq.jpg -------------------------------------------------------------------------------- /Doc/Schematic_Nano-VFO.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-belokon/NanoVFO/HEAD/Doc/Schematic_Nano-VFO.pdf -------------------------------------------------------------------------------- /Doc/Schematic_Nano-VFO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrey-belokon/NanoVFO/HEAD/Doc/Schematic_Nano-VFO.png -------------------------------------------------------------------------------- /NanoVFO/Encoder.h: -------------------------------------------------------------------------------- 1 | #ifndef ENCODER_H 2 | #define ENCODER_H 3 | 4 | #include 5 | 6 | class Encoder { 7 | public: 8 | static void Setup(); 9 | static long GetDelta(); 10 | static void SetValue(long Value); 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /NanoVFO/disp_MAX7219.h: -------------------------------------------------------------------------------- 1 | #ifndef DISP_MAX7219_H 2 | #define DISP_MAX7219_H 3 | 4 | #if ARDUINO < 100 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #include "TRX.h" 11 | 12 | class Display_MAX7219 { 13 | private: 14 | long lastfreq; 15 | uint8_t last_cw; 16 | uint8_t last_brightness; 17 | public: 18 | void setup(); 19 | // 1..15 20 | void setBright(uint8_t brightness); 21 | void Draw(TRX& trx); 22 | void DrawMenu(int id, char* text, int value, uint8_t edit); 23 | void clear(); 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /NanoVFO/disp_OLED128x32.h: -------------------------------------------------------------------------------- 1 | #ifndef DISP_OLED12832_H 2 | #define DISP_OLED12832_H 3 | 4 | #if ARDUINO < 100 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #include "TRX.h" 11 | 12 | class Display_OLED128x32 { 13 | private: 14 | long last_freq; 15 | uint8_t last_tx; 16 | int last_BandIndex; 17 | uint8_t last_wpm; 18 | uint8_t last_cw; 19 | byte last_brightness; 20 | public: 21 | void setup(); 22 | // 1..15 23 | void setBright(uint8_t brightness); 24 | void Draw(TRX& trx); 25 | void DrawMenu(int id, char* text, int value, uint8_t edit); 26 | void clear(); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /NanoVFO/disp_OLED128x64.h: -------------------------------------------------------------------------------- 1 | #ifndef DISP_OLED12864_H 2 | #define DISP_OLED12864_H 3 | 4 | #if ARDUINO < 100 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #include "TRX.h" 11 | 12 | class Display_OLED128x64 { 13 | private: 14 | long last_freq; 15 | uint8_t last_tx; 16 | int last_BandIndex; 17 | uint8_t last_wpm; 18 | uint8_t last_cw; 19 | byte last_brightness; 20 | public: 21 | void setup(); 22 | // 1..15 23 | void setBright(uint8_t brightness); 24 | void Draw(TRX& trx); 25 | void DrawMenu(int id, char* text, int value, uint8_t edit); 26 | void clear(); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /NanoVFO/disp_OLED_SH1106_128x64.h: -------------------------------------------------------------------------------- 1 | #ifndef DISP_OLED_SH1106_12864_H 2 | #define DISP_OLED_SH1106_12864_H 3 | 4 | #if ARDUINO < 100 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #include "TRX.h" 11 | 12 | class Display_OLED_SH1106_128x64 { 13 | private: 14 | long last_freq; 15 | uint8_t last_tx; 16 | int last_BandIndex; 17 | uint8_t last_wpm; 18 | uint8_t last_cw; 19 | byte last_brightness; 20 | public: 21 | void setup(); 22 | // 1..15 23 | void setBright(uint8_t brightness); 24 | void Draw(TRX& trx); 25 | void DrawMenu(int id, char* text, int value, uint8_t edit); 26 | void clear(); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /NanoVFO/disp_1602.h: -------------------------------------------------------------------------------- 1 | #ifndef DISP_1602_H 2 | #define DISP_1602_H 3 | 4 | #if ARDUINO < 100 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #include "TRX.h" 11 | #include "LCD1602_I2C.h" 12 | 13 | class Display_1602_I2C { 14 | private: 15 | LiquidCrystal_I2C lcd; 16 | uint8_t last_tx; 17 | int last_BandIndex; 18 | long last_freq; 19 | uint8_t last_wpm; 20 | uint8_t last_cw; 21 | public: 22 | Display_1602_I2C (int i2c_addr): lcd(i2c_addr,16,2) {} 23 | void setup(); 24 | void setBright(uint8_t brightness); 25 | void Draw(TRX& trx); 26 | void DrawMenu(int id, char* text, int value, uint8_t edit); 27 | void clear(); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /NanoVFO/TRX.h: -------------------------------------------------------------------------------- 1 | #ifndef TRX_H 2 | #define TRX_H 3 | 4 | #include 5 | #include "config.h" 6 | 7 | class TRX { 8 | public: 9 | long BandData[BAND_COUNT+1]; 10 | int BandIndex; 11 | long Freq; 12 | uint8_t sideband; 13 | uint8_t CW; 14 | uint8_t TX; 15 | uint8_t CWTX; 16 | uint8_t cw_speed; 17 | uint16_t dit_time; 18 | uint16_t dah_time; 19 | 20 | TRX(); 21 | void SwitchToBand(int band); 22 | void NextBand(); 23 | void PrevBand(); 24 | void ChangeFreq(long freq_delta); 25 | uint8_t inCW(); 26 | uint8_t setCWSpeed(uint8_t speed, int dash_ratio); 27 | 28 | uint16_t StateHash(); 29 | void StateSave(); 30 | void StateLoad(); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Nano VFO for portable TRX

2 | 3 | CPU: Arduino ProMini
4 | PLL: Si5351 or/and Si570
5 | Display: OLED 0.91" 128x32, OLED 0.96" 128x64, OLED 1.3" 128/132x64, I2C LCD 1602, MAX7219
6 | Encoder: optical/mechanic rotary encode 7 | Keypad: 0..6 buttons 8 | Support different TRX architecture:
9 | 1. Single IF superheterodyne. 10 | 2. Direct conversion with 2x or 4x output. 11 | 3. Direct conversion with quadrature output. 12 | Builtin CW key: auto/iamboc mode, 3 phrase memory, CW-VOX, touch mode 13 | 14 | Project homepage http://dspview.com/viewtopic.php?t=202 15 | Required libraries:
16 | 1. UR5FFR_Si5351 https://github.com/andrey-belokon/UR5FFR_Si5351 17 | 2. SSD1306Ascii - install from Arduino IDE 18 | 19 | What's new in version 2.0
20 | 1. Save current freq/band to EEPROM and restore on star 21 | 2. Improved encoder unit. 4x increase pulses for mechanical encoder 22 | 3. New Si5351 library 23 | 4. Change power to 5v without I2C level conversion 24 | 5. Many minor bugfixes 25 | 26 | 27 | 28 | 29 | 30 | Copyright (c) 2016-2020, Andrii Bilokon, UR5FFR
31 | License GNU GPL, see license.txt for more information -------------------------------------------------------------------------------- /NanoVFO/pins.h: -------------------------------------------------------------------------------- 1 | #ifndef PINS_H 2 | #define PINS_H 3 | 4 | #include 5 | 6 | #define PIN_NC 0xFF 7 | 8 | // pin with bouncing, pull up and active low level 9 | class InputPullUpPin { 10 | private: 11 | uint8_t pin; 12 | uint8_t last; 13 | long last_tm; 14 | public: 15 | InputPullUpPin(uint8_t _pin):pin(_pin),last(false),last_tm(0) {} 16 | void setup(); 17 | uint8_t Read(); 18 | }; 19 | 20 | // return raw ADC result for internal 1.1v voltage reference 21 | int ReadV11Ref(); 22 | 23 | class InputAnalogPin { 24 | private: 25 | uint8_t pin; 26 | int value,rfac; 27 | public: 28 | InputAnalogPin(uint8_t _pin, int _rfac=0): 29 | pin(_pin),value(0),rfac(_rfac) {} 30 | void setup(); 31 | int Read(); 32 | // return raw ADC data 0..1023 33 | int ReadRaw(); 34 | }; 35 | 36 | class InputAnalogKeypad { 37 | private: 38 | uint8_t pin; 39 | uint8_t btn_cnt; 40 | int16_t *levels; 41 | uint8_t last; 42 | long last_tm; 43 | public: 44 | InputAnalogKeypad(uint8_t _pin, uint8_t _btn_cnt, int16_t *_levels): pin(_pin), btn_cnt(_btn_cnt), levels(_levels), last_tm(-1000) {} 45 | void setup(); 46 | uint8_t Read(); 47 | void waitUnpress(); 48 | }; 49 | 50 | class OutputBinPin { 51 | private: 52 | uint8_t pin,active_level,def_value,state; 53 | public: 54 | OutputBinPin(uint8_t _pin, uint8_t _def_value, uint8_t _active_level): 55 | pin(_pin),active_level(_active_level),def_value(_def_value),state(0xFF) {} 56 | void setup(); 57 | void Write(uint8_t value); 58 | }; 59 | 60 | class OutputPCF8574 { 61 | private: 62 | uint8_t i2c_addr,value,old_value; 63 | void pcf8574_write(uint8_t data); 64 | public: 65 | OutputPCF8574(uint8_t _i2c_addr, uint8_t init_state):i2c_addr(_i2c_addr),value(init_state),old_value(init_state) {} 66 | void setup(); 67 | void Set(uint8_t pin, uint8_t state); 68 | void Write(); 69 | }; 70 | 71 | void OutputTone(uint8_t pin, int value); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /NanoVFO/config_hw.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_HW_H 2 | #define CONFIG_HW_H 3 | 4 | // раскоментировать используемый дисплей (только один!). 5 | //#define DISPLAY_1602 // LCD 1602 via I2C 6 | //#define DISPLAY_MAX7219 7 | //#define DISPLAY_OLED128x32 // OLED 0.91" 128x32 8 | #define DISPLAY_OLED128x64 // OLED 0.96" 128x64 9 | //#define DISPLAY_OLED_SH1106_128x64 // OLED 1.3" 128x64 (132x64) 10 | 11 | #define I2C_ADR_DISPLAY_1602 0x27 12 | 13 | // keypad pool interval in ms 14 | #define POOL_INTERVAL 50 15 | 16 | // раскоментировать установленные чипы 17 | #define VFO_SI5351 18 | //#define VFO_SI570 19 | 20 | // выбрать в меню калибровку и прописать измеренные частоты на выходах синтезаторов 21 | #define SI5351_CALIBRATION 25000000 22 | #define SI570_CALIBRATION 56319832 23 | 24 | // уровень сигнала на выходе Si5351. 0=2mA, 1=4mA, 2=6mA, 3=8mA 25 | #define SI5351_CLK0_DRIVE 0 26 | #define SI5351_CLK1_DRIVE 0 27 | #define SI5351_CLK2_DRIVE 0 28 | 29 | // Pin mapping and active levels 30 | #define PIN_OUT_CW 13 31 | #define OUT_CW_ACTIVE_LEVEL HIGH 32 | #define PIN_OUT_PTT 12 33 | #define OUT_PTT_ACTIVE_LEVEL HIGH 34 | #define PIN_OUT_KEY 11 35 | #define OUT_KEY_ACTIVE_LEVEL HIGH 36 | 37 | #define PIN_IN_PTT 9 38 | #define PIN_OUT_TONE 10 39 | #define PIN_ANALOG_KEYPAD A6 40 | #define PIN_CW_SPEED_POT A7 41 | 42 | #define PIN_IN_DIT 4 43 | #define PIN_IN_DAH 5 44 | 45 | // строб для "сенсорного" ключа 46 | #define PIN_KEY_READ_STROB 6 47 | 48 | #define PIN_OUT_BAND0 17 49 | #define PIN_OUT_BAND1 16 50 | #define PIN_OUT_BAND2 15 51 | #define PIN_OUT_BAND3 14 52 | // HIGH or LOW - active level for PIN_OUT_BAND* 53 | #define BAND_ACTIVE_LEVEL_HIGH 54 | //#define BAND_ACTIVE_LEVEL_LOW 55 | 56 | // раскоментировать ТОЛЬКО ОДИН требуемый тип энкодера. закоментировать все если нет 57 | //#define ENCODER_OPTICAL 58 | #define ENCODER_MECHANIC 59 | 60 | #if defined(ENCODER_OPTICAL) && defined(ENCODER_MECHANIC) 61 | #error You need select single encoder 62 | #endif 63 | 64 | // изменение частоты в Гц на один оборот в обычном режиме 65 | #define ENCODER_FREQ_LO_STEP 3000 66 | // изменение частоты в Гц на один оборот в ускоренном режиме 67 | #define ENCODER_FREQ_HI_STEP 15000 68 | // порог переключения в ускоренный режим. если частота изменится более 69 | // чем на ENCODER_FREQ_HI_LO_TRASH Гц за секунду то переходим в ускоренный режим 70 | #define ENCODER_FREQ_HI_LO_TRASH 2000 71 | 72 | #ifdef ENCODER_OPTICAL 73 | #define ENCODER_ENABLE 74 | // количество импульсов на оборот примененного оптического энкодера 75 | #define ENCODER_PULSE_PER_TURN 360 76 | #endif 77 | 78 | #ifdef ENCODER_MECHANIC 79 | #define ENCODER_ENABLE 80 | // количество импульсов на оборот примененного механического энкодера 81 | #define ENCODER_PULSE_PER_TURN 20 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /NanoVFO/config_sw.h: -------------------------------------------------------------------------------- 1 | // Конфиг для DragonFly Pro http://dspview.com/viewtopic.php?f=8&t=196 2 | // Одна ПЧ 8MHz, фильтр USB, гетеродины не переключаемые, 3 | // Первый гетеродин выше частоты приема при LSB и ниже при USB 4 | 5 | #ifndef CONFIG_SW_H 6 | #define CONFIG_SW_H 7 | 8 | // В режиме передачи CW на CLK2 формировать сигнал непосредственно с частотой передачи. При этом 9 | // остальные выходы отключены. 10 | // Если закоментарено то формируется сигнал с частотой в пределах полосы пропускания ПЧ 11 | // который должен в тракте смешиваться с сигналом первого гетеродина 12 | //#define CWTX_DIRECT_FREQ 13 | 14 | // Частота 2го гетеродина в детекторе SSB. 15 | // Может быть определена как одна константа для верхнего/нижнего ската так и обе. 16 | // При определении только одной константы изменение боковой полосы производится 1ым гетеродином 17 | // При определении обеих констант они должны находится на соответствующих скатах фидьтра. 18 | //#define SSBDetectorFreq_LSB 7995600L 19 | #define SSBDetectorFreq_USB 7998350L 20 | 21 | // множители частоты на выходах. в случае необходимости получения на выводе 2/4 кратной 22 | // частоты установить в соответствующее значение 23 | const long CLK0_MULT = 1; 24 | const long CLK1_MULT = 1; 25 | const long CLK2_MULT = 1; 26 | 27 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 28 | // необходимо раскоментировать требуемую моду (только одну!) 29 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 30 | 31 | // режим прямого преобразования. частота формируется на 1ом выводе. установить 32 | // CLK0_MULT в значение 1/2/4 в зависимости от коэффициента деления частоты гетеродина 33 | // второй и третий гетеродины отключены 34 | //#define MODE_DC 35 | 36 | // режим прямого преобразования с формированием квадратурн 37 | // частота формируется на выводах CLK0,CLK1 со сдвигом фаз 90град 38 | // CLK2 отключен. Минимальная частота настройки 2MHz (по даташиту 4MHz) может зависеть от экземпляра Si5351 39 | // режим работает только при использовании Si5351 40 | //#define MODE_DC_QUADRATURE 41 | 42 | // одна промежуточная частота. требуемая боковая формируется на счет переключения 43 | // первого гетеродина с инверсией боковой либо без инверсии. второй гетеродин формируется на выходе CLK1 44 | // тип КФ зависит от параметров SSBDetectorFreq_LSB/USB. если фильтр симметричный (определены две частоты SSBDetectorFreq_*) 45 | // то частота первого гетеродина всегда сверху (меньше пораженок) а боковая выбирается изменением частоты второго гетеродина 46 | #define MODE_SINGLE_IF 47 | 48 | // аналогично MODE_SINGLE_IF но второй гетеродин генерируется на CLK1 при RX и 49 | // на CLK2 в режиме TX 50 | //#define MODE_SINGLE_IF_RXTX 51 | 52 | // аналогично MODE_SINGLE_IF но в режиме передачи гетеродины комутируются, 53 | // тоесть первый формируется на CLK1, а второй - на CLK0 54 | // для трактов где необходимо переключение гетеродинов при смене RX/TX (например Радио-76, Аматор) 55 | //#define MODE_SINGLE_IF_SWAP 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /NanoVFO/disp_OLED128x64.cpp: -------------------------------------------------------------------------------- 1 | #include "disp_oled128x64.h" 2 | // SSD1306Ascii library https://github.com/greiman/SSD1306Ascii 3 | #include "SSD1306AsciiAvrI2c.h" 4 | #include "fonts\lcdnums14x24mod.h" 5 | 6 | #define I2C_ADDRESS 0x3C 7 | 8 | SSD1306AsciiAvrI2c oled64; 9 | 10 | void Display_OLED128x64::setBright(uint8_t brightness) 11 | { 12 | if (brightness < 0) brightness = 0; 13 | if (brightness > 15) brightness = 15; 14 | if (brightness == 0) 15 | oled64.ssd1306WriteCmd(SSD1306_DISPLAYOFF); 16 | else { 17 | if (last_brightness == 0) 18 | oled64.ssd1306WriteCmd(SSD1306_DISPLAYON); 19 | oled64.setContrast(brightness << 4); 20 | } 21 | last_brightness = brightness; 22 | } 23 | 24 | void Display_OLED128x64::setup() 25 | { 26 | oled64.begin(&Adafruit128x64, I2C_ADDRESS); 27 | clear(); 28 | last_brightness=0; 29 | } 30 | 31 | void Display_OLED128x64::Draw(TRX& trx) 32 | { 33 | if (trx.Freq != last_freq) { 34 | char buf[10]; 35 | long f = trx.Freq/10; 36 | buf[8] = '0'+f%10; f/=10; 37 | buf[7] = '0'+f%10; f/=10; 38 | buf[6] = '.'; 39 | buf[5] = '0'+f%10; f/=10; 40 | buf[4] = '0'+f%10; f/=10; 41 | buf[3] = '0'+f%10; f/=10; 42 | buf[2] = '.'; 43 | buf[1] = '0'+f%10; f/=10; 44 | if (f > 0) buf[0] = '0'+f; 45 | else buf[0] = ':'; 46 | buf[9] = 0; 47 | oled64.setFont(lcdnums14x24mod); 48 | oled64.setCursor(1, 3); 49 | oled64.print(buf); 50 | last_freq = trx.Freq; 51 | } 52 | 53 | if (trx.BandIndex != last_BandIndex || trx.TX != last_tx || trx.CW != last_cw) { 54 | oled64.setFont(X11fixed7x14); 55 | oled64.setCursor(20,0); 56 | if (trx.TX) oled64.print("TX"); 57 | else oled64.print("RX"); 58 | 59 | int mc = Bands[trx.BandIndex].mc; 60 | oled64.setCursor(128-20-7*4,0); 61 | if (mc < 100) oled64.print(' '); 62 | oled64.print(mc); 63 | oled64.print('m'); 64 | 65 | oled64.setCursor(57,0); 66 | if (trx.CW) oled64.print("CW"); 67 | else oled64.print(" "); 68 | 69 | last_tx = trx.TX; 70 | last_cw = trx.CW; 71 | last_BandIndex = trx.BandIndex; 72 | } 73 | 74 | if (trx.cw_speed != last_wpm) { 75 | oled64.setFont(Adafruit5x7); 76 | 77 | oled64.setCursor(43,7); 78 | if (trx.cw_speed < 10) oled64.print(' '); 79 | oled64.print(trx.cw_speed); 80 | oled64.print(" wpm"); 81 | 82 | last_wpm = trx.cw_speed; 83 | } 84 | } 85 | 86 | void Display_OLED128x64::DrawMenu(int id, char* text, int value, uint8_t edit) 87 | { 88 | oled64.clear(); 89 | oled64.setFont(Adafruit5x7); 90 | oled64.setCursor(10,1); 91 | oled64.print(id); 92 | oled64.print(' '); 93 | oled64.print(text); 94 | if (edit) { 95 | oled64.setCursor(0,3); 96 | oled64.print("EDIT:"); 97 | } 98 | oled64.setCursor(50,3); 99 | oled64.print(value); 100 | oled64.print(" "); 101 | } 102 | 103 | void Display_OLED128x64::clear() 104 | { 105 | oled64.clear(); 106 | last_freq=0; 107 | last_tx=0xFF; 108 | last_BandIndex=0xFF; 109 | last_wpm=0; 110 | last_cw=0xFF; 111 | } 112 | 113 | -------------------------------------------------------------------------------- /NanoVFO/disp_OLED_SH1106_128x64.cpp: -------------------------------------------------------------------------------- 1 | #include "disp_oled_sh1106_128x64.h" 2 | // SSD1306Ascii library https://github.com/greiman/SSD1306Ascii 3 | #include "SSD1306AsciiAvrI2c.h" 4 | #include "fonts\lcdnums14x24mod.h" 5 | 6 | #define I2C_ADDRESS 0x3C 7 | 8 | SSD1306AsciiAvrI2c oled642; 9 | 10 | void Display_OLED_SH1106_128x64::setBright(uint8_t brightness) 11 | { 12 | if (brightness < 0) brightness = 0; 13 | if (brightness > 15) brightness = 15; 14 | if (brightness == 0) 15 | oled642.ssd1306WriteCmd(SSD1306_DISPLAYOFF); 16 | else { 17 | if (last_brightness == 0) 18 | oled642.ssd1306WriteCmd(SSD1306_DISPLAYON); 19 | oled642.setContrast(brightness << 4); 20 | } 21 | last_brightness = brightness; 22 | } 23 | 24 | void Display_OLED_SH1106_128x64::setup() 25 | { 26 | oled642.begin(&SH1106_128x64, I2C_ADDRESS); 27 | clear(); 28 | last_brightness=0; 29 | } 30 | 31 | void Display_OLED_SH1106_128x64::Draw(TRX& trx) 32 | { 33 | if (trx.Freq != last_freq) { 34 | char buf[10]; 35 | long f = trx.Freq/10; 36 | buf[8] = '0'+f%10; f/=10; 37 | buf[7] = '0'+f%10; f/=10; 38 | buf[6] = '.'; 39 | buf[5] = '0'+f%10; f/=10; 40 | buf[4] = '0'+f%10; f/=10; 41 | buf[3] = '0'+f%10; f/=10; 42 | buf[2] = '.'; 43 | buf[1] = '0'+f%10; f/=10; 44 | if (f > 0) buf[0] = '0'+f; 45 | else buf[0] = ':'; 46 | buf[9] = 0; 47 | oled642.setFont(lcdnums14x24mod); 48 | oled642.setCursor(1, 3); 49 | oled642.print(buf); 50 | last_freq = trx.Freq; 51 | } 52 | 53 | if (trx.BandIndex != last_BandIndex || trx.TX != last_tx || trx.CW != last_cw) { 54 | oled642.setFont(X11fixed7x14); 55 | oled642.setCursor(20,0); 56 | if (trx.TX) oled642.print("TX"); 57 | else oled642.print("RX"); 58 | 59 | int mc = Bands[trx.BandIndex].mc; 60 | oled642.setCursor(128-20-7*4,0); 61 | if (mc < 100) oled642.print(' '); 62 | oled642.print(mc); 63 | oled642.print('m'); 64 | 65 | oled642.setCursor(57,0); 66 | if (trx.CW) oled642.print("CW"); 67 | else oled642.print(" "); 68 | 69 | last_tx = trx.TX; 70 | last_cw = trx.CW; 71 | last_BandIndex = trx.BandIndex; 72 | } 73 | 74 | if (trx.cw_speed != last_wpm) { 75 | oled642.setFont(Adafruit5x7); 76 | 77 | oled642.setCursor(43,7); 78 | if (trx.cw_speed < 10) oled642.print(' '); 79 | oled642.print(trx.cw_speed); 80 | oled642.print(" wpm"); 81 | 82 | last_wpm = trx.cw_speed; 83 | } 84 | } 85 | 86 | void Display_OLED_SH1106_128x64::DrawMenu(int id, char* text, int value, uint8_t edit) 87 | { 88 | oled642.clear(); 89 | oled642.setFont(Adafruit5x7); 90 | oled642.setCursor(10,1); 91 | oled642.print(id); 92 | oled642.print(' '); 93 | oled642.print(text); 94 | if (edit) { 95 | oled642.setCursor(0,3); 96 | oled642.print("EDIT:"); 97 | } 98 | oled642.setCursor(50,3); 99 | oled642.print(value); 100 | oled642.print(" "); 101 | } 102 | 103 | void Display_OLED_SH1106_128x64::clear() 104 | { 105 | oled642.clear(); 106 | last_freq=0; 107 | last_tx=0xFF; 108 | last_BandIndex=0xFF; 109 | last_wpm=0; 110 | last_cw=0xFF; 111 | } 112 | 113 | -------------------------------------------------------------------------------- /NanoVFO/fonts/lcdnums12x16mod.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fixed width font for numbers that looks like LCD panel digits 3 | * This font including pad pixels, will render 12x16 pixels on the display 4 | * 5 | * This font is very useful when using overstrike as all characters & numbers 6 | * are all the same width. 7 | * 8 | * This font is not a complete character set. The font only contains 9 | * the characters: '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '9', ':' 10 | * 11 | * This font is nice for certain applications like clocks, signed values or decimal point values. 12 | * 13 | */ 14 | 15 | GLCDFONTDECL(lcdnums12x16mod) = 16 | { 17 | 0x0, 0x0, // size of zero indicates fixed width font 18 | 11, // width (will be 12 with pad pixel on right) 19 | 15, // height (will be 16 with pad pixel on bottom) 20 | '+', // first char 21 | 16, // char count 22 | 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0xe0, 0x80, 0x80, 0x00, 0x00, 23 | 0x00, 0x00, 0x01, 0x03, 0x03, 0x0f, 0x0f, 0x03, 0x03, 0x01, 0x00, // + 24 | 25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, 0x00, // , 27 | 28 | 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 29 | 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, // - 30 | 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, // . 33 | 34 | 0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 35 | 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x81, 0x00, // / 36 | 37 | 0x00, 0xfc, 0x7a, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7a, 0xfc, 38 | 0x00, 0x7e, 0xbc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xbc, 0x7e, // 0 39 | 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xfc, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x7e, // 1 42 | 43 | 0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 44 | 0x00, 0x7e, 0xbd, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0x81, 0x00, // 2 45 | 46 | 0x00, 0x00, 0x02, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 47 | 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, // 3 48 | 49 | 0x00, 0xfc, 0x78, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x78, 0xfc, 50 | 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3d, 0x7e, // 4 51 | 52 | 0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 53 | 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, // 5 54 | 55 | 0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x02, 0x00, 56 | 0x00, 0x7e, 0xbd, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, // 6 57 | 58 | 0x00, 0x00, 0x02, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x7a, 0xfc, 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x7e, // 7 60 | 61 | 0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 62 | 0x00, 0x7e, 0xbd, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, // 8 63 | 64 | 0x00, 0xfc, 0x7a, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x7a, 0xfc, 65 | 0x00, 0x00, 0x81, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xbd, 0x7e, // 9 66 | 67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // : 69 | }; 70 | -------------------------------------------------------------------------------- /NanoVFO/disp_MAX7219.cpp: -------------------------------------------------------------------------------- 1 | #include "disp_MAX7219.h" 2 | 3 | #define DIN_PIN 8 4 | #define CS_PIN 7 5 | #define CLK_PIN 6 6 | 7 | #define DECODEMODE_ADDR 9 8 | #define BRIGHTNESS_ADDR 10 9 | #define SCANLIMIT_ADDR 11 10 | #define SHUTDOWN_ADDR 12 11 | #define DISPLAYTEST_ADDR 15 12 | 13 | uint8_t charTable [] = { 14 | B01111110,B00110000,B01101101,B01111001,B00110011,B01011011,B01011111,B01110000,B01111111,B01111011 15 | }; 16 | 17 | void max7219_write(volatile byte address, volatile byte data) { 18 | digitalWrite(CS_PIN, LOW); 19 | shiftOut(DIN_PIN, CLK_PIN, MSBFIRST, address); 20 | shiftOut(DIN_PIN, CLK_PIN, MSBFIRST, data); 21 | digitalWrite(CS_PIN, HIGH); 22 | digitalWrite(CLK_PIN, LOW); // this pin also used in touch key read. so turn to low after use 23 | } 24 | 25 | void max7219_clear() { 26 | for (int i = 1; i <= 8; i++) { 27 | max7219_write(i, B00000000); 28 | } 29 | } 30 | 31 | void max7219_setDigitLimit(uint8_t limit) { 32 | max7219_write(DISPLAYTEST_ADDR, 0); 33 | max7219_write(SCANLIMIT_ADDR, limit-1); 34 | // 0: Register Format 35 | // 255: Code B Font (0xff) 36 | max7219_write(DECODEMODE_ADDR, 0); 37 | max7219_clear(); 38 | max7219_write(SHUTDOWN_ADDR, 1); 39 | } 40 | 41 | void Display_MAX7219::setBright(uint8_t brightness) 42 | { 43 | if (brightness < 0) brightness = 0; 44 | if (brightness > 15) brightness = 15; 45 | if (brightness == 0) 46 | max7219_write(SHUTDOWN_ADDR, 0x00); 47 | else { 48 | if (last_brightness == 0) 49 | max7219_write(SHUTDOWN_ADDR, 0x01); 50 | max7219_write(BRIGHTNESS_ADDR, brightness); 51 | } 52 | last_brightness = brightness; 53 | } 54 | 55 | void Display_MAX7219::setup() 56 | { 57 | pinMode(DIN_PIN, OUTPUT); 58 | pinMode(CS_PIN, OUTPUT); 59 | pinMode(CLK_PIN, OUTPUT); 60 | digitalWrite(CS_PIN, HIGH); 61 | setBright(7); 62 | max7219_setDigitLimit(8); 63 | clear(); 64 | } 65 | 66 | void Display_MAX7219::Draw(TRX& trx) 67 | { 68 | long freq = trx.Freq; 69 | if (freq != lastfreq || trx.CW != last_cw) { 70 | lastfreq = freq; 71 | last_cw = trx.CW; 72 | for (uint8_t i=1; i <= 8; i++) { 73 | if (freq) { 74 | uint8_t ch = charTable[freq%10]; 75 | if ((i == 1 && trx.CW) || i == 4 || i == 7) ch |= B10000000; 76 | max7219_write(i,ch); 77 | freq /= 10; 78 | } else { 79 | max7219_write(i,0); 80 | } 81 | } 82 | } 83 | } 84 | 85 | void Display_MAX7219::DrawMenu(int id, char* text, int value, uint8_t edit) 86 | { 87 | clear(); 88 | uint8_t ch = charTable[id%10]; 89 | if (edit) ch |= B10000000; 90 | max7219_write(7,ch); 91 | max7219_write(8,charTable[id/10]); 92 | if (value == 0) { 93 | max7219_write(1,charTable[0]); 94 | return; 95 | } 96 | uint8_t sign = 0; 97 | if (value < 0) { 98 | sign = 1; 99 | value = -value; 100 | } 101 | for (uint8_t i=1; i <= 5; i++) { 102 | if (value) { 103 | uint8_t ch = charTable[value%10]; 104 | max7219_write(i,ch); 105 | value /= 10; 106 | } else { 107 | if (sign) max7219_write(i,1); 108 | break; 109 | } 110 | } 111 | } 112 | 113 | void Display_MAX7219::clear() 114 | { 115 | lastfreq = 0; 116 | last_cw = 0xFF; 117 | max7219_clear(); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /NanoVFO/disp_OLED128x32.cpp: -------------------------------------------------------------------------------- 1 | #include "disp_oled128x32.h" 2 | // SSD1306Ascii library https://github.com/greiman/SSD1306Ascii 3 | #include "SSD1306AsciiAvrI2c.h" 4 | #include "fonts\lcdnums12x16mod.h" 5 | 6 | #define I2C_ADDRESS 0x3C 7 | 8 | SSD1306AsciiAvrI2c oled32; 9 | 10 | void Display_OLED128x32::setBright(uint8_t brightness) 11 | { 12 | if (brightness < 0) brightness = 0; 13 | if (brightness > 15) brightness = 15; 14 | if (brightness == 0) 15 | oled32.ssd1306WriteCmd(SSD1306_DISPLAYOFF); 16 | else { 17 | if (last_brightness == 0) 18 | oled32.ssd1306WriteCmd(SSD1306_DISPLAYON); 19 | oled32.setContrast(brightness << 4); 20 | } 21 | last_brightness = brightness; 22 | } 23 | 24 | void Display_OLED128x32::setup() 25 | { 26 | oled32.begin(&Adafruit128x32, I2C_ADDRESS); 27 | clear(); 28 | last_brightness=0; 29 | } 30 | 31 | void Display_OLED128x32::Draw(TRX& trx) 32 | { 33 | if (trx.Freq != last_freq) { 34 | char buf[11]; 35 | long f = trx.Freq; 36 | buf[9] = '0'+f%10; f/=10; 37 | buf[8] = '0'+f%10; f/=10; 38 | buf[7] = '0'+f%10; f/=10; 39 | buf[6] = '.'; 40 | buf[5] = '0'+f%10; f/=10; 41 | buf[4] = '0'+f%10; f/=10; 42 | buf[3] = '0'+f%10; f/=10; 43 | buf[2] = '.'; 44 | buf[1] = '0'+f%10; f/=10; 45 | if (f > 0) buf[0] = '0'+f; 46 | else buf[0] = ':'; 47 | buf[10] = 0; 48 | oled32.setFont(lcdnums12x16mod); 49 | oled32.setCursor(1, 0); 50 | oled32.print(buf); 51 | last_freq = trx.Freq; 52 | } 53 | 54 | if (trx.TX != last_tx) { 55 | oled32.setFont(Adafruit5x7); 56 | oled32.setCursor(7,3); 57 | if (trx.TX) oled32.print("TX"); 58 | else oled32.print("RX"); 59 | last_tx = trx.TX; 60 | } 61 | 62 | if (trx.CW != last_cw) { 63 | oled32.setFont(Adafruit5x7); 64 | oled32.setCursor(27,3); 65 | if (trx.CW) oled32.print("CW"); 66 | else oled32.print(" "); 67 | last_cw = trx.CW; 68 | } 69 | 70 | if (trx.BandIndex != last_BandIndex) { 71 | int mc = Bands[trx.BandIndex].mc; 72 | oled32.setFont(Adafruit5x7); 73 | oled32.setCursor(47,3); 74 | if (mc < 100) oled32.print(' '); 75 | oled32.print(mc); 76 | oled32.print('m'); 77 | last_BandIndex = trx.BandIndex; 78 | } 79 | 80 | if (trx.cw_speed != last_wpm) { 81 | oled32.setFont(Adafruit5x7); 82 | oled32.setCursor(85,3); 83 | if (trx.cw_speed < 10) oled32.print(' '); 84 | oled32.print(trx.cw_speed); 85 | oled32.print(" wpm"); 86 | last_wpm = trx.cw_speed; 87 | } 88 | } 89 | 90 | void Display_OLED128x32::DrawMenu(int id, char* text, int value, uint8_t edit) 91 | { 92 | oled32.clear(); 93 | oled32.setFont(Adafruit5x7); 94 | oled32.setCursor(10,0); 95 | oled32.print(id); 96 | oled32.print(' '); 97 | oled32.print(text); 98 | if (edit) { 99 | oled32.setCursor(0,2); 100 | oled32.print("EDIT:"); 101 | } 102 | oled32.setCursor(50,2); 103 | oled32.print(value); 104 | oled32.print(" "); 105 | } 106 | 107 | void Display_OLED128x32::clear() 108 | { 109 | oled32.clear(); 110 | last_freq=0; 111 | last_tx=0xFF; 112 | last_BandIndex=0xFF; 113 | last_wpm=0; 114 | last_cw=0xFF; 115 | } 116 | -------------------------------------------------------------------------------- /NanoVFO/TRX.cpp: -------------------------------------------------------------------------------- 1 | #include "TRX.h" 2 | #include "config.h" 3 | 4 | const struct _Bands Bands[BAND_COUNT] = { 5 | DEFINED_BANDS 6 | }; 7 | 8 | TRX::TRX() { 9 | for (byte i=0; i < BAND_COUNT; i++) { 10 | if (Bands[i].startSSB != 0) 11 | BandData[i] = Bands[i].startSSB; 12 | else 13 | BandData[i] = Bands[i].start; 14 | } 15 | TX = 0; 16 | CWTX = 0; 17 | SwitchToBand(0); 18 | } 19 | 20 | void TRX::SwitchToBand(int band) { 21 | BandIndex = band; 22 | Freq = BandData[BandIndex]; 23 | sideband = Bands[BandIndex].sideband; 24 | CW = inCW(); 25 | } 26 | 27 | void TRX::ChangeFreq(long freq_delta) 28 | { 29 | if (!TX) { 30 | uint8_t old_cw = inCW(); 31 | Freq += freq_delta; 32 | // проверяем выход за пределы диапазона 33 | if (Freq < Bands[BandIndex].start) 34 | Freq = Bands[BandIndex].start; 35 | else if (Freq > Bands[BandIndex].end) 36 | Freq = Bands[BandIndex].end; 37 | uint8_t new_cw = inCW(); 38 | if (old_cw != new_cw) CW = new_cw; 39 | } 40 | } 41 | 42 | void TRX::NextBand() 43 | { 44 | if (!TX) { 45 | BandData[BandIndex] = Freq; 46 | if (++BandIndex >= BAND_COUNT) 47 | BandIndex = 0; 48 | Freq = BandData[BandIndex]; 49 | sideband = Bands[BandIndex].sideband; 50 | CW = inCW(); 51 | } 52 | } 53 | 54 | void TRX::PrevBand() 55 | { 56 | if (!TX) { 57 | BandData[BandIndex] = Freq; 58 | if (--BandIndex < 0) 59 | BandIndex = BAND_COUNT-1; 60 | Freq = BandData[BandIndex]; 61 | sideband = Bands[BandIndex].sideband; 62 | CW = inCW(); 63 | } 64 | } 65 | 66 | uint8_t TRX::inCW() { 67 | return 68 | BandIndex >= 0 && Bands[BandIndex].startSSB > 0 && 69 | Freq < Bands[BandIndex].startSSB && 70 | Freq >= Bands[BandIndex].start; 71 | } 72 | 73 | uint8_t TRX::setCWSpeed(uint8_t speed, int dash_ratio) 74 | { 75 | if (speed != cw_speed) { 76 | cw_speed = speed; 77 | dit_time = 1200/cw_speed; 78 | dah_time = dit_time*dash_ratio/10; 79 | return 1; 80 | } 81 | return 0; 82 | } 83 | 84 | struct TRXState { 85 | long BandData[BAND_COUNT+1]; 86 | int BandIndex; 87 | long Freq; 88 | }; 89 | 90 | uint16_t hash_data(uint16_t hval, uint8_t* data, int sz) 91 | { 92 | while (sz--) { 93 | hval ^= *data++; 94 | hval = (hval << 11) | (hval >> 5); 95 | } 96 | return hval; 97 | } 98 | 99 | uint16_t TRX::StateHash() 100 | { 101 | uint16_t hash = 0x5AC3; 102 | hash = hash_data(hash,(uint8_t*)BandData,sizeof(BandData)); 103 | hash = hash_data(hash,(uint8_t*)&BandIndex,sizeof(BandIndex)); 104 | hash = hash_data(hash,(uint8_t*)&Freq,sizeof(Freq)); 105 | return hash; 106 | } 107 | 108 | struct TRXState EEMEM eeState; 109 | uint16_t EEMEM eeStateVer; 110 | #define STATE_VER 0x5F17 111 | 112 | void TRX::StateSave() 113 | { 114 | struct TRXState st; 115 | for (byte i=0; i <= BAND_COUNT+1; i++) 116 | st.BandData[i] = BandData[i]; 117 | st.BandIndex = BandIndex; 118 | st.Freq = Freq; 119 | eeprom_write_block(&st, &eeState, sizeof(st)); 120 | eeprom_write_word(&eeStateVer, STATE_VER); 121 | } 122 | 123 | void TRX::StateLoad() 124 | { 125 | struct TRXState st; 126 | uint16_t ver; 127 | ver = eeprom_read_word(&eeStateVer); 128 | if (ver == STATE_VER) { 129 | eeprom_read_block(&st, &eeState, sizeof(st)); 130 | for (byte i=0; i <= BAND_COUNT+1; i++) 131 | BandData[i] = st.BandData[i]; 132 | SwitchToBand(st.BandIndex); 133 | Freq = st.Freq; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /NanoVFO/Encoder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Encoder.h" 3 | #include "config_hw.h" 4 | 5 | /* 6 | подключение энкодера PIN 2,3 7 | */ 8 | 9 | #ifdef ENCODER_OPTICAL 10 | 11 | #define ENC_LO_STEP (ENCODER_FREQ_LO_STEP/ENCODER_PULSE_PER_TURN) 12 | #define ENC_HI_STEP (ENCODER_FREQ_HI_STEP/ENCODER_PULSE_PER_TURN) 13 | 14 | volatile long Encoder_Value = 0; 15 | volatile uint8_t enc_last = 0; 16 | volatile long enc_last_tm = 0; 17 | volatile long enc_sum = 0; 18 | volatile uint8_t hi_mode = 0; 19 | 20 | void Encoder::SetValue(long Value) 21 | { 22 | cli(); 23 | Encoder_Value = Value; 24 | sei(); 25 | } 26 | 27 | long Encoder::GetDelta() 28 | { 29 | long val; 30 | cli(); 31 | val = Encoder_Value; 32 | Encoder_Value = 0; 33 | sei(); 34 | return val; 35 | } 36 | 37 | void EncoderHandler() 38 | { 39 | cli(); //stop interrupts happening before we read pin values 40 | byte state = (PIND & 0xC) | enc_last; 41 | int delta; 42 | enc_last = state >> 2; 43 | switch(state){ 44 | case 0b0100: 45 | delta = (hi_mode ? ENC_HI_STEP : ENC_LO_STEP); 46 | break; 47 | case 0b1110: 48 | delta = (hi_mode ? -ENC_HI_STEP : -ENC_LO_STEP); 49 | break; 50 | default: 51 | delta = 0; 52 | } 53 | Encoder_Value += delta; 54 | enc_sum += delta; 55 | if (millis()-enc_last_tm > 250) { 56 | if (enc_sum < 0) enc_sum = -enc_sum; 57 | hi_mode = enc_sum > ENCODER_FREQ_HI_LO_TRASH/4; // measured in 250msec 58 | enc_sum = 0; 59 | enc_last_tm = millis(); 60 | } 61 | sei(); //restart interrupts 62 | } 63 | 64 | void Encoder::Setup() { 65 | cli(); 66 | pinMode(2, INPUT_PULLUP); // set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases) 67 | pinMode(3, INPUT_PULLUP); // set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases) 68 | attachInterrupt(0,EncoderHandler,CHANGE); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below) 69 | attachInterrupt(1,EncoderHandler,CHANGE); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below) 70 | sei(); 71 | } 72 | 73 | #else 74 | 75 | #define ENC_LO_STEP (ENCODER_FREQ_LO_STEP/ENCODER_PULSE_PER_TURN/4) 76 | #define ENC_HI_STEP (ENCODER_FREQ_HI_STEP/ENCODER_PULSE_PER_TURN/4) 77 | 78 | long Encoder_Value = 0; 79 | uint8_t enc_last = 0; 80 | long enc_last_tm = 0; 81 | long enc_sum = 0; 82 | uint8_t hi_mode = 0; 83 | 84 | void Encoder::SetValue(long Value) 85 | { 86 | Encoder_Value = Value; 87 | } 88 | 89 | long Encoder::GetDelta() 90 | { 91 | // обрабатываем все возможные состояния для увеличения кол-ва импульсов на оборот до 4х 92 | byte state = (PIND & 0xC) | enc_last; 93 | enc_last = state >> 2; 94 | switch(state){ 95 | case 0b0100: 96 | case 0b1101: 97 | case 0b1011: 98 | case 0b0010: 99 | Encoder_Value -= (hi_mode ? ENC_HI_STEP : ENC_LO_STEP); 100 | break; 101 | case 0b1000: 102 | case 0b1110: 103 | case 0b0111: 104 | case 0b0001: 105 | Encoder_Value += (hi_mode ? ENC_HI_STEP : ENC_LO_STEP); 106 | break; 107 | } 108 | long val; 109 | val = Encoder_Value; 110 | Encoder_Value = 0; 111 | enc_sum += val; 112 | if (millis()-enc_last_tm > 250) { 113 | if (enc_sum < 0) enc_sum = -enc_sum; 114 | hi_mode = enc_sum > ENCODER_FREQ_HI_LO_TRASH/4; // measured in 250msec 115 | enc_sum = 0; 116 | enc_last_tm = millis(); 117 | } 118 | return val; 119 | } 120 | 121 | void Encoder::Setup() { 122 | pinMode(2, INPUT_PULLUP); 123 | pinMode(3, INPUT_PULLUP); 124 | } 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /NanoVFO/LCD1602_I2C.h: -------------------------------------------------------------------------------- 1 | //YWROBOT 2 | #ifndef LCD1602_I2C_H 3 | #define LCD1602_I2C_H 4 | 5 | #include 6 | #include "Print.h" 7 | 8 | // commands 9 | #define LCD_CLEARDISPLAY 0x01 10 | #define LCD_RETURNHOME 0x02 11 | #define LCD_ENTRYMODESET 0x04 12 | #define LCD_DISPLAYCONTROL 0x08 13 | #define LCD_CURSORSHIFT 0x10 14 | #define LCD_FUNCTIONSET 0x20 15 | #define LCD_SETCGRAMADDR 0x40 16 | #define LCD_SETDDRAMADDR 0x80 17 | 18 | // flags for display entry mode 19 | #define LCD_ENTRYRIGHT 0x00 20 | #define LCD_ENTRYLEFT 0x02 21 | #define LCD_ENTRYSHIFTINCREMENT 0x01 22 | #define LCD_ENTRYSHIFTDECREMENT 0x00 23 | 24 | // flags for display on/off control 25 | #define LCD_DISPLAYON 0x04 26 | #define LCD_DISPLAYOFF 0x00 27 | #define LCD_CURSORON 0x02 28 | #define LCD_CURSOROFF 0x00 29 | #define LCD_BLINKON 0x01 30 | #define LCD_BLINKOFF 0x00 31 | 32 | // flags for display/cursor shift 33 | #define LCD_DISPLAYMOVE 0x08 34 | #define LCD_CURSORMOVE 0x00 35 | #define LCD_MOVERIGHT 0x04 36 | #define LCD_MOVELEFT 0x00 37 | 38 | // flags for function set 39 | #define LCD_8BITMODE 0x10 40 | #define LCD_4BITMODE 0x00 41 | #define LCD_2LINE 0x08 42 | #define LCD_1LINE 0x00 43 | #define LCD_5x10DOTS 0x04 44 | #define LCD_5x8DOTS 0x00 45 | 46 | // flags for backlight control 47 | #define LCD_BACKLIGHT 0x08 48 | #define LCD_NOBACKLIGHT 0x00 49 | 50 | #define En B00000100 // Enable bit 51 | #define Rw B00000010 // Read/Write bit 52 | #define Rs B00000001 // Register select bit 53 | 54 | class LiquidCrystal_I2C : public Print { 55 | public: 56 | LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows); 57 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS ); 58 | void clear(); 59 | void home(); 60 | void noDisplay(); 61 | void display(); 62 | void noBlink(); 63 | void blink(); 64 | void noCursor(); 65 | void cursor(); 66 | void scrollDisplayLeft(); 67 | void scrollDisplayRight(); 68 | void printLeft(); 69 | void printRight(); 70 | void leftToRight(); 71 | void rightToLeft(); 72 | void shiftIncrement(); 73 | void shiftDecrement(); 74 | void noBacklight(); 75 | void backlight(); 76 | void autoscroll(); 77 | void noAutoscroll(); 78 | void createChar(uint8_t, uint8_t[]); 79 | void setCursor(uint8_t, uint8_t); 80 | #if defined(ARDUINO) && ARDUINO >= 100 81 | virtual size_t write(uint8_t); 82 | #else 83 | virtual void write(uint8_t); 84 | #endif 85 | void command(uint8_t); 86 | void init(); 87 | 88 | ////compatibility API function aliases 89 | void blink_on(); // alias for blink() 90 | void blink_off(); // alias for noBlink() 91 | void cursor_on(); // alias for cursor() 92 | void cursor_off(); // alias for noCursor() 93 | void setBacklight(uint8_t new_val); // alias for backlight() and nobacklight() 94 | void load_custom_character(uint8_t char_num, uint8_t *rows); // alias for createChar() 95 | void printstr(const char[]); 96 | 97 | ////Unsupported API functions (not implemented in this library) 98 | uint8_t status(); 99 | void setContrast(uint8_t new_val); 100 | uint8_t keypad(); 101 | void setDelay(int,int); 102 | void on(); 103 | void off(); 104 | uint8_t init_bargraph(uint8_t graphtype); 105 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end); 106 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end); 107 | 108 | 109 | private: 110 | void init_priv(); 111 | void send(uint8_t, uint8_t); 112 | void write4bits(uint8_t); 113 | void expanderWrite(uint8_t); 114 | void pulseEnable(uint8_t); 115 | uint8_t _Addr; 116 | uint8_t _displayfunction; 117 | uint8_t _displaycontrol; 118 | uint8_t _displaymode; 119 | uint8_t _numlines; 120 | uint8_t _cols; 121 | uint8_t _rows; 122 | uint8_t _backlightval; 123 | }; 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /NanoVFO/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | 4 | #define LSB 0 5 | #define USB 1 6 | 7 | // число диапазонов 8 | #define BAND_COUNT 3 9 | 10 | extern const struct _Bands { 11 | uint8_t mc; 12 | long start, startSSB, end; 13 | uint8_t sideband; 14 | } Bands[]; 15 | 16 | #define DEFINED_BANDS \ 17 | {80, 3500000L, 3600000L, 3800000L, LSB}, \ 18 | {40, 7000000L, 7045000L, 7200000L, LSB}, \ 19 | {20, 14000000L, 14100000L, 14350000L, USB} 20 | 21 | /* описание стандартных любительских диапазонов 22 | * скопировать требуемые в DEFINED_BANDS 23 | * и изменить константу BAND_COUNT 24 | {160, 1810000L, 1840000L, 2000000L, LSB}, \ 25 | {80, 3500000L, 3600000L, 3800000L, LSB}, \ 26 | {40, 7000000L, 7045000L, 7200000L, LSB}, \ 27 | {30, 10100000L, 0, 10150000L, USB}, \ 28 | {20, 14000000L, 14100000L, 14350000L, USB}, \ 29 | {17, 18068000L, 18110000L, 18168000L, USB}, \ 30 | {15, 21000000L, 21150000L, 21450000L, USB}, \ 31 | {12, 24890000L, 24930000L, 25140000L, USB}, \ 32 | {10, 28000000L, 28200000L, 29700000L, USB} 33 | */ 34 | 35 | struct _Settings { 36 | int id; 37 | int def_value; 38 | int min_value; 39 | int max_value; 40 | int step; 41 | char* title; 42 | }; 43 | 44 | #define SETTINGS_COUNT 17 45 | 46 | #define SETTINGS_DATA \ 47 | {10, 8, 0, 60, 1, "PWR DWN DELAY"}, /* через сколько времени переходить в режим сохранения питания, сек*/ \ 48 | {11, 7, 1, 15, 1, "BRIGHT HIGH"}, /* яркость LCD - 0..15 в обычнойм режиме и powerdown (0 - погашен) */ \ 49 | {12, 1, 0, 15, 1, "BRIGHT LOW"}, /* 0 - постоянно включен */ \ 50 | \ 51 | {20, 700, 300, 2000, 10, "CW TONE"}, /* частота самоконтроля и сдвиг частоты на CLK2 для формирования CW-сигнала */ \ 52 | {21, 0, 0, 1, 1, "IAMBIC"}, /* switch between iambic and auto mode of cw keyer */ \ 53 | {22, 6, 2, 30, 1, "TOUCH THRESHOLD"}, /* задержка в мкс при опросе сенсора ключа */ \ 54 | {23, 6, 1, 20, 1, "CW SPEED MIN"}, /* min/max cw speed in WPM */ \ 55 | {24, 25, 5, 35, 1, "CW SPEED MAX"}, \ 56 | {25, 30, 20, 40, 1, "DASH-DOT RATIO"}, /* length of dash (in dots) *10 */ \ 57 | {26, 30, 20, 60, 1, "LETTER SPACE"}, /* length of space between letters (in dots) *10 */ \ 58 | {27, 70, 30, 120, 1, "WORD SPACE"}, /* length of space between words (in dots) *10 */ \ 59 | \ 60 | {30, 1, 0, 1, 1, "CW VOX"}, /* auto turn into TX on keyer press (on if in CW mode). if undef you need external PTT */ \ 61 | {31, 800, 100, 2000, 10, "BREAK IN DELAY"}, /* break-in hang time (mS) in CW VOX mode. turn off TX if keyer not pressed more than BREAK_IN_DELAY time */ \ 62 | \ 63 | {41, 0, -10000, 10000, 10, "LSB SHIFT"}, /* доп.сдвиг второго гетеродина относительно констант SSBDetectorFreq_LSB/SSBDetectorFreq_USB */ \ 64 | {42, 0, -10000, 10000, 10, "USB SHIFT"}, \ 65 | {99, 0, -20000, 20000, 5, "SI5351 XTAL"}, \ 66 | {0, 0, 0, 0, 0, "FULL RESET"} 67 | 68 | // increase for reset stored to EEPROM settings values to default 69 | #define SETTINGS_VERSION 0x02 70 | 71 | // id for fast settings access 72 | enum { 73 | ID_POWER_DOWN_DELAY = 0, 74 | ID_DISPLAY_BRIGHT_HIGH, 75 | ID_DISPLAY_BRIGHT_LOW, 76 | ID_CW_TONE_HZ, 77 | ID_CW_IAMBIC, 78 | ID_CW_TOUCH_THRESHOLD, 79 | ID_CW_SPEED_MIN, 80 | ID_CW_SPEED_MAX, 81 | ID_CW_DASH_LEN, 82 | ID_CW_LETTER_SPACE, 83 | ID_CW_WORD_SPACE, 84 | ID_CW_VOX, 85 | ID_BREAK_IN_DELAY, 86 | ID_LSB_SHIFT, 87 | ID_USB_SHIFT, 88 | ID_SI5351_XTAL 89 | }; 90 | 91 | #define MEMO1 "CQ CQ CQ DE UR5FFR UR5FFR UR5FFR K" 92 | #define MEMO2 "CQ CQ CQ DE UR5FFR/P UR5FFR/P UR5FFR/P K" 93 | #define MEMO3 "TNX FER CALL = UR RST 599 599 = NAME IS ANDREY ANDREY QTH ODESSA ODESSA = HW?" 94 | 95 | // конфиг "железа" 96 | #include "config_hw.h" 97 | 98 | // настройки генерируемых частот 99 | #include "config_sw.h" 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /NanoVFO/disp_1602.cpp: -------------------------------------------------------------------------------- 1 | #include "disp_1602.h" 2 | 3 | byte chInverseT[8] = { 0b11111, 0b11111, 0b11111, 0b10001, 0b11011, 0b11011, 0b11111, 0b11111}; 4 | byte chInverseX[8] = { 0b11111, 0b11111, 0b11111, 0b10101, 0b11011, 0b10101, 0b11111, 0b11111}; 5 | byte chLock[8] = { 0b00000, 0b01110, 0b10001, 0b11111, 0b10101, 0b10001, 0b11111, 0b00000}; 6 | byte chCW[8] = { 0b01100, 0b10000, 0b10000, 0b01100, 0b00000, 0b10001, 0b10101, 0b01010}; 7 | 8 | void Display_1602_I2C::setup() { 9 | lcd.init(); 10 | lcd.backlight();// Включаем подсветку дисплея 11 | lcd.createChar(1, chInverseT); 12 | lcd.createChar(2, chInverseX); 13 | lcd.createChar(3, chCW); 14 | lcd.createChar(4, chLock); 15 | clear(); 16 | } 17 | 18 | void Display_1602_I2C::Draw(TRX& trx) { 19 | char buf[17]; 20 | 21 | if (trx.TX != last_tx || trx.BandIndex != last_BandIndex || trx.cw_speed != last_wpm) { 22 | memset(buf,' ',17); 23 | if (trx.TX) { 24 | buf[0] = (char)1; 25 | buf[1] = (char)2; 26 | } else { 27 | buf[0] = 'R'; 28 | buf[1] = 'X'; 29 | } 30 | 31 | int mc = Bands[trx.BandIndex].mc; 32 | if (mc > 99) { 33 | buf[5] = '0'+mc%10; mc/=10; 34 | buf[4] = '0'+mc%10; mc/=10; 35 | buf[3] = '0'+mc; 36 | } else { 37 | buf[5] = '0'+mc%10; mc/=10; 38 | buf[4] = '0'+mc; 39 | } 40 | buf[6] = 'm'; 41 | 42 | uint8_t wpm = trx.cw_speed; 43 | if (wpm > 9) { 44 | buf[10] = '0'+wpm%10; wpm/=10; 45 | buf[9] = '0'+wpm; 46 | } else { 47 | buf[10] = '0'+wpm; 48 | } 49 | buf[12] = 'W'; 50 | buf[13] = 'P'; 51 | buf[14] = 'M'; 52 | 53 | buf[16] = 0; // stop for .print 54 | lcd.setCursor(0, 0); 55 | lcd.print(buf); 56 | 57 | last_tx = trx.TX; 58 | last_BandIndex = trx.BandIndex; 59 | last_wpm = trx.cw_speed; 60 | } 61 | 62 | if (trx.CW != last_cw || trx.Freq != last_freq) { 63 | memset(buf,' ',17); 64 | if (trx.CW) { 65 | buf[0] = 'C'; 66 | buf[1] = 'W'; 67 | } 68 | 69 | long f = trx.Freq; 70 | buf[15] = '0'+f%10; f/=10; 71 | buf[14] = '0'+f%10; f/=10; 72 | buf[13] = '0'+f%10; f/=10; 73 | buf[12] = '.'; 74 | buf[11] = '0'+f%10; f/=10; 75 | buf[10] = '0'+f%10; f/=10; 76 | buf[9] = '0'+f%10; f/=10; 77 | buf[8] = '.'; 78 | buf[7] = '0'+f%10; f/=10; 79 | if (f > 0) buf[6] = '0'+f; 80 | 81 | buf[16] = 0; // stop for .print 82 | lcd.setCursor(0, 1); 83 | lcd.print(buf); 84 | 85 | last_cw = trx.CW; 86 | last_freq = trx.Freq; 87 | } 88 | } 89 | 90 | void Display_1602_I2C::setBright(uint8_t brightness) 91 | { 92 | lcd.setBacklight(brightness); 93 | } 94 | 95 | void Display_1602_I2C::DrawMenu(int id, char* text, int value, uint8_t edit) 96 | { 97 | char buf[17],*p; 98 | memset(buf,' ',17); 99 | buf[0] = '0'+id/10; 100 | buf[1] = '0'+id%10; 101 | for (uint8_t j=3; j <= 15 && *text; j++) 102 | buf[j] = *text++; 103 | buf[16] = 0; // stop for .print 104 | lcd.setCursor(0, 0); 105 | lcd.print(buf); 106 | memset(buf,' ',17); 107 | if (edit) { 108 | buf[0] = 'E'; 109 | buf[1] = 'D'; 110 | buf[2] = 'I'; 111 | buf[3] = 'T'; 112 | buf[4] = ':'; 113 | } 114 | p = &buf[6]; 115 | if (value < 0) { 116 | *p++ = '-'; 117 | value = -value; 118 | } 119 | if (value > 9999) { 120 | *p++ = '0'+value/10000; 121 | value %= 10000; 122 | } 123 | if (value > 999) { 124 | *p++ = '0'+value/1000; 125 | value %= 1000; 126 | } 127 | if (value > 99) { 128 | *p++ = '0'+value/100; 129 | value %= 100; 130 | } 131 | if (value > 9) { 132 | *p++ = '0'+value/10; 133 | value %= 10; 134 | } 135 | *p++ = '0'+value; 136 | lcd.setCursor(0, 1); 137 | lcd.print(buf); 138 | } 139 | 140 | void Display_1602_I2C::clear() 141 | { 142 | last_tx=0xFF; 143 | last_BandIndex=0xFF; 144 | last_wpm=0xFF; 145 | last_cw=0xFF; 146 | last_freq=0xFF; 147 | } 148 | 149 | -------------------------------------------------------------------------------- /NanoVFO/fonts/lcdnums14x24mod.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fixed width font for numbers that looks like LCD panel digits 3 | * This font including pad pixels, will render 14x24 pixels on the display 4 | * 5 | * This font is very useful when using overstrike as all characters & numbers 6 | * are all the same width. 7 | * 8 | * This font is not a complete character set. The font only contains 9 | * the characters: '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '9', ':' 10 | * 11 | * This font is nice for certain applications like clocks, signed values or decimal point values. 12 | * 13 | */ 14 | 15 | 16 | GLCDFONTDECL(lcdnums14x24mod) = 17 | { 18 | 0x0, 0x0, // size of zero indicates fixed width font 19 | 13, // width (will be 14 with pad pixel on right) 20 | 23, // height (will be 24 with pad pixel on bottom) 21 | '+', // first char 22 | 16, // char count 23 | 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0xff, 0xff, 0x38, 0x38, 0x38, 0x10, 0x00, 26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // + 27 | 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x78, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, // , 31 | 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 | 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x10, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // - 35 | 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xe0, 0xe0, 0x40, 0x00, 0x00, 0x00, 0x00, // . 39 | 40 | 0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x06, 0x02, 0x00, 41 | 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x10, 0x00, 42 | 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x00, // / 43 | 44 | 0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 45 | 0x00, 0xef, 0xc7, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc7, 0xef, 46 | 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, // 0 47 | 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf8, 0xfc, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc7, 0xef, 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x3f, 0x7f, // 1 51 | 52 | 0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 53 | 0x00, 0xe0, 0xd0, 0xb8, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x3b, 0x17, 0x0f, 54 | 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x00, // 2 55 | 56 | 0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 57 | 0x00, 0x00, 0x10, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 58 | 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, // 3 59 | 60 | 0x00, 0xfc, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf8, 0xfc, 61 | 0x00, 0x0f, 0x17, 0x3b, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x3f, 0x7f, // 4 63 | 64 | 0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x06, 0x02, 0x00, 65 | 0x00, 0x0f, 0x17, 0x3b, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xb8, 0xd0, 0xe0, 66 | 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, // 5 67 | 68 | 0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x06, 0x02, 0x00, 69 | 0x00, 0xef, 0xd7, 0xbb, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xb8, 0xd0, 0xe0, 70 | 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, // 6 71 | 72 | 0x00, 0x00, 0x02, 0x06, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 73 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0xc7, 0xef, 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x3f, 0x7f, // 7 75 | 76 | 0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 77 | 0x00, 0xef, 0xd7, 0xbb, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 78 | 0x00, 0x7f, 0xbf, 0xdf, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, // 8 79 | 80 | 0x00, 0xfc, 0xfa, 0xf6, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0x0e, 0xf6, 0xfa, 0xfc, 81 | 0x00, 0x0f, 0x17, 0x3b, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0xbb, 0xd7, 0xef, 82 | 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xdf, 0xbf, 0x7f, // 9 83 | 84 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // : 86 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 87 | }; 88 | -------------------------------------------------------------------------------- /NanoVFO/pins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pins.h" 3 | 4 | uint8_t InputPullUpPin::Read() { 5 | if (pin == PIN_NC) return false; 6 | if (millis()-last_tm < 50) return last; 7 | uint8_t val = digitalRead(pin) == LOW; 8 | if (val != last) { 9 | last = val; 10 | last_tm = millis(); 11 | } 12 | return val; 13 | } 14 | 15 | void InputPullUpPin::setup() { 16 | if (pin != PIN_NC) 17 | pinMode(pin, INPUT_PULLUP); 18 | } 19 | 20 | void InputAnalogKeypad::setup() 21 | { 22 | if (pin != PIN_NC) 23 | pinMode(pin, INPUT); 24 | } 25 | 26 | uint8_t InputAnalogKeypad::Read() 27 | { 28 | if (pin == PIN_NC) return 0; 29 | if ((millis()-last_tm) < 50) return last; 30 | uint16_t aval = 1024; 31 | for (byte i=5; i > 0; i--) { 32 | uint16_t v = analogRead(pin); 33 | if (v < aval) aval = v; 34 | } 35 | uint8_t val=0; 36 | while (aval > levels[val] && val < btn_cnt) val++; 37 | val++; 38 | if (val > btn_cnt) val = 0; 39 | if (val != last) { 40 | last = val; 41 | last_tm = millis(); 42 | } 43 | return val; 44 | } 45 | 46 | void InputAnalogKeypad::waitUnpress() 47 | { 48 | while (Read() != 0) delay(1); 49 | delay(50); 50 | } 51 | 52 | void InputAnalogPin::setup() { 53 | if (pin != PIN_NC) 54 | pinMode(pin, INPUT); 55 | } 56 | 57 | // read internal 1.1 source 58 | int ReadV11Ref() 59 | { 60 | int acc = 0; 61 | 62 | analogReference(DEFAULT); 63 | // Read 1.1V reference against AVcc 64 | // set the reference to Vcc and the measurement to the internal 1.1V reference 65 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 66 | 67 | delay(1); // otherwise unstable 68 | for (byte i=0; i < 3; i++) { 69 | ADCSRA |= _BV(ADSC); // Start conversion 70 | while (bit_is_set(ADCSRA,ADSC)); // measuring 71 | uint8_t low = ADCL; // must read ADCL first - it then locks ADCH 72 | uint8_t high = ADCH; // unlocks both 73 | acc += (high<<8) | low; 74 | } 75 | return acc/3; 76 | delay(1); 77 | } 78 | 79 | int InputAnalogPin::Read() 80 | { 81 | int vref = ReadV11Ref(); 82 | int new_value = 0; 83 | analogReference(DEFAULT); 84 | new_value += analogRead(pin); 85 | new_value += analogRead(pin); 86 | new_value += analogRead(pin); 87 | new_value = (long)new_value *1100L/vref/3; 88 | if (abs(new_value-value) > rfac) 89 | value=new_value; 90 | return value; 91 | } 92 | 93 | int InputAnalogPin::ReadRaw() 94 | { 95 | int new_value = 0; 96 | analogReference(DEFAULT); 97 | new_value += analogRead(pin); 98 | new_value += analogRead(pin); 99 | new_value += analogRead(pin); 100 | new_value = new_value/3; 101 | if (abs(new_value-value) > rfac) 102 | value=new_value; 103 | return value; 104 | } 105 | 106 | void OutputBinPin::setup() 107 | { 108 | if (pin != PIN_NC) { 109 | pinMode(pin, OUTPUT); 110 | Write(def_value); 111 | } 112 | } 113 | 114 | void OutputBinPin::Write(uint8_t value) 115 | { 116 | if (pin != PIN_NC && state != value) { 117 | digitalWrite(pin,value?(active_level == HIGH?HIGH:LOW):(active_level == HIGH?LOW:HIGH)); 118 | state = value; 119 | } 120 | } 121 | 122 | void OutputPCF8574::setup() 123 | { 124 | pcf8574_write(value); 125 | } 126 | 127 | void OutputPCF8574::Set(uint8_t pin, uint8_t state) 128 | { 129 | if (state) value |= (1 << (pin & 0x7)); 130 | else value &= ~(1 << (pin & 0x7)); 131 | } 132 | 133 | void OutputPCF8574::Write() 134 | { 135 | if (value != old_value) { 136 | pcf8574_write(value); 137 | old_value = value; 138 | } 139 | } 140 | 141 | void OutputPCF8574::pcf8574_write(uint8_t data) 142 | { 143 | i2c_begin_write(i2c_addr); 144 | i2c_write(data); 145 | i2c_end(); 146 | } 147 | 148 | ////////////////////////////////////////////////////////////////////////////////// 149 | 150 | uint8_t OutputTone_state=0; 151 | uint8_t OutputTone_pin=0; 152 | volatile uint8_t OutputTone_toggle=0; 153 | 154 | void OutputTone(uint8_t pin, int value) 155 | { 156 | if (value) { 157 | if (!OutputTone_state) { 158 | int prescalers[] = {1, 8, 32, 64, 128, 256, 1024}; // timer2 159 | uint8_t ipresc=5,mreg; 160 | for (uint8_t i=0; i <= 6; i++) { 161 | long t=F_CPU/((long)prescalers[i]*value*2)-1; 162 | if (t <= 0xFF) { 163 | ipresc=i; 164 | mreg=t; 165 | break; 166 | } 167 | } 168 | if (ipresc > 6) return; 169 | ipresc++; 170 | OutputTone_pin = pin; 171 | // init timer2 2kHz interrup 172 | cli(); 173 | TCCR2A = 0;// set entire TCCR2A register to 0 174 | TCCR2B = 0;// same for TCCR2B 175 | TCNT2 = 0;//initialize counter value to 0 176 | OCR2A = mreg; 177 | // turn on CTC mode 178 | TCCR2A |= (1 << WGM21); 179 | TCCR2B |= ipresc; 180 | // enable timer compare interrupt 181 | TIMSK2 |= (1 << OCIE2A); 182 | sei(); 183 | OutputTone_state = 1; 184 | } 185 | } else { 186 | if (OutputTone_state) { 187 | // disable interrup 188 | cli(); 189 | TIMSK2 = 0; 190 | sei(); 191 | // set pin to zero 192 | OutputTone_state = 0; 193 | } 194 | } 195 | } 196 | 197 | ISR(TIMER2_COMPA_vect) 198 | { 199 | digitalWrite(OutputTone_pin, OutputTone_toggle++ & 1); 200 | } 201 | -------------------------------------------------------------------------------- /NanoVFO/freq_calc.h: -------------------------------------------------------------------------------- 1 | void vfo_set_freq(long f1, long f2, long f3) 2 | { 3 | #ifdef VFO_SI570 4 | #ifdef VFO_SI5351 5 | vfo570.set_freq(f1); 6 | vfo5351.set_freq(f2,f3,0); 7 | #else 8 | // single Si570 9 | if (f1 != 0) vfo570.set_freq(f1); 10 | else vfo570.set_freq(f3); 11 | #endif 12 | #else 13 | #ifdef VFO_SI5351 14 | vfo5351.set_freq(f1,f2,f3); 15 | #endif 16 | #endif 17 | } 18 | 19 | void UpdateFreq() 20 | { 21 | uint8_t cwtx = trx.TX && trx.CWTX; 22 | 23 | #ifdef MODE_DC 24 | vfo_set_freq( 25 | cwtx? 0: CLK0_MULT*trx.Freq, 26 | 0, 27 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 28 | ); 29 | #endif 30 | 31 | #ifdef MODE_DC_QUADRATURE 32 | vfo5351.set_freq_quadrature( 33 | cwtx? 0: trx.Freq, 34 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 35 | ); 36 | #endif 37 | 38 | #ifdef MODE_SINGLE_IF 39 | #if defined(SSBDetectorFreq_USB) && defined(SSBDetectorFreq_LSB) 40 | vfo_set_freq( // инверсия боковой - гетеродин сверху 41 | #ifdef CWTX_DIRECT_FREQ 42 | cwtx? 0: 43 | #endif 44 | CLK0_MULT*(trx.Freq + (trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]))), 45 | cwtx? 0: CLK1_MULT*(trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])), 46 | #ifdef CWTX_DIRECT_FREQ 47 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 48 | #else 49 | cwtx? (trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])+Settings[ID_CW_TONE_HZ]: (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-Settings[ID_CW_TONE_HZ]): 0 50 | #endif 51 | ); 52 | #elif defined(SSBDetectorFreq_USB) 53 | long f = trx.Freq; 54 | if (trx.sideband == LSB) { 55 | f+=(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]); 56 | } else { 57 | f = abs((SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])-f); 58 | } 59 | vfo_set_freq( 60 | #ifdef CWTX_DIRECT_FREQ 61 | cwtx? 0: 62 | #endif 63 | CLK0_MULT*f, 64 | cwtx? 0: CLK1_MULT*(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]), 65 | #ifdef CWTX_DIRECT_FREQ 66 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 67 | #else 68 | cwtx? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])+Settings[ID_CW_TONE_HZ]: 0 69 | #endif 70 | ); 71 | #elif defined(SSBDetectorFreq_LSB) 72 | long f = trx.Freq; 73 | if (trx.sideband == USB) { 74 | f+=(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]); 75 | } else { 76 | f = abs((SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-f); 77 | } 78 | vfo_set_freq( 79 | #ifdef CWTX_DIRECT_FREQ 80 | cwtx? 0: 81 | #endif 82 | CLK0_MULT*f, 83 | cwtx? 0: CLK1_MULT*(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]), 84 | #ifdef CWTX_DIRECT_FREQ 85 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 86 | #else 87 | cwtx? (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-Settings[ID_CW_TONE_HZ]: 0 88 | #endif 89 | ); 90 | #else 91 | #error You must define (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]) or/and (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) 92 | #endif 93 | #endif 94 | 95 | #ifdef MODE_SINGLE_IF_RXTX 96 | #if defined(SSBDetectorFreq_USB) && defined(SSBDetectorFreq_LSB) 97 | long f = CLK1_MULT*(trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])); 98 | vfo_set_freq( // инверсия боковой - гетеродин сверху 99 | #ifdef CWTX_DIRECT_FREQ 100 | cwtx? 0: 101 | #endif 102 | CLK0_MULT*(trx.Freq + (trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]))), 103 | trx.TX ? 0 : f, 104 | #ifdef CWTX_DIRECT_FREQ 105 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 106 | #else 107 | cwtx? (trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])+Settings[ID_CW_TONE_HZ]: (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-Settings[ID_CW_TONE_HZ]): (trx.TX ? f : 0) 108 | #endif 109 | ); 110 | #elif defined(SSBDetectorFreq_USB) 111 | long f = trx.Freq; 112 | if (trx.sideband == LSB) { 113 | f+=(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]); 114 | } else { 115 | f = abs((SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])-f); 116 | } 117 | vfo_set_freq( 118 | #ifdef CWTX_DIRECT_FREQ 119 | cwtx? 0: 120 | #endif 121 | CLK0_MULT*f, 122 | trx.TX ? 0 : CLK1_MULT*(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]), 123 | #ifdef CWTX_DIRECT_FREQ 124 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 125 | #else 126 | cwtx? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])+Settings[ID_CW_TONE_HZ]: (trx.TX ? CLK1_MULT*(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : 0) 127 | #endif 128 | ); 129 | #elif defined(SSBDetectorFreq_LSB) 130 | long f = trx.Freq; 131 | if (trx.sideband == USB) { 132 | f+=(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]); 133 | } else { 134 | f = abs((SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-f); 135 | } 136 | vfo_set_freq( 137 | #ifdef CWTX_DIRECT_FREQ 138 | cwtx? 0: 139 | #endif 140 | CLK0_MULT*f, 141 | trx.TX ? 0 : CLK1_MULT*(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]), 142 | #ifdef CWTX_DIRECT_FREQ 143 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 144 | #else 145 | cwtx? (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-Settings[ID_CW_TONE_HZ]: (trx.TX ? CLK1_MULT*(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]) : 0) 146 | #endif 147 | ); 148 | #else 149 | #error You must define (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]) or/and (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) 150 | #endif 151 | #endif 152 | 153 | #ifdef MODE_SINGLE_IF_SWAP 154 | #if defined(SSBDetectorFreq_USB) && defined(SSBDetectorFreq_LSB) 155 | long vfo = CLK0_MULT*(trx.Freq + (trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]))); 156 | long f = CLK1_MULT*(trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])); 157 | vfo_set_freq( // инверсия боковой - гетеродин сверху 158 | cwtx? 0: (trx.TX ? f : vfo), 159 | #ifdef CWTX_DIRECT_FREQ 160 | cwtx? 0: 161 | #endif 162 | trx.TX ? vfo : f, 163 | #ifdef CWTX_DIRECT_FREQ 164 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 165 | #else 166 | cwtx? (trx.sideband == LSB ? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])+Settings[ID_CW_TONE_HZ]: (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-Settings[ID_CW_TONE_HZ]): 0 167 | #endif 168 | ); 169 | #elif defined(SSBDetectorFreq_USB) 170 | long f = trx.Freq; 171 | if (trx.sideband == LSB) { 172 | f+=(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]); 173 | } else { 174 | f = abs((SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])-f); 175 | } 176 | vfo_set_freq( 177 | cwtx? 0: (trx.TX ? CLK1_MULT*(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) : CLK0_MULT*f), 178 | #ifdef CWTX_DIRECT_FREQ 179 | cwtx? 0: 180 | #endif 181 | trx.TX ? CLK0_MULT*f : CLK1_MULT*(SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]), 182 | #ifdef CWTX_DIRECT_FREQ 183 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 184 | #else 185 | cwtx? (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT])+Settings[ID_CW_TONE_HZ]: 0 186 | #endif 187 | ); 188 | #elif defined(SSBDetectorFreq_LSB) 189 | long f = trx.Freq; 190 | if (trx.sideband == USB) { 191 | f+=(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]); 192 | } else { 193 | f = abs((SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-f); 194 | } 195 | vfo_set_freq( 196 | cwtx? 0: (trx.TX ? CLK1_MULT*(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]) : CLK0_MULT*f), 197 | #ifdef CWTX_DIRECT_FREQ 198 | cwtx? 0: 199 | #endif 200 | trx.TX ? CLK0_MULT*f : CLK1_MULT*(SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]), 201 | #ifdef CWTX_DIRECT_FREQ 202 | cwtx? trx.Freq+(trx.sideband == LSB ? -Settings[ID_CW_TONE_HZ]: Settings[ID_CW_TONE_HZ]): 0 203 | #else 204 | cwtx? (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT])-Settings[ID_CW_TONE_HZ]: 0 205 | #endif 206 | ); 207 | #else 208 | #error You must define (SSBDetectorFreq_LSB+Settings[ID_LSB_SHIFT]) or/and (SSBDetectorFreq_USB+Settings[ID_USB_SHIFT]) 209 | #endif 210 | #endif 211 | } 212 | 213 | -------------------------------------------------------------------------------- /NanoVFO/LCD1602_I2C.cpp: -------------------------------------------------------------------------------- 1 | // Based on the work by DFRobot 2 | 3 | #include "LCD1602_I2C.h" 4 | #include 5 | #include 6 | 7 | #if defined(ARDUINO) && ARDUINO >= 100 8 | #include "Arduino.h" 9 | inline size_t LiquidCrystal_I2C::write(uint8_t value) { 10 | send(value, Rs); 11 | return 1; 12 | } 13 | #else 14 | #include "WProgram.h" 15 | inline void LiquidCrystal_I2C::write(uint8_t value) { 16 | send(value, Rs); 17 | } 18 | #endif 19 | 20 | // When the display powers up, it is configured as follows: 21 | // 22 | // 1. Display clear 23 | // 2. Function set: 24 | // DL = 1; 8-bit interface data 25 | // N = 0; 1-line display 26 | // F = 0; 5x8 dot character font 27 | // 3. Display on/off control: 28 | // D = 0; Display off 29 | // C = 0; Cursor off 30 | // B = 0; Blinking off 31 | // 4. Entry mode set: 32 | // I/D = 1; Increment by 1 33 | // S = 0; No shift 34 | // 35 | // Note, however, that resetting the Arduino doesn't reset the LCD, so we 36 | // can't assume that its in that state when a sketch starts (and the 37 | // LiquidCrystal constructor is called). 38 | 39 | LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows) 40 | { 41 | _Addr = lcd_Addr; 42 | _cols = lcd_cols; 43 | _rows = lcd_rows; 44 | _backlightval = LCD_NOBACKLIGHT; 45 | } 46 | 47 | void LiquidCrystal_I2C::init(){ 48 | init_priv(); 49 | } 50 | 51 | void LiquidCrystal_I2C::init_priv() 52 | { 53 | i2c_init(); 54 | _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; 55 | begin(_cols, _rows); 56 | } 57 | 58 | void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { 59 | if (lines > 1) { 60 | _displayfunction |= LCD_2LINE; 61 | } 62 | _numlines = lines; 63 | 64 | // for some 1 line displays you can select a 10 pixel high font 65 | if ((dotsize != 0) && (lines == 1)) { 66 | _displayfunction |= LCD_5x10DOTS; 67 | } 68 | 69 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! 70 | // according to datasheet, we need at least 40ms after power rises above 2.7V 71 | // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 72 | delay(50); 73 | 74 | // Now we pull both RS and R/W low to begin commands 75 | expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1) 76 | delay(1000); 77 | 78 | //put the LCD into 4 bit mode 79 | // this is according to the hitachi HD44780 datasheet 80 | // figure 24, pg 46 81 | 82 | // we start in 8bit mode, try to set 4 bit mode 83 | write4bits(0x03 << 4); 84 | delayMicroseconds(4500); // wait min 4.1ms 85 | 86 | // second try 87 | write4bits(0x03 << 4); 88 | delayMicroseconds(4500); // wait min 4.1ms 89 | 90 | // third go! 91 | write4bits(0x03 << 4); 92 | delayMicroseconds(150); 93 | 94 | // finally, set to 4-bit interface 95 | write4bits(0x02 << 4); 96 | 97 | 98 | // set # lines, font size, etc. 99 | command(LCD_FUNCTIONSET | _displayfunction); 100 | 101 | // turn the display on with no cursor or blinking default 102 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 103 | display(); 104 | 105 | // clear it off 106 | clear(); 107 | 108 | // Initialize to default text direction (for roman languages) 109 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 110 | 111 | // set the entry mode 112 | command(LCD_ENTRYMODESET | _displaymode); 113 | 114 | home(); 115 | 116 | } 117 | 118 | /********** high level commands, for the user! */ 119 | void LiquidCrystal_I2C::clear(){ 120 | command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero 121 | delayMicroseconds(2000); // this command takes a long time! 122 | } 123 | 124 | void LiquidCrystal_I2C::home(){ 125 | command(LCD_RETURNHOME); // set cursor position to zero 126 | delayMicroseconds(2000); // this command takes a long time! 127 | } 128 | 129 | void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){ 130 | int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; 131 | if ( row > _numlines ) { 132 | row = _numlines-1; // we count rows starting w/0 133 | } 134 | command(LCD_SETDDRAMADDR | (col + row_offsets[row])); 135 | } 136 | 137 | // Turn the display on/off (quickly) 138 | void LiquidCrystal_I2C::noDisplay() { 139 | _displaycontrol &= ~LCD_DISPLAYON; 140 | command(LCD_DISPLAYCONTROL | _displaycontrol); 141 | } 142 | void LiquidCrystal_I2C::display() { 143 | _displaycontrol |= LCD_DISPLAYON; 144 | command(LCD_DISPLAYCONTROL | _displaycontrol); 145 | } 146 | 147 | // Turns the underline cursor on/off 148 | void LiquidCrystal_I2C::noCursor() { 149 | _displaycontrol &= ~LCD_CURSORON; 150 | command(LCD_DISPLAYCONTROL | _displaycontrol); 151 | } 152 | void LiquidCrystal_I2C::cursor() { 153 | _displaycontrol |= LCD_CURSORON; 154 | command(LCD_DISPLAYCONTROL | _displaycontrol); 155 | } 156 | 157 | // Turn on and off the blinking cursor 158 | void LiquidCrystal_I2C::noBlink() { 159 | _displaycontrol &= ~LCD_BLINKON; 160 | command(LCD_DISPLAYCONTROL | _displaycontrol); 161 | } 162 | void LiquidCrystal_I2C::blink() { 163 | _displaycontrol |= LCD_BLINKON; 164 | command(LCD_DISPLAYCONTROL | _displaycontrol); 165 | } 166 | 167 | // These commands scroll the display without changing the RAM 168 | void LiquidCrystal_I2C::scrollDisplayLeft(void) { 169 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 170 | } 171 | void LiquidCrystal_I2C::scrollDisplayRight(void) { 172 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 173 | } 174 | 175 | // This is for text that flows Left to Right 176 | void LiquidCrystal_I2C::leftToRight(void) { 177 | _displaymode |= LCD_ENTRYLEFT; 178 | command(LCD_ENTRYMODESET | _displaymode); 179 | } 180 | 181 | // This is for text that flows Right to Left 182 | void LiquidCrystal_I2C::rightToLeft(void) { 183 | _displaymode &= ~LCD_ENTRYLEFT; 184 | command(LCD_ENTRYMODESET | _displaymode); 185 | } 186 | 187 | // This will 'right justify' text from the cursor 188 | void LiquidCrystal_I2C::autoscroll(void) { 189 | _displaymode |= LCD_ENTRYSHIFTINCREMENT; 190 | command(LCD_ENTRYMODESET | _displaymode); 191 | } 192 | 193 | // This will 'left justify' text from the cursor 194 | void LiquidCrystal_I2C::noAutoscroll(void) { 195 | _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; 196 | command(LCD_ENTRYMODESET | _displaymode); 197 | } 198 | 199 | // Allows us to fill the first 8 CGRAM locations 200 | // with custom characters 201 | void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) { 202 | location &= 0x7; // we only have 8 locations 0-7 203 | command(LCD_SETCGRAMADDR | (location << 3)); 204 | for (int i=0; i<8; i++) { 205 | write(charmap[i]); 206 | } 207 | } 208 | 209 | // Turn the (optional) backlight off/on 210 | void LiquidCrystal_I2C::noBacklight(void) { 211 | _backlightval=LCD_NOBACKLIGHT; 212 | expanderWrite(0); 213 | } 214 | 215 | void LiquidCrystal_I2C::backlight(void) { 216 | _backlightval=LCD_BACKLIGHT; 217 | expanderWrite(0); 218 | } 219 | 220 | 221 | 222 | /*********** mid level commands, for sending data/cmds */ 223 | 224 | inline void LiquidCrystal_I2C::command(uint8_t value) { 225 | send(value, 0); 226 | } 227 | 228 | 229 | /************ low level data pushing commands **********/ 230 | 231 | // write either command or data 232 | void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) { 233 | uint8_t highnib=value&0xf0; 234 | uint8_t lownib=(value<<4)&0xf0; 235 | write4bits((highnib)|mode); 236 | write4bits((lownib)|mode); 237 | } 238 | 239 | void LiquidCrystal_I2C::write4bits(uint8_t value) { 240 | expanderWrite(value); 241 | pulseEnable(value); 242 | } 243 | 244 | void LiquidCrystal_I2C::expanderWrite(uint8_t _data){ 245 | i2c_begin_write(_Addr); 246 | i2c_write((int)(_data) | _backlightval); 247 | i2c_end(); 248 | } 249 | 250 | void LiquidCrystal_I2C::pulseEnable(uint8_t _data){ 251 | expanderWrite(_data | En); // En high 252 | delayMicroseconds(1); // enable pulse must be >450ns 253 | 254 | expanderWrite(_data & ~En); // En low 255 | delayMicroseconds(50); // commands need > 37us to settle 256 | } 257 | 258 | 259 | // Alias functions 260 | 261 | void LiquidCrystal_I2C::cursor_on(){ 262 | cursor(); 263 | } 264 | 265 | void LiquidCrystal_I2C::cursor_off(){ 266 | noCursor(); 267 | } 268 | 269 | void LiquidCrystal_I2C::blink_on(){ 270 | blink(); 271 | } 272 | 273 | void LiquidCrystal_I2C::blink_off(){ 274 | noBlink(); 275 | } 276 | 277 | void LiquidCrystal_I2C::load_custom_character(uint8_t char_num, uint8_t *rows){ 278 | createChar(char_num, rows); 279 | } 280 | 281 | void LiquidCrystal_I2C::setBacklight(uint8_t new_val){ 282 | if(new_val){ 283 | backlight(); // turn backlight on 284 | }else{ 285 | noBacklight(); // turn backlight off 286 | } 287 | } 288 | 289 | void LiquidCrystal_I2C::printstr(const char c[]){ 290 | //This function is not identical to the function used for "real" I2C displays 291 | //it's here so the user sketch doesn't have to be changed 292 | print(c); 293 | } 294 | 295 | 296 | // unsupported API functions 297 | void LiquidCrystal_I2C::off(){} 298 | void LiquidCrystal_I2C::on(){} 299 | void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {} 300 | uint8_t LiquidCrystal_I2C::status(){return 0;} 301 | uint8_t LiquidCrystal_I2C::keypad (){return 0;} 302 | uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;} 303 | void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end){} 304 | void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end){} 305 | void LiquidCrystal_I2C::setContrast(uint8_t new_val){} 306 | 307 | 308 | -------------------------------------------------------------------------------- /NanoVFO/NanoVFO.ino: -------------------------------------------------------------------------------- 1 | // 2 | // UR5FFR Si5351 NanoVFO 3 | // v2.1 from 28.06.2020 4 | // Copyright (c) Andrey Belokon, 2017-2020 Odessa 5 | // https://github.com/andrey-belokon/ 6 | // GNU GPL license 7 | // Special thanks for 8 | // Iambic sensor key http://www.jel.gr/cw-mode/iambic-keyer-with-arduino-in-5-minutes 9 | // vk3hn CW keyer https://github.com/prt459/vk3hn_CW_keyer/blob/master/Basic_CW_Keyer.ino 10 | // 11 | 12 | #include 13 | #include 14 | 15 | // !!! all user setting defined in config.h, config_hw.h and config_sw.h files !!! 16 | #include "config.h" 17 | 18 | #include "pins.h" 19 | #include 20 | #include "TRX.h" 21 | #include "Encoder.h" 22 | 23 | #ifdef VFO_SI5351 24 | #include 25 | #endif 26 | #ifdef VFO_SI570 27 | #include 28 | #endif 29 | 30 | #ifdef DISPLAY_MAX7219 31 | #include "disp_MAX7219.h" 32 | #endif 33 | #ifdef DISPLAY_1602 34 | #include "disp_1602.h" 35 | #endif 36 | #ifdef DISPLAY_OLED128x32 37 | #include "disp_OLED128x32.h" 38 | #endif 39 | #ifdef DISPLAY_OLED128x64 40 | #include "disp_OLED128x64.h" 41 | #endif 42 | #ifdef DISPLAY_OLED_SH1106_128x64 43 | #include "disp_OLED_SH1106_128x64.h" 44 | #endif 45 | 46 | #ifdef VFO_SI5351 47 | Si5351 vfo5351; 48 | #endif 49 | #ifdef VFO_SI570 50 | Si570 vfo570; 51 | #endif 52 | 53 | Encoder encoder; 54 | TRX trx; 55 | 56 | #ifdef DISPLAY_MAX7219 57 | Display_MAX7219 disp; 58 | #endif 59 | #ifdef DISPLAY_1602 60 | Display_1602_I2C disp(I2C_ADR_DISPLAY_1602); 61 | #endif 62 | #ifdef DISPLAY_OLED128x32 63 | Display_OLED128x32 disp; 64 | #endif 65 | #ifdef DISPLAY_OLED128x64 66 | Display_OLED128x64 disp; 67 | #endif 68 | #ifdef DISPLAY_OLED_SH1106_128x64 69 | Display_OLED_SH1106_128x64 disp; 70 | #endif 71 | 72 | InputPullUpPin inPTT(PIN_IN_PTT); 73 | 74 | OutputBinPin outCW(PIN_OUT_CW, !OUT_CW_ACTIVE_LEVEL, OUT_CW_ACTIVE_LEVEL); 75 | OutputBinPin outPTT(PIN_OUT_PTT, !OUT_PTT_ACTIVE_LEVEL, OUT_PTT_ACTIVE_LEVEL); 76 | OutputBinPin outKEY(PIN_OUT_KEY, !OUT_KEY_ACTIVE_LEVEL, OUT_KEY_ACTIVE_LEVEL); 77 | 78 | uint16_t KeyLevels[] = {150,300,450,600,780,900}; 79 | InputAnalogKeypad keypad(PIN_ANALOG_KEYPAD, 6, KeyLevels); 80 | 81 | struct _Settings SettingsDef[SETTINGS_COUNT] = { 82 | SETTINGS_DATA 83 | }; 84 | 85 | uint16_t EEMEM eeSettingsVersion = 0; 86 | int EEMEM eeSettings[SETTINGS_COUNT] = {0}; 87 | 88 | int Settings[SETTINGS_COUNT] = {0}; 89 | 90 | void writeSettings() 91 | { 92 | eeprom_write_block(Settings, eeSettings, sizeof(Settings)); 93 | } 94 | 95 | void resetSettings() 96 | { 97 | for (uint8_t j=0; j < SETTINGS_COUNT; j++) 98 | Settings[j] = SettingsDef[j].def_value; 99 | } 100 | 101 | void readSettings() 102 | { 103 | uint16_t ver; 104 | ver = eeprom_read_word(&eeSettingsVersion); 105 | if (ver == ((SETTINGS_VERSION << 8) | SETTINGS_COUNT)) 106 | eeprom_read_block(Settings, eeSettings, sizeof(Settings)); 107 | else { 108 | // fill with defaults 109 | resetSettings(); 110 | writeSettings(); 111 | ver = (SETTINGS_VERSION << 8) | SETTINGS_COUNT; 112 | eeprom_write_word(&eeSettingsVersion, ver); 113 | } 114 | } 115 | 116 | void setup() 117 | { 118 | // раскоментарить в случае использования ProMini328 с кварцем на 16МГц при питании пониженном до 3.3в 119 | // подробнее http://dspview.com/viewtopic.php?f=24&t=201 120 | // clock_prescale_set(clock_div_2); 121 | 122 | readSettings(); 123 | outCW.setup(); 124 | outPTT.setup(); 125 | outKEY.setup(); 126 | inPTT.setup(); 127 | keypad.setup(); 128 | pinMode(PIN_OUT_BAND0, OUTPUT); 129 | pinMode(PIN_OUT_BAND1, OUTPUT); 130 | pinMode(PIN_OUT_BAND2, OUTPUT); 131 | pinMode(PIN_OUT_BAND3, OUTPUT); 132 | pinMode(PIN_OUT_TONE, OUTPUT); 133 | pinMode(PIN_CW_SPEED_POT, INPUT); 134 | pinMode(PIN_KEY_READ_STROB, OUTPUT); 135 | digitalWrite(PIN_KEY_READ_STROB,LOW); 136 | pinMode(PIN_IN_DIT, INPUT); 137 | pinMode(PIN_IN_DAH, INPUT); 138 | i2c_init(); 139 | #ifdef VFO_SI5351 140 | vfo5351.VCOFreq_Max = 800000000; // для использования "кривых" SI-шек с нестабильной генерацией 141 | // change for required output level 142 | vfo5351.setup( 143 | SI5351_CLK0_DRIVE, 144 | SI5351_CLK1_DRIVE, 145 | SI5351_CLK2_DRIVE 146 | ); 147 | vfo5351.set_xtal_freq((SI5351_CALIBRATION/10000)*10000+Settings[ID_SI5351_XTAL]); 148 | #endif 149 | #ifdef VFO_SI570 150 | vfo570.setup(SI570_CALIBRATION); 151 | #endif 152 | encoder.Setup(); 153 | disp.setup(); 154 | trx.StateLoad(); 155 | analogReference(DEFAULT); 156 | } 157 | 158 | #include "freq_calc.h" 159 | 160 | void UpdateBandCtrl() 161 | { 162 | #ifdef BAND_ACTIVE_LEVEL_HIGH 163 | if (BAND_COUNT <= 4) { 164 | digitalWrite(PIN_OUT_BAND0, trx.BandIndex == 0); 165 | digitalWrite(PIN_OUT_BAND1, trx.BandIndex == 1); 166 | digitalWrite(PIN_OUT_BAND2, trx.BandIndex == 2); 167 | digitalWrite(PIN_OUT_BAND3, trx.BandIndex == 3); 168 | } else { 169 | digitalWrite(PIN_OUT_BAND0, trx.BandIndex & 0x1); 170 | digitalWrite(PIN_OUT_BAND1, trx.BandIndex & 0x2); 171 | digitalWrite(PIN_OUT_BAND2, trx.BandIndex & 0x4); 172 | digitalWrite(PIN_OUT_BAND3, trx.BandIndex & 0x8); 173 | } 174 | #else 175 | if (BAND_COUNT <= 4) { 176 | digitalWrite(PIN_OUT_BAND0, trx.BandIndex != 0); 177 | digitalWrite(PIN_OUT_BAND1, trx.BandIndex != 1); 178 | digitalWrite(PIN_OUT_BAND2, trx.BandIndex != 2); 179 | digitalWrite(PIN_OUT_BAND3, trx.BandIndex != 3); 180 | } else { 181 | digitalWrite(PIN_OUT_BAND0, !(trx.BandIndex & 0x1)); 182 | digitalWrite(PIN_OUT_BAND1, !(trx.BandIndex & 0x2)); 183 | digitalWrite(PIN_OUT_BAND2, !(trx.BandIndex & 0x4)); 184 | digitalWrite(PIN_OUT_BAND3, !(trx.BandIndex & 0x8)); 185 | } 186 | #endif 187 | } 188 | 189 | struct morse_char_t { 190 | char ch[7]; 191 | }; 192 | 193 | morse_char_t MorseCode[] = { 194 | {'A', '.', '-', 0, 0, 0, 0}, 195 | {'B', '-', '.', '.', '.', 0, 0}, 196 | {'C', '-', '.', '-', '.', 0, 0}, 197 | {'D', '-', '.', '.', 0, 0, 0}, 198 | {'E', '.', 0, 0, 0, 0, 0}, 199 | {'F', '.', '.', '-', '.', 0, 0}, 200 | {'G', '-', '-', '.', 0, 0, 0}, 201 | {'H', '.', '.', '.', '.', 0, 0}, 202 | {'I', '.', '.', 0, 0, 0, 0}, 203 | {'J', '.', '-', '-', '-', 0, 0}, 204 | {'K', '-', '.', '-', 0, 0, 0}, 205 | {'L', '.', '-', '.', '.', 0, 0}, 206 | {'M', '-', '-', 0, 0, 0, 0}, 207 | {'N', '-', '.', 0, 0, 0, 0}, 208 | {'O', '-', '-', '-', 0, 0, 0}, 209 | {'P', '.', '-', '-', '.', 0, 0}, 210 | {'Q', '-', '-', '.', '-', 0, 0}, 211 | {'R', '.', '-', '.', 0, 0, 0}, 212 | {'S', '.', '.', '.', 0, 0, 0}, 213 | {'T', '-', 0, 0, 0, 0, 0}, 214 | {'U', '.', '.', '-', 0, 0, 0}, 215 | {'V', '.', '.', '.', '-', 0, 0}, 216 | {'W', '.', '-', '-', 0, 0, 0}, 217 | {'X', '-', '.', '.', '-', 0, 0}, 218 | {'Y', '-', '.', '-', '-', 0, 0}, 219 | {'Z', '-', '-', '.', '.', 0, 0}, 220 | {'0', '-', '-', '-', '-', '-', 0}, 221 | {'1', '.', '-', '-', '-', '-', 0}, 222 | {'2', '.', '.', '-', '-', '-', 0}, 223 | {'3', '.', '.', '.', '-', '-', 0}, 224 | {'4', '.', '.', '.', '.', '-', 0}, 225 | {'5', '.', '.', '.', '.', '.', 0}, 226 | {'6', '-', '.', '.', '.', '.', 0}, 227 | {'7', '-', '-', '.', '.', '.', 0}, 228 | {'8', '-', '-', '-', '.', '.', 0}, 229 | {'9', '-', '-', '-', '-', '.', 0}, 230 | {'/', '-', '.', '.', '-', '.', 0}, 231 | {'?', '.', '.', '-', '-', '.', '.'}, 232 | {'.', '.', '-', '.', '-', '.', '-'}, 233 | {',', '-', '-', '.', '.', '-', '-'}, 234 | {0} 235 | }; 236 | 237 | long last_event = 0; 238 | long last_pool = 0; 239 | uint8_t in_power_save = 0; 240 | uint8_t last_key = 0; 241 | long last_cw = 0; 242 | uint8_t first_call = 1; 243 | 244 | enum {imIDLE,imDIT,imDAH}; 245 | uint8_t im_state = imIDLE; 246 | 247 | void power_save(uint8_t enable) 248 | { 249 | if (enable) { 250 | if (!in_power_save) { 251 | disp.setBright(Settings[ID_DISPLAY_BRIGHT_LOW]); 252 | in_power_save = 1; 253 | } 254 | } else { 255 | if (in_power_save) { 256 | disp.setBright(Settings[ID_DISPLAY_BRIGHT_HIGH]); 257 | in_power_save = 0; 258 | } 259 | last_event = millis(); 260 | } 261 | } 262 | 263 | uint8_t readDit() 264 | { 265 | uint8_t dit; 266 | digitalWrite(PIN_KEY_READ_STROB,HIGH); 267 | delayMicroseconds(Settings[ID_CW_TOUCH_THRESHOLD]); 268 | if(digitalRead(PIN_IN_DIT)) dit=0; else dit=1; 269 | digitalWrite(PIN_KEY_READ_STROB,LOW); 270 | if (dit) Serial.println("dit"); 271 | return dit; 272 | } 273 | 274 | uint8_t readDah() 275 | { 276 | uint8_t dah; 277 | digitalWrite(PIN_KEY_READ_STROB,HIGH); 278 | delayMicroseconds(Settings[ID_CW_TOUCH_THRESHOLD]); 279 | if(digitalRead(PIN_IN_DAH)) dah=0; else dah=1; 280 | digitalWrite(PIN_KEY_READ_STROB,LOW); 281 | if (dah) Serial.println("dah"); 282 | return dah; 283 | } 284 | 285 | void sendDit() 286 | { 287 | outKEY.Write(1); 288 | OutputTone(PIN_OUT_TONE,Settings[ID_CW_TONE_HZ]); 289 | delay(trx.dit_time); 290 | outKEY.Write(0); 291 | OutputTone(PIN_OUT_TONE,0); 292 | delay(trx.dit_time); 293 | last_cw = millis(); 294 | } 295 | 296 | void sendDah() 297 | { 298 | outKEY.Write(1); 299 | OutputTone(PIN_OUT_TONE,Settings[ID_CW_TONE_HZ]); 300 | delay(trx.dah_time); 301 | outKEY.Write(0); 302 | OutputTone(PIN_OUT_TONE,0); 303 | delay(trx.dit_time); 304 | last_cw = millis(); 305 | } 306 | 307 | uint8_t readCWSpeed() 308 | { 309 | return trx.setCWSpeed( 310 | Settings[ID_CW_SPEED_MIN] + (long)analogRead(PIN_CW_SPEED_POT)*(Settings[ID_CW_SPEED_MAX]-Settings[ID_CW_SPEED_MIN]+1)/1024, 311 | Settings[ID_CW_DASH_LEN] 312 | ); 313 | } 314 | 315 | void playMessage(char* msg) 316 | { 317 | char ch; 318 | while ((ch = *msg++) != 0) { 319 | if (ch == ' ') 320 | delay(trx.dit_time*Settings[ID_CW_WORD_SPACE]/10); 321 | else { 322 | for(int i=0; MorseCode[i].ch[0] != 0; i++) { 323 | if (ch == MorseCode[i].ch[0]) { 324 | // play letter 325 | for (uint8_t j=1; j < 7; j++) { 326 | switch(MorseCode[i].ch[j]) { 327 | case '.': 328 | sendDit(); 329 | break; 330 | case '-': 331 | sendDah(); 332 | break; 333 | } 334 | } 335 | delay(trx.dit_time*Settings[ID_CW_LETTER_SPACE]/10); 336 | break; 337 | } 338 | } 339 | } 340 | if (readDit() || readDah()) return; 341 | readCWSpeed(); 342 | } 343 | } 344 | 345 | void cwTXOn() 346 | { 347 | trx.CWTX = 1; 348 | if (!trx.TX) { 349 | trx.TX = 1; 350 | outPTT.Write(1); 351 | UpdateFreq(); 352 | disp.Draw(trx); 353 | } 354 | } 355 | 356 | void edit_item(uint8_t mi) 357 | { 358 | int val = Settings[mi]; 359 | if (SettingsDef[mi].id == 99) { 360 | #ifdef VFO_SI5351 361 | vfo5351.out_calibrate_freq(); 362 | #endif 363 | #ifdef VFO_SI570 364 | vfo570.out_calibrate_freq(); 365 | #endif 366 | } 367 | disp.DrawMenu(SettingsDef[mi].id,SettingsDef[mi].title,val,1); 368 | keypad.waitUnpress(); 369 | while (readDit() || readDah()) ; 370 | while (1) { 371 | uint8_t key = keypad.Read(); 372 | if (key == 0 && readDit()) key = 1; 373 | if (key == 0 && readDah()) key = 2; 374 | switch (key) { 375 | case 1: 376 | // save value 377 | Settings[mi] = val; 378 | writeSettings(); 379 | #ifdef VFO_SI5351 380 | if (SettingsDef[mi].id == 99) vfo5351.set_xtal_freq((SI5351_CALIBRATION/10000)*10000+Settings[ID_SI5351_XTAL]); 381 | #endif 382 | return; 383 | break; 384 | case 2: 385 | // exit 386 | return; 387 | } 388 | long d=encoder.GetDelta(); 389 | if (d < 0) { 390 | val -= SettingsDef[mi].step; 391 | if (val < SettingsDef[mi].min_value) val = SettingsDef[mi].min_value; 392 | disp.DrawMenu(SettingsDef[mi].id,SettingsDef[mi].title,val,1); 393 | } else if (d > 0) { 394 | val += SettingsDef[mi].step; 395 | if (val > SettingsDef[mi].max_value) val = SettingsDef[mi].max_value; 396 | disp.DrawMenu(SettingsDef[mi].id,SettingsDef[mi].title,val,1); 397 | } 398 | } 399 | } 400 | 401 | void show_menu() 402 | { 403 | uint8_t mi=0; 404 | disp.DrawMenu(SettingsDef[mi].id,SettingsDef[mi].title,Settings[mi],0); 405 | keypad.waitUnpress(); 406 | while (readDit() || readDah()) ; 407 | while (1) { 408 | uint8_t key = keypad.Read(); 409 | if (key == 0 && readDit()) key = 1; 410 | if (key == 0 && readDah()) key = 2; 411 | switch (key) { 412 | case 1: 413 | if (SettingsDef[mi].id == 0) { 414 | resetSettings(); 415 | writeSettings(); 416 | } else // edit value 417 | edit_item(mi); 418 | disp.DrawMenu(SettingsDef[mi].id,SettingsDef[mi].title,Settings[mi],0); 419 | keypad.waitUnpress(); 420 | while (readDit() || readDah()) ; 421 | break; 422 | case 2: 423 | // exit 424 | disp.clear(); 425 | return; 426 | break; 427 | } 428 | long d=encoder.GetDelta(); 429 | if (d < 0) { 430 | if (mi == 0) mi = SETTINGS_COUNT-1; 431 | else mi--; 432 | disp.DrawMenu(SettingsDef[mi].id,SettingsDef[mi].title,Settings[mi],0); 433 | delay(300); 434 | encoder.GetDelta(); 435 | } else if (d > 0) { 436 | mi++; 437 | if (mi >= SETTINGS_COUNT) mi = 0; 438 | disp.DrawMenu(SettingsDef[mi].id,SettingsDef[mi].title,Settings[mi],0); 439 | delay(300); 440 | encoder.GetDelta(); 441 | } 442 | } 443 | } 444 | 445 | void loop() 446 | { 447 | if (first_call && (keypad.Read() == 1) && ((readDit() && !readDah()) || (!readDit() && readDah()))) { 448 | // show menu on startup 449 | show_menu(); 450 | keypad.waitUnpress(); 451 | while (readDit() || readDah()) ; 452 | } 453 | first_call = 0; 454 | 455 | long delta = encoder.GetDelta(); 456 | if (delta) { 457 | trx.ChangeFreq(delta); 458 | power_save(0); 459 | } 460 | 461 | if (millis()-last_pool > POOL_INTERVAL) { 462 | last_pool = millis(); 463 | uint8_t key = keypad.Read(); 464 | if (!last_key && key) { 465 | // somewhat pressed 466 | last_key = key; 467 | switch (key) { 468 | case 1: 469 | trx.NextBand(); 470 | break; 471 | case 2: 472 | trx.CW = !trx.CW; 473 | outCW.Write(trx.CW); 474 | break; 475 | case 3: 476 | show_menu(); 477 | keypad.waitUnpress(); 478 | break; 479 | case 4: 480 | case 5: 481 | case 6: 482 | // MEMO 483 | if (trx.CW) { 484 | cwTXOn(); 485 | switch (key) { 486 | case 4: 487 | playMessage(MEMO1); 488 | break; 489 | case 5: 490 | playMessage(MEMO2); 491 | break; 492 | case 6: 493 | playMessage(MEMO3); 494 | break; 495 | } 496 | } 497 | break; 498 | } 499 | power_save(0); 500 | } else if (!key) { 501 | last_key = 0; 502 | } 503 | 504 | readCWSpeed(); 505 | 506 | trx.TX = trx.CWTX || inPTT.Read(); 507 | outPTT.Write(trx.TX); 508 | 509 | UpdateFreq(); 510 | UpdateBandCtrl(); 511 | disp.Draw(trx); 512 | 513 | if (Settings[ID_POWER_DOWN_DELAY] > 0 && millis()-last_event > Settings[ID_POWER_DOWN_DELAY]*1000) 514 | power_save(1); 515 | } 516 | 517 | if (trx.TX || Settings[ID_CW_VOX]) { 518 | if (Settings[ID_CW_IAMBIC]) { 519 | if (im_state == imIDLE) { 520 | if (readDit()) im_state = imDIT; 521 | else if (readDah()) im_state = imDAH; 522 | } 523 | if (im_state == imDIT) { 524 | cwTXOn(); 525 | sendDit(); 526 | //now, if dah is pressed go there, else check for dit 527 | if (readDah()) im_state = imDAH; 528 | else { 529 | if (readDit()) im_state = imDIT; 530 | else { 531 | //delay(trx.dit_time*Settings[ID_CW_LETTER_SPACE]/10-trx.dit_time); 532 | im_state = imIDLE; 533 | } 534 | } 535 | } else if (im_state == imDAH) { 536 | cwTXOn(); 537 | sendDah(); 538 | //now, if dit is pressed go there, else check for dah 539 | if (readDit()) im_state = imDIT; 540 | else { 541 | if (readDah()) im_state = imDAH; 542 | else { 543 | //delay(trx.dit_time*Settings[ID_CW_LETTER_SPACE]/10-trx.dit_time); 544 | im_state = imIDLE; 545 | } 546 | } 547 | } 548 | } else { 549 | if (readDit()) { 550 | cwTXOn(); 551 | sendDit(); 552 | } else if (readDah()) { 553 | cwTXOn(); 554 | sendDah(); 555 | } 556 | } 557 | } 558 | 559 | if (trx.CWTX && millis()-last_cw > Settings[ID_BREAK_IN_DELAY]) { 560 | trx.CWTX = 0; 561 | trx.TX = inPTT.Read(); 562 | outPTT.Write(trx.TX); 563 | if (!trx.TX) 564 | UpdateFreq(); 565 | } 566 | 567 | static long state_poll_tm = 0; 568 | if (millis()-state_poll_tm > 500) { 569 | static uint16_t state_hash = 0; 570 | static uint8_t state_changed = false; 571 | static long state_changed_tm = 0; 572 | uint16_t new_state_hash = trx.StateHash(); 573 | if (new_state_hash != state_hash) { 574 | state_hash = new_state_hash; 575 | state_changed = true; 576 | state_changed_tm = millis(); 577 | } else if (state_changed && (millis()-state_changed_tm > 5000)) { 578 | // save state 579 | trx.StateSave(); 580 | state_changed = false; 581 | } 582 | state_poll_tm = millis(); 583 | } 584 | } 585 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------