diff --git a/MySensors.h b/MySensors.h index e60234d..2501983 100644 --- a/MySensors.h +++ b/MySensors.h @@ -41,34 +41,40 @@ #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" -// OTA Debug, have to defined before HAL +// OTA Debug, has to be defined before HAL #if defined(MY_OTA_LOG_SENDER_FEATURE) || defined(MY_OTA_LOG_RECEIVER_FEATURE) #include "core/MyOTALogging.h" #endif // HARDWARE +#include "hal/architecture/MyHw.h" #if defined(ARDUINO_ARCH_ESP8266) -#include "hal/architecture/MyHwESP8266.cpp" +#include "hal/architecture/ESP8266/MyHwESP8266.cpp" #elif defined(ARDUINO_ARCH_AVR) #include "drivers/AVR/DigitalWriteFast/digitalWriteFast.h" -#include "hal/architecture/MyHwAVR.cpp" +#include "hal/architecture/AVR/MyHwAVR.cpp" #elif defined(ARDUINO_ARCH_SAMD) #include "drivers/extEEPROM/extEEPROM.cpp" -#include "hal/architecture/MyHwSAMD.cpp" +#include "hal/architecture/SAMD/MyHwSAMD.cpp" #elif defined(ARDUINO_ARCH_STM32F1) -#include "hal/architecture/MyHwSTM32F1.cpp" +#include "hal/architecture/STM32F1/MyHwSTM32F1.cpp" #elif defined(ARDUINO_ARCH_NRF5) || defined(ARDUINO_ARCH_NRF52) #include "drivers/NVM/VirtualPage.cpp" #include "drivers/NVM/NVRAM.cpp" -#include "hal/architecture/MyHwNRF5.cpp" +#include "hal/architecture/NRF5/MyHwNRF5.cpp" #elif defined(__arm__) && defined(TEENSYDUINO) -#include "hal/architecture/MyHwTeensy3.cpp" +#include "hal/architecture/Teensy3/MyHwTeensy3.cpp" #elif defined(__linux__) -#include "hal/architecture/MyHwLinuxGeneric.cpp" +#include "hal/architecture/Linux/MyHwLinuxGeneric.cpp" #endif // OTA Debug second part, depends on HAL @@ -130,7 +136,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs // GATEWAY - TRANSPORT #if defined(MY_CONTROLLER_IP_ADDRESS) || defined(MY_CONTROLLER_URL_ADDRESS) -#define MY_GATEWAY_CLIENT_MODE +#define MY_GATEWAY_CLIENT_MODE //!< gateway client mode #endif #if defined(MY_USE_UDP) && !defined(MY_GATEWAY_CLIENT_MODE) @@ -248,7 +254,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs // SANITY CHECK #if defined(MY_REPEATER_FEATURE) || defined(MY_GATEWAY_FEATURE) -#define MY_TRANSPORT_SANITY_CHECK +#define MY_TRANSPORT_SANITY_CHECK //!< enable regular transport sanity checks #endif // TRANSPORT INCLUDES @@ -268,7 +274,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs // RAM ROUTING TABLE #if defined(MY_RAM_ROUTING_TABLE_FEATURE) && defined(MY_REPEATER_FEATURE) // activate feature based on architecture -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_NRF5) || defined(__linux__) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_NRF5) || defined(ARDUINO_ARCH_STM32F1) || defined(TEENSYDUINO) || defined(__linux__) #define MY_RAM_ROUTING_TABLE_ENABLED #elif defined(ARDUINO_ARCH_AVR) #if defined(__avr_atmega1280__) || defined(__avr_atmega1284__) || defined(__avr_atmega2560__) @@ -306,7 +312,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs #include "drivers/RF24/RF24.cpp" #include "hal/transport/MyTransportRF24.cpp" #elif defined(MY_RADIO_NRF5_ESB) -#if !defined(ARDUINO_ARCH_NRF5) +#if !defined(ARDUINO_ARCH_NRF5) #error No support for nRF5 radio on this platform #endif #if defined(MY_NRF5_ESB_ENABLE_ENCRYPTION) @@ -382,16 +388,20 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs // HW mains #if !defined(MY_CORE_ONLY) -#if defined(ARDUINO_ARCH_ESP8266) -#include "hal/architecture/MyMainESP8266.cpp" +#if defined(ARDUINO_ARCH_AVR) +#include "hal/architecture/AVR/MyMainAVR.cpp" +#elif defined(ARDUINO_ARCH_SAMD) +#include "hal/architecture/SAMD/MyMainSAMD.cpp" +#elif defined(ARDUINO_ARCH_ESP8266) +#include "hal/architecture/ESP8266/MyMainESP8266.cpp" +#elif defined(ARDUINO_ARCH_NRF5) +#include "hal/architecture/NRF5/MyMainNRF5.cpp" #elif defined(__linux__) -#include "hal/architecture/MyMainLinux.cpp" +#include "hal/architecture/Linux/MyMainLinux.cpp" #elif defined(ARDUINO_ARCH_STM32F1) -#include "hal/architecture/MyMainSTM32F1.cpp" +#include "hal/architecture/STM32F1/MyMainSTM32F1.cpp" #elif defined(TEENSYDUINO) -#include "hal/architecture/MyMainTeensy3.cpp" -#else -#include "hal/architecture/MyMainDefault.cpp" +#include "hal/architecture/Teensy3/MyMainTeensy3.cpp" #endif #endif diff --git a/drivers/NRF5/Radio_ESB.cpp b/drivers/NRF5/Radio_ESB.cpp index dfa6e2e..c4e9a0d 100644 --- a/drivers/NRF5/Radio_ESB.cpp +++ b/drivers/NRF5/Radio_ESB.cpp @@ -21,7 +21,7 @@ #include "Radio.h" #include "Radio_ESB.h" -#include "hal/architecture/MyHwNRF5.h" +#include "hal/architecture/NRF5/MyHwNRF5.h" #include "drivers/CircularBuffer/CircularBuffer.h" #include diff --git a/drivers/RF24/RF24.h b/drivers/RF24/RF24.h index 0634cd2..6f709e2 100644 --- a/drivers/RF24/RF24.h +++ b/drivers/RF24/RF24.h @@ -105,10 +105,6 @@ _SPI; #include #include -#if !defined(_BV) -#define _BV(x) (1<<(x)) //!< _BV() -#endif - #if defined(__arm__) || defined(__linux__) #include #else diff --git a/hal/architecture/MyHwAVR.cpp b/hal/architecture/AVR/MyHwAVR.cpp similarity index 100% rename from hal/architecture/MyHwAVR.cpp rename to hal/architecture/AVR/MyHwAVR.cpp diff --git a/hal/architecture/MyHwAVR.h b/hal/architecture/AVR/MyHwAVR.h similarity index 98% rename from hal/architecture/MyHwAVR.h rename to hal/architecture/AVR/MyHwAVR.h index bf535c8..a189f70 100644 --- a/hal/architecture/MyHwAVR.h +++ b/hal/architecture/AVR/MyHwAVR.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 @@ -20,7 +20,6 @@ #ifndef MyHwAVR_h #define MyHwAVR_h -#include "MyHw.h" #include #include #include diff --git a/hal/architecture/AVR/MyMainAVR.cpp b/hal/architecture/AVR/MyMainAVR.cpp new file mode 100644 index 0000000..8c67595 --- /dev/null +++ b/hal/architecture/AVR/MyMainAVR.cpp @@ -0,0 +1,39 @@ +/* + * 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-2017 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. + */ + +// Initialize library and handle sketch functions like we want to + +int main(void) +{ + init(); +#if defined(USBCON) + USBDevice.attach(); +#endif + _begin(); // Startup MySensors library + for(;;) { + _process(); // Process incoming data + if (loop) { + loop(); // Call sketch loop + } + if (serialEventRun) { + serialEventRun(); + } + } + return 0; +} diff --git a/hal/architecture/MyHwESP8266.cpp b/hal/architecture/ESP8266/MyHwESP8266.cpp similarity index 100% rename from hal/architecture/MyHwESP8266.cpp rename to hal/architecture/ESP8266/MyHwESP8266.cpp diff --git a/hal/architecture/MyHwESP8266.h b/hal/architecture/ESP8266/MyHwESP8266.h similarity index 98% rename from hal/architecture/MyHwESP8266.h rename to hal/architecture/ESP8266/MyHwESP8266.h index 0890687..4057261 100644 --- a/hal/architecture/MyHwESP8266.h +++ b/hal/architecture/ESP8266/MyHwESP8266.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 @@ -19,8 +19,6 @@ #ifndef MyHwESP8266_h #define MyHwESP8266_h -#include "MyHw.h" - #ifdef __cplusplus #include #endif diff --git a/hal/architecture/MyMainESP8266.cpp b/hal/architecture/ESP8266/MyMainESP8266.cpp similarity index 100% rename from hal/architecture/MyMainESP8266.cpp rename to hal/architecture/ESP8266/MyMainESP8266.cpp diff --git a/hal/architecture/MyHwLinuxGeneric.cpp b/hal/architecture/Linux/MyHwLinuxGeneric.cpp similarity index 100% rename from hal/architecture/MyHwLinuxGeneric.cpp rename to hal/architecture/Linux/MyHwLinuxGeneric.cpp diff --git a/hal/architecture/MyHwLinuxGeneric.h b/hal/architecture/Linux/MyHwLinuxGeneric.h similarity index 99% rename from hal/architecture/MyHwLinuxGeneric.h rename to hal/architecture/Linux/MyHwLinuxGeneric.h index 3c57b98..a933632 100644 --- a/hal/architecture/MyHwLinuxGeneric.h +++ b/hal/architecture/Linux/MyHwLinuxGeneric.h @@ -22,7 +22,6 @@ #include #include -#include "MyHw.h" #include "SerialPort.h" #include "SerialSimulator.h" diff --git a/hal/architecture/MyMainLinux.cpp b/hal/architecture/Linux/MyMainLinux.cpp similarity index 100% rename from hal/architecture/MyMainLinux.cpp rename to hal/architecture/Linux/MyMainLinux.cpp diff --git a/hal/architecture/MyHwNRF5.cpp b/hal/architecture/NRF5/MyHwNRF5.cpp similarity index 100% rename from hal/architecture/MyHwNRF5.cpp rename to hal/architecture/NRF5/MyHwNRF5.cpp diff --git a/hal/architecture/MyHwNRF5.h b/hal/architecture/NRF5/MyHwNRF5.h similarity index 99% rename from hal/architecture/MyHwNRF5.h rename to hal/architecture/NRF5/MyHwNRF5.h index 3a8f2b0..ff3f8e3 100644 --- a/hal/architecture/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 @@ -22,8 +22,6 @@ #ifndef MyHwNRF5_h #define MyHwNRF5_h -#include "MyHw.h" - #ifdef __cplusplus #include #endif diff --git a/hal/architecture/NRF5/MyMainNRF5.cpp b/hal/architecture/NRF5/MyMainNRF5.cpp new file mode 100644 index 0000000..8c67595 --- /dev/null +++ b/hal/architecture/NRF5/MyMainNRF5.cpp @@ -0,0 +1,39 @@ +/* + * 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-2017 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. + */ + +// Initialize library and handle sketch functions like we want to + +int main(void) +{ + init(); +#if defined(USBCON) + USBDevice.attach(); +#endif + _begin(); // Startup MySensors library + for(;;) { + _process(); // Process incoming data + if (loop) { + loop(); // Call sketch loop + } + if (serialEventRun) { + serialEventRun(); + } + } + return 0; +} diff --git a/hal/architecture/MyHwSAMD.cpp b/hal/architecture/SAMD/MyHwSAMD.cpp similarity index 100% rename from hal/architecture/MyHwSAMD.cpp rename to hal/architecture/SAMD/MyHwSAMD.cpp diff --git a/hal/architecture/MyHwSAMD.h b/hal/architecture/SAMD/MyHwSAMD.h similarity index 99% rename from hal/architecture/MyHwSAMD.h rename to hal/architecture/SAMD/MyHwSAMD.h index a3ca0d8..a567092 100644 --- a/hal/architecture/MyHwSAMD.h +++ b/hal/architecture/SAMD/MyHwSAMD.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 @@ -19,8 +19,6 @@ #ifndef MyHwSAMD_h #define MyHwSAMD_h -#include "MyHw.h" - #ifdef __cplusplus #include #endif diff --git a/hal/architecture/MyMainDefault.cpp b/hal/architecture/SAMD/MyMainSAMD.cpp similarity index 96% rename from hal/architecture/MyMainDefault.cpp rename to hal/architecture/SAMD/MyMainSAMD.cpp index 419aec2..9bd40b7 100644 --- a/hal/architecture/MyMainDefault.cpp +++ b/hal/architecture/SAMD/MyMainSAMD.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 @@ -25,14 +25,11 @@ int main(void) { init(); #if defined(USBCON) -#if defined(ARDUINO_ARCH_SAMD) __libc_init_array(); USBDevice.init(); -#endif USBDevice.attach(); #endif _begin(); // Startup MySensors library - for(;;) { _process(); // Process incoming data if (loop) { diff --git a/hal/architecture/MyHwSTM32F1.cpp b/hal/architecture/STM32F1/MyHwSTM32F1.cpp similarity index 100% rename from hal/architecture/MyHwSTM32F1.cpp rename to hal/architecture/STM32F1/MyHwSTM32F1.cpp diff --git a/hal/architecture/MyHwSTM32F1.h b/hal/architecture/STM32F1/MyHwSTM32F1.h similarity index 99% rename from hal/architecture/MyHwSTM32F1.h rename to hal/architecture/STM32F1/MyHwSTM32F1.h index f123700..ae27ba0 100644 --- a/hal/architecture/MyHwSTM32F1.h +++ b/hal/architecture/STM32F1/MyHwSTM32F1.h @@ -20,8 +20,6 @@ #ifndef MyHwSTM32F1_h #define MyHwSTM32F1_h -#include "MyHw.h" - #include #include #include diff --git a/hal/architecture/MyMainSTM32F1.cpp b/hal/architecture/STM32F1/MyMainSTM32F1.cpp similarity index 100% rename from hal/architecture/MyMainSTM32F1.cpp rename to hal/architecture/STM32F1/MyMainSTM32F1.cpp diff --git a/hal/architecture/MyHwTeensy3.cpp b/hal/architecture/Teensy3/MyHwTeensy3.cpp similarity index 100% rename from hal/architecture/MyHwTeensy3.cpp rename to hal/architecture/Teensy3/MyHwTeensy3.cpp diff --git a/hal/architecture/MyHwTeensy3.h b/hal/architecture/Teensy3/MyHwTeensy3.h similarity index 99% rename from hal/architecture/MyHwTeensy3.h rename to hal/architecture/Teensy3/MyHwTeensy3.h index 990bdaf..863b555 100644 --- a/hal/architecture/MyHwTeensy3.h +++ b/hal/architecture/Teensy3/MyHwTeensy3.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 @@ -28,7 +28,6 @@ #ifndef MyHwTeensy3_h #define MyHwTeensy3_h -#include "MyHw.h" #ifdef __cplusplus #include #endif diff --git a/hal/architecture/MyMainTeensy3.cpp b/hal/architecture/Teensy3/MyMainTeensy3.cpp similarity index 100% rename from hal/architecture/MyMainTeensy3.cpp rename to hal/architecture/Teensy3/MyMainTeensy3.cpp