Skip to content

Commit

Permalink
add teensy support, add arduino101
Browse files Browse the repository at this point in the history
  • Loading branch information
moxondesign committed Sep 17, 2016
1 parent abf5464 commit 9715c88
Show file tree
Hide file tree
Showing 42 changed files with 1,413 additions and 19 deletions.
21 changes: 19 additions & 2 deletions examples/Embedis/Embedis.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,38 @@
*/

#include <Embedis.h>

/* 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 <EEPROM.h>
#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); },
Expand Down
2 changes: 1 addition & 1 deletion examples/Flip_n_Click/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
110 changes: 110 additions & 0 deletions examples/arduino101/Embedis/Embedis.ino
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#include <Embedis.h>

/* 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();
}
22 changes: 22 additions & 0 deletions examples/arduino101/README.md
Original file line number Diff line number Diff line change
@@ -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.

<span class="badge-paypal"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=5NPC24C7VQ89L" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a></span>

109 changes: 109 additions & 0 deletions examples/avr/Embedis/Embedis.ino
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#include <Embedis.h>

/* 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 <EEPROM.h>
#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();
}
65 changes: 65 additions & 0 deletions examples/avr/Embedis_I2C_EEPROM/EEPROM.ino
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

// 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 <EEPROM.h>

// 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); }
);
}

Loading

0 comments on commit 9715c88

Please sign in to comment.