전원 버튼 롱프레스 본드 삭제
- 전원 꺼진 상태에서 15초 이상 전원 버튼 누르고 있는 경우 본드 삭제
This commit is contained in:
@@ -46,6 +46,7 @@ static const led_pattern_t m_patterns[LED_STATE_COUNT] = {
|
|||||||
[LED_STATE_ALIGN_SEARCHING] = { 1000, 1000, COLOR_ORANGE, true },
|
[LED_STATE_ALIGN_SEARCHING] = { 1000, 1000, COLOR_ORANGE, true },
|
||||||
[LED_STATE_ALIGN_COMPLETE] = { 0, 0, COLOR_GREEN, false },
|
[LED_STATE_ALIGN_COMPLETE] = { 0, 0, COLOR_GREEN, false },
|
||||||
[LED_STATE_ERROR] = { 0, 0, COLOR_ORANGE, true },
|
[LED_STATE_ERROR] = { 0, 0, COLOR_ORANGE, true },
|
||||||
|
[LED_STATE_BOND_DELETE] = { 0, 0, COLOR_ORANGE, false },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Module variables */
|
/* Module variables */
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ typedef enum
|
|||||||
LED_STATE_ALIGN_SEARCHING, // 5: Orange blink 1s/1s
|
LED_STATE_ALIGN_SEARCHING, // 5: Orange blink 1s/1s
|
||||||
LED_STATE_ALIGN_COMPLETE, // 6: Green ON
|
LED_STATE_ALIGN_COMPLETE, // 6: Green ON
|
||||||
LED_STATE_ERROR, // 7: Orange 3Hz x3 / 1s off
|
LED_STATE_ERROR, // 7: Orange 3Hz x3 / 1s off
|
||||||
|
LED_STATE_BOND_DELETE, // Bond Delete: Orange on
|
||||||
LED_STATE_COUNT
|
LED_STATE_COUNT
|
||||||
} led_state_t;
|
} led_state_t;
|
||||||
|
|
||||||
|
|||||||
+54
-1
@@ -6,9 +6,14 @@
|
|||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/drivers/gpio.h>
|
#include <zephyr/drivers/gpio.h>
|
||||||
#include <zephyr/sys/printk.h>
|
#include <zephyr/sys/printk.h>
|
||||||
|
#include <zephyr/sys/reboot.h>
|
||||||
#include <zephyr/dfu/mcuboot.h>
|
#include <zephyr/dfu/mcuboot.h>
|
||||||
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
|
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
|
||||||
#include <hal/nrf_power.h>
|
#include <hal/nrf_power.h>
|
||||||
|
#if IS_ENABLED(CONFIG_BT_SMP)
|
||||||
|
#include <zephyr/bluetooth/bluetooth.h>
|
||||||
|
#include <zephyr/bluetooth/conn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "debug_print.h"
|
#include "debug_print.h"
|
||||||
@@ -42,7 +47,8 @@ LOG_MODULE_REGISTER(vesiscan, LOG_LEVEL_INF);
|
|||||||
#define POWER_BTN_NODE DT_NODELABEL(button_check) // 전원 버튼
|
#define POWER_BTN_NODE DT_NODELABEL(button_check) // 전원 버튼
|
||||||
|
|
||||||
/* 전원 버튼 상태머신 (5ms 폴링) */
|
/* 전원 버튼 상태머신 (5ms 폴링) */
|
||||||
#define BOOT_THRESHOLD 300 // 5ms x 400 = 2초 -> 초기화 시간 고려 체감상 2초에 맞춤
|
#define BOOT_THRESHOLD 350 // 5ms x 400 = 2초 -> 초기화 시간 고려 체감상 2초에 맞춤
|
||||||
|
#define BOND_RESET_THRESHOLD (15000 / POWER_ON_DELAY) // 전원 ON 상태에서 15초 롱프레스 → 본드 삭제
|
||||||
|
|
||||||
/* 전원 제어 GPIO */
|
/* 전원 제어 GPIO */
|
||||||
static const struct gpio_dt_spec power_hold = GPIO_DT_SPEC_GET(POWER_HOLD_NODE, gpios);
|
static const struct gpio_dt_spec power_hold = GPIO_DT_SPEC_GET(POWER_HOLD_NODE, gpios);
|
||||||
@@ -78,8 +84,10 @@ static bool dfu_reset_resume_request; // DFU 완료 리셋 후 자동 복
|
|||||||
static uint32_t boot_reset_reason; // RESETREAS 원본 값
|
static uint32_t boot_reset_reason; // RESETREAS 원본 값
|
||||||
static struct k_work adv_start_work; // advertising 시작 work
|
static struct k_work adv_start_work; // advertising 시작 work
|
||||||
static struct k_work adv_stop_work; // advertising 중지 work
|
static struct k_work adv_stop_work; // advertising 중지 work
|
||||||
|
static struct k_work bond_reset_work; // 전원 버튼 15초 롱프레스 본드 삭제 work
|
||||||
static bool dfu_led_active; // DFU 업로드 중 초록 LED ON
|
static bool dfu_led_active; // DFU 업로드 중 초록 LED ON
|
||||||
static const char *power_off_pending_reason = "none";
|
static const char *power_off_pending_reason = "none";
|
||||||
|
static bool bond_reset_pending; // 본드 삭제 work 중복 예약 방지
|
||||||
|
|
||||||
static enum mgmt_cb_return dfu_status_cb(uint32_t event,
|
static enum mgmt_cb_return dfu_status_cb(uint32_t event,
|
||||||
enum mgmt_cb_return prev_status,
|
enum mgmt_cb_return prev_status,
|
||||||
@@ -170,6 +178,36 @@ static void adv_stop_work_handler(struct k_work *work)
|
|||||||
ble_advertising_stop();
|
ble_advertising_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 전원 버튼 15초 롱프레스: BLE 본드 삭제 후 리부트 */
|
||||||
|
static void bond_reset_work_handler(struct k_work *work)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(work);
|
||||||
|
|
||||||
|
DBG_ERR("[BTN] 15s long press -> BLE bond reset\r\n");
|
||||||
|
battery_timer_stop();
|
||||||
|
ble_advertising_stop();
|
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_BT_SMP)
|
||||||
|
int err = bt_unpair(BT_ID_DEFAULT, NULL);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
DBG_ERR("[BTN] bt_unpair failed err=%d\r\n", err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bond_data_delete = true;
|
||||||
|
DBG_PRINTF("[BTN] BLE bond data deleted\r\n");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
bond_data_delete = true;
|
||||||
|
DBG_PRINTF("[BTN] BLE bond delete skipped (BT_SMP disabled)\r\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
led_set_state(LED_STATE_BOND_TEST); // 삭제 완료 확인 LED TEST
|
||||||
|
k_msleep(1500);
|
||||||
|
sys_reboot(SYS_REBOOT_COLD);
|
||||||
|
}
|
||||||
|
|
||||||
/* BLE RX 콜백 */
|
/* BLE RX 콜백 */
|
||||||
static void ble_rx_handler(const uint8_t *data, uint16_t len)
|
static void ble_rx_handler(const uint8_t *data, uint16_t len)
|
||||||
{
|
{
|
||||||
@@ -430,6 +468,18 @@ static void main_s(struct k_timer *timer)
|
|||||||
if (!button_pressed)
|
if (!button_pressed)
|
||||||
{
|
{
|
||||||
boot_btn_released = true;
|
boot_btn_released = true;
|
||||||
|
cnt_s = 0;
|
||||||
|
}
|
||||||
|
else // 전원 ON부터 계속 유지 중 → 15초 넘으면 본드 삭제 + 리부트
|
||||||
|
{
|
||||||
|
cnt_s++;
|
||||||
|
|
||||||
|
if ((cnt_s >= BOND_RESET_THRESHOLD) && !bond_reset_pending)
|
||||||
|
{
|
||||||
|
bond_reset_pending = true;
|
||||||
|
k_work_submit(&bond_reset_work);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (button_pressed) // 버튼 새로 누르고 있음
|
else if (button_pressed) // 버튼 새로 누르고 있음
|
||||||
@@ -471,6 +521,9 @@ static void timers_init(void)
|
|||||||
k_work_init(&adv_start_work, adv_start_work_handler);
|
k_work_init(&adv_start_work, adv_start_work_handler);
|
||||||
k_work_init(&adv_stop_work, adv_stop_work_handler);
|
k_work_init(&adv_stop_work, adv_stop_work_handler);
|
||||||
|
|
||||||
|
// 전원 버튼 15초 롱프레스 본드 삭제 work
|
||||||
|
k_work_init(&bond_reset_work, bond_reset_work_handler);
|
||||||
|
|
||||||
// BLE 명령 처리 work queue
|
// BLE 명령 처리 work queue
|
||||||
k_work_init(&ble_cmd_work, ble_cmd_work_handler);
|
k_work_init(&ble_cmd_work, ble_cmd_work_handler);
|
||||||
k_work_queue_start(&ble_cmd_work_q, ble_cmd_workq_stack, K_THREAD_STACK_SIZEOF(ble_cmd_workq_stack), BLE_CMD_WORKQ_PRIORITY, NULL);
|
k_work_queue_start(&ble_cmd_work_q, ble_cmd_workq_stack, K_THREAD_STACK_SIZEOF(ble_cmd_workq_stack), BLE_CMD_WORKQ_PRIORITY, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user