4 gray scale(2 bits) display color settings

Hi everyone,

I am new at lvgl. I use lvgl 8.3 version with c language. I am a litte bit confused about drive my 4 gray scale display(2 bits for each color). The available colors for my display are 00(black), 01(dark gray), 10(light gray), 11(white).

I have wrote a set_px_cb function to update the buffer according to my display (waveshare 4.2 inch e-ink). But I am confused about color settings. What should be the color depth and how should I map color to 2 bits.

Thank you for your help. I am gladful for your support!

Hi @Zeyzey ,

I am no expert at this but I think you need to do something like this, which expands on the monochrome example in the documentation here:

void set_px_cb(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa)
   buf += buf_w * (y >> 3) + x;
   if(lv_color_brightness(color) < 64) (*buf) = 0b00;
   else if(lv_color_brightness(color) >= 64 && lv_color_brightness(color) < 128 ) (*buf) = 0b01;
   else if(lv_color_brightness(color) >= 128 && lv_color_brightness(color) < 192 ) (*buf) = 0b10;
   else if(lv_color_brightness(color) >= 192 ) (*buf) = 0b11;

This should work with 24-bit/32-bit RGB colours, you can probably experiment with different formats to see which gives the best performance versus image quality. I am unsure how you have implemented your buffer logic so you may need to adjust the code to suite your implementation but hopefully you can see from this what to do.



@pete-pjb thank you :). It was really helpful

1 Like