Skip to content

Commit d13cd04

Browse files
committed
update libraries E-I
1 parent a19ec7f commit d13cd04

File tree

113 files changed

+4245
-1605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4245
-1605
lines changed

libraries/FRAM/FRAM.cpp

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
//
22
// FILE: FRAM.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
5-
// PURPOSE: Class for FRAM memory
6-
// URL:
4+
// VERSION: 0.2.1
5+
// DATE: 2018-01-24
6+
// PURPOSE: Arduino library for I2C FRAM
7+
// URL: https://github.com/RobTillaart/FRAM_I2C
78
//
89
// HISTORY:
9-
// 0.1.0 initial version
10-
// 0.1.1 added suppport for Fujitsu 64Kbit MB85RC64T (kudos ysoyipek)
10+
// 0.1.0 2018-01-24 initial version
11+
// 0.1.1 2019-07-31 added suppport for Fujitsu 64Kbit MB85RC64T (kudos ysoyipek)
12+
// 0.2.0 2020-04-30 refactor, add writeProtectPin code
13+
// 0.2.1 2020-06-10 fix library.json
1114

1215
#include "FRAM.h"
1316

14-
#define FRAM_SLAVE_ID_ 0x7C
17+
const uint8_t FRAM_SLAVE_ID_= 0x7C;
1518

1619
/////////////////////////////////////////////////////
1720
//
@@ -20,7 +23,7 @@
2023
FRAM::FRAM()
2124
{}
2225

23-
int FRAM::begin(int address = 0X50)
26+
int FRAM::begin(uint8_t address, int8_t writeProtectPin)
2427
{
2528
if (address < 0x50 || address > 0x57)
2629
{
@@ -30,18 +33,11 @@ int FRAM::begin(int address = 0X50)
3033
_address = address;
3134
Wire.begin();
3235

33-
uint16_t mid = getManufacturerID();
34-
uint16_t pid = getProductID();
35-
_size = 0; // UNKNOWN
36-
if (mid == 0x000A) // fujitsu
36+
if (writeProtectPin > -1)
3737
{
38-
// note pid's are from fujitsu SIZE TYPE
39-
if (pid == 0x0358) _size = 8; // 8KB MB85RC64T
40-
if (pid == 0x0510) _size = 32; // 32KB MB85RC256V
41-
if (pid == 0x0658) _size = 64; // 64KB MB85RC512T
42-
if (pid == 0x0758) _size = 128; // 128KB MB85RC1MT
38+
_writeProtectPin = writeProtectPin;
39+
pinMode(_writeProtectPin, OUTPUT);
4340
}
44-
4541
return FRAM_OK;
4642
}
4743

@@ -104,7 +100,7 @@ uint32_t FRAM::read32(uint16_t memaddr)
104100

105101
void FRAM::read(uint16_t memaddr, uint8_t * obj, uint16_t size)
106102
{
107-
const int blocksize = 24;
103+
const uint8_t blocksize = 24;
108104
uint8_t * p = obj;
109105
while (size >= blocksize)
110106
{
@@ -113,44 +109,70 @@ void FRAM::read(uint16_t memaddr, uint8_t * obj, uint16_t size)
113109
p += blocksize;
114110
size -= blocksize;
115111
}
112+
// remainder
116113
if (size > 0)
117114
{
118115
readBlock(memaddr, p, size);
119116
}
120117
}
121118

119+
bool FRAM::setWriteProtect(bool b)
120+
{
121+
if (_writeProtectPin == -1) return false;
122+
digitalWrite(_writeProtectPin, b ? HIGH : LOW);
123+
return true;
124+
}
125+
122126
uint16_t FRAM::getManufacturerID()
123127
{
124-
uint16_t value = 0;
125-
Wire.beginTransmission(FRAM_SLAVE_ID_);
126-
Wire.write(_address << 1);
127-
Wire.endTransmission(false);
128-
int x = Wire.requestFrom(FRAM_SLAVE_ID_, 2);
129-
if (x != 2) return -1;
130-
value = Wire.read() << 4;
131-
value |= Wire.read() >> 4;
132-
return value;
128+
return getMetaData(0);
133129
}
134130

135131
uint16_t FRAM::getProductID()
136132
{
137-
uint16_t value = 0;
133+
return getMetaData(1);
134+
}
135+
136+
uint16_t FRAM::getSize()
137+
{
138+
uint16_t val = getMetaData(2); // density bits
139+
if (val > 0) return 1 << val;
140+
return 0;
141+
}
142+
143+
///////////////////////////////////////////////////////////
144+
//
145+
// PRIVATE
146+
//
147+
148+
// metadata is packed as [....MMMM][MMMMDDDD][PPPPPPPP]
149+
// M = manufacturerID
150+
// D = density => memsize = 2^D KB
151+
// P = product ID (together with D)
152+
uint16_t FRAM::getMetaData(uint8_t field)
153+
{
154+
if (field > 2) return 0;
155+
138156
Wire.beginTransmission(FRAM_SLAVE_ID_);
139157
Wire.write(_address << 1);
140158
Wire.endTransmission(false);
141-
int x = Wire.requestFrom(FRAM_SLAVE_ID_, 3);
159+
int x = Wire.requestFrom(FRAM_SLAVE_ID_, (uint8_t)3);
142160
if (x != 3) return -1;
143-
Wire.read();
144-
value = (Wire.read() & 0x0F) << 8;
161+
162+
uint32_t value = 0;
163+
value = Wire.read();
164+
value |= Wire.read();
145165
value |= Wire.read();
146-
return value;
166+
// MANUFACTURER
167+
if (field == 0) return (value >> 12) & 0xFF;
168+
// PRODUCT ID
169+
if (field == 1) return value & 0x0FFF;
170+
// DENSITY
171+
if (field == 2) return (value >> 8) & 0x0F;
172+
return 0;
147173
}
148174

149-
///////////////////////////////////////////////////////////
150-
//
151-
// PRIVATE
152-
//
153-
void FRAM::writeBlock(uint16_t memaddr, uint8_t * obj, uint16_t size)
175+
void FRAM::writeBlock(uint16_t memaddr, uint8_t * obj, uint8_t size)
154176
{
155177
// TODO constrain size < 30 ??
156178
Wire.beginTransmission(_address);
@@ -164,7 +186,7 @@ void FRAM::writeBlock(uint16_t memaddr, uint8_t * obj, uint16_t size)
164186
Wire.endTransmission();
165187
}
166188

167-
void FRAM::readBlock(uint16_t memaddr, uint8_t * obj, uint16_t size)
189+
void FRAM::readBlock(uint16_t memaddr, uint8_t * obj, uint8_t size)
168190
{
169191
Wire.beginTransmission(_address);
170192
Wire.write(memaddr >> 8);
@@ -178,4 +200,4 @@ void FRAM::readBlock(uint16_t memaddr, uint8_t * obj, uint16_t size)
178200
}
179201
}
180202

181-
// END OF FILE
203+
// -- END OF FILE --

libraries/FRAM/FRAM.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
#pragma once
12
//
23
// FILE: FRAM.h
34
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
5-
// PURPOSE: Class for FRAM memory
6-
// URL:
5+
// VERSION: 0.2.1
6+
// DATE: 2018-01-24
7+
// PURPOSE: Arduino library for I2C FRAM
8+
// URL: https://github.com/RobTillaart/FRAM_I2C
79
//
810
// HISTORY:
911
// see FRAM.cpp file
1012
//
1113

12-
#ifndef FRAM_H
13-
#define FRAM_H
14-
1514
#include "Arduino.h"
1615
#include "Wire.h"
1716

18-
#define FRAM_LIB_VERSION (F("0.1.1"))
17+
#define FRAM_LIB_VERSION (F("0.2.1"))
1918

2019
#define FRAM_OK 0
2120
#define FRAM_ERROR_ADDR -10
@@ -25,7 +24,8 @@ class FRAM
2524
public:
2625
FRAM();
2726

28-
int begin(const int address); // defaults to 0x50
27+
// writeProtectPin is optional
28+
int begin(const uint8_t address = 0x50, int8_t writeProtectPin = -1);
2929

3030
void write8(uint16_t memaddr, uint8_t value);
3131
void write16(uint16_t memaddr, uint16_t value);
@@ -37,18 +37,19 @@ class FRAM
3737
uint32_t read32(uint16_t memaddr);
3838
void read(uint16_t memaddr, uint8_t * obj, uint16_t size);
3939

40+
bool setWriteProtect(bool b);
41+
4042
uint16_t getManufacturerID();
4143
uint16_t getProductID();
42-
uint16_t getSize() { return _size; };
44+
uint16_t getSize();
4345

4446
private:
45-
int8_t _address;
46-
uint16_t _size; // unknown
47+
uint8_t _address;
48+
int8_t _writeProtectPin = -1; // default no pin ==> no write protect.
4749

48-
void writeBlock(uint16_t memaddr, uint8_t * obj, uint16_t size);
49-
void readBlock(uint16_t memaddr, uint8_t * obj, uint16_t size);
50+
uint16_t getMetaData(uint8_t id);
51+
void writeBlock(uint16_t memaddr, uint8_t * obj, uint8_t size);
52+
void readBlock(uint16_t memaddr, uint8_t * obj, uint8_t size);
5053
};
5154

52-
#endif
53-
54-
// END OF FILE
55+
// -- END OF FILE --

libraries/FRAM/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-2020 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/FRAM/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# FRAM_I2C
2+
3+
Arduino library for I2C FRAM
4+
5+
# Description
6+
7+
FRAM is a library to read and write (over I2C) to an FRAM module.
8+
FRAM is much faster than EEPROM and almost as fast as Arduino UNO RAM.
9+
Another imaportant feature is that FRAM keeps its content after a reboot (non-volatile)
10+
11+
Types of FRAM it should work with
12+
13+
| SIZE | TYPE |
14+
|:---:|:---:|
15+
| 8KB | MB85RC64T |
16+
| 32KB | MB85RC256V |
17+
| 64KB | MB85RC512T |
18+
| 128KB | MB85RC1MT |
19+
20+
21+
# Operational
22+
23+
See examples

libraries/FRAM/examples/testFRAM/testFRAM.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// AUTHOR: Rob Tillaart
44
// VERSION: 0.1.0
55
// PURPOSE: test for FRAM library for Arduino
6-
// URL:
6+
// URL: https://github.com/RobTillaart/FRAM_I2C
77
//
88
// Released to the public domain
99
//
@@ -171,7 +171,6 @@ void testReadWriteLarge()
171171
Serial.println();
172172
}
173173

174-
175174
void testWriteText()
176175
{
177176
char str[10][20] =

libraries/FRAM/examples/testFRAMPerformance/testFRAMPerformance.ino

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
// AUTHOR: Rob Tillaart
44
// VERSION: 0.1.0
55
// PURPOSE: test for FRAM library for Arduino
6-
// URL:
7-
//
8-
// Released to the public domain
6+
// URL: https://github.com/RobTillaart/FRAM_I2C
97
//
108

119
#include "FRAM.h"
@@ -15,6 +13,8 @@ FRAM fram;
1513
uint32_t start;
1614
uint32_t stop;
1715

16+
int ar[600];
17+
1818
void setup()
1919
{
2020
Serial.begin(115200);
@@ -55,30 +55,31 @@ void testReadWriteLarge()
5555
Serial.println();
5656
Serial.println(__FUNCTION__);
5757

58-
uint8_t ar[100];
59-
for (int i = 0; i < 100; i++) ar[i] = i;
58+
for (int i = 0; i < 600; i++) ar[i] = i;
6059

6160
start = millis();
62-
fram.write(1000, ar, 100);
61+
fram.write(1000, (uint8_t*)ar, 1200);
6362
stop = millis();
64-
Serial.print("WRITE 100 bytes TIME:\t");
63+
Serial.print("WRITE 1200 bytes TIME:\t");
6564
Serial.print(stop - start);
6665
Serial.println(" ms");
6766

68-
for (int i = 0; i < 100; i++) ar[i] = 0;
67+
for (int i = 0; i < 600; i++) ar[i] = 0;
6968

7069
start = millis();
71-
fram.read(1000, ar, 100);
70+
fram.read(1000, (uint8_t*)ar, 1200);
7271
stop = millis();
73-
Serial.print("READ 100 bytes TIME:\t");
72+
Serial.print("READ 1200 bytes TIME:\t");
7473
Serial.print(stop - start);
7574
Serial.println(" ms");
7675

77-
for (int i = 0; i < 100; i++)
76+
for (int i = 0; i < 600; i++)
7877
{
7978
if (ar[i] != i)
8079
{
8180
Serial.print("FAIL: \t");
81+
Serial.print(ar[i]);
82+
Serial.print('\t');
8283
Serial.println(i);
8384
}
8485
}

libraries/FRAM/keywords.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
#######################################
21
# Syntax Coloring Map for FRAM
3-
#######################################
42

5-
#######################################
63
# Datatypes (KEYWORD1)
7-
#######################################
8-
94
FRAM KEYWORD1
105

11-
#######################################
126
# Methods and Functions (KEYWORD2)
13-
#######################################
7+
begin KEYWORD2
8+
9+
write8 KEYWORD2
10+
write16 KEYWORD2
11+
write32 KEYWORD2
12+
write KEYWORD2
13+
14+
read8 KEYWORD2
15+
read16 KEYWORD2
16+
read32 KEYWORD2
17+
read KEYWORD2
1418

1519
getManufacturerID KEYWORD2
1620
getProductID KEYWORD2
21+
getSize KEYWORD2
1722

18-
#######################################
1923
# Constants (LITERAL1)
20-
#######################################
21-
22-
unknown LITERAL1
24+
FRAM_OK LITERAL1
25+
FRAM_ERROR_ADDR LITERAL1

0 commit comments

Comments
 (0)