Skip to content

Commit

Permalink
refactor: Flash.h
Browse files Browse the repository at this point in the history
Signed-off-by: noteolvides <[email protected]>
  • Loading branch information
Noteolvides committed Oct 3, 2023
1 parent 4c92651 commit b36b568
Showing 1 changed file with 1 addition and 57 deletions.
58 changes: 1 addition & 57 deletions src/kaleidoscope/driver/storage/Flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,62 +25,6 @@

#pragma once

#if defined(ARDUINO_SAMD_RAISE)

#include "kaleidoscope/driver/storage/Base.h"
#include <FlashStorage.h>
#include <FlashAsEEPROM.h>

// We need to undefine Flash, because `FlashStorage` defines it as a macro, yet,
// we want to use it as a class name.
#ifdef Flash
#undef Flash
#endif

namespace kaleidoscope {
namespace driver {
namespace storage {

struct FlashProps : kaleidoscope::driver::storage::BaseProps {
static constexpr uint16_t length = EEPROM_EMULATION_SIZE;
};

template <typename _StorageProps>
class Flash: public kaleidoscope::driver::storage::Base<_StorageProps> {
public:
template<typename T>
T& get(uint16_t offset, T& t) {
return EEPROM.get(offset, t);
}

template<typename T>
const T& put(uint16_t offset, T& t) {
EEPROM.put(offset, t);
}

uint8_t read(int idx) {
return EEPROM.read(idx);
}

void write(int idx, uint8_t val) {
EEPROM.write(idx, val);
}

void update(int idx, uint8_t val) {
EEPROM.update(idx, val);
}

void commit() {
EEPROM.commit();
}
};

}
}
}

#elif defined(ARDUINO_RASPBERRY_PI_PICO) // ARDUINO_RASPBERRY_PI_PICO

#include "kaleidoscope/driver/storage/Base.h"
#include "EEPROM.h" // EEPROM library for RP2040: libraries/EEPROM/EEPROM.h

Expand Down Expand Up @@ -138,4 +82,4 @@ class Flash: public kaleidoscope::driver::storage::Base<_StorageProps> {
}
}

#endif

0 comments on commit b36b568

Please sign in to comment.