Просмотр исходного кода

update:剥离软解码实现函数为通用函数

Dozingfiretruck 6 месяцев назад
Родитель
Сommit
e48651700a
3 измененных файлов с 41 добавлено и 38 удалено
  1. 17 17
      components/lcd/luat_lcd.c
  2. 12 9
      components/lcd/luat_lcd.h
  3. 12 12
      components/lcd/luat_lib_lcd_jpg.c

+ 17 - 17
components/lcd/luat_lcd.c

@@ -134,7 +134,7 @@ const char* luat_lcd_name(luat_lcd_conf_t* conf) {
     return conf->opts->name;
 }
 
-LUAT_WEAK int luat_lcd_init_default(luat_lcd_conf_t* conf) {
+int luat_lcd_init_default(luat_lcd_conf_t* conf) {
 	conf->is_init_done = 0;
 
     if (conf->w == 0)
@@ -153,13 +153,13 @@ LUAT_WEAK int luat_lcd_init_default(luat_lcd_conf_t* conf) {
     if (conf->pin_pwr != LUAT_GPIO_NONE) {
         luat_gpio_set(conf->pin_pwr, Luat_GPIO_LOW);
     }
-	if (conf->opts->user_ctrl_init) {
-		int res = conf->opts->user_ctrl_init(conf);
-		if (res > 0) {
-			goto INIT_NOT_DONE;
-		}
-		goto INIT_DONE;
-	}
+    if (conf->opts->user_ctrl_init) {
+        int res = conf->opts->user_ctrl_init(conf);
+        if (res > 0) {
+            goto INIT_NOT_DONE;
+        }
+        goto INIT_DONE;
+    }
     luat_gpio_set(conf->pin_rst, Luat_GPIO_LOW);
     luat_rtos_task_sleep(100);
     luat_gpio_set(conf->pin_rst, Luat_GPIO_HIGH);
@@ -196,15 +196,15 @@ INIT_NOT_DONE:
     return -1;
 }
 
-LUAT_WEAK int luat_lcd_setup_buff_default(luat_lcd_conf_t* conf){
-	if (conf->buff) {
-		LLOGE("lcd buff已经分配过了");
-		return 0;
-	}
+int luat_lcd_setup_buff_default(luat_lcd_conf_t* conf){
+    if (conf->buff) {
+        LLOGE("lcd buff已经分配过了");
+        return 0;
+    }
     conf->buff = luat_heap_opt_malloc(LUAT_HEAP_PSRAM, sizeof(luat_color_t) * conf->w * conf->h);
     if (conf->buff == NULL) {
-      LLOGW("psram 分配 lcd buff失败, 尝试在sram分配");
-      conf->buff = luat_heap_opt_malloc(LUAT_HEAP_SRAM, sizeof(luat_color_t) * conf->w * conf->h);
+        LLOGW("psram 分配 lcd buff失败, 尝试在sram分配");
+        conf->buff = luat_heap_opt_malloc(LUAT_HEAP_SRAM, sizeof(luat_color_t) * conf->w * conf->h);
     }
     if (conf->buff == NULL) {
         LLOGE("分配 lcd buff失败");
@@ -212,8 +212,8 @@ LUAT_WEAK int luat_lcd_setup_buff_default(luat_lcd_conf_t* conf){
     }
     conf->buff_ex = luat_heap_opt_malloc(LUAT_HEAP_PSRAM, sizeof(luat_color_t) * conf->w * conf->h);
     if (conf->buff_ex == NULL) {
-      LLOGW("psram 分配 lcd buff_ex失败, 尝试在sram分配");
-      conf->buff_ex = luat_heap_opt_malloc(LUAT_HEAP_SRAM, sizeof(luat_color_t) * conf->w * conf->h);
+        LLOGW("psram 分配 lcd buff_ex失败, 尝试在sram分配");
+        conf->buff_ex = luat_heap_opt_malloc(LUAT_HEAP_SRAM, sizeof(luat_color_t) * conf->w * conf->h);
     }
     if (conf->buff_ex == NULL) {
         LLOGE("分配 lcd buff_ex失败");

+ 12 - 9
components/lcd/luat_lcd.h

@@ -171,16 +171,25 @@ void luat_lcd_execute_cmds(luat_lcd_conf_t* conf);
 int lcd_write_cmd_data(luat_lcd_conf_t* conf,const uint8_t cmd, const uint8_t *data, uint8_t data_len);
 int lcd_read_cmd_data(luat_lcd_conf_t* conf,const uint8_t cmd, const uint8_t *data, uint8_t data_len, uint8_t dummy_bit);
 
-// xxx_default 一般为通用spi设备使用
+// xxx_default 为luatos内部默认实现,bsp可不使用default实现
 int luat_lcd_init_default(luat_lcd_conf_t* conf);
 int luat_lcd_setup_buff_default(luat_lcd_conf_t* conf);
 int luat_lcd_flush_default(luat_lcd_conf_t* conf);
 int luat_lcd_draw_default(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color);
+int lcd_draw_jpeg_default(luat_lcd_conf_t* conf, const char* path, int16_t x, int16_t y);
+int lcd_jpeg_decode_default(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info);
 
-luat_lcd_conf_t* luat_lcd_get_default(void);
-const char* luat_lcd_name(luat_lcd_conf_t* conf);
+// 以下为luatos内部实现通用接口
+// 以下为 weak函数 可bsp单独适配硬件加速或其他接口适配等功能,默认指向上方xxx_default函数
 int luat_lcd_init(luat_lcd_conf_t* conf);
 int luat_lcd_setup_buff(luat_lcd_conf_t* conf);
+int luat_lcd_flush(luat_lcd_conf_t* conf);
+int luat_lcd_draw(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color);
+int lcd_draw_jpeg(luat_lcd_conf_t* conf, const char* path, int16_t x, int16_t y);
+int lcd_jpeg_decode(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info);
+// 以下为非 weak 函数
+luat_lcd_conf_t* luat_lcd_get_default(void);
+const char* luat_lcd_name(luat_lcd_conf_t* conf);
 int luat_lcd_close(luat_lcd_conf_t* conf);
 int luat_lcd_display_on(luat_lcd_conf_t* conf);
 int luat_lcd_display_off(luat_lcd_conf_t* conf);
@@ -190,8 +199,6 @@ int luat_lcd_inv_off(luat_lcd_conf_t* conf);
 int luat_lcd_inv_on(luat_lcd_conf_t* conf);
 int luat_lcd_set_address(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
 int luat_lcd_set_color(luat_color_t back, luat_color_t fore);
-int luat_lcd_draw(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color);
-int luat_lcd_flush(luat_lcd_conf_t* conf);
 int luat_lcd_draw_no_block(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t x2, int16_t y2, luat_color_t* color, uint8_t last_flush);
 int luat_lcd_clear(luat_lcd_conf_t* conf, luat_color_t color);
 int luat_lcd_draw_fill(luat_lcd_conf_t* conf, int16_t x1,int16_t y1,int16_t x2,int16_t y2,luat_color_t color);
@@ -203,10 +210,6 @@ int luat_lcd_draw_rectangle(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16
 int luat_lcd_draw_circle(luat_lcd_conf_t* conf, int16_t x0, int16_t y0, uint8_t r, luat_color_t color);
 int luat_lcd_set_direction(luat_lcd_conf_t* conf, uint8_t direction);
 
-// weak函数 可bsp单独适配硬件加速实现
-int lcd_draw_jpeg(luat_lcd_conf_t* conf, const char* path, int16_t x, int16_t y);
-int lcd_jpeg_decode(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info);
-
 /*
  * csdk适配用
  */

+ 12 - 12
components/lcd/luat_lib_lcd_jpg.c

@@ -76,7 +76,7 @@ static int lcd_out_func (JDEC* jd, void* bitmap, JRECT* rect){
     return 1;    /* Continue to decompress */
 }
 
-LUAT_WEAK int lcd_draw_jpeg(luat_lcd_conf_t* conf, const char* path, int16_t x, int16_t y){
+int lcd_draw_jpeg_default(luat_lcd_conf_t* conf, const char* path, int16_t x, int16_t y){
     JRESULT res;      /* Result code of TJpgDec API */
     JDEC jdec;        /* Decompression object */
     void *work;       /* Pointer to the decompressor work area */
@@ -87,7 +87,7 @@ LUAT_WEAK int lcd_draw_jpeg(luat_lcd_conf_t* conf, const char* path, int16_t x,
 #endif
     IODEV devid;      /* User defined device identifier */
 
-    FILE* fd = luat_fs_fopen(path, "r");
+    FILE* fd = luat_fs_fopen(path, "rb");
     if (fd == NULL) {
         LLOGW("no such file %s", path);
     return -1;
@@ -138,14 +138,6 @@ static int decode_out_func (JDEC* jd, void* bitmap, JRECT* rect){
     uint16_t* tmp = (uint16_t*)bitmap;
 
     // rgb高低位swap
-    // uint16_t count = (rect->right - rect->left + 1) * (rect->bottom - rect->top + 1);
-    // for (size_t i = 0; i < count; i++){
-    //     if (lcd_dft_conf->endianness_swap)
-    //         buff_info->buff[buff_info->offset] = ((tmp[i] >> 8) & 0xFF)+ ((tmp[i] << 8) & 0xFF00);
-    //     else
-    //         buff_info->buff[buff_info->offset] = tmp[i];
-	// 	buff_info->offset++;
-    // }
 	uint16_t idx = 0;
 	for (size_t y = rect->top; y <= rect->bottom; y++){
 		uint16_t offset = y*buff_info->width + rect->left;
@@ -162,7 +154,7 @@ static int decode_out_func (JDEC* jd, void* bitmap, JRECT* rect){
     // LLOGD("jpeg seg size %d %d %d", rect->right - rect->left + 1, rect->bottom - rect->top + 1, (rect->right - rect->left + 1) * (rect->bottom - rect->top + 1));
     return 1;    /* Continue to decompress */
 }
-LUAT_WEAK int lcd_jpeg_decode(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info){
+int lcd_jpeg_decode_default(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info){
     JRESULT res;      /* Result code of TJpgDec API */
     JDEC jdec;        /* Decompression object */
     void *work = NULL;       /* Pointer to the decompressor work area */
@@ -171,7 +163,7 @@ LUAT_WEAK int lcd_jpeg_decode(luat_lcd_conf_t* conf, const char* path, luat_lcd_
 #else
     size_t sz_work = 3500; /* Size of work area */
 #endif
-    FILE* fd = luat_fs_fopen(path, "r");
+    FILE* fd = luat_fs_fopen(path, "rb");
     if (fd == NULL) {
         LLOGW("no such file %s", path);
 		goto error;
@@ -209,4 +201,12 @@ error:
 	return -1;
 }
 
+LUAT_WEAK int lcd_draw_jpeg(luat_lcd_conf_t* conf, const char* path, int16_t x, int16_t y){
+    return lcd_draw_jpeg_default(conf, path, x, y);
+}
+
+LUAT_WEAK int lcd_jpeg_decode(luat_lcd_conf_t* conf, const char* path, luat_lcd_buff_info_t* buff_info){
+    return lcd_jpeg_decode_default(conf, path, buff_info);
+}
+
 #endif