This commit is contained in:
pvvx 2024-02-20 07:20:01 +03:00
parent dbd040fb8d
commit 0909e6131c
29 changed files with 28879 additions and 13265 deletions

View file

@ -1,20 +1,22 @@
# BTHome THB2, BTH01, TH-05
Custom firmware for Tuya [THB2](https://pvvx.github.io/THB2), [THB1](https://pvvx.github.io/THB1), [BTH01](https://pvvx.github.io/BTH01/), [TH05_V1.4](https://pvvx.github.io/TH-05).
# BTHome THB1, THB2, BTH01, TH05(HW: v1.3..1.6)
Custom firmware for Tuya [THB2](https://pvvx.github.io/THB2), [THB1](https://pvvx.github.io/THB1), [BTH01](https://pvvx.github.io/BTH01/), [TH05_V1.3](https://pvvx.github.io/TH05-v1.3), [TH05_V1.4](https://pvvx.github.io/TH-05).
* Программа для настройки и BLE OTA [PHY62x2BTHome.html](https://pvvx.github.io/THB2/web/PHY62x2BTHome.html)
## Прошивки Boot-OTA:
* Прошивки [Boot-OTA](https://github.com/pvvx/THB2/issues/10) имеет минимум функций. Boot-OTA используются только для выполнения OTA - для загрузки полнофункциональной версии APP (Application - файлы *.bin).
Прошивка Boot-OTA для THB2 (файл bin\BOOT_THB2_v12.hex).
THB2 - файл bin\BOOT_THB2_v13.hex
Прошивка Boot-OTA для BTH01 (файл bin\BOOT_BTH01_v12.hex).
BTH01 - файл bin\BOOT_BTH01_v13.hex
Прошивка Boot-OTA для TH05 (файл bin\BOOT_TH05_v12.hex) для версий указанных на печатной плате: TH05_V1.4, TH05_V1.5, TH05_V1.6 с чипом BL55028
TH05 - файл bin\BOOT_TH05_v13.hex для версий указанных на печатной плате: [TH05_V1.4](https://pvvx.github.io/TH-05), TH05_V1.5, TH05_V1.6 с чипом BL55028
Boot-OTA для THB1 (файл bin\BOOT_BTH1_v13.hex)
Тестовые версии 1.3 пока не рекомендуются к установке (!)
TH05V13 - файл bin\BOOT_TH05V13_v13.hex для [TH05_V1.3](https://pvvx.github.io/TH05-v1.3) с чипом BL55072
THB1 - файл bin\BOOT_BTH1_v13.hex
## Основные характеристики:

3088
bin/BOOT_BTH01_v13.hex Normal file

File diff suppressed because it is too large Load diff

3158
bin/BOOT_TH05V13_v13.hex Normal file

File diff suppressed because it is too large Load diff

3151
bin/BOOT_TH05_v13.hex Normal file

File diff suppressed because it is too large Load diff

3148
bin/BOOT_THB1_v13.hex Normal file

File diff suppressed because it is too large Load diff

3085
bin/BOOT_THB2_v13.hex Normal file

File diff suppressed because it is too large Load diff

BIN
bin/BTH01_v13.bin Normal file

Binary file not shown.

BIN
bin/TH05V13_v13.bin Normal file

Binary file not shown.

BIN
bin/TH05_v13.bin Normal file

Binary file not shown.

BIN
bin/THB1_v13.bin Normal file

Binary file not shown.

BIN
bin/THB2_v13.bin Normal file

Binary file not shown.

View file

@ -49,13 +49,13 @@ DEFINES += -DPERIPHERAL_CFG=0x04
DEFINES += -DCENTRAL_CFG=0x08
DEFINES += -DHOST_CONFIG=0x4
DEFINES += -DARMCM0
DEFINES += -D_RTE_
DEFINES += -DCFG_CP
DEFINES += -DOSAL_CBTIMER_NUM_TASKS=1
DEFINES += -DHCI_TL_NONE=1
@DEFINES += -D_RTE_
#DEFINES += -DCFG_CP
#DEFINES += -DOSAL_CBTIMER_NUM_TASKS=1 - > osal_cbtimer.h
#DEFINES += -DHCI_TL_NONE=1
DEFINES += -DENABLE_LOG_ROM_=0
DEFINES += -D_OBJ_DIR_FOR_DTM_=0
DEFINES += -DDBG_ROM_MAIN=0
#DEFINES += -D_OBJ_DIR_FOR_DTM_=0
#DEFINES += -DDBG_ROM_MAIN=0
DEFINES += -DAPP_CFG=0
DEFINES += -DOSALMEM_METRICS=0
DEFINES += -DPHY_MCU_TYPE=MCU_BUMBEE_M0
@ -278,6 +278,9 @@ all: directory $(SRC_O) $(OBJ_DIR)/$(PROJECT_NAME).elf $(OBJ_DIR)/$(PROJECT_NAME
flash:
@$(PYTHON) ./rdwr_phy62x2.py -p$(COM_PORT) -b 1000000 -r wh $(OBJ_DIR)/$(PROJECT_NAME).hex
flash_ota:
@$(PYTHON) ./rdwr_phy62x2.py -p$(COM_PORT) -b 1000000 -r we 0x10000 $(OBJ_DIR)/$(PROJECT_NAME).bin
erase_and_flash:
@$(PYTHON) ./rdwr_phy62x2.py -p$(COM_PORT) -b 1000000 -e -r wh $(OBJ_DIR)/$(PROJECT_NAME).hex

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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -38,7 +38,7 @@ void __attribute__((used)) hal_ADC_IRQHandler(void) {
}
AP_ADCC->intr_clear = 0x1FF;
// stop_adc_batt
AP_AON->PMCTL2_1 = 0x00;
AP_AON->PMCTL2_1 = 0;
NVIC_DisableIRQ((IRQn_Type) ADCC_IRQn);
// JUMP_FUNCTION(ADCC_IRQ_HANDLER) = 0;
// AP_ADCC->intr_clear = 0x1FF;
@ -46,22 +46,17 @@ void __attribute__((used)) hal_ADC_IRQHandler(void) {
if (g_system_clk != SYS_CLK_DBL_32M) {
AP_PCRM->CLKHF_CTL1 &= ~BIT(13);
}
AP_IOMUX->Analog_IO_en &= ~BIT(ADC_PIN - P11); // hal_gpio_cfg_analog_io(ADC_PIN, Bit_DISABLE);
#if !ADC_PIN_USE_OUT
// hal_gpio_pin_init(ADC_PIN, GPIO_INPUT); // ie=0, oen=1 set to imput
// hal_gpio_pull_set(ADC_PIN, GPIO_FLOATING);
#endif
AP_PCRM->ANA_CTL &= ~BIT(0); // Power down analog LDO
AP_IOMUX->Analog_IO_en = 0; /// &= ~BIT(ADC_PIN - P11); // hal_gpio_cfg_analog_io(ADC_PIN, Bit_DISABLE);
AP_PCRM->ANA_CTL &= ~BIT(0); // Power down analog LDO
hal_clk_reset(MOD_ADCC);
hal_clk_gate_disable(MOD_ADCC);
hal_pwrmgr_unlock(MOD_ADCC);
// 3280/3764 = 0.8714
// 30*3764 = 112920
// 112920 * 1904 = 214999680
// 214999680 >> 16 = 3280
AP_IOMUX->pad_ps0 &= ~BIT(ADC_PIN); // hal_gpio_ds_control(ADC_PIN, Bit_ENABLE);
LOG("ADC_measure = %d\n", adc_sum);
#if ADC_VBAT_CHL == VBAT_ADC_P15
measured_data.battery_mv = (adc_sum * 1710) >> 16; // 3200*65536/(30*4096)=1706.666
#else
measured_data.battery_mv = (adc_sum * 1904) >> 16;
#endif
if (measured_data.battery_mv < 3000)
if (measured_data.battery_mv > 2000)
measured_data.battery = (measured_data.battery_mv - 2000) / 10;
@ -72,6 +67,8 @@ void __attribute__((used)) hal_ADC_IRQHandler(void) {
#if ((DEV_SERVICES & SERVICE_THS) == 0)
measured_data.count++;
#endif
hal_pwrmgr_unlock(MOD_ADCC);
extern uint8 gapRole_AdvEnabled;
if (!gapRole_AdvEnabled)
osal_set_event(simpleBLEPeripheral_TaskID, BATT_VALUE_EVT);
@ -110,23 +107,6 @@ void batt_start_measure(void) {
#else
AP_ADCC->intr_mask = BIT(ADC_VBAT_CHL + 1); // ENABLE_ADC_INT;
#endif
#if 0
#if ADC_VBAT_CHL == VBAT_ADC_P11
AP_ADCC->intr_mask = BIT(ADC_VBAT_CHL + 1); // ENABLE_ADC_INT;
#elif ADC_VBAT_CHL == VBAT_ADC_P23
AP_ADCC->intr_mask = BIT(ADC_VBAT_CHL - 1); // ENABLE_ADC_INT;
#elif ADC_VBAT_CHL == VBAT_ADC_P24
AP_ADCC->intr_mask = BIT(ADC_VBAT_CHL + 1); // ENABLE_ADC_INT;
#elif ADC_VBAT_CHL == VBAT_ADC_P14
AP_ADCC->intr_mask = BIT(ADC_VBAT_CHL - 1); // ENABLE_ADC_INT;
#elif ADC_VBAT_CHL == VBAT_ADC_P15
AP_ADCC->intr_mask = BIT(ADC_VBAT_CHL + 1); // ENABLE_ADC_INT;
#elif ADC_VBAT_CHL == VBAT_ADC_P20
AP_ADCC->intr_mask = BIT(ADC_VBAT_CHL - 1); // ENABLE_ADC_INT;
#endif
#endif
}
static void init_adc_batt(void) {
@ -151,14 +131,20 @@ static void init_adc_batt(void) {
// AP_PCRM->ADC_CTL4 |= BIT(4); // mannual mode
AP_PCRM->ADC_CTL4 &= ~BIT(4); //enable auto mode
AP_PCRM->ADC_CTL4 |= BIT(0);
#if ADC_VBAT_CHL == VBAT_ADC_P20
AP_AON->PMCTL2_1 = BIT(7 + 8);
//AP_AON->PMCTL2_1 |= BIT(7); // -> 0.8V, else 3.2V
#else
AP_AON->PMCTL2_1 = BIT((ADC_VBAT_CHL - MIN_ADC_CH) + 8);
// AP_AON->PMCTL2_1 |= BIT(ADC_VBAT_CHL - MIN_ADC_CH); // -> 0.8V, else 3.2V
#endif
AP_PCRM->ADC_CTL0 &= ~(BIT(20) | BIT(4));
AP_PCRM->ADC_CTL1 &= ~(BIT(20) | BIT(4));
AP_PCRM->ADC_CTL2 &= ~(BIT(20) | BIT(4));
AP_PCRM->ADC_CTL3 &= ~(BIT(20) | BIT(4));
AP_PCRM->ANA_CTL &= ~BIT(23); //disable micbias
#if ADC_PIN_USE_OUT
hal_gpio_pin_init(ADC_PIN, GPIO_OUTPUT);
hal_gpio_pull_set(ADC_PIN, GPIO_PULL_UP);
hal_gpio_write(ADC_PIN, 1);
AP_IOMUX->pad_ps0 |= BIT(ADC_PIN); // hal_gpio_ds_control(ADC_PIN, Bit_ENABLE);
#else

View file

@ -93,7 +93,7 @@ void test_config(void) {
cfg.rf_tx_power = RF_PHY_TX_POWER_EXTRA_MAX;
g_rfPhyTxPower = cfg.rf_tx_power;
rf_phy_set_txPower(g_rfPhyTxPower);
#if FIX_CONN_INTERVAL
#if 1 // FIX_CONN_INTERVAL
gapRole_MinConnInterval = periConnParameters.intervalMin = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
gapRole_MaxConnInterval = periConnParameters.intervalMax = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
gapRole_SlaveLatency = periConnParameters.latency = cfg.connect_latency;

View file

@ -43,7 +43,7 @@
#define DEVICE_TH05V13 24
#ifndef DEVICE
#define DEVICE DEVICE_TH05V13
#define DEVICE DEVICE_THB1
#endif
// supported services by the device (bits)
@ -267,6 +267,10 @@
#error "Not SERVICE_TH_TRG!"
#endif
//#define GPIO_LED GPIO_P00 // не припаян
//#define LED_ON 1
//#define LED_OFF 0
#define ADC_PIN_USE_OUT 1 // нет подключения к +Vbat
#define ADC_PIN GPIO_P15
#define ADC_VBAT_CHL VBAT_ADC_P15

View file

@ -22,7 +22,7 @@
5.0
BLE --1.0-- --2.0-- |-------------4.6-------------|
0.4 | | | | 3.6 | 3.5 | 3.2 | 3.1 | 4.5 | ]
0.4 | | | | 3.6 | 3.5 | 3.1 | 3.2 | 4.5 | ]
1.4 1.1 2.4 2.1 |-------------4.6-------------|
0.1 0.1 | | | |
0.0( O 0.2 O )0.0 --1.5-- --2.5--

View file

@ -192,9 +192,9 @@ void show_battery(uint8_t level) {
if(level > 84)
display_buff[4] |= BIT(5);
if(level > 68)
display_buff[3] |= BIT(1);
if(level > 52)
display_buff[3] |= BIT(2);
if(level > 52)
display_buff[3] |= BIT(1);
if(level > 36)
display_buff[3] |= BIT(5);
if(level > 20)

View file

@ -235,7 +235,7 @@ const ioinit_cfg_t ioInit[] = {
{ GPIO_P00, GPIO_PULL_DOWN }, // LED - не припаян R1 Q10 ...
{ GPIO_P01, GPIO_PULL_DOWN },
{ GPIO_P02, GPIO_PULL_UP }, // KEY - GPIO_KEY
{ GPIO_P03, GPIO_PULL_DOWN },
{ GPIO_P03, GPIO_PULL_UP },
{ GPIO_P07, GPIO_PULL_UP }, // CHT8305 Alert
#ifdef GPIO_TRG
{ GPIO_P09, GPIO_FLOATING }, // TX - GPIO_TRG
@ -245,7 +245,7 @@ const ioinit_cfg_t ioInit[] = {
{ GPIO_P10, GPIO_PULL_UP }, // RX - GPIO_INP
{ GPIO_P11, GPIO_FLOATING }, // BL55072 SDA
{ GPIO_P14, GPIO_FLOATING }, // BL55072 SCL
{ GPIO_P15, GPIO_PULL_DOWN }, // назначен как ADC_PIN, т.к. вывод P20 подключен к делителю
{ GPIO_P15, GPIO_PULL_UP }, // назначен как ADC_PIN, т.к. вывод P20 подключен к делителю
{ GPIO_P16, GPIO_PULL_DOWN },
{ GPIO_P17, GPIO_PULL_DOWN },
{ GPIO_P18, GPIO_FLOATING }, // I2C_SDA CHT8310
@ -278,8 +278,10 @@ const ioinit_cfg_t ioInit[] = {
#endif
};
for (uint8_t i = 0; i < sizeof(ioInit) / sizeof(ioinit_cfg_t); i++)
for (uint8_t i = 0; i < sizeof(ioInit) / sizeof(ioinit_cfg_t); i++) {
hal_gpio_pull_set(ioInit[i].pin, ioInit[i].type);
//hal_gpio_pin_init(ioInit[i].pin, GPIO_INPUT);
}
#ifdef GPIO_SPWR
hal_gpio_write(GPIO_SPWR, 1);
#endif
@ -301,6 +303,7 @@ const ioinit_cfg_t ioInit[] = {
hal_pwrmgr_RAM_retention(RET_SRAM0 | RET_SRAM1);
} else {
hal_pwrmgr_RAM_retention(RET_SRAM0); // RET_SRAM0|RET_SRAM1|RET_SRAM2
//test hal_pwrmgr_RAM_retention(RET_SRAM0 | RET_SRAM1 | RET_SRAM2);
}
#else
@ -312,7 +315,8 @@ const ioinit_cfg_t ioInit[] = {
#endif
hal_pwrmgr_RAM_retention_set();
hal_pwrmgr_LowCurrentLdo_enable();
subWriteReg(0x4000f014,26,26, 1); // hal_pwrmgr_LowCurrentLdo_enable();
//hal_pwrmgr_LowCurrentLdo_disable();
}
static void ble_mem_init_config(void) {
@ -394,8 +398,8 @@ int main(void) {
wrk.boot_flg = (uint8_t)read_reg(OTA_MODE_SELECT_REG);
#if defined(OTA_TYPE) && OTA_TYPE == OTA_TYPE_BOOT
#if (DEV_SERVICES & SERVICE_KEY)
hal_gpio_pin_init(GPIO_KEY, IE);
if (hal_gpio_read(GPIO_KEY) == 0
hal_gpio_pin_init(GPIO_KEY, GPIO_INPUT);
if (hal_gpio_read(GPIO_KEY) == 0
|| wrk.boot_flg == BOOT_FLG_OTA
|| wrk.boot_flg == BOOT_FLG_FW0) {
#else

View file

@ -809,7 +809,7 @@ static void peripheralStateReadRssiCB( int8_t rssi )
LOG("Gaprole_Disconnection\n");
osal_stop_timerEx(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT);
bthome_data_beacon((void *) gapRole_AdvertData);
#if FIX_CONN_INTERVAL
#if 1 //FIX_CONN_INTERVAL
gapRole_SlaveLatency = periConnParameters.latency = cfg.connect_latency;
#else
gapRole_SlaveLatency = cfg.connect_latency;