lvgl / lvgl_esp32_drivers

Drivers for ESP32 to be used with LVGL
MIT License
339 stars 285 forks source link

ILI9488 driver modification #239

Open JoachimF opened 1 month ago

JoachimF commented 1 month ago

Hello,

Here is my code modification to use "Swap the 2 bytes of RGB565 color" or not, it is working for me :

` uint32_t j = 0;

/* uint16_t blue : 5; uint16_t green : 6; uint16_t red : 5;

    BBBB BGGG GGGR RRRR

*/

if LV_COLOR_16_SWAP != 1

uint32_t LD = 0;
for (uint32_t i = 0; i < size; i++) {
    LD = buffer_16bit[i].full;
    mybuf[j] = (uint8_t) (((LD & 0xF800) >> 8) | ((LD & 0x8000) >> 13)); // B
    j++;
    mybuf[j] = (uint8_t) ((LD & 0x07E0) >> 3); // G
    j++;
    mybuf[j] = (uint8_t) (((LD & 0x001F) << 3) | ((LD & 0x0010) >> 2));  //R 0001 0000 ->  0000 0100
    j++;
}

endif

/ B = 0000 0000 BBBB B100 G = 0000 0000 GGGG GG00 R = 0000 0000 RRRR R100 /

/* uint16_t green_h : 3; 0000 0000 0000 0111 uint16_t red : 5; 0000 0000 0001 1111 uint16_t blue : 5; 0000 0000 0001 1111 uint16_t green_l : 3; 0000 0000 0000 0111

    GGGR RRRR BBBB BGGG
    0000 0000 000G GG00
    */

if LV_COLOR_16_SWAP == 1

for (uint32_t i = 0; i < size; i++) {
    mybuf[j] = (uint8_t)((buffer_16bit[i].ch.red << 3) | ((buffer_16bit[i].ch.red & 0x0010) >> 2));
    j++;
    mybuf[j] = (uint8_t)((buffer_16bit[i].ch.green_h << 5) | ((buffer_16bit[i].ch.green_l) << 2));
    j++;
    mybuf[j] = (uint8_t)((buffer_16bit[i].ch.blue << 3) | ((buffer_16bit[i].ch.blue & 0x0010) >> 2));;
    j++;
}

endif

/* Column addresses  */

`

I leave my comment for those wants to understand how bits are shifted.

I didn't understand while des MSB bits of red and blue are copied to LSB, if someone can explain to me.

Regards,