diff --git a/examples/Embedis/Embedis.ino b/examples/Embedis/Embedis.ino index f91967c..6a5a89b 100644 --- a/examples/Embedis/Embedis.ino +++ b/examples/Embedis/Embedis.ino @@ -16,21 +16,38 @@ */ #include + +/* Test for platforms that have no native or emulated EEPROM - need special examples for those */ +#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) || defined(__ARDUINO_X86__) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARC32_TOOLS) +#error "Please use the specific example for your board type as it has no native EEPROM - this generic example won't work for it." +#else #include +#endif // Embedis will run on the Serial port. Use the Arduino // serial monitor and send "COMMANDS" to get started. // Make sure "No line ending" is -not- selected. All others work. Embedis embedis(Serial); -// If E2END isn't defined you can manually set this. +/* If E2END isn't defined you can manually set this. + * Set to 1024 bytes by default if undefined + */ +#ifndef E2END + #define E2END 1023 + #warning "EEPROM size set to 1024 by default!" +#endif const size_t EEPROM_SIZE = E2END + 1; void setup() { Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB (Leo, Teensy, etc) + } + Serial.println("Embedis: enter 'commands' to list the available commands"); + Serial.println("Embedis: select 'Both NL & CR' as your line ending"); - // Add a key-value store. + // Create a key-value Dictionary in EEPROM Embedis::dictionary( "EEPROM", EEPROM_SIZE, [](size_t pos) -> char { return EEPROM.read(pos); }, diff --git a/examples/Flip_n_Click/README.md b/examples/Flip_n_Click/README.md index 20f97cf..7b555e1 100644 --- a/examples/Flip_n_Click/README.md +++ b/examples/Flip_n_Click/README.md @@ -1,6 +1,6 @@ # Embedis - Embedded Dictionary Server -## Examples for MikroElectronica Flip-n-Click +## Examples for SAM3X - MikroElectronica Flip-n-Click The Arduino IDE now has he capability to support many different CPU architectures and boards. These examples are specifically for the MikroElectronica Flip-n-Click. diff --git a/examples/README.md b/examples/README.md index 0ca5fd2..896bd7c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,7 +5,7 @@ The Arduino IDE now has he capability to support many different CPU architectures and boards. The generic Embedis example uses the builtin EEPROM however many other add ons are possible.. -If you have a different board (and/or CPU architecture) you will need to use one of the examples specifically for that board. +If you have a different board (and/or CPU architecture) you will need to use one of the examples specifically for that architecture or board. ## Contributors diff --git a/examples/arduino101/Embedis/Embedis.ino b/examples/arduino101/Embedis/Embedis.ino new file mode 100644 index 0000000..759c84f --- /dev/null +++ b/examples/arduino101/Embedis/Embedis.ino @@ -0,0 +1,110 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +#include + +/* Test for Arduino101 platform - need special examples for those */ +#if defined(ARDUINO_ARC32_TOOLS) +#include "CurieEEPROM.h" +#else +#error "Please use the specific example for your board type as it has no native EEPROM - this generic example won't work for it." +#endif + +// Embedis will run on the Serial port. Use the Arduino +// serial monitor and send "COMMANDS" to get started. +// Make sure "No line ending" is -not- selected. All others work. +Embedis embedis(Serial); + +/* If E2END isn't defined you can manually set this. + * Set to 1024 bytes by default if undefined + */ +#ifndef E2END + #define E2END 1023 + #warning "EEPROM size set to 1024 by default!" +#endif +const size_t CUR_EEPROM_SIZE = E2END + 1; + +void setup() +{ + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB (Leo, Teensy, etc) + } + Serial.println("Embedis: enter 'commands' to list the available commands"); + Serial.println("Embedis: select 'Both NL & CR' as your line ending"); + + // Create a key-value Dictionary in EEPROM + Embedis::dictionary( + "EEPROM", + CUR_EEPROM_SIZE, + [](size_t pos) -> char { return EEPROM.read8(pos); }, + [](size_t pos, char value) { EEPROM.write8(pos, value); } + ); + + // Add pinMode command to mirror Arduino's + Embedis::command( F("pinMode"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv3(e->argv[2]); + argv3.toUpperCase(); + int mode; + if (argv3 == "INPUT") mode = INPUT; + else if (argv3 == "OUTPUT") mode = OUTPUT; + else if (argv3 == "INPUT_PULLUP") mode = INPUT_PULLUP; + else return e->response(Embedis::ARGS_ERROR); + pinMode(pin, mode); + e->response(Embedis::OK); + }); + + // Add digitalWrite command to mirror Arduino's + Embedis::command( F("digitalWrite"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv3(e->argv[2]); + argv3.toUpperCase(); + int mode; + if (argv3 == "HIGH") mode = HIGH; + else if (argv3 == "LOW") mode = LOW; + else mode = argv3.toInt(); + digitalWrite(pin, mode); + e->response(Embedis::OK); + }); + + // Add digitalRead command to mirror Arduino's + Embedis::command( F("digitalRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + if (digitalRead(pin)) { + e->response(F("HIGH")); + } else { + e->response(F("LOW")); + } + }); + + // Add analogRead command to mirror Arduino's + Embedis::command( F("analogRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + e->response(':', analogRead(pin)); + }); + +} + +void loop() +{ + embedis.process(); +} diff --git a/examples/arduino101/README.md b/examples/arduino101/README.md new file mode 100644 index 0000000..6442941 --- /dev/null +++ b/examples/arduino101/README.md @@ -0,0 +1,22 @@ +# Embedis - Embedded Dictionary Server + +## Examples for Arduino101 + +Just starting support for the Arduino101 platform. +It compiles and executes, however the CurrieEEPROM emulation in Flash, +doesn't appear to be "writing" data correctly yet - not sure where the problem lies... + +## Contributors + +The folks who make this project possible: + + * PatternAgents, LLC + * Tom Moxon + * David Turnbull + +## Community Supported + +[Embedis](https://github.com/thingSoC/embedis) and [thingSoC](http://www.thingsoc.com) are community supported, you can help by donating to support this work. + +PayPal donate button + diff --git a/examples/avr/Embedis/Embedis.ino b/examples/avr/Embedis/Embedis.ino new file mode 100644 index 0000000..6a5a89b --- /dev/null +++ b/examples/avr/Embedis/Embedis.ino @@ -0,0 +1,109 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +#include + +/* Test for platforms that have no native or emulated EEPROM - need special examples for those */ +#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) || defined(__ARDUINO_X86__) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARC32_TOOLS) +#error "Please use the specific example for your board type as it has no native EEPROM - this generic example won't work for it." +#else +#include +#endif + +// Embedis will run on the Serial port. Use the Arduino +// serial monitor and send "COMMANDS" to get started. +// Make sure "No line ending" is -not- selected. All others work. +Embedis embedis(Serial); + +/* If E2END isn't defined you can manually set this. + * Set to 1024 bytes by default if undefined + */ +#ifndef E2END + #define E2END 1023 + #warning "EEPROM size set to 1024 by default!" +#endif +const size_t EEPROM_SIZE = E2END + 1; + +void setup() +{ + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB (Leo, Teensy, etc) + } + Serial.println("Embedis: enter 'commands' to list the available commands"); + Serial.println("Embedis: select 'Both NL & CR' as your line ending"); + + // Create a key-value Dictionary in EEPROM + Embedis::dictionary( "EEPROM", + EEPROM_SIZE, + [](size_t pos) -> char { return EEPROM.read(pos); }, + [](size_t pos, char value) { EEPROM.write(pos, value); } + ); + + // Add pinMode command to mirror Arduino's + Embedis::command( F("pinMode"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv3(e->argv[2]); + argv3.toUpperCase(); + int mode; + if (argv3 == "INPUT") mode = INPUT; + else if (argv3 == "OUTPUT") mode = OUTPUT; + else if (argv3 == "INPUT_PULLUP") mode = INPUT_PULLUP; + else return e->response(Embedis::ARGS_ERROR); + pinMode(pin, mode); + e->response(Embedis::OK); + }); + + // Add digitalWrite command to mirror Arduino's + Embedis::command( F("digitalWrite"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv3(e->argv[2]); + argv3.toUpperCase(); + int mode; + if (argv3 == "HIGH") mode = HIGH; + else if (argv3 == "LOW") mode = LOW; + else mode = argv3.toInt(); + digitalWrite(pin, mode); + e->response(Embedis::OK); + }); + + // Add digitalRead command to mirror Arduino's + Embedis::command( F("digitalRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + if (digitalRead(pin)) { + e->response(F("HIGH")); + } else { + e->response(F("LOW")); + } + }); + + // Add analogRead command to mirror Arduino's + Embedis::command( F("analogRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + e->response(':', analogRead(pin)); + }); + +} + +void loop() +{ + embedis.process(); +} diff --git a/examples/avr/Embedis_I2C_EEPROM/EEPROM.ino b/examples/avr/Embedis_I2C_EEPROM/EEPROM.ino new file mode 100644 index 0000000..a7c4923 --- /dev/null +++ b/examples/avr/Embedis_I2C_EEPROM/EEPROM.ino @@ -0,0 +1,65 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015, 2016 PatternAgents, LLC + + 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 . +*/ + +// Add an "EEPROM" dictionary to Embedis, using the Ardunio EEPROM API +// +// Since the esp8266 platform does not have real EEPROM internal to the device, +// it is emulated using SPI Flash memory. +// Use "SET/Write" sparingly to avoid SPI Flash memory wear leveling issues. +// +// We show in this example how to use Embedis to hold configuration settings. +// Due to Wear leveling issues this is not recommended for real-time and changing data. +// Use NVSRAM, FRAM or other suitable storage technology for rapidly changing data sets! +// +// To configure an EEPROM dictionary, call setup_EEPROM from your +// main setup() function. Optionally, supply the database name you want to use. +// e.g. setup_EEPROM(); +// setup_EEPROM( F("MYEEPROM") ); +// +// Use the Embedis "select" command to enable your optional database name +// e.g. embedis-> select MYEEPROM +// The Embedis default database is "EEPROM", using the internal EEPROM memory. +// (or in the case of ESP8266 or Arduino Due, Emulated EEPROM...) +// +#include + +// Set your particular EEPROM size, which may want to be less than the physical device size. +// As an example, a 16K byte EEPROM might use only the first 4096 bytes to +// hold an IMPI, DeviceTree or other persistant data structure. +// Since Embedis writes from high memory to low memory, you could use 12K bytes +// of that memory for an Embedis Keystore, coexisting with the other persistant data structure. +// If E2END isn't defined you can uncoment the line below and manually set the size (in bytes). +// +#define E2END 1023 +const size_t EEPROM_SIZE = E2END + 1; + +void setup_EEPROM() +{ + setup_EEPROM( F("EEPROM") ); +} + +void setup_EEPROM(const String& dict) +{ + EEPROM.begin(); + Embedis::dictionary( dict, + EEPROM_SIZE, + [](size_t pos) -> char { return EEPROM.read(pos); }, + [](size_t pos, char value) { EEPROM.write(pos, value); }, + []() { delay(1); } + ); +} + diff --git a/examples/avr/Embedis_I2C_EEPROM/Embedis_I2C_EEPROM.ino b/examples/avr/Embedis_I2C_EEPROM/Embedis_I2C_EEPROM.ino new file mode 100644 index 0000000..7b40a56 --- /dev/null +++ b/examples/avr/Embedis_I2C_EEPROM/Embedis_I2C_EEPROM.ino @@ -0,0 +1,93 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ +/* + ====================================================================================== + + Embedis_I2C_EEPROM : Embedis example with Internal EEPROM and External I2C EEPROM Keystores + ------------------------------------------------------------------------------------------- + This example Arduino IDE sketch works on a number of platforms including AVR & ESP8266 + and provides an Embedis server that store permenant (persistant) data in + either the internal EEPROM of the processor or an external I2C EEPROM, + such as the 24AA256 or 24LC256 type parts. + + The Embedis server can be used to get/set keys in the EEPROM or I2C_EEPROM databases, + and can be used to store project and configuration settings. + You no longer need to embed that "data" into your "program"! + The EEPROM & I2C_EEPROM are persistant memory structures, and can be + used across multiple projects to configure your program setting for + the specific hardware and network configuration you are using. + + Now, you don't need to recompile your program and reflash your device + in order to change the device settings anymore. + + We think that this is a much better mechanism for storing settings between projects. + Once you start using Embedis for your projects, you'll see how quick and easy + it is to move and reconfigure your devices without needing to recompile + and reflash your device firmware just to change a configuration setting. + Now settings can be changed "on-the-fly" with just an Embedis Server. + (some settings changes however, will require a restart/reboot to take effect.) + + ====================================================================================== +*/ + +#include + +// Embedis will run on the Serial port. Use the Arduino +// serial monitor and send "COMMANDS" to get started. +// Make sure "No line ending" is -not- selected. All others work. +// +Embedis embedis(Serial); + +void setup() +{ + Serial.begin(115200); + delay(50); + + LOG( String() + F(" ") ); + LOG( String() + F("[ Embedis I2C_EEPROM Sketch ]") ); + + setup_EEPROM(); + setup_I2C_EEPROM(); + setup_commands(); + + LOG( String() + F("[ type 'commands' to get a list... ]") ); +} + +void loop() +{ + /* Always call the process method fro the main loop to run the Embedis system */ + embedis.process(); + + /* Give the internal RTOS time to task switch in ESP8266, Edison, Currie, etc. */ + /* not really necessary on AVR or Cortex platforms, but hey - it doesn't hurt... */ + delay(20); +} + +// This will log to an embedis channel called "log". +// Use SUBSCRIBE LOG to get these messages. +// Logs are also printed to Serial until an empty message is received. +void LOG(const String& message) { + static bool inSetup = true; + if (inSetup) { + if (!message.length()) { + inSetup = false; + return; + } + SERIAL_PORT_MONITOR.println(message); + } + Embedis::publish("log", message); +} diff --git a/examples/avr/Embedis_I2C_EEPROM/I2C_EEPROM.ino b/examples/avr/Embedis_I2C_EEPROM/I2C_EEPROM.ino new file mode 100644 index 0000000..1477691 --- /dev/null +++ b/examples/avr/Embedis_I2C_EEPROM/I2C_EEPROM.ino @@ -0,0 +1,47 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +/* extEEPROM Library from: https://github.com/PaoloP74/extEEPROM */ +#include + +/* define the device size, number of devices, page size */ +#define I2C_EEPROM_SIZE 8192 +extEEPROM ext_i2c_eeprom(kbits_64, 1, 32); + +void setup_I2C_EEPROM() +{ + setup_I2C_EEPROM( F("I2C_EEPROM") ); +} + +void setup_I2C_EEPROM(const String& dict) +{ + uint8_t ext_i2c_eepromStatus = ext_i2c_eeprom.begin(twiClock400kHz); + if (ext_i2c_eepromStatus) { + LOG( String() + F("[ No I2C_EEPROM found ... check your connections and address setting! ]") ); + } else { + LOG( String() + F("[ Found I2C_EEPROM ]") ); + } + + + Embedis::dictionary( dict, + (I2C_EEPROM_SIZE), + [](size_t pos) -> char { return ext_i2c_eeprom.read(pos); }, + [](size_t pos, char value) { ext_i2c_eeprom.write(pos, value); }, + []() { } + ); + +} diff --git a/examples/avr/Embedis_I2C_EEPROM/commands.ino b/examples/avr/Embedis_I2C_EEPROM/commands.ino new file mode 100644 index 0000000..c9ba682 --- /dev/null +++ b/examples/avr/Embedis_I2C_EEPROM/commands.ino @@ -0,0 +1,73 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015, 2016 PatternAgents, LLC + + 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 . +*/ + +// Adds some useful commands to Embedis. +// We'll add some Arduino I/O commands for making it interpretive... +// +// Call setup_commands from your main setup() function. +// e.g. setup_commands(); + +void setup_commands() +{ + /* create an interactive "pinMode" command */ + Embedis::command( F("pinMode"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv2(e->argv[2]); + argv2.toUpperCase(); + int mode; + if (argv2 == "INPUT") mode = INPUT; + else if (argv2 == "OUTPUT") mode = OUTPUT; + else if (argv2 == "INPUT_PULLUP") mode = INPUT_PULLUP; + else return e->response(Embedis::ARGS_ERROR); + pinMode(pin, mode); + e->response(Embedis::OK); + }); + + /* create an interactive "digitalWrite" command */ + Embedis::command( F("digitalWrite"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv2(e->argv[2]); + argv2.toUpperCase(); + int mode; + if (argv2 == "HIGH") mode = HIGH; + else if (argv2 == "LOW") mode = LOW; + else mode = argv2.toInt(); + digitalWrite(pin, mode); + e->response(Embedis::OK); + }); + + /* create an interactive "digitalRead" command */ + Embedis::command( F("digitalRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + if (digitalRead(pin)) { + e->response(F("HIGH")); + } else { + e->response(F("LOW")); + } + }); + + /* create an interactive "analogRead" command */ + Embedis::command( F("analogRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + e->response(':', analogRead(pin)); + }); + +} diff --git a/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_1.png b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_1.png new file mode 100644 index 0000000..59cd63a Binary files /dev/null and b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_1.png differ diff --git a/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_2.png b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_2.png new file mode 100644 index 0000000..aa6f241 Binary files /dev/null and b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_2.png differ diff --git a/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_3.png b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_3.png new file mode 100644 index 0000000..9a110e1 Binary files /dev/null and b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_3.png differ diff --git a/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_4.png b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_4.png new file mode 100644 index 0000000..de0b616 Binary files /dev/null and b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_4.png differ diff --git a/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_5.png b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_5.png new file mode 100644 index 0000000..0e371f7 Binary files /dev/null and b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_5.png differ diff --git a/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_aasemble.png b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_aasemble.png new file mode 100644 index 0000000..3b9389a Binary files /dev/null and b/examples/avr/Embedis_I2C_EEPROM/howto-images/embedis_uno_aasemble.png differ diff --git a/examples/avr/Embedis_I2C_FRAM/EEPROM.ino b/examples/avr/Embedis_I2C_FRAM/EEPROM.ino new file mode 100644 index 0000000..f30ec45 --- /dev/null +++ b/examples/avr/Embedis_I2C_FRAM/EEPROM.ino @@ -0,0 +1,69 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015, 2016 PatternAgents, LLC + + 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 . +*/ + +// Add an "EEPROM" dictionary to Embedis, using the Ardunio EEPROM API +// +// Since the esp8266 platform does not have real EEPROM internal to the device, +// it is emulated using SPI Flash memory. +// Use "SET/Write" sparingly to avoid SPI Flash memory wear leveling issues. +// +// We show in this example how to use Embedis to hold configuration settings. +// Due to Wear leveling issues this is not recommended for real-time and changing data. +// Use NVSRAM, FRAM or other suitable storage technology for rapidly changing data sets! +// +// To configure an EEPROM dictionary, call setup_EEPROM from your +// main setup() function. Optionally, supply the database name you want to use. +// e.g. setup_EEPROM(); +// setup_EEPROM( F("MYEEPROM") ); +// +// Use the Embedis "select" command to enable your optional database name +// e.g. embedis-> select MYEEPROM +// The Embedis default database is "EEPROM", using the internal EEPROM memory. +// (or in the case of ESP8266 or Arduino Due, Emulated EEPROM...) +// +#include + +// Set your particular EEPROM size, which may want to be less than the physical device size. +// As an example, a 16K byte EEPROM might use only the first 4096 bytes to +// hold an IMPI, DeviceTree or other persistant data structure. +// Since Embedis writes from high memory to low memory, you could use 12K bytes +// of that memory for an Embedis Keystore, coexisting with the other persistant data structure. +// If E2END isn't defined you can uncoment the line below and manually set the size (in bytes). +// +#define E2END 1023 +const size_t EEPROM_SIZE = E2END + 1; + +// We need this because the ESP8266 EEPROM is emulated in SPI Flash +// this is also the case in the Arduino Due platform +#include "spi_flash.h" + +void setup_EEPROM() +{ + setup_EEPROM( F("EEPROM") ); +} + +void setup_EEPROM(const String& dict) +{ + EEPROM.begin(SPI_FLASH_SEC_SIZE); + Embedis::dictionary( dict, + SPI_FLASH_SEC_SIZE, + [](size_t pos) -> char { return EEPROM.read(pos); }, + [](size_t pos, char value) { EEPROM.write(pos, value); }, + []() { EEPROM.commit(); } + ); +} + diff --git a/examples/avr/Embedis_I2C_FRAM/Embedis_I2C_FRAM.ino b/examples/avr/Embedis_I2C_FRAM/Embedis_I2C_FRAM.ino new file mode 100644 index 0000000..30cadf1 --- /dev/null +++ b/examples/avr/Embedis_I2C_FRAM/Embedis_I2C_FRAM.ino @@ -0,0 +1,94 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ +/* + ====================================================================================== + + Embedis_I2C_FRAM : Embedis example with EEPROM and I2C FRAM Keystores + --------------------------------------------------------------------- + This example Arduino IDE sketch works on a number of platforms including AVR & ESP8266 + and provides an Embedis server that store permenant (persistant) data in + either the internal EEPROM of the processor or an external I2C FRAM, + or Ferro-Electric Random Access Memory, such as the MB85RC256V or FM24V10 type parts. + + The Embedis server can be used to get/set keys in the EEPROM or FRAM databases, + and can be used to store project and configuration settings. + You no longer need to embed that "data" into your "program"! + The EEPROM & FRAM are persistant memory structures, and can be + used across multiple projects to configure your program setting for + the specific hardware and network configuration you are using. + + Now, you don't need to recompile your program and reflash your device + in order to change the device settings anymore. + + We think that this is a much better mechanism for storing settings between projects. + Once you start using Embedis for your projects, you'll see how quick and easy + it is to move and reconfigure your devices without needing to recompile + and reflash your device firmware just to change a configuration setting. + Now settings can be changed "on-the-fly" with just an Embedis Server. + (some settings changes however, will require a restart/reboot to take effect.) + + ====================================================================================== +*/ + +#include +#include + +// Embedis will run on the Serial port. Use the Arduino +// serial monitor and send "COMMANDS" to get started. +// Make sure "No line ending" is -not- selected. All others work. +// +Embedis embedis(Serial); + +void setup() +{ + Serial.begin(115200); + delay(50); + + LOG( String() + F(" ") ); + LOG( String() + F("[ Embedis I2C_FRAM Sketch ]") ); + + setup_EEPROM(); + setup_I2C_FRAM(); + setup_commands(); + + LOG( String() + F("[ type 'commands' to get a list... ]") ); +} + +void loop() +{ + /* Always call the process method fro the main loop to run the Embedis system */ + embedis.process(); + + /* Give the internal RTOS time to task switch in ESP8266, Edison, Currie, etc. */ + /* not really necessary on AVR or Cortex platforms, but hey - it doesn't hurt... */ + delay(20); +} + +// This will log to an embedis channel called "log". +// Use SUBSCRIBE LOG to get these messages. +// Logs are also printed to Serial until an empty message is received. +void LOG(const String& message) { + static bool inSetup = true; + if (inSetup) { + if (!message.length()) { + inSetup = false; + return; + } + SERIAL_PORT_MONITOR.println(message); + } + Embedis::publish("log", message); +} diff --git a/examples/avr/Embedis_I2C_FRAM/I2C_FRAM.ino b/examples/avr/Embedis_I2C_FRAM/I2C_FRAM.ino new file mode 100644 index 0000000..dc15c09 --- /dev/null +++ b/examples/avr/Embedis_I2C_FRAM/I2C_FRAM.ino @@ -0,0 +1,58 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +/* Using I2C based memories, so include "wire" */ +#include + +/* I2C_FRAM (MB85RC256, FM24V10, etc.) */ +/* e.g. https://www.adafruit.com/products/1895 */ +#include "Adafruit_FRAM_I2C.h" + +/* Example wiring for the Adafruit I2C FRAM breakout */ +/* Connect SCL to analog 5 + Connect SDA to analog 4 + Connect VDD to 5.0V DC + Connect GROUND to common ground */ + +Adafruit_FRAM_I2C fram = Adafruit_FRAM_I2C(); + +/* the settings for your particlar I2C_FRAM type... */ +#define I2C_FRAM_MODEL FM24V10-G /* Cypress/Ramtron/etc. */ +#define I2C_FRAM_SIZE 32768 /* FM24V10 = 128K x 8 */ +uint8_t I2C_FRAM_Addr = 0x57; /* A2 = A1 = A0 = "1" */ + +void setup_I2C_FRAM() +{ + setup_I2C_FRAM( F("I2C_FRAM") ); +} + +void setup_I2C_FRAM(const String& dict) +{ + if (fram.begin(I2C_FRAM_Addr)) { + LOG( String() + F("[ Found I2C_FRAM ]") ); + } else { + LOG( String() + F("[ No I2C_FRAM found ... check your connections and address setting! ]") ); + while (1); + } + + Embedis::dictionary( dict, + (I2C_FRAM_SIZE), + [](size_t pos) -> char { return fram.read8(pos); }, + [](size_t pos, char value) { fram.write8(pos, value); }, + []() { } + ); +} diff --git a/examples/avr/Embedis_I2C_FRAM/commands.ino b/examples/avr/Embedis_I2C_FRAM/commands.ino new file mode 100644 index 0000000..bd0b5f2 --- /dev/null +++ b/examples/avr/Embedis_I2C_FRAM/commands.ino @@ -0,0 +1,76 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015, 2016 PatternAgents, LLC + + 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 . +*/ + +// Adds some useful commands to Embedis. +// We'll add some Arduino I/O commands for making it interpretive... +// +// Call setup_commands from your main setup() function. +// e.g. setup_commands(); + +//#include +//#include + +void setup_commands() +{ + /* create an interactive "pinMode" command */ + Embedis::command( F("pinMode"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv2(e->argv[2]); + argv2.toUpperCase(); + int mode; + if (argv2 == "INPUT") mode = INPUT; + else if (argv2 == "OUTPUT") mode = OUTPUT; + else if (argv2 == "INPUT_PULLUP") mode = INPUT_PULLUP; + else return e->response(Embedis::ARGS_ERROR); + pinMode(pin, mode); + e->response(Embedis::OK); + }); + + /* create an interactive "digitalWrite" command */ + Embedis::command( F("digitalWrite"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv2(e->argv[2]); + argv2.toUpperCase(); + int mode; + if (argv2 == "HIGH") mode = HIGH; + else if (argv2 == "LOW") mode = LOW; + else mode = argv2.toInt(); + digitalWrite(pin, mode); + e->response(Embedis::OK); + }); + + /* create an interactive "digitalRead" command */ + Embedis::command( F("digitalRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + if (digitalRead(pin)) { + e->response(F("HIGH")); + } else { + e->response(F("LOW")); + } + }); + + /* create an interactive "analogRead" command */ + Embedis::command( F("analogRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + e->response(':', analogRead(pin)); + }); + +} diff --git a/examples/esp8266/Embedis/Embedis.ino b/examples/esp8266/Embedis/Embedis.ino new file mode 100644 index 0000000..a1e2c35 --- /dev/null +++ b/examples/esp8266/Embedis/Embedis.ino @@ -0,0 +1,104 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +#include + +/* Test for ESP platform */ +#if defined(ARDUINO_ARCH_ESP8266) +#include +#include "spi_flash.h" +#else +#error "Please use the specific example for your board type - this example is for ESP8266 only..." +#endif + +// Embedis will run on the Serial port. Use the Arduino +// serial monitor and send "COMMANDS" to get started. +// Make sure "No line ending" is -not- selected. All others work. +Embedis embedis(Serial); + +void setup() +{ + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB (Leo, Teensy, etc) + } + Serial.println("Embedis: enter 'commands' to list the available commands"); + Serial.println("Embedis: select 'Both NL & CR' as your line ending"); + + // Create a key-value Dictionary in emulated EEPROM (FLASH actually...) + EEPROM.begin(SPI_FLASH_SEC_SIZE); + Embedis::dictionary( + "EEPROM", + SPI_FLASH_SEC_SIZE, + [](size_t pos) -> char { return EEPROM.read(pos); }, + [](size_t pos, char value) { EEPROM.write(pos, value); }, + []() { EEPROM.commit(); } + ); + + // Add pinMode command to mirror Arduino's + Embedis::command( F("pinMode"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv3(e->argv[2]); + argv3.toUpperCase(); + int mode; + if (argv3 == "INPUT") mode = INPUT; + else if (argv3 == "OUTPUT") mode = OUTPUT; + else if (argv3 == "INPUT_PULLUP") mode = INPUT_PULLUP; + else return e->response(Embedis::ARGS_ERROR); + pinMode(pin, mode); + e->response(Embedis::OK); + }); + + // Add digitalWrite command to mirror Arduino's + Embedis::command( F("digitalWrite"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv3(e->argv[2]); + argv3.toUpperCase(); + int mode; + if (argv3 == "HIGH") mode = HIGH; + else if (argv3 == "LOW") mode = LOW; + else mode = argv3.toInt(); + digitalWrite(pin, mode); + e->response(Embedis::OK); + }); + + // Add digitalRead command to mirror Arduino's + Embedis::command( F("digitalRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + if (digitalRead(pin)) { + e->response(F("HIGH")); + } else { + e->response(F("LOW")); + } + }); + + // Add analogRead command to mirror Arduino's + Embedis::command( F("analogRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + e->response(':', analogRead(pin)); + }); + +} + +void loop() +{ + embedis.process(); +} diff --git a/examples/sam3x/Embedis_Due/Embedis_Due.ino b/examples/sam3x/Embedis_Due/Embedis_Due.ino new file mode 100644 index 0000000..d7c3c8d --- /dev/null +++ b/examples/sam3x/Embedis_Due/Embedis_Due.ino @@ -0,0 +1,65 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +#include + +// Embedis will run on the Serial port. Use the Arduino +// serial monitor and send "COMMANDS" to get started. +// Make sure "No line ending" is -not- selected. All others work. +Embedis embedis(Serial); + +void setup() +{ + Serial.begin(115200); + delay(50); + LOG( String() + F(" ") ); + LOG( String() + F("[ Embedis Flip-n-Click (Arduino Due) Sketch ]") ); + + // "FLASH" is the internal Flash memory of the Arduino Due Processor + setup_FLASH(); + + // Add the SPI FRAM Click Board in Socket C + setup_SPI_FRAM(); + + // Add the I2C EEPROM Click Board in Socket D + setup_I2C_EEPROM(); + + // Add some useful commands + setup_commands(); + LOG( String() + F("[ type 'commands' to get a list... ]") ); +} + +void loop() +{ + embedis.process(); + delay(20); +} + +// This will log to an embedis channel called "log". +// Use SUBSCRIBE LOG to get these messages. +// Logs are also printed to Serial until an empty message is received. +void LOG(const String& message) { + static bool inSetup = true; + if (inSetup) { + if (!message.length()) { + inSetup = false; + return; + } + SERIAL_PORT_MONITOR.println(message); + } + Embedis::publish("log", message); +} diff --git a/examples/sam3x/Embedis_Due/FLASH.ino b/examples/sam3x/Embedis_Due/FLASH.ino new file mode 100644 index 0000000..435d9a4 --- /dev/null +++ b/examples/sam3x/Embedis_Due/FLASH.ino @@ -0,0 +1,35 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +/* FLASH for Arduino Due */ +#include +DueFlashStorage FlashDue; + +void setup_FLASH() +{ + setup_FLASH( F("FLASH") ); +} + +void setup_FLASH(const String& dict) +{ + Embedis::dictionary( dict, + 1024, + [](size_t pos) -> char { return FlashDue.read(pos); }, + [](size_t pos, char value) { FlashDue.write(pos, value); }, + []() { } + ); +} diff --git a/examples/sam3x/Embedis_Due/I2C_EEPROM.ino b/examples/sam3x/Embedis_Due/I2C_EEPROM.ino new file mode 100644 index 0000000..5aa5dd1 --- /dev/null +++ b/examples/sam3x/Embedis_Due/I2C_EEPROM.ino @@ -0,0 +1,46 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +/* extEEPROM Library from: https://github.com/PaoloP74/extEEPROM */ +#include + +/* define the device size, number of devices, page size */ +#define I2C_EEPROM_SIZE 8192 +extEEPROM ext_i2c_eeprom(kbits_64, 1, 32); + +void setup_I2C_EEPROM() +{ + setup_I2C_EEPROM( F("I2C_EEPROM") ); +} + +void setup_I2C_EEPROM(const String& dict) +{ + uint8_t ext_i2c_eepromStatus = ext_i2c_eeprom.begin(twiClock400kHz); + if (ext_i2c_eepromStatus) { + LOG( String() + F("[ No I2C_EEPROM found ... check your connections and address setting! ]") ); + } else { + LOG( String() + F("[ Found I2C_EEPROM ]") ); + } + + Embedis::dictionary( dict, + (I2C_EEPROM_SIZE), + [](size_t pos) -> char { return ext_i2c_eeprom.read(pos); }, + [](size_t pos, char value) { ext_i2c_eeprom.write(pos, value); }, + []() { } + ); +} + diff --git a/examples/sam3x/Embedis_Due/SPI_FRAM.ino b/examples/sam3x/Embedis_Due/SPI_FRAM.ino new file mode 100644 index 0000000..0b915d8 --- /dev/null +++ b/examples/sam3x/Embedis_Due/SPI_FRAM.ino @@ -0,0 +1,72 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015 PatternAgents, LLC + + 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 . +*/ + +/* FRAM_Click */ + +#include "flip_n_click_pins.h" + +/* FRAM CLICK Pin Assignment + * FRAM installed in Socket "C" on the Flip-n-Click Board + * + * To install in Socket "A", just change the "C" suffix to "A" + * i.e. FRAM_CS = CSNA; + * FRAM_SCK = SCKA; + * FRAM_MISO = MISOA; + * FRAM_MOSI = MOSIA; + */ +uint8_t FRAM_CS = CSNC; /* FRAM Chip Select */ +uint8_t FRAM_SCK = SCKC; /* FRAM Clock */ +uint8_t FRAM_MISO = MISOC; /* FRAM Master Out */ +uint8_t FRAM_MOSI = MOSIC; /* FRAM Mater In */ +uint8_t FRAM_HOLD = RSTSC; /* FRAM HOLD */ +uint8_t FRAM_WRTP = PWMC; /* FRAM Write Protect */ +uint32_t FRAM_SIZE = 32768; /* MB85RS256 is 256K bits or 32768 x 8 bits*/ + +#include +#include "Adafruit_FRAM_SPI.h" + +/* Create the Adafruit_FRAM_SPI instance */ +//Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS); /* use hardware SPI */ +Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_SCK, FRAM_MISO, FRAM_MOSI, FRAM_CS); /* use software SPI */ + +void setup_SPI_FRAM() +{ + setup_SPI_FRAM( F("SPI_FRAM") ); +} + +void setup_SPI_FRAM(const String& dict) +{ + /* Configure the FRAM control pins correctly */ + pinMode(FRAM_HOLD, OUTPUT); + digitalWrite(FRAM_HOLD, HIGH); + pinMode(FRAM_WRTP, OUTPUT); + digitalWrite(FRAM_WRTP, HIGH); + if (fram.begin()) { + LOG( String() + F("[ Found SPI_FRAM ]") ); + fram.writeEnable(false); + } else { + LOG( String() + F("[ No SPI_FRAM found ... check your connections and address setting! ]") ); + while (1); + } + + Embedis::dictionary( dict, + (FRAM_SIZE), + [](size_t pos) -> char { return fram.read8(pos); }, + [](size_t pos, char value) { fram.writeEnable(true); fram.write8(pos, value); fram.writeEnable(false); }, + []() { } + ); +} diff --git a/examples/sam3x/Embedis_Due/commands.ino b/examples/sam3x/Embedis_Due/commands.ino new file mode 100644 index 0000000..566fc81 --- /dev/null +++ b/examples/sam3x/Embedis_Due/commands.ino @@ -0,0 +1,75 @@ +/* Embedis - Embedded Dictionary Server + Copyright (C) 2015, 2016 PatternAgents, LLC + + 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 . +*/ + +// Adds some useful commands to Embedis. +// We'll add some Arduino I/O commands for making it interpretive... +// +// Call setup_commands from your main setup() function. +// e.g. setup_commands(); + +//#include + +void setup_commands() +{ + /* create an interactive "pinMode" command */ + Embedis::command( F("pinMode"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv2(e->argv[2]); + argv2.toUpperCase(); + int mode; + if (argv2 == "INPUT") mode = INPUT; + else if (argv2 == "OUTPUT") mode = OUTPUT; + else if (argv2 == "INPUT_PULLUP") mode = INPUT_PULLUP; + else return e->response(Embedis::ARGS_ERROR); + pinMode(pin, mode); + e->response(Embedis::OK); + }); + + /* create an interactive "digitalWrite" command */ + Embedis::command( F("digitalWrite"), [](Embedis* e) { + if (e->argc != 3) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + String argv2(e->argv[2]); + argv2.toUpperCase(); + int mode; + if (argv2 == "HIGH") mode = HIGH; + else if (argv2 == "LOW") mode = LOW; + else mode = argv2.toInt(); + digitalWrite(pin, mode); + e->response(Embedis::OK); + }); + + /* create an interactive "digitalRead" command */ + Embedis::command( F("digitalRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + if (digitalRead(pin)) { + e->response(F("HIGH")); + } else { + e->response(F("LOW")); + } + }); + + /* create an interactive "analogRead" command */ + Embedis::command( F("analogRead"), [](Embedis* e) { + if (e->argc != 2) return e->response(Embedis::ARGS_ERROR); + int pin = String(e->argv[1]).toInt(); + e->response(':', analogRead(pin)); + }); + +} diff --git a/examples/sam3x/Embedis_Due/flip_n_click_pins.h b/examples/sam3x/Embedis_Due/flip_n_click_pins.h new file mode 100644 index 0000000..d36b130 --- /dev/null +++ b/examples/sam3x/Embedis_Due/flip_n_click_pins.h @@ -0,0 +1,98 @@ +/* + * Pin Out Definition for Mikroe Flip-n-Click + * ========================================== + * + * Pin Assignment for Mikroe Flip-n-Click Board Revision 1.0 + * + * We'll use the schematic node names as our pin names where it makes sense. + * (this should really be put into a varient of arduino_pins.h after testing) + * + * http://www.mikroe.com/download/eng/documents/development-tools/accessory-boards/click/flip-n-click/flip-n-click-v100.manual.web.pdf + * + */ + +/* Pin Out for Bottom Arduino Shield Connector + */ +#define RX_USB 0 /* PA8 : RX : Arduino Due D0 : FTDI USB Serial (Don't use for Input/Output) */ +#define TX_USB 1 /* PA9 : TX: : Arduino Due D1 : FTDI USB Serial (Don't use for Input/Output) */ +#define PWM2 2 /* PB25 : PWM2 : Arduino Due D2 : */ +#define PWM3 3 /* PC28 : PWM3 : Arduino Due D3 : */ +#define PWM4 4 /* PA29 : PWM4 : Arduino Due D4 : Due also connects PC26? test which one */ +#define PWM5 5 /* PC25 : PWM5 : Arduino Due D5 : */ +#define PWM6 6 /* PC24 : PWM6 : Arduino Due D6 : */ +#define PWM7 7 /* PC23 : PWM7 : Arduino Due D7 : */ +#define PWM8 8 /* PC22 : PWM8 : Arduino Due D8 : */ +#define PWM9 9 /* PC21 : PWM9 : Arduino Due D9 : */ +#define PWM10 10 /* PC29 : PWM10 : Arduino Due D10 : Due also connects PA28? */ +#define PWM11 11 /* PD7 : PWM11 : Arduino Due D11 : */ +#define PWM12 12 /* PD8 : PWM12 : Arduino Due D12 : */ +#define PWM13 13 /* PB27 : PWM13 : Arduino Due D13 : LED_BULITIN */ +#define SDA0 70 /* PA17 : I2C0_SDA : Arduino Due SDA : */ +#define SCL0 71 /* PA18 : I2C0_SCL : Arduino Due SCL : */ +#define AREF -1 /* NC : NC : Arduino Due AREF : AREF is floating? */ +#define AD0 54 /* PA16 : AD0 : Arduino Due A0 : */ +#define AD1 55 /* PA24 : AD1 : Arduino Due A1 : */ +#define AD2 56 /* PA23 : AD2 : Arduino Due A2 : */ +#define AD3 57 /* PA22 : AD3 : Arduino Due A3 : */ +#define AD4 58 /* PA6 : AD4 : Arduino Due A4 : */ +#define AD5 59 /* PA4 : AD5 : Arduino Due A5 : */ + +/* Pinout for Click Socket A + */ +#define LEDA 38 /* PC6 : LEDA : Arduino Due D38 : */ +#define SDAA 70 /* PA17 : I2C0_SDA : Arduino Due SDA : */ +#define SCLA 71 /* PA18 : I2C0_SCL : Arduino Due SCL : */ +#define TXDA 18 /* PA11 : TXD0 : Arduino Due TX1 : Serial1 */ +#define RXDA 19 /* PA10 : RXD0 : Arduino Due RX1 : Serial1 */ +#define PWMA 6 /* PC24 : PWM6 : Arduino Due D6 : */ +#define ANAA 54 /* PA16 : AD0 : Arduino Due A0 : */ +#define RSTA 33 /* PC1 : RSTA : Arduino Due D33 : */ +#define CSNA 77 /* PA28 : SPI0_CS0 : Arduino Due CS0 : */ +#define SCKA 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */ +#define MISOA 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */ +#define MOSIA 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */ + +/* Pinout for Click Socket B + */ +#define LEDB 37 /* PC5 : LEDB : Arduino Due D37 : */ +#define SDAB 70 /* PA17 : I2C0_SDA : Arduino Due SDA : */ +#define SCLB 71 /* PA18 : I2C0_SCL : Arduino Due SCL : */ +#define TXDB 16 /* PA13 : TXD2 : Arduino Due TX2 : Serial2 */ +#define RXDB 17 /* PA12 : RXD2 : Arduino Due RX2 : Serial2 */ +#define PWMB 7 /* PC23 : PWM7 : Arduino Due D7 : */ +#define ANAB 55 /* PA24 : AD1 : Arduino Due A1 : */ +#define RSTB 34 /* PC2 : RSTB : Arduino Due D34 : */ +#define CSNB 79 /* PA29 : SPI0_CS1 : Arduino Due ??? : N.B. this is not mapped for Due? */ +#define SCKB 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */ +#define MISOB 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */ +#define MOSIB 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */ + +/* Pinout for Click Socket C + */ +#define LEDC 39 /* PC7 : LEDC : Arduino Due D39 : */ +#define SDAC 20 /* PB12 : I2C1_SDA : Arduino Due SDA1 : */ +#define SCLC 21 /* PB13 : I2C1_SCL : Arduino Due SCL1 : */ +#define TXDC 14 /* PD4 : TXD3 : Arduino Due TX3 : Serial3 */ +#define RXDC 15 /* PD5 : RXD3 : Arduino Due RX3 : Serial3 */ +#define PWMC 8 /* PC22 : PWM8 : Arduino Due D8 : */ +#define ANA 56 /* PA23 : AD2 : Arduino Due A2 : */ +#define RSTSC 35 /* PC3 : RSTC : Arduino Due D35 : */ +#define CSNC 52 /* PB21 : SPI0_CS2 : Arduino Due D52 : */ +#define SCKC 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */ +#define MISOC 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */ +#define MOSIC 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */ + +/* Pinout for Click Socket D + */ +#define LEDD 40 /* PC8 : LEDD : Arduino Due D40 : */ +#define SDAD 20 /* PB12 : I2C1_SDA : Arduino Due SDA1 : */ +#define SCLD 21 /* PB13 : I2C1_SCL : Arduino Due SDA1 : */ +#define TXDD 14 /* PD4 : TXD3 : Arduino Due TX3 : */ +#define RXDD 15 /* PD5 : RXD3 : Arduino Due RX3 : */ +#define PWMD 9 /* PC21 : PWM9 : Arduino Due D9 : */ +#define ANAD 57 /* PA22 : AD3 : Arduino Due A3 : */ +#define RSTD 36 /* PC4 : RSTD : Arduino Due D36 : */ +#define CSND 78 /* PB23 : SPI0_CS3 : Arduino Due D78 : */ +#define SCKD 76 /* PA27 : SPI0_SCK : Arduino Due SCK : */ +#define MISOD 74 /* PA25 : SPI0_MISO : Arduino Due MISO : */ +#define MOSID 75 /* PA26 : SPI0_MOSI : Arduino Due MOSI : */ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due.png new file mode 100644 index 0000000..2cca1c6 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_1.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_1.png new file mode 100644 index 0000000..b2bb216 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_1.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_10.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_10.png new file mode 100644 index 0000000..4f60b79 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_10.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_11.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_11.png new file mode 100644 index 0000000..3c793f9 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_11.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_2.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_2.png new file mode 100644 index 0000000..b538b96 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_2.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_3.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_3.png new file mode 100644 index 0000000..7cee74f Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_3.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_4.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_4.png new file mode 100644 index 0000000..943d8ac Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_4.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_5.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_5.png new file mode 100644 index 0000000..e4d7699 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_5.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_6.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_6.png new file mode 100644 index 0000000..478dd82 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_6.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_7.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_7.png new file mode 100644 index 0000000..31f9410 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_7.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_8.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_8.png new file mode 100644 index 0000000..107aa05 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_8.png differ diff --git a/examples/sam3x/Embedis_Due/howto-images/embedis_due_9.png b/examples/sam3x/Embedis_Due/howto-images/embedis_due_9.png new file mode 100644 index 0000000..3b1fed5 Binary files /dev/null and b/examples/sam3x/Embedis_Due/howto-images/embedis_due_9.png differ diff --git a/examples/Due/README.md b/examples/sam3x/README.md similarity index 88% rename from examples/Due/README.md rename to examples/sam3x/README.md index 4d8457e..9b75950 100644 --- a/examples/Due/README.md +++ b/examples/sam3x/README.md @@ -1,9 +1,9 @@ # Embedis - Embedded Dictionary Server -## Examples for Arduino Due +## Examples for SAM3x (Arduino Due) The Arduino IDE now has he capability to support many different CPU architectures and boards. -These examples are specifically for the Arduino Due. +These examples are specifically for the Arduino Due ## Contributors diff --git a/library.properties b/library.properties index 9d977d1..e575834 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedis -version=1.1.4 +version=1.1.5 author=David Turnbull, Tom Moxon maintainer=The PatternAgents, LLC sentence=An Embedded Dictionary Server. diff --git a/src/Embedis.h b/src/Embedis.h old mode 100755 new mode 100644 index 6b5e818..183fa2a --- a/src/Embedis.h +++ b/src/Embedis.h @@ -20,25 +20,91 @@ #ifdef __cplusplus -// Arduino is like a box of chocolates. -// You never know what you're going to get. -#if __cplusplus < 201103L -#include -#include -inline void * operator new (size_t size, void * ptr) { - (void)size; - return ptr; -} +/* Arduino is like a box of chocolates, + You never know what you're going to get... + + could be any compiler, version, or c/c++ libraries, + could be any processor architecture, board, configuration, ... + I have looked at many examples, but if anyone has a better, + more canonical way to do this, please, please show me... +*/ +/* Arduino Version Specific */ +#if (ARDUINO >= 100) + #include "Arduino.h" +#else + #include "WProgram.h" +#endif + +/* Architecture Specific */ +#if defined(ARDUINO_ARCH_AVR) + // AVR specific code + // break down further by cpu model if necessary + #include "avr/pgmspace.h" +#elif defined(ARDUINO_ARCH_SAM) + // SAM-specific code + // break down further by cpu model if necessary +#elif defined(ARDUINO_ARCH_SAMD) + // SAMD-specific code + // break down further by cpu model if necessary +#elif defined(ARDUINO_ARCH_ARC32) + // Arduino101 Arc Core Specific +#elif defined(CORE_TEENSY) + // Teensy specific + // this is not ideal, maybe use "_ARCH_" when available + // break down further by cpu model if necessary + #include "avr/pgmspace.h" +#elif defined(ESP_H) + // ESP8266 specific + // this is not ideal, maybe use "_ARCH_" when available +#elif defined(__X86__) + // Edison, Galileo, x86 specific #else -#include -#include -#include + // untested architecture, it might work... + #pragma message ( "Core Architecture not Recognized - untested... " ) #endif +/* C/C++ Compiler Specific */ +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline +#elif defined ( __TMS470__ ) + #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ + #define __STATIC_INLINE static inline +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline + /* Obsolete versions for now... + #include + #include + #include + */ +#elif defined ( __TASKING__ ) + #define __ASM __asm /*!< asm keyword for TASKING Compiler */ + #define __INLINE inline /*!< inline keyword for TASKING Compiler */ + #define __STATIC_INLINE static inline + +#endif + +/* Non-Specific (i.e.generic) Includes */ +/* stuff below should generally work everywhere... */ +#include +#include #include "WString.h" #include "Stream.h" +/* it's NEW! */ +inline void * operator new (size_t size, void * ptr) { + (void)size; + return ptr; +} +/* embedis class */ class Embedis { protected: