From a269c45b0a9c0c69062fae1124e2deeb5d727875 Mon Sep 17 00:00:00 2001 From: Patrick Sunday <33767+cafedomingo@users.noreply.github.com> Date: Mon, 23 Feb 2026 15:20:45 -0800 Subject: [PATCH 1/2] Optimize character rendering and fix off-by-one bugs Buffer character pixels in memory and use burst I2C transfer instead of pushing one pixel at a time. Use a stack buffer (832 bytes max) instead of malloc/free per character. Remove redundant SYNC_REG call from lcd_write_string. Fix off-by-one clipping in lcd_fill_rectangle and wrong dimension calculation in lcd_draw_image. Adapted from UCTRONICS/SKU_RM0004#27 with endianness fix (the original PR stores native uint16_t values but i2c_burst_transfer expects big-endian byte order) and stack buffer simplification. Co-authored-by: slyglif <10196904+slyglif@users.noreply.github.com> --- hardware/st7735/st7735.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/hardware/st7735/st7735.c b/hardware/st7735/st7735.c index 1007086..342ff9c 100644 --- a/hardware/st7735/st7735.c +++ b/hardware/st7735/st7735.c @@ -40,25 +40,22 @@ void lcd_set_address_window(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) */ void lcd_write_char(uint16_t x, uint16_t y, char ch, FontDef font, uint16_t color, uint16_t bgcolor) { - uint32_t i, b, j; - - lcd_set_address_window(x, y, x + font.width - 1, y + font.height - 1); + uint8_t buff[16 * 26 * 2]; /* max font size: 16x26 */ + uint32_t i, b, j, idx; for (i = 0; i < font.height; i++) { b = font.data[(ch - 32) * font.height + i]; for (j = 0; j < font.width; j++) { - if ((b << j) & 0x8000) - { - i2c_write_data(color >> 8, color & 0xFF); - } - else - { - i2c_write_data(bgcolor >> 8, bgcolor & 0xFF); - } + idx = (i * font.width + j) * 2; + uint16_t c = ((b << j) & 0x8000) ? color : bgcolor; + buff[idx] = c >> 8; + buff[idx + 1] = c & 0xFF; } } + + lcd_draw_image(x, y, font.width, font.height, buff); } void lcd_write_ch(uint16_t x, uint16_t y, char ch, FontType font, uint16_t color, uint16_t bgcolor) @@ -106,7 +103,6 @@ void lcd_write_string(uint16_t x, uint16_t y, char *str, FontDef font, uint16_t } lcd_write_char(x, y, *str, font, color, bgcolor); - i2c_write_command(SYNC_REG, 0x00, 0x01); x += font.width; str++; } @@ -141,9 +137,9 @@ void lcd_fill_rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t // clipping if ((x >= ST7735_WIDTH) || (y >= ST7735_HEIGHT)) return; - if ((x + w - 1) >= ST7735_WIDTH) + if ((x + w) >= ST7735_WIDTH) w = ST7735_WIDTH - x; - if ((y + h - 1) >= ST7735_HEIGHT) + if ((y + h) >= ST7735_HEIGHT) h = ST7735_HEIGHT - y; lcd_set_address_window(x, y, x + w - 1, y + h - 1); @@ -170,10 +166,8 @@ void lcd_fill_screen(uint16_t color) void lcd_draw_image(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t *data) { - uint16_t col = h - y; - uint16_t row = w - x; lcd_set_address_window(x, y, x + w - 1, y + h - 1); - i2c_burst_transfer(data, sizeof(uint16_t) * col * row); + i2c_burst_transfer(data, sizeof(uint16_t) * w * h); } uint8_t lcd_begin(void) From 8e624469216b99f51bc3529831472950e5e5f03d Mon Sep 17 00:00:00 2001 From: Patrick Sunday <33767+cafedomingo@users.noreply.github.com> Date: Mon, 23 Feb 2026 15:20:49 -0800 Subject: [PATCH 2/2] Use MemAvailable instead of MemFree for RAM reporting MemAvailable includes reclaimable cache and buffers, giving a more accurate picture of actually available memory. Adapted from UCTRONICS/SKU_RM0004#17 Co-authored-by: mobejm <4407468+mobejm@users.noreply.github.com> --- hardware/rpiInfo/rpiInfo.c | 6 +++--- hardware/rpiInfo/rpiInfo.h | 2 +- hardware/st7735/st7735.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hardware/rpiInfo/rpiInfo.c b/hardware/rpiInfo/rpiInfo.c index d85a117..e7d0662 100644 --- a/hardware/rpiInfo/rpiInfo.c +++ b/hardware/rpiInfo/rpiInfo.c @@ -114,7 +114,7 @@ char* get_ip_address_new(void) /* * get ram memory */ -void get_cpu_memory(float *Totalram,float *freeram) +void get_cpu_memory(float *Totalram,float *availram) { struct sysinfo s_info; @@ -138,9 +138,9 @@ void get_cpu_memory(float *Totalram,float *freeram) { *Totalram=value/1000.0/1000.0; } - else if(strcmp(famer,"MemFree:")==0) + else if(strcmp(famer,"MemAvailable:")==0) { - *freeram=value/1000.0/1000.0; + *availram=value/1000.0/1000.0; } } fclose(fp); diff --git a/hardware/rpiInfo/rpiInfo.h b/hardware/rpiInfo/rpiInfo.h index 365e745..8e64a07 100644 --- a/hardware/rpiInfo/rpiInfo.h +++ b/hardware/rpiInfo/rpiInfo.h @@ -25,7 +25,7 @@ char* get_ip_address(void); char* get_ip_address_new(void); void get_sd_memory(uint32_t *MemSize, uint32_t *freesize); -void get_cpu_memory(float *Totalram, float *freeram); +void get_cpu_memory(float *Totalram, float *availram); uint8_t get_temperature(void); uint8_t get_cpu_message(void); uint8_t get_hard_disk_memory(uint16_t *diskMemSize, uint16_t *useMemSize); diff --git a/hardware/st7735/st7735.c b/hardware/st7735/st7735.c index 342ff9c..9b7033a 100644 --- a/hardware/st7735/st7735.c +++ b/hardware/st7735/st7735.c @@ -299,13 +299,13 @@ void lcd_display_cpuLoad(void) void lcd_display_ram(void) { float Totalram = 0.0; - float freeram = 0.0; + float availram = 0.0; uint8_t residue = 0; uint8_t Total[10] = {0}; uint8_t free[10] = {0}; uint8_t residueStr[10] = {0}; - get_cpu_memory(&Totalram, &freeram); - residue = (Totalram - freeram) / Totalram * 100; + get_cpu_memory(&Totalram, &availram); + residue = (Totalram - availram) / Totalram * 100; sprintf(residueStr, "%d", residue); lcd_fill_rectangle(0, 35, ST7735_WIDTH, 20, ST7735_BLACK); lcd_write_string(36, 35, "RAM:", Font_11x18, ST7735_WHITE, ST7735_BLACK); @@ -401,7 +401,7 @@ void lcd_display_all(void) static int header_drawn = 0; char buf[24]; uint8_t cpuLoad; - float totalRam = 0.0, freeRam = 0.0; + float totalRam = 0.0, availRam = 0.0; uint8_t ramPercent; uint16_t temp; uint32_t sdMemSize = 0, sdUseMemSize = 0; @@ -412,8 +412,8 @@ void lcd_display_all(void) /* Gather all data */ cpuLoad = get_cpu_message(); - get_cpu_memory(&totalRam, &freeRam); - ramPercent = (totalRam > 0) ? (uint8_t)((totalRam - freeRam) / totalRam * 100) : 0; + get_cpu_memory(&totalRam, &availRam); + ramPercent = (totalRam > 0) ? (uint8_t)((totalRam - availRam) / totalRam * 100) : 0; temp = get_temperature(); get_sd_memory(&sdMemSize, &sdUseMemSize); get_hard_disk_memory(&diskMemSize, &diskUseMemSize);