Description
Trying to use a PMOLED in monochrome.
What MCU/Processor/Board and compiler are you using?
STM32F4
What LVGL version are you using?
7.0.1
What do you want to achieve?
Want to initialize LVGL with PMOLED background BLACK, text, symbols, and lines, etc in WHITE.
What have you tried so far?
In lv_conf.h
, I have set the followings:
#define LV_USE_THEME_EMPTY 1
#define LV_USE_THEME_TEMPLATE 1
#define LV_USE_THEME_MATERIAL 1
#define LV_USE_THEME_MONO 1
#define LV_THEME_DEFAULT_COLOR_PRIMARY LV_COLOR_WHITE
#define LV_THEME_DEFAULT_FLAG LV_THEME_MATERIAL_FLAG_LIGHT
The OLED displays a picture and static text properly, but the whole screen changed to a white background somehow. I am using a bitwise frame-buffer similar to that of Sharp MIP:
#define DEV_BUFIDX(x, y) ((x >> 3) + (y*(LV_HOR_RES_MAX >> 3)))
#define PIXIDX(x) (1 << ((x) & 7))
In the callback function to set pixel, I use:
void mydisp_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) {
(void) disp_drv;
(void) buf_w;
(void) opa;
lv_coord_t _x,_y;
//also working on a runtime screen orientation change.
#if defined (LV_SCREEN_ROTATE_270)
_x = y;
_y = (LV_HOR_RES_MAX-1)-x;
#elif defined (LV_SCREEN_ROTATE_180)
_x = (LV_HOR_RES_MAX-1)-x;
_y = (LV_VER_RES_MAX-1)-y;
#elif defined (LV_SCREEN_ROTATE_90)
_x = (LV_VER_RES_MAX-1)-y;
_y = x;
#else
_x = x;
_y = y;
#endif
if (lv_color_to1(color) == 1) {
buf[DEV_BUFIDX(_x, _y)] |= PIXIDX(_x); //Set VDB pixel bit to 1 for other colors than BLACK
} else {
buf[DEV_BUFIDX(_x, _y)] &= ~PIXIDX(_x); //Set VDB pixel bit to 0 for BLACK color
}
}
I did an online debug and I was able to trace the actual function that sets the background white. It is located in lv_draw_rect.c::draw_bg(coords, clip, dsc)
at line 97. After stepping through this function, the screen turns white, setting the whole frame buffer 0xff.
I am wondering if a style is required for MONOCHROME? I have not applied any style yet. The lv_hal_init()
is short with snippet below:
void lv_hal_init(void)
{
mydisp_init(); //a proven function to initialize the display will bg=BLACK, fg=WHITE, writing a bit 0=BLACK, 1=WHITE
static lv_disp_buf_t lv_disp_buf;
static lv_color_t lv_buf_array[LV_HOR_RES_MAX*LV_VER_RES_MAX];
lv_disp_buf_init(&lv_disp_buf, lv_buf_array, NULL, LV_HOR_RES_MAX*LV_VER_RES_MAX);
lv_disp_drv_t disp_drv;
//disp_drv.rotated = 1;
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &lv_disp_buf;
disp_drv.flush_cb = mydisp_flush_cb;
disp_drv.set_px_cb = mydisp_set_px_cb;
lv_disp_drv_register(&disp_drv);
}
Screenshot and/or video
The expected result is a black background with white text. But it is now inverted.