Way to Rotate lvgl example?

Hi,

I have been working on a project involving an LCD screen using the LVGL sample as a base. However, it would be nice if I could rotate either the text itself or the screen by 90 degrees. I tried the lv_disp_set _rotation command found in lv_hal_disp.c but rather than rotating the screen it just broke the display. The same thing happens if I flip the width and height in the overlay. 1) is this error some how caused by the lv_disp library and 2) is there a fix for this? I am using the SH1107 OLED which is compatible with the ssd1306 drivers and I am using an unedited version of the lvgl example. Any help would be appreciated.

Thanks!

Parents
  • For anyone else who finds this: If you are using specifically the SSD1306 driver the way you get around this is you set up an LVGL canvas, write on the canvas, and then rotate that. I will post on example of writing simple text and then rotating it. It is somewhat version depenent though so check you Zephyr and LVGL version and find out what the current syntax is.

    char count_str[11] = {0};
        const struct device *display_dev;

        display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
        if (!device_is_ready(display_dev)) {
            LOG_ERR("Device not ready, aborting test");
            return 0;
        }

        static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
        lv_obj_t *canvas = lv_canvas_create(lv_scr_act());
        lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
        lv_canvas_set_palette(canvas, 1, lv_color_hex(0xffffff));
        lv_canvas_set_palette(canvas, 0, lv_color_hex(0x000000));
        lv_obj_align(canvas, LV_ALIGN_DEFAULT, 0, 0);
       

        lv_color_t black; black.full = 1;
        lv_color_t white; white.full = 0;

        lv_canvas_fill_bg(canvas, black, LV_OPA_COVER);

        lv_draw_label_dsc_t label_dsc;
        lv_draw_label_dsc_init(&label_dsc);
        label_dsc.color = white;

        lv_draw_label_dsc_t label_dsc2;
        lv_draw_label_dsc_init(&label_dsc2);
        label_dsc2.color = label_dsc.color;

        lv_draw_label_dsc_t label_HR;
        lv_draw_label_dsc_init(&label_HR);
        label_HR.color = label_dsc.color;

        lv_draw_label_dsc_t label_BAS;
        lv_draw_label_dsc_init(&label_BAS);
        label_BAS.color = label_dsc.color;

        lv_draw_label_dsc_t label_PHN;
        lv_draw_label_dsc_init(&label_PHN);
        label_PHN.color = label_dsc.color;

        lv_draw_label_dsc_t label_PHN_val;
        lv_draw_label_dsc_init(&label_PHN_val);
        label_PHN_val.color = label_dsc.color;

        lv_draw_label_dsc_t label_Conn;
        lv_draw_label_dsc_init(&label_Conn);
        label_Conn.color = label_dsc.color;

        lv_draw_label_dsc_t label_Conn_val;
        lv_draw_label_dsc_init(&label_Conn_val);
        label_Conn_val.color = label_dsc.color;
       
        char bas_data_str[5];
        char hr_data_str[5];
        char phn_data_str[5];

        lv_task_handler();
        display_blanking_off(display_dev);
        while (1) {
            //printf("here\n");
            sprintf(bas_data_str, "%d", incoming_bas);
            sprintf(hr_data_str, "%d", incoming_hr);
            sprintf(phn_data_str, "%d", sent_data);
            lv_canvas_fill_bg(canvas, black, LV_OPA_COVER);
            lv_canvas_draw_text(canvas, 0, 28,100, &label_PHN, "Data Sent:");
            lv_canvas_draw_text(canvas, 100, 28,100, &label_PHN_val, phn_data_str);
            lv_canvas_draw_text(canvas, 0, 28+14,100, &label_Conn, "Connected:");
            lv_canvas_draw_text(canvas, 70, 28+14,100, &label_Conn_val, name_list[1]);
            lv_canvas_draw_text(canvas, 0, 14,100, &label_HR, "BAS Value:");
            lv_canvas_draw_text(canvas, 0, 0, 100, &label_dsc, "HR Value:");
            lv_canvas_draw_text(canvas, 100, 14, 30, &label_dsc2, bas_data_str);
            lv_canvas_draw_text(canvas, 100, 0, 30, &label_dsc, hr_data_str);
       
            static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
            memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
            lv_img_dsc_t img;
            img.data = (void *)cbuf_tmp;
            img.header.cf = LV_IMG_CF_TRUE_COLOR;
            img.header.w = CANVAS_WIDTH;
            img.header.h = CANVAS_HEIGHT;

            lv_canvas_transform(canvas, &img, 900, LV_IMG_ZOOM_NONE, -1, 0, 64 / 2, 64 / 2, true);
            lv_task_handler();
            //printk("here");
            //k_yield();
        }
Reply
  • For anyone else who finds this: If you are using specifically the SSD1306 driver the way you get around this is you set up an LVGL canvas, write on the canvas, and then rotate that. I will post on example of writing simple text and then rotating it. It is somewhat version depenent though so check you Zephyr and LVGL version and find out what the current syntax is.

    char count_str[11] = {0};
        const struct device *display_dev;

        display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
        if (!device_is_ready(display_dev)) {
            LOG_ERR("Device not ready, aborting test");
            return 0;
        }

        static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
        lv_obj_t *canvas = lv_canvas_create(lv_scr_act());
        lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
        lv_canvas_set_palette(canvas, 1, lv_color_hex(0xffffff));
        lv_canvas_set_palette(canvas, 0, lv_color_hex(0x000000));
        lv_obj_align(canvas, LV_ALIGN_DEFAULT, 0, 0);
       

        lv_color_t black; black.full = 1;
        lv_color_t white; white.full = 0;

        lv_canvas_fill_bg(canvas, black, LV_OPA_COVER);

        lv_draw_label_dsc_t label_dsc;
        lv_draw_label_dsc_init(&label_dsc);
        label_dsc.color = white;

        lv_draw_label_dsc_t label_dsc2;
        lv_draw_label_dsc_init(&label_dsc2);
        label_dsc2.color = label_dsc.color;

        lv_draw_label_dsc_t label_HR;
        lv_draw_label_dsc_init(&label_HR);
        label_HR.color = label_dsc.color;

        lv_draw_label_dsc_t label_BAS;
        lv_draw_label_dsc_init(&label_BAS);
        label_BAS.color = label_dsc.color;

        lv_draw_label_dsc_t label_PHN;
        lv_draw_label_dsc_init(&label_PHN);
        label_PHN.color = label_dsc.color;

        lv_draw_label_dsc_t label_PHN_val;
        lv_draw_label_dsc_init(&label_PHN_val);
        label_PHN_val.color = label_dsc.color;

        lv_draw_label_dsc_t label_Conn;
        lv_draw_label_dsc_init(&label_Conn);
        label_Conn.color = label_dsc.color;

        lv_draw_label_dsc_t label_Conn_val;
        lv_draw_label_dsc_init(&label_Conn_val);
        label_Conn_val.color = label_dsc.color;
       
        char bas_data_str[5];
        char hr_data_str[5];
        char phn_data_str[5];

        lv_task_handler();
        display_blanking_off(display_dev);
        while (1) {
            //printf("here\n");
            sprintf(bas_data_str, "%d", incoming_bas);
            sprintf(hr_data_str, "%d", incoming_hr);
            sprintf(phn_data_str, "%d", sent_data);
            lv_canvas_fill_bg(canvas, black, LV_OPA_COVER);
            lv_canvas_draw_text(canvas, 0, 28,100, &label_PHN, "Data Sent:");
            lv_canvas_draw_text(canvas, 100, 28,100, &label_PHN_val, phn_data_str);
            lv_canvas_draw_text(canvas, 0, 28+14,100, &label_Conn, "Connected:");
            lv_canvas_draw_text(canvas, 70, 28+14,100, &label_Conn_val, name_list[1]);
            lv_canvas_draw_text(canvas, 0, 14,100, &label_HR, "BAS Value:");
            lv_canvas_draw_text(canvas, 0, 0, 100, &label_dsc, "HR Value:");
            lv_canvas_draw_text(canvas, 100, 14, 30, &label_dsc2, bas_data_str);
            lv_canvas_draw_text(canvas, 100, 0, 30, &label_dsc, hr_data_str);
       
            static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
            memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
            lv_img_dsc_t img;
            img.data = (void *)cbuf_tmp;
            img.header.cf = LV_IMG_CF_TRUE_COLOR;
            img.header.w = CANVAS_WIDTH;
            img.header.h = CANVAS_HEIGHT;

            lv_canvas_transform(canvas, &img, 900, LV_IMG_ZOOM_NONE, -1, 0, 64 / 2, 64 / 2, true);
            lv_task_handler();
            //printk("here");
            //k_yield();
        }
Children
No Data
Related