code beautifying
This commit is contained in:
parent
9a07c24d8f
commit
08885a3aac
8 changed files with 292 additions and 113 deletions
|
@ -6,14 +6,14 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
constexpr const uint32_t FLASH_TARGET_OFFSET = PICO_FLASH_SIZE_BYTES - FLASH_SECTOR_SIZE;
|
||||
const uint8_t *flash_target_contents = (const uint8_t *)(XIP_BASE + FLASH_TARGET_OFFSET);
|
||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||
}
|
||||
constexpr const uint32_t FLASH_TARGET_OFFSET = PICO_FLASH_SIZE_BYTES - FLASH_SECTOR_SIZE;
|
||||
const uint8_t *flash_target_contents = (const uint8_t *)(XIP_BASE + FLASH_TARGET_OFFSET);
|
||||
const uint LED_PIN = PICO_DEFAULT_LED_PIN;
|
||||
} // namespace
|
||||
|
||||
void flash_store_callback(void *settings)
|
||||
{
|
||||
//int writeSize = (sizeof(struct Settings) / FLASH_PAGE_SIZE) + 1;
|
||||
// int writeSize = (sizeof(struct Settings) / FLASH_PAGE_SIZE) + 1;
|
||||
|
||||
flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE);
|
||||
flash_range_program(FLASH_TARGET_OFFSET, (uint8_t *)settings, FLASH_PAGE_SIZE);
|
||||
|
@ -24,8 +24,7 @@ void store_settings(Settings &settings)
|
|||
uint8_t *settingsAsBytes = (uint8_t *)&settings;
|
||||
|
||||
int result = flash_safe_execute(flash_store_callback, settingsAsBytes, 1000);
|
||||
if (result == PICO_OK)
|
||||
{
|
||||
if (result == PICO_OK) {
|
||||
gpio_put(LED_PIN, 1);
|
||||
sleep_ms(250);
|
||||
gpio_put(LED_PIN, 0);
|
||||
|
@ -47,8 +46,7 @@ Settings read_settings()
|
|||
|
||||
memcpy(&settings, flash_target_contents, sizeof(struct Settings));
|
||||
|
||||
if (settings.magic_number != MAGIC_NUMBER)
|
||||
{
|
||||
if (settings.magic_number != MAGIC_NUMBER) {
|
||||
settings = Settings();
|
||||
|
||||
gpio_put(LED_PIN, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue