测温改用i2C

This commit is contained in:
hu-jiafeng 2025-07-07 11:16:00 +08:00
parent 40fdd1395f
commit c9a78c7244
19 changed files with 58234 additions and 52988 deletions

View File

@ -13,9 +13,9 @@
#include "le_common.h"
#include "cpu.h"
#include "timer.h"
#include "trs55d.h"
#include "os/os_api.h"
#include "system/includes.h"
#include "asm/power/p33.h"
#include "gatt_common/le_gatt_common.h"
#include "examples/trans_data/ble_trans_profile.h"
//#include "ble_trans_profile.h"
@ -299,154 +299,34 @@ static uint8_t reversal(uint8_t data)
return ret;
}
int nst1002_read_cal(uint16_t *pcal)
{
int retry = 0;
uint8_t crc;
uint8_t i, j;
uint8_t bit0 = 1;
uint8_t data[3] = {0, 0, 0};
uint8_t swap[2];
uint8_t read[4];
//--------------power up-----------------------
//pin_mode(DQ_PIN, PIN_MODE_OUTPUT_OD);
//pin_write(DQ_PIN, PIN_HIGH);
gpio_set_direction(DQ_PIN,0);
gpio_direction_output(DQ_PIN, 1);
delay_ms(15);
//--------------send start convert -----------------------------
gpio_direction_output(DQ_PIN, 0);//pin_write(DQ_PIN, PIN_LOW); // DQ low
//printf("send start convert out 0\r\n");
delay_us_by_timer0(300);
gpio_direction_output(DQ_PIN, 1);//pin_write(DQ_PIN, PIN_HIGH);
//printf("send start convert out 1\r\n");
delay_us_by_timer0(20);
//-----------------check DQ pin status should be high---------------------------------------
gpio_set_direction(DQ_PIN,1);
gpio_set_die(DQ_PIN,1);
//gpio_set_direction(DQ_PIN,1);//pin_mode(DQ_PIN, PIN_MODE_INPUT);
//gpio_set_pull_up(DQ_PIN, 1);
//printf("check DQ pin status should be high cur dq:%d:\r\n" ,pin_read(DQ_PIN));
//delay_ms(30);
if (pin_read(DQ_PIN) == 0)
{
printf("check DQ pin == 0 should be high!!\r\n");
*pcal = (uint16_t)(ERR_NC * 128);
temperature_detect_count --;
return -1;
}
//printf("check DQ pin status pin_read(DQ_PIN) == 1 \r\n");
//delay_ms(20);
//--------------wait for done pulse---------------
printf("wait for done pulse ... \r\n");
do
{
bit0 = pin_read(DQ_PIN);
delay_us_by_timer0(2);
retry++;
if (retry > 30000) // time out 40ms
{
*pcal = (uint16_t)(ERR_DONE * 128);
printf("wait for done pulse fail \r\n");
return -2;
}
} while (bit0);
printf("wait for done pulse succ \r\n");
delay_us_by_timer0(10);
//--------------read 24bit data---------------
gpio_set_direction(DQ_PIN,0);
gpio_direction_output(DQ_PIN, 1);//pin_write(DQ_PIN, PIN_HIGH);
//pin_mode(DQ_PIN, PIN_MODE_OUTPUT_OD);
//delay_us(200);
for (i = 0; i < 24; i++)
{
gpio_direction_output(DQ_PIN, 0);//pin_write(DQ_PIN, PIN_LOW); // Falling edge
delay_us(1);// Adjust according to the mcu clock cycle,It's not necessary
gpio_set_direction(DQ_PIN,1);//pin_mode(DQ_PIN, PIN_MODE_INPUT);
gpio_set_die(DQ_PIN,1);
//gpio_set_pull_up(DQ_PIN, 1);
// If the output bit is 0, the DQ will remain low for about 14us
for (j = 0; j < 4; j++)
// It's not necessary to read it 4 timers , adjust according to the mcuclock cycle
{
read[j] = pin_read(DQ_PIN);
}
if (read[0] == read[1]) // It's not necessary
bit0 = read[1];
else
{
*pcal = (uint16_t)(ERR_DAT * 128);
return -3;
}
data[i / 8] <<= 1;
data[i / 8] |= bit0;
gpio_set_direction(DQ_PIN,0);
gpio_direction_output(DQ_PIN, 1);//pin_write(DQ_PIN, PIN_HIGH); // DQ low
//pin_mode(DQ_PIN, PIN_MODE_OUTPUT_OD);
//delay_us(60);
delay_us_by_timer0(60);
}
//------------------- NST1002 Big Endian,but mcu Little Endian
swap[0] = data[1];
swap[1] = data[0];
*pcal = *((uint16_t *)swap); // output data need swap
crc = crc8_maxim(data, 2);
if (crc == data[2])
return 0;
else
{
printf("data %02x %02x %02x CRC %02x\r\n", data[0], data[1], data[2], crc);
*pcal = ERR_CRC * 128;
return -4;
}
}
char err_code[4][20] = {"NOT Connected", "No DONE signal", "DAT Recv Err", "CRC Err"};
static tuya_ble_queue_t temp_queue;
u16 buffer[MAX_SIZE];
void nst1002_read_temperatura(void)
void i2c_read_temperatura(void)
{
if(charge_state){
printf("charging...\r\n");
return;
}
int err, ei;
float dtmp;
int16_t cal;
// NTC VDD
gpio_set_direction(IO_PORTB_05,0);
gpio_direction_output(IO_PORTB_05, 1);
uint16_t t_body = 0;
uint16_t t_ntc = 0;
uint16_t result = Trs_Read(&t_body,&t_ntc);
err = nst1002_read_cal((uint16_t *)&cal);
if (err < 0)
{
if (ei < 4)
ei = -1 - err;
printf("NST1002 err code :%d err %s\r\n", err,err_code[ei]);
return;
}
//printf("cal %d\r\n", cal);
dtmp = cal / 128.0f;
int temp_value = dtmp*100;
//printf("Temp %3.7f\r\n", dtmp);
if (!result) {
printf("error: %d\r\n", result);
return;
}
int temp_value = t_body;
printf("Temp: %d\r\n\r\n", temp_value);
//FF
//BBOOEEb 2字节体温 2字节物温 2字节环温 1字节电量
u16 body = (u16)temp_value;
u16 obj = (u16)temp_value;
u16 ntc = (u16)0;
// u8 battery = 99;
u16 ntc = (u16)t_ntc;
u8 battery = get_vbat_percent();
u16 batt_val = 0;
@ -455,8 +335,7 @@ u16 buffer[MAX_SIZE];
} else {
batt_val = (get_vbat_level() + batt_val) / 2;
}
//batt
// battery = get_cur_battery_level() *10;
dev_info.init_sensor = body; //原始温度
if (ADJ_temp != 0) {
@ -506,7 +385,7 @@ u16 buffer[MAX_SIZE];
//计算当前温度是否稳定
u16 temp_body = dev_info.temperature_sensor;
//添加数据到队列,数量足够后取出所有温度数据 计算方差 如果小于 N N可以趋近于0 暂定小于20 则表示温度稳定
//添加数据到队列,数量足够后取出所有温度数据 计算方差 如果小于 N N可以趋近于0 暂定小于30 则表示温度稳定
if (tuya_ble_queue_isFull(&temp_queue)) {
tuya_ble_queue_decrease(&temp_queue); // 移除队首元素
}
@ -545,14 +424,6 @@ u16 buffer[MAX_SIZE];
mean_value = (t_datas[MAX_SIZE / 2 - 1] + t_datas[MAX_SIZE / 2]) / 2;
}
printf("mean_value:%d \r\n", mean_value);
// //计算平均值
// u32 sum = 0;
// for(i = 0;i < MAX_SIZE; i++){
// sum += t_datas[i];
// }
// u16 mean_value = sum / MAX_SIZE;
// printf("mean_value:%d \r\n", mean_value);
//计算方差
double sumOfSquares = 0;
@ -613,25 +484,7 @@ u16 buffer[MAX_SIZE];
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); //打印修改后闹钟时间值
}
static u8 low_battery_led_blinking = 0;
static u16 low_battery_led_timer_id = 0;
@ -673,7 +526,7 @@ void low_battery_check()
}
void temperature_detect(void)
{
nst1002_read_temperatura();
i2c_read_temperatura();
low_battery_check();
}
#endif
@ -845,7 +698,7 @@ void temperature_charge_state(int state){
}
printf("BLE_TEMPERATURE_CHARGE_STATE_CHARGING\n");
charge_inited = 1;
temperature_chargeing();
//temperature_chargeing();
break;
//拔出电压0.6左右)< ldoin < vbat
case BLE_TEMPERATURE_CHARGE_KEEP_CHARGING :
@ -855,7 +708,7 @@ void temperature_charge_state(int state){
}
printf("BLE_TEMPERATURE_CHARGE_KEEP_CHARGING\n");
charge_inited = 1;
temperature_chargeing();
//temperature_chargeing();
break;
//充电完成
case BLE_TEMPERATURE_CHARGE_STATE_FULL :
@ -869,7 +722,6 @@ void temperature_charge_state(int state){
printf("BLE_TEMPERATURE_CHARGE_STATE_IDLE\n");
//timer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
//temperature_charge_led(0);
if(init_complete == 0 ){ //如果开机未进入BLE_TEMPERATURE_CHARGE_KEEP_CHARGING则亮灯
temperature_work_led(1);
@ -906,7 +758,7 @@ void temperature_ble_init(){
le_controller_set_mac((void *)bt_mac_addr);
//设置名称
char ble_name[12] ={0};
sprintf(ble_name,"iT12_%02X%02X",bt_mac_addr[1],bt_mac_addr[0]);
sprintf(ble_name,"iT22_%02X%02X",bt_mac_addr[1],bt_mac_addr[0]);
ble_comm_set_config_name(&ble_name, 0);
}
/**
@ -934,7 +786,6 @@ void temperature_config_init(){
printf("temperature_offset :%d", dev_config.temperature_offset);
}
dev_config.detect_interval = 2000;
}
void alarm_isr_user_cbfun(u8 index)
{
@ -960,6 +811,8 @@ void temperature_init(void)
gpio_set_pull_up(IO_PORTA_00, 1);
// 添加以上代码看打印值如果为15跟63那就要用烧录器先烧录一遍。
TRS55D_Init();
temperature_config_init();
hell_wakeup_callback();
@ -980,17 +833,12 @@ void temperature_init(void)
//timer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
//HALL PIN 输入
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
//gpio_set_direction(IO_PORTB_05,0);
//gpio_direction_output(IO_PORTB_05, 1);

View File

@ -153,6 +153,7 @@
<Add option="../../../../cpu/bd19/liba/MotionDetection.a" />
<Add option="../../../../apps/common/third_party_profile/tuya_protocol/sdk/lib/lib_tuya_v200_Q32S.a" />
<Add option="../../../../cpu/bd19/liba/media.a" />
<Add option="../../../../cpu/bd19/liba/libW_TRS_CAL.a" />
<Add option="../../../../cpu/bd19/liba/lc3_codec_lib.a" />
<Add option="../../../../cpu/bd19/liba/usbc_codec_lib.a" />
<Add option="../../../../cpu/bd19/liba/lib_adpcm_ima_code.a" />
@ -395,6 +396,7 @@
<Unit filename="../../../../apps/common/update/update.c"><Option compilerVer="CC"/></Unit>
<Unit filename="../../../../apps/spp_and_le/app_main.c"><Option compilerVer="CC"/></Unit>
<Unit filename="../../../../apps/spp_and_le/app_temperature.c"><Option compilerVer="CC"/></Unit>
<Unit filename="../../../../apps/spp_and_le/trs55d.c"><Option compilerVer="CC"/></Unit>
<Unit filename="../../../../apps/spp_and_le/board/bd19/board_ac6321a_demo.c"><Option compilerVer="CC"/></Unit>
<Unit filename="../../../../apps/spp_and_le/board/bd19/board_ac6321a_demo_cfg.h" />
<Unit filename="../../../../apps/spp_and_le/board/bd19/board_ac6321a_demo_global_build_cfg.h" />
@ -520,6 +522,8 @@
<Unit filename="../../../../apps/spp_and_le/include/app_handshake.h" />
<Unit filename="../../../../apps/spp_and_le/include/app_main.h" />
<Unit filename="../../../../apps/spp_and_le/include/app_temperature.h" />
<Unit filename="../../../../apps/spp_and_le/include/trs55d.h" />
<Unit filename="../../../../apps/spp_and_le/include/W_TRS_CAL.h" />
<Unit filename="../../../../apps/spp_and_le/include/app_power_manage.h" />
<Unit filename="../../../../apps/spp_and_le/include/app_task.h" />
<Unit filename="../../../../apps/spp_and_le/include/at.h" />

View File

@ -2,16 +2,66 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="board_config.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="518" topLine="13" />
</Cursor>
</File>
<File name="..\..\modules\bt\app_comm_edr.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1154" topLine="18" />
</Cursor>
</File>
<File name="..\..\app_main.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3753" topLine="118" />
</Cursor>
</File>
<File name="..\..\..\..\include_lib\system\timer.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1916" topLine="61" />
</Cursor>
</File>
<File name="..\..\examples\trans_data\ble_trans.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="553" topLine="0" />
</Cursor>
</File>
<File name="..\..\include\app_config.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="10242" topLine="189" />
</Cursor>
</File>
<File name="..\..\app_temperature.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="14390" topLine="437" />
</Cursor>
</File>
<File name="..\..\..\common\device\usb\host\aoa.c" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="593" topLine="9" />
</Cursor>
</File>
<File name="..\..\..\..\cpu\bd19\charge.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="8796" topLine="308" />
</Cursor>
</File>
<File name="..\..\..\common\device\usb\device\user_setup.c" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="6496" topLine="231" />
</Cursor>
</File>
<File name="..\..\..\..\cpu\bd19\adc_api.c" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="11677" topLine="439" />
</Cursor>
</File>
<File name="board_ac6323a_demo_cfg.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="12074" topLine="209" />
</Cursor>
</File>
<File name="..\..\examples\trans_data\ble_trans.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="26810" topLine="719" />
@ -27,54 +77,4 @@
<Cursor1 position="27428" topLine="677" />
</Cursor>
</File>
<File name="board_config.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="518" topLine="13" />
</Cursor>
</File>
<File name="board_ac6323a_demo_cfg.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="12074" topLine="209" />
</Cursor>
</File>
<File name="..\..\..\..\cpu\bd19\charge.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="8796" topLine="308" />
</Cursor>
</File>
<File name="..\..\..\common\device\usb\device\user_setup.c" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="6496" topLine="231" />
</Cursor>
</File>
<File name="..\..\app_temperature.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="25741" topLine="759" />
</Cursor>
</File>
<File name="..\..\..\common\device\usb\host\aoa.c" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="593" topLine="9" />
</Cursor>
</File>
<File name="..\..\examples\trans_data\ble_trans.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="553" topLine="0" />
</Cursor>
</File>
<File name="..\..\modules\bt\app_comm_edr.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1154" topLine="18" />
</Cursor>
</File>
<File name="..\..\..\..\include_lib\system\timer.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1916" topLine="61" />
</Cursor>
</File>
<File name="..\..\app_main.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3753" topLine="118" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View File

@ -335,6 +335,7 @@ c_SRC_FILES := \
../../../../apps/common/update/update.c \
../../../../apps/spp_and_le/app_main.c \
../../../../apps/spp_and_le/app_temperature.c \
../../../../apps/spp_and_le/trs55d.c \
../../../../apps/spp_and_le/board/bd19/board_ac6321a_demo.c \
../../../../apps/spp_and_le/board/bd19/board_ac6323a_demo.c \
../../../../apps/spp_and_le/board/bd19/board_ac6323a_fmy.c \
@ -480,6 +481,7 @@ LFLAGS := \
../../../../cpu/bd19/liba/MotionDetection.a \
../../../../apps/common/third_party_profile/tuya_protocol/sdk/lib/lib_tuya_v200_Q32S.a \
../../../../cpu/bd19/liba/media.a \
../../../../cpu/bd19/liba/libW_TRS_CAL.a \
../../../../cpu/bd19/liba/lc3_codec_lib.a \
../../../../cpu/bd19/liba/usbc_codec_lib.a \
../../../../cpu/bd19/liba/lib_adpcm_ima_code.a \

View File

@ -0,0 +1,28 @@
#ifndef _W_TRS_CAL_H_
#define _W_TRS_CAL_H_
/* exact-width signed integer types */
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
/* exact-width unsigned integer types */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
// input:
// int32_t tmp_ad, // ambient temperature, adc val
// uint32_t corr_k1 // default 1000
// int32_t tob_ad // target temperature, adc val
// uint32_t corr_k2 // default 1000
//
//
// output:
// int16_t tax10 // Ten times the ambient temperature, degree centigrade
// int16_t tox10 // Ten times the target temperature, degree centigrade
void Cal_get_temp(int32_t tmp_ad, int32_t corr_k1, int32_t tob_ad, int32_t corr_k2, int16_t *tax10, int16_t *tox10);
#endif

View File

@ -5,14 +5,14 @@
#include "system/event.h"
/**
* 1.0.3 2025.06.26
* 1.0.4 2025.07.03
*/
#define BLE_TEMPERATURE_DEVICE_SOFT_VER "1.0.3"
#define BLE_TEMPERATURE_DEVICE_SOFT_VER "1.0.4"
#define BLE_TEMPERATURE_DETECT_INTERVAL 250
#define BLE_TEMPERATURE_WORK_TIMEOUT 10*1000
#define BLE_TEMPERATURE_SLEEP_TIMEOUT 3*1000
#define BLE_TEMPERATURE_DEVICE_NAME "IT12"
#define BLE_TEMPERATURE_DEVICE_NAME "IT22"
#define BLE_TEMPERATURE_LOWPOWER_OFFSIZE 3000 //mV
#define BLE_TEMPERATURE_DEVICE_NST1002 1002
@ -28,7 +28,6 @@
//VM用户自定义配置项[1 ~ 49]
#define BLE_TEMPERATURE_VM_DEVICE_CONFIG 2
#define INIT_COMPLETE_FLAG_CONFIG 3
#define ADJ_TEMP_CONFIG 4
#define HELL_WAKEUP 5

View File

@ -0,0 +1,86 @@
/*
#ifndef _TRS55D_H_
#define _TRS55D_H_
#include <stdint.h>
#define TRS55D_NORMAL_Tobj_MSB_R 0x10
#define TRS55D_NORMAL_Tobj_CSB_R 0x11
#define TRS55D_NORMAL_Tobj_LSB_R 0x12
#define TRS55D_NORMAL_TEMP_MSB_R 0x16
#define TRS55D_NORMAL_TEMP_CSB_R 0x17
#define TRS55D_NORMAL_TEMP_LSB_R 0x18
#define TRS55D_NORMAL_DATA1_MSB_R 0x19
#define TRS55D_NORMAL_DATA1_CSB_R 0x1A
#define TRS55D_NORMAL_DATA1_LSB_R 0x1B
#define TRS55D_NORMAL_DATA2_MSB_R 0x1C
#define TRS55D_NORMAL_DATA2_CSB_R 0x1D
#define TRS55D_NORMAL_DATA2_LSB_R 0x1E
#define TRS55D_RAW_DATA1_MSB_R 0x22
#define TRS55D_RAW_DATA1_CSB_R 0x23
#define TRS55D_RAW_DATA1_LSB_R 0x24
#define TRS55D_RAW_DATA2_MSB_R 0x25
#define TRS55D_RAW_DATA2_CSB_R 0x26
#define TRS55D_RAW_DATA2_LSB_R 0x27
#define TRS55D_RAW_TEMP_MSB_R 0x28
#define TRS55D_RAW_TEMP_CSB_R 0x29
#define TRS55D_RAW_TEMP_LSB_R 0x2A
#define ADDR_TRS55D 0xFE //(0x7F << 1)
#define _STATUS_DRDY_ 0x01
void TRS55D_Init();
void TRS55D_read(void);
#endif
*/
#ifndef _TRS_H_
#define _TRS_H_
#include "typedef.h"
#include "system/event.h"
#define NORMAL_Tobj_MSB_R 0x10
#define NORMAL_Tobj_CSB_R 0x11
#define NORMAL_Tobj_LSB_R 0x12
#define NORMAL_TEMP_MSB_R 0x16
#define NORMAL_TEMP_CSB_R 0x17
#define NORMAL_TEMP_LSB_R 0x18
#define NORMAL_DATA1_MSB_R 0x19
#define NORMAL_DATA1_CSB_R 0x1A
#define NORMAL_DATA1_LSB_R 0x1B
#define NORMAL_DATA2_MSB_R 0x1C
#define NORMAL_DATA2_CSB_R 0x1D
#define NORMAL_DATA2_LSB_R 0x1E
#define RAW_DATA1_MSB_R 0x22
#define RAW_DATA1_CSB_R 0x23
#define RAW_DATA1_LSB_R 0x24
#define RAW_DATA2_MSB_R 0x25
#define RAW_DATA2_CSB_R 0x26
#define RAW_DATA2_LSB_R 0x27
#define RAW_TEMP_MSB_R 0x28
#define RAW_TEMP_CSB_R 0x29
#define RAW_TEMP_LSB_R 0x2A
#define TRS_ADDR_AD (0x7F << 1) //0xfe
#define _STATUS_DRDY_ 0x01
typedef union{
uint16_t uu16;
struct {
uint8_t u8l;
uint8_t u8h;
}un;
}uu16_t;
typedef union{
int32_t i32;
struct {
uint8_t u8b0;
uint8_t u8b1;
uint8_t u8b2;
uint8_t u8b3;
}un;
}uu32_t;
void TRS55D_Init();
uint16_t Trs_Read(uint16_t *t_body,uint16_t *t_ntc);
#endif

View File

@ -0,0 +1,510 @@
// trs55d.c
#include "system/includes.h"
#include "app_config.h"
#include "app_action.h"
#include "app_main.h"
#include "update.h"
#include "update_loader_download.h"
#include "app_charge.h"
#include "app_power_manage.h"
#include "asm/charge.h"
#include "app_temperature.h"
#include "typedef.h"
#include "le_common.h"
#include "cpu.h"
#include "timer.h"
#include "os/os_api.h"
#include "system/includes.h"
#include "gatt_common/le_gatt_common.h"
#include "examples/trans_data/ble_trans_profile.h"
#include "asm/iic_soft.h"
#include "trs55d.h"
#define IIC_CHANNEL_1 0
const struct soft_iic_config soft_iic_cfg[] = {
//iic0 data
{
.scl = IO_PORTA_07, //IIC CLK脚
.sda = IO_PORTA_08, //IIC DAT脚
.delay = 50, //软件IIC延时参数影响通讯时钟频率
.io_pu = 1, //是否打开上拉电阻如果外部电路没有焊接上拉电阻需要置1
},
};
#if 1
//如果无reg_addr:reg_addr=NULL,reg_len=0
//return: <0:error, =read_len:ok
int soft_i2c_master_read_nbytes_from_device_reg(soft_iic_dev iic, //iic索引
unsigned char dev_addr, //设备地址
int reg_addr, unsigned char reg_len,//设备寄存器地址,长度
unsigned char *read_buf, int read_len)//缓存buf读取长度
{
u8 ack;
int ret = 0;
// 发送起始条件
soft_iic_start(iic);
// 1. 发送设备地址(写模式)
ack = soft_iic_tx_byte(iic, dev_addr & 0xFE);
if (!ack) {
printf("dev_addr no ack!\n");
ret = -1;
goto exit;
}
// 2. 发送寄存器地址(支持多字节地址)
if (reg_len > 0) {
// 处理多字节地址(高位在前)
uint8_t addr_buf[4];
for (int i = reg_len - 1; i >= 0; i--) {
addr_buf[i] = (reg_addr >> (8 * (reg_len - 1 - i))) & 0xFF;
}
for (u8 i = 0; i < reg_len; i++) {
ack = soft_iic_tx_byte(iic, addr_buf[i]);
if (!ack) {
printf("reg_addr no ack at byte %d!\n", i);
ret = -1;
goto exit;
}
}
}
// 3. 发送重复起始条件
soft_iic_start(iic);
// 4. 发送设备地址(读模式)
ack = soft_iic_tx_byte(iic, dev_addr | 0x01);
if (!ack) {
printf("dev_addr (read) no ack!\n");
ret = -1;
goto exit;
}
// 5. 读取数据
ret = soft_iic_read_buf(iic, read_buf, read_len);
exit:
// 发送停止条件
soft_iic_stop(iic);
return ret;
/*
u8 ack;
int ret = 0;
//local_irq_disable();
//if (soft_iic_check_busy(iic) == IIC_ERROR_BUSY) { //busy
// ret = IIC_ERROR_BUSY; //busy
// goto _read_exit2;
//}
if ((reg_addr != 0) && (reg_len != 0)) {
soft_iic_start(iic);
ack = soft_iic_tx_byte(iic, dev_addr);
if (ack == 0) {
printf("dev_addr no ack!");
//ret = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
ret = -1;
goto _read_exit1;
}
for (u8 i = 0; i < reg_len; i++) {
ack = soft_iic_tx_byte(iic, reg_addr);
if (ack == 0) {
printf("reg_addr no ack!");
//ret = IIC_ERROR_REG_ADDR_ACK_ERROR; //无应答
ret = -1;
goto _read_exit1;
}
}
}
soft_iic_start(iic);
ack = soft_iic_tx_byte(iic, dev_addr | BIT(0));
if (ack == 0) {
printf("dev_addr no ack!");
//ret = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
goto _read_exit1;
}
ret = soft_iic_read_buf(iic, read_buf, read_len);
_read_exit1:
soft_iic_stop(iic);
return ret;*/
}
//如果无reg_addr:reg_addr=NULL,reg_len=0
//return: =write_len:ok, other:error
int soft_i2c_master_write_nbytes_to_device_reg(soft_iic_dev iic,
unsigned char dev_addr, //设备地址
int reg_addr, unsigned char reg_len,//设备寄存器地址,长度
unsigned char *write_buf, int write_len)//数据buf, 写入长度
{
int res;
u8 ack;
//local_irq_disable();//软件iic不可被中断
//if (soft_iic_check_busy(iic) == IIC_ERROR_BUSY) { //busy
// res = IIC_ERROR_BUSY; //busy
// goto _write_exit2;
//}
soft_iic_start(iic);
ack = soft_iic_tx_byte(iic, dev_addr);
if (ack == 0) {
printf("dev_addr no ack!");
//res = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
res = -1; //无应答
goto _write_exit1;
}
if ((reg_addr !=0 ) && (reg_len != 0)) {
for (u8 i = 0; i < reg_len; i++) {
ack = soft_iic_tx_byte(iic, reg_addr);
if (ack == 0) {
printf("reg_addr no ack!");
//res = IIC_ERROR_REG_ADDR_ACK_ERROR; //无应答
res = -1;
goto _write_exit1;
}
}
}
for (res = 0; res < write_len; res++) {
if (0 == soft_iic_tx_byte(iic, write_buf[res])) {
printf("write data no ack!");
goto _write_exit1;
}
}
_write_exit1:
soft_iic_stop(iic);
return res;
}
#endif
static void udelay(u32 usec)
{
/* if (set_to_close_timer0_delay) { */
/* JL_MCPWM->MCPWM_CON0 &= ~BIT(8 + 3); */
/* JL_MCPWM->TMR3_CNT = 0; */
/* JL_MCPWM->TMR3_PR = clk_get("lsb") / 1000000 * usec; */
/* JL_MCPWM->TMR3_CON = BIT(10) | BIT(0); */
/* JL_MCPWM->MCPWM_CON0 |= BIT(8 + 3); */
/* while (!(JL_MCPWM->TMR3_CON & BIT(12))); */
/* JL_MCPWM->TMR3_CON = BIT(10); */
/* JL_MCPWM->MCPWM_CON0 &= ~BIT(8 + 3); */
/* } else { */
JL_TIMER0->CON = BIT(14);
JL_TIMER0->CNT = 0;
JL_TIMER0->PRD = 16 * 1000000L / 1000000L * usec; //1us
JL_TIMER0->CON = BIT(0); //sys clk
while ((JL_TIMER0->CON & BIT(15)) == 0);
JL_TIMER0->CON = BIT(14);
/* } */
}
void TRS55D_Init(){
#if 0
//LCD VDD3.3
pmu_set_aldo_voltage(PMU_ALDO_MODE_NORMAL,PMU_ALDO_VOL_3_3);
//LCD RESET
system_set_port_mux(GPIO_PORT_A,GPIO_BIT_4,PORTA4_FUNC_A4);
gpio_set_dir(GPIO_PORT_A, GPIO_BIT_4, GPIO_DIR_OUT);
gpio_set_pin_value(GPIO_PORT_A,GPIO_BIT_4,1);
co_delay_100us(1000);
system_set_port_mux(GPIO_PORT_A, GPIO_BIT_6, PORTA6_FUNC_I2C1_CLK);//Pa6
system_set_port_mux(GPIO_PORT_A, GPIO_BIT_7, PORTA7_FUNC_I2C1_DAT);//Pa7
system_set_port_pull( (GPIO_PA6|GPIO_PA7), true);
//IIC0, 1M hz. slave addr: 0xd6
iic_init(IIC_CHANNEL_1,100,TRS_ADDR_AD);
soft_iic_init(0);
#endif
//打开电源
gpio_set_direction(IO_PORTA_02,0);
gpio_direction_output(IO_PORTA_02, 1);
//初始化IIC
soft_iic_init(IIC_CHANNEL_1);
}
uint8_t TRS55D_IIC_Read(uint8_t addr_dev, uint8_t addr_reg, uint8_t *buf, uint16_t count)
{
#if 0
uint8_t ret;
uint8_t ackflag;
uint16_t i = 0;
/*
drv_i2c_start();
drv_i2c_select_dev(addr_dev,DRV_I2C_OPWR);
drv_i2c_writebyte(addr_reg);
drv_i2c_start();
drv_i2c_select_dev(addr_dev,DRV_I2C_OPRD);
for(i = 0; i < count; i ++) {
ackflag = (i < (count-1)) ? 1:0; buf[i] = drv_i2c_readbyte(ackflag);
}
drv_i2c_stop();
*/
iic_read_bytes(IIC_CHANNEL_1, addr_dev, addr_reg, buf, count);
return ret;
#endif
//soft_iic_read_buf(IIC_CHANNEL_1, buf, count);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,
addr_dev, //设备地址
addr_reg, 1,//设备寄存器地址,长度
buf, count);//数据buf, 写入长度
return 1;
}
void TRS55D_IIC_Write(uint8_t addr_dev, uint8_t addr_reg, uint8_t *buf, uint16_t count)
{
uint16_t i = 0;
/*
drv_i2c_start();
drv_i2c_select_dev(addr_dev,DRV_I2C_OPWR);
drv_i2c_writebyte(addr_reg);
for (i = 0; i < count; i ++)
{
drv_i2c_writebyte(buf[i]);
}
drv_i2c_stop();
*/
// iic_write_bytes(IIC_CHANNEL_1,addr_dev,addr_reg,buf,count);
//soft_iic_write_buf(IIC_CHANNEL_1, buf, count);
soft_i2c_master_write_nbytes_to_device_reg(IIC_CHANNEL_1,
addr_dev, //设备地址
addr_reg, 1,//设备寄存器地址,长度
buf, count);//数据buf, 写入长度
}
static char buffer[264];
uu32_t obj,tmp_3, vtp_cor;
float tamb_temp ,vtp_cor_uv ,Tobj_temp ;
//#include "FW_TRS_CAL.h"
uint16_t t_objx10_u16;
int16_t Tambx10_u16;
uint16_t Trs_Read(uint16_t *t_body, uint16_t *t_ntc)
{
uint8_t rbuf[4];
uint8_t raddr, rdat;
uint8_t waddr = 0x0, wdat = 0x0;
int timeout = 0;
waddr = 0x30; // CMD
wdat = 0x09; // 0x0000 1 FSM 001 单通道连续转换
TRS55D_IIC_Write(TRS_ADDR_AD, waddr, &wdat, 1); // start conversion 模式使能
udelay(100);
raddr = 0x03; // 原始数据地址
do
{
TRS55D_IIC_Read(TRS_ADDR_AD, raddr, &rdat, 1);
} while (((rdat == 0xFF) || (!(rdat & 0x30))) && timeout++ < 100); // 全真为真
// flag置1 结果为真 取反为假跳出循环
raddr = 0x02; // 经过校准后的数据地址
do
{
TRS55D_IIC_Read(TRS_ADDR_AD, raddr, &rdat, 1);
} while (((rdat == 0xFF) || (!(rdat & 0x0B))) && timeout++ < 200);
// flag置1 结果为真 取反为假跳出循环
udelay(500);
// raddr = NORMAL_DATA1_MSB_R;//0x19 通道1校准后adc数据
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x19, &rbuf[0]);
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x1A, &rbuf[1]);
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x1B, &rbuf[2]);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x19, 1,&rbuf[0], 1);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x1A, 1,&rbuf[1], 1);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x1B, 1,&rbuf[2], 1);
//printf("0x19:%02X 0x1A:%02X 0x1B:%02X \r\n", rbuf[0], rbuf[1], rbuf[2]);
vtp_cor.un.u8b2 = rbuf[0];
vtp_cor.un.u8b1 = rbuf[1];
vtp_cor.un.u8b0 = rbuf[2];
if (vtp_cor.un.u8b2 & 0x80)
{
vtp_cor.un.u8b3 = 0xFF;
}
else
{
vtp_cor.un.u8b3 = 0x00;
}
float vt_cor = 524288;
vtp_cor_uv = (float)vtp_cor.i32 / vt_cor; // vtp_cor_uv=DATA1/2^19±16mV=vtp_cor.i32/vt_cor
vtp_cor_uv *= 1000.0;
// raddr = NORMAL_TEMP_MSB_R;//0x16环境校准后温度
// TRS55D_IIC_Read (TRS_ADDR_AD, raddr, &rbuf[0],3);
// uint8_t iic_read_byte(enum iic_channel_t channel, uint8_t slave_addr, uint8_t reg_addr, uint8_t *buffer)
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x16, &rbuf[0]);
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x17, &rbuf[1]);
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x18, &rbuf[2]);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x16, 1,&rbuf[0], 1);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x17, 1,&rbuf[1], 1);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x18, 1,&rbuf[2], 1);
//printf("0x16:%02X 0x17:%02X 0x18:%02X \r\n", rbuf[0], rbuf[1], rbuf[2]);
tmp_3.un.u8b2 = rbuf[0];
tmp_3.un.u8b1 = rbuf[1];
tmp_3.un.u8b0 = rbuf[2];
if (tmp_3.un.u8b2 & 0x80)
{
tmp_3.un.u8b3 = 0xFF;
}
else
{
tmp_3.un.u8b3 = 0x00;
}
// raddr = NORMAL_Tobj_MSB_R;//0x10 dsp处理数据据
// TRS55D_IIC_Read (TRS_ADDR_AD, raddr, &rbuf[0],3);
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x10, &rbuf[0]);
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x11, &rbuf[1]);
//iic_read_byte(IIC_CHANNEL_1, TRS_ADDR_AD, 0x12, &rbuf[2]);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x10, 1,&rbuf[0], 1);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x11, 1,&rbuf[1], 1);
soft_i2c_master_read_nbytes_from_device_reg(IIC_CHANNEL_1,TRS_ADDR_AD,0x12, 1,&rbuf[2], 1);
//printf("0x10:%02X 0x11:%02X 0x12:%02X \r\n", rbuf[0], rbuf[1], rbuf[2]);
obj.un.u8b2 = rbuf[0];
obj.un.u8b1 = rbuf[1];
obj.un.u8b0 = rbuf[2];
if (obj.un.u8b2 & 0x80)
{
obj.un.u8b3 = 0xFF;
}
else
{
obj.un.u8b3 = 0x00;
}
// co_printf("NORMAL_Tobj_MSB_R :%02X %02X %02X\r\n",rbuf[0],rbuf[1],rbuf[2]);
//printf("tmp_3.i32: %d obj.i32: %d \r\n", tmp_3.i32, obj.i32);
Cal_get_temp(tmp_3.i32, 1000, obj.i32, 1000, &Tambx10_u16, &t_objx10_u16);
Tobj_temp = (float)t_objx10_u16 / 10;
tamb_temp = (float)Tambx10_u16 / 10;
*t_body = (uint16_t)(Tobj_temp * 100);
*t_ntc = (uint16_t)(tamb_temp * 100);
return 1;
}
/*
static char buffer[264];
uu32_t tobj, tamb_cal;
uu32_t vtp_cor;
float vtp_uv_f = 0.0;
float vtp_cor_f = 0.0;
float tambf = 0.0;
float tobjf = 0.0;
float tbdyf = 0.0;
void TRS55D_read(void){
co_printf("TRS55D_read !! \r\n");
uint8_t rbuf[4];
uint8_t raddr,rdat;
uint8_t waddr = 0x0, wdat = 0x0;
int timeout=0;
iic_read_byte(IIC_CHANNEL_1, ADDR_TRS55D, 0x97, &rdat);
co_printf("read raddr :%02X rdat %02X\r\n",0x97,rdat);
co_delay_100us(1000);
waddr = 0x30; wdat = 0x09;
TRS55D_IIC_Write(ADDR_TRS55D, waddr, &wdat,1); //start conversion
//delay_ms(100);
co_delay_100us(1000);
// waite for conversion over
// co_printf("waite for conversion over !! \r\n");
raddr = 0x03;
do {
TRS55D_IIC_Read (ADDR_TRS55D, raddr, &rdat,1);
co_printf("read raddr :%02X rdat %02X\r\n",raddr,rdat);
} while(((rdat == 0xFF) || (!(rdat & 0x30))) && timeout++ < 200);
raddr = 0x02;
do {
TRS55D_IIC_Read (ADDR_TRS55D, raddr, &rdat,1);
co_printf("read raddr :%02X rdat %02X\r\n",raddr,rdat);
} while(((rdat == 0xFF) || (!(rdat & 0x0B))) && timeout++ < 200);
// voltage value after calibration
raddr = TRS55D_NORMAL_DATA1_MSB_R;
TRS55D_IIC_Read (ADDR_TRS55D, raddr,&rbuf[0],3);
co_printf("NORMAL_DATA1_MSB_R :%02X %02X %02X\r\n",rbuf[0],rbuf[1],rbuf[2]);
vtp_cor.un.u8b2 = rbuf[0];
vtp_cor.un.u8b1 = rbuf[1];
vtp_cor.un.u8b0 =rbuf[2];
if (vtp_cor.un.u8b2 & 0x80)
{
vtp_cor.un.u8b3 = 0xFF;
}else {
vtp_cor.un.u8b3 = 0x00;// vtp after corrected
}
vtp_cor_f = (float)vtp_cor.i32/524288.0;
vtp_cor_f *= 1000;
// ambient temperature value after calibration
raddr = TRS55D_NORMAL_TEMP_MSB_R;
TRS55D_IIC_Read (ADDR_TRS55D,raddr,&rbuf[0],3);
co_printf("NORMAL_TEMP_MSB_R :%02X %02X %02X\r\n",rbuf[0],rbuf[1],rbuf[2]);
tamb_cal.un.u8b2 = rbuf[0];
tamb_cal.un.u8b1 =rbuf[1];
tamb_cal.un.u8b0 =rbuf[2];
tambf = (float)tamb_cal.i32 / 16384.0;
// ambient temperature
// object(surface) temperature after calibration
raddr = TRS55D_NORMAL_Tobj_MSB_R;
TRS55D_IIC_Read (ADDR_TRS55D,raddr,&rbuf[0],3);
tobj.un.u8b2 = rbuf[0];
tobj.un.u8b1 = rbuf[1];
tobj.un.u8b0 =rbuf[2];
tobjf = (float)tobj.i32 / 16384.0;
sprintf(buffer, "tambf = %.2f, vtp_cor = %.2f, tobj = %.2f, tbdy = %.2f\r\n",tambf,vtp_cor_f,tobjf,tbdyf);
co_printf("%s \r\n",buffer);
//co_printf("tambf:%.2f vtp_cor_f:%.2f tobjf:%.2f \r\n",tambf,vtp_cor_f,tobjf);
// object(surface) temperature
// get bodytemp
//tbdyf = get_body_temp(tambf,tobjf);
// get bodytemp
// display on uart
// sprintf(buffer, "tamb = %.2f, vtp_cor = %.2f, tobj = %.2f, tbdy = %.2f\r\n",\tambf,vtp_cor_f,tobjf,tbdyf);
//uartSendString(buffer);
// display on oled
/*
float vals[4] = {tambf, vtp_cor_f, tobjf, tbdyf+0.05};
OLED_ShowBNum(64, 0, vals[0], 4, 16, 1); // Tamb
OLED_ShowBNum(48, 16, vals[1], 6, 16, 1); // vtp
OLED_ShowString(112,16,"uv",16, 1);
OLED_ShowBNum(64, 32, vals[2], 4, 16, 1); // Tobj
OLED_ShowBNum(64, 48, vals[3], 4, 16, 1); // Tbdy
*/
//}*/

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -225,7 +225,7 @@ obj/Release/cpu/bd19/iic_soft.o
-r=obj/Release/cpu/bd19/iic_soft.o,gpio_read,l
-r=obj/Release/cpu/bd19/iic_soft.o,soft_iic_read_buf,pl
-r=obj/Release/cpu/bd19/iic_soft.o,soft_iic_write_buf,pl
-r=obj/Release/cpu/bd19/iic_soft.o,soft_iic_cfg,
-r=obj/Release/cpu/bd19/iic_soft.o,soft_iic_cfg,l
obj/Release/cpu/bd19/irflt.o
-r=obj/Release/cpu/bd19/irflt.o,timer_ir_isr,pl
-r=obj/Release/cpu/bd19/irflt.o,set_ir_clk,pl
@ -2340,11 +2340,9 @@ obj/Release/apps/spp_and_le/app_temperature.o
-r=obj/Release/apps/spp_and_le/app_temperature.o,local_irq_disable,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,local_irq_enable,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,delay_ms_by_timer0,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,nst1002_read_cal,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,i2c_read_temperatura,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_set_direction,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_set_die,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_read,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,nst1002_read_temperatura,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,Trs_Read,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbat_percent,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbat_level,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_queue_isFull,l
@ -2353,8 +2351,6 @@ obj/Release/apps/spp_and_le/app_temperature.o
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_get_queue_used,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,trans_client_adv_data_set_ff,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_update_adv_ff,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,rtc_test_demo,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,read_sys_time,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,low_battery_led_flash,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,stop_low_battery_blink,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,low_battery_check,pl
@ -2366,6 +2362,7 @@ obj/Release/apps/spp_and_le/app_temperature.o
-r=obj/Release/apps/spp_and_le/app_temperature.o,sys_timeout_add,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,power_set_soft_poweroff,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,hall_isr_check,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_read,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,hell_wakeup_callback,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,syscfg_read,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_detect_timer_del,pl
@ -2382,15 +2379,15 @@ obj/Release/apps/spp_and_le/app_temperature.o
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_comm_set_config_name,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_config_init,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,alarm_isr_user_cbfun,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,timer_sleep_callback,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_init,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbat_trim,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbg_trim,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_set_die,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_set_pull_up,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,TRS55D_Init,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_queue_init,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_queue_flush,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,dev_info,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,err_code,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,dev_config,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,charge_led_hander,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,buffer,pl
@ -3467,6 +3464,31 @@ obj/Release/apps/spp_and_le/modules/user_cfg.o
-r=obj/Release/apps/spp_and_le/modules/user_cfg.o,log_tag_const_i_USER_CFG,l
-r=obj/Release/apps/spp_and_le/modules/user_cfg.o,app_var,l
-r=obj/Release/apps/spp_and_le/modules/user_cfg.o,log_tag_const_d_USER_CFG,l
obj/Release/apps/spp_and_le/trs55d.o
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_i2c_master_read_nbytes_from_device_reg,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_iic_start,l
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_iic_tx_byte,l
-r=obj/Release/apps/spp_and_le/trs55d.o,printf,l
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_iic_read_buf,l
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_iic_stop,l
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_i2c_master_write_nbytes_to_device_reg,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,TRS55D_Init,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,gpio_set_direction,l
-r=obj/Release/apps/spp_and_le/trs55d.o,gpio_direction_output,l
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_iic_init,l
-r=obj/Release/apps/spp_and_le/trs55d.o,TRS55D_IIC_Read,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,TRS55D_IIC_Write,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,Trs_Read,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,Cal_get_temp,l
-r=obj/Release/apps/spp_and_le/trs55d.o,soft_iic_cfg,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,vtp_cor,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,vtp_cor_uv,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,tmp_3,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,obj,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,Tambx10_u16,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,t_objx10_u16,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,Tobj_temp,pl
-r=obj/Release/apps/spp_and_le/trs55d.o,tamb_temp,pl
obj/Release/apps/spp_and_le/version.o
-r=obj/Release/apps/spp_and_le/version.o,app_version_check,pl
-r=obj/Release/apps/spp_and_le/version.o,puts,l
@ -12634,6 +12656,11 @@ obj/Release/apps/spp_and_le/board/bd19/board_ac632n_demo.o
-r=../../../../cpu/bd19/liba/media.a.llvm.158140.audio_decoder.c,config_asser,l
-r=../../../../cpu/bd19/liba/media.a.llvm.158140.audio_decoder.c,audio_decoder_begin,
-r=../../../../cpu/bd19/liba/media.a.llvm.158140.audio_decoder.c,audio_decoder_end,
../../../../cpu/bd19/liba/libW_TRS_CAL.a.llvm.196.W_TRS_CAL.c
-r=../../../../cpu/bd19/liba/libW_TRS_CAL.a.llvm.196.W_TRS_CAL.c,S24tos32,pl
-r=../../../../cpu/bd19/liba/libW_TRS_CAL.a.llvm.196.W_TRS_CAL.c,get_Tax10,pl
-r=../../../../cpu/bd19/liba/libW_TRS_CAL.a.llvm.196.W_TRS_CAL.c,get_t_objx10,pl
-r=../../../../cpu/bd19/liba/libW_TRS_CAL.a.llvm.196.W_TRS_CAL.c,Cal_get_temp,pl
../../../../cpu/bd19/liba/update.a.llvm.6448.lmp_ch_update.c
-r=../../../../cpu/bd19/liba/update.a.llvm.6448.lmp_ch_update.c,bt_f_seek,pl
-r=../../../../cpu/bd19/liba/update.a.llvm.6448.lmp_ch_update.c,bt_f_read,pl

File diff suppressed because it is too large Load Diff

View File

@ -1,181 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <cstdlib>
static unsigned int LunarCalendarDay;
static unsigned int LunarCalendarTable[199] =
{
0x04AE53,0x0A5748,0x5526BD,0x0D2650,0x0D9544,0x46AAB9,0x056A4D,0x09AD42,0x24AEB6,0x04AE4A,/*1901-1910*/
0x6A4DBE,0x0A4D52,0x0D2546,0x5D52BA,0x0B544E,0x0D6A43,0x296D37,0x095B4B,0x749BC1,0x049754,/*1911-1920*/
0x0A4B48,0x5B25BC,0x06A550,0x06D445,0x4ADAB8,0x02B64D,0x095742,0x2497B7,0x04974A,0x664B3E,/*1921-1930*/
0x0D4A51,0x0EA546,0x56D4BA,0x05AD4E,0x02B644,0x393738,0x092E4B,0x7C96BF,0x0C9553,0x0D4A48,/*1931-1940*/
0x6DA53B,0x0B554F,0x056A45,0x4AADB9,0x025D4D,0x092D42,0x2C95B6,0x0A954A,0x7B4ABD,0x06CA51,/*1941-1950*/
0x0B5546,0x555ABB,0x04DA4E,0x0A5B43,0x352BB8,0x052B4C,0x8A953F,0x0E9552,0x06AA48,0x6AD53C,/*1951-1960*/
0x0AB54F,0x04B645,0x4A5739,0x0A574D,0x052642,0x3E9335,0x0D9549,0x75AABE,0x056A51,0x096D46,/*1961-1970*/
0x54AEBB,0x04AD4F,0x0A4D43,0x4D26B7,0x0D254B,0x8D52BF,0x0B5452,0x0B6A47,0x696D3C,0x095B50,/*1971-1980*/
0x049B45,0x4A4BB9,0x0A4B4D,0xAB25C2,0x06A554,0x06D449,0x6ADA3D,0x0AB651,0x093746,0x5497BB,/*1981-1990*/
0x04974F,0x064B44,0x36A537,0x0EA54A,0x86B2BF,0x05AC53,0x0AB647,0x5936BC,0x092E50,0x0C9645,/*1991-2000*/
0x4D4AB8,0x0D4A4C,0x0DA541,0x25AAB6,0x056A49,0x7AADBD,0x025D52,0x092D47,0x5C95BA,0x0A954E,/*2001-2010*/
0x0B4A43,0x4B5537,0x0AD54A,0x955ABF,0x04BA53,0x0A5B48,0x652BBC,0x052B50,0x0A9345,0x474AB9,/*2011-2020*/
0x06AA4C,0x0AD541,0x24DAB6,0x04B64A,0x69573D,0x0A4E51,0x0D2646,0x5E933A,0x0D534D,0x05AA43,/*2021-2030*/
0x36B537,0x096D4B,0xB4AEBF,0x04AD53,0x0A4D48,0x6D25BC,0x0D254F,0x0D5244,0x5DAA38,0x0B5A4C,/*2031-2040*/
0x056D41,0x24ADB6,0x049B4A,0x7A4BBE,0x0A4B51,0x0AA546,0x5B52BA,0x06D24E,0x0ADA42,0x355B37,/*2041-2050*/
0x09374B,0x8497C1,0x049753,0x064B48,0x66A53C,0x0EA54F,0x06B244,0x4AB638,0x0AAE4C,0x092E42,/*2051-2060*/
0x3C9735,0x0C9649,0x7D4ABD,0x0D4A51,0x0DA545,0x55AABA,0x056A4E,0x0A6D43,0x452EB7,0x052D4B,/*2061-2070*/
0x8A95BF,0x0A9553,0x0B4A47,0x6B553B,0x0AD54F,0x055A45,0x4A5D38,0x0A5B4C,0x052B42,0x3A93B6,/*2071-2080*/
0x069349,0x7729BD,0x06AA51,0x0AD546,0x54DABA,0x04B64E,0x0A5743,0x452738,0x0D264A,0x8E933E,/*2081-2090*/
0x0D5252,0x0DAA47,0x66B53B,0x056D4F,0x04AE45,0x4A4EB9,0x0A4D4C,0x0D1541,0x2D92B5 /*2091-2099*/
};
static int MonthAdd[12] = { 0,31,59,90,120,151,181,212,243,273,304,334 };
static int LunarCalendar(int year, int month, int day)
{
int Spring_NY, Sun_NY, StaticDayCount;
int index, flag;
//Spring_NY 记录春节离当年元旦的天数。
//Sun_NY 记录阳历日离当年元旦的天数。
if (((LunarCalendarTable[year - 1901] & 0x0060) >> 5) == 1)
Spring_NY = (LunarCalendarTable[year - 1901] & 0x001F) - 1;
else
Spring_NY = (LunarCalendarTable[year - 1901] & 0x001F) - 1 + 31;
Sun_NY = MonthAdd[month - 1] + day - 1;
if ((!(year % 4)) && (month > 2))
Sun_NY++;
//特殊处理2025年4月28日-2025年5月26日
if (year == 2025 && ((month == 4 && day >= 28) || (month == 5 && day <= 26))) {
Sun_NY--;
}
// 特殊处理2025年4月27日
if (year == 2025 && month == 4 && day == 27) {
LunarCalendarDay = (3 << 6) | 30;
return 0;
}
//StaticDayCount记录大小月的天数 29 或30
//index 记录从哪个月开始来计算。
//flag 是用来对闰月的特殊处理。
//判断阳历日在春节前还是春节后
if (Sun_NY >= Spring_NY)//阳历日在春节后(含春节那天)
{
Sun_NY -= Spring_NY;
month = 1;
index = 1;
flag = 0;
int leap_month = (LunarCalendarTable[year - 1901] & 0xF00000) >> 20;
while (1) {
if ((LunarCalendarTable[year - 1901] & (0x80000 >> (index - 1))))
StaticDayCount = 30;
else
StaticDayCount = 29;
if (Sun_NY < StaticDayCount)
break;
Sun_NY -= StaticDayCount;
if (month == leap_month && !flag) {
flag = 1; // 遇到闰月,处理闰月
int leapDays = ((LunarCalendarTable[year - 1901] & (0x80000 >> (index))) ? 30 : 29);
if (Sun_NY < leapDays) {
// 闰月内
month = leap_month;
flag = 1;
break;
}
else {
Sun_NY -= leapDays;
index++;
}
}
index++;
month++;
}
day = Sun_NY + 1;
}
else //阳历日在春节前
{
Spring_NY -= Sun_NY;
year--;
month = 12;
if (((LunarCalendarTable[year - 1901] & 0xF00000) >> 20) == 0)
index = 12;
else
index = 13;
flag = 0;
if ((LunarCalendarTable[year - 1901] & (0x80000 >> (index - 1))) == 0)
StaticDayCount = 29;
else
StaticDayCount = 30;
while (Spring_NY > StaticDayCount)
{
Spring_NY -= StaticDayCount;
index--;
if (flag == 0)
month--;
if (month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20))
flag = ~flag;
if ((LunarCalendarTable[year - 1901] & (0x80000 >> (index - 1))) == 0)
StaticDayCount = 29;
else
StaticDayCount = 30;
}
day = StaticDayCount - Spring_NY + 1;
}
LunarCalendarDay |= day;
LunarCalendarDay |= (month << 6);
if (month == ((LunarCalendarTable[year - 1901] & 0xF00000) >> 20))
return 1;
else
return 0;
}
// char *to_luanr(int year,int month,int day)
void to_luanr(int year, int month, int day)
{
const char* ChDay[] = { "*","初一","初二","初三","初四","初五",
"初六","初七","初八","初九","初十",
"十一","十二","十三","十四","十五",
"十六","十七","十八","十九","二十",
"廿一","廿二","廿三","廿四","廿五",
"廿六","廿七","廿八","廿九","三十"
};
const char* ChMonth[] = { "*","","","","","","","","","","","十一","" };
// char *str;
// str = (char *)lv_mem_alloc(15);
char str[15];
memset(str, 0, 15);
LunarCalendarDay = 0;
if (LunarCalendar(year, month, day))
{
strcat(str, "");
strcat(str, ChMonth[(LunarCalendarDay & 0x3C0) >> 6]);
}
else
strcat(str, ChMonth[(LunarCalendarDay & 0x3C0) >> 6]);
strcat(str, "");
strcat(str, ChDay[LunarCalendarDay & 0x3F]);
printf("str:%s\n", str);
// return str; //记得lv_mem_free(str);
}
int main(int argc, char* argv[]) {
if (argc != 4) {
printf("Usage: %s <year> <month> <day>\n", argv[0]);
return 1;
}
int year = atoi(argv[1]);
int month = atoi(argv[2]);
int day = atoi(argv[3]);
if (year < 1901 || year > 2099 || month < 1 || month > 12 || day < 1 || day > 31) {
printf("Invalid date. Please provide a valid year (1901-2099), month (1-12), and day (1-31).\n");
return 1;
}
to_luanr(year, month, day);
return 0;
}