samples: drivers: display: distinguish mono pixel format

In exceptional cases, monochrome displays can deviate from the
general interpretation (PIXEL_FORMAT_MONO01) of a logical 1 as
pixel on (white) and 0 as pixel off (black) and instead set the
capability to PIXEL_FORMAT_MONO10. This small but significant
difference has been ignored so far, resulting in an inverse
display for those displays. In order to be technically correct
here, the buffers for a "white" background should be set to 0
instead of 1 and for "black" to 1 instead of 0.

Signed-off-by: Stephan Linz <linz@li-pro.net>
This commit is contained in:
Stephan Linz 2024-01-01 14:01:07 +01:00 committed by Maureen Helm
parent e46265669f
commit 2fdea6b2b9

View file

@ -140,23 +140,36 @@ static void fill_buffer_bgr565(enum corner corner, uint8_t grey, uint8_t *buf,
}
}
static void fill_buffer_mono(enum corner corner, uint8_t grey, uint8_t *buf,
size_t buf_size)
static void fill_buffer_mono(enum corner corner, uint8_t grey,
uint8_t black, uint8_t white,
uint8_t *buf, size_t buf_size)
{
uint16_t color;
switch (corner) {
case BOTTOM_LEFT:
color = (grey & 0x01u) ? 0xFFu : 0x00u;
color = (grey & 0x01u) ? white : black;
break;
default:
color = 0;
color = black;
break;
}
memset(buf, color, buf_size);
}
static inline void fill_buffer_mono01(enum corner corner, uint8_t grey,
uint8_t *buf, size_t buf_size)
{
fill_buffer_mono(corner, grey, 0x00u, 0xFFu, buf, buf_size);
}
static inline void fill_buffer_mono10(enum corner corner, uint8_t grey,
uint8_t *buf, size_t buf_size)
{
fill_buffer_mono(corner, grey, 0xFFu, 0x00u, buf, buf_size);
}
int main(void)
{
size_t x;
@ -166,6 +179,7 @@ int main(void)
size_t h_step;
size_t scale;
size_t grey_count;
uint8_t bg_color;
uint8_t *buf;
int32_t grey_scale_sleep;
const struct device *display_dev;
@ -216,24 +230,34 @@ int main(void)
switch (capabilities.current_pixel_format) {
case PIXEL_FORMAT_ARGB_8888:
bg_color = 0xFFu;
fill_buffer_fnc = fill_buffer_argb8888;
buf_size *= 4;
break;
case PIXEL_FORMAT_RGB_888:
bg_color = 0xFFu;
fill_buffer_fnc = fill_buffer_rgb888;
buf_size *= 3;
break;
case PIXEL_FORMAT_RGB_565:
bg_color = 0xFFu;
fill_buffer_fnc = fill_buffer_rgb565;
buf_size *= 2;
break;
case PIXEL_FORMAT_BGR_565:
bg_color = 0xFFu;
fill_buffer_fnc = fill_buffer_bgr565;
buf_size *= 2;
break;
case PIXEL_FORMAT_MONO01:
bg_color = 0xFFu;
fill_buffer_fnc = fill_buffer_mono01;
buf_size = DIV_ROUND_UP(DIV_ROUND_UP(
buf_size, NUM_BITS(uint8_t)), sizeof(uint8_t));
break;
case PIXEL_FORMAT_MONO10:
fill_buffer_fnc = fill_buffer_mono;
bg_color = 0x00u;
fill_buffer_fnc = fill_buffer_mono10;
buf_size = DIV_ROUND_UP(DIV_ROUND_UP(
buf_size, NUM_BITS(uint8_t)), sizeof(uint8_t));
break;
@ -257,7 +281,7 @@ int main(void)
#endif
}
(void)memset(buf, 0xFFu, buf_size);
(void)memset(buf, bg_color, buf_size);
buf_desc.buf_size = buf_size;
buf_desc.pitch = capabilities.x_resolution;