diff --git a/ili9341.c b/ili9341.c index e134025..6372f1c 100644 --- a/ili9341.c +++ b/ili9341.c @@ -21,7 +21,7 @@ #include "hal.h" #include "nanovna.h" -uint16_t spi_buffer[2048]; +uint16_t spi_buffer[SPI_BUFFER_SIZE]; // Default foreground & background colors uint16_t foreground_color=DEFAULT_FG_COLOR; uint16_t background_color=DEFAULT_BG_COLOR; diff --git a/nanovna.h b/nanovna.h index b516545..97522ec 100644 --- a/nanovna.h +++ b/nanovna.h @@ -300,6 +300,9 @@ extern int16_t vbat; #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 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_BG_COLOR RGB565( 0, 0, 0) #define DEFAULT_GRID_COLOR RGB565(128,128,128) @@ -317,7 +320,7 @@ extern int16_t vbat; extern uint16_t foreground_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_setRotation(uint8_t r); diff --git a/plot.c b/plot.c index b514311..0e67fbd 100644 --- a/plot.c +++ b/plot.c @@ -16,6 +16,10 @@ int16_t area_height = AREA_HEIGHT_NORMAL; // Depends from spi_buffer size, CELLWIDTH*CELLHEIGHT <= sizeof(spi_buffer) #define CELLWIDTH (64) #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) #define MAX_MARKMAP_X ((320+CELLWIDTH-1)/CELLWIDTH)