/* SPI Master example This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" #include "driver/gpio.h" #include "lvgl/lvgl.h" #include "lv_examples/lv_apps/demo/demo.h" #include "esp_freertos_hooks.h" #include "drv/disp_spi.h" #include "drv/ili9341.h" #include "drv/tp_spi.h" #include "drv/xpt2046.h" #include "lodepng.h" // #include "png_decoder.h" static void IRAM_ATTR lv_tick_task(void) { lv_tick_inc(portTICK_RATE_MS); } void app_main() { lv_init(); disp_spi_init(); ili9341_init(); static lv_color_t buf1[DISP_BUF_SIZE]; static lv_color_t buf2[DISP_BUF_SIZE]; static lv_disp_buf_t disp_buf; lv_disp_buf_init(&disp_buf, buf1, buf2, DISP_BUF_SIZE); lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); disp_drv.flush_cb = ili9341_flush; disp_drv.buffer = &disp_buf; lv_disp_drv_register(&disp_drv); esp_register_freertos_tick_hook(lv_tick_task); // LV_IMG_DECLARE(sun); /*Declare the C array*/ LV_IMG_DECLARE(sun_tca); /*Declare the C array*/ LV_IMG_DECLARE(png_decoder_test); /*Declare the C array*/ /*Decode the PNG image*/ unsigned char * png_decoded = NULL; /*Will be pointer to the decoded image*/ uint32_t png_width; /*Will be the width of the decoded image*/ uint32_t png_height; /*Will be the width of the decoded image*/ /*Decode the loaded image in ARGB8888 */ // uint32_t error = lodepng_decode32(&png_decoded, &png_width, &png_height, sun.data, sun.data_size); uint32_t error = lodepng_decode32(&png_decoded, &png_width, &png_height, png_decoder_test.data, png_decoder_test.data_size); if (error) { printf("error %u: %s\n", error, lodepng_error_text(error)); while (1); } printf("error: %d\n", error); printf("%p\n", png_decoded); printf("png_width:%d\n", png_width); printf("png_height:%d\n", png_height); // printf("png_decoder_test.data_size:%d\n", png_decoder_test.data_size); /*Initialize an image descriptor for LittlevGL with the decoded image*/ static lv_img_dsc_t png_dsc; png_dsc.header.always_zero = 0; /*It must be zero*/ png_dsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA; /*Set the color format*/ png_dsc.header.w = png_width; png_dsc.header.h = png_height; png_dsc.data_size = png_width * png_height * 4; png_dsc.data = png_decoded; printf("png_dsc.data_size %d, png_dsc.data %p\n", png_dsc.data_size, png_dsc.data); /*Create an image object and set the decoded PNG image as it's source*/ lv_obj_t * img_obj = lv_img_create(lv_scr_act(), NULL); /*Create the an image object in LittlevGL*/ lv_img_set_src(img_obj, &png_dsc); /*Set the image source to the decoded PNG*/ lv_obj_set_drag(img_obj, true); /*Make to image dragable*/ /*Set a non-white background color for the scren to see the alpha is working on the image*/ lv_style_scr.body.main_color = LV_COLOR_MAKE(0x40, 0x70, 0xAA); lv_obj_t * img_var = lv_img_create(lv_scr_act(), NULL); /*Crate an image object*/ lv_img_set_src(img_var, &sun_tca); /*Set the created file as image (a red flower)*/ lv_obj_set_pos(img_var, 200, 100); /*Set the positions*/ lv_obj_set_drag(img_var, true); while (1) { vTaskDelay(1); lv_task_handler(); } }