add config.h, clean code...
This commit is contained in:
parent
70f62b3a21
commit
8b77d51a88
22 changed files with 246 additions and 220 deletions
|
|
@ -14,7 +14,7 @@
|
|||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.28719871" name="Default" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.dockerdpath=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.28719871" name="Default" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.dockerdpath=,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=" parent="org.eclipse.cdt.build.core.emptycfg">
|
||||
<folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.28719871.266191087" name="/" resourcePath="">
|
||||
<toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.321694806" name="Arm Cross GCC" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base">
|
||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.2086137351" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/>
|
||||
|
|
@ -95,20 +95,23 @@
|
|||
<builder buildPath="${workspace_loc:/${ProjName}}/" enableAutoBuild="false" id="ilg.gnuarmeclipse.managedbuild.cross.builder.214507476" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnuarmeclipse.managedbuild.cross.builder"/>
|
||||
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.521605472" name="GNU Arm Cross Assembler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler">
|
||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor.832172772" name="Use preprocessor" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor" value="true" valueType="boolean"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs.424614369" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="USE_ROMSYM_ALIAS=1"/>
|
||||
<listOptionValue builtIn="false" value="__GCC"/>
|
||||
</option>
|
||||
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input.598587326" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.1775991431" name="GNU Arm Cross C Compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.1576445581" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""D:\MCU\GNU_Tools_ARM_Embedded\10.2021.10\arm-none-eabi\include""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/source}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/led_light}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/profiles/ota_app}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/profiles/DevInfo}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/profiles/SimpleProfile}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/profiles/Roles}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/misc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/inc}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/clock}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/gpio}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/arch/cm0}""/>
|
||||
|
|
@ -159,12 +162,13 @@
|
|||
<listOptionValue builtIn="false" value="OBSERVER_CFG=0x02"/>
|
||||
<listOptionValue builtIn="false" value="PERIPHERAL_CFG=0x04"/>
|
||||
<listOptionValue builtIn="false" value="CENTRAL_CFG=0x08"/>
|
||||
<listOptionValue builtIn="false" value="USE_ROMSYM_ALIAS=1"/>
|
||||
<listOptionValue builtIn="false" value="__GCC"/>
|
||||
</option>
|
||||
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input.1659095882" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.1120283720" name="GNU Arm Cross C++ Compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler">
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.include.paths.1769584270" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""D:\MCU\GNU_Tools_ARM_Embedded\10.2021.10\arm-none-eabi\include""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/source}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/led_light}""/>
|
||||
|
|
@ -190,7 +194,6 @@
|
|||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/pwrmgr}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/timer}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/spi}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/libraries/fs}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/pwm}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/kscan}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/dma}""/>
|
||||
|
|
@ -198,6 +201,7 @@
|
|||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/spiflash}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/watchdog}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/driver/i2c}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/SDK/components/libraries/fs}""/>
|
||||
</option>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.defs.778573213" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="DEBUG_INFO=0"/>
|
||||
|
|
@ -224,6 +228,8 @@
|
|||
<listOptionValue builtIn="false" value="OBSERVER_CFG=0x02"/>
|
||||
<listOptionValue builtIn="false" value="PERIPHERAL_CFG=0x04"/>
|
||||
<listOptionValue builtIn="false" value="CENTRAL_CFG=0x08"/>
|
||||
<listOptionValue builtIn="false" value="USE_ROMSYM_ALIAS=1"/>
|
||||
<listOptionValue builtIn="false" value="__GCC"/>
|
||||
</option>
|
||||
<inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.input.1110288971" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.input"/>
|
||||
</tool>
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ static xflash_Ctx_t s_xflashCtx = {
|
|||
.spif_ref_clk = SYS_CLK_DLL_64M,
|
||||
.rd_instr = XFRD_FCMD_READ_DUAL };
|
||||
|
||||
chipMAddr_t g_chipMAddr;
|
||||
|
||||
__ATTR_SECTION_SRAM__ static inline uint32_t spif_lock() {
|
||||
HAL_ENTER_CRITICAL_SECTION();
|
||||
|
|
@ -150,7 +149,7 @@ FLASH_CHIP_INFO phy_flash = { .init_flag = FALSE, .IdentificationID = 0x00,
|
|||
|
||||
int hal_get_flash_info(void) {
|
||||
uint32_t cs;
|
||||
uint8_t data[17];
|
||||
uint8_t data[4];
|
||||
|
||||
if (phy_flash.init_flag == TRUE) {
|
||||
return PPlus_SUCCESS;
|
||||
|
|
@ -426,7 +425,7 @@ int flash_write_word(unsigned int offset, uint32_t value) {
|
|||
return (hal_flash_write(offset, (uint8_t*) &temp, 4));
|
||||
}
|
||||
|
||||
CHIP_ID_STATUS_e read_chip_mAddr(void) {
|
||||
CHIP_ID_STATUS_e read_chip_mAddr(uint8_t * mAddr) {
|
||||
CHIP_ID_STATUS_e ret = CHIP_ID_UNCHECK;
|
||||
uint8_t b;
|
||||
for (int i = 0; i < CHIP_MADDR_LEN; i++) {
|
||||
|
|
@ -434,19 +433,19 @@ CHIP_ID_STATUS_e read_chip_mAddr(void) {
|
|||
read_reg(CHIP_MADDR_FLASH_ADDRESS+(i<<2)));
|
||||
|
||||
if (ret == CHIP_ID_VALID) {
|
||||
g_chipMAddr.mAddr[CHIP_MADDR_LEN - 1 - i] = b;
|
||||
mAddr[CHIP_MADDR_LEN - 1 - i] = b;
|
||||
} else {
|
||||
if (i > 0 && ret == CHIP_ID_EMPTY) {
|
||||
ret = CHIP_ID_INVALID;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
void check_chip_mAddr(void) {
|
||||
//chip id check
|
||||
for (int i = 0; i < CHIP_MADDR_LEN; i++) {
|
||||
|
|
@ -474,3 +473,4 @@ void LOG_CHIP_MADDR(void) {
|
|||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ typedef enum
|
|||
CHIP_ID_INVALID,
|
||||
} CHIP_ID_STATUS_e;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CHIP_ID_STATUS_e chipMAddrStatus;
|
||||
|
|
@ -106,6 +107,7 @@ typedef struct
|
|||
uint32_t IdentificationID;
|
||||
uint32_t Capacity;
|
||||
} FLASH_CHIP_INFO;
|
||||
extern FLASH_CHIP_INFO phy_flash;
|
||||
|
||||
extern int _spif_wait_nobusy(uint8_t flg, uint32_t tout_ns);
|
||||
extern int spif_write(uint32_t addr, uint8_t* data, uint32_t size);
|
||||
|
|
@ -125,6 +127,7 @@ int hal_spif_cache_init(sysclk_t spif_ref_clk, uint32_t rd_instr);
|
|||
#if(FLASH_PROTECT_FEATURE == 1)
|
||||
int hal_flash_lock(void);
|
||||
int hal_flash_unlock(void);
|
||||
uint8_t hal_flash_get_lock_state(void);
|
||||
#endif
|
||||
int hal_flash_write(uint32_t addr, uint8_t* data, uint32_t size);
|
||||
int hal_flash_write_by_dma(uint32_t addr, uint8_t* data, uint32_t size);
|
||||
|
|
@ -133,21 +136,18 @@ int hal_flash_erase_sector(unsigned int addr);
|
|||
int hal_flash_erase_block64(unsigned int addr);
|
||||
int flash_write_word(unsigned int offset, uint32_t value);
|
||||
|
||||
#ifdef FLASH_PROTECT_FEATURE
|
||||
int hal_flash_lock(void);
|
||||
int hal_flash_unlock(void);
|
||||
uint8_t hal_flash_get_lock_state(void);
|
||||
#endif
|
||||
|
||||
CHIP_ID_STATUS_e chip_id_one_bit_hot_convter(uint8_t* b,uint32_t w);
|
||||
|
||||
void LL_PLUS_LoadMACFromFlash(uint32_t addr);
|
||||
|
||||
CHIP_ID_STATUS_e LL_PLUS_LoadMACFromChipMAddr(void);
|
||||
|
||||
CHIP_ID_STATUS_e read_chip_mAddr(uint8_t * mAddr);
|
||||
int hal_get_flash_info(void);
|
||||
|
||||
void check_chip_mAddr(void);
|
||||
void LOG_CHIP_MADDR(void);
|
||||
|
||||
//void check_chip_mAddr(void);
|
||||
//void LOG_CHIP_MADDR(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ static gapConfigLLParams_t gapParams;
|
|||
|
||||
// GAP settable parameters, these can be accessed through GAP_SetParamValue() and
|
||||
// GAP_GetParamValue() public APIs.
|
||||
static uint16 gapParameters[] =
|
||||
uint16 gapParameters[] =
|
||||
{
|
||||
// Default Timer values
|
||||
TGAP_GEN_DISC_ADV_MIN_DEFAULT,
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ extern struct buf_tx_desc tx_scanRsp_desc;
|
|||
|
||||
extern struct buf_rx_desc g_rx_adv_buf;
|
||||
|
||||
extern chipMAddr_t g_chipMAddr;
|
||||
//extern chipMAddr_t g_chipMAddr;
|
||||
|
||||
extern uint8 g_llAdvMode;
|
||||
extern uint32_t g_llHdcDirAdvTime;
|
||||
|
|
@ -8256,6 +8256,7 @@ hciStatus_t HCI_LE_ConnUpdateCmd( uint16 connHandle,
|
|||
return( HCI_SUCCESS );
|
||||
}
|
||||
|
||||
__ATTR_SECTION_XIP__
|
||||
CHIP_ID_STATUS_e chip_id_one_bit_hot_convter(uint8_t* b,uint32_t w)
|
||||
{
|
||||
uint16 dh = w>>16;
|
||||
|
|
@ -8341,6 +8342,7 @@ void LL_PLUS_LoadMACFromFlash(uint32_t addr)
|
|||
|
||||
@return CHIP_ID_STATUS_e.
|
||||
*/
|
||||
/*
|
||||
CHIP_ID_STATUS_e LL_PLUS_LoadMACFromChipMAddr(void)
|
||||
{
|
||||
check_chip_mAddr();
|
||||
|
|
@ -8354,6 +8356,7 @@ CHIP_ID_STATUS_e LL_PLUS_LoadMACFromChipMAddr(void)
|
|||
|
||||
return g_chipMAddr.chipMAddrStatus;
|
||||
}
|
||||
*/
|
||||
|
||||
extern const char* s_company_id;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,26 @@
|
|||
/**************************************************************************************************
|
||||
**************************************************************************************************/
|
||||
/*
|
||||
battery.c
|
||||
Author: pvvx
|
||||
*/
|
||||
#include "types.h"
|
||||
#include "config.h"
|
||||
#include "adc.h"
|
||||
#include "battery.h"
|
||||
#include "bleperipheral.h"
|
||||
#include "OSAL.h"
|
||||
#include "OSAL_Timers.h"
|
||||
#include "string.h"
|
||||
#include "gpio.h"
|
||||
#include "gpio.h"
|
||||
#include "error.h"
|
||||
#include "log.h"
|
||||
#include "pwrmgr.h"
|
||||
#include "clock.h"
|
||||
#include "adc.h"
|
||||
#include "jump_function.h"
|
||||
#include "version.h"
|
||||
#include "sensor.h"
|
||||
#include "rf_phy_driver.h"
|
||||
|
||||
#ifndef ADC_PIN
|
||||
#define ADC_PIN GPIO_P11
|
||||
#endif
|
||||
#ifndef ADC_CHL
|
||||
#define ADC_CHL ADC_CH1N_P11
|
||||
#endif
|
||||
#define MIN_ADC_CH 2
|
||||
|
||||
static void init_adc_batt(void);
|
||||
|
||||
void __attribute__((used)) hal_ADC_IRQHandler(void) {
|
||||
uint32_t adc_sum = 0, i;
|
||||
//int status = AP_ADCC->intr_status;
|
||||
|
|
@ -73,7 +71,23 @@ void hal_adc_init(void) {
|
|||
hal_pwrmgr_register(MOD_ADCC, NULL, NULL);
|
||||
}
|
||||
|
||||
void init_adc_batt(void) {
|
||||
void batt_start_measure(void) {
|
||||
LOG("batt_meassured\n");
|
||||
init_adc_batt();
|
||||
// start_adc_bat
|
||||
hal_pwrmgr_lock(MOD_ADCC);
|
||||
JUMP_FUNCTION(ADCC_IRQ_HANDLER) = (uint32_t) &hal_ADC_IRQHandler;
|
||||
|
||||
AP_PCRM->ADC_CTL1 |= BIT(20);
|
||||
AP_PCRM->ANA_CTL |= BIT(3); //ENABLE_ADC;
|
||||
AP_PCRM->ANA_CTL |= BIT(0); //new
|
||||
|
||||
NVIC_SetPriority((IRQn_Type) ADCC_IRQn, IRQ_PRIO_HAL);
|
||||
NVIC_EnableIRQ((IRQn_Type) ADCC_IRQn); //ADC_IRQ_ENABLE;
|
||||
AP_ADCC->intr_mask = BIT(ADC_CHL + 1); //ENABLE_ADC_INT;
|
||||
}
|
||||
|
||||
static void init_adc_batt(void) {
|
||||
AP_AON->PMCTL2_1 = 0x00;
|
||||
AP_PCRM->ANA_CTL &= ~BIT(0);
|
||||
AP_PCRM->ANA_CTL &= ~BIT(3);
|
||||
|
|
@ -95,69 +109,13 @@ void init_adc_batt(void) {
|
|||
// AP_PCRM->ADC_CTL4 |= BIT(4); // mannual mode
|
||||
AP_PCRM->ADC_CTL4 &= ~BIT(4); //enable auto mode
|
||||
AP_PCRM->ADC_CTL4 |= BIT(0);
|
||||
AP_AON->PMCTL2_1 = BIT((ADC_CHL - MIN_ADC_CH)+8);
|
||||
AP_PCRM->ADC_CTL0 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL0 &= ~BIT(4);
|
||||
AP_PCRM->ADC_CTL1 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL1 &= ~BIT(4);
|
||||
AP_PCRM->ADC_CTL2 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL2 &= ~BIT(4);
|
||||
AP_PCRM->ADC_CTL3 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL3 &= ~BIT(4);
|
||||
AP_PCRM->ANA_CTL &= ~BIT(23); //disable micbias
|
||||
// hal_gpio_pull_set(ADC_PIN, GPIO_FLOATING);
|
||||
hal_gpio_ds_control(ADC_PIN, Bit_ENABLE);
|
||||
hal_gpio_cfg_analog_io(ADC_PIN, Bit_ENABLE);
|
||||
}
|
||||
|
||||
void batt_start_measure(void) {
|
||||
LOG("batt_meassured\n");
|
||||
//Event handler is called immediately after conversion is finished.
|
||||
// init_adc_batt
|
||||
AP_AON->PMCTL2_1 = 0x00;
|
||||
AP_PCRM->ANA_CTL &= ~BIT(0);
|
||||
AP_PCRM->ANA_CTL &= ~BIT(3);
|
||||
hal_clk_gate_disable(MOD_ADCC);
|
||||
hal_clk_reset(MOD_ADCC);
|
||||
hal_clk_gate_enable(MOD_ADCC);
|
||||
//CLK_1P28M_ENABLE;
|
||||
AP_PCRM->CLKSEL |= BIT(6);
|
||||
//ENABLE_XTAL_OUTPUT; //enable xtal 16M output,generate the 32M dll clock
|
||||
AP_PCRM->CLKHF_CTL0 |= BIT(18);
|
||||
//ENABLE_DLL; //enable DLL
|
||||
AP_PCRM->CLKHF_CTL1 |= BIT(7);
|
||||
//ADC_DBLE_CLOCK_DISABLE; //disable double 32M clock,we are now use 32M clock,should enable bit<13>, diable bit<21>
|
||||
AP_PCRM->CLKHF_CTL1 &= ~BIT(21); //check
|
||||
//subWriteReg(0x4000F044,21,20,3);
|
||||
//ADC_CLOCK_ENABLE; //adc clock enbale,always use clk_32M
|
||||
AP_PCRM->CLKHF_CTL1 |= BIT(13);
|
||||
//subWriteReg(0x4000f07c,4,4,1); //set adc mode,1:mannual,0:auto mode
|
||||
// AP_PCRM->ADC_CTL4 |= BIT(4); // mannual mode
|
||||
AP_PCRM->ADC_CTL4 &= ~BIT(4); //enable auto mode
|
||||
AP_PCRM->ADC_CTL4 |= BIT(0);
|
||||
AP_AON->PMCTL2_1 = BIT((ADC_CHL - MIN_ADC_CH)+8);
|
||||
AP_PCRM->ADC_CTL0 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL0 &= ~BIT(4);
|
||||
AP_PCRM->ADC_CTL1 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL1 &= ~BIT(4);
|
||||
AP_PCRM->ADC_CTL2 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL2 &= ~BIT(4);
|
||||
AP_PCRM->ADC_CTL3 &= ~BIT(20);
|
||||
AP_PCRM->ADC_CTL3 &= ~BIT(4);
|
||||
AP_AON->PMCTL2_1 = BIT((ADC_CHL - MIN_ADC_CH) + 8);
|
||||
AP_PCRM->ADC_CTL0 &= ~(BIT(20) | BIT(4));
|
||||
AP_PCRM->ADC_CTL1 &= ~(BIT(20) | BIT(4));
|
||||
AP_PCRM->ADC_CTL2 &= ~(BIT(20) | BIT(4));
|
||||
AP_PCRM->ADC_CTL3 &= ~(BIT(20) | BIT(4));
|
||||
AP_PCRM->ANA_CTL &= ~BIT(23); //disable micbias
|
||||
hal_gpio_pull_set(ADC_PIN, GPIO_FLOATING);
|
||||
hal_gpio_ds_control(ADC_PIN, Bit_ENABLE);
|
||||
hal_gpio_cfg_analog_io(ADC_PIN, Bit_ENABLE);
|
||||
// start_adc_bat
|
||||
hal_pwrmgr_lock(MOD_ADCC);
|
||||
JUMP_FUNCTION(ADCC_IRQ_HANDLER) = (uint32_t) &hal_ADC_IRQHandler;
|
||||
|
||||
AP_PCRM->ADC_CTL1 |= BIT(20);
|
||||
AP_PCRM->ANA_CTL |= BIT(3); //ENABLE_ADC;
|
||||
AP_PCRM->ANA_CTL |= BIT(0); //new
|
||||
|
||||
NVIC_SetPriority((IRQn_Type) ADCC_IRQn, IRQ_PRIO_HAL);
|
||||
NVIC_EnableIRQ((IRQn_Type) ADCC_IRQn); //ADC_IRQ_ENABLE;
|
||||
AP_ADCC->intr_mask = BIT(ADC_CHL + 1); //ENABLE_ADC_INT;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/**************************************************************************************************
|
||||
/*
|
||||
battery.h
|
||||
**************************************************************************************************/
|
||||
Author: pvvx
|
||||
*/
|
||||
|
||||
#ifndef _BATTERY_HEAD_FILE
|
||||
#define _BATTERY_HEAD_FILE
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**************************************************************************************************
|
||||
/*
|
||||
battservice.c
|
||||
**************************************************************************************************/
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
INCLUDES
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**************************************************************************************************
|
||||
/*
|
||||
battservice.h
|
||||
**************************************************************************************************/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BATTSERVICE_H
|
||||
|
|
@ -19,24 +19,10 @@ extern "C"
|
|||
CONSTANTS
|
||||
*/
|
||||
|
||||
// Battery Service Get/Set Parameters
|
||||
#define BATT_PARAM_LEVEL 0
|
||||
#define BATT_PARAM_CRITICAL_LEVEL 1
|
||||
#define BATT_PARAM_SERVICE_HANDLE 2
|
||||
#define BATT_PARAM_BATT_LEVEL_IN_REPORT 3
|
||||
|
||||
// Callback events
|
||||
#define BATT_LEVEL_NOTI_ENABLED 1
|
||||
#define BATT_LEVEL_NOTI_DISABLED 2
|
||||
|
||||
// HID Report IDs for the service
|
||||
#define HID_RPT_ID_BATT_LEVEL_IN 4 // Battery Level input report ID
|
||||
|
||||
#ifdef HID_VOICE_SPEC
|
||||
#define GATT_DESC_LENGTH_UUID 0x3111 // Used with Unit percent
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
TYPEDEFS
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
/**************************************************************************************************
|
||||
*******
|
||||
**************************************************************************************************/
|
||||
|
||||
/**************************************************************************************************
|
||||
Filename: simpleBLEperipheral.h
|
||||
Filename: bleperipheral.h
|
||||
Revised:
|
||||
Revision:
|
||||
|
||||
|
|
@ -59,9 +55,6 @@ extern "C"
|
|||
*/
|
||||
#define MAC_DATA_LEN 6
|
||||
|
||||
#define GPIO_KEY P7
|
||||
#define GPIO_LED P26
|
||||
|
||||
extern uint8 simpleBLEPeripheral_TaskID;
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
|
|
|
|||
32
bthome_phy6222/source/config.h
Normal file
32
bthome_phy6222/source/config.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* config.h
|
||||
*
|
||||
* Created on: 11 янв. 2024 г.
|
||||
* Author: pvvx
|
||||
*/
|
||||
|
||||
#ifndef SOURCE_CONFIG_H_
|
||||
#define SOURCE_CONFIG_H_
|
||||
|
||||
#define APP_VERSION 0x01 // BCD
|
||||
|
||||
#define DEF_SOFTWARE_REVISION {'V', '0'+ (APP_VERSION >> 4), '.' , '0'+ (APP_VERSION & 0x0F), 0}
|
||||
|
||||
/* Model: THB2 */
|
||||
|
||||
#define ADC_PIN GPIO_P11
|
||||
#define ADC_CHL ADC_CH1N_P11
|
||||
#define I2C_SDA GPIO_P18
|
||||
#define I2C_SCL GPIO_P20
|
||||
#define GPIO_KEY GPIO_P07
|
||||
#define GPIO_LED GPIO_P26
|
||||
|
||||
#define DEF_MODEL_NUMBER_STR "THB2"
|
||||
#define DEF_HARDWARE_REVISION "0001"
|
||||
#define DEF_MANUFACTURE_NAME_STR "Tuya"
|
||||
|
||||
|
||||
|
||||
#define FS_ID_MAC 0xACAD
|
||||
|
||||
#endif /* SOURCE_CONFIG_H_ */
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
/*********************************************************************
|
||||
INCLUDES
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "bcomdef.h"
|
||||
#include "OSAL.h"
|
||||
#include "linkdb.h"
|
||||
|
|
@ -18,20 +19,37 @@
|
|||
#include "gatt_profile_uuid.h"
|
||||
#include "gattservapp.h"
|
||||
|
||||
|
||||
#include "devinfoservice.h"
|
||||
|
||||
/*********************************************************************
|
||||
MACROS
|
||||
*/
|
||||
#define SYSTEM_ID_ENABLE 0
|
||||
#define SYSTEM_ID_ENABLE 0
|
||||
#ifdef DEF_MODEL_NUMBER_STR
|
||||
#define MODEL_NUMBER_STR_ENABLE 1
|
||||
#else
|
||||
#define MODEL_NUMBER_STR_ENABLE 0
|
||||
#endif
|
||||
#define SERIAL_NUMBER_STR_ENABLE 1
|
||||
#define FIRMWARE_REVISION_ENABLE 1
|
||||
#ifdef DEF_HARDWARE_REVISION
|
||||
#define HARDWARE_REVISION_ENABLE 1
|
||||
#else
|
||||
#define HARDWARE_REVISION_ENABLE 0
|
||||
#endif
|
||||
#ifdef DEF_SOFTWARE_REVISION
|
||||
#define SOFTWARE_REVISION_ENABLE 1
|
||||
#define MANUFACTURE_NAME_STR_ENABLE 1
|
||||
#define IEEE_DATA_ENABLE 0
|
||||
#define PNP_ID_ENABLE 0
|
||||
#else
|
||||
#define SOFTWARE_REVISION_ENABLE 0
|
||||
#endif
|
||||
#ifdef DEF_MANUFACTURE_NAME_STR
|
||||
#define MANUFACTURE_NAME_STR_ENABLE 1
|
||||
#else
|
||||
#define MANUFACTURE_NAME_STR_ENABLE 0
|
||||
#endif
|
||||
#define IEEE_DATA_ENABLE 0
|
||||
#define PNP_ID_ENABLE 0
|
||||
|
||||
/*********************************************************************
|
||||
CONSTANTS
|
||||
|
|
@ -130,16 +148,16 @@ static uint8 devInfoSystemIdProps = GATT_PROP_READ;
|
|||
static uint8 devInfoSystemId[DEVINFO_SYSTEM_ID_LEN] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
#endif
|
||||
|
||||
#if MODEL_NUMBER_STR_ENABLE
|
||||
#if MODEL_NUMBER_STR_ENABLE
|
||||
// Model Number String characteristic
|
||||
static uint8 devInfoModelNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoModelNumber[] = "THB2";
|
||||
static const uint8 devInfoModelNumber[] = DEF_MODEL_NUMBER_STR;
|
||||
#endif
|
||||
|
||||
#if SERIAL_NUMBER_STR_ENABLE
|
||||
// Serial Number String characteristic
|
||||
static uint8 devInfoSerialNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSerialNumber[] = "0001";
|
||||
uint8 devInfoSerialNumber[17] = "000000-0000-0000"; // FLASH_ID-SENSOR_ID-EFUSE
|
||||
#endif
|
||||
|
||||
#if FIRMWARE_REVISION_ENABLE
|
||||
|
|
@ -151,19 +169,19 @@ static const uint8 devInfoFirmwareRev[] = "github.com/pvvx";
|
|||
#if HARDWARE_REVISION_ENABLE
|
||||
// Hardware Revision String characteristic
|
||||
static uint8 devInfoHardwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoHardwareRev[] = "0.1";
|
||||
static const uint8 devInfoHardwareRev[] = DEF_HARDWARE_REVISION;
|
||||
#endif
|
||||
|
||||
#if SOFTWARE_REVISION_ENABLE
|
||||
// Software Revision String characteristic
|
||||
static uint8 devInfoSoftwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSoftwareRev[] = "V0.3";
|
||||
static const uint8 devInfoSoftwareRev[] = DEF_SOFTWARE_REVISION;
|
||||
#endif
|
||||
|
||||
#if MANUFACTURE_NAME_STR_ENABLE
|
||||
// Manufacturer Name String characteristic
|
||||
static uint8 devInfoMfrNameProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoMfrName[] = "Tuya";
|
||||
static const uint8 devInfoMfrName[] = DEF_MANUFACTURE_NAME_STR;
|
||||
#endif
|
||||
|
||||
#if IEEE_DATA_ENABLE
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ bStatus_t DevInfo_SetParameter( uint8 param, uint8 len, void* value );
|
|||
*/
|
||||
extern bStatus_t DevInfo_GetParameter( uint8 param, void* value );
|
||||
|
||||
|
||||
extern uint8 devInfoSerialNumber[17];
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
/**************************************************************************************************
|
||||
/********************************************************************
|
||||
Filename: gpio_demo.h
|
||||
Revised: $Date $
|
||||
Revision: $Revision $
|
||||
**************************************************************************************************/
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef __HAL_PERIPHERAL_H__
|
||||
#define __HAL_PERIPHERAL_H__
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**************************************************************************************************
|
||||
/*
|
||||
main.c
|
||||
**************************************************************************************************/
|
||||
*/
|
||||
|
||||
#include "bus_dev.h"
|
||||
#include "gpio.h"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
sensor.h
|
||||
Author: pvvx
|
||||
*/
|
||||
|
||||
#ifndef _SENSORS_H_
|
||||
#define _SENSORS_H_
|
||||
|
|
@ -59,6 +63,7 @@ typedef struct _measured_data_t {
|
|||
} measured_data_t;
|
||||
|
||||
extern measured_data_t measured_data;
|
||||
extern unsigned short th_sensor_id;
|
||||
|
||||
void init_sensor(void);
|
||||
int read_sensor(void);
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
/*
|
||||
sensor.c
|
||||
Author: pvvx
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include "config.h"
|
||||
#include "gpio.h"
|
||||
#include "rom_sym_def.h"
|
||||
#include "i2c.h"
|
||||
#include "sensor.h"
|
||||
|
||||
/* Tuya:
|
||||
* I2C0 SCL P24
|
||||
* I2C0 SDA P23
|
||||
|
||||
SCL P20
|
||||
SDA P18
|
||||
KEY P07
|
||||
VBAT P10
|
||||
*/
|
||||
#define I2C_SDA P18
|
||||
#define I2C_SCL P20
|
||||
#ifndef I2C_SDA
|
||||
#define I2C_SDA GPIO_P18
|
||||
#define I2C_SCL GPIO_P20
|
||||
#endif
|
||||
|
||||
measured_data_t measured_data;
|
||||
unsigned short th_sensor_id;
|
||||
|
||||
void init_i2c(void) {
|
||||
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);
|
||||
//hal_i2c_init(I2C_0, I2C_CLOCK_400K):
|
||||
|
||||
int pclk = clk_get_pclk();
|
||||
|
||||
|
|
@ -57,11 +57,11 @@ void init_i2c(void) {
|
|||
pi2cdev->IC_FS_SCL_HCNT = 105;
|
||||
pi2cdev->IC_FS_SCL_LCNT = 113;
|
||||
}
|
||||
pi2cdev->IC_TAR = I2C_MASTER_ADDR_DEF;
|
||||
// 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;
|
||||
// pi2cdev->IC_ENABLE = 1;
|
||||
}
|
||||
|
||||
void deinit_i2c(void) {
|
||||
|
|
@ -80,13 +80,17 @@ int read_i2c_bytes(uint8 addr, uint8 reg, uint8 * data, uint8 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) {
|
||||
|
|
@ -139,7 +143,7 @@ int send_i2c_wreg(uint8 addr, uint8 reg, uint16 data) {
|
|||
if(osal_sys_tick - to > 10)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__ATTR_SECTION_XIP__ void init_sensor(void) {
|
||||
|
|
@ -147,9 +151,12 @@ __ATTR_SECTION_XIP__ void init_sensor(void) {
|
|||
send_i2c_byte(0, 0x06); // Reset command using the general call address
|
||||
WaitMs(3);
|
||||
send_i2c_wreg(CHT8310_I2C_ADDR0, CHT8310_REG_CRT, 0x0300); // Set conversion ratio 5 sec
|
||||
WaitMs(1);
|
||||
read_i2c_bytes(CHT8310_I2C_ADDR0, CHT8310_REG_ID, (uint8 *)&th_sensor_id, 2);
|
||||
deinit_i2c();
|
||||
}
|
||||
|
||||
|
||||
int read_sensor(void) {
|
||||
int32 _r32;
|
||||
int16 _r16;
|
||||
|
|
@ -160,16 +167,10 @@ int read_sensor(void) {
|
|||
_r32 |= read_i2c_bytes(CHT8310_I2C_ADDR0, CHT8310_REG_HMD, ®_data[2], 2);
|
||||
deinit_i2c();
|
||||
if (!_r32) {
|
||||
/* https://esp8266.ru/forum/threads/ble-soc-phy6202.4666/post-95300
|
||||
температура в 0.01 C (_r16 * 100 + 50) >> 8
|
||||
влажность в 0.01 % (_r32 * 10000 + 5000) >> 15
|
||||
заряд батареи в % ((battery_mv - 2000) * 6534 + 3277) >> 16
|
||||
заряд батареи в 0.1% (((battery_mv - 2000) << 16) + 32768) >> 16
|
||||
*/
|
||||
_r16 = (reg_data[0] << 8) | reg_data[1];
|
||||
measured_data.temp = (int32)(_r16 * 25606) >> 16; // x 0.01 C
|
||||
measured_data.temp = (int32)(_r16 * 25606 + 0x7fff) >> 16; // x 0.01 C
|
||||
_r32 = ((reg_data[2] << 8) | reg_data[3]) & 0x7fff;
|
||||
measured_data.humi = (uint32)(_r32 * 20000) >> 16; // x 0.01 %
|
||||
measured_data.humi = (uint32)(_r32 * 20000 + 0x7fff) >> 16; // x 0.01 %
|
||||
if (measured_data.humi > 9999)
|
||||
measured_data.humi = 9999;
|
||||
measured_data.count++;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
* INCLUDES
|
||||
*/
|
||||
#include "bcomdef.h"
|
||||
#include "config.h"
|
||||
#include "rf_phy_driver.h"
|
||||
#include "global_config.h"
|
||||
#include "OSAL.h"
|
||||
|
|
@ -42,7 +43,7 @@
|
|||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
//#define LOG(...)
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
|
@ -69,10 +70,13 @@
|
|||
*/
|
||||
perStatsByChan_t g_perStatsByChanTest;
|
||||
|
||||
uint8 adv_count;
|
||||
uint8 adv_con_count;
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL VARIABLES
|
||||
*/
|
||||
volatile uint8_t g_current_advType = LL_ADV_CONNECTABLE_UNDIRECTED_EVT;
|
||||
//volatile uint8_t g_current_advType = LL_ADV_CONNECTABLE_UNDIRECTED_EVT;
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
|
|
@ -124,24 +128,16 @@ static void set_mac(void)
|
|||
{
|
||||
extern uint8 ownPublicAddr[LL_DEVICE_ADDR_LEN];
|
||||
uint8 * p = &attDeviceName[5];
|
||||
#if 1 // =0 - test!
|
||||
uint16 len;
|
||||
if(hal_fs_item_read(0xACAD, ownPublicAddr, LL_DEVICE_ADDR_LEN, &len) != PPlus_SUCCESS) {
|
||||
LL_Rand(ownPublicAddr,3);
|
||||
ownPublicAddr[3] = 0x8d;
|
||||
ownPublicAddr[4] = 0x1f;
|
||||
ownPublicAddr[5] = 0x38;
|
||||
hal_fs_item_write(0xACAD, ownPublicAddr, LL_DEVICE_ADDR_LEN);
|
||||
if (read_chip_mAddr(ownPublicAddr) != CHIP_ID_VALID) {
|
||||
uint16 len;
|
||||
if(hal_fs_item_read(FS_ID_MAC, ownPublicAddr, LL_DEVICE_ADDR_LEN, &len) != PPlus_SUCCESS) {
|
||||
LL_Rand(ownPublicAddr,3);
|
||||
ownPublicAddr[3] = 0x8d;
|
||||
ownPublicAddr[4] = 0x1f;
|
||||
ownPublicAddr[5] = 0x38;
|
||||
hal_fs_item_write(0xACAD, ownPublicAddr, LL_DEVICE_ADDR_LEN);
|
||||
}
|
||||
}
|
||||
#else
|
||||
ownPublicAddr[0] = 0x56;
|
||||
ownPublicAddr[1] = 0x34;
|
||||
ownPublicAddr[2] = 0x12;
|
||||
ownPublicAddr[3] = 0x34;
|
||||
ownPublicAddr[4] = 0x12;
|
||||
ownPublicAddr[5] = 0x25;
|
||||
#endif
|
||||
|
||||
p = str_bin2hex(p, &ownPublicAddr[2], 1);
|
||||
p = str_bin2hex(p, &ownPublicAddr[1], 1);
|
||||
str_bin2hex(p, &ownPublicAddr[0], 1);
|
||||
|
|
@ -150,9 +146,29 @@ static void set_mac(void)
|
|||
osal_memcpy(&scanRspData[2], attDeviceName, sizeof(attDeviceName));
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EFUSE_BLOCK_0 = 0,
|
||||
EFUSE_BLOCK_1 = 1,
|
||||
EFUSE_BLOCK_2 = 2,
|
||||
EFUSE_BLOCK_3 = 3,
|
||||
|
||||
} EFUSE_block_t;
|
||||
|
||||
extern int efuse_read(EFUSE_block_t block,uint32_t* buf);
|
||||
|
||||
static void set_serial_number(void)
|
||||
{
|
||||
hal_get_flash_info();
|
||||
uint32_t temp_rd[2] = {0, 0};
|
||||
efuse_read(EFUSE_BLOCK_0, temp_rd);
|
||||
uint8_t *p = str_bin2hex(devInfoSerialNumber, (uint8_t *)&phy_flash.IdentificationID, 3);
|
||||
*p++ = '-';
|
||||
p = str_bin2hex(p, (uint8_t *)&th_sensor_id, 2);
|
||||
*p++ = '-';
|
||||
p = str_bin2hex(p, (uint8_t *)&temp_rd[0], 2);
|
||||
}
|
||||
|
||||
uint8 adv_count;
|
||||
uint8 adv_con_count;
|
||||
/*
|
||||
extern uint8 gapRole_AdvEnabled;
|
||||
extern uint8 gapRole_AdvertData[B_MAX_ADV_LEN];
|
||||
|
|
@ -169,24 +185,24 @@ extern gaprole_States_t gapRole_state;
|
|||
*/
|
||||
|
||||
extern gapPeriConnectParams_t periConnParameters;
|
||||
extern uint16 gapParameters[];
|
||||
|
||||
// Set new advertising interval
|
||||
static void set_adv_interval(uint16 advInt)
|
||||
{
|
||||
#if 0
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
|
||||
#else
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MAX] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MAX] = advInt;
|
||||
#endif
|
||||
GAP_EndDiscoverable( gapRole_TaskID );
|
||||
gapRole_state = GAPROLE_WAITING_AFTER_TIMEOUT;
|
||||
/*
|
||||
LL_SetAdvParam(advInt, advInt, // actual time = advInt * 625us
|
||||
LL_ADV_CONNECTABLE_UNDIRECTED_EVT,
|
||||
gapRole_AdvEventType,
|
||||
gapRole_AdvDirectType,
|
||||
gapRole_AdvDirectAddr,
|
||||
gapRole_AdvChanMap,
|
||||
gapRole_AdvFilterPolicy ); */
|
||||
// Turn advertising back on.
|
||||
osal_set_event( gapRole_TaskID, START_ADVERTISING_EVT );
|
||||
}
|
||||
|
|
@ -214,7 +230,7 @@ static void adv_measure(void) {
|
|||
/*********************************************************************
|
||||
* LED and Key
|
||||
*/
|
||||
static void posedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
|
||||
static void posedge_int_wakeup_cb(GPIO_Pin_e pin, IO_Wakeup_Pol_e type)
|
||||
{
|
||||
(void) pin;
|
||||
if(type == POSEDGE)
|
||||
|
|
@ -232,7 +248,7 @@ static void posedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
|
|||
}
|
||||
}
|
||||
|
||||
static void negedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
|
||||
static void negedge_int_wakeup_cb(GPIO_Pin_e pin, IO_Wakeup_Pol_e type)
|
||||
{
|
||||
(void) pin;
|
||||
if(type == NEGEDGE)
|
||||
|
|
@ -246,12 +262,10 @@ static void negedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
|
|||
}
|
||||
}
|
||||
|
||||
static void init_led_key(void)
|
||||
void init_led_key(void)
|
||||
{
|
||||
//hal_gpio_pin_init(GPIO_KEY, GPIO_INPUT);
|
||||
hal_gpioin_register(GPIO_KEY, posedge_int_wakeup_cb, negedge_int_wakeup_cb);
|
||||
hal_gpioretention_register(GPIO_LED);//enable this pin retention
|
||||
//hal_gpioretention_unregister(pin);//disable this pin retention
|
||||
hal_gpio_write(GPIO_LED, 1);
|
||||
}
|
||||
|
||||
|
|
@ -307,8 +321,14 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
|||
|
||||
init_sensor();
|
||||
|
||||
set_serial_number();
|
||||
|
||||
// Setup the GAP
|
||||
VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL );
|
||||
#if 0
|
||||
GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL );
|
||||
#else
|
||||
gapParameters[TGAP_CONN_PAUSE_PERIPHERAL] = DEFAULT_CONN_PAUSE_PERIPHERAL;
|
||||
#endif
|
||||
|
||||
// Setup the GAP Peripheral Role Profile
|
||||
{
|
||||
|
|
@ -355,12 +375,19 @@ void SimpleBLEPeripheral_Init( uint8 task_id )
|
|||
// Set advertising interval
|
||||
{
|
||||
uint16 advInt = DEF_ADV_INERVAL; // actual time = advInt * 625us
|
||||
#if 0
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );
|
||||
#else
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_LIM_DISC_ADV_INT_MAX] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MIN] = advInt;
|
||||
gapParameters[TGAP_GEN_DISC_ADV_INT_MAX] = advInt;
|
||||
#endif
|
||||
}
|
||||
HCI_PPLUS_AdvEventDoneNoticeCmd(simpleBLEPeripheral_TaskID, ADV_BROADCAST_EVT);
|
||||
HCI_PPLUS_AdvEventDoneNoticeCmd(simpleBLEPeripheral_TaskID, ADV_BROADCAST_EVT);
|
||||
#if (DEF_GAPBOND_MGR_ENABLE==1)
|
||||
// Setup the GAP Bond Manager, add 2017-11-15
|
||||
{
|
||||
|
|
@ -500,7 +527,7 @@ uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
|
|||
}
|
||||
if(events & SBP_DEALDATA)
|
||||
{
|
||||
LOG("\ndeal app datas in events!!!\n");
|
||||
LOG("\ndeal app datas in events!\n");
|
||||
// return unprocessed events
|
||||
return(events ^ SBP_DEALDATA);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**************************************************************************************************
|
||||
Filename: peripheral.c
|
||||
Filename: th_peripheral.c
|
||||
Revised:
|
||||
Revision:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
/**
|
||||
@headerfile: peripheral.h
|
||||
@headerfile: th_peripheral.h
|
||||
$Date:
|
||||
$Revision:
|
||||
|
||||
This GAP profile advertises and allows connections.
|
||||
*/
|
||||
|
||||
#ifndef PERIPHERAL_H
|
||||
#define PERIPHERAL_H
|
||||
#ifndef TH_PERIPHERAL_H
|
||||
#define TH_PERIPHERAL_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -18,6 +18,7 @@ extern "C"
|
|||
/* -------------------------------------------------------------------
|
||||
INCLUDES
|
||||
*/
|
||||
#include "bcomdef.h"
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
CONSTANTS
|
||||
|
|
@ -326,4 +327,4 @@ extern gaprole_States_t gapRole_state;
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* PERIPHERAL_H */
|
||||
#endif /* TH_PERIPHERAL_H */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**************************************************************************************************
|
||||
/*
|
||||
thservice.c
|
||||
**************************************************************************************************/
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
INCLUDES
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**************************************************************************************************
|
||||
/*
|
||||
thservice.h
|
||||
**************************************************************************************************/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _THSERVICE_H_
|
||||
|
|
@ -22,13 +22,6 @@ extern "C"
|
|||
#define TEMPERATYRE_UUID 0x2A6E
|
||||
#define HUMIDITY_UUID 0x2A6F
|
||||
|
||||
|
||||
// Battery Service Get/Set Parameters
|
||||
#define BATT_PARAM_LEVEL 0
|
||||
#define BATT_PARAM_CRITICAL_LEVEL 1
|
||||
#define BATT_PARAM_SERVICE_HANDLE 2
|
||||
#define BATT_PARAM_BATT_LEVEL_IN_REPORT 3
|
||||
|
||||
// Callback events
|
||||
#define TEMP_LEVEL_NOTI_ENABLED 1
|
||||
#define TEMP_LEVEL_NOTI_DISABLED 2
|
||||
|
|
@ -64,9 +57,9 @@ typedef void (*thServiceTeardownCB_t)(void);
|
|||
*/
|
||||
|
||||
/*********************************************************************
|
||||
@fn Batt_AddService
|
||||
@fn TH_AddService
|
||||
|
||||
@brief Initializes the Battery service by registering
|
||||
@brief Initializes the TH service by registering
|
||||
GATT attributes with the GATT server.
|
||||
|
||||
@return Success or Failure
|
||||
|
|
@ -74,9 +67,9 @@ typedef void (*thServiceTeardownCB_t)(void);
|
|||
extern bStatus_t TH_AddService( void );
|
||||
|
||||
/*********************************************************************
|
||||
@fn Batt_Register
|
||||
@fn TH_Register
|
||||
|
||||
@brief Register a callback function with the Battery Service.
|
||||
@brief Register a callback function with the TH Service.
|
||||
|
||||
@param pfnServiceCB - Callback function.
|
||||
|
||||
|
|
@ -85,9 +78,9 @@ extern bStatus_t TH_AddService( void );
|
|||
extern void TH_Register( thServiceCB_t pfnServiceCB );
|
||||
|
||||
/*********************************************************************
|
||||
@fn Batt_HandleConnStatusCB
|
||||
@fn TH_HandleConnStatusCB
|
||||
|
||||
@brief Battery Service link status change handler function.
|
||||
@brief TH Service link status change handler function.
|
||||
|
||||
@param connHandle - connection handle
|
||||
@param changeType - type of change
|
||||
|
|
@ -99,7 +92,7 @@ void TH_HandleConnStatusCB( uint16 connHandle, uint8 changeType );
|
|||
/*********************************************************************
|
||||
@fn thNotifyLevelState
|
||||
|
||||
@brief Send a notification of the battery level state
|
||||
@brief Send a notification of the TH measure state
|
||||
characteristic if a connection is established.
|
||||
|
||||
@return None.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue