A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add and modify SPI eeprom lib
Geo8a09a3b54e36
diff --git a/lib/EEPROM_SPI_WE/.piopm b/lib/EEPROM_SPI_WE/.piopmnew file mode 100644index 00000000..3fda9c99--- /dev/null+++ b/lib/EEPROM_SPI_WE/.piopm@@ -0,0 +1 @@+{"type": "library", "name": "EEPROM_SPI_WE", "version": "1.1.5", "spec": {"owner": "wollewald", "id": 13697, "name": "EEPROM_SPI_WE", "requirements": null, "uri": null}}\ No newline at end of filediff --git a/lib/EEPROM_SPI_WE/LICENSE b/lib/EEPROM_SPI_WE/LICENSEnew file mode 100644index 00000000..8c5e394e--- /dev/null+++ b/lib/EEPROM_SPI_WE/LICENSE@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2022 Wolfgang (Wolle) Ewald++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.diff --git a/lib/EEPROM_SPI_WE/README.md b/lib/EEPROM_SPI_WE/README.mdnew file mode 100644index 00000000..7b0a07e9--- /dev/null+++ b/lib/EEPROM_SPI_WE/README.md@@ -0,0 +1,18 @@+# EEPROM_SPI_WE+Arduino library for SPI based EEPROMs++With this library you can write data to and read data from SPI based EEPROMs of the 25 series, including small EEPROMs like the 25LC0x0A or ST950x0 with x = 1,2,4,8. Although it uses page writing, you don't have to worry about the page limits. You can directly write bytes, integers, floats and arrays. Furthermore, I have implemented functions to read and write strings. I have adopted the method of handling different variable types for put() and get() from Sparkfun's great library <a href="https://github.com/sparkfun/SparkFun_External_EEPROM_Arduino_Library">SparkFun_External_EEPROM_Arduino_Library</a> for I2C EEPROMs.++I have implemented the protection options for the storage and and the status register.++The functions for erasing pages or sectors only work with the larger EEPROMs. Check the data sheet if you are not sure.++I have tested several EEPROMs (25LC512, 25A512, 25LC640, 25LC040A) using various MCU boards, such as the ESP32 development board, WEMOS D1 mini (ESP8266) and the Arduino Nano.++The library can now also deal with EEPROMs that use 24 bit addressing such as the 25CSM04. You need to set the memory size before accessing the EEPROM using the method `setMemorySize`. Note that this particular EEPROM25CSM04 does not support erase operations.++Here you find the detailed documentation:++https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)++https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)diff --git a/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_basic_read_write/EEPROM_SPI_WE_basic_read_write.ino b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_basic_read_write/EEPROM_SPI_WE_basic_read_write.inonew file mode 100644index 00000000..7d5ab366--- /dev/null+++ b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_basic_read_write/EEPROM_SPI_WE_basic_read_write.ino@@ -0,0 +1,106 @@+/*******************************************************************************+* This is an example sketch for the EEPROM_SPI_WE library+*+* It shows how to write data to and read data from the EEPROM.+*+* Written by Wolfgang (Wolle) Ewald.+*+* Here you find the detailed documentation:+* https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)+* https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)+*+********************************************************************************/++#include <SPI.h>+#include <EEPROM_SPI_WE.h>+const int csPin = 10; // Chip select pin+const int wpPin = 9; // Write protect pin (optional)++/* There are different options to create your EEPROM_SPI_WE object:+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin, spiClockSpeed); // e.g. uint32t spiClockSpeed = 4000000+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin, spiClockSpeed);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin);+ * If you don't define the wpPin and you connect it to GND or VCC,+ * then protectStatusRegister() is the only function that won't work.+ * Passing the SPI object allows you, for example, to use both SPI+ * interfaces on the ESP32.+ */+ EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);++void setup(){+ Serial.begin(9600);+ if(myEEP.init()){+ Serial.println("EEPROM connected");+ }+ else{+ Serial.println("EEPROM does not respond");+ while(1);+ }+ /* You can change the SPI clock speed also after you have created your+ * object. The default is 8 MHz. Check the data sheet which clock speed is+ * allowed. The frequency limit migh also depend on the voltage.+ */+ //myEEP.setSPIClockSpeed(4000000); // use AFTER init()!++ /* Select the page size of your EEPROM.+ * Choose EEPROM_PAGE_SIZE_xxx,+ * with xxx = 16, 32, 64, 128 or 256+ */+ myEEP.setPageSize(EEPROM_PAGE_SIZE_32);++ byte byteToWrite = 42;+ myEEP.write(10, byteToWrite); // write a byte to EEPROM address 10+ byte byteToRead = myEEP.read(10);+ Serial.print("Byte read: ");+ Serial.println(byteToRead);++ int intToWrite = -4242;+ int intToRead = 0;+ myEEP.put(10, intToWrite); // write an integer to EEPROM address 10+ myEEP.get(10, intToRead);+ Serial.print("Integer read: ");+ Serial.println(intToRead);++ float floatToWrite = 42.42;+ float floatToRead = 0.0;+ myEEP.put(10, floatToWrite);+ myEEP.get(10, floatToRead);+ Serial.print("Float read: ");+ Serial.println(floatToRead);++ char charArrayToWrite[] = "This is no poetry, I am just a simple char array";+ myEEP.put(110, charArrayToWrite); // write stringToWrite to address 110+ char charArrayToRead[60] = ""; // reserve sufficient space+ myEEP.get(110, charArrayToRead);+ Serial.print("Char array read: ");+ Serial.println(charArrayToRead);++ String stringToWrite = "Hello, I am a test string";+ unsigned int nextAddr = myEEP.putString(200, stringToWrite); // String objects need a different put function++ String stringToRead = "";+ myEEP.getString(200, stringToRead);+ Serial.print("String read: ");+ Serial.println(stringToRead);+ Serial.print("Next free address: ");+ Serial.println(nextAddr);++ int intArrayToWrite[20];+ int intArrayToRead[20];+ for(unsigned int i=0; i<(sizeof(intArrayToWrite)/sizeof(int)); i++){+ intArrayToWrite[i] = 10*i;+ }+ myEEP.put(250, intArrayToWrite);+ myEEP.get(250, intArrayToRead);+ for(unsigned int i=0; i<(sizeof(intArrayToRead)/sizeof(int)); i++){+ Serial.print("intArrayToRead[");+ Serial.print(i);+ Serial.print("]: ");+ Serial.println(intArrayToRead[i]);+ }+}++void loop(){}diff --git a/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_continuous_put/EEPROM_SPI_WE_continuous_put.ino b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_continuous_put/EEPROM_SPI_WE_continuous_put.inonew file mode 100644index 00000000..8487f87a--- /dev/null+++ b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_continuous_put/EEPROM_SPI_WE_continuous_put.ino@@ -0,0 +1,161 @@+/*******************************************************************************+* This is an example sketch for the EEPROM_SPI_WE library+*+* It shows how to write data continuously and how to use the hold pin.+*+* Written by Wolfgang (Wolle) Ewald.+*+* Here you find the detailed documentation:+* https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)+* https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)+*+********************************************************************************/++#include <SPI.h>+#include <EEPROM_SPI_WE.h>+const int csPin = 10; // Chip select pin+const int wpPin = 9; // Write protect pin (optional)+const int holdPin = 5; // Hold pin, pauses SPI transaction if LOW++/* There are different options to create your EEPROM_SPI_WE object:+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin, spiClockSpeed); // e.g. uint32t spiClockSpeed = 4000000+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin, spiClockSpeed);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin);+ * If you don't define the wpPin and you connect it to GND or VCC,+ * then protectStatusRegister() is the only function that won't work.+ * Passing the SPI object allows you, for example, to use both SPI+ * interfaces on the ESP32.+ */+EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);++void setup(){+ Serial.begin(9600);+ pinMode(holdPin,OUTPUT);+ digitalWrite(holdPin, HIGH);+ if(myEEP.init()){+ Serial.println("EEPROM connected");+ }+ else{+ Serial.println("EEPROM does not respond");+ while(1);+ }+ /* You can change the SPI clock speed also after you have created your+ * object. The default is 8 MHz. Check the data sheet which clock speed is+ * allowed. The frequency limit migh also depend on the voltage.+ */+ //myEEP.setSPIClockSpeed(4000000); // use AFTER init()!++ /* Select the page size of your EEPROM.+ * Choose EEPROM_PAGE_SIZE_xxx,+ * with xxx = 16, 32, 64, 128 or 256+ */+ myEEP.setPageSize(EEPROM_PAGE_SIZE_128);++ unsigned int address = 0;+ unsigned long writeDuration = 0;+ unsigned long startTime = millis();++ /* Conventional way of writing:+ * For each call of put() you have to wait the write cycle+ * time (~4 ms).+ */+ myEEP.put(125,0);+ myEEP.put(127, 1111);+ myEEP.put(129, 2222);+ myEEP.put(131, 3333);+ myEEP.put(133, 4444);+ myEEP.put(135, 5555);+ myEEP.put(137, 6666);+ myEEP.put(139, 7777);+ myEEP.put(141, 8888);+ myEEP.put(143, 9999);+ writeDuration = millis() - startTime;+ Serial.print("Time needed for discontinuous writing [ms]: ");+ Serial.println(writeDuration);++ /* Continuous writing:+ * You only need to wait the write cycle time when a page is+ * completed and when calling continuousPutDisable().+ * In this example the page is completed after writing to address 127.+ */+ address = 125;+ startTime = millis();+ myEEP.continuousPutEnable(address); // start address+ myEEP.continuousPut(9999);+ myEEP.continuousPut(8888);+ myEEP.continuousPut(7777);+ myEEP.continuousPut(6666);+ myEEP.continuousPut(5555);+ myEEP.continuousPut(4444);+ myEEP.continuousPut(3333);+ myEEP.continuousPut(2222);+ myEEP.continuousPut(1111);+ myEEP.continuousPut(0);+ myEEP.continuousPutDisable();+ writeDuration = millis() - startTime;++ Serial.print("Time needed for continuous writing incl. page change [ms]: ");+ Serial.println(writeDuration);+ /* Just to check that writing worked fine: */+ int intToRead;+ address = 125;+ for(unsigned int i=0; i<10; i++){+ myEEP.get(address, intToRead);+ address += sizeof(int);+ Serial.println(intToRead);+ }+++ /* Another continuous writing:+ * Here writing starts at address 0. If your page size is >= 32 you will write+ * everything into one page. So, only one write cycle waiting time is needed at+ * the end.+ */+ address = 0;+ startTime = millis();+ myEEP.continuousPutEnable(address);+ myEEP.continuousPut(0);+ myEEP.continuousPut(1111);+ myEEP.continuousPut(2222);+ myEEP.continuousPut(3333);+ myEEP.continuousPut(4444);+ myEEP.continuousPut(5555);+ myEEP.continuousPut(6666);+ myEEP.continuousPut(7777);+ myEEP.continuousPut(8888);+ myEEP.continuousPut(9999);+ myEEP.continuousPutDisable();+ writeDuration = millis() - startTime;+ Serial.print("Time needed for continuous writing without page change [ms]: ");+ Serial.println(writeDuration);++ /* The next example shows how to use the hold pin */+ address = 0;+ myEEP.continuousPutEnable(address);+ myEEP.continuousPut(999);+ myEEP.continuousPut(888);+ myEEP.continuousPut(777);+ myEEP.continuousPut(666);+ digitalWrite(holdPin,LOW);+ /* With the hold pin low you can now use the SPI lines to control other+ devices. The current SPI transaction with the EEPOM is just paused+ (CS pin is still LOW). After the hold Pin is back to HIGH you can continue+ the former transaction.+ */+ digitalWrite(holdPin,HIGH);+ myEEP.continuousPut(555);+ myEEP.continuousPut(444);+ myEEP.continuousPutDisable();+ /* Just to show that writing worked fine: */+ address = 0;+ for(unsigned int i=0; i<10; i++){+ myEEP.get(address, intToRead);+ address += sizeof(int);+ Serial.println(intToRead);+ }+}++void loop(){}diff --git a/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_erase/EEPROM_SPI_WE_erase.ino b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_erase/EEPROM_SPI_WE_erase.inonew file mode 100644index 00000000..00977839--- /dev/null+++ b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_erase/EEPROM_SPI_WE_erase.ino@@ -0,0 +1,100 @@+/******************************************************************************+* This is an example sketch for the EEPROM_SPI_WE library.+*+* Here you learn the different how to erase pages, sectors or the+* entire EEPROM.+*+* THESE FUNCTIONS ARE ONLY AVAILABLE ON BIGGER EEPROMS. Check the+* data sheet!+*+* Written by Wolfgang (Wolle) Ewald.+*+* Here you find the detailed documentation:+* https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)+* https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)+*+*******************************************************************************/++#include <SPI.h>+#include <EEPROM_SPI_WE.h>+const int csPin = 10; // Chip select pin+const int wpPin = 9; // Write protect pin (optional)++/* There are different options to create your EEPROM_SPI_WE object:+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin, spiClockSpeed); // e.g. uint32t spiClockSpeed = 4000000+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin, spiClockSpeed);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin);+ * If you don't define the wpPin and you connect it to GND or VCC,+ * then protectStatusRegister() is the only function that won't work.+ * Passing the SPI object allows you, for example, to use both SPI+ * interfaces on the ESP32.+ */+ EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);++void setup(){+ Serial.begin(9600);+ if(myEEP.init()){+ Serial.println("EEPROM connected");+ }+ else{+ Serial.println("EEPROM does not respond");+ while(1);+ }+ /* You can change the SPI clock speed also after you have created your+ * object. The default is 8 MHz. Check the data sheet which clock speed is+ * allowed. The frequency limit migh also depend on the voltage.+ */+ //myEEP.setSPIClockSpeed(4000000); // use AFTER init()!++ /* Select the page size of your EEPROM.+ * Choose EEPROM_PAGE_SIZE_xxx,+ * with xxx = 16, 32, 64, 128 or 256+ */+ myEEP.setPageSize(EEPROM_PAGE_SIZE_128);++ int testInt = 42;+ myEEP.put(10, testInt);+ myEEP.get(10, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("Erasing page....");+ myEEP.erasePage(3); // choose any address within the page you want to erase+ myEEP.get(10, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("");++ testInt = 42;+ myEEP.put(10, testInt);+ myEEP.get(10, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("Erasing sector....");+ myEEP.eraseSector(7); // choose any address within the sector you want to erase+ myEEP.get(10, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("");++ testInt = 42;+ myEEP.put(10, testInt);+ myEEP.get(10, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("Erasing complete EEPROM....");+ myEEP.eraseCompleteEEPROM();+ myEEP.get(10, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);++ Serial.print("testInt, MSB: ");+ Serial.println(myEEP.read(10), BIN);+ Serial.print("testInt, LSB: ");+ Serial.println(myEEP.read(11), BIN);+ Serial.println("Erasing means writing 0xFF to all addresses");+}++void loop(){}diff --git a/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_sleep_and_protect/EEPROM_SPI_WE_sleep_and_protect.ino b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_sleep_and_protect/EEPROM_SPI_WE_sleep_and_protect.inonew file mode 100644index 00000000..23b9e681--- /dev/null+++ b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_sleep_and_protect/EEPROM_SPI_WE_sleep_and_protect.ino@@ -0,0 +1,107 @@+/******************************************************************************+* This is an example sketch for the EEPROM_SPI_WE library.+*+* It shows how to apply the deep power down mode and different+* methods for write protection and protection of the status register.+*+* Written by Wolfgang (Wolle) Ewald.+*+* Here you find the detailed documentation:+* https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)+* https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)+*+*******************************************************************************/++#include <SPI.h>+#include <EEPROM_SPI_WE.h>+const int csPin = 10; // Chip select pin+const int wpPin = 9; // Write protect pin (needed for this sketch)++/* There are different options to create your EEPROM_SPI_WE object:+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin, spiClockSpeed); // e.g. uint32t spiClockSpeed = 4000000+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin, spiClockSpeed);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin);+ * If you don't define the wpPin and you connect it to GND or VCC,+ * then protectStatusRegister() is the only function that won't work.+ * Passing the SPI object allows you, for example, to use both SPI+ * interfaces on the ESP32.+ */+ EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);++void setup(){+ Serial.begin(9600);+ if(myEEP.init()){+ Serial.println("EEPROM connected");+ }+ else{+ Serial.println("EEPROM does not respond");+ while(1);+ }+ /* You can change the SPI clock speed also after you have created your+ * object. The default is 8 MHz. Check the data sheet which clock speed is+ * allowed. The frequency limit migh also depend on the voltage.+ */+ //myEEP.setSPIClockSpeed(4000000); // use AFTER init()!++ /* Select the page size of your EEPROM.+ * Choose EEPROM_PAGE_SIZE_xxx,+ * with xxx = 16, 32, 64, 128 or 256+ */+ myEEP.setPageSize(EEPROM_PAGE_SIZE_128);++ int testInt = 42;+ myEEP.put(50, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("Going in deep power down mode...");+ myEEP.deepPowerDown();+ Serial.println("Trying to read testInt... ");+ myEEP.get(50, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("Releasing from deep power down mode...");+ byte id = myEEP.powerUpAndReadID();+ Serial.print("testInt: ");+ myEEP.get(50, testInt);+ Serial.println(testInt);+ Serial.print("Device ID: 0x");+ Serial.println(id, HEX);+ Serial.println("");++/* You can write protect the device. The following options are available:+ * PROTECT_ALL Complete write protection;+ * PROTECT_UPPER_QUARTER Protect the upper quarter;+ * PROTECT_UPPER_HALF Protect the upper half;+ * PROTECT_NONE No write protection+ */+ myEEP.writeProtect(PROTECT_ALL);+ Serial.println("Protecting Device, trying to overwrite testInt...");+ myEEP.put(50, 4321);+ myEEP.writeProtect(PROTECT_NONE);+ Serial.print("testInt: ");+ myEEP.get(50, testInt);+ Serial.println(testInt);+ Serial.println("Protection removed, trying to overwrite testInt again...");+ myEEP.put(50, 4321);+ myEEP.get(50, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("");++ Serial.println("Protecting status register...");+ myEEP.protectStatusRegister(true); //protects the non-volatile bits of status register+ Serial.println("Trying to protect device...");+ myEEP.writeProtect(PROTECT_ALL);+ Serial.println("Now overwriting testInt...");+ myEEP.put(50, 1234);+ myEEP.get(50, testInt);+ Serial.print("testInt: ");+ Serial.println(testInt);+ Serial.println("Status register protection prevented changing the device protection!");+ myEEP.protectStatusRegister(false);+}++void loop(){}diff --git a/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_small_eeproms/EEPROM_SPI_WE_small_eeproms.ino b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_small_eeproms/EEPROM_SPI_WE_small_eeproms.inonew file mode 100644index 00000000..27912e33--- /dev/null+++ b/lib/EEPROM_SPI_WE/examples/EEPROM_SPI_WE_small_eeproms/EEPROM_SPI_WE_small_eeproms.ino@@ -0,0 +1,125 @@+/*******************************************************************************+* This is an example sketch for the EEPROM_SPI_WE library+*+* It shows how to use small EEPROMs of 128, 256, 512 or 1024 bytes. These types+* have typically a designation .....0x0y with x = 1, 2, 4 or 8, e.g. 25LC040A or+* ST95020.+*+* Be aware that small EEPROMs might not support all functions. If in doubt, check+* the data sheet.+*+* Written by Wolfgang (Wolle) Ewald.+*+* Here you find the detailed documentation:+* https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)+* https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)+*+********************************************************************************/++#include <SPI.h>+#include <EEPROM_SPI_WE.h>+const int csPin = 10; // Chip select pin+const int wpPin = 9; // Write protect pin (optional)++/* There are different options to create your EEPROM_SPI_WE object:+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin, spiClockSpeed); // e.g. uint32t spiClockSpeed = 4000000+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin, spiClockSpeed);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin, wpPin);+ * EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(&SPI, csPin);+ * If you don't define the wpPin and you connect it to GND or VCC,+ * then protectStatusRegister() is the only function that won't work.+ * Passing the SPI object allows you, for example, to use both SPI+ * interfaces on the ESP32.+ */+ EEPROM_SPI_WE myEEP = EEPROM_SPI_WE(csPin, wpPin);++void setup(){+ Serial.begin(9600);+ if(myEEP.init()){+ Serial.println("EEPROM connected");+ }+ else{+ Serial.println("EEPROM does not respond");+ while(1);+ }++ /* You can change the SPI clock speed also after you have created your+ * object. The default is 8 MHz. Check the data sheet which clock speed is+ * allowed. The frequency limit migh also depend on the voltage.+ */+ myEEP.setSPIClockSpeed(2000000); // use AFTER init()!++ /* Function to set small EEPROMs */+ myEEP.setSmallEEPROM();++ /* Select the page size of your EEPROM.+ * Choose EEPROM_PAGE_SIZE_xxx,+ * with xxx = 16, 32, 64, 128 or 256+ */+ myEEP.setPageSize(EEPROM_PAGE_SIZE_16);++ /* Small EEPROMs do not have an embedded instruction to erase+ * the complete chip. Therefore, the eraseCompleteEEPROM function will+ * override every byte with 0. For this, you need to specify the+ * EEPROM size in kbits. You can choose:+ * EEPROM_KBITS_x with x = 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 or 2048+ */+ // myEEP.setMemorySize(EEPROM_KBITS_2); // adjust and uncomment+ // Serial.print("Memory size in kbits: ");+ // Serial.println(myEEP.getMemorySize());+ // myEEP.eraseCompleteEEPROM();++ byte byteToWrite = 42;+ myEEP.write(10, byteToWrite); // write a byte to EEPROM address 10+ byte byteToRead = myEEP.read(10);+ Serial.print("Byte read: ");+ Serial.println(byteToRead);++ int intToWrite = -4242;+ int intToRead = 0;+ myEEP.put(10, intToWrite); // write an integer to EEPROM address 10+ myEEP.get(10, intToRead);+ Serial.print("Integer read: ");+ Serial.println(intToRead);++ float floatToWrite = 42.42;+ float floatToRead = 0.0;+ myEEP.put(10, floatToWrite);+ myEEP.get(10, floatToRead);+ Serial.print("Float read: ");+ Serial.println(floatToRead);++ char charArrayToWrite[] = "This is no poetry, I am just a simple char array";+ myEEP.put(10, charArrayToWrite); // write stringToWrite to address 10+ char charArrayToRead[60] = ""; // reserve sufficient space+ myEEP.get(10, charArrayToRead);+ Serial.print("Char array read: ");+ Serial.println(charArrayToRead);++ String stringToWrite = "Hello, I am a test string";+ unsigned int nextAddr = myEEP.putString(105, stringToWrite); // String objects need a different put function+ String stringToRead = "";+ myEEP.getString(105, stringToRead); // String objects need a different get function+ Serial.print("String read: ");+ Serial.println(stringToRead);+ Serial.print("Next free address: ");+ Serial.println(nextAddr);++ int intArrayToWrite[10];+ int intArrayToRead[10];+ for(unsigned int i=0; i<(sizeof(intArrayToWrite)/sizeof(int)); i++){+ intArrayToWrite[i] = 10*i;+ }+ myEEP.put(105, intArrayToWrite);+ myEEP.get(105, intArrayToRead);+ for(unsigned int i=0; i<(sizeof(intArrayToRead)/sizeof(int)); i++){+ Serial.print("intArrayToRead[");+ Serial.print(i);+ Serial.print("]: ");+ Serial.println(intArrayToRead[i]);+ }+}++void loop(){}diff --git a/lib/EEPROM_SPI_WE/keywords.txt b/lib/EEPROM_SPI_WE/keywords.txtnew file mode 100644index 00000000..6e8b96ab--- /dev/null+++ b/lib/EEPROM_SPI_WE/keywords.txt@@ -0,0 +1,70 @@+#######################################+# Syntax Coloring Map For EEPROM_SPI_WE+#######################################++#######################################+# Datatypes (KEYWORD1)+#######################################++EEPROM_SPI_WE KEYWORD1++# ENUM TYPES+eeprom_pageSize KEYWORD1+EEPROM_PAGE_SIZE KEYWORD1+eeprom_writeProtect KEYWORD1+EEPROM_WRITE_PROTECT KEYWORD1++#######################################+# Methods and Functions (KEYWORD2)+#######################################++init KEYWORD2+setPageSize KEYWORD2+setMemorySize KEYWORD2+getMemorySize KEYWORD2+deepPowerDown KEYWORD2+powerUpAndReadID KEYWORD2+erasePage KEYWORD2+eraseSector KEYWORD2+eraseCompleteEEPROM KEYWORD2+write KEYWORD2+read KEYWORD2+writeProtect KEYWORD2+protectStatusRegister KEYWORD2+get KEYWORD2+put KEYWORD2+isBusy KEYWORD2+eepromReadStatusReg KEYWORD2+setSPIClockSpeed KEYWORD2+continuousPutEnable KEYWORD2+continuousPut KEYWORD2+continuousPutDisable KEYWORD2+getString KEYWORD2+putString KEYWORD2+setSmallEEPROM KEYWORD2++#######################################+# Constants (LITERAL1)+#######################################++# ENUM VALUES+EEPROM_KBITS_2 LITERAL1+EEPROM_KBITS_4 LITERAL1+EEPROM_KBITS_8 LITERAL1+EEPROM_KBITS_16 LITERAL1+EEPROM_KBITS_32 LITERAL1+EEPROM_KBITS_64 LITERAL1+EEPROM_KBITS_128 LITERAL1+EEPROM_KBITS_256 LITERAL1+EEPROM_KBITS_512 LITERAL1+EEPROM_KBITS_1024 LITERAL1+EEPROM_KBITS_2048 LITERAL1+EEPROM_PAGE_SIZE_16 LITERAL1+EEPROM_PAGE_SIZE_32 LITERAL1+EEPROM_PAGE_SIZE_64 LITERAL1+EEPROM_PAGE_SIZE_128 LITERAL1+EEPROM_PAGE_SIZE_256 LITERAL1+PROTECT_NONE LITERAL1+PROTECT_UPPER_QUARTER LITERAL1+PROTECT_UPPER_HALF LITERAL1+PROTECT_ALL LITERAL1\ No newline at end of filediff --git a/lib/EEPROM_SPI_WE/library.properties b/lib/EEPROM_SPI_WE/library.propertiesnew file mode 100644index 00000000..d1811ef0--- /dev/null+++ b/lib/EEPROM_SPI_WE/library.properties@@ -0,0 +1,10 @@+name=EEPROM_SPI_WE+version=1.1.5+author=Wolfgang Ewald <[email protected]>+maintainer=Wolfgang Ewald <[email protected]>+sentence=Library for external SPI based EEPROMs+paragraph=With this library you can directly write various variable types to the EEPROM, including large arrays. Although it does page writing, you don't have to take care about the page limits. Tested on AVR-, ESP32- and ESP8266 Boards.+category=Data Storage+url=https://github.com/wollewald/EEPROM_SPI_WE+architectures=*+includes=EEPROM_SPI_WE.hdiff --git a/lib/EEPROM_SPI_WE/src/EEPROM_SPI_WE.cpp b/lib/EEPROM_SPI_WE/src/EEPROM_SPI_WE.cppnew file mode 100644index 00000000..82ddba93--- /dev/null+++ b/lib/EEPROM_SPI_WE/src/EEPROM_SPI_WE.cpp@@ -0,0 +1,385 @@+/*****************************************************************************+* This is a library for SPI EEPROMs like the 25LCxxx, 25Axxx, etc.+*+* In case you like it would be cool if you give it a star.+*+* If you find bugs, please inform me!+*+* Written by Wolfgang (Wolle) Ewald+*+* Here you find the detailed documentation:+* https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)+* https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)+*+*******************************************************************************/++#include "EEPROM_SPI_WE.h"++/************ Basic settings ************/++bool EEPROM_SPI_WE::init(uint8_t sckPin, uint8_t misoPin, uint8_t mosiPin, uint8_t cs, uint8_t wp) {+ csPin = cs;+ wpPin = wp;++ _spi->begin(sckPin, misoPin, mosiPin, csPin);+ mySPISettings = SPISettings(spiClock, MSBFIRST, SPI_MODE0);+ pinMode(csPin, OUTPUT);+ digitalWrite(csPin, HIGH);+ contAddr = 0;+ smallEEPROM = false;+ memSize = 0;++ if (wpPin != 999) {+ pinMode(wpPin, OUTPUT);+ digitalWrite(wpPin, HIGH);+ }++ pageSize = 16;+ writeProtect(PROTECT_NONE);+ eepromWriteStatusReg(EEP_WREN);++ if (eepromReadStatusReg() & 0x02) {+ eepromWriteStatusReg(EEP_WRDI);+ return true;+ } else {+ return false;+ }+}++void EEPROM_SPI_WE::setPageSize(eeprom_pageSize eps){+ pageSize = 16 << eps;+}++void EEPROM_SPI_WE::setMemorySize(eeprom_size_t size){+ memSize = size;+}++uint32_t EEPROM_SPI_WE::getMemorySize(){+ return memSize;+}++void EEPROM_SPI_WE::deepPowerDown(){+ eepromWriteStatusReg(EEP_DPD);+}++uint8_t EEPROM_SPI_WE::powerUpAndReadID(){+ uint8_t id = 0;+ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ _spi->transfer(EEP_RDID);+ _spi->transfer(0xFF); // dummy address+ _spi->transfer(0xFF);+ id = _spi->transfer(0x00);+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();+ while(isBusy()){}+ return id;+}++/************ read and write ************/++void EEPROM_SPI_WE::erasePage(uint32_t addr){+ eepromWriteEnable();++ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ _spi->transfer(EEP_PE);+ if (memSize > EEPROM_KBITS_512) {+ _spi->transfer(static_cast<uint8_t>(addr>>16));+ }+ _spi->transfer(static_cast<uint8_t>(addr>>8));+ _spi->transfer(static_cast<uint8_t>(addr&0xFF));+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();++ while(isBusy()){}+}++void EEPROM_SPI_WE::eraseSector(uint32_t addr){+ eepromWriteEnable();++ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ _spi->transfer(EEP_SE);+ if (memSize > EEPROM_KBITS_512) {+ _spi->transfer(static_cast<uint8_t>(addr>>16));+ }+ _spi->transfer(static_cast<uint8_t>(addr>>8));+ _spi->transfer(static_cast<uint8_t>(addr&0xFF));+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();++ while(isBusy()){}+}++void EEPROM_SPI_WE::eraseCompleteEEPROM(){+ if (smallEEPROM){+ //No EEP_CE instruction set available on small eeproms+ for (uint32_t i = 0; i < memSize; i++) {+ write(i, 0);+ }+ } else {+ eepromWriteEnable();+ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ _spi->transfer(EEP_CE);+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();+ while(isBusy()){}+ }+}++void EEPROM_SPI_WE::write(uint32_t addr, uint8_t val){+ if (read(addr) != val)+ writeEEPROM(addr, &val, 1);+ while(isBusy()){}+}++uint8_t EEPROM_SPI_WE::read(uint32_t addr){+ uint8_t byteVal;+ readEEPROM(addr, &byteVal, 1);+ return byteVal;+}++void EEPROM_SPI_WE::writeProtect(eeprom_writeProtect sectors){+ eepromWriteEnable();++ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ _spi->transfer(EEP_WRSR);+ _spi->transfer((sectors << 2) | 0x80);+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();+ while(isBusy()){}+}++void EEPROM_SPI_WE::protectStatusRegister(bool protect){+ uint8_t statusReg = eepromReadStatusReg();+ if(!protect && (wpPin != 999)){+ digitalWrite(wpPin, HIGH);+ }+ else if(protect && (wpPin != 999)){+ statusReg |= 0x80;+ eepromWriteEnable();+ eepromWriteStatusReg(statusReg);+ digitalWrite(wpPin, LOW);+ }+}++uint32_t EEPROM_SPI_WE::putString(uint32_t addr, String &strToWrite){+ int strLen = strToWrite.length() + 1;+ writeEEPROM(addr, (uint8_t*)strToWrite.c_str(), strLen);+ return addr + strLen;+}++void EEPROM_SPI_WE::getString(uint32_t addr, String &strToRead){+ if(strToRead.length()){+ strToRead.remove(0,strToRead.length());+ }+ uint8_t tmp = 65; // dummy+ uint8_t *tmpPtr;+ tmpPtr = &tmp;+ while(tmp != 0){+ readEEPROM(addr, tmpPtr, 1);+ if(tmp != 0){+ strToRead += static_cast<char>(tmp);+ }+ addr++;+ }+}++uint8_t EEPROM_SPI_WE::eepromReadStatusReg(){+ uint8_t statusReg = 0;++ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ _spi->transfer(EEP_RDSR);+ statusReg = _spi->transfer(0x00);+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();++ return statusReg;+}++bool EEPROM_SPI_WE::isBusy(){+ delayMicroseconds(50);+ uint8_t statusReg = eepromReadStatusReg();+ return (statusReg & 0x01);+}++void EEPROM_SPI_WE::setSPIClockSpeed(unsigned long clock){+ mySPISettings = SPISettings(clock, MSBFIRST, SPI_MODE0);+}++void EEPROM_SPI_WE::setSmallEEPROM(){+ smallEEPROM = true;+}++/************************************************+ Private Functions+*************************************************/++void EEPROM_SPI_WE::eepromWriteEnable(){+ eepromWriteStatusReg(EEP_WREN);+}++void EEPROM_SPI_WE::eepromWriteStatusReg(uint8_t cmd){+ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ _spi->transfer(cmd);+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();++ while(isBusy()){}+}++void EEPROM_SPI_WE::writeEEPROM(uint32_t addr, const uint8_t *buf, uint16_t sizeOfBuf){+ uint16_t noOfBytesStillToWrite = sizeOfBuf;+ uint16_t arrayIndex = 0;++ while((noOfBytesStillToWrite != 0)){+ uint16_t chunk = noOfBytesStillToWrite;+ uint16_t positionInPage = addr % pageSize;+ uint16_t spaceLeftInPage = pageSize - positionInPage;++ if(spaceLeftInPage < noOfBytesStillToWrite){+ chunk = spaceLeftInPage;+ }++ eepromWriteEnable();++ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ if(!smallEEPROM){+ _spi->transfer(EEP_WRITE);+ if (memSize > EEPROM_KBITS_512) {+ _spi->transfer(static_cast<uint8_t>(addr>>16));+ }+ _spi->transfer(static_cast<uint8_t>(addr>>8));+ _spi->transfer(static_cast<uint8_t>(addr&0xFF));+ }+ else{+ if(addr>>8){+ if(addr>>9){+ _spi->transfer(EEP_READ | EEP_A8 | EEP_A9);+ }+ else{+ _spi->transfer(EEP_READ | EEP_A8);+ }+ }+ else {+ _spi->transfer(EEP_WRITE);+ }+ _spi->transfer(static_cast<uint8_t>(addr));+ }++ for(uint16_t i=arrayIndex; i<(arrayIndex + chunk); i++){+ _spi->transfer(static_cast<uint8_t>(buf[i]));+ }++ digitalWrite(csPin, HIGH);+ _spi->endTransaction();++ addr += chunk;+ arrayIndex += chunk;+ noOfBytesStillToWrite -= chunk;+ while(isBusy()){}+ }+}++void EEPROM_SPI_WE::continuousPutEnable(uint32_t addr){+ contAddr = addr;+ eepromWriteEnable();+ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ if(!smallEEPROM){+ _spi->transfer(EEP_WRITE);+ if (memSize > EEPROM_KBITS_512) {+ _spi->transfer(static_cast<uint8_t>(addr>>16));+ }+ _spi->transfer(static_cast<uint8_t>(addr>>8));+ _spi->transfer(static_cast<uint8_t>(addr&0xFF));+ }+ else{+ if(addr>>8){+ _spi->transfer(EEP_WRITE | EEP_A8);+ }+ else {+ _spi->transfer(EEP_WRITE);+ }+ _spi->transfer(static_cast<uint8_t>(addr));+ }+}++void EEPROM_SPI_WE::continuousPutDisable(){+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();+ while(isBusy());+}++void EEPROM_SPI_WE::continuousWriteEEPROM(const uint8_t *buf, uint16_t sizeOfBuf){+ uint16_t noOfBytesStillToWrite = sizeOfBuf;+ uint16_t arrayIndex = 0;++ while((noOfBytesStillToWrite != 0)){+ uint16_t chunk = noOfBytesStillToWrite;+ uint16_t positionInPage = contAddr % pageSize;+ uint16_t spaceLeftInPage = pageSize - positionInPage;+ bool pageEnd = false;++ if(spaceLeftInPage < noOfBytesStillToWrite){+ chunk = spaceLeftInPage;+ pageEnd = true;+ }++ for(uint16_t i=arrayIndex; i<(arrayIndex + chunk); i++){+ _spi->transfer(static_cast<uint8_t>(buf[i]));+ }++ contAddr += chunk;+ arrayIndex += chunk;+ noOfBytesStillToWrite -= chunk;+ if(pageEnd){+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();+ while(isBusy()){}+ continuousPutEnable(contAddr);+ pageEnd = false;+ }+ }+}++void EEPROM_SPI_WE::readEEPROM(uint32_t addr, uint8_t *buf, uint16_t sizeOfBuf){+ _spi->beginTransaction(mySPISettings);+ digitalWrite(csPin, LOW);+ if(!smallEEPROM){+ _spi->transfer(EEP_READ);+ if (memSize > EEPROM_KBITS_512) {+ _spi->transfer(static_cast<uint8_t>(addr>>16));+ }+ _spi->transfer(static_cast<uint8_t>(addr>>8));+ _spi->transfer(static_cast<uint8_t>(addr&0xFF));+ }+ else{+ if(addr>>8){+ if(addr>>9){+ _spi->transfer(EEP_READ | EEP_A8 | EEP_A9);+ }+ else{+ _spi->transfer(EEP_READ | EEP_A8);+ }+ }+ else {+ _spi->transfer(EEP_READ);+ }+ _spi->transfer(static_cast<uint8_t>(addr));+ }+ for(uint16_t i=0; i<sizeOfBuf; i++){+ buf[i] = _spi->transfer(0x00);+ }+ digitalWrite(csPin, HIGH);+ _spi->endTransaction();+}+++diff --git a/lib/EEPROM_SPI_WE/src/EEPROM_SPI_WE.h b/lib/EEPROM_SPI_WE/src/EEPROM_SPI_WE.hnew file mode 100644index 00000000..62e0740f--- /dev/null+++ b/lib/EEPROM_SPI_WE/src/EEPROM_SPI_WE.h@@ -0,0 +1,136 @@+/******************************************************************************+* This is a library for SPI EEPROMs like the 25LCxxx, 25Axxx, etc.+*+* In case you like it would be cool if you give it a star.+*+* If you find bugs, please inform me!+*+* Written by Wolfgang (Wolle) Ewald+*+* Here you find the detailed documentation:+* https://wolles-elektronikkiste.de/en/eeprom-part-3-external-spi-eeproms (English)+* https://wolles-elektronikkiste.de/eeprom-teil-3-externe-spi-eeproms (German)+*+********************************************************************************/++#ifndef EEPROM_SPI_WE_H_+#define EEPROM_SPI_WE_H_++#if ARDUINO < 100+#include <WProgram.h>+#else+#include <Arduino.h>+#endif++#include <SPI.h>++typedef enum EEPROM_WE_PAGE_SIZE {+ EEPROM_PAGE_SIZE_16, EEPROM_PAGE_SIZE_32, EEPROM_PAGE_SIZE_64, EEPROM_PAGE_SIZE_128, EEPROM_PAGE_SIZE_256+} eeprom_pageSize;++typedef enum EEPROM_WE_WRITE_PROTECT {+ PROTECT_NONE, PROTECT_UPPER_QUARTER, PROTECT_UPPER_HALF, PROTECT_ALL+} eeprom_writeProtect;++enum eeprom_size_t {+ EEPROM_KBITS_2 = 256,+ EEPROM_KBITS_4 = 512,+ EEPROM_KBITS_8 = 1024,+ EEPROM_KBITS_16 = 2028,+ EEPROM_KBITS_32 = 4096,+ EEPROM_KBITS_64 = 8192,+ EEPROM_KBITS_128 = 16384,+ EEPROM_KBITS_256 = 32768,+ EEPROM_KBITS_512 = 65536,+ EEPROM_KBITS_1024 = 131072,+ EEPROM_KBITS_2048 = 262144,+ EEPROM_KBITS_4096 = 524288,+};++class EEPROM_SPI_WE+{+ public:+ static constexpr uint8_t EEP_READ {0x03}; // write+ static constexpr uint8_t EEP_WRITE{0x02}; // read+ static constexpr uint8_t EEP_WREN {0x06}; // write enable+ static constexpr uint8_t EEP_WRDI {0x04}; // write disable+ static constexpr uint8_t EEP_RDSR {0x05}; // read status register+ static constexpr uint8_t EEP_WRSR {0x01}; // write status register+ static constexpr uint8_t EEP_PE {0x42}; // page erase+ static constexpr uint8_t EEP_SE {0xD8}; // sector erase+ static constexpr uint8_t EEP_CE {0xC7}; // chip erase+ static constexpr uint8_t EEP_RDID {0xAB}; // release from deep power down and read electronic signature+ static constexpr uint8_t EEP_DPD {0xB9}; // deep power down mode+ static constexpr uint8_t EEP_A8 {0x08}; // A8 address bit for small EEPROMs+ static constexpr uint8_t EEP_A9 {0x10}; // A9 address bit for small EEPROMs++ EEPROM_SPI_WE(uint16_t cs, uint16_t wp = 999, uint32_t sc = 8000000) : _spi{&SPI}, csPin{cs}, wpPin{wp}, spiClock{sc} {}+ EEPROM_SPI_WE(SPIClass *s, uint16_t cs, uint16_t wp = 999, uint32_t sc = 8000000) : _spi{s}, csPin{cs}, wpPin{wp}, spiClock{sc} {}+ EEPROM_SPI_WE() : _spi{&SPI}, csPin{255}, wpPin{999}, spiClock{8000000} {}+ bool init(uint8_t sckPin, uint8_t misoPin, uint8_t mosiPin, uint8_t cs, uint8_t wp);+ uint32_t getMemorySize(); //neu+ void setPageSize(eeprom_pageSize eps);+ void setMemorySize(eeprom_size_t size); // neu+ void deepPowerDown();+ uint8_t powerUpAndReadID();+ void erasePage(uint32_t addr);+ void eraseSector(uint32_t addr);+ void eraseCompleteEEPROM();+ void write(uint32_t addr, uint8_t val);+ uint8_t read(uint32_t addr);+ void writeProtect(eeprom_writeProtect sectors);+ void protectStatusRegister(bool protect = true);++ template <typename T>+ T &get(uint32_t addr, T &t){+ uint8_t *data = (uint8_t *)&t;+ readEEPROM(addr, data, sizeof(T));+ return t;+ }++ template <typename T>+ const T &put(uint32_t addr, const T &t){+ const uint8_t *data = (const uint8_t *)&t;+ writeEEPROM(addr, data, sizeof(T));+ return t;+ }++ uint32_t putString(uint32_t addr, String &strToWrite);+ void getString(uint32_t addr, String &strToRead);++ void continuousPutEnable(uint32_t addr);+ void continuousPutDisable();++ template <typename T>+ const T &continuousPut(const T &t){+ const uint8_t *data = (const uint8_t *)&t;+ continuousWriteEEPROM(data, sizeof(T));+ return t;+ }++ bool isBusy();+ uint8_t eepromReadStatusReg();+ void setSPIClockSpeed(unsigned long clock);+ void setSmallEEPROM();++ protected:+ SPIClass *_spi;+ SPISettings mySPISettings;+ uint16_t csPin;+ uint16_t wpPin;+ uint32_t spiClock;+ uint16_t pageSize;+ uint32_t contAddr;+ bool smallEEPROM;+ uint32_t memSize;++ void eepromWriteEnable();+ void eepromWriteStatusReg(uint8_t cmd);+ void writeEEPROM(uint32_t addr, const uint8_t *buf, uint16_t sizeOfBuf);+ void continuousWriteEEPROM(const uint8_t *buf, uint16_t sizeOfBuf);+ void readEEPROM(uint32_t addr, uint8_t *buf, uint16_t sizeOfBuf);+};++#endif++