From 069e24bdb294f27cc45c50497b05b5377d9f16d7 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 28 Jun 2020 20:37:32 +0200 Subject: [PATCH] add examples folder with arduio examples and move porting folder there --- .../arduino/ESP32_TFT_eSPI/ESP32_TFT_eSPI.ino | 119 ++++++++++++++++++ examples/arduino/ESP32_TFT_eSPI/README.md | 44 +++++++ examples/arduino/README.md | 37 ++++++ .../porting}/lv_port_disp_template.c | 0 .../porting}/lv_port_disp_template.h | 0 .../porting}/lv_port_fs_template.c | 0 .../porting}/lv_port_fs_template.h | 0 .../porting}/lv_port_indev_template.c | 0 .../porting}/lv_port_indev_template.h | 0 library.properties | 10 -- lv_conf_template.h | 4 +- src/lv_conf_internal.h | 4 +- 12 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 examples/arduino/ESP32_TFT_eSPI/ESP32_TFT_eSPI.ino create mode 100644 examples/arduino/ESP32_TFT_eSPI/README.md create mode 100644 examples/arduino/README.md rename {porting => examples/porting}/lv_port_disp_template.c (100%) rename {porting => examples/porting}/lv_port_disp_template.h (100%) rename {porting => examples/porting}/lv_port_fs_template.c (100%) rename {porting => examples/porting}/lv_port_fs_template.h (100%) rename {porting => examples/porting}/lv_port_indev_template.c (100%) rename {porting => examples/porting}/lv_port_indev_template.h (100%) delete mode 100644 library.properties diff --git a/examples/arduino/ESP32_TFT_eSPI/ESP32_TFT_eSPI.ino b/examples/arduino/ESP32_TFT_eSPI/ESP32_TFT_eSPI.ino new file mode 100644 index 000000000..4e777c19e --- /dev/null +++ b/examples/arduino/ESP32_TFT_eSPI/ESP32_TFT_eSPI.ino @@ -0,0 +1,119 @@ +#include +#include + +TFT_eSPI tft = TFT_eSPI(); /* TFT instance */ +static lv_disp_buf_t disp_buf; +static lv_color_t buf[LV_HOR_RES_MAX * 10]; + +#if USE_LV_LOG != 0 +/* Serial debugging */ +void my_print(lv_log_level_t level, const char * file, uint32_t line, const char * dsc) +{ + + Serial.printf("%s@%d->%s\r\n", file, line, dsc); + Serial.flush(); +} +#endif + +/* Display flushing */ +void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) +{ + uint32_t w = (area->x2 - area->x1 + 1); + uint32_t h = (area->y2 - area->y1 + 1); + + tft.startWrite(); + tft.setAddrWindow(area->x1, area->y1, w, h); + tft.pushColors(&color_p->full, w * h, true); + tft.endWrite(); + + lv_disp_flush_ready(disp); +} + +/*Read the touchpad*/ +bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) +{ + uint16_t touchX, touchY; + + bool touched = tft.getTouch(&touchX, &touchY, 600); + + if(!touched) + { + data->state = LV_INDEV_STATE_REL; + return false; + } + else + { + data->state = LV_INDEV_STATE_PR; + } + + if(touchX>screenWidth || touchY > screenHeight) + { + Serial.println("Y or y outside of expected parameters.."); + Serial.print("y:"); + Serial.print(touchX); + Serial.print(" x:"); + Serial.print(touchY); + } + else + { + /*Set the coordinates*/ + data->point.x = touchX; + data->point.y = touchY; + + Serial.print("Data x"); + Serial.println(touchX); + + Serial.print("Data y"); + Serial.println(touchY); + + } + + return false; /*Return `false` because we are not buffering and no more data to read*/ +} + +void setup() +{ + Serial.begin(115200); /* prepare for possible serial debug */ + + lv_init(); + +#if USE_LV_LOG != 0 + lv_log_register_print_cb(my_print); /* register print function for debugging */ +#endif + + tft.begin(); /* TFT init */ + tft.setRotation(1); /* Landscape orientation */ + + uint16_t calData[5] = { 275, 3620, 264, 3532, 1 }; + tft.setTouch(calData); + + lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); + + /*Initialize the display*/ + lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); + disp_drv.hor_res = 320; + disp_drv.ver_res = 240; + disp_drv.flush_cb = my_disp_flush; + disp_drv.buffer = &disp_buf; + lv_disp_drv_register(&disp_drv); + + /*Initialize the (dummy) input device driver*/ + lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = my_touchpad_read; + lv_indev_drv_register(&indev_drv); + + /* Try an example from the lv_examples repository + * https://github.com/lvgl/lv_examples*/ + lv_ex_btn_1(); +} + + +void loop() +{ + + lv_task_handler(); /* let the GUI do its work */ + delay(5); +} diff --git a/examples/arduino/ESP32_TFT_eSPI/README.md b/examples/arduino/ESP32_TFT_eSPI/README.md new file mode 100644 index 000000000..10f583d42 --- /dev/null +++ b/examples/arduino/ESP32_TFT_eSPI/README.md @@ -0,0 +1,44 @@ +# Example for lv_arduino using a slider + +This example has the screen set to 320x480 (ILI9488), change this by altering the following lines in the main ino file: + +```C +int screenWidth = 480; +int screenHeight = 320; +``` + +## Backlight + +Change pin 32 to your preferred backlight pin using a PNP transistor (2N3906) or remove the following code and connect directly to +ve: + +```C + ledcSetup(10, 5000/*freq*/, 10 /*resolution*/); + ledcAttachPin(32, 10); + analogReadResolution(10); + ledcWrite(10,768); +``` + +## Theme selection + +Change the following to change the theme: + +```C + lv_theme_t * th = lv_theme_night_init(210, NULL); //Set a HUE value and a Font for the Night Theme + lv_theme_set_current(th); +``` + +## Calibration + +This is using the bodmer tft_espi driver for touch. To correctly set the calibration load the calibration sketch and replace the following with your values: + +```C +uint16_t calData[5] = { 275, 3620, 264, 3532, 1 }; +``` + +## Screen rotation + +Check the following if you need to alter your screen rotation: + +```C + tft.setRotation(3); +``` diff --git a/examples/arduino/README.md b/examples/arduino/README.md new file mode 100644 index 000000000..b6a764c9e --- /dev/null +++ b/examples/arduino/README.md @@ -0,0 +1,37 @@ +# LVGL Arduino examples + +LVGL can be installed via Arduino IDE Library Manager or as an .ZIP library. +It will install [lv_exmaples](https://github.com/lvgl/lv_examples) which contains a lot of examples and demos to try LVGL. + +## Example + +There are simple examples which use the [TFT_eSPI](https://github.com/Bodmer/TFT_eSPI) library as a TFT driver to simplify testing. +To get all this to work you have to setup TFT_eSPI to work with your TFT display type via editing the `User_Setup.h` file in TFT_eSPI library folder, or by selecting your own configurtion in the `User_Setup_Select.h` file in TFT_eSPI library folder. + +LVGL library has its own configuration file called `lv_conf.h`. When LVGL is installed to followings needs to be done to configure it: +1. Go to directory of the installed Arduno libraries +2. Go to `lvgl` and copy `lv_conf_template.h` as `lvgl.h` next to the `lvgl` folder. +3. Open `lv_conf.h` and change the first `#if 0` to `#if 1` +4. Set the resolution of your display in `LV_HOR_RES_MAX` and `LV_VER_RES_MAX` +5. Set the color depth of you display in `LV_COLOR_DEPTH` +6. Set `LV_TICK_CUSTOM 1` + +## Debugging + +In case of trouble there are debug informations inside LVGL. In the `ESP32_TFT_eSPI` example there is `my_print` method, which allow to send this debug informations to the serial interface. To enable this feature you have to edit `lv_conf.h` file and enable logging in section `log settings`: + +```c +/*Log settings*/ +#define USE_LV_LOG 1 /*Enable/disable the log module*/ +#if LV_USE_LOG +/* How important log should be added: + * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information + * LV_LOG_LEVEL_INFO Log important events + * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem + * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail + * LV_LOG_LEVEL_NONE Do not log anything + */ +# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN +``` + +After enabling log module and setting LV_LOG_LEVEL accordingly the output log is sent to the `Serial` port @ 115200 Bd. diff --git a/porting/lv_port_disp_template.c b/examples/porting/lv_port_disp_template.c similarity index 100% rename from porting/lv_port_disp_template.c rename to examples/porting/lv_port_disp_template.c diff --git a/porting/lv_port_disp_template.h b/examples/porting/lv_port_disp_template.h similarity index 100% rename from porting/lv_port_disp_template.h rename to examples/porting/lv_port_disp_template.h diff --git a/porting/lv_port_fs_template.c b/examples/porting/lv_port_fs_template.c similarity index 100% rename from porting/lv_port_fs_template.c rename to examples/porting/lv_port_fs_template.c diff --git a/porting/lv_port_fs_template.h b/examples/porting/lv_port_fs_template.h similarity index 100% rename from porting/lv_port_fs_template.h rename to examples/porting/lv_port_fs_template.h diff --git a/porting/lv_port_indev_template.c b/examples/porting/lv_port_indev_template.c similarity index 100% rename from porting/lv_port_indev_template.c rename to examples/porting/lv_port_indev_template.c diff --git a/porting/lv_port_indev_template.h b/examples/porting/lv_port_indev_template.h similarity index 100% rename from porting/lv_port_indev_template.h rename to examples/porting/lv_port_indev_template.h diff --git a/library.properties b/library.properties deleted file mode 100644 index 9c8c48826..000000000 --- a/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=lvgl -version=7.0.2 -author=kisvegabor -maintainer=Pavel Brychta -sentence=Full-featured Graphics Library for Embedded Systems -paragraph=Powerful and easy-to-use embedded GUI with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash). -category=Display -url=https://lvgl.io -architectures=* -includes=lvgl.h diff --git a/lv_conf_template.h b/lv_conf_template.h index f4cd80800..945761c86 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -268,8 +268,8 @@ typedef void * lv_img_decoder_user_data_t; * It removes the need to manually update the tick with `lv_tick_inc`) */ #define LV_TICK_CUSTOM 0 #if LV_TICK_CUSTOM == 1 -#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/ -#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ +#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ #endif /*LV_TICK_CUSTOM*/ typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index 8b389a355..d6c9163b6 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -391,10 +391,10 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h" */ #endif #if LV_TICK_CUSTOM == 1 #ifndef LV_TICK_CUSTOM_INCLUDE -#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/ +#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the sys time function*/ #endif #ifndef LV_TICK_CUSTOM_SYS_TIME_EXPR -#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current sys time in ms*/ #endif #endif /*LV_TICK_CUSTOM*/