EEPROM_store.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* this is the eeprom abstraction for the microbit v2.
  2. * the eeprom will be mapped to a simple file in the file system, later.
  3. */
  4. #ifdef _MICROBIT_V2_
  5. const int STORESIZE = 256;
  6. byte program[STORESIZE];
  7. bool loaded = false;
  8. void load() {
  9. loaded = true;
  10. }
  11. byte readbyte(int addr) {
  12. if (!loaded) {
  13. load();
  14. }
  15. if ((addr >=0) && (addr < STORESIZE)) {
  16. return program[addr];
  17. }
  18. return 0xFF;
  19. }
  20. void writebyte(int addr, byte value) {
  21. if ((addr >=0) && (addr < STORESIZE)) {
  22. program[addr] = value;
  23. }
  24. }
  25. void store() {
  26. }
  27. #endif
  28. #ifdef ESP32
  29. #include <EEPROM.h>
  30. const int STORESIZE = 1024;
  31. byte program[STORESIZE];
  32. bool loaded = false;
  33. void load() {
  34. EEPROM.begin(STORESIZE);
  35. EEPROM.readBytes(0, program, STORESIZE);
  36. loaded = true;
  37. }
  38. byte readbyte(int addr) {
  39. if (!loaded) {
  40. load();
  41. }
  42. if ((addr >=0) && (addr < STORESIZE)) {
  43. return program[addr];
  44. }
  45. return 0xFF;
  46. }
  47. void writebyte(int addr, byte value) {
  48. if ((addr >=0) && (addr < STORESIZE)) {
  49. program[addr] = value;
  50. }
  51. }
  52. void store() {
  53. EEPROM.writeBytes(0, program, STORESIZE);
  54. }
  55. #endif
  56. #if defined(__AVR_ATmega328P__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny861__) || defined(__AVR_ATtiny4313__)
  57. #include <EEPROM.h>
  58. #include <avr/eeprom.h>
  59. const int STORESIZE = E2END;
  60. byte readbyte(int addr) {
  61. return EEPROM.read(addr);
  62. }
  63. void writebyte(int addr, byte value) {
  64. EEPROM.write(addr, value);
  65. }
  66. void store() {
  67. }
  68. #endif