「App:Library:LVGL:docs:Get started」の版間の差分
提供: robot-jp wiki
ナビゲーションに移動検索に移動13行目: | 13行目: | ||
|- | |- | ||
| | | | ||
+ | == Get started in a simulator == | ||
+ | Instead of porting LVGL to embedded hardware straight away, it's highly recommended to get started in a simulator first. | ||
+ | |||
+ | LVGL is ported to many IDEs to be sure you will find your favorite one. Go to the Simulators section to get ready-to-use projects that can be run on your PC. This way you can save the time of porting for now and get some experience with LVGL immediately. | ||
| | | | ||
|- | |- | ||
| | | | ||
+ | == Add LVGL into your project == | ||
+ | If you would rather try LVGL on your own project follow these steps: | ||
+ | |||
+ | * Download or clone the library from GitHub with <code>git clone <nowiki>https://github.com/lvgl/lvgl.git</nowiki></code>. | ||
+ | * Copy the <code>lvgl</code> folder into your project. | ||
+ | * Copy <code>lvgl/lv_conf_template.h</code> as <code>lv_conf.h</code> next to the <code>lvgl</code> folder, change the first <code>#if 0</code> to <code>1</code> to enable the file's content and set the <code>LV_COLOR_DEPTH</code> defines. | ||
+ | * Include <code>lvgl/lvgl.h</code> in files where you need to use LVGL related functions. | ||
+ | * Call <code>lv_tick_inc(x)</code> every <code>x</code> milliseconds in a Timer or Task (<code>x</code> should be between 1 and 10). It is required for the internal timing of LVGL. Alternatively, configure <code>LV_TICK_CUSTOM</code> (see <code>lv_conf.h</code>) so that LVGL can retrieve the current time directly. | ||
+ | * Call <code>lv_init()</code> | ||
+ | * Create a draw buffer: LVGL will render the graphics here first, and send the rendered image to the display. The buffer size can be set freely but 1/10 screen size is a good starting point. | ||
+ | |||
+ | static lv_disp_draw_buf_t draw_buf; | ||
+ | static lv_color_t buf1[DISP_HOR_RES * DISP_VER_RES / 10]; /*Declare a buffer for 1/10 screen size*/ | ||
+ | lv_disp_draw_buf_init(&draw_buf, buf1, NULL, MY_DISP_HOR_RES * MY_DISP_VER_SER / 10); /*Initialize the display buffer.*/ | ||
+ | |||
+ | * Implement and register a function which can copy the rendered image to an area of your display: | ||
+ | |||
+ | static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ | ||
+ | lv_disp_drv_init(&disp_drv); /*Basic initialization*/ | ||
+ | disp_drv.flush_cb = my_disp_flush; /*Set your driver function*/ | ||
+ | disp_drv.draw_buf = &draw_buf; /*Assign the buffer to the display*/ | ||
+ | disp_drv.hor_res = MY_DISP_HOR_RES; /*Set the horizontal resolution of the display*/ | ||
+ | disp_drv.ver_res = MY_DISP_VER_RES; /*Set the vertical resolution of the display*/ | ||
+ | lv_disp_drv_register(&disp_drv); /*Finally register the driver*/ | ||
+ | |||
+ | void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) | ||
+ | { | ||
+ | int32_t x, y; | ||
+ | /*It's a very slow but simple implementation. | ||
+ | *`set_pixel` needs to be written by you to a set pixel on the screen*/ | ||
+ | for(y = area->y1; y <= area->y2; y++) { | ||
+ | for(x = area->x1; x <= area->x2; x++) { | ||
+ | set_pixel(x, y, *color_p); | ||
+ | color_p++; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ | ||
+ | } | ||
+ | |||
+ | * Implement and register a function which can read an input device. E.g. for a touchpad: | ||
+ | |||
+ | static lv_indev_drv_t indev_drv; /*Descriptor of a input device driver*/ | ||
+ | lv_indev_drv_init(&indev_drv); /*Basic initialization*/ | ||
+ | indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/ | ||
+ | indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/ | ||
+ | lv_indev_drv_register(&indev_drv); /*Finally register the driver*/ | ||
+ | |||
+ | void my_touchpad_read(lv_indev_t * indev, lv_indev_data_t * data) | ||
+ | { | ||
+ | /*`touchpad_is_pressed` and `touchpad_get_xy` needs to be implemented by you*/ | ||
+ | if(touchpad_is_pressed()) { | ||
+ | data->state = LV_INDEV_STATE_PRESSED; | ||
+ | touchpad_get_xy(&data->point.x, &data->point.y); | ||
+ | } else { | ||
+ | data->state = LV_INDEV_STATE_RELEASED; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | * Call <code>lv_timer_handler()</code> periodically every few milliseconds in the main <code>while(1)</code> loop or in an operating system task. It will redraw the screen if required, handle input devices, animation etc. | ||
+ | |||
+ | For a more detailed guide go to the Porting section. | ||
| | | | ||
|- | |- |
2022年6月20日 (月) 12:07時点における版
https://docs.lvgl.io/8.2/get-started/index.html
英文 | 自動翻訳 |
---|---|
Quick overviewHere you can learn the most important things about LVGL. You should read this first to get a general impression and read the detailed Porting and Overview sections after that. |
|
Get started in a simulatorInstead of porting LVGL to embedded hardware straight away, it's highly recommended to get started in a simulator first. LVGL is ported to many IDEs to be sure you will find your favorite one. Go to the Simulators section to get ready-to-use projects that can be run on your PC. This way you can save the time of porting for now and get some experience with LVGL immediately. |
|
Add LVGL into your projectIf you would rather try LVGL on your own project follow these steps:
static lv_disp_draw_buf_t draw_buf; static lv_color_t buf1[DISP_HOR_RES * DISP_VER_RES / 10]; /*Declare a buffer for 1/10 screen size*/ lv_disp_draw_buf_init(&draw_buf, buf1, NULL, MY_DISP_HOR_RES * MY_DISP_VER_SER / 10); /*Initialize the display buffer.*/
static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ disp_drv.flush_cb = my_disp_flush; /*Set your driver function*/ disp_drv.draw_buf = &draw_buf; /*Assign the buffer to the display*/ disp_drv.hor_res = MY_DISP_HOR_RES; /*Set the horizontal resolution of the display*/ disp_drv.ver_res = MY_DISP_VER_RES; /*Set the vertical resolution of the display*/ lv_disp_drv_register(&disp_drv); /*Finally register the driver*/ void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) { int32_t x, y; /*It's a very slow but simple implementation. *`set_pixel` needs to be written by you to a set pixel on the screen*/ for(y = area->y1; y <= area->y2; y++) { for(x = area->x1; x <= area->x2; x++) { set_pixel(x, y, *color_p); color_p++; } } lv_disp_flush_ready(disp); /* Indicate you are ready with the flushing*/ }
static lv_indev_drv_t indev_drv; /*Descriptor of a input device driver*/ lv_indev_drv_init(&indev_drv); /*Basic initialization*/ indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/ indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/ lv_indev_drv_register(&indev_drv); /*Finally register the driver*/ void my_touchpad_read(lv_indev_t * indev, lv_indev_data_t * data) { /*`touchpad_is_pressed` and `touchpad_get_xy` needs to be implemented by you*/ if(touchpad_is_pressed()) { data->state = LV_INDEV_STATE_PRESSED; touchpad_get_xy(&data->point.x, &data->point.y); } else { data->state = LV_INDEV_STATE_RELEASED; } }
For a more detailed guide go to the Porting section. |
|