Ls018b7dh02 Sharp Memory Displayed Inverted

Hello

I have integrated sharp memory driver as per LCD configuration that I have used. I am printing “HELLO WORLD” on LCD, but it is displaying as inverted.

Code

The code block(s) should be between ```c and ``` tags:

/*You code here*/

MEMLCD_HandleTypeDef hmemlcd = {
.hspi = &hspi2,
.htim = &htim2,
.tim_ch = TIM_CHANNEL_3,
.CS_Port = LCD_CS_GPIO_Port,
.CS_Pin = LCD_CS_Pin,
.DISP_Port = LCD_DISP_GPIO_Port,
.DISP_Pin = LCD_DISP_Pin,
.EXTCOM_Port = LCD_EXTCOM_GPIO_Port,
.EXTCOM_Pin = LCD_EXTCOM_Pin,
};

void lv_port_disp_init(void)
{
MX_Queue_tx_Config();
HAL_DMAEx_List_LinkQ(&handle_GPDMA1_Channel0, &Queue_tx);
__HAL_LINKDMA(&hspi2, hdmatx, handle_GPDMA1_Channel0);
hmemlcd.model = 12;
MEMLCD_init(&hmemlcd);
MEMLCD_clear_all(&hmemlcd);

static lv_disp_draw_buf_t draw_buf_dsc_2;

lv_disp_draw_buf_init(&draw_buf_dsc_2, hmemlcd.buffer, NULL, (240*303));   /*Initialize the display buffer*/
lv_disp_drv_init(&disp_drv);

disp_drv.hor_res = 240;
disp_drv.ver_res = 303;

// disp_drv.full_refresh = 1;
disp_drv.flush_cb = sharp_mip_flush;
disp_drv.set_px_cb = sharp_mip_set_px;
disp_drv.draw_buf = &draw_buf_dsc_2;
disp_drv.rounder_cb = sharp_mip_rounder;

lv_disp_drv_register(&disp_drv);

}

void sharp_mip_set_px(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;

if (lv_color_to1(color) != 0) {
buf[BUFIDX(x, y)] |= PIXIDX(x); /Set draw_buf pixel bit to 1 for other colors than BLACK/
} else {
buf[BUFIDX(x, y)] &= ~PIXIDX(x); /Set draw_buf pixel bit to 0 for BLACK color/
}
}

void sharp_mip_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) {

/Return if the area is out the screen/
if(area->y2 < 0) return;
if(area->y1 > SHARP_MIP_VER_RES - 1) return;

/Truncate the area to the screen/
uint16_t act_y1 = area->y1 < 0 ? 0 : area->y1;
uint16_t act_y2 = area->y2 > SHARP_MIP_VER_RES - 1 ? SHARP_MIP_VER_RES - 1 : area->y2;

uint8_t * buf = (uint8_t *) color_p; /Get the buffer address/
uint16_t buf_h = (act_y2 - act_y1 + 1); /Number of buffer lines/
uint16_t buf_size = buf_h * (2 + SHARP_MIP_HOR_RES / 8) + 2; /*Buffer size in bytes */

/* Set lines to flush dummy byte & gate address in draw_buf*/
for(uint16_t act_y = 0 ; act_y < buf_h ; act_y++) {
buf[BUFIDX(0, act_y) - 1] = ((act_y1 + act_y + 1)>>1) & 0xff; //SHARP_MIP_REV_BYTE((act_y1 + act_y + 1));
buf[BUFIDX(0, act_y) - 2] = 1 | (((act_y1 + act_y + 1) << 7) & 0xff); //0;
}

/* Set last dummy two bytes in draw_buf */
buf[BUFIDX(0, buf_h) - 1] = 0;
buf[BUFIDX(0, buf_h) - 2] = 0;

/* Set frame header in draw_buf */
buf[0] = SHARP_MIP_HEADER |
SHARP_MIP_UPDATE_RAM_FLAG;
buf[0] = 1 | ((1 << 7) & 0xff);

/* Write the frame on display memory */
HAL_GPIO_WritePin(hmemlcd.CS_Port, hmemlcd.CS_Pin, 1);
HAL_SPI_Transmit(hmemlcd.hspi, buf, buf_size, HAL_MAX_DELAY);
HAL_GPIO_WritePin(hmemlcd.CS_Port, hmemlcd.CS_Pin, 0);

lv_disp_flush_ready(disp_drv);
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.