更新提交 1.验证了RTC 唤醒 2.添加蓝牙直连

This commit is contained in:
helloyifa 2025-05-16 17:31:05 +08:00
parent 1c6f199f37
commit f0a8f13cd6
8 changed files with 3722 additions and 3561 deletions

View File

@ -128,10 +128,6 @@ void enter_sleep(){
//power_set_soft_poweroff(); //power_set_soft_poweroff();
} }
void alarm_isr_user_cbfun(u8 index)
{
printf("**** alarm %d : hello world ****\n", index);
}
void user_main(){ void user_main(){
printf(">>>>>>>>>>>>>>>>>user_main...\n"); printf(">>>>>>>>>>>>>>>>>user_main...\n");

View File

@ -21,8 +21,9 @@
//#include "ble_trans_profile.h" //#include "ble_trans_profile.h"
static int led_state = 0; static int led_state = 0;
static u16 temer_temperature_detect = 0; static u16 temer_temperature_detect = 0;
static u16 temer_sleep = 0;
//struct app_dev_info_t dev_info; app_dev_info_t dev_info;
//struct app_dev_config_t dev_config; //struct app_dev_config_t dev_config;
app_dev_config_t dev_config; app_dev_config_t dev_config;
@ -55,6 +56,7 @@ void ble_send_data(u8 *sdata,u8 len)
if (ble_comm_att_check_send(connection_handle, len) && if (ble_comm_att_check_send(connection_handle, len) &&
ble_gatt_server_characteristic_ccc_get(connection_handle, ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE)) ble_gatt_server_characteristic_ccc_get(connection_handle, ATT_CHARACTERISTIC_ae02_01_CLIENT_CONFIGURATION_HANDLE))
{ {
printf("SEND: %s\n",sdata);
//使用notify方式发送 //使用notify方式发送
ble_comm_att_send_data(connection_handle, ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, sdata, len, ATT_OP_NOTIFY); ble_comm_att_send_data(connection_handle, ATT_CHARACTERISTIC_ae02_01_VALUE_HANDLE, sdata, len, ATT_OP_NOTIFY);
} }
@ -62,14 +64,78 @@ void ble_send_data(u8 *sdata,u8 len)
void ble_receive_callback(u8* data,u16 len){ void ble_receive_callback(u8* data,u16 len){
printf("ble_receive_callback (rx:%d): %s\n",len, data); printf("ble_receive_callback (rx:%d): %s\n",len, data);
if(strstr(data,"AT+GETTEMP=?") != NULL){ //TEMP
printf("111\n"); if(strstr(data,"AT^TEMP:") != NULL){
int detect_temp = 365; u8 str_get_temp[64] = {0};
u8 str_get_temp[24] = {0}; memset(str_get_temp,0,sizeof(str_get_temp));
sprintf(str_get_temp,"AT+GETTEMP=%d",detect_temp); sprintf(str_get_temp,"AT^TEMP:%d,%d,%d", dev_info.temperature_sensor/10, dev_info.temperature_sensor/10, dev_info.temperature_sensor/10);
ble_send_data(&str_get_temp,strlen(str_get_temp)); ble_send_data(&str_get_temp,strlen(str_get_temp));
}
else if(strstr(data,"AT+TEMP=") != NULL){
u8 str_get_temp[64] = {0};
memset(str_get_temp,0,sizeof(str_get_temp));
sprintf(str_get_temp,"AT+TEMP=%d,%d,%d", dev_info.temperature_sensor/10, dev_info.temperature_sensor/10, dev_info.temperature_sensor/10);
ble_send_data(&str_get_temp,strlen(str_get_temp));
}
//BATT 真实电压值
else if(strstr(data,"AT^BATT=") != NULL){
u8 str_get_batt[64] = {0};
memset(str_get_batt,0,sizeof(str_get_batt));
sprintf(str_get_batt,"AT^BATT=%d", dev_info.batt_val);
ble_send_data(&str_get_batt,strlen(str_get_batt));
}
else if(strstr(data,"AT+BATT=") != NULL){
u8 str_get_batt[64] = {0};
memset(str_get_batt,0,sizeof(str_get_batt));
sprintf(str_get_batt,"AT+BATT=%d", dev_info.batt_val);
ble_send_data(&str_get_batt,strlen(str_get_batt));
}
//BATT 转换后的电量百分百
else if(strstr(data,"AT^BATP=") != NULL){
u8 str_get_batt[64] = {0};
memset(str_get_batt,0,sizeof(str_get_batt));
sprintf(str_get_batt,"AT^BATP=%d", dev_info.batt_percent);
ble_send_data(&str_get_batt,strlen(str_get_batt));
}
else if(strstr(data,"AT+BATP=") != NULL){
u8 str_get_batt[64] = {0};
memset(str_get_batt,0,sizeof(str_get_batt));
sprintf(str_get_batt,"AT+BATP=%d", dev_info.batt_percent);
ble_send_data(&str_get_batt,strlen(str_get_batt));
}
//VERSION 软件版本
else if(strstr(data,"AT^VER=") != NULL){
u8 str_get_batt[64] = {0};
memset(str_get_batt,0,sizeof(str_get_batt));
sprintf(str_get_batt,"AT^VER=%s", BLE_TEMPERATURE_DEVICE_SOFT_VER);
ble_send_data(&str_get_batt,strlen(str_get_batt));
}
else if(strstr(data,"AT+VER=") != NULL){
u8 str_get_batt[64] = {0};
memset(str_get_batt,0,sizeof(str_get_batt));
sprintf(str_get_batt,"AT+VER=%s", BLE_TEMPERATURE_DEVICE_SOFT_VER);
ble_send_data(&str_get_batt,strlen(str_get_batt));
}
else if(strstr(data,"AT+ADJ37=") != NULL){
u8 str_adj[64] = {0};
memset(str_adj,0,sizeof(str_adj));
sprintf(str_adj,"AT+ADJ37=OK");
ble_send_data(&str_adj,strlen(str_adj));
}
else{
printf("unknow cmd\n");
}
}
/**
*
*1
*/
void ble_on_connect_change(u8 is_connect){
printf("ble_on_connect_change :(state:%d) \n",is_connect);
if(is_connect){
temperature_work_led(1);
}else{ }else{
printf("222\n"); temperature_work_led(0);
} }
} }
@ -338,21 +404,19 @@ static uint8_t reversal(uint8_t data)
//FF //FF
//先查明当前连接的conn_handle
u16 connection_handle = ble_comm_dev_get_handle(0, GATT_ROLE_SERVER);
if(connection_handle != 0)//
{
printf("ble connected !! connection_handle: %04x\n", connection_handle);
return ;
}else{
//printf("connection_handle: %04x\n", connection_handle);
}
//BBOOEEb 2字节体温 2字节物温 2字节环温 1字节电量 //BBOOEEb 2字节体温 2字节物温 2字节环温 1字节电量
u16 body = (u16)temp_value; u16 body = (u16)temp_value;
u16 obj = (u16)temp_value; u16 obj = (u16)temp_value;
u16 ntc = (u16)0; u16 ntc = (u16)0;
u8 battery = 99; u8 battery = 99;
//batt
battery = get_cur_battery_level() *10;
dev_info.temperature_sensor = body;
dev_info.temperature_ntc = body;
dev_info.batt_percent = battery;
dev_info.batt_val = get_vbat_value();
u8 ff_temp_data[7] = {0}; u8 ff_temp_data[7] = {0};
//body //body
ff_temp_data[0] = (body >> 8) & 0xFF; ff_temp_data[0] = (body >> 8) & 0xFF;
@ -363,9 +427,21 @@ static uint8_t reversal(uint8_t data)
//env //env
ff_temp_data[4] = (ntc >> 8) & 0xFF; ff_temp_data[4] = (ntc >> 8) & 0xFF;
ff_temp_data[5] = (ntc) & 0xFF; ff_temp_data[5] = (ntc) & 0xFF;
//batt
battery = get_cur_battery_level() *10;
ff_temp_data[6] = battery & 0xFF; ff_temp_data[6] = battery & 0xFF;
//先查明当前连接的conn_handle
u16 connection_handle = ble_comm_dev_get_handle(0, GATT_ROLE_SERVER);
if(connection_handle != 0)//
{
printf("ble connected !! connection_handle: %04x\n", connection_handle);
return ;
}else{
//printf("connection_handle: %04x\n", connection_handle);
}
trans_client_adv_data_set_ff(ff_temp_data,sizeof(ff_temp_data)); trans_client_adv_data_set_ff(ff_temp_data,sizeof(ff_temp_data));
gpio_direction_output(IO_PORTB_05, 0); gpio_direction_output(IO_PORTB_05, 0);
} }
@ -397,8 +473,31 @@ static uint8_t reversal(uint8_t data)
trans_client_adv_data_set_ff(ff_temp_data,sizeof(ff_temp_data)); trans_client_adv_data_set_ff(ff_temp_data,sizeof(ff_temp_data));
} }
void rtc_test_demo()
{
struct sys_time tmp_time;
memset((u8 *)&tmp_time, 0, sizeof(tmp_time));
read_sys_time(&tmp_time); //读当前rtc时间
printf("read_sys_time: %d-%d-%d %d:%d:%d", tmp_time.year, tmp_time.month, tmp_time.day, tmp_time.hour, tmp_time.min, tmp_time.sec); //打印读取时间值
//rtc_write_time(&test_sys_time); //修改rtc时间
//read_sys_time(&tmp_time); //读修改后rtc时间
//printf("rtc_rtc_read_time_after: %d-%d-%d %d:%d:%d", tmp_time.year, tmp_time.month, tmp_time.day, tmp_time.hour, tmp_time.min, tmp_time.sec); //打印修改后时间值
//read_alarm(&tmp_time); //读当前alarm时间
//printf("rtc_read_alarm_before: %d-%d-%d %d:%d:%d", tmp_time.year, tmp_time.month, tmp_time.day, tmp_time.hour, tmp_time.min, tmp_time.sec); //打印读取闹钟时间值
//rtc_write_alarm(&test_alarm); //修改alarm时间
//read_alarm(&tmp_time); //读修改后alarm时间
//printf("rtc_read_alarm_after: %d-%d-%d %d:%d:%d", tmp_time.year, tmp_time.month, tmp_time.day, tmp_time.hour, tmp_time.min, tmp_time.sec); //打印修改后闹钟时间值
}
void temperature_detect(void) void temperature_detect(void)
{ {
rtc_test_demo();
nst1002_read_temperatura(); nst1002_read_temperatura();
} }
@ -433,6 +532,8 @@ void temperature_poweron_led_timeout(){
void temperature_set_soft_poweroff(void) void temperature_set_soft_poweroff(void)
{ {
printf("temperature_set_soft_poweroff\n"); printf("temperature_set_soft_poweroff\n");
temperature_deinit();
//VCM_DET_EN(0);//关闭VCM复位 //VCM_DET_EN(0);//关闭VCM复位
//gpio_shortpress_reset_config(0);//1--enable 0--disable //gpio_shortpress_reset_config(0);//1--enable 0--disable
@ -548,9 +649,30 @@ void temperature_config_init(){
dev_config.detect_interval = 2000; dev_config.detect_interval = 2000;
} }
void alarm_isr_user_cbfun(u8 index)
{
printf("**** 11 alarm %d : hello world ****\n", index);
}
/**
*
*/
void timer_sleep_callback(void)
{
//关机开启闹钟
printf(">>>>>>>>>>>>>>>>> timer_sleep_callback ...\n");
rtc_alarm_set_timer(10);
temperature_set_soft_poweroff();
}
void temperature_init(void) void temperature_init(void)
{ {
//extern void user_alarm_test(void);
//extern void alarm_rtc_start(void);
//alarm_rtc_start();
//user_alarm_test();
printf(">>>>>>>>>>>>>>>>> temperature_init ...\n"); printf(">>>>>>>>>>>>>>>>> temperature_init ...\n");
delay_us(60); delay_us(60);
printf(">>>>>>>>>>>>>>>>> temperature_OTA ...\n"); printf(">>>>>>>>>>>>>>>>> temperature_OTA ...\n");
@ -570,12 +692,21 @@ void temperature_init(void)
//sys_s_hi_timer_add(NULL, temperature_detect, 2000); //sys_s_hi_timer_add(NULL, temperature_detect, 2000);
//sys_timer_add 方式添加定时任务 任务里边可以使用udelay delay_ms 等延时 sys_s_hi_timer_add 则延时无效 //sys_timer_add 方式添加定时任务 任务里边可以使用udelay delay_ms 等延时 sys_s_hi_timer_add 则延时无效
temer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval); temer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
//工作10秒关机 关机10s后 RTC重新唤醒
//temer_sleep = sys_timer_add(NULL, timer_sleep_callback,10*1000);
//HALL PIN 输入 //HALL PIN 输入
gpio_set_direction(IO_PORTA_00,1); gpio_set_direction(IO_PORTA_00,1);
gpio_set_die(IO_PORTA_00,1); gpio_set_die(IO_PORTA_00,1);
gpio_set_direction(IO_PORTB_04,0);
gpio_direction_output(IO_PORTB_04, 1);
gpio_set_direction(IO_PORTB_06,0);
gpio_direction_output(IO_PORTB_06, 1);
// NTC VDD // NTC VDD
//gpio_set_direction(IO_PORTB_05,0); //gpio_set_direction(IO_PORTB_05,0);
//gpio_direction_output(IO_PORTB_05, 1); //gpio_direction_output(IO_PORTB_05, 1);
@ -603,5 +734,21 @@ void temperature_deinit(void)
{ {
printf(">>>>>>>>>>>>>>>>> temperature_deinit ...\n"); printf(">>>>>>>>>>>>>>>>> temperature_deinit ...\n");
// NTC VDD // NTC VDD
gpio_set_direction(IO_PORTB_05,0);
gpio_direction_output(IO_PORTB_05, 0); gpio_direction_output(IO_PORTB_05, 0);
//gpio_set_direction(IO_PORTB_04,0);
//gpio_direction_output(IO_PORTB_04, 0);
// gpio_set_direction(IO_PORTB_06,0);
//gpio_direction_output(IO_PORTB_06, 0);
gpio_set_direction(IO_PORTA_00,0);
gpio_direction_output(IO_PORTA_00, 0);
gpio_set_pull_up(IO_PORTB_04,0);
gpio_set_pull_up(IO_PORTB_06,0);
} }

View File

@ -35,6 +35,8 @@ const struct low_power_param power_param = {
.osc_type = TCFG_LOWPOWER_OSC_TYPE, .osc_type = TCFG_LOWPOWER_OSC_TYPE,
.lpctmu_en = TCFG_LP_TOUCH_KEY_ENABLE, .lpctmu_en = TCFG_LP_TOUCH_KEY_ENABLE,
.vd13_cap_en = TCFG_VD13_CAP_EN, .vd13_cap_en = TCFG_VD13_CAP_EN,
//helloyifa
.rtc_clk = 1,
}; };
/************************** KEY MSG****************************/ /************************** KEY MSG****************************/
@ -185,6 +187,8 @@ RTC_DEV_PLATFORM_DATA_BEGIN(rtc_data)
.default_alarm = &def_alarm, .default_alarm = &def_alarm,
/* .cbfun = NULL, //闹钟中断的回调函数,用户自行定义 */ /* .cbfun = NULL, //闹钟中断的回调函数,用户自行定义 */
.cbfun = alarm_isr_user_cbfun, .cbfun = alarm_isr_user_cbfun,
//helloyifa
.clk_sel = CLK_SEL_LRC,
RTC_DEV_PLATFORM_DATA_END() RTC_DEV_PLATFORM_DATA_END()
#endif #endif

View File

@ -220,13 +220,13 @@
CHARGE_FULL_V_4308 CHARGE_FULL_V_4349 CHARGE_FULL_V_4391 CHARGE_FULL_V_4434 CHARGE_FULL_V_4308 CHARGE_FULL_V_4349 CHARGE_FULL_V_4391 CHARGE_FULL_V_4434
CHARGE_FULL_V_4472 CHARGE_FULL_V_4517 CHARGE_FULL_V_4564 CHARGE_FULL_V_4611 CHARGE_FULL_V_4472 CHARGE_FULL_V_4517 CHARGE_FULL_V_4564 CHARGE_FULL_V_4611
*/ */
#define TCFG_CHARGE_FULL_V CHARGE_FULL_V_4222 #define TCFG_CHARGE_FULL_V CHARGE_FULL_V_4175
/* /*
CHARGE_FULL_mA_2 CHARGE_FULL_mA_5 CHARGE_FULL_mA_7 CHARGE_FULL_mA_10 CHARGE_FULL_mA_2 CHARGE_FULL_mA_5 CHARGE_FULL_mA_7 CHARGE_FULL_mA_10
CHARGE_FULL_mA_15 CHARGE_FULL_mA_20 CHARGE_FULL_mA_25 CHARGE_FULL_mA_30 CHARGE_FULL_mA_15 CHARGE_FULL_mA_20 CHARGE_FULL_mA_25 CHARGE_FULL_mA_30
*/ */
#define TCFG_CHARGE_FULL_MA CHARGE_FULL_mA_5 #define TCFG_CHARGE_FULL_MA CHARGE_FULL_mA_7
/* /*
CHARGE_mA_20 CHARGE_mA_30 CHARGE_mA_40 CHARGE_mA_50 CHARGE_mA_20 CHARGE_mA_30 CHARGE_mA_40 CHARGE_mA_50
@ -234,7 +234,7 @@
CHARGE_mA_100 CHARGE_mA_110 CHARGE_mA_120 CHARGE_mA_140 CHARGE_mA_100 CHARGE_mA_110 CHARGE_mA_120 CHARGE_mA_140
CHARGE_mA_160 CHARGE_mA_180 CHARGE_mA_200 CHARGE_mA_220 CHARGE_mA_160 CHARGE_mA_180 CHARGE_mA_200 CHARGE_mA_220
*/ */
#define TCFG_CHARGE_MA CHARGE_mA_20 #define TCFG_CHARGE_MA CHARGE_mA_30
//*********************************************************************************// //*********************************************************************************//
// LED 配置 // // LED 配置 //

View File

@ -383,7 +383,8 @@ static int trans_event_packet_handler(int event, u8 *packet, u16 size, u8 *ext_p
log_info("con_interval = %d\n", little_endian_read_16(ext_param, 14 + 0)); log_info("con_interval = %d\n", little_endian_read_16(ext_param, 14 + 0));
log_info("con_latency = %d\n", little_endian_read_16(ext_param, 14 + 2)); log_info("con_latency = %d\n", little_endian_read_16(ext_param, 14 + 2));
log_info("cnn_timeout = %d\n", little_endian_read_16(ext_param, 14 + 4)); log_info("cnn_timeout = %d\n", little_endian_read_16(ext_param, 14 + 4));
//helloyifa
ble_on_connect_change(1);
#if ATT_MTU_REQUEST_ENALBE #if ATT_MTU_REQUEST_ENALBE
att_server_set_exchange_mtu(trans_con_handle);/*主动请求MTU长度交换*/ att_server_set_exchange_mtu(trans_con_handle);/*主动请求MTU长度交换*/
#endif #endif
@ -411,6 +412,8 @@ static int trans_event_packet_handler(int event, u8 *packet, u16 size, u8 *ext_p
trans_client_search_remote_stop(trans_con_handle); trans_client_search_remote_stop(trans_con_handle);
#endif #endif
trans_con_handle = 0; trans_con_handle = 0;
//helloyifa
ble_on_connect_change(0);
} }
break; break;

View File

@ -4,6 +4,11 @@
#include "typedef.h" #include "typedef.h"
#include "system/event.h" #include "system/event.h"
/**
* 1.0.1 2025.05.16
*/
#define BLE_TEMPERATURE_DEVICE_SOFT_VER "1.0.1"
#define BLE_TEMPERATURE_DETECT_INTERVAL 250 #define BLE_TEMPERATURE_DETECT_INTERVAL 250
#define BLE_TEMPERATURE_WORK_TIMEOUT 10*1000 #define BLE_TEMPERATURE_WORK_TIMEOUT 10*1000
#define BLE_TEMPERATURE_SLEEP_TIMEOUT 3*1000 #define BLE_TEMPERATURE_SLEEP_TIMEOUT 3*1000
@ -26,9 +31,9 @@
typedef struct typedef struct
{ {
u16 temperature_sensor; u16 temperature_sensor;
u32 temperature_ntc; u16 temperature_ntc;
u8 batt_percent; u8 batt_percent;
u16 batt_vat; u16 batt_val;
u8 is_bat_charge; u8 is_bat_charge;
u8 is_bat_full; u8 is_bat_full;
}app_dev_info_t; }app_dev_info_t;
@ -46,9 +51,12 @@ typedef struct
void temperature_ble_init(); void temperature_ble_init();
void temperature_init(void); void temperature_init(void);
void ble_receive_callback(u8* data,u16 len); void ble_receive_callback(u8* data,u16 len);
void ble_on_connect_change(u8 is_connect);
void temperature_work_led(u8 on); void temperature_work_led(u8 on);
void temperature_charge_led(u8 on); void temperature_charge_led(u8 on);
void temperature_charge_state(int state); void temperature_charge_state(int state);
void temperature_deinit(void);
#endif //_APP_TEMPERATURE_H_ #endif //_APP_TEMPERATURE_H_

View File

@ -89,6 +89,7 @@ void charge_ldo5v_off_deal(void)
int app_charge_event_handler(struct device_event *dev) int app_charge_event_handler(struct device_event *dev)
{ {
log_info("%s\n %d", __FUNCTION__,dev->event);
switch (dev->event) { switch (dev->event) {
case CHARGE_EVENT_CHARGE_START: case CHARGE_EVENT_CHARGE_START:
charge_start_deal(); charge_start_deal();

View File

@ -325,6 +325,7 @@ SYS_EVENT_HANDLER(SYS_DEVICE_EVENT, alarm_event_handler, 0);
void alarm_send_event(u8 index) void alarm_send_event(u8 index)
{ {
printf("**** rtc alarm_send_event ****\n");
struct sys_event e; struct sys_event e;
e.type = SYS_DEVICE_EVENT; e.type = SYS_DEVICE_EVENT;
e.arg = (void *)DEVICE_EVENT_FROM_ALM; e.arg = (void *)DEVICE_EVENT_FROM_ALM;
@ -335,6 +336,7 @@ void alarm_send_event(u8 index)
void alm_wakeup_isr(void) void alm_wakeup_isr(void)
{ {
printf("**** rtc alm_wakeup_isr ****\n");
if (alarm_pnd_flag) { if (alarm_pnd_flag) {
alarm_send_event(alarm_mask.alarm_active_index); alarm_send_event(alarm_mask.alarm_active_index);
} else { } else {