Custom grayscale pixel format

Description

I have my display working just fine using mono, and now I’m trying to utilize the grayscale aspect of my display driver. To make it easiest, I’m representing one pixel as one byte. It isn’t working, and I was hoping someone could double-check my pixel callback and flush callback functions below.

What MCU/Processor/Board and compiler are you using?

GCC compiler. STM32G4 on custom HW

What LVGL version are you using?

7.6.1 with Zephyr 2.7

What do you want to achieve?

Grayscale using LVGL and Zephyr

Code to reproduce

Below are my callback functions. Is this accurate? I don’t understand what the lvgl_set_px_cb_8bit is supposed to achieve. Can someone enlighten me?

void lvgl_flush_cb_8bit(struct _disp_drv_t *disp_drv,
		const lv_area_t *area, lv_color_t *color_p)
{
	const struct device *display_dev = (const struct device *)disp_drv->user_data;
	uint16_t w = area->x2 - area->x1 + 1;
	uint16_t h = area->y2 - area->y1 + 1;
	struct display_buffer_descriptor desc;

	desc.buf_size = w * h;
	desc.width = w;
	desc.pitch = w;
	desc.height = h;
	display_write(display_dev, area->x1, area->y1, &desc, (void *) color_p);

	lv_disp_flush_ready(disp_drv);
}

void lvgl_set_px_cb_8bit(struct _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)
{
	uint8_t *buf_xy;
	buf_xy = buf + x + y * buf_w;
	*buf_xy = lv_color_brightness(color);
}

Thanks,
Rob

@TridentTD I saw you had some good responses to other posts. I’m pretty sure my set_px_cb function is wrong, but I can’t figure out how. Is *buf a buffer containing info from every pixel? And using the buf_w and x and y variables, do I change the data contents of that one pixel? I don’t understand what buf_w is. Is it the width of just the draw area that is changing? Does each entry in *buf correspond to one pixel (as a uint8_t?

Thanks.