ver 1.7
This commit is contained in:
parent
198bbd9369
commit
35b62a3e20
49 changed files with 7348 additions and 7345 deletions
|
|
@ -1,5 +1,5 @@
|
|||
@set PATH=D:\MCU\GNU_Tools_ARM_Embedded\13.2.rel1\bin;%PATH%
|
||||
@set SWVER=_v16
|
||||
@set SWVER=_v17
|
||||
@del /Q "build\THB2%SWVER%.hex"
|
||||
@del /Q "build\THB2%SWVER%.bin"
|
||||
@mkdir .\bin
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// #include "bus_dev.h"
|
||||
|
||||
#ifndef APP_VERSION
|
||||
#define APP_VERSION 0x16 // BCD
|
||||
#define APP_VERSION 0x17 // BCD
|
||||
#endif
|
||||
|
||||
/* rf_phy_ana_cfg
|
||||
|
|
|
|||
|
|
@ -4,9 +4,6 @@
|
|||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "sensors.h"
|
||||
|
||||
measured_data_t measured_data;
|
||||
|
||||
#if (DEV_SERVICES & SERVICE_THS)
|
||||
#include "clock.h"
|
||||
|
|
@ -15,6 +12,9 @@ measured_data_t measured_data;
|
|||
#include "rom_sym_def.h"
|
||||
#include "dev_i2c.h"
|
||||
#include "trigger.h"
|
||||
#include "sensors.h"
|
||||
|
||||
measured_data_t measured_data;
|
||||
|
||||
dev_i2c_t i2c_dev0 = {
|
||||
//.pi2cdev = AP_I2C0,
|
||||
|
|
@ -49,66 +49,66 @@ const thsensor_coef_t def_thcoef_aht30 = {
|
|||
};
|
||||
|
||||
|
||||
int read_sensor_cht8xxx(void) {
|
||||
int read_sensor_cht8305(pdev_i2c_t pi2c_dev) {
|
||||
uint32_t _temp;
|
||||
uint8_t reg_data[4];
|
||||
int32_t _r32;
|
||||
int16_t _r16;
|
||||
i2c_dev0.speed = I2C_100KHZ;
|
||||
init_i2c(&i2c_dev0);
|
||||
if(thsensor_cfg.vid == CHT8305_VID) {
|
||||
_r32 = read_i2c_nabuf(&i2c_dev0, thsensor_cfg.i2c_addr, reg_data, 4);
|
||||
} else {
|
||||
_r32 = read_i2c_bytes(&i2c_dev0, thsensor_cfg.i2c_addr, CHT83xx_REG_TMP, reg_data, 2);
|
||||
_r32 |= read_i2c_bytes(&i2c_dev0, thsensor_cfg.i2c_addr, CHT83xx_REG_HMD, ®_data[2], 2);
|
||||
}
|
||||
deinit_i2c(&i2c_dev0);
|
||||
i2c_dev0.speed = I2C_400KHZ;
|
||||
if (!_r32) {
|
||||
_r16 = (reg_data[0] << 8) | reg_data[1];
|
||||
measured_data.temp = ((int32)(_r16 * thsensor_cfg.coef.temp_k) >> 16) + thsensor_cfg.coef.temp_z;; // x 0.01 C
|
||||
_r32 = ((reg_data[2] << 8) | reg_data[3]); // & 0x7fff ;
|
||||
measured_data.humi = ((uint32)(_r32 * thsensor_cfg.coef.humi_k) >> 16) + thsensor_cfg.coef.humi_z; // x 0.01 %
|
||||
if (measured_data.humi < 0)
|
||||
measured_data.humi = 0;
|
||||
else if (measured_data.humi > 9999)
|
||||
measured_data.humi = 9999;
|
||||
measured_data.count++;
|
||||
if (!read_i2c_nabuf(pi2c_dev, thsensor_cfg.i2c_addr, reg_data, 4)) {
|
||||
_temp = (reg_data[0] << 8) | reg_data[1];
|
||||
measured_data.temp = ((uint32_t)(_temp * thsensor_cfg.coef.temp_k) >> 16) + thsensor_cfg.coef.temp_z;; // x 0.01 C
|
||||
_temp = ((reg_data[2] << 8) | reg_data[3]); // & 0x7fff ;
|
||||
measured_data.humi = ((uint32_t)(_temp * thsensor_cfg.coef.humi_k) >> 16) + thsensor_cfg.coef.humi_z; // x 0.01 %
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int read_sensor_ahtxx(void) {
|
||||
int read_sensor_cht821x(pdev_i2c_t pi2c_dev) {
|
||||
uint8_t reg_data[4];
|
||||
uint32_t _r32;
|
||||
int16_t _r16;
|
||||
if (read_i2c_bytes(pi2c_dev, thsensor_cfg.i2c_addr, CHT83xx_REG_TMP, reg_data, 2) == 0
|
||||
&& read_i2c_bytes(pi2c_dev, thsensor_cfg.i2c_addr, CHT83xx_REG_HMD, ®_data[2], 2) == 0) {
|
||||
_r16 = (reg_data[0] << 8) | reg_data[1];
|
||||
measured_data.temp = ((int32_t)(_r16 * thsensor_cfg.coef.temp_k) >> 16) + thsensor_cfg.coef.temp_z;; // x 0.01 C
|
||||
_r32 = ((reg_data[2] << 8) | reg_data[3]); // & 0x7fff ;
|
||||
measured_data.humi = ((uint32_t)(_r32 * thsensor_cfg.coef.humi_k) >> 16) + thsensor_cfg.coef.humi_z; // x 0.01 %
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int read_sensor_ahtxx(pdev_i2c_t pi2c_dev) {
|
||||
uint32_t _temp;
|
||||
uint8_t reg_data[8];
|
||||
init_i2c(&i2c_dev0);
|
||||
if(!read_i2c_nabuf(&i2c_dev0, thsensor_cfg.i2c_addr, reg_data, 7)
|
||||
&& (reg_data[0] & 0x80) == 0) { // busy
|
||||
//send_i2c_wreg(&i2c_dev0, thsensor_cfg.i2c_addr, AHT2x_CMD_INI, AHT2x_DATA_LPWR);
|
||||
deinit_i2c(&i2c_dev0);
|
||||
if(read_i2c_nabuf(pi2c_dev, thsensor_cfg.i2c_addr, reg_data, 7) == 0
|
||||
&& (reg_data[0] & 0x80) == 0) { // busy
|
||||
_temp = ((reg_data[3] & 0x0F) << 16) | (reg_data[4] << 8) | reg_data[5];
|
||||
measured_data.temp = ((uint32_t)(_temp * thsensor_cfg.coef.temp_k) >> 16) + thsensor_cfg.coef.temp_z; // x 0.01 C
|
||||
_temp = (reg_data[1] << 12) | (reg_data[2] << 4) | (reg_data[3] >> 4);
|
||||
measured_data.humi = ((uint32_t)(_temp * thsensor_cfg.coef.humi_k) >> 16) + thsensor_cfg.coef.humi_z; // x 0.01 %
|
||||
if (measured_data.humi < 0)
|
||||
measured_data.humi = 0;
|
||||
else if (measured_data.humi > 9999)
|
||||
measured_data.humi = 9999;
|
||||
measured_data.count++;
|
||||
return 0;
|
||||
}
|
||||
//send_i2c_wreg(&i2c_dev0, thsensor_cfg.i2c_addr, AHT2x_CMD_INI, AHT2x_DATA_LPWR);
|
||||
deinit_i2c(&i2c_dev0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int read_sensor(void) {
|
||||
int read_sensors(void) {
|
||||
int ret = 1;
|
||||
if(thsensor_cfg.i2c_addr && thsensor_cfg.read_sensor != NULL)
|
||||
ret = thsensor_cfg.read_sensor();
|
||||
if(thsensor_cfg.i2c_addr && thsensor_cfg.read_sensor != NULL) {
|
||||
init_i2c(&i2c_dev0);
|
||||
ret = thsensor_cfg.read_sensor(&i2c_dev0);
|
||||
deinit_i2c(&i2c_dev0);
|
||||
if(!ret) {
|
||||
if (measured_data.humi < 0)
|
||||
measured_data.humi = 0;
|
||||
else if (measured_data.humi > 9999)
|
||||
measured_data.humi = 9999;
|
||||
measured_data.count++;
|
||||
}
|
||||
}
|
||||
#if (OTA_TYPE == OTA_TYPE_APP) && ((DEV_SERVICES & SERVICE_TH_TRG) || (DEV_SERVICES & SERVICE_SCREEN))
|
||||
set_trigger_out();
|
||||
set_trigger_out();
|
||||
#endif
|
||||
if(ret)
|
||||
init_sensor();
|
||||
|
|
@ -151,13 +151,13 @@ void init_sensor(void) {
|
|||
send_i2c_wreg(&i2c_dev0, thsensor_cfg.i2c_addr, CHT8305_REG_CFG, CHT8305_CFG_MODE );
|
||||
#endif
|
||||
ptabinit = (uint8_t *)&def_thcoef_cht8305;
|
||||
thsensor_cfg.read_sensor = read_sensor_cht8xxx;
|
||||
thsensor_cfg.read_sensor = read_sensor_cht8305;
|
||||
} else if(thsensor_cfg.vid == CHT8215_VID) { // 0x8210/0x8215 ?
|
||||
if(adv_wrk.measure_interval_ms >= 5000) // > 5 sec
|
||||
send_i2c_wreg(&i2c_dev0, thsensor_cfg.i2c_addr, CHT8215_REG_CRT, 0x0300); // Set conversion ratio 5 sec
|
||||
// else 1 sec
|
||||
ptabinit = (uint8_t *)&def_thcoef_cht8215;
|
||||
thsensor_cfg.read_sensor = read_sensor_cht8xxx;
|
||||
thsensor_cfg.read_sensor = read_sensor_cht821x;
|
||||
}
|
||||
} else
|
||||
thsensor_cfg.i2c_addr = 0;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#if (DEV_SERVICES & SERVICE_THS)
|
||||
|
||||
#include "dev_i2c.h"
|
||||
|
||||
// Timing
|
||||
#define SENSOR_POWER_TIMEOUT_ms 3
|
||||
#define SENSOR_RESET_TIMEOUT_ms 3
|
||||
|
|
@ -162,7 +164,7 @@ typedef struct _thsensor_coef_t {
|
|||
int16_t humi_z;
|
||||
} thsensor_coef_t;
|
||||
|
||||
typedef int (*psernsor_rd_t)(void);
|
||||
typedef int (*psernsor_rd_t)(pdev_i2c_t pi2c_dev);
|
||||
//typedef void (*psernsor_sm_t)(void);
|
||||
|
||||
typedef struct _thsensor_cfg_t {
|
||||
|
|
@ -178,7 +180,7 @@ extern thsensor_cfg_t thsensor_cfg;
|
|||
|
||||
void init_sensor(void);
|
||||
void start_measure(void);
|
||||
int read_sensor(void);
|
||||
int read_sensors(void);
|
||||
|
||||
#else // (DEV_SERVICES & SERVICE_THS)
|
||||
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ static void adv_measure(void) {
|
|||
} else {
|
||||
if(adv_wrk.meas_count >= cfg.measure_interval) {
|
||||
adv_wrk.meas_count = 0;
|
||||
read_sensor();
|
||||
read_sensors();
|
||||
if(adv_wrk.new_battery) {
|
||||
adv_wrk.new_battery = 0;
|
||||
check_battery();
|
||||
|
|
@ -635,7 +635,7 @@ uint16_t BLEPeripheral_ProcessEvent( uint8_t task_id, uint16_t events )
|
|||
adv_wrk.measure_batt_tik = clkt.utc_time_tik;
|
||||
batt_start_measure();
|
||||
}
|
||||
read_sensor();
|
||||
read_sensors();
|
||||
start_measure();
|
||||
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||
chow_lcd(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue