add test history (logger)
This commit is contained in:
parent
ce58642ba0
commit
ff022754a2
36 changed files with 10214 additions and 318 deletions
1
bthome_phy6222/.gitignore
vendored
1
bthome_phy6222/.gitignore
vendored
|
|
@ -1,4 +1,3 @@
|
||||||
bin
|
|
||||||
Listings
|
Listings
|
||||||
Objects
|
Objects
|
||||||
TestTHB2.asm
|
TestTHB2.asm
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,11 @@
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.python.pydev.PyDevBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||||
<triggers>clean,full,incremental,</triggers>
|
<triggers>clean,full,incremental,</triggers>
|
||||||
|
|
@ -24,5 +29,6 @@
|
||||||
<nature>org.eclipse.cdt.autotools.core.autotoolsNatureV2</nature>
|
<nature>org.eclipse.cdt.autotools.core.autotoolsNatureV2</nature>
|
||||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||||
|
<nature>org.python.pydev.pythonNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="20603724518044815" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="177609020486394017" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,16 @@ SRC_PRJ += peripheral_main.c
|
||||||
SRC_PRJ += sbp_profile.c
|
SRC_PRJ += sbp_profile.c
|
||||||
SRC_PRJ += devinfoservice.c
|
SRC_PRJ += devinfoservice.c
|
||||||
SRC_PRJ += sensors.c
|
SRC_PRJ += sensors.c
|
||||||
|
SRC_PRJ += dev_i2c.c
|
||||||
SRC_PRJ += config.c
|
SRC_PRJ += config.c
|
||||||
SRC_PRJ += cmd_parcer.c
|
SRC_PRJ += cmd_parser.c
|
||||||
SRC_PRJ += thb2_main.c
|
SRC_PRJ += thb2_main.c
|
||||||
SRC_PRJ += thb2_peripheral.c
|
SRC_PRJ += thb2_peripheral.c
|
||||||
SRC_PRJ += thservice.c
|
SRC_PRJ += thservice.c
|
||||||
SRC_PRJ += flash_eep.c
|
SRC_PRJ += flash_eep.c
|
||||||
SRC_PRJ += lcd_th05.c
|
SRC_PRJ += lcd_th05.c
|
||||||
SRC_PRJ += ble_ota.c
|
SRC_PRJ += ble_ota.c
|
||||||
|
SRC_PRJ += logger.c
|
||||||
|
|
||||||
INCLUDES = -I$(SRC_PATH)
|
INCLUDES = -I$(SRC_PATH)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,15 @@ typedef struct
|
||||||
gattAttribute_t* attrs;
|
gattAttribute_t* attrs;
|
||||||
} gattService_t;
|
} gattService_t;
|
||||||
|
|
||||||
|
// Structure to keep Attribute Server info
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// Info maintained for Handle Value Confirmation message
|
||||||
|
uint16 connHandle; // connection message was sent on
|
||||||
|
uint8 timerId; // confirmation timeout timer id
|
||||||
|
uint8 taskId; // task to be notified of confirmation
|
||||||
|
} gattServerInfo_t;
|
||||||
|
bStatus_t gattGetServerStatus( uint16 connHandle, gattServerInfo_t** p2pServer );
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
VARIABLES
|
VARIABLES
|
||||||
*/
|
*/
|
||||||
|
|
@ -785,7 +794,7 @@ extern bStatus_t GATT_DiscCharsByUUID( uint16 connHandle, attReadByTypeReq_t* pR
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief This sub-procedure is used by a client to find all the
|
@brief This sub-procedure is used by a client to find all the
|
||||||
characteristic descriptor’s Attribute Handles and Attribute
|
characteristic descriptor<EFBFBD>s Attribute Handles and Attribute
|
||||||
Types within a characteristic definition when only the
|
Types within a characteristic definition when only the
|
||||||
characteristic handle range is known. The characteristic
|
characteristic handle range is known. The characteristic
|
||||||
specified is identified by the characteristic handle range.
|
specified is identified by the characteristic handle range.
|
||||||
|
|
@ -1149,7 +1158,7 @@ extern bStatus_t GATT_ReliableWrites( uint16 connHandle, attPrepareWriteReq_t* p
|
||||||
/**
|
/**
|
||||||
@brief This sub-procedure is used to read a characteristic descriptor
|
@brief This sub-procedure is used to read a characteristic descriptor
|
||||||
from a server when the client knows the characteristic descriptor
|
from a server when the client knows the characteristic descriptor
|
||||||
declaration’s Attribute handle.
|
declaration<EFBFBD>s Attribute handle.
|
||||||
|
|
||||||
The ATT Read Request is used for this sub-procedure. The Read
|
The ATT Read Request is used for this sub-procedure. The Read
|
||||||
Request is used with the Attribute Handle parameter set to the
|
Request is used with the Attribute Handle parameter set to the
|
||||||
|
|
@ -1182,7 +1191,7 @@ extern bStatus_t GATT_ReadCharDesc( uint16 connHandle, attReadReq_t* pReq, uint8
|
||||||
/**
|
/**
|
||||||
@brief This sub-procedure is used to read a characteristic descriptor
|
@brief This sub-procedure is used to read a characteristic descriptor
|
||||||
from a server when the client knows the characteristic descriptor
|
from a server when the client knows the characteristic descriptor
|
||||||
declaration’s Attribute handle and the length of the characteristic
|
declaration<EFBFBD>s Attribute handle and the length of the characteristic
|
||||||
descriptor declaration is longer than can be sent in a single Read
|
descriptor declaration is longer than can be sent in a single Read
|
||||||
Response attribute protocol message.
|
Response attribute protocol message.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
//define flash ucds
|
//define flash ucds
|
||||||
#define FLASH_BASE_ADDR (0x11000000)
|
#define FLASH_BASE_ADDR (0x11000000)
|
||||||
#define FLASH_UCDS_ADDR_BASE 0x11005000
|
//#define FLASH_UCDS_ADDR_BASE 0x11005000
|
||||||
|
|
||||||
#define CHIP_ID_LENGTH 64
|
#define CHIP_ID_LENGTH 64
|
||||||
#define CHIP_ID_PID_LEN 16
|
#define CHIP_ID_PID_LEN 16
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,6 @@ typedef struct _attAttrList
|
||||||
gattService_t service; // service record
|
gattService_t service; // service record
|
||||||
} gattServiceList_t;
|
} gattServiceList_t;
|
||||||
|
|
||||||
// Structure to keep Attribute Server info
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
// Info maintained for Handle Value Confirmation message
|
|
||||||
uint16 connHandle; // connection message was sent on
|
|
||||||
uint8 timerId; // confirmation timeout timer id
|
|
||||||
uint8 taskId; // task to be notified of confirmation
|
|
||||||
} gattServerInfo_t;
|
|
||||||
|
|
||||||
// Structure to keep the Parse and Process function pointers for Requests
|
// Structure to keep the Parse and Process function pointers for Requests
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
@ -100,7 +92,7 @@ static bStatus_t gattProcessWriteReq( uint16 connHandle, attMsg_t* pMsg );
|
||||||
static bStatus_t gattProcessExecuteWriteReq( uint16 connHandle, attMsg_t* pMsg );
|
static bStatus_t gattProcessExecuteWriteReq( uint16 connHandle, attMsg_t* pMsg );
|
||||||
|
|
||||||
static void gattStoreServerInfo( gattServerInfo_t* pServer, uint8 taskId );
|
static void gattStoreServerInfo( gattServerInfo_t* pServer, uint8 taskId );
|
||||||
static bStatus_t gattGetServerStatus( uint16 connHandle, gattServerInfo_t** p2pServer );
|
//static bStatus_t gattGetServerStatus( uint16 connHandle, gattServerInfo_t** p2pServer );
|
||||||
static gattServerInfo_t* gattFindServerInfo( uint16 connHandle );
|
static gattServerInfo_t* gattFindServerInfo( uint16 connHandle );
|
||||||
static void gattResetServerInfo( gattServerInfo_t* pServer );
|
static void gattResetServerInfo( gattServerInfo_t* pServer );
|
||||||
static void gattServerStartTimer( uint8* pData, uint16 timeout, uint8* pTimerId );
|
static void gattServerStartTimer( uint8* pData, uint16 timeout, uint8* pTimerId );
|
||||||
|
|
@ -1324,7 +1316,7 @@ static bStatus_t gattProcessExecuteWriteReq( uint16 connHandle, attMsg_t* pMsg )
|
||||||
blePending: Confirmation pending
|
blePending: Confirmation pending
|
||||||
bleTimeout: Previous transaction timed out
|
bleTimeout: Previous transaction timed out
|
||||||
*/
|
*/
|
||||||
static bStatus_t gattGetServerStatus( uint16 connHandle, gattServerInfo_t** p2pServer )
|
bStatus_t gattGetServerStatus( uint16 connHandle, gattServerInfo_t** p2pServer )
|
||||||
{
|
{
|
||||||
gattServerInfo_t* pServer;
|
gattServerInfo_t* pServer;
|
||||||
pServer = gattFindServerInfo( connHandle );
|
pServer = gattFindServerInfo( connHandle );
|
||||||
|
|
|
||||||
3002
bthome_phy6222/bin/BOOT_BTH01_v07.hex
Normal file
3002
bthome_phy6222/bin/BOOT_BTH01_v07.hex
Normal file
File diff suppressed because it is too large
Load diff
3056
bthome_phy6222/bin/BOOT_TH05_v07.hex
Normal file
3056
bthome_phy6222/bin/BOOT_TH05_v07.hex
Normal file
File diff suppressed because it is too large
Load diff
2999
bthome_phy6222/bin/BOOT_THB2_v07.hex
Normal file
2999
bthome_phy6222/bin/BOOT_THB2_v07.hex
Normal file
File diff suppressed because it is too large
Load diff
BIN
bthome_phy6222/bin/BTH01_v07.bin
Normal file
BIN
bthome_phy6222/bin/BTH01_v07.bin
Normal file
Binary file not shown.
BIN
bthome_phy6222/bin/TH05_v07.bin
Normal file
BIN
bthome_phy6222/bin/TH05_v07.bin
Normal file
Binary file not shown.
BIN
bthome_phy6222/bin/THB2_v07.bin
Normal file
BIN
bthome_phy6222/bin/THB2_v07.bin
Normal file
Binary file not shown.
|
|
@ -64,6 +64,9 @@ void __attribute__((used)) hal_ADC_IRQHandler(void) {
|
||||||
measured_data.battery = 0;
|
measured_data.battery = 0;
|
||||||
else
|
else
|
||||||
measured_data.battery = 100;
|
measured_data.battery = 100;
|
||||||
|
#if ((DEV_SERVICES & SERVICE_THS) == 0)
|
||||||
|
measured_data.count++;
|
||||||
|
#endif
|
||||||
extern uint8 gapRole_AdvEnabled;
|
extern uint8 gapRole_AdvEnabled;
|
||||||
if (!gapRole_AdvEnabled)
|
if (!gapRole_AdvEnabled)
|
||||||
osal_set_event(simpleBLEPeripheral_TaskID, BATT_VALUE_EVT);
|
osal_set_event(simpleBLEPeripheral_TaskID, BATT_VALUE_EVT);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@
|
||||||
#ifndef BLE_OTA_H_
|
#ifndef BLE_OTA_H_
|
||||||
#define BLE_OTA_H_
|
#define BLE_OTA_H_
|
||||||
|
|
||||||
#if OTA_TYPE
|
|
||||||
/* FLASH */
|
/* FLASH */
|
||||||
|
|
||||||
#ifndef FLASH_SIZE
|
#ifndef FLASH_SIZE
|
||||||
#define FLASH_SIZE 0x80000 // 512k (512*1024)
|
#define FLASH_SIZE 0x80000 // 512k (512*1024)
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -16,12 +14,12 @@
|
||||||
#ifndef FLASH_SECTOR_SIZE
|
#ifndef FLASH_SECTOR_SIZE
|
||||||
#define FLASH_SECTOR_SIZE 0x01000 // 4k (4*1024)
|
#define FLASH_SECTOR_SIZE 0x01000 // 4k (4*1024)
|
||||||
#endif
|
#endif
|
||||||
#define FADDR_START_ADDR 0x11000000
|
#define FADDR_START_ADDR FLASH_BASE_ADDR
|
||||||
#define FADDR_BOOT_ROM_INFO (FADDR_START_ADDR + 0x02000) // 4k
|
#define FADDR_BOOT_ROM_INFO (FADDR_START_ADDR + 0x02000) // 4k
|
||||||
#define FADDR_OTA_SEC (FADDR_START_ADDR + 0x03000) // 52k
|
#define FADDR_OTA_SEC (FADDR_START_ADDR + 0x03000) // 52k
|
||||||
#define FADDR_APP_SEC (FADDR_START_ADDR + 0x10000) // 176k+
|
#define FADDR_APP_SEC (FADDR_START_ADDR + 0x10000) // 176k (for 256k Flash)
|
||||||
//#define FADDR_DATA_SEC (FADDR_START_ADDR + 0x40000)
|
|
||||||
#define FADDR_EEP_SEC (FADDR_START_ADDR + (FLASH_SIZE - 4*FLASH_SECTOR_SIZE))
|
#if OTA_TYPE
|
||||||
|
|
||||||
#define START_UP_FLAG 0x36594850 // "PHY6"
|
#define START_UP_FLAG 0x36594850 // "PHY6"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ extern "C"
|
||||||
#define TIMER_BATT_EVT 0x0008 // for battery detect
|
#define TIMER_BATT_EVT 0x0008 // for battery detect
|
||||||
#define BATT_VALUE_EVT 0x0010 // Event for battery voltage value update
|
#define BATT_VALUE_EVT 0x0010 // Event for battery voltage value update
|
||||||
#define ADV_BROADCAST_EVT 0x0020 // Advent. Event Done Notice
|
#define ADV_BROADCAST_EVT 0x0020 // Advent. Event Done Notice
|
||||||
//#define SBP_OTADATA 0x0040 // receive OTA data
|
#define WRK_NOTIFY_EVT 0x0040 // work notify
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
#include "rom_sym_def.h"
|
#include "rom_sym_def.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "config.h"
|
||||||
#include "bcomdef.h"
|
#include "bcomdef.h"
|
||||||
#include "gapbondmgr.h"
|
#include "gapbondmgr.h"
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
|
|
@ -13,8 +14,12 @@
|
||||||
|
|
||||||
//adv_buf_t adv_buf;
|
//adv_buf_t adv_buf;
|
||||||
|
|
||||||
void bthome_data_beacon(padv_bthome_ns1_t p) {
|
void bthome_data_beacon(void * padbuf) {
|
||||||
// padv_bthome_ns1_t p = (padv_bthome_ns1_t)&adv_buf.data;
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
|
padv_bthome_ns1_t p = (padv_bthome_ns1_t)padbuf;
|
||||||
|
#else
|
||||||
|
padv_bthome_ns2_t p = (padv_bthome_ns2_t)padbuf;
|
||||||
|
#endif
|
||||||
p->flag[0] = 0x02; // size
|
p->flag[0] = 0x02; // size
|
||||||
p->flag[1] = GAP_ADTYPE_FLAGS; // type
|
p->flag[1] = GAP_ADTYPE_FLAGS; // type
|
||||||
/* Flags:
|
/* Flags:
|
||||||
|
|
@ -33,10 +38,12 @@ void bthome_data_beacon(padv_bthome_ns1_t p) {
|
||||||
p->pid = (uint8)measured_data.count;
|
p->pid = (uint8)measured_data.count;
|
||||||
p->data.b_id = BtHomeID_battery;
|
p->data.b_id = BtHomeID_battery;
|
||||||
p->data.battery_level = measured_data.battery;
|
p->data.battery_level = measured_data.battery;
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
p->data.t_id = BtHomeID_temperature;
|
p->data.t_id = BtHomeID_temperature;
|
||||||
p->data.temperature = measured_data.temp; // x0.01 C
|
p->data.temperature = measured_data.temp; // x0.01 C
|
||||||
p->data.h_id = BtHomeID_humidity;
|
p->data.h_id = BtHomeID_humidity;
|
||||||
p->data.humidity = measured_data.humi; // x0.01 %
|
p->data.humidity = measured_data.humi; // x0.01 %
|
||||||
|
#endif
|
||||||
p->data.v_id = BtHomeID_voltage;
|
p->data.v_id = BtHomeID_voltage;
|
||||||
p->data.battery_mv = measured_data.battery_mv; // x mV
|
p->data.battery_mv = measured_data.battery_mv; // x mV
|
||||||
p->head.size = sizeof(adv_bthome_ns1_t) - sizeof(p->head.size) - sizeof(p->flag);
|
p->head.size = sizeof(adv_bthome_ns1_t) - sizeof(p->head.size) - sizeof(p->flag);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#ifndef BTHOME_BEACON_H_
|
#ifndef BTHOME_BEACON_H_
|
||||||
#define BTHOME_BEACON_H_
|
#define BTHOME_BEACON_H_
|
||||||
|
|
||||||
//#include "stack/ble/ble_8258/ble_common.h"
|
#include "config.h"
|
||||||
|
|
||||||
#define ADV_BTHOME_UUID16 0xFCD2 // 16-bit UUID Service 0xFCD2 BTHOME
|
#define ADV_BTHOME_UUID16 0xFCD2 // 16-bit UUID Service 0xFCD2 BTHOME
|
||||||
|
|
||||||
|
|
@ -117,17 +117,24 @@ typedef struct __attribute__((packed)) _adv_bthome_data1_t {
|
||||||
uint8 t_id; // = BtHomeID_temperature
|
uint8 t_id; // = BtHomeID_temperature
|
||||||
int16 temperature; // x 0.01 degree
|
int16 temperature; // x 0.01 degree
|
||||||
uint8 h_id; // = BtHomeID_humidity
|
uint8 h_id; // = BtHomeID_humidity
|
||||||
uint16 humidity; // x 0.01 %
|
uint16 humidity; // x 0.01 %
|
||||||
uint8 v_id; // = BtHomeID_voltage
|
uint8 v_id; // = BtHomeID_voltage
|
||||||
uint16 battery_mv; // x 0.001 V
|
uint16 battery_mv; // x 0.001 V
|
||||||
} adv_bthome_data1_t, * padv_bthome_data1_t;
|
} adv_bthome_data1_t, * padv_bthome_data1_t;
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed)) _adv_bthome_data2_t {
|
||||||
|
uint8 b_id; // = BtHomeID_battery
|
||||||
|
uint8 battery_level; // 0..100 %
|
||||||
|
uint8 v_id; // = BtHomeID_voltage
|
||||||
|
uint16 battery_mv; // x 0.001 V
|
||||||
|
} adv_bthome_data2_t, * padv_bthome_data2_t;
|
||||||
|
|
||||||
|
|
||||||
#define ADV_BUFFER_SIZE (31-3)
|
#define ADV_BUFFER_SIZE (31-3)
|
||||||
|
|
||||||
// BTHOME data1, no security
|
// BTHOME data1, no security
|
||||||
typedef struct __attribute__((packed)) _adv_bthome_ns1_t {
|
typedef struct __attribute__((packed)) _adv_bthome_ns1_t {
|
||||||
uint8 flag[3]; // Advertise type flags
|
uint8 flag[3]; // Advertise type flags
|
||||||
adv_head_bth_t head;
|
adv_head_bth_t head;
|
||||||
uint8 info; // = 0x40 BtHomeID_Info
|
uint8 info; // = 0x40 BtHomeID_Info
|
||||||
uint8 p_id; // = BtHomeID_PacketId
|
uint8 p_id; // = BtHomeID_PacketId
|
||||||
|
|
@ -135,15 +142,25 @@ typedef struct __attribute__((packed)) _adv_bthome_ns1_t {
|
||||||
adv_bthome_data1_t data;
|
adv_bthome_data1_t data;
|
||||||
} adv_bthome_ns1_t, * padv_bthome_ns1_t;
|
} adv_bthome_ns1_t, * padv_bthome_ns1_t;
|
||||||
|
|
||||||
|
// BTHOME data2, no security
|
||||||
|
typedef struct __attribute__((packed)) _adv_bthome_ns2_t {
|
||||||
|
uint8 flag[3]; // Advertise type flags
|
||||||
|
adv_head_bth_t head;
|
||||||
|
uint8 info; // = 0x40 BtHomeID_Info
|
||||||
|
uint8 p_id; // = BtHomeID_PacketId
|
||||||
|
uint8 pid; // PacketId (measurement count)
|
||||||
|
adv_bthome_data2_t data;
|
||||||
|
} adv_bthome_ns2_t, * padv_bthome_ns2_t;
|
||||||
|
|
||||||
typedef struct _adv_buf_t {
|
typedef struct _adv_buf_t {
|
||||||
uint32 send_count; // count & id advertise, = beacon_nonce.cnt32
|
uint32 send_count; // count & id advertise, = beacon_nonce.cnt32
|
||||||
// uint16 old_measured_count; // old measured_data.count
|
// uint16 old_measured_count; // old measured_data.count
|
||||||
// uint16 adv_restore_count;
|
// uint16 adv_restore_count;
|
||||||
adv_bthome_ns1_t data;
|
adv_bthome_ns1_t data;
|
||||||
} adv_buf_t;
|
} adv_buf_t;
|
||||||
|
|
||||||
//void bls_set_advertise_prepare(void *p);
|
//void bls_set_advertise_prepare(void *p);
|
||||||
//int app_advertise_prepare_handler(rf_packet_adv_t * p);
|
//int app_advertise_prepare_handler(rf_packet_adv_t * p);
|
||||||
void bthome_data_beacon(padv_bthome_ns1_t p);
|
void bthome_data_beacon(void * padbuf);
|
||||||
|
|
||||||
#endif /* BTHOME_BEACON_H_ */
|
#endif /* BTHOME_BEACON_H_ */
|
||||||
|
|
|
||||||
218
bthome_phy6222/source/cmd_parser.c
Normal file
218
bthome_phy6222/source/cmd_parser.c
Normal file
|
|
@ -0,0 +1,218 @@
|
||||||
|
/*
|
||||||
|
* cmd_parser.c
|
||||||
|
*
|
||||||
|
* Created on: 16 01 2024
|
||||||
|
* Author: pvvx
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*/
|
||||||
|
#include "bcomdef.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "OSAL.h"
|
||||||
|
#include "linkdb.h"
|
||||||
|
#include "att.h"
|
||||||
|
#include "gatt.h"
|
||||||
|
#include "gatt_uuid.h"
|
||||||
|
#include "gattservapp.h"
|
||||||
|
#include "gapbondmgr.h"
|
||||||
|
#include "flash.h"
|
||||||
|
#include "flash_eep.h"
|
||||||
|
#include "bleperipheral.h"
|
||||||
|
#include "sbp_profile.h"
|
||||||
|
#include "sensor.h"
|
||||||
|
#include "cmd_parser.h"
|
||||||
|
#include "devinfoservice.h"
|
||||||
|
#include "ble_ota.h"
|
||||||
|
#include "thb2_peripheral.h"
|
||||||
|
#include "lcd_th05.h"
|
||||||
|
#include "logger.h"
|
||||||
|
/*********************************************************************/
|
||||||
|
extern gapPeriConnectParams_t periConnParameters;
|
||||||
|
|
||||||
|
#define SEND_DATA_SIZE 16
|
||||||
|
|
||||||
|
const dev_id_t dev_id = {
|
||||||
|
.pid = CMD_ID_DEVID,
|
||||||
|
.revision = 1,
|
||||||
|
.hw_version = DEVICE,
|
||||||
|
.sw_version = APP_VERSION,
|
||||||
|
.dev_spec_data = 0,
|
||||||
|
.services = DEV_SERVICES
|
||||||
|
};
|
||||||
|
|
||||||
|
int cmd_parser(uint8_t * obuf, uint8_t * ibuf, uint32_t len) {
|
||||||
|
int olen = 0;
|
||||||
|
if (len) {
|
||||||
|
uint8_t cmd = ibuf[0];
|
||||||
|
obuf[0] = cmd;
|
||||||
|
obuf[1] = 0; // no err
|
||||||
|
if (cmd == CMD_ID_DEVID) { // Get DEV_ID
|
||||||
|
osal_memcpy(obuf, &dev_id, sizeof(dev_id));
|
||||||
|
olen = sizeof(dev_id);
|
||||||
|
} else if (cmd == CMD_ID_CFG) { // Get/Set device config
|
||||||
|
if (--len > sizeof(cfg))
|
||||||
|
len = sizeof(cfg);
|
||||||
|
if (len) {
|
||||||
|
osal_memcpy(&cfg, &ibuf[1], len);
|
||||||
|
test_config();
|
||||||
|
flash_write_cfg(&cfg, EEP_ID_CFG, sizeof(cfg));
|
||||||
|
}
|
||||||
|
osal_memcpy(&obuf[1], &cfg, sizeof(cfg));
|
||||||
|
olen = sizeof(cfg) + 1;
|
||||||
|
} else if (cmd == CMD_ID_CFG_DEF) { // Set default device config
|
||||||
|
osal_memcpy(&cfg, &def_cfg, sizeof(cfg));
|
||||||
|
test_config();
|
||||||
|
flash_write_cfg(&cfg, EEP_ID_CFG, sizeof(cfg));
|
||||||
|
osal_memcpy(&obuf[1], &cfg, sizeof(cfg));
|
||||||
|
olen = sizeof(cfg) + 1;
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
|
} else if (cmd == CMD_ID_CFS) { // Get/Set sensor config
|
||||||
|
if (--len > sizeof(thsensor_cfg.coef))
|
||||||
|
len = sizeof(thsensor_cfg.coef);
|
||||||
|
if (len) {
|
||||||
|
osal_memcpy(&thsensor_cfg.coef, &ibuf[1], len);
|
||||||
|
flash_write_cfg(&thsensor_cfg.coef, EEP_ID_CFS, sizeof(thsensor_cfg.coef));
|
||||||
|
}
|
||||||
|
osal_memcpy(&obuf[1], &thsensor_cfg, thsensor_cfg_send_size);
|
||||||
|
olen = thsensor_cfg_send_size + 1;
|
||||||
|
} else if (cmd == CMD_ID_CFS_DEF) { // Get/Set default sensor config
|
||||||
|
osal_memset(&thsensor_cfg, 0, thsensor_cfg_send_size);
|
||||||
|
init_sensor();
|
||||||
|
osal_memcpy(&obuf[1], &thsensor_cfg, thsensor_cfg_send_size);
|
||||||
|
olen = thsensor_cfg_send_size + 1;
|
||||||
|
} else if (cmd == CMD_ID_SEN_ID) {
|
||||||
|
osal_memcpy(&obuf[1], (uint8_t *)&thsensor_cfg.mid, 5);
|
||||||
|
olen = 1 + 5;
|
||||||
|
#endif
|
||||||
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
} else if (cmd == CMD_ID_LOGGER && len > 2) { // Read memory measures
|
||||||
|
rd_memo.cnt = ibuf[1] | (ibuf[2] << 8);
|
||||||
|
if (rd_memo.cnt) {
|
||||||
|
rd_memo.saved = memo;
|
||||||
|
if (len > 4)
|
||||||
|
rd_memo.cur = ibuf[3] | (ibuf[4] << 8);
|
||||||
|
else
|
||||||
|
rd_memo.cur = 0;
|
||||||
|
//gapRole_SlaveLatency = periConnParameters.latency = 0;
|
||||||
|
//osal_set_event(gapRole_TaskID, START_CONN_UPDATE_EVT);
|
||||||
|
} else {
|
||||||
|
//gapRole_SlaveLatency = periConnParameters.latency = cfg.connect_latency;
|
||||||
|
//osal_set_event(gapRole_TaskID, START_CONN_UPDATE_EVT);
|
||||||
|
}
|
||||||
|
wrk_notify();
|
||||||
|
// osal_set_event(simpleBLEPeripheral_TaskID, WRK_NOTIFY_EVT);
|
||||||
|
} else if (cmd == CMD_ID_CLRLOG && len > 2) { // Clear memory measures
|
||||||
|
if (ibuf[1] == 0x12 && ibuf[2] == 0x34) {
|
||||||
|
clear_memo();
|
||||||
|
olen = 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else if (cmd == CMD_ID_SERIAL) {
|
||||||
|
osal_memcpy(&obuf[1], devInfoSerialNumber, sizeof(devInfoSerialNumber)-1);
|
||||||
|
olen = 1 + sizeof(devInfoSerialNumber)-1;
|
||||||
|
} else if (cmd == CMD_ID_FLASH_ID) {
|
||||||
|
osal_memcpy(&obuf[1], (uint8_t *)&phy_flash.IdentificationID, 8);
|
||||||
|
olen = 1 + 8;
|
||||||
|
// } else if (cmd == CMD_ID_DNAME) {
|
||||||
|
// } else if (cmd == CMD_ID_DEV_MAC) {
|
||||||
|
} else if (cmd == CMD_ID_MTU) {
|
||||||
|
if (ibuf[1] <= MTU_SIZE)
|
||||||
|
ATT_UpdateMtuSize(gapRole_ConnectionHandle, ibuf[1]);
|
||||||
|
else
|
||||||
|
obuf[1] = 0xff;
|
||||||
|
olen = 2;
|
||||||
|
} else if (cmd == CMD_ID_REBOOT) {
|
||||||
|
GAPRole_TerminateConnection();
|
||||||
|
if(len >= 2) {
|
||||||
|
write_reg(OTA_MODE_SELECT_REG, ibuf[1]);
|
||||||
|
}
|
||||||
|
hal_system_soft_reset();
|
||||||
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
|
} else if (cmd == CMD_ID_LCD_DUMP) { // Get/set lcd buf
|
||||||
|
if (--len > sizeof(display_buff))
|
||||||
|
len = sizeof(display_buff);
|
||||||
|
if (len) {
|
||||||
|
osal_memcpy(display_buff, &ibuf[1], len);
|
||||||
|
update_lcd();
|
||||||
|
}
|
||||||
|
osal_memcpy(&obuf[1], display_buff, sizeof(display_buff));
|
||||||
|
olen = 1 + sizeof(display_buff);
|
||||||
|
#endif
|
||||||
|
} else if (cmd == CMD_ID_UTC_TIME) { // Get/set utc time
|
||||||
|
if (--len > sizeof(clkt.utc_time_sec))
|
||||||
|
len = sizeof(clkt.utc_time_sec);
|
||||||
|
if (len) {
|
||||||
|
memcpy(&clkt.utc_time_sec, &ibuf[1], len);
|
||||||
|
#if (DEV_SERVICES & SERVICE_TIME_ADJUST)
|
||||||
|
clkt.utc_set_time_sec =clkt. utc_time_sec;
|
||||||
|
#endif
|
||||||
|
clkt.utc_time_tik = clock_time_rtc();
|
||||||
|
}
|
||||||
|
get_utc_time_sec();
|
||||||
|
osal_memcpy(&obuf[1], &clkt.utc_time_sec, sizeof(clkt.utc_time_sec));
|
||||||
|
#if (DEV_SERVICES & SERVICE_TIME_ADJUST)
|
||||||
|
memcpy(&obuf[sizeof(clkt.utc_time_sec) + 1], &clkt.utc_set_time_sec, sizeof(clkt.utc_set_time_sec));
|
||||||
|
olen = sizeof(clkt.utc_time_sec) + sizeof(clkt.utc_set_time_sec) + 1;
|
||||||
|
#else
|
||||||
|
olen = sizeof(clkt.utc_time_sec) + 1;
|
||||||
|
#endif // SERVICE_TIME_ADJUST
|
||||||
|
#if (DEV_SERVICES & SERVICE_TIME_ADJUST)
|
||||||
|
} else if (cmd == CMD_ID_TADJUST) { // Get/set adjust time clock delta (in 1/16 us for 1 sec)
|
||||||
|
if (len > 4) {
|
||||||
|
memcpy(&clkt.delta_time, &ibuf[1], 4);
|
||||||
|
flash_write_cfg(&clkt.delta_time, EEP_ID_TIM, sizeof(&clkt.delta_time));
|
||||||
|
}
|
||||||
|
memcpy(&send_buf[1], &clkt.delta_time, sizeof(clkt.delta_time));
|
||||||
|
olen = sizeof(clkt.delta_time) + 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//---------- Debug commands (unsupported in different versions!):
|
||||||
|
|
||||||
|
} else if (cmd == CMD_ID_EEP_RW && len > 2) {
|
||||||
|
obuf[1] = ibuf[1];
|
||||||
|
obuf[2] = ibuf[2];
|
||||||
|
uint16_t id = ibuf[1] | (ibuf[2] << 8);
|
||||||
|
if(len > 3) {
|
||||||
|
flash_write_cfg(&ibuf[3], id, len - 3);
|
||||||
|
}
|
||||||
|
int16_t i = flash_read_cfg(&obuf[3], id, SEND_DATA_SIZE);
|
||||||
|
if(i < 0) {
|
||||||
|
obuf[1] = (uint8_t)(i & 0xff); // Error
|
||||||
|
olen = 2;
|
||||||
|
} else
|
||||||
|
olen = i + 3;
|
||||||
|
} else if (cmd == CMD_ID_MEM_RW && len > 4) { // Read/Write memory
|
||||||
|
uint8_t *p = (uint8_t *)
|
||||||
|
((uint32_t)(ibuf[1] | (ibuf[2]<<8) | (ibuf[3]<<16) | (ibuf[4]<<24)));
|
||||||
|
if(len > 5) {
|
||||||
|
len -= 5;
|
||||||
|
osal_memcpy(p, &ibuf[5], len);
|
||||||
|
} else
|
||||||
|
len = SEND_DATA_SIZE;
|
||||||
|
osal_memcpy(obuf, ibuf, 5);
|
||||||
|
osal_memcpy(&obuf[5], p, len);
|
||||||
|
olen = len + 1 + 4;
|
||||||
|
} else if (cmd == CMD_ID_REG_RW && len > 4) { // Read/Write register
|
||||||
|
volatile uint32_t *p = (volatile uint32_t *)
|
||||||
|
((uint32_t)(ibuf[1] | (ibuf[2]<<8) | (ibuf[3]<<16) | (ibuf[4]<<24)));
|
||||||
|
uint32_t tmp;
|
||||||
|
if(len > 8) {
|
||||||
|
tmp = ibuf[5] | (ibuf[6]<<8) | (ibuf[7]<<16) | (ibuf[8]<<24);
|
||||||
|
*p = tmp;
|
||||||
|
} else {
|
||||||
|
obuf[1] = 0xfe; // Error size
|
||||||
|
olen = 2;
|
||||||
|
}
|
||||||
|
tmp = *p;
|
||||||
|
osal_memcpy(obuf, ibuf, 5);
|
||||||
|
osal_memcpy(&obuf[5], &tmp, 4);
|
||||||
|
olen = 1 + 4 + 4;
|
||||||
|
} else {
|
||||||
|
obuf[1] = 0xff; // Error cmd
|
||||||
|
olen = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return olen;
|
||||||
|
}
|
||||||
106
bthome_phy6222/source/cmd_parser.h
Normal file
106
bthome_phy6222/source/cmd_parser.h
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* cmd_parcer.h
|
||||||
|
*
|
||||||
|
* Created on: 16 01 2024
|
||||||
|
* Author: pvvx
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CMD_PARSER_H_
|
||||||
|
#define _CMD_PARSER_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
//#include "types.h"
|
||||||
|
/*********************************************************************
|
||||||
|
* CONSTANTS
|
||||||
|
*/
|
||||||
|
// A complete list of interface commands for different devices.
|
||||||
|
// Not all commands are supported by a specific device (!)
|
||||||
|
enum CMD_ID_KEYS {
|
||||||
|
CMD_ID_DEVID = 0x00, // Get dev id, version, services
|
||||||
|
CMD_ID_DNAME = 0x01, // Get/Set device name, "\0" - default: THB2_xxxx
|
||||||
|
CMD_ID_GDEVS = 0x02, // Get address devices
|
||||||
|
CMD_ID_I2C_SCAN = 0x03, // I2C scan
|
||||||
|
CMD_ID_I2C_UTR = 0x04, // Universal I2C/SMBUS read-write
|
||||||
|
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_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
|
||||||
|
CMD_ID_UTC_TIME = 0x23, // Get/Set utc time (if USE_CLOCK = 1)
|
||||||
|
CMD_ID_TADJUST = 0x24, // Get/Set adjust time clock delta (in 1/16 us for 1 sec)
|
||||||
|
CMD_ID_CFS = 0x25, // Get/Set sensor config
|
||||||
|
CMD_ID_CFS_DEF = 0x26, // Get/Set default sensor config
|
||||||
|
CMD_ID_MEASURE = 0x33, // Start/stop notify measures in connection mode
|
||||||
|
CMD_ID_LOGGER = 0x35, // Read memory measures
|
||||||
|
CMD_ID_CLRLOG = 0x36, // Clear memory measures
|
||||||
|
CMD_ID_RDS = 0x40, // Get/Set Reed switch config (DIY devices)
|
||||||
|
CMD_ID_TRG = 0x44, // Get/Set trg and Reed switch data config
|
||||||
|
CMD_ID_TRG_OUT = 0x45, // Get/Set trg out, Send Reed switch and trg data
|
||||||
|
CMD_ID_HXC = 0x49, // Get/Set HX71X config
|
||||||
|
CMD_ID_CFG = 0x55, // Get/Set device config
|
||||||
|
CMD_ID_CFG_DEF = 0x56, // Set default device config
|
||||||
|
CMD_ID_LCD_DUMP = 0x60, // Get/Set lcd buf
|
||||||
|
CMD_ID_LCD_FLG = 0x61, // Start/Stop notify lcd dump and ...
|
||||||
|
CMD_ID_PINCODE = 0x70, // Set new PinCode 0..999999
|
||||||
|
CMD_ID_MTU = 0x71, // Request Mtu Size Exchange (23..255)
|
||||||
|
CMD_ID_REBOOT = 0x72, // Set Reboot on disconnect
|
||||||
|
CMD_ID_SET_OTA = 0x73, // Extension BigOTA: Get/set address and size OTA, erase sectors
|
||||||
|
|
||||||
|
|
||||||
|
// Debug commands (unsupported in different versions!):
|
||||||
|
|
||||||
|
CMD_ID_OTAC = 0xD1, // OTA clear
|
||||||
|
CMD_ID_WRFB = 0xD3, // Write Flash
|
||||||
|
CMD_ID_RDFB = 0xD4, // Read Flash Block
|
||||||
|
CMD_ID_ERFB = 0xD5, // Erase Flash Sector
|
||||||
|
CMD_ID_CHGB = 0xD7, // Change boot
|
||||||
|
CMD_ID_REG_RW = 0xDA, // Read/Write Registers
|
||||||
|
CMD_ID_MEM_RW = 0xDB, // Read/Write memory
|
||||||
|
CMD_ID_EEP_RW = 0xDC, // Get/set EEP
|
||||||
|
CMD_ID_LR_RESET = 0xDD, // Reset Long Range
|
||||||
|
CMD_ID_DEBUG = 0xDE // Test/Debug
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// supported services by the device
|
||||||
|
typedef struct _dev_services_t{
|
||||||
|
uint32_t ota: 1; //0 OTA
|
||||||
|
uint32_t ota_ext: 1; //1 OTA extension
|
||||||
|
uint32_t pincode: 1; //2 pin-code
|
||||||
|
uint32_t bindkey: 1; //3 bindkey
|
||||||
|
uint32_t history: 1; //4 history
|
||||||
|
uint32_t screen: 1; //5 screen
|
||||||
|
uint32_t long_range: 1; //6 LE Long Range
|
||||||
|
uint32_t ths: 1; //7 T & H sensor
|
||||||
|
uint32_t rds: 1; //8 Reed switch sensor
|
||||||
|
uint32_t key: 1; //9 key
|
||||||
|
uint32_t out_pins: 1; //10 Output pins
|
||||||
|
uint32_t inp_pins: 1; //11 Input pins
|
||||||
|
uint32_t reserved: 20;
|
||||||
|
} dev_services_t;
|
||||||
|
|
||||||
|
|
||||||
|
// CMD_ID_DEV_ID
|
||||||
|
typedef struct _dev_id_t{
|
||||||
|
uint8_t pid; // packet identifier = CMD_ID_DEVID
|
||||||
|
uint8_t revision; // protocol version/revision
|
||||||
|
uint16_t hw_version; // hardware version
|
||||||
|
uint16_t sw_version; // software version (BCD)
|
||||||
|
uint16_t dev_spec_data; // device-specific data
|
||||||
|
uint32_t services; // supported services by the device
|
||||||
|
} dev_id_t, * pdev_id_t;
|
||||||
|
|
||||||
|
extern const dev_id_t dev_id;
|
||||||
|
|
||||||
|
int cmd_parser(uint8_t * obuf, uint8_t * ibuf, uint32_t len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _CMD_PARSER_H_ */
|
||||||
|
|
@ -38,20 +38,46 @@
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#include "sbp_profile.h"
|
#include "sbp_profile.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
extern gapPeriConnectParams_t periConnParameters;
|
extern gapPeriConnectParams_t periConnParameters;
|
||||||
|
|
||||||
|
clock_time_t clkt;
|
||||||
|
|
||||||
cfg_t cfg;
|
cfg_t cfg;
|
||||||
|
|
||||||
const cfg_t def_cfg = {
|
const cfg_t def_cfg = {
|
||||||
.rf_tx_power = RF_PHY_TX_POWER_0DBM,
|
.rf_tx_power = RF_PHY_TX_POWER_0DBM,
|
||||||
.advertising_interval = 80, // 80 * 62.5 = 5000 ms
|
.advertising_interval = 80, // 80 * 62.5 = 5000 ms
|
||||||
.measure_interval = 2, // 5 * 2 = 10 sec
|
.measure_interval = 2, // 5 * 2 = 10 sec
|
||||||
.batt_interval = 6, // 60 sec
|
.batt_interval = 60, // 60 sec
|
||||||
.connect_latency = 29, // 30*30 = 900 ms
|
.connect_latency = 29, // 30*30 = 900 ms
|
||||||
.averaging_measurements = 180 // 180*10 = 1800 sec, 30 min
|
.averaging_measurements = 2 // 180*10 = 1800 sec, 30 min
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
uint32_t get_delta_time_rtc(uint32_t start_time_rtc) {
|
||||||
|
uint32_t new_time_rtc = clock_time_rtc();
|
||||||
|
if(new_time_rtc < start_time_rtc)
|
||||||
|
new_time_rtc += 0x1000000; // + 512 sec
|
||||||
|
return new_time_rtc - start_time_rtc;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t get_utc_time_sec(void) {
|
||||||
|
uint32_t new_time_tik = clock_time_rtc();
|
||||||
|
if(new_time_tik < clkt.utc_time_tik)
|
||||||
|
new_time_tik += 0x1000000; // + 512 sec
|
||||||
|
clkt.utc_time_add += new_time_tik - clkt.utc_time_tik;
|
||||||
|
clkt.utc_time_tik = new_time_tik;
|
||||||
|
clkt.utc_time_sec += clkt.utc_time_add >> 15; // div 32768
|
||||||
|
clkt.utc_time_add &= 32767;
|
||||||
|
#if (DEV_SERVICES & SERVICE_TIME_ADJUST)
|
||||||
|
// TODO
|
||||||
|
#endif
|
||||||
|
return clkt.utc_time_sec;
|
||||||
|
}
|
||||||
|
|
||||||
void test_config(void) {
|
void test_config(void) {
|
||||||
if (cfg.rf_tx_power > RF_PHY_TX_POWER_EXTRA_MAX)
|
if (cfg.rf_tx_power > RF_PHY_TX_POWER_EXTRA_MAX)
|
||||||
cfg.rf_tx_power = RF_PHY_TX_POWER_EXTRA_MAX;
|
cfg.rf_tx_power = RF_PHY_TX_POWER_EXTRA_MAX;
|
||||||
|
|
@ -78,10 +104,21 @@ void load_eep_config(void) {
|
||||||
} else {
|
} else {
|
||||||
if (flash_read_cfg(&cfg, EEP_ID_CFG, sizeof(cfg)) != sizeof(cfg))
|
if (flash_read_cfg(&cfg, EEP_ID_CFG, sizeof(cfg)) != sizeof(cfg))
|
||||||
osal_memcpy(&cfg, &def_cfg, sizeof(cfg));
|
osal_memcpy(&cfg, &def_cfg, sizeof(cfg));
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
if(flash_read_cfg(&thsensor_cfg.coef, EEP_ID_CFS, sizeof(thsensor_cfg.coef)) != sizeof(thsensor_cfg.coef)) {
|
if(flash_read_cfg(&thsensor_cfg.coef, EEP_ID_CFS, sizeof(thsensor_cfg.coef)) != sizeof(thsensor_cfg.coef)) {
|
||||||
osal_memset(&thsensor_cfg.coef, 0, sizeof(thsensor_cfg.coef));
|
osal_memset(&thsensor_cfg.coef, 0, sizeof(thsensor_cfg.coef));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#if (DEV_SERVICES & SERVICE_TIME_ADJUST)
|
||||||
|
if (flash_read_cfg(&clkt.delta_time, EEP_ID_TIM, sizeof(&clkt.delta_time)) != sizeof(&clkt.delta_time)) {
|
||||||
|
clkt.delta_time = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
memo_init();
|
||||||
|
#endif
|
||||||
test_config();
|
test_config();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#ifndef SOURCE_CONFIG_H_
|
#ifndef SOURCE_CONFIG_H_
|
||||||
#define SOURCE_CONFIG_H_
|
#define SOURCE_CONFIG_H_
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#ifndef APP_VERSION
|
#ifndef APP_VERSION
|
||||||
|
|
@ -38,40 +39,49 @@
|
||||||
#define DEVICE_TH05 21
|
#define DEVICE_TH05 21
|
||||||
|
|
||||||
#ifndef DEVICE
|
#ifndef DEVICE
|
||||||
#define DEVICE DEVICE_THB2
|
#define DEVICE DEVICE_TH05
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// supported services by the device (bits)
|
// supported services by the device (bits)
|
||||||
#define SERVICE_OTA 0x0001
|
#define SERVICE_OTA 0x00001
|
||||||
#define SERVICE_OTA_EXT 0x0002
|
#define SERVICE_OTA_EXT 0x00002
|
||||||
#define SERVICE_PINCODE 0x0004 // пока нет
|
#define SERVICE_PINCODE 0x00004 // пока нет
|
||||||
#define SERVICE_BINDKEY 0x0008 // пока нет
|
#define SERVICE_BINDKEY 0x00008 // пока нет
|
||||||
#define SERVICE_HISTORY 0x0010 // пока нет
|
#define SERVICE_HISTORY 0x00010 // пока нет
|
||||||
#define SERVICE_SCREEN 0x0020 // пока нет
|
#define SERVICE_SCREEN 0x00020 // пока нет
|
||||||
#define SERVICE_LE_LR 0x0040 // пока нет
|
#define SERVICE_LE_LR 0x00040 // пока нет
|
||||||
#define SERVICE_THS 0x0080
|
#define SERVICE_THS 0x00080
|
||||||
#define SERVICE_RDS 0x0100 // пока нет
|
#define SERVICE_RDS 0x00100 // пока нет
|
||||||
#define SERVICE_KEY 0x0200
|
#define SERVICE_KEY 0x00200
|
||||||
#define SERVICE_OUTS 0x0400 // пока нет
|
#define SERVICE_OUTS 0x00400 // пока нет
|
||||||
#define SERVICE_INS 0x0800 // пока нет
|
#define SERVICE_INS 0x00800 // пока нет
|
||||||
|
#define SERVICE_TIME_ADJUST 0x01000 // пока нет
|
||||||
|
#define SERVICE_HARD_CLOCK 0x02000 // пока нет
|
||||||
|
|
||||||
#define OTA_TYPE_NONE 0 // нет OTA
|
#define OTA_TYPE_NONE 0 // нет OTA
|
||||||
#define OTA_TYPE_BOOT (SERVICE_OTA | SERVICE_OTA_EXT) // вариант для прошивки boot + OTA
|
#define OTA_TYPE_BOOT (SERVICE_OTA | SERVICE_OTA_EXT) // вариант для прошивки boot + OTA
|
||||||
#define OTA_TYPE_APP SERVICE_OTA_EXT // переключение из APP на OTA + boot прошивку, пока не реализовано
|
#define OTA_TYPE_APP SERVICE_OTA_EXT // переключение из APP на OTA + boot прошивку, пока не реализовано
|
||||||
|
|
||||||
#ifndef OTA_TYPE
|
#ifndef OTA_TYPE
|
||||||
#define OTA_TYPE OTA_TYPE_BOOT
|
#define OTA_TYPE OTA_TYPE_NONE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEF_SOFTWARE_REVISION {'V', '0'+ (APP_VERSION >> 4), '.' , '0'+ (APP_VERSION & 0x0F), 0}
|
#define DEF_SOFTWARE_REVISION {'V', '0'+ (APP_VERSION >> 4), '.' , '0'+ (APP_VERSION & 0x0F), 0}
|
||||||
|
|
||||||
#if DEVICE == DEVICE_THB2
|
#if DEVICE == DEVICE_THB2
|
||||||
/* Model: THB2 */
|
/* Model: THB2 */
|
||||||
|
#if OTA_TYPE == OTA_TYPE_BOOT
|
||||||
#define DEV_SERVICES (OTA_TYPE \
|
#define DEV_SERVICES (OTA_TYPE \
|
||||||
| SERVICE_THS \
|
| SERVICE_THS \
|
||||||
| SERVICE_KEY \
|
| SERVICE_KEY \
|
||||||
)
|
)
|
||||||
|
#else
|
||||||
|
#define DEV_SERVICES (OTA_TYPE \
|
||||||
|
| SERVICE_THS \
|
||||||
|
| SERVICE_KEY \
|
||||||
|
| SERVICE_HISTORY \
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ADC_PIN_USE_OUT 0
|
#define ADC_PIN_USE_OUT 0
|
||||||
#define ADC_PIN GPIO_P11
|
#define ADC_PIN GPIO_P11
|
||||||
|
|
@ -90,10 +100,18 @@
|
||||||
|
|
||||||
#elif DEVICE == DEVICE_BTH01
|
#elif DEVICE == DEVICE_BTH01
|
||||||
/* Model: BTH01 */
|
/* Model: BTH01 */
|
||||||
|
#if OTA_TYPE == OTA_TYPE_BOOT
|
||||||
#define DEV_SERVICES (OTA_TYPE \
|
#define DEV_SERVICES (OTA_TYPE \
|
||||||
| SERVICE_THS \
|
| SERVICE_THS \
|
||||||
| SERVICE_KEY \
|
| SERVICE_KEY \
|
||||||
)
|
)
|
||||||
|
#else
|
||||||
|
#define DEV_SERVICES (OTA_TYPE \
|
||||||
|
| SERVICE_THS \
|
||||||
|
| SERVICE_KEY \
|
||||||
|
| SERVICE_HISTORY \
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ADC_PIN_USE_OUT 1 // hal_gpio_write(ADC_PIN, 1);
|
#define ADC_PIN_USE_OUT 1 // hal_gpio_write(ADC_PIN, 1);
|
||||||
#define ADC_PIN GPIO_P11
|
#define ADC_PIN GPIO_P11
|
||||||
|
|
@ -113,12 +131,20 @@
|
||||||
|
|
||||||
#elif DEVICE == DEVICE_TH05
|
#elif DEVICE == DEVICE_TH05
|
||||||
/* Model: TH05 */
|
/* Model: TH05 */
|
||||||
|
#if OTA_TYPE == OTA_TYPE_BOOT
|
||||||
#define DEV_SERVICES (OTA_TYPE \
|
#define DEV_SERVICES (OTA_TYPE \
|
||||||
| SERVICE_THS \
|
| SERVICE_THS \
|
||||||
| SERVICE_KEY \
|
|
||||||
| SERVICE_SCREEN \
|
| SERVICE_SCREEN \
|
||||||
|
| SERVICE_KEY \
|
||||||
)
|
)
|
||||||
|
#else
|
||||||
|
#define DEV_SERVICES (OTA_TYPE \
|
||||||
|
| SERVICE_THS \
|
||||||
|
| SERVICE_SCREEN \
|
||||||
|
| SERVICE_KEY \
|
||||||
|
| SERVICE_HISTORY \
|
||||||
|
)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ADC_PIN_USE_OUT 1 // hal_gpio_write(ADC_PIN, 1);
|
#define ADC_PIN_USE_OUT 1 // hal_gpio_write(ADC_PIN, 1);
|
||||||
#define ADC_PIN GPIO_P11
|
#define ADC_PIN GPIO_P11
|
||||||
|
|
@ -175,13 +201,33 @@ extern const cfg_t def_cfg;
|
||||||
|
|
||||||
typedef struct _adv_work_t {
|
typedef struct _adv_work_t {
|
||||||
uint32_t measure_interval_ms;
|
uint32_t measure_interval_ms;
|
||||||
|
uint32_t measure_batt_tik;
|
||||||
uint8_t adv_count;
|
uint8_t adv_count;
|
||||||
uint8_t adv_batt_count;
|
|
||||||
uint8_t adv_con_count;
|
uint8_t adv_con_count;
|
||||||
|
uint8_t adv_batt;
|
||||||
} adv_work_t;
|
} adv_work_t;
|
||||||
|
|
||||||
extern adv_work_t adv_wrk;
|
extern adv_work_t adv_wrk;
|
||||||
|
|
||||||
|
// uint32_t rtc_get_counter(void); // tik 32768
|
||||||
|
inline uint32 clock_time_rtc(void) {
|
||||||
|
return (*(volatile unsigned int*)0x4000f028);// & 0xffffff; // max 512 sec
|
||||||
|
}
|
||||||
|
// uint32_t get_delta_time_rtc(uint32_t start_time_rtc);
|
||||||
|
|
||||||
|
typedef struct _clock_time_t {
|
||||||
|
uint32_t utc_time_sec; // utc, sec 01 01 1970
|
||||||
|
uint32_t utc_time_add; // add
|
||||||
|
uint32_t utc_time_tik; // old rtc tik, in 32768 Hz
|
||||||
|
uint32_t utc_set_time_sec; // время установки utc_time_sec
|
||||||
|
#if (DEV_SERVICES & SERVICE_TIME_ADJUST)
|
||||||
|
int32_t delta_time; // коррекция времени rtc
|
||||||
|
#endif
|
||||||
|
} clock_time_t;
|
||||||
|
extern clock_time_t clkt;
|
||||||
|
|
||||||
|
uint32_t get_utc_time_sec(void);
|
||||||
|
|
||||||
void test_config(void);
|
void test_config(void);
|
||||||
void load_eep_config(void);
|
void load_eep_config(void);
|
||||||
|
|
||||||
|
|
|
||||||
202
bthome_phy6222/source/dev_i2c.c
Normal file
202
bthome_phy6222/source/dev_i2c.c
Normal file
|
|
@ -0,0 +1,202 @@
|
||||||
|
/*
|
||||||
|
* dev_i2c.c
|
||||||
|
*
|
||||||
|
* Created on: 25 янв. 2024 г.
|
||||||
|
* Author: pvvx
|
||||||
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
#include "OSAL.h"
|
||||||
|
#include "gpio.h"
|
||||||
|
#include "rom_sym_def.h"
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "dev_i2c.h"
|
||||||
|
|
||||||
|
#define I2C_WAIT_ms 1
|
||||||
|
|
||||||
|
void init_i2c(bool speed400khz) {
|
||||||
|
hal_gpio_fmux_set(I2C_SCL, FMUX_IIC0_SCL);
|
||||||
|
hal_gpio_fmux_set(I2C_SDA, FMUX_IIC0_SDA);
|
||||||
|
|
||||||
|
//hal_i2c_init(I2C_0, I2C_CLOCK_400K):
|
||||||
|
|
||||||
|
int pclk = clk_get_pclk();
|
||||||
|
|
||||||
|
AP_I2C_TypeDef* pi2cdev = AP_I2C0;
|
||||||
|
hal_clk_gate_enable(MOD_I2C0);
|
||||||
|
pi2cdev->IC_ENABLE = 0;
|
||||||
|
pi2cdev->IC_CON = 0x61;
|
||||||
|
if(speed400khz) {
|
||||||
|
// SET_I2C_SPEED 400 kHz
|
||||||
|
pi2cdev->IC_CON = ((pi2cdev->IC_CON) & 0xfffffff9) | (0x02 << 1); // SPEED_FAST
|
||||||
|
if (pclk == 16000000) {
|
||||||
|
pi2cdev->IC_FS_SCL_HCNT = 10;
|
||||||
|
pi2cdev->IC_FS_SCL_LCNT = 17;
|
||||||
|
} else if (pclk == 32000000) {
|
||||||
|
pi2cdev->IC_FS_SCL_HCNT = 30;
|
||||||
|
pi2cdev->IC_FS_SCL_LCNT = 35;
|
||||||
|
} else if (pclk == 48000000) {
|
||||||
|
pi2cdev->IC_FS_SCL_HCNT = 48;
|
||||||
|
pi2cdev->IC_FS_SCL_LCNT = 54;
|
||||||
|
} else if (pclk == 64000000) {
|
||||||
|
pi2cdev->IC_FS_SCL_HCNT = 67;
|
||||||
|
pi2cdev->IC_FS_SCL_LCNT = 75;
|
||||||
|
} else if (pclk == 96000000) {
|
||||||
|
pi2cdev->IC_FS_SCL_HCNT = 105;
|
||||||
|
pi2cdev->IC_FS_SCL_LCNT = 113;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// SET_I2C_SPEED 100 kHz
|
||||||
|
pi2cdev->IC_CON = ((pi2cdev->IC_CON) & 0xfffffff9) | (0x01 << 1); // SPEED_STANDARD
|
||||||
|
if (pclk == 16000000) {
|
||||||
|
pi2cdev->IC_SS_SCL_HCNT = 70; //16
|
||||||
|
pi2cdev->IC_SS_SCL_LCNT = 76; //32)
|
||||||
|
} else if (pclk == 32000000) {
|
||||||
|
pi2cdev->IC_SS_SCL_HCNT = 148; //16
|
||||||
|
pi2cdev->IC_SS_SCL_LCNT = 154; //32)
|
||||||
|
} else if (pclk == 48000000) {
|
||||||
|
pi2cdev->IC_SS_SCL_HCNT = 230; //16
|
||||||
|
pi2cdev->IC_SS_SCL_LCNT = 236; //32)
|
||||||
|
} else if (pclk == 64000000) {
|
||||||
|
pi2cdev->IC_SS_SCL_HCNT = 307; //16
|
||||||
|
pi2cdev->IC_SS_SCL_LCNT = 320; //32)
|
||||||
|
} else if (pclk == 96000000) {
|
||||||
|
pi2cdev->IC_SS_SCL_HCNT = 460; //16
|
||||||
|
pi2cdev->IC_SS_SCL_LCNT = 470; //32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// pi2cdev->IC_TAR = I2C_MASTER_ADDR_DEF;
|
||||||
|
pi2cdev->IC_INTR_MASK = 0;
|
||||||
|
pi2cdev->IC_RX_TL = 0x0;
|
||||||
|
pi2cdev->IC_TX_TL = 0x1;
|
||||||
|
// pi2cdev->IC_ENABLE = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deinit_i2c(void) {
|
||||||
|
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
||||||
|
pi2cdev->IC_ENABLE = 0;
|
||||||
|
hal_clk_gate_disable(MOD_I2C0);
|
||||||
|
hal_gpio_pin_init(I2C_SCL, IE);
|
||||||
|
hal_gpio_pin_init(I2C_SDA, IE);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern volatile uint32 osal_sys_tick;
|
||||||
|
|
||||||
|
/* size max = 7 ! */
|
||||||
|
int read_i2c_bytes(uint8 addr, uint8 reg, uint8 * data, uint8 size) {
|
||||||
|
int i = size;
|
||||||
|
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
||||||
|
pi2cdev->IC_ENABLE = 0;
|
||||||
|
pi2cdev->IC_TAR = addr;
|
||||||
|
|
||||||
|
HAL_ENTER_CRITICAL_SECTION();
|
||||||
|
|
||||||
|
pi2cdev->IC_ENABLE = 1;
|
||||||
|
pi2cdev->IC_DATA_CMD = reg;
|
||||||
|
//while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
||||||
|
while(i--)
|
||||||
|
pi2cdev->IC_DATA_CMD = 0x100;
|
||||||
|
|
||||||
|
HAL_EXIT_CRITICAL_SECTION();
|
||||||
|
|
||||||
|
uint32 to = osal_sys_tick;
|
||||||
|
i = size;
|
||||||
|
while(i) {
|
||||||
|
if(pi2cdev->IC_STATUS & 0x08) { // fifo not empty
|
||||||
|
*data = pi2cdev->IC_DATA_CMD & 0xff;
|
||||||
|
data++;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
if(osal_sys_tick - to > I2C_WAIT_ms)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int read_i2c_nabuf(uint8 addr, uint8 * data, uint8 size) {
|
||||||
|
int i = size;
|
||||||
|
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
||||||
|
pi2cdev->IC_ENABLE = 0;
|
||||||
|
pi2cdev->IC_TAR = addr;
|
||||||
|
|
||||||
|
HAL_ENTER_CRITICAL_SECTION();
|
||||||
|
pi2cdev->IC_ENABLE = 1;
|
||||||
|
while(i--)
|
||||||
|
pi2cdev->IC_DATA_CMD = 0x100;
|
||||||
|
|
||||||
|
HAL_EXIT_CRITICAL_SECTION();
|
||||||
|
|
||||||
|
uint32 to = osal_sys_tick;
|
||||||
|
i = size;
|
||||||
|
while(i) {
|
||||||
|
if(pi2cdev->IC_STATUS & 0x08) { // fifo not empty
|
||||||
|
*data = pi2cdev->IC_DATA_CMD & 0xff;
|
||||||
|
data++;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
if(osal_sys_tick - to > I2C_WAIT_ms)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_i2c_byte(uint8 addr, uint8 data) {
|
||||||
|
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
||||||
|
pi2cdev->IC_ENABLE = 0;
|
||||||
|
pi2cdev->IC_TAR = addr;
|
||||||
|
HAL_ENTER_CRITICAL_SECTION();
|
||||||
|
pi2cdev->IC_ENABLE = 1;
|
||||||
|
pi2cdev->IC_DATA_CMD = data;
|
||||||
|
// while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
||||||
|
HAL_EXIT_CRITICAL_SECTION();
|
||||||
|
uint32 to = osal_sys_tick;
|
||||||
|
while(1) {
|
||||||
|
if(pi2cdev->IC_RAW_INTR_STAT & 0x200)// check tx empty
|
||||||
|
break;
|
||||||
|
if(osal_sys_tick - to > I2C_WAIT_ms)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_i2c_wreg(uint8 addr, uint8 reg, uint16 data) {
|
||||||
|
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
||||||
|
pi2cdev->IC_ENABLE = 0;
|
||||||
|
pi2cdev->IC_TAR = addr;
|
||||||
|
HAL_ENTER_CRITICAL_SECTION();
|
||||||
|
pi2cdev->IC_ENABLE = 1;
|
||||||
|
pi2cdev->IC_DATA_CMD = reg;
|
||||||
|
while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
||||||
|
pi2cdev->IC_DATA_CMD = (data >> 8) & 0xff;
|
||||||
|
while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
||||||
|
pi2cdev->IC_DATA_CMD = data & 0xff;
|
||||||
|
HAL_EXIT_CRITICAL_SECTION();
|
||||||
|
uint32 to = osal_sys_tick;
|
||||||
|
while(1) {
|
||||||
|
if(pi2cdev->IC_RAW_INTR_STAT & 0x200)// check tx empty
|
||||||
|
break;
|
||||||
|
if(osal_sys_tick - to > I2C_WAIT_ms)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_i2c_buf(uint8 addr, uint8 * pdata, int len) {
|
||||||
|
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
||||||
|
pi2cdev->IC_ENABLE = 0;
|
||||||
|
pi2cdev->IC_TAR = addr;
|
||||||
|
HAL_ENTER_CRITICAL_SECTION();
|
||||||
|
pi2cdev->IC_ENABLE = 1;
|
||||||
|
while(len--) {
|
||||||
|
pi2cdev->IC_DATA_CMD = *pdata++;
|
||||||
|
while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
||||||
|
}
|
||||||
|
HAL_EXIT_CRITICAL_SECTION();
|
||||||
|
uint32 to = osal_sys_tick;
|
||||||
|
while(1) {
|
||||||
|
if(pi2cdev->IC_RAW_INTR_STAT & 0x200)// check tx empty
|
||||||
|
break;
|
||||||
|
if(osal_sys_tick - to > I2C_WAIT_ms)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
20
bthome_phy6222/source/dev_i2c.h
Normal file
20
bthome_phy6222/source/dev_i2c.h
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* dev_i2c.h
|
||||||
|
*
|
||||||
|
* Created on: 25 янв. 2024 г.
|
||||||
|
* Author: pvvx
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _DEV_I2C_H_
|
||||||
|
#define _DEV_I2C_H_
|
||||||
|
|
||||||
|
void init_i2c(bool speed400khz);
|
||||||
|
void deinit_i2c(void);
|
||||||
|
int send_i2c_byte(uint8_t addr, uint8_t data);
|
||||||
|
int send_i2c_wreg(uint8 addr, uint8 reg, uint16 data);
|
||||||
|
int send_i2c_buf(uint8 addr, uint8 * pdata, int len);
|
||||||
|
int read_i2c_bytes(uint8 addr, uint8 reg, uint8 * data, uint8 size);
|
||||||
|
int read_i2c_nabuf(uint8 addr, uint8 * data, uint8 size);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _DEV_I2C_H_ */
|
||||||
|
|
@ -20,7 +20,7 @@ extern "C" {
|
||||||
//#define EEP_ID_PCD (0xC0DE) // EEP ID pincode
|
//#define EEP_ID_PCD (0xC0DE) // EEP ID pincode
|
||||||
//#define EEP_ID_CMF (0x0FCC) // EEP ID comfort data
|
//#define EEP_ID_CMF (0x0FCC) // EEP ID comfort data
|
||||||
//#define EEP_ID_DVN (0xDEAE) // EEP ID device name
|
//#define EEP_ID_DVN (0xDEAE) // EEP ID device name
|
||||||
//#define EEP_ID_TIM (0x0ADA) // EEP ID time adjust
|
#define EEP_ID_TIM (0x0ADA) // EEP ID time adjust
|
||||||
//#define EEP_ID_KEY (0xBC0D) // EEP ID bkey
|
//#define EEP_ID_KEY (0xBC0D) // EEP ID bkey
|
||||||
#define EEP_ID_VER (0x5555) // EEP ID blk: unsigned int = minimum supported version
|
#define EEP_ID_VER (0x5555) // EEP ID blk: unsigned int = minimum supported version
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,16 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
#include "OSAL.h"
|
#include "OSAL.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "rom_sym_def.h"
|
#include "rom_sym_def.h"
|
||||||
#include "i2c.h"
|
#include "dev_i2c.h"
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
#include "lcd_th05.h"
|
#include "lcd_th05.h"
|
||||||
|
|
||||||
#define SET_I2C_SPEED 400 // 100 or 400 kHz
|
#define LCD_I2C_SPEED 100 // 100 or 400 kHz
|
||||||
|
#define LCD_I2C_ADDR 0x3E
|
||||||
#define I2C_WAIT_ms 1
|
#define I2C_WAIT_ms 1
|
||||||
|
|
||||||
/* 0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F*/
|
/* 0,1,2,3,4,5,6,7,8,9,A,b,C,d,E,F*/
|
||||||
|
|
@ -46,7 +48,7 @@ const uint8_t display_numbers[] = {
|
||||||
#define LCD_SYM_0 0b011110011 // "0"
|
#define LCD_SYM_0 0b011110011 // "0"
|
||||||
#define LCD_SYM_a 0b011110110 // 'a'
|
#define LCD_SYM_a 0b011110110 // 'a'
|
||||||
|
|
||||||
#define lcd_i2c_addr 0x3E
|
uint8_t lcd_i2c_addr; // = 0x3E
|
||||||
|
|
||||||
uint8_t display_buff[LCD_BUF_SIZE] = {
|
uint8_t display_buff[LCD_BUF_SIZE] = {
|
||||||
LCD_SYM_o, LCD_SYM_o, LCD_SYM_o,
|
LCD_SYM_o, LCD_SYM_o, LCD_SYM_o,
|
||||||
|
|
@ -207,37 +209,16 @@ void show_clock(void) {
|
||||||
|
|
||||||
extern volatile uint32 osal_sys_tick;
|
extern volatile uint32 osal_sys_tick;
|
||||||
|
|
||||||
int send_i2c_buf(uint8 addr, uint8 * pdata, int len) {
|
|
||||||
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
|
||||||
pi2cdev->IC_ENABLE = 0;
|
|
||||||
pi2cdev->IC_TAR = addr;
|
|
||||||
HAL_ENTER_CRITICAL_SECTION();
|
|
||||||
pi2cdev->IC_ENABLE = 1;
|
|
||||||
while(len--) {
|
|
||||||
pi2cdev->IC_DATA_CMD = *pdata++;
|
|
||||||
while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
|
||||||
}
|
|
||||||
HAL_EXIT_CRITICAL_SECTION();
|
|
||||||
uint32 to = osal_sys_tick;
|
|
||||||
while(1) {
|
|
||||||
if(pi2cdev->IC_RAW_INTR_STAT & 0x200)// check tx empty
|
|
||||||
break;
|
|
||||||
if(osal_sys_tick - to > I2C_WAIT_ms)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void send_to_lcd(uint8_t *pbuf, int len){
|
static void send_to_lcd(uint8_t *pbuf, int len){
|
||||||
init_i2c(0);
|
init_i2c(0);
|
||||||
//send_i2c_byte(lcd_i2c_addr, 0x48);
|
if (send_i2c_buf(0x3E, pbuf, len))
|
||||||
send_i2c_buf(lcd_i2c_addr, pbuf, len);
|
|
||||||
//send_i2c_byte(lcd_i2c_addr, 0x58);
|
|
||||||
deinit_i2c();
|
deinit_i2c();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_lcd(void) {
|
void update_lcd(void) {
|
||||||
if (memcmp(&display_out_buff[1], display_buff, sizeof(display_buff))) {
|
if (lcd_i2c_addr && memcmp(&display_out_buff[1], display_buff, sizeof(display_buff))) {
|
||||||
memcpy(&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));
|
send_to_lcd(display_out_buff, sizeof(display_out_buff));
|
||||||
}
|
}
|
||||||
|
|
@ -245,13 +226,13 @@ void update_lcd(void) {
|
||||||
|
|
||||||
void init_lcd(void) {
|
void init_lcd(void) {
|
||||||
init_i2c(0);
|
init_i2c(0);
|
||||||
send_to_lcd((uint8_t *) lcd_init_cmd, sizeof(lcd_init_cmd)); // sleep: 15.5 uA
|
if(!send_i2c_buf(LCD_I2C_ADDR, (uint8_t *) lcd_init_cmd, sizeof(lcd_init_cmd))) // sleep: 15.5 uA
|
||||||
// display_out_buff[0] = 0xf0;
|
lcd_i2c_addr = LCD_I2C_ADDR;
|
||||||
// display_out_buff[1] = 0x00;
|
else
|
||||||
display_out_buff[3] = 0xFF;
|
lcd_i2c_addr = 0;
|
||||||
//display_cmp_buff[2+LCD_BUF_SIZE] = 0x58;
|
|
||||||
//send_i2c_byte(lcd_i2c_addr, 0x58);
|
|
||||||
deinit_i2c();
|
deinit_i2c();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************/
|
/****************************************************/
|
||||||
|
#endif // (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
#define LCD_BUF_SIZE 6
|
#define LCD_BUF_SIZE 6
|
||||||
|
|
||||||
// extern uint8_t lcd_i2c_addr; // LCD controller I2C address
|
extern uint8_t lcd_i2c_addr; // LCD controller I2C address
|
||||||
extern uint8_t display_buff[LCD_BUF_SIZE];
|
extern uint8_t display_buff[LCD_BUF_SIZE];
|
||||||
|
|
||||||
void init_lcd(void);
|
void init_lcd(void);
|
||||||
|
|
|
||||||
212
bthome_phy6222/source/logger.c
Normal file
212
bthome_phy6222/source/logger.c
Normal file
|
|
@ -0,0 +1,212 @@
|
||||||
|
/*
|
||||||
|
* logger.c
|
||||||
|
*
|
||||||
|
* Created on: 29.01.2021
|
||||||
|
* Author: pvvx
|
||||||
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
#include "flash.h"
|
||||||
|
#include "flash_eep.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "sensor.h"
|
||||||
|
#include "cmd_parser.h"
|
||||||
|
|
||||||
|
#define RAM
|
||||||
|
|
||||||
|
#define MEMO_SEC_COUNT ((FLASH_ADDR_END_MEMO - FLASH_ADDR_START_MEMO) / FLASH_SECTOR_SIZE) // 76 sectors
|
||||||
|
#define MEMO_SEC_RECS ((FLASH_SECTOR_SIZE-_memo_head_size)/_memo_blk_size) // - sector: 409 records
|
||||||
|
//#define MEMO_REC_COUNT (MEMO_SEC_RECS*(MEMO_SEC_COUNT-1))// max (76-1)*409 = 30675 records
|
||||||
|
|
||||||
|
#define _flash_read(a,b,c) memcpy((void *)c, (void *)(FLASH_BASE_ADDR + (unsigned int)a), b) // _flash_read(rdaddr, len, pbuf);
|
||||||
|
#define _flash_erase_sector(addr) hal_flash_erase_sector(FLASH_BASE_ADDR + addr)
|
||||||
|
#define _flash_write_dword(addr, wd) flash_write_word(FLASH_BASE_ADDR + addr,wd)
|
||||||
|
#define _flash_write(a,l,b) hal_flash_write(FLASH_BASE_ADDR + a,(unsigned char *)b, l)
|
||||||
|
|
||||||
|
typedef struct _summ_data_t {
|
||||||
|
uint32_t battery_mv; // mV
|
||||||
|
int32_t temp; // x 0.01 C
|
||||||
|
uint32_t humi; // x 0.01 %
|
||||||
|
uint32_t count;
|
||||||
|
} summ_data_t;
|
||||||
|
RAM summ_data_t summ_data;
|
||||||
|
|
||||||
|
RAM memo_inf_t memo;
|
||||||
|
RAM memo_rd_t rd_memo;
|
||||||
|
|
||||||
|
static uint32_t test_next_memo_sec_addr(uint32_t faddr) {
|
||||||
|
uint32_t mfaddr = faddr;
|
||||||
|
if (mfaddr >= FLASH_ADDR_END_MEMO)
|
||||||
|
mfaddr = FLASH_ADDR_START_MEMO;
|
||||||
|
else if (mfaddr < FLASH_ADDR_START_MEMO)
|
||||||
|
mfaddr = FLASH_ADDR_END_MEMO - FLASH_SECTOR_SIZE;
|
||||||
|
return mfaddr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void memo_sec_init(uint32_t faddr) {
|
||||||
|
uint32_t mfaddr = faddr;
|
||||||
|
mfaddr &= ~(FLASH_SECTOR_SIZE-1);
|
||||||
|
_flash_erase_sector(mfaddr);
|
||||||
|
_flash_write_dword(mfaddr, MEMO_SEC_ID);
|
||||||
|
memo.faddr = mfaddr + _memo_head_size;
|
||||||
|
memo.cnt_cur_sec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void memo_sec_close(uint32_t faddr) {
|
||||||
|
uint32_t mfaddr = faddr;
|
||||||
|
uint16_t flg = 0;
|
||||||
|
mfaddr &= ~(FLASH_SECTOR_SIZE-1);
|
||||||
|
_flash_write(mfaddr + _memo_head_size - sizeof(flg), sizeof(flg), &flg);
|
||||||
|
memo_sec_init(test_next_memo_sec_addr(mfaddr + FLASH_SECTOR_SIZE));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void memo_init_count(void) {
|
||||||
|
memo_head_t mhs;
|
||||||
|
uint32_t cnt, i = 0;
|
||||||
|
uint32_t faddr = memo.faddr & (~(FLASH_SECTOR_SIZE-1));
|
||||||
|
cnt = memo.faddr - faddr - _memo_head_size; // смещение в секторе
|
||||||
|
cnt /= _memo_blk_size;
|
||||||
|
do {
|
||||||
|
faddr = test_next_memo_sec_addr(faddr - FLASH_SECTOR_SIZE);
|
||||||
|
_flash_read(faddr, &mhs, _memo_head_size);
|
||||||
|
i++;
|
||||||
|
} while (mhs.id == MEMO_SEC_ID && mhs.flg == 0 && i < MEMO_SEC_COUNT);
|
||||||
|
cnt += i *MEMO_SEC_RECS;
|
||||||
|
memo.count = cnt;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void memo_init(void) {
|
||||||
|
memo_head_t mhs;
|
||||||
|
uint32_t tmp, fsec_end;
|
||||||
|
uint32_t faddr = FLASH_ADDR_START_MEMO;
|
||||||
|
memo.cnt_cur_sec = 0;
|
||||||
|
while (faddr < FLASH_ADDR_END_MEMO) {
|
||||||
|
_flash_read(faddr, _memo_head_size, &mhs);
|
||||||
|
if (mhs.id != MEMO_SEC_ID) {
|
||||||
|
memo_sec_init(faddr);
|
||||||
|
return;
|
||||||
|
} else if (mhs.flg == 0xffff) {
|
||||||
|
fsec_end = faddr + FLASH_SECTOR_SIZE;
|
||||||
|
faddr += _memo_head_size;
|
||||||
|
while (faddr < fsec_end) {
|
||||||
|
_flash_read(faddr, sizeof(tmp), &tmp);
|
||||||
|
if (tmp == 0xffffffff) {
|
||||||
|
memo.faddr = faddr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clkt.utc_time_sec = tmp + 5;
|
||||||
|
memo.cnt_cur_sec++;
|
||||||
|
faddr += _memo_blk_size;
|
||||||
|
}
|
||||||
|
memo_sec_close(fsec_end - FLASH_SECTOR_SIZE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
faddr += FLASH_SECTOR_SIZE;
|
||||||
|
}
|
||||||
|
memo_sec_init(FLASH_ADDR_START_MEMO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_memo(void) {
|
||||||
|
uint32_t tmp;
|
||||||
|
uint32_t faddr = FLASH_ADDR_START_MEMO + FLASH_SECTOR_SIZE;
|
||||||
|
memo.cnt_cur_sec = 0;
|
||||||
|
while (faddr < FLASH_ADDR_END_MEMO) {
|
||||||
|
_flash_read(faddr, sizeof(tmp), &tmp);
|
||||||
|
if (tmp == MEMO_SEC_ID)
|
||||||
|
_flash_erase_sector(faddr);
|
||||||
|
faddr += FLASH_SECTOR_SIZE;
|
||||||
|
}
|
||||||
|
memo_sec_init(FLASH_ADDR_START_MEMO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned get_memo(uint32_t bnum, pmemo_blk_t p) {
|
||||||
|
memo_head_t mhs;
|
||||||
|
uint32_t faddr;
|
||||||
|
faddr = rd_memo.saved.faddr & (~(FLASH_SECTOR_SIZE-1));
|
||||||
|
if (bnum > rd_memo.saved.cnt_cur_sec) {
|
||||||
|
bnum -= rd_memo.saved.cnt_cur_sec;
|
||||||
|
faddr -= FLASH_SECTOR_SIZE;
|
||||||
|
if (faddr < FLASH_ADDR_START_MEMO)
|
||||||
|
faddr = FLASH_ADDR_END_MEMO - FLASH_SECTOR_SIZE;
|
||||||
|
while (bnum > MEMO_SEC_RECS) {
|
||||||
|
bnum -= MEMO_SEC_RECS;
|
||||||
|
faddr -= FLASH_SECTOR_SIZE;
|
||||||
|
if (faddr < FLASH_ADDR_START_MEMO)
|
||||||
|
faddr = FLASH_ADDR_END_MEMO - FLASH_SECTOR_SIZE;
|
||||||
|
}
|
||||||
|
bnum = MEMO_SEC_RECS - bnum;
|
||||||
|
_flash_read(faddr, _memo_head_size, &mhs);
|
||||||
|
if (mhs.id != MEMO_SEC_ID || mhs.flg != 0)
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
bnum = rd_memo.saved.cnt_cur_sec - bnum;
|
||||||
|
}
|
||||||
|
faddr += _memo_head_size; // смещение в секторе
|
||||||
|
faddr += bnum * _memo_blk_size; // * size memo
|
||||||
|
_flash_read(faddr, _memo_blk_size, p);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int send_memo_blk(uint8_t * send_buf) {
|
||||||
|
int olen = 0;
|
||||||
|
send_buf[0] = CMD_ID_LOGGER;
|
||||||
|
if (++rd_memo.cur > rd_memo.cnt || (!get_memo(rd_memo.cur, (pmemo_blk_t)&send_buf[3]))) {
|
||||||
|
send_buf[1] = 0;
|
||||||
|
send_buf[2] = 0;
|
||||||
|
olen = 3;
|
||||||
|
// bls_pm_setManualLatency(cfg.connect_latency);
|
||||||
|
rd_memo.cnt = 0;
|
||||||
|
} else {
|
||||||
|
send_buf[1] = rd_memo.cur;
|
||||||
|
send_buf[2] = rd_memo.cur >> 8;
|
||||||
|
olen = 3 + _memo_blk_size;
|
||||||
|
}
|
||||||
|
return olen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if (cfg.averaging_measurements != 0) write_memo();
|
||||||
|
void write_memo(void) {
|
||||||
|
memo_blk_t mblk;
|
||||||
|
if (cfg.averaging_measurements == 1) {
|
||||||
|
mblk.temp = measured_data.temp;
|
||||||
|
mblk.humi = measured_data.humi;
|
||||||
|
mblk.vbat = measured_data.battery_mv;
|
||||||
|
} else {
|
||||||
|
summ_data.temp += measured_data.temp;
|
||||||
|
summ_data.humi += measured_data.humi;
|
||||||
|
summ_data.battery_mv += measured_data.battery_mv;
|
||||||
|
summ_data.count++;
|
||||||
|
if (cfg.averaging_measurements > summ_data.count)
|
||||||
|
return;
|
||||||
|
mblk.temp = (int16_t)(summ_data.temp/(int32_t)summ_data.count);
|
||||||
|
mblk.humi = (uint16_t)(summ_data.humi/summ_data.count);
|
||||||
|
mblk.vbat = (uint16_t)(summ_data.battery_mv/summ_data.count);
|
||||||
|
memset(&summ_data, 0, sizeof(summ_data));
|
||||||
|
}
|
||||||
|
if (clkt.utc_time_sec == 0xffffffff)
|
||||||
|
mblk.time = 0xfffffffe;
|
||||||
|
else
|
||||||
|
mblk.time = clkt.utc_time_sec;
|
||||||
|
uint32_t faddr = memo.faddr;
|
||||||
|
if (!faddr) {
|
||||||
|
memo_init();
|
||||||
|
faddr = memo.faddr;
|
||||||
|
}
|
||||||
|
_flash_write(faddr, _memo_blk_size, &mblk);
|
||||||
|
faddr += _memo_blk_size;
|
||||||
|
faddr &= (~(FLASH_SECTOR_SIZE-1));
|
||||||
|
if (memo.cnt_cur_sec >= MEMO_SEC_RECS - 1 ||
|
||||||
|
(memo.faddr & (~(FLASH_SECTOR_SIZE-1))) != faddr) {
|
||||||
|
memo_sec_close(memo.faddr);
|
||||||
|
} else {
|
||||||
|
memo.cnt_cur_sec++;
|
||||||
|
memo.faddr += _memo_blk_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // defined(DEV_SERVICES) && (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
57
bthome_phy6222/source/logger.h
Normal file
57
bthome_phy6222/source/logger.h
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* logger.h
|
||||||
|
*
|
||||||
|
* Created on: 29.01.2021
|
||||||
|
* Author: pvvx
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LOGGER_H_
|
||||||
|
#define _LOGGER_H_
|
||||||
|
#include <string.h>
|
||||||
|
#include "config.h"
|
||||||
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
#include "flash.h"
|
||||||
|
#include "flash_eep.h"
|
||||||
|
#include "ble_ota.h"
|
||||||
|
|
||||||
|
#define MEMO_SEC_ID 0x55AAC0DE // sector head
|
||||||
|
#define FLASH_ADDR_START_MEMO ((FADDR_APP_SEC - FADDR_START_ADDR) + 0x20000 ) // + 128 kbytes
|
||||||
|
#define FLASH_ADDR_END_MEMO FMEMORY_SCFG_BASE_ADDR
|
||||||
|
|
||||||
|
typedef struct _memo_blk_t {
|
||||||
|
uint32_t time; // time (UTC)
|
||||||
|
int16_t temp; // x0.01 C
|
||||||
|
uint16_t humi; // x0.01 %
|
||||||
|
uint16_t vbat; // mV
|
||||||
|
}memo_blk_t, * pmemo_blk_t;
|
||||||
|
#define _memo_blk_size 10
|
||||||
|
|
||||||
|
typedef struct _memo_inf_t {
|
||||||
|
uint32_t faddr;
|
||||||
|
uint32_t cnt_cur_sec;
|
||||||
|
}memo_inf_t;
|
||||||
|
|
||||||
|
typedef struct _memo_rd_t {
|
||||||
|
memo_inf_t saved;
|
||||||
|
uint32_t cnt;
|
||||||
|
uint32_t cur;
|
||||||
|
}memo_rd_t;
|
||||||
|
|
||||||
|
typedef struct _memo_head_t {
|
||||||
|
uint32_t id; // = 0x55AAC0DE (MEMO_SEC_ID)
|
||||||
|
uint16_t flg; // = 0xffff - new sector, = 0 close sector
|
||||||
|
}memo_head_t;
|
||||||
|
#define _memo_head_size (4+2)
|
||||||
|
|
||||||
|
|
||||||
|
extern memo_rd_t rd_memo;
|
||||||
|
extern memo_inf_t memo;
|
||||||
|
|
||||||
|
void memo_init(void);
|
||||||
|
void clear_memo(void);
|
||||||
|
unsigned get_memo(uint32_t bnum, pmemo_blk_t p);
|
||||||
|
void write_memo(void);
|
||||||
|
int send_memo_blk(uint8_t * send_buf);
|
||||||
|
|
||||||
|
#endif // (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
#endif /* _LOGGER_H_ */
|
||||||
|
|
@ -321,7 +321,10 @@ int main(void) {
|
||||||
|
|
||||||
#if defined(OTA_TYPE) && OTA_TYPE == OTA_TYPE_BOOT
|
#if defined(OTA_TYPE) && OTA_TYPE == OTA_TYPE_BOOT
|
||||||
if (read_reg(OTA_MODE_SELECT_REG) != 0x55
|
if (read_reg(OTA_MODE_SELECT_REG) != 0x55
|
||||||
&& hal_gpio_read(GPIO_KEY) ) {
|
#if (DEV_SERVICES & SERVICE_KEY)
|
||||||
|
&& hal_gpio_read(GPIO_KEY)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
spif_config(SYS_CLK_DLL_64M, 1, XFRD_FCMD_READ_DUAL, 0, 0);
|
spif_config(SYS_CLK_DLL_64M, 1, XFRD_FCMD_READ_DUAL, 0, 0);
|
||||||
AP_PCR->CACHE_BYPASS = 1; // just bypass cache
|
AP_PCR->CACHE_BYPASS = 1; // just bypass cache
|
||||||
startup_app();
|
startup_app();
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,9 @@
|
||||||
#include "thb2_peripheral.h"
|
#include "thb2_peripheral.h"
|
||||||
#include "bleperipheral.h"
|
#include "bleperipheral.h"
|
||||||
#include "sbp_profile.h"
|
#include "sbp_profile.h"
|
||||||
#include "cmd_parcer.h"
|
#include "cmd_parser.h"
|
||||||
#include "ble_ota.h"
|
#include "ble_ota.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
@ -65,7 +66,7 @@ CONST uint8_t simpleProfilechar2UUID[ATT_BT_UUID_SIZE] =
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* EXTERNAL VARIABLES
|
* EXTERNAL VARIABLES
|
||||||
*/
|
*/
|
||||||
|
extern gapPeriConnectParams_t periConnParameters;
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* EXTERNAL FUNCTIONS
|
* EXTERNAL FUNCTIONS
|
||||||
*/
|
*/
|
||||||
|
|
@ -444,9 +445,9 @@ static void simpleProfile_HandleConnStatusCB( uint16_t connHandle, uint8_t chang
|
||||||
|
|
||||||
void new_cmd_data(void) {
|
void new_cmd_data(void) {
|
||||||
attHandleValueNoti_t noti;
|
attHandleValueNoti_t noti;
|
||||||
noti.handle = simpleProfileAttrTbl[CDM_DATA_ATTR_IDX].handle;
|
|
||||||
noti.len = cmd_parser(noti.value, cmd_in_buffer, cmd_in_len);
|
noti.len = cmd_parser(noti.value, cmd_in_buffer, cmd_in_len);
|
||||||
if(noti.len) {
|
if(noti.len) {
|
||||||
|
noti.handle = simpleProfileAttrTbl[CDM_DATA_ATTR_IDX].handle;
|
||||||
GATT_Notification(gapRole_ConnectionHandle, ¬i, FALSE );
|
GATT_Notification(gapRole_ConnectionHandle, ¬i, FALSE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -454,10 +455,31 @@ void new_cmd_data(void) {
|
||||||
#if OTA_TYPE
|
#if OTA_TYPE
|
||||||
void new_ota_data(void) {
|
void new_ota_data(void) {
|
||||||
attHandleValueNoti_t noti;
|
attHandleValueNoti_t noti;
|
||||||
noti.handle = simpleProfileAttrTbl[OTA_DATA_ATTR_IDX].handle;
|
|
||||||
noti.len = ota_parser(noti.value, ota_in_buffer, ota_in_len);
|
noti.len = ota_parser(noti.value, ota_in_buffer, ota_in_len);
|
||||||
if(noti.len) {
|
if(noti.len) {
|
||||||
|
noti.handle = simpleProfileAttrTbl[OTA_DATA_ATTR_IDX].handle;
|
||||||
GATT_Notification(gapRole_ConnectionHandle, ¬i, FALSE );
|
GATT_Notification(gapRole_ConnectionHandle, ¬i, FALSE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void wrk_notify(void) {
|
||||||
|
gattServerInfo_t* pServer;
|
||||||
|
attHandleValueNoti_t noti;
|
||||||
|
if (gattGetServerStatus( gapRole_ConnectionHandle, &pServer ) != bleTimeout) {
|
||||||
|
noti.len = 0;
|
||||||
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
// if(rd_memo.cnt)
|
||||||
|
noti.len = send_memo_blk(noti.value);
|
||||||
|
#endif
|
||||||
|
if(noti.len) {
|
||||||
|
noti.handle = simpleProfileAttrTbl[CDM_DATA_ATTR_IDX].handle;
|
||||||
|
if(ATT_HandleValueNoti(gapRole_ConnectionHandle, ¬i) != SUCCESS || noti.len <= 3)
|
||||||
|
return;
|
||||||
|
osal_set_event(simpleBLEPeripheral_TaskID, WRK_NOTIFY_EVT);
|
||||||
|
} else
|
||||||
|
return;
|
||||||
|
} else
|
||||||
|
osal_start_timerEx(simpleBLEPeripheral_TaskID, WRK_NOTIFY_EVT, 30);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ extern bStatus_t SimpleProfile_AddService( uint32_t services );
|
||||||
|
|
||||||
void new_cmd_data(void);
|
void new_cmd_data(void);
|
||||||
void new_ota_data(void);
|
void new_ota_data(void);
|
||||||
|
void wrk_notify(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@
|
||||||
#ifndef _SENSORS_H_
|
#ifndef _SENSORS_H_
|
||||||
#define _SENSORS_H_
|
#define _SENSORS_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "config.h"
|
||||||
|
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
|
|
||||||
// Timing
|
// Timing
|
||||||
#define SENSOR_POWER_TIMEOUT_ms 3
|
#define SENSOR_POWER_TIMEOUT_ms 3
|
||||||
|
|
@ -120,7 +122,6 @@ struct __attribute__((packed)) _cht8305_config_t{
|
||||||
#define AHT2x_DATA_TMS 0x3300 // Trigger Measurement data
|
#define AHT2x_DATA_TMS 0x3300 // Trigger Measurement data
|
||||||
#define AHT2x_CMD_RST 0x0BA // Soft Reset Command
|
#define AHT2x_CMD_RST 0x0BA // Soft Reset Command
|
||||||
|
|
||||||
|
|
||||||
typedef struct _measured_data_t {
|
typedef struct _measured_data_t {
|
||||||
uint16_t count;
|
uint16_t count;
|
||||||
int16_t temp; // x 0.01 C
|
int16_t temp; // x 0.01 C
|
||||||
|
|
@ -156,9 +157,19 @@ void init_sensor(void);
|
||||||
void start_measure(void);
|
void start_measure(void);
|
||||||
int read_sensor(void);
|
int read_sensor(void);
|
||||||
|
|
||||||
void init_i2c(bool speed400khz);
|
#else // (DEV_SERVICES & SERVICE_THS)
|
||||||
void deinit_i2c(void);
|
|
||||||
int send_i2c_byte(uint8 addr, uint8 data);
|
|
||||||
|
|
||||||
|
typedef struct _measured_data_t {
|
||||||
|
uint16_t count;
|
||||||
|
// int16_t temp; // x 0.01 C
|
||||||
|
// int16_t humi; // x 0.01 %
|
||||||
|
uint16_t battery_mv; // mV
|
||||||
|
uint8_t battery; // 0..100 %
|
||||||
|
} measured_data_t;
|
||||||
|
|
||||||
|
extern measured_data_t measured_data;
|
||||||
|
|
||||||
|
|
||||||
|
#endif // (DEV_SERVICES & SERVICE_THS)
|
||||||
|
|
||||||
#endif // _SENSORS_H_
|
#endif // _SENSORS_H_
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,18 @@
|
||||||
Author: pvvx
|
Author: pvvx
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "sensor.h"
|
||||||
|
|
||||||
|
measured_data_t measured_data;
|
||||||
|
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
#include "OSAL.h"
|
#include "OSAL.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "rom_sym_def.h"
|
#include "rom_sym_def.h"
|
||||||
#include "i2c.h"
|
#include "dev_i2c.h"
|
||||||
#include "sensor.h"
|
|
||||||
|
|
||||||
#define SET_I2C_SPEED 400 // 100 or 400 kHz
|
|
||||||
#define I2C_WAIT_ms 1
|
|
||||||
|
|
||||||
measured_data_t measured_data;
|
|
||||||
thsensor_cfg_t thsensor_cfg;
|
thsensor_cfg_t thsensor_cfg;
|
||||||
|
|
||||||
const thsensor_coef_t def_thcoef_cht8310 = {
|
const thsensor_coef_t def_thcoef_cht8310 = {
|
||||||
|
|
@ -38,172 +38,6 @@ const thsensor_coef_t def_thcoef_aht30 = {
|
||||||
.humi_z = 0
|
.humi_z = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_i2c(bool speed400khz) {
|
|
||||||
hal_gpio_fmux_set(I2C_SCL, FMUX_IIC0_SCL);
|
|
||||||
hal_gpio_fmux_set(I2C_SDA, FMUX_IIC0_SDA);
|
|
||||||
|
|
||||||
//hal_i2c_init(I2C_0, I2C_CLOCK_400K):
|
|
||||||
|
|
||||||
int pclk = clk_get_pclk();
|
|
||||||
|
|
||||||
AP_I2C_TypeDef* pi2cdev = AP_I2C0;
|
|
||||||
hal_clk_gate_enable(MOD_I2C0);
|
|
||||||
pi2cdev->IC_ENABLE = 0;
|
|
||||||
pi2cdev->IC_CON = 0x61;
|
|
||||||
if(speed400khz) {
|
|
||||||
// SET_I2C_SPEED 400 kHz
|
|
||||||
pi2cdev->IC_CON = ((pi2cdev->IC_CON) & 0xfffffff9) | (0x02 << 1); // SPEED_FAST
|
|
||||||
if (pclk == 16000000) {
|
|
||||||
pi2cdev->IC_FS_SCL_HCNT = 10;
|
|
||||||
pi2cdev->IC_FS_SCL_LCNT = 17;
|
|
||||||
} else if (pclk == 32000000) {
|
|
||||||
pi2cdev->IC_FS_SCL_HCNT = 30;
|
|
||||||
pi2cdev->IC_FS_SCL_LCNT = 35;
|
|
||||||
} else if (pclk == 48000000) {
|
|
||||||
pi2cdev->IC_FS_SCL_HCNT = 48;
|
|
||||||
pi2cdev->IC_FS_SCL_LCNT = 54;
|
|
||||||
} else if (pclk == 64000000) {
|
|
||||||
pi2cdev->IC_FS_SCL_HCNT = 67;
|
|
||||||
pi2cdev->IC_FS_SCL_LCNT = 75;
|
|
||||||
} else if (pclk == 96000000) {
|
|
||||||
pi2cdev->IC_FS_SCL_HCNT = 105;
|
|
||||||
pi2cdev->IC_FS_SCL_LCNT = 113;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// SET_I2C_SPEED 100 kHz
|
|
||||||
pi2cdev->IC_CON = ((pi2cdev->IC_CON) & 0xfffffff9) | (0x01 << 1); // SPEED_STANDARD
|
|
||||||
if (pclk == 16000000) {
|
|
||||||
pi2cdev->IC_SS_SCL_HCNT = 70; //16
|
|
||||||
pi2cdev->IC_SS_SCL_LCNT = 76; //32)
|
|
||||||
} else if (pclk == 32000000) {
|
|
||||||
pi2cdev->IC_SS_SCL_HCNT = 148; //16
|
|
||||||
pi2cdev->IC_SS_SCL_LCNT = 154; //32)
|
|
||||||
} else if (pclk == 48000000) {
|
|
||||||
pi2cdev->IC_SS_SCL_HCNT = 230; //16
|
|
||||||
pi2cdev->IC_SS_SCL_LCNT = 236; //32)
|
|
||||||
} else if (pclk == 64000000) {
|
|
||||||
pi2cdev->IC_SS_SCL_HCNT = 307; //16
|
|
||||||
pi2cdev->IC_SS_SCL_LCNT = 320; //32)
|
|
||||||
} else if (pclk == 96000000) {
|
|
||||||
pi2cdev->IC_SS_SCL_HCNT = 460; //16
|
|
||||||
pi2cdev->IC_SS_SCL_LCNT = 470; //32)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// pi2cdev->IC_TAR = I2C_MASTER_ADDR_DEF;
|
|
||||||
pi2cdev->IC_INTR_MASK = 0;
|
|
||||||
pi2cdev->IC_RX_TL = 0x0;
|
|
||||||
pi2cdev->IC_TX_TL = 0x1;
|
|
||||||
// pi2cdev->IC_ENABLE = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void deinit_i2c(void) {
|
|
||||||
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
|
||||||
pi2cdev->IC_ENABLE = 0;
|
|
||||||
hal_clk_gate_disable(MOD_I2C0);
|
|
||||||
hal_gpio_pin_init(I2C_SCL, IE);
|
|
||||||
hal_gpio_pin_init(I2C_SDA, IE);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern volatile uint32 osal_sys_tick;
|
|
||||||
|
|
||||||
/* size max = 7 ! */
|
|
||||||
int read_i2c_bytes(uint8 addr, uint8 reg, uint8 * data, uint8 size) {
|
|
||||||
int i = size;
|
|
||||||
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
|
||||||
pi2cdev->IC_ENABLE = 0;
|
|
||||||
pi2cdev->IC_TAR = addr;
|
|
||||||
|
|
||||||
HAL_ENTER_CRITICAL_SECTION();
|
|
||||||
|
|
||||||
pi2cdev->IC_ENABLE = 1;
|
|
||||||
pi2cdev->IC_DATA_CMD = reg;
|
|
||||||
//while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
|
||||||
while(i--)
|
|
||||||
pi2cdev->IC_DATA_CMD = 0x100;
|
|
||||||
|
|
||||||
HAL_EXIT_CRITICAL_SECTION();
|
|
||||||
|
|
||||||
uint32 to = osal_sys_tick;
|
|
||||||
i = size;
|
|
||||||
while(i) {
|
|
||||||
if(pi2cdev->IC_STATUS & 0x08) { // fifo not empty
|
|
||||||
*data = pi2cdev->IC_DATA_CMD & 0xff;
|
|
||||||
data++;
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
if(osal_sys_tick - to > I2C_WAIT_ms)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int read_noreg_i2c_bytes(uint8 addr, uint8 * data, uint8 size) {
|
|
||||||
int i = size;
|
|
||||||
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
|
||||||
pi2cdev->IC_ENABLE = 0;
|
|
||||||
pi2cdev->IC_TAR = addr;
|
|
||||||
|
|
||||||
HAL_ENTER_CRITICAL_SECTION();
|
|
||||||
pi2cdev->IC_ENABLE = 1;
|
|
||||||
while(i--)
|
|
||||||
pi2cdev->IC_DATA_CMD = 0x100;
|
|
||||||
|
|
||||||
HAL_EXIT_CRITICAL_SECTION();
|
|
||||||
|
|
||||||
uint32 to = osal_sys_tick;
|
|
||||||
i = size;
|
|
||||||
while(i) {
|
|
||||||
if(pi2cdev->IC_STATUS & 0x08) { // fifo not empty
|
|
||||||
*data = pi2cdev->IC_DATA_CMD & 0xff;
|
|
||||||
data++;
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
if(osal_sys_tick - to > I2C_WAIT_ms)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int send_i2c_byte(uint8 addr, uint8 data) {
|
|
||||||
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
|
||||||
pi2cdev->IC_ENABLE = 0;
|
|
||||||
pi2cdev->IC_TAR = addr;
|
|
||||||
HAL_ENTER_CRITICAL_SECTION();
|
|
||||||
pi2cdev->IC_ENABLE = 1;
|
|
||||||
pi2cdev->IC_DATA_CMD = data;
|
|
||||||
// while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
|
||||||
HAL_EXIT_CRITICAL_SECTION();
|
|
||||||
uint32 to = osal_sys_tick;
|
|
||||||
while(1) {
|
|
||||||
if(pi2cdev->IC_RAW_INTR_STAT & 0x200)// check tx empty
|
|
||||||
break;
|
|
||||||
if(osal_sys_tick - to > I2C_WAIT_ms)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int send_i2c_wreg(uint8 addr, uint8 reg, uint16 data) {
|
|
||||||
AP_I2C_TypeDef * pi2cdev = AP_I2C0;
|
|
||||||
pi2cdev->IC_ENABLE = 0;
|
|
||||||
pi2cdev->IC_TAR = addr;
|
|
||||||
HAL_ENTER_CRITICAL_SECTION();
|
|
||||||
pi2cdev->IC_ENABLE = 1;
|
|
||||||
pi2cdev->IC_DATA_CMD = reg;
|
|
||||||
while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
|
||||||
pi2cdev->IC_DATA_CMD = (data >> 8) & 0xff;
|
|
||||||
while(!(pi2cdev->IC_RAW_INTR_STAT & 0x10));
|
|
||||||
pi2cdev->IC_DATA_CMD = data & 0xff;
|
|
||||||
HAL_EXIT_CRITICAL_SECTION();
|
|
||||||
uint32 to = osal_sys_tick;
|
|
||||||
while(1) {
|
|
||||||
if(pi2cdev->IC_RAW_INTR_STAT & 0x200)// check tx empty
|
|
||||||
break;
|
|
||||||
if(osal_sys_tick - to > I2C_WAIT_ms)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int read_sensor_cht83xx(void) {
|
int read_sensor_cht83xx(void) {
|
||||||
uint8 reg_data[4];
|
uint8 reg_data[4];
|
||||||
|
|
@ -233,7 +67,7 @@ int read_sensor_ahtxx(void) {
|
||||||
uint32_t _temp;
|
uint32_t _temp;
|
||||||
uint8 reg_data[8];
|
uint8 reg_data[8];
|
||||||
init_i2c(1);
|
init_i2c(1);
|
||||||
if(!read_noreg_i2c_bytes(thsensor_cfg.i2c_addr, reg_data, 7)
|
if(!read_i2c_nabuf(thsensor_cfg.i2c_addr, reg_data, 7)
|
||||||
&& (reg_data[0] & 0x80) == 0) { // busy
|
&& (reg_data[0] & 0x80) == 0) { // busy
|
||||||
deinit_i2c();
|
deinit_i2c();
|
||||||
_temp = ((reg_data[3] & 0x0F) << 16) | (reg_data[4] << 8) | reg_data[5];
|
_temp = ((reg_data[3] & 0x0F) << 16) | (reg_data[4] << 8) | reg_data[5];
|
||||||
|
|
@ -300,7 +134,7 @@ __ATTR_SECTION_XIP__ void init_sensor(void) {
|
||||||
// Configure
|
// Configure
|
||||||
send_i2c_wreg(thsensor_cfg.i2c_addr, CHT8305_REG_CFG, CHT8305_CFG_MODE );
|
send_i2c_wreg(thsensor_cfg.i2c_addr, CHT8305_REG_CFG, CHT8305_CFG_MODE );
|
||||||
#endif */
|
#endif */
|
||||||
if(adv_wrk.measure_interval_ms >= 5000) // > 5 sec
|
if(adv_wrk.measure_interval_ms >= 5050) // > 5 sec
|
||||||
send_i2c_wreg(CHT8315_I2C_ADDR0, CHT8315_REG_CRT, 0x0300); // Set conversion ratio 5 sec
|
send_i2c_wreg(CHT8315_I2C_ADDR0, CHT8315_REG_CRT, 0x0300); // Set conversion ratio 5 sec
|
||||||
// else 1 sec
|
// else 1 sec
|
||||||
thsensor_cfg.read_sensor = read_sensor_cht83xx;
|
thsensor_cfg.read_sensor = read_sensor_cht83xx;
|
||||||
|
|
@ -313,6 +147,7 @@ __ATTR_SECTION_XIP__ void init_sensor(void) {
|
||||||
if(!send_i2c_wreg(thsensor_cfg.i2c_addr, AHT2x_CMD_TMS, AHT2x_DATA_TMS)) {
|
if(!send_i2c_wreg(thsensor_cfg.i2c_addr, AHT2x_CMD_TMS, AHT2x_DATA_TMS)) {
|
||||||
ptabinit = (uint8_t *)&def_thcoef_aht30;
|
ptabinit = (uint8_t *)&def_thcoef_aht30;
|
||||||
thsensor_cfg.read_sensor = read_sensor_ahtxx;
|
thsensor_cfg.read_sensor = read_sensor_ahtxx;
|
||||||
|
thsensor_cfg.vid = 0xAAAA;
|
||||||
} else
|
} else
|
||||||
thsensor_cfg.i2c_addr = 0;
|
thsensor_cfg.i2c_addr = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -321,3 +156,5 @@ __ATTR_SECTION_XIP__ void init_sensor(void) {
|
||||||
}
|
}
|
||||||
deinit_i2c();
|
deinit_i2c();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // (DEV_SERVICES & SERVICE_THS)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#include "sbp_profile.h"
|
#include "sbp_profile.h"
|
||||||
#include "lcd_th05.h"
|
#include "lcd_th05.h"
|
||||||
|
#include "logger.h"
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* MACROS
|
* MACROS
|
||||||
*/
|
*/
|
||||||
|
|
@ -104,10 +105,16 @@ static void peripheralStateReadRssiCB( int8 rssi );
|
||||||
|
|
||||||
#if (DEV_SERVICES & SERVICE_SCREEN)
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
void chow_measure(void) {
|
void chow_measure(void) {
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
show_big_number_x10(measured_data.temp/10);
|
show_big_number_x10(measured_data.temp/10);
|
||||||
show_small_number(measured_data.humi/100, true);
|
show_small_number(measured_data.humi/100, true);
|
||||||
show_battery_symbol(measured_data.battery < 20);
|
show_battery_symbol(measured_data.battery < 20);
|
||||||
show_temp_symbol(3);
|
show_temp_symbol(3);
|
||||||
|
#else
|
||||||
|
show_big_number_x10(measured_data.battery_mv/100);
|
||||||
|
show_small_number(measured_data.battery, true);
|
||||||
|
show_battery_symbol(1);
|
||||||
|
#endif
|
||||||
show_smiley(0);
|
show_smiley(0);
|
||||||
show_ble_symbol(gapRole_state == GAPROLE_CONNECTED);
|
show_ble_symbol(gapRole_state == GAPROLE_CONNECTED);
|
||||||
update_lcd();
|
update_lcd();
|
||||||
|
|
@ -159,10 +166,18 @@ static void set_serial_number(void)
|
||||||
hal_get_flash_info();
|
hal_get_flash_info();
|
||||||
uint8_t *p = str_bin2hex(devInfoSerialNumber, (uint8_t *)&phy_flash.IdentificationID, 3);
|
uint8_t *p = str_bin2hex(devInfoSerialNumber, (uint8_t *)&phy_flash.IdentificationID, 3);
|
||||||
*p++ = '-';
|
*p++ = '-';
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
p = str_bin2hex(p, (uint8_t *)&thsensor_cfg.mid, 4);
|
p = str_bin2hex(p, (uint8_t *)&thsensor_cfg.mid, 4);
|
||||||
|
#else
|
||||||
|
p = str_bin2hex(p, (uint8_t *)FLASH_BASE_ADDR, 4);
|
||||||
|
#endif
|
||||||
*p++ = '-';
|
*p++ = '-';
|
||||||
|
#if (DEV_SERVICES & SERVICE_LCD)
|
||||||
|
p = str_bin2hex(p, (uint8_t *)&lcd_i2c_addr, 1);
|
||||||
|
#else
|
||||||
*p++ = '0';
|
*p++ = '0';
|
||||||
*p = '0';
|
*p = '0';
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern gapPeriConnectParams_t periConnParameters;
|
extern gapPeriConnectParams_t periConnParameters;
|
||||||
|
|
@ -183,14 +198,14 @@ static void set_adv_interval(uint16 advInt)
|
||||||
{
|
{
|
||||||
#ifdef __GCC
|
#ifdef __GCC
|
||||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MIN] = advInt;
|
gapParameters[TGAP_LIM_DISC_ADV_INT_MIN] = advInt;
|
||||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MAX] = advInt;
|
gapParameters[TGAP_LIM_DISC_ADV_INT_MAX] = advInt + 10;
|
||||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MIN] = advInt;
|
gapParameters[TGAP_GEN_DISC_ADV_INT_MIN] = advInt;
|
||||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MAX] = advInt;
|
gapParameters[TGAP_GEN_DISC_ADV_INT_MAX] = advInt + 10;
|
||||||
#else
|
#else
|
||||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
|
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
|
||||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
|
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt + 10);
|
||||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
|
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
|
||||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
|
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt + 10);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,21 +213,42 @@ static void set_adv_interval(uint16 advInt)
|
||||||
|
|
||||||
static void adv_measure(void) {
|
static void adv_measure(void) {
|
||||||
if(gapRole_AdvEnabled) {
|
if(gapRole_AdvEnabled) {
|
||||||
|
uint32_t tmp = get_utc_time_sec();
|
||||||
|
if(tmp - adv_wrk.measure_batt_tik >= cfg.batt_interval) {
|
||||||
|
adv_wrk.measure_batt_tik = tmp;
|
||||||
|
batt_start_measure();
|
||||||
|
#if ((DEV_SERVICES & SERVICE_THS) == 0)
|
||||||
|
adv_wrk.adv_batt = 1;
|
||||||
|
} else if(adv_wrk.adv_batt) {
|
||||||
|
adv_wrk.adv_batt = 0;
|
||||||
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
|
chow_measure();
|
||||||
|
#endif
|
||||||
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
if (cfg.averaging_measurements != 0)
|
||||||
|
write_memo();
|
||||||
|
#endif
|
||||||
|
bthome_data_beacon((void *) gapRole_AdvertData);
|
||||||
|
LL_SetAdvData(sizeof(adv_bthome_ns2_t), gapRole_AdvertData);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
if(adv_wrk.adv_count == (uint8_t)(cfg.measure_interval - 1)) {
|
if(adv_wrk.adv_count == (uint8_t)(cfg.measure_interval - 1)) {
|
||||||
start_measure();
|
start_measure();
|
||||||
} else if(adv_wrk.adv_count >= cfg.measure_interval) {
|
} else if(adv_wrk.adv_count >= cfg.measure_interval) {
|
||||||
adv_wrk.adv_count = 0;
|
adv_wrk.adv_count = 0;
|
||||||
read_sensor();
|
read_sensor();
|
||||||
if(++adv_wrk.adv_batt_count >= cfg.batt_interval) { // = 60
|
|
||||||
adv_wrk.adv_batt_count = 0;
|
|
||||||
batt_start_measure();
|
|
||||||
}
|
|
||||||
#if (DEV_SERVICES & SERVICE_SCREEN)
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
chow_measure();
|
chow_measure();
|
||||||
#endif
|
#endif
|
||||||
bthome_data_beacon((padv_bthome_ns1_t) gapRole_AdvertData);
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
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(sizeof(adv_bthome_ns1_t), gapRole_AdvertData);
|
||||||
}
|
}
|
||||||
|
#endif // (DEV_SERVICES & SERVICE_THS)
|
||||||
if(adv_wrk.adv_con_count) {
|
if(adv_wrk.adv_con_count) {
|
||||||
if(--adv_wrk.adv_con_count == 0) {
|
if(--adv_wrk.adv_con_count == 0) {
|
||||||
set_new_adv_interval(cfg.advertising_interval * 100);
|
set_new_adv_interval(cfg.advertising_interval * 100);
|
||||||
|
|
@ -222,6 +258,7 @@ static void adv_measure(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (DEV_SERVICES & SERVICE_KEY)
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* LED and Key
|
* LED and Key
|
||||||
*/
|
*/
|
||||||
|
|
@ -260,10 +297,11 @@ static void negedge_int_wakeup_cb(GPIO_Pin_e pin, IO_Wakeup_Pol_e type)
|
||||||
LOG("error\n");
|
LOG("error\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // (DEV_SERVICES & SERVICE_KEY)
|
||||||
|
|
||||||
void init_led_key(void)
|
static void init_app_gpio(void)
|
||||||
{
|
{
|
||||||
#ifdef GPIO_KEY
|
#if (DEV_SERVICES & SERVICE_KEY)
|
||||||
hal_gpioin_register(GPIO_KEY, posedge_int_wakeup_cb, negedge_int_wakeup_cb);
|
hal_gpioin_register(GPIO_KEY, posedge_int_wakeup_cb, negedge_int_wakeup_cb);
|
||||||
#endif
|
#endif
|
||||||
#ifdef GPIO_LED
|
#ifdef GPIO_LED
|
||||||
|
|
@ -348,14 +386,14 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
||||||
{
|
{
|
||||||
simpleBLEPeripheral_TaskID = task_id;
|
simpleBLEPeripheral_TaskID = task_id;
|
||||||
|
|
||||||
init_led_key();
|
init_app_gpio();
|
||||||
|
|
||||||
#if (DEV_SERVICES & SERVICE_SCREEN)
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
init_lcd();
|
init_lcd();
|
||||||
#endif
|
#endif
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
init_sensor();
|
init_sensor();
|
||||||
|
#endif
|
||||||
set_serial_number();
|
set_serial_number();
|
||||||
|
|
||||||
// Setup the GAP
|
// Setup the GAP
|
||||||
|
|
@ -367,7 +405,6 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
||||||
|
|
||||||
// Setup the GAP Peripheral Role Profile
|
// Setup the GAP Peripheral Role Profile
|
||||||
{
|
{
|
||||||
|
|
||||||
set_mac();
|
set_mac();
|
||||||
// gapRole_AdvEventType = LL_ADV_CONNECTABLE_UNDIRECTED_EVT; // already set default
|
// gapRole_AdvEventType = LL_ADV_CONNECTABLE_UNDIRECTED_EVT; // already set default
|
||||||
// gapRole_AdvDirectAddr[B_ADDR_LEN] = {1,2,3,4,5,6}; // already set default
|
// gapRole_AdvDirectAddr[B_ADDR_LEN] = {1,2,3,4,5,6}; // already set default
|
||||||
|
|
@ -423,7 +460,9 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
||||||
GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes
|
GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes
|
||||||
DevInfo_AddService(); // Device Information Service
|
DevInfo_AddService(); // Device Information Service
|
||||||
Batt_AddService();
|
Batt_AddService();
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
TH_AddService();
|
TH_AddService();
|
||||||
|
#endif
|
||||||
SimpleProfile_AddService( GATT_ALL_SERVICES ); // Simple GATT Profile
|
SimpleProfile_AddService( GATT_ALL_SERVICES ); // Simple GATT Profile
|
||||||
|
|
||||||
#if (1)
|
#if (1)
|
||||||
|
|
@ -477,16 +516,14 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
||||||
uint16 BLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
uint16 BLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
||||||
{
|
{
|
||||||
VOID task_id; // OSAL required parameter that isn't used in this function
|
VOID task_id; // OSAL required parameter that isn't used in this function
|
||||||
if ( events & ADV_BROADCAST_EVT)
|
if ( events & ADV_BROADCAST_EVT) {
|
||||||
{
|
|
||||||
adv_measure();
|
adv_measure();
|
||||||
LOG("advN%u\n", adv_wrk.adv_count);
|
LOG("advN%u\n", adv_wrk.adv_count);
|
||||||
// return unprocessed events
|
// return unprocessed events
|
||||||
return (events ^ ADV_BROADCAST_EVT);
|
return (events ^ ADV_BROADCAST_EVT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( events & SYS_EVENT_MSG )
|
if ( events & SYS_EVENT_MSG ) {
|
||||||
{
|
|
||||||
uint8 *pMsg;
|
uint8 *pMsg;
|
||||||
|
|
||||||
if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL )
|
if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL )
|
||||||
|
|
@ -501,43 +538,54 @@ uint16 BLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable adv (from gaprole start)
|
// enable adv (from gaprole start)
|
||||||
if ( events & SBP_RESET_ADV_EVT )
|
if ( events & SBP_RESET_ADV_EVT ) {
|
||||||
{
|
|
||||||
LOG("SBP_RESET_ADV_EVT\n");
|
LOG("SBP_RESET_ADV_EVT\n");
|
||||||
adv_wrk.adv_count = 0;
|
adv_wrk.adv_count = 0;
|
||||||
// set_new_adv_interval(DEF_ADV_INERVAL); // actual time = advInt * 625us
|
// set_new_adv_interval(DEF_ADV_INERVAL); // actual time = advInt * 625us
|
||||||
gatrole_advert_enable(TRUE);
|
gatrole_advert_enable(TRUE);
|
||||||
return ( events ^ SBP_RESET_ADV_EVT );
|
return ( events ^ SBP_RESET_ADV_EVT );
|
||||||
}
|
}
|
||||||
if( events & TIMER_BATT_EVT)
|
if( events & TIMER_BATT_EVT) {
|
||||||
{
|
|
||||||
LOG("TIMER_EVT\n");
|
LOG("TIMER_EVT\n");
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
|
uint32_t tmp = get_utc_time_sec();
|
||||||
|
if(tmp - adv_wrk.measure_batt_tik >= cfg.batt_interval) {
|
||||||
|
adv_wrk.measure_batt_tik = tmp;
|
||||||
|
batt_start_measure();
|
||||||
|
}
|
||||||
read_sensor();
|
read_sensor();
|
||||||
start_measure();
|
start_measure();
|
||||||
#if (DEV_SERVICES & SERVICE_SCREEN)
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
chow_measure();
|
chow_measure();
|
||||||
|
#endif
|
||||||
|
#if (DEV_SERVICES & SERVICE_HISTORY)
|
||||||
|
if (cfg.averaging_measurements != 0)
|
||||||
|
write_memo();
|
||||||
#endif
|
#endif
|
||||||
// TH Notify
|
// TH Notify
|
||||||
TH_NotifyLevel();
|
TH_NotifyLevel();
|
||||||
if(++adv_wrk.adv_batt_count >= cfg.batt_interval) { // 60 sec
|
#else
|
||||||
adv_wrk.adv_batt_count = 0;
|
get_utc_time_sec();
|
||||||
batt_start_measure();
|
batt_start_measure();
|
||||||
}
|
#endif // (DEV_SERVICES & SERVICE_THS)
|
||||||
// return unprocessed events
|
// return unprocessed events
|
||||||
return ( events ^ TIMER_BATT_EVT);
|
return ( events ^ TIMER_BATT_EVT);
|
||||||
}
|
}
|
||||||
if( events & BATT_VALUE_EVT)
|
if( events & BATT_VALUE_EVT) {
|
||||||
{
|
|
||||||
LOG("Vbat: %d mV, %d %%\n", measured_data.battery_mv, measured_data.battery);
|
LOG("Vbat: %d mV, %d %%\n", measured_data.battery_mv, measured_data.battery);
|
||||||
// Batt Notify
|
// Batt Notify
|
||||||
if(!gapRole_AdvEnabled) {
|
if(!gapRole_AdvEnabled) {
|
||||||
BattNotifyLevel();
|
BattNotifyLevel();
|
||||||
|
#if ((DEV_SERVICES & SERVICE_THS)==0)
|
||||||
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
|
chow_measure();
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// return unprocessed events
|
// return unprocessed events
|
||||||
return ( events ^ BATT_VALUE_EVT);
|
return ( events ^ BATT_VALUE_EVT);
|
||||||
}
|
}
|
||||||
if ( events & SBP_START_DEVICE_EVT )
|
if ( events & SBP_START_DEVICE_EVT ) {
|
||||||
{
|
|
||||||
// Start the Device
|
// Start the Device
|
||||||
VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );
|
VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );
|
||||||
#if (DEF_GAPBOND_MGR_ENABLE==1)
|
#if (DEF_GAPBOND_MGR_ENABLE==1)
|
||||||
|
|
@ -556,22 +604,17 @@ uint16 BLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
||||||
// return unprocessed events
|
// return unprocessed events
|
||||||
return ( events ^ SBP_START_DEVICE_EVT );
|
return ( events ^ SBP_START_DEVICE_EVT );
|
||||||
}
|
}
|
||||||
if(events & SBP_CMDDATA)
|
if(events & WRK_NOTIFY_EVT) {
|
||||||
{
|
LOG("Wrk notify events\n");
|
||||||
|
wrk_notify();
|
||||||
|
return(events ^ WRK_NOTIFY_EVT);
|
||||||
|
}
|
||||||
|
if(events & SBP_CMDDATA) {
|
||||||
LOG("CMD data events\n");
|
LOG("CMD data events\n");
|
||||||
new_cmd_data();
|
new_cmd_data();
|
||||||
// return unprocessed events
|
// return unprocessed events
|
||||||
return(events ^ SBP_CMDDATA);
|
return(events ^ SBP_CMDDATA);
|
||||||
}
|
}
|
||||||
#if 0 // OTA_TYPE
|
|
||||||
if(events & SBP_OTADATA)
|
|
||||||
{
|
|
||||||
LOG("OTA data events\n");
|
|
||||||
new_ota_data();
|
|
||||||
// return unprocessed events
|
|
||||||
return(events ^ SBP_OTADATA);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// Discard unknown events
|
// Discard unknown events
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -654,8 +697,12 @@ static void peripheralStateReadRssiCB( int8 rssi )
|
||||||
case GAPROLE_CONNECTED:
|
case GAPROLE_CONNECTED:
|
||||||
adv_wrk.adv_count = 0;
|
adv_wrk.adv_count = 0;
|
||||||
adv_wrk.adv_con_count = 0;
|
adv_wrk.adv_con_count = 0;
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
osal_start_reload_timer(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT, adv_wrk.measure_interval_ms); // 10000 ms
|
osal_start_reload_timer(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT, adv_wrk.measure_interval_ms); // 10000 ms
|
||||||
HCI_PPLUS_ConnEventDoneNoticeCmd(simpleBLEPeripheral_TaskID, NULL);
|
#else
|
||||||
|
osal_start_reload_timer(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT, cfg.batt_interval*1000);
|
||||||
|
#endif
|
||||||
|
HCI_PPLUS_ConnEventDoneNoticeCmd(simpleBLEPeripheral_TaskID, 0);
|
||||||
LOG("Gaprole_Connected\n");
|
LOG("Gaprole_Connected\n");
|
||||||
#if (DEV_SERVICES & SERVICE_SCREEN)
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
show_ble_symbol(1);
|
show_ble_symbol(1);
|
||||||
|
|
@ -669,9 +716,11 @@ static void peripheralStateReadRssiCB( int8 rssi )
|
||||||
|
|
||||||
case GAPROLE_WAITING:
|
case GAPROLE_WAITING:
|
||||||
LOG("Gaprole_Disconnection\n");
|
LOG("Gaprole_Disconnection\n");
|
||||||
adv_wrk.adv_con_count = 1;
|
|
||||||
osal_stop_timerEx(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT);
|
osal_stop_timerEx(simpleBLEPeripheral_TaskID, TIMER_BATT_EVT);
|
||||||
|
bthome_data_beacon((void *) gapRole_AdvertData);
|
||||||
|
gapRole_SlaveLatency = periConnParameters.latency = cfg.connect_latency;
|
||||||
adv_wrk.adv_count = 0;
|
adv_wrk.adv_count = 0;
|
||||||
|
adv_wrk.adv_con_count = 1;
|
||||||
#if (DEV_SERVICES & SERVICE_SCREEN)
|
#if (DEV_SERVICES & SERVICE_SCREEN)
|
||||||
show_ble_symbol(0);
|
show_ble_symbol(0);
|
||||||
update_lcd();
|
update_lcd();
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
INCLUDES
|
INCLUDES
|
||||||
*/
|
*/
|
||||||
#include "bcomdef.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "config.h"
|
||||||
|
#if (DEV_SERVICES & SERVICE_THS)
|
||||||
|
#include "bcomdef.h"
|
||||||
#include "OSAL.h"
|
#include "OSAL.h"
|
||||||
#include "linkdb.h"
|
#include "linkdb.h"
|
||||||
#include "att.h"
|
#include "att.h"
|
||||||
|
|
@ -386,3 +388,5 @@ void TH_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // (DEV_SERVICES & SERVICE_THS)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue