I'm trying to modify esp32-nesemu project to use it with 18-bit color of ILI9486. While loop sends bmp line in every iteration,
while(1) {
xQueueReceive(vidQueue, &bmp, portMAX_DELAY);
ili9341_write_frame(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, (const uint8_t **)bmp->line);
}
but this code is ok for rgb565 (16-bit color), if I compile it for ILI9486 I will get grayscale bmps.
I found another code of TFT-eSPI library, where 16-bit color code is converted to 18-bit:
// Split out the colours
uint32_t r = (color & 0xF800)>>8;
uint32_t g = (color & 0x07E0)<<5;
uint32_t b = (color & 0x001F)<<19;
// Concatenate 4 pixels into three 32 bit blocks
uint32_t r0 = r<<24 | b | g | r;
uint32_t r1 = r0>>8 | g<<16;
uint32_t r2 = r1>>8 | b<<8;
Using SPI registers I'm able to write 16 x 4 bytes in time.
esp32-nesemu offers to write one horizontal line in time putting all pixels in array
while (x<width) {
for (i=0; i<16; i++) {
if(data == NULL){
temp[i] = 0;
x += 2;
continue;
}
x1 = myPalette[(unsigned char)(data[y][x])]; x++;
y1 = myPalette[(unsigned char)(data[y][x])]; x++;
temp[i] = U16x2toU32(x1,y1);
}
while (READ_PERI_REG(SPI_CMD_REG(SPI_NUM))&SPI_USR);
for (i=0; i<16; i++) {
WRITE_PERI_REG((SPI_W0_REG(SPI_NUM) + (i << 2)), temp[i]);
}
SET_PERI_REG_MASK(SPI_CMD_REG(SPI_NUM), SPI_USR);
}
if I convert temp[i] to 18-bit color before writing I'll get true colors, but my pixels will be mixed. How do I modify this code to write pixels to display using SPI registers?