This commit is contained in:
BoomPC 2024-05-06 22:35:49 +08:00
commit b273c2620c
17 changed files with 4666 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

15
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"stm32-for-vscode.openOCDPath": false,
"stm32-for-vscode.makePath": false,
"stm32-for-vscode.armToolchainPath": false,
"files.associations": {
"刷新画线": "c",
"optional": "cpp",
"random": "cpp",
"limits": "cpp",
"new": "cpp",
"*.tcc": "cpp",
"cmath": "cpp",
"utility": "cpp"
}
}

39
include/README Normal file
View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README Normal file
View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

29
platformio.ini Normal file
View File

@ -0,0 +1,29 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-c3-devkitm-1]
platform = espressif32
board_build.flash_mode = dio
board = esp32-c3-devkitm-1
framework = arduino
monitor_speed = 115200
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
-Isrc/
-DLV_CONF_INCLUDE_SIMPLE
-DLV_DEMO_CONF_INCLUDE_SIMPLE
-DLV_USE_DEMO_BENCHMARK
lib_deps =
lovyan03/LovyanGFX@^1.1.12
tanakamasayuki/efont Unicode Font Data@^1.0.9
peterus/INA226Lib@^1.1.3
lvgl/lvgl@^8.3.4
lvgl/lv_demos@^8.1.0

335
src/LVGL Normal file
View File

@ -0,0 +1,335 @@
#include <Wire.h>
#include <INA226.h>
INA226 ina(Wire);
// #define LGFX_AUTODETECT
// #include <LGFX_AUTODETECT.hpp>
#include <lv_demo.h>
#include <lvgl.h>
/*Change to your screen resolution*/
static const uint16_t screenWidth = 320;
static const uint16_t screenHeight = 172;
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[2][screenWidth * 10];
#include <LovyanGFX.hpp>
// ESP32でLovyanGFXを独自設定で利用する場合の設定例
//----------------------------------------------------------------------------
/// 独自の設定を行うクラスを、LGFX_Deviceから派生して作成します。
class LGFX : public lgfx::LGFX_Device
{
lgfx::Panel_ST7789 _panel_instance;
lgfx::Bus_SPI _bus_instance; // SPIバスのインスタンス
lgfx::Light_PWM _light_instance;
public:
// コンストラクタを作成し、ここで各種設定を行います。
// クラス名を変更した場合はコンストラクタも同じ名前を指定してください。
LGFX(void)
{
{ // バス制御の設定を行います。
auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。
// SPIバスの設定
cfg.spi_host = SPI2_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST
// ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。
cfg.spi_mode = 3; // SPI通信モードを設定 (0 ~ 3)
cfg.freq_write = 80000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます)
cfg.freq_read = 16000000; // 受信時のSPIクロック
cfg.spi_3wire = true; // 受信をMOSIピンで行う場合はtrueを設定
cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定
cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定)
// ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。
cfg.pin_sclk = 4; // SPIのSCLKピン番号を設定
cfg.pin_mosi = 5; // SPIのMOSIピン番号を設定
cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable)
cfg.pin_dc = 6; // SPIのD/Cピン番号を設定 (-1 = disable)
// SDカードと共通のSPIバスを使う場合、MISOは省略せず必ず設定してください。
_bus_instance.config(cfg); // 設定値をバスに反映します。
_panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。
}
{ // 表示パネル制御の設定を行います。
auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。
cfg.pin_cs = 8; // CSが接続されているピン番号 (-1 = disable)
cfg.pin_rst = 7; // RSTが接続されているピン番号 (-1 = disable)
cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable)
// ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。
cfg.panel_width = 172; // 実際に表示可能な幅
cfg.panel_height = 320; // 実際に表示可能な高さ
cfg.offset_x = 34; // パネルのX方向オフセット量
cfg.offset_y = 0; // パネルのY方向オフセット量
cfg.offset_rotation = 3; // 回転方向の値のオフセット 0~7 (4~7は上下反転)
cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数
cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数
cfg.readable = false; // データ読出しが可能な場合 trueに設定
cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定
cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定
cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定
cfg.bus_shared = false; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います)
_panel_instance.config(cfg);
}
{ // バックライト制御の設定を行います。(必要なければ削除)
auto cfg = _light_instance.config(); // バックライト設定用の構造体を取得します。
cfg.pin_bl = 10; // バックライトが接続されているピン番号
cfg.invert = true; // バックライトの輝度を反転させる場合 true
cfg.freq = 44100; // バックライトのPWM周波数
cfg.pwm_channel = 1; // 使用するPWMのチャンネル番号
_light_instance.config(cfg);
_panel_instance.setLight(&_light_instance); // バックライトをパネルにセットします。
}
setPanel(&_panel_instance); // 使用するパネルをセットします。
}
};
static LGFX lcd;
// static LGFX_Sprite sprite(&lcd);
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
if (lcd.getStartCount() == 0)
{ // Processing if not yet started
lcd.startWrite();
}
lcd.pushImageDMA(area->x1, area->y1, area->x2 - area->x1 + 1, area->y2 - area->y1 + 1, (lgfx::swap565_t *)&color_p->full);
lv_disp_flush_ready(disp);
}
// void sd_access_sample(void)
// {
// if (lcd.getStartCount() > 0)
// { // Free the bus before accessing the SD card
// gfx.endWrite();
// }
// // Something to manipulate the SD card.
// auto file = SD.open("/file");
// file.close();
// }
/*Read the touchpad*/
void my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
uint16_t touchX, touchY;
data->state = LV_INDEV_STATE_REL;
if (lcd.getTouch(&touchX, &touchY))
{
data->state = LV_INDEV_STATE_PR;
/*Set the coordinates*/
data->point.x = touchX;
data->point.y = touchY;
}
}
void checkConfig()
{
Serial.print("Mode: ");
switch (ina.getMode())
{
case INA226_MODE_POWER_DOWN:
Serial.println("Power-Down");
break;
case INA226_MODE_SHUNT_TRIG:
Serial.println("Shunt Voltage, Triggered");
break;
case INA226_MODE_BUS_TRIG:
Serial.println("Bus Voltage, Triggered");
break;
case INA226_MODE_SHUNT_BUS_TRIG:
Serial.println("Shunt and Bus, Triggered");
break;
case INA226_MODE_ADC_OFF:
Serial.println("ADC Off");
break;
case INA226_MODE_SHUNT_CONT:
Serial.println("Shunt Voltage, Continuous");
break;
case INA226_MODE_BUS_CONT:
Serial.println("Bus Voltage, Continuous");
break;
case INA226_MODE_SHUNT_BUS_CONT:
Serial.println("Shunt and Bus, Continuous");
break;
default:
Serial.println("unknown");
}
Serial.print("Samples average: ");
switch (ina.getAverages())
{
case INA226_AVERAGES_1:
Serial.println("1 sample");
break;
case INA226_AVERAGES_4:
Serial.println("4 samples");
break;
case INA226_AVERAGES_16:
Serial.println("16 samples");
break;
case INA226_AVERAGES_64:
Serial.println("64 samples");
break;
case INA226_AVERAGES_128:
Serial.println("128 samples");
break;
case INA226_AVERAGES_256:
Serial.println("256 samples");
break;
case INA226_AVERAGES_512:
Serial.println("512 samples");
break;
case INA226_AVERAGES_1024:
Serial.println("1024 samples");
break;
default:
Serial.println("unknown");
}
Serial.print("Bus conversion time: ");
switch (ina.getBusConversionTime())
{
case INA226_BUS_CONV_TIME_140US:
Serial.println("140uS");
break;
case INA226_BUS_CONV_TIME_204US:
Serial.println("204uS");
break;
case INA226_BUS_CONV_TIME_332US:
Serial.println("332uS");
break;
case INA226_BUS_CONV_TIME_588US:
Serial.println("558uS");
break;
case INA226_BUS_CONV_TIME_1100US:
Serial.println("1.100ms");
break;
case INA226_BUS_CONV_TIME_2116US:
Serial.println("2.116ms");
break;
case INA226_BUS_CONV_TIME_4156US:
Serial.println("4.156ms");
break;
case INA226_BUS_CONV_TIME_8244US:
Serial.println("8.244ms");
break;
default:
Serial.println("unknown");
}
Serial.print("Shunt conversion time: ");
switch (ina.getShuntConversionTime())
{
case INA226_SHUNT_CONV_TIME_140US:
Serial.println("140uS");
break;
case INA226_SHUNT_CONV_TIME_204US:
Serial.println("204uS");
break;
case INA226_SHUNT_CONV_TIME_332US:
Serial.println("332uS");
break;
case INA226_SHUNT_CONV_TIME_588US:
Serial.println("558uS");
break;
case INA226_SHUNT_CONV_TIME_1100US:
Serial.println("1.100ms");
break;
case INA226_SHUNT_CONV_TIME_2116US:
Serial.println("2.116ms");
break;
case INA226_SHUNT_CONV_TIME_4156US:
Serial.println("4.156ms");
break;
case INA226_SHUNT_CONV_TIME_8244US:
Serial.println("8.244ms");
break;
default:
Serial.println("unknown");
}
Serial.print("Max possible current: ");
Serial.print(ina.getMaxPossibleCurrent());
Serial.println(" A");
Serial.print("Max current: ");
Serial.print(ina.getMaxCurrent());
Serial.println(" A");
Serial.print("Max shunt voltage: ");
Serial.print(ina.getMaxShuntVoltage());
Serial.println(" V");
Serial.print("Max power: ");
Serial.print(ina.getMaxPower());
Serial.println(" W");
}
void setup(void)
{
lcd.init();
// lcd.startWrite();
lcd.setBrightness(100);
lv_init();
lv_disp_draw_buf_init(&draw_buf, buf[0], buf[1], screenWidth * 10);
/*Initialize the display*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
/*Change the following line to your display resolution*/
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
/*Initialize the input device driver*/
static 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);
lv_demo_benchmark();
Wire.begin(1, 0, 100000);
// Default INA226 address is 0x40
bool success = ina.begin();
// Check if the connection was successful, stop if not
if (!success)
{
Serial.println("Connection error");
while (1)
;
}
// Configure INA226
ina.configure(INA226_AVERAGES_1, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);
// Calibrate INA226. Rshunt = 0.001 ohm, Max excepted current = 4A
ina.calibrate(0.001, 40);
// Display configuration
checkConfig();
}
int32_t current;
int32_t current_buf[322];
float t = 0;
void loop(void)
{
lv_timer_handler(); /* let the GUI do its work */
delay(1);
}

31
src/image.h Normal file
View File

@ -0,0 +1,31 @@
_ _ _ _ _ _ _ _ _ _ _ _ _ R R R R R R R _ _ _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ _ R R R R R R R R R R R _ _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ _ R R R R R R R R R R R R R _ _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ _ R R R R _ _ _ _ _ _ R R R R R _ _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ R R R R R _ _ R R R _ _ R R R R R _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _ R R R R R _ _ R R R _ _ R R R R R _ _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ _ _ _ _ R R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R _ _ R R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R R _ _ R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R R _ _ R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R _ _ R R R _ _ R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ _ R R R R R R R R R R R R R R R R R R R _ _ _ _ _ _ _
_ _ _ _ _ _ G Y Y Y Y Y Y R R R R R R R M M M M M M B _ _ _ _ _ _
_ _ _ _ G G G G Y Y Y Y Y Y Y R R R M M M M M M M B B B B _ _ _ _
_ _ _ G G G G G Y Y Y Y Y Y Y Y R M M M M M M M M B B B B B _ _ _
_ _ G G G G G G G Y Y Y Y Y Y Y W M M M M M M M B B B B B B B _ _
_ G G G G G G G G G Y Y Y Y Y W W W M M M M M B B B B B B B B B _
_ G G G G G G G G G G Y Y Y Y W W W M M M M B B B B B B B B B B _
G G G G G G G G G G G G G Y W W W W W M B B B B B B B B B B B B B
G G G G G _ _ _ _ G G G G G C C C C C B B B B _ _ _ _ _ B B B B B
G G G G _ _ G G _ _ G G G G C C C C C B B B B _ _ B B _ _ B B B B
G G G G _ _ G G G G G G G G C C C C C B B B B _ _ B B _ _ B B B B
G G G G _ _ G G G G G G G G C C C C C B B B B _ _ _ _ _ B B B B B
G G G G _ _ G _ _ _ G G G G C C C C C B B B B _ _ B B _ _ B B B B
G G G G _ _ G G _ _ G G G G C C C C C B B B B _ _ B B _ _ B B B B
_ G G G _ _ G G _ _ G G G G G C C C B B B B B _ _ B B _ _ B B B _
_ G G G G _ _ _ _ G G G G G G C C C B B B B B _ _ _ _ _ B B B B _
_ _ G G G G G G G G G G G G G G C B B B B B B B B B B B B B B _ _
_ _ _ G G G G G G G G G G G G G _ B B B B B B B B B B B B B _ _ _
_ _ _ _ G G G G G G G G G G G _ _ _ B B B B B B B B B B B _ _ _ _
_ _ _ _ _ _ G G G G G G G _ _ _ _ _ _ _ B B B B B B B _ _ _ _ _ _

677
src/lv_conf.h Normal file
View File

@ -0,0 +1,677 @@
/**
* @file lv_conf.h
* Configuration file for v8.3.0-dev
*/
/*
* Copy this file as `lv_conf.h`
* 1. simply next to the `lvgl` folder
* 2. or any other places and
* - define `LV_CONF_INCLUDE_SIMPLE`
* - add the path as include path
*/
/* clang-format off */
#if 1 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
#include <stdint.h>
/*====================
COLOR SETTINGS
*====================*/
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH 16
/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP 1
/*Enable more complex drawing routines to manage screens transparency.
*Can be used if the UI is above another layer, e.g. an OSD menu or video player.
*Requires `LV_COLOR_DEPTH = 32` colors and the screen's `bg_opa` should be set to non LV_OPA_COVER value*/
#define LV_COLOR_SCREEN_TRANSP 0
/* Adjust color mix functions rounding. GPUs might calculate color mix (blending) differently.
* 0: round down, 64: round up from x.75, 128: round up from half, 192: round up from x.25, 254: round up */
#define LV_COLOR_MIX_ROUND_OFS (LV_COLOR_DEPTH == 32 ? 0: 128)
/*Images pixels with this color will not be drawn if they are chroma keyed)*/
#define LV_COLOR_CHROMA_KEY lv_color_hex(0x00ff00) /*pure green*/
/*=========================
MEMORY SETTINGS
*=========================*/
/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#define LV_MEM_CUSTOM 0
#if LV_MEM_CUSTOM == 0
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/
/*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/
#define LV_MEM_ADR 0 /*0: unused*/
/*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/
#if LV_MEM_ADR == 0
//#define LV_MEM_POOL_INCLUDE your_alloc_library /* Uncomment if using an external allocator*/
//#define LV_MEM_POOL_ALLOC your_alloc /* Uncomment if using an external allocator*/
#endif
#else /*LV_MEM_CUSTOM*/
#define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
#define LV_MEM_CUSTOM_ALLOC malloc
#define LV_MEM_CUSTOM_FREE free
#define LV_MEM_CUSTOM_REALLOC realloc
#endif /*LV_MEM_CUSTOM*/
/*Number of the intermediate memory buffer used during rendering and other internal processing mechanisms.
*You will see an error log message if there wasn't enough buffers. */
#define LV_MEM_BUF_MAX_NUM 16
/*Use the standard `memcpy` and `memset` instead of LVGL's own functions. (Might or might not be faster).*/
#define LV_MEMCPY_MEMSET_STD 0
/*====================
HAL SETTINGS
*====================*/
/*Default display refresh period. LVG will redraw changed areas with this period time*/
#define LV_DISP_DEF_REFR_PERIOD 16 /*[ms]*/
/*Input device read period in milliseconds*/
#define LV_INDEV_DEF_READ_PERIOD 30 /*[ms]*/
/*Use a custom tick source that tells the elapsed time in milliseconds.
*It removes the need to manually update the tick with `lv_tick_inc()`)*/
#define LV_TICK_CUSTOM 1
#if LV_TICK_CUSTOM
#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*/
/*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings.
*(Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI_DEF 130 /*[px/inch]*/
/*=======================
* FEATURE CONFIGURATION
*=======================*/
/*-------------
* Drawing
*-----------*/
/*Enable complex draw engine.
*Required to draw shadow, gradient, rounded corners, circles, arc, skew lines, image transformations or any masks*/
#define LV_DRAW_COMPLEX 1
#if LV_DRAW_COMPLEX != 0
/*Allow buffering some shadow calculation.
*LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer, where shadow size is `shadow_width + radius`
*Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost*/
#define LV_SHADOW_CACHE_SIZE 0
/* Set number of maximally cached circle data.
* The circumference of 1/4 circle are saved for anti-aliasing
* radius * 4 bytes are used per circle (the most often used radiuses are saved)
* 0: to disable caching */
#define LV_CIRCLE_CACHE_SIZE 4
#endif /*LV_DRAW_COMPLEX*/
/*Default image cache size. Image caching keeps the images opened.
*If only the built-in image formats are used there is no real advantage of caching. (I.e. if no new image decoder is added)
*With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
*However the opened images might consume additional RAM.
*0: to disable caching*/
#define LV_IMG_CACHE_DEF_SIZE 0
/*Number of stops allowed per gradient. Increase this to allow more stops.
*This adds (sizeof(lv_color_t) + 1) bytes per additional stop*/
#define LV_GRADIENT_MAX_STOPS 2
/*Default gradient buffer size.
*When LVGL calculates the gradient "maps" it can save them into a cache to avoid calculating them again.
*LV_GRAD_CACHE_DEF_SIZE sets the size of this cache in bytes.
*If the cache is too small the map will be allocated only while it's required for the drawing.
*0 mean no caching.*/
#define LV_GRAD_CACHE_DEF_SIZE 0
/*Allow dithering the gradients (to achieve visual smooth color gradients on limited color depth display)
*LV_DITHER_GRADIENT implies allocating one or two more lines of the object's rendering surface
*The increase in memory consumption is (32 bits * object width) plus 24 bits * object width if using error diffusion */
#define LV_DITHER_GRADIENT 0
#if LV_DITHER_GRADIENT
/*Add support for error diffusion dithering.
*Error diffusion dithering gets a much better visual result, but implies more CPU consumption and memory when drawing.
*The increase in memory consumption is (24 bits * object's width)*/
#define LV_DITHER_ERROR_DIFFUSION 0
#endif
/*Maximum buffer size to allocate for rotation.
*Only used if software rotation is enabled in the display driver.*/
#define LV_DISP_ROT_MAX_BUF (10*1024)
/*-------------
* GPU
*-----------*/
/*Use Arm's 2D acceleration library Arm-2D */
#define LV_USE_GPU_ARM2D 0
/*Use STM32's DMA2D (aka Chrom Art) GPU*/
#define LV_USE_GPU_STM32_DMA2D 0
#if LV_USE_GPU_STM32_DMA2D
/*Must be defined to include path of CMSIS header of target processor
e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
#define LV_GPU_DMA2D_CMSIS_INCLUDE
#endif
/*Use NXP's PXP GPU iMX RTxxx platforms*/
#define LV_USE_GPU_NXP_PXP 0
#if LV_USE_GPU_NXP_PXP
/*1: Add default bare metal and FreeRTOS interrupt handling routines for PXP (lv_gpu_nxp_pxp_osa.c)
* and call lv_gpu_nxp_pxp_init() automatically during lv_init(). Note that symbol SDK_OS_FREE_RTOS
* has to be defined in order to use FreeRTOS OSA, otherwise bare-metal implementation is selected.
*0: lv_gpu_nxp_pxp_init() has to be called manually before lv_init()
*/
#define LV_USE_GPU_NXP_PXP_AUTO_INIT 0
#endif
/*Use NXP's VG-Lite GPU iMX RTxxx platforms*/
#define LV_USE_GPU_NXP_VG_LITE 0
/*Use SDL renderer API*/
#define LV_USE_GPU_SDL 0
#if LV_USE_GPU_SDL
#define LV_GPU_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Texture cache size, 8MB by default*/
#define LV_GPU_SDL_LRU_SIZE (1024 * 1024 * 8)
/*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/
#define LV_GPU_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#endif
/*-------------
* Logging
*-----------*/
/*Enable the log module*/
#define LV_USE_LOG 0
#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_USER Only logs added by the user
*LV_LOG_LEVEL_NONE Do not log anything*/
#define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
/*1: Print the log with 'printf';
*0: User need to register a callback with `lv_log_register_print_cb()`*/
#define LV_LOG_PRINTF 0
/*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
#define LV_LOG_TRACE_MEM 1
#define LV_LOG_TRACE_TIMER 1
#define LV_LOG_TRACE_INDEV 1
#define LV_LOG_TRACE_DISP_REFR 1
#define LV_LOG_TRACE_EVENT 1
#define LV_LOG_TRACE_OBJ_CREATE 1
#define LV_LOG_TRACE_LAYOUT 1
#define LV_LOG_TRACE_ANIM 1
#endif /*LV_USE_LOG*/
/*-------------
* Asserts
*-----------*/
/*Enable asserts if an operation is failed or an invalid data is found.
*If LV_USE_LOG is enabled an error message will be printed on failure*/
#define LV_USE_ASSERT_NULL 1 /*Check if the parameter is NULL. (Very fast, recommended)*/
#define LV_USE_ASSERT_MALLOC 1 /*Checks is the memory is successfully allocated or no. (Very fast, recommended)*/
#define LV_USE_ASSERT_STYLE 0 /*Check if the styles are properly initialized. (Very fast, recommended)*/
#define LV_USE_ASSERT_MEM_INTEGRITY 0 /*Check the integrity of `lv_mem` after critical operations. (Slow)*/
#define LV_USE_ASSERT_OBJ 0 /*Check the object's type and existence (e.g. not deleted). (Slow)*/
/*Add a custom handler when assert happens e.g. to restart the MCU*/
#define LV_ASSERT_HANDLER_INCLUDE <stdint.h>
#define LV_ASSERT_HANDLER while(1); /*Halt by default*/
/*-------------
* Others
*-----------*/
/*1: Show CPU usage and FPS count*/
#define LV_USE_PERF_MONITOR 0
#if LV_USE_PERF_MONITOR
#define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
#endif
/*1: Show the used memory and the memory fragmentation
* Requires LV_MEM_CUSTOM = 0*/
#define LV_USE_MEM_MONITOR 0
#if LV_USE_MEM_MONITOR
#define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#endif
/*1: Draw random colored rectangles over the redrawn areas*/
#define LV_USE_REFR_DEBUG 0
/*Change the built in (v)snprintf functions*/
#define LV_SPRINTF_CUSTOM 0
#if LV_SPRINTF_CUSTOM
#define LV_SPRINTF_INCLUDE <stdio.h>
#define lv_snprintf snprintf
#define lv_vsnprintf vsnprintf
#else /*LV_SPRINTF_CUSTOM*/
#define LV_SPRINTF_USE_FLOAT 0
#endif /*LV_SPRINTF_CUSTOM*/
#define LV_USE_USER_DATA 1
/*Garbage Collector settings
*Used if lvgl is bound to higher level language and the memory is managed by that language*/
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
#define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
#endif /*LV_ENABLE_GC*/
/*=====================
* COMPILER SETTINGS
*====================*/
/*For big endian systems set to 1*/
#define LV_BIG_ENDIAN_SYSTEM 0
/*Define a custom attribute to `lv_tick_inc` function*/
#define LV_ATTRIBUTE_TICK_INC
/*Define a custom attribute to `lv_timer_handler` function*/
#define LV_ATTRIBUTE_TIMER_HANDLER
/*Define a custom attribute to `lv_disp_flush_ready` function*/
#define LV_ATTRIBUTE_FLUSH_READY
/*Required alignment size for buffers*/
#define LV_ATTRIBUTE_MEM_ALIGN_SIZE 1
/*Will be added where memories needs to be aligned (with -Os data might not be aligned to boundary by default).
* E.g. __attribute__((aligned(4)))*/
#define LV_ATTRIBUTE_MEM_ALIGN
/*Attribute to mark large constant arrays for example font's bitmaps*/
#define LV_ATTRIBUTE_LARGE_CONST
/*Compiler prefix for a big array declaration in RAM*/
#define LV_ATTRIBUTE_LARGE_RAM_ARRAY
/*Place performance critical functions into a faster memory (e.g RAM)*/
#define LV_ATTRIBUTE_FAST_MEM
/*Prefix variables that are used in GPU accelerated operations, often these need to be placed in RAM sections that are DMA accessible*/
#define LV_ATTRIBUTE_DMA
/*Export integer constant to binding. This macro is used with constants in the form of LV_<CONST> that
*should also appear on LVGL binding API such as Micropython.*/
#define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning /*The default value just prevents GCC warning*/
/*Extend the default -32k..32k coordinate range to -4M..4M by using int32_t for coordinates instead of int16_t*/
#define LV_USE_LARGE_COORD 0
/*==================
* FONT USAGE
*===================*/
/*Montserrat fonts with ASCII range and some symbols using bpp = 4
*https://fonts.google.com/specimen/Montserrat*/
#define LV_FONT_MONTSERRAT_8 0
#define LV_FONT_MONTSERRAT_10 0
#define LV_FONT_MONTSERRAT_12 1
#define LV_FONT_MONTSERRAT_14 1
#define LV_FONT_MONTSERRAT_16 1
#define LV_FONT_MONTSERRAT_18 0
#define LV_FONT_MONTSERRAT_20 0
#define LV_FONT_MONTSERRAT_22 0
#define LV_FONT_MONTSERRAT_24 0
#define LV_FONT_MONTSERRAT_26 0
#define LV_FONT_MONTSERRAT_28 0
#define LV_FONT_MONTSERRAT_30 0
#define LV_FONT_MONTSERRAT_32 0
#define LV_FONT_MONTSERRAT_34 0
#define LV_FONT_MONTSERRAT_36 0
#define LV_FONT_MONTSERRAT_38 0
#define LV_FONT_MONTSERRAT_40 0
#define LV_FONT_MONTSERRAT_42 0
#define LV_FONT_MONTSERRAT_44 0
#define LV_FONT_MONTSERRAT_46 0
#define LV_FONT_MONTSERRAT_48 0
/*Demonstrate special features*/
#define LV_FONT_MONTSERRAT_12_SUBPX 0
#define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /*bpp = 3*/
#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /*Hebrew, Arabic, Persian letters and all their forms*/
#define LV_FONT_SIMSUN_16_CJK 0 /*1000 most common CJK radicals*/
/*Pixel perfect monospace fonts*/
#define LV_FONT_UNSCII_8 0
#define LV_FONT_UNSCII_16 0
/*Optionally declare custom fonts here.
*You can use these fonts as default font too and they will be available globally.
*E.g. #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) LV_FONT_DECLARE(my_font_2)*/
#define LV_FONT_CUSTOM_DECLARE
/*Always set a default font*/
#define LV_FONT_DEFAULT &lv_font_montserrat_14
/*Enable handling large font and/or fonts with a lot of characters.
*The limit depends on the font size, font face and bpp.
*Compiler error will be triggered if a font needs it.*/
#define LV_FONT_FMT_TXT_LARGE 0
/*Enables/disables support for compressed fonts.*/
#define LV_USE_FONT_COMPRESSED 0
/*Enable subpixel rendering*/
#define LV_USE_FONT_SUBPX 0
#if LV_USE_FONT_SUBPX
/*Set the pixel order of the display. Physical order of RGB channels. Doesn't matter with "normal" fonts.*/
#define LV_FONT_SUBPX_BGR 0 /*0: RGB; 1:BGR order*/
#endif
/*=================
* TEXT SETTINGS
*=================*/
/**
* Select a character encoding for strings.
* Your IDE or editor should have the same character encoding
* - LV_TXT_ENC_UTF8
* - LV_TXT_ENC_ASCII
*/
#define LV_TXT_ENC LV_TXT_ENC_UTF8
/*Can break (wrap) texts on these chars*/
#define LV_TXT_BREAK_CHARS " ,.;:-_"
/*If a word is at least this long, will break wherever "prettiest"
*To disable, set to a value <= 0*/
#define LV_TXT_LINE_BREAK_LONG_LEN 0
/*Minimum number of characters in a long word to put on a line before a break.
*Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3
/*Minimum number of characters in a long word to put on a line after a break.
*Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3
/*The control character to use for signalling text recoloring.*/
#define LV_TXT_COLOR_CMD "#"
/*Support bidirectional texts. Allows mixing Left-to-Right and Right-to-Left texts.
*The direction will be processed according to the Unicode Bidirectional Algorithm:
*https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/
#define LV_USE_BIDI 0
#if LV_USE_BIDI
/*Set the default direction. Supported values:
*`LV_BASE_DIR_LTR` Left-to-Right
*`LV_BASE_DIR_RTL` Right-to-Left
*`LV_BASE_DIR_AUTO` detect texts base direction*/
#define LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_AUTO
#endif
/*Enable Arabic/Persian processing
*In these languages characters should be replaced with an other form based on their position in the text*/
#define LV_USE_ARABIC_PERSIAN_CHARS 0
/*==================
* WIDGET USAGE
*================*/
/*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/
#define LV_USE_ARC 1
#define LV_USE_ANIMIMG 1
#define LV_USE_BAR 1
#define LV_USE_BTN 1
#define LV_USE_BTNMATRIX 1
#define LV_USE_CANVAS 1
#define LV_USE_CHECKBOX 1
#define LV_USE_DROPDOWN 1 /*Requires: lv_label*/
#define LV_USE_IMG 1 /*Requires: lv_label*/
#define LV_USE_LABEL 1
#if LV_USE_LABEL
#define LV_LABEL_TEXT_SELECTION 1 /*Enable selecting text of the label*/
#define LV_LABEL_LONG_TXT_HINT 1 /*Store some extra info in labels to speed up drawing of very long texts*/
#endif
#define LV_USE_LINE 1
#define LV_USE_ROLLER 1 /*Requires: lv_label*/
#if LV_USE_ROLLER
#define LV_ROLLER_INF_PAGES 7 /*Number of extra "pages" when the roller is infinite*/
#endif
#define LV_USE_SLIDER 1 /*Requires: lv_bar*/
#define LV_USE_SWITCH 1
#define LV_USE_TEXTAREA 1 /*Requires: lv_label*/
#if LV_USE_TEXTAREA != 0
#define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
#define LV_USE_TABLE 1
/*==================
* EXTRA COMPONENTS
*==================*/
/*-----------
* Widgets
*----------*/
#define LV_USE_CALENDAR 1
#if LV_USE_CALENDAR
#define LV_CALENDAR_WEEK_STARTS_MONDAY 0
#if LV_CALENDAR_WEEK_STARTS_MONDAY
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}
#else
#define LV_CALENDAR_DEFAULT_DAY_NAMES {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}
#endif
#define LV_CALENDAR_DEFAULT_MONTH_NAMES {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
#define LV_USE_CALENDAR_HEADER_ARROW 1
#define LV_USE_CALENDAR_HEADER_DROPDOWN 1
#endif /*LV_USE_CALENDAR*/
#define LV_USE_CHART 1
#define LV_USE_COLORWHEEL 1
#define LV_USE_IMGBTN 1
#define LV_USE_KEYBOARD 1
#define LV_USE_LED 1
#define LV_USE_LIST 1
#define LV_USE_MENU 1
#define LV_USE_METER 1
#define LV_USE_MSGBOX 1
#define LV_USE_SPINBOX 1
#define LV_USE_SPINNER 1
#define LV_USE_TABVIEW 1
#define LV_USE_TILEVIEW 1
#define LV_USE_WIN 1
#define LV_USE_SPAN 1
#if LV_USE_SPAN
/*A line text can contain maximum num of span descriptor */
#define LV_SPAN_SNIPPET_STACK_SIZE 64
#endif
/*-----------
* Themes
*----------*/
/*A simple, impressive and very complete theme*/
#define LV_USE_THEME_DEFAULT 1
#if LV_USE_THEME_DEFAULT
/*0: Light mode; 1: Dark mode*/
#define LV_THEME_DEFAULT_DARK 0
/*1: Enable grow on press*/
#define LV_THEME_DEFAULT_GROW 1
/*Default transition time in [ms]*/
#define LV_THEME_DEFAULT_TRANSITION_TIME 80
#endif /*LV_USE_THEME_DEFAULT*/
/*A very simple theme that is a good starting point for a custom theme*/
#define LV_USE_THEME_BASIC 1
/*A theme designed for monochrome displays*/
#define LV_USE_THEME_MONO 1
/*-----------
* Layouts
*----------*/
/*A layout similar to Flexbox in CSS.*/
#define LV_USE_FLEX 1
/*A layout similar to Grid in CSS.*/
#define LV_USE_GRID 1
/*---------------------
* 3rd party libraries
*--------------------*/
/*File system interfaces for common APIs */
/*API for fopen, fread, etc*/
#define LV_USE_FS_STDIO 0
#if LV_USE_FS_STDIO
#define LV_FS_STDIO_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_STDIO_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_STDIO_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
/*API for open, read, etc*/
#define LV_USE_FS_POSIX 0
#if LV_USE_FS_POSIX
#define LV_FS_POSIX_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_POSIX_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_POSIX_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
/*API for CreateFile, ReadFile, etc*/
#define LV_USE_FS_WIN32 0
#if LV_USE_FS_WIN32
#define LV_FS_WIN32_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_WIN32_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/
#define LV_FS_WIN32_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
/*API for FATFS (needs to be added separately). Uses f_open, f_read, etc*/
#define LV_USE_FS_FATFS 0
#if LV_USE_FS_FATFS
#define LV_FS_FATFS_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_FATFS_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
/*PNG decoder library*/
#define LV_USE_PNG 0
/*BMP decoder library*/
#define LV_USE_BMP 0
/* JPG + split JPG decoder library.
* Split JPG is a custom format optimized for embedded systems. */
#define LV_USE_SJPG 0
/*GIF decoder library*/
#define LV_USE_GIF 0
/*QR code library*/
#define LV_USE_QRCODE 0
/*FreeType library*/
#define LV_USE_FREETYPE 0
#if LV_USE_FREETYPE
/*Memory used by FreeType to cache characters [bytes] (-1: no caching)*/
#define LV_FREETYPE_CACHE_SIZE (16 * 1024)
#if LV_FREETYPE_CACHE_SIZE >= 0
/* 1: bitmap cache use the sbit cache, 0:bitmap cache use the image cache. */
/* sbit cache:it is much more memory efficient for small bitmaps(font size < 256) */
/* if font size >= 256, must be configured as image cache */
#define LV_FREETYPE_SBIT_CACHE 0
/* Maximum number of opened FT_Face/FT_Size objects managed by this cache instance. */
/* (0:use system defaults) */
#define LV_FREETYPE_CACHE_FT_FACES 0
#define LV_FREETYPE_CACHE_FT_SIZES 0
#endif
#endif
/*Rlottie library*/
#define LV_USE_RLOTTIE 0
/*FFmpeg library for image decoding and playing videos
*Supports all major image formats so do not enable other image decoder with it*/
#define LV_USE_FFMPEG 0
#if LV_USE_FFMPEG
/*Dump input information to stderr*/
#define LV_FFMPEG_AV_DUMP_FORMAT 0
#endif
/*-----------
* Others
*----------*/
/*1: Enable API to take snapshot for object*/
#define LV_USE_SNAPSHOT 0
/*1: Enable Monkey test*/
#define LV_USE_MONKEY 0
/*1: Enable grid navigation*/
#define LV_USE_GRIDNAV 0
/*1: Enable lv_obj fragment*/
#define LV_USE_FRAGMENT 0
/*==================
* EXAMPLES
*==================*/
/*Enable the examples to be built with the library*/
#define LV_BUILD_EXAMPLES 1
/*--END OF LV_CONF_H--*/
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

58
src/lv_demo_conf.h Normal file
View File

@ -0,0 +1,58 @@
/**
* @file lv_demo_conf.h
* Configuration file for v8.1.1-dev
*
*/
/*
* COPY THIS FILE AS lv_demo_conf.h
*/
/* clang-format off */
#if 0 /*Set it to "1" to enable the content*/
#ifndef LV_DEMO_CONF_H
#define LV_DEMO_CONF_H
/*******************
* GENERAL SETTING
*******************/
#define LV_EX_PRINTF 0 /*Enable printf-ing data in demoes and examples*/
#define LV_EX_KEYBOARD 0 /*Add PC keyboard support to some examples (`lv_drivers` repository is required)*/
#define LV_EX_MOUSEWHEEL 0 /*Add 'encoder' (mouse wheel) support to some examples (`lv_drivers` repository is required)*/
/*********************
* DEMO USAGE
*********************/
/*Show some widget*/
#define LV_USE_DEMO_WIDGETS 0
#if LV_USE_DEMO_WIDGETS
#define LV_DEMO_WIDGETS_SLIDESHOW 0
#endif
/*Printer demo, optimized for 800x480*/
#define LV_USE_DEMO_PRINTER 0
/*Demonstrate the usage of encoder and keyboard*/
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0
/*Benchmark your system*/
#define LV_USE_DEMO_BENCHMARK 0
/*Stress test for LVGL*/
#define LV_USE_DEMO_STRESS 0
/*Music player demo*/
#define LV_USE_DEMO_MUSIC 1
#if LV_USE_DEMO_MUSIC
# define LV_DEMO_MUSIC_SQUARE 0
# define LV_DEMO_MUSIC_LANDSCAPE 0
# define LV_DEMO_MUSIC_ROUND 0
# define LV_DEMO_MUSIC_LARGE 0
# define LV_DEMO_MUSIC_AUTO_PLAY 0
#endif
#endif /*LV_DEMO_CONF_H*/
#endif /*End of "Content enable"*/

541
src/main copy Normal file
View File

@ -0,0 +1,541 @@
#include <Arduino.h>
#include <LovyanGFX.hpp>
// ESP32でLovyanGFXを独自設定で利用する場合の設定例
/// 独自の設定を行うクラスを、LGFX_Deviceから派生して作成します。
class LGFX : public lgfx::LGFX_Device
{
/*
クラス名は"LGFX"から別の名前に変更しても構いません。
AUTODETECTと併用する場合は"LGFX"は使用されているため、LGFX以外の名前に変更してください。
また、複数枚のパネルを同時使用する場合もそれぞれに異なる名前を付けてください。
※ クラス名を変更する場合はコンストラクタの名前も併せて同じ名前に変更が必要です。
名前の付け方は自由に決めて構いませんが、設定が増えた場合を想定し、
例えばESP32 DevKit-CでSPI接続のILI9341の設定を行った場合、
LGFX_DevKitC_SPI_ILI9341
のような名前にし、ファイル名とクラス名を一致させておくことで、利用時に迷いにくくなります。
//*/
// 接続するパネルの型にあったインスタンスを用意します。
// lgfx::Panel_GC9A01 _panel_instance;
// lgfx::Panel_GDEW0154M09 _panel_instance;
// lgfx::Panel_HX8357B _panel_instance;
// lgfx::Panel_HX8357D _panel_instance;
// lgfx::Panel_ILI9163 _panel_instance;
// lgfx::Panel_ILI9341 _panel_instance;
// lgfx::Panel_ILI9342 _panel_instance;
// lgfx::Panel_ILI9481 _panel_instance;
// lgfx::Panel_ILI9486 _panel_instance;
// lgfx::Panel_ILI9488 _panel_instance;
// lgfx::Panel_IT8951 _panel_instance;
// lgfx::Panel_RA8875 _panel_instance;
// lgfx::Panel_SH110x _panel_instance; // SH1106, SH1107
// lgfx::Panel_SSD1306 _panel_instance;
// lgfx::Panel_SSD1327 _panel_instance;
// lgfx::Panel_SSD1331 _panel_instance;
// lgfx::Panel_SSD1351 _panel_instance; // SSD1351, SSD1357
// lgfx::Panel_SSD1963 _panel_instance;
// lgfx::Panel_ST7735 _panel_instance;
// lgfx::Panel_ST7735S _panel_instance;
lgfx::Panel_ST7789 _panel_instance;
// lgfx::Panel_ST7796 _panel_instance;
// パネルを接続するバスの種類にあったインスタンスを用意します。
lgfx::Bus_SPI _bus_instance; // SPIバスのインスタンス
// lgfx::Bus_I2C _bus_instance; // I2Cバスのインスタンス
// lgfx::Bus_Parallel8 _bus_instance; // 8ビットパラレルバスのインスタンス
// バックライト制御が可能な場合はインスタンスを用意します。(必要なければ削除)
// lgfx::Light_PWM _light_instance;
// タッチスクリーンの型にあったインスタンスを用意します。(必要なければ削除)
// lgfx::Touch_CST816S _touch_instance;
// lgfx::Touch_FT5x06 _touch_instance; // FT5206, FT5306, FT5406, FT6206, FT6236, FT6336, FT6436
// lgfx::Touch_GSL1680E_800x480 _touch_instance; // GSL_1680E, 1688E, 2681B, 2682B
// lgfx::Touch_GSL1680F_800x480 _touch_instance;
// lgfx::Touch_GSL1680F_480x272 _touch_instance;
// lgfx::Touch_GSLx680_320x320 _touch_instance;
// lgfx::Touch_GT911 _touch_instance;
// lgfx::Touch_STMPE610 _touch_instance;
// lgfx::Touch_TT21xxx _touch_instance; // TT21100
// lgfx::Touch_XPT2046 _touch_instance;
public:
// コンストラクタを作成し、ここで各種設定を行います。
// クラス名を変更した場合はコンストラクタも同じ名前を指定してください。
LGFX(void)
{
{ // バス制御の設定を行います。
auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。
// SPIバスの設定
cfg.spi_host = SPI2_HOST; // 使用するSPIを選択 ESP32-S2,C3 : SPI2_HOST or SPI3_HOST / ESP32 : VSPI_HOST or HSPI_HOST
// ※ ESP-IDFバージョンアップに伴い、VSPI_HOST , HSPI_HOSTの記述は非推奨になるため、エラーが出る場合は代わりにSPI2_HOST , SPI3_HOSTを使用してください。
cfg.spi_mode = 0; // SPI通信モードを設定 (0 ~ 3)
cfg.freq_write = 40000000; // 送信時のSPIクロック (最大80MHz, 80MHzを整数で割った値に丸められます)
cfg.freq_read = 16000000; // 受信時のSPIクロック
cfg.spi_3wire = true; // 受信をMOSIピンで行う場合はtrueを設定
cfg.use_lock = true; // トランザクションロックを使用する場合はtrueを設定
cfg.dma_channel = SPI_DMA_CH_AUTO; // 使用するDMAチャンネルを設定 (0=DMA不使用 / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=自動設定)
// ※ ESP-IDFバージョンアップに伴い、DMAチャンネルはSPI_DMA_CH_AUTO(自動設定)が推奨になりました。1ch,2chの指定は非推奨になります。
cfg.pin_sclk = 2; // SPIのSCLKピン番号を設定
cfg.pin_mosi = 3; // SPIのMOSIピン番号を設定
cfg.pin_miso = -1; // SPIのMISOピン番号を設定 (-1 = disable)
cfg.pin_dc = 8; // SPIのD/Cピン番号を設定 (-1 = disable)
// SDカードと共通のSPIバスを使う場合、MISOは省略せず必ず設定してください。
//*/
/*
// I2Cバスの設定
cfg.i2c_port = 0; // 使用するI2Cポートを選択 (0 or 1)
cfg.freq_write = 400000; // 送信時のクロック
cfg.freq_read = 400000; // 受信時のクロック
cfg.pin_sda = 21; // SDAを接続しているピン番号
cfg.pin_scl = 22; // SCLを接続しているピン番号
cfg.i2c_addr = 0x3C; // I2Cデバイスのアドレス
//*/
/*
// 8ビットパラレルバスの設定
cfg.i2s_port = I2S_NUM_0; // 使用するI2Sポートを選択 (I2S_NUM_0 or I2S_NUM_1) (ESP32のI2S LCDモードを使用します)
cfg.freq_write = 20000000; // 送信クロック (最大20MHz, 80MHzを整数で割った値に丸められます)
cfg.pin_wr = 4; // WR を接続しているピン番号
cfg.pin_rd = 2; // RD を接続しているピン番号
cfg.pin_rs = 15; // RS(D/C)を接続しているピン番号
cfg.pin_d0 = 12; // D0を接続しているピン番号
cfg.pin_d1 = 13; // D1を接続しているピン番号
cfg.pin_d2 = 26; // D2を接続しているピン番号
cfg.pin_d3 = 25; // D3を接続しているピン番号
cfg.pin_d4 = 17; // D4を接続しているピン番号
cfg.pin_d5 = 16; // D5を接続しているピン番号
cfg.pin_d6 = 27; // D6を接続しているピン番号
cfg.pin_d7 = 14; // D7を接続しているピン番号
//*/
_bus_instance.config(cfg); // 設定値をバスに反映します。
_panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。
}
{ // 表示パネル制御の設定を行います。
auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。
cfg.pin_cs = 5; // CSが接続されているピン番号 (-1 = disable)
cfg.pin_rst = 7; // RSTが接続されているピン番号 (-1 = disable)
cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable)
// ※ 以下の設定値はパネル毎に一般的な初期値が設定されていますので、不明な項目はコメントアウトして試してみてください。
cfg.panel_width = 135; // 実際に表示可能な幅
cfg.panel_height = 240; // 実際に表示可能な高さ
cfg.offset_x = 53; // パネルのX方向オフセット量
cfg.offset_y = 40; // パネルのY方向オフセット量
cfg.offset_rotation = 0; // 回転方向の値のオフセット 0~7 (4~7は上下反転)
cfg.dummy_read_pixel = 8; // ピクセル読出し前のダミーリードのビット数
cfg.dummy_read_bits = 1; // ピクセル以外のデータ読出し前のダミーリードのビット数
cfg.readable = true; // データ読出しが可能な場合 trueに設定
cfg.invert = false; // パネルの明暗が反転してしまう場合 trueに設定
cfg.rgb_order = false; // パネルの赤と青が入れ替わってしまう場合 trueに設定
cfg.dlen_16bit = false; // 16bitパラレルやSPIでデータ長を16bit単位で送信するパネルの場合 trueに設定
cfg.bus_shared = true; // SDカードとバスを共有している場合 trueに設定(drawJpgFile等でバス制御を行います)
// 以下はST7735やILI9163のようにピクセル数が可変のドライバで表示がずれる場合にのみ設定してください。
// cfg.memory_width = 240; // ドライバICがサポートしている最大の幅
// cfg.memory_height = 320; // ドライバICがサポートしている最大の高さ
_panel_instance.config(cfg);
}
// //*
// { // バックライト制御の設定を行います。(必要なければ削除)
// auto cfg = _light_instance.config(); // バックライト設定用の構造体を取得します。
// cfg.pin_bl = 32; // バックライトが接続されているピン番号
// 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 = 0; // タッチスクリーンから得られる最小のX値(生の値)
// cfg.x_max = 239; // タッチスクリーンから得られる最大のX値(生の値)
// cfg.y_min = 0; // タッチスクリーンから得られる最小のY値(生の値)
// cfg.y_max = 319; // タッチスクリーンから得られる最大のY値(生の値)
// cfg.pin_int = 38; // INTが接続されているピン番号
// cfg.bus_shared = true; // 画面と共通のバスを使用している場合 trueを設定
// cfg.offset_rotation = 0;// 表示とタッチの向きのが一致しない場合の調整 0~7の値で設定
// // SPI接続の場合
// cfg.spi_host = VSPI_HOST;// 使用するSPIを選択 (HSPI_HOST or VSPI_HOST)
// cfg.freq = 1000000; // SPIクロックを設定
// cfg.pin_sclk = 18; // SCLKが接続されているピン番号
// cfg.pin_mosi = 23; // MOSIが接続されているピン番号
// cfg.pin_miso = 19; // MISOが接続されているピン番号
// cfg.pin_cs = 5; // CSが接続されているピン番号
// // I2C接続の場合
// cfg.i2c_port = 1; // 使用するI2Cを選択 (0 or 1)
// cfg.i2c_addr = 0x38; // I2Cデバイスアドレス番号
// cfg.pin_sda = 23; // SDAが接続されているピン番号
// cfg.pin_scl = 32; // SCLが接続されているピン番号
// cfg.freq = 400000; // I2Cクロックを設定
// _touch_instance.config(cfg);
// _panel_instance.setTouch(&_touch_instance); // タッチスクリーンをパネルにセットします。
// }
// //*/
setPanel(&_panel_instance); // 使用するパネルをセットします。
}
};
// 準備したクラスのインスタンスを作成します。
static LGFX lcd;
static LGFX_Sprite sprite(&lcd);
// void setup(void)
// {
// // SPIバスとパネルの初期化を実行すると使用可能になります。
// display.init();
// display.setTextSize((std::max(display.width(), display.height()) + 255) >> 8);
// // タッチが使用可能な場合のキャリブレーションを行います。(省略可)
// if (display.touch())
// {
// if (display.width() < display.height())
// display.setRotation(display.getRotation() ^ 1);
// // 画面に案内文章を描画します。
// display.setTextDatum(textdatum_t::middle_center);
// display.drawString("touch the arrow marker.", display.width() >> 1, display.height() >> 1);
// display.setTextDatum(textdatum_t::top_left);
// // タッチを使用する場合、キャリブレーションを行います。画面の四隅に表示される矢印の先端を順にタッチしてください。
// std::uint16_t fg = TFT_WHITE;
// std::uint16_t bg = TFT_BLACK;
// if (display.isEPD())
// std::swap(fg, bg);
// display.calibrateTouch(nullptr, fg, bg, std::max(display.width(), display.height()) >> 3);
// }
// display.fillScreen(TFT_BLACK);
// }
// uint32_t count = ~0;
// void loop(void)
// {
// display.startWrite();
// display.setRotation(++count & 7);
// display.setColorDepth((count & 8) ? 16 : 24);
// display.setTextColor(TFT_WHITE);
// display.drawNumber(display.getRotation(), 16, 0);
// display.setTextColor(0xFF0000U);
// display.drawString("R", 30, 16);
// display.setTextColor(0x00FF00U);
// display.drawString("G", 40, 16);
// display.setTextColor(0x0000FFU);
// display.drawString("B", 50, 16);
// display.drawRect(30, 30, display.width() - 60, display.height() - 60, count * 7);
// display.drawFastHLine(0, 0, 10);
// display.endWrite();
// int32_t x, y;
// if (display.getTouch(&x, &y))
// {
// display.fillRect(x - 2, y - 2, 5, 5, count * 7);
// }
// }
void setup(void)
{
// 最初に初期化関数を呼び出します。
lcd.init();
// 回転方向を 03 の4方向から設定します。(47を使用すると上下反転になります。)
lcd.setRotation(1);
// バックライトの輝度を 0255 の範囲で設定します。
lcd.setBrightness(128);
// 必要に応じてカラーモードを設定します。初期値は16
// 16の方がSPI通信量が少なく高速に動作しますが、赤と青の諧調が5bitになります。
// 24の方がSPI通信量が多くなりますが、諧調表現が綺麗になります。
//lcd.setColorDepth(16); // RGB565の16ビットに設定
lcd.setColorDepth(24); // RGB888の24ビットに設定(表示される色数はパネル性能によりRGB666の18ビットになります)
// 基本的な図形の描画関数は以下の通りです。
/*
fillScreen ( color); // 画面全体の塗り潰し
drawPixel ( x, y , color); // 点
drawFastVLine ( x, y , h , color); // 垂直線
drawFastHLine ( x, y, w , color); // 水平線
drawRect ( x, y, w, h , color); // 矩形の外周
fillRect ( x, y, w, h , color); // 矩形の塗り
drawRoundRect ( x, y, w, h, r, color); // 角丸の矩形の外周
fillRoundRect ( x, y, w, h, r, color); // 角丸の矩形の塗り
drawCircle ( x, y , r, color); // 円の外周
fillCircle ( x, y , r, color); // 円の塗り
drawEllipse ( x, y, rx, ry , color); // 楕円の外周
fillEllipse ( x, y, rx, ry , color); // 楕円の塗り
drawLine ( x0, y0, x1, y1 , color); // 2点間の直線
drawTriangle ( x0, y0, x1, y1, x2, y2, color); // 3点間の三角形の外周
fillTriangle ( x0, y0, x1, y1, x2, y2, color); // 3点間の三角形の塗り
drawBezier ( x0, y0, x1, y1, x2, y2, color); // 3点間のベジエ曲線
drawBezier ( x0, y0, x1, y1, x2, y2, x3, y3, color); // 4点間のベジエ曲線
drawArc ( x, y, r0, r1, angle0, angle1, color); // 円弧の外周
fillArc ( x, y, r0, r1, angle0, angle1, color); // 円弧の塗り
*/
// 例えばdrawPixelで点を書く場合は、引数は X座標,Y座標,色 の3つ。
lcd.drawPixel(0, 0, 0xFFFF); // 座標0:0に白の点を描画
// カラーコードを生成する関数が用意されており、色の指定に使用できます。
// 引数は、赤,緑,青をそれぞれ 0255で指定します。
// 色情報の欠落を防ぐため、color888を使う事を推奨します。
lcd.drawFastVLine(2, 0, 100, lcd.color888(255, 0, 0)); // 赤で垂直の線を描画
lcd.drawFastVLine(4, 0, 100, lcd.color565( 0, 255, 0)); // 緑で垂直の線を描画
lcd.drawFastVLine(6, 0, 100, lcd.color332( 0, 0, 255)); // 青で垂直の線を描画
// カラーコード生成関数を使用しない場合は以下のようになります。
// RGB888 24ビットで指定 uint32_t型
// RGB565 16ビットで指定 uint16_t型、int32_t型
// RGB332 8ビットで指定 uint8_t型
// uint32_t型を使用すると、RGB888の24ビットとして扱われます。
// 16進数2桁で赤緑青の順に記述できます。
// uint32_t型の変数を使うか、末尾にUを付けるか、uint32_t型にキャストして使用します。
uint32_t red = 0xFF0000;
lcd.drawFastHLine(0, 2, 100, red); // 赤で水平の線を描画
lcd.drawFastHLine(0, 4, 100, 0x00FF00U); // 緑で水平の線を描画
lcd.drawFastHLine(0, 6, 100, (uint32_t)0xFF); // 青で水平の線を描画
// uint16_t型およびint32_t型を使用すると、RGB565の16ビットとして扱われます。
// 特別な書き方をしない場合はint32_t型として扱われるので、この方式になります。
// AdafruitGFX や TFT_eSPI との互換性のために、このようにしています。)
uint16_t green = 0x07E0;
lcd.drawRect(10, 10, 50, 50, 0xF800); // 赤で矩形の外周を描画
lcd.drawRect(12, 12, 50, 50, green); // 緑で矩形の外周を描画
lcd.drawRect(14, 14, 50, 50, (uint16_t)0x1F); // 青で矩形の外周を描画
// int8_t型、uint8_t型を使用すると、RGB332の8ビットとして扱われます。
uint8_t blue = 0x03;
lcd.fillRect(20, 20, 20, 20, (uint8_t)0xE0); // 赤で矩形の塗りを描画
lcd.fillRect(30, 30, 20, 20, (uint8_t)0x1C); // 緑で矩形の塗りを描画
lcd.fillRect(40, 40, 20, 20, blue); // 青で矩形の塗りを描画
// 描画関数の引数の色は省略できます。
// 省略した場合、setColor関数で設定した色 または最後に使用した色を描画色として使用します。
// 同じ色で繰り返し描画する場合は、省略した方がわずかに速く動作します。
lcd.setColor(0xFF0000U); // 描画色に赤色を指定
lcd.fillCircle ( 40, 80, 20 ); // 赤色で円の塗り
lcd.fillEllipse( 80, 40, 10, 20); // 赤色で楕円の塗り
lcd.fillArc ( 80, 80, 20, 10, 0, 90); // 赤色で円弧の塗り
lcd.fillTriangle(80, 80, 60, 80, 80, 60); // 赤色で三角の塗り
lcd.setColor(0x0000FFU); // 描画色に青色を指定
lcd.drawCircle ( 40, 80, 20 ); // 青色で円の外周
lcd.drawEllipse( 80, 40, 10, 20); // 青色で楕円の外周
lcd.drawArc ( 80, 80, 20, 10, 0, 90); // 青色で円弧の外周
lcd.drawTriangle(60, 80, 80, 80, 80, 60); // 青色で三角の外周
lcd.setColor(0x00FF00U); // 描画色に緑色を指定
lcd.drawBezier( 60, 80, 80, 80, 80, 60); // 緑色で二次ベジエ曲線
lcd.drawBezier( 60, 80, 80, 20, 20, 80, 80, 60);// 緑色で三次ベジエ曲線
// グラデーションの線を描画するdrawGradientLine は色の指定を省略できません。
lcd.drawGradientLine( 0, 80, 80, 0, 0xFF0000U, 0x0000FFU);// 赤から青へのグラデーション直線
delay(1000);
// clearまたはfillScreenで画面全体を塗り潰せます。
// fillScreenはfillRectの画面全体を指定したのと同じで、色の指定は描画色の扱いになります。
lcd.fillScreen(0xFFFFFFu); // 白で塗り潰し
lcd.setColor(0x00FF00u); // 描画色に緑色を指定
lcd.fillScreen(); // 緑で塗り潰し
// clearは描画系の関数とは別で背景色という扱いで色を保持しています。
// 背景色は出番が少ないですが、スクロール機能使用時の隙間を塗る色としても使用されます。
lcd.clear(0xFFFFFFu); // 背景色に白を指定して塗り潰し
lcd.setBaseColor(0x000000u);// 背景色に黒を指定
lcd.clear(); // 黒で塗り潰し
// SPIバスの確保と解放は描画関数を呼び出した時に自動的に行われますが、
// 描画スピードを重視する場合は、描画処理の前後に startWriteとendWriteを使用します。
// SPIバスの確保と解放が抑制され、速度が向上します。
// 電子ペーパー(EPD)の場合、startWrite()以降の描画は、endWrite()を呼ぶ事で画面に反映されます。
lcd.drawLine(0, 1, 39, 40, red); // SPIバス確保、線を描画、SPIバス解放
lcd.drawLine(1, 0, 40, 39, blue); // SPIバス確保、線を描画、SPIバス解放
lcd.startWrite(); // SPIバス確保
lcd.drawLine(38, 0, 0, 38, 0xFFFF00U); // 線を描画
lcd.drawLine(39, 1, 1, 39, 0xFF00FFU); // 線を描画