From 054e43e6e9bdfbf0f15193c494844fa11e8f6cd9 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 24 Feb 2019 21:20:51 +0100 Subject: [PATCH] indev/disp cb: pass driver as first argument --- lv_core/lv_refr.c | 8 ++++---- lv_draw/lv_draw_basic.c | 12 ++++++------ lv_hal/lv_hal_disp.c | 7 ++++--- lv_hal/lv_hal_disp.h | 16 +++++++++------- lv_hal/lv_hal_indev.c | 2 +- lv_hal/lv_hal_indev.h | 13 +++++++------ 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/lv_core/lv_refr.c b/lv_core/lv_refr.c index d17d83917..7ac2c6c14 100644 --- a/lv_core/lv_refr.c +++ b/lv_core/lv_refr.c @@ -101,7 +101,7 @@ void lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p) /*The area is truncated to the screen*/ if(suc != false) { - if(disp->driver.rounder_cb) disp->driver.rounder_cb(disp_refr, &com_area); + if(disp->driver.rounder_cb) disp->driver.rounder_cb(&disp_refr->driver, &com_area); /*Save only if this area is not in one of the saved areas*/ uint16_t i; @@ -192,7 +192,7 @@ static void lv_refr_task(void * param) /*Call monitor cb if present*/ if(disp_refr->driver.monitor_cb) { - disp_refr->driver.monitor_cb(disp_refr, lv_tick_elaps(start), px_num); + disp_refr->driver.monitor_cb(&disp_refr->driver, lv_tick_elaps(start), px_num); } } } @@ -297,7 +297,7 @@ static void lv_refr_area(const lv_area_t * area_p) lv_coord_t y_tmp = max_row; do { tmp.y2 = y_tmp; - disp_refr->driver.rounder_cb(disp_refr, &tmp); + disp_refr->driver.rounder_cb(&disp_refr->driver, &tmp); y_tmp --; /*Decrement the number of line until it is rounded to a smaller (or equal) value then the original. */ } while(lv_area_get_height(&tmp) > max_row && y_tmp != 0); @@ -539,7 +539,7 @@ static void lv_refr_vdb_flush(void) /*Flush the rendered content to the display*/ lv_disp_t * disp = lv_refr_get_disp_refreshing(); - if(disp->driver.flush_cb) disp->driver.flush_cb(disp, &vdb->area, vdb->buf_act); + if(disp->driver.flush_cb) disp->driver.flush_cb(&disp->driver, &vdb->area, vdb->buf_act); if(vdb->buf1 && vdb->buf2) { diff --git a/lv_draw/lv_draw_basic.c b/lv_draw/lv_draw_basic.c index f675e54b5..31b8ba481 100644 --- a/lv_draw/lv_draw_basic.c +++ b/lv_draw/lv_draw_basic.c @@ -87,7 +87,7 @@ void lv_draw_px(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t y -= vdb->area.y1; if(disp->driver.set_px_cb) { - disp->driver.set_px_cb(disp, (uint8_t *)vdb->buf_act, vdb_width, x, y, color, opa); + disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, x, y, color, opa); } else { lv_color_t * vdb_px_p = vdb->buf_act; vdb_px_p += y * vdb_width + x; @@ -336,7 +336,7 @@ void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * mask_p, } if(disp->driver.set_px_cb) { - disp->driver.set_px_cb(disp, (uint8_t *)vdb->buf_act, vdb_width, + disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, (col + pos_x) - vdb->area.x1, (row + pos_y) - vdb->area.y1, color, px_opa); } else { @@ -434,7 +434,7 @@ void lv_draw_map(const lv_area_t * cords_p, const lv_area_t * mask_p, for(row = masked_a.y1; row <= masked_a.y2; row++) { for(col = 0; col < map_useful_w; col++) { lv_color_t px_color = *((lv_color_t *)&map_p[(uint32_t)col * px_size_byte]); - disp->driver.set_px_cb(disp, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1, row, px_color, opa); + disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1, row, px_color, opa); } map_p += map_width * px_size_byte; /*Next row on the map*/ } @@ -497,7 +497,7 @@ void lv_draw_map(const lv_area_t * cords_p, const lv_area_t * mask_p, } /*Handle custom VDB write is present*/ if(disp->driver.set_px_cb) { - disp->driver.set_px_cb(disp, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1, row, recolored_px, opa_result); + disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1, row, recolored_px, opa_result); } /*Normal native VDB write*/ else { @@ -507,7 +507,7 @@ void lv_draw_map(const lv_area_t * cords_p, const lv_area_t * mask_p, } else { /*Handle custom VDB write is present*/ if(disp->driver.set_px_cb) { - disp->driver.set_px_cb(disp, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1, row, px_color, opa_result); + disp->driver.set_px_cb(&disp->driver, (uint8_t *)vdb->buf_act, vdb_width, col + masked_a.x1, row, px_color, opa_result); } /*Normal native VDB write*/ else { @@ -571,7 +571,7 @@ static void sw_color_fill(lv_area_t * mem_area, lv_color_t * mem, const lv_area_ if(disp->driver.set_px_cb) { for(col = fill_area->x1; col <= fill_area->x2; col++) { for(row = fill_area->y1; row <= fill_area->y2; row++) { - disp->driver.set_px_cb(disp, (uint8_t *)mem, mem_width, col, row, color, opa); + disp->driver.set_px_cb(&disp->driver, (uint8_t *)mem, mem_width, col, row, color, opa); } } } else { diff --git a/lv_hal/lv_hal_disp.c b/lv_hal/lv_hal_disp.c index 82e597fb3..339f2853e 100644 --- a/lv_hal/lv_hal_disp.c +++ b/lv_hal/lv_hal_disp.c @@ -180,11 +180,12 @@ lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp) } /** - * Call in the display driver's `flush` function when the flushing is finished + * Call in the display driver's `flush_cb` function when the flushing is finished + * @param disp_drv pointer to display driver in `flush_cb` where this function is called */ -LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_t * disp) +LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv) { - disp->driver.buffer->flushing = 0; + disp_drv->buffer->flushing = 0; /*If the screen is transparent initialize it when the flushing is ready*/ #if LV_COLOR_SCREEN_TRANSP diff --git a/lv_hal/lv_hal_disp.h b/lv_hal/lv_hal_disp.h index 0f83d82a2..0fed2c454 100644 --- a/lv_hal/lv_hal_disp.h +++ b/lv_hal/lv_hal_disp.h @@ -38,6 +38,7 @@ extern "C" { **********************/ struct _disp_t; +struct _disp_drv_t; typedef struct @@ -67,22 +68,22 @@ typedef struct _disp_drv_t { lv_disp_buf_t * buffer; /* MANDATORY: Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished */ - void (*flush_cb)(struct _disp_t * disp, const lv_area_t * area, lv_color_t * color_p); + void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); lv_disp_user_data_t flush_user_data; /* OPTIONAL: Extend the invalidated areas to match with the display drivers requirements * E.g. round `y` to, 8, 16 ..) on a monochrome display*/ - void (*rounder_cb)(struct _disp_t * disp, lv_area_t * area); + void (*rounder_cb)(struct _disp_drv_t * disp_drv, lv_area_t * area); lv_disp_user_data_t rounder_user_data; /* OPTIONAL: Set a pixel in a buffer according to the special requirements of the display * Can be used for color format not supported in LittelvGL. E.g. 2 bit -> 4 gray scales * Note: Much slower then drawing with supported color formats. */ - void (*set_px_cb)(struct _disp_t * disp, 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 (*set_px_cb)(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); lv_disp_user_data_t set_px_user_data; - /* Called after every refresh cycle to tell the rendering and flushing time + the number of flushed pixels */ - void (*monitor_cb)(struct _disp_t * disp, uint32_t time, uint32_t px); + /* OPTIONAL: Called after every refresh cycle to tell the rendering and flushing time + the number of flushed pixels */ + void (*monitor_cb)(struct _disp_drv_t * disp_drv, uint32_t time, uint32_t px); lv_disp_user_data_t monitor_user_data; #if USE_LV_GPU @@ -178,9 +179,10 @@ lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp); lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp); /** - * Call in the display driver's `flush` function when the flushing is finished + * Call in the display driver's `flush_cb` function when the flushing is finished + * @param disp_drv pointer to display driver in `flush_cb` where this function is called */ -LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_t * disp); +LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv); /** diff --git a/lv_hal/lv_hal_indev.c b/lv_hal/lv_hal_indev.c index 2604bc08c..7ee8530e3 100644 --- a/lv_hal/lv_hal_indev.c +++ b/lv_hal/lv_hal_indev.c @@ -113,7 +113,7 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) if(indev->driver.read_cb) { LV_LOG_TRACE("idnev read started"); - cont = indev->driver.read_cb(indev, data); + cont = indev->driver.read_cb(&indev->driver, data); LV_LOG_TRACE("idnev read finished"); } else { LV_LOG_WARN("indev function registered"); diff --git a/lv_hal/lv_hal_indev.h b/lv_hal/lv_hal_indev.h index a9208d997..ed488ba96 100644 --- a/lv_hal/lv_hal_indev.h +++ b/lv_hal/lv_hal_indev.h @@ -33,8 +33,10 @@ extern "C" { * TYPEDEFS **********************/ +struct _lv_obj_t; struct _disp_t; struct _lv_indev_t; +struct _lv_indev_drv_t; /*Possible input device types*/ enum { @@ -67,14 +69,13 @@ typedef struct { } lv_indev_data_t; /*Initialized by the user and registered by 'lv_indev_add()'*/ -typedef struct { - lv_hal_indev_type_t type; /*Input device type*/ - bool (*read_cb)(struct _lv_indev_t * indev, lv_indev_data_t *data); /*Function pointer to read_cb data. Return 'true' if there is still data to be read_cb (buffered)*/ - lv_indev_user_data_t read_user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/ - struct _disp_t * disp; +typedef struct _lv_indev_drv_t { + lv_hal_indev_type_t type; /*Input device type*/ + bool (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t *data); /*Function pointer to read_cb data. Return 'true' if there is still data to be read_cb (buffered)*/ + lv_indev_user_data_t read_user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/ + struct _disp_t * disp; /*Pointer to the assigned display*/ } lv_indev_drv_t; -struct _lv_obj_t; /*Run time data of input devices*/ typedef struct _lv_indev_proc_t {