Merge pull request #121 from DiSlord/master

Fix crash on trace command, reduce flash usage by 8k, up to 2x faster screen render
damib-autoscale
TT 6 years ago committed by GitHub
commit f6b28c2c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,6 +11,7 @@
#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)
#define FONT_MAX_WIDTH 7
#define FONT_GET_HEIGHT 7 #define FONT_GET_HEIGHT 7
#define CHAR5x7_WIDTH_1px 0x07 #define CHAR5x7_WIDTH_1px 0x07

@ -100,9 +100,9 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk
include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk
# Other files (optional). # Other files (optional).
include $(CHIBIOS)/test/rt/test.mk #include $(CHIBIOS)/test/rt/test.mk
include $(CHIBIOS)/os/hal/lib/streams/streams.mk include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk #include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here # Define linker script file here
#LDSCRIPT= $(STARTUPLD)/STM32F072xB.ld #LDSCRIPT= $(STARTUPLD)/STM32F072xB.ld

@ -156,7 +156,7 @@
* *
* @note The default is @p TRUE. * @note The default is @p TRUE.
*/ */
#define CH_CFG_USE_WAITEXIT TRUE #define CH_CFG_USE_WAITEXIT FALSE
/** /**
* @brief Semaphores APIs. * @brief Semaphores APIs.
@ -193,7 +193,7 @@
* @note The default is @p FALSE. * @note The default is @p FALSE.
* @note Requires @p CH_CFG_USE_MUTEXES. * @note Requires @p CH_CFG_USE_MUTEXES.
*/ */
#define CH_CFG_USE_MUTEXES_RECURSIVE TRUE #define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
/** /**
* @brief Conditional Variables APIs. * @brief Conditional Variables APIs.
@ -221,7 +221,7 @@
* *
* @note The default is @p TRUE. * @note The default is @p TRUE.
*/ */
#define CH_CFG_USE_EVENTS TRUE #define CH_CFG_USE_EVENTS FALSE
/** /**
* @brief Events Flags APIs with timeout. * @brief Events Flags APIs with timeout.
@ -231,7 +231,7 @@
* @note The default is @p TRUE. * @note The default is @p TRUE.
* @note Requires @p CH_CFG_USE_EVENTS. * @note Requires @p CH_CFG_USE_EVENTS.
*/ */
#define CH_CFG_USE_EVENTS_TIMEOUT TRUE #define CH_CFG_USE_EVENTS_TIMEOUT FALSE
/** /**
* @brief Synchronous Messages APIs. * @brief Synchronous Messages APIs.

@ -29,7 +29,7 @@
#include "hal.h" #include "hal.h"
#include "chprintf.h" #include "chprintf.h"
#include "memstreams.h" //#include "memstreams.h"
#include <math.h> #include <math.h>
// Enable [flags], support: // Enable [flags], support:
@ -56,7 +56,6 @@ static char smallPrefix[]= { 'm', 0x1d, 'n', 'p', 'f', 'a', 'z', 'y',
#pragma pack(pop) #pragma pack(pop)
//86066 5116 11456 102622 190de build/ch.elf
static char *long_to_string_with_divisor(char *p, static char *long_to_string_with_divisor(char *p,
uint32_t num, uint32_t num,
uint32_t radix, uint32_t radix,
@ -467,6 +466,7 @@ unsigned_common:/*
* *
* @api * @api
*/ */
#if 0
int chprintf(BaseSequentialStream *chp, const char *fmt, ...) { int chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
va_list ap; va_list ap;
int formatted_bytes; int formatted_bytes;
@ -477,7 +477,7 @@ int chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
return formatted_bytes; return formatted_bytes;
} }
#endif
/** /**
* @brief System formatted output function. * @brief System formatted output function.
* @details This function implements a minimal @p vprintf()-like functionality * @details This function implements a minimal @p vprintf()-like functionality
@ -506,6 +506,7 @@ int chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
* *
* @api * @api
*/ */
#if 0
int chsnprintf(char *str, size_t size, const char *fmt, ...) { int chsnprintf(char *str, size_t size, const char *fmt, ...) {
va_list ap; va_list ap;
MemoryStream ms; MemoryStream ms;
@ -535,5 +536,52 @@ int chsnprintf(char *str, size_t size, const char *fmt, ...) {
/* Return number of bytes that would have been written.*/ /* Return number of bytes that would have been written.*/
return retval; return retval;
} }
#endif
//
// Small memory stream object, only put function
//
struct printStreamVMT {
_base_sequential_stream_methods
};
typedef struct {
const struct printStreamVMT *vmt;
uint8_t *buffer;
uint16_t size;
} printStream;
static msg_t put(void *ip, uint8_t b) {
printStream *ps = ip;
if (ps->size > 1){
*(ps->buffer++) = b;
ps->size--;
}
return MSG_OK;
}
static const struct printStreamVMT vmt = {NULL, NULL, put, NULL};
void printObjectInit(printStream *ps, int size, uint8_t *buffer){
ps->vmt = &vmt;
ps->buffer = buffer;
ps->size = size;
}
// Simple print in buffer function
int plot_printf(char *str, int size, const char *fmt, ...) {
va_list ap;
printStream ps;
int retval;
if (size <= 0) return 0;
// Init small memory stream for print
printObjectInit(&ps, size, (uint8_t *)str);
// Performing the print operation using the common code.
va_start(ap, fmt);
retval = chvprintf((BaseSequentialStream *)(void *)&ps, fmt, ap);
va_end(ap);
*(ps.buffer)=0;
if (retval > size-1) retval = size-1;
// Return number of bytes that would have been written.
return retval;
}
/** @} */ /** @} */

@ -64,8 +64,6 @@ void flash_unlock(void)
FLASH->KEYR = 0xCDEF89AB; FLASH->KEYR = 0xCDEF89AB;
} }
#define rotate(x) (((x)<<1) | ((x)&(1<<31)?1:0))
static uint32_t static uint32_t
checksum(const void *start, size_t len) checksum(const void *start, size_t len)
{ {
@ -73,14 +71,14 @@ checksum(const void *start, size_t len)
uint32_t *tail = (uint32_t*)(start + len); uint32_t *tail = (uint32_t*)(start + len);
uint32_t value = 0; uint32_t value = 0;
while (p < tail) while (p < tail)
value = rotate(value) + *p++; value = __ROR(value, 31) + *p++;
return value; return value;
} }
#define FLASH_PAGESIZE 0x800 #define FLASH_PAGESIZE 0x800
const uint32_t save_config_area = 0x08018000; const uint32_t save_config_area = SAVE_CONFIG_ADDR;
int int
config_save(void) config_save(void)
@ -122,14 +120,15 @@ config_recall(void)
return 0; return 0;
} }
#define SAVEAREA_MAX 5 const uint32_t saveareas[SAVEAREA_MAX] = {
SAVE_PROP_CONFIG_0_ADDR,
const uint32_t saveareas[] = SAVE_PROP_CONFIG_1_ADDR,
{ 0x08018800, 0x0801a000, 0x0801b800, 0x0801d000, 0x0801e800 }; SAVE_PROP_CONFIG_2_ADDR,
SAVE_PROP_CONFIG_3_ADDR,
SAVE_PROP_CONFIG_4_ADDR };
int16_t lastsaveid = 0; int16_t lastsaveid = 0;
int int
caldata_save(int id) caldata_save(int id)
{ {
@ -174,15 +173,15 @@ caldata_recall(int id)
void *dst = &current_props; void *dst = &current_props;
if (id < 0 || id >= SAVEAREA_MAX) if (id < 0 || id >= SAVEAREA_MAX)
return -1; goto load_default;
// point to saved area on the flash memory // point to saved area on the flash memory
src = (properties_t*)saveareas[id]; src = (properties_t*)saveareas[id];
if (src->magic != CONFIG_MAGIC) if (src->magic != CONFIG_MAGIC)
return -1; goto load_default;
if (checksum(src, sizeof *src - sizeof src->checksum) != src->checksum) if (checksum(src, sizeof *src - sizeof src->checksum) != src->checksum)
return -1; goto load_default;
/* active configuration points to save data on flash memory */ /* active configuration points to save data on flash memory */
active_props = src; active_props = src;
@ -190,8 +189,10 @@ caldata_recall(int id)
/* duplicated saved data onto sram to be able to modify marker/trace */ /* duplicated saved data onto sram to be able to modify marker/trace */
memcpy(dst, src, sizeof(properties_t)); memcpy(dst, src, sizeof(properties_t));
return 0; return 0;
load_default:
loadDefaultProps();
return -1;
} }
const properties_t * const properties_t *
@ -209,7 +210,7 @@ caldata_ref(int id)
return src; return src;
} }
const uint32_t save_config_prop_area_size = 0x8000; const uint32_t save_config_prop_area_size = SAVE_CONFIG_AREA_SIZE;
void void
clear_all_config_prop_data(void) clear_all_config_prop_data(void)

@ -118,7 +118,7 @@
* @brief Enables the RTC subsystem. * @brief Enables the RTC subsystem.
*/ */
#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) #if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
#define HAL_USE_RTC TRUE #define HAL_USE_RTC FALSE
#endif #endif
/** /**

@ -21,7 +21,7 @@
#include "hal.h" #include "hal.h"
#include "nanovna.h" #include "nanovna.h"
uint16_t spi_buffer[2048]; uint16_t spi_buffer[SPI_BUFFER_SIZE];
// 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;
@ -487,6 +487,10 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
} }
#endif #endif
void clearScreen(void){
ili9341_fill(0, 0, ILI9341_WIDTH, ILI9341_HEIGHT, background_color);
}
void setForegroundColor(uint16_t fg) {foreground_color = fg;} void setForegroundColor(uint16_t fg) {foreground_color = fg;}
void setBackgroundColor(uint16_t bg) {background_color = bg;} void setBackgroundColor(uint16_t bg) {background_color = bg;}

870
main.c

File diff suppressed because it is too large Load Diff

@ -25,6 +25,8 @@
/* /*
* main.c * main.c
*/ */
#define START_MIN 50000
#define STOP_MAX 2700000000U
#define POINTS_COUNT 101 #define POINTS_COUNT 101
extern float measured[2][POINTS_COUNT][2]; extern float measured[2][POINTS_COUNT][2];
@ -71,8 +73,9 @@ extern float measured[2][POINTS_COUNT][2];
void cal_collect(int type); void cal_collect(int type);
void cal_done(void); void cal_done(void);
#define MAX_FREQ_TYPE 5
enum { enum {
ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW ST_START=0, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
}; };
void set_sweep_frequency(int type, uint32_t frequency); void set_sweep_frequency(int type, uint32_t frequency);
@ -81,9 +84,25 @@ uint32_t get_sweep_frequency(int type);
double my_atof(const char *p); double my_atof(const char *p);
void toggle_sweep(void); void toggle_sweep(void);
void loadDefaultProps(void);
extern int8_t sweep_enabled; extern int8_t sweep_enabled;
/*
* flash.c
*/
#define SAVEAREA_MAX 5
// Begin addr 0x08018000
#define SAVE_CONFIG_AREA_SIZE 0x00008000
// config save area
#define SAVE_CONFIG_ADDR 0x08018000
// properties_t save area
#define SAVE_PROP_CONFIG_0_ADDR 0x08018800
#define SAVE_PROP_CONFIG_1_ADDR 0x0801a000
#define SAVE_PROP_CONFIG_2_ADDR 0x0801b800
#define SAVE_PROP_CONFIG_3_ADDR 0x0801d000
#define SAVE_PROP_CONFIG_4_ADDR 0x0801e800
/* /*
* ui.c * ui.c
*/ */
@ -144,7 +163,7 @@ extern void tlv320aic3204_select(int channel);
#define FREQUENCIES_XPOS1 OFFSETX #define FREQUENCIES_XPOS1 OFFSETX
#define FREQUENCIES_XPOS2 200 #define FREQUENCIES_XPOS2 200
#define FREQUENCIES_YPOS (HEIGHT+1) #define FREQUENCIES_YPOS (240-7)
// GRIDX calculated depends from frequency span // GRIDX calculated depends from frequency span
//#define GRIDY 29 //#define GRIDY 29
@ -167,6 +186,7 @@ extern int16_t area_height;
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))
#define FONT_MAX_WIDTH 7
#define FONT_GET_HEIGHT 7 #define FONT_GET_HEIGHT 7
extern const uint16_t numfont16x22[]; extern const uint16_t numfont16x22[];
@ -187,8 +207,9 @@ extern const uint16_t numfont16x22[];
#define TRACES_MAX 4 #define TRACES_MAX 4
#define MAX_TRACE_TYPE 12
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=0, 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 // 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)) #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))
@ -220,7 +241,7 @@ typedef struct {
uint16_t menu_active_color; uint16_t menu_active_color;
uint16_t trace_color[TRACES_MAX]; uint16_t trace_color[TRACES_MAX];
int16_t touch_cal[4]; int16_t touch_cal[4];
int8_t default_loadcal; int8_t reserved_1;
uint32_t harmonic_freq_threshold; uint32_t harmonic_freq_threshold;
uint8_t _reserved[24]; uint8_t _reserved[24];
@ -298,6 +319,9 @@ extern int16_t vbat;
#define RGB565(r,g,b) ( (((g)&0x1c)<<11) | (((b)&0xf8)<<5) | ((r)&0xf8) | (((g)&0xe0)>>5) ) #define RGB565(r,g,b) ( (((g)&0x1c)<<11) | (((b)&0xf8)<<5) | ((r)&0xf8) | (((g)&0xe0)>>5) )
#define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) ) #define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) )
// Define size of screen buffer in pixels (one pixel 16bit size)
#define SPI_BUFFER_SIZE 2048
#define DEFAULT_FG_COLOR RGB565(255,255,255) #define DEFAULT_FG_COLOR RGB565(255,255,255)
#define DEFAULT_BG_COLOR RGB565( 0, 0, 0) #define DEFAULT_BG_COLOR RGB565( 0, 0, 0)
#define DEFAULT_GRID_COLOR RGB565(128,128,128) #define DEFAULT_GRID_COLOR RGB565(128,128,128)
@ -315,7 +339,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[2048]; extern uint16_t spi_buffer[SPI_BUFFER_SIZE];
void ili9341_init(void); void ili9341_init(void);
//void ili9341_setRotation(uint8_t r); //void ili9341_setRotation(uint8_t r);
@ -324,6 +348,7 @@ void ili9341_bulk(int x, int y, int w, int h);
void ili9341_fill(int x, int y, int w, int h, int color); void ili9341_fill(int x, int y, int w, int h, int color);
void setForegroundColor(uint16_t fg); void setForegroundColor(uint16_t fg);
void setBackgroundColor(uint16_t fg); void setBackgroundColor(uint16_t fg);
void clearScreen(void);
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap); void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap);
void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap); void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap);
void ili9341_drawchar(uint8_t ch, int x, int y); void ili9341_drawchar(uint8_t ch, int x, int y);
@ -458,6 +483,10 @@ int16_t adc_vbat_read(ADC_TypeDef *adc);
/* /*
* misclinous * misclinous
*/ */
int plot_printf(char *str, int, const char *fmt, ...);
#define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0) #define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0)
// Speed profile definition
#define START_PROFILE systime_t time = chVTGetSystemTimeX();
#define STOP_PROFILE {char string_buf[12];plot_printf(string_buf, sizeof string_buf, "T:%06d", chVTGetSystemTimeX() - time);ili9341_drawstringV(string_buf, 1, 60);}
/*EOF*/ /*EOF*/

@ -98,8 +98,8 @@ const uint16_t numfont16x22[] = {
0b0111111111111110, 0b0111111111111110,
0b0111110000111110, 0b0111110000111110,
0b1111100000011111, 0b1111100000011111,
0b1111000000011111, 0b1111000000001111,
0b1111000000011111, 0b1111000000001111,
0b0000000000011110, 0b0000000000011110,
0b0000000000111110, 0b0000000000111110,
0b0000000111111100, 0b0000000111111100,
@ -305,7 +305,7 @@ const uint16_t numfont16x22[] = {
0b0000000000001111, 0b0000000000001111,
0b0000000000011111, 0b0000000000011111,
0b0000000000111111, 0b0000000000111111,
0b0000000000111111, 0b0000000001111111,
0b0000000000001111, 0b0000000000001111,
0b0000000000001111, 0b0000000000001111,
0b0000000000001111, 0b0000000000001111,
@ -381,10 +381,10 @@ const uint16_t numfont16x22[] = {
0b1111000000000000, 0b1111000000000000,
0b1111000000000000, 0b1111000000000000,
0b1111000000000000, 0b1111000000000000,
0b1111000000000000, 0b1111000000111111,
0b1111000001111111, 0b1111000000111111,
0b1111000001111111, 0b1111000000111111,
0b1111000001111111, 0b1111000000000111,
0b1111000000001111, 0b1111000000001111,
0b1111100000011111, 0b1111100000011111,
0b0111110000111111, 0b0111110000111111,

426
plot.c

@ -5,7 +5,7 @@
#include "chprintf.h" #include "chprintf.h"
#include "nanovna.h" #include "nanovna.h"
static void cell_draw_marker_info(int m, int n, int w, int h); static void cell_draw_marker_info(int x0, int y0);
int16_t grid_offset; int16_t grid_offset;
int16_t grid_width; int16_t grid_width;
@ -16,6 +16,10 @@ int16_t area_height = AREA_HEIGHT_NORMAL;
// Depends from spi_buffer size, CELLWIDTH*CELLHEIGHT <= sizeof(spi_buffer) // Depends from spi_buffer size, CELLWIDTH*CELLHEIGHT <= sizeof(spi_buffer)
#define CELLWIDTH (64) #define CELLWIDTH (64)
#define CELLHEIGHT (32) #define CELLHEIGHT (32)
// Check buffer size
#if CELLWIDTH*CELLHEIGHT > SPI_BUFFER_SIZE
#error "Too small spi_buffer size SPI_BUFFER_SIZE < CELLWIDTH*CELLHEIGH"
#endif
// indicate dirty cells (not redraw if cell data not changed) // indicate dirty cells (not redraw if cell data not changed)
#define MAX_MARKMAP_X ((320+CELLWIDTH-1)/CELLWIDTH) #define MAX_MARKMAP_X ((320+CELLWIDTH-1)/CELLWIDTH)
@ -565,23 +569,23 @@ format_smith_value(char *buf, int len, const float coeff[2], uint32_t frequency)
float value; float value;
switch (marker_smith_format) { switch (marker_smith_format) {
case MS_LIN: case MS_LIN:
chsnprintf(buf, len, "%.2f %.1f" S_DEGREE, linear(coeff), phase(coeff)); plot_printf(buf, len, "%.2f %.1f" S_DEGREE, linear(coeff), phase(coeff));
break; break;
case MS_LOG: { case MS_LOG: {
float v = logmag(coeff); float v = logmag(coeff);
if (v == -INFINITY) if (v == -INFINITY)
chsnprintf(buf, len, "-"S_INFINITY" dB"); plot_printf(buf, len, "-"S_INFINITY" dB");
else else
chsnprintf(buf, len, "%.1fdB %.1f" S_DEGREE, v, phase(coeff)); plot_printf(buf, len, "%.1fdB %.1f" S_DEGREE, v, phase(coeff));
} }
break; break;
case MS_REIM: case MS_REIM:
chsnprintf(buf, len, "%F%+Fj", coeff[0], coeff[1]); plot_printf(buf, len, "%F%+Fj", coeff[0], coeff[1]);
break; break;
case MS_RX: case MS_RX:
chsnprintf(buf, len, "%F"S_OHM"%+Fj", zr, zi); plot_printf(buf, len, "%F"S_OHM"%+Fj", zr, zi);
break; break;
case MS_RLC: case MS_RLC:
@ -593,7 +597,7 @@ format_smith_value(char *buf, int len, const float coeff[2], uint32_t frequency)
prefix = 'H'; prefix = 'H';
value = zi / (2 * M_PI * frequency); value = zi / (2 * M_PI * frequency);
} }
chsnprintf(buf, len, "%F"S_OHM" %F%c", zr, value, prefix); plot_printf(buf, len, "%F"S_OHM" %F%c", zr, value, prefix);
break; break;
} }
} }
@ -646,11 +650,11 @@ trace_get_value_string(int t, char *buf, int len, float array[POINTS_COUNT][2],
return; return;
//case TRC_ADMIT: //case TRC_ADMIT:
case TRC_POLAR: case TRC_POLAR:
chsnprintf(buf, len, "%.2f%+.2fj", coeff[0], coeff[1]); plot_printf(buf, len, "%.2f%+.2fj", coeff[0], coeff[1]);
default: default:
return; return;
} }
chsnprintf(buf, len, format, v); plot_printf(buf, len, format, v);
} }
static void static void
@ -704,12 +708,12 @@ trace_get_value_string_delta(int t, char *buf, int len, float array[POINTS_COUNT
break; break;
//case TRC_ADMIT: //case TRC_ADMIT:
case TRC_POLAR: case TRC_POLAR:
chsnprintf(buf, len, "%.2f%+.2fj", coeff[0], coeff[1]); plot_printf(buf, len, "%.2f%+.2fj", coeff[0], coeff[1]);
return; return;
default: default:
return; return;
} }
chsnprintf(buf, len, format, v); plot_printf(buf, len, format, v);
} }
static int static int
@ -719,18 +723,18 @@ trace_get_info(int t, char *buf, int len)
float scale = get_trace_scale(t); float scale = get_trace_scale(t);
switch (trace[t].type) { switch (trace[t].type) {
case TRC_LOGMAG: case TRC_LOGMAG:
return chsnprintf(buf, len, "%s %ddB/", name, (int)scale); return plot_printf(buf, len, "%s %ddB/", name, (int)scale);
case TRC_PHASE: case TRC_PHASE:
return chsnprintf(buf, len, "%s %d" S_DEGREE "/", name, (int)scale); return plot_printf(buf, len, "%s %d" S_DEGREE "/", name, (int)scale);
case TRC_SMITH: case TRC_SMITH:
//case TRC_ADMIT: //case TRC_ADMIT:
case TRC_POLAR: case TRC_POLAR:
if (scale != 1.0) if (scale != 1.0)
return chsnprintf(buf, len, "%s %.1fFS", name, scale); return plot_printf(buf, len, "%s %.1fFS", name, scale);
else else
return chsnprintf(buf, len, "%s ", name); return plot_printf(buf, len, "%s ", name);
default: default:
return chsnprintf(buf, len, "%s %F/", name, scale); return plot_printf(buf, len, "%s %F/", name, scale);
} }
return 0; return 0;
} }
@ -835,98 +839,37 @@ markmap_upperarea(void)
invalidateRect(0, 0, AREA_WIDTH_NORMAL, 31); invalidateRect(0, 0, AREA_WIDTH_NORMAL, 31);
} }
#define INSIDE 0b0000; #define SWAP(x,y) {int t=x;x=y;y=t;}
#define LEFT 0b0001; //
#define RIGHT 0b0010; // in most cases _compute_outcode clip calculation not give render line speedup
#define BOTTOM 0b0100; //
#define TOP 0b1000; static inline void
cell_drawline(int x0, int y0, int x1, int y1, int c)
static uint32_t
_compute_outcode(int w, int h, int x, int y)
{ {
uint32_t code = INSIDE; if (x0<0 && x1<0) return;
if (x < 0) { if (y0<0 && y1<0) return;
code |= LEFT; if (x0>=CELLWIDTH && x1>=CELLWIDTH )return;
} else if (y0>=CELLHEIGHT && y1>=CELLHEIGHT)return;
if (x > w) {
code |= RIGHT;
}
if (y < 0) {
code |= BOTTOM;
} else
if (y > h) {
code |= TOP;
}
return code;
}
static void
cell_drawline(int w, int h, int x0, int y0, int x1, int y1, int c)
{
uint32_t outcode1 = _compute_outcode(w, h, x0, y0);
uint32_t outcode2 = _compute_outcode(w, h, x1, y1);
if (outcode1 & outcode2) {
// this line is out of requested area. early return
return;
}
// If outcode1 == 0 && outcode2 == 0, no clipping, not need check
//outcode1+=outcode2;
// modifed Bresenham's line algorithm, see https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm // 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;} if (x1 < x0) {SWAP(x0,x1);SWAP(y0,y1);}
int dx = x1 - x0;
int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;} int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;}
int err = (dx > dy ? dx : -dy) / 2; int err = (dx > dy ? dx : -dy) / 2;
while (1){ while (1){
if (//outcode1 == 0 || if (y0>=0 && y0<CELLHEIGHT && x0>=0 && x0<CELLWIDTH)
(y0 >= 0 && y0 < h && x0 >= 0 && x0 < w)) spi_buffer[y0*CELLWIDTH+x0]|= c;
spi_buffer[y0*w+x0] |= c;
if (x0 == x1 && y0 == y1) if (x0 == x1 && y0 == y1)
break; return;
int e2 = err; int e2 = err;
if (e2 > -dx) { err -= dy; x0 += sx; } if (e2 > -dx) { err -= dy; x0++; }
if (e2 < dy) { err += dx; y0 += sy; } if (e2 < dy) { err += dx; y0+=sy;}
}
}
#if 0
int
search_index_range(int x, int y, uint32_t index[POINTS_COUNT], int *i0, int *i1)
{
int i, j;
int head = 0;
int tail = sweep_points;
i = 0;
x &= 0x03e0;
y &= 0x03e0;
while (head < tail) {
i = (head + tail) / 2;
if (x < CELL_X0(index[i]))
tail = i+1;
else if (x > CELL_X0(index[i]))
head = i;
else if (y < CELL_Y0(index[i]))
tail = i+1;
else if (y > CELL_Y0(index[i]))
head = i;
else
break;
} }
if (x != CELL_X0(index[i]) || y != CELL_Y0(index[i]))
return FALSE;
j = i;
while (j > 0 && x == CELL_X0(index[j-1]) && y == CELL_Y0(index[j-1]))
j--;
*i0 = j;
j = i;
while (j < POINTS_COUNT-1 && x == CELL_X0(index[j+1]) && y == CELL_Y0(index[j+1]))
j++;
*i1 = j;
return TRUE;
} }
#endif
// Give a little speedup then draw rectangular plot (50 systick on all calls, all render req 700 systick)
// Write more difficult algoritm for seach indexes not give speedup
static int static int
search_index_range_x(int x1, int x2, uint32_t index[POINTS_COUNT], int *i0, int *i1) search_index_range_x(int x1, int x2, uint32_t index[POINTS_COUNT], int *i0, int *i1)
{ {
@ -967,7 +910,7 @@ search_index_range_x(int x1, int x2, uint32_t index[POINTS_COUNT], int *i0, int
return TRUE; return TRUE;
} }
#define REFERENCE_WIDTH 5 #define REFERENCE_WIDTH 6
#define REFERENCE_HEIGHT 5 #define REFERENCE_HEIGHT 5
#define REFERENCE_X_OFFSET 5 #define REFERENCE_X_OFFSET 5
#define REFERENCE_Y_OFFSET 2 #define REFERENCE_Y_OFFSET 2
@ -982,17 +925,17 @@ static const uint8_t reference_bitmap[]={
}; };
static void static void
draw_refpos(int w, int h, int x, int y, int c) draw_refpos(int x, int y, int c)
{ {
int y0=y, j; int y0=y, j;
for (j=0; j<REFERENCE_HEIGHT; j++, y0++){ for (j=0; j<REFERENCE_HEIGHT; j++, y0++){
if (y0 < 0 || y0 >= h) if (y0 < 0 || y0 >= CELLHEIGHT)
continue; continue;
int x0=x; int x0=x;
uint8_t bits = reference_bitmap[j]; uint8_t bits = reference_bitmap[j];
while (bits){ while (bits){
if (x0 >= 0 && x0 < w) if (x0 >= 0 && x0 < CELLWIDTH)
spi_buffer[y0*w+x0] = (bits&0x80) ? c : DEFAULT_BG_COLOR; spi_buffer[y0*CELLWIDTH+x0] = (bits&0x80) ? c : DEFAULT_BG_COLOR;
x0++; x0++;
bits<<=1; bits<<=1;
} }
@ -1051,21 +994,21 @@ static const uint8_t marker_bitmap[]={
}; };
static void static void
draw_marker(int w, int h, int x, int y, int c, int ch) draw_marker(int x, int y, int c, int ch)
{ {
int y0=y, j; int y0=y, j;
for (j=0;j<MARKER_HEIGHT;j++,y0++){ for (j=0;j<MARKER_HEIGHT;j++,y0++){
int x0=x; int x0=x;
uint8_t bits = marker_bitmap[ch*10+j]; uint8_t bits = marker_bitmap[ch*MARKER_HEIGHT+j];
bool force_color = false; bool force_color = false;
while (bits){ while (bits){
if (bits&0x80) if (bits&0x80)
force_color = true; force_color = true;
if (x0 >= 0 && x0 < w && y0 >= 0 && y0 < h){ if (x0 >= 0 && x0 < CELLWIDTH && y0 >= 0 && y0 < CELLHEIGHT){
if (bits&0x80) if (bits&0x80)
spi_buffer[y0*w+x0] = c; spi_buffer[y0*CELLWIDTH+x0] = c;
else if (force_color) else if (force_color)
spi_buffer[y0*w+x0] = DEFAULT_BG_COLOR; spi_buffer[y0*CELLWIDTH+x0] = DEFAULT_BG_COLOR;
} }
x0++; x0++;
bits<<=1; bits<<=1;
@ -1253,6 +1196,7 @@ draw_cell(int m, int n)
int x, y; int x, y;
int i0, i1, i; int i0, i1, i;
int t; int t;
uint16_t c;
// Clip cell by area // Clip cell by area
if (x0 + w > area_width) if (x0 + w > area_width)
w = area_width - x0; w = area_width - x0;
@ -1260,62 +1204,81 @@ draw_cell(int m, int n)
h = area_height - y0; h = area_height - y0;
if (w <= 0 || h <= 0) if (w <= 0 || h <= 0)
return; return;
// PULSE;
PULSE; // Clear buffer ("0 : height" lines)
// Clear buffer #if 0
memset(spi_buffer, DEFAULT_BG_COLOR, sizeof spi_buffer); // use memset 350 system ticks for all screen calls
uint16_t c = config.grid_color; // as understand it use 8 bit set, slow down on 32 bit systems
// Draw grid memset(spi_buffer, DEFAULT_BG_COLOR, (h*CELLWIDTH)*sizeof(uint16_t));
for (t = 0; t < TRACES_MAX; t++) { #else
if (!trace[t].enabled) // use direct set 35 system ticks for all screen calls
continue; #if CELLWIDTH%8 != 0
uint32_t trace_type = (1<<trace[t].type); #error "CELLWIDTH % 8 should be == 0 for speed, or need rewrite cell cleanup"
// Draw rectangular plot #endif
// Set DEFAULT_BG_COLOR for 8 pixels in one cycle
int count = h*CELLWIDTH / 8;
uint32_t *p = (uint32_t *)spi_buffer;
while (count--) {
p[0] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
p[1] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
p[2] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
p[3] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
p+=4;
}
#endif
// Draw grid
#if 1
c = config.grid_color;
// Generate grid type list
uint32_t trace_type = 0;
for (t = 0; t < TRACES_MAX; t++)
if (trace[t].enabled)
trace_type|=(1<<trace[t].type);
// Draw rectangular plot (40 system ticks for all screen calls)
if (trace_type&RECTANGULAR_GRID_MASK){ if (trace_type&RECTANGULAR_GRID_MASK){
for (x = 0; x < w; x++) { for (x = 0; x < w; x++) {
if (rectangular_grid_x(x+x0)){ if (rectangular_grid_x(x+x0)){
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
spi_buffer[y * w + x] = c; spi_buffer[y * CELLWIDTH + x] = c;
} }
} }
for (y = 0; y < h; y++) { for (y = 0; y < h; y++) {
if (rectangular_grid_y(y+y0)){ if (rectangular_grid_y(y+y0)){
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
if (x+x0 >= CELLOFFSETX && x+x0 <= WIDTH+CELLOFFSETX) if (x+x0 >= CELLOFFSETX && x+x0 <= WIDTH+CELLOFFSETX)
spi_buffer[y * w + x] = c; spi_buffer[y * CELLWIDTH + x] = c;
} }
} }
continue;
} }
// Smith greed line (1000 system ticks for all screen calls)
if(trace_type&(1<<TRC_SMITH)){ if(trace_type&(1<<TRC_SMITH)){
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
if (smith_grid(x+x0, y+y0)) if (smith_grid(x+x0, y+y0))
spi_buffer[y * w + x] = c; spi_buffer[y * CELLWIDTH + x] = c;
continue;
} }
if(trace_type&(1<<TRC_POLAR)){ // Polar greed line (800 system ticks for all screen calls)
else if(trace_type&(1<<TRC_POLAR)){
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
if (polar_grid(x+x0, y+y0)) if (polar_grid(x+x0, y+y0))
spi_buffer[y * w + x] = c; spi_buffer[y * CELLWIDTH + x] = c;
continue;
} }
#if 0 #if 0
if(trace_type&(1<<TRC_ADMIT)){ else if(trace_type&(1<<TRC_ADMIT)){
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
if (smith_grid3(x+x0, y+y0) if (smith_grid3(x+x0, y+y0)
// smith_grid2(x+x0, y+y0, 0.5)) // smith_grid2(x+x0, y+y0, 0.5))
spi_buffer[y * w + x] = c; spi_buffer[y * CELLWIDTH + x] = c;
continue;
} }
#endif #endif
} #endif
PULSE; // PULSE;
// Draw traces (50-600 system ticks for all screen calls, depend from lines count and size)
#if 1 #if 1
// Draw traces
for (t = 0; t < TRACES_MAX; t++) { for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled) if (!trace[t].enabled)
continue; continue;
@ -1325,19 +1288,24 @@ draw_cell(int m, int n)
uint32_t trace_type = (1<<trace[t].type); uint32_t trace_type = (1<<trace[t].type);
if (trace_type & ((1<<TRC_SMITH)|(1<<TRC_POLAR))) if (trace_type & ((1<<TRC_SMITH)|(1<<TRC_POLAR)))
i1 = sweep_points-1; i1 = sweep_points-1;
else // draw rectangular plot (search index range in cell) else // draw rectangular plot (search index range in cell, save 50-70 system ticks for all screen calls)
search_index_range_x(x0, x0+w, trace_index[t], &i0, &i1); search_index_range_x(x0, x0+w, trace_index[t], &i0, &i1);
uint32_t *index = trace_index[t];
for (i=i0; i < i1; i++) { for (i=i0; i < i1; i++) {
int x1 = CELL_X(trace_index[t][i ]) - x0; int x1 = CELL_X(index[i ]) - x0;
int y1 = CELL_Y(trace_index[t][i ]) - y0; int y1 = CELL_Y(index[i ]) - y0;
int x2 = CELL_X(trace_index[t][i+1]) - x0; int x2 = CELL_X(index[i+1]) - x0;
int y2 = CELL_Y(trace_index[t][i+1]) - y0; int y2 = CELL_Y(index[i+1]) - y0;
cell_drawline(w, h, x1, y1, x2, y2, c); cell_drawline(x1, y1, x2, y2, c);
} }
} }
#else
for (x=0;x<area_width;x+=6)
cell_drawline(x-x0, 0-y0, area_width-x-x0, area_height-y0, config.trace_color[0]);
#endif #endif
PULSE; // PULSE;
//draw marker symbols on each trace //draw marker symbols on each trace (<10 system ticks for all screen calls)
#if 1
for (i = 0; i < MARKERS_MAX; i++) { for (i = 0; i < MARKERS_MAX; i++) {
if (!markers[i].enabled) if (!markers[i].enabled)
continue; continue;
@ -1348,17 +1316,18 @@ draw_cell(int m, int n)
int x = CELL_X(index) - x0 - X_MARKER_OFFSET; int x = CELL_X(index) - x0 - X_MARKER_OFFSET;
int y = CELL_Y(index) - y0 - Y_MARKER_OFFSET; int y = CELL_Y(index) - y0 - Y_MARKER_OFFSET;
// Check marker icon on cell // Check marker icon on cell
if (x+MARKER_WIDTH>=0 && x-MARKER_WIDTH<w && y+MARKER_HEIGHT>=0 && y-MARKER_HEIGHT<h) if (x+MARKER_WIDTH>=0 && x-MARKER_WIDTH<CELLWIDTH && y+MARKER_HEIGHT>=0 && y-MARKER_HEIGHT<CELLHEIGHT)
draw_marker(w, h, x, y, config.trace_color[t], i); draw_marker(x, y, config.trace_color[t], i);
} }
} }
// Draw trace and marker info on the top #endif
// Draw trace and marker info on the top (50 system ticks for all screen calls)
#if 1
if (n == 0) if (n == 0)
cell_draw_marker_info(m, n, w, h); cell_draw_marker_info(x0, y0);
#endif
PULSE; // PULSE;
// Draw reference position (<10 system ticks for all screen calls)
// Draw refrence position
for (t = 0; t < TRACES_MAX; t++) { for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled) if (!trace[t].enabled)
continue; continue;
@ -1366,20 +1335,30 @@ draw_cell(int m, int n)
if (trace_type&((1<<TRC_SMITH)|(1<<TRC_POLAR))) if (trace_type&((1<<TRC_SMITH)|(1<<TRC_POLAR)))
continue; continue;
int x = 0 - x0 + CELLOFFSETX - REFERENCE_X_OFFSET; int x = 0 - x0 + CELLOFFSETX - REFERENCE_X_OFFSET;
if (x+REFERENCE_WIDTH>=0 && x-REFERENCE_WIDTH<w){ if (x+REFERENCE_WIDTH>=0 && x-REFERENCE_WIDTH<CELLWIDTH){
int y = HEIGHT - floatToInt((get_trace_refpos(t) * GRIDY)) - y0 - REFERENCE_Y_OFFSET; int y = HEIGHT - floatToInt((get_trace_refpos(t) * GRIDY)) - y0 - REFERENCE_Y_OFFSET;
if (y+REFERENCE_HEIGHT>=0 && y-REFERENCE_HEIGHT<h) if (y+REFERENCE_HEIGHT>=0 && y-REFERENCE_HEIGHT<CELLHEIGHT)
draw_refpos(w, h, x, y, config.trace_color[t]); draw_refpos(x, y, config.trace_color[t]);
}
} }
// Need right clip cell render (25 system ticks for all screen calls)
#if 1
if (w < CELLWIDTH){
uint16_t *src = spi_buffer+CELLWIDTH;
uint16_t *dst = spi_buffer+w;
for (y=h; --y; src+=CELLWIDTH-w)
for(x=w;x--;)
*dst++=*src++;
} }
// Draw cell #endif
// Draw cell (500 system ticks for all screen calls)
ili9341_bulk(OFFSETX + x0, OFFSETY + y0, w, h); ili9341_bulk(OFFSETX + x0, OFFSETY + y0, w, h);
} }
static void static void
draw_all_cells(bool flush_markmap) draw_all_cells(bool flush_markmap){
{
int m, n; int m, n;
// START_PROFILE
for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++) for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++)
for (n = 0; n < (area_height+CELLHEIGHT-1) / CELLHEIGHT; n++) { for (n = 0; n < (area_height+CELLHEIGHT-1) / CELLHEIGHT; n++) {
uint16_t bit = 1<<m; uint16_t bit = 1<<m;
@ -1390,7 +1369,7 @@ draw_all_cells(bool flush_markmap)
// else // else
// ili9341_fill(m*CELLWIDTH+10, n*CELLHEIGHT, 2, 2, RGB565(0,255,0)); // ili9341_fill(m*CELLWIDTH+10, n*CELLHEIGHT, 2, 2, RGB565(0,255,0));
} }
// STOP_PROFILE
if (flush_markmap) { if (flush_markmap) {
// keep current map for update // keep current map for update
swap_markmap(); swap_markmap();
@ -1445,21 +1424,23 @@ request_to_draw_cells_behind_numeric_input(void)
} }
static int static int
cell_drawchar(int w, int h, uint8_t ch, int x, int y) cell_drawchar(uint8_t ch, int x, int y)
{ {
uint8_t bits; uint8_t bits;
int c, r, ch_size; int c, r, ch_size;
const uint8_t *char_buf = FONT_GET_DATA(ch); const uint8_t *char_buf = FONT_GET_DATA(ch);
ch_size=FONT_GET_WIDTH(ch); ch_size=FONT_GET_WIDTH(ch);
if (y <= -FONT_GET_HEIGHT || y >= h || x <= -ch_size || x >= w) // if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT || x <= -ch_size || x >= CELLWIDTH)
// return ch_size;
if (x <= -ch_size)
return ch_size; return ch_size;
for(c = 0; c < FONT_GET_HEIGHT; c++) { for(c = 0; c < FONT_GET_HEIGHT; c++) {
bits = *char_buf++; bits = *char_buf++;
if ((y + c) < 0 || (y + c) >= h) if ((y + c) < 0 || (y + c) >= CELLHEIGHT)
continue; continue;
for (r = 0; r < ch_size; r++) { for (r = 0; r < ch_size; r++) {
if ((x+r) >= 0 && (x+r) < w && (0x80 & bits)) if ((x+r) >= 0 && (x+r) < CELLWIDTH && (0x80 & bits))
spi_buffer[(y+c)*w + (x+r)] = foreground_color; spi_buffer[(y+c)*CELLWIDTH + (x+r)] = foreground_color;
bits <<= 1; bits <<= 1;
} }
} }
@ -1467,142 +1448,136 @@ cell_drawchar(int w, int h, uint8_t ch, int x, int y)
} }
static void static void
cell_drawstring(int w, int h, char *str, int x, int y) cell_drawstring(char *str, int x, int y)
{ {
if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT)
return;
while (*str) { while (*str) {
x += cell_drawchar(w, h, *str, x, y); if (x >= CELLWIDTH)
str++; return;
x += cell_drawchar(*str++, x, y);
} }
} }
static void static void
cell_draw_marker_info(int m, int n, int w, int h) cell_draw_marker_info(int x0, int y0)
{ {
char buf[32]; char buf[24];
int t; int t;
if (n != 0)
return;
if (active_marker < 0) if (active_marker < 0)
return; return;
int idx = markers[active_marker].index; int idx = markers[active_marker].index;
int j = 0; int j = 0;
if (active_marker != -1 && previous_marker != -1 && uistat.current_trace != -1) { if (previous_marker != -1 && uistat.current_trace != -1) {
int t = uistat.current_trace; int t = uistat.current_trace;
int mk; int mk;
for (mk = 0; mk < MARKERS_MAX; mk++) { for (mk = 0; mk < MARKERS_MAX; mk++) {
if (!markers[mk].enabled) if (!markers[mk].enabled)
continue; continue;
int xpos = 1 + (j%2)*146; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
xpos -= m * CELLWIDTH - CELLOFFSETX;
ypos -= n * CELLHEIGHT;
setForegroundColor(config.trace_color[t]); setForegroundColor(config.trace_color[t]);
if (mk == active_marker) if (mk == active_marker)
cell_drawstring(w, h, S_SARROW, xpos, ypos); cell_drawstring(S_SARROW, xpos, ypos);
xpos += 5; xpos += 5;
chsnprintf(buf, sizeof buf, "M%d", mk+1); plot_printf(buf, sizeof buf, "M%d", mk+1);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
xpos += 13; xpos += 13;
//trace_get_info(t, buf, sizeof buf); //trace_get_info(t, buf, sizeof buf);
uint32_t freq = frequencies[markers[mk].index]; uint32_t freq = frequencies[markers[mk].index];
if (uistat.marker_delta && mk != active_marker) { if (uistat.marker_delta && mk != active_marker) {
uint32_t freq1 = frequencies[markers[active_marker].index]; uint32_t freq1 = frequencies[markers[active_marker].index];
uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq; uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq;
chsnprintf(buf, sizeof buf, S_DELTA"%.9qHz", delta); plot_printf(buf, sizeof buf, S_DELTA"%.9qHz", delta);
} else { } else {
chsnprintf(buf, sizeof buf, "%.10qHz", freq); plot_printf(buf, sizeof buf, "%.10qHz", freq);
} }
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
xpos += 67; xpos += 67;
if (uistat.marker_delta && mk != active_marker) if (uistat.marker_delta && mk != active_marker)
trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index); trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index);
else else
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index); trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index);
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
j++; j++;
} }
// draw marker delta // draw marker delta
if (!uistat.marker_delta && previous_marker >= 0 && active_marker != previous_marker && markers[previous_marker].enabled) { if (!uistat.marker_delta && previous_marker >= 0 && active_marker != previous_marker && markers[previous_marker].enabled) {
int idx0 = markers[previous_marker].index; int idx0 = markers[previous_marker].index;
int xpos = 180; int xpos = (WIDTH/2+30) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
xpos -= m * CELLWIDTH -CELLOFFSETX;
ypos -= n * CELLHEIGHT; plot_printf(buf, sizeof buf, S_DELTA"%d-%d:", active_marker+1, previous_marker+1);
chsnprintf(buf, sizeof buf, S_DELTA"%d-%d", active_marker+1, previous_marker+1);
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
xpos += 24; xpos += 27;
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
uint32_t freq = frequencies[idx]; uint32_t freq = frequencies[idx];
uint32_t freq1 = frequencies[idx0]; uint32_t freq1 = frequencies[idx0];
uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq; uint32_t delta = freq > freq1 ? freq - freq1 : freq1 - freq;
chsnprintf(buf, sizeof buf, "%c%.13qHz", freq >= freq1 ? '+' : '-', delta); plot_printf(buf, sizeof buf, "%c%.13qHz", freq >= freq1 ? '+' : '-', delta);
} else { } else {
chsnprintf(buf, sizeof buf, "%Fs (%Fm)", time_of_index(idx) - time_of_index(idx0), distance_of_index(idx) - distance_of_index(idx0)); plot_printf(buf, sizeof buf, "%Fs (%Fm)", time_of_index(idx) - time_of_index(idx0), distance_of_index(idx) - distance_of_index(idx0));
} }
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
} }
} else { } else {
for (t = 0; t < TRACES_MAX; t++) { for (t = 0; t < TRACES_MAX; t++) {
if (!trace[t].enabled) if (!trace[t].enabled)
continue; continue;
int xpos = 1 + (j%2)*146; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
xpos -= m * CELLWIDTH -CELLOFFSETX;
ypos -= n * CELLHEIGHT;
setForegroundColor(config.trace_color[t]); setForegroundColor(config.trace_color[t]);
if (t == uistat.current_trace) if (t == uistat.current_trace)
cell_drawstring(w, h, S_SARROW, xpos, ypos); cell_drawstring(S_SARROW, xpos, ypos);
xpos += 5; xpos += 5;
chsnprintf(buf, sizeof buf, "CH%d", trace[t].channel); plot_printf(buf, sizeof buf, "CH%d", trace[t].channel);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
xpos += 19; xpos += 19;
int n = trace_get_info(t, buf, sizeof buf); int n = trace_get_info(t, buf, sizeof buf);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
xpos += n * 5 + 2; xpos += n * 5 + 2;
//xpos += 60; //xpos += 60;
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], idx); trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], idx);
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
j++; j++;
} }
// draw marker frequency // draw marker frequency
int xpos = 185; int xpos = (WIDTH/2+40) + CELLOFFSETX - x0;
int ypos = 1 + (j/2)*8; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
xpos -= m * CELLWIDTH -CELLOFFSETX;
ypos -= n * CELLHEIGHT;
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
if (uistat.lever_mode == LM_MARKER) if (uistat.lever_mode == LM_MARKER)
cell_drawstring(w, h, S_SARROW, xpos, ypos); cell_drawstring(S_SARROW, xpos, ypos);
xpos += 5; xpos += 5;
chsnprintf(buf, sizeof buf, "M%d:", active_marker+1); plot_printf(buf, sizeof buf, "M%d:", active_marker+1);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
xpos += 19; xpos += 19;
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
chsnprintf(buf, sizeof buf, "%qHz", frequencies[idx]); plot_printf(buf, sizeof buf, "%qHz", frequencies[idx]);
} else { } else {
chsnprintf(buf, sizeof buf, "%Fs (%Fm)", time_of_index(idx), distance_of_index(idx)); plot_printf(buf, sizeof buf, "%Fs (%Fm)", time_of_index(idx), distance_of_index(idx));
} }
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
} }
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
if (electrical_delay != 0) { if (electrical_delay != 0) {
// draw electrical delay // draw electrical delay
int xpos = 21; int xpos = 21 + CELLOFFSETX - x0;
int ypos = 1 + ((j+1)/2)*8; int ypos = 1 + ((j+1)/2)*(FONT_GET_HEIGHT+1) - y0;
xpos -= m * CELLWIDTH -CELLOFFSETX;
ypos -= n * CELLHEIGHT;
float light_speed_ps = 299792458e-12; //(m/ps) float light_speed_ps = 299792458e-12; //(m/ps)
chsnprintf(buf, sizeof buf, "Edelay %Fs %Fm", electrical_delay * 1e-12, plot_printf(buf, sizeof buf, "Edelay %Fs %Fm", electrical_delay * 1e-12,
electrical_delay * light_speed_ps * velocity_factor); electrical_delay * light_speed_ps * velocity_factor);
cell_drawstring(w, h, buf, xpos, ypos); cell_drawstring(buf, xpos, ypos);
} }
} }
@ -1613,21 +1588,21 @@ draw_frequencies(void)
char buf2[32];buf2[0]=0; char buf2[32];buf2[0]=0;
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
if (FREQ_IS_STARTSTOP()) { if (FREQ_IS_STARTSTOP()) {
chsnprintf(buf1, sizeof(buf1), " START %qHz", frequency0); plot_printf(buf1, sizeof(buf1), " START %qHz", frequency0);
chsnprintf(buf2, sizeof(buf2), " STOP %qHz", frequency1); plot_printf(buf2, sizeof(buf2), " STOP %qHz", frequency1);
} else if (FREQ_IS_CENTERSPAN()) { } else if (FREQ_IS_CENTERSPAN()) {
chsnprintf(buf1, sizeof(buf1), " CENTER %qHz", FREQ_CENTER()); plot_printf(buf1, sizeof(buf1), " CENTER %qHz", FREQ_CENTER());
chsnprintf(buf2, sizeof(buf2), " SPAN %qHz", FREQ_SPAN()); plot_printf(buf2, sizeof(buf2), " SPAN %qHz", FREQ_SPAN());
} else { } else {
chsnprintf(buf1, sizeof(buf1), " CW %qHz", frequency0); plot_printf(buf1, sizeof(buf1), " CW %qHz", frequency0);
} }
} else { } else {
chsnprintf(buf1, sizeof(buf1), " START 0s"); plot_printf(buf1, sizeof(buf1), " START 0s");
chsnprintf(buf2, sizeof(buf2), "STOP %Fs (%Fm)", time_of_index(POINTS_COUNT-1), distance_of_index(POINTS_COUNT-1)); plot_printf(buf2, sizeof(buf2), "STOP %Fs (%Fm)", time_of_index(POINTS_COUNT-1), distance_of_index(POINTS_COUNT-1));
} }
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
setBackgroundColor(DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
ili9341_fill(0, 232, 320, 8, DEFAULT_BG_COLOR); ili9341_fill(0, FREQUENCIES_YPOS, 320, FONT_GET_HEIGHT, DEFAULT_BG_COLOR);
if (uistat.lever_mode == LM_CENTER) if (uistat.lever_mode == LM_CENTER)
buf1[0] = S_SARROW[0]; buf1[0] = S_SARROW[0];
if (uistat.lever_mode == LM_SPAN) if (uistat.lever_mode == LM_SPAN)
@ -1688,11 +1663,11 @@ draw_battery_status(void)
{ {
if (vbat<=0) if (vbat<=0)
return; return;
uint8_t string_buf[25]; uint8_t string_buf[16];
// Set battery color // Set battery color
setForegroundColor(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR); setForegroundColor(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR);
setBackgroundColor(DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
// chsnprintf(string_buf, sizeof string_buf, "V:%d", vbat); // plot_printf(string_buf, sizeof string_buf, "V:%d", vbat);
// ili9341_drawstringV(string_buf, 1, 60); // ili9341_drawstringV(string_buf, 1, 60);
// Prepare battery bitmap image // Prepare battery bitmap image
// Battery top // Battery top
@ -1709,7 +1684,7 @@ draw_battery_status(void)
// string_buf[x++] = 0b10000001; // string_buf[x++] = 0b10000001;
string_buf[x++] = 0b11111111; string_buf[x++] = 0b11111111;
// Draw battery // Draw battery
blit8BitWidthBitmap(0, 1, 8, x, string_buf); blit8BitWidthBitmap(1, 1, 8, x, string_buf);
} }
void void
@ -1722,7 +1697,8 @@ request_to_redraw_grid(void)
void void
redraw_frame(void) redraw_frame(void)
{ {
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
clearScreen();
draw_frequencies(); draw_frequencies();
draw_cal_status(); draw_cal_status();
} }

@ -69,15 +69,17 @@ si5351_init(void)
} }
} }
static const uint8_t disable_output[] = {
SI5351_REG_16_CLK0_CONTROL,
SI5351_CLK_POWERDOWN,
SI5351_CLK_POWERDOWN,
SI5351_CLK_POWERDOWN
};
void si5351_disable_output(void) void si5351_disable_output(void)
{ {
uint8_t reg[4];
si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0xff); si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0xff);
reg[0] = SI5351_REG_16_CLK0_CONTROL; si5351_bulk_write(disable_output, sizeof(disable_output));
reg[1] = SI5351_CLK_POWERDOWN;
reg[2] = SI5351_CLK_POWERDOWN;
reg[3] = SI5351_CLK_POWERDOWN;
si5351_bulk_write(reg, 4);
} }
void si5351_enable_output(void) void si5351_enable_output(void)
@ -85,19 +87,19 @@ void si5351_enable_output(void)
si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0x00); si5351_write(SI5351_REG_3_OUTPUT_ENABLE_CONTROL, 0x00);
} }
void si5351_reset_pll(void) static void si5351_reset_pll(void)
{ {
//si5351_write(SI5351_REG_177_PLL_RESET, SI5351_PLL_RESET_A | SI5351_PLL_RESET_B); //si5351_write(SI5351_REG_177_PLL_RESET, SI5351_PLL_RESET_A | SI5351_PLL_RESET_B);
si5351_write(SI5351_REG_177_PLL_RESET, 0xAC); si5351_write(SI5351_REG_177_PLL_RESET, 0xAC);
} }
void si5351_setupPLL(uint8_t pll, /* SI5351_PLL_A or SI5351_PLL_B */ static void si5351_setupPLL(uint8_t pll, /* SI5351_PLL_A or SI5351_PLL_B */
uint8_t mult, uint8_t mult,
uint32_t num, uint32_t num,
uint32_t denom) uint32_t denom)
{ {
/* Get the appropriate starting point for the PLL registers */ /* Get the appropriate starting point for the PLL registers */
const uint8_t pllreg_base[] = { static const uint8_t pllreg_base[] = {
SI5351_REG_26_PLL_A, SI5351_REG_26_PLL_A,
SI5351_REG_34_PLL_B SI5351_REG_34_PLL_B
}; };
@ -147,7 +149,7 @@ void si5351_setupPLL(uint8_t pll, /* SI5351_PLL_A or SI5351_PLL_B */
si5351_bulk_write(reg, 9); si5351_bulk_write(reg, 9);
} }
void static void
si5351_setupMultisynth(uint8_t output, si5351_setupMultisynth(uint8_t output,
uint8_t pllSource, uint8_t pllSource,
uint32_t div, // 4,6,8, 8+ ~ 900 uint32_t div, // 4,6,8, 8+ ~ 900
@ -157,12 +159,12 @@ si5351_setupMultisynth(uint8_t output,
uint8_t drive_strength) uint8_t drive_strength)
{ {
/* Get the appropriate starting point for the PLL registers */ /* Get the appropriate starting point for the PLL registers */
const uint8_t msreg_base[] = { static const uint8_t msreg_base[] = {
SI5351_REG_42_MULTISYNTH0, SI5351_REG_42_MULTISYNTH0,
SI5351_REG_50_MULTISYNTH1, SI5351_REG_50_MULTISYNTH1,
SI5351_REG_58_MULTISYNTH2, SI5351_REG_58_MULTISYNTH2,
}; };
const uint8_t clkctrl[] = { static const uint8_t clkctrl[] = {
SI5351_REG_16_CLK0_CONTROL, SI5351_REG_16_CLK0_CONTROL,
SI5351_REG_17_CLK1_CONTROL, SI5351_REG_17_CLK1_CONTROL,
SI5351_REG_18_CLK2_CONTROL SI5351_REG_18_CLK2_CONTROL
@ -226,7 +228,7 @@ si5351_setupMultisynth(uint8_t output,
#define PLL_N 32 #define PLL_N 32
#define PLLFREQ (XTALFREQ * PLL_N) #define PLLFREQ (XTALFREQ * PLL_N)
void static void
si5351_set_frequency_fixedpll(int channel, int pll, uint32_t pllfreq, uint32_t freq, si5351_set_frequency_fixedpll(int channel, int pll, uint32_t pllfreq, uint32_t freq,
int rdiv, uint8_t drive_strength, int mul) int rdiv, uint8_t drive_strength, int mul)
{ {
@ -255,7 +257,7 @@ si5351_set_frequency_fixedpll(int channel, int pll, uint32_t pllfreq, uint32_t f
si5351_setupMultisynth(channel, pll, div, num, denom, rdiv, drive_strength); si5351_setupMultisynth(channel, pll, div, num, denom, rdiv, drive_strength);
} }
void static void
si5351_set_frequency_fixeddiv(int channel, int pll, uint32_t freq, int div, si5351_set_frequency_fixeddiv(int channel, int pll, uint32_t freq, int div,
uint8_t drive_strength, int mul) uint8_t drive_strength, int mul)
{ {
@ -291,6 +293,7 @@ si5351_set_frequency_fixeddiv(int channel, int pll, uint32_t freq, int div,
* 100~150MHz fractional PLL 600-900MHz, fixed divider 6 * 100~150MHz fractional PLL 600-900MHz, fixed divider 6
* 150~200MHz fractional PLL 600-900MHz, fixed divider 4 * 150~200MHz fractional PLL 600-900MHz, fixed divider 4
*/ */
#if 0
void void
si5351_set_frequency(int channel, int freq, uint8_t drive_strength) si5351_set_frequency(int channel, int freq, uint8_t drive_strength)
{ {
@ -303,7 +306,7 @@ si5351_set_frequency(int channel, int freq, uint8_t drive_strength)
si5351_set_frequency_fixeddiv(channel, SI5351_PLL_B, freq, 4, drive_strength, 1); si5351_set_frequency_fixeddiv(channel, SI5351_PLL_B, freq, 4, drive_strength, 1);
} }
} }
#endif
int current_band = -1; int current_band = -1;

@ -74,16 +74,4 @@
void si5351_init(void); void si5351_init(void);
void si5351_setupPLL(uint8_t pll, /* SI5351_PLL_A or SI5351_PLL_B */
uint8_t mult,
uint32_t num,
uint32_t denom);
void si5351_setupMultisynth(uint8_t output,
uint8_t pllSource,
uint32_t div,
uint32_t num,
uint32_t denom,
uint32_t rdiv,
uint8_t drive_strength);
void si5351_set_frequency(int channel, int freq, uint8_t drive_strength); void si5351_set_frequency(int channel, int freq, uint8_t drive_strength);

192
ui.c

@ -86,16 +86,17 @@ typedef struct {
#pragma pack(pop) #pragma pack(pop)
// Touch screen // Touch screen
static int8_t last_touch_status = FALSE; #define EVT_TOUCH_NONE 0
#define EVT_TOUCH_DOWN 1
#define EVT_TOUCH_PRESSED 2
#define EVT_TOUCH_RELEASED 3
static int8_t last_touch_status = EVT_TOUCH_NONE;
static int16_t last_touch_x; static int16_t last_touch_x;
static int16_t last_touch_y; static int16_t last_touch_y;
//int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 }; //int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 };
//int16_t touch_cal[4] = { 620, 600, 130, 180 }; //int16_t touch_cal[4] = { 620, 600, 130, 180 };
#define EVT_TOUCH_NONE 0
#define EVT_TOUCH_DOWN 1
#define EVT_TOUCH_PRESSED 2
#define EVT_TOUCH_RELEASED 3
int awd_count; int awd_count;
//int touch_x, touch_y; //int touch_x, touch_y;
@ -287,57 +288,44 @@ touch_check(void)
if (stat != last_touch_status) { if (stat != last_touch_status) {
last_touch_status = stat; last_touch_status = stat;
if (stat) { return stat ? EVT_TOUCH_PRESSED : EVT_TOUCH_RELEASED;
return EVT_TOUCH_PRESSED;
} else {
return EVT_TOUCH_RELEASED;
}
} else {
if (stat)
return EVT_TOUCH_DOWN;
else
return EVT_TOUCH_NONE;
} }
return stat ? EVT_TOUCH_DOWN : EVT_TOUCH_NONE;
} }
static void static inline void
touch_wait_release(void) touch_wait_release(void) {
{ while(touch_check()!=EVT_TOUCH_RELEASED);
int status; }
/* wait touch release */
do { static inline void
status = touch_check(); touch_wait_pressed(void) {
} while(status != EVT_TOUCH_RELEASED); while(touch_check()!=EVT_TOUCH_PRESSED);
} }
void void
touch_cal_exec(void) touch_cal_exec(void)
{ {
int status;
int x1, x2, y1, y2; int x1, x2, y1, y2;
adc_stop(ADC1); adc_stop(ADC1);
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
setBackgroundColor(DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR); clearScreen();
ili9341_line(0, 0, 0, 32); ili9341_line(0, 0, 0, 32);
ili9341_line(0, 0, 32, 0); ili9341_line(0, 0, 32, 0);
ili9341_drawstring("TOUCH UPPER LEFT", 10, 10); ili9341_drawstring("TOUCH UPPER LEFT", 10, 10);
do { touch_wait_release();
status = touch_check();
} while(status != EVT_TOUCH_RELEASED);
x1 = last_touch_x; x1 = last_touch_x;
y1 = last_touch_y; y1 = last_touch_y;
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR); clearScreen();
ili9341_line(320-1, 240-1, 320-1, 240-32); ili9341_line(320-1, 240-1, 320-1, 240-32);
ili9341_line(320-1, 240-1, 320-32, 240-1); ili9341_line(320-1, 240-1, 320-32, 240-1);
ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220); ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220);
do { touch_wait_release();
status = touch_check();
} while(status != EVT_TOUCH_RELEASED);
x2 = last_touch_x; x2 = last_touch_x;
y2 = last_touch_y; y2 = last_touch_y;
@ -353,30 +341,26 @@ touch_cal_exec(void)
void void
touch_draw_test(void) touch_draw_test(void)
{ {
int status;
int x0, y0; int x0, y0;
int x1, y1; int x1, y1;
adc_stop(ADC1); adc_stop(ADC1);
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR);
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
setBackgroundColor(DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
clearScreen();
ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, 233); ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, 233);
do { touch_wait_pressed();
status = touch_check();
} while(status != EVT_TOUCH_PRESSED);
touch_position(&x0, &y0); touch_position(&x0, &y0);
do { do {
status = touch_check();
touch_position(&x1, &y1); touch_position(&x1, &y1);
ili9341_line(x0, y0, x1, y1); ili9341_line(x0, y0, x1, y1);
x0 = x1; x0 = x1;
y0 = y1; y0 = y1;
chThdSleepMilliseconds(50); chThdSleepMilliseconds(50);
} while(status != EVT_TOUCH_RELEASED); } while(touch_check()!=EVT_TOUCH_RELEASED);
touch_start_watchdog(); touch_start_watchdog();
} }
@ -394,12 +378,11 @@ void
show_version(void) show_version(void)
{ {
int x = 5, y = 5; int x = 5, y = 5;
adc_stop(ADC1); adc_stop(ADC1);
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR);
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
setBackgroundColor(DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
clearScreen();
ili9341_drawstring_size(BOARD_NAME, x, y, 4); ili9341_drawstring_size(BOARD_NAME, x, y, 4);
y += 25; y += 25;
@ -433,7 +416,7 @@ enter_dfu(void)
setForegroundColor(DEFAULT_FG_COLOR); setForegroundColor(DEFAULT_FG_COLOR);
setBackgroundColor(DEFAULT_BG_COLOR); setBackgroundColor(DEFAULT_BG_COLOR);
// leave a last message // leave a last message
ili9341_fill(0, 0, 320, 240, DEFAULT_BG_COLOR); clearScreen();
ili9341_drawstring("DFU: Device Firmware Update Mode", x, y += 10); ili9341_drawstring("DFU: Device Firmware Update Mode", x, y += 10);
ili9341_drawstring("To exit DFU mode, please reset device yourself.", x, y += 10); ili9341_drawstring("To exit DFU mode, please reset device yourself.", x, y += 10);
@ -496,9 +479,9 @@ menu_cal2_cb(int item, uint8_t data)
case 3: // CORRECTION case 3: // CORRECTION
// toggle applying correction // toggle applying correction
cal_status ^= CALSTAT_APPLY; cal_status ^= CALSTAT_APPLY;
draw_menu();
break; break;
} }
draw_menu();
draw_cal_status(); draw_cal_status();
//menu_move_back(); //menu_move_back();
} }
@ -507,12 +490,11 @@ static void
menu_recall_cb(int item, uint8_t data) menu_recall_cb(int item, uint8_t data)
{ {
(void)item; (void)item;
if (caldata_recall(data) == 0) { caldata_recall(data);
menu_move_back(); menu_move_back();
ui_mode_normal(); ui_mode_normal();
update_grid(); update_grid();
draw_cal_status(); draw_cal_status();
}
} }
static void static void
@ -642,8 +624,7 @@ static void
menu_velocity_cb(int item, uint8_t data){ menu_velocity_cb(int item, uint8_t data){
(void)item; (void)item;
(void)data; (void)data;
int status = btn_wait_release(); if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
if (status & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(KM_VELOCITY_FACTOR); ui_mode_numeric(KM_VELOCITY_FACTOR);
ui_process_numeric(); ui_process_numeric();
} else { } else {
@ -664,7 +645,7 @@ static void
choose_active_marker(void) choose_active_marker(void)
{ {
int i; int i;
for (i = 0; i < 4; i++) for (i = 0; i < MARKERS_MAX; i++)
if (markers[i].enabled) { if (markers[i].enabled) {
active_marker = i; active_marker = i;
return; return;
@ -679,8 +660,7 @@ menu_scale_cb(int item, uint8_t data)
if (data == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) { if (data == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) {
data = KM_SCALEDELAY; data = KM_SCALEDELAY;
} }
int status = btn_wait_release(); if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
if (status & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(data); ui_mode_numeric(data);
ui_process_numeric(); ui_process_numeric();
} else { } else {
@ -693,15 +673,13 @@ static void
menu_stimulus_cb(int item, uint8_t data) menu_stimulus_cb(int item, uint8_t data)
{ {
(void)data; (void)data;
int status;
switch (item) { switch (item) {
case 0: /* START */ case 0: /* START */
case 1: /* STOP */ case 1: /* STOP */
case 2: /* CENTER */ case 2: /* CENTER */
case 3: /* SPAN */ case 3: /* SPAN */
case 4: /* CW */ case 4: /* CW */
status = btn_wait_release(); if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
if (status & EVT_BUTTON_DOWN_LONG) {
ui_mode_numeric(item); ui_mode_numeric(item);
ui_process_numeric(); ui_process_numeric();
} else { } else {
@ -718,11 +696,10 @@ menu_stimulus_cb(int item, uint8_t data)
} }
} }
static uint32_t static uint32_t
get_marker_frequency(int marker) get_marker_frequency(int marker)
{ {
if (marker < 0 || marker >= 4) if (marker < 0 || marker >= MARKERS_MAX)
return 0; return 0;
if (!markers[marker].enabled) if (!markers[marker].enabled)
return 0; return 0;
@ -782,7 +759,7 @@ static void
menu_marker_search_cb(int item, uint8_t data) menu_marker_search_cb(int item, uint8_t data)
{ {
(void)data; (void)data;
int i; int i = -1;
if (active_marker == -1) if (active_marker == -1)
return; return;
@ -791,23 +768,19 @@ menu_marker_search_cb(int item, uint8_t data)
case 1: /* minimum */ case 1: /* minimum */
set_marker_search(item); set_marker_search(item);
i = marker_search(); i = marker_search();
if (i != -1)
markers[active_marker].index = i;
break; break;
case 2: /* search Left */ case 2: /* search Left */
i = marker_search_left(markers[active_marker].index); i = marker_search_left(markers[active_marker].index);
if (i != -1)
markers[active_marker].index = i;
break; break;
case 3: /* search right */ case 3: /* search right */
i = marker_search_right(markers[active_marker].index); i = marker_search_right(markers[active_marker].index);
if (i != -1)
markers[active_marker].index = i;
break; break;
case 4: /* tracking */ case 4: /* tracking */
marker_tracking = !marker_tracking; marker_tracking = !marker_tracking;
break; break;
} }
if (i != -1)
markers[active_marker].index = i;
draw_menu(); draw_menu();
redraw_marker(active_marker, TRUE); redraw_marker(active_marker, TRUE);
select_lever_mode(LM_SEARCH); select_lever_mode(LM_SEARCH);
@ -842,7 +815,8 @@ static void
menu_marker_sel_cb(int item, uint8_t data) menu_marker_sel_cb(int item, uint8_t data)
{ {
(void)data; (void)data;
if (item >= 0 && item < 4) { int t;
if (item >= 0 && item < MARKERS_MAX) {
if (markers[item].enabled) { if (markers[item].enabled) {
if (item == active_marker) { if (item == active_marker) {
// disable if active trace is selected // disable if active trace is selected
@ -856,10 +830,8 @@ menu_marker_sel_cb(int item, uint8_t data)
active_marker_select(item); active_marker_select(item);
} }
} else if (item == 4) { /* all off */ } else if (item == 4) { /* all off */
markers[0].enabled = FALSE; for (t = 0; t < MARKERS_MAX; t++)
markers[1].enabled = FALSE; markers[t].enabled = FALSE;
markers[2].enabled = FALSE;
markers[3].enabled = FALSE;
previous_marker = -1; previous_marker = -1;
active_marker = -1; active_marker = -1;
} else if (item == 5) { /* marker delta */ } else if (item == 5) { /* marker delta */
@ -1076,7 +1048,7 @@ const menuitem_t menu_top[] = {
#define MENU_STACK_DEPTH_MAX 4 #define MENU_STACK_DEPTH_MAX 4
uint8_t menu_current_level = 0; uint8_t menu_current_level = 0;
const menuitem_t *menu_stack[4] = { const menuitem_t *menu_stack[MENU_STACK_DEPTH_MAX] = {
menu_top, NULL, NULL, NULL menu_top, NULL, NULL, NULL
}; };
@ -1157,6 +1129,10 @@ menu_invoke(int item)
} }
} }
#define MENU_BUTTON_WIDTH 60
#define MENU_BUTTON_HEIGHT 30
#define NUM_INPUT_HEIGHT 30
#define KP_WIDTH 48 #define KP_WIDTH 48
#define KP_HEIGHT 48 #define KP_HEIGHT 48
// Key x, y position (0 - 15) on screen // Key x, y position (0 - 15) on screen
@ -1291,10 +1267,10 @@ draw_keypad(void)
static 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, 240-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, DEFAULT_MENU_COLOR);
setForegroundColor(DEFAULT_MENU_TEXT_COLOR); setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
setBackgroundColor(DEFAULT_MENU_COLOR); setBackgroundColor(DEFAULT_MENU_COLOR);
ili9341_drawstring(keypad_mode_label[keypad_mode], 10, 220); ili9341_drawstring(keypad_mode_label[keypad_mode], 10, 240-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2);
//ili9341_drawfont(KP_KEYPAD, 300, 216); //ili9341_drawfont(KP_KEYPAD, 300, 216);
} }
@ -1320,22 +1296,22 @@ draw_numeric_input(const char *buf)
if (ui_mode == UI_NUMERIC && 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)
bg = DEFAULT_MENU_COLOR; // bg = DEFAULT_MENU_COLOR;
} }
setForegroundColor(fg); setForegroundColor(fg);
setBackgroundColor(bg); setBackgroundColor(bg);
if (c >= 0) // c is number if (c >= 0) // c is number
ili9341_drawfont(c, x, 208+4); ili9341_drawfont(c, x, 240-NUM_INPUT_HEIGHT+4);
else if (focused) // c not number, but focused else if (focused) // c not number, but focused
ili9341_drawfont(0, x, 208+4); ili9341_drawfont(0, x, 240-NUM_INPUT_HEIGHT+4);
else // erase else // erase
ili9341_fill(x, 208+4, 20, 24, bg); ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_HEIGHT, NUM_FONT_GET_WIDTH+2+8, bg);
x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2; x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2;
} }
// erase last // erase last
ili9341_fill(x, 208+4, NUM_FONT_GET_WIDTH+2+8, 24, DEFAULT_MENU_COLOR); ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_WIDTH+2+8, NUM_FONT_GET_WIDTH+2+8, DEFAULT_MENU_COLOR);
} }
static int static int
@ -1353,7 +1329,7 @@ static void
menu_item_modify_attribute(const menuitem_t *menu, int item, menu_item_modify_attribute(const menuitem_t *menu, int item,
uint16_t *fg, uint16_t *bg) uint16_t *fg, uint16_t *bg)
{ {
if (menu == menu_trace && item < 4) { if (menu == menu_trace && item < TRACES_MAX) {
if (trace[item].enabled) if (trace[item].enabled)
*bg = config.trace_color[item]; *bg = config.trace_color[item];
} else if (menu == menu_marker_sel) { } else if (menu == menu_marker_sel) {
@ -1429,24 +1405,24 @@ draw_menu_buttons(const menuitem_t *menu)
break; break;
if (menu[i].type == MT_BLANK) if (menu[i].type == MT_BLANK)
continue; continue;
int y = 32*i; int y = MENU_BUTTON_HEIGHT*i;
uint16_t bg = config.menu_normal_color; uint16_t bg = config.menu_normal_color;
uint16_t fg = DEFAULT_MENU_TEXT_COLOR; uint16_t fg = DEFAULT_MENU_TEXT_COLOR;
// focus only in MENU mode but not in KEYPAD mode // focus only in MENU mode but not in KEYPAD mode
if (ui_mode == UI_MENU && i == selection) if (ui_mode == UI_MENU && i == selection)
bg = config.menu_active_color; bg = config.menu_active_color;
ili9341_fill(320-60, y, 60, 30, bg); ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg);
menu_item_modify_attribute(menu, i, &fg, &bg); menu_item_modify_attribute(menu, i, &fg, &bg);
setForegroundColor(fg); setForegroundColor(fg);
setBackgroundColor(bg); setBackgroundColor(bg);
if (menu_is_multiline(menu[i].label, &l1, &l2)) { if (menu_is_multiline(menu[i].label, &l1, &l2)) {
ili9341_fill(320-57, y+6, 54, 19, bg); ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+5, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg);
ili9341_drawstring(l1, 320-55, y+8); ili9341_drawstring(l1, 320-MENU_BUTTON_WIDTH+5, y+7);
ili9341_drawstring(l2, 320-55, y+16); ili9341_drawstring(l2, 320-MENU_BUTTON_WIDTH+5, y+7+FONT_GET_HEIGHT+1);
} else { } else {
ili9341_fill(320-57, y+10, 54, 11, bg); ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+8, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+2, bg);
ili9341_drawstring(menu[i].label, 320-55, y+12); ili9341_drawstring(menu[i].label, 320-MENU_BUTTON_WIDTH+5, y+10);
} }
} }
} }
@ -1474,9 +1450,8 @@ menu_apply_touch(void)
break; break;
if (menu[i].type == MT_BLANK) if (menu[i].type == MT_BLANK)
continue; continue;
int y = 32*i; int y = MENU_BUTTON_HEIGHT*i;
if (y-2 < touch_y && touch_y < y+30+2 if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && 320-MENU_BUTTON_WIDTH < touch_x) {
&& 320-60 < touch_x) {
menu_select_touch(i); menu_select_touch(i);
return; return;
} }
@ -1495,13 +1470,13 @@ draw_menu(void)
static 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-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*7, DEFAULT_BG_COLOR);
} }
static 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-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, DEFAULT_BG_COLOR);
} }
static void static void
@ -1601,7 +1576,7 @@ static void
draw_numeric_area(void) draw_numeric_area(void)
{ {
char buf[10]; char buf[10];
chsnprintf(buf, sizeof buf, "%9d", uistat.value); plot_printf(buf, sizeof buf, "%9d", uistat.value);
draw_numeric_input(buf); draw_numeric_input(buf);
} }
@ -1613,7 +1588,7 @@ ui_mode_menu(void)
ui_mode = UI_MENU; ui_mode = UI_MENU;
/* narrowen plotting area */ /* narrowen plotting area */
area_width = AREA_WIDTH_NORMAL - 60; area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH;
area_height = AREA_HEIGHT_NORMAL; area_height = AREA_HEIGHT_NORMAL;
ensure_selection(); ensure_selection();
draw_menu(); draw_menu();
@ -1631,7 +1606,7 @@ 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;//AREA_HEIGHT_NORMAL - 32; area_height = 240-NUM_INPUT_HEIGHT;//AREA_HEIGHT_NORMAL - 32;
draw_numeric_area_frame(); draw_numeric_area_frame();
fetch_numeric_target(); fetch_numeric_target();
@ -1653,7 +1628,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 - 60; area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH;
area_height = HEIGHT - 32; area_height = HEIGHT - 32;
draw_menu(); draw_menu();
draw_keypad(); draw_keypad();
@ -1718,7 +1693,7 @@ step_round(uint32_t v)
{ {
// decade step // decade step
uint32_t x = 1; uint32_t x = 1;
for (x = 1; x*10 < v; x *= 10) for (x = 1; x*10 < v; x*= 10)
; ;
// 1-2-5 step // 1-2-5 step
@ -1896,8 +1871,7 @@ keypad_apply_touch(void)
while (keypads[i].c>=0) { while (keypads[i].c>=0) {
int x = KP_GET_X(keypads[i].x); int x = KP_GET_X(keypads[i].x);
int y = KP_GET_Y(keypads[i].y); int y = KP_GET_Y(keypads[i].y);
if (x < touch_x && touch_x < x+KP_WIDTH if (x < touch_x && touch_x < x+KP_WIDTH && y < touch_y && touch_y < y+KP_HEIGHT) {
&& y < touch_y && touch_y < y+KP_HEIGHT) {
// draw focus // draw focus
selection = i; selection = i;
draw_keypad(); draw_keypad();
@ -2042,8 +2016,7 @@ ui_process_keypad(void)
break; break;
} }
status = touch_check(); if (touch_check() == EVT_TOUCH_PRESSED) {
if (status == EVT_TOUCH_PRESSED) {
int key = keypad_apply_touch(); int key = keypad_apply_touch();
if (key >= 0 && keypad_click(key)) if (key >= 0 && keypad_click(key))
/* exit loop on done or cancel */ /* exit loop on done or cancel */
@ -2077,11 +2050,9 @@ ui_process_lever(void)
} }
} }
static void static void
drag_marker(int t, int m) drag_marker(int t, int m)
{ {
int status;
/* wait touch release */ /* wait touch release */
do { do {
int touch_x, touch_y; int touch_x, touch_y;
@ -2095,9 +2066,7 @@ drag_marker(int t, int m)
markers[m].frequency = frequencies[index]; markers[m].frequency = frequencies[index];
redraw_marker(m, TRUE); redraw_marker(m, TRUE);
} }
} while(touch_check()!=EVT_TOUCH_RELEASED);
status = touch_check();
} while(status != EVT_TOUCH_RELEASED);
} }
static int static int
@ -2147,21 +2116,15 @@ touch_lever_mode_select(void)
int touch_x, touch_y; int touch_x, touch_y;
touch_position(&touch_x, &touch_y); touch_position(&touch_x, &touch_y);
if (touch_y > HEIGHT) { if (touch_y > HEIGHT) {
if (touch_x < 160) { select_lever_mode(touch_x < FREQUENCIES_XPOS2 ? LM_CENTER : LM_SPAN);
select_lever_mode(LM_CENTER);
} else {
select_lever_mode(LM_SPAN);
}
return TRUE; return TRUE;
} }
if (touch_y < 15) { if (touch_y < 15) {
select_lever_mode(LM_MARKER); select_lever_mode(LM_MARKER);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
static static
void ui_process_touch(void) void ui_process_touch(void)
@ -2173,10 +2136,9 @@ void ui_process_touch(void)
if (status == EVT_TOUCH_PRESSED || status == EVT_TOUCH_DOWN) { if (status == EVT_TOUCH_PRESSED || status == EVT_TOUCH_DOWN) {
switch (ui_mode) { switch (ui_mode) {
case UI_NORMAL: case UI_NORMAL:
if (touch_pickup_marker())
if (touch_pickup_marker()) {
break; break;
} else if (touch_lever_mode_select()) { if (touch_lever_mode_select()) {
draw_all(FALSE); draw_all(FALSE);
touch_wait_release(); touch_wait_release();
break; break;

Loading…
Cancel
Save

Powered by TurnKey Linux.