Compare commits

..
4 Commits
28 changed files with 986 additions and 691 deletions
+9
View File
@@ -833,6 +833,15 @@
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="apps/usr_app/app_function.h" /> <Unit filename="apps/usr_app/app_function.h" />
<Unit filename="apps/usr_app/app_audio_debug.h" />
<Unit filename="apps/usr_app/car_audio_test.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="apps/usr_app/car_audio_test.h" />
<Unit filename="apps/usr_app/app_no_disturb.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="apps/usr_app/app_no_disturb.h" />
<Unit filename="apps/usr_app/app_shake_wake.c"> <Unit filename="apps/usr_app/app_shake_wake.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
+1
View File
@@ -412,6 +412,7 @@ c_SRC_FILES := \
apps/usr_app/app_boot.c \ apps/usr_app/app_boot.c \
apps/usr_app/app_function.c \ apps/usr_app/app_function.c \
apps/usr_app/app_no_disturb.c \ apps/usr_app/app_no_disturb.c \
apps/usr_app/car_audio_test.c \
apps/usr_app/app_shake_wake.c \ apps/usr_app/app_shake_wake.c \
apps/usr_le_code/ble_proto.c \ apps/usr_le_code/ble_proto.c \
apps/usr_le_code/bleproto.c \ apps/usr_le_code/bleproto.c \
+3 -3
View File
@@ -236,9 +236,9 @@ _notify:
} }
if (key_event_remap(&e)) { if (key_event_remap(&e)) {
sys_event_notify(&e); sys_event_notify(&e);
#if TCFG_KEY_TONE_EN // #if TCFG_KEY_TONE_EN
audio_key_tone_play(); // audio_key_tone_play();
#endif // #endif
} }
_scan_end: _scan_end:
scan_para->last_key = cur_key_value; scan_para->last_key = cur_key_value;
+3 -3
View File
@@ -735,8 +735,7 @@ struct port_wakeup port0 = {
}; };
#if BOARD_CHG_ENABLE #if BOARD_CHG_ENABLE
/* R18 is not fitted on CBC4, so VBUS never reaches VPWR in softoff. Wake on /* TP4056 CHRG falls when charging starts; use it for softoff charge wake. */
* the fitted ME4054 CHG_ON signal instead; it falls when charging starts. */
struct port_wakeup board_chg_wakeup_port = { struct port_wakeup board_chg_wakeup_port = {
.pullup_down_enable = ENABLE, .pullup_down_enable = ENABLE,
.edge = FALLING_EDGE, .edge = FALLING_EDGE,
@@ -1001,8 +1000,9 @@ void board_set_soft_poweroff(void)
soff_gpio_protect(TCFG_IOKEY_POWER_ONE_PORT); soff_gpio_protect(TCFG_IOKEY_POWER_ONE_PORT);
#endif #endif
#if BOARD_CHG_ENABLE #if BOARD_CHG_ENABLE
/* Preserve PG8 input state and its external pull-up for softoff wake. */ /* Preserve both TP4056 open-drain inputs and their pull-ups in softoff. */
soff_gpio_protect(BOARD_CHG_PIN); soff_gpio_protect(BOARD_CHG_PIN);
soff_gpio_protect(BOARD_STDBY_PIN);
#endif #endif
#if (!(TCFG_LP_TOUCH_KEY_ENABLE && TCFG_LP_TOUCH_KEY1_EN)) #if (!(TCFG_LP_TOUCH_KEY_ENABLE && TCFG_LP_TOUCH_KEY1_EN))
File diff suppressed because it is too large Load Diff
+14
View File
@@ -0,0 +1,14 @@
#ifndef APP_AUDIO_DEBUG_H
#define APP_AUDIO_DEBUG_H
#include "app_config.h"
#include "system/includes.h"
/* UTF-8 中文日志;只在状态变化时打印,不在音频采样循环内连续打印。 */
#if TCFG_MAGIC_AUDIO_DEBUG_ENABLE
#define MAGIC_AUDIO_LOG(fmt, ...) printf("[魔盒声音] " fmt "\n", ##__VA_ARGS__)
#else
#define MAGIC_AUDIO_LOG(...) do { } while (0)
#endif
#endif /* APP_AUDIO_DEBUG_H */
+4 -2
View File
@@ -127,8 +127,10 @@ static uint8_t boot_skip_key_wait(void)
/* USB 在位(充电口有电):说明是插着电源,不是用户凭空按键开机 */ /* USB 在位(充电口有电):说明是插着电源,不是用户凭空按键开机 */
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
if (bsp_chg_is_low() || bsp_vpwr_is_online() /* VPWR/LDO5V are the authoritative external-power indicators.
|| get_ldo5v_online_hw()) { * CHRG is open-drain and is only meaningful after VPWR is present;
* do not let an abnormal low PG8 skip the key wait by itself. */
if (get_ldo5v_online_hw()) {
log_info("boot usb, skip key wait\n"); log_info("boot usb, skip key wait\n");
return 1; return 1;
} }
+214 -64
View File
@@ -20,6 +20,8 @@
#include "app_led.h" #include "app_led.h"
#include "app_shake_wake.h" #include "app_shake_wake.h"
#include "app_no_disturb.h" #include "app_no_disturb.h"
#include "car_audio_test.h"
#include "app_audio_debug.h"
#include "app_time_util.h" #include "app_time_util.h"
#include "bsp_hw.h" #include "bsp_hw.h"
#include "board_pin.h" #include "board_pin.h"
@@ -33,13 +35,18 @@
#include "debug.h" #include "debug.h"
/** 功能模块总状态,替代原来一堆散落的 static 变量 */ /** 功能模块总状态,替代原来一堆散落的 static 变量 */
typedef struct { typedef struct
{
uint8_t app_power; /**< DP00=软关,电机/玩法停,BLE 仍在 */ uint8_t app_power; /**< DP00=软关,电机/玩法停,BLE 仍在 */
uint8_t play_mode; /**< 当前自动模式 0~5 */ uint8_t play_mode; /**< 当前自动模式 0~5 */
uint32_t play_ms; /**< 当前自动模式已运行时长,超时回待机 */ uint32_t play_ms; /**< 当前自动模式已运行时长,超时回待机 */
uint8_t hand_busy; /**< 手动点动进行中 */ uint8_t hand_busy; /**< 手动点动进行中 */
uint8_t hand_cmd_last; /**< 最近一次手动命令 */ uint8_t hand_cmd_last; /**< 最近一次手动命令 */
uint16_t hand_ms; uint16_t hand_ms;
uint8_t hand_queue[BOARD_HAND_QUEUE_LEN]; /**< DP2 连点排队:待执行命令 FIFO */
uint8_t hand_queue_head; /**< 队首下标 */
uint8_t hand_queue_count; /**< 待执行条数 */
volatile uint8_t hand_write_pending; /**< DP2 刚写入(03 停转要靠事件) */ volatile uint8_t hand_write_pending; /**< DP2 刚写入(03 停转要靠事件) */
volatile uint8_t hand_write_cmd; volatile uint8_t hand_write_cmd;
volatile uint8_t power_write_pending; volatile uint8_t power_write_pending;
@@ -50,6 +57,10 @@ typedef struct {
} AppFunctionCtx_t; } AppFunctionCtx_t;
static AppFunctionCtx_t s_func; static AppFunctionCtx_t s_func;
static void function_hand_apply(uint8_t cmd);
static uint16_t function_hand_action_ms(void);
static void function_hand_queue_push(uint8_t cmd);
static uint8_t function_hand_queue_pop(uint8_t *cmd);
static void function_hand_stop(void); static void function_hand_stop(void);
static void function_play_mode_apply(uint8_t mode); static void function_play_mode_apply(uint8_t mode);
@@ -88,7 +99,7 @@ void app_function_dp_play_write(uint8_t mode)
/** /**
* @brief DP2 写入钩子:仅记录第 1 字节,真正执行在 app_function_poll * @brief DP2 写入钩子:仅记录第 1 字节,真正执行在 app_function_poll
* @param cmd 0=停止,1=上部电机探出,2=下部电机探出 * @param cmd 0=停止,1=上部电机探出,2=下电机顺时针转动,3=下电机逆时针转动
* @return 无 * @return 无
*/ */
void app_function_dp_hand_write(uint8_t cmd) void app_function_dp_hand_write(uint8_t cmd)
@@ -110,21 +121,31 @@ void app_function_set_shake_wake(uint8_t enable)
*/ */
void app_function_poll(void) void app_function_poll(void)
{ {
if (s_func.shake_wake != !!gDevData.shake_wake) { if (s_func.shake_wake != !!gDevData.shake_wake)
{
app_function_set_shake_wake(gDevData.shake_wake); app_function_set_shake_wake(gDevData.shake_wake);
} }
if (s_func.power_write_pending) { if (s_func.power_write_pending)
{
uint8_t enable = s_func.power_write_value; uint8_t enable = s_func.power_write_value;
s_func.power_write_pending = 0; s_func.power_write_pending = 0;
if (enable) { if (enable)
if (function_power_on(1)) { {
if (function_power_on(1))
{
log_info("APP power on\n"); log_info("APP power on\n");
} else { }
else
{
gDevData.power = s_func.app_power; gDevData.power = s_func.app_power;
} }
} else if (!enable && s_func.app_power) { }
else if (!enable && s_func.app_power)
{
app_function_soft_off(); app_function_soft_off();
} else { }
else
{
gDevData.power = s_func.app_power; gDevData.power = s_func.app_power;
} }
} }
@@ -144,13 +165,23 @@ void app_function_tick_1ms(uint16_t dt)
app_shake_wake_poll(); app_shake_wake_poll();
if (s_func.hand_busy) { if (s_func.hand_busy) {
uint8_t next_cmd;
bsp_motor_switch_tick(); /* 手动点动期间也要走换向死区 */ bsp_motor_switch_tick(); /* 手动点动期间也要走换向死区 */
if (gDevData.hand_mode == HAND_MODE_1) {
app_mode_run(); /* cmd=1 的上电机波形靠自动引擎推进 */
}
s_func.hand_ms = app_add_ms(s_func.hand_ms, dt); s_func.hand_ms = app_add_ms(s_func.hand_ms, dt);
if (s_func.hand_ms >= BOARD_HAND_PULSE_MS) { if (s_func.hand_ms >= function_hand_action_ms()) {
if (function_hand_queue_pop(&next_cmd)) {
s_func.hand_ms = 0; /* 接着补做排队的,不打断 */
function_hand_apply(next_cmd);
log_info("manual next %d\n", next_cmd);
} else {
function_hand_stop(); function_hand_stop();
gDevData.hand_mode = HAND_MODE_0;
app_led_request_mode_blink(); app_led_request_mode_blink();
log_info("manual timeout %ums\n", (unsigned)BOARD_HAND_PULSE_MS); log_info("manual done\n");
}
} }
} else { } else {
app_mode_run(); app_mode_run();
@@ -166,10 +197,88 @@ static void function_hand_stop(void)
{ {
s_func.hand_busy = 0; s_func.hand_busy = 0;
s_func.hand_ms = 0; s_func.hand_ms = 0;
s_func.hand_queue_head = 0;
s_func.hand_queue_count = 0;
gDevData.hand_mode = HAND_MODE_0; gDevData.hand_mode = HAND_MODE_0;
app_mode_stop();
bsp_drive_stop(); bsp_drive_stop();
} }
/**
* @brief 把一条 DP2 命令压入排队 FIFO
* @param cmd HAND_MODE_1/2/3
* @return 无
*/
static void function_hand_queue_push(uint8_t cmd)
{
uint8_t idx;
if (s_func.hand_queue_count >= BOARD_HAND_QUEUE_LEN) {
log_info("hand queue full, drop %d\n", cmd);
return;
}
idx = (uint8_t)((s_func.hand_queue_head + s_func.hand_queue_count)
% BOARD_HAND_QUEUE_LEN);
s_func.hand_queue[idx] = cmd;
s_func.hand_queue_count++;
}
/**
* @brief 取出队首命令
* @param cmd 出参
* @return 1=取到,0=队列空
*/
static uint8_t function_hand_queue_pop(uint8_t *cmd)
{
if (s_func.hand_queue_count == 0) {
return 0;
}
*cmd = s_func.hand_queue[s_func.hand_queue_head];
s_func.hand_queue_head = (uint8_t)((s_func.hand_queue_head + 1)
% BOARD_HAND_QUEUE_LEN);
s_func.hand_queue_count--;
return 1;
}
/**
* @brief 下发一轮手动动作(驱动层唯一出口)
* @param cmd HAND_MODE_1/2/3
* @return 无
*/
static void function_hand_apply(uint8_t cmd)
{
app_mode_stop(); /* 清掉上一轮残留,含 cmd=1 借用的自动引擎 */
gDevData.hand_mode = cmd;
switch (cmd) {
case HAND_MODE_1:
app_mode_start(APP_MODE_UPPER_ONLY);
break;
case HAND_MODE_2:
bsp_drive_set(BSP_MOTOR_STOP, 0, BSP_MOTOR_FORWARD, 8000);
break;
case HAND_MODE_3:
bsp_drive_set(BSP_MOTOR_STOP, 0, BSP_MOTOR_BACKWARD, 8000);
break;
default:
bsp_drive_stop();
break;
}
}
/**
* @brief 当前手动动作的单轮时长
* @return 毫秒
*/
static uint16_t function_hand_action_ms(void)
{
if (gDevData.hand_mode == HAND_MODE_2 || gDevData.hand_mode == HAND_MODE_3) {
return BOARD_HAND_STEP_MS; /* 下电机:一轮 = 半圈 */
}
return BOARD_HAND_PULSE_MS; /* 上电机波形:保留 5s 上限 */
}
/** /**
* @brief 停手动 + 自动模式,并清 DP1 * @brief 停手动 + 自动模式,并清 DP1
* @return 无 * @return 无
@@ -254,27 +363,45 @@ static void function_play_mode_apply(uint8_t mode)
{ {
uint8_t old_mode = s_func.play_mode; uint8_t old_mode = s_func.play_mode;
if (mode > PLAY_MODE_5) { MAGIC_AUDIO_LOG("模式切换请求:旧=%u,请求=%u,DP4=%u,功能开关=%u,充电=%u,关机中=%uOTA=%u",
old_mode, mode, gDevData.beep_trig, s_func.app_power,
app_power_usb_online(), app_power_poweroff_pending(), app_led_is_ota());
if (mode > PLAY_MODE_5)
{
mode = 0; mode = 0;
} }
/* Pairing is an online overlay; only charging, OTA and power-off stop motion. */ /* Pairing is an online overlay; only charging, OTA and power-off stop motion. */
if (app_power_usb_online() || !s_func.app_power || app_power_poweroff_pending() if (app_power_usb_online() || !s_func.app_power || app_power_poweroff_pending() || app_led_is_ota())
|| app_led_is_ota()) { {
mode = 0; mode = 0;
} }
if (mode != 0 && s_func.hand_busy) { if (mode != 0 && s_func.hand_busy)
{
function_hand_stop(); /* 手动切到自动:先停手动点动,再进自动模式 */ function_hand_stop(); /* 手动切到自动:先停手动点动,再进自动模式 */
} }
s_func.play_mode = mode; s_func.play_mode = mode;
s_func.play_ms = 0; /* 每次切模式都重新计 10 分钟 */ s_func.play_ms = 0; /* 每次切模式都重新计 10 分钟 */
gDevData.play_mode = mode; gDevData.play_mode = mode;
if (mode == 0) { if (mode == 0)
{
app_mode_stop(); app_mode_stop();
} else { }
else
{
app_mode_start(mode); app_mode_start(mode);
} }
if (mode != old_mode) { // MAGIC_AUDIO_LOG("模式切换结果:旧=%u,实际=%u;当前测试不拦截DP4", old_mode, mode);
if (mode != old_mode)
{
app_led_request_mode_blink(); /* 模式真变了才闪两下 */ app_led_request_mode_blink(); /* 模式真变了才闪两下 */
/* DP4:0=关闭模式切换鸟叫,1=允许播放 */
//&& gDevData.beep_trig
if ((mode != PLAY_MODE_0) && gDevData.beep_trig)
{
Car_Audio_Test_Play();
}
} }
} }
@@ -288,20 +415,23 @@ static void function_play_mode_poll(void)
{ {
uint8_t mode; uint8_t mode;
if (!s_func.play_write_pending) { if (!s_func.play_write_pending)
{
return; return;
} }
s_func.play_write_pending = 0; s_func.play_write_pending = 0;
if (app_power_usb_online() || !s_func.app_power || app_power_poweroff_pending() if (app_power_usb_online() || !s_func.app_power || app_power_poweroff_pending() || app_led_is_ota())
|| app_led_is_ota()) { {
gDevData.play_mode = s_func.play_mode; gDevData.play_mode = s_func.play_mode;
return; return;
} }
mode = s_func.play_write_mode; mode = s_func.play_write_mode;
if (mode > PLAY_MODE_5) { if (mode > PLAY_MODE_5)
{
mode = 0; mode = 0;
} }
if (mode != PLAY_MODE_0 && mode == s_func.play_mode) { if (mode != PLAY_MODE_0 && mode == s_func.play_mode)
{
mode = PLAY_MODE_0; mode = PLAY_MODE_0;
} }
function_play_mode_apply(mode); function_play_mode_apply(mode);
@@ -317,11 +447,13 @@ static void function_play_mode_poll(void)
*/ */
static void function_play_mode_timeout(uint16_t dt) static void function_play_mode_timeout(uint16_t dt)
{ {
if (s_func.play_mode == 0) { if (s_func.play_mode == 0)
{
return; return;
} }
s_func.play_ms += dt; s_func.play_ms += dt;
if (s_func.play_ms < BOARD_AUTO_MODE_MAX_MS) { if (s_func.play_ms < BOARD_AUTO_MODE_MAX_MS)
{
return; return;
} }
log_info("auto mode %d run %ums, timeout to standby\n", log_info("auto mode %d run %ums, timeout to standby\n",
@@ -330,7 +462,7 @@ static void function_play_mode_timeout(uint16_t dt)
} }
/** /**
* @brief DP2 手动:只看第 1 字节。0=空闲,1=上部探出,2=下部探出 * @brief DP2 手动:只看第 1 字节。0=上下都停,1=仅上电机往复,2=仅下电机顺时针,3=仅下电机逆时针
* @return 无 * @return 无
*/ */
static void function_hand_poll(void) static void function_hand_poll(void)
@@ -339,29 +471,36 @@ static void function_hand_poll(void)
uint8_t got_write = s_func.hand_write_pending; uint8_t got_write = s_func.hand_write_pending;
/* 优先用 DP 写入钩子带来的边沿;没有新写入才读协议层当前值 */ /* 优先用 DP 写入钩子带来的边沿;没有新写入才读协议层当前值 */
if (got_write) { if (got_write)
{
s_func.hand_write_pending = 0; s_func.hand_write_pending = 0;
cmd = s_func.hand_write_cmd; cmd = s_func.hand_write_cmd;
} else { }
else
{
cmd = gDevData.hand_mode; cmd = gDevData.hand_mode;
} }
if (app_power_usb_online() || !s_func.app_power || app_power_poweroff_pending() if (app_power_usb_online() || !s_func.app_power || app_power_poweroff_pending() || app_led_is_ota())
|| app_led_is_ota()) { {
if (s_func.hand_busy) { if (s_func.hand_busy)
{
app_function_stop_all(); app_function_stop_all();
} }
s_func.hand_cmd_last = cmd; s_func.hand_cmd_last = cmd;
return; return;
} }
if (!got_write) { if (!got_write)
{
s_func.hand_cmd_last = cmd; s_func.hand_cmd_last = cmd;
return; return;
} }
if (cmd == HAND_MODE_0) { if (cmd == HAND_MODE_0)
if (s_func.hand_busy) { {
if (s_func.hand_busy)
{
function_hand_stop(); function_hand_stop();
app_led_request_mode_blink(); app_led_request_mode_blink();
} }
@@ -369,33 +508,32 @@ static void function_hand_poll(void)
return; return;
} }
if (cmd == HAND_MODE_1 || cmd == HAND_MODE_2) { if (cmd >= HAND_MODE_1 && cmd <= HAND_MODE_3) {
if (s_func.hand_busy) {
/* 正在动作中:不打断、不清零计时,只把新指令排到队尾 */
function_hand_queue_push(cmd);
s_func.hand_cmd_last = cmd;
return;
}
s_func.play_mode = 0; s_func.play_mode = 0;
s_func.play_ms = 0; s_func.play_ms = 0;
gDevData.play_mode = 0; gDevData.play_mode = 0;
app_mode_stop(); /* 自动切手动:先停自动玩法 */
s_func.hand_busy = 1; s_func.hand_busy = 1;
s_func.hand_ms = 0; s_func.hand_ms = 0;
gDevData.hand_mode = cmd; function_hand_apply(cmd);
if (cmd == HAND_MODE_1) {
bsp_drive_set(BSP_MOTOR_FORWARD, 5500, app_led_request_mode_blink();
BSP_MOTOR_STOP, 0); if (gDevData.beep_trig) {
} else { Car_Audio_Test_Play();
bsp_drive_set(BSP_MOTOR_STOP, 0,
BSP_MOTOR_FORWARD, 5500);
} }
app_led_request_mode_blink(); /* 自动/空闲切到手动,闪两下提示 */
log_info("hand cmd=%d %s max=%ums\n", cmd,
(cmd == HAND_MODE_1) ? "upper" : "lower",
(unsigned)BOARD_HAND_PULSE_MS);
} else { } else {
gDevData.hand_mode = HAND_MODE_0; gDevData.hand_mode = HAND_MODE_0;
if (s_func.hand_busy) { if (s_func.hand_busy) {
function_hand_stop(); function_hand_stop();
} }
log_info("ignore unsupported hand cmd=%d\n", cmd);
} }
s_func.hand_cmd_last = cmd; s_func.hand_cmd_last = cmd;
} }
/** /**
@@ -404,12 +542,12 @@ static void function_hand_poll(void)
*/ */
static void function_on_click(void) static void function_on_click(void)
{ {
if (s_func.hand_busy) { if (s_func.hand_busy)
{
log_info("key click ignored, hand busy\n"); log_info("key click ignored, hand busy\n");
return; return;
} }
function_play_mode_apply((s_func.play_mode >= PLAY_MODE_5) ? function_play_mode_apply((s_func.play_mode >= PLAY_MODE_5) ? PLAY_MODE_1 : (uint8_t)(s_func.play_mode + 1));
PLAY_MODE_1 : (uint8_t)(s_func.play_mode + 1));
log_info("key click play_mode=%d\n", s_func.play_mode); log_info("key click play_mode=%d\n", s_func.play_mode);
} }
@@ -419,20 +557,25 @@ static void function_on_click(void)
*/ */
void usr_on_key_short(void) void usr_on_key_short(void)
{ {
if (app_power_poweroff_pending()) { if (app_power_poweroff_pending())
{
return; return;
} }
if (app_power_usb_online()) { if (app_power_usb_online())
{
log_info("key click ignored, charging\n"); log_info("key click ignored, charging\n");
return; return;
} }
if (app_led_is_ota()) { if (app_led_is_ota())
{
log_info("key click ignored, ota\n"); log_info("key click ignored, ota\n");
return; return;
} }
if (!s_func.app_power) { if (!s_func.app_power)
{
/* 软关状态下短按:只唤醒功能,不切模式 */ /* 软关状态下短按:只唤醒功能,不切模式 */
if (function_power_on(1)) { if (function_power_on(1))
{
log_info("key click cancel soft off\n"); log_info("key click cancel soft off\n");
} }
return; return;
@@ -446,14 +589,17 @@ void usr_on_key_short(void)
*/ */
void usr_on_key_long(void) void usr_on_key_long(void)
{ {
if (app_power_poweroff_pending()) { if (app_power_poweroff_pending())
{
return; return;
} }
if (app_power_usb_online()) { if (app_power_usb_online())
{
log_info("key hold 3s ignored, charging\n"); log_info("key hold 3s ignored, charging\n");
return; return;
} }
if (app_led_is_ota()) { if (app_led_is_ota())
{
log_info("key hold 3s, exit ota and poweroff\n"); log_info("key hold 3s, exit ota and poweroff\n");
usr_app_ota_exit(); usr_app_ota_exit();
app_led_exit_ota(); app_led_exit_ota();
@@ -468,10 +614,12 @@ void usr_on_key_long(void)
static uint8_t function_power_on(uint8_t show_hint) static uint8_t function_power_on(uint8_t show_hint)
{ {
if (app_power_usb_online() || app_power_poweroff_pending() || if (app_power_usb_online() || app_power_poweroff_pending() ||
app_led_is_ota()) { app_led_is_ota())
{
return 0; return 0;
} }
if (s_func.app_power) { if (s_func.app_power)
{
gDevData.power = 1; gDevData.power = 1;
return 1; return 1;
} }
@@ -481,7 +629,8 @@ static uint8_t function_power_on(uint8_t show_hint)
gDevData.power = 1; gDevData.power = 1;
app_shake_wake_reset(); app_shake_wake_reset();
usr_ble_set_standby(0); usr_ble_set_standby(0);
if (show_hint) { if (show_hint)
{
app_led_hint_power_on(); app_led_hint_power_on();
} }
return 1; return 1;
@@ -499,7 +648,8 @@ static uint8_t function_shake_wake_allowed(void)
static void function_shake_wake_trigger(void) static void function_shake_wake_trigger(void)
{ {
if (function_power_on(1)) { if (function_power_on(1))
{
log_info("shake wake power on\n"); log_info("shake wake power on\n");
} }
} }
-1
View File
@@ -39,7 +39,6 @@ void app_function_dp_hand_write(uint8_t cmd);
/** CBC4 DP6 震动开机开关。 */ /** CBC4 DP6 震动开机开关。 */
void app_function_set_shake_wake(uint8_t enable); void app_function_set_shake_wake(uint8_t enable);
/** /**
* @brief 跟随 APP 下发的 DP0/DP1,并处理 DP2 手动点动,每个业务 tick 调用一次 * @brief 跟随 APP 下发的 DP0/DP1,并处理 DP2 手动点动,每个业务 tick 调用一次
* @return 无 * @return 无
+8 -3
View File
@@ -28,6 +28,7 @@ typedef struct {
uint8_t initialized; uint8_t initialized;
uint8_t active; uint8_t active;
uint8_t output_valid; uint8_t output_valid;
uint8_t upper_only; /* 1=只输出上电机,下电机恒停 */
uint8_t upper_phase; uint8_t upper_phase;
uint8_t lower_pattern; uint8_t lower_pattern;
uint8_t lower_segment; uint8_t lower_segment;
@@ -271,7 +272,9 @@ static void app_mode5_process(uint32_t now_ms)
} }
} }
app_mode_outputs_set(s_mode.upper_direction, s_mode.upper_speed, app_mode_outputs_set(s_mode.upper_direction, s_mode.upper_speed,
s_mode.lower_direction, MAGIC_BOX_HIGH_PERCENT); s_mode.upper_only ? BSP_MOTOR_STOP : s_mode.lower_direction,
s_mode.upper_only ? 0 : MAGIC_BOX_HIGH_PERCENT);
} }
AppMode_Ret_t app_mode_init(void) AppMode_Ret_t app_mode_init(void)
@@ -297,12 +300,13 @@ AppMode_Ret_t app_mode_start(uint8_t mode)
if (!s_mode.initialized) { if (!s_mode.initialized) {
return APP_MODE_ERR_NOT_INIT; return APP_MODE_ERR_NOT_INIT;
} }
if (mode < 1 || mode > 5) { if (mode < 1 || mode > APP_MODE_UPPER_ONLY) { /* 放宽到 6 */
app_mode_stop(); app_mode_stop();
return APP_MODE_ERR_PARAM; return APP_MODE_ERR_PARAM;
} }
s_mode.active = mode; s_mode.upper_only = (mode == APP_MODE_UPPER_ONLY);
s_mode.active = s_mode.upper_only ? 5 : mode; /* 内部仍按模式 5 跑 */
app_mode_start_current(timer_get_ms()); app_mode_start_current(timer_get_ms());
log_info("magic box mode %d start\n", mode); log_info("magic box mode %d start\n", mode);
return APP_MODE_OK; return APP_MODE_OK;
@@ -311,6 +315,7 @@ AppMode_Ret_t app_mode_start(uint8_t mode)
void app_mode_stop(void) void app_mode_stop(void)
{ {
s_mode.active = 0; s_mode.active = 0;
s_mode.upper_only = 0;
s_mode.output_valid = 0; s_mode.output_valid = 0;
bsp_drive_stop(); bsp_drive_stop();
} }
+5
View File
@@ -12,9 +12,14 @@
#ifndef __APP_MODE_H__ #ifndef __APP_MODE_H__
#define __APP_MODE_H__ #define __APP_MODE_H__
#define APP_MODE_UPPER_ONLY 6
#include <stdint.h> #include <stdint.h>
/** 特殊玩法编号:复用模式 5 的上电机波形,但下电机恒停(供 DP2=1 使用) */
typedef enum { typedef enum {
APP_MODE_OK = 0, APP_MODE_OK = 0,
APP_MODE_ERR_PARAM, APP_MODE_ERR_PARAM,
+62 -85
View File
@@ -1,10 +1,17 @@
#include "app_no_disturb.h" #include "app_no_disturb.h"
#include "usr_rtc.h"
#include "system/includes.h" #include "system/includes.h"
#include "usr_rtc.h"
#define APP_NO_DISTURB_VM_ID 28U
#define APP_NO_DISTURB_MAGIC 0x4e44U
#define APP_NO_DISTURB_VERSION 1U
#define APP_MINUTES_PER_DAY (24U * 60U) #define APP_MINUTES_PER_DAY (24U * 60U)
#define APP_NO_DISTURB_VM_MAGIC 0x444e4431UL
#define APP_NO_DISTURB_VM_VERSION 1U typedef struct __attribute__((packed)) {
uint16_t magic;
uint8_t version;
uint8_t cfg[APP_NO_DISTURB_CFG_LEN];
} AppNoDisturbVm_t;
typedef struct { typedef struct {
uint8_t enabled; uint8_t enabled;
@@ -13,36 +20,65 @@ typedef struct {
uint16_t end_minute; uint16_t end_minute;
} AppNoDisturbCtx_t; } AppNoDisturbCtx_t;
typedef struct {
uint32_t magic;
uint8_t version;
uint8_t length;
uint16_t checksum;
uint8_t data[APP_NO_DISTURB_DATA_LEN];
} AppNoDisturbVm_t;
static AppNoDisturbCtx_t s_no_disturb; static AppNoDisturbCtx_t s_no_disturb;
static uint8_t s_saved_data[APP_NO_DISTURB_DATA_LEN];
static uint8_t s_saved_valid;
static uint16_t app_no_disturb_checksum(const uint8_t *data) static uint8_t app_no_disturb_cfg_valid(const uint8_t cfg[APP_NO_DISTURB_CFG_LEN])
{ {
uint16_t checksum = 0xa55aU;
uint8_t i; uint8_t i;
for (i = 0; i < APP_NO_DISTURB_DATA_LEN; i++) { if (!cfg || cfg[0] > 1U || cfg[9] >= 24U || cfg[11] >= 24U ||
checksum = (uint16_t)((checksum << 5) | (checksum >> 11)); cfg[10] >= 60U || cfg[12] >= 60U) {
checksum ^= data[i]; return 0;
} }
return checksum; for (i = 0; i < 7U; i++) {
if (cfg[2U + i] > 1U) {
return 0;
}
}
return 1;
} }
static uint8_t app_no_disturb_vm_valid(const AppNoDisturbVm_t *vm) void app_no_disturb_configure(uint8_t enable, uint8_t weekdays_mask,
uint16_t start_minute, uint16_t end_minute)
{ {
return vm->magic == APP_NO_DISTURB_VM_MAGIC && s_no_disturb.enabled = !!enable;
vm->version == APP_NO_DISTURB_VM_VERSION && s_no_disturb.weekdays_mask = weekdays_mask & 0x7fU;
vm->length == APP_NO_DISTURB_DATA_LEN && s_no_disturb.start_minute = start_minute;
vm->checksum == app_no_disturb_checksum(vm->data); s_no_disturb.end_minute = end_minute;
}
uint8_t app_no_disturb_storage_load(uint8_t cfg[APP_NO_DISTURB_CFG_LEN])
{
AppNoDisturbVm_t vm;
int ret;
if (!cfg) {
return 0;
}
memset(&vm, 0, sizeof(vm));
ret = syscfg_read(APP_NO_DISTURB_VM_ID, &vm, sizeof(vm));
if (ret != (int)sizeof(vm) || vm.magic != APP_NO_DISTURB_MAGIC ||
vm.version != APP_NO_DISTURB_VERSION || !app_no_disturb_cfg_valid(vm.cfg)) {
memset(cfg, 0, APP_NO_DISTURB_CFG_LEN);
return 0;
}
memcpy(cfg, vm.cfg, APP_NO_DISTURB_CFG_LEN);
return 1;
}
uint8_t app_no_disturb_storage_save(const uint8_t cfg[APP_NO_DISTURB_CFG_LEN])
{
AppNoDisturbVm_t vm;
if (!app_no_disturb_cfg_valid(cfg)) {
return 0;
}
memset(&vm, 0, sizeof(vm));
vm.magic = APP_NO_DISTURB_MAGIC;
vm.version = APP_NO_DISTURB_VERSION;
memcpy(vm.cfg, cfg, APP_NO_DISTURB_CFG_LEN);
return (uint8_t)(syscfg_write(APP_NO_DISTURB_VM_ID, &vm, sizeof(vm)) ==
(int)sizeof(vm));
} }
static uint8_t app_no_disturb_weekday_monday0(const struct sys_time *time) static uint8_t app_no_disturb_weekday_monday0(const struct sys_time *time)
@@ -66,15 +102,6 @@ static uint8_t app_no_disturb_day_selected(uint8_t weekday)
return (uint8_t)((s_no_disturb.weekdays_mask & (1U << weekday)) != 0U); return (uint8_t)((s_no_disturb.weekdays_mask & (1U << weekday)) != 0U);
} }
void app_no_disturb_configure(uint8_t enable, uint8_t weekdays_mask,
uint16_t start_minute, uint16_t end_minute)
{
s_no_disturb.enabled = !!enable;
s_no_disturb.weekdays_mask = weekdays_mask & 0x7fU;
s_no_disturb.start_minute = start_minute;
s_no_disturb.end_minute = end_minute;
}
uint8_t app_no_disturb_is_active_at(const struct sys_time *time) uint8_t app_no_disturb_is_active_at(const struct sys_time *time)
{ {
uint8_t weekday; uint8_t weekday;
@@ -83,12 +110,10 @@ uint8_t app_no_disturb_is_active_at(const struct sys_time *time)
if (!time || !s_no_disturb.enabled || !s_no_disturb.weekdays_mask || if (!time || !s_no_disturb.enabled || !s_no_disturb.weekdays_mask ||
s_no_disturb.start_minute >= APP_MINUTES_PER_DAY || s_no_disturb.start_minute >= APP_MINUTES_PER_DAY ||
s_no_disturb.end_minute >= APP_MINUTES_PER_DAY || s_no_disturb.end_minute >= APP_MINUTES_PER_DAY ||
time->month < 1U || time->month > 12U || time->month < 1U || time->month > 12U || time->day < 1U ||
time->day < 1U || time->day > 31U || time->day > 31U || time->hour > 23U || time->min > 59U) {
time->hour > 23U || time->min > 59U) {
return 0; return 0;
} }
weekday = app_no_disturb_weekday_monday0(time); weekday = app_no_disturb_weekday_monday0(time);
now_minute = (uint16_t)(time->hour * 60U + time->min); now_minute = (uint16_t)(time->hour * 60U + time->min);
@@ -118,51 +143,3 @@ uint8_t app_no_disturb_is_active(void)
} }
return app_no_disturb_is_active_at(&time); return app_no_disturb_is_active_at(&time);
} }
uint8_t app_no_disturb_storage_load(uint8_t data[APP_NO_DISTURB_DATA_LEN])
{
AppNoDisturbVm_t vm;
int ret;
if (!data) {
return 0;
}
memset(&vm, 0, sizeof(vm));
ret = syscfg_read(CFG_USER_NO_DISTURB, (uint8_t *)&vm, sizeof(vm));
if (ret != (int)sizeof(vm) || !app_no_disturb_vm_valid(&vm)) {
s_saved_valid = 0;
return 0;
}
memcpy(data, vm.data, APP_NO_DISTURB_DATA_LEN);
memcpy(s_saved_data, vm.data, APP_NO_DISTURB_DATA_LEN);
s_saved_valid = 1;
return 1;
}
uint8_t app_no_disturb_storage_save(const uint8_t data[APP_NO_DISTURB_DATA_LEN])
{
AppNoDisturbVm_t vm;
int ret;
if (!data) {
return 0;
}
if (s_saved_valid &&
!memcmp(s_saved_data, data, APP_NO_DISTURB_DATA_LEN)) {
return 1;
}
memset(&vm, 0, sizeof(vm));
vm.magic = APP_NO_DISTURB_VM_MAGIC;
vm.version = APP_NO_DISTURB_VM_VERSION;
vm.length = APP_NO_DISTURB_DATA_LEN;
memcpy(vm.data, data, APP_NO_DISTURB_DATA_LEN);
vm.checksum = app_no_disturb_checksum(vm.data);
ret = syscfg_write(CFG_USER_NO_DISTURB, (uint8_t *)&vm, sizeof(vm));
if (ret != (int)sizeof(vm)) {
return 0;
}
memcpy(s_saved_data, data, APP_NO_DISTURB_DATA_LEN);
s_saved_valid = 1;
return 1;
}
+4 -4
View File
@@ -4,14 +4,14 @@
#include <stdint.h> #include <stdint.h>
#include "system/sys_time.h" #include "system/sys_time.h"
#define APP_NO_DISTURB_DATA_LEN 13U #define APP_NO_DISTURB_CFG_LEN 13
/* weekdays_mask bit 0..6 means Monday..Sunday. */ /* DP7: bytes 2..8 are Monday..Sunday, byte 1 is reserved. */
void app_no_disturb_configure(uint8_t enable, uint8_t weekdays_mask, void app_no_disturb_configure(uint8_t enable, uint8_t weekdays_mask,
uint16_t start_minute, uint16_t end_minute); uint16_t start_minute, uint16_t end_minute);
uint8_t app_no_disturb_storage_load(uint8_t cfg[APP_NO_DISTURB_CFG_LEN]);
uint8_t app_no_disturb_storage_save(const uint8_t cfg[APP_NO_DISTURB_CFG_LEN]);
uint8_t app_no_disturb_is_active(void); uint8_t app_no_disturb_is_active(void);
uint8_t app_no_disturb_is_active_at(const struct sys_time *time); uint8_t app_no_disturb_is_active_at(const struct sys_time *time);
uint8_t app_no_disturb_storage_load(uint8_t data[APP_NO_DISTURB_DATA_LEN]);
uint8_t app_no_disturb_storage_save(const uint8_t data[APP_NO_DISTURB_DATA_LEN]);
#endif /* __APP_NO_DISTURB_H__ */ #endif /* __APP_NO_DISTURB_H__ */
+67 -26
View File
@@ -36,14 +36,21 @@
#define BAT_BOOT_MS 3000 /* 上电 3s 内不因低电深睡 */ #define BAT_BOOT_MS 3000 /* 上电 3s 内不因低电深睡 */
#define BAT_LOG_MS 10000 #define BAT_LOG_MS 10000
#define BAT_PERIODIC_LOG_ENABLE 0 /* Production standby must not wake UART periodically. */ #define BAT_PERIODIC_LOG_ENABLE 0 /* Production standby must not wake UART periodically. */
#define CHG_ON_CONFIRM_MS 50u
#define CHG_OFF_CONFIRM_MS 150u
#define CHG_FULL_RECHECK_MS 1000u
#define BAT_LOW_WIN 3 /* 连续约 2.4s 才进低电告警(仅闪灯,不关机) */ #define BAT_LOW_WIN 3 /* 连续约 2.4s 才进低电告警(仅闪灯,不关机) */
/** 充电检测:CHG/VPWR 消抖后的结果 */ /** TP4056 CHRG/STDBY debounced charging state. */
typedef struct { typedef struct {
uint8_t usb_online; uint8_t usb_online;
uint8_t charge_led; /**< 0=无 1=充电红 2=充满绿 */ uint8_t charge_led;
uint8_t charge_led_last; /**< 仅用于变化时打日志 */ uint8_t charge_led_last;
uint16_t full_ms; /**< 拔电瞬间 CHG 先变高,需等满 1s 才当充满 */ uint16_t charging_ms;
uint16_t unplugged_ms;
uint16_t full_ms;
uint16_t full_recheck_ms;
uint8_t full_latched;
} AppChargeState_t; } AppChargeState_t;
/** 电量采样:滑动平均 + 百分比 */ /** 电量采样:滑动平均 + 百分比 */
@@ -221,7 +228,7 @@ static void power_do_poweroff(void *priv)
} }
/** /**
* @brief 充电检测:CHG 低=充电中;VPWR 在且 CHG 高满 1s=充满;拔电报 USB_OUT * @brief TP4056 CHRG/STDBY 组合检测,稳定状态变化后报告 USB 事件
* @param dt 距上次调用的毫秒数 * @param dt 距上次调用的毫秒数
* @return USB 插拔边沿事件 * @return USB 插拔边沿事件
*/ */
@@ -229,37 +236,71 @@ static AppPowerEvt_t power_charge_tick(uint16_t dt)
{ {
AppChargeState_t *c = &s_power.charge; AppChargeState_t *c = &s_power.charge;
uint8_t chg_low = bsp_chg_is_low(); uint8_t chg_low = bsp_chg_is_low();
uint8_t vpwr = bsp_vpwr_is_online(); uint8_t stby_low = bsp_stby_is_low();
uint8_t usb; uint8_t usb = c->usb_online;
AppPowerEvt_t evt = APP_POWER_EVT_NONE; AppPowerEvt_t evt = APP_POWER_EVT_NONE;
if (chg_low) { if (chg_low && stby_low) {
/* CHG 拉低:正在充电,红灯 */ /* 00 is invalid: keep the previous stable state. */
c->charging_ms = 0;
c->unplugged_ms = 0;
c->full_ms = 0; c->full_ms = 0;
c->full_recheck_ms = 0;
} else if (!chg_low && !stby_low) {
/* 11: charger absent. */
c->charging_ms = 0;
c->full_ms = 0;
c->full_recheck_ms = 0;
c->unplugged_ms = app_add_ms(c->unplugged_ms, dt);
if (c->unplugged_ms >= CHG_OFF_CONFIRM_MS) {
c->charge_led = 0;
c->full_latched = 0;
usb = 0;
}
} else if (chg_low) {
/* 01: charging. */
c->unplugged_ms = 0;
c->full_ms = 0;
if (c->full_latched) {
c->charging_ms = 0;
c->full_recheck_ms = app_add_ms(c->full_recheck_ms, dt);
if (c->full_recheck_ms >= CHG_FULL_RECHECK_MS) {
c->full_latched = 0;
c->charge_led = 1; c->charge_led = 1;
gDevData.charge = CHARGE_1; }
usb = 1; usb = 1;
} else if (vpwr) { } else {
/* VPWR 在但 CHG 已高:可能是充满,也可能是拔电瞬间 CHG 先变高。 c->full_recheck_ms = 0;
* 等满 BOARD_CHG_FULL_MS 才当真充满,避免拔电误报绿灯 */ c->charging_ms = app_add_ms(c->charging_ms, dt);
if (c->charging_ms >= CHG_ON_CONFIRM_MS) {
c->charge_led = 1;
usb = 1;
}
}
} else {
/* 10: charge complete. */
c->charging_ms = 0;
c->unplugged_ms = 0;
c->full_recheck_ms = 0;
if (c->full_latched) {
c->charge_led = 2;
usb = 1;
} else {
c->full_ms = app_add_ms(c->full_ms, dt); c->full_ms = app_add_ms(c->full_ms, dt);
if (c->full_ms >= BOARD_CHG_FULL_MS) { if (c->full_ms >= BOARD_CHG_FULL_MS) {
c->charge_led = 2; c->charge_led = 2;
} c->full_latched = 1;
gDevData.charge = (c->charge_led == 1) ? CHARGE_1 : CHARGE_2;
usb = 1; usb = 1;
} else {
/* USB 不在位:充电灯灭 */
c->full_ms = 0;
c->charge_led = 0;
gDevData.charge = CHARGE_2;
usb = 0;
} }
}
}
gDevData.charge = (c->charge_led == 1) ? CHARGE_1 : CHARGE_2;
if (usb != c->usb_online) { if (usb != c->usb_online) {
c->usb_online = usb; c->usb_online = usb;
log_info("usb %s vpwr=%d chg=%d mv=%d pair=%d goto=%d\n", log_info("charge input %s chg_low=%d stby_low=%d pair=%d goto=%d\n",
usb ? "in" : "out", vpwr, chg_low, bsp_vpwr_mv(), usb ? "in" : "out", chg_low, stby_low,
usr_get_pair_flag(), usr_var.usr_goto_pair); usr_get_pair_flag(), usr_var.usr_goto_pair);
usr_var.usr_power_charge_flag = usb ? 1 : 2; usr_var.usr_power_charge_flag = usb ? 1 : 2;
if (usb) { if (usb) {
@@ -272,10 +313,10 @@ static AppPowerEvt_t power_charge_tick(uint16_t dt)
if (c->charge_led != c->charge_led_last) { if (c->charge_led != c->charge_led_last) {
c->charge_led_last = c->charge_led; c->charge_led_last = c->charge_led;
log_info("charge_led=%d chg=%d vpwr=%d mv=%d\n", log_info("charge_led=%d chg_low=%d stby_low=%d\n",
c->charge_led, chg_low, vpwr, bsp_vpwr_mv()); c->charge_led, chg_low, stby_low);
if (c->charge_led == 2) { if (c->charge_led == 2) {
/* 硬件(CHG+VPWR 满 BOARD_CHG_FULL_MS判定充满,电量强制收尾到 /* STDBY 持续为低满 BOARD_CHG_FULL_MS判定充满,电量强制收尾到
* 100%,避免电压拟合曲线因基准/温漂等原因走不到 100% 就卡住 */ * 100%,避免电压拟合曲线因基准/温漂等原因走不到 100% 就卡住 */
app_battery_set_percent(100); app_battery_set_percent(100);
s_power.sample.pct = 100; s_power.sample.pct = 100;
+51
View File
@@ -0,0 +1,51 @@
/******************************************************************************
* @file car_audio_test.c
* @brief Car audio hardware test using the SDK key-tone sine path.
*
* Notes:
* - The SDK sine sample rate is 16 kHz; points is the PCM sample count.
* - freq is specified as actual frequency * 512.
* - decay=0 keeps amplitude constant for observing DAC/PA end behavior.
* - The parameter array has static storage because playback is asynchronous.
******************************************************************************/
#include <stdint.h>
#include "system/includes.h"
#include "tone_player.h"
#include "application/audio_dec_app.h"
#include "car_audio_test.h"
#include "app_audio_debug.h"
static uint16_t s_car_audio_restart_guard_ms;
int Car_Audio_Test_Play(void)
{
/* bird.mp3 is packed as a standalone file in the internal resource area. */
int ret;
MAGIC_AUDIO_LOG("鸟叫接口进入:资源=%s,当前播放状态=%d",
SDFILE_RES_ROOT_PATH"bird.mp3", audio_key_tone_is_play());
ret = audio_key_tone_play_name(SDFILE_RES_ROOT_PATH"bird.mp3", 1);
MAGIC_AUDIO_LOG("鸟叫请求返回=%d(0仅表示请求已提交,不代表已经出声)", ret);
return ret;
}
void Car_Audio_Test_Loop(uint16_t dt_ms)
{
if (s_car_audio_restart_guard_ms > dt_ms) {
s_car_audio_restart_guard_ms -= dt_ms;
return;
}
if (audio_key_tone_is_play()) {
return;
}
if (Car_Audio_Test_Play() == 0) {
/*
* 防止播放请求刚入队、SDK 尚未更新播放状态时被重复提交。
*/
s_car_audio_restart_guard_ms = 50;
}
}
+26
View File
@@ -0,0 +1,26 @@
/******************************************************************************
* @file car_audio_test.h
* @brief Car audio hardware test API using the SDK key-tone sine path.
******************************************************************************/
#include <stdint.h>
#ifndef __CAR_AUDIO_TEST_H__
#define __CAR_AUDIO_TEST_H__
/**
* @brief Play the bird-call MP3 stored in the internal resource area.
*
* The API only queues a request. Playback is asynchronous in the SDK key-tone
* task; it does not wait for completion or block the caller. This test is not
* triggered automatically; call it explicitly from test code.
*
* @return 0=request queued; negative value=module unavailable/request failed.
*/
int Car_Audio_Test_Play(void);
/**
* @brief 开机状态下维护循环测试音。
* @param dt_ms 距离上次调用的毫秒数
*/
void Car_Audio_Test_Loop(uint16_t dt_ms);
#endif /* __CAR_AUDIO_TEST_H__ */
+4 -12
View File
@@ -30,7 +30,6 @@ static volatile uint32_t timerMs;
#define JB_DND_START_MIN_OFFSET 10 #define JB_DND_START_MIN_OFFSET 10
#define JB_DND_END_HOUR_OFFSET 11 #define JB_DND_END_HOUR_OFFSET 11
#define JB_DND_END_MIN_OFFSET 12 #define JB_DND_END_MIN_OFFSET 12
static void jbNoDisturbApply(uint8_t *cfg) static void jbNoDisturbApply(uint8_t *cfg)
{ {
uint8_t i; uint8_t i;
@@ -64,10 +63,10 @@ void userInit(void)
gDevData.play_mode = 0; /* PLAY_MODE_0 (停止复位) */ gDevData.play_mode = 0; /* PLAY_MODE_0 (停止复位) */
gDevData.hand_mode = 0; /* HAND_MODE_0 (忽略) */ gDevData.hand_mode = 0; /* HAND_MODE_0 (忽略) */
gDevData.alm_low_battery = 0; /* DP3 低电量报警 0=关 1=开 */ gDevData.alm_low_battery = 0; /* DP3 低电量报警 0=关 1=开 */
gDevData.beep_trig = 0; /* DP4 声音开关 0=关 1=开 */ gDevData.beep_trig = 1; /* DP4 声音开关 0=关 1=开 */
gDevData.battery = 0; /* DP5 电量上报 */ gDevData.battery = 0; /* DP5 电量上报 */
gDevData.shake_wake = 0; /* DP6 震动触发开机 0=关 1=开 */ gDevData.shake_wake = 0; /* DP6 震动触发开机 0=关 1=开 */
memset(gDevData.no_disturb_enable, 0, 13); /* DP7 勿扰模式开关 */ memset(gDevData.no_disturb_enable, 0, APP_NO_DISTURB_CFG_LEN); /* DP7 勿扰模式开关 */
app_no_disturb_storage_load(gDevData.no_disturb_enable); app_no_disturb_storage_load(gDevData.no_disturb_enable);
gDevData.charge = 0; /* CHARGE_0 (不支持充电) */ gDevData.charge = 0; /* CHARGE_0 (不支持充电) */
gDevData.reserva_dp3 = 0; /* DP10 预留DP3 */ gDevData.reserva_dp3 = 0; /* DP10 预留DP3 */
@@ -148,19 +147,12 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
break; break;
/* ── DP7 勿扰模式开关 (raw) ── */ /* ── DP7 勿扰模式开关 (raw) ── */
case DP_ID_NO_DISTURB_ENABLE: { case DP_ID_NO_DISTURB_ENABLE:
uint8_t previous[JB_DND_LEN];
memcpy(previous, gDevData.no_disturb_enable, JB_DND_LEN);
memcpy(gDevData.no_disturb_enable, ctrl->no_disturb_enable, memcpy(gDevData.no_disturb_enable, ctrl->no_disturb_enable,
JB_DND_LEN); JB_DND_LEN);
jbNoDisturbApply(gDevData.no_disturb_enable); jbNoDisturbApply(gDevData.no_disturb_enable);
if (memcmp(previous, gDevData.no_disturb_enable, JB_DND_LEN) && app_no_disturb_storage_save(gDevData.no_disturb_enable);
!app_no_disturb_storage_save(gDevData.no_disturb_enable)) {
printf("dnd vm write failed\n");
}
break; break;
}
/* ── DP10 预留DP3 (uint32) ── */ /* ── DP10 预留DP3 (uint32) ── */
case DP_ID_RESERVA_DP3: case DP_ID_RESERVA_DP3:
+5 -3
View File
@@ -159,11 +159,13 @@ typedef enum
/* 手动模式 */ /* 手动模式 */
typedef enum typedef enum
{ {
HAND_MODE_0 = 0, /* 停 */ HAND_MODE_0 = 0, /* 上下电机都停 */
HAND_MODE_1 = 1, /* 上部电机探出 */ HAND_MODE_1 = 1, /* 仅上电机:按玩法5波形往复 */
HAND_MODE_2 = 2, /* 下部电机探出 */ HAND_MODE_2 = 2, /* 仅下电机:顺时针 */
HAND_MODE_3 = 3, /* 仅下电机:逆时针 */
} HAND_MODE_t; } HAND_MODE_t;
/* 充电状态 */ /* 充电状态 */
typedef enum typedef enum
{ {
+10
View File
@@ -36,6 +36,7 @@
#include "system/includes.h" #include "system/includes.h"
#include "app_config.h" #include "app_config.h"
#include "asm/dac.h"
#include "app_main.h" #include "app_main.h"
#include "app_task.h" #include "app_task.h"
#include "user_cfg.h" #include "user_cfg.h"
@@ -52,11 +53,13 @@
#include "app_pair.h" #include "app_pair.h"
#include "app_boot.h" #include "app_boot.h"
#include "app_function.h" #include "app_function.h"
#include "app_audio_debug.h"
#include "app_mode.h" #include "app_mode.h"
#include "app_led.h" #include "app_led.h"
#include "key_manager.h" #include "key_manager.h"
#include "asm/power/power_api.h" #include "asm/power/power_api.h"
#define LOG_TAG_CONST APP #define LOG_TAG_CONST APP
#define LOG_TAG "[USR_JB]" #define LOG_TAG "[USR_JB]"
#define LOG_INFO_ENABLE #define LOG_INFO_ENABLE
@@ -285,6 +288,13 @@ void usr_jb_init(void)
{ {
usr_log_boot_version(); /* UART 已在 app_main 起来,按键判定前就能看到版本 */ usr_log_boot_version(); /* UART 已在 app_main 起来,按键判定前就能看到版本 */
MAGIC_AUDIO_LOG("诊断固件启动:编译=%s %s,UART0使能=%dTX引脚编号=%u,波特率=%u",
__DATE__, __TIME__, TCFG_UART0_ENABLE,
(unsigned)TCFG_UART0_TX_PORT, (unsigned)TCFG_UART0_BAUDRATE);
MAGIC_AUDIO_LOG("配置:提示音=%dMP3=%dDAC=%dDAC通道=%dDAC模式=%d,音量类型=%d",
TCFG_KEY_TONE_EN, TCFG_DEC_MP3_ENABLE, TCFG_AUDIO_DAC_ENABLE,
TCFG_AUDIO_DAC_CONNECT_MODE, TCFG_AUDIO_DAC_MODE, SYS_VOL_TYPE);
MAGIC_AUDIO_LOG("鸟叫资源路径=%s,中文显示请使用UTF-8", SDFILE_RES_ROOT_PATH"bird.mp3");
bsp_hw_init(); bsp_hw_init();
app_led_init(); /* 提前到按键判定之前:3s/5s/拒绝开机低电闪都要直接用灯效事件表 */ app_led_init(); /* 提前到按键判定之前:3s/5s/拒绝开机低电闪都要直接用灯效事件表 */
+12 -9
View File
@@ -26,7 +26,7 @@
#define BOARD_LED_ENABLE 1 /**< 1=红绿 LED */ #define BOARD_LED_ENABLE 1 /**< 1=红绿 LED */
#define BOARD_KEY_ENABLE 1 /**< 1=按键 PB1 */ #define BOARD_KEY_ENABLE 1 /**< 1=按键 PB1 */
#define BOARD_CHG_ENABLE 1 /**< 1=充电检测 PG8 + VPWR */ #define BOARD_CHG_ENABLE 1 /**< 1=TP4056: PG8 CHRG + PC5 STDBY */
#define BOARD_MOTOR_ENABLE 1 /**< 1=双电机 U13 + U18 */ #define BOARD_MOTOR_ENABLE 1 /**< 1=双电机 U13 + U18 */
#define BOARD_SHAKE_ENABLE 1 /**< 1=震动输入 PA3 */ #define BOARD_SHAKE_ENABLE 1 /**< 1=震动输入 PA3 */
@@ -39,14 +39,16 @@
#define BOARD_RIGHT_BACKWARD_PIN IO_PORTC_03 /**< U18-INA,右轮后退 */ #define BOARD_RIGHT_BACKWARD_PIN IO_PORTC_03 /**< U18-INA,右轮后退 */
#define BOARD_RIGHT_FORWARD_PIN IO_PORTC_04 /**< U18-INB,右轮前进 */ #define BOARD_RIGHT_FORWARD_PIN IO_PORTC_04 /**< U18-INB,右轮前进 */
#define BOARD_SHAKE_PIN IO_PORTA_03 /**< 震动开机,常闭开关断开时高脉冲有效 */ #define BOARD_SHAKE_PIN IO_PORTA_03 /**< 震动开机,常闭开关断开时高脉冲有效 */
#define BOARD_LED_RED_PIN IO_PORTA_08 /**< 红灯 LED_PWR,低电平亮 */ #define BOARD_LED_RED_PIN IO_PORTA_07 /**< 红灯 LED_PWR,低电平亮 */
#define BOARD_LED_GREEN_PIN IO_PORTA_07 /**< 绿灯 LED_CHG,低电平亮 */ #define BOARD_LED_GREEN_PIN IO_PORTA_08 /**< 绿灯 LED_CHG,低电平亮 */
#define BOARD_KEY_PIN IO_PORTB_01 /**< 按键,低电平按下 */ #define BOARD_KEY_PIN IO_PORTB_01 /**< 按键,低电平按下 */
#define BOARD_CHG_PIN IO_PORTG_08 /**< ME4054 CHG,外部 2.2k 上拉 */ #define BOARD_CHG_PIN IO_PORTG_08 /**< TP4056 CHRG, active low, internal pull-up */
#define BOARD_STDBY_PIN IO_PORTC_05 /**< TP4056 STDBY, active low, internal pull-up */
#define BOARD_LED_ON_LEVEL 0 /**< LED 点亮电平:0=低亮 */ #define BOARD_LED_ON_LEVEL 0 /**< LED 点亮电平:0=低亮 */
#define BOARD_KEY_ACTIVE_LEVEL 0 /**< 按键有效电平:0=按下为低 */ #define BOARD_KEY_ACTIVE_LEVEL 0 /**< 按键有效电平:0=按下为低 */
#define BOARD_CHG_CHARGING_LEVEL 0 /**< CHG 充电中为低 */ #define BOARD_CHG_CHARGING_LEVEL 0 /**< CHG 充电中为低 */
#define BOARD_STDBY_FULL_LEVEL 0 /**< STDBY 充满时为低 */
#define BOARD_SHAKE_ACTIVE_LEVEL 1 /**< 常闭震动开关:断开时高脉冲有效 */ #define BOARD_SHAKE_ACTIVE_LEVEL 1 /**< 常闭震动开关:断开时高脉冲有效 */
@@ -62,9 +64,9 @@
#define BOARD_VBAT_LOW_HYST_MV 50 /**< 低电恢复回差 */ #define BOARD_VBAT_LOW_HYST_MV 50 /**< 低电恢复回差 */
#define BOARD_VBAT_SHUTDOWN_MV 3250 /**< 约 5%,仅开机拦截用:关机状态下 app_battery 尚未运行,只能摸裸电压 */ #define BOARD_VBAT_SHUTDOWN_MV 3250 /**< 约 5%,仅开机拦截用:关机状态下 app_battery 尚未运行,只能摸裸电压 */
#define BOARD_BATTERY_SHUTDOWN_PCT 5 /**< 运行中显示电量 <= 此值才自动关机,跟 APP 看到的百分比对齐 */ #define BOARD_BATTERY_SHUTDOWN_PCT 5 /**< 运行中显示电量 <= 此值才自动关机,跟 APP 看到的百分比对齐 */
#define BOARD_VPWR_ONLINE_MV 4000 /**< VPWR 判定 USB 插入 */ #define BOARD_VPWR_ONLINE_MV 4000
#define BOARD_VPWR_OFF_MV 1500 /**< 低于此值认定已拔出 */ #define BOARD_VPWR_OFF_MV 1500
#define BOARD_CHG_FULL_MS 1000 /**< CHG 已高且 VPWR 在,满 1s 认充满 */ #define BOARD_CHG_FULL_MS 1000 /**< STDBY low confirmation time */
/*============================================================================*/ /*============================================================================*/
/* 按键 / 灯效 */ /* 按键 / 灯效 */
@@ -105,6 +107,8 @@
#define BOARD_MOTOR_REVERSE_MS 1 /**< 换向前先松开,防 H 桥直通 */ #define BOARD_MOTOR_REVERSE_MS 1 /**< 换向前先松开,防 H 桥直通 */
#define BOARD_HAND_PULSE_MS 5000 /**< 手动右转/左转单次最长 5s */ #define BOARD_HAND_PULSE_MS 5000 /**< 手动右转/左转单次最长 5s */
#define BOARD_HAND_STEP_MS 1500 /**< DP2 下电机单轮动作时长(=半圈),按实测标定 */
#define BOARD_HAND_QUEUE_LEN 8
#define BOARD_MOTOR_PWM_HZ 200 /**< 弹力魔盒验证过的 MCPWM 频率(Hz) */ #define BOARD_MOTOR_PWM_HZ 200 /**< 弹力魔盒验证过的 MCPWM 频率(Hz) */
#define BOARD_MOTOR_PWM_DUTY 8000 /**< 占空比 0~10000=0%~100%80% */ #define BOARD_MOTOR_PWM_DUTY 8000 /**< 占空比 0~10000=0%~100%80% */
#define BOARD_MOTOR_PWM_IDLE_CLOSE 1 /**< 1=空闲/轻睡关 MCPWM;0=保持开着,方便对比待机电流 */ #define BOARD_MOTOR_PWM_IDLE_CLOSE 1 /**< 1=空闲/轻睡关 MCPWM;0=保持开着,方便对比待机电流 */
@@ -124,8 +128,7 @@
#define BOARD_SHAKE_TRIGGER_WINDOW_MS 250u /**< 保留窗口参数,便于恢复多脉冲策略 */ #define BOARD_SHAKE_TRIGGER_WINDOW_MS 250u /**< 保留窗口参数,便于恢复多脉冲策略 */
#define BOARD_SHAKE_POLL_MS 10u /**< 与业务调度器共用的采样节拍 */ #define BOARD_SHAKE_POLL_MS 10u /**< 与业务调度器共用的采样节拍 */
/* PG8/CHG_ON is the only fitted USB-related signal that changes while the /* PG8/CHRG is used to detect charge insertion while in softoff. */
* product is in softoff; VPWR is disconnected on boards with R18 not fitted. */
#define BOARD_CHG_WAKEUP_INDEX 3u #define BOARD_CHG_WAKEUP_INDEX 3u
#endif /* __BOARD_PIN_H__ */ #endif /* __BOARD_PIN_H__ */
+20 -3
View File
@@ -233,13 +233,20 @@ BspHw_Ret_t bsp_hw_init(void)
#if BOARD_CHG_ENABLE #if BOARD_CHG_ENABLE
/* PORTG 作数字输入必须开 dieh,否则读不到 ME4054 CHG */ /* PORTG 作数字输入必须开 dieh,否则读不到 ME4054 CHG */
gpio_disable_fun_output_port(BOARD_CHG_PIN); gpio_disable_fun_output_port(BOARD_CHG_PIN);
gpio_set_pull_up(BOARD_CHG_PIN, 0); /* ME4054 CHRG is open-drain/high-Z when not charging. Keep PG8 pulled
* high so the digital input has a deterministic level in that state. */
gpio_set_pull_up(BOARD_CHG_PIN, 1);
gpio_set_pull_down(BOARD_CHG_PIN, 0); gpio_set_pull_down(BOARD_CHG_PIN, 0);
gpio_set_die(BOARD_CHG_PIN, 1); gpio_set_die(BOARD_CHG_PIN, 1);
gpio_set_dieh(BOARD_CHG_PIN, 1); gpio_set_dieh(BOARD_CHG_PIN, 1);
gpio_direction_input(BOARD_CHG_PIN); gpio_direction_input(BOARD_CHG_PIN);
adc_add_sample_ch(AD_CH_LDO5V);
adc_set_sample_freq(AD_CH_LDO5V, 500); gpio_disable_fun_output_port(BOARD_STDBY_PIN);
gpio_set_pull_up(BOARD_STDBY_PIN, 1);
gpio_set_pull_down(BOARD_STDBY_PIN, 0);
gpio_set_die(BOARD_STDBY_PIN, 1);
gpio_set_dieh(BOARD_STDBY_PIN, 1);
gpio_direction_input(BOARD_STDBY_PIN);
#endif #endif
#if BOARD_MOTOR_ENABLE #if BOARD_MOTOR_ENABLE
@@ -423,6 +430,16 @@ uint8_t bsp_chg_is_low(void)
#endif #endif
} }
/** @return 1 when TP4056 STDBY is low; otherwise 0. */
uint8_t bsp_stby_is_low(void)
{
#if BOARD_CHG_ENABLE
return (uint8_t)(gpio_read(BOARD_STDBY_PIN) == BOARD_STDBY_FULL_LEVEL);
#else
return 0;
#endif
}
/** /**
* @brief 读取电池电压 * @brief 读取电池电压
* @return 电池电压,单位 mV * @return 电池电压,单位 mV
+3
View File
@@ -101,6 +101,9 @@ uint8_t bsp_key_is_pressed(void);
*/ */
uint8_t bsp_chg_is_low(void); uint8_t bsp_chg_is_low(void);
/** @return 1 when TP4056 STDBY is low; otherwise 0. */
uint8_t bsp_stby_is_low(void);
/** /**
* @brief 读取电池电压 * @brief 读取电池电压
* @return 电池电压,单位 mV * @return 电池电压,单位 mV
Binary file not shown.
@@ -1 +0,0 @@
3DBA0ACD41A68B534365C721F7B23619914B4106E1024B5592A0A49D1DD417152E4DCF18
@@ -4,6 +4,7 @@ cd %~dp0
copy ..\..\script.ver . copy ..\..\script.ver .
copy ..\..\tone.cfg . copy ..\..\tone.cfg .
copy ..\..\bird.mp3 .
copy ..\..\p11_code.bin . copy ..\..\p11_code.bin .
copy ..\..\br28loader.bin . copy ..\..\br28loader.bin .
copy ..\..\ota.bin . copy ..\..\ota.bin .
@@ -15,7 +16,7 @@ if not exist p11_code.bin (
exit /b 1 exit /b 1
) )
set "ISD_CMD=..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg p11_code.bin -uboot_compress" set "ISD_CMD=..\..\isd_download.exe ..\..\isd_config.ini -tonorflash -dev br28 -boot 0x120000 -div8 -wait 300 -uboot ..\..\uboot.boot -app ..\..\app.bin -res ..\..\cfg_tool.bin tone.cfg bird.mp3 p11_code.bin -uboot_compress"
if not exist RS-5B88.key ( if not exist RS-5B88.key (
echo [download] ERROR: RS-5B88.key not found echo [download] ERROR: RS-5B88.key not found
-62
View File
@@ -1,62 +0,0 @@
# SOC 代码生成模板 — 分支索引
本仓库按 **「厂商-型号」** 组织分支,每个分支是一套完整的 SOC 工程模板。
远程仓库:[soc-codegen-template](https://git.jianbao-tech.com/pets-device/soc-codegen-template)
---
## 分支列表
| 分支 | 厂商 | 型号 | 平台 | 默认能力 | 状态 |
|------|------|------|------|----------|------|
| [`JieLi-JL7016`](https://git.jianbao-tech.com/pets-device/soc-codegen-template/src/branch/JieLi-JL7016) | 杰理 JieLi | JL7016 / AC7016C | BR28 | 耳机 SDK + BLE + jb_protocol + OTA | ✅ 可用 |
> 新模板上线后在此表追加一行即可。
---
## 如何获取某 SOC 模板
### 见宝工具箱 / 自动化脚本
```bash
git clone https://git.jianbao-tech.com/pets-device/soc-codegen-template.git
cd soc-codegen-template
git checkout JieLi-JL7016
```
### 仅下载指定分支(浅克隆)
```bash
git clone --branch JieLi-JL7016 --single-branch \
https://git.jianbao-tech.com/pets-device/soc-codegen-template.git jl7016-template
```
---
## 分支命名规范
```
<厂商>-<型号>
```
示例:`JieLi-JL7016``JieLi-AC701N`
- 默认包含耳机应用与 jb_protocol,分支名**不加**多余后缀
- 同一芯片多种工程结构差异过大时,再考虑加后缀:`JieLi-JL7016-dongle`
---
## 新增 SOC 模板(维护者)
1.`main` 拉新分支:`git checkout -b <厂商>-<型号> main`
2. 合入该 SOC 完整工程(apps + cpu + include_lib + tools
3. 更新本文件分支表 + `main/README.md` 快速索引
4. 推送分支并在 Gitea 设为受保护分支(可选)
---
## 各分支 README
每个 SOC 分支根目录有独立的 `README.md`(构建、打包、协议对接说明)。
-1
View File
@@ -172,7 +172,6 @@ u8 *syscfg_ptr_read(u16 item_id, u16 *len);
#define CFG_USER_PLAN_INFO1 25+1 #define CFG_USER_PLAN_INFO1 25+1
#define CFG_USER_BATTERY_LEVEL 26+1 #define CFG_USER_BATTERY_LEVEL 26+1
#define CFG_USER_NO_DISTURB 28
#define CFG_USER_DEFINE_END 49 #define CFG_USER_DEFINE_END 49
+49
View File
@@ -0,0 +1,49 @@
# 改动日志
日期:2026-09-08
## 本次 MAGIC_BOX_FW 音频与充电对齐
1. 文件:`apps/earphone/board/br28/board_jl701n_demo_cfg.h`
- 行号:104,369(修改后行号以当前文件为准)
- 原代码:`TCFG_KEY_TONE_EN``DISABLE`DAC 模式为 `DAC_MODE_L_SINGLE`
- 修改后:启用 `TCFG_KEY_TONE_EN`DAC 模式改为 `DAC_MODE_H2_SINGLE`
- 原因:启用 SDK key-tone 播放任务,并匹配 FK_CAR_FW 使用 ROUT 单端输出的配置。
2. 文件:`apps/usr_app/app_function.c`
- 行号:约 26、254-259
- 原代码:模式改变时只调用 `app_led_request_mode_blink()`
- 修改后:模式改变且 `mode != PLAY_MODE_0` 时调用 `Car_Audio_Test_Play()`
- 原因:每次实际切换到运行模式时播放一次鸟叫;不放入 1ms tick,因此不会连续调用。
3. 文件:`apps/usr_app/car_audio_test.c``apps/usr_app/car_audio_test.h`
- 原代码:MAGIC_BOX_FW 未纳入该音频测试模块。
- 修改后:加入 FK_CAR_FW 当前版本的鸟叫播放接口,路径为 `mnt/sdfile/res/bird.mp3`
- 原因:提供模式切换调用的播放实现。
4. 文件:`Makefile`
- 行号:约 414
- 原代码:源文件列表不含 `apps/usr_app/car_audio_test.c`
- 修改后:加入该源文件。
- 原因:确保编译、链接播放接口实现。
5. 文件:`cpu/br28/tools/download/earphone/download_app_ota.bat`
- 行号:约 5、18
- 原代码:未复制 `bird.mp3`,资源参数只有 `tone.cfg p11_code.bin`
- 修改后:复制 `bird.mp3`,并在 `-res` 参数中加入 `bird.mp3`
- 原因:将鸟叫文件打包进内部资源区。
6. 文件:`cpu/br28/tools/bird.mp3`
- 原代码:MAGIC_BOX_FW 中缺少可供下载脚本复制的鸟叫文件。
- 修改后:加入当前 FK_CAR_FW 使用的 `bird.mp3`
- 原因:提供资源打包输入文件。
说明:MAGIC_BOX_FW 当前 `app_power.c` 的充电状态主逻辑已经是 CHRG+STDBY 组合检测,与当前 FK_CAR_FW 一致;本次未重复改写该逻辑,保留其 VPWR 辅助函数未被应用层使用。
7. 文件:`apps/earphone/board/br28/board_jl701n_demo_cfg.h`
- 行号:825
- 原代码:`#define TCFG_DRC_ENABLE 0 /*DRC .../`(块注释未闭合)。
- 修改后:将该注释改为合法的 `/*DRC */`
- 原因:首次完整编译发现该处导致 `line 828: expected identifier or '('`,属于当前工程已有的语法错误,必须修复后才能验证本次功能。
8. 同一配置文件第1197行:补齐损坏的 `#error` 字符串结束引号,消除预处理语法错误。