From cc8bffcf1d4a7405a9e9cbae21578e571cff807d Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Tue, 3 Dec 2024 20:46:33 +0800 Subject: [PATCH] add factory reset cmd --- EPD/EPD_ble.c | 20 +++++++++++++++++--- EPD/EPD_ble.h | 1 + html/index.html | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/EPD/EPD_ble.c b/EPD/EPD_ble.c index b2ef464..33dd034 100644 --- a/EPD/EPD_ble.c +++ b/EPD/EPD_ble.c @@ -63,11 +63,15 @@ static uint32_t epd_config_load(epd_config_t *cfg) return pstorage_load((uint8_t *)cfg, &m_flash_handle, sizeof(epd_config_t), 0); } +static uint32_t epd_config_clear(epd_config_t *cfg) +{ + return pstorage_clear(&m_flash_handle, sizeof(epd_config_t)); +} + static uint32_t epd_config_save(epd_config_t *cfg) { - uint32_t err_code; - err_code = pstorage_clear(&m_flash_handle, sizeof(epd_config_t)); - if (err_code != NRF_SUCCESS) + uint32_t err_code; + if ((err_code = epd_config_clear(cfg)) != NRF_SUCCESS) { return err_code; } @@ -192,6 +196,11 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le ble_epd_sleep_prepare(p_epd); sd_power_system_off(); break; + + case EPD_CMD_CFG_ERASE: + epd_config_clear(&p_epd->config); + NVIC_SystemReset(); + break; default: break; @@ -357,6 +366,11 @@ static void epd_config_init(ble_epd_t * p_epd) p_epd->config.driver_id = p_epd->driver->id; save_config = true; } + if (p_epd->config.wakeup_pin == 0xFF) + { + p_epd->config.wakeup_pin = 7; + save_config = true; + } if (save_config) { epd_config_save(&p_epd->config); diff --git a/EPD/EPD_ble.h b/EPD/EPD_ble.h index c24282d..55d318f 100644 --- a/EPD/EPD_ble.h +++ b/EPD/EPD_ble.h @@ -54,6 +54,7 @@ enum EPD_CMDS EPD_CMD_SET_CONFIG = 0x90, /**< set full EPD config */ EPD_CMD_SYS_RESET = 0x91, /**< MCU reset */ EPD_CMD_SYS_SLEEP = 0x92, /**< MCU enter sleep mode */ + EPD_CMD_CFG_ERASE = 0x99, /**< Erase config and reset */ }; /**< EPD driver IDs. */ diff --git a/html/index.html b/html/index.html index 27fbb74..6d75d20 100644 --- a/html/index.html +++ b/html/index.html @@ -105,6 +105,7 @@
  • 90+配置: 写入配置信息(重启生效,格式参考源码 epd_config_t
  • 91: 系统重启
  • 92: 系统睡眠
  • +
  • 99: 恢复默认设置并重启