From 5e864f1d05667b9e88f8e60d54c423f6432ce8ac Mon Sep 17 00:00:00 2001 From: Csaba Nagy Date: Fri, 17 Apr 2015 21:51:28 +0200 Subject: [PATCH 1/4] Update platform.txt Quoting the serial.port will enable esptool to work for dev/tty devices with spaces in their name. Like in OSX: `/dev/tty.wch ch341 USB=>RS232 fa130`. Without quote the esptool fails silently since it only parses the `/dev/tty.wch`. --- hardware/esp8266com/esp8266/platform.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/esp8266com/esp8266/platform.txt b/hardware/esp8266com/esp8266/platform.txt index 505bfea89..3490ef416 100644 --- a/hardware/esp8266com/esp8266/platform.txt +++ b/hardware/esp8266com/esp8266/platform.txt @@ -91,5 +91,5 @@ tools.esptool.path={runtime.ide.path}/hardware/tools/esp8266 tools.esptool.upload.protocol=esp tools.esptool.upload.params.verbose=-vv tools.esptool.upload.params.quiet= -tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp {serial.port} -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x40000 -cf "{build.path}/{build.project_name}_40000.bin" +tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x40000 -cf "{build.path}/{build.project_name}_40000.bin" From 69158c293c70abcc3af41724b7530ccbd65a1bad Mon Sep 17 00:00:00 2001 From: "Bundit J." Date: Sat, 18 Apr 2015 15:33:45 +0700 Subject: [PATCH 2/4] Add get and put functions to EEPROM As available in http://www.arduino.cc/en/Reference/EEPROM --- .../esp8266/libraries/EEPROM/EEPROM.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h index 0c7068d1c..c51f759b7 100644 --- a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h +++ b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h @@ -35,6 +35,27 @@ class EEPROMClass void commit(); void end(); + template T &get(int address, T &t) + { + if (address < 0 || address >= _size) + return t; + + uint8_t *ptr = (uint8_t*) &t; + for(int count = 0; count < sizeof(T); ++count) *ptr++ = _data[address + count]; + return t; + } + + template const T &put(int address, const T &t) + { + if (address < 0 || address >= _size) + return t; + + const uint8_t *ptr = (const uint8_t*) &t; + for(int count = 0; count < sizeof(T); ++count) _data[address + count] = *ptr++; + _dirty = true; + return t; + } + protected: uint8_t* _data; size_t _size; From 7795695c2e1f7bbf9c20df437f52c6bc258e5e21 Mon Sep 17 00:00:00 2001 From: "Bundit J." Date: Sat, 18 Apr 2015 16:08:36 +0700 Subject: [PATCH 3/4] Add get and put functions to EEPROM As available in http://www.arduino.cc/en/Reference/EEPROM --- hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h index c51f759b7..961ff8b08 100644 --- a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h +++ b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h @@ -37,7 +37,7 @@ class EEPROMClass template T &get(int address, T &t) { - if (address < 0 || address >= _size) + if (address < 0 || address + sizeof(T) > _size) return t; uint8_t *ptr = (uint8_t*) &t; @@ -47,7 +47,7 @@ class EEPROMClass template const T &put(int address, const T &t) { - if (address < 0 || address >= _size) + if (address < 0 || address + sizeof(T) > _size) return t; const uint8_t *ptr = (const uint8_t*) &t; From 33f735c15d8bbf0448d941ed48d1091edfd0063d Mon Sep 17 00:00:00 2001 From: "Bundit J." Date: Sat, 18 Apr 2015 22:48:04 +0700 Subject: [PATCH 4/4] Use memcpy instead of loop --- hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h index 961ff8b08..52de83909 100644 --- a/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h +++ b/hardware/esp8266com/esp8266/libraries/EEPROM/EEPROM.h @@ -24,6 +24,7 @@ #include #include +#include class EEPROMClass { @@ -41,7 +42,7 @@ class EEPROMClass return t; uint8_t *ptr = (uint8_t*) &t; - for(int count = 0; count < sizeof(T); ++count) *ptr++ = _data[address + count]; + memcpy(ptr, _data + address, sizeof(T)); return t; } @@ -51,7 +52,7 @@ class EEPROMClass return t; const uint8_t *ptr = (const uint8_t*) &t; - for(int count = 0; count < sizeof(T); ++count) _data[address + count] = *ptr++; + memcpy(_data + address, ptr, sizeof(T)); _dirty = true; return t; }