From 0a24a6e37b415d45b490667edf0632831121aff0 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 23 Jun 2020 17:52:06 +0200 Subject: [PATCH] Prepare for 4 inch display --- ili9341.c | 107 +++++++++++++++++++++++++++--------------------------- nanovna.h | 4 +- ui.c | 4 +- 3 files changed, 57 insertions(+), 58 deletions(-) diff --git a/ili9341.c b/ili9341.c index 22f4878..30af869 100644 --- a/ili9341.c +++ b/ili9341.c @@ -350,6 +350,24 @@ void ili9341_init(void) } } +void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette) +{ + uint32_t xx = __REV16(x | ((x + w - 1) << 16)); + uint32_t yy = __REV16(y | ((y + h - 1) << 16)); + send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx); + send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy); + send_command(ILI9341_MEMORY_WRITE, 0, NULL); + + uint8_t *buf = (uint8_t *)spi_buffer; + int32_t len = w * h; + while (len-- > 0) { + uint16_t color = palette[*buf++]; + while (SPI_TX_IS_NOT_EMPTY) + ; + SPI_WRITE_16BIT(color); + } +} + #ifndef __USE_DISPLAY_DMA__ void ili9341_fill(int x, int y, int w, int h, int color) { @@ -405,24 +423,6 @@ void ili9341_fill(int x, int y, int w, int h, int color) dmaStreamFlush(w * h); } -void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette) -{ - uint32_t xx = __REV16(x | ((x + w - 1) << 16)); - uint32_t yy = __REV16(y | ((y + h - 1) << 16)); - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy); - send_command(ILI9341_MEMORY_WRITE, 0, NULL); - - uint8_t *buf = (uint8_t *)spi_buffer; - int32_t len = w * h; - while (len-- > 0) { - uint16_t color = palette[*buf++]; - while (SPI_TX_IS_NOT_EMPTY) - ; - SPI_WRITE_16BIT(color); - } -} - // Copy spi_buffer to region void ili9341_bulk(int x, int y, int w, int h) { @@ -438,7 +438,41 @@ void ili9341_bulk(int x, int y, int w, int h) STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC); dmaStreamFlush(w * h); } -#if 1 // Read DMA hangs +#if 0 // If read DMA hangs +static uint8_t ssp_sendrecvdata(void) +{ + // Start RX clock (by sending data) + SPI_WRITE_8BIT(0); + while (SPI_RX_IS_EMPTY && SPI_IS_BUSY) + ; + return SPI_READ_DATA; +} + +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); + send_command(ILI9341_MEMORY_READ, 0, NULL); + + // Skip data from rx buffer + while (SPI_RX_IS_NOT_EMPTY) + (void) SPI_READ_DATA; + // require 8bit dummy clock + ssp_sendrecvdata(); + while (len-- > 0) { + // read data is always 18bit + uint8_t r = ssp_sendrecvdata(); + uint8_t g = ssp_sendrecvdata(); + uint8_t b = ssp_sendrecvdata(); + *out++ = RGB565(r, g, b); + } + CS_HIGH; +} +#else // Copy screen data to buffer // Warning!!! buffer size must be greater then 3*len + 1 bytes void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) @@ -496,41 +530,6 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) rgbbuf += 3; } } -#else -static uint8_t ssp_sendrecvdata(void) -{ - // Start RX clock (by sending data) - SPI_WRITE_8BIT(0); - while (SPI_RX_IS_EMPTY && SPI_IS_BUSY) - ; - return SPI_READ_DATA; -} - -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); - send_command(ILI9341_MEMORY_READ, 0, NULL); - - // Skip data from rx buffer - while (SPI_RX_IS_NOT_EMPTY) - (void) SPI_READ_DATA; - // require 8bit dummy clock - ssp_sendrecvdata(); - while (len-- > 0) { - // read data is always 18bit - uint8_t r = ssp_sendrecvdata(); - uint8_t g = ssp_sendrecvdata(); - uint8_t b = ssp_sendrecvdata(); - *out++ = RGB565(r, g, b); - } - CS_HIGH; -} - #endif #endif diff --git a/nanovna.h b/nanovna.h index 71b410a..bbe79c2 100644 --- a/nanovna.h +++ b/nanovna.h @@ -281,7 +281,7 @@ extern int _height; #define HEIGHT 230 // WIDTH better be n*(POINTS_COUNT-1) #endif -#define WIDTH (320 - 1 - OFFSETX) +#define WIDTH (LCD_WIDTH - 1 - OFFSETX) #define CELLWIDTH (32) #define CELLHEIGHT (32) @@ -291,7 +291,7 @@ extern int _height; #define FREQUENCIES_XPOS1 OFFSETX #define FREQUENCIES_XPOS2 200 -#define FREQUENCIES_YPOS (240-7) +#define FREQUENCIES_YPOS (LCD_HEIGHT-7) // GRIDX calculated depends from frequency span //#define GRIDY 29 diff --git a/ui.c b/ui.c index a0c27b9..4bb4915 100644 --- a/ui.c +++ b/ui.c @@ -1271,8 +1271,8 @@ menu_invoke(int item) } } -#define KP_WIDTH 48 -#define KP_HEIGHT 48 +#define KP_WIDTH (LCD_HEIGHT/5) +#define KP_HEIGHT (LCD_HEIGHT/5) // Key x, y position (0 - 15) on screen #define KP_GET_X(posx) ((posx)*KP_WIDTH + (LCD_WIDTH-MENU_BUTTON_WIDTH-5-KP_WIDTH*4)) #define KP_GET_Y(posy) ((posy)*KP_HEIGHT + 12 )