Compare commits
4 Commits
c72349cf13
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f252c7bef | |||
| be1ca58bd6 | |||
| e20e8f5665 | |||
| 2bff259fa3 |
@@ -115,8 +115,6 @@
|
|||||||
#include "dr_piezo.h" /* Piezo ultrasound driver */
|
#include "dr_piezo.h" /* Piezo ultrasound driver */
|
||||||
#include "led_control.h" /* LED direct control driver */
|
#include "led_control.h" /* LED direct control driver */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* Build Configuration
|
* Build Configuration
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
@@ -157,7 +155,6 @@
|
|||||||
#define POWER_ON_DELAY 5 /* Power button polling interval (5ms) */
|
#define POWER_ON_DELAY 5 /* Power button polling interval (5ms) */
|
||||||
#define POWER_OFF_DELAY 3000 /* Power-off delay: 3s after LED indication */
|
#define POWER_OFF_DELAY 3000 /* Power-off delay: 3s after LED indication */
|
||||||
#define POWER_RESET_DELAY 2000 /* Reset delay: 2s */
|
#define POWER_RESET_DELAY 2000 /* Reset delay: 2s */
|
||||||
#define LED_NUM 24 /* LED pin number */
|
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* BLE Instances (statically allocated via SoftDevice macros)
|
* BLE Instances (statically allocated via SoftDevice macros)
|
||||||
@@ -195,6 +192,9 @@ static char * roles_str[] = {"INVALID_ROLE", "CENTRAL", "PERIPHERAL"};
|
|||||||
|
|
||||||
bool power_off_duble_prohibit = false; /* Power-off double prevention flag */
|
bool power_off_duble_prohibit = false; /* Power-off double prevention flag */
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* Extern Variables and Functions
|
||||||
|
*============================================================================*/
|
||||||
/* -- External module flags (defined in main_timer/power_control) -- */
|
/* -- External module flags (defined in main_timer/power_control) -- */
|
||||||
extern bool go_device_power_off; /* Power-off request flag */
|
extern bool go_device_power_off; /* Power-off request flag */
|
||||||
extern bool go_sleep_mode_enter; /* Sleep mode entry request flag */
|
extern bool go_sleep_mode_enter; /* Sleep mode entry request flag */
|
||||||
@@ -206,6 +206,14 @@ extern bool info4; /* Device info transmission complete flag
|
|||||||
extern uint8_t add_cycle; /* Additional measurement cycle counter */
|
extern uint8_t add_cycle; /* Additional measurement cycle counter */
|
||||||
extern bool motion_raw_data_enabled; /* Motion raw data streaming enabled */
|
extern bool motion_raw_data_enabled; /* Motion raw data streaming enabled */
|
||||||
|
|
||||||
|
/* -- External module functions (used in DFU prepare / disconnect cleanup) -- */
|
||||||
|
extern void maa_async_abort(void);
|
||||||
|
extern bool maa_async_on_tx_ready(void);
|
||||||
|
extern bool maa_async_is_busy(void);
|
||||||
|
extern void dr_piezo_power_off(void);
|
||||||
|
extern void battery_timer_stop(void);
|
||||||
|
extern void main_timer_stop(void);
|
||||||
|
|
||||||
uint16_t cnt_s; /* Power button polling counter (5ms units, 150=0.75s) */
|
uint16_t cnt_s; /* Power button polling counter (5ms units, 150=0.75s) */
|
||||||
char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0}; /* BLE text transmission buffer */
|
char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0}; /* BLE text transmission buffer */
|
||||||
uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] = {0}; /* BLE binary response buffer */
|
uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] = {0}; /* BLE binary response buffer */
|
||||||
@@ -492,7 +500,6 @@ static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
|
|||||||
break;
|
break;
|
||||||
case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
|
case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
|
||||||
DBG_PRINTF("[DFU] Error\r\n");
|
DBG_PRINTF("[DFU] Error\r\n");
|
||||||
APP_ERROR_CHECK(false);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -551,10 +558,6 @@ static void nrf_qwr_error_handler(uint32_t nrf_error)
|
|||||||
APP_ERROR_HANDLER(nrf_error);
|
APP_ERROR_HANDLER(nrf_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Async MAA TX complete handler (forward declarations) */
|
|
||||||
extern bool maa_async_on_tx_ready(void);
|
|
||||||
extern bool maa_async_is_busy(void);
|
|
||||||
extern void maa_async_abort(void);
|
|
||||||
|
|
||||||
/* 2026-03-17: Prevent blocking in BLE callback -- buffer command for main loop processing */
|
/* 2026-03-17: Prevent blocking in BLE callback -- buffer command for main loop processing */
|
||||||
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN] = {0};
|
static volatile uint8_t pending_cmd_buf[BLE_NUS_MAX_DATA_LEN] = {0};
|
||||||
@@ -1630,7 +1633,7 @@ static void main_s(void * p_context)
|
|||||||
go_device_power_off = true;
|
go_device_power_off = true;
|
||||||
main_timer_start();
|
main_timer_start();
|
||||||
}
|
}
|
||||||
else if (cnt_s > 250 || (m_reset_status == 2)) /* 250 x 5ms = 1.25s + α */
|
else if (cnt_s >= 250 || (m_reset_status == 2)) /* 250 x 5ms = 1.25s + α */
|
||||||
{
|
{
|
||||||
DBG_PRINTF("[BTN] Boot (cnt=%d)\r\n", cnt_s);
|
DBG_PRINTF("[BTN] Boot (cnt=%d)\r\n", cnt_s);
|
||||||
device_reset = false;
|
device_reset = false;
|
||||||
|
|||||||
@@ -36,8 +36,9 @@
|
|||||||
* : Improved low-battery detection and automatic power-off handling.
|
* : Improved low-battery detection and automatic power-off handling.
|
||||||
* : Updated BLE security, bonding, and advertising timeout behavior.
|
* : Updated BLE security, bonding, and advertising timeout behavior.
|
||||||
* : Cleaned up command parsing and removed unused project files.
|
* : Cleaned up command parsing and removed unused project files.
|
||||||
|
* - VBTFW0111 260421 jhChun
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
#define FIRMWARE_VERSION "VBTFW0103"
|
#define FIRMWARE_VERSION "VBTFW0111"
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* Data Length Constants
|
* Data Length Constants
|
||||||
|
|||||||
@@ -20,6 +20,22 @@ static struct {
|
|||||||
bool bonds_delete_pending;
|
bool bonds_delete_pending;
|
||||||
} m_state = {0};
|
} m_state = {0};
|
||||||
|
|
||||||
|
static const char * sec_error_name(pm_sec_error_code_t error)
|
||||||
|
{
|
||||||
|
switch (error) {
|
||||||
|
case PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING:
|
||||||
|
return "PIN_OR_KEY_MISSING";
|
||||||
|
case PM_CONN_SEC_ERROR_MIC_FAILURE:
|
||||||
|
return "MIC_FAILURE";
|
||||||
|
case PM_CONN_SEC_ERROR_DISCONNECT:
|
||||||
|
return "DISCONNECT";
|
||||||
|
case PM_CONN_SEC_ERROR_SMP_TIMEOUT:
|
||||||
|
return "SMP_TIMEOUT";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize BLE security
|
* @brief Initialize BLE security
|
||||||
*/
|
*/
|
||||||
@@ -102,8 +118,9 @@ void ble_security_quick_pm_handler(pm_evt_t const *p_evt)
|
|||||||
|
|
||||||
// DEV mode: do not forward security failure events to SDK handler (prevent disconnect)
|
// DEV mode: do not forward security failure events to SDK handler (prevent disconnect)
|
||||||
if (m_state.dev_mode && p_evt->evt_id == PM_EVT_CONN_SEC_FAILED) {
|
if (m_state.dev_mode && p_evt->evt_id == PM_EVT_CONN_SEC_FAILED) {
|
||||||
DBG_PRINTF("Security failed: error=%d\r\n",
|
DBG_PRINTF("Security failed: error=%d (%s)\r\n",
|
||||||
p_evt->params.conn_sec_failed.error);
|
p_evt->params.conn_sec_failed.error,
|
||||||
|
sec_error_name(p_evt->params.conn_sec_failed.error));
|
||||||
DBG_PRINTF("DEV: Ignoring sec failure, keeping connection\r\n");
|
DBG_PRINTF("DEV: Ignoring sec failure, keeping connection\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -129,8 +146,9 @@ void ble_security_quick_pm_handler(pm_evt_t const *p_evt)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PM_EVT_CONN_SEC_FAILED:
|
case PM_EVT_CONN_SEC_FAILED:
|
||||||
DBG_PRINTF("Security failed: error=%d\r\n",
|
DBG_PRINTF("Security failed: error=%d (%s)\r\n",
|
||||||
p_evt->params.conn_sec_failed.error);
|
p_evt->params.conn_sec_failed.error,
|
||||||
|
sec_error_name(p_evt->params.conn_sec_failed.error));
|
||||||
|
|
||||||
if (m_state.dev_mode) {
|
if (m_state.dev_mode) {
|
||||||
// DEV mode: ignore security failure, keep connection
|
// DEV mode: ignore security failure, keep connection
|
||||||
@@ -138,6 +156,20 @@ void ble_security_quick_pm_handler(pm_evt_t const *p_evt)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_DISCONNECT) {
|
||||||
|
// The peer/link already disconnected before security finished.
|
||||||
|
// There is no live connection to repair; BLE_GAP_EVT_DISCONNECTED
|
||||||
|
// will restart advertising.
|
||||||
|
DBG_PRINTF("Security ended by disconnect; waiting for reconnect\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_SMP_TIMEOUT) {
|
||||||
|
// The SDK cannot start another SMP procedure on this link.
|
||||||
|
pm_handler_disconnect_on_sec_failure(p_evt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING) {
|
if (p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING) {
|
||||||
// Key missing: attempt re-pairing, fall back to disconnect on failure
|
// Key missing: attempt re-pairing, fall back to disconnect on failure
|
||||||
err_code = pm_conn_secure(p_evt->conn_handle, true);
|
err_code = pm_conn_secure(p_evt->conn_handle, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user