mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Big code redisign (increase CELL draw size, more faster screen render), also save about 4-5kB flash size
Try remove all hardcoded values from code (use definition if set) Some error fix main.c: Rewrite Shell, now it run on main thread and require less RAM (not need stack) (possible run it as thread if define VNA_SHELL_THREAD Remove not used trace_info[].scale_unit in set_trace_scale/get_trace_scale (it just divede on set and multiple on get, better use it for default scale set) Replace some hardcoded values MARKERS_MAX SAVEAREA_MAX TRACES_MAX plot.c Rewrite CELLWIDTH and CELLHEIGHT use, now possible set any CELL width and height (CELLWIDTH * CELLHEIGHT <= spi_buffer size) Free RAM from shell stack use fore increase spi_buffer size now it have 2048 pixel (64x32) Rewrite cell index and markmap use (now correct use cell size, and more faster), correct use CELLWIDTH and CELLHEIGHT in calculation Fore set update area use invalidateRect (still need use some hardcoded values :( ) Rewrite cell_draw_line Rewrite many hardcoded size definitions Refrence point now draw as bitmap (less size, more costumable) Fix drag marker (now correct search closest index in search_nearest_index) Rewrite plot_into_index, now correct use size definitions, moe ui.c Small rewrite keyboard definitions, for use less flash size Define KP_WIDTH, KP_HEIGHT for set key size Better look some big font symvols All: use static fore some local functions (use less space on calls) replace tabs on spaces (code style) Use M_PI from math.h fore define pi value Fix printf on print HEX values
This commit is contained in:
parent
2381e338eb
commit
02a5715bb4
|
|
@ -64,7 +64,7 @@ static char *long_to_string_with_divisor(char *p,
|
||||||
do {
|
do {
|
||||||
uint8_t c = num % radix;
|
uint8_t c = num % radix;
|
||||||
num /= radix;
|
num /= radix;
|
||||||
*--q = c + ((c > 9) ? 'A' : '0');
|
*--q = c + ((c > 9) ? ('A'-10) : '0');
|
||||||
}while((precision && --precision) || num);
|
}while((precision && --precision) || num);
|
||||||
// copy string at begin
|
// copy string at begin
|
||||||
int i = (int)(b - q);
|
int i = (int)(b - q);
|
||||||
|
|
|
||||||
39
ili9341.c
39
ili9341.c
|
|
@ -21,7 +21,7 @@
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "nanovna.h"
|
#include "nanovna.h"
|
||||||
|
|
||||||
uint16_t spi_buffer[1024];
|
uint16_t spi_buffer[2048];
|
||||||
// Default foreground & background colors
|
// Default foreground & background colors
|
||||||
uint16_t foreground_color=DEFAULT_FG_COLOR;
|
uint16_t foreground_color=DEFAULT_FG_COLOR;
|
||||||
uint16_t background_color=DEFAULT_BG_COLOR;
|
uint16_t background_color=DEFAULT_BG_COLOR;
|
||||||
|
|
@ -568,10 +568,34 @@ void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size)
|
||||||
while (*str)
|
while (*str)
|
||||||
x += ili9341_drawchar_size(*str++, x, y, size);
|
x += ili9341_drawchar_size(*str++, x, y, size);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
static void ili9341_pixel(int x, int y, uint16_t color)
|
||||||
|
{
|
||||||
|
uint32_t xx = __REV16(x|((x)<<16));
|
||||||
|
uint32_t yy = __REV16(y|((y)<<16));
|
||||||
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
||||||
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
||||||
|
send_command(ILI9341_MEMORY_WRITE, 2, &color);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SWAP(x,y) { int z=x; x = y; y = z; }
|
#define SWAP(x,y) { int z=x; x = y; y = z; }
|
||||||
void ili9341_line(int x0, int y0, int x1, int y1)
|
void ili9341_line(int x0, int y0, int x1, int y1)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
|
// modifed Bresenham's line algorithm, see https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
||||||
|
int dx = x1 - x0, sx = 1; if (dx < 0) {dx = -dx; sx = -1;}
|
||||||
|
int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;}
|
||||||
|
int err = (dx > dy ? dx : -dy) / 2;
|
||||||
|
while (1){
|
||||||
|
ili9341_pixel(x0, y0, DEFAULT_FG_COLOR);
|
||||||
|
if (x0 == x1 && y0 == y1)
|
||||||
|
break;
|
||||||
|
int e2 = err;
|
||||||
|
if (e2 > -dx) { err -= dy; x0 += sx; }
|
||||||
|
if (e2 < dy) { err += dx; y0 += sy; }
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (x0 > x1) {
|
if (x0 > x1) {
|
||||||
SWAP(x0, x1);
|
SWAP(x0, x1);
|
||||||
|
|
@ -611,20 +635,8 @@ static const uint16_t colormap[] = {
|
||||||
RGBHEX(0x00ffff), RGBHEX(0xff00ff), RGBHEX(0xffff00)
|
RGBHEX(0x00ffff), RGBHEX(0xff00ff), RGBHEX(0xffff00)
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ili9341_pixel(int x, int y, int color)
|
|
||||||
{
|
|
||||||
uint8_t xx[4] = { x >> 8, x, (x+1) >> 8, (x+1) };
|
|
||||||
uint8_t yy[4] = { y >> 8, y, (y+1) >> 8, (y+1) };
|
|
||||||
uint8_t cc[2] = { color >> 8, color };
|
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx);
|
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy);
|
|
||||||
send_command(ILI9341_MEMORY_WRITE, 2, cc);
|
|
||||||
//send_command16(ILI9341_MEMORY_WRITE, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ili9341_test(int mode)
|
void ili9341_test(int mode)
|
||||||
{
|
{
|
||||||
chMtxLock(&mutex_ili9341);
|
|
||||||
int x, y;
|
int x, y;
|
||||||
int i;
|
int i;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|
@ -666,6 +678,5 @@ void ili9341_test(int mode)
|
||||||
ili9341_line(0, 100, 100, 0);
|
ili9341_line(0, 100, 100, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
chMtxUnlock(&mutex_ili9341);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
424
main.c
424
main.c
|
|
@ -26,13 +26,34 @@
|
||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
|
|
||||||
#include <chprintf.h>
|
#include <chprintf.h>
|
||||||
#include <shell.h>
|
//#include <stdlib.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
//#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Shell settings
|
||||||
|
*/
|
||||||
|
// If need run shell as thread (use more amount of memory fore stack), after enable this need reduce spi_buffer size, by default shell run in main thread
|
||||||
|
//#define VNA_SHELL_THREAD
|
||||||
|
|
||||||
|
static BaseSequentialStream *shell_stream = (BaseSequentialStream *)&SDU1;
|
||||||
|
|
||||||
|
// Shell new line
|
||||||
|
#define VNA_SHELL_NEWLINE_STR "\r\n"
|
||||||
|
// Shell command promt
|
||||||
|
#define VNA_SHELL_PROMPT_STR "ch> "
|
||||||
|
// Shell max arguments
|
||||||
|
#define VNA_SHELL_MAX_ARGUMENTS 4
|
||||||
|
// Shell max command line size
|
||||||
|
#define VNA_SHELL_MAX_LENGTH 64
|
||||||
|
// Shell command functions prototypes
|
||||||
|
typedef void (*vna_shellcmd_t)(BaseSequentialStream *chp, int argc, char *argv[]);
|
||||||
|
#define VNA_SHELL_FUNCTION(command_name) static void command_name(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
||||||
//#define ENABLED_DUMP
|
//#define ENABLED_DUMP
|
||||||
|
//#define ENABLE_THREADS_COMMAND
|
||||||
|
|
||||||
|
|
||||||
static void apply_error_term_at(int i);
|
static void apply_error_term_at(int i);
|
||||||
static void apply_edelay_at(int i);
|
static void apply_edelay_at(int i);
|
||||||
|
|
@ -124,7 +145,8 @@ toggle_sweep(void)
|
||||||
sweep_enabled = !sweep_enabled;
|
sweep_enabled = !sweep_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
float bessel0(float x) {
|
static float
|
||||||
|
bessel0(float x) {
|
||||||
const float eps = 0.0001;
|
const float eps = 0.0001;
|
||||||
|
|
||||||
float ret = 0;
|
float ret = 0;
|
||||||
|
|
@ -136,18 +158,17 @@ float bessel0(float x) {
|
||||||
++m;
|
++m;
|
||||||
term *= (x*x) / (4*m*m);
|
term *= (x*x) / (4*m*m);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
float kaiser_window(float k, float n, float beta) {
|
static float
|
||||||
|
kaiser_window(float k, float n, float beta) {
|
||||||
if (beta == 0.0) return 1.0;
|
if (beta == 0.0) return 1.0;
|
||||||
float r = (2 * k) / (n - 1) - 1;
|
float r = (2 * k) / (n - 1) - 1;
|
||||||
return bessel0(beta * sqrt(1 - r * r)) / bessel0(beta);
|
return bessel0(beta * sqrt(1 - r * r)) / bessel0(beta);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static void
|
||||||
void
|
|
||||||
transform_domain(void)
|
transform_domain(void)
|
||||||
{
|
{
|
||||||
if ((domain_mode & DOMAIN_MODE) != DOMAIN_TIME) return; // nothing to do for freq domain
|
if ((domain_mode & DOMAIN_MODE) != DOMAIN_TIME) return; // nothing to do for freq domain
|
||||||
|
|
@ -220,6 +241,16 @@ transform_domain(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shell commands output
|
||||||
|
static int shell_printf(BaseSequentialStream *chp, const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
int formatted_bytes;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
formatted_bytes = chvprintf(chp, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return formatted_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
static void cmd_pause(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_pause(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
(void)chp;
|
(void)chp;
|
||||||
|
|
@ -249,13 +280,13 @@ static void cmd_reset(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
if (strcmp(argv[0], "dfu") == 0) {
|
if (strcmp(argv[0], "dfu") == 0) {
|
||||||
chprintf(chp, "Performing reset to DFU mode\r\n");
|
shell_printf(chp, "Performing reset to DFU mode\r\n");
|
||||||
enter_dfu();
|
enter_dfu();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chprintf(chp, "Performing reset\r\n");
|
shell_printf(chp, "Performing reset\r\n");
|
||||||
|
|
||||||
rccEnableWWDG(FALSE);
|
rccEnableWWDG(FALSE);
|
||||||
|
|
||||||
|
|
@ -312,7 +343,7 @@ int set_frequency(uint32_t freq)
|
||||||
// Rewrite universal standart str to value functions to more compact
|
// Rewrite universal standart str to value functions to more compact
|
||||||
//
|
//
|
||||||
// Convert string to int32
|
// Convert string to int32
|
||||||
int32_t my_atoi(const char *p){
|
static int32_t my_atoi(const char *p){
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
uint32_t c;
|
uint32_t c;
|
||||||
bool neg = false;
|
bool neg = false;
|
||||||
|
|
@ -374,7 +405,7 @@ my_atof(const char *p)
|
||||||
static void cmd_offset(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_offset(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
chprintf(chp, "usage: offset {frequency offset(Hz)}\r\n");
|
shell_printf(chp, "usage: offset {frequency offset(Hz)}\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
frequency_offset = my_atoui(argv[0]);
|
frequency_offset = my_atoui(argv[0]);
|
||||||
|
|
@ -394,13 +425,13 @@ static void cmd_freq(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
return;
|
return;
|
||||||
usage:
|
usage:
|
||||||
chprintf(chp, "usage: freq {frequency(Hz)}\r\n");
|
shell_printf(chp, "usage: freq {frequency(Hz)}\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_power(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_power(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
chprintf(chp, "usage: power {0-3|-1}\r\n");
|
shell_printf(chp, "usage: power {0-3|-1}\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
drive_strength = my_atoi(argv[0]);
|
drive_strength = my_atoi(argv[0]);
|
||||||
|
|
@ -413,7 +444,7 @@ static void cmd_time(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
rtcGetTime(&RTCD1, ×pec);
|
rtcGetTime(&RTCD1, ×pec);
|
||||||
chprintf(chp, "%d/%d/%d %d\r\n", timespec.year+1980, timespec.month, timespec.day, timespec.millisecond);
|
shell_printf(chp, "%d/%d/%d %d\r\n", timespec.year+1980, timespec.month, timespec.day, timespec.millisecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -421,8 +452,8 @@ static void cmd_dac(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
chprintf(chp, "usage: dac {value(0-4095)}\r\n");
|
shell_printf(chp, "usage: dac {value(0-4095)}\r\n"\
|
||||||
chprintf(chp, "current value: %d\r\n", config.dac_value);
|
"current value: %d\r\n", config.dac_value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
value = my_atoi(argv[0]);
|
value = my_atoi(argv[0]);
|
||||||
|
|
@ -434,8 +465,8 @@ static void cmd_threshold(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
chprintf(chp, "usage: threshold {frequency in harmonic mode}\r\n");
|
shell_printf(chp, "usage: threshold {frequency in harmonic mode}\r\n"\
|
||||||
chprintf(chp, "current: %d\r\n", config.harmonic_freq_threshold);
|
"current: %d\r\n", config.harmonic_freq_threshold);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
value = my_atoui(argv[0]);
|
value = my_atoui(argv[0]);
|
||||||
|
|
@ -447,24 +478,24 @@ static void cmd_saveconfig(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
config_save();
|
config_save();
|
||||||
chprintf(chp, "Config saved.\r\n");
|
shell_printf(chp, "Config saved.\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_clearconfig(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_clearconfig(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
chprintf(chp, "usage: clearconfig {protection key}\r\n");
|
shell_printf(chp, "usage: clearconfig {protection key}\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(argv[0], "1234") != 0) {
|
if (strcmp(argv[0], "1234") != 0) {
|
||||||
chprintf(chp, "Key unmatched.\r\n");
|
shell_printf(chp, "Key unmatched.\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_all_config_prop_data();
|
clear_all_config_prop_data();
|
||||||
chprintf(chp, "Config and all cal data cleared.\r\n");
|
shell_printf(chp, "Config and all cal data cleared.\r\n"\
|
||||||
chprintf(chp, "Do reset manually to take effect. Then do touch cal and save.\r\n");
|
"Do reset manually to take effect. Then do touch cal and save.\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
|
@ -560,18 +591,18 @@ static void cmd_data(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
chMtxLock(&mutex);
|
chMtxLock(&mutex);
|
||||||
for (i = 0; i < sweep_points; i++) {
|
for (i = 0; i < sweep_points; i++) {
|
||||||
if (frequencies[i] != 0)
|
if (frequencies[i] != 0)
|
||||||
chprintf(chp, "%f %f\r\n", measured[sel][i][0], measured[sel][i][1]);
|
shell_printf(chp, "%f %f\r\n", measured[sel][i][0], measured[sel][i][1]);
|
||||||
}
|
}
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
} else if (sel >= 2 && sel < 7) {
|
} else if (sel >= 2 && sel < 7) {
|
||||||
chMtxLock(&mutex);
|
chMtxLock(&mutex);
|
||||||
for (i = 0; i < sweep_points; i++) {
|
for (i = 0; i < sweep_points; i++) {
|
||||||
if (frequencies[i] != 0)
|
if (frequencies[i] != 0)
|
||||||
chprintf(chp, "%f %f\r\n", cal_data[sel-2][i][0], cal_data[sel-2][i][1]);
|
shell_printf(chp, "%f %f\r\n", cal_data[sel-2][i][0], cal_data[sel-2][i][1]);
|
||||||
}
|
}
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
} else {
|
} else {
|
||||||
chprintf(chp, "usage: data [array]\r\n");
|
shell_printf(chp, "usage: data [array]\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -591,9 +622,9 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
len /= 2;
|
len /= 2;
|
||||||
for (i = 0; i < len; ) {
|
for (i = 0; i < len; ) {
|
||||||
for (j = 0; j < 16; j++, i++) {
|
for (j = 0; j < 16; j++, i++) {
|
||||||
chprintf(chp, "%04x ", 0xffff & (int)dump_buffer[i]);
|
shell_printf(chp, "%04x ", 0xffff & (int)dump_buffer[i]);
|
||||||
}
|
}
|
||||||
chprintf(chp, "\r\n");
|
shell_printf(chp, "\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -609,7 +640,7 @@ static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
|
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
|
||||||
for (int y=0; y < 240; y+=2)
|
for (int y=0; y < 240; y+=2)
|
||||||
{
|
{
|
||||||
// use uint16_t spi_buffer[1024] (defined in ili9341) for read buffer
|
// use uint16_t spi_buffer[2048] (defined in ili9341) for read buffer
|
||||||
uint8_t *buf = (uint8_t *)spi_buffer;
|
uint8_t *buf = (uint8_t *)spi_buffer;
|
||||||
ili9341_read_memory(0, y, 320, 2, 2*320, spi_buffer);
|
ili9341_read_memory(0, y, 320, 2, 2*320, spi_buffer);
|
||||||
for (int i = 0; i < 4*320; i++) {
|
for (int i = 0; i < 4*320; i++) {
|
||||||
|
|
@ -633,7 +664,7 @@ static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
calculate_gamma(gamma);
|
calculate_gamma(gamma);
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
|
|
||||||
chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]);
|
shell_printf(chp, "%d %d\r\n", gamma[0], gamma[1]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -653,7 +684,7 @@ static void cmd_sample(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chprintf(chp, "usage: sample {gamma|ampl|ref}\r\n");
|
shell_printf(chp, "usage: sample {gamma|ampl|ref}\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
config_t config = {
|
config_t config = {
|
||||||
|
|
@ -674,10 +705,10 @@ properties_t current_props = {
|
||||||
._frequency0 = 50000, // start = 50kHz
|
._frequency0 = 50000, // start = 50kHz
|
||||||
._frequency1 = 900000000, // end = 900MHz
|
._frequency1 = 900000000, // end = 900MHz
|
||||||
._sweep_points = POINTS_COUNT,
|
._sweep_points = POINTS_COUNT,
|
||||||
._trace = {/*enable, type, channel, polar, scale, refpos*/
|
._trace = {/*enable, type, channel, reserved, scale, refpos*/
|
||||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 9.0 },
|
{ 1, TRC_LOGMAG, 0, 0, 1.0, 9.0 },
|
||||||
{ 1, TRC_LOGMAG, 1, 0, 1.0, 9.0 },
|
{ 1, TRC_LOGMAG, 1, 0, 1.0, 9.0 },
|
||||||
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
|
{ 1, TRC_SMITH, 0, 0, 1.0, 0.0 },
|
||||||
{ 1, TRC_PHASE, 1, 0, 1.0, 5.0 }
|
{ 1, TRC_PHASE, 1, 0, 1.0, 5.0 }
|
||||||
},
|
},
|
||||||
._markers = {
|
._markers = {
|
||||||
|
|
@ -748,20 +779,20 @@ static void cmd_scan(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
int16_t points = sweep_points;
|
int16_t points = sweep_points;
|
||||||
|
|
||||||
if (argc != 2 && argc != 3) {
|
if (argc != 2 && argc != 3) {
|
||||||
chprintf(chp, "usage: scan {start(Hz)} {stop(Hz)} [points]\r\n");
|
shell_printf(chp, "usage: scan {start(Hz)} {stop(Hz)} [points]\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = my_atoui(argv[0]);
|
start = my_atoui(argv[0]);
|
||||||
stop = my_atoui(argv[1]);
|
stop = my_atoui(argv[1]);
|
||||||
if (start == 0 || stop == 0 || start > stop) {
|
if (start == 0 || stop == 0 || start > stop) {
|
||||||
chprintf(chp, "frequency range is invalid\r\n");
|
shell_printf(chp, "frequency range is invalid\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
points = my_atoi(argv[2]);
|
points = my_atoi(argv[2]);
|
||||||
if (points <= 0 || points > sweep_points) {
|
if (points <= 0 || points > sweep_points) {
|
||||||
chprintf(chp, "sweep points exceeds range\r\n");
|
shell_printf(chp, "sweep points exceeds range\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -785,7 +816,7 @@ update_marker_index(void)
|
||||||
{
|
{
|
||||||
int m;
|
int m;
|
||||||
int i;
|
int i;
|
||||||
for (m = 0; m < 4; m++) {
|
for (m = 0; m < MARKERS_MAX; m++) {
|
||||||
if (!markers[m].enabled)
|
if (!markers[m].enabled)
|
||||||
continue;
|
continue;
|
||||||
uint32_t f = markers[m].frequency;
|
uint32_t f = markers[m].frequency;
|
||||||
|
|
@ -854,7 +885,7 @@ update_frequencies(void)
|
||||||
update_grid();
|
update_grid();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
freq_mode_startstop(void)
|
freq_mode_startstop(void)
|
||||||
{
|
{
|
||||||
if (frequency0 > frequency1) {
|
if (frequency0 > frequency1) {
|
||||||
|
|
@ -865,7 +896,7 @@ freq_mode_startstop(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
freq_mode_centerspan(void)
|
freq_mode_centerspan(void)
|
||||||
{
|
{
|
||||||
if (frequency0 <= frequency1) {
|
if (frequency0 <= frequency1) {
|
||||||
|
|
@ -876,7 +907,6 @@ freq_mode_centerspan(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define START_MIN 50000
|
#define START_MIN 50000
|
||||||
#define STOP_MAX 2700000000U
|
#define STOP_MAX 2700000000U
|
||||||
|
|
||||||
|
|
@ -983,7 +1013,7 @@ get_sweep_frequency(int type)
|
||||||
static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
chprintf(chp, "%d %d %d\r\n", frequency0, frequency1, sweep_points);
|
shell_printf(chp, "%d %d %d\r\n", frequency0, frequency1, sweep_points);
|
||||||
return;
|
return;
|
||||||
} else if (argc > 3) {
|
} else if (argc > 3) {
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
@ -1018,8 +1048,8 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
set_sweep_frequency(ST_STOP, value1);
|
set_sweep_frequency(ST_STOP, value1);
|
||||||
return;
|
return;
|
||||||
usage:
|
usage:
|
||||||
chprintf(chp, "usage: sweep {start(Hz)} [stop(Hz)]\r\n");
|
shell_printf(chp, "usage: sweep {start(Hz)} [stop(Hz)]\r\n"\
|
||||||
chprintf(chp, "\tsweep {start|stop|center|span|cw} {freq(Hz)}\r\n");
|
"\tsweep {start|stop|center|span|cw} {freq(Hz)}\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1058,7 +1088,7 @@ adjust_ed(void)
|
||||||
// prepare 1/s11ao to avoid dividing complex
|
// prepare 1/s11ao to avoid dividing complex
|
||||||
float c = 1000e-15;
|
float c = 1000e-15;
|
||||||
float z0 = 50;
|
float z0 = 50;
|
||||||
//float z = 6.2832 * frequencies[i] * c * z0;
|
//float z = 2 * M_PI * frequencies[i] * c * z0;
|
||||||
float z = 0.02;
|
float z = 0.02;
|
||||||
cal_data[ETERM_ED][i][0] += z;
|
cal_data[ETERM_ED][i][0] += z;
|
||||||
}
|
}
|
||||||
|
|
@ -1076,7 +1106,7 @@ eterm_calc_es(void)
|
||||||
float c = 50e-15;
|
float c = 50e-15;
|
||||||
//float c = 1.707e-12;
|
//float c = 1.707e-12;
|
||||||
float z0 = 50;
|
float z0 = 50;
|
||||||
float z = 6.2832 * frequencies[i] * c * z0;
|
float z = 2 * M_PI * frequencies[i] * c * z0;
|
||||||
float sq = 1 + z*z;
|
float sq = 1 + z*z;
|
||||||
float s11aor = (1 - z*z) / sq;
|
float s11aor = (1 - z*z) / sq;
|
||||||
float s11aoi = 2*z / sq;
|
float s11aoi = 2*z / sq;
|
||||||
|
|
@ -1181,7 +1211,7 @@ void apply_error_term(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void apply_error_term_at(int i)
|
static void apply_error_term_at(int i)
|
||||||
{
|
{
|
||||||
// S11m' = S11m - Ed
|
// S11m' = S11m - Ed
|
||||||
// S11a = S11m' / (Er + Es S11m')
|
// S11a = S11m' / (Er + Es S11m')
|
||||||
|
|
@ -1298,7 +1328,7 @@ cal_done(void)
|
||||||
redraw_request |= REDRAW_CAL_STATUS;
|
redraw_request |= REDRAW_CAL_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
cal_interpolate(int s)
|
cal_interpolate(int s)
|
||||||
{
|
{
|
||||||
const properties_t *src = caldata_ref(s);
|
const properties_t *src = caldata_ref(s);
|
||||||
|
|
@ -1370,9 +1400,9 @@ static void cmd_cal(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
if (cal_status & (1<<i))
|
if (cal_status & (1<<i))
|
||||||
chprintf(chp, "%s ", items[i]);
|
shell_printf(chp, "%s ", items[i]);
|
||||||
}
|
}
|
||||||
chprintf(chp, "\r\n");
|
shell_printf(chp, "\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1403,11 +1433,11 @@ static void cmd_cal(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
redraw_request |= REDRAW_CAL_STATUS;
|
redraw_request |= REDRAW_CAL_STATUS;
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(cmd, "data") == 0) {
|
} else if (strcmp(cmd, "data") == 0) {
|
||||||
chprintf(chp, "%f %f\r\n", cal_data[CAL_LOAD][0][0], cal_data[CAL_LOAD][0][1]);
|
shell_printf(chp, "%f %f\r\n", cal_data[CAL_LOAD][0][0], cal_data[CAL_LOAD][0][1]);
|
||||||
chprintf(chp, "%f %f\r\n", cal_data[CAL_OPEN][0][0], cal_data[CAL_OPEN][0][1]);
|
shell_printf(chp, "%f %f\r\n", cal_data[CAL_OPEN][0][0], cal_data[CAL_OPEN][0][1]);
|
||||||
chprintf(chp, "%f %f\r\n", cal_data[CAL_SHORT][0][0], cal_data[CAL_SHORT][0][1]);
|
shell_printf(chp, "%f %f\r\n", cal_data[CAL_SHORT][0][0], cal_data[CAL_SHORT][0][1]);
|
||||||
chprintf(chp, "%f %f\r\n", cal_data[CAL_THRU][0][0], cal_data[CAL_THRU][0][1]);
|
shell_printf(chp, "%f %f\r\n", cal_data[CAL_THRU][0][0], cal_data[CAL_THRU][0][1]);
|
||||||
chprintf(chp, "%f %f\r\n", cal_data[CAL_ISOLN][0][0], cal_data[CAL_ISOLN][0][1]);
|
shell_printf(chp, "%f %f\r\n", cal_data[CAL_ISOLN][0][0], cal_data[CAL_ISOLN][0][1]);
|
||||||
return;
|
return;
|
||||||
} else if (strcmp(cmd, "in") == 0) {
|
} else if (strcmp(cmd, "in") == 0) {
|
||||||
int s = 0;
|
int s = 0;
|
||||||
|
|
@ -1417,7 +1447,7 @@ static void cmd_cal(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
redraw_request |= REDRAW_CAL_STATUS;
|
redraw_request |= REDRAW_CAL_STATUS;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
chprintf(chp, "usage: cal [load|open|short|thru|isoln|done|reset|on|off|in]\r\n");
|
shell_printf(chp, "usage: cal [load|open|short|thru|isoln|done|reset|on|off|in]\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1437,7 +1467,7 @@ static void cmd_save(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
chprintf(chp, "save {id}\r\n");
|
shell_printf(chp, "save {id}\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
@ -1462,10 +1492,10 @@ static void cmd_recall(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
chprintf(chp, "recall {id}\r\n");
|
shell_printf(chp, "recall {id}\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct {
|
static const struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
uint16_t refpos;
|
uint16_t refpos;
|
||||||
float scale_unit;
|
float scale_unit;
|
||||||
|
|
@ -1487,22 +1517,16 @@ const char * const trc_channel_name[] = {
|
||||||
"CH0", "CH1"
|
"CH0", "CH1"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *
|
const char *get_trace_typename(int t)
|
||||||
get_trace_typename(int t)
|
|
||||||
{
|
{
|
||||||
return trace_info[trace[t].type].name;
|
return trace_info[trace[t].type].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_trace_type(int t, int type)
|
void set_trace_type(int t, int type)
|
||||||
{
|
{
|
||||||
int polar = type == TRC_SMITH || type == TRC_POLAR;
|
|
||||||
int enabled = type != TRC_OFF;
|
int enabled = type != TRC_OFF;
|
||||||
int force = FALSE;
|
int force = FALSE;
|
||||||
|
|
||||||
if (trace[t].polar != polar) {
|
|
||||||
trace[t].polar = polar;
|
|
||||||
force = TRUE;
|
|
||||||
}
|
|
||||||
if (trace[t].enabled != enabled) {
|
if (trace[t].enabled != enabled) {
|
||||||
trace[t].enabled = enabled;
|
trace[t].enabled = enabled;
|
||||||
force = TRUE;
|
force = TRUE;
|
||||||
|
|
@ -1510,7 +1534,6 @@ void set_trace_type(int t, int type)
|
||||||
if (trace[t].type != type) {
|
if (trace[t].type != type) {
|
||||||
trace[t].type = type;
|
trace[t].type = type;
|
||||||
trace[t].refpos = trace_info[type].refpos;
|
trace[t].refpos = trace_info[type].refpos;
|
||||||
if (polar)
|
|
||||||
force = TRUE;
|
force = TRUE;
|
||||||
}
|
}
|
||||||
if (force) {
|
if (force) {
|
||||||
|
|
@ -1529,7 +1552,7 @@ void set_trace_channel(int t, int channel)
|
||||||
|
|
||||||
void set_trace_scale(int t, float scale)
|
void set_trace_scale(int t, float scale)
|
||||||
{
|
{
|
||||||
scale /= trace_info[trace[t].type].scale_unit;
|
// scale /= trace_info[trace[t].type].scale_unit;
|
||||||
if (trace[t].scale != scale) {
|
if (trace[t].scale != scale) {
|
||||||
trace[t].scale = scale;
|
trace[t].scale = scale;
|
||||||
force_set_markmap();
|
force_set_markmap();
|
||||||
|
|
@ -1538,7 +1561,7 @@ void set_trace_scale(int t, float scale)
|
||||||
|
|
||||||
float get_trace_scale(int t)
|
float get_trace_scale(int t)
|
||||||
{
|
{
|
||||||
return trace[t].scale * trace_info[trace[t].type].scale_unit;
|
return trace[t].scale;// * trace_info[trace[t].type].scale_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_trace_refpos(int t, float refpos)
|
void set_trace_refpos(int t, float refpos)
|
||||||
|
|
@ -1563,13 +1586,13 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
for (t = 0; t < 4; t++) {
|
for (t = 0; t < TRACES_MAX; t++) {
|
||||||
if (trace[t].enabled) {
|
if (trace[t].enabled) {
|
||||||
const char *type = trace_info[trace[t].type].name;
|
const char *type = trace_info[trace[t].type].name;
|
||||||
const char *channel = trc_channel_name[trace[t].channel];
|
const char *channel = trc_channel_name[trace[t].channel];
|
||||||
float scale = get_trace_scale(t);
|
float scale = get_trace_scale(t);
|
||||||
float refpos = get_trace_refpos(t);
|
float refpos = get_trace_refpos(t);
|
||||||
chprintf(chp, "%d %s %s %f %f\r\n", t, type, channel, scale, refpos);
|
shell_printf(chp, "%d %s %s %f %f\r\n", t, type, channel, scale, refpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -1577,30 +1600,26 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
||||||
if (strcmp(argv[0], "all") == 0 &&
|
if (strcmp(argv[0], "all") == 0 &&
|
||||||
argc > 1 && strcmp(argv[1], "off") == 0) {
|
argc > 1 && strcmp(argv[1], "off") == 0) {
|
||||||
set_trace_type(0, TRC_OFF);
|
for (t = 0; t < TRACES_MAX; t++)
|
||||||
set_trace_type(1, TRC_OFF);
|
set_trace_type(t, TRC_OFF);
|
||||||
set_trace_type(2, TRC_OFF);
|
|
||||||
set_trace_type(3, TRC_OFF);
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = my_atoi(argv[0]);
|
t = my_atoi(argv[0]);
|
||||||
if (t < 0 || t >= 4)
|
if (t < 0 || t >= TRACES_MAX)
|
||||||
goto usage;
|
goto usage;
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
const char *type = get_trace_typename(t);
|
const char *type = get_trace_typename(t);
|
||||||
const char *channel = trc_channel_name[trace[t].channel];
|
const char *channel = trc_channel_name[trace[t].channel];
|
||||||
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
shell_printf(chp, "%d %s %s\r\n", t, type, channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 1) {
|
|
||||||
static const type_list t_list[] = {
|
static const type_list t_list[] = {
|
||||||
{"logmag", TRC_LOGMAG},
|
{"logmag", TRC_LOGMAG},
|
||||||
{"phase", TRC_PHASE},
|
{"phase", TRC_PHASE},
|
||||||
{"polar", TRC_POLAR},
|
|
||||||
{"smith", TRC_SMITH},
|
|
||||||
{"delay", TRC_DELAY},
|
{"delay", TRC_DELAY},
|
||||||
|
{"smith", TRC_SMITH},
|
||||||
|
{"polar", TRC_POLAR},
|
||||||
{"linear", TRC_LINEAR},
|
{"linear", TRC_LINEAR},
|
||||||
{"swr", TRC_SWR},
|
{"swr", TRC_SWR},
|
||||||
{"real", TRC_REAL},
|
{"real", TRC_REAL},
|
||||||
|
|
@ -1626,7 +1645,7 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
check_ch_num:
|
check_ch_num:
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
int src = my_atoi(argv[2]);
|
int src = my_atoi(argv[2]);
|
||||||
|
|
@ -1637,8 +1656,8 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
exit:
|
exit:
|
||||||
return;
|
return;
|
||||||
usage:
|
usage:
|
||||||
chprintf(chp, "trace {0|1|2|3|all} [logmag|phase|polar|smith|linear|delay|swr|real|imag|r|x|off] [src]\r\n");
|
shell_printf(chp, "trace {0|1|2|3|all} [logmag|phase|polar|smith|linear|delay|swr|real|imag|r|x|off] [src]\r\n"\
|
||||||
chprintf(chp, "trace {0|1|2|3} {scale|refpos} {value}\r\n");
|
"trace {0|1|2|3} {scale|refpos} {value}\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1658,7 +1677,7 @@ float get_electrical_delay(void)
|
||||||
static void cmd_edelay(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_edelay(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
chprintf(chp, "%f\r\n", electrical_delay);
|
shell_printf(chp, "%f\r\n", electrical_delay);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
|
|
@ -1671,26 +1690,26 @@ static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
for (t = 0; t < 4; t++) {
|
for (t = 0; t < MARKERS_MAX; t++) {
|
||||||
if (markers[t].enabled) {
|
if (markers[t].enabled) {
|
||||||
chprintf(chp, "%d %d %d\r\n", t+1, markers[t].index, markers[t].frequency);
|
shell_printf(chp, "%d %d %d\r\n", t+1, markers[t].index, markers[t].frequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "off") == 0) {
|
if (strcmp(argv[0], "off") == 0) {
|
||||||
active_marker = -1;
|
active_marker = -1;
|
||||||
for (t = 0; t < 4; t++)
|
for (t = 0; t < MARKERS_MAX; t++)
|
||||||
markers[t].enabled = FALSE;
|
markers[t].enabled = FALSE;
|
||||||
redraw_request |= REDRAW_MARKER;
|
redraw_request |= REDRAW_MARKER;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = my_atoi(argv[0])-1;
|
t = my_atoi(argv[0])-1;
|
||||||
if (t < 0 || t >= 4)
|
if (t < 0 || t >= MARKERS_MAX)
|
||||||
goto usage;
|
goto usage;
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
chprintf(chp, "%d %d %d\r\n", t+1, markers[t].index, frequency);
|
shell_printf(chp, "%d %d %d\r\n", t+1, markers[t].index, frequency);
|
||||||
active_marker = t;
|
active_marker = t;
|
||||||
// select active marker
|
// select active marker
|
||||||
markers[t].enabled = TRUE;
|
markers[t].enabled = TRUE;
|
||||||
|
|
@ -1719,7 +1738,7 @@ static void cmd_marker(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
usage:
|
usage:
|
||||||
chprintf(chp, "marker [n] [off|{index}]\r\n");
|
shell_printf(chp, "marker [n] [off|{index}]\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_touchcal(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_touchcal(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
@ -1730,15 +1749,15 @@ static void cmd_touchcal(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
chMtxLock(&mutex);
|
chMtxLock(&mutex);
|
||||||
chprintf(chp, "first touch upper left, then lower right...");
|
shell_printf(chp, "first touch upper left, then lower right...");
|
||||||
touch_cal_exec();
|
touch_cal_exec();
|
||||||
chprintf(chp, "done\r\n");
|
shell_printf(chp, "done\r\n");
|
||||||
|
|
||||||
chprintf(chp, "touch cal params: ");
|
shell_printf(chp, "touch cal params: ");
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
chprintf(chp, "%d ", config.touch_cal[i]);
|
shell_printf(chp, "%d ", config.touch_cal[i]);
|
||||||
}
|
}
|
||||||
chprintf(chp, "\r\n");
|
shell_printf(chp, "\r\n");
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1763,7 +1782,7 @@ static void cmd_frequencies(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
(void)argv;
|
(void)argv;
|
||||||
for (i = 0; i < sweep_points; i++) {
|
for (i = 0; i < sweep_points; i++) {
|
||||||
if (frequencies[i] != 0)
|
if (frequencies[i] != 0)
|
||||||
chprintf(chp, "%d\r\n", frequencies[i]);
|
shell_printf(chp, "%d\r\n", frequencies[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1821,7 +1840,7 @@ static void cmd_transform(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
chprintf(chp, "usage: transform {on|off|impulse|step|bandpass|minimum|normal|maximum} [...]\r\n");
|
shell_printf(chp, "usage: transform {on|off|impulse|step|bandpass|minimum|normal|maximum} [...]\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
@ -1861,22 +1880,22 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//extern adcsample_t adc_samples[2];
|
//extern adcsample_t adc_samples[2];
|
||||||
//chprintf(chp, "adc: %d %d\r\n", adc_samples[0], adc_samples[1]);
|
//shell_printf(chp, "adc: %d %d\r\n", adc_samples[0], adc_samples[1]);
|
||||||
int i;
|
int i;
|
||||||
int x, y;
|
int x, y;
|
||||||
for (i = 0; i < 50; i++) {
|
for (i = 0; i < 50; i++) {
|
||||||
test_touch(&x, &y);
|
test_touch(&x, &y);
|
||||||
chprintf(chp, "adc: %d %d\r\n", x, y);
|
shell_printf(chp, "adc: %d %d\r\n", x, y);
|
||||||
chThdSleepMilliseconds(200);
|
chThdSleepMilliseconds(200);
|
||||||
}
|
}
|
||||||
//extern int touch_x, touch_y;
|
//extern int touch_x, touch_y;
|
||||||
//chprintf(chp, "adc: %d %d\r\n", touch_x, touch_y);
|
//shell_printf(chp, "adc: %d %d\r\n", touch_x, touch_y);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (argc > 1) {
|
while (argc > 1) {
|
||||||
int x, y;
|
int x, y;
|
||||||
touch_position(&x, &y);
|
touch_position(&x, &y);
|
||||||
chprintf(chp, "touch: %d %d\r\n", x, y);
|
shell_printf(chp, "touch: %d %d\r\n", x, y);
|
||||||
chThdSleepMilliseconds(200);
|
chThdSleepMilliseconds(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1886,7 +1905,7 @@ static void cmd_gain(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
int rvalue;
|
int rvalue;
|
||||||
int lvalue = 0;
|
int lvalue = 0;
|
||||||
if (argc != 1 && argc != 2) {
|
if (argc != 1 && argc != 2) {
|
||||||
chprintf(chp, "usage: gain {lgain(0-95)} [rgain(0-95)]\r\n");
|
shell_printf(chp, "usage: gain {lgain(0-95)} [rgain(0-95)]\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rvalue = my_atoi(argv[0]);
|
rvalue = my_atoi(argv[0]);
|
||||||
|
|
@ -1899,7 +1918,7 @@ static void cmd_port(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int port;
|
int port;
|
||||||
if (argc != 1) {
|
if (argc != 1) {
|
||||||
chprintf(chp, "usage: port {0:TX 1:RX}\r\n");
|
shell_printf(chp, "usage: port {0:TX 1:RX}\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
port = my_atoi(argv[0]);
|
port = my_atoi(argv[0]);
|
||||||
|
|
@ -1932,14 +1951,14 @@ static void cmd_stat(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
stat.ave[0] = ave0;
|
stat.ave[0] = ave0;
|
||||||
stat.ave[1] = ave1;
|
stat.ave[1] = ave1;
|
||||||
|
|
||||||
chprintf(chp, "average: %d %d\r\n", stat.ave[0], stat.ave[1]);
|
shell_printf(chp, "average: %d %d\r\n", stat.ave[0], stat.ave[1]);
|
||||||
chprintf(chp, "rms: %d %d\r\n", stat.rms[0], stat.rms[1]);
|
shell_printf(chp, "rms: %d %d\r\n", stat.rms[0], stat.rms[1]);
|
||||||
chprintf(chp, "callback count: %d\r\n", stat.callback_count);
|
shell_printf(chp, "callback count: %d\r\n", stat.callback_count);
|
||||||
//chprintf(chp, "interval cycle: %d\r\n", stat.interval_cycles);
|
//shell_printf(chp, "interval cycle: %d\r\n", stat.interval_cycles);
|
||||||
//chprintf(chp, "busy cycle: %d\r\n", stat.busy_cycles);
|
//shell_printf(chp, "busy cycle: %d\r\n", stat.busy_cycles);
|
||||||
//chprintf(chp, "load: %d\r\n", stat.busy_cycles * 100 / stat.interval_cycles);
|
//shell_printf(chp, "load: %d\r\n", stat.busy_cycles * 100 / stat.interval_cycles);
|
||||||
extern int awd_count;
|
extern int awd_count;
|
||||||
chprintf(chp, "awd: %d\r\n", awd_count);
|
shell_printf(chp, "awd: %d\r\n", awd_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1953,19 +1972,50 @@ static void cmd_version(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
chprintf(chp, "%s\r\n", NANOVNA_VERSION);
|
shell_printf(chp, "%s\r\n", NANOVNA_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_vbat(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_vbat(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
chprintf(chp, "%d mV\r\n", vbat);
|
shell_printf(chp, "%d mV\r\n", vbat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static THD_WORKING_AREA(waThread2, /* cmd_* max stack size + alpha */442);
|
#ifdef ENABLE_THREADS_COMMAND
|
||||||
|
#if CH_CFG_USE_REGISTRY == FALSE
|
||||||
|
#error "Threads Requite enabled CH_CFG_USE_REGISTRY in chconf.h"
|
||||||
|
#endif
|
||||||
|
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
|
static const char *states[] = {CH_STATE_NAMES};
|
||||||
|
thread_t *tp;
|
||||||
|
|
||||||
static const ShellCommand commands[] =
|
(void)argv;
|
||||||
|
if (argc > 0) {
|
||||||
|
shellUsage(chp, "threads");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chprintf(chp, "stklimit stack addr refs prio state name\r\n"SHELL_NEWLINE_STR);
|
||||||
|
tp = chRegFirstThread();
|
||||||
|
do {
|
||||||
|
uint32_t stklimit = (uint32_t)tp->wabase;
|
||||||
|
shell_printf(chp, "%08x %08x %08x %4u %4u %9s %12s"SHELL_NEWLINE_STR,
|
||||||
|
stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp,
|
||||||
|
(uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state],
|
||||||
|
tp->name == NULL ? "" : tp->name);
|
||||||
|
tp = chRegNextThread(tp);
|
||||||
|
} while (tp != NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
static void cmd_help(BaseSequentialStream *chp, int argc, char *argv[]);
|
||||||
|
typedef struct {
|
||||||
|
const char *sc_name;
|
||||||
|
vna_shellcmd_t sc_function;
|
||||||
|
} VNAShellCommand;
|
||||||
|
|
||||||
|
static const VNAShellCommand commands[] =
|
||||||
{
|
{
|
||||||
{ "version" , cmd_version },
|
{ "version" , cmd_version },
|
||||||
{ "reset" , cmd_reset },
|
{ "reset" , cmd_reset },
|
||||||
|
|
@ -2003,14 +2053,126 @@ static const ShellCommand commands[] =
|
||||||
{ "vbat" , cmd_vbat },
|
{ "vbat" , cmd_vbat },
|
||||||
{ "transform" , cmd_transform },
|
{ "transform" , cmd_transform },
|
||||||
{ "threshold" , cmd_threshold },
|
{ "threshold" , cmd_threshold },
|
||||||
|
{ "help" , cmd_help },
|
||||||
|
#ifdef ENABLE_THREADS_COMMAND
|
||||||
|
// { "threads" , cmd_threads },
|
||||||
|
#endif
|
||||||
{ NULL , NULL }
|
{ NULL , NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static const ShellConfig shell_cfg1 =
|
static void cmd_help(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
(BaseSequentialStream *)&SDU1,
|
(void)argc;
|
||||||
commands
|
(void)argv;
|
||||||
};
|
const VNAShellCommand *scp = commands;
|
||||||
|
shell_printf(chp, "Commands:");
|
||||||
|
while (scp->sc_name != NULL) {
|
||||||
|
shell_printf(chp, " %s", scp->sc_name);
|
||||||
|
scp++;
|
||||||
|
}
|
||||||
|
shell_printf(chp, VNA_SHELL_NEWLINE_STR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* VNA shell functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// Read command line from shell_stream
|
||||||
|
//
|
||||||
|
static int VNAShell_readLine(char *line, int max_size){
|
||||||
|
// Read line from input stream
|
||||||
|
uint8_t c;
|
||||||
|
char *ptr = line;
|
||||||
|
while (1){
|
||||||
|
// Return 0 only if stream not active
|
||||||
|
if (streamRead(shell_stream, &c, 1) == 0)
|
||||||
|
return 0;
|
||||||
|
// Backspace
|
||||||
|
if (c == 8) {
|
||||||
|
if (ptr != line) {
|
||||||
|
static const char backspace[] = {0x08,0x20,0x08,0x00};
|
||||||
|
shell_printf(shell_stream, backspace);
|
||||||
|
ptr--;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// New line (Enter)
|
||||||
|
if (c == '\r') {
|
||||||
|
shell_printf(shell_stream, VNA_SHELL_NEWLINE_STR);
|
||||||
|
*ptr = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
// Others (skip)
|
||||||
|
if (c < 0x20)
|
||||||
|
continue;
|
||||||
|
// Store
|
||||||
|
if (ptr < line + max_size - 1) {
|
||||||
|
streamPut(shell_stream, c); // Echo
|
||||||
|
*ptr++ = (char)c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Parse and run command line
|
||||||
|
//
|
||||||
|
static void VNAShell_executeLine(char *line){
|
||||||
|
// Parse and execute line
|
||||||
|
char *args[VNA_SHELL_MAX_ARGUMENTS + 1];
|
||||||
|
int n = 0;
|
||||||
|
char *lp = line, *ep;
|
||||||
|
while (*lp!=0){
|
||||||
|
// Skipping white space and tabs at string begin.
|
||||||
|
while (*lp==' ' || *lp=='\t') lp++;
|
||||||
|
// If an argument starts with a double quote then its delimiter is another quote, else delimiter is white space.
|
||||||
|
ep = (*lp == '"') ? strpbrk(++lp, "\"") : strpbrk( lp, " \t");
|
||||||
|
// Store in args string
|
||||||
|
args[n++]=lp;
|
||||||
|
// Stop, end of input string
|
||||||
|
if ((lp = ep) == NULL)
|
||||||
|
break;
|
||||||
|
// Argument limits check
|
||||||
|
if (n > VNA_SHELL_MAX_ARGUMENTS) {
|
||||||
|
shell_printf(shell_stream, "too many arguments, max 4"VNA_SHELL_NEWLINE_STR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Set zero at the end of string and continue check
|
||||||
|
*lp++ = 0;
|
||||||
|
}
|
||||||
|
if (n == 0)
|
||||||
|
return;
|
||||||
|
// Execute line
|
||||||
|
const VNAShellCommand *scp;
|
||||||
|
for (scp = commands; scp->sc_name!=NULL;scp++) {
|
||||||
|
if (strcmp(scp->sc_name, args[0]) == 0) {
|
||||||
|
// chMtxLock(&mutex);
|
||||||
|
scp->sc_function(shell_stream, n-1, &args[1]);
|
||||||
|
// chMtxUnlock(&mutex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shell_printf(shell_stream, "%s?"VNA_SHELL_NEWLINE_STR, args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef VNA_SHELL_THREAD
|
||||||
|
static THD_WORKING_AREA(waThread2, /* cmd_* max stack size + alpha */442);
|
||||||
|
THD_FUNCTION(myshellThread, p) {
|
||||||
|
(void)p;
|
||||||
|
chRegSetThreadName("shell");
|
||||||
|
char line[VNA_SHELL_MAX_LENGTH];
|
||||||
|
shell_printf(shell_stream, VNA_SHELL_NEWLINE_STR"NanoVNA Shell"VNA_SHELL_NEWLINE_STR);
|
||||||
|
while (true) {
|
||||||
|
shell_printf(shell_stream, VNA_SHELL_PROMPT_STR);
|
||||||
|
if (VNAShell_readLine(line, VNA_SHELL_MAX_LENGTH))
|
||||||
|
VNAShell_executeLine(line);
|
||||||
|
else // Putting a delay in order to avoid an endless loop trying to read an unavailable stream.
|
||||||
|
osalThreadSleepMilliseconds(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static const I2CConfig i2ccfg = {
|
static const I2CConfig i2ccfg = {
|
||||||
0x00300506, //voodoo magic 400kHz @ HSI 8MHz
|
0x00300506, //voodoo magic 400kHz @ HSI 8MHz
|
||||||
|
|
@ -2094,21 +2256,27 @@ int main(void)
|
||||||
|
|
||||||
ui_init();
|
ui_init();
|
||||||
|
|
||||||
/*
|
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL);
|
||||||
* Shell manager initialization.
|
|
||||||
*/
|
|
||||||
shellInit();
|
|
||||||
|
|
||||||
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (SDU1.config->usbp->state == USB_ACTIVE) {
|
if (SDU1.config->usbp->state == USB_ACTIVE) {
|
||||||
|
#ifdef VNA_SHELL_THREAD
|
||||||
thread_t *shelltp = chThdCreateStatic(waThread2, sizeof(waThread2),
|
thread_t *shelltp = chThdCreateStatic(waThread2, sizeof(waThread2),
|
||||||
NORMALPRIO + 1,
|
NORMALPRIO + 1,
|
||||||
shellThread, (void *)&shell_cfg1);
|
myshellThread, NULL);
|
||||||
chThdWait(shelltp); /* Waiting termination. */
|
chThdWait(shelltp);
|
||||||
|
#else
|
||||||
|
char line[VNA_SHELL_MAX_LENGTH];
|
||||||
|
shell_printf(shell_stream, VNA_SHELL_NEWLINE_STR"NanoVNA Shell"VNA_SHELL_NEWLINE_STR);
|
||||||
|
do {
|
||||||
|
shell_printf(shell_stream, VNA_SHELL_PROMPT_STR);
|
||||||
|
if (VNAShell_readLine(line, VNA_SHELL_MAX_LENGTH))
|
||||||
|
VNAShell_executeLine(line);
|
||||||
|
else
|
||||||
|
chThdSleepMilliseconds(200);
|
||||||
|
} while (SDU1.config->usbp->state == USB_ACTIVE);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
chThdSleepMilliseconds(1000);
|
chThdSleepMilliseconds(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
nanovna.h
37
nanovna.h
|
|
@ -126,30 +126,35 @@ extern void tlv320aic3204_init(void);
|
||||||
extern void tlv320aic3204_set_gain(int lgain, int rgain);
|
extern void tlv320aic3204_set_gain(int lgain, int rgain);
|
||||||
extern void tlv320aic3204_select(int channel);
|
extern void tlv320aic3204_select(int channel);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* plot.c
|
* plot.c
|
||||||
*/
|
*/
|
||||||
#define OFFSETX 15
|
// GRIDX calculated depends from frequency span
|
||||||
|
#define GRIDY 23
|
||||||
|
|
||||||
|
// Offset of plot area
|
||||||
|
#define OFFSETX 10
|
||||||
#define OFFSETY 0
|
#define OFFSETY 0
|
||||||
#define WIDTH 291
|
|
||||||
|
// WIDTH better be n*(POINTS_COUNT-1)
|
||||||
|
#define WIDTH 300
|
||||||
|
// HEIGHT = 10*GRIDY
|
||||||
#define HEIGHT 230
|
#define HEIGHT 230
|
||||||
|
|
||||||
// Smith/polar chart
|
//
|
||||||
#define P_CENTER_X 145
|
|
||||||
#define P_CENTER_Y 115
|
|
||||||
#define P_RADIUS 115
|
|
||||||
|
|
||||||
#define CELLOFFSETX 5
|
#define CELLOFFSETX 5
|
||||||
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
|
#define AREA_WIDTH_NORMAL (CELLOFFSETX + WIDTH + 1 + 4)
|
||||||
|
#define AREA_HEIGHT_NORMAL ( HEIGHT + 1)
|
||||||
|
|
||||||
|
// Smith/polar chart
|
||||||
|
#define P_CENTER_X (CELLOFFSETX + WIDTH/2)
|
||||||
|
#define P_CENTER_Y (HEIGHT/2)
|
||||||
|
#define P_RADIUS (HEIGHT/2)
|
||||||
|
|
||||||
extern int16_t area_width;
|
extern int16_t area_width;
|
||||||
extern int16_t area_height;
|
extern int16_t area_height;
|
||||||
|
|
||||||
#define GRIDY 23
|
|
||||||
|
|
||||||
// font
|
// font
|
||||||
|
|
||||||
extern const uint8_t x5x7_bits [];
|
extern const uint8_t x5x7_bits [];
|
||||||
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
||||||
#define FONT_GET_WIDTH(ch) (8-(x5x7_bits[ch*7]&7))
|
#define FONT_GET_WIDTH(ch) (8-(x5x7_bits[ch*7]&7))
|
||||||
|
|
@ -176,6 +181,8 @@ extern const uint16_t numfont16x22[];
|
||||||
enum {
|
enum {
|
||||||
TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
|
TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
|
||||||
};
|
};
|
||||||
|
// Mask for define rectangular plot
|
||||||
|
#define RECTANGULAR_GRID_MASK ((1<<TRC_LOGMAG)|(1<<TRC_PHASE)|(1<<TRC_DELAY)|(1<<TRC_LINEAR)|(1<<TRC_SWR)|(1<<TRC_REAL)|(1<<TRC_IMAG)|(1<<TRC_R)|(1<<TRC_X))
|
||||||
|
|
||||||
// LOGMAG: SCALE, REFPOS, REFVAL
|
// LOGMAG: SCALE, REFPOS, REFVAL
|
||||||
// PHASE: SCALE, REFPOS, REFVAL
|
// PHASE: SCALE, REFPOS, REFVAL
|
||||||
|
|
@ -191,7 +198,7 @@ typedef struct {
|
||||||
uint8_t enabled;
|
uint8_t enabled;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t channel;
|
uint8_t channel;
|
||||||
uint8_t polar;
|
uint8_t reserved;
|
||||||
float scale;
|
float scale;
|
||||||
float refpos;
|
float refpos;
|
||||||
} trace_t;
|
} trace_t;
|
||||||
|
|
@ -256,7 +263,7 @@ void draw_all(bool flush);
|
||||||
|
|
||||||
void draw_cal_status(void);
|
void draw_cal_status(void);
|
||||||
|
|
||||||
void markmap_all_markers(void);
|
//void markmap_all_markers(void);
|
||||||
|
|
||||||
void marker_position(int m, int t, int *x, int *y);
|
void marker_position(int m, int t, int *x, int *y);
|
||||||
int search_nearest_index(int x, int y, int t);
|
int search_nearest_index(int x, int y, int t);
|
||||||
|
|
@ -299,7 +306,7 @@ extern int16_t vbat;
|
||||||
extern uint16_t foreground_color;
|
extern uint16_t foreground_color;
|
||||||
extern uint16_t background_color;
|
extern uint16_t background_color;
|
||||||
|
|
||||||
extern uint16_t spi_buffer[1024];
|
extern uint16_t spi_buffer[2048];
|
||||||
|
|
||||||
void ili9341_init(void);
|
void ili9341_init(void);
|
||||||
//void ili9341_setRotation(uint8_t r);
|
//void ili9341_setRotation(uint8_t r);
|
||||||
|
|
|
||||||
|
|
@ -271,10 +271,10 @@ const uint16_t numfont16x22[] = {
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000011100000000,
|
0b0000001110000000,
|
||||||
0b0000111110000000,
|
0b0000011111000000,
|
||||||
0b0000111110000000,
|
0b0000011111000000,
|
||||||
0b0000011100000000,
|
0b0000001110000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
|
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
|
|
@ -300,9 +300,6 @@ const uint16_t numfont16x22[] = {
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000011,
|
0b0000000000000011,
|
||||||
0b0000000000000111,
|
0b0000000000000111,
|
||||||
0b0000000000001111,
|
0b0000000000001111,
|
||||||
|
|
@ -322,6 +319,9 @@ const uint16_t numfont16x22[] = {
|
||||||
0b0111101111001111,
|
0b0111101111001111,
|
||||||
0b1111000111101111,
|
0b1111000111101111,
|
||||||
0b0110000011001111,
|
0b0110000011001111,
|
||||||
|
0b0000000000001111,
|
||||||
|
0b0000000000001111,
|
||||||
|
0b0000000000001111,
|
||||||
|
|
||||||
0b1111000000000000,
|
0b1111000000000000,
|
||||||
0b1111000000000000,
|
0b1111000000000000,
|
||||||
|
|
@ -358,8 +358,6 @@ const uint16_t numfont16x22[] = {
|
||||||
0b1111111111111111,
|
0b1111111111111111,
|
||||||
0b1111111111111111,
|
0b1111111111111111,
|
||||||
0b1111111111111111,
|
0b1111111111111111,
|
||||||
0b1111111111111111,
|
|
||||||
0b1111111111111111,
|
|
||||||
0b1111011111101111,
|
0b1111011111101111,
|
||||||
0b1111011111101111,
|
0b1111011111101111,
|
||||||
0b1111001111001111,
|
0b1111001111001111,
|
||||||
|
|
@ -368,6 +366,8 @@ const uint16_t numfont16x22[] = {
|
||||||
0b1111000110001111,
|
0b1111000110001111,
|
||||||
0b1111000000001111,
|
0b1111000000001111,
|
||||||
0b1111000000001111,
|
0b1111000000001111,
|
||||||
|
0b1111000000001111,
|
||||||
|
0b1111000000001111,
|
||||||
|
|
||||||
0b0000111111110000,
|
0b0000111111110000,
|
||||||
0b0011111111111100,
|
0b0011111111111100,
|
||||||
|
|
@ -420,28 +420,24 @@ const uint16_t numfont16x22[] = {
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000111000111000,
|
0b0001111000111100,
|
||||||
0b0001111101111100,
|
0b0011111101111110,
|
||||||
0b0011111111111110,
|
0b0111001111100110,
|
||||||
0b0111001111001110,
|
0b0110000111000011,
|
||||||
0b1110000110000111,
|
0b1110000111000011,
|
||||||
0b1110000110000111,
|
0b1100000110000011,
|
||||||
0b1110000110000111,
|
0b1100000110000011,
|
||||||
0b1110000110000111,
|
0b1100000110000011,
|
||||||
0b1110000110000111,
|
0b1100000110000011,
|
||||||
0b1110000110000111,
|
0b1100001110000111,
|
||||||
0b0111001111001110,
|
0b1100001110000110,
|
||||||
0b0111111111111110,
|
0b0110011111001110,
|
||||||
0b0011111011111100,
|
0b0111111011111100,
|
||||||
0b0001110001110000,
|
0b0011110001111000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
|
|
@ -450,6 +446,8 @@ const uint16_t numfont16x22[] = {
|
||||||
0b0000001101100110,
|
0b0000001101100110,
|
||||||
0b0000001101100110,
|
0b0000001101100110,
|
||||||
0b0000001101100110,
|
0b0000001101100110,
|
||||||
|
0b0000001101100110,
|
||||||
|
0b0000001101100110,
|
||||||
0b0011101101111100,
|
0b0011101101111100,
|
||||||
0b0111111101111110,
|
0b0111111101111110,
|
||||||
0b1110011101100111,
|
0b1110011101100111,
|
||||||
|
|
@ -457,28 +455,30 @@ const uint16_t numfont16x22[] = {
|
||||||
0b1100001101100011,
|
0b1100001101100011,
|
||||||
0b1100001101100011,
|
0b1100001101100011,
|
||||||
0b1100001101100011,
|
0b1100001101100011,
|
||||||
|
0b1100001101100011,
|
||||||
|
0b1100001101100011,
|
||||||
0b1110011101100111,
|
0b1110011101100111,
|
||||||
0b0111111101111110,
|
0b0111111101111110,
|
||||||
0b0011101101111100,
|
0b0011101101111100,
|
||||||
|
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000001110000000,
|
0b0000001110000000,
|
||||||
0b0000001110000000,
|
0b0000001110000000,
|
||||||
0b0000001110000000,
|
0b0000001110000000,
|
||||||
0b0001111111110000,
|
0b0000001110000000,
|
||||||
0b0001111111110000,
|
0b0011111111111000,
|
||||||
0b0001111111110000,
|
0b0011111111111000,
|
||||||
|
0b0011111111111000,
|
||||||
|
0b0000001110000000,
|
||||||
0b0000001110000000,
|
0b0000001110000000,
|
||||||
0b0000001110000000,
|
0b0000001110000000,
|
||||||
0b0000001110000000,
|
0b0000001110000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0001111111110000,
|
0b0011111111111000,
|
||||||
0b0001111111110000,
|
0b0011111111111000,
|
||||||
0b0001111111110000,
|
0b0011111111111000,
|
||||||
0b0000000000000000,
|
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
0b0000000000000000,
|
0b0000000000000000,
|
||||||
|
|
|
||||||
339
ui.c
339
ui.c
|
|
@ -22,7 +22,7 @@
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "chprintf.h"
|
#include "chprintf.h"
|
||||||
#include "nanovna.h"
|
#include "nanovna.h"
|
||||||
#include <stdlib.h>
|
//#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -106,19 +106,20 @@ int awd_count;
|
||||||
#define KP_DONE 1
|
#define KP_DONE 1
|
||||||
#define KP_CANCEL 2
|
#define KP_CANCEL 2
|
||||||
|
|
||||||
char kp_buf[NUMINPUT_LEN+1];
|
static char kp_buf[NUMINPUT_LEN+1];
|
||||||
int8_t kp_index = 0;
|
static int8_t kp_index = 0;
|
||||||
|
|
||||||
void ui_mode_normal(void);
|
static void ui_mode_normal(void);
|
||||||
void ui_mode_menu(void);
|
static void ui_mode_menu(void);
|
||||||
void ui_mode_numeric(int _keypad_mode);
|
static void ui_mode_numeric(int _keypad_mode);
|
||||||
void ui_mode_keypad(int _keypad_mode);
|
static void ui_mode_keypad(int _keypad_mode);
|
||||||
void draw_menu(void);
|
static void draw_menu(void);
|
||||||
void leave_ui_mode(void);
|
static void leave_ui_mode(void);
|
||||||
void erase_menu_buttons(void);
|
static void erase_menu_buttons(void);
|
||||||
void ui_process_keypad(void);
|
static void ui_process_keypad(void);
|
||||||
static void ui_process_numeric(void);
|
static void ui_process_numeric(void);
|
||||||
|
|
||||||
|
static void menu_move_back(void);
|
||||||
static void menu_push_submenu(const menuitem_t *submenu);
|
static void menu_push_submenu(const menuitem_t *submenu);
|
||||||
|
|
||||||
static int btn_check(void)
|
static int btn_check(void)
|
||||||
|
|
@ -202,7 +203,7 @@ static int btn_wait_release(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
touch_measure_y(void)
|
touch_measure_y(void)
|
||||||
{
|
{
|
||||||
int v;
|
int v;
|
||||||
|
|
@ -222,7 +223,7 @@ touch_measure_y(void)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
touch_measure_x(void)
|
touch_measure_x(void)
|
||||||
{
|
{
|
||||||
int v;
|
int v;
|
||||||
|
|
@ -262,14 +263,15 @@ touch_start_watchdog(void)
|
||||||
adc_start_analog_watchdogd(ADC1, ADC_CHSELR_CHSEL7);
|
adc_start_analog_watchdogd(ADC1, ADC_CHSELR_CHSEL7);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
touch_status(void)
|
touch_status(void)
|
||||||
{
|
{
|
||||||
touch_prepare_sense();
|
touch_prepare_sense();
|
||||||
return adc_single_read(ADC1, ADC_CHSELR_CHSEL7) > TOUCH_THRESHOLD;
|
return adc_single_read(ADC1, ADC_CHSELR_CHSEL7) > TOUCH_THRESHOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
int touch_check(void)
|
static int
|
||||||
|
touch_check(void)
|
||||||
{
|
{
|
||||||
int stat = touch_status();
|
int stat = touch_status();
|
||||||
if (stat) {
|
if (stat) {
|
||||||
|
|
@ -298,7 +300,8 @@ int touch_check(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void touch_wait_release(void)
|
static void
|
||||||
|
touch_wait_release(void)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
/* wait touch release */
|
/* wait touch release */
|
||||||
|
|
@ -451,10 +454,6 @@ enum {
|
||||||
|
|
||||||
typedef void (*menuaction_cb_t)(int item, uint8_t data);
|
typedef void (*menuaction_cb_t)(int item, uint8_t data);
|
||||||
|
|
||||||
|
|
||||||
static void menu_move_back(void);
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menu_calop_cb(int item, uint8_t data)
|
menu_calop_cb(int item, uint8_t data)
|
||||||
{
|
{
|
||||||
|
|
@ -563,7 +562,7 @@ choose_active_trace(void)
|
||||||
if (trace[uistat.current_trace].enabled)
|
if (trace[uistat.current_trace].enabled)
|
||||||
// do nothing
|
// do nothing
|
||||||
return;
|
return;
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < TRACES_MAX; i++)
|
||||||
if (trace[i].enabled) {
|
if (trace[i].enabled) {
|
||||||
uistat.current_trace = i;
|
uistat.current_trace = i;
|
||||||
return;
|
return;
|
||||||
|
|
@ -815,7 +814,7 @@ menu_marker_smith_cb(int item, uint8_t data)
|
||||||
draw_menu();
|
draw_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
active_marker_select(int item)
|
active_marker_select(int item)
|
||||||
{
|
{
|
||||||
if (item == -1) {
|
if (item == -1) {
|
||||||
|
|
@ -863,7 +862,7 @@ menu_marker_sel_cb(int item, uint8_t data)
|
||||||
uistat.lever_mode = LM_MARKER;
|
uistat.lever_mode = LM_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
const menuitem_t menu_calop[] = {
|
static const menuitem_t menu_calop[] = {
|
||||||
{ MT_CALLBACK, CAL_OPEN, "OPEN", menu_calop_cb },
|
{ MT_CALLBACK, CAL_OPEN, "OPEN", menu_calop_cb },
|
||||||
{ MT_CALLBACK, CAL_SHORT, "SHORT", menu_calop_cb },
|
{ MT_CALLBACK, CAL_SHORT, "SHORT", menu_calop_cb },
|
||||||
{ MT_CALLBACK, CAL_LOAD, "LOAD", menu_calop_cb },
|
{ MT_CALLBACK, CAL_LOAD, "LOAD", menu_calop_cb },
|
||||||
|
|
@ -1085,7 +1084,8 @@ ensure_selection(void)
|
||||||
selection = i-1;
|
selection = i-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menu_move_back(void)
|
static void
|
||||||
|
menu_move_back(void)
|
||||||
{
|
{
|
||||||
if (menu_current_level == 0)
|
if (menu_current_level == 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -1095,7 +1095,8 @@ static void menu_move_back(void)
|
||||||
draw_menu();
|
draw_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menu_push_submenu(const menuitem_t *submenu)
|
static void
|
||||||
|
menu_push_submenu(const menuitem_t *submenu)
|
||||||
{
|
{
|
||||||
if (menu_current_level < MENU_STACK_DEPTH_MAX-1)
|
if (menu_current_level < MENU_STACK_DEPTH_MAX-1)
|
||||||
menu_current_level++;
|
menu_current_level++;
|
||||||
|
|
@ -1106,7 +1107,8 @@ static void menu_push_submenu(const menuitem_t *submenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static void menu_move_top(void)
|
static void
|
||||||
|
menu_move_top(void)
|
||||||
{
|
{
|
||||||
if (menu_current_level == 0)
|
if (menu_current_level == 0)
|
||||||
return;
|
return;
|
||||||
|
|
@ -1117,7 +1119,8 @@ static void menu_move_top(void)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void menu_invoke(int item)
|
static void
|
||||||
|
menu_invoke(int item)
|
||||||
{
|
{
|
||||||
const menuitem_t *menu = menu_stack[menu_current_level];
|
const menuitem_t *menu = menu_stack[menu_current_level];
|
||||||
menu = &menu[item];
|
menu = &menu[item];
|
||||||
|
|
@ -1147,9 +1150,23 @@ void menu_invoke(int item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define KP_X(x) (48*(x) + 2 + (320-64-192))
|
#define KP_WIDTH 48
|
||||||
#define KP_Y(y) (48*(y) + 2)
|
#define KP_HEIGHT 48
|
||||||
|
// Key x, y position (0 - 15) on screen
|
||||||
|
#define KP_GET_X(posx) ((posx)*KP_WIDTH + (320-64-KP_WIDTH*4))
|
||||||
|
#define KP_GET_Y(posy) ((posy)*KP_HEIGHT + 12 )
|
||||||
|
|
||||||
|
// Key names
|
||||||
|
#define KP_0 0
|
||||||
|
#define KP_1 1
|
||||||
|
#define KP_2 2
|
||||||
|
#define KP_3 3
|
||||||
|
#define KP_4 4
|
||||||
|
#define KP_5 5
|
||||||
|
#define KP_6 6
|
||||||
|
#define KP_7 7
|
||||||
|
#define KP_8 8
|
||||||
|
#define KP_9 9
|
||||||
#define KP_PERIOD 10
|
#define KP_PERIOD 10
|
||||||
#define KP_MINUS 11
|
#define KP_MINUS 11
|
||||||
#define KP_X1 12
|
#define KP_X1 12
|
||||||
|
|
@ -1164,74 +1181,72 @@ void menu_invoke(int item)
|
||||||
#define KP_N 21
|
#define KP_N 21
|
||||||
#define KP_P 22
|
#define KP_P 22
|
||||||
|
|
||||||
// Set struct data align as BYTE for save flash memory
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t x, y;
|
uint8_t x:4;
|
||||||
|
uint8_t y:4;
|
||||||
int8_t c;
|
int8_t c;
|
||||||
} keypads_t;
|
} keypads_t;
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
const keypads_t *keypads;
|
static const keypads_t *keypads;
|
||||||
uint8_t keypads_last_index;
|
static uint8_t keypads_last_index;
|
||||||
|
|
||||||
const keypads_t keypads_freq[] = {
|
static const keypads_t keypads_freq[] = {
|
||||||
{ KP_X(1), KP_Y(3), KP_PERIOD },
|
{ 1, 3, KP_PERIOD },
|
||||||
{ KP_X(0), KP_Y(3), 0 },
|
{ 0, 3, KP_0 },
|
||||||
{ KP_X(0), KP_Y(2), 1 },
|
{ 0, 2, KP_1 },
|
||||||
{ KP_X(1), KP_Y(2), 2 },
|
{ 1, 2, KP_2 },
|
||||||
{ KP_X(2), KP_Y(2), 3 },
|
{ 2, 2, KP_3 },
|
||||||
{ KP_X(0), KP_Y(1), 4 },
|
{ 0, 1, KP_4 },
|
||||||
{ KP_X(1), KP_Y(1), 5 },
|
{ 1, 1, KP_5 },
|
||||||
{ KP_X(2), KP_Y(1), 6 },
|
{ 2, 1, KP_6 },
|
||||||
{ KP_X(0), KP_Y(0), 7 },
|
{ 0, 0, KP_7 },
|
||||||
{ KP_X(1), KP_Y(0), 8 },
|
{ 1, 0, KP_8 },
|
||||||
{ KP_X(2), KP_Y(0), 9 },
|
{ 2, 0, KP_9 },
|
||||||
{ KP_X(3), KP_Y(0), KP_G },
|
{ 3, 0, KP_G },
|
||||||
{ KP_X(3), KP_Y(1), KP_M },
|
{ 3, 1, KP_M },
|
||||||
{ KP_X(3), KP_Y(2), KP_K },
|
{ 3, 2, KP_K },
|
||||||
{ KP_X(3), KP_Y(3), KP_X1 },
|
{ 3, 3, KP_X1 },
|
||||||
{ KP_X(2), KP_Y(3), KP_BS },
|
{ 2, 3, KP_BS },
|
||||||
{ 0, 0, -1 }
|
{ 0, 0, -1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const keypads_t keypads_scale[] = {
|
static const keypads_t keypads_scale[] = {
|
||||||
{ KP_X(1), KP_Y(3), KP_PERIOD },
|
{ 1, 3, KP_PERIOD },
|
||||||
{ KP_X(0), KP_Y(3), 0 },
|
{ 0, 3, KP_0 },
|
||||||
{ KP_X(0), KP_Y(2), 1 },
|
{ 0, 2, KP_1 },
|
||||||
{ KP_X(1), KP_Y(2), 2 },
|
{ 1, 2, KP_2 },
|
||||||
{ KP_X(2), KP_Y(2), 3 },
|
{ 2, 2, KP_3 },
|
||||||
{ KP_X(0), KP_Y(1), 4 },
|
{ 0, 1, KP_4 },
|
||||||
{ KP_X(1), KP_Y(1), 5 },
|
{ 1, 1, KP_5 },
|
||||||
{ KP_X(2), KP_Y(1), 6 },
|
{ 2, 1, KP_6 },
|
||||||
{ KP_X(0), KP_Y(0), 7 },
|
{ 0, 0, KP_7 },
|
||||||
{ KP_X(1), KP_Y(0), 8 },
|
{ 1, 0, KP_8 },
|
||||||
{ KP_X(2), KP_Y(0), 9 },
|
{ 2, 0, KP_9 },
|
||||||
{ KP_X(3), KP_Y(3), KP_X1 },
|
{ 3, 3, KP_X1 },
|
||||||
{ KP_X(2), KP_Y(3), KP_BS },
|
{ 2, 3, KP_BS },
|
||||||
{ 0, 0, -1 }
|
{ 0, 0, -1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const keypads_t keypads_time[] = {
|
static const keypads_t keypads_time[] = {
|
||||||
{ KP_X(1), KP_Y(3), KP_PERIOD },
|
{ 1, 3, KP_PERIOD },
|
||||||
{ KP_X(0), KP_Y(3), 0 },
|
{ 0, 3, KP_0 },
|
||||||
{ KP_X(0), KP_Y(2), 1 },
|
{ 0, 2, KP_1 },
|
||||||
{ KP_X(1), KP_Y(2), 2 },
|
{ 1, 2, KP_2 },
|
||||||
{ KP_X(2), KP_Y(2), 3 },
|
{ 2, 2, KP_3 },
|
||||||
{ KP_X(0), KP_Y(1), 4 },
|
{ 0, 1, KP_4 },
|
||||||
{ KP_X(1), KP_Y(1), 5 },
|
{ 1, 1, KP_5 },
|
||||||
{ KP_X(2), KP_Y(1), 6 },
|
{ 2, 1, KP_6 },
|
||||||
{ KP_X(0), KP_Y(0), 7 },
|
{ 0, 0, KP_7 },
|
||||||
{ KP_X(1), KP_Y(0), 8 },
|
{ 1, 0, KP_8 },
|
||||||
{ KP_X(2), KP_Y(0), 9 },
|
{ 2, 0, KP_9 },
|
||||||
{ KP_X(3), KP_Y(1), KP_N },
|
{ 3, 1, KP_N },
|
||||||
{ KP_X(3), KP_Y(2), KP_P },
|
{ 3, 2, KP_P },
|
||||||
{ KP_X(3), KP_Y(3), KP_MINUS },
|
{ 3, 3, KP_MINUS },
|
||||||
{ KP_X(2), KP_Y(3), KP_BS },
|
{ 2, 3, KP_BS },
|
||||||
{ 0, 0, -1 }
|
{ 0, 0, -1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const keypads_t * const keypads_mode_tbl[] = {
|
static const keypads_t * const keypads_mode_tbl[] = {
|
||||||
keypads_freq, // start
|
keypads_freq, // start
|
||||||
keypads_freq, // stop
|
keypads_freq, // stop
|
||||||
keypads_freq, // center
|
keypads_freq, // center
|
||||||
|
|
@ -1244,27 +1259,29 @@ const keypads_t * const keypads_mode_tbl[] = {
|
||||||
keypads_time // scale of delay
|
keypads_time // scale of delay
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * const keypad_mode_label[] = {
|
static const char * const keypad_mode_label[] = {
|
||||||
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY"
|
"START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY"
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
static void
|
||||||
draw_keypad(void)
|
draw_keypad(void)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (keypads[i].x) {
|
while (keypads[i].c>=0) {
|
||||||
uint16_t bg = config.menu_normal_color;
|
uint16_t bg = config.menu_normal_color;
|
||||||
if (i == selection)
|
if (i == selection)
|
||||||
bg = config.menu_active_color;
|
bg = config.menu_active_color;
|
||||||
setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
|
setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
|
||||||
setBackgroundColor(bg);
|
setBackgroundColor(bg);
|
||||||
ili9341_fill(keypads[i].x, keypads[i].y, 44, 44, bg);
|
int x = KP_GET_X(keypads[i].x);
|
||||||
ili9341_drawfont(keypads[i].c, keypads[i].x+14, keypads[i].y+10);
|
int y = KP_GET_Y(keypads[i].y);
|
||||||
|
ili9341_fill(x+2, y+2, KP_WIDTH-4, KP_HEIGHT-4, bg);
|
||||||
|
ili9341_drawfont(keypads[i].c, x+(KP_WIDTH-NUM_FONT_GET_WIDTH)/2, y+(KP_HEIGHT-NUM_FONT_GET_HEIGHT)/2);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
draw_numeric_area_frame(void)
|
draw_numeric_area_frame(void)
|
||||||
{
|
{
|
||||||
ili9341_fill(0, 208, 320, 32, DEFAULT_MENU_COLOR);
|
ili9341_fill(0, 208, 320, 32, DEFAULT_MENU_COLOR);
|
||||||
|
|
@ -1274,15 +1291,15 @@ draw_numeric_area_frame(void)
|
||||||
//ili9341_drawfont(KP_KEYPAD, 300, 216);
|
//ili9341_drawfont(KP_KEYPAD, 300, 216);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
draw_numeric_input(const char *buf)
|
draw_numeric_input(const char *buf)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i;
|
||||||
int x = 64;
|
int x;
|
||||||
int focused = FALSE;
|
int focused = FALSE;
|
||||||
uint16_t xsim = 0b0010010000000000;
|
uint16_t xsim = 0b0010010000000000;
|
||||||
|
|
||||||
for (i = 0; i < 10 && buf[i]; i++, xsim<<=1) {
|
for (i = 0, x = 64; i < 10 && buf[i]; i++, xsim<<=1) {
|
||||||
uint16_t fg = DEFAULT_MENU_TEXT_COLOR;
|
uint16_t fg = DEFAULT_MENU_TEXT_COLOR;
|
||||||
uint16_t bg = DEFAULT_MENU_COLOR;
|
uint16_t bg = DEFAULT_MENU_COLOR;
|
||||||
int c = buf[i];
|
int c = buf[i];
|
||||||
|
|
@ -1290,12 +1307,10 @@ draw_numeric_input(const char *buf)
|
||||||
c = KP_PERIOD;
|
c = KP_PERIOD;
|
||||||
else if (c == '-')
|
else if (c == '-')
|
||||||
c = KP_MINUS;
|
c = KP_MINUS;
|
||||||
else if (c >= '0' && c <= '9')
|
else// if (c >= '0' && c <= '9')
|
||||||
c = c - '0';
|
c = c - '0';
|
||||||
else
|
|
||||||
c = -1;
|
|
||||||
|
|
||||||
if (uistat.digit == 8-i) {
|
if (ui_mode == UI_NUMERIC && uistat.digit == 8-i) {
|
||||||
fg = DEFAULT_SPEC_INPUT_COLOR;
|
fg = DEFAULT_SPEC_INPUT_COLOR;
|
||||||
focused = TRUE;
|
focused = TRUE;
|
||||||
if (uistat.digit_mode)
|
if (uistat.digit_mode)
|
||||||
|
|
@ -1303,18 +1318,17 @@ draw_numeric_input(const char *buf)
|
||||||
}
|
}
|
||||||
setForegroundColor(fg);
|
setForegroundColor(fg);
|
||||||
setBackgroundColor(bg);
|
setBackgroundColor(bg);
|
||||||
if (c >= 0)
|
if (c >= 0) // c is number
|
||||||
ili9341_drawfont(c, x, 208+4);
|
ili9341_drawfont(c, x, 208+4);
|
||||||
else if (focused)
|
else if (focused) // c not number, but focused
|
||||||
ili9341_drawfont(0, x, 208+4);
|
ili9341_drawfont(0, x, 208+4);
|
||||||
else
|
else // erase
|
||||||
ili9341_fill(x, 208+4, 20, 24, bg);
|
ili9341_fill(x, 208+4, 20, 24, bg);
|
||||||
|
|
||||||
x += xsim&0x8000 ? 18+8 : 18;
|
x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2;
|
||||||
}
|
|
||||||
if (i < 10) {
|
|
||||||
ili9341_fill(x, 208+4, 20*(10-i), 24, DEFAULT_MENU_COLOR);
|
|
||||||
}
|
}
|
||||||
|
// erase last
|
||||||
|
ili9341_fill(x, 208+4, NUM_FONT_GET_WIDTH+2+8, 24, DEFAULT_MENU_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -1398,7 +1412,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
draw_menu_buttons(const menuitem_t *menu)
|
draw_menu_buttons(const menuitem_t *menu)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -1430,7 +1444,7 @@ draw_menu_buttons(const menuitem_t *menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
menu_select_touch(int i)
|
menu_select_touch(int i)
|
||||||
{
|
{
|
||||||
selection = i;
|
selection = i;
|
||||||
|
|
@ -1440,7 +1454,7 @@ menu_select_touch(int i)
|
||||||
menu_invoke(i);
|
menu_invoke(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
menu_apply_touch(void)
|
menu_apply_touch(void)
|
||||||
{
|
{
|
||||||
int touch_x, touch_y;
|
int touch_x, touch_y;
|
||||||
|
|
@ -1465,25 +1479,25 @@ menu_apply_touch(void)
|
||||||
ui_mode_normal();
|
ui_mode_normal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
draw_menu(void)
|
draw_menu(void)
|
||||||
{
|
{
|
||||||
draw_menu_buttons(menu_stack[menu_current_level]);
|
draw_menu_buttons(menu_stack[menu_current_level]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
erase_menu_buttons(void)
|
erase_menu_buttons(void)
|
||||||
{
|
{
|
||||||
ili9341_fill(320-60, 0, 60, 32*7, DEFAULT_BG_COLOR);
|
ili9341_fill(320-60, 0, 60, 32*7, DEFAULT_BG_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
erase_numeric_input(void)
|
erase_numeric_input(void)
|
||||||
{
|
{
|
||||||
ili9341_fill(0, 240-32, 320, 32, DEFAULT_BG_COLOR);
|
ili9341_fill(0, 240-32, 320, 32, DEFAULT_BG_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
leave_ui_mode()
|
leave_ui_mode()
|
||||||
{
|
{
|
||||||
if (ui_mode == UI_MENU) {
|
if (ui_mode == UI_MENU) {
|
||||||
|
|
@ -1496,7 +1510,7 @@ leave_ui_mode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
fetch_numeric_target(void)
|
fetch_numeric_target(void)
|
||||||
{
|
{
|
||||||
switch (keypad_mode) {
|
switch (keypad_mode) {
|
||||||
|
|
@ -1542,7 +1556,8 @@ fetch_numeric_target(void)
|
||||||
uistat.previous_value = uistat.value;
|
uistat.previous_value = uistat.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_numeric_value(void)
|
static void
|
||||||
|
set_numeric_value(void)
|
||||||
{
|
{
|
||||||
switch (keypad_mode) {
|
switch (keypad_mode) {
|
||||||
case KM_START:
|
case KM_START:
|
||||||
|
|
@ -1575,7 +1590,7 @@ void set_numeric_value(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
draw_numeric_area(void)
|
draw_numeric_area(void)
|
||||||
{
|
{
|
||||||
char buf[10];
|
char buf[10];
|
||||||
|
|
@ -1583,7 +1598,7 @@ draw_numeric_area(void)
|
||||||
draw_numeric_input(buf);
|
draw_numeric_input(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
ui_mode_menu(void)
|
ui_mode_menu(void)
|
||||||
{
|
{
|
||||||
if (ui_mode == UI_MENU)
|
if (ui_mode == UI_MENU)
|
||||||
|
|
@ -1591,13 +1606,13 @@ ui_mode_menu(void)
|
||||||
|
|
||||||
ui_mode = UI_MENU;
|
ui_mode = UI_MENU;
|
||||||
/* narrowen plotting area */
|
/* narrowen plotting area */
|
||||||
area_width = AREA_WIDTH_NORMAL - (64-8);
|
area_width = AREA_WIDTH_NORMAL - 60;
|
||||||
area_height = HEIGHT+1;
|
area_height = AREA_HEIGHT_NORMAL;
|
||||||
ensure_selection();
|
ensure_selection();
|
||||||
draw_menu();
|
draw_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
ui_mode_numeric(int _keypad_mode)
|
ui_mode_numeric(int _keypad_mode)
|
||||||
{
|
{
|
||||||
if (ui_mode == UI_NUMERIC)
|
if (ui_mode == UI_NUMERIC)
|
||||||
|
|
@ -1609,14 +1624,14 @@ ui_mode_numeric(int _keypad_mode)
|
||||||
keypad_mode = _keypad_mode;
|
keypad_mode = _keypad_mode;
|
||||||
ui_mode = UI_NUMERIC;
|
ui_mode = UI_NUMERIC;
|
||||||
area_width = AREA_WIDTH_NORMAL;
|
area_width = AREA_WIDTH_NORMAL;
|
||||||
area_height = 240-32;//HEIGHT - 32;
|
area_height = 240-32;//AREA_HEIGHT_NORMAL - 32;
|
||||||
|
|
||||||
draw_numeric_area_frame();
|
draw_numeric_area_frame();
|
||||||
fetch_numeric_target();
|
fetch_numeric_target();
|
||||||
draw_numeric_area();
|
draw_numeric_area();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
ui_mode_keypad(int _keypad_mode)
|
ui_mode_keypad(int _keypad_mode)
|
||||||
{
|
{
|
||||||
if (ui_mode == UI_KEYPAD)
|
if (ui_mode == UI_KEYPAD)
|
||||||
|
|
@ -1631,7 +1646,7 @@ ui_mode_keypad(int _keypad_mode)
|
||||||
keypads_last_index = i;
|
keypads_last_index = i;
|
||||||
|
|
||||||
ui_mode = UI_KEYPAD;
|
ui_mode = UI_KEYPAD;
|
||||||
area_width = AREA_WIDTH_NORMAL - (64-8);
|
area_width = AREA_WIDTH_NORMAL - 60;
|
||||||
area_height = HEIGHT - 32;
|
area_height = HEIGHT - 32;
|
||||||
draw_menu();
|
draw_menu();
|
||||||
draw_keypad();
|
draw_keypad();
|
||||||
|
|
@ -1639,14 +1654,14 @@ ui_mode_keypad(int _keypad_mode)
|
||||||
draw_numeric_input("");
|
draw_numeric_input("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
ui_mode_normal(void)
|
ui_mode_normal(void)
|
||||||
{
|
{
|
||||||
if (ui_mode == UI_NORMAL)
|
if (ui_mode == UI_NORMAL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
area_width = AREA_WIDTH_NORMAL;
|
area_width = AREA_WIDTH_NORMAL;
|
||||||
area_height = HEIGHT+1;
|
area_height = AREA_HEIGHT_NORMAL;
|
||||||
leave_ui_mode();
|
leave_ui_mode();
|
||||||
ui_mode = UI_NORMAL;
|
ui_mode = UI_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
@ -1676,16 +1691,14 @@ lever_move_marker(int status)
|
||||||
static void
|
static void
|
||||||
lever_search_marker(int status)
|
lever_search_marker(int status)
|
||||||
{
|
{
|
||||||
|
int i = -1;
|
||||||
if (active_marker >= 0) {
|
if (active_marker >= 0) {
|
||||||
if (status & EVT_DOWN) {
|
if (status & EVT_DOWN)
|
||||||
int i = marker_search_left(markers[active_marker].index);
|
i = marker_search_left(markers[active_marker].index);
|
||||||
|
else if (status & EVT_UP)
|
||||||
|
i = marker_search_right(markers[active_marker].index);
|
||||||
if (i != -1)
|
if (i != -1)
|
||||||
markers[active_marker].index = i;
|
markers[active_marker].index = i;
|
||||||
} else if (status & EVT_UP) {
|
|
||||||
int i = marker_search_right(markers[active_marker].index);
|
|
||||||
if (i != -1)
|
|
||||||
markers[active_marker].index = i;
|
|
||||||
}
|
|
||||||
redraw_marker(active_marker, TRUE);
|
redraw_marker(active_marker, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1768,14 +1781,13 @@ ui_process_menu(void)
|
||||||
if (menu_stack[menu_current_level][selection+1].type == MT_NONE)
|
if (menu_stack[menu_current_level][selection+1].type == MT_NONE)
|
||||||
goto menuclose;
|
goto menuclose;
|
||||||
selection++;
|
selection++;
|
||||||
draw_menu();
|
|
||||||
}
|
}
|
||||||
if (status & EVT_DOWN) {
|
if (status & EVT_DOWN) {
|
||||||
if (selection == 0)
|
if (selection == 0)
|
||||||
goto menuclose;
|
goto menuclose;
|
||||||
selection--;
|
selection--;
|
||||||
draw_menu();
|
|
||||||
}
|
}
|
||||||
|
draw_menu();
|
||||||
status = btn_wait_release();
|
status = btn_wait_release();
|
||||||
} while (status != 0);
|
} while (status != 0);
|
||||||
}
|
}
|
||||||
|
|
@ -1867,9 +1879,11 @@ keypad_apply_touch(void)
|
||||||
|
|
||||||
touch_position(&touch_x, &touch_y);
|
touch_position(&touch_x, &touch_y);
|
||||||
|
|
||||||
while (keypads[i].x) {
|
while (keypads[i].c>=0) {
|
||||||
if (keypads[i].x-2 < touch_x && touch_x < keypads[i].x+44+2
|
int x = KP_GET_X(keypads[i].x);
|
||||||
&& keypads[i].y-2 < touch_y && touch_y < keypads[i].y+44+2) {
|
int y = KP_GET_Y(keypads[i].y);
|
||||||
|
if (x < touch_x && touch_x < x+KP_WIDTH
|
||||||
|
&& y < touch_y && touch_y < y+KP_HEIGHT) {
|
||||||
// draw focus
|
// draw focus
|
||||||
selection = i;
|
selection = i;
|
||||||
draw_keypad();
|
draw_keypad();
|
||||||
|
|
@ -1951,35 +1965,28 @@ ui_process_numeric(void)
|
||||||
do {
|
do {
|
||||||
if (uistat.digit_mode) {
|
if (uistat.digit_mode) {
|
||||||
if (status & EVT_DOWN) {
|
if (status & EVT_DOWN) {
|
||||||
if (uistat.digit < 8) {
|
if (uistat.digit < 8)
|
||||||
uistat.digit++;
|
uistat.digit++;
|
||||||
draw_numeric_area();
|
else
|
||||||
} else {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (status & EVT_UP) {
|
if (status & EVT_UP) {
|
||||||
if (uistat.digit > 0) {
|
if (uistat.digit > 0)
|
||||||
uistat.digit--;
|
uistat.digit--;
|
||||||
draw_numeric_area();
|
else
|
||||||
} else {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
int32_t step = 1;
|
int32_t step = 1;
|
||||||
int n;
|
int n;
|
||||||
for (n = uistat.digit; n > 0; n--)
|
for (n = uistat.digit; n > 0; n--)
|
||||||
step *= 10;
|
step *= 10;
|
||||||
if (status & EVT_DOWN) {
|
if (status & EVT_DOWN)
|
||||||
uistat.value += step;
|
uistat.value += step;
|
||||||
draw_numeric_area();
|
if (status & EVT_UP)
|
||||||
}
|
|
||||||
if (status & EVT_UP) {
|
|
||||||
uistat.value -= step;
|
uistat.value -= step;
|
||||||
|
}
|
||||||
draw_numeric_area();
|
draw_numeric_area();
|
||||||
}
|
|
||||||
}
|
|
||||||
status = btn_wait_release();
|
status = btn_wait_release();
|
||||||
} while (status != 0);
|
} while (status != 0);
|
||||||
}
|
}
|
||||||
|
|
@ -1992,7 +1999,7 @@ ui_process_numeric(void)
|
||||||
ui_mode_normal();
|
ui_mode_normal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
ui_process_keypad(void)
|
ui_process_keypad(void)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
@ -2004,20 +2011,13 @@ ui_process_keypad(void)
|
||||||
if (status & (EVT_UP|EVT_DOWN)) {
|
if (status & (EVT_UP|EVT_DOWN)) {
|
||||||
int s = status;
|
int s = status;
|
||||||
do {
|
do {
|
||||||
if (s & EVT_UP) {
|
if (s & EVT_UP)
|
||||||
selection--;
|
if (--selection < 0)
|
||||||
if (selection < 0)
|
|
||||||
selection = keypads_last_index;
|
selection = keypads_last_index;
|
||||||
draw_keypad();
|
if (s & EVT_DOWN)
|
||||||
}
|
if (++selection > keypads_last_index)
|
||||||
if (s & EVT_DOWN) {
|
|
||||||
selection++;
|
|
||||||
if (keypads[selection].c < 0) {
|
|
||||||
// reaches to tail
|
|
||||||
selection = 0;
|
selection = 0;
|
||||||
}
|
|
||||||
draw_keypad();
|
draw_keypad();
|
||||||
}
|
|
||||||
s = btn_wait_release();
|
s = btn_wait_release();
|
||||||
} while (s != 0);
|
} while (s != 0);
|
||||||
}
|
}
|
||||||
|
|
@ -2086,12 +2086,6 @@ drag_marker(int t, int m)
|
||||||
} while(status != EVT_TOUCH_RELEASED);
|
} while(status != EVT_TOUCH_RELEASED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
sq_distance(int x0, int y0)
|
|
||||||
{
|
|
||||||
return x0*x0 + y0*y0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
touch_pickup_marker(void)
|
touch_pickup_marker(void)
|
||||||
{
|
{
|
||||||
|
|
@ -2101,18 +2095,19 @@ touch_pickup_marker(void)
|
||||||
touch_x -= OFFSETX;
|
touch_x -= OFFSETX;
|
||||||
touch_y -= OFFSETY;
|
touch_y -= OFFSETY;
|
||||||
|
|
||||||
for (m = 0; m < 4; m++) {
|
for (m = 0; m < MARKERS_MAX; m++) {
|
||||||
if (!markers[m].enabled)
|
if (!markers[m].enabled)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (t = 0; t < 4; t++) {
|
for (t = 0; t < TRACES_MAX; t++) {
|
||||||
int x, y;
|
int x, y;
|
||||||
if (!trace[t].enabled)
|
if (!trace[t].enabled)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
marker_position(m, t, &x, &y);
|
marker_position(m, t, &x, &y);
|
||||||
|
x-=touch_x;
|
||||||
if (sq_distance(x - touch_x, y - touch_y) < 400) {
|
y-=touch_y;
|
||||||
|
if ((x*x+y*y) < 20*20) {
|
||||||
if (active_marker != m) {
|
if (active_marker != m) {
|
||||||
previous_marker = active_marker;
|
previous_marker = active_marker;
|
||||||
active_marker = m;
|
active_marker = m;
|
||||||
|
|
@ -2223,7 +2218,7 @@ static const GPTConfig gpt3cfg = {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
static void
|
||||||
test_touch(int *x, int *y)
|
test_touch(int *x, int *y)
|
||||||
{
|
{
|
||||||
adc_stop(ADC1);
|
adc_stop(ADC1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue