From c9f861ac09d340b9cd6820e8f7120278a6a17a1c Mon Sep 17 00:00:00 2001 From: Links Date: Sun, 17 Jan 2021 15:31:16 +0100 Subject: [PATCH 1/3] add ST7789 support --- .clang-format | 63 +++++++++++++++++++++++ .github/workflows/main.yml | 7 +++ README.md | 5 +- examples/VNC_ST7789/VNC_ST7789.ino | 78 ++++++++++++++++++++++++++++ library.json | 28 ++++++---- library.properties | 2 +- src/VNC.cpp | 2 + src/VNC.h | 1 + src/VNC_ST7789.cpp | 82 ++++++++++++++++++++++++++++++ src/VNC_ST7789.h | 62 ++++++++++++++++++++++ src/VNC_config.h | 1 + 11 files changed, 317 insertions(+), 14 deletions(-) create mode 100644 .clang-format create mode 100644 examples/VNC_ST7789/VNC_ST7789.ino create mode 100644 src/VNC_ST7789.cpp create mode 100644 src/VNC_ST7789.h diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..e72c54b --- /dev/null +++ b/.clang-format @@ -0,0 +1,63 @@ +--- +BasedOnStyle: Google +AccessModifierOffset: '-2' +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'false' +AlignEscapedNewlines: Left +AlignTrailingComments: 'true' +AllowAllParametersOfDeclarationOnNextLine: 'false' +AllowShortBlocksOnASingleLine: 'false' +AllowShortCaseLabelsOnASingleLine: 'false' +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: 'true' +AllowShortLoopsOnASingleLine: 'true' +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: 'true' +AlwaysBreakTemplateDeclarations: 'false' +BinPackParameters: 'true' +BreakAfterJavaFieldAnnotations: 'false' +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: 'false' +BreakBeforeTernaryOperators: 'false' +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: 'false' +ColumnLimit: '0' +CompactNamespaces: 'true' +ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' +ConstructorInitializerIndentWidth: '4' +ContinuationIndentWidth: '4' +Cpp11BracedListStyle: 'false' +DerivePointerAlignment: 'false' +FixNamespaceComments: 'true' +IndentCaseLabels: 'true' +IndentWidth: '4' +IndentWrappedFunctionNames: 'false' +JavaScriptQuotes: Single +JavaScriptWrapImports: 'false' +KeepEmptyLinesAtTheStartOfBlocks: 'false' +MaxEmptyLinesToKeep: '1' +NamespaceIndentation: All +ObjCBlockIndentWidth: '4' +ObjCSpaceAfterProperty: 'false' +ObjCSpaceBeforeProtocolList: 'false' +PointerAlignment: Middle +SortIncludes: 'false' +SortUsingDeclarations: 'true' +SpaceAfterCStyleCast: 'false' +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeParens: Never +SpaceInEmptyParentheses: 'false' +SpacesBeforeTrailingComments: '4' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInContainerLiterals: 'false' +SpacesInParentheses: 'false' +SpacesInSquareBrackets: 'false' +TabWidth: '4' +UseTab: Never + +... diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9413b91..e12f4bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -108,6 +108,12 @@ jobs: source $GITHUB_WORKSPACE/travis/common.sh clone_library https://github.com/Links2004/Adafruit_ILI9341 + - name: download TFT_eSPI + if: steps.cache_all.outputs.cache-hit != 'true' + run: | + source $GITHUB_WORKSPACE/travis/common.sh + clone_library https://github.com/Bodmer/TFT_eSPI + - name: download esp8266 if: steps.cache_all.outputs.cache-hit != 'true' run: | @@ -171,6 +177,7 @@ jobs: - name: copy code run: | + mkdir -p $HOME/Arduino/libraries/ cp -r $GITHUB_WORKSPACE $HOME/Arduino/libraries/arduinoVNC - name: config IDE diff --git a/README.md b/README.md index 23b8051..38aca8c 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,13 @@ Video: - ZLIB ##### Supported Hardware ##### - - ESP8266 [Arduino for ESP8266](https://github.com/Links2004/Arduino) - + - ESP8266 [Arduino for ESP8266](https://github.com/esp8266/Arduino) + - ESP32 [Arduino for ESP32](https://github.com/espressif/arduino-esp32) may run on Arduino DUE too. ##### Supported Displays ##### - ILI9341 [library](https://github.com/Links2004/Adafruit_ILI9341) + - ST7789 [library](https://github.com/Bodmer/TFT_eSPI) more possible using ```VNCdisplay``` Interface diff --git a/examples/VNC_ST7789/VNC_ST7789.ino b/examples/VNC_ST7789/VNC_ST7789.ino new file mode 100644 index 0000000..6299da7 --- /dev/null +++ b/examples/VNC_ST7789/VNC_ST7789.ino @@ -0,0 +1,78 @@ +/* + * VNC_ST7789.ino + * + * Created on: 17.01.2021 + * + * required librarys: + * - SPI (arduino core) + * - WiFi (arduino core) + * - arduinoVNC (https://github.com/Links2004/arduinoVNC) + * - TFT_eSPI (https://github.com/Bodmer/TFT_eSPI) + */ + +#include +#ifdef ESP8266 +#include +#else +#include +#endif +#include + +#include +#include +#include + +const char * vnc_ip = "192.168.1.12"; +const uint16_t vnc_port = 5900; +const char * vnc_pass = "12345678"; + +const char* ssid = "your-ssid"; +const char* password = "your-password"; + +ST7789VNC tft = ST7789VNC(); +arduinoVNC vnc = arduinoVNC(&tft); + +void setup(void) { + tft.begin(); + Serial.begin(115200); + + tft.setRotation(0); + tft.setTextSize(2); + tft.setCursor(0, 0, 1); + tft.println("Ready"); + + Serial.setDebugOutput(true); + Serial.println(); + Serial.println(); + Serial.println(); + + Serial.print("Connecting to "); + Serial.println(ssid); + + WiFi.begin(ssid, password); + while(WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + Serial.println(F("[SETUP] VNC...")); + + vnc.begin(vnc_ip, vnc_port); + //vnc.setPassword(vnc_pass); // check for vnc server settings +} + +void loop() { + if(WiFi.status() != WL_CONNECTED) { + vnc.reconnect(); + delay(100); + } else { + vnc.loop(); + if(!vnc.connected()) { + delay(5000); + } + } +} \ No newline at end of file diff --git a/library.json b/library.json index a3bce16..663d8ce 100644 --- a/library.json +++ b/library.json @@ -2,18 +2,24 @@ "name": "arduinoVNC", "keywords": "VNC, rfbproto, client, image, rfb", "description": "VNC Client for Arduino", - "repository": - { + "repository": { "type": "git", "url": "https://github.com/Links2004/arduinoVNC.git" }, - "exclude": "tests", "frameworks": "arduino", - "platforms": "esp8266", - "authors": - { - "name": "Markus Sattler", - "url": "https://github.com/Links2004", - "maintainer": true - } -} + "platforms": "esp8266, espressif32", + "authors": [ + { + "maintainer": true, + "name": "Markus Sattler", + "url": "https://github.com/Links2004" + } + ], + "export": { + "exclude": [ + "tests" + ] + }, + "version": "1.4", + "license": "GPL-2" +} \ No newline at end of file diff --git a/library.properties b/library.properties index bfb39dc..10b4468 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=arduinoVNC -version=1.3 +version=1.4 author=Markus Sattler maintainer=Markus Sattler sentence=VNC Client for Arduino diff --git a/src/VNC.cpp b/src/VNC.cpp index 155ac19..463afaa 100644 --- a/src/VNC.cpp +++ b/src/VNC.cpp @@ -129,6 +129,8 @@ void arduinoVNC::begin(char *_host, uint16_t _port, bool _onlyFullUpdate) { opt.h_offset = 0; opt.v_offset = 0; + display->vnc_options_override(&opt); + setMaxFPS(100); } diff --git a/src/VNC.h b/src/VNC.h index e3ecd27..bf7f694 100644 --- a/src/VNC.h +++ b/src/VNC.h @@ -160,6 +160,7 @@ class VNCdisplay { virtual void area_update_data(char *data, uint32_t pixel) = 0; virtual void area_update_end(void) = 0; + virtual void vnc_options_override(dfb_vnc_options * opt) {}; }; class arduinoVNC { diff --git a/src/VNC_ST7789.cpp b/src/VNC_ST7789.cpp new file mode 100644 index 0000000..0d1981b --- /dev/null +++ b/src/VNC_ST7789.cpp @@ -0,0 +1,82 @@ +/* + * @file VNC_ST7789.cpp + * @date 17.01.2021 + * @author Markus Sattler + * + * based on the work of modi12jin + * + * Copyright (c) 2021 Markus Sattler. All rights reserved. + * This file is part of the VNC client for Arduino. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, a copy can be downloaded from + * http://www.gnu.org/licenses/gpl.html, or obtained by writing to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * + */ + +#include "VNC_config.h" + +#ifdef VNC_ST7789 + +#include "VNC.h" + +#include +#include + +#include "VNC_ST7789.h" + +ST7789VNC::ST7789VNC() { + TFT_eSPI(); +} + +bool ST7789VNC::hasCopyRect(void) { + return false; +} + +uint32_t ST7789VNC::getHeight(void) { + return 240; +} + +uint32_t ST7789VNC::getWidth(void) { + return 240; +} + +void ST7789VNC::draw_area(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t * data) { + TFT_eSPI::pushImage(x, y, w, h, (uint16_t *)data); +} + +void ST7789VNC::draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t color) { + TFT_eSPI::fillRect(x, y, w, h, ((((color)&0xff) << 8) | (((color) >> 8)))); +} + +void ST7789VNC::copy_rect(uint32_t src_x, uint32_t src_y, uint32_t dest_x, uint32_t dest_y, uint32_t w, uint32_t h) { +} + +void ST7789VNC::area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { + TFT_eSPI::setAddrWindow(x, y, w, h); +} + +void ST7789VNC::area_update_data(char * data, uint32_t pixel) { + TFT_eSPI::pushPixels((uint8_t *)data, pixel); +} + +void ST7789VNC::area_update_end(void) { +} + +void vnc_options_override(dfb_vnc_options * opt) { + // TODO: may need to be swaped for ESP8266 + opt->client.bigendian = 1; +} +#endif \ No newline at end of file diff --git a/src/VNC_ST7789.h b/src/VNC_ST7789.h new file mode 100644 index 0000000..8041feb --- /dev/null +++ b/src/VNC_ST7789.h @@ -0,0 +1,62 @@ +/* + * @file VNC_ST7789.h + * @date 17.01.2021 + * @author Markus Sattler + * + * based on the work of modi12jin + * + * Copyright (c) 2021 Markus Sattler. All rights reserved. + * This file is part of the VNC client for Arduino. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, a copy can be downloaded from + * http://www.gnu.org/licenses/gpl.html, or obtained by writing to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * + */ + +#ifndef VNC_ST7789_H_ +#define VNC_ST7789_H_ + +#include "VNC_config.h" +#include +#include "VNC_ST7789.h" +#include "VNC.h" + +class ST7789VNC : public VNCdisplay, public TFT_eSPI { + public: + ST7789VNC(); + + bool hasCopyRect(void); + + uint32_t getHeight(void); + uint32_t getWidth(void); + + void draw_area(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t * data); + + void draw_rect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t color); + + void copy_rect(uint32_t src_x, uint32_t src_y, uint32_t dest_x, uint32_t dest_y, uint32_t w, uint32_t h); + + void area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h); + void area_update_data(char * data, uint32_t pixel); + void area_update_end(void); + + void vnc_options_override(dfb_vnc_options * opt); + + private: + uint32_t area_x, area_y, area_w, area_h; +}; + +#endif \ No newline at end of file diff --git a/src/VNC_config.h b/src/VNC_config.h index 3c129b2..64d916c 100644 --- a/src/VNC_config.h +++ b/src/VNC_config.h @@ -29,6 +29,7 @@ /// Display #define VNC_ILI9341 +#define VNC_ST7789 // RA8875 not fully implemented //#define VNC_RA8875 From 9720de31194a5b820d5b8a52e04ff15ec86559a4 Mon Sep 17 00:00:00 2001 From: Links Date: Sun, 17 Jan 2021 15:40:13 +0100 Subject: [PATCH 2/3] add missing class name --- src/VNC_ST7789.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VNC_ST7789.cpp b/src/VNC_ST7789.cpp index 0d1981b..566e0cb 100644 --- a/src/VNC_ST7789.cpp +++ b/src/VNC_ST7789.cpp @@ -75,7 +75,7 @@ void ST7789VNC::area_update_data(char * data, uint32_t pixel) { void ST7789VNC::area_update_end(void) { } -void vnc_options_override(dfb_vnc_options * opt) { +void ST7789VNC::vnc_options_override(dfb_vnc_options * opt) { // TODO: may need to be swaped for ESP8266 opt->client.bigendian = 1; } From 7b8782957d303acaebb7f713cdc9c07c314bba0b Mon Sep 17 00:00:00 2001 From: Links Date: Sun, 17 Jan 2021 15:48:41 +0100 Subject: [PATCH 3/3] update pio license string --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 663d8ce..e0417d2 100644 --- a/library.json +++ b/library.json @@ -21,5 +21,5 @@ ] }, "version": "1.4", - "license": "GPL-2" + "license": "GPL-2.0-or-later" } \ No newline at end of file