Embedded lvgl mono LCD driver code - JohnHau/mis GitHub Wiki

void st7565_rounder_cb(struct _disp_drv_t * disp_drv, lv_area_t *area) { area->y1 = (area->y1 & (~0x7)); area->y2 = (area->y2 & (~0x7)) + 7; }

void st7565_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) { /* Write to the buffer as required for the display. * Write only 1-bit for monochrome displays mapped vertically:*/ buf += buf_w * (y >> 3) + x; if (color.full) { (*buf) &= ~(1 << (7-(y % 8))); } else { (*buf) |= (1 << (7-(y % 8))); }

//printf("px_cb buf_w= %d, x=%d, y=%d \n", buf_w, x, y); }

//-------------------------------------------------------------------------------------------------------------------------

void st7586s_rounder_cb(struct _disp_drv_t * disp_drv, lv_area_t *area) { // round x range to multiple of 3 pixels uint8_t remainder1 = area->x1 % 3; area->x1 = area->x1 - remainder1 ;

uint8_t  remainder2 = area->x2 % 3;
area->x2 = area->x2 - remainder2 + 2 ;//+2 instead of +3,difference value between x2 and the round value is 2, such as 0,1,2

}

void st7586s_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) { // Write to the buffer as required for the display. // buf_w is the width of the required display area. It can be changed due to the value rounding. // x and y are the relative address of the required display area. buf_w is the max value of x. // buf is pointing to the required byte address of the pixel

buf += (x / 3) + (y * ((buf_w)/3));

    if (color.full)
    {

    	switch(x%3)
    		{
    			case 0:
    				(*buf) |=0xE0;
    			break;

    			case 1:
    				(*buf) |=0x1C;
    			break;

    			case 2:
    				(*buf) |=0x03;
    			break;
    		}

    }
    else
    {

    	     switch(x%3)
        		{
        			case 0:
        				(*buf) &=~ 0xE0;
        			break;

        			case 1:
        				(*buf) &=~0x1C;
        			break;

        			case 2:
        				(*buf) &=~ 0x03;
        			break;
        		}

    }

}