From d304f5e0de03ac47e04500261b447decdd0b931c Mon Sep 17 00:00:00 2001
From: stark1898y <1658608470@qq.com>
Date: Sun, 15 Dec 2024 17:22:09 +0800
Subject: [PATCH] Replace main branch content with new branch
---
.cproject | 15 +-
.settings/language.settings.xml | 2 +-
.settings/org.eclipse.core.resources.prefs | 3 -
.vscode/settings.json | 11 +-
APP/peripheral.c | 188 +++++++--------------
APP/peripheral_main.c | 30 ++--
BSP/inc/bsP_bt.h | 21 ---
BSP/inc/bsp_adc.h | 2 +-
BSP/inc/bsp_beep_led_emv.h | 8 +-
BSP/inc/bsp_i2c.h | 10 ++
BSP/inc/bsp_iwdg.h | 10 ++
BSP/inc/bsp_tim.h | 10 ++
BSP/src/bsp_i2c.c | 17 +-
BSP/src/bsp_iwdg.c | 10 ++
BSP/src/bsp_tim.c | 10 ++
BSP/src/bsp_uart.c | 1 +
BSP/src/bsp_valve.c | 10 ++
HAL/SLEEP.c | 2 +-
HAL/include/CONFIG.h | 2 +-
HAL/include/SLEEP.h | 1 +
Profile/include/gattprofile.h | 10 +-
StdPeriphDriver/CH59x_adc.c | 4 +-
22 files changed, 171 insertions(+), 206 deletions(-)
delete mode 100644 BSP/inc/bsP_bt.h
diff --git a/.cproject b/.cproject
index 78da63f..7420052 100644
--- a/.cproject
+++ b/.cproject
@@ -14,7 +14,7 @@
-
+
@@ -56,8 +56,6 @@
-
+
@@ -105,10 +103,9 @@
-
+
-
-
+
@@ -127,7 +124,7 @@
-
+
@@ -176,5 +173,5 @@
-
+
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index a1fa25e..18c8056 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
index 691bc15..a253c4c 100644
--- a/.settings/org.eclipse.core.resources.prefs
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -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
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 2dee5fa..dc0807a 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -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"
+ }
}
diff --git a/APP/peripheral.c b/APP/peripheral.c
index 4fb000f..47b8e37 100644
--- a/APP/peripheral.c
+++ b/APP/peripheral.c
@@ -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
-// adType:TRUE 更改广播数据,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);
}
+
+
+
diff --git a/APP/peripheral_main.c b/APP/peripheral_main.c
index a4375c3..00294cb 100644
--- a/APP/peripheral_main.c
+++ b/APP/peripheral_main.c
@@ -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);
diff --git a/BSP/inc/bsP_bt.h b/BSP/inc/bsP_bt.h
deleted file mode 100644
index 102bcf3..0000000
--- a/BSP/inc/bsP_bt.h
+++ /dev/null
@@ -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;
-};
diff --git a/BSP/inc/bsp_adc.h b/BSP/inc/bsp_adc.h
index bc5c354..93da33e 100644
--- a/BSP/inc/bsp_adc.h
+++ b/BSP/inc/bsp_adc.h
@@ -12,7 +12,7 @@
#define __BSP_ADC_H__
-#include "CH59x_common.h"
+#include "CONFIG.h"
void BSP_ADC_Init(void);
diff --git a/BSP/inc/bsp_beep_led_emv.h b/BSP/inc/bsp_beep_led_emv.h
index dd39ece..f009f8c 100644
--- a/BSP/inc/bsp_beep_led_emv.h
+++ b/BSP/inc/bsp_beep_led_emv.h
@@ -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__
diff --git a/BSP/inc/bsp_i2c.h b/BSP/inc/bsp_i2c.h
index 22704e4..ada6b44 100644
--- a/BSP/inc/bsp_i2c.h
+++ b/BSP/inc/bsp_i2c.h
@@ -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__
diff --git a/BSP/inc/bsp_iwdg.h b/BSP/inc/bsp_iwdg.h
index f7bcf33..70b167c 100644
--- a/BSP/inc/bsp_iwdg.h
+++ b/BSP/inc/bsp_iwdg.h
@@ -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
diff --git a/BSP/inc/bsp_tim.h b/BSP/inc/bsp_tim.h
index 9405455..4074919 100644
--- a/BSP/inc/bsp_tim.h
+++ b/BSP/inc/bsp_tim.h
@@ -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__
diff --git a/BSP/src/bsp_i2c.c b/BSP/src/bsp_i2c.c
index 926dfce..6ea2fc8 100644
--- a/BSP/src/bsp_i2c.c
+++ b/BSP/src/bsp_i2c.c
@@ -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();
diff --git a/BSP/src/bsp_iwdg.c b/BSP/src/bsp_iwdg.c
index bc47114..a4c5f80 100644
--- a/BSP/src/bsp_iwdg.c
+++ b/BSP/src/bsp_iwdg.c
@@ -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"
diff --git a/BSP/src/bsp_tim.c b/BSP/src/bsp_tim.c
index 6ab92fb..f8f71c9 100644
--- a/BSP/src/bsp_tim.c
+++ b/BSP/src/bsp_tim.c
@@ -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_cntSysTick_Handler()1ms +1
diff --git a/BSP/src/bsp_uart.c b/BSP/src/bsp_uart.c
index 283cd9e..8534726 100644
--- a/BSP/src/bsp_uart.c
+++ b/BSP/src/bsp_uart.c
@@ -3,6 +3,7 @@
#include "CH59x_uart.h"
#include "shell_port.h"
+// https://www.cnblogs.com/iot-fan/p/14744671.html
lwrb_t Uart1Rx;
diff --git a/BSP/src/bsp_valve.c b/BSP/src/bsp_valve.c
index 3cbf3e7..fe34fb3 100644
--- a/BSP/src/bsp_valve.c
+++ b/BSP/src/bsp_valve.c
@@ -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
diff --git a/HAL/SLEEP.c b/HAL/SLEEP.c
index 0b5b727..97be725 100644
--- a/HAL/SLEEP.c
+++ b/HAL/SLEEP.c
@@ -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
diff --git a/HAL/include/CONFIG.h b/HAL/include/CONFIG.h
index 4d10b1d..a633c3f 100644
--- a/HAL/include/CONFIG.h
+++ b/HAL/include/CONFIG.h
@@ -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];
diff --git a/HAL/include/SLEEP.h b/HAL/include/SLEEP.h
index 6488466..1e798dc 100644
--- a/HAL/include/SLEEP.h
+++ b/HAL/include/SLEEP.h
@@ -25,6 +25,7 @@ extern "C" {
void BSP_RequestSleep(void);
void BSP_BlockSleep(void);
+
/*********************************************************************
* FUNCTIONS
*/
diff --git a/Profile/include/gattprofile.h b/Profile/include/gattprofile.h
index 29b9340..163cdee 100644
--- a/Profile/include/gattprofile.h
+++ b/Profile/include/gattprofile.h
@@ -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
diff --git a/StdPeriphDriver/CH59x_adc.c b/StdPeriphDriver/CH59x_adc.c
index 6917234..1d1fcba 100644
--- a/StdPeriphDriver/CH59x_adc.c
+++ b/StdPeriphDriver/CH59x_adc.c
@@ -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;