123456789101112131415161718192021222324252627282930313233343536373839 |
- #include <string.h>
- #include "settings.h"
- #include "flash.h"
- #define RAM_SETTINGS (0x20012000)
- #define FLASH_SETTINGS (0x0E0000)
- #define SETTINGS_PART_SIZE (0x20000) /* 128 KB */
- struct settings *Settings = (struct settings *)(RAM_SETTINGS);
- void settings_save(void)
- {
- flash_unlock();
- flash_erase(FLASH_SETTINGS, SETTINGS_PART_SIZE);
- flash_write(FLASH_SETTINGS, (const void *)(RAM_SETTINGS), sizeof(struct settings));
- flash_lock();
- }
- static void restore_defaults(void)
- {
- memset(Settings, 0, sizeof(struct settings));
- Settings->storage_hdr = STORAGE_HDR;
- Settings->bpm = 125;
- settings_save();
- }
- void settings_load(void)
- {
- struct settings *s = (struct settings *)FLASH_SETTINGS;
- if (s->storage_hdr != STORAGE_HDR) {
- restore_defaults();
- return;
- }
- memcpy((void *)RAM_SETTINGS, (const void *)FLASH_SETTINGS, sizeof(struct settings));
- }
|