Skip to content

Commit b31c53a

Browse files
2 parents e92c783 + d28bbfa commit b31c53a

File tree

8 files changed

+390
-2
lines changed

8 files changed

+390
-2
lines changed

libraries/Basics/examples/LowPower_WakeUpByTimer/LowPower_WakeUpByTimer.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ void setup() {
2929
Serial.begin(115200);
3030
boardInitMcu();
3131
Radio.Sleep( );
32-
TimerInit( &sleep, OnSleep );
32+
TimerInit( &sleep, onSleep );
3333
TimerInit( &wakeUp, onWakeUp );
34-
OnSleep();
34+
onSleep();
3535
}
3636

3737
void loop() {

libraries/EEPROM/EEPROM.cpp

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
EEPROM.cpp - ASR650x EEPROM emulation
3+
4+
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
22+
/*
23+
* note that the chip has 1K user flash.;
24+
* the size of user flash row is 256;
25+
* user flash row 0-2 can be edited;
26+
* user flash row 3 is reservated, must not be edited;
27+
*
28+
* CY_FLASH_SIZEOF_ROW is 256 , CY_SFLASH_USERBASE is 0x0ffff400
29+
*
30+
*/
31+
32+
#include "Arduino.h"
33+
#include "EEPROM.h"
34+
#include "debug.h"
35+
36+
#ifdef DEBUG_ASR_CORE
37+
#define DEBUGV(fmt, ...) ::printf((PGM_P)PSTR(fmt), ## __VA_ARGS__)
38+
#endif
39+
40+
#ifndef DEBUGV
41+
#define DEBUGV(...) do { (void)0; } while (0)
42+
#endif
43+
44+
#define _EEPROM_SIZE (CY_FLASH_SIZEOF_ROW * 3)
45+
46+
EEPROMClass::EEPROMClass(uint32_t baddr)
47+
: _baddr(baddr)
48+
, _data(0)
49+
, _size(0)
50+
, _dirty(false)
51+
{
52+
}
53+
54+
EEPROMClass::EEPROMClass(void)
55+
: _baddr(CY_SFLASH_USERBASE)
56+
, _data(0)
57+
, _size(0)
58+
, _dirty(false)
59+
{
60+
}
61+
62+
void EEPROMClass::begin(size_t size) {
63+
if (size <= 0) {
64+
DEBUGV("EEPROMClass::begin error, size == 0\n");
65+
return;
66+
}
67+
if (size > _EEPROM_SIZE) {
68+
DEBUGV("EEPROMClass::begin error, %d > %d\n", size, _EEPROM_SIZE);
69+
size = _EEPROM_SIZE;
70+
}
71+
72+
size = (size + 3) & (~3);
73+
74+
//In case begin() is called a 2nd+ time, don't reallocate if size is the same
75+
if(_data && size != _size) {
76+
delete[] _data;
77+
_data = new uint8_t[size];
78+
} else if(!_data) {
79+
_data = new uint8_t[size];
80+
}
81+
82+
_size = size;
83+
84+
if (FLASH_read_at(_baddr, reinterpret_cast<uint8_t *>(_data), _size) == -1) {
85+
DEBUGV("EEPROMClass::begin flash read failed\n");
86+
}
87+
88+
_dirty = false; //make sure dirty is cleared in case begin() is called 2nd+ time
89+
}
90+
91+
void EEPROMClass::end() {
92+
if (!_size)
93+
return;
94+
95+
commit();
96+
if(_data) {
97+
delete[] _data;
98+
}
99+
_data = 0;
100+
_size = 0;
101+
_dirty = false;
102+
}
103+
104+
105+
uint8_t EEPROMClass::read(int const address) {
106+
if (address < 0 || (size_t)address >= _size) {
107+
DEBUGV("EEPROMClass::read error, address %d > %d or %d < 0\n", address, _size, address);
108+
return 0;
109+
}
110+
if (!_data) {
111+
DEBUGV("EEPROMClass::read without ::begin\n");
112+
return 0;
113+
}
114+
115+
return _data[address];
116+
}
117+
118+
void EEPROMClass::write(int const address, uint8_t const value) {
119+
if (address < 0 || (size_t)address >= _size) {
120+
DEBUGV("EEPROMClass::write error, address %d > %d or %d < 0\n", address, _size, address);
121+
return;
122+
}
123+
if(!_data) {
124+
DEBUGV("EEPROMClass::read without ::begin\n");
125+
return;
126+
}
127+
128+
// Optimise _dirty. Only flagged if data written is different.
129+
uint8_t* pData = &_data[address];
130+
if (*pData != value)
131+
{
132+
*pData = value;
133+
_dirty = true;
134+
}
135+
}
136+
137+
bool EEPROMClass::commit() {
138+
if (!_size)
139+
return false;
140+
if(!_dirty)
141+
return true;
142+
if(!_data)
143+
return false;
144+
145+
if (FLASH_update(_baddr, reinterpret_cast<const void *>(_data), _size) == 0) {
146+
_dirty = false;
147+
return true;
148+
}
149+
150+
DEBUGV("EEPROMClass::commit failed\n");
151+
return false;
152+
}
153+
154+
uint8_t * EEPROMClass::getDataPtr() {
155+
_dirty = true;
156+
return &_data[0];
157+
}
158+
159+
uint8_t const * EEPROMClass::getConstDataPtr() const {
160+
return &_data[0];
161+
}
162+
163+
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
164+
EEPROMClass EEPROM;
165+
#endif
166+

libraries/EEPROM/EEPROM.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
EEPROM.cpp - ASR650x EEPROM emulation
3+
4+
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
22+
#ifndef EEPROM_h
23+
#define EEPROM_h
24+
25+
#include <stddef.h>
26+
#include <stdint.h>
27+
#include <string.h>
28+
29+
class EEPROMClass {
30+
public:
31+
EEPROMClass(uint32_t baddr);
32+
EEPROMClass(void);
33+
34+
void begin(size_t size);
35+
uint8_t read(int const address);
36+
void write(int const address, uint8_t const val);
37+
bool commit();
38+
void end();
39+
40+
uint8_t * getDataPtr();
41+
uint8_t const * getConstDataPtr() const;
42+
43+
template<typename T>
44+
T &get(int const address, T &t) {
45+
if (address < 0 || address + sizeof(T) > _size)
46+
return t;
47+
48+
memcpy((uint8_t*) &t, _data + address, sizeof(T));
49+
return t;
50+
}
51+
52+
template<typename T>
53+
const T &put(int const address, const T &t) {
54+
if (address < 0 || address + sizeof(T) > _size)
55+
return t;
56+
if (memcmp(_data + address, (const uint8_t*)&t, sizeof(T)) != 0) {
57+
_dirty = true;
58+
memcpy(_data + address, (const uint8_t*)&t, sizeof(T));
59+
}
60+
61+
return t;
62+
}
63+
64+
size_t length() {return _size;}
65+
66+
uint8_t& operator[](int const address) {return getDataPtr()[address];}
67+
uint8_t const & operator[](int const address) const {return getConstDataPtr()[address];}
68+
69+
protected:
70+
uint32_t _baddr;
71+
uint8_t* _data;
72+
size_t _size;
73+
bool _dirty;
74+
};
75+
76+
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
77+
extern EEPROMClass EEPROM;
78+
#endif
79+
80+
#endif
81+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
EEPROM Clear
3+
4+
Sets all of the bytes of the EEPROM to 0.
5+
This example code is in the public domain.
6+
7+
*/
8+
9+
#include <EEPROM.h>
10+
11+
void setup() {
12+
EEPROM.begin(512);
13+
// write a 0 to all 512 bytes of the EEPROM
14+
for (int i = 0; i < 512; i++) {
15+
EEPROM.write(i, 0);
16+
}
17+
18+
// turn the LED on when we're done
19+
pinMode(13, OUTPUT);
20+
digitalWrite(13, HIGH);
21+
EEPROM.end();
22+
}
23+
24+
void loop() {
25+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
EEPROM Read
3+
4+
Reads the value of each byte of the EEPROM and prints it
5+
to the computer.
6+
This example code is in the public domain.
7+
*/
8+
9+
#include <EEPROM.h>
10+
11+
// start reading from the first byte (address 0) of the EEPROM
12+
int address = 0;
13+
byte value;
14+
15+
void setup() {
16+
// initialize serial and wait for port to open:
17+
Serial.begin(115200);
18+
while (!Serial) {
19+
; // wait for serial port to connect. Needed for Leonardo only
20+
}
21+
EEPROM.begin(512);
22+
}
23+
24+
void loop() {
25+
// read a byte from the current address of the EEPROM
26+
value = EEPROM.read(address);
27+
28+
Serial.print(address);
29+
Serial.print("\t");
30+
Serial.print(value, DEC);
31+
Serial.println();
32+
33+
// advance to the next address of the EEPROM
34+
address = address + 1;
35+
36+
// there are only 512 bytes of EEPROM, from 0 to 511, so if we're
37+
// on address 512, wrap around to address 0
38+
if (address == 512) {
39+
address = 0;
40+
}
41+
42+
delay(500);
43+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
EEPROM Write
3+
4+
Stores values read from analog input 0 into the EEPROM.
5+
These values will stay in the EEPROM when the board is
6+
turned off and may be retrieved later by another sketch.
7+
*/
8+
9+
#include <EEPROM.h>
10+
11+
// the current address in the EEPROM (i.e. which byte
12+
// we're going to write to next)
13+
int addr = 0;
14+
15+
void setup() {
16+
Serial.begin(115200);
17+
EEPROM.begin(512);
18+
}
19+
20+
void loop() {
21+
// need to divide by 4 because analog inputs range from
22+
// 0 to 1023 and each byte of the EEPROM can only hold a
23+
// value from 0 to 255.
24+
int val = analogRead(A0) / 4;
25+
26+
// write the value to the appropriate byte of the EEPROM.
27+
// these values will remain there when the board is
28+
// turned off.
29+
EEPROM.write(addr, val);
30+
31+
// advance to the next address. there are 512 bytes in
32+
// the EEPROM, so go back to 0 when we hit 512.
33+
// save all changes to the flash.
34+
addr = addr + 1;
35+
if (addr == 512) {
36+
addr = 0;
37+
if (EEPROM.commit()) {
38+
Serial.println("EEPROM successfully committed");
39+
} else {
40+
Serial.println("ERROR! EEPROM commit failed");
41+
}
42+
}
43+
44+
delay(100);
45+
}

libraries/EEPROM/keywords.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#######################################
2+
# Syntax Coloring Map For Ultrasound
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
EEPROM KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
#######################################
16+
# Constants (LITERAL1)
17+
#######################################
18+

0 commit comments

Comments
 (0)