Merge pull request #311 from tbowmo/samd

Samd
This commit is contained in:
Patrick Fallberg
2016-01-03 23:35:32 +01:00
13 changed files with 56 additions and 41 deletions
@@ -189,6 +189,12 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#define MYSX_A1 #define MYSX_A1
#define MYSX_A2 #define MYSX_A2
#define MY_SIGNING_ATSHA204_PIN 17
#define MY_DEFAULT_ERR_LED_PIN LED_RED
#define MY_DEFAULT_RX_LED_PIN LED_YELLOW
#define MY_DEFAULT_TX_LED_PIN LED_GREEN
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
* Arduino objects - C++ only * Arduino objects - C++ only
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@@ -226,11 +232,12 @@ extern Uart Serial1;
// //
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default. // pins are NOT connected to anything by default.
#define SERIAL_PORT_USBVIRTUAL SerialUSB //#define SERIAL_PORT_USBVIRTUAL SerialUSB
#define SERIAL_PORT_MONITOR Serial //#define SERIAL_PORT_MONITOR Serial
// Serial has no physical pins broken out, so it's not listed as HARDWARE port // Serial has no physical pins broken out, so it's not listed as HARDWARE port
#define SERIAL_PORT_HARDWARE Serial1 //#define SERIAL_PORT_HARDWARE Serial1
#define SERIAL_PORT_HARDWARE_OPEN Serial1 //#define SERIAL_PORT_HARDWARE_OPEN Serial1
#define Serial SerialUSB
#endif /* _VARIANT_ARDUINO_ZERO_ */ #endif /* _VARIANT_ARDUINO_ZERO_ */
@@ -107,22 +107,22 @@ bool gatewayTransportInit() {
while (WiFi.status() != WL_CONNECTED) while (WiFi.status() != WL_CONNECTED)
{ {
delay(500); delay(500);
SERIALDEVICE.print("."); MY_SERIALDEVICE.print(".");
yield(); yield();
} }
SERIALDEVICE.print(F("IP: ")); MY_SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(WiFi.localIP()); MY_SERIALDEVICE.println(WiFi.localIP());
#else #else
#ifdef MY_IP_ADDRESS #ifdef MY_IP_ADDRESS
Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP); Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
SERIALDEVICE.print(F("IP: ")); MY_SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP()); MY_SERIALDEVICE.println(Ethernet.localIP());
#else #else
// Get IP address from DHCP // Get IP address from DHCP
Ethernet.begin(_ethernetGatewayMAC); Ethernet.begin(_ethernetGatewayMAC);
SERIALDEVICE.print(F("IP: ")); MY_SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP()); MY_SERIALDEVICE.println(Ethernet.localIP());
#endif /* IP_ADDRESS_DHCP */ #endif /* IP_ADDRESS_DHCP */
// give the Ethernet interface a second to initialize // give the Ethernet interface a second to initialize
// TODO: use HW delay // TODO: use HW delay
@@ -161,21 +161,21 @@ bool gatewayTransportInit() {
while (WiFi.status() != WL_CONNECTED) while (WiFi.status() != WL_CONNECTED)
{ {
delay(500); delay(500);
SERIALDEVICE.print("."); MY_SERIALDEVICE.print(".");
yield(); yield();
} }
SERIALDEVICE.print(F("IP: ")); MY_SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(WiFi.localIP()); MY_SERIALDEVICE.println(WiFi.localIP());
#else #else
#ifdef MY_IP_ADDRESS #ifdef MY_IP_ADDRESS
Ethernet.begin(_clientMAC, _clientIp); Ethernet.begin(_clientMAC, _clientIp);
SERIALDEVICE.print(F("IP: ")); MY_SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP()); MY_SERIALDEVICE.println(Ethernet.localIP());
#else #else
// Get IP address from DHCP // Get IP address from DHCP
Ethernet.begin(_clientMAC); Ethernet.begin(_clientMAC);
SERIALDEVICE.print(F("IP: ")); MY_SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP()); MY_SERIALDEVICE.println(Ethernet.localIP());
#endif /* IP_ADDRESS_DHCP */ #endif /* IP_ADDRESS_DHCP */
// give the Ethernet interface a second to initialize // give the Ethernet interface a second to initialize
// TODO: use HW delay // TODO: use HW delay
@@ -31,7 +31,7 @@ MyMessage _serialMsg;
bool gatewayTransportSend(MyMessage &message) { bool gatewayTransportSend(MyMessage &message) {
SERIALDEVICE.print(protocolFormat(message)); MY_SERIALDEVICE.print(protocolFormat(message));
// Serial print is always successful // Serial print is always successful
return true; return true;
} }
@@ -45,9 +45,9 @@ bool gatewayTransportInit() {
bool gatewayTransportAvailable() { bool gatewayTransportAvailable() {
bool available = false; bool available = false;
while (SERIALDEVICE.available()) { while (MY_SERIALDEVICE.available()) {
// get the new byte: // get the new byte:
char inChar = (char) SERIALDEVICE.read(); char inChar = (char) MY_SERIALDEVICE.read();
// if the incoming character is a newline, set a flag // if the incoming character is a newline, set a flag
// so the main loop can do something about it: // so the main loop can do something about it:
if (_serialInputPos < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1 && !available) { if (_serialInputPos < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1 && !available) {
+1 -1
View File
@@ -36,7 +36,7 @@
#include <Arduino.h> #include <Arduino.h>
#endif #endif
#define SERIALDEVICE Serial #define MY_SERIALDEVICE Serial
#if defined __AVR_ATmega328P__ #if defined __AVR_ATmega328P__
#ifndef sleep_bod_disable #ifndef sleep_bod_disable
#define sleep_bod_disable() \ #define sleep_bod_disable() \
+1 -1
View File
@@ -30,7 +30,7 @@
//#include <SPI.h> //#include <SPI.h>
#endif #endif
#define SERIALDEVICE Serial #define MY_SERIALDEVICE Serial
#define min(a,b) ((a)<(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b))
+10 -5
View File
@@ -99,8 +99,11 @@ void hwWriteConfig(int adr, uint8_t value)
} }
void hwInit() { void hwInit() {
SERIALDEVICE.begin(MY_BAUD_RATE); MY_SERIALDEVICE.begin(MY_BAUD_RATE);
while (!SERIALDEVICE) {} #ifndef MY_GATEWAY_W5100
while (!MY_SERIALDEVICE) {}
#endif
Wire.begin();
} }
void hwWatchdogReset() { void hwWatchdogReset() {
@@ -137,11 +140,12 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
#ifdef MY_DEBUG #ifdef MY_DEBUG
void hwDebugPrint(const char *fmt, ... ) { void hwDebugPrint(const char *fmt, ... ) {
if (MY_SERIALDEVICE) {
char fmtBuffer[300]; char fmtBuffer[300];
#ifdef MY_GATEWAY_FEATURE #ifdef MY_GATEWAY_FEATURE
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf(fmtBuffer, 299, PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE); snprintf(fmtBuffer, 299, PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
SERIALDEVICE.print(fmtBuffer); MY_SERIALDEVICE.print(fmtBuffer);
#endif #endif
va_list args; va_list args;
va_start (args, fmt ); va_start (args, fmt );
@@ -155,9 +159,10 @@ void hwDebugPrint(const char *fmt, ... ) {
vsnprintf(fmtBuffer, 299, fmt, args); vsnprintf(fmtBuffer, 299, fmt, args);
#endif #endif
va_end (args); va_end (args);
SERIALDEVICE.print(fmtBuffer); MY_SERIALDEVICE.print(fmtBuffer);
// SERIALDEVICE.flush(); // MY_SERIALDEVICE.flush();
//Serial.write(freeRam()); //Serial.write(freeRam());
}
} }
#endif #endif
+2 -2
View File
@@ -31,7 +31,7 @@
#endif #endif
#include <avr/dtostrf.h> #include <avr/dtostrf.h>
#define I2C_EEP_ADDRESS 55 #define I2C_EEP_ADDRESS 0x50
#define min(a,b) ((a)<(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b))
@@ -52,7 +52,7 @@ void hwWriteConfigBlock(void* buf, void* adr, size_t length);
void hwWriteConfig(int adr, uint8_t value); void hwWriteConfig(int adr, uint8_t value);
uint8_t hwReadConfig(int adr); uint8_t hwReadConfig(int adr);
#define SERIALDEVICE SerialUSB #define MY_SERIALDEVICE SerialUSB
/* /*
@@ -63,7 +63,7 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
#ifdef MY_GATEWAY_FEATURE #ifdef MY_GATEWAY_FEATURE
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(printBuffer, 299, PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE); snprintf_P(printBuffer, 299, PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
SERIALDEVICE.print(printBuffer); MY_SERIALDEVICE.print(printBuffer);
#endif #endif
for (int i=0; i<sz; i++) for (int i=0; i<sz; i++)
{ {
@@ -75,12 +75,12 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
// Truncate message if this is gateway node // Truncate message if this is gateway node
printBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1-strlen_P((const char*)str)] = '\0'; printBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1-strlen_P((const char*)str)] = '\0';
#endif #endif
SERIALDEVICE.print(str); MY_SERIALDEVICE.print(str);
if (sz > 0) if (sz > 0)
{ {
SERIALDEVICE.print(printBuffer); MY_SERIALDEVICE.print(printBuffer);
} }
SERIALDEVICE.println(""); MY_SERIALDEVICE.println("");
} }
#else #else
#define DEBUG_SIGNING_PRINTBUF(str, buf, sz) #define DEBUG_SIGNING_PRINTBUF(str, buf, sz)
@@ -66,7 +66,7 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
#ifdef MY_GATEWAY_FEATURE #ifdef MY_GATEWAY_FEATURE
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE) // prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(printBuffer, 299, PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE); snprintf_P(printBuffer, 299, PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
SERIALDEVICE.print(printBuffer); MY_SERIALDEVICE.print(printBuffer);
#endif #endif
for (int i=0; i<sz; i++) for (int i=0; i<sz; i++)
{ {
@@ -78,12 +78,12 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
// Truncate message if this is gateway node // Truncate message if this is gateway node
printBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1-strlen_P((const char*)str)] = '\0'; printBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1-strlen_P((const char*)str)] = '\0';
#endif #endif
SERIALDEVICE.print(str); MY_SERIALDEVICE.print(str);
if (sz > 0) if (sz > 0)
{ {
SERIALDEVICE.print(printBuffer); MY_SERIALDEVICE.print(printBuffer);
} }
SERIALDEVICE.println(""); MY_SERIALDEVICE.println("");
} }
#else #else
#define DEBUG_SIGNING_PRINTBUF(str, buf, sz) #define DEBUG_SIGNING_PRINTBUF(str, buf, sz)
@@ -72,9 +72,11 @@
// Digital pin used for inclusion mode button // Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3 #define MY_INCLUSION_MODE_BUTTON_PIN 3
#ifndef MY_DEFAULT_ERR_LED_PIN
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin #define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin #define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED #define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED
#endif
#include <SPI.h> #include <SPI.h>
#include <MySensor.h> #include <MySensor.h>
@@ -57,7 +57,7 @@
// Enable Soft SPI for NRF radio (note different radio wiring is required) // Enable Soft SPI for NRF radio (note different radio wiring is required)
// The W5100 ethernet module seems to have a hard time co-operate with // The W5100 ethernet module seems to have a hard time co-operate with
// radio on the same spi bus. // radio on the same spi bus.
#if !defined(MY_W5100_SPI_EN) #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
#define MY_SOFTSPI #define MY_SOFTSPI
#define MY_SOFT_SPI_SCK_PIN 14 #define MY_SOFT_SPI_SCK_PIN 14
#define MY_SOFT_SPI_MISO_PIN 16 #define MY_SOFT_SPI_MISO_PIN 16
@@ -100,9 +100,11 @@
// Digital pin used for inclusion mode button // Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3 #define MY_INCLUSION_MODE_BUTTON_PIN 3
#ifndef MY_DEFAULT_ERR_LED_PIN
#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin #define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin #define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 9 // the PCB, on board LED #define MY_DEFAULT_TX_LED_PIN 9 // the PCB, on board LED
#endif
#include <SPI.h> #include <SPI.h>
@@ -57,7 +57,6 @@
* Make sure to fill in your ssid and WiFi password below for ssid & pass. * Make sure to fill in your ssid and WiFi password below for ssid & pass.
*/ */
#include <EEPROM.h>
#include <SPI.h> #include <SPI.h>
// Enable debug prints to serial monitor // Enable debug prints to serial monitor
@@ -82,7 +81,7 @@
// Enable Soft SPI for NRF radio (note different radio wiring is required) // Enable Soft SPI for NRF radio (note different radio wiring is required)
// The W5100 ethernet module seems to have a hard time co-operate with // The W5100 ethernet module seems to have a hard time co-operate with
// radio on the same spi bus. // radio on the same spi bus.
#if !defined(MY_W5100_SPI_EN) #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
#define MY_SOFTSPI #define MY_SOFTSPI
#define MY_SOFT_SPI_SCK_PIN 14 #define MY_SOFT_SPI_SCK_PIN 14
#define MY_SOFT_SPI_MISO_PIN 16 #define MY_SOFT_SPI_MISO_PIN 16