-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i use ESP32-2432S028 : #2
Comments
LVGL drivers for Chinese Sunton Smart display boards, aka CYD (Cheap Yellow Display)Supported boardsThese Sunton boards have an LCD display and most of them have a touch interface. More information, data sheets, ordering information etc. can be found at Sunton Boards information.
Currently this library supports the following boards:
This library integrates seamlessly in PlatformIO and supports these boards by providing display and touch and provides a jump start! Why this libraryWith the boards, there is a link supplied and there are a lot of examples present and this looks fine.... If you know your way around.... These examples for LVGL depend on external libraries (LCD_eSPI or LovyanGFX) but also different touch drivers. However, when working with these libraries, I found out that these libraries had their flaws using these boards:
DependenciesThis library depends on:
How to useGet started by following the steps below. It is also highly recommended to look at the demo application esp32-smartdisplay-demo to quickly see the possibilities of this library. This demo provides:
The next sections will guide you though the process of creating an application. However, some knowledge of PlatformIO, C/C++ and LVGL is required! If you run into problems, first try to open a discussion on the github esp32-smartdisplay discussion board. Step 1: Download (or open) PlatformIOThis library is made for usage in PlatformIO. If not familiar with PlatformIO please take a look at their site and micro controller boards they support. However these boards only use the Arduino platform and ESP32 boards. Make sure you have PlatformIO installed and functional. Follow the documentation on their site: https://docs.platformio.org/en/latest/ Step 2: Boards definitionsThe board definitions required for this library are defined in the boards library platformio-espressif32-sunton. This library must reside in the It is recommended to use
Step 3: Create a new projectUse the standard PlatformIO create project to start a new project. When using a new PlatformIO installation these boards, defined in platformio-espressif32-sunton, are not present. Just use a known ESP32 board and correct this later in the platformIO file. Optionally, you can copy the boards definition to the Step 4: Add this library to your projectTo add this library (and its dependency on LVGL) add the following line to the From the platformIO registry (version 2.0.x):
or the Github repository:
This will automatically download the library, the LVGL library (as a dependency) and set the defines required for the low level drivers. Step 5: Create a settings file for LVGLLVGL needs a configuration file;
Important settings are:
For debugging it is possible to enable logging from LVGL. The library will output to the debugging output (using
By default the logging is only More information about the LVGL configuration can be found in the excellent LVGL documentation.
Step 6: Copy the build flags below in your projectEspecially the definition of the LV_CONF_PATH is critical, this must point to an absolute path where the
The line in the settings logs to the serial console but can be omitted for production builds:
The -Wall flag can also be removed but outputs all the warnings. Step 7: Initialize the display (and touch) in your projectTo enable to display in your project call the void
and update the timer (and drawing) in the loop:
Step 8 (Optional): Create your LVGL file or use SquareLine Studio to make a designThere is a good UI designer available for LVGL and free (but some limitations) for personal use: SquareLine Studio: This tool makes it easy to create transitions, insert images, attach events, work with round screens etc.. A big advantage is that the UI C-code is generated! SquareLine als provides drivers but only export the ui files! In the project settings change the include Step 9: Compile, upload and enjoyThese steps should make it possible to run your application on the display! If there are problems:
More on lv_conf.hTo use the LVGL library, a To include it globally, the define must be (for the include directory):
LV_COLOR_16_SWAPThe LVGL library has a define called LV_COLOR_16_SWAP in the Setting this variable to true is recommended for the SPI interfaces (GC9A01A, ST7789, ILI9341 and ST7796). If not, a warning will be issued but the code should work. The parallel 16 bits panels without interface are not affected by this; the GPIO pin layout will change accordingly. This makes it easier to have only one definition for lv_conf.h and SquareLine.
Additionally, when using the SquareLine Studio for designing the user interface, the display properties (under the project settings) must match this variable. It needs to be set both in LVGL initialization FunctionsThe library exposes the following functions. void smartdisplay_init()This is the first function that needs to be called. It initializes the display controller and touch controller and will turn on the display at 50% brightness. void smartdisplay_lcd_set_backlight(float duty)Set the brightness of the backlight display. The timer used has 13 bits (0 - 8191) but this is converted into a float so the value can be set in percent.. The range is from [0, 1] so 0 is off, 0.5 is half and 1 is full brightness. void smartdisplay_lcd_set_brightness_cb(smartdisplay_lcd_adaptive_brightness_cb_t cb, uint interval)This function can be called to periodically call a user defined function to set the brightness of the display. If a NULL value is passed for the parameter The callback function must have the following format:
If the board has a CdS sensor, a callback is automatically provided. The callback can be set to the internal function So, to enable adaptive brightness using the CdS sensor, call
If no CdS sensor is present, for example, the time of day can be used or sunrise/set. void smartdisplay_led_set_rgb(bool r, bool g, bool b)If the board has a RGB led, this function controls the on/off state of the RGB leds. A true value means: ON (LED is lit), false turns off the led. This function allows only 8 LED colors:
Supported boards N = No touch ESP32-1732S019 N/C Why this library These examples for LVGL depend on external libraries (LCD_eSPI or LovyanGFX) but also different touch drivers. However, when working with these libraries, I found out that these libraries had their flaws using these boards: Lots of configuring to do before it all works, LVGL, currently version 8.3.9 How to use Demo screen This demo provides: User Interface created using the SquareLine Studio GUI generator. If you run into problems, first try to open a discussion on the github esp32-smartdisplay discussion board. Step 1: Download (or open) PlatformIO This library is made for usage in PlatformIO. If not familiar with PlatformIO please take a look at their site and micro controller boards they support. However these boards only use the Arduino platform and ESP32 boards. Make sure you have PlatformIO installed and functional. Follow the documentation on their site: https://docs.platformio.org/en/latest/ Step 2: Boards definitions It is recommended to use git submodule to include these board definitions automatically. [!TIP] If you already have a project, clone it with the git clone --recurse-submodules. If creating a new project, use git submodule add https://github.com/rzeldent/platformio-espressif32-sunton.git boards to add them to your project as a submodule. Step 3: Create a new project Optionally, you can copy the boards definition to the /.platformio\platforms\espressif32\boards directory to have them always available but it is probably easier to create the project, add the boards as a git submodule and change the board afterwards. For each supported board there is a board definition. Step 4: Add this library to your project From the platformIO registry (version 2.0.x): lib_deps = rzeldent/esp32_smartdisplay lib_deps = https://github.com/rzeldent/esp32-smartdisplay.git Step 5: Create a settings file for LVGL [!TIP] LVGL can also be downloaded manually from: https://github.com/lvgl/lvgl/archive/master.zip to extract the template. The template can also be copied from the demo application. Important settings are: Only the R5G6B5 format is supported on these panels. /Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)/ /Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)/ /Use a custom tick source that tells the elapsed time in milliseconds and enables this code./ #define LV_USE_PERF_MONITOR 1 ... #define LV_USE_ARC 1 /Enable the log module/ More information about the LVGL configuration can be found in the excellent LVGL documentation. [!WARNING] After the library has been build, changes in the lv_conf.h are no longer applied because libraries are cached. To apply these settings, delete the .pio directory so the libraries will be rebuild. Step 6: Copy the build flags below in your project build_flags = -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE Step 7: Initialize the display (and touch) in your project void setup() auto disp = lv_disp_get_default(); void loop() SquareLine Studio This tool makes it easy to create transitions, insert images, attach events, work with round screens etc.. A big advantage is that the UI C-code is generated! SquareLine als provides drivers but only export the ui files! In the project settings change the include lvgl/lvgl.h to lvgl.h. Step 9: Compile, upload and enjoy If there are problems: Read this manual again to see if all the steps were followed, To include it globally, the define must be (for the include directory): -D LV_CONF_PATH=${PROJECT_INCLUDE_DIR}/lv_conf.h LV_COLOR_16_SWAP Setting this variable to true is recommended for the SPI interfaces (GC9A01A, ST7789, ILI9341 and ST7796). If not, a warning will be issued but the code should work. The parallel 16 bits panels without interface are not affected by this; the GPIO pin layout will change accordingly. This makes it easier to have only one definition for lv_conf.h and SquareLine. [!IMPORTANT] If this is not done, the code will run but swapping will be done runtime (degrading a bit the performance). So it is preferable to always set the LV_COLOR_16_SWAP to 1 when using SPI. Additionally, when using the SquareLine Studio for designing the user interface, the display properties (under the project settings) must match this variable. It needs to be set both in lv_conf.h configuration file and the corresponding display properties (16 bit swap) in SquareLine Studio. SquareLine display properties LVGL initialization Functions void smartdisplay_init() void smartdisplay_lcd_set_backlight(float duty) void smartdisplay_lcd_set_brightness_cb(smartdisplay_lcd_adaptive_brightness_cb_t cb, uint interval) The callback function must have the following format: float smartdisplay_lcd_adaptive_brightness_function)() So, to enable adaptive brightness using the CdS sensor, call smartdisplay_lcd_set_brightness_cb(smartdisplay_lcd_adaptive_brightness_cds, 100); void smartdisplay_led_set_rgb(bool r, bool g, bool b) This function allows only 8 LED colors: R G B Color touch_calibration_data_t touch_calibration_data touch_calibration_data_t smartdisplay_compute_touch_calibration(const lv_point_t screen[3], const lv_point_t touch[3]) Rotation of the display and touch From the LVGL documentation: The rotation values are relative to how you would rotate the physical display in the clockwise direction. Thus, LV_DISP_ROT_90 means you rotate the hardware 90 degrees clockwise, and the display rotates 90 degrees counterclockwise to compensate. Rotating is done calling the lv_disp_set_rotation function in the LVGL library with the rotation: auto disp = lv_disp_get_default(); To adjust the display and touch to the default (LV_DISP_ROT_NONE) there are 6 defines in the boards definition: Name Description [!TIP] When building using a pipeline (github action), the ini below, with all the boards, can be used automatically create builds for all the boards. [platformio] [env] monitor_speed = 115200 Partition scheme for OTAboard_build.partitions = min_spiffs.csv build_flags = lib_deps = [env:esp32-1732S019C] [env:esp32-1732S019N] [env:esp32-2424S012C] [env:esp32-2424S012N] [env:esp32-2432S022N] [env:esp32-2432S022C] [env:esp32-2432S024C] [env:esp32-2432S024N] [env:esp32-2432S024R] [env:esp32-2432S028R] [env:esp32-2432S028Rv2] [env:esp32-2432S028Rv3] [env:esp32-2432S032C] [env:esp32-2432S032N] [env:esp32-2432S032R] [env:esp32-3248S035C] [env:esp32-3248S035R] [env:esp32-4827S043C] [env:esp32-4827S043R] [env:esp32-4827S043N] [env:esp32-4848S040CIY1] [env:esp32-4848S040CIY3] [env:esp32-8048S043C] [env:esp32-8048S043N] [env:esp32-8048S043R] [env:esp32-8048S050C] [env:esp32-8048S050N] [env:esp32-8048S050R] [env:esp32-8048S070C] [env:esp32-8048S070N] [env:esp32-8048S070R] Name Version |
It is work !!!!! |
SPI
Two separate SPI busses are being used for the display and the touchscreen.
spi:
clk_pin: GPIO14
mosi_pin: GPIO13
miso_pin: GPIO12
clk_pin: GPIO25
mosi_pin: GPIO32
miso_pin: GPIO39
https://macsbug.wordpress.com/2022/08/17/esp32-2432s028/
LIbrary Lovyan GFX 使用により多くの事が容易にできます。
日本語Fontは 綺麗で簡単に使用できます。
Lovyan GFX 設定:
Display:ILI9341 :SPI2 HOST:SPI2_HOST
cfg.freq_write : Max 40MHz
Touch:XPT2046:SPI3 HOST:VSPI_HOST
Touch:cfg.pin_int = 36; Touchが動作しない場合は -1 にします。
/```
/----------------------------------------------------------------------
// https://github.com/lovyan03/LovyanGFX/blob/master/examples/HowToUse/2_user_setting/2_user_setting.ino
class LGFX : public lgfx::LGFX_Device{
lgfx::Panel_ILI9341 _panel_instance;
lgfx::Bus_SPI _bus_instance;
lgfx::Light_PWM _light_instance;
lgfx::Touch_XPT2046 _touch_instance;
//----------------------------------------------------------------------
public:LGFX(void){
{ // バス制御の設定を行います。
auto cfg = _bus_instance.config();// バス設定用の構造体を取得します。
// SPIバスの設定
cfg.spi_host = SPI2_HOST; // 使用するSPIを選択 (VSPI_HOST or HSPI_HOST)
cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3)
cfg.freq_write = 40000000; // 送信時のSPIクロック(最大80MHz,80MHzを整数割値に丸め)
cfg.freq_read = 16000000; // 受信時のSPIクロック
cfg.spi_3wire = false; // 受信をMOSIピンで行う場合はtrueを設定
cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定
cfg.dma_channel= 1; // 使用DMAチャンネル設定(1or2,0=disable)(0=DMA不使用)
cfg.pin_sclk = 14; // SPIのSCLKピン番号を設定 SCK
cfg.pin_mosi = 13; // SPIのMOSIピン番号を設定 SDI
cfg.pin_miso = 12; // SPIのMISOピン番号を設定 (-1 = disable) SDO
cfg.pin_dc = 2; // SPIのD/C ピン番号を設定 (-1 = disable) RS
// SDカードと共通のSPIバスを使う場合、MISOは省略せず必ず設定してください。
_bus_instance.config(cfg); // 設定値をバスに反映します。
_panel_instance.setBus(&_bus_instance);// バスをパネルにセットします。
}
{ // 表示パネル制御の設定を行います。
auto cfg = _panel_instance.config();// 表示パネル設定用の構造体を取得します。
cfg.pin_cs = 15; // CS が接続されているピン番号(-1 = disable)
cfg.pin_rst = -1; // RST が接続されているピン番号(-1 = disable)
cfg.pin_busy = -1; // BUSYが接続されているピン番号(-1 = disable)
cfg.memory_width = 240; // ドライバICがサポートしている最大の幅
cfg.memory_height = 320; // ドライバICがサポートしている最大の高さ
cfg.panel_width = 240; // 実際に表示可能な幅
cfg.panel_height = 320; // 実際に表示可能な高さ
cfg.offset_x = 0; // パネルのX方向オフセット量
cfg.offset_y = 0; // パネルのY方向オフセット量
cfg.offset_rotation = 0; // 回転方向の値のオフセット 0
7 (47は上下反転)cfg.dummy_read_pixel= 8; // ピクセル読出し前のダミーリードのビット数
cfg.dummy_read_bits = 1; // ピクセル外のデータ読出し前のダミーリードのビット数
cfg.readable = true; // データ読出しが可能な場合 trueに設定
cfg.invert = false; // パネルの明暗が反転場合 trueに設定
cfg.rgb_order = false; // パネルの赤と青が入れ替わる場合 trueに設定 ok
cfg.dlen_16bit = false; // データ長16bit単位で送信するパネル trueに設定
cfg.bus_shared = false; // SDカードとバスを共有 trueに設定
_panel_instance.config(cfg);
}
{ // バックライト制御の設定を行います。(必要なければ削除)
auto cfg = _light_instance.config();// バックライト設定用の構造体を取得します。
cfg.pin_bl = 21; // バックライトが接続されているピン番号 BL
cfg.invert = false; // バックライトの輝度を反転させる場合 true
cfg.freq = 44100; // バックライトのPWM周波数
cfg.pwm_channel = 7; // 使用するPWMのチャンネル番号
_light_instance.config(cfg);
_panel_instance.setLight(&_light_instance);//バックライトをパネルにセットします。
}
{ // タッチスクリーン制御の設定を行います。(必要なければ削除)
auto cfg = _touch_instance.config();
cfg.x_min = 300; // タッチスクリーンから得られる最小のX値(生の値)
cfg.x_max = 3900; // タッチスクリーンから得られる最大のX値(生の値)
cfg.y_min = 200; // タッチスクリーンから得られる最小のY値(生の値)
cfg.y_max = 3700; // タッチスクリーンから得られる最大のY値(生の値)
cfg.pin_int = -1; // INTが接続されているピン番号, TP IRQ 36
cfg.bus_shared = false; // 画面と共通のバスを使用している場合 trueを設定
cfg.offset_rotation = 6; // 表示とタッチの向きのが一致しない場合の調整 0~7の値で設定
// SPI接続の場合
cfg.spi_host = VSPI_HOST;// 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
cfg.freq = 1000000; // SPIクロックを設定
cfg.pin_sclk = 25; // SCLKが接続されているピン番号, TP CLK
cfg.pin_mosi = 32; // MOSIが接続されているピン番号, TP DIN
cfg.pin_miso = 39; // MISOが接続されているピン番号, TP DOUT
cfg.pin_cs = 33; // CS が接続されているピン番号, TP CS
_touch_instance.config(cfg);
_panel_instance.setTouch(&_touch_instance); // タッチスクリーンをパネルにセットします。
}
setPanel(&_panel_instance);// 使用するパネルをセットします。
}
};
LGFX tft; // 準備したクラスのインスタンスを作成します。
//=====================================================================
The text was updated successfully, but these errors were encountered: