simpleSA/simpleSA.h

376 lines
12 KiB
C
Raw Normal View History

2020-08-16 02:03:43 +08:00
/*
* "tinySA.h"
*
* This file contains various parameters for the TinySA spectrum analyzer software.
*
* In general, the user should not have any need to change anything defined in here.
* All the things that a user might need to (or want to) change can be found in the
* "My_SA.h" file.
*
* The starting point for this version is the "tinySA_touch02" software developed
* by Dave (M0WID). That software is based on the original version by Erik Kaashoek.
*
* Modified by John Price (WA2FZW):
*
* Version 1.0:
*
* Just add comments and try to figure out how it all works!
*
*
* Version 1.7:
*
* Moved lots of definitions from the main file to here to reduce the clutter
* in that file.
*/
#ifndef TINYSA_H_
#define TINYSA_H_ // Prevent double inclusion
#include "my_SA.h" // User settable parameters
2020-08-16 02:03:43 +08:00
#include <Arduino.h> // General Arduino definitions
#include <TFT_eSPI.h>
#define PROGRAM_NAME "simpleSA" // These are for the WiFi interface
#define PROGRAM_VERSION "Version 0.1" // Current version - beta!
2020-08-16 02:03:43 +08:00
/*
* I think this symbol defines the number of different trace types that are available,
* but I'm not sure about that yet. This is the way Dave has it set, so until I figure
* it out, it will stay set at '1'.
*/
#define TRACE_COUNT 1 // Number of different traces available
2020-08-16 02:03:43 +08:00
/*
* Define variables and functions associated with drawing stuff on the screen.
*/
#define DISPLAY_POINTS 290 // Number of scan points in a sweep
#define BANDSCOPE_POINTS 80 // Number of scan points in a bandscope sweep
2020-08-16 02:03:43 +08:00
#define CHAR_HEIGHT 8 // Height of a character
#define HALF_CHAR_H 4 // Half a character height
#define CHAR_WIDTH 6 // Width of a character
#define X_GRID 10 // Number of vertical grid lines
#define Y_GRID 10 // Number of horizontal grid lines
#define DELTA_X ( DISPLAY_POINTS / X_GRID ) // Spacing of x axis grid lines
#define DELTA_Y ( 21 ) // Spacing of y axis grid lines
#define X_ORIGIN 27 // 'X' origin of checkerboard
#define Y_ORIGIN ( CHAR_HEIGHT * 2 + 3 ) // 'Y' origin of checkerboard
#define GRID_HEIGHT ( Y_GRID * DELTA_Y ) // Height of checkerboard
#define WATERFALL_HEIGHT 100 // Height of waterfall in Bandscope mode
2020-08-16 02:03:43 +08:00
/*
* Definitions used in signal generator mode
*/
enum {SIG_MENU_KEY, SIG_FM_KEY, SIG_AM_KEY, SIG_ON_KEY, SIG_FREQ_KEY, SIG_MOD_KEY};
#define SA_FONT_LARGE "NotoSansBold56"
// sig gen mode key position, size and font
#define KEY_W 50 // Width and height
#define KEY_H 40
#define NUM_W 31 // width for numeric digits
#define NUM_H 33 // height for numeric digit +/- keys
#define KEY_FONT "NotoSansSCM14" //Semi Condensed Monospaced 14pt
#define KEY_COLOR TFT_WHITE
#define KEY_SEL_COLOR TFT_CYAN
#define KEY_ON_COLOR TFT_GREEN
#define KEY_OFF_COLOR TFT_PINK
#define SIG_KEY_COUNT 18
#define MAX_SIGLO_FREQ 250000000
#define MIN_SIGLO_FREQ 100
/*
* Symbols for the various attenuator options
*/
#define PE4302_PCF 1
#define PE4302_GPIO 2
#define PE4302_SERIAL 3
/*
* Color definitions for the standard displays; Again, these need to be moved to
* a separate header file.
*
* Modified in M0WID Version 05 - Eliminate all but the ILI9431 color definitions.
* Modified in WA2FZW Version 1.1 - Change all "DISPLAY_color" to simply "color".
*
* The "TFT_color" values are defined in the "TFT_eSPI.h" file in the library.
*/
#define WHITE TFT_WHITE
#define BLACK TFT_BLACK
#define DARKGREY TFT_DARKGREY
#define YELLOW TFT_YELLOW
#define ORANGE TFT_ORANGE
#define RED TFT_RED
#define GREEN TFT_GREEN
#define BLUE TFT_BLUE
#define PINK TFT_PINK
#define LT_BLUE 0x6F1F
#define MAGENTA TFT_MAGENTA
#define INVERSE TFT_WHITE
#define BACKGROUND TFT_BLACK // Default background color
#define SCREEN_WIDTH 320 // Display width, in pixels
#define SCREEN_HEIGHT 240 // Display height, in pixels
#define DELAY_ERROR 2 // Time in seconds to show error message on display
#define ERR_INFO 1 // Informational type error
#define ERR_WARN 2 // Warning
#define ERR_FATAL 3 // Fatal error
/*
* A factor used to increase the number of measurement points above that calculated by
* just dividing the sweep span by the RBW. Allows for some overlap to reduce the effect
* of the 3dB drop at the filter edges
*/
#define OVERLAP 1.1
2020-09-08 02:01:14 +08:00
/*
* Minimum delay left for the websockets to be checked while waiting
* for the SI4432 filters to settle
* Webocket.loop() takes around 35microseconds, varies a bit
*/
#define MIN_DELAY_WEBSOCKETS 50
2020-08-16 02:03:43 +08:00
/*
* These are the minimum and maximum values for the "IF Frequency". In reality, testing has
* shown that settings of more than about 100KHz from the normal 433.92MHz cause lots of
* spurs, but some SAW filters may behave differently.
*/
#define MIN_IF_FREQ 433000000UL // 433MHz
#define MAX_IF_FREQ 435000000UL // 435MHz
/*
* Tracking Generator offset limits - note signed
*/
#define MIN_TG_OFFSET -1000000L // -1MHz
#define MAX_TG_OFFSET 1000000L // +1MHz
/*
* SI4432 max and min drive levels
*/
#define MIN_DRIVE 0
#define MAX_DRIVE 7
/*
* SI4432 MAx no of bandpass filters
*/
#define MAX_SI4432_FILTERS 57
2020-08-16 02:03:43 +08:00
/*
* The various operating modes:
*
* Only SA_LOW_RANGE implemented so far - some of these may never get implemented!
* Low range is using the mixer, range around 1Mhz-250Mhz depending on low pass
* filter installed.
*
* High range is direct to the LO SI4432, bypassing mixer, attenuator and filters,
* range approx 240MHz - 930Mhz
*
* High range performance will be limited due to no bandpass filtering other than
* in SI4432 itself.
*/
enum { SA_LOW_RANGE, SA_HIGH_RANGE, SIG_GEN_LOW_RANGE, SIG_GEN_HIGH_RANGE,
IF_SWEEP, ZERO_SPAN_LOW_RANGE, ZERO_SPAN_HIGH_RANGE, BANDSCOPE, RX_SWEEP };
2020-08-16 02:03:43 +08:00
/*
* The "AV_XXXX" symbols define various options for how readings are averaged"
*/
enum { AV_OFF, AV_MIN, AV_MAX, AV_2, AV_4, AV_8 };
/*
* Modulation types for signal generator mode
*/
enum { MOD_OFF, MOD_AM, MOD_FM, NOISE };
/*
* This is a macro that is used to determine the number of elements in an array. It figures
* that out by dividing the total size of the array by the size of a single element. This is
* how we will calculate the number of entries in the "msgTable" array.
*/
#define ELEMENTS(x) ( sizeof ( x ) / sizeof ( x[0] ))
#define min(a,b) ( a<b ? a : b )
/*
* The "peak_t" type structure is used for recording the locations of the markers:
*/
typedef struct {
uint8_t Level;
uint16_t Index;
uint32_t Freq;
} peak_t;
/*
* The "settings_t" structure defines the parameters used to configure the
* spectrum analyzer for a particular scan.
*
* The "settings" are saved as a file in the flash memory and can be recalled
* from there.
*/
typedef struct {
uint32_t ScanStart = 0; // Scan start frequency (***)
uint32_t ScanStop = 100000000; // Scan end frequency (***)
uint32_t IF_Freq = 433920000; // Default IF frequency (***)
int16_t MaxGrid = -10; // Default dB for top line of graph (***)
int16_t MinGrid = -110; // Default dB for bottom line of graph (***)
int8_t Attenuate = 0; // Attenuator setting (***)
double ExternalGain = 0.0; // External gain or attenuation
2020-08-16 02:03:43 +08:00
int8_t Generate = 0; // Signal generator mode if not zero (***)
int16_t Bandwidth10 = 0; // Resolution Bandwidth setting*10; 0 = auto
double LevelOffset = 0; // Calibration value (move to config?)
2020-08-16 02:03:43 +08:00
int8_t ReferenceOut = 1; // Transmitter GPIO2 set to 15MHz
int16_t PowerGrid = 10; // dB/vertical divison on the grid
bool Spur = 0; // Spur reduction on or off
int32_t SpurOffset = 300000; // Amount to offset IF if spur reduction on. Can be -ve
uint8_t Average = 0; // Averaging setting (0 - 5)
bool ShowStorage = 0; // Display stored scan (on or off)
bool SubtractStorage = 0; // Subtract stored scan (on or off)
bool ShowGain = 1; // Display gain trace (on or off)
bool ShowSweep = 1; // Display dB trace (on or off)
uint8_t Drive = 6; // LO Drive power (***) (move to config?)
2020-08-16 02:03:43 +08:00
uint8_t SigGenDrive = 5; // Signal generator drive (for RX SI4432)
uint8_t spareUint8t_1 = 5; // spare
uint8_t spareUint8t_2 = 5; // spare
uint8_t PreampGain = 0x60; // AGC on
uint16_t Mode = SA_LOW_RANGE; // Default to low freq range Spectrum analyser mode
uint16_t Timebase = 100; // Timebase for Zero IF modes (milliSeconds)
int16_t TriggerLevel = -40; // Trigger level for ZeroIF mode (dBm)
2020-08-21 19:33:06 +08:00
uint32_t BandscopeStart = 14000000; // Start frequency for bandscope sweep
2020-08-16 02:03:43 +08:00
uint32_t BandscopeSpan = 200000; // Span for the bandscope sweep
uint16_t BandscopePoints = BANDSCOPE_POINTS; // No of points in the sweep. 80/160/320
int16_t BandscopeMaxGrid= -30;
int16_t BandscopeMinGrid= -130;
2020-08-21 19:33:06 +08:00
int16_t BandscopeRBW10 = 28; // Resolution Bandwidth setting*10;
int16_t WaterfallMin = 17; // RSSI values below this are treated as zero
2020-08-21 19:33:06 +08:00
double WaterfallGain = 1.5; // Multiply RSSI value to get colour intensity
2020-08-16 02:03:43 +08:00
/*
* The following line should read:
*
* MkrStatus[MARKER_COUNT] = { MKR_ACTIVE, 0, 0, 0 };
*
* however, there is a chicken & egg thing going on between this file and "Marker.h"
* so for now, the initialization values are hard-coded.
*/
uint8_t MkrStatus[4] = { 0x08, 0, 0, 0 };
/*
* The "Dummy" entry is here for testing purposes. Bu enabling or disabling it, one
* can force the default settings to be used at startup as opposed to the saved ones.
*/
uint32_t Dummy;
} settings_t;
/*
* Setting structure for signal generator mode
*
* Saved as a file to flash.
*/
typedef struct {
uint32_t Frequency = 14000000; // in Hz
uint8_t LO_Drive = 6; // 0 = -1, 1=2, 2=5, 3=8, 4=11, 5=14, 6=17, 7=20 dBm
uint8_t RX_Drive = 3; // as above, B3555 SAW filter max 10dBm, assume some loss in switch, so 4 would be the max allowed
uint8_t ModulationType = MOD_OFF; // see enum
uint16_t ModFrequency = 1000; // in Hz
uint8_t ModDepth = 100; // in %
int16_t Calibration = -13; // in dBm, max power out from your unit with no attenuation
int16_t Power = -15; // in dBm. Required output power.
uint8_t Dummy = 123; // dummy to check if the data is valid
} sigGenSettings_t;
/*
* Setting structure for tracking generator
* If two SI4432 are used for tracking generator IF and LO then
* the Tracking Generator can also be used as a signal generator
*
* Saved as a file to flash.
*/
typedef struct {
uint8_t Mode = 0; // 0 = off, 1 = track, 2 = sig gen
uint32_t Frequency = 14000000; // in Hz
int32_t Offset = 0; // Offset from LO in Hz. Can be -ve
uint8_t LO_Drive = 6; // 0 = -1, 1=2, 2=5, 3=8, 4=11, 5=14, 6=17, 7=20 dBm
uint8_t IF_Drive = 3; // as above, B3555 SAW filter max 10dBm, assume some loss in switch, so 4 would be the max allowed
uint8_t ModulationType = MOD_OFF; // see enum
uint16_t ModFrequency = 1000; // in Hz
uint8_t ModDepth = 100; // in %
int16_t Calibration = -13; // in dBm, max power out from your unit with no attenuation
int16_t Power = -15; // in dBm. Required output power.
uint8_t Dummy = 99; // dummy to check if the data is valid
} trackGenSettings_t;
/*
* The "config" structure defines some general display parameters.
*
*/
typedef struct {
int32_t magic = 1234;
#ifdef __DAC__
uint16_t dac_value;
#endif
uint16_t grid_color = BLACK;
uint16_t menu_normal_color = WHITE;
uint16_t menu_active_color = LT_BLUE;
uint16_t trace_color[TRACE_COUNT] = { LT_BLUE };
uint32_t harmonic_freq_threshold = 0;
int16_t vbat_offset = 0;
uint16_t touch_cal[5] = { 398, 3479, 335, 3465, 1 }; // Default values for TFT_eSPI touch
uint8_t RX_capacitance = RX_CAPACITANCE; // allows some calibration of frequency
uint8_t TX_capacitance = TX_CAPACITANCE;
uint8_t tgLO_capacitance = TG_LO_CAPACITANCE;
uint8_t tgIF_capacitance = TG_IF_CAPACITANCE;
int32_t checksum = 0;
} config_t;
/*
* Used for keys in Sig Gen mode
*/
typedef struct {
uint16_t x;
uint16_t y;
uint16_t width;
uint16_t height;
uint16_t color;
uint16_t activeColor;
const char * text; // pointer to key text
const char * activeText;
} sig_key_t;
#endif // #ifndef TINYSA_H_