Skip to content

Commit 8edee5a

Browse files
committed
lcd speed optimization
27.24 ms to write a frame! also skip every other frame for much smoother playback (30FPS)
1 parent eb5c540 commit 8edee5a

File tree

3 files changed

+78
-15
lines changed

3 files changed

+78
-15
lines changed

components/nofrendo-esp32/spi_lcd.c

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,22 @@ static void spi_master_init()
283283
}
284284
}
285285

286+
#define U16x2toU32(m,l) ((((uint32_t)(l>>8|(l&0xFF)<<8))<<16)|(m>>8|(m&0xFF)<<8))
287+
286288
void ili9341_send_data(int x, int y, int width, int height, const uint16_t *data) {
287-
#define U16x2toU32(a,b) ((((uint32_t)(b>>8|(b&0xFF)<<8))<<16)|(a>>8|(a&0xFF)<<8))
288289
int i, l;
289290
uint16_t x1, y1;
290291
uint32_t xv, yv, dc, bv;
291-
x1 = x+(width-1);
292-
xv = U16x2toU32(x,x1);
293-
y1 = y+(height-1);
294-
yv = U16x2toU32(y,y1);
295292
l = height*width;
296-
dc = (1 << PIN_NUM_DC);
293+
x1 = x+(width-1);//287
294+
y1 = y+(height-1);//y
295+
xv = U16x2toU32(x,x1);//32,287
296+
yv = U16x2toU32(y,y1);//y,y
297297

298298
// x = 32, y = 8 - 231, width = 256, height = 1
299-
//ets_printf("%u.%u %ux%u\n", x, y, width, height);
300-
299+
//ets_printf("%08X\n", xv);
300+
301+
dc = (1 << PIN_NUM_DC);
301302
GPIO.out_w1tc = dc;
302303
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 7, SPI_USR_MOSI_DBITLEN_S);
303304
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), 0x2A);
@@ -340,6 +341,69 @@ void ili9341_send_data(int x, int y, int width, int height, const uint16_t *data
340341
}
341342
}
342343

344+
extern uint16_t myPalette[];
345+
346+
void ili9341_write_frame(const uint16_t xs, const uint16_t ys, const uint16_t width, const uint16_t height, const uint8_t * data[]){
347+
int x, y;
348+
int i;
349+
uint16_t x1, y1;
350+
uint32_t xv, yv, dc, bv;
351+
uint32_t temp[16];
352+
dc = (1 << PIN_NUM_DC);
353+
354+
for (y=0; y<height; y++) {
355+
//start line
356+
x1 = xs+(width-1);
357+
y1 = ys+y+(height-1);
358+
xv = U16x2toU32(xs,x1);
359+
yv = U16x2toU32((ys+y),y1);
360+
361+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
362+
GPIO.out_w1tc = dc;
363+
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 7, SPI_USR_MOSI_DBITLEN_S);
364+
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), 0x2A);
365+
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
366+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
367+
GPIO.out_w1ts = dc;
368+
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 31, SPI_USR_MOSI_DBITLEN_S);
369+
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), xv);
370+
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
371+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
372+
GPIO.out_w1tc = dc;
373+
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 7, SPI_USR_MOSI_DBITLEN_S);
374+
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), 0x2B);
375+
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
376+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
377+
GPIO.out_w1ts = dc;
378+
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 31, SPI_USR_MOSI_DBITLEN_S);
379+
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), yv);
380+
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
381+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
382+
GPIO.out_w1tc = dc;
383+
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 7, SPI_USR_MOSI_DBITLEN_S);
384+
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM)), 0x2C);
385+
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
386+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
387+
388+
x = 0;
389+
GPIO.out_w1ts = dc;
390+
SET_PERI_REG_BITS(SPI_MOSI_DLEN_REG(SPI_NUM), SPI_USR_MOSI_DBITLEN, 511, SPI_USR_MOSI_DBITLEN_S);
391+
while (x<width) {
392+
for (i=0; i<16; i++) {
393+
x1 = myPalette[(unsigned char)(data[y][x])]; x++;
394+
y1 = myPalette[(unsigned char)(data[y][x])]; x++;
395+
temp[i] = U16x2toU32(x1,y1);
396+
}
397+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
398+
for (i=0; i<16; i++) {
399+
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM) + (i << 2)), temp[i]);
400+
}
401+
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
402+
}
403+
}
404+
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
405+
}
406+
343407
void ili9341_init()
344408
{
345409
spi_master_init();

components/nofrendo-esp32/spi_lcd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C"
2626
{
2727
#endif
2828

29+
void ili9341_write_frame(const uint16_t x, const uint16_t y, const uint16_t width, const uint16_t height, const uint8_t *data[]);
2930
void ili9341_send_data(int x, int y, int width, int height, const uint16_t *data);
3031
void ili9341_init();
3132

components/nofrendo-esp32/video_audio.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,12 @@ static void custom_blit(bitmap_t *bmp, int num_dirties, rect_t *dirty_rects) {
220220
static void videoTask(void *arg) {
221221
int x, y;
222222
bitmap_t *bmp=NULL;
223-
while(1) {
223+
x = (320-DEFAULT_WIDTH)/2;
224+
y = ((240-DEFAULT_HEIGHT)/2);
225+
while(1) {
226+
xQueueReceive(vidQueue, &bmp, portMAX_DELAY);//skip one frame to drop to 30
224227
xQueueReceive(vidQueue, &bmp, portMAX_DELAY);
225-
for (y=0; y<DEFAULT_HEIGHT; y++) {
226-
for (x=0; x<DEFAULT_WIDTH; x++) {
227-
line[x]=myPalette[(unsigned char)bmp->line[y][x]];
228-
}
229-
ili9341_send_data((320-DEFAULT_WIDTH)/2, y+((240-DEFAULT_HEIGHT)/2), DEFAULT_WIDTH, 1, line);
230-
}
228+
ili9341_write_frame(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, (const uint8_t **)bmp->line);
231229
}
232230
}
233231

0 commit comments

Comments
 (0)