Compare commits
1
Commits
3d1ca8bda9
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ab37b7845 |
@@ -411,7 +411,6 @@ 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/app_shake_wake.c \
|
||||
apps/usr_le_code/ble_proto.c \
|
||||
apps/usr_le_code/bleproto.c \
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "app_mode.h"
|
||||
#include "app_led.h"
|
||||
#include "app_shake_wake.h"
|
||||
#include "app_no_disturb.h"
|
||||
#include "app_time_util.h"
|
||||
#include "bsp_hw.h"
|
||||
#include "board_pin.h"
|
||||
@@ -47,6 +46,7 @@ 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,6 +71,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -104,6 +105,12 @@ 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 无
|
||||
@@ -113,6 +120,10 @@ 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;
|
||||
@@ -490,7 +501,7 @@ static uint8_t function_power_on(uint8_t show_hint)
|
||||
static uint8_t function_shake_wake_allowed(void)
|
||||
{
|
||||
return s_func.shake_wake &&
|
||||
!app_no_disturb_is_active() &&
|
||||
!s_func.no_disturb &&
|
||||
!s_func.app_power &&
|
||||
!app_power_usb_online() &&
|
||||
!app_power_poweroff_pending() &&
|
||||
|
||||
@@ -39,6 +39,8 @@ 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 调用一次
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
#include "app_no_disturb.h"
|
||||
#include "usr_rtc.h"
|
||||
#include "system/includes.h"
|
||||
|
||||
#define APP_MINUTES_PER_DAY (24U * 60U)
|
||||
#define APP_NO_DISTURB_VM_MAGIC 0x444e4431UL
|
||||
#define APP_NO_DISTURB_VM_VERSION 1U
|
||||
|
||||
typedef struct {
|
||||
uint8_t enabled;
|
||||
uint8_t weekdays_mask;
|
||||
uint16_t start_minute;
|
||||
uint16_t end_minute;
|
||||
} 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 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)
|
||||
{
|
||||
uint16_t checksum = 0xa55aU;
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < APP_NO_DISTURB_DATA_LEN; i++) {
|
||||
checksum = (uint16_t)((checksum << 5) | (checksum >> 11));
|
||||
checksum ^= data[i];
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
|
||||
static uint8_t app_no_disturb_vm_valid(const AppNoDisturbVm_t *vm)
|
||||
{
|
||||
return vm->magic == APP_NO_DISTURB_VM_MAGIC &&
|
||||
vm->version == APP_NO_DISTURB_VM_VERSION &&
|
||||
vm->length == APP_NO_DISTURB_DATA_LEN &&
|
||||
vm->checksum == app_no_disturb_checksum(vm->data);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef __APP_NO_DISTURB_H__
|
||||
#define __APP_NO_DISTURB_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "system/sys_time.h"
|
||||
|
||||
#define APP_NO_DISTURB_DATA_LEN 13U
|
||||
|
||||
/* weekdays_mask bit 0..6 means Monday..Sunday. */
|
||||
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_is_active(void);
|
||||
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__ */
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "jb_product.h"
|
||||
#include "app_function.h"
|
||||
#include "app_no_disturb.h"
|
||||
#include "usr_rtc.h"
|
||||
|
||||
/* ════════════════════════════════════════════════════════════════
|
||||
* 全局变量
|
||||
@@ -30,27 +30,70 @@ 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;
|
||||
|
||||
static void jbNoDisturbApply(uint8_t *cfg)
|
||||
/* 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)
|
||||
{
|
||||
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]) {
|
||||
weekdays |= (uint8_t)(1U << i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════════════════
|
||||
@@ -68,10 +111,10 @@ void userInit(void)
|
||||
gDevData.battery = 0; /* DP5 电量上报 */
|
||||
gDevData.shake_wake = 0; /* DP6 震动触发开机 0=关 1=开 */
|
||||
memset(gDevData.no_disturb_enable, 0, 13); /* DP7 勿扰模式开关 */
|
||||
app_no_disturb_storage_load(gDevData.no_disturb_enable);
|
||||
gDevData.charge = 0; /* CHARGE_0 (不支持充电) */
|
||||
gDevData.reserva_dp3 = 0; /* DP10 预留DP3 */
|
||||
jbNoDisturbApply(gDevData.no_disturb_enable);
|
||||
jbLastNoDisturbActive = 0xff;
|
||||
jbNoDisturbUpdate();
|
||||
}
|
||||
|
||||
/* ════════════════════════════════════════════════════════════════
|
||||
@@ -80,6 +123,8 @@ void userInit(void)
|
||||
* ════════════════════════════════════════════════════════════════ */
|
||||
void userHandle(void)
|
||||
{
|
||||
jbNoDisturbUpdate();
|
||||
|
||||
/* ── 可上报 DP (RO / RW): 用户数据采集 ── */
|
||||
// gDevData.power = read_sensor(); /* DP0 开关 */
|
||||
// gDevData.play_mode = read_sensor(); /* DP1 自动模式 */
|
||||
@@ -148,19 +193,12 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
|
||||
break;
|
||||
|
||||
/* ── DP7 勿扰模式开关 (raw) ── */
|
||||
case DP_ID_NO_DISTURB_ENABLE: {
|
||||
uint8_t previous[JB_DND_LEN];
|
||||
|
||||
memcpy(previous, gDevData.no_disturb_enable, JB_DND_LEN);
|
||||
case DP_ID_NO_DISTURB_ENABLE:
|
||||
memcpy(gDevData.no_disturb_enable, ctrl->no_disturb_enable,
|
||||
JB_DND_LEN);
|
||||
jbNoDisturbApply(gDevData.no_disturb_enable);
|
||||
if (memcmp(previous, gDevData.no_disturb_enable, JB_DND_LEN) &&
|
||||
!app_no_disturb_storage_save(gDevData.no_disturb_enable)) {
|
||||
printf("dnd vm write failed\n");
|
||||
}
|
||||
jbNoDisturbNormalize(gDevData.no_disturb_enable);
|
||||
jbNoDisturbUpdate();
|
||||
break;
|
||||
}
|
||||
|
||||
/* ── DP10 预留DP3 (uint32) ── */
|
||||
case DP_ID_RESERVA_DP3:
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
3DBA0ACD41A68B534365C721F7B23619914B4106E1024B5592A0A49D1DD417152E4DCF18
|
||||
@@ -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`(构建、打包、协议对接说明)。
|
||||
@@ -172,7 +172,6 @@ u8 *syscfg_ptr_read(u16 item_id, u16 *len);
|
||||
#define CFG_USER_PLAN_INFO1 25+1
|
||||
|
||||
#define CFG_USER_BATTERY_LEVEL 26+1
|
||||
#define CFG_USER_NO_DISTURB 28
|
||||
|
||||
|
||||
#define CFG_USER_DEFINE_END 49
|
||||
|
||||
Reference in New Issue
Block a user