Compare commits

..
1 Commits
22 changed files with 871 additions and 528 deletions
+9
View File
@@ -833,6 +833,15 @@
<Option compilerVar="CC" />
</Unit>
<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">
<Option compilerVar="CC" />
</Unit>
+2
View File
@@ -411,6 +411,8 @@ c_SRC_FILES := \
apps/usr_app/app_pair.c \
apps/usr_app/app_boot.c \
apps/usr_app/app_function.c \
apps/usr_app/app_no_disturb.c \
apps/usr_app/car_audio_test.c \
apps/usr_app/app_shake_wake.c \
apps/usr_le_code/ble_proto.c \
apps/usr_le_code/bleproto.c \
+3 -3
View File
@@ -236,9 +236,9 @@ _notify:
}
if (key_event_remap(&e)) {
sys_event_notify(&e);
#if TCFG_KEY_TONE_EN
audio_key_tone_play();
#endif
// #if TCFG_KEY_TONE_EN
// audio_key_tone_play();
// #endif
}
_scan_end:
scan_para->last_key = cur_key_value;
+3 -3
View File
@@ -735,8 +735,7 @@ struct port_wakeup port0 = {
};
#if BOARD_CHG_ENABLE
/* R18 is not fitted on CBC4, so VBUS never reaches VPWR in softoff. Wake on
* the fitted ME4054 CHG_ON signal instead; it falls when charging starts. */
/* TP4056 CHRG falls when charging starts; use it for softoff charge wake. */
struct port_wakeup board_chg_wakeup_port = {
.pullup_down_enable = ENABLE,
.edge = FALLING_EDGE,
@@ -1001,8 +1000,9 @@ void board_set_soft_poweroff(void)
soff_gpio_protect(TCFG_IOKEY_POWER_ONE_PORT);
#endif
#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_STDBY_PIN);
#endif
#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 在位(充电口有电):说明是插着电源,不是用户凭空按键开机 */
for (i = 0; i < 10; i++) {
if (bsp_chg_is_low() || bsp_vpwr_is_online()
|| get_ldo5v_online_hw()) {
/* VPWR/LDO5V are the authoritative external-power indicators.
* 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");
return 1;
}
+21 -19
View File
@@ -19,6 +19,9 @@
#include "app_mode.h"
#include "app_led.h"
#include "app_shake_wake.h"
#include "app_no_disturb.h"
#include "car_audio_test.h"
#include "app_audio_debug.h"
#include "app_time_util.h"
#include "bsp_hw.h"
#include "board_pin.h"
@@ -46,7 +49,6 @@ typedef struct {
volatile uint8_t play_write_pending;
volatile uint8_t play_write_mode;
uint8_t shake_wake;
uint8_t no_disturb;
} AppFunctionCtx_t;
static AppFunctionCtx_t s_func;
@@ -71,7 +73,6 @@ void app_function_init(void)
app_shake_wake_init(function_shake_wake_allowed,
function_shake_wake_trigger);
s_func.shake_wake = !!gDevData.shake_wake;
s_func.no_disturb = !!gDevData.no_disturb_enable[0];
app_shake_wake_set_enable(s_func.shake_wake);
}
@@ -105,12 +106,6 @@ void app_function_set_shake_wake(uint8_t enable)
app_shake_wake_set_enable(s_func.shake_wake);
}
void app_function_set_no_disturb(uint8_t enable)
{
s_func.no_disturb = !!enable;
app_shake_wake_reset();
}
/**
* @brief 跟随 APP 下发的 DP0/DP1,并处理 DP2 手动点动
* @return 无
@@ -120,10 +115,6 @@ void app_function_poll(void)
if (s_func.shake_wake != !!gDevData.shake_wake) {
app_function_set_shake_wake(gDevData.shake_wake);
}
if (s_func.no_disturb != !!gDevData.no_disturb_enable[0]) {
app_function_set_no_disturb(gDevData.no_disturb_enable[0]);
}
if (s_func.power_write_pending) {
uint8_t enable = s_func.power_write_value;
s_func.power_write_pending = 0;
@@ -265,6 +256,10 @@ static void function_play_mode_apply(uint8_t mode)
{
uint8_t old_mode = s_func.play_mode;
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;
}
@@ -284,10 +279,17 @@ static void function_play_mode_apply(uint8_t mode)
} else {
app_mode_start(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();
}
}
}
/**
* @brief 跟随 APP 下发的 DP1 自动模式
@@ -384,7 +386,7 @@ static void function_hand_poll(void)
s_func.play_mode = 0;
s_func.play_ms = 0;
gDevData.play_mode = 0;
app_mode_stop(); /* 自动切手动:先停自动玩法 */
app_mode_stop();
s_func.hand_busy = 1;
s_func.hand_ms = 0;
gDevData.hand_mode = cmd;
@@ -395,10 +397,10 @@ static void function_hand_poll(void)
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);
app_led_request_mode_blink();
if (gDevData.beep_trig) {
Car_Audio_Test_Play();
}
} else {
gDevData.hand_mode = HAND_MODE_0;
if (s_func.hand_busy) {
@@ -501,7 +503,7 @@ static uint8_t function_power_on(uint8_t show_hint)
static uint8_t function_shake_wake_allowed(void)
{
return s_func.shake_wake &&
!s_func.no_disturb &&
!app_no_disturb_is_active() &&
!s_func.app_power &&
!app_power_usb_online() &&
!app_power_poweroff_pending() &&
-3
View File
@@ -39,9 +39,6 @@ void app_function_dp_hand_write(uint8_t cmd);
/** CBC4 DP6 震动开机开关。 */
void app_function_set_shake_wake(uint8_t enable);
/** 勿扰时段是否正在生效;生效时屏蔽震动开机。 */
void app_function_set_no_disturb(uint8_t enable);
/**
* @brief 跟随 APP 下发的 DP0/DP1,并处理 DP2 手动点动,每个业务 tick 调用一次
* @return 无
+145
View File
@@ -0,0 +1,145 @@
#include "app_no_disturb.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)
typedef struct __attribute__((packed)) {
uint16_t magic;
uint8_t version;
uint8_t cfg[APP_NO_DISTURB_CFG_LEN];
} AppNoDisturbVm_t;
typedef struct {
uint8_t enabled;
uint8_t weekdays_mask;
uint16_t start_minute;
uint16_t end_minute;
} AppNoDisturbCtx_t;
static AppNoDisturbCtx_t s_no_disturb;
static uint8_t app_no_disturb_cfg_valid(const uint8_t cfg[APP_NO_DISTURB_CFG_LEN])
{
uint8_t i;
if (!cfg || cfg[0] > 1U || cfg[9] >= 24U || cfg[11] >= 24U ||
cfg[10] >= 60U || cfg[12] >= 60U) {
return 0;
}
for (i = 0; i < 7U; i++) {
if (cfg[2U + i] > 1U) {
return 0;
}
}
return 1;
}
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_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 const uint8_t month_offset[12] = {
0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4
};
uint32_t year = time->year;
uint8_t sunday0;
if (time->month < 3U) {
year--;
}
sunday0 = (uint8_t)((year + year / 4U - year / 100U + year / 400U +
month_offset[time->month - 1U] + time->day) % 7U);
return (uint8_t)((sunday0 + 6U) % 7U);
}
static uint8_t app_no_disturb_day_selected(uint8_t weekday)
{
return (uint8_t)((s_no_disturb.weekdays_mask & (1U << weekday)) != 0U);
}
uint8_t app_no_disturb_is_active_at(const struct sys_time *time)
{
uint8_t weekday;
uint16_t now_minute;
if (!time || !s_no_disturb.enabled || !s_no_disturb.weekdays_mask ||
s_no_disturb.start_minute >= APP_MINUTES_PER_DAY ||
s_no_disturb.end_minute >= APP_MINUTES_PER_DAY ||
time->month < 1U || time->month > 12U || time->day < 1U ||
time->day > 31U || time->hour > 23U || time->min > 59U) {
return 0;
}
weekday = app_no_disturb_weekday_monday0(time);
now_minute = (uint16_t)(time->hour * 60U + time->min);
if (s_no_disturb.start_minute == s_no_disturb.end_minute) {
return app_no_disturb_day_selected(weekday);
}
if (s_no_disturb.start_minute < s_no_disturb.end_minute) {
return app_no_disturb_day_selected(weekday) &&
now_minute >= s_no_disturb.start_minute &&
now_minute < s_no_disturb.end_minute;
}
if (now_minute >= s_no_disturb.start_minute) {
return app_no_disturb_day_selected(weekday);
}
if (now_minute < s_no_disturb.end_minute) {
return app_no_disturb_day_selected((uint8_t)((weekday + 6U) % 7U));
}
return 0;
}
uint8_t app_no_disturb_is_active(void)
{
struct sys_time time;
if (!usr_rtc_get_time(&time)) {
return 0;
}
return app_no_disturb_is_active_at(&time);
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef __APP_NO_DISTURB_H__
#define __APP_NO_DISTURB_H__
#include <stdint.h>
#include "system/sys_time.h"
#define APP_NO_DISTURB_CFG_LEN 13
/* DP7: bytes 2..8 are Monday..Sunday, byte 1 is reserved. */
void app_no_disturb_configure(uint8_t enable, uint8_t weekdays_mask,
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_at(const struct sys_time *time);
#endif /* __APP_NO_DISTURB_H__ */
+71 -30
View File
@@ -36,14 +36,21 @@
#define BAT_BOOT_MS 3000 /* 上电 3s 内不因低电深睡 */
#define BAT_LOG_MS 10000
#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 才进低电告警(仅闪灯,不关机) */
/** 充电检测:CHG/VPWR 消抖后的结果 */
/** TP4056 CHRG/STDBY debounced charging state. */
typedef struct {
uint8_t usb_online;
uint8_t charge_led; /**< 0=无 1=充电红 2=充满绿 */
uint8_t charge_led_last; /**< 仅用于变化时打日志 */
uint16_t full_ms; /**< 拔电瞬间 CHG 先变高,需等满 1s 才当充满 */
uint8_t charge_led;
uint8_t charge_led_last;
uint16_t charging_ms;
uint16_t unplugged_ms;
uint16_t full_ms;
uint16_t full_recheck_ms;
uint8_t full_latched;
} 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 距上次调用的毫秒数
* @return USB 插拔边沿事件
*/
@@ -229,37 +236,71 @@ static AppPowerEvt_t power_charge_tick(uint16_t dt)
{
AppChargeState_t *c = &s_power.charge;
uint8_t chg_low = bsp_chg_is_low();
uint8_t vpwr = bsp_vpwr_is_online();
uint8_t usb;
uint8_t stby_low = bsp_stby_is_low();
uint8_t usb = c->usb_online;
AppPowerEvt_t evt = APP_POWER_EVT_NONE;
if (chg_low) {
/* CHG 拉低:正在充电,红灯 */
if (chg_low && stby_low) {
/* 00 is invalid: keep the previous stable state. */
c->charging_ms = 0;
c->unplugged_ms = 0;
c->full_ms = 0;
c->charge_led = 1;
gDevData.charge = CHARGE_1;
usb = 1;
} else if (vpwr) {
/* VPWR 在但 CHG 已高:可能是充满,也可能是拔电瞬间 CHG 先变高。
* 等满 BOARD_CHG_FULL_MS 才当真充满,避免拔电误报绿灯 */
c->full_ms = app_add_ms(c->full_ms, dt);
if (c->full_ms >= BOARD_CHG_FULL_MS) {
c->charge_led = 2;
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;
}
gDevData.charge = (c->charge_led == 1) ? CHARGE_1 : CHARGE_2;
usb = 1;
} else {
/* USB 不在位:充电灯灭 */
} else if (chg_low) {
/* 01: charging. */
c->unplugged_ms = 0;
c->full_ms = 0;
c->charge_led = 0;
gDevData.charge = CHARGE_2;
usb = 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;
}
usb = 1;
} else {
c->full_recheck_ms = 0;
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);
if (c->full_ms >= BOARD_CHG_FULL_MS) {
c->charge_led = 2;
c->full_latched = 1;
usb = 1;
}
}
}
gDevData.charge = (c->charge_led == 1) ? CHARGE_1 : CHARGE_2;
if (usb != c->usb_online) {
c->usb_online = usb;
log_info("usb %s vpwr=%d chg=%d mv=%d pair=%d goto=%d\n",
usb ? "in" : "out", vpwr, chg_low, bsp_vpwr_mv(),
log_info("charge input %s chg_low=%d stby_low=%d pair=%d goto=%d\n",
usb ? "in" : "out", chg_low, stby_low,
usr_get_pair_flag(), usr_var.usr_goto_pair);
usr_var.usr_power_charge_flag = usb ? 1 : 2;
if (usb) {
@@ -272,10 +313,10 @@ static AppPowerEvt_t power_charge_tick(uint16_t dt)
if (c->charge_led != c->charge_led_last) {
c->charge_led_last = c->charge_led;
log_info("charge_led=%d chg=%d vpwr=%d mv=%d\n",
c->charge_led, chg_low, vpwr, bsp_vpwr_mv());
log_info("charge_led=%d chg_low=%d stby_low=%d\n",
c->charge_led, chg_low, stby_low);
if (c->charge_led == 2) {
/* 硬件(CHG+VPWR 满 BOARD_CHG_FULL_MS判定充满,电量强制收尾到
/* STDBY 持续为低满 BOARD_CHG_FULL_MS判定充满,电量强制收尾到
* 100%,避免电压拟合曲线因基准/温漂等原因走不到 100% 就卡住 */
app_battery_set_percent(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__ */
+17 -63
View File
@@ -14,7 +14,7 @@
#include "jb_product.h"
#include "app_function.h"
#include "usr_rtc.h"
#include "app_no_disturb.h"
/* ════════════════════════════════════════════════════════════════
* 全局变量
@@ -30,70 +30,26 @@ static volatile uint32_t timerMs;
#define JB_DND_START_MIN_OFFSET 10
#define JB_DND_END_HOUR_OFFSET 11
#define JB_DND_END_MIN_OFFSET 12
static uint8_t jbLastNoDisturbActive;
/* Return weekday with Monday=0, matching DP7 bytes 2..8. */
static uint8_t jbWeekdayMonday0(const struct sys_time *time)
{
static const uint8_t monthOffset[12] = {
0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4
};
uint16_t year = time->year;
uint8_t sunday0;
if (time->month < 3) {
year--;
}
sunday0 = (uint8_t)((year + year / 4U - year / 100U + year / 400U +
monthOffset[time->month - 1U] + time->day) % 7U);
return (uint8_t)((sunday0 + 6U) % 7U);
}
static void jbNoDisturbNormalize(uint8_t *cfg)
static void jbNoDisturbApply(uint8_t *cfg)
{
uint8_t i;
uint8_t weekdays = 0;
uint16_t start_minute;
uint16_t end_minute;
cfg[JB_DND_ENABLE_OFFSET] = !!cfg[JB_DND_ENABLE_OFFSET];
for (i = 0; i < 7; i++) {
cfg[JB_DND_WEEK_OFFSET + i] = !!cfg[JB_DND_WEEK_OFFSET + i];
}
}
static uint8_t jbNoDisturbScheduleValid(const uint8_t *cfg)
{
uint8_t i;
if (cfg[JB_DND_START_HOUR_OFFSET] >= 24 ||
cfg[JB_DND_END_HOUR_OFFSET] >= 24 ||
cfg[JB_DND_START_MIN_OFFSET] >= 60 ||
cfg[JB_DND_END_MIN_OFFSET] >= 60) {
return 0;
}
for (i = 0; i < 7; i++) {
if (cfg[JB_DND_WEEK_OFFSET + i]) {
return 1;
weekdays |= (uint8_t)(1U << i);
}
}
return 0;
}
static uint8_t jbNoDisturbActive(void)
{
/* Match the verified product behavior: DP7 byte 0 is the global
* no-disturb switch. Schedule bytes are retained and reported, but do
* not gate the local vibration wake path. */
return !!gDevData.no_disturb_enable[JB_DND_ENABLE_OFFSET];
}
static void jbNoDisturbUpdate(void)
{
uint8_t active = jbNoDisturbActive();
if (active == jbLastNoDisturbActive) {
return;
}
jbLastNoDisturbActive = active;
app_function_set_no_disturb(active);
start_minute = (uint16_t)(cfg[JB_DND_START_HOUR_OFFSET] * 60U +
cfg[JB_DND_START_MIN_OFFSET]);
end_minute = (uint16_t)(cfg[JB_DND_END_HOUR_OFFSET] * 60U +
cfg[JB_DND_END_MIN_OFFSET]);
app_no_disturb_configure(cfg[JB_DND_ENABLE_OFFSET], weekdays,
start_minute, end_minute);
}
/* ════════════════════════════════════════════════════════════════
@@ -110,11 +66,11 @@ void userInit(void)
gDevData.beep_trig = 0; /* DP4 声音开关 0=关 1=开 */
gDevData.battery = 0; /* DP5 电量上报 */
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);
gDevData.charge = 0; /* CHARGE_0 (不支持充电) */
gDevData.reserva_dp3 = 0; /* DP10 预留DP3 */
jbLastNoDisturbActive = 0xff;
jbNoDisturbUpdate();
jbNoDisturbApply(gDevData.no_disturb_enable);
}
/* ════════════════════════════════════════════════════════════════
@@ -123,8 +79,6 @@ void userInit(void)
* ════════════════════════════════════════════════════════════════ */
void userHandle(void)
{
jbNoDisturbUpdate();
/* ── 可上报 DP (RO / RW): 用户数据采集 ── */
// gDevData.power = read_sensor(); /* DP0 开关 */
// gDevData.play_mode = read_sensor(); /* DP1 自动模式 */
@@ -196,8 +150,8 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
case DP_ID_NO_DISTURB_ENABLE:
memcpy(gDevData.no_disturb_enable, ctrl->no_disturb_enable,
JB_DND_LEN);
jbNoDisturbNormalize(gDevData.no_disturb_enable);
jbNoDisturbUpdate();
jbNoDisturbApply(gDevData.no_disturb_enable);
app_no_disturb_storage_save(gDevData.no_disturb_enable);
break;
/* ── DP10 预留DP3 (uint32) ── */
+10
View File
@@ -36,6 +36,7 @@
#include "system/includes.h"
#include "app_config.h"
#include "asm/dac.h"
#include "app_main.h"
#include "app_task.h"
#include "user_cfg.h"
@@ -52,11 +53,13 @@
#include "app_pair.h"
#include "app_boot.h"
#include "app_function.h"
#include "app_audio_debug.h"
#include "app_mode.h"
#include "app_led.h"
#include "key_manager.h"
#include "asm/power/power_api.h"
#define LOG_TAG_CONST APP
#define LOG_TAG "[USR_JB]"
#define LOG_INFO_ENABLE
@@ -285,6 +288,13 @@ void usr_jb_init(void)
{
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();
app_led_init(); /* 提前到按键判定之前:3s/5s/拒绝开机低电闪都要直接用灯效事件表 */
+10 -9
View File
@@ -26,7 +26,7 @@
#define BOARD_LED_ENABLE 1 /**< 1=红绿 LED */
#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_SHAKE_ENABLE 1 /**< 1=震动输入 PA3 */
@@ -39,14 +39,16 @@
#define BOARD_RIGHT_BACKWARD_PIN IO_PORTC_03 /**< U18-INA,右轮后退 */
#define BOARD_RIGHT_FORWARD_PIN IO_PORTC_04 /**< U18-INB,右轮前进 */
#define BOARD_SHAKE_PIN IO_PORTA_03 /**< 震动开机,常闭开关断开时高脉冲有效 */
#define BOARD_LED_RED_PIN IO_PORTA_08 /**< 红灯 LED_PWR,低电平亮 */
#define BOARD_LED_GREEN_PIN IO_PORTA_07 /**< 绿灯 LED_CHG,低电平亮 */
#define BOARD_LED_RED_PIN IO_PORTA_07 /**< 红灯 LED_PWR,低电平亮 */
#define BOARD_LED_GREEN_PIN IO_PORTA_08 /**< 绿灯 LED_CHG,低电平亮 */
#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_KEY_ACTIVE_LEVEL 0 /**< 按键有效电平:0=按下为低 */
#define BOARD_CHG_CHARGING_LEVEL 0 /**< CHG 充电中为低 */
#define BOARD_STDBY_FULL_LEVEL 0 /**< STDBY 充满时为低 */
#define BOARD_SHAKE_ACTIVE_LEVEL 1 /**< 常闭震动开关:断开时高脉冲有效 */
@@ -62,9 +64,9 @@
#define BOARD_VBAT_LOW_HYST_MV 50 /**< 低电恢复回差 */
#define BOARD_VBAT_SHUTDOWN_MV 3250 /**< 约 5%,仅开机拦截用:关机状态下 app_battery 尚未运行,只能摸裸电压 */
#define BOARD_BATTERY_SHUTDOWN_PCT 5 /**< 运行中显示电量 <= 此值才自动关机,跟 APP 看到的百分比对齐 */
#define BOARD_VPWR_ONLINE_MV 4000 /**< VPWR 判定 USB 插入 */
#define BOARD_VPWR_OFF_MV 1500 /**< 低于此值认定已拔出 */
#define BOARD_CHG_FULL_MS 1000 /**< CHG 已高且 VPWR 在,满 1s 认充满 */
#define BOARD_VPWR_ONLINE_MV 4000
#define BOARD_VPWR_OFF_MV 1500
#define BOARD_CHG_FULL_MS 1000 /**< STDBY low confirmation time */
/*============================================================================*/
/* 按键 / 灯效 */
@@ -124,8 +126,7 @@
#define BOARD_SHAKE_TRIGGER_WINDOW_MS 250u /**< 保留窗口参数,便于恢复多脉冲策略 */
#define BOARD_SHAKE_POLL_MS 10u /**< 与业务调度器共用的采样节拍 */
/* PG8/CHG_ON is the only fitted USB-related signal that changes while the
* product is in softoff; VPWR is disconnected on boards with R18 not fitted. */
/* PG8/CHRG is used to detect charge insertion while in softoff. */
#define BOARD_CHG_WAKEUP_INDEX 3u
#endif /* __BOARD_PIN_H__ */
+20 -3
View File
@@ -233,13 +233,20 @@ BspHw_Ret_t bsp_hw_init(void)
#if BOARD_CHG_ENABLE
/* PORTG 作数字输入必须开 dieh,否则读不到 ME4054 CHG */
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_die(BOARD_CHG_PIN, 1);
gpio_set_dieh(BOARD_CHG_PIN, 1);
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
#if BOARD_MOTOR_ENABLE
@@ -423,6 +430,16 @@ uint8_t bsp_chg_is_low(void)
#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 读取电池电压
* @return 电池电压,单位 mV
+3
View File
@@ -101,6 +101,9 @@ uint8_t bsp_key_is_pressed(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 读取电池电压
* @return 电池电压,单位 mV
Binary file not shown.
@@ -4,6 +4,7 @@ cd %~dp0
copy ..\..\script.ver .
copy ..\..\tone.cfg .
copy ..\..\bird.mp3 .
copy ..\..\p11_code.bin .
copy ..\..\br28loader.bin .
copy ..\..\ota.bin .
@@ -15,7 +16,7 @@ if not exist p11_code.bin (
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 (
echo [download] ERROR: RS-5B88.key not found
+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` 字符串结束引号,消除预处理语法错误。