From 3b61c73a114813bbede7c486198542ac9eff4d64 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 14 Jun 2020 13:37:53 +0200 Subject: [PATCH] Replace LCD size constants --- ili9341.c | 16 +++++++------- main.c | 8 +++---- nanovna.h | 3 +++ plot.c | 16 +++++++------- ui.c | 62 +++++++++++++++++++++++++++---------------------------- ui_sa.c | 2 +- 6 files changed, 55 insertions(+), 52 deletions(-) diff --git a/ili9341.c b/ili9341.c index bba3dd9..5496c3c 100644 --- a/ili9341.c +++ b/ili9341.c @@ -27,8 +27,8 @@ uint16_t foreground_color = 0; uint16_t background_color = 0; // Display width and height definition -#define ILI9341_WIDTH 320 -#define ILI9341_HEIGHT 240 +#define ILI9341_WIDTH LCD_WIDTH +#define ILI9341_HEIGHT LCD_HEIGHT // Display commands list #define ILI9341_NOP 0x00 @@ -726,15 +726,15 @@ void ili9341_test(int mode) switch (mode) { default: #if 1 - ili9341_fill(0, 0, 320, 240, 0); - for (y = 0; y < 240; y++) { - ili9341_fill(0, y, 320, 1, RGB(240-y, y, (y + 120) % 256)); + ili9341_fill(0, 0, LCD_WIDTH, LCD_HEIGHT, 0); + for (y = 0; y < LCD_HEIGHT; y++) { + ili9341_fill(0, y, LCD_WIDTH, 1, RGB(LCD_HEIGHT-y, y, (y + 120) % 256)); } break; case 1: - ili9341_fill(0, 0, 320, 240, 0); - for (y = 0; y < 240; y++) { - for (x = 0; x < 320; x++) { + ili9341_fill(0, 0, LCD_WIDTH, LCD_HEIGHT, 0); + for (y = 0; y < LCD_HEIGHT; y++) { + for (x = 0; x < LCD_WIDTH; x++) { ili9341_pixel(x, y, (y<<8)|x); } } diff --git a/main.c b/main.c index 9427a12..4bd8be1 100644 --- a/main.c +++ b/main.c @@ -771,15 +771,15 @@ VNA_SHELL_FUNCTION(cmd_capture) (void)argc; (void)argv; int i, y; -#if SPI_BUFFER_SIZE < (3*320 + 1) +#if SPI_BUFFER_SIZE < (3*LCD_WIDTH + 1) #error "Low size of spi_buffer for cmd_capture" #endif // read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size) - for (y = 0; y < 240; y += 2) { + for (y = 0; y < LCD_HEIGHT; y += 2) { // use uint16_t spi_buffer[2048] (defined in ili9341) for read buffer uint8_t *buf = (uint8_t *)spi_buffer; - ili9341_read_memory(0, y, 320, 2, 2 * 320, spi_buffer); - for (i = 0; i < 4 * 320; i++) { + ili9341_read_memory(0, y, LCD_WIDTH, 2, 2 * LCD_WIDTH, spi_buffer); + for (i = 0; i < 4 * LCD_WIDTH; i++) { streamPut(shell_stream, *buf++); } } diff --git a/nanovna.h b/nanovna.h index 813e4e4..eb496af 100644 --- a/nanovna.h +++ b/nanovna.h @@ -482,6 +482,9 @@ extern volatile uint8_t redraw_request; // Define size of screen buffer in pixels (one pixel 16bit size) #define SPI_BUFFER_SIZE 1024 +#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) diff --git a/plot.c b/plot.c index 64fac6e..1a04554 100644 --- a/plot.c +++ b/plot.c @@ -52,8 +52,8 @@ pixel_t *cell_buffer = (pixel_t *)spi_buffer; #endif // indicate dirty cells (not redraw if cell data not changed) -#define MAX_MARKMAP_X ((320+CELLWIDTH-1)/CELLWIDTH) -#define MAX_MARKMAP_Y ((240+CELLHEIGHT-1)/CELLHEIGHT) +#define MAX_MARKMAP_X ((LCD_WIDTH+CELLWIDTH-1)/CELLWIDTH) +#define MAX_MARKMAP_Y ((LCD_HEIGHT+CELLHEIGHT-1)/CELLHEIGHT) // Define markmap mask size #if MAX_MARKMAP_X <= 8 typedef uint8_t map_t; @@ -1725,9 +1725,9 @@ request_to_draw_cells_behind_menu(void) { // Values Hardcoded from ui.c if (current_menu_is_form()) - invalidate_rect(25, 0, 319, 239); + invalidate_rect(25, 0, LCD_WIDTH-1, LCD_HEIGHT-1); else - invalidate_rect(320-60 - 25, 0, 319, 239); + invalidate_rect(LCD_WIDTH-60 - 25, 0, LCD_WIDTH-1, LCD_HEIGHT-1); redraw_request |= REDRAW_CELLS; } @@ -1735,7 +1735,7 @@ void request_to_draw_cells_behind_numeric_input(void) { // Values Hardcoded from ui.c - invalidate_rect(0, 240-32, 319, 239); + invalidate_rect(0, LCD_HEIGHT-32, LCD_WIDTH-1, LCD_HEIGHT-1); redraw_request |= REDRAW_CELLS; } @@ -2153,14 +2153,14 @@ draw_frequencies(void) #endif ili9341_set_foreground(DEFAULT_FG_COLOR); ili9341_set_background(DEFAULT_BG_COLOR); - ili9341_fill(0, FREQUENCIES_YPOS, 320, FONT_GET_HEIGHT, DEFAULT_BG_COLOR); + ili9341_fill(0, FREQUENCIES_YPOS, LCD_WIDTH, FONT_GET_HEIGHT, DEFAULT_BG_COLOR); if (uistat.lever_mode == LM_CENTER) buf1[0] = S_SARROW[0]; if (uistat.lever_mode == LM_SPAN) buf2[0] = S_SARROW[0]; int p2 = FREQUENCIES_XPOS2; if (FREQ_IS_CW()) { - p2 = 320 - 7*strlen(buf2); + p2 = LCD_WIDTH - 7*strlen(buf2); } ili9341_drawstring(buf1, FREQUENCIES_XPOS1, FREQUENCIES_YPOS); ili9341_drawstring(buf2, p2, FREQUENCIES_YPOS); @@ -2256,7 +2256,7 @@ toggle_waterfall(void) { if (!waterfall) { _height = HEIGHT_SCROLL; - ili9341_fill(5*5, HEIGHT, 320 - 5*5, 236-HEIGHT, 0); + ili9341_fill(5*5, HEIGHT, LCD_WIDTH - 5*5, 236-HEIGHT, 0); waterfall = true; fullscreen = false; w_min = (int)min_level; diff --git a/ui.c b/ui.c index 3002ba8..818f63d 100644 --- a/ui.c +++ b/ui.c @@ -329,8 +329,8 @@ touch_cal_exec(void) y1 = last_touch_y; ili9341_clear_screen(); - ili9341_line(320-1, 240-1, 320-1, 240-32); - ili9341_line(320-1, 240-1, 320-32, 240-1); + ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-1, LCD_HEIGHT-32); + ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-32, LCD_HEIGHT-1); ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220); touch_wait_release(); @@ -339,8 +339,8 @@ touch_cal_exec(void) config.touch_cal[0] = x1; config.touch_cal[1] = y1; - config.touch_cal[2] = (x2 - x1) * 16 / 320; - config.touch_cal[3] = (y2 - y1) * 16 / 240; + config.touch_cal[2] = (x2 - x1) * 16 / LCD_WIDTH; + config.touch_cal[3] = (y2 - y1) * 16 / LCD_HEIGHT; //redraw_all(); touch_start_watchdog(); @@ -1107,9 +1107,9 @@ const menuitem_t menu_top[] = { #define MENU_BUTTON_WIDTH 60 -#define MENU_BUTTON_START (320-MENU_BUTTON_WIDTH) +#define MENU_BUTTON_START (LCD_WIDTH-MENU_BUTTON_WIDTH) #define MENU_FORM_WIDTH 295 -#define MENU_FORM_START (320 - MENU_FORM_WIDTH) +#define MENU_FORM_START (LCD_WIDTH - MENU_FORM_WIDTH) #define MENU_BUTTON_HEIGHT 30 #define NUM_INPUT_HEIGHT 30 @@ -1252,7 +1252,7 @@ menu_invoke(int item) #define KP_WIDTH 48 #define KP_HEIGHT 48 // Key x, y position (0 - 15) on screen -#define KP_GET_X(posx) ((posx)*KP_WIDTH + (320-64-KP_WIDTH*4)) +#define KP_GET_X(posx) ((posx)*KP_WIDTH + (LCD_WIDTH-64-KP_WIDTH*4)) #define KP_GET_Y(posy) ((posy)*KP_HEIGHT + 12 ) #ifdef __VNA__ // Key names @@ -1401,14 +1401,14 @@ draw_numeric_area_frame(void) { const char *l1; const char *l2; - ili9341_fill(0, 240-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, config.menu_normal_color); + 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); if (menu_is_multiline(keypad_mode_label[keypad_mode], &l1, &l2)) { - ili9341_drawstring_7x13(l1, 10, 240-NUM_INPUT_HEIGHT+1); - ili9341_drawstring_7x13(l2, 10, 240-NUM_INPUT_HEIGHT/2 + 1); + ili9341_drawstring_7x13(l1, 10, LCD_HEIGHT-NUM_INPUT_HEIGHT+1); + ili9341_drawstring_7x13(l2, 10, LCD_HEIGHT-NUM_INPUT_HEIGHT/2 + 1); } else - ili9341_drawstring_7x13(keypad_mode_label[keypad_mode], 10, 240-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2); + ili9341_drawstring_7x13(keypad_mode_label[keypad_mode], 10, LCD_HEIGHT-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2); //ili9341_drawfont(KP_KEYPAD, 300, 216); } @@ -1440,26 +1440,26 @@ draw_numeric_input(const char *buf) ili9341_set_foreground(fg); ili9341_set_background(bg); if (c >= 0) // c is number - ili9341_drawfont(c, x, 240-NUM_INPUT_HEIGHT+4); + ili9341_drawfont(c, x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4); else if (focused) // c not number, but focused - ili9341_drawfont(0, x, 240-NUM_INPUT_HEIGHT+4); + ili9341_drawfont(0, x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4); else // erase - ili9341_fill(x, 240-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, bg); x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2; } // erase last -// ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, NUM_FONT_GET_WIDTH+2+8, NUM_FONT_GET_WIDTH+2+8, config.menu_normal_color); - ili9341_fill(x, 240-NUM_INPUT_HEIGHT+4, 320-64, NUM_FONT_GET_WIDTH+2+8, config.menu_normal_color); +// 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-64, NUM_FONT_GET_WIDTH+2+8, config.menu_normal_color); if (buf[0] == 0 && kp_help_text != NULL) { ili9341_set_foreground(fg); ili9341_set_background(bg); const char *l1,*l2; if (menu_is_multiline(kp_help_text, &l1, &l2)) { - ili9341_drawstring_7x13(l1, 64+NUM_FONT_GET_WIDTH+2, 240-NUM_INPUT_HEIGHT+1); - ili9341_drawstring_7x13(l2, 64+NUM_FONT_GET_WIDTH+2, 240-NUM_INPUT_HEIGHT/2 + 1); + ili9341_drawstring_7x13(l1, 64+NUM_FONT_GET_WIDTH+2, LCD_HEIGHT-NUM_INPUT_HEIGHT+1); + ili9341_drawstring_7x13(l2, 64+NUM_FONT_GET_WIDTH+2, LCD_HEIGHT-NUM_INPUT_HEIGHT/2 + 1); } else - ili9341_drawstring_7x13(kp_help_text, 64+NUM_FONT_GET_WIDTH+2, 240-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2); + ili9341_drawstring_7x13(kp_help_text, 64+NUM_FONT_GET_WIDTH+2, LCD_HEIGHT-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2); } } @@ -1588,7 +1588,7 @@ draw_menu_buttons(const menuitem_t *menu) int active_button_start; menu_item_modify_attribute(menu, i, &fg, &bg); // before plot_printf to create status text if (menu[i].type & MT_FORM) { - active_button_start = 320 - MENU_FORM_WIDTH; + active_button_start = LCD_WIDTH - MENU_FORM_WIDTH; active_button_width = MENU_FORM_WIDTH - 30; // Shorten at the right if (MT_MASK(menu[i].type) == MT_KEYPAD) { // Only keypad retrieves value keypad_mode = menu[i].data; @@ -1598,12 +1598,12 @@ draw_menu_buttons(const menuitem_t *menu) } else { active_button_width = MENU_BUTTON_WIDTH; - active_button_start = 320 - MENU_BUTTON_WIDTH; + active_button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; } ili9341_fill(active_button_start, y, active_button_width, MENU_BUTTON_HEIGHT-4, old_bg); // Set button to unmodified background color #if 0 // 3D button accent - int bw = 320; + int bw = LCD_WIDTH; if (MT_MASK(menu[i].type) != MT_TITLE) { ili9341_fill(bw-active_button_width, y, 2, MENU_BUTTON_HEIGHT-4, LIGHT_GREY); // Set button to unmodified background color @@ -1620,7 +1620,7 @@ draw_menu_buttons(const menuitem_t *menu) ili9341_drawstring_size(text, active_button_start+6, y+6, 2); #ifdef __ICONS__ if (menu[i].type & MT_ICON) { - blit16BitWidthBitmap(240,y+6,16,16,&left_icons[((menu[i].data >>4)&0xf)*16]); + blit16BitWidthBitmap(LCD_HEIGHT,y+6,16,16,&left_icons[((menu[i].data >>4)&0xf)*16]); blit16BitWidthBitmap(256,y+6,16,16,&right_icons[((menu[i].data >>0)&0xf)*16]); } #endif @@ -1685,7 +1685,7 @@ menu_apply_touch(void) else active_button_width = MENU_BUTTON_WIDTH; - if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && 320-active_button_width < touch_x) { + if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && LCD_WIDTH-active_button_width < touch_x) { menu_select_touch(i); return; } @@ -1706,18 +1706,18 @@ draw_menu(void) static void erase_menu_buttons(void) { -// ili9341_fill(area_width, 0, 320 - area_width, area_height, DEFAULT_BG_COLOR); +// ili9341_fill(area_width, 0, LCD_WIDTH - area_width, area_height, DEFAULT_BG_COLOR); if (current_menu_is_form()) - ili9341_fill(5*5, 0,320-5*5, MENU_BUTTON_HEIGHT*8, DEFAULT_BG_COLOR); + ili9341_fill(5*5, 0,LCD_WIDTH-5*5, MENU_BUTTON_HEIGHT*8, DEFAULT_BG_COLOR); else - ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*8, DEFAULT_BG_COLOR); + ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*8, DEFAULT_BG_COLOR); draw_frequencies(); } static void erase_numeric_input(void) { - ili9341_fill(0, 240-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, DEFAULT_BG_COLOR); + ili9341_fill(0, LCD_HEIGHT-NUM_INPUT_HEIGHT, LCD_WIDTH, NUM_INPUT_HEIGHT, DEFAULT_BG_COLOR); } static void @@ -1850,7 +1850,7 @@ ui_mode_numeric(int _keypad_mode) keypad_mode = _keypad_mode; ui_mode = UI_NUMERIC; area_width = AREA_WIDTH_NORMAL; - area_height = 240-NUM_INPUT_HEIGHT;//AREA_HEIGHT_NORMAL - 32; + area_height = LCD_HEIGHT-NUM_INPUT_HEIGHT;//AREA_HEIGHT_NORMAL - 32; draw_numeric_area_frame(); fetch_numeric_target(); @@ -2204,7 +2204,7 @@ numeric_apply_touch(void) return; } - if (touch_y > 240-40) { + if (touch_y > LCD_HEIGHT-40) { int n = 9 - (touch_x - 64) / 20; uistat.digit = n; uistat.digit_mode = TRUE; @@ -2448,7 +2448,7 @@ touch_marker_select(void) int selected_marker = 0; int touch_x, touch_y; touch_position(&touch_x, &touch_y); - if (current_menu_is_form() || touch_x > 320-MENU_BUTTON_WIDTH || touch_x < 25 || touch_y > 30) + if (current_menu_is_form() || touch_x > LCD_WIDTH-MENU_BUTTON_WIDTH || touch_x < 25 || touch_y > 30) return FALSE; if (touch_y > 15) selected_marker = 2; diff --git a/ui_sa.c b/ui_sa.c index c4b4b9a..967138a 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -285,7 +285,7 @@ enum { -#define KP_X(x) (48*(x) + 2 + (320-BUTTON_WIDTH-192)) +#define KP_X(x) (48*(x) + 2 + (LCD_WIDTH-BUTTON_WIDTH-192)) #define KP_Y(y) (48*(y) + 2)