perf(lcd): cache idle eye frames and anchor blink timing

This commit is contained in:
chenjintao
2026-10-09 17:03:10 +08:00
parent b5c8aeb4fe
commit 89e8e3abc2
4 changed files with 382 additions and 19 deletions
+43 -3
View File
@@ -9,6 +9,7 @@ def extract(name):
if src[b]=='}': depth-=1
b+=1
return src[a:b]
cache_table=re.search(r'static const uint8_t s_emote_cache_closures.*?\n};',src,re.S).group(0)
prefix='''#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -16,6 +17,12 @@ prefix='''#include <stdint.h>
#include <string.h>
#include <assert.h>
#define LCD_DIRECT_WIDTH 320
#define LCD_DIRECT_EMOTE_CACHE_COUNT 9
#define LCD_DIRECT_EMOTE_CLOSED_THRESHOLD 232
#define LCD_DIRECT_EMOTE_CACHE_X 39
#define LCD_DIRECT_EMOTE_CACHE_Y 63
#define LCD_DIRECT_EMOTE_CACHE_WIDTH 242
#define LCD_DIRECT_EMOTE_CACHE_HEIGHT 97
#define LCD_DIRECT_EMOTE_DMA_ROWS 16
#define LCD_DIRECT_TRANSFER_TIMEOUT_MS 100
#define portENTER_CRITICAL(x) ((void)0)
@@ -29,7 +36,12 @@ prefix='''#include <stdint.h>
typedef int esp_err_t;
typedef int gfx_disp_t;
static bool s_emote_active, s_emote_transfer_fault;
static uint32_t s_emote_completed_regions;
static uint64_t s_emote_copy_us, s_emote_spi_us;
static int64_t fake_time;
static int64_t esp_timer_get_time(void) {return ++fake_time;}
static int s_emote_flush_error, s_panel, s_transfer_done_sem;
static uint16_t *s_emote_capture_pixels;
static uint16_t dma[5120];
static uint16_t *s_emote_dma_pixels=dma;
static uint16_t capture[320*240];
@@ -44,12 +56,36 @@ static int esp_lcd_panel_draw_bitmap(int panel,int x1,int y1,int x2,int y2,const
}
'''
test='''int main(void) {
for(unsigned i=0;i<9;++i) assert(lcd_direct_emote_cache_index(s_emote_cache_closures[i])==(int)i);
assert(lcd_direct_emote_cache_index(255)==8);
assert(lcd_direct_emote_cache_index(1)==-1);
assert(lcd_direct_emote_fps_x100(12,570000)==2105);
assert(lcd_direct_emote_fps_x100(9,570000)==1578);
assert(lcd_direct_emote_fps_x100(12,0)==0);
assert(lcd_direct_emote_fps_x100(0,570000)==0);
uint16_t source[320*240];
for(int i=0;i<320*240;++i) source[i]=(uint16_t)i;
uint16_t cache[242*97+2]; cache[0]=cache[242*97+1]=0xabcd;
s_emote_capture_pixels=cache+1; calls=ready=0;
lcd_direct_emote_flush(NULL,0,0,320,240,source);
assert(calls==0 && ready==1);
for(int y=0;y<97;++y) for(int x=0;x<242;++x)
assert(cache[1+y*242+x]==source[(y+63)*320+x+39]);
assert(cache[0]==0xabcd && cache[242*97+1]==0xabcd);
memset(cache+1,0,242*97*2);
for(int y=0;y<240;y+=8)
lcd_direct_emote_capture(cache+1,0,y,320,y+8,source+y*320);
for(int y=0;y<97;++y) for(int x=0;x<242;++x)
assert(cache[1+y*242+x]==source[(y+63)*320+x+39]);
s_emote_capture_pixels=NULL;
for(width=1;width<=320;++width) {
calls=ready=fail_call=timeout_call=0;origin_y=65;s_emote_active=true;
s_emote_transfer_fault=false;s_emote_flush_error=0;
const uint32_t before=s_emote_completed_regions;
lcd_direct_emote_flush(NULL,0,65,width,158,source);
assert(s_emote_completed_regions==before+CONFIG_TQ_LCD_EMOTE_FPS_LOG);
assert((s_emote_copy_us>0)==CONFIG_TQ_LCD_EMOTE_FPS_LOG);
assert((s_emote_spi_us>0)==CONFIG_TQ_LCD_EMOTE_FPS_LOG);
assert(ready==1 && s_emote_flush_error==0);
assert(memcmp(source,capture,width*93*2)==0);
assert(calls==(93+5120/width-1)/(5120/width));
@@ -75,6 +111,10 @@ test='''int main(void) {
}'''
with tempfile.TemporaryDirectory(prefix='emote-transport-') as tmp:
c=Path(tmp)/'test.c';exe=Path(tmp)/'test'
c.write_text(prefix+extract('lcd_direct_emote_flush')+'\n'+extract('lcd_direct_emote_draw_closed_eyes')+'\n'+test)
subprocess.run(['clang','-std=c11','-fsanitize=address,undefined',str(c),'-o',str(exe)],check=True)
subprocess.run([str(exe)],check=True)
for enabled in (0,1):
c.write_text('#define CONFIG_TQ_LCD_EMOTE_FPS_LOG '+str(enabled)+'\n'+prefix+cache_table+'\n'+extract('lcd_direct_emote_cache_index')+'\n'+
extract('lcd_direct_emote_capture')+'\n'+extract('lcd_direct_emote_flush')+'\n'+extract('lcd_direct_emote_draw_closed_eyes')+'\n'+
extract('lcd_direct_emote_fps_x100')+'\n'+test)
subprocess.run(['clang','-std=c11','-fsanitize=address,undefined',str(c),'-o',str(exe)],check=True)
subprocess.run([str(exe)],check=True)
print('PASS: cache mapping/capture without LCD transfer, FPS logging on/off and measured-rate arithmetic')