diff --git a/Font5x7.c b/Font5x7.c index a82086c..63f66bd 100644 --- a/Font5x7.c +++ b/Font5x7.c @@ -575,22 +575,22 @@ const uint8_t x5x7_bits[127*7] = 0b10011000, /* Character (0x1d): - width=6 + width=7 +--------+ | | - |* * | - |* * | - |* * | - |** ** | - |* * * | + | | + | * * | + | * * | + | ** ** | + | * * * | |* | +--------+ */ - 0b00000000|CHAR5x7_WIDTH_6px, - 0b10001000, - 0b10001000, - 0b11011000, - 0b10101000, - 0b10000000, + 0b00000000|CHAR5x7_WIDTH_7px, + 0b00000000, + 0b01000100, + 0b01000100, + 0b01101100, + 0b01010100, 0b10000000, /* Character (0x1e): diff --git a/chconf.h b/chconf.h index 05112aa..34e6afe 100644 --- a/chconf.h +++ b/chconf.h @@ -147,7 +147,7 @@ * * @note The default is @p TRUE. */ -#define CH_CFG_USE_REGISTRY TRUE +#define CH_CFG_USE_REGISTRY FALSE /** * @brief Threads synchronization APIs. @@ -269,7 +269,7 @@ * * @note The default is @p TRUE. */ -#define CH_CFG_USE_QUEUES TRUE +#define CH_CFG_USE_QUEUES FALSE /** * @brief Core Memory Manager APIs. @@ -530,11 +530,11 @@ * ChibiOS/os/various/shell/shell_cmd.c */ #define SHELL_CMD_EXIT_ENABLED TRUE -#define SHELL_CMD_INFO_ENABLED TRUE +#define SHELL_CMD_INFO_ENABLED FALSE #define SHELL_CMD_ECHO_ENABLED FALSE #define SHELL_CMD_SYSTIME_ENABLED FALSE #define SHELL_CMD_MEM_ENABLED FALSE -#define SHELL_CMD_THREADS_ENABLED TRUE +#define SHELL_CMD_THREADS_ENABLED FALSE #define SHELL_CMD_TEST_ENABLED FALSE diff --git a/ili9341.c b/ili9341.c index 9cd184d..12edc9c 100644 --- a/ili9341.c +++ b/ili9341.c @@ -343,11 +343,12 @@ void ili9341_init(void) #ifndef __USE_DISPLAY_DMA__ void ili9341_fill(int x, int y, int w, int h, int color) { - uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; - uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; - - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy); +// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; +// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; + uint32_t xx = __REV16(x|((x+w-1)<<16)); + uint32_t yy = __REV16(y|((y+h-1)<<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, 0, NULL); int32_t len = w * h; while (len-- > 0){ @@ -358,12 +359,13 @@ void ili9341_fill(int x, int y, int w, int h, int color) void ili9341_bulk(int x, int y, int w, int h) { - uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; - uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; +// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; +// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; uint16_t *buf = spi_buffer; - - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy); + uint32_t xx = __REV16(x|((x+w-1)<<16)); + uint32_t yy = __REV16(y|((y+h-1)<<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, 0, NULL); int32_t len = w * h; while (len-- > 0){ @@ -372,7 +374,7 @@ void ili9341_bulk(int x, int y, int w, int h) } } -static uint8_t ssp_sendrecvdata() +static uint8_t ssp_sendrecvdata(void) { // Start RX clock (by sending data) SPI_WRITE_8BIT(0); @@ -383,10 +385,12 @@ static uint8_t ssp_sendrecvdata() void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) { - uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; - uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy); +// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; +// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; + uint32_t xx = __REV16(x|((x+w-1)<<16)); + uint32_t yy = __REV16(y|((y+h-1)<<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_READ, 0, NULL); // Skip data from rx buffer @@ -411,10 +415,10 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) // Fill region by some color void ili9341_fill(int x, int y, int w, int h, int color) { - uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; - uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy); + uint32_t xx = __REV16(x|((x+w-1)<<16)); + uint32_t yy = __REV16(y|((y+h-1)<<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, 0, NULL); dmaStreamSetMemory0(dmatx, &color); @@ -424,10 +428,10 @@ void ili9341_fill(int x, int y, int w, int h, int color) // Copy spi_buffer to region void ili9341_bulk(int x, int y, int w, int h) { - uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; - uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy); + uint32_t xx = __REV16(x|((x+w-1)<<16)); + uint32_t yy = __REV16(y|((y+h-1)<<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, 0, NULL); // Init Tx DMA mem->spi, set size, mode (spi and mem data size is 16 bit) @@ -443,11 +447,10 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) uint8_t dummy_tx = 0; uint8_t *rgbbuf=(uint8_t *)out; uint16_t data_size = len * 3 + 1; - - uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; - uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, yy); + uint32_t xx = __REV16(x|((x+w-1)<<16)); + uint32_t yy = __REV16(y|((y+h-1)<<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_READ, 0, NULL); // Skip SPI rx buffer while (SPI_RX_IS_NOT_EMPTY) diff --git a/main.c b/main.c index 07c8245..efb45b8 100644 --- a/main.c +++ b/main.c @@ -156,18 +156,18 @@ transform_domain(void) // and calculate ifft for time domain float* tmp = (float*)spi_buffer; - uint8_t window_size = 101, offset = 0; + uint8_t window_size = POINTS_COUNT, offset = 0; uint8_t is_lowpass = FALSE; switch (domain_mode & TD_FUNC) { case TD_FUNC_BANDPASS: offset = 0; - window_size = 101; + window_size = POINTS_COUNT; break; case TD_FUNC_LOWPASS_IMPULSE: case TD_FUNC_LOWPASS_STEP: is_lowpass = TRUE; - offset = 101; - window_size = 202; + offset = POINTS_COUNT; + window_size = POINTS_COUNT*2; break; } @@ -187,17 +187,17 @@ transform_domain(void) for (int ch = 0; ch < 2; ch++) { memcpy(tmp, measured[ch], sizeof(measured[0])); - for (int i = 0; i < 101; i++) { + for (int i = 0; i < POINTS_COUNT; i++) { float w = kaiser_window(i+offset, window_size, beta); tmp[i*2+0] *= w; tmp[i*2+1] *= w; } - for (int i = 101; i < FFT_SIZE; i++) { + for (int i = POINTS_COUNT; i < FFT_SIZE; i++) { tmp[i*2+0] = 0.0; tmp[i*2+1] = 0.0; } if (is_lowpass) { - for (int i = 1; i < 101; i++) { + for (int i = 1; i < POINTS_COUNT; i++) { tmp[(FFT_SIZE-i)*2+0] = tmp[i*2+0]; tmp[(FFT_SIZE-i)*2+1] = -tmp[i*2+1]; } @@ -205,7 +205,7 @@ transform_domain(void) fft256_inverse((float(*)[2])tmp); memcpy(measured[ch], tmp, sizeof(measured[0])); - for (int i = 0; i < 101; i++) { + for (int i = 0; i < POINTS_COUNT; i++) { measured[ch][i][0] /= (float)FFT_SIZE; if (is_lowpass) { measured[ch][i][1] = 0.0; @@ -214,7 +214,7 @@ transform_domain(void) } } if ( (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP ) { - for (int i = 1; i < 101; i++) { + for (int i = 1; i < POINTS_COUNT; i++) { measured[ch][i][0] += measured[ch][i-1][0]; } } @@ -420,7 +420,7 @@ int16_t dump_selection = 0; volatile int16_t wait_count = 0; -float measured[2][101][2]; +float measured[2][POINTS_COUNT][2]; static void wait_dsp(int count) @@ -605,7 +605,7 @@ properties_t current_props = { .magic = CONFIG_MAGIC, ._frequency0 = 50000, // start = 50kHz ._frequency1 = 900000000, // end = 900MHz - ._sweep_points = 101, + ._sweep_points = POINTS_COUNT, ._trace = {/*enable, type, channel, polar, scale, refpos*/ { 1, TRC_LOGMAG, 0, 0, 1.0, 9.0 }, { 1, TRC_LOGMAG, 1, 0, 1.0, 9.0 }, diff --git a/nanovna.h b/nanovna.h index 95c0187..86ee9a0 100644 --- a/nanovna.h +++ b/nanovna.h @@ -26,7 +26,8 @@ * main.c */ -extern float measured[2][101][2]; +#define POINTS_COUNT 101 +extern float measured[2][POINTS_COUNT][2]; #define CAL_LOAD 0 #define CAL_OPEN 1 @@ -142,8 +143,8 @@ extern void tlv320aic3204_select(int channel); #define CELLOFFSETX 5 #define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2) -extern int area_width; -extern int area_height; +extern int16_t area_width; +extern int16_t area_height; #define GRIDY 23 @@ -225,7 +226,7 @@ void draw_battery_status(void); void set_electrical_delay(float picoseconds); float get_electrical_delay(void); -float groupdelay_from_array(int i, float array[101][2]); +float groupdelay_from_array(int i, float array[POINTS_COUNT][2]); // marker @@ -249,7 +250,7 @@ void request_to_draw_cells_behind_menu(void); void request_to_draw_cells_behind_numeric_input(void); 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 plot_into_index(float measured[2][POINTS_COUNT][2]); void force_set_markmap(void); void draw_frequencies(void); void draw_all(bool flush); @@ -288,10 +289,13 @@ extern int16_t vbat; #define DEFAULT_MENU_COLOR RGB565(255,255,255) #define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0) #define DEFAULT_MENU_ACTIVE_COLOR RGB565(180,255,180) -#define DEFAULT_TRACE_1_COLOR RGB565( 0,255,255) -#define DEFAULT_TRACE_2_COLOR RGB565(255, 0, 40) -#define DEFAULT_TRACE_3_COLOR RGB565( 0, 0,255) -#define DEFAULT_TRACE_4_COLOR RGB565( 50,255, 0) +#define DEFAULT_TRACE_1_COLOR RGB565(255,200, 14) +#define DEFAULT_TRACE_2_COLOR RGB565( 0,191,231) +#define DEFAULT_TRACE_3_COLOR RGB565( 64,255, 0) +#define DEFAULT_TRACE_4_COLOR RGB565(255,160,100) +#define DEFAULT_NORMAL_BAT_COLOR RGB565( 31,227, 0) +#define DEFAULT_LOW_BAT_COLOR RGB565(255, 0, 0) +#define DEFAULT_SPEC_INPUT_COLOR RGB565(128,255,128); extern uint16_t foreground_color; extern uint16_t background_color; @@ -330,8 +334,8 @@ typedef struct { int16_t _sweep_points; uint16_t _cal_status; - uint32_t _frequencies[101]; - float _cal_data[5][101][2]; + uint32_t _frequencies[POINTS_COUNT]; + float _cal_data[5][POINTS_COUNT][2]; float _electrical_delay; // picoseconds trace_t _trace[TRACES_MAX]; diff --git a/plot.c b/plot.c index 7d1b47c..0b069b7 100644 --- a/plot.c +++ b/plot.c @@ -12,19 +12,15 @@ void frequency_string(char *buf, size_t len, uint32_t freq, char *prefix); void frequency_string_short(char *buf, size_t len, int32_t freq, char prefix); void markmap_all_markers(void); -//#define GRID_COLOR 0x0863 -//uint16_t grid_color = 0x1084; - /* indicate dirty cells */ uint16_t markmap[2][8]; uint16_t current_mappage = 0; -int32_t fgrid = 50000000; int16_t grid_offset; int16_t grid_width; -int area_width = AREA_WIDTH_NORMAL; -int area_height = HEIGHT+1; +int16_t area_width = AREA_WIDTH_NORMAL; +int16_t area_height = HEIGHT+1; #define GRID_RECTANGULAR (1<<0) #define GRID_SMITH (1<<1) @@ -42,7 +38,7 @@ int area_height = HEIGHT+1; * CELL_X[5:9] position in the cell * CELL_Y[0:4] */ -uint32_t trace_index[TRACES_MAX][101]; +uint32_t trace_index[TRACES_MAX][POINTS_COUNT]; #define INDEX(x, y, n) \ ((((x)&0x03e0UL)<<22) | (((y)&0x03e0UL)<<17) | (((n)&0x0fffUL)<<10) \ @@ -66,10 +62,10 @@ int floatToInt(float v){ void update_grid(void) { - int32_t gdigit = 100000000; - int32_t fstart, fspan; - int32_t grid; - if (frequency0 < frequency1) { + uint32_t gdigit = 100000000; + uint32_t fstart, fspan; + uint32_t grid; + if (frequency0 <= frequency1) { fstart = frequency0; fspan = frequency1 - frequency0; } else { @@ -89,10 +85,9 @@ void update_grid(void) break; gdigit /= 10; } - fgrid = grid; - grid_offset = (WIDTH-1) * ((fstart % fgrid) / 100) / (fspan / 100); - grid_width = (WIDTH-1) * (fgrid / 100) / (fspan / 1000); + grid_offset = (WIDTH-1) * ((fstart % grid) / 100) / (fspan / 100); + grid_width = (WIDTH-1) * (grid / 100) / (fspan / 1000); force_set_markmap(); redraw_request |= REDRAW_FREQUENCY; @@ -294,16 +289,16 @@ smith_grid2(int x, int y, float scale) #endif const int cirs[][4] = { - { 0, 58/2, 58/2, 0 }, // Constant Reactance Circle: 2j : R/2 = 58 - { 29/2, 0, 29/2, 1 }, // Constant Resistance Circle: 3 : R/4 = 29 - { 0, 115/2, 115/2, 0 }, // Constant Reactance Circle: 1j : R = 115 - { 58/2, 0, 58/2, 1 }, // Constant Resistance Circle: 1 : R/2 = 58 - { 0, 230/2, 230/2, 0 }, // Constant Reactance Circle: 1/2j : R*2 = 230 - { 86/2, 0, 86/2, 1 }, // Constant Resistance Circle: 1/3 : R*3/4 = 86 - { 0, 460/2, 460/2, 0 }, // Constant Reactance Circle: 1/4j : R*4 = 460 - { 115/2, 0, 115/2, 1 }, // Constant Resistance Circle: 0 : R - { 173/2, 0, 173/2, 1 }, // Constant Resistance Circle: -1/3 : R*3/2 = 173 - { 0, 0, 0, 0 } // sentinel + { 0, 58/2, 58/2, 0 }, // Constant Reactance Circle: 2j : R/2 = 58 + { 29/2, 0, 29/2, 1 }, // Constant Resistance Circle: 3 : R/4 = 29 + { 0, 115/2, 115/2, 0 }, // Constant Reactance Circle: 1j : R = 115 + { 58/2, 0, 58/2, 1 }, // Constant Resistance Circle: 1 : R/2 = 58 + { 0, 230/2, 230/2, 0 }, // Constant Reactance Circle: 1/2j : R*2 = 230 + { 86/2, 0, 86/2, 1 }, // Constant Resistance Circle: 1/3 : R*3/4 = 86 + { 0, 460/2, 460/2, 0 }, // Constant Reactance Circle: 1/4j : R*4 = 460 + { 115/2, 0, 115/2, 1 }, // Constant Resistance Circle: 0 : R + { 173/2, 0, 173/2, 1 }, // Constant Resistance Circle: -1/3 : R*3/2 = 173 + { 0, 0, 0, 0 } // sentinel }; int @@ -498,28 +493,16 @@ cartesian_scale(float re, float im, int *xp, int *yp, float scale) } float -groupdelay_from_array(int i, float array[101][2]) +groupdelay_from_array(int i, float array[POINTS_COUNT][2]) { -/* - if (i == 0) { - float deltaf = frequencies[1] - frequencies[0]; - return groupdelay(array[0], array[1], deltaf); - } else if (i == 100) { - float deltaf = frequencies[i] - frequencies[i-1]; - return groupdelay(array[i-1], array[i], deltaf); - } else { - float deltaf = frequencies[i+1] - frequencies[i-1]; - return groupdelay(array[i-1], array[i+1], deltaf); - } -*/ int bottom = (i == 0) ? 0 : i - 1; - int top = (i == 100) ? 100 : i + 1; + int top = (i == POINTS_COUNT-1) ? POINTS_COUNT-1 : i + 1; float deltaf = frequencies[top] - frequencies[bottom]; return groupdelay(array[bottom], array[top], deltaf); } uint32_t -trace_into_index(int x, int t, int i, float array[101][2]) +trace_into_index(int x, int t, int i, float array[POINTS_COUNT][2]) { int y = 0; float v = 0; @@ -626,7 +609,6 @@ string_value_with_prefix(char *buf, int len, float val, char unit) return n; } - #define PI2 6.283184 static void @@ -704,7 +686,7 @@ gamma2reactance(char *buf, int len, const float coeff[2]) } static void -trace_get_value_string(int t, char *buf, int len, float array[101][2], int i) +trace_get_value_string(int t, char *buf, int len, float array[POINTS_COUNT][2], int i) { float *coeff = array[i]; float v; @@ -758,7 +740,7 @@ trace_get_value_string(int t, char *buf, int len, float array[101][2], int i) } static void -trace_get_value_string_delta(int t, char *buf, int len, float array[101][2], int index, int index_ref) +trace_get_value_string_delta(int t, char *buf, int len, float array[POINTS_COUNT][2], int index, int index_ref) { float *coeff = array[index]; float *coeff_ref = array[index_ref]; @@ -928,11 +910,11 @@ mark_cells_from_index(void) } } -void plot_into_index(float measured[2][101][2]) +void plot_into_index(float measured[2][POINTS_COUNT][2]) { int i, t; for (i = 0; i < sweep_points; i++) { - int x = i * (WIDTH-1) / (sweep_points-1); + int x = (i * (WIDTH-1) + sweep_points/2) / (sweep_points-1); for (t = 0; t < TRACES_MAX; t++) { if (!trace[t].enabled) continue; @@ -1026,7 +1008,7 @@ cell_drawline(int w, int h, int x0, int y0, int x1, int y1, int c) } int -search_index_range(int x, int y, uint32_t index[101], int *i0, int *i1) +search_index_range(int x, int y, uint32_t index[POINTS_COUNT], int *i0, int *i1) { int i, j; int head = 0; @@ -1056,14 +1038,14 @@ search_index_range(int x, int y, uint32_t index[101], int *i0, int *i1) j--; *i0 = j; j = i; - while (j < 100 && x == CELL_X0(index[j+1]) && y == CELL_Y0(index[j+1])) + while (j < POINTS_COUNT-1 && x == CELL_X0(index[j+1]) && y == CELL_Y0(index[j+1])) j++; *i1 = j; return TRUE; } static int -search_index_range_x(int x, uint32_t index[101], int *i0, int *i1) +search_index_range_x(int x, uint32_t index[POINTS_COUNT], int *i0, int *i1) { int i, j; int head = 0; @@ -1093,7 +1075,7 @@ search_index_range_x(int x, uint32_t index[101], int *i0, int *i1) j--; *i0 = j; j = i; - while (j < 100 && x == CELL_X0(index[j+1])) + while (j < POINTS_COUNT-1 && x == CELL_X0(index[j+1])) j++; *i1 = j; return TRUE; @@ -1238,7 +1220,7 @@ marker_search(void) return -1; int value = CELL_Y(trace_index[uistat.current_trace][0]); - for (i = 0; i < 101; i++) { + for (i = 0; i < POINTS_COUNT; i++) { uint32_t index = trace_index[uistat.current_trace][i]; if ((*compare)(value, CELL_Y(index))) { value = CELL_Y(index); @@ -1296,14 +1278,14 @@ marker_search_right(int from) return -1; int value = CELL_Y(trace_index[uistat.current_trace][from]); - for (i = from + 1; i < 101; i++) { + for (i = from + 1; i < POINTS_COUNT; i++) { uint32_t index = trace_index[uistat.current_trace][i]; if ((*compare)(value, CELL_Y(index))) break; value = CELL_Y(index); } - for (; i < 101; i++) { + for (; i < POINTS_COUNT; i++) { uint32_t index = trace_index[uistat.current_trace][i]; if ((*compare)(CELL_Y(index), value)) { break; @@ -1482,7 +1464,7 @@ draw_cell(int m, int n) if (search_index_range_x(x0, trace_index[t], &i0, &i1)) { if (i0 > 0) i0--; - if (i1 < 101-1) + if (i1 < POINTS_COUNT-1) i1++; for (i = i0; i < i1; i++) { int x1 = CELL_X(trace_index[t][i]); @@ -1665,10 +1647,10 @@ cell_draw_marker_info(int m, int n, int w, int h) if (mk == active_marker) cell_drawstring(w, h, S_SARROW, xpos, ypos); xpos += 5; - chsnprintf(buf, sizeof buf, "MK%d", mk); + chsnprintf(buf, sizeof buf, "M%d", mk+1); cell_drawstring(w, h, buf, xpos, ypos); - xpos += 19; + xpos += 13; //trace_get_info(t, buf, sizeof buf); int32_t freq = frequencies[markers[mk].index]; if (uistat.marker_delta && mk != active_marker) { @@ -1691,7 +1673,7 @@ cell_draw_marker_info(int m, int n, int w, int h) // draw marker delta if (!uistat.marker_delta && previous_marker >= 0 && active_marker != previous_marker && markers[previous_marker].enabled) { int idx0 = markers[previous_marker].index; - int xpos = 192; + int xpos = 185; int ypos = 1 + (j/2)*8; xpos -= m * CELLWIDTH -CELLOFFSETX; ypos -= n * CELLHEIGHT; @@ -1701,7 +1683,8 @@ cell_draw_marker_info(int m, int n, int w, int h) cell_drawstring(w, h, buf, xpos, ypos); xpos += 19; if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { - frequency_string(buf, sizeof buf, frequencies[idx] - frequencies[idx0], ""); + uint32_t delta = frequencies[idx] > frequencies[idx0] ? frequencies[idx]-frequencies[idx0] : frequencies[idx0]-frequencies[idx]; + frequency_string(buf, sizeof buf, delta, ""); } else { //chsnprintf(buf, sizeof buf, "%d ns %.1f m", (uint16_t)(time_of_index(idx) * 1e9 - time_of_index(idx0) * 1e9), // distance_of_index(idx) - distance_of_index(idx0)); @@ -1742,10 +1725,11 @@ cell_draw_marker_info(int m, int n, int w, int h) } // draw marker frequency - int xpos = 192; + int xpos = 185; int ypos = 1 + (j/2)*8; xpos -= m * CELLWIDTH -CELLOFFSETX; ypos -= n * CELLHEIGHT; + setForegroundColor(DEFAULT_FG_COLOR); // strcpy(buf, "1:"); // buf[0] += active_marker; // xpos += 5; @@ -1755,7 +1739,7 @@ cell_draw_marker_info(int m, int n, int w, int h) if (uistat.lever_mode == LM_MARKER) cell_drawstring(w, h, S_SARROW, xpos, ypos); xpos += 5; - chsnprintf(buf, sizeof buf, "1:%d", active_marker); + chsnprintf(buf, sizeof buf, "M%d:", active_marker+1); cell_drawstring(w, h, buf, xpos, ypos); xpos += 19; @@ -1840,31 +1824,29 @@ frequency_string_short(char *b, size_t len, int32_t freq, char prefix) void draw_frequencies(void) { - char buf1[24];buf1[0]=' '; - char buf2[24]; - if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { - if (frequency0 < frequency1) { - frequency_string(buf1+1, sizeof(buf1)-1, frequency0, "START "); - frequency_string(buf2, sizeof buf2, frequency1, "STOP "); - } else if (frequency0 > frequency1) { - frequency_string(buf1+1, sizeof(buf1)-1, frequency0/2 + frequency1/2, "CENTER "); - frequency_string(buf2, sizeof buf2, frequency0 - frequency1, "SPAN "); - } else { - frequency_string(buf1+1, sizeof(buf1)-1, frequency0, "CW "); - } - - } else { - chsnprintf(buf1, sizeof buf1, "START 0s"); - chsnprintf(buf2, sizeof buf2, "%s%d ns", "STOP ", (uint16_t)(time_of_index(101) * 1e9)); - } - setForegroundColor(DEFAULT_FG_COLOR); - setBackgroundColor(DEFAULT_BG_COLOR); - ili9341_fill(0, 232, 320, 8, DEFAULT_BG_COLOR); - if (uistat.lever_mode == LM_SPAN || uistat.lever_mode == LM_CENTER) - buf1[0] = S_SARROW[0]; - ili9341_drawstring(buf1, OFFSETX, 232); - ili9341_drawstring(buf2, 205, 232); - + char buf1[24];buf1[0]=' '; + char buf2[24];buf2[0]=0; + if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { + if (frequency0 < frequency1) { + frequency_string(buf1+1, sizeof(buf1)-1, frequency0, "START "); + frequency_string(buf2, sizeof buf2, frequency1, "STOP "); + } else if (frequency0 > frequency1) { + frequency_string(buf1+1, sizeof(buf1)-1, frequency0/2 + frequency1/2, "CENTER "); + frequency_string(buf2, sizeof buf2, frequency0 - frequency1, "SPAN "); + } else { + frequency_string(buf1+1, sizeof(buf1)-1, frequency0, "CW "); + } + } else { + chsnprintf(buf1+1, sizeof(buf1)-1, "START 0s"); + chsnprintf(buf2, sizeof buf2, "%s%dns (%.2fm)", "STOP ", (uint16_t)(time_of_index(POINTS_COUNT-1) * 1e9), distance_of_index(POINTS_COUNT-1)); + } + setForegroundColor(DEFAULT_FG_COLOR); + setBackgroundColor(DEFAULT_BG_COLOR); + ili9341_fill(0, 232, 320, 8, DEFAULT_BG_COLOR); + if (uistat.lever_mode == LM_SPAN || uistat.lever_mode == LM_CENTER) + buf1[0] = S_SARROW[0]; + ili9341_drawstring(buf1, OFFSETX, 232); + ili9341_drawstring(buf2, 205, 232); } void @@ -1919,7 +1901,7 @@ draw_battery_status(void) { uint8_t string_buf[25]; // Set battery color - setForegroundColor(vbat < BATTERY_WARNING_LEVEL ? RGBHEX(0xff0000) : RGBHEX(0x1fe300)); + setForegroundColor(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR); setBackgroundColor(DEFAULT_BG_COLOR); // chsnprintf(string_buf, sizeof string_buf, "V:%d", vbat); // ili9341_drawstringV(string_buf, 1, 60); diff --git a/ui.c b/ui.c index 651bd9d..f35f504 100644 --- a/ui.c +++ b/ui.c @@ -33,7 +33,6 @@ uistat_t uistat = { marker_delta: FALSE, }; - #define NO_EVENT 0 #define EVT_BUTTON_SINGLE_CLICK 0x01 #define EVT_BUTTON_DOUBLE_CLICK 0x02 @@ -72,9 +71,9 @@ enum { KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY }; -uint8_t ui_mode = UI_NORMAL; -uint8_t keypad_mode; -int8_t selection = 0; +static uint8_t ui_mode = UI_NORMAL; +static uint8_t keypad_mode; +static int8_t selection = 0; // Set structure align as WORD (save flash memory) #pragma pack(push, 2) @@ -86,9 +85,11 @@ typedef struct { } menuitem_t; #pragma pack(pop) -int8_t last_touch_status = FALSE; -int16_t last_touch_x; -int16_t last_touch_y; +// Touch screen +static int8_t last_touch_status = FALSE; +static int16_t last_touch_x; +static int16_t last_touch_y; + //int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 }; //int16_t touch_cal[4] = { 620, 600, 130, 180 }; #define EVT_TOUCH_NONE 0 @@ -108,7 +109,6 @@ int awd_count; char kp_buf[11]; int8_t kp_index = 0; - void ui_mode_normal(void); void ui_mode_menu(void); void ui_mode_numeric(int _keypad_mode); @@ -439,7 +439,6 @@ enter_dfu(void) NVIC_SystemReset(); } - // type of menu item enum { MT_NONE, @@ -515,27 +514,27 @@ menu_config_cb(int item, uint8_t data) switch (item) { case 0: touch_cal_exec(); - redraw_frame(); - request_to_redraw_grid(); - draw_menu(); break; case 1: touch_draw_test(); - redraw_frame(); - request_to_redraw_grid(); - draw_menu(); - break; - case 2: - config_save(); - menu_move_back(); - ui_mode_normal(); break; case 3: show_version(); - redraw_frame(); - request_to_redraw_grid(); - draw_menu(); + break; } + redraw_frame(); + request_to_redraw_grid(); + draw_menu(); +} + +static void +menu_config_save_cb(int item, uint8_t data) +{ + (void)item; + (void)data; + config_save(); + menu_move_back(); + ui_mode_normal(); } static void @@ -574,6 +573,7 @@ choose_active_trace(void) static void menu_trace_cb(int item, uint8_t data) { + (void)item; if (trace[data].enabled) { if (data == uistat.current_trace) { // disable if active trace is selected @@ -581,11 +581,11 @@ menu_trace_cb(int item, uint8_t data) choose_active_trace(); } else { // make active selected trace - uistat.current_trace = item; + uistat.current_trace = data; } } else { trace[data].enabled = TRUE; - uistat.current_trace = item; + uistat.current_trace = data; } request_to_redraw_grid(); draw_menu(); @@ -712,46 +712,40 @@ menu_stimulus_cb(int item, uint8_t data) } -static int32_t +static uint32_t get_marker_frequency(int marker) { if (marker < 0 || marker >= 4) - return -1; + return 0; if (!markers[marker].enabled) - return -1; + return 0; return frequencies[markers[marker].index]; } static void menu_marker_op_cb(int item, uint8_t data) { - (void)data; - int32_t freq = get_marker_frequency(active_marker); - if (freq < 0) + uint32_t freq = get_marker_frequency(active_marker); + if (freq == 0) return; // no active marker switch (item) { case 0: /* MARKER->START */ - set_sweep_frequency(ST_START, freq); - break; case 1: /* MARKER->STOP */ - set_sweep_frequency(ST_STOP, freq); - break; case 2: /* MARKER->CENTER */ - set_sweep_frequency(ST_CENTER, freq); + set_sweep_frequency(data, freq); break; case 3: /* MARKERS->SPAN */ { if (previous_marker == -1 || active_marker == previous_marker) { - // if only 1 marker is active, keep center freq and make span the marker comes to the edge - int32_t center = get_sweep_frequency(ST_CENTER); - int32_t span = center - freq; - if (span < 0) span = -span; + // if only 1 marker is active, keep center freq and make span the marker comes to the edge + uint32_t center = get_sweep_frequency(ST_CENTER); + uint32_t span = center > freq ? center - freq : freq - center; set_sweep_frequency(ST_SPAN, span * 2); } else { // if 2 or more marker active, set start and stop freq to each marker - int32_t freq2 = get_marker_frequency(previous_marker); - if (freq2 < 0) + uint32_t freq2 = get_marker_frequency(previous_marker); + if (freq2 == 0) return; if (freq > freq2) { freq2 = freq; @@ -792,25 +786,22 @@ menu_marker_search_cb(int item, uint8_t data) i = marker_search(); if (i != -1) markers[active_marker].index = i; - draw_menu(); break; case 2: /* search Left */ i = marker_search_left(markers[active_marker].index); if (i != -1) markers[active_marker].index = i; - draw_menu(); break; case 3: /* search right */ i = marker_search_right(markers[active_marker].index); if (i != -1) markers[active_marker].index = i; - draw_menu(); break; case 4: /* tracking */ marker_tracking = !marker_tracking; - draw_menu(); break; } + draw_menu(); redraw_marker(active_marker, TRUE); uistat.lever_mode = LM_SEARCH; } @@ -943,7 +934,6 @@ const menuitem_t menu_scale[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; - const menuitem_t menu_channel[] = { { MT_CALLBACK, 0, "\2CH0\0REFLECT", menu_channel_cb }, { MT_CALLBACK, 1, "\2CH1\0THROUGH", menu_channel_cb }, @@ -1003,10 +993,10 @@ const menuitem_t menu_marker_sel[] = { }; const menuitem_t menu_marker_ops[] = { - { MT_CALLBACK, 0, S_RARROW"START", menu_marker_op_cb }, - { MT_CALLBACK, 0, S_RARROW"STOP", menu_marker_op_cb }, - { MT_CALLBACK, 0, S_RARROW"CENTER", menu_marker_op_cb }, - { MT_CALLBACK, 0, S_RARROW"SPAN", menu_marker_op_cb }, + { MT_CALLBACK, ST_START, S_RARROW"START", menu_marker_op_cb }, + { MT_CALLBACK, ST_STOP, S_RARROW"STOP", menu_marker_op_cb }, + { MT_CALLBACK, ST_CENTER, S_RARROW"CENTER", menu_marker_op_cb }, + { MT_CALLBACK, ST_SPAN, S_RARROW"SPAN", menu_marker_op_cb }, { MT_CALLBACK, 0, S_RARROW"EDELAY", menu_marker_op_cb }, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel @@ -1061,7 +1051,7 @@ const menuitem_t menu_dfu[] = { const menuitem_t menu_config[] = { { MT_CALLBACK, 0, "TOUCH CAL", menu_config_cb }, { MT_CALLBACK, 0, "TOUCH TEST", menu_config_cb }, - { MT_CALLBACK, 0, "SAVE", menu_config_cb }, + { MT_CALLBACK, 0, "SAVE", menu_config_save_cb }, { MT_CALLBACK, 0, "VERSION", menu_config_cb }, { MT_SUBMENU, 0, S_RARROW"DFU", menu_dfu }, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, @@ -1081,7 +1071,7 @@ const menuitem_t menu_top[] = { #define MENU_STACK_DEPTH_MAX 4 uint8_t menu_current_level = 0; const menuitem_t *menu_stack[4] = { - menu_top, 0, NULL, NULL, NULL + menu_top, NULL, NULL, NULL }; static void @@ -1174,10 +1164,13 @@ void menu_invoke(int item) #define KP_N 21 #define KP_P 22 +// Set struct data align as BYTE for save flash memory +#pragma pack(push, 1) typedef struct { uint16_t x, y; int8_t c; } keypads_t; +#pragma pack(pop) const keypads_t *keypads; uint8_t keypads_last_index; @@ -1303,7 +1296,7 @@ draw_numeric_input(const char *buf) c = -1; if (uistat.digit == 8-i) { - fg = RGB565(128,255,128); + fg = DEFAULT_SPEC_INPUT_COLOR; focused = TRUE; if (uistat.digit_mode) bg = DEFAULT_MENU_COLOR; @@ -1487,8 +1480,7 @@ erase_menu_buttons(void) void erase_numeric_input(void) { - uint16_t bg = 0; - ili9341_fill(0, 240-32, 320, 32, bg); + ili9341_fill(0, 240-32, 320, 32, DEFAULT_BG_COLOR); } void @@ -1578,7 +1570,7 @@ void set_numeric_value(void) set_electrical_delay(uistat.value); break; case KM_VELOCITY_FACTOR: - velocity_factor = uistat.value; + velocity_factor = uistat.value/100.0; break; } } @@ -1591,7 +1583,6 @@ draw_numeric_area(void) draw_numeric_input(buf); } - void ui_mode_menu(void) { @@ -1725,12 +1716,11 @@ lever_zoom_span(int status) uint32_t span = get_sweep_frequency(ST_SPAN); if (status & EVT_UP) { span = step_round(span - 1); - set_sweep_frequency(ST_SPAN, span); } else if (status & EVT_DOWN) { span = step_round(span + 1); span = step_round(span * 3); - set_sweep_frequency(ST_SPAN, span); } + set_sweep_frequency(ST_SPAN, span); } static void