From 75538934955572cec762d1116d380fa1e5719714 Mon Sep 17 00:00:00 2001 From: Patrick Fallberg Date: Mon, 25 Jun 2018 09:21:45 +0200 Subject: [PATCH 01/31] Development version 2.3.1-alpha (#1154) --- README.md | 2 +- core/Version.h | 4 ++-- library.json | 2 +- library.properties | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ed896fa45..c56472174 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -MySensors Library v2.3.0 +MySensors Library v2.3.1-alpha Please visit www.mysensors.org for more information diff --git a/core/Version.h b/core/Version.h index 0107653fc..323ddf895 100644 --- a/core/Version.h +++ b/core/Version.h @@ -48,9 +48,9 @@ #define MYSENSORS_LIBRARY_VERSION_MAJOR 2 //!< Major release version #define MYSENSORS_LIBRARY_VERSION_MINOR 3 //!< Minor release version -#define MYSENSORS_LIBRARY_VERSION_PATCH 0 //!< Patch version +#define MYSENSORS_LIBRARY_VERSION_PATCH 1 //!< Patch version #define MYSENSORS_LIBRARY_VERSION_PRERELEASE "alpha" //!< Pre-release suffix, i.e. alpha, beta, rc.1, etc -#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0xFF //!< incremental counter, starting at 0x00. 0xFF for final release +#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0x00 //!< incremental counter, starting at 0x00. 0xFF for final release #if (MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER != 0xFF) diff --git a/library.json b/library.json index 53b328622..eebef8717 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/mysensors/MySensors.git" }, - "version": "2.3.0", + "version": "2.3.1-alpha", "frameworks": "arduino", "platforms": [ "atmelavr", diff --git a/library.properties b/library.properties index acc31d30a..01f1e648e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=MySensors -version=2.3.0 +version=2.3.1-alpha author=The MySensors Team maintainer=The MySensors Team sentence=Home Automation Framework From c6a970be8ba27ba84f1db83a686eb87cd85c3e64 Mon Sep 17 00:00:00 2001 From: Embedded Innovation Date: Mon, 30 Jul 2018 13:14:36 +0200 Subject: [PATCH 02/31] Prevent toggle ACTIVATE (#1164) Fix issue #1163. Prevent toggling advanced features on nRF24L01 non-plus versions. --- drivers/RF24/RF24.cpp | 15 +++++++++++++-- drivers/RF24/RF24.h | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index 58d8c3738..2620b5da6 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -179,6 +179,18 @@ LOCAL void RF24_setRFSetup(const uint8_t RFsetup) LOCAL void RF24_setFeature(const uint8_t feature) { RF24_writeByteRegister(RF24_REG_FEATURE, feature); + + if (RF24_getFeature() != feature) + { + // toggle features (necessary on some clones and non-P versions) + RF24_enableFeatures(); + RF24_writeByteRegister(RF24_REG_FEATURE, feature); + } +} + +LOCAL uint8_t RF24_getFeature(void) +{ + return RF24_readByteRegister(RF24_REG_FEATURE); } LOCAL void RF24_setPipe(const uint8_t pipe) @@ -220,6 +232,7 @@ LOCAL void RF24_setStatus(const uint8_t status) { RF24_writeByteRegister(RF24_REG_STATUS, status); } + LOCAL void RF24_enableFeatures(void) { RF24_RAW_writeByteRegister(RF24_CMD_ACTIVATE, 0x73); @@ -502,8 +515,6 @@ LOCAL bool RF24_initialize(void) RF24_setChannel(MY_RF24_CHANNEL); // set data rate and pa level RF24_setRFSetup(RF24_RF_SETUP); - // toggle features (necessary on some clones and non-P versions) - RF24_enableFeatures(); // enable ACK payload and dynamic payload RF24_setFeature(RF24_FEATURE); // sanity check (this function is P/non-P independent) diff --git a/drivers/RF24/RF24.h b/drivers/RF24/RF24.h index 4b182b7b5..56f6ce57a 100644 --- a/drivers/RF24/RF24.h +++ b/drivers/RF24/RF24.h @@ -320,6 +320,11 @@ LOCAL void RF24_setRFSetup(const uint8_t RFsetup); */ LOCAL void RF24_setFeature(const uint8_t feature); /** +* @brief RF24_getFeature +* @return +*/ +LOCAL uint8_t RF24_getFeature(void); +/** * @brief RF24_setPipe * @param pipe */ From 2badd59a71a096b1b14ce39d313e6c39835d79a1 Mon Sep 17 00:00:00 2001 From: tekka Date: Sat, 4 Aug 2018 20:40:54 +0200 Subject: [PATCH 03/31] ESP8266: Updates to support 2.4.2 board defs (#1169) --- .ci/arduino.groovy | 2 +- drivers/RF24/RF24.cpp | 3 +- hal/architecture/ESP8266/MyMainESP8266.cpp | 129 ++++++++++++++++----- 3 files changed, 99 insertions(+), 35 deletions(-) diff --git a/.ci/arduino.groovy b/.ci/arduino.groovy index 7037309f7..4409a342d 100644 --- a/.ci/arduino.groovy +++ b/.ci/arduino.groovy @@ -210,7 +210,7 @@ def buildSTM32F1(config, sketches, String key) { } def buildESP8266(config, sketches, String key) { - def fqbn = '-fqbn=esp8266:esp8266:generic:CpuFrequency=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,FlashSize=512K0,led=2,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=115200' + def fqbn = '-fqbn=esp8266:esp8266:generic:CpuFrequency=80,VTable=flash,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,FlashSize=512K0,led=2,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=115200' config.pr.setBuildStatus(config, 'PENDING', 'Toll gate (ESP8266 - '+key+')', 'Building...', '${BUILD_URL}flowGraphTable/') try { for (sketch = 0; sketch < sketches.size(); sketch++) { diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index 2620b5da6..29d04f9c4 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -180,8 +180,7 @@ LOCAL void RF24_setFeature(const uint8_t feature) { RF24_writeByteRegister(RF24_REG_FEATURE, feature); - if (RF24_getFeature() != feature) - { + if (RF24_getFeature() != feature) { // toggle features (necessary on some clones and non-P versions) RF24_enableFeatures(); RF24_writeByteRegister(RF24_REG_FEATURE, feature); diff --git a/hal/architecture/ESP8266/MyMainESP8266.cpp b/hal/architecture/ESP8266/MyMainESP8266.cpp index 5a871fa44..d71755157 100644 --- a/hal/architecture/ESP8266/MyMainESP8266.cpp +++ b/hal/architecture/ESP8266/MyMainESP8266.cpp @@ -6,7 +6,7 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB + * Copyright (C) 2013-2018 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org @@ -19,6 +19,7 @@ //This may be used to change user task stack size: //#define CONT_STACKSIZE 4096 +#include #include "Schedule.h" extern "C" { #include "ets_sys.h" @@ -29,14 +30,34 @@ extern "C" { #include "cont.h" } #include +#include "gdb_hooks.h" #define LOOP_TASK_PRIORITY 1 #define LOOP_QUEUE_SIZE 1 - #define OPTIMISTIC_YIELD_TIME_US 16000 +extern "C" void call_user_start(); +extern void loop(); +extern void setup(); +extern void(*__init_array_start)(void); +extern void(*__init_array_end)(void); + +/* Not static, used in Esp.cpp */ struct rst_info resetInfo; +/* Not static, used in core_esp8266_postmortem.c. +* Placed into noinit section because we assign value to this variable +* before .bss is zero-filled, and need to preserve the value. +*/ +cont_t* g_pcont __attribute__((section(".noinit"))); + +/* Event queue used by the main (arduino) task */ +static os_event_t s_loop_queue[LOOP_QUEUE_SIZE]; + +/* Used to implement optimistic_yield */ +static uint32_t s_micros_at_task_start; + + extern "C" { extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER; @@ -48,13 +69,6 @@ extern "C" { #endif } // extern "C" -int atexit(void(*func)()) -{ - (void)func; - return 0; -} - -extern "C" void ets_update_cpu_frequency(int freqmhz); void initVariant() __attribute__((weak)); void initVariant() { @@ -69,18 +83,11 @@ void preloop_update_frequency() #endif } -extern void(*__init_array_start)(void); -extern void(*__init_array_end)(void); - -cont_t g_cont __attribute__((aligned(16))); -static os_event_t g_loop_queue[LOOP_QUEUE_SIZE]; - -static uint32_t g_micros_at_task_start; extern "C" void esp_yield() { - if (cont_can_yield(&g_cont)) { - cont_yield(&g_cont); + if (cont_can_yield(g_pcont)) { + cont_yield(g_pcont); } } @@ -91,7 +98,7 @@ extern "C" void esp_schedule() extern "C" void __yield() { - if (cont_can_yield(&g_cont)) { + if (cont_can_yield(g_pcont)) { esp_schedule(); esp_yield(); } else { @@ -103,8 +110,8 @@ extern "C" void yield(void) __attribute__((weak, alias("__yield"))); extern "C" void optimistic_yield(uint32_t interval_us) { - if (cont_can_yield(&g_cont) && - (system_get_time() - g_micros_at_task_start) > interval_us) { + if (cont_can_yield(g_pcont) && + (system_get_time() - s_micros_at_task_start) > interval_us) { yield(); } } @@ -126,9 +133,9 @@ static void loop_wrapper() static void loop_task(os_event_t *events) { (void)events; - g_micros_at_task_start = system_get_time(); - cont_run(&g_cont, &loop_wrapper); - if (cont_check(&g_cont) != 0) { + s_micros_at_task_start = system_get_time(); + cont_run(g_pcont, &loop_wrapper); + if (cont_check(g_pcont) != 0) { panic(); } } @@ -141,12 +148,6 @@ static void do_global_ctors(void) } } -extern "C" void __gdb_init() {} -extern "C" void gdb_init(void) __attribute__((weak, alias("__gdb_init"))); - -extern "C" void __gdb_do_break() {} -extern "C" void gdb_do_break(void) __attribute__((weak, alias("__gdb_do_break"))); - void init_done() { system_set_os_print(1); @@ -155,6 +156,70 @@ void init_done() esp_schedule(); } +/* This is the entry point of the application. +* It gets called on the default stack, which grows down from the top +* of DRAM area. +* .bss has not been zeroed out yet, but .data and .rodata are in place. +* Cache is not enabled, so only ROM and IRAM functions can be called. +* Peripherals (except for SPI0 and UART0) are not initialized. +* This function does not return. +*/ +/* +A bit of explanation for this entry point: + +SYS is the SDK task/context used by the upperlying system to run its +administrative tasks (at least WLAN and lwip's receive callbacks and +Ticker). NONOS-SDK is designed to run user's non-threaded code in +another specific task/context with its own stack in BSS. + +Some clever fellows found that the SYS stack was a large and quite unused +piece of ram that we could use for the user's stack instead of using user's +main memory, thus saving around 4KB on ram/heap. + +A problem arose later, which is that this stack can heavily be used by +the SDK for some features. One of these features is WPS. We still don't +know if other features are using this, or if this memory is going to be +used in future SDK releases. + +WPS beeing flawed by its poor security, or not beeing used by lots of +users, it has been decided that we are still going to use that memory for +user's stack and disable the use of WPS, with an option to revert that +back at the user's discretion. This selection can be done with the +global define NO_EXTRA_4K_HEAP. An option has been added to the board +generator script. + +References: +https://github.com/esp8266/Arduino/pull/4553 +https://github.com/esp8266/Arduino/pull/4622 +https://github.com/esp8266/Arduino/issues/4779 +https://github.com/esp8266/Arduino/pull/4889 + +*/ + +#ifdef NO_EXTRA_4K_HEAP +/* this is the default NONOS-SDK user's heap location */ +cont_t g_cont __attribute__((aligned(16))); +#endif + +extern "C" void ICACHE_RAM_ATTR app_entry(void) +{ +#ifdef NO_EXTRA_4K_HEAP + + /* this is the default NONOS-SDK user's heap location */ + g_pcont = &g_cont; + +#else + + /* Allocate continuation context on this SYS stack, + and save pointer to it. */ + cont_t s_cont __attribute__((aligned(16))); + g_pcont = &s_cont; + +#endif + + /* Call the entry point of the SDK code. */ + call_user_start(); +} extern "C" void user_init(void) { @@ -167,10 +232,10 @@ extern "C" void user_init(void) initVariant(); - cont_init(&g_cont); + cont_init(g_pcont); ets_task(loop_task, - LOOP_TASK_PRIORITY, g_loop_queue, + LOOP_TASK_PRIORITY, s_loop_queue, LOOP_QUEUE_SIZE); system_init_done_cb(&init_done); From d0d0ee7e5ee6f30dff20cce2ea8911a8de9a14a9 Mon Sep 17 00:00:00 2001 From: Mikael Falkvidd Date: Mon, 6 Aug 2018 19:15:47 +0200 Subject: [PATCH 04/31] Add CPPFLAGS to configure output (#1168) Printing the CPPFLAGS might help people notice when they are not including all parameters on one line. --- configure | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/configure b/configure index ddf766658..27905be1e 100755 --- a/configure +++ b/configure @@ -663,6 +663,8 @@ else printf " ${OK} Encryption: Disabled.\n" fi +printf " ${OK} CPPFLAGS: $CPPFLAGS\n" + LDFLAGS="-pthread $LDFLAGS" CPPFLAGS="$CPUFLAGS $CPPFLAGS" @@ -676,7 +678,7 @@ elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then INIT_SYSTEM=sysvinit printf " ${OK} Init system detected: sysvinit.\n" else - printf " ${FAILED} Unknown init system." + printf " ${FAILED} Unknown init system.\n" fi printf "${SECTION} Saving configuration.\n" From 57e3294bcc82b8e4fa80b0b74419ada5fcc46ba4 Mon Sep 17 00:00:00 2001 From: tekka Date: Tue, 7 Aug 2018 16:00:48 +0200 Subject: [PATCH 05/31] Update library props and fix typo (#1173) --- core/MyTransport.h | 2 +- library.json | 8 ++------ library.properties | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/MyTransport.h b/core/MyTransport.h index 8d910ce2d..3985cf337 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -428,7 +428,7 @@ bool transportWaitUntilReady(const uint32_t waitingMS = 0); /** * @brief Initialize transport and SM */ -void transportInitialize(void); +void transportInitialise(void); /** * @brief Process FIFO msg and update SM */ diff --git a/library.json b/library.json index eebef8717..4e70025c3 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "name": "MySensors", "keywords": "framework, sensor, rf", - "description": "Home Automation Framework. Create your own wireless sensor mesh using NRF24L01+, RFM69 and RFM95 radios running on AVR, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers.", + "description": "Home Automation Framework. Create your own wireless sensor mesh using NRF24L01+, RFM69 and RFM95 radios running on AVR, ESP32, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers.", "repository": { "type": "git", @@ -9,11 +9,7 @@ }, "version": "2.3.1-alpha", "frameworks": "arduino", - "platforms": [ - "atmelavr", - "atmelsam", - "espressif8266" - ], + "platforms": "*", "export": { "exclude": [ "tests", diff --git a/library.properties b/library.properties index 01f1e648e..83c865ed0 100644 --- a/library.properties +++ b/library.properties @@ -3,7 +3,7 @@ version=2.3.1-alpha author=The MySensors Team maintainer=The MySensors Team sentence=Home Automation Framework -paragraph=Create your own wireless sensor mesh using NRF24L01+, RFM69 and RFM95 radios running on AVR, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers. +paragraph=Create your own wireless sensor mesh using NRF24L01+, RFM69 and RFM95 radios running on AVR, ESP32, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers. category=Communication url=https://www.mysensors.org architectures=* From 4a94fcfd4fafaf7511144baeadb942d64eefc955 Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 15 Aug 2018 14:32:08 +0200 Subject: [PATCH 06/31] GW: Send discovery message after startup --- core/MyTransport.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index 06f0c1450..0fa7ce24a 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -1,4 +1,4 @@ -/* +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -305,7 +305,8 @@ void stReadyTransition(void) void stReadyUpdate(void) { #if defined(MY_GATEWAY_FEATURE) - if (hwMillis() - _lastNetworkDiscovery > MY_TRANSPORT_DISCOVERY_INTERVAL_MS) { + if (!_lastNetworkDiscovery || + (hwMillis() - _lastNetworkDiscovery > MY_TRANSPORT_DISCOVERY_INTERVAL_MS)) { _lastNetworkDiscovery = hwMillis(); TRANSPORT_DEBUG(PSTR("TSM:READY:NWD REQ\n")); // send transport network discovery (void)transportRouteMessage(build(_msgTmp, BROADCAST_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, From 831e0e8cd232f7e749d06de3fb70db4255cb0924 Mon Sep 17 00:00:00 2001 From: tekka Date: Tue, 21 Aug 2018 19:20:06 +0200 Subject: [PATCH 07/31] Direct node2node traffic (#1174) --- core/MyTransport.cpp | 10 ++++- core/MyTransport.h | 2 + examples/Node2Node/Node2Node.ino | 68 ++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 examples/Node2Node/Node2Node.ino diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index 0fa7ce24a..ed7e114dc 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -547,10 +547,18 @@ bool transportRouteMessage(MyMessage &message) #endif } #else + if (destination > GATEWAY_ADDRESS && destination < BROADCAST_ADDRESS) { + // node2node traffic: assume node is in vincinity. If transmission fails, hand over to parent + if (transportSendWrite(destination, message)) { + TRANSPORT_DEBUG(PSTR("TSF:RTE:N2N OK\n")); + return true; + } + TRANSPORT_DEBUG(PSTR("!TSF:RTE:N2N FAIL\n")); + } route = _transportConfig.parentNodeId; // not a repeater, all traffic routed via parent #endif } - // send message, HAL + // send message const bool result = transportSendWrite(route, message); #if !defined(MY_GATEWAY_FEATURE) // update counter diff --git a/core/MyTransport.h b/core/MyTransport.h index 3985cf337..30af141fa 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -119,6 +119,8 @@ * | | TSF | SRT | OK | Saving routing table successful * |!| TSF | RTE | FPAR ACTIVE | Finding parent active, message not sent * |!| TSF | RTE | DST %%d UNKNOWN | Routing for destination (DST) unknown, send message to parent +* | | TSF | RTE | N2N OK | Node-to-node communication succeeded +* |!| TSF | RTE | N2N FAIL | Node-to-node communication failed, handing over to parent for re-routing * | | TSF | RRT | ROUTE N=%%d,R=%%d | Routing table, messages to node (N) are routed via node (R) * |!| TSF | SND | TNR | Transport not ready, message cannot be sent * | | TSF | TDI | TSL | Set transport to sleep diff --git a/examples/Node2Node/Node2Node.ino b/examples/Node2Node/Node2Node.ino new file mode 100644 index 000000000..0033e6152 --- /dev/null +++ b/examples/Node2Node/Node2Node.ino @@ -0,0 +1,68 @@ +/* + The MySensors Arduino library handles the wireless radio link and protocol + between your home built sensors/actuators and HA controller of choice. + The sensors forms a self healing radio network with optional repeaters. Each + repeater and gateway builds a routing tables in EEPROM which keeps track of the + network topology allowing messages to be routed to nodes. + + Created by Henrik Ekblad + Copyright (C) 2013-2018 Sensnology AB + Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + + Documentation: http://www.mysensors.org + Support Forum: http://forum.mysensors.org + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + +*/ + +#define MY_DEBUG +#define MY_RADIO_RF24 +#define CHILD_SENSOR_ID 0 +#define ACTUATOR_ID 200 +//#define SIGNING_ENABLED // enable for secure actuator + +#if defined(SIGNING_ENABLED) +// Signing, select soft/hardware signing method +#define MY_SIGNING_SOFT +//#define MY_SIGNING_ATSHA204 +#define MY_DEBUG_VERBOSE_SIGNING +// Enable this if you want destination node to sign all messages sent to this node. +//#define MY_SIGNING_REQUEST_SIGNATURES +#endif + +// triggering interval +static const uint32_t trigger_ms = 10000; + +#include "MySensors.h" +MyMessage msgGeneral(CHILD_SENSOR_ID, V_STATUS); +uint32_t lastTrigger = 0; +bool actuatorStatus = false; + +void presentation(void) +{ + sendSketchInfo("Node2Node", __DATE__); + present(CHILD_SENSOR_ID, S_BINARY, "Remote"); +} + +void setup() +{ +#if defined(SIGNING_ENABLED) + SET_SIGN(ACTUATOR_ID); // define signing requirements for remote node +#endif +} + +void loop() +{ + if (millis() - lastTrigger > trigger_ms) { + lastTrigger = millis(); + // set destination address + msgGeneral.setDestination(ACTUATOR_ID); + // send message to node + send(msgGeneral.set(actuatorStatus)); + // invert status + actuatorStatus ^= true; + } +} From 2e406f51350f46c473ae7bf9ebdef25e7781d978 Mon Sep 17 00:00:00 2001 From: tekka Date: Tue, 21 Aug 2018 19:30:11 +0200 Subject: [PATCH 08/31] Introduce CryptoHAL, optimize crypto functions (#1178) --- MyASM.S | 1067 +++++++++++++++++ MySensors.h | 10 +- core/MySigning.cpp | 50 +- core/MySigning.h | 27 - core/MySigningAtsha204Soft.cpp | 211 ++-- drivers/ATSHA204/sha256.cpp | 216 ---- drivers/ATSHA204/sha256.h | 49 - .../SecurityPersonalizer.ino | 26 +- hal/architecture/AVR/MyHwAVR.h | 2 + hal/architecture/ESP32/MyHwESP32.h | 2 + hal/architecture/ESP8266/MyHwESP8266.h | 2 + hal/architecture/Linux/MyHwLinuxGeneric.h | 2 + hal/architecture/NRF5/MyHwNRF5.cpp | 2 + hal/architecture/NRF5/MyHwNRF5.h | 2 + hal/architecture/SAMD/MyHwSAMD.h | 2 + hal/architecture/STM32F1/MyHwSTM32F1.h | 2 + hal/architecture/Teensy3/MyHwTeensy3.h | 9 +- hal/crypto/AVR/MyCryptoAVR.cpp | 101 ++ hal/crypto/AVR/MyCryptoAVR.h | 155 +++ hal/crypto/ESP32/MyCryptoESP32.cpp | 73 ++ hal/crypto/ESP32/MyCryptoESP32.h | 27 + hal/crypto/MyCryptoHAL.h | 49 + hal/crypto/generic/MyCryptoGeneric.cpp | 225 ++++ hal/crypto/generic/MyCryptoGeneric.h | 50 + 24 files changed, 1901 insertions(+), 460 deletions(-) create mode 100644 MyASM.S delete mode 100644 drivers/ATSHA204/sha256.cpp delete mode 100644 drivers/ATSHA204/sha256.h create mode 100644 hal/crypto/AVR/MyCryptoAVR.cpp create mode 100644 hal/crypto/AVR/MyCryptoAVR.h create mode 100644 hal/crypto/ESP32/MyCryptoESP32.cpp create mode 100644 hal/crypto/ESP32/MyCryptoESP32.h create mode 100644 hal/crypto/MyCryptoHAL.h create mode 100644 hal/crypto/generic/MyCryptoGeneric.cpp create mode 100644 hal/crypto/generic/MyCryptoGeneric.h diff --git a/MyASM.S b/MyASM.S new file mode 100644 index 000000000..a87b93d90 --- /dev/null +++ b/MyASM.S @@ -0,0 +1,1067 @@ +/* + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Henrik Ekblad + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + */ + +#if defined(ARDUINO_ARCH_NRF5) +/* workaround to prevent compiler error */ + .thumb_func +doNothing: + nop + .size doNothing, .-doNothing + +#elif defined(ARDUINO_ARCH_AVR) +/* + * This file is part of the AVR-Crypto-Lib. + * Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) + * + * 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 . + * + * Author: Daniel Otte + * + * License: GPLv3 or later + */ +; sha-256 implementation in assembler +SHA256_BLOCK_BITS = 512 +SHA256_HASH_BITS = 256 + + +.macro precall + /* push r18 - r27, r30 - r31*/ + push r0 + push r1 + push r18 + push r19 + push r20 + push r21 + push r22 + push r23 + push r24 + push r25 + push r26 + push r27 + push r30 + push r31 + clr r1 +.endm + +.macro postcall + pop r31 + pop r30 + pop r27 + pop r26 + pop r25 + pop r24 + pop r23 + pop r22 + pop r21 + pop r20 + pop r19 + pop r18 + pop r1 + pop r0 +.endm + + +.macro hexdump length + push r27 + push r26 + ldi r25, '\r' + mov r24, r25 + call uart_putc + ldi r25, '\n' + mov r24, r25 + call uart_putc + pop r26 + pop r27 + movw r24, r26 +.if \length > 16 + ldi r22, lo8(16) + ldi r23, hi8(16) + push r27 + push r26 + call uart_hexdump + pop r26 + pop r27 + adiw r26, 16 + hexdump \length-16 +.else + ldi r22, lo8(\length) + ldi r23, hi8(\length) + call uart_hexdump +.endif +.endm + +/* X points to Block */ +.macro dbg_hexdump length + precall + hexdump \length + postcall +.endm + +.section .text + +SPL = 0x3D +SPH = 0x3E +SREG = 0x3F + + +; +;sha256_ctx_t is: +; +; [h0][h1][h2][h3][h4][h5][h6][h7][length] +; hn is 32 bit large, length is 64 bit large + +;########################################################### + +.global sha256_ctx2hash +; === sha256_ctx2hash === +; this function converts a state into a normal hash (bytestring) +; param1: the 16-bit destination pointer +; given in r25,r24 (r25 is most significant) +; param2: the 16-bit pointer to sha256_ctx structure +; given in r23,r22 +sha256_ctx2hash: + movw r26, r22 + movw r30, r24 + ldi r21, 8 + sbiw r26, 4 +1: + ldi r20, 4 + adiw r26, 8 +2: + ld r0, -X + st Z+, r0 + dec r20 + brne 2b + + dec r21 + brne 1b + + ret + +;########################################################### + +.global sha256 +; === sha256 === +; this function calculates SHA-256 hashes from messages in RAM +; param1: the 16-bit hash destination pointer +; given in r25,r24 (r25 is most significant) +; param2: the 16-bit pointer to message +; given in r23,r22 +; param3: 32-bit length value (length of message in bits) +; given in r21,r20,r19,r18 +sha256: +sha256_prolog: + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r16 + push r17 + in r30, SPL + in r31, SPH + sbiw r30, 8*4+8 + in r0, SREG + cli + out SPL, r30 + out SREG, r0 + out SPH, r31 + + push r25 + push r24 + adiw r30, 1 + movw r16, r30 + movw r8, r18 /* backup of length*/ + movw r10, r20 + + movw r12, r22 /* backup pf msg-ptr */ + + movw r24, r16 + rcall sha256_init + /* if length > 0xffff */ +1: + tst r11 + brne 2f + tst r10 + breq 4f +2: + movw r24, r16 + movw r22, r12 + rcall sha256_nextBlock + ldi r19, 64 + add r12, r19 + adc r13, r1 + /* length -= 512 */ + ldi r19, 0x02 + sub r9, r19 + sbc r10, r1 + sbc r11, r1 + rjmp 1b + +4: + movw r24, r16 + movw r22, r12 + movw r20, r8 + rcall sha256_lastBlock + + pop r24 + pop r25 + movw r22, r16 + rcall sha256_ctx2hash + +sha256_epilog: + in r30, SPL + in r31, SPH + adiw r30, 8*4+8 + in r0, SREG + cli + out SPL, r30 + out SREG, r0 + out SPH, r31 + pop r17 + pop r16 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + ret + +;########################################################### + + +; block MUST NOT be larger than 64 bytes + +.global sha256_lastBlock +; === sha256_lastBlock === +; this function does padding & Co. for calculating SHA-256 hashes +; param1: the 16-bit pointer to sha256_ctx structure +; given in r25,r24 (r25 is most significant) +; param2: an 16-bit pointer to 64 byte block to hash +; given in r23,r22 +; param3: an 16-bit integer specifing length of block in bits +; given in r21,r20 +sha256_lastBlock_localSpace = (SHA256_BLOCK_BITS/8+1) + + +sha256_lastBlock: + cpi r21, 0x02 + brlo sha256_lastBlock_prolog + push r25 + push r24 + push r23 + push r22 + push r21 + push r20 + rcall sha256_nextBlock + pop r20 + pop r21 + pop r22 + pop r23 + pop r24 + pop r25 + subi r21, 0x02 + ldi r19, 64 + add r22, r19 + adc r23, r1 + rjmp sha256_lastBlock +sha256_lastBlock_prolog: + /* allocate space on stack */ + in r30, SPL + in r31, SPH + in r0, SREG + subi r30, lo8(64) + sbci r31, hi8(64) + cli + out SPL, r30 + out SREG,r0 + out SPH, r31 + + adiw r30, 1 /* SP points to next free byte on stack */ + mov r18, r20 /* r20 = LSB(length) */ + lsr r18 + lsr r18 + lsr r18 + bst r21, 0 /* may be we should explain this ... */ + bld r18, 5 /* now: r18 == length/8 (aka. length in bytes) */ + + + movw r26, r22 /* X points to begin of msg */ + tst r18 + breq sha256_lastBlock_post_copy + mov r1, r18 +sha256_lastBlock_copy_loop: + ld r0, X+ + st Z+, r0 + dec r1 + brne sha256_lastBlock_copy_loop +sha256_lastBlock_post_copy: +sha256_lastBlock_insert_stuffing_bit: + ldi r19, 0x80 + mov r0,r19 + ldi r19, 0x07 + and r19, r20 /* if we are in bitmode */ + breq 2f /* no bitmode */ +1: + lsr r0 + dec r19 + brne 1b + ld r19, X +/* maybe we should do some ANDing here, just for safety */ + or r0, r19 +2: + st Z+, r0 + inc r18 + +/* checking stuff here */ + cpi r18, 64-8+1 + brsh 0f + rjmp sha256_lastBlock_insert_zeros +0: + /* oh shit, we landed here */ + /* first we have to fill it up with zeros */ + ldi r19, 64 + sub r19, r18 + breq 2f +1: + st Z+, r1 + dec r19 + brne 1b +2: + sbiw r30, 63 + sbiw r30, 1 + movw r22, r30 + + push r31 + push r30 + push r25 + push r24 + push r21 + push r20 + rcall sha256_nextBlock + pop r20 + pop r21 + pop r24 + pop r25 + pop r30 + pop r31 + + /* now we should subtract 512 from length */ + movw r26, r24 + adiw r26, 4*8+1 /* we can skip the lowest byte */ + ld r19, X + subi r19, hi8(512) + st X+, r19 + ldi r18, 6 +1: + ld r19, X + sbci r19, 0 + st X+, r19 + dec r18 + brne 1b + +; clr r18 /* not neccessary ;-) */ + /* reset Z pointer to begin of block */ + +sha256_lastBlock_insert_zeros: + ldi r19, 64-8 + sub r19, r18 + breq sha256_lastBlock_insert_length + clr r1 +1: + st Z+, r1 /* r1 is still zero */ + dec r19 + brne 1b + +; rjmp sha256_lastBlock_epilog +sha256_lastBlock_insert_length: + movw r26, r24 /* X points to state */ + adiw r26, 8*4 /* X points to (state.length) */ + adiw r30, 8 /* Z points one after the last byte of block */ + ld r0, X+ + add r0, r20 + st -Z, r0 + ld r0, X+ + adc r0, r21 + st -Z, r0 + ldi r19, 6 +1: + ld r0, X+ + adc r0, r1 + st -Z, r0 + dec r19 + brne 1b + + sbiw r30, 64-8 + movw r22, r30 + rcall sha256_nextBlock + +sha256_lastBlock_epilog: + in r30, SPL + in r31, SPH + in r0, SREG + adiw r30, 63 ; lo8(64) + adiw r30, 1 ; hi8(64) + cli + out SPL, r30 + out SREG,r0 + out SPH, r31 + clr r1 + ret + +/**/ +;########################################################### + +.global sha256_nextBlock +; === sha256_nextBlock === +; this is the core function for calculating SHA-256 hashes +; param1: the 16-bit pointer to sha256_ctx structure +; given in r25,r24 (r25 is most significant) +; param2: an 16-bit pointer to 64 byte block to hash +; given in r23,r22 +sha256_nextBlock_localSpace = (64+8)*4 ; 64 32-bit values for w array and 8 32-bit values for a array (total 288 byte) + +Bck1 = 12 +Bck2 = 13 +Bck3 = 14 +Bck4 = 15 +Func1 = 22 +Func2 = 23 +Func3 = 24 +Func4 = 25 +Accu1 = 16 +Accu2 = 17 +Accu3 = 18 +Accu4 = 19 +XAccu1 = 8 +XAccu2 = 9 +XAccu3 = 10 +XAccu4 = 11 +T1 = 4 +T2 = 5 +T3 = 6 +T4 = 7 +LoopC = 1 +/* byteorder: high number <--> high significance */ +sha256_nextBlock: + ; initial, let's make some space ready for local vars + push r4 /* replace push & pop by mem ops? */ + push r5 + push r6 + push r7 + push r8 + push r9 + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + push r16 + push r17 + push r28 + push r29 + in r20, SPL + in r21, SPH + movw r18, r20 ;backup SP +; movw r26, r20 ; X points to free space on stack + movw r30, r22 ; Z points to message + subi r20, lo8(sha256_nextBlock_localSpace) ;sbiw can do only up to 63 + sbci r21, hi8(sha256_nextBlock_localSpace) + movw r26, r20 ; X points to free space on stack + in r0, SREG + cli ; we want to be uninterrupted while updating SP + out SPL, r20 + out SREG, r0 + out SPH, r21 + push r18 + push r19 + push r24 + push r25 /* param1 will be needed later */ + ; now we fill the w array with message (think about endianess) + adiw r26, 1 ; X++ + ldi r20, 16 +sha256_nextBlock_wcpyloop: + ld r23, Z+ + ld r22, Z+ + ld r19, Z+ + ld r18, Z+ + st X+, r18 + st X+, r19 + st X+, r22 + st X+, r23 + dec r20 + brne sha256_nextBlock_wcpyloop +/* for (i=16; i<64; ++i){ + w[i] = SIGMA_b(w[i-2]) + w[i-7] + SIGMA_a(w[i-15]) + w[i-16]; + } */ + /* r25,r24,r23,r24 (r21,r20) are function values + r19,r18,r17,r16 are the accumulator + r15,r14,r13,rBck1 are backup1 + r11,r10,r9 ,r8 are xor accu + r1 is round counter */ + + ldi r20, 64-16 + mov LoopC, r20 +sha256_nextBlock_wcalcloop: + movw r30, r26 ; cp X to Z + sbiw r30, 63 + sbiw r30, 1 ; substract 64 = 16*4 + ld Accu1, Z+ + ld Accu2, Z+ + ld Accu3, Z+ + ld Accu4, Z+ /* w[i] = w[i-16] */ + ld Bck1, Z+ + ld Bck2, Z+ + ld Bck3, Z+ + ld Bck4, Z+ /* backup = w[i-15] */ + /* now sigma 0 */ + mov Func1, Bck2 + mov Func2, Bck3 + mov Func3, Bck4 + mov Func4, Bck1 /* prerotated by 8 */ + ldi r20, 1 + rcall bitrotl + movw XAccu1, Func1 + movw XAccu3, Func3 /* store ROTR(w[i-15],7) in xor accu */ + movw Func1, Bck3 + movw Func3, Bck1 /* prerotated by 16 */ + ldi r20, 2 + rcall bitrotr + eor XAccu1, Func1 /* xor ROTR(w[i-15], 18)*/ + eor XAccu2, Func2 + eor XAccu3, Func3 + eor XAccu4, Func4 + ldi Func2, 3 /* now shr3 */ /*we can destroy backup now*/ +sigma0_shr: + lsr Bck4 + ror Bck3 + ror Bck2 + ror Bck1 + dec Func2 + brne sigma0_shr + eor XAccu1, Bck1 + eor XAccu2, Bck2 + eor XAccu3, Bck3 + eor XAccu4, Bck4 /* xor SHR(w[i-15], 3)*/ /* xor accu == sigma1(w[i-15]) */ + add Accu1, XAccu1 + adc Accu2, XAccu2 + adc Accu3, XAccu3 + adc Accu4, XAccu4 /* finished with sigma0 */ + ldd Func1, Z+7*4 /* now accu += w[i-7] */ + ldd Func2, Z+7*4+1 + ldd Func3, Z+7*4+2 + ldd Func4, Z+7*4+3 + add Accu1, Func1 + adc Accu2, Func2 + adc Accu3, Func3 + adc Accu4, Func4 + ldd Bck1, Z+12*4 /* now backup = w[i-2]*/ + ldd Bck2, Z+12*4+1 + ldd Bck3, Z+12*4+2 + ldd Bck4, Z+12*4+3 + /* now sigma 1 */ + movw Func1, Bck3 + movw Func3, Bck1 /* prerotated by 16 */ + ldi r20, 1 + rcall bitrotr + movw XAccu3, Func3 + movw XAccu1, Func1 /* store in ROTR(w[i-2], 17) xor accu */ +; movw Func1, Bck3 +; movw Func3, Bck1 /* prerotated by 16 */ + ldi r20, 2 + rcall bitrotr + eor XAccu1, Func1 /* xor ROTR(w[i-2], 19)*/ + eor XAccu2, Func2 + eor XAccu3, Func3 + eor XAccu4, Func4 + ldi Func2, 2 /* now shr10 (dirty trick, skipping a byte) */ /*we can destroy backup now*/ +sigma1_shr: + lsr Bck4 + ror Bck3 + ror Bck2 + dec Func2 + brne sigma1_shr + eor XAccu1, Bck2 + eor XAccu2, Bck3 + eor XAccu3, Bck4 /* xor SHR(w[i-2], 10)*/ /* xor accu == sigma1(w[i-15]) */ + add Accu1, XAccu1 + adc Accu2, XAccu2 + adc Accu3, XAccu3 + adc Accu4, XAccu4 /* finished with sigma0 */ + /* now let's store the shit */ + st X+, Accu1 + st X+, Accu2 + st X+, Accu3 + st X+, Accu4 + dec LoopC + breq 3f ; skip if zero + rjmp sha256_nextBlock_wcalcloop +3: + /* we are finished with w array X points one byte post w */ +/* init a array */ + pop r31 + pop r30 + push r30 + push r31 + ldi r25, 8*4 /* 8 32-bit values to copy from ctx to a array */ +init_a_array: + ld r1, Z+ + st X+, r1 + dec r25 + brne init_a_array + +/* now the real fun begins */ +/* for (i=0; i<64; ++i){ + t1 = a[7] + SIGMA1(a[4]) + CH(a[4],a[5],a[6]) + k[i] + w[i]; + t2 = SIGMA0(a[0]) + MAJ(a[0],a[1],a[2]); + memmove(&(a[1]), &(a[0]), 7*4); // a[7]=a[6]; a[6]=a[5]; a[5]=a[4]; a[4]=a[3]; a[3]=a[2]; a[2]=a[1]; a[1]=a[0]; + a[4] += t1; + a[0] = t1 + t2; + } */ + /* Y points to a[0], Z ('cause lpm wants it) points to k[i], X points to w[i] */ + sbiw r26, 8*4 /* X still points at a[7]+1*/ + movw r28, r26 + ldi r30, lo8(sha256_kv) + ldi r31, hi8(sha256_kv) + dec r27 /* X - (64*4 == 256) */ + ldi r25, 64 + mov LoopC, r25 +sha256_main_loop: + /* now calculate t1 */ + /*CH(x,y,z) = (x&y)^((~x)&z)*/ + ldd T1, Y+5*4 + ldd T2, Y+5*4+1 + ldd T3, Y+5*4+2 + ldd T4, Y+5*4+3 /* y in T */ + ldd Func1, Y+4*4 + ldd Func2, Y+4*4+1 + ldd Func3, Y+4*4+2 + ldd Func4, Y+4*4+3 /* x in Func */ + ldd Bck1, Y+6*4 + ldd Bck2, Y+6*4+1 + ldd Bck3, Y+6*4+2 + ldd Bck4, Y+6*4+3 /* z in Bck */ + and T1, Func1 + and T2, Func2 + and T3, Func3 + and T4, Func4 + com Func1 + com Func2 + com Func3 + com Func4 + and Bck1, Func1 + and Bck2, Func2 + and Bck3, Func3 + and Bck4, Func4 + eor T1, Bck1 + eor T2, Bck2 + eor T3, Bck3 + eor T4, Bck4 /* done, CH(x,y,z) is in T */ + /* now SIGMA1(a[4]) */ + ldd Bck4, Y+4*4 /* think about using it from Func reg above*/ + ldd Bck1, Y+4*4+1 + ldd Bck2, Y+4*4+2 + ldd Bck3, Y+4*4+3 /* load prerotate by 8-bit */ + movw Func1, Bck1 + movw Func3, Bck3 + ldi r20, 2 + rcall bitrotl /* rotr(x,6) */ + movw XAccu1, Func1 + movw XAccu3, Func3 + movw Func1, Bck1 + movw Func3, Bck3 + ldi r20, 3 + rcall bitrotr /* rotr(x,11) */ + eor XAccu1, Func1 + eor XAccu2, Func2 + eor XAccu3, Func3 + eor XAccu4, Func4 + movw Func1, Bck3 /* this prerotates furteh 16 bits*/ + movw Func3, Bck1 /* so we have now prerotated by 24 bits*/ + ldi r20, 1 + rcall bitrotr /* rotr(x,11) */ + eor XAccu1, Func1 + eor XAccu2, Func2 + eor XAccu3, Func3 + eor XAccu4, Func4 /* finished with SIGMA1, add it to T */ + add T1, XAccu1 + adc T2, XAccu2 + adc T3, XAccu3 + adc T4, XAccu4 + /* now we've to add a[7], w[i] and k[i] */ + ldd XAccu1, Y+4*7 + ldd XAccu2, Y+4*7+1 + ldd XAccu3, Y+4*7+2 + ldd XAccu4, Y+4*7+3 + add T1, XAccu1 + adc T2, XAccu2 + adc T3, XAccu3 + adc T4, XAccu4 /* add a[7] */ + ld XAccu1, X+ + ld XAccu2, X+ + ld XAccu3, X+ + ld XAccu4, X+ + add T1, XAccu1 + adc T2, XAccu2 + adc T3, XAccu3 + adc T4, XAccu4 /* add w[i] */ + lpm XAccu1, Z+ + lpm XAccu2, Z+ + lpm XAccu3, Z+ + lpm XAccu4, Z+ + add T1, XAccu1 + adc T2, XAccu2 + adc T3, XAccu3 + adc T4, XAccu4 /* add k[i] */ /* finished with t1 */ + /*now t2 = SIGMA0(a[0]) + MAJ(a[0],a[1],a[2]) */ /*i did to much x86 asm, i always see 4 32bit regs*/ + /* starting with MAJ(x,y,z) */ + ldd Func1, Y+4*0+0 + ldd Func2, Y+4*0+1 + ldd Func3, Y+4*0+2 + ldd Func4, Y+4*0+3 /* load x=a[0] */ + ldd XAccu1, Y+4*1+0 + ldd XAccu2, Y+4*1+1 + ldd XAccu3, Y+4*1+2 + ldd XAccu4, Y+4*1+3 /* load y=a[1] */ + and XAccu1, Func1 + and XAccu2, Func2 + and XAccu3, Func3 + and XAccu4, Func4 /* XAccu == (x & y) */ + ldd Bck1, Y+4*2+0 + ldd Bck2, Y+4*2+1 + ldd Bck3, Y+4*2+2 + ldd Bck4, Y+4*2+3 /* load z=a[2] */ + and Func1, Bck1 + and Func2, Bck2 + and Func3, Bck3 + and Func4, Bck4 + eor XAccu1, Func1 + eor XAccu2, Func2 + eor XAccu3, Func3 + eor XAccu4, Func4 /* XAccu == (x & y) ^ (x & z) */ + ldd Func1, Y+4*1+0 + ldd Func2, Y+4*1+1 + ldd Func3, Y+4*1+2 + ldd Func4, Y+4*1+3 /* load y=a[1] */ + and Func1, Bck1 + and Func2, Bck2 + and Func3, Bck3 + and Func4, Bck4 + eor XAccu1, Func1 + eor XAccu2, Func2 + eor XAccu3, Func3 + eor XAccu4, Func4 /* XAccu == Maj(x,y,z) == (x & y) ^ (x & z) ^ (y & z) */ + /* SIGMA0(a[0]) */ + ldd Bck1, Y+4*0+0 /* we should combine this with above */ + ldd Bck2, Y+4*0+1 + ldd Bck3, Y+4*0+2 + ldd Bck4, Y+4*0+3 + movw Func1, Bck1 + movw Func3, Bck3 + ldi r20, 2 + rcall bitrotr + movw Accu1, Func1 + movw Accu3, Func3 /* Accu = shr(a[0], 2) */ + movw Func1, Bck3 + movw Func3, Bck1 /* prerotate by 16 bits */ + ldi r20, 3 + rcall bitrotl + eor Accu1, Func1 + eor Accu2, Func2 + eor Accu3, Func3 + eor Accu4, Func4 /* Accu ^= shr(a[0], 13) */ + mov Func1, Bck4 + mov Func2, Bck1 + mov Func3, Bck2 + mov Func4, Bck3 /* prerotate by 24 bits */ + ldi r20, 2 + rcall bitrotl + eor Accu1, Func1 + eor Accu2, Func2 + eor Accu3, Func3 + eor Accu4, Func4 /* Accu ^= shr(a[0], 22) */ + add Accu1, XAccu1 /* add previous result (MAJ)*/ + adc Accu2, XAccu2 + adc Accu3, XAccu3 + adc Accu4, XAccu4 + /* now we are finished with the computing stuff (t1 in T, t2 in Accu)*/ + /* a[7]=a[6]; a[6]=a[5]; a[5]=a[4]; a[4]=a[3]; a[3]=a[2]; a[2]=a[1]; a[1]=a[0]; */ + + ldi r21, 7*4 + adiw r28, 7*4 +a_shift_loop: + ld r25, -Y /* warning: this is PREdecrement */ + std Y+4, r25 + dec r21 + brne a_shift_loop + + ldd Bck1, Y+4*4+0 + ldd Bck2, Y+4*4+1 + ldd Bck3, Y+4*4+2 + ldd Bck4, Y+4*4+3 + add Bck1, T1 + adc Bck2, T2 + adc Bck3, T3 + adc Bck4, T4 + std Y+4*4+0, Bck1 + std Y+4*4+1, Bck2 + std Y+4*4+2, Bck3 + std Y+4*4+3, Bck4 + add Accu1, T1 + adc Accu2, T2 + adc Accu3, T3 + adc Accu4, T4 + std Y+4*0+0, Accu1 + std Y+4*0+1, Accu2 + std Y+4*0+2, Accu3 + std Y+4*0+3, Accu4 /* a array updated */ + + + dec LoopC + breq update_state + rjmp sha256_main_loop ;brne sha256_main_loop +update_state: + /* update state */ + /* pointers to state should still exist on the stack ;-) */ + pop r31 + pop r30 + ldi r21, 8 +update_state_loop: + ldd Accu1, Z+0 + ldd Accu2, Z+1 + ldd Accu3, Z+2 + ldd Accu4, Z+3 + ld Func1, Y+ + ld Func2, Y+ + ld Func3, Y+ + ld Func4, Y+ + add Accu1, Func1 + adc Accu2, Func2 + adc Accu3, Func3 + adc Accu4, Func4 + st Z+, Accu1 + st Z+, Accu2 + st Z+, Accu3 + st Z+, Accu4 + dec r21 + brne update_state_loop + /* now we just have to update the length */ + adiw r30, 1 /* since we add 512, we can simply skip the LSB */ + ldi r21, 2 + ldi r22, 6 + ld r20, Z + add r20, r21 + st Z+, r20 + clr r21 +sha256_nextBlock_fix_length: + brcc sha256_nextBlock_epilog + ld r20, Z + adc r20, r21 + st Z+, r20 + dec r22 + brne sha256_nextBlock_fix_length + +; EPILOG +sha256_nextBlock_epilog: +/* now we should clean up the stack */ + + pop r21 + pop r20 + in r0, SREG + cli ; we want to be uninterrupted while updating SP + out SPL, r20 + out SREG, r0 + out SPH, r21 + clr r1 + pop r29 + pop r28 + pop r17 + pop r16 + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + pop r9 + pop r8 + pop r7 + pop r6 + pop r5 + pop r4 + ret + +sha256_kv: ; round-key-vector stored in ProgMem +.word 0x2f98, 0x428a, 0x4491, 0x7137, 0xfbcf, 0xb5c0, 0xdba5, 0xe9b5, 0xc25b, 0x3956, 0x11f1, 0x59f1, 0x82a4, 0x923f, 0x5ed5, 0xab1c +.word 0xaa98, 0xd807, 0x5b01, 0x1283, 0x85be, 0x2431, 0x7dc3, 0x550c, 0x5d74, 0x72be, 0xb1fe, 0x80de, 0x06a7, 0x9bdc, 0xf174, 0xc19b +.word 0x69c1, 0xe49b, 0x4786, 0xefbe, 0x9dc6, 0x0fc1, 0xa1cc, 0x240c, 0x2c6f, 0x2de9, 0x84aa, 0x4a74, 0xa9dc, 0x5cb0, 0x88da, 0x76f9 +.word 0x5152, 0x983e, 0xc66d, 0xa831, 0x27c8, 0xb003, 0x7fc7, 0xbf59, 0x0bf3, 0xc6e0, 0x9147, 0xd5a7, 0x6351, 0x06ca, 0x2967, 0x1429 +.word 0x0a85, 0x27b7, 0x2138, 0x2e1b, 0x6dfc, 0x4d2c, 0x0d13, 0x5338, 0x7354, 0x650a, 0x0abb, 0x766a, 0xc92e, 0x81c2, 0x2c85, 0x9272 +.word 0xe8a1, 0xa2bf, 0x664b, 0xa81a, 0x8b70, 0xc24b, 0x51a3, 0xc76c, 0xe819, 0xd192, 0x0624, 0xd699, 0x3585, 0xf40e, 0xa070, 0x106a +.word 0xc116, 0x19a4, 0x6c08, 0x1e37, 0x774c, 0x2748, 0xbcb5, 0x34b0, 0x0cb3, 0x391c, 0xaa4a, 0x4ed8, 0xca4f, 0x5b9c, 0x6ff3, 0x682e +.word 0x82ee, 0x748f, 0x636f, 0x78a5, 0x7814, 0x84c8, 0x0208, 0x8cc7, 0xfffa, 0x90be, 0x6ceb, 0xa450, 0xa3f7, 0xbef9, 0x78f2, 0xc671 + + +;########################################################### + +.global sha256_init +;uint32_t sha256_init_vector[]={ +; 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, +; 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 }; +; +;void sha256_init(sha256_ctx_t *state){ +; state->length=0; +; memcpy(state->h, sha256_init_vector, 8*4); +;} +; param1: (r23,r24) 16-bit pointer to sha256_ctx_t struct in ram +; modifys: Z(r30,r31), Func1, r22 +sha256_init: + movw r26, r24 ; (24,25) --> (26,27) load X with param1 + ldi r30, lo8((sha256_init_vector)) + ldi r31, hi8((sha256_init_vector)) + ldi r22, 32+8 +sha256_init_vloop: + lpm r23, Z+ + st X+, r23 + dec r22 + brne sha256_init_vloop + ret + +sha256_init_vector: +.word 0xE667, 0x6A09 +.word 0xAE85, 0xBB67 +.word 0xF372, 0x3C6E +.word 0xF53A, 0xA54F +.word 0x527F, 0x510E +.word 0x688C, 0x9B05 +.word 0xD9AB, 0x1F83 +.word 0xCD19, 0x5BE0 +.word 0x0000, 0x0000 +.word 0x0000, 0x0000 + +;########################################################### + +.global rotl32 +; === ROTL32 === +; function that rotates a 32 bit word to the left +; param1: the 32-bit word to rotate +; given in r25,r24,r23,r22 (r25 is most significant) +; param2: an 8-bit value telling how often to rotate +; given in r20 +; modifys: r21, r22 +rotl32: + cpi r20, 8 + brlo bitrotl + mov r21, r25 + mov r25, r24 + mov r24, r23 + mov r23, r22 + mov r22, r21 + subi r20, 8 + rjmp rotl32 +bitrotl: + clr r21 + clc +bitrotl_loop: + tst r20 + breq fixrotl +2: + rol r22 + rol r23 + rol r24 + rol r25 + rol r21 + dec r20 + brne 2b +fixrotl: + or r22, r21 + ret + + +;########################################################### + +.global rotr32 +; === ROTR32 === +; function that rotates a 32 bit word to the right +; param1: the 32-bit word to rotate +; given in r25,r24,r23,22 (r25 is most significant) +; param2: an 8-bit value telling how often to rotate +; given in r20 +; modifys: r21, r22 +rotr32: + cpi r20, 8 + brlo bitrotr + mov r21, r22 + mov r22, r23 + mov r23, r24 + mov r24, r25 + mov r25, r21 + subi r20, 8 + rjmp rotr32 +bitrotr: + clr r21 + clc +bitrotr_loop: + tst r20 + breq fixrotr +2: + ror r25 + ror r24 + ror r23 + ror r22 + ror r21 + dec r20 + brne 2b +fixrotr: + or r25, r21 + ret + + +;########################################################### + +.global change_endian32 +; === change_endian32 === +; function that changes the endianess of a 32-bit word +; param1: the 32-bit word +; given in r25,r24,r23,22 (r25 is most significant) +; modifys: r21, r22 +change_endian32: + movw r20, r22 ; (r22,r23) --> (r20,r21) + mov r22, r25 + mov r23, r24 + mov r24, r21 + mov r25, r20 + ret + +#endif \ No newline at end of file diff --git a/MySensors.h b/MySensors.h index 0033d5df1..734efea2e 100644 --- a/MySensors.h +++ b/MySensors.h @@ -57,26 +57,35 @@ // HARDWARE #include "hal/architecture/MyHw.h" +#include "hal/crypto/MyCryptoHAL.h" #if defined(ARDUINO_ARCH_ESP8266) #include "hal/architecture/ESP8266/MyHwESP8266.cpp" +#include "hal/crypto/generic/MyCryptoGeneric.cpp" #elif defined(ARDUINO_ARCH_ESP32) #include "hal/architecture/ESP32/MyHwESP32.cpp" +#include "hal/crypto/ESP32/MyCryptoESP32.cpp" #elif defined(ARDUINO_ARCH_AVR) #include "drivers/AVR/DigitalWriteFast/digitalWriteFast.h" #include "hal/architecture/AVR/MyHwAVR.cpp" +#include "hal/crypto/AVR/MyCryptoAVR.cpp" #elif defined(ARDUINO_ARCH_SAMD) #include "drivers/extEEPROM/extEEPROM.cpp" #include "hal/architecture/SAMD/MyHwSAMD.cpp" +#include "hal/crypto/generic/MyCryptoGeneric.cpp" #elif defined(ARDUINO_ARCH_STM32F1) #include "hal/architecture/STM32F1/MyHwSTM32F1.cpp" +#include "hal/crypto/generic/MyCryptoGeneric.cpp" #elif defined(ARDUINO_ARCH_NRF5) || defined(ARDUINO_ARCH_NRF52) #include "drivers/NVM/VirtualPage.cpp" #include "drivers/NVM/NVRAM.cpp" #include "hal/architecture/NRF5/MyHwNRF5.cpp" +#include "hal/crypto/generic/MyCryptoGeneric.cpp" #elif defined(__arm__) && defined(TEENSYDUINO) #include "hal/architecture/Teensy3/MyHwTeensy3.cpp" +#include "hal/crypto/generic/MyCryptoGeneric.cpp" #elif defined(__linux__) #include "hal/architecture/Linux/MyHwLinuxGeneric.cpp" +#include "hal/crypto/generic/MyCryptoGeneric.cpp" #else #error Hardware abstraction not defined (unsupported platform) #endif @@ -109,7 +118,6 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs // SIGNING #include "core/MySigning.cpp" -#include "drivers/ATSHA204/sha256.cpp" #if defined(MY_SIGNING_FEATURE) // SIGNING COMMON FUNCTIONS #if defined(MY_SIGNING_ATSHA204) && defined(MY_SIGNING_SOFT) diff --git a/core/MySigning.cpp b/core/MySigning.cpp index e8611c04e..f74b3e951 100644 --- a/core/MySigning.cpp +++ b/core/MySigning.cpp @@ -18,7 +18,6 @@ */ #include "MySigning.h" -#include "drivers/ATSHA204/sha256.h" #define SIGNING_PRESENTATION_VERSION_1 1 #define SIGNING_PRESENTATION_REQUIRE_SIGNATURES (1 << 0) @@ -319,25 +318,6 @@ bool signerVerifyMsg(MyMessage &msg) return verificationResult; } -Sha256Class _soft_sha256; - -void signerSha256Init(void) -{ - _soft_sha256.init(); -} - -void signerSha256Update(const uint8_t* data, size_t sz) -{ - for (size_t i = 0; i < sz; i++) { - _soft_sha256.write(data[i]); - } -} - -uint8_t* signerSha256Final(void) -{ - return _soft_sha256.result(); -} - int signerMemcmp(const void* a, const void* b, size_t sz) { int retVal; @@ -586,24 +566,20 @@ static bool signerInternalValidatePersonalization(void) // Personalization on linux is a bit more crude return true; #else - uint8_t buffer[32]; - uint8_t* hash; + uint8_t buffer[SIZE_SIGNING_SOFT_HMAC_KEY + SIZE_RF_ENCRYPTION_AES_KEY + SIZE_SIGNING_SOFT_SERIAL]; + uint8_t hash[32]; uint8_t checksum; - - signerSha256Init(); - hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32); - signerSha256Update(buffer, 32); - hwReadConfigBlock((void*)buffer, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16); - signerSha256Update(buffer, 16); - hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9); - signerSha256Update(buffer, 9); - hash = signerSha256Final(); - hwReadConfigBlock((void*)&checksum, (void*)EEPROM_PERSONALIZATION_CHECKSUM_ADDRESS, 1); - if (checksum != hash[0]) { - return false; - } else { - return true; - } + hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, + SIZE_SIGNING_SOFT_HMAC_KEY); + hwReadConfigBlock((void*)&buffer[SIZE_SIGNING_SOFT_HMAC_KEY], + (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, SIZE_RF_ENCRYPTION_AES_KEY); + hwReadConfigBlock((void*)&buffer[SIZE_SIGNING_SOFT_HMAC_KEY + SIZE_RF_ENCRYPTION_AES_KEY], + (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, SIZE_SIGNING_SOFT_SERIAL); + hwReadConfigBlock((void*)&checksum, (void*)EEPROM_PERSONALIZATION_CHECKSUM_ADDRESS, + SIZE_PERSONALIZATION_CHECKSUM); + + SHA256(hash, buffer, sizeof(buffer)); + return (checksum == hash[0]); #endif } #endif diff --git a/core/MySigning.h b/core/MySigning.h index ecc3b172d..0f64b3081 100644 --- a/core/MySigning.h +++ b/core/MySigning.h @@ -711,33 +711,6 @@ bool signerSignMsg(MyMessage &msg); */ bool signerVerifyMsg(MyMessage &msg); -/** - * @brief Initialize a hash calculation session. - * - * Any ongoing calculation session will be terminated/reset. - */ -void signerSha256Init(void); - -/** - * @brief Add data to an ongoing hash calculation session. - * - * More data can be added by repeated calls to this function. - * - * @param data Buffer with data to add. - * @param sz Size of data buffer. - */ -void signerSha256Update(const uint8_t* data, size_t sz); - -/** - * @brief Finalize an ongoing hash calculation session and return the hash. - * - * The returned hash size is always 32 bytes. Buffer can be assumed to be valid - * until @ref signerSha256Init() is called again. - * - * @returns Buffer with 32-byte hash. - */ -uint8_t* signerSha256Final(void); - /** * @brief Do a timing neutral memory comparison. * diff --git a/core/MySigningAtsha204Soft.cpp b/core/MySigningAtsha204Soft.cpp index acd7bca06..880aa73f3 100644 --- a/core/MySigningAtsha204Soft.cpp +++ b/core/MySigningAtsha204Soft.cpp @@ -1,4 +1,4 @@ -/* +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -31,13 +31,12 @@ #include "MySigning.h" #ifdef MY_SIGNING_SOFT -#include "drivers/ATSHA204/sha256.h" #define SIGNING_IDENTIFIER (1) //HMAC-SHA256 #if defined(MY_DEBUG_VERBOSE_SIGNING) #define SIGN_DEBUG(x,...) DEBUG_OUTPUT(x, ##__VA_ARGS__) static char printStr[65]; -static char i2h(uint8_t i) +static char i2h(const uint8_t i) { uint8_t k = i & 0x0F; if (k <= 9) { @@ -47,13 +46,12 @@ static char i2h(uint8_t i) } } -static void buf2str(const uint8_t* buf, size_t sz) +static void buf2str(const uint8_t *buf, size_t sz) { - uint8_t i; if (sz > 32) { sz = 32; //clamp to 32 bytes } - for (i = 0; i < sz; i++) { + for (uint8_t i = 0; i < sz; i++) { printStr[i * 2] = i2h(buf[i] >> 4); printStr[(i * 2) + 1] = i2h(buf[i]); } @@ -63,63 +61,67 @@ static void buf2str(const uint8_t* buf, size_t sz) #define SIGN_DEBUG(x,...) #endif -HmacClass _signing_sha256; static unsigned long _signing_timestamp; static bool _signing_verification_ongoing = false; +static bool _signing_init_ok = false; static uint8_t _signing_verifying_nonce[32+9+1]; -static uint8_t _signing_signing_nonce[32+9+1]; -static uint8_t _signing_temp_message[32]; -static uint8_t _signing_hmac_key[32]; +static uint8_t _signing_nonce[32+9+1]; +static uint8_t _signing_hmac_key[SIZE_SIGNING_SOFT_HMAC_KEY]; static uint8_t _signing_hmac[32]; -static uint8_t _signing_node_serial_info[9]; +static uint8_t _signing_node_serial_info[SIZE_SIGNING_SOFT_SERIAL]; + #ifdef MY_SIGNING_NODE_WHITELISTING static const whitelist_entry_t _signing_whitelist[] = MY_SIGNING_NODE_WHITELISTING; #endif -static bool init_ok = false; -static const uint8_t reset_serial[9] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - -static void signerCalculateSignature(MyMessage &msg, bool signing); -static uint8_t* signerAtsha204AHmac(const uint8_t* nonce, const uint8_t* data); -static uint8_t* signerSha256(const uint8_t* data, size_t sz); +static void signerCalculateSignature(MyMessage &msg, const bool signing); +static void signerAtsha204AHmac(uint8_t *dest, const uint8_t *nonce, const uint8_t *data); bool signerAtsha204SoftInit(void) { - init_ok = true; - + _signing_init_ok = true; // initialize pseudo-RNG hwRandomNumberInit(); // Set secrets #ifdef MY_SIGNING_SIMPLE_PASSWD if (strnlen(MY_SIGNING_SIMPLE_PASSWD, 32) < 8) { SIGN_DEBUG(PSTR("!SGN:BND:PWD<8\n")); //Password is too short to be acceptable - init_ok = false; + _signing_init_ok = false; } else { - memset(_signing_hmac_key, 0, 32); - memcpy(_signing_hmac_key, MY_SIGNING_SIMPLE_PASSWD, strnlen(MY_SIGNING_SIMPLE_PASSWD, 32)); - memset(_signing_node_serial_info, 0, 9); - memcpy(_signing_node_serial_info, MY_SIGNING_SIMPLE_PASSWD, - strnlen(MY_SIGNING_SIMPLE_PASSWD, 8)); + (void)memset((void *)_signing_hmac_key, 0x00, sizeof(_signing_hmac_key)); + (void)memcpy((void *)_signing_hmac_key, MY_SIGNING_SIMPLE_PASSWD, strnlen(MY_SIGNING_SIMPLE_PASSWD, + 32)); + (void)memset((void *)_signing_node_serial_info, 0x00, sizeof(_signing_node_serial_info)); + (void)memcpy((void *)_signing_node_serial_info, MY_SIGNING_SIMPLE_PASSWD, + strnlen(MY_SIGNING_SIMPLE_PASSWD, 8)); _signing_node_serial_info[8] = getNodeId(); } #else - hwReadConfigBlock((void*)_signing_hmac_key, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32); - hwReadConfigBlock((void*)_signing_node_serial_info, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9); + hwReadConfigBlock((void *)_signing_hmac_key, (void *)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, + SIZE_SIGNING_SOFT_HMAC_KEY); + hwReadConfigBlock((void *)_signing_node_serial_info, (void *)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, + SIZE_SIGNING_SOFT_SERIAL); #endif - if (!memcmp(_signing_node_serial_info, reset_serial, 9)) { + + uint16_t chk = 0; + for (uint8_t i = 0; i < SIZE_SIGNING_SOFT_SERIAL; i++) { + chk += _signing_node_serial_info[i]; + } + if (chk==SIZE_SIGNING_SOFT_SERIAL * + 0xFF) { // test if == { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } unique_id_t uniqueID; // There is no serial, attempt to get unique ID for serial instead if (hwUniqueID(&uniqueID)) { // There is a unique serial, use that - memcpy(_signing_node_serial_info, uniqueID, 9); + (void)memcpy((void *)_signing_node_serial_info, (const void *)uniqueID, SIZE_SIGNING_SOFT_SERIAL); } } - return init_ok; + return _signing_init_ok; } bool signerAtsha204SoftCheckTimer(void) { - if (!init_ok) { + if (!_signing_init_ok) { return false; } if (_signing_verification_ongoing) { @@ -134,8 +136,8 @@ bool signerAtsha204SoftCheckTimer(void) if (time_now > _signing_timestamp + MY_VERIFICATION_TIMEOUT_MS) { SIGN_DEBUG(PSTR("!SGN:BND:TMR\n")); //Verification timeout // Purge nonce - memset(_signing_signing_nonce, 0xAA, 32); - memset(_signing_verifying_nonce, 0xAA, 32); + (void)memset((void *)_signing_nonce, 0xAA, sizeof(_signing_nonce)); + (void)memset((void *)_signing_verifying_nonce, 0xAA, sizeof(_signing_verifying_nonce)); _signing_verification_ongoing = false; return false; } @@ -145,7 +147,7 @@ bool signerAtsha204SoftCheckTimer(void) bool signerAtsha204SoftGetNonce(MyMessage &msg) { - if (!init_ok) { + if (!_signing_init_ok) { return false; } @@ -155,16 +157,16 @@ bool signerAtsha204SoftGetNonce(MyMessage &msg) #else // We used a basic whitening technique that XORs a random byte with the current hwMillis() counter // and then the byte is hashed (SHA256) to produce the resulting nonce - _signing_sha256.init(); - for (int i = 0; i < 32; i++) { - _signing_sha256.write(random(256) ^ (hwMillis()&0xFF)); + uint8_t randBuffer[32]; + for (uint8_t i = 0; i < sizeof(randBuffer); i++) { + randBuffer[i] = random(256) ^ (hwMillis() & 0xFF); } - memcpy(_signing_verifying_nonce, _signing_sha256.result(), MIN(MAX_PAYLOAD, 32)); + SHA256(_signing_verifying_nonce, randBuffer, sizeof(randBuffer)); #endif if (MAX_PAYLOAD < 32) { // We set the part of the 32-byte nonce that does not fit into a message to 0xAA - memset(&_signing_verifying_nonce[MAX_PAYLOAD], 0xAA, 32-MAX_PAYLOAD); + (void)memset((void *)&_signing_verifying_nonce[MAX_PAYLOAD], 0xAA, 32-MAX_PAYLOAD); } // Transfer the first part of the nonce to the message @@ -182,14 +184,14 @@ bool signerAtsha204SoftGetNonce(MyMessage &msg) void signerAtsha204SoftPutNonce(MyMessage &msg) { - if (!init_ok) { + if (!_signing_init_ok) { return; } - memcpy(_signing_signing_nonce, (uint8_t*)msg.getCustom(), MIN(MAX_PAYLOAD, 32)); + (void)memcpy((void *)_signing_nonce, (const void *)msg.getCustom(), MIN(MAX_PAYLOAD, 32)); if (MAX_PAYLOAD < 32) { // We set the part of the 32-byte nonce that does not fit into a message to 0xAA - memset(&_signing_signing_nonce[MAX_PAYLOAD], 0xAA, 32-MAX_PAYLOAD); + (void)memset((void *)&_signing_nonce[MAX_PAYLOAD], 0xAA, 32-MAX_PAYLOAD); } } @@ -209,10 +211,10 @@ bool signerAtsha204SoftSignMsg(MyMessage &msg) if (DO_WHITELIST(msg.destination)) { // Salt the signature with the senders nodeId and the (hopefully) unique serial The Creator has // provided. We can reuse the nonce buffer now since it is no longer needed - memcpy(_signing_signing_nonce, _signing_hmac, 32); - _signing_signing_nonce[32] = msg.sender; - memcpy(&_signing_signing_nonce[33], _signing_node_serial_info, 9); - memcpy(_signing_hmac, signerSha256(_signing_signing_nonce, 32+1+9), 32); + (void)memcpy((void *)_signing_nonce, (const void *)_signing_hmac, 32); + _signing_nonce[32] = msg.sender; + (void)memcpy((void *)&_signing_nonce[33], (const void *)_signing_node_serial_info, 9); + SHA256(_signing_hmac, _signing_nonce, 32+1+9); SIGN_DEBUG(PSTR("SGN:BND:SIG WHI,ID=%" PRIu8 "\n"), msg.sender); #ifdef MY_DEBUG_VERBOSE_SIGNING buf2str(_signing_node_serial_info, 9); @@ -224,7 +226,8 @@ bool signerAtsha204SoftSignMsg(MyMessage &msg) _signing_hmac[0] = SIGNING_IDENTIFIER; // Transfer as much signature data as the remaining space in the message permits - memcpy(&msg.data[mGetLength(msg)], _signing_hmac, MIN(MAX_PAYLOAD-mGetLength(msg), 32)); + (void)memcpy((void *)&msg.data[mGetLength(msg)], (const void *)_signing_hmac, + MIN(MAX_PAYLOAD-mGetLength(msg), 32)); return true; } @@ -252,13 +255,13 @@ bool signerAtsha204SoftVerifyMsg(MyMessage &msg) #ifdef MY_SIGNING_NODE_WHITELISTING // Look up the senders nodeId in our whitelist and salt the signature with that data size_t j; - for (j=0; j < NUM_OF(_signing_whitelist); j++) { + for (j = 0; j < NUM_OF(_signing_whitelist); j++) { if (_signing_whitelist[j].nodeId == msg.sender) { // We can reuse the nonce buffer now since it is no longer needed - memcpy(_signing_verifying_nonce, _signing_hmac, 32); + (void)memcpy((void *)_signing_verifying_nonce, (const void *)_signing_hmac, 32); _signing_verifying_nonce[32] = msg.sender; - memcpy(&_signing_verifying_nonce[33], _signing_whitelist[j].serial, 9); - memcpy(_signing_hmac, signerSha256(_signing_verifying_nonce, 32+1+9), 32); + (void)memcpy((void *)&_signing_verifying_nonce[33], (const void *)_signing_whitelist[j].serial, 9); + SHA256(_signing_hmac, _signing_verifying_nonce, 32+1+9); SIGN_DEBUG(PSTR("SGN:BND:VER WHI,ID=%" PRIu8 "\n"), msg.sender); #ifdef MY_DEBUG_VERBOSE_SIGNING buf2str(_signing_whitelist[j].serial, 9); @@ -287,35 +290,36 @@ bool signerAtsha204SoftVerifyMsg(MyMessage &msg) } // Helper to calculate signature of msg (returned in _signing_hmac) -static void signerCalculateSignature(MyMessage &msg, bool signing) +static void signerCalculateSignature(MyMessage &msg, const bool signing) { // Signature is calculated on everything expect the first byte in the header - uint16_t bytes_left = mGetLength(msg)+HEADER_SIZE-1; + uint8_t bytes_left = mGetLength(msg)+HEADER_SIZE-1; int16_t current_pos = 1-(int16_t)HEADER_SIZE; // Start at the second byte in the header - uint8_t* nonce = signing ? _signing_signing_nonce : _signing_verifying_nonce; + uint8_t* nonce = signing ? _signing_nonce : _signing_verifying_nonce; #ifdef MY_DEBUG_VERBOSE_SIGNING buf2str(nonce, 32); SIGN_DEBUG(PSTR("SGN:BND:NONCE=%s\n"), printStr); #endif + uint8_t _signing_temp_message[32]; + while (bytes_left) { - uint16_t bytes_to_include = MIN(bytes_left, 32); + uint8_t bytes_to_include = MIN(bytes_left, 32); - memset(_signing_temp_message, 0, 32); - memcpy(_signing_temp_message, (uint8_t*)&msg.data[current_pos], bytes_to_include); + (void)memset((void *)_signing_temp_message, 0x00, sizeof(_signing_temp_message)); + (void)memcpy((void *)_signing_temp_message, (const void *)&msg.data[current_pos], bytes_to_include); - // We can 'void' signerAtsha204AHmac because the HMAC is already put in the correct place - (void)signerAtsha204AHmac(nonce, _signing_temp_message); + signerAtsha204AHmac(_signing_hmac, nonce, _signing_temp_message); // Purge nonce when used - memset(nonce, 0xAA, 32); + (void)memset((void *)nonce, 0xAA, 32); bytes_left -= bytes_to_include; current_pos += bytes_to_include; - if (bytes_left > 0) { + if (bytes_left) { // We will do another pass, use current HMAC as nonce for the next HMAC - memcpy(nonce, _signing_hmac, 32); + (void)memcpy((void *)nonce, (const void *)_signing_hmac, 32); } } #ifdef MY_DEBUG_VERBOSE_SIGNING @@ -327,7 +331,7 @@ static void signerCalculateSignature(MyMessage &msg, bool signing) // Helper to calculate a ATSHA204A specific HMAC-SHA256 using provided 32 byte nonce and data // (zero padded to 32 bytes) // The pointer to the HMAC is returned, but the HMAC is also stored in _signing_hmac -static uint8_t* signerAtsha204AHmac(const uint8_t* nonce, const uint8_t* data) +static void signerAtsha204AHmac(uint8_t *dest, const uint8_t *nonce, const uint8_t *data) { // ATSHA204 calculates the HMAC with a PSK and a SHA256 digest of the following data: // 32 bytes zeroes @@ -351,63 +355,36 @@ static uint8_t* signerAtsha204AHmac(const uint8_t* nonce, const uint8_t* data) // 25 bytes zeroes // 32 bytes nonce + uint8_t buffer[96]; // Calculate message digest first - _signing_sha256.init(); - for (int i=0; i<32; i++) { - _signing_sha256.write(data[i]); - } - _signing_sha256.write(0x15); // OPCODE - _signing_sha256.write(0x02); // param1 - _signing_sha256.write(0x08); // param2(1) - _signing_sha256.write(0x00); // param2(2) - _signing_sha256.write(0xEE); // SN[8] - _signing_sha256.write(0x01); // SN[0] - _signing_sha256.write(0x23); // SN[1] - for (int i=0; i<25; i++) { - _signing_sha256.write(0x00); - } - for (int i=0; i<32; i++) { - _signing_sha256.write(nonce[i]); - } - memcpy(_signing_hmac, _signing_sha256.result(), 32); + (void)memset((void *)buffer, 0x00, sizeof(buffer)); + (void)memcpy((void *)buffer, (const void *)data, 32); + buffer[0 + 32] = 0x15; // OPCODE + buffer[1 + 32] = 0x02; // param1 + buffer[2 + 32] = 0x08; // param2(1) + //buffer[3 + 32] = 0x00; // param2(2) + buffer[4 + 32] = 0xEE; // SN[8] + buffer[5 + 32] = 0x01; // SN[0] + buffer[6 + 32] = 0x23; // SN[1] + // buffer[7 + 32..31 + 32] => 0x00; + (void)memcpy((void *)&buffer[64], (const void *)nonce, 32); + SHA256(_signing_hmac, buffer, 96); // Feed "message" to HMAC calculator - _signing_sha256.initHmac(_signing_hmac_key, 32); // Set the key to use - for (int i=0; i<32; i++) { - _signing_sha256.write(0x00); // 32 bytes zeroes - } - for (int i=0; i<32; i++) { - _signing_sha256.write(_signing_hmac[i]); // 32 bytes digest - } - _signing_sha256.write(0x11); // OPCODE - _signing_sha256.write(0x04); // Mode - _signing_sha256.write(0x00); // SlotID(1) - _signing_sha256.write(0x00); // SlotID(2) - for (int i=0; i<11; i++) { - _signing_sha256.write(0x00); // 11 bytes zeroes - } - _signing_sha256.write(0xEE); // SN[8] - for (int i=0; i<4; i++) { - _signing_sha256.write(0x00); // 4 bytes zeroes - } - _signing_sha256.write(0x01); // SN[0] - _signing_sha256.write(0x23); // SN[1] - for (int i=0; i<2; i++) { - _signing_sha256.write(0x00); // 2 bytes zeroes - } - - memcpy(_signing_hmac, _signing_sha256.resultHmac(), 32); - return _signing_hmac; + (void)memset((void *)buffer, 0x00, sizeof(buffer)); + (void)memcpy((void *)&buffer[32], (const void *)_signing_hmac, 32); + buffer[0 + 64] = 0x11; // OPCODE + buffer[1 + 64] = 0x04; // Mode + //buffer[2 + 64] = 0x00; // SlotID(1) + //buffer[3 + 64] = 0x00; // SlotID(2) + //buffer[4 + 64..14 + 64] => 0x00; // 11 bytes zeroes + buffer[15 + 64] = 0xEE; // SN[8] + //buffer[16 + 64..19 + 64] => 0x00; // 4 bytes zeroes + buffer[20 + 64] = 0x01; + buffer[21 + 64] = 0x23; + //buffer[22 + 64] = 0x00; // SN[0] + //buffer[23 + 64] = 0x00; // SN[1] + SHA256HMAC(dest, _signing_hmac_key, 32, buffer, 88); } -// Helper to calculate a generic SHA256 digest of provided buffer -// The pointer to the hash is returned -static uint8_t* signerSha256(const uint8_t* data, size_t sz) -{ - _signing_sha256.init(); - for (size_t i=0; i -#if defined(__AVR__) -#include -#define PRIPSTR "%S" -#elif defined(ESP8266) -#include -#endif -#include "sha256.h" - - -const uint32_t sha256K[] PROGMEM = { - 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, - 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174, - 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da, - 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967, - 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85, - 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070, - 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3, - 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 -}; - -const uint8_t sha256InitState[] PROGMEM = { - 0x67,0xe6,0x09,0x6a, // H0 - 0x85,0xae,0x67,0xbb, // H1 - 0x72,0xf3,0x6e,0x3c, // H2 - 0x3a,0xf5,0x4f,0xa5, // H3 - 0x7f,0x52,0x0e,0x51, // H4 - 0x8c,0x68,0x05,0x9b, // H5 - 0xab,0xd9,0x83,0x1f, // H6 - 0x19,0xcd,0xe0,0x5b // H7 -}; - -// Suppress warning about uninitialized variables because initializing them in an init function -// allows the compiler to optimize away the variables in case the class is only instantiated but -// never used. -// cppcheck-suppress uninitMemberVar -Sha256Class::Sha256Class() -{ - /* - memset(keyBuffer, 0, BLOCK_LENGTH); - memset(innerHash, 0, HASH_LENGTH); - memset(buffer.b, 0, BLOCK_LENGTH); - memset(state.b, 0, BLOCK_LENGTH); - bufferOffset = 0; - byteCount = 0; - */ -} - - -void Sha256Class::init(void) -{ - memcpy_P(state.b,sha256InitState,32); - byteCount = 0; - bufferOffset = 0; -} - -uint32_t Sha256Class::ror32(uint32_t number, uint8_t bits) -{ - return ((number << (32-bits)) | (number >> bits)); -} - -void Sha256Class::hashBlock() -{ - uint8_t i; - uint32_t a,b,c,d,e,f,g,h,t1,t2; - - a=state.w[0]; - b=state.w[1]; - c=state.w[2]; - d=state.w[3]; - e=state.w[4]; - f=state.w[5]; - g=state.w[6]; - h=state.w[7]; - - for (i=0; i<64; i++) { - if (i>=16) { - t1 = buffer.w[i&15] + buffer.w[(i-7)&15]; - t2 = buffer.w[(i-2)&15]; - t1 += ror32(t2,17) ^ ror32(t2,19) ^ (t2>>10); - t2 = buffer.w[(i-15)&15]; - t1 += ror32(t2,7) ^ ror32(t2,18) ^ (t2>>3); - buffer.w[i&15] = t1; - } - t1 = h; - t1 += ror32(e,6) ^ ror32(e,11) ^ ror32(e,25); // ∑1(e) - t1 += g ^ (e & (g ^ f)); // Ch(e,f,g) - t1 += pgm_read_dword(sha256K+i); // Ki - t1 += buffer.w[i&15]; // Wi - t2 = ror32(a,2) ^ ror32(a,13) ^ ror32(a,22); // ∑0(a) - t2 += ((b & c) | (a & (b | c))); // Maj(a,b,c) - h=g; - g=f; - f=e; - e=d+t1; - d=c; - c=b; - b=a; - a=t1+t2; - } - state.w[0] += a; - state.w[1] += b; - state.w[2] += c; - state.w[3] += d; - state.w[4] += e; - state.w[5] += f; - state.w[6] += g; - state.w[7] += h; -} - -void Sha256Class::addUncounted(uint8_t data) -{ - buffer.b[bufferOffset ^ 3] = data; - bufferOffset++; - if (bufferOffset == BLOCK_LENGTH) { - hashBlock(); - bufferOffset = 0; - } -} - -void Sha256Class::write(uint8_t data) -{ - ++byteCount; - addUncounted(data); -} - -void Sha256Class::pad() -{ - // Implement SHA-256 padding (fips180-2 §5.1.1) - - // Pad with 0x80 followed by 0x00 until the end of the block - addUncounted(0x80); - while (bufferOffset != 56) { - addUncounted(0x00); - } - - // Append length in the last 8 bytes - addUncounted(0); // We're only using 32 bit lengths - addUncounted(0); // But SHA-1 supports 64 bit lengths - addUncounted(0); // So zero pad the top bits - addUncounted(byteCount >> 29); // Shifting to multiply by 8 - addUncounted(byteCount >> 21); // as SHA-1 supports bitstreams as well as - addUncounted(byteCount >> 13); // byte. - addUncounted(byteCount >> 5); - addUncounted(byteCount << 3); -} - - -uint8_t* Sha256Class::result(void) -{ - // Pad to complete the last block - pad(); - - // Swap byte order back - for (int i=0; i<8; i++) { - uint32_t a,b; - a=state.w[i]; - b=a<<24; - b|=(a<<8) & 0x00ff0000; - b|=(a>>8) & 0x0000ff00; - b|=a>>24; - state.w[i]=b; - } - - // Return pointer to hash (20 characters) - return state.b; -} - -#define HMAC_IPAD 0x36 -#define HMAC_OPAD 0x5c - -// Suppress warning about uninitialized variables because initializing them in an init function -// allows the compiler to optimize away the variables in case the class is only instantiated but -// never used. -// cppcheck-suppress uninitMemberVar -HmacClass::HmacClass() -{ -} - -void HmacClass::initHmac(const uint8_t* key, int keyLength) -{ - uint8_t i; - memset(keyBuffer,0,BLOCK_LENGTH); - if (keyLength > BLOCK_LENGTH) { - // Hash long keys - init(); - for (; keyLength--;) { - write(*key++); - } - memcpy(keyBuffer,result(),HASH_LENGTH); - } else { - // Block length keys are used as is - memcpy(keyBuffer,key,keyLength); - } - // Start inner hash - init(); - for (i=0; i - -#define HASH_LENGTH 32 -#define BLOCK_LENGTH 64 - -union _buffer { - uint8_t b[BLOCK_LENGTH]; - uint32_t w[BLOCK_LENGTH/4]; -}; -union _state { - uint8_t b[HASH_LENGTH]; - uint32_t w[HASH_LENGTH/4]; -}; - -class Sha256Class -{ -public: - Sha256Class(); // Constructor - void init(void); - uint8_t* result(void); - void write(uint8_t); -private: - void pad(); - void addUncounted(uint8_t data); - void hashBlock(); - uint32_t ror32(uint32_t number, uint8_t bits); - _buffer buffer; - uint8_t bufferOffset; - _state state; - uint32_t byteCount; -}; - -class HmacClass : public Sha256Class -{ -public: - HmacClass(); // Constructor - void initHmac(const uint8_t* secret, int secretLength); - uint8_t* resultHmac(void); -private: - uint8_t keyBuffer[BLOCK_LENGTH]; - uint8_t innerHash[HASH_LENGTH]; -}; - -#endif -#endif diff --git a/examples/SecurityPersonalizer/SecurityPersonalizer.ino b/examples/SecurityPersonalizer/SecurityPersonalizer.ino index 17eeac542..7ee2e661c 100644 --- a/examples/SecurityPersonalizer/SecurityPersonalizer.ino +++ b/examples/SecurityPersonalizer/SecurityPersonalizer.ino @@ -686,17 +686,21 @@ static void reset_eeprom(void) static void write_eeprom_checksum(void) { - uint8_t buffer[32]; - uint8_t* hash; - signerSha256Init(); - hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, 32); - signerSha256Update(buffer, 32); - hwReadConfigBlock((void*)buffer, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16); - signerSha256Update(buffer, 16); - hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, 9); - signerSha256Update(buffer, 9); - hash = signerSha256Final(); - hwWriteConfigBlock((void*)&hash[0], (void*)EEPROM_PERSONALIZATION_CHECKSUM_ADDRESS, 1); + uint8_t buffer[SIZE_SIGNING_SOFT_HMAC_KEY + SIZE_RF_ENCRYPTION_AES_KEY + SIZE_SIGNING_SOFT_SERIAL]; + uint8_t hash[32]; + uint8_t checksum; + hwReadConfigBlock((void*)buffer, (void*)EEPROM_SIGNING_SOFT_HMAC_KEY_ADDRESS, + SIZE_SIGNING_SOFT_HMAC_KEY); + hwReadConfigBlock((void*)&buffer[SIZE_SIGNING_SOFT_HMAC_KEY], + (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, SIZE_RF_ENCRYPTION_AES_KEY); + hwReadConfigBlock((void*)&buffer[SIZE_SIGNING_SOFT_HMAC_KEY + SIZE_RF_ENCRYPTION_AES_KEY], + (void*)EEPROM_SIGNING_SOFT_SERIAL_ADDRESS, SIZE_SIGNING_SOFT_SERIAL); + hwReadConfigBlock((void*)&checksum, (void*)EEPROM_PERSONALIZATION_CHECKSUM_ADDRESS, + SIZE_PERSONALIZATION_CHECKSUM); + + SHA256(hash, buffer, sizeof(buffer)); + hwWriteConfigBlock((void*)&hash[0], (void*)EEPROM_PERSONALIZATION_CHECKSUM_ADDRESS, + SIZE_PERSONALIZATION_CHECKSUM); } /** @brief Store keys depending on configuration */ diff --git a/hal/architecture/AVR/MyHwAVR.h b/hal/architecture/AVR/MyHwAVR.h index 863ed641c..c0329fdfd 100644 --- a/hal/architecture/AVR/MyHwAVR.h +++ b/hal/architecture/AVR/MyHwAVR.h @@ -33,6 +33,8 @@ #include #endif +#define MYSENSORS_SHA256_ASM_AVR // use the ASM implementation for the sha256 code + #ifndef MY_SERIALDEVICE #define MY_SERIALDEVICE Serial #endif diff --git a/hal/architecture/ESP32/MyHwESP32.h b/hal/architecture/ESP32/MyHwESP32.h index 64d6ac786..346ec6ed1 100644 --- a/hal/architecture/ESP32/MyHwESP32.h +++ b/hal/architecture/ESP32/MyHwESP32.h @@ -45,6 +45,8 @@ #include #endif +#define CRYPTO_LITTLE_ENDIAN + #define MY_SERIALDEVICE Serial #define min(a,b) ((a)<(b)?(a):(b)) diff --git a/hal/architecture/ESP8266/MyHwESP8266.h b/hal/architecture/ESP8266/MyHwESP8266.h index 4057261ae..162f17d91 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.h +++ b/hal/architecture/ESP8266/MyHwESP8266.h @@ -23,6 +23,8 @@ #include #endif +#define CRYPTO_LITTLE_ENDIAN + #ifndef MY_SERIALDEVICE #define MY_SERIALDEVICE Serial #endif diff --git a/hal/architecture/Linux/MyHwLinuxGeneric.h b/hal/architecture/Linux/MyHwLinuxGeneric.h index 220a72089..214b61267 100644 --- a/hal/architecture/Linux/MyHwLinuxGeneric.h +++ b/hal/architecture/Linux/MyHwLinuxGeneric.h @@ -25,6 +25,8 @@ #include "SerialPort.h" #include "StdInOutStream.h" +#define CRYPTO_LITTLE_ENDIAN + #ifdef MY_LINUX_SERIAL_PORT #ifdef MY_LINUX_SERIAL_IS_PTY SerialPort Serial = SerialPort(MY_LINUX_SERIAL_PORT, true); diff --git a/hal/architecture/NRF5/MyHwNRF5.cpp b/hal/architecture/NRF5/MyHwNRF5.cpp index 921bbf8a3..808b92f82 100644 --- a/hal/architecture/NRF5/MyHwNRF5.cpp +++ b/hal/architecture/NRF5/MyHwNRF5.cpp @@ -23,6 +23,8 @@ #include "MyHwNRF5.h" #include +#define CRYPTO_LITTLE_ENDIAN + #define INVALID_INTERRUPT_NUM (0xFFu) volatile uint8_t _wokeUpByInterrupt = INVALID_INTERRUPT_NUM; // Interrupt number that woke the mcu. diff --git a/hal/architecture/NRF5/MyHwNRF5.h b/hal/architecture/NRF5/MyHwNRF5.h index ff3f8e3c1..c9d6595b0 100644 --- a/hal/architecture/NRF5/MyHwNRF5.h +++ b/hal/architecture/NRF5/MyHwNRF5.h @@ -26,6 +26,8 @@ #include #endif +#define CRYPTO_LITTLE_ENDIAN + // Define NRF5_SOFTDEVICE when SoftDevice found #if defined(S110) || defined(S130) || defined(S132) || defined(S140) #ifndef SOFTDEVICE_PRESENT diff --git a/hal/architecture/SAMD/MyHwSAMD.h b/hal/architecture/SAMD/MyHwSAMD.h index 178ec102f..353e9bcaf 100644 --- a/hal/architecture/SAMD/MyHwSAMD.h +++ b/hal/architecture/SAMD/MyHwSAMD.h @@ -25,6 +25,8 @@ #include +#define CRYPTO_LITTLE_ENDIAN + // defines for sensebender gw variant.h #define MY_EXT_EEPROM_I2C_ADDRESS (0x50u) #define MY_EXT_EEPROM_SIZE (kbits_512) diff --git a/hal/architecture/STM32F1/MyHwSTM32F1.h b/hal/architecture/STM32F1/MyHwSTM32F1.h index ae27ba02b..bca1f5360 100644 --- a/hal/architecture/STM32F1/MyHwSTM32F1.h +++ b/hal/architecture/STM32F1/MyHwSTM32F1.h @@ -27,6 +27,8 @@ #include #endif +#define CRYPTO_LITTLE_ENDIAN + // SS default #ifndef SS #define SS PA4 diff --git a/hal/architecture/Teensy3/MyHwTeensy3.h b/hal/architecture/Teensy3/MyHwTeensy3.h index 863b555d4..99e5046dc 100644 --- a/hal/architecture/Teensy3/MyHwTeensy3.h +++ b/hal/architecture/Teensy3/MyHwTeensy3.h @@ -33,6 +33,8 @@ #endif #include "util/atomic.h" +#define CRYPTO_LITTLE_ENDIAN + #ifndef _BV #define _BV(x) (1<<(x)) #endif @@ -49,8 +51,11 @@ #define SIM_SCGC6_RNGA ((uint32_t)0x00000200) #endif -#define MIN(a,b) min(a,b) -#define MAX(a,b) max(a,b) +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) + +#define MIN min +#define MAX max // Define these as macros to save valuable space #define hwDigitalWrite(__pin, __value) digitalWriteFast(__pin, __value) diff --git a/hal/crypto/AVR/MyCryptoAVR.cpp b/hal/crypto/AVR/MyCryptoAVR.cpp new file mode 100644 index 000000000..a803a884d --- /dev/null +++ b/hal/crypto/AVR/MyCryptoAVR.cpp @@ -0,0 +1,101 @@ +/* +* The MySensors Arduino library handles the wireless radio link and protocol +* between your home built sensors/actuators and HA controller of choice. +* The sensors forms a self healing radio network with optional repeaters. Each +* repeater and gateway builds a routing tables in EEPROM which keeps track of the +* network topology allowing messages to be routed to nodes. +* +* Created by Henrik Ekblad +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* +* Documentation: http://www.mysensors.org +* Support Forum: http://forum.mysensors.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* ====================================================================== +* +* SHA256 and SHA256 implementation for AVR: +* +* This file is part of the AVR-Crypto-Lib. +* Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) +* +* 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 . +* +* Author: Daniel Otte +* +* License: GPLv3 or later +* +* ====================================================================== +*/ + +#include "MyCryptoAVR.h" + +// SHA256 implementation in ASM, see MyASM.S + +void SHA256(uint8_t *dest, const uint8_t *data, size_t dataLength) +{ + sha256((sha256_hash_t *)dest, data, dataLength << 3); // data length in bits +} + +// SHA256HMAC + +/* +* all lengths in bits! +*/ +void hmac_sha256(void *dest, const void *key, uint16_t keylength_b, const void *msg, + uint32_t msglength_b) +{ + sha256_ctx_t s; + uint8_t buffer[HMAC_SHA256_BLOCK_BYTES]; + + (void)memset((void *)buffer, 0x00, HMAC_SHA256_BLOCK_BYTES); + + /* if key is larger than a block we have to hash it*/ + if (keylength_b > SHA256_BLOCK_BITS) { + sha256((sha256_hash_t *)buffer, key, keylength_b); + } else { + (void)memcpy((void *)buffer, (const void *)key, (keylength_b + 7) / 8); + } + + for (uint8_t i = 0; i < SHA256_BLOCK_BYTES; ++i) { + buffer[i] ^= IPAD; + } + sha256_init(&s); + sha256_nextBlock(&s, buffer); + while (msglength_b >= HMAC_SHA256_BLOCK_BITS) { + sha256_nextBlock(&s, msg); + msg = (uint8_t *)msg + HMAC_SHA256_BLOCK_BYTES; + msglength_b -= HMAC_SHA256_BLOCK_BITS; + } + sha256_lastBlock(&s, msg, msglength_b); + /* since buffer still contains key xor ipad we can do ... */ + for (uint8_t i = 0; i < HMAC_SHA256_BLOCK_BYTES; ++i) { + buffer[i] ^= IPAD ^ OPAD; + } + sha256_ctx2hash((sha256_hash_t *)dest, &s); /* save inner hash temporary to dest */ + sha256_init(&s); + sha256_nextBlock(&s, buffer); + sha256_lastBlock(&s, dest, SHA256_HASH_BITS); + sha256_ctx2hash((sha256_hash_t *)dest, &s); +} + +void SHA256HMAC(uint8_t *dest, const uint8_t *key, size_t keyLength, const uint8_t *data, + size_t dataLength) +{ + hmac_sha256(dest, key, keyLength << 3, data, dataLength << 3); +} diff --git a/hal/crypto/AVR/MyCryptoAVR.h b/hal/crypto/AVR/MyCryptoAVR.h new file mode 100644 index 000000000..78fa369f3 --- /dev/null +++ b/hal/crypto/AVR/MyCryptoAVR.h @@ -0,0 +1,155 @@ +/* +* The MySensors Arduino library handles the wireless radio link and protocol +* between your home built sensors/actuators and HA controller of choice. +* The sensors forms a self healing radio network with optional repeaters. Each +* repeater and gateway builds a routing tables in EEPROM which keeps track of the +* network topology allowing messages to be routed to nodes. +* +* Created by Henrik Ekblad +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* +* Documentation: http://www.mysensors.org +* Support Forum: http://forum.mysensors.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* ====================================================================== +* +* SHA256 and SHA256 implementation for AVR: +* +* This file is part of the AVR-Crypto-Lib. +* Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) +* +* 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 . +* +* Author: Daniel Otte +* +* License: GPLv3 or later +* +* ====================================================================== +*/ + +#ifndef MyCryptoGeneric_h +#define MyCryptoGeneric_h + +#include "hal/crypto/MyCryptoHAL.h" + +#define SHA256_HASH_BITS 256 //!< Defines the size of a SHA-256 hash value in bits +#define SHA256_HASH_BYTES (SHA256_HASH_BITS/8) //!< Defines the size of a SHA-256 hash value in bytes +#define SHA256_BLOCK_BITS 512 //!< Defines the size of a SHA-256 input block in bits +#define SHA256_BLOCK_BYTES (SHA256_BLOCK_BITS/8) //!< Defines the size of a SHA-256 input block in bytes + +/** +* @brief SHA-256 context type +* +* A variable of this type may hold the state of a SHA-256 hashing process +*/ +typedef struct { + uint32_t h[8]; //!< h + uint64_t length; //!< length +} sha256_ctx_t; + +/** +* @brief SHA-256 hash value type +* +* A variable of this type may hold the hash value produced by the +* sha256_ctx2hash(sha256_hash_t *dest, const sha256_ctx_t *state) function. +*/ +typedef uint8_t sha256_hash_t[SHA256_HASH_BYTES]; + +extern "C" { // ASM implementation, see MyASM.S + +/** +* @brief initialise a SHA-256 context +* +* This function sets a ::sha256_ctx_t to the initial values for hashing. +* @param state pointer to the SHA-256 hashing context +*/ +void sha256_init(sha256_ctx_t *state); + +/** +* @brief update the context with a given block +* +* This function updates the SHA-256 hash context by processing the given block +* of fixed length. +* @param state pointer to the SHA-256 hash context +* @param block pointer to the block of fixed length (512 bit = 64 byte) +*/ +void sha256_nextBlock(sha256_ctx_t *state, const void *block); + +/** +* @brief finalize the context with the given block +* +* This function finalizes the SHA-256 hash context by processing the given block +* of variable length. +* @param state pointer to the SHA-256 hash context +* @param block pointer to the block of fixed length (512 bit = 64 byte) +* @param length_b the length of the block in bits +*/ +void sha256_lastBlock(sha256_ctx_t *state, const void *block, uint16_t length_b); + +/** +* @brief convert the hash state into the hash value +* +* This function reads the context and writes the hash value to the destination +* @param dest pointer to the location where the hash value should be written +* @param state pointer to the SHA-256 hash context +*/ +void sha256_ctx2hash(sha256_hash_t *dest, const sha256_ctx_t *state); + +/** +* @brief simple SHA-256 hashing function for direct hashing +* +* This function automaticaly hashes a given message of arbitary length with +* the SHA-256 hashing algorithm. +* @param dest pointer to the location where the hash value is going to be written to +* @param msg pointer to the message thats going to be hashed +* @param length_b length of the message in bits +*/ +void sha256(sha256_hash_t *dest, const void *msg, uint32_t length_b); +} +// MHAC SHA256 + +#define IPAD 0x36 //!< HMAC, inner hash, xor byte +#define OPAD 0x5C //!< HMAC, outer hash, xor byte + +#define HMAC_SHA256_BITS SHA256_HASH_BITS //!< Defines the size of a SHA-256 HMAC hash value in bits +#define HMAC_SHA256_BYTES SHA256_HASH_BYTES //!< Defines the size of a SHA-256 HMAC hash value in bytes +#define HMAC_SHA256_BLOCK_BITS SHA256_BLOCK_BITS //!< Defines the size of a SHA-256 HMAC input block in bits +#define HMAC_SHA256_BLOCK_BYTES SHA256_BLOCK_BYTES //!< Defines the size of a SHA-256 HMAC input block in bytes + +/** +* @brief hash context structure +*/ +typedef struct { + sha256_ctx_t a; //!< a + sha256_ctx_t b; //!< b +} hmac_sha256_ctx_t; + +/** +* @brief SHA256 HMAC function +* +* @param dest pointer to the location where the hash value is going to be written to +* @param key pointer to the key that's is needed for the HMAC calculation +* @param keylength_b length of the key +* @param msg pointer to the message thats going to be hashed +* @param msglength_b length of the message +*/ +void hmac_sha256(void *dest, const void *key, uint16_t keylength_b, const void *msg, + uint32_t msglength_b); + +#endif diff --git a/hal/crypto/ESP32/MyCryptoESP32.cpp b/hal/crypto/ESP32/MyCryptoESP32.cpp new file mode 100644 index 000000000..b41d72606 --- /dev/null +++ b/hal/crypto/ESP32/MyCryptoESP32.cpp @@ -0,0 +1,73 @@ +/* +* The MySensors Arduino library handles the wireless radio link and protocol +* between your home built sensors/actuators and HA controller of choice. +* The sensors forms a self healing radio network with optional repeaters. Each +* repeater and gateway builds a routing tables in EEPROM which keeps track of the +* network topology allowing messages to be routed to nodes. +* +* Created by Henrik Ekblad +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* +* Documentation: http://www.mysensors.org +* Support Forum: http://forum.mysensors.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +*/ + +#include "MyCryptoESP32.h" + +// ESP32 SHA256 +void SHA256(uint8_t *dest, const uint8_t *data, size_t dataLength) +{ + mbedtls_md_context_t ctx; + mbedtls_md_init(&ctx); + mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 0); + mbedtls_md_starts(&ctx); + mbedtls_md_update(&ctx, (const unsigned char *)data, dataLength); + mbedtls_md_finish(&ctx, dest); +} + + +// ESP32 SHA256HMAC +void SHA256HMAC(uint8_t *dest, const uint8_t *key, size_t keyLength, const uint8_t *data, + size_t dataLength) +{ + mbedtls_md_context_t ctx; + mbedtls_md_init(&ctx); + mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1); + mbedtls_md_starts(&ctx); + mbedtls_md_hmac_starts(&ctx, (const unsigned char *)key, keyLength); + mbedtls_md_hmac_update(&ctx, (const unsigned char *)data, dataLength); + mbedtls_md_hmac_finish(&ctx, dest); +} + +/* not tested yet +// ESP32 AES128 CBC +esp_aes_context aes_ctx; + +void AES128CBCInit(const uint8_t *key) +{ + esp_aes_init(&aes_ctx); + (void)esp_aes_setkey(&aes_ctx, key, 128); +} + +void AES128CBCEncrypt(uint8_t *dest, const uint8_t *data, size_t dataLength) +{ + uint8_t iv[16] = { 0 }; + esp_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_ENCRYPT, dataLength, iv, (const unsigned char *)data, (unsigned char *)dest); +} + +void AES128CBCDecrypt(uint8_t *dest, const uint8_t *data, size_t dataLength) +{ + uint8_t iv[16] = { 0 }; + esp_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_DECRYPT, dataLength, iv, (const unsigned char *)data, (unsigned char *)dest); +} + +void AES128CBCFree(void) +{ + esp_aes_free(&aes_ctx); +} +*/ diff --git a/hal/crypto/ESP32/MyCryptoESP32.h b/hal/crypto/ESP32/MyCryptoESP32.h new file mode 100644 index 000000000..8e7a295c8 --- /dev/null +++ b/hal/crypto/ESP32/MyCryptoESP32.h @@ -0,0 +1,27 @@ +/* +* The MySensors Arduino library handles the wireless radio link and protocol +* between your home built sensors/actuators and HA controller of choice. +* The sensors forms a self healing radio network with optional repeaters. Each +* repeater and gateway builds a routing tables in EEPROM which keeps track of the +* network topology allowing messages to be routed to nodes. +* +* Created by Henrik Ekblad +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* +* Documentation: http://www.mysensors.org +* Support Forum: http://forum.mysensors.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +*/ + +#ifndef MyCryptoESP32_h +#define MyCryptoESP32_h + +#include "hal/crypto/MyCryptoHAL.h" +#include "mbedtls/md.h" +#include "mbedtls/aes.h" + +#endif diff --git a/hal/crypto/MyCryptoHAL.h b/hal/crypto/MyCryptoHAL.h new file mode 100644 index 000000000..1c8dbfd82 --- /dev/null +++ b/hal/crypto/MyCryptoHAL.h @@ -0,0 +1,49 @@ +/* +* The MySensors Arduino library handles the wireless radio link and protocol +* between your home built sensors/actuators and HA controller of choice. +* The sensors forms a self healing radio network with optional repeaters. Each +* repeater and gateway builds a routing tables in EEPROM which keeps track of the +* network topology allowing messages to be routed to nodes. +* +* Created by Henrik Ekblad +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* +* Documentation: http://www.mysensors.org +* Support Forum: http://forum.mysensors.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +*/ + +#ifndef MyCryptoHAL_h +#define MyCryptoHAL_h + +// Implement these as functions or macros + +/** +* @brief SHA256 calculation +* +* The returned hash size is always 32 bytes. +* +* @param dest Buffer to return 32-byte hash. +* @param data Buffer with data to add. +* @param dataLength Size of data buffer. +*/ +void SHA256(uint8_t *dest, const uint8_t *data, size_t dataLength); + +/** +* @brief SHA256 HMAC calculation +* +* The returned hash size is always 32 bytes. +* +* @param dest Buffer to return 32-byte hash. +* @param key Buffer with HMAC key. +* @param keyLength Size of HMAC key. +* @param data Buffer with data to add. +* @param dataLength Size of data buffer. +*/ +void SHA256HMAC(uint8_t *dest, const uint8_t *key, size_t keyLength, const uint8_t *data, + size_t dataLength); +#endif diff --git a/hal/crypto/generic/MyCryptoGeneric.cpp b/hal/crypto/generic/MyCryptoGeneric.cpp new file mode 100644 index 000000000..fc2906479 --- /dev/null +++ b/hal/crypto/generic/MyCryptoGeneric.cpp @@ -0,0 +1,225 @@ +/* +* The MySensors Arduino library handles the wireless radio link and protocol +* between your home built sensors/actuators and HA controller of choice. +* The sensors forms a self healing radio network with optional repeaters. Each +* repeater and gateway builds a routing tables in EEPROM which keeps track of the +* network topology allowing messages to be routed to nodes. +* +* Created by Henrik Ekblad +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* +* Documentation: http://www.mysensors.org +* Support Forum: http://forum.mysensors.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +*/ + +#include "MyCryptoGeneric.h" + +const uint32_t SHA256K[] PROGMEM = { + 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, + 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174, + 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da, + 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967, + 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85, + 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070, + 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3, + 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2 +}; + +const uint8_t SHA256InitState[] PROGMEM = { + 0x67,0xe6,0x09,0x6a, // H0 + 0x85,0xae,0x67,0xbb, // H1 + 0x72,0xf3,0x6e,0x3c, // H2 + 0x3a,0xf5,0x4f,0xa5, // H3 + 0x7f,0x52,0x0e,0x51, // H4 + 0x8c,0x68,0x05,0x9b, // H5 + 0xab,0xd9,0x83,0x1f, // H6 + 0x19,0xcd,0xe0,0x5b // H7 +}; + +_SHA256buffer_t SHA256buffer; +uint8_t SHA256bufferOffset; +_SHA256state_t SHA256state; +uint32_t SHA256byteCount; +uint8_t SHA256keyBuffer[BLOCK_LENGTH]; + +void SHA256Init(void) +{ + (void)memcpy_P((void *)&SHA256state.b, (const void *)&SHA256InitState, 32); + SHA256byteCount = 0; + SHA256bufferOffset = 0; +} + +uint32_t SHA256ror32(const uint32_t number, const uint8_t bits) +{ + return ((number << (32 - bits)) | (number >> bits)); +} + +void SHA256hashBlock(void) +{ + uint32_t a, b, c, d, e, f, g, h, t1, t2; + + a = SHA256state.w[0]; + b = SHA256state.w[1]; + c = SHA256state.w[2]; + d = SHA256state.w[3]; + e = SHA256state.w[4]; + f = SHA256state.w[5]; + g = SHA256state.w[6]; + h = SHA256state.w[7]; + + for (uint8_t i = 0; i < 64; i++) { + if (i >= 16) { + t1 = SHA256buffer.w[i & 15] + SHA256buffer.w[(i - 7) & 15]; + t2 = SHA256buffer.w[(i - 2) & 15]; + t1 += SHA256ror32(t2, 17) ^ SHA256ror32(t2, 19) ^ (t2 >> 10); + t2 = SHA256buffer.w[(i - 15) & 15]; + t1 += SHA256ror32(t2, 7) ^ SHA256ror32(t2, 18) ^ (t2 >> 3); + SHA256buffer.w[i & 15] = t1; + } + t1 = h; + t1 += SHA256ror32(e, 6) ^ SHA256ror32(e, 11) ^ SHA256ror32(e, 25); // ∑1(e) + t1 += g ^ (e & (g ^ f)); // Ch(e,f,g) + t1 += pgm_read_dword(SHA256K + i); // Ki + t1 += SHA256buffer.w[i & 15]; // Wi + t2 = SHA256ror32(a, 2) ^ SHA256ror32(a, 13) ^ SHA256ror32(a, 22); // ∑0(a) + t2 += ((b & c) | (a & (b | c))); // Maj(a,b,c) + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + } + SHA256state.w[0] += a; + SHA256state.w[1] += b; + SHA256state.w[2] += c; + SHA256state.w[3] += d; + SHA256state.w[4] += e; + SHA256state.w[5] += f; + SHA256state.w[6] += g; + SHA256state.w[7] += h; +} + +void SHA256addUncounted(const uint8_t data) +{ + SHA256buffer.b[SHA256bufferOffset ^ 3] = data; + SHA256bufferOffset++; + if (SHA256bufferOffset == BLOCK_LENGTH) { + SHA256hashBlock(); + SHA256bufferOffset = 0; + } +} + + +void SHA256Add(const uint8_t data) +{ + SHA256byteCount++; + SHA256addUncounted(data); +} + +void SHA256Add(const uint8_t *data, size_t dataLength) +{ + while (dataLength--) { + SHA256Add(*data++); + } +} + +void SHA256Result(uint8_t *dest) +{ + // Pad to complete the last block + SHA256addUncounted(0x80); + while (SHA256bufferOffset != 56) { + SHA256addUncounted(0x00); + } + + // Append length in the last 8 bytes + SHA256addUncounted(0); // We're only using 32 bit lengths + SHA256addUncounted(0); // But SHA-1 supports 64 bit lengths + SHA256addUncounted(0); // So zero pad the top bits + SHA256addUncounted(SHA256byteCount >> 29); // Shifting to multiply by 8 + SHA256addUncounted(SHA256byteCount >> 21); // as SHA-1 supports bitstreams as well as + SHA256addUncounted(SHA256byteCount >> 13); // byte. + SHA256addUncounted(SHA256byteCount >> 5); + SHA256addUncounted(SHA256byteCount << 3); + + // Swap byte order back + for (uint8_t i = 0; i<8; i++) { + uint32_t a, b; + a = SHA256state.w[i]; + b = a << 24; + b |= (a << 8) & 0x00ff0000; + b |= (a >> 8) & 0x0000ff00; + b |= a >> 24; + SHA256state.w[i] = b; + } + (void)memcpy((void *)dest, (const void *)SHA256state.b, 32); + // Return pointer to hash (20 characters) + //return SHA256state.b; +} + +void SHA256(uint8_t *dest, const uint8_t *data, size_t dataLength) +{ + SHA256Init(); + SHA256Add(data, dataLength); + SHA256Result(dest); +} + +// SHA256HMAC + +void SHA256HMACInit(const uint8_t *key, size_t keyLength) +{ + (void)memset((void *)&SHA256keyBuffer, 0x00, BLOCK_LENGTH); + if (keyLength > BLOCK_LENGTH) { + // Hash long keys + SHA256Init(); + SHA256Add(key, keyLength); + SHA256Result(SHA256keyBuffer); + } else { + // Block length keys are used as is + (void)memcpy((void *)SHA256keyBuffer, (const void *)key, keyLength); + } + // Start inner hash + SHA256Init(); + for (uint8_t i = 0; i < BLOCK_LENGTH; i++) { + SHA256Add(SHA256keyBuffer[i] ^ HMAC_IPAD); + } +} + +void SHA256HMACAdd(const uint8_t data) +{ + SHA256Add(data); +} + +void SHA256HMACAdd(const uint8_t *data, size_t dataLength) +{ + SHA256Add(data, dataLength); +} + +void SHA256HMACResult(uint8_t *dest) +{ + uint8_t innerHash[HASH_LENGTH]; + // Complete inner hash + SHA256Result(innerHash); + // Calculate outer hash + SHA256Init(); + for (uint8_t i = 0; i < BLOCK_LENGTH; i++) { + SHA256Add(SHA256keyBuffer[i] ^ HMAC_OPAD); + } + SHA256Add(innerHash, HASH_LENGTH); + SHA256Result(dest); +} + +void SHA256HMAC(uint8_t *dest, const uint8_t *key, size_t keyLength, const uint8_t *data, + size_t dataLength) +{ + SHA256HMACInit(key, keyLength); + SHA256HMACAdd(data, dataLength); + SHA256HMACResult(dest); +} diff --git a/hal/crypto/generic/MyCryptoGeneric.h b/hal/crypto/generic/MyCryptoGeneric.h new file mode 100644 index 000000000..1b361e605 --- /dev/null +++ b/hal/crypto/generic/MyCryptoGeneric.h @@ -0,0 +1,50 @@ +/* +* The MySensors Arduino library handles the wireless radio link and protocol +* between your home built sensors/actuators and HA controller of choice. +* The sensors forms a self healing radio network with optional repeaters. Each +* repeater and gateway builds a routing tables in EEPROM which keeps track of the +* network topology allowing messages to be routed to nodes. +* +* Created by Henrik Ekblad +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* +* Documentation: http://www.mysensors.org +* Support Forum: http://forum.mysensors.org +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +*/ + +// This code is taken from https://github.com/Cathedrow/Cryptosuite (Peter Knight) and is lightly modified for MySensors use + +#ifndef MyCryptoESP32_h +#define MyCryptoESP32_h + +#include "hal/crypto/MyCryptoHAL.h" + +#define HASH_LENGTH 32 //!< HASH_LENGTH +#define BLOCK_LENGTH 64 //!< BLOCK_LENGTH + +/** +* @brief buffer for SHA256 calculator +*/ +union _SHA256buffer_t { + uint8_t b[BLOCK_LENGTH]; //!< SHA256 b + uint32_t w[BLOCK_LENGTH / 4]; //!< SHA256 w +}; + +/** +* @brief state variables for SHA256 calculator +*/ +union _SHA256state_t { + uint8_t b[HASH_LENGTH]; //!< SHA256 b + uint32_t w[HASH_LENGTH / 4]; //!< SHA256 w +}; + +// SHA256 HMAC padding bytes +#define HMAC_IPAD 0x36 //!< HMAC_IPAD +#define HMAC_OPAD 0x5c //!< HMAC_OPAD + +#endif From c8d951d3df05a2371b911ee9f9303c9437f89dbd Mon Sep 17 00:00:00 2001 From: Jeeva Kandasamy Date: Tue, 21 Aug 2018 23:01:10 +0530 Subject: [PATCH 09/31] Update #1184, RFM69 frequency band support for India (#1185) --- MyConfig.h | 1 + configure | 4 +++- drivers/RFM69/new/RFM69_new.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/MyConfig.h b/MyConfig.h index 5c2098725..9d11af507 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -604,6 +604,7 @@ * * - RFM69_315MHZ * - RFM69_433MHZ + * - RFM69_865MHZ * - RFM69_868MHZ * - RFM69_915MHZ * - Custom frequency in Hz (new %RFM69 driver only) diff --git a/configure b/configure index 27905be1e..a0fa47656 100755 --- a/configure +++ b/configure @@ -76,7 +76,7 @@ MySensors options: personalized with the same AES key. --my-rx-message-buffer-size= Buffer size for incoming messages when using rf24 interrupts. [20] - --my-rfm69-frequency=[315|433|868|915] + --my-rfm69-frequency=[315|433|865|868|915] RFM69 Module Frequency. [868] --my-is-rfm69hw Enable high-powered rfm69hw. --my-rfm69-irq-pin= Pin number connected to RFM69 IRQ pin. @@ -437,6 +437,8 @@ for opt do CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_315MHZ $CPPFLAGS" elif [[ ${optarg} == "433" ]]; then CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_433MHZ $CPPFLAGS" + elif [[ ${optarg} == "865" ]]; then + CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_865MHZ $CPPFLAGS" elif [[ ${optarg} == "868" ]]; then CPPFLAGS="-DMY_RFM69_FREQUENCY=RFM69_868MHZ $CPPFLAGS" elif [[ ${optarg} == "915" ]]; then diff --git a/drivers/RFM69/new/RFM69_new.h b/drivers/RFM69/new/RFM69_new.h index 1f08b084f..45974228b 100644 --- a/drivers/RFM69/new/RFM69_new.h +++ b/drivers/RFM69/new/RFM69_new.h @@ -177,6 +177,7 @@ extern HardwareSPI SPI; //!< SPI // available frequency bands, non trivial values to avoid misconfiguration #define RFM69_315MHZ (315000000ul) //!< RFM69_315MHZ #define RFM69_433MHZ (433920000ul) //!< RFM69_433MHZ, center frequencz 433.92 MHz +#define RFM69_865MHZ (865500000ul) //!< RFM69_865MHZ, center frequency 865.5 MHz #define RFM69_868MHZ (868000000ul) //!< RFM69_868MHZ #define RFM69_915MHZ (915000000ul) //!< RFM69_915MHZ From 6ffe29cb5fcfa33fa83133044c2d16ee45c66697 Mon Sep 17 00:00:00 2001 From: tekka Date: Wed, 22 Aug 2018 20:50:16 +0200 Subject: [PATCH 10/31] Code maintenance (#1186) --- .ci/butler.sh | 2 +- Documentation/mainpage.dox | 2 +- Documentation/styles/html/footerFile.html | 2 +- MyASM.S | 2 +- MyConfig.h | 26 ++++-- MySensors.h | 31 +++++-- README.md | 2 +- configure | 12 +-- core/MyCapabilities.h | 4 +- core/MyEepromAddresses.h | 6 +- core/MyGatewayTransport.cpp | 4 +- core/MyGatewayTransport.h | 4 +- core/MyGatewayTransportEthernet.cpp | 2 +- core/MyGatewayTransportMQTTClient.cpp | 4 +- core/MyGatewayTransportSerial.cpp | 6 +- core/MyInclusionMode.cpp | 6 +- core/MyInclusionMode.h | 4 +- core/MyIndication.cpp | 4 +- core/MyIndication.h | 4 +- core/MyLeds.cpp | 6 +- core/MyLeds.h | 6 +- core/MyMessage.cpp | 72 ++++++++-------- core/MyMessage.h | 82 ++++++++++--------- core/MyOTAFirmwareUpdate.cpp | 4 +- core/MyOTAFirmwareUpdate.h | 4 +- core/MyOTALogging.cpp | 4 +- core/MyOTALogging.h | 4 +- core/MyPrivateConfig.h.sample | 8 +- core/MyProtocol.h | 6 +- core/MyProtocolMySensors.cpp | 6 +- core/MySensorsCore.cpp | 4 +- core/MySensorsCore.h | 7 +- core/MySigning.cpp | 4 +- core/MySigning.h | 4 +- core/MySigningAtsha204.cpp | 4 +- core/MySigningAtsha204Soft.cpp | 4 +- core/MySplashScreen.cpp | 4 +- core/MySplashScreen.h | 4 +- core/MyTransport.cpp | 12 +-- core/MyTransport.h | 25 ++---- core/Version.h | 10 +-- drivers/BCM/BCM.cpp | 4 +- drivers/BCM/BCM.h | 4 +- drivers/BCM/RPi.cpp | 4 +- drivers/BCM/RPi.h | 4 +- drivers/BCM/SPIBCM.cpp | 4 +- drivers/BCM/SPIBCM.h | 4 +- drivers/Linux/Arduino.h | 4 +- drivers/Linux/EthernetClient.cpp | 4 +- drivers/Linux/EthernetClient.h | 4 +- drivers/Linux/EthernetServer.cpp | 4 +- drivers/Linux/EthernetServer.h | 4 +- drivers/Linux/GPIO.cpp | 4 +- drivers/Linux/GPIO.h | 4 +- drivers/Linux/SPI.h | 4 +- drivers/Linux/SPIDEV.cpp | 4 +- drivers/Linux/SPIDEV.h | 4 +- drivers/Linux/SerialPort.cpp | 4 +- drivers/Linux/SerialPort.h | 4 +- drivers/Linux/SoftEeprom.cpp | 2 +- drivers/Linux/SoftEeprom.h | 2 +- drivers/Linux/StdInOutStream.cpp | 4 +- drivers/Linux/StdInOutStream.h | 4 +- drivers/Linux/compatibility.cpp | 4 +- drivers/Linux/config.c | 2 +- drivers/Linux/config.h | 2 +- drivers/Linux/interrupt.cpp | 4 +- drivers/Linux/interrupt.h | 4 +- drivers/Linux/log.c | 2 +- drivers/Linux/log.h | 2 +- drivers/NRF5/Radio.h | 4 +- drivers/NRF5/Radio_ESB.cpp | 10 +-- drivers/NRF5/Radio_ESB.h | 6 +- drivers/RF24/RF24.cpp | 2 +- drivers/RF24/RF24.h | 4 +- drivers/RF24/RF24registers.h | 2 +- drivers/RFM69/new/RFM69_new.cpp | 2 +- drivers/RFM69/new/RFM69_new.h | 4 +- drivers/RFM69/new/RFM69registers_new.h | 2 +- drivers/RFM95/RFM95.cpp | 2 +- drivers/RFM95/RFM95.h | 2 +- drivers/RFM95/RFM95registers.h | 2 +- .../AirQualitySensor/AirQualitySensor.ino | 8 +- .../BatteryPoweredSensor.ino | 8 +- .../BinarySwitchSleepSensor.ino | 8 +- examples/CO2Sensor/CO2Sensor.ino | 8 +- .../ClearEepromConfig/ClearEepromConfig.ino | 4 +- .../DimmableLEDActuator.ino | 8 +- examples/DimmableLight/DimmableLight.ino | 8 +- examples/DustSensor/DustSensor.ino | 8 +- examples/DustSensorDSM/DustSensorDSM.ino | 8 +- .../EnergyMeterPulseSensor.ino | 8 +- examples/GatewayESP32/GatewayESP32.ino | 4 +- .../GatewayESP32MQTTClient.ino | 4 +- examples/GatewayESP8266/GatewayESP8266.ino | 8 +- .../GatewayESP8266MQTTClient.ino | 8 +- .../GatewayESP8266OTA/GatewayESP8266OTA.ino | 8 +- .../GatewayGSMMQTTClient.ino | 14 ++-- examples/GatewaySerial/GatewaySerial.ino | 6 +- .../GatewaySerialRS485/GatewaySerialRS485.ino | 4 +- examples/GatewayW5100/GatewayW5100.ino | 8 +- .../GatewayW5100MQTTClient.ino | 8 +- examples/LightSensor/LightSensor.ino | 8 +- examples/LogOTAGateway/LogOTAGateway.ino | 6 +- examples/LogOTANode/LogOTANode.ino | 6 +- examples/MockMySensors/MockMySensors.ino | 34 ++++++-- examples/MotionSensor/MotionSensor.ino | 8 +- .../MotionSensorRS485/MotionSensorRS485.ino | 6 +- examples/Node2Node/Node2Node.ino | 46 ++++++----- examples/PHSensor/PHSensor.ino | 49 +++++------ examples/PassiveNode/PassiveNode.ino | 8 +- examples/PingPongSensor/MYSLog.h | 21 ++++- examples/PingPongSensor/PingPongSensor.ino | 31 +++++-- .../RFM69_RFM95_ATC_SignalReport.ino | 6 +- examples/RelayActuator/RelayActuator.ino | 8 +- examples/RepeaterNode/RepeaterNode.ino | 8 +- .../SecretKnockSensor/SecretKnockSensor.ino | 8 +- examples/SecureActuator/SecureActuator.ino | 8 +- .../SecurityPersonalizer.ino | 5 +- .../SensebenderGatewaySerial.ino | 6 +- examples/SoilMoistSensor/SoilMoistSensor.ino | 6 +- examples/UVSensor/UVSensor.ino | 8 +- examples/VibrationSensor/VibrationSensor.ino | 10 +-- .../WaterMeterPulseSensor.ino | 8 +- examples_linux/mysgw.cpp | 2 +- hal/architecture/AVR/MyHwAVR.cpp | 6 +- hal/architecture/AVR/MyHwAVR.h | 15 ++-- hal/architecture/AVR/MyMainAVR.cpp | 4 +- hal/architecture/ESP32/MyHwESP32.cpp | 7 +- hal/architecture/ESP32/MyHwESP32.h | 8 +- hal/architecture/ESP32/MyMainESP32.cpp | 2 +- hal/architecture/ESP8266/MyHwESP8266.cpp | 17 ++-- hal/architecture/ESP8266/MyHwESP8266.h | 13 +-- hal/architecture/ESP8266/MyMainESP8266.cpp | 4 +- hal/architecture/Linux/MyHwLinuxGeneric.cpp | 20 ++--- hal/architecture/Linux/MyHwLinuxGeneric.h | 15 ++-- hal/architecture/Linux/MyMainLinuxGeneric.cpp | 4 +- hal/architecture/MyHw.h | 18 ++-- hal/architecture/NRF5/MyHwNRF5.cpp | 40 ++++----- hal/architecture/NRF5/MyHwNRF5.h | 25 +++--- hal/architecture/NRF5/MyMainNRF5.cpp | 4 +- hal/architecture/SAMD/MyHwSAMD.cpp | 33 ++++---- hal/architecture/SAMD/MyHwSAMD.h | 17 ++-- hal/architecture/SAMD/MyMainSAMD.cpp | 4 +- hal/architecture/STM32F1/MyHwSTM32F1.cpp | 20 ++--- hal/architecture/STM32F1/MyHwSTM32F1.h | 12 +-- hal/architecture/STM32F1/MyMainSTM32F1.cpp | 6 +- hal/architecture/Teensy3/MyHwTeensy3.cpp | 10 +-- hal/architecture/Teensy3/MyHwTeensy3.h | 26 ++---- hal/architecture/Teensy3/MyMainTeensy3.cpp | 4 +- hal/crypto/AVR/MyCryptoAVR.cpp | 2 +- hal/crypto/AVR/MyCryptoAVR.h | 2 +- hal/crypto/ESP32/MyCryptoESP32.cpp | 2 +- hal/crypto/ESP32/MyCryptoESP32.h | 2 +- hal/crypto/MyCryptoHAL.h | 2 +- hal/crypto/generic/MyCryptoGeneric.cpp | 2 +- hal/crypto/generic/MyCryptoGeneric.h | 2 +- hal/transport/MyTransportHAL.h | 2 +- .../NRF5_ESB/MyTransportNRF5_ESB.cpp | 2 +- hal/transport/RF24/MyTransportRF24.cpp | 2 +- hal/transport/RFM69/MyTransportRFM69.cpp | 2 +- hal/transport/RFM95/MyTransportRFM95.cpp | 2 +- hal/transport/RS485/MyTransportRS485.cpp | 2 +- library.json | 4 +- library.properties | 4 +- ...ard_signing_no_whitelisting_full_debug.ino | 6 +- .../hard_signing_whitelisting_full_debug.ino | 6 +- ...gning_whitelisting_full_debug_nodelock.ino | 6 +- ...ning_whitelisting_full_debug_nrf24_rsa.ino | 6 +- ...ning_whitelisting_full_debug_rfm69_rsa.ino | 4 +- ...ning_whitelisting_full_debug_rfm95_rsa.ino | 4 +- .../new_rfm69_driver/new_rfm69_driver.ino | 4 +- .../ota_firmware_update_nrf24.ino | 6 +- ...t_hard_signing_whitelisting_full_debug.ino | 4 +- ...t_soft_signing_whitelisting_full_debug.ino | 4 +- ...oft_signing_no_whitelisting_full_debug.ino | 6 +- .../soft_signing_whitelisting_full_debug.ino | 6 +- 177 files changed, 740 insertions(+), 701 deletions(-) diff --git a/.ci/butler.sh b/.ci/butler.sh index 3fdce1710..bdf7db29e 100755 --- a/.ci/butler.sh +++ b/.ci/butler.sh @@ -81,7 +81,7 @@ fi astyle --options=.mystools/astyle/config/style.cfg -nq --recursive "*.h" "*.c" "*.cpp" git diff > restyling.patch if [ -s restyling.patch ]; then - echo "I am afraid your coding style is not entirely in line with the MySensors preffered style.
A mail with a patch has been sent to you that, if applied to your PR, will make it follow the MySensors coding standards.

" >> butler.html + echo "I am afraid your coding style is not entirely in line with the MySensors prefered style.
A mail with a patch has been sent to you that, if applied to your PR, will make it follow the MySensors coding standards.

" >> butler.html echo "You can apply the patch using:
" >> butler.html echo "git apply restyling.patch
" >> butler.html echo "
" >> butler.html diff --git a/Documentation/mainpage.dox b/Documentation/mainpage.dox index 7d16379ea..9cc8d2973 100644 --- a/Documentation/mainpage.dox +++ b/Documentation/mainpage.dox @@ -7,7 +7,7 @@ Are you a core/library developer, see @ref internals @copyright (C) 2013-2018 Sensnology AB -Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors */ /* diff --git a/Documentation/styles/html/footerFile.html b/Documentation/styles/html/footerFile.html index 4a2a680ee..6413607af 100644 --- a/Documentation/styles/html/footerFile.html +++ b/Documentation/styles/html/footerFile.html @@ -12,7 +12,7 @@ diff --git a/MyASM.S b/MyASM.S index a87b93d90..0189e0ef2 100644 --- a/MyASM.S +++ b/MyASM.S @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/MyConfig.h b/MyConfig.h index 9d11af507..b118efc4a 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -16,6 +16,7 @@ * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. */ + /** * @file MyConfig.h * @ingroup MyConfigGrp @@ -35,6 +36,7 @@ * @brief These options control serial and debugging features and functionalities in the library. * @{ */ + /** * @def MY_DEBUG * @brief Define MY_DEBUG to show debug prints. @@ -46,6 +48,7 @@ * the flag in your sketch. */ //#define MY_DEBUG + /** * @def MY_DEBUGDEVICE * @brief Define MY_DEBUGDEVICE to redirect debug prints. @@ -61,6 +64,7 @@ * hardware serial device or a software serial device. */ //#define MY_DEBUGDEVICE + /** * @def MY_DEBUG_OTA * @brief Define MY_DEBUG_OTA to redirect debug prints to given node ID @@ -268,9 +272,16 @@ * | Silicon Labs(?) | SI24R1 * @{ */ -// legacy + +// legacy - remove for 3.0.0 +/** +* @def MY_RADIO_NRF24 +* @brief Define this to use a RF24-based radio transport for sensor network communication. +* @deprecated This flag is deprecated and replaced by @ref MY_RADIO_RF24 +*/ #ifdef MY_RADIO_NRF24 -//MY_RADIO_NRF24 is deprecated +#warning MY_RADIO_NRF24 is deprecated, use MY_RADIO_RF24 instead. +#undef MY_RADIO_NRF24 #define MY_RADIO_RF24 #endif @@ -332,7 +343,7 @@ /** * @def MY_RF24_POWER_PIN - * @brief Define this to use the NRF24 power pin (optional). + * @brief Define this to use the RF24 power pin (optional). */ //#define MY_RF24_POWER_PIN (3) @@ -1118,7 +1129,7 @@ * @brief Timeout in ms until transport is ready during startup, set to 0 for no timeout */ #ifndef MY_TRANSPORT_WAIT_READY_MS -#define MY_TRANSPORT_WAIT_READY_MS (0ul) +#define MY_TRANSPORT_WAIT_READY_MS (0) #endif /** @@ -2098,9 +2109,8 @@ #endif // temp. workaround for nRF5 verifier: redirect RF24 to NRF_ESB -#if defined(ARDUINO_ARCH_NRF5) && (defined(MY_RADIO_RF24) || defined(MY_RADIO_NRF24) ) +#if defined(ARDUINO_ARCH_NRF5) && (defined(MY_RADIO_RF24) ) #undef MY_RADIO_RF24 -#undef MY_RADIO_NRF24 #define MY_RADIO_NRF5_ESB #endif @@ -2269,6 +2279,7 @@ * @brief Supplied by your cell carrier / mobile operator. If not required, leave undefined. */ #define MY_GSM_USR + // LED #define MY_DEFAULT_ERR_LED_PIN #define MY_DEFAULT_TX_LED_PIN @@ -2293,6 +2304,7 @@ #define MY_RS485_HWSERIAL // RF24 #define MY_RADIO_RF24 +#define MY_RADIO_NRF24 //deprecated #define MY_DEBUG_VERBOSE_RF24 #define MY_RF24_POWER_PIN #define MY_RF24_IRQ_PIN diff --git a/MySensors.h b/MySensors.h index 734efea2e..b1722a01f 100644 --- a/MySensors.h +++ b/MySensors.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -22,8 +22,6 @@ * @ingroup publics * @{ * @brief The primary public API declaration for the MySensors library - * - * */ /** @@ -41,11 +39,6 @@ #include #endif -// general macros -#if !defined(_BV) -#define _BV(x) (1<<(x)) //!< _BV -#endif - #include "MyConfig.h" #include "core/MySplashScreen.h" #include "core/MySensorsCore.h" @@ -90,6 +83,27 @@ #error Hardware abstraction not defined (unsupported platform) #endif +// commonly used macros, sometimes missing in arch definitions +#if !defined(_BV) +#define _BV(x) (1<<(x)) //!< _BV +#endif + +#if !defined(min) && !defined(__linux__) +#define min(a,b) ((a)<(b)?(a):(b)) //!< min +#endif + +#if !defined(max) && !defined(__linux__) +#define max(a,b) ((a)>(b)?(a):(b)) //!< max +#endif + +#if !defined(MIN) +#define MIN min //!< MIN +#endif + +#if !defined(MAX) +#define MAX max //!< MAX +#endif + // OTA Debug second part, depends on HAL #if defined(MY_OTA_LOG_SENDER_FEATURE) || defined(MY_OTA_LOG_RECEIVER_FEATURE) #include "core/MyOTALogging.cpp" @@ -135,7 +149,6 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs #endif #endif - // FLASH #if defined(MY_OTA_FIRMWARE_FEATURE) #ifndef MCUBOOT_PRESENT diff --git a/README.md b/README.md index c56472174..5a7726bb9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -MySensors Library v2.3.1-alpha +MySensors Library v2.3.1-beta Please visit www.mysensors.org for more information diff --git a/configure b/configure index a0fa47656..65b47573f 100755 --- a/configure +++ b/configure @@ -62,14 +62,14 @@ MySensors options: MQTT publish topic prefix. --my-mqtt-subscribe-topic-prefix= MQTT subscribe topic prefix. - --my-transport=[none|nrf24|rs485|rfm95|rfm69] - Set the transport to be used to communicate with other nodes. [nrf24] + --my-transport=[none|rf24|rs485|rfm95|rfm69] + Set the transport to be used to communicate with other nodes. [rf24] --my-rf24-channel=<0-125> RF channel for the sensor net. [76] --my-rf24-pa-level=[RF24_PA_MAX|RF24_PA_LOW] RF24 PA level. [RF24_PA_MAX] --my-rf24-ce-pin= Pin number to use for rf24 Chip-Enable. --my-rf24-cs-pin= Pin number to use for rf24 Chip-Select. - --my-rf24-irq-pin= Pin number connected to nRF24L01 IRQ pin. + --my-rf24-irq-pin= Pin number connected to nRF24L01P IRQ pin. --my-rf24-encryption-enabled Enables RF24 encryption. All nodes and gateway must have this enabled, and all must be @@ -285,7 +285,7 @@ function gcc_cpu_flags { # Default values debug=enable gateway_type=ethernet -transport_type=nrf24 +transport_type=rf24 signing=none signing_request_signatures=false encryption=false @@ -621,8 +621,8 @@ printf " ${OK} Type: ${gateway_type}.\n" if [[ ${transport_type} == "none" ]]; then # Transport disabled : -elif [[ ${transport_type} == "nrf24" ]]; then - CPPFLAGS="-DMY_RADIO_NRF24 $CPPFLAGS" +elif [[ ${transport_type} == "rf24" ]]; then + CPPFLAGS="-DMY_RADIO_RF24 $CPPFLAGS" elif [[ ${transport_type} == "rfm69" ]]; then CPPFLAGS="-DMY_RADIO_RFM69 -DMY_RFM69_NEW_DRIVER $CPPFLAGS" elif [[ ${transport_type} == "rs485" ]]; then diff --git a/core/MyCapabilities.h b/core/MyCapabilities.h index 629ea6b64..3be1c5f41 100644 --- a/core/MyCapabilities.h +++ b/core/MyCapabilities.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyEepromAddresses.h b/core/MyEepromAddresses.h index 7bb39d6f2..cdc7fef1a 100644 --- a/core/MyEepromAddresses.h +++ b/core/MyEepromAddresses.h @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyGatewayTransport.cpp b/core/MyGatewayTransport.cpp index b37bb6b5b..064221b02 100644 --- a/core/MyGatewayTransport.cpp +++ b/core/MyGatewayTransport.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,7 +7,7 @@ * * Created by Tomas Hozza * Copyright (C) 2015 Tomas Hozza - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyGatewayTransport.h b/core/MyGatewayTransport.h index 9ddee8c97..7fcd9bef4 100644 --- a/core/MyGatewayTransport.h +++ b/core/MyGatewayTransport.h @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,7 +7,7 @@ * * Created by Tomas Hozza * Copyright (C) 2015 Tomas Hozza - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyGatewayTransportEthernet.cpp b/core/MyGatewayTransportEthernet.cpp index 6d1f576ae..7ba465007 100644 --- a/core/MyGatewayTransportEthernet.cpp +++ b/core/MyGatewayTransportEthernet.cpp @@ -7,7 +7,7 @@ * * Created by Tomas Hozza * Copyright (C) 2015 Tomas Hozza - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyGatewayTransportMQTTClient.cpp b/core/MyGatewayTransportMQTTClient.cpp index 1c96dab96..ad9a92930 100644 --- a/core/MyGatewayTransportMQTTClient.cpp +++ b/core/MyGatewayTransportMQTTClient.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2017 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyGatewayTransportSerial.cpp b/core/MyGatewayTransportSerial.cpp index a092cfdbc..9bab20e06 100644 --- a/core/MyGatewayTransportSerial.cpp +++ b/core/MyGatewayTransportSerial.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyInclusionMode.cpp b/core/MyInclusionMode.cpp index 0b50621b3..94a1f2751 100644 --- a/core/MyInclusionMode.cpp +++ b/core/MyInclusionMode.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyInclusionMode.h b/core/MyInclusionMode.h index d1296d32f..8f2ed0e19 100644 --- a/core/MyInclusionMode.h +++ b/core/MyInclusionMode.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyIndication.cpp b/core/MyIndication.cpp index 473da5ec6..47f753bb0 100644 --- a/core/MyIndication.cpp +++ b/core/MyIndication.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyIndication.h b/core/MyIndication.h index 7c446b088..310d1557c 100644 --- a/core/MyIndication.h +++ b/core/MyIndication.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyLeds.cpp b/core/MyLeds.cpp index 322fce385..739c8ea3b 100644 --- a/core/MyLeds.cpp +++ b/core/MyLeds.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyLeds.h b/core/MyLeds.h index b7ea85233..1b318e95a 100644 --- a/core/MyLeds.h +++ b/core/MyLeds.h @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyMessage.cpp b/core/MyMessage.cpp index 838272589..b749b182b 100644 --- a/core/MyMessage.cpp +++ b/core/MyMessage.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -23,19 +23,19 @@ #include #include -MyMessage::MyMessage() +MyMessage::MyMessage(void) { clear(); } -MyMessage::MyMessage(uint8_t _sensor, uint8_t _type) +MyMessage::MyMessage(const uint8_t _sensor, const uint8_t _type) { clear(); sensor = _sensor; type = _type; } -void MyMessage::clear() +void MyMessage::clear(void) { last = 0u; sender = 0u; @@ -50,23 +50,23 @@ void MyMessage::clear() miSetVersion(PROTOCOL_VERSION); } -bool MyMessage::isAck() const +bool MyMessage::isAck(void) const { return miGetAck(); } -uint8_t MyMessage::getCommand() const +uint8_t MyMessage::getCommand(void) const { return miGetCommand(); } /* Getters for payload converted to desired form */ -void* MyMessage::getCustom() const +void* MyMessage::getCustom(void) const { return (void *)data; } -const char* MyMessage::getString() const +const char* MyMessage::getString(void) const { uint8_t payloadType = miGetPayloadType(); if (payloadType == P_STRING) { @@ -76,7 +76,7 @@ const char* MyMessage::getString() const } } -char MyMessage::i2h(uint8_t i) const +char MyMessage::i2h(const uint8_t i) const { uint8_t k = i & 0x0F; if (k <= 9) { @@ -111,20 +111,20 @@ char* MyMessage::getString(char *buffer) const uint8_t payloadType = miGetPayloadType(); if (buffer != NULL) { if (payloadType == P_STRING) { - strncpy(buffer, data, miGetLength()); + (void)strncpy(buffer, data, miGetLength()); buffer[miGetLength()] = 0; } else if (payloadType == P_BYTE) { - itoa(bValue, buffer, 10); + (void)itoa(bValue, buffer, 10); } else if (payloadType == P_INT16) { - itoa(iValue, buffer, 10); + (void)itoa(iValue, buffer, 10); } else if (payloadType == P_UINT16) { - utoa(uiValue, buffer, 10); + (void)utoa(uiValue, buffer, 10); } else if (payloadType == P_LONG32) { - ltoa(lValue, buffer, 10); + (void)ltoa(lValue, buffer, 10); } else if (payloadType == P_ULONG32) { - ultoa(ulValue, buffer, 10); + (void)ultoa(ulValue, buffer, 10); } else if (payloadType == P_FLOAT32) { - dtostrf(fValue,2,min(fPrecision, (uint8_t)8),buffer); + (void)dtostrf(fValue, 2, min(fPrecision, (uint8_t)8), buffer); } else if (payloadType == P_CUSTOM) { return getCustomString(buffer); } @@ -134,12 +134,12 @@ char* MyMessage::getString(char *buffer) const } } -bool MyMessage::getBool() const +bool MyMessage::getBool(void) const { return getByte(); } -uint8_t MyMessage::getByte() const +uint8_t MyMessage::getByte(void) const { if (miGetPayloadType() == P_BYTE) { return data[0]; @@ -151,7 +151,7 @@ uint8_t MyMessage::getByte() const } -float MyMessage::getFloat() const +float MyMessage::getFloat(void) const { if (miGetPayloadType() == P_FLOAT32) { return fValue; @@ -162,7 +162,7 @@ float MyMessage::getFloat() const } } -int32_t MyMessage::getLong() const +int32_t MyMessage::getLong(void) const { if (miGetPayloadType() == P_LONG32) { return lValue; @@ -173,7 +173,7 @@ int32_t MyMessage::getLong() const } } -uint32_t MyMessage::getULong() const +uint32_t MyMessage::getULong(void) const { if (miGetPayloadType() == P_ULONG32) { return ulValue; @@ -184,7 +184,7 @@ uint32_t MyMessage::getULong() const } } -int16_t MyMessage::getInt() const +int16_t MyMessage::getInt(void) const { if (miGetPayloadType() == P_INT16) { return iValue; @@ -195,7 +195,7 @@ int16_t MyMessage::getInt() const } } -uint16_t MyMessage::getUInt() const +uint16_t MyMessage::getUInt(void) const { if (miGetPayloadType() == P_UINT16) { return uiValue; @@ -207,26 +207,26 @@ uint16_t MyMessage::getUInt() const } -MyMessage& MyMessage::setType(uint8_t _type) +MyMessage& MyMessage::setType(const uint8_t _type) { type = _type; return *this; } -MyMessage& MyMessage::setSensor(uint8_t _sensor) +MyMessage& MyMessage::setSensor(const uint8_t _sensor) { sensor = _sensor; return *this; } -MyMessage& MyMessage::setDestination(uint8_t _destination) +MyMessage& MyMessage::setDestination(const uint8_t _destination) { destination = _destination; return *this; } // Set payload -MyMessage& MyMessage::set(void* value, uint8_t length) +MyMessage& MyMessage::set(const void* value, const uint8_t length) { uint8_t payloadLength = value == NULL ? 0 : min(length, (uint8_t)MAX_PAYLOAD); miSetLength(payloadLength); @@ -265,7 +265,7 @@ MyMessage& MyMessage::set(const __FlashStringHelper* value) #endif -MyMessage& MyMessage::set(bool value) +MyMessage& MyMessage::set(const bool value) { miSetLength(1); miSetPayloadType(P_BYTE); @@ -273,7 +273,7 @@ MyMessage& MyMessage::set(bool value) return *this; } -MyMessage& MyMessage::set(uint8_t value) +MyMessage& MyMessage::set(const uint8_t value) { miSetLength(1); miSetPayloadType(P_BYTE); @@ -281,7 +281,7 @@ MyMessage& MyMessage::set(uint8_t value) return *this; } -MyMessage& MyMessage::set(float value, uint8_t decimals) +MyMessage& MyMessage::set(const float value, const uint8_t decimals) { miSetLength(5); // 32 bit float + persi miSetPayloadType(P_FLOAT32); @@ -290,7 +290,7 @@ MyMessage& MyMessage::set(float value, uint8_t decimals) return *this; } -MyMessage& MyMessage::set(uint32_t value) +MyMessage& MyMessage::set(const uint32_t value) { miSetPayloadType(P_ULONG32); miSetLength(4); @@ -298,7 +298,7 @@ MyMessage& MyMessage::set(uint32_t value) return *this; } -MyMessage& MyMessage::set(int32_t value) +MyMessage& MyMessage::set(const int32_t value) { miSetPayloadType(P_LONG32); miSetLength(4); @@ -306,7 +306,7 @@ MyMessage& MyMessage::set(int32_t value) return *this; } -MyMessage& MyMessage::set(uint16_t value) +MyMessage& MyMessage::set(const uint16_t value) { miSetPayloadType(P_UINT16); miSetLength(2); @@ -314,7 +314,7 @@ MyMessage& MyMessage::set(uint16_t value) return *this; } -MyMessage& MyMessage::set(int16_t value) +MyMessage& MyMessage::set(const int16_t value) { miSetPayloadType(P_INT16); miSetLength(2); diff --git a/core/MyMessage.h b/core/MyMessage.h index bdd465420..312cbd8e0 100644 --- a/core/MyMessage.h +++ b/core/MyMessage.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -43,12 +43,12 @@ /// @brief The command field (message-type) defines the overall properties of a message typedef enum { - C_PRESENTATION = 0, //!< Sent by a node when they present attached sensors. This is usually done in presentation() at startup. - C_SET = 1, //!< This message is sent from or to a sensor when a sensor value should be updated. - C_REQ = 2, //!< Requests a variable value (usually from an actuator destined for controller). - C_INTERNAL = 3, //!< Internal MySensors messages (also include common messages provided/generated by the library). - C_STREAM = 4 //!< For firmware and other larger chunks of data that need to be divided into pieces. -} mysensor_command; + C_PRESENTATION = 0, //!< Sent by a node when they present attached sensors. This is usually done in presentation() at startup. + C_SET = 1, //!< This message is sent from or to a sensor when a sensor value should be updated. + C_REQ = 2, //!< Requests a variable value (usually from an actuator destined for controller). + C_INTERNAL = 3, //!< Internal MySensors messages (also include common messages provided/generated by the library). + C_STREAM = 4 //!< For firmware and other larger chunks of data that need to be divided into pieces. +} mysensors_command_t; #if !DOXYGEN // Hide until we migrate /// @brief Type of sensor (used when presenting sensors) @@ -94,7 +94,7 @@ typedef enum { S_GAS = 37, //!< Gas meter, V_FLOW, V_VOLUME S_GPS = 38, //!< GPS Sensor, V_POSITION S_WATER_QUALITY = 39 //!< V_TEMP, V_PH, V_ORP, V_EC, V_STATUS -} mysensor_sensor; +} mysensors_sensor_t; /// @brief Type of sensor data (for set/req/ack messages) typedef enum { @@ -158,7 +158,7 @@ typedef enum { V_VAR = 54, //!< S_POWER, Reactive power: volt-ampere reactive (var) V_VA = 55, //!< S_POWER, Apparent power: volt-ampere (VA) V_POWER_FACTOR = 56, //!< S_POWER, Ratio of real power to apparent power: floating point value in the range [-1,..,1] -} mysensor_data; +} mysensors_data_t; #endif @@ -198,7 +198,7 @@ typedef enum { I_SIGNAL_REPORT_RESPONSE = 31, //!< Device signal strength response (RSSI) I_PRE_SLEEP_NOTIFICATION = 32, //!< Message sent before node is going to sleep I_POST_SLEEP_NOTIFICATION = 33 //!< Message sent after node woke up (if enabled) -} mysensor_internal; +} mysensors_internal_t; /// @brief Type of data stream (for streamed message) @@ -211,7 +211,7 @@ typedef enum { ST_IMAGE = 5, //!< Image ST_FIRMWARE_CONFIRM = 6, //!< Mark running firmware as valid (MyOTAFirmwareUpdateNVM + mcuboot) ST_FIRMWARE_RESPONSE_RLE = 7, //!< Response FW block with run length encoded data -} mysensor_stream; +} mysensors_stream_t; /// @brief Type of payload typedef enum { @@ -223,7 +223,7 @@ typedef enum { P_ULONG32 = 5, //!< Payload type is UINT32 P_CUSTOM = 6, //!< Payload type is binary P_FLOAT32 = 7 //!< Payload type is float32 -} mysensor_payload; +} mysensors_payload_t; @@ -292,26 +292,26 @@ class MyMessage /** * Default constructor */ - MyMessage(); + MyMessage(void); /** * Constructor * @param sensor id of the child sensor for this message * @param type see http://korturl.nu/stupidurl */ - MyMessage(uint8_t sensor, uint8_t type); + MyMessage(const uint8_t sensor, const uint8_t type); /** * Single character hex (0 - 15) conversion * @param i byte (only lower 4 bits will be considered) * @return single char with the hex representation (0 to F) of the parameter */ - char i2h(uint8_t i) const; + char i2h(const uint8_t i) const; /** * @brief Clear message contents. */ - void clear(); + void clear(void); /** * If payload is something else than P_STRING you can have the payload value converted @@ -330,90 +330,92 @@ class MyMessage * @brief Get payload as string * @return pointer to a char array storing the string */ - const char* getString() const; + const char* getString(void) const; /** * @brief Get custom payload * @return pointer to the raw payload */ - void* getCustom() const; + void* getCustom(void) const; /** * @brief Get bool payload * @return a bool with the value of the payload (true/false) */ - bool getBool() const; + bool getBool(void) const; /** * @brief Get unsigned 8-bit integer payload * @return the value of the payload, 0 to 255 */ - uint8_t getByte() const; + uint8_t getByte(void) const; /** * @brief Get float payload * @return the floating-point value of the payload */ - float getFloat() const; + float getFloat(void) const; /** * @brief Get signed 16-bit integer payload * @return the value of the payload, –32768 to 32767 */ - int16_t getInt() const; + int16_t getInt(void) const; /** * @brief Get unsigned 16-bit integer payload * @return the value of the payload, 0 to 65535 */ - uint16_t getUInt() const; + uint16_t getUInt(void) const; /** * @brief Get signed 32-bit integer payload * @return the value of the payload, –2147483648 to 2147483647 */ - int32_t getLong() const; + int32_t getLong(void) const; /** * @brief Get unsigned 32-bit integer payload * @return the value of the payload, 0 to 4294967295 */ - uint32_t getULong() const; + uint32_t getULong(void) const; /** * @brief Getter for command type - * @return #mysensor_command + * @return #mysensors_command_t */ - uint8_t getCommand() const; + uint8_t getCommand(void) const; /** * @brief Getter for ack-flag. * @return true if this is an ack message */ - bool isAck() const; + bool isAck(void) const; /** * @brief Set message type * @param type see http://korturl.nu/stupidurl */ - MyMessage& setType(uint8_t type); + MyMessage& setType(const uint8_t type); /** * @brief Set which child sensor this message belongs to + * @param sensor */ - MyMessage& setSensor(uint8_t sensor); + MyMessage& setSensor(const uint8_t sensor); /** * @brief Set final destination node id for this message + * @param destination */ - MyMessage& setDestination(uint8_t destination); + MyMessage& setDestination(const uint8_t destination); /** * @brief Set entire payload * @param payload pointer to the buffer where the payload is stored * @param length of the payload */ - MyMessage& set(void* payload, uint8_t length); + MyMessage& set(const void* payload, const uint8_t length); /** * @brief Set payload to character array @@ -433,43 +435,43 @@ class MyMessage * @param value float * @param decimals number of decimals to include */ - MyMessage& set(float value, uint8_t decimals); + MyMessage& set(const float value, const uint8_t decimals); /** * @brief Set payload to bool value * @param value true or false */ - MyMessage& set(bool value); + MyMessage& set(const bool value); /** * @brief Set payload to unsigned 8-bit integer value * @param value (0 to 255) */ - MyMessage& set(uint8_t value); + MyMessage& set(const uint8_t value); /** * @brief Set payload to unsigned 32-bit integer value * @param value (0 to 4294967295) */ - MyMessage& set(uint32_t value); + MyMessage& set(const uint32_t value); /** * @brief Set payload to signed 32-bit integer value * @param value (–2147483648 to 2147483647) */ - MyMessage& set(int32_t value); + MyMessage& set(const int32_t value); /** * @brief Set payload to unsigned 16-bit integer value * @param value (0 to 65535) */ - MyMessage& set(uint16_t value); + MyMessage& set(const uint16_t value); /** * @brief Set payload to signed 16-bit integer value * @param value (–32768 to 32767) */ - MyMessage& set(int16_t value); + MyMessage& set(const int16_t value); #else diff --git a/core/MyOTAFirmwareUpdate.cpp b/core/MyOTAFirmwareUpdate.cpp index 35e3ce7cd..25bdbd75a 100644 --- a/core/MyOTAFirmwareUpdate.cpp +++ b/core/MyOTAFirmwareUpdate.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyOTAFirmwareUpdate.h b/core/MyOTAFirmwareUpdate.h index 321ffd340..9295766c9 100644 --- a/core/MyOTAFirmwareUpdate.h +++ b/core/MyOTAFirmwareUpdate.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyOTALogging.cpp b/core/MyOTALogging.cpp index 693290f83..7e027543d 100644 --- a/core/MyOTALogging.cpp +++ b/core/MyOTALogging.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyOTALogging.h b/core/MyOTALogging.h index d2d1035fb..168628908 100644 --- a/core/MyOTALogging.h +++ b/core/MyOTALogging.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyPrivateConfig.h.sample b/core/MyPrivateConfig.h.sample index 8311d39f9..3d77bd6de 100644 --- a/core/MyPrivateConfig.h.sample +++ b/core/MyPrivateConfig.h.sample @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -44,7 +44,7 @@ //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}} /********************************** -* NRF24L01 Driver Defaults +* nRF24L01 Driver Defaults ***********************************/ // Enables RF24 encryption (all nodes and gateway must have this enabled) //#define MY_RF24_ENABLE_ENCRYPTION diff --git a/core/MyProtocol.h b/core/MyProtocol.h index e453260d1..cf127cb88 100644 --- a/core/MyProtocol.h +++ b/core/MyProtocol.h @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyProtocolMySensors.cpp b/core/MyProtocolMySensors.cpp index def4b971c..c874504bd 100755 --- a/core/MyProtocolMySensors.cpp +++ b/core/MyProtocolMySensors.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index eb1f1aba9..fba4bc21e 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MySensorsCore.h b/core/MySensorsCore.h index 721cbdeab..8a56da074 100644 --- a/core/MySensorsCore.h +++ b/core/MySensorsCore.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -38,7 +38,7 @@ * MySensorsCore debug log messages: * * |E| SYS | SUB | Message | Comment -* |-|-----|-----|---------------------------------------------|---------------------------------------------------------------------------- +* |-|-----|-----|---------------------------------------------|-------------------------------------------------------------------------------------------------- * |!| MCO | BGN | HW ERR | Error HW initialization (e.g. ext. EEPROM) * | | MCO | BGN | INIT %%s,CP=%%s,VER=%%s | Core initialization, capabilities (CP), library version (VER) * | | MCO | BGN | BFR | Callback before() @@ -461,7 +461,6 @@ static inline MyMessage& buildGw(MyMessage &msg, const uint8_t type) return msg; } - #endif /** @}*/ diff --git a/core/MySigning.cpp b/core/MySigning.cpp index f74b3e951..75da2f674 100644 --- a/core/MySigning.cpp +++ b/core/MySigning.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MySigning.h b/core/MySigning.h index 0f64b3081..e305b0ec3 100644 --- a/core/MySigning.h +++ b/core/MySigning.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MySigningAtsha204.cpp b/core/MySigningAtsha204.cpp index d6ab75ec1..73fd36e5e 100644 --- a/core/MySigningAtsha204.cpp +++ b/core/MySigningAtsha204.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MySigningAtsha204Soft.cpp b/core/MySigningAtsha204Soft.cpp index 880aa73f3..2bc5ea440 100644 --- a/core/MySigningAtsha204Soft.cpp +++ b/core/MySigningAtsha204Soft.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MySplashScreen.cpp b/core/MySplashScreen.cpp index 9c5f7fb27..977713879 100644 --- a/core/MySplashScreen.cpp +++ b/core/MySplashScreen.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2017 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MySplashScreen.h b/core/MySplashScreen.h index cc29dc3c3..4e42e9199 100644 --- a/core/MySplashScreen.h +++ b/core/MySplashScreen.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2017 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index ed7e114dc..9d22bae3c 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -67,7 +67,7 @@ static uint32_t _lastSanityCheck; //!< last sanity check // regular network discovery, sends I_DISCOVER_REQUESTS to update routing table // sufficient to have GW triggering requests to also update repeater nodes #if defined(MY_GATEWAY_FEATURE) -static uint32_t _lastNetworkDiscovery; //! last network discovery +static uint32_t _lastNetworkDiscovery; //!< last network discovery #endif // stInit: initialise transport HW @@ -77,13 +77,13 @@ void stInitTransition(void) // initialise status variables _transportSM.pingActive = false; _transportSM.transportActive = false; - _transportSM.lastUplinkCheck = 0ul; + _transportSM.lastUplinkCheck = 0; #if defined(MY_TRANSPORT_SANITY_CHECK) _lastSanityCheck = hwMillis(); #endif #if defined(MY_GATEWAY_FEATURE) - _lastNetworkDiscovery = 0ul; + _lastNetworkDiscovery = 0; #endif #if defined(MY_RAM_ROUTING_TABLE_ENABLED) _lastRoutingTableSave = hwMillis(); @@ -675,7 +675,7 @@ void transportProcessMessage(void) // Reject payloads with incorrect length if (payloadLength != expectedMessageLength) { setIndication(INDICATION_ERR_LENGTH); - TRANSPORT_DEBUG(PSTR("!TSF:MSG:LEN,%" PRIu8 "!=%" PRIu8 "\n"), payloadLength, + TRANSPORT_DEBUG(PSTR("!TSF:MSG:LEN=%" PRIu8 ",EXP=%" PRIu8 "\n"), payloadLength, expectedMessageLength); // invalid payload length return; } diff --git a/core/MyTransport.h b/core/MyTransport.h index 30af141fa..08fd0e422 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -105,7 +105,7 @@ * | | TSF | MSG | FWD BC MSG | Controlled broadcast message forwarding * | | TSF | MSG | REL MSG | Relay message * | | TSF | MSG | REL PxNG,HP=%%d | Relay PING/PONG message, increment hop counter (HP) -* |!| TSF | MSG | LEN,%%d!=%%d | Invalid message length, (actual!=expected) +* |!| TSF | MSG | LEN=%%d,EXP=%%d | Invalid message length (LEN), exptected length (EXP) * |!| TSF | MSG | PVER,%%d!=%%d | Message protocol version mismatch (actual!=expected) * |!| TSF | MSG | SIGN VERIFY FAIL | Signing verification failed * |!| TSF | MSG | REL MSG,NORP | Node received a message for relaying, but node is not a repeater, message skipped @@ -209,21 +209,6 @@ #define isValidDistance(_distance) (bool)(_distance!=DISTANCE_INVALID) //!< returns true if distance is valid #define isValidParent(_parent) (bool)(_parent != AUTO) //!< returns true if parent is valid -// RX queue ==> shift to HAL -#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) -#if defined(MY_RADIO_RFM69) -#error Receive message buffering not supported for RFM69! -#endif -#if defined(MY_RS485) -#error Receive message buffering not supported for RS485! -#endif -#if defined(MY_RADIO_NRF5_ESB) -#error Receive message buffering not supported for NRF5 radio! Please define MY_NRF5_RX_BUFFER_SIZE -#endif -#elif !defined(MY_RX_MESSAGE_BUFFER_FEATURE) && defined(MY_RX_MESSAGE_BUFFER_SIZE) -#error Receive message buffering requires message buffering feature enabled! -#endif - /** * @brief Callback type */ @@ -249,10 +234,10 @@ typedef struct { */ typedef struct { void(*Transition)(void); //!< state transition function - void(*Update)(void); //!< state update function + void(*Update)(void); //!< state update function } transportState_t; /** -* @brief +* @brief Datatype for internal RSSI storage */ typedef int16_t transportRSSI_t; //!< Datatype for internal RSSI storage diff --git a/core/Version.h b/core/Version.h index 323ddf895..f279c7ab0 100644 --- a/core/Version.h +++ b/core/Version.h @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -49,8 +49,8 @@ #define MYSENSORS_LIBRARY_VERSION_MAJOR 2 //!< Major release version #define MYSENSORS_LIBRARY_VERSION_MINOR 3 //!< Minor release version #define MYSENSORS_LIBRARY_VERSION_PATCH 1 //!< Patch version -#define MYSENSORS_LIBRARY_VERSION_PRERELEASE "alpha" //!< Pre-release suffix, i.e. alpha, beta, rc.1, etc -#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0x00 //!< incremental counter, starting at 0x00. 0xFF for final release +#define MYSENSORS_LIBRARY_VERSION_PRERELEASE "beta" //!< Pre-release suffix, i.e. alpha, beta, rc.1, etc +#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0x01 //!< incremental counter, starting at 0x00. 0xFF for final release #if (MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER != 0xFF) diff --git a/drivers/BCM/BCM.cpp b/drivers/BCM/BCM.cpp index cb9acd944..3f09c9934 100644 --- a/drivers/BCM/BCM.cpp +++ b/drivers/BCM/BCM.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/BCM/BCM.h b/drivers/BCM/BCM.h index c59196848..c40e17cd6 100644 --- a/drivers/BCM/BCM.h +++ b/drivers/BCM/BCM.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/BCM/RPi.cpp b/drivers/BCM/RPi.cpp index 10449e9b3..4d47082fc 100644 --- a/drivers/BCM/RPi.cpp +++ b/drivers/BCM/RPi.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/BCM/RPi.h b/drivers/BCM/RPi.h index 0a8eea0d2..fb84b328a 100644 --- a/drivers/BCM/RPi.h +++ b/drivers/BCM/RPi.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/BCM/SPIBCM.cpp b/drivers/BCM/SPIBCM.cpp index cc0180c81..6a29783c5 100644 --- a/drivers/BCM/SPIBCM.cpp +++ b/drivers/BCM/SPIBCM.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/BCM/SPIBCM.h b/drivers/BCM/SPIBCM.h index 1d353ada2..0d95f23b3 100644 --- a/drivers/BCM/SPIBCM.h +++ b/drivers/BCM/SPIBCM.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/Arduino.h b/drivers/Linux/Arduino.h index eb9ee3848..8656379cf 100644 --- a/drivers/Linux/Arduino.h +++ b/drivers/Linux/Arduino.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/EthernetClient.cpp b/drivers/Linux/EthernetClient.cpp index 446e7177f..831284196 100644 --- a/drivers/Linux/EthernetClient.cpp +++ b/drivers/Linux/EthernetClient.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/EthernetClient.h b/drivers/Linux/EthernetClient.h index 710f8ddf3..1f65609bd 100644 --- a/drivers/Linux/EthernetClient.h +++ b/drivers/Linux/EthernetClient.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/EthernetServer.cpp b/drivers/Linux/EthernetServer.cpp index 58d0b5c0a..8a4a16150 100644 --- a/drivers/Linux/EthernetServer.cpp +++ b/drivers/Linux/EthernetServer.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/EthernetServer.h b/drivers/Linux/EthernetServer.h index 8e5c240a6..4c98817d0 100644 --- a/drivers/Linux/EthernetServer.h +++ b/drivers/Linux/EthernetServer.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/GPIO.cpp b/drivers/Linux/GPIO.cpp index c8e44c7dd..84e9f4547 100644 --- a/drivers/Linux/GPIO.cpp +++ b/drivers/Linux/GPIO.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/GPIO.h b/drivers/Linux/GPIO.h index 1a962d1ab..3fc238ec1 100644 --- a/drivers/Linux/GPIO.h +++ b/drivers/Linux/GPIO.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/SPI.h b/drivers/Linux/SPI.h index 8efbcc347..b7d373296 100644 --- a/drivers/Linux/SPI.h +++ b/drivers/Linux/SPI.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/SPIDEV.cpp b/drivers/Linux/SPIDEV.cpp index 5e773036a..0c65e24fa 100644 --- a/drivers/Linux/SPIDEV.cpp +++ b/drivers/Linux/SPIDEV.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/SPIDEV.h b/drivers/Linux/SPIDEV.h index ba45dea10..adc69a9fc 100644 --- a/drivers/Linux/SPIDEV.h +++ b/drivers/Linux/SPIDEV.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/SerialPort.cpp b/drivers/Linux/SerialPort.cpp index 71af94616..0f96eb848 100644 --- a/drivers/Linux/SerialPort.cpp +++ b/drivers/Linux/SerialPort.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/SerialPort.h b/drivers/Linux/SerialPort.h index edd301672..a6e9cef95 100644 --- a/drivers/Linux/SerialPort.h +++ b/drivers/Linux/SerialPort.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/SoftEeprom.cpp b/drivers/Linux/SoftEeprom.cpp index f7980c295..f8e3241ef 100644 --- a/drivers/Linux/SoftEeprom.cpp +++ b/drivers/Linux/SoftEeprom.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/SoftEeprom.h b/drivers/Linux/SoftEeprom.h index 806bb0a74..6630255d9 100644 --- a/drivers/Linux/SoftEeprom.h +++ b/drivers/Linux/SoftEeprom.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/StdInOutStream.cpp b/drivers/Linux/StdInOutStream.cpp index d9867d15a..0a8c7a875 100644 --- a/drivers/Linux/StdInOutStream.cpp +++ b/drivers/Linux/StdInOutStream.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/StdInOutStream.h b/drivers/Linux/StdInOutStream.h index 2f0356ee8..f991181c9 100644 --- a/drivers/Linux/StdInOutStream.h +++ b/drivers/Linux/StdInOutStream.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/compatibility.cpp b/drivers/Linux/compatibility.cpp index bfd3545c5..d15acec23 100644 --- a/drivers/Linux/compatibility.cpp +++ b/drivers/Linux/compatibility.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/config.c b/drivers/Linux/config.c index 79252edfc..6e50205ca 100644 --- a/drivers/Linux/config.c +++ b/drivers/Linux/config.c @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/config.h b/drivers/Linux/config.h index 988cfbae4..027993a22 100644 --- a/drivers/Linux/config.h +++ b/drivers/Linux/config.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/interrupt.cpp b/drivers/Linux/interrupt.cpp index e85f24267..395c2175c 100644 --- a/drivers/Linux/interrupt.cpp +++ b/drivers/Linux/interrupt.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/interrupt.h b/drivers/Linux/interrupt.h index 4e5c3fd9c..13050e4c9 100644 --- a/drivers/Linux/interrupt.h +++ b/drivers/Linux/interrupt.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/log.c b/drivers/Linux/log.c index a88bb2df0..6834ccad7 100644 --- a/drivers/Linux/log.c +++ b/drivers/Linux/log.c @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/Linux/log.h b/drivers/Linux/log.h index 0cecfc42c..9498b14cf 100644 --- a/drivers/Linux/log.h +++ b/drivers/Linux/log.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/NRF5/Radio.h b/drivers/NRF5/Radio.h index 3bd69f10d..c91b9fd05 100644 --- a/drivers/NRF5/Radio.h +++ b/drivers/NRF5/Radio.h @@ -1,5 +1,5 @@  -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -10,7 +10,7 @@ * Created by Frank Holtz * Copyright (C) 2017 Frank Holtz * Full contributor list: - * https://github.com/mysensors/Arduino/graphs/contributors + * https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/NRF5/Radio_ESB.cpp b/drivers/NRF5/Radio_ESB.cpp index 3b0a929eb..f927a815b 100644 --- a/drivers/NRF5/Radio_ESB.cpp +++ b/drivers/NRF5/Radio_ESB.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors formrs a self healing radio network with optional repeaters. Each @@ -9,7 +9,7 @@ * Created by Frank Holtz * Copyright (C) 2017 Frank Holtz * Full contributor list: - * https://github.com/mysensors/Arduino/graphs/contributors + * https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -142,7 +142,7 @@ static bool NRF5_ESB_initialize() // Enable listening on Node and BC address NRF_RADIO->RXADDRESSES = (1 << NRF5_ESB_NODE_ADDR) | (1 << NRF5_ESB_BC_ADDR); - // Packet configuration for NRF24 compatibility + // Packet configuration for nRF24 compatibility NRF_RADIO->PCNF0 = (6 << RADIO_PCNF0_LFLEN_Pos) | // 6 Bits length field (0 << RADIO_PCNF0_S0LEN_Pos) | // No S0 #ifdef RADIO_PCNF0_S1INCL_Pos @@ -159,7 +159,7 @@ static bool NRF5_ESB_initialize() (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos); // Disable whitening // HINT: Fast ramp up can enabled here. Needs more code on other lines - // Fast ramp up isn't supported by NRF24 and NRF51 series. + // Fast ramp up isn't supported by nRF24 and NRF51 series. // Set bitcounter to trigger interrupt after ACK bit NRF_RADIO->BCC = NRF5_ESB_BITCOUNTER; @@ -571,7 +571,7 @@ extern "C" { // In RX mode -> prepare ACK or RX if (NRF_RADIO->STATE == RADIO_STATE_STATE_Rx) { - // Send ACK only for node address, don't care about the ACK bit to handle bad NRF24 clones + // Send ACK only for node address, don't care about the ACK bit to handle bad nRF24 clones if (NRF_RADIO->RXMATCH == NRF5_ESB_NODE_ADDR) { // Send ACK after END, an empty packet is provided in READY event NRF_RADIO->SHORTS = NRF5_ESB_SHORTS_RX_TX; diff --git a/drivers/NRF5/Radio_ESB.h b/drivers/NRF5/Radio_ESB.h index 6e716d400..8380eb2c6 100644 --- a/drivers/NRF5/Radio_ESB.h +++ b/drivers/NRF5/Radio_ESB.h @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -9,7 +9,7 @@ * Created by Frank Holtz * Copyright (C) 2017 Frank Holtz * Full contributor list: - * https://github.com/mysensors/Arduino/graphs/contributors + * https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -38,7 +38,7 @@ /** Wait for start of an ACK packet in us * Calculation: ramp up time + packet header (57 Bit): round to 9 Byte * If you don't receive ACK packages, you have to increase this value. - * My measured (Aurduino Uno+NRF24L01P) minimal timeouts: + * My measured (Arduino Uno + nRF24L01P) minimal timeouts: * 250kbit 411us -> 182 us to ACK start * 1MBit 205us -> 147 us * 2MBit 173us -> 143 us diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index 29d04f9c4..b87168a40 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/RF24/RF24.h b/drivers/RF24/RF24.h index 56f6ce57a..763a6ff79 100644 --- a/drivers/RF24/RF24.h +++ b/drivers/RF24/RF24.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -19,7 +19,7 @@ * Based on maniacbug's RF24 library, copyright (C) 2011 J. Coliz * RF24 driver refactored and optimized for speed and size, copyright (C) 2017 Olivier Mauti * -* Definitions for Nordic NRF24L01+ radios: +* Definitions for Nordic nRF24L01+ radios: * https://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P * */ diff --git a/drivers/RF24/RF24registers.h b/drivers/RF24/RF24registers.h index 83b2298c6..fa13235c4 100644 --- a/drivers/RF24/RF24registers.h +++ b/drivers/RF24/RF24registers.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/RFM69/new/RFM69_new.cpp b/drivers/RFM69/new/RFM69_new.cpp index c1a065a1b..26641b7f2 100644 --- a/drivers/RFM69/new/RFM69_new.cpp +++ b/drivers/RFM69/new/RFM69_new.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/RFM69/new/RFM69_new.h b/drivers/RFM69/new/RFM69_new.h index 45974228b..fee55b826 100644 --- a/drivers/RFM69/new/RFM69_new.h +++ b/drivers/RFM69/new/RFM69_new.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -176,7 +176,7 @@ extern HardwareSPI SPI; //!< SPI // available frequency bands, non trivial values to avoid misconfiguration #define RFM69_315MHZ (315000000ul) //!< RFM69_315MHZ -#define RFM69_433MHZ (433920000ul) //!< RFM69_433MHZ, center frequencz 433.92 MHz +#define RFM69_433MHZ (433920000ul) //!< RFM69_433MHZ, center frequency 433.92 MHz #define RFM69_865MHZ (865500000ul) //!< RFM69_865MHZ, center frequency 865.5 MHz #define RFM69_868MHZ (868000000ul) //!< RFM69_868MHZ #define RFM69_915MHZ (915000000ul) //!< RFM69_915MHZ diff --git a/drivers/RFM69/new/RFM69registers_new.h b/drivers/RFM69/new/RFM69registers_new.h index 2c2dade75..bd1a349fc 100644 --- a/drivers/RFM69/new/RFM69registers_new.h +++ b/drivers/RFM69/new/RFM69registers_new.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/RFM95/RFM95.cpp b/drivers/RFM95/RFM95.cpp index a8e7deee6..de3d325b4 100644 --- a/drivers/RFM95/RFM95.cpp +++ b/drivers/RFM95/RFM95.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/RFM95/RFM95.h b/drivers/RFM95/RFM95.h index 4db4a5a57..fb9164aef 100644 --- a/drivers/RFM95/RFM95.h +++ b/drivers/RFM95/RFM95.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/drivers/RFM95/RFM95registers.h b/drivers/RFM95/RFM95registers.h index 33d256285..dafd7e53c 100644 --- a/drivers/RFM95/RFM95registers.h +++ b/drivers/RFM95/RFM95registers.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/examples/AirQualitySensor/AirQualitySensor.ino b/examples/AirQualitySensor/AirQualitySensor.ino index ca3a59d90..3fa4bf5c1 100644 --- a/examples/AirQualitySensor/AirQualitySensor.ino +++ b/examples/AirQualitySensor/AirQualitySensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -38,7 +38,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino b/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino index 1b5826993..7c5b6d318 100644 --- a/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino +++ b/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -32,7 +32,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino b/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino index c02262a86..73f545172 100644 --- a/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino +++ b/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -34,7 +34,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/CO2Sensor/CO2Sensor.ino b/examples/CO2Sensor/CO2Sensor.ino index f19940a32..5f088fa27 100644 --- a/examples/CO2Sensor/CO2Sensor.ino +++ b/examples/CO2Sensor/CO2Sensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -42,7 +42,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/ClearEepromConfig/ClearEepromConfig.ino b/examples/ClearEepromConfig/ClearEepromConfig.ino index e61313633..302991164 100644 --- a/examples/ClearEepromConfig/ClearEepromConfig.ino +++ b/examples/ClearEepromConfig/ClearEepromConfig.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/examples/DimmableLEDActuator/DimmableLEDActuator.ino b/examples/DimmableLEDActuator/DimmableLEDActuator.ino index 167be9da2..411cc3b9d 100644 --- a/examples/DimmableLEDActuator/DimmableLEDActuator.ino +++ b/examples/DimmableLEDActuator/DimmableLEDActuator.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -39,7 +39,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/DimmableLight/DimmableLight.ino b/examples/DimmableLight/DimmableLight.ino index c67b6a9bb..8fde150ea 100644 --- a/examples/DimmableLight/DimmableLight.ino +++ b/examples/DimmableLight/DimmableLight.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -33,7 +33,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/DustSensor/DustSensor.ino b/examples/DustSensor/DustSensor.ino index eb250ac42..9452768ef 100644 --- a/examples/DustSensor/DustSensor.ino +++ b/examples/DustSensor/DustSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -42,7 +42,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/DustSensorDSM/DustSensorDSM.ino b/examples/DustSensorDSM/DustSensorDSM.ino index 418c7ae28..337346572 100644 --- a/examples/DustSensorDSM/DustSensorDSM.ino +++ b/examples/DustSensorDSM/DustSensorDSM.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -34,7 +34,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino b/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino index 94862608e..d2a08cfe4 100644 --- a/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino +++ b/examples/EnergyMeterPulseSensor/EnergyMeterPulseSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -38,7 +38,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/GatewayESP32/GatewayESP32.ino b/examples/GatewayESP32/GatewayESP32.ino index c2d1f9954..dfc4f00bf 100644 --- a/examples/GatewayESP32/GatewayESP32.ino +++ b/examples/GatewayESP32/GatewayESP32.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino b/examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino index 9783ddd2d..a448e1abf 100644 --- a/examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino +++ b/examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/examples/GatewayESP8266/GatewayESP8266.ino b/examples/GatewayESP8266/GatewayESP8266.ino index 32bbf332f..30c200861 100644 --- a/examples/GatewayESP8266/GatewayESP8266.ino +++ b/examples/GatewayESP8266/GatewayESP8266.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -58,7 +58,7 @@ #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino b/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino index f517cb5a1..a036c2106 100644 --- a/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino +++ b/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -51,7 +51,7 @@ #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino b/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino index f83fe52e7..5d46594d5 100644 --- a/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino +++ b/examples/GatewayESP8266OTA/GatewayESP8266OTA.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -59,7 +59,7 @@ #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino b/examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino index c9b572840..5bfd2cc27 100644 --- a/examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino +++ b/examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -37,7 +37,7 @@ #define MY_DEBUG // Enables and select radio type (if attached) -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 @@ -122,16 +122,16 @@ void setup() { - // Setup locally attached sensors + // Setup locally attached sensors } void presentation() { - // Present locally attached sensors here + // Present locally attached sensors here } void loop() { - // Send locally attached sensors data here + // Send locally attached sensors data here } diff --git a/examples/GatewaySerial/GatewaySerial.ino b/examples/GatewaySerial/GatewaySerial.ino index 3913bc2bb..c2c8bb435 100644 --- a/examples/GatewaySerial/GatewaySerial.ino +++ b/examples/GatewaySerial/GatewaySerial.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2015 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -41,7 +41,7 @@ // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/GatewaySerialRS485/GatewaySerialRS485.ino b/examples/GatewaySerialRS485/GatewaySerialRS485.ino index 36750ebbc..381fe2ab2 100644 --- a/examples/GatewaySerialRS485/GatewaySerialRS485.ino +++ b/examples/GatewaySerialRS485/GatewaySerialRS485.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2015 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/examples/GatewayW5100/GatewayW5100.ino b/examples/GatewayW5100/GatewayW5100.ino index 6d7a488c4..ded710db4 100644 --- a/examples/GatewayW5100/GatewayW5100.ino +++ b/examples/GatewayW5100/GatewayW5100.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -45,7 +45,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino b/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino index 3f1cad082..8a179bcfb 100644 --- a/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino +++ b/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -62,7 +62,7 @@ #define MY_DEBUG // Enables and select radio type (if attached) -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/LightSensor/LightSensor.ino b/examples/LightSensor/LightSensor.ino index 3716ffd36..377a79c83 100644 --- a/examples/LightSensor/LightSensor.ino +++ b/examples/LightSensor/LightSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -30,7 +30,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/LogOTAGateway/LogOTAGateway.ino b/examples/LogOTAGateway/LogOTAGateway.ino index c1e62d75b..c8f51f5de 100644 --- a/examples/LogOTAGateway/LogOTAGateway.ino +++ b/examples/LogOTAGateway/LogOTAGateway.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2015 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -47,7 +47,7 @@ #define MY_OTA_LOG_RECEIVER_FEATURE // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/LogOTANode/LogOTANode.ino b/examples/LogOTANode/LogOTANode.ino index aaf1384d2..96a3209b6 100644 --- a/examples/LogOTANode/LogOTANode.ino +++ b/examples/LogOTANode/LogOTANode.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -37,7 +37,7 @@ //#define MY_DEBUG_OTA_DISABLE_ACK // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/MockMySensors/MockMySensors.ino b/examples/MockMySensors/MockMySensors.ino index 1eeeafa9d..3498cd2c6 100644 --- a/examples/MockMySensors/MockMySensors.ino +++ b/examples/MockMySensors/MockMySensors.ino @@ -1,16 +1,36 @@ /* -* MockMySensors -* -* This skecth is intended to crate fake sensors which register and respond to the controller -* *** -* Barduino 2015, GizMoCuz 2015 -*/ + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Henrik Ekblad + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + ******************************* + * + * REVISION HISTORY + * Version 1.0 - Barduino 2015, GizMoCuz 2015 + * + * DESCRIPTION + * This sketch is intended to create fake sensors which register and respond to the controller + * + */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/MotionSensor/MotionSensor.ino b/examples/MotionSensor/MotionSensor.ino index bc1133a15..b4ee0a05f 100644 --- a/examples/MotionSensor/MotionSensor.ino +++ b/examples/MotionSensor/MotionSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -31,7 +31,7 @@ // #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/MotionSensorRS485/MotionSensorRS485.ino b/examples/MotionSensorRS485/MotionSensorRS485.ino index a1713fa59..4e9790d62 100644 --- a/examples/MotionSensorRS485/MotionSensorRS485.ino +++ b/examples/MotionSensorRS485/MotionSensorRS485.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/examples/Node2Node/Node2Node.ino b/examples/Node2Node/Node2Node.ino index 0033e6152..173816488 100644 --- a/examples/Node2Node/Node2Node.ino +++ b/examples/Node2Node/Node2Node.ino @@ -1,23 +1,31 @@ /* - The MySensors Arduino library handles the wireless radio link and protocol - between your home built sensors/actuators and HA controller of choice. - The sensors forms a self healing radio network with optional repeaters. Each - repeater and gateway builds a routing tables in EEPROM which keeps track of the - network topology allowing messages to be routed to nodes. - - Created by Henrik Ekblad - Copyright (C) 2013-2018 Sensnology AB - Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors - - Documentation: http://www.mysensors.org - Support Forum: http://forum.mysensors.org - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as published by the Free Software Foundation. - -*/ - + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Henrik Ekblad + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + ******************************* + * + * REVISION HISTORY + * Version 1.0 - tekka 2018 + * + * DESCRIPTION + * Node to node communication example, destination node id = ACTUATOR_ID + * Use SIGNING_ENABLED to enable soft/hard signing + * + */ #define MY_DEBUG #define MY_RADIO_RF24 #define CHILD_SENSOR_ID 0 diff --git a/examples/PHSensor/PHSensor.ino b/examples/PHSensor/PHSensor.ino index 1a9cb30bc..21b02d1ff 100644 --- a/examples/PHSensor/PHSensor.ino +++ b/examples/PHSensor/PHSensor.ino @@ -1,32 +1,35 @@ -/** - The MySensors Arduino library handles the wireless radio link and protocol - between your home built sensors/actuators and HA controller of choice. - The sensors forms a self healing radio network with optional repeaters. Each - repeater and gateway builds a routing tables in EEPROM which keeps track of the - network topology allowing messages to be routed to nodes. - - Created by mboyer85 - Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors - - Documentation: http://www.mysensors.org - Support Forum: http://forum.mysensors.org - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as published by the Free Software Foundation. - +/* + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Henrik Ekblad + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * ******************************* - - DESCRIPTION - - Example sketch showing how to send PH readings back to the controller -*/ + * + * REVISION HISTORY + * Version 1.0 - mboyer85 + * + * DESCRIPTION + * Example sketch showing how to send PH readings back to the controller + */ // Enable debug prints to serial monitor //#define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/PassiveNode/PassiveNode.ino b/examples/PassiveNode/PassiveNode.ino index 7ff1ca769..8910902c7 100644 --- a/examples/PassiveNode/PassiveNode.ino +++ b/examples/PassiveNode/PassiveNode.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -36,7 +36,7 @@ #define MY_NODE_ID 100 // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/PingPongSensor/MYSLog.h b/examples/PingPongSensor/MYSLog.h index dbf7e8fe3..e90f3e556 100644 --- a/examples/PingPongSensor/MYSLog.h +++ b/examples/PingPongSensor/MYSLog.h @@ -1,4 +1,23 @@ -/**** +/* + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Henrik Ekblad + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + ******************************* + * * Formatted logging to the Serial console. * Compiled in by setting LOGDEBUG * diff --git a/examples/PingPongSensor/PingPongSensor.ino b/examples/PingPongSensor/PingPongSensor.ino index 0fd8461da..d29f755a8 100644 --- a/examples/PingPongSensor/PingPongSensor.ino +++ b/examples/PingPongSensor/PingPongSensor.ino @@ -1,4 +1,23 @@ -/*** +/* + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Henrik Ekblad + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + ******************************* + * * This is a simple sketch used to demonstrate and test node-to-node MySensors communication. * To use this sketch, assemble MySensors nodes - they need nothing more than a radio * 1. Flash each node with the same sketch, open the console and type either 0 or 1 to the respective nodes to set their ID @@ -12,7 +31,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 @@ -70,7 +89,7 @@ void loop() void receive(const MyMessage &message) { - LOG(F("Received %s from %s\n"), msgTypeAsCharRepresentation((mysensor_data)message.type), + LOG(F("Received %s from %s\n"), msgTypeAsCharRepresentation((mysensors_data_t)message.type), nodeTypeAsCharRepresentation(message.sender)); delay(250); @@ -82,7 +101,7 @@ void sendPingOrPongResponse( MyMessage msg ) MyMessage response = (msg.type == V_VAR1 ? mPong : mPing); - LOG(F("Sending %s to %s\n"), msgTypeAsCharRepresentation( (mysensor_data)response.type ), + LOG(F("Sending %s to %s\n"), msgTypeAsCharRepresentation( (mysensors_data_t)response.type ), nodeTypeAsCharRepresentation(msg.sender)); // Set payload to current time in millis to ensure each message is unique @@ -97,7 +116,7 @@ void setNodeId(byte nodeID) hwWriteConfig(EEPROM_NODE_ID_ADDRESS, (byte)nodeID); } -const char * msgTypeAsCharRepresentation( mysensor_data mType ) +const char * msgTypeAsCharRepresentation( mysensors_data_t mType ) { return mType == V_VAR1 ? "Ping" : "Pong"; } @@ -105,4 +124,4 @@ const char * msgTypeAsCharRepresentation( mysensor_data mType ) const char * nodeTypeAsCharRepresentation( uint8_t node ) { return node == YING ? "Ying Node" : "Yang Node"; -} +} \ No newline at end of file diff --git a/examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino b/examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino index 852f30315..08ffd5e3e 100644 --- a/examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino +++ b/examples/RFM69_RFM95_ATC_SignalReport/RFM69_RFM95_ATC_SignalReport.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/examples/RelayActuator/RelayActuator.ino b/examples/RelayActuator/RelayActuator.ino index 3e17066eb..ad57b82b8 100644 --- a/examples/RelayActuator/RelayActuator.ino +++ b/examples/RelayActuator/RelayActuator.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -31,7 +31,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/RepeaterNode/RepeaterNode.ino b/examples/RepeaterNode/RepeaterNode.ino index 768b55537..2829c8c54 100644 --- a/examples/RepeaterNode/RepeaterNode.ino +++ b/examples/RepeaterNode/RepeaterNode.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -32,7 +32,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/SecretKnockSensor/SecretKnockSensor.ino b/examples/SecretKnockSensor/SecretKnockSensor.ino index d626b7f61..ffe641e64 100644 --- a/examples/SecretKnockSensor/SecretKnockSensor.ino +++ b/examples/SecretKnockSensor/SecretKnockSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -55,7 +55,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/SecureActuator/SecureActuator.ino b/examples/SecureActuator/SecureActuator.ino index 38b80faa4..a8932f8f4 100644 --- a/examples/SecureActuator/SecureActuator.ino +++ b/examples/SecureActuator/SecureActuator.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -46,8 +46,8 @@ #define MY_NODE_LOCK_FEATURE //!< Enable lockdown of node if suspicious activity is detected // Enable and select radio type attached -#define MY_RADIO_NRF24 //!< NRF24L01 radio driver -//#define MY_RADIO_NRF5_ESB //!< nRF5 radio driver (NRF24 compatible) +#define MY_RADIO_RF24 //!< nRF24L01 radio driver +//#define MY_RADIO_NRF5_ESB //!< nRF5 radio driver (RF24 compatible) //#define MY_RADIO_RFM69 //!< RFM69 radio driver //#define MY_RADIO_RFM95 //!< RFM95 radio driver diff --git a/examples/SecurityPersonalizer/SecurityPersonalizer.ino b/examples/SecurityPersonalizer/SecurityPersonalizer.ino index 7ee2e661c..e456ef286 100644 --- a/examples/SecurityPersonalizer/SecurityPersonalizer.ino +++ b/examples/SecurityPersonalizer/SecurityPersonalizer.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -16,7 +16,6 @@ * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * - ******************************* */ /** * @ingroup MySigninggrp diff --git a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino index 1c682ac8e..e5bed8dd8 100644 --- a/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino +++ b/examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2015 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -41,7 +41,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/SoilMoistSensor/SoilMoistSensor.ino b/examples/SoilMoistSensor/SoilMoistSensor.ino index 719d8ced7..a0f403993 100644 --- a/examples/SoilMoistSensor/SoilMoistSensor.ino +++ b/examples/SoilMoistSensor/SoilMoistSensor.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -64,7 +64,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/UVSensor/UVSensor.ino b/examples/UVSensor/UVSensor.ino index c0246218c..9720c741c 100644 --- a/examples/UVSensor/UVSensor.ino +++ b/examples/UVSensor/UVSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -40,7 +40,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/VibrationSensor/VibrationSensor.ino b/examples/VibrationSensor/VibrationSensor.ino index d28c6d518..b0d20c207 100644 --- a/examples/VibrationSensor/VibrationSensor.ino +++ b/examples/VibrationSensor/VibrationSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -30,13 +30,13 @@ * * Based on: http://www.dfrobot.com/wiki/index.php/DFRobot_Digital_Vibration_Sensor_V2_SKU:DFR0027 * Contributor: epierre -**/ + */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino b/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino index 1afd45a34..6a18eefb7 100644 --- a/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino +++ b/examples/WaterMeterPulseSensor/WaterMeterPulseSensor.ino @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -38,7 +38,7 @@ #define MY_DEBUG // Enable and select radio type attached -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 diff --git a/examples_linux/mysgw.cpp b/examples_linux/mysgw.cpp index 22771a8ba..cd59dcbcb 100644 --- a/examples_linux/mysgw.cpp +++ b/examples_linux/mysgw.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/AVR/MyHwAVR.cpp b/hal/architecture/AVR/MyHwAVR.cpp index de3ff86dc..880691cc6 100644 --- a/hal/architecture/AVR/MyHwAVR.cpp +++ b/hal/architecture/AVR/MyHwAVR.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/AVR/MyHwAVR.h b/hal/architecture/AVR/MyHwAVR.h index c0329fdfd..f9c77c38a 100644 --- a/hal/architecture/AVR/MyHwAVR.h +++ b/hal/architecture/AVR/MyHwAVR.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -39,9 +39,6 @@ #define MY_SERIALDEVICE Serial #endif -#define MIN(a,b) min(a,b) -#define MAX(a,b) max(a,b) - // Define these as macros to save valuable space #define hwDigitalWrite(__pin, __value) digitalWriteFast(__pin, __value) #define hwDigitalRead(__pin) digitalReadFast(__pin) @@ -52,10 +49,10 @@ bool hwInit(void); #define hwWatchdogReset() wdt_reset() #define hwReboot() wdt_enable(WDTO_15MS); while (1) #define hwMillis() millis() -#define hwReadConfig(__pos) eeprom_read_byte((uint8_t*)(__pos)) -#define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t*)(__pos), (__val)) -#define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void*)(__buf), (void*)(__pos), (__length)) -#define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((void*)(__buf), (void*)(__pos), (__length)) +#define hwReadConfig(__pos) eeprom_read_byte((const uint8_t *)__pos) +#define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t *)__pos, (uint8_t)__val) +#define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void *)__buf, (const void *)__pos, (uint32_t)__length) +#define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((const void *)__buf, (void *)__pos, (uint32_t)__length) inline void hwRandomNumberInit(void); void hwInternalSleep(uint32_t ms); diff --git a/hal/architecture/AVR/MyMainAVR.cpp b/hal/architecture/AVR/MyMainAVR.cpp index 8c67595f9..d2792d1a4 100644 --- a/hal/architecture/AVR/MyMainAVR.cpp +++ b/hal/architecture/AVR/MyMainAVR.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/ESP32/MyHwESP32.cpp b/hal/architecture/ESP32/MyHwESP32.cpp index 25578fc35..94d89d982 100644 --- a/hal/architecture/ESP32/MyHwESP32.cpp +++ b/hal/architecture/ESP32/MyHwESP32.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -154,13 +154,12 @@ void hwDebugPrint(const char *fmt, ...) #endif va_list args; va_start(args, fmt); + // cppcheck-suppress wrongPrintfScanfArgNum + vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node - vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; -#else - vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #endif va_end(args); MY_SERIALDEVICE.print(fmtBuffer); diff --git a/hal/architecture/ESP32/MyHwESP32.h b/hal/architecture/ESP32/MyHwESP32.h index 346ec6ed1..d7929fbee 100644 --- a/hal/architecture/ESP32/MyHwESP32.h +++ b/hal/architecture/ESP32/MyHwESP32.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -49,12 +49,6 @@ #define MY_SERIALDEVICE Serial -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) - -#define MIN min -#define MAX max - #define MY_EEPROM_SIZE 1024 #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value) diff --git a/hal/architecture/ESP32/MyMainESP32.cpp b/hal/architecture/ESP32/MyMainESP32.cpp index 99be1711d..21df14d3f 100644 --- a/hal/architecture/ESP32/MyMainESP32.cpp +++ b/hal/architecture/ESP32/MyMainESP32.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/ESP8266/MyHwESP8266.cpp b/hal/architecture/ESP8266/MyHwESP8266.cpp index 4a8570761..74158bcb6 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.cpp +++ b/hal/architecture/ESP8266/MyHwESP8266.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -30,7 +30,7 @@ bool hwInit(void) return true; } -void hwReadConfigBlock(void* buf, void* addr, size_t length) +void hwReadConfigBlock(void *buf, void *addr, size_t length) { uint8_t* dst = static_cast(buf); int pos = reinterpret_cast(addr); @@ -39,7 +39,7 @@ void hwReadConfigBlock(void* buf, void* addr, size_t length) } } -void hwWriteConfigBlock(void* buf, void* addr, size_t length) +void hwWriteConfigBlock(void *buf, void *addr, size_t length) { uint8_t* src = static_cast(buf); int pos = reinterpret_cast(addr); @@ -125,7 +125,7 @@ ADC_MODE(ADC_VCC); ADC_MODE(ADC_TOUT); #endif -uint16_t hwCPUVoltage() +uint16_t hwCPUVoltage(void) { #if defined(MY_SPECIAL_DEBUG) // in mV, requires ADC_VCC set @@ -136,13 +136,13 @@ uint16_t hwCPUVoltage() #endif } -uint16_t hwCPUFrequency() +uint16_t hwCPUFrequency(void) { // in 1/10Mhz return ESP.getCpuFreqMHz()*10; } -uint16_t hwFreeMem() +uint16_t hwFreeMem(void) { return ESP.getFreeHeap(); } @@ -166,6 +166,7 @@ void hwDebugPrint(const char *fmt, ... ) #endif va_list args; va_start (args, fmt ); + // cppcheck-suppress wrongPrintfScanfArgNum vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node diff --git a/hal/architecture/ESP8266/MyHwESP8266.h b/hal/architecture/ESP8266/MyHwESP8266.h index 162f17d91..5a33fa53a 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.h +++ b/hal/architecture/ESP8266/MyHwESP8266.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -29,11 +29,6 @@ #define MY_SERIALDEVICE Serial #endif -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) min(a,b) -#define MAX(a,b) max(a,b) - #define EEPROM_size (1024) // Define these as macros to save valuable space @@ -47,8 +42,8 @@ #define hwRandomNumberInit() bool hwInit(void); -void hwReadConfigBlock(void* buf, void* adr, size_t length); -void hwWriteConfigBlock(void* buf, void* adr, size_t length); +void hwReadConfigBlock(void *buf, void *addr, size_t length); +void hwWriteConfigBlock(void *buf, void *addr, size_t length); void hwWriteConfig(const int addr, uint8_t value); uint8_t hwReadConfig(const int addr); ssize_t hwGetentropy(void *__buffer, size_t __length); diff --git a/hal/architecture/ESP8266/MyMainESP8266.cpp b/hal/architecture/ESP8266/MyMainESP8266.cpp index d71755157..34cccf5da 100644 --- a/hal/architecture/ESP8266/MyMainESP8266.cpp +++ b/hal/architecture/ESP8266/MyMainESP8266.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/Linux/MyHwLinuxGeneric.cpp b/hal/architecture/Linux/MyHwLinuxGeneric.cpp index 8be3de8d0..b45cd4e9b 100644 --- a/hal/architecture/Linux/MyHwLinuxGeneric.cpp +++ b/hal/architecture/Linux/MyHwLinuxGeneric.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -51,27 +51,27 @@ bool hwInit(void) return true; } -void hwReadConfigBlock(void* buf, void* addr, size_t length) +void hwReadConfigBlock(void *buf, void *addr, size_t length) { eeprom.readBlock(buf, addr, length); } -void hwWriteConfigBlock(void* buf, void* addr, size_t length) +void hwWriteConfigBlock(void *buf, void *addr, size_t length) { eeprom.writeBlock(buf, addr, length); } -uint8_t hwReadConfig(int addr) +uint8_t hwReadConfig(const int addr) { return eeprom.readByte(addr); } -void hwWriteConfig(int addr, uint8_t value) +void hwWriteConfig(const int addr, uint8_t value) { eeprom.writeByte(addr, value); } -void hwRandomNumberInit() +void hwRandomNumberInit(void) { uint32_t seed=0; @@ -92,7 +92,7 @@ ssize_t hwGetentropy(void *__buffer, size_t __length) return(fread(__buffer, 1, __length, randomFp)); } -uint32_t hwMillis() +uint32_t hwMillis(void) { return millis(); } @@ -135,19 +135,19 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo return MY_SLEEP_NOT_POSSIBLE; } -uint16_t hwCPUVoltage() +uint16_t hwCPUVoltage(void) { // TODO: Not supported! return FUNCTION_NOT_SUPPORTED; } -uint16_t hwCPUFrequency() +uint16_t hwCPUFrequency(void) { // TODO: Not supported! return FUNCTION_NOT_SUPPORTED; } -uint16_t hwFreeMem() +uint16_t hwFreeMem(void) { // TODO: Not supported! return FUNCTION_NOT_SUPPORTED; diff --git a/hal/architecture/Linux/MyHwLinuxGeneric.h b/hal/architecture/Linux/MyHwLinuxGeneric.h index 214b61267..0ae3dda60 100644 --- a/hal/architecture/Linux/MyHwLinuxGeneric.h +++ b/hal/architecture/Linux/MyHwLinuxGeneric.h @@ -41,9 +41,6 @@ StdInOutStream Serial = StdInOutStream(); #define MY_SERIALDEVICE Serial #endif -#define MIN(a,b) ((a)<(b)?(a):(b)) -#define MAX(a,b) ((a)>(b)?(a):(b)) - // Define these as macros (do nothing) #define hwWatchdogReset() #define hwReboot() @@ -53,14 +50,14 @@ inline int hwDigitalRead(uint8_t); inline void hwPinMode(uint8_t, uint8_t); bool hwInit(void); -inline void hwReadConfigBlock(void* buf, void* addr, size_t length); -inline void hwWriteConfigBlock(void* buf, void* addr, size_t length); -inline uint8_t hwReadConfig(int addr); -inline void hwWriteConfig(int addr, uint8_t value); -inline void hwRandomNumberInit(); +inline void hwReadConfigBlock(void *buf, void *addr, size_t length); +inline void hwWriteConfigBlock(void *buf, void *addr, size_t length); +inline uint8_t hwReadConfig(const int addr); +inline void hwWriteConfig(const int addr, uint8_t value); +inline void hwRandomNumberInit(void); ssize_t hwGetentropy(void *__buffer, size_t __length); #define MY_HW_HAS_GETENTROPY -inline uint32_t hwMillis(); +inline uint32_t hwMillis(void); #ifdef MY_RF24_IRQ_PIN static pthread_mutex_t hw_mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/hal/architecture/Linux/MyMainLinuxGeneric.cpp b/hal/architecture/Linux/MyMainLinuxGeneric.cpp index 6003f9c1a..b4f80edcc 100644 --- a/hal/architecture/Linux/MyMainLinuxGeneric.cpp +++ b/hal/architecture/Linux/MyMainLinuxGeneric.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/MyHw.h b/hal/architecture/MyHw.h index cd45a54b7..5cca78d77 100644 --- a/hal/architecture/MyHw.h +++ b/hal/architecture/MyHw.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -43,10 +43,10 @@ #define hwDigitalRead(__pin) #define hwPinMode(__pin, __value) -void hwReadConfigBlock(void* buf, void* adr, size_t length); -void hwWriteConfigBlock(void* buf, void* adr, size_t length); -void hwWriteConfig(int adr, uint8_t value); -uint8_t hwReadConfig(int adr); +void hwReadConfigBlock(void *buf, void *addr, size_t length); +void hwWriteConfigBlock(void *buf, void *addr, size_t length); +void hwWriteConfig(const int addr, uint8_t value); +uint8_t hwReadConfig(const int addr); */ /** @@ -99,19 +99,19 @@ bool hwUniqueID(unique_id_t* uniqueID); * CPU voltage * @return CPU voltage in mV */ -uint16_t hwCPUVoltage(); +uint16_t hwCPUVoltage(void); /** * CPU frequency * @return CPU frequency in 1/10Mhz */ -uint16_t hwCPUFrequency(); +uint16_t hwCPUFrequency(void); /** * Free memory * @return free memory in bytes */ -uint16_t hwFreeMem(); +uint16_t hwFreeMem(void); #if defined(DEBUG_OUTPUT_ENABLED) void hwDebugPrint(const char *fmt, ... ); diff --git a/hal/architecture/NRF5/MyHwNRF5.cpp b/hal/architecture/NRF5/MyHwNRF5.cpp index 808b92f82..ee07c7a18 100644 --- a/hal/architecture/NRF5/MyHwNRF5.cpp +++ b/hal/architecture/NRF5/MyHwNRF5.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,10 +7,10 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB + * Copyright (C) 2013-2018 Sensnology AB * Copyright (C) 2017 Frank Holtz * Full contributor list: - * https://github.com/mysensors/Arduino/graphs/contributors + * https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -42,31 +42,31 @@ void wakeUp2() // place to send the second interrupts _wokeUpByInterrupt = _wakeUp2Interrupt; } -void hwReadConfigBlock(void *buf, void *adr, size_t length) +void hwReadConfigBlock(void *buf, void *addr, size_t length) { uint8_t *dst = static_cast(buf); - const int offs = reinterpret_cast(adr); + const int offs = reinterpret_cast(addr); (void)NVRAM.read_block(dst, offs, length); } -void hwWriteConfigBlock(void *buf, void *adr, size_t length) +void hwWriteConfigBlock(void *buf, void *addr, size_t length) { uint8_t *src = static_cast(buf); - const int offs = reinterpret_cast(adr); + const int offs = reinterpret_cast(addr); (void)NVRAM.write_block(src, offs, length); } -uint8_t hwReadConfig(int adr) +uint8_t hwReadConfig(const int addr) { - return NVRAM.read(adr); + return NVRAM.read(addr); } -void hwWriteConfig(int adr, uint8_t value) +void hwWriteConfig(const int addr, uint8_t value) { - (void)NVRAM.write(adr, value); + (void)NVRAM.write(addr, value); } -bool hwInit() +bool hwInit(void) { #ifdef MY_LOCK_MCU #ifdef NRF51 @@ -133,7 +133,7 @@ bool hwInit() static nrf_ecb_t hwRngData; static int8_t hwRndDataReadPos = -1; -void hwRandomNumberInit() +void hwRandomNumberInit(void) { // Start HWRNG #ifdef NRF51 @@ -222,12 +222,12 @@ ssize_t hwGetentropy(void *__buffer, size_t __length) return __length; } -void hwWatchdogReset() +void hwWatchdogReset(void) { NRF_WDT->RR[0] = WDT_RR_RR_Reload; } -void hwReboot() +void hwReboot(void) { NVIC_SystemReset(); while (true) @@ -332,14 +332,14 @@ void hwSleepEnd(uint32_t ms) } // Halt CPU until next interrupt event -inline void hwWaitForInterrupt() +inline void hwWaitForInterrupt(void) { __DSB(); __WFI(); } // Sleep in System ON mode -inline void hwSleep() +inline void hwSleep(void) { __WFE(); __SEV(); @@ -440,7 +440,7 @@ bool hwUniqueID(unique_id_t *uniqueID) return true; } -uint16_t hwCPUVoltage() +uint16_t hwCPUVoltage(void) { // VDD is prescaled 1/3 and compared with the internal 1.2V reference #if defined(NRF_ADC) @@ -515,7 +515,7 @@ uint16_t hwCPUVoltage() #endif } -uint16_t hwCPUFrequency() +uint16_t hwCPUFrequency(void) { #if defined(VARIANT_MCK) return (VARIANT_MCK) / 100000UL; @@ -526,7 +526,7 @@ uint16_t hwCPUFrequency() #endif } -uint16_t hwFreeMem() +uint16_t hwFreeMem(void) { // TODO: Not supported! return FUNCTION_NOT_SUPPORTED; diff --git a/hal/architecture/NRF5/MyHwNRF5.h b/hal/architecture/NRF5/MyHwNRF5.h index c9d6595b0..70a26097f 100644 --- a/hal/architecture/NRF5/MyHwNRF5.h +++ b/hal/architecture/NRF5/MyHwNRF5.h @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -7,10 +7,10 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB + * Copyright (C) 2013-2018 Sensnology AB * Copyright (C) 2017 Frank Holtz * Full contributor list: - * https://github.com/mysensors/Arduino/graphs/contributors + * https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -61,9 +61,6 @@ #define printf_P printf #endif -#define MIN(a,b) min(a,b) -#define MAX(a,b) max(a,b) - // redefine 8 bit types of inttypes.h until fix of https://github.com/sandeepmistry/arduino-nRF5/issues/197 #undef PRId8 #undef PRIi8 @@ -108,14 +105,14 @@ #define hwPinMode(__pin, __value) nrf5_pinMode(__pin, __value) #define hwMillis() millis() -bool hwInit(); -void hwWatchdogReset(); -void hwReboot(); -void hwReadConfigBlock(void *buf, void *adr, size_t length); -void hwWriteConfigBlock(void *buf, void *adr, size_t length); -void hwWriteConfig(int adr, uint8_t value); -uint8_t hwReadConfig(int adr); -void hwRandomNumberInit(); +bool hwInit(void); +void hwWatchdogReset(void); +void hwReboot(void); +void hwReadConfigBlock(void *buf, void *addr, size_t length); +void hwWriteConfigBlock(void *buf, void *addr, size_t length); +void hwWriteConfig(const int addr, uint8_t value); +uint8_t hwReadConfig(const int addr); +void hwRandomNumberInit(void); ssize_t hwGetentropy(void *__buffer, size_t __length); #define MY_HW_HAS_GETENTROPY diff --git a/hal/architecture/NRF5/MyMainNRF5.cpp b/hal/architecture/NRF5/MyMainNRF5.cpp index 8c67595f9..d2792d1a4 100644 --- a/hal/architecture/NRF5/MyMainNRF5.cpp +++ b/hal/architecture/NRF5/MyMainNRF5.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/SAMD/MyHwSAMD.cpp b/hal/architecture/SAMD/MyHwSAMD.cpp index 47a14afe8..e0e1f4d6d 100644 --- a/hal/architecture/SAMD/MyHwSAMD.cpp +++ b/hal/architecture/SAMD/MyHwSAMD.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -41,30 +41,29 @@ ISR (WDT_vect) */ -void hwReadConfigBlock(void* buf, void* adr, size_t length) +void hwReadConfigBlock(void *buf, void *addr, size_t length) { uint8_t* dst = static_cast(buf); - const int offs = reinterpret_cast(adr); + const int offs = reinterpret_cast(addr); (void)eep.read(offs, dst, length); - } -void hwWriteConfigBlock(void* buf, void* adr, size_t length) +void hwWriteConfigBlock(void *buf, void *addr, size_t length) { uint8_t* src = static_cast(buf); - const int offs = reinterpret_cast(adr); + const int offs = reinterpret_cast(addr); // use update() instead of write() to reduce e2p wear off (void)eep.update(offs, src, length); } -uint8_t hwReadConfig(int adr) +uint8_t hwReadConfig(const int addr) { - return eep.read(adr); + return eep.read(addr); } -void hwWriteConfig(int adr, uint8_t value) +void hwWriteConfig(const int addr, uint8_t value) { - (void)eep.update(adr, value); + (void)eep.update(addr, value); } bool hwInit(void) @@ -125,12 +124,12 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo bool hwUniqueID(unique_id_t *uniqueID) { - (void)memcpy((uint8_t*)uniqueID, (uint32_t *)0x0080A00C, 4); - (void)memcpy((uint8_t*)uniqueID + 4, (uint32_t *)0x0080A040, 12); + (void)memcpy((uint8_t *)uniqueID, (uint32_t *)0x0080A00C, 4); + (void)memcpy((uint8_t *)uniqueID + 4, (uint32_t *)0x0080A040, 12); return true; } -uint16_t hwCPUVoltage() +uint16_t hwCPUVoltage(void) { // disable ADC @@ -167,13 +166,13 @@ uint16_t hwCPUVoltage() return valueRead * 4; } -uint16_t hwCPUFrequency() +uint16_t hwCPUFrequency(void) { // TODO: currently reporting compile time frequency (in 1/10MHz) return F_CPU / 100000UL; } -uint16_t hwFreeMem() +uint16_t hwFreeMem(void) { // TODO: Not supported! return FUNCTION_NOT_SUPPORTED; diff --git a/hal/architecture/SAMD/MyHwSAMD.h b/hal/architecture/SAMD/MyHwSAMD.h index 353e9bcaf..b38534023 100644 --- a/hal/architecture/SAMD/MyHwSAMD.h +++ b/hal/architecture/SAMD/MyHwSAMD.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -36,11 +36,6 @@ extEEPROM eep(MY_EXT_EEPROM_SIZE, 1, MY_EXT_EEPROM_PAGE_SIZE, MY_EXT_EEPROM_I2C_ADDRESS); //device size, number of devices, page size - -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) min(a,b) -#define MAX(a,b) max(a,b) #define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__) #define vsnprintf_P(s, n, f, ...) vsnprintf((s), (n), (f), __VA_ARGS__) @@ -54,10 +49,10 @@ extEEPROM eep(MY_EXT_EEPROM_SIZE, 1, MY_EXT_EEPROM_PAGE_SIZE, bool hwInit(void); void hwWatchdogReset(void); void hwReboot(void); -void hwReadConfigBlock(void* buf, void* adr, size_t length); -void hwWriteConfigBlock(void* buf, void* adr, size_t length); -void hwWriteConfig(int adr, uint8_t value); -uint8_t hwReadConfig(int adr); +void hwReadConfigBlock(void *buf, void * addr, size_t length); +void hwWriteConfigBlock(void *buf, void * addr, size_t length); +void hwWriteConfig(const int addr, uint8_t value); +uint8_t hwReadConfig(const int addr); #ifndef MY_SERIALDEVICE #define MY_SERIALDEVICE SerialUSB diff --git a/hal/architecture/SAMD/MyMainSAMD.cpp b/hal/architecture/SAMD/MyMainSAMD.cpp index 9bd40b793..ed4537a6d 100644 --- a/hal/architecture/SAMD/MyMainSAMD.cpp +++ b/hal/architecture/SAMD/MyMainSAMD.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/STM32F1/MyHwSTM32F1.cpp b/hal/architecture/STM32F1/MyHwSTM32F1.cpp index 435d24442..aac9b7178 100644 --- a/hal/architecture/STM32F1/MyHwSTM32F1.cpp +++ b/hal/architecture/STM32F1/MyHwSTM32F1.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -59,18 +59,18 @@ bool hwInit(void) return false; } -void hwReadConfigBlock(void* buf, void* addr, size_t length) +void hwReadConfigBlock(void *buf, void *addr, size_t length) { - uint8_t* dst = static_cast(buf); + uint8_t *dst = static_cast(buf); int pos = reinterpret_cast(addr); while (length-- > 0) { *dst++ = EEPROM.read(pos++); } } -void hwWriteConfigBlock(void* buf, void* addr, size_t length) +void hwWriteConfigBlock(void *buf, void *addr, size_t length) { - uint8_t* src = static_cast(buf); + uint8_t *src = static_cast(buf); int pos = reinterpret_cast(addr); while (length-- > 0) { EEPROM.write(pos++, *src++); @@ -149,7 +149,7 @@ bool hwUniqueID(unique_id_t* uniqueID) return true; } -uint16_t hwCPUVoltage() +uint16_t hwCPUVoltage(void) { adc_reg_map *regs = ADC1->regs; regs->CR2 |= ADC_CR2_TSVREFE; // enable VREFINT and temp sensor @@ -157,12 +157,12 @@ uint16_t hwCPUVoltage() return 1200 * 4096 / adc_read(ADC1, 17); } -uint16_t hwCPUFrequency() +uint16_t hwCPUFrequency(void) { return F_CPU/100000UL; } -uint16_t hwFreeMem() +uint16_t hwFreeMem(void) { //Not yet implemented return FUNCTION_NOT_SUPPORTED; diff --git a/hal/architecture/STM32F1/MyHwSTM32F1.h b/hal/architecture/STM32F1/MyHwSTM32F1.h index bca1f5360..49dd759cd 100644 --- a/hal/architecture/STM32F1/MyHwSTM32F1.h +++ b/hal/architecture/STM32F1/MyHwSTM32F1.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -45,9 +45,6 @@ #define MY_SERIALDEVICE Serial #endif -#define MIN(a,b) min(a,b) -#define MAX(a,b) max(a,b) - #ifndef digitalPinToInterrupt #define digitalPinToInterrupt(__pin) (__pin) #endif @@ -60,11 +57,10 @@ #define hwMillis() millis() extern void serialEventRun(void) __attribute__((weak)); -//void (*serialEventRun)() = NULL; bool hwInit(void); void hwRandomNumberInit(void); -void hwReadConfigBlock(void* buf, void* adr, size_t length); -void hwWriteConfigBlock(void* buf, void* adr, size_t length); +void hwReadConfigBlock(void *buf, void *addr, size_t length); +void hwWriteConfigBlock(void *buf, void *addr, size_t length); void hwWriteConfig(const int addr, uint8_t value); uint8_t hwReadConfig(const int addr); diff --git a/hal/architecture/STM32F1/MyMainSTM32F1.cpp b/hal/architecture/STM32F1/MyMainSTM32F1.cpp index dbc9f2172..d688655ad 100644 --- a/hal/architecture/STM32F1/MyMainSTM32F1.cpp +++ b/hal/architecture/STM32F1/MyMainSTM32F1.cpp @@ -1,4 +1,4 @@ -/** +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/architecture/Teensy3/MyHwTeensy3.cpp b/hal/architecture/Teensy3/MyHwTeensy3.cpp index 1771795cb..ccd042c15 100644 --- a/hal/architecture/Teensy3/MyHwTeensy3.cpp +++ b/hal/architecture/Teensy3/MyHwTeensy3.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2017 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -99,7 +99,7 @@ bool hwUniqueID(unique_id_t *uniqueID) return true; } -uint16_t hwCPUVoltage() +uint16_t hwCPUVoltage(void) { analogReference(DEFAULT); analogReadResolution(12); @@ -120,13 +120,13 @@ uint16_t hwCPUVoltage() #endif } -uint16_t hwCPUFrequency() +uint16_t hwCPUFrequency(void) { // TODO: currently reporting compile time frequency (in 1/10MHz) return F_CPU / 100000UL; } -uint16_t hwFreeMem() +uint16_t hwFreeMem(void) { // TODO: Not supported! return FUNCTION_NOT_SUPPORTED; diff --git a/hal/architecture/Teensy3/MyHwTeensy3.h b/hal/architecture/Teensy3/MyHwTeensy3.h index 99e5046dc..08cee3c6c 100644 --- a/hal/architecture/Teensy3/MyHwTeensy3.h +++ b/hal/architecture/Teensy3/MyHwTeensy3.h @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad -* Copyright (C) 2013-2017 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Copyright (C) 2013-2018 Sensnology AB +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -35,8 +35,8 @@ #define CRYPTO_LITTLE_ENDIAN -#ifndef _BV -#define _BV(x) (1<<(x)) +#ifndef MY_SERIALDEVICE +#define MY_SERIALDEVICE Serial #endif #if defined(__MK64FX512__) || defined(__MK66FX1M0__) @@ -51,12 +51,6 @@ #define SIM_SCGC6_RNGA ((uint32_t)0x00000200) #endif -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) - -#define MIN min -#define MAX max - // Define these as macros to save valuable space #define hwDigitalWrite(__pin, __value) digitalWriteFast(__pin, __value) #define hwDigitalRead(__pin) digitalReadFast(__pin) @@ -69,14 +63,10 @@ void hwWatchdogReset(void); void hwReboot(void); // Teensy 3.x implements avr-libc EEPROM API -#define hwReadConfig(__pos) eeprom_read_byte((uint8_t*)(__pos)) -#define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t*)(__pos), (__val)) -#define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void*)(__buf), (void*)(__pos), (__length)) -#define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((void*)(__buf), (void*)(__pos), (__length)) - -#ifndef MY_SERIALDEVICE -#define MY_SERIALDEVICE Serial -#endif +#define hwReadConfig(__pos) eeprom_read_byte((const uint8_t *)__pos) +#define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t *)__pos, (uint8_t)__val) +#define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void *)__buf, (const void *)__pos, (uint32_t)__length) +#define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((const void *)__buf, (void *)__pos, (uint32_t)__length) #if defined(__MK64FX512__) || defined(__MK66FX1M0__) #define MY_HW_HAS_GETENTROPY diff --git a/hal/architecture/Teensy3/MyMainTeensy3.cpp b/hal/architecture/Teensy3/MyMainTeensy3.cpp index be686887c..630ebd27a 100644 --- a/hal/architecture/Teensy3/MyMainTeensy3.cpp +++ b/hal/architecture/Teensy3/MyMainTeensy3.cpp @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/crypto/AVR/MyCryptoAVR.cpp b/hal/crypto/AVR/MyCryptoAVR.cpp index a803a884d..99732b18e 100644 --- a/hal/crypto/AVR/MyCryptoAVR.cpp +++ b/hal/crypto/AVR/MyCryptoAVR.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/crypto/AVR/MyCryptoAVR.h b/hal/crypto/AVR/MyCryptoAVR.h index 78fa369f3..1a5156b2a 100644 --- a/hal/crypto/AVR/MyCryptoAVR.h +++ b/hal/crypto/AVR/MyCryptoAVR.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/crypto/ESP32/MyCryptoESP32.cpp b/hal/crypto/ESP32/MyCryptoESP32.cpp index b41d72606..03999be00 100644 --- a/hal/crypto/ESP32/MyCryptoESP32.cpp +++ b/hal/crypto/ESP32/MyCryptoESP32.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/crypto/ESP32/MyCryptoESP32.h b/hal/crypto/ESP32/MyCryptoESP32.h index 8e7a295c8..41555caeb 100644 --- a/hal/crypto/ESP32/MyCryptoESP32.h +++ b/hal/crypto/ESP32/MyCryptoESP32.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/crypto/MyCryptoHAL.h b/hal/crypto/MyCryptoHAL.h index 1c8dbfd82..334fe4f4b 100644 --- a/hal/crypto/MyCryptoHAL.h +++ b/hal/crypto/MyCryptoHAL.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/crypto/generic/MyCryptoGeneric.cpp b/hal/crypto/generic/MyCryptoGeneric.cpp index fc2906479..f2aa2fc99 100644 --- a/hal/crypto/generic/MyCryptoGeneric.cpp +++ b/hal/crypto/generic/MyCryptoGeneric.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/crypto/generic/MyCryptoGeneric.h b/hal/crypto/generic/MyCryptoGeneric.h index 1b361e605..75dd57fbe 100644 --- a/hal/crypto/generic/MyCryptoGeneric.h +++ b/hal/crypto/generic/MyCryptoGeneric.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB -* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors +* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/transport/MyTransportHAL.h b/hal/transport/MyTransportHAL.h index a3da5133a..308e0dd46 100644 --- a/hal/transport/MyTransportHAL.h +++ b/hal/transport/MyTransportHAL.h @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp b/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp index ddc29a6b4..483bd5690 100644 --- a/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp +++ b/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp @@ -9,7 +9,7 @@ * Copyright (C) 2013-2018 Sensnology AB * Copyright (C) 2017 Frank Holtz * Full contributor list: - * https://github.com/mysensors/Arduino/graphs/contributors + * https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/transport/RF24/MyTransportRF24.cpp b/hal/transport/RF24/MyTransportRF24.cpp index 85b1b0b10..9ce7fcf17 100644 --- a/hal/transport/RF24/MyTransportRF24.cpp +++ b/hal/transport/RF24/MyTransportRF24.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/transport/RFM69/MyTransportRFM69.cpp b/hal/transport/RFM69/MyTransportRFM69.cpp index b1ff3db1f..44533f54c 100644 --- a/hal/transport/RFM69/MyTransportRFM69.cpp +++ b/hal/transport/RFM69/MyTransportRFM69.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/transport/RFM95/MyTransportRFM95.cpp b/hal/transport/RFM95/MyTransportRFM95.cpp index 5e3bd648a..c8188df00 100644 --- a/hal/transport/RFM95/MyTransportRFM95.cpp +++ b/hal/transport/RFM95/MyTransportRFM95.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/hal/transport/RS485/MyTransportRS485.cpp b/hal/transport/RS485/MyTransportRS485.cpp index 00e869598..a8feff48f 100644 --- a/hal/transport/RS485/MyTransportRS485.cpp +++ b/hal/transport/RS485/MyTransportRS485.cpp @@ -7,7 +7,7 @@ * * Created by Henrik Ekblad * Copyright (C) 2013-2018 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/library.json b/library.json index 4e70025c3..a77abdb16 100644 --- a/library.json +++ b/library.json @@ -1,13 +1,13 @@ { "name": "MySensors", "keywords": "framework, sensor, rf", - "description": "Home Automation Framework. Create your own wireless sensor mesh using NRF24L01+, RFM69 and RFM95 radios running on AVR, ESP32, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers.", + "description": "Home Automation Framework. Create your own wireless sensor mesh using nRF24L01+, RFM69 and RFM95 radios running on AVR, ESP32, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers.", "repository": { "type": "git", "url": "https://github.com/mysensors/MySensors.git" }, - "version": "2.3.1-alpha", + "version": "2.3.1-beta", "frameworks": "arduino", "platforms": "*", "export": { diff --git a/library.properties b/library.properties index 83c865ed0..7bf6b93ee 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=MySensors -version=2.3.1-alpha +version=2.3.1-beta author=The MySensors Team maintainer=The MySensors Team sentence=Home Automation Framework -paragraph=Create your own wireless sensor mesh using NRF24L01+, RFM69 and RFM95 radios running on AVR, ESP32, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers. +paragraph=Create your own wireless sensor mesh using nRF24L01+, RFM69 and RFM95 radios running on AVR, ESP32, ESP8266, NRF5x, SAMD, STM32F1 and Teensyduino. Over-the-air updates and MySensors support by 20+ home automation controllers. category=Communication url=https://www.mysensors.org architectures=* diff --git a/tests/Arduino/sketches/hard_signing_no_whitelisting_full_debug/hard_signing_no_whitelisting_full_debug.ino b/tests/Arduino/sketches/hard_signing_no_whitelisting_full_debug/hard_signing_no_whitelisting_full_debug.ino index dea5111cb..1aff80cae 100644 --- a/tests/Arduino/sketches/hard_signing_no_whitelisting_full_debug/hard_signing_no_whitelisting_full_debug.ino +++ b/tests/Arduino/sketches/hard_signing_no_whitelisting_full_debug/hard_signing_no_whitelisting_full_debug.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -22,7 +22,7 @@ #include #define MY_DEBUG #define MY_DEBUG_VERBOSE_SIGNING -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_SIGNING_SOFT #define MY_SIGNING_ATSHA204 //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}} diff --git a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug/hard_signing_whitelisting_full_debug.ino b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug/hard_signing_whitelisting_full_debug.ino index 23f0d9b82..55f20354e 100644 --- a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug/hard_signing_whitelisting_full_debug.ino +++ b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug/hard_signing_whitelisting_full_debug.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -22,7 +22,7 @@ #include #define MY_DEBUG #define MY_DEBUG_VERBOSE_SIGNING -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_SIGNING_SOFT #define MY_SIGNING_ATSHA204 #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}} diff --git a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nodelock/hard_signing_whitelisting_full_debug_nodelock.ino b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nodelock/hard_signing_whitelisting_full_debug_nodelock.ino index 43ff5e971..aa90b0484 100644 --- a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nodelock/hard_signing_whitelisting_full_debug_nodelock.ino +++ b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nodelock/hard_signing_whitelisting_full_debug_nodelock.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -22,7 +22,7 @@ #include #define MY_DEBUG #define MY_DEBUG_VERBOSE_SIGNING -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_SIGNING_SOFT #define MY_SIGNING_ATSHA204 #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}} diff --git a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nrf24_rsa/hard_signing_whitelisting_full_debug_nrf24_rsa.ino b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nrf24_rsa/hard_signing_whitelisting_full_debug_nrf24_rsa.ino index d1263b7d0..8707807d4 100644 --- a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nrf24_rsa/hard_signing_whitelisting_full_debug_nrf24_rsa.ino +++ b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_nrf24_rsa/hard_signing_whitelisting_full_debug_nrf24_rsa.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -22,7 +22,7 @@ #include #define MY_DEBUG #define MY_DEBUG_VERBOSE_SIGNING -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 //#define MY_SIGNING_SOFT #define MY_SIGNING_ATSHA204 #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}} diff --git a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm69_rsa/hard_signing_whitelisting_full_debug_rfm69_rsa.ino b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm69_rsa/hard_signing_whitelisting_full_debug_rfm69_rsa.ino index 489f926da..15177246d 100644 --- a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm69_rsa/hard_signing_whitelisting_full_debug_rfm69_rsa.ino +++ b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm69_rsa/hard_signing_whitelisting_full_debug_rfm69_rsa.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm95_rsa/hard_signing_whitelisting_full_debug_rfm95_rsa.ino b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm95_rsa/hard_signing_whitelisting_full_debug_rfm95_rsa.ino index 67fc11e4c..fe4f925b9 100644 --- a/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm95_rsa/hard_signing_whitelisting_full_debug_rfm95_rsa.ino +++ b/tests/Arduino/sketches/hard_signing_whitelisting_full_debug_rfm95_rsa/hard_signing_whitelisting_full_debug_rfm95_rsa.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2016 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/tests/Arduino/sketches/new_rfm69_driver/new_rfm69_driver.ino b/tests/Arduino/sketches/new_rfm69_driver/new_rfm69_driver.ino index eb67aebed..833cdeb89 100644 --- a/tests/Arduino/sketches/new_rfm69_driver/new_rfm69_driver.ino +++ b/tests/Arduino/sketches/new_rfm69_driver/new_rfm69_driver.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2017 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/tests/Arduino/sketches/ota_firmware_update_nrf24/ota_firmware_update_nrf24.ino b/tests/Arduino/sketches/ota_firmware_update_nrf24/ota_firmware_update_nrf24.ino index 038cb37ea..8a0a76344 100644 --- a/tests/Arduino/sketches/ota_firmware_update_nrf24/ota_firmware_update_nrf24.ino +++ b/tests/Arduino/sketches/ota_firmware_update_nrf24/ota_firmware_update_nrf24.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -21,6 +21,6 @@ #include #include #define MY_DEBUG -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 #define MY_OTA_FIRMWARE_FEATURE #include diff --git a/tests/Arduino/sketches/serial_gw_no_transport_hard_signing_whitelisting_full_debug/serial_gw_no_transport_hard_signing_whitelisting_full_debug.ino b/tests/Arduino/sketches/serial_gw_no_transport_hard_signing_whitelisting_full_debug/serial_gw_no_transport_hard_signing_whitelisting_full_debug.ino index 65109fcc6..ff41ab9ec 100644 --- a/tests/Arduino/sketches/serial_gw_no_transport_hard_signing_whitelisting_full_debug/serial_gw_no_transport_hard_signing_whitelisting_full_debug.ino +++ b/tests/Arduino/sketches/serial_gw_no_transport_hard_signing_whitelisting_full_debug/serial_gw_no_transport_hard_signing_whitelisting_full_debug.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2016 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/tests/Arduino/sketches/serial_gw_no_transport_soft_signing_whitelisting_full_debug/serial_gw_no_transport_soft_signing_whitelisting_full_debug.ino b/tests/Arduino/sketches/serial_gw_no_transport_soft_signing_whitelisting_full_debug/serial_gw_no_transport_soft_signing_whitelisting_full_debug.ino index 7dd4fdec8..9d5ea3763 100644 --- a/tests/Arduino/sketches/serial_gw_no_transport_soft_signing_whitelisting_full_debug/serial_gw_no_transport_soft_signing_whitelisting_full_debug.ino +++ b/tests/Arduino/sketches/serial_gw_no_transport_soft_signing_whitelisting_full_debug/serial_gw_no_transport_soft_signing_whitelisting_full_debug.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2016 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org diff --git a/tests/Arduino/sketches/soft_signing_no_whitelisting_full_debug/soft_signing_no_whitelisting_full_debug.ino b/tests/Arduino/sketches/soft_signing_no_whitelisting_full_debug/soft_signing_no_whitelisting_full_debug.ino index f922d57ef..34faae7c8 100644 --- a/tests/Arduino/sketches/soft_signing_no_whitelisting_full_debug/soft_signing_no_whitelisting_full_debug.ino +++ b/tests/Arduino/sketches/soft_signing_no_whitelisting_full_debug/soft_signing_no_whitelisting_full_debug.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -22,7 +22,7 @@ #include #define MY_DEBUG #define MY_DEBUG_VERBOSE_SIGNING -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 #define MY_SIGNING_SOFT //#define MY_SIGNING_ATSHA204 //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}} diff --git a/tests/Arduino/sketches/soft_signing_whitelisting_full_debug/soft_signing_whitelisting_full_debug.ino b/tests/Arduino/sketches/soft_signing_whitelisting_full_debug/soft_signing_whitelisting_full_debug.ino index 3790fc690..d9e8749a2 100644 --- a/tests/Arduino/sketches/soft_signing_whitelisting_full_debug/soft_signing_whitelisting_full_debug.ino +++ b/tests/Arduino/sketches/soft_signing_whitelisting_full_debug/soft_signing_whitelisting_full_debug.ino @@ -6,8 +6,8 @@ * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad - * Copyright (C) 2013-2015 Sensnology AB - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * Copyright (C) 2013-2018 Sensnology AB + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org @@ -22,7 +22,7 @@ #include #define MY_DEBUG #define MY_DEBUG_VERBOSE_SIGNING -#define MY_RADIO_NRF24 +#define MY_RADIO_RF24 #define MY_SIGNING_SOFT //#define MY_SIGNING_ATSHA204 #define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}} From 46568ba14a6b6e679be57219e05fd59d8ef69f2f Mon Sep 17 00:00:00 2001 From: tekka Date: Sun, 26 Aug 2018 14:46:16 +0200 Subject: [PATCH 11/31] RF24: Fix TX issue regarding PA+LNA modules (#1189) --- drivers/RF24/RF24.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index b87168a40..144cd820d 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -314,14 +314,13 @@ LOCAL bool RF24_sendMessage(const uint8_t recipient, const void *buf, const uint RF24_CMD_WRITE_TX_PAYLOAD, (uint8_t *)buf, len, false ); // go, TX starts after ~10us, CE high also enables PA+LNA on supported HW RF24_ce(HIGH); - delayMicroseconds(10); // datasheet: Pulse CE at least 10us - RF24_ce(LOW); // timeout counter to detect HW issues uint16_t timeout = 0xFFFF; do { RF24_status = RF24_getStatus(); } while (!(RF24_status & ( _BV(RF24_MAX_RT) | _BV(RF24_TX_DS) )) && timeout--); // timeout value after successful TX on 16Mhz AVR ~ 65500, i.e. msg is transmitted after ~36 loop cycles + RF24_ce(LOW); // reset interrupts RF24_setStatus(_BV(RF24_TX_DS) | _BV(RF24_MAX_RT) ); // Max retries exceeded From 5051d516dcb42cc7f840cfd612cdef941004ef94 Mon Sep 17 00:00:00 2001 From: Embedded Innovation Date: Sun, 26 Aug 2018 17:38:46 +0200 Subject: [PATCH 12/31] Add lowlevel nRF24 functions (#1190) * Implemented nRF24 constant carrier wave For testing purposes only! Not used by regular MySensors stack. * Please Jenkins for unused functions --- drivers/RF24/RF24.cpp | 14 ++++++++++++++ drivers/RF24/RF24.h | 10 +++++++++- drivers/RF24/RF24registers.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index 144cd820d..519dc2492 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -418,6 +418,20 @@ LOCAL int16_t RF24_getSendingRSSI(void) return static_cast(-29 - (8 * (RF24_getObserveTX() & 0xF))); } +LOCAL void RF24_enableConstantCarrierWave(void) +{ + RF24_standBy(); + delayMicroseconds(1500); + RF24_setRFSetup(RF24_RF_SETUP | _BV(RF24_CONT_WAVE) | _BV(RF24_PLL_LOCK) ); + RF24_ce(HIGH); +} + +LOCAL void RF24_disableConstantCarrierWave(void) +{ + RF24_ce(LOW); + RF24_setRFSetup(RF24_RF_SETUP); +} + #if defined(MY_RX_MESSAGE_BUFFER_FEATURE) LOCAL void RF24_irqHandler(void) { diff --git a/drivers/RF24/RF24.h b/drivers/RF24/RF24.h index 763a6ff79..20f008b5e 100644 --- a/drivers/RF24/RF24.h +++ b/drivers/RF24/RF24.h @@ -146,7 +146,7 @@ extern HardwareSPI SPI; //!< SPI #define RF24_CONFIGURATION (uint8_t) (RF24_CRC_16 << 2) //!< RF24_CONFIGURATION #endif #define RF24_FEATURE (uint8_t)( _BV(RF24_EN_DPL)) //!< RF24_FEATURE -#define RF24_RF_SETUP (uint8_t)( ((MY_RF24_DATARATE & 0b10 ) << 4) | ((MY_RF24_DATARATE & 0b01 ) << 3) | (MY_RF24_PA_LEVEL << 1) ) + 1 //!< RF24_RF_SETUP, +1 for Si24R1 and LNA +#define RF24_RF_SETUP (uint8_t)(( ((MY_RF24_DATARATE & 0b10 ) << 4) | ((MY_RF24_DATARATE & 0b01 ) << 3) | (MY_RF24_PA_LEVEL << 1) ) + 1) //!< RF24_RF_SETUP, +1 for Si24R1 and LNA // powerup delay #define RF24_POWERUP_DELAY_MS (100u) //!< Power up delay, allow VCC to settle, transport to become fully operational @@ -392,6 +392,14 @@ LOCAL bool RF24_setTxPowerPercent(const uint8_t newPowerPercent); * @return Pseudo-RSSI based on ARC register */ LOCAL int16_t RF24_getSendingRSSI(void); +/** +* @brief Generate a constant carrier wave at active channel & transmit power (for testing only). +*/ +LOCAL void RF24_enableConstantCarrierWave(void) __attribute__((unused)); +/** +* @brief Stop generating a constant carrier wave (for testing only). +*/ +LOCAL void RF24_disableConstantCarrierWave(void) __attribute__((unused)); #if defined(MY_RX_MESSAGE_BUFFER_FEATURE) diff --git a/drivers/RF24/RF24registers.h b/drivers/RF24/RF24registers.h index fa13235c4..1c2911cd8 100644 --- a/drivers/RF24/RF24registers.h +++ b/drivers/RF24/RF24registers.h @@ -129,6 +129,7 @@ #define RF24_ARD (4) #define RF24_ARC (0) #define RF24_PLL_LOCK (4) +#define RF24_CONT_WAVE (7) #define RF24_RF_DR (3) #define RF24_RF_PWR (6) #define RF24_RX_DR (6) From ea7f7bec79573a553a97f52a81fa591637602960 Mon Sep 17 00:00:00 2001 From: tekka Date: Sun, 26 Aug 2018 17:39:47 +0200 Subject: [PATCH 13/31] AVR: Fix variable scope in SHA256 ASM (#1188) * AVR: Disable SHA256 ASM implementation * AVR: Fix variable scope in SHA256 ASM --- core/MySigningAtsha204Soft.cpp | 59 ++++++++++++++++++---------------- hal/architecture/AVR/MyHwAVR.h | 2 +- hal/crypto/AVR/MyCryptoAVR.h | 2 ++ 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/core/MySigningAtsha204Soft.cpp b/core/MySigningAtsha204Soft.cpp index 2bc5ea440..1ee1919c0 100644 --- a/core/MySigningAtsha204Soft.cpp +++ b/core/MySigningAtsha204Soft.cpp @@ -187,7 +187,6 @@ void signerAtsha204SoftPutNonce(MyMessage &msg) if (!_signing_init_ok) { return; } - (void)memcpy((void *)_signing_nonce, (const void *)msg.getCustom(), MIN(MAX_PAYLOAD, 32)); if (MAX_PAYLOAD < 32) { // We set the part of the 32-byte nonce that does not fit into a message to 0xAA @@ -355,36 +354,40 @@ static void signerAtsha204AHmac(uint8_t *dest, const uint8_t *nonce, const uint8 // 25 bytes zeroes // 32 bytes nonce - uint8_t buffer[96]; +#if defined(MY_CRYPTO_SHA256_ASM) + static uint8_t _signing_buffer[96]; // static for AVR ASM SHA256 +#else + uint8_t _signing_buffer[96]; +#endif // Calculate message digest first - (void)memset((void *)buffer, 0x00, sizeof(buffer)); - (void)memcpy((void *)buffer, (const void *)data, 32); - buffer[0 + 32] = 0x15; // OPCODE - buffer[1 + 32] = 0x02; // param1 - buffer[2 + 32] = 0x08; // param2(1) - //buffer[3 + 32] = 0x00; // param2(2) - buffer[4 + 32] = 0xEE; // SN[8] - buffer[5 + 32] = 0x01; // SN[0] - buffer[6 + 32] = 0x23; // SN[1] - // buffer[7 + 32..31 + 32] => 0x00; - (void)memcpy((void *)&buffer[64], (const void *)nonce, 32); - SHA256(_signing_hmac, buffer, 96); + (void)memset((void *)_signing_buffer, 0x00, sizeof(_signing_buffer)); + (void)memcpy((void *)_signing_buffer, (const void *)data, 32); + _signing_buffer[0 + 32] = 0x15; // OPCODE + _signing_buffer[1 + 32] = 0x02; // param1 + _signing_buffer[2 + 32] = 0x08; // param2(1) + //_signing_buffer[3 + 32] = 0x00; // param2(2) + _signing_buffer[4 + 32] = 0xEE; // SN[8] + _signing_buffer[5 + 32] = 0x01; // SN[0] + _signing_buffer[6 + 32] = 0x23; // SN[1] + // _signing_buffer[7 + 32..31 + 32] => 0x00; + (void)memcpy((void *)&_signing_buffer[64], (const void *)nonce, 32); + SHA256(_signing_hmac, _signing_buffer, 96); // Feed "message" to HMAC calculator - (void)memset((void *)buffer, 0x00, sizeof(buffer)); - (void)memcpy((void *)&buffer[32], (const void *)_signing_hmac, 32); - buffer[0 + 64] = 0x11; // OPCODE - buffer[1 + 64] = 0x04; // Mode - //buffer[2 + 64] = 0x00; // SlotID(1) - //buffer[3 + 64] = 0x00; // SlotID(2) - //buffer[4 + 64..14 + 64] => 0x00; // 11 bytes zeroes - buffer[15 + 64] = 0xEE; // SN[8] - //buffer[16 + 64..19 + 64] => 0x00; // 4 bytes zeroes - buffer[20 + 64] = 0x01; - buffer[21 + 64] = 0x23; - //buffer[22 + 64] = 0x00; // SN[0] - //buffer[23 + 64] = 0x00; // SN[1] - SHA256HMAC(dest, _signing_hmac_key, 32, buffer, 88); + (void)memset((void *)_signing_buffer, 0x00, sizeof(_signing_buffer)); + (void)memcpy((void *)&_signing_buffer[32], (const void *)_signing_hmac, 32); + _signing_buffer[0 + 64] = 0x11; // OPCODE + _signing_buffer[1 + 64] = 0x04; // Mode + //_signing_buffer[2 + 64] = 0x00; // SlotID(1) + //_signing_buffer[3 + 64] = 0x00; // SlotID(2) + //_signing_buffer[4 + 64..14 + 64] => 0x00; // 11 bytes zeroes + _signing_buffer[15 + 64] = 0xEE; // SN[8] + //_signing_buffer[16 + 64..19 + 64] => 0x00; // 4 bytes zeroes + _signing_buffer[20 + 64] = 0x01; + _signing_buffer[21 + 64] = 0x23; + //_signing_buffer[22 + 64] = 0x00; // SN[0] + //_signing_buffer[23 + 64] = 0x00; // SN[1] + SHA256HMAC(dest, _signing_hmac_key, 32, _signing_buffer, 88); } #endif //MY_SIGNING_SOFT diff --git a/hal/architecture/AVR/MyHwAVR.h b/hal/architecture/AVR/MyHwAVR.h index f9c77c38a..8da3f40d2 100644 --- a/hal/architecture/AVR/MyHwAVR.h +++ b/hal/architecture/AVR/MyHwAVR.h @@ -33,7 +33,7 @@ #include #endif -#define MYSENSORS_SHA256_ASM_AVR // use the ASM implementation for the sha256 code +#define CRYPTO_LITTLE_ENDIAN #ifndef MY_SERIALDEVICE #define MY_SERIALDEVICE Serial diff --git a/hal/crypto/AVR/MyCryptoAVR.h b/hal/crypto/AVR/MyCryptoAVR.h index 1a5156b2a..6711bffed 100644 --- a/hal/crypto/AVR/MyCryptoAVR.h +++ b/hal/crypto/AVR/MyCryptoAVR.h @@ -48,6 +48,8 @@ #include "hal/crypto/MyCryptoHAL.h" +#define MY_CRYPTO_SHA256_ASM //!< Switch to define correct variable scope for ASM SHA256 implementation + #define SHA256_HASH_BITS 256 //!< Defines the size of a SHA-256 hash value in bits #define SHA256_HASH_BYTES (SHA256_HASH_BITS/8) //!< Defines the size of a SHA-256 hash value in bytes #define SHA256_BLOCK_BITS 512 //!< Defines the size of a SHA-256 input block in bits From 6d24ab1bb52ed4402140def8f5ba83fa51b7c0d2 Mon Sep 17 00:00:00 2001 From: tekka Date: Wed, 29 Aug 2018 14:52:01 +0200 Subject: [PATCH 14/31] Improve transport function & debug messages (#1191) --- core/MyGatewayTransport.cpp | 2 +- core/MySensorsCore.cpp | 11 +++++------ core/MySensorsCore.h | 8 ++++---- core/MyTransport.cpp | 20 ++++++++++---------- core/MyTransport.h | 1 + 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/MyGatewayTransport.cpp b/core/MyGatewayTransport.cpp index 064221b02..042631f6e 100644 --- a/core/MyGatewayTransport.cpp +++ b/core/MyGatewayTransport.cpp @@ -52,7 +52,7 @@ inline void gatewayTransportProcess(void) inclusionModeSet(atoi(_msg.data) == 1); #endif } else { - _processInternalMessages(); + (void)_processInternalCoreMessage(); } } else { // Call incoming message callback if available diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index fba4bc21e..8e175711d 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -400,15 +400,14 @@ bool requestTime(const bool ack) } // Message delivered through _msg -bool _processInternalMessages(void) +bool _processInternalCoreMessage(void) { const uint8_t type = _msg.type; - if (_msg.sender == GATEWAY_ADDRESS) { if (type == I_REBOOT) { #if !defined(MY_DISABLE_REMOTE_RESET) - // Requires MySensors or other bootloader with watchdogs enabled setIndication(INDICATION_REBOOT); + // WDT fuse should be enabled hwReboot(); #endif } else if (type == I_REGISTRATION_RESPONSE) { @@ -468,7 +467,7 @@ bool _processInternalMessages(void) } #endif } else { - return false; + return false; // further processing required } } else { // sender is a node @@ -496,10 +495,10 @@ bool _processInternalMessages(void) #endif #endif } else { - return false; + return false; // further processing required } } - return true; + return true; // if not GW or no further processing required } diff --git a/core/MySensorsCore.h b/core/MySensorsCore.h index 8a56da074..31e922561 100644 --- a/core/MySensorsCore.h +++ b/core/MySensorsCore.h @@ -32,7 +32,7 @@ * - MCO:BGN from @ref _begin() * - MCO:REG from @ref _registerNode() * - MCO:SND from @ref send() -* - MCO:PIM from @ref _processInternalMessages() +* - MCO:PIM from @ref _processInternalCoreMessage() * - MCO:NLK from @ref _nodeLock() * * MySensorsCore debug log messages: @@ -385,10 +385,10 @@ void _begin(void); */ void _process(void); /** -* @brief Processes internal messages -* @return True if received message requires further processing +* @brief Processes internal core message +* @return True if no further processing required */ -bool _processInternalMessages(void); +bool _processInternalCoreMessage(void); /** * @brief Puts node to a infinite loop if unrecoverable situation detected */ diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index 9d22bae3c..ef7e190dd 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -775,7 +775,7 @@ void transportProcessMessage(void) } else { TRANSPORT_DEBUG(PSTR("!TSF:MSG:FPAR INACTIVE\n")); // find parent response received, but inactive } - return; + return; // no further processing required #endif } #endif // !defined(MY_GATEWAY_FEATURE) @@ -802,16 +802,13 @@ void transportProcessMessage(void) } return; // no further processing required } - if (_processInternalMessages()) { - return; // no further processing required - } if (type == I_SIGNAL_REPORT_REVERSE) { return; // no further processing required } if (type == I_SIGNAL_REPORT_REQUEST) { - const char command = _msg.data[0]; int16_t value = INVALID_RSSI; #if defined(MY_SIGNAL_REPORT_ENABLED) + const char command = _msg.data[0]; if (_msg.data[1] != '!') { value = transportSignalReport(command); } else { @@ -822,13 +819,15 @@ void transportProcessMessage(void) value = transportSignalReport(command + 32); // reverse }; } -#else - (void)command; #endif (void)transportRouteMessage(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_SIGNAL_REPORT_RESPONSE).set(value)); - return; + return; // no further processing required + } + if (_processInternalCoreMessage()) { + return; // no further processing required } + return; // other C_INTERNAL messages do not require further processing } else if (command == C_STREAM) { #if defined(MY_OTA_FIRMWARE_FEATURE) if(firmwareOTAUpdateProcess()) { @@ -918,6 +917,7 @@ void transportProcessMessage(void) (void)gatewayTransportSend(_msg); #endif if (receive) { + TRANSPORT_DEBUG(PSTR("TSF:MSG:RCV CB\n")); // hand over message to receive callback function receive(_msg); } } @@ -926,18 +926,18 @@ void transportProcessMessage(void) // msg not to us and not BC, relay msg #if defined(MY_REPEATER_FEATURE) if (isTransportReady()) { - TRANSPORT_DEBUG(PSTR("TSF:MSG:REL MSG\n")); // relay msg if (command == C_INTERNAL) { if (type == I_PING || type == I_PONG) { uint8_t hopsCnt = _msg.getByte(); + TRANSPORT_DEBUG(PSTR("TSF:MSG:REL PxNG,HP=%" PRIu8 "\n"), hopsCnt); if (hopsCnt != MAX_HOPS) { - TRANSPORT_DEBUG(PSTR("TSF:MSG:REL PxNG,HP=%" PRIu8 "\n"), hopsCnt); hopsCnt++; _msg.set(hopsCnt); } } } // Relay this message to another node + TRANSPORT_DEBUG(PSTR("TSF:MSG:REL MSG\n")); // relay msg (void)transportRouteMessage(_msg); } #else diff --git a/core/MyTransport.h b/core/MyTransport.h index 08fd0e422..98f578472 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -103,6 +103,7 @@ * | | TSF | MSG | BC | Broadcast message received * | | TSF | MSG | GWL OK | Link to GW ok * | | TSF | MSG | FWD BC MSG | Controlled broadcast message forwarding +* | | TSF | MSG | RCV CB | Hand over message to @ref receive() callback function * | | TSF | MSG | REL MSG | Relay message * | | TSF | MSG | REL PxNG,HP=%%d | Relay PING/PONG message, increment hop counter (HP) * |!| TSF | MSG | LEN=%%d,EXP=%%d | Invalid message length (LEN), exptected length (EXP) From cff369679b96afb1e47ea73ed31d50d9367b223f Mon Sep 17 00:00:00 2001 From: freynder Date: Thu, 30 Aug 2018 21:13:44 +0200 Subject: [PATCH 15/31] Inclusion mode: change pinmode to INPUT_PULLUP (#1197) Issue 1196: https://github.com/mysensors/MySensors/issues/1196 According to arduino references we should instead use INPUT_PULLUP as of Arduino 1.0.1 https://www.arduino.cc/en/Tutorial/DigitalPins --- core/MyInclusionMode.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/MyInclusionMode.cpp b/core/MyInclusionMode.cpp index 94a1f2751..365dfbaa9 100644 --- a/core/MyInclusionMode.cpp +++ b/core/MyInclusionMode.cpp @@ -30,8 +30,7 @@ inline void inclusionInit() _inclusionMode = false; #if defined(MY_INCLUSION_BUTTON_FEATURE) // Setup digital in that triggers inclusion mode - hwPinMode(MY_INCLUSION_MODE_BUTTON_PIN, INPUT); - hwDigitalWrite(MY_INCLUSION_MODE_BUTTON_PIN, HIGH); + hwPinMode(MY_INCLUSION_MODE_BUTTON_PIN, INPUT_PULLUP); #endif #if defined (MY_INCLUSION_LED_PIN) // Setup LED pin that indicates inclusion mode From 966c5d70e12ba418ff3318534a3e428e028c2d82 Mon Sep 17 00:00:00 2001 From: Embedded Innovation Date: Thu, 30 Aug 2018 21:14:10 +0200 Subject: [PATCH 16/31] Nrf24 lowlevel (#1192) * Implemented nRF24 constant carrier wave For testing purposes only! Not used by regular MySensors stack. * Please Jenkins for unused functions * Add RPD retrieval --- drivers/RF24/RF24.cpp | 7 +++++++ drivers/RF24/RF24.h | 6 +++++- drivers/RF24/RF24registers.h | 6 ++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index 519dc2492..b3d8924a0 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -432,6 +432,13 @@ LOCAL void RF24_disableConstantCarrierWave(void) RF24_setRFSetup(RF24_RF_SETUP); } +LOCAL bool RF24_getReceivedPowerDetector(void) +{ + // nRF24L01+ only. nRF24L01 contains a carrier detect function (same register & bit) which works + // slightly different and takes at least 128us to become active. + return (RF24_readByteRegister(RF24_REG_RPD) & _BV(RF24_RPD)) != 0; +} + #if defined(MY_RX_MESSAGE_BUFFER_FEATURE) LOCAL void RF24_irqHandler(void) { diff --git a/drivers/RF24/RF24.h b/drivers/RF24/RF24.h index 20f008b5e..9780a576f 100644 --- a/drivers/RF24/RF24.h +++ b/drivers/RF24/RF24.h @@ -400,7 +400,11 @@ LOCAL void RF24_enableConstantCarrierWave(void) __attribute__((unused)); * @brief Stop generating a constant carrier wave (for testing only). */ LOCAL void RF24_disableConstantCarrierWave(void) __attribute__((unused)); - +/** +* @brief Retrieve latched RPD power level, in receive mode (for testing, nRF24L01+ only). +* @return True when power level >-64dBm for more than 40us. +*/ +LOCAL bool RF24_getReceivedPowerDetector(void) __attribute__((unused)); #if defined(MY_RX_MESSAGE_BUFFER_FEATURE) /** diff --git a/drivers/RF24/RF24registers.h b/drivers/RF24/RF24registers.h index 1c2911cd8..c2cf5942c 100644 --- a/drivers/RF24/RF24registers.h +++ b/drivers/RF24/RF24registers.h @@ -56,7 +56,8 @@ #define RF24_REG_RF_SETUP (0x06) #define RF24_REG_STATUS (0x07) #define RF24_REG_OBSERVE_TX (0x08) -#define RF24_REG_CD (0x09) +#define RF24_REG_RPD (0x09) // nRF24L01+ +#define RF24_REG_CD (RF24_REG_RPD) // nRF24L01 #define RF24_REG_RX_ADDR_P0 (0x0A) #define RF24_REG_RX_ADDR_P1 (0x0B) #define RF24_REG_RX_ADDR_P2 (0x0C) @@ -79,7 +80,6 @@ // instructions #define RF24_CMD_READ_REGISTER (0x00) -#define RF24_CMD_RPD (0x09) #define RF24_CMD_WRITE_REGISTER (0x20) #define RF24_CMD_ACTIVATE (0x50) #define RF24_CMD_READ_RX_PL_WID (0x60) @@ -144,6 +144,8 @@ #define RF24_TX_EMPTY (4) #define RF24_RX_FULL (1) #define RF24_RX_EMPTY (0) +#define RF24_RPD (0) // nRF24L01+ +#define RF24_CD (RF24_RPD) // nRF24L01 // features #define RF24_EN_DPL (2) From 7214b0d4577ba9bee4f1e458651ff1335fe6651b Mon Sep 17 00:00:00 2001 From: tekka Date: Thu, 30 Aug 2018 20:14:29 +0100 Subject: [PATCH 17/31] RF24: Add delay after power-up (#1193) --- drivers/RF24/RF24.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index b3d8924a0..805480f2e 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -295,6 +295,8 @@ LOCAL void RF24_standBy(void) RF24_DEBUG(PSTR("RF24:SBY\n")); // put radio to standby RF24_ce(LOW); RF24_setRFConfiguration(RF24_CONFIGURATION | _BV(RF24_PWR_UP)); + // There must be a delay of up to 4.5ms after the nRF24L01+ leaves power down mode before the CE is set high. + delayMicroseconds(4500); } @@ -421,7 +423,6 @@ LOCAL int16_t RF24_getSendingRSSI(void) LOCAL void RF24_enableConstantCarrierWave(void) { RF24_standBy(); - delayMicroseconds(1500); RF24_setRFSetup(RF24_RF_SETUP | _BV(RF24_CONT_WAVE) | _BV(RF24_PLL_LOCK) ); RF24_ce(HIGH); } @@ -522,10 +523,8 @@ LOCAL bool RF24_initialize(void) // attach interrupt attachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN), RF24_irqHandler, FALLING); #endif - // CRC and power up - RF24_setRFConfiguration(RF24_CONFIGURATION | _BV(RF24_PWR_UP)) ; - // settle >2ms - delay(5); + // power up and standby + RF24_standBy(); // set address width RF24_setAddressWidth(MY_RF24_ADDR_WIDTH); // auto retransmit delay 1500us, auto retransmit count 15 From 0b51d5c1476086f5dcc7ac27e5087a7a69580123 Mon Sep 17 00:00:00 2001 From: tekka Date: Fri, 31 Aug 2018 10:17:02 +0100 Subject: [PATCH 18/31] Update Jenkins to use Arduino 1.8.6 (#1199) --- .ci/arduino.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/arduino.groovy b/.ci/arduino.groovy index 4409a342d..8634263a0 100644 --- a/.ci/arduino.groovy +++ b/.ci/arduino.groovy @@ -1,6 +1,6 @@ #!groovy def buildArduino(config, String buildFlags, String sketch, String key) { - def root = '/opt/arduino-1.8.5/' + def root = '/opt/arduino-1.8.6/' if (config.nightly_arduino_ide) { root = '/opt/arduino-nightly/' From 1c33609556e10b15079d8d7452cd1355457bb147 Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Tue, 4 Sep 2018 03:59:32 -0300 Subject: [PATCH 19/31] Fix SPIDEV on Armbian Stretch (#1200) Fix #1195 --- configure | 28 +++---- drivers/BCM/BCM.cpp | 34 +++++---- drivers/BCM/BCM.h | 12 +++ drivers/BCM/SPIBCM.cpp | 3 + drivers/Linux/SPIDEV.cpp | 125 ++++++++++++++++++++++++++------ drivers/Linux/SPIDEV.h | 3 +- drivers/RF24/RF24.cpp | 10 ++- drivers/RFM69/new/RFM69_new.cpp | 12 ++- drivers/RFM95/RFM95.cpp | 10 ++- 9 files changed, 177 insertions(+), 60 deletions(-) diff --git a/configure b/configure index 65b47573f..a4e68aaba 100755 --- a/configure +++ b/configure @@ -193,25 +193,25 @@ function detect_machine { soc="BCM2837" fi ;; - sun4i|Sun4iw1p1) + *sun4i*|*Sun4iw1p1*) soc="A10" ;; - sun5i|Sun4iw2p1) + *sun5i*|*Sun4iw2p1*) soc="A13" ;; - Sun4iw2p2) + *Sun4iw2p2*) soc="A12" ;; - Sun4iw2p3) + *Sun4iw2p3*) soc="A10s" ;; - sun6i|Sun8iw1p1) + *sun6i*|*Sun8iw1p1*) soc="A31" ;; - Sun8iw1p2) + *Sun8iw1p2*) soc="A31s" ;; - sun7i|Sun8iw2p1) + *sun7i*|*Sun8iw2p1*) soc="A20" if [[ $machine == "Banana Pi"* ]]; then tp="BananaPi" @@ -219,25 +219,25 @@ function detect_machine { tp="BananaPro" fi ;; - sun8i|Sun8iw7p1) + *sun8i*|*Sun8iw7p1*) soc="H3" ;; - Sun8iw3p1) + *Sun8iw3p1*) soc="A23" ;; - Sun8iw5p1) + *Sun8iw5p1*) soc="A33" ;; - Sun8iw6p1) + *Sun8iw6p1*) soc="A83t" ;; - sun9i|Sun9iw1p1) + *sun9i*|*Sun9iw1p1*) soc="A80" ;; - Sun9iw1p2) + *Sun9iw1p2*) soc="A80t" ;; - sun50i|Sun50iw1p1) + *sun50i*|*Sun50iw1p1*) soc="A64" ;; 'Generic AM33XX'*) diff --git a/drivers/BCM/BCM.cpp b/drivers/BCM/BCM.cpp index 3f09c9934..ce5ba1216 100644 --- a/drivers/BCM/BCM.cpp +++ b/drivers/BCM/BCM.cpp @@ -34,14 +34,21 @@ BCMClass::~BCMClass() } } +uint8_t BCMClass::init() +{ + if (!bcm2835_init()) { + logError("Failed to initialized bcm2835.\n"); + exit(1); + } + initialized = 1; + + return 1; +} + void BCMClass::pinMode(uint8_t gpio, uint8_t mode) { if (!initialized) { - if (!bcm2835_init()) { - logError("Failed to initialized bcm2835.\n"); - exit(1); - } - initialized = 1; + init(); } bcm2835_gpio_fsel(gpio, mode); @@ -50,11 +57,7 @@ void BCMClass::pinMode(uint8_t gpio, uint8_t mode) void BCMClass::digitalWrite(uint8_t gpio, uint8_t value) { if (!initialized) { - if (!bcm2835_init()) { - logError("Failed to initialized bcm2835.\n"); - exit(1); - } - initialized = 1; + init(); } bcm2835_gpio_write(gpio, value); @@ -65,12 +68,13 @@ void BCMClass::digitalWrite(uint8_t gpio, uint8_t value) uint8_t BCMClass::digitalRead(uint8_t gpio) { if (!initialized) { - if (!bcm2835_init()) { - logError("Failed to initialized bcm2835.\n"); - exit(1); - } - initialized = 1; + init(); } return bcm2835_gpio_lev(gpio); } + +uint8_t BCMClass::isInitialized() +{ + return initialized; +} diff --git a/drivers/BCM/BCM.h b/drivers/BCM/BCM.h index c40e17cd6..9c0bd8a35 100644 --- a/drivers/BCM/BCM.h +++ b/drivers/BCM/BCM.h @@ -37,6 +37,12 @@ class BCMClass * @brief BCMClass destructor. */ ~BCMClass(); + /** + * @brief Initializes BCM. + * + * @return 1 if successful, else exits the program. + */ + uint8_t init(); /** * @brief Configures the specified pin to behave either as an input or an output. * @@ -65,6 +71,12 @@ class BCMClass * @return The GPIO pin number. */ inline uint8_t digitalPinToInterrupt(uint8_t gpio); + /** + * @brief Checks if SPI was initialized. + * + * @return 1 if initialized, else 0. + */ + uint8_t isInitialized(); private: static uint8_t initialized; //!< @brief BCM initialized flag. diff --git a/drivers/BCM/SPIBCM.cpp b/drivers/BCM/SPIBCM.cpp index 6a29783c5..c3ea6a5a5 100644 --- a/drivers/BCM/SPIBCM.cpp +++ b/drivers/BCM/SPIBCM.cpp @@ -34,6 +34,9 @@ uint8_t SPIBCMClass::initialized = 0; void SPIBCMClass::begin() { if (!initialized) { + if (!BCM.isInitialized()) { + BCM.init(); + } if (!bcm2835_spi_begin()) { logError("You need root privilege to use SPI.\n"); exit(1); diff --git a/drivers/Linux/SPIDEV.cpp b/drivers/Linux/SPIDEV.cpp index 0c65e24fa..abc3bf29e 100644 --- a/drivers/Linux/SPIDEV.cpp +++ b/drivers/Linux/SPIDEV.cpp @@ -37,9 +37,10 @@ SPIDEVClass SPIDEV = SPIDEVClass(); uint8_t SPIDEVClass::initialized = 0; int SPIDEVClass::fd = -1; std::string SPIDEVClass::device = SPI_SPIDEV_DEVICE; +uint8_t SPIDEVClass::mode = SPI_MODE0; uint32_t SPIDEVClass::speed = SPI_CLOCK_BASE; -uint32_t SPIDEVClass::speed_temp = SPI_CLOCK_BASE; -struct spi_ioc_transfer SPIDEVClass::tr = {0,0,0,0,0,8,1,0,0,0}; // 8 bits_per_word, 1 cs_change +uint8_t SPIDEVClass::bit_order = MSBFIRST; +struct spi_ioc_transfer SPIDEVClass::tr = {0,0,0,0,0,8,0,0,0,0}; // 8 bits_per_word, 0 cs_change SPIDEVClass::SPIDEVClass() { @@ -78,15 +79,21 @@ void SPIDEVClass::end() } } -void SPIDEVClass::setBitOrder(uint8_t bit_order) +void SPIDEVClass::setBitOrder(uint8_t border) { pthread_mutex_lock(&spiMutex); /* * bit order */ - int lsb_setting = bit_order; - int ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb_setting); + bit_order = border; + int ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &bit_order); + if (ret == -1) { + logError("Can't set SPI bit order.\n"); + abort(); + } + + ret = ioctl(fd, SPI_IOC_RD_LSB_FIRST, &bit_order); if (ret == -1) { logError("Can't set SPI bit order.\n"); abort(); @@ -102,7 +109,14 @@ void SPIDEVClass::setDataMode(uint8_t data_mode) /* * spi mode */ - int ret = ioctl(fd, SPI_IOC_WR_MODE, &data_mode); + mode = data_mode; + int ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); + if (ret == -1) { + logError("Can't set SPI mode.\n"); + abort(); + } + + ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); if (ret == -1) { logError("Can't set SPI mode.\n"); abort(); @@ -113,6 +127,10 @@ void SPIDEVClass::setDataMode(uint8_t data_mode) void SPIDEVClass::setClockDivider(uint16_t divider) { + if (divider == 0) { + return; + } + pthread_mutex_lock(&spiMutex); /* @@ -125,6 +143,12 @@ void SPIDEVClass::setClockDivider(uint16_t divider) abort(); } + ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); + if (ret == -1) { + logError("Can't set SPI max speed hz.\n"); + abort(); + } + pthread_mutex_unlock(&spiMutex); } @@ -195,29 +219,63 @@ void SPIDEVClass::beginTransaction(SPISettings settings) /* * spi mode */ - ret = ioctl(fd, SPI_IOC_WR_MODE, &settings.dmode); - if (ret == -1) { - logError("Can't set spi mode.\n"); - abort(); + if (settings.dmode != mode) { + mode = settings.dmode; + + ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); + if (ret == -1) { + logError("Can't set spi mode.\n"); + abort(); + } + + ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); + if (ret == -1) { + logError("Can't set spi mode.\n"); + abort(); + } } - // Save the current speed - speed_temp = speed; - speed = settings.clock; + /* + * speed + */ + if (settings.clock != speed) { + speed = settings.clock; + + ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); + if (ret == -1) { + logError("Can't set SPI max speed hz.\n"); + abort(); + } + + ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); + if (ret == -1) { + logError("Can't set SPI max speed hz.\n"); + abort(); + } + } /* * bit order */ - ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &settings.border); - if (ret == -1) { - logError("Can't set bits per word.\n"); - abort(); + if (settings.border != bit_order) { + bit_order = settings.border; + + ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &bit_order); + if (ret == -1) { + logError("Can't set SPI bit order.\n"); + abort(); + } + + ret = ioctl(fd, SPI_IOC_RD_LSB_FIRST, &bit_order); + if (ret == -1) { + logError("Can't set SPI bit order.\n"); + abort(); + } } } void SPIDEVClass::endTransaction() { - speed = speed_temp; pthread_mutex_unlock(&spiMutex); } @@ -248,38 +306,59 @@ void SPIDEVClass::init() /* * spi mode */ - uint8_t mode = SPI_MODE0; int ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); if (ret == -1) { logError("Can't set SPI mode.\n"); abort(); } + ret = ioctl(fd, SPI_IOC_RD_MODE, &mode); + if (ret == -1) { + logError("Can't set SPI mode.\n"); + abort(); + } + /* * bits per word */ - uint8_t bits = 0; // 0 corresponds to 8 bits per word + uint8_t bits = 8; // 8 bits per word ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (ret == -1) { logError("Can't set SPI bits per word.\n"); abort(); } + ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); + if (ret == -1) { + logError("Can't set SPI bits per word.\n"); + abort(); + } + /* * max speed hz */ - speed = SPI_CLOCK_BASE; ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); if (ret == -1) { logError("Can't set SPI max speed hz.\n"); abort(); } + ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed); + if (ret == -1) { + logError("Can't set SPI max speed hz.\n"); + abort(); + } + /* * bit order */ - int lsb_setting = MSBFIRST; - ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &lsb_setting); + ret = ioctl(fd, SPI_IOC_WR_LSB_FIRST, &bit_order); + if (ret == -1) { + logError("Can't set SPI bit order.\n"); + abort(); + } + + ret = ioctl(fd, SPI_IOC_RD_LSB_FIRST, &bit_order); if (ret == -1) { logError("Can't set SPI bit order.\n"); abort(); diff --git a/drivers/Linux/SPIDEV.h b/drivers/Linux/SPIDEV.h index adc69a9fc..683f65ab9 100644 --- a/drivers/Linux/SPIDEV.h +++ b/drivers/Linux/SPIDEV.h @@ -199,8 +199,9 @@ class SPIDEVClass static uint8_t initialized; //!< @brief SPI initialized flag. static int fd; //!< @brief SPI device file descriptor. static std::string device; //!< @brief Default SPI device. + static uint8_t mode; //!< @brief SPI mode. static uint32_t speed; //!< @brief SPI speed. - static uint32_t speed_temp; //!< @brief Used when doing transaction. + static uint8_t bit_order; //!< @brief SPI bit order. static struct spi_ioc_transfer tr; //!< @brief Auxiliar struct for data transfer. static void init(); diff --git a/drivers/RF24/RF24.cpp b/drivers/RF24/RF24.cpp index 805480f2e..b6165293b 100644 --- a/drivers/RF24/RF24.cpp +++ b/drivers/RF24/RF24.cpp @@ -36,7 +36,7 @@ LOCAL uint8_t RF24_NODE_ADDRESS = RF24_BROADCAST_ADDRESS; LOCAL RF24_receiveCallbackType RF24_receiveCallback = NULL; #endif -#if defined(LINUX_SPI_BCM) +#if defined(__linux__) uint8_t RF24_spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes) uint8_t RF24_spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command) @@ -44,7 +44,11 @@ uint8_t RF24_spi_txbuff[32+1] LOCAL void RF24_csn(const bool level) { +#if defined(__linux__) + (void)level; +#else hwDigitalWrite(MY_RF24_CS_PIN, level); +#endif } LOCAL void RF24_ce(const bool level) @@ -65,7 +69,7 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_t RF24_csn(LOW); // timing delayMicroseconds(10); -#ifdef LINUX_SPI_BCM +#ifdef __linux__ uint8_t *prx = RF24_spi_rxbuff; uint8_t *ptx = RF24_spi_txbuff; uint8_t size = len + 1; // Add register value to transmit buffer @@ -509,7 +513,9 @@ LOCAL bool RF24_initialize(void) hwPinMode(MY_RF24_IRQ_PIN,INPUT); #endif hwPinMode(MY_RF24_CE_PIN, OUTPUT); +#if !defined(__linux__) hwPinMode(MY_RF24_CS_PIN, OUTPUT); +#endif RF24_ce(LOW); RF24_csn(HIGH); diff --git a/drivers/RFM69/new/RFM69_new.cpp b/drivers/RFM69/new/RFM69_new.cpp index 26641b7f2..797328dd2 100644 --- a/drivers/RFM69/new/RFM69_new.cpp +++ b/drivers/RFM69/new/RFM69_new.cpp @@ -44,7 +44,7 @@ rfm69_internal_t RFM69; //!< internal variables volatile uint8_t RFM69_irq; //!< rfm69 irq flag -#if defined(LINUX_SPI_BCM) +#if defined(__linux__) // SPI RX and TX buffers (max packet len + 1 byte for the command) uint8_t RFM69_spi_rxbuff[RFM69_MAX_PACKET_LEN + 1]; uint8_t RFM69_spi_txbuff[RFM69_MAX_PACKET_LEN + 1]; @@ -52,7 +52,11 @@ uint8_t RFM69_spi_txbuff[RFM69_MAX_PACKET_LEN + 1]; LOCAL void RFM69_csn(const bool level) { +#if defined(__linux__) + (void)level; +#else hwDigitalWrite(MY_RFM69_CS_PIN, level); +#endif } LOCAL void RFM69_prepareSPITransaction(void) @@ -79,7 +83,7 @@ LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_ RFM69_prepareSPITransaction(); RFM69_csn(LOW); -#if defined(LINUX_SPI_BCM) +#if defined(__linux__) uint8_t *prx = RFM69_spi_rxbuff; uint8_t *ptx = RFM69_spi_txbuff; uint8_t size = len + 1; // Add register value to transmit buffer @@ -203,8 +207,10 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz) RFM69.ATCtargetRSSI = RFM69_RSSItoInternal(MY_RFM69_ATC_TARGET_RSSI_DBM); // SPI init +#if !defined(__linux__) hwDigitalWrite(MY_RFM69_CS_PIN, HIGH); hwPinMode(MY_RFM69_CS_PIN, OUTPUT); +#endif RFM69_SPI.begin(); (void)RFM69_setRadioMode(RFM69_RADIO_MODE_STDBY); // set configuration, encryption is disabled @@ -251,7 +257,7 @@ LOCAL void RFM69_interruptHandling(void) if (regIrqFlags2 & RFM69_IRQFLAGS2_FIFOLEVEL) { RFM69_prepareSPITransaction(); RFM69_csn(LOW); -#if defined(LINUX_SPI_BCM) +#if defined(__linux__) char data[RFM69_MAX_PACKET_LEN + 1]; // max packet len + 1 byte for the command data[0] = RFM69_REG_FIFO & RFM69_READ_REGISTER; RFM69_SPI.transfern(data, 3); diff --git a/drivers/RFM95/RFM95.cpp b/drivers/RFM95/RFM95.cpp index de3d325b4..8111a23bc 100644 --- a/drivers/RFM95/RFM95.cpp +++ b/drivers/RFM95/RFM95.cpp @@ -38,7 +38,7 @@ rfm95_internal_t RFM95; //!< internal variables volatile uint8_t RFM95_irq; // Date: Tue, 4 Sep 2018 08:00:38 +0100 Subject: [PATCH 20/31] Allow flash strings in present() to save RAM (#1198) --- core/MySensorsCore.cpp | 13 ++++++++++++- core/MySensorsCore.h | 9 ++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 8e175711d..fff479f48 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -355,9 +355,20 @@ bool present(const uint8_t childSensorId, const uint8_t sensorType, const char * const bool ack) { return _sendRoute(build(_msgTmp, GATEWAY_ADDRESS, childSensorId, C_PRESENTATION, sensorType, - ack).set(childSensorId==NODE_SENSOR_ID?MYSENSORS_LIBRARY_VERSION:description)); + ack).set(childSensorId == NODE_SENSOR_ID ? MYSENSORS_LIBRARY_VERSION : description)); } +#if !defined(__linux__) +bool present(const uint8_t childSensorId, const uint8_t sensorType, + const __FlashStringHelper *description, + const bool ack) +{ + return _sendRoute(build(_msgTmp, GATEWAY_ADDRESS, childSensorId, C_PRESENTATION, sensorType, + ack).set(childSensorId == NODE_SENSOR_ID ? F(" MYSENSORS_LIBRARY_VERSION "): description)); +} +#endif + + bool sendSketchInfo(const char *name, const char *version, const bool ack) { bool result = true; diff --git a/core/MySensorsCore.h b/core/MySensorsCore.h index 31e922561..c757e63db 100644 --- a/core/MySensorsCore.h +++ b/core/MySensorsCore.h @@ -137,10 +137,14 @@ void presentNode(void); */ bool present(const uint8_t sensorId, const uint8_t sensorType, const char *description="", const bool ack = false); - +#if !defined(__linux__) +bool present(const uint8_t childSensorId, const uint8_t sensorType, + const __FlashStringHelper *description, + const bool ack = false); +#endif /** * Sends sketch meta information to the gateway. Not mandatory but a nice thing to do. - * @param name String containing a short Sketch name or NULL if not applicable + * @param name String containing a short Sketch name or NULL if not applicable * @param version String containing a short Sketch version or NULL if not applicable * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack. * @return true Returns true if message reached the first stop on its way to destination. @@ -153,7 +157,6 @@ bool sendSketchInfo(const __FlashStringHelper *name, const __FlashStringHelper * /** * Sends a message to gateway or one of the other nodes in the radio network -* * @param msg Message to send * @param ack Set this to true if you want destination node to send ack back to this node. Default is not to request any ack. * @return true Returns true if message reached the first stop on its way to destination. From 5d159a6c57209e9be91834b498d0072d3a1a25d6 Mon Sep 17 00:00:00 2001 From: tekka Date: Wed, 12 Sep 2018 10:27:12 +0100 Subject: [PATCH 21/31] Fix internal message forwarding (#1205) --- core/MyTransport.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index ef7e190dd..ec5244fd9 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -827,7 +827,6 @@ void transportProcessMessage(void) if (_processInternalCoreMessage()) { return; // no further processing required } - return; // other C_INTERNAL messages do not require further processing } else if (command == C_STREAM) { #if defined(MY_OTA_FIRMWARE_FEATURE) if(firmwareOTAUpdateProcess()) { From 5a7f3a4faee19e16233676795f12caa014e85686 Mon Sep 17 00:00:00 2001 From: tekka Date: Sun, 21 Oct 2018 13:10:07 +0200 Subject: [PATCH 22/31] Add GatewayESP32OTA example (#1216) --- .ci/arduino.groovy | 7 ++ examples/GatewayESP32OTA/GatewayESP32OTA.ino | 122 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 examples/GatewayESP32OTA/GatewayESP32OTA.ino diff --git a/.ci/arduino.groovy b/.ci/arduino.groovy index 8634263a0..f151d0f6e 100644 --- a/.ci/arduino.groovy +++ b/.ci/arduino.groovy @@ -50,6 +50,7 @@ def buildMySensorsMicro(config, sketches, String key) { sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' && + sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') { buildArduino(config, fqbn, sketches[sketch].path, key+'_MySensorsMicro') @@ -85,6 +86,7 @@ def buildMySensorsGw(config, sketches, String key) { sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' && + sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewaySerialRS485/GatewaySerialRS485.ino' && sketches[sketch].path != config.library_root+'examples/MotionSensorRS485/MotionSensorRS485.ino') { @@ -119,6 +121,7 @@ def buildArduinoUno(config, sketches, String key) { sketches[sketch].path != config.library_root+'examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' && + sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') { buildArduino(config, fqbn, sketches[sketch].path, key+'_ArduinoUno') @@ -152,6 +155,7 @@ def buildArduinoMega(config, sketches, String key) { sketches[sketch].path != config.library_root+'examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' && + sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') { buildArduino(config, fqbn, sketches[sketch].path, key+'_ArduinoMega') @@ -185,6 +189,7 @@ def buildSTM32F1(config, sketches, String key) { sketches[sketch].path != config.library_root+'examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' && + sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino') { buildArduino(config, fqbn, sketches[sketch].path, key+'_STM32F1') @@ -222,6 +227,7 @@ def buildESP8266(config, sketches, String key) { sketches[sketch].path != config.library_root+'examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' && + sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/MotionSensorRS485/MotionSensorRS485.ino' && sketches[sketch].path != config.library_root+'examples/SensebenderGatewaySerial/SensebenderGatewaySerial.ino' && @@ -309,6 +315,7 @@ def buildnRF5(config, sketches, String key) { sketches[sketch].path != config.library_root+'examples/GatewayGSMMQTTClient/GatewayGSMMQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP8266OTA/GatewayESP8266OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32/GatewayESP32.ino' && + sketches[sketch].path != config.library_root+'examples/GatewayESP32OTA/GatewayESP32OTA.ino' && sketches[sketch].path != config.library_root+'examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino' && sketches[sketch].path != config.library_root+'examples/GatewaySerialRS485/GatewaySerialRS485.ino' && sketches[sketch].path != config.library_root+'examples/GatewayW5100/GatewayW5100.ino' && diff --git a/examples/GatewayESP32OTA/GatewayESP32OTA.ino b/examples/GatewayESP32OTA/GatewayESP32OTA.ino new file mode 100644 index 000000000..5944b7599 --- /dev/null +++ b/examples/GatewayESP32OTA/GatewayESP32OTA.ino @@ -0,0 +1,122 @@ +/** + The MySensors Arduino library handles the wireless radio link and protocol + between your home built sensors/actuators and HA controller of choice. + The sensors forms a self healing radio network with optional repeaters. Each + repeater and gateway builds a routing tables in EEPROM which keeps track of the + network topology allowing messages to be routed to nodes. + + Created by Henrik Ekblad + Copyright (C) 2013-2018 Sensnology AB + Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + + Documentation: http://www.mysensors.org + Support Forum: http://forum.mysensors.org + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + ******************************* + + REVISION HISTORY + Version 1.0 - tekka + Contribution by Berk + + DESCRIPTION + The ESP32 gateway sends data received from sensors to the WiFi link. + The gateway also accepts input on ethernet interface, which is then sent out to the radio network. + + Make sure to fill in your ssid and WiFi password below. +*/ + +// Enable debug prints to serial monitor +#define MY_DEBUG + +// Enables and select radio type (if attached) +#define MY_RADIO_RF24 +//#define MY_RADIO_RFM69 +//#define MY_RADIO_RFM95 + +#define MY_GATEWAY_ESP32 + +#define MY_WIFI_SSID "MySSID" +#define MY_WIFI_PASSWORD "MyVerySecretPassword" + +// Set the hostname for the WiFi Client. This is the hostname +// it will pass to the DHCP server if not static. +#define MY_HOSTNAME "ESP32_GW" + +// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) +//#define MY_IP_ADDRESS 192,168,1,100 + +// If using static ip you can define Gateway and Subnet address as well +//#define MY_IP_GATEWAY_ADDRESS 192,168,1,1 +//#define MY_IP_SUBNET_ADDRESS 255,255,255,0 + +// The port to keep open on node server mode +#define MY_PORT 5003 + +// How many clients should be able to connect to this gateway (default 1) +#define MY_GATEWAY_MAX_CLIENTS 2// Set blinking period + + +// Advanced Gateway Options +//#define MY_DEFAULT_LED_BLINK_PERIOD 50 + +// Flash leds on rx/tx/err +// Led pins used if blinking feature is enabled above +//#define MY_DEFAULT_ERR_LED_PIN 32 // Transfer data error led pin +//#define MY_DEFAULT_RX_LED_PIN 25 // Receive Data led pin +//#define MY_DEFAULT_TX_LED_PIN 27 // Transmit Data led pin + +//#define MY_WITH_LEDS_BLINKING_INVERSE // At the time of Error, Receive, Transmit the pin is at a high level + + + +#include +#include + +void setup() +{ + // Setup locally attached sensors + ArduinoOTA.onStart([]() { + Serial.println("Start updating"); + }); + ArduinoOTA.onEnd([]() { + Serial.println("\nEnd updating"); + }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100))); + }); + ArduinoOTA.onError([](ota_error_t error) { + Serial.printf("Error[%u]: ", error); + if (error == OTA_AUTH_ERROR) { + Serial.println("Auth Failed"); + } else if (error == OTA_BEGIN_ERROR) { + Serial.println("Begin Failed"); + } else if (error == OTA_CONNECT_ERROR) { + Serial.println("Connect Failed"); + } else if (error == OTA_RECEIVE_ERROR) { + Serial.println("Receive Failed"); + } else if (error == OTA_END_ERROR) { + Serial.println("End Failed"); + } + }); + ArduinoOTA.begin(); + + + + // Setup locally attached sensors +} + +void presentation() +{ + // Present locally attached sensors here +} + +void loop() +{ + // Send locally attached sensors data here + + ArduinoOTA.handle(); +} \ No newline at end of file From b6ab7aaf03354bf273d3202396348b52931bc1c9 Mon Sep 17 00:00:00 2001 From: tekka Date: Sun, 21 Oct 2018 13:10:21 +0200 Subject: [PATCH 23/31] Jenkins:Update Arduino 1.8.7 (#1215) --- .ci/arduino.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/arduino.groovy b/.ci/arduino.groovy index f151d0f6e..1d372247f 100644 --- a/.ci/arduino.groovy +++ b/.ci/arduino.groovy @@ -1,6 +1,6 @@ #!groovy def buildArduino(config, String buildFlags, String sketch, String key) { - def root = '/opt/arduino-1.8.6/' + def root = '/opt/arduino-1.8.7/' if (config.nightly_arduino_ide) { root = '/opt/arduino-nightly/' From 8e8f44b40252e9d29ca57926842a7b8950b31a80 Mon Sep 17 00:00:00 2001 From: tekka Date: Sun, 21 Oct 2018 16:55:24 +0200 Subject: [PATCH 24/31] Code updates & harmonization (#1201) --- MyASM.S | 9 +- MyConfig.h | 1 + MySensors.h | 18 +- core/MyEepromAddresses.h | 4 +- core/MyMessage.h | 36 +- core/MySensorsCore.cpp | 10 +- core/MyTransport.cpp | 10 +- core/MyTransport.h | 4 +- core/Version.h | 4 +- drivers/AltSoftSerial/AltSoftSerial.cpp | 102 ++- drivers/AltSoftSerial/AltSoftSerial.h | 32 +- drivers/AltSoftSerial/README.md | 2 +- .../config/AltSoftSerial_Boards.h | 19 +- .../config/AltSoftSerial_Timers.h | 17 +- drivers/AltSoftSerial/config/known_boards.h | 103 --- drivers/AltSoftSerial/config/known_timers.h | 106 --- drivers/AltSoftSerial/docs/issue_template.md | 64 ++ .../examples/{Test/Test.pde => Echo/Echo.ino} | 2 + .../examples/ReceiveTest/ReceiveTest.ino | 56 ++ .../ShowConfiguration/ShowConfiguration.ino | 97 +++ drivers/NVM/Flash.h | 2 +- drivers/SPIFlash/License.txt | 674 ++++++++++++++++++ drivers/SPIFlash/README.md | 32 + drivers/SPIFlash/SPIFlash.cpp | 12 +- drivers/SPIFlash/SPIFlash.h | 2 + .../SPIFlash_ReadWrite/SPIFlash_ReadWrite.ino | 127 ++++ drivers/SPIFlash/keywords.txt | 18 + drivers/extEEPROM/ReadMe.md | 136 ++-- .../eepromReadWrite/eepromReadWrite.ino | 209 ++++++ .../examples/eepromTest/eepromTest.ino | 4 +- .../eepromTest_Wire1/eepromTest_Wire1.ino | 233 ++++++ drivers/extEEPROM/extEEPROM.cpp | 74 +- drivers/extEEPROM/extEEPROM.h | 25 +- drivers/extEEPROM/library.properties | 10 - hal/architecture/AVR/MyHwAVR.cpp | 27 +- hal/architecture/AVR/MyHwAVR.h | 4 + .../AVR/drivers}/DigitalIO/DigitalIO.h | 0 .../AVR/drivers}/DigitalIO/DigitalPin.h | 0 .../AVR/drivers}/DigitalIO/I2cConstants.h | 0 .../AVR/drivers}/DigitalIO/PinIO.cpp | 0 .../AVR/drivers}/DigitalIO/PinIO.h | 0 .../AVR/drivers}/DigitalIO/SoftI2cMaster.cpp | 0 .../AVR/drivers}/DigitalIO/SoftI2cMaster.h | 0 .../AVR/drivers}/DigitalIO/SoftSPI.h | 0 .../AVR/drivers}/DigitalIO/attic/ADS7818.h | 0 .../AVR/drivers}/DigitalIO/attic/MCP320X.h | 0 .../AVR/drivers}/DigitalIO/attic/MCP355X.h | 0 .../DigitalPinBlink/DigitalPinBlink.ino | 0 .../DigitalPinConfigToggle.ino | 0 .../DigitalPinReadWrite.ino | 0 .../DigitalPinShiftOut/DigitalPinShiftOut.ino | 0 .../examples/PinIOBegin/PinIOBegin.ino | 0 .../PinIOConfigToggle/PinIOConfigToggle.ino | 0 .../PinIOReadWrite/PinIOReadWrite.ino | 0 .../examples/ScanI2cBus/ScanI2cBus.ino | 0 .../SoftDS1307Utility/SoftDS1307Utility.ino | 0 .../examples/testArduino/testArduino.ino | 0 .../testDigitalPin/testDigitalPin.ino | 0 .../testFastDigital/testFastDigital.ino | 0 .../examples/testPinIO/testPinIO.ino | 0 .../examples/testSoftSPI/testSoftSPI.ino | 0 .../DigitalWriteFast/digitalWriteFast.h | 0 hal/architecture/ESP32/MyHwESP32.cpp | 27 +- hal/architecture/ESP32/MyHwESP32.h | 6 + hal/architecture/ESP8266/MyHwESP8266.cpp | 29 +- hal/architecture/ESP8266/MyHwESP8266.h | 4 + hal/architecture/Linux/MyHwLinuxGeneric.cpp | 5 + hal/architecture/{MyHw.h => MyHwHAL.h} | 14 +- hal/architecture/NRF5/MyHwNRF5.cpp | 18 +- hal/architecture/NRF5/MyHwNRF5.h | 17 +- .../architecture/NRF5/drivers}/Flash.cpp | 0 .../NRF5/drivers}/nrf5_wiring_constants.h | 0 .../NRF5/drivers}/nrf5_wiring_digital.c | 0 hal/architecture/NRF5/drivers/nrf_temp.h | 78 ++ .../architecture/NRF5/drivers}/wdt.h | 0 hal/architecture/SAMD/MyHwSAMD.cpp | 67 +- hal/architecture/SAMD/MyHwSAMD.h | 19 +- hal/architecture/STM32F1/MyHwSTM32F1.cpp | 33 +- hal/architecture/STM32F1/MyHwSTM32F1.h | 12 +- hal/architecture/Teensy3/MyHwTeensy3.cpp | 18 +- hal/architecture/Teensy3/MyHwTeensy3.h | 4 + .../NRF5_ESB/MyTransportNRF5_ESB.cpp | 4 +- .../transport/NRF5_ESB/driver}/Radio.cpp | 2 +- .../transport/NRF5_ESB/driver}/Radio.h | 1 - .../transport/NRF5_ESB/driver}/Radio_ESB.cpp | 0 .../transport/NRF5_ESB/driver}/Radio_ESB.h | 0 hal/transport/RF24/MyTransportRF24.cpp | 2 +- .../transport/RF24/driver}/RF24.cpp | 0 .../RF24 => hal/transport/RF24/driver}/RF24.h | 0 .../transport/RF24/driver}/RF24registers.h | 0 hal/transport/RFM69/MyTransportRFM69.cpp | 4 +- .../transport/RFM69/driver}/new/RFM69_new.cpp | 2 +- .../transport/RFM69/driver}/new/RFM69_new.h | 0 .../RFM69/driver}/new/RFM69registers_new.h | 0 .../transport/RFM69/driver}/old/RFM69_old.cpp | 2 +- .../transport/RFM69/driver}/old/RFM69_old.h | 0 .../RFM69/driver}/old/RFM69registers_old.h | 0 hal/transport/RFM95/MyTransportRFM95.cpp | 18 +- .../transport/RFM95/driver}/RFM95.cpp | 0 .../transport/RFM95/driver}/RFM95.h | 0 .../transport/RFM95/driver}/RFM95registers.h | 0 101 files changed, 2114 insertions(+), 557 deletions(-) delete mode 100644 drivers/AltSoftSerial/config/known_boards.h delete mode 100644 drivers/AltSoftSerial/config/known_timers.h create mode 100644 drivers/AltSoftSerial/docs/issue_template.md rename drivers/AltSoftSerial/examples/{Test/Test.pde => Echo/Echo.ino} (95%) create mode 100644 drivers/AltSoftSerial/examples/ReceiveTest/ReceiveTest.ino create mode 100644 drivers/AltSoftSerial/examples/ShowConfiguration/ShowConfiguration.ino create mode 100644 drivers/SPIFlash/License.txt create mode 100644 drivers/SPIFlash/README.md create mode 100644 drivers/SPIFlash/examples/SPIFlash_ReadWrite/SPIFlash_ReadWrite.ino create mode 100644 drivers/SPIFlash/keywords.txt create mode 100644 drivers/extEEPROM/examples/eepromReadWrite/eepromReadWrite.ino create mode 100644 drivers/extEEPROM/examples/eepromTest_Wire1/eepromTest_Wire1.ino delete mode 100644 drivers/extEEPROM/library.properties rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/DigitalIO.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/DigitalPin.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/I2cConstants.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/PinIO.cpp (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/PinIO.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/SoftI2cMaster.cpp (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/SoftI2cMaster.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/SoftSPI.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/attic/ADS7818.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/attic/MCP320X.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/attic/MCP355X.h (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/PinIOBegin/PinIOBegin.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/testArduino/testArduino.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/testDigitalPin/testDigitalPin.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/testFastDigital/testFastDigital.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/testPinIO/testPinIO.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalIO/examples/testSoftSPI/testSoftSPI.ino (100%) rename {drivers/AVR => hal/architecture/AVR/drivers}/DigitalWriteFast/digitalWriteFast.h (100%) rename hal/architecture/{MyHw.h => MyHwHAL.h} (95%) rename {drivers/NRF5 => hal/architecture/NRF5/drivers}/Flash.cpp (100%) rename {drivers/NRF5 => hal/architecture/NRF5/drivers}/nrf5_wiring_constants.h (100%) rename {drivers/NRF5 => hal/architecture/NRF5/drivers}/nrf5_wiring_digital.c (100%) create mode 100644 hal/architecture/NRF5/drivers/nrf_temp.h rename {drivers/NRF5 => hal/architecture/NRF5/drivers}/wdt.h (100%) rename {drivers/NRF5 => hal/transport/NRF5_ESB/driver}/Radio.cpp (98%) rename {drivers/NRF5 => hal/transport/NRF5_ESB/driver}/Radio.h (99%) rename {drivers/NRF5 => hal/transport/NRF5_ESB/driver}/Radio_ESB.cpp (100%) rename {drivers/NRF5 => hal/transport/NRF5_ESB/driver}/Radio_ESB.h (100%) rename {drivers/RF24 => hal/transport/RF24/driver}/RF24.cpp (100%) rename {drivers/RF24 => hal/transport/RF24/driver}/RF24.h (100%) rename {drivers/RF24 => hal/transport/RF24/driver}/RF24registers.h (100%) rename {drivers/RFM69 => hal/transport/RFM69/driver}/new/RFM69_new.cpp (99%) rename {drivers/RFM69 => hal/transport/RFM69/driver}/new/RFM69_new.h (100%) rename {drivers/RFM69 => hal/transport/RFM69/driver}/new/RFM69registers_new.h (100%) rename {drivers/RFM69 => hal/transport/RFM69/driver}/old/RFM69_old.cpp (99%) rename {drivers/RFM69 => hal/transport/RFM69/driver}/old/RFM69_old.h (100%) rename {drivers/RFM69 => hal/transport/RFM69/driver}/old/RFM69registers_old.h (100%) rename {drivers/RFM95 => hal/transport/RFM95/driver}/RFM95.cpp (100%) rename {drivers/RFM95 => hal/transport/RFM95/driver}/RFM95.h (100%) rename {drivers/RFM95 => hal/transport/RFM95/driver}/RFM95registers.h (100%) diff --git a/MyASM.S b/MyASM.S index 0189e0ef2..eb8d529cc 100644 --- a/MyASM.S +++ b/MyASM.S @@ -18,7 +18,14 @@ * */ -#if defined(ARDUINO_ARCH_NRF5) +#if defined(ARDUINO_ARCH_SAMD) +/* workaround to prevent compiler error */ + .thumb_func +doNothing: + nop + .size doNothing, .-doNothing + +#elif defined(ARDUINO_ARCH_NRF5) /* workaround to prevent compiler error */ .thumb_func doNothing: diff --git a/MyConfig.h b/MyConfig.h index b118efc4a..e8c820109 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -1641,6 +1641,7 @@ * | @ref MY_SIGNING_SOFT_RANDOMSEED_PIN | Change default software RNG seed pin | "#define" in the top of your sketch | Not supported * | @ref MY_RF24_ENABLE_ENCRYPTION | Enables encryption on RF24 radios | "#define" in the top of your sketch | @verbatim --my-rf24-encryption-enabled @endverbatim * | @ref MY_RFM69_ENABLE_ENCRYPTION | Enables encryption on %RFM69 radios | "#define" in the top of your sketch | @verbatim --my-rfm69-encryption-enabled @endverbatim + * | @ref MY_RFM95_ENABLE_ENCRYPTION | Enables encryption on %RFM95 radios | "#define" in the top of your sketch | @verbatim --my-rfm95-encryption-enabled @endverbatim * | @ref MY_NRF5_ESB_ENABLE_ENCRYPTION | Enables encryption on nRF5 radios | "#define" in the top of your sketch | Not supported * | @ref MY_NODE_LOCK_FEATURE | Enables the node locking feature | "#define" in the top of your sketch | Not supported * | @ref MY_NODE_UNLOCK_PIN | Change default unlock pin | "#define" in the top of your sketch | Not supported diff --git a/MySensors.h b/MySensors.h index b1722a01f..79b865176 100644 --- a/MySensors.h +++ b/MySensors.h @@ -49,7 +49,7 @@ #endif // HARDWARE -#include "hal/architecture/MyHw.h" +#include "hal/architecture/MyHwHAL.h" #include "hal/crypto/MyCryptoHAL.h" #if defined(ARDUINO_ARCH_ESP8266) #include "hal/architecture/ESP8266/MyHwESP8266.cpp" @@ -58,7 +58,7 @@ #include "hal/architecture/ESP32/MyHwESP32.cpp" #include "hal/crypto/ESP32/MyCryptoESP32.cpp" #elif defined(ARDUINO_ARCH_AVR) -#include "drivers/AVR/DigitalWriteFast/digitalWriteFast.h" +#include "hal/architecture/AVR/drivers/DigitalWriteFast/digitalWriteFast.h" #include "hal/architecture/AVR/MyHwAVR.cpp" #include "hal/crypto/AVR/MyCryptoAVR.cpp" #elif defined(ARDUINO_ARCH_SAMD) @@ -338,7 +338,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs #if defined(ARDUINO_ARCH_ESP8266) #error Soft SPI is not available on ESP8266 #endif -#include "drivers/AVR/DigitalIO/DigitalIO.h" +#include "hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h" #endif // SOFTSERIAL @@ -361,14 +361,14 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs // Transport drivers #if defined(MY_RADIO_RF24) -#include "drivers/RF24/RF24.cpp" +#include "hal/transport/RF24/driver/RF24.cpp" #include "hal/transport/RF24/MyTransportRF24.cpp" #elif defined(MY_RADIO_NRF5_ESB) #if !defined(ARDUINO_ARCH_NRF5) #error No support for nRF5 radio on this platform #endif -#include "drivers/NRF5/Radio.cpp" -#include "drivers/NRF5/Radio_ESB.cpp" +#include "hal/transport/NRF5_ESB/driver/Radio.cpp" +#include "hal/transport/NRF5_ESB/driver/Radio_ESB.cpp" #include "hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp" #elif defined(MY_RS485) #if !defined(MY_RS485_HWSERIAL) @@ -380,13 +380,13 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs #include "hal/transport/RS485/MyTransportRS485.cpp" #elif defined(MY_RADIO_RFM69) #if defined(MY_RFM69_NEW_DRIVER) -#include "drivers/RFM69/new/RFM69_new.cpp" +#include "hal/transport/RFM69/driver/new/RFM69_new.cpp" #else -#include "drivers/RFM69/old/RFM69_old.cpp" +#include "hal/transport/RFM69/driver/old/RFM69_old.cpp" #endif #include "hal/transport/RFM69/MyTransportRFM69.cpp" #elif defined(MY_RADIO_RFM95) -#include "drivers/RFM95/RFM95.cpp" +#include "hal/transport/RFM95/driver/RFM95.cpp" #include "hal/transport/RFM95/MyTransportRFM95.cpp" #endif diff --git a/core/MyEepromAddresses.h b/core/MyEepromAddresses.h index cdc7fef1a..ac710de3f 100644 --- a/core/MyEepromAddresses.h +++ b/core/MyEepromAddresses.h @@ -83,9 +83,9 @@ /** @brief Address RF AES encryption key. This is set with @ref SecurityPersonalizer.ino */ #define EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS (EEPROM_SIGNING_SOFT_SERIAL_ADDRESS + SIZE_SIGNING_SOFT_SERIAL) /** @brief Address node lock counter. This is set with @ref SecurityPersonalizer.ino */ -#define EEPROM_NODE_LOCK_COUNTER (EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS + SIZE_RF_ENCRYPTION_AES_KEY) +#define EEPROM_NODE_LOCK_COUNTER_ADDRESS (EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS + SIZE_RF_ENCRYPTION_AES_KEY) /** @brief First free address for sketch static configuration */ -#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_NODE_LOCK_COUNTER + SIZE_NODE_LOCK_COUNTER) +#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_NODE_LOCK_COUNTER_ADDRESS + SIZE_NODE_LOCK_COUNTER) #endif // MyEepromAddresses_h diff --git a/core/MyMessage.h b/core/MyMessage.h index 312cbd8e0..83824008e 100644 --- a/core/MyMessage.h +++ b/core/MyMessage.h @@ -479,9 +479,9 @@ typedef union { struct { #endif - uint8_t last; ///< 8 bit - Id of last node this message passed - uint8_t sender; ///< 8 bit - Id of sender node (origin) - uint8_t destination; ///< 8 bit - Id of destination node + uint8_t last; //!< 8 bit - Id of last node this message passed + uint8_t sender; //!< 8 bit - Id of sender node (origin) + uint8_t destination; //!< 8 bit - Id of destination node /** * 2 bit - Protocol version
@@ -498,8 +498,8 @@ typedef union { */ uint8_t command_ack_payload; - uint8_t type; ///< 8 bit - Type varies depending on command - uint8_t sensor; ///< 8 bit - Id of sensor that this message concerns. + uint8_t type; //!< 8 bit - Type varies depending on command + uint8_t sensor; //!< 8 bit - Id of sensor that this message concerns. /* * Each message can transfer a payload. We add one extra byte for string @@ -507,26 +507,26 @@ typedef union { * This union is used to simplify the construction of the binary data types transferred. */ union { - uint8_t bValue; ///< unsigned byte value (8-bit) - uint16_t uiValue; ///< unsigned integer value (16-bit) - int16_t iValue; ///< signed integer value (16-bit) - uint32_t ulValue; ///< unsigned long value (32-bit) - int32_t lValue; ///< signed long value (32-bit) - struct { //< Float messages + uint8_t bValue; //!< unsigned byte value (8-bit) + uint16_t uiValue; //!< unsigned integer value (16-bit) + int16_t iValue; //!< signed integer value (16-bit) + uint32_t ulValue; //!< unsigned long value (32-bit) + int32_t lValue; //!< signed long value (32-bit) + struct { //!< Float messages float fValue; - uint8_t fPrecision; ///< Number of decimals when serializing + uint8_t fPrecision; //!< Number of decimals when serializing }; - struct { //< Presentation messages - uint8_t version; ///< Library version - uint8_t sensorType; ///< Sensor type hint for controller, see table above + struct { //!< Presentation messages + uint8_t version; //!< Library version + uint8_t sensorType; //!< Sensor type hint for controller, see table above }; - char data[MAX_PAYLOAD + 1]; ///< Buffer for raw payload data - } __attribute__((packed)); ///< Doxygen will complain without this comment + char data[MAX_PAYLOAD + 1]; //!< Buffer for raw payload data + } __attribute__((packed)); //!< Doxygen will complain without this comment #if defined(__cplusplus) || defined(DOXYGEN) } __attribute__((packed)); #else }; -uint8_t array[HEADER_SIZE + MAX_PAYLOAD + 1]; ///< buffer for entire message +uint8_t array[HEADER_SIZE + MAX_PAYLOAD + 1]; //!< buffer for entire message } __attribute__((packed)) MyMessage; #endif diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index fff479f48..0007f25ee 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -706,7 +706,7 @@ void _nodeLock(const char* str) { #ifdef MY_NODE_LOCK_FEATURE // Make sure EEPROM is updated to locked status - hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, 0); + hwWriteConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS, 0); while (1) { setIndication(INDICATION_ERR_LOCKED); CORE_DEBUG(PSTR("MCO:NLK:NODE LOCKED. TO UNLOCK, GND PIN %" PRIu8 " AND RESET\n"), @@ -730,7 +730,7 @@ void _checkNodeLock(void) { #ifdef MY_NODE_LOCK_FEATURE // Check if node has been locked down - if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0) { + if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS) == 0) { // Node is locked, check if unlock pin is asserted, else hang the node hwPinMode(MY_NODE_UNLOCK_PIN, INPUT_PULLUP); // Make a short delay so we are sure any large external nets are fully pulled @@ -738,7 +738,7 @@ void _checkNodeLock(void) while (hwMillis() - enter < 2) {} if (hwDigitalRead(MY_NODE_UNLOCK_PIN) == 0) { // Pin is grounded, reset lock counter - hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX); + hwWriteConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS, MY_NODE_LOCK_COUNTER_MAX); // Disable pullup hwPinMode(MY_NODE_UNLOCK_PIN, INPUT); setIndication(INDICATION_ERR_LOCKED); @@ -748,9 +748,9 @@ void _checkNodeLock(void) hwPinMode(MY_NODE_UNLOCK_PIN, INPUT); _nodeLock("LDB"); //Locked during boot } - } else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0xFF) { + } else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS) == 0xFF) { // Reset value - hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX); + hwWriteConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS, MY_NODE_LOCK_COUNTER_MAX); } #endif } diff --git a/core/MyTransport.cpp b/core/MyTransport.cpp index ec5244fd9..0aced7d33 100644 --- a/core/MyTransport.cpp +++ b/core/MyTransport.cpp @@ -90,7 +90,7 @@ void stInitTransition(void) #endif // Read node settings (ID, parent ID, GW distance) from EEPROM - hwReadConfigBlock((void*)&_transportConfig, (void*)EEPROM_NODE_ID_ADDRESS, + hwReadConfigBlock((void *)&_transportConfig, (void *)EEPROM_NODE_ID_ADDRESS, sizeof(transportConfig_t)); } @@ -360,7 +360,7 @@ void stFailureUpdate(void) } } -void transportSwitchSM(transportState_t& newState) +void transportSwitchSM(transportState_t &newState) { if (_transportSM.currentState != &newState) { _transportSM.stateRetries = 0u; // state change, reset retry counter @@ -411,7 +411,6 @@ void resetMessageReceived(void) _transportSM.msgReceived = false; } - void transportInitialise(void) { _transportSM.failureCounter = 0u; // reset failure counter @@ -431,6 +430,7 @@ void transportDisable(void) transportSleep(); } } + void transportReInitialise(void) { if (RADIO_CAN_POWER_OFF == true) { @@ -443,7 +443,6 @@ void transportReInitialise(void) } } - bool transportWaitUntilReady(const uint32_t waitingMS) { // check if transport ready @@ -467,7 +466,6 @@ void transportProcess(void) transportProcessFIFO(); } - bool transportCheckUplink(const bool force) { if (!force && (hwMillis() - _transportSM.lastUplinkCheck) < MY_TRANSPORT_CHKUPL_INTERVAL_MS) { @@ -717,7 +715,7 @@ void transportProcessMessage(void) // Is message addressed to this node? if (destination == _transportConfig.nodeId) { // prevent buffer overflow by limiting max. possible message length (5 bits=31 bytes max) to MAX_PAYLOAD (25 bytes) - mSetLength(_msg, min(mGetLength(_msg),(uint8_t)MAX_PAYLOAD)); + mSetLength(_msg, min(mGetLength(_msg), (uint8_t)MAX_PAYLOAD)); // null terminate data _msg.data[msgLength] = 0u; // Check if sender requests an ack back. diff --git a/core/MyTransport.h b/core/MyTransport.h index 98f578472..54fc7d695 100644 --- a/core/MyTransport.h +++ b/core/MyTransport.h @@ -253,7 +253,7 @@ typedef int16_t transportRSSI_t; //!< Datatype for internal RSSI storage */ typedef struct { // SM variables - transportState_t* currentState; //!< pointer to current FSM state + transportState_t *currentState; //!< pointer to current FSM state uint32_t stateEnter; //!< state enter timepoint // general transport variables uint32_t lastUplinkCheck; //!< last uplink check, required to prevent GW flooding @@ -334,7 +334,7 @@ void stFailureUpdate(void); * @brief Switch SM state * @param newState New state to switch SM to */ -void transportSwitchSM(transportState_t& newState); +void transportSwitchSM(transportState_t &newState); /** * @brief Update SM state */ diff --git a/core/Version.h b/core/Version.h index f279c7ab0..ab475f958 100644 --- a/core/Version.h +++ b/core/Version.h @@ -49,8 +49,8 @@ #define MYSENSORS_LIBRARY_VERSION_MAJOR 2 //!< Major release version #define MYSENSORS_LIBRARY_VERSION_MINOR 3 //!< Minor release version #define MYSENSORS_LIBRARY_VERSION_PATCH 1 //!< Patch version -#define MYSENSORS_LIBRARY_VERSION_PRERELEASE "beta" //!< Pre-release suffix, i.e. alpha, beta, rc.1, etc -#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0x01 //!< incremental counter, starting at 0x00. 0xFF for final release +#define MYSENSORS_LIBRARY_VERSION_PRERELEASE "beta" //!< Pre-release suffix, i.e. alpha, beta, rc.1, etc +#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0x02 //!< incremental counter, starting at 0x00. 0xFF for final release #if (MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER != 0xFF) diff --git a/drivers/AltSoftSerial/AltSoftSerial.cpp b/drivers/AltSoftSerial/AltSoftSerial.cpp index 149bef3ea..94d94e1af 100644 --- a/drivers/AltSoftSerial/AltSoftSerial.cpp +++ b/drivers/AltSoftSerial/AltSoftSerial.cpp @@ -21,6 +21,9 @@ * THE SOFTWARE. */ +// Revisions are now tracked on GitHub +// https://github.com/PaulStoffregen/AltSoftSerial +// // Version 1.2: Support Teensy 3.x // // Version 1.1: Improve performance in receiver code @@ -55,23 +58,45 @@ static uint8_t tx_bit; static volatile uint8_t tx_buffer_head; static volatile uint8_t tx_buffer_tail; #define TX_BUFFER_SIZE 68 -static volatile uint8_t tx_buffer[RX_BUFFER_SIZE]; +static volatile uint8_t tx_buffer[TX_BUFFER_SIZE]; #ifndef INPUT_PULLUP #define INPUT_PULLUP INPUT #endif +#define MAX_COUNTS_PER_BIT 6241 // 65536 / 10.5 + void AltSoftSerial::init(uint32_t cycles_per_bit) { - if (cycles_per_bit < 7085) { + //Serial.printf("cycles_per_bit = %d\n", cycles_per_bit); + if (cycles_per_bit < MAX_COUNTS_PER_BIT) { CONFIG_TIMER_NOPRESCALE(); } else { cycles_per_bit /= 8; - if (cycles_per_bit < 7085) { + //Serial.printf("cycles_per_bit/8 = %d\n", cycles_per_bit); + if (cycles_per_bit < MAX_COUNTS_PER_BIT) { CONFIG_TIMER_PRESCALE_8(); } else { - return; // minimum 283 baud at 16 MHz clock +#if defined(CONFIG_TIMER_PRESCALE_256) + cycles_per_bit /= 32; + //Serial.printf("cycles_per_bit/256 = %d\n", cycles_per_bit); + if (cycles_per_bit < MAX_COUNTS_PER_BIT) { + CONFIG_TIMER_PRESCALE_256(); + } else { + return; // baud rate too low for AltSoftSerial + } +#elif defined(CONFIG_TIMER_PRESCALE_128) + cycles_per_bit /= 16; + //Serial.printf("cycles_per_bit/128 = %d\n", cycles_per_bit); + if (cycles_per_bit < MAX_COUNTS_PER_BIT) { + CONFIG_TIMER_PRESCALE_128(); + } else { + return; // baud rate too low for AltSoftSerial + } +#else + return; // baud rate too low for AltSoftSerial +#endif } } ticks_per_bit = cycles_per_bit; @@ -111,7 +136,7 @@ void AltSoftSerial::writeByte(uint8_t b) if (head >= TX_BUFFER_SIZE) { head = 0; } - while (tx_buffer_tail == head) {} // wait until space in buffer + while (tx_buffer_tail == head) ; // wait until space in buffer intr_state = SREG; cli(); if (tx_state) { @@ -131,16 +156,19 @@ void AltSoftSerial::writeByte(uint8_t b) ISR(COMPARE_A_INTERRUPT) { - uint8_t state, byte, head, tail; + uint8_t state, byte, bit, head, tail; uint16_t target; state = tx_state; byte = tx_byte; target = GET_COMPARE_A(); - while (state < 9) { - uint8_t bit; + while (state < 10) { target += ticks_per_bit; - bit = byte & 1; + if (state < 9) { + bit = byte & 1; + } else { + bit = 1; // stopbit + } byte >>= 1; state++; if (bit != tx_bit) { @@ -157,20 +185,19 @@ ISR(COMPARE_A_INTERRUPT) return; } } - if (state == 9) { - tx_state = 10; - CONFIG_MATCH_SET(); - SET_COMPARE_A(target + ticks_per_bit); - return; - } head = tx_buffer_head; tail = tx_buffer_tail; if (head == tail) { - tx_state = 0; - CONFIG_MATCH_NORMAL(); - DISABLE_INT_COMPARE_A(); + if (state == 10) { + // Wait for final stop bit to finish + tx_state = 11; + SET_COMPARE_A(target + ticks_per_bit); + } else { + tx_state = 0; + CONFIG_MATCH_NORMAL(); + DISABLE_INT_COMPARE_A(); + } } else { - tx_state = 1; if (++tail >= TX_BUFFER_SIZE) { tail = 0; } @@ -178,14 +205,19 @@ ISR(COMPARE_A_INTERRUPT) tx_byte = tx_buffer[tail]; tx_bit = 0; CONFIG_MATCH_CLEAR(); - SET_COMPARE_A(target + ticks_per_bit); + if (state == 10) { + SET_COMPARE_A(target + ticks_per_bit); + } else { + SET_COMPARE_A(GET_TIMER_COUNT() + 16); + } + tx_state = 1; // TODO: how to detect timing_error? } } void AltSoftSerial::flushOutput(void) { - while (tx_state) {}/* wait */ + while (tx_state) /* wait */ ; } @@ -193,7 +225,6 @@ void AltSoftSerial::flushOutput(void) /** Reception **/ /****************************************/ - ISR(CAPTURE_INTERRUPT) { uint8_t state, bit; @@ -211,27 +242,26 @@ ISR(CAPTURE_INTERRUPT) state = rx_state; if (state == 0) { if (!bit) { - SET_COMPARE_B(capture + rx_stop_ticks); + uint16_t end = capture + rx_stop_ticks; + SET_COMPARE_B(end); ENABLE_INT_COMPARE_B(); rx_target = capture + ticks_per_bit + ticks_per_bit/2; rx_state = 1; } } else { - uint16_t target; - target = rx_target; + uint16_t target = rx_target; + const uint16_t offset_overflow = 65535 - ticks_per_bit; while (1) { - int16_t offset; - offset = capture - target; - if (offset < 0) { + const uint16_t offset = capture - target; + if (offset > offset_overflow) { break; } rx_byte = (rx_byte >> 1) | rx_bit; target += ticks_per_bit; state++; if (state >= 9) { - uint8_t head; DISABLE_INT_COMPARE_B(); - head = rx_buffer_head + 1; + uint8_t head = rx_buffer_head + 1; if (head >= RX_BUFFER_SIZE) { head = 0; } @@ -304,6 +334,9 @@ int AltSoftSerial::peek(void) if (head == tail) { return -1; } + if (++tail >= RX_BUFFER_SIZE) { + tail = 0; + } return rx_buffer[tail]; } @@ -330,14 +363,15 @@ void ftm0_isr(void) { uint32_t flags = FTM0_STATUS; FTM0_STATUS = 0; + if (flags & (1<<0) && (FTM0_C0SC & 0x40)) { + altss_compare_b_interrupt(); + } if (flags & (1<<5)) { altss_capture_interrupt(); } - if (flags & (1<<6)) { + if (flags & (1<<6) && (FTM0_C6SC & 0x40)) { altss_compare_a_interrupt(); } - if (flags & (1<<0)) { - altss_compare_b_interrupt(); - } } #endif + diff --git a/drivers/AltSoftSerial/AltSoftSerial.h b/drivers/AltSoftSerial/AltSoftSerial.h index 4bb1fdae1..ba8ebe0fb 100644 --- a/drivers/AltSoftSerial/AltSoftSerial.h +++ b/drivers/AltSoftSerial/AltSoftSerial.h @@ -46,11 +46,11 @@ class AltSoftSerial : public Stream AltSoftSerial() { } //!< Constructor ~AltSoftSerial() { - end(); //!< Destructor + end(); //!< Destructor } static void begin(uint32_t baud) { - init((ALTSS_BASE_FREQ + baud / 2) / baud); //!< begin + init((ALTSS_BASE_FREQ + baud / 2) / baud); //!< begin } static void end(); //!< end int peek(); //!< peek @@ -59,47 +59,55 @@ class AltSoftSerial : public Stream #if ARDUINO >= 100 size_t write(uint8_t byte) { - writeByte(byte); //!< write + writeByte(byte); //!< write return 1; } void flush() { - flushOutput(); //!< flush + flushOutput(); //!< flush } #else void write(uint8_t byte) { - writeByte(byte); //!< write + writeByte(byte); //!< write } void flush() { - flushInput(); //!< flush + flushInput(); //!< flush } #endif using Print::write; static void flushInput(); //!< flushInput static void flushOutput(); //!< flushOutput // for drop-in compatibility with NewSoftSerial, rxPin & txPin ignored - //AltSoftSerial(uint8_t rxPin, uint8_t txPin, bool inverse = false) { } + AltSoftSerial(uint8_t rxPin, uint8_t txPin, bool inverse = false) + { + (void)rxPin; //!< AltSoftSerial + (void)txPin; + (void)inverse; + } bool listen() { - return false; //!< listen + return false; //!< listen } bool isListening() { - return true; //!< isListening + return true; //!< isListening } bool overflow() { - bool r = timing_error; //!< overflow + bool r = timing_error; //!< overflow timing_error = false; return r; } static int library_version() { - return 1; //!< library_version + return 1; //!< library_version + } + static void enable_timer0(bool enable) + { + (void)enable; //!< enable_timer0 } - static void enable_timer0(bool) { } //!< enable_timer0 static bool timing_error; //!< timing_error private: static void init(uint32_t cycles_per_bit); diff --git a/drivers/AltSoftSerial/README.md b/drivers/AltSoftSerial/README.md index 35c290d96..376b2e37d 100644 --- a/drivers/AltSoftSerial/README.md +++ b/drivers/AltSoftSerial/README.md @@ -1,4 +1,4 @@ -#AltSoftSerial Library# +# AltSoftSerial Library Improved software emulated serial, using hardware timers for precise signal timing and availability of CPU time for other libraries to respond to interrupts diff --git a/drivers/AltSoftSerial/config/AltSoftSerial_Boards.h b/drivers/AltSoftSerial/config/AltSoftSerial_Boards.h index 51e1f1876..19fcd22c3 100644 --- a/drivers/AltSoftSerial/config/AltSoftSerial_Boards.h +++ b/drivers/AltSoftSerial/config/AltSoftSerial_Boards.h @@ -55,9 +55,9 @@ //#define OUTPUT_COMPARE_C_PIN 14 // unusable PWM -// Teensy 3.0 & 3.1 +// Teensy 3.x // -#elif defined(__MK20DX128__) || defined(__MK20DX256__) +#elif defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #define ALTSS_USE_FTM0 #define INPUT_CAPTURE_PIN 20 // receive (FTM0_CH5) #define OUTPUT_COMPARE_A_PIN 21 // transmit (FTM0_CH6) @@ -123,16 +123,25 @@ -// Sanguino -#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) +// EnviroDIY Mayfly, Sodaq Mbili +#elif defined ARDUINO_AVR_ENVIRODIY_MAYFLY || defined ARDUINO_AVR_SODAQ_MBILI +#define ALTSS_USE_TIMER1 +#define INPUT_CAPTURE_PIN 6 // receive +#define OUTPUT_COMPARE_A_PIN 5 // transmit +#define OUTPUT_COMPARE_B_PIN 4 // unusable PWM + + + +// Sanguino, Mighty 1284 +#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) #define ALTSS_USE_TIMER1 #define INPUT_CAPTURE_PIN 14 // receive #define OUTPUT_COMPARE_A_PIN 13 // transmit #define OUTPUT_COMPARE_B_PIN 12 // unusable PWM + // Unknown board #else #error "Please define your board timer and pins" #endif - diff --git a/drivers/AltSoftSerial/config/AltSoftSerial_Timers.h b/drivers/AltSoftSerial/config/AltSoftSerial_Timers.h index 3f8c96fc4..3ad18d7c4 100644 --- a/drivers/AltSoftSerial/config/AltSoftSerial_Timers.h +++ b/drivers/AltSoftSerial/config/AltSoftSerial_Timers.h @@ -24,6 +24,7 @@ #if defined(ALTSS_USE_TIMER1) #define CONFIG_TIMER_NOPRESCALE() (TIMSK1 = 0, TCCR1A = 0, TCCR1B = (1< Boards > Board Manager) +Operating system & version +Any other software or hardware? + + +### Arduino Sketch + +```cpp +// Change the code below by your sketch (please try to give the smallest code which demonstrates the problem) +#include + +// libraries: give links/details so anyone can compile your code for the same result + +void setup() { +} + +void loop() { +} +``` + + +### Errors or Incorrect Output + +If you see any errors or incorrect output, please show it here. Please use copy & paste to give an exact copy of the message. Details matter, so please show (not merely describe) the actual message or error exactly as it appears. + + diff --git a/drivers/AltSoftSerial/examples/Test/Test.pde b/drivers/AltSoftSerial/examples/Echo/Echo.ino similarity index 95% rename from drivers/AltSoftSerial/examples/Test/Test.pde rename to drivers/AltSoftSerial/examples/Echo/Echo.ino index 32e599fa0..b6d5e3953 100644 --- a/drivers/AltSoftSerial/examples/Test/Test.pde +++ b/drivers/AltSoftSerial/examples/Echo/Echo.ino @@ -13,6 +13,8 @@ // Wiring-S 5 6 4 // Sanguino 13 14 12 +// This example code is in the public domain. + AltSoftSerial altSerial; void setup() { diff --git a/drivers/AltSoftSerial/examples/ReceiveTest/ReceiveTest.ino b/drivers/AltSoftSerial/examples/ReceiveTest/ReceiveTest.ino new file mode 100644 index 000000000..f3c1adb20 --- /dev/null +++ b/drivers/AltSoftSerial/examples/ReceiveTest/ReceiveTest.ino @@ -0,0 +1,56 @@ +// AltSoftSerial Receive Test +// +// Transmit data with Serial1 and try to receive +// it with AltSoftSerial. You must connect a wire +// from Serial1 TX to AltSoftSerial RX. + +#include + +AltSoftSerial altser; +const int mybaud = 9600; + +// Board Serial1 TX AltSoftSerial RX +// ----- ---------- ---------------- +// Teensy 3.x 1 20 +// Teensy 2.0 8 (D3) 10 (C7) +// Teensy++ 2.0 3 (D3) 4 (D4) +// Arduino Leonardo 1 13 +// Arduino Mega 18 48 + +// Serial1 on AVR @ 16 MHz minimum baud is 245 +// Serial1 on Teensy 3.2 @ 96 MHz minimum baud is 733 + +// This example code is in the public domain. + +byte sentbyte; +unsigned long prevmillis; +byte testbyte=0xF0; + +void setup() +{ + delay(200); + Serial.begin(9600); + while (!Serial) ; // wait for Arduino Serial Monitor + Serial1.begin(mybaud); // connect a wire from TX1 + altser.begin(mybaud); // to AltSoftSerial RX + Serial.println("AltSoftSerial Receive Test"); + prevmillis = millis(); +} + +void loop() +{ + // transmit a test byte on Serial 1 + if (millis() - prevmillis > 250) { + sentbyte = testbyte++; + Serial1.write(sentbyte); + prevmillis = millis(); + } + // attempt to receive it by AltSoftSerial + if (altser.available() > 0) { + byte b = altser.read(); + Serial.println(b); + if (b != sentbyte) { + Serial.println("***** ERROR *****"); + } + } +} diff --git a/drivers/AltSoftSerial/examples/ShowConfiguration/ShowConfiguration.ino b/drivers/AltSoftSerial/examples/ShowConfiguration/ShowConfiguration.ino new file mode 100644 index 000000000..df0b76edc --- /dev/null +++ b/drivers/AltSoftSerial/examples/ShowConfiguration/ShowConfiguration.ino @@ -0,0 +1,97 @@ +#include + +// AltSoftSerial show configuration example +// Will print library configuration to default serial port +// Open your serial monitor to see config for your board +// Printout would repeat every 10sec (just in case you missed it somehow) + +// Print Configuration +// ----------------------- + +// Direct include AltSoftSerial internals to obtaion PIN setup (you do not need this in regular code) + +// This example code is in the public domain. + +#include + +void printAltSoftSerialSetup(Stream &port) +{ +#define PRINT_PFX "AltSoftSerial:" +#define PRINT_PIN_NAME(pin,name) { char buffer[128+1]; sprintf(buffer, PRINT_PFX "PIN:%2d %s", (int)pin, (const char*)name); port.println(buffer); } + + port.println(PRINT_PFX "Setup info: begin"); + +#if defined(ALTSS_USE_FTM0) + port.println(PRINT_PFX "USE FTM0"); +#endif + +#if defined(ALTSS_USE_TIMER1) + port.println(PRINT_PFX "USE TIMER1"); +#endif + +#if defined(ALTSS_USE_TIMER2) + port.println(PRINT_PFX "USE TIMER2"); +#endif + +#if defined(ALTSS_USE_TIMER3) + port.println(PRINT_PFX "USE TIMER3"); +#endif + +#if defined(ALTSS_USE_TIMER4) + port.println(PRINT_PFX "USE TIMER4"); +#endif + +#if defined(ALTSS_USE_TIMER5) + port.println(PRINT_PFX "USE TIMER5"); +#endif + +#if defined(INPUT_CAPTURE_PIN) + PRINT_PIN_NAME(INPUT_CAPTURE_PIN,"RX"); +#endif + +#if defined(OUTPUT_COMPARE_A_PIN) + PRINT_PIN_NAME(OUTPUT_COMPARE_A_PIN,"TX"); +#endif + +#if defined(OUTPUT_COMPARE_B_PIN) + PRINT_PIN_NAME(OUTPUT_COMPARE_B_PIN,"(unused PWM)"); +#endif + +#if defined(OUTPUT_COMPARE_C_PIN) + PRINT_PIN_NAME(OUTPUT_COMPARE_C_PIN,"(unused PWM)"); +#endif + +#if defined(OUTPUT_COMPARE_D_PIN) + PRINT_PIN_NAME(OUTPUT_COMPARE_D_PIN,"(unused PWM)"); +#endif + +#if defined(OUTPUT_COMPARE_E_PIN) + PRINT_PIN_NAME(OUTPUT_COMPARE_E_PIN,"(unused PWM)"); +#endif + +#if defined(OUTPUT_COMPARE_F_PIN) + PRINT_PIN_NAME(OUTPUT_COMPARE_F_PIN,"(unused PWM)"); +#endif + + port.println(PRINT_PFX "Setup info: end"); + +#undef PRINT_PIN_NAME +#undef PRINT_PFX +} + +void setup() +{ + // Open default serial to dump config to + Serial.begin(9600); + while (!Serial) ; // wait for serial monitor + printAltSoftSerialSetup(Serial); +} + +void loop() +{ + // Repeat every 10 sec (just in case) + delay(10000); + Serial.println(""); + printAltSoftSerialSetup(Serial); +} + diff --git a/drivers/NVM/Flash.h b/drivers/NVM/Flash.h index 7ade8c266..ffffbe26f 100644 --- a/drivers/NVM/Flash.h +++ b/drivers/NVM/Flash.h @@ -170,7 +170,7 @@ extern FlashClass Flash; /** Load Hardwarespecific files */ #ifdef NRF5 -#include "drivers/NRF5/Flash.cpp" +#include "hal/architecture/NRF5/drivers/Flash.cpp" #else #error "Unsupported platform." #endif diff --git a/drivers/SPIFlash/License.txt b/drivers/SPIFlash/License.txt new file mode 100644 index 000000000..94a9ed024 --- /dev/null +++ b/drivers/SPIFlash/License.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/drivers/SPIFlash/README.md b/drivers/SPIFlash/README.md new file mode 100644 index 000000000..3a7a7ba30 --- /dev/null +++ b/drivers/SPIFlash/README.md @@ -0,0 +1,32 @@ +SPIFlash +======== +[![Build Status](https://travis-ci.org/LowPowerLab/SPIFlash.svg?branch=master)](https://travis-ci.org/LowPowerLab/SPIFlash) +[![GitHub release](https://img.shields.io/github/release/LowPowerLab/SPIFlash.svg)](https://github.com/LowPowerLab/SPIFlash) +[![GitHub issues](https://img.shields.io/github/issues/LowPowerLab/SPIFlash.svg)](https://github.com/LowPowerLab/SPIFlash/issues) +[![GitHub pull requests](https://img.shields.io/github/issues-pr/LowPowerLab/SPIFlash.svg)](https://github.com/LowPowerLab/SPIFlash/pulls) +[![license](https://img.shields.io/github/license/LowPowerLab/SPIFlash.svg)](https://github.com/LowPowerLab/SPIFlash/blob/master/LICENSE.txt) + +Arduino/Moteino library for read/write access to SPI flash memory chips. +This works with 256byte/page SPI flash memory such as the [4MBIT W25X40CLSNIG](https://lowpowerlab.com/shop/product/72) used on [Moteino](https://www.moteino.com) for data storage and wireless programming. +
+For instance a 4MBit (512Kbyte) flash chip will have 2048 pages: 256*2048 = 524288 bytes (512Kbytes). +
Minimal modifications should allow chips that have different page size to work. +
DEPENDS ON: Arduino native *SPI library*. +
+This library was primarily developed to enable **safe** wireless programming on Moteino nodes and Moteino based applications such as the [SwitchMote](https://lowpowerlab.com/guide/switchmote/). This has been documented at [lowpowerlab](https://lowpowerlab.com/guide/moteino/wireless-programming/). [Dualoptiboot](https://github.com/LowPowerLab/DualOptiboot) (all AVR based Moteinos come with it) and [RFM69_OTA WirelessProgramming library](https://github.com/LowPowerLab/RFM69) are required to be able to wirelessly re-flash a remote Moteino. + +### Installation +Copy the content of this library in the "Arduino/libraries/SPIFlash" folder. +
+To find your Arduino folder go to File>Preferences in the Arduino IDE. +
+See [this tutorial](https://www.arduino.cc/en/Guide/Libraries) on installing Arduino libraries. + +### License +Copyright (c) 2013-2018 by Felix Rusu +

+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 . diff --git a/drivers/SPIFlash/SPIFlash.cpp b/drivers/SPIFlash/SPIFlash.cpp index 973c53e4e..38e308276 100644 --- a/drivers/SPIFlash/SPIFlash.cpp +++ b/drivers/SPIFlash/SPIFlash.cpp @@ -9,6 +9,7 @@ // > Selective merge by Felix after testing in IDE 1.0.6, 1.6.4 // > Updated May 19, 2016 D-H-R, added support for SST25/Microchip Flash which does not support Page programming with OPCode 0x02, // > use define MY_SPIFLASH_SST25TYPE for SST25 Type Flash Memory +// > Updated Sep 07, 2018 tekka, sync with https://github.com/LowPowerLab/SPIFlash // ********************************************************************************** // License // ********************************************************************************** @@ -76,7 +77,6 @@ void SPIFlash::select() SPI.setBitOrder(MSBFIRST); SPI.setClockDivider( SPI_CLOCK_DIV4); //decided to slow down from DIV2 after SPI stalling in some instances, especially visible on mega1284p when RFM69 and FLASH chip both present - SPI.begin(); #endif hwDigitalWrite(_slaveSelectPin, LOW); } @@ -105,6 +105,7 @@ bool SPIFlash::initialize() _SPSR = SPSR; #endif hwPinMode(_slaveSelectPin, OUTPUT); + SPI.begin(); // see https://github.com/LowPowerLab/SPIFlash/issues/20 #ifdef SPI_HAS_TRANSACTION _settings = SPISettings(4000000, MSBFIRST, SPI_MODE0); #endif @@ -345,6 +346,15 @@ void SPIFlash::blockErase32K(uint32_t addr) SPI.transfer(addr); unselect(); } +/// erase a 64Kbyte block +void SPIFlash::blockErase64K(uint32_t addr) +{ + command(SPIFLASH_BLOCKERASE_64K, true); // Block Erase + SPI.transfer(addr >> 16); + SPI.transfer(addr >> 8); + SPI.transfer(addr); + unselect(); +} void SPIFlash::sleep() { diff --git a/drivers/SPIFlash/SPIFlash.h b/drivers/SPIFlash/SPIFlash.h index 158c6a96e..6adc3a242 100644 --- a/drivers/SPIFlash/SPIFlash.h +++ b/drivers/SPIFlash/SPIFlash.h @@ -9,6 +9,7 @@ // > Selective merge by Felix after testing in IDE 1.0.6, 1.6.4 // > Updated May 19, 2016 D-H-R, added support for SST25/Microchip Flash which does not support Page programming with OPCode 0x02, // > use define MY_SPIFLASH_SST25TYPE for SST25 Type Flash Memory. Added / changed comments to better suit doxygen +// > Updated Sep 07, 2018 tekka, sync with https://github.com/LowPowerLab/SPIFlash // ********************************************************************************** // License // ********************************************************************************** @@ -175,6 +176,7 @@ class SPIFlash void chipErase(); //!< erase entire flash memory array void blockErase4K(uint32_t address); //!< erase a 4Kbyte block void blockErase32K(uint32_t address); //!< erase a 32Kbyte block + void blockErase64K(uint32_t addr); //!< erase a 64Kbyte block uint16_t readDeviceId(); //!< Get the manufacturer and device ID bytes (as a short word) uint8_t* readUniqueId(); //!< Get the 64 bit unique identifier, stores it in @ref UNIQUEID[8] diff --git a/drivers/SPIFlash/examples/SPIFlash_ReadWrite/SPIFlash_ReadWrite.ino b/drivers/SPIFlash/examples/SPIFlash_ReadWrite/SPIFlash_ReadWrite.ino new file mode 100644 index 000000000..d2350507a --- /dev/null +++ b/drivers/SPIFlash/examples/SPIFlash_ReadWrite/SPIFlash_ReadWrite.ino @@ -0,0 +1,127 @@ +// ********************************************************************************** +// This sketch is an example of using the SPIFlash library with a Moteino +// that has an onboard SPI Flash chip. This sketch listens to a few serial commands +// Hence type the following commands to interact with the SPI flash memory array: +// - 'd' dumps the first 256bytes of the flash chip to screen +// - 'e' erases the entire memory chip +// - 'i' print manufacturer/device ID +// - [0-9] writes a random byte to addresses [0-9] (either 0xAA or 0xBB) +// Get the SPIFlash library from here: https://github.com/LowPowerLab/SPIFlash +// ********************************************************************************** +// Copyright Felix Rusu, LowPowerLab.com +// Library and code by Felix Rusu - felix@lowpowerlab.com +// ********************************************************************************** +// License +// ********************************************************************************** +// 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 . +// +// Licence can be viewed at +// http://www.gnu.org/licenses/gpl-3.0.txt +// +// Please maintain this license information along with authorship +// and copyright notices in any redistribution of this code +// ********************************************************************************** + + +#include //get it here: https://github.com/LowPowerLab/SPIFlash +#include + +#define SERIAL_BAUD 115200 +char input = 0; +long lastPeriod = -1; + +#ifdef __AVR_ATmega1284P__ +#define LED 15 // Moteino MEGAs have LEDs on D15 +#define FLASH_SS 23 // and FLASH SS on D23 +#else +#define LED 9 // Moteinos have LEDs on D9 +#define FLASH_SS 8 // and FLASH SS on D8 +#endif + +////////////////////////////////////////// +// flash(SPI_CS, MANUFACTURER_ID) +// SPI_CS - CS pin attached to SPI flash chip (8 in case of Moteino) +// MANUFACTURER_ID - OPTIONAL, 0x1F44 for adesto(ex atmel) 4mbit flash +// 0xEF30 for windbond 4mbit flash +////////////////////////////////////////// +SPIFlash flash(FLASH_SS, 0xEF30); + +void setup() +{ + Serial.begin(SERIAL_BAUD); + Serial.print("Start..."); + + if (flash.initialize()) { + Serial.println("Init OK!"); + Blink(LED, 20, 10); + } else { + Serial.println("Init FAIL!"); + } + + delay(1000); +} + +void loop() +{ + // Handle serial input (to allow basic DEBUGGING of FLASH chip) + // ie: display first 256 bytes in FLASH, erase chip, write bytes at first 10 positions, etc + if (Serial.available() > 0) { + input = Serial.read(); + if (input == 'd') { //d=dump flash area + Serial.println("Flash content:"); + int counter = 0; + + while(counter<=256) { + Serial.print(flash.readByte(counter++), HEX); + Serial.print('.'); + } + + Serial.println(); + } else if (input == 'e') { + Serial.print("Erasing Flash chip ... "); + flash.chipErase(); + while(flash.busy()); + Serial.println("DONE"); + } else if (input == 'i') { + Serial.print("DeviceID: "); + Serial.println(flash.readDeviceId(), HEX); + } else if (input >= 48 && input <= 57) { //0-9 + Serial.print("\nWriteByte("); + Serial.print(input); + Serial.print(")"); + flash.writeByte(input-48, (millis()%2) ? 0xaa : 0xbb); + } + } + + // Periodically blink the onboard LED while listening for serial commands + if ((int)(millis()/500) > lastPeriod) { + lastPeriod++; + pinMode(LED, OUTPUT); + digitalWrite(LED, lastPeriod%2); + } +} + +void Blink(byte PIN, int DELAY_MS, byte loops) +{ + pinMode(PIN, OUTPUT); + while (loops--) { + digitalWrite(PIN,HIGH); + delay(DELAY_MS); + digitalWrite(PIN,LOW); + delay(DELAY_MS); + } +} \ No newline at end of file diff --git a/drivers/SPIFlash/keywords.txt b/drivers/SPIFlash/keywords.txt new file mode 100644 index 000000000..652da982d --- /dev/null +++ b/drivers/SPIFlash/keywords.txt @@ -0,0 +1,18 @@ +SPIFlash KEYWORD1 +initialize KEYWORD2 +command KEYWORD2 +readStatus KEYWORD2 +readByte KEYWORD2 +readBytes KEYWORD2 +writeByte KEYWORD2 +writeBytes KEYWORD2 +flashBusy KEYWORD2 +chipErase KEYWORD2 +blockErase4K KEYWORD2 +blockErase32K KEYWORD2 +readDeviceId KEYWORD2 +readUniqueId KEYWORD2 +UNIQUEID KEYWORD2 +sleep KEYWORD2 +wakeup KEYWORD2 +end KEYWORD2 \ No newline at end of file diff --git a/drivers/extEEPROM/ReadMe.md b/drivers/extEEPROM/ReadMe.md index af4b67658..594336a9c 100644 --- a/drivers/extEEPROM/ReadMe.md +++ b/drivers/extEEPROM/ReadMe.md @@ -1,9 +1,7 @@ -# Arduino External EEPROM Library v3.2 # +# Arduino External EEPROM Library v3.4 # Original library by http://github.com/JChristensen/extEEPROM -ReadMe file by Jack Christensen Jul 2014 - ## Introduction ## **Arduino External EEPROM Library** @@ -17,6 +15,7 @@ The **extEEPROM Library** has been tested with: - Microchip 24LC256 (256k bit) - Microchip 24FC1026 (1M bit, thanks to Gabriele B on the Arduino forum) - ST Micro M24M02 (2M bit) +- Atmel AT24C256C (32k x 8, thanks to Searobin) The **extEEPROM Library** will **NOT** work with Microchip 24xx1025 as its control byte does not conform to the following assumptions. @@ -28,19 +27,26 @@ The **extEEPROM Library** will **NOT** work with Microchip 24xx1025 as its contr Note that the Arduino Wire library has a buffer size of 32 bytes. This limits the size of physical I/Os that can be done to EEPROM. For writes, one or two bytes are used for the address, so writing is therefore limited to 31 or 30 bytes. Because the **extEEPROM Library** will handle I/O across block, page and device boundaries, the only consequence this has for the user is one of efficiency; arbitrarily large blocks of data can be written and read; however, carefully chosen block sizes may reduce the number of physical I/Os needed. -"Arduino External EEPROM Library" by Jack Christensen is licensed under [CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/). - ## Installation ## -To use the **extEEPROM Library**: -- Go to http://github.com/JChristensen/extEEPROM, click the **Download ZIP** button and save the ZIP file to a convenient location on your PC. + +### Install with the Library Manager +- For Arduino IDE versions 1.6.2 and up, add library by selecting "Manage Libraries..." from the "Include Library" submenu within the Sketch menu. +- The library manager will open and you will find a list of libraries that are already installed or ready for installation. Scroll the list to find **extEEPROM** library and click on it. + - Select the version of the library you want to install. + - Click on install and wait for the IDE to install the new library. Downloading may take time depending on your connection speed. + - Once it has finished, an Installed tag should appear, You can close the library manager. + +### Manual Install +- Go to http://github.com/PaoloP74/extEEPROM, click the **Download ZIP** button and save the ZIP file to a convenient location on your PC. - Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually **extEEPROM-master**. - Rename the folder to just **extEEPROM**. - Copy the renamed folder to the Arduino sketchbook\libraries folder. ## Examples ## The following example sketch is included with the **extEEPROM Library**: +- **eepromReadWrite** - **eepromTest:** Writes 32-bit integers to the entire EEPROM address space, starting at address 0 and continuing to the topmost address. These are then read back in and verified; any discrepancies are reported to the serial monitor. - +- **eepromTest_Wire1** ## Usage notes ## The **extEEPROM Library** is designed for use with Arduino version 1.0 or later. @@ -49,11 +55,10 @@ To use the **extEEPROM Library**, the standard [Arduino Wire library](http://ard #include //http://arduino.cc/en/Reference/Wire (included with Arduino IDE) ``` ## Enumerations ## - -###eeprom_size_t -#####Description +### eeprom_size_t +##### Description EEPROM device size in k-bits. Many manufacturers' EEPROM part numbers are designated in k-bits. -#####Values +##### Values - kbits_2 - kbits_4 - kbits_8 @@ -65,62 +70,75 @@ EEPROM device size in k-bits. Many manufacturers' EEPROM part numbers are design - kbits_512 - kbits_1024 - kbits_2048 - -###twiClockFreq_t -#####Description +### twiClockFreq_t +##### Description I2C bus speed. -#####Values -- twiClock100kHz -- twiClock400kHz +##### Values +- extEEPROM::twiClock100kHz +- extEEPROM::twiClock400kHz ## Constructor ## - -###extEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr) -#####Description +### extEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr) +##### Description Instantiates an external EEPROM object. -#####Syntax -`extEEPROM myEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr));` -#####Parameters +##### Syntax +`extEEPROM myEEPROM(eeprom_size_t devCap, byte nDev, unsigned int pgSize, byte busAddr);` +##### Parameters **devCap** *(eeprom_size_t)*: The size of one EEPROM device in k-bits. Choose a value from the eeprom_size_t enumeration above. **nDev** *(byte)*: The number of EEPROM devices on the bus. Note that if there are multiple EEPROM devices on the bus, they must be identical and each must have its address pins strapped properly. **pgSize** *(unsigned int)*: The EEPROM page size in bytes. Consult the datasheet if you are unsure of the page size. **busAddr** *(byte)*: The base I2C bus address for the EEPROM(s). 0x50 is a common value and this parameter can be omitted, in which case 0x50 will be used as the default. -#####Example +##### Example ```c++ extEEPROM myEEPROM(kbits_256, 2, 64); //two 24LC256 EEPROMS on the bus extEEPROM oddEEPROM(kbits_8, 1, 16, 0x42); //an EEPROM with a non-standard I2C address ``` ## Methods ## -###begin(twiClockFreq_t freq) -#####Description +### begin(twiClockFreq_t freq, TwoWire *_comm) +##### Description Initializes the library. Call this method once in the setup code. begin() does a dummy I/O so that the user may interrogate the return status to ensure the EEPROM is operational. -#####Syntax +##### Syntax `myEEPROM.begin(twiClockFreq_t freq);` -#####Parameters -**freq** *(twiClockFreq_t)*: The desired I2C bus speed, twiClock100kHz or twiClock400kHz. Can be omitted in which case it will default to twiClock100kHz. **NOTE:** When using 400kHz, if there are other devices on the bus they must all support a 400kHz bus speed. **Secondly**, the other devices should be initialized first, as other libraries may not support adjusting the bus speed. To ensure the desired speed is set, call the extEEPROM.begin() function *after* initializing all other I2C devices. -#####Returns +or +`myEEPROM.begin(twiClockFreq_t freq, TwoWire *_comm);` +##### Parameters +**freq** *(twiClockFreq_t)*: The desired I2C bus speed, `extEEPROM::twiClock100kHz` or `extEEPROM::twiClock400kHz`. Can be omitted in which case it will default to `twiClock100kHz`. +**NOTE:** When using 400kHz, if there are other devices on the bus they must all support a 400kHz bus speed. **Secondly**, the other devices should be initialized first, as other libraries may not support adjusting the bus speed. To ensure the desired speed is set, call the extEEPROM.begin() function *after* initializing all other I2C devices. + +**_comm** *(TwoWire * )*: The Used I2C TwoWire channel . Can be omitted in which case it will default to the first Arduino I2C channel `Wire`. If another of the possible I2C channel is used its pointer shall be passed as parameter. +**NOTE:** If another I2C channel is unse, and not the default one, the first parameters **freq** MUST be defined. +##### Returns I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. -#####Example + +##### Examples ```c++ extEEPROM myEEPROM(kbits_256, 2, 64); -byte i2cStat = myEEPROM.begin(twiClock400kHz); +byte i2cStat = myEEPROM.begin(extEEPROM::twiClock400kHz); if ( i2cStat != 0 ) { //there was a problem } ``` -###write(unsigned long addr, byte *values, unsigned int nBytes) -#####Description +##### Use of other I2C channel +```c++ +extEEPROM myEEPROM(kbits_256, 2, 64); +byte i2cStat = myEEPROM.begin(extEEPROM::twiClock400kHz, &Wire1); +if ( i2cStat != 0 ) { + //there was a problem +} +``` +### write(unsigned long addr, byte *values, unsigned int nBytes) +##### Description Write one or more bytes to external EEPROM. -#####Syntax +##### Syntax `myEEPROM.write(unsigned long addr, byte* values, byte nBytes);` -#####Parameters +##### Parameters **addr** *(unsigned long)*: The beginning EEPROM location to write. **values** _(byte*)_: Pointer to an array containing the data to write. **nBytes** *(unsigned int)*: The number of bytes to write. -#####Returns +##### Returns I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space. -#####Example +##### Example ```c++ byte myData[10]; //write 10 bytes starting at location 42 @@ -135,33 +153,33 @@ if ( i2cStat != 0 ) { } } ``` -###write(unsigned long addr, byte value) -#####Description +### write(unsigned long addr, byte value) +##### Description Writes a single byte to external EEPROM. -#####Syntax +##### Syntax `myEEPROM.write(unsigned long addr, byte value);` -#####Parameters +##### Parameters **addr** *(unsigned long)*: The EEPROM location to write. **values** _(byte)_: The value to write. -#####Returns +##### Returns Same as multiple-byte write() above. -#####Example +##### Example ```c++ //write the value 16 to EEPROM location 314. byte i2cStat = myEEPROM.write(314, 16); ``` -###read(unsigned long addr, byte *values, unsigned int nBytes) -#####Description +### read(unsigned long addr, byte *values, unsigned int nBytes) +##### Description Reads one or more bytes from external EEPROM into an array supplied by the caller. -#####Syntax +##### Syntax `myEEPROM.read(unsigned long addr, byte *values, byte nBytes);` -#####Parameters +##### Parameters **addr** *(unsigned long)*: The beginning EEPROM location to read from. **values** _(byte*)_: Pointer to an array to receive the data. **nBytes** *(unsigned int)*: The number of bytes to read. -#####Returns +##### Returns I2C I/O status, zero if successful *(byte)*. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of other return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space. -#####Example +##### Example ```c++ byte myData[10]; //read 10 bytes starting at location 42 @@ -176,17 +194,16 @@ if ( i2cStat != 0 ) { } } ``` -###read(unsigned long addr) -#####Description +### read(unsigned long addr) +##### Description Reads a single byte from external EEPROM. -#####Syntax +##### Syntax `myEEPROM.read(unsigned long addr);` -#####Parameters +##### Parameters **addr** *(unsigned long)*: The EEPROM location to read from. -#####Returns +##### Returns The data read from EEPROM or an error code *(int)*. To distinguish error values from valid data, error values are returned as negative numbers. See the [Arduino Wire.endTransmission() function](http://arduino.cc/en/Reference/WireEndTransmission) for a description of return codes. Returns a status of EEPROM_ADDR_ERR if the I/O would extend past the top of the EEPROM address space. - -#####Example +##### Example ```c++ int myData; //read a byte from location 42 @@ -201,8 +218,9 @@ if ( readValue < 0 ) { } } else { - //data read ok + //data read ok } ``` +"Arduino External EEPROM Library" by Jack Christensen is licensed under [CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/). ![CC BY-SA](http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by-sa.png) diff --git a/drivers/extEEPROM/examples/eepromReadWrite/eepromReadWrite.ino b/drivers/extEEPROM/examples/eepromReadWrite/eepromReadWrite.ino new file mode 100644 index 000000000..f260c39ab --- /dev/null +++ b/drivers/extEEPROM/examples/eepromReadWrite/eepromReadWrite.ino @@ -0,0 +1,209 @@ +/* + Copyright (c) 2014 Arduino. All right reserved. + + This library is free software; you can redistribute it and / or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110 - 1301 USA +*/ + +#include "extEEPROM.h" + +extEEPROM myEEPROM(kbits_256, 1, 64, 0x57); + +void setup(void) +{ + SerialUSB.begin(115200); + while (!SerialUSB) { + ; + } + + byte i2cStat = myEEPROM.begin(myEEPROM.twiClock100kHz); + if ( i2cStat != 0 ) { + SerialUSB.println(F("I2C Problem")); + } + + SerialUSB.println( + F("EEPROM Memory commands: read:(a)(l)(r) , write:(a)(d)(w), next read data (n)")); + SerialUSB.println(F("- Commands TO PRESS:")); + SerialUSB.println(F("\t a : memory address to read / write")); + SerialUSB.println(F("\t d : data to write")); + SerialUSB.println(F("\t l : data to write")); + SerialUSB.println(F("\t r : read command")); + SerialUSB.println(F("\t w : write command")); +} + +unsigned long address = 0; +const unsigned int maxDataSize = 1024; //0x8000; // 32 k bytes (32768 = 0x8000) = 256 kbits + +byte data[maxDataSize] = {'p', 'i', 'p', 'p', 'o'}; +unsigned int dataSize = 5; + +void eprom_read_write(bool write) +{ + byte i2cStat = 0; + if (write) { + i2cStat = myEEPROM.write(address, data, dataSize); + } else { + memset(data, 0, maxDataSize); + i2cStat = myEEPROM.read(address, data, dataSize); + } + if ( i2cStat != 0 ) { + //there was a problem + SerialUSB.print(F("I2C Problem: ")); + if ( i2cStat == EEPROM_ADDR_ERR) { + SerialUSB.println(F("Wrong address")); + } else { + SerialUSB.print(F("I2C error: ")); + SerialUSB.print(i2cStat); + SerialUSB.println(F("")); + } + } +} + + +void parse(char inChar) +{ + const char addr_len = 5; + char addr_char[addr_len] = ""; + const char data_len = 3; + char data_char[data_len] = ""; + char size_char[data_len] = ""; + char inc = 0, i = 0, j = 0; + + switch (inChar) { + case 'a': + SerialUSB.print(F("Insert Address as 4 Hex chars (without '0x'): ")); + + while (i < 4) { + while (SerialUSB.available() <= 0) + ; + inc = SerialUSB.read(); + + if (inc == 'q') { + return; + } + + addr_char[i] = inc; + ++i; + } + address = (unsigned long)strtol(addr_char, NULL, 16); + SerialUSB.println(address); + break; + + case 'd': + SerialUSB.print(F("Insert Hex data sequence (without '0x'), return to enter: ")); + memset(data, 0, maxDataSize); + while (true) { + while (SerialUSB.available() <= 0) + ; + inc = SerialUSB.read(); + if (inc == 'q') { + return; + } + if (inc == '\r' || inc == '\n') { + break; + } + + if (inc >= 'a' && inc <= 'f') { + data[j] += inc - 'a' + 10; + } else if (inc >= 'A' && inc <= 'F') { + data[j] += inc - 'A' + 10; + } else if (inc >= '0' && inc <= '9') { + data[j] += inc - '0'; + } else { + return; + } + + if (i % 2) { + j++; + } else { + data[j] = data[j] << 4; + } + i++; + } + dataSize = j; + SerialUSB.println(dataSize); + SerialUSB.println(F("")); + break; + case 'l': + SerialUSB.print(F("Insert data len as 2 Hex chars (without '0x'): ")); + while (i < 2) { + while (SerialUSB.available() <= 0) + ; + inc = SerialUSB.read(); + if (inc == 'q') { + return; + } + + size_char[i] = inc; + ++i; + if (inc == '\n') { + return; + } + } + + dataSize = (unsigned int)strtol(size_char, NULL, 16); + SerialUSB.println(dataSize); + break; + + + case 'n': + address += dataSize; + /* FALLTHROUGH */ + case 'r': + SerialUSB.print(F("reading address: ")); + SerialUSB.println(address, HEX); + + eprom_read_write(false); + for (i = 0; i < dataSize ; ++i) { + SerialUSB.print(data[i], HEX); + SerialUSB.print(F(" ")); + } + SerialUSB.println(); + + break; + + case 'w': + SerialUSB.print(F("writing at address: ")); + SerialUSB.print(address, HEX); + SerialUSB.print(F(", len: ")); + SerialUSB.println(address, dataSize); + for (i = 0; i < dataSize ; ++i) { + SerialUSB.print(data[i], HEX); + SerialUSB.print(F(" ")); + } + eprom_read_write(true); + SerialUSB.println(); + + break; + case 'T': + SerialUSB.println(F("Memory test: writing and verifying the whole memory")); + break; + + default: + break; + } +} + + +void loop(void) +{ + if (SerialUSB.available() > 0) { + char inChar = SerialUSB.read(); + SerialUSB.print(inChar); + parse(inChar); + } + + delay(10); +} + diff --git a/drivers/extEEPROM/examples/eepromTest/eepromTest.ino b/drivers/extEEPROM/examples/eepromTest/eepromTest.ino index 893dc12ec..079daca0c 100644 --- a/drivers/extEEPROM/examples/eepromTest/eepromTest.ino +++ b/drivers/extEEPROM/examples/eepromTest/eepromTest.ino @@ -3,7 +3,7 @@ //Wire a button from digital pin 6 to ground, this is used as a start button //so the sketch doesn't do unnecessary EEPROM writes every time it's reset. //Jack Christensen 09Jul2014 -//Paolo Paolucci 17Mar2016 +//Paolo Paolucci 17Mar2016 (fix 28Jun2017) #include //https://github.com/PaoloP74/extEEPROM @@ -17,7 +17,7 @@ void setup(void) { pinMode(btnStart, INPUT_PULLUP); Serial.begin(115200); - uint8_t eepStatus = eep.begin(twiClock400kHz); //go fast! + uint8_t eepStatus = eep.begin(eep.twiClock400kHz); //go fast! if (eepStatus) { Serial.print(F("extEEPROM.begin() failed, status = ")); Serial.println(eepStatus); diff --git a/drivers/extEEPROM/examples/eepromTest_Wire1/eepromTest_Wire1.ino b/drivers/extEEPROM/examples/eepromTest_Wire1/eepromTest_Wire1.ino new file mode 100644 index 000000000..44a8f8fe7 --- /dev/null +++ b/drivers/extEEPROM/examples/eepromTest_Wire1/eepromTest_Wire1.ino @@ -0,0 +1,233 @@ +//Test extEEPROM library. +//Writes the EEPROM full of 32-bit integers and reads them back to verify. +//Wire a button from digital pin 6 to ground, this is used as a start button +//so the sketch doesn't do unnecessary EEPROM writes every time it's reset. +//Jack Christensen 09Jul2014 +//Paolo Paolucci 17Mar2016 (fix 28Jun2017) +//Mik 03Jan2017 (configured Library to use the Wire1 as I2C channel) + +#include //https://github.com/PaoloP74/extEEPROM + +//One 24LC256 EEPROMs on the bus +const uint32_t totalKBytes = 32; //for read and write test functions +extEEPROM eep(kbits_256, 1, 64, 0x57); //device size, number of devices, page size + +const uint8_t btnStart = 6; //start button + +void setup(void) +{ + uint8_t eepStatus; + pinMode(btnStart, INPUT_PULLUP); + Serial.begin(115200); + while (!SerialUSB) {} + + bool channelInsert = false; + Serial.println(F("Select the number of Wire channel use the eeprom")); + Serial.println(F("0 = Wire")); + Serial.println(F("1 = Wire1")); + Serial.println(F("....")); + Serial.println(F("x = WIRE_INTERFACES_COUNT")); + + do { + if (Serial.available()) { + char I2Cchannel = Serial.read(); + + // only number that are less than WIRE_INTERFACES_COUNT are allowed + if ((I2Cchannel > '0') && (I2Cchannel < ('0' + WIRE_INTERFACES_COUNT))) { + channelInsert = true; + } + + switch ((I2Cchannel - '0')) { + + case 0: + Serial.println(F("Using the default Wire interface")); + eepStatus = eep.begin(eep.twiClock400kHz); //go fast! + break; + + case 1: + Serial.println(F("Using the Wire1 interface")); + eepStatus = eep.begin(eep.twiClock400kHz, &Wire1); //go fast! + break; + + /* + Uncomment till the number of WIRE_INTERFACES_COUNT of your Arduino board + case 2: + Serial.println(F("Using the Wire2 interface")); + eepStatus = eep.begin(eep.twiClock400kHz, &Wire2); //go fast! + break; + + case 3: + Serial.println(F("Using the Wire3 interface")); + eepStatus = eep.begin(eep.twiClock400kHz, &Wire3); //go fast! + break; + + case 4: + Serial.println(F("Using the Wire4 interface")); + eepStatus = eep.begin(eep.twiClock400kHz, &Wire4); //go fast! + break; + + case 5: + Serial.println(F("Using the Wire5 interface")); + eepStatus = eep.begin(eep.twiClock400kHz, &Wire5); //go fast! + break;*/ + + default: + Serial.println(F("A wrong channel has been inserted (Arduino manage max 5)")); + break; + } + } + } while (!channelInsert); + + if (eepStatus) { + Serial.print(F("extEEPROM.begin() failed, status = ")); + Serial.println(eepStatus); + while (1); + } + + Serial.println(F("Started !!")); + + uint8_t chunkSize = + 64; //this can be changed, but must be a multiple of 4 since we're writing 32-bit integers + // eeErase(chunkSize, 0, totalKBytes * 1024 - 1); + eeWrite(chunkSize); + eeRead(chunkSize); + + dump(0, 32); //the first 32 bytes + dump(32256, 64); //the last 64 bytes + //dump(32512, 64); //across the device boundary + //dump(65520, 16); //the last 16 bytes +} + +void loop(void) +{ +} + +//write test data (32-bit integers) to eeprom, "chunk" bytes at a time +void eeWrite(uint8_t chunk) +{ + chunk &= 0xFC; //force chunk to be a multiple of 4 + uint8_t data[chunk]; + uint32_t val = 0; + Serial.println(F("Writing...")); + uint32_t msStart = millis(); + + for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) { + if ( (addr & 0xFFF) == 0 ) { + Serial.println(addr); + } + for (uint8_t c = 0; c < chunk; c += 4) { + data[c + 0] = val >> 24; + data[c + 1] = val >> 16; + data[c + 2] = val >> 8; + data[c + 3] = val; + ++val; + } + eep.write(addr, data, chunk); + } + uint32_t msLapse = millis() - msStart; + Serial.print(F("Write lapse: ")); + Serial.print(msLapse); + Serial.println(F(" ms")); +} + +//read test data (32-bit integers) from eeprom, "chunk" bytes at a time +void eeRead(uint8_t chunk) +{ + chunk &= 0xFC; //force chunk to be a multiple of 4 + uint8_t data[chunk]; + uint32_t val = 0, testVal; + Serial.println(F("Reading...")); + uint32_t msStart = millis(); + + for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) { + if ( (addr & 0xFFF) == 0 ) { + Serial.println(addr); + } + eep.read(addr, data, chunk); + for (uint8_t c = 0; c < chunk; c += 4) { + testVal = ((uint32_t)data[c + 0] << 24) + ((uint32_t)data[c + 1] << 16) + (( + uint32_t)data[c + 2] << 8) + (uint32_t)data[c + 3]; + if (testVal != val) { + Serial.print(F("Error @ addr ")); + Serial.print(addr + c); + Serial.print(F(" Expected ")); + Serial.print(val); + Serial.print(F(" Read ")); + Serial.print(testVal); + Serial.print(F(" 0x")); + Serial.println(testVal, HEX); + } + ++val; + } + } + uint32_t msLapse = millis() - msStart; + Serial.print(F("Last value: ")); + Serial.print(val); + Serial.print(F(" Read lapse: ")); + Serial.print(msLapse); + Serial.println(F(" ms")); +} + +//write 0xFF to eeprom, "chunk" bytes at a time +void eeErase(uint8_t chunk, uint32_t startAddr, uint32_t endAddr) +{ + chunk &= 0xFC; //force chunk to be a multiple of 4 + uint8_t data[chunk]; + Serial.println(F("Erasing...")); + for (int i = 0; i < chunk; i++) { + data[i] = 0xFF; + } + uint32_t msStart = millis(); + + for (uint32_t a = startAddr; a <= endAddr; a += chunk) { + if ( (a & 0xFFF) == 0 ) { + Serial.println(a); + } + eep.write(a, data, chunk); + } + uint32_t msLapse = millis() - msStart; + Serial.print(F("Erase lapse: ")); + Serial.print(msLapse); + Serial.print(F(" ms")); +} + +//dump eeprom contents, 16 bytes at a time. +//always dumps a multiple of 16 bytes. +void dump(uint32_t startAddr, uint32_t nBytes) +{ + Serial.print(F("EEPROM DUMP 0x")); + Serial.print(startAddr, HEX); + Serial.print(F(" 0x")); + Serial.print(nBytes, HEX); + Serial.print(F(" ")); + Serial.print(startAddr); + Serial.print(F(" ")); + Serial.println(nBytes); + uint32_t nRows = (nBytes + 15) >> 4; + + uint8_t d[16]; + for (uint32_t r = 0; r < nRows; r++) { + uint32_t a = startAddr + 16 * r; + eep.read(a, d, 16); + Serial.print(F("0x")); + if ( a < 16 * 16 * 16 ) { + Serial.print(F("0")); + } + if ( a < 16 * 16 ) { + Serial.print(F("0")); + } + if ( a < 16 ) { + Serial.print(F("0")); + } + Serial.print(a, HEX); + Serial.print(F(" ")); + for ( int c = 0; c < 16; c++ ) { + if ( d[c] < 16 ) { + Serial.print(F("0")); + Serial.print(d[c], HEX); + Serial.print( c == 7 ? " " : " "); + } + } + Serial.println(F("")); + } +} diff --git a/drivers/extEEPROM/extEEPROM.cpp b/drivers/extEEPROM/extEEPROM.cpp index f6d3bc66b..5b56c17b6 100644 --- a/drivers/extEEPROM/extEEPROM.cpp +++ b/drivers/extEEPROM/extEEPROM.cpp @@ -1,4 +1,4 @@ -/*-----------------------------------------------------------------------------* +/*-----------------------------------------------------------------------------* * extEEPROM.cpp - Arduino library to support external I2C EEPROMs. * * * * This library will work with most I2C serial EEPROM chips between 2k bits * @@ -56,11 +56,10 @@ *-----------------------------------------------------------------------------*/ #include "extEEPROM.h" -#include -// added for SAMD arch, tekka 2017 -#if !defined(BUFFER_LENGTH) -#define BUFFER_LENGTH SERIAL_BUFFER_SIZE +// workaround, BUFFER_LENGTH is not defined in Wire.h for SAMD controllers +#ifndef BUFFER_LENGTH +#define BUFFER_LENGTH 32 #endif // Constructor. @@ -75,6 +74,7 @@ extEEPROM::extEEPROM(eeprom_size_t deviceCapacity, byte nDevice, unsigned int pageSize, uint8_t eepromAddr) { + communication = NULL; _dvcCapacity = deviceCapacity; _nDevice = nDevice; _pageSize = pageSize; @@ -104,16 +104,17 @@ extEEPROM::extEEPROM(eeprom_size_t deviceCapacity, byte nDevice, unsigned int pa //when using a 400kHz bus speed and there are multiple I2C devices on the //bus (other than EEPROM), call extEEPROM::begin() after any initialization //calls for the other devices to ensure the intended I2C clock speed is set. -byte extEEPROM::begin(twiClockFreq_t twiFreq) +byte extEEPROM::begin(twiClockFreq_t twiFreq, TwoWire *_comm) { - Wire.begin(); - Wire.setClock(twiFreq); - Wire.beginTransmission(_eepromAddr); + communication = _comm; + communication->begin(); + communication->setClock(twiFreq); + communication->beginTransmission(_eepromAddr); if (_nAddrBytes == 2) { - Wire.write((byte)0); //high addr byte + communication->write((byte)0); //high addr byte } - Wire.write((byte)0); //low addr byte - return Wire.endTransmission(); + communication->write((byte)0); //low addr byte + return communication->endTransmission(); } //Write bytes to external EEPROM. @@ -129,21 +130,18 @@ byte extEEPROM::write(unsigned long addr, byte *values, unsigned int nBytes) } while (nBytes > 0) { - uint8_t ctrlByte; //control byte (I2C device address & chip/block select bits) - uint16_t nWrite; //number of bytes to write - uint16_t nPage; //number of bytes remaining on current page, starting at addr - nPage = _pageSize - ( addr & (_pageSize - 1) ); + const uint16_t nPage = _pageSize - ( addr & (_pageSize - 1) ); //find min(nBytes, nPage, BUFFER_LENGTH) -- BUFFER_LENGTH is defined in the Wire library. - nWrite = nBytes < nPage ? nBytes : nPage; + uint16_t nWrite = nBytes < nPage ? nBytes : nPage; nWrite = BUFFER_LENGTH - _nAddrBytes < nWrite ? BUFFER_LENGTH - _nAddrBytes : nWrite; - ctrlByte = _eepromAddr | (byte) (addr >> _csShift); - Wire.beginTransmission(ctrlByte); + const uint8_t ctrlByte = _eepromAddr | (byte) (addr >> _csShift); + communication->beginTransmission(ctrlByte); if (_nAddrBytes == 2) { - Wire.write( (byte) (addr >> 8) ); //high addr byte + communication->write( (byte) (addr >> 8) ); //high addr byte } - Wire.write( (byte) addr ); //low addr byte - Wire.write(values, nWrite); - txStatus = Wire.endTransmission(); + communication->write( (byte) addr ); //low addr byte + communication->write(values, nWrite); + txStatus = communication->endTransmission(); if (txStatus != 0) { return txStatus; } @@ -151,12 +149,12 @@ byte extEEPROM::write(unsigned long addr, byte *values, unsigned int nBytes) //wait up to 50ms for the write to complete for (uint8_t i=100; i; --i) { delayMicroseconds(500); //no point in waiting too fast - Wire.beginTransmission(ctrlByte); + communication->beginTransmission(ctrlByte); if (_nAddrBytes == 2) { - Wire.write((byte)0); //high addr byte + communication->write((byte)0); //high addr byte } - Wire.write((byte)0); //low addr byte - txStatus = Wire.endTransmission(); + communication->write((byte)0); //low addr byte + txStatus = communication->endTransmission(); if (txStatus == 0) { break; } @@ -183,27 +181,23 @@ byte extEEPROM::read(unsigned long addr, byte *values, unsigned int nBytes) } while (nBytes > 0) { - byte ctrlByte; - byte rxStatus; - uint16_t nRead; //number of bytes to read - uint16_t nPage; //number of bytes remaining on current page, starting at addr - nPage = _pageSize - ( addr & (_pageSize - 1) ); - nRead = nBytes < nPage ? nBytes : nPage; + const uint16_t nPage = _pageSize - ( addr & (_pageSize - 1) ); + uint16_t nRead = nBytes < nPage ? nBytes : nPage; nRead = BUFFER_LENGTH < nRead ? BUFFER_LENGTH : nRead; - ctrlByte = _eepromAddr | (byte) (addr >> _csShift); - Wire.beginTransmission(ctrlByte); + byte ctrlByte = _eepromAddr | (byte) (addr >> _csShift); + communication->beginTransmission(ctrlByte); if (_nAddrBytes == 2) { - Wire.write( (byte) (addr >> 8) ); //high addr byte + communication->write( (byte) (addr >> 8) ); //high addr byte } - Wire.write( (byte) addr ); //low addr byte - rxStatus = Wire.endTransmission(); + communication->write( (byte) addr ); //low addr byte + const byte rxStatus = communication->endTransmission(); if (rxStatus != 0) { return rxStatus; //read error } - Wire.requestFrom(ctrlByte, nRead); + communication->requestFrom(ctrlByte, nRead); for (byte i=0; iread(); } addr += nRead; //increment the EEPROM address diff --git a/drivers/extEEPROM/extEEPROM.h b/drivers/extEEPROM/extEEPROM.h index 1fe49a48d..42f43dc7e 100644 --- a/drivers/extEEPROM/extEEPROM.h +++ b/drivers/extEEPROM/extEEPROM.h @@ -1,4 +1,4 @@ -/*-----------------------------------------------------------------------------* +/*-----------------------------------------------------------------------------* * extEEPROM.h - Arduino library to support external I2C EEPROMs. * * * * This library will work with most I2C serial EEPROM chips between 2k bits * @@ -55,10 +55,15 @@ * http://creativecommons.org/licenses/by-sa/4.0/ * *-----------------------------------------------------------------------------*/ +/* + * tekka 2018: + * Re-implementing extEEPROM::update(unsigned long addr, byte value); + */ #ifndef extEEPROM_h #define extEEPROM_h #include +#include //EEPROM size in kilobits. EEPROM part numbers are usually designated in k-bits. enum eeprom_size_t { @@ -75,16 +80,24 @@ enum eeprom_size_t { kbits_2048 = 2048 }; -enum twiClockFreq_t { twiClock100kHz = 100000, twiClock400kHz = 400000 }; - //EEPROM addressing error, returned by write() or read() if upper address bound is exceeded const uint8_t EEPROM_ADDR_ERR = 9; /** extEEPROM class */ - class extEEPROM { +private: + // the private attribute used to comunicate with the correct I2C SERCOM + TwoWire *communication; + public: + /** + * I2C clock frequencies + */ + enum twiClockFreq_t { + twiClock100kHz = 100000, //!< twiClock100kHz + twiClock400kHz = 400000 //!< twiClock400kHz + }; /** * @brief Constructor * @param deviceCapacity @@ -94,7 +107,9 @@ class extEEPROM */ extEEPROM(eeprom_size_t deviceCapacity, byte nDevice, unsigned int pageSize, byte eepromAddr = 0x50); - byte begin(twiClockFreq_t twiFreq = twiClock100kHz); //!< begin() + + // It is ready for every I2C Sercom, by default use the main Wire + byte begin(twiClockFreq_t twiFreq = twiClock100kHz, TwoWire *_comm=&Wire); //!< begin() byte write(unsigned long addr, byte *values, unsigned int nBytes); //!< write() byte write(unsigned long addr, byte value); //!< write() byte read(unsigned long addr, byte *values, unsigned int nBytes); //!< read() diff --git a/drivers/extEEPROM/library.properties b/drivers/extEEPROM/library.properties deleted file mode 100644 index 647756909..000000000 --- a/drivers/extEEPROM/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=extEEPROM -version=3.3.2 -author=Jack Christensen -maintainer=Paolo Paolucci -sentence=Arduino library to support external I2C EEPROMs. -paragraph=This library will work with most I2C serial EEPROM chips between 2k bits and 2048k bits (2M bits) in size. Multiple EEPROMs on the bus are supported as a single address space. -category=Data Storage -url=https://github.com/PaoloP74/extEEPROM -architectures=* -includes=Wire.h,extEEPROM.h diff --git a/hal/architecture/AVR/MyHwAVR.cpp b/hal/architecture/AVR/MyHwAVR.cpp index 880691cc6..f62ed0495 100644 --- a/hal/architecture/AVR/MyHwAVR.cpp +++ b/hal/architecture/AVR/MyHwAVR.cpp @@ -25,6 +25,9 @@ bool hwInit(void) { #if !defined(MY_DISABLED_SERIAL) MY_SERIALDEVICE.begin(MY_BAUD_RATE); +#if defined(MY_GATEWAY_SERIAL) + while (!MY_SERIALDEVICE) {} +#endif #endif return true; } @@ -253,19 +256,19 @@ inline void hwRandomNumberInit(void) randomSeed(seed); } -bool hwUniqueID(unique_id_t* uniqueID) +bool hwUniqueID(unique_id_t *uniqueID) { // padding (void)memset(uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t)); // no unique ID for non-PB AVR, use HW specifics for diversification - *((uint8_t*)uniqueID) = boot_signature_byte_get(0x00); - *((uint8_t*)uniqueID + 1) = boot_signature_byte_get(0x02); - *((uint8_t*)uniqueID + 2) = boot_signature_byte_get(0x04); - *((uint8_t*)uniqueID + 3) = boot_signature_byte_get(0x01); //OSCCAL + *((uint8_t *)uniqueID) = boot_signature_byte_get(0x00); + *((uint8_t *)uniqueID + 1) = boot_signature_byte_get(0x02); + *((uint8_t *)uniqueID + 2) = boot_signature_byte_get(0x04); + *((uint8_t *)uniqueID + 3) = boot_signature_byte_get(0x01); //OSCCAL #if defined(__AVR_ATmega328PB__) // ATMEGA328PB specifics, has unique ID for(uint8_t idx = 0; idx < 10; idx++) { - *((uint8_t*)uniqueID + 4 + idx) = boot_signature_byte_get(0xE + idx); + *((uint8_t *)uniqueID + 4 + idx) = boot_signature_byte_get(0xE + idx); } return true; // unique ID returned #else @@ -329,6 +332,11 @@ uint16_t hwCPUFrequency(void) return TCNT1 * 2048UL / 100000UL; } +int8_t hwCPUTemperature(void) +{ + return -127; // not implemented yet +} + uint16_t hwFreeMem(void) { extern int __heap_start, *__brkval; @@ -338,9 +346,6 @@ uint16_t hwFreeMem(void) void hwDebugPrint(const char *fmt, ... ) { -#ifndef MY_DEBUGDEVICE -#define MY_DEBUGDEVICE MY_SERIALDEVICE -#endif #ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL @@ -354,14 +359,14 @@ void hwDebugPrint(const char *fmt, ... ) MY_DEBUGDEVICE.print(F(" ")); #endif va_list args; - va_start (args, fmt ); + va_start(args, fmt); vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #endif - va_end (args); + va_end(args); MY_DEBUGDEVICE.print(fmtBuffer); MY_DEBUGDEVICE.flush(); #else diff --git a/hal/architecture/AVR/MyHwAVR.h b/hal/architecture/AVR/MyHwAVR.h index 8da3f40d2..16b50b104 100644 --- a/hal/architecture/AVR/MyHwAVR.h +++ b/hal/architecture/AVR/MyHwAVR.h @@ -39,6 +39,10 @@ #define MY_SERIALDEVICE Serial #endif +#ifndef MY_DEBUGDEVICE +#define MY_DEBUGDEVICE MY_SERIALDEVICE +#endif + // Define these as macros to save valuable space #define hwDigitalWrite(__pin, __value) digitalWriteFast(__pin, __value) #define hwDigitalRead(__pin) digitalReadFast(__pin) diff --git a/drivers/AVR/DigitalIO/DigitalIO.h b/hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h similarity index 100% rename from drivers/AVR/DigitalIO/DigitalIO.h rename to hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h diff --git a/drivers/AVR/DigitalIO/DigitalPin.h b/hal/architecture/AVR/drivers/DigitalIO/DigitalPin.h similarity index 100% rename from drivers/AVR/DigitalIO/DigitalPin.h rename to hal/architecture/AVR/drivers/DigitalIO/DigitalPin.h diff --git a/drivers/AVR/DigitalIO/I2cConstants.h b/hal/architecture/AVR/drivers/DigitalIO/I2cConstants.h similarity index 100% rename from drivers/AVR/DigitalIO/I2cConstants.h rename to hal/architecture/AVR/drivers/DigitalIO/I2cConstants.h diff --git a/drivers/AVR/DigitalIO/PinIO.cpp b/hal/architecture/AVR/drivers/DigitalIO/PinIO.cpp similarity index 100% rename from drivers/AVR/DigitalIO/PinIO.cpp rename to hal/architecture/AVR/drivers/DigitalIO/PinIO.cpp diff --git a/drivers/AVR/DigitalIO/PinIO.h b/hal/architecture/AVR/drivers/DigitalIO/PinIO.h similarity index 100% rename from drivers/AVR/DigitalIO/PinIO.h rename to hal/architecture/AVR/drivers/DigitalIO/PinIO.h diff --git a/drivers/AVR/DigitalIO/SoftI2cMaster.cpp b/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.cpp similarity index 100% rename from drivers/AVR/DigitalIO/SoftI2cMaster.cpp rename to hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.cpp diff --git a/drivers/AVR/DigitalIO/SoftI2cMaster.h b/hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.h similarity index 100% rename from drivers/AVR/DigitalIO/SoftI2cMaster.h rename to hal/architecture/AVR/drivers/DigitalIO/SoftI2cMaster.h diff --git a/drivers/AVR/DigitalIO/SoftSPI.h b/hal/architecture/AVR/drivers/DigitalIO/SoftSPI.h similarity index 100% rename from drivers/AVR/DigitalIO/SoftSPI.h rename to hal/architecture/AVR/drivers/DigitalIO/SoftSPI.h diff --git a/drivers/AVR/DigitalIO/attic/ADS7818.h b/hal/architecture/AVR/drivers/DigitalIO/attic/ADS7818.h similarity index 100% rename from drivers/AVR/DigitalIO/attic/ADS7818.h rename to hal/architecture/AVR/drivers/DigitalIO/attic/ADS7818.h diff --git a/drivers/AVR/DigitalIO/attic/MCP320X.h b/hal/architecture/AVR/drivers/DigitalIO/attic/MCP320X.h similarity index 100% rename from drivers/AVR/DigitalIO/attic/MCP320X.h rename to hal/architecture/AVR/drivers/DigitalIO/attic/MCP320X.h diff --git a/drivers/AVR/DigitalIO/attic/MCP355X.h b/hal/architecture/AVR/drivers/DigitalIO/attic/MCP355X.h similarity index 100% rename from drivers/AVR/DigitalIO/attic/MCP355X.h rename to hal/architecture/AVR/drivers/DigitalIO/attic/MCP355X.h diff --git a/drivers/AVR/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinBlink/DigitalPinBlink.ino diff --git a/drivers/AVR/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinConfigToggle/DigitalPinConfigToggle.ino diff --git a/drivers/AVR/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinReadWrite/DigitalPinReadWrite.ino diff --git a/drivers/AVR/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/DigitalPinShiftOut/DigitalPinShiftOut.ino diff --git a/drivers/AVR/DigitalIO/examples/PinIOBegin/PinIOBegin.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOBegin/PinIOBegin.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/PinIOBegin/PinIOBegin.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/PinIOBegin/PinIOBegin.ino diff --git a/drivers/AVR/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/PinIOConfigToggle/PinIOConfigToggle.ino diff --git a/drivers/AVR/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/PinIOReadWrite/PinIOReadWrite.ino diff --git a/drivers/AVR/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/ScanI2cBus/ScanI2cBus.ino diff --git a/drivers/AVR/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/SoftDS1307Utility/SoftDS1307Utility.ino diff --git a/drivers/AVR/DigitalIO/examples/testArduino/testArduino.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testArduino/testArduino.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/testArduino/testArduino.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/testArduino/testArduino.ino diff --git a/drivers/AVR/DigitalIO/examples/testDigitalPin/testDigitalPin.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testDigitalPin/testDigitalPin.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/testDigitalPin/testDigitalPin.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/testDigitalPin/testDigitalPin.ino diff --git a/drivers/AVR/DigitalIO/examples/testFastDigital/testFastDigital.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testFastDigital/testFastDigital.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/testFastDigital/testFastDigital.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/testFastDigital/testFastDigital.ino diff --git a/drivers/AVR/DigitalIO/examples/testPinIO/testPinIO.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testPinIO/testPinIO.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/testPinIO/testPinIO.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/testPinIO/testPinIO.ino diff --git a/drivers/AVR/DigitalIO/examples/testSoftSPI/testSoftSPI.ino b/hal/architecture/AVR/drivers/DigitalIO/examples/testSoftSPI/testSoftSPI.ino similarity index 100% rename from drivers/AVR/DigitalIO/examples/testSoftSPI/testSoftSPI.ino rename to hal/architecture/AVR/drivers/DigitalIO/examples/testSoftSPI/testSoftSPI.ino diff --git a/drivers/AVR/DigitalWriteFast/digitalWriteFast.h b/hal/architecture/AVR/drivers/DigitalWriteFast/digitalWriteFast.h similarity index 100% rename from drivers/AVR/DigitalWriteFast/digitalWriteFast.h rename to hal/architecture/AVR/drivers/DigitalWriteFast/digitalWriteFast.h diff --git a/hal/architecture/ESP32/MyHwESP32.cpp b/hal/architecture/ESP32/MyHwESP32.cpp index 94d89d982..4577a15a1 100644 --- a/hal/architecture/ESP32/MyHwESP32.cpp +++ b/hal/architecture/ESP32/MyHwESP32.cpp @@ -28,6 +28,9 @@ bool hwInit(void) { #if !defined(MY_DISABLED_SERIAL) MY_SERIALDEVICE.begin(MY_BAUD_RATE, SERIAL_8N1); +#if defined(MY_GATEWAY_SERIAL) + while (!MY_SERIALDEVICE) {} +#endif #endif return EEPROM.begin(MY_EEPROM_SIZE); } @@ -128,10 +131,9 @@ uint16_t hwCPUFrequency(void) return static_cast(ESP.getCpuFreqMHz() * 10); } -uint8_t hwCPUTemperature(void) +int8_t hwCPUTemperature(void) { - // CPU temperature in °C - return static_cast(temperatureRead()); + return -127; // not implemented yet } uint16_t hwFreeMem(void) @@ -141,20 +143,20 @@ uint16_t hwFreeMem(void) void hwDebugPrint(const char *fmt, ...) { +#ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) - snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%d;0;%d;%lu "), C_INTERNAL, I_LOG_MESSAGE, - millis()); - MY_SERIALDEVICE.print(fmtBuffer); + snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "), + C_INTERNAL, I_LOG_MESSAGE, hwMillis()); + MY_DEBUGDEVICE.print(fmtBuffer); #else // prepend timestamp - MY_SERIALDEVICE.print(millis()); - MY_SERIALDEVICE.print(" "); + MY_DEBUGDEVICE.print(hwMillis()); + MY_DEBUGDEVICE.print(F(" ")); #endif va_list args; va_start(args, fmt); - // cppcheck-suppress wrongPrintfScanfArgNum vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node @@ -162,6 +164,9 @@ void hwDebugPrint(const char *fmt, ...) fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #endif va_end(args); - MY_SERIALDEVICE.print(fmtBuffer); - MY_SERIALDEVICE.flush(); + MY_DEBUGDEVICE.print(fmtBuffer); + MY_DEBUGDEVICE.flush(); +#else + (void)fmt; +#endif } diff --git a/hal/architecture/ESP32/MyHwESP32.h b/hal/architecture/ESP32/MyHwESP32.h index d7929fbee..4aa8890da 100644 --- a/hal/architecture/ESP32/MyHwESP32.h +++ b/hal/architecture/ESP32/MyHwESP32.h @@ -47,7 +47,13 @@ #define CRYPTO_LITTLE_ENDIAN +#ifndef MY_SERIALDEVICE #define MY_SERIALDEVICE Serial +#endif + +#ifndef MY_DEBUGDEVICE +#define MY_DEBUGDEVICE MY_SERIALDEVICE +#endif #define MY_EEPROM_SIZE 1024 diff --git a/hal/architecture/ESP8266/MyHwESP8266.cpp b/hal/architecture/ESP8266/MyHwESP8266.cpp index 74158bcb6..fd68deb3a 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.cpp +++ b/hal/architecture/ESP8266/MyHwESP8266.cpp @@ -25,6 +25,9 @@ bool hwInit(void) #if !defined(MY_DISABLED_SERIAL) MY_SERIALDEVICE.begin(MY_BAUD_RATE, SERIAL_8N1, MY_ESP8266_SERIAL_MODE, 1); MY_SERIALDEVICE.setDebugOutput(true); +#if defined(MY_GATEWAY_SERIAL) + while (!MY_SERIALDEVICE) {} +#endif #endif EEPROM.begin(EEPROM_size); return true; @@ -32,7 +35,7 @@ bool hwInit(void) void hwReadConfigBlock(void *buf, void *addr, size_t length) { - uint8_t* dst = static_cast(buf); + uint8_t *dst = static_cast(buf); int pos = reinterpret_cast(addr); while (length-- > 0) { *dst++ = EEPROM.read(pos++); @@ -41,7 +44,7 @@ void hwReadConfigBlock(void *buf, void *addr, size_t length) void hwWriteConfigBlock(void *buf, void *addr, size_t length) { - uint8_t* src = static_cast(buf); + uint8_t *src = static_cast(buf); int pos = reinterpret_cast(addr); while (length-- > 0) { EEPROM.write(pos++, *src++); @@ -53,23 +56,23 @@ void hwWriteConfigBlock(void *buf, void *addr, size_t length) uint8_t hwReadConfig(const int addr) { uint8_t value; - hwReadConfigBlock(&value, reinterpret_cast(addr), 1); + hwReadConfigBlock(&value, reinterpret_cast(addr), 1); return value; } void hwWriteConfig(const int addr, uint8_t value) { - hwWriteConfigBlock(&value, reinterpret_cast(addr), 1); + hwWriteConfigBlock(&value, reinterpret_cast(addr), 1); } bool hwUniqueID(unique_id_t *uniqueID) { // padding - (void)memset((uint8_t*)uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t)); + (void)memset((uint8_t *)uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t)); uint32_t val = ESP.getChipId(); - (void)memcpy((uint8_t*)uniqueID, &val, 4); + (void)memcpy((uint8_t *)uniqueID, &val, 4); val = ESP.getFlashChipId(); - (void)memcpy((uint8_t*)uniqueID + 4, &val, 4); + (void)memcpy((uint8_t *)uniqueID + 4, &val, 4); return true; } @@ -142,6 +145,11 @@ uint16_t hwCPUFrequency(void) return ESP.getCpuFreqMHz()*10; } +int8_t hwCPUTemperature(void) +{ + return -127; +} + uint16_t hwFreeMem(void) { return ESP.getFreeHeap(); @@ -149,9 +157,6 @@ uint16_t hwFreeMem(void) void hwDebugPrint(const char *fmt, ... ) { -#ifndef MY_DEBUGDEVICE -#define MY_DEBUGDEVICE MY_SERIALDEVICE -#endif #ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL @@ -165,7 +170,7 @@ void hwDebugPrint(const char *fmt, ... ) MY_DEBUGDEVICE.print(" "); #endif va_list args; - va_start (args, fmt ); + va_start(args, fmt); // cppcheck-suppress wrongPrintfScanfArgNum vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL @@ -173,7 +178,7 @@ void hwDebugPrint(const char *fmt, ... ) fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #endif - va_end (args); + va_end(args); MY_DEBUGDEVICE.print(fmtBuffer); MY_DEBUGDEVICE.flush(); #else diff --git a/hal/architecture/ESP8266/MyHwESP8266.h b/hal/architecture/ESP8266/MyHwESP8266.h index 5a33fa53a..f0486b88b 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.h +++ b/hal/architecture/ESP8266/MyHwESP8266.h @@ -29,6 +29,10 @@ #define MY_SERIALDEVICE Serial #endif +#ifndef MY_DEBUGDEVICE +#define MY_DEBUGDEVICE MY_SERIALDEVICE +#endif + #define EEPROM_size (1024) // Define these as macros to save valuable space diff --git a/hal/architecture/Linux/MyHwLinuxGeneric.cpp b/hal/architecture/Linux/MyHwLinuxGeneric.cpp index b45cd4e9b..f2ec0c726 100644 --- a/hal/architecture/Linux/MyHwLinuxGeneric.cpp +++ b/hal/architecture/Linux/MyHwLinuxGeneric.cpp @@ -147,6 +147,11 @@ uint16_t hwCPUFrequency(void) return FUNCTION_NOT_SUPPORTED; } +int8_t hwCPUTemperature(void) +{ + return -127; +} + uint16_t hwFreeMem(void) { // TODO: Not supported! diff --git a/hal/architecture/MyHw.h b/hal/architecture/MyHwHAL.h similarity index 95% rename from hal/architecture/MyHw.h rename to hal/architecture/MyHwHAL.h index 5cca78d77..b9c3c8802 100644 --- a/hal/architecture/MyHw.h +++ b/hal/architecture/MyHwHAL.h @@ -18,13 +18,13 @@ */ /** -* @file MyHw.h +* @file MyHwHAL.h * * MySensors hardware abstraction layer */ -#ifndef MyHw_h -#define MyHw_h +#ifndef MyHwHAL_h +#define MyHwHAL_h /** * @def MY_HWID_PADDING_BYTE @@ -93,7 +93,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo * @param uniqueID unique ID * @return True if unique ID successfully retrieved */ -bool hwUniqueID(unique_id_t* uniqueID); +bool hwUniqueID(unique_id_t *uniqueID); /** * CPU voltage @@ -107,6 +107,12 @@ uint16_t hwCPUVoltage(void); */ uint16_t hwCPUFrequency(void); +/** + * Non-calibrated CPU temperature (if available) + * @return CPU temperature in °C + */ +int8_t hwCPUTemperature(void); + /** * Free memory * @return free memory in bytes diff --git a/hal/architecture/NRF5/MyHwNRF5.cpp b/hal/architecture/NRF5/MyHwNRF5.cpp index ee07c7a18..17adf6e28 100644 --- a/hal/architecture/NRF5/MyHwNRF5.cpp +++ b/hal/architecture/NRF5/MyHwNRF5.cpp @@ -33,11 +33,11 @@ volatile uint8_t _wakeUp1Interrupt = volatile uint8_t _wakeUp2Interrupt = INVALID_INTERRUPT_NUM; // Interrupt number for wakeUp2-callback. -void wakeUp1() // place to send the interrupts +void wakeUp1(void) // place to send the interrupts { _wokeUpByInterrupt = _wakeUp1Interrupt; } -void wakeUp2() // place to send the second interrupts +void wakeUp2(void) // place to send the second interrupts { _wokeUpByInterrupt = _wakeUp2Interrupt; } @@ -522,10 +522,15 @@ uint16_t hwCPUFrequency(void) #elif defined(F_CPU) return (F_CPU) / 100000UL; #else - return 16; + return 160; #endif } +int8_t hwCPUTemperature(void) +{ + return -127; // not implemented yet +} + uint16_t hwFreeMem(void) { // TODO: Not supported! @@ -534,9 +539,6 @@ uint16_t hwFreeMem(void) void hwDebugPrint(const char *fmt, ...) { -#ifndef MY_DEBUGDEVICE -#define MY_DEBUGDEVICE MY_SERIALDEVICE -#endif #ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL @@ -550,14 +552,14 @@ void hwDebugPrint(const char *fmt, ...) MY_DEBUGDEVICE.print(F(" ")); #endif va_list args; - va_start (args, fmt ); + va_start(args, fmt); vsnprintf(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #endif - va_end (args); + va_end(args); MY_DEBUGDEVICE.print(fmtBuffer); MY_DEBUGDEVICE.flush(); #else diff --git a/hal/architecture/NRF5/MyHwNRF5.h b/hal/architecture/NRF5/MyHwNRF5.h index 70a26097f..9561ee338 100644 --- a/hal/architecture/NRF5/MyHwNRF5.h +++ b/hal/architecture/NRF5/MyHwNRF5.h @@ -28,6 +28,14 @@ #define CRYPTO_LITTLE_ENDIAN +#ifndef MY_SERIALDEVICE +#define MY_SERIALDEVICE Serial +#endif + +#ifndef MY_DEBUGDEVICE +#define MY_DEBUGDEVICE MY_SERIALDEVICE +#endif + // Define NRF5_SOFTDEVICE when SoftDevice found #if defined(S110) || defined(S130) || defined(S132) || defined(S140) #ifndef SOFTDEVICE_PRESENT @@ -40,8 +48,9 @@ #define ARDUINO_ARCH_NRF5 #endif -#include "drivers/NRF5/nrf5_wiring_digital.c" -#include "drivers/NRF5/wdt.h" +#include "hal/architecture/NRF5/drivers/nrf5_wiring_digital.c" +#include "hal/architecture/NRF5/drivers/wdt.h" +#include "hal/architecture/NRF5/drivers/nrf_temp.h" #include "drivers/NVM/NVRAM.h" #include "drivers/NVM/VirtualPage.h" #include @@ -116,10 +125,6 @@ void hwRandomNumberInit(void); ssize_t hwGetentropy(void *__buffer, size_t __length); #define MY_HW_HAS_GETENTROPY -#ifndef MY_SERIALDEVICE -#define MY_SERIALDEVICE Serial -#endif - /** * Disable all interrupts. * Helper function for MY_CRITICAL_SECTION. diff --git a/drivers/NRF5/Flash.cpp b/hal/architecture/NRF5/drivers/Flash.cpp similarity index 100% rename from drivers/NRF5/Flash.cpp rename to hal/architecture/NRF5/drivers/Flash.cpp diff --git a/drivers/NRF5/nrf5_wiring_constants.h b/hal/architecture/NRF5/drivers/nrf5_wiring_constants.h similarity index 100% rename from drivers/NRF5/nrf5_wiring_constants.h rename to hal/architecture/NRF5/drivers/nrf5_wiring_constants.h diff --git a/drivers/NRF5/nrf5_wiring_digital.c b/hal/architecture/NRF5/drivers/nrf5_wiring_digital.c similarity index 100% rename from drivers/NRF5/nrf5_wiring_digital.c rename to hal/architecture/NRF5/drivers/nrf5_wiring_digital.c diff --git a/hal/architecture/NRF5/drivers/nrf_temp.h b/hal/architecture/NRF5/drivers/nrf_temp.h new file mode 100644 index 000000000..007fc7d9a --- /dev/null +++ b/hal/architecture/NRF5/drivers/nrf_temp.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2012 - 2018, Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef NRF_TEMP_H__ +#define NRF_TEMP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @defgroup nrf_temp_hal TEMP HAL +* @{ +* @ingroup nrf_temp temperature_example +* @brief Temperature module init and read functions. +*/ + +#define MASK_SIGN (0x00000200UL) //!< MASK_SIGN +#define MASK_SIGN_EXTENSION (0xFFFFFC00UL) //!< MASK_SIGN_EXTENSION + +/** + * @brief Function for preparing the temp module for temperature measurement. + * + * This function initializes the TEMP module and writes to the hidden configuration register. + */ +static __INLINE void nrf_temp_init(void) +{ + /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */ + *(uint32_t *) 0x4000C504 = 0; +} + +/** + * @brief Function for reading temperature measurement. + * + * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value. + */ +static __INLINE int32_t nrf_temp_read(void) +{ + /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */ + return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (int32_t)(NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : + (NRF_TEMP->TEMP); +} + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/drivers/NRF5/wdt.h b/hal/architecture/NRF5/drivers/wdt.h similarity index 100% rename from drivers/NRF5/wdt.h rename to hal/architecture/NRF5/drivers/wdt.h diff --git a/hal/architecture/SAMD/MyHwSAMD.cpp b/hal/architecture/SAMD/MyHwSAMD.cpp index e0e1f4d6d..5f8f65235 100644 --- a/hal/architecture/SAMD/MyHwSAMD.cpp +++ b/hal/architecture/SAMD/MyHwSAMD.cpp @@ -19,7 +19,6 @@ #include "MyHwSAMD.h" - /* int8_t pinIntTrigger = 0; void wakeUp() //place to send the interrupts @@ -43,14 +42,14 @@ ISR (WDT_vect) void hwReadConfigBlock(void *buf, void *addr, size_t length) { - uint8_t* dst = static_cast(buf); + uint8_t *dst = static_cast(buf); const int offs = reinterpret_cast(addr); (void)eep.read(offs, dst, length); } void hwWriteConfigBlock(void *buf, void *addr, size_t length) { - uint8_t* src = static_cast(buf); + uint8_t *src = static_cast(buf); const int offs = reinterpret_cast(addr); // use update() instead of write() to reduce e2p wear off (void)eep.update(offs, src, length); @@ -68,12 +67,13 @@ void hwWriteConfig(const int addr, uint8_t value) bool hwInit(void) { +#if !defined(MY_DISABLED_SERIAL) MY_SERIALDEVICE.begin(MY_BAUD_RATE); #if defined(MY_GATEWAY_SERIAL) while (!MY_SERIALDEVICE) {} #endif - - const uint8_t eepInit = eep.begin(MY_EXT_EEPROM_TWI_CLOCK); +#endif + const uint8_t eepInit = eep.begin(MY_EXT_EEPROM_TWI_CLOCK, &Wire); #if defined(SENSEBENDER_GW_SAMD_V1) // check connection to external EEPROM - only sensebender GW return eepInit==0; @@ -129,40 +129,44 @@ bool hwUniqueID(unique_id_t *uniqueID) return true; } -uint16_t hwCPUVoltage(void) +// Wait for synchronization of registers between the clock domains +static __inline__ void syncADC() __attribute__((always_inline, unused)); +static void syncADC() { - - // disable ADC while (ADC->STATUS.bit.SYNCBUSY); - ADC->CTRLA.bit.ENABLE = 0x00; - - // internal 1V reference (default) - analogReference(AR_INTERNAL1V0); - // 12 bit resolution (default) - analogWriteResolution(12); - // MUXp 0x1B = SCALEDIOVCC/4 => connected to Vcc - ADC->INPUTCTRL.bit.MUXPOS = 0x1B ; +} +uint16_t hwCPUVoltage(void) +{ + // Set ADC reference to internal 1v + ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; + ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; + syncADC(); + // Set to 10 bits reading resolution + ADC->CTRLB.reg = ADC_CTRLB_RESSEL_10BIT | ADC_CTRLB_PRESCALER_DIV256; + syncADC(); + // Select MUXPOS as SCALEDIOVCC/4 channel, and MUXNEG as internal ground + ADC->INPUTCTRL.bit.MUXPOS = ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC_Val; + ADC->INPUTCTRL.bit.MUXNEG = ADC_INPUTCTRL_MUXNEG_GND_Val; + syncADC(); // enable ADC - while (ADC->STATUS.bit.SYNCBUSY); - ADC->CTRLA.bit.ENABLE = 0x01; + ADC->CTRLA.bit.ENABLE = 1; + syncADC(); // start conversion - while (ADC->STATUS.bit.SYNCBUSY); ADC->SWTRIG.bit.START = 1; // clear the Data Ready flag ADC->INTFLAG.bit.RESRDY = 1; + syncADC(); // start conversion again, since The first conversion after the reference is changed must not be used. - while (ADC->STATUS.bit.SYNCBUSY); ADC->SWTRIG.bit.START = 1; - // waiting for conversion to complete while (!ADC->INTFLAG.bit.RESRDY); + syncADC(); const uint32_t valueRead = ADC->RESULT.reg; - // disable ADC - while (ADC->STATUS.bit.SYNCBUSY); - ADC->CTRLA.bit.ENABLE = 0x00; - + ADC->CTRLA.bit.ENABLE = 0; + syncADC(); + // value is 1/4 scaled, multiply by 4 return valueRead * 4; } @@ -172,6 +176,12 @@ uint16_t hwCPUFrequency(void) return F_CPU / 100000UL; } +int8_t hwCPUTemperature(void) +{ + return -127; // not implemented yet +} + + uint16_t hwFreeMem(void) { // TODO: Not supported! @@ -180,9 +190,6 @@ uint16_t hwFreeMem(void) void hwDebugPrint(const char *fmt, ... ) { -#ifndef MY_DEBUGDEVICE -#define MY_DEBUGDEVICE MY_SERIALDEVICE -#endif #ifndef MY_DISABLED_SERIAL if (MY_DEBUGDEVICE) { char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; @@ -197,14 +204,14 @@ void hwDebugPrint(const char *fmt, ... ) MY_DEBUGDEVICE.print(" "); #endif va_list args; - va_start (args, fmt ); + va_start(args, fmt); vsnprintf(fmtBuffer, sizeof(fmtBuffer), fmt, args); #ifdef MY_GATEWAY_SERIAL // Truncate message if this is gateway node fmtBuffer[sizeof(fmtBuffer) - 2] = '\n'; fmtBuffer[sizeof(fmtBuffer) - 1] = '\0'; #endif - va_end (args); + va_end(args); MY_DEBUGDEVICE.print(fmtBuffer); // MY_SERIALDEVICE.flush(); } diff --git a/hal/architecture/SAMD/MyHwSAMD.h b/hal/architecture/SAMD/MyHwSAMD.h index b38534023..732253e06 100644 --- a/hal/architecture/SAMD/MyHwSAMD.h +++ b/hal/architecture/SAMD/MyHwSAMD.h @@ -27,15 +27,24 @@ #define CRYPTO_LITTLE_ENDIAN +#ifndef MY_SERIALDEVICE +#define MY_SERIALDEVICE SerialUSB +#endif + +#ifndef MY_DEBUGDEVICE +#define MY_DEBUGDEVICE MY_SERIALDEVICE +#endif + // defines for sensebender gw variant.h #define MY_EXT_EEPROM_I2C_ADDRESS (0x50u) #define MY_EXT_EEPROM_SIZE (kbits_512) #define MY_EXT_EEPROM_PAGE_SIZE (32u) -#define MY_EXT_EEPROM_TWI_CLOCK (twiClock100kHz) // can be set to 400kHz with precaution if other i2c devices on bus extEEPROM eep(MY_EXT_EEPROM_SIZE, 1, MY_EXT_EEPROM_PAGE_SIZE, MY_EXT_EEPROM_I2C_ADDRESS); //device size, number of devices, page size +#define MY_EXT_EEPROM_TWI_CLOCK (eep.twiClock100kHz) // can be set to 400kHz with precaution if other i2c devices on bus + #define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__) #define vsnprintf_P(s, n, f, ...) vsnprintf((s), (n), (f), __VA_ARGS__) @@ -49,15 +58,11 @@ extEEPROM eep(MY_EXT_EEPROM_SIZE, 1, MY_EXT_EEPROM_PAGE_SIZE, bool hwInit(void); void hwWatchdogReset(void); void hwReboot(void); -void hwReadConfigBlock(void *buf, void * addr, size_t length); -void hwWriteConfigBlock(void *buf, void * addr, size_t length); +void hwReadConfigBlock(void *buf, void *addr, size_t length); +void hwWriteConfigBlock(void *buf, void *addr, size_t length); void hwWriteConfig(const int addr, uint8_t value); uint8_t hwReadConfig(const int addr); -#ifndef MY_SERIALDEVICE -#define MY_SERIALDEVICE SerialUSB -#endif - /** * Disable all interrupts. * Helper function for MY_CRITICAL_SECTION. diff --git a/hal/architecture/STM32F1/MyHwSTM32F1.cpp b/hal/architecture/STM32F1/MyHwSTM32F1.cpp index aac9b7178..5a8d21447 100644 --- a/hal/architecture/STM32F1/MyHwSTM32F1.cpp +++ b/hal/architecture/STM32F1/MyHwSTM32F1.cpp @@ -46,7 +46,12 @@ bool hwInit(void) { #if !defined(MY_DISABLED_SERIAL) MY_SERIALDEVICE.begin(MY_BAUD_RATE); +#if defined(MY_GATEWAY_SERIAL) + while (!MY_SERIALDEVICE) {} #endif +#endif + adc_calibrate(ADC1); + if (EEPROM.init() == EEPROM_OK) { uint16 cnt; EEPROM.count(&cnt); @@ -61,7 +66,7 @@ bool hwInit(void) void hwReadConfigBlock(void *buf, void *addr, size_t length) { - uint8_t *dst = static_cast(buf); + uint8_t *dst = static_cast(buf); int pos = reinterpret_cast(addr); while (length-- > 0) { *dst++ = EEPROM.read(pos++); @@ -70,7 +75,7 @@ void hwReadConfigBlock(void *buf, void *addr, size_t length) void hwWriteConfigBlock(void *buf, void *addr, size_t length) { - uint8_t *src = static_cast(buf); + uint8_t *src = static_cast(buf); int pos = reinterpret_cast(addr); while (length-- > 0) { EEPROM.write(pos++, *src++); @@ -80,13 +85,13 @@ void hwWriteConfigBlock(void *buf, void *addr, size_t length) uint8_t hwReadConfig(const int addr) { uint8_t value; - hwReadConfigBlock(&value, reinterpret_cast(addr), 1); + hwReadConfigBlock(&value, reinterpret_cast(addr), 1); return value; } void hwWriteConfig(const int addr, uint8_t value) { - hwWriteConfigBlock(&value, reinterpret_cast(addr), 1); + hwWriteConfigBlock(&value, reinterpret_cast(addr), 1); } int8_t hwSleep(uint32_t ms) @@ -129,7 +134,7 @@ void hwRandomNumberInit(void) uint16_t currentValue = 0; uint16_t newValue = 0; - for (uint8_t i = 0; i<32; i++) { + for (uint8_t i = 0; i < 32; i++) { const uint32_t timeout = hwMillis() + 20; while (timeout >= hwMillis()) { newValue = adc_read(ADC1, 16); @@ -143,17 +148,17 @@ void hwRandomNumberInit(void) randomSeed(seed); } -bool hwUniqueID(unique_id_t* uniqueID) +bool hwUniqueID(unique_id_t *uniqueID) { - (void)memcpy((uint8_t*)uniqueID, (uint32_t*)0x1FFFF7E0, 16); + (void)memcpy((uint8_t *)uniqueID, (uint32_t *)0x1FFFF7E0, 16); // FlashID + ChipID return true; } uint16_t hwCPUVoltage(void) { adc_reg_map *regs = ADC1->regs; - regs->CR2 |= ADC_CR2_TSVREFE; // enable VREFINT and temp sensor - regs->SMPR1 = ADC_SMPR1_SMP17; // sample rate for VREFINT ADC channel + regs->CR2 |= ADC_CR2_TSVREFE; // enable VREFINT and temp sensor + regs->SMPR1 = ADC_SMPR1_SMP17; // sample rate for VREFINT ADC channel return 1200 * 4096 / adc_read(ADC1, 17); } @@ -162,6 +167,11 @@ uint16_t hwCPUFrequency(void) return F_CPU/100000UL; } +int8_t hwCPUTemperature(void) +{ + return -127; // not implemented yet +} + uint16_t hwFreeMem(void) { //Not yet implemented @@ -170,9 +180,6 @@ uint16_t hwFreeMem(void) void hwDebugPrint(const char *fmt, ...) { -#ifndef MY_DEBUGDEVICE -#define MY_DEBUGDEVICE MY_SERIALDEVICE -#endif #ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL @@ -183,7 +190,7 @@ void hwDebugPrint(const char *fmt, ...) #else // prepend timestamp MY_DEBUGDEVICE.print(hwMillis()); - MY_DEBUGDEVICE.print(" "); + MY_DEBUGDEVICE.print(F(" ")); #endif va_list args; va_start(args, fmt); diff --git a/hal/architecture/STM32F1/MyHwSTM32F1.h b/hal/architecture/STM32F1/MyHwSTM32F1.h index 49dd759cd..03c929c9c 100644 --- a/hal/architecture/STM32F1/MyHwSTM32F1.h +++ b/hal/architecture/STM32F1/MyHwSTM32F1.h @@ -29,6 +29,14 @@ #define CRYPTO_LITTLE_ENDIAN +#ifndef MY_SERIALDEVICE +#define MY_SERIALDEVICE Serial +#endif + +#ifndef MY_DEBUGDEVICE +#define MY_DEBUGDEVICE MY_SERIALDEVICE +#endif + // SS default #ifndef SS #define SS PA4 @@ -41,10 +49,6 @@ #define printf_P printf #define yield() // not defined -#ifndef MY_SERIALDEVICE -#define MY_SERIALDEVICE Serial -#endif - #ifndef digitalPinToInterrupt #define digitalPinToInterrupt(__pin) (__pin) #endif diff --git a/hal/architecture/Teensy3/MyHwTeensy3.cpp b/hal/architecture/Teensy3/MyHwTeensy3.cpp index ccd042c15..185d8238c 100644 --- a/hal/architecture/Teensy3/MyHwTeensy3.cpp +++ b/hal/architecture/Teensy3/MyHwTeensy3.cpp @@ -42,9 +42,11 @@ ISR (WDT_vect) bool hwInit(void) { +#if !defined(MY_DISABLED_SERIAL) MY_SERIALDEVICE.begin(MY_BAUD_RATE); #if defined(MY_GATEWAY_SERIAL) while (!MY_SERIALDEVICE) {} +#endif #endif return true; } @@ -91,10 +93,10 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo bool hwUniqueID(unique_id_t *uniqueID) { #if defined(__MKL26Z64__) - (void)memcpy((uint8_t*)uniqueID, &SIM_UIDMH, 12); - (void)memset((uint8_t*)uniqueID + 12, MY_HWID_PADDING_BYTE, 4); + (void)memcpy((uint8_t *)uniqueID, &SIM_UIDMH, 12); + (void)memset((uint8_t *)uniqueID + 12, MY_HWID_PADDING_BYTE, 4); #else - (void)memcpy((uint8_t*)uniqueID, &SIM_UIDH, 16); + (void)memcpy((uint8_t *)uniqueID, &SIM_UIDH, 16); #endif return true; } @@ -126,6 +128,11 @@ uint16_t hwCPUFrequency(void) return F_CPU / 100000UL; } +int8_t hwCPUTemperature(void) +{ + return -127; // not implemented yet +} + uint16_t hwFreeMem(void) { // TODO: Not supported! @@ -144,7 +151,7 @@ ssize_t hwGetentropy(void *__buffer, const size_t __length) while (!(RNG_SR & RNG_SR_OREG_LVL(0xF))); const uint32_t rndVar = RNG_OR; const uint8_t bsize = (__length - pos) > sizeof(rndVar) ? sizeof(rndVar) : (__length - pos); - (void)memcpy((uint8_t*)__buffer + pos, &rndVar, bsize); + (void)memcpy((uint8_t *)__buffer + pos, &rndVar, bsize); pos += bsize; } SIM_SCGC6 &= ~SIM_SCGC6_RNGA; // disable RNG @@ -167,9 +174,6 @@ void hwRandomNumberInit(void) void hwDebugPrint(const char *fmt, ...) { -#ifndef MY_DEBUGDEVICE -#define MY_DEBUGDEVICE MY_SERIALDEVICE -#endif #ifndef MY_DISABLED_SERIAL char fmtBuffer[MY_SERIAL_OUTPUT_SIZE]; #ifdef MY_GATEWAY_SERIAL diff --git a/hal/architecture/Teensy3/MyHwTeensy3.h b/hal/architecture/Teensy3/MyHwTeensy3.h index 08cee3c6c..3092dcadc 100644 --- a/hal/architecture/Teensy3/MyHwTeensy3.h +++ b/hal/architecture/Teensy3/MyHwTeensy3.h @@ -39,6 +39,10 @@ #define MY_SERIALDEVICE Serial #endif +#ifndef MY_DEBUGDEVICE +#define MY_DEBUGDEVICE MY_SERIALDEVICE +#endif + #if defined(__MK64FX512__) || defined(__MK66FX1M0__) #define RNG_CR_GO_MASK 0x1u #define RNG_CR_HA_MASK 0x2u diff --git a/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp b/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp index 483bd5690..248f2b974 100644 --- a/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp +++ b/hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp @@ -19,8 +19,8 @@ * version 2 as published by the Free Software Foundation. */ -#include "drivers/NRF5/Radio.h" -#include "drivers/NRF5/Radio_ESB.h" +#include "hal/transport/NRF5_ESB/driver/Radio.h" +#include "hal/transport/NRF5_ESB/driver/Radio_ESB.h" #include "drivers/CircularBuffer/CircularBuffer.h" diff --git a/drivers/NRF5/Radio.cpp b/hal/transport/NRF5_ESB/driver/Radio.cpp similarity index 98% rename from drivers/NRF5/Radio.cpp rename to hal/transport/NRF5_ESB/driver/Radio.cpp index b3d732703..e420c8658 100644 --- a/drivers/NRF5/Radio.cpp +++ b/hal/transport/NRF5_ESB/driver/Radio.cpp @@ -1,4 +1,4 @@ -#include "drivers/NRF5/Radio.h" +#include "Radio.h" int16_t NRF5_getTxPowerPercent(void) { diff --git a/drivers/NRF5/Radio.h b/hal/transport/NRF5_ESB/driver/Radio.h similarity index 99% rename from drivers/NRF5/Radio.h rename to hal/transport/NRF5_ESB/driver/Radio.h index c91b9fd05..e4ac5dce9 100644 --- a/drivers/NRF5/Radio.h +++ b/hal/transport/NRF5_ESB/driver/Radio.h @@ -1,4 +1,3 @@ - /* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. diff --git a/drivers/NRF5/Radio_ESB.cpp b/hal/transport/NRF5_ESB/driver/Radio_ESB.cpp similarity index 100% rename from drivers/NRF5/Radio_ESB.cpp rename to hal/transport/NRF5_ESB/driver/Radio_ESB.cpp diff --git a/drivers/NRF5/Radio_ESB.h b/hal/transport/NRF5_ESB/driver/Radio_ESB.h similarity index 100% rename from drivers/NRF5/Radio_ESB.h rename to hal/transport/NRF5_ESB/driver/Radio_ESB.h diff --git a/hal/transport/RF24/MyTransportRF24.cpp b/hal/transport/RF24/MyTransportRF24.cpp index 9ce7fcf17..dbcb112c9 100644 --- a/hal/transport/RF24/MyTransportRF24.cpp +++ b/hal/transport/RF24/MyTransportRF24.cpp @@ -17,7 +17,7 @@ * version 2 as published by the Free Software Foundation. */ -#include "drivers/RF24/RF24.h" +#include "hal/transport/RF24/driver/RF24.h" #if defined(MY_RF24_ENABLE_ENCRYPTION) #include "drivers/AES/AES.cpp" diff --git a/drivers/RF24/RF24.cpp b/hal/transport/RF24/driver/RF24.cpp similarity index 100% rename from drivers/RF24/RF24.cpp rename to hal/transport/RF24/driver/RF24.cpp diff --git a/drivers/RF24/RF24.h b/hal/transport/RF24/driver/RF24.h similarity index 100% rename from drivers/RF24/RF24.h rename to hal/transport/RF24/driver/RF24.h diff --git a/drivers/RF24/RF24registers.h b/hal/transport/RF24/driver/RF24registers.h similarity index 100% rename from drivers/RF24/RF24registers.h rename to hal/transport/RF24/driver/RF24registers.h diff --git a/hal/transport/RFM69/MyTransportRFM69.cpp b/hal/transport/RFM69/MyTransportRFM69.cpp index 44533f54c..d1f5371be 100644 --- a/hal/transport/RFM69/MyTransportRFM69.cpp +++ b/hal/transport/RFM69/MyTransportRFM69.cpp @@ -19,7 +19,7 @@ #if defined(MY_RFM69_NEW_DRIVER) -#include "drivers/RFM69/new/RFM69_new.h" +#include "hal/transport/RFM69/driver/new/RFM69_new.h" bool transportInit(void) { @@ -154,7 +154,7 @@ bool transportSetTxPowerPercent(const uint8_t powerPercent) #else -#include "drivers/RFM69/old/RFM69_old.h" +#include "hal/transport/RFM69/driver/old/RFM69_old.h" RFM69 _radio(MY_RFM69_CS_PIN, MY_RFM69_IRQ_PIN, MY_RFM69HW, MY_RFM69_IRQ_NUM); uint8_t _address; diff --git a/drivers/RFM69/new/RFM69_new.cpp b/hal/transport/RFM69/driver/new/RFM69_new.cpp similarity index 99% rename from drivers/RFM69/new/RFM69_new.cpp rename to hal/transport/RFM69/driver/new/RFM69_new.cpp index 797328dd2..7976267e1 100644 --- a/drivers/RFM69/new/RFM69_new.cpp +++ b/hal/transport/RFM69/driver/new/RFM69_new.cpp @@ -74,7 +74,7 @@ LOCAL void RFM69_concludeSPITransaction(void) #endif } -LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t len, +LOCAL uint8_t RFM69_spiMultiByteTransfer(const uint8_t cmd, uint8_t *buf, uint8_t len, const bool aReadMode) { uint8_t status; diff --git a/drivers/RFM69/new/RFM69_new.h b/hal/transport/RFM69/driver/new/RFM69_new.h similarity index 100% rename from drivers/RFM69/new/RFM69_new.h rename to hal/transport/RFM69/driver/new/RFM69_new.h diff --git a/drivers/RFM69/new/RFM69registers_new.h b/hal/transport/RFM69/driver/new/RFM69registers_new.h similarity index 100% rename from drivers/RFM69/new/RFM69registers_new.h rename to hal/transport/RFM69/driver/new/RFM69registers_new.h diff --git a/drivers/RFM69/old/RFM69_old.cpp b/hal/transport/RFM69/driver/old/RFM69_old.cpp similarity index 99% rename from drivers/RFM69/old/RFM69_old.cpp rename to hal/transport/RFM69/driver/old/RFM69_old.cpp index 52b576170..ede5b955b 100644 --- a/drivers/RFM69/old/RFM69_old.cpp +++ b/hal/transport/RFM69/driver/old/RFM69_old.cpp @@ -400,7 +400,7 @@ void RFM69::sendFrame(uint8_t toAddress, const void* buffer, uint8_t bufferSize, SPI.transfer(CTLbyte); for (uint8_t i = 0; i < bufferSize; i++) { - SPI.transfer(((uint8_t*) buffer)[i]); + SPI.transfer(((uint8_t *)buffer)[i]); } unselect(); diff --git a/drivers/RFM69/old/RFM69_old.h b/hal/transport/RFM69/driver/old/RFM69_old.h similarity index 100% rename from drivers/RFM69/old/RFM69_old.h rename to hal/transport/RFM69/driver/old/RFM69_old.h diff --git a/drivers/RFM69/old/RFM69registers_old.h b/hal/transport/RFM69/driver/old/RFM69registers_old.h similarity index 100% rename from drivers/RFM69/old/RFM69registers_old.h rename to hal/transport/RFM69/driver/old/RFM69registers_old.h diff --git a/hal/transport/RFM95/MyTransportRFM95.cpp b/hal/transport/RFM95/MyTransportRFM95.cpp index c8188df00..844dbf739 100644 --- a/hal/transport/RFM95/MyTransportRFM95.cpp +++ b/hal/transport/RFM95/MyTransportRFM95.cpp @@ -17,7 +17,7 @@ * version 2 as published by the Free Software Foundation. */ -#include "drivers/RFM95/RFM95.h" +#include "hal/transport/RFM95/driver/RFM95.h" #if defined(MY_RFM95_ENABLE_ENCRYPTION) #include "drivers/AES/AES.h" #endif @@ -36,15 +36,15 @@ bool transportInit(void) #if defined(MY_RFM95_ENABLE_ENCRYPTION) uint8_t RFM95_psk[16]; #ifdef MY_SIGNING_SIMPLE_PASSWD - memset(RFM95_psk, 0, 16); - memcpy(RFM95_psk, MY_SIGNING_SIMPLE_PASSWD, strnlen(MY_SIGNING_SIMPLE_PASSWD, 16)); + (void)memset((void *)RFM95_psk, 0, 16); + (void)memcpy((void *)RFM95_psk, MY_SIGNING_SIMPLE_PASSWD, strnlen(MY_SIGNING_SIMPLE_PASSWD, 16)); #else - hwReadConfigBlock((void*)RFM95_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16); + hwReadConfigBlock((void *)RFM95_psk, (void *)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16); #endif //set up AES-key RFM95_aes.set_key(RFM95_psk, 16); // Make sure it is purged from memory when set - memset(RFM95_psk, 0, 16); + (void)memset((void *)RFM95_psk, 0, 16); #endif const bool result = RFM95_initialise(MY_RFM95_FREQUENCY); @@ -72,12 +72,12 @@ bool transportSend(const uint8_t to, const void *data, const uint8_t len, const { #if defined(MY_RFM95_ENABLE_ENCRYPTION) // copy input data because it is read-only - (void)memcpy(RFM95_dataenc,data,len); + (void)memcpy((void *)RFM95_dataenc, (const void *)data, len); // has to be adjusted, WIP! RFM95_aes.set_IV(0); const uint8_t finalLength = len > 16 ? 32 : 16; //encrypt data - RFM95_aes.cbc_encrypt(RFM95_dataenc, RFM95_dataenc, finalLength /16); + RFM95_aes.cbc_encrypt(RFM95_dataenc, RFM95_dataenc, finalLength / 16); if (noACK) { (void)RFM95_sendWithRetry(to, RFM95_dataenc, finalLength, 0, 0); return true; @@ -105,12 +105,12 @@ bool transportSanityCheck(void) uint8_t transportReceive(void *data) { - uint8_t len = RFM95_receive((uint8_t*)data, MAX_MESSAGE_LENGTH); + uint8_t len = RFM95_receive((uint8_t *)data, MAX_MESSAGE_LENGTH); #if defined(MY_RFM95_ENABLE_ENCRYPTION) // has to be adjusted, WIP! RFM95_aes.set_IV(0); // decrypt data - if (RFM95_aes.cbc_decrypt((uint8_t*)(data), (uint8_t*)(data), len > 16 ? 2 : 1) != AES_SUCCESS) { + if (RFM95_aes.cbc_decrypt((uint8_t *)data, (uint8_t *)data, len > 16 ? 2 : 1) != AES_SUCCESS) { len = 0; } #endif diff --git a/drivers/RFM95/RFM95.cpp b/hal/transport/RFM95/driver/RFM95.cpp similarity index 100% rename from drivers/RFM95/RFM95.cpp rename to hal/transport/RFM95/driver/RFM95.cpp diff --git a/drivers/RFM95/RFM95.h b/hal/transport/RFM95/driver/RFM95.h similarity index 100% rename from drivers/RFM95/RFM95.h rename to hal/transport/RFM95/driver/RFM95.h diff --git a/drivers/RFM95/RFM95registers.h b/hal/transport/RFM95/driver/RFM95registers.h similarity index 100% rename from drivers/RFM95/RFM95registers.h rename to hal/transport/RFM95/driver/RFM95registers.h From f5676a362207b895f4f71c793e0c8a5a319247df Mon Sep 17 00:00:00 2001 From: Lee Nelson Date: Mon, 22 Oct 2018 11:55:39 -0700 Subject: [PATCH 25/31] Allow splash screen to redirect to MY_DEBUGDEVICE if defined (#1057) (#1210) * Allow splash screen to redirect to MY_DEBUGDEVICE if defined (#1057) --- core/MySplashScreen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/MySplashScreen.cpp b/core/MySplashScreen.cpp index 977713879..6c12988cc 100644 --- a/core/MySplashScreen.cpp +++ b/core/MySplashScreen.cpp @@ -44,9 +44,9 @@ void displaySplashScreen(void) } const uint8_t rep = val > 7 ? val - 5 : 1; for (uint8_t c = 0; c Date: Tue, 23 Oct 2018 21:38:13 +0200 Subject: [PATCH 26/31] Revert "Allow splash screen to redirect to MY_DEBUGDEVICE if defined (#1057) (#1210)" (#1220) This reverts commit f5676a362207b895f4f71c793e0c8a5a319247df. --- core/MySplashScreen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/MySplashScreen.cpp b/core/MySplashScreen.cpp index 6c12988cc..977713879 100644 --- a/core/MySplashScreen.cpp +++ b/core/MySplashScreen.cpp @@ -44,9 +44,9 @@ void displaySplashScreen(void) } const uint8_t rep = val > 7 ? val - 5 : 1; for (uint8_t c = 0; c Date: Tue, 23 Oct 2018 23:26:16 +0200 Subject: [PATCH 27/31] MY_DEBUGDEVICE output (#1221) --- core/MySplashScreen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/MySplashScreen.cpp b/core/MySplashScreen.cpp index 977713879..918860a4b 100644 --- a/core/MySplashScreen.cpp +++ b/core/MySplashScreen.cpp @@ -21,7 +21,7 @@ void displaySplashScreen(void) { -#if !defined(MY_DISABLED_SERIAL) +#if !defined(MY_DISABLED_SERIAL) && defined(MY_DEBUGDEVICE) static const uint8_t splashScreen[] PROGMEM = { 0x20, 0x7C, 0x5F, 0x5c, 0x2F, 0x60, 0x2C, 0x0A, // substitution matrix 0x07, 0x02, 0x20, 0x02, 0x20, 0xB2, 0x87, 0x10, 0x03, 0x40, 0x01, 0x20, 0x00, 0x24, 0x02, 0x22, @@ -44,9 +44,9 @@ void displaySplashScreen(void) } const uint8_t rep = val > 7 ? val - 5 : 1; for (uint8_t c = 0; c Date: Sat, 3 Nov 2018 10:04:32 +0100 Subject: [PATCH 28/31] Display release number (#1217) --- core/MySensorsCore.cpp | 10 +++++++--- core/MySensorsCore.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index 0007f25ee..88d293d5b 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -110,9 +110,8 @@ void _begin(void) displaySplashScreen(); #endif - CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",VER=" - MYSENSORS_LIBRARY_VERSION "\n")); - + CORE_DEBUG(PSTR("MCO:BGN:INIT " MY_NODE_TYPE ",CP=" MY_CAPABILITIES ",REL=%" PRIu8 ",VER=" + MYSENSORS_LIBRARY_VERSION "\n"), MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER); if (!hwInitResult) { CORE_DEBUG(PSTR("!MCO:BGN:HW ERR\n")); setIndication(INDICATION_ERR_HW_INIT); @@ -438,6 +437,11 @@ bool _processInternalCoreMessage(void) presentNode(); } else if (type == I_HEARTBEAT_REQUEST) { (void)sendHeartbeat(); + } else if (_msg.type == I_VERSION) { +#if !defined(MY_GATEWAY_FEATURE) + (void)_sendRoute(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, + I_VERSION).set(MYSENSORS_LIBRARY_VERSION_INT)); +#endif } else if (type == I_TIME) { // Deliver time to callback if (receiveTime) { diff --git a/core/MySensorsCore.h b/core/MySensorsCore.h index c757e63db..7cd5295e3 100644 --- a/core/MySensorsCore.h +++ b/core/MySensorsCore.h @@ -40,7 +40,7 @@ * |E| SYS | SUB | Message | Comment * |-|-----|-----|---------------------------------------------|-------------------------------------------------------------------------------------------------- * |!| MCO | BGN | HW ERR | Error HW initialization (e.g. ext. EEPROM) -* | | MCO | BGN | INIT %%s,CP=%%s,VER=%%s | Core initialization, capabilities (CP), library version (VER) +* | | MCO | BGN | INIT %%s,CP=%%s,REL=%%d,VER=%%s (%%d) | Core initialization, capabilities (CP), release number (REL), library version (VER) * | | MCO | BGN | BFR | Callback before() * | | MCO | BGN | STP | Callback setup() * | | MCO | BGN | INIT OK,TSP=%%d | Core initialised, transport status (TSP): 0=not initialised, 1=initialised, NA=not available From bde7dadca6c50d52cc21dadd5ee6d3623be5f3c6 Mon Sep 17 00:00:00 2001 From: tekka Date: Sun, 4 Nov 2018 13:27:28 +0100 Subject: [PATCH 29/31] Implement CPUTemperature() (#1225) --- hal/architecture/AVR/MyHwAVR.cpp | 14 ++++- hal/architecture/AVR/MyHwAVR.h | 9 +++ hal/architecture/ESP32/MyHwESP32.cpp | 4 +- hal/architecture/ESP32/MyHwESP32.h | 8 +++ hal/architecture/ESP8266/MyHwESP8266.cpp | 2 +- hal/architecture/Linux/MyHwLinuxGeneric.cpp | 2 +- hal/architecture/MyHwHAL.h | 7 ++- hal/architecture/SAMD/MyHwSAMD.cpp | 68 ++++++++++++++++++++- hal/architecture/SAMD/MyHwSAMD.h | 8 +++ hal/architecture/STM32F1/MyHwSTM32F1.cpp | 22 +++++-- hal/architecture/STM32F1/MyHwSTM32F1.h | 8 +++ 11 files changed, 140 insertions(+), 12 deletions(-) diff --git a/hal/architecture/AVR/MyHwAVR.cpp b/hal/architecture/AVR/MyHwAVR.cpp index f62ed0495..f30f71e28 100644 --- a/hal/architecture/AVR/MyHwAVR.cpp +++ b/hal/architecture/AVR/MyHwAVR.cpp @@ -334,7 +334,19 @@ uint16_t hwCPUFrequency(void) int8_t hwCPUTemperature(void) { - return -127; // not implemented yet +#if defined(__AVR_ATmega168A__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328BP__) || defined(__AVR_ATmega32U4__) + // Set the internal reference and mux. + ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3)); + ADCSRA |= _BV(ADEN); // enable the ADC + delay(20); // wait for voltages to become stable. + ADCSRA |= _BV(ADSC); // Start the ADC + // Wait until conversion done + while (bit_is_set(ADCSRA, ADSC)); + // temperature is in degrees Celsius + return static_cast((ADCW - MY_AVR_TEMPERATURE_OFFSET) / MY_AVR_TEMPERATURE_GAIN); +#else + return -127; // not available +#endif } uint16_t hwFreeMem(void) diff --git a/hal/architecture/AVR/MyHwAVR.h b/hal/architecture/AVR/MyHwAVR.h index 16b50b104..14e340e27 100644 --- a/hal/architecture/AVR/MyHwAVR.h +++ b/hal/architecture/AVR/MyHwAVR.h @@ -43,6 +43,15 @@ #define MY_DEBUGDEVICE MY_SERIALDEVICE #endif +// AVR temperature calibration reference: http://ww1.microchip.com/downloads/en/AppNotes/Atmel-8108-Calibration-of-the-AVRs-Internal-Temperature-Reference_ApplicationNote_AVR122.pdf +#ifndef MY_AVR_TEMPERATURE_OFFSET +#define MY_AVR_TEMPERATURE_OFFSET (324.31f) +#endif + +#ifndef MY_AVR_TEMPERATURE_GAIN +#define MY_AVR_TEMPERATURE_GAIN (1.22f) +#endif + // Define these as macros to save valuable space #define hwDigitalWrite(__pin, __value) digitalWriteFast(__pin, __value) #define hwDigitalRead(__pin) digitalReadFast(__pin) diff --git a/hal/architecture/ESP32/MyHwESP32.cpp b/hal/architecture/ESP32/MyHwESP32.cpp index 4577a15a1..0dbd70b69 100644 --- a/hal/architecture/ESP32/MyHwESP32.cpp +++ b/hal/architecture/ESP32/MyHwESP32.cpp @@ -133,7 +133,9 @@ uint16_t hwCPUFrequency(void) int8_t hwCPUTemperature(void) { - return -127; // not implemented yet + // CPU temperature in °C + return static_cast((temperatureRead() - MY_ESP32_TEMPERATURE_OFFSET) / + MY_ESP32_TEMPERATURE_GAIN); } uint16_t hwFreeMem(void) diff --git a/hal/architecture/ESP32/MyHwESP32.h b/hal/architecture/ESP32/MyHwESP32.h index 4aa8890da..420249546 100644 --- a/hal/architecture/ESP32/MyHwESP32.h +++ b/hal/architecture/ESP32/MyHwESP32.h @@ -55,6 +55,14 @@ #define MY_DEBUGDEVICE MY_SERIALDEVICE #endif +#ifndef MY_ESP32_TEMPERATURE_OFFSET +#define MY_ESP32_TEMPERATURE_OFFSET (0.0f) +#endif + +#ifndef MY_ESP32_TEMPERATURE_GAIN +#define MY_ESP32_TEMPERATURE_GAIN (1.0f) +#endif + #define MY_EEPROM_SIZE 1024 #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value) diff --git a/hal/architecture/ESP8266/MyHwESP8266.cpp b/hal/architecture/ESP8266/MyHwESP8266.cpp index fd68deb3a..716d8a382 100644 --- a/hal/architecture/ESP8266/MyHwESP8266.cpp +++ b/hal/architecture/ESP8266/MyHwESP8266.cpp @@ -147,7 +147,7 @@ uint16_t hwCPUFrequency(void) int8_t hwCPUTemperature(void) { - return -127; + return -127; // not available } uint16_t hwFreeMem(void) diff --git a/hal/architecture/Linux/MyHwLinuxGeneric.cpp b/hal/architecture/Linux/MyHwLinuxGeneric.cpp index f2ec0c726..6b5dd8d92 100644 --- a/hal/architecture/Linux/MyHwLinuxGeneric.cpp +++ b/hal/architecture/Linux/MyHwLinuxGeneric.cpp @@ -149,7 +149,7 @@ uint16_t hwCPUFrequency(void) int8_t hwCPUTemperature(void) { - return -127; + return -127; // not implemented yet } uint16_t hwFreeMem(void) diff --git a/hal/architecture/MyHwHAL.h b/hal/architecture/MyHwHAL.h index b9c3c8802..2e709ae1f 100644 --- a/hal/architecture/MyHwHAL.h +++ b/hal/architecture/MyHwHAL.h @@ -108,13 +108,14 @@ uint16_t hwCPUVoltage(void); uint16_t hwCPUFrequency(void); /** - * Non-calibrated CPU temperature (if available) - * @return CPU temperature in °C + * CPU temperature (if available) + * Adjust calibration parameters via MY__TEMPERATURE_OFFSET and MY__TEMPERATURE_GAIN + * @return CPU temperature in °C, -127 if not available */ int8_t hwCPUTemperature(void); /** - * Free memory + * Report free memory (if function available) * @return free memory in bytes */ uint16_t hwFreeMem(void); diff --git a/hal/architecture/SAMD/MyHwSAMD.cpp b/hal/architecture/SAMD/MyHwSAMD.cpp index 5f8f65235..45cc3709c 100644 --- a/hal/architecture/SAMD/MyHwSAMD.cpp +++ b/hal/architecture/SAMD/MyHwSAMD.cpp @@ -73,6 +73,11 @@ bool hwInit(void) while (!MY_SERIALDEVICE) {} #endif #endif + + SYSCTRL->VREF.reg |= SYSCTRL_VREF_TSEN; // Enable the temperature sensor + while (ADC->STATUS.bit.SYNCBUSY == + 1); // Wait for synchronization of registers between the clock domains + const uint8_t eepInit = eep.begin(MY_EXT_EEPROM_TWI_CLOCK, &Wire); #if defined(SENSEBENDER_GW_SAMD_V1) // check connection to external EEPROM - only sensebender GW @@ -178,7 +183,68 @@ uint16_t hwCPUFrequency(void) int8_t hwCPUTemperature(void) { - return -127; // not implemented yet + // taken from https://github.com/arduino/ArduinoCore-samd/pull/277 + // Set to 12 bits resolution + ADC->CTRLB.reg = ADC_CTRLB_RESSEL_12BIT | ADC_CTRLB_PRESCALER_DIV256; + syncADC(); + // Ensure we are sampling slowly + ADC->SAMPCTRL.reg = ADC_SAMPCTRL_SAMPLEN(0x3f); + syncADC(); + // Set ADC reference to internal 1v + ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; + ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; + syncADC(); + // Select MUXPOS as temperature channel, and MUXNEG as internal ground + ADC->INPUTCTRL.bit.MUXPOS = ADC_INPUTCTRL_MUXPOS_TEMP_Val; + ADC->INPUTCTRL.bit.MUXNEG = ADC_INPUTCTRL_MUXNEG_GND_Val; + syncADC(); + // Enable ADC + ADC->CTRLA.bit.ENABLE = 1; + syncADC(); + // Start ADC conversion + ADC->SWTRIG.bit.START = 1; + // Clear the Data Ready flag + ADC->INTFLAG.reg = ADC_INTFLAG_RESRDY; + syncADC(); + // Start conversion again, since The first conversion after the reference is changed must not be used. + ADC->SWTRIG.bit.START = 1; + // Wait until ADC conversion is done + while (!(ADC->INTFLAG.bit.RESRDY)); + syncADC(); + // Get result + // This is signed so that the math later is done signed + const int32_t adcReading = ADC->RESULT.reg; + // Clear result ready flag + ADC->INTFLAG.reg = ADC_INTFLAG_RESRDY; + syncADC(); + // Disable ADC + ADC->CTRLA.bit.ENABLE = 0; + syncADC(); + // Factory room temperature readings + const uint8_t roomInteger = (*(uint32_t *)FUSES_ROOM_TEMP_VAL_INT_ADDR & + FUSES_ROOM_TEMP_VAL_INT_Msk) + >> FUSES_ROOM_TEMP_VAL_INT_Pos; + const uint8_t roomDecimal = (*(uint32_t *)FUSES_ROOM_TEMP_VAL_DEC_ADDR & + FUSES_ROOM_TEMP_VAL_DEC_Msk) + >> FUSES_ROOM_TEMP_VAL_DEC_Pos; + const int32_t roomReading = ((*(uint32_t *)FUSES_ROOM_ADC_VAL_ADDR & FUSES_ROOM_ADC_VAL_Msk) >> + FUSES_ROOM_ADC_VAL_Pos); + const int32_t roomTemperature = 1000 * roomInteger + 100 * roomDecimal; + // Factory hot temperature readings + const uint8_t hotInteger = (*(uint32_t *)FUSES_HOT_TEMP_VAL_INT_ADDR & FUSES_HOT_TEMP_VAL_INT_Msk) + >> + FUSES_HOT_TEMP_VAL_INT_Pos; + const uint8_t hotDecimal = (*(uint32_t *)FUSES_HOT_TEMP_VAL_DEC_ADDR & FUSES_HOT_TEMP_VAL_DEC_Msk) + >> + FUSES_HOT_TEMP_VAL_DEC_Pos; + const int32_t hotReading = ((*(uint32_t *)FUSES_HOT_ADC_VAL_ADDR & FUSES_HOT_ADC_VAL_Msk) >> + FUSES_HOT_ADC_VAL_Pos); + const int32_t hotTemperature = 1000 * hotInteger + 100 * hotDecimal; + // Linear interpolation of temperature using factory room temperature and hot temperature + const int32_t temperature = roomTemperature + ((hotTemperature - roomTemperature) * + (adcReading - roomReading)) / (hotReading - roomReading); + return static_cast(((temperature / 1000) - MY_SAMD_TEMPERATURE_OFFSET) / + MY_SAMD_TEMPERATURE_GAIN); } diff --git a/hal/architecture/SAMD/MyHwSAMD.h b/hal/architecture/SAMD/MyHwSAMD.h index 732253e06..09f26e0ce 100644 --- a/hal/architecture/SAMD/MyHwSAMD.h +++ b/hal/architecture/SAMD/MyHwSAMD.h @@ -35,6 +35,14 @@ #define MY_DEBUGDEVICE MY_SERIALDEVICE #endif +#ifndef MY_SAMD_TEMPERATURE_OFFSET +#define MY_SAMD_TEMPERATURE_OFFSET (0.0f) +#endif + +#ifndef MY_SAMD_TEMPERATURE_GAIN +#define MY_SAMD_TEMPERATURE_GAIN (1.0f) +#endif + // defines for sensebender gw variant.h #define MY_EXT_EEPROM_I2C_ADDRESS (0x50u) #define MY_EXT_EEPROM_SIZE (kbits_512) diff --git a/hal/architecture/STM32F1/MyHwSTM32F1.cpp b/hal/architecture/STM32F1/MyHwSTM32F1.cpp index 5a8d21447..9934cc8f1 100644 --- a/hal/architecture/STM32F1/MyHwSTM32F1.cpp +++ b/hal/architecture/STM32F1/MyHwSTM32F1.cpp @@ -50,8 +50,6 @@ bool hwInit(void) while (!MY_SERIALDEVICE) {} #endif #endif - adc_calibrate(ADC1); - if (EEPROM.init() == EEPROM_OK) { uint16 cnt; EEPROM.count(&cnt); @@ -146,6 +144,7 @@ void hwRandomNumberInit(void) seed ^= ( (newValue + hwMillis()) & 7) << i; } randomSeed(seed); + regs->CR2 &= ~ADC_CR2_TSVREFE; // disable VREFINT and temp sensor } bool hwUniqueID(unique_id_t *uniqueID) @@ -159,7 +158,11 @@ uint16_t hwCPUVoltage(void) adc_reg_map *regs = ADC1->regs; regs->CR2 |= ADC_CR2_TSVREFE; // enable VREFINT and temp sensor regs->SMPR1 = ADC_SMPR1_SMP17; // sample rate for VREFINT ADC channel - return 1200 * 4096 / adc_read(ADC1, 17); + adc_calibrate(ADC1); + + const uint16_t vdd = adc_read(ADC1, 17); + regs->CR2 &= ~ADC_CR2_TSVREFE; // disable VREFINT and temp sensor + return 1200 * 4096 / vdd; } uint16_t hwCPUFrequency(void) @@ -169,7 +172,18 @@ uint16_t hwCPUFrequency(void) int8_t hwCPUTemperature(void) { - return -127; // not implemented yet + adc_reg_map *regs = ADC1->regs; + regs->CR2 |= ADC_CR2_TSVREFE; // enable VREFINT and Temperature sensor + regs->SMPR1 |= ADC_SMPR1_SMP16 | ADC_SMPR1_SMP17; + adc_calibrate(ADC1); + + //const uint16_t adc_temp = adc_read(ADC1, 16); + //const uint16_t vref = 1200 * 4096 / adc_read(ADC1, 17); + // calibrated at 25°C, ADC output = 1430mV, avg slope = 4.3mV / °C, increasing temp ~ lower voltage + const int8_t temp = static_cast((1430.0 - (adc_read(ADC1, 16) * 1200 / adc_read(ADC1, + 17))) / 4.3 + 25.0); + regs->CR2 &= ~ADC_CR2_TSVREFE; // disable VREFINT and temp sensor + return (temp - MY_STM32F1_TEMPERATURE_OFFSET) / MY_STM32F1_TEMPERATURE_GAIN; } uint16_t hwFreeMem(void) diff --git a/hal/architecture/STM32F1/MyHwSTM32F1.h b/hal/architecture/STM32F1/MyHwSTM32F1.h index 03c929c9c..54822734e 100644 --- a/hal/architecture/STM32F1/MyHwSTM32F1.h +++ b/hal/architecture/STM32F1/MyHwSTM32F1.h @@ -37,6 +37,14 @@ #define MY_DEBUGDEVICE MY_SERIALDEVICE #endif +#ifndef MY_STM32F1_TEMPERATURE_OFFSET +#define MY_STM32F1_TEMPERATURE_OFFSET (0.0f) +#endif + +#ifndef MY_STM32F1_TEMPERATURE_GAIN +#define MY_STM32F1_TEMPERATURE_GAIN (1.0f) +#endif + // SS default #ifndef SS #define SS PA4 From 4b14f5a7401e7326e4c26edda2c05bdfa41efbe7 Mon Sep 17 00:00:00 2001 From: tekka Date: Sun, 11 Nov 2018 15:06:37 +0100 Subject: [PATCH 30/31] Update PubSubClient 2.7 (#1224) --- drivers/PubSubClient/CHANGES.txt | 10 +- drivers/PubSubClient/PubSubClient.cpp | 134 +++++++++++++++++++------- drivers/PubSubClient/PubSubClient.h | 36 ++++++- drivers/PubSubClient/README.md | 3 +- 4 files changed, 144 insertions(+), 39 deletions(-) diff --git a/drivers/PubSubClient/CHANGES.txt b/drivers/PubSubClient/CHANGES.txt index 2127b08d2..01a07ae60 100644 --- a/drivers/PubSubClient/CHANGES.txt +++ b/drivers/PubSubClient/CHANGES.txt @@ -1,8 +1,16 @@ +2.7 + * Fix remaining-length handling to prevent buffer overrun + * Add large-payload API - beginPublish/write/publish/endPublish + * Add yield call to improve reliability on ESP + * Add Clean Session flag to connect options + * Add ESP32 support for functional callback signature + * Various other fixes + 2.4 * Add MQTT_SOCKET_TIMEOUT to prevent it blocking indefinitely whilst waiting for inbound data * Fixed return code when publishing >256 bytes - + 2.3 * Add publish(topic,payload,retained) function diff --git a/drivers/PubSubClient/PubSubClient.cpp b/drivers/PubSubClient/PubSubClient.cpp index 3438e30ce..62d6f785d 100644 --- a/drivers/PubSubClient/PubSubClient.cpp +++ b/drivers/PubSubClient/PubSubClient.cpp @@ -17,7 +17,6 @@ PubSubClient::PubSubClient() this->stream = NULL; setCallback(NULL); } - // cppcheck-suppress uninitMemberVar PubSubClient::PubSubClient(Client& client) { @@ -25,7 +24,6 @@ PubSubClient::PubSubClient(Client& client) setClient(client); this->stream = NULL; } - // cppcheck-suppress uninitMemberVar PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client) { @@ -63,7 +61,6 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATUR setClient(client); setStream(stream); } - // cppcheck-suppress uninitMemberVar PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client) { @@ -101,7 +98,6 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, setClient(client); setStream(stream); } - // cppcheck-suppress uninitMemberVar PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client) { @@ -143,22 +139,29 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGN bool PubSubClient::connect(const char *id) { - return connect(id,NULL,NULL,0,0,0,0); + return connect(id,NULL,NULL,0,0,0,0,1); } bool PubSubClient::connect(const char *id, const char *user, const char *pass) { - return connect(id,user,pass,0,0,0,0); + return connect(id,user,pass,0,0,0,0,1); } bool PubSubClient::connect(const char *id, const char* willTopic, uint8_t willQos, bool willRetain, const char* willMessage) { - return connect(id,NULL,NULL,willTopic,willQos,willRetain,willMessage); + return connect(id,NULL,NULL,willTopic,willQos,willRetain,willMessage,1); } bool PubSubClient::connect(const char *id, const char *user, const char *pass, const char* willTopic, uint8_t willQos, bool willRetain, const char* willMessage) +{ + return connect(id,user,pass,willTopic,willQos,willRetain,willMessage,1); +} + +bool PubSubClient::connect(const char *id, const char *user, const char *pass, + const char* willTopic, uint8_t willQos, bool willRetain, const char* willMessage, + bool cleanSession) { if (!connected()) { int result = 0; @@ -171,7 +174,7 @@ bool PubSubClient::connect(const char *id, const char *user, const char *pass, if (result == 1) { nextMsgId = 1; // Leave room in the buffer for header and variable length field - uint16_t length = 5; + uint16_t length = MQTT_MAX_HEADER_SIZE; unsigned int j; #if MQTT_VERSION == MQTT_VERSION_3_1 @@ -187,9 +190,12 @@ bool PubSubClient::connect(const char *id, const char *user, const char *pass, uint8_t v; if (willTopic) { - v = 0x06|(willQos<<3)|(willRetain<<5); + v = 0x04|(willQos<<3)|(willRetain<<5); } else { - v = 0x02; + v = 0x00; + } + if (cleanSession) { + v = v|0x02; } if(user != NULL) { @@ -204,20 +210,26 @@ bool PubSubClient::connect(const char *id, const char *user, const char *pass, buffer[length++] = ((MQTT_KEEPALIVE) >> 8); buffer[length++] = ((MQTT_KEEPALIVE) & 0xFF); + + CHECK_STRING_LENGTH(length,id) length = writeString(id,buffer,length); if (willTopic) { + CHECK_STRING_LENGTH(length,willTopic) length = writeString(willTopic,buffer,length); + CHECK_STRING_LENGTH(length,willMessage) length = writeString(willMessage,buffer,length); } if(user != NULL) { + CHECK_STRING_LENGTH(length,user) length = writeString(user,buffer,length); if(pass != NULL) { + CHECK_STRING_LENGTH(length,pass) length = writeString(pass,buffer,length); } } - write(MQTTCONNECT,buffer,length-5); + write(MQTTCONNECT,buffer,length-MQTT_MAX_HEADER_SIZE); lastInActivity = lastOutActivity = millis(); @@ -256,6 +268,7 @@ bool PubSubClient::readByte(uint8_t * result) { uint32_t previousMillis = millis(); while(!_client->available()) { + yield(); uint32_t currentMillis = millis(); if(currentMillis - previousMillis >= ((int32_t) MQTT_SOCKET_TIMEOUT * 1000)) { return false; @@ -291,6 +304,12 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) uint8_t start = 0; do { + if (len == 5) { + // Invalid remaining length encoding - kill the connection + _state = MQTT_DISCONNECTED; + _client->stop(); + return 0; + } if(!readByte(&digit)) { return 0; } @@ -364,16 +383,15 @@ bool PubSubClient::loop() uint8_t type = buffer[0]&0xF0; if (type == MQTTPUBLISH) { if (callback) { - uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2]; + uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2]; /* topic length in bytes */ + memmove(buffer+llen+2,buffer+llen+3,tl); /* move topic inside buffer 1 byte to front */ + buffer[llen+2+tl] = 0; /* end the topic as a 'C' string with \x00 */ + char *topic = (char*) buffer+llen+2; uint8_t *payload; - char topic[tl+1]; - for (uint16_t i=0; i0 if ((buffer[0]&0x06) == MQTTQOS1) { - uint16_t msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1]; + uint16_t msgId = 0; + msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1]; payload = buffer+llen+3+tl+2; callback(topic,payload,len-llen-3-tl-2); @@ -396,6 +414,9 @@ bool PubSubClient::loop() } else if (type == MQTTPINGRESP) { pingOutstanding = false; } + } else if (!connected()) { + // readPacket has closed the connection + return false; } } return true; @@ -422,12 +443,12 @@ bool PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned i bool retained) { if (connected()) { - if (MQTT_MAX_PACKET_SIZE < 5 + 2+strlen(topic) + plength) { + if (MQTT_MAX_PACKET_SIZE < MQTT_MAX_HEADER_SIZE + 2+strlen(topic) + plength) { // Too long return false; } // Leave room in the buffer for header and variable length field - uint16_t length = 5; + uint16_t length = MQTT_MAX_HEADER_SIZE; length = writeString(topic,buffer,length); uint16_t i; for (i=0; iwrite(buffer+(MQTT_MAX_HEADER_SIZE-hlen),length-(MQTT_MAX_HEADER_SIZE-hlen)); + lastOutActivity = millis(); + return (rc == (length-(MQTT_MAX_HEADER_SIZE-hlen))); + } + return false; +} + +int PubSubClient::endPublish() +{ + return 1; +} + +size_t PubSubClient::write(uint8_t data) +{ + lastOutActivity = millis(); + return _client->write(data); +} + +size_t PubSubClient::write(const uint8_t *buffer, size_t size) +{ + lastOutActivity = millis(); + return _client->write(buffer,size); +} + +size_t PubSubClient::buildHeader(uint8_t header, uint8_t* buf, uint16_t length) { uint8_t lenBuf[4]; uint8_t llen = 0; uint8_t pos = 0; - uint16_t rc; uint16_t len = length; do { uint8_t digit; @@ -507,12 +567,19 @@ bool PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) buf[4-llen] = header; for (int i=0; i 0) && result) { @@ -524,9 +591,9 @@ bool PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) } return result; #else - rc = _client->write(buf+(4-llen),length+1+llen); + rc = _client->write(buf+(MQTT_MAX_HEADER_SIZE-hlen),length+hlen); lastOutActivity = millis(); - return (rc == 1+llen+length); + return (rc == hlen+length); #endif } @@ -537,7 +604,6 @@ bool PubSubClient::subscribe(const char* topic) bool PubSubClient::subscribe(const char* topic, uint8_t qos) { - // original: if (qos < 0 || qos > 1) { (qos is uint8_t, hence qos < 0 impossible, tekka) if (qos > 1) { return false; } @@ -547,7 +613,7 @@ bool PubSubClient::subscribe(const char* topic, uint8_t qos) } if (connected()) { // Leave room in the buffer for header and variable length field - uint16_t length = 5; + uint16_t length = MQTT_MAX_HEADER_SIZE; nextMsgId++; if (nextMsgId == 0) { nextMsgId = 1; @@ -556,7 +622,7 @@ bool PubSubClient::subscribe(const char* topic, uint8_t qos) buffer[length++] = (nextMsgId & 0xFF); length = writeString((char*)topic, buffer,length); buffer[length++] = qos; - return write(MQTTSUBSCRIBE|MQTTQOS1,buffer,length-5); + return write(MQTTSUBSCRIBE|MQTTQOS1,buffer,length-MQTT_MAX_HEADER_SIZE); } return false; } @@ -568,7 +634,7 @@ bool PubSubClient::unsubscribe(const char* topic) return false; } if (connected()) { - uint16_t length = 5; + uint16_t length = MQTT_MAX_HEADER_SIZE; nextMsgId++; if (nextMsgId == 0) { nextMsgId = 1; @@ -576,7 +642,7 @@ bool PubSubClient::unsubscribe(const char* topic) buffer[length++] = (nextMsgId >> 8); buffer[length++] = (nextMsgId & 0xFF); length = writeString(topic, buffer,length); - return write(MQTTUNSUBSCRIBE|MQTTQOS1,buffer,length-5); + return write(MQTTUNSUBSCRIBE|MQTTQOS1,buffer,length-MQTT_MAX_HEADER_SIZE); } return false; } @@ -587,6 +653,7 @@ void PubSubClient::disconnect() buffer[1] = 0; _client->write(buffer,2); _state = MQTT_DISCONNECTED; + _client->flush(); _client->stop(); lastInActivity = lastOutActivity = millis(); } @@ -644,7 +711,6 @@ PubSubClient& PubSubClient::setServer(const char * domain, uint16_t port) this->port = port; return *this; } - // cppcheck-suppress passedByValue PubSubClient& PubSubClient::setCallback(MQTT_CALLBACK_SIGNATURE) { diff --git a/drivers/PubSubClient/PubSubClient.h b/drivers/PubSubClient/PubSubClient.h index 26b09c9e8..7332375a9 100644 --- a/drivers/PubSubClient/PubSubClient.h +++ b/drivers/PubSubClient/PubSubClient.h @@ -73,15 +73,20 @@ #define MQTTQOS1 (1 << 1) #define MQTTQOS2 (2 << 1) -#ifdef ESP8266 +// Maximum size of fixed header and variable length size header +#define MQTT_MAX_HEADER_SIZE 5 + +#if defined(ESP8266) || defined(ESP32) #include #define MQTT_CALLBACK_SIGNATURE std::function callback #else #define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int) #endif +#define CHECK_STRING_LENGTH(l,s) if (l+2+strlen(s) > MQTT_MAX_PACKET_SIZE) {_client->stop();return false;} + /** PubSubClient class */ -class PubSubClient +class PubSubClient : public Print { private: Client* _client; @@ -96,6 +101,11 @@ class PubSubClient bool readByte(uint8_t * result, uint16_t * index); bool write(uint8_t header, uint8_t* buf, uint16_t length); uint16_t writeString(const char* string, uint8_t* buf, uint16_t pos); + // Build up the header ready to send + // Returns the size of the header + // Note: the header is built at the end of the first MQTT_MAX_HEADER_SIZE bytes, so will start + // (MQTT_MAX_HEADER_SIZE - ) bytes into the buffer + size_t buildHeader(uint8_t header, uint8_t* buf, uint16_t length); IPAddress ip; const char* domain; uint16_t port; @@ -133,14 +143,34 @@ class PubSubClient const char* willMessage); //!< connect bool connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, bool willRetain, const char* willMessage); //!< connect + bool connect(const char* id, const char* user, const char* pass, const char* willTopic, + uint8_t willQos, bool willRetain, const char* willMessage, bool cleanSession); //!< connect void disconnect(); //!< disconnect bool publish(const char* topic, const char* payload); //!< publish bool publish(const char* topic, const char* payload, bool retained); //!< publish bool publish(const char* topic, const uint8_t * payload, unsigned int plength); //!< publish bool publish(const char* topic, const uint8_t * payload, unsigned int plength, bool retained); //!< publish + bool publish_P(const char* topic, const char* payload, bool retained); //!< publish bool publish_P(const char* topic, const uint8_t * payload, unsigned int plength, - bool retained); //!< publish_P + bool retained); //!< publish + // Start to publish a message. + // This API: + // beginPublish(...) + // one or more calls to write(...) + // endPublish() + // Allows for arbitrarily large payloads to be sent without them having to be copied into + // a new buffer and held in memory at one time + // Returns 1 if the message was started successfully, 0 if there was an error + bool beginPublish(const char* topic, unsigned int plength, bool retained); //!< beginPublish + // Finish off this publish message (started with beginPublish) + // Returns 1 if the packet was sent successfully, 0 if there was an error + int endPublish(); //!< endPublish + // Write a single byte of payload (only to be used with beginPublish/endPublish) + virtual size_t write(uint8_t); //!< write + // Write size bytes from buffer into the payload (only to be used with beginPublish/endPublish) + // Returns the number of bytes written + virtual size_t write(const uint8_t *buffer, size_t size); //!< write bool subscribe(const char* topic); //!< subscribe bool subscribe(const char* topic, uint8_t qos); //!< subscribe bool unsubscribe(const char* topic); //!< unsubscribe diff --git a/drivers/PubSubClient/README.md b/drivers/PubSubClient/README.md index 83176919c..69cbb8f0c 100644 --- a/drivers/PubSubClient/README.md +++ b/drivers/PubSubClient/README.md @@ -8,7 +8,7 @@ a server that supports MQTT. The library comes with a number of example sketches. See File > Examples > PubSubClient within the Arduino application. -Full API documentation is available here: http://pubsubclient.knolleary.net +Full API documentation is available here: https://pubsubclient.knolleary.net ## Limitations @@ -37,6 +37,7 @@ boards and shields, including: - TI CC3000 WiFi - [library](https://github.com/sparkfun/SFE_CC3000_Library) - Intel Galileo/Edison - ESP8266 + - ESP32 The library cannot currently be used with hardware based on the ENC28J60 chip – such as the Nanode or the Nuelectronics Ethernet Shield. For those, there is an From 121648f34bb45ab0e21fc4b4835959d27b28a9c6 Mon Sep 17 00:00:00 2001 From: tekka Date: Mon, 12 Nov 2018 21:36:10 +0100 Subject: [PATCH 31/31] MQTT GW: Add INDICATION_GW_RX (#1228) --- core/MyGatewayTransportMQTTClient.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/MyGatewayTransportMQTTClient.cpp b/core/MyGatewayTransportMQTTClient.cpp index ad9a92930..dce532a9a 100644 --- a/core/MyGatewayTransportMQTTClient.cpp +++ b/core/MyGatewayTransportMQTTClient.cpp @@ -119,10 +119,11 @@ bool gatewayTransportSend(MyMessage &message) return _MQTT_client.publish(topic, message.getString(_convBuffer), retain); } -void incomingMQTT(char* topic, uint8_t* payload, unsigned int length) +void incomingMQTT(char *topic, uint8_t *payload, unsigned int length) { GATEWAY_DEBUG(PSTR("GWT:IMQ:TOPIC=%s, MSG RECEIVED\n"), topic); _MQTT_available = protocolMQTTParse(_MQTT_msg, topic, payload, length); + setIndication(INDICATION_GW_RX); } bool reconnectMQTT(void)