This commit is contained in:
pvvx 2024-04-11 19:40:09 +03:00
parent 198bbd9369
commit 35b62a3e20
49 changed files with 7348 additions and 7345 deletions

View file

@ -54,6 +54,7 @@ Custom firmware for Tuya devices on the PHY622x2 chipset
| 1.4 | Стабилизация соединения для всех вариантов устройств. Добавлен [TH05F](https://pvvx.github.io/TH05F). Коррекция хода RTC. Изменено BLE имя для TH05_V1.3 на "TH05D". Добавлены файлы для обновления Boot по OTA. |
| 1.5 | Добавлен вариант шифрования BLE рекламы с помощью BindKey. |
| 1.6 | Добавлено усреднение расчета напряжения батареи, дублирование состояния контакта open/close и счетчика через 12..20 сек (кратно интервалу рекламы) после срабатывания и далее каждые 30 минут. |
| 1.7 | Исправление ошибки (> 42 C) для сенсора CHT8305 |
## Прошивка

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

Binary file not shown.

BIN
bin/BTH01_v17.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/TH05D_v17.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/TH05F_v17.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/TH05_v17.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/THB1_v17.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/THB2_v17.bin Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/THB3_v17.bin Normal file

Binary file not shown.

View file

@ -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

View file

@ -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

View file

@ -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,64 +49,64 @@ 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, &reg_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, &reg_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)
if(read_i2c_nabuf(pi2c_dev, thsensor_cfg.i2c_addr, reg_data, 7) == 0
&& (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);
_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 %
return 0;
}
//send_i2c_wreg(&i2c_dev0, thsensor_cfg.i2c_addr, AHT2x_CMD_INI, AHT2x_DATA_LPWR);
return 1;
}
int read_sensors(void) {
int ret = 1;
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++;
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 ret = 1;
if(thsensor_cfg.i2c_addr && thsensor_cfg.read_sensor != NULL)
ret = thsensor_cfg.read_sensor();
#if (OTA_TYPE == OTA_TYPE_APP) && ((DEV_SERVICES & SERVICE_TH_TRG) || (DEV_SERVICES & SERVICE_SCREEN))
set_trigger_out();
#endif
@ -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;

View file

@ -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)

View file

@ -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);

28
fw.json
View file

@ -1,19 +1,19 @@
{"custom":[
"bin/THB2_v16.bin",
"bin/BTH01_v16.bin",
"bin/TH05_v16.bin",
"bin/THB2_v17.bin",
"bin/BTH01_v17.bin",
"bin/TH05_v17.bin",
"?",
"bin/THB1_v16.bin",
"bin/TH05D_v16.bin",
"bin/TH05F_v16.bin",
"bin/THB3_v16.bin"],
"bin/THB1_v17.bin",
"bin/TH05D_v17.bin",
"bin/TH05F_v17.bin",
"bin/THB3_v17.bin"],
"updateboot":[
"update_boot/BOOT_THB2_v16.bin",
"update_boot/BOOT_BTH01_v16.bin",
"update_boot/BOOT_TH05_v16.bin",
"update_boot/BOOT_THB2_v17.bin",
"update_boot/BOOT_BTH01_v17.bin",
"update_boot/BOOT_TH05_v17.bin",
"?",
"update_boot/BOOT_THB1_v16.bin",
"update_boot/BOOT_TH05D_v16.bin",
"update_boot/BOOT_TH05F_v16.bin",
"update_boot/BOOT_THB3_v16.bin"]
"update_boot/BOOT_THB1_v17.bin",
"update_boot/BOOT_TH05D_v17.bin",
"update_boot/BOOT_TH05F_v17.bin",
"update_boot/BOOT_THB3_v17.bin"]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,2 +1,2 @@
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_BTH01_v16.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/BTH01_v16.bin
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_BTH01_v17.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/BTH01_v17.bin

View file

@ -1,2 +1,2 @@
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_TH05_v16.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/TH05_v16.bin
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_TH05_v17.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/TH05_v17.bin

View file

@ -1,2 +1,2 @@
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_TH05D_v16.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/TH05D_v16.bin
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_TH05D_v17.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/TH05D_v17.bin

View file

@ -1,2 +1,2 @@
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_TH05F_v16.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/TH05F_v16.bin
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_TH05F_v17.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/TH05F_v17.bin

View file

@ -1,2 +1,2 @@
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_THB1_v16.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/THB1_v16.bin
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_THB1_v17.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/THB1_v17.bin

View file

@ -1,2 +1,2 @@
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_THB2_v16.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/THB2_v16.bin
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_THB2_v17.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/THB2_v17.bin

View file

@ -1,2 +1,2 @@
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_THB3_v16.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/THB3_v16.bin
python3 rdwr_phy62x2.py -p COM11 -e -r wh ./bin/BOOT_THB3_v17.hex
@rem python3 rdwr_phy62x2.py -p COM11 -r we 0x10000 ./bin/THB3_v17.bin