Compare commits

..

36 Commits

Author SHA1 Message Date
Erik Tylek Kettenburg
111396ffe5 Merge pull request #51 from per1234/output-recipes
Add output recipes
2017-08-29 16:49:34 -07:00
per1234
d208cb7669 Add output recipes
These recipes are required to support **Sketch > Export compiled
Binary**. See:

https://github.com/arduino/Arduino/blob/1.8.1/hardware/arduino/avr/platform.txt#L74-L76

https://github.com/arduino/Arduino/blob/1.8.1/hardware/arduino/sam/platform.txt#L86-L88
2017-01-19 14:21:39 -08:00
Erik Tylek Kettenburg
684c36af77 Merge pull request #36 from SukkoPera/master
Switch to Arduino-compliant EEPROM library
2016-06-13 21:12:32 -07:00
SukkoPera
d457051fd4 Switch to Arduino-compliant EEPROM library 2016-06-04 15:21:46 +02:00
Erik Kettenburg
b9a79d8b2e add eeprom library explicitly 2016-05-16 17:19:02 -07:00
Erik Tylek Kettenburg
7841eb24ff Merge pull request #31 from nfriedly/patch-1
formatting improvements to RGB example
2016-03-29 10:09:55 -07:00
Nathan Friedly
f402493d27 formatting improvements to RGB example
White space-only changes to fix indentation and general consistency withing example
2016-03-29 10:59:10 -04:00
Erik Tylek Kettenburg
41c25785db Merge pull request #30 from vlee489/master
Updates DigiKeyboard.h to add arrows keys.
2016-03-07 17:25:05 -08:00
Vincent Lee
2b684b9034 Updates DigiKeyboard.h to add arrows keys.
Signed-off-by: Vincent Lee <vlee489@users.noreply.github.com>
2016-03-07 18:59:06 +00:00
Erik Kettenburg
280b22b652 fix executables, add proper 64 bit version of launcher 2016-02-13 11:11:30 -08:00
Erik Kettenburg
822a2e4f55 update spi, fix lcd error 2016-02-12 19:09:37 -08:00
Erik Tylek Kettenburg
2c40bcdd6f Merge pull request #18 from eelmasllari/master
added functionality to send keypresses, i.e. a press without release
2016-02-12 18:31:49 -08:00
Erik Tylek Kettenburg
af7c58d1e5 Update pins_arduino.h 2016-02-12 11:12:01 -08:00
Erik Tylek Kettenburg
ab01715320 Update pins_arduino.h 2016-02-12 11:11:35 -08:00
Erik Tylek Kettenburg
c16eb3cf70 Update pins_arduino.h 2016-02-12 11:11:03 -08:00
Erik Tylek Kettenburg
40be695f81 Add __AVR_ATtiny85__ to satisfy some libraries 2016-02-12 11:09:12 -08:00
Erik Tylek Kettenburg
fbd4d79324 Merge pull request #24 from e-moe/feature/platform.txt-update
{build.path}/{archive_file} is now {archive_file_path}
2016-02-12 11:03:44 -08:00
Erik Tylek Kettenburg
92260e2acd Merge pull request #25 from e-moe/fix/LiquidCrystal_I2C
fix #if defined checks - Thanks @e-moe - merging for todays release
2016-02-12 11:03:13 -08:00
Erik Tylek Kettenburg
badec8f822 Merge pull request #28 from per1234/dummy-example-headers
Add dummy .h files to Digispark_Examples and DigiXBetaBonus folders
2016-02-12 11:01:48 -08:00
per1234
0d4830288d Add dummy .h files to Digispark_Examples and DigiXBetaBonus folders
In Arduino IDE 1.6.6 and 1.6.7 these are considered invalid libraries
without a header file and this causes a warning whenever a Digispark
board is selected from the Tools > Board menu or Boards Manager or
Library Manager is opened with a Digispark board selected and the
sketches don't appear in the File > Example menu.
2016-02-04 02:35:46 -08:00
Nikolay Labinskiy
3577e4a637 fix #if defined checks 2016-01-31 21:54:05 +02:00
Nikolay Labinskiy
eed2ff45ba {build.path}/{archive_file} is now {archive_file_path} 2016-01-31 18:42:00 +02:00
Factor Sixty
6844d32b06 added functionality to send keypresses, i.e. just a press-and-hold, without release.
sendKeyStroke sends the release automatically, which creates a problem when you want to use the repeating key functionality of your OS.
2016-01-16 14:12:45 +01:00
Erik Tylek Kettenburg
bd916e2eea Merge pull request #11 from mpflaga/master
TCCR0B not initialized in DigisparkRGB example
2015-10-10 02:14:52 -07:00
Erik Tylek Kettenburg
4a1f9c7ac5 Merge pull request #8 from awenisko/patch-1
Update wiring.h
2015-10-10 02:14:31 -07:00
Erik Tylek Kettenburg
836e363726 Merge pull request #9 from awenisko/patch-2
Update wiring_digital.c
2015-10-10 02:13:12 -07:00
Michael P. Flaga
2de159b44d TCCR0B not initialized in DigisparkRGB example 2015-10-05 13:20:42 -04:00
awenisko
7533853c57 Update wiring_digital.c
Implemented INPUT_PULLUP digital pin mode.
2015-09-03 18:32:28 +02:00
awenisko
7d52a0cfb9 Update wiring.h
Defined INPUT_PULLUP mode.
2015-09-03 18:30:06 +02:00
Erik Tylek Kettenburg
60edebc52b Merge pull request #7 from SoundGuy/patch-1
fixed bug that prevented this from compiling
2015-08-13 22:20:08 -07:00
Oded Sharon
008b95382b fixed bug that prevented this from compiling
added const to line 273 to prescalers
2015-08-11 11:41:40 +03:00
Erik Tylek Kettenburg
528559488d updated with windows drivers and installer 2015-06-25 14:49:02 -07:00
Erik Tylek Kettenburg
487b621a89 add drivers to windows 2015-06-24 16:13:07 -07:00
Erik Tylek Kettenburg
2f8eec51b4 fix to stop warning in 1.6.5+ 2015-06-24 15:55:28 -07:00
Erik Tylek Kettenburg
aeb7af566f fixes for BM compat 2015-06-24 14:40:30 -07:00
Erik Tylek Kettenburg
8810516130 add avrdude dummy back in as launcher 2015-06-23 20:30:23 -07:00
42 changed files with 1119 additions and 432 deletions

View File

@ -78,7 +78,7 @@ digispark-tiny16.upload.wait_for_upload_port = false
digispark-tiny16.upload.use_1200bps_touch = false digispark-tiny16.upload.use_1200bps_touch = false
digispark-tiny16.upload.disable_flushing = false digispark-tiny16.upload.disable_flushing = false
digispark-tiny8.name=Digispark (16mhz - No USB) digispark-tiny8.name=Digispark (8mhz - No USB)
digispark-tiny8.upload.using=micronucleusprog digispark-tiny8.upload.using=micronucleusprog
digispark-tiny8.upload.protocol=usb digispark-tiny8.upload.protocol=usb
digispark-tiny8.upload.tool=micronucleus digispark-tiny8.upload.tool=micronucleus
@ -92,7 +92,7 @@ digispark-tiny8.upload.wait_for_upload_port = false
digispark-tiny8.upload.use_1200bps_touch = false digispark-tiny8.upload.use_1200bps_touch = false
digispark-tiny8.upload.disable_flushing = false digispark-tiny8.upload.disable_flushing = false
digispark-tiny1.name=Digispark (16mhz - No USB) digispark-tiny1.name=Digispark (1mhz - No USB)
digispark-tiny1.upload.using=micronucleusprog digispark-tiny1.upload.using=micronucleusprog
digispark-tiny1.upload.protocol=usb digispark-tiny1.upload.protocol=usb
digispark-tiny1.upload.tool=micronucleus digispark-tiny1.upload.tool=micronucleus

View File

@ -43,6 +43,7 @@ extern "C"{
#define INPUT 0x0 #define INPUT 0x0
#define OUTPUT 0x1 #define OUTPUT 0x1
#define INPUT_PULLUP 0x2
#define true 0x1 #define true 0x1
#define false 0x0 #define false 0x0

View File

@ -35,21 +35,28 @@ void pinMode(uint8_t pin, uint8_t mode)
{ {
uint8_t bit = digitalPinToBitMask(pin); uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin); uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg; volatile uint8_t *reg, *out;
if (port == NOT_A_PIN) return; if (port == NOT_A_PIN) return;
// JWS: can I let the optimizer do this? // JWS: can I let the optimizer do this?
reg = portModeRegister(port); reg = portModeRegister(port);
out = portOutputRegister(port);
if (mode == INPUT) { if (mode == INPUT) {
uint8_t oldSREG = SREG; uint8_t oldSREG = SREG;
cli(); cli();
*reg &= ~bit; *reg &= ~bit;
SREG = oldSREG; SREG = oldSREG;
} else if (mode == INPUT_PULLUP) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
*out |= bit;
SREG = oldSREG;
} else { } else {
uint8_t oldSREG = SREG; uint8_t oldSREG = SREG;
cli(); cli();
*reg |= bit; *reg |= bit;
SREG = oldSREG; SREG = oldSREG;
} }

View File

@ -126,8 +126,10 @@ const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH]
#define KEY_F11 68 #define KEY_F11 68
#define KEY_F12 69 #define KEY_F12 69
#define KEY_ARROW_LEFT 0x50 #define KEY_ARROW_UP 82
#define KEY_ARROW_DOWN 81
#define KEY_ARROW_LEFT 80
#define KEY_ARROW_RIGHT 79
class DigiKeyboardDevice : public Print { class DigiKeyboardDevice : public Print {
public: public:
@ -163,14 +165,30 @@ class DigiKeyboardDevice : public Print {
} }
} }
//sendKeyStroke: sends a key press AND release
void sendKeyStroke(byte keyStroke) { void sendKeyStroke(byte keyStroke) {
sendKeyStroke(keyStroke, 0); sendKeyStroke(keyStroke, 0);
} }
//sendKeyStroke: sends a key press AND release with modifiers
void sendKeyStroke(byte keyStroke, byte modifiers) { void sendKeyStroke(byte keyStroke, byte modifiers) {
sendKeyPress(keyStroke, modifiers);
// This stops endlessly repeating keystrokes:
sendKeyPress(0,0);
}
//sendKeyPress: sends a key press only - no release
//to release the key, send again with keyPress=0
void sendKeyPress(byte keyPress) {
sendKeyPress(keyPress, 0);
}
//sendKeyPress: sends a key press only, with modifiers - no release
//to release the key, send again with keyPress=0
void sendKeyPress(byte keyPress, byte modifiers) {
while (!usbInterruptIsReady()) { while (!usbInterruptIsReady()) {
// Note: We wait until we can send keystroke // Note: We wait until we can send keyPress
// so we know the previous keystroke was // so we know the previous keyPress was
// sent. // sent.
usbPoll(); usbPoll();
_delay_ms(5); _delay_ms(5);
@ -179,20 +197,8 @@ class DigiKeyboardDevice : public Print {
memset(reportBuffer, 0, sizeof(reportBuffer)); memset(reportBuffer, 0, sizeof(reportBuffer));
reportBuffer[0] = modifiers; reportBuffer[0] = modifiers;
reportBuffer[1] = keyStroke; reportBuffer[1] = keyPress;
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
while (!usbInterruptIsReady()) {
// Note: We wait until we can send keystroke
// so we know the previous keystroke was
// sent.
usbPoll();
_delay_ms(5);
}
// This stops endlessly repeating keystrokes:
memset(reportBuffer, 0, sizeof(reportBuffer));
usbSetInterrupt(reportBuffer, sizeof(reportBuffer)); usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
} }

View File

@ -2,13 +2,10 @@
#include "LiquidCrystal_I2C.h" #include "LiquidCrystal_I2C.h"
#include <inttypes.h> #include <inttypes.h>
#if defined(__AVR_ATtiny85__) || (__AVR_ATtiny2313__) || (__AVR_ATtiny167__)
#include "TinyWireM.h" // include this if ATtiny85 or ATtiny2313
#else
#include <Wire.h> // original lib include
#endif
#include "Arduino.h" #include "Arduino.h"
#include "TinyWireM.h" // include this if ATtiny85 or ATtiny2313
// When the display powers up, it is configured as follows: // When the display powers up, it is configured as follows:
// //
@ -43,7 +40,7 @@ void LiquidCrystal_I2C::init(){
void LiquidCrystal_I2C::init_priv() void LiquidCrystal_I2C::init_priv()
{ {
#if defined (__AVR_ATtiny85__) || (__AVR_ATtiny2313__) || (__AVR_ATtiny167__) #if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny2313__) || defined(__AVR_ATtiny167__)
TinyWireM.begin(); // initialize I2C lib TinyWireM.begin(); // initialize I2C lib
#else // original call #else // original call
Wire.begin(); Wire.begin();
@ -250,7 +247,7 @@ void LiquidCrystal_I2C::write4bits(uint8_t value) {
} }
void LiquidCrystal_I2C::expanderWrite(uint8_t _data){ void LiquidCrystal_I2C::expanderWrite(uint8_t _data){
#if defined(__AVR_ATtiny85__) || (__AVR_ATtiny2313__)|| (__AVR_ATtiny167__) // Replaced Wire calls with ATtiny TWI calls #if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny2313__) || defined(__AVR_ATtiny167__) // Replaced Wire calls with ATtiny TWI calls
TinyWireM.beginTransmission(_Addr); TinyWireM.beginTransmission(_Addr);
TinyWireM.send(((int)(_data) | _backlightval)); TinyWireM.send(((int)(_data) | _backlightval));
TinyWireM.endTransmission(); TinyWireM.endTransmission();

View File

@ -8,13 +8,6 @@
#include <inttypes.h> #include <inttypes.h>
#include "Print.h" #include "Print.h"
#if defined(__AVR_ATtiny85__) || (__AVR_ATtiny2313__) || (__AVR_ATtiny167__)
#include "TinyWireM.h" // include this if ATtiny85 or ATtiny2313
#else
#include <Wire.h> // original lib include
#endif
// commands // commands
#define LCD_CLEARDISPLAY 0x01 #define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02 #define LCD_RETURNHOME 0x02

View File

@ -49,6 +49,9 @@ void DigisparkRGBBegin() {
#ifdef TIMSK0 #ifdef TIMSK0
TIMSK0 = (1 << TOV0); // enable overflow interrupt TIMSK0 = (1 << TOV0); // enable overflow interrupt
#endif #endif
#ifdef TCCR0B
TCCR0B = (1 << CS00); // start timer, no prescale
#endif
sei(); sei();

View File

@ -13,46 +13,40 @@ byte GREEN = 1;
byte COLORS[] = {RED, BLUE, GREEN}; byte COLORS[] = {RED, BLUE, GREEN};
// the setup routine runs once when you press reset: // the setup routine runs once when you press reset:
void setup() { void setup() {
DigisparkRGBBegin(); DigisparkRGBBegin();
} }
void loop () void loop() {
{ //direction: up = true, down = false
//direction: up = true, down = false boolean dir = true;
boolean dir = true; int i = 0;
int i = 0;
while(1) while(1) {
{ fade(COLORS[i%3], dir);
fade(COLORS[i%3], dir); i++;
i++; dir = !dir;
dir = !dir; }
} }
}
void fade(byte Led, boolean dir)
{
int i;
//if fading up void fade(byte Led, boolean dir) {
if (dir) int i;
{
for (i = 0; i < 256; i++) //if fading up
{ if (dir) {
DigisparkRGB(Led, i); for (i = 0; i < 256; i++) {
DigisparkRGBDelay(25);//1); DigisparkRGB(Led, i);
} DigisparkRGBDelay(25);//1);
} }
else } else {
{ for (i = 255; i >= 0; i--) {
for (i = 255; i >= 0; i--) DigisparkRGB(Led, i);
{ DigisparkRGBDelay(25);//1);
DigisparkRGB(Led, i); }
DigisparkRGBDelay(25);//1); }
}
}
} }

View File

@ -0,0 +1 @@
//This file allows the Digispark_Examples to appear in the File > Examples menu and fixes the Invalid library warning in Arduino IDE 1.6.6+

View File

@ -0,0 +1,146 @@
/*
EEPROM.h - EEPROM library
Original Copyright (c) 2006 David A. Mellis. All right reserved.
New version by Christopher Andrews 2015.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EEPROM_h
#define EEPROM_h
#include <inttypes.h>
#include <avr/eeprom.h>
#include <avr/io.h>
/***
EERef class.
This object references an EEPROM cell.
Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
***/
struct EERef{
EERef( const int index )
: index( index ) {}
//Access/read members.
uint8_t operator*() const { return eeprom_read_byte( (uint8_t*) index ); }
operator const uint8_t() const { return **this; }
//Assignment/write members.
EERef &operator=( const EERef &ref ) { return *this = *ref; }
EERef &operator=( uint8_t in ) { return eeprom_write_byte( (uint8_t*) index, in ), *this; }
EERef &operator +=( uint8_t in ) { return *this = **this + in; }
EERef &operator -=( uint8_t in ) { return *this = **this - in; }
EERef &operator *=( uint8_t in ) { return *this = **this * in; }
EERef &operator /=( uint8_t in ) { return *this = **this / in; }
EERef &operator ^=( uint8_t in ) { return *this = **this ^ in; }
EERef &operator %=( uint8_t in ) { return *this = **this % in; }
EERef &operator &=( uint8_t in ) { return *this = **this & in; }
EERef &operator |=( uint8_t in ) { return *this = **this | in; }
EERef &operator <<=( uint8_t in ) { return *this = **this << in; }
EERef &operator >>=( uint8_t in ) { return *this = **this >> in; }
EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; }
/** Prefix increment/decrement **/
EERef& operator++() { return *this += 1; }
EERef& operator--() { return *this -= 1; }
/** Postfix increment/decrement **/
uint8_t operator++ (int){
uint8_t ret = **this;
return ++(*this), ret;
}
uint8_t operator-- (int){
uint8_t ret = **this;
return --(*this), ret;
}
int index; //Index of current EEPROM cell.
};
/***
EEPtr class.
This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
Just like a normal pointer type, this can be dereferenced and repositioned using
increment/decrement operators.
***/
struct EEPtr{
EEPtr( const int index )
: index( index ) {}
operator const int() const { return index; }
EEPtr &operator=( int in ) { return index = in, *this; }
//Iterator functionality.
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
EERef operator*() { return index; }
/** Prefix & Postfix increment/decrement **/
EEPtr& operator++() { return ++index, *this; }
EEPtr& operator--() { return --index, *this; }
EEPtr operator++ (int) { return index++; }
EEPtr operator-- (int) { return index--; }
int index; //Index of current EEPROM cell.
};
/***
EEPROMClass class.
This object represents the entire EEPROM space.
It wraps the functionality of EEPtr and EERef into a basic interface.
This class is also 100% backwards compatible with earlier Arduino core releases.
***/
struct EEPROMClass{
//Basic user access methods.
EERef operator[]( const int idx ) { return idx; }
uint8_t read( int idx ) { return EERef( idx ); }
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }
//STL and C++11 iteration capability.
EEPtr begin() { return 0x00; }
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
uint16_t length() { return E2END + 1; }
//Functionality to 'get' and 'put' objects to and from EEPROM.
template< typename T > T &get( int idx, T &t ){
EEPtr e = idx;
uint8_t *ptr = (uint8_t*) &t;
for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
return t;
}
template< typename T > const T &put( int idx, const T &t ){
EEPtr e = idx;
const uint8_t *ptr = (const uint8_t*) &t;
for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
return t;
}
};
static EEPROMClass EEPROM;
#endif

View File

@ -0,0 +1,139 @@
## **EEPROM Library V2.0** for Arduino
**Written by:** _Christopher Andrews_.
### **What is the EEPROM library.**
Th EEPROM library provides an easy to use interface to interact with the internal non-volatile storage found in AVR based Arduino boards. This library will work on many AVR devices like ATtiny and ATmega chips.
### **How to use it**
The EEPROM library is included in your IDE download. To add its functionality to your sketch you'll need to reference the library header file. You do this by adding an include directive to the top of your sketch.
```Arduino
#include <EEPROM.h>
void setup(){
}
void loop(){
}
```
The library provides a global variable named `EEPROM`, you use this variable to access the library functions. The methods provided in the EEPROM class are listed below.
You can view all the examples [here](examples/).
### **Library functions**
#### **`EEPROM.read( address )`** [[_example_]](examples/eeprom_read/eeprom_read.ino)
This function allows you to read a single byte of data from the eeprom.
Its only parameter is an `int` which should be set to the address you wish to read.
The function returns an `unsigned char` containing the value read.
#### **`EEPROM.write( address, value )`** [[_example_]](examples/eeprom_write/eeprom_write.ino)
The `write()` method allows you to write a single byte of data to the EEPROM.
Two parameters are needed. The first is an `int` containing the address that is to be written, and the second is a the data to be written (`unsigned char`).
This function does not return any value.
#### **`EEPROM.update( address, value )`** [[_example_]](examples/eeprom_update/eeprom_update.ino)
This function is similar to `EEPROM.write()` however this method will only write data if the cell contents pointed to by `address` is different to `value`. This method can help prevent unnecessary wear on the EEPROM cells.
This function does not return any value.
#### **`EEPROM.get( address, object )`** [[_example_]](examples/eeprom_get/eeprom_get.ino)
This function will retrieve any object from the EEPROM.
Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to read.
This function returns a reference to the `object` passed in. It does not need to be used and is only returned for conveience.
#### **`EEPROM.put( address, object )`** [[_example_]](examples/eeprom_put/eeprom_put.ino)
This function will write any object to the EEPROM.
Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to write.
This function uses the _update_ method to write its data, and therefore only rewrites changed cells.
This function returns a reference to the `object` passed in. It does not need to be used and is only returned for conveience.
#### **Subscript operator: `EEPROM[address]`** [[_example_]](examples/eeprom_crc/eeprom_crc.ino)
This operator allows using the identifier `EEPROM` like an array.
EEPROM cells can be read _and_ **_written_** directly using this method.
This operator returns a reference to the EEPROM cell.
```c++
unsigned char val;
//Read first EEPROM cell.
val = EEPROM[ 0 ];
//Write first EEPROM cell.
EEPROM[ 0 ] = val;
//Compare contents
if( val == EEPROM[ 0 ] ){
//Do something...
}
```
#### **`EEPROM.length()`**
This function returns an `unsigned int` containing the number of cells in the EEPROM.
---
### **Advanced features**
This library uses a component based approach to provide its functionality. This means you can also use these components to design a customized approach. Two background classes are available for use: `EERef` & `EEPtr`.
#### **`EERef` class**
This object references an EEPROM cell.
Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
```C++
EERef ref = EEPROM[ 10 ]; //Create a reference to 11th cell.
ref = 4; //write to EEPROM cell.
unsigned char val = ref; //Read referenced cell.
```
#### **`EEPtr` class**
This object is a bidirectional pointer to EEPROM cells represented by `EERef` objects.
Just like a normal pointer type, this type can be dereferenced and repositioned using
increment/decrement operators.
```C++
EEPtr ptr = 10; //Create a pointer to 11th cell.
*ptr = 4; //dereference and write to EEPROM cell.
unsigned char val = *ptr; //dereference and read.
ptr++; //Move to next EEPROM cell.
```
#### **`EEPROM.begin()`**
This function returns an `EEPtr` pointing to the first cell in the EEPROM.
This is useful for STL objects, custom iteration and C++11 style ranged for loops.
#### **`EEPROM.end()`**
This function returns an `EEPtr` pointing at the location after the last EEPROM cell.
Used with `begin()` to provide custom iteration.
**Note:** The `EEPtr` returned is invalid as it is out of range. Infact the hardware causes wrapping of the address (overflow) and `EEPROM.end()` actually references the first EEPROM cell.

View File

@ -0,0 +1,35 @@
/*
* EEPROM Clear
*
* Sets all of the bytes of the EEPROM to 0.
* Please see eeprom_iteration for a more in depth
* look at how to traverse the EEPROM.
*
* This example code is in the public domain.
*/
#include <EEPROM.h>
void setup()
{
/***
Iterate through each byte of the EEPROM storage.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
for ( int i = 0 ; i < EEPROM.length() ; i++ )
EEPROM.write(i, 0);
// turn the LED on when we're done
digitalWrite(13, HIGH);
}
void loop(){ /** Empty loop. **/ }

View File

@ -0,0 +1,50 @@
/***
Written by Christopher Andrews.
CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ).
A CRC is a simple way of checking whether data has changed or become corrupted.
This example calculates a CRC value directly on the EEPROM values.
The purpose of this example is to highlight how the EEPROM object can be used just like an array.
***/
#include <Arduino.h>
#include <EEPROM.h>
void setup(){
//Start serial
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//Print length of data to run CRC on.
Serial.print( "EEPROM length: " );
Serial.println( EEPROM.length() );
//Print the result of calling eeprom_crc()
Serial.print( "CRC32 of EEPROM data: 0x" );
Serial.println( eeprom_crc(), HEX );
Serial.print( "\n\nDone!" );
}
void loop(){ /* Empty loop */ }
unsigned long eeprom_crc( void ){
const unsigned long crc_table[16] = {
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};
unsigned long crc = ~0L;
for( int index = 0 ; index < EEPROM.length() ; ++index ){
crc = crc_table[( crc ^ EEPROM[index] ) & 0x0f] ^ (crc >> 4);
crc = crc_table[( crc ^ ( EEPROM[index] >> 4 )) & 0x0f] ^ (crc >> 4);
crc = ~crc;
}
return crc;
}

View File

@ -0,0 +1,66 @@
/***
eeprom_get example.
This shows how to use the EEPROM.get() method.
To pre-set the EEPROM data, run the example sketch eeprom_put.
This sketch will run without it, however, the values shown
will be shown from what ever is already on the EEPROM.
This may cause the serial object to print out a large string
of garbage if there is no null character inside one of the strings
loaded.
Written by Christopher Andrews 2015
Released under MIT licence.
***/
#include <EEPROM.h>
void setup(){
float f = 0.00f; //Variable to store data read from EEPROM.
int eeAddress = 0; //EEPROM address to start reading from
Serial.begin( 9600 );
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print( "Read float from EEPROM: " );
//Get the float data from the EEPROM at position 'eeAddress'
EEPROM.get( eeAddress, f );
Serial.println( f, 3 ); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
/***
As get also returns a reference to 'f', you can use it inline.
E.g: Serial.print( EEPROM.get( eeAddress, f ) );
***/
/***
Get can be used with custom structures too.
I have separated this into an extra function.
***/
secondTest(); //Run the next test.
}
struct MyObject{
float field1;
byte field2;
char name[10];
};
void secondTest(){
int eeAddress = sizeof(float); //Move address to the next byte after float 'f'.
MyObject customVar; //Variable to store custom object read from EEPROM.
EEPROM.get( eeAddress, customVar );
Serial.println( "Read custom object from EEPROM: " );
Serial.println( customVar.field1 );
Serial.println( customVar.field2 );
Serial.println( customVar.name );
}
void loop(){ /* Empty loop */ }

View File

@ -0,0 +1,57 @@
/***
eeprom_iteration example.
A set of example snippets highlighting the
simplest methods for traversing the EEPROM.
Running this sketch is not necessary, this is
simply highlighting certain programming methods.
Written by Christopher Andrews 2015
Released under MIT licence.
***/
#include <EEPROM.h>
void setup() {
/***
Iterate the EEPROM using a for loop.
***/
for( int index = 0 ; index < EEPROM.length() ; index++ ){
//Add one to each cell in the EEPROM
EEPROM[ index ] += 1;
}
/***
Iterate the EEPROM using a while loop.
***/
int index = 0;
while( index < EEPROM.length() ){
//Add one to each cell in the EEPROM
EEPROM[ index ] += 1;
index++;
}
/***
Iterate the EEPROM using a do-while loop.
***/
int idx = 0; //Used 'idx' to avoid name conflict with 'index' above.
do{
//Add one to each cell in the EEPROM
EEPROM[ idx ] += 1;
idx++;
}while( idx < EEPROM.length() );
} //End of setup function.
void loop(){}

View File

@ -0,0 +1,56 @@
/***
eeprom_put example.
This shows how to use the EEPROM.put() method.
Also, this sketch will pre-set the EEPROM data for the
example sketch eeprom_get.
Note, unlike the single byte version EEPROM.write(),
the put method will use update semantics. As in a byte
will only be written to the EEPROM if the data is actually
different.
Written by Christopher Andrews 2015
Released under MIT licence.
***/
#include <EEPROM.h>
struct MyObject{
float field1;
byte field2;
char name[10];
};
void setup(){
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
float f = 123.456f; //Variable to store in EEPROM.
int eeAddress = 0; //Location we want the data to be put.
//One simple call, with the address first and the object second.
EEPROM.put( eeAddress, f );
Serial.println("Written float data type!");
/** Put is designed for use with custom structures also. **/
//Data to store.
MyObject customVar = {
3.14f,
65,
"Working!"
};
eeAddress += sizeof(float); //Move address to the next byte after float 'f'.
EEPROM.put( eeAddress, customVar );
Serial.print( "Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!" );
}
void loop(){ /* Empty loop */ }

View File

@ -0,0 +1,57 @@
/*
* EEPROM Read
*
* Reads the value of each byte of the EEPROM and prints it
* to the computer.
* This example code is in the public domain.
*/
#include <EEPROM.h>
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value;
void setup()
{
// initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop()
{
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);
Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
/***
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
address = address + 1;
if(address == EEPROM.length())
address = 0;
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++address &= EEPROM.length() - 1;
***/
delay(500);
}

View File

@ -0,0 +1,69 @@
/***
EEPROM Update method
Stores values read from analog input 0 into the EEPROM.
These values will stay in the EEPROM when the board is
turned off and may be retrieved later by another sketch.
If a value has not changed in the EEPROM, it is not overwritten
which would reduce the life span of the EEPROM unnecessarily.
Released using MIT licence.
***/
#include <EEPROM.h>
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int address = 0;
void setup(){ /** EMpty setup **/ }
void loop()
{
/***
need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a
value from 0 to 255.
***/
int val = analogRead(0) / 4;
/***
Update the particular EEPROM cell.
these values will remain there when the board is
turned off.
***/
EEPROM.update(address, val);
/***
The function EEPROM.update(address, val) is equivalent to the following:
if( EEPROM.read(address) != val ){
EEPROM.write(address, val);
}
***/
/***
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
address = address + 1;
if(address == EEPROM.length())
address = 0;
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++address &= EEPROM.length() - 1;
***/
delay(100);
}

View File

@ -0,0 +1,58 @@
/*
* EEPROM Write
*
* Stores values read from analog input 0 into the EEPROM.
* These values will stay in the EEPROM when the board is
* turned off and may be retrieved later by another sketch.
*/
#include <EEPROM.h>
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0;
void setup(){ /** Empty setup. **/}
void loop()
{
/***
Need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a
value from 0 to 255.
***/
int val = analogRead(0) / 4;
/***
Write the value to the appropriate byte of the EEPROM.
these values will remain there when the board is
turned off.
***/
EEPROM.write(addr, val);
/***
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
addr = addr + 1;
if(addr == EEPROM.length())
addr = 0;
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++addr &= EEPROM.length() - 1;
***/
delay(100);
}

View File

@ -0,0 +1,22 @@
#######################################
# Syntax Coloring Map For EEPROM
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
EEPROM KEYWORD1
EERef KEYWORD1
EEPtr KEYWORD2
#######################################
# Methods and Functions (KEYWORD2)
#######################################
update KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

View File

@ -0,0 +1,9 @@
name=EEPROM
version=2.0
author=Arduino, Christopher Andrews
maintainer=Arduino <info@arduino.cc>
sentence=Enables reading and writing to the permanent board storage. For all Arduino boards BUT Arduino DUE.
paragraph=
url=http://www.arduino.cc/en/Reference/EEPROM
architectures=avr

View File

@ -85,7 +85,7 @@ void loop() {
} }
//Read from or write to register from the SCP1000: //Read from or write to register from the SCP1000:
unsigned int readRegister(byte thisRegister, int bytesToRead ) { unsigned int readRegister(byte thisRegister, int bytesToRead) {
byte inByte = 0; // incoming byte from the SPI byte inByte = 0; // incoming byte from the SPI
unsigned int result = 0; // result to return unsigned int result = 0; // result to return
Serial.print(thisRegister, BIN); Serial.print(thisRegister, BIN);
@ -117,7 +117,7 @@ unsigned int readRegister(byte thisRegister, int bytesToRead ) {
// take the chip select high to de-select: // take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH); digitalWrite(chipSelectPin, HIGH);
// return the result: // return the result:
return(result); return (result);
} }

View File

@ -36,7 +36,7 @@ const int slaveSelectPin = 10;
void setup() { void setup() {
// set the slaveSelectPin as an output: // set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT); pinMode(slaveSelectPin, OUTPUT);
// initialize SPI: // initialize SPI:
SPI.begin(); SPI.begin();
} }

View File

@ -4,6 +4,7 @@ author=Arduino
maintainer=Arduino <info@arduino.cc> maintainer=Arduino <info@arduino.cc>
sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For all Arduino boards, BUT Arduino DUE. sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. For all Arduino boards, BUT Arduino DUE.
paragraph= paragraph=
category=Communication
url=http://www.arduino.cc/en/Reference/SPI url=http://www.arduino.cc/en/Reference/SPI
architectures=avr architectures=avr

View File

@ -270,7 +270,7 @@ void vw_pll()
// Returns prescaler index into {0, 0, 3, 6, 8, 10, 12} array // Returns prescaler index into {0, 0, 3, 6, 8, 10, 12} array
// and sets nticks to compare-match value if lower than max_ticks // and sets nticks to compare-match value if lower than max_ticks
// returns 0 & nticks = 0 on fault // returns 0 & nticks = 0 on fault
uint8_t prescalers[] PROGMEM = {0, 0, 3, 6, 8, 10, 12}; /* Must be outside the function */ const uint8_t prescalers[] PROGMEM = {0, 0, 3, 6, 8, 10, 12}; /* Must be outside the function */
uint8_t _timer_calc(uint16_t speed, uint16_t max_ticks, uint16_t *nticks) uint8_t _timer_calc(uint16_t speed, uint16_t max_ticks, uint16_t *nticks)
{ {
// Clock divider (prescaler) values - 0/4096: error flag // Clock divider (prescaler) values - 0/4096: error flag

View File

@ -12,7 +12,7 @@ version=1.5.4
# --------------------- # ---------------------
# Default "compiler.path" is correct, change only if you want to overidde the initial value # Default "compiler.path" is correct, change only if you want to overidde the initial value
#compiler.path={runtime.ide.path}/hardware/tools/avr/bin/ compiler.path={runtime.tools.avr-gcc.path}/bin/
compiler.c.cmd=avr-gcc compiler.c.cmd=avr-gcc
compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD
compiler.c.elf.flags=-Os -Wl,--gc-sections compiler.c.elf.flags=-Os -Wl,--gc-sections
@ -44,10 +44,10 @@ recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -m
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Create archives ## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects ## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{archive_file_path}" "-L{build.path}" -lm
## Create eeprom ## Create eeprom
recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep" recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"
@ -55,6 +55,10 @@ recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.obj
## Create hex ## Create hex
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
## Save hex
recipe.output.tmp_file={build.project_name}.hex
recipe.output.save_file={build.project_name}.{build.variant}.hex
## Compute size ## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).* recipe.size.regex=^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*
@ -67,12 +71,12 @@ recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
#tools.micronucleus.cmd.path={runtime.ide.path}/hardware/digistump/avr/tools/avrdude #tools.micronucleus.cmd.path={runtime.ide.path}/hardware/digistump/avr/tools/avrdude
#tools.micronucleus.cmd.path.linux={runtime.ide.path}/hardware/digistump/avr/tools/avrdude #tools.micronucleus.cmd.path.linux={runtime.ide.path}/hardware/digistump/avr/tools/avrdude
tools.micronucleus.cmd.path={runtime.tools.micronucleus.path}/micronucleus tools.micronucleus.cmd.path={runtime.tools.micronucleus.path}/launcher
tools.micronucleus.upload.params.verbose= tools.micronucleus.upload.params.verbose=
tools.micronucleus.upload.params.quiet= tools.micronucleus.upload.params.quiet=
tools.micronucleus.upload.pattern="{cmd.path}" --run --timeout 60 "{build.path}/{build.project_name}.hex" #tools.micronucleus.upload.pattern="{cmd.path}" --run --timeout 60 "{build.path}/{build.project_name}.hex"
#tools.micronucleus.upload.pattern="{cmd.path}" -cdigispark --timeout 60 -Uflash:w:{build.path}/{build.project_name}.hex:i tools.micronucleus.upload.pattern="{cmd.path}" -cdigispark --timeout 60 -Uflash:w:{build.path}/{build.project_name}.hex:i
# USB Default Flags # USB Default Flags
# Default blank usb manufacturer will be filled it at compile time # Default blank usb manufacturer will be filled it at compile time

View File

@ -47,6 +47,10 @@
#define PORT_B_ID 1 #define PORT_B_ID 1
#endif #endif
#ifndef __AVR_ATtiny85__
#define __AVR_ATtiny85__
#endif
#define NOT_A_PIN 0 #define NOT_A_PIN 0
#define NOT_A_PORT 0 #define NOT_A_PORT 0

View File

@ -27,6 +27,10 @@
#define ATTINYX7 1 #define ATTINYX7 1
#ifndef __AVR_ATtiny167__
#define __AVR_ATtiny167__
#endif
#define SERIAL_BUFFER_SIZE 16 #define SERIAL_BUFFER_SIZE 16
#include <avr/pgmspace.h> #include <avr/pgmspace.h>

View File

@ -27,6 +27,10 @@
#define ATTINYX7 1 #define ATTINYX7 1
#ifndef __AVR_ATtiny167__
#define __AVR_ATtiny167__
#endif
#define SERIAL_BUFFER_SIZE 32 #define SERIAL_BUFFER_SIZE 32
#include <avr/pgmspace.h> #include <avr/pgmspace.h>

View File

@ -27,6 +27,10 @@
#define ATTINYX7 1 #define ATTINYX7 1
#ifndef __AVR_ATtiny167__
#define __AVR_ATtiny167__
#endif
#define SERIAL_BUFFER_SIZE 64 #define SERIAL_BUFFER_SIZE 64
#include <avr/pgmspace.h> #include <avr/pgmspace.h>

View File

@ -14,3 +14,4 @@ digix.build.variant=digix
digix.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a digix.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
digix.build.vid=0x16D0 digix.build.vid=0x16D0
digix.build.pid=0x078A digix.build.pid=0x078A
digix.build.board=SAM_DIGIX

View File

@ -0,0 +1 @@
//This file allows the DigiXBetaBonus sketches to appear in the File > Examples menu and fixes the Invalid library warning in Arduino IDE 1.6.6+

View File

@ -1,179 +0,0 @@
/*
Extensive TWI/I2C EEPROM Library - for 24LCxxx devices
version: 0.4.1
target device: Microchip 24LC256 or similar
compatibility: designed with Arduino Due
-> Ver. 0.4.1: Successfully tested with Arduino Uno R3 and Arduino Micro!
author: Dennis Schweer (Inglorious Engineer)
license: CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/deed.en)
Overview:
-bytewise reading/writing
void extEEPROMwrite(int chip_address, int address, byte value);
byte extEEPROMread(int chip_address, int address);
-pagewise reading/writing
void extEEPROMwritePage(int chip_address, int startaddress, byte* data_origin_array, int amount_of_transfered_bytes)
(!!!ATTENTION!!!: Limited to 30 Bytes only!)
void extEEPROMreadPage(int chip_address, int startaddress, byte* data_target_array, int amount_of_transfered_bytes)
(!!!ATTENTION!!!: Limited to 32 Bytes only)
Do not care about their size, just save them!
-read/write complete 32bit integers [Requires four bytes of your EEPROM.]
void extEEPROMwriteInt(int chip_address, int address, int data_to_be_stored)
int extEEPROMreadInt(int chip_address, int address)
-read/write your 10/12 bit sensor values (e.g., ADC values) [Requires two bytes of your EEPROM.]
void extEEPROMwriteSensor(int chip_address, int addresse, int data_to_be_stored)
int extEEPROMreadSensor(int chip_address, int addresse)
NEW IN VERSION 0.4:
Now all functions include a device address parameter, allowing you to use two
or more external EEPROM chips simultaneously on a single bus. Just choose the
right device addresses and feet them into the library functions!
NEW IN VERSION 0.4.1:
My library is designed with an Arduino Due, but now everything is successfully
tested to work on Arduino Uno R3 and Arduino Micro as well! Since all current
Arduinos are based on either ATmega328 (e.g., Uno), ATmega32U4 (e.g., Micro/
Leonardo/Esplora) or ATSAM3X8E (Due), my library should work with ALL official
or 1:1-compatible boards.
!!! Unfortunately, Arduino Due appears to be the only device with the ability
to handle 32 bit integers. Hence none of my "writeInt" / "readInt" functions
run on 8-bit Arduinos !!!
Planned for future releases:
-erase byte
-erase page
-erase complete EEPROM
-read/write with autocorrection of "startaddress"-value
*/
#include "Arduino.h"
//========FUNCTIONS=========================
///////////////// WRITE /////////////////////
void extEEPROMwrite(int EEPROM_addr, int addr, byte data)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.write((byte) data); // send data
Wire.endTransmission(true); // stop transmitting
delay(6); // wait for a successful write
}
void extEEPROMwritePage(int EEPROM_addr, int addr, byte* data_origin, int amount)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
for(int i = 0; i<amount; i++) //write array into EEPROM
{
Wire.write((byte) data_origin[i]);
}
Wire.endTransmission(true); // stop transmitting
delay(6); // wait for a successful write
}
void extEEPROMwriteInt(int EEPROM_addr, int addr, int data)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.write(lowByte(data)); // send lowest byte of 32 bit integer
data = data >> 8;
Wire.write(lowByte(data)); // send 2nd lowest byte of 32 bit integer
data = data >> 8;
Wire.write(lowByte(data)); // send 2nd highest byte of 32 bit integer
data = data >> 8;
Wire.write(lowByte(data)); // send highest byte of 32 bit integer
Wire.endTransmission(true); // stop transmitting
delay(6); // wait for a successful write
}
void extEEPROMwriteSensor(int EEPROM_addr, int addr, int data)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.write(lowByte(data)); // send low byte of 12 bit integer
data = data >> 8;
Wire.write(lowByte(data)); // send high byte of 12 bit integer
Wire.endTransmission(true); // stop transmitting
delay(6); // wait for a successful write
}
///////////////// READ /////////////////////
byte extEEPROMread(int EEPROM_addr, int addr)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.endTransmission(true); // stop transmitting
Wire.requestFrom(EEPROM_addr, 0x01, true); // request 1 byte form the device attached to EEPROM_addr
byte data_out = 64;
// read that byte
while(Wire.available() == 0) {} // wait for data
data_out = Wire.read(); //read single byte
return data_out;
}
void extEEPROMreadPage(int EEPROM_addr, int addr, byte* data_target, int amount)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.endTransmission(true); // stop transmitting
Wire.requestFrom(EEPROM_addr, amount, true); // request 1 byte form the device attached to EEPROM_addr
// read that byte
while(Wire.available() == 0) {} // wait for data
for(int i = 0; i<amount; i++) //write data into array
{
data_target[i] = Wire.read();
}
}
int extEEPROMreadInt(int EEPROM_addr, int addr)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.endTransmission(true); // stop transmitting
Wire.requestFrom(EEPROM_addr, 0x04, true); // request 1 byte form the device attached to EEPROM_addr
int data_out = 0xDEADBEEF;
int temp = 0xDEADBEEF;
// read that byte
while(Wire.available() == 0) {} // wait for data
data_out = Wire.read(); //read single byte
//reconstruct value
temp = Wire.read();
temp = temp << 8;
data_out = data_out | temp;
temp = Wire.read();
temp = temp << 16;
data_out = data_out | temp;
temp = Wire.read();
temp = temp << 24;
data_out = data_out | temp;
return data_out;
}
int extEEPROMreadSensor(int EEPROM_addr, int addr)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.endTransmission(true); // stop transmitting
Wire.requestFrom(EEPROM_addr, 0x04, true); // request 1 byte form the device attached to EEPROM_addr
int data_out = 0xDEAD;
int temp = 0xBEEF;
// read that byte
while(Wire.available() == 0) {} // wait for data
data_out = Wire.read(); //read single byte
//reconstruct value
temp = Wire.read();
temp = temp << 8;
data_out = data_out | temp;
return data_out;
}

View File

@ -1,130 +0,0 @@
/*
Extensive TWI/I2C EEPROM Library - for 24LCxxx devices
version: 0.4.1
target device: Microchip 24LC256 or similar
compatibility: designed with Arduino Due
-> Ver. 0.4.1: Successfully tested with Arduino Uno R3 and Arduino Micro!
author: Dennis Schweer (Inglorious Engineer)
license: CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/deed.en)
Overview:
-bytewise reading/writing
void extEEPROMwrite(int chip_address, int address, byte value);
byte extEEPROMread(int chip_address, int address);
-pagewise reading/writing
void extEEPROMwritePage(int chip_address, int startaddress, byte* data_origin_array, int amount_of_transfered_bytes)
(!!!ATTENTION!!!: Limited to 30 Bytes only!)
void extEEPROMreadPage(int chip_address, int startaddress, byte* data_target_array, int amount_of_transfered_bytes)
(!!!ATTENTION!!!: Limited to 32 Bytes only)
Do not care about their size, just save them!
-read/write complete 32bit integers [Requires four bytes of your EEPROM.]
void extEEPROMwriteInt(int chip_address, int address, int data_to_be_stored)
int extEEPROMreadInt(int chip_address, int address)
-read/write your 10/12 bit sensor values (e.g., ADC values) [Requires two bytes of your EEPROM.]
void extEEPROMwriteSensor(int chip_address, int addresse, int data_to_be_stored)
int extEEPROMreadSensor(int chip_address, int addresse)
NEW IN VERSION 0.4:
Now all functions include a device address parameter, allowing you to use two
or more external EEPROM chips simultaneously on a single bus. Just choose the
right device addresses and feet them into the library functions!
NEW IN VERSION 0.4.1:
My library is designed with an Arduino Due, but now everything is successfully
tested to work on Arduino Uno R3 and Arduino Micro as well! Since all current
Arduinos are based on either ATmega328 (e.g., Uno), ATmega32U4 (e.g., Micro/
Leonardo/Esplora) or ATSAM3X8E (Due), my library should work with ALL official
or 1:1-compatible boards.
!!! Unfortunately, Arduino Due appears to be the only device with the ability
to handle 32 bit integers. Hence none of my "writeInt" / "readInt" functions
run on 8-bit Arduinos !!!
Planned for future releases:
-erase byte
-erase page
-erase complete EEPROM
-read/write with autocorrection of "startaddress"-value
*/
#include <Wire.h>
#include <Extensive_EEPROM.h>
const int EEPROM_addr = 0x50;
// Testbed variables
int test = 1;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600);
test = 1;
}
void loop()
{
//Testbed
if(test == 1) //only run it once
{
//byte-wise writing/reading
Serial.println("//byte-wise writing/reading");
for(int i = 0; i < 32; i++)
{
extEEPROMwrite(EEPROM_addr, i, i); //void extEEPROMwrite(int chip_address, int address, byte value);
}
int data_back;
for(int i = 0; i < 32; i++)
{
data_back = extEEPROMread(EEPROM_addr, i); //byte extEEPROMread(int chip_address, int address);
Serial.print("original data= ");
Serial.print(i);
Serial.print(" read_back= ");
Serial.println(data_back);
}
//page-wise writing/reading
Serial.println("//page-wise writing/reading");
byte data_to_be_written[30];
for(int i=0; i<30; i++)
{
data_to_be_written[i] = (29-i); //writes the numbers 29 downto 0 into cells 0-29
Serial.print("Original Data = ");
Serial.println((29-i));
}
//store array in EEPROM (max. 30 Bytes)
extEEPROMwritePage(EEPROM_addr, 32, data_to_be_written, 30); //void extEEPROMwritePage(int chip_address, int startaddress, byte* data_origin_array, int amount_of_transfered_bytes)
//read page into an array (max. 32 Bytes)
byte data_output[30];
extEEPROMreadPage(EEPROM_addr, 32, data_output, 30); // void extEEPROMreadPage(int chip_address, int startaddress, byte* data_target_array, int amountof_transfered_bytes)
for(int j=0; j<30; j++)
{
Serial.print("Read Page= ");
Serial.println(data_output[j]); // Print array
}
//write/read 32 bit integer
Serial.println("//write/read 32 bit integer");
int original_int = 0x7FFFFFFF;
extEEPROMwriteInt(EEPROM_addr, 70, original_int);
int original_int_output;
original_int_output = extEEPROMreadInt(EEPROM_addr, 70);
Serial.print("Integer: in = ");
Serial.print(original_int);
Serial.print(" / out = ");
Serial.println(original_int_output);
//write/read 10/12 bit sensor data
Serial.println("//write/read 10/12 bit sensor data");
int original_sensor = 0x7FFF;
extEEPROMwriteInt(EEPROM_addr, 75, original_sensor);
int original_sensor_output;
original_sensor_output = extEEPROMreadInt(EEPROM_addr, 75);
Serial.print("Sensordata: in = ");
Serial.print(original_sensor);
Serial.print(" / out = ");
Serial.println(original_sensor_output);
}
test = 2; // only perform this procedure once
}

View File

@ -0,0 +1,203 @@
/*
EEPROM.h - EEPROM library for the Digistump DigiX
This is mostly the merger of the stock Arduino EEPROM library, original
Copyright (c) 2006 David A. Mellis/Christopher Andrews 2015 (LGPL 2.1) with a
few functions from Dennis Schweer (Inglorious Engineer)'s Extensive TWI/I2C
EEPROM Library for 24LCxxx devices v0.4.1 (CC-BY-SA), as distributed with the
DigiX core.
Merging work by SukkoPera <software@sukkology.net>, 2016.
The basic idea is to create a library that is interface-compatible with
Arduino's stock library that is used on non-Due boards, to achieve
compatibility at source level, so that the usual EEPROM.write()/read()/get()
/put() calls can be used.
I'm not really sure of what license the resulting code should be released
under, so I'm leaving the LGPL 2.1, as most of the code here actually came
under that license, and the rest is pretty basic stuff, but let me know if I
should change that.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EEPROM_h
#define EEPROM_h
#include <inttypes.h>
#include <Wire.h>
static const int DIGIX_EEPROM_ADDR = 0x50;
static const int E2END = 0xFFF;
/***
EERef class.
This object references an EEPROM cell.
Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
***/
struct EERef{
private:
void extEEPROMwrite(int EEPROM_addr, int addr, byte data)
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.write((byte) data); // send data
Wire.endTransmission(true); // stop transmitting
delay(6); // wait for a successful write
}
byte extEEPROMread(int EEPROM_addr, int addr) const
{
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
Wire.write(highByte(addr)); // send high byte of address
Wire.write(lowByte(addr)); // send low byte of address
Wire.endTransmission(true); // stop transmitting
Wire.requestFrom(EEPROM_addr, 0x01, true); // request 1 byte form the device attached to EEPROM_addr
byte data_out = 64;
// read that byte
while(Wire.available() == 0) {} // wait for data
data_out = Wire.read(); //read single byte
return data_out;
}
public:
EERef( const int index )
: index( index ) {}
//Access/read members.
uint8_t operator*() const { return extEEPROMread( DIGIX_EEPROM_ADDR, index ); }
operator const uint8_t() const { return **this; }
//Assignment/write members.
EERef &operator=( const EERef &ref ) { return *this = *ref; }
EERef &operator=( uint8_t in ) { return extEEPROMwrite( DIGIX_EEPROM_ADDR, index, in ), *this; }
EERef &operator +=( uint8_t in ) { return *this = **this + in; }
EERef &operator -=( uint8_t in ) { return *this = **this - in; }
EERef &operator *=( uint8_t in ) { return *this = **this * in; }
EERef &operator /=( uint8_t in ) { return *this = **this / in; }
EERef &operator ^=( uint8_t in ) { return *this = **this ^ in; }
EERef &operator %=( uint8_t in ) { return *this = **this % in; }
EERef &operator &=( uint8_t in ) { return *this = **this & in; }
EERef &operator |=( uint8_t in ) { return *this = **this | in; }
EERef &operator <<=( uint8_t in ) { return *this = **this << in; }
EERef &operator >>=( uint8_t in ) { return *this = **this >> in; }
EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; }
/** Prefix increment/decrement **/
EERef& operator++() { return *this += 1; }
EERef& operator--() { return *this -= 1; }
/** Postfix increment/decrement **/
uint8_t operator++ (int){
uint8_t ret = **this;
return ++(*this), ret;
}
uint8_t operator-- (int){
uint8_t ret = **this;
return --(*this), ret;
}
int index; //Index of current EEPROM cell.
};
/***
EEPtr class.
This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
Just like a normal pointer type, this can be dereferenced and repositioned using
increment/decrement operators.
***/
struct EEPtr{
EEPtr( const int index )
: index( index ) {}
operator const int() const { return index; }
EEPtr &operator=( int in ) { return index = in, *this; }
//Iterator functionality.
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
EERef operator*() { return index; }
/** Prefix & Postfix increment/decrement **/
EEPtr& operator++() { return ++index, *this; }
EEPtr& operator--() { return --index, *this; }
EEPtr operator++ (int) { return index++; }
EEPtr operator-- (int) { return index--; }
int index; //Index of current EEPROM cell.
};
/***
EEPROMClass class.
This object represents the entire EEPROM space.
It wraps the functionality of EEPtr and EERef into a basic interface.
This class is also 100% backwards compatible with earlier Arduino core releases.
***/
struct EEPROMClass{
boolean inited;
// c'tor
EEPROMClass () { inited = false; }
// Check if the i2c library was initialized, and do it if not.
// FIXME: What happens if the sketch has already called Wire.begin() on its
// own?
void checkInited () { if (!inited) { Wire.begin(); inited = true; } }
//Basic user access methods.
EERef operator[]( const int idx ) { return idx; }
uint8_t read( int idx ) { checkInited (); return EERef( idx ); }
void write( int idx, uint8_t val ) { checkInited (); (EERef( idx )) = val; }
void update( int idx, uint8_t val ) { checkInited (); EERef( idx ).update( val ); }
//STL and C++11 iteration capability.
EEPtr begin() { return 0x00; }
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
uint16_t length() { return E2END + 1; }
//Functionality to 'get' and 'put' objects to and from EEPROM.
template< typename T > T &get( int idx, T &t ){
checkInited ();
EEPtr e = idx;
uint8_t *ptr = (uint8_t*) &t;
for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
return t;
}
template< typename T > const T &put( int idx, const T &t ){
checkInited ();
EEPtr e = idx;
const uint8_t *ptr = (const uint8_t*) &t;
for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
return t;
}
};
static EEPROMClass EEPROM;
#endif

View File

@ -74,6 +74,10 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.f
## Create output (.bin file) ## Create output (.bin file)
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin" recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
## Save hex
recipe.output.tmp_file={build.project_name}.bin
recipe.output.save_file={build.project_name}.{build.variant}.bin
## Compute size ## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=\.text\s+([0-9]+).* recipe.size.regex=\.text\s+([0-9]+).*

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.