tested all sensors
This commit is contained in:
parent
1ccbf39e96
commit
ad38d7b758
19 changed files with 14071 additions and 14053 deletions
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/TH05_v07.bin
BIN
bin/TH05_v07.bin
Binary file not shown.
BIN
bin/THB2_v07.bin
BIN
bin/THB2_v07.bin
Binary file not shown.
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.
Binary file not shown.
Binary file not shown.
|
|
@ -12,9 +12,7 @@
|
|||
#include "sensor.h"
|
||||
#include "bthome_beacon.h"
|
||||
|
||||
//adv_buf_t adv_buf;
|
||||
|
||||
void bthome_data_beacon(void * padbuf) {
|
||||
uint8_t bthome_data_beacon(void * padbuf) {
|
||||
#if (DEV_SERVICES & SERVICE_THS)
|
||||
padv_bthome_ns1_t p = (padv_bthome_ns1_t)padbuf;
|
||||
#else
|
||||
|
|
@ -46,7 +44,13 @@ void bthome_data_beacon(void * padbuf) {
|
|||
#endif
|
||||
p->data.v_id = BtHomeID_voltage;
|
||||
p->data.battery_mv = measured_data.battery_mv; // x mV
|
||||
#if (DEV_SERVICES & SERVICE_THS)
|
||||
p->head.size = sizeof(adv_bthome_ns1_t) - sizeof(p->head.size) - sizeof(p->flag);
|
||||
return sizeof(adv_bthome_ns1_t);
|
||||
#else
|
||||
p->head.size = sizeof(adv_bthome_ns2_t) - sizeof(p->head.size) - sizeof(p->flag);
|
||||
return sizeof(adv_bthome_ns2_t);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -152,15 +152,6 @@ typedef struct __attribute__((packed)) _adv_bthome_ns2_t {
|
|||
adv_bthome_data2_t data;
|
||||
} adv_bthome_ns2_t, * padv_bthome_ns2_t;
|
||||
|
||||
typedef struct _adv_buf_t {
|
||||
uint32 send_count; // count & id advertise, = beacon_nonce.cnt32
|
||||
// uint16 old_measured_count; // old measured_data.count
|
||||
// uint16 adv_restore_count;
|
||||
adv_bthome_ns1_t data;
|
||||
} adv_buf_t;
|
||||
|
||||
//void bls_set_advertise_prepare(void *p);
|
||||
//int app_advertise_prepare_handler(rf_packet_adv_t * p);
|
||||
void bthome_data_beacon(void * padbuf);
|
||||
uint8_t bthome_data_beacon(void * padbuf);
|
||||
|
||||
#endif /* BTHOME_BEACON_H_ */
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
#define DEVICE_TH05 21
|
||||
|
||||
#ifndef DEVICE
|
||||
#define DEVICE DEVICE_THB2
|
||||
#define DEVICE DEVICE_TH05
|
||||
#endif
|
||||
|
||||
// supported services by the device (bits)
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
#define OTA_TYPE_APP SERVICE_OTA_EXT // переключение из APP на OTA + boot прошивку, пока не реализовано
|
||||
|
||||
#ifndef OTA_TYPE
|
||||
#define OTA_TYPE OTA_TYPE_NONE
|
||||
#define OTA_TYPE OTA_TYPE_BOOT
|
||||
#endif
|
||||
|
||||
#define DEF_SOFTWARE_REVISION {'V', '0'+ (APP_VERSION >> 4), '.' , '0'+ (APP_VERSION & 0x0F), 0}
|
||||
|
|
@ -133,14 +133,14 @@
|
|||
/* Model: TH05 */
|
||||
#if OTA_TYPE == OTA_TYPE_BOOT
|
||||
#define DEV_SERVICES (OTA_TYPE \
|
||||
| SERVICE_THS \
|
||||
| SERVICE_SCREEN \
|
||||
| SERVICE_THS \
|
||||
| SERVICE_KEY \
|
||||
)
|
||||
#else
|
||||
#define DEV_SERVICES (OTA_TYPE \
|
||||
| SERVICE_THS \
|
||||
| SERVICE_SCREEN \
|
||||
| SERVICE_THS \
|
||||
| SERVICE_KEY \
|
||||
| SERVICE_HISTORY \
|
||||
)
|
||||
|
|
@ -181,7 +181,7 @@
|
|||
// Supervision timeout value (units of 10ms, 1000=10s) if automatic parameter update request is enabled
|
||||
#define DEFAULT_DESIRED_CONN_TIMEOUT 400 // 4s
|
||||
|
||||
typedef struct /*__attribute__((packed))*/ _cfg_t {
|
||||
typedef struct _cfg_t {
|
||||
uint32_t flg;
|
||||
|
||||
uint8_t rf_tx_power; //
|
||||
|
|
@ -189,8 +189,8 @@ typedef struct /*__attribute__((packed))*/ _cfg_t {
|
|||
uint8_t connect_latency; // +1 x 0.03 sec ( = connection interval), Tmin = 1*30 = 30 ms, Tmax = 256 * 30 = 7680 ms
|
||||
uint8_t reserved1;
|
||||
|
||||
uint8_t measure_interval; // measure_interval
|
||||
uint8_t batt_interval; // * measure_interval
|
||||
uint8_t measure_interval; // measure TH sensor count * advertising_interval
|
||||
uint8_t batt_interval; // measure battery * seconds
|
||||
uint8_t averaging_measurements; // * measure_interval, 0 - off, 1..255 * measure_interval
|
||||
uint8_t reserved2;
|
||||
|
||||
|
|
|
|||
|
|
@ -177,11 +177,11 @@ void show_small_number(int16_t number, bool percent) {
|
|||
display_buff[4] &= BIT(3); // connect
|
||||
display_buff[5] = percent? BIT(3) : 0;
|
||||
if (number > 99) {
|
||||
display_buff[4] |= LCD_SYM_i; // "i"
|
||||
display_buff[5] |= LCD_SYM_H; // "H"
|
||||
display_buff[4] |= LCD_SYM_H; // "H"
|
||||
display_buff[5] |= LCD_SYM_i; // "i"
|
||||
} else if (number < -9) {
|
||||
display_buff[4] |= LCD_SYM_o; // "o"
|
||||
display_buff[5] |= LCD_SYM_L; // "L"
|
||||
display_buff[4] |= LCD_SYM_L; // "L"
|
||||
display_buff[5] |= LCD_SYM_o; // "o"
|
||||
} else {
|
||||
if (number < 0) {
|
||||
number = -number;
|
||||
|
|
|
|||
|
|
@ -15,49 +15,59 @@
|
|||
#define SENSOR_RESET_TIMEOUT_ms 3
|
||||
#define SENSOR_MEASURING_TIMEOUT_ms 7
|
||||
|
||||
/* CHT8310 https://github.com/pvvx/pvvx.github.io/blob/master/THB2/CHT8310.Advanced.Datasheet_Ver1.0.20230407.pdf */
|
||||
// I2C addres
|
||||
#define CHT8315_I2C_ADDR0 0x40
|
||||
#define CHT8315_I2C_ADDR1 0x44
|
||||
#define CHT8315_I2C_ADDR2 0x48
|
||||
#define CHT8315_I2C_ADDR3 0x4C
|
||||
|
||||
// Registers
|
||||
#define CHT8315_REG_TMP 0x00
|
||||
#define CHT8315_REG_HMD 0x01
|
||||
#define CHT8315_REG_STA 0x02
|
||||
#define CHT8315_REG_CFG 0x03
|
||||
#define CHT8315_REG_CRT 0x04
|
||||
#define CHT8315_REG_TLL 0x05
|
||||
#define CHT8315_REG_TLM 0x06
|
||||
#define CHT8315_REG_HLL 0x07
|
||||
#define CHT8315_REG_HLM 0x08
|
||||
#define CHT8315_REG_OST 0x0f
|
||||
#define CHT8315_REG_RST 0xfc
|
||||
#define CHT8315_REG_MID 0xfe
|
||||
#define CHT8315_REG_VID 0xff
|
||||
|
||||
// Status register mask
|
||||
#define CHT8315_STA_BUSY 0x8000
|
||||
#define CHT8315_STA_THI 0x4000
|
||||
#define CHT8315_STA_TLO 0x2000
|
||||
#define CHT8315_STA_HHI 0x1000
|
||||
#define CHT8315_STA_HLO 0x0800
|
||||
|
||||
// Config register mask
|
||||
#define CHT8315_CFG_MASK 0x8000
|
||||
#define CHT8315_CFG_SD 0x4000
|
||||
#define CHT8315_CFG_ALTH 0x2000
|
||||
#define CHT8315_CFG_EM 0x1000
|
||||
#define CHT8315_CFG_EHT 0x0100
|
||||
#define CHT8315_CFG_TME 0x0080
|
||||
#define CHT8315_CFG_POL 0x0020
|
||||
#define CHT8315_CFG_ALT 0x0018
|
||||
#define CHT8315_CFG_CONSEC_FQ 0x0006
|
||||
#define CHT8315_CFG_ATM 0x0001
|
||||
#define CHT83xx_I2C_ADDR 0x40
|
||||
#define CHT83xx_REG_TMP 0x00
|
||||
#define CHT83xx_REG_HMD 0x01
|
||||
#define CHT83xx_REG_MID 0xfe
|
||||
#define CHT83xx_REG_VID 0xff
|
||||
|
||||
#define CHT83xx_MID 0x5959
|
||||
#define CHT8315_VID 0x1582
|
||||
|
||||
|
||||
/* CHT8310 https://github.com/pvvx/pvvx.github.io/blob/master/THB2/CHT8310.Advanced.Datasheet_Ver1.0.20230407.pdf */
|
||||
// I2C addres
|
||||
|
||||
#define CHT8215_I2C_ADDR0 0x40
|
||||
#define CHT8215_I2C_ADDR1 0x44
|
||||
#define CHT8215_I2C_ADDR2 0x48
|
||||
#define CHT8215_I2C_ADDR3 0x4C
|
||||
|
||||
// Registers
|
||||
#define CHT8215_REG_TMP 0x00
|
||||
#define CHT8215_REG_HMD 0x01
|
||||
#define CHT8215_REG_STA 0x02
|
||||
#define CHT8215_REG_CFG 0x03
|
||||
#define CHT8215_REG_CRT 0x04
|
||||
#define CHT8215_REG_TLL 0x05
|
||||
#define CHT8215_REG_TLM 0x06
|
||||
#define CHT8215_REG_HLL 0x07
|
||||
#define CHT8215_REG_HLM 0x08
|
||||
#define CHT8215_REG_OST 0x0f
|
||||
#define CHT8215_REG_RST 0xfc
|
||||
#define CHT8215_REG_MID 0xfe
|
||||
#define CHT8215_REG_VID 0xff
|
||||
|
||||
// Status register mask
|
||||
#define CHT8215_STA_BUSY 0x8000
|
||||
#define CHT8215_STA_THI 0x4000
|
||||
#define CHT8215_STA_TLO 0x2000
|
||||
#define CHT8215_STA_HHI 0x1000
|
||||
#define CHT8215_STA_HLO 0x0800
|
||||
|
||||
// Config register mask
|
||||
#define CHT8215_CFG_MASK 0x8000
|
||||
#define CHT8215_CFG_SD 0x4000
|
||||
#define CHT8215_CFG_ALTH 0x2000
|
||||
#define CHT8215_CFG_EM 0x1000
|
||||
#define CHT8215_CFG_EHT 0x0100
|
||||
#define CHT8215_CFG_TME 0x0080
|
||||
#define CHT8215_CFG_POL 0x0020
|
||||
#define CHT8215_CFG_ALT 0x0018
|
||||
#define CHT8215_CFG_CONSEC_FQ 0x0006
|
||||
#define CHT8215_CFG_ATM 0x0001
|
||||
|
||||
#define CHT8315_MID 0x5959
|
||||
#define CHT8215_VID 0x1582
|
||||
|
||||
/* CHT8305 https://github.com/pvvx/pvvx.github.io/blob/master/BTH01/CHT8305.pdf */
|
||||
|
||||
|
|
@ -110,6 +120,7 @@ struct __attribute__((packed)) _cht8305_config_t{
|
|||
} cht8305_config_t;
|
||||
*/
|
||||
|
||||
#define CHT8305_MID 0x5959
|
||||
#define CHT8305_VID 0x0583
|
||||
|
||||
/*---------------------------------------
|
||||
|
|
|
|||
|
|
@ -9,15 +9,17 @@
|
|||
measured_data_t measured_data;
|
||||
|
||||
#if (DEV_SERVICES & SERVICE_THS)
|
||||
#include "clock.h"
|
||||
#include "OSAL.h"
|
||||
#include "gpio.h"
|
||||
#include "rom_sym_def.h"
|
||||
#include "dev_i2c.h"
|
||||
|
||||
#define I2C_SPEED 1
|
||||
|
||||
thsensor_cfg_t thsensor_cfg;
|
||||
|
||||
const thsensor_coef_t def_thcoef_cht8310 = {
|
||||
const thsensor_coef_t def_thcoef_cht8215 = {
|
||||
.temp_k = 25606,
|
||||
.humi_k = 20000,
|
||||
.temp_z = 0,
|
||||
|
|
@ -39,19 +41,22 @@ const thsensor_coef_t def_thcoef_aht30 = {
|
|||
};
|
||||
|
||||
|
||||
int read_sensor_cht83xx(void) {
|
||||
uint8 reg_data[4];
|
||||
int32 _r32;
|
||||
int16 _r16;
|
||||
init_i2c(1);
|
||||
_r32 = read_i2c_bytes(thsensor_cfg.i2c_addr, CHT8315_REG_TMP, reg_data, 2);
|
||||
//? WaitUs(100);
|
||||
_r32 |= read_i2c_bytes(thsensor_cfg.i2c_addr, CHT8315_REG_HMD, ®_data[2], 2);
|
||||
int read_sensor_cht8xxx(void) {
|
||||
uint8_t reg_data[4];
|
||||
int32_t _r32;
|
||||
int16_t _r16;
|
||||
init_i2c(I2C_SPEED);
|
||||
if(thsensor_cfg.vid == CHT8305_VID) {
|
||||
_r32 = read_i2c_nabuf(thsensor_cfg.i2c_addr, reg_data, 4);
|
||||
} else {
|
||||
_r32 = read_i2c_bytes(thsensor_cfg.i2c_addr, CHT83xx_REG_TMP, reg_data, 2);
|
||||
_r32 |= read_i2c_bytes(thsensor_cfg.i2c_addr, CHT83xx_REG_HMD, ®_data[2], 2);
|
||||
}
|
||||
deinit_i2c();
|
||||
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;
|
||||
_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;
|
||||
|
|
@ -65,8 +70,8 @@ int read_sensor_cht83xx(void) {
|
|||
|
||||
int read_sensor_ahtxx(void) {
|
||||
uint32_t _temp;
|
||||
uint8 reg_data[8];
|
||||
init_i2c(1);
|
||||
uint8_t reg_data[8];
|
||||
init_i2c(I2C_SPEED);
|
||||
if(!read_i2c_nabuf(thsensor_cfg.i2c_addr, reg_data, 7)
|
||||
&& (reg_data[0] & 0x80) == 0) { // busy
|
||||
deinit_i2c();
|
||||
|
|
@ -98,13 +103,13 @@ int read_sensor(void) {
|
|||
void start_measure(void) {
|
||||
if(thsensor_cfg.i2c_addr) {
|
||||
if(thsensor_cfg.i2c_addr == AHT2x_I2C_ADDR) {
|
||||
init_i2c(1);
|
||||
init_i2c(I2C_SPEED);
|
||||
send_i2c_wreg(thsensor_cfg.i2c_addr, AHT2x_CMD_TMS, AHT2x_DATA_TMS);
|
||||
deinit_i2c();
|
||||
}
|
||||
else if(thsensor_cfg.i2c_addr == CHT8305_I2C_ADDR0) {
|
||||
init_i2c(1);
|
||||
send_i2c_byte(thsensor_cfg.i2c_addr, CHT8305_REG_TMP); // start measure T/H
|
||||
else if(thsensor_cfg.vid == CHT8305_VID) {
|
||||
init_i2c(I2C_SPEED);
|
||||
send_i2c_byte(thsensor_cfg.i2c_addr, CHT83xx_REG_TMP); // start measure T/H
|
||||
deinit_i2c();
|
||||
}
|
||||
}
|
||||
|
|
@ -113,32 +118,29 @@ void start_measure(void) {
|
|||
__ATTR_SECTION_XIP__ void init_sensor(void) {
|
||||
uint8_t *ptabinit = NULL;
|
||||
thsensor_cfg.read_sensor = NULL;
|
||||
init_i2c(1);
|
||||
thsensor_cfg.i2c_addr = CHT8315_I2C_ADDR0;
|
||||
if(!read_i2c_bytes(thsensor_cfg.i2c_addr, CHT8315_REG_MID, (uint8 *)&thsensor_cfg.mid, 2) // 0x5959
|
||||
&& !read_i2c_bytes(thsensor_cfg.i2c_addr, CHT8315_REG_VID, (uint8 *)&thsensor_cfg.vid, 2)) { // 0x8215
|
||||
init_i2c(I2C_SPEED);
|
||||
//send_i2c_byte(0,6);
|
||||
thsensor_cfg.i2c_addr = CHT83xx_I2C_ADDR;
|
||||
if(!read_i2c_bytes(thsensor_cfg.i2c_addr, CHT83xx_REG_MID, (uint8 *)&thsensor_cfg.mid, 2) // 0x5959
|
||||
&& !read_i2c_bytes(thsensor_cfg.i2c_addr, CHT83xx_REG_VID, (uint8 *)&thsensor_cfg.vid, 2)) { // 0x8215
|
||||
if(thsensor_cfg.mid == CHT83xx_MID) {
|
||||
if(thsensor_cfg.vid == CHT8305_VID) {
|
||||
ptabinit = (uint8_t *)&def_thcoef_cht8305;
|
||||
thsensor_cfg.read_sensor = read_sensor_cht83xx;
|
||||
} else if(thsensor_cfg.vid == CHT8315_VID) { // 0x8210/0x8215 ?
|
||||
/* #if USE_DEFAULT_SETS_SENSOR
|
||||
hal_gpio_write(GPIO_SPWR, 0);
|
||||
WaitMs(SENSOR_POWER_TIMEOUT_ms);
|
||||
hal_gpio_write(GPIO_SPWR, 1);
|
||||
#else
|
||||
#if 0 // USE_DEFAULT_SETS_SENSOR
|
||||
// Soft reset command
|
||||
send_i2c_wreg(thsensor_cfg.i2c_addr, CHT8305_REG_CFG,
|
||||
CHT8305_CFG_SOFT_RESET | CHT8305_CFG_MODE);
|
||||
CHT8305_CFG_SOFT_RESET | CHT8305_CFG_MODE);
|
||||
WaitMs(SENSOR_RESET_TIMEOUT_ms);
|
||||
// Configure
|
||||
send_i2c_wreg(thsensor_cfg.i2c_addr, CHT8305_REG_CFG, CHT8305_CFG_MODE );
|
||||
#endif */
|
||||
#endif
|
||||
ptabinit = (uint8_t *)&def_thcoef_cht8305;
|
||||
thsensor_cfg.read_sensor = read_sensor_cht8xxx;
|
||||
} else if(thsensor_cfg.vid == CHT8215_VID) { // 0x8210/0x8215 ?
|
||||
if(adv_wrk.measure_interval_ms >= 5000) // > 5 sec
|
||||
send_i2c_wreg(CHT8315_I2C_ADDR0, CHT8315_REG_CRT, 0x0300); // Set conversion ratio 5 sec
|
||||
send_i2c_wreg(thsensor_cfg.i2c_addr, CHT8215_REG_CRT, 0x0300); // Set conversion ratio 5 sec
|
||||
// else 1 sec
|
||||
thsensor_cfg.read_sensor = read_sensor_cht83xx;
|
||||
ptabinit = (uint8_t *)&def_thcoef_cht8310;
|
||||
ptabinit = (uint8_t *)&def_thcoef_cht8215;
|
||||
thsensor_cfg.read_sensor = read_sensor_cht8xxx;
|
||||
}
|
||||
} else
|
||||
thsensor_cfg.i2c_addr = 0;
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ void chow_measure(void) {
|
|||
show_temp_symbol(3);
|
||||
#else
|
||||
show_big_number_x10(measured_data.battery_mv/100);
|
||||
show_small_number(measured_data.battery, true);
|
||||
show_small_number((measured_data.battery > 99)? 99 : measured_data.battery, true);
|
||||
show_battery_symbol(1);
|
||||
#endif
|
||||
show_smiley(0);
|
||||
|
|
@ -228,8 +228,8 @@ static void adv_measure(void) {
|
|||
if (cfg.averaging_measurements != 0)
|
||||
write_memo();
|
||||
#endif
|
||||
bthome_data_beacon((void *) gapRole_AdvertData);
|
||||
LL_SetAdvData(sizeof(adv_bthome_ns2_t), gapRole_AdvertData);
|
||||
|
||||
LL_SetAdvData(bthome_data_beacon((void *) gapRole_AdvertData), gapRole_AdvertData);
|
||||
#endif
|
||||
}
|
||||
#if (DEV_SERVICES & SERVICE_THS)
|
||||
|
|
@ -245,8 +245,8 @@ static void adv_measure(void) {
|
|||
if (cfg.averaging_measurements != 0)
|
||||
write_memo();
|
||||
#endif
|
||||
bthome_data_beacon((void *) gapRole_AdvertData);
|
||||
LL_SetAdvData(sizeof(adv_bthome_ns1_t), gapRole_AdvertData);
|
||||
|
||||
LL_SetAdvData(bthome_data_beacon((void *) gapRole_AdvertData), gapRole_AdvertData);
|
||||
}
|
||||
#endif // (DEV_SERVICES & SERVICE_THS)
|
||||
if(adv_wrk.adv_con_count) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue