diff --git a/ili9341.c b/ili9341.c index 3dd1cd6..f32ff19 100644 --- a/ili9341.c +++ b/ili9341.c @@ -309,7 +309,7 @@ static void spi_init(void) static void send_command(uint8_t cmd, uint8_t len, const uint8_t *data) { // Uncomment on low speed SPI (possible get here before previous tx complete) -// while (SPI_IN_TX_RX); + while (SPI_IN_TX_RX(LCD_SPI)); LCD_CS_LOW; LCD_DC_CMD; SPI_WRITE_8BIT(LCD_SPI, cmd); @@ -399,14 +399,18 @@ void ili9341_init(void) } } -void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette) -{ +static void ili9341_setWindow(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) }; 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); +} + +void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette) +{ + ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_WRITE, 0, NULL); uint8_t *buf = (uint8_t *)spi_buffer; @@ -418,12 +422,7 @@ void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette) #ifndef __USE_DISPLAY_DMA__ void ili9341_fill(int x, int y, int w, int h, uint16_t 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) }; - 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); + ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_WRITE, 0, NULL); int32_t len = w * h; while (len-- > 0) @@ -432,13 +431,7 @@ void ili9341_fill(int x, int y, int w, int h, uint16_t 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) }; - uint16_t *buf = spi_buffer; - 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); + ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_WRITE, 0, NULL); int32_t len = w * h; while (len-- > 0) @@ -449,17 +442,12 @@ void ili9341_bulk(int x, int y, int w, int h) // Use DMA for send data // // Fill region by some color -void ili9341_fill(int x, int y, int w, int h, uint16_t color) +void ili9341_fill(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) }; - 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); + ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_WRITE, 0, NULL); - dmaStreamSetMemory0(dmatx, &color); + dmaStreamSetMemory0(dmatx, &background_color); dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD); dmaStreamFlush(w * h); } @@ -467,10 +455,7 @@ void ili9341_fill(int x, int y, int w, int h, uint16_t color) // Copy spi_buffer to region void ili9341_bulk(int x, int y, int w, int h) { - 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); + ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_WRITE, 0, NULL); // Init Tx DMA mem->spi, set size, mode (spi and mem data size is 16 bit) @@ -485,12 +470,7 @@ void ili9341_bulk(int x, int y, int w, int h) 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) }; - 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); + ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_READ, 0, NULL); // Skip data from rx buffer spi_DropRx(); @@ -523,12 +503,8 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) uint16_t dummy_tx = 0; uint8_t *rgbbuf = (uint8_t *)out; uint16_t data_size = len * 3; - //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); + + ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_READ, 0, NULL); // Init Rx DMA buffer, size, mode (spi and mem data size is 8 bit) @@ -573,20 +549,22 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) void ili9341_clear_screen(void) { - ili9341_fill(0, 0, ILI9341_WIDTH, ILI9341_HEIGHT, background_color); + ili9341_fill(0, 0, ILI9341_WIDTH, ILI9341_HEIGHT); } #ifndef ili9341_set_foreground -void ili9341_set_foreground(uint16_t fg) +void ili9341_set_foreground(uint16_t fg_idx) { - foreground_color = fg; +// if (fg_idx >= 32) fg_idx = 0; + foreground_color = GET_PALTETTE_COLOR(fg_idx); } #endif #ifndef ili9341_set_background -void ili9341_set_background(uint16_t bg) +void ili9341_set_background(uint16_t bg_idx) { - background_color = bg; +// if (bg_idx >= 32) bg_idx = 0; + background_color = GET_PALTETTE_COLOR(bg_idx); } #endif @@ -740,7 +718,7 @@ void ili9341_line(int x0, int y0, int x1, int y1) if (e2 < dy) { err += dx; y0 += sy; } } #endif - + SWAP(foreground_color, background_color); if (x0 > x1) { SWAP(x0, x1); SWAP(y0, y1); @@ -765,12 +743,13 @@ void ili9341_line(int x0, int y0, int x1, int y1) } } if (dy > 0) - ili9341_fill(x0, y0, dx, dy, foreground_color); + ili9341_fill(x0, y0, dx, dy); else - ili9341_fill(x0, y0+dy, dx, -dy, foreground_color); + ili9341_fill(x0, y0+dy, dx, -dy); x0 += dx; y0 += dy; } + SWAP(foreground_color, background_color); } #if 0 diff --git a/main.c b/main.c index c6f25a9..0a51c49 100644 --- a/main.c +++ b/main.c @@ -863,11 +863,6 @@ usage: config_t config = { .magic = CONFIG_MAGIC, .dac_value = 1922, - .grid_color = DEFAULT_GRID_COLOR, - .ham_color = DEFAULT_HAM_COLOR, - .menu_normal_color = DEFAULT_MENU_COLOR, - .menu_active_color = DEFAULT_MENU_ACTIVE_COLOR, - .trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR}, // .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel .touch_cal = { 347, 495, 160, 205 }, // 2.8 inch LCD panel ._mode = _MODE_USB, @@ -875,6 +870,7 @@ config_t config = { #ifdef __VNA__ .harmonic_freq_threshold = 300000000, #endif + .lcd_palette = LCD_DEFAULT_PALETTE, .vbat_offset = 500, .low_level_offset = 100, // Uncalibrated .high_level_offset = 100, // Uncalibrated @@ -904,7 +900,7 @@ static const marker_t def_markers[MARKERS_MAX] = { }; // Load propeties default settings -void load_default_properties(void) +void load_LCD_properties(void) { //Magic add on caldata_save //current_props.magic = CONFIG_MAGIC; @@ -2234,43 +2230,19 @@ VNA_SHELL_FUNCTION(cmd_color) int i; if (argc != 2) { shell_printf("usage: color {id} {rgb24}\r\n"); - for (i=-3; i < TRACES_MAX; i++) { -#if 0 - switch(i) { - case -3: color = config.grid_color; break; - case -2: color = config.menu_normal_color; break; - case -1: color = config.menu_active_color; break; - default: color = config.trace_color[i];break; - } -#else - // WARNING!!! Dirty hack for size, depend from config struct - color = config.trace_color[i]; -#endif - color = ((color >> 3) & 0x001c00) | - ((color >> 5) & 0x0000f8) | - ((color << 16) & 0xf80000) | - ((color << 13) & 0x00e000); -// color = (color>>8)|(color<<8); -// color = ((color<<8)&0xF80000)|((color<<5)&0x00FC00)|((color<<3)&0x0000F8); - shell_printf(" %d: 0x%06x\r\n", i, color); + for (i=0; i < MAX_PALETTE; i++) { + color = GET_PALTETTE_COLOR(i); + color = HEXRGB(color); + shell_printf(" %2d: 0x%06x\r\n", i, color); } return; } i = my_atoi(argv[0]); - if (i < -3 && i >= TRACES_MAX) + if (i >= MAX_PALETTE) return; color = RGBHEX(my_atoui(argv[1])); -#if 0 - switch(i) { - case -3: config.grid_color = color; break; - case -2: config.menu_normal_color = color; break; - case -1: config.menu_active_color = color; break; - default: config.trace_color[i] = color;break; - } -#else - // WARNING!!! Dirty hack for size, depend from config struct - config.trace_color[i] = color; -#endif + config.lcd_palette[i] = color; + // Redraw all redraw_request|= REDRAW_AREA; } @@ -2742,7 +2714,7 @@ static UARTConfig uart_cfg_1 = { #endif #if 0 -static const SerialConfig default_config = +static const SerialConfig LCD_config = { 9600, 0, @@ -2851,7 +2823,7 @@ int main(void) /* restore config */ config_recall(); if (caldata_recall(0) == -1) { - load_default_properties(); + load_LCD_properties(); } /* @@ -2902,7 +2874,7 @@ int main(void) #endif if (caldata_recall(0) == -1) { - load_default_properties(); + load_LCD_properties(); } set_refer_output(-1); @@ -2973,8 +2945,8 @@ void hard_fault_handler_c(uint32_t *sp) int y = 0; int x = OFFSETX + 1; static char buf[96]; - ili9341_set_background(DEFAULT_BG_COLOR); - ili9341_set_foreground(DEFAULT_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); plot_printf(buf, sizeof(buf), "SP 0x%08x", (uint32_t)sp);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); plot_printf(buf, sizeof(buf), "R0 0x%08x", r0);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); diff --git a/nanovna.h b/nanovna.h index 2ea2a09..2ccf98e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -400,6 +400,9 @@ extern const uint8_t numfont16x22[]; #define S_OHM "\036" // 0x1E #define S_DEGREE "\037" // 0x1F +// Max palette indexes in config +#define MAX_PALETTE 32 + // trace #define MAX_TRACE_TYPE 12 enum trace_type { @@ -447,30 +450,27 @@ typedef struct trace { typedef struct config { int32_t magic; - uint16_t dac_value; - uint16_t grid_color; - uint16_t menu_normal_color; - uint16_t menu_active_color; - uint16_t trace_color[TRACES_MAX]; + uint16_t lcd_palette[MAX_PALETTE]; int16_t touch_cal[4]; - int8_t _mode; uint32_t _serial_speed; #ifdef __VNA__ uint32_t harmonic_freq_threshold; #endif + uint16_t dac_value; uint16_t vbat_offset; float low_level_offset; float high_level_offset; uint32_t correction_frequency[CORRECTION_POINTS]; float correction_value[CORRECTION_POINTS]; uint32_t deviceid; - uint16_t ham_color; + uint32_t setting_frequency_10mhz; + uint16_t gridlines; uint16_t hambands; - int8_t cor_am; + + int8_t _mode; int8_t cor_am; int8_t cor_wfm; int8_t cor_nfm; - uint32_t setting_frequency_10mhz; int8_t dummy; // uint8_t _reserved[22]; uint32_t checksum; @@ -573,12 +573,10 @@ extern volatile uint8_t redraw_request; * ili9341.c */ // SPI bus revert byte order -//gggBBBbb RRRrrGGG -#define byteReverse16(x) (uint16_t)(((x) << 8) & 0xff00) | (((x) >> 8) & 0xff) -#define RGB565(r,g,b) byteReverse16( ((((uint16_t)(r))<<8)&0b1111100000000000) | ((((uint16_t)(g))<<3)&0b0000011111100000) | ((((uint16_t)(b))>>3)&0b0000000000011111) ) - -//#define RGB565(r,g,b) ( (((g)&0x1c)<<11) | (((b)&0xf8)<<5) | ((r)&0xf8) | (((g)&0xe0)>>5) ) +// 16-bit gggBBBbb RRRrrGGG +#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 HEXRGB(hex) ( (((hex)>>3)&0x001c00) | (((hex)>>5)&0x0000f8) | (((hex)<<16)&0xf80000) | (((hex)<<13)&0x00e000) ) // Define size of screen buffer in pixels (one pixel 16bit size) #define SPI_BUFFER_SIZE (CELLWIDTH*CELLHEIGHT) @@ -586,27 +584,71 @@ extern volatile uint8_t redraw_request; #define LCD_WIDTH 320 #define LCD_HEIGHT 240 -#define DEFAULT_FG_COLOR RGB565(255,255,255) -#define DEFAULT_BG_COLOR RGB565( 0, 0, 0) -#define DARK_GREY RGB565(140,140,140) -#define LIGHT_GREY RGB565(220,220,220) -#define DEFAULT_GRID_COLOR RGB565(128,128,128) -#define DEFAULT_HAM_COLOR RGB565(80,80,80) -#define DEFAULT_GRID_VALUE_COLOR RGB565(196,196,196) -#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(255, 0, 0) /* RGB565(255,255, 0) */ -#define DEFAULT_TRACE_2_COLOR RGB565( 0,255, 0)/* RGB565( 0,255,255) */ -#define DEFAULT_TRACE_3_COLOR RGB565(255,255, 0)/* RGB565( 0,255, 0) */ -#define DEFAULT_TRIGGER_COLOR RGB565( 0, 0,255)/* RGB565( 0 0,255) */ -//#define DEFAULT_TRACE_4_COLOR RGB565(255, 0,255) -#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); -#define BRIGHT_COLOR_BLUE RGB565(0,0,255) -#define BRIGHT_COLOR_RED RGB565(255,128,128) -#define BRIGHT_COLOR_GREEN RGB565(0,255,0) +#define LCD_BG_COLOR 0 +#define LCD_FG_COLOR 1 +#define LCD_GRID_COLOR 2 +#define LCD_MENU_COLOR 3 +#define LCD_MENU_TEXT_COLOR 4 +#define LCD_MENU_ACTIVE_COLOR 5 +#define LCD_TRACE_1_COLOR 6 +#define LCD_TRACE_2_COLOR 7 +#define LCD_TRACE_3_COLOR 8 +#define LCD_TRACE_4_COLOR 9 +#define LCD_NORMAL_BAT_COLOR 10 +#define LCD_LOW_BAT_COLOR 11 +#define LCD_TRIGGER_COLOR 12 +#define LCD_RISE_EDGE_COLOR 13 +#define LCD_FALLEN_EDGE_COLOR 14 +#define LCD_SWEEP_LINE_COLOR 15 +#define LCD_BW_TEXT_COLOR 16 +#define LCD_INPUT_TEXT_COLOR 17 +#define LCD_INPUT_BG_COLOR 18 +#define LCD_BRIGHT_COLOR_BLUE 19 +#define LCD_BRIGHT_COLOR_RED 20 +#define LCD_BRIGHT_COLOR_GREEN 21 +#define LCD_DARK_GREY 22 +#define LCD_LIGHT_GREY 23 +#define LCD_HAM_COLOR 24 +#define LCD_GRID_VALUE_COLOR 25 +#define LCD_M_REFERENCE 26 +#define LCD_M_DELTA 27 +#define LCD_M_NOISE 28 +#define LCD_M_DEFAULT 29 + +#define LCD_DEFAULT_PALETTE {\ +[LCD_BG_COLOR ] = RGB565( 0, 0, 0), \ +[LCD_FG_COLOR ] = RGB565(255,255,255), \ +[LCD_GRID_COLOR ] = RGB565(128,128,128), \ +[LCD_MENU_COLOR ] = RGB565(230,230,230), \ +[LCD_MENU_TEXT_COLOR ] = RGB565( 0, 0, 0), \ +[LCD_MENU_ACTIVE_COLOR] = RGB565(210,210,210), \ +[LCD_TRACE_1_COLOR ] = RGB565(255,255, 0), \ +[LCD_TRACE_2_COLOR ] = RGB565( 0,255,255), \ +[LCD_TRACE_3_COLOR ] = RGB565( 0,255, 0), \ +[LCD_TRACE_4_COLOR ] = RGB565(255, 0,255), \ +[LCD_NORMAL_BAT_COLOR ] = RGB565( 31,227, 0), \ +[LCD_LOW_BAT_COLOR ] = RGB565(255, 0, 0), \ +[LCD_TRIGGER_COLOR ] = RGB565( 0, 0,255), \ +[LCD_RISE_EDGE_COLOR ] = RGB565(255,255,255), \ +[LCD_FALLEN_EDGE_COLOR] = RGB565(128,128,128), \ +[LCD_SWEEP_LINE_COLOR ] = RGB565( 0,255, 0), \ +[LCD_BW_TEXT_COLOR ] = RGB565(128,128,128), \ +[LCD_INPUT_TEXT_COLOR ] = RGB565( 0, 0, 0), \ +[LCD_INPUT_BG_COLOR ] = RGB565(255,255,255), \ +[LCD_BRIGHT_COLOR_BLUE] = RGB565( 0, 0,255), \ +[LCD_BRIGHT_COLOR_RED ] = RGB565(255,128,128), \ +[LCD_BRIGHT_COLOR_GREEN]= RGB565( 0,255, 0), \ +[LCD_DARK_GREY ] = RGB565(140,140,140), \ +[LCD_LIGHT_GREY ] = RGB565(220,220,220), \ +[LCD_HAM_COLOR ] = RGB565( 80, 80, 80), \ +[LCD_GRID_VALUE_COLOR ] = RGB565(196,196,196), \ +[LCD_M_REFERENCE ] = RGB565(255,255,255), \ +[LCD_M_DELTA ] = RGB565( 0,255, 0), \ +[LCD_M_NOISE ] = RGB565( 0,255,255), \ +[LCD_M_DEFAULT ] = RGB565(255,255, 0), \ +} + +#define GET_PALTETTE_COLOR(idx) config.lcd_palette[idx] extern uint16_t foreground_color; extern uint16_t background_color; @@ -622,15 +664,10 @@ extern uint16_t spi_buffer[SPI_BUFFER_SIZE]; void ili9341_init(void); void ili9341_test(int mode); void ili9341_bulk(int x, int y, int w, int h); -void ili9341_fill(int x, int y, int w, int h, uint16_t color); +void ili9341_fill(int x, int y, int w, int h); -#if 1 -void ili9341_set_foreground(uint16_t fg); -void ili9341_set_background(uint16_t fg); -#else -#define ili9341_set_foreground(fg) { foreground_color = fg; } -#define ili9341_set_background(bg) { background_color = bg;} -#endif +void ili9341_set_foreground(uint16_t fg_idx); +void ili9341_set_background(uint16_t bg_idx); void ili9341_clear_screen(void); void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap); @@ -815,7 +852,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e46 /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e47 /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/plot.c b/plot.c index 2e6fb6c..6497c2b 100644 --- a/plot.c +++ b/plot.c @@ -74,12 +74,12 @@ typedef uint32_t map_t; uint16_t marker_color(int mtype) { if (mtype & M_REFERENCE) - return(RGBHEX(0xFFFFFF)); + return LCD_M_REFERENCE; if (mtype & M_DELTA) - return(RGBHEX(0x00FF00)); + return LCD_M_DELTA; if (mtype & M_NOISE) - return(RGBHEX(0x00FFFF)); - return(RGBHEX(0xFFFF00)); + return LCD_M_NOISE; + return LCD_M_DEFAULT; } //#if 4 != M_TRACKING @@ -149,8 +149,10 @@ void update_grid(void) grid_width = (WIDTH) * (grid / 100) / (fspan / 1000); force_set_markmap(); - if (get_waterfall()) - ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom, 0); + if (get_waterfall()){ + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom); + } redraw_request |= REDRAW_FREQUENCY; } @@ -1539,27 +1541,28 @@ draw_cell(int m, int n) #if 0 // use memset 350 system ticks for all screen calls // as understand it use 8 bit set, slow down on 32 bit systems - memset(spi_buffer, DEFAULT_BG_COLOR, (h*CELLWIDTH)*sizeof(uint16_t)); + memset(spi_buffer, LCD_BG_COLOR, (h*CELLWIDTH)*sizeof(uint16_t)); #else // use direct set 35 system ticks for all screen calls #if CELLWIDTH%8 != 0 #error "CELLWIDTH % 8 should be == 0 for speed, or need rewrite cell cleanup" #endif - // Set DEFAULT_BG_COLOR for 8 pixels in one cycle - int count = h*CELLWIDTH / (16/sizeof(pixel_t)); + // Set LCD_BG_COLOR for 8 pixels in one cycle + int count = h*CELLWIDTH / 8; uint32_t *p = (uint32_t *)cell_buffer; + uint32_t clr = GET_PALTETTE_COLOR(LCD_BG_COLOR) | (GET_PALTETTE_COLOR(LCD_BG_COLOR) << 16); 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[0] = clr; + p[1] = clr; + p[2] = clr; + p[3] = clr; p += 4; } #endif // Draw grid #if 1 - c = config.grid_color; + c = GET_PALTETTE_COLOR(LCD_GRID_COLOR); // Generate grid type list uint32_t trace_type = 0; for (t = 0; t < TRACES_MAX; t++) { @@ -1572,7 +1575,7 @@ draw_cell(int m, int n) for (x = 0; x < w; x++) { #ifdef __HAM_BAND__ if (ham_band(x+x0)) { - for (y = 0; y < h; y++) cell_buffer[y * CELLWIDTH + x] = config.ham_color; + for (y = 0; y < h; y++) cell_buffer[y * CELLWIDTH + x] = GET_PALTETTE_COLOR(LCD_HAM_COLOR); } #endif if (rectangular_grid_x(x + x0)) { @@ -1618,7 +1621,7 @@ draw_cell(int m, int n) if (tp>=0 && tp < h) for (x = 0; x < w; x++) if (x + x0 >= CELLOFFSETX && x + x0 <= WIDTH + CELLOFFSETX) - cell_buffer[tp * CELLWIDTH + x] = DEFAULT_TRIGGER_COLOR; + cell_buffer[tp * CELLWIDTH + x] = LCD_TRIGGER_COLOR; } #if 1 @@ -1633,7 +1636,7 @@ draw_cell(int m, int n) for (t = 0; t < TRACES_MAX; t++) { if (!trace[t].enabled) continue; - c = config.trace_color[t]; + c = GET_PALTETTE_COLOR(LCD_TRACE_1_COLOR + t); // draw polar plot (check all points) i0 = 0; i1 = 0; @@ -1674,10 +1677,10 @@ draw_cell(int m, int n) if (x + MARKER_WIDTH >= 0 && x - MARKER_WIDTH < CELLWIDTH && y + MARKER_HEIGHT >= 0 && y - MARKER_HEIGHT < CELLHEIGHT){ // Draw marker plate - ili9341_set_foreground(config.trace_color[t]); + ili9341_set_foreground(LCD_TRACE_1_COLOR + t); cell_blit_bitmap(x, y, MARKER_WIDTH, MARKER_HEIGHT, MARKER_BITMAP(0)); // Draw marker number - ili9341_set_foreground(DEFAULT_BG_COLOR); + ili9341_set_foreground(LCD_BG_COLOR); cell_blit_bitmap(x, y, MARKER_WIDTH, MARKER_HEIGHT, MARKER_BITMAP(i+1)); } // } @@ -1704,7 +1707,7 @@ draw_cell(int m, int n) if (x + REFERENCE_WIDTH >= 0 && x - REFERENCE_WIDTH < CELLWIDTH) { int y = HEIGHT - float2int((get_trace_refpos(t) * GRIDY)) - y0 - REFERENCE_Y_OFFSET; if (y + REFERENCE_HEIGHT >= 0 && y - REFERENCE_HEIGHT < CELLHEIGHT){ - ili9341_set_foreground(config.trace_color[t]); + ili9341_set_foreground(GET_PALTETTE_COLOR(LCD_TRACE_1_COLOR + t)); cell_blit_bitmap(x , y, REFERENCE_WIDTH, REFERENCE_HEIGHT, reference_bitmap); } } @@ -1942,7 +1945,7 @@ cell_draw_marker_info(int x0, int y0) int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0; - ili9341_set_foreground(config.trace_color[t]); + ili9341_set_foreground(GET_PALTETTE_COLOR(LCD_TRACE_1_COLOR + t)); if (mk == active_marker) cell_drawstring(S_SARROW, xpos, ypos); xpos += 5; @@ -1964,7 +1967,7 @@ cell_draw_marker_info(int x0, int y0) trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index); else trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index); - ili9341_set_foreground(DEFAULT_FG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); cell_drawstring(buf, xpos, ypos); j++; } @@ -1976,7 +1979,7 @@ cell_draw_marker_info(int x0, int y0) int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0; plot_printf(buf, sizeof buf, S_DELTA"%d-%d:", active_marker+1, previous_marker+1); - ili9341_set_foreground(DEFAULT_FG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); cell_drawstring(buf, xpos, ypos); xpos += 27; if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { @@ -1996,7 +1999,7 @@ cell_draw_marker_info(int x0, int y0) int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0; - ili9341_set_foreground(config.trace_color[t]); + ili9341_set_foreground(GET_PALTETTE_COLOR(LCD_TRACE_1_COLOR + t)); if (t == uistat.current_trace) cell_drawstring(S_SARROW, xpos, ypos); xpos += 5; @@ -2009,7 +2012,7 @@ cell_draw_marker_info(int x0, int y0) xpos += n * 5 + 2; //xpos += 60; trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], idx); - ili9341_set_foreground(DEFAULT_FG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); cell_drawstring(buf, xpos, ypos); j++; } @@ -2018,7 +2021,7 @@ cell_draw_marker_info(int x0, int y0) int xpos = (WIDTH/2+40) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0; - ili9341_set_foreground(DEFAULT_FG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); if (uistat.lever_mode == LM_MARKER) cell_drawstring(S_SARROW, xpos, ypos); xpos += 5; @@ -2033,7 +2036,7 @@ cell_draw_marker_info(int x0, int y0) } cell_drawstring(buf, xpos, ypos); } - ili9341_set_foreground(DEFAULT_FG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); if (electrical_delay != 0) { // draw electrical delay int xpos = 21 + CELLOFFSETX - x0; @@ -2058,7 +2061,7 @@ static void cell_grid_line_info(int x0, int y0) char buf[32]; int xpos = GRID_X_TEXT - x0; int ypos = 0 - y0 + 2; - ili9341_set_foreground(DEFAULT_GRID_VALUE_COLOR); + ili9341_set_foreground(LCD_GRID_VALUE_COLOR); float ref = get_trace_refpos(TRACE_ACTUAL); float scale = get_trace_scale(TRACE_ACTUAL);; for (int i = 0; i < NGRIDY; i++){ @@ -2208,11 +2211,11 @@ static void cell_draw_marker_info(int x0, int y0) #endif int k = 0; if (i == active_marker) { -// ili9341_set_foreground(DEFAULT_BG_COLOR); +// ili9341_set_foreground(LCD_BG_COLOR); // ili9341_set_background(marker_color(markers[i].mtype)); buf[k++] = S_SARROW[0]; } else { -// ili9341_set_background(DEFAULT_BG_COLOR); +// ili9341_set_background(LCD_BG_COLOR); // ili9341_set_foreground(marker_color(markers[i].mtype)); buf[k++] = ' '; // buf[k++] = ' '; @@ -2228,12 +2231,12 @@ static void cell_draw_marker_info(int x0, int y0) buf[k++] = 'N'; buf[k++] = ' '; // buf[k++] = 0; - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_background(LCD_BG_COLOR); uint16_t color; if ((!setting.subtract_stored) && // Disabled when normalized ((setting.mode == M_LOW && temppeakLevel - get_attenuation() + setting.offset > -10) || (setting.mode == M_HIGH && temppeakLevel - get_attenuation()+ setting.offset > -29) )) - color = BRIGHT_COLOR_RED; + color = LCD_BRIGHT_COLOR_RED; else color = marker_color(markers[i].mtype); ili9341_set_foreground(color); @@ -2285,9 +2288,9 @@ draw_frequencies(void) plot_printf(buf2, sizeof(buf2), "STOP %Fs (%Fm)", time_of_index(sweep_points-1), distance_of_index(sweep_points-1)); } #endif - ili9341_set_foreground(DEFAULT_FG_COLOR); - ili9341_set_background(DEFAULT_BG_COLOR); - ili9341_fill(0, FREQUENCIES_YPOS, LCD_WIDTH, FONT_GET_HEIGHT, DEFAULT_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(0, FREQUENCIES_YPOS, LCD_WIDTH, FONT_GET_HEIGHT); if (uistat.lever_mode == LM_CENTER) buf1[0] = S_SARROW[0]; if (uistat.lever_mode == LM_SPAN) @@ -2306,9 +2309,9 @@ draw_cal_status(void) int x = 0; int y = 100; char c[3]; - ili9341_set_foreground(DEFAULT_FG_COLOR); - ili9341_set_background(DEFAULT_BG_COLOR); - ili9341_fill(0, y, OFFSETX, 6*(FONT_GET_HEIGHT+1), DEFAULT_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(0, y, OFFSETX, 6*(FONT_GET_HEIGHT+1), LCD_BG_COLOR); if (cal_status & CALSTAT_APPLY) { c[0] = cal_status & CALSTAT_INTERPOLATED ? 'c' : 'C'; c[1] = active_props == ¤t_props ? '*' : '0' + lastsaveid; @@ -2342,8 +2345,8 @@ static void draw_battery_status(void) return; uint8_t string_buf[16]; // Set battery color - ili9341_set_foreground(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR); - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_foreground(vbat < BATTERY_WARNING_LEVEL ? LCD_LOW_BAT_COLOR : LCD_NORMAL_BAT_COLOR); + ili9341_set_background(LCD_BG_COLOR); // Prepare battery bitmap image // Battery top @@ -2377,7 +2380,7 @@ request_to_redraw_grid(void) void redraw_frame(void) { - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_background(LCD_BG_COLOR); ili9341_clear_screen(); draw_frequencies(); draw_cal_status(); @@ -2474,7 +2477,8 @@ toggle_waterfall(void) waterfall = W_OFF; } _grid_y = graph_bottom / NGRIDY; - ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom, 0); + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom); request_to_redraw_grid(); } diff --git a/sa_cmd.c b/sa_cmd.c index f2f9644..3cda7e9 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -628,7 +628,6 @@ VNA_SHELL_FUNCTION(cmd_caloutput) { static const char cmd[] = "off|30|15|10|4|3|2|1"; if (argc != 1) { - usage: shell_printf("usage: caloutput %s\r\n", cmd); return; } diff --git a/sa_core.c b/sa_core.c index 45e370e..a6c5752 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2017,7 +2017,8 @@ sweep_again: // stay in sweep loop when output mo scandirty = false; if (break_on_operation && operation_requested) { // break loop if needed if (setting.actual_sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) { - ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1, 0); // Erase progress bar + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1); // Erase progress bar } return false; } @@ -2057,8 +2058,10 @@ sweep_again: // stay in sweep loop when output mo if (setting.actual_sweep_time_us > ONE_SECOND_TIME && (i & 0x07) == 0) { // if required int pos = i * (WIDTH+1) / sweep_points; - ili9341_fill(OFFSETX, CHART_BOTTOM+1, pos, 1, BRIGHT_COLOR_GREEN); // update sweep progress bar - ili9341_fill(OFFSETX+pos, CHART_BOTTOM+1, WIDTH-pos, 1, 0); + ili9341_set_background(LCD_SWEEP_LINE_COLOR); + ili9341_fill(OFFSETX, CHART_BOTTOM+1, pos, 1); // update sweep progress bar + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(OFFSETX+pos, CHART_BOTTOM+1, WIDTH-pos, 1); } // ------------------------ do all RSSI calculations from CALC menu ------------------- @@ -2177,10 +2180,11 @@ sweep_again: // stay in sweep loop when output mo } // scandirty = true; // To show trigger happened } - if (setting.actual_sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) - ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1, 0); // Erase progress bar before updating actual_sweep_time - - + if (setting.actual_sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) { + // ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1, 0); // Erase progress bar before updating actual_sweep_time + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1); + } // ---------------------- process measured actual sweep time ----------------- // For CW mode value calculated in SI4432_Fill if (setting.measure_sweep_time_us == 0) @@ -2755,8 +2759,8 @@ void draw_cal_status(void) if (!UNIT_IS_LINEAR(setting.unit)) rounding = true; const char * const unit = unit_string[setting.unit]; - - ili9341_fill(0, 0, OFFSETX, CHART_BOTTOM, 0x0000); + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(0, 0, OFFSETX, CHART_BOTTOM); if (MODE_OUTPUT(setting.mode)) { // No cal status during output return; } @@ -2764,7 +2768,7 @@ void draw_cal_status(void) // if (current_menu_is_form() && !in_selftest) // return; - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_background(LCD_BG_COLOR); float yMax = setting.reflevel; // Top level @@ -2773,20 +2777,16 @@ void draw_cal_status(void) else plot_printf(buf, BLEN, "%+4.3F", (yMax/setting.unit_scale)); - if (level_is_calibrated()) { - if (setting.auto_reflevel) - color = DEFAULT_FG_COLOR; - else - color = BRIGHT_COLOR_GREEN; - } + if (level_is_calibrated()) + color = setting.auto_reflevel ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN; else - color = BRIGHT_COLOR_RED; + color = LCD_BRIGHT_COLOR_RED; ili9341_set_foreground(color); ili9341_drawstring(buf, x, y); // Unit #if 0 - color = DEFAULT_FG_COLOR; + color = LCD_FG_COLOR; ili9341_set_foreground(color); if (setting.auto_reflevel){ y += YSTEP + YSTEP/2 ; @@ -2798,7 +2798,7 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); // Scale - color = DEFAULT_FG_COLOR; + color = LCD_FG_COLOR; ili9341_set_foreground(color); y += YSTEP + YSTEP/2; #if 1 @@ -2817,20 +2817,20 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); if (is_paused()) { - color = BRIGHT_COLOR_GREEN; + color = LCD_BRIGHT_COLOR_GREEN; ili9341_set_foreground(color); y += YSTEP + YSTEP/2 ; ili9341_drawstring("PAUSED", x, y); } if (setting.trigger == T_SINGLE || setting.trigger == T_NORMAL ) { - color = BRIGHT_COLOR_GREEN; + color = LCD_BRIGHT_COLOR_GREEN; ili9341_set_foreground(color); y += YSTEP + YSTEP/2 ; ili9341_drawstring("ARMED", x, y); } if (signal_is_AM) { - color = BRIGHT_COLOR_RED; + color = LCD_BRIGHT_COLOR_RED; ili9341_set_foreground(color); y += YSTEP + YSTEP/2 ; ili9341_drawstring("AM", x, y); @@ -2839,9 +2839,9 @@ void draw_cal_status(void) // if (setting.mode == M_LOW) { // Attenuation if (setting.auto_attenuation) - color = DEFAULT_FG_COLOR; + color = LCD_FG_COLOR; else - color = BRIGHT_COLOR_GREEN; + color = LCD_BRIGHT_COLOR_GREEN; ili9341_set_foreground(color); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Atten:", x, y); @@ -2852,7 +2852,7 @@ void draw_cal_status(void) // Average if (setting.average>0) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Calc:", x, y); @@ -2863,7 +2863,7 @@ void draw_cal_status(void) // Spur #ifdef __SPUR__ if (setting.spur_removal) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Spur:", x, y); @@ -2872,7 +2872,7 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); } if (setting.mirror_masking) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Mask:", x, y); @@ -2883,16 +2883,16 @@ void draw_cal_status(void) #endif if (setting.subtract_stored) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Norm.", x, y); } // RBW if (setting.rbw_x10) - color = BRIGHT_COLOR_GREEN; + color = LCD_BRIGHT_COLOR_GREEN; else - color = DEFAULT_FG_COLOR; + color = LCD_FG_COLOR; ili9341_set_foreground(color); y += YSTEP + YSTEP/2 ; @@ -2905,7 +2905,7 @@ void draw_cal_status(void) #if 0 // VBW if (setting.frequency_step > 0) { - ili9341_set_foreground(DEFAULT_FG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); y += YSTEP + YSTEP/2 ; ili9341_drawstring("VBW:", x, y); @@ -2917,9 +2917,9 @@ void draw_cal_status(void) #endif // Sweep time if (setting.step_delay != 0) - color = BRIGHT_COLOR_GREEN; + color = LCD_BRIGHT_COLOR_GREEN; else - color = DEFAULT_FG_COLOR; + color = LCD_FG_COLOR; ili9341_set_foreground(color); @@ -2958,7 +2958,7 @@ void draw_cal_status(void) // Cal output if (setting.refer >= 0) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Ref:", x, y); @@ -2970,7 +2970,7 @@ void draw_cal_status(void) // Offset if (setting.offset != 0.0) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Amp:", x, y); @@ -2981,7 +2981,7 @@ void draw_cal_status(void) // Repeat if (setting.repeat != 1) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Repeat:", x, y); @@ -2994,9 +2994,9 @@ void draw_cal_status(void) // Trigger if (setting.trigger != T_AUTO) { if (is_paused() || setting.trigger == T_NORMAL) { - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); } else { - ili9341_set_foreground(BRIGHT_COLOR_RED); + ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); } y += YSTEP + YSTEP/2 ; ili9341_drawstring("TRIG:", x, y); @@ -3012,16 +3012,16 @@ void draw_cal_status(void) // Mode if (level_is_calibrated()) - color = BRIGHT_COLOR_GREEN; + color = LCD_BRIGHT_COLOR_GREEN; else - color = BRIGHT_COLOR_RED; + color = LCD_BRIGHT_COLOR_RED; ili9341_set_foreground(color); y += YSTEP + YSTEP/2 ; ili9341_drawstring_7x13(MODE_LOW(setting.mode) ? "LOW" : "HIGH", x, y); // Compact status string -// ili9341_set_background(DEFAULT_FG_COLOR); - ili9341_set_foreground(DEFAULT_FG_COLOR); +// ili9341_set_background(LCD_FG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); y += YSTEP + YSTEP/2 ; strncpy(buf," ",BLEN-1); if (setting.auto_attenuation) @@ -3055,7 +3055,7 @@ void draw_cal_status(void) strncpy(buf,&VERSION[8], BLEN-1); ili9341_drawstring(buf, x, y); -// ili9341_set_background(DEFAULT_BG_COLOR); +// ili9341_set_background(LCD_BG_COLOR); if (!get_waterfall()) { // Do not draw bottom level if in waterfall mode // Bottom level y = area_height - 8 + OFFSETY; @@ -3066,11 +3066,11 @@ void draw_cal_status(void) // buf[5]=0; if (level_is_calibrated()) if (setting.auto_reflevel) - color = DEFAULT_FG_COLOR; + color = LCD_FG_COLOR; else - color = BRIGHT_COLOR_GREEN; + color = LCD_BRIGHT_COLOR_GREEN; else - color = BRIGHT_COLOR_RED; + color = LCD_BRIGHT_COLOR_RED; ili9341_set_foreground(color); ili9341_drawstring(buf, x, y); } @@ -3496,7 +3496,7 @@ void self_test(int test) if (test_step == 2) { if (peakLevel < -60) { test_step = TEST_END; - ili9341_set_foreground(BRIGHT_COLOR_RED); + ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); ili9341_drawstring_7x13("Signal level too low", 30, 140); ili9341_drawstring_7x13("Check cable between High and Low connectors", 30, 160); goto resume2; @@ -3512,7 +3512,7 @@ void self_test(int test) } test_step++; } while (test_case[test_step].kind != TC_END && setting.test_argument == 0 ); - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_drawstring_7x13("Self test complete", 50, 200); ili9341_drawstring_7x13("Touch screen to continue", 50, 215); resume2: @@ -3760,14 +3760,14 @@ void calibrate(void) test_acquire(TEST_POWER); // Acquire test local_test_status = test_validate(TEST_POWER); // Validate test if (peakLevel < -50) { - ili9341_set_foreground(BRIGHT_COLOR_RED); + ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); ili9341_drawstring_7x13("Signal level too low", 30, 140); ili9341_drawstring_7x13("Check cable between High and Low connectors", 30, 160); goto quit; } // chThdSleepMilliseconds(1000); if (local_test_status != TS_PASS) { - ili9341_set_foreground(BRIGHT_COLOR_RED); + ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); ili9341_drawstring_7x13("Calibration failed", 30, 140); goto quit; } else { @@ -3803,7 +3803,7 @@ void calibrate(void) #endif config_save(); - ili9341_set_foreground(BRIGHT_COLOR_GREEN); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_drawstring_7x13("Calibration complete", 30, 140); quit: ili9341_drawstring_7x13("Touch screen to continue", 30, 200); diff --git a/ui.c b/ui.c index 840693c..b46f0b9 100644 --- a/ui.c +++ b/ui.c @@ -328,8 +328,8 @@ touch_cal_exec(void) int x1, x2, y1, y2; adc_stop(); - ili9341_set_foreground(DEFAULT_FG_COLOR); - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); ili9341_clear_screen(); ili9341_line(0, 0, 0, 32); ili9341_line(0, 0, 32, 0); @@ -369,8 +369,8 @@ touch_draw_test(void) adc_stop(); - ili9341_set_foreground(DEFAULT_FG_COLOR); - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); ili9341_clear_screen(); ili9341_drawstring("TOUCH TEST: DRAG PANEL, PRESS BUTTON TO FINISH", OFFSETX, LCD_HEIGHT - FONT_GET_HEIGHT); @@ -414,8 +414,8 @@ show_version(void) { int x = 5, y = 5, i = 0; adc_stop(); - ili9341_set_foreground(DEFAULT_FG_COLOR); - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); ili9341_clear_screen(); uint16_t shift = 0b0000010000111110; @@ -440,8 +440,8 @@ enter_dfu(void) adc_stop(); int x = 5, y = 5; - ili9341_set_foreground(DEFAULT_FG_COLOR); - ili9341_set_background(DEFAULT_BG_COLOR); + ili9341_set_foreground(LCD_FG_COLOR); + ili9341_set_background(LCD_BG_COLOR); // leave a last message ili9341_clear_screen(); ili9341_drawstring_7x13("DFU: Device Firmware Update Mode\n" @@ -1446,15 +1446,15 @@ static void draw_button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, ui_button_t *b) { uint16_t bw = b->border&BUTTON_BORDER_WIDTH_MASK; - ili9341_fill(x + bw, y + bw, w - (bw * 2), h - (bw * 2), b->bg); + ili9341_set_background(b->bg);ili9341_fill(x + bw, y + bw, w - (bw * 2), h - (bw * 2)); if (bw==0) return; - uint16_t br = RGB565(255,255,255); - uint16_t bd = RGB565(196,196,196); + uint16_t br = LCD_RISE_EDGE_COLOR; + uint16_t bd = LCD_FALLEN_EDGE_COLOR; uint16_t type = b->border; - ili9341_fill(x, y, w, bw, type&BUTTON_BORDER_TOP ? br : bd); // top - ili9341_fill(x + w - bw, y, bw, h, type&BUTTON_BORDER_RIGHT ? br : bd); // right - ili9341_fill(x, y, bw, h, type&BUTTON_BORDER_LEFT ? br : bd); // left - ili9341_fill(x, y + h - bw, w, bw, type&BUTTON_BORDER_BOTTOM ? br : bd); // bottom + ili9341_set_background(type&BUTTON_BORDER_TOP ? br : bd);ili9341_fill(x, y, w, bw); // top + ili9341_set_background(type&BUTTON_BORDER_RIGHT ? br : bd);ili9341_fill(x + w - bw, y, bw, h); // right + ili9341_set_background(type&BUTTON_BORDER_LEFT ? br : bd);ili9341_fill(x, y, bw, h); // left + ili9341_set_background(type&BUTTON_BORDER_BOTTOM ? br : bd);ili9341_fill(x, y + h - bw, w, bw); // bottom } static void @@ -1462,20 +1462,20 @@ draw_keypad(void) { int i = 0; ui_button_t button; - button.fg = DEFAULT_MENU_TEXT_COLOR; + button.fg = LCD_MENU_TEXT_COLOR; while (keypads[i].c >= 0) { - button.bg = RGB565(230,230,230);//config.menu_normal_color; + button.bg = LCD_MENU_COLOR; if (i == selection){ - button.bg = RGB565(210,210,210);//config.menu_active_color; + button.bg = LCD_MENU_ACTIVE_COLOR; button.border = KEYBOARD_BUTTON_BORDER|BUTTON_BORDER_FALLING; } else button.border = KEYBOARD_BUTTON_BORDER|BUTTON_BORDER_RISE; - ili9341_set_foreground(button.fg); - ili9341_set_background(button.bg); int x = KP_GET_X(keypads[i].x); int y = KP_GET_Y(keypads[i].y); draw_button(x, y, KP_WIDTH, KP_HEIGHT, &button); + ili9341_set_foreground(button.fg); + ili9341_set_background(button.bg); if (keypads[i].c < KP_0) { // KP_0 ili9341_drawfont(keypads[i].c, x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2, @@ -1503,9 +1503,10 @@ menu_is_multiline(const char *label) static void draw_numeric_area_frame(void) { - ili9341_fill(0, LCD_HEIGHT-NUM_INPUT_HEIGHT, LCD_WIDTH, NUM_INPUT_HEIGHT, config.menu_normal_color); - ili9341_set_foreground(DEFAULT_MENU_TEXT_COLOR); - ili9341_set_background(config.menu_normal_color); + ili9341_set_foreground(LCD_INPUT_TEXT_COLOR); + ili9341_set_background(LCD_INPUT_BG_COLOR); + + ili9341_fill(0, LCD_HEIGHT-NUM_INPUT_HEIGHT, LCD_WIDTH, NUM_INPUT_HEIGHT); char *name = keypads_mode_tbl[keypad_mode].name; int lines = menu_is_multiline(name); ili9341_drawstring_7x13(name, 10, LCD_HEIGHT-NUM_INPUT_HEIGHT + (NUM_INPUT_HEIGHT-lines*bFONT_STR_HEIGHT)/2); @@ -1520,8 +1521,8 @@ draw_numeric_input(const char *buf) int focused = FALSE; uint16_t xsim = 0b0010010000000000; - uint16_t fg = DEFAULT_MENU_TEXT_COLOR; - uint16_t bg = config.menu_normal_color; + uint16_t fg = LCD_INPUT_TEXT_COLOR; + uint16_t bg = LCD_INPUT_BG_COLOR; for (i = 0, x = 64; i < 10 && buf[i]; i++, xsim<<=1) { int c = buf[i]; if (c == '.') @@ -1538,13 +1539,13 @@ draw_numeric_input(const char *buf) else if (focused) // c not number, but focused ili9341_drawfont(0, x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4); else // erase - ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_HEIGHT, NUM_FONT_GET_WIDTH+2+8, bg); + ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_HEIGHT, NUM_FONT_GET_WIDTH+2+8); x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2; } // erase last // ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_WIDTH+2+8, NUM_FONT_GET_WIDTH+2+8, config.menu_normal_color); - ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, LCD_WIDTH-x-1, NUM_FONT_GET_WIDTH+2+8, config.menu_normal_color); + ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, LCD_WIDTH-x-1, NUM_FONT_GET_WIDTH+2+8); if (buf[0] == 0 && kp_help_text != NULL) { ili9341_set_foreground(fg); ili9341_set_background(bg); @@ -1564,24 +1565,24 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, } else if (menu == menu_marker_sel) { if (item < 4) { if (markers[item].enabled) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } else if (item == 5) { if (uistat.marker_delta) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } } else if (menu == menu_marker_search) { if (item == 4 && uistat.marker_tracking) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } else if (menu == menu_marker_smith) { if (marker_smith_format == item) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } else if (menu == menu_calop) { @@ -1591,17 +1592,17 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, || (item == 3 && (cal_status & CALSTAT_ISOLN)) || (item == 4 && (cal_status & CALSTAT_THRU))) { domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ; - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } else if (menu == menu_stimulus) { if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } else if (menu == menu_cal) { if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY)) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } else if (menu == menu_bandwidth) { @@ -1615,7 +1616,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, || (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP) || (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS) ) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } else if (menu == menu_transform_window) { @@ -1623,7 +1624,7 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, || (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL) || (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM) ) { - *bg = DEFAULT_MENU_TEXT_COLOR; + *bg = LCD_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } } @@ -1738,16 +1739,16 @@ draw_menu_buttons(const menuitem_t *menu) button.border = MENU_BUTTON_BORDER; if (MT_MASK(menu[i].type) == MT_TITLE) { - button.fg = RGB565(255,255,255);//config.menu_normal_color; - button.bg = DEFAULT_MENU_TEXT_COLOR; + button.fg = LCD_FG_COLOR; + button.bg = LCD_BG_COLOR; button.border = 0; // no border for title } else { - button.bg = RGB565(230,230,230); - button.fg = DEFAULT_MENU_TEXT_COLOR; + button.bg = LCD_MENU_COLOR; + button.fg = LCD_MENU_TEXT_COLOR; } if (i == selection){ - button.bg = RGB565(210,210,210);//config.menu_active_color; + button.bg = LCD_MENU_ACTIVE_COLOR; button.border|= BUTTON_BORDER_FALLING; } else @@ -1771,13 +1772,14 @@ draw_menu_buttons(const menuitem_t *menu) // Prepare button label plot_printf(button.text, sizeof button.text, menu[i].label, button.param_1.u, button.param_2.u); - ili9341_set_foreground(button.fg); - ili9341_set_background(button.bg); if (menu[i].type & MT_FORM) { int button_width = MENU_FORM_WIDTH; int button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; // At center of screen int button_height = MENU_BUTTON_HEIGHT; draw_button(button_start, y, button_width, button_height, &button); + + ili9341_set_foreground(button.fg); + ili9341_set_background(button.bg); uint16_t text_offs = button_start + 6; if (button.icon >=0){ blit8BitWidthBitmap(button_start+3, y+(MENU_BUTTON_HEIGHT-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); @@ -1796,6 +1798,8 @@ draw_menu_buttons(const menuitem_t *menu) int button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; int button_height = MENU_BUTTON_HEIGHT; draw_button(button_start, y, button_width, button_height, &button); + ili9341_set_foreground(button.fg); + ili9341_set_background(button.bg); uint16_t text_offs = button_start + 7; if (button.icon >=0){ blit8BitWidthBitmap(button_start+2, y+(MENU_BUTTON_HEIGHT-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); @@ -1812,8 +1816,9 @@ draw_menu_buttons(const menuitem_t *menu) y += MENU_BUTTON_HEIGHT; } // Cleanup other buttons (less flicker) + ili9341_set_background(LCD_BG_COLOR); for (; y < MENU_BUTTON_MAX*MENU_BUTTON_HEIGHT; y+=MENU_BUTTON_HEIGHT) - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT, DEFAULT_BG_COLOR); + ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT); } static systime_t prev_touch_time = 0; @@ -1925,11 +1930,11 @@ static void erase_menu_buttons(void) { // Not need, screen redraw in all cases -// ili9341_fill(area_width, 0, LCD_WIDTH - area_width, area_height, DEFAULT_BG_COLOR); +// ili9341_fill(area_width, 0, LCD_WIDTH - area_width, area_height, LCD_BG_COLOR); // if (current_menu_is_form()) - // ili9341_fill(OFFSETX, 0,LCD_WIDTH-OFFSETX, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, DEFAULT_BG_COLOR); + // ili9341_fill(OFFSETX, 0,LCD_WIDTH-OFFSETX, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, LCD_BG_COLOR); // else - // ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, DEFAULT_BG_COLOR); + // ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, LCD_BG_COLOR); draw_frequencies(); } @@ -1937,7 +1942,8 @@ erase_menu_buttons(void) static void erase_numeric_input(void) { - ili9341_fill(0, LCD_HEIGHT-NUM_INPUT_HEIGHT, LCD_WIDTH, NUM_INPUT_HEIGHT, DEFAULT_BG_COLOR); + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(0, LCD_HEIGHT-NUM_INPUT_HEIGHT, LCD_WIDTH, NUM_INPUT_HEIGHT); } #endif @@ -1948,11 +1954,12 @@ leave_ui_mode() // request_to_draw_cells_behind_menu(); // erase_menu_buttons(); // } + ili9341_set_background(LCD_BG_COLOR); // Erase bottom area (not redraw on area update) if (MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX - area_height > 0) - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, area_height, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX - area_height, DEFAULT_BG_COLOR); + ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, area_height, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX - area_height); if (get_waterfall()) - ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom, 0); + ili9341_fill(OFFSETX, graph_bottom, LCD_WIDTH - OFFSETX, CHART_BOTTOM - graph_bottom); redraw_request|=REDRAW_AREA | REDRAW_FREQUENCY | REDRAW_CAL_STATUS | REDRAW_BATTERY; } diff --git a/ui_sa.c b/ui_sa.c index 26f32a8..a316390 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -465,7 +465,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_mode_acb) if (b){ if (item == setting.mode) { b->param_1.text = "Return"; - b->bg = RGB565(200,200,200);//config.menu_active_color; + b->bg = LCD_MENU_ACTIVE_COLOR; b->border = BUTTON_BORDER_FALLING | MENU_BUTTON_BORDER; } else