From f7e712798a5cd50961a401bc79d0ca6fd7e06aba Mon Sep 17 00:00:00 2001 From: TT Date: Sun, 6 Oct 2019 07:56:25 +0900 Subject: [PATCH 1/2] chore: remove warnings --- main.c | 17 +++++++++++------ nanovna.h | 9 ++++++--- plot.c | 11 +++++------ si5351.c | 2 +- ui.c | 1 + 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index e023e7a..acd7c1a 100644 --- a/main.c +++ b/main.c @@ -34,9 +34,11 @@ #define ENABLED_DUMP -static void apply_error_term(void); static void apply_error_term_at(int i); +static void apply_edelay_at(int i); static void cal_interpolate(int s); +void update_frequencies(void); +void set_frequencies(uint32_t start, uint32_t stop, int16_t points); bool sweep(bool break_on_operation); @@ -47,7 +49,7 @@ static MUTEX_DECL(mutex); #define IS_HARMONIC_MODE(f) ((f) > FREQ_HARMONICS) int32_t frequency_offset = 5000; -int32_t frequency = 10000000; +uint32_t frequency = 10000000; int8_t drive_strength = DRIVE_STRENGTH_AUTO; int8_t sweep_enabled = TRUE; int8_t sweep_once = FALSE; @@ -146,7 +148,7 @@ transform_domain(void) // and calculate ifft for time domain float* tmp = (float*)spi_buffer; - uint8_t window_size, offset; + uint8_t window_size = 101, offset = 0; uint8_t is_lowpass = FALSE; switch (domain_mode & TD_FUNC) { case TD_FUNC_BANDPASS: @@ -280,7 +282,7 @@ adjust_gain(int newfreq) return delay; } -int set_frequency(int freq) +int set_frequency(uint32_t freq) { int delay = 0; if (frequency == freq) @@ -827,7 +829,7 @@ freq_mode_centerspan(void) #define STOP_MAX 1500000000 void -set_sweep_frequency(int type, uint32_t freq) +set_sweep_frequency(int type, int32_t freq) { int cal_applied = cal_status & CALSTAT_APPLY; switch (type) { @@ -1110,6 +1112,7 @@ eterm_calc_et(void) cal_status |= CALSTAT_ET; } +#if 0 void apply_error_term(void) { int i; @@ -1141,6 +1144,7 @@ void apply_error_term(void) measured[1][i][1] = s21ai; } } +#endif void apply_error_term_at(int i) { @@ -1171,7 +1175,7 @@ void apply_error_term_at(int i) measured[1][i][1] = s21ai; } -void apply_edelay_at(int i) +static void apply_edelay_at(int i) { float w = 2 * M_PI * electrical_delay * frequencies[i] * 1E-12; float s = sin(w); @@ -2127,5 +2131,6 @@ void HardFault_Handler(void) void hard_fault_handler_c(uint32_t* sp) { + (void)sp; while (true) {} } diff --git a/nanovna.h b/nanovna.h index 8fbe96c..809921e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -71,7 +71,7 @@ enum { ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW }; -void set_sweep_frequency(int type, uint32_t frequency); +void set_sweep_frequency(int type, int32_t frequency); uint32_t get_sweep_frequency(int type); float my_atof(const char *p); @@ -106,7 +106,7 @@ void calculate_gamma(float *gamma); void fetch_amplitude(float *gamma); void fetch_amplitude_ref(float *gamma); -int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength); +int si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength); /* @@ -195,7 +195,7 @@ typedef struct { uint16_t trace_color[TRACES_MAX]; int16_t touch_cal[4]; int8_t default_loadcal; - int32_t harmonic_freq_threshold; + uint32_t harmonic_freq_threshold; int32_t checksum; } config_t; @@ -237,6 +237,7 @@ 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]); void force_set_markmap(void); +void draw_frequencies(void); void draw_all(bool flush); void draw_cal_status(void); @@ -361,6 +362,8 @@ void ui_hide(void); extern uint8_t operation_requested; +void touch_start_watchdog(void); +void touch_position(int *x, int *y); void handle_touch_interrupt(void); #define TOUCH_THRESHOLD 2000 diff --git a/plot.c b/plot.c index ad43241..234ca94 100644 --- a/plot.c +++ b/plot.c @@ -8,7 +8,6 @@ #define SWAP(x,y) do { int z=x; x = y; y = z; } while(0) static void cell_draw_marker_info(int m, int n, int w, int h); -void draw_frequencies(void); void frequency_string(char *buf, size_t len, int32_t freq); void markmap_all_markers(void); @@ -614,7 +613,7 @@ gamma2imp(char *buf, int len, const float coeff[2], uint32_t frequency) } static void -gamma2resistance(char *buf, int len, const float coeff[2], uint32_t frequency) +gamma2resistance(char *buf, int len, const float coeff[2]) { float z0 = 50; float d = z0 / ((1-coeff[0])*(1-coeff[0])+coeff[1]*coeff[1]); @@ -623,7 +622,7 @@ gamma2resistance(char *buf, int len, const float coeff[2], uint32_t frequency) } static void -gamma2reactance(char *buf, int len, const float coeff[2], uint32_t frequency) +gamma2reactance(char *buf, int len, const float coeff[2]) { float z0 = 50; float d = z0 / ((1-coeff[0])*(1-coeff[0])+coeff[1]*coeff[1]); @@ -665,10 +664,10 @@ trace_get_value_string(int t, char *buf, int len, float coeff[2], uint32_t frequ chsnprintf(buf, len, "%.2fj", coeff[1]); break; case TRC_R: - gamma2resistance(buf, len, coeff, frequency); + gamma2resistance(buf, len, coeff); break; case TRC_X: - gamma2reactance(buf, len, coeff, frequency); + gamma2reactance(buf, len, coeff); break; //case TRC_ADMIT: case TRC_POLAR: @@ -744,7 +743,7 @@ clear_markmap(void) memset(markmap[current_mappage], 0, sizeof markmap[current_mappage]); } -void inline +inline void force_set_markmap(void) { memset(markmap[current_mappage], 0xff, sizeof markmap[current_mappage]); diff --git a/si5351.c b/si5351.c index 6e66e8a..49de637 100644 --- a/si5351.c +++ b/si5351.c @@ -304,7 +304,7 @@ int current_band = -1; */ #define CLK2_FREQUENCY 8000000L int -si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength) +si5351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength) { int band; int delay = 3; diff --git a/ui.c b/ui.c index 8cccb6d..80147b9 100644 --- a/ui.c +++ b/ui.c @@ -20,6 +20,7 @@ #include "ch.h" #include "hal.h" +#include "chprintf.h" #include "nanovna.h" #include #include From 3fc17e18f900c6bb31fb1e72bab345adf576c15c Mon Sep 17 00:00:00 2001 From: TT Date: Mon, 7 Oct 2019 22:24:32 +0900 Subject: [PATCH 2/2] fix: break sweep loop on frequency change --- main.c | 2 ++ nanovna.h | 3 +++ ui.c | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index acd7c1a..7a933b3 100644 --- a/main.c +++ b/main.c @@ -793,6 +793,8 @@ update_frequencies(void) } set_frequencies(start, stop, sweep_points); + operation_requested = OP_FREQCHANGE; + update_marker_index(); // set grid layout diff --git a/nanovna.h b/nanovna.h index 809921e..7f35500 100644 --- a/nanovna.h +++ b/nanovna.h @@ -86,6 +86,9 @@ extern int8_t sweep_enabled; extern void ui_init(void); extern void ui_process(void); +enum { OP_NONE = 0, OP_LEVER, OP_TOUCH, OP_FREQCHANGE }; +extern uint8_t operation_requested; + /* * dsp.c */ diff --git a/ui.c b/ui.c index 80147b9..3cbac63 100644 --- a/ui.c +++ b/ui.c @@ -59,7 +59,6 @@ static uint32_t last_button_down_ticks; static uint32_t last_button_repeat_ticks; static int8_t inhibit_until_release = FALSE; -enum { OP_NONE = 0, OP_LEVER, OP_TOUCH }; uint8_t operation_requested = OP_NONE; int8_t previous_marker = -1;