This commit is contained in:
Martin Brodbeck 2024-02-06 22:11:58 +01:00
parent 1765ae4422
commit 6006fd39d7
4 changed files with 51 additions and 5 deletions

View file

@ -35,7 +35,6 @@ pico_enable_stdio_usb(pico_keyer 0)
# Add the standard library to the build # Add the standard library to the build
target_link_libraries(pico_keyer target_link_libraries(pico_keyer
hardware_flash
pico_stdlib) pico_stdlib)
# Add the standard include files to the build # Add the standard include files to the build
@ -46,6 +45,9 @@ target_include_directories(pico_keyer PRIVATE
# Add any user requested libraries # Add any user requested libraries
target_link_libraries(pico_keyer target_link_libraries(pico_keyer
hardware_flash
hardware_exception
pico_flash
) )
pico_add_extra_outputs(pico_keyer) pico_add_extra_outputs(pico_keyer)

View file

@ -1,15 +1,18 @@
#include <stdio.h> #include <stdio.h>
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "hardware/flash.h"
namespace { #include "settings.h"
static uint16_t PAGE_SIZE{256};
namespace
{
} }
int main() int main()
{ {
stdio_init_all(); stdio_init_all();
sleep_ms(1000);
puts("Hello, world!"); puts("Hello, world!");

19
settings.cpp Normal file
View file

@ -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);
}

22
settings.h Normal file
View file

@ -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