diff --git a/src/kaleidoscope/driver/storage/Flash.h b/src/kaleidoscope/driver/storage/Flash.h new file mode 100644 index 00000000..a8dc0617 --- /dev/null +++ b/src/kaleidoscope/driver/storage/Flash.h @@ -0,0 +1,80 @@ +/* -*- mode: c++ -*- + * kaleidoscope::driver::storage::Flash -- Storage driver with Flash backend + * Copyright (C) 2019 Keyboard.io, Inc + * Copyright (C) 2019 Dygma Lab S.L. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +/* + * TODO(algernon): This currently uses , making the Props + * struct fairly useless. At some point, we need to figure out a way to do this + * without EEPROM API emulation, and by having the flash data variable somewhere + * within the `storage::Flash` class. + */ + +#pragma once + +#ifdef __SAMD21G18A__ + +#include "kaleidoscope/driver/storage/Base.h" +#include +#include + +// We need to undefine Flash, because `FlashStorage` defines it as a macro, yet, +// we want to use it as a class name. +#undef Flash + +namespace kaleidoscope { +namespace driver { +namespace storage { + +struct FlashProps : kaleidoscope::driver::storage::BaseProps { + static constexpr uint16_t length = EEPROM_EMULATION_SIZE; +}; + +template +class Flash: public kaleidoscope::driver::storage::Base<_StorageProps> { + public: + template + T& get(uint16_t offset, T& t) { + return EEPROM.get(offset, t); + } + + template + 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(); + } +}; + +} +} +} + +#endif