Replace main branch content with new branch

This commit is contained in:
stark1898y 2024-12-15 17:22:09 +08:00
parent 6ec37f1274
commit d304f5e0de
22 changed files with 171 additions and 206 deletions

View File

@ -14,7 +14,7 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj" parent="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release" postbuildStep="">
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj" parent="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release" postbuildStep=" ${cross_prefix}${cross_objcopy}${cross_suffix} -O ihex &quot;${ProjName}.elf&quot; &quot;${ProjName}.hex&quot; &amp;&amp; ${cross_prefix}${cross_objcopy}${cross_suffix} -O binary &quot;${ProjName}.elf&quot; &quot;${ProjName}.bin&quot;">
<folderInfo id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074." name="/" resourcePath="">
<toolChain id="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release.231146001" name="RISC-V Cross GCC" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash.1311852988" name="Create flash image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash" useByScannerDiscovery="false" value="true" valueType="boolean"/>
@ -56,8 +56,6 @@
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187" name="GNU RISC-V Cross C Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Startup}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/common/MultiButton}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/common/FlexibleButton-2.0.1}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/common/letter-shell}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/common/letter-shell/extensions/log}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/common/lwrb-3.2.0}&quot;"/>
@ -92,7 +90,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Ld/Link.ld}&quot;"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip.1780837525" name="Omit all symbol information (-s)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/>
@ -105,10 +103,9 @@
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1577723329" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList">
<listOptionValue builtIn="false" value="--print-memory-usage"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat.1191876922" name="Use wchprintfloat(-lprintfloat)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat.1191876922" name="Use wchprintfloat(-lprintfloat)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other.1168669005" name="Other linker flags" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other" useByScannerDiscovery="false" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printf.427785884" name="Use wchprintf(-lprintf)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printf" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat.1247237734" name="Use float with nano printf (-u _printf_float)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat.978715450" name="Use float with nano printf (-u _printf_float)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@ -127,7 +124,7 @@
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver.1292785366" name="GNU RISC-V Cross Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver"/>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash.1801165667" name="GNU RISC-V Cross Create Flash Image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.777102436" name="Output file format (-O)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.ihex" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.777102436" name="Output file format (-O)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.ihexAndbinary" valueType="enumerated"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting.1356766765" name="GNU RISC-V Cross Create Listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source.2052761852" name="Display source (--source|-S)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source" useByScannerDiscovery="false" value="true" valueType="boolean"/>
@ -176,5 +173,5 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="refreshScope"/>
</cproject>

View File

@ -5,7 +5,7 @@
<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.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1299894306125289391" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1238121178080294279" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

View File

@ -1,9 +1,6 @@
eclipse.preferences.version=1
encoding//APP/peripheral.c=UTF-8
encoding//APP/peripheral_main.c=UTF-8
encoding//BSP/inc/bsp_iwdg.h=UTF-8
encoding//BSP/inc/bsp_valve.h=UTF-8
encoding//BSP/src/bsp_iwdg.c=UTF-8
encoding//BSP/src/bsp_key.c=UTF-8
encoding//BSP/src/bsp_valve.c=UTF-8
encoding//common/letter-shell/extensions/log/log.h=UTF-8

11
.vscode/settings.json vendored
View File

@ -13,13 +13,6 @@
"shell_port.h": "c",
"atomic": "cpp",
"cstddef": "cpp",
"type_traits": "cpp",
"shell.h": "c",
"ch59x_common.h": "c",
"flexible_button.h": "c",
"stdint.h": "c",
"bsp_flash.h": "c",
"bsp_valve.h": "c"
},
"marscode.chatLanguage": "cn"
"type_traits": "cpp"
}
}

View File

@ -3,8 +3,8 @@
* Author : WCH
* Version : V1.0
* Date : 2018/12/10
* Description : 广广
*
* Description : 广广
*
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
@ -43,7 +43,7 @@
*/
// How often to perform periodic event
#define SBP_PERIODIC_EVT_PERIOD (160 * 10) // (160 = 100ms)
#define SBP_PERIODIC_EVT_PERIOD (160 * 10 * 5) // (160 = 100ms)
// How often to perform read rssi event
#define SBP_READ_RSSI_EVT_PERIOD (1600 * 3) // (160 = 100ms)
@ -55,7 +55,7 @@
#define SBP_PHY_UPDATE_DELAY (1600 * 2)
// What is the advertising interval when device is discoverable (units of 625us, 80=50ms)
#define DEFAULT_ADVERTISING_INTERVAL (160 * 1)
#define DEFAULT_ADVERTISING_INTERVAL (160 * 10)
// Limited discoverable mode advertises for 30.72s, and then stops
// General discoverable mode advertises indefinitely
@ -76,81 +76,36 @@
// Company Identifier: WCH
#define WCH_COMPANY_ID 0x07D7
/*********************************************************************
* TYPEDEFS
*/
#define MAC_NAME "TYQ-93:B4:8F:10:53:5C"
// TYQ-93:B4:8F:10:53:5C
#define MAC_NAME_LEN 22
/*********************************************************************
* GLOBAL VARIABLES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
static uint8_t Peripheral_TaskID = INVALID_TASK_ID; // Task ID for internal task/event processing
// 蓝牙广播包的最大长度是37个字节其中设备地址占用了6个字节只有31个字节是可用的。
// TODO:响应体名称加上MAC地址
// GAP - SCAN RSP data (max size = 31 bytes)
static uint8_t scanRspData[] = {
// complete name
0x12, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
's', 'i', 'm', 'p', 'l', 'e', ' ', 'P', 'e', 'r', 'i', 'p', 'h', 'e', 'r', 'a', 'l',
// connection interval range
0x05, // length of this data
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
LO_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL), // 100ms
HI_UINT16(DEFAULT_DESIRED_MIN_CONN_INTERVAL),
LO_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL), // 1s
HI_UINT16(DEFAULT_DESIRED_MAX_CONN_INTERVAL),
// Tx power level
0x02, // length of this data
GAP_ADTYPE_POWER_LEVEL,
0 // 0dBm
};
// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertising)
static uint8_t advertData[] = {
// Flags; this sets the device to use limited discoverable
// mode (advertises for 30 seconds at a time) instead of general
// discoverable mode (advertises indefinitely)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
// service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16(SIMPLEPROFILE_SERV_UUID),
HI_UINT16(SIMPLEPROFILE_SERV_UUID)
};
#if 0
// 蓝牙广播包的最大长度是37个字节其中设备地址占用了6个字节只有31个字节是可用的。
// GAP - SCAN RSP data (max size = 31 bytes)
static uint8_t scanRspData[] = {
// complete name
0x08, // length of this data
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
'B',
'L',
'E',
'-',
'T',
'Y',
'Q',
' ',
'P',
'e',
'r',
'i',
'p',
'h',
'e',
'r',
'a',
'l',
// connection interval range
0x05, // length of this data
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
@ -163,24 +118,8 @@ static uint8_t scanRspData[] = {
0x02, // length of this data
GAP_ADTYPE_POWER_LEVEL,
0 // 0dBm
0x03, // length of this data
GAP_ADTYPE_MANUFACTURER_SPECIFIC,
// 前两个字节表示厂商 ID
0,
0,
0x10, // 1B 电池电压 30=3V,18=1.8V
0x01, // 1B 阀门类型
0x00, // 1B 阀门工作状态 超欠压、过流
0x00, // 1B 阀门连接状态 电磁阀BLE控制盒 0=未连接 1=已连接
0x01, // 1B 阀门开关状态 0=未知 1=关闭 2=关闭过,未按按键恢复 3=关闭过,按下了恢复键 4=打开
0x03, // 1B 阀门温度 有符号整数 25 C
0x04, // 1B 阀门进口压力 0~156 (0)kPa
0x05, // 1B 阀门出口压力 0~100 hPa 0.1kpa
0x06, // 1B 阀门大气压力 80~110 kPa
};
// GAP - Advertisement data (max size = 31 bytes, though this is
// best kept short to conserve power while advertising)
static uint8_t advertData[] = {
@ -199,10 +138,8 @@ static uint8_t advertData[] = {
HI_UINT16(SIMPLEPROFILE_SERV_UUID)
};
#endif
// GAP GATT Attributes
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "Simple Peripheral";
static uint8_t attDeviceName[GAP_DEVICE_NAME_LEN] = "BLE_TYQ";
// Connection item list
static peripheralConnItem_t peripheralConnList;
@ -213,7 +150,7 @@ static uint16_t peripheralMTU = ATT_MTU_SIZE;
*/
static void Peripheral_ProcessTMOSMsg(tmos_event_hdr_t *pMsg);
static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEvent_t *pEvent);
static void UploadPeriodicTask(void);
static void performPeriodicTask(void);
static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len);
static void peripheralParamUpdateCB(uint16_t connHandle, uint16_t connInterval,
uint16_t connSlaveLatency, uint16_t connTimeout);
@ -273,11 +210,11 @@ void Peripheral_Init()
// Setup the GAP Peripheral Role Profile
{
//开启广播使能
//开启广播使能
uint8_t initial_advertising_enable = TRUE;
//最小连接间隔
//最小连接间隔
uint16_t desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
//最大连接间隔
//最大连接间隔
uint16_t desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
// Set the GAP Role Parameters
@ -297,8 +234,8 @@ void Peripheral_Init()
GAP_SetParamValue(TGAP_DISC_ADV_INT_MAX, advInt);
// https://www.cnblogs.com/debugdabiaoge/p/17871551.html
// 默认从机在回复扫描请求后,会结束广播事件(默认广播应该是 37 38 39 在 3 个信道轮发)
// 如下使能后,可以保证广播包不受扫描请求的影响
// 默认从机在回复扫描请求后,会结束广播事件(默认广播应该是 37 38 39 在 3 个信道轮发)
// 如下使能后,可以保证广播包不受扫描请求的影响
// uint16_t adv_event_contnue=1<<1;
// GAP_SetParamValue(TGAP_ADV_SCAN_REQ_NOTIFY, adv_event_contnue);
@ -331,11 +268,11 @@ void Peripheral_Init()
// Setup the SimpleProfile Characteristic Values
{
uint8_t charValue1[SIMPLEPROFILE_CHAR1_LEN] = {1};
uint8_t charValue2[SIMPLEPROFILE_CHAR2_LEN] = {2};
uint8_t charValue3[SIMPLEPROFILE_CHAR3_LEN] = {3};
uint8_t charValue4[SIMPLEPROFILE_CHAR4_LEN] = {4};
uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = {1, 2, 3, 4, 5};
uint8_t charValue1[SIMPLEPROFILE_CHAR1_LEN] = {0};
uint8_t charValue2[SIMPLEPROFILE_CHAR2_LEN] = {0};
uint8_t charValue3[SIMPLEPROFILE_CHAR3_LEN] = {0};
uint8_t charValue4[SIMPLEPROFILE_CHAR4_LEN] = {0};
uint8_t charValue5[SIMPLEPROFILE_CHAR5_LEN] = {0, 0, 0, 0, 0};
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR1, SIMPLEPROFILE_CHAR1_LEN, charValue1);
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR2, SIMPLEPROFILE_CHAR2_LEN, charValue2);
@ -420,7 +357,7 @@ uint16_t Peripheral_ProcessEvent(uint8_t task_id, uint16_t events)
tmos_start_task(Peripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
}
// Perform periodic application task
UploadPeriodicTask();
performPeriodicTask();
return (events ^ SBP_PERIODIC_EVT);
}
@ -472,7 +409,7 @@ static void Peripheral_ProcessGAPMsg(gapRoleEvent_t *pEvent)
{
case GAP_SCAN_REQUEST_EVENT:
{
logDebug("Receive scan req from %x %x %x %x %x %x ..\n", pEvent->scanReqEvt.scannerAddr[0],
logDebug("Receive scan req from %x %x %x %x %x %x ..", pEvent->scanReqEvt.scannerAddr[0],
pEvent->scanReqEvt.scannerAddr[1], pEvent->scanReqEvt.scannerAddr[2], pEvent->scanReqEvt.scannerAddr[3],
pEvent->scanReqEvt.scannerAddr[4], pEvent->scanReqEvt.scannerAddr[5]);
break;
@ -480,7 +417,7 @@ static void Peripheral_ProcessGAPMsg(gapRoleEvent_t *pEvent)
case GAP_PHY_UPDATE_EVENT:
{
logDebug("Phy update Rx:%x Tx:%x ..\n", pEvent->linkPhyUpdate.connRxPHYS, pEvent->linkPhyUpdate.connTxPHYS);
logDebug("Phy update Rx:%x Tx:%x ..", pEvent->linkPhyUpdate.connRxPHYS, pEvent->linkPhyUpdate.connTxPHYS);
break;
}
@ -516,7 +453,7 @@ static void Peripheral_ProcessTMOSMsg(tmos_event_hdr_t *pMsg)
if(pMsgEvent->method == ATT_MTU_UPDATED_EVENT)
{
peripheralMTU = pMsgEvent->msg.exchangeMTUReq.clientRxMTU;
logDebug("mtu exchange: %d\n", pMsgEvent->msg.exchangeMTUReq.clientRxMTU);
logDebug("mtu exchange: %d", pMsgEvent->msg.exchangeMTUReq.clientRxMTU);
}
break;
}
@ -561,7 +498,7 @@ static void Peripheral_LinkEstablished(gapRoleEvent_t *pEvent)
// Start read rssi
tmos_start_task(Peripheral_TaskID, SBP_READ_RSSI_EVT, SBP_READ_RSSI_EVT_PERIOD);
logDebug("Conn %x - Int %x \n", event->connectionHandle, event->connInterval);
logDebug("Conn %x - Int %x ", event->connectionHandle, event->connInterval);
}
}
@ -589,11 +526,10 @@ static void Peripheral_LinkTerminated(gapRoleEvent_t *pEvent)
// Restart advertising
{
// 三个广播通道全部打开
// 三个广播通道全部打开
// uint8_t init_adv_channel_map = GAP_ADVCHAN_ALL ;
// GAPRole_SetParameter( GAPROLE_ADV_CHANNEL_MAP, sizeof( uint8_t ), &init_adv_channel_map);
// 开启广播
uint8_t advertising_enable = TRUE;
GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &advertising_enable);
}
@ -616,7 +552,7 @@ static void Peripheral_LinkTerminated(gapRoleEvent_t *pEvent)
*/
static void peripheralRssiCB(uint16_t connHandle, int8_t rssi)
{
logDebug("RSSI -%d dB Conn %x \n", -rssi, connHandle);
logDebug("RSSI -%d dB Conn %x ", -rssi, connHandle);
}
/*********************************************************************
@ -670,7 +606,7 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
if(pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT)
{
Peripheral_LinkTerminated(pEvent);
logDebug("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason);
logDebug("Disconnected.. Reason:%x", pEvent->linkTerminate.reason);
logDebug("Advertising..");
}
else if(pEvent->gap.opcode == GAP_MAKE_DISCOVERABLE_DONE_EVENT)
@ -702,7 +638,7 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
else if(pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT)
{
Peripheral_LinkTerminated(pEvent);
logDebug("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason);
logDebug("Disconnected.. Reason:%x", pEvent->linkTerminate.reason);
}
else if(pEvent->gap.opcode == GAP_LINK_ESTABLISHED_EVENT)
{
@ -712,17 +648,17 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
}
else
{
logDebug("Error..");
logError("Err..");
}
}
else
{
logDebug("Error..%x\n", pEvent->gap.opcode);
logError("Err..%x", pEvent->gap.opcode);
}
break;
case GAPROLE_ERROR:
logDebug("Error..");
logError("Err..");
break;
default:
@ -731,7 +667,7 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
}
/*********************************************************************
* @fn UploadPeriodicTask
* @fn performPeriodicTask
*
* @brief Perform a periodic application task. This function gets
* called every five seconds as a result of the SBP_PERIODIC_EVT
@ -744,7 +680,7 @@ static void peripheralStateNotificationCB(gapRole_States_t newState, gapRoleEven
*
* @return none
*/
static void UploadPeriodicTask(void)
static void performPeriodicTask(void)
{
// static uint8_t counter = 0;
// uint8_t notiData[SIMPLEPROFILE_CHAR4_LEN] = {0x11, 0x22, 0x33, 0x44, 0};
@ -765,7 +701,7 @@ static void UploadPeriodicTask(void)
ADC_InterBATSampInit();
for (i = 0; i < 20; i++)
{
adcBuff[i] = ADC_ExcutSingleConver(); // 连续采样20次
adcBuff[i] = ADC_ExcutSingleConver(); // 连续采样20次
}
for (i = 0; i < 20; i++)
{
@ -775,11 +711,11 @@ static void UploadPeriodicTask(void)
min_number = adcBuff[i];
max_number = adcBuff[i];
}
min_number = ((min_number > adcBuff[i]) ? adcBuff[i] : min_number); // 软件滤波
min_number = ((min_number > adcBuff[i]) ? adcBuff[i] : min_number); // 软件滤波
max_number = ((max_number < adcBuff[i]) ? adcBuff[i] : max_number);
}
logDebug("min_number = %d, max_number = %d", min_number, max_number);
CountBat = (CountBat - min_number - max_number) / 18; // 删除最小与最大值
CountBat = (CountBat - min_number - max_number) / 18; // 删除最小与最大值
logDebug("AverageCountBat = %d", CountBat);
#endif
@ -840,8 +776,6 @@ static void peripheralChar4Notify(uint8_t *pValue, uint16_t len)
}
}
/*********************************************************************
* @fn simpleProfileChangeCB
*
@ -892,7 +826,7 @@ static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len
TsFrameData *HostFrameData = BSP_VAVLE_GetFrameData(newValue, len);
if (HostFrameData != NULL)
{
// logHexDumpAll(&HostFrameData->data[0], HostFrameData->len); // 数据段
// logHexDumpAll(&HostFrameData->data[0], HostFrameData->len); // 数据段
// BSP_UART1_TxLoop();
// HR_ProcessData(HostFrameData);
switch (HostFrameData->cmd)
@ -900,7 +834,7 @@ static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len
case kCmdCfg:
// uint8_t data_buf[64] = {0};
// tmos_memset(data_buf, 0, sizeof(data_buf));
// 处理数据帧
// 处理数据帧
logDebug("kCmdCfg");
break;
case kCmdCloseVavle:
@ -916,14 +850,14 @@ static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len
BSP_UART1_TxLoop();
break;
default:
logError("无效的命令");
logError("无效的命令");
// logHexDumpAll(data, len);
break;
}
}
else
{
logError("数据帧解析失败");
logError("数据帧解析失败");
}
tmos_msg_deallocate((uint8_t*)HostFrameData);
HostFrameData = NULL;
@ -938,14 +872,16 @@ static void simpleProfileChangeCB(uint8_t paramID, uint8_t *pValue, uint16_t len
}
}
// TODO:应用加入广播数据更新部分状态数据
// 动态更新广播数据
// taskID 请求更改广播任务的 ID
// adTypeTRUE 更改广播数据FALSE 更改扫描回复数据
// datalen数据长度
// *pAdvertData数据指针
// TODO:应用加入广播数据更新部分状态数据
// 动态更新广播数据
// taskID 请求更改广播任务的 ID
// adTypeTRUE 更改广播数据FALSE 更改扫描回复数据
// datalen数据长度
// *pAdvertData数据指针
void Peripheral_UpdateAdvertData(uint8_t adType, uint8_t dataLen, uint8_t *pAdvertData)
{
GAP_UpdateAdvertisingData(Peripheral_TaskID, adType, dataLen, pAdvertData);
}

View File

@ -10,8 +10,6 @@
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
/* 头文件包含 */
#include "CONFIG.h"
#include "HAL.h"
#include "gattprofile.h"
@ -29,6 +27,8 @@
#include "bsp_i2c.h"
#include "bsp_iwdg.h"
#include "bsp_flash.h"
#undef LOG_ENABLE
#define LOG_ENABLE 1
@ -36,7 +36,6 @@
#undef LOG_TAG
#define LOG_TAG "main"
// static uint8_t main_task_id = INVALID_TASK_ID;
__attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
@ -63,7 +62,6 @@ void app_task_handler(TeAppEvtType app_evt_type)
break;
}
}
/*********************************************************************
* @fn Main_Circulation
*
@ -72,14 +70,13 @@ void app_task_handler(TeAppEvtType app_evt_type)
* @return none
*/
__HIGH_CODE
__attribute__((noinline))
void Main_Circulation()
__attribute__((noinline)) void Main_Circulation()
{
while (1)
{
TMOS_SystemProcess();
KEY_ProcessLoop();
// BSP_UART1_TxLoop();
BSP_UART1_TxLoop();
#if 0
if (GPIOB_ReadPortPin(GPIO_Pin_7) == 0)
{
@ -162,7 +159,6 @@ void BLE_ConnectEventCB(uint32_t timeUs)
logDebug("BLE_ConnectEventCB");
}
/*********************************************************************
* @fn main
*
@ -175,9 +171,9 @@ int main(void)
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
PWR_DCDCCfg(ENABLE);
#endif
// 设置主频为60MHz
SetSysClock(CLK_SOURCE_PLL_60MHz);
#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
@ -188,12 +184,11 @@ int main(void)
// UART1_DefInit();
// 改成 1500000 波特率了
// 改成1500000波特率了
BSP_UART1_Init(1500000);
// logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
logError("中文测试 %2.2f", 123.456);
ShowRestartReason();
#endif
DelayMs(1000 * 3);
@ -206,25 +201,26 @@ int main(void)
BSP_ADC_Init();
CH59x_BLEInit();
logDebug("%s\n", VER_LIB);
uint8_t MacAddr[6];
GetMACAddress(MacAddr);
// 手机APP显示是倒序的[5-0],不是[0-5]
logDebug("MacAddr: %02X:%02X:%02X:%02X:%02X:%02X", MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]);
HAL_Init();
GAPRole_PeripheralInit();
Peripheral_Init();
// 在连接间隔和广播间隔到来时,会进入回调中喂狗
// LL_AdvertiseEventRegister(BLE_AdvertiseEventCB);
// LL_ConnectEventRegister(BLE_ConnectEventCB);
BSP_FLASH_Init();
DelayMs(100);
GXHTC3C_Init();
// while (1)
// {
// DelayMs(100);
// }
// BSP_KEY_Init();
BSP_KEY_Init(app_task_handler);
// IWDG_Init(1500);

View File

@ -1,21 +0,0 @@
struct __attribute__((packed)) valve_data
{
// uint8_t valve_id;
// uint8_t valve_mac[6];
uint8_t header;
uint8_t cmd;
uint8_t data_len;
uint8_t valve_type; // 阀门类型
uint8_t valve_bat; // 1B 电池电压 30=3V,18=1.8V
uint8_t valve_status; // 1B 阀门工作状态 超欠压、过流
uint8_t valve_connct_status; // 1B 阀门连接状态 电磁阀BLE控制盒 0=未连接 1=已连接
uint8_t valve_switch_status; // 1B 阀门开关状态 0=未知 1=关闭 2=关闭过,未按按键恢复 3=关闭过,按下了恢复键 4=打开
int8_t valve_temp; // 1B 阀门温度 有符号整数 25 ℃
uint8_t valve_humidity; // 1B 阀门湿度 0~100%;
uint32_t valve_in_pressure; // 4B 阀门入口压力 Pa
uint32_t valve_out_pressure; // 4B 阀门出口压力 Pa
uint32_t valve_atm_pressure; // 4B 阀门大气压力 Pa
uint8_t tail;
};

View File

@ -12,7 +12,7 @@
#define __BSP_ADC_H__
#include "CH59x_common.h"
#include "CONFIG.h"
void BSP_ADC_Init(void);

View File

@ -2,8 +2,8 @@
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-09 09:50:56
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-13 15:51:09
* @FilePath : \BLE_TYQ_CH592F\BSP\inc\bsp_beep_led_emv.h
* @LastEditTime : 2024-12-15 15:37:31
* @FilePath : \BLE_TYQ_CH592F - \BSP\inc\bsp_beep_led_emv.h
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
@ -11,7 +11,8 @@
#ifndef __BSP_BEEP_LED_EMV_H__
#define __BSP_BEEP_LED_EMV_H__
#include "CH59x_common.h"
#include "CONFIG.h"
/**********************BOOST 12V_EN************************ */
@ -105,4 +106,5 @@
GPIOB_ModeCfg(GPIO_Pin_12, GPIO_ModeIN_Floating); \
} while (0);
#endif // !__BSP_BEEP_LED_EMV_H__

View File

@ -1,3 +1,13 @@
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 15:42:00
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 15:42:00
* @FilePath : \BLE_TYQ_CH592F - \BSP\inc\bsp_i2c.h
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
#ifndef __BSP_I2C_H__
#define __BSP_I2C_H__

View File

@ -1,3 +1,13 @@
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 16:13:37
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:13:37
* @FilePath : \BLE_TYQ_CH592F - \BSP\inc\bsp_iwdg.h
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-14 10:51:01

View File

@ -1,3 +1,13 @@
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 15:01:15
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:24:28
* @FilePath : \BLE_TYQ_CH592F - \BSP\inc\bsp_tim.h
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
#ifndef __BSP_TIM_H__
#define __BSP_TIM_H__

View File

@ -42,7 +42,8 @@ static struct i2c_slave_cb *slave_cb = NULL;
#define MASTER_ADDR 0x42
uint8_t i2c_tx_data[2];
uint8_t i2c_rx_data[6];
// __attribute__((aligned(4)))
uint8_t i2c_rx_data[8];
void BSP_I2C_Init(uint8_t address)
{
@ -95,7 +96,7 @@ int I2C_Write(uint8_t addr_7bit, const uint8_t *data, uint8_t length,
i2c_master_buffer_index = 0;
i2c_master_buffer_length = length;
memcpy(i2c_master_buffer, data, length);
tmos_memcpy(i2c_master_buffer, data, length);
i2c_slave_addr_rw = I2C_WRITE;
i2c_slave_addr_rw |= addr_7bit << 1;
@ -201,7 +202,7 @@ int I2C_Read(uint8_t addr_7bit, uint8_t *data, uint8_t length,
length = i2c_master_buffer_index;
// copy i2c buffer to data
memcpy(data, i2c_master_buffer, length);
tmos_memcpy(data, i2c_master_buffer, length);
return length;
}
@ -279,7 +280,7 @@ void GXHTC3C_SendCmd(uint16_t cmd)
i2c_tx_data[0] = HI_UINT16(cmd);
i2c_tx_data[1] = LO_UINT16(cmd);
ret = I2C_Write(GXHTC3C_ADDR, (const uint8_t *)&i2c_tx_data, 2, true, true);
logDebug("GXHTC3C_SendCmd %s", ret ? "failed" : "success");
// logDebug("GXHTC3C_SendCmd %s", ret ? "failed" : "success");
}
void GXHTC3C_Sleep(void)
@ -361,8 +362,8 @@ uint8_t GXHTC3C_GetTempHumi(float *humi, float *temp)
if ((crc_humi == i2c_rx_data[2]) && (crc_temp == i2c_rx_data[5]))
{
logDebug("crc ok");
logHexDumpAll(i2c_rx_data, 6);
// logDebug("crc ok");
// logHexDumpAll(i2c_rx_data, 6);
*humi = (100.0 * raw_humi) / 65536.0; // 湿度真实值
*temp = (175.0 * raw_temp) / 65536.0 - 45.0; // 温度真实值
@ -375,6 +376,7 @@ uint8_t GXHTC3C_GetTempHumi(float *humi, float *temp)
logError("crc error");
return 2;
}
// logDebug("0 success");
return 0;
}
@ -391,6 +393,7 @@ void GXHTC3C_Read(void)
ret = GXHTC3C_GetTempHumi(&humi, &temp);
if (ret == 0)
{
// logDebug("ret=0");
logDebug("humi %.2f %, temp %.2f C", humi, temp);
}
@ -415,7 +418,7 @@ void GXHTC3C_Init(void)
ret = GXHTC3C_GetTempHumi(&humi, &temp);
if (ret == 0)
{
logDebug("humi %.2f %, temp %.2f C", humi, temp);
// logDebug("humi %.2f %, temp %.2f C", humi, temp);
}
GXHTC3C_Sleep();

View File

@ -1,3 +1,13 @@
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 16:13:41
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:13:42
* @FilePath : \BLE_TYQ_CH592F - \BSP\src\bsp_iwdg.c
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
#include "bsp_iwdg.h"
#include "bsp_uart.h"

View File

@ -1,3 +1,13 @@
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 15:01:15
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:24:32
* @FilePath : \BLE_TYQ_CH592F - ¸±±¾\BSP\src\bsp_tim.c
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
#include "bsp_tim.h"
// tick_1ms_cnt在SysTick_Handler()中1ms +1

View File

@ -3,6 +3,7 @@
#include "CH59x_uart.h"
#include "shell_port.h"
// https://www.cnblogs.com/iot-fan/p/14744671.html
lwrb_t Uart1Rx;

View File

@ -1,3 +1,13 @@
/*
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-12-15 15:01:15
* @LastEditors : stark1898y 1658608470@qq.com
* @LastEditTime : 2024-12-15 16:31:46
* @FilePath : \BLE_TYQ_CH592F - \BSP\src\bsp_valve.c
* @Description :
*
* Copyright (c) 2024 by yzy, All Rights Reserved.
*/
/*
* @Author: mbw
* @Date: 2024-12-09 11:40:10

View File

@ -38,6 +38,7 @@ void BSP_BlockSleep(void)
block_sleep_flag = true;
}
/*******************************************************************************
* @fn CH59x_LowPower
*
@ -112,7 +113,6 @@ uint32_t CH59x_LowPower(uint32_t time)
i = RTC_GetCycle32k();
while (i == RTC_GetCycle32k());
return 0;
}
#endif

View File

@ -142,7 +142,7 @@
#define PERIPHERAL_MAX_CONNECTION 1
#endif
#ifndef CENTRAL_MAX_CONNECTION
#define CENTRAL_MAX_CONNECTION 3
#define CENTRAL_MAX_CONNECTION 2
#endif
extern uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];

View File

@ -25,6 +25,7 @@ extern "C" {
void BSP_RequestSleep(void);
void BSP_BlockSleep(void);
/*********************************************************************
* FUNCTIONS
*/

View File

@ -46,11 +46,11 @@ extern "C" {
#define SIMPLEPROFILE_SERVICE 0x00000001
// Length of characteristic in bytes ( Default MTU is 23 )
#define SIMPLEPROFILE_CHAR1_LEN 30
#define SIMPLEPROFILE_CHAR2_LEN 30
#define SIMPLEPROFILE_CHAR3_LEN 30
#define SIMPLEPROFILE_CHAR4_LEN 30
#define SIMPLEPROFILE_CHAR5_LEN 30
#define SIMPLEPROFILE_CHAR1_LEN 64
#define SIMPLEPROFILE_CHAR2_LEN 64
#define SIMPLEPROFILE_CHAR3_LEN 64
#define SIMPLEPROFILE_CHAR4_LEN 64
#define SIMPLEPROFILE_CHAR5_LEN 64
/*********************************************************************
* TYPEDEFS

View File

@ -6,7 +6,7 @@
* Description
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
@ -249,7 +249,7 @@ int adc_to_temperature_celsius(uint16_t adc_val)
C25 = (*((PUINT32)ROM_CFG_TMP_25C));
/* current temperature = standard temperature + (adc deviation * adc linearity coefficient) */
/* current temperature = standard temperature + (adc deviation * adc linearity coefficient) */
temp = (((C25 >> 16) & 0xFFFF) ? ((C25 >> 16) & 0xFFFF) : 25) + \
(adc_val - ((int)(C25 & 0xFFFF))) * 100 / 283;