From 6006fd39d7aab31ede4a1157c4ddb1dd91443c8c Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 6 Feb 2024 22:11:58 +0100 Subject: [PATCH] WIP --- CMakeLists.txt | 6 ++++-- pico_keyer.cpp | 9 ++++++--- settings.cpp | 19 +++++++++++++++++++ settings.h | 22 ++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 settings.cpp create mode 100644 settings.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ddc800..9afff99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ pico_enable_stdio_usb(pico_keyer 0) # Add the standard library to the build target_link_libraries(pico_keyer - hardware_flash pico_stdlib) # Add the standard include files to the build @@ -46,7 +45,10 @@ target_include_directories(pico_keyer PRIVATE # Add any user requested libraries target_link_libraries(pico_keyer - ) + hardware_flash + hardware_exception + pico_flash +) pico_add_extra_outputs(pico_keyer) diff --git a/pico_keyer.cpp b/pico_keyer.cpp index 7ee3990..ae63bde 100644 --- a/pico_keyer.cpp +++ b/pico_keyer.cpp @@ -1,15 +1,18 @@ #include #include "pico/stdlib.h" -#include "hardware/flash.h" -namespace { - static uint16_t PAGE_SIZE{256}; +#include "settings.h" + +namespace +{ + } int main() { stdio_init_all(); + sleep_ms(1000); puts("Hello, world!"); diff --git a/settings.cpp b/settings.cpp new file mode 100644 index 0000000..ee492c8 --- /dev/null +++ b/settings.cpp @@ -0,0 +1,19 @@ +#include "settings.h" + +namespace +{ + const size_t PAGE_SIZE{256}; + const size_t NVS_SIZE{4096}; + const uint32_t FLASH_WRITE_START = PICO_FLASH_SIZE_BYTES - NVS_SIZE; +} + +void flash_store_callback(void *settings) +{ + flash_range_erase(FLASH_WRITE_START, NVS_SIZE); + flash_range_program(FLASH_WRITE_START, (const uint8_t *)settings, PAGE_SIZE); +} + +void store_settings(Settings &settings) +{ + flash_safe_execute(flash_store_callback, (void *)&settings, 1000); +} \ No newline at end of file diff --git a/settings.h b/settings.h new file mode 100644 index 0000000..e52417a --- /dev/null +++ b/settings.h @@ -0,0 +1,22 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include "pico/flash.h" + +enum class Mode +{ + IAMBIC_A, + IAMBIC_B, + // ULTIMATE +}; + +struct Settings +{ + Mode mode{Mode::IAMBIC_B}; +}; + +void store_settings(Settings &settings); + + + +#endif \ No newline at end of file