2017-01-01 12:03:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* The software is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with GNU Radio; see the file COPYING. If not, write to
|
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
2016-12-17 05:16:56 +01:00
|
|
|
#include "ch.h"
|
|
|
|
|
|
2016-11-02 13:08:33 +01:00
|
|
|
/*
|
2017-01-01 12:03:21 +01:00
|
|
|
* main.c
|
2016-11-02 13:08:33 +01:00
|
|
|
*/
|
2017-01-01 12:03:21 +01:00
|
|
|
extern float measured[2][101][2];
|
2016-09-05 00:27:44 +02:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
#define CAL_LOAD 0
|
|
|
|
|
#define CAL_OPEN 1
|
|
|
|
|
#define CAL_SHORT 2
|
|
|
|
|
#define CAL_THRU 3
|
|
|
|
|
#define CAL_ISOLN 4
|
2016-09-05 00:27:44 +02:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
#define CALSTAT_LOAD (1<<0)
|
|
|
|
|
#define CALSTAT_OPEN (1<<1)
|
|
|
|
|
#define CALSTAT_SHORT (1<<2)
|
|
|
|
|
#define CALSTAT_THRU (1<<3)
|
|
|
|
|
#define CALSTAT_ISOLN (1<<4)
|
|
|
|
|
#define CALSTAT_ES (1<<5)
|
|
|
|
|
#define CALSTAT_ER (1<<6)
|
|
|
|
|
#define CALSTAT_ET (1<<7)
|
|
|
|
|
#define CALSTAT_ED CALSTAT_LOAD
|
|
|
|
|
#define CALSTAT_EX CALSTAT_ISOLN
|
|
|
|
|
#define CALSTAT_APPLY (1<<8)
|
2017-09-15 15:13:17 +02:00
|
|
|
#define CALSTAT_INTERPOLATED (1<<9)
|
2017-01-01 12:03:21 +01:00
|
|
|
|
|
|
|
|
#define ETERM_ED 0 /* error term directivity */
|
|
|
|
|
#define ETERM_ES 1 /* error term source match */
|
|
|
|
|
#define ETERM_ER 2 /* error term refrection tracking */
|
|
|
|
|
#define ETERM_ET 3 /* error term transmission tracking */
|
|
|
|
|
#define ETERM_EX 4 /* error term isolation */
|
2016-09-05 00:27:44 +02:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
void cal_collect(int type);
|
|
|
|
|
void cal_done(void);
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-05 01:04:28 +01:00
|
|
|
void set_sweep_frequency(int type, float frequency);
|
2017-01-01 12:03:21 +01:00
|
|
|
|
|
|
|
|
float my_atof(const char *p);
|
2016-11-02 13:08:33 +01:00
|
|
|
|
2017-01-16 17:49:22 +01:00
|
|
|
void toggle_sweep(void);
|
|
|
|
|
|
2016-11-02 13:08:33 +01:00
|
|
|
/*
|
|
|
|
|
* ui.c
|
|
|
|
|
*/
|
2016-09-05 00:27:44 +02:00
|
|
|
extern void ui_init(void);
|
|
|
|
|
extern void ui_process(void);
|
|
|
|
|
|
2016-11-02 13:08:33 +01:00
|
|
|
/*
|
|
|
|
|
* dsp.c
|
|
|
|
|
*/
|
2016-09-05 00:27:44 +02:00
|
|
|
// 5ms @ 48kHz
|
2016-09-30 02:42:49 +02:00
|
|
|
#define AUDIO_BUFFER_LEN 96
|
2016-09-05 00:27:44 +02:00
|
|
|
|
|
|
|
|
extern int16_t rx_buffer[];
|
|
|
|
|
|
2016-09-18 03:11:18 +02:00
|
|
|
#define STATE_LEN 32
|
2016-09-30 02:42:49 +02:00
|
|
|
#define SAMPLE_LEN 48
|
2016-09-05 00:27:44 +02:00
|
|
|
|
2016-09-18 03:11:18 +02:00
|
|
|
extern int16_t ref_state[];
|
|
|
|
|
extern int16_t ref_buf[];
|
|
|
|
|
extern int16_t samp_buf[];
|
|
|
|
|
|
2016-09-19 02:31:50 +02:00
|
|
|
//extern int16_t refq_buf[];
|
|
|
|
|
extern int16_t refiq_buf[];
|
|
|
|
|
|
2016-09-18 03:11:18 +02:00
|
|
|
void dsp_process(int16_t *src, size_t len);
|
2017-01-26 01:10:48 +01:00
|
|
|
void reset_dsp_accumerator(void);
|
2016-11-28 15:44:21 +01:00
|
|
|
void calculate_gamma(float *gamma);
|
2016-09-05 00:27:44 +02:00
|
|
|
|
2016-09-24 03:25:13 +02:00
|
|
|
int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength);
|
2016-09-26 17:06:00 +02:00
|
|
|
|
2016-10-28 13:50:51 +02:00
|
|
|
|
2016-11-02 13:08:33 +01:00
|
|
|
/*
|
2017-01-01 12:03:21 +01:00
|
|
|
* tlv320aic3204.c
|
2016-11-02 13:08:33 +01:00
|
|
|
*/
|
2016-12-04 08:19:31 +01:00
|
|
|
typedef struct {
|
2017-01-01 12:03:21 +01:00
|
|
|
int target_level;
|
|
|
|
|
int gain_hysteresis;
|
|
|
|
|
int attack;
|
|
|
|
|
int attack_scale;
|
|
|
|
|
int decay;
|
|
|
|
|
int decay_scale;
|
|
|
|
|
} tlv320aic3204_agc_config_t;
|
2016-10-28 13:50:51 +02:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
extern void tlv320aic3204_init(void);
|
|
|
|
|
extern void tlv320aic3204_set_gain(int lgain, int rgain);
|
|
|
|
|
extern void tlv320aic3204_set_digital_gain(int gain);
|
|
|
|
|
extern void tlv320aic3204_set_volume(int gain);
|
|
|
|
|
extern void tlv320aic3204_agc_config(tlv320aic3204_agc_config_t *conf);
|
|
|
|
|
extern void tlv320aic3204_select_in1(void);
|
|
|
|
|
extern void tlv320aic3204_select_in3(void);
|
|
|
|
|
extern void tlv320aic3204_adc_filter_enable(int enable);
|
2016-12-04 08:19:31 +01:00
|
|
|
|
2016-10-28 13:50:51 +02:00
|
|
|
|
2016-11-02 13:08:33 +01:00
|
|
|
/*
|
|
|
|
|
* plot.c
|
|
|
|
|
*/
|
2016-11-03 13:56:56 +01:00
|
|
|
#define OFFSETX 15
|
|
|
|
|
#define OFFSETY 0
|
|
|
|
|
#define WIDTH 291
|
|
|
|
|
#define HEIGHT 233
|
|
|
|
|
|
2017-01-15 15:27:05 +01:00
|
|
|
#define CELLOFFSETX 5
|
|
|
|
|
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
|
|
|
|
|
|
2016-11-03 13:56:56 +01:00
|
|
|
extern int area_width;
|
|
|
|
|
extern int area_height;
|
|
|
|
|
|
2016-11-28 01:17:54 +01:00
|
|
|
#define GRIDY 29
|
|
|
|
|
|
|
|
|
|
// font
|
|
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
extern const uint16_t x5x7_bits [];
|
|
|
|
|
extern const uint32_t numfont20x24[][24];
|
2016-11-02 13:08:33 +01:00
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
#define S_PI "\034"
|
|
|
|
|
#define S_MICRO "\035"
|
|
|
|
|
#define S_OHM "\036"
|
|
|
|
|
#define S_DEGREE "\037"
|
2017-01-02 08:59:10 +01:00
|
|
|
#define S_RARROW "\033"
|
2016-11-02 13:08:33 +01:00
|
|
|
|
2016-11-28 01:17:54 +01:00
|
|
|
// trace
|
|
|
|
|
|
2016-10-16 17:05:19 +02:00
|
|
|
#define TRACES_MAX 4
|
|
|
|
|
|
|
|
|
|
enum {
|
2017-01-05 01:04:28 +01:00
|
|
|
TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_OFF
|
2016-10-16 17:05:19 +02:00
|
|
|
};
|
|
|
|
|
|
2016-10-28 19:44:09 +02:00
|
|
|
extern const char *trc_type_name[];
|
|
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
// LOGMAG: SCALE, REFPOS, REFVAL
|
|
|
|
|
// PHASE: SCALE, REFPOS, REFVAL
|
|
|
|
|
// DELAY: SCALE, REFPOS, REFVAL
|
|
|
|
|
// SMITH: SCALE, <REFPOS>, <REFVAL>
|
|
|
|
|
// LINMAG: SCALE, REFPOS, REFVAL
|
|
|
|
|
// SWR: SCALE, REFPOS, REFVAL
|
|
|
|
|
|
|
|
|
|
// Electrical Delay
|
|
|
|
|
// Phase
|
|
|
|
|
|
2016-10-16 17:05:19 +02:00
|
|
|
typedef struct {
|
2017-01-02 11:15:16 +01:00
|
|
|
uint8_t enabled;
|
|
|
|
|
uint8_t type;
|
|
|
|
|
uint8_t channel;
|
|
|
|
|
uint8_t polar;
|
2016-10-24 18:16:05 +02:00
|
|
|
float scale;
|
2017-01-15 15:27:05 +01:00
|
|
|
float refpos;
|
2016-10-16 17:05:19 +02:00
|
|
|
} trace_t;
|
|
|
|
|
|
2017-01-02 11:15:16 +01:00
|
|
|
typedef struct {
|
|
|
|
|
int32_t magic;
|
|
|
|
|
uint16_t dac_value;
|
|
|
|
|
uint16_t grid_color;
|
2017-01-04 10:28:52 +01:00
|
|
|
uint16_t menu_normal_color;
|
|
|
|
|
uint16_t menu_active_color;
|
2017-01-02 11:15:16 +01:00
|
|
|
uint16_t trace_color[TRACES_MAX];
|
2017-01-04 10:28:52 +01:00
|
|
|
int16_t touch_cal[4];
|
2017-01-20 00:57:17 +01:00
|
|
|
int8_t default_loadcal;
|
2017-01-02 11:15:16 +01:00
|
|
|
int32_t checksum;
|
|
|
|
|
} config_t;
|
|
|
|
|
|
|
|
|
|
extern config_t config;
|
|
|
|
|
|
2016-11-28 01:17:54 +01:00
|
|
|
//extern trace_t trace[TRACES_MAX];
|
|
|
|
|
|
|
|
|
|
void set_trace_type(int t, int type);
|
2016-11-30 17:08:13 +01:00
|
|
|
void set_trace_channel(int t, int channel);
|
2016-12-04 08:19:31 +01:00
|
|
|
void set_trace_scale(int t, float scale);
|
2017-01-17 15:06:32 +01:00
|
|
|
void set_trace_refpos(int t, float refpos);
|
2016-11-28 01:17:54 +01:00
|
|
|
|
|
|
|
|
// marker
|
2016-11-04 19:37:11 +01:00
|
|
|
|
2016-10-28 20:11:13 +02:00
|
|
|
typedef struct {
|
2017-09-17 13:19:12 +02:00
|
|
|
int8_t enabled;
|
|
|
|
|
int16_t index;
|
|
|
|
|
uint32_t frequency;
|
2016-10-28 20:11:13 +02:00
|
|
|
} marker_t;
|
|
|
|
|
|
2016-11-04 19:37:11 +01:00
|
|
|
//extern marker_t markers[4];
|
|
|
|
|
//extern int active_marker;
|
2016-10-14 14:47:00 +02:00
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
void plot_init(void);
|
2016-12-12 15:45:49 +01:00
|
|
|
void update_grid(void);
|
2017-09-17 11:52:02 +02:00
|
|
|
void request_to_redraw_grid(void);
|
|
|
|
|
void redraw_frame(void);
|
|
|
|
|
//void redraw_all(void);
|
|
|
|
|
void request_to_draw_cells_behind_menu(void);
|
2016-11-05 15:06:24 +01:00
|
|
|
void redraw_marker(int marker, int update_info);
|
|
|
|
|
void trace_get_info(int t, char *buf, int len);
|
|
|
|
|
void plot_into_index(float measured[2][101][2]);
|
2016-11-28 01:17:54 +01:00
|
|
|
void force_set_markmap(void);
|
2017-01-17 15:06:32 +01:00
|
|
|
void draw_all_cells(void);
|
2016-11-05 15:06:24 +01:00
|
|
|
|
2016-11-17 16:53:40 +01:00
|
|
|
void draw_cal_status(void);
|
|
|
|
|
|
2016-11-26 16:47:21 +01:00
|
|
|
void markmap_all_markers(void);
|
|
|
|
|
|
2017-01-03 08:39:00 +01:00
|
|
|
void marker_position(int m, int t, int *x, int *y);
|
|
|
|
|
int search_nearest_index(int x, int y, int t);
|
2016-11-05 15:06:24 +01:00
|
|
|
|
2017-09-17 11:52:02 +02:00
|
|
|
extern int8_t redraw_requested;
|
|
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
/*
|
2017-01-01 12:03:21 +01:00
|
|
|
* ili9341.c
|
2016-11-05 15:06:24 +01:00
|
|
|
*/
|
2017-01-01 12:03:21 +01:00
|
|
|
#define RGB565(b,r,g) ( (((b)<<8)&0xfc00) | (((r)<<2)&0x03e0) | (((g)>>3)&0x001f) )
|
2016-10-14 14:47:00 +02:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
typedef struct {
|
|
|
|
|
uint16_t width;
|
|
|
|
|
uint16_t height;
|
|
|
|
|
uint16_t scaley;
|
|
|
|
|
uint16_t slide;
|
|
|
|
|
const uint32_t *bitmap;
|
|
|
|
|
} font_t;
|
2016-10-14 14:47:00 +02:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
extern const font_t NF20x24;
|
2016-11-19 05:11:49 +01:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
extern uint16_t spi_buffer[1024];
|
2016-12-04 08:19:31 +01:00
|
|
|
|
2017-01-01 12:03:21 +01:00
|
|
|
void ili9341_init(void);
|
|
|
|
|
void ili9341_test(int mode);
|
|
|
|
|
void ili9341_bulk(int x, int y, int w, int h);
|
|
|
|
|
void ili9341_fill(int x, int y, int w, int h, int color);
|
|
|
|
|
void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg);
|
|
|
|
|
void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg);
|
|
|
|
|
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
|
2016-12-04 08:19:31 +01:00
|
|
|
|
2016-10-16 01:11:16 +02:00
|
|
|
|
2016-11-04 17:22:48 +01:00
|
|
|
/*
|
|
|
|
|
* flash.c
|
|
|
|
|
*/
|
|
|
|
|
#define SAVEAREA_MAX 5
|
2016-10-16 13:02:38 +02:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int32_t magic;
|
2016-12-12 16:01:17 +01:00
|
|
|
int32_t _frequency0; // start or center
|
|
|
|
|
int32_t _frequency1; // stop or span
|
2016-10-16 13:02:38 +02:00
|
|
|
int16_t _sweep_points;
|
|
|
|
|
uint16_t _cal_status;
|
|
|
|
|
|
|
|
|
|
uint32_t _frequencies[101];
|
|
|
|
|
float _cal_data[5][101][2];
|
2016-11-04 19:37:11 +01:00
|
|
|
|
|
|
|
|
trace_t _trace[TRACES_MAX];
|
|
|
|
|
marker_t _markers[4];
|
|
|
|
|
int _active_marker;
|
|
|
|
|
|
2016-10-16 13:02:38 +02:00
|
|
|
int32_t checksum;
|
2017-01-02 11:15:16 +01:00
|
|
|
} properties_t;
|
2016-10-16 13:02:38 +02:00
|
|
|
|
|
|
|
|
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
|
|
|
|
|
|
2016-11-17 16:53:40 +01:00
|
|
|
extern int16_t lastsaveid;
|
2017-01-16 16:33:15 +01:00
|
|
|
extern properties_t *active_props;
|
2017-01-02 11:15:16 +01:00
|
|
|
extern properties_t current_props;
|
|
|
|
|
|
2017-09-15 17:48:34 +02:00
|
|
|
extern uint8_t previous_marker;
|
|
|
|
|
|
2017-01-02 11:15:16 +01:00
|
|
|
#define frequency0 current_props._frequency0
|
|
|
|
|
#define frequency1 current_props._frequency1
|
|
|
|
|
#define sweep_points current_props._sweep_points
|
|
|
|
|
#define cal_status current_props._cal_status
|
|
|
|
|
#define frequencies current_props._frequencies
|
2017-01-16 16:33:15 +01:00
|
|
|
#define cal_data active_props->_cal_data
|
2016-11-02 14:38:04 +01:00
|
|
|
|
2017-01-02 11:15:16 +01:00
|
|
|
#define trace current_props._trace
|
|
|
|
|
#define markers current_props._markers
|
|
|
|
|
#define active_marker current_props._active_marker
|
2016-11-04 19:37:11 +01:00
|
|
|
|
2016-11-04 17:22:48 +01:00
|
|
|
int caldata_save(int id);
|
|
|
|
|
int caldata_recall(int id);
|
2017-09-15 15:13:17 +02:00
|
|
|
const properties_t *caldata_ref(int id);
|
2016-11-04 17:22:48 +01:00
|
|
|
|
2017-01-02 14:03:20 +01:00
|
|
|
int config_save(void);
|
|
|
|
|
int config_recall(void);
|
|
|
|
|
|
2017-01-20 00:57:17 +01:00
|
|
|
void clear_all_config_prop_data(void);
|
|
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
/*
|
|
|
|
|
* ui.c
|
|
|
|
|
*/
|
2017-09-17 11:52:02 +02:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int digit; /* 0~5 */
|
|
|
|
|
int current_trace; /* 0..3 */
|
|
|
|
|
} uistat_t;
|
|
|
|
|
|
|
|
|
|
extern uistat_t uistat;
|
|
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
void ui_init(void);
|
|
|
|
|
void ui_show(void);
|
|
|
|
|
void ui_hide(void);
|
2016-11-04 17:22:48 +01:00
|
|
|
|
2016-11-30 12:17:55 +01:00
|
|
|
extern uint8_t operation_requested;
|
|
|
|
|
|
2016-12-17 10:32:27 +01:00
|
|
|
void handle_touch_interrupt(void);
|
|
|
|
|
|
|
|
|
|
#define TOUCH_THRESHOLD 2000
|
|
|
|
|
|
|
|
|
|
void touch_cal_exec(void);
|
2017-02-02 21:40:57 +01:00
|
|
|
void touch_draw_test(void);
|
2016-11-04 17:22:48 +01:00
|
|
|
|
2016-12-17 05:16:56 +01:00
|
|
|
/*
|
|
|
|
|
* adc.c
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void adc_init(void);
|
|
|
|
|
uint16_t adc_single_read(ADC_TypeDef *adc, uint32_t chsel);
|
|
|
|
|
void adc_start_analog_watchdogd(ADC_TypeDef *adc, uint32_t chsel);
|
|
|
|
|
void adc_stop(ADC_TypeDef *adc);
|
|
|
|
|
void adc_interrupt(ADC_TypeDef *adc);
|
|
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
/*
|
|
|
|
|
* misclinous
|
|
|
|
|
*/
|
2016-11-02 14:38:04 +01:00
|
|
|
#define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0)
|
2016-11-03 13:56:56 +01:00
|
|
|
|
2016-11-05 15:06:24 +01:00
|
|
|
/*EOF*/
|