From 8976021389cd58a2d4ea39790a1a3eea433a4f3d Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 20 Oct 2019 20:08:46 +0200 Subject: [PATCH 1/7] Add ArduinoHexParse library for specific page size --- lib/ArduinoHexParse/README.md | 3 + lib/ArduinoHexParse/keywords.txt | 25 ++++ lib/ArduinoHexParse/library.json | 12 ++ lib/ArduinoHexParse/library.properties | 9 ++ lib/ArduinoHexParse/src/ArduinoHexParse.cpp | 134 ++++++++++++++++++++ lib/ArduinoHexParse/src/ArduinoHexParse.h | 47 +++++++ 6 files changed, 230 insertions(+) create mode 100644 lib/ArduinoHexParse/README.md create mode 100644 lib/ArduinoHexParse/keywords.txt create mode 100644 lib/ArduinoHexParse/library.json create mode 100644 lib/ArduinoHexParse/library.properties create mode 100644 lib/ArduinoHexParse/src/ArduinoHexParse.cpp create mode 100644 lib/ArduinoHexParse/src/ArduinoHexParse.h diff --git a/lib/ArduinoHexParse/README.md b/lib/ArduinoHexParse/README.md new file mode 100644 index 000000000..c5c6a6751 --- /dev/null +++ b/lib/ArduinoHexParse/README.md @@ -0,0 +1,3 @@ +# ArduinoHexParse + +Parse hex files created by Arduino for Uno/Mini/Nano diff --git a/lib/ArduinoHexParse/keywords.txt b/lib/ArduinoHexParse/keywords.txt new file mode 100644 index 000000000..c60688578 --- /dev/null +++ b/lib/ArduinoHexParse/keywords.txt @@ -0,0 +1,25 @@ +####################################### +# Syntax Coloring Map for ArduinoHexParse +# (esp8266) +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +ArduinoHexParse KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +ArduinoHexParse KEYWORD2 +ParseLine KEYWORD2 +GetFlashPage KEYWORD2 +GetLoadAddress KEYWORD2 +IsFlashPageReady KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/lib/ArduinoHexParse/library.json b/lib/ArduinoHexParse/library.json new file mode 100644 index 000000000..896b53f6d --- /dev/null +++ b/lib/ArduinoHexParse/library.json @@ -0,0 +1,12 @@ +{ + "name": "ArduinoHexParse", + "version": "0.0.1", + "description": "Parse hex files created by Arduino for Uno/Mini/Nano", + "repository": + { + "type": "git", + "url": "https://github.com/arendst/Sonoff-Tasmota/lib/ArduinoHexParse" + }, + "frameworks": "arduino", + "platforms": "espressif8266" +} diff --git a/lib/ArduinoHexParse/library.properties b/lib/ArduinoHexParse/library.properties new file mode 100644 index 000000000..034c22e64 --- /dev/null +++ b/lib/ArduinoHexParse/library.properties @@ -0,0 +1,9 @@ +name=ArduinoHexParse +version=0.0.1 +author=Andre Thomas +maintainer=Andre Thomas +sentence=Parse hex files created by Arduino for Uno/Mini/Nano +paragraph= +category=Signal Input/Output +url= +architectures=esp8266 diff --git a/lib/ArduinoHexParse/src/ArduinoHexParse.cpp b/lib/ArduinoHexParse/src/ArduinoHexParse.cpp new file mode 100644 index 000000000..d4125f2f5 --- /dev/null +++ b/lib/ArduinoHexParse/src/ArduinoHexParse.cpp @@ -0,0 +1,134 @@ +/* + Copyright (C) 2019 Andre Thomas and Theo Arends + + 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, either version 3 of the License, or + (at your option) any later version. + + 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, see . +*/ + +#include +#include "ArduinoHexParse.h" + +ArduinoHexParse::ArduinoHexParse(void) +{ + loadAddress[0] = 0; + loadAddress[1] = 0; +} + +void ArduinoHexParse::ParseLine(byte* hexline) +{ + recordType = GetRecordType(hexline); + if (0 == recordType) { + address = GetAddress(hexline); + len = GetLength(hexline); + GetData(hexline, len); + if (128 == PageMemIdx) { + if (!firstRun) { + loadAddress[1] += 0x40; + if (0 == loadAddress[1]) { + loadAddress[0] += 1; + } + } + firstRun = false; + FlashPageReady = true; + PageMemIdx = 0; + } + nextAddress = address + len; + } + if (1 == recordType) { + EndOfFile(); + FlashPageReady = true; + } +} + +bool ArduinoHexParse::IsFlashPageReady(void) +{ + return FlashPageReady; +} + +byte* ArduinoHexParse::GetFlashPage(void) +{ + FlashPageReady = false; + return FlashPage; +} + +byte* ArduinoHexParse::GetLoadAddress(void) +{ + return loadAddress; +} + +void ArduinoHexParse::GetLoadAddress(byte* hexline) +{ + char buff[3]; + buff[2] = '\0'; + buff[0] = hexline[3]; + buff[1] = hexline[4]; + loadAddress[0] = strtol(buff, 0, 16); + buff[0] = hexline[5]; + buff[1] = hexline[6]; + loadAddress[1] = strtol(buff, 0, 16); +} + +byte* ArduinoHexParse::GetData(byte* hexline, uint32_t len) +{ + uint32_t start = 9; + uint32_t end = (len * 2) + start; + char buff[3]; + buff[2] = '\0'; + for (uint32_t x = start; x < end; x = x+2) { + buff[0] = hexline[x]; + buff[1] = hexline[x+1]; + FlashPage[PageMemIdx] = strtol(buff, 0, 16); + PageMemIdx++; + } +} + +void ArduinoHexParse::EndOfFile(void) +{ + loadAddress[1] += 0x40; + if (0 == loadAddress[1]) { + loadAddress[0] += 1; + } + while (128 > PageMemIdx) { // Fill the remaing space in the memory page with 0xFF + FlashPage[PageMemIdx] = 0xFF; + PageMemIdx++; + } +} + +uint32_t ArduinoHexParse::GetAddress(byte* hexline) +{ + char buff[5]; + buff[0] = hexline[3]; + buff[1] = hexline[4]; + buff[2] = hexline[5]; + buff[3] = hexline[6]; + buff[4] = '\0'; + return strtol(buff, 0, 16); +} + +uint16_t ArduinoHexParse::GetLength(byte* hexline) +{ + char buff[3]; + buff[0] = hexline[1]; + buff[1] = hexline[2]; + buff[2] = '\0'; + return strtol(buff, 0, 16); +} + +uint16_t ArduinoHexParse::GetRecordType(byte* hexline) +{ + char buff[3]; + buff[0] = hexline[7]; + buff[1] = hexline[8]; + buff[2] = '\0'; + return strtol(buff, 0, 16); +} diff --git a/lib/ArduinoHexParse/src/ArduinoHexParse.h b/lib/ArduinoHexParse/src/ArduinoHexParse.h new file mode 100644 index 000000000..7b941eea1 --- /dev/null +++ b/lib/ArduinoHexParse/src/ArduinoHexParse.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2019 Andre Thomas and Theo Arends + + 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, either version 3 of the License, or + (at your option) any later version. + + 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, see . +*/ + +#ifndef __ARDUINOHEXPARSE_H__ + +#include + +class ArduinoHexParse { + public: + ArduinoHexParse(void); + void ParseLine(byte* data); + byte* GetFlashPage(void); + byte* GetLoadAddress(void); + bool IsFlashPageReady(void); + private: + uint32_t address = 0; + uint32_t len = 0; + uint32_t nextAddress = 0; + uint32_t PageMemIdx = 0; + uint32_t recordType = 0; + byte FlashPage[128]; + byte loadAddress[2]; + bool FlashPageReady = false; + bool firstRun = true; + uint32_t GetAddress(byte* hexline); + uint16_t GetLength(byte* hexline); + uint16_t GetRecordType(byte* hexline); + byte* GetData(byte* hexline, uint32_t len); + void GetLoadAddress(byte* hexline); + void EndOfFile(void); +}; + +#endif // __ARDUINOHEXPARSE_H__ \ No newline at end of file From d84288b46e190b2e9f5c9798281ebb45d8b36c2f Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 20 Oct 2019 20:09:32 +0200 Subject: [PATCH 2/7] Update language files --- sonoff/language/bg-BG.h | 3 +++ sonoff/language/cs-CZ.h | 3 +++ sonoff/language/de-DE.h | 3 +++ sonoff/language/el-GR.h | 3 +++ sonoff/language/en-GB.h | 3 +++ sonoff/language/es-ES.h | 3 +++ sonoff/language/fr-FR.h | 3 +++ sonoff/language/he-HE.h | 3 +++ sonoff/language/hu-HU.h | 3 +++ sonoff/language/it-IT.h | 3 +++ sonoff/language/ko-KO.h | 3 +++ sonoff/language/nl-NL.h | 3 +++ sonoff/language/pl-PL.h | 3 +++ sonoff/language/pt-BR.h | 3 +++ sonoff/language/pt-PT.h | 3 +++ sonoff/language/ru-RU.h | 3 +++ sonoff/language/sk-SK.h | 3 +++ sonoff/language/sv-SE.h | 3 +++ sonoff/language/tr-TR.h | 3 +++ sonoff/language/uk-UK.h | 3 +++ sonoff/language/zh-CN.h | 3 +++ sonoff/language/zh-TW.h | 3 +++ 22 files changed, 66 insertions(+) diff --git a/sonoff/language/bg-BG.h b/sonoff/language/bg-BG.h index 47cc10d88..d765614f6 100644 --- a/sonoff/language/bg-BG.h +++ b/sonoff/language/bg-BG.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/cs-CZ.h b/sonoff/language/cs-CZ.h index f21911772..fd654c148 100644 --- a/sonoff/language/cs-CZ.h +++ b/sonoff/language/cs-CZ.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h index 93a44c9de..92e456f96 100644 --- a/sonoff/language/de-DE.h +++ b/sonoff/language/de-DE.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/el-GR.h b/sonoff/language/el-GR.h index 00d690e80..680633d6a 100644 --- a/sonoff/language/el-GR.h +++ b/sonoff/language/el-GR.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h index 2402e8c01..74a2fdca0 100644 --- a/sonoff/language/en-GB.h +++ b/sonoff/language/en-GB.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/es-ES.h b/sonoff/language/es-ES.h index 43c9b2fa9..2530fd6e4 100644 --- a/sonoff/language/es-ES.h +++ b/sonoff/language/es-ES.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/fr-FR.h b/sonoff/language/fr-FR.h index a33c48639..1522ec15f 100644 --- a/sonoff/language/fr-FR.h +++ b/sonoff/language/fr-FR.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/he-HE.h b/sonoff/language/he-HE.h index d31069675..3e5fe4031 100644 --- a/sonoff/language/he-HE.h +++ b/sonoff/language/he-HE.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/hu-HU.h b/sonoff/language/hu-HU.h index a5094fe44..f55f8ed38 100644 --- a/sonoff/language/hu-HU.h +++ b/sonoff/language/hu-HU.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/it-IT.h b/sonoff/language/it-IT.h index 6ac9a14d6..912e95ec1 100644 --- a/sonoff/language/it-IT.h +++ b/sonoff/language/it-IT.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/ko-KO.h b/sonoff/language/ko-KO.h index ac1ae34ce..35ae260b6 100644 --- a/sonoff/language/ko-KO.h +++ b/sonoff/language/ko-KO.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h index 5d0a6aacd..4091f9928 100644 --- a/sonoff/language/nl-NL.h +++ b/sonoff/language/nl-NL.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h index a167cfa7d..bd03d60e3 100644 --- a/sonoff/language/pl-PL.h +++ b/sonoff/language/pl-PL.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pt-BR.h b/sonoff/language/pt-BR.h index ae2349b8e..5d7b02613 100644 --- a/sonoff/language/pt-BR.h +++ b/sonoff/language/pt-BR.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/pt-PT.h b/sonoff/language/pt-PT.h index fd769a2e4..bfa234599 100644 --- a/sonoff/language/pt-PT.h +++ b/sonoff/language/pt-PT.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/ru-RU.h b/sonoff/language/ru-RU.h index 3f61e323b..13b721092 100644 --- a/sonoff/language/ru-RU.h +++ b/sonoff/language/ru-RU.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/sk-SK.h b/sonoff/language/sk-SK.h index 573975948..d35fff407 100644 --- a/sonoff/language/sk-SK.h +++ b/sonoff/language/sk-SK.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/sv-SE.h b/sonoff/language/sv-SE.h index 190e9b956..701ed43ac 100644 --- a/sonoff/language/sv-SE.h +++ b/sonoff/language/sv-SE.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/tr-TR.h b/sonoff/language/tr-TR.h index 9189de9ee..295664ae0 100755 --- a/sonoff/language/tr-TR.h +++ b/sonoff/language/tr-TR.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "A" diff --git a/sonoff/language/uk-UK.h b/sonoff/language/uk-UK.h index f09e80497..8030b1f2a 100644 --- a/sonoff/language/uk-UK.h +++ b/sonoff/language/uk-UK.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "А" diff --git a/sonoff/language/zh-CN.h b/sonoff/language/zh-CN.h index fdc8e1277..36f71ea4c 100644 --- a/sonoff/language/zh-CN.h +++ b/sonoff/language/zh-CN.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "安" diff --git a/sonoff/language/zh-TW.h b/sonoff/language/zh-TW.h index 85f68b991..53bd3e1a7 100644 --- a/sonoff/language/zh-TW.h +++ b/sonoff/language/zh-TW.h @@ -627,6 +627,9 @@ #define D_SENSOR_SM2135_DAT "SM2135 Dat" #define D_SENSOR_DEEPSLEEP "DeepSleep" #define D_SENSOR_EXS_ENABLE "EXS Enable" +#define D_SENSOR_ARDUINO_TX "Arduino TX" +#define D_SENSOR_ARDUINO_RX "Arduino RX" +#define D_SENSOR_ARDUINO_RESET "Arduino RST" // Units #define D_UNIT_AMPERE "安" From f97d1a56ed97798cb7bf2a67103a67148c761c17 Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 20 Oct 2019 20:10:14 +0200 Subject: [PATCH 3/7] Update my_user_config.h --- sonoff/my_user_config.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 33a3f9208..cbd0958f5 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -541,6 +541,11 @@ //#define USE_HRE // Add support for Badger HR-E Water Meter (+1k4 code) //#define USE_A4988_STEPPER // Add support for A4988/DRV8825 stepper-motor-driver-circuit (+10k5 code) +//#define USE_ARDUINO_SLAVE // Add support for Arduino Uno/Pro Mini via serial interface including flashing (+2k3 code, 44 mem) +// #define USE_ARDUINO_FLASH_SPEED 57600 // Usually 57600 for 3.3V variants and 115200 for 5V variants +// #define USE_ARDUINO_SERIAL_SPEED 57600 // Depends on the sketch that is running on the Uno/Pro Mini +// #define USE_ARDUINO_INVERT_RESET + // -- End of general directives ------------------- /*********************************************************************************************\ From 3411ad655dcde62b23997caf270d7405c811369a Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 20 Oct 2019 20:11:07 +0200 Subject: [PATCH 4/7] Add ArduinoSlave --- sonoff/xdrv_01_webserver.ino | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 04af1906f..b1037bdfd 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -44,7 +44,7 @@ const uint16_t HTTP_REFRESH_TIME = 2345; // milliseconds uint8_t *efm8bb1_update = nullptr; #endif // USE_RF_FLASH -enum UploadTypes { UPL_TASMOTA, UPL_SETTINGS, UPL_EFM8BB1 }; +enum UploadTypes { UPL_TASMOTA, UPL_SETTINGS, UPL_EFM8BB1, UPL_ARDUINOSLAVE }; static const char * HEADER_KEYS[] = { "User-Agent", }; @@ -2037,12 +2037,25 @@ void HandleUploadDone(void) WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "
"), WebColor(COL_TEXT_SUCCESS)); WSContentSend_P(HTTP_MSG_RSTRT); ShowWebSource(SRC_WEBGUI); +#ifdef USE_ARDUINO_SLAVE + if (ArduinoSlave_GetFlagFlashing()) { + restart_flag = 0; + } else { // It was a normal firmware file, or we are ready to restart device + restart_flag = 2; + } +#else restart_flag = 2; // Always restart to re-enable disabled features during update +#endif } SettingsBufferFree(); WSContentSend_P(PSTR("
")); WSContentSpaceButton(BUTTON_MAIN); WSContentStop(); +#ifdef USE_ARDUINO_SLAVE + if (ArduinoSlave_GetFlagFlashing()) { + ArduinoSlave_Flash(); + } +#endif } void HandleUploadLoop(void) @@ -2108,6 +2121,14 @@ void HandleUploadLoop(void) if (Web.upload_error != 0) { return; } } else #endif // USE_RF_FLASH +#ifdef USE_ARDUINO_SLAVE + if ((WEMOS == my_module_type) && (upload.buf[0] == ':')) { // Check if this is a ARDUINO SLAVE hex file + Update.end(); // End esp8266 update session + Web.upload_file_type = UPL_ARDUINOSLAVE; + Web.upload_error = ArduinoSlave_UpdateInit(); + if (Web.upload_error != 0) { return; } + } else +#endif { if (upload.buf[0] != 0xE9) { Web.upload_error = 3; // Magic byte is not 0xE9 @@ -2166,6 +2187,11 @@ void HandleUploadLoop(void) } } #endif // USE_RF_FLASH +#ifdef USE_ARDUINO_SLAVE + else if (UPL_ARDUINOSLAVE == Web.upload_file_type) { + ArduinoSlave_WriteBuffer(upload.buf, upload.currentSize); + } +#endif else { // firmware if (!Web.upload_error && (Update.write(upload.buf, upload.currentSize) != upload.currentSize)) { Web.upload_error = 5; // Upload buffer miscompare @@ -2217,6 +2243,13 @@ void HandleUploadLoop(void) Web.upload_file_type = UPL_TASMOTA; } #endif // USE_RF_FLASH +#ifdef USE_ARDUINO_SLAVE + else if (UPL_ARDUINOSLAVE == Web.upload_file_type) { + // Done writing the hex to SPI flash + ArduinoSlave_SetFlagFlashing(true); // So we know on upload success page if it needs to flash hex or do a normal restart + Web.upload_file_type = UPL_TASMOTA; + } +#endif else { if (!Update.end(true)) { // true to set the size to the current progress if (_serialoutput) { Update.printError(Serial); } From 711210c053aa01bae1e76581422de2ccf67bdde5 Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 20 Oct 2019 20:12:05 +0200 Subject: [PATCH 5/7] Add ArduinoSlave as xdrv_31 --- sonoff/xdrv_31_arduino_slave.ino | 277 +++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100644 sonoff/xdrv_31_arduino_slave.ino diff --git a/sonoff/xdrv_31_arduino_slave.ino b/sonoff/xdrv_31_arduino_slave.ino new file mode 100644 index 000000000..09e434126 --- /dev/null +++ b/sonoff/xdrv_31_arduino_slave.ino @@ -0,0 +1,277 @@ +/* + xdrv_31_arduino_slave.ino - Support for Arduino Slave on Serial + + Copyright (C) 2019 Andre Thomas and Theo Arends + + 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, either version 3 of the License, or + (at your option) any later version. + + 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, see . +*/ + +#ifdef USE_ARDUINO_SLAVE + +#include +#include + +#define CONST_STK_CRC_EOP 0x20 + +#define CMND_STK_GET_SYNC 0x30 +#define CMND_STK_SET_DEVICE 0x42 +#define CMND_STK_SET_DEVICE_EXT 0x45 +#define CMND_STK_ENTER_PROGMODE 0x50 +#define CMND_STK_LEAVE_PROGMODE 0x51 +#define CMND_STK_LOAD_ADDRESS 0x55 +#define CMND_STK_PROG_PAGE 0x64 + +uint32_t as_spi_hex_size = 0; +uint8_t as_spi_sector_start = 0x96; +uint8_t as_spi_sector_counter = 0x96; +uint8_t as_spi_sector_cursor = 0; +bool as_flashing = false; + +uint8_t as_type = 0; + +TasmotaSerial *ArduinoSlave_Serial; + +#define XDRV_31 31 + +uint8_t ArduinoSlave_UpdateInit(void) +{ + as_spi_hex_size = 0; + as_spi_sector_counter = as_spi_sector_start; // Reset the pre-defined write address where firmware will temporarily be stored + as_spi_sector_cursor = 0; + return 0; +} + +void ArduinoSlave_Reset(void) +{ + if (as_type) { +#ifdef USE_ARDUINO_INVERT_RESET + digitalWrite(pin[GPIO_ARDUINO_RESET], LOW); + delay(1); + digitalWrite(pin[GPIO_ARDUINO_RESET], HIGH); + delay(1); + digitalWrite(pin[GPIO_ARDUINO_RESET], LOW); + delay(5); +#else + digitalWrite(pin[GPIO_ARDUINO_RESET], HIGH); + delay(1); + digitalWrite(pin[GPIO_ARDUINO_RESET], LOW); + delay(1); + digitalWrite(pin[GPIO_ARDUINO_RESET], HIGH); + delay(5); +#endif + } +} + +uint8_t ArduinoSlave_waitForSerialData(int dataCount, int timeout) { + int timer = 0; + while (timer < timeout) { + if (ArduinoSlave_Serial->available() >= dataCount) { + return 1; + } + delay(1); + timer++; + } + return 0; +} + +byte ArduinoSlave_sendBytes(byte* bytes, int count) { + ArduinoSlave_Serial->write(bytes, count); + ArduinoSlave_waitForSerialData(2, 1000); + byte sync = ArduinoSlave_Serial->read(); + byte ok = ArduinoSlave_Serial->read(); + if (sync == 0x14 && ok == 0x10) { + return 1; + } + return 0; +} + +byte ArduinoSlave_execCmd(byte cmd) { + byte bytes[] = { cmd, CONST_STK_CRC_EOP }; + return ArduinoSlave_sendBytes(bytes, 2); +} + +byte ArduinoSlave_execParam(byte cmd, byte* params, int count) { + byte bytes[32]; + bytes[0] = cmd; + int i = 0; + while (i < count) { + bytes[i + 1] = params[i]; + i++; + } + bytes[i + 1] = CONST_STK_CRC_EOP; + return ArduinoSlave_sendBytes(bytes, i + 2); +} + +uint8_t ArduinoSlave_exitProgMode(void) +{ + return ArduinoSlave_execCmd(CMND_STK_LEAVE_PROGMODE); // Exit programming mode +} + +void ArduinoSlave_SetupFlash(void) +{ + byte ProgParams[] = {0x86,0x00,0x00,0x01,0x01,0x01,0x01,0x03,0xff,0xff,0xff,0xff,0x00,0x80,0x04,0x00,0x00,0x00,0x80,0x00}; + byte ExtProgParams[] = {0x05,0x04,0xd7,0xc2,0x00}; + ArduinoSlave_Serial->begin(USE_ARDUINO_FLASH_SPEED); + if (ArduinoSlave_Serial->hardwareSerial()) { + ClaimSerial(); + } + ArduinoSlave_Reset(); + ArduinoSlave_execCmd(CMND_STK_GET_SYNC); + ArduinoSlave_execParam(CMND_STK_SET_DEVICE, ProgParams, sizeof(ProgParams)); // Set programming parameters + ArduinoSlave_execParam(CMND_STK_SET_DEVICE_EXT, ExtProgParams, sizeof(ExtProgParams)); // Set extended programming parameters + ArduinoSlave_execCmd(CMND_STK_ENTER_PROGMODE); // Enter programming mode +} + +uint8_t ArduinoSlave_loadAddress(byte adrHi, byte adrLo) { + byte params[] = { adrHi, adrLo }; + return ArduinoSlave_execParam(CMND_STK_LOAD_ADDRESS, params, sizeof(params)); +} + +void ArduinoSlave_FlashPage(byte* address, byte* data) +{ + byte Header[] = {CMND_STK_PROG_PAGE, 0x00, 0x80, 0x46}; + ArduinoSlave_loadAddress(address[1], address[0]); + ArduinoSlave_Serial->write(Header, 4); + for (int i = 0; i < 128; i++) { + ArduinoSlave_Serial->write(data[i]); + } + ArduinoSlave_Serial->write(CONST_STK_CRC_EOP); + ArduinoSlave_waitForSerialData(2, 1000); + ArduinoSlave_Serial->read(); + ArduinoSlave_Serial->read(); +} + +void ArduinoSlave_Flash(void) +{ + bool reading = true; + uint32_t read = 0; + uint32_t processed = 0; + char thishexline[50]; + uint8_t position = 0; + char* flash_buffer; + ArduinoHexParse hexParse = ArduinoHexParse(); + + ArduinoSlave_SetupFlash(); + + flash_buffer = new char[SPI_FLASH_SEC_SIZE]; + while (reading) { + ESP.flashRead(0x96000 + read, (uint32_t*)flash_buffer, FLASH_SECTOR_SIZE); + read = read + FLASH_SECTOR_SIZE; + if (read >= as_spi_hex_size) { + reading = false; + } + for (uint16_t ca=0; cabegin(USE_ARDUINO_SERIAL_SPEED)) { + if (ArduinoSlave_Serial->hardwareSerial()) { + ClaimSerial(); + } + pinMode(pin[GPIO_ARDUINO_RESET], OUTPUT); + as_type = 1; + ArduinoSlave_Reset(); + AddLog_P2(LOG_LEVEL_INFO, PSTR("Arduino Slave Enabled")); + } + } +} + +void ArduinoSlave_Show(bool json) +{ + if (as_type) { + char buffer[100]; + ArduinoSlave_Serial->flush(); + ArduinoSlave_Serial->print("JSON"); + ArduinoSlave_Serial->find(char(0xFE)); + uint16_t haveread = ArduinoSlave_Serial->readBytesUntil(char(0xFF), buffer, sizeof(buffer)-1); + buffer[haveread] = '\0'; + if (json) { + ResponseAppend_P(PSTR(",\"ArduinoSlave\":%s"), buffer); + } + } +} + +bool Xdrv31(uint8_t function) +{ + bool result = false; + switch (function) { + case FUNC_EVERY_SECOND: + ArduinoSlave_Init(); + break; + case FUNC_JSON_APPEND: + ArduinoSlave_Show(1); + break; + case FUNC_COMMAND_DRIVER: + break; + default: + break; + } +} + +#endif // USE_ARDUINO_SLAVE \ No newline at end of file From 9ba9a25dc6a8554051283eef72f81699126803a1 Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 20 Oct 2019 20:12:55 +0200 Subject: [PATCH 6/7] Add ArduinoSlave to sonoff_template.h --- sonoff/sonoff_template.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index c6ed5b3e2..01fc75129 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -208,6 +208,9 @@ enum UserSelectablePins { GPIO_SM2135_DAT, // SM2135 Dat GPIO_DEEPSLEEP, // Kill switch for deepsleep GPIO_EXS_ENABLE, // EXS MCU Enable + GPIO_ARDUINO_TXD, // Arduino Slave TX + GPIO_ARDUINO_RXD, // Arduino Slave RX + GPIO_ARDUINO_RESET, // Arduino Reset Pin GPIO_SENSOR_END }; // Programmer selectable GPIO functionality @@ -286,6 +289,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_DDSU666_TX "|" D_SENSOR_DDSU666_RX "|" D_SENSOR_SM2135_CLK "|" D_SENSOR_SM2135_DAT "|" D_SENSOR_DEEPSLEEP "|" D_SENSOR_EXS_ENABLE "|" + D_SENSOR_ARDUINO_TX "|" D_SENSOR_ARDUINO_RX "|" D_SENSOR_ARDUINO_RESET "|" ; const char kSensorNamesFixed[] PROGMEM = @@ -698,6 +702,11 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_PN532_TXD, // PN532 HSU Tx GPIO_PN532_RXD, // PN532 HSU Rx #endif +#ifdef USE_ARDUINO_SLAVE + GPIO_ARDUINO_TXD, // Arduino Slave TX + GPIO_ARDUINO_RXD, // Arduino Slave RX + GPIO_ARDUINO_RESET, // Arduino Reset Pin +#endif #ifdef USE_RDM6300 GPIO_RDM6300_RX, #endif From 1d5920d1c8e719d034fc235f616ab51a26062046 Mon Sep 17 00:00:00 2001 From: andrethomas Date: Sun, 20 Oct 2019 20:14:17 +0200 Subject: [PATCH 7/7] Add ArduinoSlave Driver --- sonoff/_changelog.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 479f295aa..65820ecdf 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -4,6 +4,7 @@ * Add absolute PowerDelta using command PowerDelta 101..32000 where 101 = 101-100 = 1W, 202 = 202-100 = 102W (#5901) * Add support for EX-Store WiFi Dimmer V4 (#5856) * Add ZigbeeRead command and many improvements (#6095) + * Add ArduinoSlave driver (EXPERIMENTAL) * * 6.6.0.19 20191018 * Replace obsolete xsns_23_sdm120 with xnrg_08_sdm120 and consolidate define USE_SDM120