add test TH05_V1.3

This commit is contained in:
pvvx 2024-02-19 17:34:16 +03:00
parent ce74aa4288
commit cdf1a15762
17 changed files with 3800 additions and 161 deletions

View file

@ -1,4 +1,3 @@
bin
Listings
Objects
TestTHB2.asm

View file

@ -24,6 +24,7 @@ SRC_PRJ += thb2_peripheral.c
SRC_PRJ += thservice.c
SRC_PRJ += flash_eep.c
SRC_PRJ += lcd_th05.c
SRC_PRJ += lcd_th05v13.c
SRC_PRJ += lcd_thb1.c
SRC_PRJ += ble_ota.c
SRC_PRJ += logger.c
@ -36,7 +37,7 @@ DEFINES = -D__GCC
DEFINES += $(POJECT_DEF)
DEFINES += -DDEBUG_INFO=0
DEFINES += -DMTU_SIZE=247
DEFINES += -DTEST_RTC_DELTA=1
#DEFINES += -DTEST_RTC_DELTA=1
DEFINES += -DCFG_SLEEP_MODE=PWR_MODE_SLEEP
DEFINES += -DADV_NCONN_CFG=0x01
DEFINES += -DADV_CONN_CFG=0x02

View file

@ -1223,7 +1223,7 @@ extern uint16 ATT_GetParamValue( void );
extern uint16 ATT_GetCurrentMTUSize( uint16 connHandle );
extern void ATT_UpdateMtuSize(uint16 connHandle, uint16 mtuSize);
extern void ATT_SetMTUSizeMax(uint16 mtuSize);
extern void ATT_MTU_SIZE_UPDATE(uint8 mtuSize);
//extern void ATT_MTU_SIZE_UPDATE(uint8 mtuSize);
extern void ATT_InitMtuSize(void);

View file

@ -179,16 +179,14 @@ int hal_get_flash_info(void) {
return PPlus_SUCCESS;
}
#if(FLASH_PROTECT_FEATURE == 1)
int hal_flash_lock(void)
{
int hal_flash_wr_status(uint8_t status) {
uint32_t cs = spif_lock();
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
AP_SPIF->fcmd = 0x6000001;
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
AP_SPIF->fcmd_wrdata[0] = 0x7c;
AP_SPIF->fcmd_wrdata[0] = status;
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
AP_SPIF->fcmd = 0x1008001;
@ -198,22 +196,15 @@ int hal_flash_lock(void)
return PPlus_SUCCESS;
}
// #if(FLASH_PROTECT_FEATURE == 1)
int hal_flash_lock(void)
{
return hal_flash_wr_status(0x7c);
}
int hal_flash_unlock(void)
{
uint32_t cs = spif_lock();
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
AP_SPIF->fcmd = 0x6000001;
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
AP_SPIF->fcmd_wrdata[0] = 0x00;
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
AP_SPIF->fcmd = 0x1008001;
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
spif_unlock(cs);
return PPlus_SUCCESS;
return hal_flash_wr_status(0);
}
uint8_t hal_flash_get_lock_state(void)
@ -226,7 +217,7 @@ uint8_t hal_flash_get_lock_state(void)
spif_unlock(cs);
return status;
}
#endif
// #endif
static void hw_spif_cache_config(void)
@ -343,7 +334,7 @@ int hal_flash_write_by_dma(uint32_t addr, uint8_t *data, uint32_t size) {
}
int hal_flash_erase_sector(unsigned int addr) {
uint8_t retval;
uint8_t retval = PPlus_SUCCESS;
#if(FLASH_PROTECT_FEATURE == 1)
hal_flash_unlock();
#endif
@ -352,7 +343,15 @@ int hal_flash_erase_sector(unsigned int addr) {
HAL_CACHE_ENTER_BYPASS_SECTION();
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
#if 0
retval = spif_erase_sector(addr);
#else
AP_SPIF->fcmd = 0x6000001;
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
AP_SPIF->fcmd_addr = addr;
spif_cmd(0x20,3,0,0,0,0);
#endif
SPIF_STATUS_WAIT_IDLE(SPIF_WAIT_IDLE_CYC);
spif_wait_nobusy(SFLG_WELWIP, SPIF_TIMEOUT, PPlus_ERR_BUSY);
HAL_CACHE_EXIT_BYPASS_SECTION();
@ -431,7 +430,7 @@ CHIP_ID_STATUS_e read_chip_mAddr(uint8_t * mAddr) {
uint8_t b;
for (int i = 0; i < CHIP_MADDR_LEN; i++) {
ret = chip_id_one_bit_hot_convter(&b,
read_reg(CHIP_MADDR_FLASH_ADDRESS+(i<<2)));
read_reg(CHIP_MADDR_FLASH_ADDRESS + (i << 2)));
if (ret == CHIP_ID_VALID) {
mAddr[CHIP_MADDR_LEN - 1 - i] = b;

View file

@ -124,11 +124,12 @@ extern void spif_rddata(uint8_t* data, uint8_t len);
extern int spif_config(sysclk_t ref_clk, uint8_t div, uint32_t rd_instr, uint8_t mode_bit, uint8_t QE);
int hal_spif_cache_init(sysclk_t spif_ref_clk, uint32_t rd_instr);
//static void hal_cache_tag_flush(void);
#if(FLASH_PROTECT_FEATURE == 1)
//#if(FLASH_PROTECT_FEATURE == 1)
int hal_flash_wr_status(uint8_t status);
int hal_flash_lock(void);
int hal_flash_unlock(void);
uint8_t hal_flash_get_lock_state(void);
#endif
//#endif
int hal_flash_write(uint32_t addr, uint8_t* data, uint32_t size);
int hal_flash_write_by_dma(uint32_t addr, uint8_t* data, uint32_t size);
int hal_flash_read(uint32_t addr, uint8_t* data, uint32_t size);
@ -138,9 +139,9 @@ int flash_write_word(unsigned int offset, uint32_t value);
CHIP_ID_STATUS_e chip_id_one_bit_hot_convter(uint8_t* b,uint32_t w);
void LL_PLUS_LoadMACFromFlash(uint32_t addr);
//void LL_PLUS_LoadMACFromFlash(uint32_t addr);
CHIP_ID_STATUS_e LL_PLUS_LoadMACFromChipMAddr(void);
//CHIP_ID_STATUS_e LL_PLUS_LoadMACFromChipMAddr(void);
CHIP_ID_STATUS_e read_chip_mAddr(uint8_t * mAddr);
int hal_get_flash_info(void);

View file

@ -5602,8 +5602,8 @@ void config_RTC1(uint32 time)
sleep_tick = AP_AON->RTCCNT; // *(volatile uint32_t*) 0x4000f028; read current RTC counter
#endif
g_TIM2_IRQ_to_Sleep_DeltTick = (g_TIM2_IRQ_TIM3_CurrCount>(AP_TIM3->CurrentCount))
? (g_TIM2_IRQ_TIM3_CurrCount-(AP_TIM3->CurrentCount)): 0;
g_TIM2_IRQ_to_Sleep_DeltTick = (g_TIM2_IRQ_TIM3_CurrCount > (AP_TIM3->CurrentCount))
? (g_TIM2_IRQ_TIM3_CurrCount - (AP_TIM3->CurrentCount)) : 0;
AP_AON->RTCCC0 = sleep_tick + time; //set RTC comparatr0 value
// *(volatile uint32_t *) 0x4000f024 |= 1 << 20; //enable comparator0 envent
// *(volatile uint32_t *) 0x4000f024 |= 1 << 18; //counter overflow interrupt
@ -5751,18 +5751,9 @@ void wakeupProcess1(void)
// sleep_total = ((((dlt_tick &0xffff0000)>>16)*counter_tracking)<<9)
// + (((dlt_tick &0xffff)*counter_tracking)>>7);
//counter_tracking default 16 cycle
#if TEST_RTC_DELTA
// надо перевести в systick 625us
// dlt_tick - в 1/32768
// counter_tracking - в 16/32768
// sleep_total = ;
//counter_tracking = STD_RC32_8_CYCLE_16MHZ_CYCLE;
// TEST_RTC_DELTA
sleep_total = ((((dlt_tick &0xffff0000)>>16)*counter_tracking)<<8)
+ (((dlt_tick &0xffff)*counter_tracking)>>8);
#else
sleep_total = ((((dlt_tick &0xffff0000)>>16)*counter_tracking)<<8)
+ (((dlt_tick &0xffff)*counter_tracking)>>8);
#endif
}
else
{
@ -8301,37 +8292,33 @@ hciStatus_t HCI_LE_ConnUpdateCmd( uint16 connHandle,
}
__ATTR_SECTION_XIP__
CHIP_ID_STATUS_e chip_id_one_bit_hot_convter(uint8_t* b,uint32_t w)
CHIP_ID_STATUS_e chip_id_one_bit_hot_convter(uint8_t* b, uint32_t w)
{
uint16 dh = w>>16;
uint16 dl = w&0xffff;
uint16 h1,h0,l1,l0;
h0=l0=0xff;
h1=l1=0;
uint16 dh = w >> 16;
uint16 dl = w & 0xffff;
uint16 h1, h0, l1, l0;
h0 = l0 = 0xff;
h1 = l1 = 0;
for(int i=0; i<16; i++)
for(int i = 0; i < 16; i++)
{
l1+=((dl&(1<<i))>>i);
l1 += ((dl & (1 << i)) >> i);
if(l0==0xff && l1==1)
{
l0=i;
}
if(l0 == 0xff && l1 == 1)
l0 = i;
h1+=((dh&(1<<i))>>i);
h1 += ((dh & (1 << i)) >> i);
if(h0==0xff && h1==1)
{
h0=i;
}
if(h0 == 0xff && h1 == 1)
h0 = i;
}
if(l1==1 && h1==1)
if(l1 == 1 && h1 == 1)
{
*b=((h0<<4)+l0);
*b = ((h0 << 4) + l0);
return CHIP_ID_VALID;
}
else if(l1==16 && h1==16)
else if(l1 == 16 && h1 == 16)
{
return CHIP_ID_EMPTY;
}
@ -8356,6 +8343,7 @@ CHIP_ID_STATUS_e chip_id_one_bit_hot_convter(uint8_t* b,uint32_t w)
@return None.
*/
/*
void LL_PLUS_LoadMACFromFlash(uint32_t addr)
{
volatile uint8_t* p_ownPublicAddr = (volatile uint8_t*)0x1fff0965;
@ -8369,7 +8357,7 @@ void LL_PLUS_LoadMACFromFlash(uint32_t addr)
*(p_ownPublicAddr++) = BREAK_UINT32(macAddr[1],1);
*(p_ownPublicAddr++) = BREAK_UINT32(macAddr[1],0);
}
*/
/*******************************************************************************
@fn pplus_LoadMACFromChipMAddr

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -7,39 +7,59 @@
@make -s -j PROJECT_NAME=THB2%SWVER% POJECT_DEF="-DDEVICE=DEVICE_THB2"
@if not exist "build\THB2%SWVER%.hex" goto :error
@copy "build\THB2%SWVER%.bin" .\bin
@
@del /Q "build\BTH01%SWVER%.hex"
@del /Q "build\BTH01%SWVER%.bin"
@make -s clean
@make -s -j PROJECT_NAME=BTH01%SWVER% POJECT_DEF="-DDEVICE=DEVICE_BTH01"
@if not exist "build\BTH01%SWVER%.hex" goto :error
@copy "build\BTH01%SWVER%.bin" .\bin
@
@del /Q "build\TH05%SWVER%.hex"
@del /Q "build\TH05%SWVER%.bin"
@make -s clean
@make -s -j PROJECT_NAME=TH05%SWVER% POJECT_DEF="-DDEVICE=DEVICE_TH05"
@if not exist "build\TH05%SWVER%.hex" goto :error
@copy "build\TH05%SWVER%.bin" .\bin
@
@del /Q "build\TH05V13%SWVER%.hex"
@del /Q "build\TH05V13%SWVER%.bin"
@make -s clean
@make -s -j PROJECT_NAME=TH05V13%SWVER% POJECT_DEF="-DDEVICE=DEVICE_TH05V13"
@if not exist "build\TH05V13%SWVER%.hex" goto :error
@copy "build\TH05V13%SWVER%.bin" .\bin
@
@del /Q "build\THB1%SWVER%.hex"
@del /Q "build\THB1%SWVER%.bin"
@make -s clean
@make -s -j PROJECT_NAME=THB1%SWVER% POJECT_DEF="-DDEVICE=DEVICE_THB1"
@if not exist "build\THB1%SWVER%.hex" goto :error
@copy "build\THB1%SWVER%.bin" .\bin
@
@del /Q "build\BOOT_THB2%SWVER%.hex"
@make -s clean
@make -s -j PROJECT_NAME=BOOT_THB2%SWVER% BOOT_OTA=1 POJECT_DEF="-DDEVICE=DEVICE_THB2"
@if not exist "build\BOOT_THB2%SWVER%.hex" goto :error
@copy "build\BOOT_THB2%SWVER%.hex" .\bin
@
@del /Q "build\BOOT_BTH01%SWVER%.hex"
@make -s clean
@make -s -j PROJECT_NAME=BOOT_BTH01%SWVER% BOOT_OTA=1 POJECT_DEF="-DDEVICE=DEVICE_BTH01"
@if not exist "build\BOOT_BTH01%SWVER%.hex" goto :error
@copy "build\BOOT_BTH01%SWVER%.hex" .\bin
@
@del /Q "build\BOOT_TH05%SWVER%.hex"
@make -s clean
@make -s -j PROJECT_NAME=BOOT_TH05%SWVER% BOOT_OTA=1 POJECT_DEF="-DDEVICE=DEVICE_TH05"
@if not exist "build\BOOT_TH05%SWVER%.hex" goto :error
@copy "build\BOOT_TH05%SWVER%.hex" .\bin
@
@del /Q "build\BOOT_TH05V13%SWVER%.hex"
@make -s clean
@make -s -j PROJECT_NAME=BOOT_TH05V13%SWVER% BOOT_OTA=1 POJECT_DEF="-DDEVICE=DEVICE_TH05V13"
@if not exist "build\BOOT_TH05V13%SWVER%.hex" goto :error
@copy "build\BOOT_TH05V13%SWVER%.hex" .\bin
@
@del /Q "build\BOOT_THB1%SWVER%.hex"
@make -s clean
@make -s -j PROJECT_NAME=BOOT_THB1%SWVER% BOOT_OTA=1 POJECT_DEF="-DDEVICE=DEVICE_THB1"

View file

@ -43,6 +43,56 @@ const dev_id_t dev_id = {
.services = DEV_SERVICES
};
#if (OTA_TYPE == OTA_TYPE_BOOT)
#define FLASH_ADDR_RINFO FLASH_BASE_ADDR
#define OFFSET_ADDR_RMAC 0x900
#define FLASH_ADDR_RMAC (FLASH_BASE_ADDR + OFFSET_ADDR_RMAC)
static void write_fix_mac(uint32_t *pdata) {
uint32_t idx, tmp;
uint8_t buf_sector[FLASH_SECTOR_SIZE];
hal_flash_read(FLASH_ADDR_RINFO, buf_sector, FLASH_SECTOR_SIZE);
memcpy(&buf_sector[OFFSET_ADDR_RMAC], pdata, CHIP_MADDR_LEN*4);
tmp = phy_flash.Capacity;
phy_flash.Capacity |= FLASH_MAX_SIZE;
*(volatile int*) 0x1fff0898 = phy_flash.Capacity;
hal_flash_unlock();
hal_flash_erase_sector(FLASH_ADDR_RINFO + phy_flash.Capacity);
for(idx = 0; idx < FLASH_SECTOR_SIZE; idx += 256)
hal_flash_write(FLASH_ADDR_RINFO + phy_flash.Capacity + idx, &buf_sector[idx], 256);
phy_flash.Capacity = tmp;
*(volatile int*) 0x1fff0898 = phy_flash.Capacity;
}
void fix_mac(int write) {
int i;
uint32_t data[CHIP_MADDR_LEN];
if(write) {
if(read_chip_mAddr((uint8_t *)data) == CHIP_ID_VALID) {
if(memcmp(ownPublicAddr, data, CHIP_MADDR_LEN) == 0)
return;
}
for (i = 0; i < CHIP_MADDR_LEN; i++) {
data[CHIP_MADDR_LEN - 1 - i] = (1 << (((ownPublicAddr[i] & 0xf0) >> 4) + 16))
| (1 << (ownPublicAddr[i] & 0x0f));
}
write_fix_mac(data);
} else { // clear
hal_flash_read(FLASH_ADDR_RMAC, (uint8_t *)data, sizeof(data));
for(i = 0; i < CHIP_MADDR_LEN; i++) {
if(data[i] != 0xffffffff) {
memset(&data, 0xff, sizeof(data));
write_fix_mac(data);
break;
}
}
}
}
#endif
int cmd_parser(uint8_t * obuf, uint8_t * ibuf, uint32_t len) {
int olen = 0;
if (len) {
@ -139,9 +189,9 @@ int cmd_parser(uint8_t * obuf, uint8_t * ibuf, uint32_t len) {
memcpy(&obuf[1], (uint8_t *)&phy_flash.IdentificationID, 8);
olen = 1 + 8;
} else if (cmd == CMD_ID_MTU) {
if (ibuf[1] <= MTU_SIZE)
if (ibuf[1] <= MTU_SIZE) {
ATT_UpdateMtuSize(gapRole_ConnectionHandle, ibuf[1]);
else
} else
obuf[1] = 0xff;
olen = 2;
} else if (cmd == CMD_ID_REBOOT) {
@ -200,6 +250,11 @@ int cmd_parser(uint8_t * obuf, uint8_t * ibuf, uint32_t len) {
}
memcpy(&obuf[1], ownPublicAddr, MAC_LEN);
olen = MAC_LEN + 1;
#if (OTA_TYPE == OTA_TYPE_BOOT)
} else if (cmd == CMD_ID_FIX_MAC && len > 1) {
fix_mac(ibuf[1]);
olen = 2;
#endif
} else if (cmd == CMD_ID_DNAME) {
if (len > 1 && len < B_MAX_ADV_LEN - 2) {
if(ibuf[1] == 0)

View file

@ -27,7 +27,8 @@ typedef enum {
CMD_ID_SEN_ID = 0x05, // Get sensor ID
CMD_ID_FLASH_ID = 0x06, // Get Flash JEDEC ID
CMD_ID_SERIAL = 0x07, // Get serial string
CMD_ID_DEV_MAC = 0x10, // Get/Set MAC [+RandMAC], [size][mac[6][randmac[2]]]
CMD_ID_DEV_MAC = 0x10, // Get/Set MAC [+RandMAC], [size]<mac[6][randmac[2]]>
CMD_ID_FIX_MAC = 0x11, // Fixed MAC (не безопасная операция, переписывает сектор 0x1000 Flash)
CMD_ID_BKEY = 0x18, // Get/Set beacon bindkey in EEP
CMD_ID_COMFORT = 0x20, // Get/Set comfort parameters
CMD_ID_EXTDATA = 0x22, // Get/Set show ext. data

View file

@ -40,9 +40,10 @@
#define DEVICE_BTH01 20
#define DEVICE_TH05 21
#define DEVICE_THB1 23
#define DEVICE_TH05V13 24
#ifndef DEVICE
#define DEVICE DEVICE_THB1
#define DEVICE DEVICE_TH05V13
#endif
// supported services by the device (bits)
@ -199,7 +200,7 @@
#define DEF_MANUFACTURE_NAME_STR "Tuya"
#elif DEVICE == DEVICE_THB1
/* Model: THB1/BT1 */
/* Model: THB1 */
#if OTA_TYPE == OTA_TYPE_BOOT
#define DEV_SERVICES (OTA_TYPE \
| SERVICE_SCREEN \
@ -243,6 +244,51 @@
#define DEF_HARDWARE_REVISION "0017"
#define DEF_MANUFACTURE_NAME_STR "Tuya"
#elif DEVICE == DEVICE_TH05V13
/* Model: TH05 v1.2 */
#if OTA_TYPE == OTA_TYPE_BOOT
#define DEV_SERVICES (OTA_TYPE \
| SERVICE_SCREEN \
| SERVICE_THS \
| SERVICE_KEY \
)
#else
#define DEV_SERVICES (OTA_TYPE \
| SERVICE_SCREEN \
| SERVICE_THS \
| SERVICE_KEY \
| SERVICE_HISTORY \
| SERVICE_TH_TRG \
| SERVICE_RDS \
)
#endif
#if ((DEV_SERVICES & SERVICE_THS) == 0) && (DEV_SERVICES & SERVICE_TH_TRG)
#error "Not SERVICE_TH_TRG!"
#endif
#define ADC_PIN_USE_OUT 1 // нет подключения к +Vbat
#define ADC_PIN GPIO_P15
#define ADC_VBAT_CHL VBAT_ADC_P15
#define USE_TH_SENSOR 1
#define USE_SECREEN 1
#define I2C_SDA GPIO_P31 // SDA
#define I2C_SCL GPIO_P32 // SCL
#define I2C_LCD_SDA GPIO_P11 // SDA
#define I2C_LCD_SCL GPIO_P14 // SCL
#define GPIO_KEY GPIO_P02
#define GPIO_TRG GPIO_P09 // mark TX
#define GPIO_INP GPIO_P10 // mark RX
#define DEF_MODEL_NUMBER_STR "TH05"
#define DEF_HARDWARE_REVISION "0018"
#define DEF_MANUFACTURE_NAME_STR "Tuya"
#else
#error "DEVICE Not released!"
#endif

View file

@ -2,14 +2,38 @@
* lcd_th05.h
*
* Created on: 23 янв. 2024 г.
* Author: pvvx
* Author: pvvx, Shestoperd
*/
#ifndef _LCD_TH05_H_
#define _LCD_TH05_H_
/*
* TH-05 LCD buffer: byte.bit
* TH-05 v1.3 LCD buffer: byte.bit
--7.7-- --6.7-- --4.3--
| | | | | | |
| 7.3 7.6 6.3 6.6 5.7 4.2
| | | | | | | o 5.3
-6.0- 7.0 --7.2-- --6.2-- --5.6-- +--- 5.3
| | | | | | | 5.3|
| 7.1 7.5 6.1 6.5 5.5 4.1 ---- 5.2
| | | | | | | 5.3|
--7.4-- --6.4-- * --4.0-- ---- 5.1
5.0
BLE --1.0-- --2.0-- |-------------4.6-------------|
0.4 | | | | 3.6 | 3.5 | 3.2 | 3.1 | 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--
----- | | | |
\___/ 1.6 1.2 2.6 2.2 %
0.3 | | | | 4.7
--1.3-- --2.3--
*/
/*
* TH-05 v1.4 LCD buffer: byte.bit
--0.4-- --1.4-- --2.4-- BAT
| | | | | | | 3.6
@ -62,6 +86,8 @@
#if (DEVICE == DEVICE_THB1)
#define LCD_BUF_SIZE 7
#elif (DEVICE == DEVICE_TH05V13)
#define LCD_BUF_SIZE 8
#else
#define LCD_BUF_SIZE 6
#endif

View file

@ -2,7 +2,7 @@
* lcd_th05.c
*
* Created on: 23 янв. 2024 г.
* Author: pvvx
* Author: pvvx, Shestoperd
*/
#include <string.h>
#include "types.h"

View file

@ -1,92 +0,0 @@
/*
* lcd_th05.h
*
* Created on: 23 янв. 2024 г.
* Author: pvvx
*/
#ifndef _LCD_TH05_H_
#define _LCD_TH05_H_
/*
* TH-05 LCD buffer: byte.bit
--0.4-- --1.4-- --2.4-- BAT
| | | | | | | 3.6
| 0.6 0.0 1.6 1.0 2.6 2.0
| | | | | | | o 3.5
0.3 --0.2-- --1.2-- --2.2-- +--- 3.5
| | | | | | | 3.5|
| 0.5 0.1 1.5 1.1 2.5 2.1 ---- 3.7
| | | | | | | 3.5|
--0.7-- --1.7-- * --2.7-- ---- 2.3
1.3
--4.4-- --5.4--
| | | |
3.0 3.0 4.6 4.0 5.6 5.0
/ \ / \ | | | |
3.4( \_/ 3.2 \_/ )3.4 --4.2-- --5.2--
3.2 / \ 3.2 | | | |
\_/ 4.5 4.1 5.5 5.1 %
3.0 | | | | 5.3
--4.7-- --5.7--
OO 4.3
None: 3.1, 3.3
*/
#define LCD_BUF_SIZE 6
extern uint8_t lcd_i2c_addr; // LCD controller I2C address
extern uint8_t display_buff[LCD_BUF_SIZE];
/* 0x0 = " "
* 0x1 = "°Г"
* 0x2 = " _"
* 0x3 = "°C"
* 0x4 = " -"
* 0x5 = "°F"
* 0x6 = " ="
* 0x7 = "°E" */
typedef enum {
LCD_TSYMBOL_NONE, // " "
LCD_TSYMBOL_C = 3, // "°C"
LCD_TSYMBOL_F = 5, // "°F"
LCD_TSYMBOL_EQ = 6, // " ="
LCD_TSYMBOL_E = 7 // "°E"
} LCD_TEMP_SYMBOLS;
/* 0 = " " off,
* 1 = " ^_^ " happy
* 2 = " -^- " sad
* 3 = " ooo "
* 4 = "( )"
* 5 = "(^_^)" happy
* 6 = "(-^-)" sad
* 7 = "(ooo)" */
typedef enum {
LD_SSYMBOL_OFF, // 0 = " " off,
LD_SSYMBOL__HAPPY, // 1 = " ^_^ " happy
LD_SSYMBOL__SAD, // 2 = " -^- " sad
LD_SSYMBOL_OOO, // 3 = " ooo "
LD_SSYMBOL_CC, // 4 = "( )"
LD_SSYMBOL_HAPPY, // 5 = "(^_^)" happy
LD_SSYMBOL_SAD, // 6 = "(-^-)" sad
LD_SSYMBOL_ALL, // 7 = "(ooo)"
} LCD_SMILEY_SYMBOLS;
void init_lcd(void);
void update_lcd(void);
void show_small_number(int16_t number, bool percent);
void show_big_number_x10(int16_t number);
void show_battery_symbol(bool state);
void show_ble_symbol(bool state);
void show_smiley(LCD_SMILEY_SYMBOLS symbol);
void show_temp_symbol(LCD_TEMP_SYMBOLS symbol);
//void chow_clock(void);
//void chow_measure(void);
void chow_lcd(int flg);
void lcd_show_version(void);
#endif /* _LCD_TH05_H_ */

View file

@ -0,0 +1,406 @@
/*
* lcd_th05.c
*
* Created on: 23 янв. 2024 г.
* Author: pvvx, Shestoperd
*/
#include <string.h>
#include "types.h"
#include "config.h"
#if (DEV_SERVICES & SERVICE_SCREEN) && (DEVICE == DEVICE_TH05V13)
#include "OSAL.h"
#include "gpio.h"
#include "rom_sym_def.h"
#include "dev_i2c.h"
#include "sensors.h"
#include "lcd.h"
#include "thb2_peripheral.h"
#define LCD_I2C_ADDR 0x3E
#define I2C_WAIT_ms 1
dev_i2c_t i2c_dev1 = {
//.pi2cdev = AP_I2C1,
.scl = I2C_LCD_SCL,
.sda = I2C_LCD_SDA,
.speed = I2C_100KHZ,
.i2c_num = 0
};
/* 0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F*/
const uint8_t display_numbers67[] = {
// 76543210
0b011111010, // 0
0b001100000, // 1
0b011010110, // 2
0b011110100, // 3
0b001101100, // 4
0b010111100, // 5
0b010111110, // 6
0b011100000, // 7
0b011111110, // 8
0b011111100, // 9
0b011101110, // A
0b000111110, // b
0b010011010, // C
0b001110110, // d
0b010011110, // E
0b010001110 // F
};
#define LCD_SYM67_b 0b000111110 // "b"
#define LCD_SYM67_H 0b001101110 // "H"
#define LCD_SYM67_h 0b001001110 // "h"
#define LCD_SYM67_i 0b000000010 // "i"
#define LCD_SYM67_L 0b000011010 // "L"
#define LCD_SYM67_o 0b000110110 // "o"
#define LCD_SYM67_t 0b000011110 // "t"
#define LCD_SYM67_0 0b011111010 // "0"
#define LCD_SYM67_A 0b011101110 // "A"
#define LCD_SYM67_a 0b010110110 // "a"
#define LCD_SYM67_P 0b011001110 // "P"
const uint8_t display_numbers45[] = {
// 76543210
0b010101111, // 0
0b000000110, // 1
0b001101101, // 2
0b001001111, // 3
0b011000110, // 4
0b011001011, // 5
0b011101011, // 6
0b000001110, // 7
0b011101111, // 8
0b011001111, // 9
0b011101110, // A
0b011000011, // b
0b010101001, // C
0b001100110, // d
0b011101001, // E
0b011101000 // F
};
#define LCD_SYM45_b 0b011100011 // "b"
#define LCD_SYM45_H 0b011100110 // "H"
#define LCD_SYM45_h 0b011100010 // "h"
#define LCD_SYM45_i 0b000100000 // "i"
#define LCD_SYM45_L 0b010100001 // "L"
#define LCD_SYM45_o 0b001100011 // "o"
#define LCD_SYM45_t 0b011100001 // "t"
#define LCD_SYM45_0 0b010101111 // "0"
#define LCD_SYM45_A 0b011101110 // "A"
#define LCD_SYM45_a 0b001101111 // "a"
#define LCD_SYM45_P 0b011101100 // "P"
const uint8_t display_numbers12[] = {
// 76543210
0b001011111, // 0
0b000000110, // 1
0b001101011, // 2
0b000101111, // 3
0b000110110, // 4
0b000111101, // 5
0b001111101, // 6
0b000000111, // 7
0b001111111, // 8
0b000111111, // 9
0b001110111, // A
0b001111100, // b
0b001011001, // C
0b001101110, // d
0b001111001, // E
0b001110001 // F
};
#define LCD_SYM12_b 0b001111100 // "b"
#define LCD_SYM12_H 0b001110110 // "H"
#define LCD_SYM12_h 0b001110100 // "h"
#define LCD_SYM12_i 0b001000000 // "i"
#define LCD_SYM12_L 0b001011000 // "L"
#define LCD_SYM12_o 0b001101100 // "o"
#define LCD_SYM12_t 0b001111000 // "t"
#define LCD_SYM12_0 0b001011111 // "0"
#define LCD_SYM12_A 0b001110111 // "A"
#define LCD_SYM12_a 0b001101101 // "a"
#define LCD_SYM12_P 0b001110011 // "P"
uint8_t lcd_i2c_addr; // = 0x3E
uint8_t display_buff[LCD_BUF_SIZE] = {
0, LCD_SYM12_o, LCD_SYM12_o, 0
};
uint8_t display_out_buff[LCD_BUF_SIZE+1];
const uint8_t lcd_init_cmd[] = {
// LCD controller initialize:
0xea, // Set IC Operation(ICSET): Software Reset, Internal oscillator circuit
0xd8, // Mode Set (MODE SET): Display enable, 1/3 Bias, power saving
0xbc, // Display control (DISCTL): Power save mode 3, FRAME flip, Power save mode 1
0x80, // load data pointer
0xf0, // blink control off, 0xf2 - blink
0xfc, // All pixel control (APCTL): Normal
0x60,
0x00,0x00,000,0x00,0x00,0x00,0x00,0x00,0x00
};
/* 0x0 = " "
* 0x1 = "°Г"
* 0x2 = " _"
* 0x3 = "°C"
* 0x4 = " -"
* 0x5 = "°F"
* 0x6 = " ="
* 0x7 = "°E" */
void show_temp_symbol(LCD_TEMP_SYMBOLS symbol) {
display_buff[5] &= ~(BIT(1) | BIT(2) | BIT(3));
if(symbol & 1)
display_buff[5] |= BIT(3);
if(symbol & 2)
display_buff[5] |= BIT(1);
if(symbol & 4)
display_buff[5] |= BIT(2);
}
/* 0 = " " off,
* 1 = " ^_^ " happy
* 2 = " -^- " sad
* 3 = " ooo "
* 4 = "( )"
* 5 = "(^_^)" happy
* 6 = "(-^-)" sad
* 7 = "(ooo)" */
void show_smiley(LCD_SMILEY_SYMBOLS symbol) {
display_buff[0] &= ~(BIT(0) | BIT(1) | BIT(2) | BIT(3));
if(symbol & 1)
display_buff[0] |= BIT(1) | BIT(3);
if(symbol & 2)
display_buff[0] |= BIT(1) | BIT(2);
if(symbol & 4)
display_buff[0] |= BIT(0);
}
void show_ble_symbol(bool state) {
if (state)
display_buff[0] |= BIT(4);
else
display_buff[0] &= ~BIT(4);
}
void show_battery(uint8_t level) {
display_buff[3] &= ~(BIT(1) | BIT(2) | BIT(5) | BIT(6));
display_buff[4] &= ~(BIT(5)); // | BIT(6));
display_buff[4] |= BIT(6);
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 > 36)
display_buff[3] |= BIT(5);
if(level > 20)
display_buff[3] |= BIT(6);
}
void show_big_number_x10(int16_t number) {
display_buff[5] &= BIT(1) | BIT(2) | BIT(3); // F/C "_"
display_buff[4] &= BIT(5) | BIT(6) | BIT(7); // bat, %
if (number > 19995) {
display_buff[7] = LCD_SYM67_H; // "H"
display_buff[6] = LCD_SYM67_i; // "i"
} else if (number < -995) {
display_buff[7] = LCD_SYM67_L; // "L"
display_buff[6] = LCD_SYM67_o; // "o"
} else {
display_buff[6] = 0;
display_buff[7] = 0;
/* number: -995..19995 */
if (number > 1995 || number < -1995) {
//display_buff[5] &= ~BIT(0); // no point, show: -1999..1999
if (number < 0) {
number = -number;
display_buff[6] = BIT(0); // "-"
}
number = (number + 5) / 10; // round(div 10)
} else { // show: -199.9..199.9
display_buff[5] |= BIT(0); // point,
if (number < 0){
number = -number;
display_buff[6] = BIT(2); // "-"
}
}
/* number: -1999..1999 */
if (number > 999) display_buff[7] = BIT(0); // "1" 1000..1999
if (number > 99) display_buff[7] |= display_numbers67[number / 100 % 10];
if (number > 9) display_buff[6] |= display_numbers67[number / 10 % 10];
else display_buff[6] |= LCD_SYM67_0; // "0"
display_buff[4] |= display_numbers45[number %10] & 0x0f;
display_buff[5] |= display_numbers45[number %10] & 0xe0;
}
}
/* -9 .. 99 */
void show_small_number(int16_t number, bool percent) {
if(percent)
display_buff[4] |= BIT(7);
else
display_buff[4] &= ~BIT(7);
if (number > 99) {
display_buff[1] |= LCD_SYM12_H; // "H"
display_buff[2] |= LCD_SYM12_i; // "i"
} else if (number < -9) {
display_buff[1] |= LCD_SYM12_L; // "L"
display_buff[2] |= LCD_SYM12_o; // "o"
} else {
if (number < 0) {
number = -number;
display_buff[1] = BIT(5); // "-"
}
if (number > 9) display_buff[1] = display_numbers12[number / 10 % 10];
display_buff[2] = display_numbers12[number %10];
}
}
void lcd_show_version(void) {
display_buff[0] &= BIT(4); // connect
display_buff[3] &= BIT(1) | BIT(2) | BIT(5) | BIT(6); // bat
display_buff[4] &= BIT(5) | BIT(6);
#if OTA_TYPE
display_buff[7] = LCD_SYM67_b;
display_buff[6] = LCD_SYM67_o;
display_buff[5] = LCD_SYM45_t & 0xe0;
display_buff[4] |= LCD_SYM45_t & 0x0f;
#else
display_buff[7] = LCD_SYM67_A;
display_buff[6] = LCD_SYM67_P;
display_buff[5] = LCD_SYM45_P & 0xe0;
display_buff[4] |= LCD_SYM45_P & 0x0f;
#endif
display_buff[1] = display_numbers12[(APP_VERSION>>4) & 0x0f];
display_buff[2] = display_numbers12[APP_VERSION & 0x0f];
update_lcd();
}
void chow_clock(void) {
uint32_t tmp = clkt.utc_time_sec / 60;
uint32_t min = tmp % 60;
uint32_t hrs = (tmp / 60) % 24;
display_buff[0] &= BIT(4); // connect
display_buff[3] &= BIT(1) | BIT(2) | BIT(5) | BIT(6); // bat
display_buff[4] &= BIT(5) | BIT(6);
display_buff[7] = display_numbers67[(hrs / 10) % 10];
display_buff[6] = display_numbers67[hrs % 10];
display_buff[5] = 0;
display_buff[1] = display_numbers12[(min / 10) % 10];
display_buff[2] = display_numbers12[min % 10];
update_lcd();
}
static void chow_measure(void) {
#if (DEV_SERVICES & SERVICE_THS)
show_big_number_x10(measured_data.temp/10);
show_small_number(measured_data.humi/100, true);
show_battery(measured_data.battery);
show_temp_symbol(LCD_TSYMBOL_C);
#if (OTA_TYPE == OTA_TYPE_APP)
if(cfg.flg & FLG_SHOW_SMILEY) {
#if (DEV_SERVICES & SERVICE_TH_TRG)
if(cfg.flg & FLG_SHOW_TRG) {
if(measured_data.flg.comfort) {
if(measured_data.flg.trg_on)
show_smiley(LD_SSYMBOL_HAPPY);
else
show_smiley(LD_SSYMBOL__HAPPY);
} else {
if(measured_data.flg.trg_on)
show_smiley(LD_SSYMBOL_SAD);
else
show_smiley(LD_SSYMBOL__SAD);
}
} else
#endif // SERVICE_TH_TRG
{
if(measured_data.flg.comfort)
show_smiley(LD_SSYMBOL_HAPPY);
else
show_smiley(LD_SSYMBOL_SAD);
}
#if (DEV_SERVICES & SERVICE_TH_TRG)
} else if(cfg.flg & FLG_SHOW_TRG) {
if(measured_data.flg.trg_on)
show_smiley(LD_SSYMBOL_ALL);
else
show_smiley(LD_SSYMBOL_OFF);
} else
#endif // SERVICE_TH_TRG
#endif // OTA_TYPE
show_smiley(LD_SSYMBOL_OFF);
#else
show_big_number_x10(measured_data.battery_mv/100);
show_small_number((measured_data.battery > 99)? 99 : measured_data.battery, true);
show_battery_symbol(1);
show_smiley(LD_SSYMBOL_OFF);
#endif // SERVICE_THS
show_ble_symbol(gapRole_state == GAPROLE_CONNECTED);
update_lcd();
}
/* flg != 0 -> chow_measure */
void chow_lcd(int flg) {
#if OTA_TYPE == OTA_TYPE_BOOT
if(flg)
chow_measure();
#else
if(cfg.flg & FLG_SHOW_TIME) {
if(wrk.lcd_count++ & 1)
chow_clock();
else
chow_measure();
} else if(flg) {
chow_measure();
}
#endif
}
void send_to_lcd(uint8_t *pbuf, int len) {
if (lcd_i2c_addr) {
init_i2c(&i2c_dev1);
send_i2c_buf(&i2c_dev1, lcd_i2c_addr, pbuf, len);
deinit_i2c(&i2c_dev1);
}
}
void update_lcd(void) {
#if (OTA_TYPE == OTA_TYPE_APP)
if(lcd_i2c_addr == 0 || (cfg.flg & FLG_DISPLAY_OFF) != 0)
return;
#endif
if(memcmp(&display_out_buff[1], display_buff, sizeof(display_buff))) {
memcpy(&display_out_buff[1], display_buff, sizeof(display_buff));
send_to_lcd(display_out_buff, sizeof(display_out_buff));
}
}
void init_lcd(void) {
i2c_dev1.speed = I2C_100KHZ;
init_i2c(&i2c_dev1);
if(!send_i2c_buf(&i2c_dev1, LCD_I2C_ADDR, (uint8_t *) lcd_init_cmd, sizeof(lcd_init_cmd))) {
#if (OTA_TYPE == OTA_TYPE_APP)
if(cfg.flg & FLG_DISPLAY_OFF)
send_i2c_byte(&i2c_dev1, LCD_I2C_ADDR, 0xd0); // Mode Set (MODE SET): Display disable, 1/3 Bias, power saving
#endif
lcd_i2c_addr = LCD_I2C_ADDR;
} else
lcd_i2c_addr = 0;
deinit_i2c(&i2c_dev1);
i2c_dev1.speed = I2C_400KHZ;
}
/****************************************************/
#endif // (DEV_SERVICES & SERVICE_SCREEN)

View file

@ -231,6 +231,34 @@ const ioinit_cfg_t ioInit[] = {
{ GPIO_P32, GPIO_PULL_DOWN },
{ GPIO_P33, GPIO_PULL_UP }, // I2C_SDA CNV1972
{ GPIO_P34, GPIO_PULL_UP } // I2C_SCL CNV1972
#elif (DEVICE == DEVICE_TH05V13)
{ 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_P07, GPIO_PULL_UP }, // CHT8305 Alert
#ifdef GPIO_TRG
{ GPIO_P09, GPIO_FLOATING }, // TX - GPIO_TRG
#else
{ GPIO_P09, GPIO_PULL_UP }, // TX
#endif
{ 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_P16, GPIO_PULL_DOWN },
{ GPIO_P17, GPIO_PULL_DOWN },
{ GPIO_P18, GPIO_FLOATING }, // I2C_SDA CHT8310
{ GPIO_P20, GPIO_FLOATING }, // ADC Vbat с делителем! Не используется - Выкусить резистор R18!
{ GPIO_P23, GPIO_PULL_DOWN },
{ GPIO_P24, GPIO_PULL_DOWN },
{ GPIO_P25, GPIO_PULL_DOWN },
{ GPIO_P26, GPIO_PULL_DOWN },
{ GPIO_P27, GPIO_PULL_DOWN },
{ GPIO_P31, GPIO_FLOATING }, // CHT8305 SDA
{ GPIO_P32, GPIO_FLOATING }, // CHT8305 SCL
{ GPIO_P33, GPIO_PULL_DOWN },
{ GPIO_P34, GPIO_PULL_DOWN }
#else
#error "DEVICE Not released!"
#endif