diff --git a/.github/workflows/PlatformioBuild.yml b/.github/workflows/PlatformioBuild.yml index 18fdb7c7..c9a758f3 100644 --- a/.github/workflows/PlatformioBuild.yml +++ b/.github/workflows/PlatformioBuild.yml @@ -32,13 +32,15 @@ jobs: - m5stick-c - m5stack-core-esp32 - m5stack-core2 + - m5stack-cores3 platform-version: - 1.0.6 - - 2.0.4 + #- 2.0.4 - 2.0.5 - 2.0.6 - 2.0.7 + - 2.0.8 - default exclude: @@ -46,6 +48,7 @@ jobs: - { board: esp32-s3, platform-version: 1.0.6 } - { board: esp32-s3, platform-version: default } # 2.0.5 => esp32s3/include/newlib/platform_include/assert.h:20:10: fatal error: sdkconfig.h: No such file or directory - { board: esp32-s2, platform-version: 1.0.6 } + - { board: m5stack-cores3, platform-version: 1.0.6 } include: - board: esp32 @@ -55,6 +58,7 @@ jobs: - board: m5stick-c - board: m5stack-core-esp32 - board: m5stack-core2 + - board: m5stack-cores3 - { board: esp8266, platform-version: 3.0.0, ... } - { board: esp8266, platform-version: 3.1.0, ... } - { board: esp8266, platform-version: 3.2.0, ... } @@ -96,5 +100,7 @@ jobs: run: | cd ${{ env.PROJECT_DIR }} - pio pkg install -e ${{ matrix.board }}@${{ matrix.platform-version }} --no-save --library file://$(realpath ../../../) - pio run -e ${{ matrix.board }}@${{ matrix.platform-version }} + export pio_ver=${{ matrix.platform-version }} + export pio_env="${pio_ver//./_}" + pio pkg install -e ${{ matrix.board }}-$pio_env --no-save --library file://$(realpath ../../../) + pio run -e ${{ matrix.board }}-$pio_env diff --git a/.github/workflows/issues-auto-closer.yml b/.github/workflows/issues-auto-closer.yml index f6da5afc..bc766f34 100644 --- a/.github/workflows/issues-auto-closer.yml +++ b/.github/workflows/issues-auto-closer.yml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Automatically close issues that do not follow the issue template uses: lucasbento/auto-close-issues@v1.0.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} - issue-close-message: "@${issue.user.login}: hello! :wave:\n\nThis issue is being automatically closed because it does not follow the issue template." # optional property + issue-close-message: "Hello! :wave:\n\nThis issue is being automatically closed because it does not follow the issue template." # optional property closed-issues-label: "🙁 Not following issue template" # optional property diff --git a/examples/Test/build_test/platformio_atmelsam.ini b/examples/Test/build_test/platformio_atmelsam.ini index b6ab6dac..16e4b499 100644 --- a/examples/Test/build_test/platformio_atmelsam.ini +++ b/examples/Test/build_test/platformio_atmelsam.ini @@ -5,11 +5,11 @@ platform = atmelsam [env:seeed_wio_terminal] [env:adafruit_pybadge_m4] -[env:seeed_wio_terminal@default] +[env:seeed_wio_terminal-default] platform = ${atmelsam_default.platform} board = seeed_wio_terminal -[env:adafruit_pybadge_m4@default] +[env:adafruit_pybadge_m4-default] platform = ${atmelsam_default.platform} board = adafruit_pybadge_m4 build_src_flags = diff --git a/examples/Test/build_test/platformio_esp32.ini b/examples/Test/build_test/platformio_esp32.ini index 489a4000..b77081c2 100644 --- a/examples/Test/build_test/platformio_esp32.ini +++ b/examples/Test/build_test/platformio_esp32.ini @@ -50,7 +50,10 @@ build_flags = ${coding_standards.build_flags} platform = https://github.com/tasmota/platform-espressif32 platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32/releases/download/2.0.7/esp32-2.0.7.zip build_flags = ${coding_standards.build_flags} - +[esp32_2_0_8] +platform = https://github.com/tasmota/platform-espressif32 +platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32/releases/download/2.0.8/esp32-2.0.8.zip +build_flags = ${coding_standards.build_flags} @@ -68,6 +71,18 @@ board = m5stick-c board = m5stack-core-esp32 [M5Core2] board = m5stack-core2 +[M5CoreS3] +board = esp32-s3-devkitc-1 +board_upload.flash_size = 16MB +board_upload.maximum_size = 16777216 +board_build.partitions = default_16MB.csv +board_build.arduino.memory_type = qio_qspi +build_flags = + ${env.build_flags} + -DARDUINO_M5STACK_CORES3 + -DBOARD_HAS_PSRAM + -DARDUINO_UDB_MODE=1 + [esp32c3] board = esp32dev board_build.mcu = esp32c3 @@ -87,143 +102,167 @@ board_build.mcu = esp32s3 [env:m5stick-c] [env:m5stack-core-esp32] [env:m5stack-core2] +[env:m5stack-cores3] [env:esp32-s2] [env:esp32-s3] [env:esp32-c3] -[env:esp32@1.0.6] +[env:m5stack-cores3-2_0_5] +extends = M5CoreS3, esp32_2_0_5 +[env:m5stack-cores3-2_0_6] +extends = M5CoreS3, esp32_2_0_6 +[env:m5stack-cores3-2_0_7] +extends = M5CoreS3, esp32_2_0_7 +[env:m5stack-cores3-2_0_8] +extends = M5CoreS3, esp32_2_0_8 +[env:m5stack-cores3-default] +extends = M5CoreS3, esp32_2_0_8 + + +[env:esp32-1_0_6] extends = esp32, esp32_1_0_6 board = esp32dev -[env:esp32@2.0.0] +[env:esp32-2_0_0] extends = esp32, esp32_2_0_0 -[env:esp32@2.0.1] +[env:esp32-2_0_1] extends = esp32, esp32_2_0_1 -[env:esp32@2.0.2] +[env:esp32-2_0_2] extends = esp32, esp32_2_0_2 -[env:esp32@2.0.3] +[env:esp32-2_0_3] extends = esp32, esp32_2_0_3 -[env:esp32@2.0.4] +[env:esp32-2_0_4] extends = esp32, esp32_2_0_4 -[env:esp32@2.0.5] +[env:esp32-2_0_5] extends = esp32, esp32_2_0_5 -[env:esp32@2.0.6] +[env:esp32-2_0_6] extends = esp32, esp32_2_0_6 -[env:esp32@2.0.7] +[env:esp32-2_0_7] extends = esp32, esp32_2_0_7 - - -[env:esp32@default] +[env:esp32-2_0_8] +extends = esp32, esp32_2_0_8 +[env:esp32-default] extends = esp32, esp32_default -[env:m5stick-c@1.0.6] +[env:m5stick-c-1_0_6] extends = M5StickC, esp32_1_0_6 -[env:m5stick-c@2.0.0] +[env:m5stick-c-2_0_0] extends = M5StickC, esp32_2_0_0 -[env:m5stick-c@2.0.1] +[env:m5stick-c-2_0_1] extends = M5StickC, esp32_2_0_1 -[env:m5stick-c@2.0.2] +[env:m5stick-c-2_0_2] extends = M5StickC, esp32_2_0_2 -[env:m5stick-c@2.0.3] +[env:m5stick-c-2_0_3] extends = M5StickC, esp32_2_0_3 -[env:m5stick-c@2.0.4] +[env:m5stick-c-2_0_4] extends = esp32, esp32_2_0_4 -[env:m5stick-c@2.0.5] +[env:m5stick-c-2_0_5] extends = esp32, esp32_2_0_5 -[env:m5stick-c@2.0.6] +[env:m5stick-c-2_0_6] extends = esp32, esp32_2_0_6 -[env:m5stick-c@2.0.7] +[env:m5stick-c-2_0_7] extends = esp32, esp32_2_0_7 -[env:m5stick-c@default] +[env:m5stick-c-2_0_8] +extends = esp32, esp32_2_0_8 +[env:m5stick-c-default] extends = M5StickC, esp32_default -[env:m5stack-core-esp32@1.0.6] +[env:m5stack-core-esp32-1_0_6] extends = M5Stack, esp32_1_0_6 -[env:m5stack-core-esp32@2.0.0] +[env:m5stack-core-esp32-2_0_0] extends = M5Stack, esp32_2_0_0 -[env:m5stack-core-esp32@2.0.1] +[env:m5stack-core-esp32-2_0_1] extends = M5Stack, esp32_2_0_1 -[env:m5stack-core-esp32@2.0.2] +[env:m5stack-core-esp32-2_0_2] extends = M5Stack, esp32_2_0_2 -[env:m5stack-core-esp32@2.0.3] +[env:m5stack-core-esp32-2_0_3] extends = M5Stack, esp32_2_0_3 -[env:m5stack-core-esp32@2.0.4] +[env:m5stack-core-esp32-2_0_4] extends = esp32, esp32_2_0_4 -[env:m5stack-core-esp32@2.0.5] +[env:m5stack-core-esp32-2_0_5] extends = esp32, esp32_2_0_5 -[env:m5stack-core-esp32@2.0.6] +[env:m5stack-core-esp32-2_0_6] extends = esp32, esp32_2_0_6 -[env:m5stack-core-esp32@2.0.7] +[env:m5stack-core-esp32-2_0_7] extends = esp32, esp32_2_0_7 -[env:m5stack-core-esp32@default] +[env:m5stack-core-esp32-2_0_8] +extends = esp32, esp32_2_0_8 +[env:m5stack-core-esp32-default] extends = M5Stack, esp32_default -[env:m5stack-core2@1.0.6] +[env:m5stack-core2-1_0_6] extends = M5Core2, esp32_1_0_6 -[env:m5stack-core2@2.0.0] +[env:m5stack-core2-2_0_0] extends = M5Core2, esp32_2_0_0 -[env:m5stack-core2@2.0.1] +[env:m5stack-core2-2_0_1] extends = M5Core2, esp32_2_0_1 -[env:m5stack-core2@2.0.2] +[env:m5stack-core2-2_0_2] extends = M5Core2, esp32_2_0_2 -[env:m5stack-core2@2.0.3] +[env:m5stack-core2-2_0_3] extends = M5Core2, esp32_2_0_3 -[env:m5stack-core2@2.0.4] +[env:m5stack-core2-2_0_4] extends = esp32, esp32_2_0_4 -[env:m5stack-core2@2.0.5] +[env:m5stack-core2-2_0_5] extends = esp32, esp32_2_0_5 -[env:m5stack-core2@2.0.6] +[env:m5stack-core2-2_0_6] extends = esp32, esp32_2_0_6 -[env:m5stack-core2@2.0.7] +[env:m5stack-core2-2_0_7] extends = esp32, esp32_2_0_7 -[env:m5stack-core2@default] +[env:m5stack-core2-2_0_8] +extends = esp32, esp32_2_0_8 +[env:m5stack-core2-default] extends = M5Core2, esp32_default - -[env:esp32-c3@2.0.1] +[env:esp32-c3-2_0_1] extends = esp32c3, esp32_2_0_1 -[env:esp32-c3@2.0.2] +[env:esp32-c3-2_0_2] extends = esp32c3, esp32_2_0_2 -[env:esp32-c3@2.0.3] +[env:esp32-c3-2_0_3] extends = esp32c3, esp32_2_0_3 -[env:esp32-c3@2.0.4] +[env:esp32-c3-2_0_4] extends = esp32c3, esp32_2_0_4 -[env:esp32-c3@2.0.5] +[env:esp32-c3-2_0_5] extends = esp32c3, esp32_2_0_5 -[env:esp32-c3@2.0.6] +[env:esp32-c3-2_0_6] extends = esp32c3, esp32_2_0_6 -[env:esp32-c3@2.0.7] +[env:esp32-c3-2_0_7] extends = esp32c3, esp32_2_0_7 -[env:esp32-c3@default] +[env:esp32-c3-2_0_8] +extends = esp32c3, esp32_2_0_8 +[env:esp32-c3-default] extends = esp32c3, esp32_default -[env:esp32-s2@2.0.1] +[env:esp32-s2-2_0_1] extends = esp32s2, esp32_2_0_1 -[env:esp32-s2@2.0.2] +[env:esp32-s2-2_0_2] extends = esp32s2, esp32_2_0_2 -[env:esp32-s2@2.0.3] +[env:esp32-s2-2_0_3] extends = esp32s2, esp32_2_0_3 -[env:esp32-s2@2.0.4] +[env:esp32-s2-2_0_4] extends = esp32, esp32_2_0_4 -[env:esp32-s2@2.0.5] +[env:esp32-s2-2_0_5] extends = esp32, esp32_2_0_5 -[env:esp32-s2@2.0.6] +[env:esp32-s2-2_0_6] extends = esp32, esp32_2_0_6 -[env:esp32-s2@2.0.7] +[env:esp32-s2-2_0_7] extends = esp32, esp32_2_0_7 -[env:esp32-s2@default] +[env:esp32-s2-2_0_8] +extends = esp32, esp32_2_0_8 +[env:esp32-s2-default] extends = esp32s2, esp32_default -[env:esp32-s3@2.0.3] +[env:esp32-s3-2_0_3] extends = esp32s3, esp32_2_0_3 -[env:esp32-s3@2.0.4] +[env:esp32-s3-2_0_4] extends = esp32, esp32_2_0_4 -[env:esp32-s3@2.0.5] +[env:esp32-s3-2_0_5] extends = esp32, esp32_2_0_5 -[env:esp32-s3@2.0.6] +[env:esp32-s3-2_0_6] extends = esp32, esp32_2_0_6 -[env:esp32-s3@2.0.7] +[env:esp32-s3-2_0_7] extends = esp32, esp32_2_0_7 -[env:esp32-s3@default] +[env:esp32-s3-2_0_8] +extends = esp32, esp32_2_0_8 +[env:esp32-s3-default] extends = esp32s3, esp32_default diff --git a/examples/Test/build_test/platformio_esp8266.ini b/examples/Test/build_test/platformio_esp8266.ini index c6e71f0e..a4c5289a 100644 --- a/examples/Test/build_test/platformio_esp8266.ini +++ b/examples/Test/build_test/platformio_esp8266.ini @@ -14,15 +14,15 @@ platform = espressif8266@3.2.0 [env:esp8266] -[env:esp8266@3.0.0] +[env:esp8266-3_0_0] platform = ${esp8266_3_0_0.platform} board = d1_mini -[env:esp8266@3.1.0] +[env:esp8266-3_1_0] platform = ${esp8266_3_1_0.platform} board = d1_mini -[env:esp8266@3.2.0] +[env:esp8266-3_2_0] platform = ${esp8266_3_2_0.platform} board = d1_mini diff --git a/examples/Test/build_test/platformio_rpipico.ini b/examples/Test/build_test/platformio_rpipico.ini index 39092cd7..4b5cf0c7 100644 --- a/examples/Test/build_test/platformio_rpipico.ini +++ b/examples/Test/build_test/platformio_rpipico.ini @@ -7,7 +7,7 @@ board_build.core = earlephilhower -[env:pico@default] +[env:pico-default] extends = rpipico_default build_flags = -DDUMMY_DISPLAY diff --git a/library.json b/library.json index 3016463a..139bafa0 100644 --- a/library.json +++ b/library.json @@ -11,7 +11,7 @@ "type": "git", "url": "https://github.com/lovyan03/LovyanGFX.git" }, - "version": "1.1.6", + "version": "1.1.7", "frameworks": ["arduino", "espidf"], "platforms": ["espressif32", "espressif8266", "atmelsam"], "headers": "LovyanGFX.hpp", diff --git a/library.properties b/library.properties index 31613ff2..510299d8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=LovyanGFX -version=1.1.6 +version=1.1.7 author=lovyan03 maintainer=lovyan03 sentence=TFT LCD Graphics driver with touch for ESP32, ESP8266, SAMD21, SAMD51, RP2040 diff --git a/src/lgfx/v1/LGFXBase.cpp b/src/lgfx/v1/LGFXBase.cpp index d256796e..11cb7ab2 100644 --- a/src/lgfx/v1/LGFXBase.cpp +++ b/src/lgfx/v1/LGFXBase.cpp @@ -927,16 +927,15 @@ namespace lgfx if (r1x < 0) return; if (r1y < 0) return; - bool equal = fabsf(start - end) < std::numeric_limits::epsilon(); + bool ring = fabsf(start - end) >= 360; start = fmodf(start, 360); end = fmodf(end, 360); - if (start < 0) start += 360.0f; - if (end < 0) end += 360.0f; - + if (start < 0.0f) start = fmodf(start + 360.0f, 360); + if (end < 0.0f) end = fmodf(end + 360.0f, 360); startWrite(); fill_arc_helper(x, y, r0x, r1x, r0y, r1y, start, start); fill_arc_helper(x, y, r0x, r1x, r0y, r1y, end, end); - if (!equal && (fabsf(start - end) <= 0.0001f)) { start = .0f; end = 360.0f; } + if (ring && (fabsf(start - end) <= 0.0001f)) { start = .0f; end = 360.0f; } fill_arc_helper(x, y, r0x, r0x, r0y, r0y, start, end); fill_arc_helper(x, y, r1x, r1x, r1y, r1y, start, end); endWrite(); @@ -949,12 +948,12 @@ namespace lgfx if (r1x < 0) return; if (r1y < 0) return; - bool equal = fabsf(start - end) < std::numeric_limits::epsilon(); + bool ring = fabsf(start - end) >= 360; start = fmodf(start, 360); end = fmodf(end, 360); - if (start < 0) start += 360.0f; - if (end < 0) end += 360.0f; - if (!equal && (fabsf(start - end) <= 0.0001f)) { start = .0f; end = 360.0f; } + if (start < 0.0f) start = fmodf(start + 360.0f, 360); + if (end < 0.0f) end = fmodf(end + 360.0f, 360); + if (ring && (fabsf(start - end) <= 0.0001f)) { start = .0f; end = 360.0f; } startWrite(); fill_arc_helper(x, y, r0x, r1x, r0y, r1y, start, end); diff --git a/src/lgfx/v1/gitTagVersion.h b/src/lgfx/v1/gitTagVersion.h index b71455a0..36d68a09 100644 --- a/src/lgfx/v1/gitTagVersion.h +++ b/src/lgfx/v1/gitTagVersion.h @@ -1,4 +1,4 @@ #define LGFX_VERSION_MAJOR 1 #define LGFX_VERSION_MINOR 1 -#define LGFX_VERSION_PATCH 6 +#define LGFX_VERSION_PATCH 7 #define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH ) diff --git a/src/lgfx/v1/lgfx_filesystem_support.hpp b/src/lgfx/v1/lgfx_filesystem_support.hpp index c31c911f..bae6e0fa 100644 --- a/src/lgfx/v1/lgfx_filesystem_support.hpp +++ b/src/lgfx/v1/lgfx_filesystem_support.hpp @@ -61,7 +61,7 @@ namespace lgfx #if defined (FS_H) || defined (__SEEED_FS__) || defined (__LITTLEFS_H) || defined (_LiffleFS_H_) || defined (SDFS_H) /// load vlw fontdata from filesystem. - void loadFont(const char *path, fs::FS &fs + bool loadFont(const char *path, fs::FS &fs #if defined (_SD_H_) = SD #elif defined (_SPIFFS_H_) @@ -74,13 +74,13 @@ namespace lgfx ) { init_font_file(fs); - load_font_with_path(path); + return load_font_with_path(path); } - void loadFont(fs::FS &fs, const char *path) + bool loadFont(fs::FS &fs, const char *path) { init_font_file(fs); - load_font_with_path(path); + return load_font_with_path(path); } #define LGFX_FUNCTION_GENERATOR(drawImg, draw_img) \ @@ -142,16 +142,16 @@ namespace lgfx #if defined (__STORAGE_H__) // for SPRESENSE /// load vlw fontdata from filesystem. - void loadFont(const char *path, StorageClass &fs) + bool loadFont(const char *path, StorageClass &fs) { init_font_file(fs); - load_font_with_path(path); + return load_font_with_path(path); } - void loadFont(StorageClass &fs, const char *path) + bool loadFont(StorageClass &fs, const char *path) { init_font_file(fs); - load_font_with_path(path); + return load_font_with_path(path); } #define LGFX_FUNCTION_GENERATOR(drawImg, draw_img) \ @@ -217,16 +217,16 @@ namespace lgfx #define LGFX_SDFAT_TYPE SdBase #endif - void loadFont(const char *path, LGFX_SDFAT_TYPE &fs) + bool loadFont(const char *path, LGFX_SDFAT_TYPE &fs) { init_font_file(fs); - load_font_with_path(path); + return load_font_with_path(path); } - void loadFont(LGFX_SDFAT_TYPE &fs, const char *path) + bool loadFont(LGFX_SDFAT_TYPE &fs, const char *path) { init_font_file(fs); - load_font_with_path(path); + return load_font_with_path(path); } #define LGFX_FUNCTION_GENERATOR(drawImg, draw_img) \ @@ -372,10 +372,10 @@ namespace lgfx return drawJpgFile(path, x, y, maxWidth, maxHeight, offX, offY, 1.0f / (1 << scale)); } - void loadFont(const char *path) + bool loadFont(const char *path) { init_font_file(); - load_font_with_path(path); + return load_font_with_path(path); } #endif diff --git a/src/lgfx/v1/panel/Panel_GC9A01.hpp b/src/lgfx/v1/panel/Panel_GC9A01.hpp index 41a2902e..7b137ae7 100644 --- a/src/lgfx/v1/panel/Panel_GC9A01.hpp +++ b/src/lgfx/v1/panel/Panel_GC9A01.hpp @@ -83,6 +83,10 @@ namespace lgfx _cfg.panel_height = _cfg.memory_height = 240; _cfg.dummy_read_pixel = 16; + + // GC9A01 malfunctions when sending NOP. + // Therefore, the function to send a NOP at the end of communication should be disabled. + _nop_closing = false; } protected: diff --git a/src/lgfx/v1/panel/Panel_LCD.cpp b/src/lgfx/v1/panel/Panel_LCD.cpp index d5a4437e..2d9fe907 100644 --- a/src/lgfx/v1/panel/Panel_LCD.cpp +++ b/src/lgfx/v1/panel/Panel_LCD.cpp @@ -33,6 +33,14 @@ namespace lgfx return false; } + // pin_csが設定されておらずバスタイプがi2cでない場合は、 + // トランザクション終了時にnopを送信する。 + // これによってSPIバスをSDカード等と共有が可能となる。 + // ※ _nop_closingがtrueであることをチェックしている理由は、 + // 派生クラス側でこの機能を無効化できるようにするため。 + // 具体的には、GC9A01はNOPを受信すると誤動作を起こすため無効化する必要がある。 + _nop_closing = _nop_closing && (_cfg.pin_cs < 0) && (_bus->busType() != bus_type_t::bus_i2c); + startWrite(true); for (uint8_t i = 0; auto cmds = getInitCommands(i); i++) @@ -72,7 +80,7 @@ namespace lgfx _bus->writeData(0, 8); } - if (_cfg.pin_cs < 0 && _bus->busType() != bus_type_t::bus_i2c) + if (_nop_closing) { write_command(_cmd_nop); // NOP command } diff --git a/src/lgfx/v1/panel/Panel_LCD.hpp b/src/lgfx/v1/panel/Panel_LCD.hpp index cb3febca..1a6724c3 100644 --- a/src/lgfx/v1/panel/Panel_LCD.hpp +++ b/src/lgfx/v1/panel/Panel_LCD.hpp @@ -62,6 +62,7 @@ namespace lgfx bool _in_transaction = false; uint8_t _cmd_nop = CMD_NOP; uint8_t _cmd_ramrd = CMD_RAMRD; + bool _nop_closing = true; // トランザクション終了時にnopを送るか否か enum mad_t { MAD_MY = 0x80 diff --git a/src/lgfx/v1/panel/Panel_M5HDMI.cpp b/src/lgfx/v1/panel/Panel_M5HDMI.cpp index 615b84cc..f06859a8 100644 --- a/src/lgfx/v1/panel/Panel_M5HDMI.cpp +++ b/src/lgfx/v1/panel/Panel_M5HDMI.cpp @@ -463,6 +463,24 @@ namespace lgfx gpio_num_t _pin_num; }; + uint32_t Panel_M5HDMI::_read_fpga_id(void) + { + startWrite(); + _bus->writeData(CMD_NOP, 32); + endWrite(); + _bus->writeData(CMD_NOP, 32); + startWrite(); + _bus->writeData(CMD_READ_ID, 8); // READ_ID + _bus->beginRead(); + uint32_t retry = 16; + while (_bus->readData(8) == 0xFF && --retry) {} + _bus->readData(8); // skip 0xFF + uint32_t fpga_id = _bus->readData(32); + endWrite(); + ESP_LOGI(TAG, "FPGA ID:%08x", (int)__builtin_bswap32(fpga_id)); + return fpga_id; + } + bool Panel_M5HDMI::init(bool use_reset) { ESP_LOGI(TAG, "i2c port:%d sda:%d scl:%d", _HDMI_Trans_config.i2c_port, _HDMI_Trans_config.pin_sda, _HDMI_Trans_config.pin_scl); @@ -481,42 +499,43 @@ namespace lgfx ESP_LOGI(TAG, "Resetting HDMI transmitter..."); driver.reset(); + if (!Panel_Device::init(false)) { return false; } + + if ((_read_fpga_id() & 0xFFFF) != ('H' | 'D' << 8)) { auto bus_cfg = reinterpret_cast(_bus)->config(); _pin_backup_t backup_pins[] = { (gpio_num_t)bus_cfg.pin_sclk, (gpio_num_t)bus_cfg.pin_mosi, (gpio_num_t)bus_cfg.pin_miso }; LOAD_FPGA fpga(bus_cfg.pin_sclk, bus_cfg.pin_mosi, bus_cfg.pin_miso, _cfg.pin_cs); for (auto &bup : backup_pins) { bup.restore(); } - } - if (!Panel_Device::init(false)) { return false; } - // Initialize and read ID - ESP_LOGI(TAG, "Waiting the FPGA gets idle..."); - startWrite(); - _bus->beginRead(); - while (_bus->readData(8) != 0xFF) {} - endWrite(); - uint32_t fpga_id = ~0u; + // Initialize and read ID + ESP_LOGI(TAG, "Waiting the FPGA gets idle..."); + startWrite(); + _bus->beginRead(); + _bus->readData(32); + uint32_t retry = 1024; + do { + lgfx::delay(10); + } while ((0xFFFFFFFFu != _bus->readData(32)) && --retry); + endWrite(); + + if (retry == 0) { + ESP_LOGW(TAG, "Waiting for FPGA idle timed out."); + return false; + } + } uint32_t apbfreq = lgfx::getApbFrequency(); uint_fast8_t div_write = apbfreq / (_bus->getClock() + 1) + 1; uint_fast8_t div_read = apbfreq / (_bus->getReadClock() + 1) + 1; - for (;;) + uint32_t retry = 8; + do { // ESP_LOGI(TAG, "FREQ:%lu , %lu DIV_W:%lu , %lu", _bus->getClock(), _bus->getReadClock(), div_write, div_read); - startWrite(); - _bus->writeData(CMD_READ_ID, 8); // READ_ID - _bus->beginRead(); - while (_bus->readData(8) == 0xFF) {} - _bus->readData(8); // skip 0xFF - fpga_id = _bus->readData(32); - endWrite(); - - ESP_LOGI(TAG, "FPGA ID:%02x %02x %02x %02x", (uint8_t)fpga_id, (uint8_t)(fpga_id >> 8), (uint8_t)(fpga_id >> 16), (uint8_t)(fpga_id >> 24)); - + uint32_t fpga_id = _read_fpga_id(); // 受信したIDの先頭が "HD" なら正常動作 - if (((fpga_id ) & 0xFF) == 'H' - && ((fpga_id >> 8) & 0xFF) == 'D') + if ((fpga_id & 0xFFFF) == ('H' | 'D' << 8)) { break; } @@ -529,6 +548,11 @@ namespace lgfx { // 受信データの先頭が HD でない場合は受信速度を下げる。 _bus->setReadClock(apbfreq / ++div_read); } + } while (--retry); + + if (retry == 0) { + ESP_LOGW(TAG, "read FPGA ID failed."); + return false; } startWrite(); @@ -538,7 +562,7 @@ namespace lgfx ESP_LOGI(TAG, "Initialize HDMI transmitter..."); if (!driver.init() ) { - ESP_LOGI(TAG, "failed."); + ESP_LOGW(TAG, "HDMI transmitter Initialize failed."); return false; } @@ -659,14 +683,13 @@ namespace lgfx setScaling(_scale_w, _scale_h); _set_video_clock(&vc); - if (!res) { - // ESP_LOGI(TAG, "PLL feedback_div:%d input_div:%d output_div:%d OUTPUT_CLOCK:%ld", vc.feedback_divider, vc.input_divider, vc.output_divider, OUTPUT_CLOCK); - ESP_LOGI(TAG, "logical resolution: w:%d h:%d", _cfg.panel_width, _cfg.panel_height); - ESP_LOGI(TAG, "scaling resolution: w:%d h:%d", _cfg.panel_width * _scale_w, _cfg.panel_height * _scale_h); - ESP_LOGI(TAG, " output resolution: w:%d h:%d", _cfg.memory_width, _cfg.memory_height); - ESP_LOGI(TAG, "video timing(Hori) total:%d active:%d frontporch:%d sync:%d backporch:%d", vt.h.active + vt.h.front_porch + vt.h.sync + vt.h.back_porch, vt.h.active, vt.h.front_porch, vt.h.sync, vt.h.back_porch); - ESP_LOGI(TAG, "video timing(Vert) total:%d active:%d frontporch:%d sync:%d backporch:%d", vt.v.active + vt.v.front_porch + vt.v.sync + vt.v.back_porch, vt.v.active, vt.v.front_porch, vt.v.sync, vt.v.back_porch); + ESP_LOGD(TAG, "PLL feedback_div:%d input_div:%d output_div:%d OUTPUT_CLOCK:%d", vc.feedback_divider, vc.input_divider, vc.output_divider, (int)OUTPUT_CLOCK); + ESP_LOGD(TAG, "logical resolution: w:%d h:%d", _cfg.panel_width, _cfg.panel_height); + ESP_LOGD(TAG, "scaling resolution: w:%d h:%d", _cfg.panel_width * _scale_w, _cfg.panel_height * _scale_h); + ESP_LOGD(TAG, " output resolution: w:%d h:%d", _cfg.memory_width, _cfg.memory_height); + ESP_LOGD(TAG, "video timing(Hori) total:%d active:%d frontporch:%d sync:%d backporch:%d", vt.h.active + vt.h.front_porch + vt.h.sync + vt.h.back_porch, vt.h.active, vt.h.front_porch, vt.h.sync, vt.h.back_porch); + ESP_LOGD(TAG, "video timing(Vert) total:%d active:%d frontporch:%d sync:%d backporch:%d", vt.v.active + vt.v.front_porch + vt.v.sync + vt.v.back_porch, vt.v.active, vt.v.front_porch, vt.v.sync, vt.v.back_porch); } return res; diff --git a/src/lgfx/v1/panel/Panel_M5HDMI.hpp b/src/lgfx/v1/panel/Panel_M5HDMI.hpp index 069ada4f..9ff48edb 100644 --- a/src/lgfx/v1/panel/Panel_M5HDMI.hpp +++ b/src/lgfx/v1/panel/Panel_M5HDMI.hpp @@ -300,6 +300,7 @@ namespace lgfx void _set_video_timing(const video_timing_t::info_t* param, uint8_t cmd); void _set_video_clock(const video_clock_t* param); void _copy_rect(uint32_t dst_xy, uint32_t src_xy, uint32_t wh); + uint32_t _read_fpga_id(void); }; //---------------------------------------------------------------------------- diff --git a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp index 24ef5001..7d18754e 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp +++ b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.cpp @@ -113,17 +113,6 @@ namespace lgfx void Bus_Parallel8::_init_pin(void) { - int8_t pins[] = - { _cfg.pin_d0 - , _cfg.pin_d1 - , _cfg.pin_d2 - , _cfg.pin_d3 - , _cfg.pin_d4 - , _cfg.pin_d5 - , _cfg.pin_d6 - , _cfg.pin_d7 - }; - #if defined (CONFIG_IDF_TARGET_ESP32S2) auto idx_base = I2S0O_DATA_OUT8_IDX; #else @@ -131,22 +120,21 @@ namespace lgfx #endif for (size_t i = 0; i < 8; ++i) { - gpio_pad_select_gpio(pins[i]); - gpio_set_direction((gpio_num_t)pins[i], GPIO_MODE_INPUT_OUTPUT); - gpio_matrix_out(pins[i], idx_base + i, 0, 0); + int32_t pin = _cfg.pin_data[i]; + if (pin < 0) { continue; } + gpio_pad_select_gpio(pin); + gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT_OUTPUT); + gpio_matrix_out(pin, idx_base + i, 0, 0); } - gpio_pad_select_gpio(_cfg.pin_rd); - gpio_pad_select_gpio(_cfg.pin_wr); - gpio_pad_select_gpio(_cfg.pin_rs); - - gpio_hi(_cfg.pin_rd); - gpio_hi(_cfg.pin_wr); - gpio_hi(_cfg.pin_rs); - - gpio_set_direction((gpio_num_t)_cfg.pin_rd, GPIO_MODE_OUTPUT); - gpio_set_direction((gpio_num_t)_cfg.pin_wr, GPIO_MODE_OUTPUT); - gpio_set_direction((gpio_num_t)_cfg.pin_rs, GPIO_MODE_OUTPUT); + for (size_t i = 0; i < 3; ++i) + { + int32_t pin = _cfg.pin_ctrl[i]; + if (pin < 0) { continue; } + gpio_pad_select_gpio(pin); + gpio_hi(pin); + gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT); + } gpio_matrix_out(_cfg.pin_rs, idx_base + 8, 0, 0); diff --git a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp index abd1cc9e..96757d93 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp +++ b/src/lgfx/v1/platforms/esp32/Bus_Parallel8.hpp @@ -17,10 +17,10 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#if __has_include() - #include -#else +#if __has_include() #include +#else + #include #endif #if __has_include() @@ -51,9 +51,16 @@ namespace lgfx // max 20MHz , 16MHz , 13.3MHz , 11.43MHz , 10MHz , 8.9MHz and more ... uint32_t freq_write = 16000000; - int8_t pin_wr = -1; - int8_t pin_rd = -1; - int8_t pin_rs = -1; // D/C + union + { + int8_t pin_ctrl[3] = { -1, -1, -1 }; + struct + { + int8_t pin_rd; + int8_t pin_wr; + int8_t pin_rs; // D/C + }; + }; union { int8_t pin_data[8]; diff --git a/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp b/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp index df0cd897..a61e009a 100644 --- a/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp +++ b/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp @@ -19,10 +19,16 @@ Original Source: #include -#if __has_include() - #include -#else +#if defined (CONFIG_IDF_TARGET_ESP32S3) && __has_include() + #include +#elif defined (CONFIG_IDF_TARGET_ESP32S2) && __has_include() + #include +#elif defined (CONFIG_IDF_TARGET_ESP32C3) && __has_include() + #include +#elif __has_include() #include +#else + #include #endif #if __has_include() diff --git a/src/lgfx/v1/platforms/esp32/Panel_CVBS.cpp b/src/lgfx/v1/platforms/esp32/Panel_CVBS.cpp index 1d5cc7a9..bff093ce 100644 --- a/src/lgfx/v1/platforms/esp32/Panel_CVBS.cpp +++ b/src/lgfx/v1/platforms/esp32/Panel_CVBS.cpp @@ -29,11 +29,16 @@ Inspiration Sources: #include #include #include -#include #include #include #include +#if __has_include() + #include +#else + #include +#endif + #if __has_include() #include #endif diff --git a/src/lgfx/v1/platforms/esp32/common.cpp b/src/lgfx/v1/platforms/esp32/common.cpp index ceddcb16..9be2387a 100644 --- a/src/lgfx/v1/platforms/esp32/common.cpp +++ b/src/lgfx/v1/platforms/esp32/common.cpp @@ -1128,7 +1128,7 @@ namespace lgfx res = i2c_wait(i2c_port); if (res.has_error()) { - ESP_LOGD("LGFX", "i2c write error : ack wait"); + ESP_LOGV("LGFX", "i2c write error : ack wait"); break; } size_t idx = 0; @@ -1175,7 +1175,7 @@ namespace lgfx res = i2c_wait(i2c_port); if (res.has_error()) { - ESP_LOGD("LGFX", "i2c read error : ack wait"); + ESP_LOGV("LGFX", "i2c read error : ack wait"); break; } @@ -1236,7 +1236,7 @@ namespace lgfx { cpp::result res; if ((res = beginTransaction(i2c_port, addr, freq, true)).has_value() - && (res = readBytes(i2c_port, readdata, readlen)).has_value() + && (res = readBytes(i2c_port, readdata, readlen, true)).has_value() ) { res = endTransaction(i2c_port); @@ -1250,7 +1250,7 @@ namespace lgfx if ((res = beginTransaction(i2c_port, addr, freq, false)).has_value() && (res = writeBytes(i2c_port, writedata, writelen)).has_value() && (res = restart(i2c_port, addr, freq, true)).has_value() - && (res = readBytes(i2c_port, readdata, readlen)).has_value() + && (res = readBytes(i2c_port, readdata, readlen, true)).has_value() ) { res = endTransaction(i2c_port); diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.cpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.cpp index 5ae377dd..3c08ff4a 100644 --- a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.cpp +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.cpp @@ -79,23 +79,18 @@ namespace lgfx ; } - static void _gpio_pin_init(int pin) + bool Bus_Parallel16::init(void) { - if (pin >= 0) + _init_pin(); + + for (size_t i = 0; i < 3; ++i) { + int32_t pin = _cfg.pin_ctrl[i]; + if (pin < 0) { continue; } gpio_pad_select_gpio(pin); gpio_hi(pin); gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT); } - } - - bool Bus_Parallel16::init(void) - { - _init_pin(); - - _gpio_pin_init(_cfg.pin_rd); - _gpio_pin_init(_cfg.pin_wr); - _gpio_pin_init(_cfg.pin_rs); auto idx_base = I2S0O_DATA_OUT8_IDX; diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.hpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.hpp index 85ef6439..c085c6fd 100644 --- a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.hpp +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel16.hpp @@ -17,10 +17,10 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#if __has_include() - #include -#else +#if __has_include() #include +#else + #include #endif #if __has_include() @@ -56,9 +56,16 @@ namespace lgfx // max 40MHz , 27MHz , 20MHz , 16MHz , 13.3MHz , 11.43MHz , 10MHz , 8.9MHz and more ... uint32_t freq_write = 16000000; - int8_t pin_wr = -1; - int8_t pin_rd = -1; - int8_t pin_rs = -1; // D/C + union + { + int8_t pin_ctrl[3] = { -1, -1, -1 }; + struct + { + int8_t pin_rd; + int8_t pin_wr; + int8_t pin_rs; // D/C + }; + }; union { int8_t pin_data[16]; diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.cpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.cpp index 7987a6bc..2fdeacce 100644 --- a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.cpp +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.cpp @@ -79,23 +79,18 @@ namespace lgfx ; } - static void _gpio_pin_init(int pin) + bool Bus_Parallel8::init(void) { - if (pin >= 0) + _init_pin(); + + for (size_t i = 0; i < 3; ++i) { + int32_t pin = _cfg.pin_ctrl[i]; + if (pin < 0) { continue; } gpio_pad_select_gpio(pin); gpio_hi(pin); gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT); } - } - - bool Bus_Parallel8::init(void) - { - _init_pin(); - - _gpio_pin_init(_cfg.pin_rd); - _gpio_pin_init(_cfg.pin_wr); - _gpio_pin_init(_cfg.pin_rs); auto idx_base = I2S0O_DATA_OUT15_IDX; diff --git a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.hpp b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.hpp index 894e467b..00485caa 100644 --- a/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.hpp +++ b/src/lgfx/v1/platforms/esp32s2/Bus_Parallel8.hpp @@ -17,10 +17,10 @@ Original Source: /----------------------------------------------------------------------------*/ #pragma once -#if __has_include() - #include -#else +#if __has_include() #include +#else + #include #endif #if __has_include() @@ -56,9 +56,16 @@ namespace lgfx // max 40MHz , 27MHz , 20MHz , 16MHz , 13.3MHz , 11.43MHz , 10MHz , 8.9MHz and more ... uint32_t freq_write = 16000000; - int8_t pin_wr = -1; - int8_t pin_rd = -1; - int8_t pin_rs = -1; // D/C + union + { + int8_t pin_ctrl[3] = { -1, -1, -1 }; + struct + { + int8_t pin_rd; + int8_t pin_wr; + int8_t pin_rs; // D/C + }; + }; union { int8_t pin_data[8]; diff --git a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.cpp b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.cpp index 3ef5eac9..a5e9bf43 100644 --- a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.cpp +++ b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.cpp @@ -60,23 +60,18 @@ namespace lgfx _dev = getDev(port); } - static void _gpio_pin_init(int pin) + bool Bus_Parallel16::init(void) { - if (pin >= 0) + _init_pin(); + + for (size_t i = 0; i < 3; ++i) { + int32_t pin = _cfg.pin_ctrl[i]; + if (pin < 0) { continue; } gpio_pad_select_gpio(pin); gpio_hi(pin); gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT); } - } - - bool Bus_Parallel16::init(void) - { - _init_pin(); - - _gpio_pin_init(_cfg.pin_rd); - _gpio_pin_init(_cfg.pin_wr); - _gpio_pin_init(_cfg.pin_rs); gpio_matrix_out(_cfg.pin_rs, LCD_DC_IDX, 0, 0); gpio_matrix_out(_cfg.pin_wr, LCD_PCLK_IDX, 0, 0); diff --git a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.hpp b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.hpp index 5f888bf4..120c3884 100644 --- a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.hpp +++ b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.hpp @@ -44,9 +44,16 @@ namespace lgfx // max 40MHz. uint32_t freq_write = 16000000; uint32_t freq_read = 8000000; - int8_t pin_wr = -1; - int8_t pin_rd = -1; - int8_t pin_rs = -1; // D/C + union + { + int8_t pin_ctrl[3] = { -1, -1, -1 }; + struct + { + int8_t pin_rd; + int8_t pin_wr; + int8_t pin_rs; // D/C + }; + }; union { int8_t pin_data[16]; diff --git a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.cpp b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.cpp index dd497372..d694fd5f 100644 --- a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.cpp +++ b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.cpp @@ -60,23 +60,18 @@ namespace lgfx _dev = getDev(port); } - static void _gpio_pin_init(int pin) + bool Bus_Parallel8::init(void) { - if (pin >= 0) + _init_pin(); + + for (size_t i = 0; i < 3; ++i) { + int32_t pin = _cfg.pin_ctrl[i]; + if (pin < 0) { continue; } gpio_pad_select_gpio(pin); gpio_hi(pin); gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT); } - } - - bool Bus_Parallel8::init(void) - { - _init_pin(); - - _gpio_pin_init(_cfg.pin_rd); - _gpio_pin_init(_cfg.pin_wr); - _gpio_pin_init(_cfg.pin_rs); gpio_matrix_out(_cfg.pin_rs, LCD_DC_IDX, 0, 0); gpio_matrix_out(_cfg.pin_wr, LCD_PCLK_IDX, 0, 0); diff --git a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.hpp b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.hpp index 05ecebef..e5f32a20 100644 --- a/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.hpp +++ b/src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.hpp @@ -44,9 +44,16 @@ namespace lgfx // max 80MHz. uint32_t freq_write = 16000000; uint32_t freq_read = 8000000; - int8_t pin_wr = -1; - int8_t pin_rd = -1; - int8_t pin_rs = -1; // D/C + union + { + int8_t pin_ctrl[3] = { -1, -1, -1 }; + struct + { + int8_t pin_rd; + int8_t pin_wr; + int8_t pin_rs; // D/C + }; + }; union { int8_t pin_data[8]; diff --git a/src/lgfx/v1/touch/Touch_CST816S.cpp b/src/lgfx/v1/touch/Touch_CST816S.cpp new file mode 100644 index 00000000..0fe8ebac --- /dev/null +++ b/src/lgfx/v1/touch/Touch_CST816S.cpp @@ -0,0 +1,162 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ + +// CST816 info from here... +// https://github.com/lupyuen/hynitron_i2c_cst0xxse/blob/master/cst0xx_common.h +// https://blog.csdn.net/Distance_98/article/details/126408819 + +#include "Touch_CST816S.hpp" + +#include "../platforms/common.hpp" + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + static constexpr uint8_t CST816S_TOUCH_REG = 0x01; + static constexpr uint8_t CST816S_SLEEP_REG = 0xA5; + static constexpr uint8_t CST816S_CHIPID_REG = 0xA7; + + static constexpr uint8_t CST816S_SLEEP_IN = 0x03; + + bool Touch_CST816S::_write_reg(uint8_t reg, uint8_t val) + { + return i2c::writeRegister8(_cfg.i2c_port, _cfg.i2c_addr, reg, val, 0, _cfg.freq).has_value(); + } + + bool Touch_CST816S::_write_regs(uint8_t* val, size_t length) + { + return i2c::transactionWrite(_cfg.i2c_port, _cfg.i2c_addr, val, length, _cfg.freq).has_value(); + } + + bool Touch_CST816S::_read_reg(uint8_t reg, uint8_t *data, size_t length) + { + return lgfx::i2c::transactionWriteRead(_cfg.i2c_port, _cfg.i2c_addr, ®, 1, data, length, _cfg.freq).has_value(); + } + + bool Touch_CST816S::_check_init(void) + { + if (_inited) return true; + + uint8_t tmp[3] = { 0 }; + _inited = _write_reg(0x00, 0x00) + && _read_reg(CST816S_CHIPID_REG, tmp, 3); + // _write_reg(0xFA, 0b00000101); // レジスタ0xFAはINTピンの動作設定に関与すると思われる。 +// ESP_LOGV("LGFX","CST816S id:%02x %02x %02x", tmp[0], tmp[1], tmp[2]); + return _inited; + } + +//---------------------------------------------------------------------------- + bool Touch_CST816S::init(void) + { + _inited = false; + + if (_cfg.pin_rst >= 0) + { + lgfx::pinMode(_cfg.pin_rst, pin_mode_t::output); + lgfx::gpio_lo(_cfg.pin_rst); + lgfx::delay(10); + lgfx::gpio_hi(_cfg.pin_rst); + lgfx::delay(10); + } + + if (_cfg.pin_int >= 0) + { // intピンのプルアップ処理を行うが、「触れている間 LOW」の設定方法が不明のため、このピンを使用していない。 + // GPIO割込みを使用すれば良いが、Arduinoに依存せず解決する必要があるため、対応を保留する。 + lgfx::pinMode(_cfg.pin_int, pin_mode_t::input_pullup); + } + lgfx::i2c::init(_cfg.i2c_port, _cfg.pin_sda, _cfg.pin_scl).has_value(); + + // 画面に触れていない時、I2C通信でCST816が見つからない事がある。 + // CST816S の正確な仕様を確認することができていないが恐らく省電力モード中は通信応答しないものと思われる。 + // 通信の成否による初期化の成否の判定ができないため、ひとまず true を返す。 + return true; + } + + // void Touch_CST816S::wakeup(void) + // { + // } + + // void Touch_CST816S::sleep(void) + // { + // if (!_check_init()) return; + // // _write_reg(CST816S_SLEEP_REG, CST816S_SLEEP_IN); + // } + + size_t Touch_CST816S::_read_data(uint8_t* readdata) + { + size_t res = 0; + if (lgfx::i2c::beginTransaction(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq, false)) + { + readdata[0] = 0x02; + if (lgfx::i2c::writeBytes(_cfg.i2c_port, readdata, 1) + && lgfx::i2c::restart(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq, true) + && lgfx::i2c::readBytes(_cfg.i2c_port, readdata, 1)) + { + uint_fast8_t points = std::min(max_touch_points, readdata[0] & 0x0Fu); + if (points) + { + if (lgfx::i2c::readBytes(_cfg.i2c_port, &readdata[1], points * 6 - 2)) + { + res = points * 6 - 1; + } + } + else + { + res = 1; + } + } + lgfx::i2c::endTransaction(_cfg.i2c_port).has_value(); + } + return res; + } + + uint_fast8_t Touch_CST816S::getTouchRaw(touch_point_t *tp, uint_fast8_t count) + { + if (!_inited && !_check_init()) return 0; + + if (count > max_touch_points) { count = max_touch_points; } + + uint8_t readdata[8]; + int retry = 3; + do + { + if (!_read_reg(0x02, readdata, 6)) + { + return 0; + } + count = readdata[0]; + } while ((count > 1 || readdata[5] != 0x10) && --retry); + if (retry && count) + { + // ESP_LOGV("CST816S", "%02x %02x %02x %02x %02x %02x %02x %02x %d %d", + // readdata[0], readdata[1], readdata[2], readdata[3], + // readdata[4], readdata[5], readdata[6], readdata[7], _inited, lgfx::gpio_in(_cfg.pin_int)); + tp[0].id = 0; + tp[0].size = 1; + tp[0].x = readdata[2] | (readdata[1] & 0x0F) << 8; + tp[0].y = readdata[4] | (readdata[3] & 0x0F) << 8; + } + return count; + } + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1/touch/Touch_CST816S.hpp b/src/lgfx/v1/touch/Touch_CST816S.hpp new file mode 100644 index 00000000..af973a2c --- /dev/null +++ b/src/lgfx/v1/touch/Touch_CST816S.hpp @@ -0,0 +1,72 @@ +/*----------------------------------------------------------------------------/ + Lovyan GFX - Graphics library for embedded devices. + +Original Source: + https://github.com/lovyan03/LovyanGFX/ + +Licence: + [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) + +Author: + [lovyan03](https://twitter.com/lovyan03) + +Contributors: + [ciniml](https://github.com/ciniml) + [mongonta0716](https://github.com/mongonta0716) + [tobozo](https://github.com/tobozo) +/----------------------------------------------------------------------------*/ +#pragma once + +#include "../Touch.hpp" + +namespace lgfx +{ + inline namespace v1 + { +//---------------------------------------------------------------------------- + + struct Touch_CST816S : public ITouch + { + enum CS816S_GESTURE { + NONE = 0x00, + SWIPE_UP = 0x01, + SWIPE_DOWN = 0x02, + SWIPE_LEFT = 0x03, + SWIPE_RIGHT = 0x04, + SINGLE_CLICK = 0x05, + DOUBLE_CLICK = 0x0B, + LONG_PRESS = 0x0C + }; + + Touch_CST816S(void) + { + _cfg.i2c_addr = 0x15; + _cfg.x_min = 0; + _cfg.x_max = 320; + _cfg.y_min = 0; + _cfg.y_max = 320; + } + + bool init(void) override; + + // void wakeup(void) override; + // void sleep(void) override; + + uint_fast8_t getTouchRaw(touch_point_t* tp, uint_fast8_t count) override; + + private: + enum + { + max_touch_points = 1 + }; + + bool _check_init(void); + bool _write_reg(uint8_t reg, uint8_t val); + bool _write_regs(uint8_t* val, size_t length); + bool _read_reg(uint8_t reg, uint8_t *data, size_t length); + size_t _read_data(uint8_t* data); + }; + +//---------------------------------------------------------------------------- + } +} diff --git a/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32.hpp b/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32.hpp deleted file mode 100644 index e4ff1b38..00000000 --- a/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32.hpp +++ /dev/null @@ -1,1835 +0,0 @@ -/*----------------------------------------------------------------------------/ - Lovyan GFX - Graphics library for embedded devices. - -Original Source: - https://github.com/lovyan03/LovyanGFX/ - -Licence: - [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) - -Author: - [lovyan03](https://twitter.com/lovyan03) - -Contributors: - [ciniml](https://github.com/ciniml) - [mongonta0716](https://github.com/mongonta0716) - [tobozo](https://github.com/tobozo) -/----------------------------------------------------------------------------*/ -#pragma once - -#include "../v1_init.hpp" -#include "common.hpp" - -#include -#include -#include -#include -#include - - -#if defined( ARDUINO_M5Stack_Core_ESP32 ) || defined( ARDUINO_M5STACK_FIRE ) - #define LGFX_M5STACK -#elif defined( ARDUINO_M5STACK_Core2 ) // M5Stack Core2 - #define LGFX_M5STACK_CORE2 -#elif defined( ARDUINO_M5Stick_C ) // M5Stick C / CPlus - #define LGFX_M5STICK_C -#elif defined( ARDUINO_M5Stick_C_Plus ) - #define LGFX_M5STICK_C -#elif defined( ARDUINO_M5Stack_CoreInk ) // M5Stack CoreInk - #define LGFX_M5STACK_COREINK -#elif defined( ARDUINO_M5STACK_Paper ) // M5Paper - #define LGFX_M5PAPER -#elif defined ( ARDUINO_M5STACK_TOUGH ) - #define LGFX_M5TOUGH -#elif defined( ARDUINO_ODROID_ESP32 ) // ODROID-GO - #define LGFX_ODROID_GO -#elif defined( ARDUINO_TTGO_T1 ) // TTGO TS - #define LGFX_TTGO_TS -#elif defined( ARDUINO_TWatch ) || defined( ARDUINO_T ) // TTGO T-Watch - #define LGFX_TTGO_TWATCH -#elif defined( ARDUINO_D ) || defined( ARDUINO_DDUINO32_XS ) // DSTIKE D-duino-32 XS - #define LGFX_DDUINO32_XS -#elif defined( ARDUINO_LOLIN_D32_PRO ) - #define LGFX_LOLIN_D32_PRO -#elif defined( ARDUINO_ESP32_WROVER_KIT ) - #define LGFX_ESP_WROVER_KIT -#endif - - -namespace lgfx -{ - inline namespace v1 - { -//---------------------------------------------------------------------------- - - static constexpr char LIBRARY_NAME[] = "LovyanGFX"; - - struct Light_TWatch : public lgfx::Light_PWM - { - /// TTGO T-Watchはモデルチェンジでバックライトの仕様が何度か変更されている。; - /// 2019 : GPIO12 - /// 2020 v1 : GPIO12 & AXP202 LDO2 - /// 2020 v2 : GPIO25 & AXP202 LDO2 - /// 2020 v3 : GPIO15 & AXP202 LDO2 - /// これらに対応するため、GPIO12をPWM制御しつつ、AXP202のLDO2も併せて制御する方式とする。; - - static constexpr int32_t axp_i2c_freq = 400000; - static constexpr int_fast16_t axp_i2c_addr = 0x35; // axp202 addr - static constexpr int_fast16_t axp_i2c_port = I2C_NUM_0; - static constexpr int_fast16_t axp_i2c_sda = GPIO_NUM_21; - static constexpr int_fast16_t axp_i2c_scl = GPIO_NUM_22; - - bool init(uint8_t brightness) override - { - lgfx::i2c::init(axp_i2c_port, axp_i2c_sda, axp_i2c_scl).has_value(); - auto cfg = config(); - cfg.pin_bl = GPIO_NUM_12; - cfg.freq = 1200; - cfg.pwm_channel = 7; - cfg.invert = false; - config(cfg); - bool res = lgfx::Light_PWM::init(brightness); - setBrightness(brightness); - return res; - } - - void setBrightness(uint8_t brightness) override - { - lgfx::Light_PWM::setBrightness(brightness); - if (brightness) - { - if (brightness > 4) - { - brightness = (brightness / 24) + 5; - } - lgfx::i2c::bitOn(axp_i2c_port, axp_i2c_addr, 0x12, 0x04, axp_i2c_freq); // LDO2 enable - } - else - { - lgfx::i2c::bitOff(axp_i2c_port, axp_i2c_addr, 0x12, 0x04, axp_i2c_freq); // LDO2 disable - } - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x28, brightness<<4, 0x0F, axp_i2c_freq); - } - }; - - namespace m5stack - { - static constexpr int32_t axp_i2c_freq = 400000; - static constexpr uint_fast8_t axp_i2c_addr = 0x34; - static constexpr int_fast16_t axp_i2c_port = I2C_NUM_1; - static constexpr int_fast16_t axp_i2c_sda = GPIO_NUM_21; - static constexpr int_fast16_t axp_i2c_scl = GPIO_NUM_22; - } - - struct Panel_M5Stack : public lgfx::Panel_ILI9342 - { - Panel_M5Stack(void) - { - _cfg.pin_cs = GPIO_NUM_14; - _cfg.pin_rst = GPIO_NUM_33; - _cfg.offset_rotation = 3; - - _rotation = 1; - } - - bool init(bool use_reset) override - { - lgfx::gpio_hi(_cfg.pin_rst); - lgfx::pinMode(_cfg.pin_rst, lgfx::pin_mode_t::input_pulldown); - _cfg.invert = lgfx::gpio_in(_cfg.pin_rst); // get panel type (IPS or TN) - lgfx::pinMode(_cfg.pin_rst, lgfx::pin_mode_t::output); - - return lgfx::Panel_ILI9342::init(use_reset); - } - }; - - struct Panel_M5StackCore2 : public lgfx::Panel_ILI9342 - { - Panel_M5StackCore2(void) - { - _cfg.pin_cs = GPIO_NUM_5; - _cfg.invert = true; - _cfg.offset_rotation = 3; - - _rotation = 1; // default rotation - } - - void reset(void) override - { - using namespace m5stack; - // AXP192 reg 0x96 = GPIO3&4 control - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0, ~0x02, axp_i2c_freq); // GPIO4 LOW (LCD RST) - lgfx::delay(4); - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 2, ~0x00, axp_i2c_freq); // GPIO4 HIGH (LCD RST) - } - }; - - struct Light_M5StackCore2 : public lgfx::ILight - { - bool init(uint8_t brightness) override - { - setBrightness(brightness); - return true; - } - - void setBrightness(uint8_t brightness) override - { - using namespace m5stack; - - if (brightness) - { - brightness = (brightness >> 3) + 72; - lgfx::i2c::bitOn(axp_i2c_port, axp_i2c_addr, 0x12, 0x02, axp_i2c_freq); // DC3 enable - } - else - { - lgfx::i2c::bitOff(axp_i2c_port, axp_i2c_addr, 0x12, 0x02, axp_i2c_freq); // DC3 disable - } - // AXP192 reg 0x27 = DC3 - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x27, brightness, 0x80, axp_i2c_freq); - } - }; - - struct Light_M5Tough : public lgfx::ILight - { - bool init(uint8_t brightness) override - { - setBrightness(brightness); - return true; - } - - void setBrightness(uint8_t brightness) override - { - using namespace m5stack; - - if (brightness) - { - if (brightness > 4) - { - brightness = (brightness / 24) + 5; - } - lgfx::i2c::bitOn(axp_i2c_port, axp_i2c_addr, 0x12, 0x08, axp_i2c_freq); // LDO3 enable - } - else - { - lgfx::i2c::bitOff(axp_i2c_port, axp_i2c_addr, 0x12, 0x08, axp_i2c_freq); // LDO3 disable - } - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x28, brightness, 0xF0, axp_i2c_freq); - } - }; - - struct Touch_M5Tough : public lgfx::ITouch - { - Touch_M5Tough(void) - { - _cfg.x_min = 0; - _cfg.x_max = 319; - _cfg.y_min = 0; - _cfg.y_max = 239; - } - - void wakeup(void) override {} - void sleep(void) override {} - - bool init(void) override - { - _inited = false; - if (isSPI()) return false; - - if (_cfg.pin_int >= 0) - { - lgfx::pinMode(_cfg.pin_int, pin_mode_t::input_pullup); - } - _inited = lgfx::i2c::init(_cfg.i2c_port, _cfg.pin_sda, _cfg.pin_scl).has_value(); - static constexpr uint8_t irq_modechange_cmd[] = { 0x5a, 0x5a }; /// (INT mode change) - lgfx::i2c::transactionWrite(_cfg.i2c_port, _cfg.i2c_addr, irq_modechange_cmd, 2); - return _inited; - } - - uint_fast8_t getTouchRaw(touch_point_t* __restrict tp, uint_fast8_t count) override - { - if (tp) tp->size = 0; - if (!_inited || count == 0) return 0; - if (count > 2) count = 2; // max 2 point. - - if (_cfg.pin_int >= 0) - { - if (gpio_in(_cfg.pin_int)) return 0; - } - - size_t len = 3 + count * 6; - uint8_t buf[2][len]; - int32_t retry = 5; - bool flip = false; - uint8_t* tmp; - for (;;) - { - tmp = buf[flip]; - memset(tmp, 0, len); - if (lgfx::i2c::beginTransaction(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq, false)) - { - static constexpr uint8_t reg_number = 2; - if (lgfx::i2c::writeBytes(_cfg.i2c_port, ®_number, 1) - && lgfx::i2c::restart(_cfg.i2c_port, _cfg.i2c_addr, _cfg.freq, true) - && lgfx::i2c::readBytes(_cfg.i2c_port, tmp, 1) - && (tmp[0] != 0)) - { - flip = !flip; - size_t points = std::min(count, tmp[0]); - if (points && lgfx::i2c::readBytes(_cfg.i2c_port, &tmp[1], points * 6 - 2)) - {} - } - if (lgfx::i2c::endTransaction(_cfg.i2c_port)) {} - if (tmp[0] == 0 || memcmp(buf[0], buf[1], len) == 0) break; - } - if (0 == --retry) return 0; - } - if (count > tmp[0]) count = tmp[0]; - - for (size_t idx = 0; idx < count; ++idx) - { - auto data = &tmp[1 + idx * 6]; - tp[idx].size = 1; - tp[idx].x = (data[0] & 0x0F) << 8 | data[1]; - tp[idx].y = (data[2] & 0x0F) << 8 | data[3]; - tp[idx].id = idx; - } - return count; - } - }; - - struct Panel_M5StickC : public lgfx::Panel_ST7735S - { - Panel_M5StickC(void) - { - _cfg.invert = true; - _cfg.pin_cs = GPIO_NUM_5; - _cfg.pin_rst = GPIO_NUM_18; - _cfg.panel_width = 80; - _cfg.panel_height = 160; - _cfg.offset_x = 26; - _cfg.offset_y = 1; - _cfg.offset_rotation = 2; - } - - protected: - - const uint8_t* getInitCommands(uint8_t listno) const override - { - static constexpr uint8_t list[] = { - CMD_GAMMASET, 1, 0x08, // Gamma set, curve 4 - 0xFF,0xFF, // end - }; - if (listno == 2) return list; - return Panel_ST7735S::getInitCommands(listno); - } - }; - - struct Light_M5StickC : public lgfx::ILight - { - bool init(uint8_t brightness) override - { - using namespace m5stack; - lgfx::i2c::init(axp_i2c_port, axp_i2c_sda, axp_i2c_scl); - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x12, 0x4D, ~0, axp_i2c_freq); - setBrightness(brightness); - return true; - } - - void setBrightness(uint8_t brightness) override - { - using namespace m5stack; - if (brightness) - { - brightness = (((brightness >> 1) + 8) / 13) + 5; - lgfx::i2c::bitOn(axp_i2c_port, axp_i2c_addr, 0x12, 1 << 2, axp_i2c_freq); - } - else - { - lgfx::i2c::bitOff(axp_i2c_port, axp_i2c_addr, 0x12, 1 << 2, axp_i2c_freq); - } - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x28, brightness << 4, 0x0F, axp_i2c_freq); - } - }; - - struct Panel_M5StickCPlus : public lgfx::Panel_ST7789 - { - Panel_M5StickCPlus(void) - { - _cfg.invert = true; - _cfg.pin_cs = GPIO_NUM_5; - _cfg.pin_rst = GPIO_NUM_18; - _cfg.panel_width = 135; - _cfg.panel_height = 240; - _cfg.offset_x = 52; - _cfg.offset_y = 40; - } - }; - - class LGFX : public LGFX_Device - { - lgfx::Panel_Device* _panel_last = nullptr; - lgfx::ILight* _light_last = nullptr; - lgfx::ITouch* _touch_last = nullptr; - lgfx::Bus_SPI _bus_spi; - - static void _pin_level(int_fast16_t pin, bool level) - { - lgfx::pinMode(pin, lgfx::pin_mode_t::output); - if (level) lgfx::gpio_hi(pin); - else lgfx::gpio_lo(pin); - } - - static void _pin_reset(int_fast16_t pin, bool use_reset) - { - lgfx::gpio_hi(pin); - lgfx::pinMode(pin, lgfx::pin_mode_t::output); - if (!use_reset) return; - lgfx::gpio_lo(pin); - auto time = lgfx::millis(); - do - { - lgfx::delay(1); - } while (lgfx::millis() - time < 2); - lgfx::gpio_hi(pin); - time = lgfx::millis(); - do - { - lgfx::delay(1); - } while (lgfx::millis() - time < 10); - } - - /// TF card dummy clock送信 ; - static void _send_sd_dummy_clock(int spi_host, int_fast16_t pin_cs) - { - static constexpr uint32_t dummy_clock[] = { ~0u, ~0u, ~0u, ~0u }; - _pin_level(pin_cs, true); - lgfx::spi::writeBytes(spi_host, (const uint8_t*)dummy_clock, sizeof(dummy_clock)); - _pin_level(pin_cs, false); - } - - /// TF card をSPIモードに移行する ; - static void _set_sd_spimode(int spi_host, int_fast16_t pin_cs) - { - lgfx::spi::beginTransaction(spi_host, 400000, 0); - _send_sd_dummy_clock(spi_host, pin_cs); - - uint8_t sd_cmd58[] = { 0x7A, 0, 0, 0, 0, 0xFD, 0xFF, 0xFF }; // READ_OCR command. - lgfx::spi::readBytes(spi_host, sd_cmd58, sizeof(sd_cmd58)); - -// ESP_LOGW(LIBRARY_NAME, "SD READ_OCR: %02x %02x", sd_cmd58[6], sd_cmd58[7]); - if (sd_cmd58[6] == sd_cmd58[7]) // not SPI mode - { - _send_sd_dummy_clock(spi_host, pin_cs); - - static constexpr uint8_t sd_cmd0[] = { 0x40, 0, 0, 0, 0, 0x95, 0xFF, 0xFF }; // GO_IDLE_STATE command. - lgfx::spi::writeBytes(spi_host, sd_cmd0, sizeof(sd_cmd0)); - } - _pin_level(pin_cs, true); - lgfx::spi::endTransaction(spi_host); - } - - static uint32_t _read_panel_id(lgfx::Bus_SPI* bus, int32_t pin_cs, uint32_t cmd = 0x04, uint8_t dummy_read_bit = 1) // 0x04 = RDDID command - { - bus->beginTransaction(); - _pin_level(pin_cs, true); - bus->writeCommand(0, 8); - bus->wait(); - _pin_level(pin_cs, false); - bus->writeCommand(cmd, 8); - bus->beginRead(dummy_read_bit); - uint32_t res = bus->readData(32); - bus->endTransaction(); - _pin_level(pin_cs, true); - - ESP_LOGW(LIBRARY_NAME, "[Autodetect] read cmd:%02x = %08x", (unsigned int)cmd, (unsigned int)res); - return res; - } - - void _set_backlight(ILight* bl) - { - if (_light_last) { delete _light_last; } - _light_last = bl; - _panel_last->setLight(bl); - } - - void _set_pwm_backlight(int16_t pin, uint8_t ch, uint32_t freq = 12000, bool invert = false) - { - auto bl = new lgfx::Light_PWM(); - auto cfg = bl->config(); - cfg.pin_bl = pin; - cfg.freq = freq; - cfg.pwm_channel = ch; - cfg.invert = invert; - bl->config(cfg); - _set_backlight(bl); - } - - bool init_impl(bool use_reset, bool use_clear) - { - static constexpr char NVS_KEY[] = "AUTODETECT"; - uint32_t nvs_board = 0; - uint32_t nvs_handle = 0; - if (0 == nvs_open(LIBRARY_NAME, NVS_READONLY, &nvs_handle)) - { - nvs_get_u32(nvs_handle, NVS_KEY, static_cast(&nvs_board)); - nvs_close(nvs_handle); - ESP_LOGW(LIBRARY_NAME, "[Autodetect] load from NVS : board:%d", (int)nvs_board); - } - - if (0 == nvs_board) - { -#if defined ( ARDUINO_M5Stack_Core_ESP32 ) || defined ( ARDUINO_M5STACK_FIRE ) - - nvs_board = board_t::board_M5Stack; - -#elif defined ( ARDUINO_M5STACK_Core2 ) - - nvs_board = board_t::board_M5StackCore2; - -#elif defined ( ARDUINO_M5Stick_C ) - - nvs_board = board_t::board_M5StickC; - -#elif defined ( ARDUINO_M5Stick_C_Plus ) - - nvs_board = board_t::board_M5StickCPlus; - -#elif defined ( ARDUINO_M5Stack_CoreInk ) - - nvs_board = board_t::board_M5StackCoreInk; - -#elif defined ( ARDUINO_M5STACK_Paper ) - - nvs_board = board_t::board_M5Paper; - -#elif defined ( ARDUINO_M5STACK_TOUGH ) - - nvs_board = board_t::board_M5Tough; - -#elif defined ( ARDUINO_M5Stack_ATOM ) -//#elif defined ( ARDUINO_M5Stack_Timer_CAM ) - -#elif defined( ARDUINO_ODROID_ESP32 ) // ODROID-GO - - nvs_board = board_t::board_ODROID_GO; - -#elif defined( ARDUINO_TTGO_T1 ) // TTGO TS - - nvs_board = board_t::board_TTGO_TS; - -#elif defined( ARDUINO_TWatch ) || defined( ARDUINO_T ) // TTGO T-Watch - - nvs_board = board_t::board_TTGO_TWatch; - -#elif defined( ARDUINO_D ) || defined( ARDUINO_DDUINO32_XS ) // DSTIKE D-duino-32 XS - - nvs_board = board_t::board_DDUINO32_XS; - -#elif defined( ARDUINO_LOLIN_D32_PRO ) - - nvs_board = board_t::board_LoLinD32; - -#elif defined( ARDUINO_ESP32_WROVER_KIT ) - - nvs_board = board_t::board_ESP_WROVER_KIT; - -#endif - - } - - auto board = (board_t)nvs_board; - - int retry = 4; - do - { - if (retry == 1) use_reset = true; - board = autodetect(use_reset, board); - //ESP_LOGI(LIBRARY_NAME,"autodetect board:%d", board); - } while (board_t::board_unknown == board && --retry >= 0); - _board = board; - /// autodetectの際にreset済みなのでここではuse_resetをfalseで呼び出す。 - /// M5Paperはreset後の復帰に800msec程度掛かるのでreset省略は起動時間短縮に有効 - bool res = LGFX_Device::init_impl(false, use_clear); - - if (nvs_board != board) { - if (0 == nvs_open(LIBRARY_NAME, NVS_READWRITE, &nvs_handle)) { - ESP_LOGW(LIBRARY_NAME, "[Autodetect] save to NVS : board:%d", board); - nvs_set_u32(nvs_handle, NVS_KEY, board); - nvs_close(nvs_handle); - } - } - return res; - } - - public: - - board_t autodetect(bool use_reset = true, board_t board = board_t::board_unknown) - { - auto bus_cfg = _bus_spi.config(); -// if (bus_cfg.pin_mosi != -1 && bus_cfg.pin_sclk != -1) return true; - - panel(nullptr); - - if (_panel_last) - { - delete _panel_last; - _panel_last = nullptr; - } - if (_light_last) - { - delete _light_last; - _light_last = nullptr; - } - if (_touch_last) - { - delete _touch_last; - _touch_last = nullptr; - } - - bus_cfg.freq_write = 8000000; - bus_cfg.freq_read = 8000000; -// ArduinoESP32 v2.0.4 ではPSRAM有効にするとVSPIが使用されるのでHSPIに変更する対策を実施する; -#if CONFIG_SPIRAM_OCCUPY_VSPI_HOST && CONFIG_ESP32_SPIRAM_SUPPORT - bus_cfg.spi_host = HSPI_HOST; -#else - bus_cfg.spi_host = VSPI_HOST; -#endif - bus_cfg.spi_mode = 0; - bus_cfg.use_lock = true; - bus_cfg.dma_channel = 1; -#if __has_include() - #include - #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) - bus_cfg.dma_channel = SPI_DMA_CH_AUTO; - #endif -#endif - - uint32_t id; - (void)id; // suppress warning - - std::uint32_t pkg_ver = lgfx::get_pkg_ver(); -// ESP_LOGE("LGFX","pkg:%d", pkg_ver); - - if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) - { -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STICK_C ) || defined ( LGFX_M5STICKC ) - - if (board == 0 || board == board_t::board_M5StickC || board == board_t::board_M5StickCPlus) - { - bus_cfg.pin_mosi = GPIO_NUM_15; - bus_cfg.pin_miso = GPIO_NUM_14; - bus_cfg.pin_sclk = GPIO_NUM_13; - bus_cfg.pin_dc = GPIO_NUM_23; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_18, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, GPIO_NUM_5); - if ((id & 0xFF) == 0x85) - { // check panel (ST7789) - board = board_t::board_M5StickCPlus; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickCPlus"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 15000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_M5StickCPlus(); - p->bus(&_bus_spi); - _panel_last = p; - _set_backlight(new Light_M5StickC()); - goto init_clear; - } - if ((id & 0xFF) == 0x7C) - { // check panel (ST7735) - board = board_t::board_M5StickC; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickC"); - bus_cfg.freq_write = 27000000; - bus_cfg.freq_read = 14000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_M5StickC(); - p->bus(&_bus_spi); - _panel_last = p; - _set_backlight(new Light_M5StickC()); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_18, lgfx::pin_mode_t::input); // LCD RST - lgfx::pinMode(GPIO_NUM_5 , lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } - -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_TTGO_TWRISTBAND ) - - if (board == 0 || board == board_t::board_TTGO_TWristband) - { - bus_cfg.pin_mosi = GPIO_NUM_19; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_23; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_26, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, GPIO_NUM_5); - if ((id & 0xFF) == 0x7C) - { // check panel (ST7735) - board = board_t::board_TTGO_TWristband; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] TWristband"); - bus_cfg.freq_write = 27000000; - bus_cfg.freq_read = 14000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7735S(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.dummy_read_pixel = 17; - cfg.invert = true; - cfg.pin_cs = GPIO_NUM_5; - cfg.pin_rst = GPIO_NUM_26; - cfg.panel_width = 80; - cfg.panel_height = 160; - cfg.offset_x = 26; - cfg.offset_y = 1; - cfg.offset_rotation = 2; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_27, 7, 12000); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_26, lgfx::pin_mode_t::input); // LCD RST - lgfx::pinMode(GPIO_NUM_5 , lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STACK_COREINK ) - - if (board == 0 || board == board_t::board_M5StackCoreInk) - { - _pin_reset(GPIO_NUM_0, true); // EPDがDeepSleepしていると自動認識に失敗するためRST制御は必須とする - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = GPIO_NUM_34; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_15; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - id = _read_panel_id(&_bus_spi, GPIO_NUM_9, 0x70, 0); - if (id == 0x00F00000) - { // check panel (e-paper GDEW0154M09) - _pin_level(GPIO_NUM_12, true); // POWER_HOLD_PIN 12 - board = board_t::board_M5StackCoreInk; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StackCoreInk"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new lgfx::Panel_GDEW0154M09(); - p->bus(&_bus_spi); - _panel_last = p; - auto cfg = p->config(); - cfg.panel_height = 200; - cfg.panel_width = 200; - cfg.pin_cs = GPIO_NUM_9; - cfg.pin_rst = GPIO_NUM_0; - cfg.pin_busy = GPIO_NUM_4; - p->config(cfg); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_0, lgfx::pin_mode_t::input); // RST - lgfx::pinMode(GPIO_NUM_9, lgfx::pin_mode_t::input); // CS - _bus_spi.release(); - } -#endif - -/// CS と D/C に GPIO 16 17を使っており、PSRAMと競合するため判定順序をなるべく後にする -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_TTGO_TS ) - if (board == 0 || board == board_t::board_TTGO_TS) - { - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_5; - bus_cfg.pin_dc = GPIO_NUM_17; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_9, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, GPIO_NUM_16); - if ((id & 0xFF) == 0x7C) - { // check panel (ST7735) - board = board_t::board_TTGO_TS; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] TTGO TS"); - bus_cfg.freq_write = 20000000; - bus_cfg.freq_read = 14000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7735S(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_16; - cfg.pin_rst = GPIO_NUM_9; - cfg.panel_width = 128; - cfg.panel_height = 160; - cfg.offset_x = 2; - cfg.offset_y = 1; - cfg.offset_rotation = 2; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_27, 7, 12000); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_9 , lgfx::pin_mode_t::input); // LCD RST - lgfx::pinMode(GPIO_NUM_16, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - - } - else - if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 - || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6) - { - // ODROID_GO 判定 (ボードマネージャでM5StickCを選択していると判定失敗する事に注意); -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_ODROID_GO ) - - if (board == 0 || board == board_t::board_ODROID_GO) - { - _pin_level(GPIO_NUM_5, true); - - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = GPIO_NUM_19; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_21; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - - _set_sd_spimode(bus_cfg.spi_host, GPIO_NUM_22); - - id = _read_panel_id(&_bus_spi, GPIO_NUM_5, 0x09); - if (id != 0 && id != ~0u && id != 0xFFFFFF00 && (_read_panel_id(&_bus_spi, GPIO_NUM_5) & 0xFF) == 0) - { // check panel (ILI9341) panelIDが0なのでステータスリード0x09を併用する; - board = board_t::board_ODROID_GO; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] ODROID_GO"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ILI9341(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_5; - p->config(cfg); - p->setRotation(1); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_14, 7); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_22, lgfx::pin_mode_t::input); // ODROID-GO TF card CS - lgfx::pinMode(GPIO_NUM_5 , lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - - if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6) - { - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STATION ) || defined ( LGFX_M5STACK_CORE2 ) || defined ( LGFX_M5STACKCORE2 ) || defined ( LGFX_M5TOUGH ) - - /// AXP192の有無を最初に判定し、分岐する。 - if (board == 0 - || board == board_t::board_M5Station - || board == board_t::board_M5StackCore2 - || board == board_t::board_M5Tough) - { - using namespace m5stack; - // I2C addr 0x34 = AXP192 - lgfx::i2c::init(axp_i2c_port, axp_i2c_sda, axp_i2c_scl); - if (lgfx::i2c::readRegister8(axp_i2c_port, axp_i2c_addr, 0x03, 400000) == 0x03) // AXP192 found - { - ESP_LOGW(LIBRARY_NAME, "AXP192 found."); - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STATION ) - - if (board == 0 || board == board_t::board_M5Station) - { - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_19; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_15, use_reset); // LCD RST; - - id = _read_panel_id(&_bus_spi, GPIO_NUM_5); - if ((id & 0xFF) == 0x85) - { // ST7789 - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5Station"); - board = board_t::board_M5Station; - - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 15000000; - _bus_spi.config(bus_cfg); - - auto p = new Panel_M5StickCPlus(); - { - auto cfg = p->config(); - cfg.pin_rst = GPIO_NUM_15; - p->config(cfg); - p->setRotation(1); - } - p->bus(&_bus_spi); - _panel_last = p; - /// M5StationのバックライトはM5Toughと同じ; - _set_backlight(new Light_M5Tough()); - goto init_clear; - } - _bus_spi.release(); - lgfx::pinMode(GPIO_NUM_5 , lgfx::pin_mode_t::input); // LCD CS - lgfx::pinMode(GPIO_NUM_15, lgfx::pin_mode_t::input); // LCD RST - } - -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STACK_CORE2 ) || defined ( LGFX_M5STACKCORE2 ) || defined ( LGFX_M5TOUGH ) - - if (board == 0 || board == board_t::board_M5StackCore2 || board == board_t::board_M5Tough) - { - using namespace m5stack; - - // AXP192_LDO2 = LCD PWR - // AXP192_IO4 = LCD RST - // AXP192_DC3 = LCD BL (Core2) - // AXP192_LDO3 = LCD BL (Tough) - // AXP192_IO1 = TP RST (Tough) - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x28, 0xF0, ~0, axp_i2c_freq); // set LDO2 3300mv // LCD PWR - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x12, 0x04, ~0, axp_i2c_freq); // LDO2 enable - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x92, 0x00, 0xF8, axp_i2c_freq); // GPIO1 OpenDrain (M5Tough TOUCH) - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x95, 0x84, 0x72, axp_i2c_freq); // GPIO4 enable - if (use_reset) - { - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0, ~0x02, axp_i2c_freq); // GPIO4 LOW (LCD RST) - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0, ~0x02, axp_i2c_freq); // GPIO1 LOW (M5Tough TOUCH RST) - lgfx::delay(1); - } - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x96, 0x02, ~0, axp_i2c_freq); // GPIO4 HIGH (LCD RST) - lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0x02, ~0, axp_i2c_freq); // GPIO1 HIGH (M5Tough TOUCH RST) - - _pin_level(GPIO_NUM_5, true); - - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = GPIO_NUM_38; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_15; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - - _set_sd_spimode(bus_cfg.spi_host, GPIO_NUM_4); - - id = _read_panel_id(&_bus_spi, GPIO_NUM_5); - if ((id & 0xFF) == 0xE3) - { // ILI9342c - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - - auto p = new Panel_M5StackCore2(); - p->bus(&_bus_spi); - _panel_last = p; - - // Tough のタッチコントローラ有無をチェックする; - // Core2/Tough 判別条件としてCore2のTP(0x38)の有無を用いた場合、以下の問題が生じる; - // ・Core2のTPがスリープしている場合は反応が得られない; - // ・ToughにGoPlus2を組み合わせると0x38に反応がある; - // 上記のことから、ここではToughのTP(0x2E)の有無によって判定する; - if ( ! lgfx::i2c::readRegister8(axp_i2c_port, 0x2E, 0, 400000).has_value()) // 0x2E:M5Tough TOUCH - { - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StackCore2"); - board = board_t::board_M5StackCore2; - - _set_backlight(new Light_M5StackCore2()); - - auto t = new lgfx::Touch_FT5x06(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = GPIO_NUM_39; // INT pin number - cfg.pin_sda = GPIO_NUM_21; // I2C SDA pin number - cfg.pin_scl = GPIO_NUM_22; // I2C SCL pin number - cfg.i2c_addr = 0x38; // I2C device addr - cfg.i2c_port = I2C_NUM_1;// I2C port number - cfg.freq = 400000; // I2C freq - cfg.x_min = 0; - cfg.x_max = 319; - cfg.y_min = 0; - cfg.y_max = 279; - cfg.bus_shared = false; - t->config(cfg); - p->touch(t); - float affine[6] = { 1, 0, 0, 0, 1, 0 }; - p->setCalibrateAffine(affine); - } - else - { - // AXP192のGPIO1 = タッチコントローラRST - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5Tough"); - board = board_t::board_M5Tough; - - _set_backlight(new Light_M5Tough()); - - auto t = new lgfx::Touch_M5Tough(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = GPIO_NUM_39; // INT pin number - cfg.pin_sda = GPIO_NUM_21; // I2C SDA pin number - cfg.pin_scl = GPIO_NUM_22; // I2C SCL pin number - cfg.i2c_addr = 0x2E; // I2C device addr - cfg.i2c_port = I2C_NUM_1;// I2C port number - cfg.freq = 400000; // I2C freq - cfg.bus_shared = false; - t->config(cfg); - p->touch(t); - } - - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_4, lgfx::pin_mode_t::input); // TF card CS - lgfx::pinMode(GPIO_NUM_5, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - } - else - { - ESP_LOGW(LIBRARY_NAME, "AXP192 not found."); - } - lgfx::i2c::release(axp_i2c_port); - } - -#endif - -// TTGO T-Watch 判定 (GPIO33を使う判定を先に行うと振動モーターが作動する事に注意); -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_TTGO_TWATCH ) - - if (board == 0 || board == board_t::board_TTGO_TWatch) - { - bus_cfg.pin_mosi = GPIO_NUM_19; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_27; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - - id = _read_panel_id(&_bus_spi, GPIO_NUM_5); - if ((id & 0xFF) == 0x85) - { // check panel (ST7789) - board = board_t::board_TTGO_TWatch; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] TWatch"); - _bus_spi.release(); - bus_cfg.spi_host = HSPI_HOST; - bus_cfg.freq_write = 80000000; - bus_cfg.freq_read = 20000000; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.invert = true; - cfg.pin_cs = GPIO_NUM_5; - cfg.pin_rst = GPIO_NUM_26; - cfg.panel_width = 240; - cfg.panel_height = 240; - p->config(cfg); - } - _panel_last = p; - - _pin_level(GPIO_NUM_15, true); - _pin_level(GPIO_NUM_25, true); - _set_backlight(new Light_TWatch()); - - { - auto t = new lgfx::Touch_FT5x06(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = GPIO_NUM_38; // INT pin number - cfg.pin_sda = GPIO_NUM_23; // I2C SDA pin number - cfg.pin_scl = GPIO_NUM_32; // I2C SCL pin number - cfg.i2c_addr = 0x38; // I2C device addr - cfg.i2c_port = I2C_NUM_1;// I2C port number - cfg.freq = 400000; // I2C freq - cfg.x_min = 0; - cfg.x_max = 319; - cfg.y_min = 0; - cfg.y_max = 319; - cfg.bus_shared = false; - t->config(cfg); - p->touch(t); - } - - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_5, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - -// TTGO T-Display -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_TTGO_TDISPLAY ) - - if (board == 0 || board == board_t::board_TTGO_TDisplay) - { - bus_cfg.pin_mosi = GPIO_NUM_19; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_16; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - - id = _read_panel_id(&_bus_spi, GPIO_NUM_5); - if ((id & 0xFF) == 0x85) - { // check panel (ST7789) - board = board_t::board_TTGO_TDisplay; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] TDisplay"); - _bus_spi.release(); - bus_cfg.spi_host = HSPI_HOST; - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 14000000; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.invert = true; - cfg.pin_cs = GPIO_NUM_5; - cfg.pin_rst = GPIO_NUM_23; - cfg.panel_width = 135; - cfg.panel_height = 240; - cfg.offset_x = 52; - cfg.offset_y = 40; - cfg.dummy_read_pixel = 16; - cfg.dummy_read_bits = 1; - p->config(cfg); - } - _panel_last = p; - - _set_pwm_backlight(GPIO_NUM_4, 7, 44100); - - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_5, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_WIFIBOY_MINI ) - - if (board == 0 || board == board_t::board_WiFiBoy_Mini) - { - bus_cfg.pin_mosi = GPIO_NUM_13; - bus_cfg.pin_miso = GPIO_NUM_12; - bus_cfg.pin_sclk = GPIO_NUM_14; - bus_cfg.pin_dc = GPIO_NUM_4; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - id = _read_panel_id(&_bus_spi, GPIO_NUM_15); - if ((id & 0xFF) == 0x7C) - { // check panel (ST7735) - board = board_t::board_WiFiBoy_Mini; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] WiFiBoy mini"); - _bus_spi.release(); - bus_cfg.spi_host = HSPI_HOST; - bus_cfg.freq_write = 20000000; - bus_cfg.freq_read = 8000000; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - auto p = new Panel_ST7735S(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = -1; - cfg.panel_width = 128; - cfg.panel_height = 128; - cfg.memory_width = 132; - cfg.memory_height = 132; - cfg.offset_x = 2; - cfg.offset_y = 1; - cfg.offset_rotation = 2; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_27, 7, 12000); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_15, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_WIFIBOY_PRO ) - - if (board == 0 || board == board_t::board_WiFiBoy_Pro) - { - bus_cfg.pin_mosi = GPIO_NUM_13; - bus_cfg.pin_miso = GPIO_NUM_12; - bus_cfg.pin_sclk = GPIO_NUM_14; - bus_cfg.pin_dc = GPIO_NUM_4; - bus_cfg.spi_3wire = false; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - id = _read_panel_id(&_bus_spi, GPIO_NUM_15); - if ((id & 0xFF) == 0 && _read_panel_id(&_bus_spi, GPIO_NUM_15, 0x09) != 0) - { // check panel (ILI9341) panelIDが0なのでステータスリード0x09を併用する - board = board_t::board_WiFiBoy_Pro; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] WiFiBoy Pro"); - _bus_spi.release(); - bus_cfg.spi_host = HSPI_HOST; - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - auto p = new Panel_ILI9341(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = -1; - cfg.offset_rotation = 2; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_27, 7, 12000); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_15, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_MAKERFABS_MAKEPYTHON ) - - if (board == 0 || board == board_t::board_Makerfabs_MakePython) - { - bus_cfg.pin_mosi = GPIO_NUM_13; - bus_cfg.pin_miso = GPIO_NUM_12; - bus_cfg.pin_sclk = GPIO_NUM_14; - bus_cfg.pin_dc = GPIO_NUM_22; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_21, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, GPIO_NUM_15); - if ((id & 0xFF) == 0x85) - { // check panel (ST7789) - board = board_t::board_Makerfabs_MakePython; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] Makerfabs_Makepython"); - _bus_spi.release(); - bus_cfg.spi_host = HSPI_HOST; - bus_cfg.freq_write = 80000000; - bus_cfg.freq_read = 14000000; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.invert = true; - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = GPIO_NUM_21; - cfg.panel_height = 240; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_5, 7, 12000); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_15, lgfx::pin_mode_t::input); // LCD CS - lgfx::pinMode(GPIO_NUM_21, lgfx::pin_mode_t::input); // LCD RST - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STACK ) - - if (board == 0 || board == board_t::board_M5Stack) - { - _pin_level(GPIO_NUM_14, true); // LCD CS; - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = GPIO_NUM_19; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_27; - - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_33, use_reset); // LCD RST; - - _set_sd_spimode(bus_cfg.spi_host, GPIO_NUM_4); - - id = _read_panel_id(&_bus_spi, GPIO_NUM_14); - - if ((id & 0xFF) == 0xE3) - { // ILI9342c - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5Stack"); - board = board_t::board_M5Stack; - - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - - auto p = new Panel_M5Stack(); - p->bus(&_bus_spi); - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_32, 7, 44100); - goto init_clear; - } - _bus_spi.release(); - - lgfx::pinMode(GPIO_NUM_4 , lgfx::pin_mode_t::input); // M5Stack and LoLinD32 TF card CS - lgfx::pinMode(GPIO_NUM_14, lgfx::pin_mode_t::input); // LCD CS - lgfx::pinMode(GPIO_NUM_33, lgfx::pin_mode_t::input); // LCD RST - } - -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5PAPER ) - - if (board == 0 || board == board_t::board_M5Paper) - { - _pin_reset(GPIO_NUM_23, true); - lgfx::pinMode(GPIO_NUM_27, lgfx::pin_mode_t::input_pullup); // M5Paper EPD busy pin - if (!lgfx::gpio_in(GPIO_NUM_27)) - { - _pin_level(GPIO_NUM_2, true); // M5EPD_MAIN_PWR_PIN 2 - lgfx::pinMode(GPIO_NUM_27, lgfx::pin_mode_t::input); - //ESP_LOGW(LIBRARY_NAME, "check M5Paper"); - bus_cfg.pin_mosi = GPIO_NUM_12; - bus_cfg.pin_miso = GPIO_NUM_13; - bus_cfg.pin_sclk = GPIO_NUM_14; - bus_cfg.pin_dc = -1; - bus_cfg.spi_3wire = false; - _bus_spi.config(bus_cfg); - id = lgfx::millis(); - - _pin_level(GPIO_NUM_15, true); // M5Paper CS; - _bus_spi.init(); - _set_sd_spimode(bus_cfg.spi_host, GPIO_NUM_4); - do - { - vTaskDelay(1); - if (lgfx::millis() - id > 1024) { id = 0; break; } - } while (!lgfx::gpio_in(GPIO_NUM_27)); - if (id) - { - //ESP_LOGW(LIBRARY_NAME, "ms:%d", millis() - id); - _bus_spi.beginTransaction(); - lgfx::gpio_lo(GPIO_NUM_15); - _bus_spi.writeData(__builtin_bswap16(0x6000), 16); - _bus_spi.writeData(__builtin_bswap16(0x0302), 16); // read DevInfo - id = lgfx::millis(); - _bus_spi.wait(); - lgfx::gpio_hi(GPIO_NUM_15); - do - { - vTaskDelay(1); - if (lgfx::millis() - id > 192) { break; } - } while (!lgfx::gpio_in(GPIO_NUM_27)); - lgfx::gpio_lo(GPIO_NUM_15); - _bus_spi.writeData(__builtin_bswap16(0x1000), 16); - _bus_spi.writeData(__builtin_bswap16(0x0000), 16); - uint8_t buf[40]; - _bus_spi.beginRead(); - _bus_spi.readBytes(buf, 40, false); - _bus_spi.endRead(); - _bus_spi.endTransaction(); - lgfx::gpio_hi(GPIO_NUM_15); - id = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] panel size :%08x", (unsigned int)id); - if (id == 0x03C0021C) - { // check panel ( panel size 960(0x03C0) x 540(0x021C) ) - board = board_t::board_M5Paper; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5Paper"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 20000000; - _bus_spi.config(bus_cfg); - { - auto p = new lgfx::Panel_IT8951(); - p->setVCOM(2200); - p->bus(&_bus_spi); - _panel_last = p; - auto cfg = p->config(); - cfg.panel_height = 540; - cfg.panel_width = 960; - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = GPIO_NUM_23; - cfg.pin_busy = GPIO_NUM_27; - cfg.offset_rotation = 3; - p->config(cfg); - } - { - auto t = new lgfx::Touch_GT911(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = GPIO_NUM_36; // INT pin number - cfg.pin_sda = GPIO_NUM_21; // I2C SDA pin number - cfg.pin_scl = GPIO_NUM_22; // I2C SCL pin number - cfg.i2c_addr = 0x14; // I2C device addr - #ifdef _M5EPD_H_ - cfg.i2c_port = I2C_NUM_0;// I2C port number - #else - cfg.i2c_port = I2C_NUM_1;// I2C port number - #endif - cfg.freq = 400000; // I2C freq - cfg.x_min = 0; - cfg.x_max = 539; - cfg.y_min = 0; - cfg.y_max = 959; - cfg.offset_rotation = 1; - cfg.bus_shared = false; - t->config(cfg); - if (!t->init()) - { - cfg.i2c_addr = 0x5D; // addr change (0x14 or 0x5D) - t->config(cfg); - } - _panel_last->touch(t); - } - goto init_clear; - } - } - _bus_spi.release(); - lgfx::pinMode(GPIO_NUM_15, lgfx::pin_mode_t::input); // EPD CS - lgfx::pinMode(GPIO_NUM_4 , lgfx::pin_mode_t::input); // M5Paper TF card CS - lgfx::pinMode(GPIO_NUM_2, lgfx::pin_mode_t::input); // M5EPD_MAIN_PWR_PIN 2 - } - lgfx::pinMode(GPIO_NUM_27, lgfx::pin_mode_t::input); // BUSY - lgfx::pinMode(GPIO_NUM_23, lgfx::pin_mode_t::input); // RST - } - #endif - - } - else - if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5) - { - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_MAKERFABS_TOUCHCAMERA ) - - if (board == 0 || board == board_t::board_Makerfabs_TouchCamera) - { - bus_cfg.pin_mosi = GPIO_NUM_13; - bus_cfg.pin_miso = GPIO_NUM_12; - bus_cfg.pin_sclk = GPIO_NUM_14; - bus_cfg.pin_dc = GPIO_NUM_33; - bus_cfg.spi_3wire = false; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_level(GPIO_NUM_4, true); // TF card CS - _pin_level(GPIO_NUM_2, true); // TOUCH CS - - id = _read_panel_id(&_bus_spi, GPIO_NUM_15, 0x09); - if (id) - { - id = _read_panel_id(&_bus_spi, GPIO_NUM_15) & 0xFF; - if (id == 0x00) - { // check panel (ILI9341) - board = board_t::board_Makerfabs_TouchCamera; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] Makerfabs_TouchCamera(ILI9341)"); // 3.2inch - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ILI9341(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = -1; - p->config(cfg); - } - _panel_last = p; - { - auto t = new lgfx::Touch_STMPE610(); - _touch_last = t; - auto cfg = t->config(); - cfg.bus_shared = true; - cfg.spi_host = bus_cfg.spi_host; - cfg.pin_cs = GPIO_NUM_2; - cfg.pin_mosi = GPIO_NUM_13; - cfg.pin_miso = GPIO_NUM_12; - cfg.pin_sclk = GPIO_NUM_14; - cfg.offset_rotation = 2; - t->config(cfg); - p->touch(t); - } - - goto init_clear; - - } - else - if (id == 0x54) - { // check panel (ILI9488) - board = board_t::board_Makerfabs_TouchCamera; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] Makerfabs_TouchCamera"); // 3.5inch - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ILI9488(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = -1; - p->config(cfg); - } - _panel_last = p; - - if (lgfx::i2c::init(I2C_NUM_1, GPIO_NUM_26, GPIO_NUM_27).has_value()) - { - ITouch* t = nullptr; - ITouch::config_t cfg; - if (!lgfx::i2c::readRegister8(I2C_NUM_1, 0x38, 0, 400000).has_value()) // 0x48:NS2009 - { - t = new lgfx::Touch_NS2009(); - cfg = t->config(); - cfg.i2c_addr = 0x48; // I2C device addr - cfg.x_min = 460; - cfg.x_max = 3680; - cfg.y_min = 150; - cfg.y_max = 3780; - cfg.pin_int = GPIO_NUM_0; // INT pin number - } - else - { - t = new lgfx::Touch_FT5x06(); - cfg = t->config(); - cfg.i2c_addr = 0x38; // I2C device addr - cfg.x_min = 0; - cfg.x_max = 319; - cfg.y_min = 0; - cfg.y_max = 479; - //cfg.pin_int = GPIO_NUM_0; // INT pin number (board ver1.1 doesn't work) - } - - if (t) - { - cfg.bus_shared = false; - cfg.pin_sda = GPIO_NUM_26; // I2C SDA pin number - cfg.pin_scl = GPIO_NUM_27; // I2C SCL pin number - cfg.i2c_port = I2C_NUM_1;// I2C port number - cfg.freq = 400000; // I2C freq - _touch_last = t; - t->config(cfg); - p->touch(t); - } - } - - goto init_clear; - } - } - - lgfx::pinMode(GPIO_NUM_15, lgfx::pin_mode_t::input); // LCD CS - lgfx::pinMode(GPIO_NUM_4 , lgfx::pin_mode_t::input); // TF card CS - lgfx::pinMode(GPIO_NUM_2 , lgfx::pin_mode_t::input); // TOUCH CS - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_LOLIN_D32_PRO ) - - if (board == 0 || board == board_t::board_LoLinD32) - { - _pin_level(GPIO_NUM_14, true); // LCD CS; - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = GPIO_NUM_19; - bus_cfg.pin_sclk = GPIO_NUM_18; - bus_cfg.pin_dc = GPIO_NUM_27; - - _pin_level(GPIO_NUM_4, true); // M5Stack and LoLinD32 TF card CS - #if defined ( LGFX_AUTODETECT ) || defined ( LGFX_LOLIN_D32_PRO ) - _pin_level(GPIO_NUM_12, true); // LoLinD32 TouchScreen CS - #endif - - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_33, use_reset); // LCD RST; - - id = _read_panel_id(&_bus_spi, GPIO_NUM_14); - - if ((id & 0xFF) == 0x7C) - { // check panel (ST7735) - ESP_LOGW(LIBRARY_NAME, "[Autodetect] LoLinD32Pro ST7735"); - board = board_t::board_LoLinD32; - - #if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STACK ) - lgfx::pinMode(GPIO_NUM_4, lgfx::pin_mode_t::input); // M5Stack TF card CS - #endif - - bus_cfg.freq_write = 27000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - - auto p = new lgfx::Panel_ST7735S(); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_14; - cfg.pin_rst = GPIO_NUM_33; - cfg.memory_width = 132; - cfg.memory_height = 132; - cfg.panel_width = 128; - cfg.panel_height = 128; - cfg.offset_x = 2; - cfg.offset_y = 1; - p->config(cfg); - } - p->bus(&_bus_spi); - _panel_last = p; - - _set_pwm_backlight(GPIO_NUM_32, 7, 44100); - - goto init_clear; - } - - bus_cfg.spi_3wire = false; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_33, use_reset); // LCD RST; - id = _read_panel_id(&_bus_spi, GPIO_NUM_14); - if ((id & 0xFF) == 0 && _read_panel_id(&_bus_spi, GPIO_NUM_14, 0x09) != 0) - { // check panel (ILI9341) panelIDが0なのでステータスリード0x09を併用する - ESP_LOGW(LIBRARY_NAME, "[Autodetect] LoLinD32Pro ILI9341"); - board = board_t::board_LoLinD32; - - #if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STACK ) - lgfx::pinMode(GPIO_NUM_4, lgfx::pin_mode_t::input); // M5Stack TF card CS - #endif - - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - - auto p = new lgfx::Panel_ILI9341(); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_14; - cfg.pin_rst = GPIO_NUM_33; - p->config(cfg); - } - p->bus(&_bus_spi); - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_32, 7, 44100); - - { - auto t = new lgfx::Touch_XPT2046(); - _touch_last = t; - auto cfg = t->config(); - cfg.bus_shared = true; - cfg.freq = 2700000; - cfg.spi_host = bus_cfg.spi_host; - cfg.pin_cs = GPIO_NUM_12; - cfg.pin_mosi = GPIO_NUM_23; - cfg.pin_miso = GPIO_NUM_19; - cfg.pin_sclk = GPIO_NUM_18; - t->config(cfg); - p->touch(t); - } - - goto init_clear; - } - _bus_spi.release(); - lgfx::pinMode(GPIO_NUM_12, lgfx::pin_mode_t::input); // LoLinD32 TouchScreen CS - - lgfx::pinMode(GPIO_NUM_4 , lgfx::pin_mode_t::input); // M5Stack and LoLinD32 TF card CS - lgfx::pinMode(GPIO_NUM_14, lgfx::pin_mode_t::input); // LCD CS - lgfx::pinMode(GPIO_NUM_33, lgfx::pin_mode_t::input); // LCD RST - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_ESP_WROVER_KIT ) - - if (board == 0 || board == board_t::board_ESP_WROVER_KIT) - { - bus_cfg.pin_mosi = GPIO_NUM_23; - bus_cfg.pin_miso = GPIO_NUM_25; - bus_cfg.pin_sclk = GPIO_NUM_19; - bus_cfg.pin_dc = GPIO_NUM_21; - bus_cfg.spi_3wire = false; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_18, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, GPIO_NUM_22); - if ((id & 0xFF) == 0x85) - { // check panel (ST7789) - board = board_t::board_ESP_WROVER_KIT; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] ESP-WROVER-KIT ST7789"); - bus_cfg.freq_write = 80000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_22; - cfg.offset_rotation = 2; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_5, 7, 12000, true); - goto init_clear; - } - if ((id & 0xFF) == 0 && _read_panel_id(&_bus_spi, GPIO_NUM_22, 0x09) != 0) - { // check panel (ILI9341) panelIDが0なのでステータスリード0x09を併用する - board = board_t::board_ESP_WROVER_KIT; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] ESP-WROVER-KIT ILI9341"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 20000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ILI9341(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_22; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_5, 7, 12000, true); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_18, lgfx::pin_mode_t::input); // LCD RST - lgfx::pinMode(GPIO_NUM_22, lgfx::pin_mode_t::input); // LCD CS - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_WT32_SC01 ) - - if (board == 0 || board == board_t::board_WT32_SC01) - { - bus_cfg.pin_mosi = GPIO_NUM_13; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_14; - bus_cfg.pin_dc = GPIO_NUM_21; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_22, use_reset); // LCD RST - - id = _read_panel_id(&_bus_spi, GPIO_NUM_15); - if (id == 0) - { // 読出しが出来ない製品のため 0 判定 - lgfx::i2c::init(I2C_NUM_1, GPIO_NUM_18, GPIO_NUM_19); - // I2C通信でタッチパネルコントローラが存在するかチェックする - if (0x11 == lgfx::i2c::readRegister8(I2C_NUM_1, 0x38, 0xA8, 400000)) - { /// FocalTech's Panel ID reg=0xA8 value=0x11 - board = board_t::board_WT32_SC01; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] WT32-SC01"); - bus_cfg.freq_write = 40000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7796(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = GPIO_NUM_22; - cfg.readable = false; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_23, 7); - - { - auto t = new lgfx::Touch_FT5x06(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = GPIO_NUM_39; // INT pin number - cfg.pin_sda = GPIO_NUM_18; // I2C SDA pin number - cfg.pin_scl = GPIO_NUM_19; // I2C SCL pin number - cfg.i2c_addr = 0x38; // I2C device addr - cfg.i2c_port = I2C_NUM_1;// I2C port number - cfg.freq = 400000; // I2C freq - cfg.x_min = 0; - cfg.x_max = 319; - cfg.y_min = 0; - cfg.y_max = 479; - cfg.bus_shared = false; - t->config(cfg); - p->touch(t); - } - goto init_clear; - } - lgfx::i2c::release(I2C_NUM_1); - } - lgfx::pinMode(GPIO_NUM_15, lgfx::pin_mode_t::input); // LCD CS - lgfx::pinMode(GPIO_NUM_22, lgfx::pin_mode_t::input); // LCD RST - _bus_spi.release(); - } -#endif - - // DSTIKE D-Duino32XS については読出しが出来ないため無条件設定となる。 - // そのためLGFX_AUTO_DETECTでは機能しないようにしておく。 -#if defined ( LGFX_DDUINO32_XS ) - - if (board == 0 || board == board_t::board_DDUINO32_XS) - { - bus_cfg.pin_mosi = GPIO_NUM_26; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_27; - bus_cfg.pin_dc = GPIO_NUM_23; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_32, use_reset); // LCD RST - // id = _read_panel_id(&_bus_spi, -1); // 読出しモードから抜ける事ができないのでコメントアウト; - // if ((id & 0xFF) == 0x85) - { - board = board_t::board_DDUINO32_XS; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] D-Duino32 XS"); - bus_cfg.freq_write = 80000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.invert = true; - cfg.readable = false; - cfg.pin_cs = -1; - cfg.pin_rst = GPIO_NUM_32; - cfg.panel_height = 240; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_22, 7, 12000); - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_32, lgfx::pin_mode_t::input); // LCD RST - _bus_spi.release(); - } -#endif - - } - } - - board = board_t::board_unknown; - - goto init_clear; - init_clear: - - panel(_panel_last); - - return board; - } - }; - -//---------------------------------------------------------------------------- - } -} - -using LGFX = lgfx::LGFX; \ No newline at end of file diff --git a/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32S2.hpp b/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32S2.hpp deleted file mode 100644 index 5666e317..00000000 --- a/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32S2.hpp +++ /dev/null @@ -1,324 +0,0 @@ -/*----------------------------------------------------------------------------/ - Lovyan GFX - Graphics library for embedded devices. - -Original Source: - https://github.com/lovyan03/LovyanGFX/ - -Licence: - [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) - -Author: - [lovyan03](https://twitter.com/lovyan03) - -Contributors: - [ciniml](https://github.com/ciniml) - [mongonta0716](https://github.com/mongonta0716) - [tobozo](https://github.com/tobozo) -/----------------------------------------------------------------------------*/ -#pragma once - -#include "../v1_init.hpp" -#include "common.hpp" - -#include -#include -#include -#include - - -#if defined ( ARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT ) - #define LGFX_FEATHER_ESP32_S2_TFT -#endif - -#if defined ( ARDUINO_FUNHOUSE_ESP32S2 ) - #define LGFX_FUNHOUSE -#endif - - -namespace lgfx -{ - inline namespace v1 - { -//---------------------------------------------------------------------------- - - static constexpr char LIBRARY_NAME[] = "LovyanGFX"; - - - class LGFX : public LGFX_Device - { - lgfx::Panel_Device* _panel_last = nullptr; - lgfx::ILight* _light_last = nullptr; - lgfx::ITouch* _touch_last = nullptr; - lgfx::Bus_SPI _bus_spi; - - static void _pin_level(int_fast16_t pin, bool level) - { - lgfx::pinMode(pin, lgfx::pin_mode_t::output); - if (level) lgfx::gpio_hi(pin); - else lgfx::gpio_lo(pin); - } - - static void _pin_reset(int_fast16_t pin, bool use_reset) - { - lgfx::gpio_hi(pin); - lgfx::pinMode(pin, lgfx::pin_mode_t::output); - if (!use_reset) return; - lgfx::gpio_lo(pin); - auto time = lgfx::millis(); - do - { - lgfx::delay(1); - } while (lgfx::millis() - time < 2); - lgfx::gpio_hi(pin); - time = lgfx::millis(); - do - { - lgfx::delay(1); - } while (lgfx::millis() - time < 10); - } - - static uint32_t _read_panel_id(lgfx::Bus_SPI* bus, int32_t pin_cs, uint32_t cmd = 0x04, uint8_t dummy_read_bit = 1) // 0x04 = RDDID command - { - bus->beginTransaction(); - _pin_level(pin_cs, false); - bus->writeCommand(cmd, 8); - bus->beginRead(dummy_read_bit); - uint32_t res = bus->readData(32); - bus->endTransaction(); - _pin_level(pin_cs, true); - - ESP_LOGW(LIBRARY_NAME, "[Autodetect] read cmd:%02x = %08x", cmd, res); - return res; - } - - void _set_backlight(ILight* bl) - { - if (_light_last) { delete _light_last; } - _light_last = bl; - _panel_last->setLight(bl); - } - - void _set_pwm_backlight(int16_t pin, uint8_t ch, uint32_t freq = 12000, bool invert = false) - { - auto bl = new lgfx::Light_PWM(); - auto cfg = bl->config(); - cfg.pin_bl = pin; - cfg.freq = freq; - cfg.pwm_channel = ch; - cfg.invert = invert; - bl->config(cfg); - _set_backlight(bl); - } - - bool init_impl(bool use_reset, bool use_clear) - { - static constexpr char NVS_KEY[] = "AUTODETECT"; - uint32_t nvs_board = 0; - uint32_t nvs_handle = 0; - if (0 == nvs_open(LIBRARY_NAME, NVS_READONLY, &nvs_handle)) - { - nvs_get_u32(nvs_handle, NVS_KEY, static_cast(&nvs_board)); - nvs_close(nvs_handle); - ESP_LOGW(LIBRARY_NAME, "[Autodetect] load from NVS : board:%d", nvs_board); - } - - if (0 == nvs_board) - { - - nvs_board = board_t::board_ESP32_S2_Kaluga_1; - - } - - auto board = (board_t)nvs_board; - - int retry = 4; - do - { - if (retry == 1) use_reset = true; - board = autodetect(use_reset, board); - //ESP_LOGI(LIBRARY_NAME,"autodetect board:%d", board); - } while (board_t::board_unknown == board && --retry >= 0); - _board = board; - /// autodetectの際にreset済みなのでここではuse_resetをfalseで呼び出す。 - bool res = LGFX_Device::init_impl(false, use_clear); - - if (nvs_board != board) { - if (0 == nvs_open(LIBRARY_NAME, NVS_READWRITE, &nvs_handle)) { - ESP_LOGW(LIBRARY_NAME, "[Autodetect] save to NVS : board:%d", board); - nvs_set_u32(nvs_handle, NVS_KEY, board); - nvs_close(nvs_handle); - } - } - return res; - } - - public: - - board_t autodetect(bool use_reset = true, board_t board = board_t::board_unknown) - { - auto bus_cfg = _bus_spi.config(); -// if (bus_cfg.pin_mosi != -1 && bus_cfg.pin_sclk != -1) return true; - - panel(nullptr); - - if (_panel_last) - { - delete _panel_last; - _panel_last = nullptr; - } - if (_light_last) - { - delete _light_last; - _light_last = nullptr; - } - if (_touch_last) - { - delete _touch_last; - _touch_last = nullptr; - } - - bus_cfg.freq_write = 8000000; - bus_cfg.freq_read = 8000000; - bus_cfg.spi_host = SPI2_HOST; - bus_cfg.spi_mode = 0; - bus_cfg.dma_channel = SPI_DMA_CH_AUTO; - bus_cfg.use_lock = true; - - uint32_t id; - (void)id; // suppress warning - - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_ESP32_S2_KALUGA_1 ) - - if (board == 0 || board == board_t::board_ESP32_S2_Kaluga_1) - { - bus_cfg.pin_mosi = 9; - bus_cfg.pin_miso = 8; - bus_cfg.pin_sclk = 15; - bus_cfg.pin_dc = 13; - bus_cfg.spi_mode = false; - bus_cfg.spi_3wire = false; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(16, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, 11); - if ((id & 0xFF) == 0x85) - { // check panel (ST7789) - board = board_t::board_ESP32_S2_Kaluga_1; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_ESP32_S2_Kaluga_1"); - bus_cfg.freq_write = 80000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = 11; - cfg.pin_rst = 16; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(6, 7, 12000); - goto init_clear; - } - lgfx::pinMode(16, lgfx::pin_mode_t::input); // LCD RST - _bus_spi.release(); - } -#endif - -// Feather S2 TFT screen is write-only, no LGFX_AUTODETECT -#if defined ( LGFX_FEATHER_ESP32_S2_TFT ) - if (board == 0 || board == board_t::board_Feather_ESP32_S2_TFT) - { - lgfx::pinMode(GPIO_NUM_21, lgfx::pin_mode_t::output); - lgfx::gpio_hi(GPIO_NUM_21); // Enable power to TFT - bus_cfg.pin_mosi = GPIO_NUM_35; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_36; - bus_cfg.pin_dc = GPIO_NUM_39; - bus_cfg.spi_mode = 0; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_40, use_reset); // LCD RST - board = board_t::board_Feather_ESP32_S2_TFT; - ESP_LOGW(LIBRARY_NAME, "board_Feather_ESP32_S2_TFT"); - bus_cfg.freq_write = 40000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_7; - cfg.pin_rst = GPIO_NUM_40; - cfg.panel_width = 135; - cfg.panel_height = 240; - cfg.offset_x = 52; - cfg.offset_y = 40; - cfg.readable = false; - cfg.rgb_order = false; - cfg.invert = true; - cfg.offset_rotation = 1; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_45, 0, 12000); - - goto init_clear; - } -#endif // end LGFX_FEATHER_ESP32_S2_TFT - -// FunHouse screen is write-only, no LGFX_AUTODETECT -#if defined ( LGFX_FUNHOUSE ) - if (board == 0 || board == board_t::board_FunHouse) - { - bus_cfg.pin_mosi = GPIO_NUM_35; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_36; - bus_cfg.pin_dc = GPIO_NUM_39; - bus_cfg.spi_mode = 0; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_41, use_reset); // LCD RST - board = board_t::board_FunHouse; - ESP_LOGW(LIBRARY_NAME, "board_FunHouse"); - bus_cfg.freq_write = 40000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_40; - cfg.pin_rst = GPIO_NUM_41; - cfg.panel_width = 240; - cfg.panel_height = 240; - cfg.readable = false; - cfg.rgb_order = false; - cfg.invert = true; - cfg.offset_rotation = 2; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_21, 0, 12000); - - goto init_clear; - } -#endif // end LGFX_FUNHOUSE - - board = board_t::board_unknown; - - goto init_clear; - init_clear: - - panel(_panel_last); - - return board; - } - }; - -//---------------------------------------------------------------------------- - } -} - -using LGFX = lgfx::LGFX; diff --git a/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32S3.hpp b/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32S3.hpp deleted file mode 100644 index 13c84421..00000000 --- a/src/lgfx/v1_autodetect/LGFX_AutoDetect_ESP32S3.hpp +++ /dev/null @@ -1,558 +0,0 @@ -/*----------------------------------------------------------------------------/ - Lovyan GFX - Graphics library for embedded devices. - -Original Source: - https://github.com/lovyan03/LovyanGFX/ - -Licence: - [FreeBSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt) - -Author: - [lovyan03](https://twitter.com/lovyan03) - -Contributors: - [ciniml](https://github.com/ciniml) - [mongonta0716](https://github.com/mongonta0716) - [tobozo](https://github.com/tobozo) -/----------------------------------------------------------------------------*/ -#pragma once - -#include "../v1_init.hpp" -#include "common.hpp" - -#include -#include -#include -#include -#include - - -#if defined ( ARDUINO_ESP32_S3_BOX ) - #define LGFX_ESP32_S3_BOX -#endif - -#if defined ( ARDUINO_ADAFRUIT_FEATHER_ESP32S3_TFT ) - #define LGFX_FEATHER_ESP32_S3_TFT -#endif - - -namespace lgfx -{ - inline namespace v1 - { -//---------------------------------------------------------------------------- - - static constexpr char LIBRARY_NAME[] = "LovyanGFX"; - - namespace m5stack - { - static constexpr int32_t i2c_freq = 400000; - static constexpr int_fast16_t aw9523_i2c_addr = 0x58; // AW9523B - static constexpr int_fast16_t axp_i2c_addr = 0x34; // AXP2101 - static constexpr int_fast16_t i2c_port = I2C_NUM_1; - static constexpr int_fast16_t i2c_sda = GPIO_NUM_12; - static constexpr int_fast16_t i2c_scl = GPIO_NUM_11; - } - - struct Panel_M5StackCoreS3 : public lgfx::Panel_ILI9342 - { - static constexpr gpio_num_t pin_miso_dc = GPIO_NUM_35; - Panel_M5StackCoreS3(void) - { - _cfg.pin_cs = GPIO_NUM_3; - _cfg.invert = true; - _cfg.offset_rotation = 3; - - _rotation = 1; // default rotation - } - - void reset(void) override - { - using namespace m5stack; - // AXP192 reg 0x96 = GPIO3&4 control - lgfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x03, 0, ~(1<<5), i2c_freq); // LCD_RST - lgfx::delay(4); - lgfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x03, (1<<5), ~0, i2c_freq); // LCD_RST - } - - void cs_control(bool flg) override - { - lgfx::Panel_ILI9342::cs_control(flg); - - // 0x43==FSPI MISO / 0x100==GPIO OUT - *(volatile uint32_t*)GPIO_FUNC35_OUT_SEL_CFG_REG = flg ? 0x43 : 0x100; - } - }; - - struct Touch_M5StackCoreS3 : public lgfx::Touch_FT5x06 - { - Touch_M5StackCoreS3(void) - { - using namespace m5stack; - _cfg.pin_int = GPIO_NUM_21; - _cfg.pin_sda = i2c_sda; - _cfg.pin_scl = i2c_scl; - _cfg.i2c_addr = 0x38; - _cfg.i2c_port = i2c_port; - _cfg.freq = i2c_freq; - _cfg.x_min = 0; - _cfg.x_max = 319; - _cfg.y_min = 0; - _cfg.y_max = 239; - _cfg.bus_shared = false; - } - - uint_fast8_t getTouchRaw(touch_point_t* tp, uint_fast8_t count) override - { - using namespace m5stack; - uint_fast8_t res = 0; - if (!gpio_in(_cfg.pin_int)) - { - res = lgfx::Touch_FT5x06::getTouchRaw(tp, count); - if (res == 0) - { /// clear INT. - // レジスタ 0x00を読み出すとPort0のINTがクリアされ、レジスタ 0x01を読み出すとPort1のINTがクリアされる。 - lgfx::i2c::readRegister8(i2c_port, aw9523_i2c_addr, 0x00, i2c_freq); - lgfx::i2c::readRegister8(i2c_port, aw9523_i2c_addr, 0x01, i2c_freq); - } - } - return res; - } - }; - - struct Light_M5StackCoreS3 : public lgfx::ILight - { - bool init(uint8_t brightness) override - { - setBrightness(brightness); - return true; - } - - void setBrightness(uint8_t brightness) override - { - using namespace m5stack; - - if (brightness) - { - brightness = (brightness / 25) + 18; - // AXP2101 reg 0x90 = LDOS ON/OFF control - lgfx::i2c::bitOn(i2c_port, axp_i2c_addr, 0x90, 0x80, i2c_freq); // DLDO1 enable - } - else - { - lgfx::i2c::bitOff(i2c_port, axp_i2c_addr, 0x90, 0x80, i2c_freq); // DLDO1 disable - } - // AXP2101 reg 0x99 = DLDO1 voltage setting - lgfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x99, brightness, 0, i2c_freq); - } - }; - - class LGFX : public LGFX_Device - { - lgfx::Panel_Device* _panel_last = nullptr; - lgfx::ILight* _light_last = nullptr; - lgfx::ITouch* _touch_last = nullptr; - lgfx::Bus_SPI _bus_spi; - - static void _pin_level(int_fast16_t pin, bool level) - { - lgfx::pinMode(pin, lgfx::pin_mode_t::output); - if (level) lgfx::gpio_hi(pin); - else lgfx::gpio_lo(pin); - } - - static void _pin_reset(int_fast16_t pin, bool use_reset) - { - lgfx::gpio_hi(pin); - lgfx::pinMode(pin, lgfx::pin_mode_t::output); - if (!use_reset) return; - lgfx::gpio_lo(pin); - auto time = lgfx::millis(); - do - { - lgfx::delay(1); - } while (lgfx::millis() - time < 2); - lgfx::gpio_hi(pin); - time = lgfx::millis(); - do - { - lgfx::delay(1); - } while (lgfx::millis() - time < 10); - } - - /// TF card dummy clock送信 ; - static void _send_sd_dummy_clock(int spi_host, int_fast16_t pin_cs) - { - static constexpr uint32_t dummy_clock[] = { ~0u, ~0u, ~0u, ~0u }; - _pin_level(pin_cs, true); - lgfx::spi::writeBytes(spi_host, (const uint8_t*)dummy_clock, sizeof(dummy_clock)); - _pin_level(pin_cs, false); - } - - /// TF card をSPIモードに移行する ; - static void _set_sd_spimode(int spi_host, int_fast16_t pin_cs) - { - lgfx::spi::beginTransaction(spi_host, 400000, 0); - _send_sd_dummy_clock(spi_host, pin_cs); - - uint8_t sd_cmd58[] = { 0x7A, 0, 0, 0, 0, 0xFD, 0xFF, 0xFF }; // READ_OCR command. - lgfx::spi::readBytes(spi_host, sd_cmd58, sizeof(sd_cmd58)); - -// ESP_LOGW(LIBRARY_NAME, "SD READ_OCR: %02x %02x", sd_cmd58[6], sd_cmd58[7]); - if (sd_cmd58[6] == sd_cmd58[7]) // not SPI mode - { - _send_sd_dummy_clock(spi_host, pin_cs); - - static constexpr uint8_t sd_cmd0[] = { 0x40, 0, 0, 0, 0, 0x95, 0xFF, 0xFF }; // GO_IDLE_STATE command. - lgfx::spi::writeBytes(spi_host, sd_cmd0, sizeof(sd_cmd0)); - } - _pin_level(pin_cs, true); - lgfx::spi::endTransaction(spi_host); - } - - static uint32_t _read_panel_id(lgfx::Bus_SPI* bus, int32_t pin_cs, uint32_t cmd = 0x04, uint8_t dummy_read_bit = 1) // 0x04 = RDDID command - { - bus->beginTransaction(); - _pin_level(pin_cs, true); - bus->writeCommand(0, 8); - bus->wait(); - _pin_level(pin_cs, false); - bus->writeCommand(cmd, 8); - bus->beginRead(dummy_read_bit); - uint32_t res = bus->readData(32); - bus->endTransaction(); - _pin_level(pin_cs, true); - - ESP_LOGW(LIBRARY_NAME, "[Autodetect] read cmd:%02x = %08x", (unsigned int)cmd, (unsigned int)res); - return res; - } - - void _set_backlight(ILight* bl) - { - if (_light_last) { delete _light_last; } - _light_last = bl; - _panel_last->setLight(bl); - } - - void _set_pwm_backlight(int16_t pin, uint8_t ch, uint32_t freq = 12000, bool invert = false) - { - auto bl = new lgfx::Light_PWM(); - auto cfg = bl->config(); - cfg.pin_bl = pin; - cfg.freq = freq; - cfg.pwm_channel = ch; - cfg.invert = invert; - bl->config(cfg); - _set_backlight(bl); - } - - bool init_impl(bool use_reset, bool use_clear) - { - static constexpr char NVS_KEY[] = "AUTODETECT"; - uint32_t nvs_board = 0; - uint32_t nvs_handle = 0; - if (0 == nvs_open(LIBRARY_NAME, NVS_READONLY, &nvs_handle)) - { - nvs_get_u32(nvs_handle, NVS_KEY, static_cast(&nvs_board)); - nvs_close(nvs_handle); - ESP_LOGW(LIBRARY_NAME, "[Autodetect] load from NVS : board:%d", (int)nvs_board); - } - - if (0 == nvs_board) - { -#if defined ( ARDUINO_ESP32_S3_BOX ) - - nvs_board = board_t::board_ESP32_S3_BOX; - -#endif - - } - - auto board = (board_t)nvs_board; - - int retry = 4; - do - { - if (retry == 1) use_reset = true; - board = autodetect(use_reset, board); - //ESP_LOGI(LIBRARY_NAME,"autodetect board:%d", board); - } while (board_t::board_unknown == board && --retry >= 0); - _board = board; - /// autodetectの際にreset済みなのでここではuse_resetをfalseで呼び出す。 - bool res = LGFX_Device::init_impl(false, use_clear); - - if (nvs_board != board) { - if (0 == nvs_open(LIBRARY_NAME, NVS_READWRITE, &nvs_handle)) { - ESP_LOGW(LIBRARY_NAME, "[Autodetect] save to NVS : board:%d", board); - nvs_set_u32(nvs_handle, NVS_KEY, board); - nvs_close(nvs_handle); - } - } - return res; - } - - public: - - board_t autodetect(bool use_reset = true, board_t board = board_t::board_unknown) - { - auto bus_cfg = _bus_spi.config(); - - panel(nullptr); - - if (_panel_last) - { - delete _panel_last; - _panel_last = nullptr; - } - if (_light_last) - { - delete _light_last; - _light_last = nullptr; - } - if (_touch_last) - { - delete _touch_last; - _touch_last = nullptr; - } - - bus_cfg.freq_write = 8000000; - bus_cfg.freq_read = 8000000; - bus_cfg.spi_host = SPI2_HOST; - bus_cfg.spi_mode = 0; - bus_cfg.dma_channel = SPI_DMA_CH_AUTO; - bus_cfg.use_lock = true; - - uint32_t id; - (void)id; // suppress warning - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5ATOM_S3LCD ) - - if (board == 0 || board == board_t::board_M5AtomS3) - { - bus_cfg.pin_mosi = GPIO_NUM_21; - bus_cfg.pin_miso = GPIO_NUM_13; - bus_cfg.pin_sclk = GPIO_NUM_17; - bus_cfg.pin_dc = GPIO_NUM_33; - bus_cfg.spi_mode = 0; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_34, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, GPIO_NUM_15); - if ((id & 0xFFFFFF) == 0x079100) - { // check panel (GC9107) - board = board_t::board_M5AtomS3; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5AtomS3"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_GC9107(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_15; - cfg.pin_rst = GPIO_NUM_34; - cfg.panel_width = 128; - cfg.panel_height = 128; - cfg.offset_y = 32; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_16, 7, 240); /// AtomS3のバックライトはPWM周期が速いと点灯しない; - - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_48, lgfx::pin_mode_t::input); // LCD RST - _bus_spi.release(); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_M5STACK_CORES3 ) - - if (board == 0 || board == board_t::board_M5StackCoreS3) - { - using namespace m5stack; - lgfx::i2c::init(i2c_port, i2c_sda, i2c_scl); - -// ESP_LOGI("DEBUG","AW 0x10 :%02x ", lgfx::i2c::readRegister8(i2c_port, aw9523_i2c_addr, 0x10, 400000).value()); -// ESP_LOGI("DEBUG","AXP0x03 :%02x ", lgfx::i2c::readRegister8(i2c_port, axp_i2c_addr, 0x03, 400000).value()); - - auto chk_axp = lgfx::i2c::readRegister8(i2c_port, axp_i2c_addr, 0x03, i2c_freq); - if (chk_axp.has_value() && chk_axp.value() == 0x4A) - { - auto chk_aw = lgfx::i2c::readRegister8(i2c_port, aw9523_i2c_addr, 0x10, i2c_freq); - if (chk_aw .has_value() && chk_aw .value() == 0x23) - { - lgfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x90, 0xBF); // LDOS ON/OFF control 0 - lgfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x95, 0x28); // ALDO3 set to 3.3v // for TF card slot - lgfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x96, (0b11110 - 7)); // BLDO1 => CAM AVDD 2.8V - lgfx::i2c::writeRegister8(i2c_port, axp_i2c_addr, 0x97, (0b00000 + 7)); // BLDO2 => CAM DVDD 1.2V - - lgfx::i2c::bitOn(i2c_port, aw9523_i2c_addr, 0x02, 0b10000110); - lgfx::i2c::bitOn(i2c_port, aw9523_i2c_addr, 0x03, 0b10100000); - lgfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x04, 0b01111000); // CONFIG_P0 - lgfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x05, 0b01011000); // CONFIG_P1 - lgfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x11, 0b00010000); // GCR P0 port is Push-Pull mode. - lgfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x12, 0b11111110); // LEDMODE_P0 - lgfx::i2c::writeRegister8(i2c_port, aw9523_i2c_addr, 0x13, 0b11111000); // LEDMODE_P1 - - bus_cfg.pin_mosi = GPIO_NUM_37; - bus_cfg.pin_miso = GPIO_NUM_35; - bus_cfg.pin_sclk = GPIO_NUM_36; - bus_cfg.pin_dc = GPIO_NUM_35; - bus_cfg.spi_mode = 0; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - - _set_sd_spimode(bus_cfg.spi_host, GPIO_NUM_4); - - id = _read_panel_id(&_bus_spi, GPIO_NUM_3); - if ((id & 0xFF) == 0xE3) - { // check panel (ILI9342) - board = board_t::board_M5StackCoreS3; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_M5StackCoreS3"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_M5StackCoreS3(); - p->bus(&_bus_spi); - _panel_last = p; - - _set_backlight(new Light_M5StackCoreS3()); - - { - auto t = new lgfx::Touch_M5StackCoreS3(); - _touch_last = t; - _panel_last->touch(t); - } - - goto init_clear; - } - _bus_spi.release(); - } - } - lgfx::i2c::release(i2c_port); - } -#endif - -#if defined ( LGFX_AUTODETECT ) || defined ( LGFX_ESP32_S3_BOX ) - - if (board == 0 || board == board_t::board_ESP32_S3_BOX) - { - bus_cfg.pin_mosi = GPIO_NUM_6; - bus_cfg.pin_miso = GPIO_NUM_0; - bus_cfg.pin_sclk = GPIO_NUM_7; - bus_cfg.pin_dc = GPIO_NUM_4; - bus_cfg.spi_mode = 0; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_48, use_reset); // LCD RST - id = _read_panel_id(&_bus_spi, GPIO_NUM_5); - if ((id & 0xFF) == 0xE3) - { // check panel (ILI9342) - board = board_t::board_ESP32_S3_BOX; - ESP_LOGW(LIBRARY_NAME, "[Autodetect] board_ESP32_S3_BOX"); - bus_cfg.freq_write = 40000000; - bus_cfg.freq_read = 16000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ILI9342(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_5; - cfg.pin_rst = GPIO_NUM_48; - cfg.offset_rotation = 1; - p->config(cfg); - p->setRotation(1); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_45, 0, 12000); - - { - auto t = new lgfx::Touch_TT21xxx(); - _touch_last = t; - auto cfg = t->config(); - cfg.pin_int = GPIO_NUM_3; - cfg.pin_sda = GPIO_NUM_8; - cfg.pin_scl = GPIO_NUM_18; - cfg.i2c_addr = 0x24; - cfg.i2c_port = I2C_NUM_1; - cfg.freq = 400000; - cfg.x_min = 0; - cfg.x_max = 319; - cfg.y_min = 0; - cfg.y_max = 239; - cfg.bus_shared = false; - t->config(cfg); - p->touch(t); - float affine[6] = { 1, 0, 0, 0, -1, 240 }; - p->setCalibrateAffine(affine); - } - - goto init_clear; - } - lgfx::pinMode(GPIO_NUM_48, lgfx::pin_mode_t::input); // LCD RST - _bus_spi.release(); - } -#endif - -// Feather S3 TFT screen is write-only, no LGFX_AUTODETECT -#if defined ( LGFX_FEATHER_ESP32_S3_TFT ) - if (board == 0 || board == board_t::board_Feather_ESP32_S3_TFT) - { - lgfx::pinMode(GPIO_NUM_21, lgfx::pin_mode_t::output); - lgfx::gpio_hi(GPIO_NUM_21); // Enable power to TFT - bus_cfg.pin_mosi = GPIO_NUM_35; - bus_cfg.pin_miso = -1; - bus_cfg.pin_sclk = GPIO_NUM_36; - bus_cfg.pin_dc = GPIO_NUM_39; - bus_cfg.spi_mode = 0; - bus_cfg.spi_3wire = true; - _bus_spi.config(bus_cfg); - _bus_spi.init(); - _pin_reset(GPIO_NUM_40, use_reset); // LCD RST - board = board_t::board_Feather_ESP32_S3_TFT; - ESP_LOGW(LIBRARY_NAME, "board_Feather_ESP32_S3_TFT"); - bus_cfg.freq_write = 40000000; - _bus_spi.config(bus_cfg); - auto p = new Panel_ST7789(); - p->bus(&_bus_spi); - { - auto cfg = p->config(); - cfg.pin_cs = GPIO_NUM_7; - cfg.pin_rst = GPIO_NUM_40; - cfg.panel_width = 135; - cfg.panel_height = 240; - cfg.offset_x = 52; - cfg.offset_y = 40; - cfg.readable = false; - cfg.rgb_order = false; - cfg.invert = true; - cfg.offset_rotation = 1; - p->config(cfg); - } - _panel_last = p; - _set_pwm_backlight(GPIO_NUM_45, 0, 12000); - - goto init_clear; - } -#endif // end LGFX_FEATHER_ESP32_S3_TFT - - board = board_t::board_unknown; - - goto init_clear; - init_clear: - - panel(_panel_last); - - return board; - } - }; - -//---------------------------------------------------------------------------- - } -} - -using LGFX = lgfx::LGFX; diff --git a/src/lgfx/v1_init.hpp b/src/lgfx/v1_init.hpp index a39fce13..fb362d37 100644 --- a/src/lgfx/v1_init.hpp +++ b/src/lgfx/v1_init.hpp @@ -57,6 +57,7 @@ Original Source: #include "v1/panel/Panel_M5UnitLCD.hpp" // TouchScreen +#include "v1/touch/Touch_CST816S.hpp" #include "v1/touch/Touch_FT5x06.hpp" #include "v1/touch/Touch_GSLx680.hpp" #include "v1/touch/Touch_GT911.hpp"