diff --git a/include/cibi.h b/include/cibi.h new file mode 100644 index 0000000..738f235 --- /dev/null +++ b/include/cibi.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2019, Vincent Hervieux vincent.hervieux@gmail.com + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the author Vincent Hervieux, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef CIBI_H +#define CIBI_H + +#include "cibidisplay.h" +#include "config.h" +#include "input.h" +#include "dds.h" + +class Cibi +{ +public: + /* Cibi application requires: + - the config + - the inputs + - the display + - the dds + */ + Cibi(Config& _config, Input& _input, U8G2& _display, DDS& _dds); + Cibi(const Cibi &_cibi); + ~Cibi(); + /* main application loop called when the application has the focus */ + void loop(bool _update_display = false); + /* getter on current frequency */ + const uint32_t& getCurrentFreq(); + +protected: + friend class CibiDisplay; + /* Cibi band enum */ + enum { + CIBI_BAND_UNKNOWN = -1, + CIBI_BAND_3_INF = 0x0, + CIBI_BAND_2_INF = 0x1, + CIBI_BAND_1_INF = 0x2, + CIBI_BAND_NORMAL = 0x3, + CIBI_BAND_1_SUP = 0x4, + CIBI_BAND_2_SUP = 0x5, + CIBI_BAND_3_SUP = 0x6, + CIBI_BAND_MAX = CIBI_BAND_3_SUP + }; + +private: + /* defining a structure to store names of Cibi channels */ + typedef struct { + int8_t channel; + int8_t band; + bool bis; + } cibi_channel_t; + + + + /* make a bis for cibi channels 3,7,11,15,19 */ + const static int8_t cibi_channels[45]; + const static bool cibi_channels_bis[45]; + + /* RF ranges enum */ + enum { + RANGE_RF_UNKNOWN = -1, + RANGE_RF_LF = 0, + RANGE_RF_MF, + RANGE_RF_HF, + RANGE_RF_VHF, + RANGE_RF_MAX = RANGE_RF_VHF + }; + + /* HAM band enum */ + // enum { + // BAND_UNKNOWN = -1, + // BAND_2200 = 0, + // BAND_1750, + // BAND_630, + // BAND_160, + // BAND_80, + // BAND_60, + // BAND_40, + // BAND_30, + // BAND_20, + // BAND_17, + // BAND_15, + // BAND_12, + // BAND_11, + // BAND_10, + // BAND_6, + // BAND_2, + // BAND_MAX = BAND_2 + // }; + + /* + * @brief init Cibi context + */ + void init(); + /* @brief get cibi channel + * @param: frequency + * @return -1 if none matching, 0 if successful */ + int getCibiChannel(uint32_t _frequency, cibi_channel_t* _channel); + /* @brief get band index + * @param: frequency + * @return RF range index in -1 if none matching */ + int getBand(uint32_t _frequency); + /* Update info on display and in our context */ + void updateDisplay(uint32_t _frequency, int _position, int _modulation, bool _tx, int _smeter); + /* Update DDS values according to modulation and frequency in our context */ + void updateDDS(uint32_t _frequency, int _modulation, bool _tx); + /* Update the frequency step according to the given cursor position */ + void updateFreqStep(int cursor_pos); + /* references */ + Config &config_; + Input &input_; + DDS &dds_; + /* context */ + /* current displayed values */ + cibi_channel_t current_cibi_channel_; + uint32_t current_freq_; + uint64_t freq_change_time_; + int current_clarifier_; + uint32_t freq_step_; /* up/down frequency step */ + int current_cursor_pos_; + int current_modulation_; + int current_smeter_; + bool current_tx_; + bool scanning_; + CibiDisplay *view_; +}; + +#endif /* CIBI_H */ diff --git a/include/cibidisplay.h b/include/cibidisplay.h new file mode 100644 index 0000000..4569827 --- /dev/null +++ b/include/cibidisplay.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2019, Vincent Hervieux vincent.hervieux@gmail.com + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the author Vincent Hervieux, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef CIBIDISPLAY_H +#define CIBIDISPLAY_H + +#include "display.h" + +class CibiDisplay +{ + public: + /* Constructor and initiliaze Cibi display */ + CibiDisplay(U8G2&_display); + CibiDisplay(const CibiDisplay &_cibidisplay); + /* De-initiliaze and release display */ + ~CibiDisplay(); + /* Display initialisation */ + void init(); + /* clean screen */ + void clear(); + /* refresh display */ + void display(); + /* Update displayed frequency */ + void setFreq(uint32_t _frequency, uint16_t _color); + /* Update displayed cursor position */ + void setCursorPos(int _position, uint16_t _color); + /* Update displayed RF band */ + void setBand(uint32_t _freq, uint16_t _color); + /* Update displayed modulation */ + void setModulation(int _modulation, uint16_t _color); + /* update cibi channel display */ + void setCibiChannel(int _channel, uint16_t _color); + void setCibiChannelBis(bool _bis, uint16_t _color); + void setCibiBand(int _band, uint16_t _color); + void setTx(bool _tx); +#ifdef SMETER_DISPLAY + /* Update s-meter over a 1024 scale (analog input)*/ + void setSMeter(int _signal); +#endif + private: + /** + * CONNEXIONS + * GND GND + * VDD +5V + * SCLK pin A5 + * SDA pin A4 + */ + + /* definning a structure to store RF ranges and bands */ + typedef struct { + uint32_t low_bound; /* low boundary frequency range */ + uint32_t high_bound; /* high boundary frequency range */ + int index; /* range or band index */ + } range_t; + + const static int16_t FREQ_DECIMAL_TEXT_POS_X PROGMEM = 2; + const static int16_t FREQ_FRACTIONNAL_TEXT_POS_X PROGMEM = 35; + const static int16_t FREQ_TEXT_POS_Y PROGMEM = 36; + // OLED module + U8G2 &display_; +}; + +#endif /* CIBIDISPLAY_H */ diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..82945eb --- /dev/null +++ b/include/config.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2019, Vincent Hervieux vincent.hervieux@gmail.com + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the author Vincent Hervieux, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef CONFIG_H +#define CONFIG_H + +#include "configdisplay.h" +#include "input.h" +#include "dds.h" + +class Config +{ + public: + /* Config application requires: + - the inputs + - the display + - the DDS + */ + Config(Input& _input, U8G2& _display, DDS& _dds); + Config(const Config& _config); + ~Config(); + /* main application loop called when the application has the focus */ + void loop(bool _update_display = false); + /* retrieve config from EEPROM */ + int open(); + /* save config to EEPROM */ + int save(); + /* getters */ + /* cibi frequency on power on */ + const uint32_t& getCibiFreq(); + /* cibi allowed freq min */ + const uint32_t& getCibiMinFreq(); + /* cibi allowed freq max */ + const uint32_t& getCibiMaxFreq(); + /* freq step increment */ + const uint32_t& getFreqStepIncrement(); + /* intermediate frequency mixer AM/FM/CW */ + const uint32_t& getFiAm(); + /* intermediate frequency mixer USB */ + const uint32_t& getFiUsb(); + /* intermediate frequency mixer LSB */ + const uint32_t& getFiLsb(); + /* VFO adjustment (replace trim pot) */ + const int32_t& getVFOAdj(); + /* Clarifier adjustment (replace trim pot) */ + const int32_t& getClarifierAdj(); + /* S-meter adjustment */ + const int32_t& getSMeterAdj(); + /* setters */ + /* cibi frequency on power on */ + void setCibiFreq(const uint32_t& _freq); + private: + enum + { + CONFIG_CIBI_FREQ = 0, + CONFIG_CIBI_MIN_FREQ, // 1 + CONFIG_CIBI_MAX_FREQ, // 2 + CONFIG_FREQ_STEP, // 3 + CONFIG_FI_AM, // 4 + CONFIG_FI_USB, // 5 + CONFIG_FI_LSB, // 6 + CONFIG_VFO_ADJ, // 7 + CONFIG_CLARIFIER_ADJ, // 8 + CONFIG_SMETER_ADJ, // 9 + CONFIG_MAX // 10 + }; + /* context stored in EEPROM */ + struct context_t { + uint32_t eeprom_header; /* EEPROM flag to detect if we've already set values */ + uint32_t cibi_frequency; /* cibi default frequency on startup */ + uint32_t cibi_min_freq; /* cibi minimum frequency */ + uint32_t cibi_max_freq; /* cibi maximum frequency */ + uint32_t freq_step_inc; /* frequency step, in increment mode STEP */ + uint32_t fi_am; /* FI AM/FM/CW */ + uint32_t fi_usb; /* FI USB */ + uint32_t fi_lsb; /* FI LSB */ + int32_t vfo_adj; /* VFO frequency adjustment */ + int32_t clarifier_adj; /* Clarifier frequency adjustment */ + int32_t smeter_adj; /* S-Meter adjustment to fill S-meter */ + } context_; + /* references */ + Input& input_; + DDS& dds_; + ConfigDisplay *view_; + /* context */ + int current_cursor_pos_; + int current_menu_index_; + uint32_t* current_value_; +}; + + + +#endif /* CONFIG_H */ diff --git a/include/configdisplay.h b/include/configdisplay.h new file mode 100644 index 0000000..16ba6cc --- /dev/null +++ b/include/configdisplay.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019, Vincent Hervieux vincent.hervieux@gmail.com + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the author Vincent Hervieux, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef CONFIGDISPLAY_H +#define CONFIGDISPLAY_H + +#include "display.h" + +class ConfigDisplay +{ + public: + ConfigDisplay(U8G2&_display); + /* De-initiliaze and release display */ + ~ConfigDisplay(); + /* Display initialisation */ + void init(); + /* clean screen */ + void clear(); + /* refresh display */ + void display(); + /* erase display */ + void clearDisplay(); + /* Update displayed config menu title */ + void setTitle(int _title_index, uint16_t _color); + /* Highlight title */ + void highlightTitle(uint16_t _color); + /* Update displayed config menu value */ + void setValueUint(uint32_t _value, uint16_t _color); + void setValueInt(int32_t _value, uint16_t _color); + /* Update displayed cursor position */ + void setCursorPos(int _position, uint16_t _color); + private: + // OLED module + U8G2 &display_; + // Some common constants + const static int16_t VALUE_POS_X PROGMEM = 20; + const static int16_t VALUE_POS_Y PROGMEM = 55; + const static int16_t MAX_STR_LENGTH PROGMEM = 20; +}; + + + +#endif /* CONFIGDISPLAY_H */ diff --git a/include/dds.h b/include/dds.h new file mode 100644 index 0000000..bfffb34 --- /dev/null +++ b/include/dds.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019, Vincent Hervieux vincent.hervieux@gmail.com + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the author Vincent Hervieux, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef DDS_H +#define DDS_H + +#include + +class DDS +{ + public: + /* valid output list */ + typedef enum { + OUTPUT_FI = 0, + OUTPUT_UNUSED, // 1 + OUTPUT_VFO, // 2 + OUTPUT_MAX + } output_t; + + /* Constructor */ + DDS(); + /* De-initiliaze and release DDS */ + ~DDS(); + /* Update generator output frequency */ + void setOutputFreq(output_t _output, uint32_t _frequency); + /* Set output frequency correction */ + void setOutputCorrection(int32_t _correction); + /* get current generator output frequency */ + const uint32_t& getOutputFreq(output_t _output); + /* enable/disable FI, FI is required while transmitting */ + void enableOutput(output_t _output, bool _enable); + /* initiliaze DDS */ + void init(); + + private: + /** + * CONNEXIONS + * GND GND + * VDD +5V + * SCLK pin A5 + * SDA pin A4 + */ + /* xtal on my si5351 is 25Mhz */ + const static uint32_t XTALFREQ PROGMEM = 25000000L; + /* delayed initialisation */ + boolean initialized_; + /* internal storage for frequencies outputs */ + uint32_t current_freq_[OUTPUT_MAX]; + /* store output state */ + bool enabled_[OUTPUT_MAX]; + /* clock module */ + Si5351mcu clockgen_; + + +}; + +#endif /* DDS_H */