Initial commit for SAMD compatability

This commit is contained in:
Thomas Mørch
2015-12-06 23:16:44 +01:00
parent 9540cb2b30
commit e229e21d0e
19 changed files with 319 additions and 67 deletions
@@ -107,22 +107,22 @@ bool gatewayTransportInit() {
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
SERIALDEVICE.print(".");
yield();
}
Serial.print(F("IP: "));
Serial.println(WiFi.localIP());
SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(WiFi.localIP());
#else
#ifdef MY_IP_ADDRESS
Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
Serial.print(F("IP: "));
Serial.println(Ethernet.localIP());
SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP());
#else
// Get IP address from DHCP
Ethernet.begin(_ethernetGatewayMAC);
Serial.print(F("IP: "));
Serial.println(Ethernet.localIP());
SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP());
#endif /* IP_ADDRESS_DHCP */
// give the Ethernet interface a second to initialize
// TODO: use HW delay
@@ -144,21 +144,21 @@ bool gatewayTransportInit() {
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
SERIALDEVICE.print(".");
yield();
}
Serial.print(F("IP: "));
Serial.println(WiFi.localIP());
SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(WiFi.localIP());
#else
#ifdef MY_IP_ADDRESS
Ethernet.begin(_clientMAC, _clientIp);
Serial.print(F("IP: "));
Serial.println(Ethernet.localIP());
SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP());
#else
// Get IP address from DHCP
Ethernet.begin(_clientMAC);
Serial.print(F("IP: "));
Serial.println(Ethernet.localIP());
SERIALDEVICE.print(F("IP: "));
SERIALDEVICE.println(Ethernet.localIP());
#endif /* IP_ADDRESS_DHCP */
// give the Ethernet interface a second to initialize
// TODO: use HW delay
@@ -31,7 +31,7 @@ MyMessage _serialMsg;
bool gatewayTransportSend(MyMessage &message) {
Serial.print(protocolFormat(message));
SERIALDEVICE.print(protocolFormat(message));
// Serial print is always successful
return true;
}
@@ -45,9 +45,9 @@ bool gatewayTransportInit() {
bool gatewayTransportAvailable() {
bool available = false;
while (Serial.available()) {
while (SERIALDEVICE.available()) {
// get the new byte:
char inChar = (char) Serial.read();
char inChar = (char) SERIALDEVICE.read();
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (_serialInputPos < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1 && !available) {
+1
View File
@@ -36,6 +36,7 @@
#include <Arduino.h>
#endif
#define SERIALDEVICE Serial
#if defined __AVR_ATmega328P__
#ifndef sleep_bod_disable
#define sleep_bod_disable() \
+1 -1
View File
@@ -30,7 +30,7 @@
//#include <SPI.h>
#endif
#define SERIALDEVICE Serial
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
+151
View File
@@ -0,0 +1,151 @@
/**
* 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 <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 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 "MyHwSAMD.h"
/*
int8_t pinIntTrigger = 0;
void wakeUp() //place to send the interrupts
{
pinIntTrigger = 1;
}
void wakeUp2() //place to send the second interrupts
{
pinIntTrigger = 2;
}
// Watchdog Timer interrupt service routine. This routine is required
// to allow automatic WDIF and WDIE bit clearance in hardware.
ISR (WDT_vect)
{
// WDIE & WDIF is cleared in hardware upon entering this ISR
wdt_disable();
}
*/
static void hwInitConfigBlock( size_t length = 1024)
{
static bool initDone = false;
if (!initDone)
{
initDone = true;
}
}
void hwReadConfigBlock(void* buf, void* adr, size_t length)
{
hwInitConfigBlock();
uint8_t* dst = static_cast<uint8_t*>(buf);
int offs = reinterpret_cast<int>(adr);
while (length-- > 0)
{
*dst++ = configBlock[offs++];
}
}
void hwWriteConfigBlock(void* buf, void* adr, size_t length)
{
hwInitConfigBlock();
uint8_t* src = static_cast<uint8_t*>(buf);
int offs = reinterpret_cast<int>(adr);
while (length-- > 0)
{
configBlock[offs++] = *src++;
}
}
uint8_t hwReadConfig(int adr)
{
uint8_t value;
hwReadConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
return value;
}
void hwWriteConfig(int adr, uint8_t value)
{
uint8_t curr = hwReadConfig(adr);
if (curr != value)
{
hwWriteConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
}
}
void hwInit() {
SERIALDEVICE.begin(MY_BAUD_RATE);
while (!SERIALDEVICE) {}
}
void hwWatchdogReset() {
// TODO: Not supported!
}
void hwReboot() {
// TODO: Not supported!
}
void hwSleep(unsigned long ms) {
// TODO: Not supported!
ms = ms + 1;
}
bool hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
// TODO: Not supported!
interrupt = interrupt;
mode = mode;
ms = ms;
return false;
}
uint8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
// TODO: Not supported!
interrupt1 = interrupt1;
mode1 = mode1;
interrupt2 = interrupt2;
mode2 = mode2;
ms = ms;
return 0;
}
#ifdef MY_DEBUG
void hwDebugPrint(const char *fmt, ... ) {
char fmtBuffer[300];
#ifdef MY_GATEWAY_FEATURE
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf(fmtBuffer, 299, PSTR("0;0;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
SERIALDEVICE.print(fmtBuffer);
#endif
va_list args;
va_start (args, fmt );
va_end (args);
#ifdef MY_GATEWAY_FEATURE
// Truncate message if this is gateway node
vsnprintf(fmtBuffer, 60, fmt, args);
fmtBuffer[59] = '\n';
fmtBuffer[60] = '\0';
#else
vsnprintf(fmtBuffer, 299, fmt, args);
#endif
va_end (args);
SERIALDEVICE.print(fmtBuffer);
// SERIALDEVICE.flush();
//Serial.write(freeRam());
}
#endif
+64
View File
@@ -0,0 +1,64 @@
/**
* 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 <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 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 MyHwSAMD_h
#define MyHwSAMD_h
#include "MyHw.h"
#include "MyConfig.h"
#include "MyMessage.h"
#ifdef __cplusplus
#include <Arduino.h>
//#include <SPI.h>
#endif
#include <avr/dtostrf.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
// Define these as macros to save valuable space
uint8_t configBlock[1024];
#define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value))
void hwInit();
void hwWatchdogReset();
void hwReboot();
#define hwMillis() millis()
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);
#define SERIALDEVICE SerialUSB
/*
#define hwReadConfigBlock(__buf, __adr, __length) ( __length = __length)
#define hwWriteConfigBlock(__buf, __adr, __length) ( __length = __length)
#define hwWriteConfig(__adr, __value) ( __value = __value)
#define hwReadConfig(__adr) (0)
*/
SPIClass _SPI( &sercom1, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI );
#define USBCON
#endif // #ifdef ARDUINO_ARCH_SAMD
+1 -1
View File
@@ -37,7 +37,7 @@ void inclusionModeSet(boolean newMode) {
if (newMode != _inclusionMode) {
_inclusionMode = newMode;
// Send back mode change to controller
gatewayTransportSend(buildGw(_msg, I_INCLUSION_MODE).set(_inclusionMode?1:0));
gatewayTransportSend(buildGw(_msg, I_INCLUSION_MODE).set((uint8_t)(_inclusionMode?1:0)));
if (_inclusionMode) {
_inclusionStartTime = hwMillis();
}
+2 -1
View File
@@ -3,7 +3,8 @@
int main(void) {
init();
#if defined(USBCON)
USBDevice.attach();
USBDevice.init();
USBDevice.attach();
#endif
_begin(); // Startup MySensors library
@@ -64,7 +64,7 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
#ifdef MY_GATEWAY_FEATURE
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(printBuffer, 299, PSTR("0;0;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
Serial.print(printBuffer);
SERIALDEVICE.print(printBuffer);
#endif
for (int i=0; i<sz; i++)
{
@@ -76,12 +76,12 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf,
// Truncate message if this is gateway node
printBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1-strlen_P((const char*)str)] = '\0';
#endif
Serial.print(str);
SERIALDEVICE.print(str);
if (sz > 0)
{
Serial.print(printBuffer);
SERIALDEVICE.print(printBuffer);
}
Serial.println("");
SERIALDEVICE.println("");
}
#else
#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
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
snprintf_P(printBuffer, 299, PSTR("0;0;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
Serial.print(printBuffer);
SERIALDEVICE.print(printBuffer);
#endif
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
printBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1-strlen_P((const char*)str)] = '\0';
#endif
Serial.print(str);
SERIALDEVICE.print(str);
if (sz > 0)
{
Serial.print(printBuffer);
SERIALDEVICE.print(printBuffer);
}
Serial.println("");
SERIALDEVICE.println("");
}
#else
#define DEBUG_SIGNING_PRINTBUF(str, buf, sz)