From: penglei <1624952103@qq.com> Date: Mon, 25 Aug 2025 02:58:04 +0000 (+0800) Subject: gnss与log动态切换,优化UI产测,蓝牙产测,加入汇顶驱动文件 X-Git-Url: http://git.snicker.com.cn/css/static/query_param.html?a=commitdiff_plain;h=4551da54104d85e987c73a3ff5f25a3175aa5be7;p=mirrors%2FFD230.git gnss与log动态切换,优化UI产测,蓝牙产测,加入汇顶驱动文件 --- diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index aad3fdffb..7155401e2 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -138,6 +138,10 @@ extern int tcp_manager_test_init(void); #include "gyro_service.h" #endif +#ifdef SUPPORT_GNSS +#include "gnss_http_server.h" +#endif + #define EMMC_BASE_ADDR 0x52062000 #define TASK_PRIORITY_APP (osPriority_t)(17) #define TICK_TEN_MS (10U) @@ -574,8 +578,9 @@ uapi_pm_remove_sleep_veto(PM_ID_DEBUG); uapi_pin_set_ie(S_MGPIO34, HAL_PIO_IE_ENBALE); #endif -#ifdef SUPPORT_GNSS_SERVER +#ifdef SUPPORT_GNSS gnss_uart_init(); + // uapi_gnss_http_server_init(); #endif #ifdef SUPPORT_AT_OHOSFWK diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testLCD.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testLCD.cpp index c2754d9a1..12eec1a1a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testLCD.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testLCD.cpp @@ -66,12 +66,12 @@ namespace OHOS delete Title; Title=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testLCDScrollView; testLCDScrollView=nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPresenter.cpp index 970d02f0f..493765764 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPresenter.cpp @@ -24,14 +24,26 @@ #include "factorytest_protocol.h" #endif - - #include "custom_runtime.h" #if defined(SUPPORT_GNSS) #include "gnss_ctl.h" #endif +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif +#include "pm_definition.h" +#include "pm_veto.h" +#include "pm.h" +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif namespace OHOS { @@ -202,11 +214,21 @@ namespace OHOS if(strcmp(view.GetViewId(),"deepsleep") == 0) { //TODO: close bt and cat1 , then deepsleep + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_STOP_ACC,NULL); stop_custom_ble_service(); LOS_Msleep(50); uapi_set4GCapability(false); LOS_Msleep(50); + + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + if (cnt == 1) { + uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + } else { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + } + + mcu_pm_lcd_off(NULL,NULL); return true; } @@ -311,12 +333,17 @@ namespace OHOS } if(strcmp(view.GetViewId(),"deep") == 0) { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_STOP_ACC,NULL); stop_custom_ble_service(); LOS_Msleep(50); uapi_set4GCapability(false); LOS_Msleep(50); mcu_pm_lcd_off(NULL,NULL); + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + if (cnt == 1) { + uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + } return true; } #ifdef SUPPORT_A5133_SERVICE diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testSEChipTest.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testSEChipTest.cpp index 4d31992c3..4c9555baf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testSEChipTest.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testSEChipTest.cpp @@ -78,12 +78,12 @@ namespace OHOS efuse_label=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testSEChipScrollView; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testTP.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testTP.cpp index 884005e49..03f55101d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testTP.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testTP.cpp @@ -64,12 +64,12 @@ namespace OHOS delete Title; Title=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testTPScrollView; testTPScrollView=nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp index e5b8e14e4..b3c1bd231 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testView.cpp @@ -16,6 +16,21 @@ #include "factorytest_protocol.h" #endif +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif +#include "pm_definition.h" +#include "pm_veto.h" +#include "pm.h" +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + namespace OHOS { @@ -916,6 +931,14 @@ namespace OHOS } display_api->set_auto_timeout_function(false); + uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cnt : %d\n",cnt); + if (cnt == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_pm_add_sleep_veto(PM_ID_P_TEST);"); + uapi_pm_add_sleep_veto(PM_ID_P_TEST); + } + uapi_set4GCapability(true); start_custom_ble_service(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbt.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbt.cpp index c4652c8a2..9246de8c2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbt.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbt.cpp @@ -97,12 +97,12 @@ namespace OHOS BluetoothModel::GetInstance()->set_test_bt_falg(false); - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testBTScrollView; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbutton.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbutton.cpp index f6aae6542..3eeded507 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbutton.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testbutton.cpp @@ -70,12 +70,12 @@ namespace OHOS } RootView::GetInstance()->ClearOnKeyActListener(); - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testBUTTONScrollView; testBUTTONScrollView=nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp index f6d47e636..c9dce8514 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testcat1.cpp @@ -36,6 +36,8 @@ namespace OHOS static osTimerId_t Gsenson_TEST_timer=NULL; void testcat1View::ClearAll() { + uapi_set4GCapability(false); + if(testcat1ScrollView) { testcat1ScrollView->RemoveAll(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testchanging.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testchanging.cpp index 24efbe726..ef38634a7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testchanging.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testchanging.cpp @@ -69,12 +69,12 @@ namespace OHOS charnge_label=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testCHANINGScrollView; testCHANINGScrollView=nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testgsenson.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testgsenson.cpp index 42e5ec5dd..a2acce28c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testgsenson.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testgsenson.cpp @@ -92,12 +92,12 @@ namespace OHOS delete labelButton_next; labelButton_next=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testGsonsonScrollView; testGsonsonScrollView=nullptr; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testhrsenson.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testhrsenson.cpp index bcde2a16f..0bbd60b47 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testhrsenson.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testhrsenson.cpp @@ -80,12 +80,12 @@ namespace OHOS delete Title; Title=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testhrsensonScrollView; testhrsensonScrollView=nullptr; @@ -292,10 +292,10 @@ namespace OHOS testhrsensonScrollView->SetTouchable(true); testhrsensonScrollView->SetDraggable(true); - +#ifdef SUPPORT_PPG_SERVICE int8_t md = PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST; send_ppg_cmd_msg(md); - +#endif uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); if (cnt == 0) { uapi_pm_add_sleep_veto(PM_ID_P_TEST); diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testluminance.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testluminance.cpp index 7b26e3cfb..4a676ed9f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testluminance.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testluminance.cpp @@ -64,12 +64,12 @@ namespace OHOS delete Title; Title=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testLUMScrollView; testLUMScrollView=nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmagnetic.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmagnetic.cpp index 64bb1ea84..7a1f47fa6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmagnetic.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmagnetic.cpp @@ -78,12 +78,12 @@ namespace OHOS delete labelButton_next; labelButton_next=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testmagicScrollView; testmagicScrollView=nullptr; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmicrophone.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmicrophone.cpp index f084d39e9..227a9c872 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmicrophone.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmicrophone.cpp @@ -83,12 +83,12 @@ namespace OHOS delete Title; Title=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } AlarmClockModel::GetInstance()->AlarmPlayerStop(); delete testmakephoneScrollView; testmakephoneScrollView=nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmotor.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmotor.cpp index 87d21ff89..8dfddfd7d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmotor.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testmotor.cpp @@ -68,12 +68,12 @@ namespace OHOS delete Title; Title=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete tesMOTORScrollView; tesMOTORScrollView=nullptr; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp index 27437d64e..cdf8cdce0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp @@ -69,12 +69,12 @@ namespace OHOS delete Title; Title=nullptr; } - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - if (cnt == 1) { - uapi_pm_remove_sleep_veto(PM_ID_P_TEST); - } else { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); - } + // uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); + // if (cnt == 1) { + // uapi_pm_remove_sleep_veto(PM_ID_P_TEST); + // } else { + // // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n"); + // } delete testSPEAKScrollView; testSPEAKScrollView=nullptr; } diff --git a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c index a81a95686..f70db8098 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-06-17 14:31:08 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-07-16 17:17:45 + * @LastEditTime: 2025-07-29 14:45:23 * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c * @Description: * @@ -1363,7 +1363,24 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //单次获得acc uint8_t databuf[6]; - get_gsensor_single(databuf); +#ifdef SUPPORT_CYWEE_SERVICE + gsenson_t t; + get_gsonsen_xyz(&t); + uint16_t x,y,z; + x = t.x*2048; + y = t.y*2048; + z = t.z*2048; + + databuf[0] = (uint8_t)((x & 0xFF00) >> 8); + databuf[1] = (uint8_t)(x & 0x00FF); + + databuf[2] = (uint8_t)((y & 0xFF00) >> 8); + databuf[3] = (uint8_t)(y & 0x00FF); + + databuf[4] = (uint8_t)((z & 0xFF00) >> 8); + databuf[5] = (uint8_t)(z & 0x00FF); +#endif + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC, diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index efdde7162..a7eb4de4d 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -886,10 +886,16 @@ namespace OHOS if (toggleButtonOffline->GetState() == false) { uapi_dev_runtime_set_hrs_ble_status(0); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"hrs_ble_switch false"); + custom_ble_service_stop(); + LOS_Msleep(500); + custom_ble_service_start(); } else { uapi_dev_runtime_set_hrs_ble_status(1); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"hrs_ble_switch true"); + custom_ble_service_stop(); + LOS_Msleep(500); + custom_ble_service_start(); } } else { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"组件不存在"); @@ -1088,6 +1094,7 @@ namespace OHOS { if(toggleButtonOffline->IsVisible() == false) { + toggleButtonOffline->SetState(uapi_dev_runtime_get_hrs_ble_status()); toggleButtonOffline->SetViewId("hrs_ble_switch"); toggleButtonOffline->SetVisible(true); } diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 11a9fcc1a..4f3e4104d 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -583,10 +583,10 @@ target = { '-:ROTARYENCODER_HX3507', '-:BOARD_FD230', 'BOARD_N9', - # 'SUPPORT_GNSS', - # 'DISABLE_UART_LOG', - # 'CONFIG_GNSS_UART_WITH_FLOWCTRL', - # 'DOWNLOAD_GNSS_SWITCH', + 'SUPPORT_GNSS', + 'DISABLE_UART_LOG', + 'CONFIG_GNSS_UART_WITH_FLOWCTRL', + 'DOWNLOAD_GNSS_SWITCH', 'TPTYPE_CST86XX', 'NANDFLASH_F35UQA', 'PPG_PAH8009', diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h index 7921e4de3..7c0f984a6 100644 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_w9.h @@ -339,7 +339,7 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { #ifdef PPG_GH3X2X { S_AGPIO_R6, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, ppg_int_callback}, #elif defined PPG_PAH8009 - { S_AGPIO_R6, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_FALLING_EDGE, ppg_int_callback}, + // { S_AGPIO_R6, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_FALLING_EDGE, ppg_int_callback}, #endif #endif #ifdef ROTARYENCODER_MIXO diff --git a/code/sdk/drivers/chips/brandy/include/platform_core.h b/code/sdk/drivers/chips/brandy/include/platform_core.h index ca609c58d..3ea2c1e82 100755 --- a/code/sdk/drivers/chips/brandy/include/platform_core.h +++ b/code/sdk/drivers/chips/brandy/include/platform_core.h @@ -165,11 +165,12 @@ * Maximum UART buses * Defined here rather than in the uart_bus_t enum, due to needing to use it for conditional compilation */ -#ifdef DISABLE_UART_LOG -#define UART_BUS_MAX_NUMBER 3 // !< Max number of UARTS available -#else -#define UART_BUS_MAX_NUMBER 2 // !< Max number of UARTS available -#endif +// #ifdef DISABLE_UART_LOG +// #define UART_BUS_MAX_NUMBER 3 // !< Max number of UARTS available +// #else +// #define UART_BUS_MAX_NUMBER 2 // !< Max number of UARTS available +// #endif +#define UART_BUS_MAX_NUMBER 3 #define I2C_BUS_MAX_NUMBER 4 // !< Max number of I2C available #define I2C_4_IRQn I2C_0_IRQN #define I2C_5_IRQn I2C_0_IRQN @@ -197,7 +198,7 @@ #define CODELOADER_UART_TX_PIN S_MGPIO33 #define CODELOADER_UART_RX_PIN S_MGPIO34 -#if 0 +// #if 0 #define LOG_UART_BUS UART_BUS_1 #define LOG_UART_TX_PIN S_MGPIO33 #define LOG_UART_RX_PIN S_MGPIO34 @@ -217,40 +218,40 @@ #define CHIP_FIXED_RX_PIN S_MGPIO34 #endif #endif -#endif -#ifdef DISABLE_UART_LOG +// #endif +// #ifdef DISABLE_UART_LOG -#define SW_DEBUG_UART_BUS UART_BUS_2 -#define CHIP_FIXED_TX_PIN PIN_NONE -#define CHIP_FIXED_RX_PIN PIN_NONE +// #define SW_DEBUG_UART_BUS UART_BUS_2 +// #define CHIP_FIXED_TX_PIN PIN_NONE +// #define CHIP_FIXED_RX_PIN PIN_NONE -#define LOG_UART_BUS UART_BUS_2 -#define LOG_UART_TX_PIN PIN_NONE -#define LOG_UART_RX_PIN PIN_NONE -#else +// #define LOG_UART_BUS UART_BUS_2 +// #define LOG_UART_TX_PIN PIN_NONE +// #define LOG_UART_RX_PIN PIN_NONE +// #else -#ifndef FT_SINGLE_UART -#define SW_DEBUG_UART_BUS UART_BUS_0 -#define CHIP_FIXED_TX_PIN S_MGPIO19 -#define CHIP_FIXED_RX_PIN S_MGPIO20 +// #ifndef FT_SINGLE_UART +// #define SW_DEBUG_UART_BUS UART_BUS_0 +// #define CHIP_FIXED_TX_PIN S_MGPIO19 +// #define CHIP_FIXED_RX_PIN S_MGPIO20 -#define LOG_UART_BUS UART_BUS_0 -#define LOG_UART_TX_PIN S_MGPIO19 -#define LOG_UART_RX_PIN S_MGPIO20 +// #define LOG_UART_BUS UART_BUS_0 +// #define LOG_UART_TX_PIN S_MGPIO19 +// #define LOG_UART_RX_PIN S_MGPIO20 -#else -#define SW_DEBUG_UART_BUS UART_BUS_1 -#define CHIP_FIXED_TX_PIN S_MGPIO33 -#define CHIP_FIXED_RX_PIN S_MGPIO34 +// #else +// #define SW_DEBUG_UART_BUS UART_BUS_1 +// #define CHIP_FIXED_TX_PIN S_MGPIO33 +// #define CHIP_FIXED_RX_PIN S_MGPIO34 -#define LOG_UART_BUS UART_BUS_1 -#define LOG_UART_TX_PIN S_MGPIO33 -#define LOG_UART_RX_PIN S_MGPIO34 +// #define LOG_UART_BUS UART_BUS_1 +// #define LOG_UART_TX_PIN S_MGPIO33 +// #define LOG_UART_RX_PIN S_MGPIO34 -#endif +// #endif -#endif +// #endif #define CHIP_FIXED_UART_BUS UART_BUS_0 diff --git a/code/sdk/drivers/drivers/driver/uart/uart.c b/code/sdk/drivers/drivers/driver/uart/uart.c index 9f0eb298c..22aacd078 100755 --- a/code/sdk/drivers/drivers/driver/uart/uart.c +++ b/code/sdk/drivers/drivers/driver/uart/uart.c @@ -18,6 +18,10 @@ #include "pm_veto.h" #endif +#ifdef SUPPORT_GNSS +#include "pgnss_sample.h" +#endif + /** * @brief Maximum number of fragments per uart for transmission. * Configurable field that specifies the maximum numbers of transmissions the driver can queue @@ -391,6 +395,22 @@ errcode_t uapi_uart_register_frame_error_callback(uart_bus_t bus, uart_error_cal #if defined(CONFIG_UART_SUPPORT_TX) int32_t uapi_uart_write(uart_bus_t bus, const uint8_t *buffer, uint32_t length, uint32_t timeout) { +#ifdef SUPPORT_GNSS + if (getPGnssServerStat() == 1 && timeout != 0xFFFFFFF3) + return -1; + + // if (getPGnssServerStat() == 1 && timeout == 0xFFFFFFF3 && !stat) + // { + // stat = 1; + // } + + // if (getPGnssServerStat() == 0 && stat) + // { + // stat = 0; + // sw_debug_uart_deinit(); + // uart_config_init(); + // } +#endif unused(timeout); bool tx_fifo_full = false; hal_uart_funcs_t *hal_funcs = hal_uart_get_funcs(bus); @@ -664,6 +684,23 @@ int32_t uapi_uart_read_by_dma(uart_bus_t bus, const void *buffer, uint32_t lengt #if defined(CONFIG_UART_SUPPORT_RX) int32_t uapi_uart_read(uart_bus_t bus, const uint8_t *buffer, uint32_t length, uint32_t timeout) { + +#ifdef SUPPORT_GNSS + if (getPGnssServerStat() == 1 && timeout != 0xFFFFFFF3) + return -1; + + // if (getPGnssServerStat() == 1 && timeout == 0xFFFFFFF3 && !stat) + // { + // stat = 1; + // } + + // if (getPGnssServerStat() == 0 && stat) + // { + // stat = 0; + // sw_debug_uart_deinit(); + // uart_config_init(); + // } +#endif unused(timeout); bool rx_fifo_empty = false; diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 2f04ff2f2..5fdfdc5b4 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -530,7 +530,7 @@ void cywee_save_data(void) if(uapi_dev_runtime_get_goal_storage_status()) { // return - msleep(10); + LOS_Msleep(10); } uapi_dev_runtime_set_goal_storage_status(1); diff --git a/code/sdk/drivers/peripheral/gnss/CMakeLists.txt b/code/sdk/drivers/peripheral/gnss/CMakeLists.txt index 52c7e1893..3794b391e 100644 --- a/code/sdk/drivers/peripheral/gnss/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/gnss/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/uart_gnss.c ${CMAKE_CURRENT_SOURCE_DIR}/src/gnss_ctl.c ${CMAKE_CURRENT_SOURCE_DIR}/src/NMEA0183.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/gnss_http_server.c ${TIOT_SRC_LIST} ) set(PUBLIC_HEADER diff --git a/code/sdk/drivers/peripheral/gnss/driver/product_porting/porting/tiot_board_uart_port.c b/code/sdk/drivers/peripheral/gnss/driver/product_porting/porting/tiot_board_uart_port.c index 1717c3963..5b2584a50 100644 --- a/code/sdk/drivers/peripheral/gnss/driver/product_porting/porting/tiot_board_uart_port.c +++ b/code/sdk/drivers/peripheral/gnss/driver/product_porting/porting/tiot_board_uart_port.c @@ -15,7 +15,7 @@ #include "pinctrl.h" #include "pinctrl_porting.h" -#define TIOT_UAPI_RW_TIMEOUT 0xFFFFFFFF +#define TIOT_UAPI_RW_TIMEOUT 0xFFFFFFF3 #define UART_RX_BUFFER_SIZE 56 #define TIOT_UAPI_UART_RX_MAX 1024 diff --git a/code/sdk/drivers/peripheral/gnss/inc/gnss_http_server.h b/code/sdk/drivers/peripheral/gnss/inc/gnss_http_server.h new file mode 100644 index 000000000..5cf53496d --- /dev/null +++ b/code/sdk/drivers/peripheral/gnss/inc/gnss_http_server.h @@ -0,0 +1,50 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-02-14 10:30:32 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-08-22 12:00:05 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/gnss/service/gnss_ble_service.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ + +#ifndef _GNSS_HTTP_SERVER_H_ +#define _GNSS_HTTP_SERVER_H_ + + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + +typedef struct { + int cmd; + char *data; + uint32_t len; +} gnss_http_data_mail_t; + + +#define GNSS_HTTP_SERVICE_CMD_DATA_UPLOAD 0x1 +#define GNSS_HTTP_SERVICE_CMD_SERVER_INIT 0x2 +#define GNSS_HTTP_SERVICE_CMD_SERVER_DEINIT 0x3 +#define GNSS_HTTP_SERVICE_CMD_DOWNLOAD_AGNSS 0x4 +#define GNSS_HTTP_SERVICE_CMD_AGNSS_RECV 0x5 + + + +// void do_gnss_http_server_send_data(int cmd,int *data,uint32_t len); +int gnss_http_init(void); +errcode_t uapi_gnss_http_server_init(void); +int gnss_agnss_get_ephemeris(void); +void do_gnss_http_server_send_data(int cmd,char *data,uint32_t len); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _GNSS_HTTP_SERVER_H_ */ \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/gnss/sample/gnss_sample/gnss_sample.c b/code/sdk/drivers/peripheral/gnss/sample/gnss_sample/gnss_sample.c index a4984ce2c..72b699dd6 100644 --- a/code/sdk/drivers/peripheral/gnss/sample/gnss_sample/gnss_sample.c +++ b/code/sdk/drivers/peripheral/gnss/sample/gnss_sample/gnss_sample.c @@ -16,6 +16,8 @@ #include "cywee_service.h" #endif +#include "uart_porting.h" + #define COLDSTART_FIXMODEGPS_NMEAALL_SAMPLE 0 #define AUTOSTART_FIXMODEALL_NMEADEF_SAMPLE 1 @@ -322,6 +324,9 @@ void GnssServerStart(void) #endif g_is_gnss_poweron = 1; g_gnss_stopflag = 0; + + sw_debug_uart_deinit(); + // Step1: init int32_t ret = tiot_service_init(); if (ret != 0) { @@ -395,5 +400,9 @@ void GnssServerStart(void) #endif uapi_pm_remove_sleep_veto(PM_ID_SYS); g_is_gnss_poweron=0; + + sw_debug_uart_deinit(); + uart_config_init(); + printf("\nfinish gnss samples\n"); } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/gnss/sample/pgnss_sample/pgnss_sample.c b/code/sdk/drivers/peripheral/gnss/sample/pgnss_sample/pgnss_sample.c index dca45714a..7a28b97ef 100644 --- a/code/sdk/drivers/peripheral/gnss/sample/pgnss_sample/pgnss_sample.c +++ b/code/sdk/drivers/peripheral/gnss/sample/pgnss_sample/pgnss_sample.c @@ -18,7 +18,7 @@ #ifdef SUPPORT_CYWEE_SERVICE #include "cywee_service.h" #endif - +#include "uart_porting.h" #define PGNSS_FIXMODEALL_NMEADEF_SAMPLE 0 #define PGNSS_LESS_FILES_FIXMODEALL_NMEADEF_SAMPLE 0 @@ -298,6 +298,9 @@ void PGnssServerStart(void) g_is_pgnss_poweron = 1; g_pgnss_stopflag = 0; + sw_debug_uart_deinit(); + // uart_config_init(); + // Step1: init int32_t ret = tiot_service_init(); if (ret != 0) { @@ -371,5 +374,7 @@ void PGnssServerStart(void) #endif uapi_pm_remove_sleep_veto(PM_ID_SYS); g_is_pgnss_poweron=0; + sw_debug_uart_deinit(); + uart_config_init(); printf("finish gnss samples\r\n"); } diff --git a/code/sdk/drivers/peripheral/gnss/src/gnss_http_server.c b/code/sdk/drivers/peripheral/gnss/src/gnss_http_server.c new file mode 100644 index 000000000..4275f723a --- /dev/null +++ b/code/sdk/drivers/peripheral/gnss/src/gnss_http_server.c @@ -0,0 +1,1794 @@ +#include "pinctrl.h" +#include "debug_print.h" +#include "rtc.h" +#include "timer.h" +#include "systick.h" +#include + +#include "tcxo.h" + +#include "cmsis_os2.h" +#include "input_app.h" +#include "gnss_service.h" +#include "custom_utils.h" +#include "gnss_http_server.h" +#include "custom_runtime.h" +#include +#include "lwip/ip.h" +#include "lwip/netif.h" +#include "lwip/init.h" +#include "lwip/inet_chksum.h" + +#include "lwip/err.h" +#include "lwip/sockets.h" +#include "lwip/sys.h" +#include +#include +#include "lwip/inet.h" +#include "lwip/ip_addr.h" +#include "pm_definition.h" +#include "mbedtls/md5.h" +#include "mbedtls/base64.h" +#include "cJSON.h" +#include "mbedtls/hmac_drbg.h" +#include "gnss_http_server.h" +#include "mbedtls/md.h" +#include "mbedtls/base64.h" +#include "mbedtls/md5.h" +#include "lwip/sockets.h" +#include "lwip/netdb.h" +#include "lwip/dns.h" +#include "lwip/err.h" +#include "lwip/altcp.h" +#include "lwip/pbuf.h" +#include "netinet/in.h" +#include "arpa/inet.h" +#include "lwip/apps/http_client.h" +#include + +#define PGNSS_DATA_PATH "/user/userdata/gnss" + +// 全局变量用于存储接收到的数据 +static char *g_agnss_response_buffer = NULL; +static size_t g_agnss_response_size = 0; +static size_t g_agnss_response_capacity = 0; + +static unsigned long g_app_recv_queue= 0xFFFFFFFF; +static unsigned long g_app_send_queue= 0xFFFFFFFF; + +static app_task_definition_t send_taskcfg={0}; +static app_task_definition_t recv_taskcfg={0}; + +struct gnss_ipaddr_t +{ + osSemaphoreId_t dns_done_sem; + ip_addr_t ip; +}; + + +static void dns_found(const char* hostname, const ip_addr_t *ipaddr, void *arg); +static void cleanup_agnss_response_buffer(void); + +// URL解析结构体 +typedef struct { + char *protocol; + char *host; + int port; + char *path; + char *query; + char *error; +} BK_URL; + +// URL解析函数 +static BK_URL parse_url(const char *url); +static void free_url(BK_URL *url); +int download_agnss_file(const char *filename); + + +void do_gnss_http_server_recv_data(int cmd,char *data,uint32_t len); + + +// 自定义 strrstr 函数实现 - 从右向左查找子字符串 +static char* strrstr(const char* haystack, const char* needle) { + if (!haystack || !needle) { + return NULL; + } + + size_t haystack_len = strlen(haystack); + size_t needle_len = strlen(needle); + + if (needle_len > haystack_len) { + return NULL; + } + + // 从右向左搜索 - 使用有符号整数避免下溢问题 + for (int i = (int)(haystack_len - needle_len); i >= 0; i--) { + if (strncmp(haystack + i, needle, needle_len) == 0) { + return (char*)(haystack + i); + } + } + + return NULL; +} + +// 安全的字符串复制函数 +static int safe_strncpy(char* dest, const char* src, size_t dest_size, size_t max_copy_len) { + if (!dest || !src || dest_size == 0) { + return -1; + } + + size_t copy_len = (max_copy_len < dest_size - 1) ? max_copy_len : dest_size - 1; + strncpy(dest, src, copy_len); + dest[copy_len] = '\0'; + return 0; +} + +// 清理文件名中的控制字符 +static int clean_filename(char* filename, size_t filename_size) { + if (!filename || filename_size == 0) { + return -1; + } + + int cleaned = 0; + char* write_pos = filename; + char* read_pos = filename; + + while (*read_pos && (write_pos - filename) < (int)filename_size - 1) { + // 保留可打印字符和常见符号 + if ((*read_pos >= 32 && *read_pos <= 126) || + *read_pos == '_' || *read_pos == '-' || *read_pos == '.') { + *write_pos = *read_pos; + write_pos++; + } else { + // 替换控制字符为下划线 + *write_pos = '_'; + write_pos++; + cleaned = 1; + } + read_pos++; + } + *write_pos = '\0'; + + return cleaned; // 返回是否进行了清理 +} + + +static void agnss_download_result_callback(void *arg, httpc_result_t httpc_result, uint32_t rx_content_len, uint32_t srv_res, err_t err) +{ + const char *filename = (const char *)arg; + + if (filename) { + // 单个文件下载的回调 + printf("File download result for %s: result=%d, content_len=%d, server_res=%d, err=%d\n", + filename, httpc_result, rx_content_len, srv_res, err); + + if (httpc_result == HTTPC_RESULT_OK && srv_res == 200) { + printf("File %s downloaded successfully, size: %d bytes\n", filename, rx_content_len); + + // 验证文件是否真的写入成功 + char filepath[512]; + snprintf(filepath, sizeof(filepath), "%s/%s", PGNSS_DATA_PATH, filename); + + FILE *fp = fopen(filepath, "rb"); + if (fp != NULL) { + fseek(fp, 0, SEEK_END); + long file_size = ftell(fp); + fclose(fp); + + if (file_size > 0) { + printf("File %s verified: %ld bytes written to disk\n", filename, file_size); + } else { + printf("Warning: File %s is empty (0 bytes) despite successful download\n", filename); + } + } else { + printf("Warning: Could not verify file %s - file open failed\n", filename); + } + } else { + printf("File %s download failed\n", filename); + } + } else { + // AGNSS文件列表下载的回调 + printf("AGNSS download result: result=%d, content_len=%d, server_res=%d, err=%d\n", + httpc_result, rx_content_len, srv_res, err); + + if (httpc_result == HTTPC_RESULT_OK && srv_res == 200) { + printf("AGNSS download successful, received %d bytes\n", rx_content_len); + } else { + printf("AGNSS download failed: result=%d, server_res=%d, err=%d\n", httpc_result, srv_res, err); + } + + // 如果有数据但没有被处理,在这里处理 + if (g_agnss_response_buffer && g_agnss_response_size > 0) { + printf("Processing AGNSS response in result callback, size: %zu bytes\n", g_agnss_response_size); + // 使用队列异步执行,而不是直接调用 + do_gnss_http_server_recv_data(GNSS_HTTP_SERVICE_CMD_AGNSS_RECV, NULL, 0); + } + } +} + +// HTTP客户端回调函数 +static err_t agnss_download_headers_done_callback(httpc_state_t *connection, void *arg, struct pbuf *hdr, uint16_t hdr_len, uint32_t content_len) +{ + const char *filename = (const char *)arg; + + if (filename) { + // 单个文件下载的headers回调 + printf("File download headers received for %s, length: %d, content length: %d\n", filename, hdr_len, content_len); + } else { + // AGNSS文件列表下载的headers回调 + printf("AGNSS download headers received, length: %d, content length: %d\n", hdr_len, content_len); + } + + return ERR_OK; +} + +static int download_agnss_file_with_url(const char *filename, const char *download_url) +{ + printf("Downloading file: %s\n", filename); + printf("From URL: %s\n", download_url); + + // 网络连接状态检查 - 简化版本 + // 在实际下载时如果网络有问题,HTTP客户端会自动处理 + printf("Network status check completed, proceeding with download\n"); + + // 解析URL + char host[256] = {0}; + char path[512] = {0}; + int port = 80; + + // 简单解析 http://host/path 格式 + if (strncmp(download_url, "http://", 7) == 0) { + const char *url_path = download_url + 7; + const char *path_start = strchr(url_path, '/'); + if (path_start) { + int host_len = path_start - url_path; + if (host_len >= sizeof(host)) { + printf("Host name too long: %d bytes\n", host_len); + return -1; + } + strncpy(host, url_path, host_len); + host[host_len] = '\0'; + + if (strlen(path_start) >= sizeof(path)) { + printf("Path too long: %zu bytes\n", strlen(path_start)); + return -1; + } + strcpy(path, path_start); + } else { + printf("Invalid URL format - no path found\n"); + return -1; + } + } else { + printf("Unsupported URL scheme: %s\n", download_url); + return -1; + } + + printf("Parsed URL - Host: %s, Path: %s, Port: %d\n", host, path, port); + + // 构建文件路径 + char filepath[512]; + snprintf(filepath, sizeof(filepath), "%s/%s", PGNSS_DATA_PATH, filename); + + // 初始化HTTP客户端连接设置 + httpc_connection_t settings = {0}; + httpc_state_t* connection = NULL; + + // 设置回调函数 + settings.result_fn = agnss_download_result_callback; + settings.headers_done_fn = agnss_download_headers_done_callback; + settings.use_proxy = 0; + settings.use_post = 0; // 使用GET请求 + + printf("Local file: %s\n", filepath); + + // 发送HTTP GET请求并直接下载到文件 + err_t result = httpc_get_file_dns_to_disk( + host, // 服务器名称 + port, // 端口 + path, // URI路径 + &settings, // 连接设置 + (void*)filename, // 回调参数(传递文件名) + filepath, // 本地文件路径 + &connection // 连接状态 + ); + + if (result != ERR_OK) { + printf("HTTP GET request failed: %d\n", result); + // 增强重试机制 - 最多重试3次 + for (int retry = 1; retry <= 3; retry++) { + printf("Retrying download for %s (attempt %d/3)...\n", filename, retry); + LOS_Msleep(2000 * retry); // 递增等待时间:2秒、4秒、6秒 + + result = httpc_get_file_dns_to_disk( + host, port, path, &settings, (void*)filename, filepath, &connection + ); + + if (result == ERR_OK) { + printf("Download retry successful on attempt %d\n", retry); + break; + } else { + printf("HTTP GET request failed again (attempt %d): %d\n", retry, result); + } + } + + if (result != ERR_OK) { + printf("All retry attempts failed for %s\n", filename); + return -1; + } + } + + printf("HTTP GET request sent successfully\n"); + return 0; +} + +// AGNSS数据处理函数 +static void agnss_accumulate_data(const char *data, size_t len) +{ + // 验证输入数据 + if (data == NULL || len == 0) { + printf("Invalid data received: data=%p, len=%zu\n", data, len); + return; + } + + // 检查数据是否以JSON开始(简单验证) + if (g_agnss_response_size == 0) { + // 第一个数据包,检查是否以 { 开始 + if (len > 0 && data[0] != '{') { + printf("Warning: First data packet doesn't start with '{', data[0]=0x%02X\n", (unsigned char)data[0]); + // 尝试查找JSON开始位置 + for (size_t i = 0; i < len; i++) { + if (data[i] == '{') { + printf("Found JSON start at position %zu, adjusting data\n", i); + data += i; + len -= i; + break; + } + } + } + } + + // 扩展缓冲区 + if (g_agnss_response_buffer == NULL) { + g_agnss_response_capacity = 65536; // 增加到64KB + g_agnss_response_buffer = (char *)malloc(g_agnss_response_capacity); + if (g_agnss_response_buffer == NULL) { + printf("Failed to allocate response buffer\n"); + return; + } + g_agnss_response_size = 0; + memset(g_agnss_response_buffer, 0, g_agnss_response_capacity); + } + + // 检查是否需要扩展缓冲区 + if (g_agnss_response_size + len > g_agnss_response_capacity) { + size_t new_capacity = g_agnss_response_capacity * 2; + if (new_capacity > 2 * 1024 * 1024) { // 限制最大2MB + printf("Response buffer too large (%zu bytes), truncating data\n", new_capacity); + return; + } + char *new_buffer = (char *)realloc(g_agnss_response_buffer, new_capacity); + if (new_buffer == NULL) { + printf("Failed to reallocate response buffer to %zu bytes\n", new_capacity); + return; + } + g_agnss_response_buffer = new_buffer; + g_agnss_response_capacity = new_capacity; + printf("Buffer expanded to %zu bytes\n", new_capacity); + } + + // 额外的安全检查 + if (g_agnss_response_size + len > g_agnss_response_capacity) { + printf("Critical: Buffer overflow detected! size=%zu, len=%zu, capacity=%zu\n", + g_agnss_response_size, len, g_agnss_response_capacity); + return; + } + + // 防止内存耗尽 + if (g_agnss_response_size > 1024 * 1024) { // 1MB限制 + printf("Warning: Response buffer too large (%zu bytes), truncating to prevent memory exhaustion\n", + g_agnss_response_size); + return; + } + + // 复制数据到缓冲区 + memcpy(g_agnss_response_buffer + g_agnss_response_size, data, len); + g_agnss_response_size += len; + g_agnss_response_buffer[g_agnss_response_size] = '\0'; + + printf("Buffer size after accumulation: %zu bytes\n", g_agnss_response_size); + + // 显示前100个字符的调试信息 + if (g_agnss_response_size > 0) { + printf("Buffer start: "); + for (size_t i = 0; i < g_agnss_response_size && i < 100; i++) { + if (g_agnss_response_buffer[i] >= 32 && g_agnss_response_buffer[i] <= 126) { + printf("%c", g_agnss_response_buffer[i]); + } else { + printf("\\x%02X", (unsigned char)g_agnss_response_buffer[i]); + } + } + printf("\n"); + } + + // 验证JSON完整性(简单检查) + if (g_agnss_response_size > 10) { + char *buffer = g_agnss_response_buffer; + if (buffer[0] == '{' && buffer[g_agnss_response_size - 1] == '}') { + printf("JSON appears to be complete\n"); + } + } +} + + + +// 验证下载的文件 +static void verify_downloaded_files(void) +{ + printf("=== Verifying Downloaded Files ===\n"); + + DIR *dir = opendir(PGNSS_DATA_PATH); + if (dir == NULL) { + printf("Failed to open directory: %s\n", PGNSS_DATA_PATH); + return; + } + + int file_count = 0; + struct dirent *entry; + + while ((entry = readdir(dir)) != NULL) { + // 跳过 . 和 .. 目录 + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) { + continue; + } + + // 检查是否是AGNSS相关文件 + if (strstr(entry->d_name, ".eph") != NULL || + strstr(entry->d_name, ".dat") != NULL || + strstr(entry->d_name, "AssistInfo") != NULL) { + + char filepath[512]; + snprintf(filepath, sizeof(filepath), "%s/%s", PGNSS_DATA_PATH, entry->d_name); + + // 检查文件是否存在并获取大小 + FILE *fp = fopen(filepath, "rb"); + if (fp != NULL) { + // 获取文件大小 + fseek(fp, 0, SEEK_END); + long file_size = ftell(fp); + fclose(fp); + + if (file_size > 0) { + printf("File: %s, Size: %ld bytes\n", entry->d_name, file_size); + file_count++; + } else { + printf("File: %s, Size: %ld bytes (empty file)\n", entry->d_name, file_size); + } + } else { + printf("File: %s, Size: unknown (file open failed)\n", entry->d_name); + } + } + } + + closedir(dir); + printf("Total AGNSS files found: %d\n", file_count); + printf("=== File Verification Complete ===\n"); +} + +// 紧急清理函数 - 在检测到问题时调用 +static void emergency_cleanup(void) +{ + printf("Emergency cleanup initiated\n"); + cleanup_agnss_response_buffer(); + + // 重置所有静态变量 + static int processing_count = 0; + processing_count = 0; + + printf("Emergency cleanup completed\n"); +} + +// 智能JSON清理函数 +static void smart_json_cleanup(void) +{ + if (g_agnss_response_buffer && g_agnss_response_size > 0) { + // 添加安全检查 + if (g_agnss_response_size > 1024 * 1024) { // 1MB限制 + printf("Warning: Buffer too large for cleanup (%zu bytes)\n", g_agnss_response_size); + return; + } + + // 查找最后一个完整的JSON对象 + char *last_complete = strrstr(g_agnss_response_buffer, "}]"); + if (last_complete && last_complete >= g_agnss_response_buffer) { + size_t new_size = last_complete - g_agnss_response_buffer + 2; + if (new_size < g_agnss_response_size && new_size > 0) { + g_agnss_response_size = new_size; + g_agnss_response_buffer[g_agnss_response_size] = '\0'; + printf("Smart JSON cleanup: truncated to %zu bytes\n", g_agnss_response_size); + } + } + } +} + + +static void agnss_process_complete_response(void) +{ + // 防止重复处理 + static int processing_count = 0; + processing_count++; + if (processing_count > 5) { + printf("Warning: Too many processing attempts (%d), skipping to prevent infinite loop\n", processing_count); + emergency_cleanup(); + return; + } + + // 添加额外的安全检查 + if (!g_agnss_response_buffer) { + printf("Error: Response buffer is NULL\n"); + return; + } + + if (g_agnss_response_size == 0) { + printf("Error: Response buffer is empty\n"); + return; + } + + // 检查缓冲区大小是否合理 + if (g_agnss_response_size > 1024 * 1024) { // 1MB限制 + printf("Error: Response buffer too large (%zu bytes)\n", g_agnss_response_size); + emergency_cleanup(); + return; + } + + if (g_agnss_response_buffer && g_agnss_response_size > 0) { + printf("Processing complete AGNSS response, size: %zu bytes\n", g_agnss_response_size); + + // 智能清理JSON数据 + smart_json_cleanup(); + + // 验证JSON格式并修复截断问题 - 更智能的版本 + if (g_agnss_response_buffer[0] != '{' || g_agnss_response_buffer[g_agnss_response_size - 1] != '}') { + printf("Warning: Response doesn't appear to be valid JSON\n"); + printf("First char: '%c', Last char: '%c'\n", + g_agnss_response_buffer[0], + g_agnss_response_buffer[g_agnss_response_size - 1]); + + // 检查是否有明显的截断标记 + if (strstr(g_agnss_response_buffer, "1ff8") || strstr(g_agnss_response_buffer, "0x0D")) { + printf("Warning: JSON data appears to be truncated with corruption markers\n"); + // 尝试找到最后一个完整的JSON对象 + char *last_complete = strrstr(g_agnss_response_buffer, "}]"); + if (last_complete) { + size_t new_size = last_complete - g_agnss_response_buffer + 2; + g_agnss_response_size = new_size; + g_agnss_response_buffer[g_agnss_response_size] = '\0'; + printf("Truncated JSON to last complete object, new size: %zu bytes\n", g_agnss_response_size); + } + } + + // 尝试查找JSON开始和结束 + char *json_start = strchr(g_agnss_response_buffer, '{'); + char *json_end = strrchr(g_agnss_response_buffer, '}'); + + // 检查是否有截断的JSON数据 + if (strstr(g_agnss_response_buffer, "1ff8") || strstr(g_agnss_response_buffer, "0x0D")) { + printf("Warning: Detected corrupted JSON data with truncation markers\n"); + // 尝试找到最后一个完整的JSON对象 + char *last_complete = strrstr(g_agnss_response_buffer, "}]"); + if (last_complete) { + json_end = last_complete + 1; + printf("Truncated to last complete JSON object at position %ld\n", + json_end - g_agnss_response_buffer); + } + } + + if (json_start && json_end && json_end > json_start) { + printf("Found JSON content between positions %ld and %ld\n", + json_start - g_agnss_response_buffer, + json_end - g_agnss_response_buffer); + + // 验证这个JSON片段是否完整 + int brace_count = 0; + int bracket_count = 0; + for (char *p = json_start; p <= json_end; p++) { + if (*p == '{') brace_count++; + else if (*p == '}') brace_count--; + else if (*p == '[') bracket_count++; + else if (*p == ']') bracket_count--; + } + + if (brace_count == 0 && bracket_count == 0) { + // 调整缓冲区指针和大小 + size_t new_size = json_end - json_start + 1; + memmove(g_agnss_response_buffer, json_start, new_size); + g_agnss_response_size = new_size; + g_agnss_response_buffer[g_agnss_response_size] = '\0'; + printf("Adjusted buffer size to %zu bytes (complete JSON)\n", g_agnss_response_size); + } else { + printf("Found JSON fragment but structure incomplete - braces: %d, brackets: %d\n", brace_count, bracket_count); + // 尝试查找最后一个完整的JSON对象 + char *last_complete = NULL; + char *search_pos = g_agnss_response_buffer; + + // 查找最后一个完整的 "}]" + while ((search_pos = strstr(search_pos, "}]")) != NULL) { + last_complete = search_pos + 2; + search_pos += 2; + } + + // 如果没有找到 "}]",尝试查找最后一个 "}" + if (!last_complete) { + search_pos = g_agnss_response_buffer; + while ((search_pos = strchr(search_pos, '}')) != NULL) { + last_complete = search_pos + 1; + search_pos += 1; + } + } + + if (last_complete) { + size_t new_size = last_complete - g_agnss_response_buffer; + g_agnss_response_size = new_size; + g_agnss_response_buffer[g_agnss_response_size] = '\0'; + printf("Truncated to last complete JSON object, size: %zu bytes\n", g_agnss_response_size); + } else { + printf("Could not find any complete JSON structure, using original data\n"); + } + } + } else { + printf("Error: Could not find valid JSON boundaries\n"); + printf("JSON start found: %s\n", json_start ? "yes" : "no"); + printf("JSON end found: %s\n", json_end ? "yes" : "no"); + + // 尝试查找最后一个完整的JSON对象 + char *last_complete = NULL; + char *search_pos = g_agnss_response_buffer; + + // 查找最后一个完整的 "}]" + while ((search_pos = strstr(search_pos, "}]")) != NULL) { + last_complete = search_pos + 2; + search_pos += 2; + } + + // 如果没有找到 "}]",尝试查找最后一个 "}" + if (!last_complete) { + search_pos = g_agnss_response_buffer; + while ((search_pos = strchr(search_pos, '}')) != NULL) { + last_complete = search_pos + 1; + search_pos += 1; + } + } + + if (last_complete) { + size_t new_size = last_complete - g_agnss_response_buffer; + g_agnss_response_size = new_size; + g_agnss_response_buffer[g_agnss_response_size] = '\0'; + printf("Truncated to last complete JSON object, size: %zu bytes\n", g_agnss_response_size); + } else { + printf("Could not find any complete JSON structure, using original data\n"); + } + } + } + + printf("AGNSS JSON data:\n%s\n", g_agnss_response_buffer); + + // 检查JSON数据完整性 + int brace_count = 0; + int bracket_count = 0; + for (size_t i = 0; i < g_agnss_response_size; i++) { + if (g_agnss_response_buffer[i] == '{') brace_count++; + else if (g_agnss_response_buffer[i] == '}') brace_count--; + else if (g_agnss_response_buffer[i] == '[') bracket_count++; + else if (g_agnss_response_buffer[i] == ']') bracket_count--; + } + + if (brace_count != 0 || bracket_count != 0) { + printf("Warning: JSON structure incomplete - braces: %d, brackets: %d\n", brace_count, bracket_count); + + // 如果JSON结构不完整,尝试修复 + if (brace_count > 0 || bracket_count > 0) { + // 缺少右大括号或右方括号,尝试添加 + printf("Attempting to fix incomplete JSON by adding missing braces/brackets\n"); + size_t needed_braces = (brace_count > 0) ? brace_count : 0; + size_t needed_brackets = (bracket_count > 0) ? bracket_count : 0; + + // 防止过度修复 + if (needed_braces > 10 || needed_brackets > 10) { + printf("Warning: Too many missing braces/brackets (%zu/%zu), skipping fix to prevent corruption\n", + needed_braces, needed_brackets); + } else { + // 计算需要扩展的缓冲区大小 + size_t additional_size = needed_braces + needed_brackets; + char *new_buffer = (char *)realloc(g_agnss_response_buffer, g_agnss_response_size + additional_size + 1); + if (new_buffer) { + g_agnss_response_buffer = new_buffer; + + // 添加缺少的右方括号和右大括号 + for (size_t i = 0; i < needed_brackets; i++) { + g_agnss_response_buffer[g_agnss_response_size++] = ']'; + } + for (size_t i = 0; i < needed_braces; i++) { + g_agnss_response_buffer[g_agnss_response_size++] = '}'; + } + g_agnss_response_buffer[g_agnss_response_size] = '\0'; + + printf("Fixed JSON structure, new size: %zu bytes\n", g_agnss_response_size); + } else { + printf("Failed to allocate memory for JSON fix\n"); + } + } + } + } else { + printf("JSON structure appears complete\n"); + } + + // 解析JSON响应,提取文件列表 + if (strstr(g_agnss_response_buffer, "\"success\":true") && strstr(g_agnss_response_buffer, "\"code\":20000")) { + printf("AGNSS API call successful, parsing file list...\n"); + + // 查找data数组开始 + char *data_start = strstr(g_agnss_response_buffer, "\"data\":["); + if (data_start && (data_start - g_agnss_response_buffer) < (long)g_agnss_response_size) { + data_start += 8; // 跳过"data":[ + + // 解析每个文件项 + char *item_start = data_start; + int file_count = 0; + int download_count = 0; + int total_files_to_download = 0; + + // 首先计算总文件数 + char *count_pos = data_start; + while ((count_pos = strstr(count_pos, "\"fileName\":")) != NULL && + (count_pos - g_agnss_response_buffer) < (long)g_agnss_response_size) { + total_files_to_download++; + count_pos += 11; + } + printf("Total files to download: %d\n", total_files_to_download); + + while ((item_start = strstr(item_start, "\"fileName\":")) != NULL && + (item_start - g_agnss_response_buffer) < (long)g_agnss_response_size && + (item_start - g_agnss_response_buffer) >= 0) { + file_count++; + + // 防止无限循环 - 限制最大文件数量 + if (file_count > 100) { + printf("Warning: Too many files found (%d), stopping to prevent infinite loop\n", file_count); + emergency_cleanup(); + break; + } + + // 检查是否重复处理同一个文件 + static char last_filename[256] = {0}; + char current_filename[256] = {0}; + + // 提取当前文件名用于比较 + char *check_name_start = item_start + 11; + while (*check_name_start == ' ' || *check_name_start == '\t' || *check_name_start == '\n' || *check_name_start == '\r') { + check_name_start++; + } + if (*check_name_start == '"') { + check_name_start++; + char *name_end = strchr(check_name_start, '"'); + if (name_end && (name_end - check_name_start) < 256) { + int name_len = name_end - check_name_start; + if (safe_strncpy(current_filename, check_name_start, sizeof(current_filename), name_len) != 0) { + printf("Warning: Failed to copy filename safely\n"); + continue; + } + + // 检查是否与上一个文件名相同 - 改进版本 + static int repeat_count = 0; + if (strlen(last_filename) > 0 && strcmp(last_filename, current_filename) == 0) { + repeat_count++; + printf("Warning: Detected repeated file processing: %s (count: %d)\n", current_filename, repeat_count); + + // 只有在连续重复8次以上时才停止 + if (repeat_count >= 8) { + printf("Too many repeated files, stopping loop\n"); + emergency_cleanup(); + break; + } + // 跳过重复文件,继续处理下一个 + continue; + } else { + repeat_count = 0; // 重置重复计数器 + } + strcpy(last_filename, current_filename); + } + } + + // 提取文件名 - 更健壮的解析逻辑 + char *name_start = item_start + 11; // 跳过"fileName": + // 跳过可能的空白字符 + while (*name_start == ' ' || *name_start == '\t' || *name_start == '\n' || *name_start == '\r') { + name_start++; + } + + if (*name_start == '"') { + name_start++; // 跳过第一个引号 + char *name_end = strchr(name_start, '"'); + if (name_end && (name_end - name_start) < 256) { + int name_len = name_end - name_start; + char filename[256] = {0}; + if (safe_strncpy(filename, name_start, sizeof(filename), name_len) != 0) { + printf("Warning: Failed to copy filename safely\n"); + continue; + } + + // 验证文件名是否包含有效字符,并尝试清理 + int valid_filename = 1; + int needs_cleaning = 0; + + // 检查是否需要清理 + for (int i = 0; i < name_len; i++) { + if (filename[i] < 32 || filename[i] > 126) { + printf("Warning: Invalid character in filename at position %d: 0x%02X\n", i, (unsigned char)filename[i]); + needs_cleaning = 1; + break; + } + } + + // 如果包含控制字符,尝试清理 + if (needs_cleaning) { + printf("Attempting to clean filename: %s\n", filename); + if (clean_filename(filename, sizeof(filename)) == 1) { + printf("Filename cleaned successfully: %s\n", filename); + valid_filename = 1; + } else { + printf("Failed to clean filename, skipping\n"); + valid_filename = 0; + } + } + + // 检查文件名是否被截断或损坏 + if (strstr(filename, "wnloadUrl") || strstr(filename, "loadUrl") || + strstr(filename, "oadUrl") || strstr(filename, "adUrl") || + strstr(filename, "downloadUrl") || strstr(filename, "1ff8") || + strstr(filename, "0x0D") || strstr(filename, "\\x0D")) { + printf("Warning: Filename appears to be corrupted/truncated: %s\n", filename); + valid_filename = 0; // 暂时标记为无效,稍后尝试恢复 + } + + // 检查文件名是否以有效扩展名结尾 + if (!strstr(filename, ".eph") && !strstr(filename, ".dat")) { + printf("Warning: Filename has invalid extension: %s\n", filename); + valid_filename = 0; + } + + // 检查文件名是否包含控制字符 + for (int i = 0; i < name_len; i++) { + if (filename[i] < 32 || filename[i] == 127) { + printf("Warning: Filename contains control character at position %d: 0x%02X\n", + i, (unsigned char)filename[i]); + valid_filename = 0; + break; + } + } + + // 检查文件名长度是否合理 + if (name_len < 5 || name_len > 100) { + printf("Warning: Filename length seems unreasonable: %d bytes\n", name_len); + valid_filename = 0; + } + + if (!valid_filename) { + printf("Skipping file with invalid characters: %s\n", filename); + // 移动到下一个文件项 + item_start = strstr(item_start, "},"); + if (item_start) { + item_start += 2; + } else { + break; + } + continue; + } + + printf("File %d: %s (length: %d, extension: %s)\n", file_count, filename, name_len, + strstr(filename, ".eph") ? ".eph" : (strstr(filename, ".dat") ? ".dat" : "unknown")); + // 打印文件名的十六进制表示,帮助调试 + printf("Filename hex: "); + for (int i = 0; i < name_len && i < 20; i++) { + printf("%02X ", (unsigned char)filename[i]); + } + printf("\n"); + + // 查找对应的downloadUrl - 改进搜索逻辑 + char *url_start = strstr(item_start, "\"downloadUrl\":\""); + if (url_start) { + url_start += 15; // 跳过"downloadUrl":" + char *url_end = strchr(url_start, '"'); + if (url_end && (url_end - url_start) < 512) { + int url_len = url_end - url_start; + char download_url[512] = {0}; + if (safe_strncpy(download_url, url_start, sizeof(download_url), url_len) != 0) { + printf("Warning: Failed to copy URL safely\n"); + continue; + } + printf("Download URL: %s\n", download_url); + + // 验证文件名和URL的一致性 + char *url_filename = strrchr(download_url, '/'); + if (url_filename) { + url_filename++; // 跳过斜杠 + if (strlen(url_filename) > 0) { + // 检查URL中的文件名是否与解析的文件名匹配 + if (strstr(filename, ".eph") && !strstr(url_filename, ".eph")) { + printf("Warning: Filename/URL mismatch - filename: %s, URL file: %s\n", filename, url_filename); + continue; + } + if (strstr(filename, ".dat") && !strstr(url_filename, ".dat")) { + printf("Warning: Filename/URL mismatch - filename: %s, URL file: %s\n", filename, url_filename); + continue; + } + } + } + + // 如果文件名被标记为无效,尝试从URL恢复 + if (!valid_filename) { + if (strstr(download_url, ".eph") || strstr(download_url, ".dat")) { + char *last_slash = strrchr(download_url, '/'); + if (last_slash && strlen(last_slash + 1) > 5) { + // 从URL中提取文件名 + if (safe_strncpy(filename, last_slash + 1, sizeof(filename), strlen(last_slash + 1)) == 0) { + printf("Recovered filename from URL: %s\n", filename); + valid_filename = 1; + } + } + } + } + + // 验证URL格式 + if (strlen(download_url) == 0 || strlen(download_url) > 512) { + printf("Warning: Invalid URL length: %zu\n", strlen(download_url)); + continue; + } + + // 验证URL是否以http://开头 + if (strncmp(download_url, "http://", 7) != 0) { + printf("Warning: Invalid URL scheme: %s\n", download_url); + continue; + } + + // 检查URL是否被截断(检查是否以常见截断字符结尾) + if (strstr(download_url, "1ff8") || strstr(download_url, "0x0D") || + strstr(download_url, "\\x0D") || strstr(download_url, "\r") || + strstr(download_url, "wnloadUrl") || strstr(download_url, "loadUrl") || + strstr(download_url, "oadUrl") || strstr(download_url, "adUrl") || + strstr(download_url, "\n") || strstr(download_url, "\t")) { + printf("Warning: URL appears to be corrupted/truncated: %s\n", download_url); + continue; + } + + // 检查URL是否完整(应该以.eph或.dat结尾) + if (strlen(download_url) < 10 || (!strstr(download_url, ".eph") && !strstr(download_url, ".dat"))) { + printf("Warning: URL appears incomplete (too short or missing .eph/.dat): %s\n", download_url); + continue; + } + + // 尝试修复被截断的URL + if (strstr(download_url, "1ff0") || strstr(download_url, "1ff8")) { + printf("Warning: Attempting to fix truncated URL: %s\n", download_url); + // 查找最后一个完整的URL部分 + char *last_slash = strrchr(download_url, '/'); + if (last_slash && (last_slash - download_url) > 20) { + // 截断到最后一个斜杠 + *(last_slash + 1) = '\0'; + printf("Fixed URL (truncated): %s\n", download_url); + } else { + printf("Could not fix URL, skipping\n"); + continue; + } + } + + // 清理URL中的控制字符 + int url_cleaned = 0; + for (int i = 0; download_url[i]; i++) { + if (download_url[i] < 32 || download_url[i] > 126) { + if (!url_cleaned) { + printf("Warning: Cleaning URL with control characters\n"); + url_cleaned = 1; + } + download_url[i] = '_'; + } + } + if (url_cleaned) { + printf("URL cleaned: %s\n", download_url); + } + + // 验证URL是否包含有效字符 + int valid_url = 1; + for (int i = 0; i < url_len; i++) { + if (download_url[i] < 32 || download_url[i] > 126) { + printf("Warning: Invalid character in URL at position %d: 0x%02X\n", i, (unsigned char)download_url[i]); + valid_url = 0; + break; + } + } + + if (!valid_url) { + printf("Skipping URL with invalid characters\n"); + continue; + } + + // 验证URL是否完整(包含路径) + if (strlen(download_url) < 10 || strchr(download_url + 7, '/') == NULL) { + printf("Warning: URL appears to be truncated or incomplete: %s\n", download_url); + continue; + } + + // 检查URL是否被截断(检查是否以常见截断字符结尾) + if (strstr(download_url, "wnloadUrl") || strstr(download_url, "loadUrl") || + strstr(download_url, "oadUrl") || strstr(download_url, "adUrl") || + strstr(download_url, "1ff8") || strstr(download_url, "0x0D") || + strstr(download_url, "\\x0D") || strstr(download_url, "\r")) { + printf("Warning: URL appears to be corrupted/truncated: %s\n", download_url); + continue; + } + + // 检查URL是否包含控制字符 + int has_control_chars = 0; + for (int i = 0; i < url_len; i++) { + if (download_url[i] < 32 || download_url[i] == 127) { + has_control_chars = 1; + break; + } + } + if (has_control_chars) { + printf("Warning: URL contains control characters, skipping\n"); + continue; + } + + // 下载文件 + printf("Downloading file %d/%d: %s\n", file_count, total_files_to_download, filename); + if (download_agnss_file_with_url(filename, download_url) == 0) { + download_count++; + printf("Successfully downloaded: %s (%d/%d)\n", filename, download_count, total_files_to_download); + // 成功下载后短暂等待 + LOS_Msleep(300); // 减少到300ms,提高效率 + + // 重置连续失败计数器 + static int consecutive_failures = 0; + consecutive_failures = 0; + + // 重置重复计数器 + static int repeat_count = 0; + repeat_count = 0; + } else { + printf("Failed to download: %s (%d/%d)\n", filename, file_count, total_files_to_download); + // 失败后等待更长时间,给网络恢复时间 + LOS_Msleep(2000); // 增加到2秒 + + // 智能错误恢复:如果连续失败,增加等待时间 + static int consecutive_failures = 0; + consecutive_failures++; + if (consecutive_failures >= 3) { + printf("Warning: %d consecutive failures, increasing wait time\n", consecutive_failures); + LOS_Msleep(5000); // 额外等待5秒 + consecutive_failures = 0; // 重置计数器 + } + } + } else { + printf("Warning: Invalid URL format or too long\n"); + } + } else { + printf("Warning: No downloadUrl found for file %s\n", filename); + } + } else { + printf("Warning: Invalid filename format or too long\n"); + } + } + + // 移动到下一个文件项 - 更安全的移动 + char *next_item = strstr(item_start, "},"); + if (next_item && (next_item - g_agnss_response_buffer) < (long)g_agnss_response_size) { + item_start = next_item + 2; + } else { + // 尝试查找最后一个项目 + char *last_item = strstr(item_start, "}"); + if (last_item && (last_item - g_agnss_response_buffer) < (long)g_agnss_response_size) { + item_start = last_item + 1; + } else { + printf("Warning: Could not find next item marker, breaking loop\n"); + break; + } + } + + // 防止无限循环 - 检查指针是否前进 + static char *last_item_start = NULL; + if (last_item_start == item_start) { + printf("Warning: item_start pointer not advancing, breaking loop to prevent infinite loop\n"); + emergency_cleanup(); + break; + } + last_item_start = item_start; + + // 紧急退出检查 - 防止指针越界 + if (item_start >= g_agnss_response_buffer + g_agnss_response_size) { + printf("Warning: item_start pointer out of bounds, breaking loop\n"); + break; + } + + // 检查是否遇到截断的JSON数据 + if (strstr(item_start, "1ff8") || strstr(item_start, "0x0D") || + strstr(item_start, "\\x0D") || strstr(item_start, "\r") || + strstr(item_start, "wnloadUrl") || strstr(item_start, "loadUrl") || + strstr(item_start, "oadUrl") || strstr(item_start, "adUrl")) { + printf("Warning: Detected truncated JSON data, attempting to find last complete item\n"); + + // 尝试找到最后一个完整的文件项 + char *last_complete_item = strrstr(g_agnss_response_buffer, "}]"); + if (last_complete_item && last_complete_item > item_start) { + printf("Found last complete JSON item, continuing with valid data\n"); + // 继续处理,但限制在有效范围内 + if (last_complete_item - item_start > 15000) { + printf("Warning: Too much data to skip (%ld bytes), stopping for safety\n", + last_complete_item - item_start); + break; + } + printf("Skipping %ld bytes to continue with valid data\n", + last_complete_item - item_start); + + // 验证跳过后的数据完整性 + char *verify_start = last_complete_item - 1000; // 向前查找1000字节 + if (verify_start < g_agnss_response_buffer) { + verify_start = g_agnss_response_buffer; + } + + // 检查是否有完整的文件项结构 + char *verify_file = strstr(verify_start, "\"fileName\":"); + char *verify_url = strstr(verify_start, "\"downloadUrl\":"); + + if (!verify_file || !verify_url || verify_url < verify_file) { + printf("Warning: Incomplete file structure after skip, stopping to prevent data corruption\n"); + break; + } + } else { + printf("Warning: Could not find last complete item, attempting to continue with partial data\n"); + // 尝试继续处理,但跳过当前损坏的项目 + char *next_item = strstr(item_start, "},"); + if (next_item && (next_item - g_agnss_response_buffer) < (long)g_agnss_response_size) { + item_start = next_item + 2; + printf("Skipped corrupted item, continuing with next item\n"); + continue; + } else { + // 尝试查找下一个fileName标记 + char *next_file = strstr(item_start, "\"fileName\":"); + if (next_file && (next_file - g_agnss_response_buffer) < (long)g_agnss_response_size) { + item_start = next_file; + printf("Found next fileName marker, continuing with partial data\n"); + continue; + } else { + // 尝试更智能的恢复:查找任何可能的文件条目 + char *recovery_pos = item_start + 200; // 跳过更多字节 + if (recovery_pos < g_agnss_response_buffer + g_agnss_response_size) { + char *recovery_file = strstr(recovery_pos, "\"fileName\":"); + if (recovery_file && (recovery_file - g_agnss_response_buffer) < (long)g_agnss_response_size) { + printf("Found recovery file marker, attempting to continue\n"); + item_start = recovery_file; + continue; + } + } + printf("Warning: Could not find next item marker, stopping parsing\n"); + break; + } + } + } + } + } + + printf("Total files found: %d, Downloaded: %d\n", file_count, download_count); + } else { + printf("No 'data' array found in JSON response\n"); + } + } else { + printf("AGNSS API call failed or returned error\n"); + printf("Response content: %s\n", g_agnss_response_buffer); + } + + // 清理缓冲区 + free(g_agnss_response_buffer); + g_agnss_response_buffer = NULL; + g_agnss_response_size = 0; + g_agnss_response_capacity = 0; + + // 重置处理计数器 + static int processing_count = 0; + processing_count = 0; + + printf("AGNSS files download and storage completed successfully\n"); + printf("All files have been saved to: %s\n", PGNSS_DATA_PATH); + + // 延迟验证下载的文件,等待文件下载完成 + printf("Waiting for file downloads to complete before verification...\n"); + LOS_Msleep(5000); // 等待5秒让文件下载完成 + + // 验证下载的文件 + verify_downloaded_files(); + + } else { + printf("No response buffer or empty response\n"); + } +} + + +static err_t agnss_download_recv_callback(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err) +{ + printf("AGNSS recv callback: p=%p, err=%d\n", p, err); + + if (p == NULL) { + printf("AGNSS download completed or error occurred\n"); + // 发送完成信号到接收任务 + do_gnss_http_server_recv_data(GNSS_HTTP_SERVICE_CMD_AGNSS_RECV, NULL, 0); + return ERR_OK; + } + + printf("AGNSS download received %d bytes\n", p->len); + + // 分配内存并复制数据 + char *data = (char *)malloc(p->len + 1); + if (data == NULL) { + printf("Failed to allocate memory for AGNSS data\n"); + pbuf_free(p); + return ERR_MEM; + } + + memcpy(data, p->payload, p->len); + data[p->len] = '\0'; + + // 发送数据到接收任务 + do_gnss_http_server_recv_data(GNSS_HTTP_SERVICE_CMD_AGNSS_RECV, data, p->len); + + pbuf_free(p); + return ERR_OK; +} + + +// DNS解析辅助函数 +static int resolve_hostname(const char *hostname, uint32_t *ip_addr) +{ + struct gnss_ipaddr_t ip_sem = {0}; + int ret = -1; + int retry_count = 0; + const int max_retries = 5; // 最大重试次数 + + if (hostname == NULL || ip_addr == NULL) { + printf("Invalid parameters for DNS resolution\n"); + return -1; + } + + printf("Resolving hostname: %s\n", hostname); + + while (retry_count < max_retries) { + printf("DNS resolution attempt %d/%d for %s\n", retry_count + 1, max_retries, hostname); + + // 创建信号量 + ip_sem.dns_done_sem = osSemaphoreNew(1, 0, NULL); + if (ip_sem.dns_done_sem == NULL) { + printf("Failed to create semaphore for DNS resolution\n"); + return -1; + } + + // 初始化IP地址为0 + memset(&ip_sem.ip, 0, sizeof(ip_addr_t)); + + // 解析域名 + dns_gethostbyname(hostname, &(ip_sem.ip), dns_found, &ip_sem); + + // 等待DNS解析完成 + if (osSemaphoreAcquire(ip_sem.dns_done_sem, 30000) == osOK) { + if (ip_sem.ip.u_addr.ip4.addr != 0) { + *ip_addr = ip_sem.ip.u_addr.ip4.addr; + printf("DNS resolution successful for %s: 0x%08X (attempt %d)\n", hostname, *ip_addr, retry_count + 1); + ret = 0; + break; // 成功,跳出循环 + } else { + printf("DNS resolution failed for %s: IP address is 0 (attempt %d)\n", hostname, retry_count + 1); + } + } else { + printf("DNS resolution timeout for %s (attempt %d)\n", hostname, retry_count + 1); + } + + // 释放信号量 + osSemaphoreDelete(ip_sem.dns_done_sem); + + // 如果不是最后一次尝试,等待1秒后重试 + if (retry_count < max_retries - 1) { + printf("Waiting 1 second before retry...\n"); + LOS_Msleep(1000); + } + + retry_count++; + } + + if (ret != 0) { + printf("DNS resolution failed after %d attempts for %s\n", max_retries, hostname); + } + + return ret; +} + +// URL解析函数 +static BK_URL parse_url(const char *url) { + BK_URL result = {NULL, NULL, 0, NULL, NULL, NULL}; + + if (!url) { + result.error = "URL is NULL"; + return result; + } + + char *temp_url = strdup(url); + if (!temp_url) { + result.error = "Failed to allocate memory"; + return result; + } + + char *temp_ptr = temp_url; + + // 解析协议 + char *colon = strchr(temp_ptr, ':'); + if (!colon) { + result.error = "Invalid URL: No protocol specified"; + free(temp_url); + return result; + } + *colon = '\0'; + result.protocol = strdup(temp_ptr); + temp_ptr = colon + 3; // 跳过 "://" + + // 解析主机和端口 + char *slash = strchr(temp_ptr, '/'); + if (!slash) { + result.error = "Invalid URL: No path specified"; + free(temp_url); + return result; + } + *slash = '\0'; + + char *colon_port = strchr(temp_ptr, ':'); + if (colon_port) { + *colon_port = '\0'; + result.host = strdup(temp_ptr); + result.port = atoi(colon_port + 1); + if (!result.port) { + result.error = "Invalid port number"; + free(temp_url); + return result; + } + } else { + result.host = strdup(temp_ptr); + if (!strcmp(result.protocol, "http")) { + result.port = 80; + } else if (!strcmp(result.protocol, "https")) { + result.port = 443; + } + } + + temp_ptr = slash + 1; + + // 解析路径和查询字符串 + char *question = strchr(temp_ptr, '?'); + if (question) { + *question = '\0'; + result.path = strdup(temp_ptr); + result.query = strdup(question + 1); + } else { + result.path = strdup(temp_ptr); + result.query = NULL; + } + + free(temp_url); + return result; +} + +// 释放URL结构体 +static void free_url(BK_URL *url) { + if (url) { + free(url->protocol); + free(url->host); + free(url->path); + free(url->query); + free(url->error); + memset(url, 0, sizeof(BK_URL)); + } +} + + +static void dns_found(const char* hostname, const ip_addr_t *ipaddr, void *arg) +{ + struct gnss_ipaddr_t *ip_sem = (struct gnss_ipaddr_t *)arg; + char ip_str[20] = {0}; + + printf("hostname: %s, ", hostname); + + // 详细检查IP地址 + if (ipaddr == NULL) { + printf("DNS解析失败,IP地址为NULL\n"); + memset(&(ip_sem->ip), 0, sizeof(ip_addr_t)); + (void)osSemaphoreRelease(ip_sem->dns_done_sem); + return; + } + + // 检查IP地址类型 + if (ipaddr->type != IPADDR_TYPE_V4) { + printf("DNS解析失败,不是IPv4地址,类型: %d\n", ipaddr->type); + memset(&(ip_sem->ip), 0, sizeof(ip_addr_t)); + (void)osSemaphoreRelease(ip_sem->dns_done_sem); + return; + } + + uint32_t ip_num = ipaddr->u_addr.ip4.addr; + printf("Raw IP address: 0x%08X\n", ip_num); + + if (ip_num == 0) { + printf("DNS解析失败,IP地址为0\n"); + memset(&(ip_sem->ip), 0, sizeof(ip_addr_t)); + (void)osSemaphoreRelease(ip_sem->dns_done_sem); + return; + } + + // 处理IPv4地址 + // 分解为4字节打印 + u8_t byte0 = (ip_num >> 24) & 0xFF; + u8_t byte1 = (ip_num >> 16) & 0xFF; + u8_t byte2 = (ip_num >> 8) & 0xFF; + u8_t byte3 = ip_num & 0xFF; + printf("IPv4: %d.%d.%d.%d\n", byte0, byte1, byte2, byte3); + + // 转换为struct in_addr(已为网络字节序) + struct in_addr ipv4_addr; + ipv4_addr.s_addr = ip_num; + inet_ntop(AF_INET, &ipv4_addr, ip_str, sizeof(ip_str)); + printf("ip: %s\n", ip_str); + + // 复制IP地址到上下文 + memcpy(&(ip_sem->ip), ipaddr, sizeof(ip_addr_t)); + printf("DNS解析成功,IP地址已保存\n"); + (void)osSemaphoreRelease(ip_sem->dns_done_sem); +} + +// 下载AGNSS星历文件 +int download_agnss_file(const char *filename) +{ + printf("Downloading file: %s\n", filename); + + // 获取当前时间戳 + uint32_t timestamp = 0; + uapi_get_timestampe_ss(×tamp); + + // 构建文件路径 + char filepath[512]; + snprintf(filepath, sizeof(filepath), "%s/%s", PGNSS_DATA_PATH, filename); + + // 初始化HTTP客户端连接设置 + httpc_connection_t settings = {0}; + httpc_state_t* connection = NULL; + + // 设置回调函数 + settings.result_fn = agnss_download_result_callback; + settings.headers_done_fn = agnss_download_headers_done_callback; + settings.use_proxy = 0; + settings.use_post = 0; // 使用GET请求 + + // 构建URI + char uri[512]; + snprintf(uri, sizeof(uri), "/dev/AGNSS/geteph?deviceId=121314243×tamp=%u", timestamp); + + printf("Download URI: %s\n", uri); + printf("Local file: %s\n", filepath); + + // 发送HTTP GET请求并直接下载到文件 + err_t result = httpc_get_file_dns_to_disk( + "iot-pub.tos-cn-guangzhou.volces.com", // 服务器名称(使用正确的文件下载服务器) + 80, // 端口 + uri, // URI + &settings, // 连接设置 + (void*)filename, // 回调参数(传递文件名) + filepath, // 本地文件路径 + &connection // 连接状态 + ); + + if (result != ERR_OK) { + printf("HTTP GET request failed: %d\n", result); + return -1; + } + + printf("HTTP GET request sent successfully\n"); + return 0; +} + +int download_agnss_files(void) +{ + printf("=== Starting AGNSS Files Download ===\n"); + + + // 获取当前时间戳 + uint32_t timestamp = 0; + uapi_get_timestampe_ss(×tamp); + + // 构建完整URL + char full_url[512]; + snprintf(full_url, sizeof(full_url), + "http://app.api.thisiot.com/dev/AGNSS/geteph?deviceId=121314243×tamp=%u", + timestamp); + + printf("AGNSS URL: %s\n", full_url); + + // 初始化HTTP客户端连接设置 + httpc_connection_t settings = {0}; + httpc_state_t* connection = NULL; + + // 设置回调函数 + settings.result_fn = agnss_download_result_callback; + settings.headers_done_fn = agnss_download_headers_done_callback; + settings.use_proxy = 0; + settings.use_post = 0; // 使用GET请求 + + printf("HTTP client settings configured:\n"); + printf(" result_fn: %p\n", settings.result_fn); + printf(" headers_done_fn: %p\n", settings.headers_done_fn); + printf(" use_proxy: %d\n", settings.use_proxy); + printf(" use_post: %d\n", settings.use_post); + + // 构建URI + char uri[512]; + snprintf(uri, sizeof(uri), "/dev/AGNSS/geteph?deviceId=121314243×tamp=%u", timestamp); + + printf("AGNSS URI: %s\n", uri); + printf("Server: app.api.thisiot.com, Port: 80\n"); + + // 清理之前的缓冲区 + cleanup_agnss_response_buffer(); + + // 重置时间戳(用于调试) + printf("=== Starting new AGNSS download session ===\n"); + printf("Download request sent at: %u ms\n", LOS_TickCountGet() * 10); + + // 发送HTTP GET请求 + err_t result = httpc_get_file_dns( + "app.api.thisiot.com", // 服务器名称(API服务器,用于获取文件列表) + 80, // 端口 + uri, // URI + &settings, // 连接设置 + agnss_download_recv_callback, // 接收回调 + NULL, // 回调参数 + &connection // 连接状态 + ); + + printf("httpc_get_file_dns result: %d (0=OK, other=error)\n", result); + + if (result != ERR_OK) { + printf("HTTP GET request failed: %d\n", result); + printf("Error codes: ERR_OK=0, ERR_MEM=-1, ERR_TIMEOUT=-2, ERR_RTE=-3\n"); + return -1; + } + + printf("HTTP GET request sent successfully\n"); + printf("Connection pointer: %p\n", connection); + + printf("=== AGNSS Files Download Request Complete ===\n"); + printf("Data will be processed asynchronously by gnss_http_server_recv_task\n"); + printf("No blocking wait - download will start immediately\n"); + return 0; +} + + +void do_gnss_http_server_send_data(int cmd,char *data,uint32_t len) +{ + errcode_t ret; + gnss_http_data_mail_t send_data = {0}; + send_data.cmd = cmd; + if(len && data) + { + send_data.len = len; + send_data.data = (char *)malloc(len); + if(send_data.data == NULL) + { + PRINT("malloc failed\n"); + return; + } + memcpy_s(send_data.data,len,data,len); + } + + uint32_t send_len = sizeof(send_data); + + ret = osal_msg_queue_write_copy(g_app_send_queue, (void *)&send_data, + send_len, 0); + if (ret != OSAL_SUCCESS) { + PRINT("Error gnss Check MSG 0x send failed! err=0x%x! \r\n", ret); + } +} + +void do_gnss_http_server_recv_data(int cmd,char *data,uint32_t len) +{ + errcode_t ret; + gnss_http_data_mail_t send_data = {0}; + send_data.cmd = cmd; + if(len && data) + { + send_data.len = len; + send_data.data = (char *)malloc(len); + if(send_data.data == NULL) + { + PRINT("malloc failed\n"); + return; + } + memcpy_s(send_data.data,len,data,len); + } + + uint32_t send_len = sizeof(send_data); + + ret = osal_msg_queue_write_copy(g_app_recv_queue, (void *)&send_data, + send_len, 0); + if (ret != OSAL_SUCCESS) { + PRINT("Error gnss Check MSG 0x send failed! err=0x%x! \r\n", ret); + } +} + +// 清理AGNSS响应缓冲区 +static void cleanup_agnss_response_buffer(void) +{ + if (g_agnss_response_buffer) { + free(g_agnss_response_buffer); + g_agnss_response_buffer = NULL; + g_agnss_response_size = 0; + g_agnss_response_capacity = 0; + } +} + +static void gnss_http_server_send_task(void const *arg) +{ + unused(arg); + errcode_t ret; + + gnss_http_data_mail_t mail = {0}; + uint32_t msgsize = sizeof(gnss_http_data_mail_t); + + while (1) { + ret = osal_msg_queue_read_copy(g_app_send_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) { + continue; + } + + if(mail.cmd == GNSS_HTTP_SERVICE_CMD_DATA_UPLOAD) + { + // http_data_handler((int *)mail.data,mail.len); + // http_recv_data_handler(mail.data,mail.len); + if(mail.data != NULL) + { + printf("free(mail.data)\n"); + free(mail.data); + } + } + else if(mail.cmd == GNSS_HTTP_SERVICE_CMD_SERVER_INIT) + { + // gnss_http_init(); + uapi_delete_files(PGNSS_DATA_PATH); + uapi_create_folder(PGNSS_DATA_PATH); + + // gnss_http_sign_up(); + // if(LK_STATUS == 1) + // { + // gnss_agnss_get_ephemeris(); + // } + // else + // { + // printf("NOT LK\n"); + // } + + } + else if(mail.cmd == GNSS_HTTP_SERVICE_CMD_SERVER_DEINIT) + { + // gnss_http_deinit(); + } + else if(mail.cmd == GNSS_HTTP_SERVICE_CMD_DOWNLOAD_AGNSS) + { + uapi_delete_files(PGNSS_DATA_PATH); + uapi_create_folder(PGNSS_DATA_PATH); + + printf("Starting AGNSS files download via queue...\n"); + download_agnss_files(); + printf("AGNSS files download completed via queue.\n"); + } + } +} + + +static void gnss_http_server_recv_task(void const *arg) +{ + unused(arg); + errcode_t ret; + + gnss_http_data_mail_t mail = {0}; + uint32_t msgsize = sizeof(gnss_http_data_mail_t); + + // 添加任务保护计数器 + int task_loop_count = 0; + const int max_loop_count = 10000; // 防止无限循环 + + while (1) { + task_loop_count++; + if (task_loop_count > max_loop_count) { + printf("Warning: Task loop count exceeded %d, resetting counter\n", max_loop_count); + task_loop_count = 0; + // 清理可能的内存泄漏 + cleanup_agnss_response_buffer(); + } + + ret = osal_msg_queue_read_copy(g_app_recv_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) { + continue; + } + + if(mail.cmd == GNSS_HTTP_SERVICE_CMD_AGNSS_RECV) + { + if (mail.data == NULL) { + // 数据接收完成,处理完整的响应 + printf("AGNSS data reception completed, processing response...\n"); + agnss_process_complete_response(); + task_loop_count = 0; // 重置计数器 + } else { + // 接收数据片段 + printf("AGNSS data received via queue: %d bytes\n", mail.len); + agnss_accumulate_data(mail.data, mail.len); + free(mail.data); // 释放数据内存 + } + } + } +} + +static void create_gnss_http_send_queue(void) +{ + + if (osal_msg_queue_create("gnss_http_service_send_queue", 24, &g_app_send_queue, + 0, sizeof(gnss_http_data_mail_t)) != ERRCODE_SUCC) { + PRINT("[gnss][service] app create mail fail\n"); + } +} + +static void create_gnss_http_recv_queue(void) +{ + + if (osal_msg_queue_create("gnss_http_service_recv_queue", 24, &g_app_recv_queue, + 0, sizeof(gnss_http_data_mail_t)) != ERRCODE_SUCC) { + PRINT("[gnss][service] app create mail fail\n"); + } +} + +#define GNSS_HTTP_BOARD_TASK_SIZE 0x2000 +errcode_t uapi_gnss_http_server_init(void) +{ + PRINT("uapi_gnss_http_server_init !\r\n"); + + send_taskcfg.create_queue_handle = create_gnss_http_send_queue; + send_taskcfg.attr.name="gnss_http_server_send_task"; + send_taskcfg.attr.priority = osPriorityNormal; + send_taskcfg.attr.stack_size = GNSS_HTTP_BOARD_TASK_SIZE; + send_taskcfg.func = gnss_http_server_send_task; + send_taskcfg.use_mem = USE_EXTEND_MEM; + + errcode_t ret=uapi_create_osThread_custom(&send_taskcfg); + if(ret != ERRCODE_SUCC) + { + PRINT("create gnss_send_service failed %d!\r\n",ret); + return ERRCODE_FAIL; + } + + recv_taskcfg.create_queue_handle = create_gnss_http_recv_queue; + recv_taskcfg.attr.name="gnss_http_server_recv_task"; + recv_taskcfg.attr.priority = osPriorityNormal1; + recv_taskcfg.attr.stack_size = GNSS_HTTP_BOARD_TASK_SIZE; + recv_taskcfg.func = gnss_http_server_recv_task; + recv_taskcfg.use_mem = USE_EXTEND_MEM; + + ret=uapi_create_osThread_custom(&recv_taskcfg); + if(ret != ERRCODE_SUCC) + { + PRINT("create gnss_recv_service failed %d!\r\n",ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + diff --git a/code/sdk/drivers/peripheral/gnss/src/uart_gnss.c b/code/sdk/drivers/peripheral/gnss/src/uart_gnss.c index 506b3b2ec..2dd7383cf 100644 --- a/code/sdk/drivers/peripheral/gnss/src/uart_gnss.c +++ b/code/sdk/drivers/peripheral/gnss/src/uart_gnss.c @@ -30,6 +30,7 @@ #include "uart_gnss.h" #include "gnss_ctl.h" #include "tiot_board_pin_port.h" +// #include "pgnss_sample.h" #include "pgnss_sample.h" // errcode_t gnss_get_next_cmd(uint8_t cmd_index,uint8_t** cmdbuf,int *cmdlen); // errcode_t gnss_get_current_cmd(uint8_t cmd_index,uint8_t** cmdbuf,int *cmdlen); @@ -112,11 +113,11 @@ void do_gnss_cmd(int cmd,uint8_t *buffer,uint32_t size) uint32_t gnss_write_cmd(uint8_t * cmdbuf,uint16_t cmdlen) { - return uapi_uart_write(TIOT_UART_PORT, cmdbuf, cmdlen,0); + return uapi_uart_write(TIOT_UART_PORT, cmdbuf, cmdlen,0xFFFFFFF3); } uint32_t gnss_data_read(uint8_t * cmdbuf,uint16_t cmdlen) { - return uapi_uart_read(TIOT_UART_PORT, cmdbuf, cmdlen,0); + return uapi_uart_read(TIOT_UART_PORT, cmdbuf, cmdlen,0xFFFFFFF3); } static void uart_event_task(void const *arg) { diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/CMakeLists.txt b/code/sdk/drivers/peripheral/ppg/gh3x2x/CMakeLists.txt index 1cea5b759..5846c7f0b 100644 --- a/code/sdk/drivers/peripheral/ppg/gh3x2x/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/CMakeLists.txt @@ -8,9 +8,76 @@ if("PPG_GH3X2X" IN_LIST DEFINES) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/inc + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/inc + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/inc + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/driver/inc + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/kernel + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_agc + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_ecg + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_other + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_protocol + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_soft_adt + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_mp_code/inc + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/ + ) set(SOURCES ${SOURCES} + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_accppg_sync.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_call.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_frame.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_hook.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_memory.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_reg_array.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_strategy.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_adt.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_af.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_bt.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_ecg.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hr.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hrv.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hsm.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_nadt.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_resp.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_spo2.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/driver/src/gh_drv_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/driver/src/gh_drv_control.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/driver/src/gh_drv_dump.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/driver/src/gh_drv_interface.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/kernel/gh_demo_hook.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/kernel/gh_demo_protocol.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/kernel/gh_demo_user.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/kernel/gh_demo.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/kernel/gh_demo_reg_array.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_agc/gh_agc.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_ecg/gh_ecg.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_other/gh_changeinttime.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_other/gh_movedetect.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_protocol/gh_datatrans.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_protocol/gh_uprotocol.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_protocol/gh_zip.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_kernel_code/module/gh_soft_adt/gh_multi_sen_pro.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_mp_code/src/gh3x2x_demo_mp_process.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_mp_code/src/gh3x2x_demo_mp.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_mp_code/src/gh3x2x_mp_algorithm.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_mp_code/src/gh3x2x_mp_param_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/demo_mp_code/src/gh3x2x_mp_reg_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/goodix_ecg_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/goodix_hba_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/goodix_hrv_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/goodix_nadt_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/goodix_spo2_config.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/heart_net_org_dll.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/HRNet_knBasicWeights.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/HRNet_knConfNetWeights.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/HRNet_knMultiWeights.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/HRNet_knSceneNetWeights.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/HRNet_knSmallWeights.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/HRNet_knTdfusionWeights.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/HR/04_EXCLUSIVE/HRNet_knWeights.c + # ${CMAKE_CURRENT_SOURCE_DIR}/algo_params/SPO2/02_PREMIUM_EXCLUSIVE/pv_v2.1.0.0_spo2wrnet_for_GH3228T_cd023f.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/gh3x2x_afe_adt.c ${CMAKE_CURRENT_SOURCE_DIR}/src/gh3x2x_afe_agc.c ${CMAKE_CURRENT_SOURCE_DIR}/src/gh3x2x_afe_demo.c @@ -43,6 +110,7 @@ set(COMPONENT_PUBLIC_CCFLAGS ) set(COMPONENT_CCFLAGS + -mabi=ilp32f ) set(WHOLE_LINK @@ -53,5 +121,30 @@ set(MAIN_COMPONENT false ) +if("PPG_GH3X2X" IN_LIST DEFINES) + +find_library(LIB_PATH_DRV_COMMON lib/drv_common.a ${CMAKE_CURRENT_SOURCE_DIR}) +find_library(LIB_PATH_HR lib/hr.a ${CMAKE_CURRENT_SOURCE_DIR}) +find_library(LIB_PATH_SPO2 lib/spo2.a ${CMAKE_CURRENT_SOURCE_DIR}) +find_library(LIB_PATH_ECG lib/ecg.a ${CMAKE_CURRENT_SOURCE_DIR}) +find_library(LIB_PATH_DL lib/dl.a ${CMAKE_CURRENT_SOURCE_DIR}) +find_library(LIB_PATH_DSP lib/dsp.a ${CMAKE_CURRENT_SOURCE_DIR}) +find_library(LIB_PATH_NDAT lib/nadt.a ${CMAKE_CURRENT_SOURCE_DIR}) +find_library(LIB_PATH_HRV lib/hrv.a ${CMAKE_CURRENT_SOURCE_DIR}) + + +target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive +${LIB_PATH_DRV_COMMON} +${LIB_PATH_HR} +${LIB_PATH_SPO2} +${LIB_PATH_ECG} +${LIB_PATH_DL} +${LIB_PATH_DSP} +${LIB_PATH_NDAT} +${LIB_PATH_HRV} +PRIVATE -Wl,--whole-archive) + +endif() + build_component() diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knBasicWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knBasicWeights.c new file mode 100644 index 000000000..e2e12ebf4 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knBasicWeights.c @@ -0,0 +1,150 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION " " +#define NET_SIZE 1033 +const uint32_t knBasicWeightsArr[] = { + 0, 1065353216, 724074269, 3885820506, 116917501, 8325352, 4009493501, 3926125851, + 2161842448, 3296732125, 499697052, 3523277298, 461327217, 3960081188, 505348323, 2149717546, + 2845024915, 3171188527, 151061238, 2134244610, 4074417519, 437450231, 267058303, 50458103, + 2813066753, 3038114581, 4112774272, 2137178607, 3643742947, 4011595198, 2154615556, 953478318, + 604049279, 3925351442, 295229678, 1118162559, 1057853400, 718931178, 3792759679, 3789759757, + 650761956, 436161663, 3210615378, 1063018013, 1056639630, 1065353216, 1058578260, 1055904030, + 1059577124, 1063070521, 1063921745, 1053253201, 1062869368, 1063270524, 1056107973, 1054486009, + 1056482121, 1051663868, 1057700387, 1064292754, 4267020469, 30800337, 4243356951, 255311887, + 4148940150, 268435456, 15797825, 4196239507, 10382080, 4206944257, 33168317, 4267549491, + 4194558368, 4251032117, 4136333637, 63549088, 3218110748, 1070627100, 3224244733, 1070740148, + 45552144, 821823230, 4147767820, 3774578669, 3212990201, 1065439819, 1065353216, 268435456, + 3198541715, 1051058067, 0, 1066136862, 2155904896, 2155839615, 2155839359, 2155904896, + 3215048011, 1067481552, 1021622277, 1032504991, 1065353216, 1038368988, 1043184335, 1009913960, + 1057625652, 1015169454, 1028722280, 1045823207, 1062057380, 1041544221, 1042872117, 1026739558, + 1030026884, 1032034585, 4252355240, 31073929, 4189056835, 268435456, 4144192690, 267535180, + 28518707, 4052206990, 12099610, 64170252, 26676094, 4270547324, 4204280637, 4243282847, + 4100214973, 57002036, 3216988996, 1069505348, 3213732839, 1062662953, 0, 1072416415, + 433563725, 3239773163, 2131181908, 4265723304, 488029220, 1057086517, 1376813294, 37438783, + 3212920416, 1065370579, 1061247935, 1065353216, 76575876, 268435456, 3213940763, 1066457115, + 0, 1067168424, 3749740696, 2155083391, 3900669712, 2144960543, 2149833599, 2146271239, + 2157365888, 2146116736, 3216828142, 1069247776, 1061268306, 1054805463, 1062362518, 1048504269, + 1057162170, 1035314156, 1051676869, 1045976474, 1063211847, 1051508606, 1054179445, 1032881169, + 1062210613, 1065353216, 1057175496, 1034667418, 146732556, 20972983, 4255953782, 89001604, + 4287636647, 102922619, 4292032938, 4271503333, 53667483, 181214832, 4294190206, 228610537, + 96137260, 4026531840, 43658581, 4250910859, 3231392109, 1083908461, 3223891720, 1061594917, + 0, 1075135832, 1087603170, 3740693035, 1116173620, 3702372224, 3209232996, 1061646431, + 1065353216, 268435456, 3228063537, 1080579889, 0, 1075011896, 2139062400, 2139127936, + 3225871845, 1078286361, 1065353216, 1028055723, 1043693058, 1040568123, 1035765628, 999522116, + 1031180663, 1040038796, 90966773, 4203970396, 174305310, 268435456, 109511612, 4278446045, + 75256247, 4179291306, 3221254755, 1073771107, 3234841126, 1067097188, 521500212, 923125524, + 136041989, 511646500, 450574421, 3477102367, 24829152, 2811694719, 131393537, 418256385, + 98701815, 2163996400, 248887220, 3632326391, 931798525, 140300498, 343926214, 38207450, + 4233817947, 98817506, 198458898, 2132213620, 351985133, 4148616698, 319362349, 4160554234, + 4162653429, 32247679, 827630504, 19724546, 4042982463, 32116608, 3223693199, 1076124736, + 1053783709, 1047579787, 1062425973, 1050458755, 1059246939, 1048828207, 1065353216, 1055145552, + 87463259, 4203942127, 174412105, 268435456, 109311232, 4280280516, 75283057, 4179587927, + 3221254755, 1073771107, 3228787584, 1083001352, 0, 1082681049, 4289636220, 3089, + 3494182951, 4294297594, 72988, 4286829702, 218107406, 1594677, 3975474687, 3087016388, + 829399039, 4059889639, 3086996961, 4294306798, 4293915577, 4293061563, 4280787864, 10259297, + 11446705, 7839654, 4283199390, 7707534, 3346427648, 4278733445, 3453542400, 3553046190, + 227213452, 151280085, 2412862464, 1298876092, 2525785856, 1484549267, 3026502655, 3284253470, + 5247860, 353346197, 42926223, 81104, 3194144767, 3401890583, 4105499136, 3958468924, + 2274265723, 4287600331, 2173795144, 2019897344, 1932359884, 2171993969, 1904240253, 1701887231, + 3939888944, 4109269760, 1577085385, 1834691385, 1157648608, 1481408275, 1459642582, 1680375616, + 2254608029, 4285168532, 2763194267, 3839463513, 2691677031, 2695142144, 2779232900, 3249315584, + 2204142079, 2526145584, 2959205372, 3416503040, 3573585812, 1582731987, 1050713158, 3226087645, + 1073870099, 3212787730, 3195926809, 3216082652, 3226633333, 3215137574, 1079490460, 1065237717, + 1033423704, 1051672171, 1006691043, 1077082412, 1051372746, 1052938626, 1039207426, 1058496494, + 3203069010, 1052852587, 3199260745, 1041804355, 1051620981, 1060416570, 1039210092, 1061110839, + 3203843233, 1053051779, 3197568205, 1041798471, 1051801222, 1060814499, 3222278102, 1074720694, + 3222375327, 1074817160, 3243751324, 1096267676, 1019754651, 1063519344, 1046064357, 1012698070, + 1045097311, 1019483124, 1065353216, 1058122366, 1061821161, 1021844088, 1018390782, 1048811270, + 1038636641, 1062319611, 1052125277, 1049839807, 1009351890, 1021679867, 1006539629, 1025445043, + 1009359331, 1019697659, 1029568837, 1014340242, 1048884352, 1047653154, 1065353216, 1058945453, + 1054241782, 1054749875, 1051419295, 1060930322, 1059598055, 1052855882, 1057036698, 1050017803, + 1050794751, 1058969392, 1044175313, 1047798903, 1051308378, 1052338510, 1053477983, 1052619626, + 1052905720, 1051702097, 1048767499, 1044379887, 2302371407, 2240179846, 4283848803, 2074846882, + 3635844206, 1888790317, 1955628158, 2529152860, 1302768511, 1232755581, 1734857817, 1968929648, + 2189853336, 1600094103, 2357753474, 2002880677, 2642976623, 1247105878, 2260754278, 1684502892, + 2054652244, 2391367022, 2256377222, 1785020301, 2734708570, 1802335860, 2359125029, 1684676986, + 1360026111, 2563201343, 3531631554, 2325119653, 1111722667, 1048009824, 797014918, 2345028191, + 3362481287, 574717070, 2556936219, 1432371054, 2156353169, 1403614615, 2339402847, 1970825621, + 2678493621, 2727641126, 859936415, 1851017861, 2154730376, 2527034509, 2828375950, 1953644412, + 2975624566, 2206429262, 2073470076, 2226202112, 1064256376, 2425511503, 3920646911, 2465244324, + 916228198, 814777452, 341476752, 2516047224, 3264382863, 305667958, 1467070811, 1565869926, + 2024172456, 1583378038, 1327850659, 2357220007, 4049163220, 2413788064, 2868867364, 2341498016, + 1952158335, 2176677504, 2695596408, 2406964113, 2154855232, 2189385607, 697920411, 1462584454, + 1412538294, 1249202049, 3308727691, 1605420119, 2044826256, 2255774140, 1634614927, 2362949804, + 2492244139, 1728070013, 3784018621, 2674737283, 1016427958, 1081362290, 2203613808, 2693173058, + 4283482003, 3450252167, 1601468566, 1248892532, 1868138890, 3033440088, 3649804436, 1330141300, + 2239477833, 1767209349, 2021943434, 1716483188, 1673572944, 1822994112, 379530495, 3366801818, + 1282774892, 2808668526, 158440073, 2406643963, 3129816764, 1222019195, 2375166632, 3134632250, + 2474793844, 2305981090, 2326502500, 3862859740, 1720206189, 2269347245, 929535087, 2445707719, + 2792467400, 2940971353, 1483629676, 2979170910, 1325374623, 2423878274, 2072279939, 2757334402, + 3112937426, 1885633176, 815705720, 1669499780, 2428538311, 2960163509, 2761390480, 2074156510, + 2476386184, 4002650262, 2626258014, 1660903575, 2188679554, 2155906155, 4291324759, 1398248667, + 3400180140, 2152448895, 2021496435, 2070317915, 2092590739, 2472002224, 1772790682, 1890088344, + 2326437305, 2423428254, 1633125495, 2761711469, 2658242481, 1519817899, 2639642922, 2507045240, + 1333300323, 2676449257, 3361899395, 2173874829, 2304934253, 3072895126, 1938909647, 3059902719, + 2391113856, 2156230785, 2694942289, 2458354355, 3337261939, 1781724068, 3949039009, 2624568447, + 2277853353, 1909167255, 1940895390, 1282526555, 10714289, 2774637045, 2374333294, 2891670442, + 1373538994, 3883109548, 947460457, 3202512048, 2175763296, 2710861501, 3993034136, 2743147982, + 3500746138, 3119084445, 2308868669, 1506639364, 2040954502, 2557769087, 2053009280, 1972140258, + 853694544, 2765512075, 1921744163, 2524614038, 4285042834, 1938137658, 981299846, 947094177, + 2088324335, 2953158528, 2509335680, 2039251336, 2977064568, 1855892376, 1649125311, 1472021649, + 1063813221, 1904369543, 1685217668, 1515678636, 2470744190, 4177548908, 2993367706, 2075725978, + 2392419201, 1800963479, 2189851773, 2122484607, 1702458997, 2120776402, 2231338113, 2324599180, + 2458420078, 2323090298, 2224192910, 2189984905, 2560721549, 2089388167, 1919644800, 1884513478, + 1534550111, 1734584146, 2720108135, 2322961289, 3417010844, 3268969115, 2108072847, 2795686766, + 2164240502, 2342891661, 1904536465, 2474189141, 2070059145, 2577040478, 2089991610, 2292278411, + 3683563399, 2679688357, 3647837311, 2796198320, 2007518831, 2009378000, 2528231051, 2443706220, + 1583191447, 2611517164, 2825025578, 2158077341, 2423949415, 2994247322, 1840149350, 1890218125, + 1970702196, 1987789468, 4281954433, 1970681441, 2926872708, 2391369856, 2272470904, 1987696477, + 2022666361, 2071168396, 1837661275, 2273509193, 118064457, 2285347203, 158559379, 2492631720, + 1783598186, 2840227549, 1799914909, 2493755747, 781274806, 1131314614, 1514308437, 2187958131, + 3113775237, 1719220404, 3332606354, 1759940039, 4035082879, 1839908096, 2411875227, 2206900814, + 1339302786, 2245544064, 3159737404, 1821083239, 2158517870, 1802009772, 1937946555, 1753899628, + 3268095136, 2859440965, 2172484504, 2322572398, 9149555, 1904971239, 1620272011, 1000703876, + 1619437257, 1903658635, 2089454216, 2040232051, 2885517823, 3448233875, 2192464188, 4093657160, + 4290955144, 3703496396, 2877263726, 4281955444, 2426308501, 4294617302, 2460196997, 4198760314, + 2960156521, 4290093758, 2728555105, 4287595116, 2227407998, 4286088069, 1355450493, 1269825437, + 2485208362, 6907223, 1082217584, 2432665229, 2426767359, 3425855426, 2425651849, 1979680417, + 1867601230, 2071094015, 2346882043, 3372246659, 2188413439, 2962261935, 2660564869, 2356995456, + 1218457344, 303519752, 3548905342, 1576130695, 2388561089, 1775147007, 2659568540, 2109144983, + 2289470867, 2030018212, 2157676709, 4285499507, 1045027225, 3195156399, 1037718901, 3160320931, + 1017530882, 1044653376, 1049853487, 1039348670, 1027003274, 1015463069, 1050058673, 1030878119, + 1042229973, 1041485290, 1041891780, 1036171360, 3181755189, 1024276694, 1045172998, 1038873963, + 3175783599, 1012182795, 993447707, 1023382925, 3177036773, 1030424204, 1015367376, 1003961708, + 1017669843, 1034244175, 3171267020, 1015856047, 3214638470, 1067075211, 3215801189, 1068228846, + 3217822470, 1070338822, 1056776477, 1060485056, 1054651097, 1065353216, 1052470295, 1058186576, + 1054163221, 1057801571, 1054622292, 1059229927, 1057568093, 1059816688, 1058757508, 1057082891, + 1057017220, 1057693575, 1046038220, 1058440860, 1041658374, 1050623982, 1045999469, 1041564100, + 1042166701, 1043372405, 1050693278, 1057282511, 1057714692, 1058392653, 1058292420, 1058371987, + 1055819276, 1054472559, 1059487364, 1052380544, 1058333379, 1061166387, 1052129059, 1059485737, + 1051626949, 1053523575, 1062524611, 1061837256, 1051141380, 1058308016, 1060606548, 1061606283, + 1063173819, 1065353216, 1050814981, 1053662896, 1057971445, 1059644381, 1058171151, 1053894099, + 1047368800, 1051703920, 1050999862, 1053630173, 1057851348, 1059678044, 1058248640, 1054333290, + 1048663672, 1050673849, 1050808511, 1053667596, 1057988210, 1059650101, 1058169584, 1053884486, + 1047314016, 1051732412, 1061274806, 1053420314, 1052957645, 1056965528, 1065430091, 1055066668, + 1061157785, 1053396084, 1054162419, 1056244695, 1057685728, 1058014138, 1059934895, 1054778511, + 1051102724, 1054568131, 1061262442, 1054602947, 1052917804, 1056846561, 1065403501, 1052605457, + 1061381802, 1053341833, 1057036907, 1057000930, 1055775738, 1056977090, 1061117621, 1056900118, + 1052932409, 1052905471, 1050927578, 1053569203, 1058382631, 1059597529, 1058116451, 1053698020, + 1047876750, 1051715234, 1050902883, 1053554957, 1058400474, 1059600478, 1058102734, 1053675458, + 1047823251, 1051741527, 1058355593, 1057075606, 1055480181, 1057125400, 1061329790, 1053604470, + 1054332702, 1052876418, 1050775002, 1054451887, 1058090276, 1059593699, 1058105889, 1054179078, + 1048684516, 1050329889, 1060299262, 1060922685, 1060301902, 1058004604, 1060146378, 1057043951, + 1059285650, 1060397044, 1060423376, 1059248241, 1060620034, 1062245968, 1063034750, 1062241084, + 1065406211, 1064111170, 1065408700, 1064448288, 1062284230, 1062284100, 1064973952, 1063096283, + 1059800242, +}; + +uint32_t* get_knBasicWeightsArr_addr(void) +{ + return (uint32_t *)(knBasicWeightsArr); +} +uint32_t get_knBasicWeightsArr_size(void) +{ + return sizeof(knBasicWeightsArr) / sizeof(knBasicWeightsArr[0]); +} +void get_knBasicWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knConfNetWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knConfNetWeights.c new file mode 100644 index 000000000..d604ec462 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knConfNetWeights.c @@ -0,0 +1,393 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION "9b33ee" +#define NET_SIZE 2979 +const uint32_t knConfNetWeightsArr[] = { +0, 1065349120, 3900738106, 3318004714, 4274026504, 3140808700, 1174986441, 4010724484, +502521472, 4008254750, 3994027268, 319424226, 4046213494, 3924411520, 3840422937, 4012248550, +538570994, 1464026239, 3973627709, 788279823, 643124552, 2120569400, 2160462847, 3994697897, +204536298, 4277653988, 3539339785, 35996543, 3722692310, 3570934288, 3591768022, 437445332, +976701240, 4141645848, 3399531754, 3199010288, 3940279047, 1007597532, 243761231, 2795516186, +3376950555, 487196884, 1784102425, 3470770559, 31710928, 118690058, 4075350260, 3128986812, +1347692540, 1145648951, 1124146224, 674843984, 1949105577, 3611500671, 672572836, 347391710, +2444810259, 1988053540, 4276479770, 84350726, 4075159303, 4159035869, 1448629337, 4111083328, +4196631001, 4102079465, 3219646691, 3640583296, 3991997317, 118423527, 335935236, 318900744, +4180225044, 4162403585, 810716889, 545310721, 3303077132, 1663826153, 3708879231, 353019315, +416341741, 3689084683, 1242545373, 498710896, 2157720101, 3025939201, 520618437, 2138595629, +256859, 183564286, 3908961797, 4227530764, 2138321086, 68941217, 234035703, 2920420368, +4143057719, 759052590, 353176060, 3487352859, 310428621, 3239055373, 2138073688, 3048662602, +3638350515, 47961806, 4243255029, 4130561407, 118231937, 152825601, 451739139, 3876323077, +1483763327, 3855483107, 3388158720, 3271806908, 96710604, 838516864, 4211475313, 4278778370, +4260824056, 4228186623, 3522834303, 4142983091, 3890156554, 3743158521, 302841059, 1095056983, +1598357789, 3552608099, 782559, 607333911, 669560192, 134936926, 72203, 3927248125, +201590783, 3522881422, 219090048, 50459904, 151784459, 4244440582, 725499007, 3974610592, +3470603775, 3893687258, 1041231096, 855370717, 4229304703, 118139100, 734124276, 3403938835, +1460589696, 238621302, 472104692, 450820338, 3454140179, 3791186048, 4261280944, 185276172, +33881337, 521866753, 3208263691, 1060684699, 1050757938, 1057907911, 1054210471, 1045953334, +1051660865, 1057385148, 1050433382, 1058009944, 1056998176, 1049564054, 1044556698, 1053216301, +1056809115, 1058112067, 1054260430, 1051506851, 1050931343, 1055287118, 1043109379, 1057611734, +1050020701, 1052932758, 1049998918, 1059456311, 1061132870, 1050714636, 1057438882, 1065353216, +1050987234, 1056784568, 1049685503, 1064457174, 70498212, 58503888, 4267390377, 13612176, +16693140, 4258212014, 4894117, 4284895581, 4130888878, 268435456, 4279142416, 142222043, +4247864594, 68454020, 4254374046, 4273104253, 4293922130, 4287878881, 4212544288, 4183117306, +4275815948, 66762, 4248662688, 10710117, 24992789, 79629768, 153056835, 40745785, +4221338845, 40145577, 4270845373, 169307526, 3219817242, 1072333594, 3218232944, 1068837551, +776139372, 688609805, 729810152, 2882730173, 3995277301, 3175947791, 3973653076, 4222401619, +3205851242, 1058291097, 1065353216, 268435456, 3212551351, 1065067703, 0, 1078656145, +2290816, 3204397754, 1056783429, 1065353216, 268435456, 3221243295, 1073759647, 0, +1058194463, 2155839359, 2155839359, 2139062400, 2139062144, 2155839360, 2139062143, 2139062400, +2139062399, 3204465839, 1056868427, 1055297541, 1056217720, 1051973082, 1060480751, 1049988760, +1049018483, 1058854830, 1038297867, 1058295548, 1052791255, 1052952300, 1060591501, 1059870573, +1058628283, 1039600008, 1056844973, 1057314991, 1036674212, 1063918753, 1065353216, 1042606230, +1041567050, 1061044338, 1028048714, 1058188544, 1062291287, 1041147230, 1056774660, 1056811537, +1048645073, 1056986276, 1055028972, 6475933, 47458995, 25612877, 481668, 15182755, +9410212, 4294341666, 4267057721, 4168218233, 268435456, 4294270908, 226767434, 26495062, +56878938, 2894489, 4273697869, 2180093, 49504589, 4267074380, 4277158842, 33954514, +20235973, 4286412716, 15617654, 33726759, 129151171, 210469455, 28073590, 11379805, +58591362, 4267492099, 143900420, 3220042848, 1072559200, 3193888458, 1051887117, 0, +1071052189, 4061388249, 3883863765, 88870609, 600893151, 3324055522, 438375177, 3407869982, +101773319, 4165840326, 3363791290, 124591294, 1674560992, 3040613567, 1431046174, 2837116768, +3965196867, 3213786666, 1066230062, 1063313374, 1065353216, 136828864, 268435456, 3212980070, +1065496422, 0, 1082475162, 3426189117, 32520, 3212928231, 1065378333, 1065353216, +1062353328, 82625669, 268435456, 3213967502, 1066483854, 0, 1080013532, 343929983, +2142852479, 2134212673, 2151167615, 2164162624, 394231865, 2145419071, 2134251648, 2143649833, +746590335, 2151251764, 1518305117, 2143899776, 2021621551, 2132429951, 2140279679, 3213379879, +1065826453, 1054429555, 989003575, 1059394170, 1057576237, 1062163485, 1063091647, 1057329293, +1029617484, 1040476443, 1027706019, 1063376311, 1058661573, 1056004798, 1059118203, 1032739992, +1064241988, 1039372092, 1051867859, 1056077566, 1044810446, 1061837093, 1065353216, 1054679368, +1057072084, 1040830584, 1050546967, 1056970891, 1047609756, 1053731225, 1061627951, 1057781979, +1043503381, 4231942549, 4293907570, 4177478783, 4079376787, 16788883, 85436745, 4205351918, +4270089594, 1357106, 65824647, 67706497, 32373565, 148978953, 4107162503, 4204538840, +38994357, 4227335330, 4215831368, 4196895578, 4165061633, 4282293500, 4281651673, 176547827, +4144067114, 4270397415, 5006273, 4026531840, 4176161096, 4159892313, 4220900491, 4186976394, +4280041714, 3224318065, 1076834417, 3223312940, 1081860972, 0, 1081614911, 1049401682, +3180767598, 1046347740, 1046449901, 1050056884, 1044369992, 1031494127, 1050547688, 1059256432, +1056173111, 1053328729, 1047801170, 1043167884, 1033085153, 3188066852, 1009165057, 3182311443, +3195456552, 3194270196, 3199674790, 3165620441, 1051896713, 1040104955, 998882878, 1022079844, +1036282194, 1048805498, 1048274341, 1032000323, 1039526883, 1053243796, 1057439029, 1047028827, +1017109842, 3170947845, 3180766531, 1044486661, 1044608931, 1048531421, 1043978524, 3180151818, +1038328082, 1054010239, 1052319736, 3180300294, 3175342309, 1022587478, 1030045461, 1041004419, +1047347048, 1046961818, 1043697022, 1027773408, 1051087531, 1051423737, 3194480004, 3190975831, +1036191969, 1041339721, 1043400279, 1038341866, 3154212849, 3183407527, 3168968670, 1051360794, +1040265342, 3194672033, 3197446344, 3187709201, 3170475443, 1040317661, 1048069415, 1036996501, +1022109061, 3176721201, 3172395616, 3194629242, 1029933063, 1049948421, 1054704390, 1030591362, +3136228660, 3166744484, 3172851087, 1041059993, 1032665219, 3189852658, 1034733260, 1049343835, +3180606574, 3191059537, 3195932152, 3191221908, 1047355766, 1046762964, 1046897462, 1042012181, +1040291671, 3187416116, 3188913525, 1024784971, 1052923084, 1048576281, 3190668746, 3190843570, +3182610100, 3156300320, 1042877049, 3155605734, 1046072140, 1052263972, 1035820222, 3197905352, +3191632543, 3179536899, 966426146, 1025186865, 3187202288, 3192504083, 3186887235, 1042729491, +1037188863, 3193356313, 3188827595, 1044518490, 1048612835, 1005848295, 3194233338, 3189538000, +3177162437, 1025726785, 1046275579, 1040563572, 1026609160, 3176105971, 3177927080, 3191914067, +1019390086, 1049810974, 1056220769, 998578562, 3173328684, 3172957751, 1029979366, 1044282431, +1041654506, 1038608452, 1045212285, 1031973674, 1036764443, 1041803925, 1030675695, 1040759950, +1028540507, 1042494474, 1042444922, 1056930890, 1033638351, 1053647033, 1054314368, 1056873462, +1054744020, 1048583053, 1053511215, 1056485075, 3198154679, 1051397335, 1051541343, 1020882410, +1046024035, 1040270407, 1044325163, 1037976853, 1035606604, 1036865586, 1051668944, 1021627787, +1052204643, 1033631805, 1043433945, 3190670714, 1051502283, 1029651226, 1038925823, 1027641704, +3166666858, 3195647945, 3171352906, 3189630682, 1065280588, 3190557085, 3193143545, 1057019815, +1051454618, 1052297075, 1057008036, 1056999392, 1057745822, 1040362028, 1055583305, 1052939944, +1055163838, 1049972978, 1049774229, 1031915837, 1056741191, 1035447102, 1044095241, 1045359002, +1056941700, 1039824150, 1057762506, 1057154814, 3204522674, 1058953916, 1041971097, 1024305323, +3173244433, 1023493727, 1040771461, 1018559378, 1042977279, 1052146179, 3191456539, 1053672060, +1008402816, 1051466887, 1052089558, 1033639186, 1027269209, 1047184743, 1050702059, 1048160766, +3200506821, 1059589977, 3197490630, 1041649061, 1053144441, 3188626221, 1056528646, 1048574449, +3181253007, 1053456411, 1050502460, 1033247130, 3181793892, 1054507256, 1049677943, 3195014825, +1053698341, 3197658954, 1056773176, 1031106663, 1036524434, 3160123140, 3191273728, 3204111160, +3193992411, 1049045108, 3198991355, 3202926857, 1043847804, 3195683222, 1042856392, 1049357658, +1064616453, 3189394993, 3191494130, 1033157658, 1053706814, 3203278730, 1058545547, 3166677983, +3180861828, 1045663915, 3200942715, 3189315642, 1059080300, 3192171551, 1021838990, 1038433779, +1047212980, 3176776980, 1057394215, 1050861964, 3196368465, 1056193588, 1036898471, 1054693191, +3209351126, 1055267186, 1052998478, 1052738023, 1042122762, 1038805363, 3199774059, 1044807449, +1021698461, 1028315966, 1044544232, 1049161456, 1032880064, 1042587614, 1056447965, 1049695948, +1043933578, 1035582311, 1038026805, 1034141672, 1040727542, 1039242245, 1034598809, 3138183509, +3178815446, 1059467306, 1040327290, 1062535717, 1065220618, 1059567394, 3191670262, 3161523287, +1045999302, 1062101848, 1050077077, 1058211096, 1069489543, 3200332003, 1065559196, 3188956891, +3188507415, 1054095368, 3209612490, 1061557483, 1065725771, 1060530636, 1059687447, 3199141678, +1018147738, 1060119772, 1053620811, 1053101290, 1064531244, 1057573395, 1056433377, 1031667296, +3180781211, 3180308707, 1053099539, 1031942824, 3136097152, 3201339698, 3201850186, 1045334003, +1018408187, 3176648920, 1031898339, 1041204198, 1022332406, 1048519306, 1007523056, 1031384182, +1046013050, 3170973036, 1015104674, 1051693669, 1047021818, 3170409343, 1041483556, 3183564528, +3187147654, 1031731691, 3159602667, 3160115246, 1046111841, 1030615450, 1022674510, 1059629844, +3138936300, 3196149264, 3184087254, 1023867829, 1034985409, 3161660794, 1004990474, 1015148115, +1032074637, 1017244654, 1033132638, 3147721891, 1051216436, 1037508159, 1045130932, 1026404496, +1062726990, 1026496116, 1048592883, 3191755361, 3190095131, 1034405989, 1063518105, 1040141586, +3185043635, 1055231333, 1045649000, 1024106775, 1041943509, 1016717896, 1049558476, 1055350232, +1021921403, 1059196322, 1028044330, 1040191314, 3203434155, 1024279889, 977116640, 1037040959, +1048614240, 3160696543, 1047481796, 1053255589, 1038738140, 1049118871, 1023891817, 3191118665, +1048643786, 3178358593, 1043905081, 1041415135, 1033119409, 1041090560, 1052555495, 1022909505, +3192091480, 3187733995, 1058958805, 3166300494, 1057529808, 3179704722, 1040872020, 1050127812, +3171614228, 1045710068, 3171436346, 1023394809, 3202321235, 3192340593, 3180920324, 1013996814, +1035697955, 3179240701, 1034438925, 1050641862, 3170296627, 1052408824, 3180797885, 3169179021, +3188992767, 3183956978, 3189487531, 1047587461, 3207708496, 1035521549, 3199450019, 3162613365, +3181715702, 3199544968, 1035532574, 3187295385, 1050433272, 1015616257, 3190253440, 1052246510, +3183228580, 3186419690, 3184727447, 3188126614, 3190298205, 1043017323, 3165083099, 3195408632, +3196746936, 3181266304, 3191025997, 1024052234, 1018408453, 3176648900, 1031898340, 1041204198, +2583660216, 1903260672, 1836020224, 4140874751, 2172682496, 4004446225, 1686962101, 2071756032, +2223211519, 2240120063, 2407697151, 2779227903, 2240120063, 3166155519, 2205127423, 2811592704, +2088532992, 1026949222, 2474872832, 2121692928, 2189523968, 1627419188, 4287930395, 2306770688, +2039021724, 2386067746, 3320997067, 4286721088, 2438070208, 3657204112, 3904858623, 3196025925, +2248112529, 4204608133, 744246038, 1689255859, 3620639487, 3976251812, 2778851839, 2273664961, +738912784, 8825563, 168485898, 10081243, 3232432312, 2758955311, 1716154806, 1063284480, +252299030, 11325379, 3047096499, 2551345986, 3653501134, 3351137837, 3839688909, 3065869125, +3807518445, 4285085999, 2390556559, 1973326527, 2842662038, 2751490940, 3922420217, 4060100420, +1681588319, 915917976, 2657026187, 1456639880, 2102526060, 1345893555, 4087611382, 2541983701, +3211369850, 3172006389, 3196952434, 3204731778, 3168795509, 3198594548, 1041097533, 3166504887, +958997221, 1025208006, 3198934274, 1024833684, 1027543364, 1034736932, 3197653830, 3187495703, +3156576820, 1056995902, 3186797335, 3179861711, 1057953589, 1056667917, 1046431997, 3189768243, +3148384662, 1056996131, 3187036496, 3179170712, 1057953564, 1055676040, 1046422776, 3190029742, +3204540540, 1056990635, 3212950702, 1065400629, 3230603061, 1083119413, 1043351929, 1063400444, +1061107123, 1040476210, 1061558887, 1040381021, 1037583314, 1061144857, 1000170595, 1065353216, +1043304393, 1045015988, 1065352562, 1062316773, 1049978767, 1037102984, 1057673820, 1040288003, +1036052237, 1057227623, 1031431317, 1020212491, 1035405413, 1047421560, 1060612456, 1014825652, +1026199134, 1052038407, 1016057796, 1056420246, 1048356999, 966187847, 950492984, 1015621848, +1061489916, 1024072861, 1018805552, 1052879371, 1049182710, 1040687777, 1000795402, 1065353216, +1055789166, 1035033607, 1058521835, 1055982936, 1055331900, 1039110827, 1954623901, 3008454520, +1115584661, 3198581643, 2894642787, 2788187304, 4199556645, 1833978182, 2197828042, 2136182664, +810897024, 1266980716, 2860739766, 2307495526, 1550148260, 1648072572, 2053004908, 1534756741, +2092075344, 1869304688, 3900056, 1905417505, 1885946252, 2205899661, 1884717960, 2373942902, +2089709707, 2410378610, 2206568591, 2375459218, 2157153915, 2405920348, 1886217073, 2340719214, +1950285936, 1751930992, 1921278073, 1485273461, 1903394931, 2071620227, 2021759350, 2206499229, +2208010421, 2961278855, 1553700268, 1882296990, 2826857601, 2489947589, 1148244, 1348301637, +2100464246, 1452813898, 1582920019, 2175438710, 2071170930, 1823843240, 2727903057, 3293404030, +1750446314, 2054387843, 1228369574, 2273590346, 1095334039, 691955026, 2152278272, 2206495099, +1817525370, 1600281481, 2056999029, 2272859210, 1416326032, 1386580067, 2138973017, 2660469388, +2289659526, 1952933976, 2332067158, 2506841237, 2051434159, 1922253686, 2744297586, 2746724770, +1937592441, 1887650115, 3531492467, 2071670938, 1315423743, 2594997661, 2727640209, 2760152441, +1466197804, 1534926687, 2503547026, 1968969816, 978997369, 1684569730, 1100836922, 2495961305, +1382967687, 2072007278, 1668962142, 1651078278, 1971749740, 2035832403, 7166834, 1618108963, +1917731154, 1835675746, 1768379001, 2088006006, 1971157365, 2205780388, 1283161994, 2409398631, +2288997959, 2808633433, 1986553994, 2139121511, 1899692177, 1716675720, 1785353089, 1267433859, +1735550290, 1785619832, 1854509165, 2374658736, 1920038805, 2191093896, 1534301571, 2088860830, +2020174686, 3028123982, 1601598052, 1482031180, 2200640554, 1364999488, 189289064, 272907130, +2240316298, 2172081520, 1567849580, 1821406058, 1585339233, 862029949, 1313761122, 1584479283, +772563776, 1617965568, 1718900827, 1984836172, 1364818027, 1835232621, 2072639858, 2371653513, +4287976618, 2207926900, 2040050074, 1616412021, 2443351154, 2168216447, 507390291, 428239252, +1696765551, 1598843971, 1349869089, 2660204100, 2289732223, 2357293035, 2844358759, 2473371019, +2490665395, 2292090013, 1953467004, 1736802443, 2368632169, 1434032925, 2123850378, 2572419184, +254164311, 1263619675, 1754560612, 2712161401, 2676984733, 2056293255, 2527107180, 1649639302, +2173599616, 2104658539, 5404044, 2340973714, 1921421417, 1752850531, 2274329461, 2407694717, +1920630384, 2138873276, 1632795220, 1667726473, 1738568023, 2073594508, 2406637940, 2405136013, +1335983203, 2034171905, 2185266308, 1482770785, 1163427690, 1332307298, 2844626350, 2257023361, +1704431510, 2190696052, 1314810958, 2188672389, 2036757617, 2525709141, 1364811083, 1666064731, +2000358786, 1349727344, 3219790, 1383024220, 1838646889, 2439339644, 3367206199, 3462826328, +2140654788, 2556003691, 2275300207, 2074214349, 2105302336, 2138717090, 2209014443, 1568775326, +2089849680, 1837259653, 2474799781, 2089184085, 4271782503, 2949906528, 2212812480, 2463339729, +3483020239, 3187315571, 1061377297, 1904776869, 3043576143, 2293075111, 2678298234, 2797129149, +643580433, 1282559334, 2846009475, 2123596176, 1719445391, 2654772922, 895776356, 2524626242, +1750973012, 372453490, 1801160448, 1870307165, 2706006131, 2058191988, 1853913190, 2105631102, +2509672061, 2845483909, 1937353919, 1715900052, 2324269695, 2307886461, 520140932, 1920102494, +2189849437, 2022078316, 2138927209, 1869769853, 2122022023, 1969709920, 1300672684, 1405002375, +2306359647, 2382342531, 2020132991, 2555986500, 3953828472, 1656081227, 1862749045, 2138076335, +2290636192, 2424932743, 1786090592, 2141158534, 1430462854, 1459620384, 537497727, 1883400519, +2507502692, 1985123728, 1026300709, 1966422070, 2869703992, 1682778514, 1788304189, 1366395768, +1935748223, 1721657925, 1638058434, 3014392201, 1938000034, 2300348301, 1686140068, 2058789201, +67150468, 2015983941, 2292026116, 1704368277, 3009776255, 2913505402, 1598447468, 1653381486, +2408230569, 2193011861, 2339543191, 2730792073, 2137956732, 2269992778, 2893771105, 1668001620, +2449484581, 1952683672, 2188863620, 2510132610, 2004383594, 2089256064, 3720251263, 3665904779, +2510795519, 2437245577, 2292414322, 1601078370, 791830672, 2223732132, 1552578902, 2084595536, +2303956144, 2291174499, 2088647814, 2089257542, 2173863810, 1181655420, 2488176016, 1432189819, +2308018309, 1939819066, 1272697, 2877663854, 2307992938, 2672978821, 1835701637, 2339668883, +2457106091, 2089715037, 2592710300, 2543235495, 2410196374, 1802410629, 2409200244, 1817269354, +6718526, 2946973503, 2082355825, 2457564554, 2306181260, 3146749316, 2054779785, 2038986120, +2641901657, 3007207484, 864858725, 2739047297, 2726771321, 2157300896, 2775009337, 2102263875, +1580703135, 1334342030, 1584908578, 2053912932, 2358473364, 2206283623, 1248909981, 1958804636, +2574331267, 1666027147, 2238146707, 2210357117, 7313025, 1854643624, 1993829740, 1302357106, +2173274232, 2809629841, 1970438770, 2038472321, 2575711629, 2584498842, 1605880380, 1035972251, +1342934475, 3900743600, 2751435880, 1057691758, 2440332648, 3081949100, 2208385548, 1331648120, +2358539168, 2286310765, 3032646039, 2908842345, 2162157567, 1705288065, 2680329827, 2034729576, +732986657, 2780518465, 2250854290, 2236900197, 1902867646, 2074252941, 1921221748, 2273004655, +1602177679, 1536514102, 2305770609, 3496901763, 2814071432, 1953108278, 3479402870, 2647070670, +1864106088, 814306388, 1502133383, 2424273276, 1954576495, 2058201466, 3099813750, 2200462377, +816235493, 1889241956, 2730789958, 2841959619, 1542902654, 2144435712, 2719241636, 2172104810, +1569682117, 1303665038, 1870437250, 2170803120, 4036298099, 3449954128, 3467964159, 1819636878, +2039386480, 1855356742, 1129555013, 2930078048, 1182169418, 2205768761, 3078333261, 2695135371, +2443408771, 2623417681, 2760486533, 2576337081, 2726996407, 1721735567, 2410060182, 2170827139, +1893512854, 3103772303, 2120763606, 2794354832, 1687787668, 1432519818, 2340390792, 2172222057, +3570975339, 3535328662, 2693981659, 2258200958, 2290585203, 1822140348, 4292381308, 2511065246, +1907213556, 2390470287, 2073139849, 2089522304, 2373747080, 2239270262, 711759474, 1200655718, +2255625577, 1768062081, 1720293251, 2374521414, 977375141, 1402516866, 1751523328, 2121615984, +2356109975, 2104522870, 2022073983, 2239138164, 3956861823, 3048341456, 3050360772, 2142017701, +2206697608, 2207945136, 3032266639, 2210046888, 2042739153, 2509081184, 2172093596, 2290124164, +1938461813, 2357294975, 589037714, 810156119, 1430986549, 2086830956, 2187947389, 2590797667, +1215261862, 1747792185, 2504732951, 1855150721, 1566342007, 1265004176, 2022214256, 2088661903, +2778378879, 2360655258, 2726605241, 1870759810, 1936237690, 2052282461, 1281718632, 1837807168, +2080382794, 2572578935, 1988125314, 2122943869, 2257221247, 2307288432, 3634998677, 3502096581, +2392255420, 1955499666, 2660794488, 1582589352, 2263259232, 3184686177, 1938203903, 2241441411, +1754901406, 2139064195, 2004789347, 2256376212, 1789939032, 1870875954, 1469008845, 2024050525, +2630776153, 1564692554, 172979317, 2512724480, 2115765366, 1816477602, 1297654443, 1869834624, +2021030794, 2055767678, 2355723161, 1836483213, 2410782573, 1718323071, 2020367486, 1784696911, +3559478, 2571769142, 2082743388, 1969908085, 1853062246, 2726595190, 2256696208, 2190309532, +2506967947, 2486855495, 1335140442, 3282866814, 2458790507, 1619836590, 4159010380, 2606170181, +2037228202, 1182629529, 1753601387, 2357223291, 2206305921, 2122285979, 2705852014, 1732116577, +1167962930, 2228067212, 2053020283, 2136847025, 2341564273, 2388020528, 2303702501, 1953927818, +1936941122, 1652451951, 1854443115, 2088200842, 2276706920, 2379003036, 2591190731, 1649574530, +2294003822, 1935832686, 2918528, 2278216024, 2170919799, 2339859829, 2171633317, 2106363778, +2105045879, 2021753443, 2522117522, 1653892000, 2285992836, 2404014204, 1872011683, 2260360348, +4119632346, 2042560255, 1977654948, 2543484272, 2508819372, 2122159503, 2441511041, 2120786315, +1031880036, 1165900345, 2072262014, 2203417204, 2693956447, 1881890174, 1048161978, 1656966215, +2181053242, 1569148014, 1569625247, 1904765558, 2274262916, 2307555686, 2923731422, 3680945808, +3475730688, 2906537837, 811686265, 1803265330, 3204420689, 1343250804, 1068983190, 1275046221, +2253550284, 1365200061, 2327838861, 751668054, 1748818127, 1921285324, 2472447671, 3881939864, +2488110592, 2170648230, 1670898603, 3643380445, 3849740333, 3006665728, 2205058018, 1617605923, +3793778749, 589631487, 2100963751, 7741242, 3028578657, 979837320, 15293572, 1408209513, +2441106115, 676677811, 2675218111, 1733681552, 2818594048, 1503141807, 1320447116, 1560259635, +2218485218, 1550009572, 1232426407, 766719026, 3263729006, 893727487, 1962891364, 2172694202, +741840605, 2446260541, 7157140, 226233448, 2443353420, 324216192, 2136583441, 1037172761, +1751736994, 2127975339, 2894956756, 2894910526, 3157131102, 3711247531, 4282803651, 2506745457, +3278410086, 3260959772, 2893326079, 3292060796, 3529314853, 1193891218, 2466283394, 2155122591, +1990076217, 1383093387, 2139663000, 1955200958, 2538165403, 2594408381, 2330739875, 4286081186, +253811316, 760712285, 4282870631, 1613407412, 2255073636, 1957456489, 2449498770, 1397462973, +2713537300, 1332775183, 1331446960, 3663482827, 2504965632, 2820765016, 2063756394, 1983807469, +2791535616, 2155895668, 4290473642, 2019998648, 2028771964, 2105452611, 2897364160, 2624114841, +3187653778, 3161489197, 2106565802, 1401269815, 4284585322, 1633697666, 177160868, 1775743382, +2415880331, 1902600765, 1874094211, 2274139495, 2174621710, 576061528, 3875504355, 1901905787, +2807819214, 2802492608, 2143761771, 1049646035, 2701193148, 3989409408, 3499852287, 2891169623, +3189682537, 2690025874, 2188574617, 2441108100, 2559076963, 2709019782, 889157462, 2631364932, +1029410265, 1958851729, 4284805509, 4032464061, 2157751368, 4067462204, 2224005264, 2590870527, +2255506252, 2658831402, 3160982437, 3928482792, 2580268383, 3910855424, 1502639214, 1910542141, +2035305196, 2395238655, 2458683556, 4284719568, 2472380715, 2789438298, 3714770040, 3060106944, +1940631798, 4294758179, 2794144985, 7898922, 3091393917, 1952353161, 1788309890, 1986099071, +3657380671, 1330925901, 2715000053, 2522407056, 4284639557, 1816622902, 2659876950, 1687521054, +1064927176, 2445703935, 1013208644, 1854349459, 730243217, 1939472252, 2271730002, 3148305841, +1268028616, 3674190750, 3868065733, 2974524051, 3140512631, 4117068704, 1045028196, 3188147096, +3187091715, 1048722458, 1044438150, 1054176875, 3165809453, 3201099181, 3204448470, 1029245143, +3198830178, 3196461227, 3199413977, 3186671000, 3196405201, 3195989811, 1032168884, 1059437825, +1032064060, 1050543985, 1033045084, 1056701195, 1057021569, 1049023561, 1036199045, 1038379015, +1050094320, 1026327563, 1036063437, 3163113125, 1023780035, 1033511828, 3175687190, 3173854553, +3155533713, 3186623314, 1026763278, 3185053318, 1016586273, 3156598046, 3186716290, 1015071120, +1032117674, 1010632425, 995393526, 1032727400, 3171784975, 3175161886, 3176936336, 3162690747, +3175884424, 3186668612, 3166612526, 3188911713, 3166352688, 1022843414, 3190716421, 1020060631, +1043397138, 1043277032, 3169150825, 3184199534, 3188658047, 3161732892, 3224820465, 1077243195, +3212841926, 1065232188, 3223698690, 1076215042, 1050053902, 1056150035, 1065353216, 1053982924, +1053893536, 1052571715, 1050996111, 1064827658, 1059327947, 1057437093, 1058087927, 1051309448, +1054016810, 1060982480, 1060336120, 1056412753, 1049942441, 1045522621, 1051729123, 1060893841, +1052106948, 1052374095, 1051699368, 1057145108, 1052824750, 1054738880, 1057208621, 1046937874, +1052166813, 1042975492, 1052038751, 1049580325, 1043272423, 1042386458, 1054021399, 1057488666, +1053645904, 1057966114, 1054508149, 1054269945, 1052664979, 1048829650, 1054180111, 1048936391, +1050118801, 1050361429, 1048982779, 1050736591, 1055970571, 1055366492, 1065353216, 1062200251, +1061996119, 1054153913, 1059679626, 1064120332, 1060719999, 1059607066, 1063592999, 1062352716, +1060229252, 1062884975, 1060888553, 1061430249, 1056226279, 1052193613, 1058046252, 1058997499, +1050249023, 1060413674, 1058204673, 1051033301, 1057141104, 1054293788, 1057284288, 1055062704, +1048709326, 1056291349, 1054148009, 1052797499, 1056215580, 1059007561, 1052396216, 1057944879, +1060178220, 1055240391, 1057003677, 1058050289, 1057005833, 1056070374, 1057090670, 1056737892, +1056259717, 1055930067, 1057841029, 1055901363, 2185139389, 3931556245, 3355410511, 2869792548, +1564195760, 4285773757, 2447024974, 3023127345, 2013303415, 3358560980, 2644250383, 1668710961, +896173772, 4084989871, 3504910709, 1865105519, 2153289902, 3646003631, 3439311194, 2284411716, +2836280564, 2992439183, 3200088697, 2100251292, 714702959, 2578931290, 2044198811, 2472110732, +1984813224, 4281380794, 2899002672, 1750364186, 2359784843, 4286103972, 2865141599, 2689033051, +1985576085, 4031366510, 3702348128, 2436256512, 2961099936, 4068008300, 3019869822, 4166012850, +2590475162, 2586283965, 2892786271, 1833335040, 1902883035, 3373778101, 4292812886, 1228430381, +1261673399, 3971462343, 2293497713, 3662825581, 858511272, 3312679753, 3640602412, 2420934451, +2905701519, 3011641279, 2371575363, 2558001290, 1899731813, 462057527, 2961842261, 1618149550, +583073937, 3231149831, 228672604, 2082615018, 1889473691, 2475456795, 2190984704, 1245388684, +1932812430, 428375164, 3432767345, 1786804480, 1342142112, 2999311834, 1901268670, 2125181728, +2423128256, 1133102433, 1772593535, 1281175386, 1820091587, 4105174974, 1059937114, 1130271674, +1694471595, 2962080427, 2976283247, 2543434258, 1400864611, 2223154429, 1317880681, 2214574369, +2316016512, 3209647576, 1364656384, 530145714, 1798147947, 457400160, 3650158439, 2376894780, +2988809393, 2205336423, 2587838880, 2926598655, 1189496797, 3136211592, 1362221747, 3379429252, +979187881, 1031981217, 2967606107, 915880192, 3147984513, 9670237, 3363075240, 1650856354, +2680198012, 2641136385, 2389480811, 3478666751, 553695817, 2404854403, 1993840526, 1143277550, +6392898, 2909554616, 1030167335, 2999496060, 1646558371, 2675086847, 1766722081, 1668985458, +1971875951, 2022342299, 2776975740, 8087074, 1398827161, 2816696035, 1336475488, 3175713402, +1905302940, 1642435144, 3032521921, 2392916198, 2140587881, 2594396292, 3044715676, 4284314988, +2345291384, 1636788048, 1939434751, 1704426400, 4278354843, 341733143, 4117994916, 1182534537, +9141384, 1805805211, 2729398289, 1203913841, 2758438535, 2473555130, 1821045676, 4287739308, +1698581618, 8062299, 3162030181, 2463055210, 2434174635, 1853976969, 2674851714, 2203343008, +1704237926, 2595291248, 1350395995, 2447146028, 2883552860, 3899544244, 1753848959, 2963789056, +1358932359, 2809773765, 2267852537, 3984846989, 2514849113, 420915774, 8665813, 3791924984, +2665977649, 1514622296, 1383596203, 2216920232, 4291417744, 844586345, 2218227288, 1483263653, +1101823378, 2954778668, 7362693, 2939231394, 4055135301, 608588363, 1834628095, 3358374101, +3505817066, 520129117, 225192598, 2622366699, 3290116210, 2040180148, 2856910626, 1001149330, +3350415187, 2886060599, 10312655, 2504870358, 2364722370, 1931124627, 363802829, 4280374907, +3367935650, 7249042, 1817063834, 3641742781, 2526640741, 1231166791, 7811729, 3994691279, +3953997703, 1183143495, 3295805659, 1670817719, 3320932462, 2550238726, 531256054, 3489675772, +1903837545, 2792004983, 12723560, 2607489394, 3593801879, 1417204862, 2350138273, 520116945, +2781051177, 1345619240, 591855791, 1549751954, 2944158021, 968012442, 2291161457, 2197857135, +2629337433, 1534787723, 3398010975, 2609616984, 2028352512, 2505596535, 2559341157, 2241818987, +1433684480, 2063341972, 2576448415, 2222369369, 1668072111, 2939944813, 1163653962, 1675180903, +1919845201, 3204678710, 326248191, 1906397482, 2240045664, 2281744461, 278466443, 2238054589, +2106169691, 1822469241, 2119547847, 2835316617, 1081653697, 2082938721, 1652982458, 2342387560, +2961419174, 1560505460, 2054963915, 1526767278, 1316108861, 1489202075, 2835321685, 2757053324, +1551571022, 4285575982, 1467978895, 1582980953, 1689262398, 1252186490, 1000660746, 2058158258, +2543255385, 2287769958, 646558594, 2708769327, 1654996515, 2456027017, 1853325368, 1809455002, +1155946191, 2391268470, 1874263861, 2689676141, 466072046, 3698284927, 1727045974, 4287452734, +1488635516, 2035817563, 2343455701, 4287390306, 2499785119, 1329558901, 1938318728, 2777910399, +4283795033, 1570739861, 3208539292, 1049476240, 3162457972, 1216769466, 4284051599, 1514832615, +2037735607, 2155085714, 1755171888, 1738766189, 2237958021, 2479514540, 4284670596, 916449903, +6913887, 3650587250, 1975681935, 3050009913, 1907031903, 2189716856, 2021872054, 3164461380, +5449085, 2710797184, 2630479680, 2697406846, 263553412, 3360386909, 1275030166, 3885188420, +2978522020, 1973436819, 4284129175, 2444096129, 3685383888, 1180264057, 2757635482, 2116199167, +2506277196, 1723400323, 3646247393, 2408167026, 1090525272, 2883097482, 2188285058, 1187792487, +2900545681, 1550136196, 3093590922, 4286493302, 1056153604, 1001549168, 1062694850, 1057516040, +1041245166, 1063371019, 3211055233, 1055962907, 1037251973, 1058933293, 1017202755, 1056835427, +1059807094, 3205382205, 1045599349, 1046408632, 3174869463, 1048653317, 1037535864, 3164243130, +1050675063, 3197932750, 1040403025, 1040955800, 3181355567, 3183361016, 1046113547, 1047307519, +1040009125, 3184983209, 3193502493, 3174935277, 1041709350, 1036380543, 1038281528, 3178777731, +1032180496, 3185234195, 1034383527, 3186841277, 3189985497, 1045659305, 1035779285, 1040336220, +1039922244, 1029709734, 3189561821, 1039303907, 1024061996, 1037737431, 1038674268, 3175945227, +3179969795, 1026686725, 3158328760, 3155054061, 3185486350, 1043259074, 1025912135, 1038520838, +1023397394, 1031830153, 3180720639, 1026383194, 3215045462, 1067479023, 3209036884, 1061451851, +3227832454, 1080348806, 1060194778, 1060556088, 1059718412, 1057400320, 1065353216, 1058908440, +1064123975, 1061332058, 1059719049, 1057735981, 1058713545, 1058725348, 1054062390, 1058805631, +1051838666, 1056109030, 1056923585, 1045663284, 1051564655, 1056369011, 1052860126, 1055489157, +1049678517, 1055885276, 1057976642, 1053688137, 1055094211, 1054341324, 1051045757, 1052175184, +1053054114, 1053476472, 1046330183, 1049231544, 1052630998, 1047275203, 1049643636, 1047733937, +1051006946, 1052891045, 1046290601, 1046999367, 1051817100, 1045203222, 1052581312, 1044836693, +1051690645, 1049185897, 1056235337, 1062687999, 1065283443, 1059412476, 1064137619, 1062714064, +1064443242, 1059757281, 1060380638, 1058137226, 1060633733, 1059591653, 1060360800, 1060844858, +1064839510, 1059067842, 1052953330, 1055694299, 1061367597, 1057689846, 1057610776, 1056935455, +1059449932, 1057096842, 1058734287, 1057919403, 1058566930, 1056895411, 1054031025, 1055635203, +1059498416, 1055120428, 1058125863, 1058415083, 1065353216, 1058958671, 1060599312, 1059567352, +1060109813, 1059674485, 1064268196, 1057902728, 1060117769, 1059548721, 1063637984, 1056179587, +1063982756, 1062527920, 3182442602, 3188783726, 1015758495, 3190092607, 3187471573, 1030337675, +1037744727, 1035000633, 1047231595, 3201066392, 1017605744, 3187895739, 1020857818, 3197313594, +1006812928, 3157641267, 1036383416, 3148236092, 1023535633, 3195985295, 3183623009, 1030641371, +1034082176, 1048277884, 1044235691, 3196071439, 1033674115, 3182874057, 3178962317, 3196287554, +1039388469, 1031549056, 1039353324, 1043510178, 3169516321, 1049316448, 3189745512, 1027724561, +3194869089, 3146862128, 1041875993, 3188346560, 3191400072, 3196364207, 3150698505, 1034500746, +3164782734, 3178537940, 3208553208, 3184783143, 3180749697, 1037341235, 3198596188, 3195072986, +3197034124, 1028223053, 1049402816, 3201309091, 3200706769, 3198333769, 3189405219, 1040941292, +1043035012, 3188968956, 3183456579, 3201105443, 3178867821, 3159786005, 3193105287, 1039092813, +999969797, 1034627963, 1050340450, 3202272580, 3178361657, 3194381017, 1023004467, 3196857070, +3172066299, 3182772425, 1043909883, 1031371008, 3180088832, 1052223731, 3192133000, 1038612653, +3189019415, 3171557162, 1030087726, 3181895261, 3200770313, 3200032133, 3173051037, 1002037207, +3181656336, 3181374962, 1040710749, 3200674136, 3180968132, 1042597898, 3190194882, 1054120192, +3189831654, 3164759293, 1046631971, 3204620009, 3180860760, 3196129037, 1022019704, 3194365798, +3186657763, 3179465161, 3209682447, 1053443529, 1018091088, 3182846249, 3186277312, 3197705892, +3185991381, 982627531, 1049066620, 3188984639, 3182351727, 3187612721, 3180936076, 1058225152, +1048703438, 1025888536, 1053403047, 1051802598, 3192493801, 1049401700, 3187411851, 1034902514, +3189017154, 3175176071, 1020734439, 1024098904, 3174190304, 3197447640, 3122300643, 1030129987, +1005190391, 3156533679, 3208187636, 3137583766, 3158750930, 3177913017, 3189201020, 3198962021, +1035949322, 1029340399, 1048483900, 3196232128, 3171597973, 3194519393, 3188778030, 1033268335, +1049411613, 1034211732, 3182230353, 3199142305, 3167686807, 3190776493, 3190846108, 1032994716, +1019539884, 1028661121, 1045842692, 3205574650, 3174890315, 3191820215, 3172464520, 3195546236, +1023377709, 3164168209, 1041683328, 3200173606, 3160030277, 1019559630, 3189933411, 1054454429, +3172085723, 1007804112, 1048658525, 3202761363, 991967532, 3188557786, 1033369092, 3195730122, +3185215278, 3168142617, 3198196297, 3181061401, 1036955297, 3169617267, 1040124345, 1045710131, +3193603027, 3192547111, 3186423407, 1039345342, 1040104799, 1035137377, 1044567373, 3172533279, +1043339847, 1033360829, 1053681261, 1051692527, 3192189008, 1049419989, 3187710377, 1035980352, +3188824607, 3175780427, 1018031387, 1025594459, 3177543926, 3197528254, 3148324375, 1030035630, +973531326, 3160105858, 1031936280, 3186712394, 3174293999, 1055228840, 3193659330, 1039887091, +3192757808, 1018349796, 1044522081, 3193885710, 3202133269, 3199541501, 1007411853, 3183413482, +3183209630, 3182242207, 3190629909, 3156766241, 3171087970, 1051396405, 3197442636, 3179009517, +3198779541, 1024609819, 1041671955, 3191846133, 3204476606, 3198788192, 3162582389, 1030916450, +3174491420, 3189356868, 3160138254, 1001264504, 3182630391, 3189285192, 1015495762, 3175718786, +3159127783, 3187305330, 3159803824, 3179601732, 3166411854, 1015250056, 1040338121, 3152543508, +3184214365, 3180519801, 1057038887, 1057448382, 1057074805, 1065932723, 1061535600, 1058982608, +1064637364, 1062871033, 1057069318, 1063966360, 1063053448, 1058452086, 3202895764, 1057068248, +1063761610, 1060457440, 3199239041, +}; + +uint32_t* get_knConfNetWeightsArr_addr(void) +{ + return (uint32_t *)(knConfNetWeightsArr); +} +uint32_t get_knConfNetWeightsArr_size(void) +{ + return sizeof(knConfNetWeightsArr) / sizeof(knConfNetWeightsArr[0]); +} +void get_knConfNetWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knMultiWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knMultiWeights.c new file mode 100644 index 000000000..32cbdfb67 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knMultiWeights.c @@ -0,0 +1,179 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION " " //ep3_1p960957_sha587415 +#define NET_SIZE 1269 +const uint32_t knMultiWeightsArr[] = { + 1043000169, 1003489461, 3203556548, 1037978647, 3202562628, 3184211800, 1027257975, 1033941631, + 1041876231, 1033497998, 1055704244, 1051900041, 1062166726, 1039604749, 1003602602, 3197306771, + 1050140138, 1031857020, 1057003161, 1057647298, 1059958344, 3204737100, 1051983089, 3201898501, + 1030777414, 3186487550, 3207680481, 1027271899, 3207158883, 1054395695, 1043777335, 1049560253, + 3170463760, 3192379678, 3154618630, 3193969733, 3188197269, 1051341308, 1004068613, 1009718307, + 3177920954, 1020952064, 1055575439, 1048754649, 1053952655, 3203348445, 1046499775, 3198919192, + 1045447337, 1043387650, 3180024562, 3181236357, 1032224772, 3199639544, 3197052369, 3191056953, + 3189990449, 1005405015, 3198433215, 3208204681, 3191164218, 1058954724, 3171072317, 1051756737, + 3190186591, 3181186408, 1015238568, 3197448399, 3197587375, 1057997814, 1042611521, 1055366218, + 1014318639, 1032466341, 1042159326, 1047187093, 1040039301, 3183994137, 1042691451, 3184893581, + 3164788197, 3192789828, 1027358272, 3146807498, 3195845868, 1045112706, 1041816464, 1044159315, + 1017234693, 3196739915, 1055584887, 1012800790, 1058332983, 3189992158, 3192325821, 3179399141, + 1032018321, 1049328871, 1055415586, 1058995111, 1058544142, 3197516881, 1050147019, 1018115355, + 3189097162, 1023171823, 3212746243, 1015977571, 3206425516, 3172660193, 3196458454, 3167788939, + 3188920359, 988068955, 3204138813, 1041183371, 3205198266, 1052188562, 3194924174, 1050324545, + 1050816311, 1060429474, 1065231479, 1066151798, 1067777081, 3207982575, 1061442265, 3204900754, + 1005445651, 1040796112, 3183624010, 3196116845, 3196189984, 1057454199, 1045040363, 1052556588, + 1034886154, 1045306583, 1027667792, 1029645803, 1043237759, 1034278297, 1032760934, 3172126394, + 1049382532, 1049616205, 1042608720, 3164450833, 1051523331, 3198433495, 3193087437, 1015233075, + 1036838536, 1049831594, 3205361544, 1040776858, 3207855834, 1048974733, 1048616042, 1048870711, + 1041765309, 1040322406, 3174433308, 3166421229, 1043310863, 3198266620, 3196019258, 3189281923, + 3164963137, 1054487990, 1038764499, 1051014610, 3163151651, 3167816145, 1048600613, 1028210053, + 1041445398, 1014090059, 1041334344, 1041552907, 1046512422, 3196176836, 1005808251, 3188665101, + 3181108938, 3177707246, 3192140567, 3202945276, 3186217800, 1055109391, 3187918892, 1016674590, + 1035399062, 1052714694, 1053698430, 1047866052, 1054224108, 3197655324, 1051822727, 3196569366, + 1047469631, 1034537912, 1037487120, 1037003306, 1028755771, 3196588466, 1046883441, 3181275112, + 1041427825, 1040531447, 1049487164, 1050907532, 1048395756, 3198576122, 1040974613, 3174735553, + 1043359284, 3174859086, 3194889675, 3189589663, 3206989776, 3177281110, 1049239364, 1054063128, + 1034396553, 1048443495, 1045094033, 1050672781, 1042826858, 3198493844, 1053586833, 3177869211, + 3180613476, 1051909013, 1026350511, 3180832839, 1043166615, 3189795108, 3188156215, 3189005527, + 3154328051, 1047462455, 3202010097, 1029166271, 3207221209, 1042537081, 1044966843, 1048502221, + 3171969303, 1054673228, 1054770692, 1058597149, 1056800603, 3192864870, 1047430741, 3188512005, + 1051087931, 1031063153, 1059554378, 1052857686, 1063816204, 3158589650, 1040342134, 3199572746, + 1045020362, 3178121012, 3205104686, 1049234268, 3208107475, 3203468422, 1031988940, 3171220295, + 1045690063, 1037984854, 1055560868, 1052481609, 1059637251, 3165825504, 1044130818, 3193436513, + 3183215095, 1037690836, 3208438900, 1040312660, 3206264833, 3196265205, 3177317356, 3187915983, + 1029158840, 3173532583, 3198316342, 3182373162, 3200688723, 1041111850, 3169476603, 1019543571, + 1052196691, 1041567592, 1060118185, 1051277733, 1060638818, 3210145033, 1057186995, 3201355357, + 1046179511, 1033049438, 1055643288, 1043829028, 1060956479, 1044155430, 3189899956, 3196833012, + 1040291355, 1040947095, 3198736715, 1053418120, 3205297834, 3199421736, 1044032738, 3192869857, + 1041202379, 1040720767, 3192590122, 3192558750, 1034887895, 3198596937, 3196394775, 3186442772, + 3182151975, 1051892263, 1034947800, 1034041870, 1030627346, 1046068508, 1034417485, 1039990265, + 3181168091, 1045186008, 1044001243, 1048950481, 1049472357, 3191644337, 1048205939, 3192925817, + 1036549381, 1024828122, 1027152967, 1029933203, 1026742536, 3188433806, 1041190904, 3197237341, + 1059816238, 1052170631, 1061303133, 1061767325, 1063931317, 3208086798, 1060645600, 3203123868, + 1042408793, 3164391589, 1041957257, 1054690289, 3151127067, 1052622317, 1045640577, 1046565224, + 1039262784, 1047815138, 1025967974, 3149547249, 1051358043, 1037239506, 3176418852, 1020928587, + 1030790770, 1030787009, 3178911892, 3195943913, 3187777009, 1054712721, 3162957539, 1045337987, + 3143527200, 1036512036, 1048344074, 1044054745, 1046311903, 3204491799, 1046124692, 1023165706, + 1039941713, 3192862799, 1034385289, 1028646294, 1031513321, 3196825451, 1032562118, 3184286301, + 3191052433, 1040010419, 3164004522, 3190984881, 3197770141, 1066543719, 1023638000, 1060829570, + 3147165373, 1048276338, 1049594679, 1042234322, 1040317401, 1024948457, 1048668365, 3178005648, + 1032284096, 3176627329, 3207892681, 3163537769, 3208263027, 3193641508, 3164762844, 1012594079, + 1013310818, 1032347081, 1057259770, 1057773931, 1062351683, 1049655892, 1040731028, 3197632880, + 3173653019, 1052945840, 3186699048, 1016997370, 3196184440, 3202714168, 1042321251, 3193300598, + 3175023464, 1056134339, 1054712529, 1036321310, 1055302741, 3186341880, 3173900933, 3184305214, + 3172269813, 1034455713, 1048835342, 1033431303, 1059236189, 3186369436, 3192258800, 3195495951, + 1038440163, 3176772252, 3201325407, 1041727399, 3201560244, 3174976055, 1009573844, 1026788809, + 1000339335, 1042284962, 3197622804, 3181180761, 3206544438, 1045480200, 1044808812, 1041230273, + 3185989945, 1050582949, 1049783601, 1052685741, 1056424986, 3187353939, 1029194551, 3188686500, + 1035720595, 1049603588, 1053161518, 1052698308, 1059621964, 1033167184, 3168998543, 3164824396, + 3174394752, 1044417334, 3208572758, 1049230686, 3206824051, 1025488192, 3172110667, 3185187924, + 1029403020, 1023439896, 1025154828, 3143621215, 3189118290, 1057109037, 1052953268, 1052672020, + 1047634431, 1028724697, 1041560269, 1036887887, 1041909077, 3188315588, 1042614157, 1016498550, + 3191968066, 1040650947, 979550852, 1047626407, 1030433898, 1032194269, 1047195979, 1049514323, + 1033333292, 1051205027, 1040786610, 1036392030, 1038167175, 1043855391, 1045109358, 1056178311, + 3179782268, 1043328556, 1053670006, 3168206323, 1044451678, 1052274851, 1055104908, 1033422650, + 1048691788, 1034720844, 3190082611, 1052352734, 1042029766, 1035934677, 1044794001, 1043494777, + 1063921913, 1061804433, 1066274629, 1056849883, 1043549742, 3210715942, 3190071953, 3192665740, + 1050954128, 1062288667, 1062815960, 1062357171, 1054180237, 1056329654, 1046951294, 3194010305, + 3188081603, 1045760270, 3199608680, 3197065716, 1057609980, 1058749179, 3162866282, 3212931176, + 1055249297, 1054086214, 1052080438, 3184236709, 1035389871, 1055400134, 1027661996, 1051913301, + 1057848244, 3199349898, 3201160317, 3192344669, 1037220211, 1049492804, 1055699177, 1060921591, + 1059438088, 1044051573, 3189023794, 3181620780, 1025253951, 1017045446, 1049477942, 1044216484, + 3206705265, 1061107003, 1058512852, 3207606680, 1052685089, 1055410073, 3196521888, 3173231615, + 1052213889, 3207067397, 1059398640, 1061212879, 1031908764, 1049368976, 1051842120, 3186205965, + 3183016387, 1053160680, 1053279560, 3162736841, 3211478477, 3187261981, 3201068883, 3192696730, + 1026938053, 1040172730, 1055652853, 3197995727, 1043092976, 1055215738, 1065670847, 1063523461, + 1068169841, 3192683353, 1042193743, 3181565518, 3198112483, 1041365713, 1056242646, 1038210736, + 1060047542, 1060811195, 3204616334, 3154627334, 1058496519, 1050951945, 1052677289, 1057580840, + 3172486658, 1039765541, 1040342149, 3166530791, 3189899264, 1032983727, 1038002307, 1042957241, + 3188656418, 3152624417, 3185376351, 1049902551, 3168453919, 3182179918, 1044125305, 3187814455, + 3172768768, 1042772205, 1032762274, 1036746205, 3172265914, 1008476918, 3131375236, 1050915659, + 1008744620, 1040691653, 1039475782, 1024280570, 1041781963, 3177509311, 1043739362, 3164352644, + 1035955312, 3195943294, 3187016771, 1023005647, 3199769627, 1059549294, 1051599026, 1018405874, + 3202274094, 1060262724, 1057829418, 1064664868, 3191270880, 3193127272, 3210182220, 1064467828, + 3163170493, 1051039213, 3191015834, 1045087475, 1053088610, 3186824807, 3202164641, 1062879562, + 3196875834, 1015991607, 1046865312, 1057228489, 1033147807, 1060942193, 1051578163, 3201923372, + 3186184552, 1041143147, 1058737169, 1021900912, 1051882602, 1066890529, 3212077045, 3206196521, + 1047545249, 3196949426, 3201952902, 1021913396, 3188256574, 1024687711, 1048748530, 3205771691, + 3201325739, 3208159330, 1059476349, 3200714551, 3192545668, 1059040946, 1053308134, 3194773088, + 1058126660, 1051449829, 3165353478, 1041539043, 3169588800, 3174728122, 3208788784, 1054309789, + 3205429377, 3203427841, 3218101242, 3199825718, 3196091550, 3200738230, 1062735250, 3172390380, + 3184759116, 1047432026, 1052885883, 1054433379, 1054330907, 3208645468, 3179399153, 1041965309, + 1062132667, 1058935946, 3213753681, 1062723597, 1047506784, 1049365607, 3191005844, 1044686486, + 1053300025, 3208986473, 3198345736, 1045767690, 1053621898, 1020900202, 1062349365, 3184886093, + 1067074266, 3193967941, 1048236976, 1055902258, 3184999853, 1055140586, 3206752425, 1066531912, + 1031578827, 1039403997, 1033591111, 3199668440, 1049585291, 1010087030, 3196387535, 3172569169, + 3207749968, 3202123202, 1055742619, 3206421510, 1043395818, 1045560765, 3204813586, 3174599588, + 3191648088, 3196889873, 1065124996, 1051185645, 3182148773, 1043689821, 3201783983, 3169317391, + 3204793090, 1055533037, 1040704967, 1059595338, 3209061042, 1057857174, 1063516477, 1045874422, + 3199763463, 1058351603, 1052174940, 3201671775, 3160799321, 1053854368, 3194252243, 3199435615, + 1053596156, 1058534374, 3185848025, 1057755884, 1054812578, 1026463577, 1062193386, 3190231070, + 3192464786, 1058207510, 3206762427, 3180558782, 1044327879, 3210666358, 1062212308, 3190414647, + 1061638167, 3198996165, 1045756437, 1060542141, 3187457494, 1056005769, 3204183946, 1068868877, + 3182236342, 1057642759, 1028701599, 3198597677, 3189822298, 1041378314, 3186630506, 3184211749, + 3205934286, 3199340575, 1055091459, 3199478221, 1043589282, 1050020043, 3208720944, 3198347557, + 1040475638, 3180193761, 1056392185, 1047556728, 1040464187, 3178708530, 3194416098, 3186167573, + 3199764429, 1061767525, 1049508819, 3199822345, 1050761978, 3202380967, 1048423013, 3203941417, + 1042890663, 3173075190, 3188549307, 1051543014, 1031232875, 1059550131, 3198399640, 1057842086, + 3189047594, 3161018718, 1041578123, 3191529680, 3199434469, 3204706102, 1067000068, 1046105874, + 3199603324, 1058714795, 3179725955, 1049641286, 3204458804, 1056526646, 3159943836, 1035903365, + 1057902938, 1052501816, 1040821733, 1051947087, 3198050548, 1033812931, 3193353864, 1046162761, + 3208815609, 3201424865, 3195275136, 3189567844, 1025694885, 1062352193, 3183877297, 1050521438, + 1039709845, 1012653270, 3173156688, 3180418977, 3200018144, 3197622468, 1050722700, 1053512945, + 1019288341, 3171266719, 1042513731, 3207605472, 3197440210, 3147667973, 3189200021, 3198635798, + 1036964000, 3190204742, 1037307295, 1033190336, 1036332676, 1025084036, 1021192765, 1030915842, + 1040194619, 3188248351, 3198154744, 3180180114, 3199704554, 3162140458, 1029651309, 1038925927, + 3181787557, 1049063296, 1050192612, 1052879146, 1048153695, 3166952815, 1043792133, 3192848723, + 1044759122, 1028066456, 1042867655, 3187494595, 1047047120, 1049880747, 3181231227, 1050781803, + 1051119827, 1043822831, 1049046018, 1047111309, 1044681983, 1042226334, 1050648239, 1045598685, + 3177851508, 1027204284, 1043297513, 3172106822, 1055301043, 1051393775, 1008159369, 3164521917, + 1039824911, 1047187923, 1047285473, 1052458449, 1049605211, 3192944925, 1051553815, 3196313141, + 3185042726, 1055534164, 3190484912, 1018484877, 3189841920, 3205075232, 1044709206, 3197845920, + 3198204828, 1038037860, 1050748558, 3190191330, 1057381164, 1049822637, 3190173520, 1031031277, + 1022327203, 1043245708, 1045784048, 1043516145, 1052960952, 3176110738, 3181019431, 3194657965, + 1022008404, 1057661246, 3160805713, 1041777195, 3201571475, 1009068927, 1051207682, 3180063245, + 1048073740, 3175078927, 3189935005, 3169210088, 3192719808, 3197890838, 983412725, 1033985109, + 1011120663, 3198775001, 1048586022, 3193846351, 1058438582, 1061218164, 3188421488, 1045721939, + 3190920874, 1037853488, 3163692257, 3176477397, 3204524270, 1052659206, 1041875374, 1043781255, + 1040187743, 1051605692, 1045139088, 1052177642, 1036382346, 3197434262, 1047539199, 3196427176, + 1052455780, 1016487266, 1051917548, 1050109253, 1050201797, 3198165553, 1041928484, 3190196540, + 1056754196, 3197708447, 3181071723, 3189636751, 3197566516, 3191067508, 1035575869, 1055814464, + 1036972368, 3190204000, 1037326716, 1033252529, 1036374695, 1024999163, 1021272292, 1030876104, + 1036314791, 999930268, 3182807746, 1060737588, 1062596335, 1024377559, 3203258146, 3197988963, + 1044227665, 1049767227, 1039572699, 3163365650, 1045375536, 3205326313, 3208138950, 3171055664, + 1066850400, 1053959903, 3204564750, 3195028173, 3190676857, 1058285565, 1060132231, 3170014952, + 1004862446, 1028730575, 3193500325, 3210901694, 1058008593, 1058441232, 1048520187, 1043517108, + 1040337965, 1024949567, 1022740739, 3175408167, 1055466935, 1016021467, 1038627060, 3180607939, + 3179250214, 3190563515, 3197024697, 3192776382, 3194783404, 3198085010, 3204534883, 3198768625, + 3188312402, 1049441242, 1056971877, 1059402906, 1050810636, 1049399428, 1049931095, 1042746845, + 3172509246, 3193925466, 3190729536, 3194263598, 1055386762, 3190222888, 3195107825, 3200289569, + 3199503347, 3193460214, 3201420184, 3202089320, 3195106943, 3196183300, 3197621843, 1029629695, + 3197770611, 3204510032, 1024051482, 1047359908, 1053819451, 3203707054, 3187419183, 1060965472, + 1054174153, 1056886411, 1056998775, 3196762875, 3189076532, 1043171195, 1049917658, 1043711750, + 3210007438, 3205286690, 1050880739, 1048662011, 1043697771, 1048443709, 1040987604, 1040251225, + 3140494461, 3204557446, 3202155174, 1059280506, 1060019825, 3213525597, 3212692650, 3189998064, + 1041444780, 1049373737, 1046614074, 3197826359, 1043452217, 3163555261, 3198892228, 3206222678, + 1065951269, 1062862038, 3180266539, 3196274777, 3195101172, 1045464922, 1055631865, 3192853179, + 3184610605, 3187516929, 1036469911, 1044244315, 1059123690, 3176065736, 3207367110, 1042906451, + 1049358560, 1057113659, 1060214134, 1060350818, 1041548061, 3168687050, 3148449862, 3189704501, + 3199779983, 3165097079, 3161941291, 3173485904, 1035348862, 1031343646, 3195929988, 1032321254, + 3180927275, 1045211130, 1050206878, 1053890535, 1059784215, 1049735381, 3193400199, 3213193357, + 3205997281, 3198154434, 1049929240, 1052953089, 1057249481, 1023410883, 1035540007, 3177987979, + 3188780147, 3196492340, 3191981236, 3188041167, 1034329805, 3164710949, 3192768836, 1049300799, + 3192710118, 3201340727, 3210457565, 3196116140, 1058634862, 1027192091, 1040920900, 1048504782, + 3188203310, 1039961360, 1061216712, 1018174442, 3180304105, 3187722327, 1051539668, 1051348072, + 3188573692, 3203419861, 3197116783, 3201766333, 3195447989, 3177900690, 3200206214, 3202728528, + 1040462502, 1057243216, 1061968861, 1060250938, 3222740859, +}; + +uint32_t* get_knMultiWeightsArr_addr(void) +{ + return (uint32_t *)(knMultiWeightsArr); +} +uint32_t get_knMultiWeightsArr_size(void) +{ + return sizeof(knMultiWeightsArr) / sizeof(knMultiWeightsArr[0]); +} +void get_knMultiWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSceneNetWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSceneNetWeights.c new file mode 100644 index 000000000..6e97d6114 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSceneNetWeights.c @@ -0,0 +1,346 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION "9b33ee" +#define NET_SIZE 2599 +const uint32_t knSceneNetWeightsArr[] = { +0, 1065349120, 3926200329, 271596243, 893109729, 1959652631, 2162769258, 3822046397, +236325760, 217054214, 285871367, 535286017, 2363630463, 4260621249, 4042855962, 3590266376, +4196007928, 3821726131, 4244310912, 3909485045, 4010540281, 34939405, 303701794, 556874507, +1686105086, 703733573, 118495524, 4211871509, 150967560, 25206003, 4170775579, 3438870013, +981428020, 3520003022, 3723368670, 4177326813, 351660759, 36755961, 2141561859, 2566803518, +3641374538, 4244655746, 4025156116, 3695148820, 290513053, 652654782, 4041270024, 4157409827, +3775474437, 371454453, 2162424298, 1984423127, 4176935415, 3943111412, 166324709, 3508797426, +2136947756, 347407092, 2967856968, 3925473270, 305463468, 2133369086, 640089819, 1497450496, +2848279633, 93357440, 170411041, 4109503233, 3857115900, 3824311334, 795815389, 2160206660, +885894575, 3994828159, 776864476, 1343942655, 652671791, 254281978, 3987047931, 1264681183, +286006582, 252709117, 80542740, 3164897335, 3554928075, 3122727358, 637708473, 4227395582, +1494532330, 503807869, 374232129, 522130958, 1920957544, 1399873898, 114354990, 967766277, +38561894, 368770782, 3842040095, 4237766674, 2149256419, 453369849, 235925226, 49808890, +3875066854, 905112291, 1551794002, 4149763681, 15186560, 3820884224, 3103262971, 3941332201, +3993896193, 3350495233, 3856568017, 436662512, 234683166, 757088384, 4283412057, 1857699600, +2370968599, 1228484192, 3742971980, 4262733440, 135649261, 601421817, 4177661214, 4278387449, +3825090068, 552803051, 377452376, 873464577, 690678210, 3740861218, 2759856384, 784979596, +688120594, 1313492, 34335485, 99149302, 2161570064, 2515271384, 1853845874, 4277998642, +4246011642, 370080517, 586943755, 4127064830, 1466990338, 119418947, 4161338108, 4277005550, +3806724121, 524123949, 3944625687, 1848171477, 502466356, 3757239739, 3992191360, 775038468, +451737362, 436600590, 3208968272, 1061383775, 1060350458, 1060899932, 1050734041, 1063381109, +1065353216, 1058850046, 1051238313, 1055825603, 1055593230, 1056564540, 1052908325, 1052508809, +1049578968, 1054728404, 1057456913, 1052613031, 1056251806, 1056584816, 1050558972, 1062042073, +1051740326, 1052512807, 1058344650, 1052135343, 1055555467, 1059985087, 1057169430, 1052523481, +1052639302, 1061233682, 1047055879, 1059213027, 4139482269, 104289657, 72634680, 122609534, +4206395649, 159323114, 43699355, 24615339, 2790, 19423441, 4868590, 39329177, +4289108070, 4266086130, 4213908736, 6373274, 112796662, 4136860831, 4026531840, 48698899, +12122929, 55535503, 145643881, 4282652922, 4165090304, 4185185171, 72738430, 142774152, +54879746, 40858001, 4209613012, 54406490, 3220132772, 1072649124, 3219638433, 1081092436, +3900696058, 4113894660, 4142336218, 4073847258, 3978690565, 3523503089, 3807181928, 3775530804, +3212436647, 1064825054, 1065353216, 268435456, 3220856720, 1073373072, 0, 1075623127, +11536767, 3201189669, 1053600407, 1065353216, 4026531840, 3133131475, 985647827, 0, +1064654253, 2155839616, 2139127679, 2139062400, 2155839615, 2155905151, 2155839360, 2139062144, +2155839615, 3205851304, 1058291159, 1044407605, 1062255870, 1062390296, 1065353216, 1046238359, +1034465492, 1058215057, 997977198, 1039131768, 1050105844, 1029513093, 1013773906, 1044441203, +1007908270, 1061061812, 1043175514, 1017547956, 1044356153, 1046475461, 1055269563, 1019129815, +1056292717, 1033124668, 1062798997, 1051378258, 1032073208, 1039482053, 1007979873, 1062074609, +1034695600, 1015646444, 1058979685, 4130629254, 121916297, 4186073219, 149289773, 4201430000, +159531206, 14521749, 26595246, 29803902, 18839528, 24003349, 57898698, 3499341, +4269420547, 4268244981, 14924042, 100286511, 4122359242, 4026531840, 65624229, 21062071, +25067040, 150081220, 1088546, 4155818987, 4186160077, 68368648, 162216574, 4288546393, +40641207, 4208220973, 89665237, 3219435697, 1071952049, 3197698072, 1043705884, 0, +1080937165, 3640125752, 82041384, 472472959, 3894550827, 254093037, 283439151, 3418956856, +842351122, 2290062592, 3630131705, 587265500, 4166508304, 2616985685, 234450682, 50857254, +3223257677, 3216141893, 1068566888, 1065353216, 1059163084, 4122183622, 268435456, 3221868582, +1074384934, 0, 1090308138, 1823917183, 33009, 3201873293, 1054278690, 1058215454, +1065353216, 4086410951, 268435456, 3186394059, 1038910411, 0, 1069994553, 2163925631, +2407497659, 260079851, 1887403783, 2137081215, 2290057096, 2146337019, 327188375, 1216392320, +4152328222, 2133813376, 2143761536, 4068442109, 343899905, 3816783769, 2136367232, 3210594173, +1062996974, 1053298608, 1058156659, 1062985811, 1054604773, 1042726467, 1057376177, 1064693973, +1035562494, 1055107918, 1050023954, 1051486657, 1045036181, 1041503635, 1042741420, 1057864321, +1035953806, 1064115284, 1056309336, 1057588575, 1059381049, 1024013916, 1059866324, 1057230434, +1056093160, 1065353216, 1065217528, 1063056335, 1053646672, 1060855847, 1056557995, 1057174874, +1054640335, 4201650179, 4208218040, 4234717013, 4172660312, 4211220051, 4291327785, 4240571766, +4281550379, 4271273264, 4174951056, 4234839065, 4167081178, 4240296353, 4240329657, 66247014, +4270293694, 185240523, 4026531840, 167683661, 52278866, 4235629254, 4222033675, 4275099245, +4273205509, 528351, 4081088051, 9055641, 4138375245, 4216661442, 49460817, 3835709, +4129544859, 3213891771, 1066408123, 3206456441, 1057673193, 0, 1080477911, 3193762056, +1052035240, 1057038960, 3206883980, 3200718388, 1049260074, 1049472475, 1050915039, 1041474103, +3186637535, 3177184080, 1035231329, 1060320190, 1055541229, 3190520360, 3193230284, 3180087899, +1033293642, 3189003489, 3182305270, 3201325312, 3197611744, 1043351497, 1049522104, 3204078670, +1051853017, 1060596204, 1049446884, 3162007935, 3169657008, 1055445747, 1059265380, 1048910301, +3188666770, 3196921482, 3185251399, 1058547271, 1059907763, 3199410239, 1042115279, 1036645656, +3196646407, 3192873401, 3182641446, 3186024769, 1051165744, 1041562457, 3206606506, 3185661845, +3196116679, 1058380672, 3196021721, 3182151695, 1057750281, 1052117802, 1036154103, 3198629990, +3204392118, 3196887638, 1053919456, 1047833505, 1057854055, 3177282041, 3161141927, 1034908367, +1027755325, 3191696276, 1042398012, 1035754394, 3190897109, 3194966138, 3208023821, 3184053726, +3203824414, 1032187977, 1022617214, 3196251889, 3188569111, 1045931849, 1039659808, 1053350030, +1057071821, 1051203557, 1057183207, 978348088, 3151324892, 3138814303, 986760012, 1003679182, +1003397563, 3147464069, 1003348039, 3146117646, 3154135754, 3147856013, 3147295877, 986788802, +3151610900, 1004868226, 1003765711, 3151217048, 3143126611, 3147069815, 981136455, 997407590, +3151823870, 3151198848, 3147830093, 1046730773, 3209499113, 3181439701, 1047018404, 3183461506, +3184891897, 1026317389, 3187601080, 1038785957, 1048297315, 1051820382, 1058875924, 3191900030, +1038669750, 1051278810, 1042650709, 3185016587, 3190599635, 1019633566, 1051896632, 1054087596, +1042920951, 3203888311, 3206465936, 1048825564, 3188655612, 1048719438, 1065496435, 1058598489, +1048603888, 1057861852, 1055163878, 1058200437, 1063480031, 1064657573, 1067571282, 1040612424, +1040725612, 1044714952, 3172720018, 1055480253, 1029499101, 1018005318, 3151707530, 3153936805, +1034304917, 1001777315, 1057130111, 1059737890, 3186285890, 1055588217, 3203612261, 1063387888, +3124541447, 1055611647, 980392344, 3123646101, 1056318322, 1063258343, 1050287396, 1057104523, +1064348045, 1015855877, 1065380435, 1048909409, 1061839389, 3208167594, 990586583, 986349303, +3212876072, 3206244558, 3173365992, 1065437624, 3201079404, 1049835726, 3210027118, 1054392542, +3183157964, 1049561696, 3117656923, 1005747000, 3204822910, 1061974952, 3187451682, 3192959614, +3208055046, 3151897313, 3174657038, 1040711573, 3181039234, 1047307291, 3114027453, 1003533418, +1048808393, 1067255342, 3172044511, 3196403559, 1048100328, 1047051296, 1064612443, 3199449796, +1064952264, 3208940569, 990991235, 998653716, 3218107707, 1004847290, 3171054413, 1058458727, +1049473782, 3160558069, 1022400592, 1050450981, 1057957819, 3204083191, 1006818287, 3134197492, +3213972702, 1048270098, 3196271230, 3171982955, 1052179212, 3191018603, 1052055348, 1055988046, +1036621335, 3189778935, 3149006121, 3138937285, 1061555974, 3191505101, 3185637949, 1034976472, +3153017793, 1039708570, 1058696508, 1030726472, 1063525715, 3192095385, 3134879948, 986998539, +3196066979, 1065730722, 3195341975, 1055832128, 3183093224, 984634970, 1054709800, 1005016066, +1061864950, 3148050344, 3123498296, 3100640208, 3177925053, 1061672343, 3190228401, 3201078116, +1044350414, 3194574339, 1064802265, 3209634962, 1043290102, 1047474642, 3105515494, 1003485247, +1050427236, 1059084900, 1021202062, 1040861888, 1065370943, 3182776250, 1053077736, 1057107345, +1049459178, 1045847723, 3147083069, 999608428, 1061414610, 3180956450, 1046150032, 1065345593, +3206440522, 1063213502, 3201922934, 1034878552, 1038774341, 1041471781, 3147869726, 3118500098, +3204139110, 1072545296, 1048384262, 1055909558, 1045350499, 1018927576, 3168184396, 1042841437, +1040024651, 1044008357, 1027050936, 1025884195, 1014048514, 1049628585, 1044361590, 1056543557, +1027097340, 3165134239, 1055818175, 1057414891, 3185561769, 3177220180, 3166707486, 1060501832, +1059838769, 1041345096, 1013306091, 1058466425, 1067473452, 1060226715, 1059087715, 1044545711, +1059365239, 1030973306, 1041409242, 1048802221, 3188220262, 1034477636, 3186218960, 3158631413, +1058632326, 3201114249, 1059571001, 3189336476, 1058793270, 1051772803, 1059069198, 1036683285, +3193666043, 1043493895, 3146758934, 1032342850, 3197578869, 1049112010, 1058315808, 3199909370, +1038593924, 3204423883, 3178497059, 1036007367, 3186575426, 3174781718, 3182677299, 1036419675, +1020975393, 1041969806, 1032173348, 3171598733, 3176200028, 1058336747, 1034667566, 1053095756, +1034914079, 3205510705, 3187957850, 1050590055, 3186313081, 1018965418, 1038720930, 3200433739, +1036570165, 1038324677, 1031984839, 1003309628, 1049605530, 3150675880, 3180119548, 3193773744, +1025934407, 3192023144, 3202511043, 1044672851, 3201727092, 1042443648, 3198589850, 3203958364, +3173546221, 1045071294, 1034138694, 1049399475, 1026221554, 1052735232, 974507978, 1042525457, +3181598342, 1042692065, 3188890100, 3166659978, 1038568888, 1034578246, 1027827153, 1042991838, +1060715052, 1051456168, 3182356625, 1062882072, 3165597115, 3167212718, 3171212126, 994603850, +1041902573, 3170180980, 1053666778, 3178180942, 1027727794, 3183422734, 1038511911, 3180331248, +3167338893, 994524845, 1019271555, 3165981015, 3182389366, 3162106233, 1040015834, 3160383592, +3149965619, 1040579986, 1040654761, 1040090413, 3185293357, 1034789368, 1035295009, 3171833175, +1050929290, 1053266663, 1029843648, 1050210969, 1052053661, 1019128387, 3183578218, 3162737603, +1034403399, 1022701910, 1034989209, 3125223823, 3194467852, 1035899609, 3197615660, 1043223576, +1007230301, 1023834645, 3184633633, 3129617837, 1039606952, 1040596021, 1044921563, 1010972243, +3162653046, 3189304774, 1001054397, 3195119334, 3193846610, 1053937561, 1052564034, 1045536226, +1039277866, 1044891805, 1047965117, 1043767260, 3182514829, 3156152014, 3177664571, 3202090290, +1052031488, 3184915907, 1044644936, 1034778168, 1036062644, 1034563129, 3188321762, 3208177852, +1042297524, 3190783218, 1046354119, 1043273085, 3187329171, 3195601569, 1051703003, 3179132866, +3181445452, 1057137525, 1056645143, 1013291686, 1011731936, 1037758547, 1016724466, 3192636262, +3195874100, 3177281845, 1034856059, 3180974890, 3183733431, 1033630592, 3189354179, 3181172977, +3179865943, 1050677521, 1051324660, 3166019095, 1055271988, 3182832564, 1058015607, 1032456792, +1044494917, 3163359702, 1041189582, 1039811555, 3183384852, 1052164962, 3189552146, 1029922792, +1032954175, 1055314221, 3180189196, 3204995072, 3199395158, 3201231907, 3187326619, 3174313492, +1040092643, 3201892099, 1004056674, 1032396073, 1045438954, 1037693584, 1044776916, 3200489807, +3182742698, 3176918997, 1053839756, 3194990196, 3186577895, 3185175476, 1035516946, 1034020067, +3179245388, 3190729401, 1053372041, 3166248413, 3184873399, 3205161583, 1030604806, 3203257962, +1026119186, 3199801716, 1043223402, 1049939807, 1034352061, 3189822000, 3191709483, 3205951953, +1040695586, 3182850156, 1034548642, 1033720417, 3198055775, 3179320658, 1017002352, 3183252454, +3197157083, 3167397193, 3199464593, 1045248948, 3180011980, 3175485260, 3173693450, 3179988708, +1038587741, 1040520420, 1038837424, 3190930868, 1024360956, 3183511551, 3168865732, 1043018234, +3173564042, 1043516326, 1030297533, 3180659699, 1043845534, 1036827377, 3183116521, 1041026377, +3184915700, 3191278167, 1027293993, 1038737296, 1010442326, 3181948046, 1026413375, 1046045055, +1023884880, 1021834302, 3137564944, 3181058973, 992465940, 1027206753, 991827883, 1048410195, +3153705760, 1028892591, 3154895283, 1040219451, 3186337177, 3173992333, 3182050071, 1035994916, +1023484325, 1041586627, 1032539964, 3167968927, 2507162112, 1987414015, 68390, 327968, +3093511936, 4287260543, 1606588159, 1968321536, 2248135895, 4289041248, 4293649093, 4293778116, +14854840, 3976160650, 4292657314, 2608880895, 4287074683, 7828669, 4286543980, 2842781695, +15496561, 2489646977, 4291277963, 4286135603, 706347052, 3924563424, 1868128853, 2795765929, +2110908666, 2788161, 3152471546, 2057009, 947214198, 2410741856, 2113935515, 2816856693, +2204723811, 2576679079, 1643045, 3706270676, 2659677863, 1937309559, 828575579, 2617210230, +573050408, 3640605633, 438632473, 3858311126, 3602706342, 1426072145, 827843187, 2952795560, +490406958, 3422506927, 3802065043, 2785040480, 371267, 2722784946, 3329739892, 2348829871, +2170608895, 733497466, 2092089814, 1382940771, 1695106611, 3603487232, 3854126761, 1566768998, +559488855, 2801757065, 3447814144, 1603387035, 1052012994, 3171604797, 3220480289, 3221354371, +1062159638, 1047420760, 3187858153, 3180397868, 3181901424, 1056454364, 1071772170, 1073161560, +3198677542, 1046099020, 1066342673, 1040573042, 3212391292, 3189425433, 3196845566, 3189338090, +1051815170, 3162090187, 1057842004, 1061633777, 3212186278, 3190163969, 3197321229, 3188741726, +1054439788, 3189361685, 1058207340, 1065147656, 3219381270, 1071780958, 3215585547, 1068014889, +3238140499, 1090656851, 1049730333, 1048840762, 1062510304, 1065353216, 1049380099, 1028785876, +1049221814, 1050574477, 1042784940, 1053938700, 1063563698, 1065261090, 1042197651, 1044053214, +1060438640, 1047050098, 1015430629, 1049667200, 1027318338, 1025981113, 1024993142, 1031444394, +1058051469, 1019843295, 1058245642, 1062266110, 1047513794, 1058729185, 1062136232, 1055689820, +1065353216, 1057098510, 1054323491, 1054233139, 1060149357, 1061852431, 1053570167, 1050017474, +1055899039, 1055984305, 1059208998, 1052637098, 1050160720, 1052837715, 1053836826, 1055816301, +1058545772, 1056278486, 2458822350, 3350903936, 1838198228, 4025063291, 1687708266, 1231056248, +1874028432, 3618417271, 1149808567, 2544084326, 2291249569, 2090239901, 943817342, 725713284, +2744084541, 1938398611, 2188282248, 2947258524, 2290319048, 1836748683, 2139191164, 1428881453, +2694402851, 1365563272, 2662045826, 795116880, 2139260819, 1906095028, 2053924435, 1600812434, +2726476940, 2223340674, 1096115335, 1233808266, 1618436655, 2258671969, 2542636178, 1971355009, +2392946014, 1597192026, 1701533767, 2120570725, 1597984861, 2073135737, 1938258838, 2221823854, +1718184298, 1297035633, 1886815532, 1649082476, 1887469656, 2608945536, 2257946760, 2223470717, +2359003775, 1534750839, 2173921391, 1955561336, 1029395842, 1098986028, 2291823199, 2290512761, +2089452681, 2173731702, 1627416172, 1451394941, 1717918541, 1936350793, 1987871617, 1465677685, +1902674828, 2088665975, 2541712505, 2219730533, 1684152915, 2305190002, 1465879721, 1734441073, +1652727489, 1620608404, 2509662542, 1131125377, 2745605550, 2561906841, 1581879476, 6063771, +2290435858, 2206375326, 2088272004, 2391375470, 2572446300, 2054395310, 2189783932, 2977170011, +2979100547, 2308878258, 2357363609, 1887013790, 2710207084, 1938476436, 1367378840, 1950420540, +1834586947, 3464325513, 2727584410, 2226172340, 2140047754, 3063576725, 1836999074, 2625533777, +2359396503, 2158607540, 2104719508, 2894042768, 2005502366, 2424280200, 2844240809, 2173076668, +3318462854, 2090250683, 2491979669, 3401363866, 2509083527, 2844955555, 1754702742, 2813853660, +3739538091, 2814037417, 1599947389, 2226022552, 1988849036, 2508809041, 2476121481, 2221964677, +2072798564, 2273809013, 2405309313, 1165256283, 2307627620, 2189132693, 2392163714, 2778044303, +1342214263, 1400660066, 2289329239, 2141425499, 2492237691, 2054126219, 1834643098, 1953860228, +2104654710, 1479685705, 1064591451, 1904959851, 2356652370, 2421125535, 356005185, 2845992489, +1621068134, 3885524088, 2306091837, 1936759213, 2171666513, 2998177911, 3133001133, 2119980674, +2139386760, 2442898556, 2208345001, 1734435944, 2627965561, 3419855038, 2322432935, 2041358468, +1836016506, 2155310966, 3013178991, 1680427624, 2677446211, 2324208606, 2288628333, 1498711974, +2641915256, 1701940377, 1665670987, 24869290, 2273739633, 1785290338, 576153737, 1919844255, +1835011072, 1734907314, 1246842198, 1716347215, 1601862000, 2052268622, 1602123092, 2235836234, +2069382474, 2071760780, 1633246047, 2004647799, 1599754574, 1065443688, 2056033867, 1969095014, +2661861051, 538997395, 2053476925, 625840021, 1197623879, 926101089, 2322696304, 3534534307, +2525809585, 639375469, 1847141001, 2274521493, 2273354640, 2861274784, 1647081131, 1905418384, +2090568023, 1315352576, 3114638704, 3619470779, 2877919880, 2443877554, 1280078471, 2643195826, +976697678, 1346991913, 3921181325, 2455951542, 2121689988, 1704627590, 2425723781, 1321517674, +1453310901, 1653641345, 1218745232, 9418404, 1953588295, 2308220297, 1499299984, 2088727658, +1970305932, 2174202236, 2172020843, 2472171386, 2458211965, 1820103836, 2239592079, 2191633817, +2794553210, 1669760613, 1839695737, 1650994705, 1617528694, 2525525880, 1180980338, 1183289721, +1984959770, 930979978, 271474271, 1348078388, 1595892878, 1068947909, 3212388668, 1921869423, +1130721421, 1347305521, 2776336522, 2170707866, 2207158667, 3399109775, 2068007062, 1215797904, +1701807242, 2424736891, 2960622733, 2054652838, 3724083161, 1968128898, 2511109507, 2425654673, +1767810770, 1691348941, 3447730214, 745187466, 676820558, 1986789403, 2301457080, 511431879, +2992971341, 2073793132, 1483839628, 2490917696, 2610261118, 1900828535, 2172018532, 2675477662, +1686796880, 1665359471, 2251722615, 2339348390, 2846132093, 546340499, 2597831034, 2201116748, +2461033633, 1888328321, 2239846516, 1617733760, 2121816396, 2245445492, 1971233594, 1567921029, +4072642931, 2071705791, 3519860617, 2139793805, 2123273590, 2947986324, 1653698962, 3572213882, +1937023174, 1719060839, 3080747389, 1265142167, 2153466467, 2659879573, 2475853453, 3014721630, +2326634118, 2930072983, 1735147870, 2794286714, 1666415188, 1299617665, 1484544319, 2527964518, +3265830728, 2860172234, 4293504845, 2643433160, 2597122987, 1869580168, 2038395994, 2711463291, +1617071794, 2813239174, 2190904467, 1131079061, 2745669502, 1886486658, 2657643412, 2728825994, +2628820626, 3184488521, 2037421185, 2291704992, 2173593481, 2256440745, 1550757556, 1367693390, +1297773910, 2845078360, 4022992853, 2410199245, 2358868062, 1974063235, 1953810043, 2625996383, +2475983262, 3115297690, 2928979074, 1802538902, 2678296948, 4172128978, 2243268044, 2258347688, +1279364781, 961634658, 2222150947, 1588949553, 3266031531, 1449689770, 2592192149, 1786937469, +1887075972, 1584232555, 2106748288, 1298180984, 1229291627, 1820095567, 1379819415, 1836842947, +2155037543, 1919974782, 1970703728, 2020106347, 1495161452, 2139922322, 2070307692, 2137613180, +2220191061, 2408355204, 2356903578, 2494343834, 2574417281, 744983414, 2244994943, 1550492302, +2726788962, 2357160316, 2744289685, 2474674069, 2239529362, 1937790630, 1820942446, 2071354227, +3373198, 1735465793, 1868651919, 2191294580, 2508558486, 1802866828, 2375649404, 1920498810, +2290387582, 2458090632, 2257221004, 2795605637, 2189072766, 2172420753, 1583840135, 557663360, +2169652015, 2676587390, 2088986529, 1721993840, 2056159646, 1854109297, 2894427239, 9660320, +2038861689, 2037667476, 2339007121, 1268080513, 1970685795, 2190046604, 1719441035, 2541783680, +2473886580, 1534620573, 2121224752, 2070881678, 2055570820, 1837005686, 2122158470, 1937019024, +2507764830, 1904629890, 2054981287, 2168986487, 2256505721, 2407300741, 2156506787, 2039641970, +2742380901, 1158767488, 2423216999, 2373805716, 1433639050, 1733654297, 2574994768, 2444465759, +2190186395, 2711132274, 2140177280, 1836026246, 1837533543, 3519856006, 1784841344, 1818194806, +1550822527, 2290839678, 1702654354, 2390792332, 1903034409, 2222076474, 1717264775, 2391381165, +2374203790, 2792583280, 1149082056, 3903025284, 2205965684, 1802028191, 2273987675, 4287406741, +2160126953, 2541908872, 2020765053, 1988194446, 2189526409, 1937407377, 2407633535, 2311298674, +2575402123, 2324472210, 2292343433, 2088527739, 2273869195, 2471455819, 3181752679, 1908663005, +2458681220, 1619621245, 1737504376, 2105193567, 1162692446, 2414569854, 1063287084, 4608330, +1347387761, 1553191308, 2594416286, 2089713532, 1751549050, 2309532282, 2714730610, 2372424375, +2138084495, 2001226258, 2609088692, 1483507345, 1868576866, 2440856712, 2828105872, 439689876, +1926529362, 2460324742, 1431270792, 1818064740, 1197504219, 1953137760, 2675925103, 2577894521, +1922078504, 1582525573, 2323930490, 3314397090, 3537099706, 2123729548, 2475727727, 2812650900, +1738369131, 1802723411, 2039123070, 743210891, 1969907544, 1819239268, 2458349973, 2357956451, +2341577357, 1800929325, 2541780629, 2645939142, 2306242894, 3113585817, 2727309164, 2103013023, +2407102334, 1601079441, 1466302530, 2273141824, 1095068320, 2068197218, 2087466113, 1803061092, +2157224843, 1667462266, 809851536, 2861268839, 2374147491, 241872174, 2203938371, 2222754429, +2223533179, 2374403209, 1584365718, 2237031015, 2221753678, 2744230525, 2493224849, 2572900475, +1619366282, 2156561252, 1989246096, 3953422961, 2272098925, 2173219485, 2728551811, 4289971610, +2427249886, 2356444299, 2139058558, 2357098631, 1548715388, 2122215535, 2155643793, 2461645206, +2171832210, 2206770842, 1954708147, 2173271687, 2425263237, 2541055300, 3048781945, 1622076626, +2138414988, 2036035969, 2382390640, 1435080077, 481603583, 2612121272, 2744343061, 996216831, +8314699, 1448110479, 1450544639, 2149884067, 2181050792, 3352479461, 3785394809, 2693333119, +2496486296, 2516189393, 4252789861, 6706598, 3131702272, 580286851, 1696421120, 2897855870, +682455039, 1111162014, 1672131431, 3011028735, 4283193928, 3312236748, 4123361146, 4280573034, +846365291, 2812774656, 738209275, 4270226251, 2812463871, 3078190743, 4289551092, 2611226781, +2444666914, 2734637445, 3061892095, 3311898357, 1929389520, 3929651292, 2130680345, 800240275, +12878741, 2356844645, 3190366151, 3204174187, 3191011481, 1060928830, 1062032243, 1049047647, +1044322546, 3179781936, 1056550013, 1047798895, 1050718779, 1049051884, 1043992544, 3159620136, +3193945194, 1055487995, 1028097600, 3145675544, 3168356339, 3188391302, 985532152, 991170796, +1036282719, 3187907275, 3195919452, 1030221463, 3183420086, 3173589840, 1036092823, 996181551, +1034616249, 1049149419, 3220830099, 1073218468, 3213150519, 1065598885, 3226332854, 1078849206, +1057733678, 1061102989, 1065003354, 1065353216, 1056193979, 1063442844, 1057487778, 1057393255, +1055505424, 1062808293, 1058960307, 1056210298, 1053757602, 1058003966, 1059051349, 1059218570, +1058833513, 1060324942, 1051878275, 1057043693, 1048375301, 1053298180, 1053861365, 1062008396, +1064745834, 1061646938, 1059689037, 1063926229, 1064638365, 1049503310, 1065038245, 1059666744, +1057827589, 1053475213, 1056505369, 1054303085, 1058973148, 1053483743, 1059696819, 1061595619, +1057826583, 1062365621, 1059217533, 1059527205, 1057114162, 1057069608, 1058617537, 1065353216, +887209215, 3444629369, 9084847, 2589191288, 10913221, 2553269099, 8096928, 2403584369, +912033023, 2171795075, 92369630, 3141118720, 8646638, 2722811481, 11052464, 3609515393, +7375720, 2392758907, 16047498, 3093737075, 1375773577, 2594212147, 4287785609, 2458619056, +2660021328, 4283727937, 9334482, 1486786396, 1992456605, 2541446143, 1621850111, 1798860597, +2469765155, 1862300793, 2220635647, 846023995, 2952848247, 3184154178, 6974632, 776753753, +4287144300, 1621174006, 2676457828, 2342016256, 381499227, 4284250522, 2920440832, 1507774344, +3317279350, 1073724255, 2327297668, 536844153, 3687611792, 1124048486, 1859181421, 570409829, +2633917572, 536840615, 1953934403, 1890164736, 2377611413, 687843958, 3049692265, 1442815324, +3400050297, 3919642810, 2371978880, 268409283, 2751419018, 3129005165, 5479784, 2136832880, +2415885604, 1535939905, 4281575007, 2059775503, 1080244103, 1693026047, 1899691876, 1432672892, +2389671935, 2509335165, 2353659780, 1310365241, 2331990645, 2655415438, 4283095695, 3173625639, +2172292393, 2036677375, 1662802748, 464322385, 2253352827, 2885642402, 2341107331, 4286540634, +1068763616, 1067730203, 1063880779, 1069243601, 1065860993, 1060900256, 1069957279, 1069038927, +3195168814, 1044094210, 3172439723, 3194668214, 1053397182, 3192648212, 3154732296, 1041181218, +3172767696, 3161282903, 1030698840, 3175788050, 1045086942, 3162020767, 3139346954, 1032130943, +3175200976, 3181080400, 1044770518, 3193983710, 1044200105, 3173779270, 3171860950, 3175741806, +3221267438, 1073694028, 3221063149, 1073449697, 3234252641, 1086768993, 1057618170, 1064071000, +1062896705, 1065353216, 1061095083, 1060463329, 1057718463, 1060023667, 1056994293, 1051834080, +1049282472, 1056211677, 1054501069, 1052164575, 1051906779, 1052002716, 1044745490, 1043729691, +1033266056, 1043755183, 1044167931, 1048639168, 1040846581, 1036874921, 1057253687, 1061346117, +1059124227, 1057639245, 1057137350, 1065353216, 1058350448, 1058925239, 1049830378, 1053237344, +1047621264, 1052474039, 1050708596, 1056945912, 1055120302, 1050702037, 1057301740, 1047368166, +1047409228, 1045500642, 1052367381, 1050066520, 1051632232, 1052271691, 1051979388, 1059891473, +3197414305, 3205585635, 3155142669, 1053812688, 1059917835, 3206905995, 1028870766, 1050705079, +3194204358, 3205893456, 3193994920, 3176623806, 1052096052, 1032891260, 3195311586, 1039209713, +1043998357, 3194582756, 1026709822, 3189769637, 1036140544, 1055645189, 1052630179, 3194947048, +3207852902, 1057224393, 1049819140, 1061374605, 1063077435, 1043312415, 3190044736, 3212134193, +3208489681, 1064011670, 3198067153, 1070256219, 1060099430, 1051254333, 3154773168, 3189073103, +1061203409, 1058122407, 1027680248, 3199516337, 3169218626, 3198484466, 1008785198, 1051208731, +3199276615, 3206277265, 3191311361, 3159964284, 1049470075, 1049703679, 1066115900, 1043869792, +1047699558, 1054490916, 3188645546, 1046821902, 1050129027, 3209736510, 3212641801, 1033737270, +1050502833, 1061173445, 1042613255, 3199804038, 1052011337, 1062415236, 3157602435, 3187003461, +3214017963, 3185747618, 3209738839, 3144589141, 1031520449, 3188454975, 3192011861, 3197246046, +3211665492, 3179299129, 3195776846, 3201651526, 3204458594, 3171818070, 1040431032, 1042904625, +1067889708, 1046123540, 1045250562, 3192821524, 1041142678, 3183677522, 1044065472, 1057652801, +996235264, 3198590355, 3174050368, 1038577743, 1044426929, 1045438991, 1050252630, 3205039795, +1058613320, 1053072288, 3190541936, 1017565297, 3201528487, 3207993510, 3208465786, 1047910729, +3209037301, 3212630816, 3157979943, 1044378579, 3177770624, 3198433253, 1033808381, 3207231542, +1042123507, 1062746140, 3201678915, 1049357744, 3191828460, 3188269300, 3198546349, 3199256998, +3214004895, 1032328729, 3195503113, 3206636085, 3209687326, 3184752020, 1061469808, 3206215885, +1039407417, 3198160511, 1032803992, 3188893081, 1057342654, 3189249682, 3202737148, 1038729710, +3156678940, 3203504879, 3202102384, 1068925260, 1038184758, 3209728340, 3183210171, 3198081869, +1060420537, 1057480607, 1042102789, 3202442018, 1051346180, 1035828748, 3201507967, 3200701163, +3198226702, 1034361728, 1025227541, 1061722575, 1040385598, 3207829092, 1049593075, 3185075518, +1016670685, 1030826757, 1038359528, 976357283, 3175577336, 1052998856, 1029327036, 1042402558, +1032145437, 3176677987, 3180829792, 3171742894, 3199538855, 3185150199, 1024821157, 3176920177, +1035752371, 3190405582, 1040880561, 3233930067, 3208469087, 3220267760, 3204571435, 3226789573, +3222731018, 3213491152, 3231418840, 3222754743, 3225352381, 3220322280, 3224985736, 3211484253, +3223008667, 3210256105, 3208076663, 3220989209, 3229621526, 3229632256, 3214073651, 3229782556, +3229011897, 3239213664, 3205948683, 3233715292, 3232827061, 3196750697, 3233999911, 3231125681, +1078060503, 3234545130, 3236409052, 3211777626, 3233292869, 3228805834, 3231731137, 3234284960, +3236889000, 3230058136, 3232053837, 1052777042, 3231033461, 3216748795, 1073983101, 3210966371, +3225711830, 3230932593, 3232484890, 1064952370, 3219164616, 3231724564, 3224618581, 3232465456, +3219386194, 1062253091, 3230856846, 3225765610, 3230300667, 3236015494, 3216012069, 3230294083, +3232288153, 3233338124, 3229419730, 3234156353, 3219608058, 3230018867, 3229647020, 3219888809, +3232479553, 3216571560, 3230416338, 3230398717, 3236168394, 3206954087, 3229377796, 1049320168, +3235385074, 1074103904, 3238057385, 3211356830, 3235678342, 1056922334, 3233246934, 3232249843, +3236584557, 3229623455, 3236153244, 3208871678, 3238039613, 3237488094, 3232439487, 3233017408, +3221249102, 3238970903, 3235243394, 3242633199, 3201823237, 3231874565, 1026706913, 3242476938, +3228977949, 3220282064, 3237881276, 3217499471, 3223686667, 3229618674, 3230288171, 1077033414, +3196479941, 3238016124, 3229649111, 3223418074, 3233010338, 3227545673, 3236524096, 3237138929, +3241935407, 3234768942, 3234102478, 3226101036, 3239362354, 3222399867, 3227125893, 3236008834, +3225288469, 3215745622, 3231617447, 3226724178, 3234014501, 3236149892, 3232519420, 3234127689, +3232150348, 3234024963, 3235540406, 3238151307, 3231553718, 3232181697, 3239911153, 1075698749, +3246429198, 3239633625, 3233558452, 3210283873, 3244095632, 3225096481, 3220536850, 3238657929, +3234566074, 3231313286, 3235055625, 3204462008, 3238079123, 3216272271, 3234927099, 3234556219, +3237876030, 3222100092, 3227347945, 3221381088, 3231218622, 3241977856, 3237819374, 3231575739, +3212559748, 3237514336, 3217903397, 3233862277, 3208478765, 3220258988, 3204572194, 3226792494, +3222726227, 3213511500, 3231406489, 3222696437, 3225341927, 3220246646, 3224984379, 3211495868, +3223003847, 3210255075, 3207747543, 3220944181, 3229615506, 3229633228, 3213950844, 3229782551, +3223819742, 3241562237, 3232246113, 3234566261, 3234226527, 3226790660, 3234661209, 3223108197, +3229708843, 3204147618, 1074209593, 3236753320, 3239035502, 3222488513, 3230073223, 3236264112, +1080534471, 3220298795, 3232196115, 3232582338, 3227596057, 3247302919, 3217359652, 3219392904, +3218730871, 3227798085, 3224638173, 3225094795, 3224694615, 3247310830, 3217471642, +}; + +//scene_reg +uint32_t* get_knSceneNetWeightsArr_addr(void) +{ + return (uint32_t *)(knSceneNetWeightsArr); +} +uint32_t get_knSceneNetWeightsArr_size(void) +{ + return sizeof(knSceneNetWeightsArr) / sizeof(knSceneNetWeightsArr[0]); +} +void get_knSceneNetWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSceneSwitchWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSceneSwitchWeights.c new file mode 100644 index 000000000..94247ce52 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSceneSwitchWeights.c @@ -0,0 +1,764 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION " " +#define NET_SIZE 5951 +const uint32_t knSceneSwitchWeightsArr[] = { + 2, 6, 2929173119, 1838977409, 2206830696, 2103752849, 2457310537, 1515215977, + 2811811196, 2237056382, 1684371076, 2257486694, 1731950425, 2426440230, 1922012297, 2691137378, + 2116849796, 2320317042, 2315299217, 1133804943, 2789563011, 3129909130, 2291646890, 2421136241, + 1917667007, 1787194713, 2473625453, 2759940428, 1168285044, 1135565855, 2491136671, 2677432771, + 1600222125, 2908711109, 1753191550, 2308535659, 2304015303, 1858966595, 2626663869, 2536150678, + 2271393926, 2122270784, 2072672922, 2912643770, 2207750822, 2374206101, 2142413227, 1652777302, + 2403123067, 1750859876, 1250716845, 2389656433, 2956992829, 3451291010, 1227459686, 2846062271, + 1553077107, 1169005976, 1707538100, 1702293897, 2997659751, 2914751191, 3512102510, 3082592332, + 3047579197, 2102614633, 2610775895, 2438480755, 2743660658, 2358274730, 2721143349, 1837780053, + 9696970, 2270656948, 2940303176, 1418694317, 2674614625, 2843697799, 1820619400, 1784382077, + 1839299466, 1819182173, 2039189132, 2005432681, 1534824058, 1886486669, 2105055391, 1258321795, + 2943514991, 1951300720, 2071037531, 2055115645, 2290987398, 2121905297, 1501324447, 2156953237, + 2273996610, 2290653827, 2208609694, 2425532853, 2475719824, 2155894401, 1853373013, 2337497467, + 2272421009, 3359804338, 2624281202, 1817943168, 2974973149, 2528034751, 1467266153, 2457566128, + 2470275222, 2410068627, 1179751543, 1618763660, 1468494694, 2826015860, 2315281967, 3030429797, + 2830015388, 2573825175, 1990102879, 2474352276, 2306631019, 1635954835, 2624104292, 2934578310, + 2006760618, 609127264, 2339743671, 1148280981, 1803122244, 2784999553, 1565943933, 1766824090, + 2843704205, 2339758502, 2748485310, 1888973198, 2120696452, 1162177393, 2842654573, 2761192574, + 2712115357, 3208816482, 1786732764, 1051812727, 3090122108, 3038604643, 1739225717, 3025501260, + 1350456491, 1975614826, 372930669, 2258271481, 1500671608, 2527365243, 2307764816, 2930620603, + 3041802189, 2653853545, 1145020029, 2192272945, 541154990, 2070241896, 1982433684, 3243464851, + 946763520, 2678805562, 3045883789, 1333687096, 2007595915, 2711389598, 1531139496, 2912728459, + 2858667862, 1362828916, 1366854963, 2351409232, 2306179944, 2221586808, 2138858900, 2274721654, + 1266191722, 2141955476, 2170053059, 1788320861, 3163112504, 1245577363, 2288214873, 2004125561, + 2504690786, 2490341304, 278495397, 2489885790, 2844348498, 949059976, 2573567327, 2256042360, + 1335192746, 2423020656, 1936483621, 2361493876, 2475073967, 1942471800, 1586143536, 3142018850, + 3566846553, 1186178449, 2203276997, 2170330988, 1128677187, 2358486098, 1550158207, 1952730980, + 948990804, 2289013878, 1448315960, 1168286320, 2674570667, 2842976768, 1485336194, 2370867344, + 2391677567, 1568901719, 2440349039, 3452645286, 392664472, 2931002931, 1550846128, 661558870, + 1212751201, 3748116891, 2270196051, 2523095651, 1751891228, 1132484235, 2072018310, 2553417158, + 1721520810, 2358999076, 10572182, 3032451990, 3061164215, 2407291224, 965103502, 1735949573, + 2185469818, 1888469842, 2272686183, 2071613829, 1850619750, 2324140449, 3007807610, 1786738284, + 1667332900, 2596436630, 2523034994, 2073476244, 1216455786, 2165847946, 1028895098, 2407167352, + 1314945706, 1955089497, 2304015745, 2356700253, 1560286606, 1720363894, 2158065815, 1890802490, + 1233608539, 2493243073, 2221374897, 2005631101, 2222761339, 2777037470, 2717892476, 2557578149, + 3789783463, 1250520293, 2372555389, 2747370609, 1669221213, 2361956975, 2259897940, 2246042254, + 1804499063, 4047128143, 1199340374, 2358861929, 1900433261, 1786290541, 2458991971, 2440209803, + 2743454576, 1652926826, 2019778713, 3502998667, 1853122957, 2290212728, 1518738738, 2138670777, + 2852158332, 2274075070, 1918847372, 1439535972, 2964363412, 1804636589, 1558744992, 1975608158, + 2669173353, 2222636913, 1427677300, 1987343739, 2676190090, 2574549672, 2653183384, 1536062860, + 2088803748, 1180633396, 2038582891, 2424690604, 2758243275, 2607643482, 2089319556, 1854900359, + 2472701832, 1601081985, 2002235005, 2220721549, 2321789566, 1383829125, 2235341714, 2642715258, + 2345514927, 1654099391, 2962459996, 1687763031, 1901820250, 2020376930, 2346215054, 1187401483, + 1469413988, 2490789692, 2474273173, 2743955335, 2291432448, 1970830139, 1837083484, 2372882803, + 2342563467, 2645995373, 2525518540, 1804584337, 997421926, 2674675300, 1989384618, 2021305734, + 2541523841, 2428283242, 2073142941, 1756309294, 1066951283, 2069520696, 2372115811, 3128897111, + 1433645477, 2039980621, 2256565896, 2071611904, 814651272, 2874976134, 2591902094, 1601868453, + 2490820716, 2172614300, 2339937956, 2608429473, 1738439288, 2136701587, 4068242599, 1619088896, + 2322837587, 2488489099, 2141545309, 2844622770, 1401002098, 1468291130, 1835621482, 1599768193, + 2223218824, 2454801792, 2776984735, 2290651298, 2254331498, 1401002379, 2121304730, 2792449453, + 2122676335, 2206775421, 2779892969, 2826012559, 1696811145, 3835204515, 2071553424, 2540935569, + 3094847855, 2156951981, 1988610638, 2662177612, 1318896276, 2627765125, 1713137972, 1532657264, + 2141936010, 2475786123, 3214126122, 2074443962, 2926531248, 3300821641, 1135427945, 2711911545, + 2305127536, 1721528456, 2758344540, 2477033777, 2611259816, 1765704789, 3048701836, 2725813355, + 2342094500, 1904316055, 1636747653, 1754617463, 2544413612, 3036688223, 1871497903, 2628426880, + 1566207360, 1768463433, 2228366895, 2586124633, 2392405374, 2307408533, 2105376106, 1904566905, + 2201702534, 2306499397, 2844229973, 2356085109, 2188490919, 1755087241, 1956945278, 1049119448, + 2087018108, 2744098921, 2189852829, 2640937853, 1933414995, 1429778806, 1058977452, 1638320038, + 1921610088, 1900834410, 2793513869, 2390922113, 1207984991, 2103195722, 2405398108, 1986167965, + 2053989031, 2354201694, 1517784035, 1954110825, 2105691012, 2373885034, 2256965742, 1836153200, + 2157362798, 1701086829, 1264100444, 2557767776, 2140515438, 2674626707, 2320659075, 654860923, + 2826400633, 1620082281, 1785100169, 1367312264, 2221833324, 2013277063, 814709366, 2137684894, + 1922977352, 1837805161, 2257289870, 2053076920, 2004969090, 2205762685, 3373354636, 2323416255, + 410482607, 2177291424, 271548035, 4053735844, 3182136664, 2006419830, 4233117153, 2763427961, + 3578834903, 2514592341, 2739637036, 2068400012, 788556140, 2843767952, 2037624857, 2392946560, + 3415315388, 3722004362, 1958335131, 2946954675, 2085530001, 1403155834, 3125784902, 1646446159, + 2594022803, 2635162726, 2103619536, 2407932079, 2426200503, 2289273243, 3145026163, 442806623, + 2205395528, 527197888, 2357091153, 830234389, 2485927568, 1163766567, 2271579251, 1996516454, + 2088921749, 2020895615, 2708694597, 2189387403, 2189136512, 2068982190, 2944820626, 2155830912, + 4285626383, 2793108156, 815409957, 1353497483, 1268289936, 3431046443, 1707973281, 2944894780, + 2486200427, 2830395026, 2160628818, 2091354686, 1940565366, 1437296471, 274818939, 2474408510, + 985983158, 2256591226, 2442488785, 1818400633, 2156778201, 2487392105, 1554755226, 3165042038, + 2490749548, 2695976020, 2628229315, 3243543718, 1651289478, 1718702676, 2676672417, 2695798639, + 2695082124, 2530298792, 2177214368, 2019596408, 2979463030, 962546513, 2019325847, 1934453618, + 1917084239, 1529964869, 930901667, 2136571574, 1770671428, 2055175043, 2525011334, 1464556633, + 326396792, 2155924864, 2405586716, 2140115371, 1647297670, 2512911781, 1768377429, 1349225145, + 3348926321, 2055960918, 1586919744, 2609860757, 2302899553, 1837556355, 2183499328, 1733527375, + 1566991762, 2152678528, 4105796210, 1552390077, 2494923950, 2825874309, 714304391, 2290273023, + 1883476859, 3232470128, 2390203250, 2326504309, 2913560964, 3040132976, 2909629323, 1686661763, + 1392538271, 2459083118, 2473103993, 1535148709, 2231268508, 2322224726, 2087285328, 1085707919, + 2123005842, 1568778091, 1889428351, 1864195470, 1753656158, 1888450203, 1999782841, 1535631515, + 2103671193, 2438038873, 2221885765, 2039038855, 2743507293, 2440988557, 2386070620, 1550366848, + 1938586218, 2562302838, 2188612223, 2121311634, 1685230219, 2426887507, 1180914827, 2021035369, + 1000176953, 1971357825, 2357685901, 1409301652, 1650093895, 2290830435, 2155245711, 2118536556, + 1971004513, 2065858453, 2256555065, 2341039474, 2155714176, 4176781174, 2575414432, 2272880553, + 2509347227, 1869177195, 2221046887, 3214576792, 2408541837, 2725412981, 2305724758, 2086634363, + 2055841425, 4290232235, 1416008836, 2289529472, 1938190231, 2440592985, 2441766517, 2475987335, + 2221374849, 2257158273, 2254011813, 2275971681, 2777317236, 2323149942, 1907337936, 2123864688, + 1216778897, 3515395216, 2643307825, 3264070045, 3350355600, 1818733858, 1738256501, 2169739416, + 2877332877, 2088923797, 2857806461, 2450622636, 1902222950, 2238949251, 2638727554, 2962320025, + 2103605605, 2103902074, 1987666788, 2175198606, 1934978213, 2239519634, 2189324926, 270805370, + 2238333977, 2153678184, 3274671464, 2966259609, 1890743949, 1351204661, 1452771695, 2025881188, + 2576446241, 1939964065, 2072348470, 1903890317, 2290252338, 2291302230, 2544993715, 2156505233, + 2324643203, 2232638015, 3382022529, 1871511503, 2340646729, 1949988004, 2139705721, 2373156211, + 2288611221, 1537125730, 2946397285, 2287631726, 62622365, 1953266867, 2881379660, 1415365293, + 3079505314, 2149804512, 2490795153, 2459341442, 2657782605, 1773296300, 2726590567, 2186191028, + 2316730491, 1971024260, 2135061913, 1783266686, 1652915045, 2287574177, 1415372432, 2675535994, + 2256600954, 1868916565, 2678291592, 1371431024, 1399434143, 1303832716, 3211380921, 2407298118, + 1584886347, 2117828476, 1972789649, 2444928949, 1183148650, 3100153705, 2272169607, 1132974690, + 2457169070, 2547108531, 2289090977, 1937069195, 1754573664, 2742712914, 2225570459, 1990955377, + 2760817561, 2122776449, 2476442472, 1939116451, 3113838170, 2160820152, 2624421016, 1853850078, + 2056612435, 2220200629, 2559404210, 2022140546, 2021026170, 3179064526, 2826133099, 1683975602, + 2659287692, 2085183860, 2053795102, 1887730573, 2324786809, 2374661198, 1769884254, 2044651519, + 1687596462, 2139515000, 2156034688, 2039170467, 2204082554, 2993513862, 2473566324, 1903528339, + 1584803137, 2823333886, 2588779699, 1473225124, 2225112217, 2560403788, 1619149648, 1792193899, + 2587784703, 2893972592, 2224396147, 2866377543, 2911260258, 2172428186, 1621791873, 3263733129, + 2146604653, 2339975514, 2491437426, 2189053311, 3264968003, 3284167563, 1720358251, 1668654720, + 1870578566, 1521122694, 1737520270, 1820564713, 3527514761, 2326367124, 1397533812, 2088480908, + 2175778410, 2121497404, 2754982512, 1719810048, 2056027220, 2843697348, 2004365430, 1988928326, + 2188874357, 2209792995, 2675866002, 2995433177, 2071822981, 3283877707, 2510407125, 2137948505, + 2881005374, 2124920218, 3368983219, 2225646503, 2341832517, 2457172586, 2457916064, 1919671980, + 2256328063, 3355415160, 1520653527, 2438178401, 1901940516, 1160752523, 2693838965, 2022851950, + 1954642100, 2524151917, 2084212097, 1751106459, 2189335966, 2105490051, 2405741942, 2478013574, + 2019658120, 2155253880, 2040113261, 2258466816, 2862326259, 2321979988, 1741136190, 2222890922, + 2309535380, 2357299069, 1247575945, 1387692958, 1119054220, 2336912979, 1904388524, 1871090277, + 2370858880, 1634765999, 2358293387, 2217375863, 3028961942, 2877011832, 2255902841, 3434778781, + 3234047152, 2001579927, 2842686101, 2010308076, 2594139980, 1805539897, 2037742772, 1775526285, + 2181035467, 2883713433, 2592090453, 3262658840, 2509529259, 917779526, 1668905595, 1437635450, + 1970385758, 2139725192, 2219798496, 981447079, 1910814093, 2972753272, 2356050752, 2106443906, + 3449516411, 1701931387, 2259386755, 1467187090, 1854169716, 1426088092, 1938390873, 2725937289, + 2259122063, 2406702458, 3483523942, 2240307842, 1652185475, 2089907855, 2244107649, 2056153946, + 2408143209, 2138339233, 2124648328, 2121697147, 1451714952, 2107086279, 1886947939, 2037939321, + 2189482622, 2238876360, 2389601432, 2560661691, 2386199341, 2496691807, 1936691620, 2322828150, + 2022538644, 2141294210, 2197786527, 2429384842, 2357680530, 1903449681, 2424469449, 2428285590, + 2457693300, 3035881595, 2743701870, 2356509327, 1789430639, 2760813701, 2472640634, 2716968572, + 2911866273, 2339480181, 2753904211, 1200573826, 1669466980, 4104816296, 3829450374, 2474567533, + 2310627481, 3929361297, 2643308292, 2374078345, 1092972386, 1333625525, 4287460488, 2453317477, + 1318869148, 1687186352, 2423549504, 2473776287, 1735886968, 1805569422, 2239202409, 2261820538, + 1419104639, 2708629186, 2022022280, 1901775796, 3936464775, 2610082245, 1685165173, 1855671463, + 2363450972, 2292867121, 2793765283, 2221241502, 2074438024, 3017567875, 1938380421, 1302505320, + 2154935178, 2340977545, 2169530747, 2189435824, 1854368887, 2305459633, 1399859099, 1835943228, + 2066236308, 2388797302, 2928318589, 2189426558, 2648079754, 2221257635, 2091233407, 3312616084, + 2190050963, 1070887808, 3402222828, 1668251003, 2555992723, 1968613809, 2475540407, 2036821413, + 3833643332, 2692526956, 2540392858, 1701214051, 2425133954, 2808964472, 1566411846, 894993365, + 2474803019, 2164283465, 3483600234, 2842972037, 1955556493, 1796894343, 1889890635, 2745592477, + 3335611812, 540644488, 2444731289, 2744417334, 1537769809, 2342280333, 2017549672, 1935199436, + 2391115934, 4285823180, 2184922823, 2276820881, 2257166246, 1334345293, 1769847006, 2174136189, + 2492900767, 1903238228, 2050843791, 945793683, 1518430867, 2122237058, 2863636879, 2997731723, + 2710401390, 2474670986, 2122749900, 3992938639, 2369943330, 1983217008, 2874570398, 2256710700, + 1854452362, 2575998104, 1599103593, 1754380443, 2322755708, 1951559047, 1299753551, 1182950994, + 2036236433, 1332047798, 1349215586, 2152226195, 2934272331, 2710281886, 2172675456, 1700220210, + 1470264426, 194800987, 2677457347, 3294732615, 1077874768, 3062012325, 3326583433, 2485426772, + 2206157629, 2782693215, 1502675095, 3638920855, 1557537171, 2856888687, 2239973518, 1768320821, + 3079499620, 2427552344, 2826329195, 2844491408, 2252572940, 3179690850, 2157675171, 2306162807, + 2058983216, 1602406008, 2755877702, 2572064174, 2457299885, 1786673000, 3196285740, 2039396789, + 2002608541, 2310042707, 795224102, 2944959595, 1419311492, 1453696403, 2255328863, 2396149439, + 3679864392, 1586634169, 2154595511, 2309589363, 1115776930, 2372764110, 2020819968, 2660183898, + 2323340918, 2625113404, 2762098802, 513348468, 1636329638, 710208210, 2415853395, 1550674436, + 2771155351, 1363965503, 2576821608, 1332711806, 1519745685, 1307989054, 492222066, 3795219508, + 1834843326, 1940960424, 3212421242, 1784971181, 2306844279, 1399153806, 2356050860, 1489924414, + 1099070630, 2139420545, 3044561826, 2358734252, 1579916352, 2440333444, 680162428, 1687788686, + 2710820685, 1233815665, 1232252415, 2475128954, 1386587750, 1955030392, 2004818052, 1515692948, + 2575146413, 1952090040, 2340922727, 2491906662, 2539413905, 2084587175, 1820760223, 2149281189, + 2226153546, 2023652200, 2339749749, 3129765995, 2055705195, 1100109750, 1617734049, 2879222971, + 4135739728, 2801838633, 2007263669, 3155586924, 2431678327, 2259382107, 2543210092, 1302437761, + 1736219460, 2069658266, 2139526009, 1487251072, 2021826232, 2054063237, 1721598605, 1299541619, + 2189579661, 2223914838, 728847532, 2155429504, 1537107598, 1904252260, 2052886131, 3350619815, + 2924428894, 2358099802, 2638445406, 3228459917, 3911013, 2139321704, 2268104119, 2909759605, + 3313733955, 2040434822, 663907771, 1770155936, 2524036683, 1584938852, 2119329636, 1602266262, + 1754692488, 2126656637, 1383627884, 1686654737, 2172161919, 3616312752, 1703459956, 2571325324, + 3211767232, 1532912326, 1580489324, 4287076230, 2424544333, 381448280, 2476910698, 2627301500, + 1485779492, 1220322946, 1490429392, 816791163, 2624342634, 2674952519, 3550705461, 1948935820, + 2392356953, 1484277402, 2589045986, 1398899784, 3581638508, 2340020597, 1368153288, 2664075896, + 1009983297, 2644342659, 1464985039, 2376269173, 1784444219, 2571225442, 3422586409, 2392817262, + 2155527385, 2995088516, 2289934775, 1838760335, 2705225582, 2542049740, 2216071291, 1654110542, + 2052301438, 2206625092, 644637791, 2138203755, 1403547527, 1956337723, 2256205946, 2645519773, + 3147795548, 2254075785, 984268661, 2422720965, 2449439908, 1535870048, 3343681457, 1675247491, + 2136897885, 1523692905, 2139718284, 1718785884, 2309131920, 2359066221, 2005368974, 2847651686, + 2424535658, 2255590538, 1986689094, 1635669870, 2342087042, 2294066286, 1685298088, 2206050685, + 3311175060, 2307034833, 677625213, 2076808341, 3196086079, 1824959403, 2093537004, 3517291361, + 1344711038, 2521810136, 1516456342, 863544962, 1590987663, 3749859671, 1603654600, 1633122116, + 2151696553, 3364576933, 2474267041, 1215655267, 2844026696, 1869977764, 3047650272, 4288770983, + 2256442491, 412264870, 2271636141, 1939835214, 2960701061, 1350665190, 3419510196, 1144917892, + 2376497226, 2323729355, 2353026417, 1618386079, 1720085356, 2219745865, 1368614593, 2491988879, + 2311696113, 607077284, 2542112879, 2058017961, 2439337840, 2272225154, 1990173092, 730526719, + 2139467663, 2138859905, 2275570575, 2357498728, 1710132586, 679844234, 2460257626, 2871110035, + 3585892628, 2424536176, 3424628820, 1537567311, 2697543795, 2105566640, 1658488437, 2092613963, + 1537909145, 1902545347, 2946655712, 1449424803, 2205255324, 2371049359, 1903255393, 2253147791, + 1835222604, 1385125996, 2072969093, 2256042904, 1938852000, 2408480611, 175203439, 1599577701, + 2024510108, 1499099001, 1803917919, 2054913434, 2003187355, 1900041847, 2791415959, 9271191, + 1367360081, 2593300372, 1802597000, 1552314785, 1080919184, 1672051092, 1972203898, 2288537762, + 1900251806, 1166378388, 2725730636, 1804571029, 2449801373, 1150781321, 3553131637, 2444259721, + 56963042, 3576784537, 845635803, 1318812833, 2239263933, 3160969462, 1516615809, 1603625561, + 2256618061, 371767114, 1166711955, 2254795639, 2884854126, 1955623819, 2172803524, 2645971323, + 1953704848, 1805157761, 3165829788, 1804904576, 2322708342, 1727170995, 1888459875, 2485695140, + 2354635458, 1549486548, 2446966488, 1582995749, 1986960745, 2861465211, 2593217379, 2573308842, + 2172820842, 9796214, 845641398, 3268250554, 2170516112, 2152295043, 2359585126, 2277937542, + 2241960563, 560809801, 1898483639, 3181138819, 1853319779, 2223142780, 2678429011, 1940164265, + 2083538542, 1131131237, 2897859382, 1184610745, 3047130237, 1817737336, 1334468735, 1937334598, + 2728286632, 2458944168, 1437812584, 1518757744, 2123006847, 2087352956, 2374680575, 2021826955, + 2576976275, 1970296923, 3013037673, 2659216511, 2711056772, 2257294230, 2390294385, 3047373682, + 1267760239, 1653249434, 3501064103, 3970318483, 1104311728, 2194834343, 3569177174, 2040088955, + 2412672574, 3452145596, 664830584, 2464898939, 3982114132, 2006269670, 2304551526, 1713664377, + 4186482595, 2623772469, 1298315218, 1086165060, 2581239939, 2906678398, 1347781749, 2557443177, + 2122343060, 2308076659, 1734447748, 2893124744, 2004057930, 2374345341, 2222095231, 2172750983, + 2372702849, 2239791483, 1954452079, 2591524972, 2492229759, 2356965771, 1738569592, 2223340654, + 1855095296, 1921738112, 2156163420, 2188675418, 2340445312, 2157020049, 2172359038, 2391311481, + 2171937407, 2425048762, 2744868968, 1883860338, 2205190487, 2643156796, 2507576213, 2036968585, + 1752070800, 1467510860, 2063567704, 3032374595, 2525580137, 1326929081, 2571601489, 2155884918, + 2442042955, 3047845154, 1751589580, 2270334570, 2273548077, 932465278, 2160752553, 1919036507, + 2307298942, 2206185341, 2136167814, 2124574866, 1817672317, 3097006959, 3208087126, 1474411564, + 2372629145, 2505998971, 1593815124, 2321454668, 1716490880, 2540273062, 2995431278, 2792376481, + 2224655252, 2005627541, 2677583531, 1452050233, 1903591281, 1419482752, 2441123433, 2187496278, + 1702204821, 2122285194, 2089053060, 2942266506, 2324464002, 2578155916, 210534015, 3047250071, + 2324013724, 1634562726, 2343004030, 2457901416, 2459794348, 1752785021, 1854451327, 1371062167, + 2189472897, 3462106507, 2054261855, 1736992167, 2122080129, 2256037003, 2458426465, 2424598676, + 2223872210, 1687570800, 3062863238, 2239823738, 2728486551, 1737659249, 2258473320, 2724677025, + 1146478059, 2257697817, 3364907146, 1451408461, 3515249710, 2021314202, 616093367, 1937998716, + 67153011, 1619562914, 1487235388, 1941864056, 3347386767, 3566976201, 1887546995, 2124312936, + 441413763, 2170922389, 2390525512, 1450207147, 2089394819, 2684268185, 1180945290, 2910206753, + 2815471721, 1463590629, 1632660002, 2475998539, 2424470129, 2370412193, 2620105766, 2991954572, + 1452597878, 2789576100, 410622291, 2739752844, 2008071365, 1582235761, 2827835760, 2374806198, + 3314785728, 2156427185, 2089252470, 1967413871, 2172087337, 2289505657, 2471456388, 2344257893, + 2544238713, 261860960, 2772339609, 2726672435, 2457576820, 3077416074, 3326836585, 1943768456, + 188317592, 1872200290, 734697132, 3759329189, 1725059388, 1886295964, 1859802426, 2844511603, + 2375199341, 2441046388, 1014076293, 2628353650, 1972796781, 2440198605, 2238972283, 1853264784, + 2038533498, 2292023438, 1885967486, 2509597041, 2625997472, 2325247296, 2309454471, 2222945415, + 1856013175, 2172675216, 2290247781, 1566534785, 2291759220, 1770615444, 2288352119, 1919991471, + 1719107469, 2170392194, 1850564474, 2055364478, 2291168379, 1937539995, 2541714789, 2156330880, + 1752127356, 1854698619, 2056877718, 3965542266, 636038329, 3340544404, 3579867245, 1872331141, + 1754288769, 2109431681, 2541923490, 2476506009, 2053141597, 1184137641, 1503056206, 3029113231, + 2322112620, 2861009025, 1835634323, 1905958294, 1415865530, 2258146746, 2325248337, 2340577679, + 2256863098, 3511385434, 2493439416, 3175912551, 2965189218, 2171125985, 4290631911, 4058374418, + 1981779370, 2451067809, 2359934876, 748630103, 2308021568, 2791455928, 1586603736, 1666408558, + 2677371451, 2424648787, 2426226110, 2520804875, 2190376016, 1602056871, 2385940641, 3050145101, + 2710864041, 2439677294, 2126550382, 1583194518, 1771603320, 1564502135, 1239302840, 2267977262, + 2392147306, 2158928272, 2300022618, 2254808689, 3164180368, 1551206238, 4755881, 1927599477, + 1683967070, 2257027700, 1512263512, 3262796695, 1600739972, 2469551480, 2507252657, 1800510289, + 1688016711, 2036645210, 1921518479, 2638371227, 2240853388, 2310756709, 2524683684, 2005641577, + 2775386777, 4292635677, 1550277803, 3494657652, 1991872650, 1755821422, 2678136504, 1621586785, + 3476730279, 2051856160, 1985185717, 3367898144, 2087696270, 2337247622, 2372899175, 1451446167, + 2712953208, 1300204891, 2460117040, 2340068981, 2107282551, 2122809227, 1870362248, 2825878150, + 2223084177, 1718770306, 2559013502, 1954645368, 2022342012, 2257096317, 2106625670, 2156169831, + 2170777735, 2139133829, 2173141114, 2394005381, 2169993623, 2424272257, 2155118966, 2004853137, + 2189851013, 2175110791, 2189591414, 2525002610, 2206596989, 2208909220, 2023585169, 1670540177, + 4293432709, 2105108326, 2023538036, 2459019880, 1836941678, 2559803762, 2272166015, 2556257380, + 1788052348, 3870452824, 1432319389, 1941737847, 2068676473, 2226163761, 2442495331, 2610716013, + 1735630705, 1081435762, 2020640958, 2191898513, 2140040576, 2339750261, 1790019187, 1686474389, + 1946117765, 1971669086, 2187566453, 1534614731, 2408207491, 2138812293, 2791421296, 1868265312, + 2656339625, 2659417202, 2157224805, 1387941607, 2915607217, 2439545189, 2310054557, 1954260916, + 1970965390, 2054656648, 2155033462, 2139122822, 1603569582, 2859885920, 2105853059, 1690728031, + 2225173655, 1905695312, 2411938940, 2745570759, 4287734999, 2742379067, 2125606544, 2507898470, + 2243067506, 1647401858, 2644145263, 3122488456, 3308414416, 2170914215, 1918608508, 2413280890, + 2675671619, 2489286258, 2340378519, 1434867571, 2337954194, 2158201148, 1771991375, 2390075762, + 1030184851, 1819309083, 2857526420, 2343205758, 2741134591, 1739619957, 1349624467, 2827301854, + 1659073148, 2174058346, 3144509822, 1935502989, 1675543635, 746951594, 2212840148, 1992644261, + 3267598451, 1702512982, 1752469421, 2276941941, 1954784954, 1883128458, 1904241477, 2256427074, + 2039010952, 2186905670, 2809041757, 2706932861, 4095317098, 3183110058, 1503712588, 2841022516, + 2105505673, 1756546079, 2260020575, 2046849447, 1687368065, 477666890, 3460574647, 3764303686, + 2743971467, 1394255788, 2777776717, 1685829262, 1381266607, 1415659918, 2253092292, 3142875490, + 2726392190, 2240081276, 2373296267, 2041602472, 206666071, 595965309, 1407353089, 3356745896, + 1267298994, 1904110209, 2348857013, 1872716194, 3778354234, 2121948834, 1419084408, 2594252343, + 2440061006, 2073857391, 1396876160, 2254787029, 2410250640, 2103815087, 3416233361, 2107914669, + 943359136, 2356523662, 2123349633, 1366193063, 2605479274, 2897176767, 4131802226, 3019938480, + 1098574972, 2376250258, 3527699012, 1297256585, 1990819164, 507139428, 2591401071, 3882400101, + 1363652974, 1536731783, 2560212142, 3265429327, 1518554741, 1921028015, 1791727213, 3025502567, + 1953648288, 2845151349, 2309453711, 2022150280, 2344449660, 1786282619, 2132505018, 1636459147, + 2742196560, 1419217274, 2241701815, 1936957025, 1850697849, 2269487445, 1149531563, 1803719013, + 9482324, 1950375029, 1984065384, 1936104316, 2122493589, 2794150476, 2257286006, 2069671535, + 1517644874, 1953254537, 1501063804, 2206616905, 2122668162, 3101995343, 1920099519, 3211284291, + 2458304873, 2003594673, 4293836665, 1970902736, 2928174694, 2812512346, 2370530626, 794129811, + 1738041944, 2242807083, 1617832101, 2106029146, 2190762558, 220558951, 1720846940, 2476641592, + 2507559009, 360394122, 2202887296, 1112967283, 1284408751, 2323055734, 1191203977, 1955240363, + 2389868244, 1262442865, 2105158799, 2030903180, 2810299545, 1946625739, 1061632686, 3127944707, + 3298761609, 3080418767, 1412936960, 2629265800, 2343473730, 1472175701, 1230605056, 2239132784, + 2122401401, 2475648472, 1950912386, 3263212288, 2394263863, 1903217359, 1247303323, 1159363459, + 1699295090, 2435681381, 2667601426, 1088396933, 1161804624, 703674431, 2641635735, 3175040321, + 2742524276, 2526426222, 1431952929, 3764940161, 1496454938, 3731834879, 1870882168, 2934388264, + 2369625471, 1500401663, 3011939715, 3056503623, 2880585603, 1211071532, 1501466040, 3316541026, + 2138581704, 2461468273, 2142877582, 2510487386, 1633844583, 658878294, 1200394299, 1707234339, + 2912209295, 3162707828, 4288497139, 1785109843, 3329587363, 339781753, 2237214699, 3781642057, + 1014592256, 1098680484, 2624106367, 742339976, 2827129911, 1988857438, 2899089794, 2422171849, + 2573891744, 1116169052, 4282832728, 4288506684, 1285838456, 627289458, 3211895840, 3082178692, + 1889108647, 1903532940, 2443222114, 1785799232, 2543189865, 2824695164, 1954174689, 2489937028, + 3193662140, 1811117894, 1100119552, 2003490451, 3211220602, 2223219032, 1417636225, 2624166765, + 2106040742, 2217292962, 1876670975, 2771959511, 3047465151, 3352415964, 813334347, 4018543999, + 1144977837, 1068906639, 2360528851, 1795157602, 1535153533, 964314414, 2051496058, 2035378790, + 2236846221, 2590145074, 1318977603, 1675250046, 2556403790, 1902743090, 2013173345, 939575425, + 2441293386, 1581588171, 1561361029, 3770183846, 3193140353, 2073143174, 2239542085, 2356513259, + 992904321, 2946393976, 771800391, 1987930368, 1558739267, 2136697059, 2672585493, 2839684665, + 558785909, 2401082480, 2917037459, 1775669248, 609856409, 2136759395, 3711732619, 1763207604, + 3749539221, 2182578625, 1563571175, 3257728949, 2235071624, 1870112181, 3143764135, 2556720440, + 2019675821, 1663990892, 2761293583, 2774026109, 2771797725, 2910084661, 2562158198, 1934596448, + 2698755697, 1836890408, 1751348653, 1813721087, 1752393802, 2927108515, 3691395436, 1048613632, + 2766392642, 678978084, 1638801063, 2686868080, 1933134441, 1025872765, 2394203219, 1416600956, + 2035186297, 1476433047, 2656120876, 2136635261, 2425909614, 2105450899, 2231414705, 2404087228, + 2267912855, 1806471060, 2075110195, 3920968535, 233162555, 1839070993, 2077853009, 2410888913, + 1938666341, 1905178446, 1953272743, 1821527398, 2849089956, 2541709176, 2608237210, 2857387888, + 4287920736, 1610630546, 1651347054, 2205463412, 3029037653, 1886412205, 2774898516, 2407892092, + 2352116717, 1627416253, 2626368141, 2649261907, 2110635930, 2175539923, 2541500091, 3069614518, + 2525191331, 900037759, 3783424928, 3450383668, 3149676519, 3070187387, 4279647061, 2225438550, + 2540341178, 2118475852, 3732764725, 1561751984, 1838563102, 2479458885, 2880655147, 2692192191, + 2842441131, 1716885312, 3180240079, 2827995392, 1420019076, 2073580381, 1386938129, 3137825392, + 2909114758, 2572384617, 2474347691, 2521912064, 1541169851, 998547163, 2613622350, 3043373741, + 2788859781, 1755815643, 1635015021, 1955750345, 3918171254, 3816332930, 1383428032, 2575712942, + 2056680703, 3372200759, 612800090, 911595941, 1127652435, 2240170538, 4073760224, 2607564237, + 1701409132, 2348844364, 2841553990, 2753642603, 2929418051, 1233421435, 2760005936, 2453298730, + 2529558406, 589788846, 583550111, 3060303907, 2476447436, 1227143636, 1969062219, 1873293389, + 2394457507, 3452397824, 2994811337, 1798922650, 2576480896, 4291143661, 2863055992, 2241150544, + 3245269275, 2827255060, 1568244655, 2565823067, 1868855401, 2063105399, 1296913027, 2861145384, + 2304869228, 2147524252, 2073664337, 4285038484, 2170184524, 3184343952, 1925420381, 3899823965, + 2171366744, 3114418550, 3142811071, 1917091539, 2293727744, 2676335767, 2794022340, 1368945986, + 2726724476, 2079811974, 2465492603, 1905553594, 3566706494, 3043229842, 1838250702, 2239701396, + 4281773477, 2221277607, 3668622454, 2596505697, 2990777083, 3143914868, 3568404009, 2812180223, + 2014872191, 1451657084, 2356591239, 3465916182, 1456646989, 1973648204, 1015317428, 2039449780, + 4052785765, 2877261398, 1199186291, 2573645567, 2306352769, 2785051806, 2191981735, 1265793066, + 1858588212, 3347196019, 993634108, 1084398283, 1851293823, 2176225908, 2068610161, 2576381255, + 2390847869, 1828748144, 2156097717, 3372900004, 2523104382, 2491843222, 2070241503, 2812790214, + 1733124906, 4287795043, 3359804398, 2323688949, 1538999988, 2818604506, 2658962577, 1030824800, + 2380427905, 1808220844, 1617351625, 1045706020, 2811196928, 795120336, 136136575, 2342675032, + 2865929280, 1941827655, 8564891, 1566095241, 3078784577, 2891393102, 2743436174, 3148313653, + 1571392831, 2214568625, 2762186602, 1956152641, 2573631062, 3348135552, 1302626303, 2621991057, + 2926681402, 2000135116, 2139858825, 1519157089, 1419613486, 1659240306, 2730566219, 1621984609, + 2217949605, 2154603419, 1448964510, 2207932014, 2852095324, 1722779201, 1263440605, 1852873407, + 1737001571, 1538770297, 1786487353, 2001438567, 2039545789, 576422830, 862375056, 2355657800, + 2053993528, 2153937857, 2455151615, 2689957326, 2775670089, 1820573031, 3433743244, 2573698482, + 1052804747, 4020211558, 2006581198, 1146776187, 560967300, 2906935114, 3008329912, 1736689592, + 2154780989, 1995155638, 5996260, 1869767228, 1916622138, 1797553301, 2067241354, 1772520894, + 3830680947, 4286467911, 2304534931, 2171448144, 1990884516, 2525396844, 3015927138, 1984643954, + 2379743425, 2661713478, 2526725752, 1453290219, 2209243753, 1718067840, 2075745363, 3820505696, + 2340618343, 2233888149, 2038653536, 2931047569, 2494005361, 2460768866, 1870490815, 2075438956, + 3063126937, 3331954836, 4288059241, 2490677409, 4052172911, 4290394443, 1971427132, 1214271430, + 2558543481, 3077739165, 1486190959, 2030672525, 2092849502, 1097529356, 2296487216, 2193405012, + 7697236, 4291984815, 2421021300, 1586386542, 2908903042, 4258709045, 1390259128, 1617853832, + 1699896692, 2239409502, 2155068033, 1811960487, 2084117094, 2538055240, 3045568082, 1911066943, + 1354906466, 1957819542, 4285092977, 1852459875, 3416548519, 3535713903, 1736602214, 1451581311, + 1986199446, 2742907022, 1216107227, 2091097470, 2810548041, 3972373648, 2774370190, 1705008521, + 1434058690, 2459211675, 1787532743, 1569483557, 1335925333, 2085772891, 2941235626, 2709356118, + 2969543471, 2254800535, 2477354939, 3125577623, 2054422430, 1666554990, 1099026539, 2207945054, + 1853976161, 1365023683, 2847259986, 3441704080, 2610972821, 1968978340, 2810445671, 2378854130, + 2105783391, 2372107689, 2235792087, 3233904486, 2427226036, 1990757810, 2153513091, 1571441262, + 1758895930, 2240655733, 704649372, 1588488801, 1640678148, 2104157102, 1283451538, 4073406476, + 1417228088, 4067863163, 4176416052, 3822533833, 352301549, 4225008883, 2966856794, 2387956347, + 3288297085, 3196146242, 2240578680, 2846126266, 2560068444, 1577812100, 2121388969, 1248421723, + 933199050, 1617205394, 1787916615, 1855652043, 2863544983, 11309689, 1692072544, 3819010226, + 1206629859, 2373470079, 1528175445, 3128369192, 1217357376, 2346349500, 3884545400, 2509736813, + 2707850581, 4288565558, 1042932473, 1036046868, 1044706087, 3151670974, 1044635600, 1050108320, + 1047335586, 1041338286, 1038329480, 3171199086, 1027458487, 1026846921, 3170955028, 1038272791, + 1042099733, 1023631841, 1045623678, 1036850238, 3169992935, 1024287600, 1049767013, 995219795, + 1040643307, 998947591, 1036960834, 3179608228, 3141474354, 1039120063, 1014755058, 1037214547, + 1026831299, 3161435107, 989095806, 1012618819, 3173055039, 3167954080, 1029698723, 3161365798, + 1020350416, 1035914227, 3175887125, 1016829433, 3183727383, 3158569601, 985916898, 1030089263, + 1036454680, 3156054842, 1034743508, 3150866466, 1001270247, 1034190346, 1026856113, 1023816386, + 1025003399, 3154975140, 3159031758, 3181516378, 1017520469, 1006920169, 1026471603, 1026108426, + 995969210, 1009538160, 3159696075, 1016583445, 3150715858, 1014529258, 1008555538, 981846227, + 1015419886, 1023845324, 3171510193, 1019527226, 1020908842, 1025199819, 3154815959, 1020766835, + 3162250959, 1007879529, 3145757836, 3162556466, 3145088904, 1022244160, 3162319549, 1033161556, + 3170004997, 3179242728, 3171476541, 3168027689, 1010205841, 3174575065, 1025535253, 1034040803, + 3154321149, 3185116122, 1015042743, 3171072761, 1042197925, 1031880174, 1041379394, 3173578024, + 1036593162, 3156042609, 3177068509, 1034306201, 1021755086, 1037171564, 3166520301, 3174861139, + 1042442184, 1039408677, 3211598967, 1063993918, 3214289855, 1066729320, 3215091656, 1067608008, + 1058473425, 1055736216, 1054558327, 1063297440, 1055686113, 1053456059, 1053046526, 1058930617, + 1055175399, 1055547741, 1060943505, 1053020745, 1057992678, 1058329294, 1057580897, 1059872046, + 1053422499, 1058662413, 1057713315, 1063441270, 1051529937, 1057582539, 1055260105, 1058488996, + 1056874455, 1059299483, 1064722701, 1062051663, 1058006609, 1057492867, 1057124224, 1059576570, + 1059172961, 1057011907, 1058954562, 1058304555, 1058634745, 1053874528, 1064950885, 1058061724, + 1055327304, 1057684010, 1057613151, 1057127010, 1057215669, 1054258060, 1058885185, 1054363004, + 1057714069, 1058454715, 1055368282, 1056380665, 1056908842, 1060970973, 1055869444, 1056191281, + 1052282792, 1057108079, 1049390702, 1050919932, 1053250032, 1048624365, 1060940324, 1053426578, + 1054342651, 1057317567, 1050209903, 1049810963, 1050441118, 1058141981, 1053128956, 1048935443, + 1051213622, 1049666355, 1065353216, 1055890495, 1053174472, 1049231492, 1050745898, 1047192366, + 1050786723, 1049574412, 1053562360, 1053072316, 1057507729, 1057367590, 1056079662, 1058463884, + 1052494894, 1052580291, 1055205078, 1060115266, 1058303732, 1057790119, 1057549084, 1055993629, + 1059989068, 1058558954, 1051178684, 1051282195, 1058567206, 1057040208, 1059791824, 1059472539, + 1053583692, 1053931205, 1052483939, 1059790662, 1053767605, 1061726074, 1060099530, 1052563253, + 1058779104, 1060662324, 1052805962, 1052883783, 1054990562, 1055979719, 1056028454, 1051613030, + 1054551384, 1049019091, 1054663780, 1053511956, 1054675325, 1049570100, 1055518538, 1055157628, + 1058903396, 1055315307, 1054629148, 1057311364, 1056336387, 1056296286, 1065353216, 1054265834, + 1049974239, 1047653313, 1057291978, 1054848638, 1060135905, 1057007033, 1056277221, 1058717363, + 1058149170, 1055662652, 1056756865, 1059471026, 1057994776, 1057341594, 1061162024, 1058353051, + 1053481820, 1055676362, 1058285050, 1057169197, 1060750194, 1058895947, 1058298761, 1060738436, + 1055935944, 1058929747, 1055845734, 1051893656, 1058198359, 1058048579, 1054462770, 1056562600, + 7, 2154921508, 1770887538, 1804571171, 1655211415, 2260834924, 1233620849, 2977933677, + 1719370851, 1966699904, 1851498616, 2471624773, 2124326201, 2058003269, 1484223343, 1618630048, + 2540060241, 1482408865, 2828046186, 2774821528, 2340195995, 3515246248, 2522589317, 1752967824, + 2256904302, 2423408752, 2462826355, 1502910374, 999581839, 2341698925, 2558685392, 2906629262, + 1854834319, 2208474045, 4280128122, 2173539967, 2152229394, 2744758398, 1717462646, 1452905860, + 1601664399, 1539743144, 2535755862, 1871590026, 2659737564, 2123405764, 2458221663, 2171823953, + 1803395948, 1870633160, 2306248567, 2610895255, 3164963712, 2033815449, 2911135387, 1370579833, + 2022673047, 1704893083, 2460899476, 2507711131, 2748544220, 247032917, 1937937467, 2744607828, + 2257874561, 2294385269, 1719141738, 2578311758, 2460375673, 2441442209, 2090906229, 1937913994, + 2187869291, 1132366848, 2006871379, 2457064046, 2777546974, 2324276870, 1451790152, 2624298133, + 2088872309, 992761999, 2743576689, 1552185754, 2198630813, 1921418225, 2422624023, 2810410386, + 2035250813, 2338811502, 2422774663, 2036441023, 2128242228, 1485211460, 2257605976, 2643372192, + 2474677117, 2309851065, 1183029565, 1970551655, 2122408834, 1485082263, 2172753038, 2152033083, + 1654829726, 4288965760, 2865163625, 3146361924, 2347001747, 1301052555, 2107875722, 2288537007, + 1737642078, 1183092587, 2173196165, 2274521769, 2356300089, 2372447354, 2879031210, 2775694482, + 1788444768, 1284874646, 2422168912, 2189786489, 2710268793, 2473573741, 2192800790, 1988804739, + 293228591, 2796140543, 1102156389, 1687245194, 2239063437, 2373227152, 1636399502, 2697687020, + 1454804295, 2141090924, 1787006353, 2170778741, 1582460057, 2291359616, 2950115127, 2611061721, + 2562696639, 2307030171, 3163209639, 2406381717, 1383270777, 1990425954, 2540559977, 1617987909, + 1520741015, 1934182148, 1870571438, 2263191878, 572029663, 2741595192, 2392037987, 1866488439, + 2187826822, 772964329, 2560654669, 1317234560, 2525066066, 2151322479, 2546118292, 2961888539, + 2913242276, 3149902509, 2329787746, 3970778155, 2732289398, 1795180381, 1939053954, 2707740767, + 979011488, 2255907109, 1755610219, 1769185461, 1483965842, 2746907525, 1462598810, 1622568591, + 2426826903, 2269073620, 2155452320, 2659935864, 1333218110, 1820167796, 2677121381, 2575608480, + 2286980761, 1955747436, 2324928369, 2105711616, 2927650436, 2290981454, 2290581371, 1770952573, + 2322826614, 2873980190, 2190776189, 1075212380, 264273020, 2440129406, 1482463052, 2845215077, + 2641598565, 1194813072, 2072289781, 1378852159, 1889543242, 1181527352, 1768772473, 2286330723, + 2207619705, 1950315395, 1956164180, 3064690785, 3230703252, 2627272619, 2779029918, 1600945778, + 2493090377, 2573909607, 2878559618, 261198202, 2707396774, 1083603568, 866758773, 2630988166, + 3399518860, 1566874535, 1638037890, 1921688468, 2488615719, 1986362755, 2389484062, 8214936, + 1804435812, 24270281, 1972357758, 1567938942, 2070716812, 2091680912, 2691007906, 2218496814, + 2004405390, 848203120, 1904901263, 1802969929, 391347813, 1831237726, 2574176673, 2609351630, + 3377882274, 2996872203, 1351183803, 2064616288, 2119854450, 1385380125, 1922075485, 1737523799, + 2440315259, 2535951742, 2069326294, 4291274249, 1972695382, 2423222935, 2813313889, 2072599221, + 2419946080, 994535765, 2104396104, 2256195705, 2335928403, 2141815418, 1979490700, 3450666350, + 2707136719, 3513501313, 2875632295, 2424562061, 2694482286, 2711977945, 1535836159, 2862242756, + 2676074839, 1752791408, 2139240570, 2320542803, 1969518683, 1990046305, 2487452980, 2675018597, + 2829216855, 2411886905, 2156376044, 1167166071, 2573974887, 1553299249, 2459211152, 2306963115, + 2306453383, 2323150464, 2741924217, 2979500606, 2609618603, 2063569570, 2108258901, 2553758585, + 2291489676, 1585085052, 1399223141, 2021809279, 2037560194, 2087145370, 1333884116, 2696899250, + 1570539408, 2593879371, 2350285444, 1347281378, 1249599598, 2339880565, 2528212602, 2241235878, + 2049084598, 1971874173, 2676259218, 3079923353, 2290059429, 2373686941, 1687590761, 1998959259, + 308084676, 2829285469, 2391712086, 1987276359, 980772221, 2289225372, 1835522662, 1721005357, + 2725095816, 2003268963, 1770478491, 2371261531, 2171167329, 1131906653, 2389738354, 2103796906, + 1854509716, 1597790395, 2592442029, 2123990438, 2134552005, 2641336430, 2105241241, 1666678874, + 2508303509, 2036119236, 2645454938, 1299082614, 1615561586, 1935047525, 2219152483, 2958063376, + 2056222534, 2657836433, 1634043562, 1654946419, 2678950292, 2121820287, 1518375333, 2557280104, + 2372682871, 2138333520, 1669242482, 2274071426, 2322950513, 2087874944, 2476196096, 1923196798, + 1734973818, 2010349880, 1785230206, 1887275142, 2172280179, 2342351706, 1335009155, 1920299378, + 1902077295, 2139456810, 2425387439, 2308028778, 2055048352, 2223870844, 1295400058, 2274186837, + 2206387068, 2008123203, 1786097004, 1347782048, 1904910775, 1836090801, 2404746422, 2791208323, + 2792852630, 2521653145, 2526399127, 2579138234, 3048437650, 1404142483, 2035573340, 1450930791, + 2187323747, 3326237230, 1737780798, 2694405715, 3127870338, 2694422188, 2505353611, 521221768, + 2089188928, 2590834534, 3550164856, 1216124814, 1533757741, 2510589352, 1282450825, 1263557503, + 2560663113, 2238427801, 1363163282, 2544021418, 779042895, 2343749529, 4056112771, 2288013424, + 2116854109, 2037098389, 3025826385, 2005270378, 2426492817, 2322237881, 2845398833, 2541654334, + 1418765958, 980592442, 2473202797, 1953923482, 2559478143, 1869120855, 1434933929, 2426120079, + 2122171757, 1756004245, 1820028040, 1667660184, 1769307753, 2433310848, 2004121164, 1985770158, + 2305588577, 1516860769, 2055183224, 1754617948, 1668786812, 2200730229, 1972283285, 2374225574, + 2072793234, 2140445602, 2406964331, 2038890631, 1702914459, 3214112360, 3429342342, 2055264393, + 2958852445, 2288682496, 1633399897, 1837025911, 3248630198, 2370604193, 2408545234, 2910092679, + 1083144036, 2337378665, 1782347883, 2186725478, 2959876129, 967664210, 2640746830, 2628601891, + 1150045552, 2155033544, 424175001, 613768992, 2372895603, 3583279464, 2827983503, 1485993883, + 1938140817, 2137019030, 822192309, 3216420526, 2138476936, 1300407645, 2427227782, 1971499941, + 2979953039, 2156956294, 1516193392, 2503503984, 1971674714, 4289765193, 1973262472, 2895089524, + 2005022639, 2208001471, 2741289846, 527267928, 1604290160, 2624057956, 1952542329, 3450451058, + 2689044128, 2993976474, 1768249716, 2182529479, 1518178387, 2103208044, 1347466326, 2206629571, + 1989148830, 2289732987, 2055171682, 2674088330, 2389934964, 1920292210, 3161958251, 981420655, + 2190452616, 2660805738, 2744336750, 1970766425, 1748907886, 1818840461, 2122428290, 4168389400, + 2142414533, 1334602905, 763011745, 1703574044, 3266630285, 2995232165, 1939193210, 1080721499, + 2292040009, 1802805884, 1806854515, 1533379710, 962888276, 2287951708, 1418151942, 2640569875, + 3180714357, 2964443016, 1266848054, 3095178095, 2667550414, 1770083928, 2139920733, 2473759853, + 2288862355, 1972340624, 3494220704, 2424928915, 2340322419, 2186654305, 2978849913, 1890960315, + 2546696843, 2141603175, 730686066, 2828177500, 1449548136, 1450544222, 1840020365, 1752732019, + 2436874551, 963772527, 2157095045, 2523040659, 1551658344, 2310309593, 1109475686, 276443443, + 2139218048, 1766475112, 1972472476, 675057256, 2894167451, 2341436293, 2547554697, 2980354951, + 1735286424, 2638905473, 2773193805, 2470996347, 2727575380, 2219474532, 2086232441, 1462798436, + 2220771665, 2877862766, 1470562349, 2423155080, 2711279230, 2374649965, 2474295943, 1563784342, + 2561318767, 2557133160, 1952599891, 2137624669, 1934281068, 2508301948, 2695984006, 3143600407, + 1385604229, 2610869914, 3548025713, 2559932276, 2139901267, 1451532080, 1953264766, 2358276778, + 1033345674, 1098562523, 2813549214, 8696966, 1767146576, 2258141828, 2088013734, 1820906160, + 2489802899, 759581011, 1922077839, 2426222997, 3080880504, 2302903154, 1602071460, 2190183056, + 1887664970, 2474157949, 2489675133, 1933086559, 2306504562, 862073108, 2440722220, 1030985329, + 2256044398, 2290519135, 1493198208, 2207292272, 1669749602, 2190175857, 2828775312, 1635744405, + 2054850221, 1939634507, 1904302636, 2139058561, 3094284299, 2325980387, 1918543740, 2777636541, + 3313075818, 2896191354, 2221442502, 1854570364, 3967967588, 2556399938, 460876167, 2675932850, + 3855194707, 2069553590, 2378081125, 1942891090, 2397130594, 1720481850, 2325438370, 2490653506, + 2139661490, 2214607796, 2442283853, 2677236830, 2339859829, 2019785348, 2477689448, 2924644935, + 3114222480, 1786314544, 2793840243, 2858969414, 1568130117, 1137797259, 2137694310, 1549835404, + 2776609635, 4001855894, 1434550678, 1317634191, 2396829062, 2590542933, 1083355813, 2262069120, + 2557055108, 2710408584, 2341634184, 1818002269, 2961535356, 2289599864, 933966180, 2425252720, + 2084664443, 2757399667, 2141688730, 1850572914, 2726516374, 1535672987, 2358205851, 2037869175, + 1097103972, 2223863350, 1811974015, 2525386925, 2288803430, 2376172967, 2038135656, 2038502974, + 2284625792, 2658300786, 2442257835, 2426124925, 2074451802, 1769356401, 2239464827, 2187155711, + 2592242517, 2173208443, 2860628608, 1531932081, 880961954, 2242935572, 1805162900, 2508615063, + 2288869086, 1637129856, 1920952944, 3263216475, 2257672619, 4083659658, 2155121841, 1651478388, + 3397309043, 1889772196, 2056101796, 2239711628, 2089053584, 2119206295, 1500871779, 2089203588, + 1937546371, 2558880106, 2457238143, 1870639216, 2258345067, 2389610339, 2743038272, 1738254927, + 1952215422, 2156360023, 2275312321, 2004454799, 2456259677, 1837537665, 1199346295, 2288876671, + 2174124173, 2458149968, 2074700414, 1838320993, 2139127155, 2223803040, 2054316421, 2794362761, + 2172714879, 1699889497, 3967468425, 1863287722, 2397617568, 1721325567, 1840140897, 1936233335, + 2815077810, 1474320297, 2306119295, 1241557617, 2238985828, 2377408310, 2976341191, 2355060837, + 2558403405, 1600041019, 3851571295, 2208125546, 2880218476, 2475326855, 2087230088, 1817090414, + 2861445196, 2256253562, 1331584617, 2642850707, 2690737015, 2204532669, 2154405315, 1951158961, + 1817028271, 2658842232, 1672441537, 2358078534, 1969389983, 1735094137, 1085708672, 2742076600, + 2155186316, 2220907890, 2340946084, 2609064509, 1883059567, 2288018806, 2726533281, 1769895764, + 2022210960, 2356905317, 2022075784, 2672965297, 2642835354, 2612905040, 1686869124, 2306574461, + 1555926192, 1887985209, 1786290588, 3431824798, 2374661273, 2067305340, 3163325044, 2741731994, + 2169863526, 3427650697, 1586474912, 2089453437, 1667375039, 1985526660, 2812581512, 2105391289, + 2121304933, 1194411998, 1417986669, 2072117125, 2946665926, 2085835412, 2524079720, 2054397258, + 2324725144, 3349715362, 2120669951, 1858628200, 2528337552, 2406388729, 2422174823, 3297623432, + 1892188547, 1600818810, 2622845100, 2188153742, 2205055717, 1268030278, 2340717432, 2341322216, + 2911338634, 2291307381, 2139796446, 1434766716, 2306173559, 2140443765, 1536722045, 3296291659, + 3029043840, 2257039454, 2190500926, 3046078378, 2509744459, 1040150360, 1917889152, 1905491587, + 1970902654, 2390002304, 1487174550, 1672434559, 2188547478, 2289539714, 2072633958, 2291101310, + 1515886968, 2558956428, 2172757913, 1987412806, 2859700089, 2155809408, 2561555057, 2897394007, + 1265204662, 1636394631, 1153973124, 3562585995, 2960097174, 1070307220, 1926069101, 2050730334, + 1536684171, 1973455469, 1970263158, 1705864102, 2072927841, 1924575872, 2107043431, 3112762488, + 2345512031, 2087808148, 2508421551, 2293135419, 1885040701, 1465954201, 2222980987, 2726395500, + 1937865323, 1717984363, 1668845694, 2224912037, 1396991120, 2206173612, 2460113030, 1708289659, + 2259578766, 3398857271, 2508099199, 1656982889, 2072339862, 2021153155, 2225560757, 2222504291, + 1333955521, 2055238544, 2090505668, 1870622037, 2156555111, 2101765667, 1283027094, 2122579842, + 2315274734, 2539097709, 972527262, 3780456226, 2304526463, 981898142, 2684076660, 2913363320, + 1902344847, 2226618704, 1552957160, 1367432503, 3167333538, 3294386168, 3213933436, 2386646839, + 1871458717, 3883588910, 1934908778, 1872407505, 2860526696, 2265448547, 2594167219, 2726426765, + 2138972800, 1999078590, 2526510513, 1899576692, 3409402516, 2372459381, 1667084150, 1685540668, + 3614557334, 2522638433, 2258206094, 1748075147, 1787941302, 2905843610, 2788793192, 1968013413, + 2021103033, 2052800057, 2793060510, 1969979843, 3502346592, 2256435299, 1989955001, 4838118, + 1348830747, 2072228997, 2893572863, 4037250455, 2355406772, 1990488189, 2274193505, 1603760257, + 2338684021, 2977330323, 2538574457, 2545188080, 2510654886, 2424189775, 1065254278, 2221062254, + 2794091422, 2059706926, 2042053482, 1838188921, 2223610717, 2086099609, 1199269225, 2241543829, + 1870680953, 3533274457, 2306393719, 3215945564, 1585884312, 1409324174, 2787284100, 3780225349, + 2427626898, 2739315403, 2034222154, 2756541028, 2136240025, 2520667252, 2271761564, 2892465561, + 1503491124, 1651283354, 1470326958, 3347409297, 795961286, 1565276798, 2171846572, 1601460551, + 2190059185, 3160389476, 2003779462, 1888584080, 2137877880, 2021553003, 2610720593, 2289932171, + 2273555853, 3364191305, 2087474533, 2223736433, 2994303855, 2106683279, 2278278822, 2140251609, + 2759150480, 2676909210, 3012718702, 2277030043, 2983768715, 2257190862, 2530262393, 2172825227, + 2575670684, 2223544686, 1836481677, 1870821021, 2306181239, 2762728906, 2625998502, 3009312398, + 2629747520, 2742211719, 4290201284, 2020439859, 2838418820, 3947261887, 2473361637, 1363366523, + 2559120954, 2361940151, 1804321395, 2352712581, 2059505747, 1586007944, 1519615592, 2208866654, + 2138607469, 2642271897, 2262992250, 2875959709, 2023319194, 2339790710, 2108600679, 2106617503, + 2891028901, 2242283186, 3042947701, 1887526047, 2354410435, 2941627473, 2021230690, 2120580984, + 2054225809, 3129123509, 3081231233, 1656118904, 2555041624, 2159637568, 1822019992, 1853727624, + 2192146259, 2222037874, 2525934158, 2093050218, 1195093447, 1367239279, 2155882368, 1871421082, + 1685226608, 2258919516, 2388116372, 2205526128, 1990551906, 3078191992, 2220286356, 2709828730, + 2160029075, 1346722345, 2642908289, 2021710455, 1906475686, 2075890792, 2713289918, 2939639461, + 1535923677, 2341759653, 1954909857, 2978442353, 2390255785, 4002491679, 2207083655, 2323185526, + 2524918865, 2591710359, 1604093803, 2003997577, 1805490347, 1419155813, 1116769098, 1872004502, + 2157418612, 2676839766, 1435075451, 2961601414, 2778687890, 1215272811, 3411702896, 1901100664, + 2426841019, 2038209700, 1873580161, 2056754080, 1887275380, 2109640633, 1802468559, 578515553, + 2156003200, 1066561703, 2172217230, 2992935598, 3315182694, 1554805086, 3115739814, 2190251604, + 396457304, 1609498544, 2154591823, 2188750740, 1920363680, 2587713365, 1965599103, 2075300238, + 2459141997, 2307526059, 2258225079, 2375337363, 2842589730, 2240717743, 2190897407, 2093334393, + 2407355538, 2272923769, 2141038568, 3130628727, 1086094200, 1703515023, 3784060550, 2410721191, + 2372901809, 3114411373, 883659909, 2160753648, 1664668558, 2357560932, 1084776092, 1855885173, + 10777198, 2092330873, 2033807582, 1082100881, 2004171331, 1921343634, 594838929, 2206310820, + 2832171175, 1768841580, 2072082821, 2507315236, 2507978204, 2605564800, 3747456188, 3479725379, + 1849162380, 3198640784, 2801828210, 1936618614, 1756736557, 3057549515, 2793604897, 3798739301, + 915188799, 1589784736, 1647539254, 848335769, 2053843124, 2660186773, 1405127048, 1151062442, + 2391514040, 1923135342, 3061923347, 2289269881, 2527566893, 2192087168, 3070255978, 1782476119, + 1870237526, 1465091997, 2523571079, 2491135851, 601470046, 1755164546, 1550952362, 2205066365, + 898861484, 1559459995, 2443076544, 2074426524, 2525269926, 1853539758, 2188903005, 2003981978, + 2677048169, 2138147396, 2209322065, 1818591170, 2039055495, 1820361875, 2642111296, 1320061065, + 3047195779, 1571212620, 1719130763, 2105960229, 2405339533, 2552547258, 1959488153, 1285915559, + 2340060039, 2708898659, 2107210159, 1674937195, 2419631426, 1497980568, 1500762460, 2188620923, + 2859288894, 2021090195, 1993035963, 1224721795, 3096467260, 2122512002, 2492050092, 3077010785, + 2340977552, 1149995360, 1617870217, 1400273812, 1015054668, 2824055219, 2801745579, 2323474063, + 1904193925, 2407372158, 1819968116, 2643548085, 2915529091, 1637265526, 1857332292, 2625538323, + 2040505205, 3463552385, 2574864037, 1942777947, 2728621489, 912426837, 2055645318, 3211094310, + 1703250075, 666139728, 2290259882, 1185439053, 1266445866, 3435050158, 3034798423, 1778431866, + 2090760771, 1818039886, 1905358735, 3338107997, 2993314909, 1633728680, 2037733459, 2170596478, + 2274762177, 2690217877, 2225038419, 1719440755, 2402587539, 1584161900, 2879221432, 2373311603, + 806944897, 1987205744, 2247143258, 2714739803, 1317051297, 2072536939, 1199594111, 1419353724, + 2022093952, 2391624890, 2180147018, 2206750599, 3010094939, 1903455641, 2694635664, 2389500603, + 1773510078, 2542767239, 2303708522, 3248981060, 2508493984, 2243070073, 2211283856, 1602853042, + 2306167927, 1784448679, 1618110327, 1168537200, 1604753553, 3062597688, 3497373793, 2644413247, + 2608043896, 2491062084, 1906482858, 2794417055, 2274191963, 2612105362, 2158407016, 411992717, + 2069674050, 1750288463, 2222933619, 2489823899, 1922335643, 2071815266, 2260425630, 1836208512, + 1871613585, 2273116025, 2490005188, 1956811373, 3267331686, 11109028, 1615629127, 2877506717, + 1134987809, 1365607016, 3092811140, 2442932415, 2406124687, 2607313301, 10777502, 406487391, + 1770628753, 2084273752, 1720875371, 1316936115, 1820096625, 2291701088, 2339604886, 1934524576, + 2659541960, 3062379904, 2021950088, 2711249154, 1906221964, 2646382688, 2072010880, 75968947, + 2711445351, 1756267957, 1618032808, 2859631773, 2557585727, 2156103066, 2759690618, 1368355967, + 691386680, 2072414615, 1567013749, 2391431818, 2541307296, 1836707969, 1902944896, 1752001187, + 1829866628, 2558472448, 1315868266, 1971981963, 1805092476, 2911802243, 2236330108, 2087619202, + 1567521215, 1757776519, 1533511493, 2005300918, 2231016057, 2374522251, 1394515801, 2474797154, + 1172337523, 812933275, 4290670517, 2608110740, 2408760983, 1470117217, 2361555604, 2659356266, + 1736845453, 2292228252, 1757389993, 1468220250, 2356575092, 2070323168, 2526251371, 1952022186, + 1537051271, 2038799668, 1683261574, 1821014896, 1583988072, 1634896529, 2025689004, 3062001093, + 2005035909, 1737129838, 1819766862, 2223272322, 2290457678, 1666029994, 1903869328, 2475057280, + 1432253083, 2140760667, 2274261130, 2893975489, 3314652063, 2306473847, 2055976371, 2140959606, + 1702395265, 2290402467, 4290930048, 1555729118, 2037023806, 2226409650, 1821139850, 2292146616, + 2644668562, 2141747845, 1438954649, 2758115673, 1584943327, 2642903940, 1619117649, 1367979890, + 2694472080, 1802858329, 2342608495, 2527753409, 2288480374, 1703315333, 2557146472, 2038994564, + 1669039227, 2290254479, 2675801736, 1770096234, 2574164612, 2390918045, 2324988270, 2020382868, + 2106750602, 1803516280, 1819963262, 2508550769, 2356310911, 1385859712, 2238211174, 2562826911, + 2375267936, 2290182546, 2206371441, 2474791553, 2206495134, 2323617645, 2458150250, 2222456956, + 1937409903, 2140376168, 2424992636, 2258935951, 2525659767, 1867415927, 1754475776, 1750561182, + 2522976374, 2191944527, 2274731341, 1719755653, 1867343466, 1517715070, 1988978549, 2257033041, + 2326433294, 2406641841, 2105515907, 2459392281, 1149342847, 2039184514, 1853713242, 2608812664, + 2139266434, 2674883552, 2610725230, 1933206662, 3565768059, 2976284748, 713212208, 1957410478, + 3311568764, 916247095, 2172615028, 2835359305, 2088792154, 2523036296, 2471976360, 1622112934, + 2441558185, 2206441895, 1820349108, 2020510571, 2493213504, 1451048019, 2307091289, 1568399329, + 2910805124, 2155910784, 2555018111, 1587042200, 2415887972, 949779840, 2679595430, 1419211144, + 1335589948, 2510636419, 3023672425, 2377088607, 2675130721, 2123722648, 1168735144, 2960893799, + 3093473172, 2224248174, 2378535775, 1264925048, 2119980703, 1551660172, 2189226099, 2258342291, + 1719118799, 2358301333, 2189545597, 1434608147, 1266839681, 2461760145, 2427870612, 1820975463, + 3816992152, 2204659276, 2102772831, 3902971193, 2125044337, 1390587093, 2157813125, 1249082243, + 1615901632, 2330214758, 2708585611, 2776706866, 2559334755, 2141622890, 2037484902, 1534106494, + 2013226317, 2305122651, 1298112178, 2222898300, 2059451994, 1987552427, 1703381877, 1165403482, + 2625225109, 3110303626, 2000854636, 2270650738, 2886362762, 2037364991, 2292221277, 2357371322, + 1321048712, 1822075947, 1565101210, 1672376516, 2457709976, 1820626562, 2275240623, 2372243606, + 2340000356, 2053160785, 1534467418, 1081171582, 2055566982, 2655877304, 2645127826, 3114880407, + 1182627950, 2154261353, 3458634355, 1249285819, 3213140630, 2364711239, 2269539712, 937341530, + 1987349895, 935162240, 3493180022, 1674604641, 1685032068, 1146854526, 1416467045, 1568782753, + 2507249525, 1063503231, 2003801557, 1738370122, 1986320549, 1838153875, 2251317482, 2675934578, + 1376881844, 2072485279, 2742380347, 2074187683, 2072614712, 2207671420, 1754495611, 2313449101, + 2639558273, 2305834060, 1165002076, 2578402890, 1520469146, 2344854861, 1347708818, 2273342633, + 2006686849, 2056355733, 1400930666, 2221746901, 2067750591, 3650506859, 2172845951, 2089917269, + 2811725174, 1482512228, 3464390535, 1172111520, 2999158160, 2454877826, 1002465691, 868397946, + 2478082435, 1237631336, 1919118172, 2020179286, 1719097502, 1474469218, 2945221520, 1819121006, + 2593161138, 1603172014, 2390788665, 2339792780, 2054171049, 2393336675, 3632817050, 2106089603, + 2425588325, 2138995593, 2309326964, 2224520845, 2390995605, 3819739515, 2006478261, 1905107076, + 2291437681, 2004651198, 2122036635, 2139273666, 2808628134, 2057006455, 4287985768, 2272513133, + 3280887938, 2038211830, 2254671463, 2021750857, 2222489983, 2073276288, 1550742711, 2004976051, + 2122434434, 1171807789, 1551534467, 3301754493, 2356044664, 1201372566, 2826875477, 2541307358, + 1150976652, 1638248548, 1825022583, 2785002676, 2323882903, 2187172227, 1488226968, 2158526842, + 2339148692, 2122619265, 1769500252, 2037676946, 2003458393, 2860361396, 2040641861, 2630240314, + 1180411297, 2022052232, 2201646527, 2526067070, 887058089, 2188807038, 1330148197, 3263972054, + 2641583462, 1949007815, 3289272676, 2477485937, 2271730049, 1954505846, 1639800454, 2906429010, + 1747955485, 2176212605, 1319707781, 2876740250, 1985701276, 2574487426, 1635642458, 2206884296, + 3076510604, 2913231529, 2206203774, 1955112824, 2189786235, 2055040379, 2373092220, 2239988605, + 1618774413, 2559012216, 2021885819, 2105503878, 2108521329, 1717201300, 2273542528, 2071427718, + 2239596933, 2089320573, 2611122847, 2589552786, 2441178518, 2205781384, 2207024006, 2306836103, + 2226221976, 2474871936, 2407757944, 2189557630, 2709012529, 1854633070, 2323225962, 3917642384, + 727801713, 1585422927, 3183182920, 2423870565, 2024703868, 2155701070, 1571202190, 2089592214, + 3470095246, 1817141158, 1657177703, 2032102749, 2631330614, 1905630846, 2491263385, 2441326208, + 2659139949, 2254276233, 1869545366, 1686597745, 2339809397, 3698300255, 2524618087, 2904255053, + 2071683222, 2637085317, 10044178, 1098286929, 2218442887, 648360530, 2107790746, 3344149434, + 1902147967, 2010796174, 938086050, 3181813675, 2275253861, 3110235298, 2339546558, 2024619955, + 2028472993, 2039582343, 1984525176, 3082855873, 3197138307, 2072361349, 2575209727, 2240904582, + 1504675166, 2676989571, 1318995867, 2879880575, 2409261661, 1891124129, 2977724555, 2308531866, + 2315817629, 2408612719, 2271580529, 2656857494, 2371977918, 2124119697, 2628093555, 2525465772, + 2274856322, 2323798918, 1232816756, 2373280145, 1756164272, 1871998824, 2306315383, 2629340024, + 2755753126, 2223202177, 2221897070, 2608019191, 1765508470, 2051511951, 2788398238, 2816180095, + 2323207110, 3078334873, 1466143417, 9079949, 996040402, 2009737411, 2021938053, 2509825414, + 1737077898, 1668574336, 1233688491, 2154119750, 1886544300, 1920364726, 1970970510, 1988867978, + 2791868097, 1518697831, 2689242520, 3780621151, 3668478904, 702454125, 2304159055, 2175428001, + 12171294, 2751352532, 2101569632, 2122025586, 608926822, 3694410692, 3748500790, 2440395124, + 1518198645, 2576592845, 1853640578, 2307750305, 1601858656, 2135237502, 1923932540, 4036444507, + 2289806201, 2288556421, 2372822626, 1184197538, 1149806449, 1962894376, 1331862360, 2256305020, + 2160354406, 2890323564, 1435665763, 3213244727, 2425180039, 1754623612, 2345287555, 2272555571, + 2628293768, 2117639325, 1986841759, 2521334641, 2376755128, 1249793916, 2324792484, 1936742293, + 2995302027, 2172949631, 1433756965, 1636140400, 3148706689, 3412224372, 2841088578, 2052737439, + 2843710586, 3004985402, 2116993182, 2156034628, 2327532699, 1903061914, 2324012170, 1832637833, + 1285602205, 2509471881, 2459369629, 1904704438, 1989314958, 2759172456, 1635015775, 2037074326, + 2543880593, 3062778486, 2105763203, 2573560374, 1771411568, 1195541942, 2305408384, 1065068688, + 1333625260, 3294995835, 2405463903, 1584358795, 2224320849, 6374572, 2308466520, 1047033175, + 2136045392, 2203735903, 1587849063, 2156578868, 2375827593, 2710679669, 2288035717, 1668772229, + 2238464108, 1282157177, 612912978, 2323174006, 2558333835, 979916202, 3350760263, 2842591022, + 1616687762, 1837670013, 2223278718, 1486325383, 2106698605, 2089045695, 1200961299, 2577251801, + 3734346868, 1850323066, 3211688060, 1999726739, 1871034287, 327698785, 2401005621, 3129507896, + 2458363548, 2294913897, 1888791174, 7436930, 2239507835, 3556773989, 1280750197, 2745590423, + 2092136732, 3232268944, 3746449554, 770404223, 1585271939, 1549483657, 2794766702, 3012309430, + 1737008024, 2622926848, 2681036496, 2843119995, 1627346810, 2743114265, 1700676584, 1753789856, + 3955383429, 679011248, 2990952448, 2862923113, 1941548709, 2226029602, 2956800901, 2079338463, + 3293290317, 3103818603, 1923273578, 1384013420, 2153477943, 2024633460, 1032680384, 2572848767, + 2175945318, 1421962613, 1856416151, 2022796439, 2273933734, 2713603438, 3067230976, 2555743988, + 1651876334, 2709947723, 2809818937, 3234636429, 2506734395, 6328955, 2930928769, 1435990356, + 2998733932, 1974322980, 2696179351, 2776491586, 591265879, 1332447808, 1618770243, 4289187933, + 2630642471, 2326073587, 2386853427, 2874310332, 860946201, 2630895537, 3601366349, 1183465093, + 1565707681, 3533391625, 2256475273, 1552521049, 1265861249, 3297507672, 2824041601, 2124107175, + 949779492, 4283015498, 3195810954, 1808102063, 10260578, 2573174385, 3098044526, 2589172165, + 1137659976, 1432525391, 1920607307, 3713908341, 2344325542, 1117350399, 3114285947, 3046466660, + 2697178624, 1469400133, 1018346829, 3364572269, 2722871343, 2203681438, 3192858491, 2860033993, + 1653503127, 2693529439, 1717103959, 2225365204, 1992329380, 1405073044, 3345361276, 1385347656, + 1382711207, 2624298121, 2714598252, 1968927231, 1136148325, 1516188555, 1857148235, 2036465570, + 1940158499, 2312373015, 2797311137, 2575350282, 3362178900, 1793946273, 1956336232, 3232378713, + 4285234829, 1515874396, 2959175365, 2216918394, 1121693891, 1452380502, 3360519858, 2415961817, + 3698093449, 2568575144, 3093522225, 1677699661, 918467746, 3060034130, 2122534493, 2135257691, + 3795297377, 2963508121, 1758461804, 1600486064, 1753528370, 3451336513, 2604685378, 3151733148, + 490446002, 1839163313, 3613383055, 1979745587, 1149519033, 1884776668, 2537928767, 2204202668, + 1443445940, 1796319490, 2736031231, 2008496109, 1664912700, 274426251, 2165220168, 2188694921, + 2241830756, 1801758679, 2539879561, 2571734528, 3345068202, 3610914264, 661651308, 3821455937, + 2760091725, 2145534935, 1982628627, 2819985027, 207857496, 2759608752, 2714995517, 2127796658, + 1611282339, 3292069893, 2521465364, 997564252, 2714004048, 2686954154, 1750620002, 2034597517, + 2003386255, 4285436061, 1950824079, 1270978123, 196472356, 2824288891, 1351696300, 3379000680, + 8283087, 1280626807, 2020952738, 3132857809, 2221558584, 3347994111, 1849845361, 2507653670, + 1140865758, 1797424729, 3290014446, 2404955627, 1282258216, 3699809965, 2395048317, 3070282315, + 2059898905, 2342407719, 2609274981, 1602063781, 1518699149, 3143115775, 3519283083, 2290848904, + 2542358882, 2407498101, 3885203331, 2187696987, 714515832, 4228133751, 2561545728, 2338660537, + 2591261821, 2088782959, 2127861183, 2192776039, 2662572907, 2602016201, 2317514784, 1904309220, + 1566363738, 2640750125, 1744791320, 2073927293, 2410634592, 2539488111, 2113959865, 1718978178, + 1650565981, 2907012201, 1178228430, 8385631, 1682878645, 2853608800, 2089159494, 2042536710, + 2105498812, 1145929081, 1644865535, 1464895263, 1723698756, 2054769565, 2671916662, 1966304186, + 2139002700, 1532849267, 1900001180, 2121230986, 2225107838, 4283738209, 2292084642, 1353020501, + 1804017475, 4288326814, 2421699006, 3096099010, 2829615666, 2917744265, 1972411288, 1778359937, + 2656350603, 1485337203, 2320926088, 1469283965, 2451484359, 2089380790, 1480425056, 1670804375, + 2055956224, 2710536062, 1563980894, 2378269055, 2542555117, 3622879908, 2840052501, 2376884551, + 2207307261, 716012600, 1617741055, 2302443368, 2223160951, 2370002534, 1905289042, 2387502592, + 1579244906, 2771896778, 1686862969, 2208307675, 3604650034, 2577761926, 2709624953, 1782142207, + 1954627394, 2238257019, 2139707275, 1723048704, 2536860283, 1886708924, 358896727, 2591582535, + 816023710, 2488419508, 2508951966, 2707330870, 2238986110, 2288149176, 1768720896, 2405867153, + 2071017852, 4287647363, 2238420369, 2339023522, 1585275966, 3061079918, 3147272046, 2798673664, + 1820318554, 1781381344, 2961811035, 1453965715, 4016731931, 2257808551, 2039647062, 2746695572, + 2309599430, 3111625301, 2355526144, 2610408856, 1229945511, 2216925695, 1519022679, 2632627578, + 3382755695, 1385969740, 2096080592, 2085286875, 2423444735, 2137340290, 2441511082, 3293355161, + 2080868661, 2807014397, 1377670588, 1602067406, 3361185970, 2087681182, 1822699180, 7678039, + 2306563232, 4286883658, 2951644222, 1502283397, 2502917553, 3127086436, 2879752064, 2887672259, + 2424078764, 2564583381, 3145613605, 2321961242, 1934932139, 1041721020, 3980293887, 2778295456, + 1711001676, 427092058, 1703328603, 3364963464, 2892404285, 1442895523, 2978784811, 1775951155, + 1320794686, 2664759127, 2239714694, 1748078745, 3172971224, 2544233727, 2306178759, 3382288242, + 2082704806, 3365632418, 1027445803, 1082838362, 1702866265, 3378142868, 2415155968, 2174696594, + 2625876406, 364850539, 1717793422, 2392337227, 1706252359, 2781923, 2071495041, 1301058896, + 1655543448, 2456972349, 1833978707, 2478293849, 6724236, 2024397704, 2256110157, 2125359268, + 2355065230, 2827412475, 2794417407, 2794268733, 1631230122, 3112473523, 1682851686, 11913348, + 4170298970, 1996482948, 1665296241, 1720029840, 3629408804, 3295192692, 2092617610, 1481543611, + 2095766947, 4632936, 1703721519, 2017297711, 1715890060, 3380377470, 2658956152, 4287721118, + 2995801212, 1955830207, 2153889678, 2492101782, 1802668905, 3858515781, 2158968333, 1221027890, + 1472443665, 2425482102, 1727047117, 2761529344, 1334016350, 2196263712, 3599383671, 2061045569, + 2385018111, 1030828935, 3091822708, 2055376944, 2188266622, 2738721199, 2274719839, 2844358807, + 2392489809, 4288768845, 1987485572, 3476172682, 3388964423, 2474209923, 1953399209, 2924099710, + 2763940199, 1919899306, 2217318337, 2135312962, 1939919912, 2343287610, 1603311991, 13741232, + 4287845516, 3033573206, 1836211584, 2426162088, 3516711062, 1204330067, 1147516826, 1587097172, + 2329713931, 1130273523, 2718970812, 2534241536, 2053600824, 3165431399, 2138290339, 1248354540, + 2162743146, 3829645408, 3181719672, 1430157818, 2577380864, 1016257645, 1597325192, 2912344501, + 2454613621, 326238367, 2341502821, 3514077506, 4292571811, 2844490191, 1818968502, 1616894888, + 3432523854, 2159964359, 96576865, 1452566834, 1751518720, 3599463368, 3684531569, 3455277973, + 1971354493, 1148659286, 2351717321, 2039349174, 1517392953, 1938721892, 1837989481, 1735612292, + 1467250856, 3519318318, 3332457593, 899109258, 2005041567, 2694094965, 2063555837, 1388072462, + 1970099083, 2425063844, 2029227870, 1836150403, 1788191625, 2036465789, 2292611902, 1704884370, + 2179438272, 1478269767, 1404474753, 2291119216, 2956097622, 478538239, 2591293510, 2008895238, + 1872815007, 2994481024, 1671122913, 514348717, 2865722267, 3268064565, 2339982138, 2633979956, + 2742496818, 1514962397, 2709546836, 2827590401, 1262698628, 2224535198, 1831237214, 2072406954, + 1651354209, 1721063261, 1316618464, 2489073573, 595034021, 2046799449, 3528220021, 1826254820, + 3450365833, 1882542135, 2085653129, 1144509186, 3199656829, 2789834314, 2389190804, 2400761658, + 4288219442, 1042603771, 1035037192, 1041392947, 3164289839, 1046133844, 1043842840, 1049253840, + 1038666594, 1045196835, 3188215987, 1031619627, 1043727733, 1036661432, 1041622745, 1048824264, + 1027215517, 1044437848, 1042579783, 3184765682, 1038538413, 1046623258, 3161780724, 1041333690, + 3133471355, 1047941070, 3185256064, 3166288194, 1035189116, 1034632125, 1032433335, 3175298323, + 1016157480, 1028214081, 3183157347, 3176333289, 1036100462, 3140557907, 1026715857, 3169469313, + 3140780796, 3173586778, 1037662361, 3188986036, 1039576831, 1035604195, 3144976527, 1040946940, + 3147460742, 1031203383, 3177400140, 1026939978, 3180900631, 3164026658, 3179952814, 1040399131, + 1038638804, 1024325640, 3171885748, 3174632920, 1029056305, 1030626655, 1037954418, 1023838274, + 3154441571, 975676812, 1008935137, 1016051759, 3165650861, 3180035793, 1006108728, 3161897497, + 3160511518, 3171917153, 1008931655, 1019814600, 1027394841, 3159197524, 1029224297, 3172138065, + 1019901034, 998804741, 3159419213, 1024485164, 1017952167, 1033292974, 1023102610, 1031625448, + 3162349529, 3189807112, 1032258975, 996297794, 3192633393, 3172214307, 1005434591, 3142289465, + 3194658873, 3155884751, 3175317487, 1028443888, 1040680368, 1028102661, 1009508181, 1049361173, + 3165825931, 3182975263, 3184573791, 3178033442, 1023036774, 1033860938, 3182882872, 1051482665, + 3180928322, 3216852834, 1069272275, 3215652575, 1068081393, 3224132137, 1076648489, 1055061328, + 1054288735, 1051767353, 1055610908, 1056235109, 1051364641, 1051988695, 1055917768, 1051640368, + 1052716616, 1053584217, 1050503795, 1053217794, 1055124746, 1055481068, 1057849754, 1050736347, + 1052631439, 1059168410, 1052699872, 1051648261, 1053599727, 1050728257, 1054429730, 1054853351, + 1051224648, 1058913120, 1051715525, 1055926313, 1057521500, 1058137826, 1061106812, 1052258613, + 1056772553, 1056274931, 1054951367, 1058243306, 1054113033, 1058428496, 1050662770, 1052985765, + 1057450288, 1053636028, 1058040582, 1052837560, 1053268369, 1057973469, 1057709983, 1053742492, + 1055400157, 1048639099, 1055581633, 1055583205, 1056668019, 1054602533, 1057288882, 1053916600, + 1053254942, 1051689684, 1052825094, 1057840440, 1053405299, 1060887946, 1057854803, 1051358457, + 1052326119, 1052071987, 1051411977, 1050359446, 1056069785, 1052857365, 1058765902, 1052870840, + 1051167150, 1065353216, 1053149242, 1048327183, 1057028737, 1050414344, 1049655702, 1052345901, + 1051917585, 1050662169, 1052720943, 1053410517, 1060671004, 1052717848, 1058143277, 1055671864, + 1059147617, 1057690383, 1051027184, 1055805121, 1053202246, 1060001178, 1058611761, 1057931336, + 1056542414, 1056528372, 1058820523, 1054097365, 1056104341, 1057812339, 1059682903, 1054673906, + 1057804793, 1052857407, 1057913727, 1053763454, 1053354143, 1061551273, 1056275317, 1056290864, + 1052376167, 1056612059, 1059516478, 1055004151, 1051314504, 1062125645, 1051562457, 1054867885, + 1059712089, 1058499250, 1058644908, 1059517997, 1052621846, 1057995597, 1056730257, 1057096118, + 1058712602, 1061231925, 1055228442, 1058262020, 1057093883, 1056638879, 1056603106, 1053564184, + 1052400578, 1056714055, 1049950300, 1060693726, 1057772180, 1061522783, 1063238506, 1058120451, + 1059110739, 1060393616, 1061234807, 1057869693, 1059789631, 1064658576, 1061967263, 1060844497, + 1061052711, 1058771597, 1055671998, 1059544269, 1057948895, 1058230096, 1065353216, 1058033139, + 1062183242, 1059375690, 1058814743, 1057741551, 1062971927, 1059964249, 1057398139, +}; + +uint32_t* get_knSceneSwitchWeightsArr_addr() +{ + return (uint32_t *)(knSceneSwitchWeightsArr); +} +uint32_t get_knSceneSwitchWeightsArr_size() +{ + return sizeof(knSceneSwitchWeightsArr) / sizeof(knSceneSwitchWeightsArr[0]); +} +void get_knSceneSwitchWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSmallWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSmallWeights.c new file mode 100644 index 000000000..f5e1096a1 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knSmallWeights.c @@ -0,0 +1,254 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION "ef6000" +#define NET_SIZE 1861 +const uint32_t knSmallWeightsArr[] = { + 0, 1065353216, 723812122, 3902531414, 83232768, 8326376, 4026205180, 3859079194, + 2162170138, 3514835163, 332712607, 3590125560, 360665456, 3943107855, 671876327, 2149778726, + 3081742756, 3288432445, 100795637, 2047015422, 97822079, 370474486, 368049535, 33745659, + 2561343231, 3088577808, 4230020224, 2138359528, 3593018085, 3994099140, 2154028040, 937290933, + 637540479, 4026538260, 211082477, 916379263, 1057330916, 954468837, 3859935103, 3773244698, + 718658800, 435637887, 3210680274, 1063082402, 1055065490, 1065353216, 1058203764, 1057598177, + 1059599164, 1063897802, 1064184204, 1053699367, 1062333553, 1063954077, 1055498990, 1056671481, + 1056789418, 1051470807, 1056997914, 1064777577, 4272203610, 42802532, 4240738701, 268435456, + 4141263870, 262322266, 21834126, 4204507522, 35497600, 4224179524, 37337168, 4264372026, + 4174983159, 4252052733, 4126997501, 40900363, 3217633372, 1070149724, 3223308094, 1070699598, + 28774162, 972490496, 4080658440, 3773923306, 3212096687, 1064487750, 1065353216, 268435456, + 3198645187, 1051161539, 0, 1065781652, 2155904896, 2155839615, 2155839359, 2155904896, + 3215758969, 1068186956, 1026691050, 1028905985, 1065353216, 1034275852, 1037151867, 1016549678, + 1057361643, 1024639618, 1012170274, 1047150030, 1061770130, 1040998679, 1041135878, 1024938515, + 1028448923, 1033626658, 4254324992, 34766840, 4254684670, 268435456, 4141953961, 252128093, + 34978502, 4053006291, 31771066, 18528551, 23313140, 4264588030, 4184410713, 4275689192, + 4081945602, 29059742, 3217443012, 1069959364, 3214400132, 1062965875, 0, 1072919447, + 499817044, 3122988005, 2131313759, 4283023270, 505398308, 1006951474, 1276018921, 20137532, + 3213356089, 1065802849, 1059157879, 1065353216, 56775295, 268435456, 3214764151, 1067280503, + 0, 1067079640, 3783295134, 2153378175, 3598679841, 2144370765, 2149635199, 2145681413, + 2273365376, 2131829120, 3217173204, 1069590142, 1061047259, 1051953679, 1062346374, 1049271159, + 1058207950, 1035803004, 1047395297, 1045345303, 1062020498, 1051235752, 1054641419, 1031692732, + 1062268339, 1065353216, 1057676811, 1033425538, 152312653, 10016410, 4263687146, 98383498, + 4245241401, 91786093, 4275593632, 4274814651, 50365847, 174753486, 4293760701, 210686097, + 103853442, 4026531840, 50473322, 4250147132, 3231651314, 1084167666, 3225066264, 1063301196, + 0, 1074270171, 1357152492, 3472324914, 1049261616, 3752439171, 3209428875, 1061840780, + 1065353216, 268435456, 3228622752, 1081139104, 0, 1075894956, 2139062400, 2139127936, + 3225800544, 1078215617, 1065353216, 1021161895, 1045887687, 1039906458, 1035341205, 1007998557, + 1033761179, 1042703111, 104109880, 4294445529, 203247162, 268435456, 79485405, 4231144799, + 89729953, 4225729829, 3221980600, 1074496952, 3235255008, 1070651960, 236023587, 923382804, + 185587217, 444538377, 4244451626, 3006875415, 190634489, 3112231465, 232450565, 351081984, + 115807221, 2163865082, 316391348, 4034977764, 1048780547, 73714644, 293594809, 172423646, + 4216582241, 132633031, 199507504, 1763838591, 319152363, 36042239, 353178157, 4076866294, + 4079685364, 32379775, 809279936, 220200200, 4108911926, 15995776, 3223356808, 1075790973, + 1055623472, 1049520819, 1065353216, 1050199833, 1060061665, 1050682249, 1065041686, 1056393390, + 99735180, 4294403312, 203354404, 268435456, 78473522, 4234006502, 89761080, 4226118139, + 3221980567, 1074496919, 3230747276, 1083490337, 0, 1083460804, 4289038981, 33557783, + 3812687894, 4284791479, 534557, 2094202789, 234884622, 2314817, 3975604991, 1985544426, + 4285552370, 4177521372, 2916337407, 4294436586, 4293982133, 4293849026, 6137994, 11373148, + 8827332, 7179152, 4283920807, 4282469491, 3044573184, 4279325574, 3500720924, 3724502698, + 378536324, 218129631, 1589251605, 2923482, 2625732352, 1635483289, 3048193791, 3133064491, + 1246320051, 1224781949, 278726273, 1066203, 3528710143, 3621241133, 4137219072, 4025779224, + 1617714301, 4286028919, 2156495220, 2239124224, 2033745858, 2223112065, 1467107959, 1213130495, + 3703432512, 3907102720, 2046854332, 2323590554, 1761635255, 1852845787, 1277787348, 1426090294, + 2152236916, 4284579136, 2278621100, 3906363465, 2257698414, 3147670784, 3370705094, 4294034965, + 2124843007, 2358634101, 3094013439, 3249976350, 2974182378, 778344447, 1057020077, 3225313997, + 1075066648, 3212592491, 3196260924, 3213500530, 3226084450, 3209171433, 1080351107, 1065222879, + 1043134895, 1056982473, 3164775302, 1074460257, 1058287265, 1059104523, 1040100302, 1058387604, + 3202136656, 1053622439, 3201793808, 1039810203, 1053468556, 1060617708, 1040105390, 1060661813, + 3204229456, 1053647001, 3201309818, 1039794910, 1053479764, 1060697761, 3222289422, 1074731926, + 3222191866, 1074635132, 3244611971, 1097128323, 1018853971, 1063265417, 1046654034, 1025556313, + 1046683849, 1031972879, 1065353216, 1056616716, 1062311675, 1020713127, 1024757561, 1050572446, + 1040142628, 1060709632, 1054499736, 1052383914, 1013835328, 1019510270, 1005909834, 1022630294, + 1009332921, 1026530518, 1032064977, 1014968600, 1050578924, 1043502734, 1065353216, 1059894724, + 1057082294, 1057286913, 1048877721, 1059630074, 1060440311, 1052787528, 1058296333, 1055196263, + 1043473054, 1057604774, 1046319764, 1046308794, 1049321193, 1051051414, 1051019001, 1048246837, + 1044786149, 1051066931, 1049728273, 1042211615, 664568499, 3852517794, 3948485809, 2011329916, + 1603951947, 1898186642, 2940163974, 2159812039, 2489623935, 1482900821, 3851419779, 1450054253, + 651996530, 23039577, 1835991187, 1434474427, 3630708846, 1803393189, 4170162290, 2594152821, + 2173534607, 1586732676, 899245924, 1535594381, 2507847030, 2575342696, 646473653, 1583263394, + 2350873691, 3197913724, 2348860562, 2810625450, 1624651110, 862222182, 3260910712, 3247860741, + 2695669133, 1349478818, 3196568328, 1117362757, 3195670063, 538331562, 8485445, 2458399346, + 4051325155, 3031312798, 1408067497, 1872007537, 2339485820, 2766649681, 1773297779, 197543255, + 1382991473, 1566302564, 2291442259, 257437511, 995576026, 2677378603, 2889454466, 2934084761, + 558139466, 1114964328, 1903852663, 2730835776, 2843299423, 2032568964, 2606352896, 1079658155, + 1837915288, 1636468101, 1048676217, 2273979822, 2510796619, 2680202401, 1895804584, 2020047992, + 2522185340, 2359391361, 1016167519, 2171169398, 2390785934, 2221572728, 1063734661, 1719782540, + 389787107, 1971935586, 3531431372, 3902970488, 9404895, 791951232, 1065582190, 2027594828, + 4018630049, 845371264, 2622132571, 1936954768, 1837854866, 1622297962, 1700104870, 2844233871, + 4289278386, 2576857714, 1673039959, 1078567448, 777945213, 2829760922, 1921950842, 209025142, + 1821100691, 1732342634, 1551928179, 2073329807, 1753434300, 2761574726, 2180620268, 1591646875, + 564886879, 628769689, 1095598213, 2311085185, 3818082476, 991690867, 2188619088, 760814718, + 1657034858, 1081703329, 1293315690, 2658751583, 4281974247, 2746329242, 2209829468, 1655726451, + 2491263872, 2578225203, 3079120523, 1654158998, 2172178694, 1401397891, 1269659506, 1464750987, + 1934578323, 2459100296, 908612988, 665653706, 1943890023, 1836606794, 2471462246, 1435457880, + 2434565970, 1985813370, 2571829322, 1667138182, 1783265306, 1644996032, 1667329412, 2575718766, + 2678289807, 2257686878, 826305665, 1399683227, 1164605326, 2560207218, 2943700883, 1627416441, + 2928183716, 2052610705, 1820810877, 1349672325, 1365150570, 1868969557, 2989066486, 2449435852, + 2212196172, 2208389810, 2170914176, 2644169846, 2780596364, 1721715106, 3429543532, 2944491915, + 497179460, 562327737, 2217231242, 2309395307, 2762708596, 1772191579, 1644197236, 1954382762, + 1482530213, 1707777701, 2658908749, 1529818515, 1364239772, 2171352952, 659717215, 2003070003, + 1715239334, 2291506770, 3313131693, 3331428473, 1107333264, 1096533570, 612338556, 2730997879, + 2407363439, 124672141, 2372714398, 1920248930, 1401643651, 1414621831, 2373940838, 2339537799, + 3266871745, 2527824268, 1871343968, 2391508681, 2136771711, 2425124738, 2794096020, 1817405050, + 2054780544, 2238869640, 460746539, 1700266119, 2659742906, 1199330226, 2623241658, 1686276240, + 2709292421, 2177012308, 2579598220, 1384503592, 884700818, 2913690272, 4285908841, 2541981823, + 1820685938, 1986952098, 2305595020, 2156567218, 2086894763, 2164224693, 1350280573, 2324267913, + 2155318657, 2272626323, 2474866071, 2306577286, 2004642679, 2324595849, 2776792204, 2475066514, + 4086325326, 2223785933, 2639182681, 2611699129, 2120530333, 2296013482, 3128854169, 2191185152, + 2225702278, 2892993146, 1585928067, 3682813809, 2289735785, 3581325088, 4287846519, 947170239, + 1781458331, 1892504795, 3317076548, 2863178363, 1807381630, 1901559925, 2509206150, 2878308994, + 2829282195, 2523818433, 2694275464, 2272155580, 3078646144, 1600689546, 1538615459, 2155831162, + 2494601312, 2670439300, 2762043280, 1704198346, 1857003141, 2811202190, 2239397712, 1335416992, + 2977794702, 2105579904, 2743402320, 3163795415, 1082690499, 3638804439, 2361215327, 2339607934, + 2172355975, 2524541342, 3653001616, 1149878127, 1503035806, 2071246485, 1774287496, 1163150032, + 664194201, 2038928794, 1547778501, 2224574672, 1408735745, 2606401120, 3547033958, 2235001251, + 984437180, 1275035287, 1286308216, 2492658254, 1870821242, 2442229647, 1903537564, 1870754941, + 2825936809, 2876151663, 2009431703, 2140774521, 9019259, 2056046524, 3278931624, 2676982661, + 2156370563, 2327994470, 2022082194, 2139190405, 2423555483, 2005235080, 1381346610, 2475129246, + 1687130482, 2809028294, 4284314487, 2492576915, 2087884879, 1984080014, 1753557415, 3412643272, + 2172747129, 2306115202, 1821354293, 2291891140, 3266467459, 2792524435, 2876151417, 2236915557, + 3331229570, 2326044238, 764235894, 745302645, 1853072552, 2315308408, 2307548540, 2388419465, + 2408759149, 2542893218, 4288132139, 3057311640, 3190452391, 2207750026, 1604737697, 1338212006, + 2305999020, 2626022754, 94617478, 1973979351, 2340975983, 2507302040, 799582679, 2557303225, + 848389477, 2292424003, 2272889466, 2808449457, 3692344471, 1907824639, 3187235997, 1537639022, + 1267282303, 2391846485, 2440409986, 2677303124, 4290868784, 3533345474, 1667266117, 1754699950, + 2846134896, 2893380309, 3275074949, 2895121901, 3248474998, 2693498764, 1840019095, 2041813327, + 1332234854, 2673105794, 2709794231, 1351130748, 1216903922, 2393599384, 1803115654, 2578307137, + 15637389, 2306254244, 2891918589, 2758904729, 2912390046, 2292466036, 2341700214, 1618448029, + 3091800676, 1871217648, 3132195702, 2309579911, 2192078909, 2358675344, 4087836310, 1925160229, + 1702982291, 1935443859, 2389421556, 2147515808, 1887540100, 2406974570, 2509137503, 1832619112, + 2643431322, 1598902911, 2639357627, 2678109317, 2022871910, 2639102574, 2946135203, 2306184411, + 4292839829, 2156685908, 2140111493, 2475851889, 3735453473, 1954715831, 2806226529, 2090248378, + 3480455291, 2441002029, 1845436284, 2391455836, 631152474, 1385927029, 2574659475, 2656407035, + 2156351347, 1918328504, 2825937062, 2459596224, 2335531473, 738155999, 2977601869, 2291899023, + 2372766097, 2103341952, 1852599424, 2994681992, 2189839693, 2256957807, 2427211126, 1277322930, + 1921489544, 2323491912, 2209899672, 2307096428, 2259242838, 2220138113, 2241296757, 1500817473, + 1957078648, 8227951, 1986815475, 2117639831, 2307619732, 1013930451, 1789254803, 1720820107, + 1733022046, 2257684118, 863032980, 2341213886, 3997592466, 1836405101, 1735023472, 4282354544, + 1433101673, 1974504837, 2777867655, 2210243374, 1717270152, 1651997282, 2382411133, 2023322747, + 2406974098, 2714407307, 2291962253, 2207368520, 1672191621, 2105639577, 2140333671, 2373933443, + 2558493575, 2105506942, 3330950281, 1620944748, 1671652018, 2509918329, 1983416169, 2506859617, + 91914886, 1904436479, 1667772046, 1551459964, 2237887616, 1909760116, 2358273642, 2425252731, + 2009841151, 2119724184, 2497432604, 1887937140, 3284238028, 3352400350, 3784806523, 2493891190, + 2057677978, 3212880790, 2760887739, 2375461570, 2087878758, 2357428078, 1855167414, 2457700461, + 2679138438, 3312029554, 2778427808, 1921892463, 2674760070, 2408419203, 2457415360, 568428946, + 2155850840, 2474442604, 2206041469, 2256829052, 2980346183, 3296957558, 1845101207, 2041877138, + 2995553142, 2103545468, 3727524472, 2071330994, 3482086301, 2747944309, 1836126321, 1736956429, + 1788306043, 1851818408, 1448963224, 1905502110, 2258901418, 3127799642, 1010935142, 2553976430, + 2805379, 2286886398, 1754674858, 346979953, 1485202367, 1865913876, 1803596404, 3167405100, + 2423094156, 1216896886, 3620259500, 2023517184, 2486668157, 1968008274, 1837657488, 1303209605, + 1720942461, 1886219400, 2637194363, 2323478119, 2764869281, 2731451953, 2527764272, 3565375071, + 3801765506, 2811454897, 3733613451, 1285406240, 2927389308, 2574161686, 1909065339, 1257138029, + 2003752960, 1333243953, 2206826627, 2492042123, 2254529200, 1232439698, 1538835364, 2086111144, + 2812959366, 1705864482, 2798606238, 2090968681, 837078406, 3889384325, 4285983289, 1723232094, + 1885428632, 2809360227, 1754572122, 1853635679, 3023722913, 1315798156, 2506991773, 1835451711, + 80638087, 2105304194, 11650885, 317419611, 2020185936, 2558893149, 2657266294, 2427094874, + 1687124605, 1871847046, 4289020067, 2137431947, 2561439348, 2321382753, 26897287, 2526913259, + 2558761841, 1169920111, 1651409867, 2509404587, 1920562046, 2153939061, 2206237313, 2055761018, + 2374008953, 2156102543, 2566879361, 2458752394, 2190049123, 2040824450, 2559347083, 2072413838, + 2358805891, 2239923079, 2036040308, 1834441114, 2188640313, 2559985312, 595626069, 2358869599, + 1113059702, 2005775570, 663205003, 1490419842, 1538276337, 2359362249, 144211266, 1476382635, + 4283924304, 1398810467, 1665624433, 3674102865, 2102554327, 1793952374, 1697020347, 3623840399, + 507014290, 4015588002, 4102766485, 2188574614, 4184647093, 12565813, 2589606060, 2880976588, + 3092084854, 1919615043, 2407818401, 2355847818, 1466388374, 2893699445, 4287650192, 2682440947, + 3032968494, 2441580745, 331672135, 2281650802, 946546176, 3333840329, 777297720, 3666491502, + 2067695299, 2290970672, 3143852181, 2967118335, 1734882676, 2710394783, 1351904126, 2533309644, + 1213661310, 3400227014, 2506778203, 2498938518, 3966583463, 3165672265, 2995290506, 2720565503, + 2071985789, 4290723046, 793284424, 2476279467, 1586669921, 898872401, 3097648842, 2924916991, + 2664675715, 1720704502, 1689033544, 1811906626, 3631567484, 1836091391, 2323089544, 2000721252, + 2247229315, 1586407851, 1250466445, 1801462175, 1744992383, 2777372160, 1182739562, 2306646391, + 2090925984, 2105173084, 1701613488, 2139501442, 911638912, 3422566012, 3749539704, 2276829794, + 1939767427, 1620676772, 946902380, 2248121216, 2610194533, 1586134932, 2240052874, 2291597436, + 3187644792, 1686750115, 3985414089, 1817865409, 3752624895, 1972272751, 2438876306, 1305576587, + 2891907168, 2591597368, 2122623655, 2072084307, 2336865123, 2122421882, 1685957525, 2054422674, + 3852140421, 1168156556, 495104830, 2523061444, 1576093616, 3483697064, 1147438184, 2524921231, + 136353382, 1754233523, 2650834853, 2186106696, 2392561663, 1787069550, 2454739352, 2527766450, + 2492661645, 1988661635, 3211819915, 2424985237, 2550100370, 1905570748, 1469178464, 2126873195, + 4287600001, 748859502, 2725612185, 2453880203, 2240263, 3124046773, 869563669, 741078535, + 3049500519, 867303291, 2610680710, 1807182475, 918561342, 4289752498, 3685772069, 1611128164, + 1212954239, 4286011820, 2105638244, 1921498220, 2877280924, 1485674044, 4017190655, 2675587998, + 2714017144, 1570823069, 2056322963, 2124050043, 2207805520, 2289864077, 2030007920, 1568311705, + 2054395541, 2239398260, 4286079392, 2303579316, 3060898463, 1434299205, 3616174523, 2475919871, + 1902734747, 2875484803, 2910291327, 1972633477, 2358931881, 2122089881, 2223284839, 2097123714, + 2188937080, 2105835908, 2086109828, 4285825416, 3192921485, 1050361065, 3149442914, 3173197302, + 1037782725, 3187674054, 3164118800, 3183141576, 3189952724, 1044421715, 3201875109, 3177659050, + 1050895976, 1044914407, 3168333641, 1039378144, 1040605494, 3163432228, 3135079793, 3164590230, + 1043384252, 3178235543, 1032465731, 1044157367, 1036501142, 3188284441, 1044854541, 1034367409, + 1021915983, 1037486838, 1042596344, 1046247190, 1020602714, 3172857184, 3129006688, 1016232172, + 1045239576, 1000549393, 1044332255, 3153009832, 3164132227, 1027230476, 3181471787, 3173886868, + 1034451663, 3179158457, 1027464034, 1035937807, 1035188122, 3159962702, 3171375809, 3170699076, + 1017801649, 3184143065, 3187586170, 1024206755, 1028312176, 1012618346, 3188786352, 3164042932, + 3174102485, 1010228461, 3170123796, 1040484782, 3214324696, 1066763888, 3216805445, 1069225256, + 3218652853, 1071169205, 1049280423, 1057432742, 1052109265, 1051681762, 1054449020, 1058721350, + 1057279938, 1055801093, 1053061115, 1056951644, 1052473492, 1060135014, 1052207066, 1056045540, + 1058690379, 1058826097, 1058774173, 1065353216, 1055732099, 1053593733, 1049633656, 1058880465, + 1050200571, 1058529665, 1057527702, 1055503162, 1058115414, 1056578272, 1053780662, 1054380386, + 1056587649, 1060688885, 1042342730, 1048951067, 1046894810, 1043779977, 1045184334, 1045914358, + 1049030559, 1044217903, 1042643026, 1040873705, 1051469012, 1043758119, 1043096432, 1044338477, + 1046704522, 1057177562, 1059910484, 1052321435, 1049598651, 1051672173, 1052643463, 1057068400, + 1057386300, 1056872040, 1055353794, 1053994202, 1056377358, 1059403121, 1055129778, 1053611548, + 1050304537, 1051391390, 1050729375, 1043419892, 1051683707, 1051346709, 1057231983, 1053953866, + 1057208394, 1057470769, 1057945889, 1049189026, 1056858721, 1054339242, 1056642004, 1047977704, + 1043059641, 1052368054, 1058985543, 1057019953, 1055259290, 1055945398, 1048805676, 1051124621, + 1051592439, 1057863834, 1057116710, 1054444755, 1063910970, 1057094826, 1052418100, 1057937273, + 1059248393, 1065353216, 1048804560, 3185291693, 1025908581, 1033674267, 1051581933, 1023556120, + 1053094595, 3191215129, 1049974622, 1040061732, 3200393118, 3171525095, 1041427861, 3184434773, + 1034245222, 1056311756, 1049421916, 3186716727, 1027578547, 1033514613, 1050904216, 1023433328, + 1053224405, 3190993738, 1049792849, 1040263798, 3200408458, 3174788296, 1040909677, 3184933853, + 1034801299, 1056205315, 1048740389, 3185945367, 1027096001, 1033518483, 1050911102, 1023525341, + 1053166523, 3190866728, 1049843228, 1040262875, 3200418679, 3173290273, 1041179054, 3184843676, + 1034700573, 1056224759, 1052889451, 3176787866, 1033254425, 1028869836, 1048572213, 1029353719, + 1052666657, 3193738664, 1052763995, 1046318562, 3202334486, 1027901893, 1034301420, 3174503463, + 1017900318, 1053767903, 1049600826, 3186785523, 1027690261, 1033511426, 1050939484, 1023463786, + 1053234294, 3190967774, 1049779951, 1040264022, 3200404486, 3174932263, 1040909628, 3184957422, + 1034902337, 1056199452, 1054747671, 1048556656, 1038104318, 1049578907, 1042091268, 1043216411, + 1048962383, 3203133199, 1060771770, 1048595059, 3200929790, 1050798585, 1054344707, 3196602082, + 1040890332, 1053046357, 1055314630, 1037007426, 1044627343, 1037030715, 1044562077, 1023130230, + 1051007002, 3199216663, 1055861620, 1045085893, 3204442143, 1043629937, 1047882651, 3190452213, + 1045815687, 1052791152, 1048788442, 3185844267, 1020147462, 1035591326, 1051759383, 1018915504, + 1053207216, 3191072651, 1050002662, 1037627062, 3200377532, 3172064120, 1043531622, 3185416242, + 1034484760, 1056201486, 1053144311, 1046505694, 1043580973, 1048003100, 1044329971, 1040235301, + 1050105113, 3201697133, 1059079422, 1040566911, 3200435763, 1051398765, 1054941283, 3197659688, + 1044411666, 1052736963, 1052315481, 3177696990, 1030821663, 1024453082, 1048601381, 1029482796, + 1052795162, 3192963814, 1052760199, 1045368875, 3202081594, 1028069864, 1037530343, 3171413960, + 1022205153, 1054253923, 1048740611, 3185946228, 1027103046, 1033519507, 1050909715, 1023526061, + 1053166038, 3190867119, 1049842451, 1040262775, 3200418635, 3173294269, 1041182263, 3184843374, + 1034701044, 1056223654, 1054946951, 1040402333, 1044992385, 1032812002, 1044543342, 1026727805, + 1050973261, 3200131301, 1056597488, 1044450159, 3204433702, 1044198874, 1048575831, 3191577062, + 1046335570, 1052801722, 1054347662, 1016360477, 1002906328, 1042447931, 1046642803, 1020164943, + 1051013950, 3197183318, 1053269336, 1040168883, 3201511433, 1039991075, 1041241310, 3188775012, + 998590031, 1052781052, 1048801965, 3185321191, 1025880319, 1033672879, 1051588219, 1023545455, + 1053096843, 3191188872, 1049970202, 1040042984, 3200388753, 3171548301, 1041474719, 3184522763, + 1034274156, 1056306627, 1048803738, 3185303679, 1025916459, 1033671493, 1051589245, 1023550302, + 1053095205, 3191205518, 1049972744, 1040056530, 3200390051, 3171535558, 1041428489, 3184459050, + 1034253166, 1056309954, 1048741022, 3185945886, 1027095312, 1033521027, 1050907722, 1023542225, + 1053165405, 3190861107, 1049842370, 1040262637, 3200418788, 3173301900, 1041186166, 3184842760, + 1034706339, 1056224067, 1053869342, 3127512505, 1024996818, 1043990911, 1047459464, 3161285106, + 1051222430, 3196783860, 1053042619, 1040807468, 3201820065, 1036247490, 1038177433, 3192238802, + 3173248855, 1052807282, 1048803978, 3185303758, 1025907683, 1033672508, 1051583682, 1023551349, + 1053095313, 3191206554, 1049972348, 1040052672, 3200389924, 3171538479, 1041442877, 3184463777, + 1034257469, 1056310231, 1053099215, 1048580319, 1048546298, 1036050993, 1044195755, 1042029972, + 1050802387, 3200684577, 1056967500, 1032944341, 3200728736, 1048480881, 1053911185, 3199168533, + 1045044239, 1052859716, 1053139253, 3173608426, 1040070117, 1040375963, 1048481674, 1006215897, + 1052039741, 3195487250, 1052937466, 1046147773, 3202436649, 1032550147, 1029804498, 3183157896, + 3155508970, 1053178710, 1048788660, 3185845839, 1020139252, 1035596246, 1051757084, 1018911059, + 1053207294, 3191072447, 1050001824, 1037626526, 3200377901, 3172073827, 1043533047, 3185415945, + 1034488983, 1056200475, 1057050333, 1056977221, 1056977431, 1056958485, 1056977128, 1053883009, + 1054227116, 1056977358, 1053350793, 1056963731, 1056977436, 1054248788, 1054168123, 1057020633, + 1057035059, 1056977444, 1054276350, 1057037694, 1054104363, 1055709861, 1056977364, 1056997344, + 1056999324, 1056995738, 1058913159, 1056999126, 1060093628, 1059669266, 1056969999, 1059844912, + 1058553794, 1056995694, 1059760434, 1057642937, 1056996722, 1056997432, 1056995490, 1058035519, + 1056997489, 1059948186, 1059115777, 1056970003, 1055263074, +}; + +uint32_t* get_knSmallWeightsArr_addr(void) +{ + return (uint32_t *)(knSmallWeightsArr); +} +uint32_t get_knSmallWeightsArr_size(void) +{ + return sizeof(knSmallWeightsArr)/sizeof(knSmallWeightsArr[0]); +} +void get_knSmallWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knTdfusionWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knTdfusionWeights.c new file mode 100644 index 000000000..3af58bdd5 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knTdfusionWeights.c @@ -0,0 +1,103 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION "972f84" +#define NET_SIZE 660 +const uint32_t knTdfusionWeightsArr[] = { + 3212611938, 1065258623, 3617523296, 2162511128, 4131723467, 1527300999, 887990279, 3918715738, + 2480362861, 3730469607, 1029234836, 2145880517, 3970754097, 2715757948, 4064179679, 526442413, + 2145558227, 391976699, 1982203525, 436306985, 4069992803, 2536996647, 688713366, 233739891, + 4003299118, 2792368142, 2049378544, 4212064112, 469195904, 3948908051, 1283651068, 2804756219, + 3971016001, 2950776433, 4014961387, 980150967, 2146612193, 2378490593, 3740128150, 3368265385, + 3196879020, 2358032584, 1376779692, 201965695, 4256264260, 3127921936, 1832646897, 738910080, + 149328250, 3699668773, 2926913799, 1780024303, 29815781, 3270699898, 4159469820, 3882810571, + 2147071461, 3535603583, 3422513411, 208933092, 1459739079, 417579508, 1836664083, 1950817094, + 1208695137, 542735743, 1013215306, 4011265337, 756827264, 356291078, 579794208, 2180390667, + 4147116677, 889161640, 4068518653, 2461269549, 2750951680, 1784487883, 1495652694, 566708571, + 3513548648, 1499616800, 3771399551, 3472718809, 4252426725, 1675880140, 3655386865, 657127552, + 990480146, 4068483382, 2434083370, 270870783, 3908377471, 4162091734, 545120498, 1826878974, + 3942449430, 385548722, 4043026548, 4172312072, 3144619256, 2132144119, 3319262829, 3857802634, + 4117666522, 1300285149, 2497506027, 3498104382, 2363970633, 3981463001, 791726732, 1423737806, + 4138070857, 2616152426, 5599732, 962590379, 2146997472, 69802038, 554907288, 473202934, + 613611815, 2365729042, 3202834563, 1055232450, 1053719888, 1059090724, 1057983160, 1057969890, + 1059453812, 1058076083, 1065353216, 1054161397, 1057260716, 1059049657, 1060082832, 1061889815, + 1055607626, 1060608896, 1058153065, 1057984122, 1058853086, 1059251060, 1062777282, 1059241884, + 1060068278, 1059947500, 1060536208, 1058981408, 4218380337, 76645242, 92193286, 4286382364, + 4222173552, 73206578, 61404453, 5087134, 130630953, 34882024, 195397210, 100948017, + 55848049, 4282024932, 4252891870, 15052396, 4110485541, 5833540, 4128022358, 84887271, + 27454738, 19672006, 268435456, 4290268269, 3222835871, 1075352223, 3219083795, 1071948612, + 3847318036, 4149351411, 1042608640, 4241424389, 1169676, 41892885, 754781668, 4077415324, + 1443004665, 64124697, 3424421139, 2033189440, 3625913566, 4279215449, 3157622331, 202604798, + 1624076732, 2366241729, 635677627, 144893213, 2365607717, 271374087, 415334333, 3554714847, + 3613490983, 4251584762, 908457727, 4174838269, 34920466, 4201466639, 2943439845, 220969796, + 3934219339, 4262693618, 2057455500, 2402427857, 3214281534, 1066721064, 1063059484, 1059221280, + 1058618575, 1057029081, 1065353216, 1062902409, 268435456, 100614101, 4119414, 45803078, + 172138338, 139002063, 3232098395, 1084614747, 0, 1093498247, 2139035010, 360754955, + 3892412284, 1786781818, 32792, 3205643615, 1058085092, 1056665721, 1056607902, 1052747214, + 1065353216, 1059130712, 1054818331, 39734082, 4958179, 99819138, 4290807485, 219101839, + 268435456, 3211494812, 1064011164, 0, 1069137558, 1309798250, 892473216, 2160972874, + 3478204976, 612401338, 644545293, 4215293055, 92337285, 527234768, 2149267420, 461360869, + 47911167, 332693540, 1655763692, 2150087757, 1388683645, 3548369792, 312037621, 2148552851, + 3034586709, 2065326208, 192945120, 684379027, 2131759574, 690709404, 1048608638, 643168780, + 3712948484, 3916726482, 3934281964, 2150839532, 4253010515, 61762815, 667332735, 2214195340, + 1896503424, 3209498059, 1061909423, 1059568812, 1059914863, 1060362191, 1059743562, 1049970827, + 1059229476, 1054063820, 1036700918, 1065353216, 1056876281, 1057223109, 1064236493, 1042844160, + 1061310954, 1040019615, 1043433319, 1054712508, 1064020964, 1058532813, 1059921160, 1056477006, + 1058117930, 1055425540, 1062810102, 37046165, 26912831, 38633761, 192615279, 4057022527, + 260426158, 4174981607, 16338171, 172007841, 60254168, 132512852, 159680009, 153958387, + 27668950, 35015901, 10283278, 4026531840, 4276553097, 4150136022, 4277211435, 113051432, + 4277010931, 176798831, 11770706, 3209451696, 1061968048, 3217396375, 1073235696, 0, + 1075216046, 2589542181, 4130832428, 1769483067, 536147731, 1812325179, 4218569462, 3886785318, + 111139857, 2136068932, 4246729745, 1138602473, 4199765479, 66251813, 167772955, 654956026, + 268790271, 554827504, 2130907144, 1409092038, 201424855, 3855612635, 251203096, 3689880391, + 15517027, 3216946354, 1069365065, 1056224245, 1057011242, 1065353216, 1059493660, 66752937, + 43823882, 4286504935, 268435456, 3233157097, 1085673449, 0, 1087817967, 2155869080, + 3865078543, 1863286912, 3199191604, 1051617952, 1064200395, 1064806055, 1065353216, 1061995188, + 202397346, 88436791, 268435456, 4231180105, 3208254580, 1060770932, 0, 1063501116, + 2149656320, 2140860138, 2475332224, 2149451784, 2999943421, 3186348159, 1397718988, 357203980, + 2151392567, 3262021590, 2163153126, 3498095116, 2148458943, 3672342716, 3390996725, 2148861256, + 3210841781, 1063242648, 1057702199, 1056434892, 1060328997, 1058650920, 1064803264, 1058061423, + 1055484575, 1048649563, 1048732415, 1060605520, 1054827205, 1061463810, 1059535748, 1064123227, + 1050558390, 1065353216, 39125836, 8308965, 268435456, 4196329345, 120011066, 178151569, + 4120159351, 30903888, 96699096, 47082552, 128482097, 137204766, 41517027, 209572119, + 100585998, 4218278974, 3208645219, 1061161571, 3212574289, 1057583986, 3101417194, 1910704255, + 671415072, 3781349858, 3809014548, 3489075995, 76872203, 562046730, 3974351119, 2566323404, + 111628873, 3925342231, 25204455, 133891543, 4026718202, 123141, 117113948, 3792179709, + 4009753615, 622197517, 4261474305, 2150043818, 138018824, 267325439, 3891386769, 371328136, + 3876063781, 70178823, 176217477, 3574661077, 3658874068, 3774877275, 316992697, 4091661604, + 3997008078, 3239695623, 3744413510, 209700031, 368514030, 3584890339, 3775735330, 1124872214, + 522855590, 3058694370, 4196544813, 1861159807, 858331476, 154586635, 4227858600, 4127195059, + 4211086363, 336460827, 4155702783, 17554304, 253238836, 4111139577, 301274386, 4175134974, + 3220578817, 2281509384, 2837587698, 2133719409, 4024891079, 3849053191, 2339767003, 3908561175, + 99408813, 4131449622, 2752120850, 793885212, 864068551, 2937064421, 2989834508, 1865153543, + 333765581, 25151516, 3154228756, 3810464800, 3679143141, 41934025, 3860207403, 4022778355, + 3788257284, 3189838290, 636283015, 3644194268, 3875797538, 2015765631, 728899429, 405248445, + 4067389132, 3796898541, 875697669, 4007587113, 206145663, 4180940073, 3206335898, 1058771967, + 1051744912, 1056748872, 1064885359, 1065353216, 1053842087, 1055410824, 1058972379, 1053415483, + 1059904337, 1060228162, 1051466587, 1044711996, 1051976878, 1050109657, 1049776781, 1049085545, + 39125836, 8308965, 268435456, 4196329345, 120011066, 178151569, 4120159351, 30903888, + 96699096, 47082552, 128482097, 137204766, 41517027, 209572119, 100585998, 4218278974, + 3208645219, 1061161571, 3219098210, 1066109165, 0, 1068318313, 41932027, 4059443515, + 1677903092, 335291124, 4108645116, 31489797, 3842633475, 1392184594, 343887112, 48696183, + 537368838, 755713804, 4201609210, 340980351, 1173430071, 873352969, 3209216526, 1061630090, + 1060547205, 1065353216, 1061679052, 1060891602, 161590128, 268435456, 16818885, 4074195822, + 3209148838, 1061665190, 0, 1058811013, 2192736105, 523206570, 1694400383, 3203421606, + 1055814907, 1060445619, 1057678818, 1065353216, 1061395905, 4026531840, 261082239, 4102204708, + 153547185, 3199029727, 1051546079, 0, 1047340345, 3484858496, 3208897370, 1061313427, + 1065353216, 268435456, 3195868160, 1048384512, 3189408565, 1019949519, 1050158899, 3439443480, + 2150045672, 197595717, 3194796882, 1047192027, 1065353216, 268435456, 3195868160, 1048384512, + 3196364223, 1049228302, 3201412083, 1049498757, +}; + +uint32_t* get_knTdfusionWeightsArr_addr(void) +{ + return (uint32_t *)(knTdfusionWeightsArr); +} +uint32_t get_knTdfusionWeightsArr_size(void) +{ + return sizeof(knTdfusionWeightsArr) / sizeof(knTdfusionWeightsArr[0]); +} +void get_knTdfusionWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knWeights.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knWeights.c new file mode 100644 index 000000000..530908869 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/HRNet_knWeights.c @@ -0,0 +1,494 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION "9b33ee" +#define NET_SIZE 3785 +const uint32_t knWeightsArr[] = { + 0, 1065353216, 1434415440, 3351367097, 3203343047, 3996637372, 753911254, 2138535512, + 84213308, 16515587, 16711937, 67044610, 1274795660, 4063526733, 89448655, 1604838906, + 3570273057, 3673628519, 4178592570, 4096032991, 748012506, 2630870016, 1532910975, 3671764372, + 3871288544, 3676367322, 251191529, 2071951937, 100925011, 4277928708, 4294836481, 50202112, + 1667971993, 215992283, 3754268656, 3129011197, 2549019357, 1585404863, 4025365306, 3946244060, + 4141211634, 3267549393, 1008870735, 4261205631, 4191102728, 3306487038, 587069927, 689579873, + 1131577175, 593414942, 1906305798, 3307682902, 1753164268, 3084272421, 3460633505, 906604490, + 163888085, 1769308007, 85075763, 219799553, 519377423, 3422422795, 3598761530, 591288368, + 775832607, 1429211402, 1027740691, 2055175477, 134480222, 33358854, 16974852, 50333696, + 470619446, 660370489, 2138884607, 704002654, 3792108561, 33701759, 3822849123, 3927428072, + 281737460, 3992910321, 668725, 960800107, 494948162, 2924229939, 874589993, 1731137718, + 3859627117, 4264919758, 897635300, 2713708809, 3433244799, 3924800895, 3754496213, 3690391271, + 98691565, 1333746616, 4008049886, 3791379452, 3235514612, 3641249263, 2138927963, 151454264, + 67109892, 16974596, 67044866, 605963391, 3993224586, 3921497080, 3376352731, 621993445, + 570493056, 83754595, 4244635909, 16909317, 4261675515, 67249257, 721280, 151062265, + 4261675006, 50396167, 536216704, 50265706, 4244635908, 16909315, 4261675516, 2138928985, + 151520060, 83887364, 17040388, 50267906, 3196109652, 101578890, 182519042, 3959425282, + 4278911494, 519110528, 50199663, 4227858692, 16909315, 4261675771, 673202047, 67895436, + 167576827, 4211276800, 16711431, 472335659, 16810181, 4203354119, 2518352120, 336264693, + 1141882299, 32868991, 228073983, 3273784573, 316932108, 1245525888, 150800247, 50200584, + 4228188682, 4244898298, 3205400190, 1057843569, 1051880702, 1059676744, 1049259402, 1060052437, + 1055020755, 1057827188, 1052907982, 1049730549, 1065353216, 1057459505, 1050478146, 1060210126, + 1052574825, 1057304205, 1059726057, 1063639454, 1056580671, 1055525787, 1060223832, 1051350660, + 1058004196, 1051071279, 1062226207, 1064255926, 1062626364, 1057282324, 1055887615, 1062951340, + 1062360791, 1059729071, 1060067346, 1057731230, 9161327, 10526901, 43422303, 9485563, + 41803343, 4294635580, 4292301081, 4274504488, 4195907515, 4219429007, 4288203897, 4026531840, + 30825373, 4294757832, 4166827529, 46857534, 4198791116, 4262733151, 118893346, 171801131, + 4294564035, 25526358, 4294787832, 8983822, 10268871, 4292587228, 158000286, 13071751, + 5889193, 4242993919, 4887071, 4284791625, 3219083317, 1071599669, 3217134032, 1074269162, + 2339510357, 88873257, 307413200, 2898794811, 4092285364, 1026044696, 1025972272, 595650864, + 3196990560, 1049434103, 1065353216, 268435456, 3182844497, 1035360849, 0, 1054323930, + 8352613, 3210990908, 1063390610, 1065353216, 268435456, 3163181674, 1015698026, 0, + 1049599547, 2155839359, 2139062143, 2155839360, 2155904896, 2139062144, 2139062143, 2139127679, + 2139127679, 3213540494, 1065985813, 1057473554, 1046078985, 1038063497, 1052024304, 1062027445, + 1050042712, 1055203246, 1060185951, 1039872910, 1011210069, 1052894683, 1058990529, 1060836525, + 1049612578, 1019225221, 1052987007, 1018348850, 1049129878, 1058045751, 1065353216, 1049146658, + 1052832425, 1047529212, 1056047898, 1040430600, 1049504790, 1045728632, 1034072413, 1056028951, + 1055569312, 1063279769, 1054760983, 2675335, 4279234232, 159966472, 26495218, 47519821, + 4269580843, 4286472679, 4268959478, 4192771977, 4136174506, 4256190768, 4048039037, 37488583, + 4265867410, 4150755620, 3243417, 4209197714, 4255026235, 167212860, 244707265, 4262454931, + 4231277358, 4263575242, 4210334825, 4271573380, 4261256193, 268435456, 4279326833, 4255241798, + 4275865985, 10400569, 4239275707, 3221055281, 1073571633, 3199607868, 1059150472, 0, + 1073986285, 3523547710, 492769315, 3631283158, 3623489547, 97218291, 488975376, 1023610933, + 293633295, 3372683323, 897519912, 3628005334, 3355316757, 568093940, 605038098, 388109078, + 366497565, 3214867883, 1067302832, 1061394933, 1065353216, 4248330033, 4026531840, 3210004081, + 1062520433, 0, 1081256487, 3373367076, 32726, 3220023190, 1072417863, 1065353216, + 1055355484, 4026531840, 4232649325, 3183036248, 1035552600, 0, 1087045902, 3347037567, + 2138013442, 1182775423, 2135064326, 2136834043, 2131197567, 729776071, 2150072107, 2132705046, + 2135392277, 2137709439, 2152038219, 3984555800, 2131787745, 377454695, 863993471, 3217283376, + 1069699454, 1057712315, 1045552883, 1060285497, 1042191652, 1057697333, 1051273551, 1063050070, + 1060025580, 1058489437, 1040039088, 1058827350, 1045998986, 1054705396, 1053634695, 1039585905, + 1057402790, 1047376809, 1062204734, 1054315075, 1055785080, 1051511512, 1059948804, 1061866074, + 1062200059, 1064458341, 1054806373, 1061681649, 1065353216, 1059313265, 1060591972, 1046683460, + 1064059637, 4266030383, 4209406849, 185817147, 4226083433, 4166288488, 4167548973, 4243454620, + 157855982, 4256885829, 4239438983, 4234790590, 4190665592, 180042663, 4212531041, 4151507061, + 4274908273, 4233993977, 4239727313, 4229694039, 268435456, 4233083733, 4234193284, 4236595608, + 9145795, 4246362324, 4230425104, 231464088, 4251256872, 4267769565, 4263176546, 4187261452, + 4234519177, 3221647262, 1074163614, 3217060075, 1090861692, 0, 1091707269, 1040741947, + 1048808124, 1057711802, 1032713374, 1045761609, 1033968854, 1056653562, 1030238034, 3190596828, + 3175940054, 1045915392, 1049372314, 1042353611, 1024005112, 3172578050, 3166062809, 1009918109, + 3189752244, 3186697718, 3185900458, 3188332162, 3190607857, 3197900674, 3204666439, 1044012262, + 1033742925, 1018605985, 1007559260, 1035801005, 3188154740, 3186467670, 3184812311, 3189707105, + 3191670656, 3197298679, 3203390151, 1026002027, 1052768620, 1054690950, 1047520794, 1053416749, + 1058270736, 1048731709, 1057097861, 1053568205, 1058744234, 1059788196, 1057446300, 3187745983, + 3191669450, 3180525627, 1048516154, 3183704082, 3177312500, 3193711037, 3188848784, 1050480169, + 1034032306, 3153120472, 3181264804, 1037858285, 1050031708, 1050403289, 1049239935, 1051943237, + 1058045308, 1046263180, 1055335407, 1051307245, 1056083494, 1054470285, 1048823404, 1033285919, + 3180971794, 3190722769, 3179771536, 3181543508, 3192951105, 3196517277, 3190928796, 3190311018, + 3194661358, 3192662829, 3198179307, 1041693229, 1050147675, 1052000771, 1048628471, 1045765490, + 1056234451, 1044636996, 1054333560, 1048870424, 1053262673, 1048646443, 1033731710, 1047899334, + 1034083791, 1021983732, 1030501642, 3181614850, 3181058350, 3175965499, 3193443094, 3182900056, + 3184903704, 3196776671, 3204248758, 1031044787, 1032164170, 1033342675, 1046389031, 1036111006, + 1051211915, 1052195343, 1045232482, 1040484036, 1022957741, 999050757, 1032297980, 1035018905, + 1039173093, 1008567407, 1031219471, 1047153565, 1054079503, 1052703577, 1051770945, 1049469277, + 1045379628, 1050180309, 1048072428, 1042869941, 1032280923, 3183770758, 1045196044, 1053938407, + 1037410513, 3171056753, 3169942607, 1047597966, 1048009717, 1018768274, 3170413963, 3195849933, + 1060031352, 1057968159, 3206056283, 1043641844, 3205067950, 1064874907, 3201285836, 1052950732, + 3195851856, 3201177225, 3196024570, 3185962127, 3193669732, 3193630056, 3183205929, 3210556305, + 3183698341, 3196503943, 3186374934, 3193745017, 3166043374, 3155191174, 3168556185, 3196181302, + 3190350652, 3190738510, 3173742834, 3208835764, 3181527136, 3185178547, 3184672776, 3192990837, + 3182316922, 3148877710, 3178591975, 1030589143, 1032638069, 1019960454, 3181643975, 3205500217, + 3184980257, 1048691378, 3182148404, 3154478931, 3185306835, 3188795782, 3204092769, 3191233978, + 1040955888, 1037969419, 3180255434, 1041176333, 3179735109, 1051016867, 3178002427, 1030626596, + 3185747051, 3192677626, 3177896292, 3190197211, 1043168692, 1036803373, 3181368042, 1041076601, + 3182896773, 1055883899, 3184938154, 3173189715, 3181700490, 3180218114, 3179472731, 3193605478, + 1050008406, 1044239490, 3183168768, 1054950031, 3179079157, 1057706757, 3177159222, 1047048191, + 3172427695, 3181378070, 3182211528, 3179308287, 1049247720, 1047003074, 3187948517, 1058058382, + 3184595436, 1053255558, 3183047827, 1047806870, 3163086692, 3183113712, 3172847479, 3188336851, + 1052968218, 1051150232, 3184804919, 3203456545, 3180339830, 1054982198, 3175466481, 1046553641, + 3175040933, 3184722079, 3179450188, 3178610927, 1053873814, 1050698090, 3182624197, 3193831263, + 3181136551, 1054367580, 3179056051, 1043898042, 3183333077, 3182470569, 3177211587, 3187353615, + 1053152539, 1051499990, 3181028841, 3197813164, 3176909008, 1057388017, 3173917452, 1051836299, + 3191507571, 3186073975, 1025832471, 1031965039, 1057274332, 1057347839, 3184023873, 3195393259, + 3183170660, 1060070660, 3182975462, 1050487678, 3188109676, 3185711351, 3161210356, 1034084290, + 1059804817, 1056323207, 3182014578, 1046061682, 3180555569, 1064843759, 3178392758, 1049634804, + 3187719019, 3192537479, 3167469516, 3191320000, 3182980979, 1044964981, 1041456033, 1047374599, + 1041595198, 1037313357, 1033306300, 1024480654, 1032790860, 1048600022, 1045954024, 3200623530, + 1019505875, 1049469523, 3191669879, 3205469337, 3186583315, 3181332934, 1046748065, 1032207285, + 3177452673, 3184320441, 1058176418, 1051417490, 3187638788, 3117734480, 3174910971, 1027421206, + 3190180579, 1056081058, 1057202963, 3177663057, 3160609525, 3183518831, 3174328406, 3185607243, + 3186459790, 1057245952, 3186381233, 3187139368, 3190972046, 1037829684, 3190284786, 1049593941, + 1058530423, 3191403278, 1055592458, 3189714807, 3180893474, 3181102009, 1055449327, 1063258845, + 1056136942, 3167842590, 1054320211, 3182810143, 3166418165, 1030853238, 3204622244, 3199271999, + 3204566016, 1050841306, 3191822570, 1046551196, 3184967600, 1037010493, 3179332797, 3194654507, + 3180103381, 1032481598, 3189538908, 3180491574, 1049969399, 1045657024, 3181186685, 1048356893, + 1042221946, 1032905461, 1050114529, 3186763100, 1054397589, 3188975097, 3204638701, 3184628652, + 1037439625, 3173254814, 1024481162, 1041413325, 1031331296, 1034649889, 3167282767, 1033677963, + 1037553638, 3179092246, 1033697483, 1020911384, 1032249644, 1032276979, 1028762713, 3196597051, + 1027339014, 1024914914, 1051514671, 1034061458, 1031035182, 3211526147, 1038553091, 3205934931, + 3194666783, 1027709828, 3214455329, 3181431692, 3203316242, 1042821936, 1031959939, 1024000316, + 1028534671, 1032107872, 1040044304, 3179803962, 1043675983, 1028744919, 1028234971, 1045830141, + 3163262644, 1035818125, 3166261849, 1036268980, 1035705628, 1034562353, 1053479274, 1037732893, + 1021811742, 1031381198, 1056178246, 1048580571, 1055229068, 1038703670, 1049060098, 1042061137, + 1051211130, 1033684623, 3192957662, 3201836654, 1042427789, 1053926316, 3206135901, 1044916817, + 1034206771, 1046955807, 1049545317, 3165108201, 1053192379, 1034975792, 1052183320, 1053753154, + 1023173243, 1048832455, 3185011995, 1045590114, 1057254845, 3188981901, 1013092519, 1029237541, + 1054086716, 3187771569, 3185217701, 1042750086, 3188804072, 1041604374, 1049927134, 1022942060, + 1024631923, 3179764912, 1040853186, 1019472462, 3158753724, 1034891207, 1048301535, 1044211840, + 3171553013, 1046698905, 3148492335, 1055788739, 3190339295, 1007295209, 3188597863, 3195495376, + 1052712020, 1053797950, 3197442231, 1041743877, 3172704320, 3172195725, 1057556062, 3192993524, + 3186963870, 3177820360, 1061323400, 1051485220, 1051692469, 3195517794, 1048889329, 1026634951, + 1052091060, 3133018459, 3185371852, 3205486773, 3186906325, 1057055416, 3207236897, 1048587704, + 3135030933, 1045620426, 1053645652, 3189216668, 1057779014, 1013727530, 1060631857, 1059140903, + 3184525169, 1045210938, 3198814051, 1046523706, 3188856796, 3197090733, 1044499838, 1043086488, + 3188295559, 3189119231, 3198145723, 1039256957, 3200838861, 1028108109, 3188495096, 3203123193, + 1041457393, 3191989781, 1017873005, 3205396687, 3192883544, 3194094542, 1048585246, 1048818753, + 3195966009, 3189467181, 3196762506, 3204427818, 3200205874, 3194567698, 1039191332, 3202780094, + 3200570260, 3191075343, 1045206000, 3190584517, 1042222616, 1049591274, 3177720568, 1052236942, + 1044239835, 1045064773, 3194622628, 1034487353, 1048553988, 1043225099, 1019134490, 1056819490, + 3199648540, 1042934955, 1038278038, 1059455977, 1006654770, 3181609271, 1035414400, 1041441923, + 1046414435, 3135475201, 3134476485, 1050066449, 3181380383, 1044745566, 3195726152, 3185927293, + 1049502925, 3160803948, 3162418703, 1019170186, 3189069211, 1035592167, 1041406246, 1065223641, + 1008329426, 1028780775, 3200470840, 3185682447, 1047635755, 1051888153, 3193833856, 1054240403, + 1041236217, 3116049680, 1032514401, 1047222784, 1041524188, 3190081343, 1042864920, 1029844161, + 1005680341, 3193761428, 3197040419, 3192512325, 3199600521, 3166633457, 1003977556, 3200726503, + 3184423365, 3194188045, 1050736328, 3193652911, 3166549449, 1031915590, 3204639296, 3200021163, + 3204580045, 1052159413, 3191833208, 1047558751, 4292108962, 134164, 3561029639, 4285107332, + 3555395, 2679392255, 2963776, 4287069510, 2630183679, 3257663506, 971353599, 177114623, + 4293714373, 1515358975, 4284447845, 4293646785, 4285356396, 3449447936, 6402724, 8435670, + 4282741971, 4283540491, 4279130988, 4285103484, 3164057600, 728925800, 3819640244, 4279975668, + 1392550838, 2042922855, 1587444015, 346987776, 4445796, 585683740, 1497859370, 1467875140, + 4904816, 788058128, 4286565807, 2075145135, 2571108138, 1422713187, 3769958308, 2947135630, + 1937958484, 1241507362, 4280600648, 1606071660, 14835700, 2158838620, 4282362151, 2661446837, + 3625631363, 4186162175, 3068009983, 3130557574, 647890884, 3305129653, 1936457567, 1340790075, + 1728019341, 242420761, 3032019535, 1358904117, 4289561938, 1920665404, 2333648785, 3513581506, + 3345313886, 4282409214, 3297747534, 676921451, 1052843462, 3231804875, 1074211104, 1060469483, + 3205819759, 1065035497, 3192095641, 3213994261, 1046405407, 1064990104, 1042954260, 1052670579, + 1068150280, 3199980299, 1030877466, 1060891741, 3184776674, 1042928035, 3197565765, 3193352272, + 3204975227, 1044222597, 1059917904, 3205023500, 3187044244, 1067348447, 3198214890, 3190186520, + 3204988754, 1040062520, 1058909366, 3205174769, 3222203618, 1074646792, 3220510970, 1072901832, + 3248582091, 1101098443, 1018083559, 1065353216, 1046913864, 1024364864, 1059059146, 1028138404, + 1055840032, 1022409683, 1032787837, 1045492236, 1035283175, 1029494570, 1062667412, 1029423895, + 1033025881, 1057649746, 1021767031, 1027952019, 1023742434, 995104170, 999624448, 1024059424, + 1011026537, 1021158261, 1053153765, 1058093881, 1049687563, 1058630097, 1062636004, 1055230273, + 1065353216, 1050104057, 1054471941, 1041521070, 1043220216, 1048964954, 1049682251, 1056292701, + 1056091201, 1040088407, 1048776317, 1049372041, 1050097385, 1050886532, 1050384962, 1048959619, + 1054379051, 1043470301, 2923539859, 1198650008, 1867107277, 629761685, 1650426669, 3249892939, + 1719499939, 1382326660, 1419161170, 1786937488, 1600622231, 1974893679, 914713770, 1314031224, + 1955963185, 2088902417, 1737704704, 1834703969, 2607455908, 1838789298, 1675271295, 1747953777, + 1112581425, 1919726219, 1732278427, 2829084056, 1213843126, 3245642348, 2590358458, 2236101181, + 407462786, 1402311248, 2509689484, 2846371440, 2307943305, 2607185256, 2966643054, 1068455067, + 2843448714, 2829852031, 2238806425, 2592305, 589209279, 2476233487, 2325862555, 2863225691, + 2242864997, 1971621023, 939544538, 2829863967, 2407313079, 1515238054, 2360517260, 2323871104, + 3233917033, 2420784736, 3180946753, 2643027342, 1870365566, 1246254663, 2105038930, 1804435617, + 1752136565, 2239263866, 2221040234, 1732857088, 1903581802, 1800791931, 1986550927, 2390980200, + 1637513628, 1432717714, 1616804676, 1984673181, 2089186218, 2576587380, 2069960679, 2939439558, + 2309444699, 1655123560, 1383625879, 1703388316, 2001709425, 2389528193, 1855945087, 1798064261, + 1817653124, 2004325788, 977115518, 1599360632, 2057004157, 1979723641, 1901671545, 1352440733, + 1832802705, 1648186996, 2290976934, 1901556847, 1701597313, 2928707697, 2291674968, 1765499551, + 2340906126, 2624027800, 2291354784, 114520064, 1734313356, 980329611, 1164811663, 2120753742, + 1991802756, 224360786, 1567717273, 2575605136, 776828786, 1769827993, 1788703870, 643987020, + 1701345958, 1922718566, 3665848477, 1901549190, 2508554908, 257383484, 1601271194, 3248059246, + 1751735363, 1852271948, 2307946367, 2004527251, 2340601319, 2240709260, 2893988022, 1819621944, + 2610989932, 1488753536, 1887277969, 2791472257, 2408064961, 1989516690, 3616446860, 2376563668, + 1987407228, 2758047110, 1922510227, 3182863489, 1330744709, 3195568473, 2777919141, 2492891013, + 2340597450, 2188156927, 1765227888, 3381166727, 630174446, 1196141659, 2623224385, 2335581054, + 9401716, 544504196, 1400148628, 2555855682, 2761388417, 1666999453, 1735545156, 2307295364, + 1115125895, 1570791809, 2676842869, 1499159960, 1466715963, 1485797036, 1835359334, 2169857407, + 2424870539, 1603305869, 1755068543, 1734833543, 2170711906, 2106139492, 1786736461, 2794104998, + 1920317604, 3144461451, 1613925858, 1950247584, 2191688282, 2726262893, 1529579927, 2456062321, + 2472964979, 1902878078, 1839566219, 2791603070, 1562133643, 2169922376, 2439540600, 1181171779, + 1277165641, 2023977823, 1820895649, 2140450178, 2338885822, 2210569904, 1833929871, 1466798487, + 1653107450, 2336328603, 2682023733, 2418234944, 18194551, 879081624, 1822995607, 2963297594, + 1989837168, 1015447406, 1990956390, 2289529467, 935688073, 2327532901, 1937674612, 695700597, + 1536857161, 2722978970, 1500226996, 2002209886, 2862965640, 2259048555, 2141876125, 2456526447, + 2969590374, 1646549610, 2961667232, 2290190746, 1957340265, 935478856, 33974642, 1933081481, + 2826592607, 2105556119, 1904780173, 1445399888, 1698330226, 2174252155, 2435930505, 1231451241, + 1347985527, 1311836235, 1631151469, 772938779, 2263409, 2389002013, 2662836150, 1648629855, + 1585538937, 3162220915, 525550928, 2674547042, 1870356936, 3126292649, 1822842790, 1570673689, + 1532791159, 2152429420, 2270913187, 1954043728, 1923512959, 2269391711, 1736212863, 2071424627, + 2354591866, 2005700730, 1619889795, 2035233113, 1735558552, 1399340369, 1116761213, 1751866717, + 2088331144, 2253542523, 1920297333, 2442415470, 7768634, 1719227210, 1870164903, 2338224006, + 2641254177, 1299452686, 1884607562, 4359330, 1519563371, 3331260723, 2946787189, 1332771950, + 2171315244, 2525134218, 1985902716, 2813228112, 2978370166, 1231060335, 1851884071, 2212593530, + 2055765598, 572591351, 2390789536, 1468169850, 2948500791, 2697501017, 996637018, 945171505, + 1586063693, 2558697374, 1631160243, 1876449647, 3538333301, 1688102037, 2558295390, 2469531001, + 1953004199, 2429270928, 2876465279, 2559339647, 2745868923, 2623051387, 1936091797, 2041032836, + 2858827407, 1152687818, 1263032185, 1919585117, 2794830521, 4073744260, 4286038140, 1052082865, + 1400835180, 2607524702, 1769233272, 2921689046, 1721012604, 2810015611, 2122620021, 2224204159, + 2391124639, 1819170693, 1853663608, 2641065093, 1953986447, 2324270478, 2878373752, 1938390899, + 1921230959, 2625407609, 1652588189, 2976160693, 1870298798, 2491975809, 2174587298, 2171499133, + 2356056663, 2927659162, 2239656861, 2458490760, 2905220673, 2835395803, 2963295961, 4289108562, + 2442888081, 374310224, 2287377218, 3217064869, 1788776594, 2741346178, 2089591733, 1552981323, + 2221977019, 1537658808, 1988792739, 3310788451, 2576661713, 2576918878, 1687710593, 2543358847, + 2140571549, 1816427140, 1318557795, 2877704628, 1919363641, 2843505205, 2825809315, 2341896063, + 3049892983, 3266481559, 2424140437, 2323810435, 1868784776, 1701428591, 2393206416, 2440324200, + 2088074381, 2257872815, 2459071376, 2006150822, 2426232441, 3211878748, 2306117275, 1446072286, + 1518966142, 2037016656, 3033108631, 3098971550, 2712778707, 2460913278, 1988992939, 2442759567, + 829386637, 1577096626, 2490461112, 2205249436, 3554846038, 2766961508, 1940479807, 2387756465, + 2392673712, 2595371116, 4291921057, 4120602254, 3059774279, 2996404915, 2293327262, 2646813086, + 4005146554, 2763352730, 2698166168, 2173206438, 2574476194, 2322830154, 2744417870, 1128964560, + 2681188006, 2259526250, 897809824, 1599708277, 2559800203, 2895553371, 2677578368, 1518576234, + 1198902373, 1648704341, 2189852296, 1186987851, 2472721522, 3198058137, 1526120221, 1952310362, + 2087477632, 998110274, 1464316329, 1212441205, 2253544355, 2644606081, 2763691686, 1539096132, + 2842525497, 2240574613, 2054774942, 2595197291, 2457625238, 2757579732, 2440204188, 2172224656, + 2593221258, 2712887444, 2307556003, 2592770713, 2743364492, 2510060686, 2913236893, 3077670274, + 2491840911, 2625930648, 2778424457, 2492758924, 3030085780, 1660924762, 2089986409, 1955566712, + 2858389667, 2543879835, 2645005226, 2105723792, 2105716629, 1887867529, 2221508491, 2273673603, + 2272832943, 1618049426, 3161179277, 2590143396, 2315209363, 2927587032, 3526597278, 1927880899, + 3575356321, 2909503619, 2289863838, 2891176088, 3423641734, 2061963262, 3525220816, 2504476239, + 2479327275, 2542759536, 2507578020, 3029443729, 2723533962, 1842393748, 3060824679, 3263656822, + 1752064136, 1752270934, 2390857310, 1637054142, 2039980983, 2172689564, 1823516072, 2190244234, + 1769976201, 1053725400, 2192942549, 1469678211, 872390820, 2058121697, 1918548621, 1100517071, + 2023663280, 2762387379, 3228660598, 2237556858, 1570474885, 1706659731, 2040234984, 2794236781, + 2791537282, 2456714115, 2122806688, 2205250197, 2778767722, 3131288951, 1596090774, 3445848989, + 2521979452, 2456923456, 3819017095, 2304494138, 2333719149, 3232265097, 2860175956, 2020266112, + 4004349583, 2405022227, 2315309206, 2676249988, 1957860518, 2948093044, 2341244287, 2072223639, + 2474729265, 2021367937, 1755750551, 2712808017, 2020845187, 1403226449, 1700689259, 1822527884, + 2999243058, 1587456672, 3096869574, 2356765323, 1098210675, 3465831845, 3556747568, 3111880076, + 3030081369, 3535756130, 559763310, 3567740094, 3958735645, 2543815715, 2322562164, 1145872595, + 2407040909, 1905367399, 2664719770, 2136317819, 1685296247, 1281332152, 1836998291, 2272492694, + 1471908239, 2947124130, 2393343078, 1889513628, 2021753014, 2041150575, 1037801103, 2190901198, + 2364829509, 1856736395, 2627247307, 2548050788, 1105374621, 2125569238, 2918087454, 2923717488, + 1668642502, 2171054256, 1401649796, 1869052290, 1434935705, 2472449437, 2069522278, 1799526655, + 1870303878, 1852728198, 1751148675, 2408354986, 2610851713, 3062604430, 2803214995, 1668526218, + 2557504903, 3557077372, 2310785755, 2021817974, 1262967445, 2895485695, 2756342647, 3775188055, + 1838259662, 1873185158, 2491836240, 2002803277, 2157414284, 1316715467, 3501954984, 1955365005, + 2410967693, 2526369614, 1802919306, 2303429282, 2493031324, 2794815379, 2139398273, 2390716535, + 2590953309, 1487895437, 2123736216, 2811208810, 1912178842, 2072940144, 2315205590, 2712832951, + 2695601826, 3060716110, 551002795, 1852863144, 2085932925, 2892590439, 2055380100, 1793737927, + 3245707401, 1922211994, 1937416610, 3563355747, 2054850215, 2020047754, 2575795576, 2052226432, + 796366208, 2323747465, 3277906048, 2963380327, 2878054804, 3674930327, 2440932463, 1855171181, + 2557731773, 2476116645, 3379336348, 4060479407, 2088282220, 2527102828, 2716890485, 2341111422, + 1972414859, 2107342761, 2594804672, 2359274143, 1691833764, 2106558095, 2591585695, 2877912733, + 2020573552, 2624160616, 2408095329, 1637322388, 1121426830, 2779275153, 1569552488, 1622113967, + 3570511222, 1469937289, 4286151562, 3518233378, 1065580130, 701463940, 3167002002, 1736476598, + 2793956225, 1634892013, 1955239046, 4152338326, 2710100318, 1954724496, 2656670302, 1716940170, + 1452696197, 2675015824, 2191295123, 878870399, 2274730930, 1801424281, 3048579190, 2728949318, + 2054331002, 1768005740, 2797223289, 868318864, 2690033581, 2164199315, 2455144815, 2021164381, + 2360626789, 2858330677, 2829225820, 2791787937, 1504281235, 2724044488, 1787833066, 2612561041, + 2709415006, 2975551128, 1836479383, 1941267528, 1738582960, 594123372, 2691736437, 4284183192, + 3969616813, 2074048934, 2945541795, 2173610092, 1562939528, 2776651417, 2276166282, 1822528656, + 3516623774, 2912463755, 1712423575, 2295843753, 2091877762, 2173080939, 2658953880, 1955690371, + 2174398876, 2125979512, 1703314311, 2121886596, 2271465340, 1606444616, 3262466418, 2388286296, + 1495434933, 1338738812, 1642844308, 2757773135, 2291753352, 2197328749, 1947752851, 3211298948, + 2829041212, 1130525050, 1805535872, 1912567726, 2401328528, 2052047777, 2002687136, 2865012107, + 3212668563, 2813574414, 1854121841, 2541780872, 2186504567, 2528891814, 2173339234, 2874772130, + 2171517548, 1752276839, 2122277510, 2658374994, 2442097830, 2594013589, 1967521548, 1954839941, + 2474928503, 1582948260, 2339664071, 2675867543, 2335812105, 2088988263, 2340518799, 1566474842, + 2559540092, 2039583108, 1737271684, 2424604055, 2794289038, 2072863397, 1920640872, 2073923725, + 1534698621, 1553044324, 2595704096, 2089379204, 1586007684, 1013514137, 2458094713, 2122347100, + 1936691819, 2778285928, 2694681005, 1970177671, 2191737970, 2508092793, 2088669302, 2694400619, + 1921874589, 1668517534, 1010265221, 2020503613, 2273142907, 2055956387, 2575599988, 2596365915, + 2275167319, 2241897353, 2274260112, 2844290738, 1888126819, 2140008086, 3233702490, 2529338268, + 1082228135, 1485800653, 1569626472, 1058394548, 2006680491, 745121704, 1748223908, 3297011859, + 979489897, 67290322, 3904726155, 2726123614, 3315400781, 1939120560, 1185316983, 2674444181, + 1482932856, 2408161148, 3282069340, 1720886455, 1620619387, 2040758378, 1853903469, 1938391679, + 3113974655, 2239654786, 2626581646, 2038133910, 2089446486, 2408679304, 2526649237, 2088600437, + 2442687371, 2962723980, 2007260265, 2274525563, 2762046855, 1068498828, 2372382088, 2004131227, + 2879352428, 1906411910, 1585415049, 2640359799, 2390263200, 2055183251, 2740337530, 2556724120, + 2808178325, 2287561307, 2404476084, 1736860567, 1989046396, 2257809533, 3079754125, 2555011715, + 2575852423, 2842860412, 2818615669, 2607699068, 2306955910, 2926730890, 3383249046, 1319206567, + 1789308798, 2340518784, 2793048190, 2486936943, 3261363797, 1721468030, 929343876, 2309985640, + 2507427954, 2070315410, 2857775906, 1796976800, 3180417912, 1184731221, 3026096030, 2224808000, + 1890018704, 2637262162, 2626463357, 2036495495, 870540178, 2258449642, 2207012483, 3707784559, + 1586341005, 1620214655, 2909319818, 2775547648, 2125232535, 498689896, 2643480245, 1722587830, + 2361221728, 1717734055, 2089188228, 2054260366, 2174322030, 1956025258, 2626119253, 628935314, + 3744481946, 2022875019, 2039439498, 2455932243, 1765248394, 2778547867, 2443633920, 1865519993, + 781081230, 2024060820, 2909164881, 1840843296, 1161332441, 1790294364, 3349374884, 1146643535, + 1634188911, 2572974735, 2288994933, 1017629412, 2458095024, 2640991888, 1079273863, 647202162, + 3448927899, 1837729431, 2691725282, 1215267687, 1685356161, 2088937103, 1404776125, 1450605680, + 1567713735, 1837236437, 1431788647, 2274990753, 2108032686, 1857249900, 2389272674, 1434628741, + 2205843573, 1687709073, 2123850422, 1954840215, 2931068046, 1820624004, 2373401976, 2640545669, + 3184823398, 3902561316, 2898360269, 1636412537, 2527703730, 2757988952, 2359336565, 2186706321, + 2088639375, 2520347286, 2776205386, 1650287332, 1941615737, 3430569565, 1566006183, 1261531776, + 1314035455, 2009112184, 2927582558, 1348700446, 2932180621, 2383637911, 607424992, 1807067444, + 1384554635, 935694921, 1450083487, 2089964917, 1768460191, 2474421437, 2037619395, 2174062962, + 2489217409, 999392165, 2023327077, 2841810568, 13141875, 2627307376, 2372239483, 1115204236, + 2996208222, 2121097363, 3165686099, 1785751442, 2305786754, 866940798, 2140432013, 2389405296, + 2741012063, 2223006046, 2105440129, 1953793409, 1633653071, 2200490109, 2709813588, 1785379943, + 2471138488, 1769115992, 1665432428, 3264477235, 2272564908, 2171433359, 2291124510, 1317441922, + 1786262401, 2410998602, 1733386639, 2142334638, 2319122589, 2175509890, 1801621114, 1665588340, + 3301415760, 2827713943, 2594974030, 1872932509, 2291363456, 2255589257, 1734888237, 2720701298, + 2493075267, 2476838245, 1164928161, 2137493380, 1650491275, 2940353116, 3617561752, 2273207935, + 4279267188, 2256966000, 1703182723, 1937512091, 2845549226, 2004248757, 861376111, 1599956839, + 2288549775, 3255670665, 2708307809, 1418624655, 2192673901, 1886154643, 1669494145, 1850898832, + 1787335560, 3711665509, 1566557828, 2236058800, 2443799638, 2288555329, 2008055165, 3863517301, + 2208278067, 1504806283, 4286682244, 2645386023, 1921884002, 3714951851, 1953846294, 1804372895, + 611931499, 1938665675, 2052751707, 2894366845, 1619876434, 1654222407, 2495119520, 2140678270, + 2490599295, 1937472126, 3591460207, 2187230305, 2593418668, 2190514556, 1468969356, 1749649564, + 2406179427, 2510654277, 1871362383, 2288152202, 1162832267, 1406305133, 2977727838, 1480106604, + 293516861, 826452641, 2306642282, 2957657424, 1668257909, 2717859169, 2595958899, 1539668809, + 2206698108, 3301610047, 2055440522, 1987932816, 3353198018, 3587089063, 1870998664, 1401738112, + 1418360166, 3458041681, 2376435152, 2495914121, 3076085716, 1736996245, 1085479278, 1023742816, + 1654108092, 2225776508, 3025949312, 3384517566, 2182888872, 572993457, 1466189238, 1960030384, + 2692394409, 1518114158, 1799829645, 1006656615, 1689700987, 2524791700, 1688439969, 2983289374, + 3046216079, 3392955285, 2103740826, 1667276195, 1889237365, 2185741903, 3229003402, 1332898170, + 2197878329, 3477118857, 1988862077, 2152962436, 4066590327, 2149023151, 727930013, 659966830, + 2126667379, 4103382330, 3219774434, 3014682191, 1968937139, 1014381677, 1282386345, 2026410086, + 2106817906, 1702728843, 2910421904, 2088198499, 2021890206, 2492560255, 2423882906, 2308341360, + 2154132100, 2373428047, 2056222587, 1938198927, 2303900830, 2022154383, 2038265187, 4152259839, + 2809230502, 1853128617, 2156123717, 3012202391, 2643164292, 2153102265, 2240049778, 1937270897, + 2773632359, 849063482, 835222642, 3109892030, 1200380206, 2751478303, 3215031653, 1283417965, + 2152812196, 2466191245, 1972994964, 2847502689, 3027013730, 2001403928, 10652075, 1552602507, + 2057894779, 2504748600, 130172617, 2714751333, 2123757939, 910168320, 2758173818, 2174681195, + 2692765564, 3770053970, 833513460, 3712324596, 771739137, 473189025, 2593883219, 3604345154, + 3158382248, 2481296128, 1065256855, 2307100399, 1407161344, 1465609552, 1504864151, 199163701, + 3345152995, 2848729246, 2308793685, 1353497394, 3003366655, 1202597448, 665090224, 2353171936, + 14198837, 122308985, 2626945144, 3775347847, 1184657841, 1671538794, 2446069298, 1483678039, + 2353955489, 2693988434, 3363832059, 3853714554, 2291744602, 297323267, 2411314059, 295814266, + 2593300896, 2826043511, 3030622610, 1852595102, 1857776449, 2207078911, 1669202029, 3579267955, + 1903466893, 2574621552, 3366294388, 2524220302, 1802999886, 9800364, 2240252486, 2640987351, + 617482796, 748688896, 443201676, 944146049, 5875888, 2537320616, 1535377527, 3865339767, + 2525547887, 2161672509, 2592047548, 1218969488, 3114316672, 3077477249, 1379467132, 2171439990, + 2522963849, 3533208666, 3718240952, 627743109, 1834195402, 2659534591, 427819168, 2859206523, + 2208537978, 2170129661, 4287224624, 2188543227, 1988522046, 2258989480, 1619114941, 1381928448, + 2507642259, 2387701716, 2945408901, 2382376394, 2177721141, 1131186524, 1634839447, 1768539279, + 2173474156, 10008742, 4290142327, 2172489089, 1938591801, 529560047, 1986034836, 4280499086, + 2324189030, 2253817502, 2141219839, 1971100034, 2023002749, 1834908810, 2137259989, 1213784500, + 1202562421, 2938734490, 2415888009, 1888132737, 2105576829, 2158505103, 4286485098, 1568047990, + 2221038229, 2176293074, 2123079806, 2121302015, 1471251778, 2490401669, 2107286694, 1401749378, + 2089068421, 2491514475, 2005298813, 2231343980, 3849553814, 1654281285, 1801152877, 4286534531, + 2105572214, 1753129283, 1820088675, 1838451531, 2667608818, 1856792157, 1889893561, 1787087237, + 1973026684, 3009181821, 1688108964, 2005176214, 2030017097, 2807266163, 1987992191, 2276363334, + 4285236103, 1871603573, 3197407115, 1414038386, 2004384653, 2290647807, 2806609539, 2539944582, + 1803912058, 2205417365, 3313739829, 2507762052, 2286046097, 1090476679, 2088798588, 2222883971, + 2021953146, 4285234825, 1048764852, 3179624586, 1041413909, 3196611729, 3160056282, 1058294519, + 3192266532, 1042417098, 1010761724, 3192650422, 3183927810, 1038091820, 1057326481, 1045830840, + 1055399649, 1043650942, 1030320479, 1023336164, 1047052367, 1049099471, 1001601523, 1042414314, + 1018814770, 3186905562, 1010540119, 1045335974, 1042342790, 1037034855, 1042037839, 1033833564, + 3154204117, 1042570138, 3159773721, 3164058967, 1033340210, 1029621896, 3177027435, 1015663978, + 1029896658, 1029165993, 1023345062, 3169728338, 3176937547, 1034180599, 3178806156, 3168952431, + 988423444, 3155271010, 991552443, 3191956971, 1035504033, 1024597960, 3180953889, 1025580518, + 1037107555, 1007977363, 1035600952, 3177711927, 3170231252, 1037769082, 3176005292, 1002112056, + 1020328972, 972013123, 3216729932, 1069150333, 3215606876, 1068036051, 3222555383, 1075071735, + 1053550493, 1052162780, 1056523950, 1055869258, 1052827203, 1052008149, 1058268933, 1057659708, + 1054250630, 1053248048, 1057206263, 1052317137, 1051770702, 1057372182, 1053192863, 1055285772, + 1053573068, 1052248576, 1065353216, 1054294802, 1057419897, 1054164021, 1053064325, 1056336453, + 1054066871, 1058033413, 1051657251, 1056687169, 1056397637, 1054302107, 1053760798, 1057538370, + 1048343425, 1041001223, 1052696035, 1043649185, 1040037663, 1038680772, 1043445599, 1039703722, + 1043664463, 1041394109, 1041158144, 1040437448, 1038595135, 1040157971, 1041043545, 1041449032, + 1051341238, 1057667776, 1056281881, 1059436675, 1049325642, 1049876854, 1050756783, 1049021950, + 1058842833, 1053474531, 1057516044, 1054748936, 1056340354, 1054836283, 1045521792, 1058759605, + 1049302787, 1056329000, 1056346828, 1048950626, 1050166842, 1050477119, 1054109639, 1049030405, + 1053645959, 1052505012, 1051608013, 1053253032, 1049664412, 1052581436, 1051749823, 1048586855, + 1058958847, 1050862836, 1063364508, 1059108007, 1058595355, 1060008956, 1058385508, 1059916590, + 1054916218, 1059525615, 1059441444, 1060023962, 1060570985, 1062587505, 1054091605, 1065353216, + 3160297758, 1353799776, 2036341961, 4550520, 1211788872, 2711316360, 3096209523, 1534328933, + 2221751929, 4289297992, 3931282906, 855606692, 1912637548, 2959036541, 1955876740, 2038938735, + 2667599195, 2972719249, 983252850, 1505537896, 1533251441, 2667591582, 613836094, 3029165723, + 3042705537, 2373688457, 1838711434, 851621272, 371439193, 4098836602, 1383145029, 2063535741, + 1510670449, 3770851965, 2474867579, 1736547166, 2523751272, 3690995878, 1301633148, 576220329, + 3501392005, 1760712555, 2627941830, 1516744042, 3160267164, 537641931, 651400533, 2945056689, + 155742057, 2859817364, 2140893333, 2355232887, 2320105520, 2409862460, 3038082220, 3617695889, + 1850900806, 4121961371, 2523293695, 3503540558, 3239724106, 4244654550, 2626948439, 2949821495, + 1821616015, 1685628076, 1621360485, 2236983940, 771731087, 2556989080, 2509479027, 2023249066, + 2642469504, 1461941906, 8486798, 2289272536, 2130697114, 2491913839, 2523960991, 3019887996, + 1488508549, 1275108199, 2255652701, 4093737018, 1922814372, 12951164, 2677186450, 2086038408, + 3169955775, 380922478, 1905508291, 2117012735, 3483936121, 6390851, 1969456619, 2723442612, + 2708956559, 2032101772, 1703175272, 2172885503, 2238776433, 4279923615, 1452053834, 2428158930, + 3932582052, 1952436099, 2006087289, 2471690202, 2028704660, 2591972997, 2055371879, 2606039102, + 2396680583, 2069920650, 1719698579, 4286133137, 4285973101, 2082176158, 578117784, 2355665068, + 4285658953, 2287631746, 1970546318, 1721343860, 2306382220, 2388925582, 1788543086, 1378261196, + 8808133, 1537911634, 2726608528, 2034024231, 2298504055, 1518634111, 1854568329, 1617003899, + 2220723592, 3380177368, 12611676, 2056692055, 2516568719, 2309395304, 2841678214, 3049698412, + 2650786675, 1315082048, 3057419111, 4145445933, 3166868921, 306479489, 1906279070, 2089242367, + 3271146180, 230978679, 1905903552, 2116551679, 620800843, 3278264959, 2743032946, 2340729419, + 3262152491, 3439341979, 744752758, 1670680498, 2042018221, 885642882, 2308170883, 2559795456, + 12865518, 2108997590, 1942940742, 2669618224, 2147458453, 2140239458, 2524355715, 3076663888, + 2633399953, 1821017736, 1837011844, 4284954502, 2273220983, 1300467214, 3405807870, 2709491613, + 3914969145, 2842402687, 2315282900, 1656324253, 983778712, 1871422851, 2106720111, 2507637158, + 4164103090, 2041994731, 3657383338, 3634937826, 2792596480, 2476435375, 1633980057, 2138476424, + 1333501440, 1783247949, 1480737150, 1269792853, 3934668006, 2979200999, 4129403812, 2239011824, + 3970385810, 4073175784, 4280465354, 2256519913, 2106550528, 3783996545, 2859815119, 1737134214, + 3984400895, 1453841391, 3660105143, 3011292122, 2019850240, 2575514495, 2476300446, 1887805315, + 2525334817, 3480483984, 2399175831, 1239719269, 1819053385, 2808217713, 2041255322, 1368952179, + 1952679559, 1650676847, 2170814636, 465225071, 2528601754, 1335731605, 2634068641, 2875087513, + 2171347519, 3094314390, 4289235617, 1921884366, 1681959453, 2473025633, 1412902501, 905952358, + 1735629642, 3027894378, 1585926284, 1654296421, 1786492741, 2873884778, 1014781580, 1787790434, + 1827834982, 1837077101, 1786881058, 4279894637, 2291531971, 934241675, 2733667445, 3258727593, + 1620479345, 1885508962, 2147514813, 1955697764, 3191812214, 1455263170, 1891140995, 2507440895, + 2895749631, 3938206119, 1018015092, 2573755826, 1251383951, 1786351435, 1571618601, 3108330060, + 4282255608, 3294675199, 3576313570, 702077402, 1677756029, 1164742502, 1881708068, 2040708456, + 2056292444, 2441367162, 1612185760, 1335133815, 2865455359, 3063172265, 2590598386, 2958441894, + 898812998, 2906277941, 5397310, 1802924085, 2002220544, 2040146308, 1841705600, 1686803046, + 2387447090, 2124645273, 8024214, 2072613556, 2224785552, 2105773958, 2264957917, 1722258057, + 2191230855, 2641524354, 2097184955, 1651927682, 2594664126, 3011471000, 2390175999, 2756139159, + 3051177660, 750964655, 2588794222, 4280290735, 1165557516, 3072099906, 1047890260, 1537450288, + 2365553081, 1688375439, 1855632295, 3574666379, 3578668220, 1759412698, 2710665381, 2256702463, + 3548401151, 2648272850, 2506854310, 2323151061, 2805872865, 148242344, 3160798569, 2173674153, + 4266005747, 3245259775, 3493345252, 902548443, 2039589216, 4285935739, 1940153489, 1904313466, + 3233761195, 1540325569, 2365600235, 2053856190, 1806338202, 1653383534, 1953038190, 3208992365, + 1648988515, 2740543843, 2533320277, 1655879525, 1864068904, 2930049152, 1604520085, 951698532, + 3423950949, 2432659425, 156129749, 1738911734, 2264959347, 2289395848, 2407355493, 654114440, + 2737795970, 2591392162, 2611309151, 603970467, 1690995595, 1737788263, 1818478714, 4279121255, + 3202814259, 3217553773, 3187909186, 3216771390, 3214214851, 3222544924, 3204114129, 3207995268, + 3191842931, 3217590705, 3183208382, 3224619640, 3227803247, 3192180385, 3207564607, 3217119308, + 1032625267, 1037079029, 3192285273, 1059882233, 1056930330, 998777802, 1027990540, 3181607419, + 1020200737, 1046400206, 3200174496, 1042078882, 1048889257, 1028259388, 1035131311, 1046529212, + 1031897577, 3196121859, 3185132891, 1060700195, 1060082626, 3172207284, 3172180308, 3154621227, + 1032524315, 1035998404, 1028799848, 1045135565, 1053452071, 1031839994, 3180527514, 1035362422, + 1053335096, 3202109615, 1038695577, 1061658846, 1061616997, 1065992050, 1062813215, 3193672031, + 1052928755, 3179389457, 3196265165, 1051964256, 1057981639, 1015669427, 1042273954, 3183139869, + 3216875886, 1069295147, 3224460371, 1076885914, 3244580463, 1097096815, 1050335768, 1062858529, + 1053888724, 1062113925, 1058844314, 1063881340, 1055899017, 1049715772, 1060392890, 1062819881, + 1053851066, 1059855149, 1064880424, 1052341447, 1048680177, 1055731202, 1053087137, 1052851623, + 1057311032, 1052648514, 1045574508, 1062211984, 1064737346, 1055290212, 1056894073, 1053993700, + 1054895024, 1051309739, 1053158459, 1053964199, 1058560720, 1059324988, 1040814367, 1052270193, + 1047479988, 1056284703, 1047245081, 1046856163, 1065353216, 1049491203, 1042329667, 1052634570, + 1040468787, 1050012870, 1056295663, 1047559100, 1050647313, 1053266577, 1033795645, 1047087047, + 1050940929, 1046135960, 1043529598, 1048902746, 1042888638, 1050723053, 1041773389, 1053409182, + 1040654049, 1048995215, 1049563980, 1043007228, 1059891087, 1059899496, 1035474987, 1032736758, + 1041276762, 1037061464, 1032305622, 1039942137, 1062917324, 1037938840, 1041417883, 1036713786, + 1039549315, 1037987850, 1045253702, 1044297206, 1048240739, 1040650724, 1037212702, 1038234118, + 1043275966, 1041474399, 1039802370, 1041667507, 1065353216, 1045145369, 1040711463, 1050590272, + 1044001812, 1038780318, 1038173461, 1045178752, 1049165110, 1049023961, 1053493335, 3201465523, + 1052835077, 1055373177, 1055018436, 1053037920, 1055626545, 3196953759, 1057466692, 1050694167, + 3205793201, 1051427566, 1054939007, 3197686071, 3199453250, 1051260799, 1053734435, 3201961078, + 1053611275, 1054244021, 1054102537, 1055075612, 1054462895, 3199966150, 1054977672, 1053527476, + 3204495224, 1051812657, 1055122343, 3200055061, 3202402861, 1053888350, 1053438082, 3201806503, + 1053265627, 1054383845, 1054202424, 1054866842, 1054602440, 3199679782, 1055586771, 1052876215, + 3204764594, 1051584669, 1055266379, 3199664157, 3202207373, 1053855249, 1053735474, 3201961436, + 1053610605, 1054243523, 1054102061, 1055076670, 1054462244, 3199966598, 1054976147, 1053527872, + 3204494573, 1051812618, 1055122592, 3200056415, 3202403582, 1053889169, 1053733785, 3201960749, + 1053610475, 1054243969, 1054102304, 1055076447, 1054462573, 3199966438, 1054976811, 1053527627, + 3204495071, 1051812544, 1055123439, 3200055906, 3202403139, 1053888829, 1054071965, 3202878786, + 1055370502, 1053385673, 1053334661, 1054538438, 1053556169, 3200545253, 1053570621, 1054349170, + 3202204233, 1052859111, 1053362083, 3201935644, 3202947354, 1054728344, 1053757536, 3201969110, + 1053614019, 1054241815, 1054100842, 1055078904, 1054460000, 3199974471, 1054963921, 1053531061, + 3204487462, 1051814489, 1055072379, 3200063468, 3202406512, 1053892446, 1053486758, 3201554443, + 1052852165, 1055356011, 1055005032, 1053196253, 1055604497, 3197149274, 1057462509, 1050742591, + 3205787529, 1051427497, 1055000386, 3197952274, 3199592101, 1051291130, 1054050852, 3202993471, + 1055976039, 1053415847, 1053338190, 1054572201, 1053582652, 3200538642, 1053475498, 1054367740, + 3202068519, 1052803462, 1053338451, 3202015989, 3203044755, 1054751224, 1053735151, 3201960084, + 1053609871, 1054243491, 1054101940, 1055076982, 1054462220, 3199967399, 1054975809, 1053527985, + 3204494281, 1051812598, 1055123570, 3200056815, 3202403773, 1053888942, 1053477748, 3201807305, + 1053255333, 1054388742, 1054207181, 1054869887, 1054607571, 3199683389, 1055650547, 1052931366, + 3204760028, 1051585953, 1055265767, 3199667330, 3202208101, 1053853058, 1054071809, 3202826797, + 1055350059, 1053390796, 1053340016, 1054578202, 1053562806, 3200551727, 1053332658, 1054352304, + 3202008188, 1052880511, 1053667628, 3201708186, 3203013858, 1054732181, 1054072371, 3202825002, + 1055337883, 1053412671, 1053364756, 1054560820, 1053586358, 3200527384, 1053413889, 1054325458, + 3202051019, 1052892217, 1053649960, 3201688453, 3202984343, 1054704508, 1053483693, 3201503260, + 1052841479, 1055367980, 1055014103, 1053105914, 1055619665, 3197034464, 1057465225, 1050712258, + 3205791537, 1051427284, 1054956449, 3197820065, 3199490012, 1051270098, 1053485967, 3201492855, + 1052839319, 1055369415, 1055015689, 1053085614, 1055621812, 3197012624, 1057465509, 1050707056, + 3205791863, 1051427712, 1054950346, 3197782603, 3199476995, 1051267868, 1053293137, 3201760455, + 1053038836, 1054392572, 1054191994, 1054789113, 1054594607, 3199658228, 1056365207, 1052148820, + 3205025203, 1051335467, 1055361655, 3199446279, 3201657055, 1053148302, 1053736370, 3201962909, + 1053611039, 1054243768, 1054102276, 1055075595, 1054462519, 3199965694, 1054976864, 1053527640, + 3204495005, 1051812515, 1055120562, 3200055575, 3202403326, 1053888523, 1053448027, 3201379351, + 1052841731, 1055364193, 1055008305, 1052939117, 1055618246, 3196842915, 1057466890, 1050676397, + 3205794368, 1051425831, 1054892900, 3197671305, 3199443909, 1051255142, 1054060143, 3202816973, + 1055303699, 1053469986, 1053424917, 1054513993, 1053647398, 3200468562, 1053572683, 1054258225, + 3202135644, 1052912954, 1053664251, 3201628985, 3202914944, 1054635099, 1053733371, 3201960042, + 1053611514, 1054243813, 1054102168, 1055076596, 1054462690, 3199966679, 1054975965, 1053527887, + 3204494680, 1051812752, 1055122903, 3200056632, 3202403323, 1053889032, 1053487336, 3201561769, + 1052853922, 1055354712, 1055004489, 1053206555, 1055603044, 3197162486, 1057462348, 1050745091, + 3205786919, 1051427750, 1055005747, 3197961923, 3199606622, 1051293224, 1055333362, 1054214129, + 1054501862, 1054213775, 1054214039, 1053356473, 1054211514, 1055311215, 1053382943, 1054213717, + 1054486255, 1053410054, 1053432238, 1055327097, 1055328600, 1054468586, 1054213985, 1055325195, + 1053491310, 1054214091, 1055309269, 1059999756, 1060083643, 1060079184, 1060083567, 1060083498, + 1060261121, 1060084491, 1060018088, 1060276839, 1060083958, 1060080569, 1060222796, 1060226992, + 1060012857, 1060005864, 1060075233, 1060083872, 1059584441, 1060231862, 1060083662, 1060019057, + 1056956615, +}; + +uint32_t* get_knWeightsArr_addr(void) +{ + return (uint32_t *)(knWeightsArr); +} +uint32_t get_knWeightsArr_size(void) +{ + return sizeof(knWeightsArr) / sizeof(knWeightsArr[0]); +} +void get_knWeightsArr_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/heart_net_org_dll.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/heart_net_org_dll.c new file mode 100644 index 000000000..c195c7ab8 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/heart_net_org_dll.c @@ -0,0 +1,41 @@ +#if (_WIN32 || _WIN64) && !defined(Goodix_DSP_EXPORTS) +#include "heart_net_org_export.h" +void heart_net_dll_param_init() +{ + goodix_win_params st_dll_params_in; + + st_dll_params_in.knBasicWeights.weight_arr = get_knBasicWeightsArr_addr(); + st_dll_params_in.knBasicWeights.para_size = get_knBasicWeightsArr_size(); + get_knBasicWeightsArr_version(st_dll_params_in.knBasicWeights.net_version, VERSION_SIZE_MAX); + + st_dll_params_in.knWeightsSmall.weight_arr = get_knSmallWeightsArr_addr(); + st_dll_params_in.knWeightsSmall.para_size = get_knSmallWeightsArr_size(); + get_knSmallWeightsArr_version(st_dll_params_in.knWeightsSmall.net_version, VERSION_SIZE_MAX); + + st_dll_params_in.knWeights.weight_arr = get_knWeightsArr_addr(); + st_dll_params_in.knWeights.para_size = get_knWeightsArr_size(); + get_knWeightsArr_version(st_dll_params_in.knWeights.net_version, VERSION_SIZE_MAX); + + st_dll_params_in.knConfNetWeights.weight_arr = get_knConfNetWeightsArr_addr(); + st_dll_params_in.knConfNetWeights.para_size = get_knConfNetWeightsArr_size(); + get_knConfNetWeightsArr_version(st_dll_params_in.knConfNetWeights.net_version, VERSION_SIZE_MAX); + + st_dll_params_in.knSceneNetWeights.weight_arr = get_knSceneNetWeightsArr_addr(); + st_dll_params_in.knSceneNetWeights.para_size = get_knSceneNetWeightsArr_size(); + get_knSceneNetWeightsArr_version(st_dll_params_in.knSceneNetWeights.net_version, VERSION_SIZE_MAX); + + st_dll_params_in.knSceneSwitchWeights.weight_arr = get_knSceneSwitchWeightsArr_addr(); + st_dll_params_in.knSceneSwitchWeights.para_size = get_knSceneSwitchWeightsArr_size(); + get_knSceneSwitchWeightsArr_version(st_dll_params_in.knSceneSwitchWeights.net_version, VERSION_SIZE_MAX); + + st_dll_params_in.knMultiWeights.weight_arr = get_knMultiWeightsArr_addr(); + st_dll_params_in.knMultiWeights.para_size = get_knMultiWeightsArr_size(); + get_knMultiWeightsArr_version(st_dll_params_in.knMultiWeights.net_version, VERSION_SIZE_MAX); + + st_dll_params_in.knTdfusionWeights.weight_arr = get_knTdfusionWeightsArr_addr(); + st_dll_params_in.knTdfusionWeights.para_size = get_knTdfusionWeightsArr_size(); + get_knTdfusionWeightsArr_version(st_dll_params_in.knTdfusionWeights.net_version, VERSION_SIZE_MAX); + + goodix_heart_net_dll_set_params_inner(&st_dll_params_in); +} +#endif //#if (_WIN32 || _WIN64) diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/heart_net_org_export.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/heart_net_org_export.h new file mode 100644 index 000000000..ce6112584 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/HR/04_EXCLUSIVE/heart_net_org_export.h @@ -0,0 +1,72 @@ +#ifndef _HEART_NET_ORG_DLL_H_ +#define _HEART_NET_ORG_DLL_H_ + +#include "goodix_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + + extern uint32_t *get_knBasicWeightsArr_addr(); + extern uint32_t get_knBasicWeightsArr_size(); + extern void get_knBasicWeightsArr_version(char* ver, uint8_t len); + + extern uint32_t *get_knSmallWeightsArr_addr(); + extern uint32_t get_knSmallWeightsArr_size(); + extern void get_knSmallWeightsArr_version(char* ver, uint8_t len); + + extern uint32_t *get_knWeightsArr_addr(); + extern uint32_t get_knWeightsArr_size(); + extern void get_knWeightsArr_version(char* ver, uint8_t len); + + extern uint32_t *get_knConfNetWeightsArr_addr(); + extern uint32_t get_knConfNetWeightsArr_size(); + extern void get_knConfNetWeightsArr_version(char* ver, uint8_t len); + + extern uint32_t *get_knSceneNetWeightsArr_addr(); + extern uint32_t get_knSceneNetWeightsArr_size(); + extern void get_knSceneNetWeightsArr_version(char* ver, uint8_t len); + + extern uint32_t *get_knSceneSwitchWeightsArr_addr(); + extern uint32_t get_knSceneSwitchWeightsArr_size(); + extern void get_knSceneSwitchWeightsArr_version(char* ver, uint8_t len); + + extern uint32_t *get_knMultiWeightsArr_addr(); + extern uint32_t get_knMultiWeightsArr_size(); + extern void get_knMultiWeightsArr_version(char* ver, uint8_t len); + + extern uint32_t *get_knTdfusionWeightsArr_addr(); + extern uint32_t get_knTdfusionWeightsArr_size(); + extern void get_knTdfusionWeightsArr_version(char* ver, uint8_t len); + + +#if (_WIN32 || _WIN64) +#define VERSION_SIZE_MAX 10 +typedef struct +{ + char net_version[VERSION_SIZE_MAX]; + uint32_t para_size; + uint32_t *weight_arr; + +}st_hrnet_params_info; + +typedef struct { + st_hrnet_params_info knWeightsSmall; + st_hrnet_params_info knWeights; + st_hrnet_params_info knConfNetWeights; + st_hrnet_params_info knSceneNetWeights; + st_hrnet_params_info knSceneSwitchWeights; + st_hrnet_params_info knMultiWeights; + st_hrnet_params_info knBasicWeights; + st_hrnet_params_info knTdfusionWeights; +}goodix_win_params; + +DRVDLL_API void goodix_heart_net_dll_set_params_inner(goodix_win_params * dll_params_in); +void heart_net_dll_param_init(); +#endif + +#ifdef __cplusplus + } +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/SPO2/02_PREMIUM_EXCLUSIVE/pv_v2.1.0.0_spo2wrnet_for_GH3228T_cd023f.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/SPO2/02_PREMIUM_EXCLUSIVE/pv_v2.1.0.0_spo2wrnet_for_GH3228T_cd023f.c new file mode 100644 index 000000000..6cdadc39e --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/SPO2/02_PREMIUM_EXCLUSIVE/pv_v2.1.0.0_spo2wrnet_for_GH3228T_cd023f.c @@ -0,0 +1,511 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_type.h" +#define NET_VERSION "GH3228T_cd023f" +#define NET_SIZE 3924 +const uint32_t Spo2WRWeights[] = { +0, 1073741329, 3999574012, 3471442047, 3780214886, 4000178303, 2929950804, 2495143628, +2970290559, 2156167122, 619404616, 789348584, 3319933902, 2136996736, 3954499501, 2155844344, +4260807495, 1448902467, 3148709986, 3708372977, 3363859666, 1082112248, 3206147517, 1058585058, +1058107101, 1058524726, 1058716434, 1060996767, 1057088519, 1062156363, 1060983320, 1064176116, +1051455998, 1059839158, 1063356877, 1065353216, 1058338418, 1058483133, 1062110265, 1060347853, +4096437775, 4173578114, 96249287, 142302726, 46176432, 4279652685, 4201656531, 120110439, +112533895, 4131872153, 4251881560, 4259020204, 4058346203, 268435456, 4187527169, 4110472463, +3229969796, 1082486148, 3221450872, 1073899927, 888286203, 1051730340, 3366000070, 85295127, +1387195297, 3675960313, 333756164, 333536896, 3441354296, 856907113, 3363813340, 183520783, +601333949, 3803309266, 3584077349, 2157104088, 3210167754, 1062573886, 1063109708, 1065353216, +1064663899, 1063962545, 4056203542, 27958070, 268435456, 240853462, 3222753533, 1075269885, +0, 1080528951, 150957696, 4169099135, 1745584307, 3212691973, 1065078385, 1056383158, +1065353216, 1059458681, 1059967368, 43763034, 36959618, 29778676, 268435456, 3221610982, +1074127334, 0, 1074752954, 1082923648, 52227200, 4221369216, 2135430759, 2159638586, +3531608289, 4135525715, 2715809664, 209761226, 2771812447, 3622469461, 773619865, 2162688333, +2206207203, 1937762878, 2160061178, 3207675224, 1060100829, 1054674996, 1052144291, 1065353216, +1059417531, 1049044443, 1059058566, 1055481670, 1065001480, 1055421370, 1051162596, 1058362508, +1050752920, 1053679741, 1061351470, 1058995308, 1058531701, 4181018345, 4261061511, 4178568690, +147835997, 155989941, 4121771723, 84695956, 4165806231, 4123362933, 4145569003, 217143882, +4292846979, 4156635296, 268435456, 22989955, 4148329231, 3218508640, 1071024992, 3215272250, +1066893384, 0, 1073250996, 2161419784, 232790274, 3435180006, 1200405713, 2278343415, +3087714316, 3456860347, 951516346, 1377696222, 4062543713, 3579915609, 4084432880, 1108686887, +876234790, 2136013639, 820272608, 3209444426, 1061856209, 1065348550, 1061910582, 1063509064, +1065353216, 4281893116, 4026531840, 74441011, 4282719262, 3228146934, 1080663286, 0, +1082660499, 2153771647, 4033469177, 2145588608, 3208234995, 1060656227, 1061204640, 1063926475, +1059131310, 1065353216, 4293907511, 4285572924, 23145812, 4026531840, 3223207109, 1075723461, +0, 1073459757, 2161707529, 562037750, 2161642503, 2148857586, 142607599, 276888280, +2021710558, 2148950699, 2407560104, 176169955, 981508607, 2161648597, 562031577, 612433660, +1573617582, 4109220736, 3208800200, 1061217016, 1060271586, 1052288904, 1062534431, 1065353216, +1052662144, 1043946311, 1043405011, 1049353392, 1041199451, 1049562776, 1046290015, 1051475883, +1044370844, 1050045716, 1050591949, 1049566002, 4026531840, 4091904097, 4112926457, 4256521358, +4274151182, 4129422542, 4107332473, 4137344156, 4163127615, 4050213461, 4283471552, 4288776512, +4148506786, 88599912, 4191362814, 4205773158, 3214316959, 1066833311, 3197379088, 1035358543, +0, 1072226857, 3188088941, 1045560072, 3180863642, 1049821279, 1057142566, 1053751385, +1034609895, 3198056750, 3190147577, 3203025485, 1060921984, 1044424167, 3125393333, 1052072978, +3178442557, 1044065743, 3187014746, 1059069745, 1036939185, 1055180309, 3181306100, 3171395037, +1049596484, 1053454790, 1042198871, 3185582551, 3195715016, 1047497607, 3163126620, 1028103420, +3182220766, 3163506534, 3148835688, 3193581754, 3183899052, 3174627705, 1030714171, 3172964331, +1052302730, 3182509810, 1045909100, 3179631113, 1039075737, 3172805854, 1056014575, 3157871968, +3179349434, 1047930853, 998135196, 3179998868, 1049233863, 1036866499, 3170565541, 1030639566, +1045211681, 993360752, 1024130666, 3185090281, 3188860645, 1037967182, 1014993599, 1035674196, +3188308867, 3192352835, 1043485487, 3199297430, 1040354856, 1033474467, 3199990705, 1045841800, +3175429609, 1044661920, 3199880136, 1029998133, 1021794559, 1021463703, 1033271914, 1034820233, +1029709998, 3181645919, 3147799899, 1049963030, 3199184164, 3199077444, 3155900674, 3203313546, +1037468479, 3192183590, 1044285232, 3198823559, 3205993607, 3197838891, 3205617185, 3172102450, +1053477708, 3195074063, 3191169307, 1043668327, 3183488291, 1052728242, 1034022353, 1046113422, +1044279750, 1041054848, 3191620331, 3187156697, 1041035348, 1034087071, 1032813201, 1023877648, +1042245215, 3188129766, 3167637752, 1043168907, 3203998333, 3191339179, 3162300078, 3202238577, +3163295464, 1032097768, 1052482054, 3179969028, 3203547446, 3132765183, 993714416, 999208604, +1045959648, 3174859416, 3195910896, 1041232965, 3155232172, 1051441667, 3196366384, 3196841661, +1048244070, 3192420112, 1033124028, 1048715737, 1044820215, 1044733986, 3188801261, 3187447003, +3187977533, 1049484017, 1047212308, 3167346802, 1046109428, 1040397796, 3180521555, 3191611651, +1031928783, 1037162464, 3189617626, 3193939535, 1026923543, 3187748320, 1049254874, 1035633574, +3197885329, 3189034114, 3175164678, 1045463575, 3197861566, 3188564876, 1050754530, 3182087459, +1045174693, 3189564905, 3144047360, 3183190091, 3191713387, 3171598323, 1029072817, 3212869761, +1065287423, 1935179521, 1420445853, 880764287, 1469249464, 3231250559, 1149484672, 904494893, +2160514461, 18154881, 3051126562, 2071985661, 388267929, 478137793, 3995744738, 2135774750, +1630175210, 3179323535, 3472780780, 3414159926, 2158349285, 3206592775, 1059026837, 1060511955, +1059792811, 1064969570, 1061210391, 1062931313, 1064696255, 1064581728, 1065353216, 1060282289, +1064066905, 1058351370, 1061899575, 1062189625, 1061840365, 1061057472, 1064851025, 4279120814, +98907296, 4164514887, 31336640, 4137201817, 4255047186, 4141284609, 122038685, 4254578309, +4138156253, 30501590, 4266867559, 4026531840, 57387976, 4221338006, 4223451414, 3226551897, +1079068249, 3220028740, 1071256481, 394255882, 4277088757, 3472631835, 1875497511, 4110793252, +536542958, 3436300312, 2145178391, 2158366636, 3144058459, 537956298, 3794362566, 620970623, +1015229128, 944261495, 3755134293, 3213671024, 1066115323, 1062815108, 1065353216, 1057691518, +1058210830, 4027065002, 171977037, 4198783646, 268435456, 3212988257, 1065504609, 0, +1084488549, 3902088064, 2131984401, 1105101007, 3211491700, 1063887489, 1060175172, 1061331196, +1061379347, 1065353216, 268435456, 159007971, 4235757866, 53669661, 3230840635, 1083356987, +0, 1068453332, 3873210587, 2137524409, 4005986557, 922452116, 260001295, 3239346407, +2135560412, 3502473221, 4118787726, 3656089621, 2159492934, 2134693288, 2154043287, 545238010, +1954486799, 337575808, 3218290695, 1070698903, 1058037646, 1046971298, 1051851149, 1053039682, +1047134333, 1057149333, 1049680280, 1052161499, 1045619643, 1065353216, 1054905987, 1044675046, +1049074662, 1044604299, 1049352733, 1050360702, 44440324, 4058223431, 4077551628, 4172568318, +118086542, 4130925078, 10311762, 4181443929, 1676601, 12985021, 4278335127, 4122072537, +4280091991, 4167096920, 4026531840, 4063318117, 3214821567, 1067337919, 3216110490, 1061298437, +0, 1078092990, 847190350, 487543542, 4044517401, 148893302, 652227143, 53421900, +1110843663, 3078575385, 3673671144, 3565223828, 3352014834, 3852175336, 2138860898, 273174138, +1076509756, 812991063, 3213074511, 1065523470, 1065353216, 1062390299, 1062765183, 1059857864, +4246158256, 4131911022, 4026531840, 4249656307, 3223861647, 1076377999, 0, 1091265068, +2132605823, 2145683408, 2142110530, 3208989910, 1061405244, 1065353216, 1059505525, 1064833704, +1059611897, 4026531840, 230433096, 4294700819, 163168176, 3224217651, 1076734003, 0, +1081132085, 3205163904, 3856695501, 4260593700, 3151986704, 2147692478, 2509275153, 2162720964, +368869587, 2160706589, 3538821504, 2147228912, 752910368, 2901246143, 2934893184, 2549530240, +269254657, 3208962441, 1061377990, 1056990552, 1061548569, 1063123537, 1060051909, 1058543253, +1053995739, 1058039691, 1065353216, 1054629078, 1052946365, 1044676395, 1062117442, 1059064284, +1062187328, 1059471454, 1060631745, 60177608, 4229137977, 4139826956, 4087864650, 4166052301, +4026531840, 4194234425, 4163332493, 4124766682, 4240524033, 4127614679, 4122431874, 4116267497, +4109987968, 4102945804, 4148880372, 3218808151, 1071324503, 3224008600, 1058411404, 0, +1078148423, 1044206622, 1053430767, 1056639557, 1049911082, 1058440975, 1045600926, 1051295666, +1049504051, 1037647009, 3191770066, 3176605117, 1050932703, 3174820307, 1061602744, 1059485086, +1064398268, 3186784299, 1057080053, 3202219812, 1056136033, 1046105521, 1043444907, 3205015334, +3189649948, 3188307446, 3196246667, 3179146919, 3203560180, 3179822049, 3187058748, 3128552276, +1041648308, 3174100737, 1045517449, 1019777518, 1034703778, 1045043416, 1034437962, 3196975499, +3191496178, 3185590886, 1045498901, 3197404380, 1048020441, 1040863381, 3197627345, 1042614714, +1046713908, 3198131318, 3198766142, 996709457, 3181169656, 1045292443, 1044576779, 1050344993, +1056386536, 3184294258, 3197472383, 3175578921, 3199081539, 3144412053, 1043539774, 1044330652, +3202181394, 1041005636, 1045004977, 3205629050, 1049268002, 3182377285, 3190240943, 1037542947, +3197596410, 3195379236, 1052643436, 3199977501, 1047425113, 3197377786, 3181277733, 3182788862, +1042819476, 1026024375, 1052178452, 1062627375, 1048699344, 3190138415, 1046713891, 3186239350, +1045117425, 1034666791, 1053827024, 1033318928, 1046457723, 1046647845, 3185454146, 1045705785, +1051733151, 3200514160, 1057248131, 3182674871, 3200709601, 1037699909, 1031837487, 1006291401, +3197752302, 3199361146, 3168744842, 3166192477, 3202962896, 3195819441, 1045525673, 1051631453, +3193334791, 1046767212, 3206113678, 3200771626, 1043584866, 3202866770, 1050384903, 1033989224, +3190094361, 3198226275, 3179364448, 3194067628, 3193627120, 3179984256, 1026714116, 1046937217, +3191408781, 1048741869, 1039644997, 3175093253, 1006261299, 3201985755, 1050332211, 1046510808, +3180478847, 1032136374, 3147490039, 3156853076, 3202540773, 1034998490, 1041386093, 1042093516, +3194414963, 1048838842, 1047218431, 3203886903, 3173541244, 3199707043, 1044541491, 1032495013, +3195946982, 3204284267, 3192613026, 3202755777, 3206369496, 3206167038, 3182001609, 1044610496, +3206695141, 1025742914, 3207162995, 3190237992, 1033926510, 3204469703, 1016325476, 1033196987, +1040847229, 986556084, 1039213138, 1037606384, 1033852052, 1043964737, 3175299710, 3172095444, +1046889179, 1041888244, 1045016466, 3167606236, 1031985124, 1043137086, 3152091620, 1035225234, +1029004097, 1035840556, 1045419555, 1038176065, 1036759116, 3193383753, 3188076789, 3193863542, +3194250162, 3204539587, 3201202884, 3192855357, 3196890203, 3189559290, 3203621266, 3199361486, +3191882711, 3197672037, 3195932476, 3191936557, 1041818141, 1041447921, 1052296868, 1048900640, +1045096180, 1048559016, 1046109303, 1045536288, 1049935330, 1028920180, 1048808803, 1049970427, +1036946671, 1044396132, 1048702558, 3192069902, 1044104997, 1022692071, 3193325444, 1040833267, +3170947908, 1045648860, 3157772117, 1039307701, 3163570032, 1034065563, 1028958764, 1041991661, +1041505426, 1043325243, 3171254946, 3180657300, 3194866221, 3190525733, 3199294064, 3196193870, +3199463310, 3196699841, 3202505541, 3198385079, 3198841009, 3172321174, 3196908579, 3198066250, +3200562002, 1029039458, 3170488326, 3199063454, 3187399720, 3201782278, 3161592482, 3196159509, +1008079504, 3198130902, 3173718175, 3188626816, 1004013736, 3187779319, 3190829947, 3196738791, +3189437767, 3206028153, 3201468674, 3199812335, 3211043262, 3204331987, 3204601631, 3198182051, +3201707061, 3204439094, 3201442752, 3192164362, 3204467515, 3206090076, 3198740671, 1046161400, +1045564701, 1026276283, 3190402442, 1018197843, 3174632526, 3193869603, 3184000161, 3196683500, +3185404950, 1039001050, 3167076693, 3173466538, 1038680372, 3187921736, 1036676703, 1045938084, +1045468858, 1048130775, 1039122045, 1043784999, 1041528726, 1041340713, 1046668346, 1041075353, +1043825556, 1049114319, 1047971032, 1032753709, 1029313411, 1021024999, 1033845186, 1049189557, +1056089301, 1044848926, 1041702435, 1051597150, 1050162489, 1051415908, 1048625733, 1049561815, +1051443101, 1049143972, 1054139670, 3138858509, 3154556626, 3188469329, 1033956264, 1022012934, +3163202846, 1016265402, 1027188642, 998388144, 3180865784, 3174574579, 1020684772, 3190393756, +3167259554, 3187329222, 3169705938, 1049869081, 1019289287, 1039851497, 1043585296, 1040284624, +3165753304, 3178708555, 1020028387, 1030497791, 3179713020, 3185570936, 3165444715, 3172774915, +3194711444, 3170019297, 3185565280, 1035067722, 1044192046, 1033560582, 1047646454, 1044225917, +1050325943, 1051781471, 1046614709, 1047472258, 1049488996, 1047448175, 1046005850, 1054123539, +1051552878, 3186433140, 1051908342, 1045315252, 1045900478, 1042618624, 1035767247, 1037349445, +1035625772, 1038703266, 3164920472, 1044664539, 1032962103, 1040455550, 1045053896, 1047505183, +1028626938, 1055238670, 1051567784, 1053226593, 1052511397, 1045555688, 1049611594, 1052122819, +1050461323, 1050747069, 1053543742, 1053701710, 1053314115, 1055454149, 1045603921, 3185700550, +1034118762, 1027765029, 1046001850, 1049282518, 1054410027, 1053263099, 1053190200, 1057085518, +1052260264, 1051294782, 1054363497, 1055658395, 1057376650, 1050397602, 1028055967, 3204779168, +1051165283, 3199060034, 1015434586, 3196551670, 3190132881, 3189400146, 3201557818, 1040310059, +3194891954, 3198020784, 1042232259, 3181103636, 3205506871, 3146463807, 3192915333, 3194937428, +3192271919, 3179929049, 3186448911, 3186279824, 3196884664, 1038624074, 3198972795, 3190574441, +3192791220, 1034949164, 3204879704, 1035713159, 3178805024, 3133200509, 1043005022, 1046042573, +3180108603, 1036066567, 1043876296, 1040412273, 992157139, 1044931277, 1033801378, 1001993338, +1051125452, 980588432, 1047165106, 1057725852, 3177620055, 1046745785, 3197840192, 1046115287, +3187051345, 1021989603, 3207838666, 1050298803, 3174591865, 3205121642, 3185729240, 1019092800, +3199477566, 3196132125, 3187210762, 3173990450, 3191146073, 3189666804, 1038903322, 3190308133, +3179104991, 3174745173, 3155812486, 3196784355, 3162974800, 3173762762, 1032730548, 3204351099, +1048602922, 3190191614, 1043808995, 3173691608, 1042183865, 1044401976, 1035975904, 3136504981, +1036386957, 1022102768, 1000442227, 1037334864, 3162021683, 1041669038, 3181804227, 1044662075, +3167439520, 1045482859, 1010268806, 3149675267, 1041230354, 1019399719, 1035211372, 995671644, +1049385789, 3193399728, 1030167322, 3113291125, 1048739671, 3198390191, 1044077803, 3197902777, +3196276819, 3198122390, 3191125423, 3126098112, 1016084564, 3188874343, 1035048294, 3193480122, +3193145197, 3164712549, 3188617304, 3193860309, 3196117929, 1036064769, 1051661908, 1032188600, +1045186531, 1054389045, 3175841084, 1050507500, 1045537066, 1043422537, 1038651935, 1033697223, +1048076991, 1052289794, 1043678328, 1051875333, 1051148103, 3182219426, 3191026425, 1051155526, +1014529312, 3197471896, 1048256321, 3182283607, 3181555839, 3166493318, 3191864542, 3185462581, +3148655300, 3195309716, 1043065123, 3198356886, 1037220351, 1041224640, 1038807009, 1049769968, +1035933299, 1039053252, 1034235137, 1030846339, 1035455333, 1032758431, 3183481625, 1041247586, +1025314249, 1015899369, 1048522195, 1040284473, 1032055917, 1044294601, 1037530753, 1024632712, +1052729858, 3162615869, 1037842888, 1051211259, 1005153287, 1043196842, 1050936932, 1017828821, +1044944134, 1049632166, 3195436656, 3200984197, 3196697582, 3212183823, 3198202226, 3203718804, +3209612534, 3199582069, 3207084980, 3209087248, 3204462988, 3201434064, 3204801848, 3201482707, +3204837220, 3198621381, 3187627553, 3195440504, 3204991436, 3193740726, 3206330529, 3199337545, +3198560827, 3201107288, 3199916300, 3193448608, 3201745551, 3192450750, 3196203269, 3200762595, +3192819433, 3197923589, 1050501025, 3190096331, 3198603341, 1032496965, 3200603316, 3190204723, +3190643421, 3203532039, 1025674547, 3196354077, 3199364556, 1034065596, 3202148342, 3203154387, +3197692596, 3209586531, 3207841881, 3197351592, 3209082851, 3201045638, 3208168413, 3210373688, +3189032283, 3213289782, 3211010264, 3189432870, 3211333506, 3208521700, 1032716729, 1050173237, +1048898507, 1051464987, 1046295172, 1049973526, 1049368198, 1046414740, 1044121406, 1047777361, +1048117580, 1052919503, 1043261441, 1045446692, 1028110394, 1033360188, 1042727732, 1045751540, +1056423025, 1045486825, 1048266443, 1050749906, 1042419437, 1052495743, 1034977604, 1048993759, +1051418716, 1043760254, 1052140847, 1019473235, 1001972890, 3188194230, 1030239043, 3176823834, +3187886460, 3169649097, 3175421077, 1023293770, 3188238475, 3162779693, 3182244277, 3188165602, +3187266789, 3188505129, 3158647493, 1049340214, 1036246129, 1045203528, 1046410823, 1043449254, +1042160287, 3172768984, 1015004516, 1043640645, 1040537647, 3184383089, 1046223398, 1028774538, +998725771, 3164426960, 3171524895, 1035360170, 1042227534, 1033992100, 1050334975, 1043073259, +1042674138, 1048807858, 1049048218, 1042115330, 1047576118, 1046729989, 1052142071, 1050487457, +1051491421, 3175920747, 1047604945, 1046070889, 1040853765, 1044564089, 1037023894, 1032866137, +1033981886, 1036121231, 3180634922, 1041130457, 1043426704, 1039041979, 1031952783, 1044234397, +1033005365, 1052567121, 1051354653, 1052900593, 1050031550, 1043388381, 1049033602, 1048503284, +1051047274, 1045013712, 1049188731, 1052923496, 1046377299, 1051520170, 1045920031, 3147280754, +1040203027, 1040178504, 1049771827, 1049299982, 1053689343, 1054889314, 1057068609, 1059017659, +1052815469, 1054388783, 1057544204, 1056136604, 1056430081, 1056237455, 3169737096, 1049973056, +1050399358, 1046807571, 1043600306, 1043358631, 1044801181, 1047240286, 1037783048, 1046674652, +1049479734, 1048773843, 1035072451, 1043313556, 1033684521, 3163759900, 1040143336, 1038231753, +1053475346, 1040323086, 1041911000, 1047091104, 1040247968, 1048738566, 1037459201, 1034193965, +1050918962, 1040227319, 1042141734, 1033020758, 1029229935, 3193842629, 1019700490, 3176917567, +3179431951, 3179178771, 3188805048, 3188362836, 3192324531, 3185084962, 3189019769, 3189894041, +3180724413, 3192685802, 3188355481, 1036228514, 1028421515, 1032123534, 1046014261, 1043465920, +1037814260, 3183988309, 1012572891, 1034057770, 1032584172, 3162695548, 1034781229, 3180237885, +3185382693, 993286166, 3182310819, 1034701037, 1040931252, 1042254767, 1050674764, 1048527338, +1048990504, 1049819508, 1049256551, 1050310939, 1046969642, 1048953125, 1052289122, 1050843332, +1049720731, 1031846553, 1042483255, 1032854077, 1044231991, 1043771010, 1034718409, 1041841208, +1041580632, 1032484616, 1030497807, 1046210822, 1037999566, 1044006432, 1036088836, 1042863688, +1027521358, 1049729157, 1045082474, 1048962873, 1037731815, 1036796590, 1048696336, 1036981464, +1044510972, 1032952177, 1041377669, 1049456077, 1045246971, 1045600846, 1040251117, 1035551108, +1046507324, 1047398059, 1051543372, 1051166886, 1051833353, 1053820519, 1057139990, 1056990300, +1055558368, 1055450437, 1058293270, 1053459194, 1057871613, 1053449162, 1026138942, 3190167889, +3191423136, 3190683684, 3171113677, 3196446282, 3200834728, 3172858666, 3197980465, 3196183840, +3193316845, 3199425640, 3194175025, 3198595565, 1043299162, 1042129328, 3204851658, 1037737646, +3200834962, 3187284228, 3200002512, 3121932675, 3190675541, 3191803152, 3184063066, 1006676693, +3188883558, 3192587960, 1029740715, 3192605891, 1033842321, 1049496923, 1044862670, 1045882303, +1050980333, 1048183766, 1046802477, 1052195702, 1052357963, 1035010380, 1054084234, 1031839003, +1054722260, 1032548184, 1051087954, 998732181, 3202667250, 3195078426, 3199348838, 3188526538, +3204664114, 3179745501, 1035686162, 3208962187, 3196344259, 3193415550, 3193756453, 3207590110, +1040064693, 3203671919, 1042647661, 3194730913, 1040422604, 3191340680, 3188371633, 3188050244, +1033914753, 3201703704, 1033585034, 3192766723, 3171844171, 3196996847, 3182808383, 3183905805, +3193759903, 1015949976, 1030755443, 1036575166, 1038461322, 3182272123, 1040318116, 1042815152, +3190493698, 1043854485, 1015428818, 1041689573, 3148795534, 1037194163, 1041843435, 3173560096, +1017409889, 3196411331, 1047593033, 1000387082, 3169113002, 3181310469, 1042389779, 3191034007, +1030265944, 1037257198, 1023730041, 3141168233, 1024450665, 1040913847, 3171416337, 1046292303, +1033658642, 1023981880, 3184023859, 3193383397, 3175681605, 3189042250, 3201471034, 3184055630, +3197183239, 3187873815, 3199793398, 3163396373, 3201487995, 3183595323, 3203137822, 3202383670, +1048033567, 3204275934, 3190682401, 3198087147, 3191764083, 3205411923, 3187739479, 3181333612, +3195330661, 3205379335, 1043938329, 3201181611, 3180246764, 3187712199, 1039035122, 3203581012, +1006868833, 3196322688, 3166586407, 3202467903, 3171053354, 3196180438, 3189666994, 3181444776, +3168684324, 3180274502, 3196087082, 3159641575, 3187684872, 1050917058, 1046156752, 1047837667, +1045866057, 1046736654, 1050668130, 1042330045, 1041931608, 1051368716, 1043094894, 1052422369, +1036165861, 1051563601, 3196503342, 3200849562, 1051798261, 3205020948, 3183357029, 3197685524, +1042759053, 3210945082, 3195522268, 1039501385, 3205953021, 3191008998, 3200598810, 3173281656, +3205181114, 3181542370, 1040771994, 1023700762, 3195749284, 1024097870, 3184333535, 3167500355, +3196759833, 1036062220, 3191504221, 3145556754, 3186025936, 1043022611, 3196756625, 3115379818, +3171226787, 1037457982, 1045898466, 3164855577, 1043164619, 1035451364, 1008430291, 1038878743, +1042511315, 3180005580, 1049555390, 1033331682, 1041133336, 1015265610, 1049987107, 3157669850, +1040793024, 1049299024, 3185165484, 1041199497, 978290741, 1041483279, 3187071413, 1045552314, +3175735214, 1034995668, 1041600615, 1048301256, 1016619073, 1032517731, 1040238546, 3189845619, +3189916697, 3196039522, 3189865147, 3192920927, 3191402493, 3175012595, 3181820255, 3198587732, +3180345726, 3197576417, 3188589283, 3200615573, 3179210314, 3197256450, 1042155692, 3189309723, +1032363984, 1018500878, 3193882249, 3194285598, 1052854574, 1049265288, 1051254334, 1045361756, +3204793168, 1050610659, 1049784114, 1049691483, 3210713230, 3207200828, 1037038493, 3205761095, +1037409618, 3201944327, 3201961443, 3204711049, 1049744176, 1046308492, 3204460996, 1042569851, +1052205389, 1016513416, 1040316657, 996501061, 1034323772, 1050639436, 3199320743, 1039531669, +1042829232, 1111117364, 2149990248, 777591337, 3358533396, 3254321102, 2983108973, 3065035952, +1222876594, 2827844265, 2291229330, 1837324924, 3094267265, 2378335676, 1400335952, 1197948730, +2863343299, 1706984858, 1683776622, 2772465771, 2141747833, 2173928653, 1229814389, 2777105781, +2611072195, 1953920086, 2254928516, 2807953247, 2596388233, 1956814937, 2156175248, 1704914551, +1637242449, 1635413117, 2405796988, 2845998491, 2644298163, 3368466879, 3452747959, 2593239250, +2525661577, 2038135166, 2373419162, 3366294705, 3184236681, 3120353203, 2695807939, 2628035258, +2526973079, 2342297744, 1890549905, 2440614010, 3549607601, 2932452563, 2694226108, 3283003903, +3587691493, 3118590155, 2308151726, 2206963355, 2442235522, 2508289405, 1701341915, 2505725806, +2576338523, 2136572829, 3510272401, 1196400051, 3048597937, 3890472158, 2474210205, 1016379025, +1851478891, 3831259980, 2189339040, 2408547247, 3254352722, 1689958305, 3247155865, 2558621669, +2457832845, 1960050541, 2260430478, 2808391346, 2710414272, 3864011039, 2233036145, 2680141954, +2796530302, 2843506307, 1500088452, 1097880914, 2003587659, 1230789455, 2186966618, 2373139350, +1903005561, 3804199065, 3083445445, 4293654218, 2161372917, 2189918605, 2256568700, 1884969835, +2609805423, 3547107743, 2359854972, 2630136968, 2341179604, 2911732629, 2124650634, 2493154701, +1869323172, 3062675574, 2141958543, 1639093670, 2462673249, 2491267744, 2611999187, 2139738040, +2039047534, 1785363298, 1952270685, 2210295398, 1531199818, 2491180142, 1431398471, 2171765334, +2142403448, 1836483208, 1887408777, 2558833307, 2341107604, 2508425872, 2039384451, 2271909750, +2443263102, 2108268918, 1956811398, 2357426045, 2039780731, 2123204233, 2373086867, 1501915481, +2138283921, 2358215340, 2054849178, 2442959465, 2460003221, 2526121119, 2660342165, 1972741495, +2139267980, 2492364146, 1703411550, 2070639970, 2778770052, 1819186264, 1550218879, 2306443389, +2692260787, 2139392879, 1940758429, 811109762, 1836752673, 1079864206, 2828180887, 2593948840, +2991362161, 2492965040, 2526581905, 1900308591, 2358482852, 2661706620, 2275702945, 2357891996, +2661335393, 2156162721, 2862125706, 2289870275, 2322495618, 1649315495, 167788401, 2153997177, +1078091104, 2524599454, 2157689946, 3582033098, 2744295573, 186917543, 3045219351, 1702053480, +456610604, 3234329290, 3900347517, 2748226787, 1622856910, 1249784392, 2358620269, 2105529774, +3819073186, 3249975234, 2393429409, 3619001254, 1919947462, 3461437845, 1275033977, 1167691412, +1400936112, 2631236758, 2412367272, 3047141747, 1402456769, 2091277411, 3365041313, 1400082328, +3502086711, 3703500006, 3236479999, 2531035089, 2271234656, 2442229363, 1752993913, 2757845062, +1194350248, 1479298472, 2912033799, 2070584942, 3107700841, 2862410113, 1542675116, 902407013, +1750415902, 503670358, 1854908756, 2442096695, 3700791416, 2324742052, 1904246955, 3352142714, +2646971575, 1654958800, 2946456716, 2539148441, 759705156, 1956423737, 2042436515, 2422761836, +2021740140, 1686396763, 2472174180, 3265368761, 3333996209, 3286093780, 2022423754, 1971017073, +1417042008, 1685093230, 2291912569, 2894645439, 2360971919, 3215431839, 2319871376, 1670014563, +2173868641, 3095557485, 3030739327, 2444861055, 2543751607, 2793975463, 2949904833, 3903444713, +3940789227, 1703321521, 1198019684, 1549233492, 1632325223, 2927886197, 2508892836, 2624632478, +2458876549, 1346078079, 1868173568, 792088922, 537990706, 1838303526, 1851148686, 2391047054, +2340389258, 1412522829, 2085578849, 2188789642, 1265132169, 1701278596, 2358141547, 2359400074, +1700115360, 1533632860, 1634956650, 1636724550, 1768978530, 2456309041, 1215920216, 1902923086, +1565288244, 1564944669, 1718837317, 1180334695, 1331834412, 1433764687, 1564503915, 2355516547, +2877127762, 2745215412, 3031407008, 2947916194, 1163820900, 1399155555, 2119200132, 3162135398, +2259844457, 1685754493, 2542308525, 2173346178, 1784111940, 2138928259, 1719309403, 1500563332, +2508357027, 2308335240, 2525007773, 3565118831, 2912126604, 2630920594, 2108215220, 1769175172, +1903389298, 1532846687, 4285034327, 1635683442, 2372627610, 3228469174, 2811086481, 2965727397, +3501491319, 4141477046, 2966145504, 2372505452, 2272551059, 1700222336, 2377811112, 3413412755, +1989904779, 2562168722, 2238624430, 2307749759, 1719115883, 2677633629, 2122225337, 2895957630, +2040428942, 2173801892, 1941206176, 2293603442, 3216179111, 1787938189, 2325375371, 1886938210, +2119656039, 2594463613, 2275706022, 2060298141, 2490334888, 630882969, 1311375411, 1232238713, +993998919, 2505132868, 925523786, 1883662651, 1935105142, 678907262, 1331655537, 2220980106, +1634108564, 1919385177, 2422890082, 2845476236, 2208738956, 2255835777, 2475583048, 2407352175, +1837260903, 1717577567, 1870098066, 1601136456, 846012779, 588318279, 1767718457, 1180119623, +1614612821, 2477631107, 1115383905, 759452742, 3416796011, 3504144315, 3083321054, 2209067432, +1751679634, 1719493991, 2105636486, 2793573747, 2927128658, 1583984752, 2356101233, 2457166144, +1786411375, 2037089166, 2173668453, 2454162574, 2288702313, 896160361, 2319018314, 2342742384, +2425864632, 2493481126, 1584680582, 2022732671, 2474743171, 2089911170, 1988727199, 1268753554, +1467264624, 2710288209, 3637497735, 2506132184, 1949973209, 3566796462, 3970942906, 1656789670, +1166126516, 944326451, 3293797983, 901094506, 2862400673, 2229712601, 1844100510, 3218442156, +1451327628, 1635415407, 2109331564, 2496004258, 3671826044, 3654458239, 3210432655, 2354656570, +2176683133, 3250364823, 3612320676, 694325381, 2003591995, 2706264634, 1499211951, 861548880, +1531192931, 1261254685, 3569398709, 3151614091, 3300514766, 3116874699, 3855797174, 3228878027, +2327294314, 1089271502, 3364732262, 2377019827, 2604061524, 2309391019, 2610351581, 2445140088, +3718948818, 2204193740, 2407774876, 2893252220, 3017374804, 4290299352, 3439119571, 3598823641, +3117336275, 3620251838, 2646847915, 2629740961, 2878656717, 1819768949, 2578809745, 1707053952, +664174746, 487325741, 760885315, 1279933007, 2996005182, 2088024438, 3097334965, 3030826897, +1065372625, 1133548844, 1748926079, 2139328417, 2692724361, 2846331527, 3720922328, 2614539224, +3677309339, 2057729641, 2324991852, 2340586654, 2054773605, 2406175870, 2640477832, 2093250207, +2339795349, 2173997925, 2258733225, 2373281383, 1855358086, 1939246202, 2005700718, 1534167410, +1347833425, 1130318949, 1163480924, 2170640224, 2356765295, 2105503599, 2005166985, 2054122607, +1182107228, 1935832191, 2036881027, 2107280240, 2694424987, 2258140294, 1635812493, 2271707741, +2325965969, 2190377345, 458708857, 977351740, 688923175, 792079145, 2105440588, 2072080771, +1752921975, 1601798784, 2206297088, 1938786670, 2507696259, 2022612873, 2006021278, 1734314363, +2643489681, 2040500876, 1651406425, 2188869762, 1919511170, 1618506349, 1296655711, 1986023761, +1934791552, 1751862630, 1431729757, 1952414308, 1937597287, 1514953336, 1683246179, 1854434640, +2019070042, 2407884648, 1484810613, 2138147968, 2287434121, 2104135310, 1871212434, 2273347976, +4285501818, 2324862358, 1990690691, 2290460286, 2358547115, 202664216, 621427538, 890710548, +2281719571, 2141033373, 2863969720, 2897393336, 2861545646, 2428028053, 3483608242, 2999172776, +2595331240, 3199307168, 3015166907, 3116284350, 3166473348, 2695277738, 3182021837, 3100155093, +2690957191, 2693501329, 2796719511, 1654357951, 2021823860, 2627904409, 2509936304, 1305291913, +2930222277, 2491854493, 2625282459, 1923593134, 1077359941, 642992697, 758725936, 184575782, +1547517526, 2253613667, 1264870491, 2339078749, 1954710625, 2542626953, 1837394070, 1319003013, +2339473272, 1701733024, 2491178865, 2508565144, 2258085249, 2710287539, 1112966826, 1512063053, +522074657, 1077033237, 2289966907, 2675669872, 2190965140, 2860810108, 2373475141, 2545983158, +2713241244, 3772356778, 2154607530, 1698393446, 1417034578, 1618826812, 2643500134, 2074984086, +3551505103, 3115427245, 1314416128, 1538732647, 1433974890, 2207425946, 2125174685, 2844292241, +2561316236, 1795204742, 1248355606, 2808894835, 1670874207, 1415137704, 1482439501, 1098604686, +2176429160, 2293269200, 3265176985, 2795475098, 2746991773, 2678107592, 3197154461, 2832311439, +2728899759, 2947782318, 3133059741, 2445387429, 2358618535, 672609337, 1512439889, 207890728, +2369147188, 3213867453, 2728840079, 2879492521, 1095477668, 1246973495, 1681936743, 2169585988, +2107285306, 2611913103, 2609091737, 2679015560, 2676789651, 2056498826, 2323746486, 77496215, +825433623, 1010186796, 909328980, 2809480526, 2795158417, 3100091827, 3516721593, 2945490326, +3602499001, 3521434557, 3751929072, 753121683, 419439893, 775045944, 1531849792, 3079364431, +2496697562, 1973347978, 2642321331, 640560010, 576069938, 1650806093, 1535203697, 1640872121, +2742803123, 2613072042, 2124727423, 2189133933, 4139494075, 2759041935, 1381329031, 541404433, +1362906426, 1429748777, 2084009323, 2373626259, 2593100193, 2358686598, 2091621790, 1465539671, +1583706204, 1886347898, 975208294, 1363632487, 1935823956, 946229594, 2240895555, 2191888225, +2390983306, 1887403645, 2124250210, 1870566243, 1835953539, 1599108460, 1904251790, 2742060194, +2490533256, 811960975, 1363095601, 1280002383, 1145782846, 1736329302, 1734109795, 1668510046, +2103997315, 1517617249, 1600877909, 2003913305, 1516531857, 3452262745, 3050230728, 3687631796, +3485124796, 3247605169, 3198919588, 2965625026, 3553933556, 3488455591, 3298668501, 3386900417, +1121444523, 2053138312, 1718514047, 2156231292, 2156107905, 2576979157, 3451559576, 3197732814, +2574951854, 2712578788, 3469650659, 2175774899, 2662191000, 3233334209, 3569590192, 2932189900, +2343098844, 2174452335, 2474345851, 2541326462, 1986957694, 2071952761, 2087875199, 2239597415, +1279146752, 994597186, 995314506, 1581011300, 2254015349, 2307685542, 1920107661, 1500542585, +1699104851, 1346648656, 1112095576, 2357881129, 2088986228, 2273866093, 2004582007, 1347845258, +1499752782, 1313368927, 1416781386, 2004314753, 1870237053, 2440464782, 2809296265, 3974676367, +3034044631, 3219968496, 3538808828, 1466729846, 2171362715, 1650950509, 1347116883, 1514950752, +2474345068, 2426119528, 2726913926, 1907078051, 3366226121, 2077145027, 1788913854, 2726201197, +2646515330, 2659885501, 3032376487, 2409982665, 3113932444, 2613536936, 3064319093, 3148848293, +3435626432, 1264616120, 1617652041, 2139587416, 1754302577, 1493124980, 3266606493, 2055952974, +942770025, 2654488926, 2429653944, 2727262856, 1718530920, 2521332559, 1869572497, 2982395019, +2359020923, 3831675295, 1388429980, 3853345485, 2057997418, 663837184, 1329178416, 2672133019, +2210686602, 2439425599, 1436110957, 2237248153, 1467562333, 1783271337, 2352829833, 507061085, +1656697378, 2071754653, 3165563541, 3432497078, 3014483563, 3182796473, 2845743270, 2659362218, +1482271664, 1397761126, 976052517, 1614623286, 1954046781, 2341045138, 3043857568, 2528088937, +3164848518, 3230631632, 2511779257, 2311367643, 1192971871, 879320619, 927683133, 2644597295, +2424998574, 2361438377, 2494993306, 2947061721, 2827385508, 2760146854, 2056292473, 1953075585, +1801416554, 2241429610, 1499626084, 2831427327, 2912991444, 2748104621, 3434459344, 3161544120, +1664705917, 2775807885, 2156959882, 1802470534, 1465475970, 1010910569, 3411826774, 2038477945, +2793114267, 2609870749, 2361099882, 1704755056, 2172754054, 1869896306, 2304166993, 1704104343, +3145826197, 2574557301, 3264116098, 2759949672, 2983825051, 2777467548, 2186236261, 1801604946, +1566390840, 4280958268, 1785490758, 1804433024, 2052623457, 2004834940, 2222097040, 2189126280, +2440661612, 1351709822, 1130246730, 1130194513, 1211847250, 739138121, 1345060934, 875769619, +1194143310, 864310579, 1061902375, 943671629, 927675969, 542131476, 538788109, 573515071, +1429625127, 1515676251, 2135580280, 1633899336, 2052940633, 1616800352, 1735155578, 2038328956, +1952077162, 2839269486, 2119645570, 2725013096, 4285231246, 2295176626, 2761989708, 1604161102, +966568612, 3267982262, 2225164192, 1347116168, 3245959801, 2657584094, 3532534226, 1706116206, +2699781753, 1250918771, 1050030948, 2053276023, 918602396, 914198086, 1898361320, 1866741664, +778275680, 1648073342, 2391638842, 2788266378, 2896942728, 2926406523, 2627297685, 2158414518, +2708508564, 2909497989, 2524941698, 2205649541, 2239069841, 2390390668, 2540801420, 1515998570, +1566665821, 1635676260, 1902737760, 1400857176, 2589749109, 1788577386, 1819446894, 876615474, +992625688, 1293895265, 1901145910, 1231390343, 1851948656, 1900967827, 2590921597, 2376958095, +1904918399, 2342233514, 2441053353, 1735165321, 2440784515, 1735491702, 2155964927, 2809035625, +2207021692, 2391313012, 1249743499, 2141939554, 1398433898, 2002222160, 2423817607, 2593560180, +2559676062, 1837791107, 2676520331, 2425207181, 2007142294, 2390396557, 2558495127, 2626919816, +2106040464, 2578083216, 2358220702, 2191168897, 2393341342, 1550940322, 2609680023, 1834781078, +1687181943, 2022471058, 2289994103, 2207745666, 11769496, 2104785526, 2038461581, 2390787979, +2138083961, 2425919856, 2391572612, 2124258192, 1854112381, 1919186302, 2037154420, 2088340613, +1904572291, 2577176979, 2594207860, 2475263097, 1717803133, 2071298422, 2005502830, 2323027084, +2071490969, 2156299407, 2207742336, 2021094813, 1702917467, 2153674376, 2005760908, 2021748099, +2205124980, 2037937263, 2004123778, 1979665789, 1737061246, 1483829864, 2237367414, 2170718853, +1433098856, 1129205354, 1380020832, 2846591605, 2946477235, 3115751121, 2493300110, 1618776233, +2104186204, 1903711346, 1752848788, 2763242619, 2846612917, 3183319212, 2124066722, 1467123354, +2238617961, 2106619292, 2190176922, 1952082786, 1567981668, 2322754423, 2576310150, 2460917402, +2310643867, 2459206795, 2341011636, 2341242488, 2290315126, 1718583914, 1804363632, 2457436529, +1786020992, 1734768745, 2391313524, 2290124416, 2407762799, 1937016713, 2290256022, 2526188679, +2022207338, 2020243055, 2155711111, 1888518269, 2155181436, 2375125370, 2591846588, 1803588502, +2019004298, 2240511109, 2173013875, 1938199673, 2136703357, 2037088638, 2037476992, 2173467254, +2928182152, 1767476480, 2155047513, 1855028091, 1635546487, 1802851469, 1684236373, 1418168434, +1654559071, 880038190, 2976928192, 75192611, 1613852210, 2474148006, 2352785008, 880696421, +1735030632, 1347906854, 926234289, 1580011651, 2072011858, 2342615406, 2106360925, 2424725858, +2456856203, 2057729147, 2425914512, 680491924, 942351872, 272386370, 1075784532, 223417400, +2289732708, 2172745070, 2292015768, 2610265726, 1801557383, 2288616595, 2123206755, 2579280554, +2141693038, 2055368836, 1704106869, 2036489087, 1933993607, 1586067040, 2205979278, 2359462758, +2893644984, 1871816835, 1819967618, 2321196126, 1938321270, 2390337650, 2391567492, 1011969389, +1145269829, 2323997046, 2474934148, 2593821583, 1903919745, 1718452331, 2566869134, 2088336735, +1768584045, 1853705074, 2002814825, 1854174350, 2070637173, 1836217955, 1531271273, 1817731670, +1835885418, 1719427165, 1380998524, 1615548297, 1802988386, 1112762726, 1513177969, 1635863131, +1617198709, 2036233325, 1550869597, 1653106536, 1584953955, 1735017571, 2322237857, 2289654926, +2155444618, 1818526043, 2172937324, 2155645287, 1787329928, 1869348720, 1098010173, 1148665649, +1313635206, 3335604065, 2932261844, 3114845123, 2997408686, 3650455245, 3232730563, 3101084331, +2879444479, 3655836344, 2813510858, 3167485386, 1120457130, 2053340558, 2558880905, 2257675878, +2509735775, 3029969598, 3197283208, 3298792929, 2591989965, 2190385618, 2881268924, 2611122603, +3368475064, 2831270849, 3703754194, 3570382547, 1938086085, 2708768431, 2072483460, 1720615574, +2760598124, 2122485382, 2676594091, 1955110036, 927681913, 1480077163, 1548242512, 2540127291, +1869904749, 2170515820, 2455537023, 1650360439, 71970048, 1260926013, 1648570958, 1884395568, +1972672891, 2069392758, 1987211647, 3031992940, 2308616065, 2426509711, 2691531403, 1550022497, +1481662574, 1669364825, 4134232422, 1920696147, 2339077758, 2123470965, 1888064142, 2272499073, +2141162872, 2273148287, 2592964984, 2006024310, 2122154631, 2289992831, 2692189323, 2188411008, +1803191189, 2424212098, 2325052307, 1786680201, 2424997243, 2340128124, 2022150764, 1801871991, +2222153081, 2039052897, 2474019987, 2642646396, 2357489284, 2290449762, 2240055403, 2340582794, +1903979392, 1929426571, 1904683390, 1314475352, 1044483653, 2991021142, 3436952475, 2896471235, +2846083495, 2897586346, 3467424449, 3537093822, 3819892156, 4285577177, 1891735724, 4058949567, +3051859857, 2140376362, 2287844469, 3046086063, 2479464615, 2794902639, 2340459195, 3396725189, +2526901393, 2592393647, 2979576224, 2440727990, 2376300652, 2896734613, 3015024300, 3148593599, +2161810079, 2207148628, 1820629361, 2808320918, 1853394335, 2051175227, 1870219117, 2274139258, +3016012905, 2410185614, 2258350715, 2828306350, 1532043376, 1835222294, 2334538587, 1867272248, +2758511294, 2088539050, 1869257847, 1383179632, 1363236976, 2370921837, 1265923928, 2592969026, +1821940347, 3013586096, 3686909375, 2795350881, 2040229548, 2205188980, 2641720451, 1886936832, +2039181460, 1902744431, 1987279791, 3092998801, 2036499098, 2375320456, 2425455008, 2356647313, +1569099900, 1954051435, 2490395244, 1584506484, 2239524255, 2842187113, 1470325370, 1719432537, +1970367889, 1834708810, 1835576928, 2108056430, 2088668568, 1684643688, 2523425654, 1920307807, +2377092483, 2576527989, 2574682761, 2323547290, 2003332214, 4283989105, 3245645450, 2577700237, +2709294219, 2879559284, 1499356190, 1417251931, 1415146332, 2540791913, 2997988319, 3028726678, +2914025632, 1016510371, 1900834320, 1953045363, 459109902, 1133927031, 1044604272, 2122724961, +1380737870, 1744834395, 774586206, 2198613563, 2808887637, 2526395809, 2845610679, 2175177603, +2143455165, 2036883313, 1803310215, 1736806497, 2033138769, 1297424747, 2415935416, 1931540780, +1757513703, 2201366702, 3960144790, 7451984, 2398906593, 1584018595, 1308642221, 2487153475, +2373280234, 1330859195, 3003149514, 1849472584, 1906872750, 2132886965, 3423542948, 257147962, +1543480244, 3346745405, 1023423147, 1635630660, 2094875592, 4151293244, 3329097804, 1521713574, +1975071628, 3814904908, 3848274005, 1892310492, 882795605, 2636013235, 3358261394, 794732382, +2012245681, 867059345, 3710660, 4267028797, 3328486025, 2553571745, 2986475666, 1046724188, +1357339829, 1353462935, 2571075042, 2101018428, 746684145, 2774308270, 2050839654, 2608513905, +820248761, 2450813546, 2283360694, 1061349960, 1711240436, 1503020695, 1442866602, 2469389101, +1218267894, 6501194, 1011708036, 2939926537, 3465139899, 1773323985, 4286869911, 1819226277, +3393746494, 2899755879, 4007692349, 46477823, 1214127959, 1389576518, 1736760831, 137411092, +1424663764, 4259163648, 3063949428, 298340022, 2257280323, 4287679930, 4137826648, 381962183, +1554979893, 1167162935, 2074607499, 2256830053, 3309878399, 3124619724, 1624671488, 2007867337, +1086023072, 986556891, 1255764104, 3905581392, 2785046313, 2942366121, 4287853618, 210129331, +2090798413, 3730287724, 2957508689, 72732548, 2143486161, 4150722403, 3196078125, 817854965, +1970947411, 3849551872, 766776677, 2614774200, 2244268868, 3329145982, 3227726106, 963616429, +2008219753, 3617624641, 4286462585, 182998183, 2108975468, 2461093632, 1174236838, 1005588121, +879032648, 2250709088, 3050805628, 2952816472, 1227059541, 2277181184, 3978962151, 1446378264, +23989941, 693851024, 1331647425, 2591576943, 3330867072, 2434662316, 3017015599, 3015839999, +3660537922, 3080935749, 2234515604, 159229807, 1388531909, 3412166836, 3479531887, 1132169352, +1485963396, 2415897180, 2341820502, 4170597793, 1747209811, 1167275888, 1571195834, 2804706048, +2994048137, 4282560159, 796494437, 2744807375, 1102536364, 1266442358, 427520663, 3683148434, +3042049944, 3563430995, 3677103954, 76133281, 1473773731, 1016280682, 110192578, 3551362407, +3209953153, 1434764287, 4106205274, 543906461, 2400339489, 3011815829, 3192863069, 542478470, +2092433573, 362132874, 1504362403, 4284052855, 2416740432, 1519585536, 793081533, 3295196228, +1818725023, 28410624, 1188719201, 3211149326, 1968088164, 1047930258, 1058077054, 3195213762, +3172068641, 1037083392, 3199290160, 3190810010, 3191101268, 3177867394, 3216281462, 1034079538, +1037628998, 3216993604, 1051294694, 1040306213, 1054331623, 3195193217, 3205042508, 1013177149, +3174890906, 3204078746, 1055382020, 1048493948, 3192172859, 3199930841, 1066843317, 1040417215, +3202514636, 1043437172, 3196864225, 3191710319, 3196627622, 1041420978, 1032051425, 1033969306, +1034689191, 1045201520, 1030816114, 3196743503, 1036266732, 3188901321, 1058093398, 3190885268, +3166849516, 1053422227, 3154349190, 1044440478, 3185250501, 3185433520, 3191817392, 3173354491, +3189560285, 1050689749, 1041869260, 3181591239, 1019383768, 3192930724, 1058101848, 3190464064, +1024318092, 1041742650, 3168562461, 1048195374, 3184696862, 3216057297, 1068482953, 3214881081, +1067315927, 3234987196, 1087503548, 1057921567, 1059576087, 1057527962, 1059869773, 1059935257, +1062565932, 1054567980, 1055934164, 1060113955, 1063546876, 1063286439, 1062820932, 1065353216, +1059717957, 1055044951, 1056698388, 1059235467, 1060375340, 1060677206, 1057916914, 1057652166, +1053917533, 1059083774, 1052269900, 1060184169, 1059124754, 1061477498, 1056532185, 1052272069, +1055281643, 1057635352, 1060379793, 1051204302, 1058416541, 1060006691, 1061419975, 1054937523, +1061235429, 1052790966, 1055892888, 1060132037, 1058809836, 1058539090, 1061701273, 1056931618, +1053633995, 1059829230, 1055759650, 1062913075, 1053071356, 1059480047, 1061441591, 1059342007, +1055999485, 1060575684, 1057885457, 1063821826, 1052438328, 1065353216, 1059979609, 1063429017, +1053774029, 1062372751, 1057072245, 1050815640, 1050033265, 1043018837, 1058087866, 1057225763, +1057472273, 1051448397, 1046388967, 1053507959, 1054771718, 1056329752, 1053123053, 1055555522, +1057584925, 1047416510, 1047729929, 1046796289, 1051578329, 1048401007, 1053878631, 1058587683, +1051487216, 1060015917, 1053785070, 1056318049, 1057975118, 1054732544, 1050208612, 1057288790, +1053033657, 1050682586, 1048891004, 1046460132, 3189681285, 1041024799, 3196711699, 1049163915, +1040619896, 1028321096, 1031040341, 3193175832, 3171861617, 3196079026, 1049402785, 1032310106, +1047353772, 3197765313, 3180313333, 1035898995, 1029101441, 1037491068, 1016311807, 1029377976, +3181481127, 1046606139, 1046980825, 3170404254, 3129182093, 1044579493, 3194416252, 1032688604, +1044922561, 988133882, 1047356562, 3190925225, 1043887229, 3174346728, 1051735017, 3192145061, +3172751232, 1017827586, 1028093246, 1038227108, 1001421494, 1054986195, 3192711542, 990419090, +3195085887, 1041128997, 3192068156, 3184379530, 3188617818, 3173074324, 1041456962, 1009650467, +990787154, 1041447534, 3196348620, 3196943026, 3180609328, 3188344222, 1033624404, 3188267753, +3190436579, 1011796963, 3173869973, 1033920345, 3199742386, 3184478387, 3185633928, 3181073513, +3190901377, 1057583437, 3188456474, 3189327578, 3181075734, 3187278857, 1041613697, 3176336589, +3183609472, 1024654348, 3196639283, 3188975902, 1047228155, 1043238559, 1026972482, 1017758561, +1040265668, 1048281270, 1045654027, 3171579020, 3179324414, 3171683725, 1023724961, 1036536208, +1041774111, 3185681164, 3162958865, 1044762653, 3185853448, 1040950808, 3183031591, 1037163404, +3181097716, 3192944701, 3184692725, 3183998343, 1048008498, 3190456268, 1040353281, 1045661915, +1039646220, 3169876660, 3188798258, 1016365490, 1038780111, 3187706760, 1044572204, 1034158982, +3181052333, 1020570210, 3188436346, 3186692277, 3169791380, 1024201487, 1031101508, 3190939499, +1033361538, 3163140062, 1043798465, 3180771913, 1042875665, 1054349203, 3183265110, 3170239690, +1049288213, 1030572887, 3173707204, 1040251286, 1033934290, 1024237712, 1041888006, 3179315546, +1016084168, 3194920421, 1047469739, 1033404872, 1023265531, 1049500085, 3198488456, 1046243196, +3182480057, 1036598369, 1016299742, 3180404920, 3178300419, 3195842785, 1049630190, 1044212751, +1050209738, 3201718112, 1036951145, 3174397558, 1011283832, 1048922550, 3190459611, 1037349260, +1043032796, 3172570506, 3192970395, 1019381837, 3179074634, 3171671988, 1053123825, 3155715284, +3176653376, 3197451892, 1040528991, 1025842119, 3172699243, 3159077121, 3190454845, 1036579691, +1034102014, 3184608221, 3173236380, 3187247908, 1040835651, 3191247130, 1049566217, 1048694648, +1019362177, 3187510235, 1014081150, 1025985867, 3166942466, 1029963407, 1018500061, 3167145142, +1015247949, 1046534753, 3146050964, 1042003374, 1021866089, 3163759270, 1049638554, 1045233032, +1038264781, 1041385495, 3188168587, 3199635024, 1042193764, 1044473208, 3165704205, 1046415037, +1045263052, 1034938499, 1046903359, 1047791629, +}; + +uint32_t* get_Spo2WRWeights_addr(void) +{ + return (uint32_t *)(Spo2WRWeights); +} +uint32_t get_Spo2WRWeights_size(void) +{ + return sizeof(Spo2WRWeights) / sizeof(Spo2WRWeights[0]); +} +void get_Spo2WRWeights_version(char* ver, uint8_t len) +{ + memcpy(ver, NET_VERSION, len); +} +#endif //#ifndef Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_ecg_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_ecg_config.c new file mode 100644 index 000000000..1bcaf9133 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_ecg_config.c @@ -0,0 +1,31 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_ecg.h" +#include "gh3x2x_demo_algo_call.h" +#if 0 +const goodix_ecg_config external_cfg = +{ + .fs = 500, + .valid_channel_num = 1, + .qrs_flag = 0, + .mode_type = 0, + .ic_type = 0 +}; + +const void *goodix_ecg_config_get_arr() +{ + return &external_cfg; +} + +int32_t goodix_ecg_config_get_size() +{ + return sizeof(goodix_ecg_config); +} +#endif + +void goodix_ecg_config_get_version(char* ver, uint8_t ver_len) +{ + uint32_t copy_num = ver_len < (strlen(ECG_INTERFACE_VERSION) + 1) ? ver_len : (strlen(ECG_INTERFACE_VERSION) + 1); + GH3X2X_Memcpy(ver, ECG_INTERFACE_VERSION, copy_num); + ver[copy_num - 1] = '\0'; //Èç¹ûECG_CONFIG_VERµÄ³¤¶È´óÓÚsize£¬ÐèÒªÌí¼Ó½áÊø·û +} +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_hba_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_hba_config.c new file mode 100644 index 000000000..00d3781b6 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_hba_config.c @@ -0,0 +1,31 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_hba.h" +#include "gh3x2x_demo_algo_call.h" +#if 0 +const goodix_hba_config external_hba_cfg = +{ + .mode = HBA_TEST_DYNAMIC, // ÓÐЧͨµÀÊý + .scence = HBA_SCENES_DEFAULT, + .fs = 25, // ԭʼ²ÉÑù + .valid_channel_num = 4, +}; + +const void *goodix_hba_config_get_arr() +{ + return &external_hba_cfg; +} + +int32_t goodix_hba_config_get_size() +{ + return sizeof(external_hba_cfg); +} +#endif + +void goodix_hba_config_get_version(char* ver, uint8_t ver_len) +{ + uint32_t copy_num = ver_len < (strlen(HBA_INTERFACE_VERSION) + 1) ? ver_len : (strlen(HBA_INTERFACE_VERSION) + 1); + GH3X2X_Memcpy(ver, HBA_INTERFACE_VERSION, copy_num); + ver[copy_num - 1] = '\0'; //Èç¹ûNET_VERSIONµÄ³¤¶È´óÓÚsize£¬ÐèÒªÌí¼Ó½áÊø·û +} + +#endif //Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_hrv_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_hrv_config.c new file mode 100644 index 000000000..7469f61df --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_hrv_config.c @@ -0,0 +1,34 @@ +#ifndef Goodix_DSP_EXPORTS +#include +#include "goodix_hrv.h" +#include "gh3x2x_demo_algo_call.h" +#if 0 +const goodix_hrv_config external_hrv_cfg = +{ + .need_ipl = 1, // ÊÇ·ñÐèÒª²åÖµµ½1KHz + .fs = 100, // ²ÉÑùÂÊ + .acc_thr[0] = 200000, // acc Ïà¹ØãÐÖµ£¬Ä¬ÈÏֵΪ£º20/10/3/3 + .acc_thr[1] = 100000, + .acc_thr[2] = 30000, + .acc_thr[3] = 30000, +}; + +const void *goodix_hrv_config_get_arr() +{ + return &external_hrv_cfg; +} + +int32_t goodix_hrv_config_get_size() +{ + return sizeof(external_hrv_cfg); +} +#endif + +void goodix_hrv_config_get_version(char* ver, uint8_t ver_len) +{ + uint32_t copy_num = ver_len < (strlen(HRV_INTERFACE_VERSION) + 1) ? ver_len : (strlen(HRV_INTERFACE_VERSION) + 1); + GH3X2X_Memcpy(ver, HRV_INTERFACE_VERSION, copy_num); + ver[copy_num - 1] = '\0'; //Èç¹ûNET_VERSIONµÄ³¤¶È´óÓÚsize£¬ÐèÒªÌí¼Ó½áÊø·û +} + +#endif //Goodix_DSP_EXPORTS diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_nadt_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_nadt_config.c new file mode 100644 index 000000000..2259bd96f --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_nadt_config.c @@ -0,0 +1,63 @@ +#ifndef Goodix_DSP_EXPORTS +#include "goodix_nadt.h" +#include "gh3x2x_demo_algo_call.h" +#if 0 +const goodix_nadt_config external_cfg = +{ + .sampleRateNADT = 25, //²ÉÑùÂÊ + .unwearDetectLevel = 3, //Åå´÷µÈ¼¶ + .sleepStatus = 0, //˯Ãß״̬ + // + .checkTimeoutThr = 1200, //»îÌå¼ì²â³¬Ê±Ê±¼ä + .unwearCheckCntThr = 4, //ÍÑÂäÈ·ÈÏʱ¼ä + .wearCheckCntThr = 2, //»îÌåÈ·ÈÏʱ¼ä + // + //ADTÅÐ¶Ï + .adtWearOnThr = 8638608, //ADT wear onãÐÖµ + .adtWearOffThr = 8588608, //ADT wear offãÐÖµ + // + //Ô˶¯ÅÐ¶Ï + .accStdThr = 25, //ACC±ê×¼²î + // + //»îÌå¼ì²â + .liveDetectEnable = 1, //»îÌå¼ì²âʹÄÜ + .rawPVLenThr = 300, //¸ß´Îг²¨ãÐÖµ + .heartBeatThrLow = 50, //ÐÄÂÊÏÂÏÞ + .heartBeatThrHigh = 140, //ÐÄÂÊÉÏÏÞ + .difRrInterThr = 8, //ÐÄÂʱ仯ãÐÖµ + .wearAcfScoreThr = 50, //×ÔÏà¹Ø·ÖÊýãÐÖµ + .baseLinePosRatioThr = 30, //»ùÏßµ¥µ÷ÂÊãÐÖµ + .baseLineDiffThr = 15, //»ùÏ߯½Ì¹ÐÔãÐÖµ + .sigScaleThr = 1000, + // + //¸ßƵ±³¾°¹â¼ì²â + .bgJumpDetectEnable = 1, //±³¾°¹âÍ»±ä¼ì²âʹÄÜ + .jumpBgDiffThr = 100, //±³¾°¹â±ä»¯Á¿ãÐÖµ + .bgPeakValleyNumThr = 12, //±³¾°¹â·å¹È¸öÊýãÐÖµ + // + //±³¾°¹âÖÜÆÚ¼ì²â + .bgPeriodDetectEnable = 1, //±³¾°¹âÖÜÆÚ¼ì²âʹÄÜ + .periodBgDiffThr = 10, //±³¾°¹â±ä»¯Á¿ãÐÖµ + .bgPeriodThr = 10, //±³¾°¹âÖÜÆÚãÐÖµ + .bgPeriodDiffThr = 5 //±³¾°¹âÖÜÆÚ²îÒìãÐÖµ +}; + +const void *goodix_nadt_config_get_arr() +{ + return &external_cfg; +} + +GS32 goodix_nadt_config_get_size() +{ + return sizeof(goodix_nadt_config); +} +#endif + +void goodix_nadt_config_get_version(char* ver, GU8 ver_len) +{ + GU32 copy_num = ver_len < (strlen(NADT_INTERFACE_VERSION) + 1) ? ver_len : (strlen(NADT_INTERFACE_VERSION) + 1); + GH3X2X_Memcpy(ver, NADT_INTERFACE_VERSION, copy_num); + ver[copy_num - 1] = '\0'; //Èç¹ûNADT_CONFIG_VERµÄ³¤¶È´óÓÚsize£¬ÐèÒªÌí¼Ó½áÊø·û +} + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_spo2_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_spo2_config.c new file mode 100644 index 000000000..edee27083 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/algo_params/goodix_spo2_config.c @@ -0,0 +1,63 @@ +#ifndef Goodix_DSP_EXPORTS + +#include "goodix_spo2.h" +#include "gh3x2x_demo_algo_call.h" +#if 0 +const goodix_spo2_config external_cfg = +{ + //raw 配置信息 + .valid_chl_num = 1, // 有效通道数 + .raw_fs = 25, // 原始采样率 + //校准参数 + .cali_coef_a4 = 0, //校准参数4次项 + .cali_coef_a3 = 0, //校准参数3次项 + .cali_coef_a2 = -1, //校准参数2次项 + .cali_coef_a1 = -233736, //校准参数1次项 + .cali_coef_a0 = 1106394, //校准参数常数项 + //hb使能标志 + .hb_en_flg = 1, //hb使能标志 + //佩戴状态 + .wear_mode = 0, //佩戴状态 0:手环 1:手指 2:耳机 + // acc move thr + .acc_thr_max = 50, + .acc_thr_min = 25, + .acc_thr_scale = 3, + .acc_thr_num = 3, + .acc_thr_angle = 90, + //CTR设置 + .ctr_en_flg = 1, + .ctr_red_thr = 65, + //信号质量评估相关阈值 + .ppg_jitter_thr = 35, + .ppg_noise_thr = 25, + .ppg_coeff_thr = 70, + .quality_module_key = 253, + //出值策略 + .low_spo2_thr = 95, + .fast_out_time = 10, + .slow_out_time = 30, + .min_stable_time_high = 2, + .min_stable_time_low = 7, + .max_spo2_variation_high = 10, + .max_spo2_variation_low = 5, + .ouput_module_key = 3 +}; + +const void *goodix_spo2_config_get_instance() +{ + return &external_cfg; +} + +int32_t goodix_spo2_config_get_size() +{ + return sizeof(goodix_spo2_config); +} +#endif + +void goodix_spo2_config_get_version(char* ver,uint8_t ver_len) +{ + uint32_t copy_num = ver_len < (strlen(SPO2_INTERFACE_VERSION) + 1) ? ver_len : (strlen(SPO2_INTERFACE_VERSION) + 1); + GH3X2X_Memcpy(ver, SPO2_INTERFACE_VERSION, copy_num); + ver[copy_num - 1] = '\0'; //如果NET_VERSION的长度大于size,需要添加结束符 +} +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_accppg_sync.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_accppg_sync.h new file mode 100644 index 000000000..9294328f4 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_accppg_sync.h @@ -0,0 +1,20 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_accppg_sync.h + * + * @brief gh3x2x algo call demo code version + * + * @version ref gh3x2x_demo_algo_call_version.h + * + */ + +#ifndef _GH3X2X_DEMO_ACCPPG_SYNC_H_ +#define _GH3X2X_DEMO_ACCPPG_SYNC_H_ + +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algo_config.h" + + + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_call.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_call.h new file mode 100644 index 000000000..e38010b13 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_call.h @@ -0,0 +1,76 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_algo_call.h + * + * @brief gh3x2x algo call + * + * @version ref gh3x2x_demo_algo_call.h + * + */ +#ifndef _GH3X2X_DEMO_ALGO_CALL_H_ +#define _GH3X2X_DEMO_ALGO_CALL_H_ + +#include "gh_drv.h" + +extern GCHAR* GH3X2X_GetAlgoCallDemoVersion(void); +extern void GH3X2X_AlgoVersion(GU8 uchFunctionID, GCHAR version[120]); +extern GS8 GH3X2X_AlgoInit(GU32 unFunctionID); +extern GS8 GH3X2X_AlgoDeinit(GU32 unFunctionID); +extern GS8 GH3X2X_AlgoCalculate(GU32 unFunctionID); + +extern void GH3X2X_AlgoCallConfigInit(const STGh3x2xFrameInfo * const pstGh3x2xFrameInfo[], GU8 uchAlgoCfgIndex); +extern void GH3X2X_InitAlgoConfigParameters(void); +extern void GH3X2X_AlgoSensorEnable(GU8 uchAlgoGsensorEnable,GU8 uchAlgoCapEnable,GU8 uchAlgoTempEnable); + +extern void GH3X2X_SoftAdtParaInit(void); +extern void GH3X2X_WriteAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); + +/** + * @fn GS8 GH3X2X_HbAlgorithmOutputTimeConfig(GS32 nOutputTime) + * + * @brief Hb algorithm output time config + * + * @attention None + * + * @param[in] nOutputTime valid 7~GS32_MAX + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_ALGO_NO_SUPPORTED return algorithm no supported error + */ +extern GS8 GH3X2X_HbAlgorithmOutputTimeConfig(GS32 nLatestOutputTime, GS32 nEarliestOutputTime); + +/** + * @fn GS8 GH3X2X_HbAlgorithmScenarioConfig(GU8 uchScenario) + * + * @brief Hb algorithm scenario config + * + * @attention None + * + * @param[in] uchScenario @ref EMHbaScenesConfigType + * others: fixed 0(default) and return GH3X2X_RET_PARAMETER_ERROR + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return paramters error + * @retval #GH3X2X_RET_ALGO_NO_SUPPORTED return algorithm no supported error + */ +extern GS8 GH3X2X_HbAlgorithmScenarioConfig(GU8 uchScenario); +extern GS8 GH3X2X_BTAlgorithmRTConfig(GU16 *nRTtable); +extern GU8 GH3X2X_TimestampSyncGetFrameDataFlag(void); +extern void GH3X2X_TimestampSyncAccInit(void); +extern void GH3X2X_TimestampSyncPpgInit(GU32 unFunctionID); +extern void GH3X2X_TimestampSyncSetPpgIntFlag(GU8 uchPpgIntFlag); +extern void GH3X2X_TimestampSyncFillAccSyncBuffer(GU32 unTimeStamp, + GS16 usAccX, + GS16 usAccY, + GS16 usAccZ); +extern void GH3X2X_TimestampSyncFillPpgSyncBuffer(GU32 unTimeStamp, + const STGh3x2xFrameInfo * const pstFrameInfo); + +#endif /* _GH3X2X_DEMO_ALGO_CALL_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_call_version.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_call_version.h new file mode 100644 index 000000000..bb0b55e19 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_call_version.h @@ -0,0 +1,25 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_version.h + * + * @brief gh3x2x algo call demo code version + * + * @version ref gh3x2x_demo_algo_call_version.h + * + */ + +#ifndef _GH3X2X_DEMO_ALGO_CALL_VERSION_H_ +#define _GH3X2X_DEMO_ALGO_CALL_VERSION_H_ + +#define GOODIX_DEMO_MAJOR_VERSION_NUMBER 0 /**< major version number */ +#define GOODIX_DEMO_MINOR_VERSION_NUMBER 5 /**< minor version number */ + +#define GOODIX_TO_STRING(x) #x /**< number to char */ +#define GOODIX_STR(x) GOODIX_TO_STRING(x) /**< number to char */ + +/// makeup version string +#define GOODIX_ALGO_CALL_VERSION_STRING "Goodix_Algocall_"\ + "v"GOODIX_STR(GOODIX_DEMO_MAJOR_VERSION_NUMBER)\ + "."GOODIX_STR(GOODIX_DEMO_MINOR_VERSION_NUMBER) +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_config.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_config.h new file mode 100644 index 000000000..251f7d04e --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_config.h @@ -0,0 +1,131 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_algo_config.h + * + * @brief gh3x2x algo config + * + * @version ref gh3x2x_demo_algo_config.h + * + */ +#ifndef _GH3X2X_DEMO_ALGO_CONFIG_H_ +#define _GH3X2X_DEMO_ALGO_CONFIG_H_ + +#ifdef GOODIX_DEMO_PLATFORM +//#include "Goodix_Platform_config.h" +#endif + +#define GH3X2X_ALGO_FUNCTION_GROUP_0 (GH3X2X_FUNCTION_HR|GH3X2X_FUNCTION_SPO2|GH3X2X_FUNCTION_HRV|GH3X2X_FUNCTION_SOFT_ADT_GREEN) +#define GH3X2X_ALGO_FUNCTION_GROUP_1 (GH3X2X_FUNCTION_SPO2) +#define GH3X2X_ALGO_FUNCTION_GROUP_2 (GH3X2X_FUNCTION_ECG) +#define GH3X2X_ALGO_FUNCTION_GROUP_3 (GH3X2X_FUNCTION_HRV) +#define GH3X2X_ALGO_FUNCTION_GROUP_4 (GH3X2X_NO_FUNCTION) + +#define GOODIX_ALGO_BASIC (1) +#define GOODIX_ALGO_MEDIUM (2) +#define GOODIX_ALGO_PREMIUM (3) +#define GOODIX_ALGO_EXCLUSIVE (4) + +#define GOODIX_ECG_ALGO_500FS_QRS_ENABLE (1) +#define GOODIX_ECG_ALGO_500FS_QRS_DISABLE (2) +#define GOODIX_ECG_ALGO_250FS_QRS_ENABLE (3) +#define GOODIX_ECG_ALGO_250FS_QRS_DISABLE (4) + +#ifndef __GOODIX_HR_ALGO_VERISON__ +#define __GOODIX_HR_ALGO_VERISON__ (GOODIX_ALGO_EXCLUSIVE) +#endif +#ifndef __GOODIX_SPO2_ALGO_VERISON__ +#define __GOODIX_SPO2_ALGO_VERISON__ (GOODIX_ALGO_EXCLUSIVE) +#endif +#ifndef __GOODIX_ECG_ALGO_CONFIG__ +#define __GOODIX_ECG_ALGO_CONFIG__ (GOODIX_ECG_ALGO_250FS_QRS_ENABLE) +#endif + +#if ((__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_BASIC) || (__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_MEDIUM)) +#if ((__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_PREMIUM) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_EXCLUSIVE)) +#error "HR algo BASIC\MEDIUM version should adapt to SPO2 BASIC\MEDIUM version" +#endif +#endif + +#if ((__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_PREMIUM) || (__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_EXCLUSIVE)) +#if ((__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_BASIC) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_MEDIUM)) +#error "HR algo PREMIUM\EXCLUSIVE version should adapt to SPO2 PREMIUM\EXCLUSIVE version" +#endif +#endif + +/* 0: global buffer for goodix algorithm mem pool + * 1: user dynamic buffer for goodix algorithm mem pool */ +#define __USER_DYNAMIC_ALGO_MEM_EN__ (0) +#if __USER_DYNAMIC_ALGO_MEM_EN__ +#define GH3X2X_ALGORITHMS_MEMORY_SIZE_USERSET (0) +#endif + +/* function algo enable config */ +#define __USE_GOODIX_ADT_ALGORITHM__ (0) +#define __USE_GOODIX_HR_ALGORITHM__ (1) +#define __USE_GOODIX_HRV_ALGORITHM__ (1) +#define __USE_GOODIX_HSM_ALGORITHM__ (0) +#define __USE_GOODIX_SPO2_ALGORITHM__ (1) +#define __USE_GOODIX_ECG_ALGORITHM__ (1) +#define __USE_GOODIX_BT_ALGORITHM__ (1) +#define __USE_GOODIX_RESP_ALGORITHM__ (0) +#define __USE_GOODIX_AF_ALGORITHM__ (0) +#define __USE_GOODIX_BP_ALGORITHM__ (0) +#define __USE_GOODIX_SOFT_ADT_ALGORITHM__ (1) + +/* algorithm log */ +#define __GH3X2X_ALGO_LOG_LV_0__ (0) /** no log **/ +#define __GH3X2X_ALGO_LOG_LV_1__ (1) /** include EXAMPLE LOG information **/ +#define __GH3X2X_ALGO_LOG_LV_2__ (2) /** include EXAMPLE LOG debug **/ + +#define __ALGO_LOG_CONFIG__ (__GH3X2X_ALGO_LOG_LV_0__) + +/* BT NTC Drv Convert config*/ +#if __USE_GOODIX_BT_ALGORITHM__ +#define __USE_GOODIX_DRV_NTC_Convert (1) +#endif + +/* algorithm config max number */ +#define __GOODIX_ALGO_CFG_LIST_MAX_NUM__ (1) + +/*algorithm output value process strategy config*/ +#define __GH3X2X_HR_OUTPUT_VALUE_STRATEGY_EN__ (0) + +/* algoritm channel nunber config*/ +#define __HR_ALGORITHM_SUPPORT_CHNL_NUM__ (4) /* range 1~4 */ +#define __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ (1) /* range 1-4 */ + +/* algo and drv interactivity*/ +#define __GH_MSG_WTIH_DRV_LAYER_EN__ (0) +#define __GH_SEPARATE_ALGO_EN__ (0) + +#if (__USE_GOODIX_SOFT_ADT_ALGORITHM__) +#define __SOFT_ADT_IR_DETECT_TIMEOUT__ (30) /** (recomended value = 30 seconds) ir detect timeout **/ +#endif + +#define GH_SEND_MSG_WEAR_EVENT(event) //add your code to send message to drv layer + + + +/*********************************** DO NOT MODIFY FOLLOWING CODE *******************************/ +#if (\ + __USE_GOODIX_HR_ALGORITHM__ ||\ + __USE_GOODIX_HRV_ALGORITHM__ ||\ + __USE_GOODIX_HSM_ALGORITHM__ ||\ + __USE_GOODIX_SPO2_ALGORITHM__ ||\ + __USE_GOODIX_ECG_ALGORITHM__ ||\ + __USE_GOODIX_BT_ALGORITHM__ ||\ + __USE_GOODIX_RESP_ALGORITHM__ ||\ + __USE_GOODIX_AF_ALGORITHM__ ||\ + __USE_GOODIX_BP_ALGORITHM__ ||\ + __USE_GOODIX_SOFT_ADT_ALGORITHM__\ + ) +#define __GOODIX_ALGO_CALL_MODE__ (1) +#else +#define __GOODIX_ALGO_CALL_MODE__ (0) +#endif + + +#endif /* _GH3X2X_DEMO_ALGO_CALL_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_hook.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_hook.h new file mode 100644 index 000000000..aea2e7741 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_hook.h @@ -0,0 +1,128 @@ +#include +#include "gh_drv.h" +#include "gh3x2x_demo_algo_config.h" + +#ifdef GOODIX_DEMO_PLATFORM +#include "gh3x2x_demo_goodix_PLATFORM.h" +#else +#define GOODIX_PLATFORM_NADT_RESULT_HANDLE_ENTITY() +#define GOODIX_PLATFORM_LOG_ENTITY() +#endif + +#if (__GOODIX_ALGO_CALL_MODE__) + +/** + * @fn void GH3X2X_AdtAlgorithmResultReport(STHbAlgoResult stHbAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate adt algorithm. + * + * @attention None + * + * @param[in] stHbAlgoRes hb algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_AdtAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +/** + * @fn void GH3X2X_HrAlgorithmResultReport(STHbAlgoResult stHbAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate hb algorithm. + * + * @attention None + * + * @param[in] stHbAlgoRes hb algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_HrAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +/** + * @fn void GH3X2X_Spo2AlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult) + * + * + * @brief This function will be called after calculate spo2 algorithm. + * + * @attention None + * + * @param[in] stSpo2AlgoRes spo2 algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_Spo2AlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +/** + * @fn void GH3X2X_HrvAlgorithmResultReport(STHrvAlgoResult stHrvAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate hrv algorithm. + * + * @attention None + * + * @param[in] stHrvAlgoRes hrv algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_HrvAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +/** + * @fn void GH3X2X_EcgAlgorithmResultReport(STEcgAlgoResult stEcgAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate ecg algorithm. + * + * @attention None + * + * @param[in] stEcgAlgoRes ecg algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_EcgAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +/** + * @fn void GH3X2X_SoftAdtGreenAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) + * + * @brief This function will be called after calculate ecg algorithm. + * + * @attention None + * + * @param[in] stEcgAlgoRes ecg algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_SoftAdtGreenAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +/** + * @fn void GH3X2X_SoftAdtIrAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) + * + * @brief This function will be called after calculate ecg algorithm. + * + * @attention None + * + * @param[in] stEcgAlgoRes ecg algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_SoftAdtIrAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +#endif // end else #if (__DRIVER_LIB_MODE__==__DRV_LIB_WITHOUT_ALGO__) + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_memory.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_memory.h new file mode 100644 index 000000000..a0b999ddd --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algo_memory.h @@ -0,0 +1,394 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_algo_memory.h + * + * @brief gh3x2x algo memory set + * + * @version ref gh3x2x_demo_algo_memory.h + * + */ +#ifndef _GH3X2X_DEMO_ALGO_MEMORY_H_ +#define _GH3X2X_DEMO_ALGO_MEMORY_H_ + +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algo_config.h" + +#if (__GOODIX_ALGO_CALL_MODE__) + +/* algorithm run mode:simultaneously or not */ +#define GH3X2X_ALGORITHM_RUN_ALONE (0) /**< only excute one algorithm at the same time */ +#define GH3X2X_ALGORITHM_RUN_SIMULTANEOUSLY (1) /**< excute more than one algorithm */ + +/* algorithm mem size in byte */ +#if (__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_BASIC) + +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_1CHNL (2116) /**< HB 1 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_2CHNL (2116) /**< HB 2 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_3CHNL (2116) /**< HB 3 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_4CHNL (2116) /**< HB 4 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_1CHNL (1196) /**< HB 1 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_2CHNL (1196) /**< HB 2 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_3CHNL (1196) /**< HB 3 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_4CHNL (1196) /**< HB 4 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_HR_ALGORITHM_ROM (20212) +#define GH3X2X_HR_ALGORITHM_STACK (556) +#define GH3X2X_HR_ALGORITHM_MIPS_MS (2.61) + +#elif (__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_MEDIUM) + +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_1CHNL (3248) /**< HB 1 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_2CHNL (3248) /**< HB 2 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_3CHNL (3248) /**< HB 3 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_4CHNL (3248) /**< HB 4 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_1CHNL (2060) /**< HB 1 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_2CHNL (2060) /**< HB 2 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_3CHNL (2060) /**< HB 3 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_4CHNL (2060) /**< HB 4 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_HR_ALGORITHM_ROM (25988) +#define GH3X2X_HR_ALGORITHM_STACK (612) +#define GH3X2X_HR_ALGORITHM_MIPS_MS (3.25) + +#elif (__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_PREMIUM) + +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_1CHNL (8944) /**< HB 1 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_2CHNL (8944) /**< HB 2 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_3CHNL (8944) /**< HB 3 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_4CHNL (8944) /**< HB 4 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_1CHNL (3932) /**< HB 1 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_2CHNL (3932) /**< HB 2 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_3CHNL (3932) /**< HB 3 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_4CHNL (3932) /**< HB 4 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_HR_ALGORITHM_ROM (76424) +#define GH3X2X_HR_ALGORITHM_STACK (676) +#define GH3X2X_HR_ALGORITHM_MIPS_MS (21) + +#elif (__GOODIX_HR_ALGO_VERISON__ == GOODIX_ALGO_EXCLUSIVE) + +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_1CHNL (15584) /**< HB 1 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_2CHNL (15584) /**< HB 2 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_3CHNL (15584) /**< HB 3 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_4CHNL (15584) /**< HB 4 chnl algorithm peak memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_1CHNL (5248) /**< HB 1 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_2CHNL (5248) /**< HB 2 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_3CHNL (5248) /**< HB 3 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_4CHNL (5248) /**< HB 4 chnl algorithm desident memory size in byte */ +#define GH3X2X_HR_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_HR_ALGORITHM_ROM (57176) +#define GH3X2X_HR_ALGORITHM_STACK (552) +#define GH3X2X_HR_ALGORITHM_MIPS_MS (38) + +#else +#error "please define __GOODIX_HR_ALGO_VERISON__ in gh3x2x_demo_algo_config.h !" +#endif + +#if (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_BASIC) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_MEDIUM) + +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_1CHNL (2736) /**< SPO2 1 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_2CHNL (2736) /**< SPO2 2 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_3CHNL (2736) /**< SPO2 3 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_4CHNL (2736) /**< SPO2 4 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_1CHNL (1956) /**< SPO2 1 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_2CHNL (1956) /**< SPO2 2 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_3CHNL (1956) /**< SPO2 3 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_4CHNL (1956) /**< SPO2 4 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_SPO2_ALGORITHM_ROM (12596) +#define GH3X2X_SPO2_ALGORITHM_STACK (376) +#define GH3X2X_SPO2_ALGORITHM_MIPS_MS (/) + +#elif (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_PREMIUM) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_EXCLUSIVE) + +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_1CHNL (7864) /**< SPO2 1 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_2CHNL (7864) /**< SPO2 2 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_3CHNL (7864) /**< SPO2 3 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_4CHNL (7864) /**< SPO2 4 chnl algorithm peak memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_1CHNL (5020) /**< SPO2 1 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_2CHNL (5020) /**< SPO2 2 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_3CHNL (5020) /**< SPO2 3 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_4CHNL (5020) /**< SPO2 4 chnl algorithm memory size in byte */ +#define GH3X2X_SPO2_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_SPO2_ALGORITHM_ROM (49084) +#define GH3X2X_SPO2_ALGORITHM_STACK (492) +#define GH3X2X_SPO2_ALGORITHM_MIPS_MS (26) + +#else +#error "please define __GOODIX_SPO2_ALGO_VERISON__ in gh3x2x_demo_algo_config.h !" +#endif + +#if (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_500FS_QRS_ENABLE) + +#define GH3X2X_ECG_ALGORITHM_MEMORY_PEAK (38360) /**< ECG algorithm peak memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT (37176) /**< ECG algorithm resident memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_ECG_ALGORITHM_ROM (33784) +#define GH3X2X_ECG_ALGORITHM_STACK (5128) +#define GH3X2X_ECG_ALGORITHM_MIPS_MS (216) + +#elif (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_500FS_QRS_DISABLE) + +#define GH3X2X_ECG_ALGORITHM_MEMORY_PEAK (32024) /**< ECG algorithm peak memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT (30640) /**< ECG algorithm resident memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_ECG_ALGORITHM_ROM (33784) +#define GH3X2X_ECG_ALGORITHM_STACK (5128) +#define GH3X2X_ECG_ALGORITHM_MIPS_MS (161) + +#elif (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_250FS_QRS_ENABLE) + +#define GH3X2X_ECG_ALGORITHM_MEMORY_PEAK (23476) /**< ECG algorithm peak memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT (22132) /**< ECG algorithm resident memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_ECG_ALGORITHM_ROM (33784) +#define GH3X2X_ECG_ALGORITHM_STACK (5128) +#define GH3X2X_ECG_ALGORITHM_MIPS_MS (151) + +#elif (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_250FS_QRS_DISABLE) + +#define GH3X2X_ECG_ALGORITHM_MEMORY_PEAK (19464) /**< ECG algorithm peak memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT (18120) /**< ECG algorithm resident memory size in byte */ +#define GH3X2X_ECG_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_ECG_ALGORITHM_ROM (33784) +#define GH3X2X_ECG_ALGORITHM_STACK (5128) +#define GH3X2X_ECG_ALGORITHM_MIPS_MS (126) + +#else +#error "please define __GOODIX_ECG_ALGO_CONFIG__ in gh3x2x_demo_algo_config.h !" +#endif + +#define GH3X2X_HRV_ALGORITHM_MEMORY_PEAK (3008) /**< HRV algorithm peak memory size in byte */ +#define GH3X2X_HRV_ALGORITHM_MEMORY_RESIDENT (2844) /**< HRV algorithm resident memory size in byte */ +#define GH3X2X_HRV_ALGORITHM_MEMORY_REDUNDANCY (100) +#define GH3X2X_HRV_ALGORITHM_ROM (13320) +#define GH3X2X_HRV_ALGORITHM_STACK (964) +#define GH3X2X_HRV_ALGORITHM_MIPS_MS (/) + + +#define GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_PEAK (1128) /**< SOFT ADT algorithm peak memory size in byte */ +#define GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_RESIDENT (104) /**< SOFT ADT algorithm resident memory size in byte */ +#define GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_REDUNDANCY (100) /**< SOFT ADT algorithm redundancy memory size in byte */ +#define GH3X2X_SOFT_ADT_ALGORITHM_ROM (16889) +#define GH3X2X_SOFT_ADT_ALGORITHM_STACK (4088) +#define GH3X2X_SOFT_ADT_ALGORITHM_MIPS_MS (/) + + +#define GH3X2X_HSM_ALGORITHM_MEMORY_PEAK (944) /**< HSM algorithm memory peak size in byte */ +#define GH3X2X_HSM_ALGORITHM_MEMORY_RESIDENT (944) /**< HSM algorithm memory resident size in byte */ +#define GH3X2X_HSM_ALGORITHM_MEMORY_REDUNDANCY (100) + + +#define GH3X2X_BT_ALGORITHM_MEMORY_PEAK (1600) /**< BT algorithm memory peak size in byte */ +#define GH3X2X_BT_ALGORITHM_MEMORY_RESIDENT (1500) /**< BT algorithm memory resident size in byte */ +#define GH3X2X_BT_ALGORITHM_MEMORY_REDUNDANCY (200) + + +#define GH3X2X_RESP_ALGORITHM_MEMORY_PEAK (5435) /**< RESP algorithm memory peak size in byte */ +#define GH3X2X_RESP_ALGORITHM_MEMORY_RESIDENT (2363) /**< RESP algorithm memory resident size in byte */ +#define GH3X2X_RESP_ALGORITHM_MEMORY_REDUNDANCY (500) + + +#define GH3X2X_AF_ALGORITHM_MEMORY_PEAK (3262) /**< AF algorithm memory peak size in byte */ +#define GH3X2X_AF_ALGORITHM_MEMORY_RESIDENT (1102) /**< AF algorithm memory resident size in byte */ +#define GH3X2X_AF_ALGORITHM_MEMORY_REDUNDANCY (300) + + +/* algorithm mem config */ +#if (__GOODIX_ALGO_CALL_MODE__) + +#if (__USE_GOODIX_HR_ALGORITHM__) +#if __HR_ALGORITHM_SUPPORT_CHNL_NUM__ <= 1 +#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK GH3X2X_HR_ALGORITHM_MEMORY_PEAK_1CHNL +#define GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_1CHNL +#elif __HR_ALGORITHM_SUPPORT_CHNL_NUM__ == 2 +#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK GH3X2X_HR_ALGORITHM_MEMORY_PEAK_2CHNL +#define GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_2CHNL +#elif __HR_ALGORITHM_SUPPORT_CHNL_NUM__ == 3 +#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK GH3X2X_HR_ALGORITHM_MEMORY_PEAK_3CHNL +#define GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_3CHNL +#elif __HR_ALGORITHM_SUPPORT_CHNL_NUM__ >= 4 +#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK GH3X2X_HR_ALGORITHM_MEMORY_PEAK_4CHNL +#define GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_4CHNL +#endif +#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_ALGORITHM_HR_MEMORY_PEAK - GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY GH3X2X_HR_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY (0) +#endif + +#if (__USE_GOODIX_HSM_ALGORITHM__) +#define GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT (GH3X2X_HSM_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_HSM_ALGORITHM_MEMORY_PEAK - GH3X2X_HSM_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY GH3X2X_HSM_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY (0) +#endif + +#if (__USE_GOODIX_SPO2_ALGORITHM__) +#if __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ <= 1 +#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_1CHNL +#define GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_1CHNL +#elif __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ == 2 +#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_2CHNL +#define GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_2CHNL +#elif __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ == 3 +#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_3CHNL +#define GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_3CHNL +#elif __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ >= 4 +#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_4CHNL +#define GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_4CHNL +#endif +#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK - GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY GH3X2X_SPO2_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY (0) + +#endif + +#if (__USE_GOODIX_ECG_ALGORITHM__) +#define GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT (GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_ECG_ALGORITHM_MEMORY_PEAK - GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY GH3X2X_ECG_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY (0) +#endif + +#if (__USE_GOODIX_HRV_ALGORITHM__) +#define GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT (GH3X2X_HRV_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_HRV_ALGORITHM_MEMORY_PEAK - GH3X2X_HRV_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY GH3X2X_HRV_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY (0) +#endif + +#if (__USE_GOODIX_BT_ALGORITHM__) +#define GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT (GH3X2X_BT_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_BT_ALGORITHM_MEMORY_PEAK - GH3X2X_BT_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY GH3X2X_BT_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY (0) +#endif + +#if (__USE_GOODIX_RESP_ALGORITHM__) +#define GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT (GH3X2X_RESP_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_RESP_ALGORITHM_MEMORY_PEAK - GH3X2X_RESP_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY GH3X2X_RESP_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY (0) +#endif + +#if (__USE_GOODIX_AF_ALGORITHM__) +#define GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT (GH3X2X_AF_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_AF_ALGORITHM_MEMORY_PEAK - GH3X2X_AF_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY GH3X2X_AF_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY (0) +#endif + + +#if (__USE_GOODIX_SOFT_ADT_ALGORITHM__) +#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT (GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT (GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_PEAK - GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_RESIDENT) +#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_REDUNDANCY +#else +#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT (0) +#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT (0) +#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY (0) +#endif + + + +#endif + +#define MAX2(a0, a1) (((a0) > (a1)) ? (a0) : (a1)) +#define ADD2(a0, a1) ((a0) + (a1)) +#define MAX4(a0,a1,a2,a3) (MAX2(MAX2(a0, a1),MAX2(a2, a3))) +#define MAX5(a0,a1,a2,a3,a4) (MAX2(MAX4(a0,a1,a2,a3),a4)) +#define MAX9(a0, a1, a2, a3, a4, a5 ,a6, a7, a8) (MAX2(MAX5(a0,a1,a2,a3,a4),MAX4(a5,a6,a7,a8)))) + +#define GH3X2X_FUNCTION_SOFT_ADT (GH3X2X_FUNCTION_SOFT_ADT_GREEN|GH3X2X_FUNCTION_SOFT_ADT_IR) + +#define GH3X2X_ALGORITHMS_MEMORY_RESIDENT_(x) (\ + ((0 != (x & GH3X2X_FUNCTION_HR)) * __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_SPO2)) * __USE_GOODIX_SPO2_ALGORITHM__ * GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_ECG)) * __USE_GOODIX_ECG_ALGORITHM__ * GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_HRV)) * __USE_GOODIX_HRV_ALGORITHM__ * GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_HSM)) * __USE_GOODIX_HSM_ALGORITHM__ * GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_BT)) * __USE_GOODIX_BT_ALGORITHM__ * GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_RESP)) * __USE_GOODIX_RESP_ALGORITHM__ * GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_AF)) * __USE_GOODIX_AF_ALGORITHM__ * GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT) + \ + ((0 != (x & GH3X2X_FUNCTION_SOFT_ADT)) * __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT)) + +#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT_(x) (MAX9(\ + ADD2(((0 != (x & GH3X2X_FUNCTION_HR))* __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_HR))* __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY)),\ + ADD2(((0 != (x & GH3X2X_FUNCTION_SPO2))* __USE_GOODIX_SPO2_ALGORITHM__* GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_SPO2))* __USE_GOODIX_SPO2_ALGORITHM__* GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY)), \ + ADD2(((0 != (x & GH3X2X_FUNCTION_ECG))* __USE_GOODIX_ECG_ALGORITHM__* GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_ECG))* __USE_GOODIX_ECG_ALGORITHM__* GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY)), \ + ADD2(((0 != (x & GH3X2X_FUNCTION_HRV))* __USE_GOODIX_HRV_ALGORITHM__* GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_HRV))* __USE_GOODIX_HRV_ALGORITHM__* GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY)), \ + ADD2(((0 != (x & GH3X2X_FUNCTION_HSM))* __USE_GOODIX_HSM_ALGORITHM__* GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_HSM))* __USE_GOODIX_HSM_ALGORITHM__* GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY)), \ + ADD2(((0 != (x & GH3X2X_FUNCTION_BT))* __USE_GOODIX_BT_ALGORITHM__* GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_BT))* __USE_GOODIX_BT_ALGORITHM__* GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY)), \ + ADD2(((0 != (x & GH3X2X_FUNCTION_RESP))* __USE_GOODIX_RESP_ALGORITHM__* GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_RESP))* __USE_GOODIX_RESP_ALGORITHM__* GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY)), \ + ADD2(((0 != (x & GH3X2X_FUNCTION_AF))* __USE_GOODIX_AF_ALGORITHM__* GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_AF))* __USE_GOODIX_AF_ALGORITHM__* GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY)), \ + ADD2(((0 != (x & GH3X2X_FUNCTION_SOFT_ADT))* __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT),\ + ((0 != (x & GH3X2X_FUNCTION_SOFT_ADT))* __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY))) + +#define GH3X2X_ALGORITHMS_MEMORY_(x) (GH3X2X_ALGORITHMS_MEMORY_RESIDENT_(x) + GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT_(x)) + +#define __GH3X2X_ALGORITHMS_MEMORY (\ + MAX5(\ + GH3X2X_ALGORITHMS_MEMORY_(GH3X2X_ALGO_FUNCTION_GROUP_0),\ + GH3X2X_ALGORITHMS_MEMORY_(GH3X2X_ALGO_FUNCTION_GROUP_1),\ + GH3X2X_ALGORITHMS_MEMORY_(GH3X2X_ALGO_FUNCTION_GROUP_2),\ + GH3X2X_ALGORITHMS_MEMORY_(GH3X2X_ALGO_FUNCTION_GROUP_3),\ + GH3X2X_ALGORITHMS_MEMORY_(GH3X2X_ALGO_FUNCTION_GROUP_4)\ + )\ + ) +//final size +#define GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL (((GU32)((__GH3X2X_ALGORITHMS_MEMORY + 3) / 4)) * 4) + + +/** + * @fn GS8 GH3X2X_AlgoMemConfig( GU32 unMemSize) + * + * @brief Config algorithm memory. + * + * @attention Mem can only be static,such as global array + * + * @param[in] unMemSize memory size(unit:byte) + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_RESOURCE_ERROR return algorithm mem config error + */ +GS8 GH3X2X_AlgoMemConfig( GU32 unMemSize); + +#endif + +#endif /* _GH3X2X_DEMO_ALGO_CALL_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algorithm_calc.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algorithm_calc.h new file mode 100644 index 000000000..25c3ca96a --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_algorithm_calc.h @@ -0,0 +1,355 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_algorithm_calc.h + * + * @brief gh3x2x algorithm calc define & declaration + * + * @version ref gh3x2x_demo_algorithm_calc.h + * + */ + +#ifndef _GH3X2X_DEMO_ALGORITHM_CALC_H_ +#define _GH3X2X_DEMO_ALGORITHM_CALC_H_ + + +#include "gh3x2x_demo_algo_config.h" +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algo_hook.h" +#include "gh3x2x_demo_common.h" + + +/// algorithm calculate hook type +typedef GS8 (*pfnAlgorithmCallFunc)(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern STGh3x2xFrameInfo ** g_pstGh3x2xAlgoFrameInfo; + +#define GOODIX_HR_PARAMS_NUM_MAX (10) +#define GOODIX_HRV_PARAMS_NUM_MAX (5) +#define GOODIX_SPO2_PARAMS_NUM_MAX (26) +#define GOODIX_ECG_PARAMS_NUM_MAX (5) +#define GOODIX_BT_PARAMS_NUM_MAX (20) +#define GOODIX_AF_PARAMS_NUM_MAX (2) + +#define GH3X2X_RAWDATA_BASE_VALUE (1<<23) + +#define GH3X2X_GAIN_VALUE_INVALID (0xFF) + +/// xor val for xor num in encrypt & decrypt +#define GH3X2X_CRYP_XOR_XOR_VAL (0xFF) + +/// fixed val in encrypt & decrypt +#define GH3X2X_CRYP_FIXED_VAL (0x55) + +/// header len in encrypt & decrypt +#define GH3X2X_CRYP_HEADER_LEN (5u) + +/// cryp rawdata len to index +#define GH3X2X_ENCRYPT_LEN2INDEX (1u) + +/* encrypt & decrypt header index */ +#define GH3X2X_CRYP_HEADER_0 (0u) /**< cryp header index 0 */ +#define GH3X2X_CRYP_HEADER_1 (1u) /**< cryp header index 1 */ +#define GH3X2X_CRYP_HEADER_2 (2u) /**< cryp header index 2 */ +#define GH3X2X_CRYP_HEADER_3 (3u) /**< cryp header index 3 */ +#define GH3X2X_CRYP_HEADER_4 (4u) /**< cryp header index 4 */ + +/// encrypt data min len, min len is 4 +#define GH3X2X_ENCRYPT_CHECK_MIN_LEN(x) ((x) > 3) + +/// encrypt source add magic bytes, add after source buffer & len must >= 4, magic bytes len align to cryp header len +#define GH3X2X_ENCRYPT_SRC_ADD_MAGIC(src, len) do {\ + (src)[(len)] = ((src)[0] ^ (src)[(len) - 1]);\ + (src)[(len) + 1] = ((src)[1] ^ (src)[(len) - 3]);\ + (src)[(len) + 2] = GH3X2X_CRYP_FIXED_VAL;\ + (src)[(len) + 3] = ((src)[2] ^ (src)[(len) - 2]);\ + (src)[(len) + 4] = ((src)[3] ^ (src)[(len) - 4]);\ + } while (0) + +/// encrypt source verify magic bytes, add after source buffer & len must >= 4 +#define GH3X2X_ENCRYPT_VERIFY_SRC_MAGIC(src, len) (((src)[(len)] == ((src)[0] ^ (src)[(len) - 1])) &&\ + ((src)[(len) + 1] == ((src)[1] ^ (src)[(len) - 3])) &&\ + ((src)[(len) + 2] == GH3X2X_CRYP_FIXED_VAL) &&\ + ((src)[(len) + 3] == ((src)[2] ^ (src)[(len) - 2])) &&\ + ((src)[(len) + 4] == ((src)[3] ^ (src)[(len) - 4]))) + +/// hba scenario mcaro max val +#define GH3X2X_HBA_SCENARIO_CONFIG_MAX_VAL (HBA_SCENES_SIZE) + +/* rawdata package for algorithm */ +#define GH3X2X_ALGO_RAW_GX_INDEX (0u) /**< rawdata gsensor x-asix index */ +#define GH3X2X_ALGO_RAW_GY_INDEX (1u) /**< rawdata gsensor y-asix index */ +#define GH3X2X_ALGO_RAW_GZ_INDEX (2u) /**< rawdata gsensor z-asix index */ +#define GH3X2X_ALGO_RAW_CH0_INDEX (3u) /**< rawdata ch0 data index */ +#define GH3X2X_ALGO_RAW_CH1_INDEX (4u) /**< rawdata ch1 data index */ +#define GH3X2X_ALGO_RAW_CH2_INDEX (5u) /**< rawdata ch2 data index */ +#define GH3X2X_ALGO_RAW_CH3_INDEX (6u) /**< rawdata ch3 data index */ +#define GH3X2X_ALGO_RAW_CH4_INDEX (7u) /**< rawdata ch4 data index */ +#define GH3X2X_ALGO_RAW_CH5_INDEX (8u) /**< rawdata ch5 data index */ +#define GH3X2X_ALGO_RAW_CH6_INDEX (9u) /**< rawdata ch6 data index */ +#define GH3X2X_ALGO_RAW_CH7_INDEX (10u) /**< rawdata ch7 data index */ +#define GH3X2X_ALGO_RAW_CH8_INDEX (11u) /**< rawdata ch8 data index */ +#define GH3X2X_ALGO_RAW_CH9_INDEX (12u) /**< rawdata ch9 data index */ +#define GH3X2X_ALGO_RAW_CH10_INDEX (13u) /**< rawdata ch10 data index */ +#define GH3X2X_ALGO_RAW_CH11_INDEX (14u) /**< rawdata ch11 data index */ +#define GH3X2X_ALGO_RAWDATA_LEN (35u) /**< rawdata packet len for algorithm */ + +/// algorithm channel max cnt support +#define GH3X2X_CHANNEL_MAP_MAX_CNT (32u) + +/// get slot & adc num from rawdata flag byte, equal channel map formats +#define GH3X2X_CHANNEL_MAP_GET(x) ((x) & GH3X2X_SLOT_ADC_NUM_BITS) + +/// channel map invalid val +#define GH3X2X_CHANNEL_MAP_INVALID_VAL (0x07) + +/// channel map is ecg channel +#define GH3X2X_CHANNEL_MAP_ISNOT_ECG_CH(x) (GH3X2X_CHECK_BIT_NOT_SET((x), GH3X2X_CHANNEL_MAP_ADC3)) + +/// algorithm output GF32 to GS32, multiply by (100) +#define GH3X2X_ALGORITHM_GF32_2_GS32(x) ((GS32)((x) * 100)) + +/// rawdata is new sampling data +#define GH3X2X_IS_NEW_RAWDATA (1) + +/// rawdata is new sampling data +#define GH3X2X_IS_NOT_NEW_RAWDATA (0) + +/// number of ECG algorithm output +#define GH3X2X_ECG_ALGO_OUTPUT_NUM (sizeof(STEcgAlgoResult)) + +/// number of spo2 algorithm output +#define GH3X2X_SPO2_ALGO_OUTPUT_NUM (sizeof(STSpo2AlgoResult)) + +/// number of hb algorithm output +#define GH3X2X_HB_ALGO_OUTPUT_NUM (sizeof(STHbAlgoResult)) + +/// number of hrv algorithm output +#define GH3X2X_HRV_ALGO_OUTPUT_NUM (sizeof(STHrvAlgoResult)) + +/// memory for algorithm is not inited +#define ALGO_MEM_NO_INIT (0) + +/// memory for algorithm is already inited +#define ALGO_MEM_INIT_OK (1) + +// algo chnl map num +#define ALGO_CHNL_NUM (32) + +// algo green chnl pos +#define ALGO_GREEN_CHNL_POS (0) + +// algo ir chnl pos +#define ALGO_IR_CHNL_POS (8) + +// algo red chnl pos +#define ALGO_RED_CHNL_POS (16) + +/* ecg algorithm */ + +// ECG 采样率 +#ifndef ECG_FS +#define ECG_FS 500 +#endif + +#define ECG_OUT_FACTOR (100) +#define ECG_SNR_FACTOR (10000000) + +#define ECG_FRAME_UNUSED (5) + +#define GH3X2X_REG_IS_VIRTUAL0X3_BIT (0x3000) +#define GH3X2X_VREG_FUNCTION_OFFSET (0X0300) +#define GH3X2X_ADT_DRV_CFG_ADDR (0x3000) +#define GH3X2X_ADT_ALG_CFG_ADDR (0x30C0) +#define GH3X2X_REG_ADDR_SIZE (0x0002) /**< reg addr size */ +#define GH3X2X_VREG_ALGO_CHNL_MAP_OFFSET (0X0200) +#define GH3X2X_HR_SCENARIO_CFG_L_ADDR (0x33C0) +#define GH3X2X_HR_ALGO_CHNL_NUM_ADDR (0x35C0) +#define GH3X2X_SPO2_ALGO_CHNL_NUM_ADDR (0x44C0) +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR4_H_ADDR (0x430E) +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR0_L_ADDR (0x42C0) + +#define GH3X2X_HSM_FLAG_BUFF_LEN (120) + +typedef enum +{ + ADT_ALGO_RESULT_DEFULT = 0, + ADT_ALGO_RESULT_WAER_ON, /**< detect wear on */ + ADT_ALGO_RESULT_WAER_OFF, +} EMAdtAlgoStatus; + +/** + * @brief gh3x2x algo function id + */ +typedef enum +{ + GH3X2X_ALGO_INIT_FUNCTION = 0, + GH3X2X_ALGO_CALCULATE_FUNCTION, +// GH3X2X_ALGO_FINAL_CALCULATE_FUNCTION, + GH3X2X_ALGO_DEINIT_FUNCTION, + GH3X2X_ALGO_FUNCTION_NUM_MAX, +} EMAlgoFunctionID; + +// algo chnl map struct +typedef struct +{ + GU8 uchFlag; + GU8 uchNum; + GU8 uchEcgAlgoChnlMap; + GU8 uchAlgoChnlMap[ALGO_CHNL_NUM]; +} STAlgoChnlMap; + +typedef struct +{ + GS32 nHbaScenario; + GS32 nHbaCalcOutputTime; + GS32 nFrequency; +}STAlgoHrParas; + +/* hb algorithm */ +#if (__USE_GOODIX_HR_ALGORITHM__) +extern GS32 g_unHrParamsArr[GOODIX_HR_PARAMS_NUM_MAX]; +/// hbd rawdata channel map +extern STAlgoChnlMap g_stHbaAlgoChnlMap; +#endif + +/* hrv algorithm */ +#if (__USE_GOODIX_HRV_ALGORITHM__) +extern GS32 g_nHrvParamsArr[GOODIX_HRV_PARAMS_NUM_MAX]; +#endif + +/* spo2 algorithm */ +#if (__USE_GOODIX_SPO2_ALGORITHM__) +extern GS32 g_nSpo2ParamssArr[GOODIX_SPO2_PARAMS_NUM_MAX]; +/// spo2 rawdata channel map +extern STAlgoChnlMap g_stSpo2AlgoChnlMap; +#endif + +/* ecg algorithm */ +#if (__USE_GOODIX_ECG_ALGORITHM__) +extern GS32 g_nEcgParamsArr[GOODIX_ECG_PARAMS_NUM_MAX]; +/// ecg frame data cnt +extern GU32 g_unEcgFrameCnt; +extern GU8 g_uchClassificationFlag; +extern GU8 g_unEcgTimeSeconds; +#endif + +/* bt algorithm */ +#if (__USE_GOODIX_BT_ALGORITHM__) +extern GS32 g_nBtParamsArr[GOODIX_BT_PARAMS_NUM_MAX]; +#endif + +/* af algorithm */ +#if (__USE_GOODIX_AF_ALGORITHM__) +extern GS32 g_nAfParamsArr[GOODIX_AF_PARAMS_NUM_MAX]; +#endif + +extern GU8 g_uchAlgoGsensorEnable; +extern GU8 g_uchAlgoCapEnable; +extern GU8 g_uchAlgoTempEnable; + +extern GU8 GH3X2X_GetAlgoMemStatus(void); + +/** + * @fn GS8 GH3X2X_AlgoMemInit(void) + * + * @brief algorithm memory init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_RESOURCE_ERROR return algorithm mem init error + */ +GS8 GH3X2X_AlgoMemInit(void); + +/** + * @fn void GH3X2X_AlgoMemDeinit(void) + * + * @brief algorithm memory deinit + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_AlgoMemDeinit(void); + +/** + * @fn void GH3X2X_SetNewDataFlag(EMChannelMapId emFuncId, GU8 uchFlag) + * + * @brief Set new sampling data flag + * + * @attention None + * + * @param[in] emFuncId function id + * @param[in] uchFlag new data or not + * @param[out] None + * + * @return None + */ +void GH3X2X_SetNewDataFlag(GU8 emFuncId, GU8 uchFlag); +extern void Gh3x2xOutputValueStrategyInit(GU32 unFunctionID); +extern void GH3x2xSleepFlagSet(GU8 uchSleepFlag); +extern GU8 GH3x2xSleepFlagGet(void); +extern GS32 GH3x2x_Round(GF32 fValue); +extern GU8 GH3x2x_BitCount(GU32 n); +extern void GH3X2X_LoadGoodixAlgoRegConfigArr(const STGh3x2xInitConfig *pstGoodixAlgoCfgListArr); + +extern GU8* GH3x2xAdtVersion(void); +extern GS8 GH3x2xAdtAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xAdtAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xAdtAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xHrAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xHrAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xHrAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); +extern void GH3X2X_HbaAlgoChnlMapDefultSet(void); +extern void Gh3x2xHrOutputValueStrategyPro(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId); + +extern GS8 GH3x2xHrvAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xHrvAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xHrvAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xSpo2AlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xSpo2AlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xSpo2AlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); +extern void GH3X2X_Spo2AlgoChnlMapDefultSet(void); + +extern GS8 GH3x2xAfAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xAfAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xAfAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xAfAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xAfAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xAfAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xRespAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xRespAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xRespAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xBtAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xBtAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xBtAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xHsmAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xHsmAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xHsmAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xSoftAdtAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xSoftAdtAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xSoftAdtAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GS8 GH3x2xEcgAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xEcgAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GS8 GH3x2xEcgAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo); +extern GU8 GH3x2xEcgAlgoClassification(void); + +#endif /* _GH3X2X_DRV_ALGORITHM_CALC_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_common.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_common.h new file mode 100644 index 000000000..49be1b8ec --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/inc/gh3x2x_demo_common.h @@ -0,0 +1,344 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_common.h + * + * @brief gh3x2x algo common define + * + * @version ref gh3x2x_demo_common.h + * + */ + +#ifndef _GH3X2X_DEMO_COMMON_H_ +#define _GH3X2X_DEMO_COMMON_H_ + + +#include "gh3x2x_demo_algo_config.h" +#include "goodix_algo.h" + +/* extern log function */ +extern void GH3X2X_AlgoLog(GCHAR *chLogString); +/// log support len +#define GH3X2X_LOG_ALGO_SUP_LEN (128) + + +#if (__ALGO_LOG_CONFIG__ > __GH3X2X_ALGO_LOG_LV_0__) +#if (__ALGO_LOG_CONFIG__ == __GH3X2X_ALGO_LOG_LV_1__) +#define GH3X2X_INFO_ALGO_LOG(...) do {\ + GCHAR chDebugStr[GH3X2X_LOG_ALGO_SUP_LEN] = {0};\ + snprintf(chDebugStr, GH3X2X_LOG_ALGO_SUP_LEN, \ + "[LOG_ALGO_I]: "__VA_ARGS__);\ + GH3X2X_AlgoLog(chDebugStr);\ + } while (0) +#else +#define GH3X2X_INFO_ALGO_LOG(...) +#endif + +#if (__ALGO_LOG_CONFIG__ == __GH3X2X_ALGO_LOG_LV_2__) +#define GH3X2X_DEBUG_ALGO_LOG(...) do {\ + GCHAR chDebugStr[GH3X2X_LOG_ALGO_SUP_LEN] = {0};\ + snprintf(chDebugStr, GH3X2X_LOG_ALGO_SUP_LEN, \ + "[LOG_ALGO_D]: "__VA_ARGS__);\ + GH3X2X_AlgoLog(chDebugStr);\ + } while (0) +#else +#define GH3X2X_DEBUG_ALGO_LOG(...) +#endif + +#else +#define GH3X2X_INFO_ALGO_LOG(...) +#define GH3X2X_DEBUG_ALGO_LOG(...) +#endif + +/// channel map max channel support to unpack rawdata +#define GH3X2X_CHANNEL_MAP_MAX_CH (32) + +/// fifo rawdata bytes max len +#define GH3X2X_FIFO_DATA_BYTES_MAX_LEN (3200) // GH3X2X_FIFO_CNT_CALC(800) + +/// fifo rawdata size +#define GH3X2X_FIFO_RAWDATA_SIZE (4) + +/// fifo rawdataindex size +#define GH3X2X_FIFO_RAWDATAINDEX_SIZE (2) + +/// fifo gsensordata size +#define GH3X2X_FIFO_GSENSORDATA_SIZE (6) + +/// fifo agcdata size +#define GH3X2X_FIFO_AGCDATA_SIZE (4) + +/// fifo cnt calc +#define GH3X2X_FIFO_CNT_CALC(x) ((x) * GH3X2X_FIFO_RAWDATA_SIZE) + +/// g sensor data size +#define GH3X2X_GSENSOR_DATA_SIZE (6) + +/// agc data size +#define GH3X2X_AGC_DATA_SIZE (4) + +/// agc data cnt calc +#define GH3X2X_AGC_CNT_CALC(x) ((x) * GH3X2X_AGC_DATA_SIZE) + +/// algorithm result size +#define GH3X2X_ALGO_RESULT_SIZE (4) + +/// algorithm result calc +#define GH3X2X_ALGO_RESULT_CALC(x) ((x) * GH3X2X_ALGO_RESULT_SIZE) + +/// algorithm result with tag calc. +#define GH3X2X_ALGO_RESULT_WITH_TAG_CALC(x) ((x) * (GH3X2X_ALGO_RESULT_SIZE + 1)) + +/// g sensor data size +#define GH3X2X_GSENSOR_DATA_SIZE (6) + +/// agc data size +#define GH3X2X_AGC_DATA_SIZE (4) + +/// agc data cnt calc +#define GH3X2X_AGC_CNT_CALC(x) ((x) * GH3X2X_AGC_DATA_SIZE) + +/// algorithm result size +#define GH3X2X_ALGO_RESULT_SIZE (4) + +/// algorithm result calc +#define GH3X2X_ALGO_RESULT_CALC(x) ((x) * GH3X2X_ALGO_RESULT_SIZE) + +/// algorithm result with tag calc. +#define GH3X2X_ALGO_RESULT_WITH_TAG_CALC(x) ((x) * (GH3X2X_ALGO_RESULT_SIZE + 1)) + +/* rawdata macro */ + +/// rawdata clear slot & adc num +#define GH3X2X_RAWDATA_CLEAR_SLOT_ADC_NUM(x) ((x) & 0x07FFFFFF) + +/// rawdata get slot num from dword +#define GH3X2X_DWORD_RAWDATA_GET_SLOT_NUM(x) (((x) & 0xE0000000) >> 29) + +/// rawdata get adc num from dword +#define GH3X2X_DWORD_RAWDATA_GET_ADC_NUM(x) (((x) & 0x18000000) >> 27) + +/// rawdata get slot&adc num from dword +#define GH3X2X_DWORD_RAWDATA_GET_SLOT_ADC_NUM(x) (((x) & 0xF8000000) >> 27) + +/// rawdata get slot num from byte +#define GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(x) (((x) & 0xE0) >> 5) + +/// rawdata get adc num from byte +#define GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(x) (((x) & 0x18) >> 3) + +/// slot & adc num bits of rawdata byte +#define GH3X2X_SLOT_ADC_NUM_BITS (0xF8) + +/// rawdata get slot adc num from byte +#define GH3X2X_BYTE_RAWDATA_GET_SLOT_ADC_NUM(x) (((x) & GH3X2X_SLOT_ADC_NUM_BITS) >> 3) + +/// get slot index from channel num +#define GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(x) (((x) & 0x1F) >> 2) + +/// get adc index from channel num +#define GH3X2X_GET_ADC_FROM_CHANNEL_NUM(x) ((x) & 0x3) + +/// rawdata clear all flag +#define GH3X2X_RAWDATA_CLEAR_ALL_FLAG(x) ((x) & 0x00FFFFFF) + +/// rawdata clear data +#define GH3X2X_RAWDATA_CLEAR_DATA(x) ((x) & 0xFF000000) + +/// rawdata get adj flag0 +#define GH3X2X_RAWDATA_GET_ADJ_FLAG0(x) (((x) & 0x4000000) >> 26) + +/// rawdata get adj flag1 +#define GH3X2X_RAWDATA_GET_ADJ_FLAG1(x) (((x) & 0x2000000) >> 25) + +/// get rawdata for algorithm +#define GH3X2X_GET_RAWDATA_FOR_ALGO(x) ((x) >> 7) + +/// rawdata get fast recovery flag +#define GH3X2X_RAWDATA_GET_FAST_RECOVERY_FLAG(x) (((x) & 0x4000000) >> 26) + +/// rawdata real offset +#define GH3X2X_RAWDATA_REAL_OFFSET (0x00800000) + +/* utils macro */ + +/// byte true flag val +#define GH3X2X_BYTE_FLAG_TRUE (1) + +/// byte false flag val +#define GH3X2X_BYTE_FLAG_FALSE (0) + +/// GF32 0 val +#define GH3X2X_GF32_0 (0.0f) + +/// null val +#define GH3X2X_PTR_NULL ((void *) 0) + +/// get high 4bits from byte +#define GH3X2X_GET_HIGH_4BITS(val) ((val) & 0xF0) + +/// get low 4bits from byte +#define GH3X2X_GET_LOW_4BITS(val) ((val) & 0x0F) + +/// get first 4bits from byte +#define GH3X2X_GET_FIRST_4BITS(val) ((val) & 0x0000000FU) + +/// get high byte from word +#define GH3X2X_GET_HIGH_BYTE_FROM_WORD(sValue) ((GU8)(((sValue) >> 8) & 0xFFU)) + +/// get low byte from word +#define GH3X2X_GET_LOW_BYTE_FROM_WORD(sValue) ((GU8)((sValue) & 0xFFU)) + +/// get byte3 from dword +#define GH3X2X_GET_BYTE3_FROM_DWORD(unValue) ((GU8)(((unValue) >> 24) & 0x000000FFU)) + +/// get byte2 from dword +#define GH3X2X_GET_BYTE2_FROM_DWORD(unValue) ((GU8)(((unValue) >> 16) & 0x000000FFU)) + +/// get byte1 from dword +#define GH3X2X_GET_BYTE1_FROM_DWORD(unValue) ((GU8)(((unValue) >> 8) & 0x000000FFU)) + +/// get byte0 from dword +#define GH3X2X_GET_BYTE0_FROM_DWORD(unValue) ((GU8)((unValue) & 0x000000FFU)) + +/// get high word from dword +#define GH3X2X_GET_HIGH_WORD_FROM_DWORD(unValue) ((GU16)(((unValue) >> 16) & 0x0000FFFFU)) + +/// get low word from dword +#define GH3X2X_GET_LOW_WORD_FROM_DWORD(unValue) ((GU16)((unValue) & 0x0000FFFFU)) + +/// makeup word from bytes +#define GH3X2X_MAKEUP_WORD(uchHighByte, uchLowByte) ((GU16)(((((GU16)(uchHighByte)) << 8)& 0xFF00) |\ + (((GU16)(uchLowByte))& 0x00FF))) + +/// makeup dword from bytes +#define GH3X2X_MAKEUP_DWORD(uchByte3, uchByte2, uchByte1, uchByte0) (((((GU32)(uchByte3)) << 24) & 0xFF000000U)|\ + ((((GU32)(uchByte2)) << 16) & 0x00FF0000U) |\ + ((((GU32)(uchByte1)) << 8) & 0x0000FF00U) |\ + (((GU32)(uchByte0)) & 0x000000FFU)) + +/// makeup dword from words +#define GH3X2X_MAKEUP_DWORD2(usHighWord, usLowWord) (((((GU32)(usHighWord)) << 16) & 0xFFFF0000U) |\ + (((GU32)(usLowWord)) & 0x0000FFFFU)) + +/// macro of hook function call +/* NOLINTNEXTLINE(501) */ +#define HOOK_FUNC_CALL(func, argv) do { if ((func) != GH3X2X_PTR_NULL) { func argv; } } while (0) + +/// macro of handle function call +/* NOLINTNEXTLINE(501) */ +#define HANDLE_FUNC_CALL(func, argv) do { if ((func) != GH3X2X_PTR_NULL) { func argv; } } while (0) + +/// macro of set val via ptr +#define SET_VAL_VIA_PTR(ptr, val) do { if ((ptr) != GH3X2X_PTR_NULL) { (*(ptr)) = (val); } } while (0) + +/* bit operation macro */ + +/// macro of set bits +#define GH3X2X_SET_BIT(x, b) ((x) | (b)) + +/// macro of val set bits +#define GH3X2X_VAL_SET_BIT(x, b) ((x) |= (b)) + +/// macro of clear bits +#define GH3X2X_CLEAR_BIT(x, b) ((x) & (~(b))) + +/// macro of val clear bits +#define GH3X2X_VAL_CLEAR_BIT(x, b) ((x) &= (~(b))) + +/// macro of val get bits +#define GH3X2X_VAL_GET_BIT(x, b) ((x) &= (b)) + +/// macro of check bits set +#define GH3X2X_CHECK_BIT_SET(x, b) (((x) & (b)) == (b)) + +/// macro of check bits not set +#define GH3X2X_CHECK_BIT_NOT_SET(x, b) (((x) & (b)) != (b)) + +/// macro of check bits is set +#define GH3X2X_CHECK_BIT_IS_SET(x, b) (((x) & (b)) == (b)) + +/// macro of get bits is set +#define GH3X2X_GET_BIT_IS_SET(x) ((x) & 0xf000) + +/// macro of bit number in one byte +#define GH3X2X_BIT_PER_BYTE (4) + +/// macro of bit in reg addr for check +#define GH3X2X_REG_MODE_BIT (3) + +/// macro of check bits zero +#define GH3X2X_CHECK_REG_MODE_BIT_ZERO(x) (((x) >> (GH3X2X_BIT_PER_BYTE * GH3X2X_REG_MODE_BIT)) == (0)) + +/// macro of check lsb set +#define GH3X2X_CHECK_LSB_SET(x) (GH3X2X_CHECK_BIT_SET((x), 0x01)) + +/// macro of check left shift bit set +#define GH3X2X_CHECK_LEFT_BIT_SET(x, l) (GH3X2X_CHECK_BIT_SET((x), (1u << (l)))) + +/// macro of check left shift bit not set +#define GH3X2X_CHECK_LEFT_BIT_NOT_SET(x, l) (GH3X2X_CHECK_BIT_NOT_SET((x), (1u << (l)))) + +/// macro of val clear left shift bit +#define GH3X2X_VAL_CLEAR_LEFT_BIT(x, l) ((x) &= (~((1u << (l))))) + +/// check ret error +#define GH3X2X_RET_ERROR_CHECK(x) do { \ + if ((x) != GH3X2X_RET_OK)\ + {\ + return (x);\ + }\ + } while (0) + +/// check ret the error +#define GH3X2X_RET_ERROR_CHECK_E(x, e) do { \ + if ((x) == (e))\ + {\ + return (x);\ + }\ + } while (0) + +/// check ret the error +#define GH3X2X_RET_ERROR_CHECK_ER(x, e, r) do { \ + if ((x) == (e))\ + {\ + return (r);\ + }\ + } while (0) + +/// val rigth shfit +#define GH3X2X_SET_VAL_RIGTH_SHIFT(x, r) ((x) >>= (r)) + +/// val rigth shfit 1bit +#define GH3X2X_SET_VAL_RIGTH_SHIFT_1BIT(x) (GH3X2X_SET_VAL_RIGTH_SHIFT((x), 1u)) + +/// val left shfit +#define GH3X2X_SET_VAL_LEFT_SHIFT(x, l) ((x) <<= (l)) + +/// val left shfit 1bit +#define GH3X2X_SET_VAL_LEFT_SHIFT_1BIT(x) (GH3X2X_SET_VAL_LEFT_SHIFT((x), 1u)) + +/// get left shfit val +#define GH3X2X_GET_LEFT_SHIFT_VAL(l) (1u << (l)) + +/// val left shfit +#define GH3X2X_VAL_LEFT_SHIFT(x, l) ((x) << (l)) + +/// val cal diff value +#define GH3X2X_VAL_DIFF_VALUE(a, b) ((a) > (b) ? ((a) - (b)) : ((b) - (a))) + +/// val cal diff status +#define GH3X2X_VAL_DIFF_STA(a, b) ((a) > (b) ? (0) : (1)) + +/// val cal diff ABS +#define GH3X2X_VAL_ABS(x) ((x) >= 0 ? (x) : - (x)) + +/// val zip rawdata send cmd EVEN or ODD +#define GH3X2X_VAL_ZIPSENDCMD(x) ((x) == 1 ? (GH3X2X_UPROTOCOL_CMD_ZIPEVENRAWDATA) \ + : (GH3X2X_UPROTOCOL_CMD_ZIPODDRAWDATA)) + + + +#endif /* _GH3X2X_DRV_COMMON_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_accppg_sync.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_accppg_sync.c new file mode 100644 index 000000000..bd37a8df8 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_accppg_sync.c @@ -0,0 +1,39 @@ +#include +//#include "gh3x2x_demo_inner.h" +#include "gh3x2x_demo_algo_config.h" +#include "gh3x2x_demo_accppg_sync.h" +#include "gh3x2x_demo_common.h" + +GU8 GH3X2X_TimestampSyncGetFrameDataFlag(void) +{ + return 1; +} + +void GH3X2X_TimestampSyncSetPpgIntFlag(GU8 uchPpgIntFlag) +{ +} + +void GH3X2X_TimestampSyncAccInit(void) +{ +} + +void GH3X2X_TimestampSyncPpgInit(GU32 unFunctionID) +{ +} + +void GH3X2X_TimestampSyncSend2AlgoCall(GU8 uchFuncOffsetID) +{ +} + +void GH3X2X_TimestampSyncFillAccSyncBuffer(GU32 unTimeStamp, + GS16 usAccX, + GS16 usAccY, + GS16 usAccZ) +{ +} + +void GH3X2X_TimestampSyncFillPpgSyncBuffer(GU32 unTimeStamp, + const STGh3x2xFrameInfo * const pstFrameInfo) +{ +} + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_call.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_call.c new file mode 100644 index 000000000..6c5008235 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_call.c @@ -0,0 +1,367 @@ +#include +#include "gh3x2x_demo_algo_memory.h" +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algo_config.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_call_version.h" +#include "goodix_algo.h" +#include "goodix_mem.h" +#include "goodix_type.h" +#include "goodix_hba.h" +#include "goodix_ecg.h" +#include "goodix_af.h" +#include "goodix_hsm.h" +#include "goodix_resp.h" +#include "goodix_hrv.h" +#include "goodix_spo2.h" +#include "goodix_nadt.h" +#include "goodix_algo_bt.h" + +#if (__GOODIX_ALGO_CALL_MODE__) +extern const STGh3x2xInitConfig g_stGoodixAlgoCfgListArr[__GOODIX_ALGO_CFG_LIST_MAX_NUM__]; +STGh3x2xFrameInfo ** g_pstGh3x2xAlgoFrameInfo = GH3X2X_PTR_NULL; +static GU32 g_unAlgoFuncStartedBitmap = 0; +static GU8 g_uchAlgInitFlag[GH3X2X_FUNC_OFFSET_MAX] = {0}; +static const pfnAlgorithmCallFunc g_pfnAlgorithmCallFunc[GH3X2X_FUNC_OFFSET_MAX][GH3X2X_ALGO_FUNCTION_NUM_MAX] = { +//adt +#if __USE_GOODIX_ADT_ALGORITHM__ + { GH3x2xAdtAlgoInit, GH3x2xAdtAlgoExe, GH3x2xAdtAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//hr +#if __USE_GOODIX_HR_ALGORITHM__ + { GH3x2xHrAlgoInit, GH3x2xHrAlgoExe, GH3x2xHrAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//hrv +#if __USE_GOODIX_HRV_ALGORITHM__ + { GH3x2xHrvAlgoInit, GH3x2xHrvAlgoExe, GH3x2xHrvAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//hsm +#if __USE_GOODIX_HSM_ALGORITHM__ + { GH3x2xHsmAlgoInit, GH3x2xHsmAlgoExe, GH3x2xHsmAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//fpbp +//pwa +#if __USE_GOODIX_BP_ALGORITHM__ + { GH3x2xBpAlgoInit, GH3x2xBpAlgoExe, GH3x2xBpAlgoDeinit }, + { GH3x2xBpAlgoInit, GH3x2xBpAlgoExe, GH3x2xBpAlgoDeinit }, +#else + { 0, 0, 0 }, + { 0, 0, 0 }, +#endif +//spo2 +#if __USE_GOODIX_SPO2_ALGORITHM__ + { GH3x2xSpo2AlgoInit, GH3x2xSpo2AlgoExe, GH3x2xSpo2AlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//ecg +#if __USE_GOODIX_ECG_ALGORITHM__ + { GH3x2xEcgAlgoInit, GH3x2xEcgAlgoExe, GH3x2xEcgAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//pwtt + { 0, 0, 0 }, +//soft adt green +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ + { GH3x2xSoftAdtAlgoInit, GH3x2xSoftAdtAlgoExe, GH3x2xSoftAdtAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//bt +#if __USE_GOODIX_BT_ALGORITHM__ + { GH3x2xBtAlgoInit, GH3x2xBtAlgoExe, GH3x2xBtAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//resp +#if __USE_GOODIX_RESP_ALGORITHM__ + { GH3x2xRespAlgoInit, GH3x2xRespAlgoExe, GH3x2xRespAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//af +#if __USE_GOODIX_AF_ALGORITHM__ && __USE_GOODIX_HRV_ALGORITHM__ + { GH3x2xAfAlgoInit, GH3x2xAfAlgoExe, GH3x2xAfAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +//test + { 0, 0, 0 }, + { 0, 0, 0 }, +//soft adt ir +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ + { GH3x2xSoftAdtAlgoInit, GH3x2xSoftAdtAlgoExe, GH3x2xSoftAdtAlgoDeinit }, +#else + { 0, 0, 0 }, +#endif +}; + +GCHAR* GH3X2X_GetAlgoCallDemoVersion(void) +{ + return GOODIX_ALGO_CALL_VERSION_STRING; +} + +void GH3X2X_RegisterFuncInfoStruct(const STGh3x2xFrameInfo * const pstGh3x2xFrameInfo[]) +{ + g_pstGh3x2xAlgoFrameInfo = (STGh3x2xFrameInfo **)pstGh3x2xFrameInfo; +} + +void GH3X2X_AlgoCallConfigInit(const STGh3x2xFrameInfo * const pstGh3x2xFrameInfo[], GU8 uchAlgoCfgIndex) +{ + if (pstGh3x2xFrameInfo != GH3X2X_PTR_NULL) + { + g_pstGh3x2xAlgoFrameInfo = (STGh3x2xFrameInfo **)pstGh3x2xFrameInfo; + } + GH3X2X_AlgoMemConfig(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL); + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem size = %d\r\n",(int)GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL); + if(uchAlgoCfgIndex < __GOODIX_ALGO_CFG_LIST_MAX_NUM__) + { + GH3X2X_LoadGoodixAlgoRegConfigArr(&g_stGoodixAlgoCfgListArr[uchAlgoCfgIndex]); + } + +} + +void GH3X2X_AlgoVersion(GU8 uchFunctionID, GCHAR version[120]) +{ + if (version == 0) + { + GH3X2X_DEBUG_ALGO_LOG("[%s]:version buffer is NULL!!!\r\n", __FUNCTION__); + return; + } + GCHAR chNoVersion[10] = "no_ver"; + + switch (uchFunctionID) + { +#if __USE_GOODIX_ADT_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_ADT: + GH3X2X_Memcpy(version, GH3x2xAdtVersion(), strlen((const GCHAR *)GH3x2xAdtVersion()) + 1); + break; +#endif +#if __USE_GOODIX_HR_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_HR: + goodix_hba_version((uint8_t*)version); + break; +#endif +#if __USE_GOODIX_HRV_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_HRV: + GH3X2X_Memcpy(version, goodix_hrv_version(), strlen((const GCHAR *)goodix_hrv_version()) + 1); + break; +#endif +#if __USE_GOODIX_SPO2_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_SPO2: + goodix_spo2_version((uint8_t*)version); + break; +#endif +#if __USE_GOODIX_ECG_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_ECG: + goodix_ecg_version((uint8_t*)version); + break; +#endif +#if __USE_GOODIX_HSM_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_HSM: + GH3X2X_Memcpy(version, HSMAlgoVersion(), strlen((const GCHAR *)HSMAlgoVersion()) + 1); + break; +#endif +#if __USE_GOODIX_AF_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_AF: + GH3X2X_Memcpy(version, AFVersion(), strlen((const GCHAR *)AFVersion()) + 1); + break; +#endif +#if __USE_GOODIX_RESP_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_RESP: + GH3X2X_Memcpy(version, RespAlgoVersion(), strlen((const GCHAR *)RespAlgoVersion()) + 1); + break; +#endif +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_SOFT_ADT_GREEN: + case GH3X2X_FUNC_OFFSET_SOFT_ADT_IR: + GetNadtVersion((uint8_t *)version); + break; +#endif +#if __USE_GOODIX_BP_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_PWA: + case GH3X2X_FUNC_OFFSET_FPBP: + //GH3X2X_Memcpy(version, GoodixBpAlgoVersion(), strlen((const GCHAR *)GoodixBpAlgoVersion()) + 1); + break; +#endif +#if __USE_GOODIX_BT_ALGORITHM__ + case GH3X2X_FUNC_OFFSET_BT: +#if!__USE_GOODIX_DRV_NTC_Convert + GH3X2X_Memcpy(version, GoodixBtAlgoVersion(), strlen((const GCHAR *)GoodixBtAlgoVersion()) + 1); +#endif + break; +#endif + default: + GH3X2X_Memcpy(version, (GCHAR *)chNoVersion,\ + strlen((const GCHAR *)chNoVersion) + 1); + break; + } + //GH3X2X_INFO_ALGO_LOG("version = %s\n", version); +} + +GS8 GH3X2X_AlgoInit(GU32 unFunctionID) +{ + GU8 chRet = GH3X2X_RET_OK; + + if(GH3X2X_PTR_NULL == g_pstGh3x2xAlgoFrameInfo) + { + GH3X2X_INFO_ALGO_LOG("[%s]: Warning!!! g_pstGh3x2xAlgoFrameInfo is not init!\r\n", __FUNCTION__); + return GH3X2X_RET_OK; + } + + /* set started bit */ + g_unAlgoFuncStartedBitmap |= unFunctionID; + + /* init mem pool */ + if (GH3X2X_GetAlgoMemStatus() != ALGO_MEM_INIT_OK) + { + return -1; + } + + for(GU8 uchFunCnt = 0; uchFunCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunCnt ++) + { + if (((1<punFrameFlag[2] |= ((GU32)1)<<3; + } + if (0 == g_uchAlgInitFlag[uchFunCnt]) + { + //GH3X2X_DEBUG_ALGO_LOG("Function(funcition id = %d) didn't init!\r\n",(int)uchFunCnt); + } + else + { + if (g_pfnAlgorithmCallFunc[uchFunCnt][GH3X2X_ALGO_CALCULATE_FUNCTION] != GH3X2X_PTR_NULL) + { + chRet = g_pfnAlgorithmCallFunc[uchFunCnt][GH3X2X_ALGO_CALCULATE_FUNCTION](pstFrameInfo); + if( *(pstFrameInfo->punFrameCnt) == 0 && pstFrameInfo->pstAlgoResult->uchUpdateFlag == 0 ) + { + GH3X2X_Memset(pstFrameInfo->pstAlgoResult,0,sizeof(STGh3x2xAlgoResult)); + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->usResultBit = 0xFF; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + } + } + } + } + } + else + { + chRet = GH3X2X_RET_OK; + } + } + return chRet; +} + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_config.c new file mode 100644 index 000000000..42ada59f1 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_config.c @@ -0,0 +1,648 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_algorithm_calc.c + * + * @brief gh3x2x algorithm calc functions + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#include +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" +#include "goodix_algo.h" +#include "goodix_mem.h" +#include "goodix_type.h" +#include "goodix_hba.h" +#include "goodix_hrv.h" +#include "goodix_spo2.h" +#include "goodix_nadt.h" +#include "goodix_algo_bt.h" + +#if (__GOODIX_ALGO_CALL_MODE__) + +/* hb algorithm */ +#if (__USE_GOODIX_HR_ALGORITHM__) +GS32 g_unHrParamsArr[GOODIX_HR_PARAMS_NUM_MAX] = { + 0, // 测试模式 + 0, // 运动场景 + 0, // 预留未使用 + 20, // 最晚出值时间 + 8, // 最早出值时间 + 0, // 预留未使用 + 0, // 预留未使用 + 0, // 预留未使用 + 0, // 预留未使用 + 0 // 预留未使用 + }; +/// hbd rawdata channel map +STAlgoChnlMap g_stHbaAlgoChnlMap = {0}; +#endif + +/* hrv algorithm */ +#if (__USE_GOODIX_HRV_ALGORITHM__) +GS32 g_nHrvParamsArr[GOODIX_HRV_PARAMS_NUM_MAX] = { + 0, // 需要分辨率为1ms的输出 + 200000, 100000, 300000, 300000 // ACC相关阈值 + }; +#endif + +/* spo2 algorithm */ +#if (__USE_GOODIX_SPO2_ALGORITHM__) +#if ((__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_BASIC) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_MEDIUM)) +GS32 g_nSpo2ParamssArr[GOODIX_SPO2_PARAMS_NUM_MAX] = { + 0, 0, -134717, -115284, 1097668, // 校准参数 + 0, // 心率使能标志 + 0, // 佩戴模式 + 30, 15, 4, 3, 90, // ACC运动判断阈值 + 1, 65, // 备用 + 30, 10, 90, // PPG参数 + 253, // 质量评估模块使能开关 + 95, // 低氧阈值 + 10, 25, 3, 6, 10, 5, // 出值策略 + 3 // 出值相关模块使能开关 + }; +#elif ((__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_PREMIUM) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_EXCLUSIVE)) +GS32 g_nSpo2ParamssArr[GOODIX_SPO2_PARAMS_NUM_MAX] = { + 0, 0, 0, -239878, 1111827, // 校准参数 + 1, // 心率使能标志 + 0, // 佩戴模式 + 50, 25, 3, 3, 90, // ACC运动判断阈值 + 0, 160, // 备用 + 35, 25, 85, // PPG参数 + 0xFD, // 质量评估模块使能开关 + 95, // 低氧阈值 + 12, 18, 2, 7, 10, 5, // 出值策略 + 3 // 出值相关模块使能开关 + }; +#endif +/// spo2 rawdata channel map +STAlgoChnlMap g_stSpo2AlgoChnlMap = {0}; +#endif + +/* ecg algorithm */ +#if (__USE_GOODIX_ECG_ALGORITHM__) +GS32 g_nEcgParamsArr[GOODIX_ECG_PARAMS_NUM_MAX] = { + 0, // 采样率 + 1, // 算法有效通道数 + 1, // QRS检测标志 + 0, // ECG耦合方式 + 0 // 芯片类型 + }; +/// ecg frame data cnt +GU32 g_unEcgFrameCnt = 0; +GU8 g_uchClassificationFlag; +GU8 g_unEcgTimeSeconds = 0; +#endif + +/* bt algorithm */ +#if (__USE_GOODIX_BT_ALGORITHM__) +GS32 g_nBtParamsArr[GOODIX_BT_PARAMS_NUM_MAX] = {0}; +#endif + +/* af algorithm */ +#if (__USE_GOODIX_AF_ALGORITHM__) +GS32 g_nAfParamsArr[GOODIX_AF_PARAMS_NUM_MAX] = {45, 0}; +#endif + +/// new data flag +GU8 g_uchNewDataFlag = 0; +GU8 g_uchGh3x2xSleepFlag = 0; + +//sensor enable +GU8 g_uchAlgoGsensorEnable = 0; +GU8 g_uchAlgoCapEnable = 0; +GU8 g_uchAlgoTempEnable = 0; + +GS32 GH3x2x_Round(GF32 fValue) +{ + GS32 nRet = 0; + float fEpsinon = 0.00001; + if((fValue >= -fEpsinon)&&(fValue <= fEpsinon)) + { + nRet = 0; + } + else if(fValue < -fEpsinon) + { + nRet = (GS32)(fValue - 0.5f); + } + else if(fValue > fEpsinon) + { + nRet = (GS32)(fValue + 0.5f); + } + return nRet; +} + +GU8 GH3x2x_BitCount(GU32 n) +{ + GU8 c =0 ; // 计数器 + while (n >0) + { + if((n &1) ==1) // 当前位是1 + ++c ; // 计数器加1 + n >>=1 ; // 移位 + } + return c ; +} + +void GH3x2xSleepFlagSet(GU8 uchSleepFlag) +{ + g_uchGh3x2xSleepFlag = uchSleepFlag; +} + + +GU8 GH3x2xSleepFlagGet(void) +{ + return g_uchGh3x2xSleepFlag; +} + +void GH3X2X_AlgoSensorEnable(GU8 uchAlgoGsensorEnable, + GU8 uchAlgoCapEnable, + GU8 uchAlgoTempEnable) +{ + g_uchAlgoGsensorEnable = uchAlgoGsensorEnable; + g_uchAlgoCapEnable = uchAlgoCapEnable; + g_uchAlgoTempEnable = uchAlgoTempEnable; +} + +/** + * @fn GS8 GH3X2X_BTAlgorithmRTConfig(GS32 nOutputTime) + * + * @brief BT algorithm RT table + * + * @attention None + * + * @param[in] nRTtable + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_ALGO_NO_SUPPORTED return algorithm no supported error + */ + +GS8 GH3X2X_BTAlgorithmRTConfig(GU16 *nRTtable) +{ +#if (__USE_GOODIX_BT_ALGORITHM__) + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + GH3X2X_Memcpy(g_nBtParamsArr, nRTtable, GOODIX_BT_PARAMS_NUM_MAX * sizeof(GU16)); + return GH3X2X_RET_OK; + +#else + GH3X2X_DEBUG_ALGO_LOG("BT algorithm no supported error!\r\n"); + return GH3X2X_RET_ALGO_NO_SUPPORTED; + +#endif +} +/** + * @fn void GH3X2X_SetNewDataFlag(EMChannelMapId emFuncId, GU8 uchFlag) + * + * @brief Set new sampling data flag + * + * @attention None + * + * @param[in] emFuncId function id + * @param[in] uchFlag new data or not + * @param[out] None + * + * @return None + */ +void GH3X2X_SetNewDataFlag(GU8 emFuncId, GU8 uchFlag) +{ + if (GH3X2X_IS_NOT_NEW_RAWDATA == uchFlag) + { + GH3X2X_VAL_CLEAR_LEFT_BIT(g_uchNewDataFlag, emFuncId); + } + else + { + GH3X2X_VAL_SET_BIT(g_uchNewDataFlag, GH3X2X_GET_LEFT_SHIFT_VAL(emFuncId)); + } +} + +/** + * @fn GS8 GH3X2X_HbAlgorithmScenarioConfig(GU8 uchScenario) + * + * @brief Hb algorithm scenario config + * + * @attention None + * + * @param[in] uchScenario @ref EMHbaScenesConfigType + * others: fixed 0(default) and return GH3X2X_RET_PARAMETER_ERROR + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return paramters error + * @retval #GH3X2X_RET_ALGO_NO_SUPPORTED return algorithm no supported error + */ +GS8 GH3X2X_HbAlgorithmScenarioConfig(GU8 uchScenario) +{ +#if (__USE_GOODIX_HR_ALGORITHM__) + + GS8 chRet = GH3X2X_RET_OK; + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + if (uchScenario > GH3X2X_HBA_SCENARIO_CONFIG_MAX_VAL) + { + GH3X2X_DEBUG_ALGO_LOG("hb algorithm scenario param error!\r\n"); + g_unHrParamsArr[1] = HBA_SCENES_DEFAULT; + chRet = GH3X2X_RET_PARAMETER_ERROR; + } + else + { + g_unHrParamsArr[1] = uchScenario; + } + +#else + + GS8 chRet = GH3X2X_RET_ALGO_NO_SUPPORTED; + GH3X2X_DEBUG_ALGO_LOG("hba algorithm no supported error!\r\n"); + +#endif + + return chRet; +} + +/** + * @fn GS8 GH3X2X_HbAlgorithmOutputTimeConfig(GS32 nOutputTime) + * + * @brief Hb algorithm output time config + * + * @attention None + * + * @param[in] nOutputTime valid 7~GS32_MAX + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_ALGO_NO_SUPPORTED return algorithm no supported error + */ +GS8 GH3X2X_HbAlgorithmOutputTimeConfig(GS32 nLatestOutputTime, GS32 nEarliestOutputTime) +{ +#if (__USE_GOODIX_HR_ALGORITHM__) + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + g_unHrParamsArr[3] = nLatestOutputTime; + g_unHrParamsArr[4] = nEarliestOutputTime; + return GH3X2X_RET_OK; + +#else + + GH3X2X_DEBUG_ALGO_LOG("hba algorithm no supported error!\r\n"); + return GH3X2X_RET_ALGO_NO_SUPPORTED; + +#endif +} + +GU16 GH3X2X_ReadSpo2CorrectionFactor(GU16 usVirtualRegAddr) +{ +#if 0 + GU16 usVirtualRegData = 0; + GU16 usValIndex = 0; + + if(usVirtualRegAddr >= GH3X2X_VSPO2_CH0_CORFAC0_L_REG_ADDR && usVirtualRegAddr <= GH3X2X_VSPO2_CH0_CORFAC2_H_REG_ADDR) + { + usValIndex = (usVirtualRegAddr - GH3X2X_VSPO2_CH0_CORFAC0_L_REG_ADDR) / GH3X2X_REG_ADDR_SIZE; + } + else if(usVirtualRegAddr >= GH3X2X_VSPO2_CH0_CORFAC3_L_REG_ADDR && usVirtualRegAddr <= GH3X2X_VSPO2_CH3_CORFAC4_H_REG_ADDR) + { + usValIndex = (usVirtualRegAddr - GH3X2X_VSPO2_CH0_CORFAC3_L_REG_ADDR) / GH3X2X_REG_ADDR_SIZE + 6; + } + else + { + return usVirtualRegData; + } + + if ((usValIndex % GH3X2X_REG_ADDR_SIZE) == 0) // low word + { + usVirtualRegData = GH3X2X_GET_LOW_WORD_FROM_DWORD( + g_nSpo2ParamssArr[usValIndex / (SP02_CORR_FAC_NUM * 2)][(usValIndex % (SP02_CORR_FAC_NUM * 2)) / GH3X2X_REG_ADDR_SIZE]); + } + else // high word + { + usVirtualRegData = GH3X2X_GET_HIGH_WORD_FROM_DWORD( + g_nSpo2ParamssArr[usValIndex / (SP02_CORR_FAC_NUM * 2)][(usValIndex % (SP02_CORR_FAC_NUM * 2)) / GH3X2X_REG_ADDR_SIZE]); + } + + + return usVirtualRegData; +#else + return 0; +#endif +} + +/** + * @fn void GH3X2X_AlgoChnlMapInit(STAlgoChnlMap stAlgoChnlMap) + * + * @brief Init algo channel group struct + * + * @attention + * + * + * @return None + */ +void GH3X2X_AlgoChnlMapInit(STAlgoChnlMap *pstAlgoChnlMap) +{ + (*pstAlgoChnlMap).uchFlag = 0; + (*pstAlgoChnlMap).uchNum = 0; + for (GU32 num = 0 ; num < ALGO_CHNL_NUM ; num ++) + { + (*pstAlgoChnlMap).uchAlgoChnlMap[num] = 0xff; + } +} + +/** + * @fn void GH3X2X_HbaAlgoChnlMapDefultSet(void) + + * + * @brief Set algo channel group Defult value + * + * @attention + * + * + * @return None + */ +void GH3X2X_HbaAlgoChnlMapDefultSet(void) +{ +#if (__USE_GOODIX_HR_ALGORITHM__) + if (!g_stHbaAlgoChnlMap.uchFlag) + { + GH3X2X_AlgoChnlMapInit(&g_stHbaAlgoChnlMap); + g_stHbaAlgoChnlMap.uchNum = __HR_ALGORITHM_SUPPORT_CHNL_NUM__; + for (GU8 cnt = 0; cnt < __HR_ALGORITHM_SUPPORT_CHNL_NUM__; cnt++) + { + g_stHbaAlgoChnlMap.uchAlgoChnlMap[ALGO_GREEN_CHNL_POS + cnt] = cnt; + } + } +#endif +} + +/** + * @fn void GH3X2X_HrvAlgoChnlMapDefultSet(void) + + * + * @brief Set algo channel group Defult value + * + * @attention + * + * + * @return None + */ +void GH3X2X_HrvAlgoChnlMapDefultSet(void) +{ +#if (0) + if (!g_stHrvAlgoChnlMap.uchFlag) + { + GH3X2X_AlgoChnlMapInit(&g_stHrvAlgoChnlMap); + g_stHrvAlgoChnlMap.uchNum = 1; + g_stHrvAlgoChnlMap.uchAlgoChnlMap[ALGO_GREEN_CHNL_POS + 0] = 0; + } +#endif +} + +/** + * @fn void GH3X2X_Spo2AlgoChnlMapDefultSet(void) + + * + * @brief Set algo channel group Defult value + * + * @attention + * + * + * @return None + */ +void GH3X2X_Spo2AlgoChnlMapDefultSet(void) +{ +#if (__USE_GOODIX_SPO2_ALGORITHM__) + if (!g_stSpo2AlgoChnlMap.uchFlag) + { + GH3X2X_AlgoChnlMapInit(&g_stSpo2AlgoChnlMap); + g_stSpo2AlgoChnlMap.uchNum = 1; + g_stSpo2AlgoChnlMap.uchAlgoChnlMap[ALGO_RED_CHNL_POS + 0] = 0; + g_stSpo2AlgoChnlMap.uchAlgoChnlMap[ALGO_IR_CHNL_POS + 0] = __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__; + } +#endif +} + +void GH3X2X_BpAlgoChnlMapDefultSet(void) +{ +#if (__USE_GOODIX_BP_ALGORITHM__) + if (!g_stBpAlgoChnlMap.uchFlag) + { + GH3X2X_AlgoChnlMapInit(&g_stBpAlgoChnlMap); + g_stBpAlgoChnlMap.uchNum = 1; + g_stBpAlgoChnlMap.uchAlgoChnlMap[ALGO_GREEN_CHNL_POS + 0] = 1; + g_stBpAlgoChnlMap.uchEcgAlgoChnlMap = 0; + } +#endif +} + + +void GH3X2X_WriteAlgParametersWithVirtualReg(GU8 uchParasIndex, GU32 unFunctionID, GS32* nAlgParametersBuffer, GU8 nBufferMaxLen, GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GU16 usValIndex = (usVirtualRegAddr - (unFunctionID * GH3X2X_VREG_FUNCTION_OFFSET + GH3X2X_ADT_ALG_CFG_ADDR)) / GH3X2X_REG_ADDR_SIZE; + if ((GS16)((GS16)usValIndex / (GS16)GH3X2X_REG_ADDR_SIZE - (GS16)uchParasIndex < 0) ||\ + (usValIndex / GH3X2X_REG_ADDR_SIZE - uchParasIndex >= nBufferMaxLen)) + { + return; + } + if ((usValIndex % GH3X2X_REG_ADDR_SIZE) != 0) // high word + { + nAlgParametersBuffer[usValIndex / GH3X2X_REG_ADDR_SIZE - uchParasIndex] = \ + GH3X2X_MAKEUP_DWORD2(usVirtualRegValue, GH3X2X_GET_LOW_WORD_FROM_DWORD(nAlgParametersBuffer[usValIndex / GH3X2X_REG_ADDR_SIZE - uchParasIndex])); + + } + else // low word + { + nAlgParametersBuffer[usValIndex / GH3X2X_REG_ADDR_SIZE - uchParasIndex] = \ + GH3X2X_MAKEUP_DWORD2(GH3X2X_GET_HIGH_WORD_FROM_DWORD(nAlgParametersBuffer[usValIndex / GH3X2X_REG_ADDR_SIZE - uchParasIndex]), usVirtualRegValue); + } +} + +void GH3X2X_WriteAlgChnlMapWithVirtualReg(GU32 unFunctionID, STAlgoChnlMap* pstAlgChnlMap, GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GU16 usVirtualRegAddrOffset = usVirtualRegAddr - (unFunctionID * GH3X2X_VREG_FUNCTION_OFFSET + GH3X2X_ADT_ALG_CFG_ADDR); + switch (usVirtualRegAddrOffset) + { + case GH3X2X_VREG_ALGO_CHNL_MAP_OFFSET: + GH3X2X_AlgoChnlMapInit(pstAlgChnlMap); + pstAlgChnlMap->uchNum = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + if (pstAlgChnlMap->uchNum) + { + pstAlgChnlMap->uchFlag = 1; + } + break; + case GH3X2X_VREG_ALGO_CHNL_MAP_OFFSET + GH3X2X_REG_ADDR_SIZE: + pstAlgChnlMap->uchEcgAlgoChnlMap = (GU8)(usVirtualRegValue & 0x000000FF); + break; + default: + pstAlgChnlMap->uchAlgoChnlMap[usVirtualRegAddrOffset - GH3X2X_VREG_ALGO_CHNL_MAP_OFFSET - 2 * GH3X2X_REG_ADDR_SIZE]\ + = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + pstAlgChnlMap->uchAlgoChnlMap[usVirtualRegAddrOffset - GH3X2X_VREG_ALGO_CHNL_MAP_OFFSET - 2 * GH3X2X_REG_ADDR_SIZE + 1]\ + = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usVirtualRegValue); + } +} + +void GH3X2X_WriteHrAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ +#if (__USE_GOODIX_HR_ALGORITHM__) // hr + if (usVirtualRegAddr < GH3X2X_HR_ALGO_CHNL_NUM_ADDR) + { + if(!g_stHbaAlgoChnlMap.uchFlag) + { + GH3X2X_AlgoChnlMapInit(&g_stHbaAlgoChnlMap); + } + + //GH3X2X_WriteAlgParametersWithVirtualReg(0, GH3X2X_FUNC_OFFSET_HR, (GS32*)&g_unHrParamsArr, GOODIX_HR_PARAMS_NUM_MAX, usVirtualRegAddr,usVirtualRegValue); + //GH3X2X_DEBUG_ALGO_LOG("[%s]:Hba Scenario = %d\r\n", __FUNCTION__, g_unHrParamsArr[1]); + if(HBA_SCENES_SLEEP == g_unHrParamsArr[1]) + { + GH3x2xSleepFlagSet(1); + } + } + else + { + GH3X2X_WriteAlgChnlMapWithVirtualReg(GH3X2X_FUNC_OFFSET_HR, &g_stHbaAlgoChnlMap, usVirtualRegAddr, usVirtualRegValue); + } +#endif +} + +void GH3X2X_WriteHrvAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ +#if (__USE_GOODIX_HRV_ALGORITHM__) // hrv + GH3X2X_WriteAlgParametersWithVirtualReg(0, GH3X2X_FUNC_OFFSET_HRV, (GS32*)g_nHrvParamsArr, GOODIX_HRV_PARAMS_NUM_MAX, usVirtualRegAddr, usVirtualRegValue); +#endif +} + +void GH3X2X_WriteSpo2AlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ +#if (__USE_GOODIX_SPO2_ALGORITHM__) // spo2 + if (usVirtualRegAddr < GH3X2X_SPO2_ALGO_CHNL_NUM_ADDR) + { + GH3X2X_AlgoChnlMapInit(&g_stSpo2AlgoChnlMap); + //GH3X2X_WriteAlgParametersWithVirtualReg(0, GH3X2X_FUNC_OFFSET_SPO2, (GS32*)g_nSpo2ParamssArr, GOODIX_SPO2_PARAMS_NUM_MAX, usVirtualRegAddr,usVirtualRegValue); + } + else + { + GH3X2X_WriteAlgChnlMapWithVirtualReg(GH3X2X_FUNC_OFFSET_SPO2, &g_stSpo2AlgoChnlMap, usVirtualRegAddr, usVirtualRegValue); + } +#endif +} + +void GH3X2X_WriteEcgAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ +#if (__USE_GOODIX_ECG_ALGORITHM__) // ecg + GH3X2X_WriteAlgParametersWithVirtualReg(0, GH3X2X_FUNC_OFFSET_ECG, (GS32*)g_nEcgParamsArr, GOODIX_ECG_PARAMS_NUM_MAX, usVirtualRegAddr, usVirtualRegValue); +#endif +} + +void GH3X2X_WriteBtAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ +#if (__USE_GOODIX_BT_ALGORITHM__) // bt + GH3X2X_WriteAlgParametersWithVirtualReg(0, GH3X2X_FUNC_OFFSET_BT, (GS32*)g_nBtParamsArr, GOODIX_BT_PARAMS_NUM_MAX, usVirtualRegAddr, usVirtualRegValue); +#endif +} + +void GH3X2X_WriteAfAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ +#if (__USE_GOODIX_AF_ALGORITHM__) // af + GH3X2X_WriteAlgParametersWithVirtualReg(0, GH3X2X_FUNC_OFFSET_AF, (GS32*)&g_nAfParamsArr, GOODIX_AF_PARAMS_NUM_MAX, usVirtualRegAddr, usVirtualRegValue); +#endif +} + +void GH3X2X_WriteBpAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ +#if (__USE_GOODIX_BP_ALGORITHM__) // fpbp + +#endif +} + + +/** + * @fn GU16 GH3X2X_ReadAlgorithmConfigWithVirtualReg(GU16 usVirtualRegAddr) + * + * @brief Read algorithm param config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[out] None + * + * @return virtual reg val + */ +GU16 GH3X2X_ReadAlgorithmConfigWithVirtualReg(GU16 usVirtualRegAddr) +{ + GU16 usVirtualRegData = 0; + + return usVirtualRegData; +} + +void GH3X2X_WriteAlgConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + if (usVirtualRegAddr < GH3X2X_REG_IS_VIRTUAL0X3_BIT) + { + return; + } + GU32 unFunctionID = (usVirtualRegAddr - GH3X2X_REG_IS_VIRTUAL0X3_BIT) / GH3X2X_VREG_FUNCTION_OFFSET; + if (usVirtualRegAddr >= GH3X2X_ADT_ALG_CFG_ADDR + GH3X2X_VREG_FUNCTION_OFFSET * unFunctionID &&\ + usVirtualRegAddr < GH3X2X_ADT_DRV_CFG_ADDR + GH3X2X_VREG_FUNCTION_OFFSET * (unFunctionID + 1)) + { + switch (unFunctionID) + { + case GH3X2X_FUNC_OFFSET_HR: + GH3X2X_WriteHrAlgConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + break; + case GH3X2X_FUNC_OFFSET_HRV: + GH3X2X_WriteHrvAlgConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + break; + case GH3X2X_FUNC_OFFSET_FPBP: + case GH3X2X_FUNC_OFFSET_PWA: + //GH3X2X_WriteBpAlgConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + break; + case GH3X2X_FUNC_OFFSET_SPO2: + GH3X2X_WriteSpo2AlgConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + break; + case GH3X2X_FUNC_OFFSET_ECG: + GH3X2X_WriteEcgAlgConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + break; + case GH3X2X_FUNC_OFFSET_BT: + GH3X2X_WriteBtAlgConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + break; + case GH3X2X_FUNC_OFFSET_AF: + GH3X2X_WriteAfAlgConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + break; + default: + break; + } + } +} + +void GH3X2X_LoadGoodixAlgoRegConfigArr(const STGh3x2xInitConfig *pstGoodixAlgoCfgListArr) +{ + const STGh3x2xReg *pstRegConfigArr = pstGoodixAlgoCfgListArr->pstRegConfigArr; + GU16 usRegConfigLen = pstGoodixAlgoCfgListArr->usConfigArrLen; + GU16 usIndex = 0; + if ((pstRegConfigArr != GH3X2X_PTR_NULL) && (usRegConfigLen != 0)) + { + for (usIndex = 0; usIndex < usRegConfigLen; usIndex++) // write GH3X2X reg. + { + GH3X2X_WriteAlgConfigWithVirtualReg(pstRegConfigArr[usIndex].usRegAddr, pstRegConfigArr[usIndex].usRegData); + } + } +} + +#endif + + + + + + + + + + + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_frame.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_frame.c new file mode 100644 index 000000000..6bae1d860 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_frame.c @@ -0,0 +1,817 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh2x2x_demo_algo_frame.c + * + * @brief gh3x2x algo frame info + * + * @author Gooidx Iot Team + * + */ + +/* includes */ +#include "gh3x2x_demo_algo_config.h" +#include "gh_demo_config.h" +#include "gh_drv.h" + + +#if __GH_SEPARATE_ALGO_EN__ + +#if __FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ +#if __USE_GOODIX_HR_ALGORITHM__ +GU32 g_pun_HR_FrameIncompleteRawdata[GH3X2X_HR_CHNL_NUM]; +GU32 g_un_HR_FrameIncompleteChnlMapBit; +GU8 g_puch_HR_FrameLastGain[GH3X2X_HR_CHNL_NUM]; +GU32 g_un_HR_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_HR; +#endif +#if __USE_GOODIX_HRV_ALGORITHM__ +GU32 g_pun_HRV_FrameIncompleteRawdata[GH3X2X_HRV_CHNL_NUM]; +GU32 g_un_HRV_FrameIncompleteChnlMapBit; +GU8 g_puch_HRV_FrameLastGain[GH3X2X_HRV_CHNL_NUM]; +GU32 g_un_HRV_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_HRV; +#endif +#if __USE_GOODIX_HSM_ALGORITHM__ +GU32 g_pun_HSM_FrameIncompleteRawdata[GH3X2X_HSM_CHNL_NUM]; +GU32 g_un_HSM_FrameIncompleteChnlMapBit; +GU8 g_puch_HSM_FrameLastGain[GH3X2X_HSM_CHNL_NUM]; +GU32 g_un_HSM_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_HSM; +#endif +#if __USE_GOODIX_SPO2_ALGORITHM__ +GU32 g_pun_SPO2_FrameIncompleteRawdata[GH3X2X_SPO2_CHNL_NUM]; +GU32 g_un_SPO2_FrameIncompleteChnlMapBit; +GU8 g_puch_SPO2_FrameLastGain[GH3X2X_SPO2_CHNL_NUM]; +GU32 g_un_SPO2_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_SPO2; +#endif +#if __USE_GOODIX_ECG_ALGORITHM__ +GU32 g_pun_ECG_FrameIncompleteRawdata[GH3X2X_ECG_CHNL_NUM]; +GU32 g_un_ECG_FrameIncompleteChnlMapBit; +GU8 g_puch_ECG_FrameLastGain[GH3X2X_ECG_CHNL_NUM]; +GU32 g_un_ECG_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_ECG; +#endif +#if 0 +GU32 g_pun_PWTT_FrameIncompleteRawdata[GH3X2X_PWTT_CHNL_NUM]; +GU32 g_un_PWTT_FrameIncompleteChnlMapBit; +GU8 g_puch_PWTT_FrameLastGain[GH3X2X_PWTT_CHNL_NUM]; +GU32 g_un_PWTT_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_PWTT; +#endif +#if __USE_GOODIX_BT_ALGORITHM__ +GU32 g_pun_BT_FrameIncompleteRawdata[GH3X2X_BT_CHNL_NUM]; +GU32 g_un_BT_FrameIncompleteChnlMapBit; +GU8 g_puch_BT_FrameLastGain[GH3X2X_BT_CHNL_NUM]; +GU32 g_un_BT_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_BT; +#endif +#if __USE_GOODIX_RESP_ALGORITHM__ +GU32 g_pun_RESP_FrameIncompleteRawdata[GH3X2X_RESP_CHNL_NUM]; +GU32 g_un_RESP_FrameIncompleteChnlMapBit; +GU8 g_puch_RESP_FrameLastGain[GH3X2X_RESP_CHNL_NUM]; +GU32 g_un_RESP_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_RESP; +#endif +#if __USE_GOODIX_AF_ALGORITHM__ +GU32 g_pun_AF_FrameIncompleteRawdata[GH3X2X_AF_CHNL_NUM]; +GU32 g_un_AF_FrameIncompleteChnlMapBit; +GU8 g_puch_AF_FrameLastGain[GH3X2X_AF_CHNL_NUM]; +GU32 g_un_AF_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_AF; +#endif +#if __USE_GOODIX_BP_ALGORITHM__ +GU32 g_pun_BP_FrameIncompleteRawdata[GH3X2X_BP_CHNL_NUM]; +GU32 g_un_BP_FrameIncompleteChnlMapBit; +GU8 g_puch_BP_FrameLastGain[GH3X2X_BP_CHNL_NUM]; +GU32 g_un_BP_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_BP; +#endif +#if 0 +GU32 g_pun_TEST1_FrameIncompleteRawdata[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST1_FrameIncompleteChnlMapBit; +GU8 g_puch_TEST1_FrameLastGain[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST1_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_TEST1; +GU32 g_pun_TEST2_FrameIncompleteRawdata[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST2_FrameIncompleteChnlMapBit; +GU8 g_puch_TEST2_FrameLastGain[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST2_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_TEST2; +#endif +#else +GU32 g_pun_MAIN_FUNC_FrameIncompleteRawdata[GH3X2X_MAIN_FUNC_CHNL_NUM]; +GU32 g_un_MAIN_FUNC_FrameIncompleteChnlMapBit; +GU8 g_puch_MAIN_FUNC_FrameLastGain[GH3X2X_MAIN_FUNC_CHNL_NUM]; +GU32 g_un_MAIN_FUNC_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_MAIN_FUNC; +#endif +#if __USE_GOODIX_ADT_ALGORITHM__ +GU32 g_pun_ADT_FrameIncompleteRawdata[GH3X2X_ADT_CHNL_NUM]; +GU32 g_un_ADT_FrameIncompleteChnlMapBit; +GU8 g_puch_ADT_FrameLastGain[GH3X2X_ADT_CHNL_NUM]; +GU32 g_un_ADT_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_ADT; +#endif +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ +GU32 g_pun_SOFT_ADT_GREEN_FrameIncompleteRawdata[GH3X2X_SOFT_ADT_CHNL_NUM]; +GU32 g_un_SOFT_ADT_GREEN_FrameIncompleteChnlMapBit; +GU8 g_puch_SOFT_ADT_GREEN_FrameLastGain[GH3X2X_SOFT_ADT_CHNL_NUM]; +GU32 g_un_SOFT_ADT_GREEN_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_SOFT_ADT_GREEN; +#endif + + + + +#if __USE_GOODIX_HR_ALGORITHM__ +GU8 g_pch_HR_ChnlMap[GH3X2X_HR_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_HR_FuncitonInfo; +STGh3x2xAlgoResult g_st_HR_AlgoRecordResult; +#endif +#if __USE_GOODIX_HRV_ALGORITHM__ +GU8 g_pch_HRV_ChnlMap[GH3X2X_HRV_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_HRV_FuncitonInfo; +STGh3x2xAlgoResult g_st_HRV_AlgoRecordResult; +#endif +#if __USE_GOODIX_HSM_ALGORITHM__ +GU8 g_pch_HSM_ChnlMap[GH3X2X_HSM_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_HSM_FuncitonInfo; +#endif +#if __USE_GOODIX_SPO2_ALGORITHM__ +GU8 g_pch_SPO2_ChnlMap[GH3X2X_SPO2_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_SPO2_FuncitonInfo; +STGh3x2xAlgoResult g_st_SPO2_AlgoRecordResult; +#endif +#if __USE_GOODIX_ECG_ALGORITHM__ +GU8 g_pch_ECG_ChnlMap[GH3X2X_ECG_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_ECG_FuncitonInfo; +#endif +#if 0 +GU8 g_pch_PWTT_ChnlMap[GH3X2X_PWTT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_PWTT_FuncitonInfo; +#endif +#if __USE_GOODIX_BT_ALGORITHM__ +GU8 g_pch_BT_ChnlMap[GH3X2X_BT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_BT_FuncitonInfo; +#endif +#if __USE_GOODIX_RESP_ALGORITHM__ +GU8 g_pch_RESP_ChnlMap[GH3X2X_RESP_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_RESP_FuncitonInfo; +#endif +#if __USE_GOODIX_AF_ALGORITHM__ +GU8 g_pch_AF_ChnlMap[GH3X2X_AF_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_AF_FuncitonInfo; +#endif +#if __USE_GOODIX_ADT_ALGORITHM__ +GU8 g_pch_ADT_ChnlMap[GH3X2X_ADT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_ADT_FuncitonInfo; +#endif +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ +GU8 g_pch_SOFT_ADT_GREEN_ChnlMap[GH3X2X_SOFT_ADT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_SOFT_ADT_GREEN_FuncitonInfo; +#endif +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ +GU8 g_pch_SOFT_ADT_IR_ChnlMap[GH3X2X_SOFT_ADT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_SOFT_ADT_IR_FuncitonInfo; +#endif +#if __FUNC_TYPE_BP_ENABLE__ +GU8 g_pch_BP_ChnlMap[GH3X2X_BP_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_BP_FuncitonInfo; +#endif +#if 0 +GU8 g_pch_TEST1_ChnlMap[GH3X2X_TEST_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_TEST1_FuncitonInfo; +GU8 g_pch_TEST2_ChnlMap[GH3X2X_TEST_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_TEST2_FuncitonInfo; +#endif + +GU32 g_punGh3x2xFrameRawdata[GH3X2X_FUNC_CHNL_NUM_MAX]; +#if __GS_GYRO_ENABLE__ +GS16 g_psGh3x2xFrameGsensorData[6]; +#else +GS16 g_psGh3x2xFrameGsensorData[3]; +#endif +GU32 g_punGh3x2xFrameAgcInfo[GH3X2X_FUNC_CHNL_NUM_MAX]; +GU32 g_punGh3x2xFrameFlag[8]; +STGh3x2xAlgoResult g_stGh3x2xAlgoResult; + +STCapRawdata g_pstGh3x2xFrameCapData; +STTempRawdata g_pstGh3x2xFrameTempData; + + + +//HR data info +#if __USE_GOODIX_HR_ALGORITHM__ +const STGh3x2xFrameInfo g_stHR_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_HR, + .pstFunctionInfo = &g_st_HR_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_HR_CHNL_NUM, + .pchChnlMap = g_pch_HR_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = &g_st_HR_AlgoRecordResult, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_HR_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_HR_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_HR_FrameLastGain, + .punFrameCnt = &g_un_HR_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_HR, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xHR_FrameInfo = &g_stHR_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xHR_FrameInfo = 0; +#endif +//HRV data info +#if __USE_GOODIX_HRV_ALGORITHM__ +const STGh3x2xFrameInfo g_stHRV_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_HRV, + .pstFunctionInfo = &g_st_HRV_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_HRV_CHNL_NUM, + .pchChnlMap = g_pch_HRV_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = &g_st_HRV_AlgoRecordResult, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_HRV_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_HRV_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_HRV_FrameLastGain, + .punFrameCnt = &g_un_HRV_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_HRV, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xHRV_FrameInfo = &g_stHRV_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xHRV_FrameInfo = 0; +#endif +//HSM data info +#if __USE_GOODIX_HSM_ALGORITHM__ +const STGh3x2xFrameInfo g_stHSM_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_HSM, + .pstFunctionInfo = &g_st_HSM_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_HSM_CHNL_NUM, + .pchChnlMap = g_pch_HSM_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_HSM_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_HSM_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_HSM_FrameLastGain, + .punFrameCnt = &g_un_HSM_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_HSM, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xHSM_FrameInfo = &g_stHSM_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xHSM_FrameInfo = 0; +#endif +//SPO2 data info +#if __USE_GOODIX_SPO2_ALGORITHM__ +const STGh3x2xFrameInfo g_stSPO2_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_SPO2, + .pstFunctionInfo = &g_st_SPO2_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_SPO2_CHNL_NUM, + .pchChnlMap = g_pch_SPO2_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = &g_st_SPO2_AlgoRecordResult, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_SPO2_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_SPO2_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_SPO2_FrameLastGain, + .punFrameCnt = &g_un_SPO2_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_SPO2, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xSPO2_FrameInfo = &g_stSPO2_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xSPO2_FrameInfo = 0; +#endif +//ECG data info +#if __USE_GOODIX_ECG_ALGORITHM__ +const STGh3x2xFrameInfo g_stECG_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_ECG, + .pstFunctionInfo = &g_st_ECG_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_ECG_CHNL_NUM, + .pchChnlMap = g_pch_ECG_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_ECG_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_ECG_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_ECG_FrameLastGain, + .punFrameCnt = &g_un_ECG_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_ECG, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = &g_stECG_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = 0; +#endif +#if 0 +const STGh3x2xFrameInfo g_stPWTT_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_PWTT, + .pstFunctionInfo = &g_st_PWTT_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_PWTT_CHNL_NUM, + .pchChnlMap = g_pch_PWTT_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_PWTT_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_PWTT_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_PWTT_FrameLastGain, + .punFrameCnt = &g_un_PWTT_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_PWTT, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = &g_stECG_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = 0; +#endif +//BT data info +#if __USE_GOODIX_BT_ALGORITHM__ +const STGh3x2xFrameInfo g_stBT_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_BT, + .pstFunctionInfo = &g_st_BT_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_BT_CHNL_NUM, + .pchChnlMap = g_pch_BT_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_BT_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_BT_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_BT_FrameLastGain, + .punFrameCnt = &g_un_BT_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_BT, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xBT_FrameInfo = &g_stBT_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xBT_FrameInfo = 0; +#endif +//RESP data info +#if __USE_GOODIX_RESP_ALGORITHM__ +const STGh3x2xFrameInfo g_stRESP_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_RESP, + .pstFunctionInfo = &g_st_RESP_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_RESP_CHNL_NUM, + .pchChnlMap = g_pch_RESP_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_RESP_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_RESP_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_RESP_FrameLastGain, + .punFrameCnt = &g_un_RESP_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_RESP, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xRESP_FrameInfo = &g_stRESP_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xRESP_FrameInfo = 0; +#endif +//AF data info +#if __USE_GOODIX_AF_ALGORITHM__ +const STGh3x2xFrameInfo g_stAF_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_AF, + .pstFunctionInfo = &g_st_AF_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_AF_CHNL_NUM, + .pchChnlMap = g_pch_AF_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_AF_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_AF_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_AF_FrameLastGain, + .punFrameCnt = &g_un_AF_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_AF, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xAF_FrameInfo = &g_stAF_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xAF_FrameInfo = 0; +#endif +#if __USE_GOODIX_BP_ALGORITHM__ +const STGh3x2xFrameInfo g_stFPBP_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_FPBP, + .pstFunctionInfo = &g_st_BP_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_BP_CHNL_NUM, + .pchChnlMap = g_pch_BP_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_BP_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_BP_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_BP_FrameLastGain, + .punFrameCnt = &g_un_BP_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_BP, +#endif +}; +const STGh3x2xFrameInfo g_stPWA_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_PWA, + .pstFunctionInfo = &g_st_BP_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_PWA_CHNL_NUM, + .pchChnlMap = g_pch_BP_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_BP_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_BP_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_BP_FrameLastGain, + .punFrameCnt = &g_un_BP_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_BP, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xFPBP_FrameInfo = &g_stFPBP_FrameInfo; +//const STGh3x2xFrameInfo * const g_pstGh3x2xPWA_FrameInfo = &g_stPWA_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xFPBP_FrameInfo = 0; +//const STGh3x2xFrameInfo * const g_pstGh3x2xPWA_FrameInfo = 0; +#endif +#if 0 +const STGh3x2xFrameInfo g_stTEST1_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_TEST1, + .pstFunctionInfo = &g_st_TEST1_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_TEST_CHNL_NUM, + .pchChnlMap = g_pch_TEST1_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_TEST1_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_TEST1_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_TEST1_FrameLastGain, + .punFrameCnt = &g_un_TEST1_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_TEST1, +#endif +}; +const STGh3x2xFrameInfo g_stTEST2_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_TEST2, + .pstFunctionInfo = &g_st_TEST2_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_TEST_CHNL_NUM, + .pchChnlMap = g_pch_TEST2_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_TEST2_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_TEST2_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_TEST2_FrameLastGain, + .punFrameCnt = &g_un_TEST2_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_TEST2, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST1_FrameInfo = &g_stTEST1_FrameInfo; +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST2_FrameInfo = &g_stTEST2_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST1_FrameInfo = 0; +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST2_FrameInfo = 0; +#endif +//ADT data info +#if __USE_GOODIX_ADT_ALGORITHM__ +const STGh3x2xFrameInfo g_stADT_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_ADT, + .pstFunctionInfo = &g_st_ADT_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_ADT_CHNL_NUM, + .pchChnlMap = g_pch_ADT_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .punIncompleteRawdata = g_pun_ADT_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_ADT_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_ADT_FrameLastGain, + .punFrameCnt = &g_un_ADT_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_ADT, + .pstAlgoRecordResult = 0, +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xADT_FrameInfo = &g_stADT_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xADT_FrameInfo = 0; +#endif +//SOFT ADT data info +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ +const STGh3x2xFrameInfo g_stSOFT_ADT_GREEN_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_SOFT_ADT_GREEN, + .pstFunctionInfo = &g_st_SOFT_ADT_GREEN_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_SOFT_ADT_CHNL_NUM, + .pchChnlMap = g_pch_SOFT_ADT_GREEN_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .punIncompleteRawdata = g_pun_SOFT_ADT_GREEN_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_SOFT_ADT_GREEN_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_SOFT_ADT_GREEN_FrameLastGain, + .punFrameCnt = &g_un_SOFT_ADT_GREEN_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_SOFT_ADT_GREEN, + .pstAlgoRecordResult = 0, +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_GREEN_FrameInfo = &g_stSOFT_ADT_GREEN_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_GREEN_FrameInfo = 0; +#endif +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ +const STGh3x2xFrameInfo g_stSOFT_ADT_IR_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_SOFT_ADT_IR, + .pstFunctionInfo = &g_st_SOFT_ADT_IR_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_SOFT_ADT_CHNL_NUM, + .pchChnlMap = g_pch_SOFT_ADT_IR_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .punIncompleteRawdata = g_pun_SOFT_ADT_GREEN_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_SOFT_ADT_GREEN_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_SOFT_ADT_GREEN_FrameLastGain, + .punFrameCnt = &g_un_SOFT_ADT_GREEN_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_SOFT_ADT_GREEN, + .pstAlgoRecordResult = 0, +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_IR_FrameInfo = &g_stSOFT_ADT_IR_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_IR_FrameInfo = 0; +#endif + + +//Function data info struct +const STGh3x2xFrameInfo * const g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_MAX] = +{ +//adt +#if __USE_GOODIX_ADT_ALGORITHM__ + &g_stADT_FrameInfo, +#else + 0, +#endif +//hr +#if __USE_GOODIX_HR_ALGORITHM__ + &g_stHR_FrameInfo, +#else + 0, +#endif +//hrv +#if __USE_GOODIX_HRV_ALGORITHM__ + &g_stHRV_FrameInfo, +#else + 0, +#endif +//hsm +#if __USE_GOODIX_HSM_ALGORITHM__ + &g_stHSM_FrameInfo, +#else + 0, +#endif +//fpbp +//pwa +#if __USE_GOODIX_BP_ALGORITHM__ + &g_stFPBP_FrameInfo, + &g_stPWA_FrameInfo, +#else + 0, + 0, +#endif +//spo2 +#if __USE_GOODIX_SPO2_ALGORITHM__ + &g_stSPO2_FrameInfo, +#else + 0, +#endif +//ecg +#if __USE_GOODIX_ECG_ALGORITHM__ + &g_stECG_FrameInfo, +#else + 0, +#endif +//pwtt +#if 0 + &g_stPWTT_FrameInfo, +#else + 0, +#endif +//soft adt green +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ + &g_stSOFT_ADT_GREEN_FrameInfo, +#else + 0, +#endif +//bt +#if __USE_GOODIX_BT_ALGORITHM__ + &g_stBT_FrameInfo, +#else + 0, +#endif +//resp +#if __USE_GOODIX_RESP_ALGORITHM__ + &g_stRESP_FrameInfo, +#else + 0, +#endif +//af +#if __USE_GOODIX_AF_ALGORITHM__ + &g_stAF_FrameInfo, +#else + 0, +#endif +#if 0 + &g_stTEST1_FrameInfo, + &g_stTEST2_FrameInfo, +#else + 0, + 0, +#endif +//soft adt ir +#if __USE_GOODIX_SOFT_ADT_ALGORITHM__ + &g_stSOFT_ADT_IR_FrameInfo, +#else + 0, +#endif + 0, //GH3X2X_FUNCTION_RS0 + 0, //GH3X2X_FUNCTION_RS1 + 0, //GH3X2X_FUNCTION_RS2 + 0, //GH3X2X_FUNCTION_LEAD_DET +}; + + + +#endif + + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_hook.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_hook.c new file mode 100644 index 000000000..6deef95d9 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_hook.c @@ -0,0 +1,263 @@ +#include +#include "gh3x2x_demo_common.h" +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algo_config.h" +#include "gh3x2x_demo_algo_hook.h" + +#if (__GOODIX_ALGO_CALL_MODE__) + +/** + * @fn void GH3X2X_AlgoLog(char *log_string) + * + * @brief for debug version, log + * + * @attention this function must define that use debug version lib + * + * @param[in] log_string pointer to log string + * @param[out] None + * + * @return None + */ + +void GH3X2X_AlgoLog(GCHAR *log_string) +{ + GOODIX_PLATFORM_LOG_ENTITY(); +} + +/** + * @fn void GH3X2X_AdtAlgorithmResultReport(STHbAlgoResult stHbAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate hb algorithm. + * + * @attention None + * + * @param[in] stHbAlgoRes hb algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_AdtAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ +#if (__USE_GOODIX_ADT_ALGORITHM__) + if (pstAlgoResult->uchUpdateFlag) + { + if (pstAlgoResult->snResult[0] == 1) //wear on + { + #if __GH_MSG_WTIH_DRV_LAYER_EN__ + GH_SEND_MSG_WEAR_EVENT(GH3X2X_SOFT_EVENT_WEAR_ON_ALGO_ADT); + #else + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF_ALGO_ADT); + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON_ALGO_ADT); + #endif + /* code implement by user */ + } + else if (pstAlgoResult->snResult[0] == 2) //wear off + { + #if __GH_MSG_WTIH_DRV_LAYER_EN__ + GH_SEND_MSG_WEAR_EVENT(GH3X2X_SOFT_EVENT_WEAR_OFF_ALGO_ADT); + #else + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON_ALGO_ADT); + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF_ALGO_ADT); + #endif + /* code implement by user */ + } + } +#endif +} + +/** + * @fn void GH3X2X_HrAlgorithmResultReport(STHbAlgoResult stHbAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate hb algorithm. + * + * @attention None + * + * @param[in] stHbAlgoRes hb algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_HrAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ +#if (__USE_GOODIX_HR_ALGORITHM__) + /* code implement by user */ + //GOODIX_PLATFORM_HR_RESULT_REPORT_ENTITY(); +#endif +} + +/** + * @fn void GH3X2X_Spo2AlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult) + * + * + * @brief This function will be called after calculate spo2 algorithm. + * + * @attention None + * + * @param[in] stSpo2AlgoRes spo2 algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_Spo2AlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ +#if (__USE_GOODIX_SPO2_ALGORITHM__) + + /* code implement by user */ + //GOODIX_PLATFORM_SPO2_RESULT_REPORT_ENTITY(); +#endif +} + +/** + * @fn void GH3X2X_HrvAlgorithmResultReport(STHrvAlgoResult stHrvAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate hrv algorithm. + * + * @attention None + * + * @param[in] stHrvAlgoRes hrv algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_HrvAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ +#if (__USE_GOODIX_HRV_ALGORITHM__) + /* code implement by user */ + //SLAVER_LOG("snHrvOut0=%d,snHrvOut1=%d,snHrvOut2=%d,snHrvOut3=%d,snHrvNum=%d,snHrvConfi=%d\r\n", + // stHrvAlgoRes[0].snHrvOut0,stHrvAlgoRes[0].snHrvOut1,stHrvAlgoRes[0].snHrvOut2,stHrvAlgoRes[0].snHrvOut3,stHrvAlgoRes[0].snHrvNum,stHrvAlgoRes[0].snHrvNum); + //GOODIX_PLATFORM_HRV_RESULT_REPORT_ENTITY(); +#endif +} + +/** + * @fn void GH3X2X_EcgAlgorithmResultReport(STEcgAlgoResult stEcgAlgoRes[], GU16 pusAlgoResIndexArr[], usAlgoResCnt) + * + * @brief This function will be called after calculate ecg algorithm. + * + * @attention None + * + * @param[in] stEcgAlgoRes ecg algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_EcgAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ +#if (__USE_GOODIX_ECG_ALGORITHM__) + /* code implement by user */ + //GOODIX_PLATFORM_ECG_RESULT_REPORT_ENTITY(); +#endif +} + +/** + * @fn void GH3X2X_SoftAdtGreenAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) + * + * @brief This function will be called after calculate ecg algorithm. + * + * @attention None + * + * @param[in] stEcgAlgoRes ecg algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ + +GU8 g_SoftAdtWearState = GH3X2X_SOFT_ALGO_ADT_DEFAULT; // 0:default 1: wear on 1: wear off +void GH3X2X_SoftAdtGreenAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ +#if (__USE_GOODIX_SOFT_ADT_ALGORITHM__) + GH3X2X_DEBUG_ALGO_LOG("[%s]:result = %d,%d\r\n", __FUNCTION__, pstAlgoResult->snResult[0], pstAlgoResult->snResult[1]); + //live object + if (pstAlgoResult->snResult[0] == 0x1 && g_SoftAdtWearState != GH3X2X_SOFT_ALGO_ADT_WEAR_ON) + { + GH3X2X_DEBUG_ALGO_LOG("[%s]:get algo wear on event\r\n", __FUNCTION__); + #if __GH_MSG_WTIH_DRV_LAYER_EN__ + GH_SEND_MSG_WEAR_EVENT(GH3X2X_SOFT_EVENT_WEAR_ON); + #else + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF); + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON); + #endif + g_SoftAdtWearState = GH3X2X_SOFT_ALGO_ADT_WEAR_ON; + /* code implement by user */ + } + //non live object + else if ((pstAlgoResult->snResult[0] & 0x2) && g_SoftAdtWearState != GH3X2X_SOFT_ALGO_ADT_WEAR_OFF) + { + GH3X2X_DEBUG_ALGO_LOG("[%s]:get algo wear off event\r\n", __FUNCTION__); + #if __GH_MSG_WTIH_DRV_LAYER_EN__ + GH_SEND_MSG_WEAR_EVENT(GH3X2X_SOFT_EVENT_WEAR_OFF); + #else + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON); + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF); + #endif + g_SoftAdtWearState = GH3X2X_SOFT_ALGO_ADT_WEAR_OFF; + /* code implement by user */ + } + GOODIX_PLATFORM_NADT_RESULT_HANDLE_ENTITY(); +#endif +} + +/** + * @fn void GH3X2X_SoftAdtIrAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) + * + * @brief This function will be called after calculate ecg algorithm. + * + * @attention None + * + * @param[in] stEcgAlgoRes ecg algorithm result array + * @param[in] pusAlgoResIndexArr frame index of every algo result + * @param[in] usAlgoResCnt number of algo result + * @param[out] None + * + * @return None + */ +void GH3X2X_SoftAdtIrAlgorithmResultReport(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ +#if (__USE_GOODIX_SOFT_ADT_ALGORITHM__) + GH3X2X_DEBUG_ALGO_LOG("[%s]:result = %d,%d\r\n", __FUNCTION__, pstAlgoResult->snResult[0], pstAlgoResult->snResult[1]); + //live object + if (pstAlgoResult->snResult[0] == 0x1 && g_SoftAdtWearState != GH3X2X_SOFT_ALGO_ADT_WEAR_ON) + { + GH3X2X_DEBUG_ALGO_LOG("[%s]:get algo wear on event\r\n", __FUNCTION__); + //Gh3x2xDemoStopSampling(GH3X2X_FUNCTION_SOFT_ADT_IR); + //Gh3x2xDemoStartSampling(GH3X2X_FUNCTION_SOFT_ADT_GREEN|GH3X2X_FUNCTION_HR); + #if __GH_MSG_WTIH_DRV_LAYER_EN__ + GH_SEND_MSG_WEAR_EVENT(GH3X2X_SOFT_EVENT_WEAR_ON); + #else + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF); + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON); + #endif + g_SoftAdtWearState = GH3X2X_SOFT_ALGO_ADT_WEAR_ON; + /* code implement by user */ + } + //non live object + else if ((pstAlgoResult->snResult[0] & 0x2) && g_SoftAdtWearState != GH3X2X_SOFT_ALGO_ADT_WEAR_OFF) + { + GH3X2X_DEBUG_ALGO_LOG("[%s]:get algo wear off event\r\n", __FUNCTION__); + #if __GH_MSG_WTIH_DRV_LAYER_EN__ + GH_SEND_MSG_WEAR_EVENT(GH3X2X_SOFT_EVENT_WEAR_OFF); + #else + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON); + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF); + #endif + g_SoftAdtWearState = GH3X2X_SOFT_ALGO_ADT_WEAR_OFF; + /* code implement by user */ + } + GOODIX_PLATFORM_NADT_RESULT_HANDLE_ENTITY(); +#endif +} + +#endif // end else #if (__DRIVER_LIB_MODE__==__DRV_LIB_WITHOUT_ALGO__) + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_memory.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_memory.c new file mode 100644 index 000000000..5524f3248 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_memory.c @@ -0,0 +1,334 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_algorithm.c + * + * @brief gh3x2x driver lib demo code for algorithm + * + * @author Gooidx Iot Team + * + */ +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algo_memory.h" +#include "gh3x2x_demo_algo_config.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "goodix_algo.h" +#include "goodix_mem.h" + +#if (__GOODIX_ALGO_CALL_MODE__) +#if __USER_DYNAMIC_ALGO_MEM_EN__ +GU32 *g_punGh3x2xAlgoMemBufferPointer = GH3X2X_ALGORITHMS_MEMORY_SIZE_USERSET; +#else +GU32 g_punGh3x2xAlgoMemBuffer[GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL/4] = {0}; +GU32 *g_punGh3x2xAlgoMemBufferPointer = g_punGh3x2xAlgoMemBuffer; +#endif +#else //without algorithm +GU32 *g_punGh3x2xAlgoMemBufferPointer = 0; +#endif + +void GH3X2X_MemFree(void* mem_addr) +{ + goodix_mem_free(mem_addr); +} + +void* GH3X2X_MemMalloc(GS32 nSize) +{ + return goodix_mem_malloc(nSize); +} + +void Gh3x2xPoolIsNotEnough(void) +{ + while(1) + { + GH3X2X_DEBUG_ALGO_LOG("MEMORY ERROR!!!PLEASE RESET HARDWARE!!!\n"); + } +} + +#if (__GOODIX_ALGO_CALL_MODE__) + +#if __GH3X2X_MEM_POOL_CHECK_EN__ + +const GU32 g_unGh3z2xMemCheckAreaStart[17] = +{ + 0, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*1/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*2/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*3/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*4/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*5/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*6/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*7/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*8/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*9/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*10/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*11/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*12/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*13/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*14/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*15/16, + GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL, +}; + +GU32 g_unGh3x2xLastMemPoolCheckSumArea[16]; + + + +GU8 g_uchGh3x2xMemPollHaveGetCheckSum = 0; +GU16 g_usGh3x2xMemPollErrorFlag = 0; +GU32 Gh3x2xGetMemPoolCheckSum(GU8 *lunMemPool, GU32 lunByteSize) +{ + GU32 lunCheckSum = 0; + for(GU32 lunByteCnt = 0; lunByteCnt < lunByteSize; lunByteCnt += 4) + { + lunCheckSum += *((GU32*)(lunMemPool+lunByteCnt)); + } + + return lunCheckSum; +} + + +void Gh3x2xMemPoolCheckSumWrite(GU8 *lunMemPool) +{ + for(GU8 uchAreaCnt = 0; uchAreaCnt < 16; uchAreaCnt ++) + { + g_unGh3x2xLastMemPoolCheckSumArea[uchAreaCnt] = Gh3x2xGetMemPoolCheckSum(lunMemPool + ((g_unGh3z2xMemCheckAreaStart[uchAreaCnt]/4)*4), (g_unGh3z2xMemCheckAreaStart[uchAreaCnt + 1]/4)*4 - (g_unGh3z2xMemCheckAreaStart[uchAreaCnt]/4)*4); + } + g_uchGh3x2xMemPollHaveGetCheckSum = 1; +} + + +GU16 Gh3x2xMemPoolCheckSumCheck(GU8 *lunMemPool) +{ + GU16 usErrorFlag = 0; + + if(0 == g_usGh3x2xMemPollErrorFlag) + { + for(GU8 uchAreaCnt = 0; uchAreaCnt < 16; uchAreaCnt ++) + { + if(g_unGh3x2xLastMemPoolCheckSumArea[uchAreaCnt] != Gh3x2xGetMemPoolCheckSum(lunMemPool + ((g_unGh3z2xMemCheckAreaStart[uchAreaCnt]/4)*4), (g_unGh3z2xMemCheckAreaStart[uchAreaCnt + 1]/4)*4 - (g_unGh3z2xMemCheckAreaStart[uchAreaCnt]/4)*4)) + { + usErrorFlag |= (((GU16)1) << uchAreaCnt); + } + } + } + + g_usGh3x2xMemPollErrorFlag = usErrorFlag; + return usErrorFlag; +} + + +void Gh3x2xCheckMemPollBeforeAlgoCal(void) +{ + if(g_uchGh3x2xMemPollHaveGetCheckSum) + { + if(Gh3x2xMemPoolCheckSumCheck((GU8*)g_punGh3x2xAlgoMemBufferPointer)) + { + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check error!!! error flag = 0x%X\r\n", g_usGh3x2xMemPollErrorFlag); + while(1); //error !!! mem pool is be destroy + } + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 0 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[0]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 1 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[1]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 2 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[2]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 3 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[3]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 4 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[4]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 5 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[5]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 6 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[6]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 7 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[7]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 8 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[8]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 9 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[9]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 10 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[10]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 11 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[11]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 12 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[12]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 13 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[13]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 14 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[14]); + GH3X2X_DEBUG_ALGO_LOG("Gh3x2x mem check ok, check sum 15 = 0x%X\r\n",g_unGh3x2xLastMemPoolCheckSumArea[15]); + } + +} + +void Gh3x2xUpdataMemPollChkSumAfterAlgoCal(void) +{ + + Gh3x2xMemPoolCheckSumWrite((GU8*)g_punGh3x2xAlgoMemBufferPointer); + + + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*1/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*2/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*3/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*4/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*5/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*6/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*7/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*8/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*9/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*10/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*11/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*12/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*13/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*14/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*15/16)/4 - 1] = 0x3333; //test + //g_punGh3x2xAlgoMemBuffer[(GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL*16/16)/4 - 1] = 0x3333; //test + +} +#endif + + + +#if __USER_DYNAMIC_ALGO_MEM_EN__ +void* Gh3x2xAlgoMemApply(GU32 unMemSize) +{ + return Gh3x2xMallocUser(unMemSize) +} + +void Gh3x2xAlgoMemFree(void* MemAddr) +{ + Gh3x2xFreeUser(MemAddr); +} +#else +void* Gh3x2xAlgoMemApply(GU32 unMemSize) +{ + return &g_punGh3x2xAlgoMemBuffer[0]; +} + +void Gh3x2xAlgoMemFree(void* MemAddr) +{ + +} +#endif + +/// algorithm memory is inited or not +GU8 g_uchAlgoMemStatus = ALGO_MEM_NO_INIT; + +/// buffer for algorithm, this addr is import from outer +//void* g_unAlgorithmMemBuffer = 0; + +/// buffer size(byte) for algorithm, this size is import from outer +GU32 g_unAlgorithmMemBufferSize = 0; + +/** + * @fn GS8 GH3X2X_AlgoMemConfig( GU32 unMemSize) + * + * @brief Config algorithm memory. + * + * @attention Mem can only be static,such as global array + * + * @param[in] unMemSize memory size(unit:byte) + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_RESOURCE_ERROR return algorithm mem config error + */ +GS8 GH3X2X_AlgoMemConfig( GU32 unMemSize) +{ + GS8 chRet = GH3X2X_RET_OK; + if (unMemSize > 0) + { + GH3X2X_AlgoDeinit(0xFFFFFFFF); + g_unAlgorithmMemBufferSize = unMemSize; + chRet = GH3X2X_RET_OK; + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem Config complete!Size:%d\r\n", (int)unMemSize); + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem init start...\r\n"); + chRet = GH3X2X_AlgoMemInit(); + } + else + { + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem config fail!\r\n"); + chRet = GH3X2X_RET_RESOURCE_ERROR; + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_AlgoMemInit(void) + * + * @brief algorithm memory init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_RESOURCE_ERROR return algorithm mem init error + */ +GS8 GH3X2X_AlgoMemInit(void) +{ + GS8 chRet = GH3X2X_RET_OK; + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem init start...\r\n"); + if (ALGO_MEM_NO_INIT == g_uchAlgoMemStatus) + { + g_punGh3x2xAlgoMemBufferPointer = (GU32*)Gh3x2xAlgoMemApply(g_unAlgorithmMemBufferSize); + if ((g_punGh3x2xAlgoMemBufferPointer != 0) && (g_unAlgorithmMemBufferSize > 0)) + { + if(MEMPOOL_IS_OK_E != goodix_mem_init((void*)g_punGh3x2xAlgoMemBufferPointer, g_unAlgorithmMemBufferSize)) + { + chRet = GH3X2X_RET_RESOURCE_ERROR; + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem init error!\r\n"); + + } + else + { + g_uchAlgoMemStatus = ALGO_MEM_INIT_OK; + chRet = GH3X2X_RET_OK; + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem init success.Addr:0x%x,Size:%d\r\n", (unsigned int)g_punGh3x2xAlgoMemBufferPointer, \ + (int)g_unAlgorithmMemBufferSize); + } + } + else + { + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem para error!\r\n"); + chRet = GH3X2X_RET_RESOURCE_ERROR; + } + } + return chRet; +} + +/** +* @fn void GH3X2X_AlgoMemDeinit(void) +* +* @brief algorithm memory deinit +* +* @attention None +* +* @param[in] None +* @param[out] None +* +* @return None +*/ +void GH3X2X_AlgoMemDeinit(void) +{ + if (ALGO_MEM_INIT_OK == g_uchAlgoMemStatus) + { + goodix_mem_deinit(); //destroy all memory + if(g_punGh3x2xAlgoMemBufferPointer) + { + Gh3x2xAlgoMemFree((void*)g_punGh3x2xAlgoMemBufferPointer); + g_punGh3x2xAlgoMemBufferPointer = 0; + } + g_uchAlgoMemStatus = ALGO_MEM_NO_INIT; + GH3X2X_DEBUG_ALGO_LOG("Algorithm mem deinit!\r\n"); + } +} + +GU8 GH3X2X_GetAlgoMemStatus(void) +{ + return g_uchAlgoMemStatus; +} + +GU8 Gh3x2xGetHrAlgoSupportChnl(void) +{ + return __HR_ALGORITHM_SUPPORT_CHNL_NUM__; +} + +GU8 Gh3x2xGetSpo2AlgoSupportChnl(void) +{ + return __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__; +} + + + +#endif + + + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_reg_array.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_reg_array.c new file mode 100644 index 000000000..7a9eb14fb --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_algo_reg_array.c @@ -0,0 +1,101 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_reg_array.c + * + * @brief gh3x2x driver lib reg config array + * + * @author Gooidx Iot Team + * + */ + +#include "gh3x2x_demo_algo_config.h" +#include "gh_drv.h" + +/// HR +const STGh3x2xReg gh3x2x_algo_reg_list0[] = +{ + {0x33C0, 0x0000}, {0x33C2, 0x0000}, {0x33C4, 0x0000}, {0x33C6, 0x0000}, {0x33C8, 0x0000}, {0x33CA, 0x0000}, + {0x33CC, 0x0000}, {0x33CE, 0x0000}, {0x33D0, 0x0000}, {0x33D2, 0x0000}, {0x35C0, 0x0004}, {0x35C4, 0x0100}, + {0x35C6, 0x0302}, {0x42C0, 0x846C}, {0x42C2, 0xFFFD}, {0x42C4, 0x87E3}, {0x42C6, 0xFFFF}, {0x42C8, 0xCC38}, + {0x42CA, 0x000F}, {0x42CC, 0x0001}, {0x42CE, 0x0000}, {0x42D0, 0x0000}, {0x42D2, 0x0000}, {0x42D4, 0x001E}, + {0x42D6, 0x0000}, {0x42D8, 0x000F}, {0x42DA, 0x0000}, {0x42DC, 0x0004}, {0x42DE, 0x0000}, {0x42E0, 0x0003}, + {0x42E2, 0x0000}, {0x42E4, 0x0000}, {0x42E6, 0x0000}, {0x42E8, 0x0000}, {0x42EA, 0x0000}, {0x44C0, 0x0001}, + {0x44CC, 0xFF01}, {0x44D4, 0xFF00}, {0xFFFF, 0x0001} +}; + +#if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 1) +const STGh3x2xReg gh3x2x_algo_reg_list1[] = +{ + {0,0}, +}; +#endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 1) */ + +#if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 2) +const STGh3x2xReg gh3x2x_algo_reg_list2[] = +{ + {0,0}, +}; +#endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 2) */ + +#if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 3) +const STGh3x2xReg gh3x2x_algo_reg_list3[] = +{ + {0,0}, +}; +#endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 3) */ + +#if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 4) +const STGh3x2xReg gh3x2x_algo_reg_list4[] = +{ + {0,0}, +}; +#endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 4) */ + +#if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 5) +const STGh3x2xReg gh3x2x_algo_reg_list5[] = +{ + {0,0}, +}; +#endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 5) */ + +#if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 6) +const STGh3x2xReg gh3x2x_algo_reg_list6[] = +{ + {0,0}, +}; +#endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 6) */ + +#if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 7) +const STGh3x2xReg gh3x2x_algo_reg_list7[] = +{ + {0,0}, +}; +#endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 7) */ + +const STGh3x2xInitConfig g_stGoodixAlgoCfgListArr[__GOODIX_ALGO_CFG_LIST_MAX_NUM__] = +{ + {gh3x2x_algo_reg_list0,sizeof(gh3x2x_algo_reg_list0) / sizeof(gh3x2x_algo_reg_list0[0])}, + #if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 1) + {gh3x2x_algo_reg_list1,sizeof(gh3x2x_algo_reg_list1) / sizeof(gh3x2x_algo_reg_list1[0])}, + #endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 1) */ + #if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 2) + {gh3x2x_algo_reg_list2,sizeof(gh3x2x_algo_reg_list2) / sizeof(gh3x2x_algo_reg_list2[0])}, + #endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 2) */ + #if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 3) + {gh3x2x_algo_reg_list3,sizeof(gh3x2x_algo_reg_list3) / sizeof(gh3x2x_algo_reg_list3[0])}, + #endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 3) */ + #if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 4) + {gh3x2x_algo_reg_list4,sizeof(gh3x2x_algo_reg_list4) / sizeof(gh3x2x_algo_reg_list4[0])}, + #endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 4) */ + #if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 5) + {gh3x2x_algo_reg_list5,sizeof(gh3x2x_algo_reg_list5) / sizeof(gh3x2x_algo_reg_list5[0])}, + #endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 5) */ + #if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 6) + {gh3x2x_algo_reg_list6,sizeof(gh3x2x_algo_reg_list6) / sizeof(gh3x2x_algo_reg_list6[0])}, + #endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 6) */ + #if (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 7) + {gh3x2x_algo_reg_list7,sizeof(gh3x2x_algo_reg_list7) / sizeof(gh3x2x_algo_reg_list7[0])}, + #endif /* (__GOODIX_ALGO_CFG_LIST_MAX_NUM__ > 7) */ +}; + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_strategy.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_strategy.c new file mode 100644 index 000000000..c546b3ec6 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_application/src/gh3x2x_demo_strategy.c @@ -0,0 +1,79 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_strategy.c + * + * @brief + * + * @author + * + */ + +/* includes */ +#include "goodix_algo.h" +#include "gh3x2x_demo_algo_config.h" +#include "gh3x2x_demo_algo_call.h" + + +GU8 g_uchPreHrValue = 0; + + +void Gh3x2xOutputValueStrategyInit(GU32 unFunctionID) +{ +#if __GH3X2X_HR_OUTPUT_VALUE_STRATEGY_EN__ + if(GH3X2X_FUNCTION_HR & unFunctionID == GH3X2X_FUNCTION_HR) + { + g_uchPreHrValue = 0; + } +#endif +} + + +#define GH3X2X_DIFF_ABS(x,y) (x > y ? (x - y):(y - x)) +#if __GH3X2X_HR_OUTPUT_VALUE_STRATEGY_EN__ +void Gh3x2xHrOutputValueStrategyPro(STGh3x2xAlgoResult * pstAlgoResult, GU32 lubFrameId) +{ + GU8 uchCurrentOriginalHrValue = (GU8)(pstAlgoResult->snResult[0]); + GU8 uchConf = (GU8)(pstAlgoResult->snResult[1]); + GU8 uchNewHrValue = uchCurrentOriginalHrValue; + + if(0 == g_uchPreHrValue) + { + g_uchPreHrValue = uchCurrentOriginalHrValue; + } + else + { + if((GH3X2X_DIFF_ABS(g_uchPreHrValue,uchCurrentOriginalHrValue) > 50) &&(uchConf <= 50)) //there is big difference between pre hr and current orignal hr AND confidence is low + { + //smooth vaule + uchNewHrValue = (((GU16)g_uchPreHrValue) *2 + (GU16)uchCurrentOriginalHrValue)/3; + } + g_uchPreHrValue = uchNewHrValue; + + //write back to result + pstAlgoResult->snResult[0] = uchNewHrValue; + } +} +#endif + + + + + + + + + + + + + + + + + + + + + + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_af.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_af.h new file mode 100644 index 000000000..eec8f9897 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_af.h @@ -0,0 +1,20 @@ +#ifndef __GOODIX_AF_H +#define __GOODIX_AF_H + + +#include "goodix_type.h" +#include "goodix_algo.h" +#ifdef __cplusplus +extern "C" { +#endif + +extern const GU8 *AFVersion(void); +extern GS32 AFInit(GS32 g_s32WaitTime); +extern GS32 AF_Detection_Module(GS32 *s32RRIRawdataArray,GU32* nResult); +extern GS32 AFDeInit(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_algo.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_algo.h new file mode 100644 index 000000000..299d40cac --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_algo.h @@ -0,0 +1,106 @@ +#ifndef GOODIX_ALGO_H +#define GOODIX_ALGO_H + +#include "stdint.h" +#include "string.h" +#include "stdio.h" +#include "gh_drv.h" +// + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +// typedef unsigned char GU8; /**< 8bit unsigned integer type */ +// typedef signed char GS8; /**< 8bit signed integer type */ +// typedef unsigned short GU16; /**< 16bit unsigned integer type */ +// typedef signed short GS16; /**< 16bit signed integer type */ +// typedef int GS32; /**< 32bit signed integer type */ +// typedef unsigned int GU32; /**< 32bit unsigned integer type */ +// typedef float GF32; /**< float type */ +// typedef double GD64; /**< double type */ +// typedef char GCHAR; /**< char type */ +// typedef unsigned char GBOOL; +// typedef long long GS64; /**< 64bit signed integer type */ + +#define GH3X2X_PTR_NULL ((void *) 0) +#define GH3X2X_CHANNEL_MAP_MAX_CH (32) + +/* extern log function */ +extern void GH3X2X_PlatformLog(GCHAR *chLogString); + +/// log support len +#define GH3X2X_LOG_ALGO_SUP_LEN (128) +#if 0 +//#define GH3X2X_DEBUG_ALGO_LOG(...) do {\ + if(g_pSnprintfUserIn)\ + {\ + GCHAR _7iwtO6qX0[GH3X2X_LOG_ALGO_SUP_LEN] = {0};\ + g_pSnprintfUserIn(_7iwtO6qX0, GH3X2X_LOG_ALGO_SUP_LEN, \ + "[gh3x2x_drv]: "__VA_ARGS__);\ + GH3X2X_PlatformLog(_7iwtO6qX0);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn("[gh3x2x_drv]: "__VA_ARGS__);\ + } while (0) +#endif +/* ******************************************************************************************* */ +//public part +typedef struct +{ + void *pnParametersBuffer; //STGoodixAlgorithmXXXControlConfigParametersBuffer + GS32 nBaseBufferLen; + GS32 *pnBaseBuffer; +}STGoodixAlgorithmControlConfig; + +typedef struct +{ + GU8 uchFrameId; //frame id 0x00~0xFF + /* suggest default struct : 0-7:green, 8-15:ir, 16-23:red, 24-31:other(bg) */ + GU8 uchRawdataLen; //rawdata number(<=32) + GS32 *pnRawdata; //rawdata buffer basic address + GU8 *puchCurAdjFlag; //tx current adj flag buffer basic address + GU16 *pusCurAdjValue; //tx current adj value buffer basic address, dr0:0-8bit dr1:9-16bit + GU8 *puchGainAdjValue; //rx gain adj value buffer basic address + GU8 *puchChnlColorInfo; //color info & enable flag buffer basic address 0:Not enable,1:Green,2:Ir,3:Red,4:Ecg,5:Bg + /* *********************************************************************** */ + void *psAccdata; //STGoodixAlgorithmXXXCalculateInputAccdata + void *pnRefBuffer; //STGoodixAlgorithmXXXInputRefBuffer +}STGoodixAlgorithmCalculateInput; + +/* Goodix Algorithm Output Struct */ +typedef struct +{ + void *pnResult; //STGoodixAlgorithmXXXCalculateOutputResult + GS32 nMiddleBaseBufferLen; + GS32 *pnMiddleBaseBuffer; +}STGoodixAlgorithmCalculateOutput; + +/* Goodix Algorithm Deinit Struct */ +typedef struct +{ + void *pnFinalResult; //STGoodixAlgorithmXXXFinalOutputResult + GS32 nBaseBufferLen; + GS32* pnBaseBuffer; +}STGoodixAlgorithmFinalOutput; + +/** + * @brief Goodix Algorithm Whole struct + */ +typedef struct +{ + /* Application section malloc part */ + STGoodixAlgorithmControlConfig stAlgorithmConfig; + STGoodixAlgorithmCalculateInput stAlgorithmCalcInput; + + /* Algorithm section malloc part */ + STGoodixAlgorithmCalculateOutput stAlgorithmCalcOutput; + STGoodixAlgorithmFinalOutput stAlgorithmFinalOutput; +}STGoodixAlgorithmInfo; + +typedef GS32 (*pfnAlgoCallFunc)(STGoodixAlgorithmInfo* pstGoodixAlgorithmInfo); +typedef GU8* (*pfnAlgoCallGetVersion)(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_algo_bt.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_algo_bt.h new file mode 100644 index 000000000..1f660231c --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_algo_bt.h @@ -0,0 +1,312 @@ +#ifndef GOODIX_ALGO_BT_H +#define GOODIX_ALGO_BT_H +#include +#include "goodix_algo.h" +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#if _WIN32 || _WIN64 +#define DLL_API_BODY_TEMPERATURE extern _declspec(dllexport) +#else +#define DLL_API_BODY_TEMPERATURE +#endif + + /* **************************************const value define*********************************************** */ + /** + * @brief configuration virtual registers define + */ +#define BT_VIRTUAL_REG_UINIT (sizeof(GU16))//length of virtual register +#define BT_CFG_HEADER_LENGTH (0x06) //length of header registers +#define BT_CFG_HWINFO_LENGTH (0x2D) //length of hardware information registers +#define BT_CFG_THRES_LENGTH (0x14) //length of threshold registers +#define BT_CFG_ALGO_LENGTH (0x64) //length of algorithm configuration registers +#define BT_CFG_TOTAL_LENGTH (0xAB) //length of configuration + + /** + * @brief algorithm errorcode define + */ + // common errorcode +#define BT_ERRORCODE_OK (0x00) //Errorcode: ok +#define BT_ERRORCODE_UNINIT (0x01) //Errorcode: the initialization function was not called +//function errorcode +#define BT_ERRORCODE_NULL_PTR (0x03) //Errorcode: called empty pointer +#define BT_ERRORCODE_MALLOC_FAIL (0x04) //Errorcode: out of memory +#define BT_ERRORCODE_INVALID_PARAM (0x05) //Errorcode: illegal parameter +#define BT_ERRORCODE_FAIL (0x06) //Errorcode: calculation failed +//module base value +#define BT_ERRORCODE_BASE_VALUE_INIT (0x10) //Errorcode: preprocessing module +#define BT_ERRORCODE_BASE_VALUE_PRE (0x20) //Errorcode: preprocessing module +#define BT_ERRORCODE_BASE_VALUE_ALGO (0x30) //Errorcode: algorithm module + +#define BT_MAX_CH_NUM (0x02) //Channel number + +/* ******************************************enum define************************************************** */ + +/** + * @brief BT device type enum +*/ + typedef enum + { + CB62K928D = 0, + CB62K552D, + DT104D3950, + }EM_BT_NTC_TYPE; + + /** + * @brief BT R_T convert flag +*/ + typedef enum + { + EM_CONVER_OK = 0, + EM_TEMP_OUT_RANGE_H, + EM_TEMP_OUT_RANGE_L, + EM_TEMP_OUT_RANGE_WRONG_INPUT, + }EM_BT_ALGO_OUT_RANGE; + + +/** + * @brief BT device type enum +*/ + typedef enum + { + EM_BT_DEVICE_WATCH_BAND = 0x00, //Device type: wearable watch or band + EM_BT_DEVICE_INEAR_DEEP, //Device type: in-depth earphones + EM_BT_DEVICE_INEAR_NORMAL, //Device type: shallow in-ear earphones + EM_BT_DEVICE_TYPE_MAX, //Device type: device type total number + }EM_BT_DEVICE_TYPE; + + /** + * @brief BT monitor mode + */ + typedef enum + { + EM_MODE_ONCE = 0x00, //monitor mode: single measurement + EM_MODE_CONTINUE, //monitor mode: continue measurement + EM_MODE_TEST, //monitor mode: mass production testing + EM_MODE_MAX, //monitor mode: monitor mode total number + }EM_BT_MONITOR_MODE; + + /** + * @brief BT monitor mode + */ + typedef enum + { + EM_BT_TYPE_SHELL = 0x00, //monitor body temperature type: single + EM_BT_TYPE_CORE, //monitor body temperature type: continue + EM_BT_TYPE_MAX, //monitor body temperature type: mode total number + }EM_BT_TYPE; + + /** + * @brief BT rawdate type + */ + typedef enum + { + EM_RAWDATA_ADC = 0x00, //rawdata type: normal ADC code + EM_RAWDATA_RESIS, //rawdata type: NTC resistance + EM_RAWDATA_TEMP, //rawdata type: temperature + EM_RAWDATA_MAX, //rawdata type: type total + }EM_BT_RAWDATA_TYPE; + + /** + * @brief BT sensor type + */ + typedef enum + { + EM_SENSOR_NTC = 0x00, //sensor type: NTC + EM_SENSOR_IC, //sensor type: IC + EM_SENSOR_MAX, //sensor type: type total + }EM_BT_SENSOR_TYPE; + + /* ******************************************struct define************************************************ */ + + /** + * @brief data min max average + */ + typedef struct + { + GS16 nMin; + GS16 nMax; + GS32 nSum; + }STBtPreprocRwatemp; + + /** + * @brief final output struct + */ + typedef struct + { + GU8 chFrameIndex; // frame count + STBtPreprocRwatemp stRawTemp[BT_MAX_CH_NUM]; + /* Body Temperature */ + GS16 nFrameTemperature[BT_MAX_CH_NUM]; //finaloutput: (included) shell body temperature + GS16 nSecTemperature[BT_MAX_CH_NUM]; //finaloutput: (included) core body temperature + GU8 chOutRangeFlag; // + }STGH3x2xDrvBtOutputResult; + + + /** + * @brief initialize configuration + */ + typedef struct + { + /*********************** configuration header 6 words *****************************/ + //config length & config version (up to the tool) + GU16 unCfgLen; //initialize configuration: size of struct + GU16 unCfgVer; //initialize configuration: version of configuration + GU16 unCfgTimL; //initialize configuration: configuration compiler time + GU16 unCfgTimH; //initialize configuration: configuration compiler time + GU16 unCfgProjCode; //initialize configuration: customer code + GU16 unCheckSum; //initialize configuration: configuration checksum + + /*********************** hardware information 45 words ****************************/ + //device information (up to the device hardware) + GU16 unDeviceType; //initialize configuration: type of device + GU16 unChannelNum; //initialize configuration: number of channels + GU16 unMonitorMode; //initialize configuration: monitor mode + GU16 unMonitorType; //initialize configuration: monitor type + GU16 unTempRangeUpper; //initialize configuration: temperature upper limit + GU16 unTempRangeLower; //initialize configuration: lower temperature limit + //rawdata information (up to the application) + GU16 unSampleFrequency; //initialize configuration: sampling frequency + GU16 unRawdataType; //initialize configuration: rawdata meaning + //inherent deviation (up to the device) + GS16 nTempConstOffset0; //initialize configuration: inherent deviation of device //GS16 force to GU16 + GS16 nTempConstOffset1; //initialize configuration: inherent deviation of device //GS16 force to GU16 + //reserved + GU16 unDeviceReserved[2]; //initialize configuration: device info reserved + + // temperature sensor information + GU16 unSensorType; //initialize configuration: sensor type + GU16 unSensorNtcRef; //initialize configuration: NTC ref resistance: unit:10ohm + GU16 unSensorNtcRT_Len; //initialize configuration: NTC R-T table length + GU16 unSensorParameter[30]; //initialize configuration: sensor parameters buffer NTC_R:Order: unTempRangeLower to unTempRangeUpper + //unTempRangeLower step 2 celsius until 25 celsius, 25 celsius step 1 celsius to unTempRangeUpper + /*********************** threshold information 20 words ****************************/ + // threshold + GU16 unBufferMax; //initialize configuration: data buffer length, unit is senconds, default:300s + + GU16 unTimeWindow; //initialize configuration: data buffer window, unit is senconds, default: 20s + GU16 unTimeStep; //initialize configuration: step size of sliding window, unit is senconds, default: 5s + GU16 unTimeFast; //initialize configuration: fastest output time, unit is senconds, at least 60s + GU16 unTimeFastSlidWindow; //initialize configuration: fastest output slid window size + GU16 unTimeFastSlidStep; //initialize configuration: fastest output slid window step + + GU16 unCntStable; //initialize configuration: stable time + GU16 chTempFluctuate; //initialize configuration: fluctuate temperature + GU16 unCntFluctRecover; //initialize configuration: recver time frome fluctuate + GU16 unTimeStable; //initialize configuration: minimum stable time requirement, unit is senconds, at least: 30s + + GU16 unTimeRecover; //initialize configuration: minimum recover time requirement, unit is senconds, at least: 30s + + GU16 unTempStable; //initialize configuration: minimum stable time requirement, unit is senconds, at least: 30s + GU16 unTempStableUpper; //initialize configuration: minimum stable time requirement, unit is senconds, at least: 30s + GU16 unTempStableLower; //initialize configuration: minimum stable time requirement, unit is senconds, at least: 30s + GU16 unThresReserved[6]; //initialize configuration: threshold reserved + + /*********************** algorithm information 100 words ****************************/ + // Please contact GOODIX + GU16 unConfig[100]; //initialize configuration: algorithm + + }STGoodixAlgorithmBtControlConfigParametersBuffer; + + /** + * @brief Gsensor information + */ + typedef struct + { + GS16 nGSensorX; //refer: acc_x_axis, normalized to 512/g(9.80m/s^2) + GS16 nGSensorY; //refer: acc_y_axis, normalized to 512/g(9.80m/s^2) + GS16 nGSensorZ; //refer: acc_z_axis, normalized to 512/g(9.80m/s^2) + }STGoodixAlgorithmBtCalculateInputAccdata; + + /** + * @brief external input reference + */ + typedef struct + { + /* Personal information */ + GU8 uchAge; //refer: (recommend) age (0-100) + GU8 uchGender; //refer: (recommend) gender (0- male, 1- female) + GU16 uchHeight; //refer: (recommend) height (unit: cm) + GU16 uchWeight; //refer: (recommend) weight (unit: kg) + /* physiological signal */ + GU16 unHR; //refer: (required) heart rate (unit: bpm) + GU16 unRRI; //refer: (recommend) RR interval (unit: ms) + GU16 unSPO2; //refer: (optional) Oxygen saturation (unit: normalized to 0-100) + GS16 unET; //refer: (optional) enviroment temperature (unit: 0.01 Celsius) + GU16 unBT; //refer: (optional) core body temperature (unit: 0.01 Celsius) + GU16 unPI; //refer: (optional) perfusion index (unit: normalized to 0-100) + /* wearing state */ + GU16 unWear; //refer: (recommend) wearing quality (unit: normalized to 0-100) + /* device info */ + GU16 unChargeFlag; //refer: (required) the device was charged ten minutes ago,0- no 1- charged + GU16 unReserves[4]; //refer: (reserved) reserved + }STGoodixAlgorithmBtInputRef; + + /** + * @brief output struct + */ + typedef struct + { + /* flag of Body Temperature */ + GU8 uchRefresh; //output: (included) refresh flag + GU8 uchCBTUpate; + GU8 uchConfidence; //output: (included) confidence level, normalized to 0-100 + GU8 uchState; //output: (included) 0-default 1-rise 2-stable 3-under-stable 4-fluctuate + GU8 uchReserved[5]; //output: (Reserved) reserved + /* Body Temperature */ + GS16 nBT; //output: (included) shell body temperature + GS16 nCBT; //output: (included) core body temperature + GS16 nFPCBT; //output: (included) core body temperature of quick forecast result + GS16 nReserved[2]; //output: (Reserved) reserved + }STGoodixAlgorithmBtCalculateOutputResult; + + /** + * @brief final output struct + */ + typedef struct + { + /* flag of Body Temperature */ + GU8 uchRefresh; //finaloutput: (included) refresh flag + GU8 uchConfidence; //finaloutput: (included) confidence level, normalized to 0-100 + GU8 uchState; //finaloutput: (included) 0-default 1-rise 2-stable 3-under-stable 4-fluctuate + GU8 uchReserved[5]; //finaloutput: (Reserved) Reserved + /* Body Temperature */ + GS16 nBT; //finaloutput: (included) shell body temperature + GU16 unCBT; //finaloutput: (included) core body temperature + GS16 nReserved[2]; //finaloutput: (Reserved) reserved + }STGoodixAlgorithmBtFinalOutputResult; + + /* *************************************Implemented by customer******************************************* */ + /** + * @brief memory malloc function + * @param size + * @return pointer of memory + */ + extern void* GoodixSensorAlgoMalloc(GS32 size); + + /** + * @brief memory free function + * @param addr + */ + extern void GoodixSensorAlgoFree(void* addr); + + /** + * @brief algorithm log function + * @param addr + */ + extern void GoodixSensorAlgoLog(GCHAR* pLogStr); + + /* ******************************************API INTERFACE************************************************ */ + DLL_API_BODY_TEMPERATURE GU8* GoodixBtAlgoVersion(void); + DLL_API_BODY_TEMPERATURE GS32 GoodixBtAlgoInit(STGoodixAlgorithmInfo* pstGoodixAlgorithmInfo); + DLL_API_BODY_TEMPERATURE GS32 GoodixBtAlgoCalculate(STGoodixAlgorithmInfo* pstGoodixAlgorithmInfo); + DLL_API_BODY_TEMPERATURE GS32 GoodixBtAlgoFinalCalculate(STGoodixAlgorithmInfo* pstGoodixAlgorithmInfo); + DLL_API_BODY_TEMPERATURE GS32 GoodixBtAlgoDeinit(STGoodixAlgorithmInfo* pstGoodixAlgorithmInfo); + + /* ******************************************************************************************************* */ + +#ifdef __cplusplus +} +#endif +#endif //GOODIX_ALGO_BT_H diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_ecg.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_ecg.h new file mode 100644 index 000000000..e5a519723 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_ecg.h @@ -0,0 +1,129 @@ +#ifndef __GOODIX_ECG_H +#define __GOODIX_ECG_H + +#include "stdint.h" +#include "goodix_type.h" + +#define ECG_INTERFACE_VERSION "pv_v1.0.0" +#define ECG_INTERFACE_VERSION_LEN_MAX (20) +#define ECG_CHANNEL_NUM (2) + +/** +* @brief ECG �㷨��������״ֵ̬ +*/ +typedef enum +{ + GX_ALGO_ECG_SUCCESS = 0x00000000, /**< �ɹ� */ + GX_ALGO_ECG_RWONG_INPUT = 0x00000001, /**< �������ݸ�ʽ���Ϸ� */ + GX_ALGO_ECG_NO_MEMORY = 0x00000002, /**< �ڴ�ռ䲻�� */ +}goodix_ecg_ret; + +typedef struct +{ + uint32_t fs; // ������ + uint32_t valid_channel_num; // ��Чͨ���� + uint32_t qrs_flag; // QRS���flag��0������������� + uint32_t mode_type; // ECG��Ϸ�ʽ��0: AC mode,1: DC mode + uint32_t ic_type; // оƬ���ͣ�0��CardiffA��1��CardiffB +}goodix_ecg_config; + +typedef struct +{ + uint32_t out_delay; // �˲��ӳ� +}goodix_ecg_init_result; + +typedef struct +{ + uint32_t frameid; // ֡��� + int32_t *ecg_rawdata; // ԭʼ���� + int32_t acc_x; // ���ٶȼ�x�� + int32_t acc_y; // ���ٶȼ�y�� + int32_t acc_z; // ���ٶȼ�z�� + int32_t ecg_qc_flag; // ���ٻָ���� + int32_t pace; // pace���� +}goodix_ecg_input_rawdata; + +typedef struct +{ + float *ecg_out; // �ĵ�ֵ + goodix_stage *ecg_stage; // P-QRS-J-T ��״̬ + float ecg_bpm; + float *ecg_snr; // ����� + float *ecg_powerline_out; // �˳���Ƶ���� ��� + float *ecg_blw_out; // �˳�����Ư�� ��� + float *ecg_bpm_ch; // ����ֵ +}goodix_ecg_result; + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief ECG �����㷨�汾�� +* @param[in] version �ⲿ����汾�ſռ䣬����20�ֽ� +* @param[out] �� +* @return ����ִ����� +*/ +DRVDLL_API goodix_ecg_ret goodix_ecg_version(uint8_t version[100]); + + +/** +* @brief ECG �����㷨��ʼ�� +* @param[in] cfg ������Ϣ +* @param[in] cfg_size ������Ϣ��С +* @param[out] res ���صĽ�� +* @return ����ִ����� +*/ +DRVDLL_API goodix_ecg_ret goodix_ecg_init(const void *cfg_instance, goodix_ecg_init_result *res, int32_t cfg_size, const char *interface_ver); + + +/** +* @brief ECG �㷨���� +* @param[in] raw ECG ����������Ϣ +* @param[out] res ECG ���صĽ�� +* @return ����ִ����� +*/ +DRVDLL_API goodix_ecg_ret goodix_ecg_update(goodix_ecg_input_rawdata* raw, goodix_ecg_result *res); + +/** +*@brief ECG �������� +* @param[in] �� +* @param[out] res ECG ������ +* @return ����ִ����� +*/ +DRVDLL_API goodix_ecg_ret goodix_ecg_classification_update(goodix_classification_flag *res); + +/** +* @brief ECG �㷨���٣��ͷ��ڲ����ڴ�ռ䣬��������ģ���㷨ʱʹ�� +* @param[out] �� +* @return ����ִ����� +*/ +DRVDLL_API goodix_ecg_ret goodix_ecg_deinit(void); + +/** +* @brief ECG ���ò�����ȡ����ʼ��ǰ���ã��������ýṹ���ڴ� +* @param[out] �� +* @return ����ִ����� +*/ +DRVDLL_API const void *goodix_ecg_config_get_arr(void); + +/** +* @brief ECG ���ò�����С��ȡ����ʼ��ǰ���ã������㷨�ڲ�����У�� +* @param[out] �� +* @return ��������ò�����С +*/ +DRVDLL_API int32_t goodix_ecg_config_get_size(void); + +/** +* @brief ECG ���ð汾�Ż�ȡ����ʼ��ǰ���ã������㷨�ڲ�����У�� +* param[in] �汾�ų��� +* @param[out] ���ڴ��config�İ汾������ +* @return �� +*/ +DRVDLL_API void goodix_ecg_config_get_version(char* ver, uint8_t ver_len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hba.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hba.h new file mode 100644 index 000000000..8278802df --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hba.h @@ -0,0 +1,215 @@ +#ifndef __GOODIX_HBA_H +#define __GOODIX_HBA_H + +#include +#ifndef _ARM_MATH_H +#include "goodix_type.h" +#endif +#include "gh_drv.h" +// HBA ������ +#ifndef HBA_FS +#define HBA_FS 25 +#endif +#define PPG_CHANNEL_NUM 4 + +#define HBA_INTERFACE_VERSION "pv_v1.0.0" +#define HBA_INTERFACE_VERSION_LEN_MAX (20) + +/** +* @brief HBA ͨ������ +*/ +typedef enum +{ + CH_ENABLE_DEFAULT=0,//����Ĭ������ + //��ͨ�� + CH1_ENABLE_1000 = 1000, + CH1_ENABLE_0100 = 100, + CH1_ENABLE_0010 = 10, + CH1_ENABLE_0001 = 1, + //˫ͨ��,�Բ����� + CH2_ENABLE_1010 = 1010, + CH2_ENABLE_0101 = 101, + //��ͨ�� + CH3_ENABLE_0111 = 111, + CH3_ENABLE_1011 = 1011, + CH3_ENABLE_1101 = 1101, + CH3_ENABLE_1110 = 1110, + //��ͨ�� + CH4_ENABLE_1111 = 1111, +}goodix_hba_ch_enable; + +/** +* @brief HBA �㷨��������״ֵ̬ +*/ +typedef enum +{ + GX_ALGO_HBA_SUCCESS = 0x00000000, /**< �ɹ� */ + GX_ALGO_HBA_RWONG_INPUT = 0x00000001, /**< �������ݸ�ʽ���Ϸ� */ + GX_ALGO_HBA_NO_MEMORY = 0x00008000, /**< �ڴ�ռ䲻�� */ +}goodix_hba_ret; + +typedef enum { + HBA_SCENES_DEFAULT = 0, // Ĭ�ϣ����㷨�ڲ�ʶ���� + + HBA_SCENES_DAILY_LIFE = 1, // �ճ����� + HBA_SCENES_RUNNING_INSIDE = 2, // �����ܲ��� + HBA_SCENES_WALKING_INSIDE = 3, // ���ڲ��� + HBA_SCENES_STAIRS = 4, // ����¥�� + + HBA_SCENES_RUNNING_OUTSIDE = 5, // �����ܲ� + HBA_SCENES_WALKING_OUTSIDE = 6, // ���ⲽ�� + + HBA_SCENES_STILL_REST = 7, // ��Ϣ + HBA_SCENES_REST = 8, // ��Ϣ + HBA_SCENES_STILLRADON = 9, // ���� + + HBA_SCENES_BIKING_INSIDE = 10, //�������г� + HBA_SCENES_BIKING_OUTSIDE = 11, //�������г� + HBA_SCENES_BIKING_MOUNTAIN= 12, //�������г�ԽҰ + HBA_SCENES_RUNNING_HIGH_HR = 13, //�������ܲ� + + HBA_SCENES_RUNNING_TREADMILL_CCOMBINE= 14, // �ܲ�������� + + HBA_SCENES_HIGH_INTENSITY_COMBINE = 15, // ��ǿ���˶���� + HBA_SCENES_TRADITIONAL_STRENGTH_COMBINE = 16, // ��ͳ����ѵ����� + HBA_SCENES_STEP_TEST = 17, // ̨�ײ��� + + HBA_SCENES_BALL_SPORTS = 18, // �����˶� + HBA_SCENES_AEROBICS = 19, // ������ + + HBA_SCENES_SLEEP = 20, // ˯�߳��� + HBA_SCENES_JUMP = 21, //����������LS ROMA�� + HBA_SCENES_CORDLESS_JUMP = 22, // ��������������� + HBA_SCENES_SWIMMING = 23, // ��Ӿ���� + HBA_SCENES_SIZE = 24, // ������Ŀ +}hba_scenes_e; + +typedef enum { + HBA_TEST_DYNAMIC = 0, // Ĭ�ϣ���̬���� + HBA_TEST_DOT = 1, // ��� + HBA_TEST_SENSELESS = 2, // �޸�ģʽ +}hba_test_mode; + +typedef struct { + hba_test_mode mode; // ����ģʽ + hba_scenes_e scence; // ���� + uint32_t fs; // ������ + int32_t valid_channel_num; // ��Чͨ���� + // �����ⲿ�����㷨�����ԵIJ��� + uint32_t back_track_len; // ���ݵ�ʱ��,Ĭ��30s,���ʱ������Ϊ120s�����ʱ������Ϊ30s + int32_t hba_latest_output_time; // ������ֵʱ�� + int32_t hba_earliest_output_time; // �����ֵʱ�� + uint32_t hba_lowerest_confidence; // ��ͳ�ֵ���Ŷ� + uint32_t hba_out_step_second; // ��ֵ��� + uint32_t hba_convergence_rate; // ׷�ٹ����е��������� + uint32_t senseless_mode_step; // �޸м��ʱ��������Ϊ0��ʾδ֪ + uint32_t senseless_mode_duration; // �޸г���ʱ��������Ϊ0��ʾδ֪ +}goodix_hba_config; + +typedef struct +{ + uint32_t frameid; // ֡��� + uint32_t total_channel_num; // ͨ������ + int32_t *ppg_rawdata; // PPGԭʼ���ݣ������̹�1234-����1234-���1234 + int32_t *cur_adj_flg; // ���������־λ + int32_t *gain_adj_flg; // ��������־λ + int32_t *enable_flg; // ͨ��ʹ�ܱ�־λ + + int32_t acc_x; // ���ٶȼ�x�� + int32_t acc_y; // ���ٶȼ�y�� + int32_t acc_z; // ���ٶȼ�z�� + + uint32_t sleep_flg; //˯��flg +}goodix_hba_input_rawdata; + +typedef struct +{ + uint32_t hba_out_flag; // ��ֵ��ǣ�Ϊ 1 ��Ч + int32_t hba_out; // ����ֵ + float hba_confi; // ���Ŷ� + float hba_snr; // ����� : �˲�ȥ�����ź�Ƶ�������������������� + uint32_t valid_level; // ���ŵȼ� : 0 -> 1 -> 2 ��Խ��Խ�ɿ� + uint32_t valid_score; // ���ŷ��� : 0->100 Խ��Խ�ɿ� + uint32_t hba_acc_info; // �˶�״̬ : 0-��Ϣ��С�˶���1-����-���˶���2-�ܲ�-���˶��� + hba_scenes_e hba_acc_scence; // �˶����� : �ο� hba_scenes_e ö������ + // ÿһ·������ֵ�����ڵ��� + uint32_t *hba_out_flag_channel; // ��ֵ��ǣ�Ϊ 1 ��Ч + uint32_t *hba_out_channel; // ����ֵ + float *hba_confi_channel; // ���Ŷ� + float *hba_snr_channel; // ����� + float **p_hba_td_filter; // ʱ���˲����ָ������ + float **p_hba_fd_filter; // Ƶ��(��)�˲����ָ�����飬4·��1·���� +}goodix_hba_result; + +#ifdef __cplusplus +extern "C" { +#endif + + +/** +* @brief HBA �����㷨�汾�� +* @param[in] version �ⲿ����汾�ſռ䣬����20�ֽ� +* @param[out] �� +* @return ����ִ����� +*/ +DRVDLL_API goodix_hba_ret goodix_hba_version(uint8_t version[120]); + + +/** +* @brief HBA �����㷨��ʼ�� +* @param[in] scence ʹ�ó��� +* @param[in] fs HBA �� ACC �IJ����ʡ�ע��������ҪͬƵ�� +* @param[out] �� +* @return ����ִ����� +*/ +DRVDLL_API goodix_hba_ret goodix_hba_init(const void *cfg_instance, uint32_t cfg_size, const char *interface_ver); + + +/** +* @brief HBA �㷨���� +* @param[in] raw �������� +* @param[out] res ���������� +* @return ����ִ����� +*/ +DRVDLL_API goodix_hba_ret goodix_hba_update(goodix_hba_input_rawdata* raw, goodix_hba_result *res); + +/** +* @brief HBA �㷨���٣��ͷ��ڲ����ڴ�ռ䣬��������ģ���㷨ʱʹ�� +* @param[out] �� +* @return ����ִ����� +*/ +DRVDLL_API goodix_hba_ret goodix_hba_deinit(void); + +/** +* @brief ��ȡhba��Ĭ�����ò��� +* @return hba��Ĭ�����ò��� +*/ +DRVDLL_API const void *goodix_hba_config_get_arr(void); + +/** +* @brief ��ȡhba������size +* @return hba������size +*/ +DRVDLL_API int32_t goodix_hba_config_get_size(void); + +/** +* @brief ��ȡHBA�����ļ��İ汾�� +* @param[in/out] ver �汾�ű������� +* @param[in] ver_len �汾�ų��ȣ�����ʹ��HBA_INTERFACE_VERSION_LEN_MAX +* @return �� +*/ +DRVDLL_API void goodix_hba_config_get_version(char* ver, uint8_t ver_len); + + +/** +* @brief �û����ô�ӡHBA��Ҫ��Ϣ����Ҫ��ǰ��ʼ����ӡ���� +* @param[in] raw �����������ݣ�NULL == rawʱ������ӡ���� +* @return �� +*/ +DRVDLL_API void hba_essential_info_print(goodix_hba_input_rawdata* raw); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hrv.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hrv.h new file mode 100644 index 000000000..565798b5d --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hrv.h @@ -0,0 +1,96 @@ +/* +* HRVLib.h +*/ + +#ifndef _GOODIX_SYS_HRV_LIB_H_ +#define _GOODIX_SYS_HRV_LIB_H_ + +#include +#include "iot_sys_def.h" +#if DEBUG_HRV +#include "..\..\HRVTest\goodix_debug.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* ·µ»Ø´íÎóÂë */ +typedef enum { + GX_HRV_ALGO_OK = 0x00000000, // ³É¹¦·µ»Ø£¬»òÎÞ³öֵˢР+ GX_HRV_ALGO_FAILED = 0x10000001, // ʧ°Ü·µ»Ø + GX_HRV_ALGO_NULL_PTR = 0x10000002, // Íⲿ´«ÈëµÄÖ¸ÕëΪ¿Õ + GX_HRV_ALGO_INVALID_PARAM = 0x10000003, // ²ÎÊý·¶Î§ÎÞЧ + GX_HRV_ALGO_OUT_OF_MEM = 0x10000004, // ÄÚ´æ·ÖÅäʧ°Ü + GX_HRV_ALGO_DEINIT_ABORT = 0x10000005, // ÊÍ·Åʧ°Ü + GX_HRV_ALGO_UPDATE = 0x10000006, // ÓгöֵˢР+}goodix_hrv_ret; + +#define PPG_CHANNEL_NUM 4 +#define RRI_NUM 4 +#define ACC_THR_NUM 4 + +#define HRV_INTERFACE_VERSION "pv_v1.0.0" +#define HRV_INTERFACE_VERSION_LEN_MAX (20) + +typedef struct { + int32_t need_ipl; // ÊÇ·ñÐèÒª²åÖµµ½1KHz + int32_t fs; // ²ÉÑùÂÊ + int32_t acc_thr[ACC_THR_NUM]; // acc Ïà¹ØãÐÖµ£¬Ä¬ÈÏֵΪ£º20/10/3/3 +}goodix_hrv_config; + +typedef struct { + uint8_t bit_num; //Êý¾ÝλÊý + int32_t *ppg_rawdata; // PPGԭʼÐźţ¬×î¶àËÄͨµÀ + int32_t *cur_adj_flg; // µçÁ÷µ÷¹â±ê־λ + int32_t *gain_adj_flg; // ÔöÒæµ÷¹â±ê־λ + int32_t acc_x; // ¼ÓËÙ¼Æ x Öá + int32_t acc_y; // ¼ÓËÙ¼Æ y Öá + int32_t acc_z; // ¼ÓËÙ¼Æ z Öá + int32_t frame_id; // Ö¡ÐòºÅ + int32_t hr; // µ±Ç°ÐÄÂÊÖµ +}goodix_hrv_input_rawdata; + +typedef struct { + int32_t rri[RRI_NUM]; // RRI½á¹ûÊý×é + int32_t rri_confidence; // ½á¹ûÖÃÐÅ¶È + int32_t rri_valid_num; // RRIÓÐЧ½á¹ûÊýÁ¿ +}goodix_hrv_result; + +IOT_SYS_DLL_API uint8_t *goodix_hrv_version(void); + +IOT_SYS_DLL_API goodix_hrv_ret goodix_hrv_init(const void *cfg_instance, uint32_t cfg_size, const char *interface_ver); + +IOT_SYS_DLL_API goodix_hrv_ret goodix_hrv_calc(goodix_hrv_input_rawdata *input_data, goodix_hrv_result *output_data); + +IOT_SYS_DLL_API goodix_hrv_ret goodix_hrv_deinit(void); + +/** +* @brief »ñÈ¡hrvµÄĬÈÏÅäÖòÎÊý +* @return hrvµÄĬÈÏÅäÖòÎÊý +*/ +IOT_SYS_DLL_API const void *goodix_hrv_config_get_arr(void); + +/** +* @brief »ñÈ¡hrvµÄÅäÖÃsize +* @return hrvµÄÅäÖÃsize +*/ +IOT_SYS_DLL_API int32_t goodix_hrv_config_get_size(void); + +/** +* @brief »ñÈ¡HRVÅäÖÃÎļþµÄ°æ±¾ºÅ +* @param[in/out] ver °æ±¾ºÅ±£´æÊý×é +* @param[in] ver_len °æ±¾ºÅ³¤¶È£¬½¨ÒéʹÓÃHRV_INTERFACE_VERSION_LEN_MAX +* @return ÎÞ +*/ +IOT_SYS_DLL_API void goodix_hrv_config_get_version(char* ver, uint8_t ver_len); + + +#if DEBUG_HRV +IOT_SYS_DLL_API goodix_hrv_debug *copy_debug_addr(); +#endif +#ifdef __cplusplus +} +#endif + +#endif // _GOODIX_SYS_HRV_LIB_H_ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hsm.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hsm.h new file mode 100644 index 000000000..a89fcd79c --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_hsm.h @@ -0,0 +1,47 @@ +#ifndef __GOODIX_HSM_H +#define __GOODIX_HSM_H + + +#include "goodix_type.h" +#include "goodix_algo.h" +#ifdef __cplusplus +extern "C" { +#endif + +extern int32_t HSMAlgoDeInit(void); +extern int32_t HSMAlgoInit(int32_t *Fs); +extern uint8_t *HSMAlgoVersion(void); +typedef struct +{ + GU32 ulSleepInTime; + GU32 ulSleepOutTime; + GU16 nSleepLength; + GU16 nDeepRatio; + GU16 nLightRatio; + GU16 nRemRatio; + GU8 nWakeTimes; + GU8 nSleepScore; +}ST_HSM_SCORE; +typedef struct +{ + int32_t IPpgRaw; + int32_t IACCx; + int32_t IACCy; + int32_t IACCz; + int32_t IHeart; +}ST_HSM_DATA_IN; +#define GH3X2X_HSM_FLAG_BUFF_LEN (120) +typedef struct +{ + uint8_t uchStageOutNum; + uint8_t uchStageDataFlag; + uint8_t puchHSMStageOut[GH3X2X_HSM_FLAG_BUFF_LEN]; +}ST_HSM_DATA_OUT; +extern int32_t HSMProc(ST_HSM_DATA_IN* pstHSMDataIn, ST_HSM_DATA_OUT* pstHSMDataOut, ST_HSM_SCORE* pstHSMScore); +extern int32_t HSMLastDataProc(ST_HSM_DATA_OUT* pstHSMDataOut, ST_HSM_SCORE* pstHSMScore); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_log.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_log.h new file mode 100644 index 000000000..6076781aa --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_log.h @@ -0,0 +1,39 @@ +#ifndef _GOODIX_LOG_H_ +#define _GOODIX_LOG_H_ +#include "goodix_type.h" + +typedef int32_t(*CallbackPrintfUser)(const char *, ...); +typedef int32_t(*CallbackSnprintfUser)(char *str, size_t size, const char *format, ...); +typedef void(*Callback_GH3X2X_Log)(GCHAR *log_string); + +DRVDLL_API void goodix_set_sprintFunc(CallbackPrintfUser g_pPrintfUserIn, CallbackSnprintfUser g_pSnprintfUserIn, Callback_GH3X2X_Log GH3X2X_Log_In); + +//log print +//extern CallbackPrintfUser g_pPrintfUser; +//extern CallbackSnprintfUser g_pSnprintfUser; +//extern Callback_GH3X2X_Log GH3X2X_PlatformLog; + +///// log support len +//#define GH3X2X_LOG_DEBUG_SUP_LEN (128) + +//#define GH3X2X_INFO_LOG_PARAM(...) do {\ +//if(g_pSnprintfUser)\ +//{\ +//GCHAR chDebugStr[GH3X2X_LOG_DEBUG_SUP_LEN]={0};\ +//g_pSnprintfUser(chDebugStr, GH3X2X_LOG_DEBUG_SUP_LEN, \ +//"alg:"__VA_ARGS__);\ +//GH3X2X_PlatformLog(chDebugStr);\ +//}\ +//if(g_pPrintfUser)g_pPrintfUser("alg:"__VA_ARGS__);\ +//} while (0)//bp log + +// need to init goodix_set_sprintFunc() first +/* LOG example: +#if DEBUG_LOG +#define LOG_PRINT GH3X2X_INFO_LOG_PARAM +#else +#define LOG_PRINT +#endif //#if DEBUG_LOG +*/ + +#endif // !_GOODIX_LOG_H_ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_mem.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_mem.h new file mode 100644 index 000000000..be142418a --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_mem.h @@ -0,0 +1,78 @@ +#ifndef __GOODIX_MEM_H +#define __GOODIX_MEM_H + +#include "stdint.h" +#include "goodix_type.h" + + +typedef enum +{ + MEMPOOL_IS_OK_E = 0, /*< MEM POOL is ok >*/ + ERR_MEMPOOL_NOT_EXIST_E = -1, /*< mempool not exist >*/ + ERR_PARAMS_MEMPOOL_SIZE_E = -2, /*< Input parameter is invalid: mempool size is invalid >*/ + ERR_PARAMS_MALLOC_SIZE_E = -3, /*< Input parameter is invalid: malloc size is invalid >*/ + ERR_MEMPOOL_NOT_ENOUGH_MEM_E = -4, /*< Memory size does not meet the required memory >*/ + ERR_PARAMS_ADDR_WRONG_E = -5, /*< Input parameter is invalid: free addr is invalid >*/ + ERR_OP_CHUNK_TREAD_E = -6, /*< Occur memory tread >*/ + ERR_OP_CHUNK_LEAKY_E = -7, /*< Occur memory leaky >*/ +}goodix_mem_ret; + +#ifdef __cplusplus +extern "C" { +#endif + +//内存不足时的接口,只支持内存分配时候调用,不支持内存越界时调用 +#if !(_WIN32 || _WIN64) +extern void Gh3x2xPoolIsNotEnough(void); +#endif + +/** +* @brief 内存池初始化操作 +* @param[in] mem_addr 内存地址 + size 内存大小 +* @param[out] 无 +* @return 初始化情况 0 < Operation success. + -1 < Input parameter is invalid + -2 < Memory size does not meet the minimum required memory + -3 < Memory manager has been initialized. +*/ +DRVDLL_API int32_t goodix_mem_init(void* mem_addr, int32_t size); + +/** +* @brief 内存池销毁操作 +* @param[in] 无 +* @param[out] 无 +* @return 无 +*/ +DRVDLL_API void goodix_mem_deinit(void); + +/** +* @brief 内存申请操作 +* @param[in] 申请内存大小(字节) +* @param[out] 无 +* @return 申请到的内存段首地址(在函数调用外做类型转换) +*/ +DRVDLL_API void* goodix_mem_malloc(int32_t size); + +/** +* @brief 释放内存操作 +* @param[in] 释放内存段的首地址 +* @param[out] 无 +* @return 无 +*/ +DRVDLL_API void goodix_mem_free(void* mem_addr); + +/** +* @brief 获取内存池当前空闲内存容量 +* @param[in] 无 +* @param[out] 无 +* @return 内存池当前空闲容量(byte) +*/ +DRVDLL_API uint32_t goodix_mem_get_free_size(void); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_nadt.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_nadt.h new file mode 100644 index 000000000..f4a99100f --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_nadt.h @@ -0,0 +1,132 @@ +#ifndef _WWD_MAIN_H_ +#define _WWD_MAIN_H_ +#include +#include +#include +#include +#include "goodix_type.h" +#include "gh_drv.h" + +#define NADT_INTERFACE_VERSION "pv_v1.0.0" +#define NADT_INTERFACE_VERSION_LEN_MAX (20) + +#define IOT_NADT_MAX(a,b) ((a)<(b)?(b):(a)) +#define IOT_NADT_MIN(a,b) ((a)>(b)?(b):(a)) +#define IOT_NADT_ABS(x) abs(x) +#define IOT_NADT_ABS_GS32(x) abs((GS32)(x)) +//#define IOT_NADT_ABS_GF32(x) fabsf((GF32)(x)) +//#define IOT_NADT_ABS_GF64(x) fabs((GF64)(x)) +//#define IOT_NADT_SQRT(x) sqrt(x) +#define IOT_NADT_SQRTF(x) sqrtf(x) +#define IOT_NADT_ROUND(x) round(x) +#define NADT_PTR_NULL ((void *)0) + +typedef enum +{ + GX_ALGO_NADT_SUCCESS = 0x00000000, /**< 成功 */ + GX_ALGO_NADT_NO_MEMORY = 0x00000001, /**< 内存空间不够 */ + GX_ALGO_NADT_UNINIT = 0x00000002, + GX_ALGO_NADT_RWONG_INPUT = 0x00000003, /**< 输入数据格式不合法 */ +}goodix_nadt_ret; + +#define NADT_MID_INFO_OUT 1 + +//算法中间变量 +typedef struct +{ + // + GU8 wearResult; + GU8 moveFlag; + GU8 liveFlag; + GU8 bgJumpFlag; + GU8 bgPeriodFlag; + //// + ////ADT判断 + //GS32 adtIRAvg; //ADT值 + // + //运动判断 + GS32 accStd; //ACC标准差 + // + //活体检测 + GS32 rawPVLen; //波谷数 + GS32 curHR; //心率 + GS32 difRrInter; //心率变化 + GU8 heartBeatFlag; //心率标记 + GU8 confiHeartBeatFlag; //高置信度心率标记 + GU8 wearAcfScore; //自相关分数 + GS32 signal; //信号量 + //基线判断 + GU16 baseLineRatio; //基线单调率 + GS32 baseLineDiff; //基线diff值 + // + //高频背景光检测 + GS16 jumpBgDiff; //背景光diff + GU8 bgPeakNum; //背景光波峰个数 + // + //背景光周期检测 + GS16 periodBgDiff; //背景光变化量 + GU16 bgPeriod; //背景光周期 + GU16 bgPeriodDiff; //背景光周期差异 +}NADT_ST_MID_INFO; + + + +typedef struct +{ + GU16 sampleRateNADT; //采样率 + GU8 unwearDetectLevel; //佩戴等级 + GU8 sleepStatus; //睡眠状态 + // + GU16 checkTimeoutThr; //活体检测超时时间 + GU8 unwearCheckCntThr; //脱落确认时间 + GU8 wearCheckCntThr; //活体确认时间 + // + //ADT判断 + GS32 adtWearOnThr; //ADT wear on阈值 + GS32 adtWearOffThr; //ADT wear off阈值 + // + //运动判断 + GS32 accStdThr; //ACC标准差 + // + //活体检测 + GU8 liveDetectEnable; //活体检测使能 + GS32 rawPVLenThr; //高次谐波阈值 + GU16 heartBeatThrLow; //心率下限 + GU16 heartBeatThrHigh; //心率上限 + GS32 difRrInterThr; //心率变化阈值 + GU8 wearAcfScoreThr; //自相关分数阈值 + GU16 baseLinePosRatioThr; //基线单调率阈值 + GS32 baseLineDiffThr; //基线平坦性阈值 + GS32 sigScaleThr; + // + //高频背景光检测 + GU8 bgJumpDetectEnable; //背景光突变检测使能 + GS16 jumpBgDiffThr; //背景光变化量阈值 + GU8 bgPeakValleyNumThr; //背景光峰谷个数阈值 + // + //背景光周期检测 + GU8 bgPeriodDetectEnable; //背景光周期检测使能 + GS16 periodBgDiffThr; //背景光变化量阈值 + GU16 bgPeriodThr; //背景光周期阈值 + GU16 bgPeriodDiffThr; //背景光周期差异阈值 +}goodix_nadt_config; + +#ifdef __cplusplus +extern "C" { +#endif + +DRVDLL_API goodix_nadt_ret NADTProcInit(const void *cfg_instance, GS32 cfg_size, const char *interface_ver); +DRVDLL_API goodix_nadt_ret NADTProcDeinit(void); +DRVDLL_API goodix_nadt_ret NADTProc(GS32 lPacketInfoArr[], GS32 lResult[], NADT_ST_MID_INFO *stMidInfo); +DRVDLL_API goodix_nadt_ret GetNadtVersion(GU8 version[120]); +DRVDLL_API GU8 NADTWearDetectByCap(GS32 lPacketInfoArr[]); + +DRVDLL_API const void *goodix_nadt_config_get_arr(void); +DRVDLL_API GS32 goodix_nadt_config_get_size(void); +DRVDLL_API void goodix_nadt_config_get_version(char* ver, GU8 ver_len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_resp.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_resp.h new file mode 100644 index 000000000..a7cbbb43e --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_resp.h @@ -0,0 +1,35 @@ +#ifndef __GOODIX_RESP_H +#define __GOODIX_RESP_H + + +#include "goodix_type.h" +#include "goodix_algo.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern GS32 RespInit(GS32 *fs); +extern void RespDeInit (void); +typedef struct +{ + GS32 IPpgRaw; + GS32 IACCx; + GS32 IACCy; + GS32 IACCz; + GS32 IAdjFlag; +}RESP_ST_DATA_IN; +typedef struct +{ + GU8 nRespRate; + GU8 nBelieve; + GBOOL nRespOutFlag; +}RESP_ST_DATA_OUT; +extern GS32 RespProc(RESP_ST_DATA_IN* stRespDataIn, RESP_ST_DATA_OUT* stRespDataOut); +extern GU8* RespAlgoVersion (void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_spo2.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_spo2.h new file mode 100644 index 000000000..28a898a30 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_spo2.h @@ -0,0 +1,179 @@ +#ifndef __GOODIX_SPO2_INTERFACE_H +#define __GOODIX_SPO2_INTERFACE_H + +#include +#include "goodix_type.h" +#include "gh3x2x_demo_algo_config.h" + +#if ((__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_BASIC) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_MEDIUM)) +#define SPO2_INTERFACE_VERSION "bas_pv_v1.0.0" +#elif ((__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_PREMIUM) || (__GOODIX_SPO2_ALGO_VERISON__ == GOODIX_ALGO_EXCLUSIVE)) +#define SPO2_INTERFACE_VERSION "pre_pv_v1.0.0" +#endif +#define SPO2_INTERFACE_VERSION_LEN_MAX (20) +#define CHIP_PPG_CHL_NUM (4) + +/** +* @brief SPO2 Ëã·¨º¯Êý·µ»Ø×´Ì¬Öµ +*/ +typedef enum +{ + GX_ALGO_SPO2_SUCCESS = 0x00000000, /**< ³É¹¦ */ + GX_ALGO_SPO2_RWONG_INPUT = 0x00000001, /**< ÊäÈëÊý¾Ý¸ñʽ²»ºÏ·¨ */ + GX_ALGO_SPO2_NO_MEMORY = 0x00000002, /**< ÄÚ´æ¿Õ¼ä²»¹» */ + GX_ALGO_SPO2_FRAME_UNCOMPLETE = 0x00000003, /**< ´¦ÓÚ½µ²ÉÑùƽ¾ù¹ý³ÌÖÐ*/ + GX_ALGO_SPO2_WIN_UNCOMPLETE = 0x00000004, /**< δµ½ÍêÕû»¬´°Ö¡Î»Öã¨ÕûÊýs£© */ + GX_ALGO_SPO2_UNEXPECTED = 0x00000005, /*²»ºÏÉè¼ÆÂß¼­Òì³£ */ + GX_ALGO_SPO2_CFG_ERROR = 0x00000006, /*ÅäÖòÎÊýУÑ鲻ͨ¹ý*/ + GX_ALGO_SPO2_INIT_FAILURE = 0x00000007, /*³õʼ»¯Ê§°Ü*/ +}goodix_spo2_ret; + +typedef struct { + //raw ÅäÖÃÐÅÏ¢ + uint32_t valid_chl_num; // ÓÐЧͨµÀÊý + uint32_t raw_fs; // ԭʼ²ÉÑùÂÊ + + int32_t cali_coef_a4; //У׼²ÎÊý4´ÎÏî + int32_t cali_coef_a3; //У׼²ÎÊý3´ÎÏî + int32_t cali_coef_a2; //У׼²ÎÊý2´ÎÏî + int32_t cali_coef_a1; //У׼²ÎÊý1´ÎÏî + int32_t cali_coef_a0; //У׼²ÎÊý³£ÊýÏî + //hbʹÄܱêÖ¾ + uint32_t hb_en_flg; //hbʹÄܱêÖ¾ + //Åå´÷״̬ + uint32_t wear_mode; //Åå´÷״̬ 0:ÊÖ»· 1£ºÊÖÖ¸ 2£º¶ú»ú + // acc move thr + uint32_t acc_thr_max; + uint32_t acc_thr_min; + uint32_t acc_thr_scale; + uint32_t acc_thr_num; + uint32_t acc_thr_angle; + //CTRÉèÖà + uint32_t ctr_en_flg; + uint32_t ctr_red_thr; + + //ÐźÅÖÊÁ¿ÆÀ¹ÀÏà¹ØãÐÖµ + uint8_t ppg_jitter_thr; + uint8_t ppg_noise_thr; + uint8_t ppg_coeff_thr; + uint8_t quality_module_key; + + //³öÖµ²ßÂÔ + uint8_t low_spo2_thr; + uint8_t fast_out_time; + uint8_t slow_out_time; + uint8_t min_stable_time_high; + uint8_t min_stable_time_low; + uint8_t max_spo2_variation_high; + uint8_t max_spo2_variation_low; + uint8_t ouput_module_key; +}goodix_spo2_config; + +typedef struct +{ + uint32_t frameid; // Ö¡ÐòºÅ + uint8_t bit_num; // Êý¾ÝλÊý + uint8_t ch_num; // ¹àÈëÊý¾ÝµÄͨµÀÊý£¨1¸öͨµÀͬʱ°üº¬Â̹⡢ºìÍâ¡¢ºì¹âÊý¾Ý£© + int32_t *ppg_rawdata; // PPGԭʼÊý¾Ý£¬ÒÀ´ÎÂ̹â1234-ºìÍâ1234-ºì¹â1234 + int8_t *cur_adj_flg; // µçÁ÷µ÷¹â±ê־룬 ÒÀ´ÎÂ̹â1234-ºìÍâ1234-ºì¹â1234 + int8_t *gain_adj_flg; // ÔöÒæµ÷¹â±ê־룬 ÒÀ´ÎÂ̹â1234-ºìÍâ1234-ºì¹â1234 + int8_t *enable_flg; // ͨµÀʹÄܱê־룬 ÒÀ´ÎÂ̹â1234-ºìÍâ1234-ºì¹â1234 + int32_t *ch_agc_drv0; // Çý¶¯µçÁ÷0-ÒÀ´ÎÂ̹â1234-ºìÍâ1234-ºì¹â1234 + int32_t *ch_agc_drv1; // Çý¶¯µçÁ÷1-ÒÀ´ÎÂ̹â1234-ºìÍâ1234-ºì¹â1234 + int8_t *ch_agc_gain; // gainÖµ1-ÒÀ´ÎÂ̹â1234-ºìÍâ1234-ºì¹â1234 + int32_t acc_x; // ¼ÓËٶȼÆxÖá + int32_t acc_y; // ¼ÓËٶȼÆyÖá + int32_t acc_z; // ¼ÓËٶȼÆzÖá + int32_t wear_on_flag; // Åå´÷¼ì²â±êÖ¾ +}goodix_spo2_input_rawdata; + +typedef struct +{ + //**********************ËÄͨµÀÊä³ö×îÖÕÖµ***************************// + int32_t final_spo2; + int32_t final_valid_level; + int32_t final_confi_coeff; + int32_t final_WeightR; + int32_t final_hb_mean; + int32_t final_hb_confi_lvl; + int32_t final_invalidFlg; + int32_t final_piIR; + int32_t final_piRed; + int32_t final_snrIR; + int32_t final_snrRed; + int32_t final_r_val; + int32_t final_calc_flg; +}goodix_spo2_result; + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @brief SPO2 ´¦ÀíËã·¨°æ±¾ºÅ +* @param[in] version Íⲿ´¢´æ°æ±¾ºÅ¿Õ¼ä£¬·ÖÅä20×Ö½Ú +* @param[out] ÎÞ +* @return º¯ÊýÖ´ÐÐÇé¿ö +*/ +DRVDLL_API goodix_spo2_ret goodix_spo2_version(uint8_t version[150]); + +/** +* @brief SPO2 ´¦ÀíËã·¨³õʼ»¯ +* @param[in] cfg_instance Íⲿ´«ÈëµÄÅäÖòÎÊý½á¹¹Ìå +* @param[in] cfg_size ÅäÖýṹÌå´óС£¬ÓÃÓÚУÑéÍⲿ½Ó¿ÚÎļþÊÇ·ñ¶ÔÆë +* @param[in] interface_ver ½Ó¿Ú°æ±¾ºÅ£¬ÓÃÓÚУÑéÍⲿ½Ó¿ÚÎļþÊÇ·ñ¶ÔÆë +* @param[out] ÎÞ +* @return º¯ÊýÖ´ÐÐÇé¿ö +*/ +DRVDLL_API goodix_spo2_ret goodix_spo2_init(const void *cfg_instance, int32_t cfg_size, char *interface_ver); + +/** +* @brief SPO2 ѪÑõ¼ÆËã +* @param[in] raw ÊäÈëԭʼÊý¾Ý½á¹¹Ìå +* @param[out] res Êä³ö½á¹û½á¹¹Ìå +* @return º¯ÊýÖ´ÐÐÇé¿ö +*/ +DRVDLL_API goodix_spo2_ret goodix_spo2_calc(goodix_spo2_input_rawdata* raw, goodix_spo2_result* res); + + +/** +* @brief ¹©¿Í»§µ÷ÊÔ¶ÔÆëʱµ÷Ó㬴òÓ¡Ëã·¨Æô¶¯ÔËÐкóµÄһЩ¹Ø¼ü±äÁ¿ÐÅÏ¢£¨ÔÚgoodix_spo2_calcºóµ÷Óã© +* @param[in] raw ÊäÈëԭʼÊý¾Ý½á¹¹Ì壬NULL==rawdataʱ£¬²»´òÓ¡Êý¾ÝÐÅÏ¢ +* @param[out] ÎÞ +* @return ÎÞ +*/ +DRVDLL_API void goodix_spo2_essential_info_print(goodix_spo2_input_rawdata* raw_data); +/** +* @brief SPO2 Ëã·¨Ïú»Ù£¬ÊÍ·ÅÄÚ²¿µÄÄÚ´æ¿Õ¼ä£¬µ÷ÓÃÆäËûÄ£¿éË㷨ʱʹÓà +* @param[out] ÎÞ +* @return º¯ÊýÖ´ÐÐÇé¿ö +*/ +DRVDLL_API goodix_spo2_ret goodix_spo2_deinit(void); + + +/** +* @brief SPO2 ÅäÖòÎÊý»ñÈ¡£¬³õʼ»¯Ç°µ÷Ó㬵¼Èë´æ·ÅÅäÖýṹÌåÄÚÈݵÄÄÚ´æ +* @param[out] ÎÞ +* @return Ö¸ÏòÅäÖýṹÌåʵÀýµÄÖ¸Õë +*/ +const void *goodix_spo2_config_get_instance(void); + +/** +* @brief SPO2 »ñÈ¡ÅäÖòÎÊý½á¹¹ÌåµÄÄÚ´æ¿Õ¼ä´óС£¬³õʼ»¯Ç°µ÷Óã¬ÓÃÓÚËã·¨ÄÚ²¿½øÐмìÑé +* @param[out] ÎÞ +* @return ÅäÖòÎÊýÕ¼ÓõÄÄÚ´æ¿Õ¼ä´óС +*/ +int32_t goodix_spo2_config_get_size(void); + +/** +* @brief SPO2 »ñÈ¡½Ó¿ÚÎļþµÄ°æ±¾£¬³õʼ»¯Ç°µ÷Óã¬ÓÃÓÚËã·¨ÄÚ²¿½øÐмìÑ飨·ÀÖ¹Íⲿ±àÒëʱ½Ó¿ÚÎļþ¶¨Òåδ¶ÔÆë£© +* @param[out] ÎÞ +* @return ÎÞ +*/ +void goodix_spo2_config_get_version(char *ver, uint8_t ver_len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_type.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_type.h new file mode 100644 index 000000000..e35cd86fd --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_type.h @@ -0,0 +1,104 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-06-25 13:57:14 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-06-25 15:23:36 + * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/goodix_type.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef __GOODIX_TYPE +#define __GOODIX_TYPE + +// 与零比较的公共阈值 +#ifndef EPS +#define EPS 0.000001f +#endif + +// 输出 lib 用 +#if _WIN32 || _WIN64 +#define DRVDLL_API extern _declspec(dllexport) +#else +#define DRVDLL_API +#endif + +// 类型重定义 +#if _WIN32 || _WIN64 +typedef signed char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef long long int64_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long long uint64_t; +#else +#include +#endif +// #ifndef _ARM_MATH_H +// typedef float float; +// typedef double float64_t; +// #endif + +// typedef unsigned char GBOOL; +// typedef char GCHAR; +// typedef unsigned char GUCHAR; +// typedef signed char GS8; +// typedef unsigned char GU8; + +// typedef signed short GS16; +// typedef unsigned short GU16; + +// typedef signed int GS32; +// typedef unsigned int GU32; + +// typedef signed long long GS64; +// typedef unsigned long long GU64; + +// typedef float GF32; +// typedef double GF64; +// typedef long double GF128; + +#include +#include + +typedef enum { + False = 0, + True = 1, +}goodix_flag_e; + +// 当前点所处的状态:算法内部检测【目前输出 R 点】 +typedef enum { + // 输出值是否有效 + stage_noneffect_out = 0, + + // 默认值 + stage_default, + + + // 快速恢复相关 + //stage_former_begin, + //stage_former_top, + //stage_former_downing, + + // 波形特征点 + stage_pqrst_p, + stage_pqrst_q, + stage_pqrst_r, + stage_pqrst_j, + stage_pqrst_j60, + stage_pqrst_s, + stage_pqrst_t_onset, + stage_pqrst_t, + stage_pqrst_t_offset, + stage_pqrst_u, +}goodix_stage; + +// ECG信号病例分类标志 +typedef enum { + FLAG_NORMAL, // ECG信号检测为正常 + FLAG_ATRIAL_FIBRILLATION, // ECG信号检测为房颤 + FLAG_OTHER, // ECG信号检测为其它 + FLAG_NOISE, // ECG信号检测为噪声 +}goodix_classification_flag; + +#endif // !__GOODIX_TYPE diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/iot_sys_def.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/iot_sys_def.h new file mode 100644 index 000000000..a19902cdb --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/inc/iot_sys_def.h @@ -0,0 +1,164 @@ +/* +* hrv_type_def.h +*/ + +#ifndef _GOODIX_IOT_SYS_TYPE_DEF_H_ +#define _GOODIX_IOT_SYS_TYPE_DEF_H_ + +#include +#include + +// typedef unsigned char GBOOL; +// typedef char GCHAR; +// typedef unsigned char GUCHAR; +// typedef signed char GS8; +// typedef unsigned char GU8; + +// typedef signed short GS16; +// typedef unsigned short GU16; + +// typedef signed int GS32; +// typedef unsigned int GU32; + +// typedef signed long long GS64; +// typedef unsigned long long GU64; + +// typedef float GF32; +// typedef double GF64; +// typedef long double GF128; + +#if (_WIN32 || _WIN64) +#define DEBUG_HRV 1 +#endif + +/* ��ӡ���� */ +#define IOT_SYS_DEBUG 1 + +#if defined(_WIN32) || defined(_WIN64) +#define USE_MEMPOOL 1 +#else +#define USE_MEMPOOL 0 +#endif +#define UPDATEMEMINFO() +#if defined(_WIN32) || defined(_WIN64) + +#if USE_MEMPOOL +#ifdef UPDATEMEMINFO() +#undef UPDATEMEMINFO() +#endif +#include "goodix_memusage.h" +#if DEBUG_MEMUSAGE +#define IOT_SYS_REALLOC(p,x) MEMSTAT_REALLOC(p,x) +#define IOT_SYS_MALLOC(x) MEMSTAT_MALLOC(x) +#define IOT_SYS_FREE(x) MEMSTAT_FREE(x) +#define IOT_SYS_MEM_INIT(p,x) GD_MEM_INIT((p),(x)); MEMSTAT_INIT(p); +#define IOT_SYS_MEM_DESTORY() GD_MEM_DESTORY(); MEMSTAT_COMP(); +#else +#define IOT_SYS_MEM_INIT(p,x) GD_MEM_INIT((p),(x)); +#define IOT_SYS_MEM_DESTORY() GD_MEM_DESTORY(); +#define IOT_SYS_MALLOC(x) GD_MEM_MALLOC(x) +#define IOT_SYS_FREE(x) GD_MEM_FREE(x) +#define IOT_SYS_REALLOC(p,x) GD_MEM_REALLOC(p,x) +#endif + +#else //USE_MEMPOOL +#include +#ifndef IOT_SYS_MALLOC +#define IOT_SYS_MALLOC malloc +#endif +#ifndef IOT_SYS_FREE +#define IOT_SYS_FREE free +#endif +#endif //!USE_MEMPOOL + +#ifndef IOT_SYS_DLL_API +#define IOT_SYS_DLL_API extern _declspec(dllexport) +#endif + +#if IOT_SYS_DEBUG +#include +#ifndef IOT_SYS_PRINT +#define IOT_SYS_PRINT printf +#endif +#endif + +#elif defined(__linux__) || defined(ANDROID) +#include +#ifndef IOT_SYS_MALLOC +#define IOT_SYS_MALLOC malloc +#endif +#ifndef IOT_SYS_FREE +#define IOT_SYS_FREE free +#endif +#ifndef IOT_SYS_DLL_API +#define IOT_SYS_DLL_API +#endif + +#ifndef __ANDROID_NATIVE__ // for app +#include +#ifndef IOT_SYS_LOG_TAG +#define IOT_SYS_LOG_TAG "IoTSys" +#ifndef IOT_SYS_PRINT +#define IOT_SYS_PRINT(...) __android_log_print(ANDROID_LOG_DEBUG, IOT_SYS_LOG_TAG, __VA_ARGS__) +#endif +#endif +#else // for exe on cell phone +#ifndef IOT_SYS_PRINT +#define IOT_SYS_PRINT printf +#endif +#endif + +#else +/* +* Roma-II +*/ +//extern void *GmAlgMemMalloc(GU32 unSize); +//extern void GmAlgMemFree(void *pmemaddr); +// +//#define IOT_SYS_MALLOC(x) GmAlgMemMalloc((x)) +//#define IOT_SYS_FREE(p) GmAlgMemFree((p)) +//#define IOT_SYS_DLL_API + +/* +* Cardiff +*/ +extern void* goodix_mem_malloc(int32_t size); +extern void goodix_mem_free(void* mem_addr); + +#ifndef IOT_SYS_MALLOC +#define IOT_SYS_MALLOC(x) goodix_mem_malloc((x)) +#endif +#ifndef IOT_SYS_FREE +#define IOT_SYS_FREE(p) goodix_mem_free((p)) +#endif +#ifndef IOT_SYS_DLL_API +#define IOT_SYS_DLL_API +#endif + +#if IOT_SYS_DEBUG +/* extern log function */ +extern void GH3X2X_PlatformLog(char *chLogString); + +/// log support len +#define GH3X2X_LOG_DEBUG_SUP_LEN (128) + +/// log string with param +#define GH3X2X_DEBUG_LOG_PARAM(...) do {\ + char chDebugStr[GH3X2X_LOG_DEBUG_SUP_LEN] = {0};\ + snprintf(chDebugStr, GH3X2X_LOG_DEBUG_SUP_LEN, \ + "[gh3x2x_drv]: "__VA_ARGS__);\ + GH3X2X_PlatformLog(chDebugStr);\ + } while (0) + +#ifndef IOT_SYS_PRINT +#define IOT_SYS_PRINT GH3X2X_DEBUG_LOG_PARAM +#endif +#endif + +#endif + +// ����궨�� +#define SINGLE_PRECISION_SUPPORT // ����ɿ�ʱʹ�ܣ���VS�����У�Ӱ�� LMS_FILTER_STEP_FACTOR������VS��MCU�Բ��� + +/********END OF FILE********* (C) COPYRIGHT 2015-2025 .********/ +#endif //_GOODIX_IOT_SYS_TYPE_DEF_H_ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_adt.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_adt.c new file mode 100644 index 000000000..9f6ccc7e1 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_adt.c @@ -0,0 +1,154 @@ +#include +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" + +#if (__USE_GOODIX_ADT_ALGORITHM__) + +#define __HARD_ADT_WAER_ON_THRD__ 9000000 +#define __HARD_ADT_WAER_OFF_THRD__ 8800000 +#define __HARD_ADT_WAER_ON_DIFF_THRD__ -8000000 +#define __HARD_ADT_WAER_BIG_DIFF__ 30000 +#define GH3X2X_MOVINF_AVA_WINDOW_SIZE 6 + +static EMWearDetectType g_emAlgoWearStatus = WEAR_DETECT_WEAR_ON; +static GU32 g_punGh3x2xMovingAvaFilterBuf[GH3X2X_MOVINF_AVA_WINDOW_SIZE]; +static GU8 g_uchGh3x2xMovingAvaFilterPointCnt; + + + +void Gh3x2xMovingAvaFilterInit(void) +{ + g_uchGh3x2xMovingAvaFilterPointCnt = 0; +} + +GU8 Gh3x2xMovingAvaFilter(GU32 *Rawdata, GU8 uchBypass) +{ + GU32 unSum = 0; + + if(uchBypass) + { + return 1; + } + else + { + if(g_uchGh3x2xMovingAvaFilterPointCnt >= GH3X2X_MOVINF_AVA_WINDOW_SIZE) + { + for(GU8 uchCnt = 1; uchCnt < GH3X2X_MOVINF_AVA_WINDOW_SIZE; uchCnt ++) + { + g_punGh3x2xMovingAvaFilterBuf[uchCnt - 1] = g_punGh3x2xMovingAvaFilterBuf[uchCnt]; + } + g_uchGh3x2xMovingAvaFilterPointCnt = GH3X2X_MOVINF_AVA_WINDOW_SIZE - 1; + } + g_punGh3x2xMovingAvaFilterBuf[g_uchGh3x2xMovingAvaFilterPointCnt] = Rawdata[0]; + g_uchGh3x2xMovingAvaFilterPointCnt ++; + + if(g_uchGh3x2xMovingAvaFilterPointCnt > 1) + { + for(GU8 uchCnt = 0; uchCnt < g_uchGh3x2xMovingAvaFilterPointCnt - 1; uchCnt ++) + { + unSum += g_punGh3x2xMovingAvaFilterBuf[uchCnt]; + } + Rawdata[0] = unSum/(g_uchGh3x2xMovingAvaFilterPointCnt - 1); + } + return 1; + } +} + +#define ADT_CHECK_ALGO_VERSION "GX_HARDADT_SOFTCHECK_v0.1" + +GU8* GH3x2xAdtVersion (void) +{ + return (GU8*)ADT_CHECK_ALGO_VERSION; +} + +GS8 GH3x2xAdtAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + Gh3x2xMovingAvaFilterInit(); + g_emAlgoWearStatus = WEAR_DETECT_WEAR_ON; + return GH3X2X_RET_OK; +} + +GS8 GH3x2xAdtAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + Gh3x2xMovingAvaFilterInit(); + g_emAlgoWearStatus = WEAR_DETECT_WEAR_ON; + return GH3X2X_RET_OK; +} + +GS8 GH3x2xAdtAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GU32 unCurrentFrameRawdata = 0; + GS32 snDiffRawdata = 0; + GU32 unRawDataBeforeFilter = 0; + + unCurrentFrameRawdata = pstFrameInfo->punFrameRawdata[0]; + unRawDataBeforeFilter = pstFrameInfo->punFrameRawdata[0]; + GH3X2X_DEBUG_ALGO_LOG("[GH3x2xAdtAlgoExe]:punFrameRawdata = %d\r\n", unCurrentFrameRawdata); + Gh3x2xMovingAvaFilter(&unCurrentFrameRawdata, 0); + GH3X2X_DEBUG_ALGO_LOG("[GH3x2xAdtAlgoExe]:punFrameRawdata after filter = %d\r\n", unCurrentFrameRawdata); + GH3X2X_DEBUG_ALGO_LOG("[GH3x2xAdtAlgoExe]:g_emAlgoWearStatus = %d, start check...\r\n",g_emAlgoWearStatus); + + snDiffRawdata = (GS32)unRawDataBeforeFilter - (GS32)unCurrentFrameRawdata; + pstFrameInfo->pstAlgoResult->snResult[0] = ADT_ALGO_RESULT_DEFULT; + + + if(WEAR_DETECT_WEAR_ON == g_emAlgoWearStatus) + { + #if (__HARD_ADT_WAER_OFF_THRD__ > __HARD_ADT_WAER_ON_THRD__) //penetration model + if(unRawDataBeforeFilter < __HARD_ADT_WAER_ON_THRD__) + #else //reflex model + if((unRawDataBeforeFilter > __HARD_ADT_WAER_ON_THRD__)&&((snDiffRawdata > (GS32)__HARD_ADT_WAER_ON_DIFF_THRD__))) + #endif + { + g_emAlgoWearStatus = WEAR_DETECT_WEAR_OFF; + GH3X2X_INFO_ALGO_LOG("[GH3x2xAdtAlgoExe]:wear on event, Rawdata = %d, unRawdataDiff = %d\r\n",unCurrentFrameRawdata,snDiffRawdata); + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->snResult[0] = ADT_ALGO_RESULT_WAER_ON; + } + else + { + #if (__HARD_ADT_WAER_OFF_THRD__ > __HARD_ADT_WAER_ON_THRD__) //penetration model + #else //reflex model + if(unRawDataBeforeFilter > __HARD_ADT_WAER_ON_THRD__) + { + GH3X2X_INFO_ALGO_LOG("[GH3x2xAdtAlgoExe]:wear on condition is not match ! r = %d, r_diff = %d\r\n",unCurrentFrameRawdata,snDiffRawdata); + } + #endif + } + #if (__HARD_ADT_WAER_OFF_THRD__ > __HARD_ADT_WAER_ON_THRD__) //penetration model + #else //reflex model + if(snDiffRawdata > __HARD_ADT_WAER_BIG_DIFF__) + { + //pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + //pstFrameInfo->pstAlgoResult->snResult[0] = ADT_ALGO_RESULT_DIFF_BIG; + GH3X2X_INFO_ALGO_LOG("[GH3x2xAdtAlgoExe]:ppg 5Hz diff big event, Rawdata = %d, unRawdataDiff = %d\r\n",unCurrentFrameRawdata,snDiffRawdata); + } + #endif + } + else if(WEAR_DETECT_WEAR_OFF == g_emAlgoWearStatus) + { + #if (__HARD_ADT_WAER_OFF_THRD__ > __HARD_ADT_WAER_ON_THRD__) //penetration model + if(unRawDataBeforeFilter > __HARD_ADT_WAER_OFF_THRD__) + #else //reflex model + if(unRawDataBeforeFilter < __HARD_ADT_WAER_OFF_THRD__) + #endif + { + g_emAlgoWearStatus = WEAR_DETECT_WEAR_ON; + GH3X2X_INFO_ALGO_LOG("[GH3x2xAdtAlgoExe]:wear off event, Rawdata = %d, unRawdataDiff = %d\r\n",unCurrentFrameRawdata,snDiffRawdata); + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->snResult[0] = ADT_ALGO_RESULT_WAER_OFF; + } + } + + pstFrameInfo->pstAlgoResult->usResultBit = 0x7; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + pstFrameInfo->pstAlgoResult->snResult[1] = snDiffRawdata; + pstFrameInfo->pstAlgoResult->snResult[2] = pstFrameInfo->punFrameCnt[0]; + GH3X2X_AdtAlgorithmResultReport(pstFrameInfo->pstAlgoResult, pstFrameInfo->punFrameCnt[0]); + + return GH3X2X_RET_OK; +} + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_af.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_af.c new file mode 100644 index 000000000..3fc2c65ee --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_af.c @@ -0,0 +1,124 @@ +#include +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" +#include "goodix_hba.h" +#include "goodix_hrv.h" +#include "goodix_af.h" + +#if (__USE_GOODIX_HRV_ALGORITHM__ && __USE_GOODIX_AF_ALGORITHM__) + +extern GU32 g_unHrvLastHrResult; +extern goodix_hrv_ret goodix_hrv_init_func(GU32 fs); +extern goodix_hrv_ret goodix_hrv_deinit_func(void); + +GS8 GH3x2xAfAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + for (GU8 uchChMapCnt = 0; uchChMapCnt < g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_AF]->pstFunctionInfo->uchChnlNum; ++uchChMapCnt) + { + g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_RESP]->puchFrameLastGain[uchChMapCnt] = GH3X2X_GAIN_VALUE_INVALID; + } + GH3X2X_INFO_ALGO_LOG("[%s]:params = %d,\r\n", __FUNCTION__, g_nAfParamsArr[0]); + if ((AFInit((GS32)g_nAfParamsArr[0]) == GX_ALGO_HBA_SUCCESS) &&\ + (goodix_hrv_init_func(pstFrameInfo ->pstFunctionInfo ->usSampleRate) == GX_ALGO_HBA_SUCCESS)) + { + pstFrameInfo->pstAlgoResult->usResultBit = 0xFF; + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("af deinit error!\r\n"); + } + g_unHrvLastHrResult = 0; + return chRet; +} + +GS8 GH3x2xAfAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + if ((goodix_hrv_deinit_func() == GX_ALGO_HBA_SUCCESS) && (AFDeInit() == GX_ALGO_HBA_SUCCESS)) + { + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("af deinit error!\r\n"); + } + return chRet; +} + +GS8 GH3x2xAfAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + if(0 == pstFrameInfo ) + { + return GH3X2X_RET_GENERIC_ERROR; + } + GU32 unResult[3] = {0}; + GS32 nOutputData[6] = {0}; + GS32 nAfInputData[6] = {0}; + ST_HRV_INPUT_INFO siRawdataInput; + memset((GU8*)&siRawdataInput, 0, sizeof(ST_HRV_INPUT_INFO)); + GU8 uchGainValue = 0; + + for (int nRawdatacnt = 0 ; nRawdatacnt< HRV_CHNL_MAX_NUM ; nRawdatacnt ++) + { + siRawdataInput.ppg_green[nRawdatacnt] = GH3X2X_RAWDATA_CLEAR_ALL_FLAG(pstFrameInfo->punFrameRawdata[nRawdatacnt]); + siRawdataInput.ppg_green[nRawdatacnt] = GH3X2X_GET_RAWDATA_FOR_ALGO(siRawdataInput.ppg_green[nRawdatacnt]); + uchGainValue = GH3X2X_GET_LOW_4BITS(pstFrameInfo->punFrameAgcInfo[nRawdatacnt]); + if ((pstFrameInfo->puchFrameLastGain[nRawdatacnt] != uchGainValue) && \ + (pstFrameInfo->puchFrameLastGain[nRawdatacnt] != GH3X2X_GAIN_VALUE_INVALID)) + { + siRawdataInput.green_gain_adj_flag[nRawdatacnt] = 1; + pstFrameInfo->puchFrameLastGain[nRawdatacnt] = uchGainValue; + } + + siRawdataInput.green_cur_adj_flag[nRawdatacnt] = ((pstFrameInfo->punFrameFlag[0]) & 0x01); + } + siRawdataInput.acc_x = pstFrameInfo->pusFrameGsensordata[0]; + siRawdataInput.acc_y = pstFrameInfo->pusFrameGsensordata[1]; + siRawdataInput.acc_z = pstFrameInfo->pusFrameGsensordata[2]; + siRawdataInput.frame_id = GH3X2X_GET_BYTE0_FROM_DWORD(*(pstFrameInfo->punFrameCnt)); + if (g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->uchUpdateFlag) + { + g_unHrvLastHrResult = g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->snResult[0]; + } + siRawdataInput.hr = g_unHrvLastHrResult; + + GU8 uchHrvUpdateFlag = HRVCalculateAlgo(&siRawdataInput, nOutputData); + + if (uchHrvUpdateFlag && (nOutputData[5] != 0)) + { + for (int i = 0 ; i < 6 ; i ++) + { + nAfInputData[i] = nOutputData[i]; + } + + pstFrameInfo->pstAlgoResult->uchUpdateFlag = AF_Detection_Module(nAfInputData, unResult); + + if(pstFrameInfo->pstAlgoResult->uchUpdateFlag == 1) + { + pstFrameInfo->pstAlgoResult->snResult[0] = (GS32)unResult[0]; + pstFrameInfo->pstAlgoResult->snResult[1] = (GS32)unResult[1]; + pstFrameInfo->pstAlgoResult->snResult[2] = (GS32)unResult[2]; + pstFrameInfo->pstAlgoResult->snResult[3] = (GS32)nOutputData[0]; + pstFrameInfo->pstAlgoResult->snResult[4] = (GS32)nOutputData[1]; + pstFrameInfo->pstAlgoResult->snResult[5] = (GS32)nOutputData[2]; + pstFrameInfo->pstAlgoResult->snResult[6] = (GS32)nOutputData[3]; + pstFrameInfo->pstAlgoResult->snResult[7] = (GS32)nOutputData[4]; + pstFrameInfo->pstAlgoResult->usResultBit = 0xFF; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + GH3X2X_DEBUG_ALGO_LOG("[%s]af = %d,UpdateFlag = %d\r\n",__FUNCTION__,(int)pstFrameInfo->pstAlgoResult->snResult[0],(int)pstFrameInfo->pstAlgoResult->uchUpdateFlag); + //GH3X2X_HrAlgorithmResultReport(pstFrameInfo->pstAlgoResult,stRawdata.frameid); + } + } + return GH3X2X_RET_OK; +} + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_bt.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_bt.c new file mode 100644 index 000000000..2e1d806f5 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_bt.c @@ -0,0 +1,293 @@ +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_call.h" +#include "goodix_mem.h" +#include "goodix_algo.h" +#include "goodix_algo_bt.h" + +#if (__USE_GOODIX_BT_ALGORITHM__) + +#define NTCSecondResult 0 + +/*****体温全局变量*****/ +//NTC R-T table +#define NTC_TYPE CB62K552D +#if (CB62K928D==NTC_TYPE) +GU16 RT_Table[] = {25992,24742,23559,22437,21375,20367,19413,18507,17648,16833,16060,15325,14628,13965,13336,12738,12169,11629,11115,10625,10160,9717,9295,8894,8512,8147,7800,7469,7154,6853,6566,6293,6032,5783,5545,5318,5101,4894,4696,4507}; +#elif(CB62K552D==NTC_TYPE) +GU16 RT_Table[] = {25837,24594,23418,22303,21247,20246,19297,18397,17543,16733,15964,15234,14540,13882,13256,12662,12097,11559,11048,10562,10099,9659,9240,8841,8461,8099,7754,7425,7111,6812,6527,6255,5996,5748,5512,5286,5071,4865,4668,4480}; +#elif(DT104D3950==NTC_TYPE) +GU16 RT_Table[] = {26630,25340,24130,22980,21890,20850,19880,18950,18070,17240,16450,15700,14990,14320,13680,13070,12490,11940,11420,10920,10450,10000,9572,9165,8777,8408,8056,7720,7401,7096,6805,6528,6263,6011,5769,5539,5319,5109,4908,4717}; +#endif +GU16 unSensorNtcRT_Len = sizeof(RT_Table)/sizeof(RT_Table[0]); +GU16 unSensorNtcRef = 3000; // NTC ref resistance (unit : 10ohm) +GS16 unTempRangeLower = 4*100; +GS16 unTempRangeUpper = 43*100; +GU8 unNTCChnalRes = 156; +GU32 g_unBtLastHrResult = 0; +GU16 uFs =0; + +#if !__USE_GOODIX_DRV_NTC_Convert +STGoodixAlgorithmBtControlConfigParametersBuffer gstBtCFG; +STGoodixAlgorithmBtInputRef gstBtInputRef; +STGoodixAlgorithmBtCalculateOutputResult gstBtAlgoOUT; +//STGoodixAlgorithmBtFinalOutputResult gstBtAlgoFinal; +STGoodixAlgorithmInfo gstBtAlgoInfo; +/** + * @brief memory malloc function + * @param size + * @return pointer of memory +*/ +void* GoodixSensorAlgoMalloc(GS32 size) +{ + return goodix_mem_malloc(size); +} + +/** + * @brief memory free function + * @param addr +*/ +void GoodixSensorAlgoFree(void* addr) +{ + goodix_mem_free(addr); +} + +/** + * @brief algorithm log function + * @param addr +*/ +void GoodixSensorAlgoLog(GCHAR* pLogStr) +{ + //GH3X2X_DEBUG_ALGO_LOG("[%s]:%s\n", __FUNCTION__, pLogStr); +} + +#else +STGH3x2xDrvBtOutputResult gstDrvBtOutRes; + +GU16 GetRTIndex(GS32 R, GU16* pR, GU16 len) +{ + GU16 i =0; + while(R <= pR[i]*10) + { + i++; + if(len == i) + { + i = 0xFFFF; + break; + } + } + return i; +} + +/** + * @fn GS16 GH3x2xBtRTConvert(GS32* pnRawdata,STGH3x2xDrvBtOutputResult* pstDrvBtOutRes) + * + * @brief calc byte check rawdata + * + * @attention + * + * @param[in] punRawdata one rawdata addr IDEL REF NTC0 NTC1 + * @param[out] None + * + * @return target rawdata + */ +static GS16 GH3x2xBtRTConvert(GS32* pnRawdata,STGH3x2xDrvBtOutputResult* pstDrvBtOutRes) +{ + GU8 uchIdx = 0; + GU16 uRTIdx =0; + GS32 nRestemp0, nRestemp1; + GS16 nRawTemp =0; + GU8 chRet=0; + + for(uchIdx=0;uchIdx nFrameTemperature[uchIdx] = nRawTemp; + if(0 == pstDrvBtOutRes->chFrameIndex) + { + pstDrvBtOutRes->stRawTemp[uchIdx].nMin = nRawTemp; + pstDrvBtOutRes->stRawTemp[uchIdx].nMax = nRawTemp; + pstDrvBtOutRes->stRawTemp[uchIdx].nSum = nRawTemp; + GH3X2X_DEBUG_ALGO_LOG("[%s]:index: %d rawdata sum %d: %d \n", __FUNCTION__,pstDrvBtOutRes->chFrameIndex,uchIdx, pstDrvBtOutRes->stRawTemp[uchIdx].nSum); + } + else + { + pstDrvBtOutRes->stRawTemp[uchIdx].nMin = (pstDrvBtOutRes->stRawTemp[uchIdx].nMin>nRawTemp)?nRawTemp:pstDrvBtOutRes->stRawTemp[uchIdx].nMin; + pstDrvBtOutRes->stRawTemp[uchIdx].nMax = (pstDrvBtOutRes->stRawTemp[uchIdx].nMaxstRawTemp[uchIdx].nMax; + pstDrvBtOutRes->stRawTemp[uchIdx].nSum += nRawTemp; + GH3X2X_DEBUG_ALGO_LOG("[%s]:index: %d rawdata sum %d: %d \n", __FUNCTION__,pstDrvBtOutRes->chFrameIndex,uchIdx, pstDrvBtOutRes->stRawTemp[uchIdx].nSum); + } + } + ++pstDrvBtOutRes->chFrameIndex; + if(pstDrvBtOutRes->chFrameIndex == uFs) + { + pstDrvBtOutRes->chFrameIndex=0; + for(uchIdx=0;uchIdx nSecTemperature[uchIdx] = 0; + } + else + { + if(uFs>2) + { + GH3X2X_DEBUG_ALGO_LOG("[%s]:rawdata sum: %d \n", __FUNCTION__, pstDrvBtOutRes->stRawTemp[uchIdx].nSum); + pstDrvBtOutRes->nSecTemperature[uchIdx] = (pstDrvBtOutRes->stRawTemp[uchIdx].nSum - pstDrvBtOutRes->stRawTemp[uchIdx].nMin - pstDrvBtOutRes->stRawTemp[uchIdx].nMax +((uFs-2)>>1))/(uFs-2); + } + else + { + pstDrvBtOutRes->nSecTemperature[uchIdx] = (pstDrvBtOutRes->stRawTemp[uchIdx].nMin + pstDrvBtOutRes->stRawTemp[uchIdx].nMax)>>1; + } + chRet = EM_CONVER_OK; + } + } + } + + return chRet; +} +#endif + +GS8 GH3x2xBtAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + #if !__USE_GOODIX_DRV_NTC_Convert + //gstBtAlgoInfo.stAlgorithmConfig.pnParametersBuffer = &gstBtCFG; + gstBtAlgoInfo.stAlgorithmCalcOutput.pnResult = &gstBtAlgoOUT; + gstBtAlgoInfo.stAlgorithmCalcInput.pnRefBuffer = &gstBtInputRef; + gstBtCFG.unChannelNum = 2; + + if(BT_ERRORCODE_OK != GoodixBtAlgoInit(&gstBtAlgoInfo)) + { + return GH3X2X_RET_GENERIC_ERROR; + } + + pstFrameInfo->pstAlgoResult->usResultBit = 0x1F; + g_unBtLastHrResult = 0; + uFs = pstFrameInfo ->pstFunctionInfo ->usSampleRate; + GH3X2X_Memset(&gstBtAlgoOUT, 0, sizeof(STGoodixAlgorithmBtCalculateOutputResult)); + GH3X2X_Memset(&gstBtInputRef, 0, sizeof(STGoodixAlgorithmBtInputRef)); + #else + //drv calculate bt + GH3X2X_Memset(&gstDrvBtOutRes, 0, sizeof(STGH3x2xDrvBtOutputResult)); + //GH3X2X_Memcpy(RT_Table, g_nBtParamsArr, GOODIX_BT_PARAMS_NUM_MAX * sizeof(GU16)); + //unSensorNtcRT_Len = sizeof(RT_Table)/sizeof(RT_Table[0]); + #endif + return GH3X2X_RET_OK; +} + +GS8 GH3x2xBtAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + #if !__USE_GOODIX_DRV_NTC_Convert + if(BT_ERRORCODE_OK != GoodixBtAlgoDeinit(&gstBtAlgoInfo)) + { + return GH3X2X_RET_GENERIC_ERROR; + } + #endif + return GH3X2X_RET_OK; +} + +GS8 GH3x2xBtAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS32 TempRawdata[4] = {0}; + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + for(GU8 i = 0; i < 4; i++) + { + TempRawdata[i] = (int)(pstFrameInfo->pstFrameTempdata->unTempData[i]); + } + + if (g_uchAlgoTempEnable == 0) + { + for(GU8 i = 0; i < 4; i++) + { + TempRawdata[i] = (int)(pstFrameInfo->punFrameRawdata[i]); + } + } +#if !__USE_GOODIX_DRV_NTC_Convert + gstBtAlgoInfo.stAlgorithmCalcInput.pnRawdata = TempRawdata; + + if (g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->uchUpdateFlag) + { + g_unBtLastHrResult = g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->snResult[0]; + } + gstBtInputRef.unHR = g_unBtLastHrResult; + + //GH3X2X_DEBUG_ALGO_LOG("[%s]:%d,%d,%d,%d\n", __FUNCTION__, gstBtAlgoInfo.stAlgorithmCalcInput.pnRawdata[0], gstBtAlgoInfo.stAlgorithmCalcInput.pnRawdata[1], gstBtAlgoInfo.stAlgorithmCalcInput.pnRawdata[2], gstBtAlgoInfo.stAlgorithmCalcInput.pnRawdata[3]); + + + if(BT_ERRORCODE_OK == GoodixBtAlgoCalculate(&gstBtAlgoInfo)) + { + //if(gstBtAlgoOUT.uchRefresh) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->usResultBit = 0x3F; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + if (0!=gstBtAlgoInfo.stAlgorithmCalcOutput.pnMiddleBaseBuffer) + { + for (int i =0; i < 2; i++) + { + pstFrameInfo->pstAlgoResult->snResult[i] = gstBtAlgoInfo.stAlgorithmCalcOutput.pnMiddleBaseBuffer[i];//ntc0 + //pstFrameInfo->pstAlgoResult->snResult[1] = gstBtAlgoOUT.nFPCBT;//ntc1 + } + } + pstFrameInfo->pstAlgoResult->snResult[2] = gstBtAlgoOUT.uchState; + pstFrameInfo->pstAlgoResult->snResult[3] = gstBtAlgoOUT.uchConfidence; + pstFrameInfo->pstAlgoResult->snResult[4] = gstBtAlgoOUT.nCBT; + pstFrameInfo->pstAlgoResult->snResult[5] = g_unBtLastHrResult; + } + chRet = GH3X2X_RET_OK; + } +#else + // drv calculate bt + chRet =GH3x2xBtRTConvert( TempRawdata, &gstDrvBtOutRes); + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->usResultBit = 0x03; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + for (int i =0; i < 2; i++) + { + #if NTCSecondResult + pstFrameInfo->pstAlgoResult->snResult[i] = gstDrvBtOutRes.nSecTemperature[i];//ntc0 ntc1 per second + GH3X2X_DEBUG_ALGO_LOG("[%s]:rawdata: %d %d %d %d.second temp: %d %d\n", __FUNCTION__, TempRawdata[0],TempRawdata[1],TempRawdata[2],TempRawdata[3],gstDrvBtOutRes.nSecTemperature[0],gstDrvBtOutRes.nSecTemperature[1]); + #else + pstFrameInfo->pstAlgoResult->snResult[i] = gstDrvBtOutRes.nFrameTemperature[i];//ntc0 ntc1 per frame + GH3X2X_DEBUG_ALGO_LOG("[%s]:rawdata: %d %d %d %d.frame temp: %d %d\n", __FUNCTION__, TempRawdata[0],TempRawdata[1],TempRawdata[2],TempRawdata[3],gstDrvBtOutRes.nFrameTemperature[0],gstDrvBtOutRes.nFrameTemperature[1]); + #endif + } +#endif + return chRet; +} + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_ecg.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_ecg.c new file mode 100644 index 000000000..7fdbfbdfe --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_ecg.c @@ -0,0 +1,207 @@ + +#include +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" +#include "goodix_ecg.h" + +#if (__USE_GOODIX_ECG_ALGORITHM__) + +#define GH3X2X_SINGLE_CLASSIFICATION_TIME 32 + +goodix_ecg_ret goodix_ecg_init_func(GU32 fs) +{ + goodix_ecg_config stEcgCfg = {0}; + goodix_ecg_init_result stInitResult = {0}; + GCHAR uchEcgVersion[100] = {0}; + + goodix_ecg_version((uint8_t*)uchEcgVersion); + GH3X2X_DEBUG_ALGO_LOG("ecg algorithm version : %s\r\n", uchEcgVersion); + +#if (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_500FS_QRS_ENABLE) || (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_500FS_QRS_DISABLE) + if (500 != fs) + { + GH3X2X_DEBUG_ALGO_LOG("[%s] fail! The sampling rate(%d) does not match the macro settings.\r\n", __FUNCTION__, fs); + return GX_ALGO_ECG_RWONG_INPUT; + } +#elif (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_250FS_QRS_ENABLE) || (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_250FS_QRS_DISABLE) + if (250 != fs) + { + GH3X2X_DEBUG_ALGO_LOG("[%s] fail! The sampling rate(%d) does not match the macro settings.\r\n", __FUNCTION__, fs); + return GX_ALGO_ECG_RWONG_INPUT; + } +#else +#error "please define __GOODIX_ECG_ALGO_CONFIG__ in gh3x2x_demo_algo_config.h !" +#endif + +#if (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_500FS_QRS_ENABLE) || (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_250FS_QRS_ENABLE) + stEcgCfg.qrs_flag = 1; +#elif (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_500FS_QRS_DISABLE) || (__GOODIX_ECG_ALGO_CONFIG__ == GOODIX_ECG_ALGO_250FS_QRS_DISABLE) + stEcgCfg.qrs_flag = 0; +#else +#error "please define __GOODIX_ECG_ALGO_CONFIG__ in gh3x2x_demo_algo_config.h !" +#endif + + stEcgCfg.fs = fs; + stEcgCfg.valid_channel_num = (uint32_t)g_nEcgParamsArr[1]; + stEcgCfg.mode_type = (uint32_t)g_nEcgParamsArr[3]; + stEcgCfg.ic_type = (uint32_t)g_nEcgParamsArr[4]; + + GH3X2X_INFO_ALGO_LOG("[%s]:params = %d,%d,%d,%d,%d\r\n", __FUNCTION__, + stEcgCfg.fs, + stEcgCfg.valid_channel_num, + stEcgCfg.qrs_flag, + stEcgCfg.mode_type, + stEcgCfg.ic_type); + + const void *p_CfgInstance = (void *)&stEcgCfg; + char chVer[ECG_INTERFACE_VERSION_LEN_MAX] = {0}; + + goodix_ecg_config_get_version(chVer, ECG_INTERFACE_VERSION_LEN_MAX); + const char *p_InterfaceVer = chVer; + + goodix_ecg_ret ret = goodix_ecg_init(p_CfgInstance, &stInitResult, sizeof(stEcgCfg), p_InterfaceVer); + g_uchClassificationFlag = 0; + g_unEcgTimeSeconds = 0; + + return ret; +} + +goodix_ecg_ret goodix_ecg_deinit_func(void) +{ + return goodix_ecg_deinit(); +} + +GS8 GH3x2xEcgAlgoInit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GU16 usSampleRate = pstFrameInfo->pstFunctionInfo->usSampleRate; + + goodix_ecg_ret ret = goodix_ecg_init_func(usSampleRate); + if (GX_ALGO_ECG_SUCCESS == ret) + { + chRet = GH3X2X_RET_OK; + } + else + { + chRet = GH3X2X_RET_PARAMETER_ERROR; + GH3X2X_DEBUG_ALGO_LOG("ecg init error! ret = 0x%x\r\n", ret); + } + g_unEcgFrameCnt = 0; + GH3X2X_SetNewDataFlag(GH3X2X_FUNC_OFFSET_ECG, GH3X2X_IS_NEW_RAWDATA); + + *(pstFrameInfo->punFrameCnt) = 0; + + return chRet; +} + +GS8 GH3x2xEcgAlgoDeinit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + goodix_ecg_ret ret = goodix_ecg_deinit_func(); + if (ret == GX_ALGO_ECG_SUCCESS) + { + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("ecg deinit error! ret = 0x%x\r\n", ret); + } + + return chRet; +} + +GS8 GH3x2xEcgAlgoExe(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + if (0 == pstFrameInfo) + { + return GH3X2X_RET_GENERIC_ERROR; + } + + goodix_ecg_input_rawdata stRawdata = {0}; + goodix_ecg_result stResult; + GS8 chAlgoRet = 0; + GU32 unRawdata[ECG_CHANNEL_NUM] = {0}; + GF32 fEcgOutData[ECG_CHANNEL_NUM] = {0}; + goodix_stage unEcgStage[ECG_CHANNEL_NUM] = {stage_noneffect_out, stage_noneffect_out}; + GF32 fEcgSnr[ECG_CHANNEL_NUM] = {0}; + GF32 fEcgPowerLineOut[ECG_CHANNEL_NUM] = {0}; + GF32 fEcgBlwOut[ECG_CHANNEL_NUM] = {0}; + GF32 fEcgBpmCh[ECG_CHANNEL_NUM] = {0}; + + stResult.ecg_out = fEcgOutData; + stResult.ecg_stage = unEcgStage; + stResult.ecg_snr = fEcgSnr; + stResult.ecg_powerline_out = fEcgPowerLineOut; + stResult.ecg_blw_out = fEcgBlwOut; + stResult.ecg_bpm_ch = fEcgBpmCh; + + stRawdata.ecg_rawdata = (GS32 *)&unRawdata; + stRawdata.frameid = GH3X2X_GET_BYTE0_FROM_DWORD(*(pstFrameInfo->punFrameCnt)); + stRawdata.acc_x = pstFrameInfo->pusFrameGsensordata[0]; + stRawdata.acc_y = pstFrameInfo->pusFrameGsensordata[1]; + stRawdata.acc_z = pstFrameInfo->pusFrameGsensordata[2]; + stRawdata.ecg_rawdata[0] = pstFrameInfo->punFrameRawdata[0]; + stRawdata.ecg_rawdata[1] = pstFrameInfo->punFrameRawdata[1]; + stRawdata.ecg_qc_flag = GH3X2X_CHECK_BIT_IS_SET(pstFrameInfo->punFrameFlag[2], 0x01); + GH3X2X_DEBUG_ALGO_LOG("[%s]ecg ecg_rawdata = %d, %d, ecg_qc_flag = %d\r\n", __FUNCTION__, stRawdata.ecg_rawdata[0], stRawdata.ecg_rawdata[1], \ + stRawdata.ecg_qc_flag); + + if (g_unEcgFrameCnt <= ECG_FRAME_UNUSED) /* the first 5 frame data can't be used for algo */ + { + g_unEcgFrameCnt++; + stRawdata.ecg_qc_flag = 1; + } + + if (1 == stRawdata.ecg_qc_flag) /* when fast recovery,data can't be used for algo */ + { + return chAlgoRet; + } + + goodix_ecg_ret stRet = goodix_ecg_update(&stRawdata, &stResult); + + if (stRet == GX_ALGO_ECG_SUCCESS) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->snResult[0] = GH3x2x_Round(stResult.ecg_out[0] * ECG_OUT_FACTOR); + pstFrameInfo->pstAlgoResult->snResult[2] = GH3x2x_Round(stResult.ecg_out[1] * ECG_OUT_FACTOR); + + GH3X2X_DEBUG_ALGO_LOG("ecg out0 = %.3f\r\n", stResult.ecg_out[0]); + GH3X2X_DEBUG_ALGO_LOG("ecg out1 = %.3f\r\n", stResult.ecg_out[1]); + //GH3X2X_INFO_ALGO_LOG("bpm result = %d\r\n",(GS32)(stResult.ecg_bpm + 0.5f)); + + pstFrameInfo->pstAlgoResult->snResult[1] = (GS32)(stResult.ecg_bpm + 0.5f); + pstFrameInfo->pstAlgoResult->usResultBit = 0x1 | \ + ((0x1 << 1) * (pstFrameInfo->pstAlgoResult->snResult[1] != 0)) | \ + ((0x1 << 2) * (g_nEcgParamsArr[1] == 2)); + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + + GH3X2X_EcgAlgorithmResultReport(pstFrameInfo->pstAlgoResult, pstFrameInfo->punFrameCnt[0]); + } + else + { + GH3X2X_DEBUG_ALGO_LOG("GH3x2xEcgAlgoExe error! error code:0x%x\r\n", stRet); + GH3X2X_DEBUG_ALGO_LOG("please feedback to GOODIX!\r\n"); + chAlgoRet = GH3X2X_RET_RESOURCE_ERROR; + } + + return chAlgoRet; +} + +GU8 GH3x2xEcgAlgoClassification(void) +{ + goodix_ecg_classification_update((goodix_classification_flag *)&g_uchClassificationFlag); + return g_uchClassificationFlag; +} +#else +GU8 GH3x2xEcgAlgoClassification(void) +{ + return 0; +} +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hr.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hr.c new file mode 100644 index 000000000..01f6775bc --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hr.c @@ -0,0 +1,224 @@ +/** + * @copyright (c) 2003 - 2024, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_algo_call_hr.c + * + * @brief gh3x2x algo hr interface + * + */ + +#include +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" +#include "goodix_hba.h" + +#if (__USE_GOODIX_HR_ALGORITHM__) + +void Gh3x2xSetHbaMode(GS32 nHbaScenario) +{ + g_unHrParamsArr[1] = nHbaScenario; +} + +goodix_hba_ret goodix_hba_init_func(GU32 fs) +{ + goodix_hba_config stHbCfg; + goodix_hba_ret stAlgoRet = GX_ALGO_HBA_SUCCESS; + GCHAR uchHrVersion[120] = {0}; + + goodix_hba_ret ret = goodix_hba_version((uint8_t *)uchHrVersion); + if (GX_ALGO_HBA_SUCCESS != ret) + { + GH3X2X_DEBUG_ALGO_LOG("hba algorithm init fail : 0x%x\r\n", ret); + return ret; + } + + GH3X2X_HbaAlgoChnlMapDefultSet(); + + GH3X2X_DEBUG_ALGO_LOG("hba algorithm version : %s\r\n", uchHrVersion); + GH3X2X_DEBUG_ALGO_LOG("hba algorithm legal chnl num : %d\r\n", g_stHbaAlgoChnlMap.uchNum); + + if (g_stHbaAlgoChnlMap.uchNum > Gh3x2xGetHrAlgoSupportChnl()) + { + GH3X2X_DEBUG_ALGO_LOG("ERROR: hr algorithm legal chnl num is too big, check cfg !!! \r\n"); + return GX_ALGO_HBA_RWONG_INPUT; + } + + stHbCfg.mode = (hba_test_mode)g_unHrParamsArr[0]; + stHbCfg.scence = (hba_scenes_e)g_unHrParamsArr[1]; + stHbCfg.fs = fs; + stHbCfg.valid_channel_num = g_stHbaAlgoChnlMap.uchNum; + stHbCfg.back_track_len = g_unHrParamsArr[2]; + stHbCfg.hba_latest_output_time = g_unHrParamsArr[3]; + stHbCfg.hba_earliest_output_time = g_unHrParamsArr[4]; + stHbCfg.hba_lowerest_confidence = g_unHrParamsArr[5]; + stHbCfg.hba_out_step_second = g_unHrParamsArr[6]; + stHbCfg.hba_convergence_rate = g_unHrParamsArr[7]; + stHbCfg.senseless_mode_step = g_unHrParamsArr[8]; + stHbCfg.senseless_mode_duration = g_unHrParamsArr[9]; + + GH3X2X_INFO_ALGO_LOG("[%s]:params = %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n", __FUNCTION__, + stHbCfg.mode, + stHbCfg.scence, + stHbCfg.fs, + stHbCfg.valid_channel_num, + stHbCfg.back_track_len, + stHbCfg.hba_latest_output_time, + stHbCfg.hba_earliest_output_time, + stHbCfg.hba_lowerest_confidence, + stHbCfg.hba_out_step_second, + stHbCfg.hba_convergence_rate, + stHbCfg.senseless_mode_step, + stHbCfg.senseless_mode_duration); + + const void *p_CfgInstance = (void *)&stHbCfg; + char chVer[HBA_INTERFACE_VERSION_LEN_MAX] = {0}; + + goodix_hba_config_get_version(chVer, HBA_INTERFACE_VERSION_LEN_MAX); + const char *p_InterfaceVer = chVer; + + stAlgoRet = goodix_hba_init(p_CfgInstance, sizeof(stHbCfg), p_InterfaceVer); + + return stAlgoRet; +} + +goodix_hba_ret goodix_hba_deinit_func(void) +{ + return goodix_hba_deinit(); +} + +GS8 GH3x2xHrAlgoInit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + goodix_hba_ret ret = goodix_hba_init_func(pstFrameInfo->pstFunctionInfo->usSampleRate); + + if (GX_ALGO_HBA_SUCCESS == ret) + { + chRet = GH3X2X_RET_OK; + GH3X2X_DEBUG_ALGO_LOG("[%s]GH3X2X_HbaInit success!!\r\n", __FUNCTION__); + } + else + { + GH3X2X_DEBUG_ALGO_LOG("hba init error! error code:0x%x\r\n", ret); + } + + pstFrameInfo->pstAlgoRecordResult->uchUpdateFlag = 0; + pstFrameInfo->pstAlgoRecordResult->snResult[0] = 0; + + return chRet; +} + +GS8 GH3x2xHrAlgoDeinit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + goodix_hba_ret ret = goodix_hba_deinit_func(); + if (GX_ALGO_HBA_SUCCESS == ret) + { + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("hba deinit error! error code:0x%x\r\n", ret); + } + + return chRet; +} + +//call algo 2-level interface +GS8 GH3x2xHrAlgoExe(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + if (0 == pstFrameInfo) + { + return GH3X2X_RET_GENERIC_ERROR; + } + + GS32 ppg_rawdata[3 * PPG_CHANNEL_NUM] = {0}; + GS32 cur_adj_flg[3 * PPG_CHANNEL_NUM] = {0}; + GS32 gain_adj_flg[3 * PPG_CHANNEL_NUM] = {0}; + GS32 enable_flg[3 * PPG_CHANNEL_NUM] = {0}; + + goodix_hba_input_rawdata stRawdata = {0}; + goodix_hba_result stResult = {0}; + + stRawdata.ppg_rawdata = ppg_rawdata; + stRawdata.cur_adj_flg = cur_adj_flg; + stRawdata.gain_adj_flg = gain_adj_flg; + stRawdata.enable_flg = enable_flg; + + stRawdata.frameid = GH3X2X_GET_BYTE0_FROM_DWORD(*(pstFrameInfo->punFrameCnt)); + stRawdata.acc_x = pstFrameInfo->pusFrameGsensordata[0]; + stRawdata.acc_y = pstFrameInfo->pusFrameGsensordata[1]; + stRawdata.acc_z = pstFrameInfo->pusFrameGsensordata[2]; + stRawdata.sleep_flg = GH3x2xSleepFlagGet(); + + GU8 uchChMapCnt = 0; + GU8 uchRawdataIndex = 0; + GU8 uchTotalChannelNum = 0; + GS8 chAlgoRet = GH3X2X_RET_OK; + + for (uchChMapCnt = 0; uchChMapCnt < 3 * PPG_CHANNEL_NUM; ++uchChMapCnt) + { + if (g_stHbaAlgoChnlMap.uchAlgoChnlMap[uchChMapCnt + 4 * (uchChMapCnt / 4)] < 0xff) + { + uchRawdataIndex = g_stHbaAlgoChnlMap.uchAlgoChnlMap[uchChMapCnt + 4 * (uchChMapCnt / 4)]; + + //make gain_adj_flg and cur_adj_flg to 0 for algo 1.0.5.0(alpha). + stRawdata.gain_adj_flg[uchChMapCnt] = 0; + stRawdata.cur_adj_flg[uchChMapCnt] = 0; + stRawdata.enable_flg[uchChMapCnt] = 1; + stRawdata.ppg_rawdata[uchChMapCnt] = pstFrameInfo->punFrameRawdata[uchRawdataIndex]; + uchTotalChannelNum++; + + GH3X2X_DEBUG_ALGO_LOG("[%s]ppg_rawdata = %d,gain_adj_flg = %d,cur_adj_flg = %d\r\n", __FUNCTION__, \ + (int)stRawdata.ppg_rawdata[uchChMapCnt], (int)stRawdata.gain_adj_flg[uchChMapCnt], \ + (int)stRawdata.cur_adj_flg[uchChMapCnt]); + } + } + stRawdata.total_channel_num = uchTotalChannelNum; + + /* call algorithm, update result */ + goodix_hba_ret ret = goodix_hba_update(&stRawdata, &stResult); + if (GX_ALGO_HBA_SUCCESS == ret) + { + if (1 == stResult.hba_out_flag) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = (GU8)stResult.hba_out_flag; + pstFrameInfo->pstAlgoResult->snResult[0] = (GS32)stResult.hba_out; + pstFrameInfo->pstAlgoResult->snResult[1] = (GS32)stResult.valid_score; + pstFrameInfo->pstAlgoResult->snResult[2] = GH3X2X_ALGORITHM_GF32_2_GS32(stResult.hba_snr); + pstFrameInfo->pstAlgoResult->snResult[3] = (GS32)stResult.valid_level; + pstFrameInfo->pstAlgoResult->snResult[4] = (GS32)stResult.hba_acc_info; + pstFrameInfo->pstAlgoResult->snResult[5] = (GS32)stResult.hba_acc_scence; + + GH3X2X_DEBUG_ALGO_LOG("[%s]hr = %d,UpdateFlag = %d\r\n", __FUNCTION__, \ + (int)pstFrameInfo->pstAlgoResult->snResult[0], (int)pstFrameInfo->pstAlgoResult->uchUpdateFlag); + + pstFrameInfo->pstAlgoResult->usResultBit = 0x3F; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); +#if __GH3X2X_HR_OUTPUT_VALUE_STRATEGY_EN__ + Gh3x2xHrOutputValueStrategyPro(pstFrameInfo->pstAlgoResult,pstFrameInfo->punFrameCnt[0]); +#endif + GH3X2X_HrAlgorithmResultReport(pstFrameInfo->pstAlgoResult,pstFrameInfo->punFrameCnt[0]); + + pstFrameInfo->pstAlgoRecordResult->uchUpdateFlag = (GU8)stResult.hba_out_flag; + pstFrameInfo->pstAlgoRecordResult->snResult[0] = (GS32)stResult.hba_out; + } + } + else + { + chAlgoRet = GH3X2X_RET_RESOURCE_ERROR; + GH3X2X_DEBUG_ALGO_LOG("GH3x2xHrAlgoExe error! error code = 0x%x\r\n", ret); + GH3X2X_DEBUG_ALGO_LOG("please feedback to GOODIX!\r\n"); + } + + return chAlgoRet; +} + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hrv.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hrv.c new file mode 100644 index 000000000..f88f7ec26 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hrv.c @@ -0,0 +1,172 @@ +#include +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "goodix_hba.h" +#include "goodix_hrv.h" + +#if (__USE_GOODIX_HRV_ALGORITHM__) + +GU32 g_unHrvLastHrResult = 0; + +//hrv +goodix_hrv_ret goodix_hrv_init_func(GU32 fs) +{ + goodix_hrv_ret stAlgoRet = GX_HRV_ALGO_OK; + goodix_hrv_config stHrvConfig = { + g_nHrvParamsArr[0], + fs, + {g_nHrvParamsArr[1] * 10000, g_nHrvParamsArr[2] * 10000, g_nHrvParamsArr[3] * 10000, g_nHrvParamsArr[4] * 10000} + }; + + GCHAR uchHrvVersion[100] = {0}; + GH3X2X_Memcpy(uchHrvVersion, goodix_hrv_version(), strlen((GCHAR *)goodix_hrv_version()) + 1); + GH3X2X_DEBUG_ALGO_LOG("hrv algorithm version : %s\r\n", uchHrvVersion); + + GH3X2X_INFO_ALGO_LOG("[%s]:params = %d,%d,%d,%d,%d,%d,\r\n", __FUNCTION__, + stHrvConfig.need_ipl, + stHrvConfig.fs, + stHrvConfig.acc_thr[0], + stHrvConfig.acc_thr[1], + stHrvConfig.acc_thr[2], + stHrvConfig.acc_thr[3]); + + const void *p_CfgInstance = (void *)&stHrvConfig; + char chVer[HRV_INTERFACE_VERSION_LEN_MAX] = {0}; + + goodix_hrv_config_get_version(chVer, HRV_INTERFACE_VERSION_LEN_MAX); + const char *p_InterfaceVer = chVer; + + stAlgoRet = goodix_hrv_init(p_CfgInstance, sizeof(stHrvConfig), p_InterfaceVer); + + return stAlgoRet; +} + +goodix_hrv_ret goodix_hrv_deinit_func(void) +{ + goodix_hrv_ret nRet = GX_HRV_ALGO_OK; + + nRet = goodix_hrv_deinit(); + if (GX_HRV_ALGO_OK != nRet) + { + GH3X2X_DEBUG_ALGO_LOG("hrv init errorcode : 0x%x\r\n", nRet); + } + + return nRet; +} + +GS8 GH3x2xHrvAlgoInit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + goodix_hrv_ret ret = goodix_hrv_init_func(pstFrameInfo->pstFunctionInfo->usSampleRate); + if (GX_ALGO_HBA_SUCCESS == ret) + { + pstFrameInfo->pstAlgoResult->usResultBit = 0x7F; + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("hrv init error! error code = 0x%x\r\n", ret); + } + g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->uchUpdateFlag = 0; + g_unHrvLastHrResult = 0; + + return chRet; +} + +GS8 GH3x2xHrvAlgoDeinit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + if (GX_ALGO_HBA_SUCCESS == goodix_hrv_deinit_func()) + { + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("hrv deinit error!\r\n"); + } + + return chRet; +} + +GS8 GH3x2xHrvAlgoExe(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + if (0 == pstFrameInfo) + { + return GH3X2X_RET_GENERIC_ERROR; + } + + GS8 chAlgoRet = GH3X2X_RET_OK; + GU8 uchGainValue = 0; + GS32 ppg_rawdata[PPG_CHANNEL_NUM] = {0}; + GS32 cur_adj_flg[PPG_CHANNEL_NUM] = {0}; + GS32 gain_adj_flg[PPG_CHANNEL_NUM] = {0}; + goodix_hrv_result stResult = {0}; + goodix_hrv_input_rawdata stRawdataInput = {0}; + + stRawdataInput.ppg_rawdata = ppg_rawdata; + stRawdataInput.cur_adj_flg = cur_adj_flg; + stRawdataInput.gain_adj_flg = gain_adj_flg; + + stRawdataInput.bit_num = 24; + stRawdataInput.acc_x = pstFrameInfo->pusFrameGsensordata[0]; + stRawdataInput.acc_y = pstFrameInfo->pusFrameGsensordata[1]; + stRawdataInput.acc_z = pstFrameInfo->pusFrameGsensordata[2]; + stRawdataInput.frame_id = GH3X2X_GET_BYTE0_FROM_DWORD(*(pstFrameInfo->punFrameCnt)); + if (g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->uchUpdateFlag) + { + g_unHrvLastHrResult = g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->snResult[0]; + } + stRawdataInput.hr = g_unHrvLastHrResult; + + for (GS32 nRawdatacnt = 0; nRawdatacnt < PPG_CHANNEL_NUM; nRawdatacnt++) + { + stRawdataInput.ppg_rawdata[nRawdatacnt] = pstFrameInfo->punFrameRawdata[nRawdatacnt]; + uchGainValue = GH3X2X_GET_LOW_4BITS(pstFrameInfo->punFrameAgcInfo[nRawdatacnt]); + if ((pstFrameInfo->puchFrameLastGain[nRawdatacnt] != uchGainValue) && \ + (pstFrameInfo->puchFrameLastGain[nRawdatacnt] != GH3X2X_GAIN_VALUE_INVALID)) + { + stRawdataInput.gain_adj_flg[nRawdatacnt] = 1; + pstFrameInfo->puchFrameLastGain[nRawdatacnt] = uchGainValue; + } + stRawdataInput.cur_adj_flg[nRawdatacnt] = ((pstFrameInfo->punFrameFlag[0]) & 0x01); + + GH3X2X_DEBUG_ALGO_LOG("[%s]ppg_rawdata = %d, gain_adj_flg = %d, cur_adj_flg = %d\r\n", __FUNCTION__, \ + (int)stRawdataInput.ppg_rawdata[nRawdatacnt], (int)stRawdataInput.gain_adj_flg[nRawdatacnt], \ + (int)stRawdataInput.cur_adj_flg[nRawdatacnt]); + } + + goodix_hrv_ret ret = goodix_hrv_calc(&stRawdataInput, &stResult); + if (GX_HRV_ALGO_OK == ret || GX_HRV_ALGO_UPDATE == ret) + { + if (GX_HRV_ALGO_UPDATE == ret) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->snResult[0] = (GS32)stResult.rri[0]; + pstFrameInfo->pstAlgoResult->snResult[1] = (GS32)stResult.rri[1]; + pstFrameInfo->pstAlgoResult->snResult[2] = (GS32)stResult.rri[2]; + pstFrameInfo->pstAlgoResult->snResult[3] = (GS32)stResult.rri[3]; + pstFrameInfo->pstAlgoResult->snResult[4] = (GS32)stResult.rri_confidence; + pstFrameInfo->pstAlgoResult->snResult[5] = (GS32)stResult.rri_valid_num; + pstFrameInfo->pstAlgoResult->usResultBit = 0x7F; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + GH3X2X_HrvAlgorithmResultReport(pstFrameInfo->pstAlgoResult, pstFrameInfo->punFrameCnt[0]); + } + } + else + { + chAlgoRet = GH3X2X_RET_RESOURCE_ERROR; + GH3X2X_DEBUG_ALGO_LOG("GH3x2xHrAlgoExe error! error code = 0x%x\r\n", ret); + GH3X2X_DEBUG_ALGO_LOG("please feedback to GOODIX!\r\n"); + } + + return chAlgoRet; +} + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hsm.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hsm.c new file mode 100644 index 000000000..6372a0609 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_hsm.c @@ -0,0 +1,131 @@ +#include +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" +#include "goodix_hsm.h" + +#if (__USE_GOODIX_HSM_ALGORITHM__) + +GS8 GH3x2xHsmAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + int32_t nRet = GH3X2X_RET_GENERIC_ERROR; +#if (GH3X2X_ALGORITHM_HSM_SUPPORT) + + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + //g_uchLastGainOfChannel[0] = GH3X2X_GAIN_VALUE_INVALID; + //int nHSMFs = (int)pstFrameInfo ->pstFunctionInfo ->usSampleRate; + int32_t nHSMFs = 25; + nRet = HSMAlgoInit(&nHSMFs); + if (nRet != GH3X2X_RET_OK) + { + GH3X2X_DEBUG_ALGO_LOG("hsm process error! error code : %d\r\n", (int)nRet); + } + else + { + pstFrameInfo->pstAlgoResult->usResultBit = 0x1; + } + g_unHsmLastHrResult = 0; +#else + nRet = GH3X2X_RET_ALGO_NO_SUPPORTED; + GH3X2X_DEBUG_ALGO_LOG("hsm algorithm no supported error!\r\n"); +#endif + return (GS8)nRet; +} + +GS8 GH3x2xHsmAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ +#if (GH3X2X_ALGORITHM_HSM_SUPPORT) + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + + ST_HSM_DATA_OUT stHSMDataOut; + ST_HSM_SCORE stHSMScore; + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + GU8 uchHsmResultSendBuffer[235] = {0}; + GU8 uchHsmPackLen = 140; + if (HSMLastDataProc(&stHSMDataOut, &stHSMScore) == GH3X2X_RET_OK) + { + uchHsmResultSendBuffer[4] = 2; + if (stHSMDataOut.uchStageDataFlag != 0) + { + GH3X2X_Memcpy(uchHsmResultSendBuffer + 1 + 4, (GU8*)&stHSMScore, 18); + uchHsmResultSendBuffer[23] = stHSMDataOut.uchStageOutNum; + GH3X2X_Memcpy(uchHsmResultSendBuffer + 1 + 4 + 19, stHSMDataOut.puchHSMStageOut, 120); + } + GU16 usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_HSM_RESULT_UPDATE, uchHsmResultSendBuffer, + &uchHsmResultSendBuffer[4], uchHsmPackLen); + Gh3x2xDemoSendProtocolData(uchHsmResultSendBuffer,usRespondLen); + chRet = HSMAlgoDeInit(); + } + else + { + chRet = HSMAlgoDeInit(); + GH3X2X_RET_ERROR_CHECK(chRet); + chRet = GH3X2X_RET_GENERIC_ERROR; + } +#else + GS8 chRet = GH3X2X_RET_ALGO_NO_SUPPORTED; + GH3X2X_DEBUG_ALGO_LOG("hsm algorithm no supported error!\r\n"); +#endif + return chRet; +} + +GS8 GH3x2xHsmAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + if(0 == pstFrameInfo ) + { + return 0; + } +#if (GH3X2X_ALGORITHM_HSM_SUPPORT) + ST_HSM_DATA_IN stHSMDataIn; + ST_HSM_DATA_OUT stHSMDataOut; + ST_HSM_SCORE stHSMScore; + + if(GH3X2X_RET_OK != GH3x2xCheckAndFreeMem(pstFrameInfo)) + { + return; + } + + stHSMDataIn.IPpgRaw = (int)GH3X2X_GET_RAWDATA_FOR_ALGO((int)pstFrameInfo->punFrameRawdata[0] - GH3X2X_RAWDATA_BASE_VALUE); + stHSMDataIn.IACCx = pstFrameInfo->pusFrameGsensordata[0]; + stHSMDataIn.IACCy = pstFrameInfo->pusFrameGsensordata[1]; + stHSMDataIn.IACCz = pstFrameInfo->pusFrameGsensordata[2]; + if (g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->uchUpdateFlag) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->usResultBit = 0x1; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + pstFrameInfo->pstAlgoResult->snResult[0] = (GS32)g_unHsmLastHrResult; + g_unHsmLastHrResult = g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstAlgoRecordResult->snResult[0]; + } + stHSMDataIn.IHeart = g_unHsmLastHrResult; + + if (HSMProc(&stHSMDataIn, &stHSMDataOut, &stHSMScore) == GH3X2X_RET_OK) + { + if (stHSMDataOut.uchStageDataFlag != 0) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->snResult[0] = 1; + GU8 uchHsmResultSendBuffer[235] = {0}; + GU8 uchHsmPackLen = 140; + uchHsmResultSendBuffer[4] = stHSMDataOut.uchStageDataFlag; + GH3X2X_Memcpy(uchHsmResultSendBuffer + 1 + 4, (GU8*)&stHSMScore, 18); + uchHsmResultSendBuffer[23] = stHSMDataOut.uchStageOutNum; + GH3X2X_Memcpy(uchHsmResultSendBuffer + 1 + 4 + 19, stHSMDataOut.puchHSMStageOut, 120); + GU16 usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_HSM_RESULT_UPDATE, uchHsmResultSendBuffer, + &uchHsmResultSendBuffer[4], uchHsmPackLen); + Gh3x2xDemoSendProtocolData(uchHsmResultSendBuffer,usRespondLen); + } + } + else + { + GH3X2X_DEBUG_ALGO_LOG("hsm process error!\r\n"); + } +#else + return; +#endif +} + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_nadt.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_nadt.c new file mode 100644 index 000000000..a1da18362 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_nadt.c @@ -0,0 +1,282 @@ +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "goodix_mem.h" +#include "goodix_nadt.h" + +#if (__USE_GOODIX_SOFT_ADT_ALGORITHM__) + +#define NADT_CONFIG_SAMPLE_RATE_TYPE (0) +#define NADT_CONFIG_MULTI_SAMPLE_RATE_TYPE (0) + +#define SOFT_WEAR_INPUT_DATA_CHNL0_INDEX (0) +#define SOFT_WEAR_INPUT_DATA_ACCX_INDEX (1) +#define SOFT_WEAR_INPUT_DATA_ACCY_INDEX (2) +#define SOFT_WEAR_INPUT_DATA_ACCZ_INDEX (3) +#define SOFT_WEAR_INPUT_COLOR_INDEX (4) +#define SOFT_WEAR_INPUT_DATA_ADT_INDEX (5) //ir adt data +#define SOFT_WEAR_INPUT_DATA_BG_INDEX (6) +#define SOFT_WEAR_INPUT_DATA_CAP0_INDEX (7) +#define SOFT_WEAR_INPUT_DATA_CAP1_INDEX (8) +#define SOFT_WEAR_INPUT_DATA_CAP2_INDEX (9) +#define SOFT_WEAR_INPUT_DATA_CAP3_INDEX (10) +#define SOFT_WEAR_INPUT_DATA_INDEX_TOTAL (11) +#define SOFT_WEAR_OUTPUT_DATA_INDEX_TOTAL (8) +#define WATCH_NUM (3) + +#if (WATCH_NUM == 1) +static GS32 lWearCap1 = 16400; +static GS32 lUnwearCap1 = 12400; +static GS32 lNoise1 = 300; +static GS32 lWearCap2 = 0; +static GS32 lUnwearCap2 = 0; +static GS32 lNoise2 = 0; +#elif (WATCH_NUM == 2) +static GS32 lWearCap1 = 20000; +static GS32 lUnwearCap1 = 16000; +static GS32 lNoise1 = 200; +static GS32 lWearCap2 = 3700; +static GS32 lUnwearCap2 = 1200; +static GS32 lNoise2 = 200; +#elif (WATCH_NUM == 3) +static GS32 lWearCap1 = 42500; +static GS32 lUnwearCap1 = 39500; +//static GS32 lNoise1 = 150; +static GS32 lWearCap2 = 42500; +static GS32 lUnwearCap2 = 39500; +//static GS32 lNoise2 = 150; +#endif + +//static GS32 ghbrelsult[10]; +//static GS32 glConfig[3] = { 0 }; +static GU8 g_uchSoftAdtChannl0Color; // 0: green 1: ir +static GU32 g_unNadtIrDefaultTimeOutRecord = 0; +static GU32 g_unNadtIrDefaultTimeOutSecondsThrd = __SOFT_ADT_IR_DETECT_TIMEOUT__; +static GU8 g_SoftWearQuality = 0; +NADT_ST_MID_INFO stMidInfo; +extern GU8 g_SoftAdtWearState; + +void Gh3x2x_SetIRDetectTimeThreshold(GU32 unIRDetectTimeThreshold) +{ + g_unNadtIrDefaultTimeOutSecondsThrd = unIRDetectTimeThreshold; +} + +void SoftWearControlInit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + g_SoftAdtWearState = GH3X2X_SOFT_ALGO_ADT_DEFAULT; + GCHAR uchNadtVersion[100] = {0}; + + GetNadtVersion((uint8_t *)uchNadtVersion); + GH3X2X_DEBUG_ALGO_LOG("[%s]nadt algorithm version : %s\r\n", __FUNCTION__, uchNadtVersion); + + goodix_nadt_config stNadtCfg = { + pstFrameInfo->pstFunctionInfo->usSampleRate, // 采样率 + 3, // 佩戴等级 + 0, // 睡眠状态 + 1200, // 活体检测超时时间 + 4, // 脱落确认时间 + 2, // 活体确认时间 + 8638608, // ADT wear on阈值 + 8588608, // ADT wear off阈值 + 25, // ACC阈值 + 1, // 活体检测使能标记 + 300, // 高次谐波含量阈值 + 50, // 心率下限 + 140, // 心率上限 + 8, // 心率周期差异阈值 + 50, // 信号平稳性分数阈值 + 30, // 基线单调性阈值 + 15, // 基线平坦性阈值 + 1000, // 归一化信号阈值放大系数 + 1, // 环境光突变检测使能标记 + 100, // 突变环境光变化量阈值 + 12, // 突变环境光峰谷个数阈值 + 1, // 环境光周期检测使能标记 + 10, // 周期环境光变化量阈值 + 10, // 环境光周期阈值 + 5 // 环境光周期差异阈值 + }; + GH3X2X_DEBUG_ALGO_LOG("[%s]nadt param0 : %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\n", __FUNCTION__, stNadtCfg.sampleRateNADT, \ + stNadtCfg.unwearDetectLevel, stNadtCfg.sleepStatus, stNadtCfg.checkTimeoutThr, stNadtCfg.unwearCheckCntThr, stNadtCfg.wearCheckCntThr, \ + stNadtCfg.adtWearOnThr, stNadtCfg.adtWearOffThr, stNadtCfg.accStdThr, stNadtCfg.liveDetectEnable, stNadtCfg.rawPVLenThr, \ + stNadtCfg.heartBeatThrLow, stNadtCfg.heartBeatThrHigh, stNadtCfg.difRrInterThr, stNadtCfg.wearAcfScoreThr); + GH3X2X_DEBUG_ALGO_LOG("[%s]nadt param1 : %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\n", __FUNCTION__, stNadtCfg.baseLinePosRatioThr, \ + stNadtCfg.baseLineDiffThr, stNadtCfg.sigScaleThr, stNadtCfg.bgJumpDetectEnable, stNadtCfg.jumpBgDiffThr, stNadtCfg.bgPeakValleyNumThr, \ + stNadtCfg.bgPeriodDetectEnable, stNadtCfg.periodBgDiffThr, stNadtCfg.bgPeriodThr, stNadtCfg.bgPeriodDiffThr); + + const void *p_CfgInstance = (void *)&stNadtCfg; + char chVer[NADT_INTERFACE_VERSION_LEN_MAX] = {0}; + + goodix_nadt_config_get_version(chVer, NADT_INTERFACE_VERSION_LEN_MAX); + const char *p_InterfaceVer = chVer; + + NADTProcInit(p_CfgInstance, sizeof(stNadtCfg), p_InterfaceVer); + memset(&stMidInfo, 0, sizeof(NADT_ST_MID_INFO)); +} + +void GH3x2xCapNadtResultPro(const STGh3x2xFrameInfo * const pstFrameInfo,GS32 pnSoftWearOffDetResult[]) +{ + if (pnSoftWearOffDetResult[3]) // 电容更新标记,更新佩戴检测阈值 + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + lUnwearCap1 = pnSoftWearOffDetResult[4]; + lWearCap1 = pnSoftWearOffDetResult[5]; + lUnwearCap2 = pnSoftWearOffDetResult[6]; + lWearCap2 = pnSoftWearOffDetResult[7]; + } + if(g_SoftWearQuality != pnSoftWearOffDetResult[2]) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + g_SoftWearQuality = pnSoftWearOffDetResult[2]; + } + if(pstFrameInfo->punFrameCnt == 0) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + } + if(pstFrameInfo->pstAlgoResult->uchUpdateFlag == 1) + { + pstFrameInfo->pstAlgoResult->usResultBit = 0x7; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + pstFrameInfo->pstAlgoResult->snResult[0] = pnSoftWearOffDetResult[0]; // (bit0-bit1):佩戴状态(0默认,1佩戴,2脱落,3非活体); (bit2):疑似脱落标记(0正常,1疑似脱落); + pstFrameInfo->pstAlgoResult->snResult[1] = pnSoftWearOffDetResult[1]; //活体检测置信度 + pstFrameInfo->pstAlgoResult->snResult[2] = pnSoftWearOffDetResult[2]; //佩戴质量(1紧佩戴,2松佩戴,3极度松佩戴,4脱落); + if(pstFrameInfo->punFrameCnt == 0) + { + pstFrameInfo->pstAlgoResult->usResultBit = 0x7F; + pstFrameInfo->pstAlgoResult->snResult[3] = lUnwearCap1; //脱落电容值1; + pstFrameInfo->pstAlgoResult->snResult[4] = lWearCap1; //佩戴电容值1; + pstFrameInfo->pstAlgoResult->snResult[5] = lUnwearCap2; //脱落电容值2; + pstFrameInfo->pstAlgoResult->snResult[6] = lWearCap2; //佩戴电容值2; + } + else + { + pstFrameInfo->pstAlgoResult->usResultBit = 0x7F; + pstFrameInfo->pstAlgoResult->snResult[3] = pnSoftWearOffDetResult[4]; //脱落电容值1; + pstFrameInfo->pstAlgoResult->snResult[4] = pnSoftWearOffDetResult[5]; //佩戴电容值1; + pstFrameInfo->pstAlgoResult->snResult[5] = pnSoftWearOffDetResult[6]; //脱落电容值2; + pstFrameInfo->pstAlgoResult->snResult[6] = pnSoftWearOffDetResult[7]; //佩戴电容值2; + } + } +} + +GS8 GH3x2xSoftAdtAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS32 nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_INDEX_TOTAL] = {0}; + GS32 pnSoftWearOffDetResult[SOFT_WEAR_OUTPUT_DATA_INDEX_TOTAL] = {0}; + + if(pstFrameInfo) + { + GU32 unLedAdjFlag = 0; + + if(pstFrameInfo->punFrameFlag[0]&0x00000001) //led current change + { + unLedAdjFlag = 1; + } + if((0xFF != pstFrameInfo->puchFrameLastGain[0])&&((pstFrameInfo->punFrameAgcInfo[0]&0x0000000F) != pstFrameInfo->puchFrameLastGain[0])) //tia gain change + { + unLedAdjFlag = 1; + } + + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_ACCX_INDEX] = pstFrameInfo->pusFrameGsensordata[0]; + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_ACCY_INDEX] = pstFrameInfo->pusFrameGsensordata[1]; + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_ACCZ_INDEX] = pstFrameInfo->pusFrameGsensordata[2]; + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_CHNL0_INDEX] = pstFrameInfo->punFrameRawdata[0]; + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_CHNL0_INDEX] |= (unLedAdjFlag << 26); //led adj flag + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_COLOR_INDEX] = g_uchSoftAdtChannl0Color; //0:GREEN 1:IR + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_ADT_INDEX] = pstFrameInfo->punFrameRawdata[1]; + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_BG_INDEX] = pstFrameInfo->punFrameRawdata[2]; + + if (g_uchAlgoCapEnable == 1) + { + for (int k = 0; k < 4; k++) + { + nSoftWearOffInputBuf[SOFT_WEAR_INPUT_DATA_CAP0_INDEX + k] = pstFrameInfo->pstFrameCapdata->unCapData[k];// [PPGACCLEN + ALGOLEN + guchCompareNum + k]; //电容 + } + } + + goodix_nadt_ret uchRet = NADTProc(nSoftWearOffInputBuf, pnSoftWearOffDetResult, &stMidInfo); + GU32 unNadtIrDefaultTimeOutThrd = g_unNadtIrDefaultTimeOutSecondsThrd * pstFrameInfo->pstFunctionInfo->usSampleRate; + if (g_unNadtIrDefaultTimeOutRecord >= unNadtIrDefaultTimeOutThrd && ((pnSoftWearOffDetResult[0] & 0x3) == 0)) + { + pnSoftWearOffDetResult[0] = pnSoftWearOffDetResult[0] | 0x1; + g_unNadtIrDefaultTimeOutRecord = 0; + } + + if ((pnSoftWearOffDetResult[0] & 0x2) == 0) + { + if (GH3X2X_FUNCTION_SOFT_ADT_IR == pstFrameInfo->unFunctionID) + { + g_unNadtIrDefaultTimeOutRecord++; + } + } + + if (GX_ALGO_NADT_SUCCESS != uchRet) + { + GH3X2X_DEBUG_ALGO_LOG("[GH3x2xSoftAdtAlgoExe]NADTProc: error! error code = 0x%x\r\n", uchRet); + } + + if (g_uchAlgoCapEnable == 1) + { + GH3x2xCapNadtResultPro(pstFrameInfo, pnSoftWearOffDetResult); + } + else + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->usResultBit = 0x3; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + pstFrameInfo->pstAlgoResult->snResult[0] = pnSoftWearOffDetResult[0]; // (bit0-bit1):佩戴状态(0默认,1佩戴,2脱落,3非活体); (bit2):疑似脱落标记(0正常,1疑似脱落); + pstFrameInfo->pstAlgoResult->snResult[1] = pnSoftWearOffDetResult[1]; // 活体检测置信度 + GH3X2X_DEBUG_ALGO_LOG("[nadt] wear status:%d %d, confiidence = %d\r\n", pstFrameInfo->pstAlgoResult->snResult[0] & 0x3, \ + (pstFrameInfo->pstAlgoResult->snResult[0] >> 2) & 0x1, pstFrameInfo->pstAlgoResult->snResult[1]); + } + + //report + if (g_uchSoftAdtChannl0Color == 0) + { + GH3X2X_SoftAdtGreenAlgorithmResultReport(pstFrameInfo->pstAlgoResult, GH3X2X_GET_BYTE0_FROM_DWORD(*(pstFrameInfo->punFrameCnt))); + } + else if(g_uchSoftAdtChannl0Color == 1) + { + GH3X2X_SoftAdtIrAlgorithmResultReport(pstFrameInfo->pstAlgoResult, GH3X2X_GET_BYTE0_FROM_DWORD(*(pstFrameInfo->punFrameCnt))); + } + } + return GH3X2X_RET_OK; +} + + +GS8 GH3x2xSoftAdtAlgoInit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + if (pstFrameInfo) + { + g_SoftWearQuality = 0; + g_uchSoftAdtChannl0Color = 1 * (GH3X2X_FUNCTION_SOFT_ADT_IR == (pstFrameInfo ->unFunctionID)); + + GH3X2X_DEBUG_ALGO_LOG("[SoftAdt]CH0 slot = %d, rx = %d\r\n", GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(pstFrameInfo ->pchChnlMap[0]), \ + GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(pstFrameInfo ->pchChnlMap[0])); + GH3X2X_DEBUG_ALGO_LOG("[SoftAdt]CH1 slot = %d, rx = %d\r\n", GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(pstFrameInfo ->pchChnlMap[1]), \ + GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(pstFrameInfo ->pchChnlMap[1])); + GH3X2X_DEBUG_ALGO_LOG("[SoftAdt]CH2 slot = %d, rx = %d\r\n", GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(pstFrameInfo ->pchChnlMap[2]), \ + GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(pstFrameInfo ->pchChnlMap[2])); + GH3X2X_DEBUG_ALGO_LOG("[SoftAdt]g_uchSoftAdtChannl0Color = %d\r\n", g_uchSoftAdtChannl0Color); + + SoftWearControlInit(pstFrameInfo); + } + + return GH3X2X_RET_OK; +} + +GS8 GH3x2xSoftAdtAlgoDeinit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GH3X2X_DEBUG_ALGO_LOG("[SoftAdt]%s\r\n", __FUNCTION__); + + goodix_nadt_ret ret = NADTProcDeinit(); + g_unNadtIrDefaultTimeOutRecord = 0; + if (GX_ALGO_NADT_SUCCESS != ret) + { + GH3X2X_DEBUG_ALGO_LOG("[%s] fail! error code = 0x%x\r\n", __FUNCTION__, ret); + return GH3X2X_RET_GENERIC_ERROR; + } + + return GH3X2X_RET_OK; +} + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_resp.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_resp.c new file mode 100644 index 000000000..fdb829c53 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_resp.c @@ -0,0 +1,72 @@ +#include +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" +#include "goodix_resp.h" + +#if (__USE_GOODIX_RESP_ALGORITHM__) + +GS8 GH3x2xRespAlgoInit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + g_pstGh3x2xAlgoFrameInfo[GH3X2X_FUNC_OFFSET_RESP]->puchFrameLastGain[0] = GH3X2X_GAIN_VALUE_INVALID; + GS32 nRespFs = ((GS32)(pstFrameInfo ->pstFunctionInfo ->usSampleRate) & 0xFFFF); + chRet = RespInit(&nRespFs); + if (chRet == GH3X2X_RET_OK) + { + pstFrameInfo->pstAlgoResult->usResultBit = 0x3; + } + return chRet; +} + +GS8 GH3x2xRespAlgoDeinit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + RespDeInit(); + chRet = GH3X2X_RET_OK; + return chRet; +} + +GS8 GH3x2xRespAlgoExe(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + if(0 == pstFrameInfo ) + { + return GH3X2X_RET_GENERIC_ERROR; + } + RESP_ST_DATA_IN stRespDataIn = {0}; + RESP_ST_DATA_OUT stRespDataOut = {0}; + GU8 uchGainValue = 0; + + stRespDataIn.IPpgRaw = GH3X2X_GET_RAWDATA_FOR_ALGO(pstFrameInfo->punFrameRawdata[0] - GH3X2X_RAWDATA_BASE_VALUE); + stRespDataIn.IACCx = pstFrameInfo->pusFrameGsensordata[0]; + stRespDataIn.IACCy = pstFrameInfo->pusFrameGsensordata[1]; + stRespDataIn.IACCz = pstFrameInfo->pusFrameGsensordata[2]; + + uchGainValue = GH3X2X_GET_LOW_4BITS(pstFrameInfo->punFrameAgcInfo[0]); + if (((pstFrameInfo->puchFrameLastGain[0] != uchGainValue) && \ + (pstFrameInfo->puchFrameLastGain[0] != GH3X2X_GAIN_VALUE_INVALID)) ||\ + ((pstFrameInfo->punFrameFlag[0]) & 0x01)) + { + stRespDataIn.IAdjFlag = 1; + pstFrameInfo->puchFrameLastGain[0] = uchGainValue; + } + + GU8 chRet = RespProc(&stRespDataIn, &stRespDataOut); + + if (1 == stRespDataOut.nRespOutFlag && chRet == 0) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 1; + pstFrameInfo->pstAlgoResult->snResult[0] = (GS32)stRespDataOut.nRespRate; + pstFrameInfo->pstAlgoResult->snResult[1] = (GS32)stRespDataOut.nBelieve; + pstFrameInfo->pstAlgoResult->usResultBit = 0x3; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + //GH3X2X_HrvAlgorithmResultReport(pstFrameInfo->pstAlgoResult,stRawdata.frameid); + } + return chRet; +} + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_spo2.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_spo2.c new file mode 100644 index 000000000..1ea4ab073 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_algo_code/goodix_algo_call/src/gh3x2x_demo_algo_call_spo2.c @@ -0,0 +1,218 @@ +#include "gh3x2x_demo_algo_call.h" +#include "gh3x2x_demo_algorithm_calc.h" +#include "gh3x2x_demo_algo_config.h" +#include "goodix_algo.h" +#include "goodix_spo2.h" + +#if (__USE_GOODIX_SPO2_ALGORITHM__) + +goodix_spo2_ret goodix_spo2_init_func(GU32 fs) +{ + goodix_spo2_ret stAlgoRet = GX_ALGO_SPO2_SUCCESS; + GCHAR uchSpo2Version[150] = {0}; + + GH3X2X_Spo2AlgoChnlMapDefultSet(); + goodix_spo2_version((uint8_t *)uchSpo2Version); + GH3X2X_DEBUG_ALGO_LOG("spo2 algorithm version : %s\r\n", uchSpo2Version); + GH3X2X_DEBUG_ALGO_LOG("spo2 algorithm legal chnl num : %d\r\n", g_stSpo2AlgoChnlMap.uchNum); + + if (g_stSpo2AlgoChnlMap.uchNum > Gh3x2xGetSpo2AlgoSupportChnl()) + { + GH3X2X_DEBUG_ALGO_LOG("ERROR: spo2 algorithm legal chnl num is too big, check cfg !!! \r\n"); + return GX_ALGO_SPO2_RWONG_INPUT; + } + + goodix_spo2_config stSpo2Cfg = { + g_stSpo2AlgoChnlMap.uchNum, // 有效通道数 + fs, // 采样率 + g_nSpo2ParamssArr[0], g_nSpo2ParamssArr[1], g_nSpo2ParamssArr[2], g_nSpo2ParamssArr[3], + g_nSpo2ParamssArr[4], g_nSpo2ParamssArr[5], g_nSpo2ParamssArr[6], g_nSpo2ParamssArr[7], + g_nSpo2ParamssArr[8], g_nSpo2ParamssArr[9], g_nSpo2ParamssArr[10], g_nSpo2ParamssArr[11], + g_nSpo2ParamssArr[12], g_nSpo2ParamssArr[13], g_nSpo2ParamssArr[14], g_nSpo2ParamssArr[15], + g_nSpo2ParamssArr[16], g_nSpo2ParamssArr[17], g_nSpo2ParamssArr[18], g_nSpo2ParamssArr[19], + g_nSpo2ParamssArr[20], g_nSpo2ParamssArr[21], g_nSpo2ParamssArr[22], g_nSpo2ParamssArr[23], + g_nSpo2ParamssArr[24], g_nSpo2ParamssArr[25] + }; + + GH3X2X_INFO_ALGO_LOG("[%s]: params1 = %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n", __FUNCTION__, + stSpo2Cfg.valid_chl_num, + stSpo2Cfg.raw_fs, + stSpo2Cfg.cali_coef_a4, + stSpo2Cfg.cali_coef_a3, + stSpo2Cfg.cali_coef_a2, + stSpo2Cfg.cali_coef_a1, + stSpo2Cfg.cali_coef_a0, + stSpo2Cfg.hb_en_flg, + stSpo2Cfg.wear_mode, + stSpo2Cfg.acc_thr_max, + stSpo2Cfg.acc_thr_min, + stSpo2Cfg.acc_thr_scale, + stSpo2Cfg.acc_thr_num, + stSpo2Cfg.acc_thr_angle, + stSpo2Cfg.ctr_en_flg, + stSpo2Cfg.ctr_red_thr); + + GH3X2X_INFO_ALGO_LOG("[%s]: params2 = %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n", __FUNCTION__, + stSpo2Cfg.ppg_jitter_thr, + stSpo2Cfg.ppg_noise_thr, + stSpo2Cfg.ppg_coeff_thr, + stSpo2Cfg.quality_module_key, + stSpo2Cfg.low_spo2_thr, + stSpo2Cfg.fast_out_time, + stSpo2Cfg.slow_out_time, + stSpo2Cfg.min_stable_time_high, + stSpo2Cfg.min_stable_time_low, + stSpo2Cfg.max_spo2_variation_high, + stSpo2Cfg.max_spo2_variation_low, + stSpo2Cfg.ouput_module_key); + + const void *p_CfgInstance = (void *)&stSpo2Cfg; + char chVer[SPO2_INTERFACE_VERSION_LEN_MAX] = {0}; + + goodix_spo2_config_get_version(chVer, SPO2_INTERFACE_VERSION_LEN_MAX); + //const char *p_InterfaceVer = chVer; + + stAlgoRet = goodix_spo2_init(p_CfgInstance, sizeof(stSpo2Cfg), chVer); + + return stAlgoRet; +} + +goodix_spo2_ret goodix_spo2_deinit_func(void) +{ + return goodix_spo2_deinit(); +} + +GS8 GH3x2xSpo2AlgoInit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + goodix_spo2_ret ret = goodix_spo2_init_func(pstFrameInfo->pstFunctionInfo->usSampleRate); + if (GX_ALGO_SPO2_SUCCESS == ret) + { + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("spo2 init error! error code:0x%x\r\n", ret); + } + + return chRet; +} + +GS8 GH3x2xSpo2AlgoDeinit(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_ALGO_LOG("%s\r\n", __FUNCTION__); + + goodix_spo2_ret ret = goodix_spo2_deinit_func(); + if (GX_ALGO_SPO2_SUCCESS == ret) + { + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_ALGO_LOG("spo2 deinit error! error code:0x%x\r\n", ret); + } + + return chRet; +} + +GS8 GH3x2xSpo2AlgoExe(const STGh3x2xFrameInfo *const pstFrameInfo) +{ + if (0 == pstFrameInfo) + { + return GH3X2X_RET_GENERIC_ERROR; + } + + GU8 uchChannelNum = 0; + GS32 ppg_rawdata[3 * CHIP_PPG_CHL_NUM] = {0}; + GS8 cur_adj_flg[3 * CHIP_PPG_CHL_NUM] = {0}; + GS8 gain_adj_flg[3 * CHIP_PPG_CHL_NUM] = {0}; + GS8 enable_flg[3 * CHIP_PPG_CHL_NUM] = {0}; + GS32 ch_agc_drv0[3 * CHIP_PPG_CHL_NUM] = {0}; + GS32 ch_agc_drv1[3 * CHIP_PPG_CHL_NUM] = {0}; + GS8 ch_agc_gain[3 * CHIP_PPG_CHL_NUM] = {0}; + + goodix_spo2_input_rawdata stRawdata = {0}; + goodix_spo2_result stResult = {0}; + GS8 emAlgoRet = GH3X2X_RET_OK; + + stRawdata.frameid = GH3X2X_GET_BYTE0_FROM_DWORD(*(pstFrameInfo->punFrameCnt)); + stRawdata.bit_num = 24; + stRawdata.ppg_rawdata = ppg_rawdata; + stRawdata.cur_adj_flg = cur_adj_flg; + stRawdata.gain_adj_flg = gain_adj_flg; + stRawdata.enable_flg = enable_flg; + stRawdata.ch_agc_drv0 = ch_agc_drv0; + stRawdata.ch_agc_drv1 = ch_agc_drv1; + stRawdata.ch_agc_gain = ch_agc_gain; + stRawdata.acc_x = pstFrameInfo->pusFrameGsensordata[0]; // 46 + stRawdata.acc_y = pstFrameInfo->pusFrameGsensordata[1]; // -183 + stRawdata.acc_z = pstFrameInfo->pusFrameGsensordata[2]; // 482 + stRawdata.wear_on_flag = 1; + + /* call algorithm, update result */ + for (GU8 uchChMapCnt = 0; uchChMapCnt < CHIP_PPG_CHL_NUM * 3; ++uchChMapCnt) + { + if (g_stSpo2AlgoChnlMap.uchAlgoChnlMap[uchChMapCnt + 4 * (uchChMapCnt / 4)] < 0xff) + { + GU8 uchRawdataIndex = g_stSpo2AlgoChnlMap.uchAlgoChnlMap[uchChMapCnt + 4 * (uchChMapCnt / 4)]; + + stRawdata.ch_agc_drv0[uchChMapCnt] = ((pstFrameInfo->punFrameAgcInfo[uchRawdataIndex] >> 8) & 0xFF); + stRawdata.ch_agc_drv1[uchChMapCnt] = ((pstFrameInfo->punFrameAgcInfo[uchRawdataIndex] >> 16) & 0xFF); + stRawdata.ch_agc_gain[uchChMapCnt] = (pstFrameInfo->punFrameAgcInfo[uchRawdataIndex] & 0xF); + + if (((pstFrameInfo->puchFrameLastGain[uchRawdataIndex] != stRawdata.ch_agc_gain[uchChMapCnt]) && \ + (pstFrameInfo->puchFrameLastGain[uchRawdataIndex] != GH3X2X_GAIN_VALUE_INVALID)) || \ + ((pstFrameInfo->punFrameFlag[0]) & 0x01)) + { + stRawdata.gain_adj_flg[uchChMapCnt] = 1; + pstFrameInfo->puchFrameLastGain[uchRawdataIndex] = stRawdata.ch_agc_gain[uchChMapCnt]; + } + stRawdata.cur_adj_flg[uchChMapCnt] = (((pstFrameInfo->punFrameFlag[0]) >> uchRawdataIndex) & 0x01); + stRawdata.enable_flg[uchChMapCnt] = 1; + stRawdata.ppg_rawdata[uchChMapCnt] = pstFrameInfo->punFrameRawdata[uchRawdataIndex]; + uchChannelNum++; + + GH3X2X_DEBUG_ALGO_LOG("[%s] ch%d ppg_rawdata = %d,gain_adj_flg = %d,cur_adj_flg = %d\r\n", __FUNCTION__, uchChMapCnt, \ + (int)stRawdata.ppg_rawdata[uchChMapCnt], (int)stRawdata.gain_adj_flg[uchChMapCnt], \ + (int)stRawdata.cur_adj_flg[uchChMapCnt]); + } + } + stRawdata.ch_num = CHIP_PPG_CHL_NUM; + + goodix_spo2_ret ret = goodix_spo2_calc(&stRawdata, &stResult); + // goodix_spo2_essential_info_print(&stRawdata); + + if (GX_ALGO_SPO2_SUCCESS == ret || GX_ALGO_SPO2_FRAME_UNCOMPLETE == ret || GX_ALGO_SPO2_WIN_UNCOMPLETE == ret) + { + if (1 == stResult.final_calc_flg) + { + pstFrameInfo->pstAlgoResult->uchUpdateFlag = (GU8)stResult.final_calc_flg; + pstFrameInfo->pstAlgoResult->snResult[0] = (GS32)(GH3x2x_Round((float)stResult.final_spo2 / 10000)); + pstFrameInfo->pstAlgoResult->snResult[1] = (GS32)stResult.final_r_val; + pstFrameInfo->pstAlgoResult->snResult[2] = (GS32)stResult.final_confi_coeff; + pstFrameInfo->pstAlgoResult->snResult[3] = (GS32)stResult.final_valid_level; + pstFrameInfo->pstAlgoResult->snResult[4] = (GS32)stResult.final_hb_mean; + pstFrameInfo->pstAlgoResult->snResult[5] = (GS32)stResult.final_invalidFlg; + pstFrameInfo->pstAlgoResult->usResultBit = 0x7F; + pstFrameInfo->pstAlgoResult->uchResultNum = GH3x2x_BitCount(pstFrameInfo->pstAlgoResult->usResultBit); + GH3X2X_Spo2AlgorithmResultReport(pstFrameInfo->pstAlgoResult, pstFrameInfo->punFrameCnt[0]); + GH3X2X_DEBUG_ALGO_LOG("[%s] final_spo2:%d, r = %d, final_valid_level:%d\r\n", __FUNCTION__, pstFrameInfo->pstAlgoResult->snResult[0], \ + pstFrameInfo->pstAlgoResult->snResult[1], pstFrameInfo->pstAlgoResult->snResult[3]); + } + } + else + { + emAlgoRet = GH3X2X_RET_RESOURCE_ERROR; + GH3X2X_DEBUG_ALGO_LOG("GH3x2xSpo2AlgoExe error! error code = 0x%x\r\n", ret); + GH3X2X_DEBUG_ALGO_LOG("please feedback to GOODIX!\r\n"); + } + + return (GS8)emAlgoRet; +} + +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv.h new file mode 100644 index 000000000..3b12fccc8 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv.h @@ -0,0 +1,2849 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh_drv.h + * + * @brief gh3x2x driver functions + * + * @version v4.0.1.2 + * + * @author Gooidx Iot Team + * + */ + + +#ifndef _GH3X2X_DRV_H_ +#define _GH3X2X_DRV_H_ + +#include +#include + +#ifndef UNUSED_VAR +#define UNUSED_VAR(X) ((void)(X)) +#endif // UNUSED_VAR + +/* type redefine */ +typedef uint8_t GU8; /**< 8bit unsigned integer type */ +typedef int8_t GS8; /**< 8bit signed integer type */ +typedef uint16_t GU16; /**< 16bit unsigned integer type */ +typedef int16_t GS16; /**< 16bit signed integer type */ +typedef int32_t GS32; /**< 32bit signed integer type */ +typedef uint32_t GU32; /**< 32bit unsigned integer type */ +typedef float GF32; /**< float type */ +typedef double GD64; /**< double type */ +typedef char GCHAR; /**< char type */ +typedef unsigned char GBOOL; /**< bool type */ +typedef int64_t GS64; /**< 64bit signed integer type */ +typedef uint64_t GU64; /**< 64bit unsigned integer type */ + + + +/* communicate interface macro */ +#define __GH3X2X_INTERFACE_I2C__ (1) /**< interface use i2c */ +#define __GH3X2X_INTERFACE_SPI__ (2) /**< interface use spi */ + +/* spi cs type macro */ +#define __GH3X2X_SPI_TYPE_SOFTWARE_CS__ (1) /** cs is software controled in spi module **/ +#define __GH3X2X_SPI_TYPE_HARDWARE_CS__ (2) /** cs is hardtware controled in spi module **/ + +/* int process type macro */ +#define __NORMAL_INT_PROCESS_MODE__ (0) /** int event handle int mode **/ +#define __POLLING_INT_PROCESS_MODE__ (1) /** int event handle polling mode **/ +#define __MIX_INT_PROCESS_MODE__ (2) /** int event handle polling+int mode **/ + +/* protocol serial type macro */ +#define __PROTOCOL_SERIAL_USE_UART__ (1) /**< protocol communicate use UART */ +#define __PROTOCOL_SERIAL_USE_BLE__ (2) /**< protocol communicate use BLE */ + +/* application mode of driver lib */ +#define __DRV_LIB_WITHOUT_ALGO__ (1) /**< not use driver lib interface about algo */ +#define __DRV_LIB_WITH_ALGO__ (2) /**< use driver lib interface about algo */ + +/* algo section run mode*/ +#define __SINGLE_THREAD_MODE__ (0) /** section run in one thread **/ +#define __MULTI_THREAD_MODE__ (1) /** section run in two thread **/ +#define __MULTI_CORE_MODE__ (2) /** section run in two core **/ + +/* log method*/ +#define __GH3X2X_INFO_LOG_DISABLE__ (0) +#define __GH3X2X_INFO_LOG_METHOD_0__ (1) /** need to achieve GH3X2X_PlatformLog, and relay on snprintf in **/ +#define __GH3X2X_INFO_LOG_METHOD_1__ (2) /** need register printf in via GH3X2X_RegisterPrintf **/ + +/* log lv*/ +#define __GH3X2X_INFO_LOG_LV_0__ (0) /** no log **/ +#define __GH3X2X_INFO_LOG_LV_1__ (1) /** include EXAMPLE LOG information **/ +#define __GH3X2X_INFO_LOG_LV_2__ (2) /** include EXAMPLE LOG debug **/ +#define __GH3X2X_INFO_LOG_LV_3__ (4) /** include EXAMPLE LOG waring **/ +#define __GH3X2X_INFO_LOG_LV_4__ (8) /** include EXAMPLE LOG error **/ + +/* algorithm config */ +/** + * @brief support multi algorithm run simultaneously type enum + */ +#define SUPPORT_NO_MULTI_ALGORITHM (0) +#define SUPPORT_MULTI_ALGORITHM (1) +#define SUPPORT_GROUP_MULTI_ALGORITHM (2) + + + +/** + * @brief universal protocol cmd enum + */ +typedef enum +{ + UPROTOCOL_CMD_START = 0x00, /**< start */ + UPROTOCOL_CMD_STOP, /**< stop */ + UPROTOCOL_CMD_EVK_MODE, /**< evk work mode */ + UPROTOCOL_CMD_APP_MODE, /**< app work mode */ + UPROTOCOL_CMD_MCU_ONLINE_MODE, /**< mcu online work mode */ + UPROTOCOL_CMD_MCU_OFFLINE_MODE, /**< mcu offline work mode */ + UPROTOCOL_CMD_TEST_TUNE_MODE, /**< test tune work mode */ + UPROTOCOL_CMD_PASS_THROUGH_MODE, + UPROTOCOL_CMD_IRQ_STATUS_REPORT_ACK, /**< irq status report ack */ + UPROTOCOL_CMD_MPT_MODE, + UPROTOCOL_CMD_IGNORE = 0xFF, /**< ignore */ +} EMUprotocolParseCmdType; + +/** + * @brief i2c addr (7bits) low two bit select enum + */ +enum EMGh3x2xI2cIdSelect +{ + GH3X2X_I2C_ID_SEL_1L0L = 0, /**< i2c ID0 & ID1 pin low */ + GH3X2X_I2C_ID_SEL_1L0H, /**< i2c ID0 pin high & ID1 pin low */ + GH3X2X_I2C_ID_SEL_1H0L, /**< i2c ID0 pin low & ID1 pin high */ + GH3X2X_I2C_ID_SEL_1H0H, /**< i2c ID0 & ID1 pin high */ + GH3X2X_I2C_ID_INVALID, /**< invalid val */ +}; + +/** + * @brief gsensor sensitivity(counts/g) enum + */ +typedef enum +{ + GSENSOR_SENSITIVITY_512_COUNTS_PER_G = 0, /**< sensitivity = 512/g */ + GSENSOR_SENSITIVITY_1024_COUNTS_PER_G, /**< sensitivity = 1024/g */ + GSENSOR_SENSITIVITY_2048_COUNTS_PER_G, /**< sensitivity = 2048/g */ + GSENSOR_SENSITIVITY_4096_COUNTS_PER_G, /**< sensitivity = 4096/g */ + GSENSOR_SENSITIVITY_8192_COUNTS_PER_G, /**< sensitivity = 8192/g */ +} EMGsensorSensitivity; + +/** + * @brief slot index enable config enum + */ +typedef enum +{ + GH3X2X_SET_SLOT_ENABLE = 0, /**< enable slot and last set slot enable */ + GH3X2X_SET_SLOT_DISABLE, /**< disable slot by set */ + GH3X2X_SET_SLOT_DIRECT_ENABLE, /**< only enable slot by set */ +} EMSlotEnableConfigType; + +/** + * @brief irq mode config + */ +typedef enum +{ + IRQ_MODE_LEVEL_HIGH = 0x00, /**< int pin output high level */ + IRQ_MODE_LEVEL_LOW = 0x01, /**< int pin output low level */ + IRQ_MODE_EDGE_RISING = 0x02, /**< int pin output rising edge */ + IRQ_MODE_EDGE_FALLING = 0x03, /**< int pin output falling edge */ +} EMIrqModeConfig; + + + +/** + * @brief wear detect enable type enum + */ +typedef enum +{ + WEAR_DETECT_DISABLE = 0, /**< wear detect disable */ + WEAR_DETECT_ENABLE, /**< wear detect enable */ +} EMWearDetectEnableType; + +/** + * @brief wear detect type enum + */ +typedef enum +{ + WEAR_DETECT_WEAR_ON = 0, /**< detect wear on */ + WEAR_DETECT_WEAR_OFF, /**< detect wear off */ +} EMWearDetectType; + +/** + * @brief wear detect force switch enum + */ +typedef enum +{ + WEAR_DETECT_DONT_FORCE_SWITCH = 0, /**< don't force switch */ + WEAR_DETECT_FORCE_SWITCH, /**< force switch */ +} EMWearDetectForceSwitch; + +/** + * @brief skin color status enum + */ +typedef enum +{ + SKIN_COLOR_STATUS_DARK = 0, /**< dark skin status */ + SKIN_COLOR_STATUS_BROWN, /**< brown skin status */ + SKIN_COLOR_STATUS_YELLOW, /**< yellow skin status */ + SKIN_COLOR_STATUS_FAIR, /**< fair skin status */ +} EMSkinColorStatusType; + +/** + * @brief register struct + */ +typedef struct +{ + GU16 usRegAddr; /**< register address */ + GU16 usRegData; /**< register val */ +} STGh3x2xReg; + +/** + * @brief init config struct type + */ +typedef struct +{ + const STGh3x2xReg *pstRegConfigArr; /**< pointer of register config array */ + GU16 usConfigArrLen; /**< register config array length */ +} STGh3x2xInitConfig; + +/** + * @brief slot rawwdata struct type + */ +typedef struct +{ + GU32 (*punRawdata)[4]; /**< pointer of buffer store 4 adc rawdata, if slot no use, can set NULL */ + GU16 usRawdataCnt; /**< slot rawdata count */ +} STGh3x2xSlotRawdata; + +/** + * @brief get rawwdata struct type + */ +typedef struct +{ + GU8 *puchReadBuffer; /**< pointer of buffer for read rawdata */ + STGh3x2xSlotRawdata stSlotRawdataArr[8]; /**< 8 slot rawdata array */ +} STGh3x2xRawdata; + +/** + * @brief gsensor rawwdata struct type + */ + + +/** + * @brief channnel rawwdata struct type + */ +typedef struct +{ + GU32 *punChRawdataArr; /**< pointer to buffer store channel data, data map e.g. ch0 ch1...chx ch0 */ + GU16 usChRawdataCnt; /**< channel rawdata count output */ + GU32 *punIncompleteChRawdataArr; /**< pointer to last incomplete packet buffer */ + GU32 unIncompleteChMark; /**< last channel rawdata incomplete mark, if chx incomplete bit[x] set 1 */ +} STGh3x2xChannelRawdata; + +/** + * @brief soft lead result + */ +typedef struct +{ + GU16 usEvent; /**< event */ + GU8 uchNeedForceReadFifo; /**< need force read fifo after call GH3X2X_LeadHandle(...) */ +} STSoftLeadResult; + +/** + * @brief HB algorithm output result + */ +typedef struct +{ + GS32 snHbOut; /**< hb algorithm output value */ + GS32 snHbConfi; /**< hb algorithm output confidence */ + GS32 snHbSnr; /**< hb snr */ + GS32 snHbValidLv; /**< hb confidence valid level */ +} STHbAlgoResult; + +/** + * @brief HRV algorithm output result + */ +typedef struct +{ + GS32 snHrvOut0; /**< hrv algorithm output 0 */ + GS32 snHrvOut1; /**< hrv algorithm output 1 */ + GS32 snHrvOut2; /**< hrv algorithm output 2 */ + GS32 snHrvOut3; /**< hrv algorithm output 3 */ + GS32 snHrvNum; /**< hrv effective result num of snHrvOut */ + GS32 snHrvConfi; /**< hrv algorithm output confidence */ +} STHrvAlgoResult; + +/** + * @brief SPO2 algorithm output result + */ +typedef struct +{ + GS32 snSpo2Out; /**< spo2 algorithm output value */ + GS32 snSpo2Rvalue; /**< R value */ + GS32 snSpo2Confi; /**< confidence */ + GS32 snSpo2ValidLevel; /**< valid level */ +} STSpo2AlgoResult; + +/** + * @brief ECG algorithm output result + */ +typedef struct +{ + GS32 snEcgOut; /**< ecg algorithm output value */ + GS32 snEcgBpm; /**< bpm */ + GS32 snEcgSnr; /**< snr */ +} STEcgAlgoResult; + +/** + * @brief algorithm result stuct + */ +typedef struct +{ + GS32* pnAlgoCalcResult; //pointer to algorithm result array + GU16* pusAlgoResIndex; //pointer to frame index array corresponding to algorithm result + GU16 usAlgoResCnt; //number of algorithm result + GU8 uchAlgoResSize; //item number of every algorithm result +} STAlgoCalculateRes; + +typedef struct +{ + GU32 unCapData[4]; + +}STCapRawdata; + +typedef struct +{ + GU32 unTempData[4]; +}STTempRawdata; + +/* byte false or true */ +#define BYTE_FALSE (0) /**< byte false */ +#define BYTE_TRUE (1) /**< byte true */ + +/* return code definitions list */ +#define GH3X2X_RET_READ_FIFO_CONTINUE (4) /**< Fifo not read empty,should read it again */ +#define GH3X2X_RET_RAW_DATA_PKG_OVER (3) /**< already read all of rawdata package data */ +#define GH3X2X_RET_RAW_DATA_PKG_CONTINUE (2) /**< there is rawdata package data left */ +#define GH3X2X_RET_ALGO_HAS_REFRESHED (1) /**< algorithm has refreshed */ +#define GH3X2X_RET_OK (0) /**< there is no error */ +#define GH3X2X_RET_GENERIC_ERROR (-1) /**< a generic error happens */ +#define GH3X2X_RET_PARAMETER_ERROR (-2) /**< parameter error */ +#define GH3X2X_RET_COMM_NOT_REGISTERED_ERROR (-3) /**< i2c/spi operation not registered error */ +#define GH3X2X_RET_COMM_ERROR (-4) /**< i2c/spi communication error */ +#define GH3X2X_RET_RESOURCE_ERROR (-5) /**< resource full or not available error */ +#define GH3X2X_RET_NO_INITED_ERROR (-6) /**< no inited error */ +#define GH3X2X_RET_ALGO_NO_SUPPORTED (-7) /**< the algorithm no supported error */ + +/* irq status mask. */ +#define GH3X2X_IRQ_MSK_CHIP_WAKEUP_BIT (0x0001) /**< chip wakeup */ +#define GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT (0x0002) /**< lead on */ +#define GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT (0x0004) /**< lead off */ +#define GH3X2X_IRQ_MSK_FAST_RECOVERY_BIT (0x0008) /**< fast recovery */ +#define GH3X2X_IRQ_MSK_ADC_DONE_BIT (0x0010) /**< adc sampling done */ +#define GH3X2X_IRQ_MSK_FIFO_WATERMARK_BIT (0x0020) /**< fifo watermark */ +#define GH3X2X_IRQ_MSK_FIFO_FULL_BIT (0x0040) /**< fifo full */ +#define GH3X2X_IRQ_MSK_TUNNING_FAIL_BIT (0x0100) /**< tunning fail */ +#define GH3X2X_IRQ_MSK_TUNNING_DONE_BIT (0x0200) /**< tuning done */ +#define GH3X2X_IRQ_MSK_WEAR_ON_BIT (0x0400) /**< wear on */ +#define GH3X2X_IRQ_MSK_WEAR_OFF_BIT (0x0800) /**< wear off */ +#define GH3X2X_IRQ_MSK_SLOT_TIMEOUT_BIT (0x1000) /**< slot timeout */ +#define GH3X2X_IRQ_MSK_SAMPLE_RATE_ERR_BIT (0x2000) /**< sample rate error */ +#define GH3X2X_IRQ_MSK_CHIP_RESET_BIT (0x4000) /**< chip reset */ + +/* evnet ex*/ +#define GH3X2X_EVENT_EX_BIT_WEAR_LIVING_TYPE ((GU8)1<<0) //0: object/no objiect 1: living/nonliving object +#define GH3X2X_EVENT_EX_BIT_CHIP0_LEAD_ON ((GU8)1<<1) //0: None 1: chip0 lead on +#define GH3X2X_EVENT_EX_BIT_CHIP0_LEAD_OFF ((GU8)1<<2) //0: None 1: chip0 lead off +#define GH3X2X_EVENT_EX_BIT_CHIP1_LEAD_ON ((GU8)1<<3) //0: None 1: chip1 lead on +#define GH3X2X_EVENT_EX_BIT_CHIP1_LEAD_OFF ((GU8)1<<4) //0: None 1: chip1 lead off +#define GH3X2X_EVENT_EX_BIT_MULTI_SENSOR ((GU8)1<<5) //0: None 1: multi-sensor +#define GH3X2X_EVENT_EX_BIT_RS1 ((GU8)1<<6) +#define GH3X2X_EVENT_EX_BIT_RS2 ((GU8)1<<7) + + +/*some reg addr*/ +#define GH3X2X_INT_FIFO_UR_REG_ADDR (0x050A) /**< fifo use cnt */ + +/** + * @brief channel map for function id + */ +#define GH3X2X_FUNC_OFFSET_ADT (0) /**<0 ADT FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_HR (1) /**<1 HR FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_HRV (2) /**<2 HRV FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_HSM (3) /**<3 HSM FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_FPBP (4) /**<4 BPD FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_PWA (5) /**<5 PFA FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_SPO2 (6) /**<6 SPO2 FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_ECG (7) /**<7 ECG FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_PWTT (8) /**<8 PWTT FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_SOFT_ADT_GREEN (9) /**<9 SOFT ADT GREEN FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_BT (10) /**<10 BT FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_RESP (11) /**<11 RESP FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_AF (12) /**<12 AF ADT FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_TEST1 (13) /**<13 TEST1 FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_TEST2 (14) /**<14 TEST2 ADT FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_SOFT_ADT_IR (15) /**<15 SOFT ADT IR FUNC_OFFSET */ +#define GH3X2X_FUNC_OFFSET_RS0 (16) /**<16 */ +#define GH3X2X_FUNC_OFFSET_RS1 (17) /**<17 */ +#define GH3X2X_FUNC_OFFSET_RS2 (18) /**<18 */ +#define GH3X2X_FUNC_OFFSET_LEAD_DET (19) /**<19 */ +#define GH3X2X_FUNC_OFFSET_MAX (20) + +/* Function mode. */ +#define GH3X2X_NO_FUNCTION (0) /**<0x00000000 NO function */ +#define GH3X2X_FUNCTION_ADT ((0x1) << (GH3X2X_FUNC_OFFSET_ADT)) /**<0x00000001 ADT function */ +#define GH3X2X_FUNCTION_HR ((0x1) << (GH3X2X_FUNC_OFFSET_HR)) /**<0x00000002 HR function */ +#define GH3X2X_FUNCTION_HRV ((0x1) << (GH3X2X_FUNC_OFFSET_HRV)) /**<0x00000004 HRV function */ +#define GH3X2X_FUNCTION_HSM ((0x1) << (GH3X2X_FUNC_OFFSET_HSM)) /**<0x00000008 HSM function */ +#define GH3X2X_FUNCTION_FPBP ((0x1) << (GH3X2X_FUNC_OFFSET_FPBP)) /**<0x00000010 FPBP function */ +#define GH3X2X_FUNCTION_PWA ((0x1) << (GH3X2X_FUNC_OFFSET_PWA)) /**<0x00000020 PWA function */ +#define GH3X2X_FUNCTION_SPO2 ((0x1) << (GH3X2X_FUNC_OFFSET_SPO2)) /**<0x00000040 SPO2 function */ +#define GH3X2X_FUNCTION_ECG ((0x1) << (GH3X2X_FUNC_OFFSET_ECG)) /**<0x00000080 ECG function */ +#define GH3X2X_FUNCTION_PWTT ((0x1) << (GH3X2X_FUNC_OFFSET_PWTT)) /**<0x00000100 PWTT function */ +#define GH3X2X_FUNCTION_SOFT_ADT_GREEN ((0x1) << (GH3X2X_FUNC_OFFSET_SOFT_ADT_GREEN)) /**<0x00000200 SOFT ADT GREEN function */ +#define GH3X2X_FUNCTION_BT ((0x1) << (GH3X2X_FUNC_OFFSET_BT)) /**<0x00000400 BT function */ +#define GH3X2X_FUNCTION_RESP ((0x1) << (GH3X2X_FUNC_OFFSET_RESP)) /**<0x00000800 RESP function */ +#define GH3X2X_FUNCTION_AF ((0x1) << (GH3X2X_FUNC_OFFSET_AF)) /**<0x00001000 AF function */ +#define GH3X2X_FUNCTION_TEST1 ((0x1) << (GH3X2X_FUNC_OFFSET_TEST1)) /**<0x00002000 TEST1 function */ +#define GH3X2X_FUNCTION_TEST2 ((0x1) << (GH3X2X_FUNC_OFFSET_TEST2)) /**<0x00004000 TEST2 function */ +#define GH3X2X_FUNCTION_SOFT_ADT_IR ((0x1) << (GH3X2X_FUNC_OFFSET_SOFT_ADT_IR)) /**<0x00008000 SOFT ADT IR function */ +#define GH3X2X_FUNCTION_RS0 ((0x1) << (GH3X2X_FUNC_OFFSET_RS0)) +#define GH3X2X_FUNCTION_RS1 ((0x1) << (GH3X2X_FUNC_OFFSET_RS1)) +#define GH3X2X_FUNCTION_RS2 ((0x1) << (GH3X2X_FUNC_OFFSET_RS2)) +#define GH3X2X_FUNCTION_LEAD_DET ((0x1) << (GH3X2X_FUNC_OFFSET_LEAD_DET)) + + + + + + +/* slot index . */ +#define GH3X2X_SLOT_INDEX_0 (0x0001) /**< slot index 0 */ +#define GH3X2X_SLOT_INDEX_1 (0x0002) /**< slot index 1 */ +#define GH3X2X_SLOT_INDEX_2 (0x0004) /**< slot index 2 */ +#define GH3X2X_SLOT_INDEX_3 (0x0008) /**< slot index 3 */ +#define GH3X2X_SLOT_INDEX_4 (0x0010) /**< slot index 4 */ +#define GH3X2X_SLOT_INDEX_5 (0x0020) /**< slot index 5 */ +#define GH3X2X_SLOT_INDEX_6 (0x0040) /**< slot index 6 */ +#define GH3X2X_SLOT_INDEX_7 (0x0080) /**< slot index 7 */ +#define GH3X2X_SLOT_INDEX_ALL (0x00FF) /**< all slot */ + +/* led driver index . */ +#define GH3X2X_LED_DRV_INDEX_0 (0x0000) /**< led driver index 0 */ +#define GH3X2X_LED_DRV_INDEX_1 (0x0001) /**< led driver index 1 */ + +/* channel map to slot & adc for algorithm */ +#define GH3X2X_CHANNEL_MAP_SLOT0 (0x00) /**< channel map to slot 0 */ +#define GH3X2X_CHANNEL_MAP_SLOT1 (0x20) /**< channel map to slot 1 */ +#define GH3X2X_CHANNEL_MAP_SLOT2 (0x40) /**< channel map to slot 2 */ +#define GH3X2X_CHANNEL_MAP_SLOT3 (0x60) /**< channel map to slot 3 */ +#define GH3X2X_CHANNEL_MAP_SLOT4 (0x80) /**< channel map to slot 4 */ +#define GH3X2X_CHANNEL_MAP_SLOT5 (0xA0) /**< channel map to slot 5 */ +#define GH3X2X_CHANNEL_MAP_SLOT6 (0xC0) /**< channel map to slot 6 */ +#define GH3X2X_CHANNEL_MAP_SLOT7 (0xE0) /**< channel map to slot 7 */ +#define GH3X2X_CHANNEL_MAP_ADC0 (0x00) /**< channel map to adc 0 */ +#define GH3X2X_CHANNEL_MAP_ADC1 (0x08) /**< channel map to adc 1 */ +#define GH3X2X_CHANNEL_MAP_ADC2 (0x10) /**< channel map to adc 2 */ +#define GH3X2X_CHANNEL_MAP_ADC3 (0x18) /**< channel map to adc 3 */ +#define GH3X2X_CHANNEL_MAP(slot, adc) ((slot) | (adc)) /**< calc channel map */ + +#define GH3X2X_DEMO_WORK_MODE_EVK (0) +#define GH3X2X_DEMO_WORK_MODE_APP (1) +#define GH3X2X_DEMO_WORK_MODE_MCU_ONLINE (2) +#define GH3X2X_DEMO_WORK_MODE_MCU_OFFLINE (3) +#define GH3X2X_DEMO_WORK_MODE_TEST_TUNE (4) +#define GH3X2X_DEMO_WORK_MODE_PASS_THROUGH (5) +#define GH3X2X_DEMO_GET_WORK_MODE (6) +#define GH3X2X_DEMO_WORK_MODE_MPT (7) + +/* soft event list*/ +#define GH3X2X_SOFT_EVENT_NEED_FORCE_READ_FIFO ((GU8)1) +#define GH3X2X_SOFT_EVENT_WEAR_OFF ((GU8)2) //event generated by nadt algo +#define GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO ((GU8)4) +#define GH3X2X_SOFT_EVENT_WEAR_ON ((GU8)8) //event generated by nadt algo +#define GH3X2X_SOFT_EVENT_WEAR_ON_ALGO_ADT ((GU8)16) //event generated by adt algo +#define GH3X2X_SOFT_EVENT_WEAR_OFF_ALGO_ADT ((GU8)32) //event generated by adt algo +/* adt confirm status */ +#define GH3X2X_SENSOR_IS_NOT_MOVING ((GU8)0) +#define GH3X2X_SENSOR_IS_MOVING ((GU8)1) +/* soft nadt algo adt status */ +#define GH3X2X_SOFT_ALGO_ADT_DEFAULT ((GU8)0) +#define GH3X2X_SOFT_ALGO_ADT_WEAR_ON ((GU8)1) +#define GH3X2X_SOFT_ALGO_ADT_WEAR_OFF ((GU8)2) + +#define GH3X2X_ALGO_INFO_RECORD_GSENSOR_NUM (3) +#define GH3X2X_ALGO_INFO_RECORD_RAWDARA_NUM (4) +#define GH3X2X_ALGO_INFO_RECORD_AGC_INFO_NUM (4) +#define GH3X2X_ALGO_INFO_RECORD_FALG_NUM (3) +#define GH3X2X_ALGO_INFO_RECORD_RESULT_NUM (8) + +#define GH3X2X_ALGO_RESULT_MAX_NUM (16) + +/// universal protocol packet max len support +#define GH3X2X_UPROTOCOL_PACKET_LEN_MAX (243) + +#define GH3X2X_UPROTOCOL_PACKET_HEADER_LEN (4u) /**< packet header len */ +#define GH3X2X_UPROTOCOL_PACKET_TAIL_LEN (1u) /**< packet tail len */ + + +/// packet header&tail len +#define GH3X2X_UPROTOCOL_PACKET_HEADER_TAIL_LEN (GH3X2X_UPROTOCOL_PACKET_HEADER_LEN + \ + GH3X2X_UPROTOCOL_PACKET_TAIL_LEN) + + +/// universal protocol payload max len +#define GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX (GH3X2X_UPROTOCOL_PACKET_LEN_MAX - \ + GH3X2X_UPROTOCOL_PACKET_HEADER_TAIL_LEN) + +/// Overflow protocol payload max len +#define GH3X2X_UPROTOCOL_OVERFLOW_PAYLOAD_HEADER_LEN (10) +#define GH3X2X_UPROTOCOL_OVERFLOW_PAYLOAD_LEN_MAX (220) + +/// number of channel map id +#define CHANNEL_MAP_ID_NUM (32) + +/// number of channel map id +#define CHANNEL_SLOT_NUM (8) + +/// null val +#define GH3X2X_PTR_NULL ((void *) 0) + +/* ecg sample event type */ +#define ECG_SAMPLE_EVENT_TYPE_SAMPLE (0x01) /**< sample evt type sample config */ +#define ECG_SAMPLE_EVENT_TYPE_SLOT (0x02) /**< sample evt type slot config */ +#define ECG_SAMPLE_EVENT_TYPE_LEAD (0x04) /**< sample evt type lead irq */ +#define ECG_SAMPLE_EVENT_ALL (ECG_SAMPLE_EVENT_TYPE_SAMPLE | ECG_SAMPLE_EVENT_TYPE_SLOT | \ + ECG_SAMPLE_EVENT_TYPE_LEAD) /**< sample evt all */ + +/* ecg sample event type */ +#define ECG_SAMPLE_EVENT_INFO_SAMPLE_STOP (0) /**< sample evt info sample stop */ +#define ECG_SAMPLE_EVENT_INFO_SAMPLE_START (1) /**< sample evt info sample start */ +#define ECG_SAMPLE_EVENT_INFO_LEAD_OFF (0) /**< sample evt info lead off */ +#define ECG_SAMPLE_EVENT_INFO_LEAD_ON (1) /**< sample evt info lead on */ + + + + +typedef struct +{ + GU32 unFunctionID; //Function id use maroc exp: GH3X2X_FUNCTION_HR + GU8 ubChnlNum; + GU8 ubFrameId; + GS16 usGsensor[GH3X2X_ALGO_INFO_RECORD_GSENSOR_NUM]; + GU32 unRawdata[GH3X2X_ALGO_INFO_RECORD_RAWDARA_NUM]; + GU32 unAgcInfo[GH3X2X_ALGO_INFO_RECORD_AGC_INFO_NUM]; + GU32 unFlag[GH3X2X_ALGO_INFO_RECORD_FALG_NUM]; + GU32 unResult[GH3X2X_ALGO_INFO_RECORD_RESULT_NUM]; +} STGh3x2xAlgoInfoRecordData; + + + + +typedef struct +{ + // void (*DumpInit) (void); + //void (*BgLevelSet)(GU16); + //void (*DumpModeSet)(GU16); + //void (*MemSetSpo2IncompleteArr)(void); + //void (*MemSetHbaIncompleteArr)(void); + void (*AlgoInfoRecordInputData)(GS32* ,GU8 ,GU32 ,GU8* ,GU32 ); + void (*AlgoInfoRecordOutputData)(GS32 *, GU8 ); +} STGh3x2xModuleFunList; + + + + + +typedef struct +{ + GU8 puchPacketPayloadArr[GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX + 8]; + GU8 uchFrameIdArr[CHANNEL_MAP_ID_NUM]; +} STGh3x2xProtocolData; + + + + +#define GH3X2X_AGC_REG_AGC_EN 0 +#define GH3X2X_AGC_REG_LED_CURRENT_UP_LIMIT 1 +#define GH3X2X_AGC_REG_LED_CURRENT_DOWN_LIMIT 2 +#define GH3X2X_AGC_REG_LED_CURRENT_DRV0 3 +#define GH3X2X_AGC_REG_LED_CURRENT_DRV1 4 +#define GH3X2X_AGC_REG_TIA_GAIN_RX0 5 +#define GH3X2X_AGC_REG_TIA_GAIN_RX1 6 +#define GH3X2X_AGC_REG_TIA_GAIN_RX2 7 +#define GH3X2X_AGC_REG_TIA_GAIN_RX3 8 +#define GH3X2X_AGC_REG_AGC_SRC 9 +#define GH3X2X_AGC_REG_BG_CANCEL_RX0 10 +#define GH3X2X_AGC_REG_BG_CANCEL_RX1 11 +#define GH3X2X_AGC_REG_BG_CANCEL_RX2 12 +#define GH3X2X_AGC_REG_BG_CANCEL_RX3 13 +#define GH3X2X_AGC_REG_SR_MULIPLIPER 14 +#define GH3X2X_AGC_ECG_PPG_RX_EN 15 + + + + + + + +#define GH3X2X_ENGINEERING_MODE_CHNL_NUM_MAX 32 + +#define GH3X2X_ENGINEERING_MODE_INT_TIME_10_US 0 +#define GH3X2X_ENGINEERING_MODE_INT_TIME_20_US 1 +#define GH3X2X_ENGINEERING_MODE_INT_TIME_30_US 2 +#define GH3X2X_ENGINEERING_MODE_INT_TIME_39_US 3 +#define GH3X2X_ENGINEERING_MODE_INT_TIME_79_US 4 +#define GH3X2X_ENGINEERING_MODE_INT_TIME_158_US 5 +#define GH3X2X_ENGINEERING_MODE_INT_TIME_316_US 6 + + +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_10_K 0 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_25_K 1 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_50_K 2 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_75_K 3 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_100_K 4 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_250_K 5 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_500_K 6 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_750_K 7 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_1000_K 8 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_1250_K 9 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_1500_K 10 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_1750_K 11 +#define GH3X2X_ENGINEERING_MODE_TIA_GAIN_2000_K 12 + +#define GH3X2X_FRAME_FLAG_NUM 8 +#define GH3X2X_AGC_MAIN_SLOT_NUM 8 + +typedef struct +{ + /// save gain + GU8 uchTiaGainRecord[CHANNEL_MAP_ID_NUM]; + GU8 uchTiaGainAfterSoftAgc[CHANNEL_MAP_ID_NUM]; + /// save current of drv0 and drv1 + GU16 uchDrvCurrentAfterSoftAgc[CHANNEL_SLOT_NUM]; + GU16 uchDrvCurrentRecord[CHANNEL_SLOT_NUM]; +} STGh3x2xAgcInfo; + +typedef struct +{ + GU32 unFunctionID; //Function id use maroc exp: GH3X2X_FUNCTION_HR + GU8 uchSampleRateChangeEn; // 0: do not need change sample rate 1: need change sample rate + GU16 usSampleRate; // sample rate (unit Hz range 5Hz~1000Hz) + GU8 uchIntTimeChangeEn; // 0: do not need change integrator time 1: need change intergrator time + GU8 uchIntTime; // use maroc exp: GH3X2X_ENGINEERING_MODE_INT_TIME_10_US + GU8 uchTiaGainChangeEn; // 0: do not need change TIA gain 1: need change TIA gain + GU8 uchTiaGain[GH3X2X_ENGINEERING_MODE_CHNL_NUM_MAX]; //TIA gain for every channel, use maroc GH3X2X_ENGINEERING_MODE_TIA_GAIN_10_K + GU8 uchLedCurrentChangeEn; // 0: do not need change LED current 1: need change change LED current + GU8 uchLedDrv0Current[GH3X2X_ENGINEERING_MODE_CHNL_NUM_MAX]; //LED driver0 current for every channel (unit: mA range: 0~200) + GU8 uchLedDrv1Current[GH3X2X_ENGINEERING_MODE_CHNL_NUM_MAX]; //LED driver1 current for every channel (unit: mA range: 0~200) +} STGh3x2xEngineeringModeSampleParam; + + +typedef struct +{ + GU8 uchEnable; + GU8 uchSpo2ChnlIndex; //0: is not spo2 channel N(N > 0): is spo2 channl + GU8 uchSlotAdc; + GU8 uchCurrentTiaGain; + GU8 uchCurrentDrv; + GU8 uchTiaGainUpLimit; + GU8 uchHaveBakRegFlag; + GU8 uchBakRegAgcEn; + GU8 uchBakRegAgcSrc; + GU8 uchBakRegLedCurrentMin; + GU8 uchBakRegLedCurrentMax; + GU8 uchBakTiaGain; +} STGh3x2xNewAgcMainChnlInfo; + + + +typedef struct +{ + GU16 Sat_CheckCnt[GH3X2X_AGC_MAIN_SLOT_NUM]; /* num of data checked*/ + GU16 Sat_cnt[GH3X2X_AGC_MAIN_SLOT_NUM]; /* sat num of each channel*/ + GU8 Sat_flag; /* sat flag one bit each channel*/ +} STGh3x2xNewAgcMainChnlSat; + +typedef struct +{ + GU32 unMaxRawdata; + GU32 unMinRawdata; + GU32 unSumAdjust; // cacluate drv current and gain + GU32 unSumTrige; // judge whether AGC + GU32 unRawdataMean; + GU32 unLastRawdataMean; + GU16 usSampleRate; + GU16 usAnalysisCnt; // numble of nalysis data + GU8 uchHaveAgcAtLastReadPrd; //0: no agc action at last fifo read period 1: have agc action at last fifo read preiod + GU8 uchDropFlag; +} STGh3x2xNewAgcMainChnlMeanInfo; + +typedef struct +{ + GU8 uchIniteFirst; // inite first time 0:yes 1:not + GU8 uchSeconsCnt; // +} STGh3x2xNewAgcMainChnlIdaelAdjInfo; + +typedef struct +{ + GU32 unLastRawdata; + GU32 unLastLastRawdata; + GU32 unRawdataSum; + GU16 usAnalysisCnt; + GU16 usMoreThanUpLimitPointCnt; + GU16 usMoreThanUpLimitPointCntForBiggerGain; + GU16 usTrigeUpLimitForBiggerGain; // rawdate/256 + GU8 uchEn; + GU8 uchSlotAdcNo; + GU8 uchCurrentGain; +}STGh3x2xNewAgcSubChnlRxInfo; + + +typedef struct +{ + GS32 snCounter; + GS32 sniqCounter; + long long snniVal; + long long snnqVal; + GU8 uchFlagFrPrev; + GU8 uchFastRecoryHistory; + long long snniqAmp[5]; +} STGh3x2xSoftLeadOffDetInfo; + + +typedef struct +{ + GS32 snRsXbuf[100/1 + 1]; + GS32 snBufHead; + GS32 snRsFirState; + GU32 nRsIcounter; + GU32 nRrsDcounter; + GU8 uchFlagFrPrev; + GU32 nRsLastRaw; + GU32 fDownStep; + GU8 uchLinearInterState; + GU8 uchLinearDataUpdate; +} STGh3x2xRsInfo; + + +typedef struct +{ + GU16 usSampleRate; //current sample rate + GU16 usSampleRateForUserSetting; //0: use default sample rate via cfg array others: use usSampleRateForUserSetting + GU32 unChnlEnForUserSetting; //BitN = 1: channel N is enable BitN = 0: channel N is disable + GU8 uchChnlNum; + GU8 uchSlotBit; +} STGh3x2xFunctionInfo; + +typedef struct +{ + GU8 uchUpdateFlag; + GU8 uchResultNum; + GU16 usResultBit; + GS32 snResult[GH3X2X_ALGO_RESULT_MAX_NUM]; +} STGh3x2xAlgoResult; + + + +typedef struct +{ + GU8 uchDownSampleFactor; //0: down sample disable N(N != 0): down sample radio = (N + 1) : 1 + GU8 uchDownSampleCnt; // data will output when uchDownSampleFactor = uchDownSampleCnt +} STGh3x2xDownSampleInfo; + + + +typedef struct +{ + GU32 unFunctionID ; + STGh3x2xFunctionInfo *pstFunctionInfo; + STGh3x2xDownSampleInfo *pstDownSampleInfo; + GU8 uchFuntionChnlLimit; //max chnl num + GU8 *pchChnlMap; + GU32 *punFrameRawdata; + GS16 *pusFrameGsensordata; + STCapRawdata *pstFrameCapdata; + STTempRawdata *pstFrameTempdata; + GU32 *punFrameAgcInfo; + GU32 *punFrameFlag; + GU32 *punIncompleteRawdata; + GU32 *punIncompleteChnlMapBit; + GU8 * puchFrameLastGain; + GU32 * punFrameCnt; + STGh3x2xAlgoResult * pstAlgoResult; + STGh3x2xAlgoResult * pstAlgoRecordResult; +} STGh3x2xFrameInfo; + + +extern GU8 NewAgcMainChelFlag ; + + +void ResisterpGh3x2xModuleFunList(STGh3x2xModuleFunList *pGh3x2xModuleFunList); + +#if 0 +void GH3X2X_DumpInit(void); +void GH3X2X_DumpInitNullFun(void); +void GH3X2X_BgLevelSet(GU16 usRegVal); +void GH3X2X_BgLevelSetNullFun(GU16 usRegVal); +void GH3X2X_DumpModeSet(GU16 usRegVal); +void GH3X2X_DumpModeSetNullFun(GU16 usRegVal); +void GH3X2X_MemSetSpo2IncompleteArr(void); +void GH3X2X_MemSetSpo2IncompleteArrNullFun(void); +void GH3X2X_MemSetHbaIncompleteArr(void); +void GH3X2X_MemSetHbaIncompleteArrNullFun(void); +#endif + + + + + +//extern GU8 * const g_uchPacketPayloadArr;//[GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX]; + +extern STGh3x2xProtocolData * const g_pstGh3x2xProtocolData;//[GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX]; + + +extern void GH3X2X_ProtocolFrameIdClean(GU8 uchFunctionID); + + + + +/** + * @fn void GH3X2X_RegisterHookFunc(void (*pInitHookFunc)(void), + * void (*pStartHookFunc)(void), + * void (*pStopHookFunc)(void), + * void (*pGetRawdataHookFunc)(GU8 *puchReadDataBuffer, GU16 usReadDataLen)) + * + * @brief Register hook function callback. + * + * @attention None + * + * @param[in] pInitHookFunc pointer to init hook function + * @param[in] pStartHookFunc pointer to start hook function + * @param[in] pStopHookFunc pointer to stop hook function + * @param[in] pGetRawdataHookFunc pointer to get rawdata hook function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterHookFunc(void (*pInitHookFunc)(void), + void (*pStartHookFunc)(void), + void (*pStopHookFunc)(void), + void (*pGetRawdataHookFunc)(GU8 *puchReadDataBuffer, GU16 usReadDataLen), + void (*pGetIoStructInfoHookFunc)(const STGh3x2xFrameInfo * const pstFrameInfo), + void (*pResetByProtocolHookFunc)(void), + void (*pConfigSetStartHookFunc)(void), + void (*pConfigSetStopHookFunc)(void), + void (*pfnWriteAlgConfigWithVirtualReg)(GU16 usVirtualRegAddr, GU16 usVirtualRegValue)); + +/** + * @fn void GH3X2X_RegisterDelayUsCallback(void (*pPlatformDelayUsFunc)(GU16 usUsec)) + * + * @brief Register delay us callback function, should register delay us function in platforms + * + * @attention None + * + * @param[in] pPlatformDelayUsFunc pointer to delay us function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterDelayUsCallback(void (*pPlatformDelayUsFunc)(GU16 usUsec)); + +/** + * @fn void GH3X2X_WriteReg(GU16 usRegAddr, GU16 usRegValue) + * + * @brief Write register via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] usRegValue register data + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteReg(GU16 usRegAddr, GU16 usRegValue); + +/** + * @fn GU16 GH3X2X_ReadReg(GU16 usRegAddr) + * + * @brief Read register via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[out] None + * + * @return register data + */ +GU16 GH3X2X_ReadReg(GU16 usRegAddr); + +/** + * @fn GU32 GH3X2X_ReadRegs(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 usLen) + * + * @brief Read multi register via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] pusRegValueBuffer pointer to register value buffer + * @param[in] uchLen registers len + * @param[out] None + * + * @return None + */ +GU32 GH3X2X_ReadRegs(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 usLen); + +/** + * @fn void GH3X2X_ReadFifo(GU8 *puchDataBuffer, GU16 usLen) + * + * @brief Read fifo via i2c or spi + * + * @attention None + * + * @param[in] puchDataBuffer pointer to buffer for fifo rawdata + * @param[in] usLen fifo bytes len + * @param[out] None + * + * @return None + */ +void GH3X2X_ReadFifo(GU8 *puchDataBuffer, GU16 usLen); + +/** + * @fn void GH3X2X_WriteRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb, GU16 usValue) + * + * @brief write register bit field via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] uchLsb lsb of bit field + * @param[in] uchMsb msb of bit field + * @param[in] usRegValue register data + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb, GU16 usValue); + +/** + * @fn GU16 GH3X2X_ReadRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb) + * + * @brief Read register bit field via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] uchLsb lsb of bit field + * @param[in] uchMsb msb of bit field + * @param[out] None + * + * @return register bit field data + */ +GU16 GH3X2X_ReadRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb); + +/** + * @fn GS8 GH3X2X_RegisterSpiOperationFunc(GU8 (*pSpiWriteFunc)(GU8 uchWriteBytesArr[], GU16 usWriteLen), + * GU8 (*pSpiReadFunc)(GU8 uchReadBytesArr[], GU16 usMaxReadLen), + * void (*pSpiCsCtrlFunc)(GU8 uchCsLevelHigh)) + * + * @brief Register spi operation function callback + * + * @attention None + * + * @param[in] pSpiWriteFunc pointer to spi write function + * @param[in] pSpiReadFunc pointer to spi read function + * @param[in] pSpiCsCtrlFunc pointer to spi cs operation function + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR spi operation function pointer parameter error + */ +GS8 GH3X2X_RegisterSpiOperationFunc(GU8 (*pSpiWriteFunc)(GU8 uchWriteBytesArr[], GU16 usWriteLen), + GU8 (*pSpiReadFunc)(GU8 uchReadBytesArr[], GU16 usMaxReadLen), + void (*pSpiCsCtrlFunc)(GU8 uchCsLevelHigh)); + + + + + + + + + + + +/** + * @fn GS8 GH3X2X_RegisterSpiHwCsOperationFunc(GU8 (*pSpiWriteFunc)(GU8 uchWriteBytesArr[], GU16 usWriteLen), + * GU8 (*pSpiWriteF0ReadFunc)(GU8 uchReadBytesArr[], GU16 usMaxReadLen) + * ) + * + * @brief Register spi operation function callback + * + * @attention None + * + * @param[in] pSpiWriteFunc pointer to spi write function + * @param[in] pSpiWriteF1ReadFunc pointer to spi write f1 and read function + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR spi operation function pointer parameter error + */ +GS8 GH3X2X_RegisterSpiHwCsOperationFunc(GU8 (*pSpiWriteFunc)(GU8 uchWriteBytesArr[], GU16 usWriteLen), + GU8 (*pSpiWriteF1ReadFunc)(GU8 uchReadBytesArr[], GU16 usMaxReadLen) + ); + + + + + + + + +/** + * @fn GS8 GH3X2X_RegisterI2cOperationFunc(GU8 uchI2cIdLowTwoBitsSelect, + * GU8 (*pI2cWriteFunc)(GU8 uchDeviceId, const GU8 uchWriteBytesArr[], GU16 usWriteLen), + * GU8 (*pI2cReadFunc)(GU8 uchDeviceId, const GU8 uchCmddBytesArr[], GU16 usCmddLen, + * GU8 uchReadBytesArr[], GU16 usMaxReadLen)) + * + * @brief Register i2c operation function callback + * + * @attention None + * + * @param[in] uchI2cIdLowTwoBitsSelect i2c low two bits addr selected, ref EMGh3x2xI2cIdSelect + * @param[in] pI2cWriteFunc pointer to i2c write function + * @param[in] pI2cReadFunc pointer to i2c read function + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR i2c operation function pointer parameter error + */ +GS8 GH3X2X_RegisterI2cOperationFunc(GU8 uchI2cIdLowTwoBitsSelect, + GU8 (*pI2cWriteFunc)(GU8 uchDeviceId, const GU8 uchWriteBytesArr[], GU16 usWriteLen), + GU8 (*pI2cReadFunc)(GU8 uchDeviceId, const GU8 uchCmddBytesArr[], GU16 usCmddLen, + GU8 uchReadBytesArr[], GU16 usMaxReadLen)); + +/************Start,Ecg Cascade API*************************/ +#if 1 + + + +void GH3X2X_CascadeOperationMasterChip(void); +void GH3X2X_CascadeOperationSlaverChip(void); +void GH3X2X_CascadeSetLogicMasterChip(GU8 uchPhysicsChipIndex); + + +void GH3X2X_SendCmd(GU8 uchCmd); + +/// uchChip2ChannelMap: must set 0x08 +GS16 GH3X2X_CascadeReadFifodata(GU8 *puchGh3x2xReadFifoDataCascade, GU8 *puchGh3x2xReadFifoDataSingleBuf, GU16* pusReadFifoDataLen ,GU16 usFifoReadByteNum, GU8 uchChip2ChannelMap); + +///1: set Ecg Cascade enable. 0: set Ecg Cascade disable +void GH3X2X_CascadeSetEcgEnFlag(GU8 uchCascadeEnFlag); +void GH3X2X_CascadeSetEcgSlaveInitSuccess(GU8 uchCascadeInitSuccess); + +///return 1: Ecg Cascade enable. return 0: Ecg Cascade disable +GU8 GH3X2X_CascadeGetEcgEnFlag(void); + +///the initialization state of the second chip in the cascade +///return 1: Init Success. return 0: Init fail or not init +GU8 GH3X2X_CascadeGetEcgSlaveInitSuccess(void); + +GS8 GH3X2X_CascadeCalibrateECGGain(GU8 *puchReadFifoBuffer, GU16 usFifoBufferLen); + +void GH3X2X_CascadeEcgSlaverLeadDectDis(void); +void GH3X2X_CascadeEcgSlaverLeadDectEn(void); + +GU8 GH3X2X_CascadeGetEcgMasterLeadStatus(GU8 *puchEvent); +GU8 GH3X2X_CascadeGetEcgSlaverLeadStatus(GU8 *puchEvent); + +GU16 GH3X2X_CascadeLeadOnEventPreDeal(GU16 usIrqStatus,GU16 usIrqStatusChip2,GU8 *puchEventEx); +void Gh3x2xEnterCascadeMode(void); +void Gh3x2xExitCascadeMode(void); +#endif +/************End:Ecg Cascade API*************************/ + +/** + * @fn GS8 GH3X2X_ExitLowPowerMode(void) + * + * @brief Exit lowpower mode, in this mode, can read&write reg with gh3x2x + * + * @attention Power consumption bigger than lowpower mode, detaile ref gh3x2x datasheet + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR exit low power mode error + */ +GS8 GH3X2X_ExitLowPowerMode(void); + +/** + * @fn GS8 GH3X2X_EnterLowPowerMode(void) + * + * @brief Enter lowpower mode, in this mode, can't read&write reg with gh3x2x + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR enter low power mode error + */ +GS8 GH3X2X_EnterLowPowerMode(void); + +/** + * @fn void GH3X2X_RegisterResetPinControlFunc(void (*pResetPinLevelControlFunc)(GU8 uchPinLevel)) + * + * @brief Register reset pin level control function + * + * @attention Pin level set val should define as 1 [high level] or 0 [low level]; + * + * @param[in] pResetPinLevelControlFunc pointer to set reset pin level function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterResetPinControlFunc(void (*pResetPinLevelControlFunc)(GU8 uchPinLevel)); + +/** + * @fn GS8 GH3X2X_HardReset(void) + * + * @brief Gh3x2x softreset via i2c/spi, can read&write reg with gh3x2x after reset + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR reset pin control function not register + */ +GS8 GH3X2X_HardReset(void); + +/** + * @fn void GH3X2X_SendCmd(GU8 uchCmd) + * + * @brief Send cmd via i2c or spi + * + * @attention None + * + * @param[in] uchCmd cmd + * @param[out] None + * + * @return None + */ +void GH3X2X_SendCmd(GU8 uchCmd); + +/** + * @fn void GH3X2X_WearDetectEnable(EMWearDetectEnableType emWearDetectEnable) + * + * @brief enable or disable wear detect + * + * @attention None + * + * @param[in] emWearDetectEnable enable or disable @ref EMWearDetectEnableType + * @param[out] None + * + * @return None + */ +void GH3X2X_WearDetectEnable(EMWearDetectEnableType emWearDetectEnable); + +/** + * @fn void GH3X2X_ResetHardAdt(void) + * + * @brief Gh3x2x reset hard adt + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_ResetHardAdt(void); + +/** + * @fn GS8 GH3X2X_WearDetectSwitchTo(EMWearDetectType emWearDetectType, EMWearDetectForceSwitch emForceSwitch) + * + * @brief Gh3x2x switch to detect wear on/off type + * + * @attention Should follow that use WEAR_DETECT_DONT_FORCE_SWITCH @wear on/off irq status process. + * If want force switch to detect on/off, should use WEAR_DETECT_FORCE_SWITCH. careful!!! + * + * @param[in] emWearDetectType switch to detect type @ref EMWearDetectType + * @param[in] emForceSwitch force switch type @ref EMWearDetectForceSwitch + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR detect type equal last type, don't need to switch + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_WearDetectSwitchTo(EMWearDetectType emWearDetectType, EMWearDetectForceSwitch emForceSwitch); + +/** + * @fn EMSkinColorStatusType GH3X2X_GetSkinStatus(void) + * + * @brief Get gh3x2x skin color status + * + * @attention Must using when chip hard wear detect module enable, if not always return 0 + * + * @param[in] None + * @param[out] None + * + * @return skin color status @ref EMSkinColorStatusType + */ +EMSkinColorStatusType GH3X2X_GetSkinStatus(void); + +/** + * @fn GS8 GH3X2X_SoftReset(void) + * + * @brief Gh3x2x softreset via i2c/spi, can read&write reg with gh3x2x after reset + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR exit low power mode error + */ +GS8 GH3X2X_SoftReset(void); + +/** + * @fn GS8 GH3X2X_LoadNewRegConfigArr(const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen) + * + * @brief Load new gh3x2x reg config array + * + * @attention If reg val don't need verify, should set reg addr bit 12; + * If reg is virtual reg, should set reg addr bit 13; + * e.g. need config reg 0x0000: 0x0611 + * {0x0000, 0x0611} //verify write by read reg + * {0x1000, 0x0611} //don't need verify write val + * {0x2000, 0x0611} //set virtual reg + * + * @param[in] pstRegConfigArr pointer to the reg struct array + * @param[in] usRegConfigLen reg struct array length + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_COMM_ERROR gh3x2x communicate error + */ +GS8 GH3X2X_LoadNewRegConfigArr(const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen, GU8 uchChipIndex); + +/** + * @fn GS8 GH3X2X_DumpRegs(STGh3x2xReg *pstDumpRegsArr, GU16 usDumpRegsStartAddr, GU16 usDumpRegsLen) + * + * @brief Dump gh3x2x regs + * + * @attention usDumpRegsStartAddr only allow even address, if param set odd address val that val & 0xFFFE in api; + * If address greater than reg max addres 0xFFFE, it will return GH3X2X_RET_GENERIC_ERROR. + * + * @param[out] pstDumpRegsArr pointer to the dump reg struct output + * @param[in] usDumpRegsStartAddr dump reg address + * @param[in] usDumpRegsLen dump reg length + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR dump gh3x2x address out of bounds + */ +GS8 GH3X2X_DumpRegs(STGh3x2xReg *pstDumpRegsArr, GU16 usDumpRegsStartAddr, GU16 usDumpRegsLen); + +/** + * @fn void *GH3X2X_Memcpy(void *pDest, const void *pSrc, GU32 unByteSize) + * + * @brief memcpy() Re-implementation + * + * @attention None + * + * @param[in] pSrc pointer to source buffer + * @param[in] unByteSize source buffer byte size + * @param[out] pDest pointer to destination buffer + * + * @return pointer to destination buffer + */ +void *GH3X2X_Memcpy(void *pDest, const void *pSrc, GU32 unByteSize); + +/** + * @fn void *GH3X2X_Memset(void* pDest, GCHAR chVal, GU32 unByteSize) + * + * @brief memset() Re-implementation + * + * @attention None + * + * @param[in] chVal char val for set + * @param[in] unByteSize source buffer len + * @param[out] pDest pointer to destination buffer + * + * @return pointer to destination buffer + */ +void *GH3X2X_Memset(void* pDest, GCHAR chVal, GU32 unByteSize); + +/** + * @fn GU32 GH3X2X_Strlen(const GCHAR *pszSrc) + * + * @brief strlen() Re-implementation + * + * @attention None + * + * @param[in] pszSrc pointer to string + * @param[out] None + * + * @return string len + */ +GU32 GH3X2X_Strlen(const GCHAR *pszSrc); + +/** + * @fn GS8 GH3X2X_CommunicateConfirm(void) + * + * @brief Communication operation interface confirm + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_COMM_ERROR gh3x2x communicate error + */ +GS8 GH3X2X_CommunicateConfirm(void); + +/** + * @fn GS8 GH3X2X_Init(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam) + * + * @brief Init gh3x2x with configure parameters + * + * @attention None + * + * @param[in] pstGh3x2xInitConfigParam pointer to gh3x2x init config param + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_COMM_ERROR gh3x2x communicate error + */ +GS8 GH3X2X_Init(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam); + +/** + * @fn GS8 GH3X2X_StartSampling(void) + * + * @brief Start gh3x2x sampling + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + * @retval #GH3X2X_RET_GENERIC_ERROR gh3x2x has started, need restart should call GH3X2X_StopSampling then start + */ +GS8 GH3X2X_StartSampling(void); + +/** + * @fn GS8 GH3X2X_StopSampling(void) + * + * @brief Stop gh3x2x sampling + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_StopSampling(void); + +/** + * @fn GU16 GH3X2X_GetIrqStatus(void) + * + * @brief Get irq status reg val + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return irq status val, ref irq status mask + */ +GU16 GH3X2X_GetIrqStatus(void); + +/** + * @fn GS16 GH3X2X_ReadFifodata(GU8 *puchGh3x2xReadFifoData, GU16* pusReadFifoDataLen) + * + * @brief Read Gh3x2x Fifo Data + * + * @attention None + * + * @param[in] None + * @param[out] puchGh3x2xReadFifoData pointer to Gh3x2x fifo data + * @param[out] pusReadFifoDataLen pointer to Gh3x2x fifo data length in byte + * + * @return error code + * @retval #GH3X2X_RET_OK return read fifo successful + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo is not empty + */ +GS16 GH3X2X_ReadFifodata(GU8 *puchGh3x2xReadFifoData, GU16* pusReadFifoDataLen ,GU16 usFifoReadByteNum); + + +/** + * @fn GS16 GH3X2X_GetRawdata(STGh3x2xRawdata *pstGh3x2xRawdata, GU16* usFifoLength) + * + * @brief Get rawdata from fifo + * + * @attention None + * + * @param[in] None + * @param[out] pstGh3x2xRawdata pointer to rawdata struct output + * @param[out] usFifoLength pointer to read fifo bytes + * + * @return error code + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo not empty + */ +GS16 GH3X2X_GetRawdata(STGh3x2xRawdata *pstGh3x2xRawdata, GU16* usFifoLength); + +/** + * @fn void GH3X2X_UnpackRawdataPackage(STGh3x2xSlotRawdata *pstSlotRawdataArr, + * GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen) + * + * @brief Unpack to 8 slot rawdata from read fifo data buffer + * + * @attention This function should use in get rawdata hook; + * param pstSlotRawdataArr size must equal 8, defile like stSlotRawdataArr[8]. + * + * @param[out] pstSlotRawdataArr pointer to 8 slot rawdata struct output + * @param[in] puchReadRawdataBuffer pointer to read fifo buffer + * @param[in] usReadRawdataLen read fifo rawdata data len (bytes) + * + * @return None + */ +void GH3X2X_UnpackRawdataPackage(STGh3x2xSlotRawdata *pstSlotRawdataArr, + GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen); + +/** + * @fn GS16 GH3X2X_GetRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + * GU8 *puchReadRawdataBuffer, GU16* usFifoLength, GU8 uchChannelMapCnt, + * GU8 *puchChannelMapArr) + * + * @brief Get rawdata from fifo with channel map + * + * @attention None + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[out] pstGh3x2xChannelRawdata pointer to channel rawdata struct output + * @param[out] usFifoLength pointer to read fifo data length in bytes + * + * @return GH3X2X_RET_OK return read fifo successful + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo is not empty + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS16 GH3X2X_GetRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + GU8 *puchReadRawdataBuffer, GU16* usFifoLength, GU8 uchChannelMapCnt, + GU8 *puchChannelMapArr); + +/** + * @fn GS8 GH3X2X_ChannelMapRawdataClear(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata) + * + * @brief clear channel map rawdata struct + * + * @attention This function must use before get rawdata by onne kind channel map + * e.g. channel map start/stop need clear + * + * @param[in] pstGh3x2xChannelRawdata pointer to channel rawdata struct + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_ChannelMapRawdataClear(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata); + +/** + * @fn GS8 GH3X2X_UnpackRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + * GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr) + * + * @brief Unpack to channel rawdata from read fifo data buffer; + * if last channel rawdata incomplete, should change fifo watermark + * + * @attention This function should use in get rawdata hook + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] usReadRawdataLen read data length + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[out] pstGh3x2xChannelRawdata pointer to channel rawdata struct + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_UnpackRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr); + +/** + * @fn GS8 GH3X2X_SlotEnableConfig(GU16 usSlotEnableConfig, EMSlotEnableConfigType emSlotEnableConfigType) + * + * @brief Slot enable config + * + * @attention Set slot enable or disable, if just need enable slot by enable config param + * + * @param[in] usSlotEnableConfig slot enable index , @ref GH3X2X_SLOT_INDEX_0 ... GH3X2X_SLOT_INDEX_ALL + * @param[in] emSlotEnableConfigType slot config type, @ref EMSlotEnableConfigType + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_SlotEnableConfig(GU16 usSlotEnableConfig, EMSlotEnableConfigType emSlotEnableConfigType); + +/** + * @fn GS8 GH3X2X_FifoWatermarkThrConfig(GU16 usFifoWatermarkThr) + * + * @brief Fifo water mark threshold config + * + * @attention Watermark threshold val must in (2, 800]. if val <= 2, will set 3, if val > 800, set 800; + * Be careful that fifo_use_cnt greater than val, gh3x2x willn't generate fifo_watermark interrupt after! + * + * @param[in] usFifoWatermarkThr watermark threshold val + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + */ +GS8 GH3X2X_FifoWatermarkThrConfig(GU16 usFifoWatermarkThr); + +/** + * @fn GU16 GH3X2X_GetFifoWatermarkThr(void) + * + * @brief Get fifo water mark threshold + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return fifo water mark threshold + */ +GU16 GH3X2X_GetFifoWatermarkThr(void); + +/** + * @fn void GH3X2X_SetMaxNumWhenReadFifo(GU16 usMaxNum) + * + * @brief Set max number of rawdata read from fifo every time + * + * @attention None. + * + * @param[in] usMaxNum max number of rawdata read from fifo + * @param[out] None + * + * @return None + */ +void GH3X2X_SetMaxNumWhenReadFifo(GU16 usMaxNum); + +/** + * @fn GS8 GH3X2X_SlotLedCurrentConfig(GU8 uchSlotIndex, GU8 uchDrvIndex, GU8 uchCurrentVal) + * + * @brief Slot led current config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchDrvIndex driver index @ref GH3X2X_LED_DRV_INDEX_0 ... GH3X2X_LED_DRV_INDEX_1 + * @param[in] uchCurrentVal current val + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_SlotLedCurrentConfig(GU8 uchSlotIndex, GU8 uchDrvIndex, GU8 uchCurrentVal); + +/** + * @fn GU8 GH3X2X_GetSlotLedCurrent(GU8 uchSlotIndex, GU8 uchDrvIndex) + * + * @brief Get slot led current config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchDrvIndex driver index @ref GH3X2X_LED_DRV_INDEX_0 ... GH3X2X_LED_DRV_INDEX_1 + * @param[out] None + * + * @return current val. if param error, return val always equal 0 + */ +GU8 GH3X2X_GetSlotLedCurrent(GU8 uchSlotIndex, GU8 uchDrvIndex); + +/** + * @fn GS8 GH3X2X_SlotLedTiaGainConfig(GU8 uchSlotIndex, GU8 uchAdcIndex, GU8 uchGainVal) + * + * @brief Slot gain config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchAdcIndex adc index [0-3] + * @param[in] uchGainVal tia gain val [0-12] + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_SlotLedTiaGainConfig(GU8 uchSlotIndex, GU8 uchAdcIndex, GU8 uchGainVal); + +/** + * @fn GU8 GH3X2X_GetSlotLedTiaGain(GU8 uchSlotIndex, GU8 uchAdcIndex) + * + * @brief Get slot gain config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchAdcIndex adc index [0-3] + * @param[out] None + * + * @return tia gain val. if param error, return val always equal 0 + */ +GU8 GH3X2X_GetSlotLedTiaGain(GU8 uchSlotIndex, GU8 uchAdcIndex); + +/** + * @fn GS8 GH3X2X_AdcBgcThrConfig(GU8 uchAdcIndex, GU8 uchBgcThrVal) + * + * @brief adc bgc thr config + * + * @attention None + * + * @param[in] uchAdcIndex adc index [0-3] + * @param[in] uchBgcThrVal bgc thr val [0-7] + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_AdcBgcThrConfig(GU8 uchAdcIndex, GU8 uchBgcThrVal); + +/** + * @fn GU8 GH3X2X_GetAdcBgcThr(GU8 uchAdcIndex) + * + * @brief Get adc bgc thr config + * + * @attention None + * + * @param[in] uchAdcIndex adc index [0-3] + * @param[out] None + * + * @return tia gain val. if param error, return val always equal 0 + */ +GU8 GH3X2X_GetAdcBgcThr(GU8 uchAdcIndex); + +/** + * @fn GS8 GH3X2X_IrqWidthConfig(GU16 usIrqPulseWidth, GU16 usIrqColdWidth) + * + * @brief Irq width config + * + * @attention Irq val must in [0, 2047]. real_width = (val + 1) * low_clk_tick; + * low_clk default 32k, if set ext clk enable that use low_ext_clk; + * + * @param[in] usIrqPulseWidth irq pulse width val + * @param[in] usIrqColdWidth irq cold width val + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + */ +GS8 GH3X2X_IrqWidthConfig(GU16 usIrqPulseWidth, GU16 usIrqColdWidth); + +/** + * @fn GS8 GH3X2X_IrqModeConfig(EMIrqModeConfig emIrqMode) + * + * @brief Irq mode config + * + * @attention None + * + * @param[in] emIrqMode irq mode config @ref EMIrqModeConfig + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + */ +GS8 GH3X2X_IrqModeConfig(EMIrqModeConfig emIrqMode); + +/** + * @fn GS8 GH3X2X_HsiClockCalibration(void) + * + * @brief Calibration Hsi(high-speed internal) clock + * + * @attention must use 4M clock input @OSCIN pin + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR input clock is unstable, or sampling was started + */ +GS8 GH3X2X_HsiClockCalibration(void); + +/** + * @fn GS8 GH3X2X_LsiClockCalibration(void) + * + * @brief Calibration Lsi(low-speed internal) clock + * + * @attention must use 4M clock input @OSCIN pin, take case that will consume about 100ms + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR input clock is unstable, or sampling was started + */ +GS8 GH3X2X_LsiClockCalibration(void); + + + + +/** + * @fn void GH3X2X_SoftLedADJAutoADJInt(void) + * + * @brief init some agc parameter + * + * @attention + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_SoftLedADJAutoADJInt(void); + +/** + * @fn void GH3X2X_LedAgcProcess(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo) + * + * @brief led agc process function + * + * @attention None + * + * @param[in] puchReadFifoBuffer pointer to read fifo data buffer + * @param[in] usFifoLen read fifo data buffer length + * @param[out] None + * + * @return None + */ +void GH3X2X_LedAgcProcess(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo); + +/** + * @fn void GH3X2X_LedAgcProcessEx(GU8* puchReadFifoBuffer) + * + * @brief led agc process function + * + * @attention None + * + * @param[in] puchReadFifoBuffer pointer to read fifo data buffer + * @param[out] None + * + * @return None + */ +void GH3X2X_LedAgcProcessEx(GU8* puchReadFifoBuffer); + +void GH3x2xNewAgcMeanInfoReset(GU8 uchSlotEnChange); + +/** + * @fn void GH3X2X_RegisterReadPinStatusFunc(GU8 (*pReadIntPinStatusFunc)(void), + * GU8 (*pReadResetPinStatusFunc)(void), + * GU8 (*pReadSpcsPinStatusFunc)(void), + * GU8 (*pReadSpdoPinStatusFunc)(void)) + * + * @brief Register read pin status function + * + * @attention Only use for debug, read gh3x2x some pin status can debug some hardware errors; + * Pin status return should define as 1 [high level] or 0 [low level]; + * + * @param[in] pReadIntPinStatusFunc pointer to read int pin staus function + * @param[in] pReadResetPinStatusFunc pointer to read reset pin staus function + * @param[in] pReadSpcsPinStatusFunc pointer to read spcs pin staus function + * @param[in] pReadSpdoPinStatusFunc pointer to read spdo pin staus function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterReadPinStatusFunc(GU8 (*pReadIntPinStatusFunc)(void), + GU8 (*pReadResetPinStatusFunc)(void), + GU8 (*pReadSpcsPinStatusFunc)(void), + GU8 (*pReadSpdoPinStatusFunc)(void)); + +/** + * @fn GCHAR *GH3X2X_GetDriverLibVersion(void) + * + * @brief Get driver version + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return library version string + */ +GCHAR *GH3X2X_GetDriverLibVersion(void); +GCHAR *GH3X2X_GetProtocolVersion(void); +GCHAR *GH3X2X_GetVirtualRegVersion(void); + +/** + * @fn void GH3X2X_RegisterGetFirmwareVersionFunc(GCHAR* (*pGetFirmwareVersionFunc)(void)) + * + * @brief Register get firmware version function + * + * @attention None + * + * @param[in] pGetFirmwareVersionFunc pointer to get firmware versionn function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterGetFirmwareVersionFunc(GCHAR* (*pGetFirmwareVersionFunc)(void), + GCHAR* (*pGetDemoVersionFunc)(void), + GCHAR* (*pGetBootloaderVersionFunc)(void)); + +/** + * @fn EMUprotocolParseCmdType GH3X2X_UprotocolParseHandler(GU8 *puchRespondBuffer, GU16 *pusRespondLen, + * GU8 *puchRecvDataBuffer, GU16 usRecvLen) + * + * @brief universal protocol parse handler, parse protocol receive data + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * @param[in] puchRecvDataBuffer pointer to receive data buffer + * @param[in] usRecvLen receive data len + * + * @return @ref EMUprotocolParseCmdType + */ +EMUprotocolParseCmdType GH3X2X_UprotocolParseHandler(GU8 *puchRespondBuffer, GU16 *pusRespondLen, + GU8 *puchRecvDataBuffer, GU16 usRecvLen); + +/** + * @fn GU8 GH3X2X_UprotocolPacketMaxLenConfig(GU8 uchPacketMaxLen) + * + * @brief packet max len support, default len is 243 + * + * @attention uchPacketMaxLen val must at [20, 243] + * + * @param[out] None + * @param[in] uchPacketMaxLen packet max len + * + * @return packet max len after config + */ +GU8 GH3X2X_UprotocolPacketMaxLenConfig(GU8 uchPacketMaxLen); + +/** + * @fn GS8 GH3X2X_SendRawDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoRawdataLen, GU8 uchChannelMapArr[], GU8 uchChannelMapCnt, + * STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity, + * GU8 uchChannelMapId, GU32 *punLastIncompleteMark, GU32 *punIncompleteRawdataArr) + * + * @brief Pack rawdata with g sensor data + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to protocol pkg data. + * @param[out] pusRespondLen pointer to protocol pkg data length + * @param[in] puchFifoRawdata pointer to data buffer of rawdata + * @param[in] usFifoRawdataLen data num of rawdata buf + * @param[in] uchChannelMapArr pointer to channel map array + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum g sensor data number + * @param[in] emGsSensitivity g sensor sensitivity + * @param[in] uchChannelMapId channel map id(0 - 5) + * @param[in] punLastIncompleteMark incomplete mark + * @param[in] punIncompleteRawdataArr incomplete data array + * @return error code + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_RAW_DATA_PKG_OVER return already read all the package data + * @retval #GH3X2X_RET_RAW_DATA_PKG_CONTINUE return should read rawdata package data again + * @retval #GH3X2X_RET_RESOURCE_ERROR return not enough data + */ + + +/** + * @fn GS8 GH3X2X_CustomizeFuncStartedBitSet(void) + * + * @brief Set Customize started bitmap + * + * @attention None + * + * @param[out] None + * @param[in] None + * + * @return error code + * @retval #GH3X2X_RET_OK return algorithm run successfully + */ +GS8 GH3X2X_CustomizeFuncStartedBitSet(void); + +/** + * @fn GS8 GH3X2X_CustomizeFuncStartedBitClear(void) + * + * @brief Clear Customize started bitmap + * + * @attention None + * + * @param[out] None + * @param[in] None + * + * @return error code + * @retval #GH3X2X_RET_OK return algorithm run successfully + */ +GS8 GH3X2X_CustomizeFuncStartedBitClear(void); + +/** + * @fn GS8 GH3X2X_GetRawdataForAlgorithmEx(GU8 *puchPackageDataBuffer) + * + * @brief Get rawdata package for algorithm + * + * @attention buffer size must define greater or equal to ((fifo_thr + n) * 4 + 5) + * + * @param[in] None + * @param[out] puchPackageDataBuffer pointer to package data output + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_RESOURCE_ERROR resource error + */ +GS8 GH3X2X_GetRawdataForAlgorithmEx(GU8 *puchPackageDataBuffer ,GU16 uchFifoReadByteNum); + +/** + * @fn GS8 GH3X2X_AllFuncDeinit(void) + * + * @brief deinit all func + * + * @attention if disable all or chip reset, need call this api + * + * @param[in] None + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return algorithm deinit error + * @retval #GH3X2X_RET_ALGO_NO_SUPPORTED return algorithm no supported error + */ +GS8 GH3X2X_AllFuncDeinit(void); + +/** + * @fn GS8 GH3X2X_AllFuncDeinitEx(void) + * + * @brief deinit all func + * + * @attention this api not deinit algorithm + * + * @param[in] None + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return algorithm deinit error + * @retval #GH3X2X_RET_ALGO_NO_SUPPORTED return algorithm no supported error + */ +GS8 GH3X2X_AllFuncDeinitEx(void); + +/** + * @fn void GH3X2X_ReportIrqStatus(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU16 usIrqStatus) + * + * @brief report irq status of Gh3x2x + * + * @attention none + * + * @param[out] puchRespondBuffer pointer to protocol pkg data. + * @param[out] pusRespondLen pointer to protocol pkg data length + * @param[in] usIrqStatus irq status need report + * @return none + */ +void GH3X2X_ReportIrqStatus(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU16 usIrqStatus); + + + + + + + + +/** + * @fn void GhMoveDetectByGsData(STGsensorRawdata* stGsData, GU16 usGsDataCnt, GU8 uchCheckWindowSize) + + * + * @brief Move detection by software. + * + * @attention None + * + * @param[in] stGsData gsensor data buffer + * @param[in] usGsDataCnt gsensor data count + * @param[in] uchCheckWindowSize the window size of cheak moving peak num + * @param[out] None + * + * @return None + */ +void GhMoveDetectByGsData(GS16* pusGsData, GU16 usGsDataCnt); + + + + + +/** + * @fn GU8 Gh3x2x_GetMoveDetStatus(void) + * + * @brief Get status of movement detected + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return GH3X2X_SENSOR_IS_NOT_MOVING/GH3X2X_SENSOR_IS_MOVING + */ +GU8 Gh3x2x_GetMoveDetStatus(void); + +/** + * @fn GU8 Gh3x2x_GetAdtGsensorDetectStatus(void) + * + * @brief Get status of Gsensor detect status + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return g_uchGsensorDetectEn 0:disable 1:enable + */ +GU8 Gh3x2x_GetAdtGsensorDetectStatus(void); + +/** + * @fn void Gh3x2x_SetAdtGsensorDetectStatus(void) + * @brief set g_uchGsensorDetectEn + * @param[in] None + * @param[out] None + * @return None + */ +void Gh3x2x_SetAdtGsensorDetectStatus(void); + +/** + * @fn void Gh3x2x_ClearAdtGsensorDetectStatus(void) + * @brief clear g_uchGsensorDetectEn + * @param[in] None + * @param[out] None + * @return None + */ +void Gh3x2x_ClearAdtGsensorDetectStatus(void); + +/** + * @fn GS8 GH3X2X_SendAdtRawdataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * STAlgoCalculateRes* pstAlgoRes, STGsensorRawdata *pstGsAxisValueArr, + * GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X adt rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] pstAlgoRes pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ + + + + +/** + * @fn GS8 GH3X2X_SendAdtRawdataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoDataLen, STAlgoCalculateRes* pstAlgoRes, STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity); + * + * @brief pack GH3X2X adt rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] usFifoDataLen gh3x2x fifo data len in byte + * @param[in] pstAlgoRes pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ + + + + +/** + * @fn GS8 GH3X2X_SendZipAdtRawdataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * STAlgoCalculateRes* pstAlgoRes, STGsensorRawdata *pstGsAxisValueArr, + * GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X Zip adt rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] pstAlgoRes pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ + + + + +/** + * @fn GS8 GH3X2X_SendZipAdtRawdataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoDataLen, STAlgoCalculateRes* pstAlgoRes, STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity); + * + * @brief pack GH3X2X Zip adt rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] usFifoDataLen gh3x2x fifo data len in byte + * @param[in] pstAlgoRes pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ + + + + +/** + * @fn GU32 GH3X2X_GetFuncModeAvailable(void) + * + * @brief Get all function mode available + * + * @attention None + * + * @param[out] None + * @param[in] None + * @return function mode, @ref GH3X2X_NO_FUNCTION ... GH3X2X_FUNCTION_PWTT + */ +GU32 GH3X2X_GetFuncModeAvailable(void); + +/** + * @fn GU32 GH3X2X_GetFuncModeOpened(void) + * + * @brief Get function mode that already opened + * + * @attention None + * + * @param[out] None + * @param[in] None + * @return function mode, @ref GH3X2X_NO_FUNCTION ... GH3X2X_FUNCTION_PWTT + */ +GU32 GH3X2X_GetFuncModeOpened(void); + +/** + * @fn GU32 GH3X2X_GetTargetFuncMode(void) + * + * @brief Get function mode that will be opened or closed + * + * @attention None + * + * @param[out] None + * @param[in] None + * @return function mode, @ref GH3X2X_NO_FUNCTION ... GH3X2X_FUNCTION_PWTT + */ +GU32 GH3X2X_GetTargetFuncMode(void); + +/** + * @fn GS8 GH3X2X_DecodeRegCfgArr(GU32* punRunMode, const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen) + * + * @brief Analyze reg cfg array to get the run mode. + * + * @attention None + * + * @param[in] pstRegConfigArr pointer to reg config array + * @param[in] usRegConfigLen reg config array length + * @param[out] punRunMode pointer to run mode contained in reg config array + * + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return parameter error + */ +GS8 GH3X2X_DecodeRegCfgArr(GU32* punRunMode, const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen); + +/** + * @fn GU8 GH3X2X_GetGsensorEnableFlag(void) + * + * @brief Inquire if need gsensor data + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return 1: need gsensor data 0: not need gsensor data + */ +GU8 GH3X2X_GetGsensorEnableFlag(void); +GU8 GH3X2X_GetCapEnableFlag(void); +GU8 GH3X2X_GetTempEnableFlag(void); +/** + * @fn STSoftLeadResult GH3X2X_LeadHandle(GU16 usIrqStatus, GU8 *puchReadFifoBuffer, GU16* pusFifoBufferLen) + * + * @brief ecg soft lead handle + * + * @attention None + * + * @param[in] usIrqStatus irq status + * @param[in] puchReadFifoBuffer pointer to read fifo data buffer + * @param[in] usFifoBufferLen read fifo buffer len + * @param[out] None + * + * @return soft lead handle process, @ref STSoftLeadResult + */ +STSoftLeadResult GH3X2X_LeadHandle(GU16 usIrqStatus, GU8 *puchReadFifoBuffer, GU16* pusFifoBufferLen); + +/** + * @fn STSoftLeadResult GH3X2X_LeadHandleEx(GU16 usIrqStatus, GU8 *puchReadFifoBuffer) + * + * @brief ecg soft lead handle + * + * @attention use after GH3X2X_GetRawdataForAlgorithm or GH3X2X_GetRawdataForAlgorithmEx + * + * @param[in] usIrqStatus irq status + * @param[in] puchReadFifoBuffer pointer to read fifo data buffer + * @param[out] None + * + * @return soft lead handle process, @ref STSoftLeadResult + */ +//STSoftLeadResult GH3X2X_LeadHandleEx(GU16 usIrqStatus, GU8 *puchReadFifoBuffer); + +/** + * @fn GU32 GH3X2X_GetSoftEvent(void) + * @brief Get soft event + * @param[in] None + * @param[out] Soft event + * + * @return soft event + */ +GU32 GH3X2X_GetSoftEvent(void); + +/** + * @fn void GH3X2X_SetSoftEvent(GU32 unEvent) + * @brief set soft event + * @param[in] uchEvent + * @param[out] None + * @return None + */ +void GH3X2X_SetSoftEvent(GU32 unEvent); + +/** + * @fn void GH3X2X_ClearSoftEvent(GU32 unEvent) + * @brief clear soft event + * @param[in] uchEvent + * @param[out] None + * @return None + */ +void GH3X2X_ClearSoftEvent(GU32 unEvent); + + +/** + * @fn void GH3X2X_AddElectrodeWearRevCnt(void) + * + * @brief GH3X2X_AddElectrodeWearRevCnt + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_AddElectrodeWearRevCnt(void); + +/** + * @fn GU8 GH3X2X_ElectrodeWearRevertDebugModeIsEnabled(void) + * + * @brief Check if electrode wear revert debug mode is enabled + * + * @attention In this mode,not need report wear event,need report the number of wear electrode revert. + * + * @param[in] None + * @param[out] None + * + * @return 1: enabled, 0:disabled + */ +GU8 GH3X2X_ElectrodeWearRevertDebugModeIsEnabled(void); + + + +/** + * @fn void GH3X2X_SoftWearOffDetInit(void) + * + * @brief Soft wear off detect init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_SoftWearOffDetInit(void); + + + +void GH3X2X_SetSoftWearOffDetEn(GU8 uchSoftWearOffDetEn); +void GH3X2X_SetHardAdtAlgoCheckEn(GU8 uchHardAdtCheckByAlgo); + +/** + * @fn GU8 GH3X2X_UpdateSoftWearOffStatus(GU16 *pusEvent) + * + * @brief update wear status + * + * @attention None + * + * @param[in] old event point + * @param[out] 0: no soft wear off det event 1: have soft wear off det event + * + * @return new event + */ +GU8 GH3X2X_UpdateSoftWearOffStatus(GU16 *pusEvent, GU8 *puchSoftAdtFlag ,GU8 *puchLivingConfi); + +/** + * @fn GU16 GH3X2X_GetCurrentFifoWaterLine(void) + * + * @brief get current fifo water line setting + * + * @attention None. + * + * @param[in] None + * @param[out] fifo water line + * + * @return None + */ +GU16 GH3X2X_GetCurrentFifoWaterLine(void); + + + +/** + * @fn GS8 GH3X2X_CalibrateECGGainEx(GU8 *puchReadFifoBuffer) + * + * @brief Calibrate ECG Gain + * + * @attention None + * + * @param[in] puchReadFifoBuffer pointer read data buffer from GH3X2X_GetRawdataForAlgorithm + * + * @return error code + * @retval #GH3X2X_RET_OK return algorithm run successfully, but output hasn't refreshed + * @retval #GH3X2X_RET_GENERIC_ERROR return algorithm generic error + */ + +GS8 GH3X2X_CalibrateECGGainEx(GU8 *puchReadFifoBuffer); + + +/** + * @fn GS8 GH3X2X_CalibrateECGGain(GU8 *puchReadFifoBuffer) + * + * @brief Calibrate ECG Gain + * + * @attention None + * + * @param[in] puchReadFifoBuffer pointer read data buffer + * @param[in] usFifoBufferLen fifo byte length + * @return error code + * @retval #GH3X2X_RET_OK return algorithm run successfully, but output hasn't refreshed + * @retval #GH3X2X_RET_GENERIC_ERROR return algorithm generic error + */ + +GS8 GH3X2X_CalibrateECGGain(GU8 *puchReadFifoBuffer, GU16 usFifoBufferLen); + + + +/** + * @fn GU8 GH3x2x_SetChipResetRecoveringFlag(void) + + + * + * @brief + * + * @attention None. + * + * @param[in] chip reset recovering flag 0: is not in chip reset recovering flag 1: is in chip reset recovering + * @param[out] None + * + * @return None + */ +void GH3x2x_SetChipResetRecoveringFlag(GU8 uchChipResetRecoeringFlag); + + +/** + * @fn GU8 GH3x2x_GetChipResetRecoveringFlag(void) + + + * + * @brief + * + * @attention None. + * + * @param[in] None + * @param[out] chip reset recovering flag 0: is not in chip reset recovering flag 1: is in chip reset recovering + * + * @return None + */ +GU8 GH3x2x_GetChipResetRecoveringFlag(void); + + + + +/** + * @fn GU8 GH3x2x_GetActiveChipResetFlag(void) + + + * + * @brief + * + * @attention None. + * + * @param[in] None + * @param[out] ActiveChipResetFlag 1: user have done chip reset(soft reset and hardwear reset) actively gh3x2x_init will clear it + * + * @return None + */ +GU8 GH3x2x_GetActiveChipResetFlag(void); + + +/** + * @fn void GH3X2X_UpdateAgcInfo(void) + * + * @brief record tia gain drv information + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_UpdateAgcInfo(void); + + + + + + + + +/** + * @fn void GH3X2X_SlotEnRegSet(GU8 uchSetValue) + * + * @brief Slot enable reg set + * + * @attention None + * + * @param[in] set value + * @param[out] None + * + * @return None + */ +void GH3X2X_SlotEnRegSet(GU8 uchSetValue); + +/** + * @fn void GH3X2X_ModifyFunctionFrequency(GU8 uchFunctionID, GU16 usFrequencyValue) + * + * @brief Modify fs for each function + * + * @attention None + * + * @param[in] uchFunctionID function offset + * @param[in] usFrequencyValue 5Hz-1000Hz + * @param[out] None + * + * @return None + */ +void GH3X2X_ModifyFunctionFrequency(GU8 uchFunctionID, GU16 usFrequencyValue); + +/** + * @fn void GH3X2X_ModifyFunctionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current) + * + * @brief Modify led current for each function + * + * @attention None + * + * @param[in] uchFunctionID function offset + * @param[in] usLedDrv0Current 0mA-200mA + * @param[in] usLedDrv1Current 0mA-200mA + * @param[out] None + * + * @return None + */ +void GH3X2X_ModifyFunctionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current); + +extern const GU8 g_uchGyroEnable; + +//extern void GH3X2X_SetFifoPackageMode(GU8 uchMode, GU8 *puchFifoBuffer); +extern void GH3X2X_SendRawdataFifoPackage(GU8 *puchGh3x2xReadFifoData, GU16 usFifoReadByteNum); +//extern void GH3X2X_PackRawdataFifoPackage(GU8 *puchGh3x2xReadFifoData, GU16 usFifoReadByteNum); +extern GU8 GH3X2X_GetFifoPackageMode(void); + + +/** + * @fn void GH3x2x_ChangeSampleParmForEngineeringMode(GU32 unFunctionMode, STGh3x2xEngineeringModeSampleParam *pstSampleParaGroup , GU8 uchSampleParaGroupNum) + + * + * @brief + * + * @attention None. + * + * @param[in] unFunctionMode: function group exp: GH3X2X_FUNCTION_ADT|GH3X2X_FUNCTION_HR + * @param[in] pstSampleParaGroup the pointer of engineering mode sample param group struct array base + * @param[in] uchSampleParaGroupNum engineering mode sample param group number + * @param[out] None + * + * @return None + */ +void GH3x2x_ChangeSampleParmForEngineeringMode(const STGh3x2xFrameInfo * const pstGh3x2xFrameInfo[], GU32 unFunctionMode, STGh3x2xEngineeringModeSampleParam *pstSampleParaGroup , GU8 uchSampleParaGroupNum); + + +GS8 GH3X2X_FunctionStart(const STGh3x2xFrameInfo * const pstFrameInfo); +GS8 GH3X2X_FunctionStop(const STGh3x2xFrameInfo * const pstFrameInfo); + + + + + + + +void GH3x2xFunctionProcess(GU8 *puchRawdataBuf, GU16 usRawDataByteLen, GS16 *pusGsValueArr, GU16 usGsDataNum, + STCapRawdata* pstCapValueArr,GU16 usCapDataNum,STTempRawdata* pstTempValueArr,GU16 usTempDataNum, + const STGh3x2xFrameInfo * const pstFrameInfo); +GU8* GH3x2xGetFunctionChnlMap(const STGh3x2xFrameInfo * const pstFrameInfo); +void GH3x2xSetFunctionChnlNum(const STGh3x2xFrameInfo * const pstFrameInfo, GU8 uchChnlNum); +void GH3x2xSetFunctionChnlMap(const STGh3x2xFrameInfo * const pstFrameInfo, GU8 uchChnlId, GU8 uchChnlTag); +void GH3x2xCalFunctionSlotBit(const STGh3x2xFrameInfo * const pstFrameInfo); +GU32 GH3X2X_GetFuncStartedBitmap(void); + + + + + + + + +extern const STGh3x2xFrameInfo * const g_pstGh3x2xFrameInfo[]; + + +/** + * @fn void GH3X2X_EcgSampleHookHandle(GU8 uchEventType, GU8 uchEventInfo) + * + * @brief ecg sample hook handle + * + * @attention None + * + * @param[in] uchEventType ecg sample event type, @ref ECG_SAMPLE_EVENT_TYPE_SAMPLE etc + * @param[in] uchEventInfo ecg sample event info, @ref ECG_SAMPLE_EVENT_INFO_SAMPLE_STOP etc + * @param[out] None + * + * @return None + */ +void GH3X2X_EcgSampleHookHandle(GU8 uchEventType, GU8 uchEventInfo); + + +void GH3X2X_LeadDetEnInHardAdt(GU8 uchEn); + +/** + * @fn GH3X2X_LeadDetEnControl(GU8 uchEventInfo) + * + * @brief lead detect enable control + * + * @attention None + * + * @param[in] uchEventInfo control event, only ecg start/stop evt + * @param[out] None + * + * @return None + */ +void GH3X2X_LeadDetEnControl(GU8 uchEventInfo); +/** + * @fn void GH3X2X_SlaverSoftLeadPramSet(GU16 usRegVal, GU8 uchRegPosi) + * + * @brief slave soft lead off param set from virtual reg + * + * @attention None + * + * @param[in] usRegVal reg value + * @param[in] uchRegPosi reg position + * @param[out] None + * + * @return None + */ +void GH3X2X_SlaverSoftLeadPramSet(GU16 usRegVal, GU8 uchRegPosi); + +/** + * @fn void GH3X2X_SlaverSoftLeadPramInit(void) + * + * @brief slave soft lead off param init to default value + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_SlaverSoftLeadPramInit(void); + +/** + * @fn void GH3X2X_FindGu16MaxMinVal(GU16 *pusMaxVal, GU16 *pusMinVal, GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find min val & max val + * + * @attention len must > 0, ptr not null + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] pusMaxVal pointer to max val + * @param[out] pusMinVal pointer to min val + * + * @return None + */ +void GH3X2X_FindGu16MaxMinVal(GU16 *pusMaxVal, GU16 *pusMinVal, GU16 *pusBuffer, GU8 uchLen); + +/** + * @fn GU16 GH3X2X_FindGu16MaxVal(GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find max val + * + * @attention len must > 0 + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] None + * + * @return max val, if len = 0, return 0 + */ +GU16 GH3X2X_FindGu16MaxVal(GU16 *pusBuffer, GU8 uchLen); + +/** + * @fn GU16 GH3X2X_FindGu16MinVal(GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find min val + * + * @attention len must > 0 + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] None + * + * @return min val, if len = 0, return 0 + */ +GU16 GH3X2X_FindGu16MinVal(GU16 *pusBuffer, GU8 uchLen); + +/** + * @fn GU8 GH3x2xGetChipOperateIndexRealtime(void) + * + * @brief get current chip operate index + * + * @attention None + * @param[in] None + * @param[out] 0: chip0 1: chip1 + * + * @return None + */ +GU8 GH3x2xGetChipOperateIndexRealtime(void); + + +void GH3X2X_StartHardAdtAndResetGsDetect(void); +void GH3X2X_StopHardAdtAndStartGsDetect(void); +GU8 GH3X2X_GetSoftLeadDetMode(void); +GU8 GH3X2X_GetAdtElectrodeAdtEn(void); + +/** + * @fn void Gh3x2x_DemoSendProtocolData(GU8* puchProtocolDataBuffer, GU16 usProtocolDataLen) + * + * @brief Copy protocol data to buffer that will be sent out to APP/EVK. + * + * @attention None + * + * @param[in] puchProtocolDataBuffer point to protocol data + * @param[in] usProtocolDataLen protocol data length + * @param[out] None + * + * @return None + */ +extern void Gh3x2xDemoSendProtocolData(GU8* puchProtocolDataBuffer, GU16 usProtocolDataLen); +extern GU8 GH3X2X_UprotocolPacketFormat(GU8 uchCmd, GU8 *puchPacketBuffer, GU8 *puchPayloadData, GU8 uchPayloadDataLen); + +extern void Gh2x2xUploadDataToMaster(const STGh3x2xFrameInfo * const pstFrameInfo, GU16 usFrameCnt, GU16 usFrameNum, GU8* puchTagArray); +extern void Gh2x2xUploadZipDataToMaster(const STGh3x2xFrameInfo * const pstFrameInfo, GU16 usFrameCnt, GU16 usFrameNum, GU8* puchTagArray); + +extern GU16 GH3x2xGetFrameNum(GU8 *puchRawdataBuf, GU16 usRawDataByteLen, const STGh3x2xFrameInfo * const pstFrameInfo); +GU8 GH3X2X_CalcArrayCrc8Val(GU8 uchDataArr[], GU16 usDataIndex, GU16 usDataLen); + +void Gh3x2xSetProtocolEventAck(void); +GU8 Gh3x2xGetProtocolEventReportId(void); + +extern void Gh3x2xSetFrameFlag2(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern GU8 Gh3x2xGetHrAlgoSupportChnl(void); +extern GU8 Gh3x2xGetSpo2AlgoSupportChnl(void); + +extern void GH3X2X_ReadIntTime(void); +extern GU8 GH3X2X_GetIntTimeInArray(GU8 uchSlotIndex); + + +extern void Gh3x2xFunctionInfoForUserInit(void); + +extern void GH3x2xCalFunctionSlotBit(const STGh3x2xFrameInfo * const pstFrameInfo); + +extern void GH3x2xSetAgcReg(GU8 uchAgcReg, GU8 uchSlot, GU16 usValue); + +extern GU16 GH3x2xGetAgcReg(GU8 uchAgcReg, GU8 uchSlot); + +extern void GH3x2xSendAllVersion(void); + + +extern void GH3X2X_SetAlgoEnableFlag(GU8 uchAlgoEnableFlag); +extern GU8 GH3X2X_GetAlgoEnableFlag(void); +extern GU8 GH3X2X_GetSingleChipModeEnableFlag(void); +extern void GH3X2X_SetSingleChipModeEnableFlag(GU8 uchAlgoEnableFlag); + +extern void GH3X2X_UprotocolFpbpDataReceiveCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen); +extern void GH3x2xBpAlgoInitSetting(GU8 *puchRespondBuffer); + +extern GS32 GH3X2X_LeadOffDetectInit(void); +extern GU8 GH3X2X_LeadOffDetect(GU8* puchFifoBuffer, GU16* pusFifoBufferLen); + +extern GU8 GH3X2X_EcgRsHandle(GU8 *puchFifoBuffer, GU16 *pusFifoBufferLen); +extern void Gh3x2xSetGh3x2xSoftWearOffDetFunctionId(GU32 unFunctionId); +extern void Gh3x2xIntPinTriggerModePro(void); +extern void GH3X2X_ECGResampleConfig(GU16 usEcgSampleRate); +extern void GH3X2X_PPGResampleConfig(GU16 usEcgSampleRate); +extern void Gh3x2xNewAgcSubChnlModuleReset(void); +extern GU8 GH3x2xNewAgcSetNewSubChnl(GU8 uchSlotNo, GU8 uchRxEn, STGh3x2xAgcInfo *STGh3x2xAgcInfo); +extern void GH3X2X_NewAgcSubChnlGainAdj(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo); +extern void GH3x2xNewAgcSubChnlClearAnalysisCntAndSetGain(GU8 uchSlotNo, GU8 uchRxEn ,GU8 uchNextGain); +extern void GH3x2xNewAgcSetSubChnlSlotInfo(GU8 uchSlotCnt, GU16 usSampleRate); +extern void GH3x2xWriteCapToFlash(void); +extern void GH3x2xReadCapFromFlash(void); +extern void GH3X2X_MoveDetectByCapData(STCapRawdata* pusCapData, GU16 usCapDataCnt); +extern void GH3x2xSlotTimeInfo(void); +extern void GH3X2X_NewAgcMainChnlPro(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo); + +extern void GH3X2X_RegisterI2cDeviceChip1(GU8 uchI2cIdLowTwoBitsSelect); + +extern void GH3X2X_LoadSlaveCfgForCascadeMode(void); +extern void GH3X2X_CascadeEcgSlaverLeadDectDisEx(void); +extern void GH3X2X_CascadeEcgSlaverFastRecTrigEx(void); +extern void GH3X2X_SoftResetSlaveChip(void); +extern void GH3X2X_StartSamplingSlaveChip(void); +extern void GH3X2X_StopSamplingSlaveChip(void); +extern void GH3X2X_EcgCascadeSlotEnRegSet(GU8 uchSetValue); +extern STGh3x2xSoftLeadOffDetInfo * const g_pstGh3x2xSoftLeadOffDetInfo; +extern STGh3x2xRsInfo * const g_pstGh3x2xEcgRsInfo; +extern STGh3x2xRsInfo * const g_pstGh3x2xPPGRsInfo; +extern const GU8 g_uchGh3x2xEcgChnlNumLimit; +extern const GU32 g_uchPPGDownSampleChnlNumLimit; + +extern const STGh3x2xReg stGh3x2xEcgCascadeSlaveRealReglist[]; +extern const GU16 g_usEcgCascadeSlaveRealRegLen; +extern GS32 g_nEcgParamsArr[5]; +extern void Gh3x2x_CHECK_0x0088_Ex(void); +extern int (*g_pPrintfUserIn)(const char *format, ...); +extern int (*g_pSnprintfUserIn)(char *str, size_t size, const char *format, ...); +extern void GH3X2X_ConfigLeadOffThr(GU32 uIQAmpThr, GU32 uIQAmpDiffThr,GU32 uValThr); +extern void GH3x2x_GetLedCurrentFullScal(GU8 *puchDrv0Fs, GU8 *puchDrv1Fs); + +extern GU32 GH3X2X_GetConfigFuncMode(void); +extern void GH3X2X_SetConfigFuncMode(GU32 unConfigFuncMode); +extern void Gh3x2xFifoRecovery(void); +extern void GH3X2X_SetDivZeroFlag(void); +extern void GH3X2X_ClearDivZeroFlag(void); + +extern void GH3X2X_AdtPramInit(void); +extern void GH3X2X_AdtPramSet(GU16 usRegVal, GU8 uchRegPosi); + +/** + * @fn void GH3X2X_ClearChipSleepFlag(GU8 uchChipIndex) + * + * @brief clear chip sleep flag + * + * @attention None + * + * @param[in] uchChipIndex 0: chip0 1: chip1 + * @param[out] None + * + * @return None + */ +extern void GH3X2X_ClearChipSleepFlag(GU8 uchChipIndex); + +/** + * @fn void GH3X2X_SetChipSleepFlag(GU8 uchChipIndex) + * + * @brief set chip sleep flag + * + * @attention None + * + * @param[in] uchChipIndex 0: chip0 1: chip1 + * @param[out] None + * + * @return None + */ +extern void GH3X2X_SetChipSleepFlag(GU8 uchChipIndex); + + + +extern void GhDrvConfigManagerInit(void); +extern GU32 GhDrvConfigManagerGetCurFunctionSupprort(void); + + + +#endif /* _GH3X2X_DRV_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_common.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_common.h new file mode 100644 index 000000000..c954607b6 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_common.h @@ -0,0 +1,463 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_common.h + * + * @brief gh3x2x driver common define + * + * @version ref gh3x2x_drv_version.h + * + */ + +#ifndef _GH3X2X_DRV_COMMON_H_ +#define _GH3X2X_DRV_COMMON_H_ + + +#include "gh_drv_config.h" +#include "gh_drv_registers.h" +#include "gh_drv.h" + + +#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ + #ifndef __packed + #define __packed __attribute__((__packed__)) + #endif /* __packed */ +#endif /* __GNUC__ */ + + +/* extern log function */ +extern void GH3X2X_PlatformLog(GCHAR *chLogString); + +//sample log enable flag +#define SAMPLE_DEBUG_ENABLE (1) +#if SAMPLE_DEBUG_ENABLE +//sample log open +/// log support len +#define GH3X2X_LOG_DEBUG_SUP_LEN (128) +//enable flag +#define SAMPLE_DEBUG_ENABLE_BP (0) +#define SAMPLE_DEBUG_ENABLE_AGC (0) +//log define +#define GH3X2X_INFO_LOG_PARAM(...) do {\ + if(g_pSnprintfUserIn)\ + {\ + GCHAR chDebugStr[GH3X2X_LOG_DEBUG_SUP_LEN] = {0};\ + g_pSnprintfUserIn(chDebugStr, GH3X2X_LOG_DEBUG_SUP_LEN, \ + "[LOG_DRV_I]: "__VA_ARGS__);\ + GH3X2X_PlatformLog(chDebugStr);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn("[LOG_DRV_I]: "__VA_ARGS__);\ + } while (0) + +//agc log +#if (SAMPLE_DEBUG_ENABLE_AGC) +#define GH3X2X_INFO_LOG_PARAM_AGC(...) { GH3X2X_INFO_LOG_PARAM(__VA_ARGS__); } +#else +#define GH3X2X_INFO_LOG_PARAM_AGC(...) +#endif +#else +//sample log close +#define GH3X2X_INFO_LOG_PARAM(...) +#define GH3X2X_INFO_LOG_PARAM_AGC(...) +#endif + +#define DRVLIB_GOODIX_DEMO_PLANFORM_DEBUG 0 +#ifdef GOODIX_DEMO_PLATFORM +#ifdef GH3X2X_LOG_DEBUG +#undef GH3X2X_LOG_DEBUG +#endif +#define GH3X2X_LOG_DEBUG DRVLIB_GOODIX_DEMO_PLANFORM_DEBUG +#endif + + +/* debug log control, if enable debug, GH3X2X_PlatformLog must define in platforms code */ +#if defined(GH3X2X_LOG_DEBUG) && (GH3X2X_LOG_DEBUG > 0) // debug level > 0 + + +#if 1 +/// log string with param +#define GH3X2X_DEBUG_LOG_PARAM(...) do {\ + if(g_pSnprintfUserIn)\ + {\ + GCHAR chDebugStr[GH3X2X_LOG_DEBUG_SUP_LEN] = {0};\ + g_pSnprintfUserIn(chDebugStr, GH3X2X_LOG_DEBUG_SUP_LEN, \ + "[LOG_DRV_D]: "__VA_ARGS__);\ + GH3X2X_PlatformLog(chDebugStr);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn("[LOG_DRV_D]: "__VA_ARGS__);\ + } while (0) + +#else +#define GH3X2X_DEBUG_LOG_PARAM(...) +#endif + + + + + +#if (GH3X2X_LOG_DEBUG > 1) // debug level > 1 + +/// internal log +#define GH3X2X_DEBUG_LOG_INTERNAL(...) { GH3X2X_DEBUG_LOG_PARAM(__VA_ARGS__); } + +#else + +/// internal log +#define GH3X2X_DEBUG_LOG_INTERNAL(...) + +#endif + +#else // debug level <= 0 + +/// log string with param +#define GH3X2X_DEBUG_LOG_PARAM(...) + +/// internal log +#define GH3X2X_DEBUG_LOG_INTERNAL(...) + +#endif + +/// fifo rawdata bytes max len +#define GH3X2X_FIFO_DATA_BYTES_MAX_LEN (3200) // GH3X2X_FIFO_CNT_CALC(800) + +/// fifo rawdata size +#define GH3X2X_FIFO_RAWDATA_SIZE (4) + +/// fifo rawdataindex size +#define GH3X2X_FIFO_RAWDATAINDEX_SIZE (2) + +/// fifo gsensordata size +#define GH3X2X_FIFO_GSENSORDATA_SIZE (6) + +/// fifo agcdata size +#define GH3X2X_FIFO_AGCDATA_SIZE (4) + +/// fifo cnt calc +#define GH3X2X_FIFO_CNT_CALC(x) ((x) * GH3X2X_FIFO_RAWDATA_SIZE) + +/// g sensor data size +#define GH3X2X_GSENSOR_DATA_SIZE (6) + +/// agc data size +#define GH3X2X_AGC_DATA_SIZE (4) + +/// agc data cnt calc +#define GH3X2X_AGC_CNT_CALC(x) ((x) * GH3X2X_AGC_DATA_SIZE) + +/// algorithm result size +#define GH3X2X_ALGO_RESULT_SIZE (4) + +/// algorithm result calc +#define GH3X2X_ALGO_RESULT_CALC(x) ((x) * GH3X2X_ALGO_RESULT_SIZE) + +/// algorithm result with tag calc. +#define GH3X2X_ALGO_RESULT_WITH_TAG_CALC(x) ((x) * (GH3X2X_ALGO_RESULT_SIZE + 1)) + +/* rawdata macro */ + +/// rawdata clear slot & adc num +#define GH3X2X_RAWDATA_CLEAR_SLOT_ADC_NUM(x) ((x) & 0x07FFFFFF) + +/// rawdata get slot num from dword +#define GH3X2X_DWORD_RAWDATA_GET_SLOT_NUM(x) (((x) & 0xE0000000) >> 29) + +/// rawdata get adc num from dword +#define GH3X2X_DWORD_RAWDATA_GET_ADC_NUM(x) (((x) & 0x18000000) >> 27) + +/// rawdata get slot&adc num from dword +#define GH3X2X_DWORD_RAWDATA_GET_SLOT_ADC_NUM(x) (((x) & 0xF8000000) >> 27) + +/// rawdata get slot num from byte +#define GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(x) (((x) & 0xE0) >> 5) + +/// rawdata get adc num from byte +#define GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(x) (((x) & 0x18) >> 3) + +/// slot & adc num bits of rawdata byte +#define GH3X2X_SLOT_ADC_NUM_BITS (0xF8) + +/// rawdata get slot adc num from byte +#define GH3X2X_BYTE_RAWDATA_GET_SLOT_ADC_NUM(x) (((x) & GH3X2X_SLOT_ADC_NUM_BITS) >> 3) + +/// get slot index from channel num +#define GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(x) (((x) & 0x1F) >> 2) + +/// get adc index from channel num +#define GH3X2X_GET_ADC_FROM_CHANNEL_NUM(x) ((x) & 0x3) + +/// rawdata clear all flag +#define GH3X2X_RAWDATA_CLEAR_ALL_FLAG(x) ((x) & 0x00FFFFFF) + +/// rawdata clear data +#define GH3X2X_RAWDATA_CLEAR_DATA(x) ((x) & 0xFF000000) + +/// rawdata get adj flag0 +#define GH3X2X_RAWDATA_GET_ADJ_FLAG0(x) (((x) & 0x4000000) >> 26) + +/// rawdata get adj flag1 +#define GH3X2X_RAWDATA_GET_ADJ_FLAG1(x) (((x) & 0x2000000) >> 25) + +/// get rawdata for algorithm +#define GH3X2X_GET_RAWDATA_FOR_ALGO(x) ((x) >> 7) + +/// rawdata get fast recovery flag +#define GH3X2X_RAWDATA_GET_FAST_RECOVERY_FLAG(x) (((x) & 0x4000000) >> 26) + +/// rawdata real offset +#define GH3X2X_RAWDATA_REAL_OFFSET (0x00800000) + + +/* algorithm config */ + +/// ecg algorithm default sampling frequency +#define GH3X2X_ALGORITHM_ADT_DEFAULT_FS (5) + +/// ram for algorithms bytes align +#define GH3X2X_ALGORITHMS_MEMORY_ALIGN (4) + +/// ram for algorithms bytes to align size +#define GH3X2X_ALGORITHMS_MEMORY_BYTES_2_ALGIN_SIZE(x) ((x) / GH3X2X_ALGORITHMS_MEMORY_ALIGN) + +/// hba algorithm support +#define GH3X2X_ALGORITHM_HBA_SUPPORT (1) + +/// hba algorithm default sampling frequency +#define GH3X2X_ALGORITHM_HBA_DEFAULT_FS (25) + +/// hrv algorithm support +#define GH3X2X_ALGORITHM_HRV_SUPPORT (0) + +/// hrv algorithm default sampling frequency +#define GH3X2X_ALGORITHM_HRV_DEFAULT_FS (100) + +/// spo2 algorithm support +#define GH3X2X_ALGORITHM_SPO2_SUPPORT (1) + +/// spo2 algorithm default sampling frequency +#define GH3X2X_ALGORITHM_SPO2_DEFAULT_FS (100) + +/// ecg algorithm support +#define GH3X2X_ALGORITHM_ECG_SUPPORT (1) + + +/// ecg algorithm default sampling frequency +#define GH3X2X_ALGORITHM_ECG_DEFAULT_FS (500) + +/// hsm algorithm support +#define GH3X2X_ALGORITHM_HSM_SUPPORT (0) +/// bt algorithm support +#define GH3X2X_ALGORITHM_BT_SUPPORT (0) +/// resp algorithm support +#define GH3X2X_ALGORITHM_RESP_SUPPORT (0) +/// af algorithm support +#define GH3X2X_ALGORITHM_AF_SUPPORT (0) +/// nadt algorithm support +#define GH3X2X_ALGORITHM_NADT_SUPPORT (1) +/// fpbp algorithm support +#define GH3X2X_ALGORITHM_BP_SUPPORT (0) + + +/* utils macro */ + +/// byte true flag val +#define GH3X2X_BYTE_FLAG_TRUE (1) + +/// byte false flag val +#define GH3X2X_BYTE_FLAG_FALSE (0) + +/// GF32 0 val +#define GH3X2X_GF32_0 (0.0f) + +/// null val +//#define GH3X2X_PTR_NULL ((void *) 0) + +/// get high 4bits from byte +#define GH3X2X_GET_HIGH_4BITS(val) ((val) & 0xF0) + +/// get low 4bits from byte +#define GH3X2X_GET_LOW_4BITS(val) ((val) & 0x0F) + +/// get first 4bits from byte +#define GH3X2X_GET_FIRST_4BITS(val) ((val) & 0x0000000FU) + +/// get high byte from word +#define GH3X2X_GET_HIGH_BYTE_FROM_WORD(sValue) ((GU8)(((sValue) >> 8) & 0xFFU)) + +/// get low byte from word +#define GH3X2X_GET_LOW_BYTE_FROM_WORD(sValue) ((GU8)((sValue) & 0xFFU)) + +/// get byte3 from dword +#define GH3X2X_GET_BYTE3_FROM_DWORD(unValue) ((GU8)(((unValue) >> 24) & 0x000000FFU)) + +/// get byte2 from dword +#define GH3X2X_GET_BYTE2_FROM_DWORD(unValue) ((GU8)(((unValue) >> 16) & 0x000000FFU)) + +/// get byte1 from dword +#define GH3X2X_GET_BYTE1_FROM_DWORD(unValue) ((GU8)(((unValue) >> 8) & 0x000000FFU)) + +/// get byte0 from dword +#define GH3X2X_GET_BYTE0_FROM_DWORD(unValue) ((GU8)((unValue) & 0x000000FFU)) + +/// get high word from dword +#define GH3X2X_GET_HIGH_WORD_FROM_DWORD(unValue) ((GU16)(((unValue) >> 16) & 0x0000FFFFU)) + +/// get low word from dword +#define GH3X2X_GET_LOW_WORD_FROM_DWORD(unValue) ((GU16)((unValue) & 0x0000FFFFU)) + +/// makeup word from bytes +#define GH3X2X_MAKEUP_WORD(uchHighByte, uchLowByte) ((GU16)(((((GU16)(uchHighByte)) << 8)& 0xFF00) |\ + (((GU16)(uchLowByte))& 0x00FF))) + +/// makeup dword from bytes +#define GH3X2X_MAKEUP_DWORD(uchByte3, uchByte2, uchByte1, uchByte0) (((((GU32)(uchByte3)) << 24) & 0xFF000000U)|\ + ((((GU32)(uchByte2)) << 16) & 0x00FF0000U) |\ + ((((GU32)(uchByte1)) << 8) & 0x0000FF00U) |\ + (((GU32)(uchByte0)) & 0x000000FFU)) + +/// makeup dword from words +#define GH3X2X_MAKEUP_DWORD2(usHighWord, usLowWord) (((((GU32)(usHighWord)) << 16) & 0xFFFF0000U) |\ + (((GU32)(usLowWord)) & 0x0000FFFFU)) + +/// macro of hook function call +/* NOLINTNEXTLINE(501) */ +#define HOOK_FUNC_CALL(func, argv) do { if ((func) != GH3X2X_PTR_NULL) { func argv; } } while (0) + +/// macro of handle function call +/* NOLINTNEXTLINE(501) */ +#define HANDLE_FUNC_CALL(func, argv) do { if ((func) != GH3X2X_PTR_NULL) { func argv; } } while (0) + +/// macro of set val via ptr +#define SET_VAL_VIA_PTR(ptr, val) do { if ((ptr) != GH3X2X_PTR_NULL) { (*(ptr)) = (val); } } while (0) + +/** + * @brief macro of read pin status, e.g. READ_PIN_STATUS_CALL(g_pGh3x2xReadIntPinStatus, uchPinStatus) + * func() should retrun 0(low level) or 1(high), if not register func, return 0xFF(invalid) + */ +#define READ_PIN_STATUS_CALL(func, status) do {\ + if ((func) != GH3X2X_PTR_NULL)\ + {\ + (status) = (func)();\ + }\ + else\ + {\ + (status) = 0xFF;\ + }\ + } while (0) + + +/* bit operation macro */ + +/// macro of set bits +#define GH3X2X_SET_BIT(x, b) ((x) | (b)) + +/// macro of val set bits +#define GH3X2X_VAL_SET_BIT(x, b) ((x) |= (b)) + +/// macro of clear bits +#define GH3X2X_CLEAR_BIT(x, b) ((x) & (~(b))) + +/// macro of val clear bits +#define GH3X2X_VAL_CLEAR_BIT(x, b) ((x) &= (~(b))) + +/// macro of val get bits +#define GH3X2X_VAL_GET_BIT(x, b) ((x) &= (b)) + +/// macro of check bits set +#define GH3X2X_CHECK_BIT_SET(x, b) (((x) & (b)) == (b)) + +/// macro of check bits not set +#define GH3X2X_CHECK_BIT_NOT_SET(x, b) (((x) & (b)) != (b)) + +/// macro of check bits is set +#define GH3X2X_CHECK_BIT_IS_SET(x, b) (((x) & (b)) == (b)) + +/// macro of get bits is set +#define GH3X2X_GET_BIT_IS_SET(x) ((x) & 0xf000) + +/// macro of bit number in one byte +#define GH3X2X_BIT_PER_BYTE (4) + +/// macro of bit in reg addr for check +#define GH3X2X_REG_MODE_BIT (3) + +/// macro of check bits zero +#define GH3X2X_CHECK_REG_MODE_BIT_ZERO(x) (((x) >> (GH3X2X_BIT_PER_BYTE * GH3X2X_REG_MODE_BIT)) == (0)) + +/// macro of check lsb set +#define GH3X2X_CHECK_LSB_SET(x) (GH3X2X_CHECK_BIT_SET((x), 0x01)) + +/// macro of check left shift bit set +#define GH3X2X_CHECK_LEFT_BIT_SET(x, l) (GH3X2X_CHECK_BIT_SET((x), (1u << (l)))) + +/// macro of check left shift bit not set +#define GH3X2X_CHECK_LEFT_BIT_NOT_SET(x, l) (GH3X2X_CHECK_BIT_NOT_SET((x), (1u << (l)))) + +/// macro of val clear left shift bit +#define GH3X2X_VAL_CLEAR_LEFT_BIT(x, l) ((x) &= (~((1u << (l))))) + +/// check ret error +#define GH3X2X_RET_ERROR_CHECK(x) do { \ + if ((x) != GH3X2X_RET_OK)\ + {\ + GH3X2X_DEBUG_LOG_PARAM("[%s]:error code = 0x%x\r\n", __FUNCTION__, x);\ + return (x);\ + }\ + } while (0) + +/// check ret the error +#define GH3X2X_RET_ERROR_CHECK_E(x, e) do { \ + if ((x) == (e))\ + {\ + return (x);\ + }\ + } while (0) + +/// check ret the error +#define GH3X2X_RET_ERROR_CHECK_ER(x, e, r) do { \ + if ((x) == (e))\ + {\ + return (r);\ + }\ + } while (0) + +/// val rigth shfit +#define GH3X2X_SET_VAL_RIGTH_SHIFT(x, r) ((x) >>= (r)) + +/// val rigth shfit 1bit +#define GH3X2X_SET_VAL_RIGTH_SHIFT_1BIT(x) (GH3X2X_SET_VAL_RIGTH_SHIFT((x), 1u)) + +/// val left shfit +#define GH3X2X_SET_VAL_LEFT_SHIFT(x, l) ((x) <<= (l)) + +/// val left shfit 1bit +#define GH3X2X_SET_VAL_LEFT_SHIFT_1BIT(x) (GH3X2X_SET_VAL_LEFT_SHIFT((x), 1u)) + +/// get left shfit val +#define GH3X2X_GET_LEFT_SHIFT_VAL(l) (1u << (l)) + +/// val left shfit +#define GH3X2X_VAL_LEFT_SHIFT(x, l) ((x) << (l)) + +/// val cal diff value +#define GH3X2X_VAL_DIFF_VALUE(a, b) ((a) > (b) ? ((a) - (b)) : ((b) - (a))) + +/// val cal diff status +#define GH3X2X_VAL_DIFF_STA(a, b) ((a) > (b) ? (0) : (1)) + +/// val cal diff ABS +#define GH3X2X_VAL_ABS(x) ((x) >= 0 ? (x) : - (x)) + +/// val zip rawdata send cmd EVEN or ODD +#define GH3X2X_VAL_ZIPSENDCMD(x) ((x) == 1 ? (GH3X2X_UPROTOCOL_CMD_ZIPEVENRAWDATA) \ + : (GH3X2X_UPROTOCOL_CMD_ZIPODDRAWDATA)) + + +extern const STGh3x2xModuleFunList g_Gh3x2xModuleFunList; + + + + + +#endif /* _GH3X2X_DRV_COMMON_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_config.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_config.h new file mode 100644 index 000000000..b16757f45 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_config.h @@ -0,0 +1,668 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_config.h + * + * @brief gh3x2x driver configurations + * + * @version ref gh3x2x_drv_version.h + * + */ + +#ifndef _GH3X2X_DRV_CONFIG_H_ +#define _GH3X2X_DRV_CONFIG_H_ +#include "gh_drv.h" + +/* started bitmap */ + +#define GH3X2X_STARTED_BITMAP_ALL_OFF (0x0000) /**< fnction started bitmap, all off bit */ +#define GH3X2X_STARTED_BITMAP_HBA (0x0001) /**< fnction started bitmap, hba bit */ +#define GH3X2X_STARTED_BITMAP_SPO2 (0x0002) /**< fnction started bitmap, spo2 bit */ +#define GH3X2X_STARTED_BITMAP_ECG (0x0004) /**< fnction started bitmap, ecg bit */ +#define GH3X2X_STARTED_BITMAP_ADT (0x0008) /**< fnction started bitmap, adt bit */ +#define GH3X2X_STARTED_BITMAP_HRV (0x0010) /**< fnction started bitmap, hrv bit */ +#define GH3X2X_STARTED_BITMAP_CUSTOMIZE (0x0080) /**< fnction started bitmap, customize bit */ + + +#define GH3X2X_REG_IS_VIRTUAL0X0_BIT (0x0000) +#define GH3X2X_REG_IS_VIRTUAL0X1_BIT (0x1000) +#define GH3X2X_REG_IS_VIRTUAL0X2_BIT (0x2000) +#define GH3X2X_REG_IS_VIRTUAL0X3_BIT (0x3000) +#define GH3X2X_REG_IS_VIRTUAL0X4_BIT (0x4000) +#define GH3X2X_REG_IS_VIRTUAL0X5_BIT (0x5000) +#define GH3X2X_REG_IS_VIRTUAL0X6_BIT (0x6000) +#define GH3X2X_REG_IS_VIRTUAL0X7_BIT (0x7000) +#define GH3X2X_REG_IS_VIRTUAL0X8_BIT (0x8000) +#define GH3X2X_REG_IS_VIRTUAL0X9_BIT (0x9000) +#define GH3X2X_REG_IS_VIRTUAL0XA_BIT (0xA000) +#define GH3X2X_REG_IS_VIRTUAL0XB_BIT (0xB000) +#define GH3X2X_REG_IS_VIRTUAL0XC_BIT (0xC000) +#define GH3X2X_REG_IS_VIRTUAL0XE_BIT (0xE000) +#define GH3X2X_REG_IS_VIRTUAL0XF_BIT (0xF000) + + +//vitual addr version +#define GH3X2X_VIRTUAL_REG_VERSION_STRING "Gh3x2x_Virtual_Reg_v3.4" +//top +#define GH3X2X_TOP_INFO_ADDR 0x1000 +#define GH3X2X_TOP_INFO_ADDR_END (0x10E0 - 1) + +#define GH3X2X_SLOT_LEDDRV_ADDR 0x10E0 +#define GH3X2X_SLOT_LEDDRV_ADDR_END (0x1100 - 1) + +#define GH3X2X_DUMP_CFG_ADDR 0x1100 +#define GH3X2X_DUMP_CFG_ADDR_END (0x1120 - 1) + +#define GH3X2X_FIFO_CTRL_ADDR 0x1120 +#define GH3X2X_FIFO_CTRL_ADDR_END (0x1140 - 1) + +#define GH3X2X_G_SENSOR_CFG_ADDR 0x1140 +#define GH3X2X_G_SENSOR_CFG_ADDR_END (0x1160 -1) + +#define GH3X2X_SOFT_AGC_PARA_ADDR 0x1160 +#define GH3X2X_SOFT_AGC_PARA_ADDR_END (0x1180 - 1) + +#define GH3X2X_CAP_CFG_ADDR 0x1180 +#define GH3X2X_CAP_CFG_ADDR_END (0x11A0 - 1) + +#define GH3X2X_TEMP_CFG_ADDR 0x11A0 +#define GH3X2X_TEMP_CFG_ADDR_END (0x2000 - 1) + + +#define GH3X2X_CHNL_MAP_ADDR 0x2000 +#define GH3X2X_CHNL_MAP_ADDR_END (0x2880 - 1) + +#define GH3X2X_FS_PARA_ADDR 0x2880 +#define GH3X2X_FS_PARA_ADDR_END (0x3000 - 1) + +#define GH3X2X_ADT_DRV_CFG_ADDR 0x3000 +#define GH3X2X_ADT_ALG_CFG_ADDR 0x30C0 +#define GH3X2X_HR_DRV_CFG_ADDR 0x3300 +#define GH3X2X_HR_ALG_CFG_ADDR 0x33C0 +#define GH3X2X_HRV_DRV_CFG_ADDR 0x3600 +#define GH3X2X_HRV_ALG_CFG_ADDR 0x36C0 +#define GH3X2X_HSM_DRV_CFG_ADDR 0x3900 +#define GH3X2X_HSM_ALG_CFG_ADDR 0x39C0 +#define GH3X2X_FPBP_DRV_CFG_ADDR 0x3C00 +#define GH3X2X_FPBP_ALG_CFG_ADDR 0x3CC0 +#define GH3X2X_PWA_DRV_CFG_ADDR 0x3F00 +#define GH3X2X_PWA_ALG_CFG_ADDR 0x3FC0 +#define GH3X2X_SPO2_DRV_CFG_ADDR 0x4200 +#define GH3X2X_SPO2_ALG_CFG_ADDR 0x42C0 +#define GH3X2X_ECG_DRV_CFG_ADDR 0x4500 +#define GH3X2X_ECG_ALG_CFG_ADDR 0x45C0 +#define GH3X2X_PWTT_DRV_CFG_ADDR 0x4800 +#define GH3X2X_PWTT_ALG_CFG_ADDR 0x48C0 +#define GH3X2X_SOFTADTGREEN_DRV_CFG_ADDR 0x4B00 +#define GH3X2X_SOFTADTGREEN_ALG_CFG_ADDR 0x4BC0 +#define GH3X2X_BT_DRV_CFG_ADDR 0x4E00 +#define GH3X2X_BT_ALG_CFG_ADDR 0x4EC0 +#define GH3X2X_RESP_DRV_CFG_ADDR 0x5100 +#define GH3X2X_RESP_ALG_CFG_ADDR 0x51C0 +#define GH3X2X_AF_DRV_CFG_ADDR 0x5400 +#define GH3X2X_AF_ALG_CFG_ADDR 0x54C0 +#define GH3X2X_TEST1_DRV_CFG_ADDR 0x5700 +#define GH3X2X_TEST1_ALG_CFG_ADDR 0x57C0 +#define GH3X2X_TEST2_DRV_CFG_ADDR 0x5A00 +#define GH3X2X_TEST2_ALG_CFG_ADDR 0x5AC0 +#define GH3X2X_SOFTADTIR_DRV_CFG_ADDR 0x5D00 +#define GH3X2X_SOFTADTIR_ALG_CFG_ADDR 0x5DC0 +#define GH3X2X_FINISH_FLAG_ADDR 0xFF00 +//top_info +#define GH3X2X_TOP_INFO_OFFSET 0x00DF +#define GH3X2X_CFG_VER_ADDR 0x1000 +#define GH3X2X_CFG_TOOL_VER_ADDR 0x1002 +#define GH3X2X_PROJECT_ID_ADDR 0x1004 +#define GH3X2X_TIMESTAMP_L_ADDR 0x1006 +#define GH3X2X_TIMESTAMP_H_ADDR 0x1008 +#define GH3X2X_REINIT_PARAM_ADDR 0x100A +//slot_leddrv +#define GH3X2X_SLOT_LEDDRV_OFFSET 0x001F +#define GH3X2X_SLOT0_1_LEDDRV_ADDR 0x10E0 +#define GH3X2X_SLOT2_3_LEDDRV_ADDR 0x10E2 +#define GH3X2X_SLOT4_5_LEDDRV_ADDR 0x10E4 +#define GH3X2X_SLOT6_7_LEDDRV_ADDR 0x10E6 +//dump_cfg +#define GH3X2X_DUMP_CFG_OFFSET 0x001F +#define GH3X2X_PPG_DUMP_MODE_ADDR 0x1100 +#define GH3X2X_BG_LEVEL_SET_ADDR 0x1102 +//fifo_ctrl +#define GH3X2X_FIFO_CTRL_OFFSET 0x001F +#define GH3X2X_NORMAL_FIFO_WATER_LINE_ADDR 0x1120 +#define GH3X2X_ADT_FIFO_WATER_LINE_ADDR 0x1122 +#define GH3X2X_FIFO_PACKAGE_SEND_MODE_ADDR 0x1124 +//g_sensor_cfg +#define GH3X2X_G_SENSOR_CFG_OFFSET 0x001F +#define GH3X2X_GSENSOR_VENDOR_ID_ADDR 0x1140 +#define GH3X2X_GSENSOR_SAMPLE_RATE_ADDR 0x1142 +#define GH3X2X_GSENSOR_CTRL_ADDR 0x1144 +//soft_agc_para +#define GH3X2X_SOFT_AGC_PARA_OFFSET 0x001F +#define GH3X2X_AGC_BG_CANCEL_ADJUST_SLOT_EN_ADDR 0x1160 +#define GH3X2X_AGC_AMB_SLOT_CTRL_ADDR 0x1162 +#define GH3X2X_AGC_CONFIG_RES 0x1164 +#define GH3X2X_AGC_GAIN_LIMIT_ADDR 0x1166 +#define GH3X2X_AGC_TRIG_THD_H_LSB_16_ADDR 0x1168 +#define GH3X2X_AGC_TRIG_THD_H_MSB_16_ADDR 0x116A +#define GH3X2X_AGC_TRIG_THD_L_LSB_16_ADDR 0x116C +#define GH3X2X_AGC_TRIG_THD_L_MSB_16_ADDR 0x116E +#define GH3X2X_AGC_RESTRAIN_THD_H_LSB_16_ADDR 0x1170 +#define GH3X2X_AGC_RESTRAIN_THD_H_MSB_16_ADDR 0x1172 +#define GH3X2X_AGC_RESTRAIN_THD_L_LSB_16_ADDR 0x1174 +#define GH3X2X_AGC_RESTRAIN_THD_L_MSB_16_ADDR 0x1176 +//cap_cfg +#define GH3X2X_CAP_CFG_OFFSET 0x001F +#define GH3X2X_CAP_CTRL_ADDR 0x1180 +//Temp_cfg +#define GH3X2X_TEMP_CFG_OFFSET 0x001F +#define GH3X2X_TEMP_CTRL_ADDR 0x11A0 + + +//chnl_map +#define GH3X2X_CHNL_MAP_OFFSET 0x087F +#define GH3X2X_ADT_CHMAP_CNT_ADDR 0x2000 +#define GH3X2X_ADT_CHMAP_CH0_1_ADDR 0x2002 +#define GH3X2X_HR_CHMAP_CNT_ADDR 0x2022 +#define GH3X2X_HR_CHMAP_CH0_1_ADDR 0x2024 +#define GH3X2X_HRV_CHMAP_CNT_ADDR 0x2044 +#define GH3X2X_HRV_CHMAP_CH0_1_ADDR 0x2046 +#define GH3X2X_HSM_CHMAP_CNT_ADDR 0x2066 +#define GH3X2X_HSM_CHMAP_CH0_1_ADDR 0x2068 +#define GH3X2X_FPBP_CHMAP_CNT_ADDR 0x2088 +#define GH3X2X_FPBP_CHMAP_CH0_1_ADDR 0x208A +#define GH3X2X_PWA_CHMAP_CNT_ADDR 0x20AA +#define GH3X2X_PWA_CHMAP_CH0_1_ADDR 0x20AC +#define GH3X2X_SPO2_CHMAP_CNT_ADDR 0x20CC +#define GH3X2X_SPO2_CHMAP_CH0_1_ADDR 0x20CE +#define GH3X2X_ECG_CHMAP_CNT_ADDR 0x20EE +#define GH3X2X_ECG_CHMAP_CH0_1_ADDR 0x20F0 +#define GH3X2X_PWTT_CHMAP_CNT_ADDR 0x2110 +#define GH3X2X_PWTT_CHMAP_CH0_1_ADDR 0x2112 +#define GH3X2X_SOFT_ADT_GREEN_CHMAP_CNT_ADDR 0x2132 +#define GH3X2X_SOFT_ADT_GREEN_CHMAP_CH0_1_ADDR 0x2134 +#define GH3X2X_BT_CHMAP_CNT_ADDR 0x2154 +#define GH3X2X_BT_CHMAP_CH0_1_ADDR 0x2156 +#define GH3X2X_RESP_CHMAP_CNT_ADDR 0x2176 +#define GH3X2X_RESP_CHMAP_CH0_1_ADDR 0x2178 +#define GH3X2X_AF_CHMAP_CNT_ADDR 0x2198 +#define GH3X2X_AF_CHMAP_CH0_1_ADDR 0x219A +#define GH3X2X_TEST1_CHMAP_CNT_ADDR 0x21BA +#define GH3X2X_TEST1_CHMAP_CH0_1_ADDR 0x21BC +#define GH3X2X_TEST2_CHMAP_CNT_ADDR 0x21DC +#define GH3X2X_TEST2_CHMAP_CH0_1_ADDR 0x21DE +#define GH3X2X_SOFT_ADT_IR_CHMAP_CNT_ADDR 0x21FE +#define GH3X2X_SOFT_ADT_IR_CHMAP_CH0_1_ADDR 0x2200 +//fs_para +#define GH3X2X_FS_PARA_OFFSET 0x007F +#define GH3X2X_ADT_FS_ADDR 0x2880 +#define GH3X2X_HR_FS_ADDR 0x2882 +#define GH3X2X_HRV_FS_ADDR 0x2884 +#define GH3X2X_HSM_FS_ADDR 0x2886 +#define GH3X2X_FPBP_FS_ADDR 0x2888 +#define GH3X2X_PWA_FS_ADDR 0x288A +#define GH3X2X_SPO2_FS_ADDR 0x288C +#define GH3X2X_ECG_FS_ADDR 0x288E +#define GH3X2X_PWTT_FS_ADDR 0x2890 +#define GH3X2X_SOFT_ADT_GREEN_FS_ADDR 0x2892 +#define GH3X2X_BT_FS_ADDR 0x2894 +#define GH3X2X_RESP_FS_ADDR 0x2896 +#define GH3X2X_AF_FS_ADDR 0x2898 +#define GH3X2X_TEST1_FS_ADDR 0x289A +#define GH3X2X_TEST2_FS_ADDR 0x289C +#define GH3X2X_SOFT_ADT_IR_FS_ADDR 0x289E +//adt_drv_cfg +#define GH3X2X_ADT_DRV_CFG_OFFSET 0x00C7 +#define GH3X2X_ADT_CONFIG0_ADDR 0x3000 +#define GH3X2X_ADT_CONFIG1_ADDR 0x3002 +//adt_alg_cfg +#define GH3X2X_ADT_ALG_CFG_OFFSET 0x023F +//hr_drv_cfg +#define GH3X2X_HR_DRV_CFG_OFFSET 0x00C7 +//hr_alg_cfg +#define GH3X2X_HR_ALG_CFG_OFFSET 0x023F +#define GH3X2X_HR_SCENARIO_CFG_L_ADDR 0x33C0 +#define GH3X2X_HR_SCENARIO_CFG_H_ADDR 0x33C2 +#define GH3X2X_HR_OUTPUT_TIME_L_ADDR 0x33C4 +#define GH3X2X_HR_OUTPUT_TIME_H_ADDR 0x33C6 +#define GH3X2X_HR_FS_L_ADDR 0x33C8 +#define GH3X2X_HR_FS_H_ADDR 0x33CA +#define GH3X2X_HR_ALGO_CHNL_NUM_ADDR 0x35C0 +#define GH3X2X_ALGO_CHNL_MAP_HR_GREEN_CHNL0_1_ADDR 0x35C4 +#define GH3X2X_ALGO_CHNL_MAP_HR_GREEN_CHNL2_3_ADDR 0x35C6 +#define GH3X2X_ALGO_CHNL_MAP_HR_IR_CHNL0_1_ADDR 0x35CC +#define GH3X2X_ALGO_CHNL_MAP_HR_IR_CHNL2_3_ADDR 0x35CE +#define GH3X2X_ALGO_CHNL_MAP_HR_RED_CHNL0_1_ADDR 0x35D4 +#define GH3X2X_ALGO_CHNL_MAP_HR_RED_CHNL2_3_ADDR 0x35D6 +//hrv_drv_cfg +#define GH3X2X_HRV_DRV_CFG_OFFSET 0x00C7 +//hrv_alg_cfg +#define GH3X2X_HRV_ALG_CFG_OFFSET 0x023F +#define GH3X2X_HRV_INTERPOLATION_ENABLE_L_ADDR 0x36C0 +#define GH3X2X_HRV_INTERPOLATION_ENABLE_H_ADDR 0x36C2 +#define GH3X2X_HRV_ACC_THR_MAX_L_ADDR 0x36C4 +#define GH3X2X_HRV_ACC_THR_MAX_H_ADDR 0x36C6 +#define GH3X2X_HRV_ACC_THR_MIN_L_ADDR 0x36C8 +#define GH3X2X_HRV_ACC_THR_MIN_H_ADDR 0x36CA +#define GH3X2X_HRV_ACC_THR_NUM_L_ADDR 0x36CC +#define GH3X2X_HRV_ACC_THR_NUM_H_ADDR 0x36D0 +#define GH3X2X_HRV_ACC_THR_SCALE_L_ADDR 0x36D2 +#define GH3X2X_HRV_ACC_THR_SCALE_H_ADDR 0x36D4 +//hsm_drv_cfg +#define GH3X2X_HSM_DRV_CFG_OFFSET 0x00C7 +//hsm_alg_cfg +#define GH3X2X_HSM_ALG_CFG_OFFSET 0x023F +//fpbp_drv_cfg +#define GH3X2X_FPBP_DRV_CFG_OFFSET 0x00C7 +//fpbp_alg_cfg +#define GH3X2X_FPBP_ALG_CFG_OFFSET 0x023F +#define GH3X2X_FPBP_CALC_MODE_L_ADDR 0x3CC0 +#define GH3X2X_FPBP_CALC_MODE_H_ADDR 0x3CC2 +#define GH3X2X_FPBP_CALI_WAVE_REPLEVEL_THRD_L_ADDR 0x3CC4 +#define GH3X2X_FPBP_CALI_WAVE_REPLEVEL_THRD_H_ADDR 0x3CC6 +#define GH3X2X_FPBP_CALI_WAVE_STBLEVEL_THRD_L_ADDR 0x3CC8 +#define GH3X2X_FPBP_CALI_WAVE_STBLEVEL_THRD_H_ADDR 0x3CCA +#define GH3X2X_FPBP_CALI_CONFSCORE_THRD_L_ADDR 0x3CCC +#define GH3X2X_FPBP_CALI_CONFSCORE_THRD_H_ADDR 0x3CCE +#define GH3X2X_FPBP_CALC_WAVE_REPLEVEL_THRD_L_ADDR 0x3CD0 +#define GH3X2X_FPBP_CALC_WAVE_REPLEVEL_THRD_H_ADDR 0x3CD2 +#define GH3X2X_FPBP_CALC_WAVE_STBLEVEL_THRD_L_ADDR 0x3CD4 +#define GH3X2X_FPBP_CALC_WAVE_STBLEVEL_THRD_H_ADDR 0x3CD6 +#define GH3X2X_FPBP_CALC_CONFSCORE_THRD_L_ADDR 0x3CD8 +#define GH3X2X_FPBP_CALC_CONFSCORE_THRD_H_ADDR 0x3CDA +#define GH3X2X_FPBP_RESULT_CHECK_FLAG_L_ADDR 0x3CDC +#define GH3X2X_FPBP_RESULT_CHECK_FLAG_H_ADDR 0x3CDE +#define GH3X2X_FPBP_PROGRAM_SELECT_L_ADDR 0x3CE0 +#define GH3X2X_FPBP_PROGRAM_SELECT_H_ADDR 0x3CE2 +#define GH3X2X_FPBP_PRESSURE_OFFSET_L_ADDR 0x3CE4 +#define GH3X2X_FPBP_PRESSURE_OFFSET_H_ADDR 0x3CE6 +#define GH3X2X_FPBP_PRESSURE_FACTOR_L_ADDR 0x3CE8 +#define GH3X2X_FPBP_PRESSURE_FACTOR_H_ADDR 0x3CEA +#define GH3X2X_FPBP_PRESSURE_AREA_L_ADDR 0x3CEC +#define GH3X2X_FPBP_PRESSURE_AREA_H_ADDR 0x3CEE +#define GH3X2X_FPBP_ALGO_CHNL_NUM_ADDR 0x3EC0 +#define GH3X2X_ALGO_CHNL_MAP_FPBP_ECG_CHNL_ADDR 0x3EC2 +#define GH3X2X_ALGO_CHNL_MAP_FPBP_GREEN_CHNL0_1_ADDR 0x3EC4 +#define GH3X2X_ALGO_CHNL_MAP_FPBP_GREEN_CHNL2_3_ADDR 0x3EC6 +#define GH3X2X_ALGO_CHNL_MAP_FPBP_IR_CHNL0_1_ADDR 0x3ECC +#define GH3X2X_ALGO_CHNL_MAP_FPBP_IR_CHNL2_3_ADDR 0x3ECE +#define GH3X2X_ALGO_CHNL_MAP_FPBP_RED_CHNL0_1_ADDR 0x3ED4 +#define GH3X2X_ALGO_CHNL_MAP_FPBP_RED_CHNL2_3_ADDR 0x3ED6 +//pwa_drv_cfg +#define GH3X2X_PWA_DRV_CFG_OFFSET 0x00C7 +//pwa_alg_cfg +#define GH3X2X_PWA_ALG_CFG_OFFSET 0x023F +#define GH3X2X_PWA_CALC_MODE_L_ADDR 0x3FC0 +#define GH3X2X_PWA_CALC_MODE_H_ADDR 0x3FC2 +#define GH3X2X_PWA_CALI_WAVE_REPLEVEL_THRD_L_ADDR 0x3FC4 +#define GH3X2X_PWA_CALI_WAVE_REPLEVEL_THRD_H_ADDR 0x3FC6 +#define GH3X2X_PWA_CALI_WAVE_STBLEVEL_THRD_L_ADDR 0x3FC8 +#define GH3X2X_PWA_CALI_WAVE_STBLEVEL_THRD_H_ADDR 0x3FCA +#define GH3X2X_PWA_CALI_CONFSCORE_THRD_L_ADDR 0x3FCC +#define GH3X2X_PWA_CALI_CONFSCORE_THRD_H_ADDR 0x3FCE +#define GH3X2X_PWA_CALC_WAVE_REPLEVEL_THRD_L_ADDR 0x3FD0 +#define GH3X2X_PWA_CALC_WAVE_REPLEVEL_THRD_H_ADDR 0x3FD2 +#define GH3X2X_PWA_CALC_WAVE_STBLEVEL_THRD_L_ADDR 0x3FD4 +#define GH3X2X_PWA_CALC_WAVE_STBLEVEL_THRD_H_ADDR 0x3FD6 +#define GH3X2X_PWA_CALC_CONFSCORE_THRD_L_ADDR 0x3FD8 +#define GH3X2X_PWA_CALC_CONFSCORE_THRD_H_ADDR 0x3FDA +#define GH3X2X_PWA_RESULT_CHECK_FLAG_L_ADDR 0x3FDC +#define GH3X2X_PWA_RESULT_CHECK_FLAG_H_ADDR 0x3FDE +#define GH3X2X_PWA_PROGRAM_SELECT_L_ADDR 0x3FE0 +#define GH3X2X_PWA_PROGRAM_SELECT_H_ADDR 0x3FE2 +#define GH3X2X_PWA_PRESSURE_OFFSET_L_ADDR 0x3FE4 +#define GH3X2X_PWA_PRESSURE_OFFSET_H_ADDR 0x3FE6 +#define GH3X2X_PWA_PRESSURE_FACTOR_L_ADDR 0x3FE8 +#define GH3X2X_PWA_PRESSURE_FACTOR_H_ADDR 0x3FEA +#define GH3X2X_PWA_PRESSURE_AREA_L_ADDR 0x3FEC +#define GH3X2X_PWA_PRESSURE_AREA_H_ADDR 0x3FEE +#define GH3X2X_PWA_ALGO_CHNL_NUM_ADDR 0x41C0 +#define GH3X2X_ALGO_CHNL_MAP_PWA_ECG_CHNL_ADDR 0x41C2 +#define GH3X2X_ALGO_CHNL_MAP_PWA_GREEN_CHNL0_1_ADDR 0x41C4 +#define GH3X2X_ALGO_CHNL_MAP_PWA_GREEN_CHNL2_3_ADDR 0x41C6 +#define GH3X2X_ALGO_CHNL_MAP_PWA_IR_CHNL0_1_ADDR 0x41CC +#define GH3X2X_ALGO_CHNL_MAP_PWA_IR_CHNL2_3_ADDR 0x41CE +#define GH3X2X_ALGO_CHNL_MAP_PWA_RED_CHNL0_1_ADDR 0x41D4 +#define GH3X2X_ALGO_CHNL_MAP_PWA_RED_CHNL2_3_ADDR 0x41D6 +//spo2_drv_cfg +#define GH3X2X_SPO2_DRV_CFG_OFFSET 0x00C7 +//spo2_alg_cfg +#define GH3X2X_SPO2_ALG_CFG_OFFSET 0x023F +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR0_L_ADDR 0x42C0 +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR0_H_ADDR 0x42C2 +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR1_L_ADDR 0x42C4 +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR1_H_ADDR 0x42C6 +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR2_L_ADDR 0x42C8 +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR2_H_ADDR 0x42CA +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR3_L_ADDR 0x42CC +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR3_H_ADDR 0x42CE +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR4_L_ADDR 0x42D0 +#define GH3X2X_SPO2_CH0_CORRECTION_FACTOR4_H_ADDR 0x42D2 +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR0_L_ADDR 0x42D4 +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR0_H_ADDR 0x42D6 +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR1_L_ADDR 0x42D8 +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR1_H_ADDR 0x42DA +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR2_L_ADDR 0x42DC +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR2_H_ADDR 0x42DE +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR3_L_ADDR 0x42E0 +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR3_H_ADDR 0x42E2 +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR4_L_ADDR 0x42E4 +#define GH3X2X_SPO2_CH1_CORRECTION_FACTOR4_H_ADDR 0x42E6 +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR0_L_ADDR 0x42E8 +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR0_H_ADDR 0x42EA +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR1_L_ADDR 0x42EC +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR1_H_ADDR 0x42EE +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR2_L_ADDR 0x42F0 +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR2_H_ADDR 0x42F2 +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR3_L_ADDR 0x42F4 +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR3_H_ADDR 0x42F6 +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR4_L_ADDR 0x42F8 +#define GH3X2X_SPO2_CH2_CORRECTION_FACTOR4_H_ADDR 0x42FA +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR0_L_ADDR 0x42FC +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR0_H_ADDR 0x42FE +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR1_L_ADDR 0x4300 +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR1_H_ADDR 0x4302 +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR2_L_ADDR 0x4304 +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR2_H_ADDR 0x4306 +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR3_L_ADDR 0x4308 +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR3_H_ADDR 0x430A +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR4_L_ADDR 0x430C +#define GH3X2X_SPO2_CH3_CORRECTION_FACTOR4_H_ADDR 0x430E +#define GH3X2X_SPO2_ALGO_CHNL_NUM_ADDR 0x44C0 +#define GH3X2X_ALGO_CHNL_MAP_SPO2_GREEN_CHNL0_1_ADDR 0x44C4 +#define GH3X2X_ALGO_CHNL_MAP_SPO2_GREEN_CHNL2_3_ADDR 0x44C6 +#define GH3X2X_ALGO_CHNL_MAP_SPO2_IR_CHNL0_1_ADDR 0x44CC +#define GH3X2X_ALGO_CHNL_MAP_SPO2_IR_CHNL2_3_ADDR 0x44CE +#define GH3X2X_ALGO_CHNL_MAP_SPO2_RED_CHNL0_1_ADDR 0x44D4 +#define GH3X2X_ALGO_CHNL_MAP_SPO2_RED_CHNL2_3_ADDR 0x44D6 +//ecg_drv_cfg +#define GH3X2X_ECG_DRV_CFG_OFFSET 0x00C7 +#define GH3X2X_ECG_SETTING0_ADDR 0x4500 +#define GH3X2X_ECG_SETTING1_ADDR 0x4502 +#define GH3X2X_ECG_SETTING2_ADDR 0x4504 +#define GH3X2X_ECG_SETTING3_ADDR 0x4506 +//ecg_alg_cfg +#define GH3X2X_ECG_ALG_CFG_OFFSET 0x023F +//pwtt_drv_cfg +#define GH3X2X_PWTT_DRV_CFG_OFFSET 0x00C7 +//pwtt_alg_cfg +#define GH3X2X_PWTT_ALG_CFG_OFFSET 0x023F +//softadtgreen_drv_cfg +#define GH3X2X_SOFTADTGREEN_DRV_CFG_OFFSET 0x00C7 +//softadtgreen_alg_cfg +#define GH3X2X_SOFTADTGREEN_ALG_CFG_OFFSET 0x023F +#define GH3X2X_SOFTADT_GREEN_ALGO_CHNL_NUM_ADDR 0x4DC0 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTGREEN_GREEN_CHNL0_1_ADDR 0x4DC4 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTGREEN_GREEN_CHNL2_3_ADDR 0x4DC6 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTGREEN_GREEN_BG_CHNL0_1_ADDR 0x4DCC +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTGREEN_BG_CHNL2_3_ADDR 0x4DCE +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTGREEN_ADT_CHNL0_1_ADDR 0x4DD4 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTGREEN_ADT_CHNL2_3_ADDR 0x4DD6 +//bt_drv_cfg +#define GH3X2X_BT_DRV_CFG_OFFSET 0x00C7 +//bt_alg_cfg +#define GH3X2X_BT_ALG_CFG_OFFSET 0x023F +#define GH3X2X_BT_NTC0_CALIRESISTANCE1_L_ADDR 0x4EC0 +#define GH3X2X_BT_NTC0_CALIRESISTANCE1_H_ADDR 0x4EC2 +#define GH3X2X_BT_NTC0_CALIRESISTANCE2_L_ADDR 0x4EC4 +#define GH3X2X_BT_NTC0_CALIRESISTANCE2_H_ADDR 0x4EC6 +#define GH3X2X_BT_NTC0_CALIRESISTANCE3_L_ADDR 0x4EC8 +#define GH3X2X_BT_NTC0_CALIRESISTANCE3_H_ADDR 0x4ECA +#define GH3X2X_BT_NTC0_BASERESISTANCE_L_ADDR 0x4ECC +#define GH3X2X_BT_NTC0_BASERESISTANCE_H_ADDR 0x4ECE +#define GH3X2X_BT_NTC0_CALITEMPERATURE1_L_ADDR 0x4ED0 +#define GH3X2X_BT_NTC0_CALITEMPERATURE1_H_ADDR 0x4ED2 +#define GH3X2X_BT_NTC0_CALITEMPERATURE2_L_ADDR 0x4ED4 +#define GH3X2X_BT_NTC0_CALITEMPERATURE2_H_ADDR 0x4ED6 +#define GH3X2X_BT_NTC0_CALITEMPERATURE3_L_ADDR 0x4ED8 +#define GH3X2X_BT_NTC0_CALITEMPERATURE3_H_ADDR 0x4EDA +#define GH3X2X_BT_NTC1_CALIRESISTANCE1_L_ADDR 0x4EDC +#define GH3X2X_BT_NTC1_CALIRESISTANCE1_H_ADDR 0x4EDE +#define GH3X2X_BT_NTC1_CALIRESISTANCE2_L_ADDR 0x4EE0 +#define GH3X2X_BT_NTC1_CALIRESISTANCE2_H_ADDR 0x4EE2 +#define GH3X2X_BT_NTC1_CALIRESISTANCE3_L_ADDR 0x4EE4 +#define GH3X2X_BT_NTC1_CALIRESISTANCE3_H_ADDR 0x4EE6 +#define GH3X2X_BT_NTC1_BASERESISTANCE_L_ADDR 0x4EE8 +#define GH3X2X_BT_NTC1_BASERESISTANCE_H_ADDR 0x4EEA +#define GH3X2X_BT_NTC1_CALITEMPERATURE1_L_ADDR 0x4EEC +#define GH3X2X_BT_NTC1_CALITEMPERATURE1_H_ADDR 0x4EEE +#define GH3X2X_BT_NTC1_CALITEMPERATURE2_L_ADDR 0x4EF0 +#define GH3X2X_BT_NTC1_CALITEMPERATURE2_H_ADDR 0x4EF2 +#define GH3X2X_BT_NTC1_CALITEMPERATURE3_L_ADDR 0x4EF4 +#define GH3X2X_BT_NTC1_CALITEMPERATURE3_H_ADDR 0x4EF6 +//resp_drv_cfg +#define GH3X2X_RESP_DRV_CFG_OFFSET 0x00C7 +//resp_alg_cfg +#define GH3X2X_RESP_ALG_CFG_OFFSET 0x023F +//af_drv_cfg +#define GH3X2X_AF_DRV_CFG_OFFSET 0x00C7 +//af_alg_cfg +#define GH3X2X_AF_ALG_CFG_OFFSET 0x023F +#define GH3X2X_AF_WAIT_TIME_L_ADDR 0x54C0 +#define GH3X2X_AF_WAIT_TIME_H_ADDR 0x54C2 +//test1_drv_cfg +#define GH3X2X_TEST1_DRV_CFG_OFFSET 0x00C7 +//test1_alg_cfg +#define GH3X2X_TEST1_ALG_CFG_OFFSET 0x023F +//test2_drv_cfg +#define GH3X2X_TEST2_DRV_CFG_OFFSET 0x00C7 +//test2_alg_cfg +#define GH3X2X_TEST2_ALG_CFG_OFFSET 0x023F +//softadtir_drv_cfg +#define GH3X2X_SOFTADTIR_DRV_CFG_OFFSET 0x00C7 +//softadtir_alg_cfg +#define GH3X2X_SOFTADTIR_ALG_CFG_OFFSET 0x023F +#define GH3X2X_SOFTADT_ALGO_IR_CHNL_NUM_ADDR 0x5FC0 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTIR_IR_CHNL0_1_ADDR 0x5FC4 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTIR_IR_CHNL2_3_ADDR 0x5FC6 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTIR_BG_CHNL0_1_ADDR 0x5FCC +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTIR_BG_CHNL2_3_ADDR 0x5FCE +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTIR_ADT_CHNL0_1_ADDR 0x5FD4 +#define GH3X2X_ALGO_CHNL_MAP_SOFTADTIR_ADT_CHNL2_3_ADDR 0x5FD6 +//finish_flag +#define GH3X2X_FINISH_FLAG_OFFSET 0x00FF +#define GH3X2X_CHECKSUM_ADDR 0xFFFE +#define GH3X2X_END_FLAG_ADDR 0xFFFF + + + +#define GH3X2X_CHNLMAP_OFFSET 0X0022 +#define GH3X2X_VREG_ALGO_PARA_OFFSET 0X00C0 +#define GH3X2X_VREG_FUNCTION_OFFSET 0X0300 +#define GH3X2X_VREG_FUNCTION_ALGO_OFFSET 0X00C0 +#define GH3X2X_VREG_ALGO_CHNL_MAP_OFFSET 0X0200 + + + +/* control config */ + +#define GH3X2X_DUMP_MODE_EN (0) + +#define GH3X2X_ELECTRO_RRECER_OBSERVE_EN (0) + +#define GH3X2X_AGC_BG_CANCEL_ADJ_EN (0) + +#define GH3X2X_AGC_2X2_GAIN_ADJ_EN (0) + +#define GH3X2X_SUPPORT_READ_BACK_VIRTUAL_REG (0) + + + + + + + +/// wakeup and sleep every control api +#define GH3X2X_CTRL_API_INSERT_WAKEUP_AND_DSLP_ENABLED (0) + +/// instructions chip inited by reg val, using reg chip_sw_backup[1:0] +#define GH3X2X_INSTRUCTIONS_CHIP_INIED_ENABLED (1) + +/// wait power pulse mode off effective +#define GH3X2X_PMU_WAIT_PULSE_OFF_ENABLED (0) + +/// fifo power cut before sleep +#define GH3X2X_PMU_FIFO_POWER_CTRL_ENABLED (1) + +/// init communicate confirm max cnt +#define GH3X2X_COMMUNICATE_CONFIRM_MAX_CNT (3) + +/// virtual reg support config software +#define GH3X2X_VIRTUAL_REG_SW_CONFIG_SUPPORT (1) + +/// channel map max channel support to unpack rawdata +#define GH3X2X_CHANNEL_MAP_MAX_CH (32) + +/// gsensor data num +#define GH3X2X_GSENSOR_MAX_SIZE (3) + +/// wear on force switch with adt logic sel +#define GH3X2X_WEAR_ON_FORCE_SWITCH_WITH_LOGIC_SEL (1) + +/// ex control slot enable bit form virtual reg config +#define GH3X2X_EX_SLOT_EN_FROM_CONFIG (0) + +/// ex control channel map cnt follow algorithm +#define GH3X2X_EX_CHANNEL_CNT_FOLLOW_ALGORITHMS (0) + + +/* protocol config */ + +/// universal protocol packet min len support +#define GH3X2X_UPROTOCOL_PACKET_LEN_MIN (20) + + + +/// cmd support config: fifo thr cmd support +#define GH3X2X_UPROTOCOL_FIFO_THR_CFG_CMD_SUP (1) + +/// cmd support config: chip ctrl cmd support wakeup & sleep +#define GH3X2X_UPROTOCOL_CHIP_CTRL_CMD_WAKEUP_SLEEP_SUP (1) + + + + + + + +typedef struct +{ + GU16 usAddrStart; + GU16 usAddrEnd; + void (*ParmSet)(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); +}STGhVirRegSwModuleInfo; + + + + + + + + + + + + + + + + + + + +/** + * @fn GU16 GH3X2X_ReadSwConfigWithVirtualReg(GU16 usVirtualRegAddr) + * + * @brief Read software config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[out] None + * + * @return virtual reg val + */ +GU16 GH3X2X_ReadSwConfigWithVirtualReg(GU16 usVirtualRegAddr); + +/** + * @fn GS8 GH3X2X_WriteSwConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) + * + * @brief Write software param config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[in] usVirtualRegValue virtual reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteSwConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); + +/** + * @fn GU16 GH3X2X_ReadChnlMapConfigWithVirtualReg(GU16 usVirtualRegAddr) + * + * @brief Read software config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[out] None + * + * @return virtual reg val + */ +GU16 GH3X2X_ReadChnlMapConfigWithVirtualReg(GU16 usVirtualRegAddr); + +/** + * @fn GS8 GH3X2X_WriteChnlMapConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) + * + * @brief Write software param config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[in] usVirtualRegValue virtual reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteChnlMapConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); + +/** + * @fn GS8 GH3X2X_WriteVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) + * + * @brief Write virtual reg val, for software param config + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[in] usVirtualRegValue virtual reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); + +/** + * @fn GU16 GH3X2X_ReadVirtualReg(GU16 usVirtualRegAddr) + * + * @brief Read virtual reg val, for software param config + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[out] None + * + * @return virtual reg val + */ +GU16 GH3X2X_ReadVirtualReg(GU16 usVirtualRegAddr); + + + + + + +GU32 GhGetFunctionIdViaVirReg(GU16 usVirRegAddr, GU16 usVirRegData); + +#endif /* _GH3X2X_DRV_CONFIG_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_control.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_control.h new file mode 100644 index 000000000..7dc07fb70 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_control.h @@ -0,0 +1,576 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_control.h + * + * @brief gh3x2x control define & declaration + * + * @version ref gh3x2x_drv_version.h + * + */ + +#ifndef _GH3X2X_DRV_CONTROL_H_ +#define _GH3X2X_DRV_CONTROL_H_ + + +#include "gh_drv_config.h" +#include "gh_drv.h" +#include "gh_drv_registers.h" +#include "gh_demo_config.h" + + +/** + * @brief status flag enum + */ +enum EMGh3x2xStatus +{ + GH3X2X_STATUS_NO_INIT = 0, /**< no init status */ + GH3X2X_STATUS_INITED, /**< inited status */ + GH3X2X_STATUS_STARTED, /**< started status */ + GH3X2X_STATUS_INVALID, /**< invaild status */ +}; + + +/* function ptr typedef */ + +typedef void (*pfnNormalHookFunc)(void); /**< normal hook type */ +typedef void (*pfnGetRawdataHookFunc)(GU8 *puchDataBuffer, GU16 usLen); /**< get rawdata hook type */ +typedef GU8 (*pfnReadPinStatus)(void); /**< read pin status type */ +typedef void (*pfnSetPinLevel)(GU8 uchPinLevel); /**< set pin status type */ +typedef void (*pfnGetIoStructInfo)(const STGh3x2xFrameInfo * const pstFrameInfo); +typedef void (*pfnWriteAlgConfigWithVirtualReg)(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); + +extern GU8 g_uchGh3x2xChipOperateIndexRealtime; + + + +/// send wakeup(resume) cmd +#define GH3X2X_SEND_WAKEUP_CMD() do { GH3X2X_SendCmd(GH3X2X_CMD_RESUME); } while (0) + +/// send sleep cmd +#define GH3X2X_SEND_DSLEEP_CMD() do { GH3X2X_SendCmd(GH3X2X_CMD_SLEEP); } while (0) + +/// send reset cmd +#define GH3X2X_SEND_RESET_CMD() do { GH3X2X_SendCmd(GH3X2X_CMD_RESET); } while (0) + +/// wait send cmd done +#define GH3X2X_SEND_WAIT_CMD_DONE() do { GH3X2X_DelayUs(GH3X2X_CMD_DELAY_X_US); } while (0) + +/// wait send sleep done +#define GH3X2X_SEND_WAIT_SLEEP_CMD_DONE() do { GH3X2X_DelayUs(50); } while (0) + + + + +#define GH3X2X_CHECK_0x0088() GH3X2X_SEND_WAKEUP_CMD();\ + GH3X2X_SEND_WAIT_CMD_DONE();\ + GH3X2X_DEBUG_LOG_PARAM("Master: 0x088:%04x\r\n",GH3X2X_ReadReg(0x88)); + +/// chip wakeup +#define GH3X2X_CHIP_WAKEUP(ret) do {\ + GH3X2X_SEND_WAKEUP_CMD();\ + GH3X2X_SEND_WAIT_CMD_DONE();\ + GH3X2X_PMU_FIFO_POWER_RECOVERY();\ + (ret) = GH3X2X_RET_OK;\ + } while (0) + +/// chip sleep +#define GH3X2X_CHIP_SLEEP(ret) do {\ + GH3X2X_PMU_FIFO_POWER_OFF();\ + GH3X2X_SEND_DSLEEP_CMD();\ + GH3X2X_SEND_WAIT_SLEEP_CMD_DONE();\ + (ret) = GH3X2X_RET_OK;\ + } while (0) + +/// chip reset +#define GH3X2X_CHIP_RESET(ret) do {\ + GH3X2X_SEND_RESET_CMD();\ + (ret) = GH3X2X_RET_OK;\ + } while (0) + +/// chip wakeup +#define GH3X2X_CHIP_WAKEUP_NORET() + +/// chip sleep +#define GH3X2X_CHIP_SLEEP_NORET() do {\ + GH3X2X_PMU_FIFO_POWER_OFF();\ + GH3X2X_SEND_DSLEEP_CMD();\ + GH3X2X_SEND_WAIT_SLEEP_CMD_DONE();\ + GH3X2X_SetChipSleepFlag(g_uchGh3x2xChipOperateIndexRealtime);\ + } while (0) + + + + +/// chip wakeup +#define GH3X2X_CHIP_WAKEUP_PROTOCOL() + +/// chip sleep +#define GH3X2X_CHIP_SLEEP_PROTOCOL() do {\ + GH3X2X_SEND_DSLEEP_CMD();\ + GH3X2X_SEND_WAIT_SLEEP_CMD_DONE();\ + GH3X2X_SetChipSleepFlag(g_uchGh3x2xChipOperateIndexRealtime);\ + } while (0) + + + + + +/// chip reset +#define GH3X2X_CHIP_RESET_NORET() do {\ + GH3X2X_SEND_RESET_CMD();\ + } while (0) + + + +/// chip wakeup +#define GH3X2X_WAIT_CHIP_WAKEUP() + +/// chip sleep +#define GH3X2X_WAIT_CHIP_DSLP() + + + +#if GH3X2X_PMU_WAIT_PULSE_OFF_ENABLED + +/// wait pulse mode off +#define GH3X2X_PMU_WAIT_PULSE_MODE_OFF() do {\ + GH3X2X_SEND_DSLEEP_CMD();\ + GH3X2X_SEND_WAIT_SLEEP_CMD_DONE();\ + GH3X2X_SEND_WAKEUP_CMD();\ + GH3X2X_SEND_WAIT_CMD_DONE();\ + GH3X2X_SEND_WAIT_CMD_DONE();\ + } while (0) + +#else + +/// wait pulse mode off +#define GH3X2X_PMU_WAIT_PULSE_MODE_OFF() do {} while (0) + +#endif + +/* reg addr control bit macro */ + +/// reg addr[11:0] valid +#define GH3X2X_GET_REG_REAL_ADRR(x) ((x) & 0x0FFF) + +/* virtual reg addr mcaro */ + +/// software config reg end addr, software addr map [0x0000~0x09FE] +#define GH3X2X_VIRTUAL_REG_SW_CONFIG_END_ADDR (0x29FF) + +/// algorithm config reg end addr, algorithm addr map [0x0A00~0x0EFE] +#define GH3X2X_VIRTUAL_REG_ALGO_CONFIG_END_ADDR (0x2EFF) + +/// write algorithm config function +#define GH3X2X_FUNCTION_CONFIG_WRITE(...) do { GH3X2X_WriteFunctionConfigWithVirtualReg(__VA_ARGS__); } while (0) +/// write algorithm config function +#define GH3X2X_FUNCTION_CONFIG_READ(...) //(GH3X2X_ReadAlgorithmConfigWithVirtualReg(__VA_ARGS__)) + +/// write software config function +#define GH3X2X_SW_CONFIG_WRITE(...) do { GH3X2X_WriteSwConfigWithVirtualReg(__VA_ARGS__); } while (0) +/// write software config function +#define GH3X2X_SW_CONFIG_READ(...) //(GH3X2X_ReadSwConfigWithVirtualReg(__VA_ARGS__)) + +/* reg instructions chip inited macro */ +#if GH3X2X_INSTRUCTIONS_CHIP_INIED_ENABLED + +/// set chip inited flag into reg +#define GH3X2X_SET_CHIP_INIED() do {\ + GU16 usChipIniedRegValTmp =\ + GH3X2X_ReadReg(GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_ADDR);\ + GH3X2X_WriteReg(GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_ADDR, \ + usChipIniedRegValTmp | GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_VAL);\ + } while (0) + +/// read chip inited flag from reg +#define GH3X2X_IS_CHIP_INIED() ((GH3X2X_ReadReg(GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_ADDR) &\ + GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_VAL) == \ + GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_VAL) +#else + +/// set chip inited flag into reg +#define GH3X2X_SET_CHIP_INIED() + +/// read chip inited flag from reg +#define GH3X2X_IS_CHIP_INIED() (1) + +#endif + +#if GH3X2X_PMU_FIFO_POWER_CTRL_ENABLED + +/// store fifo power status +#define GH3X2X_PMU_FIFO_POWER_OFF() do {\ + if (g_puchPmuFifoModuleCtrlCacheStatus[g_uchGh3x2xChipOperateIndexRealtime] == 0)\ + {\ + if ((g_uchGh3x2xStatus == GH3X2X_STATUS_INITED) || \ + (g_uchGh3x2xStatus == GH3X2X_STATUS_NO_INIT)) \ + {\ + g_pusPmuFifoModuleCtrlVal[g_uchGh3x2xChipOperateIndexRealtime] = \ + GH3X2X_ReadReg(GH3X2X_PMU_CTRL4_REG_ADDR);\ + GH3X2X_WriteReg(GH3X2X_PMU_CTRL4_REG_ADDR, \ + (g_pusPmuFifoModuleCtrlVal[g_uchGh3x2xChipOperateIndexRealtime] | GH3X2X_PMU_CTRL4_FIFO_DISABLE_MASK));\ + g_puchPmuFifoModuleCtrlCacheStatus[g_uchGh3x2xChipOperateIndexRealtime] = 1;\ + GH3X2X_DEBUG_LOG_INTERNAL("save pmu fifo module status!\r\n");\ + }\ + }\ + } while (0) + +/// set chip inited flag into reg +#define GH3X2X_PMU_FIFO_POWER_RECOVERY() do {\ + if (g_puchPmuFifoModuleCtrlCacheStatus[g_uchGh3x2xChipOperateIndexRealtime] == 1)\ + {\ + GH3X2X_WriteReg(GH3X2X_PMU_CTRL4_REG_ADDR, \ + g_pusPmuFifoModuleCtrlVal[g_uchGh3x2xChipOperateIndexRealtime]);\ + GH3X2X_DEBUG_LOG_PARAM("write pmu: 0x%X\r\n",g_pusPmuFifoModuleCtrlVal[g_uchGh3x2xChipOperateIndexRealtime]);\ + GH3X2X_PMU_WAIT_PULSE_MODE_OFF();\ + g_puchPmuFifoModuleCtrlCacheStatus[g_uchGh3x2xChipOperateIndexRealtime] = 0;\ + GH3X2X_DEBUG_LOG_INTERNAL(\ + "recovery pmu fifo module status!\r\n");\ + }\ + } while (0) + +#else + +/// store fifo power status +#define GH3X2X_PMU_FIFO_POWER_OFF() + +/// set chip inited flag into reg +#define GH3X2X_PMU_FIFO_POWER_RECOVERY() + +#endif + +/// wear detect force switch delay +#define GH3X2X_WEAR_DETECT_SWITCH_WAIT_X_US (150) + +/// hard reset delay +#define GH3X2X_HARD_RESET_DELAY_X_US (100) + +/// fifo watermark thr min val +#define GH3X2X_FIFO_WATERMARK_THR_MIN (3) + +/// fifo watermark thr max val +#define GH3X2X_FIFO_WATERMARK_THR_MAX (800) + +/// irq width val +#define GH3X2X_IRQ_WIDTH_VAL_MAX (2047) + +/* osc cali */ + +/// osc calibration code lock flag +#define GH3X2X_OSC_CALI_CODE_LOACKED (0x0001) + +/// osc calibration Ctrl disable +#define GH3X2X_OSC_CALI_CTRL_DIS_VAL (0x0000) + +/// hsi osc calibration delay +#define GH3X2X_HSI_CALI_DELAY_VAL (1000u) + +/// hsi osc calibration theroy count +#define GH3X2X_HSI_CALI_THR_CNT_VAL (0x0196) + +/// hsi osc calibration Ctrl enable +#define GH3X2X_HSI_CALI_CTRL_EN_VAL (0x0271) + +/// lsi osc calibration theroy count +#define GH3X2X_LSI_CALI_THR_CNT_VAL (0x1F40) + +/// lsi osc calibration ctrl coarse enable +#define GH3X2X_LSI_CALI_CTRL_C_EN_VAL (0x09D7) + +/// lsi osc calibration ctrl fine enable +#define GH3X2X_LSI_CALI_CTRL_F_EN_VAL (0x19D3) + +/// lsi osc calibration error val max +#define GH3X2X_LSI_CALI_ERR_MAX_VAL (0x3FFF) + +/// lsi osc calibration error val fixed val +#define GH3X2X_LSI_CALI_ERR_FIXED_VAL (0x8000) + +/// lsi osc calibration fine error max +#define GH3X2X_LSI_CALI_FINE_VAL_MAX (255u) + +/// lsi osc calibration fine tune max cnt +#define GH3X2X_LSI_CALI_FINE_TUNE_MAX (9u) + +/// lsi osc calibration fine div num +#define GH3X2X_LSI_CALI_FINE_DIV_NUM (2u) + +/// lsi osc calibration delay +#define GH3X2X_LSI_COR_CALI_DELAY_VAL (50000u) + +/// lsi osc calibration delay +#define GH3X2X_LSI_FINE_CALI_DELAY_VAL (5000u) + +/**< rawdata buffer size in byte */ +#define GH3X2X_RAWDATA_BUFFER_SIZE (200*4) + +/// get slot & adc num from rawdata flag byte, equal channel map formats +#define GH3X2X_CHANNEL_MAP_GET(x) ((x) & GH3X2X_SLOT_ADC_NUM_BITS) + + + +// fifo monitor start + +typedef struct +{ + GU8 uchDecimaionChnlNum; //0~8 + GU8 puchSlotAdcIdx[GH3X2X_DECIMAION_CHNL_MAX]; //slot and adc index for valid decimation channel + GU8 puchDecimationOption[GH3X2X_DECIMAION_CHNL_MAX]; //1: 2x decimation 2: 4x decimaiton 3: 8x deccimaion others: is illegal +} STGh3x2xDecimationInfo; + + + + +#define EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX0_INDEX 0 +#define EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX1_INDEX 1 +#define EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX2_INDEX 2 +#define EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX3_INDEX 3 + + +#define GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE 1 +#define GH3X2X_FIFO_MONITOR_DEBUG 0 + + +typedef struct +{ + GU8 uchLowestChnlSlotAdcIdx; // slot and adc index of lowest channel, 0xFF means: there is no channel output to fifo + GU8 uchLowestChnlAppearedFlag; //0£ºnever appeared 1: appeared + GU16 usNeedSkipFifoByteNum; //the number which we need skip before formal monitor +#if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + GU16 usRealTimeSampleCnt[GH3X2X_SLOT_NUM_MAX]; //real time counter of sample of every slot between two lowest channels sample + #if GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT + GU16 uchEstiSampleCntUplimit[GH3X2X_SLOT_NUM_MAX]; //estimate up limit counter of sample of every slot between two lowest channels sample + #endif + GU16 usEstiSampleCntlimit [GH3X2X_SLOT_NUM_MAX]; //estimate down limit counter of sample of every slot between two lowest channels sample +#endif + GU16 usAllChnlRealTimeSampleCnt; + #if GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT + GU16 usEstiAllChnlSampleCntUplimit; + #endif + GU16 usEstiAllChnlSampleCntlimit; +#if GH3X2X_FIFO_MONITOR_DEBUG + GU16 usEveryChnlRealTimeSampleCnt[GH3X2X_SLOT_NUM_MAX][GH3X2X_RX_NUM_MAX]; +#endif +} STGh3x2xFifoMonitorInfo; + + + + + + + + + +/* extern variables declaration */ + +/// get rawdata hook func ptr +extern pfnGetRawdataHookFunc g_pGh3x2xGetRawdataHookFunc; + +/// read int pin status func ptr +extern pfnReadPinStatus g_pGh3x2xReadIntPinStatusFunc; + +/// read reset pin status func ptr +extern pfnReadPinStatus g_pGh3x2xReadResetPinStatusFunc; + +/// read spcs pin status func ptr +extern pfnReadPinStatus g_pGh3x2xReadSpcsPinStatusFunc; + +/// read spdo pin status func ptr +extern pfnReadPinStatus g_pGh3x2xReadSpdoPinStatusFunc; + +/// set algo config hook func ptr +extern pfnWriteAlgConfigWithVirtualReg g_pGh3x2xWriteAlgConfigWithVirtualRegHookFunc; + +/// config start set hook func ptr +extern pfnNormalHookFunc g_pGh3x2xConfigSetStartHookFunc; + +/// config stop set hook func ptr +extern pfnNormalHookFunc g_pGh3x2xConfigSetStopHookFunc; + +#if GH3X2X_PMU_FIFO_POWER_CTRL_ENABLED + +/// fifo power ctrl fifo control reg cache var +extern GU16 g_pusPmuFifoModuleCtrlVal[]; + +/// for fifo power ctrl cache status +extern GU8 g_puchPmuFifoModuleCtrlCacheStatus[]; + +#endif + +/// gh3x2x status +extern GU8 g_uchGh3x2xStatus; + +/// max rawdata num read from fifo every time +extern GU16 g_usMaxNumReadFromFifo; + + + +extern GU8 g_uchGsensorEnable; +/// Cap enable flag +extern GU8 g_uchCapEnable; + +/// Temp enable flag +extern GU8 g_uchTempEnable; + +/// function started bitmap, use for sampling control +extern GU32 g_unFuncStartedBitmap ; + +/** + * @fn GU16 GH3X2X_FindGu16MinVal(GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find min val + * + * @attention len must > 0 + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] None + * + * @return min val, if len = 0, return 0 + */ +GU16 GH3X2X_FindGu16MinVal(GU16 *pusBuffer, GU8 uchLen); + +/** + * @fn GU16 GH3X2X_FindGu16MaxVal(GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find max val + * + * @attention len must > 0 + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] None + * + * @return max val, if len = 0, return 0 + */ +GU16 GH3X2X_FindGu16MaxVal(GU16 *pusBuffer, GU8 uchLen); + +/** + * @fn void GH3X2X_FindGu16MaxMinVal(GU16 *pusMaxVal, GU16 *pusMinVal, GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find min val & max val + * + * @attention len must > 0, ptr not null + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] pusMaxVal pointer to max val + * @param[out] pusMinVal pointer to min val + * + * @return None + */ +void GH3X2X_FindGu16MaxMinVal(GU16 *pusMaxVal, GU16 *pusMinVal, GU16 *pusBuffer, GU8 uchLen); + +/** + * @fn GU8 GH3x2x_GetChipResetRecoveringFlag(void) + + + * + * @brief + * + * @attention None. + * + * @param[in] None + * @param[out] chip reset recovering flag 0: is not in chip reset recovering flag 1: is in chip reset recovering + * + * @return None + */ +GU8 GH3x2x_GetChipResetRecoveringFlag(void); + + +/** + * @fn void GH3X2X_ReinitAllSwModuleParam(GU16 usReinitFlag) + * + * @brief reinit all software param config + * + * @attention None + * + * @param[in] usReinitFlag reinit flag, #0 don't reinit, #others reinit all + * @param[out] None + * + * @return None + */ +void GH3X2X_ReinitAllSwModuleParam(GU16 usReinitFlag); + +GU8 GH3x2xGetProtocolMode(void); +void GH3x2xCreatTagArray(GU8 *puchTagArray, GU16 usArrayLen,GU32 *unCompeletMask, const STGh3x2xFrameInfo * const pstFrameInfo); +void GH3x2xHandleFrameData(const STGh3x2xFrameInfo * const pstFrameInfo, GU32 *punTempIncompeletFlag, + GU32 *punFunctionID, GU8 uchChnlNum, GU8 *puchRawdataBuf, GU32 *punFrameRawdata, + GU8 *puchTag, GS16 *pusGsValueArr, float fGsensorIndex, + STCapRawdata* pstCapValueArr,float fCapIndex,STTempRawdata* pstTempValueArr,float fTempIndex); + +GU8 GH3X2X_CheckRawdataBuf(GU8 *puchRawdata, GU16 usRawdataLen); +float GH3x2xCalGsensorStep(GU16 usGsDataNum, GU16 usFrameNum); +void GH3X2X_SendOverflowLengthBuffer(GU8 *puchBuffer, GS32 nBufferLen, GU8 uchCmd, GU8 uchSignID); +GU8 GH3X2X_ReceiveOverflowLengthBuffer(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchReceiveBuffer, GS32 *pnReceiveBufferLen); + + +/** + * @fn GU32 DRV_DSP_RawdataCalc(GU32 *punRawdata) + * + * @brief calc byte check rawdata + * + * @attention + * + * @param[in] punRawdata one rawdata addr + * @param[out] None + * + * @return target rawdata + */ +GU32 DRV_DSP_RawdataCalc(GU32 unRawdata); + +/** + * @fn GU8 DRV_DSP_RawdataCheck(GU32 unRawdata) + * + * @brief rawdata check last byte in algo lib + * + * @attention none + * + * @param[in] unRawdata single rawdata + * @param[out] None + * + * @return errcode + * @retval 0 check success + * @retval 1 check failed + */ +GU8 DRV_DSP_RawdataCheck(GU32 unRawdata); + +/** + * @fn void DRV_DSP_RawdataTransform(GU32 *punRawdata) + * + * @brief calc new rawdata + * + * @attention + * + * @param[in] punRawdata + * + * @return none + */ +void DRV_DSP_RawdataTransform(GU32 *punRawdata); + +/** + * @fn GU8 GH3X2X_GetSoftWearColor(void) + * + * @brief GetSoftWearColor + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return SoftWearColor 0: green 1:ir + */ + +GU8 GH3X2X_GetSoftWearColor(void); +void GH3X2X_SetConfigDrvEcode(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam); +void GH3X2X_SetDrvEcode(GS8 chECode); + +#if (GH3X2X_FIFO_MONITOR_EN&(__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__)) +void Gh3x2xFifoMonitorInit(STGh3x2xFifoMonitorInfo *pstMonitorInfo); +void Gh3x2xFifoMonitorPro(STGh3x2xFifoMonitorInfo *pstMonitorInfo, GU8 *pFifo, GU16 FifoByteNum); +#endif + +#endif /* _GH3X2X_DRV_CONTROL_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_dump.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_dump.h new file mode 100644 index 000000000..ee4c8d177 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_dump.h @@ -0,0 +1,463 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_dump.h + * + * @brief gh3x2x dump data define & declaration + * + * @version ref gh3x2x_drv_version.h + * + */ + +#ifndef _GH3X2X_DRV_DUMP_H_ +#define _GH3X2X_DRV_DUMP_H_ + + +#include "gh_drv_config.h" +#include "gh_drv.h" + + +typedef struct +{ + GU8 uchAddrOffset; + GU8 uchMsb; + GU8 uchLsb; +} STGh3x2xAgcReg; + + + +/** + * @brief dump data bg lvl select enum + */ +enum EMGh3x2xDumpRawdataBgLvlSelect +{ + GH3X2X_DUMP_RAWDATA_BGLVL0 = 0, /**< dump rawdata bg 0 lvl */ + GH3X2X_DUMP_RAWDATA_BGLVL1, /**< dump rawdata bg 1 lvl */ + GH3X2X_DUMP_RAWDATA_BGLVL2, /**< dump rawdata bg 2 lvl */ + GH3X2X_DUMP_RAWDATA_BGLVL2X2, /**< dump rawdata bg 2x2 lvl */ +}; + +/** + * @brief channnel dump data struct type + */ +typedef struct +{ + GU32 *punPkgNoAndCurrentArr; /**< pointer to buffer store PkgNo¤t data, map e.g. ch0 ch1...chx ch0 */ + GU32 *punChBgRawdataArr; /**< pointer to buffer store channel bg data, map e.g. ch0 ch1...chx ch0 */ + GU32 *punChRawdataArr; /**< pointer to buffer store channel data, map e.g. ch0 ch1...chx ch0 */ + GU16 usChRawdataCnt; /**< channel rawdata count output */ + GU32 (*punIncompleteChRawdataArr)[6]; /**< pointer to last incomplete packet buffer */ + GU8 uchChIncompleteFlagArr[32]; /**< channel incomplete flag, max 32 channel */ +} STGh3x2xChannelDumpData; + + + + + + + + + + + + +/// rawdata filter array length in byte +#define RAWDATA_FILTER_ARRAY_BYTE_LENGTH (200 * GH3X2X_FIFO_RAWDATA_SIZE) + +/// dump data max num +#define DUMP_DATA_MAX_NUM (6) + +/// max slot num +#define GH3X2X_MAX_SLOT_NUM (8) + +/// ADC num +#define GH3X2X_ADC_NUM (4) + +/// offset of slot0 ~ slot8 regs address +#define SLOT_ADDR_OFFSET (0x001C) + +/// mask of adc0 ~ adc3 tia gain +#define GH3X2X_DRV_CURRENT_BIT_MASK (0xFF) + +/// left shift bit of drv0 current in drv current data +#define GH3X2X_DRV0_CURRENT_LEFT_SHIFT_BIT_NUM (0x0) + +/// left shift bit of drv1 current in drv current data +#define GH3X2X_DRV1_CURRENT_LEFT_SHIFT_BIT_NUM (0x8) + +/// bit num of adc0 ~ adc3 bg cancel +#define GH3X2X_ADC_TIA_GAIN_BIT_NUM (0x4) + +/// mask of adc0 ~ adc3 tia gain +#define GH3X2X_ADC_TIA_GAIN_BIT_MASK (0xF) + +/// bit num of adc0 ~ adc3 bg cancel +#define GH3X2X_ADC_BG_CANCEL_BIT_NUM (0x2) + +/// mask of adc0 ~ adc3 bg cancel +#define GH3X2X_ADC_BG_CANCEL_BIT_MASK (0x3) + +/// left shift bit of gain in gain&bgcancel data +#define GH3X2X_ADC_TIA_GAIN_LEFT_SHIFT_BIT_NUM (0x0) + +/// left shift bit of bg cancel in gain&bgcancel data +#define GH3X2X_ADC_BG_CANCEL_LEFT_SHIFT_BIT_NUM (0x4) + +/// mask of slot bg level +#define GH3X2X_SLOT_BG_LEVEL_BIT_MASK (0x03) + +/// dump data offset +#define GH3X2X_DUMP_DATA_OFFSET (8388608) + +/// max dump data num of every channel +#define GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL (4) + +/// max dump data num of every channel that will upload +#define GH3X2X_MAX_DUMP_DATA_NUM_UPLOAD (3) + +/// dump gain & current enable +#define GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT (0) + +/// dump ambiance enable +#define GH3X2X_DUMP_AMBIANCE_ENABLE_BIT (1) + +/// dump electrode wear enable +#define GH3X2X_DUMP_ELECTR_WEAR_ENABLE_BIT (2) + +/// ECG enable bit +#define GH3X2X_ECG_ENABLE_BIT (0x1) + +/// ECG ADC index +#define GH3X2X_ECG_ADC_INDEX (0x3) + +/// dump electrode wear status bit field +#define GH3X2X_ELECTR_WEAR_STATUS_BIT_FIELD (0x1) + +/// dump electrode wear status bit in data tag of rawdata +#define GH3X2X_ELECTR_WEAR_STATUS_BIT_IN_DATA_TAG (0x1) + +/// dump data ppg index in buffer after filter +#define GH3X2X_DUMP_DATA_PPG_INDEX (0) + +/// dump data gain current index in buffer after filter +#define GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX (1) + +/// dump data ambiance index in buffer after filter +#define GH3X2X_DUMP_DATA_AMBIANCE_INDEX (2) + +/// gain & current data size +#define GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE (4) + +/// ambiance data size +#define GH3X2X_DUMP_AMBIANCE_DATA_SIZE (3) + +/// gain & current data calc +#define GH3X2X_DUMP_GAIN_CURRENT_CALC(x) ((x) * GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE) + +/// ambiance data calc +#define GH3X2X_DUMP_AMBIANCE_CALC(x) ((x) * GH3X2X_DUMP_AMBIANCE_DATA_SIZE) + +/// gain value in dump data +#define DUMP_GAIN(x) ((((GU8*)(&(x)))[1]) >> 4) + +/// current0 in dump data +#define DUMP_CUREENT0(x) (((GU8*)(&(x)))[3]) + +/// current1 in dump data +#define DUMP_CUREENT1(x) (((GU8*)(&(x)))[2]) + +/// PPG data in dump data +#define DUMP_PPG_DATA(x) ((((GU32)(((GU8*)(&(x)))[1])) << 16) + (((GU32)(((GU8*)(&(x)))[2])) << 8)\ + + (((GU32)(((GU8*)(&(x)))[3])) << 0)) + +/// current data index in raw data buf +extern GU16 g_usGh3x2xDataIndexInBuf; + +/// current data index in raw data buf of every channel +extern GU16 g_usRawdataByteIndexArr[]; + +/// packet payload +//extern GU8 g_uchPacketPayloadArr[]; + +/// current data index in raw data buf +extern GF32 g_fGsDataIndexInBuf; + +/// packet max len support +extern GU8 g_uchPacketMaxLenSupport; + +/// function started bitmap, use for sampling control +extern GU32 g_unFuncStartedBitmap; + +//save bg cancel value of every channel +extern GU8 g_puchGainBgCancelRecord[]; + +//save current of drv0 and drv1 +extern STGh3x2xAgcInfo *g_pstGh3x2xAgcInfo; + +/** + * @fn void GH3X2X_DumpInit(void) + * + * @brief init dump moudle + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_DumpInit(void); + +/** + * @fn void GH3X2X_DumpModeSet(GU16 usRegVal) + * + * @brief set dump mode + * + * @attention None + * + * @param[in] usRegVal reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_DumpModeSet(GU16 usRegVal); + +/** + * @fn GU16 GH3X2X_DumpModeGet(void) + * + * @brief get dump mode + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return dump mode + */ +GU16 GH3X2X_DumpModeGet(void); + +/** + * @fn void GH3X2X_BgLevelSet(GU16 usRegVal) + * + * @brief set bg level of every slot + * + * @attention None + * + * @param[in] usRegVal reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_BgLevelSet(GU16 usRegVal); + +/** + * @fn void GH3X2X_RecordDumpData(void) + * + * @brief read some dump data, and save them + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_RecordDumpData(void); + +/** + * @fn void GH3X2X_ReadElectrodeWearDumpData(void) + * + * @brief read eletrode wear status + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return dump mode + */ +void GH3X2X_ReadElectrodeWearDumpData(void); + +/** + * @fn void GH3X2X_BgLevelDecode(GU8 puchBgLvArr[], GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU16 usBgLevel) + * + * @brief decode function's bg level array according to channel map and slot bg level + * + * @attention if there is 2x2 bg level,set the first slot to level 2 + * + * @param[in] uchChannelCnt channel cnt + * @param[in] puchChannelMapArray channel map array + * @param[in] usBgLevel bg level of slot + * @param[out] puchBgLvArr bg level array + * + * @return None + */ +void GH3X2X_BgLevelDecode(GU8 puchBgLvArr[], GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU16 usBgLevel); + +/** + * @fn GS8 GH3X2X_GetDumpDataInfo(GF32 *pfGsFloatIncVal, GU16 *pusChannelDataCnt, + * GU8 *puchNextIncompleteFlag,GU8 *puchDumpDataIndexArr, + * GU8 *puchIncompleteFlagArr, GU16 usFifoLength, GU8 *puchDataBuffer, + * GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU8 *puchChannelBgLvlArr, + * GU16 usReadGsensorArrCnt) + * + * @brief Get information from rawdata + * + * @attention None + * + * @param[out] pfGsFloatIncVal pointer to gsensor inc value output + * @param[out] pusChannelDataCnt pointer to slot data cnt output + * @param[out] puchNextIncompleteFlag pointer to next incomplete flag arr output + * @param[out] puchDumpDataIndexArr pointer to dump data index output + * @param[in] puchIncompleteFlagArr incomplete flag array of last rawdata frame + * @param[in] usFifoLength read fifo buffer data len + * @param[in] puchDataBuffer pointer to read fifo buffer + * @param[in] uchChannelCnt channel map arr cnt + * @param[in] puchChannelMapArray pointer to channel map arr + * @param[in] puchChannelBgLvlArr pointer to bg lvl arr + * @param[in] usReadGsensorArrCnt read gsensor array cnt + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR generic error when size is 0 + * @retval #GH3X2X_RET_RESOURCE_ERROR resource error when doesn't correspond to channel map + */ +GS8 GH3X2X_GetDumpDataInfo(GF32 *pfGsFloatIncVal, GU16 *pusChannelDataCnt, + GU8 *puchNextIncompleteFlag, GU8 *puchDumpDataIndexArr, + GU8 *puchIncompleteFlagArr, GU16 usFifoLength, GU8 *puchDataBuffer, + GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU8 *puchChannelBgLvlArr, + GU16 usReadGsensorArrCnt); + +/** + * @fn GS8 GH3X2X_UnpackDumpDataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + * GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, + * GU8 *puchChannelBgLvlArr) + * + * @brief Unpack to channel dump data from read fifo data buffer; + * if dump data incomplete, should change fifo watermark + * + * @attention This function should use in get rawdata hook + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] usReadRawdataLen read data length + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[in] puchChannelBgLvlArr pointer to channel lvl array, @ref EMGh3x2xDumpRawdataBgLvlSelect + * @param[out] pstGh3x2xChannelDumpData pointer to channel rawdata struct + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_UnpackDumpDataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, + GU8 *puchChannelBgLvlArr); + +/** + * @fn GS16 GH3X2X_GetDumpdataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + * GU8 *puchReadRawdataBuffer, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, GU8 *puchBglvlArr) + * + * @brief Get dump data from fifo with channel map + * + * @attention None + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[in] puchBglvlArr pointer to bg lvl array, @ref EMGh3x2xDumpRawdataBgLvlSelect + * @param[out] pstGh3x2xChannelDumpData pointer to channel rawdata struct output + * + * @return GH3X2X_RET_OK return get data successful + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo is not empty + */ +GS16 GH3X2X_GetDumpdataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + GU8 *puchReadRawdataBuffer, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, GU8 *puchBglvlArr); + +/** + * @fn GS8 GH3X2X_ChannelMapDumpDataClear(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData) + * + * @brief clear channel map dump data struct + * + * @attention This function must use before get dump data by one kind channel map + * e.g. channel map start/stop need clear + * + * @param[in] pstGh3x2xChannelDumpData pointer to channel dump data struct + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_ChannelMapDumpDataClear(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData); + +/** + * @fn void GH3X2X_ElectrWearDumpDataPro(GU8* puchRawdataTag, GU8 uchChMapIndex) + * + * @brief electrode wear dump data pro + * + * @attention None + * + * @param[in] puchRawdataTag data tag of rawdata + * @param[in] uchChMapIndex channel map index + * @param[out] None + * + * @return None + */ +void GH3X2X_ElectrWearDumpDataPro(GU8* puchRawdataTag, GU8 uchChMapIndex); + +/** + * @fn GS8 GH3X2X_SendSpo2DumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ + +/** + * @fn GS8 GH3X2X_SendHbDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ + + + + + + + +#endif /* _GH3X2X_DRV_DUMP_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_interface.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_interface.h new file mode 100644 index 000000000..9784f8a09 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_interface.h @@ -0,0 +1,118 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_interface.h + * + * @brief gh3x2x interface define & declaration + * + * @version ref gh3x2x_drv_version.h + * + */ + +#ifndef _GH3X2X_DRV_INTERFACE_H_ +#define _GH3X2X_DRV_INTERFACE_H_ + + +#include "gh_drv_config.h" +#include "gh_drv.h" + + +/* function ptr typedef */ + +typedef GU8 (*pfnI2cWrite)(GU8 uchDeviceId, const GU8 uchWriteBytesArr[], GU16 usWriteLen); /**< i2c write type */ +typedef GU8 (*pfnI2cRead)(GU8 uchDeviceId, const GU8 uchCmddBytesArr[], GU16 usCmddLen, + GU8 uchReadBytesArr[], GU16 usMaxReadLen); /**< i2c read type */ +typedef void (*pfnDelayUs)(GU16 usUsec); /**< delay us type */ +typedef GU8 (*pfnSpiRWCtrl)(GU8 uchBufferArrArr[], GU16 usLen); /**< spi rw type */ +typedef void (*pfnSpiCsCtrl)(GU8 uchCsLevel); /**< spi cs ctrl type */ +typedef void (*pfnSendCmd)(GU8 uchCmd); /**< send cmd type */ +typedef void (*pfnWriteReg)(GU16 usAddr, GU16 usValue); /**< write reg type */ +typedef GU16 (*pfnReadReg)(GU16 usAddr); /**< read reg type */ +typedef void (*pfnReadRegs)(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 uchLen); /**< read regs type */ +typedef void (*pfnReadFifo)(GU8 *puchDataBuffer, GU16 usLen); /**< read fifo type */ + + + +/// i2c ctrl interface, base device addr +#define GH3X2X_I2C_DEVICE_ID_BASE (0x28) + +/// spi seq write cmd val +#define GH3X2X_SPI_CMD_WRITE (0xF0) + +/// spi seq read cmd val +#define GH3X2X_SPI_CMD_READ (0xF1) + +/// spi cs ctrl high level val +#define GH3X2X_SPI_CS_CTRL_HIGH (0x01) + +/// spi cs ctrl low level val +#define GH3X2X_SPI_CS_CTRL_LOW (0x00) + +/// spi seq wait delay, 4us +#define GH3X2X_SPI_WAIT_DELAY_X_US (4) + +/// spi seq end delay, 2us +#define GH3X2X_SPI_END_DELAY_X_US (3) + +/// send cmd delay, 500us +#define GH3X2X_CMD_DELAY_X_US (500) + +/// sleep cmd val +#define GH3X2X_CMD_SLEEP (0xC4) + +/// resume cmd val +#define GH3X2X_CMD_RESUME (0xC3) + +/// reset cmd val +#define GH3X2X_CMD_RESET (0xC2) + +/// use for delay 1us, must test in more platforms, only test in stm32f412 +#define GH3X2X_DELAY_ONE_US_CNT (9u) + + +/** + * @fn void GH3X2X_SwapLittleBigEndianData(GU8 *puchDataBuffer, GU16 usDataLength) + * + * @brief Swap little big endian data + * + * @attention None + * + * @param[in] puchDataBuffer pointer to data buffer. + * @param[in] usDataLength data buffer len. + * @param[out] None + * + * @return None + */ +void GH3X2X_SwapLittleBigEndianData(GU8 *puchDataBuffer, GU16 usDataLength); + +/** + * @fn void GH3X2X_DelayUs(GU16 usUsCnt) + * + * @brief Delay N Us for gh3x2x + * + * @attention None + * + * @param[in] usUsCnt count need to delay(Us) + * @param[out] None + * + * @return None + */ +void GH3X2X_DelayUs(GU16 usUsCnt); + +/** + * @fn void GH3X2X_SendCmd(GU8 uchCmd) + * + * @brief Send cmd via i2c or spi + * + * @attention None + * + * @param[in] uchCmd cmd + * @param[out] None + * + * @return None + */ +void GH3X2X_SendCmd(GU8 uchCmd); + +#endif /* _GH3X2X_DRV_INTERFACE_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_registers.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_registers.h new file mode 100644 index 000000000..0faa2065b --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_registers.h @@ -0,0 +1,460 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_registers.h + * + * @brief gh3x2x driver registers define + * + * @version ref gh3x2x_drv_version.h + * + */ + +#ifndef _GH3X2X_DRV_REGISTERS_H_ +#define _GH3X2X_DRV_REGISTERS_H_ + +/* register mapping definition */ + +// top ctrl block, start addr: 0x0000 +#define GH3X2X_CARDIFF_CTRL_REG_ADDR (0x0000) /**< start ctrl */ +#define GH3X2X_SYSCLK_CTRL_REG_ADDR (0x0002) +#define GH3X2X_SYS_SAMPLE_RATE_CTRL_REG_ADDR (0x0004) +#define GH3X2X_DATA_CTRL0_REG_ADDR (0x0006) +#define GH3X2X_DATA_CTRL1_REG_ADDR (0x0008) +#define GH3X2X_FIFO_WATERLINE_REG_ADDR (0x000A) /**< fifo watermark thr */ +#define GH3X2X_WKUP_TMR_REG_ADDR (0x000E) +#define GH3X2X_ADC0_DATA_L_REG_ADDR (0x0010) +#define GH3X2X_ADC0_DATA_H_REG_ADDR (0x0012) +#define GH3X2X_ADC1_DATA_L_REG_ADDR (0x0014) +#define GH3X2X_ADC1_DATA_H_REG_ADDR (0x0016) +#define GH3X2X_ADC2_DATA_L_REG_ADDR (0x0018) +#define GH3X2X_ADC2_DATA_H_REG_ADDR (0x001A) +#define GH3X2X_ADC3_DATA_L_REG_ADDR (0x001C) +#define GH3X2X_ADC3_DATA_H_REG_ADDR (0x001E) +#define GH3X2X_PAD_CTRL0_REG_ADDR (0x0020) +#define GH3X2X_PAD_CTRL1_REG_ADDR (0x0022) +#define GH3X2X_PAD_CTRL2_REG_ADDR (0x0024) +#define GH3X2X_PAD_CTRL3_REG_ADDR (0x0026) +#define GH3X2X_PAD_CTRL4_REG_ADDR (0x0028) +#define GH3X2X_PAD_CTRL5_REG_ADDR (0x002A) +#define GH3X2X_PRODUCT_L_REG_ADDR (0x0030) /**< product id l */ +#define GH3X2X_PRODUCT_H_REG_ADDR (0x0032) /**< product id h */ +#define GH3X2X_CHIP_ID_REG_ADDR (0x0034) /**< chip id */ +#define GH3X2X_CHIP_READY_CODE_REG_ADDR (0x0036) +#define GH3X2X_DYN_CKGT_CTRL_REG_ADDR (0x0038) +#define GH3X2X_ACCESS_READY_CODE_ADDR (0x0050) +#define GH3X2X_CHIP_ECG_BACKDOOR_REG_ADDR (0x0070) +#define GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_ADDR (0x0072) /**< reg addr 0x72:rg_chip_sw_backup. */ +#define GH3X2X_CHIP_ECO_RESERVE_REG_ADDR (0x0074) + +// pmu block, start addr: 0x0080 +#define GH3X2X_PMU_CTRL0_REG_ADDR (0x0080) +#define GH3X2X_PMU_CTRL1_REG_ADDR (0x0082) +#define GH3X2X_PMU_CTRL2_REG_ADDR (0x0084) +#define GH3X2X_PMU_CTRL3_REG_ADDR (0x0086) +#define GH3X2X_PMU_CTRL4_REG_ADDR (0x0088) /**< pmu fifo power ctrl */ +#define GH3X2X_PMU_CTRL5_REG_ADDR (0x008A) +#define GH3X2X_PMU_CTRL6_REG_ADDR (0x008C) +#define GH3X2X_PMU_CTRL7_REG_ADDR (0x008E) +#define GH3X2X_PMU_CTRL8_REG_ADDR (0x0090) + +// timeslot block, start addr: 0x0100 +#define GH3X2X_SLOT_INDEX_CTRL0_REG_ADDR (0x0100) +#define GH3X2X_SLOT_INDEX_CTRL1_REG_ADDR (0x0102) +#define GH3X2X_SLOT_INDEX_CTRL2_REG_ADDR (0x0104) +#define GH3X2X_SLOT_INDEX_CTRL3_REG_ADDR (0x0106) +#define GH3X2X_SLOT_ENABLE_CFG_REG_ADDR (0x0108) /**< slot enable config */ +#define GH3X2X_SLOT_ENABLE_CFG_REG_LSB (0) +#define GH3X2X_SLOT_ENABLE_CFG_REG_MSB (7) +#define GH3X2X_SLOT_RX_EN_FIFO_EN_LSB (2) +#define GH3X2X_SLOT_RX_EN_FIFO_EN_MSB (6) +#define GH3X2X_SLOT_FIFO_EN_LSB (6) +#define GH3X2X_SLOT_FIFO_EN_MSB (6) +#define GH3X2X_SLOT_CTRL_ADDR_INTERVAL (0x1C) +#define GH3X2X_SLOT_SR_MULTIPLIER_LSB (8) +#define GH3X2X_SLOT_SR_MULTIPLIER_MSB (15) +#define GH3X2X_SLOT0_CTRL_0_REG_ADDR (0x010A) /**< slot 0 */ +#define GH3X2X_SLOT0_CTRL_1_REG_ADDR (0x010C) +#define GH3X2X_SLOT0_CTRL_2_REG_ADDR (0x010E) +#define GH3X2X_SLOT0_CTRL_3_REG_ADDR (0x0110) +#define GH3X2X_SLOT0_CTRL_4_REG_ADDR (0x0112) +#define GH3X2X_SLOT0_CTRL_5_REG_ADDR (0x0114) +#define GH3X2X_SLOT0_CTRL_6_REG_ADDR (0x0116) +#define GH3X2X_SLOT0_CTRL_7_REG_ADDR (0x0118) +#define GH3X2X_SLOT0_CTRL_8_REG_ADDR (0x011A) +#define GH3X2X_SLOT0_CTRL_9_REG_ADDR (0x011C) +#define GH3X2X_SLOT0_CTRL_10_REG_ADDR (0x011E) +#define GH3X2X_SLOT0_CTRL_11_REG_ADDR (0x0120) +#define GH3X2X_SLOT0_CTRL_12_REG_ADDR (0x0122) +#define GH3X2X_SLOT0_CTRL_13_REG_ADDR (0x0124) +#define GH3X2X_SLOT1_CTRL_0_REG_ADDR (0x0126) /**< slot 1 */ +#define GH3X2X_SLOT1_CTRL_1_REG_ADDR (0x0128) +#define GH3X2X_SLOT1_CTRL_2_REG_ADDR (0x012A) +#define GH3X2X_SLOT1_CTRL_3_REG_ADDR (0x012C) +#define GH3X2X_SLOT1_CTRL_4_REG_ADDR (0x012E) +#define GH3X2X_SLOT1_CTRL_5_REG_ADDR (0x0130) +#define GH3X2X_SLOT1_CTRL_6_REG_ADDR (0x0132) +#define GH3X2X_SLOT1_CTRL_7_REG_ADDR (0x0134) +#define GH3X2X_SLOT1_CTRL_8_REG_ADDR (0x0136) +#define GH3X2X_SLOT1_CTRL_9_REG_ADDR (0x0138) +#define GH3X2X_SLOT1_CTRL_10_REG_ADDR (0x013A) +#define GH3X2X_SLOT1_CTRL_11_REG_ADDR (0x013C) +#define GH3X2X_SLOT1_CTRL_12_REG_ADDR (0x013E) +#define GH3X2X_SLOT1_CTRL_13_REG_ADDR (0x0140) +#define GH3X2X_SLOT2_CTRL_0_REG_ADDR (0x0142) /**< slot 2 */ +#define GH3X2X_SLOT2_CTRL_1_REG_ADDR (0x0144) +#define GH3X2X_SLOT2_CTRL_2_REG_ADDR (0x0146) +#define GH3X2X_SLOT2_CTRL_3_REG_ADDR (0x0148) +#define GH3X2X_SLOT2_CTRL_4_REG_ADDR (0x014A) +#define GH3X2X_SLOT2_CTRL_5_REG_ADDR (0x014C) +#define GH3X2X_SLOT2_CTRL_6_REG_ADDR (0x014E) +#define GH3X2X_SLOT2_CTRL_7_REG_ADDR (0x0150) +#define GH3X2X_SLOT2_CTRL_8_REG_ADDR (0x0152) +#define GH3X2X_SLOT2_CTRL_9_REG_ADDR (0x0154) +#define GH3X2X_SLOT2_CTRL_10_REG_ADDR (0x0156) +#define GH3X2X_SLOT2_CTRL_11_REG_ADDR (0x0158) +#define GH3X2X_SLOT2_CTRL_12_REG_ADDR (0x015A) +#define GH3X2X_SLOT2_CTRL_13_REG_ADDR (0x015C) +#define GH3X2X_SLOT3_CTRL_0_REG_ADDR (0x015E) /**< slot 3 */ +#define GH3X2X_SLOT3_CTRL_1_REG_ADDR (0x0160) +#define GH3X2X_SLOT3_CTRL_2_REG_ADDR (0x0162) +#define GH3X2X_SLOT3_CTRL_3_REG_ADDR (0x0164) +#define GH3X2X_SLOT3_CTRL_4_REG_ADDR (0x0166) +#define GH3X2X_SLOT3_CTRL_5_REG_ADDR (0x0168) +#define GH3X2X_SLOT3_CTRL_6_REG_ADDR (0x016A) +#define GH3X2X_SLOT3_CTRL_7_REG_ADDR (0x016C) +#define GH3X2X_SLOT3_CTRL_8_REG_ADDR (0x016E) +#define GH3X2X_SLOT3_CTRL_9_REG_ADDR (0x0170) +#define GH3X2X_SLOT3_CTRL_10_REG_ADDR (0x0172) +#define GH3X2X_SLOT3_CTRL_11_REG_ADDR (0x0174) +#define GH3X2X_SLOT3_CTRL_12_REG_ADDR (0x0176) +#define GH3X2X_SLOT3_CTRL_13_REG_ADDR (0x0178) +#define GH3X2X_SLOT4_CTRL_0_REG_ADDR (0x017A) /**< slot 4 */ +#define GH3X2X_SLOT4_CTRL_1_REG_ADDR (0x017C) +#define GH3X2X_SLOT4_CTRL_2_REG_ADDR (0x017E) +#define GH3X2X_SLOT4_CTRL_3_REG_ADDR (0x0180) +#define GH3X2X_SLOT4_CTRL_4_REG_ADDR (0x0182) +#define GH3X2X_SLOT4_CTRL_5_REG_ADDR (0x0184) +#define GH3X2X_SLOT4_CTRL_6_REG_ADDR (0x0186) +#define GH3X2X_SLOT4_CTRL_7_REG_ADDR (0x0188) +#define GH3X2X_SLOT4_CTRL_8_REG_ADDR (0x018A) +#define GH3X2X_SLOT4_CTRL_9_REG_ADDR (0x018C) +#define GH3X2X_SLOT4_CTRL_10_REG_ADDR (0x018E) +#define GH3X2X_SLOT4_CTRL_11_REG_ADDR (0x0190) +#define GH3X2X_SLOT4_CTRL_12_REG_ADDR (0x0192) +#define GH3X2X_SLOT4_CTRL_13_REG_ADDR (0x0194) +#define GH3X2X_SLOT5_CTRL_0_REG_ADDR (0x0196) /**< slot 5 */ +#define GH3X2X_SLOT5_CTRL_1_REG_ADDR (0x0198) +#define GH3X2X_SLOT5_CTRL_2_REG_ADDR (0x019A) +#define GH3X2X_SLOT5_CTRL_3_REG_ADDR (0x019C) +#define GH3X2X_SLOT5_CTRL_4_REG_ADDR (0x019E) +#define GH3X2X_SLOT5_CTRL_5_REG_ADDR (0x01A0) +#define GH3X2X_SLOT5_CTRL_6_REG_ADDR (0x01A2) +#define GH3X2X_SLOT5_CTRL_7_REG_ADDR (0x01A4) +#define GH3X2X_SLOT5_CTRL_8_REG_ADDR (0x01A6) +#define GH3X2X_SLOT5_CTRL_9_REG_ADDR (0x01A8) +#define GH3X2X_SLOT5_CTRL_10_REG_ADDR (0x01AA) +#define GH3X2X_SLOT5_CTRL_11_REG_ADDR (0x01AC) +#define GH3X2X_SLOT5_CTRL_12_REG_ADDR (0x01AE) +#define GH3X2X_SLOT5_CTRL_13_REG_ADDR (0x01B0) +#define GH3X2X_SLOT6_CTRL_0_REG_ADDR (0x01B2) /**< slot 6 */ +#define GH3X2X_SLOT6_CTRL_1_REG_ADDR (0x01B4) +#define GH3X2X_SLOT6_CTRL_2_REG_ADDR (0x01B6) +#define GH3X2X_SLOT6_CTRL_3_REG_ADDR (0x01B8) +#define GH3X2X_SLOT6_CTRL_4_REG_ADDR (0x01BA) +#define GH3X2X_SLOT6_CTRL_5_REG_ADDR (0x01BC) +#define GH3X2X_SLOT6_CTRL_6_REG_ADDR (0x01BE) +#define GH3X2X_SLOT6_CTRL_7_REG_ADDR (0x01C0) +#define GH3X2X_SLOT6_CTRL_8_REG_ADDR (0x01C2) +#define GH3X2X_SLOT6_CTRL_9_REG_ADDR (0x01C4) +#define GH3X2X_SLOT6_CTRL_10_REG_ADDR (0x01C6) +#define GH3X2X_SLOT6_CTRL_11_REG_ADDR (0x01C8) +#define GH3X2X_SLOT6_CTRL_12_REG_ADDR (0x01CA) +#define GH3X2X_SLOT6_CTRL_13_REG_ADDR (0x01CC) +#define GH3X2X_SLOT7_CTRL_0_REG_ADDR (0x01CE) /**< slot 7 */ +#define GH3X2X_SLOT7_CTRL_1_REG_ADDR (0x01D0) +#define GH3X2X_SLOT7_CTRL_2_REG_ADDR (0x01D2) +#define GH3X2X_SLOT7_CTRL_3_REG_ADDR (0x01D4) +#define GH3X2X_SLOT7_CTRL_4_REG_ADDR (0x01D6) +#define GH3X2X_SLOT7_CTRL_5_REG_ADDR (0x01D8) +#define GH3X2X_SLOT7_CTRL_6_REG_ADDR (0x01DA) +#define GH3X2X_SLOT7_CTRL_7_REG_ADDR (0x01DC) +#define GH3X2X_SLOT7_CTRL_8_REG_ADDR (0x01DE) +#define GH3X2X_SLOT7_CTRL_9_REG_ADDR (0x01E0) +#define GH3X2X_SLOT7_CTRL_10_REG_ADDR (0x01E2) +#define GH3X2X_SLOT7_CTRL_11_REG_ADDR (0x01E4) +#define GH3X2X_SLOT7_CTRL_12_REG_ADDR (0x01E6) +#define GH3X2X_SLOT7_CTRL_13_REG_ADDR (0x01E8) +#define GH3X2X_ECG_CTRL_REG_ADDR (0x01EA) +#define GH3X2X_RG_SLOT_TMR0_REG_ADDR (0x01EC) +#define GH3X2X_RG_SLOT_TMR1_REG_ADDR (0x01EE) +#define GH3X2X_RG_SLOT_TMR2_REG_ADDR (0x01F0) +#define GH3X2X_RG_SLOT_TMR3_REG_ADDR (0x01F2) +#define GH3X2X_RG_SLOT_TMR4_REG_ADDR (0x01F4) +#define GH3X2X_RG_SLOT_TMR5_REG_ADDR (0x01F6) +#define GH3X2X_RG_SLOT_TMR6_REG_ADDR (0x01F8) +#define GH3X2X_RG_SLOT_TMR7_REG_ADDR (0x01FA) + +// afe_top block, start addr: 0x0200 +#define GH3X2X_AFE_REG0_REG_ADDR (0x0200) +#define GH3X2X_AFE_REG1_REG_ADDR (0x0202) +#define GH3X2X_AFE_REG2_REG_ADDR (0x0204) +#define GH3X2X_AFE_REG3_REG_ADDR (0x0206) +#define GH3X2X_AFE_REG4_REG_ADDR (0x0208) +#define GH3X2X_AFE_REG5_REG_ADDR (0x020A) +#define GH3X2X_AFE_REG6_REG_ADDR (0x020C) +#define GH3X2X_AFE_REG7_REG_ADDR (0x020E) +#define GH3X2X_AFE_REG8_REG_ADDR (0x0210) +#define GH3X2X_AFE_REG9_REG_ADDR (0x0212) +#define GH3X2X_AFE_REG10_REG_ADDR (0x0214) + +// led_agc block, start addr: 0x0280 +#define GH3X2X_LED_AGC_CTRL0_REG_ADDR (0x0280) +#define GH3X2X_LED_AGC_CTRL1_REG_ADDR (0x0282) +#define GH3X2X_LED_AGC_CTRL2_REG_ADDR (0x0284) +#define GH3X2X_LED_AGC_CTRL3_REG_ADDR (0x0286) +#define GH3X2X_LED_AGC_CTRL4_REG_ADDR (0x0288) +#define GH3X2X_LED_AGC_CTRL5_REG_ADDR (0x028A) +#define GH3X2X_LED_AGC_CTRL6_REG_ADDR (0x028C) +#define GH3X2X_LED_AGC_CTRL7_REG_ADDR (0x028E) +#define GH3X2X_LED_AGC_CTRL8_REG_ADDR (0x0290) +#define GH3X2X_LED_AGC_CTRL9_REG_ADDR (0x0292) + +// decimation block, start addr: 0x0300 +#define GH3X2X_DCMT_CTRL0_REG_ADDR (0x0300) +#define GH3X2X_DCMT_CTRL1_REG_ADDR (0x0302) +#define GH3X2X_DCMT_CTRL2_REG_ADDR (0x0304) +#define GH3X2X_DCMT_CTRL3_REG_ADDR (0x0306) +#define GH3X2X_DCMT_CTRL4_REG_ADDR (0x0308) +#define GH3X2X_DCMT_CTRL5_REG_ADDR (0x030A) +#define GH3X2X_DCMT_CTRL6_REG_ADDR (0x030C) +#define GH3X2X_DCMT_CTRL7_REG_ADDR (0x0310) +#define GH3X2X_DCMT_CTRL8_REG_ADDR (0x0312) + + +#define GH3X2X_DCMT_EN_LSB (0) +#define GH3X2X_DCMT_EN_MSB (7) +#define GH3X2X_DCMT_DNSAMPLE_DIS_LSB (8) +#define GH3X2X_DCMT_DNSAMPLE_DIS_MSB (15) +#define GH3X2X_DCMT_HEAD_LSB (0) +#define GH3X2X_DCMT_HEAD_MSB (4) +#define GH3X2X_DCMT_RND_SEL_LSB (8) +#define GH3X2X_DCMT_RND_SEL_MSB (9) + + +// spi_i2c block, start addr: 0x0380 +#define GH3X2X_SPI_CTRL0_REG_ADDR (0x0380) + +// adt block, start addr: 0x0400 +#define GH3X2X_ADT_LEADON_CR_REG_ADDR (0x0400) +#define GH3X2X_ADT_LEADON_TR_REG_ADDR (0x0402) +#define GH3X2X_ADT_LEADON_PR_REG_ADDR (0x0404) +#define GH3X2X_ADT_LEADON_PR1_REG_ADDR (0x0406) +#define GH3X2X_ADT_WEARON_CR_REG_ADDR (0x0408) +#define GH3X2X_ADT_WEARON1_THU_L_REG_ADDR (0x0410) +#define GH3X2X_ADT_WEARON1_THU_H_REG_ADDR (0x0412) +#define GH3X2X_ADT_WEARON1_THD_L_REG_ADDR (0x0414) +#define GH3X2X_ADT_WEARON1_THD_H_REG_ADDR (0x0416) +#define GH3X2X_ADT_WEARON2_THU_L_REG_ADDR (0x0418) +#define GH3X2X_ADT_WEARON2_THU_H_REG_ADDR (0x041A) +#define GH3X2X_ADT_WEARON2_THD_L_REG_ADDR (0x041C) +#define GH3X2X_ADT_WEARON2_THD_H_REG_ADDR (0x041E) +#define GH3X2X_ADT_LEADON_CR2_REG_ADDR (0x0420) +#define GH3X2X_ADT_WEARON_PR_REG_ADDR (0x0422) +#define GH3X2X_ADT_WEARON_CONFIRM_TIME_REG_ADDR (0x0424) +#define GH3X2X_ADT_WEARON_LOGIC_SEL_REG_ADDR (0x0426) +#define GH3X2X_ADT_WEAROFF_LOGIC_SEL_REG_ADDR (0x0428) +#define GH3X2X_ADT_LEADON_STR_REG_ADDR (0x042A) + +// ecg_recovery block, start addr: 0x0480 +#define GH3X2X_ECG_RECOVERY_CR_REG_ADDR (0x0480) +#define GH3X2X_ECG_RECOVERY_DMCR_REG_ADDR (0x0482) + +// int_ctrl block, start addr: 0x0500 +#define GH3X2X_INT_CR_REG_ADDR (0x0500) +#define GH3X2X_INT_CR2_REG_ADDR (0x0502) +#define GH3X2X_INT_PWR_REG_ADDR (0x0504) +#define GH3X2X_INT_CTR_REG_ADDR (0x0506) +#define GH3X2X_INT_STR_REG_ADDR (0x0508) +//#define GH3X2X_INT_FIFO_UR_REG_ADDR (0x050A) /**< fifo use cnt */ +#define GH3X2X_INT_STR2_REG_ADDR (0x050C) + +// osc_cal block, start addr: 0x0580 +#define GH3X2X_OSC_CR_REG_ADDR (0x0580) +#define GH3X2X_OSC_THR_REG_ADDR (0x0582) +#define GH3X2X_OSC13M_TUNE_REG_ADDR (0x0584) +#define GH3X2X_OSC32K_TUNE_REG_ADDR (0x0586) +#define GH3X2X_OSC32K_TEMP_REG_ADDR (0x0588) +#define GH3X2X_OSC_FREQ_ERR_UR_REG_ADDR (0x058A) +#define GH3X2X_OSC_FLAG_REG_ADDR (0x058C) + +// skin_color block, start addr: 0x0600 +#define GH3X2X_SKIN_BLR_REG_ADDR (0x0600) +#define GH3X2X_SKIN_BHR_REG_ADDR (0x0602) +#define GH3X2X_SKIN_YLR_REG_ADDR (0x0604) +#define GH3X2X_SKIN_YHR_REG_ADDR (0x0606) +#define GH3X2X_SKIN_FLR_REG_ADDR (0x0608) +#define GH3X2X_SKIN_FHR_REG_ADDR (0x060A) +#define GH3X2X_SKIN_CR_REG_ADDR (0x060C) +#define GH3X2X_SKIN_STR_REG_ADDR (0x060E) + +// sys_afe block, start addr: 0x0680 +#define GH3X2X_PPG_TIA_AD_REG_REG_ADDR (0x0680) +#define GH3X2X_PPG_DAC_AD_REG0_REG_ADDR (0x0682) +#define GH3X2X_PPG_DAC_AD_REG1_REG_ADDR (0x0684) +#define GH3X2X_PPG_DAC_AD_REG2_REG_ADDR (0x0686) +#define GH3X2X_PPG_DAC_AD_REG3_REG_ADDR (0x0688) +#define GH3X2X_PPG_ADC_AD_REG_REG_ADDR (0x0690) +#define GH3X2X_LED_DRV_AD_REG_REG_ADDR (0x0692) +#define GH3X2X_ECG_IA_AD_REG_REG_ADDR (0x0694) +#define GH3X2X_ECG_IA_AD_REG1_REG_ADDR (0x0696) +#define GH3X2X_ECG_IA_AD_REG2_REG_ADDR (0x0698) +#define GH3X2X_ECG_IA_AD_REG3_REG_ADDR (0x069A) +#define GH3X2X_ECG_IA_AD_REG4_REG_ADDR (0x069C) +#define GH3X2X_ECG_IA_AD_REG5_REG_ADDR (0x06A0) +#define GH3X2X_ECG_IA_AD_REG6_REG_ADDR (0x06A2) +#define GH3X2X_SYS_AFE_REG0_REG_ADDR (0x06B0) +#define GH3X2X_SYS_AD_REG_REG_ADDR (0x06B2) + +// efuse_ctrl block, start addr: 0x0700 +#define GH3X2X_EFUSE_CTRL_CMD_REG_ADDR (0x0700) +#define GH3X2X_EFUSE_CTRL_PASSWORD_REG_ADDR (0x0702) +#define GH3X2X_EFUSE_CTRL_TIMING_CFG_0_REG_ADDR (0x0704) +#define GH3X2X_EFUSE_CTRL_TIMING_CFG_1_REG_ADDR (0x0706) +#define GH3X2X_EFUSE_CTRL_WDATA_0_REG_ADDR (0x0708) +#define GH3X2X_EFUSE_CTRL_WDATA_1_REG_ADDR (0x070A) +#define GH3X2X_EFUSE_CTRL_WDATA_2_REG_ADDR (0x070C) +#define GH3X2X_EFUSE_CTRL_WDATA_3_REG_ADDR (0x070E) +#define GH3X2X_EFUSE_CTRL_RDATA_0_REG_ADDR (0x0710) +#define GH3X2X_EFUSE_CTRL_RDATA_1_REG_ADDR (0x0712) +#define GH3X2X_EFUSE_CTRL_RDATA_2_REG_ADDR (0x0714) +#define GH3X2X_EFUSE_CTRL_RDATA_3_REG_ADDR (0x0716) +#define GH3X2X_EFUSE_CTRL_STATUS_REG_ADDR (0x0718) +#define GH3X2X_EFUSE_CTRL_REG_MODE_REG_ADDR (0x071A) +#define GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_0_ADDR (0x071C) +#define GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_1_ADDR (0x071E) +#define GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_2_ADDR (0x0720) +#define GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_3_ADDR (0x0722) +#define GH3X2X_EFUSE_CTRL_EFUSE1_AUTOLOAD_0_ADDR (0x0724) +#define GH3X2X_EFUSE_CTRL_EFUSE1_AUTOLOAD_1_ADDR (0x0726) +#define GH3X2X_EFUSE_CTRL_EFUSE1_AUTOLOAD_2_ADDR (0x0728) +#define GH3X2X_EFUSE_CTRL_EFUSE1_AUTOLOAD_3_ADDR (0x072A) +#define GH3X2X_EFUSE_CTRL_EFUSE2_AUTOLOAD_0_ADDR (0x072C) +#define GH3X2X_EFUSE_CTRL_EFUSE2_AUTOLOAD_1_ADDR (0x072E) +#define GH3X2X_EFUSE_CTRL_EFUSE2_AUTOLOAD_2_ADDR (0x0730) +#define GH3X2X_EFUSE_CTRL_EFUSE2_AUTOLOAD_3_ADDR (0x0732) + +// special reg addr +#define GH3X2X_FIFO_REG_ADDR (0xAAAA) /**< fifo reg addr */ +#define GH3X2X_I2C_CMD_ADDR (0xDDDD) /**< i2c cmd reg addr */ + + +#define GH3X2X_REG_ADDR_SIZE (0x0002) /**< reg addr size */ +#define GH3X2X_REG_ADDR_EVEN_FIXED (0xFFFE) /**< reg addr even fixed */ +#define GH3X2X_REG_ADDR_MAX (0xFFFF) /**< reg addr max */ + +/* Register bit definition */ + +#define GH3X2X_CARDIFF_CTRL_START_BIT (0x0001u) /**< start bit msk */ + +#define GH3X2X_CHIP_ID_REG_VAL (0x0011) /**< chip id value */ +#define GH3X2X_PRODUCT_L_REG_VAL (0x0201) /**< product l value */ +#define GH3X2X_PRODUCT_H_REG_VAL (0x0301) /**< product l value */ +#define GH3X2X_CHIP_READY_REG_VAL (0xAA55) /**< chip ready value */ + +#define GH3X2X_INT_STR_MSK_ALL_BIT (0x7FFFu) /**< irq status mask */ +#define GH3X2X_INT_CTRL_MODE_MSK_BIT (0x0003u) /**< int ctrl mode bit msk */ + +#define GH3X2X_PMU_CTRL4_FIFO_DISABLE_MASK (0x0003u) /**< fifo module disable mask */ + +#define GH3X2X_INSTRUCTIONS_CHIP_INIED_REG_VAL (0x0011) /**< reg rg_chip_sw_backup bit4&bit0 set 1(0x0011) */ + +#define GH3X2X_SLOT_CTRL_OFFSET (0x001C) /**< slot ctrl reg offset */ + +#define GH3X2X_ADT_WEAR_STATUS_MASK_BIT (0x0010u) /**< wear status bit mask */ +#define GH3X2X_ADT_WEAR_DET_EN_MASK_BIT (0x0001u) /**< wear detect enable bit mask */ +#define GH3X2X_ADT_WEAR_CR_WEAR_ON_VAL (0x0A00u) /**< wear detect ctrl reg wear on val! cardful ! */ +#define GH3X2X_ADT_WEAR_CR_WEAR_OFF_VAL (0x0500u) /**< wear detect ctrl reg wear off val! cardful ! */ + +#define GH3X2X_SKIN_COLOR_STATUS_MASK_BIT (0x0003u) /**< skin color status bit mask */ + +#define GH3X2X_SLOT_LED_CURRENT_CLEAR_MASK (0x00FFu) /**< slot led current clear mask */ + +/* utils reg macro */ + +#define GH3X2X_SLOT_NUM_MAX (8) /**< slot num max */ + +#define GH3X2X_RX_NUM_MAX (4) + +#define GH3X2X_DECIMAION_CHNL_MAX (8) /** max channel number supported by decimaiton module in chip**/ + +#define GH3X2X_SLOT_LED_DRV_NUM_MAX (2) /**< slot led driver max */ + +#define GH3X2X_SLOT_TIA_GAIN_NUM_MAX (4) /**< slot tia gain num max */ + +#define GH3X2X_SLOT_TIA_GAIN_VAL_MAX (13) /**< slot tia gain val max */ + +#define GH3X2X_SLOT_TIA_GAIN_BITS_SIZE (4) /**< slot tia gain val bits size */ + +#define GH3X2X_SLOT_TIA_GAIN_BITS_MARK (0x000F) /**< slot tia gain val bits mark */ + +#define GH3X2X_SLOT_KDC_THR_VAL_MAX (8) /**< kdc thr val max */ + +#define GH3X2X_SLOT_KDC_THR_BITS_SIZE (4) /**< kdc thr bits size */ + +#define GH3X2X_SLOT_KDC_THR_BITS_MARK (0x0007) /**< kdc thr bits mark */ + +#define GH3X2X_SLOT_KDC_THR_ADC_INDEX_MAX (3) /**< kdc thr adc index max */ + + +/* reg bit field index */ + +#define GH3X2X_ECG_FAST_RECV_EN_LSB (10) /**< ecg fast recv en lsb @GH3X2X_ECG_CTRL_REG */ +#define GH3X2X_ECG_FAST_RECV_EN_MSB (10) /**< ecg fast recv en msb @GH3X2X_ECG_CTRL_REG */ + +#define GH3X2X_ECG_LEAD_DET_EN_LSB (0) /**< ecg lead det en lsb @GH3X2X_ADT_LEADON_CR_REG */ +#define GH3X2X_ECG_LEAD_DET_EN_MSB (0) /**< ecg lead det en msb @GH3X2X_ADT_LEADON_CR_REG */ + +#define GH3X2X_LEAD_ON_AUTO_SWITCH_LSB (8) /**< lead on auto switch lsb @GH3X2X_ECG_CTRL_REG */ +#define GH3X2X_LEAD_ON_AUTO_SWITCH_MSB (8) /**< lead on auto switch msb @GH3X2X_ECG_CTRL_REG */ + +#define GH3X2X_LEAD_OFF_AUTO_SWITCH_LSB (9) /**< lead off auto switch lsb @GH3X2X_ECG_CTRL_REG */ +#define GH3X2X_LEAD_OFF_AUTO_SWITCH_MSB (9) /**< lead off auto switch msb @GH3X2X_ECG_CTRL_REG */ + + +#define GH3X2X_WEAR_ON_EVENT_EN_LSB (10) /**< wear on event en lsb*/ +#define GH3X2X_WEAR_ON_EVENT_EN_MSB (10) /**< wear on event en msb*/ + +#define GH3X2X_WEAR_OFF_EVENT_EN_LSB (11) /**< wear off event en lsb*/ +#define GH3X2X_WEAR_OFF_EVENT_EN_MSB (11) /**< wear off event en msb*/ + + +#define GH3X2X_DRV0_FULL_SCAL_CURRENT_LSB (0) +#define GH3X2X_DRV0_FULL_SCAL_CURRENT_MSB (1) + +#define GH3X2X_DRV1_FULL_SCAL_CURRENT_LSB (4) +#define GH3X2X_DRV1_FULL_SCAL_CURRENT_MSB (5) + + +#define GH3X2X_SLOT_AGC_EN_LSB (8) +#define GH3X2X_SLOT_AGC_EN_MSB (9) + +#define GH3X2X_SLOT_BG_LEVEL_LSB (4) +#define GH3X2X_SLOT_BG_LEVEL_MSB (5) + +#define GH3X2X_SLOT_BG_CANCEL_LSB (10) +#define GH3X2X_SLOT_BG_CANCEL_MSB (10) + +#define GH3X2X_SLOT_ADC_INT_TIME_LSB (0) +#define GH3X2X_SLOT_ADC_INT_TIME_MSB (3) + +#define GH3X2X_SLOT_SR_LSB (8) +#define GH3X2X_SLOT_SR_MSB (15) + + + + + + +#endif /* _GH3X2X_DRV_REGISTERS_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_version.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_version.h new file mode 100644 index 000000000..a62d0adb0 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/inc/gh_drv_version.h @@ -0,0 +1,291 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_version.h + * + * @brief gh3x2x driver version and change log + * + * @par history: + * @verbatim + * Date Author Version Notes + * 2019-10-21 Chris-Chan v0.0.1.0 1.First version + * 2019-11-04 Chris-Chan v0.0.1.1 1.Change name to GH31XX + * 2019-12-17 Chris-Chan v0.0.1.2 1.Fix some bugs + * 2019-12-25 Chris-Chan v0.0.1.3 1.Add hook function + * 2019-12-31 Chris-Chan v0.0.1.4 1.Add hb algorithm support, but use roma ii algorithm now + * 2020-01-19 Chris-Chan v0.0.1.5 1.Add inited confirm support + * 2.Add some control api + * 2020-02-12 Chris-Chan v0.0.1.6 1.Add debug log support + * 2.Add some control api and some easy to debug + * 2020-02-17 Chris-Chan v0.0.1.7 1.Add some control api + * 2020-02-28 Chris-Chan v0.0.1.8 1.Add some control api + * 2020-03-06 Chris-Chan v0.0.1.9 1.Add universal protocol + * 2020-03-20 Chris-Chan v0.0.2.0 1.Add more cmd handler + * 2.Add all header files & move some code to *.h from common.h + * 3.Change to new algorithm api + * 2020-03-27 Chris-Chan v0.0.2.1 1.Fix cryp header that distinguish data is encrypted or not + * 2.Add some control api + * 3.Add virtual regs control + * 2020-04-03 Chris-Chan v0.1.0.0 1.Add send pkg api with universal protocol + * 2.Add Soft Adjust api + * 2020-04-07 Chris-Chan v0.1.0.1 1.Fix algorithm calc hook call, need prevent buffer reverse modification! + * 2.Fix unpack rawdata api, when using 1slot1adc unpack bug + * 2020-04-08 Chris-Chan v0.1.0.2 1.Change name to GH3X2X + * 2020-04-17 Chris-Chan v0.1.1.0 1.Add incomplete rawdata support + * 2.Change spo2 channel map handle + * 2020-04-24 Chris-Chan v0.1.2.0 1.Add dump rawdata support + * 2.Add wait pulse mode off code when exit low power mode, but disable now + * 3.Add verify for encrypt input, input buffer must has magic bytes + * 4.Fix protocol cmd handle and add some cmd + * 2020-04-30 Chris-Chan v0.1.3.0 1.Add lead handle support + * 2020-05-09 Chris-Chan v0.1.4.0 1.Add macro ctrl channel cnt + * 2020-05-09 Chris-Chan v0.1.4.1 1.Fix some bugs + * 2020-05-12 Chris-Chan v0.1.4.2 1.Fix some code style + * 2020-05-13 Chris-Chan v0.1.4.3 1.Fix slot unpack bug + * 2.Fix wear detect switch + * 2020-05-18 Chris-Chan v0.1.4.4 1.Fix all function deinit by add api + * 2020-05-26 Chris-Chan v0.1.4.5 1.Change don't send cmd @ start sampling + * 2020-07-21 wangtao v0.1.4.6 1.Add AGC code + * 2.Fix some bugs + * 2020-08-05 wangtao v0.1.5.0 1.add zip code + * 2.add code for single driver + * 2020-08-18 wangtao v0.1.6.0 1.add communicate test code + * 2.change some macro default value + * 2020-08-20 wangtao v0.1.6.1 1.fix bug of GH3X2X_Spo2AlgorithmStop,which lost call stop sampling + * 2020-08-20 wangtao v0.1.6.2 1.fix bug when confirm connect status + * 2020-08-20 wanpeng v0.1.6.3 1.add Itype 0nA code + * 2020-08-20 zhengxiaoyu v0.1.6.4 1.add app interface of zip function + * 2020-08-30 wangtao v0.1.6.5 1.change method of upload flag data + * 2.fix bug of zip interface when pack g sensor data + * 2020-08-30 wangtao v0.1.6.6 1.fix bug of tag value of flag data + * 2020-08-30 wangtao v0.1.6.7 1.change method of upload algorithm result,need upload every algorithm result + * 2.change format of algorithm result and related interfaces + ************************************************************************************ + * 2020-09-10 wangtao v1.0.0.0 1.update new algorithm lib of ECG HR and SPO2 + * 2020-09-10 wangtao v1.0.0.1 1.open spo2 and ecg + * 2020-09-19 zhengxiaoyu v1.0.0.2 1.change channel map virtual reg addr + * 2020-09-21 wangtao v1.0.1.0 1.add soft wear on/off function & alg + * 2020-09-21 wangtao v1.0.2.0 1.add movement detection by gsensor + * 2020-09-21 wangtao v1.1.0.0 1.config algorithm memory by user,delete code about algorithm memory + * 2020-09-27 wangtao v1.1.1.0 1.fix bug of soft ADT,which will overstep the boundary of array + * 2020-09-29 wangtao v1.1.2.0 1.fix bug of memory init + * 2020-09-29 wangtao v1.1.3.0 1.update new algorithm + * 2020-09-29 zhengxiaoyu v1.1.3.1 1.update function frequency reg virtual receive and analysis + * 2020-09-29 wanpeng v1.1.3.2 1.fix softwearoff bug that g_nPpgIdx bigger than 99 + * 2020-09-29 wanpeng v1.1.3.3 1.change logic soft adt + * 2020-10-13 wangtao v1.1.4.0 1.fix bug of soft adt + * 2020-10-14 wangtao v1.1.4.1 1.fix some code style + * 2.change some threshold of soft adt + * 2020-10-15 wangtao v1.1.4.2 1.cancel restrict of adt enable + * 2.fix hb algorithm bug + * 2020-10-15 wangtao v1.1.5.0 1.fix bug of soft adt + * 2020-10-22 wangtao v1.1.6.0 1.add HRV algorithm + * 2020-10-26 zhengxiaoyu v1.1.6.1 1.fix protocol bug + * 2020-10-22 wangtao v1.1.7.0 1.add new algo lib + * 2.fix bug of acc data dislocation when channel map cnt is larger than 8 + * 2020-11-03 zhengxiaoyu v1.1.7.1 1.Add spo2 Correction Factor input + * 2020-11-03 zhengxiaoyu v1.1.7.2 1.Fix HRV error result bug + * 2020-11-05 zengjiemin v1.1.8.0 1.Add Android Compile + * 2020-11-05 wanpeng v1.1.8.1 1.In ECG 5nA mode, reset ecg module when stop ecg sample + * 2020-11-11 zhengxiaoyu v1.1.9.0 1.Add Algo Channel map + * 2020-11-11 zhengxiaoyu v1.1.9.1 1.Add Algo Version print + * 2020-11-17 zhengxiaoyu v1.1.9.2 1.Fix Ecg 0nA mode lead bug + * 2020-11-17 zhengxiaoyu v1.3.0.0 1.Fix Ecg 0nA mode lead bug + * 2020-11-17 zhengxiaoyu v1.3.0.1 1.Fix Gsnesor Bug + * 2020-11-17 qiuchuitong v1.3.0.2 1.Fix Ecg Rowdata to algorithm bug + * 2020-12-16 wanpeng v1.3.0.2 save code and disable ecg and dump mode /change spo2 hr result struct + * 2020-12-22 wanpeng v1.3.0.3 add engineering mode sample interface + * 2020-12-24 wanpeng v1.3.0.4 add chip reset recovery code + ************************************************************************************ + * 2021-01-07 wanpeng v3.0.0.0 modify compile script and start new drvlib + * 2021-01-08 wanpeng v3.0.0.1 add frame process code and start function code + * 2021-01-11 wanpeng v3.0.0.2 add some code in ecg.c/config.c + * 2021-01-12 wanpeng v3.0.0.8 1.add some code about soft agc + * 2.remove code in control_ex.c + * 3.add some code in config.c + * 4.add 2nd level algo api + * 5.use frameinfo pointer array instead of pointers + * 6.add algo init and deinit api + * 2021-01-13 wanpeng v3.0.1.1 1.free alo protect arr in alo call api + * 2.set last gain + * 3.add rawdata buffer feature value calculate and check + * 2021-01-14 wanpeng v3.0.1.4 1.send flag msg to alg + * 2.send flag msg to alg从 + * 3.fix algo call and agc lib + * 2021-01-15 wanpeng v3.0.1.5 add upload function + * 2021-01-19 qiuchuitong v3.0.1.8 1.modify algo call lib + * 2.fix ecg bug + * 3.fix ecg func return bug + * 2021-01-20 qiuchuitong v3.0.1.9 upload algo result + * 2021-01-21 qiuchuitong v3.0.2.2 1.fix data pkg bug + * 2.fix hrv channel map config bug + * 3.fix soft adt bug + * 2021-01-22 wanpeng v3.0.2.3 separate fucntion GetFrameNum + * 2021-01-29 qiuchuitong v3.0.2.6 1.fix ECG bug + * 2.add app work mode + * 3.modify algo result hook func + * 2021-01-29 zhengxiaoyu v3.0.2.8 1.Update Zip Protocol + * 2.Fix spo2 Alg bug + * 2021-02-02 zhengxiaoyu v3.0.3.1 1.Update zip Protocol + * 2.Fix ECG Flag2 bugs + * 3.Fix Spo2 Rawdata bug + * 2021-02-02 zhengxiaoyu v3.0.3.3 1.Update code format + * 2.Update softwear wear on detect + * 2021-02-08 zhengxiaoyu v3.0.3.5 1.Update Zip protocol + * 2.Change ResultHook to ResultReport + * 2021-02-09 zhengxiaoyu v3.0.3.6 1.Fix Zip Protocol bug + * 2021-02-09 zhengxiaoyu v3.0.3.8 1.Fix Engineering Mode mode + * 2.Fix Decode reg bug & add HRV function Decode + * 2021-02-25 zhengxiaoyu v3.0.4.2 1.Fix Build bug when close goodix alg + * 2.Add 0x0b new rawdata protocol + * 3.Add protocol version + * 4.Add Amb section in new rawdata protocol + * 2021-03-09 qiuchuitong v3.0.5.0 1.Update soft adt algo lib + * 2.add lead off detect 2 for 800Hz sample rate + * 2021-03-09 zhengxiaoyu v3.0.6.0 1.Add AF/HSM/RESP/BT lib + * 2.Update code struct + * 2021-03-09 zhengxiaoyu v3.0.6.2 1.Update HSM/AF lib + * 2.Update HSM/AF API + * 2021-03-10 zhengxiaoyu v3.0.6.5 1.Update HSM/AF function lib + * 2.Update HSM result protocol + * 3.Update code structure + * 2021-03-11 qiuchuitong v3.0.6.6 1.Update HR/SPO2/ECG/ ALGO lib + * 2.add virtual reg for spo2 and soft adt + * 2021-03-12 zhengxiaoyu v3.0.6.7 1.Update HSM Report Send + * 2021-03-12 qiuchuitong v3.0.6.8 1.Add bootloader version function + * 2021-03-12 qiuchuitong v3.0.6.9 1.fix spo2 corret factor bug + * 2021-03-17 qiuchuitong v3.0.7.1 1.Update HSM ALGO lib + * 2.fix warnings + * 2021-03-19 qiuchuitong v3.0.7.3 1.Update HR ALGO lib + * 2.modify spo2 default factor + * 2021-03-19 qiuchuitong v3.0.7.4 1.Update af ALGO lib + * 2021-03-22 qiuchuitong v3.0.7.5 1.Update af,HSM,RESP ALGO lib + * 2021-03-22 zhengxiaoyu v3.0.7.9 1.Update HSM lib + * 2.Update float cal + * 3.Add FPBP/PWA functions + * 2021-03-23 qiuchuitong v3.0.8.0 1.fix spo2 upload results bug + * 2021-03-23 qiuchuitong v3.0.8.1 1.fix ECG results bug + * 2021-03-24 wanpeng v3.0.8.2 1.fix movement detect bug + 2.add multi chnl memsize maroc(HR and SPO2) + * 2021-03-30 zhengxiaoyu v3.0.8.6 1.Change function id to u32 + * 2.Add init/deinit/update error check + * 3.Add test1/2 functions + * 4.Add virtual-reg setting + * 2021-03-30 zhengxiaoyu v3.0.8.8 1.Fix RESP gain flag bug + * 2.Add write reg check + * 2021-04-01 zhengxiaoyu v3.0.9.1 1.Fix PWA chnl map bug + * 2.Add Hr result get + * 3.Fix gain-get bug + * 4.Add Android define + * 2021-04-01 zhengxiaoyu v3.0.9.2 1.Fix PT mode ADT bug + * 2021-04-06 zhengxiaoyu v3.0.9.3 1.Update hr result input hrv/hsm + * 2021-04-16 zhengxiaoyu v3.0.9.6 1.Fix control bug + * 2021-04-17 zhengxiaoyu v3.0.9.8 1.Update softadt alg + * 2.Fix bug & Update struct + * 2021-04-19 zhengxiaoyu v3.0.9.9 1.Fix bug + * 2021-04-20 wanpeng v3.1.0.0 1.Fix agc bug + * 2021-05-11 zhengxiaoyu v3.2.0.0 1.Update FPBP Alg & VirtualReg & something else + * 2021-05-11 zhengxiaoyu v3.2.0.1 1.Update Algo Version Update + * 2021-05-15 zhengxiaoyu v3.2.0.2 1.Add FPBP Algo chnl init + * 2021-05-17 zhengxiaoyu v3.2.0.3 1.Fix FPBP bug + * 2021-05-17 zhengxiaoyu v3.2.0.4 1.Update FPBP Input&Output API + * 2021-05-18 zhengxiaoyu v3.2.0.5 1.Fix some FPBP bug + * 2021-05-19 zhengxiaoyu v3.2.0.6 1.Add FPBP error code update + * 2021-05-20 zhengxiaoyu v3.2.0.7 1.Add FPBP result pressure data + * 2021-05-20 zhengxiaoyu v3.2.0.8 1.Add update FPBP pressure parameters setting + * 2021-05-24 zhengxiaoyu v3.2.1.0 1.Add eeprom handle + * 2.Fix zip protocol bug + * 2021-05-25 zhengxiaoyu v3.2.1.1 1.Change rawdata a0/a1 read + * 2021-05-26 zhengxiaoyu v3.2.1.2 1.Update FPBP hook logic + * 2021-05-27 zhengxiaoyu v3.2.1.4 1.Update FPBP pressure parameters setting + * 2.Add PWA program & Alglib + * 2021-05-28 zhengxiaoyu v3.2.1.5 1.Fix decode cfg list bug + * 2021-05-31 zhengxiaoyu v3.2.1.6 1.Add PWA algo function + * 2021-06-01 zhengxiaoyu v3.2.1.7 1.Add SoftAdt IR function + * 2021-06-01 zhengxiaoyu v3.2.1.8 1.Add function freauency control api + * 2021-06-02 zhengxiaoyu v3.2.1.9 1.Fix virtual alg chnl map bug + * 2021-06-03 zhengxiaoyu v3.2.2.0 1.Update PWA new program + * 2021-06-04 zhengxiaoyu v3.2.2.1 1.Update some algo weak api + * 2021-06-08 zhengxiaoyu v3.2.2.2 1.Add function led current + * 2021-06-08 wanpeng v3.2.2.4 1.add hardware spi + * 2.add sample rate modify function + * 2021-06-19 qiuchuitong v3.2.2.5 1.add ecg 800Hz to 250Hz resample code + * 2.add Gs gyro code + * 3.disable rx2 and rx3 for 3026 + * 2021-06-21 zhengxiaoyu v3.2.2.6 1.Fix fifo send progress bug + * 2021-06-22 zhengxiaoyu v3.2.2.7 1.Fix zip protocol & fifo send bug + * 2021-06-22 zhengxiaoyu v3.2.2.8 1.Update hrv input struct + * 2021-06-24 zhengxiaoyu v3.2.2.9 1.Add function infomation send protocol + * 2021-06-25 zhengxiaoyu v3.2.3.0 1.Add config protect handle + * 2021-06-29 qiuchuitong v3.2.3.1 1.divide ecg lead off det and resample + * 2021-06-29 qiuchuitong v3.2.3.2 1.fix check chip Model bug + * 2021-06-29 qiuchuitong v3.2.3.3 1.fix ecg resample bug + * 2021-06-29 zhengxiaoyu v3.2.3.4 1.fix spo2 algo channel bug + * 2021-07-16 zhengxiaoyu v3.2.3.5 1.update zip protocol + * 2021-07-21 zhengxiaoyu v3.2.3.7 1.update hr&spo2 api&struct + * 2021-07-21 zhengxiaoyu v3.2.3.8 1.update hr&spo2 memory + * 2021-07-21 qiuchuitong v3.2.3.9 1. add bt version code + * 2021-07-21 qiuchuitong v3.2.4.0 1. update nadt + * 2021-08-12 zhengxiaoyu v3.2.4.1 1.update bp and other + * 2021-08-12 zhengxiaoyu v3.2.4.7 1.update algo lib + * 2021-08-12 qiuchuitong v3.2.4.8 1.update bt algo lib + * 2021-12-16 zhengxiaoyu v3.2.4.9 1.update hr/spo2/ecg/nadt algo lib + * 2021-12-16 zhengxiaoyu v3.2.5.0 1.interrupt mode change func + * 2.result select and protocol update + * 3.change some code format + * 4.add Gh3x2xDemoStartSamplingWithCfgSwitch api + * 5.fix some note error + * 2021-12-16 zhengxiaoyu v3.2.5.1 1.fix hrv algo hr result bug + * 2.add check start sample func if exist in config + * 2022-01-13 zhengxiaoyu v3.2.5.2 1.rewrite nadt application process + * 2.fix some bug + * 2022-01-13 zhengxiaoyu v3.2.5.3 1.update log define + * 2.fix some bug + ************************************************************************************ + * 2022-02-11 zhengxiaoyu v4.0.0.0 1.delete all algo related section + * 2.fix some format bug + * 3.add some hook function + * 2022-02-11 zhengxiaoyu v4.0.0.1 1.change some funcs addr + * 2022-02-16 zhengxiaoyu v4.0.0.2 1.update format + * 2022-03-24 zhengxiaoyu v4.0.0.5 1.fix build bug + * 2.add gain read when disable agc func + * 2022-03-29 qiuchuitong v4.0.0.6 1.fix mp mode bug + * 2022-03-29 qiuchuitong v4.0.0.7 1.update bt algo + * 2022-03-29 qiuchuitong v4.0.0.8 1.update algo call code + * 2.add datatrans code + * 2022-04-13 zhengxiaoyu v4.0.0.9 1.update nadt process code + * 2022-04-13 zhengxiaoyu v4.0.1.0 1.add agcinfo reset + * 2.add ecode current set + * 2022-05-19 zhengxiaoyu v4.0.1.1 1.delete some code + * 2.update soft event + * 2023-04-06 wenyongfeng v4.1.0.1 1.fix bug + * + * 2023-04-25 wenyongfeng v4.1.0.2 1.add drv calculate bt + * + * 2023-05-16 wenyongfeng v4.2.0.0 1.open source + * + * 2024-01-05 wenyongfeng v4.2.0.1 1.fix compilation issue + * @endverbatim */ + +#ifndef _GH3X2X_DRV_VERSION_H_ +#define _GH3X2X_DRV_VERSION_H_ + + +#define GH3X2X_DRV_MAJOR_VERSION_NUMBER 4 /**< major version number */ +#define GH3X2X_DRV_MINOR_VERSION_NUMBER 2 /**< minor version number */ +#define GH3X2X_DRV_REVISION_VERSION_NUMBER 0 /**< revision version number */ +#define GH3X2X_DRV_FIXED_VERSION_NUMBER 1 /**< fixed version number */ + +#define GH3X2X_TO_STRING(x) #x /**< number to char */ +#define GH3X2X_STR(x) GH3X2X_TO_STRING(x) /**< number to char */ + +/// makeup version string +#define GH3X2X_VERSION_STRING "v"GH3X2X_STR(GH3X2X_DRV_MAJOR_VERSION_NUMBER)\ + "."GH3X2X_STR(GH3X2X_DRV_MINOR_VERSION_NUMBER)\ + "."GH3X2X_STR(GH3X2X_DRV_REVISION_VERSION_NUMBER)\ + "."GH3X2X_STR(GH3X2X_DRV_FIXED_VERSION_NUMBER)\ + " (build:"__DATE__"_"__TIME__")" + +#endif /* _GH3X2X_DRV_VERSION_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_config.c new file mode 100644 index 000000000..96b8ec201 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_config.c @@ -0,0 +1,880 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_control_ex.c + * + * @brief gh3x2x extension control functions, using function map like evk + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" +#include "gh_uprotocol.h" +#include "gh_agc.h" +#include "gh_drv_dump.h" +#include "gh_drv_config.h" +#include "gh_ecg.h" +#include "gh_demo_config.h" + + + +typedef struct +{ + GU8 usCurrentConfigFlag; +#if 0 + GU16 usInfoConfigArrVer; /// info: reg config array version + GU16 usInfoConfigToolVer; /// info: reg config create tool version + GU16 usInfoProjectId; /// info: project id + GU32 unInfoCreatedTimestamp; /// info: reg config created timestamp +#endif + GU32 unGhFuncSupportedAtCurCfg; //function combination supported by current config +}STGhDrvConfigManger; + +STGhDrvConfigManger g_stGhDrvConfigManger; +/// function started bitmap, use for sampling control +GU32 g_unFuncStartedBitmap = 0; + + + + +void GhDrvConfigManagerInit(void) +{ + GH3X2X_Memset((void *)(&g_stGhDrvConfigManger), 0, sizeof(g_stGhDrvConfigManger)); +} + +GU32 GhDrvConfigManagerGetCurFunctionSupprort(void) +{ + return g_stGhDrvConfigManger.unGhFuncSupportedAtCurCfg; +} + + + + + + +GS32 g_nAdtWearonThrd = 0; +extern GU8 g_uchFifoPackageMode; +extern GU8 g_uchGsensorEnable; +/// Cap enable flag +extern GU8 g_uchCapEnable; + +/// Temp enable flag +extern GU8 g_uchTempEnable; + + +GCHAR *GH3X2X_GetVirtualRegVersion(void) +{ + return (GCHAR *)GH3X2X_VIRTUAL_REG_VERSION_STRING; +} + + + +void GH3X2X_InitSensorParameters(void) +{ + g_uchGsensorEnable = 0; + g_uchCapEnable = 0; + g_uchTempEnable = 0; +} + + +/// if support algorithm run simultaneously +//GU8 g_uchAlgoRunMode = GH3X2X_ALGORITHM_RUN_ALONE; + + + +/// @brief get function id via virtual register +/// @param usVirRegAddr virtual register addr +/// @param usVirRegData virtual register value +/// @return fucntion ID , such as: GH3X2X_FUNCTION_ADT +GU32 GhGetFunctionIdViaVirReg(GU16 usVirRegAddr, GU16 usVirRegData) +{ + GU32 unTempFunctionId = 0; + if(usVirRegAddr >= GH3X2X_REG_IS_VIRTUAL0X2_BIT && usVirRegAddr < 0x2880) + { + if(0 == ((usVirRegAddr - GH3X2X_REG_IS_VIRTUAL0X2_BIT)%GH3X2X_CHNLMAP_OFFSET)) //addr = 0x2000,0x2022,0x2044... + { + if(usVirRegData) + { + unTempFunctionId = ((GU32)1 << ((usVirRegAddr - GH3X2X_REG_IS_VIRTUAL0X2_BIT)/GH3X2X_CHNLMAP_OFFSET)); + GH3X2X_DEBUG_LOG_PARAM("[GhGetFunctionIdViaVirReg]:Got valid function, ID = 0x%X\r\n", unTempFunctionId); + } + } + } + return unTempFunctionId; +} +/** + * @fn GS8 GH3X2X_DecodeRegCfgArr(GU32* punRunMode, const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen) + * + * @brief Analyze reg cfg array to get the run mode. + * + * @attention None + * + * @param[in] pstRegConfigArr pointer to reg config array + * @param[in] usRegConfigLen reg config array length + * @param[out] punRunMode pointer to run mode contained in reg config array + * + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return parameter error + */ +GS8 GH3X2X_DecodeRegCfgArr(GU32* punRunMode, const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen) +{ + GS8 chRet = GH3X2X_RET_OK; + + *punRunMode = GH3X2X_NO_FUNCTION; + //polling every regs in reg cfg array to get functions + if ((GH3X2X_PTR_NULL != punRunMode) && (GH3X2X_PTR_NULL != pstRegConfigArr) && (0 != usRegConfigLen)) + { + for (GU16 usArrCnt = 0; usArrCnt < usRegConfigLen ; usArrCnt ++) + { + *punRunMode |= GhGetFunctionIdViaVirReg(pstRegConfigArr[usArrCnt].usRegAddr, pstRegConfigArr[usArrCnt].usRegData); + } + } + else + { + chRet = GH3X2X_RET_PARAMETER_ERROR; + } + return chRet; +} + +/** + * @fn GU16 GH3X2X_ReadSwConfigWithVirtualReg(GU16 usVirtualRegAddr) + * + * @brief Read software config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[out] None + * + * @return virtual reg val + */ +GU16 GH3X2X_ReadSwConfigWithVirtualReg(GU16 usVirtualRegAddr) +{ + GU16 usVirtualRegData = 0; +#if 0 + GU16 usValIndex = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (usVirtualRegAddr < GH3X2X_VINFO_END_REG_ADDR) // config arr info + { + switch (usVirtualRegAddr) + { + case GH3X2X_VINFO_CFG_VER_REG_ADDR: + usVirtualRegData = g_stGhDrvConfigManger.usInfoConfigArrVer; + break; + case GH3X2X_VINFO_TOOL_VER_REG_ADDR: + usVirtualRegData = g_stGhDrvConfigManger.usInfoConfigToolVer; + break; + case GH3X2X_VINFO_PROJ_ID_REG_ADDR: + usVirtualRegData = g_stGhDrvConfigManger.usInfoProjectId; + break; + case GH3X2X_VINFO_TIMSTAMP_L_REG_ADDR: + usVirtualRegData = GH3X2X_GET_LOW_WORD_FROM_DWORD(g_stGhDrvConfigManger.unInfoCreatedTimestamp); + break; + case GH3X2X_VINFO_TIMSTAMP_H_REG_ADDR: + usVirtualRegData = GH3X2X_GET_HIGH_WORD_FROM_DWORD(g_stGhDrvConfigManger.unInfoCreatedTimestamp); + break; + default: // do nothing + break; + } + } // end of if (usVirtualRegAddr < GH3X2X_VINFO_END_REG_ADDR) + else if (usVirtualRegAddr < GH3X2X_VCHM_END_REG_ADDR) // config channel map + { + if (usVirtualRegAddr < GH3X2X_VCHM_HBA_CH_END_REG_ADDR) // hba + { + switch (usVirtualRegAddr) + { + case GH3X2X_VCHM_HBA_CNT_REG_ADDR: + usVirtualRegData = g_uchHbaChannelMapCnt; + break; + default: + usValIndex = (GU16)(usVirtualRegAddr - GH3X2X_VCHM_HBA_CH0_1_REG_ADDR); + if (usValIndex < GH3X2X_HBA_CHANNEL_MAP_MAX_CNT) + { + usVirtualRegData = GH3X2X_MAKEUP_WORD(g_uchHbaChannelMapArr[usValIndex + 1], \ + g_uchHbaChannelMapArr[usValIndex]); + } + break; + } + } + else if (usVirtualRegAddr < GH3X2X_VCHM_SPO2_CH_END_REG_ADDR) // spo2 + { + switch (usVirtualRegAddr) + { + case GH3X2X_VCHM_SPO2_CNT_REG_ADDR: + usVirtualRegData = g_uchSpo2ChannelMapCnt; + break; + default: + usValIndex = (GU16)(usVirtualRegAddr - GH3X2X_VCHM_SPO2_CH0_1_REG_ADDR); + if (usValIndex < GH3X2X_SPO2_CHANNEL_MAP_MAX_CNT) + { + usVirtualRegData = GH3X2X_MAKEUP_WORD(g_uchSpo2ChannelMapArr[usValIndex + 1], \ + g_uchSpo2ChannelMapArr[usValIndex]); + } + break; + } + } + else + { + switch (usVirtualRegAddr) + { + case GH3X2X_VCHM_ECG_CH0_REG_ADDR: + usVirtualRegData = g_uchEcgChannelMap; + break; + case GH3X2X_VCHM_ADT_CNT_REG_ADDR: + usVirtualRegData = g_uchAdtChannelMapCnt; + break; + case GH3X2X_VCHM_ADT_CH0_1_REG_ADDR: + usVirtualRegData = GH3X2X_MAKEUP_WORD(g_uchAdtChannelMapArr[1], g_uchAdtChannelMapArr[0]); + break; + case GH3X2X_VCHM_ADT_CH2_3_REG_ADDR: + usVirtualRegData = GH3X2X_MAKEUP_WORD(g_uchAdtChannelMapArr[3], g_uchAdtChannelMapArr[2]); + break; + default: // do nothing + break; + } // end of switch (usVirtualRegAddr) + } + } // end of else if (usVirtualRegAddr < GH3X2X_VCHM_END_REG_ADDR) + else if (usVirtualRegAddr < GH3X2X_VDUMP_END_REG_ADDR) // dump module + { + switch (usVirtualRegAddr) + { + case GH3X2X_VDUMP_DUMP_MODE_REG_ADDR: + break; + case GH3X2X_VDUMP_BG_LEVEL_REG_ADDR: + break; + default: // do nothing + break; + } + } + else if (usVirtualRegAddr < GH3X2X_VECG_END_REG_ADDR) // ecg module + { + switch (usVirtualRegAddr) + { + case GH3X2X_VECG_0_REG_ADDR: + case GH3X2X_VECG_1_REG_ADDR: + case GH3X2X_VECG_2_REG_ADDR: + usValIndex = (usVirtualRegAddr - GH3X2X_VECG_0_REG_ADDR) / GH3X2X_REG_ADDR_SIZE; + break; + default: // do nothing + break; + } + } // end of else if (usVirtualRegAddr < GH3X2X_VECG_END_REG_ADDR) + else if (usVirtualRegAddr < GH3X2X_VAGC_END_REG_ADDR) // agc config + { + switch (usVirtualRegAddr) + { + case GH3X2X_VAGC_AGC_BG_SLOT_ENABLE_REG_ADDR: + break; + case GH3X2X_VAGC_AMB_SLOT_CTRL_REG_ADDR: + break; + case GH3X2X_VAGC_RES_REG_ADDR: + break; + default: // do nothing + break; + } + } // end of else if (usVirtualRegAddr < GH3X2X_VAGC_END_REG_ADDR) +#endif + return usVirtualRegData; +} + +void GH3X2X_WriteFsConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GU8 uchFuncOffsetIndex = (usVirtualRegAddr - GH3X2X_ADT_FS_ADDR) / 2; + if(g_pstGh3x2xFrameInfo[uchFuncOffsetIndex] != 0) + { + g_pstGh3x2xFrameInfo[uchFuncOffsetIndex] ->pstFunctionInfo ->usSampleRate = GH3X2X_GET_LOW_WORD_FROM_DWORD(usVirtualRegValue); + } +} + + + +void GH3X2X_WriteChnlMapConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GU16 usValIndex = 0; + usVirtualRegAddr = GH3X2X_GET_REG_REAL_ADRR(usVirtualRegAddr); + switch (usVirtualRegAddr % GH3X2X_CHNLMAP_OFFSET) + { + case 0: + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[usVirtualRegAddr / GH3X2X_CHNLMAP_OFFSET],GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue)); + break; + default: + usValIndex = (GU16)((usVirtualRegAddr % GH3X2X_CHNLMAP_OFFSET) - 2); + if (usValIndex < GH3X2X_CHANNEL_MAP_MAX_CH) + { + GH3x2xSetFunctionChnlMap(g_pstGh3x2xFrameInfo[usVirtualRegAddr / GH3X2X_CHNLMAP_OFFSET],usValIndex + 1,GH3X2X_GET_HIGH_BYTE_FROM_WORD(usVirtualRegValue)); + GH3x2xSetFunctionChnlMap(g_pstGh3x2xFrameInfo[usVirtualRegAddr / GH3X2X_CHNLMAP_OFFSET],usValIndex,GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue)); + } + break; + } +} + +#if __SUPPORT_SOFT_AGC_CONFIG__ +void GH3X2X_WriteAgcConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GU16 usValIndex; + switch (usVirtualRegAddr) + { + case GH3X2X_AGC_BG_CANCEL_ADJUST_SLOT_EN_ADDR: + case GH3X2X_AGC_AMB_SLOT_CTRL_ADDR: + case GH3X2X_AGC_CONFIG_RES: + case GH3X2X_AGC_GAIN_LIMIT_ADDR: + case GH3X2X_AGC_TRIG_THD_H_LSB_16_ADDR: + case GH3X2X_AGC_TRIG_THD_H_MSB_16_ADDR: + case GH3X2X_AGC_TRIG_THD_L_LSB_16_ADDR: + case GH3X2X_AGC_TRIG_THD_L_MSB_16_ADDR: + case GH3X2X_AGC_RESTRAIN_THD_H_LSB_16_ADDR: + case GH3X2X_AGC_RESTRAIN_THD_H_MSB_16_ADDR: + case GH3X2X_AGC_RESTRAIN_THD_L_LSB_16_ADDR: + case GH3X2X_AGC_RESTRAIN_THD_L_MSB_16_ADDR: + usValIndex = (usVirtualRegAddr - GH3X2X_AGC_BG_CANCEL_ADJUST_SLOT_EN_ADDR) / GH3X2X_REG_ADDR_SIZE; + GH3X2X_LedAgcPramWrite(usVirtualRegValue, usValIndex); + break; + default: // do nothing + break; + } +} +#endif + + +#if 1 + + +void GhConfigSwModuleConfigInfoParmSet(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + switch (usVirtualRegAddr) + { +#if 0 //wanpeng this info is not using, delet them to save code + case GH3X2X_CFG_VER_ADDR: + g_stGhDrvConfigManger.usInfoConfigArrVer = usVirtualRegValue; + break; + case GH3X2X_CFG_TOOL_VER_ADDR: + g_stGhDrvConfigManger.usInfoConfigToolVer = usVirtualRegValue; + break; + case GH3X2X_PROJECT_ID_ADDR: + g_stGhDrvConfigManger.usInfoProjectId = usVirtualRegValue; + break; + case GH3X2X_TIMESTAMP_L_ADDR: + g_stGhDrvConfigManger.unInfoCreatedTimestamp = GH3X2X_MAKEUP_DWORD2(GH3X2X_GET_HIGH_WORD_FROM_DWORD(g_stGhDrvConfigManger.unInfoCreatedTimestamp), + usVirtualRegValue); + break; + case GH3X2X_TIMESTAMP_H_ADDR: + g_stGhDrvConfigManger.unInfoCreatedTimestamp = GH3X2X_MAKEUP_DWORD2(usVirtualRegValue, + GH3X2X_GET_LOW_WORD_FROM_DWORD(g_stGhDrvConfigManger.unInfoCreatedTimestamp)); + break; +#endif + case GH3X2X_REINIT_PARAM_ADDR: + GH3X2X_ReinitAllSwModuleParam(usVirtualRegValue); + break; + default: // do nothing + break; + } +} + +void GhConfigSwModuleDumpInit(void) +{ + GH3X2X_DumpModeSet(0); +} + +void GhConfigSwModuleDumpParmSet(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + switch (usVirtualRegAddr) + { + case GH3X2X_PPG_DUMP_MODE_ADDR: + GH3X2X_DumpModeSet(usVirtualRegValue); + break; + case GH3X2X_BG_LEVEL_SET_ADDR: + //GH3X2X_BgLevelSet(usVirtualRegValue); + break; + default: // do nothing + break; + } +} + +void GhConfigSwModuleFifoInfoParmSet(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + switch (usVirtualRegAddr) + { + case GH3X2X_FIFO_PACKAGE_SEND_MODE_ADDR: + g_uchFifoPackageMode = usVirtualRegValue; + break; + default: // do nothing + break; + } +} + + + +void GhConfigSwModuleGsParmSet(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + switch (usVirtualRegAddr) + { + case GH3X2X_GSENSOR_CTRL_ADDR: + g_uchGsensorEnable = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + break; + default: // do nothing + break; + } +} + + + + +#if __CAP_ENABLE__ +void GhConfigSwModuleCapParmSet(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + switch (usVirtualRegAddr) + { + case GH3X2X_CAP_CTRL_ADDR: + g_uchCapEnable = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + break; + default: // do nothing + break; + } +} +#endif + +#if __TEMP_ENABLE__ +void GhConfigSwModuleTempParmSet(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + switch (usVirtualRegAddr) + { + case GH3X2X_TEMP_CTRL_ADDR: + g_uchTempEnable = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + break; + default: // do nothing + break; + } +} +#endif + + + + +const STGhVirRegSwModuleInfo g_stGhVirRegSwModuleInfo[] = +{ + /** usAddrStart usAddrEnd ParmSet *****/ + /*config info*/ {GH3X2X_TOP_INFO_ADDR, GH3X2X_TOP_INFO_ADDR_END, GhConfigSwModuleConfigInfoParmSet}, + /*dump*/ {GH3X2X_DUMP_CFG_ADDR, GH3X2X_DUMP_CFG_ADDR_END, GhConfigSwModuleDumpParmSet}, + /*fifo info*/ {GH3X2X_FIFO_CTRL_ADDR, GH3X2X_FIFO_CTRL_ADDR_END, GhConfigSwModuleFifoInfoParmSet}, + /*gsensor*/ {GH3X2X_G_SENSOR_CFG_ADDR, GH3X2X_G_SENSOR_CFG_ADDR_END, GhConfigSwModuleGsParmSet}, +#if __SUPPORT_SOFT_AGC_CONFIG__ + /*agc*/ {GH3X2X_SOFT_AGC_PARA_ADDR, GH3X2X_SOFT_AGC_PARA_ADDR_END, GH3X2X_WriteAgcConfigWithVirtualReg}, +#endif +#if __CAP_ENABLE__ + /*cap*/ {GH3X2X_CAP_CFG_ADDR, GH3X2X_CAP_CFG_ADDR_END, GhConfigSwModuleCapParmSet}, +#endif +#if __TEMP_ENABLE__ + /*temp*/ {GH3X2X_TEMP_CFG_ADDR, GH3X2X_TEMP_CFG_ADDR_END, GhConfigSwModuleTempParmSet}, +#endif + /*ChnlMap*/ {GH3X2X_CHNL_MAP_ADDR, GH3X2X_CHNL_MAP_ADDR_END, GH3X2X_WriteChnlMapConfigWithVirtualReg}, + /*Fs*/ {GH3X2X_FS_PARA_ADDR, GH3X2X_FS_PARA_ADDR_END, GH3X2X_WriteFsConfigWithVirtualReg}, +}; + + + + +void GH3X2X_WriteSwConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + for(GU8 ubModuleCnt = 0; ubModuleCnt < sizeof(g_stGhVirRegSwModuleInfo)/sizeof(STGhVirRegSwModuleInfo); ubModuleCnt ++) + { + if((usVirtualRegAddr >= g_stGhVirRegSwModuleInfo[ubModuleCnt].usAddrStart)&&(usVirtualRegAddr < g_stGhVirRegSwModuleInfo[ubModuleCnt].usAddrEnd)) + { + if(g_stGhVirRegSwModuleInfo[ubModuleCnt].ParmSet) + { + g_stGhVirRegSwModuleInfo[ubModuleCnt].ParmSet(usVirtualRegAddr, usVirtualRegValue); + } + } + } +} + +#else + +/** + * @fn GS8 GH3X2X_WriteSwConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) + * + * @brief Write software param config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[in] usVirtualRegValue virtual reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteSwConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + if (usVirtualRegAddr < GH3X2X_SLOT_LEDDRV_ADDR) // config arr info 0x1F + { + switch (usVirtualRegAddr) + { + #if 0 + case GH3X2X_CFG_VER_ADDR: + g_stGhDrvConfigManger.usInfoConfigArrVer = usVirtualRegValue; + break; + case GH3X2X_CFG_TOOL_VER_ADDR: + g_stGhDrvConfigManger.usInfoConfigToolVer = usVirtualRegValue; + break; + case GH3X2X_PROJECT_ID_ADDR: + g_stGhDrvConfigManger.usInfoProjectId = usVirtualRegValue; + break; + case GH3X2X_TIMESTAMP_L_ADDR: + g_stGhDrvConfigManger.unInfoCreatedTimestamp = GH3X2X_MAKEUP_DWORD2(GH3X2X_GET_HIGH_WORD_FROM_DWORD(g_stGhDrvConfigManger.unInfoCreatedTimestamp), + usVirtualRegValue); + break; + case GH3X2X_TIMESTAMP_H_ADDR: + g_stGhDrvConfigManger.unInfoCreatedTimestamp = GH3X2X_MAKEUP_DWORD2(usVirtualRegValue, + GH3X2X_GET_LOW_WORD_FROM_DWORD(g_stGhDrvConfigManger.unInfoCreatedTimestamp)); + break; + #endif + case GH3X2X_REINIT_PARAM_ADDR: + GH3X2X_ReinitAllSwModuleParam(usVirtualRegValue); + break; + default: // do nothing + break; + } + } // end of if (usVirtualRegAddr < GH3X2X_VINFO_END_REG_ADDR) + else if (usVirtualRegAddr < GH3X2X_DUMP_CFG_ADDR) // slot drv map module + { + //TO BE DONE + } + else if (usVirtualRegAddr < GH3X2X_FIFO_CTRL_ADDR) // dump module + { + switch (usVirtualRegAddr) + { + case GH3X2X_PPG_DUMP_MODE_ADDR: + GH3X2X_DumpModeSet(usVirtualRegValue); + break; + case GH3X2X_BG_LEVEL_SET_ADDR: + //GH3X2X_BgLevelSet(usVirtualRegValue); + break; + default: // do nothing + break; + } + } // end of else if (usVirtualRegAddr < GH3X2X_VDUMP_END_REG_ADDR) + else if (usVirtualRegAddr < GH3X2X_G_SENSOR_CFG_ADDR) // fifo info + { + switch (usVirtualRegAddr) + { + case GH3X2X_FIFO_PACKAGE_SEND_MODE_ADDR: + g_uchFifoPackageMode = usVirtualRegValue; + break; + default: // do nothing + break; + } + } + else if (usVirtualRegAddr < GH3X2X_SOFT_AGC_PARA_ADDR) + { + switch (usVirtualRegAddr) + { + case GH3X2X_GSENSOR_CTRL_ADDR: + g_uchGsensorEnable = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + break; + default: // do nothing + break; + } + } // end of else if (usVirtualRegAddr < GH3X2X_VGS_END_REG_ADDR) + else if (usVirtualRegAddr < GH3X2X_CAP_CFG_ADDR) // agc config + { + #if __SUPPORT_SOFT_AGC_CONFIG__ + GH3X2X_WriteAgcConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + #endif + + } // end of else if (usVirtualRegAddr < GH3X2X_VAGC_END_REG_ADDR) + else if (usVirtualRegAddr < GH3X2X_TEMP_CFG_ADDR) + { + switch (usVirtualRegAddr) + { + case GH3X2X_CAP_CTRL_ADDR: + g_uchCapEnable = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + break; + default: // do nothing + break; + } + } + else if (usVirtualRegAddr < GH3X2X_CHNL_MAP_ADDR) + { + switch (usVirtualRegAddr) + { + case GH3X2X_TEMP_CTRL_ADDR: + g_uchTempEnable = GH3X2X_GET_LOW_BYTE_FROM_WORD(usVirtualRegValue); + break; + default: // do nothing + break; + } + } + else if (usVirtualRegAddr < GH3X2X_FS_PARA_ADDR) + { + GH3X2X_WriteChnlMapConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + } + else if (usVirtualRegAddr < GH3X2X_REG_IS_VIRTUAL0X3_BIT) + { + GH3X2X_WriteFsConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + } +} + +#endif + +#if __FUNC_TYPE_ECG_ENABLE__ +void GH3X2X_WriteEcgDrvConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GU16 usValIndex; + switch (usVirtualRegAddr) + { + case GH3X2X_ECG_SETTING0_ADDR: + case GH3X2X_ECG_SETTING1_ADDR: + case GH3X2X_ECG_SETTING2_ADDR: + usValIndex = (usVirtualRegAddr - GH3X2X_ECG_SETTING0_ADDR) / GH3X2X_REG_ADDR_SIZE; + GH3X2X_SlaverSoftLeadPramSet(usVirtualRegValue, usValIndex); + break; + case GH3X2X_ECG_SETTING3_ADDR: + GH3x2xSetEcgOutputFs(usVirtualRegValue); + break; + default: // do nothing + break; + } +} +#endif + + +void GH3X2X_WriteDrvConfigWithVirtualReg(GU32 unFunctionID, GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + switch (unFunctionID) + { + case GH3X2X_FUNC_OFFSET_ADT: + #if __FUNC_TYPE_ECG_ENABLE__ //only for ADT by using ecg-electronic + GH3X2X_WriteAdtDrvConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + #endif + break; + case GH3X2X_FUNC_OFFSET_ECG: + #if __FUNC_TYPE_ECG_ENABLE__ + GH3X2X_WriteEcgDrvConfigWithVirtualReg(usVirtualRegAddr, usVirtualRegValue); + #endif + break; + default: + break; + } +} + +/** + * @fn GS8 GH3X2X_WriteAlgorithmConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) + * + * @brief Write algorithm param config with virtual reg + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[in] usVirtualRegValue virtual reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteFunctionConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GU32 unFunctionID = (usVirtualRegAddr - GH3X2X_REG_IS_VIRTUAL0X3_BIT) / GH3X2X_VREG_FUNCTION_OFFSET; + if (usVirtualRegAddr >= GH3X2X_ADT_DRV_CFG_ADDR + GH3X2X_VREG_FUNCTION_OFFSET * unFunctionID &&\ + usVirtualRegAddr < GH3X2X_ADT_ALG_CFG_ADDR + GH3X2X_VREG_FUNCTION_OFFSET * unFunctionID) + { + GH3X2X_WriteDrvConfigWithVirtualReg(unFunctionID, usVirtualRegAddr, usVirtualRegValue); + } + else if (usVirtualRegAddr >= GH3X2X_ADT_ALG_CFG_ADDR + GH3X2X_VREG_FUNCTION_OFFSET * unFunctionID &&\ + usVirtualRegAddr < GH3X2X_ADT_DRV_CFG_ADDR + GH3X2X_VREG_FUNCTION_OFFSET * (unFunctionID + 1)) + { + /* call hook */ + HOOK_FUNC_CALL(g_pGh3x2xWriteAlgConfigWithVirtualRegHookFunc, (usVirtualRegAddr, usVirtualRegValue) ); + } +} + + + +/** + * @fn GS8 GH3X2X_WriteVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) + * + * @brief Write virtual reg val, for software param config + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[in] usVirtualRegValue virtual reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + if (usVirtualRegAddr < GH3X2X_REG_IS_VIRTUAL0X3_BIT) + { + if (usVirtualRegAddr > GH3X2X_TOP_INFO_ADDR && 0 == g_stGhDrvConfigManger.usCurrentConfigFlag) + { + GH3X2X_DEBUG_LOG_PARAM("[%s]:Config version error!!!\r\n", __FUNCTION__); + } + else + { + GH3X2X_SW_CONFIG_WRITE(usVirtualRegAddr, usVirtualRegValue); + } + } + else if (usVirtualRegAddr < GH3X2X_FINISH_FLAG_ADDR) + { + GH3X2X_FUNCTION_CONFIG_WRITE(usVirtualRegAddr, usVirtualRegValue); + } + + switch (usVirtualRegAddr) + { + case GH3X2X_END_FLAG_ADDR: // virtual reg write finish + if (g_stGhDrvConfigManger.usCurrentConfigFlag == 1) + { + g_stGhDrvConfigManger.usCurrentConfigFlag = 0; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("[%s]:Config version error!!!\r\n", __FUNCTION__); + } + GH3X2X_DEBUG_LOG_PARAM("[GH3X2X_WriteVirtualReg]: unGhFuncSupportedAtCurCfg = 0x%X.\r\n", g_stGhDrvConfigManger.unGhFuncSupportedAtCurCfg); + HOOK_FUNC_CALL(g_pGh3x2xConfigSetStopHookFunc, ()); + break; + case GH3X2X_TOP_INFO_ADDR: + GhDrvConfigManagerInit(); + HOOK_FUNC_CALL(g_pGh3x2xConfigSetStartHookFunc, ()); + g_stGhDrvConfigManger.usCurrentConfigFlag = 1; + GH3X2X_InitSensorParameters(); + GH3X2X_SetConfigFuncMode(0); + break; + default: + break; + } + g_stGhDrvConfigManger.unGhFuncSupportedAtCurCfg |= GhGetFunctionIdViaVirReg(usVirtualRegAddr, usVirtualRegValue); +} + +/** + * @fn GU16 GH3X2X_ReadVirtualReg(GU16 usVirtualRegAddr) + * + * @brief Read virtual reg val, for software param config + * + * @attention Virtual reg addr has del control bits, so reg addr is [0:11] valid. + * + * @param[in] usVirtualRegAddr virtual reg addr + * @param[out] None + * + * @return virtual reg val + */ +GU16 GH3X2X_ReadVirtualReg(GU16 usVirtualRegAddr) +{ + GU16 usVirtualRegData = 0; +#if GH3X2X_SUPPORT_READ_BACK_VIRTUAL_REG + +#endif + return usVirtualRegData; +} + +void GH3X2X_CheckChipModel(void) +{ + GU16 usRegVal = 0; + usRegVal = GH3X2X_ReadReg(GH3X2X_EFUSE_CTRL_EFUSE1_AUTOLOAD_0_ADDR); + //if chip is 3026,disable rx2 and rx3 + if(((usRegVal >> 5)&0x07) == 1) + { + for(GU8 uchSlotNo = 0; uchSlotNo < 8; uchSlotNo++) + { + GH3X2X_WriteRegBitField(GH3X2X_SLOT0_CTRL_0_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotNo,4,5, 0); + } + } +} + +/** + * @fn GS8 GH3X2X_LoadNewRegConfigArr(const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen) + * + * @brief Load new gh3x2x reg config array + * + * @attention If reg val don't need verify, should set reg addr bit 12; + * If reg is virtual reg, should set reg addr bit 13; + * e.g. need config reg 0x0000: 0x0611 + * {0x0000, 0x0611} //verify write by read reg + * {0x1000, 0x0611} //don't need verify write val + * {0x2000, 0x0611} //set virtual reg + * + * @param[in] pstRegConfigArr pointer to the reg struct array + * @param[in] usRegConfigLen reg struct array length + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_COMM_ERROR gh3x2x communicate error + */ +GS8 GH3X2X_LoadNewRegConfigArr(const STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen , GU8 uchChipIndex) +{ + GS8 chRet = GH3X2X_RET_OK; + GU16 usIndex = 0; + GU16 usReadRegVal = 0; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((pstRegConfigArr != GH3X2X_PTR_NULL) && (usRegConfigLen != 0)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + for (usIndex = 0; usIndex < usRegConfigLen; usIndex++) // write GH3X2X reg. + { + switch (GH3X2X_GET_BIT_IS_SET(pstRegConfigArr[usIndex].usRegAddr)) + { + case 0: + GH3X2X_WriteReg(pstRegConfigArr[usIndex].usRegAddr, pstRegConfigArr[usIndex].usRegData); + usReadRegVal = GH3X2X_ReadReg(pstRegConfigArr[usIndex].usRegAddr); + if (usReadRegVal != pstRegConfigArr[usIndex].usRegData) + { + GH3X2X_DEBUG_LOG_PARAM("[%s]:reg verify error! addr:0x%.4x,w_val:0x%.4x,r_val:0x%.4x\r\n", __FUNCTION__, + GH3X2X_GET_REG_REAL_ADRR(pstRegConfigArr[usIndex].usRegAddr), + pstRegConfigArr[usIndex].usRegData, usReadRegVal); + chRet = GH3X2X_RET_COMM_ERROR; + } + break; + default: + if(0 == uchChipIndex) + { + /* write & verify virtual reg, if verify error, only log error, shouldn't return error */ + GH3X2X_WriteVirtualReg(pstRegConfigArr[usIndex].usRegAddr, pstRegConfigArr[usIndex].usRegData); + } + #if 0 + usReadRegVal = GH3X2X_ReadVirtualReg(pstRegConfigArr[usIndex].usRegAddr); + if (usReadRegVal != pstRegConfigArr[usIndex].usRegData) + { + GH3X2X_DEBUG_LOG_PARAM("[%s]:vreg reg verify error! addr:0x%.4x,w_val:0x%.4x,r_val:0x%.4x\r\n", __FUNCTION__, + pstRegConfigArr[usIndex].usRegAddr, + pstRegConfigArr[usIndex].usRegData, usReadRegVal); + } + #endif + break; + } + } // end of for (usIndex = 0; usIndex < usRegConfigLen; usIndex++) + GH3X2X_WAIT_CHIP_DSLP(); + } // end of if ((pstRegConfigArr != GH3X2X_PTR_NULL) && (usRegConfigLen != 0)) + GH3X2X_CheckChipModel(); + return chRet; +} + + + + +void GH3X2X_SetCurrentConfigFlag(GU8 value) +{ + g_stGhDrvConfigManger.usCurrentConfigFlag = value; +} + + + + + + + + + + + + + + + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_control.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_control.c new file mode 100644 index 000000000..d76c7ceab --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_control.c @@ -0,0 +1,4314 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_control.c + * + * @brief gh3x2x control functions + * + * @version ref gh3x2x_drv_version.h + * + */ + +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" + +#include "gh_uprotocol.h" +#include "gh_ecg.h" +#include "gh_drv_dump.h" +#include "gh_agc.h" +#include "gh_drv_config.h" +#include "gh_zip.h" +#include "gh_demo.h" +#include "gh_demo_config.h" +#include "gh_demo_inner.h" +#include "gh_demo_version.h" +#include "gh_drv.h" +#include "gh_multi_sen_pro.h" +#include "gh_agc.h" + +GU8 g_uchFifoPackageID = 0xFF; +GU8 g_uchFifoPackageMode = 0; +//GU8 *gpuchSendFifoPackage = GH3X2X_PTR_NULL; +GU32 g_unSendFifoPackageCnt = 0; + +//function set in config +GU32 g_unConfigFuncMode = 0; + +GU8 g_uchAlgoEnableFlag = 1; + +GU8 g_uchSingleChipModeEnableFlag = 0; //1��spi/iic only operate one chip + +GU8 g_uchOddEvenChangeFlag = 1; + +/// soft event +GU32 g_unSoftEvent = 0; //G202008231001 wanpeng + +/// G sensor enable flag +GU8 g_uchGsensorEnable = 0; + +/// Cap enable flag +GU8 g_uchCapEnable = 0; + +/// Temp enable flag +GU8 g_uchTempEnable = 0; + +GU8 g_uchResetFromProtocolFlag = 0; + +/// gh3x2x status +GU8 g_uchGh3x2xStatus = GH3X2X_STATUS_NO_INIT; + +/// current fifo water line +GU16 g_usCurrentFiFoWaterLine = 0; + +/// init hook func ptr +pfnNormalHookFunc g_pGh3x2xInitHookFunc = GH3X2X_PTR_NULL; + +/// start hook func ptr +pfnNormalHookFunc g_pGh3x2xStartHookFunc = GH3X2X_PTR_NULL; + +/// stop hook func ptr +pfnNormalHookFunc g_pGh3x2xStopHookFunc = GH3X2X_PTR_NULL; + +/// get rawdata hook func ptr +pfnGetRawdataHookFunc g_pGh3x2xGetRawdataHookFunc = GH3X2X_PTR_NULL; + +/// get struct hook func ptr +pfnGetIoStructInfo g_pGh3x2xGetIoStructInfoHookFunc = GH3X2X_PTR_NULL; + +/// set algo config hook func ptr +pfnWriteAlgConfigWithVirtualReg g_pGh3x2xWriteAlgConfigWithVirtualRegHookFunc = GH3X2X_PTR_NULL; + +/// config start set hook func ptr +pfnNormalHookFunc g_pGh3x2xConfigSetStartHookFunc = GH3X2X_PTR_NULL; + +/// config stop set hook func ptr +pfnNormalHookFunc g_pGh3x2xConfigSetStopHookFunc = GH3X2X_PTR_NULL; + +/// start hook func ptr +pfnNormalHookFunc g_pGh3x2xResetByProtocolHookFunc = GH3X2X_PTR_NULL; + +/// read int pin status func ptr +pfnReadPinStatus g_pGh3x2xReadIntPinStatusFunc = GH3X2X_PTR_NULL; + +/// read reset pin status func ptr +pfnReadPinStatus g_pGh3x2xReadResetPinStatusFunc = GH3X2X_PTR_NULL; + +/// read spcs pin status func ptr +pfnReadPinStatus g_pGh3x2xReadSpcsPinStatusFunc = GH3X2X_PTR_NULL; + +/// read spdo pin status func ptr +pfnReadPinStatus g_pGh3x2xReadSpdoPinStatusFunc = GH3X2X_PTR_NULL; + +/// set reset pin level spi +pfnSetPinLevel g_pGh3x2xResetPinLevelControlFunc = GH3X2X_PTR_NULL; + +#if GH3X2X_PMU_FIFO_POWER_CTRL_ENABLED + +/// fifo power ctrl fifo control reg cache var +GU16 g_pusPmuFifoModuleCtrlVal[2] = {0x0000, 0x0000}; + +/// for fifo power ctrl cache status +GU8 g_puchPmuFifoModuleCtrlCacheStatus[2] = {0,0}; + +/// max rawdata num read from fifo every time +GU16 g_usMaxNumReadFromFifo = GH3X2X_FIFO_DATA_BYTES_MAX_LEN; + +#endif + + +GU8 g_uchActiveChipResetFlag = 0; //1: user have done chip reset(soft reset and hardwear reset) actively gh3x2x_init will clear it +GU8 g_uchChipResetRecoveringFlag = 0; //0: is not in chip reset recovering flag 1: is in chip reset recovering + +extern GU32 g_unFuncStartedBitmap; +extern GU8 g_uchGhx2xChipSleepFlag; +extern GU8 g_uchChipDivZeroFlag; +/** + * @fn void GH3X2X_RegisterHookFunc(void (*pInitHookFunc)(void), + * void (*pStartHookFunc)(void), + * void (*pStopHookFunc)(void), + * void (*pGetRawdataHookFunc)(GU8 *puchReadDataBuffer, GU16 usReadDataLen)) + * + * @brief Register hook function callback + * + * @attention None + * + * @param[in] pInitHookFunc pointer to init hook function + * @param[in] pStartHookFunc pointer to start hook function + * @param[in] pStopHookFunc pointer to stop hook function + * @param[in] pGetRawdataHookFunc pointer to get rawdata hook function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterHookFunc(void (*pInitHookFunc)(void), + void (*pStartHookFunc)(void), + void (*pStopHookFunc)(void), + void (*pGetRawdataHookFunc)(GU8 *puchReadDataBuffer, GU16 usReadDataLen), + void (*pGetIoStructInfoHookFunc)(const STGh3x2xFrameInfo * const pstFrameInfo), + void (*pResetByProtocolHookFunc)(void), + void (*pConfigSetStartHookFunc)(void), + void (*pConfigSetStopHookFunc)(void), + void (*pfnWriteAlgConfigWithVirtualReg)(GU16 usVirtualRegAddr, GU16 usVirtualRegValue)) +{ + g_pGh3x2xInitHookFunc = pInitHookFunc; + g_pGh3x2xStartHookFunc = pStartHookFunc; + g_pGh3x2xStopHookFunc = pStopHookFunc; + g_pGh3x2xGetRawdataHookFunc = pGetRawdataHookFunc; + g_pGh3x2xGetIoStructInfoHookFunc = pGetIoStructInfoHookFunc; + g_pGh3x2xResetByProtocolHookFunc = pResetByProtocolHookFunc; + g_pGh3x2xConfigSetStartHookFunc = pConfigSetStartHookFunc; + g_pGh3x2xConfigSetStopHookFunc = pConfigSetStopHookFunc; + g_pGh3x2xWriteAlgConfigWithVirtualRegHookFunc = pfnWriteAlgConfigWithVirtualReg; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); +} + +/** + * @fn GS8 GH3X2X_ExitLowPowerMode(void) + * + * @brief Exit lowpower mode, in this mode, can read&write reg with gh3x2x + * + * @attention Power consumption bigger than lowpower mode, detaile ref gh3x2x datasheet + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR exit low power mode error + */ +GS8 GH3X2X_ExitLowPowerMode(void) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GH3X2X_CHIP_WAKEUP(chRet); + return chRet; +} + +/** + * @fn GS8 GH3X2X_EnterLowPowerMode(void) + * + * @brief Enter lowpower mode, in this mode, can't read&write reg with gh3x2x. + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR enter low power mode error + */ +GS8 GH3X2X_EnterLowPowerMode(void) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GH3X2X_CHIP_SLEEP(chRet); + g_uchGhx2xChipSleepFlag |= (1 << g_uchGh3x2xChipOperateIndexRealtime); //set sleep flag + return chRet; +} + +/** + * @fn GS8 GH3X2X_SoftReset(void) + * + * @brief Gh3x2x softreset via i2c/spi, can read&write reg with gh3x2x after reset + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR exit low power mode error + */ +GS8 GH3X2X_SoftReset(void) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GH3X2X_CHIP_RESET(chRet); + if(0 == GH3X2X_GetSingleChipModeEnableFlag()) + { + GH3X2X_SoftResetSlaveChip(); + } + g_uchActiveChipResetFlag = 1; + if (g_uchResetFromProtocolFlag == 1) + { + g_uchResetFromProtocolFlag = 0; + HOOK_FUNC_CALL(g_pGh3x2xResetByProtocolHookFunc, () ); /* call hook */ + } + return chRet; +} + +#if !__GH3X2X_CASCADE_EN__ +void GH3X2X_SoftResetSlaveChip(void){} +#else +void GH3X2X_SoftResetSlaveChip(void) +{ + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_SEND_RESET_CMD(); + GH3X2X_CascadeOperationMasterChip(); +} +#endif + +#if defined(GH3X2X_LOG_DEBUG) && (GH3X2X_LOG_DEBUG > 0) // debug level > 0 +/** + * @fn void GH3X2X_LogConfigArr(STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen) + * + * @brief log gh3x2x reg config array + * + * @attention Only use for dbg version; + * + * @param[in] pstRegConfigArr pointer to the reg struct array + * @param[in] usRegConfigLen reg struct array length + * @param[out] None + * + * @return None + */ +void GH3X2X_LogConfigArr(STGh3x2xReg *pstRegConfigArr, GU16 usRegConfigLen) +{ + GU16 usIndex = 0; + GH3X2X_DEBUG_LOG_PARAM("Log reg config arr:\r\n"); + if ((pstRegConfigArr != GH3X2X_PTR_NULL) && (usRegConfigLen != 0)) + { + for (usIndex = 0; usIndex < usRegConfigLen; usIndex++) + { + GH3X2X_DEBUG_LOG_PARAM("addr:0x%.4x, val:0x%.4x\r\n", pstRegConfigArr[usIndex].usRegAddr, + pstRegConfigArr[usIndex].usRegData); + } + } +} +#endif + +/** + * @fn GS8 GH3X2X_DumpRegs(STGh3x2xReg *pstDumpRegsArr, GU16 usDumpRegsStartAddr, GU16 usDumpRegsLen) + * + * @brief Dump gh3x2x regs + * + * @attention usDumpRegsStartAddr only allow even address, if param set odd address val that val & 0xFFFE in api; + * If address greater than reg max addres 0xFFFE, it will return GH3X2X_RET_GENERIC_ERROR. + * + * @param[out] pstDumpRegsArr pointer to the dump reg struct output + * @param[in] usDumpRegsStartAddr dump reg address + * @param[in] usDumpRegsLen dump reg length + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR dump gh3x2x address out of bounds + */ +GS8 GH3X2X_DumpRegs(STGh3x2xReg *pstDumpRegsArr, GU16 usDumpRegsStartAddr, GU16 usDumpRegsLen) +{ + GS8 chRet = GH3X2X_RET_OK; + GU16 usIndex = 0; + GU16 usDumpRegsAddr = usDumpRegsStartAddr & GH3X2X_REG_ADDR_EVEN_FIXED; // just allow even addr val + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((pstDumpRegsArr != GH3X2X_PTR_NULL) && (usDumpRegsLen != 0)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + for (usIndex = 0; usIndex < usDumpRegsLen; usIndex++) // read GH3X2X reg. + { + pstDumpRegsArr[usIndex].usRegAddr = usDumpRegsAddr; + pstDumpRegsArr[usIndex].usRegData = GH3X2X_ReadReg(usDumpRegsAddr); + if (usDumpRegsAddr < GH3X2X_REG_ADDR_MAX) // last reg addr : 0xfffe + { + usDumpRegsAddr += GH3X2X_REG_ADDR_SIZE; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("Dump reg address out of bounds!\r\n"); + chRet = GH3X2X_RET_GENERIC_ERROR; + break; + } + } + GH3X2X_WAIT_CHIP_DSLP(); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_CommunicateConfirm(void) + * + * @brief Communication operation interface confirm + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_COMM_ERROR gh3x2x communicate error + */ +GS8 GH3X2X_CommunicateConfirm(void) +{ + GU8 uchIndex = GH3X2X_COMMUNICATE_CONFIRM_MAX_CNT; + GS8 chRet = GH3X2X_RET_COMM_ERROR; + GU16 uchReadData; + GU16 uchWriteData; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + do + { + GH3X2X_WAIT_CHIP_WAKEUP(); + if (GH3X2X_ReadReg(GH3X2X_CHIP_READY_CODE_REG_ADDR) == GH3X2X_CHIP_READY_REG_VAL) + { + uchReadData = GH3X2X_ReadReg(GH3X2X_RG_SLOT_TMR0_REG_ADDR); + GH3X2X_DEBUG_LOG_PARAM("slot_time0 reg = %d\r\n", (int)uchReadData); + uchWriteData = ~uchReadData; + GH3X2X_WriteReg(GH3X2X_RG_SLOT_TMR0_REG_ADDR, uchWriteData); + uchReadData = GH3X2X_ReadReg(GH3X2X_RG_SLOT_TMR0_REG_ADDR); + GH3X2X_DEBUG_LOG_PARAM("slot_time0 reg = %d\r\n", (int)uchReadData); + if (uchWriteData == uchReadData) + { + chRet = GH3X2X_RET_OK; + uchWriteData = ~uchReadData; + GH3X2X_WriteReg(GH3X2X_RG_SLOT_TMR0_REG_ADDR, uchWriteData); + break; + } + } + else + { + GH3X2X_DEBUG_LOG_PARAM("ready code reg is error !!! %s\r\n", __FUNCTION__); + } + uchIndex--; + } while (uchIndex > 0); + GH3X2X_WAIT_CHIP_DSLP(); + + return chRet; +} + + +extern GU8 g_uchEcgCascadeEn; +extern GU8 g_uchEcgCascadeWriteRegVerifyEn; +///0: not init 1: initialized +GU8 g_uchEcgCascadeSlaveInitSuccess; + +void Gh3x2x_CHECK_0x0088_Ex(void) +{ + GH3X2X_CHECK_0x0088(); +} + + + + + + + + + +#if !__GH3X2X_CASCADE_EN__ +void GH3X2X_LoadSlaveCfgForCascadeMode(void) +{} +#else +void GH3X2X_LoadSlaveCfgForCascadeMode(void) +{ + + GH3X2X_CascadeOperationSlaverChip(); + + /* clear int status. */ + GH3X2X_WAIT_CHIP_WAKEUP(); + GH3X2X_WriteReg(GH3X2X_INT_STR_REG_ADDR, GH3X2X_INT_STR_MSK_ALL_BIT); + GH3X2X_WAIT_CHIP_DSLP(); + if(GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_DEBUG_LOG_PARAM("Slaver is enable!\r\n"); + //g_uchEcgCascadeEn = 1; + g_uchEcgCascadeSlaveInitSuccess = 0; + //Write the others chip's reg + + // GU16 lusRegLen = sizeof(stGh3x2xEcgCascadeSlaveRealReglist) / sizeof(STGh3x2xReg); + GU16 lusRegLen = g_usEcgCascadeSlaveRealRegLen; + //GH3X2X_WAIT_CHIP_WAKEUP(); +#if 0 + GU16 usReadRegVal = 0; + for (GU16 lusIndex = 0; lusIndex < lusRegLen; lusIndex++) + { + GH3X2X_WriteReg(stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegAddr, + stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegData); + + /* need verify val. */ + if (g_uchEcgCascadeWriteRegVerifyEn) + { + usReadRegVal = GH3X2X_ReadReg(stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegAddr); + if (usReadRegVal != stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegData) + { + GH3X2X_DEBUG_LOG_PARAM("reg verify error! addr:0x%.4x,w_val:0x%.4x,r_val:0x%.4x\r\n", + stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegAddr, + stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegData, usReadRegVal); + //chRet = GH3X2X_RET_COMM_ERROR; + g_uchEcgCascadeSlaveInitSuccess = 0; + break; + } + } + else + { + GH3X2X_DEBUG_LOG_PARAM("reg don't verify! addr:0x%.4x,w_val:0x%.4x\r\n", + stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegAddr, + stGh3x2xEcgCascadeSlaveRealReglist[lusIndex].usRegData); + } + if ((lusRegLen -1) == lusIndex) + { + g_uchEcgCascadeSlaveInitSuccess = 1; + } + } +#else + if (GH3X2X_RET_OK == GH3X2X_LoadNewRegConfigArr(stGh3x2xEcgCascadeSlaveRealReglist, lusRegLen, 1)) + { + g_uchEcgCascadeSlaveInitSuccess = 1; + } + else + { + g_uchEcgCascadeSlaveInitSuccess = 0; + } +#endif + //GH3X2X_WAIT_CHIP_DSLP(); + + //modify ecg chnl map and chnl num + g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchChnlNum = 2; + if(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->uchFuntionChnlLimit > 1) + { + g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pchChnlMap[1] = 0x08; + } + } + GH3X2X_CascadeOperationMasterChip(); + +} +#endif + +void GH3X2X_SensorPramInit(void) +{ + g_uchGsensorEnable = 0; + g_uchCapEnable = 0; + g_uchTempEnable = 0; +} + +void GH3X2X_DrvControlInit(void) +{ + g_uchAlgoEnableFlag = 1; + g_unSoftEvent = 0; + g_unConfigFuncMode = 0; + g_unFuncStartedBitmap = 0; + g_uchGh3x2xStatus = GH3X2X_STATUS_NO_INIT; + g_uchSingleChipModeEnableFlag = 0; + g_uchActiveChipResetFlag = 0; + g_uchGhx2xChipSleepFlag = 0x03; + g_uchChipDivZeroFlag = 0; +} + +void GH3X2X_FifoControlInit(void) +{ + g_uchFifoPackageID = 0xFF; + g_uchFifoPackageMode = 0; + g_unSendFifoPackageCnt = 0; + g_usCurrentFiFoWaterLine = 0; +} + +void GH3X2X_ProtocolFlagInit(void) +{ + g_uchResetFromProtocolFlag = 0; +} + + +void GH3X2XDrvConfigInit(void) +{ + GH3X2X_ProtocolFlagInit(); + GH3X2X_FifoControlInit(); + #if __FUNC_TYPE_ECG_ENABLE__ + GH3X2X_AdtPramInit(); + #endif + GH3X2X_SensorPramInit(); + GH3X2X_DrvControlInit(); +} + +/** + * @fn GS8 GH3X2X_Init(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam) + * + * @brief Init gh3x2x with configure parameters + * + * @attention None + * + * @param[in] pstGh3x2xInitConfigParam pointer to gh3x2x init config param + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_COMM_ERROR gh3x2x communicate error + */ +GS8 GH3X2X_Init(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam) +{ + + GH3X2XDrvConfigInit(); + GH3X2X_DEBUG_LOG_PARAM("%s : Lib Version : %s\r\n", __FUNCTION__, GH3X2X_GetDriverLibVersion()); + if (GH3X2X_CommunicateConfirm() != GH3X2X_RET_OK) /* confirm GH3X2X communicate. */ + { + GH3X2X_DEBUG_LOG_PARAM("communicate confirm error!\r\n"); + return GH3X2X_RET_COMM_ERROR; + } + + /* clear int status. */ + GH3X2X_WAIT_CHIP_WAKEUP(); + GH3X2X_WriteReg(GH3X2X_INT_STR_REG_ADDR, GH3X2X_INT_STR_MSK_ALL_BIT); + GH3X2X_WAIT_CHIP_DSLP(); + + if (pstGh3x2xInitConfigParam != GH3X2X_PTR_NULL) + { + /* load config */ + if (GH3X2X_LoadNewRegConfigArr(pstGh3x2xInitConfigParam->pstRegConfigArr, + pstGh3x2xInitConfigParam->usConfigArrLen, 0) != GH3X2X_RET_OK) + { + return GH3X2X_RET_COMM_ERROR; + } + /* load slave chip config for cascade mode */ + if(0 == GH3X2X_GetSingleChipModeEnableFlag()) + { + GH3X2X_LoadSlaveCfgForCascadeMode(); + } + } + else + { + GH3X2X_DEBUG_LOG_PARAM("gh init param is null!\r\n"); + } + + GH3X2X_WriteReg(0x0700,0x0020); + GH3X2X_WriteReg(0x0700,0x0030); + while(!(GH3X2X_ReadReg(0x0718)&0x0001)); + GS8 err_code = (GS8)(GH3X2X_ReadReg(0x0712) & 0xFF); + GH3X2X_SetDrvEcode(err_code); + GH3X2X_SetConfigDrvEcode(pstGh3x2xInitConfigParam); + + /* @ fix chip error code below here. + * e.g. otp clk err + */ + + /* @end of fix chip error. */ + + /* call hook */ + GH3X2X_WAIT_CHIP_WAKEUP(); + HOOK_FUNC_CALL(g_pGh3x2xInitHookFunc, () ); + GH3X2X_WAIT_CHIP_DSLP(); + + /* set chip status inited. */ + GH3X2X_SET_CHIP_INIED(); + g_uchGh3x2xStatus = GH3X2X_STATUS_INITED; + return GH3X2X_RET_OK; +} + + +void GH3X2X_RecordAgcInfo(void) +{ + GU16 usDrv0CurRegData = 0; + GU16 usDrv0CurRegAddr = 0; + GU16 usDrv1CurRegData = 0; + GU16 usDrv1CurRegAddr = 0; + GU16 uchTIAData = 0; + + // record TIA + for (GU8 uchSlotIndex = 0; uchSlotIndex < 8; uchSlotIndex++) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + uchTIAData = GH3X2X_ReadReg(GH3X2X_SLOT0_CTRL_4_REG_ADDR + (uchSlotIndex * GH3X2X_SLOT_CTRL_OFFSET)); + GH3X2X_WAIT_CHIP_DSLP(); + + for (GU8 nAdcCnt = 0; nAdcCnt < 4; nAdcCnt++) + { + GU8 uchTempTIAData = (GU8)(((uchTIAData) >> (GH3X2X_SLOT_TIA_GAIN_BITS_SIZE * nAdcCnt)) & GH3X2X_SLOT_TIA_GAIN_BITS_MARK); + g_pstGh3x2xAgcInfo->uchTiaGainAfterSoftAgc[uchSlotIndex*4 + nAdcCnt] = uchTempTIAData; + } + } + + //Record Drv + GH3X2X_WAIT_CHIP_WAKEUP(); + usDrv0CurRegAddr = GH3X2X_SLOT0_CTRL_10_REG_ADDR; + usDrv1CurRegAddr = GH3X2X_SLOT0_CTRL_11_REG_ADDR; + for (GU8 uchSlotIndexCnt = 0; uchSlotIndexCnt < GH3X2X_MAX_SLOT_NUM; uchSlotIndexCnt++) + { + usDrv0CurRegData = (GH3X2X_ReadReg(usDrv0CurRegAddr + (uchSlotIndexCnt * GH3X2X_SLOT_CTRL_OFFSET)) & GH3X2X_DRV_CURRENT_BIT_MASK); + usDrv1CurRegData = (GH3X2X_ReadReg(usDrv1CurRegAddr + (uchSlotIndexCnt * GH3X2X_SLOT_CTRL_OFFSET)) & GH3X2X_DRV_CURRENT_BIT_MASK); + g_pstGh3x2xAgcInfo->uchDrvCurrentAfterSoftAgc[uchSlotIndexCnt] = (GU16)(usDrv0CurRegData << GH3X2X_DRV0_CURRENT_LEFT_SHIFT_BIT_NUM); + g_pstGh3x2xAgcInfo->uchDrvCurrentAfterSoftAgc[uchSlotIndexCnt] |= (GU16)(usDrv1CurRegData << GH3X2X_DRV1_CURRENT_LEFT_SHIFT_BIT_NUM); + } + GH3X2X_WAIT_CHIP_DSLP(); +} + +/** + * @fn GS8 GH3X2X_StartSampling(void) + * + * @brief Start gh3x2x sampling + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + * @retval #GH3X2X_RET_GENERIC_ERROR gh3x2x has started, need restart should call GH3X2X_StopSampling then start + */ +GS8 GH3X2X_StartSampling(void) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (g_uchGh3x2xStatus != GH3X2X_STATUS_STARTED) + { + g_uchFifoPackageID = 0xFF; + if (GH3X2X_IS_CHIP_INIED() && (g_uchGh3x2xStatus == GH3X2X_STATUS_INITED)) + { + GU16 usRegVal = 0; + GH3X2X_WAIT_CHIP_WAKEUP(); + g_usCurrentFiFoWaterLine = GH3X2X_ReadReg(GH3X2X_FIFO_WATERLINE_REG_ADDR); //record water line + usRegVal = GH3X2X_ReadReg(GH3X2X_CARDIFF_CTRL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, GH3X2X_SET_BIT(usRegVal, GH3X2X_CARDIFF_CTRL_START_BIT)); + #if GH3X2X_ALGORITHM_ECG_SUPPORT && __FUNC_TYPE_ECG_ENABLE__ + GH3X2X_LeadDetEnControl(ECG_SAMPLE_EVENT_INFO_SAMPLE_START); + #endif + + GH3X2X_RecordAgcInfo(); //record agc info + #if __SUPPORT_SOFT_AGC_CONFIG__ + GH3X2X_LedAgcInit(g_pstGh3x2xAgcInfo); + #endif + #if GH3X2X_DUMP_MODE_EN + GH3X2X_DumpInit(); + #endif + g_uchGh3x2xStatus = GH3X2X_STATUS_STARTED; + HOOK_FUNC_CALL(g_pGh3x2xStartHookFunc, () ); /* call hook */ + GH3X2X_WAIT_CHIP_DSLP(); // GH3X2X_SEND_DSLEEP_CMD(); // enter sleep mode in application code + GH3X2X_StartSamplingSlaveChip(); + chRet = GH3X2X_RET_OK; + } + else + { + g_uchGh3x2xStatus = GH3X2X_STATUS_NO_INIT; + chRet = GH3X2X_RET_NO_INITED_ERROR; + GH3X2X_DEBUG_LOG_PARAM("gh start error that don't inited!\r\n"); + } + } + else + { + GH3X2X_DEBUG_LOG_PARAM("gh started,restart call stop->start!\r\n"); + } + + return chRet; +} + +#if !__GH3X2X_CASCADE_EN__ +void GH3X2X_StartSamplingSlaveChip(void){} +void GH3X2X_StopSamplingSlaveChip(void){} +#else +void GH3X2X_StartSamplingSlaveChip(void) +{ + GU16 usRegVal = 0; + if(GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_WAIT_CHIP_WAKEUP(); + if (g_usCurrentFiFoWaterLine != GH3X2X_ReadReg(GH3X2X_FIFO_WATERLINE_REG_ADDR)) //record water line + { + GH3X2X_WriteReg(GH3X2X_FIFO_WATERLINE_REG_ADDR, g_usCurrentFiFoWaterLine); + GH3X2X_DEBUG_LOG_PARAM("gh chip2 and chip1 fifowater linie not equal!\r\n"); + } + usRegVal = GH3X2X_ReadReg(GH3X2X_CARDIFF_CTRL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, GH3X2X_SET_BIT(usRegVal, GH3X2X_CARDIFF_CTRL_START_BIT)); +// #if GH3X2X_ALGORITHM_ECG_SUPPORT +// GH3X2X_LeadDetEnControl(ECG_SAMPLE_EVENT_INFO_SAMPLE_START); +// #endif + GH3X2X_CascadeOperationMasterChip(); + GH3X2X_DEBUG_LOG_PARAM("gh chip2 ecg start!\r\n"); + } +} + +void GH3X2X_StopSamplingSlaveChip(void) +{ + GU16 usRegVal = 0; + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_WAIT_CHIP_WAKEUP(); + //g_uchGh3x2xStatus = GH3X2X_STATUS_INITED; + usRegVal = GH3X2X_ReadReg(GH3X2X_CARDIFF_CTRL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, GH3X2X_CLEAR_BIT(usRegVal, GH3X2X_CARDIFF_CTRL_START_BIT)); +// #if GH3X2X_ALGORITHM_ECG_SUPPORT +// GH3X2X_LeadDetEnControl(ECG_SAMPLE_EVENT_INFO_SAMPLE_STOP); +// #endif + //HOOK_FUNC_CALL(g_pGh3x2xStopHookFunc, () ); /* call hook */ + GH3X2X_WAIT_CHIP_DSLP(); + GH3X2X_CascadeOperationMasterChip(); + } +} +#endif +/** + * @fn GS8 GH3X2X_StopSampling(void) + * + * @brief Stop gh3x2x sampling + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_StopSampling(void) +{ + GS8 chRet = GH3X2X_RET_NO_INITED_ERROR; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((g_uchGh3x2xStatus == GH3X2X_STATUS_INITED) || (g_uchGh3x2xStatus == GH3X2X_STATUS_STARTED)) + { + GU16 usRegVal = 0; + GH3X2X_WAIT_CHIP_WAKEUP(); + g_uchGh3x2xStatus = GH3X2X_STATUS_INITED; + usRegVal = GH3X2X_ReadReg(GH3X2X_CARDIFF_CTRL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, GH3X2X_CLEAR_BIT(usRegVal, GH3X2X_CARDIFF_CTRL_START_BIT)); + #if GH3X2X_ALGORITHM_ECG_SUPPORT && __FUNC_TYPE_ECG_ENABLE__ + GH3X2X_LeadDetEnControl(ECG_SAMPLE_EVENT_INFO_SAMPLE_STOP); + #endif + HOOK_FUNC_CALL(g_pGh3x2xStopHookFunc, () ); /* call hook */ + GH3X2X_WAIT_CHIP_DSLP(); + GH3X2X_StopSamplingSlaveChip(); + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("gh stop error that don't inited!\r\n"); + } + + return chRet; +} + + + +/** + * @fn GU16 GH3X2X_GetIrqStatus(void) + * + * @brief Get irq status reg val + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return irq status val, ref irq status mask + */ +GU16 GH3X2X_GetIrqStatus(void) +{ + GU16 usIrqRegVal = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GH3X2X_WAIT_CHIP_WAKEUP(); + usIrqRegVal = GH3X2X_ReadReg(GH3X2X_INT_STR_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_INT_STR_REG_ADDR, usIrqRegVal); + GH3X2X_WAIT_CHIP_DSLP(); + return (GU16)(usIrqRegVal & (GU16)GH3X2X_INT_STR_MSK_ALL_BIT); +} + +/** + * @fn void GH3X2X_UnpackRawdataPackage(STGh3x2xSlotRawdata *pstSlotRawdataArr, + * GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen) + * + * @brief Unpack to 8 slot rawdata from read fifo data buffer + * + * @attention This function should use in get rawdata hook; + * param pstSlotRawdataArr size must equal 8, define like stSlotRawdataArr[8]. If not define 8, + * that mcu will occur array out of bounds error, careful!!! + * + * @param[out] pstSlotRawdataArr pointer to 8 slot rawdata struct output + * @param[in] puchReadRawdataBuffer pointer to read fifo buffer + * @param[in] usReadRawdataLen read fifo rawdata data len (bytes) + * + * @return None + */ +void GH3X2X_UnpackRawdataPackage(STGh3x2xSlotRawdata *pstSlotRawdataArr, + GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen) +{ + GU16 usIndex = 0; + GU8 uchSlotNum = 0; + GU8 uchAdcNum = 0; + GU8 uchLastSlotNum = 0; + GU8 uchLastAdcNum = 0; + GU16 usRawdataIndex = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + for (usIndex = 0; usIndex < GH3X2X_SLOT_NUM_MAX; usIndex ++) + { + pstSlotRawdataArr[usIndex].usRawdataCnt = 0; // clear cnt + } + for (usIndex = 0; usIndex < usReadRawdataLen; usIndex += GH3X2X_FIFO_RAWDATA_SIZE) + { + uchSlotNum = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(puchReadRawdataBuffer[usIndex]); + uchAdcNum = GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(puchReadRawdataBuffer[usIndex]); + if (usIndex == 0) // fixed started + { + uchLastSlotNum = uchSlotNum; + uchLastAdcNum = uchAdcNum; + } + if ((uchLastSlotNum != uchSlotNum) + || ((uchLastSlotNum == uchSlotNum) && (uchAdcNum <= uchLastAdcNum) && (usIndex != 0))) + { + pstSlotRawdataArr[uchLastSlotNum].usRawdataCnt++; + } + usRawdataIndex = pstSlotRawdataArr[uchSlotNum].usRawdataCnt; + if (pstSlotRawdataArr[uchSlotNum].punRawdata != GH3X2X_PTR_NULL) + { + pstSlotRawdataArr[uchSlotNum].punRawdata[usRawdataIndex][uchAdcNum] = \ + GH3X2X_RAWDATA_CLEAR_SLOT_ADC_NUM(\ + GH3X2X_MAKEUP_DWORD(puchReadRawdataBuffer[usIndex], + puchReadRawdataBuffer[usIndex + 1], + puchReadRawdataBuffer[usIndex + 2], + puchReadRawdataBuffer[usIndex + 3])); + } + uchLastSlotNum = uchSlotNum; + uchLastAdcNum = uchAdcNum; + if ((usIndex + GH3X2X_FIFO_RAWDATA_SIZE) == usReadRawdataLen) + { + pstSlotRawdataArr[uchSlotNum].usRawdataCnt++; + } + } // for (usIndex = 0; usIndex < usReadRawdataLen; usIndex += 4) +} + +/** + * @fn GS16 GH3X2X_GetRawdata(STGh3x2xRawdata *pstGh3x2xRawdata, GU16* usFifoLength) + * + * @brief Get rawdata from fifo + * + * @attention None + * + * @param[in] None + * @param[out] pstGh3x2xRawdata pointer to rawdata struct output + * @param[out] usFifoLength pointer to read fifo bytes + * + * @return error code + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo is not empty + */ +GS16 GH3X2X_GetRawdata(STGh3x2xRawdata *pstGh3x2xRawdata, GU16* usFifoLength) +{ + GU16 usIndex = 0; + GS16 sRet = GH3X2X_RET_PARAMETER_ERROR; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (pstGh3x2xRawdata != GH3X2X_PTR_NULL) + { + if (pstGh3x2xRawdata->puchReadBuffer != GH3X2X_PTR_NULL) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + *usFifoLength = GH3X2X_FIFO_CNT_CALC(GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR)); + + if (*usFifoLength > g_usMaxNumReadFromFifo) + { + *usFifoLength = g_usMaxNumReadFromFifo; + sRet = GH3X2X_RET_READ_FIFO_CONTINUE; + } + + if ((*usFifoLength > 0) && (*usFifoLength <= GH3X2X_FIFO_DATA_BYTES_MAX_LEN)) + { + GH3X2X_ReadFifo(pstGh3x2xRawdata->puchReadBuffer, *usFifoLength); + } + else + { + if (*usFifoLength > GH3X2X_FIFO_DATA_BYTES_MAX_LEN) + { + *usFifoLength = 0; + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo len greater than max, pelease check i2c/spi!\r\n"); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo equl 0!\r\n"); + } + } + + /* call hook */ + HOOK_FUNC_CALL(g_pGh3x2xGetRawdataHookFunc, (pstGh3x2xRawdata->puchReadBuffer, *usFifoLength) ); + GH3X2X_WAIT_CHIP_DSLP(); + GH3X2X_UnpackRawdataPackage(pstGh3x2xRawdata->stSlotRawdataArr, + pstGh3x2xRawdata->puchReadBuffer, *usFifoLength); + }// if (pstGh3x2xRawdata->puchReadBuffer != GH3X2X_PTR_NULL) + else // fixed clear cnt if readbuffer ptr is null + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata error that readbuffer is null!\r\n"); + for (usIndex = 0; usIndex < GH3X2X_SLOT_NUM_MAX; usIndex ++) + { + pstGh3x2xRawdata->stSlotRawdataArr[usIndex].usRawdataCnt = 0; // clear cnt + } + } + }// if (pstGh3x2xRawdata != GH3X2X_PTR_NULL) + + return sRet; +} + +#if 0 +void GH3X2X_SetFifoPackageMode(GU8 uchMode, GU8 *puchFifoBuffer) +{ + g_uchFifoPackageMode = uchMode; + gpuchSendFifoPackage = puchFifoBuffer; +} +#endif + + +#if (0 == __FIFO_PACKAGE_SEND_ENABLE__) +GU8 GH3X2X_GetFifoPackageMode(void) +{ + return 0; +} +void GH3X2X_SendRawdataFifoPackage(GU8 *puchGh3x2xReadFifoData, GU16 usFifoReadByteNum){} +#else +GU8 GH3X2X_GetFifoPackageMode(void) + +{ + return g_uchFifoPackageMode; +} + +void GH3X2X_SendRawdataFifoPackage(GU8 *puchGh3x2xReadFifoData, GU16 usFifoReadByteNum) +{ + if (usFifoReadByteNum == 0) + { + return; + } + g_uchFifoPackageID ++; + GU8 unRawdataFifoBuffer[220] = {0}; + GU8 unSendRawdataFifoBuffer[235] = {0}; + GU32 uRawdataBufCnt = 0; + GU8 uchIdChangeFlag = 0; + GU16 usPackageNum = usFifoReadByteNum / 200; + GU16 usLastRawdataFifoBufNum = usFifoReadByteNum % 200; + if (usLastRawdataFifoBufNum == 0) + { + usLastRawdataFifoBufNum = 200; + usPackageNum--; + } + for (uRawdataBufCnt = 0 ; uRawdataBufCnt < usPackageNum ; uRawdataBufCnt ++) + { + unRawdataFifoBuffer[0] = g_uchFifoPackageID; + unRawdataFifoBuffer[1] = 200; + unRawdataFifoBuffer[2] = uchIdChangeFlag; + uchIdChangeFlag ++; + GH3X2X_Memcpy(&unRawdataFifoBuffer[5], &puchGh3x2xReadFifoData[uRawdataBufCnt * 200], (GU32)200); + GU16 usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_RAWDATA_FIFO_UPDATE, unSendRawdataFifoBuffer, + unRawdataFifoBuffer, 200 + 5); + Gh3x2xDemoSendProtocolData(unSendRawdataFifoBuffer, usRespondLen); + } + unRawdataFifoBuffer[0] = g_uchFifoPackageID; + unRawdataFifoBuffer[1] = (GU8)(usLastRawdataFifoBufNum); + unRawdataFifoBuffer[2] = 0x10 | uchIdChangeFlag; + GH3X2X_Memcpy(&unRawdataFifoBuffer[5], &puchGh3x2xReadFifoData[usPackageNum * 200], (GU32)usLastRawdataFifoBufNum); + GU16 usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_RAWDATA_FIFO_UPDATE, unSendRawdataFifoBuffer, + unRawdataFifoBuffer, usLastRawdataFifoBufNum + 5); + Gh3x2xDemoSendProtocolData(unSendRawdataFifoBuffer, usRespondLen); +} +#endif + +#if 0 +void GH3X2X_PackRawdataFifoPackage(GU8 *puchGh3x2xReadFifoData, GU16 usFifoReadByteNum) +{ + if (usFifoReadByteNum == 0) + { + return; + } + + if (usFifoReadByteNum + g_unSendFifoPackageCnt >= GH3X2X_RAWDATA_BUFFER_SIZE) + { + GU32 usFifoReadExternByteNum = GH3X2X_RAWDATA_BUFFER_SIZE - g_unSendFifoPackageCnt; + GH3X2X_Memcpy(&gpuchSendFifoPackage[g_unSendFifoPackageCnt], puchGh3x2xReadFifoData, usFifoReadExternByteNum); + g_unSendFifoPackageCnt += usFifoReadExternByteNum; + + GH3X2X_SendRawdataFifoPackage(gpuchSendFifoPackage, g_unSendFifoPackageCnt); + + g_unSendFifoPackageCnt = 0; + + GH3X2X_Memcpy(&gpuchSendFifoPackage[g_unSendFifoPackageCnt],\ + &puchGh3x2xReadFifoData[usFifoReadByteNum - (GH3X2X_RAWDATA_BUFFER_SIZE - g_unSendFifoPackageCnt)],\ + usFifoReadByteNum + g_unSendFifoPackageCnt - GH3X2X_RAWDATA_BUFFER_SIZE); + g_unSendFifoPackageCnt += usFifoReadByteNum + g_unSendFifoPackageCnt - GH3X2X_RAWDATA_BUFFER_SIZE; + } + else + { + GH3X2X_Memcpy(&gpuchSendFifoPackage[g_unSendFifoPackageCnt], puchGh3x2xReadFifoData, usFifoReadByteNum); + g_unSendFifoPackageCnt += usFifoReadByteNum; + } +} +#endif + + +/** + * @fn GU16 GH3X2X_FindGu16MinVal(GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find min val + * + * @attention len must > 0 + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] None + * + * @return min val, if len = 0, return 0 + */ +GU16 GH3X2X_FindGu16MinVal(GU16 *pusBuffer, GU8 uchLen) +{ + GU16 usMinVal = pusBuffer[0]; + GU8 uchIndex = 1; + + for (uchIndex = 1; uchIndex < uchLen; uchIndex++) + { + if (pusBuffer[uchIndex] < usMinVal) + { + usMinVal = pusBuffer[uchIndex]; + } + } + return usMinVal; +} + +/** + * @fn GU16 GH3X2X_FindGu16MaxVal(GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find max val + * + * @attention len must > 0 + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] None + * + * @return max val, if len = 0, return 0 + */ +GU16 GH3X2X_FindGu16MaxVal(GU16 *pusBuffer, GU8 uchLen) +{ + GU16 usMaxVal = pusBuffer[0]; + GU8 uchIndex = 1; + + for (uchIndex = 1; uchIndex < uchLen; uchIndex++) + { + if (pusBuffer[uchIndex] > usMaxVal) + { + usMaxVal = pusBuffer[uchIndex]; + } + } + return usMaxVal; +} + +/** + * @fn void GH3X2X_FindGu16MaxMinVal(GU16 *pusMaxVal, GU16 *pusMinVal, GU16 *pusBuffer, GU8 uchLen) + * + * @brief Find min val & max val + * + * @attention len must > 0, ptr not null + * + * @param[in] pusBuffer pointer to buffer + * @param[in] uchLen buffer length + * @param[out] pusMaxVal pointer to max val + * @param[out] pusMinVal pointer to min val + * + * @return None + */ +void GH3X2X_FindGu16MaxMinVal(GU16 *pusMaxVal, GU16 *pusMinVal, GU16 *pusBuffer, GU8 uchLen) +{ + GU16 usMaxVal = pusBuffer[0]; + GU16 usMinVal = pusBuffer[0]; + GU8 uchIndex = 1; + + for (uchIndex = 1; uchIndex < uchLen; uchIndex++) + { + if (pusBuffer[uchIndex] > usMaxVal) + { + usMaxVal = pusBuffer[uchIndex]; + } + if (pusBuffer[uchIndex] < usMinVal) + { + usMinVal = pusBuffer[uchIndex]; + } + } + SET_VAL_VIA_PTR(pusMaxVal, usMaxVal); + SET_VAL_VIA_PTR(pusMinVal, usMinVal); +} + +/** + * @fn GS8 GH3X2X_UnpackRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + * GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr) + * + * @brief Unpack to channel rawdata from read fifo data buffer; + * if last channel rawdata incomplete, should change fifo watermark + * + * @attention This function should use in get rawdata hook + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] usReadRawdataLen read data length + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[out] pstGh3x2xChannelRawdata pointer to channel rawdata struct + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_UnpackRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr) +{ + GU8 uchChCntIndex = 0; + GU16 usRawdataIndex = 0; + GU16 usRawdataCnt = 0; + GU16 usRawdataCntMin = 0; + GU16 usRawdataCntMax = 0; + GU16 usRawdataIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; // use for rawdata cnt & rawdata bytes index + GU16 usRawdataByteIndexTmp = 0; + GU16 usRawdataBaseIndex = 0; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + + /* check pram */ + if ((pstGh3x2xChannelRawdata->punIncompleteChRawdataArr == GH3X2X_PTR_NULL) + || (pstGh3x2xChannelRawdata->punChRawdataArr == GH3X2X_PTR_NULL) || (puchReadRawdataBuffer == GH3X2X_PTR_NULL) + || (pstGh3x2xChannelRawdata == GH3X2X_PTR_NULL) || (puchChannelMapArr == GH3X2X_PTR_NULL)) + { + GH3X2X_DEBUG_LOG_PARAM("pointer param set null error!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + if (GH3X2X_CLEAR_BIT(puchChannelMapArr[uchChCntIndex], GH3X2X_SLOT_ADC_NUM_BITS) != 0) + { + GH3X2X_DEBUG_LOG_PARAM("channel map error! set @ref GH3X2X_CHANNEL_MAP!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + } + if (uchChannelMapCnt > GH3X2X_CHANNEL_MAP_MAX_CH) + { + GH3X2X_DEBUG_LOG_PARAM("channel cnt greater than max!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + + /* calc rawdata len */ + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + if (GH3X2X_CHECK_LEFT_BIT_SET(pstGh3x2xChannelRawdata->unIncompleteChMark, uchChCntIndex)) + { + usRawdataIndexArr[uchChCntIndex]++; + } + for (usRawdataIndex = 0; usRawdataIndex < usReadRawdataLen; usRawdataIndex += GH3X2X_FIFO_RAWDATA_SIZE) + { + if (puchChannelMapArr[uchChCntIndex] == GH3X2X_CHANNEL_MAP_GET(puchReadRawdataBuffer[usRawdataIndex])) + { + usRawdataIndexArr[uchChCntIndex]++; // if rawdata channel map equal config(included slot&adc) + } + } + } + GH3X2X_FindGu16MaxMinVal(&usRawdataCntMax, &usRawdataCntMin, usRawdataIndexArr, uchChannelMapCnt); // calc min&max + if (usRawdataCntMax == usRawdataCntMin) + { + usRawdataCnt = usRawdataCntMax; // whatever last data complete or incomplete + } + else + { + if ((usRawdataCntMax - usRawdataCntMin) > 1) + { + GH3X2X_DEBUG_LOG_PARAM("rawdata doesn't correspond to channel map error!\r\n"); + usRawdataCnt = 0; + pstGh3x2xChannelRawdata->unIncompleteChMark = 0; + GH3X2X_Memset(pstGh3x2xChannelRawdata->punIncompleteChRawdataArr, 0, uchChannelMapCnt * sizeof(GU32)); + } + else // cnt tolerable deviation is 1 + { + usRawdataCnt = GH3X2X_FindGu16MinVal(usRawdataIndexArr, uchChannelMapCnt); + } + } // end of if (usRawdataCntMax == usRawdataCntMin) + GH3X2X_Memset(usRawdataIndexArr, 0, uchChannelMapCnt * sizeof(GU16)); // clear index array, before next use + + if (usRawdataCnt != 0) + { + for (usRawdataIndex = 0; usRawdataIndex < usRawdataCnt; usRawdataIndex++) + { + usRawdataBaseIndex = (GU16)(usRawdataIndex * uchChannelMapCnt); + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // search each channel + { + if (GH3X2X_CHECK_LEFT_BIT_SET(pstGh3x2xChannelRawdata->unIncompleteChMark, uchChCntIndex)) + { + pstGh3x2xChannelRawdata->punChRawdataArr[usRawdataBaseIndex + uchChCntIndex] = \ + pstGh3x2xChannelRawdata->punIncompleteChRawdataArr[uchChCntIndex]; + pstGh3x2xChannelRawdata->punIncompleteChRawdataArr[uchChCntIndex] = 0; + GH3X2X_VAL_CLEAR_LEFT_BIT(pstGh3x2xChannelRawdata->unIncompleteChMark, uchChCntIndex); + } + else + { + usRawdataByteIndexTmp = usRawdataIndexArr[uchChCntIndex]; + while (usRawdataByteIndexTmp < usReadRawdataLen) // search each + { + if (GH3X2X_CHANNEL_MAP_GET(puchReadRawdataBuffer[usRawdataByteIndexTmp]) == \ + puchChannelMapArr[uchChCntIndex]) // if map equal + { + pstGh3x2xChannelRawdata->punChRawdataArr[usRawdataBaseIndex + uchChCntIndex] = \ + GH3X2X_RAWDATA_CLEAR_SLOT_ADC_NUM( + GH3X2X_MAKEUP_DWORD(puchReadRawdataBuffer[usRawdataByteIndexTmp], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 1], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 2], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 3])); + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + break; + } + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + } + usRawdataIndexArr[uchChCntIndex] = usRawdataByteIndexTmp; // write back byte index + } + } // end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + } // end of for (usRawdataIndex = 0; usRawdataIndex < usRawdataCnt; usRawdataIndex++) + if (usRawdataCntMax != usRawdataCnt) + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // search each channel + { + usRawdataByteIndexTmp = usRawdataIndexArr[uchChCntIndex]; + while (usRawdataByteIndexTmp < usReadRawdataLen) // search each + { + if (GH3X2X_CHANNEL_MAP_GET(puchReadRawdataBuffer[usRawdataByteIndexTmp]) == \ + puchChannelMapArr[uchChCntIndex]) // if map equal + { + pstGh3x2xChannelRawdata->punIncompleteChRawdataArr[uchChCntIndex] = \ + GH3X2X_RAWDATA_CLEAR_SLOT_ADC_NUM( + GH3X2X_MAKEUP_DWORD(puchReadRawdataBuffer[usRawdataByteIndexTmp], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 1], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 2], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 3])); + pstGh3x2xChannelRawdata->unIncompleteChMark |= GH3X2X_GET_LEFT_SHIFT_VAL(uchChCntIndex); + break; + } + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + } + if (GH3X2X_CHECK_LEFT_BIT_NOT_SET(pstGh3x2xChannelRawdata->unIncompleteChMark, uchChCntIndex)) + { + pstGh3x2xChannelRawdata->punIncompleteChRawdataArr[uchChCntIndex] = 0; + } + } + } // end of if (usRawdataCntMax != usRawdataCnt) + } // end of if (usRawdataCnt != 0) + pstGh3x2xChannelRawdata->usChRawdataCnt = usRawdataCnt; + return GH3X2X_RET_OK; +} + +/** + * @fn GS16 GH3X2X_GetRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + * GU8 *puchReadRawdataBuffer, GU16* usFifoLength, GU8 uchChannelMapCnt, + * GU8 *puchChannelMapArr) + * + * @brief Get rawdata from fifo with channel map + * + * @attention None + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[out] pstGh3x2xChannelRawdata pointer to channel rawdata struct output + * @param[out] usFifoLength pointer to read fifo data length in bytes + * + * @return GH3X2X_RET_OK return read fifo successful + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo is not empty + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS16 GH3X2X_GetRawdataWithChannelMap(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata, + GU8 *puchReadRawdataBuffer, GU16* usFifoLength, GU8 uchChannelMapCnt, + GU8 *puchChannelMapArr) +{ + GS16 sRet = GH3X2X_RET_OK; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + + if ((puchReadRawdataBuffer != GH3X2X_PTR_NULL) && (usFifoLength != GH3X2X_PTR_NULL)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + *usFifoLength = GH3X2X_FIFO_CNT_CALC(GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR)); + if (*usFifoLength > g_usMaxNumReadFromFifo) + { + *usFifoLength = g_usMaxNumReadFromFifo; + sRet = GH3X2X_RET_READ_FIFO_CONTINUE; + } + if ((*usFifoLength > 0) && (*usFifoLength <= GH3X2X_FIFO_DATA_BYTES_MAX_LEN)) + { + GH3X2X_ReadFifo(puchReadRawdataBuffer, *usFifoLength); + } + else + { + if (*usFifoLength > GH3X2X_FIFO_DATA_BYTES_MAX_LEN) + { + *usFifoLength = 0; + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo len greater than max, pelease check i2c/spi!\r\n"); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo equl 0!\r\n"); + } + } + + /* call hook */ + HOOK_FUNC_CALL(g_pGh3x2xGetRawdataHookFunc, (puchReadRawdataBuffer, *usFifoLength)); + GH3X2X_WAIT_CHIP_DSLP(); + sRet = GH3X2X_UnpackRawdataWithChannelMap(pstGh3x2xChannelRawdata, puchReadRawdataBuffer, *usFifoLength, + uchChannelMapCnt, puchChannelMapArr); + } + else // fixed clear cnt if readbuffer ptr is null + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata error that readbuffer is null!\r\n"); + sRet = GH3X2X_RET_PARAMETER_ERROR; + } + + return sRet; +} + +/** + * @fn GS8 GH3X2X_ChannelMapRawdataClear(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata) + * + * @brief clear channel map rawdata struct + * + * @attention This function must use before get rawdata by onne kind channel map + * e.g. channel map start/stop need clear + * + * @param[in] pstGh3x2xChannelRawdata pointer to channel rawdata struct + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_ChannelMapRawdataClear(STGh3x2xChannelRawdata *pstGh3x2xChannelRawdata) +{ + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (pstGh3x2xChannelRawdata != GH3X2X_PTR_NULL) + { + pstGh3x2xChannelRawdata->unIncompleteChMark = 0; + pstGh3x2xChannelRawdata->usChRawdataCnt = 0; + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("channel rawdata param is null!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SlotEnableConfig(GU16 usSlotEnableConfig, EMSlotEnableConfigType emSlotEnableConfigType) + * + * @brief Slot enable config + * + * @attention Set slot enable or disable, if just need enable slot by enable config param + * + * @param[in] usSlotEnableConfig slot enable index , @ref GH3X2X_SLOT_INDEX_0 ... GH3X2X_SLOT_INDEX_ALL + * @param[in] emSlotEnableConfigType slot config type, @ref EMSlotEnableConfigType + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_SlotEnableConfig(GU16 usSlotEnableConfig, EMSlotEnableConfigType emSlotEnableConfigType) +{ + GS8 chRet = GH3X2X_RET_OK; + GU16 usSlotEnableCfgRegVal = 0; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (GH3X2X_CHECK_BIT_SET(GH3X2X_SLOT_INDEX_ALL, usSlotEnableConfig)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + switch (emSlotEnableConfigType) + { + case GH3X2X_SET_SLOT_ENABLE: + usSlotEnableCfgRegVal = GH3X2X_ReadReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, + GH3X2X_SET_BIT(usSlotEnableCfgRegVal, usSlotEnableConfig) & GH3X2X_SLOT_INDEX_ALL); + break; + case GH3X2X_SET_SLOT_DISABLE: + usSlotEnableCfgRegVal = GH3X2X_ReadReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, + GH3X2X_CLEAR_BIT(usSlotEnableCfgRegVal, usSlotEnableConfig) & GH3X2X_SLOT_INDEX_ALL); + break; + default: // include GH3X2X_SET_SLOT_DIRECT_ENABLE mode + GH3X2X_WriteReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, usSlotEnableConfig & GH3X2X_SLOT_INDEX_ALL); + break; + } + GH3X2X_WAIT_CHIP_DSLP(); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("slot enable config error!\r\n"); + chRet = GH3X2X_RET_PARAMETER_ERROR; + } + return chRet; +} + +/** + * @fn void GH3X2X_SlotEnRegSet(GU8 uchSetValue) + * + * @brief Slot enable reg set + * + * @attention None + * + * @param[in] set value + * @param[out] None + * + * @return None + */ +void GH3X2X_SlotEnRegSet(GU8 uchSetValue) +{ + + + GH3X2X_DEBUG_LOG_PARAM("[SlotEnRegSet] set slot en: 0x%X\r\n",uchSetValue); + GH3X2X_WriteReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, + (GU16)uchSetValue); +} + + +void GH3X2X_EcgCascadeSlotEnRegSet(GU8 uchSetValue) +{ + //chip1 disable ecg_slot + GH3X2X_WriteReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, + (GU16)0); + GU16 usRegVal = 0; + //chip1 clear fifo + usRegVal = GH3X2X_ReadReg(GH3X2X_CARDIFF_CTRL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, GH3X2X_CLEAR_BIT(usRegVal, GH3X2X_CARDIFF_CTRL_START_BIT)); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, usRegVal); + + + GH3X2X_CascadeOperationSlaverChip(); + //chip2 clear fifo, chip2 reset lead status + usRegVal = GH3X2X_ReadReg(GH3X2X_CARDIFF_CTRL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, GH3X2X_CLEAR_BIT(usRegVal, GH3X2X_CARDIFF_CTRL_START_BIT)); + GH3X2X_WriteReg(GH3X2X_CARDIFF_CTRL_REG_ADDR, usRegVal); + + GH3X2X_WriteReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, + (GU16)uchSetValue); + GH3X2X_CascadeOperationMasterChip(); + + //chip1 enable ecg_slot + GH3X2X_WriteReg(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, + (GU16)uchSetValue); + +} + + + + + +/** + * @fn GS8 GH3X2X_FifoWatermarkThrConfig(GU16 usFifoWatermarkThr) + * + * @brief Fifo water mark threshold config + * + * @attention Watermark threshold val must in (2, 800]. if val <= 2, will set 3, if val > 800, set 800; + * Be careful that fifo_use_cnt greater than val, gh3x2x willn't generate fifo_watermark interrupt after! + * + * @param[in] usFifoWatermarkThr watermark threshold val + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + */ +GS8 GH3X2X_FifoWatermarkThrConfig(GU16 usFifoWatermarkThr) +{ + GU16 usFifoWatermarkThrVal = usFifoWatermarkThr; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (usFifoWatermarkThrVal < GH3X2X_FIFO_WATERMARK_THR_MIN) + { + GH3X2X_DEBUG_LOG_PARAM("fifo wateramrk thr param less than min!\r\n"); + usFifoWatermarkThrVal = GH3X2X_FIFO_WATERMARK_THR_MIN; + } + else if (usFifoWatermarkThrVal > GH3X2X_FIFO_WATERMARK_THR_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("fifo wateramrk thr param greater than max!\r\n"); + usFifoWatermarkThrVal = GH3X2X_FIFO_WATERMARK_THR_MAX; + } + GH3X2X_WAIT_CHIP_WAKEUP(); + GH3X2X_WriteReg(GH3X2X_FIFO_WATERLINE_REG_ADDR, usFifoWatermarkThrVal); + GH3X2X_WAIT_CHIP_DSLP(); + g_usCurrentFiFoWaterLine = usFifoWatermarkThrVal; + return GH3X2X_RET_OK; +} + +/** + * @fn GU16 GH3X2X_GetFifoWatermarkThr(void) + * + * @brief Get fifo water mark threshold + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return fifo water mark threshold + */ +GU16 GH3X2X_GetFifoWatermarkThr(void) +{ + GU16 usFifoWatermarkThrVal = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GH3X2X_WAIT_CHIP_WAKEUP(); + usFifoWatermarkThrVal = GH3X2X_ReadReg(GH3X2X_FIFO_WATERLINE_REG_ADDR); + GH3X2X_WAIT_CHIP_DSLP(); + return usFifoWatermarkThrVal; +} + +/** + * @fn GS8 GH3X2X_SlotLedCurrentConfig(GU8 uchSlotIndex, GU8 uchDrvIndex, GU8 uchCurrentVal) + * + * @brief Slot led current config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchDrvIndex driver index @ref GH3X2X_LED_DRV_INDEX_0 ... GH3X2X_LED_DRV_INDEX_1 + * @param[in] uchCurrentVal current val + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_SlotLedCurrentConfig(GU8 uchSlotIndex, GU8 uchDrvIndex, GU8 uchCurrentVal) +{ + GU16 usCurrentRegVal = 0; + GU16 usSlotDrvRegAddr = 0; + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((uchSlotIndex < GH3X2X_SLOT_NUM_MAX) && (uchDrvIndex < GH3X2X_SLOT_LED_DRV_NUM_MAX)) + { + usSlotDrvRegAddr = GH3X2X_SLOT0_CTRL_10_REG_ADDR + (uchSlotIndex * GH3X2X_SLOT_CTRL_OFFSET)\ + + (uchDrvIndex * GH3X2X_REG_ADDR_SIZE); + GH3X2X_WAIT_CHIP_WAKEUP(); + usCurrentRegVal = GH3X2X_ReadReg(usSlotDrvRegAddr); + GH3X2X_VAL_CLEAR_BIT(usCurrentRegVal, (GU16)GH3X2X_SLOT_LED_CURRENT_CLEAR_MASK); + GH3X2X_VAL_SET_BIT(usCurrentRegVal, (GU16)uchCurrentVal); + GH3X2X_WriteReg(usSlotDrvRegAddr, usCurrentRegVal); + GH3X2X_WAIT_CHIP_DSLP(); + chRet = GH3X2X_RET_OK; + } + else + { + if (uchSlotIndex >= GH3X2X_SLOT_NUM_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("slot index param greater than max!\r\n"); + } + else // uchDrvIndex >= GH3X2X_SLOT_LED_DRV_NUM_MAX + { + GH3X2X_DEBUG_LOG_PARAM("drv index param greater than max!\r\n"); + } + } + return chRet; +} + +/** + * @fn GU8 GH3X2X_GetSlotLedCurrent(GU8 uchSlotIndex, GU8 uchDrvIndex) + * + * @brief Get slot led current config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchDrvIndex driver index @ref GH3X2X_LED_DRV_INDEX_0 ... GH3X2X_LED_DRV_INDEX_1 + * @param[out] None + * + * @return current val. if param error, return val always equal 0 + */ +GU8 GH3X2X_GetSlotLedCurrent(GU8 uchSlotIndex, GU8 uchDrvIndex) +{ + GU16 usCurrentRegVal = 0; + GU16 usSlotDrvRegAddr = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((uchSlotIndex < GH3X2X_SLOT_NUM_MAX) && (uchDrvIndex < GH3X2X_SLOT_LED_DRV_NUM_MAX)) + { + usSlotDrvRegAddr = GH3X2X_SLOT0_CTRL_10_REG_ADDR + (uchSlotIndex * GH3X2X_SLOT_CTRL_OFFSET)\ + + (uchDrvIndex * GH3X2X_REG_ADDR_SIZE); + GH3X2X_WAIT_CHIP_WAKEUP(); + usCurrentRegVal = GH3X2X_ReadReg(usSlotDrvRegAddr); + GH3X2X_WAIT_CHIP_DSLP(); + } + else + { + if (uchSlotIndex >= GH3X2X_SLOT_NUM_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("slot index param greater than max!\r\n"); + } + else // uchDrvIndex >= GH3X2X_SLOT_LED_DRV_NUM_MAX + { + GH3X2X_DEBUG_LOG_PARAM("drv index param greater than max!\r\n"); + } + } + return GH3X2X_GET_LOW_BYTE_FROM_WORD(usCurrentRegVal); +} + +/** + * @fn GS8 GH3X2X_SlotLedTiaGainConfig(GU8 uchSlotIndex, GU8 uchAdcIndex, GU8 uchGainVal) + * + * @brief Slot gain config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchAdcIndex adc index [0-3] + * @param[in] uchGainVal tia gain val [0-12] + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_SlotLedTiaGainConfig(GU8 uchSlotIndex, GU8 uchAdcIndex, GU8 uchGainVal) +{ + GU16 usGainRegVal = 0; + GU16 usSlotTiaGainRegAddr = 0; + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((uchSlotIndex < GH3X2X_SLOT_NUM_MAX) && (uchAdcIndex < GH3X2X_SLOT_TIA_GAIN_NUM_MAX) + && (uchGainVal < GH3X2X_SLOT_TIA_GAIN_VAL_MAX)) + { + usSlotTiaGainRegAddr = GH3X2X_SLOT0_CTRL_4_REG_ADDR + (uchSlotIndex * GH3X2X_SLOT_CTRL_OFFSET); + GH3X2X_WAIT_CHIP_WAKEUP(); + usGainRegVal = GH3X2X_ReadReg(usSlotTiaGainRegAddr); + GH3X2X_VAL_CLEAR_BIT(usGainRegVal, + (GH3X2X_SLOT_TIA_GAIN_BITS_MARK << (GH3X2X_SLOT_TIA_GAIN_BITS_SIZE * uchAdcIndex))); + GH3X2X_VAL_SET_BIT(usGainRegVal, (((GU16)uchGainVal) << (GH3X2X_SLOT_TIA_GAIN_BITS_SIZE * uchAdcIndex))); + GH3X2X_WriteReg(usSlotTiaGainRegAddr, usGainRegVal); + GH3X2X_WAIT_CHIP_DSLP(); + chRet = GH3X2X_RET_OK; + } + else + { + if (uchSlotIndex >= GH3X2X_SLOT_NUM_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("slot index param greater than max!\r\n"); + } + else if (uchAdcIndex >= GH3X2X_SLOT_TIA_GAIN_NUM_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("adc index param greater than max!\r\n"); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("gain val param greater than max!\r\n"); + } + } + return chRet; +} + +/** + * @fn GU8 GH3X2X_GetSlotLedTiaGain(GU8 uchSlotIndex, GU8 uchAdcIndex) + * + * @brief Get slot gain config + * + * @attention None + * + * @param[in] uchSlotIndex slot index [0-7] + * @param[in] uchAdcIndex adc index [0-3] + * @param[out] None + * + * @return tia gain val. if param error, return val always equal 0 + */ +GU8 GH3X2X_GetSlotLedTiaGain(GU8 uchSlotIndex, GU8 uchAdcIndex) +{ + GU16 usGainRegVal = 0; + GU16 usSlotTiaGainRegAddr = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((uchSlotIndex < GH3X2X_SLOT_NUM_MAX) && (uchAdcIndex < GH3X2X_SLOT_TIA_GAIN_NUM_MAX)) + { + usSlotTiaGainRegAddr = GH3X2X_SLOT0_CTRL_4_REG_ADDR + (uchSlotIndex * GH3X2X_SLOT_CTRL_OFFSET); + GH3X2X_WAIT_CHIP_WAKEUP(); + usGainRegVal = GH3X2X_ReadReg(usSlotTiaGainRegAddr); + GH3X2X_WAIT_CHIP_DSLP(); + } + else + { + if (uchSlotIndex >= GH3X2X_SLOT_NUM_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("slot index param greater than max!\r\n"); + } + else // uchAdcIndex >= GH3X2X_SLOT_TIA_GAIN_NUM_MAX + { + GH3X2X_DEBUG_LOG_PARAM("adc index param greater than max!\r\n"); + } + } + return (GU8)(((usGainRegVal) >> (GH3X2X_SLOT_TIA_GAIN_BITS_SIZE * uchAdcIndex)) & GH3X2X_SLOT_TIA_GAIN_BITS_MARK); +} + +/** + * @fn GS8 GH3X2X_AdcBgcThrConfig(GU8 uchAdcIndex, GU8 uchBgcThrVal) + * + * @brief adc bgc thr config + * + * @attention None + * + * @param[in] uchAdcIndex adc index [0-3] + * @param[in] uchBgcThrVal bgc thr val [0-7] + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_AdcBgcThrConfig(GU8 uchAdcIndex, GU8 uchBgcThrVal) +{ + GU16 usBgcThregVal = 0; + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + GU8 uchKdcCh = (GU8)(GH3X2X_SLOT_KDC_THR_ADC_INDEX_MAX - uchAdcIndex); + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((uchAdcIndex < GH3X2X_SLOT_TIA_GAIN_NUM_MAX) && (uchBgcThrVal < GH3X2X_SLOT_KDC_THR_VAL_MAX)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + usBgcThregVal = GH3X2X_ReadReg(GH3X2X_PPG_DAC_AD_REG1_REG_ADDR); + GH3X2X_VAL_CLEAR_BIT(usBgcThregVal, + (GH3X2X_SLOT_KDC_THR_BITS_MARK << (GH3X2X_SLOT_KDC_THR_BITS_SIZE * uchKdcCh))); + GH3X2X_VAL_SET_BIT(usBgcThregVal, (((GU16)uchBgcThrVal) << (GH3X2X_SLOT_KDC_THR_BITS_SIZE * uchKdcCh))); + GH3X2X_WriteReg(GH3X2X_PPG_DAC_AD_REG1_REG_ADDR, usBgcThregVal); + GH3X2X_WAIT_CHIP_DSLP(); + chRet = GH3X2X_RET_OK; + } + else + { + if (uchAdcIndex >= GH3X2X_SLOT_TIA_GAIN_NUM_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("adc index param greater than max!\r\n"); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("bgc thr val param greater than max!\r\n"); + } + } + return chRet; +} + +/** + * @fn GU8 GH3X2X_GetAdcBgcThr(GU8 uchAdcIndex) + * + * @brief Get adc bgc thr config + * + * @attention None + * + * @param[in] uchAdcIndex adc index [0-3] + * @param[out] None + * + * @return tia gain val. if param error, return val always equal 0 + */ +GU8 GH3X2X_GetAdcBgcThr(GU8 uchAdcIndex) +{ + GU16 usBgcThregVal = 0; + GU8 uchKdcCh = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (uchAdcIndex < GH3X2X_SLOT_TIA_GAIN_NUM_MAX) + { + uchKdcCh = (GU8)(GH3X2X_SLOT_KDC_THR_ADC_INDEX_MAX - uchAdcIndex); + GH3X2X_WAIT_CHIP_WAKEUP(); + usBgcThregVal = GH3X2X_ReadReg(GH3X2X_PPG_DAC_AD_REG1_REG_ADDR); + GH3X2X_WAIT_CHIP_DSLP(); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("adc index param greater than max!\r\n"); + } + return (GU8)(((usBgcThregVal) >> (GH3X2X_SLOT_KDC_THR_BITS_SIZE * uchKdcCh)) & GH3X2X_SLOT_KDC_THR_BITS_MARK); +} + +/** + * @fn GS8 GH3X2X_IrqWidthConfig(GU16 usIrqPulseWidth, GU16 usIrqColdWidth) + * + * @brief Irq width config + * + * @attention Irq val must in [0, 2047]. real_width = (val + 1) * low_clk_tick; + * low_clk default 32k, if set ext clk enable that use low_ext_clk; + * + * @param[in] usIrqPulseWidth irq pulse width val + * @param[in] usIrqColdWidth irq cold width val + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + */ +GS8 GH3X2X_IrqWidthConfig(GU16 usIrqPulseWidth, GU16 usIrqColdWidth) +{ + GU16 usIrqPulseWidthVal = usIrqPulseWidth; + GU16 usIrqColdWidthVal = usIrqColdWidth; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (usIrqPulseWidthVal > GH3X2X_IRQ_WIDTH_VAL_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("irq pulse width param greater than max!\r\n"); + usIrqPulseWidthVal = GH3X2X_IRQ_WIDTH_VAL_MAX; + } + if (usIrqColdWidthVal > GH3X2X_IRQ_WIDTH_VAL_MAX) + { + GH3X2X_DEBUG_LOG_PARAM("irq cold width param greater than max!\r\n"); + usIrqColdWidthVal = GH3X2X_IRQ_WIDTH_VAL_MAX; + } + GH3X2X_WAIT_CHIP_WAKEUP(); + GH3X2X_WriteReg(GH3X2X_INT_PWR_REG_ADDR, usIrqPulseWidthVal); + GH3X2X_WriteReg(GH3X2X_INT_CTR_REG_ADDR, usIrqColdWidthVal); + GH3X2X_WAIT_CHIP_DSLP(); + return GH3X2X_RET_OK; +} + +/** + * @fn GS8 GH3X2X_IrqModeConfig(EMIrqModeConfig emIrqMode) + * + * @brief Irq mode config + * + * @attention None + * + * @param[in] emIrqMode irq mode config @ref EMIrqModeConfig + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + */ +GS8 GH3X2X_IrqModeConfig(EMIrqModeConfig emIrqMode) +{ + GU16 usIrqCtrlRegVal = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GH3X2X_WAIT_CHIP_WAKEUP(); + usIrqCtrlRegVal = GH3X2X_ReadReg(GH3X2X_INT_CR_REG_ADDR); + GH3X2X_VAL_CLEAR_BIT(usIrqCtrlRegVal, (GU16)GH3X2X_INT_CTRL_MODE_MSK_BIT); + GH3X2X_VAL_SET_BIT(usIrqCtrlRegVal, ((GU16)emIrqMode) & GH3X2X_INT_CTRL_MODE_MSK_BIT); + GH3X2X_WriteReg(GH3X2X_INT_CR_REG_ADDR, usIrqCtrlRegVal); + GH3X2X_WAIT_CHIP_DSLP(); + return GH3X2X_RET_OK; +} + +/** + * @fn void GH3X2X_RegisterResetPinControlFunc(void (*pResetPinLevelControlFunc)(GU8 uchPinLevel)) + * + * @brief Register reset pin level control function + * + * @attention Pin level set val should define as 1 [high level] or 0 [low level]; + * + * @param[in] pResetPinLevelControlFunc pointer to set reset pin level function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterResetPinControlFunc(void (*pResetPinLevelControlFunc)(GU8 uchPinLevel)) +{ + g_pGh3x2xResetPinLevelControlFunc = pResetPinLevelControlFunc; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); +} + +/** + * @fn GS8 GH3X2X_HardReset(void) + * + * @brief Gh3x2x softreset via i2c/spi, can read&write reg with gh3x2x after reset + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR reset pin control function not register + */ +GS8 GH3X2X_HardReset(void) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (g_pGh3x2xResetPinLevelControlFunc != GH3X2X_PTR_NULL) + { + g_pGh3x2xResetPinLevelControlFunc(0); + GH3X2X_DelayUs(GH3X2X_HARD_RESET_DELAY_X_US); /* hard reset delay 20us. */ + g_pGh3x2xResetPinLevelControlFunc(1); + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("reset pin ctrl func has not register!\r\n"); + } + g_uchActiveChipResetFlag = 1; + if (g_uchResetFromProtocolFlag == 1) + { + g_uchResetFromProtocolFlag = 0; + HOOK_FUNC_CALL(g_pGh3x2xResetByProtocolHookFunc, () ); /* call hook */ + } + return chRet; +} + +/** + * @fn void GH3X2X_WearDetectEnable(EMWearDetectEnableType emWearDetectEnable) + * + * @brief enable or disable wear detect + * + * @attention None + * + * @param[in] emWearDetectEnable enable or disable @ref EMWearDetectEnableType + * @param[out] None + * + * @return None + */ +void GH3X2X_WearDetectEnable(EMWearDetectEnableType emWearDetectEnable) +{ + GU16 usWearStatus = 0; + + GH3X2X_WAIT_CHIP_WAKEUP(); + usWearStatus = GH3X2X_ReadReg(GH3X2X_ADT_WEARON_CR_REG_ADDR); + + if (WEAR_DETECT_ENABLE == emWearDetectEnable) + { + GH3X2X_VAL_SET_BIT(usWearStatus, GH3X2X_ADT_WEAR_DET_EN_MASK_BIT); + } + else + { + GH3X2X_VAL_CLEAR_BIT(usWearStatus, (GU16)GH3X2X_ADT_WEAR_DET_EN_MASK_BIT); + } + + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, usWearStatus); + GH3X2X_WAIT_CHIP_DSLP(); +} + +/** + * @fn void GH3X2X_ResetHardAdt(void) + * + * @brief Gh3x2x reset hard adt + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_ResetHardAdt(void) +{ + /* clear int status. restart adt */ + GH3X2X_ExitLowPowerMode(); + GH3X2X_WriteRegBitField(GH3X2X_ADT_WEARON_CR_REG_ADDR,0,0,0); + GH3X2X_WriteReg(GH3X2X_INT_STR_REG_ADDR, GH3X2X_IRQ_MSK_WEAR_ON_BIT | GH3X2X_IRQ_MSK_WEAR_OFF_BIT); + GH3X2X_WriteRegBitField(GH3X2X_ADT_WEARON_CR_REG_ADDR,0,0,1); + GH3X2X_EnterLowPowerMode(); +} + + +/** + * @fn GS8 GH3X2X_WearDetectSwitchTo(EMWearDetectType emWearDetectType, EMWearDetectForceSwitch emForceSwitch) + * + * @brief Gh3x2x switch to detect wear on/off type + * + * @attention Should follow that use WEAR_DETECT_DONT_FORCE_SWITCH @wear on/off irq status process. + * If want force switch to detect on/off, should use WEAR_DETECT_FORCE_SWITCH. careful!!! + * + * @param[in] emWearDetectType switch to detect type @ref EMWearDetectType + * @param[in] emForceSwitch force switch type @ref EMWearDetectForceSwitch + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR detect type equal last type, don't need to switch + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_WearDetectSwitchTo(EMWearDetectType emWearDetectType, EMWearDetectForceSwitch emForceSwitch) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GU16 usWearStatus = 0; + GU16 usWearLogicSel = 0; + + GH3X2X_DEBUG_LOG_PARAM("%s:type = %d\r\n", __FUNCTION__, emWearDetectType); + if (emWearDetectType > WEAR_DETECT_WEAR_OFF) + { + GH3X2X_DEBUG_LOG_PARAM("param set error! @ref EMWearDetectType\r\n"); + chRet = GH3X2X_RET_PARAMETER_ERROR; + } + else + { + GH3X2X_WAIT_CHIP_WAKEUP(); + usWearStatus = GH3X2X_ReadReg(GH3X2X_ADT_WEARON_CR_REG_ADDR); + GH3X2X_DEBUG_LOG_PARAM("[GH3X2X_WearDetectSwitchTo] usWearStatus = %d\r\n",(int)usWearStatus); + if (emWearDetectType == WEAR_DETECT_WEAR_ON) // switch to detect wear on (got wear off evt) + { + if ((GH3X2X_CHECK_BIT_SET(usWearStatus, GH3X2X_ADT_WEAR_STATUS_MASK_BIT)) \ + || (emForceSwitch != WEAR_DETECT_DONT_FORCE_SWITCH)) // system is wear on + { + GH3X2X_DEBUG_LOG_PARAM("[GH3X2X_WearDetectSwitchTo] WEAR_DETECT_WEAR_ON\r\n"); +#if (GH3X2X_WEAR_ON_FORCE_SWITCH_WITH_LOGIC_SEL) // wear on force switch with adt logic sel + GH3X2X_VAL_CLEAR_BIT(usWearStatus, (GU16)GH3X2X_ADT_WEAR_STATUS_MASK_BIT); + if (emForceSwitch != WEAR_DETECT_DONT_FORCE_SWITCH) + { + usWearLogicSel = GH3X2X_ReadReg(GH3X2X_ADT_WEARON_LOGIC_SEL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_LOGIC_SEL_REG_ADDR, 0); // clear all logic + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, usWearStatus); // set system into wear off + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, \ + GH3X2X_SET_BIT(usWearStatus, GH3X2X_ADT_WEAR_CR_WEAR_ON_VAL)); + GH3X2X_DelayUs(GH3X2X_WEAR_DETECT_SWITCH_WAIT_X_US); + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_LOGIC_SEL_REG_ADDR, usWearLogicSel); // re-sel wear on logic + } + else + { + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, usWearStatus); // set system into wear off + } +#else + GH3X2X_VAL_CLEAR_BIT(usWearStatus, (GU16)GH3X2X_ADT_WEAR_STATUS_MASK_BIT); + if ((GH3X2X_CHECK_BIT_SET(usWearStatus, GH3X2X_ADT_WEAR_DET_EN_MASK_BIT)) + && (emForceSwitch != WEAR_DETECT_DONT_FORCE_SWITCH)) + { + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, \ + GH3X2X_CLEAR_BIT(usWearStatus, GH3X2X_ADT_WEAR_DET_EN_MASK_BIT)); + + GH3X2X_DEBUG_LOG_PARAM("[GH3X2X_WearDetectSwitchTo] write det en to 0 !!!\r\n"); + } + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, usWearStatus); // set system into wear off + + GH3X2X_DEBUG_LOG_PARAM("[GH3X2X_WearDetectSwitchTo] usWearStatus = %d\r\n",(int)usWearStatus); + + +#endif + chRet = GH3X2X_RET_OK; + } // end of if (GH3X2X_CHECK_BIT_SET(usWearStatus, GH3X2X_ADT_WEAR_STATUS_MASK_BIT)) + } // end of if (emWearDetectType == WEAR_DETECT_WEAR_ON) + else // switch to detect wear off (got wear on evt) + { + if (GH3X2X_CHECK_BIT_NOT_SET(usWearStatus, GH3X2X_ADT_WEAR_STATUS_MASK_BIT) \ + || (emForceSwitch != WEAR_DETECT_DONT_FORCE_SWITCH)) // system is wear off + { + GH3X2X_DEBUG_LOG_PARAM("[GH3X2X_WearDetectSwitchTo] WEAR_DETECT_WEAR_OFF\r\n"); + GH3X2X_VAL_SET_BIT(usWearStatus, GH3X2X_ADT_WEAR_STATUS_MASK_BIT); + if (emForceSwitch != WEAR_DETECT_DONT_FORCE_SWITCH) + { + usWearLogicSel = GH3X2X_ReadReg(GH3X2X_ADT_WEAROFF_LOGIC_SEL_REG_ADDR); + GH3X2X_WriteReg(GH3X2X_ADT_WEAROFF_LOGIC_SEL_REG_ADDR, 0); // clear all logic + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, usWearStatus); // set system into wear on + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, \ + GH3X2X_SET_BIT(usWearStatus, GH3X2X_ADT_WEAR_CR_WEAR_OFF_VAL)); + GH3X2X_DelayUs(GH3X2X_WEAR_DETECT_SWITCH_WAIT_X_US); + GH3X2X_WriteReg(GH3X2X_ADT_WEAROFF_LOGIC_SEL_REG_ADDR, usWearLogicSel); // re-sel wear off logic + } + else + { + GH3X2X_WriteReg(GH3X2X_ADT_WEARON_CR_REG_ADDR, usWearStatus); // set system into wear on + } + chRet = GH3X2X_RET_OK; + } + } + GH3X2X_WAIT_CHIP_DSLP(); + } // end of else if (emWearDetectType > WEAR_DETECT_WEAR_OFF) + return chRet; +} + +/** + * @fn EMSkinColorStatusType GH3X2X_GetSkinStatus(void) + * + * @brief Get gh3x2x skin color status + * + * @attention Must using when chip hard wear detect module enable, if not always return 0 + * + * @param[in] None + * @param[out] None + * + * @return skin color status @ref EMSkinColorStatusType + */ +EMSkinColorStatusType GH3X2X_GetSkinStatus(void) +{ + GU16 usSkinStatus = 0; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + GH3X2X_WAIT_CHIP_WAKEUP(); + usSkinStatus = GH3X2X_ReadReg(GH3X2X_SKIN_STR_REG_ADDR); + GH3X2X_WAIT_CHIP_DSLP(); + return ((EMSkinColorStatusType) GH3X2X_VAL_GET_BIT(usSkinStatus, GH3X2X_SKIN_COLOR_STATUS_MASK_BIT)); +} + +/** + * @fn GS8 GH3X2X_HsiClockCalibration(void) + * + * @brief Calibration Hsi(high-speed internal) clock + * + * @attention must use 4M clock input @OSCIN pin + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR input clock is unstable, or sampling was started + */ +GS8 GH3X2X_HsiClockCalibration(void) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (g_uchGh3x2xStatus < GH3X2X_STATUS_STARTED) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + GH3X2X_WriteReg(GH3X2X_OSC_THR_REG_ADDR, GH3X2X_HSI_CALI_THR_CNT_VAL); + GH3X2X_WriteReg(GH3X2X_OSC_CR_REG_ADDR, GH3X2X_HSI_CALI_CTRL_EN_VAL); + GH3X2X_DelayUs(GH3X2X_HSI_CALI_DELAY_VAL); + if (GH3X2X_CHECK_BIT_SET(GH3X2X_ReadReg(GH3X2X_OSC_FLAG_REG_ADDR), GH3X2X_OSC_CALI_CODE_LOACKED)) + { + chRet = GH3X2X_RET_OK; + } + GH3X2X_DEBUG_LOG_PARAM("Hsi: 0x%.4x\r\n", GH3X2X_ReadReg(GH3X2X_OSC13M_TUNE_REG_ADDR)); + GH3X2X_WriteReg(GH3X2X_OSC_CR_REG_ADDR, GH3X2X_OSC_CALI_CTRL_DIS_VAL); + GH3X2X_WAIT_CHIP_DSLP(); + } + + return chRet; +} + +/** + * @fn GS8 GH3X2X_LsiClockCalibration(void) + * + * @brief Calibration Lsi(low-speed internal) clock + * + * @attention must use 4M clock input @OSCIN pin, take case that will consume about 100ms + * + * @param[in] None + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR input clock is unstable, or sampling was started + */ +GS8 GH3X2X_LsiClockCalibration(void) +{ + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + GU16 usCaliVal = 0; + GS16 sFreqErrVal = 0; + GS16 sLastFreqErrVal = GH3X2X_LSI_CALI_ERR_MAX_VAL; + GU8 uchIndex = 0; + GU8 uchMinVal = 0; + GU8 uchMaxVal = GH3X2X_LSI_CALI_FINE_VAL_MAX; + GU8 uchCalcVal = 0; + GU8 uchLastCalcVal = GH3X2X_LSI_CALI_FINE_VAL_MAX; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (g_uchGh3x2xStatus < GH3X2X_STATUS_STARTED) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + GH3X2X_WriteReg(GH3X2X_OSC_THR_REG_ADDR, GH3X2X_LSI_CALI_THR_CNT_VAL); + GH3X2X_WriteReg(GH3X2X_OSC_CR_REG_ADDR, GH3X2X_LSI_CALI_CTRL_C_EN_VAL); + GH3X2X_DelayUs(GH3X2X_LSI_COR_CALI_DELAY_VAL); + if (GH3X2X_CHECK_BIT_SET(GH3X2X_ReadReg(GH3X2X_OSC_FLAG_REG_ADDR), GH3X2X_OSC_CALI_CODE_LOACKED)) + { + usCaliVal = GH3X2X_ReadReg(GH3X2X_OSC32K_TUNE_REG_ADDR); + uchCalcVal = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usCaliVal); + for (uchIndex = 0; uchIndex < GH3X2X_LSI_CALI_FINE_TUNE_MAX; uchIndex++) + { + usCaliVal = GH3X2X_MAKEUP_WORD(uchCalcVal, GH3X2X_GET_LOW_BYTE_FROM_WORD(usCaliVal)); + GH3X2X_WriteReg(GH3X2X_OSC32K_TUNE_REG_ADDR, usCaliVal); + GH3X2X_WriteReg(GH3X2X_OSC_CR_REG_ADDR, GH3X2X_LSI_CALI_CTRL_F_EN_VAL); + GH3X2X_DelayUs(GH3X2X_LSI_FINE_CALI_DELAY_VAL); + sFreqErrVal = GH3X2X_ReadReg(GH3X2X_OSC_FREQ_ERR_UR_REG_ADDR); + if (sFreqErrVal > GH3X2X_LSI_CALI_ERR_MAX_VAL) + { + sFreqErrVal = (GS16)(GH3X2X_LSI_CALI_ERR_FIXED_VAL - sFreqErrVal); + uchMinVal = uchCalcVal; + } + else + { + uchMaxVal = uchCalcVal; + } + uchCalcVal = ((GU16)uchMaxVal + (GU16)uchMinVal) / GH3X2X_LSI_CALI_FINE_DIV_NUM; + if (uchLastCalcVal == uchCalcVal) + { + chRet = GH3X2X_RET_OK; + if (sLastFreqErrVal < sFreqErrVal) + { + usCaliVal = GH3X2X_MAKEUP_WORD(uchMaxVal, GH3X2X_GET_LOW_BYTE_FROM_WORD(usCaliVal)); + GH3X2X_WriteReg(GH3X2X_OSC32K_TUNE_REG_ADDR, usCaliVal); + } + break; + } + uchLastCalcVal = uchCalcVal; + if (sLastFreqErrVal > sFreqErrVal) + { + sLastFreqErrVal = sFreqErrVal; + } + } // end of for (uchIndex = 0; uchIndex < GH3X2X_LSI_CALI_FINE_TUNE_MAX; uchIndex++) + } // end of if (GH3X2X_CHECK_BIT_SET(GH3X2X_ReadReg(GH3X2X_OSC_FLAG_REG_ADDR), GH3X2X_OSC_CALI_CODE_LOACKED)) + GH3X2X_DEBUG_LOG_PARAM("Lsi: 0x%.4x\r\n", GH3X2X_ReadReg(GH3X2X_OSC32K_TUNE_REG_ADDR)); + GH3X2X_WriteReg(GH3X2X_OSC_CR_REG_ADDR, GH3X2X_OSC_CALI_CTRL_DIS_VAL); + GH3X2X_WAIT_CHIP_DSLP(); + } // end of if (g_uchGh3x2xStatus < GH3X2X_STATUS_STARTED) + return chRet; +} + +/** + * @fn void GH3X2X_RegisterReadPinStatusFunc(GU8 (*pReadIntPinStatusFunc)(void), + * GU8 (*pReadResetPinStatusFunc)(void), + * GU8 (*pReadSpcsPinStatusFunc)(void), + * GU8 (*pReadSpdoPinStatusFunc)(void)) + * + * @brief Register read pin status function + * + * @attention Only use for debug, read gh3x2x some pin status can debug some hardware errors; + * Pin status return should define as 1 [high level] or 0 [low level]; + * + * @param[in] pReadIntPinStatusFunc pointer to read int pin staus function + * @param[in] pReadResetPinStatusFunc pointer to read reset pin staus function + * @param[in] pReadSpcsPinStatusFunc pointer to read spcs pin staus function + * @param[in] pReadSpdoPinStatusFunc pointer to read spdo pin staus function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterReadPinStatusFunc(GU8 (*pReadIntPinStatusFunc)(void), + GU8 (*pReadResetPinStatusFunc)(void), + GU8 (*pReadSpcsPinStatusFunc)(void), + GU8 (*pReadSpdoPinStatusFunc)(void)) +{ + g_pGh3x2xReadIntPinStatusFunc = pReadIntPinStatusFunc; + g_pGh3x2xReadResetPinStatusFunc = pReadResetPinStatusFunc; + g_pGh3x2xReadSpcsPinStatusFunc = pReadSpcsPinStatusFunc; + g_pGh3x2xReadSpdoPinStatusFunc = pReadSpdoPinStatusFunc; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); +} + +/** + * @fn GCHAR *GH3X2X_GetDriverLibVersion(void) + * + * @brief Get driver version + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return library version string + */ +GCHAR *GH3X2X_GetDriverLibVersion(void) +{ + return (GCHAR *)GH3X2X_VERSION_STRING; +} + +/** + * @fn void GH3X2X_SetMaxNumWhenReadFifo(GU16 usMaxNum) + * + * @brief Set max number of rawdata read from fifo every time + * + * @attention None. + * + * @param[in] usMaxNum max number of rawdata read from fifo + * @param[out] None + * + * @return None + */ +void GH3X2X_SetMaxNumWhenReadFifo(GU16 usMaxNum) +{ + if (usMaxNum <= GH3X2X_FIFO_DATA_BYTES_MAX_LEN) + { + g_usMaxNumReadFromFifo = (usMaxNum/4) * 4; + } +} + + +/** + * @fn GU16 GH3X2X_GetCurrentFifoWaterLine(void) + * + * @brief get current fifo water line setting + * + * @attention None. + * + * @param[in] None + * @param[out] fifo water line + * + * @return None + */ +GU16 GH3X2X_GetCurrentFifoWaterLine(void) +{ + return g_usCurrentFiFoWaterLine; +} + + + +const GU8 g_uchLedCurrentFullScal[4] = {25,50,100,200}; + + + + +/** + * @fn GU8 Gh3x2x_GetLedCurrentFullScal(void) + + * + * @brief + * + * @attention None. + * + * @param[in] None + * @param[out] Drv 0/1Current fs (mA) + * + * @return None + */ + +void GH3x2x_GetLedCurrentFullScal(GU8 *puchDrv0Fs, GU8 *puchDrv1Fs) +{ + (*puchDrv0Fs)= GH3X2X_ReadRegBitField(GH3X2X_LED_DRV_AD_REG_REG_ADDR,GH3X2X_DRV0_FULL_SCAL_CURRENT_LSB,GH3X2X_DRV0_FULL_SCAL_CURRENT_MSB); + (*puchDrv1Fs)= GH3X2X_ReadRegBitField(GH3X2X_LED_DRV_AD_REG_REG_ADDR,GH3X2X_DRV1_FULL_SCAL_CURRENT_LSB,GH3X2X_DRV1_FULL_SCAL_CURRENT_MSB); + + + (*puchDrv0Fs) = g_uchLedCurrentFullScal[*puchDrv0Fs]; + (*puchDrv1Fs) = g_uchLedCurrentFullScal[*puchDrv1Fs]; + +} + + + +void GH3x2x_DisableHardwareAgc(void) +{ + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + GH3X2X_WriteRegBitField(GH3X2X_SLOT0_CTRL_3_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotCnt,GH3X2X_SLOT_AGC_EN_LSB,GH3X2X_SLOT_AGC_EN_MSB, 0); + } +} + + +void GH3x2x_GetBgLevel(GU8 *puchBglevel) +{ + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + puchBglevel[uchSlotCnt] = GH3X2X_ReadRegBitField(GH3X2X_SLOT0_CTRL_3_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotCnt,GH3X2X_SLOT_BG_LEVEL_LSB,GH3X2X_SLOT_BG_LEVEL_MSB); + } +} + +void GH3x2x_GetBgCancel(GU8 *puchBgCancel) +{ + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + puchBgCancel[uchSlotCnt] = GH3X2X_ReadRegBitField(GH3X2X_SLOT0_CTRL_3_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotCnt,GH3X2X_SLOT_BG_CANCEL_LSB,GH3X2X_SLOT_BG_CANCEL_MSB); + } +} + + + +void GH3x2x_SetIntTime(GU8 uchSlotNo, GU8 uchIntTimeIndex) +{ + GH3X2X_WriteRegBitField(GH3X2X_SLOT0_CTRL_3_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotNo,GH3X2X_SLOT_ADC_INT_TIME_LSB,GH3X2X_SLOT_ADC_INT_TIME_MSB, uchIntTimeIndex); +} + +void GH3x2x_SetSlotTime(GU8 uchSlotNo, GU16 usSlotTime) +{ + GH3X2X_WriteReg(GH3X2X_RG_SLOT_TMR0_REG_ADDR + 2*uchSlotNo, usSlotTime); +} + + +void GH3x2x_SetSlotSampleRate(GU8 uchSlotNo, GU16 usSampleRate) +{ + GU16 usDivReg; + if(usSampleRate > 1000) + { + usSampleRate = 1000; + } + if(usSampleRate < 5) + { + usSampleRate = 5; + } + + usDivReg = (1000/usSampleRate) - 1; + + + GH3X2X_WriteRegBitField(GH3X2X_SLOT0_CTRL_0_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotNo,GH3X2X_SLOT_SR_LSB,GH3X2X_SLOT_SR_MSB, usDivReg); + + + GH3X2X_DEBUG_LOG_PARAM("GH3x2x_SetSlotSampleRate: uchSlotNo = %d, usSampleRate = %d, usDivReg = %d \r\n",(int)uchSlotNo,(int)usSampleRate,(int)usDivReg); +} + + + + + +const GU16 gusSlotTimeList[3][7] = { +{26, 36, 46, 56, 95, 174, 331}, +{48, 67, 87, 107, 186, 343, 658}, +{69, 99, 128, 158, 276, 512, 985} +}; + + +GU16 GH3x2x_CalSlotTime(GU8 uchBgLevel, GU8 uchBgCancel ,GU8 uchIntTimeIndex) +{ + GU16 usSlotTime; + if(uchBgLevel > 2) + { + uchBgLevel = 2; + } + usSlotTime = gusSlotTimeList[uchBgLevel][uchIntTimeIndex]; + if(uchBgCancel > 0) + { + usSlotTime += 104; + } + + usSlotTime += 80; //fix pd remain problem + + GH3X2X_DEBUG_LOG_PARAM("GH3x2x_CalSlotTime: bg level = %d, bg cancel = %d, IntTimeIndex = %d, TimeSlot = %d \r\n",(int)uchBgLevel,(int)uchBgCancel,(int)uchIntTimeIndex,(int)usSlotTime); + + return usSlotTime; +} + +GS8 g_chDrvECode = 0; + +void GH3X2X_SetDrvEcode(GS8 chECode) +{ + g_chDrvECode = chECode; +} + +#if (0 == __CURRENT_ECODE_CALIBRATE__) +GU16 GH3X2X_SetLedDrvCurrentByEcode(GU8 uchCurrent_mA, GU8 uchDrvNum, GS8 chECODE) +{ + GU8 uchDrFs[2] = {0}; + GH3x2x_GetLedCurrentFullScal(&uchDrFs[0], &uchDrFs[1]); + GU16 usDrvReg = ((GU16)uchCurrent_mA) * 255 /uchDrFs[uchDrvNum]; + return usDrvReg; +} +void GH3X2X_SetConfigDrvEcode(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam){} +#else +GU16 GH3X2X_SetLedDrvCurrentByEcode(GU8 uchCurrent_mA, GU8 uchDrvNum, GS8 chECODE) +{ + GF32 fEr; + GF32 fY; + GU8 uchN; + GU16 usDrvCode; + GU16 usDrvScale; + + if(uchDrvNum == 0) + { + fY = 0.1; + usDrvScale = GH3X2X_ReadRegBitField(GH3X2X_LED_DRV_AD_REG_REG_ADDR,GH3X2X_DRV0_FULL_SCAL_CURRENT_LSB,GH3X2X_DRV0_FULL_SCAL_CURRENT_MSB); + } + else + { + fY = 0.01; + usDrvScale = GH3X2X_ReadRegBitField(GH3X2X_LED_DRV_AD_REG_REG_ADDR,GH3X2X_DRV1_FULL_SCAL_CURRENT_LSB,GH3X2X_DRV1_FULL_SCAL_CURRENT_MSB); + + } + uchN = 1 << (3 - usDrvScale); + + fEr = (GF32)((GF32)chECODE/256) + 1.0f; + usDrvCode = (GU16)(0.5f+((GF32)fEr*255*(GF32)uchN)/(0.225f/((GF32)uchCurrent_mA/1000) - fY)); + + return usDrvCode; +} + +void GH3X2X_SetConfigDrvEcode(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam) +{ + if (pstGh3x2xInitConfigParam == GH3X2X_PTR_NULL) + { + return; + } + GU8 uchDr0Fs = 0; + GU8 uchDr1Fs = 0; + GH3x2x_GetLedCurrentFullScal(&uchDr0Fs, &uchDr1Fs); + for (GU16 usArrCnt = 0; usArrCnt < pstGh3x2xInitConfigParam->usConfigArrLen ; usArrCnt ++) + { + GU16 usRegData = pstGh3x2xInitConfigParam->pstRegConfigArr[usArrCnt].usRegData; + GU16 usRegAddr = pstGh3x2xInitConfigParam->pstRegConfigArr[usArrCnt].usRegAddr; + if ((pstGh3x2xInitConfigParam->pstRegConfigArr[usArrCnt].usRegAddr & 0xF000) == 0) + { + for (int uchSlotIndex = 0; uchSlotIndex < 8; uchSlotIndex++) + { + if ((pstGh3x2xInitConfigParam->pstRegConfigArr[usArrCnt].usRegAddr) == 0x011E + (uchSlotIndex * 0x001C) + (0 * 0x0002)) + { + GU8 uchCurrent = (GU8)((double)(usRegData&0xFF) * (double)uchDr0Fs / 255 + 0.5); + GU16 usDrv0Reg = ((usRegData & 0xFF00) | GH3X2X_SetLedDrvCurrentByEcode(uchCurrent, 0, g_chDrvECode)); + GH3X2X_INFO_LOG_PARAM("[%s]:slot%d DRV0 addr=0x%04x CURvalue=0x%04x change2 0x%04x\n", __FUNCTION__, uchSlotIndex, usRegAddr, usRegData, usDrv0Reg); + GH3X2X_WriteReg(pstGh3x2xInitConfigParam->pstRegConfigArr[usArrCnt].usRegAddr, usDrv0Reg); + if (usDrv0Reg != GH3X2X_ReadReg(usRegAddr)) + { + GH3X2X_INFO_LOG_PARAM("[%s]:reg verify error!!!\r\n", __FUNCTION__); + } + } + else if ((pstGh3x2xInitConfigParam->pstRegConfigArr[usArrCnt].usRegAddr) == 0x011E + (uchSlotIndex * 0x001C) + (1 * 0x0002)) + { + GU8 uchCurrent = (GU8)((double)(usRegData&0xFF) * (double)uchDr1Fs / 255 + 0.5); + GU16 usDrv1Reg = ((usRegData & 0xFF00) | GH3X2X_SetLedDrvCurrentByEcode(uchCurrent, 1, g_chDrvECode)); + GH3X2X_INFO_LOG_PARAM("[%s]:slot%d DRV1 addr=0x%04x CURvalue=0x%04x change2 0x%04x\n", __FUNCTION__, uchSlotIndex, usRegAddr, usRegData, usDrv1Reg); + GH3X2X_WriteReg(pstGh3x2xInitConfigParam->pstRegConfigArr[usArrCnt].usRegAddr, usDrv1Reg); + if (usDrv1Reg != GH3X2X_ReadReg(usRegAddr)) + { + GH3X2X_INFO_LOG_PARAM("[%s]:reg verify error!!!\r\n", __FUNCTION__); + } + } + } + } + } +} + +#endif + + + +/** + * @fn void GH3x2x_ChangeSampleParmForEngineeringMode(GU32 unFunctionMode, STGh3x2xEngineeringModeSampleParam *pstSampleParaGroup , GU8 uchSampleParaGroupNum) + + * + * @brief + * + * @attention None. + * + * @param[in] unFunctionMode: function group exp: GH3X2X_FUNCTION_ADT|GH3X2X_FUNCTION_HR + * @param[in] pstSampleParaGroup the pointer of engineering mode sample param group struct array base + * @param[in] uchSampleParaGroupNum engineering mode sample param group number + * @param[out] None + * + * @return None + */ +void GH3x2x_ChangeSampleParmForEngineeringMode(const STGh3x2xFrameInfo * const pstGh3x2xFrameInfo[], GU32 unFunctionMode, STGh3x2xEngineeringModeSampleParam *pstSampleParaGroup , GU8 uchSampleParaGroupNum) +{ + GU32 unFunctionID; + GU8 uchFunctionCnt; + GU8 *puchChnlMap; + GU8 uchChnlNum; + GU8 uchDr0Fs; + GU8 uchDr1Fs; + GU8 puchBglevel[8]; //slot0 ~ slot1 bg level + GU8 puchBgCancel[8]; //slot0 ~ slot1 bg cancel + + if(0 == pstSampleParaGroup) //is the point is invalid, do nothing + { + return ; + } + + //read current full scale + GH3x2x_GetLedCurrentFullScal(&uchDr0Fs, &uchDr1Fs); + + //read bg level + GH3x2x_GetBgLevel(puchBglevel); + + //read bg cancel + GH3x2x_GetBgCancel(puchBgCancel); + + //disable all hardware age slot + GH3x2x_DisableHardwareAgc(); + + + + //process every sample parm group + for(GU8 uchSampleParaGroupCnt = 0; uchSampleParaGroupCnt < uchSampleParaGroupNum; uchSampleParaGroupCnt ++) + { + STGh3x2xEngineeringModeSampleParam *pstTempSampleParam = pstSampleParaGroup + uchSampleParaGroupCnt; + unFunctionID = pstTempSampleParam->unFunctionID; + if(0 == unFunctionID) + { + continue; + } + puchChnlMap = 0; + uchChnlNum = 0; + + if(unFunctionID == (unFunctionMode&unFunctionID)) //unFunctionMode have cover unFunctionID + { + // get channl map and chnl num + for (uchFunctionCnt = 0 ; uchFunctionCnt < GH3X2X_FUNC_OFFSET_MAX ; uchFunctionCnt ++) + { + if(pstGh3x2xFrameInfo[uchFunctionCnt]) + { + if(unFunctionID == (((GU32)1) << uchFunctionCnt)) + { + break; + } + } + } + if(GH3X2X_FUNC_OFFSET_MAX == uchFunctionCnt) + { + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParmForEngineeringMode: can not find valid pstGh3x2xFrameInfo !!! unFunctionID = %d\r\n", (int)unFunctionID); + continue; + } + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParmForEngineeringMode: pstGh3x2xFrameInfo uchFunctionCnt = %d\r\n", (int)uchFunctionCnt); + puchChnlMap = pstGh3x2xFrameInfo[uchFunctionCnt]->pchChnlMap; + uchChnlNum = pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->uchChnlNum; + + if((0 != puchChnlMap)&&(0 != uchChnlNum)) //channel map and channel num is all valid + { + + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParmForEngineeringMode: ParaGroupCnt = %d, uchFunctionID = %d, uchChnlNum = %d\r\n", (int)uchSampleParaGroupCnt, (int)unFunctionID, (int)uchChnlNum); + for(GU8 uchChnlCnt = 0; uchChnlCnt < uchChnlNum; uchChnlCnt ++) + { + GU8 uchTempSlotNo = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(puchChnlMap[uchChnlCnt]); + GU8 uchTempAdtNo = GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(puchChnlMap[uchChnlCnt]); + if(pstTempSampleParam->uchIntTimeChangeEn) + { + GU16 usTimeSlot; + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParm[int time]: need change int time. \r\n"); + usTimeSlot = GH3x2x_CalSlotTime(puchBglevel[uchTempSlotNo],puchBgCancel[uchTempSlotNo], pstTempSampleParam->uchIntTime); + GH3x2x_SetIntTime(uchTempSlotNo,pstTempSampleParam->uchIntTime); + GH3x2x_SetSlotTime(uchTempSlotNo,usTimeSlot); + } + if(pstTempSampleParam->uchSampleRateChangeEn) + { + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParm[sample rate]\r\n"); + + GH3x2x_SetSlotSampleRate(uchTempSlotNo,pstTempSampleParam->usSampleRate); + } + if(pstTempSampleParam->uchTiaGainChangeEn) + { + GH3X2X_SlotLedTiaGainConfig(uchTempSlotNo, uchTempAdtNo, pstTempSampleParam->uchTiaGain[uchChnlCnt]); + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParm[tia gain]: uchSlotNo = %d, uchTempAdtNo = %d, TiaGain = %d \r\n",(int)uchTempSlotNo,(int)uchTempAdtNo,(int)pstTempSampleParam->uchTiaGain[uchChnlCnt]); + } + if(pstTempSampleParam->uchLedCurrentChangeEn) + { + + GU16 usDrv0Reg; + + GU16 usDrv1Reg; + + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParm[led current]\r\n"); + + usDrv0Reg = GH3X2X_SetLedDrvCurrentByEcode(pstTempSampleParam->uchLedDrv0Current[uchChnlCnt], 0, (GS8)g_chDrvECode); + //usDrv0Reg = ((GU16)pstTempSampleParam->uchLedDrv0Current[uchChnlCnt]) * 255 /uchDr0Fs; + + if(usDrv0Reg > 255) + { + usDrv0Reg = 255; + } + + usDrv1Reg = GH3X2X_SetLedDrvCurrentByEcode(pstTempSampleParam->uchLedDrv1Current[uchChnlCnt], 1, (GS8)g_chDrvECode); + //usDrv1Reg = ((GU16)pstTempSampleParam->uchLedDrv1Current[uchChnlCnt]) * 255 /uchDr1Fs; + + if(usDrv1Reg > 255) + { + usDrv1Reg = 255; + } + + GH3X2X_SlotLedCurrentConfig(uchTempSlotNo, 0, usDrv0Reg); + GH3X2X_SlotLedCurrentConfig(uchTempSlotNo, 1, usDrv1Reg); + + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParmForEngineeringMode: uchSlotNo = %d, uchTempAdtNo = %d, Drv0 = %d mA, Drv1 = %d mA \r\n",(int)uchTempSlotNo,(int)uchTempAdtNo,(int)pstTempSampleParam->uchLedDrv0Current[uchChnlCnt],(int)pstTempSampleParam->uchLedDrv1Current[uchChnlCnt]); + GH3X2X_DEBUG_LOG_PARAM("ChangeSampleParmForEngineeringMode: Drv0_reg = %d, Drv1_reg = %d \r\n",(int)usDrv0Reg,(int)usDrv1Reg); + } + + } + + + } + + + + } + } + + +} + +/** + * @fn GU8 GH3x2x_GetActiveChipResetFlag(void) + + + * + * @brief + * + * @attention None. + * + * @param[in] None + * @param[out] ActiveChipResetFlag 1: user have done chip reset(soft reset and hardwear reset) actively gh3x2x_init will clear it + * + * @return None + */ +GU8 GH3x2x_GetActiveChipResetFlag(void) +{ + return g_uchActiveChipResetFlag; +} + + +/** + * @fn GU8 GH3x2x_GetChipResetRecoveringFlag(void) + + + * + * @brief + * + * @attention None. + * + * @param[in] None + * @param[out] chip reset recovering flag 0: is not in chip reset recovering flag 1: is in chip reset recovering + * + * @return None + */ +GU8 GH3x2x_GetChipResetRecoveringFlag(void) +{ + return g_uchChipResetRecoveringFlag; +} + + + +/** + * @fn GU8 GH3x2x_SetChipResetRecoveringFlag(void) + + + * + * @brief + * + * @attention None. + * + * @param[in] chip reset recovering flag 0: is not in chip reset recovering flag 1: is in chip reset recovering + * @param[out] None + * + * @return None + */ +void GH3x2x_SetChipResetRecoveringFlag(GU8 uchChipResetRecoeringFlag) +{ + g_uchChipResetRecoveringFlag = uchChipResetRecoeringFlag; +} + + + + + + + + + + + + + + +void GH3x2xCreatTagArray(GU8 *puchTagArray, GU16 usArrayLen,GU32 *unCompeletMask, const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GU8 uchChnlNum; + GU8 *puchChnlMap; + + uchChnlNum = pstFrameInfo->pstFunctionInfo->uchChnlNum; + puchChnlMap = pstFrameInfo->pchChnlMap; + + //create tag array + GH3X2X_Memset(puchTagArray,0xFF,usArrayLen); + + for(GU8 uchChnlCnt = 0; uchChnlCnt < uchChnlNum; uchChnlCnt ++) + { + GU8 uchTag; + uchTag = puchChnlMap[uchChnlCnt] >> 3; + puchTagArray[uchTag] = uchChnlCnt; + } + //crete compelet mask + (*unCompeletMask) = ((((long long)1) << uchChnlNum) - 1)&pstFrameInfo->pstFunctionInfo->unChnlEnForUserSetting; +} + + + + + + +GU16 GH3x2xGetFrameNum(GU8 *puchRawdataBuf, GU16 usRawDataByteLen, const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GU32 unTempIncompeletFlag; + GU8 puchTagArray[32]; + GU32 unCompeletMask; + GU16 usFrameNum = 0; + + + unTempIncompeletFlag = *(pstFrameInfo->punIncompleteChnlMapBit); + + GH3x2xCreatTagArray(puchTagArray, 32,&unCompeletMask, pstFrameInfo); + + //set incomplete flag + for (GU16 usSearchStartPosi = 0; usSearchStartPosi < usRawDataByteLen; usSearchStartPosi += GH3X2X_FIFO_RAWDATA_SIZE) + { + GU8 uchTag; + GU8 uchChnlId; + uchTag = puchRawdataBuf[usSearchStartPosi] >> 3; + uchChnlId = puchTagArray[uchTag]; + if(0xFF != uchChnlId) + { + unTempIncompeletFlag |= (1 << uchChnlId); + } + + if(unCompeletMask == (unCompeletMask&unTempIncompeletFlag)) //got one frame + { + unTempIncompeletFlag = 0; + usFrameNum ++; + } + + } + + return usFrameNum; + +} + + +float GH3x2xCalGsensorStep(GU16 usGsDataNum, GU16 usFrameNum) +{ + float fGsensorStep = 0; + + if ((usFrameNum > 0) && (usGsDataNum > 0)) // calc gs index + { + fGsensorStep = ((GF32)(usGsDataNum)) / (usFrameNum); + } + + return fGsensorStep; + + +} + +void GH3x2xSendAllVersion(void) +{ + GU8 uchPacketPayloadArr[240] = {0}; + GU8 uchCmdArr[7 + GH3X2X_FUNC_OFFSET_MAX] = {(0x01),(0x0B),(0x0C),(0x0E),(0x0F),(0x10),(0x11)}; + GU8 uchCmdLen = 7; + + if (g_uchAlgoEnableFlag) + { + for (int nCnt = 0 ; nCnt < GH3X2X_FUNC_OFFSET_MAX ; nCnt++) + { + uchCmdArr[7 + nCnt] = 0x12 + nCnt; + } + uchCmdLen = 7 + GH3X2X_FUNC_OFFSET_MAX; + } + + for (GU8 uchOffset = 0 ; uchOffset < uchCmdLen ; uchOffset ++) + { + GU8 uchGetVersionType = UPROTOCOL_GET_VER_TYPE_ALGO_VER + uchOffset; + GCHAR pszVersionString[150] = {0}; + GH3X2X_GetVersion(uchCmdArr[uchOffset], pszVersionString); + GU8 uchVersionStringLen = (GU8)GH3X2X_Strlen(pszVersionString); + uchPacketPayloadArr[UPROTOCOL_GET_VER_TYPE_INDEX + 4] = uchGetVersionType; + uchPacketPayloadArr[UPROTOCOL_GET_VER_STRING_LEN_INDEX + 4] = uchVersionStringLen; + GH3X2X_Memcpy((GCHAR *)&uchPacketPayloadArr[UPROTOCOL_GET_VER_STRING_INDEX + 4], pszVersionString, uchVersionStringLen); + GU16 usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_BP_DATA_TRANS, uchPacketPayloadArr, &uchPacketPayloadArr[4], uchVersionStringLen + 2); + Gh3x2xDemoSendProtocolData(uchPacketPayloadArr,usRespondLen); + } +} + + +GU8 Gh3x2xFunctionID2Offset(GU32 unFunctionID) +{ + for(GU8 uchOffset = 0; uchOffset < 32; uchOffset ++) + { + if(unFunctionID == (((GU32)1) << uchOffset)) + { + return uchOffset; + } + } + return 0; +} + +void Gh3x2xFunctionInfoForUserInit(void) +{ + for(GU8 uchFuncitonCnt = 0; uchFuncitonCnt < GH3X2X_FUNC_OFFSET_MAX; uchFuncitonCnt ++) + { + if(g_pstGh3x2xFrameInfo[uchFuncitonCnt]) + { + g_pstGh3x2xFrameInfo[uchFuncitonCnt] -> pstFunctionInfo -> usSampleRateForUserSetting = 0; + g_pstGh3x2xFrameInfo[uchFuncitonCnt] -> pstFunctionInfo -> unChnlEnForUserSetting = 0xFFFFFFFF; + } + } +} + +void GH3x2xHandleFrameData(const STGh3x2xFrameInfo * const pstFrameInfo, GU32 *punTempIncompeletFlag, + GU32 *punFunctionID, GU8 uchChnlNum, GU8 *puchRawdataBuf, GU32 *punFrameRawdata, + GU8 *puchTag, GS16 *pusGsValueArr, float fGsensorIndex, + STCapRawdata* pstCapValueArr,float fCapIndex,STTempRawdata* pstTempValueArr,float fTempIndex) + +{ + GU32 unTempIncompeletFlag = *punTempIncompeletFlag; + GU8 uchTag = *puchTag; + GU32 unFunctionID = *punFunctionID; + GU8 uchGyroEnable = g_uchGyroEnable; + + GH3X2X_DEBUG_LOG_PARAM("[%s]got one frame,funcID = %d\r\n",__FUNCTION__,(int)unFunctionID); + unTempIncompeletFlag = 0; + GH3X2X_Memset((GU8*)(pstFrameInfo->punFrameFlag), 0, GH3X2X_FRAME_FLAG_NUM*4); //clear flag + GH3X2X_Memset((GU8*)(pstFrameInfo ->pstAlgoResult), 0, sizeof(STGh3x2xAlgoResult)); //clear result + GH3X2X_Memset((GU8*)(pstFrameInfo ->punFrameAgcInfo), 0, uchChnlNum * 4); //clear agc info + + for(GU8 uchChnlCnt = 0; uchChnlCnt < uchChnlNum; uchChnlCnt ++) + { + GU32 unRawdataAndTag; + unRawdataAndTag = pstFrameInfo->punIncompleteRawdata[uchChnlCnt]; + uchTag = GH3X2X_DWORD_RAWDATA_GET_SLOT_ADC_NUM(unRawdataAndTag); + + //rawdata + punFrameRawdata[uchChnlCnt] = unRawdataAndTag&0x00FFFFFF; + + //flag0 flag1 + pstFrameInfo->punFrameFlag[0] |= (((GU32)GH3X2X_RAWDATA_GET_ADJ_FLAG0(unRawdataAndTag) << uchChnlCnt)); + pstFrameInfo->punFrameFlag[1] |= (((GU32)GH3X2X_RAWDATA_GET_ADJ_FLAG1(unRawdataAndTag) << uchChnlCnt)); + + //flag2 bit 0 fast recovery flag + if ((GH3X2X_FUNCTION_ECG == unFunctionID)||(GH3X2X_FUNCTION_PWTT == unFunctionID)) + { + if(0 == uchChnlCnt) + { + if(GH3X2X_RAWDATA_GET_FAST_RECOVERY_FLAG(unRawdataAndTag)) + { + pstFrameInfo->punFrameFlag[2] |= 0x01; + } + } + } + + #if GH3X2X_DIVIDE_ZERO_FLAG_UPLODE_EN + //flag4 + if(g_uchChipDivZeroFlag) + { + pstFrameInfo->punFrameFlag[4] |= 0x01; + GH3X2X_ClearDivZeroFlag(); + } + #endif + + // agc (gain/drv0/drv1) + pstFrameInfo->punFrameAgcInfo[uchChnlCnt] |= g_pstGh3x2xAgcInfo->uchTiaGainRecord[uchTag] & 0xF; //gain + pstFrameInfo->punFrameAgcInfo[uchChnlCnt] |= ((GU32)g_pstGh3x2xAgcInfo->uchDrvCurrentRecord[(GU8)(uchTag/4)]) << 8; // drv 0/1 current + + } + + //g-sensor + for( int i=0;i<3;i++) + { + if(fGsensorIndex != (GU16)fGsensorIndex) + { + pstFrameInfo->pusFrameGsensordata[i] = pusGsValueArr[(GU16)fGsensorIndex*(3+3*uchGyroEnable)+i]*(1-fGsensorIndex+(GU16)fGsensorIndex) + pusGsValueArr[((GU16)fGsensorIndex+1)*(3+3*uchGyroEnable)+i]*(fGsensorIndex-(GU16)fGsensorIndex); + } + else + { + pstFrameInfo->pusFrameGsensordata[i] = pusGsValueArr[(GU16)fGsensorIndex*(3+3*uchGyroEnable)+i]; + } + } + if(uchGyroEnable) + { + for( int i=0;i<3;i++) + { + if(fGsensorIndex != (GU16)fGsensorIndex) + { + pstFrameInfo->pusFrameGsensordata[i+3] = pusGsValueArr[(GU16)fGsensorIndex*(3+3*uchGyroEnable)+i+3]*(1-fGsensorIndex+(GU16)fGsensorIndex) + pusGsValueArr[((GU16)fGsensorIndex+1)*(3+3*uchGyroEnable)+i+3]*(fGsensorIndex-(GU16)fGsensorIndex); + } + else + { + pstFrameInfo->pusFrameGsensordata[i+3] = pusGsValueArr[(GU16)fGsensorIndex*(3+3*uchGyroEnable)+i+3]; + } + } + } + //cap and temp + if(GH3X2X_GetCapEnableFlag()) + { + GH3X2X_Memcpy(pstFrameInfo->pstFrameCapdata,&pstCapValueArr[(GU16)fCapIndex],sizeof(STCapRawdata)); + } + if(GH3X2X_GetTempEnableFlag()) + { + GH3X2X_Memcpy(pstFrameInfo->pstFrameTempdata,&pstTempValueArr[(GU16)fTempIndex],sizeof(STTempRawdata)); + } + + //flag 2 bit1 first frame flag + + Gh3x2xSetFrameFlag2(pstFrameInfo); + /* + pstFrameInfo->punFrameFlag[2] &= (~(((GU32)1) << 1)); + if(0 == (*(pstFrameInfo->punFrameCnt))) + { + pstFrameInfo->punFrameFlag[2] |= 0x02; + } + */ + if(GH3X2X_FUNCTION_SOFT_ADT_IR == unFunctionID) + { + pstFrameInfo->punFrameFlag[2] |= ((GU32)1)<<4; + } + + GH3X2X_DEBUG_LOG_PARAM("[GetFrameData] function id: 0x%X, rawdata0 = %d, rawdata1 = %d\r\n",(int)pstFrameInfo->unFunctionID, (int)(pstFrameInfo->punFrameRawdata[0]), (int)(pstFrameInfo->punFrameRawdata[1])); + + GH3X2X_DEBUG_LOG_PARAM("[GetFrameData] TimeStamp = %d\r\n",(int)(*(pstFrameInfo->punFrameCnt))); + + + //call algo 2-level interface + unFunctionID = pstFrameInfo->unFunctionID; + pstFrameInfo->pstAlgoResult->uchUpdateFlag = 0; + + //get algo io data hook + HOOK_FUNC_CALL(g_pGh3x2xGetIoStructInfoHookFunc, (pstFrameInfo)); + + SET_VAL_VIA_PTR(punFunctionID, unFunctionID); + SET_VAL_VIA_PTR(puchTag, uchTag); + SET_VAL_VIA_PTR(punTempIncompeletFlag, unTempIncompeletFlag); +} + +void GH3x2xGetFrameDataAndProcess(GU8 *puchRawdataBuf, GU16 usRawDataByteLen, + GS16 *pusGsValueArr, GU16 usGsDataNum,STCapRawdata* pstCapValueArr,GU16 usCapDataNum,STTempRawdata* pstTempValueArr,GU16 usTempDataNum, + const STGh3x2xFrameInfo * const pstFrameInfo, float fGensorStep, float fCapStep, float fTempStep, GU16 usFrameNum) +{ + GU32 unTempIncompeletFlag; + GU8 puchTagArray[32]; + GU8 uchChnlNum; + GU32 unCompeletMask; + GU32 *punFrameRawdata; + float fGsensorIndex = 0; + float fCapIndex = 0; + float fTempIndex = 0; + GU32 unFunctionID; + GU16 usFrameCnt = 0; + + unTempIncompeletFlag = *(pstFrameInfo->punIncompleteChnlMapBit); + uchChnlNum = pstFrameInfo->pstFunctionInfo->uchChnlNum; + punFrameRawdata = pstFrameInfo->punFrameRawdata; + unFunctionID = pstFrameInfo->unFunctionID; + + GH3x2xCreatTagArray(puchTagArray, 32, &unCompeletMask, pstFrameInfo); + + //set incomplete flag + for (GU16 usSearchStartPosi = 0; usSearchStartPosi < usRawDataByteLen; usSearchStartPosi += GH3X2X_FIFO_RAWDATA_SIZE) + { + GU8 uchTag; + GU8 uchChnlId; + uchTag = puchRawdataBuf[usSearchStartPosi] >> 3; + uchChnlId = puchTagArray[uchTag]; + if(0xFF != uchChnlId) + { + GU32 unRawdataAndTag; + unTempIncompeletFlag |= (1 << uchChnlId); + unRawdataAndTag = GH3X2X_MAKEUP_DWORD(puchRawdataBuf[usSearchStartPosi], + puchRawdataBuf[usSearchStartPosi + 1], + puchRawdataBuf[usSearchStartPosi + 2], + puchRawdataBuf[usSearchStartPosi + 3]); + //store incomplete rawdata + pstFrameInfo->punIncompleteRawdata[uchChnlId] = unRawdataAndTag; + + } + + if(unCompeletMask == (unCompeletMask&unTempIncompeletFlag)) //got one frame + { + if((0 == pstFrameInfo->pstDownSampleInfo->uchDownSampleFactor)||(pstFrameInfo->pstDownSampleInfo->uchDownSampleFactor == pstFrameInfo->pstDownSampleInfo->uchDownSampleCnt)) + { + GH3x2xHandleFrameData(pstFrameInfo, &unTempIncompeletFlag, + &unFunctionID, uchChnlNum, puchRawdataBuf, punFrameRawdata, + &uchTag, pusGsValueArr, fGsensorIndex, + pstCapValueArr,fCapIndex,pstTempValueArr,fTempIndex); + + //send BLE package + #if (__SUPPORT_ZIP_PROTOCOL__) + Gh2x2xUploadZipDataToMaster(pstFrameInfo, usFrameCnt, usFrameNum, puchTagArray); + #else + Gh2x2xUploadDataToMaster(pstFrameInfo, usFrameCnt, usFrameNum, puchTagArray); + #endif + // timestamp + (*(pstFrameInfo->punFrameCnt)) ++; + // bak last gain + for(GU8 uchChnlCnt = 0; uchChnlCnt < uchChnlNum; uchChnlCnt ++) + { + pstFrameInfo ->puchFrameLastGain[uchChnlCnt] = ((pstFrameInfo->punFrameAgcInfo[uchChnlCnt]) & 0x0000000F); + } + + + usFrameCnt ++; + } + unTempIncompeletFlag = 0; + if(pstFrameInfo->pstDownSampleInfo->uchDownSampleFactor) + { + if(pstFrameInfo->pstDownSampleInfo->uchDownSampleFactor <= pstFrameInfo->pstDownSampleInfo->uchDownSampleCnt) + { + pstFrameInfo->pstDownSampleInfo->uchDownSampleCnt = 0; + } + else + { + pstFrameInfo->pstDownSampleInfo->uchDownSampleCnt ++; + } + } + + //calculate next fGsensorIndex + fGsensorIndex += fGensorStep; + fCapIndex += fCapStep; + fTempIndex += fTempStep; + } + } + + //save IncompeletFlag + *(pstFrameInfo->punIncompleteChnlMapBit) = unTempIncompeletFlag; +} + +void GH3x2xFunctionProcess(GU8 *puchRawdataBuf, GU16 usRawDataByteLen, GS16 *pusGsValueArr, GU16 usGsDataNum, + STCapRawdata* pstCapValueArr,GU16 usCapDataNum,STTempRawdata* pstTempValueArr,GU16 usTempDataNum, + const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GU16 usFrameNum; + float fGsensorStep; + float fCapStep; + float fTempStep; + + if(0 == pstFrameInfo) + { + return ; + } + + /***** check feature value *********/ + if(GH3X2X_CheckRawdataBuf(puchRawdataBuf, usRawDataByteLen) || pstFrameInfo->pstFunctionInfo->uchChnlNum == 0) + { + return; + } + + /*** cal how many frames in this fifo ***/ + usFrameNum = GH3x2xGetFrameNum(puchRawdataBuf, usRawDataByteLen, pstFrameInfo); + + /*** cal g-sensor step ***/ + fGsensorStep = GH3x2xCalGsensorStep(usGsDataNum, usFrameNum); + fCapStep = GH3x2xCalGsensorStep(usCapDataNum, usFrameNum); + fTempStep = GH3x2xCalGsensorStep(usTempDataNum, usFrameNum); + + GH3X2X_DEBUG_LOG_PARAM("[GetFrameNum]FunctionID: %d FrameNum: %d, GsensorStep: %.3f\r\n",(int)pstFrameInfo->unFunctionID, usFrameNum, fGsensorStep); + + /*** get one frame data and process***/ + GH3x2xGetFrameDataAndProcess(puchRawdataBuf,usRawDataByteLen,pusGsValueArr,usGsDataNum,pstCapValueArr,usCapDataNum,pstTempValueArr,usTempDataNum, + pstFrameInfo,fGsensorStep,fCapStep,fTempStep,usFrameNum); + + +} + + +void GH3X2X_ZipmodeInit(void) +{ + g_uchOddEvenChangeFlag = 1; +} + +GS8 GH3X2X_FunctionStart(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_OK; + GU32 unFunctionID; + if(0 == pstFrameInfo) + { + return chRet; + } + + GH3X2X_ZipmodeInit(); + + unFunctionID = pstFrameInfo->unFunctionID; + + GH3x2xCalFunctionSlotBit(pstFrameInfo); + + + + /* if all func off, start sampling */ + if (GH3X2X_NO_FUNCTION == g_unFuncStartedBitmap) + { + chRet = GH3X2X_StartSampling(); + GH3X2X_DEBUG_LOG_PARAM("[FunctionStart] function id: 0x%X, start result: %d\r\n",(int)pstFrameInfo->unFunctionID, chRet); + GH3X2X_RET_ERROR_CHECK_E(chRet, GH3X2X_RET_NO_INITED_ERROR); + } + + + #if GH3X2X_ALGORITHM_ECG_SUPPORT && __FUNC_TYPE_ECG_ENABLE__ + if (GH3X2X_FUNCTION_ECG == unFunctionID) + { + GH3X2X_EcgSampleHookHandle(ECG_SAMPLE_EVENT_TYPE_SAMPLE, ECG_SAMPLE_EVENT_INFO_SAMPLE_START); //G202008231001 wanpeng + GH3X2X_LeadOffDetectInit(); + GH3X2X_ECGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->usSampleRate); + //GH3X2X_ECGResampleConfig(250); + GH3X2X_DEBUG_LOG_PARAM("[FunctionStart] sample rate: %d\r\n",(int)g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->usSampleRate); + } + #endif + + #if __SUPPORT_PPG_DOWNSAMP__ + if(g_uchPPGDownSampleChnlNumLimit>0) + { + if (GH3X2X_FUNCTION_HR == unFunctionID) + { + GH3X2X_PPGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstFunctionInfo->usSampleRate); + GH3X2X_DEBUG_LOG_PARAM("[FunctionStart] sample rate: %d\r\n",(int)g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstFunctionInfo->usSampleRate); + } + + else if (GH3X2X_FUNCTION_SPO2 == unFunctionID) + { + GH3X2X_PPGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SPO2]->pstFunctionInfo->usSampleRate); + GH3X2X_DEBUG_LOG_PARAM("[FunctionStart] sample rate: %d\r\n",(int)g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SPO2]->pstFunctionInfo->usSampleRate); + } + else if (GH3X2X_FUNCTION_SOFT_ADT_GREEN == unFunctionID) + { + GH3X2X_PPGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_GREEN]->pstFunctionInfo->usSampleRate); + GH3X2X_DEBUG_LOG_PARAM("[FunctionStart] sample rate: %d\r\n",(int)g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_GREEN]->pstFunctionInfo->usSampleRate); + } + else if (GH3X2X_FUNCTION_SOFT_ADT_IR == unFunctionID) + { + GH3X2X_PPGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_IR]->pstFunctionInfo->usSampleRate); + GH3X2X_DEBUG_LOG_PARAM("[FunctionStart] sample rate: %d\r\n",(int)g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_IR]->pstFunctionInfo->usSampleRate); + } + } + #endif + + if (GH3X2X_FUNCTION_ADT == unFunctionID) + { + #if __FUNC_TYPE_ECG_ENABLE__ + GH3X2X_LeadDetEnInHardAdt(1); + #endif + } + + /* set started bit */ + g_unFuncStartedBitmap |= unFunctionID; + + /* clear incompelet flag */ + (*(pstFrameInfo->punIncompleteChnlMapBit)) = 0; + + /* clear timestamp */ + (*(pstFrameInfo->punFrameCnt)) = 0; + + /* set last gain */ + GH3X2X_Memset(pstFrameInfo->puchFrameLastGain, 0xFF, pstFrameInfo->pstFunctionInfo->uchChnlNum); + + return chRet; +} + +GS8 GH3X2X_FunctionStop(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GS8 chRet = GH3X2X_RET_OK; + GU32 unFunctionID; + if(0 == pstFrameInfo) + { + return chRet; + } + + unFunctionID = pstFrameInfo->unFunctionID; + GH3x2xCalFunctionSlotBit(pstFrameInfo); + + /* clear started bit */ + g_unFuncStartedBitmap &= (~unFunctionID); + + /* set result flag */ + if (pstFrameInfo->pstAlgoRecordResult != GH3X2X_PTR_NULL) + { + pstFrameInfo->pstAlgoRecordResult->uchUpdateFlag = 0; + pstFrameInfo->pstAlgoRecordResult->usResultBit = 0; + } + + /* if all func off, stop sampling */ + if (GH3X2X_NO_FUNCTION == g_unFuncStartedBitmap) + { + chRet = GH3X2X_StopSampling(); + GH3X2X_DEBUG_LOG_PARAM("[FunctionStop] function id: 0x%X, start result: %d\r\n",(int)pstFrameInfo->unFunctionID, chRet); + GH3X2X_RET_ERROR_CHECK(chRet); + + /* fixed fifo watermark thr */ + //GH3X2X_FIXED_FIFO_WATERMARK_THR(); + } + + return chRet; +} + +GU32 GH3X2X_GetFuncStartedBitmap(void) +{ + return g_unFuncStartedBitmap; +} + +GU8* GH3x2xGetFunctionChnlMap(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + if(0 == pstFrameInfo) + { + return 0; + } + else + { + return pstFrameInfo->pchChnlMap; + } +} + +void GH3x2xSetFunctionChnlNum(const STGh3x2xFrameInfo * const pstFrameInfo, GU8 uchChnlNum) +{ + GU8 uchChnlLimit; + if(pstFrameInfo) + { + uchChnlLimit = pstFrameInfo->uchFuntionChnlLimit; + if(uchChnlNum > uchChnlLimit) + { + uchChnlNum = uchChnlLimit; + } + pstFrameInfo ->pstFunctionInfo->uchChnlNum = uchChnlNum; + if (uchChnlNum > 0) + { + g_unConfigFuncMode |= pstFrameInfo->unFunctionID; + } + GH3X2X_DEBUG_LOG_PARAM("[SetFunctionChnlNum] function id: 0x%X, ChnlNum: %d\r\n",(int)pstFrameInfo->unFunctionID, uchChnlNum); + } +} + +void GH3x2xSetFunctionChnlMap(const STGh3x2xFrameInfo * const pstFrameInfo, GU8 uchChnlId, GU8 uchChnlTag) +{ + if(pstFrameInfo) + { + if(uchChnlId < (pstFrameInfo->uchFuntionChnlLimit)) + { + pstFrameInfo ->pchChnlMap[uchChnlId] = uchChnlTag; + + + GH3X2X_DEBUG_LOG_PARAM("[SetFunctionChnlMap] function id: 0x%X, SlotAdc: %d\r\n",(int)pstFrameInfo->unFunctionID, uchChnlTag>>3); + } + + } +} + + +void GH3x2xCalFunctionSlotBit(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + GU8 uchSlotBit = 0; + GU8 uchChnlTag; + if(pstFrameInfo) + { + for(GU8 uchChnlCnt = 0; uchChnlCnt < pstFrameInfo->pstFunctionInfo->uchChnlNum; uchChnlCnt ++) + { + if(pstFrameInfo->pstFunctionInfo->unChnlEnForUserSetting & (((GU32)1) << uchChnlCnt)) + { + uchChnlTag = pstFrameInfo->pchChnlMap[uchChnlCnt]; + uchSlotBit |= (1 << (GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(uchChnlTag))); + } + } + } + + + + + pstFrameInfo ->pstFunctionInfo->uchSlotBit = uchSlotBit; + + + GH3X2X_DEBUG_LOG_PARAM("[GH3x2xCalFunctionSlotBit] function id: 0x%X, slot bit: 0x%X\r\n",(int)pstFrameInfo->unFunctionID, pstFrameInfo->pstFunctionInfo->uchSlotBit); +} + + + + + + + +//G202008031001 wanpeng START +/** + * @fn GU32 GH3X2X_GetSoftEvent(void) + * @brief Get soft event + * @param[in] None + * @param[out] Soft event + * + * @return soft event + */ +GU32 GH3X2X_GetSoftEvent(void) +{ + return g_unSoftEvent; +} + +/** + * @fn void GH3X2X_SetSoftEvent(GU32 unEvent) + * @brief set soft event + * @param[in] uchEvent + * @param[out] None + * @return None + */ +void GH3X2X_SetSoftEvent(GU32 unEvent) +{ + g_unSoftEvent |= unEvent; +} +/** + * @fn void GH3X2X_ClearSoftEvent(GU32 unEvent) + * @brief clear soft event + * @param[in] uchEvent + * @param[out] None + * @return None + */ + +void GH3X2X_ClearSoftEvent(GU32 unEvent) +{ + g_unSoftEvent &= (~unEvent); +} +//G202008031001 wanpeng END + + +/** + * @fn GU8 GH3X2X_GetGsensorEnableFlag(void) + * + * @brief Inquire if need gsensor data + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return 1: need gsensor data 0: not need gsensor data + */ +GU8 GH3X2X_GetGsensorEnableFlag(void) +{ + return g_uchGsensorEnable; +} + +#if (0 == __CAP_ENABLE__) +GU8 GH3X2X_GetCapEnableFlag(void) +{ + return 0; +} +#else +GU8 GH3X2X_GetCapEnableFlag(void) +{ + return g_uchCapEnable; +} +#endif + +#if (0 == __TEMP_ENABLE__) +GU8 GH3X2X_GetTempEnableFlag(void) +{ + return 0; +} +#else +GU8 GH3X2X_GetTempEnableFlag(void) +{ + return g_uchTempEnable; +} +#endif + +void Gh3x2xFunctionInit(void) +{ + for(GU8 uchFuncitonCnt = 0; uchFuncitonCnt < GH3X2X_FUNC_OFFSET_MAX; uchFuncitonCnt ++) + { + if(g_pstGh3x2xFrameInfo[uchFuncitonCnt]) + { + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[uchFuncitonCnt], 0); //chnl num + g_pstGh3x2xFrameInfo[uchFuncitonCnt] -> pstFunctionInfo -> usSampleRate = 0; //set sample rate to invalid value + g_pstGh3x2xFrameInfo[uchFuncitonCnt] -> pstDownSampleInfo -> uchDownSampleFactor = 0; + g_pstGh3x2xFrameInfo[uchFuncitonCnt] -> pstDownSampleInfo -> uchDownSampleCnt = 0; + } + } +} + +/** + * @fn void GH3X2X_ReinitAllSwModuleParam(GU16 usReinitFlag) + * + * @brief reinit all software param config + * + * @attention None + * + * @param[in] usReinitFlag reinit flag, #0 don't reinit, #others reinit all + * @param[out] None + * + * @return None + */ +void GH3X2X_ReinitAllSwModuleParam(GU16 usReinitFlag) +{ + if (usReinitFlag != 0) // if != 0, that need reinit all software module param + { + + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_HR], 0); + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_HRV], 0); + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SPO2], 0); + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG], 0); + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_GREEN], 0); + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_IR], 0); + GH3x2xSetFunctionChnlNum(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ADT], 0); + + #if __SUPPORT_SOFT_AGC_CONFIG__ + GH3X2X_LedAgcReset(); // agc moudle param reinit + #endif + #if __FUNC_TYPE_ECG_ENABLE__ + GH3X2X_SlaverSoftLeadPramInit();// lead moudle param reinit + #endif + + GH3X2X_DumpModeSet(0); // dump module param reinit + + #if __FUNC_TYPE_ECG_ENABLE__ + GH3X2X_AdtPramInit(); ////G202008231001 wanpeng + #endif + g_uchGsensorEnable = 0; + // soft adt param reinit + } +} + + +/* util function, memcpy & memset & strlen */ + +/** + * @fn void *GH3X2X_Memcpy(void *pDest, const void *pSrc, GU32 unByteSize) + * + * @brief memcpy() Re-implementation + * + * @attention None + * + * @param[in] pSrc pointer to source buffer + * @param[in] unByteSize source buffer byte size + * @param[out] pDest pointer to destination buffer + * + * @return pointer to destination buffer + */ +void *GH3X2X_Memcpy(void *pDest, const void *pSrc, GU32 unByteSize) +{ + GU8 *puchSrc = (GU8 *)pSrc; + GU8 *puchDest = (GU8 *)pDest; + GU32 unAlign = ((GU32)puchDest | (GU32)puchSrc) << GH3X2X_UPROTOCOL_ALIGN_LEFTSHIFT; + + if ((pDest == GH3X2X_PTR_NULL) || (pSrc == GH3X2X_PTR_NULL) || (0 == unByteSize)) + { + return GH3X2X_PTR_NULL; + } + if (unAlign == 0) // if align 4 + { + while (unByteSize >= GH3X2X_UPROTOCOL_SIZE_T) + { + *(GU32 *)puchDest = *(GU32 *)puchSrc; + puchSrc += GH3X2X_UPROTOCOL_SIZE_T; + puchDest += GH3X2X_UPROTOCOL_SIZE_T; + unByteSize -= GH3X2X_UPROTOCOL_SIZE_T; + } + } + while (unByteSize) // bytes + { + *(GU8 *)puchDest = *(GU8 *)puchSrc; + puchSrc++; + puchDest++; + unByteSize--; + } + return pDest; +} + +/** + * @fn void *GH3X2X_Memset(void* pDest, GCHAR chVal, GU32 unByteSize) + * + * @brief memset() Re-implementation + * + * @attention None + * + * @param[in] chVal char val for set + * @param[in] unByteSize source buffer len + * @param[out] pDest pointer to destination buffer + * + * @return pointer to destination buffer + */ +void *GH3X2X_Memset(void* pDest, GCHAR chVal, GU32 unByteSize) +{ + GU8 *puchDest = (GU8 *)pDest; + GU32 unAlign = ((GU32)puchDest) << GH3X2X_UPROTOCOL_ALIGN_LEFTSHIFT; + GU32 unWordVal = GH3X2X_MAKEUP_DWORD(chVal, chVal, chVal, chVal); + + if (pDest == GH3X2X_PTR_NULL) + { + return GH3X2X_PTR_NULL; + } + if (unAlign == 0) // if align 4 + { + while (unByteSize >= GH3X2X_UPROTOCOL_SIZE_T) + { + *(GU32 *)puchDest = unWordVal; + puchDest += GH3X2X_UPROTOCOL_SIZE_T; + unByteSize -= GH3X2X_UPROTOCOL_SIZE_T; + } + } + while (unByteSize) // bytes + { + *(GU8 *)puchDest = (GU8)chVal; + puchDest++; + unByteSize--; + } + return pDest; +} + +/** + * @fn GU32 GH3X2X_Strlen(const GCHAR *pszSrc) + * + * @brief strlen() Re-implementation + * + * @attention None + * + * @param[in] pszSrc pointer to string + * @param[out] None + * + * @return string len + */ +GU32 GH3X2X_Strlen(const GCHAR *pszSrc) +{ + GU32 unCnt = 0; + if (pszSrc != GH3X2X_PTR_NULL) + { + while ((*pszSrc) != 0) // if not equal '\0' + { + unCnt++; + pszSrc++; + } + } + return unCnt; +} + + + +GU8 GH3X2X_GetAlgoEnableFlag(void) +{ + return g_uchAlgoEnableFlag; +} + +void GH3X2X_SetAlgoEnableFlag(GU8 uchAlgoEnableFlag) +{ + g_uchAlgoEnableFlag = uchAlgoEnableFlag; +} + + +GU8 GH3X2X_GetSingleChipModeEnableFlag(void) +{ + return g_uchSingleChipModeEnableFlag; +} + +void GH3X2X_SetSingleChipModeEnableFlag(GU8 uchAlgoEnableFlag) +{ + g_uchSingleChipModeEnableFlag = uchAlgoEnableFlag; +} + +/** + * @fn void GH3X2X_ModifyFunctionFrequency(GU8 uchFunctionID, GU16 usFrequencyValue) + * + * @brief Modify fs for each function + * + * @attention None + * + * @param[in] uchFunctionID function offset + * @param[in] usFrequencyValue 5Hz-1000Hz + * @param[out] None + * + * @return None + */ +void GH3X2X_ModifyFunctionFrequency(GU8 uchFunctionID, GU16 usFrequencyValue) +{ + GU8 uchTempSlotNo = 0; + GU8 uchTempSlotLastNo = 0xff; + GU8 uchChnlCnt = 0; + for(uchChnlCnt = 0; uchChnlCnt < g_pstGh3x2xFrameInfo[uchFunctionID]->pstFunctionInfo->uchChnlNum; uchChnlCnt ++) + { + uchTempSlotNo = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(g_pstGh3x2xFrameInfo[uchFunctionID]->pchChnlMap[uchChnlCnt]); + if (uchTempSlotLastNo != uchTempSlotNo) + { + GH3x2x_SetSlotSampleRate(uchTempSlotNo, usFrequencyValue); + uchTempSlotLastNo = uchTempSlotNo; + } + } + g_pstGh3x2xFrameInfo[uchFunctionID]->pstFunctionInfo->usSampleRate = usFrequencyValue; +} + +/** + * @fn void GH3X2X_ModifyFunctionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current) + * + * @brief Modify led current for each function + * + * @attention None + * + * @param[in] uchFunctionID function offset + * @param[in] usLedDrv0Current 0mA-200mA + * @param[in] usLedDrv1Current 0mA-200mA + * @param[out] None + * + * @return None + */ +void GH3X2X_ModifyFunctionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current) +{ + GU8 uchTempSlotNo = 0; + GU8 uchTempSlotLastNo = 0xff; + GU8 uchChnlCnt = 0; + GU16 usDrv0Reg = 0; + GU16 usDrv1Reg = 0; + GU16 usDr0Fs = 0; + GU16 usDr1Fs = 0; + + GH3x2x_GetLedCurrentFullScal((GU8*)&usDr0Fs, (GU8*)&usDr1Fs); + + for(uchChnlCnt = 0; uchChnlCnt < g_pstGh3x2xFrameInfo[uchFunctionID]->pstFunctionInfo->uchChnlNum; uchChnlCnt ++) + { + uchTempSlotNo = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(g_pstGh3x2xFrameInfo[uchFunctionID]->pchChnlMap[uchChnlCnt]); + if (uchTempSlotLastNo != uchTempSlotNo) + { + usDrv0Reg = (GU16)usLedDrv0Current * 255 /usDr0Fs; + if(usDrv0Reg > 255) + { + usDrv0Reg = 255; + } + usDrv1Reg = (GU16)usLedDrv1Current * 255 /usDr1Fs; + if(usDrv1Reg > 255) + { + usDrv1Reg = 255; + } + + GH3X2X_SlotLedCurrentConfig(uchTempSlotNo, 0, usDrv0Reg); + GH3X2X_SlotLedCurrentConfig(uchTempSlotNo, 1, usDrv1Reg); + uchTempSlotLastNo = uchTempSlotNo; + } + } +} + +GU32 GH3X2X_GetConfigFuncMode(void) +{ + return g_unConfigFuncMode; +} + +void GH3X2X_SetConfigFuncMode(GU32 unConfigFuncMode) +{ + g_unConfigFuncMode = unConfigFuncMode; +} + +void Gh3x2xFifoRecovery(void) +{ + GU16 uchSampleStateBak; + uchSampleStateBak = GH3X2X_ReadRegBitField(0x0000, 0, 0); + GH3X2X_WriteRegBitField(0x0000, 0, 0, 0); + Gh3x2x_BspDelayMs(10); + GH3X2X_WriteRegBitField(0x0000, 0, 0, uchSampleStateBak); +} + +#if (GH3X2X_FIFO_MONITOR_EN&(__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__)) + +void Gh3x2xModifiyDecimation(GU8 uchDecimationChnl, GU8 uchSlotAdc, GU8 uchOption) +{ + GU16 uchSampleStateBak; + uchSampleStateBak = GH3X2X_ReadRegBitField(0x0000, 0, 0); + GH3X2X_WriteRegBitField(0x0000, 0, 0, 0); + Gh3x2x_BspDelayMs(10); + + GH3X2X_WriteRegBitField(GH3X2X_DCMT_CTRL0_REG_ADDR, GH3X2X_DCMT_EN_LSB + uchDecimationChnl, GH3X2X_DCMT_EN_LSB + uchDecimationChnl, 1); + GH3X2X_WriteRegBitField(GH3X2X_DCMT_CTRL0_REG_ADDR, GH3X2X_DCMT_DNSAMPLE_DIS_LSB + uchDecimationChnl, GH3X2X_DCMT_DNSAMPLE_DIS_LSB + uchDecimationChnl, 0); + + GH3X2X_WriteRegBitField(GH3X2X_DCMT_CTRL1_REG_ADDR + uchDecimationChnl * 2, GH3X2X_DCMT_HEAD_LSB, GH3X2X_DCMT_HEAD_MSB, uchSlotAdc); + GH3X2X_WriteRegBitField(GH3X2X_DCMT_CTRL1_REG_ADDR + uchDecimationChnl * 2, GH3X2X_DCMT_RND_SEL_LSB, GH3X2X_DCMT_RND_SEL_MSB, uchOption); + + GH3X2X_WriteRegBitField(0x0000, 0, 0, uchSampleStateBak); +} + + + + +/// @brief get channel output en +/// @param +/// @return output enable flagx, 0: slot0 adc0 output flag 1: slot0 adc1 output flag ... 31: slot7 adc3 output flag +GU32 Gh3x2xGetChnlOutputEn(void) +{ + GU32 unChnlEn = 0; + GU8 uchSlotCfgEn = GH3X2X_ReadRegBitField(GH3X2X_SLOT_ENABLE_CFG_REG_ADDR, GH3X2X_SLOT_ENABLE_CFG_REG_LSB, GH3X2X_SLOT_ENABLE_CFG_REG_MSB); + //get channel en, need eliminate no-output channel + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_SLOT_NUM_MAX; uchSlotCnt ++) + { + if(uchSlotCfgEn&(1 << uchSlotCnt)) + { + GU8 uchRxEnFifoEn = GH3X2X_ReadRegBitField(GH3X2X_SLOT0_CTRL_0_REG_ADDR + ((GU16)uchSlotCnt * GH3X2X_SLOT_CTRL_ADDR_INTERVAL), GH3X2X_SLOT_RX_EN_FIFO_EN_LSB, GH3X2X_SLOT_RX_EN_FIFO_EN_MSB); + if(uchRxEnFifoEn & (1 << (GH3X2X_SLOT_FIFO_EN_LSB - GH3X2X_SLOT_RX_EN_FIFO_EN_LSB))) // if fifo en = 1 + { + for(GU8 uchRxCnt = 0; uchRxCnt < GH3X2X_RX_NUM_MAX; uchRxCnt ++) + { + if(uchRxEnFifoEn&(1 << uchRxCnt)) + { + unChnlEn |= 1 << (uchSlotCnt * GH3X2X_RX_NUM_MAX + uchRxCnt); + } + } + } + } + } + return unChnlEn; +} + +/// @brief get sample rate factor for every slot +/// @param puchSlotSampleRateFactor [0]: slot0 sample rate factor [1]: slot1 sample rate factor ... [7]: slot7 sample rate factor +void Gh3x2xGetSlotSampleRateFactor(GU8 *puchSlotSampleRateFactor) +{ + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_SLOT_NUM_MAX; uchSlotCnt ++) + { + puchSlotSampleRateFactor[uchSlotCnt] = GH3X2X_ReadRegBitField(GH3X2X_SLOT0_CTRL_0_REG_ADDR + ((GU16)uchSlotCnt * GH3X2X_SLOT_CTRL_ADDR_INTERVAL), GH3X2X_SLOT_SR_MULTIPLIER_LSB, GH3X2X_SLOT_SR_MULTIPLIER_MSB); + } +} + + +#if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + +/// @brief get decimation enable (decimation en = 1 and downsample disable = 0) +/// @param none +/// @return decimation +GU8 Gh3x2xGetDecimationEn(void) +{ + GU8 uchDecimationEn; + GU8 uchDownSampleEn; + uchDecimationEn = GH3X2X_ReadRegBitField(GH3X2X_DCMT_CTRL0_REG_ADDR, GH3X2X_DCMT_EN_LSB, GH3X2X_DCMT_EN_MSB); + uchDownSampleEn = GH3X2X_ReadRegBitField(GH3X2X_DCMT_CTRL0_REG_ADDR, GH3X2X_DCMT_DNSAMPLE_DIS_LSB, GH3X2X_DCMT_DNSAMPLE_DIS_MSB); + return uchDecimationEn &= (~uchDownSampleEn); +} + +#else + + +/// @brief get decimaiton information in current chip registers +/// @param pstDecimationInfo the decimation infomation that we get +void Gh3x2xGetDecimationInfo(STGh3x2xDecimationInfo *pstDecimationInfo) +{ + GU8 uchDecimationEn; + GU8 uchDownSampleEn; + GU8 uchValidChnlCnt; + uchDecimationEn = GH3X2X_ReadRegBitField(GH3X2X_DCMT_CTRL0_REG_ADDR, GH3X2X_DCMT_EN_LSB, GH3X2X_DCMT_EN_MSB); + uchDownSampleEn = GH3X2X_ReadRegBitField(GH3X2X_DCMT_CTRL0_REG_ADDR, GH3X2X_DCMT_DNSAMPLE_DIS_LSB, GH3X2X_DCMT_DNSAMPLE_DIS_MSB); + + uchDecimationEn &= (~uchDownSampleEn); //we need channel which uchDecimationEn = 1 and uchDownSampleEn = 0 + uchValidChnlCnt = 0; + for(GU8 uchChnlCnt = 0; uchChnlCnt < GH3X2X_DECIMAION_CHNL_MAX; uchChnlCnt ++) + { + if(uchDecimationEn&(1 << uchChnlCnt)) + { + pstDecimationInfo->puchSlotAdcIdx[uchValidChnlCnt] = GH3X2X_ReadRegBitField(GH3X2X_DCMT_CTRL1_REG_ADDR + uchChnlCnt * 2, GH3X2X_DCMT_HEAD_LSB, GH3X2X_DCMT_HEAD_MSB); + pstDecimationInfo->puchDecimationOption[uchValidChnlCnt] = GH3X2X_ReadRegBitField(GH3X2X_DCMT_CTRL1_REG_ADDR + uchChnlCnt * 2, GH3X2X_DCMT_RND_SEL_LSB, GH3X2X_DCMT_RND_SEL_MSB); + uchValidChnlCnt ++; + } + } + pstDecimationInfo->uchDecimaionChnlNum = uchValidChnlCnt; +} + +/// @brief get decimaion option of a specific channel +/// @param uchSlotAdcIdx +/// @return Decimaion option. 0: no decimtion 1: 2x decimation 2: 4x decimation 3: 8x decimation +GU8 Gh3x2xGetChannelDecimationOption(GU8 uchSlotAdcIdx, STGh3x2xDecimationInfo *pstDecimationInfo) +{ + for(GU8 uchChnlCnt = 0; uchChnlCnt < pstDecimationInfo->uchDecimaionChnlNum; uchChnlCnt ++) + { + if(pstDecimationInfo->puchSlotAdcIdx[uchChnlCnt] == uchSlotAdcIdx) + { + return pstDecimationInfo->puchDecimationOption[uchChnlCnt]; + } + } + return 0; +} + +#endif + +#if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) +GU16 Gh3x2xGetDividerOfChnl(GU8 uchSlotAdcIdx, GU8 *puchSlotSampleRateFactor) +#else +GU16 Gh3x2xGetDividerOfChnl(GU8 uchSlotAdcIdx, STGh3x2xDecimationInfo *pstDecimationInfo, GU8 *puchSlotSampleRateFactor) +#endif +{ + GU16 usTempDivider; + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + usTempDivider = ((GU16)puchSlotSampleRateFactor[uchSlotAdcIdx >> 2] + 1); + #else + GU8 uchDecimationOption; + uchDecimationOption = Gh3x2xGetChannelDecimationOption(uchSlotAdcIdx, pstDecimationInfo); + usTempDivider = ((GU16)puchSlotSampleRateFactor[uchSlotAdcIdx >> 2] + 1) << uchDecimationOption; + #endif + return usTempDivider; +} + +/// @brief get slot adc index of the lowest frequence channel +/// @param pstDecimationInfo +/// @param puchSlotSampleRateFactor the register value of rg_slotX_sr_multiplier(X = 0~7), the array length is 8 +/// @param unSlotAdcChnlEn bi0: slot0adc0 is en or not bit1: slot0adc1 is en or not ... bit31: is slot7adc3 is en or not +/// @return slot adc index of this channel +#if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) +GU8 Gh3x2xGetLowestChnl(GU8 *puchSlotSampleRateFactor, GU32 unSlotAdcChnlEn) +#else +GU8 Gh3x2xGetLowestChnl(STGh3x2xDecimationInfo *pstDecimationInfo, GU8 *puchSlotSampleRateFactor, GU32 unSlotAdcChnlEn) +#endif +{ + GU16 usLowestChnlDivider = 0; + GU8 uchLowestChnlSlotAdc = 0xFF; + for(GU8 uchChnlCnt = 0; uchChnlCnt < (GH3X2X_RX_NUM_MAX * GH3X2X_SLOT_NUM_MAX); uchChnlCnt ++) + { + if(unSlotAdcChnlEn&(1 << uchChnlCnt)) + { + + GU16 usTempDivider; + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + usTempDivider = Gh3x2xGetDividerOfChnl(uchChnlCnt, puchSlotSampleRateFactor); + #else + usTempDivider = Gh3x2xGetDividerOfChnl(uchChnlCnt, pstDecimationInfo, puchSlotSampleRateFactor); + #endif + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorInit] slot%d, adc%d, usTempDivider = %d.\r\n",(int)(GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(uchChnlCnt)), (int)(GH3X2X_GET_ADC_FROM_CHANNEL_NUM(uchChnlCnt)), (int)usTempDivider); + if(usTempDivider > usLowestChnlDivider) + { + usLowestChnlDivider = usTempDivider; + uchLowestChnlSlotAdc = uchChnlCnt; + } + } + } + return uchLowestChnlSlotAdc; +} + + +/// @brief get sample rate radio(integer part) of target channel and reference channel +/// @param pstDecimationInfo +/// @param puchSlotSampleRateFactor the register value of rg_slotX_sr_multiplier(X = 0~7), the array length is 8 +/// @param uchTargetChnlSlotAdcIdx slot adc index of target channel +/// @param uchRefChnlSlotAdcIdx slot adc index of reference channel +/// @param puchDecimalFlag if decimal part is not zero, the flag will be set +/// @return +#if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) +GU16 Gh3x2xGetTargetChnlSampleRateRadio(GU8 *puchSlotSampleRateFactor, GU8 uchTargetChnlSlotAdcIdx, GU8 uchRefChnlSlotAdcIdx) +#else +GU16 Gh3x2xGetTargetChnlSampleRateRadio(STGh3x2xDecimationInfo *pstDecimationInfo, GU8 *puchSlotSampleRateFactor, GU8 uchTargetChnlSlotAdcIdx, GU8 uchRefChnlSlotAdcIdx, GU8 *puchDecimalFlag) +#endif +{ + GU16 usTargetChnlDivder; + GU16 usRefChnlDivder; + GU16 usSampleRateRadio; + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + usTargetChnlDivder = Gh3x2xGetDividerOfChnl(uchTargetChnlSlotAdcIdx, puchSlotSampleRateFactor); + usRefChnlDivder = Gh3x2xGetDividerOfChnl(uchRefChnlSlotAdcIdx, puchSlotSampleRateFactor); + #else + usTargetChnlDivder = Gh3x2xGetDividerOfChnl(uchTargetChnlSlotAdcIdx, pstDecimationInfo, puchSlotSampleRateFactor); + usRefChnlDivder = Gh3x2xGetDividerOfChnl(uchRefChnlSlotAdcIdx, pstDecimationInfo, puchSlotSampleRateFactor); + #endif + usSampleRateRadio = usRefChnlDivder/usTargetChnlDivder; + #if (GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + puchDecimalFlag[0] = 0; + if(usSampleRateRadio*usTargetChnlDivder < usRefChnlDivder) + { + puchDecimalFlag[0] = 1; + } + #endif + return usSampleRateRadio; +} + + +/// @brief fifo monitor module init +/// @param pstMonitorInfo +void Gh3x2xFifoMonitorInit(STGh3x2xFifoMonitorInfo *pstMonitorInfo) +{ + GU32 unChnlEn; + #if (GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + STGh3x2xDecimationInfo stDecimationInfo; + GU8 uchDecimalFlag; + #endif + GU8 puchSlotSampleRateFactor[GH3X2X_SLOT_NUM_MAX]; + GU16 usSampleRateRadio; + + //Gh3x2xModifiyDecimation(3,(1 << 2)|(0 << 0),3); + + + + + GH3X2X_Memset((void*)pstMonitorInfo, 0, sizeof(STGh3x2xFifoMonitorInfo)); + + unChnlEn = Gh3x2xGetChnlOutputEn(); + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorInit] unChnlEn = 0x%X.\r\n",unChnlEn); + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + if(Gh3x2xGetDecimationEn()) + { + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorInit] error! decimation is detected, please set GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT to 1\r\n"); + while(1); + } + #else + Gh3x2xGetDecimationInfo(&stDecimationInfo); + #endif + Gh3x2xGetSlotSampleRateFactor(puchSlotSampleRateFactor); + + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + pstMonitorInfo->uchLowestChnlSlotAdcIdx = Gh3x2xGetLowestChnl(puchSlotSampleRateFactor, unChnlEn); + #else + pstMonitorInfo->uchLowestChnlSlotAdcIdx = Gh3x2xGetLowestChnl(&stDecimationInfo, puchSlotSampleRateFactor, unChnlEn); + #endif + + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorInit] lowest chnl is slot%d, adc%d.\r\n",(int)(GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(pstMonitorInfo->uchLowestChnlSlotAdcIdx)), (int)(GH3X2X_GET_ADC_FROM_CHANNEL_NUM(pstMonitorInfo->uchLowestChnlSlotAdcIdx))); + for(GU8 uchChnlCnt = 0; uchChnlCnt < (GH3X2X_RX_NUM_MAX * GH3X2X_SLOT_NUM_MAX); uchChnlCnt ++) + { + #if (GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + uchDecimalFlag = 0; + #endif + if(unChnlEn & (1 << uchChnlCnt)) + { + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + usSampleRateRadio = Gh3x2xGetTargetChnlSampleRateRadio(puchSlotSampleRateFactor, uchChnlCnt, pstMonitorInfo->uchLowestChnlSlotAdcIdx); + #else + usSampleRateRadio = Gh3x2xGetTargetChnlSampleRateRadio(&stDecimationInfo, puchSlotSampleRateFactor, uchChnlCnt, pstMonitorInfo->uchLowestChnlSlotAdcIdx, &uchDecimalFlag); + #endif + + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + pstMonitorInfo -> usEstiSampleCntlimit[GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(uchChnlCnt)] += usSampleRateRadio; + #endif + pstMonitorInfo -> usEstiAllChnlSampleCntlimit += usSampleRateRadio; + + #if (GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + pstMonitorInfo -> uchEstiSampleCntUplimit[GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(uchChnlCnt)] += usSampleRateRadio + uchDecimalFlag; + #endif + pstMonitorInfo -> usEstiAllChnlSampleCntUplimit += usSampleRateRadio + uchDecimalFlag; + #endif + + #if (GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorInit] slot%dadc%d usSampleRateRadio = %d, uchDecimalFlag = %d.\r\n", + (int)(GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(uchChnlCnt)), + (int)(GH3X2X_GET_ADC_FROM_CHANNEL_NUM(uchChnlCnt)), + (int)(usSampleRateRadio), + (int)(uchDecimalFlag) + ); + #else + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorInit] slot%dadc%d usSampleRateRadio = %d.\r\n", + (int)(GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(uchChnlCnt)), + (int)(GH3X2X_GET_ADC_FROM_CHANNEL_NUM(uchChnlCnt)), + (int)(usSampleRateRadio) + ); + #endif + + + + } + } + + pstMonitorInfo -> usNeedSkipFifoByteNum = GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR) * GH3X2X_FIFO_RAWDATA_SIZE; +} + + +/// @brief recovry process function which is using after abnormal fifo data is monitored +/// @param pstMonitorInfo +void Gh3x2xFifoMonitorRecovery(STGh3x2xFifoMonitorInfo *pstMonitorInfo) +{ + Gh3x2xFifoRecovery(); + Gh3x2xFifoMonitorInit(pstMonitorInfo); +} + +extern volatile GU32 g_unDebugFifoMonitor; + +/// @brief fifo monitor module process function +/// @param pstMonitorInfo +/// @param pFifo fifo data byte stream +/// @param FifoByteNum fifo date byte number +void Gh3x2xFifoMonitorPro(STGh3x2xFifoMonitorInfo *pstMonitorInfo, GU8 *pFifo, GU16 FifoByteNum) +{ + GU8 uchSlotAdc; + GU16 usAllChnlUpLimit; + GU16 usAllChnlDownLimit; + GU8 uchIsAbnormal = 0; + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + GU8 uchSlotIdx; + GU16 *pusUpLimit; + GU16 *pusDownLimit; + pusDownLimit = pstMonitorInfo ->usEstiSampleCntlimit; + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + pusUpLimit = pstMonitorInfo ->usEstiSampleCntlimit; + #else + pusUpLimit = pstMonitorInfo ->uchEstiSampleCntUplimit; + #endif + #endif + usAllChnlDownLimit = pstMonitorInfo ->usEstiAllChnlSampleCntlimit; + #if (0 == GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + usAllChnlUpLimit = pstMonitorInfo ->usEstiAllChnlSampleCntlimit; + #else + usAllChnlUpLimit = pstMonitorInfo ->usEstiAllChnlSampleCntUplimit; + #endif + + + for(GU16 usFifoByteCnt = 0; usFifoByteCnt < FifoByteNum; usFifoByteCnt += GH3X2X_FIFO_RAWDATA_SIZE) + { + if(0 == pstMonitorInfo ->usNeedSkipFifoByteNum) + { + uchSlotAdc = GH3X2X_BYTE_RAWDATA_GET_SLOT_ADC_NUM(pFifo[usFifoByteCnt]); + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + uchSlotIdx = GH3X2X_GET_SLOT_FROM_CHANNEL_NUM(uchSlotAdc); + #endif + //GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro]Got data :Slot%dAdc%d.\r\n",(int)uchSlotIdx, (int)(GH3X2X_GET_ADC_FROM_CHANNEL_NUM(uchSlotAdc))); + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + pstMonitorInfo ->usRealTimeSampleCnt[uchSlotIdx] += 1; + #endif + pstMonitorInfo ->usAllChnlRealTimeSampleCnt += 1; + #if GH3X2X_FIFO_MONITOR_DEBUG + pstMonitorInfo ->usEveryChnlRealTimeSampleCnt[uchSlotIdx][GH3X2X_GET_ADC_FROM_CHANNEL_NUM(uchSlotAdc)] += 1; + #endif + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + if(pstMonitorInfo -> usRealTimeSampleCnt[uchSlotIdx] > pusUpLimit[uchSlotIdx]) // is abnormal + { + uchIsAbnormal = 1; + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro]RealTimeSampleCnt is too big,uchSlotIdx = %d,RealTimeSampleCnt = %d, limit = %d\r\n",(int)uchSlotIdx, (int)pstMonitorInfo -> usRealTimeSampleCnt[uchSlotIdx], pusUpLimit[uchSlotIdx]); + } + + if((pstMonitorInfo ->uchLowestChnlAppearedFlag) &&(uchSlotAdc == pstMonitorInfo->uchLowestChnlSlotAdcIdx) && (uchSlotAdc == pstMonitorInfo->uchLowestChnlSlotAdcIdx)) + { + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_SLOT_NUM_MAX; uchSlotCnt ++) + { + if(pstMonitorInfo -> usRealTimeSampleCnt[uchSlotCnt] < pusDownLimit[uchSlotCnt]) + { + uchIsAbnormal = 1; + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro]RealTimeSampleCnt is too small,uchSlotCnt = %d,RealTimeSampleCnt = %d, limit = %d\r\n",(int)uchSlotCnt, (int)pstMonitorInfo -> usRealTimeSampleCnt[uchSlotCnt], pusDownLimit[uchSlotCnt]); + } + } + } + #endif + + if(pstMonitorInfo -> usAllChnlRealTimeSampleCnt > usAllChnlUpLimit) // is abnormal + { + uchIsAbnormal = 2; + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro]AllChnlRealTimeSampleCnt is too big,RealTimeSampleCnt = %d, limit = %d.\r\n", (int)pstMonitorInfo -> usAllChnlRealTimeSampleCnt, usAllChnlUpLimit); + } + if((pstMonitorInfo ->uchLowestChnlAppearedFlag)&&(uchSlotAdc == pstMonitorInfo->uchLowestChnlSlotAdcIdx) && (pstMonitorInfo -> usAllChnlRealTimeSampleCnt < usAllChnlDownLimit)) // is abnormal + { + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro]AllChnlRealTimeSampleCnt is too samll,RealTimeSampleCnt = %d, limit = %d.\r\n", (int)pstMonitorInfo -> usAllChnlRealTimeSampleCnt, usAllChnlDownLimit); + uchIsAbnormal = 2; + } + + if(2 == uchIsAbnormal) + { + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] ***************every channel information START************\r\n"); + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_SLOT_NUM_MAX; uchSlotCnt ++) + { + #if GH3X2X_FIFO_MONITOR_DEBUG + GH3X2X_DEBUG_LOG_PARAM( + "[Gh3x2xFifoMonitorPro] Real time every channel sample num: Slot%d: %d, %d, %d, %d.\r\n", + (int)uchSlotCnt, + (int)pstMonitorInfo ->usEveryChnlRealTimeSampleCnt[uchSlotCnt][EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX0_INDEX], + (int)pstMonitorInfo ->usEveryChnlRealTimeSampleCnt[uchSlotCnt][EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX1_INDEX], + (int)pstMonitorInfo ->usEveryChnlRealTimeSampleCnt[uchSlotCnt][EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX2_INDEX], + (int)pstMonitorInfo ->usEveryChnlRealTimeSampleCnt[uchSlotCnt][EVERY_CHNL_REAL_TIME_SAMPLE_CNT_RX3_INDEX] + ); + #endif + + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] Real time slot sample num up: Slot%d: %d.\r\n", (int)uchSlotCnt, (int)pstMonitorInfo ->usRealTimeSampleCnt[uchSlotCnt]); + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] slot sample num up limit: Slot%d: %d.\r\n", (int)uchSlotCnt, (int)pstMonitorInfo ->uchEstiSampleCntUplimit[uchSlotCnt]); + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] slot sample num down limit: Slot%d: %d.\r\n", (int)uchSlotCnt, (int)pstMonitorInfo ->usEstiSampleCntlimit[uchSlotCnt]); + #endif + + } + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] Real time all-chnl sample num: %d.\r\n", (int)pstMonitorInfo ->usAllChnlRealTimeSampleCnt); + #if (GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT) + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] all-chnl sample up limit num: %d.\r\n", (int)pstMonitorInfo ->usEstiAllChnlSampleCntUplimit); + #endif + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] all-chnl sample down limit num: %d.\r\n", (int)pstMonitorInfo ->usEstiAllChnlSampleCntlimit); + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro] ***************every channel information END************\r\n"); + } + + if(2 == uchIsAbnormal) + { + + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro]recover fifo start...\r\n"); + Gh3x2xFifoMonitorRecovery(pstMonitorInfo); //go to recovery process + GH3X2X_DEBUG_LOG_PARAM("[Gh3x2xFifoMonitorPro]recover fifo end.\r\n"); + break; + } + + if(uchSlotAdc == pstMonitorInfo->uchLowestChnlSlotAdcIdx) + { + pstMonitorInfo ->uchLowestChnlAppearedFlag = 1; + #if 0 == GH3X2X_FIFO_MONITOR_RAM_OPTIMIZE + GH3X2X_Memset((void*)pstMonitorInfo -> usRealTimeSampleCnt, 0, sizeof(pstMonitorInfo -> usRealTimeSampleCnt)); + #endif + pstMonitorInfo -> usAllChnlRealTimeSampleCnt = 0; + #if GH3X2X_FIFO_MONITOR_DEBUG + GH3X2X_Memset((void*)pstMonitorInfo -> usEveryChnlRealTimeSampleCnt, 0, sizeof(pstMonitorInfo -> usEveryChnlRealTimeSampleCnt)); + #endif + pstMonitorInfo->usAllChnlRealTimeSampleCnt = 0; + } + } + else + { + if(pstMonitorInfo ->usNeedSkipFifoByteNum < GH3X2X_FIFO_RAWDATA_SIZE) + { + pstMonitorInfo ->usNeedSkipFifoByteNum = 0; + } + else + { + pstMonitorInfo ->usNeedSkipFifoByteNum -= GH3X2X_FIFO_RAWDATA_SIZE; + } + } + } +} + +#endif + + +#if __DRIVER_OPEN_ALL_SOURCE__ +void GH3X2X_CalRawdataBuf(GU8 *puchRawdata, GU16 usRawdataLen) +{ + +} + +GU8 GH3X2X_CheckRawdataBuf(GU8 *puchRawdata, GU16 usRawdataLen) +{ + return 0; +} + + +/** + * @fn GS16 GH3X2X_ReadFifodata(GU8 *puchGh3x2xReadFifoData, GU16* pusReadFifoDataLen) + * + * @brief Read Gh3x2x Fifo Data for open source + * + * @attention None + * + * @param[in] None + * @param[out] puchGh3x2xReadFifoData pointer to Gh3x2x fifo data + * @param[out] pusReadFifoDataLen pointer to Gh3x2x fifo data length in byte + * + * @return error code + * @retval #GH3X2X_RET_OK return read fifo successful + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo is not empty + */ +GS16 GH3X2X_ReadFifodata(GU8 *puchGh3x2xReadFifoData, GU16* pusReadFifoDataLen ,GU16 usFifoReadByteNum) +{ + //GU16 usFifoLength = 0; + GS16 sRet = GH3X2X_RET_OK; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((puchGh3x2xReadFifoData != GH3X2X_PTR_NULL) && (pusReadFifoDataLen != GH3X2X_PTR_NULL)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + /* + usFifoLength = GH3X2X_FIFO_CNT_CALC(GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR)); + */ + if (usFifoReadByteNum > g_usMaxNumReadFromFifo) + { + usFifoReadByteNum = g_usMaxNumReadFromFifo; + sRet = GH3X2X_RET_READ_FIFO_CONTINUE; + } + + if ((usFifoReadByteNum > 0) && (usFifoReadByteNum <= GH3X2X_FIFO_DATA_BYTES_MAX_LEN)) + { + GH3X2X_ReadFifo(puchGh3x2xReadFifoData, usFifoReadByteNum); + } + else + { + if (usFifoReadByteNum > GH3X2X_FIFO_DATA_BYTES_MAX_LEN) + { + usFifoReadByteNum = 0; + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo len greater than max, pelease check i2c/spi!\r\n"); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo equl 0!\r\n"); + } + } + + /* call hook */ + HOOK_FUNC_CALL(g_pGh3x2xGetRawdataHookFunc, (puchGh3x2xReadFifoData, usFifoReadByteNum) ); + GH3X2X_WAIT_CHIP_DSLP(); + (*pusReadFifoDataLen) = usFifoReadByteNum; + }// if (pstGh3x2xRawdata->puchReadBuffer != GH3X2X_PTR_NULL) + else + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata error that pointer is null!\r\n"); + sRet = GH3X2X_RET_PARAMETER_ERROR; + } + + //SET_VAL_VIA_PTR(usFifoReadByteNum, usFifoLength); + return sRet; +} + +GS16 GH3X2X_CascadeReadFifodata(GU8 *puchGh3x2xReadFifoDataCascade, GU8 *puchGh3x2xReadFifoDataSingleBuf, GU16* pusReadFifoDataLen ,GU16 usFifoReadByteNum, GU8 uchChip2ChannelMap) +{ + //GU16 usFifoLength = 0; + GS16 sRet = GH3X2X_RET_OK; + GU16 usIndex = 0; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((puchGh3x2xReadFifoDataCascade != GH3X2X_PTR_NULL) && (puchGh3x2xReadFifoDataSingleBuf != GH3X2X_PTR_NULL) \ + && (pusReadFifoDataLen != GH3X2X_PTR_NULL)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + /* + usFifoLength = GH3X2X_FIFO_CNT_CALC(GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR)); + */ + if (usFifoReadByteNum > g_usMaxNumReadFromFifo) + { + usFifoReadByteNum = g_usMaxNumReadFromFifo; + sRet = GH3X2X_RET_READ_FIFO_CONTINUE; + } + + if ((usFifoReadByteNum > 0) && (usFifoReadByteNum <= GH3X2X_FIFO_DATA_BYTES_MAX_LEN)) + { + //GH3X2X_CascadeOperationMasterChip(); + GH3X2X_ReadFifo(puchGh3x2xReadFifoDataSingleBuf, (usFifoReadByteNum / 4) * 4); + GU32* punGh3x2xReadFifoDataCascade = (GU32* )puchGh3x2xReadFifoDataCascade; + GU32* punGh3x2xReadFifoDataSingleBuf =(GU32* ) puchGh3x2xReadFifoDataSingleBuf; + for (usIndex = 0; usIndex< usFifoReadByteNum / 4; usIndex++) + { + punGh3x2xReadFifoDataCascade[2*usIndex] = punGh3x2xReadFifoDataSingleBuf[usIndex]; + } + + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_ReadFifo(puchGh3x2xReadFifoDataSingleBuf, (usFifoReadByteNum / 4) * 4); + GH3X2X_CascadeOperationMasterChip(); + for (usIndex = 0; usIndex< usFifoReadByteNum / 4; usIndex++) + { + punGh3x2xReadFifoDataSingleBuf[usIndex] &= 0xffffff07; + punGh3x2xReadFifoDataSingleBuf[usIndex] |= uchChip2ChannelMap; + punGh3x2xReadFifoDataCascade[2*usIndex + 1] = punGh3x2xReadFifoDataSingleBuf[usIndex]; + } + } + else + { + if (usFifoReadByteNum > GH3X2X_FIFO_DATA_BYTES_MAX_LEN) + { + usFifoReadByteNum = 0; + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo len greater than max, pelease check i2c/spi!\r\n"); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo equl 0!\r\n"); + } + } + + /* call hook */ + HOOK_FUNC_CALL(g_pGh3x2xGetRawdataHookFunc, (puchGh3x2xReadFifoDataCascade, usFifoReadByteNum * 2) ); + GH3X2X_WAIT_CHIP_DSLP(); + }// if (pstGh3x2xRawdata->puchReadBuffer != GH3X2X_PTR_NULL) + else + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata error that pointer is null!\r\n"); + sRet = GH3X2X_RET_PARAMETER_ERROR; + } + + //SET_VAL_VIA_PTR(usFifoReadByteNum, usFifoLength); + (*pusReadFifoDataLen) = usFifoReadByteNum * 2; + return sRet; +} +#endif + + + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_dump.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_dump.c new file mode 100644 index 000000000..2159fc9db --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_dump.c @@ -0,0 +1,2721 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_dump.c + * + * @brief gh3x2x dump data functions + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" +#include "gh_uprotocol.h" +#include "gh_drv_dump.h" +#include "gh_agc.h" + +/// dump mode +GU16 g_usDumpMode; //bit0: GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT bit1: GH3X2X_DUMP_AMBIANCE_ENABLE_BIT bit2: GH3X2X_DUMP_ELECTR_WEAR_ENABLE_BIT + +/// electrode wear status +GU8 g_uchElectrodeWearStatus; + +/// save bg cancel value of every channel +extern GU8 g_puchGainBgCancelRecord[GH3X2X_CHANNEL_MAP_MAX_CH]; +/// save agc info of every channel +// extern STGh3x2xAgcInfo g_stGh3x2xAgcInfo; +/** + * @fn GU16 GH3X2X_DumpModeGet(void) + * + * @brief get dump mode + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return dump mode + */ +GU16 GH3X2X_DumpModeGet(void) +{ + return g_usDumpMode; +} + +/** + * @fn void GH3X2X_DumpModeSet(GU16 usRegVal) + * + * @brief set dump mode + * + * @attention None + * + * @param[in] usRegVal reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_DumpModeSet(GU16 usRegVal) +{ + g_usDumpMode = usRegVal; +} + + +const GU16 g_usGH3x2xSlotRegBase[8] = +{ + 0x0100, + 0x011C, + 0x0138, + 0x0154, + 0x0170, + 0x018C, + 0x01A8, + 0x01C4, +}; + +const STGh3x2xAgcReg g_pstGH3x2xAgcReg[] = +{ + {0x10, 9, 8}, //0: agc en + {0x22, 7, 0}, //1: led current up limit + {0x22, 15, 8}, //2: led current down limit + {0x1E, 7, 0}, //3: led current drv0 + {0x20, 7, 0}, //4: led current drv1 + {0x12, 3, 0}, //5: rx0 tia gain + {0x12, 7, 4}, //6: rx1 tia gain + {0x12, 11, 8}, //7: rx2 tia gain + {0x12, 15, 12}, //8: rx3 tia gain + {0x10, 7,6}, //9: agc src + {0x1A, 1,0}, //10: rx0 bg cancel + {0x1A, 3,2}, //11: rx1 bg cancel + {0x1A, 5,4}, //12: rx2 bg cancel + {0x1A, 7,6}, //13: rx2 bg cancel + {0x0A, 15,8}, //14: sr mulipliper + {0x0A, 5,1}, //15: ecg en& rx0~rx1 en +}; + +const GU16 g_usGH3x2xTiaGainR[] = +{ + 10, + 25, + 50, + 75, + 100, + 250, + 500, + 750, + 1000, + 1250, + 1500, + 1750, + 2000, +}; + +void GH3x2xSetAgcReg(GU8 uchAgcReg, GU8 uchSlot, GU16 usValue) +{ + GH3X2X_WriteRegBitField(g_usGH3x2xSlotRegBase[uchSlot] + g_pstGH3x2xAgcReg[uchAgcReg].uchAddrOffset, g_pstGH3x2xAgcReg[uchAgcReg].uchLsb, g_pstGH3x2xAgcReg[uchAgcReg].uchMsb, usValue); +} + +GU16 GH3x2xGetAgcReg(GU8 uchAgcReg, GU8 uchSlot) +{ + return GH3X2X_ReadRegBitField(g_usGH3x2xSlotRegBase[uchSlot] + g_pstGH3x2xAgcReg[uchAgcReg].uchAddrOffset, g_pstGH3x2xAgcReg[uchAgcReg].uchLsb, g_pstGH3x2xAgcReg[uchAgcReg].uchMsb); +} + + +/** + * @fn void GH3X2X_ElectrWearDumpDataPro(GU8* puchRawdataTag, GU8 uchChMapIndex) + * + * @brief electrode wear dump data pro + * + * @attention None + * + * @param[in] puchRawdataTag data tag of rawdata + * @param[in] uchChMapIndex channel map index + * @param[out] None + * + * @return None + */ + /* +void GH3X2X_ElectrWearDumpDataPro(GU8* puchRawdataTag, GU8 uchChMapIndex) +{ + if (GH3X2X_CHECK_LEFT_BIT_SET(GH3X2X_DumpModeGet(), GH3X2X_DUMP_ELECTR_WEAR_ENABLE_BIT)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + g_uchElectrodeWearStatus = GH3X2X_ReadRegBitField(GH3X2X_INT_STR2_REG_ADDR, \ + GH3X2X_ELECTR_WEAR_STATUS_BIT_FIELD, GH3X2X_ELECTR_WEAR_STATUS_BIT_FIELD); + GH3X2X_WAIT_CHIP_DSLP(); + } +} +*/ + +/** + * @fn void GH3X2X_RecordGainBgCancelValue(void) + * + * @brief read gain and bg cancel value, and save them + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ + /* +void GH3X2X_RecordGainBgCancelValue(void) +{ + GU8 uchSlotIndexCnt = 0; + GU8 uchAdcIndexCnt = 0; + GU8 uchSlotAdcIndex = 0; + GU8 uchBgCancelValue = 0; + GU8 uchGainValue = 0; + GU16 usBgCancelRegData = 0; + GU16 usBgCancelRegAddr = 0; + GU16 usTiaGainRegData = 0; + GU16 usTiaGainRegAddr = 0; + + GH3X2X_WAIT_CHIP_WAKEUP(); + usBgCancelRegAddr = GH3X2X_SLOT0_CTRL_8_REG_ADDR; + usTiaGainRegAddr = GH3X2X_SLOT0_CTRL_4_REG_ADDR; + for (uchSlotIndexCnt = 0; uchSlotIndexCnt < GH3X2X_MAX_SLOT_NUM; uchSlotIndexCnt++) + { + usBgCancelRegData = GH3X2X_ReadReg(usBgCancelRegAddr); + usTiaGainRegData = GH3X2X_ReadReg(usTiaGainRegAddr); + for (uchAdcIndexCnt = 0; uchAdcIndexCnt < GH3X2X_ADC_NUM; uchAdcIndexCnt++) + { + uchBgCancelValue = (usBgCancelRegData >> (uchAdcIndexCnt * GH3X2X_ADC_BG_CANCEL_BIT_NUM)) \ + & GH3X2X_ADC_BG_CANCEL_BIT_MASK; + uchGainValue = (usTiaGainRegData >> (uchAdcIndexCnt * GH3X2X_ADC_TIA_GAIN_BIT_NUM)) \ + & GH3X2X_ADC_TIA_GAIN_BIT_MASK; + g_puchGainBgCancelRecord[uchSlotAdcIndex] = (GU8)(uchBgCancelValue << \ + GH3X2X_ADC_BG_CANCEL_LEFT_SHIFT_BIT_NUM); + g_puchGainBgCancelRecord[uchSlotAdcIndex] |= (GU8)(uchGainValue << GH3X2X_ADC_TIA_GAIN_LEFT_SHIFT_BIT_NUM); + uchSlotAdcIndex++; + } + usBgCancelRegAddr += SLOT_ADDR_OFFSET; + usTiaGainRegAddr += SLOT_ADDR_OFFSET; + } + GH3X2X_WAIT_CHIP_DSLP(); +} +*/ + +/** + * @fn void GH3X2X_RecordDrvCurrentValue(void) + * + * @brief read current value of drv0 and drv1, and save them + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_RecordDrvCurrentValue(void) +{ + GU8 uchSlotIndexCnt = 0; + GU16 usDrv0CurRegData = 0; + GU16 usDrv0CurRegAddr = 0; + GU16 usDrv1CurRegData = 0; + GU16 usDrv1CurRegAddr = 0; + + if ((GH3X2X_CHECK_LEFT_BIT_NOT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) && \ + (GH3X2X_CHECK_LEFT_BIT_NOT_SET(g_usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT))) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + usDrv0CurRegAddr = GH3X2X_SLOT0_CTRL_10_REG_ADDR; + usDrv1CurRegAddr = GH3X2X_SLOT0_CTRL_11_REG_ADDR; + for (uchSlotIndexCnt = 0; uchSlotIndexCnt < GH3X2X_MAX_SLOT_NUM; uchSlotIndexCnt++) + { + usDrv0CurRegData = (GH3X2X_ReadReg(usDrv0CurRegAddr + (uchSlotIndexCnt * GH3X2X_SLOT_CTRL_OFFSET)) & GH3X2X_DRV_CURRENT_BIT_MASK); + usDrv1CurRegData = (GH3X2X_ReadReg(usDrv1CurRegAddr + (uchSlotIndexCnt * GH3X2X_SLOT_CTRL_OFFSET)) & GH3X2X_DRV_CURRENT_BIT_MASK); + g_pstGh3x2xAgcInfo->uchDrvCurrentRecord[uchSlotIndexCnt] = (GU16)(usDrv0CurRegData << GH3X2X_DRV0_CURRENT_LEFT_SHIFT_BIT_NUM); + g_pstGh3x2xAgcInfo->uchDrvCurrentRecord[uchSlotIndexCnt] |= (GU16)(usDrv1CurRegData << GH3X2X_DRV1_CURRENT_LEFT_SHIFT_BIT_NUM); + } + GH3X2X_WAIT_CHIP_DSLP(); + } +} + +/** + * @fn void GH3X2X_RecordDumpData(void) + * + * @brief read some dump data, and save them + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_RecordDumpData(void) +{ + GH3X2X_RecordDrvCurrentValue(); +} + +/** + * @fn void GH3X2X_UpdateAgcInfo(void) + * + * @brief record tia gain and drv information + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_UpdateAgcInfo(void) +{ + GH3X2X_Memcpy(g_pstGh3x2xAgcInfo->uchTiaGainRecord, g_pstGh3x2xAgcInfo->uchTiaGainAfterSoftAgc, sizeof(g_pstGh3x2xAgcInfo->uchTiaGainRecord)); + GH3X2X_Memcpy(g_pstGh3x2xAgcInfo->uchDrvCurrentRecord, g_pstGh3x2xAgcInfo->uchDrvCurrentAfterSoftAgc, sizeof(g_pstGh3x2xAgcInfo->uchDrvCurrentRecord)); + GH3X2X_DEBUG_LOG_PARAM("RecordTiaGainInfo slot0: rx0 = %d, rx1 = %d, rx2 = %d, rx3 = %d\r\n" ,g_pstGh3x2xAgcInfo->uchTiaGainRecord[0],g_pstGh3x2xAgcInfo->uchTiaGainRecord[1],g_pstGh3x2xAgcInfo->uchTiaGainRecord[2],g_pstGh3x2xAgcInfo->uchTiaGainRecord[3]); + GH3X2X_DEBUG_LOG_PARAM("uchDrvCurrentRecord slot0: drv = %d\r\n" ,g_pstGh3x2xAgcInfo->uchDrvCurrentRecord[0]); +} + + +#if GH3X2X_DUMP_MODE_EN + +/// dump data cnt map @ref EMGh3x2xDumpRawdataBgLvlSelect +const GU8 g_uchDumpDataCntMapArr[] = +{ + 2, // lvl 0 + 3, // lvl 1 + 4, // lvl 2 + 2 // lvl 2x2 /* regard the second slot of 2x2 as a separate slot*/ +}; + +/// div num of dump data map @ref EMGh3x2xDumpRawdataBgLvlSelect +const GU8 g_uchRawdataDivOfDumpDataMapArr[] = +{ + 1, // lvl 0 + 1, // lvl 1 + 2, // lvl 2 + 2 // lvl 2x2 +}; + +/// rawdata index of dump data map @ref EMGh3x2xDumpRawdataBgLvlSelect +const GU8 g_uchRawdataIndexOfDumpDataMapArr[] = +{ + 1, // lvl 0 + 2, // lvl 1 + 2, // lvl 2 + 0 // lvl 2x2 +}; + + + +/// bg level +GU16 g_usBgLevel; + +/// hbd rawdata incomplete array +GU8 g_uchHbaIncompleteArr[GH3X2X_HBA_CHANNEL_MAP_MAX_CNT]; + +/// hbd dumpdata incomplete buffer +GU32 g_unHbaIncompleteDumpdataArr[GH3X2X_HBA_CHANNEL_MAP_MAX_CNT][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL] = {{0}}; + +/// hrv rawdata incomplete array +GU8 g_uchHrvIncompleteArr[GH3X2X_HRV_CHANNEL_MAP_MAX_CNT]; + +/// hrv dumpdata incomplete buffer +GU32 g_unHrvIncompleteDumpdataArr[GH3X2X_HRV_CHANNEL_MAP_MAX_CNT][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL] = {{0}}; + +/// spo2 rawdata incomplete array +GU8 g_uchSpo2IncompleteArr[GH3X2X_SPO2_CHANNEL_MAP_MAX_CNT]; + +/// spo2 dumpdata incomplete buffer +GU32 g_unSpo2IncompleteDumpdataArr[GH3X2X_SPO2_CHANNEL_MAP_MAX_CNT][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL] = {{0}}; + +/// dump data after filter from rawdata which will be uploaded +GU32 g_punDumpDataUploadArr[GH3X2X_MAX_DUMP_DATA_NUM_UPLOAD] = {0}; + + + +/// incomplete rawdata flag array for filter data +GU8 g_uchDumpIncompleteFlagArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + +/// incomplete rawdata buffer for filter data +GU32 g_unDumpIncompleteRawdataArr[GH3X2X_CHANNEL_MAP_MAX_CH][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL] = {{0}}; + +/// save rawdata after filter +GU8 g_uchRawdataFilterArr[RAWDATA_FILTER_ARRAY_BYTE_LENGTH]; + +/// bg level of every channel +GU8 g_uchChannelBgLvlArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + +/// save slot which used for ECG +GU8 g_uchEcgSlot; + +// Zipdumpmode Tempdata +STZipLastDataTemp g_stZipDumpTempData; + +// Zip Package Num Even/Odd Flag +GU8 g_uchDumpOddEvenChangeFlag = 1; + + + + + + +/** + * @fn void GH3X2X_ReadElectrodeWearDumpData(void) + * + * @brief read eletrode wear status + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return dump mode + */ + /* +void GH3X2X_ReadElectrodeWearDumpData(void) +{ + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_ELECTR_WEAR_ENABLE_BIT)) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + g_uchElectrodeWearStatus = GH3X2X_ReadRegBitField(GH3X2X_INT_STR2_REG_ADDR, \ + GH3X2X_ELECTR_WEAR_STATUS_BIT_FIELD, GH3X2X_ELECTR_WEAR_STATUS_BIT_FIELD); + GH3X2X_WAIT_CHIP_DSLP(); + } +} +*/ + + + + + +/** + * @fn void GH3X2X_BgLevelDecode(GU8 puchBgLvArr[], GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU16 usBgLevel) + * + * @brief decode function's bg level array according to channel map and slot bg level + * + * @attention if there is 2x2 bg level,set the first slot to level 2 + * + * @param[in] uchChannelCnt channel cnt + * @param[in] puchChannelMapArray channel map array + * @param[in] usBgLevel bg level of slot + * @param[out] puchBgLvArray bg level array + * + * @return None + */ +void GH3X2X_BgLevelDecode(GU8 puchBgLvArr[], GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU16 usBgLevel) +{ + GU8 uchChCnt = 0; + GU8 uchSlotCnt = 0; + GU8 uchBgLv2x2Cnt = 0; + GU8 uchSlotNum = 0; + GU16 usBgLvTemp = usBgLevel; + + //if BgLevel has level 2x2,change the first slot of 2x2 slot to level 2 + for (uchSlotCnt = 0; uchSlotCnt < GH3X2X_MAX_SLOT_NUM; uchSlotCnt++) + { + if (GH3X2X_DUMP_RAWDATA_BGLVL2X2 == ((usBgLevel >> (uchSlotCnt << 1)) & GH3X2X_SLOT_BG_LEVEL_BIT_MASK)) + { + if (0 == uchBgLv2x2Cnt) + { + uchBgLv2x2Cnt++; + } + else + { + //set last slot bg level as GH3X2X_DUMP_RAWDATA_BGLVL2 + usBgLvTemp &= ~(GH3X2X_SLOT_BG_LEVEL_BIT_MASK << ((uchSlotCnt - 1) << 1)); + usBgLvTemp |= GH3X2X_DUMP_RAWDATA_BGLVL2 << ((uchSlotCnt - 1) << 1); + uchBgLv2x2Cnt = 0; + } + } + else + { + uchBgLv2x2Cnt = 0; + } + } + + for (uchChCnt = 0; uchChCnt < uchChannelCnt; uchChCnt++) + { + uchSlotNum = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(puchChannelMapArray[uchChCnt]); + puchBgLvArr[uchChCnt] = (usBgLvTemp >> (uchSlotNum << 1)) & GH3X2X_SLOT_BG_LEVEL_BIT_MASK; + } +} + +/** + * @fn void GH3X2X_GetChannelBgLevel(GU16 usBgLevel) + * + * @brief get bg level of every channel + * + * @attention if there is two 2x2 bg level,set the first 2x2 slot to bg level 2 + * + * @param[in] usBgLevel slot bg level + * @param[out] None + * + * @return None + */ +void GH3X2X_GetChannelBgLevel(GU16 usBgLevel) +{ + GU8 uchSlotCnt = 0; + GU8 uchChBgLvl = 0; + GU8 uchBhLvl2x2FirstSlot = 1; + + GH3X2X_Memset(g_uchChannelBgLvlArr, 0, sizeof(g_uchChannelBgLvlArr[0]) * GH3X2X_CHANNEL_MAP_MAX_CH); + + for (uchSlotCnt = 0; uchSlotCnt < GH3X2X_MAX_SLOT_NUM; ++uchSlotCnt) + { + uchChBgLvl = (usBgLevel >> (uchSlotCnt << 1)) & GH3X2X_SLOT_BG_LEVEL_BIT_MASK; + if (GH3X2X_DUMP_RAWDATA_BGLVL2X2 == uchChBgLvl) + { + if (uchBhLvl2x2FirstSlot) + { + uchChBgLvl = GH3X2X_DUMP_RAWDATA_BGLVL2; + uchBhLvl2x2FirstSlot = 0; + } + else + { + uchBhLvl2x2FirstSlot = 1; + } + } + else + { + if (0 == uchBhLvl2x2FirstSlot) + { + GH3X2X_DEBUG_LOG_PARAM("%s 2x2 Bg Level set error.\r\n", __FUNCTION__); + uchBhLvl2x2FirstSlot = 1; + } + } + + GH3X2X_Memset(&g_uchChannelBgLvlArr[uchSlotCnt * GH3X2X_ADC_NUM], uchChBgLvl, \ + sizeof(g_uchChannelBgLvlArr[0]) * GH3X2X_ADC_NUM); + } +} + +/** + * @fn void GH3X2X_BgLevelSet(GU16 usRegVal) + * + * @brief set bg level of every slot + * + * @attention None + * + * @param[in] usRegVal reg value + * @param[out] None + * + * @return None + */ +void GH3X2X_BgLevelSet(GU16 usRegVal) +{ + g_usBgLevel = usRegVal; +} + +/** + * @fn void GH3X2X_GetEcgSlot(void) + * + * @brief get slot used for ecg + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_GetEcgSlot(void) +{ + GU16 usEcgEnRegData = 0; + GU16 usEcgEnRegAddr = 0; + GU8 uchSlotIndexCnt = 0; + + GH3X2X_WAIT_CHIP_WAKEUP(); + g_uchEcgSlot = 0; + usEcgEnRegAddr = GH3X2X_SLOT0_CTRL_0_REG_ADDR; + for (uchSlotIndexCnt = 0; uchSlotIndexCnt < GH3X2X_MAX_SLOT_NUM; ++uchSlotIndexCnt) + { + usEcgEnRegData = GH3X2X_ReadReg(usEcgEnRegAddr); + if (GH3X2X_CHECK_BIT_SET(usEcgEnRegData, GH3X2X_ECG_ENABLE_BIT)) + { + GH3X2X_VAL_SET_BIT(g_uchEcgSlot, (GU16)GH3X2X_GET_LEFT_SHIFT_VAL(uchSlotIndexCnt)); + } + usEcgEnRegAddr += SLOT_ADDR_OFFSET; + } + GH3X2X_WAIT_CHIP_DSLP(); +} + +/** + * @fn void GH3X2X_DumpInit(void) + * + * @brief init dump moudle + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_DumpInit(void) +{ + //if dump mode is not enable,just return + if (GH3X2X_CHECK_LEFT_BIT_NOT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT) && \ + GH3X2X_CHECK_LEFT_BIT_NOT_SET(g_usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + return; + } + + //when dump mode and agc are both enabled,should do this + //if (GH3X2X_LED_AGC_ENABLE == GH3X2X_GetLedAgcState()) + { + GH3X2X_Memset(g_uchDumpIncompleteFlagArr, 0, \ + sizeof(g_uchDumpIncompleteFlagArr[0]) * GH3X2X_CHANNEL_MAP_MAX_CH); + GH3X2X_GetChannelBgLevel(g_usBgLevel); + GH3X2X_GetEcgSlot(); + } +} + +/** + * @fn GU8 GH3X2X_FindLastSlotChMapIndex(GU8* puchTargetChMapIndex, GU8 puchChMapArr[], + GU8 uchChMapCnt,GU8 uchChMapIndex) + * + * @brief Find target channel map index which slot id minus 1 than input channel map + * + * @attention None + * + * @param[out] puchTargetChMapIndex target channel map index + * @param[in] puchChMapArr[] channel map array + * @param[in] uchChMapCnt channel map cnt + * @param[in] uchChCntIndex channel cnt index + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_FindLastSlotChMapIndex(GU8* puchTargetChMapIndex, GU8 puchChMapArr[], GU8 uchChMapCnt, GU8 uchChCntIndex) +{ + GU8 uchSlotNum; + GU8 uchSlotNumTemp; + GU8 uchAdcNum; + GU8 uchAdcNumTemp; + GU8 i; + GS8 chRet = GH3X2X_RET_OK; + + if (GH3X2X_PTR_NULL == puchTargetChMapIndex) + { + return GH3X2X_RET_PARAMETER_ERROR; + } + + uchSlotNum = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(puchChMapArr[uchChCntIndex]); + uchAdcNum = GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(puchChMapArr[uchChCntIndex]); + + for (i = 0; i < uchChMapCnt; i++) + { + uchSlotNumTemp = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(puchChMapArr[i]); + uchAdcNumTemp = GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(puchChMapArr[i]); + if ((uchSlotNumTemp == (uchSlotNum - 1)) && (uchAdcNumTemp == uchAdcNum)) + { + *puchTargetChMapIndex = i; + break; + } + } + + if (i >= uchChMapCnt) + { + *puchTargetChMapIndex = uchChCntIndex; + GH3X2X_DEBUG_LOG_PARAM("Find channel map error!!!can not find last slot channel map\r\n"); + chRet = GH3X2X_RET_PARAMETER_ERROR; + } + + return chRet; +} + +/** + * @fn void GH3X2X_CacheIncompleteDumpdata(GU8 punLastIncompleteArr[], + * GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], + * GU8 uchNextIncompleteFlag, GU8 *puchFifoRawdata, GU16 usFifoRawdataLen, + * GU8 uchChannelMapArr[], GU8 uchChannelMapCnt, + * GU16 usRawdataByteIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH]) + * + * @brief cache incomplete rawdata packet for algorithm + * + * @attention None + * + * @param[out] puchIncompleteFlagArr incomplete flag array of every channel + * @param[out] punIncompleteDumpdataArr incomplete data array + * @param[in] uchNextIncompleteFlag incomplete flag to indicate if cache incomplete data + * @param[in] puchFifoRawdata fifo rawdata + * @param[in] usFifoRawdataLen fifo data length + * @param[in] uchChannelMapArr channel map array + * @param[in] uchChannelMapCnt channel map array cnt + * @param[in] usRawdataByteIndexArr start index of every channel to search data + * + * @return None + */ +void GH3X2X_CacheIncompleteDumpdata(GU8 puchIncompleteFlagArr[], + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], + GU8 uchNextIncompleteFlag, GU8 *puchFifoRawdata, GU16 usFifoRawdataLen, + GU8 uchChannelMapArr[], GU8 uchChannelMapCnt, + GU16 usRawdataByteIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH]) +{ + GU16 usRawdataByteIndexTmp = 0; + GU8 uchChCntIndex = 0; + GU8 uchDumpDataIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; + + GH3X2X_Memset(puchIncompleteFlagArr, 0, sizeof(puchIncompleteFlagArr[0]) * GH3X2X_CHANNEL_MAP_MAX_CH); + + if (uchNextIncompleteFlag != 0) + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // search each channel + { + usRawdataByteIndexTmp = usRawdataByteIndexArr[uchChCntIndex]; + while (usRawdataByteIndexTmp < usFifoRawdataLen) // search each + { + if (GH3X2X_CHANNEL_MAP_GET(puchFifoRawdata[usRawdataByteIndexTmp]) == \ + uchChannelMapArr[uchChCntIndex]) // if map equal + { + GH3X2X_Memcpy(&punIncompleteDumpdataArr[uchChCntIndex][uchDumpDataIndexArr[uchChCntIndex]], + &puchFifoRawdata[usRawdataByteIndexTmp], GH3X2X_FIFO_RAWDATA_SIZE); + puchIncompleteFlagArr[uchChCntIndex] |= \ + (GU8)GH3X2X_GET_LEFT_SHIFT_VAL(uchDumpDataIndexArr[uchChCntIndex]); + uchDumpDataIndexArr[uchChCntIndex]++; + } + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + } +} + +/** + * @fn GS8 GH3X2X_GetDumpDataInfo(GF32 *pfGsFloatIncVal, GU16 *pusChannelDataCnt, + * GU8 *puchNextIncompleteFlag,GU8 *puchDumpDataIndexArr, + * GU8 *puchIncompleteFlagArr, GU16 usFifoLength, GU8 *puchDataBuffer, + * GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU8 *puchChannelBgLvlArr, + * GU16 usReadGsensorArrCnt) + * + * @brief Get information from rawdata + * + * @attention None + * + * @param[out] pfGsFloatIncVal pointer to gsensor inc value output + * @param[out] pusChannelDataCnt pointer to slot data cnt output + * @param[out] puchNextIncompleteFlag pointer to next incomplete flag arr output + * @param[out] puchDumpDataIndexArr pointer to dump data index output + * @param[in] puchIncompleteFlagArr incomplete flag array of last rawdata frame + * @param[in] usFifoLength read fifo buffer data len + * @param[in] puchDataBuffer pointer to read fifo buffer + * @param[in] uchChannelCnt channel map arr cnt + * @param[in] puchChannelMapArray pointer to channel map arr + * @param[in] puchChannelBgLvlArr pointer to bg lvl arr + * @param[in] usReadGsensorArrCnt read gsensor array cnt + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR generic error when size is 0 + * @retval #GH3X2X_RET_RESOURCE_ERROR resource error when doesn't correspond to channel map + */ +GS8 GH3X2X_GetDumpDataInfo(GF32 *pfGsFloatIncVal, GU16 *pusChannelDataCnt, + GU8 *puchNextIncompleteFlag, GU8 *puchDumpDataIndexArr, + GU8 *puchIncompleteFlagArr, GU16 usFifoLength, GU8 *puchDataBuffer, + GU8 uchChannelCnt, GU8 *puchChannelMapArray, GU8 *puchChannelBgLvlArr, + GU16 usReadGsensorArrCnt) +{ + GF32 fGsensorFloatIncTmp = GH3X2X_GF32_0; + GU16 usRawdataCntArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; + GU16 usRawdataCntTmp = 0; + GU16 usRawdataCntMaxTmp = 0; + GU16 usRawdataCntMinTmp = 0; + GU16 usRawdataAllCntMax = 0; + GU8 uchChCntIndexTmp = 0; + GU8 uchCalcCntIndexTmp = 0; + GU8 uchDumpDataCalcTmp = 0; + GU16 usRawdataIndexTmp = 0; + GU8 uchDumpDataCntCalcErrFlag = 0; + GU8 uchNextIncompleteFlagTmp = 0; + GU16 usDumpDataCntArr[DUMP_DATA_MAX_NUM] = {0}; + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + if ((pfGsFloatIncVal == GH3X2X_PTR_NULL) || (pusChannelDataCnt == GH3X2X_PTR_NULL) + || (puchNextIncompleteFlag == GH3X2X_PTR_NULL) || (puchDumpDataIndexArr == GH3X2X_PTR_NULL) + || (puchIncompleteFlagArr == GH3X2X_PTR_NULL) || (puchDataBuffer == GH3X2X_PTR_NULL) + || (puchChannelMapArray == GH3X2X_PTR_NULL) || (puchChannelBgLvlArr == GH3X2X_PTR_NULL)) + { + return GH3X2X_RET_PARAMETER_ERROR; + } + + for (uchChCntIndexTmp = 0; uchChCntIndexTmp < uchChannelCnt; uchChCntIndexTmp++) + { + GH3X2X_Memset(usDumpDataCntArr, 0, sizeof(GU16) * DUMP_DATA_MAX_NUM); + uchCalcCntIndexTmp = 0; + uchDumpDataCalcTmp = g_uchDumpDataCntMapArr[puchChannelBgLvlArr[uchChCntIndexTmp]]; + for (usRawdataIndexTmp = 0; usRawdataIndexTmp < uchDumpDataCalcTmp; usRawdataIndexTmp ++) + { + if (GH3X2X_CHECK_LEFT_BIT_SET(puchIncompleteFlagArr[uchChCntIndexTmp], uchCalcCntIndexTmp)) + { + usDumpDataCntArr[uchCalcCntIndexTmp]++; + uchCalcCntIndexTmp++; + puchDumpDataIndexArr[uchChCntIndexTmp]++; // calc start index for get data + } + } + for (usRawdataIndexTmp = 0; usRawdataIndexTmp < usFifoLength; usRawdataIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE) + { + if (puchChannelMapArray[uchChCntIndexTmp] == GH3X2X_CHANNEL_MAP_GET(puchDataBuffer[usRawdataIndexTmp])) + { + usDumpDataCntArr[uchCalcCntIndexTmp%uchDumpDataCalcTmp]++; + uchCalcCntIndexTmp++; + } + } + GH3X2X_FindGu16MaxMinVal(&usRawdataCntMaxTmp, &usRawdataCntMinTmp, usDumpDataCntArr, uchDumpDataCalcTmp); + if (usRawdataAllCntMax < usRawdataCntMaxTmp) + { + usRawdataAllCntMax = usRawdataCntMaxTmp; // calc all data cnt max + } + if (usRawdataCntMinTmp == usRawdataCntMaxTmp) + { + usRawdataCntArr[uchChCntIndexTmp] = usRawdataCntMinTmp; + } + else + { + for (usRawdataIndexTmp = 0; usRawdataIndexTmp < (uchDumpDataCalcTmp - 1); usRawdataIndexTmp ++) // checkcnt + { + if (usDumpDataCntArr[usRawdataIndexTmp] < usDumpDataCntArr[usRawdataIndexTmp + 1]) // if next>this, err + { + uchDumpDataCntCalcErrFlag = 1; + break; + } + } + if (uchDumpDataCntCalcErrFlag == 0) + { + usRawdataCntArr[uchChCntIndexTmp] = usRawdataCntMinTmp; + uchNextIncompleteFlagTmp = 1; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("dump data of buffer error!\r\n"); + break; + } + } + } // end of for (uchChCntIndexTmp = 0; uchChCntIndexTmp < uchChannelCnt; uchChCntIndexTmp++) + if (uchDumpDataCntCalcErrFlag == 0) + { + GH3X2X_FindGu16MaxMinVal(&usRawdataCntMaxTmp, &usRawdataCntMinTmp, usRawdataCntArr, uchChannelCnt); + if (usRawdataCntMaxTmp == usRawdataCntMinTmp) + { + usRawdataCntTmp = usRawdataCntMaxTmp; // whatever last data complete or incomplete + } + else + { + if (((usRawdataCntMaxTmp - usRawdataCntMinTmp) == 1) && (usRawdataAllCntMax == usRawdataCntMaxTmp)) + { + usRawdataCntTmp = usRawdataCntMinTmp; + uchNextIncompleteFlagTmp = 1; + } + else // cnt tolerable deviation is 1 + { + GH3X2X_DEBUG_LOG_PARAM("dump data doesn't correspond to channel map error!\r\n"); + usRawdataCntTmp = 0; + uchNextIncompleteFlagTmp = 0; + chRet = GH3X2X_RET_RESOURCE_ERROR; + } + } // end of if (usRawdataCntMaxTmp == usRawdataCntMinTmp) + + if (usRawdataCntTmp > 0) + { + chRet = GH3X2X_RET_OK; + if ((usRawdataCntTmp > 1) && (usReadGsensorArrCnt > 0)) // calc gs index + { + fGsensorFloatIncTmp = ((GF32)(usReadGsensorArrCnt - 1)) / (usRawdataCntTmp - 1); + } + } + } // end of if (uchDumpDataCntCalcErrFlag == 0) + SET_VAL_VIA_PTR(pfGsFloatIncVal, fGsensorFloatIncTmp); // set gsensor increasing val + SET_VAL_VIA_PTR(pusChannelDataCnt, usRawdataCntTmp); // channel data count + SET_VAL_VIA_PTR(puchNextIncompleteFlag, uchNextIncompleteFlagTmp); // channel data count max + return chRet; +} + +/** + * @fn GS8 GH3X2X_UnpackDumpDataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + * GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, + * GU8 *puchChannelBgLvlArr) + * + * @brief Unpack to channel dump data from read fifo data buffer; + * if dump data incomplete, should change fifo watermark + * + * @attention This function should use in get rawdata hook + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] usReadRawdataLen read data length + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[in] puchChannelBgLvlArr pointer to channel lvl array, @ref EMGh3x2xDumpRawdataBgLvlSelect + * @param[out] pstGh3x2xChannelDumpData pointer to channel rawdata struct + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_UnpackDumpDataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + GU8 *puchReadRawdataBuffer, GU16 usReadRawdataLen, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, + GU8 *puchChannelBgLvlArr) +{ + GU8 uchChCntIndex = 0; + GU16 usRawdataIndex = 0; + GU16 usRawdataCnt = 0; + GU16 usRawdataIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; // use for rawdata cnt & rawdata bytes index + GU16 usRawdataByteIndexTmp = 0; + GU16 usRawdataBaseIndex = 0; + GU8 uchCalcCntIndex = 0; + GU8 uchDumpDataCalcTmp = 0; + GU8 uchNextIncompleteFlag = 0; + GU8 uchDumpDataIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; + GU32 unRawdataSum = 0; + GF32 fGsensorFloatIndexInc = GH3X2X_GF32_0; + GU8 uchLastSlotChIndex = 0; + GS8 chRet = GH3X2X_RET_OK; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + + /* check pram */ + if ((pstGh3x2xChannelDumpData->punIncompleteChRawdataArr == GH3X2X_PTR_NULL) + || (pstGh3x2xChannelDumpData->punChBgRawdataArr == GH3X2X_PTR_NULL) + || (pstGh3x2xChannelDumpData->punChRawdataArr == GH3X2X_PTR_NULL) + || (pstGh3x2xChannelDumpData->punPkgNoAndCurrentArr == GH3X2X_PTR_NULL) + || (puchReadRawdataBuffer == GH3X2X_PTR_NULL) + || (puchChannelBgLvlArr == GH3X2X_PTR_NULL) + || (pstGh3x2xChannelDumpData == GH3X2X_PTR_NULL) || (puchChannelMapArr == GH3X2X_PTR_NULL)) + { + GH3X2X_DEBUG_LOG_PARAM("pointer param set null error!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + if (GH3X2X_CLEAR_BIT(puchChannelMapArr[uchChCntIndex], GH3X2X_SLOT_ADC_NUM_BITS) != 0) + { + GH3X2X_DEBUG_LOG_PARAM("channel map error! set @ref GH3X2X_CHANNEL_MAP!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + if (puchChannelBgLvlArr[uchChCntIndex] > GH3X2X_DUMP_RAWDATA_BGLVL2X2) + { + GH3X2X_DEBUG_LOG_PARAM("dump lvl error! set @ref EMGh3x2xDumpRawdataBgLvlSelect!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + } + if (uchChannelMapCnt > GH3X2X_CHANNEL_MAP_MAX_CH) + { + GH3X2X_DEBUG_LOG_PARAM("channel cnt greater than max!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + + /* calc rawdata len */ + chRet = GH3X2X_GetDumpDataInfo(&fGsensorFloatIndexInc, &usRawdataCnt, &uchNextIncompleteFlag, uchDumpDataIndexArr, + pstGh3x2xChannelDumpData->uchChIncompleteFlagArr, usReadRawdataLen, puchReadRawdataBuffer, + uchChannelMapCnt, puchChannelMapArr, puchChannelBgLvlArr, 0); + if (chRet == GH3X2X_RET_OK) + { + for (usRawdataIndex = 0; usRawdataIndex < usRawdataCnt; usRawdataIndex++) + { + usRawdataBaseIndex = usRawdataIndex * (GU16)uchChannelMapCnt; + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // search each channel + { + uchDumpDataCalcTmp = g_uchDumpDataCntMapArr[puchChannelBgLvlArr[uchChCntIndex]]; + if (uchDumpDataIndexArr[uchChCntIndex] < uchDumpDataCalcTmp) + { + usRawdataByteIndexTmp = usRawdataIndexArr[uchChCntIndex]; + while (usRawdataByteIndexTmp < usReadRawdataLen) // search each + { + if (GH3X2X_CHANNEL_MAP_GET(puchReadRawdataBuffer[usRawdataByteIndexTmp]) == \ + puchChannelMapArr[uchChCntIndex]) // if map equal + { + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchChCntIndex]\ + [uchDumpDataIndexArr[uchChCntIndex]] = \ + GH3X2X_RAWDATA_CLEAR_SLOT_ADC_NUM( + GH3X2X_MAKEUP_DWORD(puchReadRawdataBuffer[usRawdataByteIndexTmp], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 1], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 2], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 3])); + uchDumpDataIndexArr[uchChCntIndex]++; + if (uchDumpDataIndexArr[uchChCntIndex] >= uchDumpDataCalcTmp) + { + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + break; + } + } + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + uchDumpDataIndexArr[uchChCntIndex] = 0; + + usRawdataIndexArr[uchChCntIndex] = usRawdataByteIndexTmp; // write back byte index + } // end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // process each channel dump data + { + if (GH3X2X_DUMP_RAWDATA_BGLVL2X2 != puchChannelBgLvlArr[uchChCntIndex]) + { + pstGh3x2xChannelDumpData->punPkgNoAndCurrentArr[usRawdataBaseIndex + uchChCntIndex] = \ + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchChCntIndex][0]; + pstGh3x2xChannelDumpData->punChRawdataArr[usRawdataBaseIndex + uchChCntIndex] = \ + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchChCntIndex]\ + [g_uchRawdataIndexOfDumpDataMapArr[puchChannelBgLvlArr[uchChCntIndex]]]; + unRawdataSum = 0; + for (uchCalcCntIndex = 1; + uchCalcCntIndex < g_uchDumpDataCntMapArr[puchChannelBgLvlArr[uchChCntIndex]]; + uchCalcCntIndex++) + { + if (uchCalcCntIndex != g_uchRawdataIndexOfDumpDataMapArr[puchChannelBgLvlArr[uchChCntIndex]]) + { + unRawdataSum += \ + GH3X2X_RAWDATA_CLEAR_ALL_FLAG(\ + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchChCntIndex][uchCalcCntIndex]); + } + } + pstGh3x2xChannelDumpData->punChBgRawdataArr[usRawdataBaseIndex + uchChCntIndex] = \ + (unRawdataSum / g_uchRawdataDivOfDumpDataMapArr[puchChannelBgLvlArr[uchChCntIndex]]) | \ + GH3X2X_RAWDATA_CLEAR_DATA(\ + pstGh3x2xChannelDumpData->punChRawdataArr[usRawdataBaseIndex + uchChCntIndex]); + } + else + { + GH3X2X_FindLastSlotChMapIndex(&uchLastSlotChIndex, puchChannelMapArr, \ + uchChannelMapCnt, uchChCntIndex); + pstGh3x2xChannelDumpData->punPkgNoAndCurrentArr[usRawdataBaseIndex + uchChCntIndex] = \ + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchLastSlotChIndex][0]; + pstGh3x2xChannelDumpData->punChRawdataArr[usRawdataBaseIndex + uchChCntIndex] = \ + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchChCntIndex][0]; + unRawdataSum = pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchLastSlotChIndex]\ + [g_uchRawdataIndexOfDumpDataMapArr[puchChannelBgLvlArr[uchLastSlotChIndex]] + 1] + + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchChCntIndex]\ + [g_uchRawdataIndexOfDumpDataMapArr[puchChannelBgLvlArr[uchChCntIndex]] + 1]; + pstGh3x2xChannelDumpData->punChBgRawdataArr[usRawdataBaseIndex + uchChCntIndex] = \ + (unRawdataSum / g_uchRawdataDivOfDumpDataMapArr[puchChannelBgLvlArr[uchChCntIndex]]) | \ + GH3X2X_RAWDATA_CLEAR_DATA(\ + pstGh3x2xChannelDumpData->punChRawdataArr[usRawdataBaseIndex + uchChCntIndex]); + } + } // end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + } // end of for (usRawdataIndex = 0; usRawdataIndex < usRawdataCnt; usRawdataIndex++) + GH3X2X_Memset(pstGh3x2xChannelDumpData->uchChIncompleteFlagArr, 0, GH3X2X_CHANNEL_MAP_MAX_CH); + } // end of if (chRet == GH3X2X_RET_OK) + if (uchNextIncompleteFlag != 0) + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // search each channel + { + usRawdataByteIndexTmp = usRawdataIndexArr[uchChCntIndex]; + while (usRawdataByteIndexTmp < usReadRawdataLen) // search each + { + if (GH3X2X_CHANNEL_MAP_GET(puchReadRawdataBuffer[usRawdataByteIndexTmp]) == \ + puchChannelMapArr[uchChCntIndex]) // if map equal + { + pstGh3x2xChannelDumpData->punIncompleteChRawdataArr[uchChCntIndex]\ + [uchDumpDataIndexArr[uchChCntIndex]] = \ + GH3X2X_RAWDATA_CLEAR_SLOT_ADC_NUM( + GH3X2X_MAKEUP_DWORD(puchReadRawdataBuffer[usRawdataByteIndexTmp], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 1], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 2], + puchReadRawdataBuffer[usRawdataByteIndexTmp + 3])); + pstGh3x2xChannelDumpData->uchChIncompleteFlagArr[uchChCntIndex] |= \ + (GU8)GH3X2X_GET_LEFT_SHIFT_VAL(uchDumpDataIndexArr[uchChCntIndex]); + uchDumpDataIndexArr[uchChCntIndex]++; + } + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + } // end of if (uchNextIncompleteFlag != 0) + pstGh3x2xChannelDumpData->usChRawdataCnt = usRawdataCnt; + return GH3X2X_RET_OK; +} + +/** + * @fn GS16 GH3X2X_GetDumpdataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + * GU8 *puchReadRawdataBuffer, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, GU8 *puchBglvlArr) + * + * @brief Get dump data from fifo with channel map + * + * @attention None + * + * @param[in] puchReadRawdataBuffer pointer to read data buffer + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelMapArr pointer to channel map array + * @param[in] puchBglvlArr pointer to bg lvl array, @ref EMGh3x2xDumpRawdataBgLvlSelect + * @param[out] pstGh3x2xChannelDumpData pointer to channel rawdata struct output + * + * @return GH3X2X_RET_OK return get data successful + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_READ_FIFO_CONTINUE return fifo is not empty + */ +GS16 GH3X2X_GetDumpdataWithChannelMap(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData, + GU8 *puchReadRawdataBuffer, GU8 uchChannelMapCnt, GU8 *puchChannelMapArr, GU8 *puchBglvlArr) +{ + GU16 usFifoLength = 0; + GS16 sRet = GH3X2X_RET_OK; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + + if (puchReadRawdataBuffer != GH3X2X_PTR_NULL) + { + GH3X2X_WAIT_CHIP_WAKEUP(); + usFifoLength = GH3X2X_FIFO_CNT_CALC(GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR)); + if (usFifoLength > g_usMaxNumReadFromFifo) + { + usFifoLength = g_usMaxNumReadFromFifo; + sRet = GH3X2X_RET_READ_FIFO_CONTINUE; + } + + if ((usFifoLength > 0) && (usFifoLength <= GH3X2X_FIFO_DATA_BYTES_MAX_LEN)) + { + GH3X2X_ReadFifo(puchReadRawdataBuffer, usFifoLength); + } + else + { + if (usFifoLength > GH3X2X_FIFO_DATA_BYTES_MAX_LEN) + { + usFifoLength = 0; + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo len greater than max, pelease check i2c/spi!\r\n"); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata fifo equl 0!\r\n"); + } + } + + /* call hook */ + HOOK_FUNC_CALL(g_pGh3x2xGetRawdataHookFunc, (puchReadRawdataBuffer, usFifoLength)); + GH3X2X_WAIT_CHIP_DSLP(); + sRet = GH3X2X_UnpackDumpDataWithChannelMap(pstGh3x2xChannelDumpData, puchReadRawdataBuffer, usFifoLength, + uchChannelMapCnt, puchChannelMapArr, puchBglvlArr); + } + else // fixed clear cnt if readbuffer ptr is null + { + GH3X2X_DEBUG_LOG_PARAM("get rawdata error that readbuffer is null!\r\n"); + sRet = GH3X2X_RET_PARAMETER_ERROR; + } + + return sRet; +} + +/** + * @fn GS8 GH3X2X_ChannelMapDumpDataClear(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData) + * + * @brief clear channel map dump data struct + * + * @attention This function must use before get dump data by one kind channel map + * e.g. channel map start/stop need clear + * + * @param[in] pstGh3x2xChannelDumpData pointer to channel dump data struct + * @param[out] None + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + */ +GS8 GH3X2X_ChannelMapDumpDataClear(STGh3x2xChannelDumpData *pstGh3x2xChannelDumpData) +{ + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((pstGh3x2xChannelDumpData->uchChIncompleteFlagArr != GH3X2X_PTR_NULL) + && (pstGh3x2xChannelDumpData != GH3X2X_PTR_NULL)) + { + GH3X2X_Memset(pstGh3x2xChannelDumpData->uchChIncompleteFlagArr, 0, GH3X2X_CHANNEL_MAP_MAX_CH); + pstGh3x2xChannelDumpData->usChRawdataCnt = 0; + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("channel rawdata param is null!\r\n"); + } + return chRet; +} + +/** + * @fn GU32 GH3X2X_DumpRawDataPro(GU32 punRawdata, GU32 unAmb1, GU32 unAmb2) + * + * @brief transfer dump data to true rawdata + * + * @attention None + * + * @param[in] punRawdata led data + * @param[in] unAmb1 ambiance data1 + * @param[in] unAmb2 ambiance data2 + * @param[out] None + * + * @return rawdata after process + */ +GU32 GH3X2X_DumpRawDataPro(GU32 punRawdata, GU32 unAmb1, GU32 unAmb2) +{ + GU32 unLedValue = 0; + + unLedValue = (GU32)((GS32)DUMP_PPG_DATA(punRawdata) - (((GS32)DUMP_PPG_DATA(unAmb1) + \ + (GS32)DUMP_PPG_DATA(unAmb2)) >> 1) + GH3X2X_DUMP_DATA_OFFSET); + + return GH3X2X_MAKEUP_DWORD(GH3X2X_GET_BYTE0_FROM_DWORD(unLedValue), GH3X2X_GET_BYTE1_FROM_DWORD(unLedValue), \ + GH3X2X_GET_BYTE2_FROM_DWORD(unLedValue), GH3X2X_GET_BYTE0_FROM_DWORD(punRawdata)); + +} + +/** + * @fn void GH3X2X_DumpDataPro(GU32 punDumpDataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8 puchChMapArr[], + GU8 uchChMapCnt, GU8 puchChBgLvlArr[], GU8 uchChCntIndex) + * + * @brief transfer dump data to true rawdata + * + * @attention None + * + * @param[in] punDumpData[][] dump data of all channel + * @param[in] uchChMapArr[] channel map array + * @param[in] uchChMapCnt channel map cnt + * @param[in] puchChBgLvlArr[] channel bg level array + * @param[in] uchChCntIndex channel index + * @param[out] None + * + * @return None + */ +void GH3X2X_DumpDataPro(GU32 punDumpDataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8 puchChMapArr[], + GU8 uchChMapCnt, GU8 puchChBgLvlArr[], GU8 uchChCntIndex) +{ + GU8 emBgLevel = puchChBgLvlArr[uchChCntIndex]; + GU8 uchLastIndex = 0; + GU8 uchAgcData = 0; + + uchAgcData = g_puchGainBgCancelRecord[GH3X2X_BYTE_RAWDATA_GET_SLOT_ADC_NUM(puchChMapArr[uchChCntIndex])]; + switch (emBgLevel) + { + case GH3X2X_DUMP_RAWDATA_BGLVL0: + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX] = punDumpDataArr[uchChCntIndex][1]; + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX] = GH3X2X_MAKEUP_DWORD(0, \ + DUMP_CUREENT1(punDumpDataArr[uchChCntIndex][0]), \ + DUMP_CUREENT0(punDumpDataArr[uchChCntIndex][0]), \ + uchAgcData); + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX] = 0; + break; + case GH3X2X_DUMP_RAWDATA_BGLVL1: + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX] = GH3X2X_DumpRawDataPro(punDumpDataArr[uchChCntIndex][2], \ + punDumpDataArr[uchChCntIndex][1], \ + punDumpDataArr[uchChCntIndex][1]); + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX] = GH3X2X_MAKEUP_DWORD(0, \ + DUMP_CUREENT1(punDumpDataArr[uchChCntIndex][0]), \ + DUMP_CUREENT0(punDumpDataArr[uchChCntIndex][0]), \ + uchAgcData); + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX] = DUMP_PPG_DATA(punDumpDataArr[uchChCntIndex][1]); + break; + case GH3X2X_DUMP_RAWDATA_BGLVL2: + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX] = GH3X2X_DumpRawDataPro(punDumpDataArr[uchChCntIndex][2], \ + punDumpDataArr[uchChCntIndex][1], \ + punDumpDataArr[uchChCntIndex][3]); + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX] = GH3X2X_MAKEUP_DWORD(0, \ + DUMP_CUREENT1(punDumpDataArr[uchChCntIndex][0]), \ + DUMP_CUREENT0(punDumpDataArr[uchChCntIndex][0]), \ + uchAgcData); + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX] = (DUMP_PPG_DATA(punDumpDataArr[uchChCntIndex][1]) + \ + DUMP_PPG_DATA(punDumpDataArr[uchChCntIndex][3])) >> 1; + break; + case GH3X2X_DUMP_RAWDATA_BGLVL2X2: + GH3X2X_FindLastSlotChMapIndex(&uchLastIndex, puchChMapArr, uchChMapCnt, uchChCntIndex); + + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX] = GH3X2X_DumpRawDataPro(punDumpDataArr[uchChCntIndex][0], \ + punDumpDataArr[uchLastIndex][3], \ + punDumpDataArr[uchChCntIndex][1]); + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX] = GH3X2X_MAKEUP_DWORD(0, \ + DUMP_CUREENT1(punDumpDataArr[uchLastIndex][0]), \ + DUMP_CUREENT0(punDumpDataArr[uchLastIndex][0]), \ + uchAgcData); + g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX] = (DUMP_PPG_DATA(punDumpDataArr[uchLastIndex][3]) + \ + DUMP_PPG_DATA(punDumpDataArr[uchChCntIndex][1])) >> 1; + break; + default: + break; + } // end of switch (emBgLevel) +} + +/** + * @fn void GH3X2X_ElectrWearDumpDataPro(GU8* puchRawdataTag, GU8 uchChMapIndex) + * + * @brief electrode wear dump data pro + * + * @attention None + * + * @param[in] puchRawdataTag data tag of rawdata + * @param[in] uchChMapIndex channel map index + * @param[out] None + * + * @return None + */ + +void GH3X2X_ElectrWearDumpDataPro(GU8* puchRawdataTag, GU8 uchChMapIndex) +{ + if (GH3X2X_CHECK_LEFT_BIT_SET(GH3X2X_DumpModeGet(), GH3X2X_DUMP_ELECTR_WEAR_ENABLE_BIT)) + { + if (0 == uchChMapIndex) + { + if (0 == g_uchElectrodeWearStatus) + { + GH3X2X_VAL_CLEAR_BIT(*puchRawdataTag, (GU8)GH3X2X_ELECTR_WEAR_STATUS_BIT_IN_DATA_TAG); + } + else + { + GH3X2X_VAL_SET_BIT(*puchRawdataTag, GH3X2X_ELECTR_WEAR_STATUS_BIT_IN_DATA_TAG); + } + } + } +} + + +/** + * @fn void GH3X2X_FillDumpData(GU16* usPayloadIndex, GU8* uchGainCurAddr, GU8* uchAmbiAddr, + * GU8 uchChannelMapArr[], GU8 uchChannelMapCnt,GU8 *puchChannelBgLvlArr, + * GU16 usDumpMode, GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL]) + * + * @brief fill dump data to protocol data + * + * @attention None + * + * @param[in] uchChMapArr[] channel map array + * @param[in] uchChMapCnt channel map cnt + * @param[in] puchChBgLvlArr[] channel bg level array + * @param[in] usDumpMode dump mode + * @param[in] punDumpData[][] dump data of all channel + * @param[out] usPayloadIndex current payload index + * @param[out] uchGainCurAddr current payload index + * @param[out] uchAmbiAddr current payload index + * + * @return None + */ +void GH3X2X_FillDumpData(GU16* usPayloadIndex, GU8* uchGainCurAddr, GU8* uchAmbiAddr, GU8 uchChannelMapArr[], + GU8 uchChannelMapCnt, GU8 *puchChannelBgLvlArr, GU16 usDumpMode, + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL]) +{ + GU8 uchChCntIndex = 0; + + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + //dump data filter process + GH3X2X_DumpDataPro(punIncompleteDumpdataArr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, uchChCntIndex); + + GH3X2X_Memcpy(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX], GH3X2X_FIFO_RAWDATA_SIZE); + GH3X2X_ElectrWearDumpDataPro(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], uchChCntIndex); + *usPayloadIndex += GH3X2X_FIFO_RAWDATA_SIZE; + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + GH3X2X_Memcpy(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*uchGainCurAddr], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX], \ + GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE); + *uchGainCurAddr += GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE; + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + GH3X2X_Memcpy(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*uchAmbiAddr], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX], \ + GH3X2X_DUMP_AMBIANCE_DATA_SIZE); + *uchAmbiAddr += GH3X2X_DUMP_AMBIANCE_DATA_SIZE; + } + } //end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) +} + +#if 0 +/** + * @fn GS8 GH3X2X_SendDumpDataPkgWithAlgo(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 punLastIncompleteArr[], + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8 *puchFifoRawdata, + GU16 usFifoRawdataLen, GU8 uchChannelMapArr[], GU8 uchChannelMapCnt, GU8 *puchChannelBgLvlArr, + STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity, + GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum, GU8 uchChannelMapId) + * + * @brief Pack rawdata with g sensor data and algorithm data + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to protocol pkg data. + * @param[out] pusRespondLen pointer to protocol pkg data length + * @param[out] punLastIncompleteArr incomplete array + * @param[out] punIncompleteRawdataArr incomplete data array used for cache data + * @param[in] puchFifoRawdata pointer to data buffer of rawdata + * @param[in] usFifoRawdataLen data num of rawdata buf + * @param[in] uchChannelMapArr pointer to channel map array + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelBgLvlArr bg level array + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum g sensor data number + * @param[in] emGsSensitivity g sensor sensitivity + * @param[in] nAlgoCalcResultArr algorithm result + * @param[in] uchAlgoResNum number of algorithm result + * @param[in] uchChannelMapId channel map id (0 ~ 15) + * @return error code + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_RAW_DATA_PKG_OVER return already read all the package data + * @retval #GH3X2X_RET_RAW_DATA_PKG_CONTINUE return should read rawdata package data again + * @retval #GH3X2X_RET_RESOURCE_ERROR return not enough data + */ +GS8 GH3X2X_SendDumpDataPkgWithAlgo(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 punLastIncompleteArr[], + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8 *puchFifoRawdata, + GU16 usFifoRawdataLen, GU8 uchChannelMapArr[], GU8 uchChannelMapCnt, GU8 *puchChannelBgLvlArr, + STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity, + GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum, GU8 uchChannelMapId) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchChCntIndex = 0; + GF32 fIndexInc = GH3X2X_GF32_0; //step of g sensor data + GU16 usDataCnt = 0; + GU16 usDataIndex = 0; + GU16 usPayloadIndex = 0; //payload data index + GU8 uchGsEnable = 0; + GU8 uchAlgoResFlag = 0; + GU8 uchFrameDataNum = GH3X2X_FIFO_CNT_CALC(uchChannelMapCnt) + 1; //number of one frame data + GU8 uchGainCurDataNum = 0; //gain current data number of one frame data + GU8 uchAmbiDataNum = 0; //ambiance data number of one frame data + GU16 usRawdataByteIndexTmp = 0; + GU8 uchDumpDataIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; + GU8 uchNextIncompleteFlag = 0; + GU8 uchDumpDataCalcTmp = 0; + GU8 uchGainCurAddr = 0; // gain & current data addr when pack them + GU8 uchAmbiAddr = 0; // ambiance data addr when pack them + + if ((puchRespondBuffer == GH3X2X_PTR_NULL) || (pusRespondLen == GH3X2X_PTR_NULL) + || (puchFifoRawdata == GH3X2X_PTR_NULL) || (uchChannelMapArr == GH3X2X_PTR_NULL)) + { + GH3X2X_DEBUG_LOG_PARAM("pointer param set null error!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + if (GH3X2X_CLEAR_BIT(uchChannelMapArr[uchChCntIndex], GH3X2X_SLOT_ADC_NUM_BITS) != 0) + { + GH3X2X_DEBUG_LOG_PARAM("channel map error! set @ref GH3X2X_CHANNEL_MAP!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + } + + if (0 == g_usGh3x2xDataIndexInBuf) + { + GH3X2X_Memset(g_usRawdataByteIndexArr, 0, sizeof(g_usRawdataByteIndexArr[0]) * GH3X2X_CHANNEL_MAP_MAX_CH); + } + + if (nAlgoCalcResultArr == GH3X2X_PTR_NULL) + { + uchAlgoResNum = 0; + } + + if ((0 == g_usGh3x2xDataIndexInBuf) && (GH3X2X_ElectrodeWearRevertDebugModeIsEnabled())) + { + uchAlgoResNum++; + uchFrameDataNum += GH3X2X_ALGO_RESULT_WITH_TAG_CALC(1) + 1; + uchAlgoResFlag = 1; + + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + uchGainCurDataNum = (GU8)GH3X2X_DUMP_GAIN_CURRENT_CALC(uchChannelMapCnt); + uchFrameDataNum += uchGainCurDataNum; + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + uchAmbiDataNum = (GU8)GH3X2X_DUMP_AMBIANCE_CALC(uchChannelMapCnt); + uchFrameDataNum += uchAmbiDataNum; + } + + if ((pstGsAxisValueArr == GH3X2X_PTR_NULL) || (0 == usGsDataNum)) + { + uchGsEnable = 0; + } + else + { + uchGsEnable = 1; + uchFrameDataNum += GH3X2X_GSENSOR_DATA_SIZE; + } + + chRet = GH3X2X_GetDumpDataInfo(&fIndexInc, &usDataCnt, &uchNextIncompleteFlag, uchDumpDataIndexArr, + punLastIncompleteArr, usFifoRawdataLen, puchFifoRawdata, + uchChannelMapCnt, uchChannelMapArr, puchChannelBgLvlArr, usGsDataNum); + + if (0 != g_usGh3x2xDataIndexInBuf) + { + GH3X2X_Memset(uchDumpDataIndexArr, 0, sizeof(uchDumpDataIndexArr)); + } + + if (GH3X2X_RET_OK == chRet) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_TYPE_INDEX] = \ + GH3X2X_VAL_LEFT_SHIFT(uchChannelMapId, UPROTOCOL_FUNC_ID_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchGsEnable, UPROTOCOL_GS_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchAlgoResFlag, UPROTOCOL_ALGO_ENABLE_FIELD); + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_TYPE_INDEX] |= \ + GH3X2X_GET_LEFT_SHIFT_VAL(UPROTOCOL_AGC_ENABLE_FIELD); + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_TYPE_INDEX] |= \ + GH3X2X_GET_LEFT_SHIFT_VAL(UPROTOCOL_AMBIANCE_ENABLE_FIELD); + } + + usPayloadIndex = UPROTOCOL_FRAME_DATA_INDEX; + for (usDataIndex = g_usGh3x2xDataIndexInBuf; usDataIndex < usDataCnt; usDataIndex++) + { + //judge if will exceed payload length limit + if (usPayloadIndex + uchFrameDataNum >= GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport)) + { + break; + } + g_pstGh3x2xProtocolData->puchPacketPayloadArr[usPayloadIndex] = g_uchFrameIdArr[uchChannelMapId]; //FrameID + g_pstGh3x2xProtocolData->uchFrameIdArr[uchChannelMapId]++; + usPayloadIndex++; + if (1 == uchGsEnable) + { + GH3X2X_FillGsensorData(&usPayloadIndex, &pstGsAxisValueArr[(GU16)g_fGsDataIndexInBuf]); + g_fGsDataIndexInBuf += fIndexInc; + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + uchGainCurAddr = usPayloadIndex + GH3X2X_FIFO_CNT_CALC(uchChannelMapCnt); + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + uchAmbiAddr = (GU8)uchGainCurAddr + uchGainCurDataNum; + } + else + { + uchAmbiAddr = usPayloadIndex + GH3X2X_FIFO_CNT_CALC(uchChannelMapCnt); + } + } + + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // search each channel + { + uchDumpDataCalcTmp = g_uchDumpDataCntMapArr[puchChannelBgLvlArr[uchChCntIndex]]; + if (uchDumpDataIndexArr[uchChCntIndex] < uchDumpDataCalcTmp) + { + usRawdataByteIndexTmp = g_usRawdataByteIndexArr[uchChCntIndex]; + while (usRawdataByteIndexTmp < usFifoRawdataLen) // search each + { + if (GH3X2X_CHANNEL_MAP_GET(puchFifoRawdata[usRawdataByteIndexTmp]) == \ + uchChannelMapArr[uchChCntIndex]) // if map equal + { + punIncompleteDumpdataArr[uchChCntIndex][uchDumpDataIndexArr[uchChCntIndex]] = \ + GH3X2X_MAKEUP_DWORD(puchFifoRawdata[usRawdataByteIndexTmp + 3], + puchFifoRawdata[usRawdataByteIndexTmp + 2], + puchFifoRawdata[usRawdataByteIndexTmp + 1], + puchFifoRawdata[usRawdataByteIndexTmp]); + uchDumpDataIndexArr[uchChCntIndex]++; + if (uchDumpDataIndexArr[uchChCntIndex] >= uchDumpDataCalcTmp) + { + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + break; + } + } + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + + uchDumpDataIndexArr[uchChCntIndex] = 0; + g_usRawdataByteIndexArr[uchChCntIndex] = usRawdataByteIndexTmp; // write back byte index + } // end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + + GH3X2X_FillDumpData(&usPayloadIndex, &uchGainCurAddr, &uchAmbiAddr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, g_usDumpMode, punIncompleteDumpdataArr); + + usPayloadIndex += uchGainCurDataNum + uchAmbiDataNum; + + if (1 == uchAlgoResFlag) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[usPayloadIndex] = GH3X2X_ALGO_RESULT_WITH_TAG_CALC(uchAlgoResNum); + usPayloadIndex++; + if ((GH3X2X_ElectrodeWearRevertDebugModeIsEnabled()) && (0 == usDataIndex)) + { + GH3X2X_FillElectrodeWearRevertData(&usPayloadIndex); + uchAlgoResNum -= 1; //only the first frame data has Flag data + uchFrameDataNum -= GH3X2X_ALGO_RESULT_WITH_TAG_CALC(1); + } + } // end of if (1 == uchAlgoResFlag) + } // end of for (usDataIndex = g_usGh3x2xDataIndexInBuf; usDataIndex < usDataCnt; usDataIndex++) + + if (usDataIndex < usDataCnt) + { + g_usGh3x2xDataIndexInBuf = usDataIndex; + chRet = GH3X2X_RET_RAW_DATA_PKG_CONTINUE; + } + else + { + g_usGh3x2xDataIndexInBuf = 0; + g_fGsDataIndexInBuf = 0; + chRet = GH3X2X_RET_RAW_DATA_PKG_OVER; + GH3X2X_CacheIncompleteDumpdata(punLastIncompleteArr, punIncompleteDumpdataArr, uchNextIncompleteFlag, \ + puchFifoRawdata, usFifoRawdataLen, uchChannelMapArr, uchChannelMapCnt, \ + g_usRawdataByteIndexArr); + } // end else + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_LEN_INDEX] = (GU8)(usPayloadIndex - UPROTOCOL_FRAME_DATA_INDEX); + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_RAWDATA, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, usPayloadIndex)); + } // end of if (GH3X2X_RET_OK == chRet) + else + { + pusRespondLen = 0; + } + + return chRet; +} + + +/** + * @fn void GH3X2X_FillZipDumpData(GU16* usPayloadIndex, GU8* uchGainCurAddr, GU8* uchAmbiAddr, + * GU8 uchChannelMapArr[], GU8 uchChannelMapCnt,GU8 *puchChannelBgLvlArr, + * GU16 usDumpMode, GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL]) + * + * @brief fill zip dump data to protocol data + * + * @attention None + * + * @param[in] uchChMapArr[] channel map array + * @param[in] uchChMapCnt channel map cnt + * @param[in] puchChBgLvlArr[] channel bg level array + * @param[in] usDumpMode dump mode + * @param[in] punDumpData[][] dump data of all channel + * @param[out] usPayloadIndex current payload index + * @param[out] uchGainCurAddr current payload index + * @param[out] uchAmbiAddr current payload index + * + * @return None + */ +GU8 GH3X2X_FillZipDumpData(GU16* usPayloadIndex, GU8 uchChannelMapArr[], + GU8 uchChannelMapCnt, GU8 *puchChannelBgLvlArr, GU16 usDumpMode, + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], + GU8 uchZipDataFirstFrameSta, GU8 *uchZipDiffDataSize, + GU8 uchGainCurDataNum, GU8 uchAmbiDataNum) +{ + GU8 uchChCntIndex = 0; + GU32 unFifoLastRawdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU8 uchFifoLastRawdataTagArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastAgcdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastAmbdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + + GU8 uchZipDataArr[GH3X2X_UPROTOCOL_PACKET_LEN_MAX]; + GU16 usZipDataArrSize = 0; + + GU8 uchZipRawdataArr[GH3X2X_UPROTOCOL_PACKET_LEN_MAX]; + GU8 uchZipRawdataArrSize = 0; + GU8 uchZipAgcDataArr[GH3X2X_UPROTOCOL_PACKET_LEN_MAX]; + GU8 uchZipAgcDataArrSize = 0; + GU8 uchZipAmbDataArr[GH3X2X_UPROTOCOL_PACKET_LEN_MAX]; + GU8 uchZipAmbDataArrSize = 0; + + + if (g_uchDumpOddEvenChangeFlag && uchZipDataFirstFrameSta) + { + if (*usPayloadIndex + (GU16)usZipDataArrSize > \ + (GU16)GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport)) + { + return 1; + } + + usZipDataArrSize = uchGainCurDataNum + uchAmbiDataNum; + + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + //dump data filter process + GH3X2X_DumpDataPro(punIncompleteDumpdataArr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, uchChCntIndex); + GH3X2X_Memcpy(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX], GH3X2X_FIFO_RAWDATA_SIZE); + GH3X2X_ElectrWearDumpDataPro(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], uchChCntIndex); + *usPayloadIndex += GH3X2X_FIFO_RAWDATA_SIZE; + g_stZipDumpTempData.unFifoLastRawdataArr[uchChCntIndex] = GH3X2X_MAKEUP_DWORD\ + (0, \ + GH3X2X_GET_BYTE1_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX]), \ + GH3X2X_GET_BYTE2_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX]), \ + GH3X2X_GET_BYTE3_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX])); + g_stZipDumpTempData.uchFifoLastRawdataTagArr[uchChCntIndex] = \ + GH3X2X_GET_BYTE0_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX]); + }// end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + GH3X2X_DumpDataPro(punIncompleteDumpdataArr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, uchChCntIndex); + GH3X2X_Memcpy(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX], \ + GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE); + *usPayloadIndex += GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE; + GH3X2X_Memcpy(&g_stZipDumpTempData.unFifoLastAgcdataArr[uchChCntIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX], \ + GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE); + } + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + GH3X2X_DumpDataPro(punIncompleteDumpdataArr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, uchChCntIndex); + GH3X2X_Memcpy(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX], \ + GH3X2X_DUMP_AMBIANCE_DATA_SIZE); + *usPayloadIndex += GH3X2X_DUMP_AMBIANCE_DATA_SIZE; + GH3X2X_Memcpy(&g_stZipDumpTempData.unFifoLastAmbdataArr[uchChCntIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX], \ + GH3X2X_DUMP_AMBIANCE_DATA_SIZE); + } + } //end of if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + }//end of if (g_uchDumpOddEvenChangeFlag && uchZipDataFirstFrameSta) + else + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + //dump data filter process + GH3X2X_DumpDataPro(punIncompleteDumpdataArr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, uchChCntIndex); + GH3X2X_ElectrWearDumpDataPro(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], uchChCntIndex); + unFifoLastRawdataArr[uchChCntIndex] = 0; + uchFifoLastRawdataTagArr[uchChCntIndex] = 0; + unFifoLastRawdataArr[uchChCntIndex] = GH3X2X_MAKEUP_DWORD\ + (0, \ + GH3X2X_GET_BYTE1_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX]), \ + GH3X2X_GET_BYTE2_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX]), \ + GH3X2X_GET_BYTE3_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX])); + uchFifoLastRawdataTagArr[uchChCntIndex] = \ + GH3X2X_GET_BYTE0_FROM_DWORD(g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_PPG_INDEX]); + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + GH3X2X_DumpDataPro(punIncompleteDumpdataArr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, uchChCntIndex); + unFifoLastAgcdataArr[uchChCntIndex] = 0; + GH3X2X_Memcpy(&unFifoLastAgcdataArr[uchChCntIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_GAIN_CURRENT_INDEX], \ + GH3X2X_DUMP_GAIN_CURRENT_DATA_SIZE); + } + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + GH3X2X_DumpDataPro(punIncompleteDumpdataArr, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, uchChCntIndex); + unFifoLastAmbdataArr[uchChCntIndex] = 0; + GH3X2X_Memcpy(&unFifoLastAmbdataArr[uchChCntIndex], \ + &g_punDumpDataUploadArr[GH3X2X_DUMP_DATA_AMBIANCE_INDEX], \ + GH3X2X_DUMP_AMBIANCE_DATA_SIZE); + } + } //end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + + GH3X2X_Memset(uchZipRawdataArr, 0, sizeof(uchZipRawdataArr[0]) * GH3X2X_UPROTOCOL_PACKET_LEN_MAX); + GH3X2X_GetRawDataDiff(unFifoLastRawdataArr, uchFifoLastRawdataTagArr, \ + uchChannelMapCnt, uchZipRawdataArr, &uchZipRawdataArrSize, \ + g_stZipDumpTempData.uchFifoLastRawdataTagArr, g_stZipDumpTempData.unFifoLastRawdataArr); + GH3X2X_Memcpy(&uchZipDataArr[usZipDataArrSize], uchZipRawdataArr, uchZipRawdataArrSize); + usZipDataArrSize += uchZipRawdataArrSize; + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + GH3X2X_Memset(uchZipAgcDataArr, 0, sizeof(uchZipAgcDataArr[0]) * GH3X2X_UPROTOCOL_PACKET_LEN_MAX); + GH3X2X_GetDataDiff(unFifoLastAgcdataArr, uchChannelMapCnt, uchZipAgcDataArr, &uchZipAgcDataArrSize, \ + g_stZipDumpTempData.unFifoLastAgcdataArr); + GH3X2X_Memcpy(&uchZipDataArr[usZipDataArrSize], uchZipAgcDataArr, uchZipAgcDataArrSize); + usZipDataArrSize += uchZipAgcDataArrSize; + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + GH3X2X_Memset(uchZipAmbDataArr, 0, sizeof(uchZipAmbDataArr[0]) * GH3X2X_UPROTOCOL_PACKET_LEN_MAX); + GH3X2X_GetDataDiff(unFifoLastAmbdataArr, uchChannelMapCnt, uchZipAmbDataArr, &uchZipAmbDataArrSize, \ + g_stZipDumpTempData.unFifoLastAmbdataArr); + GH3X2X_Memcpy(&uchZipDataArr[usZipDataArrSize], uchZipAmbDataArr, uchZipAmbDataArrSize); + usZipDataArrSize += uchZipAmbDataArrSize; + } + + if (*usPayloadIndex + (GU16)usZipDataArrSize > \ + (GU16)GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport)) + { + return 1; + } + else + { + GH3X2X_Memcpy(g_stZipDumpTempData.unFifoLastRawdataArr, unFifoLastRawdataArr, \ + uchChannelMapCnt*GH3X2X_FIFO_RAWDATA_SIZE); + GH3X2X_Memcpy(g_stZipDumpTempData.uchFifoLastRawdataTagArr, uchFifoLastRawdataTagArr, \ + uchChannelMapCnt); + GH3X2X_Memcpy(g_stZipDumpTempData.unFifoLastAgcdataArr, unFifoLastAgcdataArr, \ + uchChannelMapCnt*GH3X2X_FIFO_RAWDATA_SIZE); + GH3X2X_Memcpy(g_stZipDumpTempData.unFifoLastAmbdataArr, unFifoLastAmbdataArr, \ + uchChannelMapCnt*GH3X2X_FIFO_RAWDATA_SIZE); + + GH3X2X_Memcpy(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[*usPayloadIndex], uchZipDataArr, usZipDataArrSize); + *usPayloadIndex += (GU16)usZipDataArrSize; + } + }// end of else + + return 0; +} + +/** + * @fn GS8 GH3X2X_SendZipDumpDataPkgWithAlgo(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 punLastIncompleteArr[], + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8 *puchFifoRawdata, + GU16 usFifoRawdataLen, GU8 uchChannelMapArr[], GU8 uchChannelMapCnt, GU8 *puchChannelBgLvlArr, + STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity, + GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum, GU8 uchChannelMapId) + * + * @brief Pack Zip rawdata with g sensor data and algorithm data + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to protocol pkg data. + * @param[out] pusRespondLen pointer to protocol pkg data length + * @param[out] punLastIncompleteArr incomplete array + * @param[out] punIncompleteRawdataArr incomplete data array used for cache data + * @param[in] puchFifoRawdata pointer to data buffer of rawdata + * @param[in] usFifoRawdataLen data num of rawdata buf + * @param[in] uchChannelMapArr pointer to channel map array + * @param[in] uchChannelMapCnt channel map array cnt, max:32 + * @param[in] puchChannelBgLvlArr bg level array + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum g sensor data number + * @param[in] emGsSensitivity g sensor sensitivity + * @param[in] nAlgoCalcResultArr algorithm result + * @param[in] uchAlgoResNum number of algorithm result + * @param[in] uchChannelMapId channel map id (0 ~ 15) + * @return error code + * @retval #GH3X2X_RET_PARAMETER_ERROR return param error + * @retval #GH3X2X_RET_RAW_DATA_PKG_OVER return already read all the package data + * @retval #GH3X2X_RET_RAW_DATA_PKG_CONTINUE return should read rawdata package data again + * @retval #GH3X2X_RET_RESOURCE_ERROR return not enough data + */ +GS8 GH3X2X_SendZipDumpDataPkgWithAlgo(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 punLastIncompleteArr[], + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8 *puchFifoRawdata, + GU16 usFifoRawdataLen, GU8 uchChannelMapArr[], GU8 uchChannelMapCnt, GU8 *puchChannelBgLvlArr, + STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity, + GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum, GU8 uchChannelMapId) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchChCntIndex = 0; + GF32 fIndexInc = GH3X2X_GF32_0; //step of g sensor data + GU16 usDataCnt = 0; + GU16 usDataIndex = 0; + GU16 usPayloadIndex = 0; //payload data index + GU8 uchGsEnable = 0; + GU8 uchAlgoResFlag = 0; + GU8 uchFrameDataNum = GH3X2X_FIFO_CNT_CALC(uchChannelMapCnt) + 1; //number of one frame data + GU8 uchGainCurDataNum = 0; //gain current data number of one frame data + GU8 uchAmbiDataNum = 0; //ambiance data number of one frame data + GU16 usRawdataByteIndexTmp = 0; + GU8 uchDumpDataIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; + GU8 uchNextIncompleteFlag = 0; + GU8 uchDumpDataCalcTmp = 0; + GU8 uchSendCmd = 0; // zip cmd (0x09/0x0a) + GU8 uchZipDataFirstFrameSta = 1; + GU8 uchZipDiffDataSize = 0; + GU8 uchZipRet = 0; + GU16 usRawdataByteIndexTmpBeforeHandleArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU16 usFrameidIndex; + + if ((puchRespondBuffer == GH3X2X_PTR_NULL) || (pusRespondLen == GH3X2X_PTR_NULL) + || (puchFifoRawdata == GH3X2X_PTR_NULL) || (uchChannelMapArr == GH3X2X_PTR_NULL)) + { + GH3X2X_DEBUG_LOG_PARAM("pointer param set null error!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + { + if (GH3X2X_CLEAR_BIT(uchChannelMapArr[uchChCntIndex], GH3X2X_SLOT_ADC_NUM_BITS) != 0) + { + GH3X2X_DEBUG_LOG_PARAM("channel map error! set @ref GH3X2X_CHANNEL_MAP!\r\n"); + return GH3X2X_RET_PARAMETER_ERROR; + } + } + + if (0 == g_usGh3x2xDataIndexInBuf) + { + GH3X2X_Memset(g_usRawdataByteIndexArr, 0, sizeof(g_usRawdataByteIndexArr[0]) * GH3X2X_CHANNEL_MAP_MAX_CH); + } + + if (nAlgoCalcResultArr == GH3X2X_PTR_NULL) + { + uchAlgoResNum = 0; + } + + if ((0 == g_usGh3x2xDataIndexInBuf) && (GH3X2X_ElectrodeWearRevertDebugModeIsEnabled())) + { + uchAlgoResNum++; + uchFrameDataNum += GH3X2X_ALGO_RESULT_WITH_TAG_CALC(1) + 1; + uchAlgoResFlag = 1; + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + uchGainCurDataNum = (GU8)GH3X2X_DUMP_GAIN_CURRENT_CALC(uchChannelMapCnt); + uchFrameDataNum += uchGainCurDataNum; + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + uchAmbiDataNum = (GU8)GH3X2X_DUMP_AMBIANCE_CALC(uchChannelMapCnt); + uchFrameDataNum += uchAmbiDataNum; + } + + if ((pstGsAxisValueArr == GH3X2X_PTR_NULL) || (0 == usGsDataNum)) + { + uchGsEnable = 0; + } + else + { + uchGsEnable = 1; + uchFrameDataNum += GH3X2X_GSENSOR_DATA_SIZE; + } + + chRet = GH3X2X_GetDumpDataInfo(&fIndexInc, &usDataCnt, &uchNextIncompleteFlag, uchDumpDataIndexArr, + punLastIncompleteArr, usFifoRawdataLen, puchFifoRawdata, + uchChannelMapCnt, uchChannelMapArr, puchChannelBgLvlArr, usGsDataNum); + + if (0 != g_usGh3x2xDataIndexInBuf) + { + GH3X2X_Memset(uchDumpDataIndexArr, 0, sizeof(uchDumpDataIndexArr)); + } + + if (GH3X2X_RET_OK == chRet) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_TYPE_INDEX] = \ + GH3X2X_VAL_LEFT_SHIFT(uchChannelMapId, UPROTOCOL_FUNC_ID_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchGsEnable, UPROTOCOL_GS_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchAlgoResFlag, UPROTOCOL_ALGO_ENABLE_FIELD); + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_GAIN_CURRENT_ENABLE_BIT)) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_TYPE_INDEX] |= \ + GH3X2X_GET_LEFT_SHIFT_VAL(UPROTOCOL_AGC_ENABLE_FIELD); + } + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_usDumpMode, GH3X2X_DUMP_AMBIANCE_ENABLE_BIT)) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_TYPE_INDEX] |= \ + GH3X2X_GET_LEFT_SHIFT_VAL(UPROTOCOL_AMBIANCE_ENABLE_FIELD); + } + + usPayloadIndex = UPROTOCOL_FRAME_DATA_INDEX; + for (usDataIndex = g_usGh3x2xDataIndexInBuf; usDataIndex < usDataCnt; usDataIndex++) + { + uchZipDataFirstFrameSta = (usDataIndex == g_usGh3x2xDataIndexInBuf); + //judge if will exceed payload length limit + g_pstGh3x2xProtocolData->puchPacketPayloadArr[usPayloadIndex] = g_pstGh3x2xProtocolData->uchFrameIdArr[uchChannelMapId]; //FrameID + usFrameidIndex = usPayloadIndex; + g_pstGh3x2xProtocolData->uchFrameIdArr[uchChannelMapId]++; + usPayloadIndex++; + if (1 == uchGsEnable) + { + GH3X2X_FillGsensorData(&usPayloadIndex, &pstGsAxisValueArr[(GU16)g_fGsDataIndexInBuf]); + g_fGsDataIndexInBuf += fIndexInc; + } + + for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) // search each channel + { + uchDumpDataCalcTmp = g_uchDumpDataCntMapArr[puchChannelBgLvlArr[uchChCntIndex]]; + usRawdataByteIndexTmpBeforeHandleArr[uchChCntIndex] = g_usRawdataByteIndexArr[uchChCntIndex]; + if (uchDumpDataIndexArr[uchChCntIndex] < uchDumpDataCalcTmp) + { + usRawdataByteIndexTmp = g_usRawdataByteIndexArr[uchChCntIndex]; + while (usRawdataByteIndexTmp < usFifoRawdataLen) // search each + { + if (GH3X2X_CHANNEL_MAP_GET(puchFifoRawdata[usRawdataByteIndexTmp]) == \ + uchChannelMapArr[uchChCntIndex]) // if map equal + { + punIncompleteDumpdataArr[uchChCntIndex][uchDumpDataIndexArr[uchChCntIndex]] = \ + GH3X2X_MAKEUP_DWORD(puchFifoRawdata[usRawdataByteIndexTmp + 3], + puchFifoRawdata[usRawdataByteIndexTmp + 2], + puchFifoRawdata[usRawdataByteIndexTmp + 1], + puchFifoRawdata[usRawdataByteIndexTmp]); + uchDumpDataIndexArr[uchChCntIndex]++; + if (uchDumpDataIndexArr[uchChCntIndex] >= uchDumpDataCalcTmp) + { + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + break; + } + } + usRawdataByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + + uchDumpDataIndexArr[uchChCntIndex] = 0; + g_usRawdataByteIndexArr[uchChCntIndex] = usRawdataByteIndexTmp; // write back byte index + } // end of for (uchChCntIndex = 0; uchChCntIndex < uchChannelMapCnt; uchChCntIndex++) + + uchZipRet = GH3X2X_FillZipDumpData(&usPayloadIndex, uchChannelMapArr, uchChannelMapCnt, \ + puchChannelBgLvlArr, g_usDumpMode, punIncompleteDumpdataArr, uchZipDataFirstFrameSta, \ + &uchZipDiffDataSize, uchGainCurDataNum, uchAmbiDataNum); + + if (1 == uchZipRet) + { + GH3X2X_ZipPackFullStatusHandle(uchChannelMapId, usFrameidIndex, fIndexInc, \ + &usPayloadIndex, &usRawdataByteIndexTmp, \ + uchChannelMapCnt, usRawdataByteIndexTmpBeforeHandleArr); + break; + } + + if (1 == uchAlgoResFlag) + { + if (usPayloadIndex + (GU16)GH3X2X_ALGO_RESULT_WITH_TAG_CALC(uchAlgoResNum) + 1 >= \ + (GU16)GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport)) + { + GH3X2X_ZipPackFullStatusHandle(uchChannelMapId, usFrameidIndex, fIndexInc, \ + &usPayloadIndex, &usRawdataByteIndexTmp, \ + uchChannelMapCnt, usRawdataByteIndexTmpBeforeHandleArr); + break; + } + g_pstGh3x2xProtocolData->puchPacketPayloadArr[usPayloadIndex] = GH3X2X_ALGO_RESULT_WITH_TAG_CALC(uchAlgoResNum); + usPayloadIndex++; + #if 0 + if (nAlgoCalcResultArr != GH3X2X_PTR_NULL) + { + if (GH3X2X_ElectrodeWearRevertDebugModeIsEnabled()) + { + GH3X2X_FillAlgoData(&usPayloadIndex, nAlgoCalcResultArr, uchAlgoResNum - 1); + } + else + { + GH3X2X_FillAlgoData(&usPayloadIndex, nAlgoCalcResultArr, uchAlgoResNum); + } + } + #endif + + if ((GH3X2X_ElectrodeWearRevertDebugModeIsEnabled()) && (0 == usDataIndex)) + { + GH3X2X_FillElectrodeWearRevertData(&usPayloadIndex); + uchAlgoResNum -= 1; //only the first frame data has Flag data + } + + //uchAlgoResFlag = 0; + //uchFrameDataNum -= (GH3X2X_ALGO_RESULT_WITH_TAG_CALC(uchAlgoResNum) + 1); + } // end of if (1 == uchAlgoResFlag) + } // end of for (usDataIndex = g_usGh3x2xDataIndexInBuf; usDataIndex < usDataCnt; usDataIndex++) + + if (usDataIndex < usDataCnt) + { + g_usGh3x2xDataIndexInBuf = usDataIndex; + chRet = GH3X2X_RET_RAW_DATA_PKG_CONTINUE; + } + else + { + g_usGh3x2xDataIndexInBuf = 0; + g_fGsDataIndexInBuf = 0; + chRet = GH3X2X_RET_RAW_DATA_PKG_OVER; + GH3X2X_CacheIncompleteDumpdata(punLastIncompleteArr, punIncompleteDumpdataArr, uchNextIncompleteFlag, \ + puchFifoRawdata, usFifoRawdataLen, uchChannelMapArr, uchChannelMapCnt, \ + g_usRawdataByteIndexArr); + } // end else + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_RAWDATA_LEN_INDEX] = (GU8)(usPayloadIndex - UPROTOCOL_FRAME_DATA_INDEX); + uchSendCmd = GH3X2X_VAL_ZIPSENDCMD(g_uchDumpOddEvenChangeFlag); + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(uchSendCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, usPayloadIndex)); + g_uchDumpOddEvenChangeFlag = !g_uchDumpOddEvenChangeFlag; + } // end of if (GH3X2X_RET_OK == chRet) + else + { + pusRespondLen = 0; + } + + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendHbDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendHbDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHbaBgLevelArr[GH3X2X_HBA_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HBA)) + { + GU16 usReadDataLen = 0; + GH3X2X_BgLevelDecode(uchHbaBgLevelArr, g_uchHbaChannelMapCnt, g_uchHbaChannelMapArr, g_usBgLevel); + GH3X2X_DecryptRawdataBuffer(puchFifoRawdata, &usReadDataLen); + chRet = GH3X2X_SendDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHbaIncompleteArr, + g_unHbaIncompleteDumpdataArr, puchFifoRawdata, usReadDataLen, + g_uchHbaChannelMapArr, g_uchHbaChannelMapCnt, uchHbaBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HB_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HR); + GH3X2X_EncryptRawdataBuffer(puchFifoRawdata, usReadDataLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hba hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendHbDumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoDataLen, GS32 nAlgoResultArr[], + * STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, + * EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] usFifoDataLen gh3x2x fifo data len in byte + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendHbDumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, GU16 usFifoDataLen, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHbaBgLevelArr[GH3X2X_HBA_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HBA)) + { + GH3X2X_BgLevelDecode(uchHbaBgLevelArr, g_uchHbaChannelMapCnt, g_uchHbaChannelMapArr, g_usBgLevel); + chRet = GH3X2X_SendDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHbaIncompleteArr, + g_unHbaIncompleteDumpdataArr, puchFifoRawdata, usFifoDataLen, + g_uchHbaChannelMapArr, g_uchHbaChannelMapCnt, uchHbaBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HB_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HR); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hba hasn't started error!\r\n"); + } + return chRet; +} + +GS8 GH3X2X_SendHrvDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHrvBgLevelArr[GH3X2X_HRV_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HRV)) + { + GU16 usReadDataLen = 0; + GH3X2X_BgLevelDecode(uchHrvBgLevelArr, g_uchHrvChannelMapCnt, g_uchHrvChannelMapArr, g_usBgLevel); + GH3X2X_DecryptRawdataBuffer(puchFifoRawdata, &usReadDataLen); + chRet = GH3X2X_SendDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHrvIncompleteArr, + g_unHrvIncompleteDumpdataArr, puchFifoRawdata, usReadDataLen, + g_uchHrvChannelMapArr, g_uchHrvChannelMapCnt, uchHrvBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HRV_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HRV); + GH3X2X_EncryptRawdataBuffer(puchFifoRawdata, usReadDataLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hrv hasn't started error!\r\n"); + } + return chRet; +} + +GS8 GH3X2X_SendHrvDumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, GU16 usFifoDataLen, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHrvBgLevelArr[GH3X2X_HRV_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HRV)) + { + GH3X2X_BgLevelDecode(uchHrvBgLevelArr, g_uchHrvChannelMapCnt, g_uchHrvChannelMapArr, g_usBgLevel); + chRet = GH3X2X_SendDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHrvIncompleteArr, + g_unHrvIncompleteDumpdataArr, puchFifoRawdata, usFifoDataLen, + g_uchHrvChannelMapArr, g_uchHrvChannelMapCnt, uchHrvBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HRV_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HRV); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hrv hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendSpo2DumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendSpo2DumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchSpo2LevelArr[GH3X2X_SPO2_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_SPO2)) + { + GU16 usReadDataLen = 0; + GH3X2X_BgLevelDecode(uchSpo2LevelArr, g_uchSpo2ChannelMapCnt, g_uchSpo2ChannelMapArr, g_usBgLevel); + GH3X2X_DecryptRawdataBuffer(puchFifoRawdata, &usReadDataLen); + chRet = GH3X2X_SendDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchSpo2IncompleteArr, + g_unSpo2IncompleteDumpdataArr, puchFifoRawdata, usReadDataLen, + g_uchSpo2ChannelMapArr, g_uchSpo2ChannelMapCnt, uchSpo2LevelArr, + pstGsAxisValueArr, usGsDataNum, emGsSensitivity, GH3X2X_PTR_NULL, + GH3X2X_SPO2_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_SPO2); + GH3X2X_EncryptRawdataBuffer(puchFifoRawdata, usReadDataLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("spo2 hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendSpo2DumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoDataLen, GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] usFifoDataLen gh3x2x fifo data len in byte + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendSpo2DumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, GU16 usFifoDataLen, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchSpo2LevelArr[GH3X2X_SPO2_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_SPO2)) + { + GH3X2X_BgLevelDecode(uchSpo2LevelArr, g_uchSpo2ChannelMapCnt, g_uchSpo2ChannelMapArr, g_usBgLevel); + chRet = GH3X2X_SendDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchSpo2IncompleteArr, + g_unSpo2IncompleteDumpdataArr, puchFifoRawdata, usFifoDataLen, + g_uchSpo2ChannelMapArr, g_uchSpo2ChannelMapCnt, uchSpo2LevelArr, + pstGsAxisValueArr, usGsDataNum, emGsSensitivity, GH3X2X_PTR_NULL, + GH3X2X_SPO2_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_SPO2); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("spo2 hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendZipHbDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X Zip hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendZipHbDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHbaBgLevelArr[GH3X2X_HBA_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HBA)) + { + GU16 usReadDataLen = 0; + GH3X2X_BgLevelDecode(uchHbaBgLevelArr, g_uchHbaChannelMapCnt, g_uchHbaChannelMapArr, g_usBgLevel); + GH3X2X_DecryptRawdataBuffer(puchFifoRawdata, &usReadDataLen); + chRet = GH3X2X_SendZipDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHbaIncompleteArr, + g_unHbaIncompleteDumpdataArr, puchFifoRawdata, usReadDataLen, + g_uchHbaChannelMapArr, g_uchHbaChannelMapCnt, uchHbaBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HB_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HR); + GH3X2X_EncryptRawdataBuffer(puchFifoRawdata, usReadDataLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hba hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendZipHbDumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoDataLen, GS32 nAlgoResultArr[], + * STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, + * EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X Zip hb rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] usFifoDataLen gh3x2x fifo data len in byte + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendZipHbDumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, GU16 usFifoDataLen, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHbaBgLevelArr[GH3X2X_HBA_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HBA)) + { + GH3X2X_BgLevelDecode(uchHbaBgLevelArr, g_uchHbaChannelMapCnt, g_uchHbaChannelMapArr, g_usBgLevel); + chRet = GH3X2X_SendZipDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHbaIncompleteArr, + g_unHbaIncompleteDumpdataArr, puchFifoRawdata, usFifoDataLen, + g_uchHbaChannelMapArr, g_uchHbaChannelMapCnt, uchHbaBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HB_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HR); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hba hasn't started error!\r\n"); + } + return chRet; +} + /** + * @fn GS8 GH3X2X_SendZipHrvDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X Zip hrv rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendZipHrvDumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHrvBgLevelArr[GH3X2X_HRV_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HRV)) + { + GU16 usReadDataLen = 0; + GH3X2X_BgLevelDecode(uchHrvBgLevelArr, g_uchHrvChannelMapCnt, g_uchHrvChannelMapArr, g_usBgLevel); + GH3X2X_DecryptRawdataBuffer(puchFifoRawdata, &usReadDataLen); + chRet = GH3X2X_SendZipDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHrvIncompleteArr, + g_unHrvIncompleteDumpdataArr, puchFifoRawdata, usReadDataLen, + g_uchHrvChannelMapArr, g_uchHrvChannelMapCnt, uchHrvBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HRV_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HRV); + GH3X2X_EncryptRawdataBuffer(puchFifoRawdata, usReadDataLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hba hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendZipHrvDumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoDataLen, GS32 nAlgoResultArr[], + * STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, + * EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X Zip hrv rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] usFifoDataLen gh3x2x fifo data len in byte + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendZipHrvDumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, GU16 usFifoDataLen, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchHrvBgLevelArr[GH3X2X_HRV_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_HRV)) + { + GH3X2X_BgLevelDecode(uchHrvBgLevelArr, g_uchHrvChannelMapCnt, g_uchHrvChannelMapArr, g_usBgLevel); + chRet = GH3X2X_SendZipDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchHrvIncompleteArr, + g_unHrvIncompleteDumpdataArr, puchFifoRawdata, usFifoDataLen, + g_uchHrvChannelMapArr, g_uchHrvChannelMapCnt, uchHrvBgLevelArr, + pstGsAxisValueArr, usGsDataNum, + emGsSensitivity, GH3X2X_PTR_NULL, GH3X2X_HRV_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_HRV); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("hrv hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendZipSpo2DumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X Zip spo2 rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendZipSpo2DumpDataPkg(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchSpo2LevelArr[GH3X2X_SPO2_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_SPO2)) + { + GU16 usReadDataLen = 0; + GH3X2X_BgLevelDecode(uchSpo2LevelArr, g_uchSpo2ChannelMapCnt, g_uchSpo2ChannelMapArr, g_usBgLevel); + GH3X2X_DecryptRawdataBuffer(puchFifoRawdata, &usReadDataLen); + chRet = GH3X2X_SendZipDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchSpo2IncompleteArr, + g_unSpo2IncompleteDumpdataArr, puchFifoRawdata, usReadDataLen, + g_uchSpo2ChannelMapArr, g_uchSpo2ChannelMapCnt, uchSpo2LevelArr, + pstGsAxisValueArr, usGsDataNum, emGsSensitivity, GH3X2X_PTR_NULL, + GH3X2X_SPO2_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_SPO2); + GH3X2X_EncryptRawdataBuffer(puchFifoRawdata, usReadDataLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("spo2 hasn't started error!\r\n"); + } + return chRet; +} + +/** + * @fn GS8 GH3X2X_SendZipSpo2DumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, + * GU16 usFifoDataLen, GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief pack GH3X2X Zip spo2 rawdata and other type of data according to specific protocol + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to frame data package + * @param[out] pusRespondLen pointer to data length of package + * @param[in] puchFifoRawdata pointer to encrypted rawdata + * @param[in] usFifoDataLen gh3x2x fifo data len in byte + * @param[in] nAlgoResultArr pointer to algorithm result + * @param[in] pstGsAxisValueArr pointer to g sensor data + * @param[in] usGsDataNum number of g sensor data + * @param[in] emGsSensitivity sensitivity of g sensor + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_GENERIC_ERROR return func start error + * @retval #GH3X2X_RET_NO_INITED_ERROR gh3x2x has not inited + */ +GS8 GH3X2X_SendZipSpo2DumpDataPkgEx(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU8 *puchFifoRawdata, GU16 usFifoDataLen, + GS32 nAlgoResultArr[], STGsensorRawdata *pstGsAxisValueArr, + GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchSpo2LevelArr[GH3X2X_SPO2_CHANNEL_MAP_MAX_CNT] = {0}; + if (GH3X2X_CHECK_BIT_SET(g_usFuncStartedBitmap, GH3X2X_STARTED_BITMAP_SPO2)) + { + GH3X2X_BgLevelDecode(uchSpo2LevelArr, g_uchSpo2ChannelMapCnt, g_uchSpo2ChannelMapArr, g_usBgLevel); + chRet = GH3X2X_SendZipDumpDataPkgWithAlgo(puchRespondBuffer, pusRespondLen, g_uchSpo2IncompleteArr, + g_unSpo2IncompleteDumpdataArr, puchFifoRawdata, usFifoDataLen, + g_uchSpo2ChannelMapArr, g_uchSpo2ChannelMapCnt, uchSpo2LevelArr, + pstGsAxisValueArr, usGsDataNum, emGsSensitivity, GH3X2X_PTR_NULL, + GH3X2X_SPO2_ALGO_OUTPUT_NUM, GH3X2X_FUNC_OFFSET_SPO2); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("spo2 hasn't started error!\r\n"); + } + return chRet; +} +#endif +/** + * @fn GS8 GH3X2X_DumpRawdataFilter(GU8* puchRawDataBuffer, GU16* usRawDataLen, GU8 punLastIncompleteFlagArr[], + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8* puchReadFifoBuffer, + GU16 usFifoLen, GU16 usBgLevel) + * + * @brief filter dump fifo data to get rawdata + * + * @attention None + * + * @param[out] puchRawDataBuffer pointer to rawdata buffer + * @param[out] usRawDataLen pointer to rawdata number + * @param[out] punLastIncompleteFlagArr pointer to incomplete flag array + * @param[out] punIncompleteDumpdataArr pointer to incomplete data + * @param[in] puchReadFifoBuffer pointer to fifo data buffer + * @param[in] usFifoLen fifo data num + * @param[in] usBgLevel slot bg level + * + * @return error code + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR return parameter error + */ +GS8 GH3X2X_DumpRawdataFilter(GU8* puchRawDataBuffer, GU16* usRawDataLen, GU8 punLastIncompleteFlagArr[], + GU32 punIncompleteDumpdataArr[][GH3X2X_MAX_DUMP_DATA_NUM_CHANNEL], GU8* puchReadFifoBuffer, + GU16 usFifoLen, GU16 usBgLevel) +{ + GS8 schRetValue = GH3X2X_RET_OK; + GU16 usDataIndex = 0; + GU8 uchSlotIndex = 0; + GU8 uchAdcIndex = 0; + GU8 uchChIndex = 0; + GU8 uchBgLevel = 0; + GU8 puchDumpDataCntArr[GH3X2X_CHANNEL_MAP_MAX_CH] = {0}; //save dump data number of every channel + GU8 uchDumpDataCnt = 0; + GU8 uchDumpDataNum = 0; //dump data num of correspond bg level + GU32 unPpgDataFilter = 0; + + if ((GH3X2X_PTR_NULL == puchRawDataBuffer) || (GH3X2X_PTR_NULL == usRawDataLen) || \ + (GH3X2X_PTR_NULL == punLastIncompleteFlagArr) || (GH3X2X_PTR_NULL == punIncompleteDumpdataArr) || \ + (GH3X2X_PTR_NULL == puchReadFifoBuffer) || (0 == usFifoLen)) + { + usRawDataLen = 0; + schRetValue = GH3X2X_RET_PARAMETER_ERROR; + return schRetValue; + } + + //get current dump data index of every channel by count incomplete data + for (uchChIndex = 0; uchChIndex < GH3X2X_CHANNEL_MAP_MAX_CH; ++uchChIndex) + { + //loop time can be decided by bg level + uchBgLevel = g_uchChannelBgLvlArr[uchChIndex]; + uchDumpDataNum = g_uchDumpDataCntMapArr[uchBgLevel]; + for (uchDumpDataCnt = 0; uchDumpDataCnt < uchDumpDataNum; ++uchDumpDataCnt) + { + //if imcomplete bit flag is 1 + if (GH3X2X_CHECK_LEFT_BIT_SET(punLastIncompleteFlagArr[uchChIndex], uchDumpDataCnt)) + { + puchDumpDataCntArr[uchChIndex]++; + if (puchDumpDataCntArr[uchChIndex] >= uchDumpDataNum) + { + GH3X2X_DEBUG_LOG_PARAM("Cache incomplete data too much!\r\n"); + } + } + else + { + break; + } + } + } + + *usRawDataLen = 0; + + //filter every rawdata + for (usDataIndex = 0; usDataIndex < usFifoLen; usDataIndex += GH3X2X_FIFO_RAWDATA_SIZE) + { + //decode slot adc index + uchChIndex = GH3X2X_BYTE_RAWDATA_GET_SLOT_ADC_NUM(puchReadFifoBuffer[usDataIndex]); + uchSlotIndex = GH3X2X_BYTE_RAWDATA_GET_SLOT_NUM(puchReadFifoBuffer[usDataIndex]); + uchAdcIndex = GH3X2X_BYTE_RAWDATA_GET_ADC_NUM(puchReadFifoBuffer[usDataIndex]); + + if (GH3X2X_CHECK_LEFT_BIT_SET(g_uchEcgSlot, uchSlotIndex)) + { + //ECG data not need to filter + if (uchAdcIndex == GH3X2X_ECG_ADC_INDEX) + { + GH3X2X_Memcpy(&puchRawDataBuffer[*usRawDataLen], &puchReadFifoBuffer[usDataIndex], \ + GH3X2X_FIFO_RAWDATA_SIZE); + *usRawDataLen += GH3X2X_FIFO_RAWDATA_SIZE; + continue; + } + } + //decode bg level + uchBgLevel = g_uchChannelBgLvlArr[uchChIndex]; + uchDumpDataNum = g_uchDumpDataCntMapArr[uchBgLevel]; + //save them to implete array + GH3X2X_Memcpy(&punIncompleteDumpdataArr[uchChIndex][puchDumpDataCntArr[uchChIndex]], \ + &puchReadFifoBuffer[usDataIndex], GH3X2X_FIFO_RAWDATA_SIZE); + //set incomplete flag + punLastIncompleteFlagArr[uchChIndex] |= (GU8)GH3X2X_GET_LEFT_SHIFT_VAL(puchDumpDataCntArr[uchChIndex]); + puchDumpDataCntArr[uchChIndex]++; + //if save enough,calculate it,and save it to g_uchRawdataFilterArr,and clear incomplete flag + if (puchDumpDataCntArr[uchChIndex] >= uchDumpDataNum) + { + switch (uchBgLevel) + { + case GH3X2X_DUMP_RAWDATA_BGLVL0: + GH3X2X_Memcpy(&puchRawDataBuffer[*usRawDataLen], &punIncompleteDumpdataArr[uchChIndex][1], \ + GH3X2X_FIFO_RAWDATA_SIZE); + break; + case GH3X2X_DUMP_RAWDATA_BGLVL1: + unPpgDataFilter = GH3X2X_DumpRawDataPro(punIncompleteDumpdataArr[uchChIndex][2], \ + punIncompleteDumpdataArr[uchChIndex][1], \ + punIncompleteDumpdataArr[uchChIndex][1]); + GH3X2X_Memcpy(&puchRawDataBuffer[*usRawDataLen], &unPpgDataFilter, GH3X2X_FIFO_RAWDATA_SIZE); + break; + case GH3X2X_DUMP_RAWDATA_BGLVL2: + unPpgDataFilter = GH3X2X_DumpRawDataPro(punIncompleteDumpdataArr[uchChIndex][2], \ + punIncompleteDumpdataArr[uchChIndex][1], \ + punIncompleteDumpdataArr[uchChIndex][3]); + GH3X2X_Memcpy(&puchRawDataBuffer[*usRawDataLen], &unPpgDataFilter, GH3X2X_FIFO_RAWDATA_SIZE); + break; + case GH3X2X_DUMP_RAWDATA_BGLVL2X2: + unPpgDataFilter = GH3X2X_DumpRawDataPro(punIncompleteDumpdataArr[uchChIndex][0], \ + punIncompleteDumpdataArr[uchChIndex - GH3X2X_ADC_NUM][3], \ + punIncompleteDumpdataArr[uchChIndex][1]); + GH3X2X_Memcpy(&puchRawDataBuffer[*usRawDataLen], &unPpgDataFilter, GH3X2X_FIFO_RAWDATA_SIZE); + break; + default: + break; + } + *usRawDataLen += GH3X2X_FIFO_RAWDATA_SIZE; + puchDumpDataCntArr[uchChIndex] = 0; + punLastIncompleteFlagArr[uchChIndex] = 0; + } // end if (puchDumpDataCntArr[uchChIndex] >= uchDumpDataNum) + } // end for (usDataIndex = 0; usDataIndex < usFifoLen; usDataIndex += GH3X2X_FIFO_RAWDATA_SIZE) + return schRetValue; +} + +/** + * @fn void GH3X2X_LedAgcProcessExDump(GU8* puchReadFifoBuffer) + * + * @brief led agc process function + * + * @attention None + * + * @param[in] puchReadFifoBuffer pointer to read fifo data buffer + * @param[out] None + * + * @return None + */ +void GH3X2X_LedAgcProcessExDump(GU8* puchReadFifoBuffer) +{ + GU16 usFifoLen = 0; + GU16 usRawdataLen = 0; + GS8 schRetValue = GH3X2X_RET_OK; + //if (GH3X2X_LED_AGC_ENABLE != GH3X2X_GetLedAgcState()) + //{ + // return; + //} + GH3X2X_Memset(g_uchRawdataFilterArr, 0, RAWDATA_FILTER_ARRAY_BYTE_LENGTH * sizeof(g_uchRawdataFilterArr[0])); + //filter dump data,because AGC only process raw data + schRetValue = GH3X2X_DumpRawdataFilter(g_uchRawdataFilterArr, &usRawdataLen, g_uchDumpIncompleteFlagArr, \ + g_unDumpIncompleteRawdataArr, puchReadFifoBuffer, usFifoLen, g_usBgLevel); + if (GH3X2X_RET_OK == schRetValue) + { + GH3X2X_LedAgcProcess(g_uchRawdataFilterArr, usRawdataLen); + } +} + +#endif +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_interface.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_interface.c new file mode 100644 index 000000000..6941ef5a6 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/driver/src/gh_drv_interface.c @@ -0,0 +1,957 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_interface.c + * + * @brief gh3x2x interface functions + * + * @version ref gh3x2x_drv_version.h + * + */ + +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" +#include "gh_demo.h" +#include "gh_demo_config.h" +#include "gh_demo_inner.h" + +/// swap size of GU16 +#define SWAP_SIZE_OF_GU16 (2) + +/// swap index of next byte +#define SWAP_INDEX_OF_NEXT_BYTE (1) + +/* index of interface buffer */ +#define INTERFACE_INDEX_0_BUFFER (0) /**< index 0 of buffer */ +#define INTERFACE_INDEX_1_BUFFER (1) /**< index 1 of buffer */ +#define INTERFACE_INDEX_2_BUFFER (2) /**< index 2 of buffer */ +#define INTERFACE_INDEX_3_BUFFER (3) /**< index 3 of buffer */ +#define INTERFACE_INDEX_4_BUFFER (4) /**< index 4 of buffer */ +#define INTERFACE_INDEX_5_BUFFER (5) /**< index 5 of buffer */ +#define INTERFACE_INDEX_6_BUFFER (6) /**< index 6 of buffer */ +#define INTERFACE_INDEX_7_BUFFER (7) /**< index 7 of buffer */ + +/* spi operation */ +#define SPI_CMD_BUFFER_LEN (1) /**< spi cmd buffer len */ +#define SPI_WRITE_REG_BUFFER_LEN (7) /**< spi write reg buffer len */ +#define SPI_WRITE_REG_LEN_H (0x00) /**< spi write reg len high byte */ +#define SPI_WRITE_REG_LEN_L (0x02) /**< spi write reg len low byte */ +#define SPI_READ_REG_BUFFER_LEN (3) /**< spi read reg buffer len */ +#define SPI_READ_REG_CMD_LEN (1) /**< spi read reg buffer len */ +#define SPI_READ_REG_DATA_LEN (2) /**< spi read reg buffer len */ + +/* i2c operation */ +#define I2C_CMD_BUFFER_LEN (3) /**< i2c cmd buffer len */ +#define I2C_WRITE_REG_BUFFER_LEN (4) /**< i2c write reg buffer len */ +#define I2C_READ_REG_ADDR_LEN (2) /**< i2c read reg buffer len */ +#define I2C_READ_REG_DATA_LEN (2) /**< i2c read reg buffer len */ + + +/// +GU8 g_uchGh3x2xChipOperateIndexRealtime = 0; //0: chip0 1: chip1 +GU8 g_uchGh3x2xLogicMasterChipIndex = 0; //0: default master chip index 1: chip1(for mp test) + + +GU8 g_uchGhx2xChipSleepFlag = 0x03; // bit0: 0: chip0 wake up 1: chip0 sleep bit1: 0: chip1 wake up 1: chip1 sleep + +GU8 g_uchChipDivZeroFlag= 0; // 1: divde 0 happen + +/// i2c device addr +GU8 g_puchI2cDeviceIdList[2] = {GH3X2X_I2C_DEVICE_ID_BASE, GH3X2X_I2C_DEVICE_ID_BASE}; + +/// delay us func ptr +static pfnDelayUs g_pDelayUsFunc = GH3X2X_PTR_NULL; + +/// spi write func ptr +static pfnSpiRWCtrl g_pSpiWriteFunc = GH3X2X_PTR_NULL; + +/// spi read func ptr +static pfnSpiRWCtrl g_pSpiReadFunc = GH3X2X_PTR_NULL; + +/// spi cs ctrl func ptr +static pfnSpiCsCtrl g_pSpiCsCtrlFunc = GH3X2X_PTR_NULL; + +/// i2c write func ptr +static pfnI2cWrite g_pI2cWriteFunc = GH3X2X_PTR_NULL; + +/// i2c read func ptr +static pfnI2cRead g_pI2cReadFunc = GH3X2X_PTR_NULL; + +/// gh3x2x send cmd func ptr +static pfnSendCmd g_pGh3x2xSendCmdFunc = GH3X2X_PTR_NULL; + +/// gh3x2x write reg func ptr +static pfnWriteReg g_pGh3x2xWriteRegFunc = GH3X2X_PTR_NULL; + +/// gh3x2x read reg func ptr +static pfnReadReg g_pGh3x2xReadRegFunc = GH3X2X_PTR_NULL; + +/// gh3x2x read regs func ptr +static pfnReadRegs g_pGh3x2xReadRegsFunc = GH3X2X_PTR_NULL; + +/// gh3x2x read fifo func ptr +static pfnReadFifo g_pGh3x2xReadFifoFunc = GH3X2X_PTR_NULL; + + +/** + * @fn void GH3X2X_SwapLittleBigEndianData(GU8 *puchDataBuffer, GU16 usDataLength) + * + * @brief Swap little big endian data + * + * @attention None + * + * @param[in] puchDataBuffer pointer to data buffer. + * @param[in] usDataLength data buffer len. + * @param[out] None + * + * @return None + */ +void GH3X2X_SwapLittleBigEndianData(GU8 *puchDataBuffer, GU16 usDataLength) +{ + GU16 usIndex = 0; + + for (usIndex = 0; usIndex < (usDataLength / SWAP_SIZE_OF_GU16); usIndex++) + { + puchDataBuffer[usIndex * SWAP_SIZE_OF_GU16] ^= \ + puchDataBuffer[usIndex * SWAP_SIZE_OF_GU16 + SWAP_INDEX_OF_NEXT_BYTE]; + puchDataBuffer[usIndex * SWAP_SIZE_OF_GU16 + SWAP_INDEX_OF_NEXT_BYTE] ^= \ + puchDataBuffer[usIndex * SWAP_SIZE_OF_GU16]; + puchDataBuffer[usIndex * SWAP_SIZE_OF_GU16] ^= \ + puchDataBuffer[usIndex * SWAP_SIZE_OF_GU16 + SWAP_INDEX_OF_NEXT_BYTE]; + } +} + +/** + * @fn void GH3X2X_DelayUs(GU16 usUsCnt) + * + * @brief Delay N Us for gh3x2x + * + * @attention None + * + * @param[in] usUsCnt count need to delay(Us) + * @param[out] None + * + * @return None + */ +void GH3X2X_DelayUs(GU16 usUsCnt) +{ + if (g_pDelayUsFunc != GH3X2X_PTR_NULL) + { + g_pDelayUsFunc(usUsCnt); + } + else + { + volatile GU8 uchIndex; + while (usUsCnt > 0) + { + for (uchIndex = 0; uchIndex < GH3X2X_DELAY_ONE_US_CNT; uchIndex++) + { + // do nothing, like _nop(); + } + usUsCnt--; + } + } +} + +/** + * @fn void GH3X2X_RegisterDelayUsCallback(void (*pPlatformDelayUsFunc)(GU16 usUsec)) + * + * @brief Register delay us callback function + * + * @attention None + * + * @param[in] pPlatformDelayUsFunc pointer to delay us function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterDelayUsCallback(void (*pPlatformDelayUsFunc)(GU16 usUsec)) +{ + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + g_pDelayUsFunc = pPlatformDelayUsFunc; +} + +/** + * @fn static void GH3X2X_SpiSendCmd(GU8 uchCmd) + * + * @brief Send cmd via spi + * + * @attention None + * + * @param[in] uchCmd spi cmd + * @param[out] None + * + * @return None + */ +static void GH3X2X_SpiSendCmd(GU8 uchCmd) +{ + GU8 uchBuffArr[SPI_CMD_BUFFER_LEN]; + + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = uchCmd; + g_pSpiWriteFunc(uchBuffArr, SPI_CMD_BUFFER_LEN); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); +} + + +static void GH3X2X_SpiSendCmdHardwareCs(GU8 uchCmd) +{ + GU8 uchBuffArr[SPI_CMD_BUFFER_LEN]; + + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = uchCmd; + g_pSpiWriteFunc(uchBuffArr, SPI_CMD_BUFFER_LEN); +} + + +/** + * @fn static void GH3X2X_SpiWriteReg(GU16 usRegAddr, GU16 usRegValue) + * + * @brief Write register via spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] usRegValue register data + * @param[out] None + * + * @return None + */ +static void GH3X2X_SpiWriteReg(GU16 usRegAddr, GU16 usRegValue) +{ + GU8 uchBuffArr[SPI_WRITE_REG_BUFFER_LEN]; + + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_SPI_CMD_WRITE; + uchBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegAddr); + uchBuffArr[INTERFACE_INDEX_2_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegAddr); + uchBuffArr[INTERFACE_INDEX_3_BUFFER] = SPI_WRITE_REG_LEN_H; + uchBuffArr[INTERFACE_INDEX_4_BUFFER] = SPI_WRITE_REG_LEN_L; + uchBuffArr[INTERFACE_INDEX_5_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegValue); + uchBuffArr[INTERFACE_INDEX_6_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegValue); + g_pSpiWriteFunc(uchBuffArr, SPI_WRITE_REG_BUFFER_LEN); + GH3X2X_DelayUs(GH3X2X_SPI_WAIT_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); +} + + +static void GH3X2X_SpiWriteRegHardwareCs(GU16 usRegAddr, GU16 usRegValue) +{ + GU8 puchWriteBuf[7]; + puchWriteBuf[0] = 0xF0; + puchWriteBuf[1] = usRegAddr>>8; + puchWriteBuf[2] = usRegAddr&0x00FF; + puchWriteBuf[3] = 0; + puchWriteBuf[4] = 2; + puchWriteBuf[5] = usRegValue>>8; + puchWriteBuf[6] = usRegValue&0x00FF; + g_pSpiWriteFunc(puchWriteBuf, SPI_WRITE_REG_BUFFER_LEN); +} + + + + + + +/** + * @fn static GU16 GH3X2X_SpiReadReg(GU16 usRegAddr) + * + * @brief Read register via spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[out] None + * + * @return register data + */ +static GU16 GH3X2X_SpiReadReg(GU16 usRegAddr) +{ + GU8 uchBuffArr[SPI_READ_REG_BUFFER_LEN] = {0}; + + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_SPI_CMD_WRITE; + uchBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegAddr); + uchBuffArr[INTERFACE_INDEX_2_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegAddr); + g_pSpiWriteFunc(uchBuffArr, SPI_READ_REG_BUFFER_LEN); + GH3X2X_DelayUs(GH3X2X_SPI_WAIT_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_SPI_CMD_READ; + g_pSpiWriteFunc(uchBuffArr, SPI_READ_REG_CMD_LEN); + g_pSpiReadFunc(uchBuffArr, SPI_READ_REG_DATA_LEN); + GH3X2X_DelayUs(GH3X2X_SPI_WAIT_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); + return GH3X2X_MAKEUP_WORD(uchBuffArr[INTERFACE_INDEX_0_BUFFER], uchBuffArr[INTERFACE_INDEX_1_BUFFER]); +} + + +static GU16 GH3X2X_SpiReadRegHardwareCs(GU16 usRegAddr) +{ + GU8 puchWriteBuf[7]; + GU8 puchReadBuf[2]; + puchWriteBuf[0] = 0xF0; + puchWriteBuf[1] = usRegAddr>>8; + puchWriteBuf[2] = usRegAddr&0x00FF; + g_pSpiWriteFunc(puchWriteBuf, 3); + g_pSpiReadFunc(puchReadBuf, 2); + return ((((GU16)puchReadBuf[0])<<8) + puchReadBuf[1]); +} + + + + + +/** + * @fn static void GH3X2X_SpiReadRegs(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 uchLen) + * + * @brief Read multi register via spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] pusRegValueBuffer pointer to register value buffer + * @param[in] uchLen registers len + * @param[out] None + * + * @return None + */ +static void GH3X2X_SpiReadRegs(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 uchLen) +{ + GU8 uchBuffArr[SPI_READ_REG_BUFFER_LEN] = {0}; + + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_SPI_CMD_WRITE; + uchBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegAddr); + uchBuffArr[INTERFACE_INDEX_2_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegAddr); + g_pSpiWriteFunc(uchBuffArr, SPI_READ_REG_BUFFER_LEN); + GH3X2X_DelayUs(GH3X2X_SPI_WAIT_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_SPI_CMD_READ; + g_pSpiWriteFunc(uchBuffArr, SPI_READ_REG_CMD_LEN); + g_pSpiReadFunc((GU8 *)pusRegValueBuffer, uchLen * SPI_READ_REG_DATA_LEN); + GH3X2X_SwapLittleBigEndianData((GU8 *)pusRegValueBuffer, (GU16)((GU16)uchLen * SPI_READ_REG_DATA_LEN)); + GH3X2X_DelayUs(GH3X2X_SPI_WAIT_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); +} + + + +static void GH3X2X_SpiReadRegsHardwareCs(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 uchLen) +{ + GU8 puchWriteBuf[3]; + puchWriteBuf[0] = 0xF0; + puchWriteBuf[1] = usRegAddr>>8; + puchWriteBuf[2] = usRegAddr&0x00FF; + g_pSpiWriteFunc(puchWriteBuf, 3); + g_pSpiReadFunc((GU8 *)pusRegValueBuffer, uchLen * SPI_READ_REG_DATA_LEN); + GH3X2X_SwapLittleBigEndianData((GU8 *)pusRegValueBuffer, (GU16)((GU16)uchLen * SPI_READ_REG_DATA_LEN)); + +} + + + + + +/** + * @fn static void GH3X2X_SpiReadFifo(GU8 *puchDataBuffer, GU16 usLen) + * + * @brief Read fifo via spi + * + * @attention None + * + * @param[in] puchDataBuffer pointer to buffer for fifo rawdata + * @param[in] usLen fifo bytes len + * @param[out] None + * + * @return None + */ +static void GH3X2X_SpiReadFifo(GU8 *puchDataBuffer, GU16 usLen) +{ + GU8 uchBuffArr[SPI_READ_REG_BUFFER_LEN] = {0}; + + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_SPI_CMD_WRITE; + uchBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(GH3X2X_FIFO_REG_ADDR); + uchBuffArr[INTERFACE_INDEX_2_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_FIFO_REG_ADDR); + g_pSpiWriteFunc(uchBuffArr, SPI_READ_REG_BUFFER_LEN); + GH3X2X_DelayUs(GH3X2X_SPI_WAIT_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_LOW); + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_SPI_CMD_READ; + g_pSpiWriteFunc(uchBuffArr, SPI_READ_REG_CMD_LEN); + g_pSpiReadFunc(puchDataBuffer, usLen); + GH3X2X_DelayUs(GH3X2X_SPI_WAIT_DELAY_X_US); + g_pSpiCsCtrlFunc(GH3X2X_SPI_CS_CTRL_HIGH); + GH3X2X_DelayUs(GH3X2X_SPI_END_DELAY_X_US); +} + +static void GH3X2X_SpiReadFifoHardwareCs(GU8 *puchDataBuffer, GU16 usLen) +{ + GU8 puchWriteBuf[3]; + puchWriteBuf[0] = 0xF0; + puchWriteBuf[1] = 0xAAAA>>8; + puchWriteBuf[2] = 0xAAAA&0x00FF; + g_pSpiWriteFunc(puchWriteBuf, 3); + g_pSpiReadFunc(puchDataBuffer, usLen); +} + + +/** + * @fn static void GH3X2X_I2cSendCmd(GU8 uchCmd) + * + * @brief Send cmd via i2c + * + * @attention None + * + * @param[in] uchCmd i2c cmd + * @param[out] None + * + * @return None + */ +static void GH3X2X_I2cSendCmd(GU8 uchCmd) +{ + GU8 uchBuffArr[I2C_CMD_BUFFER_LEN] = {0}; + + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(GH3X2X_I2C_CMD_ADDR); + uchBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_I2C_CMD_ADDR); + uchBuffArr[INTERFACE_INDEX_2_BUFFER] = uchCmd; + g_pI2cWriteFunc(g_puchI2cDeviceIdList[g_uchGh3x2xChipOperateIndexRealtime], uchBuffArr, I2C_CMD_BUFFER_LEN); +} + +/** + * @fn static void GH3X2X_I2cWriteReg(GU16 usRegAddr, GU16 usRegValue) + * + * @brief Write register via i2c + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] usRegValue register data + * @param[out] None + * + * @return None + */ +static void GH3X2X_I2cWriteReg(GU16 usRegAddr, GU16 usRegValue) +{ + GU8 uchBuffArr[I2C_WRITE_REG_BUFFER_LEN] = {0}; + + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegAddr); + uchBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegAddr); + uchBuffArr[INTERFACE_INDEX_2_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegValue); + uchBuffArr[INTERFACE_INDEX_3_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegValue); + g_pI2cWriteFunc(g_puchI2cDeviceIdList[g_uchGh3x2xChipOperateIndexRealtime], uchBuffArr, I2C_WRITE_REG_BUFFER_LEN); +} + +/** + * @fn static GU16 GH3X2X_I2cReadReg(GU16 usRegAddr) + * + * @brief Read register via i2c + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[out] None + * + * @return register data + */ +static GU16 GH3X2X_I2cReadReg(GU16 usRegAddr) +{ + GU8 uchCmdBuffArr[I2C_READ_REG_ADDR_LEN] = {0}; + GU8 uchReadBuffArr[I2C_READ_REG_DATA_LEN] = {0}; + + uchCmdBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegAddr); + uchCmdBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegAddr); + g_pI2cReadFunc(g_puchI2cDeviceIdList[g_uchGh3x2xChipOperateIndexRealtime], uchCmdBuffArr, I2C_READ_REG_ADDR_LEN, uchReadBuffArr, I2C_READ_REG_DATA_LEN); + return GH3X2X_MAKEUP_WORD(uchReadBuffArr[INTERFACE_INDEX_0_BUFFER], uchReadBuffArr[INTERFACE_INDEX_1_BUFFER]); +} + +/** + * @fn static void GH3X2X_I2cReadRegs(GU16 usRegAddr, GU16 *pusRegValueArr, GU16 uchLen) + * + * @brief Read multi register via i2c + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] pusRegValueBuffer pointer to register value buffer + * @param[in] uchLen registers len + * @param[out] None + * + * @return None + */ +static void GH3X2X_I2cReadRegs(GU16 usRegAddr, GU16 *pusRegValueArr, GU16 uchLen) +{ + GU8 uchBuffArr[I2C_READ_REG_ADDR_LEN] = {0}; + + uchBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegAddr); + uchBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegAddr); + g_pI2cReadFunc(g_puchI2cDeviceIdList[g_uchGh3x2xChipOperateIndexRealtime], uchBuffArr, I2C_READ_REG_ADDR_LEN, \ + (GU8 *)pusRegValueArr, uchLen * I2C_READ_REG_DATA_LEN); + GH3X2X_SwapLittleBigEndianData((GU8 *)pusRegValueArr, (GU16)uchLen * I2C_READ_REG_DATA_LEN); +} + +/** + * @fn static void GH3X2X_I2cReadFifo(GU8 *puchDataBuffer, GU16 usLen) + * + * @brief Read fifo via i2c + * + * @attention None + * + * @param[in] puchDataBuffer pointer to buffer for fifo rawdata + * @param[in] usLen fifo bytes len + * @param[out] None + * + * @return None + */ +static void GH3X2X_I2cReadFifo(GU8 *puchDataBuffer, GU16 usLen) +{ + GU8 uchCmdBuffArr[I2C_READ_REG_ADDR_LEN] = {0}; + + uchCmdBuffArr[INTERFACE_INDEX_0_BUFFER] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(GH3X2X_FIFO_REG_ADDR); + uchCmdBuffArr[INTERFACE_INDEX_1_BUFFER] = GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_FIFO_REG_ADDR); + g_pI2cReadFunc(g_puchI2cDeviceIdList[g_uchGh3x2xChipOperateIndexRealtime], uchCmdBuffArr, I2C_READ_REG_ADDR_LEN, puchDataBuffer, usLen); +} + +/** + * @fn void GH3X2X_SendCmd(GU8 uchCmd) + * + * @brief Send cmd via i2c or spi + * + * @attention None + * + * @param[in] uchCmd cmd + * @param[out] None + * + * @return None + */ +void GH3X2X_SendCmd(GU8 uchCmd) +{ + if (g_pGh3x2xSendCmdFunc != GH3X2X_PTR_NULL) + { + g_pGh3x2xSendCmdFunc(uchCmd); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("communicate interface register error!\r\n"); + } +} + + +void GH3X2X_TryWakeUp(void) +{ + GU8 uchSleepFlag; + uchSleepFlag = (g_uchGhx2xChipSleepFlag&(1 << g_uchGh3x2xChipOperateIndexRealtime)); + if(uchSleepFlag) + { + g_uchGhx2xChipSleepFlag &= (~(1 << g_uchGh3x2xChipOperateIndexRealtime)); //clear sleep flag + GH3X2X_ExitLowPowerMode(); + } +} + + + +/** + * @fn void GH3X2X_ClearChipSleepFlag(GU8 uchChipIndex) + * + * @brief clear chip sleep flag + * + * @attention None + * + * @param[in] uchChipIndex 0: chip0 1: chip1 + * @param[out] None + * + * @return None + */ +void GH3X2X_ClearChipSleepFlag(GU8 uchChipIndex) +{ + g_uchGhx2xChipSleepFlag &= (~(1 << uchChipIndex)); +} + + +/** + * @fn void GH3X2X_SetChipSleepFlag(GU8 uchChipIndex) + * + * @brief set chip sleep flag + * + * @attention None + * + * @param[in] uchChipIndex 0: chip0 1: chip1 + * @param[out] None + * + * @return None + */ +void GH3X2X_SetChipSleepFlag(GU8 uchChipIndex) +{ + g_uchGhx2xChipSleepFlag |= ((1 << uchChipIndex)); +} + +#if GH3X2X_DIVIDE_ZERO_FLAG_UPLODE_EN +void GH3X2X_SetDivZeroFlag() +{ + g_uchChipDivZeroFlag = 1; +} + +void GH3X2X_ClearDivZeroFlag() +{ + g_uchChipDivZeroFlag = 0; + GOODIX_PLATFORM_INT_DIVIDE_ZERO_ENABLE_ENTITY(); +} +#endif + +/** + * @fn void GH3X2X_WriteReg(GU16 usRegAddr, GU16 usRegValue) + * + * @brief Write register via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] usRegValue register data + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteReg(GU16 usRegAddr, GU16 usRegValue) +{ + if (g_pGh3x2xWriteRegFunc != GH3X2X_PTR_NULL) + { + GH3X2X_TryWakeUp(); + g_pGh3x2xWriteRegFunc(usRegAddr, usRegValue); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("communicate interface register error!\r\n"); + } +} + +/** + * @fn GU16 GH3X2X_ReadReg(GU16 usRegAddr) + * + * @brief Read register via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[out] None + * + * @return register data + */ +GU16 GH3X2X_ReadReg(GU16 usRegAddr) +{ + GU16 usRegData = 0; + + + if (g_pGh3x2xReadRegFunc != GH3X2X_PTR_NULL) + { + GH3X2X_TryWakeUp(); + usRegData = g_pGh3x2xReadRegFunc(usRegAddr); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("communicate interface register error!\r\n"); + } + return usRegData; +} + +/** + * @fn GU32 GH3X2X_ReadRegs(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 usLen) + * + * @brief Read multi register via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] pusRegValueBuffer pointer to register value buffer + * @param[in] uchLen registers len + * @param[out] None + * + * @return None + */ +GU32 GH3X2X_ReadRegs(GU16 usRegAddr, GU16 *pusRegValueBuffer, GU16 usLen) +{ + GU32 unRegData = 0; + if (g_pGh3x2xReadRegsFunc != GH3X2X_PTR_NULL) + { + GH3X2X_TryWakeUp(); + g_pGh3x2xReadRegsFunc(usRegAddr, pusRegValueBuffer, usLen); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("communicate interface register error!\r\n"); + } + return unRegData; +} + +/** + * @fn void GH3X2X_ReadFifo(GU8 *puchDataBuffer, GU16 usLen) + * + * @brief Read fifo via i2c or spi + * + * @attention None + * + * @param[in] puchDataBuffer pointer to buffer for fifo rawdata + * @param[in] usLen fifo bytes len + * @param[out] None + * + * @return None + */ +void GH3X2X_ReadFifo(GU8 *puchDataBuffer, GU16 usLen) +{ + if (g_pGh3x2xReadFifoFunc != GH3X2X_PTR_NULL) + { + GH3X2X_TryWakeUp(); + g_pGh3x2xReadFifoFunc(puchDataBuffer, usLen); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("communicate interface register error!\r\n"); + } +} + +/** + * @fn void GH3X2X_WriteRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb, GU16 usValue) + * + * @brief write register bit field via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] uchLsb lsb of bit field + * @param[in] uchMsb msb of bit field + * @param[in] usRegValue register data + * @param[out] None + * + * @return None + */ +void GH3X2X_WriteRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb, GU16 usValue) +{ + GU16 usMakData = ((((GU16)0x0001) << (uchMsb - uchLsb + 1)) - 1) << uchLsb; + GU16 usRegData = 0; + if ((g_pGh3x2xReadRegFunc != GH3X2X_PTR_NULL) && (g_pGh3x2xWriteRegFunc != GH3X2X_PTR_NULL)) + { + GH3X2X_TryWakeUp(); + usRegData = g_pGh3x2xReadRegFunc(usRegAddr); + GH3X2X_VAL_CLEAR_BIT(usRegData, usMakData); + GH3X2X_VAL_SET_BIT(usRegData, (usValue << uchLsb) & usMakData); + g_pGh3x2xWriteRegFunc(usRegAddr, usRegData); + } + else + { + GH3X2X_DEBUG_LOG_PARAM("communicate interface register error!\r\n"); + } +} + +/** + * @fn GU16 GH3X2X_ReadRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb) + * + * @brief Read register bit field via i2c or spi + * + * @attention None + * + * @param[in] usRegAddr register addr + * @param[in] uchLsb lsb of bit field + * @param[in] uchMsb msb of bit field + * @param[out] None + * + * @return register bit field data + */ +GU16 GH3X2X_ReadRegBitField(GU16 usRegAddr, GU8 uchLsb, GU8 uchMsb) +{ + GU16 usMakData = ((((GU16)0x0001) << (uchMsb - uchLsb + 1)) - 1) << uchLsb; + GU16 usRegData = 0; + if (g_pGh3x2xReadRegFunc != GH3X2X_PTR_NULL) + { + GH3X2X_TryWakeUp(); + usRegData = g_pGh3x2xReadRegFunc(usRegAddr); + GH3X2X_VAL_GET_BIT(usRegData, usMakData); + usRegData >>= uchLsb; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("communicate interface register error!\r\n"); + } + return usRegData; +} + +/** + * @fn GS8 GH3X2X_RegisterSpiOperationFunc(GU8 (*pSpiWriteFunc)(GU8 uchWriteBytesArr[], GU16 usWriteLen), + * GU8 (*pSpiReadFunc)(GU8 uchReadBytesArr[], GU16 usMaxReadLen), + * void (*pSpiCsCtrlFunc)(GU8 uchCsLevelHigh)) + * + * @brief Register spi operation function callback + * + * @attention None + * + * @param[in] pSpiWriteFunc pointer to spi write function + * @param[in] pSpiReadFunc pointer to spi read function + * @param[in] pSpiCsCtrlFunc pointer to spi cs operation function + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR spi operation function pointer parameter error + */ +GS8 GH3X2X_RegisterSpiOperationFunc(GU8 (*pSpiWriteFunc)(GU8 uchWriteBytesArr[], GU16 usWriteLen), + GU8 (*pSpiReadFunc)(GU8 uchReadBytesArr[], GU16 usMaxReadLen), + void (*pSpiCsCtrlFunc)(GU8 uchCsLevelHigh)) +{ + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((pSpiWriteFunc != GH3X2X_PTR_NULL) && (pSpiReadFunc != GH3X2X_PTR_NULL) && (pSpiCsCtrlFunc != GH3X2X_PTR_NULL)) + { + g_pSpiWriteFunc = pSpiWriteFunc; + g_pSpiReadFunc = pSpiReadFunc; + g_pSpiCsCtrlFunc = pSpiCsCtrlFunc; + + g_pGh3x2xSendCmdFunc = GH3X2X_SpiSendCmd; + g_pGh3x2xWriteRegFunc = GH3X2X_SpiWriteReg; + g_pGh3x2xReadRegFunc = GH3X2X_SpiReadReg; + g_pGh3x2xReadRegsFunc = GH3X2X_SpiReadRegs; + g_pGh3x2xReadFifoFunc = GH3X2X_SpiReadFifo; + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("spi register param error!\r\n"); + } + return chRet; +} + +GS8 GH3X2X_RegisterSpiHwCsOperationFunc(GU8 (*pSpiWriteFunc)(GU8 uchWriteBytesArr[], GU16 usWriteLen), + GU8 (*pSpiWriteF1ReadFunc)(GU8 uchReadBytesArr[], GU16 usMaxReadLen) + ) +{ + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((pSpiWriteFunc != GH3X2X_PTR_NULL) && (pSpiWriteF1ReadFunc != GH3X2X_PTR_NULL) ) + { + g_pSpiWriteFunc = pSpiWriteFunc; + g_pSpiReadFunc = pSpiWriteF1ReadFunc; + + g_pGh3x2xSendCmdFunc = GH3X2X_SpiSendCmdHardwareCs; + g_pGh3x2xWriteRegFunc = GH3X2X_SpiWriteRegHardwareCs; + g_pGh3x2xReadRegFunc = GH3X2X_SpiReadRegHardwareCs; + g_pGh3x2xReadRegsFunc = GH3X2X_SpiReadRegsHardwareCs; + g_pGh3x2xReadFifoFunc = GH3X2X_SpiReadFifoHardwareCs; + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("spi register param error!\r\n"); + } + return chRet; +} + + +/** + * @fn GS8 GH3X2X_RegisterI2cOperationFunc(GU8 uchI2cIdLowTwoBitsSelect, + * GU8 (*pI2cWriteFunc)(GU8 uchDeviceId, const GU8 uchWriteBytesArr[], GU16 usWriteLen), + * GU8 (*pI2cReadFunc)(GU8 uchDeviceId, const GU8 uchCmddBytesArr[], GU16 usCmddLen, + * GU8 uchReadBytesArr[], GU16 usMaxReadLen)) + * + * @brief Register i2c operation function callback + * + * @attention None + * + * @param[in] uchI2cIdLowTwoBitsSelect i2c low two bits addr selected, ref EMGh3x2xI2cIdSelect + * @param[in] pI2cWriteFunc pointer to i2c write function + * @param[in] pI2cReadFunc pointer to i2c read function + * @param[out] None + * + * @return errcode + * @retval #GH3X2X_RET_OK return successfully + * @retval #GH3X2X_RET_PARAMETER_ERROR i2c operation function pointer parameter error + */ +GS8 GH3X2X_RegisterI2cOperationFunc(GU8 uchI2cIdLowTwoBitsSelect, + GU8 (*pI2cWriteFunc)(GU8 uchDeviceId, const GU8 uchWriteBytesArr[], GU16 usWriteLen), + GU8 (*pI2cReadFunc)(GU8 uchDeviceId, const GU8 uchCmddBytesArr[], GU16 usCmddLen, + GU8 uchReadBytesArr[], GU16 usMaxReadLen)) +{ + GS8 chRet = GH3X2X_RET_PARAMETER_ERROR; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if ((pI2cWriteFunc != GH3X2X_PTR_NULL) && (pI2cReadFunc != GH3X2X_PTR_NULL) + && (uchI2cIdLowTwoBitsSelect < GH3X2X_I2C_ID_INVALID)) + { + g_puchI2cDeviceIdList[0] = GH3X2X_I2C_DEVICE_ID_BASE | (uchI2cIdLowTwoBitsSelect << 1); + g_pI2cWriteFunc = pI2cWriteFunc; + g_pI2cReadFunc = pI2cReadFunc; + + g_pGh3x2xSendCmdFunc = GH3X2X_I2cSendCmd; + g_pGh3x2xWriteRegFunc = GH3X2X_I2cWriteReg; + g_pGh3x2xReadRegFunc = GH3X2X_I2cReadReg; + g_pGh3x2xReadRegsFunc = GH3X2X_I2cReadRegs; + g_pGh3x2xReadFifoFunc = GH3X2X_I2cReadFifo; + chRet = GH3X2X_RET_OK; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("i2c register param error!\r\n"); + } + return chRet; +} + + +/** + * @fn GU8 GH3x2xGetChipOperateIndexRealtime(void) + * + * @brief get current chip operate index + * + * @attention None + * @param[in] None + * @param[out] 0: chip0 1: chip1 + * + * @return None + */ +GU8 GH3x2xGetChipOperateIndexRealtime(void) +{ + return g_uchGh3x2xChipOperateIndexRealtime; +} + + +/** + * @fn void GH3X2X_RegisterI2cDeviceChip1(GU8 uchI2cIdLowTwoBitsSelect) + * + * @brief Register chip1 i2c device addr + * + * @attention None + * @param[in] uchI2cIdLowTwoBitsSelect i2c low two bits addr selected, ref EMGh3x2xI2cIdSelect + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterI2cDeviceChip1(GU8 uchI2cIdLowTwoBitsSelect) +{ + g_puchI2cDeviceIdList[1] = GH3X2X_I2C_DEVICE_ID_BASE | (uchI2cIdLowTwoBitsSelect << 1); +} + +void GH3X2X_CascadeOperationMasterChip(void) +{ + g_uchGh3x2xChipOperateIndexRealtime = g_uchGh3x2xLogicMasterChipIndex; +} + +void GH3X2X_CascadeOperationSlaverChip(void) +{ + g_uchGh3x2xChipOperateIndexRealtime = 1; +} + +void GH3X2X_CascadeSetLogicMasterChip(GU8 uchPhysicsChipIndex) +{ + g_uchGh3x2xLogicMasterChipIndex = uchPhysicsChipIndex; + GH3X2X_CascadeOperationMasterChip(); +} + + + + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo.c new file mode 100644 index 000000000..5f88dcad7 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo.c @@ -0,0 +1,3611 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo.c + * + * @brief gh3x2x driver example + * + * @author Gooidx Iot Team + * + */ + +/* includes */ +#include "gh_demo.h" +#include "gh_demo_config.h" +#include "gh_demo_inner.h" +#include "gh_multi_sen_pro.h" +#include "gh_demo_version.h" +#include "gh3x2x_demo_algo_config.h" +#include "gh_drv.h" +#include "goodix_log.h" +#include "gh_drv_control.h" + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) +#include "gh3x2x_demo_algo_call.h" +#endif + +#define GH3X2X_INT_PROCESS_SUCCESS (0) /**< gh3x2x interrupt process success */ +#define GH3X2X_INT_PROCESS_REPEAT (1) /**< need process gh3x2x interrupt process again */ + + +#if (__SUPPORT_HARD_ADT_CONFIG__) +#define __GH3X2X_ADT_EVENT_MASK__ (GH3X2X_IRQ_MSK_WEAR_ON_BIT | GH3X2X_IRQ_MSK_WEAR_OFF_BIT) +#else +#define __GH3X2X_ADT_EVENT_MASK__ (0) +#endif + + +#if (__ADT_ONLY_PARTICULAR_WM_CONFIG__) +GU16 g_usCurrentConfigListFifoWmBak = 0; +extern GU16 g_usCurrentFiFoWaterLine; +#endif + + +#if (__FUNC_TYPE_ECG_ENABLE__) +#define __GH3X2X_ECG_EVENT_MASK__ (GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT) +#else +#define __GH3X2X_ECG_EVENT_MASK__ (0) +#endif + +/* GH3X2X event that need to process */ +#define __GH3X2X_EVENT_PROCESS_MASK__ (\ + __GH3X2X_ADT_EVENT_MASK__ | __GH3X2X_ECG_EVENT_MASK__ | \ + GH3X2X_IRQ_MSK_FIFO_WATERMARK_BIT | GH3X2X_IRQ_MSK_FIFO_FULL_BIT | \ + GH3X2X_IRQ_MSK_TUNNING_FAIL_BIT | GH3X2X_IRQ_MSK_TUNNING_DONE_BIT | \ + GH3X2X_IRQ_MSK_CHIP_RESET_BIT \ + ) +#define DRV_LIB_REG_CFG_EMPTY (0x00) //there is no reg config array loaded into driver lib +#define DRV_LIB_REG_CFG_MIN_LEN (0x5) //minimum length of reg config array + +int (*g_pPrintfUserIn)(const char *, ...) = 0; +int (*g_pSnprintfUserIn)(char *str, size_t size, const char *format, ...) = 0; + + + + +#if __GS_GYRO_ENABLE__ +const GU8 g_uchGyroEnable = 1; +#else +const GU8 g_uchGyroEnable = 0; +#endif +/// gsensor fifo index +static GU16 gsensor_soft_fifo_buffer_index = 0; + +/// gsensor fifo +static STGsensorRawdata gsensor_soft_fifo_buffer[__GSENSOR_DATA_BUFFER_SIZE__ + __GS_EXTRA_BUF_LEN__]; +#if __CAP_ENABLE__ +static GU16 cap_soft_fifo_buffer_index = 0; +static STCapRawdata cap_soft_fifo_buffer[__CAP_DATA_BUFFER_SIZE__]; +#else +static GU16 cap_soft_fifo_buffer_index = 0; +static STCapRawdata* cap_soft_fifo_buffer = 0; +#endif +#if __TEMP_ENABLE__ +static GU16 temp_soft_fifo_buffer_index = 0; +static STTempRawdata temp_soft_fifo_buffer[__TEMP_DATA_BUFFER_SIZE__]; +#else +static GU16 temp_soft_fifo_buffer_index = 0; +static STTempRawdata* temp_soft_fifo_buffer = 0; +#endif + +GU32 g_unDemoFuncMode = 0; +GU8 g_uchDemoWorkMode = GH3X2X_DEMO_WORK_MODE_MCU_ONLINE; +GU8 g_uchDemoAlgoEnableFlag = 1; +#if __SLOT_SEQUENCE_DYNAMIC_ADJUST_EN__ +GU16 g_usGh3x2xSlotTime[8]; +#endif + + +#if (__SUPPORT_ELECTRODE_WEAR_STATUS_DUMP__) +GU8 g_uchGh3x2xElectrodeWearStatus; +#endif +EMWearDetectType g_uchWearDetectStatus = WEAR_DETECT_WEAR_ON; +/// save bg cancel value of every channel +GU8 g_puchGainBgCancelRecord[CHANNEL_MAP_ID_NUM]; + +//save agc info +STGh3x2xAgcInfo g_stGh3x2xAgcInfo = {0}; +STGh3x2xAgcInfo *g_pstGh3x2xAgcInfo = &g_stGh3x2xAgcInfo; + +#if __FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ +#if __FUNC_TYPE_HR_ENABLE__ +GU32 g_pun_HR_FrameIncompleteRawdata[GH3X2X_HR_CHNL_NUM]; +GU32 g_un_HR_FrameIncompleteChnlMapBit; +GU8 g_puch_HR_FrameLastGain[GH3X2X_HR_CHNL_NUM]; +GU32 g_un_HR_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_HR; +#endif +#if __FUNC_TYPE_HRV_ENABLE__ +GU32 g_pun_HRV_FrameIncompleteRawdata[GH3X2X_HRV_CHNL_NUM]; +GU32 g_un_HRV_FrameIncompleteChnlMapBit; +GU8 g_puch_HRV_FrameLastGain[GH3X2X_HRV_CHNL_NUM]; +GU32 g_un_HRV_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_HRV; +#endif +#if __FUNC_TYPE_HSM_ENABLE__ +GU32 g_pun_HSM_FrameIncompleteRawdata[GH3X2X_HSM_CHNL_NUM]; +GU32 g_un_HSM_FrameIncompleteChnlMapBit; +GU8 g_puch_HSM_FrameLastGain[GH3X2X_HSM_CHNL_NUM]; +GU32 g_un_HSM_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_HSM; +#endif +#if __FUNC_TYPE_SPO2_ENABLE__ +GU32 g_pun_SPO2_FrameIncompleteRawdata[GH3X2X_SPO2_CHNL_NUM]; +GU32 g_un_SPO2_FrameIncompleteChnlMapBit; +GU8 g_puch_SPO2_FrameLastGain[GH3X2X_SPO2_CHNL_NUM]; +GU32 g_un_SPO2_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_SPO2; +#endif +#if __FUNC_TYPE_ECG_ENABLE__ +GU32 g_pun_ECG_FrameIncompleteRawdata[GH3X2X_ECG_CHNL_NUM]; +GU32 g_un_ECG_FrameIncompleteChnlMapBit; +GU8 g_puch_ECG_FrameLastGain[GH3X2X_ECG_CHNL_NUM]; +GU32 g_un_ECG_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_ECG; +#endif +#if __FUNC_TYPE_PWTT_ENABLE__ +GU32 g_pun_PWTT_FrameIncompleteRawdata[GH3X2X_PWTT_CHNL_NUM]; +GU32 g_un_PWTT_FrameIncompleteChnlMapBit; +GU8 g_puch_PWTT_FrameLastGain[GH3X2X_PWTT_CHNL_NUM]; +GU32 g_un_PWTT_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_PWTT; +#endif +#if __FUNC_TYPE_BT_ENABLE__ +GU32 g_pun_BT_FrameIncompleteRawdata[GH3X2X_BT_CHNL_NUM]; +GU32 g_un_BT_FrameIncompleteChnlMapBit; +GU8 g_puch_BT_FrameLastGain[GH3X2X_BT_CHNL_NUM]; +GU32 g_un_BT_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_BT; +#endif +#if __FUNC_TYPE_RESP_ENABLE__ +GU32 g_pun_RESP_FrameIncompleteRawdata[GH3X2X_RESP_CHNL_NUM]; +GU32 g_un_RESP_FrameIncompleteChnlMapBit; +GU8 g_puch_RESP_FrameLastGain[GH3X2X_RESP_CHNL_NUM]; +GU32 g_un_RESP_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_RESP; +#endif +#if __FUNC_TYPE_AF_ENABLE__ +GU32 g_pun_AF_FrameIncompleteRawdata[GH3X2X_AF_CHNL_NUM]; +GU32 g_un_AF_FrameIncompleteChnlMapBit; +GU8 g_puch_AF_FrameLastGain[GH3X2X_AF_CHNL_NUM]; +GU32 g_un_AF_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_AF; +#endif +#if __FUNC_TYPE_BP_ENABLE__ +GU32 g_pun_BP_FrameIncompleteRawdata[GH3X2X_BP_CHNL_NUM]; +GU32 g_un_BP_FrameIncompleteChnlMapBit; +GU8 g_puch_BP_FrameLastGain[GH3X2X_BP_CHNL_NUM]; +GU32 g_un_BP_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_BP; +#endif +#if __FUNC_TYPE_TEST_ENABLE__ +GU32 g_pun_TEST1_FrameIncompleteRawdata[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST1_FrameIncompleteChnlMapBit; +GU8 g_puch_TEST1_FrameLastGain[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST1_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_TEST1; +GU32 g_pun_TEST2_FrameIncompleteRawdata[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST2_FrameIncompleteChnlMapBit; +GU8 g_puch_TEST2_FrameLastGain[GH3X2X_TEST_CHNL_NUM]; +GU32 g_un_TEST2_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_TEST2; +#endif +#else +GU32 g_pun_MAIN_FUNC_FrameIncompleteRawdata[GH3X2X_MAIN_FUNC_CHNL_NUM]; +GU32 g_un_MAIN_FUNC_FrameIncompleteChnlMapBit; +GU8 g_puch_MAIN_FUNC_FrameLastGain[GH3X2X_MAIN_FUNC_CHNL_NUM]; +GU32 g_un_MAIN_FUNC_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_MAIN_FUNC; +#endif +#if __SUPPORT_HARD_ADT_CONFIG__ +GU32 g_pun_ADT_FrameIncompleteRawdata[GH3X2X_ADT_CHNL_NUM]; +GU32 g_un_ADT_FrameIncompleteChnlMapBit; +GU8 g_puch_ADT_FrameLastGain[GH3X2X_ADT_CHNL_NUM]; +GU32 g_un_ADT_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_ADT; +#endif +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ +GU32 g_pun_SOFT_ADT_GREEN_FrameIncompleteRawdata[GH3X2X_SOFT_ADT_CHNL_NUM]; +GU32 g_un_SOFT_ADT_GREEN_FrameIncompleteChnlMapBit; +GU8 g_puch_SOFT_ADT_GREEN_FrameLastGain[GH3X2X_SOFT_ADT_CHNL_NUM]; +GU32 g_un_SOFT_ADT_GREEN_TimeStamp; +STGh3x2xDownSampleInfo g_stGh3x2xDownSampleInfo_SOFT_ADT_GREEN; +#endif + + + + +#if __FUNC_TYPE_HR_ENABLE__ +GU8 g_pch_HR_ChnlMap[GH3X2X_HR_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_HR_FuncitonInfo; +STGh3x2xAlgoResult g_st_HR_AlgoRecordResult; +#endif +#if __FUNC_TYPE_HRV_ENABLE__ +GU8 g_pch_HRV_ChnlMap[GH3X2X_HRV_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_HRV_FuncitonInfo; +STGh3x2xAlgoResult g_st_HRV_AlgoRecordResult; +#endif +#if __FUNC_TYPE_HSM_ENABLE__ +GU8 g_pch_HSM_ChnlMap[GH3X2X_HSM_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_HSM_FuncitonInfo; +#endif +#if __FUNC_TYPE_SPO2_ENABLE__ +GU8 g_pch_SPO2_ChnlMap[GH3X2X_SPO2_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_SPO2_FuncitonInfo; +STGh3x2xAlgoResult g_st_SPO2_AlgoRecordResult; +#endif +#if __FUNC_TYPE_ECG_ENABLE__ +GU8 g_pch_ECG_ChnlMap[GH3X2X_ECG_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_ECG_FuncitonInfo; +#endif +#if __FUNC_TYPE_PWTT_ENABLE__ +GU8 g_pch_PWTT_ChnlMap[GH3X2X_PWTT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_PWTT_FuncitonInfo; +#endif +#if __FUNC_TYPE_BT_ENABLE__ +GU8 g_pch_BT_ChnlMap[GH3X2X_BT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_BT_FuncitonInfo; +#endif +#if __FUNC_TYPE_RESP_ENABLE__ +GU8 g_pch_RESP_ChnlMap[GH3X2X_RESP_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_RESP_FuncitonInfo; +#endif +#if __FUNC_TYPE_AF_ENABLE__ +GU8 g_pch_AF_ChnlMap[GH3X2X_AF_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_AF_FuncitonInfo; +#endif +#if __SUPPORT_HARD_ADT_CONFIG__ +GU8 g_pch_ADT_ChnlMap[GH3X2X_ADT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_ADT_FuncitonInfo; +#endif +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ +GU8 g_pch_SOFT_ADT_GREEN_ChnlMap[GH3X2X_SOFT_ADT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_SOFT_ADT_GREEN_FuncitonInfo; +#endif +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ +GU8 g_pch_SOFT_ADT_IR_ChnlMap[GH3X2X_SOFT_ADT_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_SOFT_ADT_IR_FuncitonInfo; +#endif +#if __FUNC_TYPE_BP_ENABLE__ +GU8 g_pch_BP_ChnlMap[GH3X2X_BP_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_BP_FuncitonInfo; +#endif +#if __FUNC_TYPE_TEST_ENABLE__ +GU8 g_pch_TEST1_ChnlMap[GH3X2X_TEST_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_TEST1_FuncitonInfo; +GU8 g_pch_TEST2_ChnlMap[GH3X2X_TEST_CHNL_NUM]; +STGh3x2xFunctionInfo g_st_TEST2_FuncitonInfo; +#endif + +GU32 g_punGh3x2xFrameRawdata[GH3X2X_FUNC_CHNL_NUM_MAX]; +#if __GS_GYRO_ENABLE__ +GS16 g_psGh3x2xFrameGsensorData[6]; +#else +GS16 g_psGh3x2xFrameGsensorData[3]; +#endif +GU32 g_punGh3x2xFrameAgcInfo[GH3X2X_FUNC_CHNL_NUM_MAX]; +GU32 g_punGh3x2xFrameFlag[8]; +STGh3x2xAlgoResult g_stGh3x2xAlgoResult; + +STCapRawdata g_pstGh3x2xFrameCapData; +STTempRawdata g_pstGh3x2xFrameTempData; + + + +//HR data info +#if __FUNC_TYPE_HR_ENABLE__ +const STGh3x2xFrameInfo g_stHR_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_HR, + .pstFunctionInfo = &g_st_HR_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_HR_CHNL_NUM, + .pchChnlMap = g_pch_HR_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = &g_st_HR_AlgoRecordResult, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_HR_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_HR_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_HR_FrameLastGain, + .punFrameCnt = &g_un_HR_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_HR, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xHR_FrameInfo = &g_stHR_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xHR_FrameInfo = 0; +#endif +//HRV data info +#if __FUNC_TYPE_HRV_ENABLE__ +const STGh3x2xFrameInfo g_stHRV_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_HRV, + .pstFunctionInfo = &g_st_HRV_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_HRV_CHNL_NUM, + .pchChnlMap = g_pch_HRV_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = &g_st_HRV_AlgoRecordResult, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_HRV_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_HRV_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_HRV_FrameLastGain, + .punFrameCnt = &g_un_HRV_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_HRV, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xHRV_FrameInfo = &g_stHRV_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xHRV_FrameInfo = 0; +#endif +//HSM data info +#if __FUNC_TYPE_HSM_ENABLE__ +const STGh3x2xFrameInfo g_stHSM_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_HSM, + .pstFunctionInfo = &g_st_HSM_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_HSM_CHNL_NUM, + .pchChnlMap = g_pch_HSM_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_HSM_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_HSM_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_HSM_FrameLastGain, + .punFrameCnt = &g_un_HSM_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_HSM, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xHSM_FrameInfo = &g_stHSM_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xHSM_FrameInfo = 0; +#endif +//SPO2 data info +#if __FUNC_TYPE_SPO2_ENABLE__ +const STGh3x2xFrameInfo g_stSPO2_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_SPO2, + .pstFunctionInfo = &g_st_SPO2_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_SPO2_CHNL_NUM, + .pchChnlMap = g_pch_SPO2_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = &g_st_SPO2_AlgoRecordResult, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_SPO2_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_SPO2_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_SPO2_FrameLastGain, + .punFrameCnt = &g_un_SPO2_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_SPO2, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xSPO2_FrameInfo = &g_stSPO2_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xSPO2_FrameInfo = 0; +#endif +//ECG data info +#if __FUNC_TYPE_ECG_ENABLE__ +const STGh3x2xFrameInfo g_stECG_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_ECG, + .pstFunctionInfo = &g_st_ECG_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_ECG_CHNL_NUM, + .pchChnlMap = g_pch_ECG_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_ECG_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_ECG_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_ECG_FrameLastGain, + .punFrameCnt = &g_un_ECG_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_ECG, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = &g_stECG_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = 0; +#endif +#if __FUNC_TYPE_PWTT_ENABLE__ +const STGh3x2xFrameInfo g_stPWTT_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_PWTT, + .pstFunctionInfo = &g_st_PWTT_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_PWTT_CHNL_NUM, + .pchChnlMap = g_pch_PWTT_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_PWTT_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_PWTT_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_PWTT_FrameLastGain, + .punFrameCnt = &g_un_PWTT_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_PWTT, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = &g_stECG_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xECG_FrameInfo = 0; +#endif +//BT data info +#if __FUNC_TYPE_BT_ENABLE__ +const STGh3x2xFrameInfo g_stBT_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_BT, + .pstFunctionInfo = &g_st_BT_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_BT_CHNL_NUM, + .pchChnlMap = g_pch_BT_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_BT_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_BT_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_BT_FrameLastGain, + .punFrameCnt = &g_un_BT_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_BT, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xBT_FrameInfo = &g_stBT_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xBT_FrameInfo = 0; +#endif +//RESP data info +#if __FUNC_TYPE_RESP_ENABLE__ +const STGh3x2xFrameInfo g_stRESP_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_RESP, + .pstFunctionInfo = &g_st_RESP_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_RESP_CHNL_NUM, + .pchChnlMap = g_pch_RESP_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_RESP_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_RESP_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_RESP_FrameLastGain, + .punFrameCnt = &g_un_RESP_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_RESP, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xRESP_FrameInfo = &g_stRESP_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xRESP_FrameInfo = 0; +#endif +//AF data info +#if __FUNC_TYPE_AF_ENABLE__ +const STGh3x2xFrameInfo g_stAF_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_AF, + .pstFunctionInfo = &g_st_AF_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_AF_CHNL_NUM, + .pchChnlMap = g_pch_AF_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_AF_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_AF_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_AF_FrameLastGain, + .punFrameCnt = &g_un_AF_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_AF, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xAF_FrameInfo = &g_stAF_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xAF_FrameInfo = 0; +#endif +#if __FUNC_TYPE_BP_ENABLE__ +const STGh3x2xFrameInfo g_stFPBP_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_FPBP, + .pstFunctionInfo = &g_st_BP_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_BP_CHNL_NUM, + .pchChnlMap = g_pch_BP_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_BP_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_BP_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_BP_FrameLastGain, + .punFrameCnt = &g_un_BP_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_BP, +#endif +}; +const STGh3x2xFrameInfo g_stPWA_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_PWA, + .pstFunctionInfo = &g_st_BP_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_PWA_CHNL_NUM, + .pchChnlMap = g_pch_BP_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_BP_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_BP_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_BP_FrameLastGain, + .punFrameCnt = &g_un_BP_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_BP, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xFPBP_FrameInfo = &g_stFPBP_FrameInfo; +//const STGh3x2xFrameInfo * const g_pstGh3x2xPWA_FrameInfo = &g_stPWA_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xFPBP_FrameInfo = 0; +//const STGh3x2xFrameInfo * const g_pstGh3x2xPWA_FrameInfo = 0; +#endif +#if __FUNC_TYPE_TEST_ENABLE__ +const STGh3x2xFrameInfo g_stTEST1_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_TEST1, + .pstFunctionInfo = &g_st_TEST1_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_TEST_CHNL_NUM, + .pchChnlMap = g_pch_TEST1_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_TEST1_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_TEST1_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_TEST1_FrameLastGain, + .punFrameCnt = &g_un_TEST1_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_TEST1, +#endif +}; +const STGh3x2xFrameInfo g_stTEST2_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_TEST2, + .pstFunctionInfo = &g_st_TEST2_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_TEST_CHNL_NUM, + .pchChnlMap = g_pch_TEST2_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .pstAlgoRecordResult = 0, +#if !__FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ + .punIncompleteRawdata = g_pun_MAIN_FUNC_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_MAIN_FUNC_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_MAIN_FUNC_FrameLastGain, + .punFrameCnt = &g_un_MAIN_FUNC_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_MAIN_FUNC, +#else + .punIncompleteRawdata = g_pun_TEST2_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_TEST2_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_TEST2_FrameLastGain, + .punFrameCnt = &g_un_TEST2_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_TEST2, +#endif +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST1_FrameInfo = &g_stTEST1_FrameInfo; +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST2_FrameInfo = &g_stTEST2_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST1_FrameInfo = 0; +//const STGh3x2xFrameInfo * const g_pstGh3x2xTEST2_FrameInfo = 0; +#endif +//ADT data info +#if __SUPPORT_HARD_ADT_CONFIG__ +const STGh3x2xFrameInfo g_stADT_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_ADT, + .pstFunctionInfo = &g_st_ADT_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_ADT_CHNL_NUM, + .pchChnlMap = g_pch_ADT_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .punIncompleteRawdata = g_pun_ADT_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_ADT_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_ADT_FrameLastGain, + .punFrameCnt = &g_un_ADT_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_ADT, + .pstAlgoRecordResult = 0, +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xADT_FrameInfo = &g_stADT_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xADT_FrameInfo = 0; +#endif +//SOFT ADT data info +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ +const STGh3x2xFrameInfo g_stSOFT_ADT_GREEN_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_SOFT_ADT_GREEN, + .pstFunctionInfo = &g_st_SOFT_ADT_GREEN_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_SOFT_ADT_CHNL_NUM, + .pchChnlMap = g_pch_SOFT_ADT_GREEN_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .punIncompleteRawdata = g_pun_SOFT_ADT_GREEN_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_SOFT_ADT_GREEN_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_SOFT_ADT_GREEN_FrameLastGain, + .punFrameCnt = &g_un_SOFT_ADT_GREEN_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_SOFT_ADT_GREEN, + .pstAlgoRecordResult = 0, +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_GREEN_FrameInfo = &g_stSOFT_ADT_GREEN_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_GREEN_FrameInfo = 0; +#endif +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ +const STGh3x2xFrameInfo g_stSOFT_ADT_IR_FrameInfo = +{ + .unFunctionID = GH3X2X_FUNCTION_SOFT_ADT_IR, + .pstFunctionInfo = &g_st_SOFT_ADT_IR_FuncitonInfo, + .pstAlgoResult = &g_stGh3x2xAlgoResult, + .uchFuntionChnlLimit = GH3X2X_SOFT_ADT_CHNL_NUM, + .pchChnlMap = g_pch_SOFT_ADT_IR_ChnlMap, + .punFrameRawdata = g_punGh3x2xFrameRawdata, + .pusFrameGsensordata = g_psGh3x2xFrameGsensorData, + .pstFrameCapdata = &g_pstGh3x2xFrameCapData, + .pstFrameTempdata = &g_pstGh3x2xFrameTempData, + .punFrameAgcInfo = g_punGh3x2xFrameAgcInfo, + .punFrameFlag = g_punGh3x2xFrameFlag, + .punIncompleteRawdata = g_pun_SOFT_ADT_GREEN_FrameIncompleteRawdata, + .punIncompleteChnlMapBit = &g_un_SOFT_ADT_GREEN_FrameIncompleteChnlMapBit, + .puchFrameLastGain = g_puch_SOFT_ADT_GREEN_FrameLastGain, + .punFrameCnt = &g_un_SOFT_ADT_GREEN_TimeStamp, + .pstDownSampleInfo = &g_stGh3x2xDownSampleInfo_SOFT_ADT_GREEN, + .pstAlgoRecordResult = 0, +}; +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_IR_FrameInfo = &g_stSOFT_ADT_IR_FrameInfo; +#else +//const STGh3x2xFrameInfo * const g_pstGh3x2xSOFT_ADT_IR_FrameInfo = 0; +#endif + + +//Function data info struct +const STGh3x2xFrameInfo * const g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_MAX] = +{ +//adt +#if __SUPPORT_HARD_ADT_CONFIG__ + &g_stADT_FrameInfo, +#else + 0, +#endif +//hr +#if __FUNC_TYPE_HR_ENABLE__ + &g_stHR_FrameInfo, +#else + 0, +#endif +//hrv +#if __FUNC_TYPE_HRV_ENABLE__ + &g_stHRV_FrameInfo, +#else + 0, +#endif +//hsm +#if __FUNC_TYPE_HSM_ENABLE__ + &g_stHSM_FrameInfo, +#else + 0, +#endif +//fpbp +//pwa +#if __FUNC_TYPE_BP_ENABLE__ + &g_stFPBP_FrameInfo, + &g_stPWA_FrameInfo, +#else + 0, + 0, +#endif +//spo2 +#if __FUNC_TYPE_SPO2_ENABLE__ + &g_stSPO2_FrameInfo, +#else + 0, +#endif +//ecg +#if __FUNC_TYPE_ECG_ENABLE__ + &g_stECG_FrameInfo, +#else + 0, +#endif +//pwtt +#if __FUNC_TYPE_PWTT_ENABLE__ + &g_stPWTT_FrameInfo, +#else + 0, +#endif +//soft adt green +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ + &g_stSOFT_ADT_GREEN_FrameInfo, +#else + 0, +#endif +//bt +#if __FUNC_TYPE_BT_ENABLE__ + &g_stBT_FrameInfo, +#else + 0, +#endif +//resp +#if __FUNC_TYPE_RESP_ENABLE__ + &g_stRESP_FrameInfo, +#else + 0, +#endif +//af +#if __FUNC_TYPE_AF_ENABLE__ + &g_stAF_FrameInfo, +#else + 0, +#endif +#if __FUNC_TYPE_TEST_ENABLE__ + &g_stTEST1_FrameInfo, + &g_stTEST2_FrameInfo, +#else + 0, + 0, +#endif +//soft adt ir +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ + &g_stSOFT_ADT_IR_FrameInfo, +#else + 0, +#endif + 0, //GH3X2X_FUNCTION_RS0 + 0, //GH3X2X_FUNCTION_RS1 + 0, //GH3X2X_FUNCTION_RS2 + 0, //GH3X2X_FUNCTION_LEAD_DET +}; + +/// read data buffer + +#if __USER_DYNAMIC_DRV_BUF_EN__ +static GU8 *g_puchGh3x2xReadRawdataBuffer = 0; +#if __GH3X2X_CASCADE_EN__ +static GU8 *g_puchGh3x2xReadRawdataBufferSlaveChip = 0; +#endif +#else +#if __GH3X2X_CASCADE_EN__ +static GU8 g_puchGh3x2xReadRawdataBuffer[2 * __GH3X2X_RAWDATA_BUFFER_SIZE__]; +static GU8 g_puchGh3x2xReadRawdataBufferSlaveChip[__GH3X2X_RAWDATA_SLAVE_BUFFER_SIZE__]; +#else +static GU8 g_puchGh3x2xReadRawdataBuffer[__GH3X2X_RAWDATA_BUFFER_SIZE__]; +#endif +#endif + +/// read data buffer len +GU16 g_usGh3x2xReadRawdataLen = 0; + + +extern void Gh3x2xDemoStopSamplingInner(GU32 unFuncMode); +extern void Gh3x2xDemoStartSamplingInner(GU32 unFuncMode, GU8 uchSwitchEnable); + + +/// driver lib demo init flag +static GU8 g_uchGh3x2xInitFlag = 0; + + +static GU8 g_uchGh3x2xInterruptProNotFinishFlag = 0; + +#if (__NORMAL_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__ || __MIX_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__) +//hal_gh3x2x_int_handler_call_back is called, this value is 1 +GU8 g_uchGh3x2xIntCallBackIsCalled = 0; +#endif + +#if (__SUPPORT_ENGINEERING_MODE__) +GU8 g_uchEngineeringModeStatus = 0; // 0: is not in engineering mode 1: is in engineering mode +STGh3x2xEngineeringModeSampleParam *g_pstSampleParaGroup = 0; +GU8 g_uchEngineeringModeSampleParaGroupNum = 0; +#endif + +/// current gh3x2x reg config array index +GU8 g_uchGh3x2xRegCfgArrIndex = DRV_LIB_REG_CFG_EMPTY; + +/// int mode +GU8 g_uchGh3x2xIntMode = __INTERRUPT_PROCESS_MODE__; + + +#if __FUNC_TYPE_ECG_ENABLE__ +#if __GH3X2X_CASCADE_EN__ +STGh3x2xSoftLeadOffDetInfo g_pstGh3x2xSoftLeadOffDetInfoEntity[2]; +STGh3x2xRsInfo g_pstGh3x2xEcgRsInfoEntity[2]; +const GU8 g_uchGh3x2xEcgChnlNumLimit = 2; +#else +STGh3x2xSoftLeadOffDetInfo g_pstGh3x2xSoftLeadOffDetInfoEntity[1]; +STGh3x2xRsInfo g_pstGh3x2xEcgRsInfoEntity[1]; +const GU8 g_uchGh3x2xEcgChnlNumLimit = 1; +#endif +STGh3x2xSoftLeadOffDetInfo * const g_pstGh3x2xSoftLeadOffDetInfo = g_pstGh3x2xSoftLeadOffDetInfoEntity; +STGh3x2xRsInfo * const g_pstGh3x2xEcgRsInfo = g_pstGh3x2xEcgRsInfoEntity; +#else +STGh3x2xSoftLeadOffDetInfo * const g_pstGh3x2xSoftLeadOffDetInfo = 0; +STGh3x2xRsInfo * const g_pstGh3x2xEcgRsInfo = 0; +const GU8 g_uchGh3x2xEcgChnlNumLimit = 0; +#endif + +#if (__FUNC_TYPE_HR_ENABLE__&& __SUPPORT_PPG_DOWNSAMP__) +const GU32 g_uchPPGDownSampleChnlNumLimit = GH3X2X_PPG_DOWNSAMP_CHNL_NUM; +STGh3x2xRsInfo g_pstGh3x2xPPGRsInfoEntity[GH3X2X_PPG_DOWNSAMP_CHNL_NUM]; +STGh3x2xRsInfo * const g_pstGh3x2xPPGRsInfo = g_pstGh3x2xPPGRsInfoEntity; +#else +const GU32 g_uchPPGDownSampleChnlNumLimit = 0; +STGh3x2xRsInfo * const g_pstGh3x2xPPGRsInfo = 0; +#endif + +#if (GH3X2X_FIFO_MONITOR_EN&(__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__)) +STGh3x2xFifoMonitorInfo g_stFifoMonitorInfo; +#endif + +void Gh3x2xGetConfigVersion(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam) +{ + GU32 unCfgTimeStamp = 0; + + if (pstGh3x2xInitConfigParam->usConfigArrLen <= 1) + { + return; + } + else + { + for (GU16 usCnt = 0 ; usCnt < pstGh3x2xInitConfigParam->usConfigArrLen ; usCnt ++) + { + switch(pstGh3x2xInitConfigParam->pstRegConfigArr[usCnt].usRegAddr) + { + case 0x1006: + unCfgTimeStamp |= pstGh3x2xInitConfigParam->pstRegConfigArr[usCnt].usRegData; + break; + case 0x1008: + unCfgTimeStamp |= (pstGh3x2xInitConfigParam->pstRegConfigArr[usCnt].usRegData << 16); + break; + } + } + } + if (unCfgTimeStamp != 0) + { + GH3X2X_INFO_LOG("%s : Config Version : %x\n", __FUNCTION__, (unsigned int)unCfgTimeStamp); + } + else + { + GH3X2X_INFO_LOG("%s : No Config Version !!!\n", __FUNCTION__); + } +} + +#if __GS_NONSYNC_READ_EN__ +GU8 g_uchGh3x2xGsenosrExtralBufLen = __GS_EXTRA_BUF_LEN__; +GS16 g_sGh3x2xGsenorCurrentRemainPointNum; +GU16 g_usGsenorRefFunction = 0; +float g_fGh3x2xNonSyncGsensorStep; + + +void Gh3x2xNonSyncGsensorInit(void) +{ + g_sGh3x2xGsenorCurrentRemainPointNum = 0; + GH3X2X_INFO_LOG("[Non-Sync Gsensor]non-sync gsensor init.\r\n"); +} + +GU16 Gh3x2xGetCurrentRefFunction(void) +{ + GU16 usSampleRateMax = 0; + GU16 usRefFucntion = 0; + //find max sample rate function in opened function + for(GU8 uchFunCnt = 0; uchFunCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunCnt ++) + { + if(g_pstGh3x2xFrameInfo[uchFunCnt]) + { + if(g_unDemoFuncMode & (((GU32)1)<< uchFunCnt)) + { + if(usSampleRateMax < g_pstGh3x2xFrameInfo[uchFunCnt]->pstFunctionInfo->usSampleRate) + { + usSampleRateMax = g_pstGh3x2xFrameInfo[uchFunCnt]->pstFunctionInfo->usSampleRate; + usRefFucntion = g_pstGh3x2xFrameInfo[uchFunCnt]->unFunctionID; + } + } + } + } + + GH3X2X_INFO_LOG("[Non-Sync Gsensor]usRefFucntion = 0x%X.\r\n",usRefFucntion); + //calculate step + if(usSampleRateMax) + { + g_fGh3x2xNonSyncGsensorStep = __GS_SAMPLE_RATE_HZ__ / usSampleRateMax; + } + else + { + g_fGh3x2xNonSyncGsensorStep = 0; + GH3X2X_INFO_LOG("[Non-Sync Gsensor]Error !!! usSampleRateMax = 0.\r\n"); + } + GH3X2X_INFO_LOG("[Non-Sync Gsensor]g_fGh3x2xNonSyncGsensorStep = %.3f.\r\n",g_fGh3x2xNonSyncGsensorStep); + + GH3X2X_INFO_LOG("[Non-Sync Gsensor]usRefFucntion = 0x%d,usSampleRateMax = %d.\r\n",usRefFucntion,usSampleRateMax); + return usRefFucntion; +} + +GU16 Gh3x2xGetGsensorNeedPointNum(GU16 usCurrentGsenosrPoint,GU8* puchReadFifoBuffer, GU16 usFifoBuffLen) +{ + GU8 uchFunctionOfst = 0xFF; + GU16 usFrameNum = 0; + GU16 usTempGsensorPointNum = 0; + GU16 usTempGsensorPointNumFloat = 0; + static GU16 usTempGsensorPointNumFractPart = 0; + + for(GU8 uchFunCnt = 0; uchFunCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunCnt ++) + { + if (g_usGsenorRefFunction == (((GU32)1)<< uchFunCnt)) + { + uchFunctionOfst = uchFunCnt; + break; + } + } + if(0xFF == uchFunctionOfst) + { + return 0; + } + + //get ref function frame num in this fifo data + if(g_pstGh3x2xFrameInfo[uchFunctionOfst]) + { + usFrameNum = GH3x2xGetFrameNum(puchReadFifoBuffer,usFifoBuffLen,g_pstGh3x2xFrameInfo[uchFunctionOfst]); + } + + + + usTempGsensorPointNumFloat = (float)usFrameNum * g_fGh3x2xNonSyncGsensorStep; + usTempGsensorPointNum = (GU16)(usTempGsensorPointNumFloat + usTempGsensorPointNumFractPart); + usTempGsensorPointNumFractPart = usTempGsensorPointNumFloat - (GU16)usTempGsensorPointNumFloat; + + if(usTempGsensorPointNum > (__GS_EXTRA_BUF_LEN__ + usCurrentGsenosrPoint)) + { + usTempGsensorPointNum = __GS_EXTRA_BUF_LEN__ + usCurrentGsenosrPoint; + } + + + GH3X2X_INFO_LOG("[Non-Sync Gsensor]GsensorNeedPointNum = %d.\r\n",usTempGsensorPointNum); + + return usTempGsensorPointNum; +} + +GS16 Gh3x2xGetGsensorHeadPos(GU16 usCurrentGsenosrPoint,GU16 usNeedPoinNum) +{ + GS16 sPos1; + GS16 sPos2; + GH3X2X_INFO_LOG("[Non-Sync Gsensor]usCurrentGsenosrPoint = %d.\r\n",usCurrentGsenosrPoint); + sPos1 = (GS16)usCurrentGsenosrPoint - (GS16)usNeedPoinNum; + sPos2= (GS16)0 - g_sGh3x2xGsenorCurrentRemainPointNum; + + if(sPos1 < sPos2) + { + GS16 sOldestPosi; + GU8 uchExistOldData = 1; + GS16 sDesPosi = sPos1; + if(g_sGh3x2xGsenorCurrentRemainPointNum) //exist remain data + { + sOldestPosi = (GS16)0 - (GS16)g_sGh3x2xGsenorCurrentRemainPointNum; + } + else if(usCurrentGsenosrPoint) //use new gsensor data + { + sOldestPosi = 0; + } + else + { + uchExistOldData = 0; + } + GH3X2X_INFO_LOG("[Non-Sync Gsensor]Gsensor data is not enough,add oldest point num = %d, uchExistOldData = %d.****\r\n",sPos2 - sPos1,uchExistOldData); + GH3X2X_INFO_LOG("[Non-Sync Gsensor]GsensorHeadPos = %d.\r\n",sPos1); + if(uchExistOldData) + { + for(sDesPosi = sPos1; sDesPosi < sOldestPosi; sDesPosi++) //copy oldest point value + { + GH3X2X_Memcpy((GU8*)(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__ + sDesPosi),(GU8*)(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__ + sOldestPosi),sizeof(STGsensorRawdata)); + } + } + else //copy 0 + { + GH3X2X_Memset((GU8*)gsensor_soft_fifo_buffer+ __GS_EXTRA_BUF_LEN__ + sDesPosi,0, usNeedPoinNum * sizeof(STGsensorRawdata)); + } + + return sPos1; + } + GH3X2X_INFO_LOG("[Non-Sync Gsensor]GsensorHeadPos = %d.\r\n",sPos2); + return sPos2; +} + +void Gh3x2xNonSyncGsenosrPostProcess(GU16 usCurrentGsenosrPoint,GU16 usNeedPoinNum ,GS16 sHeadPos) +{ + GS16 sRemainPointSrcStartPosi; + GS16 sRemainPointDesStartPosi; + GU16 usRemainPoinNum; + sRemainPointSrcStartPosi = (GS16)usNeedPoinNum + sHeadPos; + usRemainPoinNum = usCurrentGsenosrPoint - sRemainPointSrcStartPosi; + GH3X2X_INFO_LOG("[Non-Sync Gsensor]raw usRemainPoinNum = %d.\r\n",usRemainPoinNum); + if(usRemainPoinNum > __GS_EXTRA_BUF_LEN__) + { + + GH3X2X_INFO_LOG("[Non-Sync Gsensor]******Gsensor data is too much, give up oldest point num = %d.****************\r\n",(usRemainPoinNum - __GS_EXTRA_BUF_LEN__)); + sRemainPointSrcStartPosi += (usRemainPoinNum - __GS_EXTRA_BUF_LEN__); //give up oldest data + usRemainPoinNum = __GS_EXTRA_BUF_LEN__; + } + sRemainPointDesStartPosi = ((GS16)0) - usRemainPoinNum; + //copy remain data to extral buf + if(usRemainPoinNum) + { + GH3X2X_Memcpy((GU8*)(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__ + sRemainPointDesStartPosi),(GU8*)(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__ + sRemainPointSrcStartPosi),usRemainPoinNum*sizeof(STGsensorRawdata)); + } + //update g_sGh3x2xGsenorCurrentRemainPointNum + g_sGh3x2xGsenorCurrentRemainPointNum = usRemainPoinNum; + GH3X2X_INFO_LOG("[Non-Sync Gsensor]GsenosrPostProcess: RemainPointNum= %d.\r\n",g_sGh3x2xGsenorCurrentRemainPointNum); +} +#endif + +void Gh3x2xDemoHardConfigReset(const STGh3x2xInitConfig *pstGh3x2xInitConfigParam) +{ + GH3X2X_INFO_LOG("[%s]:g_uchGh3x2xRegCfgArrIndex = %d\n", __FUNCTION__, g_uchGh3x2xRegCfgArrIndex); + for (GU16 usArrCnt = 0; usArrCnt < (pstGh3x2xInitConfigParam)->usConfigArrLen ; usArrCnt ++) + { + if (((pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegAddr & 0xF000) == 0) + { + for (int uchSlotIndex = 0; uchSlotIndex < 8; uchSlotIndex++) + { + if (((pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegAddr) ==\ + 0x011E + (uchSlotIndex * 0x001C) + (0 * 0x0002)|| + ((pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegAddr) ==\ + 0x011E + (uchSlotIndex * 0x001C) + (1 * 0x0002) || + ((pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegAddr) ==\ + 0x0112 + (uchSlotIndex * 0x001C)) + { + GH3X2X_INFO_LOG("[%s]:addr-value = 0x%04x-0x%04x\n", __FUNCTION__, (pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegAddr, (pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegData); + GH3X2X_WriteReg((pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegAddr,\ + (pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegData); + if ((pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegData != \ + GH3X2X_ReadReg((pstGh3x2xInitConfigParam)->pstRegConfigArr[usArrCnt].usRegAddr)) + { + GH3X2X_INFO_LOG("[%s]:reg verify error!!!\r\n", __FUNCTION__); + } + } + } + } + } + GH3X2X_EnterLowPowerMode(); +} + +#if (__SUPPORT_HARD_ADT_CONFIG__) +/** + * @fn void Gh3x2xDemoWearEventProcess(u16* usEvent,EMWearDetectForceSwitch emForceSwitch) + * + * @brief Process wear on/off event + * + * @attention None + * + * @param[in] usEvent gh3x2x irq status + * @param[in] emForceSwitch switch wear detect status by force or not + * @param[out] None + * + * @return None + */ +#if (0 == __HARD_ADT_ALGO_CHECK_EN__) +void Gh3x2xDemoWearEventProcess(GU16* usEvent,EMWearDetectForceSwitch emForceSwitch) +{ + if ((g_unDemoFuncMode & GH3X2X_FUNCTION_ADT) == GH3X2X_FUNCTION_ADT) + { + if((0 != (*usEvent & GH3X2X_IRQ_MSK_WEAR_ON_BIT)) || (0 != (*usEvent & GH3X2X_IRQ_MSK_WEAR_OFF_BIT))) + { + if(0 != (*usEvent & GH3X2X_IRQ_MSK_WEAR_ON_BIT)) + { + g_uchWearDetectStatus = WEAR_DETECT_WEAR_OFF; + if(GH3X2X_RET_OK != GH3X2X_WearDetectSwitchTo(WEAR_DETECT_WEAR_OFF,emForceSwitch)) + { + *usEvent &= ~GH3X2X_IRQ_MSK_WEAR_ON_BIT; + } + else + { + GH3X2X_INFO_LOG("[%s]:switch to wear off\r\n", __FUNCTION__); + } + } + else + { + g_uchWearDetectStatus = WEAR_DETECT_WEAR_ON; + if(GH3X2X_RET_OK != GH3X2X_WearDetectSwitchTo(WEAR_DETECT_WEAR_ON,emForceSwitch)) + { + *usEvent &= ~GH3X2X_IRQ_MSK_WEAR_OFF_BIT; + } + else + { + GH3X2X_INFO_LOG("[%s]:switch to wear on\r\n", __FUNCTION__); + } + + } + } + } + else + { + *usEvent &= ~(GH3X2X_IRQ_MSK_WEAR_OFF_BIT|GH3X2X_IRQ_MSK_WEAR_ON_BIT); + } +} +#endif +#endif + +GCHAR* GH3X2X_GetFirmwareVersion(void) +{ +#ifdef GOODIX_DEMO_PLATFORM + return GetEvkVersion(); +#else + return GH3X2X_DEMO_VERSION_STRING; +#endif +} + +GCHAR* GH3X2X_GetDemoVersion(void) +{ + return GH3X2X_DEMO_VERSION_STRING; +} + +#if (__SUPPORT_PROTOCOL_ANALYZE__) +GCHAR* GH3X2X_GetEvkBootloaderVersion(void) +{ +#ifdef GOODIX_DEMO_PLATFORM + return GetBootloaderVersion(); +#else + return GH3X2X_DEMO_VERSION_STRING; +#endif +} +#endif + +/** + * @fn void Gh3x2x_NormalizeGsensorSensitivity(STGsensorRawdata gsensor_buffer[], GU16 gsensor_point_num) + * + * @brief normalize gsensor sensitivity to 512LSB/g + * + * @attention None + * + * @param[in] gsensor_buffer gsensor rawdata buffer + * @param[in] gsensor_point_num gsensor rawdata point num + * @param[out] None + * + * @return None + */ +void Gh3x2x_NormalizeGsensorSensitivity(STGsensorRawdata gsensor_buffer[], GU16 gsensor_point_num) +{ + GU8 uchRightShift; + uchRightShift = __GS_SENSITIVITY_CONFIG__; + for(GU16 uchCnt = 0; uchCnt < gsensor_point_num; uchCnt++) + { + gsensor_buffer[uchCnt].sXAxisVal >>= uchRightShift; + gsensor_buffer[uchCnt].sYAxisVal >>= uchRightShift; + gsensor_buffer[uchCnt].sZAxisVal >>= uchRightShift; + } +} + + +void Gh3x2xFunctionCtrlModuleInit(void) +{ + g_unDemoFuncMode = 0; +} +/** + * @fn void Gh3x2xDemoFunctionSampleRateSet(GU32 unFunctionID, GU16 usSampleRate) + * + * @brief + * + * @attention None + * + * @param[in] unFunctionID such as: GH3X2X_FUNCTION_HR or GH3X2X_FUNCTION_HR|GH3X2X_FUNCTION_HRV + * @param[in] usSampleRate only 25Hz times supported (25/50/75...) + * @param[out] None + * + * @return None + */ +#if __SUPPORT_FUNCTION_SAMPLE_RATE_MODIFY__ +void Gh3x2xDemoFunctionSampleRateSet(GU32 unFunctionID, GU16 usSampleRate) +{ + if((0 == usSampleRate)||(0 !=(usSampleRate%25))) + { + GH3X2X_INFO_LOG("%s : usSampleRate is invalid !!!\r\n", __FUNCTION__); + while(1); + } + + for(GU8 uchFunctionCnt = 0; uchFunctionCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunctionCnt++) + { + if(unFunctionID&(((GU32)1)<pstFunctionInfo->usSampleRateForUserSetting = usSampleRate; + } + } + } +} +#endif + + + +/** + * @fn void Gh3x2xDemoFunctionChannelEnSet(GU32 unFunctionID, GU32 unChnlEn) + * + * @brief + * + * @attention None + * + * @param[in] unFunctionID such as: GH3X2X_FUNCTION_HR or GH3X2X_FUNCTION_HR|GH3X2X_FUNCTION_HRV + * @param[in] unChnlEn BitN = 0: channel N is disable BitN = 1: channel N is enable + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoFunctionChannelEnSet(GU32 unFunctionID, GU32 unChnlEn) +{ + for(GU8 uchFunctionCnt = 0; uchFunctionCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunctionCnt++) + { + if(unFunctionID&(((GU32)1)<pstFunctionInfo->unChnlEnForUserSetting = unChnlEn; + } + } + } +} + +/** + * @fn void Gh3x2xDemoFunctionProcess(GU8* puchReadFifoBuffer, STGsensorRawdata *pstGsAxisValueArr, + * GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief Function process.This function will be called in Gh3x2xDemoInterruptProcess() + * + * @attention None + * + * @param[in] puchReadFifoBuffer point to gh3x2x fifo data buffer + * @param[in] pstGsAxisValueArr point to gsensor data buffer + * @param[in] usGsDataNum gsensor data cnt + * @param[in] emGsSensitivity sensitivity of gsensor + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoFunctionProcess(GU8* puchReadFifoBuffer, GU16 usFifoBuffLen,STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, + STCapRawdata* pstCapValueArr,GU16 usCapDataNum,STTempRawdata* pstTempValueArr,GU16 usTempDataNum) +{ + for(GU8 uchFunCnt = 0; uchFunCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunCnt ++) + { + if(g_pstGh3x2xFrameInfo[uchFunCnt]) + { + + if(g_unDemoFuncMode & (((GU32)1)<< uchFunCnt)) + { + GH3x2xFunctionProcess(puchReadFifoBuffer,usFifoBuffLen,(GS16*)pstGsAxisValueArr,usGsDataNum, + pstCapValueArr,usCapDataNum,pstTempValueArr,usTempDataNum, + g_pstGh3x2xFrameInfo[uchFunCnt]); + } + } + } +} + + +#if __USER_DYNAMIC_DRV_BUF_EN__ +/** + * @fn GU8 Gh3x2xDemoMemCheckValid(void) + * + * @brief check dynamic memory is valid or not + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return 0: invalid 1: valid + */ +GU8 Gh3x2xDemoMemCheckValid(void) +{ + if(0 == g_puchGh3x2xReadRawdataBuffer) + { + GH3X2X_INFO_LOG("%s : g_puchGh3x2xReadRawdataBuffer is invalid !!!\r\n", __FUNCTION__); + return 0; + } + #if __GH3X2X_CASCADE_EN__ + if (GH3X2X_CascadeGetEcgEnFlag()) + { + if(0 == g_puchGh3x2xReadRawdataBufferSlaveChip) + { + GH3X2X_INFO_LOG("%s : g_puchGh3x2xReadRawdataBufferSlaveChip is invalid !!!\r\n", __FUNCTION__); + return 0; + } + } + #endif + return 1; +} + + +void Gh3x2xDemoMemInit(void) +{ + if(0 == g_puchGh3x2xReadRawdataBuffer) + { + #if __GH3X2X_CASCADE_EN__ + g_puchGh3x2xReadRawdataBuffer = Gh3x2xMallocUser(2 * __GH3X2X_RAWDATA_BUFFER_SIZE__); + #else + g_puchGh3x2xReadRawdataBuffer = Gh3x2xMallocUser(__GH3X2X_RAWDATA_BUFFER_SIZE__); + #endif + } + if(0 == Gh3x2xDemoMemCheckValid()) + { + while(1); + } +} +#endif +/** + * @fn int Gh3x2xDemoInit(void) + * + * @brief Init GH3x2x module + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return error code + */ +int Gh3x2xDemoInit(void) +{ + + /// int mode default check + if (g_uchGh3x2xIntMode == __MIX_INT_PROCESS_MODE__) + { + g_uchGh3x2xIntMode = __POLLING_INT_PROCESS_MODE__; + } + + GS8 schret = GH3X2X_RET_OK; + + #if __GH3X2X_INFO_LOG_TYPE__ == __GH3X2X_INFO_LOG_METHOD_0__ + g_pSnprintfUserIn = snprintf; + #if (__ALGO_LOG_CONFIG__) + goodix_set_sprintFunc(NULL, g_pSnprintfUserIn, GH3X2X_PlatformLog); + #endif + #elif __GH3X2X_INFO_LOG_TYPE__ == __GH3X2X_INFO_LOG_METHOD_1__ + GH3X2X_RegisterPrintf(&g_pPrintfUserIn); + #endif + + #if __USER_DYNAMIC_DRV_BUF_EN__ + Gh3x2xDemoMemInit(); + #endif + + #ifdef GOODIX_DEMO_PLATFORM + GH3X2X_INFO_LOG("%s : Firmware Version : %s\r\n", __FUNCTION__, GH3X2X_GetFirmwareVersion()); + #endif + GH3X2X_INFO_LOG("%s : Democode Version : %s\r\n", __FUNCTION__, GH3X2X_GetDemoVersion()); + GH3X2X_INFO_LOG("%s : DrvLib Version : %s\r\n", __FUNCTION__, GH3X2X_GetDriverLibVersion()); + #if (__SUPPORT_PROTOCOL_ANALYZE__) + GH3X2X_INFO_LOG("%s : Protocol Version : %s\r\n", __FUNCTION__, GH3X2X_GetProtocolVersion()); + #endif + GH3X2X_INFO_LOG("%s : Config Version : %s\r\n", __FUNCTION__, GH3X2X_GetVirtualRegVersion()); + #if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + GCHAR algo_version[120] = {0}; + for (int i=0;i __GH3X2X_INFO_LOG_DISABLE__) + if(0 != (usGotEvent & GH3X2X_IRQ_MSK_WEAR_ON_BIT)) + { + GH3X2X_INFO_LOG("Got hardware wear on !!! \r\n"); + } + if(0 != (usGotEvent & GH3X2X_IRQ_MSK_WEAR_OFF_BIT)) + { + GH3X2X_INFO_LOG("Got hardware wear off !!! \r\n"); + } + #endif + #endif + #if 0 + (&usGotEvent, &uchEventEx); + #endif + + + /* 3) check soft adt event */ + //nadt event + if(GH3X2X_GetSoftEvent() & GH3X2X_SOFT_EVENT_WEAR_OFF) + { + uchEventEx |= GH3X2X_EVENT_EX_BIT_WEAR_LIVING_TYPE; + usGotEvent |= GH3X2X_IRQ_MSK_WEAR_OFF_BIT; + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF); + } + else if(GH3X2X_GetSoftEvent() & GH3X2X_SOFT_EVENT_WEAR_ON) + { + uchEventEx |= GH3X2X_EVENT_EX_BIT_WEAR_LIVING_TYPE; + usGotEvent |= GH3X2X_IRQ_MSK_WEAR_ON_BIT; + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON); + } + #if __HARD_ADT_ALGO_CHECK_EN__ + //algo adt event + if(GH3X2X_GetSoftEvent() & GH3X2X_SOFT_EVENT_WEAR_OFF_ALGO_ADT) + { + usGotEvent |= GH3X2X_IRQ_MSK_WEAR_OFF_BIT; + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF_ALGO_ADT); + } + else if(GH3X2X_GetSoftEvent() & GH3X2X_SOFT_EVENT_WEAR_ON_ALGO_ADT) + { + usGotEvent |= GH3X2X_IRQ_MSK_WEAR_ON_BIT; + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_ON_ALGO_ADT); + } + #else + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF_ALGO_ADT|GH3X2X_SOFT_EVENT_WEAR_ON_ALGO_ADT); //if use ADT module in chip, we need ignore these soft event + #endif + #endif + + /****** Start: Ecg Cascade Debug information********/ +#if (__GH3X2X_CASCADE_EN__) + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeOperationMasterChip(); + //GH3X2X_INFO_LOG("Master: 0x00:%04x 0x108:%d 0x400:%04x 0x50c:%04x 0x088:%04x\r\n",GH3X2X_ReadReg(0x00),GH3X2X_ReadReg(0x108),GH3X2X_ReadReg(0x400),GH3X2X_ReadReg(0x74),GH3X2X_ReadReg(0x88)); + GH3X2X_CascadeOperationSlaverChip(); + //GH3X2X_INFO_LOG("Slaver: 0x00:%04x 0x108:%d 0x400:%04x 0x50c:%04x 0x088:%04x\r\n",GH3X2X_ReadReg(0x00),GH3X2X_ReadReg(0x108),GH3X2X_ReadReg(0x400),GH3X2X_ReadReg(0x74),GH3X2X_ReadReg(0x88)); + GH3X2X_CascadeOperationMasterChip(); + } + else + { + GH3X2X_INFO_LOG("Master: 0x00:%04x 0x108:%d 0x400:%04x 0x50c:%04x 0x088:%04x\r\n",GH3X2X_ReadReg(0x00),GH3X2X_ReadReg(0x108),GH3X2X_ReadReg(0x400),GH3X2X_ReadReg(0x74),GH3X2X_ReadReg(0x88)); + } +#endif + /****** End: Ecg Cascade Debug information********/ + + /* Step 3: if it's FIFO interrupt, read gh3x2x fifo data, read gsensor data*/ + #if (__POLLING_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__ || __MIX_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__) + if (g_uchGh3x2xIntMode == __POLLING_INT_PROCESS_MODE__) + { + usGotEvent |= GH3X2X_IRQ_MSK_FIFO_WATERMARK_BIT; + } + #endif + g_usGh3x2xReadRawdataLen = 0; + if ((usGotEvent & (GH3X2X_IRQ_MSK_FIFO_WATERMARK_BIT | GH3X2X_IRQ_MSK_FIFO_FULL_BIT)) \ + || (GH3X2X_GetSoftEvent() & (GH3X2X_SOFT_EVENT_NEED_FORCE_READ_FIFO|GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO))) + { + GU16 usFifoByteNum = ((GU16)4)*GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR); //read fifo use + //GH3X2X_INFO_LOG("usFifoByteNum = %d\r\n", usFifoByteNum); + #if (__GH3X2X_CASCADE_EN__) + //vTaskDelay(5); + GU16 usFifoByteNumSlaver = 0; + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeOperationSlaverChip(); + usFifoByteNumSlaver = ((GU16)4)*GH3X2X_ReadReg(GH3X2X_INT_FIFO_UR_REG_ADDR); + GH3X2X_CascadeOperationMasterChip(); + } + + #endif + #if (__NORMAL_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__ || __MIX_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__) + if (g_uchGh3x2xIntMode == __NORMAL_INT_PROCESS_MODE__) + { + uchIsForceRead = (GH3X2X_GetSoftEvent() & (GH3X2X_SOFT_EVENT_NEED_FORCE_READ_FIFO|GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO)); + if(0 == uchIsForceRead) + { + if(usFifoByteNum < ((GU16)4)*GH3X2X_GetCurrentFifoWaterLine()) //data is too less + { + usFifoByteNum = 0; //no need read + GH3X2X_INFO_LOG("Data is too less, no need read\r\n"); + } + } + } + #endif + + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_NEED_FORCE_READ_FIFO|GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO); + if (usFifoByteNum != 0) + { + #if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + GH3X2X_TimestampSyncSetPpgIntFlag(1); + #endif + #if !(__GH3X2X_CASCADE_EN__) + if (GH3X2X_RET_READ_FIFO_CONTINUE == GH3X2X_ReadFifodata(g_puchGh3x2xReadRawdataBuffer, &g_usGh3x2xReadRawdataLen, usFifoByteNum)) + { + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO); + } + #else + if (GH3X2X_CascadeGetEcgEnFlag()) + { + //GH3X2X_INFO_LOG("Master fifo:%d Slaver Fifo:%d CurrentFifoWaterLine:%d\r\n", usFifoByteNum/4, usFifoByteNumSlaver/4, GH3X2X_GetCurrentFifoWaterLine()); + if (usFifoByteNum > usFifoByteNumSlaver) + { + usFifoByteNum = usFifoByteNumSlaver; + } + if (usFifoByteNum > __GH3X2X_RAWDATA_SLAVE_BUFFER_SIZE__) + { + usFifoByteNum = __GH3X2X_RAWDATA_SLAVE_BUFFER_SIZE__; + } + if (GH3X2X_RET_READ_FIFO_CONTINUE == GH3X2X_CascadeReadFifodata(g_puchGh3x2xReadRawdataBuffer,g_puchGh3x2xReadRawdataBufferSlaveChip, &g_usGh3x2xReadRawdataLen ,usFifoByteNum, 0x08)) + { + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO); + } + } + + else + { + if (GH3X2X_RET_READ_FIFO_CONTINUE == GH3X2X_ReadFifodata(g_puchGh3x2xReadRawdataBuffer, &g_usGh3x2xReadRawdataLen, usFifoByteNum)) + { + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO); + } + } + #endif + #if ((__SUPPORT_PROTOCOL_ANALYZE__)||(__SUPPORT_ALGO_INPUT_OUTPUT_DATA_HOOK_CONFIG__)) + #if (__SUPPORT_ELECTRODE_WEAR_STATUS_DUMP__) + GH3X2X_ReadElectrodeWearDumpData(); + #endif + #if !__SUPPORT_SOFT_AGC_CONFIG__ + GH3X2X_RecordDumpData(); + #endif + #endif + if( uchIntRepeatNum == 0) + { + GH3X2X_UpdateAgcInfo(); + } + } + } + + #if (__FUNC_TYPE_ECG_ENABLE__) + /* extra step: ECG Gain calibration*/ + #if !(__GH3X2X_CASCADE_EN__) + GH3X2X_CalibrateECGGain(g_puchGh3x2xReadRawdataBuffer,g_usGh3x2xReadRawdataLen); + #else + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeCalibrateECGGain(g_puchGh3x2xReadRawdataBuffer,g_usGh3x2xReadRawdataLen); + } + else + { + GH3X2X_CalibrateECGGain(g_puchGh3x2xReadRawdataBuffer,g_usGh3x2xReadRawdataLen); + } + #endif + + /* Step 4: if ECG enabled, do soft lead off process */ + #if (__GH3X2X_CASCADE_EN__) + if (GH3X2X_CascadeGetEcgEnFlag()) + { + usGotEvent = GH3X2X_CascadeLeadOnEventPreDeal(usGotEvent, usGotSlaverEvent,&uchEventEx); + } + #endif + stLeadResult = GH3X2X_LeadHandle(usGotEvent, g_puchGh3x2xReadRawdataBuffer, &g_usGh3x2xReadRawdataLen); + usGotEvent = stLeadResult.usEvent; + + if(stLeadResult.uchNeedForceReadFifo) + { + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_NEED_FORCE_READ_FIFO); + } + GH3X2X_EcgRsHandle(g_puchGh3x2xReadRawdataBuffer, &g_usGh3x2xReadRawdataLen); + #endif + + /* Step 5: do soft agc process*/ + Gh3x2x_UserHandleCurrentInfo(); + #if (__SUPPORT_ENGINEERING_MODE__) + if(0 == g_uchEngineeringModeStatus) //in engineering mode, disable soft agc function + #endif + { + if(0 != (usGotEvent & (GH3X2X_IRQ_MSK_TUNNING_FAIL_BIT | GH3X2X_IRQ_MSK_TUNNING_DONE_BIT))) + { +// GH3X2X_SoftLedADJAutoADJInt(); + } + #if (__SUPPORT_SAMPLE_DEBUG_MODE__) + if((g_usDumpMode & 0x3) != 0) + { + GH3X2X_LedAgcProcessExDump(g_puchGh3x2xReadRawdataBuffer); + } + else + #endif + { + #if __SUPPORT_SOFT_AGC_CONFIG__ + if( uchIntRepeatNum == 0) + { + GH3X2X_LedAgcProcess(g_puchGh3x2xReadRawdataBuffer, g_usGh3x2xReadRawdataLen, g_pstGh3x2xAgcInfo); + } + #endif + } + } + + /* Extern Step: send fifo*/ + #if (__FIFO_PACKAGE_SEND_ENABLE__) + if (GH3X2X_GetFifoPackageMode()) + { + GH3X2X_SendRawdataFifoPackage(g_puchGh3x2xReadRawdataBuffer, g_usGh3x2xReadRawdataLen); + } + #endif + + /* Step 6: chip reset event process*/ + if(0 != (usGotEvent & GH3X2X_IRQ_MSK_CHIP_RESET_BIT)) + { + if(0 == GH3x2x_GetChipResetRecoveringFlag()) //do nothing in recover period + { + GH3X2X_INFO_LOG("Got chip reset event !!! ActiveChipResetFlag = %d, g_unDemoFuncMode = %d, recovering flag = %d\r\n",(int)GH3x2x_GetActiveChipResetFlag(), (int)g_unDemoFuncMode, (int)GH3x2x_GetChipResetRecoveringFlag()); + if((GH3x2x_GetActiveChipResetFlag())) //it will enter this "if" after loading cfg in EVK mode + { + Gh3x2xDemoSamplingControl(0xFFFFFFFF, UPROTOCOL_CMD_STOP); + GH3X2X_Init(GH3X2X_PTR_NULL); //It should not init any config in array.c, because PC tool will send config after this process in EVK mode + } + + #ifdef GOODIX_DEMO_PLATFORM + else if(g_uchDemoWorkMode <= GH3X2X_DEMO_WORK_MODE_MCU_ONLINE) //in APP/EVK/MCU online mode, do not support recovery from abnormal reset + { + Gh3x2xDemoSamplingControl(0xFFFFFFFF, UPROTOCOL_CMD_STOP); + GH3X2X_Init(GH3X2X_PTR_NULL); + } + #endif + else + { + //need recovery for chip reset + GU8 uchTryCnt = 5; //retry max count + GS8 schret = GH3X2X_RET_GENERIC_ERROR; + GU32 unDemoFuncModeBeforeChipReset; + GH3X2X_INFO_LOG("Gh3x2xDemoInterruptProcess:start chip reset recovery...\r\n"); + GH3x2x_SetChipResetRecoveringFlag(1); + + + unDemoFuncModeBeforeChipReset = g_unDemoFuncMode; + do{ + #if __SUPPORT_HARD_RESET_CONFIG__ + GH3X2X_HardReset(); + #else + GH3X2X_SoftReset(); + #endif + Gh3x2x_BspDelayMs(30); + + Gh3x2xDemoStopSampling(g_unDemoFuncMode); + GH3X2X_INFO_LOG("Gh3x2xDemoInterruptProcess:use cfg%d to recover.\r\n",g_uchGh3x2xRegCfgArrIndex); + + schret = GH3X2X_Init(g_stGh3x2xCfgListArr+g_uchGh3x2xRegCfgArrIndex); + + if (GH3X2X_RET_OK == schret) + { + GH3X2X_INFO_LOG("Gh3x2xDemoInterruptProcess:recovery init success\r\n"); + } + else + { + //g_uchGh3x2xRegCfgArrIndex = DRV_LIB_REG_CFG_EMPTY; + GH3X2X_INFO_LOG("Gh3x2xDemoInterruptProcess:recovery init fail, error code: %d\r\n", schret); + } + uchTryCnt --; + }while((GH3X2X_RET_OK != schret)&&(0 < uchTryCnt)); + + GH3X2X_EnterLowPowerMode(); + #if __GH3X2X_CASCADE_EN__ + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + #endif + + #if (__SUPPORT_ENGINEERING_MODE__) + if(1 == g_uchEngineeringModeStatus) + { + Gh3x2xDemoStartSamplingForEngineeringMode(unDemoFuncModeBeforeChipReset, g_uchGh3x2xRegCfgArrIndex, g_pstSampleParaGroup, g_uchEngineeringModeSampleParaGroupNum); + } + else + #endif + { + Gh3x2xDemoStartSampling(unDemoFuncModeBeforeChipReset); + } + GH3x2x_SetChipResetRecoveringFlag(0); + } + } + } + + #if !(__GH3X2X_CASCADE_EN__) + GH3X2X_EnterLowPowerMode(); + #else + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + } + else + { + GH3X2X_EnterLowPowerMode(); + } + #endif + + /* Step 7: report event */ + #if (__SUPPORT_PROTOCOL_ANALYZE__) + Gh3x2xDemoReportEvent(usGotEvent,uchEventEx); + + if(uchEventEx&GH3X2X_EVENT_EX_BIT_CHIP0_LEAD_ON) + { + GH3X2X_INFO_LOG("chip0 lead on\r\n"); + //while(1); + } + if(uchEventEx&GH3X2X_EVENT_EX_BIT_CHIP1_LEAD_ON) + { + GH3X2X_INFO_LOG("chip1 lead on\r\n"); + //while(1); + } + #endif + if ((usGotEvent & (GH3X2X_IRQ_MSK_FIFO_WATERMARK_BIT | GH3X2X_IRQ_MSK_FIFO_FULL_BIT)) \ + || uchIsForceRead) + { + #if __GS_NONSYNC_READ_EN__ + GU16 usGsensorNeedPointNum; + GS16 sGsensorHeadPosi; + #endif + if (GH3X2X_GetGsensorEnableFlag()) + { + #if (__GSENSOE_MOVE_DETECT_SUPPORT__) + if(0 == GhGsMoveDetecterIsEnable()) + #endif + { + hal_gsensor_drv_get_fifo_data(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__, &gsensor_soft_fifo_buffer_index); + Gh3x2x_NormalizeGsensorSensitivity(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__ ,gsensor_soft_fifo_buffer_index); + } + } + /*extra step: get cap and temp data from other sensor*/ + #if __CAP_ENABLE__ + if (GH3X2X_GetCapEnableFlag()) + { + hal_cap_drv_get_fifo_data(cap_soft_fifo_buffer, &cap_soft_fifo_buffer_index); + } + #endif + #if __TEMP_ENABLE__ + if (GH3X2X_GetTempEnableFlag()) + { + hal_temp_drv_get_fifo_data(temp_soft_fifo_buffer, &temp_soft_fifo_buffer_index); + } + #endif + /* Step 8: algorithm process*/ + #if __GH3X2X_MEM_POOL_CHECK_EN__ + Gh3x2xCheckMemPollBeforeAlgoCal(); + #endif + + #ifdef GOODIX_DEMO_PLATFORM + if (((GH3X2X_DEMO_WORK_MODE_MCU_ONLINE == g_uchDemoWorkMode) ||\ + (GH3X2X_DEMO_WORK_MODE_PASS_THROUGH == g_uchDemoWorkMode) ||\ + (GH3X2X_DEMO_WORK_MODE_APP == g_uchDemoWorkMode) ||\ + (GH3X2X_DEMO_WORK_MODE_EVK == g_uchDemoWorkMode)) &&\ + ((g_usDumpMode & 0x3) == 0)) + #endif + { + #if __GS_NONSYNC_READ_EN__ + usGsensorNeedPointNum = Gh3x2xGetGsensorNeedPointNum(gsensor_soft_fifo_buffer_index, g_puchGh3x2xReadRawdataBuffer, g_usGh3x2xReadRawdataLen); + sGsensorHeadPosi = Gh3x2xGetGsensorHeadPos(gsensor_soft_fifo_buffer_index,usGsensorNeedPointNum); + Gh3x2xDemoFunctionProcess(g_puchGh3x2xReadRawdataBuffer,g_usGh3x2xReadRawdataLen, gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__ + sGsensorHeadPosi, usGsensorNeedPointNum, + cap_soft_fifo_buffer,cap_soft_fifo_buffer_index,temp_soft_fifo_buffer,temp_soft_fifo_buffer_index); + + + for(GU16 usPointCnt = 0; usPointCnt < usGsensorNeedPointNum; usPointCnt++) + { + STGsensorRawdata * temp_gsensor = gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__ + sGsensorHeadPosi; + GH3X2X_INFO_LOG("[Gsensor show]x = %d,y = %d, z = %d\r\n",temp_gsensor[usPointCnt].sXAxisVal,temp_gsensor[usPointCnt].sYAxisVal,temp_gsensor[usPointCnt].sZAxisVal); + } + + + Gh3x2xNonSyncGsenosrPostProcess(gsensor_soft_fifo_buffer_index, usGsensorNeedPointNum, sGsensorHeadPosi); + #else + Gh3x2xDemoFunctionProcess(g_puchGh3x2xReadRawdataBuffer,g_usGh3x2xReadRawdataLen, gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__, gsensor_soft_fifo_buffer_index, + cap_soft_fifo_buffer,cap_soft_fifo_buffer_index,temp_soft_fifo_buffer,temp_soft_fifo_buffer_index); + #endif + } + #if __GH3X2X_MEM_POOL_CHECK_EN__ + Gh3x2xUpdataMemPollChkSumAfterAlgoCal(); + #endif + } + + /* Step 9: event hook */ + #if (__FUNC_TYPE_ECG_ENABLE__) + if (usGotEvent & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT) + { + Gh3x2x_LeadOnEventHook(); + GH3X2X_INFO_LOG("Lead on!!!\r\n"); + } + if (usGotEvent & GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT) + { + Gh3x2x_LeadOffEventHook(); + GH3X2X_INFO_LOG("Lead off!!!\r\n"); + } + #endif + + #if (__SUPPORT_HARD_ADT_CONFIG__) + if ((usGotEvent & GH3X2X_IRQ_MSK_WEAR_ON_BIT) || (usGotEvent & GH3X2X_IRQ_MSK_WEAR_OFF_BIT)) + { + #if (__GH3X2X_CASCADE_EN__) + Gh3x2x_WearEventCascadeEcgHandle(usGotEvent); + #endif + Gh3x2x_WearEventHook(usGotEvent, uchEventEx); + } + #endif + + if (GH3X2X_GetSoftEvent()) //have new soft event + { + uchRet = GH3X2X_INT_PROCESS_REPEAT; + GH3X2X_INFO_LOG("InterruptProcess: process need repeat, soft evt = 0x%X\r\n", GH3X2X_GetSoftEvent()); + } + + if (uchIntRepeatNum > 20) + { + GH3X2X_INFO_LOG("InterruptProcess: 0 Warning!!!!GetEvent Error!!!0x%x\r\n", usGotEvent); + GH3X2X_INFO_LOG("InterruptProcess: 1 Warning!!!!GetEvent Error!!!0x%x\r\n", usGotEvent); + GH3X2X_INFO_LOG("InterruptProcess: 2 Warning!!!!GetEvent Error!!!0x%x\r\n", usGotEvent); + GH3X2X_ClearSoftEvent(GH3X2X_SOFT_EVENT_NEED_TRY_READ_FIFO); + Gh3x2xFifoRecovery(); + break; + } + else + { + uchIntRepeatNum++; + } + }while(GH3X2X_INT_PROCESS_REPEAT == uchRet); + + g_uchGh3x2xInterruptProNotFinishFlag = 0; +} + +#if __GH3X2X_CASCADE_EN__ +GU8 Gh3x2xCheckCfgValidForCascade(GU8 uchCfgIndex) +{ + if(GH3X2X_CascadeGetEcgEnFlag()) + { + if(2 != uchCfgIndex) //In cascade mode, only cfg2 is valid + { + return 0; + } + } + else + { + if(2 == uchCfgIndex) //Not in cascade mode, cfg2 is invalid + { + return 0; + } + } + return 1; +} +#endif + +/** + * @fn GS8 GH3x2xDemoSearchCfgListByFunc(GU8* puchCfgIndex, GU32 unFuncMode, GU32 unFuncModeFilter) + * + * @brief Search reg config array by function mode + * + * @attention None + * + * @param[in] unFuncMode function mode + * @param[in] unFuncModeFilter ignored function mode + * @param[out] puchCfgIndex reg config array index + * + * @return GH3X2X_RET_OK:switch application mode success + * @return GH3X2X_RET_RESOURCE_ERROR:can't find corresponding reg config array + */ +GS8 GH3x2xDemoSearchCfgListByFunc(GU8* puchCfgIndex, GU32 unFuncMode, GU32 unFuncModeFilter) +{ + GS8 chRet = GH3X2X_RET_OK; + GU8 uchIndex = 0; + GU32 unFuncModeTemp = GH3X2X_NO_FUNCTION; + //find reg config array that match unFuncMode + GH3X2X_INFO_LOG("target app mode:0x%x\r\n",unFuncMode); + for (uchIndex = 0; uchIndex < __GH3X2X_CFG_LIST_MAX_NUM__; uchIndex++) + { + if ( + (((g_stGh3x2xCfgListArr+uchIndex)->usConfigArrLen) > DRV_LIB_REG_CFG_MIN_LEN) + #if __GH3X2X_CASCADE_EN__ + &&(1 == Gh3x2xCheckCfgValidForCascade(uchIndex)) + #endif + ) + { + GH3X2X_DecodeRegCfgArr(&unFuncModeTemp,(g_stGh3x2xCfgListArr+uchIndex)->pstRegConfigArr, \ + (g_stGh3x2xCfgListArr+uchIndex)->usConfigArrLen); + + + GH3X2X_INFO_LOG("search cfg app mode:0x%x\r\n",unFuncModeTemp); + + if((unFuncMode | unFuncModeFilter) == ((unFuncModeTemp&unFuncMode) | unFuncModeFilter)) + { + (*puchCfgIndex) = uchIndex; + GH3X2X_INFO_LOG("Got right cfg ,index = %d\r\n",uchIndex); + break; + } + } + } + + if (uchIndex >= __GH3X2X_CFG_LIST_MAX_NUM__) + { + chRet = GH3X2X_RET_RESOURCE_ERROR; + } + return chRet; +} + + +/** + * @fn GS8 Gh3x2xDemoArrayCfgSwitch(GU8 uchArrayCfgIndex) + * + * @brief array cfg switch (call by user) + * + * @attention you should switch array cfg manually before calling Gh3x2xDemoStartSampling + * + * @param[in] uchArrayCfgIndex 0: gh3x2x_reg_list0 1: gh3x2x_reg_list0 ... + * @param[out] None + * + * @return GH3X2X_RET_OK:switch application mode success + * @return GH3X2X_RET_RESOURCE_ERROR:can't find corresponding reg config array + */ +GS8 Gh3x2xDemoArrayCfgSwitch(GU8 uchArrayCfgIndex) +{ + GS8 chRet = GH3X2X_RET_OK; + + if(g_uchGh3x2xRegCfgArrIndex == uchArrayCfgIndex) + { + GH3X2X_INFO_LOG("Current cfg is already cfg%d, no need switch.\r\n",(int)uchArrayCfgIndex); + } + else if(uchArrayCfgIndex < __GH3X2X_CFG_LIST_MAX_NUM__) + { + Gh3x2xDemoSamplingControl(0xFFFFFFFF, UPROTOCOL_CMD_STOP); + #if __SUPPORT_HARD_RESET_CONFIG__ + GH3X2X_HardReset(); + #else + GH3X2X_SoftReset(); + #endif + Gh3x2x_BspDelayMs(15); + #if __GH3X2X_CASCADE_EN__ + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_CascadeOperationMasterChip(); + #endif + + g_uchGh3x2xRegCfgArrIndex = uchArrayCfgIndex; + if (GH3X2X_RET_OK == GH3X2X_Init(g_stGh3x2xCfgListArr + uchArrayCfgIndex)) + { + GH3X2X_INFO_LOG("cfg%d switch success !!!.\r\n",(int)uchArrayCfgIndex); + } + else + { + g_uchGh3x2xRegCfgArrIndex = DRV_LIB_REG_CFG_EMPTY; + chRet = GH3X2X_RET_RESOURCE_ERROR; + GH3X2X_INFO_LOG("Error ! cfg%d switch fail !!!\r\n",(int)uchArrayCfgIndex); + } + GH3X2X_EnterLowPowerMode(); + #if __GH3X2X_CASCADE_EN__ + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + #endif + + } + else + { + GH3X2X_INFO_LOG("Error! uchArrayCfgIndex(%d) is invalid !!!\r\n",(int)uchArrayCfgIndex); + chRet = GH3X2X_RET_RESOURCE_ERROR; + } + return chRet; +} + +GU8 guchSlotEn = 0; + +void Gh3x2xSetCurrentSlotEnReg(GU32 unFuncMode) +{ + GU8 uchSlotEn = 0; + + #if __SLOT_SEQUENCE_DYNAMIC_ADJUST_EN__ + GU8 uchSlotSeq[8]; + GU8 uchValidSlotNum = 0; + GU16 usStartReg; + GU8 uchSlotSrDiver[8]; + GU8 uchSlotCfgHaveSortedFlag[8] = {0}; + GU8 uchSlotCfgIndexFast2Low[8]; + #endif + for(GU8 uchFunCnt = 0; uchFunCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunCnt ++) + { + if(g_pstGh3x2xFrameInfo[uchFunCnt]) + { + if(g_unDemoFuncMode & (((GU32)1)<< uchFunCnt)) + { + uchSlotEn |= g_pstGh3x2xFrameInfo[uchFunCnt]->pstFunctionInfo->uchSlotBit; + } + } + } + #if __SLOT_SEQUENCE_DYNAMIC_ADJUST_EN__ + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + //get diver for every slot cfg + uchSlotSrDiver[uchSlotCnt] = GH3x2xGetAgcReg(GH3X2X_AGC_REG_SR_MULIPLIPER, uchSlotCnt); + } + + //GH3X2X_INFO_LOG("%s : Slot cfg Sort fast to slow: \r\n", __FUNCTION__); + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + //find min diver + GU16 usCurrentMinDiver = 0xFFFF; + GU8 uchCurrentMinDiverCfgIndex = 0xFF; + for(GU8 uchSearchCnt = 0; uchSearchCnt < 8; uchSearchCnt ++) + { + if(0 == uchSlotCfgHaveSortedFlag[uchSearchCnt]) + { + if(usCurrentMinDiver > uchSlotSrDiver[uchSearchCnt]) + { + usCurrentMinDiver = uchSlotSrDiver[uchSearchCnt]; + uchCurrentMinDiverCfgIndex = uchSearchCnt; + } + } + } + if(0xFF != uchCurrentMinDiverCfgIndex) + { + uchSlotCfgHaveSortedFlag[uchCurrentMinDiverCfgIndex] = 1; + uchSlotCfgIndexFast2Low[uchSlotCnt] = uchCurrentMinDiverCfgIndex; + + //GH3X2X_INFO_LOG("%d \r\n", uchCurrentMinDiverCfgIndex); + } + } + //GH3X2X_INFO_LOG("\r\n"); + + + //find slot cfg from fastest to lowest + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + GU8 uchCurrentFastSlotCfgIndex = uchSlotCfgIndexFast2Low[uchSlotCnt]; + for(GU8 uchSlotSearchCnt = 0; uchSlotSearchCnt < 8; uchSlotSearchCnt ++) + { + if(uchSlotEn&(1<pstFunctionInfo->usSampleRateForUserSetting; + if(0 == usTempTargetSampleRate) + { + usTempTargetSampleRate = g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->usSampleRate; + } + GU8 uchTempSlotBit = g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->uchSlotBit; + GH3X2X_INFO_LOG("[Gh3x2xSampleRateUpdate]FunctionId = 0x%X, slot bit = 0x%X,usSampleRateUser = %d\r\n",g_pstGh3x2xFrameInfo[uchFunctionCnt]->unFunctionID,uchTempSlotBit, usTempTargetSampleRate); + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + if(uchTempSlotBit&(1< usTargetSampleRate[uchSlotCnt]) + { + usTargetSampleRate[uchSlotCnt] = usTempTargetSampleRate; //store faster sample rate + } + } + } + } + } + + + //update sample rate registers + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + if((usTargetSampleRate[uchSlotCnt] != usLastSampleRate[uchSlotCnt])&&(0 != usTargetSampleRate[uchSlotCnt])) + { + if(0 == uchHaveStopSample) + { + usStartReg = GH3X2X_ReadReg(0x0000); //bak start reg + GH3X2X_WriteReg(0x0000,usStartReg&(0xFFFE)); //stop sample + uchHaveStopSample = 1; + } + GH3x2xSetAgcReg(GH3X2X_AGC_REG_SR_MULIPLIPER, uchSlotCnt, (1000/usTargetSampleRate[uchSlotCnt]) - 1); + GH3X2X_INFO_LOG("[Gh3x2xSampleRateUpdate]Slot%d sample rate need change: Last = %d, Target = %d\r\n",uchSlotCnt, usLastSampleRate[uchSlotCnt], usTargetSampleRate[uchSlotCnt]); + } + } + if(uchHaveStopSample) + { + GH3X2X_WriteReg(0x0000,usStartReg); //recover sample reg + } + + + + //update usSampleRate value,and down sample check + for(GU8 uchFunctionCnt = 0; uchFunctionCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunctionCnt++) + { + GU16 usSlowestSlotSampleRate = 0xFFFF; + + if((g_pstGh3x2xFrameInfo[uchFunctionCnt])&&(unFuncMode&((GU32)1<pstFunctionInfo->uchSlotBit; + //update update usSampleRate value + if(g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->usSampleRateForUserSetting) + { + g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->usSampleRate = g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->usSampleRateForUserSetting; + } + //get slowest slot in function (target sample rate) + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + if(uchTempSlotBit&(1< usTargetSampleRate[uchSlotCnt]) + { + usSlowestSlotSampleRate = usTargetSampleRate[uchSlotCnt]; + } + } + } + if(usSlowestSlotSampleRate > g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->usSampleRate) //need down sample + { + g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstDownSampleInfo->uchDownSampleFactor = (usSlowestSlotSampleRate/g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstFunctionInfo->usSampleRate) - 1; + } + else + { + g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstDownSampleInfo->uchDownSampleFactor = 0; + } + g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstDownSampleInfo->uchDownSampleCnt = 0; + GH3X2X_INFO_LOG("[Gh3x2xSampleRateUpdate]Down sample: FunctionID = 0x%X,: SlowestSlotSR = %d, Factor = %d\r\n",g_pstGh3x2xFrameInfo[uchFunctionCnt]->unFunctionID, usSlowestSlotSampleRate, g_pstGh3x2xFrameInfo[uchFunctionCnt]->pstDownSampleInfo->uchDownSampleFactor); + + } + + } + +} +#endif + +void GH3x2xMaserControlFunctionLog(GU32 unFuncMode, EMUprotocolParseCmdType emCmdType) +{ + if(UPROTOCOL_CMD_START == emCmdType) + { + GH3X2X_INFO_LOG("Master start function = 0x%x\r\n",unFuncMode); + } + else + { + GH3X2X_INFO_LOG("Master stop function = 0x%x\r\n",unFuncMode); + } +} + + + + +/** + * @fn void Gh3x2xDemoSamplingControl(EMUprotocolParseCmdType emSwitch) + * + * @brief Start/stop sampling of gh3x2x and sensor + * + * @attention None + * + * @param[in] unFuncMode function that will be started or stopped + * @param[in] emSwitch stop/start sampling + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoSamplingControl(GU32 unFuncMode, EMUprotocolParseCmdType emSwitch) +{ + + if ((GH3X2X_GetConfigFuncMode() & unFuncMode) != unFuncMode) + { + GH3X2X_INFO_LOG("[%s]:config has no target function!!!config function = 0x%08x,unFuncMode = 0x%08x\r\n", __FUNCTION__, GH3X2X_GetConfigFuncMode(),unFuncMode); + unFuncMode = (GH3X2X_GetConfigFuncMode() & unFuncMode); + } + if(unFuncMode == 0) + { + return; + } + #if (__FUNC_TYPE_ECG_ENABLE__) + GU8 uchEcgCtrlFlag = 0; + #endif + #if __GS_NONSYNC_READ_EN__ + GU16 usTempFunction; + #endif + #if __FUNC_TYPE_ECG_ENABLE__ + GU32 unLastDemoFuncMode = g_unDemoFuncMode; + #endif + + #if !(__GH3X2X_CASCADE_EN__) + #else + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_CascadeOperationMasterChip(); + + } + else + { + } + #endif + for(GU8 uchFunCnt = 0; uchFunCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunCnt ++) + { + if(g_pstGh3x2xFrameInfo[uchFunCnt]) + { + if(unFuncMode & (((GU32)1)<< uchFunCnt)) + { + if((UPROTOCOL_CMD_START == emSwitch)&&((g_unDemoFuncMode & (((GU32)1)<< uchFunCnt)) != (((GU32)1)<< uchFunCnt))) + { + #if (__SUPPORT_HARD_ADT_CONFIG__) + if(GH3X2X_FUNC_OFFSET_ADT == uchFunCnt) + { + GH3X2X_ResetHardAdt(); //reset hard adt module before every ADT function openning + } + #endif + GH3X2X_FunctionStart(g_pstGh3x2xFrameInfo[uchFunCnt]); + #if __FUNC_TYPE_ECG_ENABLE__ + if(GH3X2X_FUNC_OFFSET_ECG == uchFunCnt) + { + uchEcgCtrlFlag = GH3X2X_ECG_CTRL_FLAG_START; + } + #endif + } + else if ((UPROTOCOL_CMD_STOP == emSwitch)&&((g_unDemoFuncMode & (((GU32)1)<< uchFunCnt)) == (((GU32)1)<< uchFunCnt))) + { + if(GH3X2X_FUNC_OFFSET_ADT == uchFunCnt) + { + #if (__SUPPORT_HARD_ADT_CONFIG__) + GH3X2X_FunctionStop(g_pstGh3x2xFrameInfo[uchFunCnt]); + #if (0 == __HARD_ADT_ALGO_CHECK_EN__) + g_uchWearDetectStatus = WEAR_DETECT_WEAR_ON; + GH3X2X_WearDetectSwitchTo(WEAR_DETECT_WEAR_ON,WEAR_DETECT_FORCE_SWITCH); + #endif + #endif + #if (__SUPPORT_PROTOCOL_ANALYZE__) + Gh3x2xDemoReportEvent(WEAR_DETECT_WEAR_OFF,0); + #endif + } + else + { + GH3X2X_FunctionStop(g_pstGh3x2xFrameInfo[uchFunCnt]); + #if __FUNC_TYPE_ECG_ENABLE__ + if(GH3X2X_FUNC_OFFSET_ECG == uchFunCnt) + { + uchEcgCtrlFlag = GH3X2X_ECG_CTRL_FLAG_STOP; + } + #endif + } + } + } + } + } + + /* Enable gsensor sampling */ + if (UPROTOCOL_CMD_START == emSwitch) + { +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + GH3X2X_TimestampSyncPpgInit(unFuncMode); +#endif + if (GH3X2X_GetGsensorEnableFlag() && (GH3X2X_NO_FUNCTION == g_unDemoFuncMode)) + { + hal_gsensor_start_cache_data(); + } +#if (__CAP_ENABLE__) + if (GH3X2X_GetCapEnableFlag() && ((unFuncMode & (GH3X2X_FUNCTION_SOFT_ADT_GREEN | GH3X2X_FUNCTION_SOFT_ADT_IR)) != GH3X2X_NO_FUNCTION)) + { + GH3x2xReadCapFromFlash(); + } + if (GH3X2X_GetCapEnableFlag() && (GH3X2X_NO_FUNCTION == g_unDemoFuncMode)) + { + hal_cap_start_cache_data(); + } +#endif +#if (__TEMP_ENABLE__) + if (GH3X2X_GetTempEnableFlag() && (GH3X2X_NO_FUNCTION == g_unDemoFuncMode)) + { + hal_temp_start_cache_data(); + } +#endif + g_unDemoFuncMode |= unFuncMode; + } + else + { + g_unDemoFuncMode &= ~unFuncMode; + if (GH3X2X_GetGsensorEnableFlag() && (GH3X2X_NO_FUNCTION == g_unDemoFuncMode)) + { + //hal_gsensor_stop_cache_data(); + } +#if (__CAP_ENABLE__) + if (GH3X2X_GetCapEnableFlag() && (GH3X2X_NO_FUNCTION == g_unDemoFuncMode)) + { + if((unFuncMode & (GH3X2X_FUNCTION_SOFT_ADT_GREEN | GH3X2X_FUNCTION_SOFT_ADT_IR)) != GH3X2X_NO_FUNCTION) + { + GH3x2xWriteCapToFlash(); + } + hal_cap_stop_cache_data(); + } +#endif +#if (__TEMP_ENABLE__) + if (GH3X2X_GetTempEnableFlag() && (GH3X2X_NO_FUNCTION == g_unDemoFuncMode)) + { + hal_temp_stop_cache_data(); + } +#endif + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_NEED_FORCE_READ_FIFO); + } + +#if __FUNC_TYPE_ECG_ENABLE__ + if(unLastDemoFuncMode&(GH3X2X_FUNCTION_ADT|GH3X2X_FUNCTION_LEAD_DET)) //have adt/lead function before change + { + if(0 == (g_unDemoFuncMode&(GH3X2X_FUNCTION_ADT|GH3X2X_FUNCTION_LEAD_DET))) //have no adt/lead function after change + { + GH3X2X_LeadDetEnInHardAdt(0); + } + } + else //have no adt/lead function before change + { + if((g_unDemoFuncMode&(GH3X2X_FUNCTION_ADT|GH3X2X_FUNCTION_LEAD_DET))) //have adt/lead function after change + { + GH3X2X_LeadDetEnInHardAdt(1); + } + } +#endif + +#if __ADT_ONLY_PARTICULAR_WM_CONFIG__ + if(GH3X2X_FUNCTION_ADT == g_unDemoFuncMode) // only ADT function is opening + { + g_usCurrentConfigListFifoWmBak = GH3X2X_ReadReg(0x000A); //bak current reg + GH3X2X_WriteReg(0x000A, __ADT_ONLY_PARTICULAR_WM_CONFIG__); //set particular watermark for ADT only + g_usCurrentFiFoWaterLine = __ADT_ONLY_PARTICULAR_WM_CONFIG__; + GH3X2X_INFO_LOG("set particular watermark for ADT only. value = %d.\r\n",(int)__ADT_ONLY_PARTICULAR_WM_CONFIG__); + } + else + { + if(g_usCurrentConfigListFifoWmBak) // if bak value is exist + { + GH3X2X_WriteReg(0x000A, g_usCurrentConfigListFifoWmBak); // recover the watermark + g_usCurrentFiFoWaterLine = g_usCurrentConfigListFifoWmBak; + g_usCurrentConfigListFifoWmBak = 0; //clear bak value + GH3X2X_INFO_LOG("recover watermark. value = %d.\r\n",(int)g_usCurrentConfigListFifoWmBak); + } + } + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_NEED_FORCE_READ_FIFO); //need force read fifo after setting watermark +#endif + + + + +#if __SUPPORT_FUNCTION_SAMPLE_RATE_MODIFY__&& (!__SUPPORT_PPG_DOWNSAMP__) &&(!__SUPPORT_ECG_DOWNSAMP__) + Gh3x2xSampleRateUpdate(g_unDemoFuncMode); +#endif + Gh3x2xSetCurrentSlotEnReg(g_unDemoFuncMode); +#if (GH3X2X_FIFO_MONITOR_EN&(__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__)) + Gh3x2xFifoMonitorInit(&g_stFifoMonitorInfo); +#endif + + GH3X2X_INFO_LOG("Current g_unDemoFuncMode= 0x%x\r\n",g_unDemoFuncMode); +#if (__FUNC_TYPE_ECG_ENABLE__) + if(GH3X2X_ECG_CTRL_FLAG_START == uchEcgCtrlFlag) + { + GH3X2X_EcgSampleHookHandle(ECG_SAMPLE_EVENT_TYPE_SLOT,g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchSlotBit); + } + else if(GH3X2X_ECG_CTRL_FLAG_STOP == uchEcgCtrlFlag) + { + GH3X2X_EcgSampleHookHandle(ECG_SAMPLE_EVENT_TYPE_SLOT,~(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchSlotBit)); + } +#endif + +#if __GS_NONSYNC_READ_EN__ + usTempFunction = Gh3x2xGetCurrentRefFunction(); + if(usTempFunction != g_usGsenorRefFunction) + { + g_usGsenorRefFunction = usTempFunction; + Gh3x2xNonSyncGsensorInit(); + } +#endif + + if(GH3X2X_GetSoftEvent()&&(0 == g_uchGh3x2xInterruptProNotFinishFlag)) //avoid nesting + { + Gh3x2xDemoInterruptProcess(); + } + +#if !(__GH3X2X_CASCADE_EN__) + GH3X2X_EnterLowPowerMode(); +#else + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + + } + else + { + GH3X2X_EnterLowPowerMode(); + } +#endif +} + + + + +void Gh3x2xFunctionSlotBitInit(void) +{ + for(GU8 uchFunctionCnt = 0; uchFunctionCnt < GH3X2X_FUNC_OFFSET_MAX; uchFunctionCnt++) + { + if(g_pstGh3x2xFrameInfo[uchFunctionCnt]) + { + GH3x2xCalFunctionSlotBit(g_pstGh3x2xFrameInfo[uchFunctionCnt]); + } + } +} + + + +void Gh3x2xEnterCascadeMode(void) +{ +#if __GH3X2X_CASCADE_EN__ + Gh3x2xDemoStopSampling(0xFFFFFFFF); //stop all function +#if __USER_DYNAMIC_DRV_BUF_EN__ + if(0 == g_puchGh3x2xReadRawdataBufferSlaveChip) + { + g_puchGh3x2xReadRawdataBufferSlaveChip = Gh3x2xMallocUser(__GH3X2X_RAWDATA_BUFFER_SIZE__); + } + if(0 == Gh3x2xDemoMemCheckValid()) + { + while(1); + } +#endif + GH3X2X_CascadeSetEcgEnFlag(1); + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_CascadeOperationMasterChip(); + + g_uchGh3x2xRegCfgArrIndex = 2; + if (GH3X2X_RET_OK != GH3X2X_Init(g_stGh3x2xCfgListArr+2)) //load ecg master and slave cfg + { + g_uchGh3x2xRegCfgArrIndex = DRV_LIB_REG_CFG_EMPTY; + } + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); +#endif +} +void Gh3x2xExitCascadeMode(void) +{ +#if __GH3X2X_CASCADE_EN__ + Gh3x2xDemoStopSampling(0xFFFFFFFF); //stop all function + GH3X2X_CascadeSetEcgEnFlag(0); + if(0 == GH3X2X_GetSingleChipModeEnableFlag()) + { + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_CascadeOperationMasterChip(); + } + + g_uchGh3x2xRegCfgArrIndex = 2; + if (GH3X2X_RET_OK != GH3X2X_Init(g_stGh3x2xCfgListArr+0)) + { + g_uchGh3x2xRegCfgArrIndex = DRV_LIB_REG_CFG_EMPTY; + } + GH3X2X_EnterLowPowerMode(); + if(0 == GH3X2X_GetSingleChipModeEnableFlag()) + { + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + } +#if __USER_DYNAMIC_DRV_BUF_EN__ + if(g_puchGh3x2xReadRawdataBufferSlaveChip) + { + Gh3x2xFreeUser(g_puchGh3x2xReadRawdataBufferSlaveChip); + g_puchGh3x2xReadRawdataBufferSlaveChip = 0; + } +#endif +#endif +} + + + + +/** + * @fn void Gh3x2xDemoStartSampling() + * + * @brief Start sampling of GH3x2x + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStartSamplingInner(GU32 unFuncMode, GU8 uchSwitchEnable) +{ + GH3X2X_INFO_LOG("[Gh3x2xDemoStartSampling] unFuncMode = 0x%X\r\n",(int)unFuncMode); + GU32 unFuncModeTemp1 = GH3X2X_NO_FUNCTION; + GU32 unFuncModeTemp2 = GH3X2X_NO_FUNCTION; + GU32 unTargetFunMode; + GU8 uchIndex = 0; + GS8 chRet = GH3X2X_RET_OK; +#if __FUNC_TYPE_ECG_ENABLE__ + GU8 uchNeedSwitchToEcgCfg = 0; +#endif +#if __FUNC_TYPE_ECG_ENABLE__ + if(unFuncMode&GH3X2X_FUNCTION_LEAD_DET) + { + uchNeedSwitchToEcgCfg = 1; + } +#endif + +#if (__SUPPORT_HARD_ADT_CONFIG__) + if (GH3X2X_FUNCTION_ADT == unFuncMode) + { + unFuncModeTemp2 = unFuncMode; + } + else + { + unFuncModeTemp2 = unFuncMode & (~GH3X2X_FUNCTION_ADT); + } +#else + unFuncModeTemp2 = unFuncMode; +#endif + + unTargetFunMode = unFuncMode; +#if __FUNC_TYPE_ECG_ENABLE__ + if(uchNeedSwitchToEcgCfg) + { + unFuncModeTemp2 |= GH3X2X_FUNCTION_ECG; //add ecg function to demand function + unFuncModeTemp2 &= (~GH3X2X_FUNCTION_LEAD_DET); + unTargetFunMode |= GH3X2X_FUNCTION_ECG; + unTargetFunMode &= (~GH3X2X_FUNCTION_LEAD_DET); + } +#endif + + //decode functions in current reg config array + + unFuncModeTemp1 = GhDrvConfigManagerGetCurFunctionSupprort(); // get current function combination supported + //if this function not exist in current reg cfg array,need switch reg cfg array + if ( + ((unFuncModeTemp2 & unFuncModeTemp1) != unFuncModeTemp2) + #if __GH3X2X_CASCADE_EN__ + ||(0 == Gh3x2xCheckCfgValidForCascade(g_uchGh3x2xRegCfgArrIndex)) + #endif + ) + { + if (uchSwitchEnable) + { + GH3X2X_INFO_LOG("Cfg Error:Reg cfg file not exist!!!APP mode:0x%x\r\n",unFuncMode); + GH3X2X_INFO_LOG("Please check cfg switched manually is correct or not !!!\r\n"); + while(1); + } + else + { + chRet = GH3x2xDemoSearchCfgListByFunc(&uchIndex, unTargetFunMode, GH3X2X_FUNCTION_ADT); + if (GH3X2X_RET_OK == chRet) + { + #if (__SUPPORT_HARD_ADT_CONFIG__) + GU32 unDemoFuncModeBeforeReset = g_unDemoFuncMode; + EMWearDetectType uchWearDetectStatusBeforeReset = g_uchWearDetectStatus; + GH3X2X_INFO_LOG("unDemoFuncModeBeforeReset = %d\r\n",unDemoFuncModeBeforeReset); + #endif + Gh3x2xDemoSamplingControl(0xFFFFFFFF, UPROTOCOL_CMD_STOP); + + #if __SUPPORT_HARD_RESET_CONFIG__ + GH3X2X_HardReset(); + #else + GH3X2X_SoftReset(); + #endif + + Gh3x2x_BspDelayMs(15); + #if !(__GH3X2X_CASCADE_EN__) + #else + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_CascadeOperationMasterChip(); + #endif + g_uchGh3x2xRegCfgArrIndex = uchIndex; + if (GH3X2X_RET_OK != GH3X2X_Init(g_stGh3x2xCfgListArr+uchIndex)) + { + g_uchGh3x2xRegCfgArrIndex = DRV_LIB_REG_CFG_EMPTY; + } + + Gh3x2xFunctionCtrlModuleInit(); + + #if (__SUPPORT_HARD_ADT_CONFIG__) + //if ADT is running,recover ADT status + GH3X2X_INFO_LOG("temp unDemoFuncModeBeforeReset = %d\r\n",(unDemoFuncModeBeforeReset & GH3X2X_FUNCTION_ADT)); + if (GH3X2X_FUNCTION_ADT == (unDemoFuncModeBeforeReset & GH3X2X_FUNCTION_ADT)) + { + GH3X2X_INFO_LOG("g_uchWearDetectStatus = %d\r\n",g_uchWearDetectStatus); + g_uchWearDetectStatus = uchWearDetectStatusBeforeReset; + unFuncMode |= GH3X2X_FUNCTION_ADT; + GH3X2X_FunctionStart(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ADT]); + + #if (0 == __HARD_ADT_ALGO_CHECK_EN__) + if(WEAR_DETECT_WEAR_OFF == g_uchWearDetectStatus) + { + g_uchWearDetectStatus = WEAR_DETECT_WEAR_OFF; + GH3X2X_WearDetectSwitchTo(WEAR_DETECT_WEAR_OFF,WEAR_DETECT_FORCE_SWITCH); + } + #endif + } + #endif + + GH3X2X_EnterLowPowerMode(); + #if __GH3X2X_CASCADE_EN__ //need enter low power mode after chip reset(master and slave chip may all be reset) + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + #endif + } + else + { + GH3X2X_INFO_LOG("APP Mode Switch Error:Reg cfg file not exist!!!APP mode:0x%x\r\n",unFuncMode); + } + } + } + + //function slot bit init + Gh3x2xFunctionSlotBitInit(); + +#if (__SUPPORT_ENGINEERING_MODE__) + if(1 == g_uchEngineeringModeStatus) + { + #if (__GH3X2X_CASCADE_EN__) + if (GH3X2X_CascadeGetEcgEnFlag()) + { + + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_CascadeOperationMasterChip(); + } + #endif + GH3x2x_ChangeSampleParmForEngineeringMode(g_pstGh3x2xFrameInfo, unFuncMode, g_pstSampleParaGroup, g_uchEngineeringModeSampleParaGroupNum); + GH3X2X_EnterLowPowerMode(); + #if (__GH3X2X_CASCADE_EN__) + if (GH3X2X_CascadeGetEcgEnFlag()) + { + + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + } + #endif + } +#endif + Gh3x2xDemoSamplingControl(unFuncMode, UPROTOCOL_CMD_START); +} + + + + +void Gh3x2xDemoStartAlgoInner(GU32 unFuncMode) +{ +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + if(0 == GH3x2x_GetChipResetRecoveringFlag()) + { + GH3X2X_AlgoInit(unFuncMode); + #if __GH3X2X_MEM_POOL_CHECK_EN__ + Gh3x2xUpdataMemPollChkSumAfterAlgoCal(); + #endif + } +#endif + +#if __GH_MSG_WITH_ALGO_LAYER_EN__ + if(0 == GH3x2x_GetChipResetRecoveringFlag()) + { + GH3X2X_SEND_MSG_ALGO_START(unFuncMode); + + } +#endif +} + + +/** + * @fn void Gh3x2xDemoStartSampling() + * + * @brief Start sampling of GH3x2x + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStartSampling(GU32 unFuncMode) +{ + Gh3x2xDemoStartSamplingInner(unFuncMode, 0); + Gh3x2xDemoStartAlgoInner(unFuncMode); +} + +/** + * @fn void Gh3x2xDemoStartSamplingWithCfgSwitch(GU32 unFuncMode, GU8 uchArrayCfgIndex) + * + * @brief Start sampling of GH3x2x + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[in] uchArrayCfgIndex cfg id + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStartSamplingWithCfgSwitch(GU32 unFuncMode, GU8 uchArrayCfgIndex) +{ + if (uchArrayCfgIndex == DRV_LIB_REG_CFG_EMPTY) + { + GH3X2X_INFO_LOG("[%s]:Array None!!!\r\n", __FUNCTION__); + } + Gh3x2xDemoArrayCfgSwitch(uchArrayCfgIndex); + Gh3x2xDemoStartSamplingInner(unFuncMode, 1); + Gh3x2xDemoStartAlgoInner(unFuncMode); +} + + + + + +#if (__SUPPORT_ENGINEERING_MODE__) + +/** + * @fn void Gh3x2xDemoStartSamplingForEngineeringMode() + * + * @brief Start sampling of GH3x2x for engineering mode + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStartSamplingForEngineeringMode(GU32 unFuncMode, GU8 uchArrayCfgIndex, STGh3x2xEngineeringModeSampleParam *pstSampleParaGroup , GU8 uchSampleParaGroupNum) +{ + Gh3x2xDemoArrayCfgSwitch(uchArrayCfgIndex); + g_pstSampleParaGroup = pstSampleParaGroup; + g_uchEngineeringModeSampleParaGroupNum = uchSampleParaGroupNum; + g_uchEngineeringModeStatus = 1; + Gh3x2xDemoStartSamplingInner(unFuncMode, 1); +} +#else +void Gh3x2xDemoStartSamplingForEngineeringMode(GU32 unFuncMode, GU8 uchArrayCfgIndex, STGh3x2xEngineeringModeSampleParam *pstSampleParaGroup , GU8 uchSampleParaGroupNum){} +#endif + + + +/** + * @fn void Gh3x2xDemoStopSampling(GU32 unFuncMode) + * + * @brief Stop sampling of GH3x2x + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStopSamplingInner(GU32 unFuncMode) +{ + GH3X2X_INFO_LOG("[Gh3x2xDemoStopSampling] unFuncMode = 0x%X\r\n",(int)unFuncMode); + Gh3x2xDemoSamplingControl(unFuncMode, UPROTOCOL_CMD_STOP); +#if (__RESET_AGCINFO_BEFORE_SAMPLE__ && __SUPPORT_SOFT_AGC_CONFIG__) + if ((g_unDemoFuncMode & (~GH3X2X_FUNCTION_ADT)) == 0) + { + Gh3x2xDemoHardConfigReset(g_stGh3x2xCfgListArr + g_uchGh3x2xRegCfgArrIndex); + } +#endif +} + + +void Gh3x2xDemoStopAlgoInner(GU32 unFuncMode) +{ +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + if(0 == GH3x2x_GetChipResetRecoveringFlag()) + { + GH3X2X_AlgoDeinit(unFuncMode); + } +#endif + +#if __GH_MSG_WITH_ALGO_LAYER_EN__ + if(0 == GH3x2x_GetChipResetRecoveringFlag()) + { + GH3X2X_SEND_MSG_ALGO_STOP(unFuncMode); + } +#endif +} + + + + +void Gh3x2xDemoStopSampling(GU32 unFuncMode) +{ + Gh3x2xDemoStopSamplingInner(unFuncMode); + Gh3x2xDemoStopAlgoInner(unFuncMode); +} + + +#if 0 +void GH3X2X_RedetectWearOn(void) +{ + if (g_uchWearDetectStatus == WEAR_DETECT_WEAR_OFF) + { + GU16 usGotEvent = 0; + GH3X2X_INFO_LOG("[%s]switch to dectecting wear on\r\n", __FUNCTION__); + usGotEvent |= GH3X2X_IRQ_MSK_WEAR_OFF_BIT; + Gh3x2xDemoWearEventProcess(&usGotEvent,WEAR_DETECT_FORCE_SWITCH); + + #if __HARD_ADT_ALGO_CHECK_EN__ + GH3X2X_INFO_LOG("[%s]reset adt algo.\r\n", __FUNCTION__); + Gh3x2xDemoStopAlgoInner(GH3X2X_FUNCTION_ADT); + Gh3x2xDemoStartAlgoInner(GH3X2X_FUNCTION_ADT); + #endif + + + } + +} +#endif + + + +#if (__SUPPORT_ENGINEERING_MODE__) + +/** + * @fn void Gh3x2xDemoStopSamplingForEngineeringMode(void) + * + * @brief Stop sampling of GH3x2x for engineering mode + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStopSamplingForEngineeringMode(void) +{ + Gh3x2xDemoStopSamplingInner(g_unDemoFuncMode); + + Gh3x2xDemoSamplingControl(0xFFFFFFFF, UPROTOCOL_CMD_STOP); + + #if __SUPPORT_HARD_RESET_CONFIG__ + GH3X2X_HardReset(); + #else + GH3X2X_SoftReset(); + #endif + + Gh3x2x_BspDelayMs(15); + #if __GH3X2X_CASCADE_EN__ + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_CascadeOperationMasterChip(); + #endif + g_uchGh3x2xRegCfgArrIndex = 0; + if (GH3X2X_RET_OK != GH3X2X_Init(&g_stGh3x2xCfgListArr[0])) + { + g_uchGh3x2xRegCfgArrIndex = DRV_LIB_REG_CFG_EMPTY; + } + + GH3X2X_EnterLowPowerMode(); + #if __GH3X2X_CASCADE_EN__ + GH3X2X_CascadeOperationSlaverChip(); + GH3X2X_EnterLowPowerMode(); + GH3X2X_CascadeOperationMasterChip(); + #endif + + Gh3x2xFunctionCtrlModuleInit(); + + g_uchEngineeringModeStatus = 0; +} +#endif + + +/** + * @fn void Gh3x2xDemoMoveDetectTimerHandler(GU32 unTimeIntervalMs) + * + * @brief Move detect timer handler callback + * + * @attention if use adt with confirm mode,must call this function to detect movement + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoMoveDetectTimerHandler(GU32 unTimeIntervalMs) +{ + GH3X2X_INFO_LOG("Gh3x2xDemoMoveDetectTimerHandler.\r\n"); + #if (__GSENSOE_MOVE_DETECT_SUPPORT__) + //check CAP + #if (__CAP_ENABLE__) + hal_cap_drv_get_fifo_data(cap_soft_fifo_buffer, &cap_soft_fifo_buffer_index); + #endif + GH3X2X_MoveDetectByCapData(cap_soft_fifo_buffer, cap_soft_fifo_buffer_index); + //check GS + hal_gsensor_drv_get_fifo_data(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__, &gsensor_soft_fifo_buffer_index); + Gh3x2x_NormalizeGsensorSensitivity(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__,gsensor_soft_fifo_buffer_index); + GhMoveDetectByGsData((GS16*)(gsensor_soft_fifo_buffer + __GS_EXTRA_BUF_LEN__), gsensor_soft_fifo_buffer_index); +#endif +} + +/** + * @fn void Gh3x2xDemoSetFuncionFrequency(GU8 uchFunctionID, GU16 usFrequencyValue) + * + * @brief Set function frequency + * + * @attention None + * + * @param[in] uchFunctionID + * @param[in] usFrequencyValue + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoSetFuncionFrequency(GU8 uchFunctionID, GU16 usFrequencyValue) +{ + GU32 unFuncModeTemp = 0; + + GH3X2X_DecodeRegCfgArr(&unFuncModeTemp, (g_stGh3x2xCfgListArr + g_uchGh3x2xRegCfgArrIndex)->pstRegConfigArr, \ + (g_stGh3x2xCfgListArr + g_uchGh3x2xRegCfgArrIndex)->usConfigArrLen); + + if (((1 << uchFunctionID) & unFuncModeTemp) == 0) + { + GH3X2X_INFO_LOG("[%s]:Current cfg cannot support !!! cfgfunc = 0x%x, selectfuncs = 0x%x\r\n", __FUNCTION__, (int)unFuncModeTemp, (1 << uchFunctionID)); + return; + } + + if (usFrequencyValue % 25 || usFrequencyValue > 1000) + { + GH3X2X_INFO_LOG("[%s]:The SR is not a multiple of 25!!!srvalue = %d\r\n", __FUNCTION__, usFrequencyValue); + return; + } + + GU32 unDemoFuncModeBeforeChipReset = g_unDemoFuncMode; + + if (unDemoFuncModeBeforeChipReset != 0) + { + Gh3x2xDemoStopSampling(unDemoFuncModeBeforeChipReset); + GH3X2X_INFO_LOG("[%s]:Stop.\r\n", __FUNCTION__); + Gh3x2x_BspDelayMs(30); + } + + GH3X2X_ModifyFunctionFrequency(uchFunctionID, usFrequencyValue); + GH3X2X_INFO_LOG("[%s]:Change fs !!! func = 0x%x, fs = %d\r\n", __FUNCTION__, (1 << uchFunctionID), usFrequencyValue); + + if (unDemoFuncModeBeforeChipReset != 0) + { + Gh3x2x_BspDelayMs(30); + Gh3x2xDemoStartSampling(unDemoFuncModeBeforeChipReset); + GH3X2X_INFO_LOG("[%s]:Restart.\r\n", __FUNCTION__); + } +} + +/** + * @fn void Gh3x2xDemoSetFuncionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current) + * + * @brief Set function led current + * + * @attention None + * + * @param[in] uchFunctionID function offset + * @param[in] usLedDrv0Current 0mA-200mA + * @param[in] usLedDrv1Current 0mA-200mA + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoSetFuncionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current) +{ + GU32 unFuncModeTemp = 0; + + GH3X2X_DecodeRegCfgArr(&unFuncModeTemp, (g_stGh3x2xCfgListArr + g_uchGh3x2xRegCfgArrIndex)->pstRegConfigArr, \ + (g_stGh3x2xCfgListArr + g_uchGh3x2xRegCfgArrIndex)->usConfigArrLen); + + if (((1 << uchFunctionID) & unFuncModeTemp) == 0) + { + GH3X2X_INFO_LOG("[%s]:Current cfg cannot support !!! cfgfunc = 0x%x, selectfuncs = 0x%x\r\n", __FUNCTION__, (int)unFuncModeTemp, (1 << uchFunctionID)); + return; + } + + GH3X2X_ModifyFunctionLedCurrent(uchFunctionID, usLedDrv0Current, usLedDrv1Current); + GH3X2X_INFO_LOG("[%s]:Change led current !!! func = 0x%x, drv0 current = %d, drv1 current = %d\r\n", __FUNCTION__, (1 << uchFunctionID), (int)usLedDrv0Current, (int)usLedDrv1Current); +} + + +#if (__SUPPORT_ELECTRODE_WEAR_STATUS_DUMP__) +void GH3X2X_ReadElectrodeWearDumpData(void) +{ + g_uchGh3x2xElectrodeWearStatus = GH3X2X_ReadRegBitField(0x050C, 1, 1); +} +#endif + +void Gh3x2xSetFrameFlag2(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + if(0 == (*(pstFrameInfo->punFrameCnt))) + { + pstFrameInfo->punFrameFlag[2] |= 0x02; + } + #if (__SUPPORT_ELECTRODE_WEAR_STATUS_DUMP__) + if(g_uchGh3x2xElectrodeWearStatus) + { + pstFrameInfo->punFrameFlag[2] |= 0x04; + } + #endif +} + + +void Gh3x2xIntPinTriggerModePro(void) +{ +#if (!(__NORMAL_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__ || __MIX_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__)) + GH3X2X_WriteReg(0x0502,0); //disable INT +#endif + GH3X2X_WriteRegBitField(0x0000,10, 10, 0); //rg_int_pwrup = 0:do not chip auto wake-up before int pin trigger +} + + +void GH3x2xSlotTimeInfo(void) +{ +#if 1 == __SLOT_SEQUENCE_DYNAMIC_ADJUST_EN__ + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + GU8 uchCfgIndex; + //get slot time infomation + if(0 == (uchSlotCnt&0x01)) //0,2,4,6 + { + uchCfgIndex = GH3X2X_ReadRegBitField(0x0100 + (uchSlotCnt&0xFE), 0,3); + } + else //1,3,5,7 + { + uchCfgIndex = GH3X2X_ReadRegBitField(0x0100 + (uchSlotCnt&0xFE), 8,11); + } + if(uchCfgIndex < 8) + { + g_usGh3x2xSlotTime[uchCfgIndex] = GH3X2X_ReadReg(0x01EC + uchCfgIndex *2); + GH3X2X_INFO_LOG("[%s]:CfgIndex[%d]:Slot time = %d\r\n", __FUNCTION__, uchCfgIndex, g_usGh3x2xSlotTime[uchCfgIndex]); + } + } +#endif +} + +#if (__GH3X2X_CASCADE_EN__) +GS8 Gh3x2xEcgCascadeCommunicationTest(void) +{ + GS8 chRet = GH3X2X_RET_OK; + GH3X2X_CascadeOperationMasterChip(); + GU16 usChipReadyCode = GH3X2X_ReadReg(0x36); + if (0xaa55 == usChipReadyCode) + { + GH3X2X_INFO_LOG("Master Communication success!!! 0x36:0x%04x\r\n",usChipReadyCode); + } + else + { + GH3X2X_INFO_LOG("Master Communication FAIL!!! 0x36:0x%04x\r\n",usChipReadyCode); + chRet = GH3X2X_RET_COMM_ERROR; + } + + + GH3X2X_CascadeOperationSlaverChip(); + usChipReadyCode = GH3X2X_ReadReg(0x36); + if (0xaa55 == usChipReadyCode) + { + GH3X2X_INFO_LOG("Slaver Communication success!!! 0x36:0x%04x\r\n",usChipReadyCode); + } + else + { + GH3X2X_INFO_LOG("Slaver Communication FAIL!!! 0x36:0x%04x\r\n",usChipReadyCode); + chRet = GH3X2X_RET_COMM_ERROR; + } + GH3X2X_CascadeOperationMasterChip(); + + return chRet; + +} + +#endif + + + +// void gh3x2x_control(char* mode, uint8_t enable) +// { + +// uint32_t md = 1; +// if (strcmp(mode, "hrs") == 0) { +// md = 0; +// } else if (strcmp(mode, "hrv") == 0) { +// md = 1; +// } else if (strcmp(mode, "spo2") == 0) { +// md = 2; +// } else if (strcmp(mode, "leaklight") == 0) { +// md = 4; +// } else if (strcmp(mode, "graycard") == 0) { +// md = 8; +// } else if (strcmp(mode, "ledoff") == 0) { +// md = 16; +// } else if (strcmp(mode, "wear") == 0) { +// md = 32; +// } else if (strcmp(mode, "single") == 0) { +// md = 64; +// }else if (strcmp(mode, "factory") == 0) { +// md = 128; +// }else if (strcmp(mode, "fpc") == 0) { +// // md = WORK_MODE_UNDEFINED; +// }else if (strcmp(mode, "int") == 0) { +// } + +// if (enable == 1) +// { +// // ppg_service_running_stat = true; +// // uapi_pm_control(PM_APP_WAKE_NEEDED); +// // GH3X2X_AFE_StartFunction(mode); +// // GH3X2X_AFE_Init(); +// // GH3X2X_AFE_StartSampling(1); +// } else { + +// // uapi_pm_control(PM_APP_WAKE_NONEED); +// // GH3X2X_AFE_StopSampling(); +// } +// } + +// /********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo.h new file mode 100644 index 000000000..c7d766850 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo.h @@ -0,0 +1,265 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x_demo.h + * + * @brief header file of gh3x2x driver lib demo + * + * @version GH(M)3X2X_DRV_LIB_DEMO_1.0 + * + * @author Gooidx Iot Team + * + */ + + +#ifndef _GH_DEMO_H_ +#define _GH_DEMO_H_ + +#include "gh_drv.h" + +#include "gh_multi_sen_pro.h" + +/** + * @fn int Gh3x2xDemoInit(void) + * + * @brief Init GH3x2x module. + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +int Gh3x2xDemoInit(void); + +/** + * @fn GU8 Gh3x2xDemoInterruptProcess(void) + * + * @brief Interrupt process of GH3x2x. + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoInterruptProcess(void); + +/** + * @fn void hal_gh3x2x_int_handler_call_back(void) + * + * @brief call back of gh3x2x int handler + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void hal_gh3x2x_int_handler_call_back(void); + +/** + * @fn GS8 Gh3x2xDemoArrayCfgSwitch(GU8 uchArrayCfgIndex) + * + * @brief array cfg switch (call by user) + * + * @attention you should switch array cfg manually before calling Gh3x2xDemoStartSampling + * + * @param[in] uchArrayCfgIndex 0: gh3x2x_reg_list0 1: gh3x2x_reg_list0 ... + * @param[out] None + * + * @return GH3X2X_RET_OK:switch application mode success + * @return GH3X2X_RET_RESOURCE_ERROR:can't find corresponding reg config array + */ +GS8 Gh3x2xDemoArrayCfgSwitch(GU8 uchArrayCfgIndex); + + +/** + * @fn void Gh3x2xDemoStartSamplingWithCfgSwitch(GU32 unFuncMode, GU8 uchArrayCfgIndex) + * + * @brief Start sampling of GH3x2x + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[in] uchArrayCfgIndex cfg id + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStartSamplingWithCfgSwitch(GU32 unFuncMode, GU8 uchArrayCfgIndex); + +/** + * @fn void Gh3x2xDemoStartSampling() + * + * @brief Start sampling of GH3x2x + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStartSampling(GU32 unFuncMode); + +/** + * @fn void Gh3x2xDemoStartSamplingForEngineeringMode() + * + * @brief Start sampling of GH3x2x for engineering mode + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStartSamplingForEngineeringMode(GU32 unFuncMode, GU8 uchArrayCfgIndex, STGh3x2xEngineeringModeSampleParam *pstSampleParaGroup , GU8 uchSampleParaGroupNum); + + +/** + * @fn void Gh3x2xDemoStopSampling(GU32 unFuncMode) + * + * @brief Stop sampling of GH3x2x + * + * @attention None + * + * @param[in] unFuncMode function mode that will start + * GH3X2X_FUNCTION_ADT/GH3X2X_FUNCTION_HR/GH3X2X_FUNCTION_SPO2/GH3X2X_FUNCTION_ECG and etc. + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStopSampling(GU32 unFuncMode); + + + +/** + * @fn void Gh3x2xDemoStopSamplingForEngineeringMode(void) + * + * @brief Stop sampling of GH3x2x for engineering mode + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoStopSamplingForEngineeringMode(void); + + + +/** + * @fn void Gh3x2x_CreateMoveDetTimer(void) + * + * @brief Create a timer for adt confirm which will read gsensor data periodically + * + * @attention Period of timer can be set by + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2xCreateMoveDetTimer(void); + + + +/** + * @fn void Gh3x2xDemoProtocolProcess(GU8* puchProtocolDataBuffer, GU16 usRecvLen) + * + * @brief Analyze protocol about GH3x2x,and pack protocol data to reply + * + * @attention None + * + * @param[in] puchProtocolDataBuffer pointer to received protocol data buffer + * @param[in] usRecvLen protocol data buffer length + * + * @return None + */ +void Gh3x2xDemoProtocolProcess(GU8* puchProtocolDataBuffer, GU16 usRecvLen); + +/** + * @fn void Gh3x2xDemoFunctionSampleRateSet(GU32 unFunctionID, GU16 usSampleRate) + * + * @brief + * + * @attention None + * + * @param[in] unFunctionID such as: GH3X2X_FUNCTION_HR or GH3X2X_FUNCTION_HR|GH3X2X_FUNCTION_HRV + * @param[in] usSampleRate only 25Hz times supported (25/50/75...) + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoFunctionSampleRateSet(GU32 unFunctionID, GU16 usSampleRate); + + + + +/** + * @fn void Gh3x2xDemoSetFuncionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current) + * + * @brief Set function led current + * + * @attention None + * + * @param[in] uchFunctionID function offset + * @param[in] usLedDrv0Current 0mA-200mA + * @param[in] usLedDrv1Current 0mA-200mA + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoSetFuncionLedCurrent(GU8 uchFunctionID, GU16 usLedDrv0Current, GU16 usLedDrv1Current); + + +/** + * @fn void Gh3x2xDemoFunctionChannelEnSet(GU32 unFunctionID, GU32 unChnlEn) + * + * @brief + * + * @attention None + * + * @param[in] unFunctionID such as: GH3X2X_FUNCTION_HR or GH3X2X_FUNCTION_HR|GH3X2X_FUNCTION_HRV + * @param[in] unChnlEn BitN = 0: channel N is disable BitN = 1: channel N is enable + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoFunctionChannelEnSet(GU32 unFunctionID, GU32 unChnlEn); + +/** + * @fn void Gh3x2xInterruptModeSwitch(EMInterruptModeType emIntModeType) + * + * @brief change Interrupt process mode of GH3x2x. + * + * @attention do not input 2 + * + * @param[in] emIntModeType 0:int pin 1: polling + * @param[out] None + * + * @return None + */ +void Gh3x2xInterruptModeSwitch(GU8 uchIntModeType); +GU8 Gh3x2xGetInterruptMode(void); +void Gh3x2xSerialSendTimerHandle(void); + +// void gh3x2x_control(char* mode, uint8_t enable); + + +#if (__GH3X2X_CASCADE_EN__) +GS8 Gh3x2xEcgCascadeCommunicationTest(void); +#endif + +#endif /* _GH_DEMO_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_config.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_config.h new file mode 100644 index 000000000..a6ede66ee --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_config.h @@ -0,0 +1,366 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh_demo_config.h + * + * @brief gh3x2x driver lib demo configuration file + * + * @author Gooidx Iot Team + * + */ +#ifndef _GH_DEMO_CONFIG_H_ +#define _GH_DEMO_CONFIG_H_ +#include "gh_drv.h" +#include "stdio.h" + + +/* bsp config */ +/**< interface config __GH3X2X_INTERFACE_I2C__ /__GH3X2X_INTERFACE_SPI__ */ +// #define __GH3X2X_INTERFACE__ (__GH3X2X_INTERFACE_SPI__) +#define __GH3X2X_INTERFACE__ (__GH3X2X_INTERFACE_I2C__) +#if(__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_SPI__) +#define __GH3X2X_SPI_TYPE__ (__GH3X2X_SPI_TYPE_SOFTWARE_CS__) +#endif +#if(__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__) +#define __GH3X2X_I2C_DEVICE_ID__ (GH3X2X_I2C_ID_SEL_1L0L) +#endif +#define __GS_SENSITIVITY_CONFIG__ (GSENSOR_SENSITIVITY_512_COUNTS_PER_G) /**< gsensor sensitivity config */ +#define __GS_GYRO_ENABLE__ (0) /*Gyro enable*/ +#define __GS_NONSYNC_READ_EN__ (0) +#if __GS_NONSYNC_READ_EN__ +#define __GS_SAMPLE_RATE_HZ__ (25) /*gsenor sample rate(Hz)*/ +#define __GS_READ_POINT_NUM__ (6) /* host read gsensor sample num in one time */ +#define __GS_READ_POINT_NUM_JITTER__ (3) /* host read gsensor sample num jitter */ +#endif + +#define __CAP_ENABLE__ (0) /*Cap enable*/ +#define __TEMP_ENABLE__ (0) /*Temperature sensor enable*/ + +#define __SUPPORT_HARD_RESET_CONFIG__ (1) /**< support hard reset config */ +#define __INTERRUPT_PROCESS_MODE__ (__NORMAL_INT_PROCESS_MODE__) /**< 2:polling+int 1:use polling 0:use interrupt */ +#define __PLATFORM_WITHOUT_OS__ (0) /**< 1:not use os 0:use os */ +#define __PASS_THROUGH_MODE__ (0) +#define __GH3X2X_MP_MODE__ (0) /**< 1:enable mp mode 0:unable mp mode */ +#define __GH3X2X_CASCADE_EN__ (0) /** dual-ecg function enable **/ +#if (__GH3X2X_CASCADE_EN__ && __GH3X2X_INTERFACE_I2C__) +#define __GH3X2X_I2C_DEVICE_SLAVER_ID__ (GH3X2X_I2C_ID_SEL_1H0L) +#endif +#define __GH3X2X_ECG_RTYPE_5M__ (0) +#define __RESET_AGCINFO_BEFORE_SAMPLE__ (0) +#define __CURRENT_ECODE_CALIBRATE__ (0) + +/* app config */ +#define __USER_DYNAMIC_DRV_BUF_EN__ (0) /*get rawdata buf via malloc*/ +#define __DRIVER_LIB_MODE__ (__DRV_LIB_WITH_ALGO__) +#define __DRIVER_OPEN_ALL_SOURCE__ (0) //0: do not open all driver source(this mode can support goodix algorithm) 1: open all driver source (this mode may can NOT support goodix algorithm) +#define __FUNC_RUN_SIMULTANEOUSLY_SUPPORT__ (1) +#define __GH_MSG_WITH_ALGO_LAYER_EN__ (0) /** enable message with algorithm send/recive process **/ + +/* ppg function type */ +#define __FUNC_TYPE_HR_ENABLE__ (1) /**< hb function tye */ +#define __FUNC_TYPE_HRV_ENABLE__ (1) /**< hrv function tye */ +#define __FUNC_TYPE_HSM_ENABLE__ (1) /**< hsm function tye */ +#define __FUNC_TYPE_SPO2_ENABLE__ (1) /**< spo2 function tye */ +#define __FUNC_TYPE_BT_ENABLE__ (1) /**< bt function tye */ +#define __FUNC_TYPE_RESP_ENABLE__ (1) /**< resp function tye */ +#define __FUNC_TYPE_AF_ENABLE__ (1) /**< af function tye */ +#define __FUNC_TYPE_TEST_ENABLE__ (1) /**< test function tye */ +#define __SUPPORT_HARD_ADT_CONFIG__ (1) /**< support hard adt config */ +#define __FUNC_TYPE_SOFT_ADT_ENABLE__ (1) /**< support soft adt config */ +#define __SUPPORT_SOFT_AGC_CONFIG__ (1) /**< support soft agc config */ + +#define __HARD_ADT_ALGO_CHECK_EN__ (0) //0: do not use algo to replace hard adt module in chip 1: use algo to replace hard adt mudule in chip +#define __ADT_ONLY_PARTICULAR_WM_CONFIG__ (5) //0: Do not set particular watermark at openning function is ADT only N (N>3&&N<800): set particular watermark, and this value is N at openning function is ADT only + +/* ecg function type */ +#define __FUNC_TYPE_ECG_ENABLE__ (1) /**< ecg algorithm tye */ +#if __FUNC_TYPE_ECG_ENABLE__ +#define __FUNC_TYPE_PWTT_ENABLE__ (1) /**< pwtt algorithm tye */ +#define __FUNC_TYPE_BP_ENABLE__ (0) /**< bp algorithm tye */ +#define __SUPPORT_ECG_LEAD_OFF_DET_800HZ__ (1) +#define GH3X2X_ECG_DOWNSAMP_CHNL_NUM (1) /**< ECG downsample chn number */ + +#if ( __FUNC_TYPE_HR_ENABLE__) +#define __SUPPORT_PPG_DOWNSAMP__ (1) /**< PPG downsample algorithm tye */ +#define GH3X2X_PPG_DOWNSAMP_CHNL_NUM (1) /**< PPG downsample chn number */ +#endif +#endif + +/*lead off parameters setting*/ +#define LEADOFF_DET_IQ_AMP_THR_uV (1500) +#define LEADOFF_DET_IQ_AMP_DIFF_THR_uV (1000) +#define LEADOFF_DET_IQ_VAL_THR_mV (80) + +/* config about mult-sensor event process*/ +#define __GH_MULTI_SENSOR_EVENT_PRO_CONIG__ (1) /**0: no support multi-sensor event process 1: support multi-sensor event process*/ +#define __GH_MULTI_SENSOR_TIMER_PERIOD_MS__ (1000) /** period of multi-sensor timer, unit: ms*/ +#define __GH_MULTI_SENSOR_WEAR_EXAMPLE_EN__ (0) /** this is example for using multi-senosr process to check wear on, you can set 1 to enable this example process*/ + +/* config about g-sensor move detection */ +#define __GSENSOE_MOVE_DETECT_SUPPORT__ (1) /**0: no NOT support move detection 1: support move detection*/ +#define __GSENSOR_MOVE_THRESHOLD__ (65) /**< DIFF of sqrt(x^2+y^2+z^2) */ +#define __GSENSOR_MOVE_CNT_THRESHOLD__ (1) /**< (recomended value = 1) more than how many times of movement can be judged as effective moveing*/ +#define __GSENSOR_NOT_MOVE_CNT_THRESHOLD__ (150) /**< (recommended value = 1.5 * sample rate of g-sensor ) more than how many times of movement can be judged as effective non-moveing*/ +#define __GSENSOR_MOVE_TIME_OUT_THRESHOLD_MS__ (5000) /**range 1~5000, the time of not move > __GSENSOR_MOVE_TIME_OUT_THRESHOLD_MS__, event : GH3X2X_MULTI_SENSOR_EVENT_GS_MOVE_TIME_OUT will be generated*/ + +/*sofe agc config*/ +#if __SUPPORT_SOFT_AGC_CONFIG__ +#define GH3X2X_NEW_AGC_SLOT_NUM_LIMIT (8u) +#define GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT (32u) +#endif + +/* marco of divide zero flag enable*/ +#define GH3X2X_DIVIDE_ZERO_FLAG_UPLODE_EN (1) + +/*sample config*/ +#define __SLOT_SEQUENCE_DYNAMIC_ADJUST_EN__ (1) + +/*debug config*/ +#define __SUPPORT_PROTOCOL_ANALYZE__ (1) /**< driver lib support protocol analyze */ +#if (__SUPPORT_PROTOCOL_ANALYZE__) +#define __UPLOAD_ALGO_RESULT__ (1) /**< upload algorithm result or not */ +#define __PROTOCOL_SERIAL_TYPE__ (__PROTOCOL_SERIAL_USE_BLE__) /**< protocol communicate serial port type */ +#define __SUPPORT_ZIP_PROTOCOL__ (1) +#define __FIFO_PACKAGE_SEND_ENABLE__ (0) /** 1: fifo package send mode enable 0: cannot open fifo package send mode */ +#define __GH3X2X_PROTOCOL_SEND_TIMER_PERIOD__ (10) /** (unit : ms ) protocal data send timer period */ +#define __GH3X2X_PROTOCOL_DATA_FIFO_LEN__ (64) /** protocal data send fifo length **/ +#define __GH3X2X_PROTOCOL_EVENT_FIFO_LEN__ (16) /** protocal event send fifo length **/ +#define __GH3X2X_PROTOCOL_EVENT_WAITING_ACK_TIME__ (500) /** (unit : ms ) protocal data waiting ack time, if time out, we will resend */ +#define __GH3X2X_PROTOCOL_EVENT_RESEND_NUM__ (255) /***** 0~255 protocal resend num (255: evenlasting resending) */ +#define __GH3X2X_PROTOCOL_DATA_FUNCTION_INTERCEPT__ (GH3X2X_NO_FUNCTION) /* GH3X2X_NO_FUNCTION: none function date will be intercepted (GH3X2X_FUNCTION_HR|GH3X2X_FUNCTION_HRV): HR and HRV function data will be intercepted, those data will not output via protocal */ +#endif +#define __SUPPORT_SAMPLE_DEBUG_MODE__ (0) /**< use sample debug mode */ +#define __SUPPORT_ELECTRODE_WEAR_STATUS_DUMP__ (1) /** use electrode wear status dump */ +#define __GH3X2X_INFO_LOG_TYPE__ (__GH3X2X_INFO_LOG_METHOD_0__) /**< example log config */ +#define __GH3X2X_INFO_LOG_LEVEL__ (__GH3X2X_INFO_LOG_LV_1__ |__GH3X2X_INFO_LOG_LV_2__) /**< example log config */ +#define GH3X2X_INFO_LOG_MAX_LEN (180) +#define __SUPPORT_ENGINEERING_MODE__ (1) /**< enginerring mode*/ +#define __GH3X2X_MEM_POOL_CHECK_EN__ (0) /** 1: drv lib checks algo mem pool befor every time of algo calculating 0: do not check **/ + +/* operate config */ +#define __SUPPORT_FUNCTION_SAMPLE_RATE_MODIFY__ (0) /** 0: only use default sample rate in array cfg 1: modifying function sample rate is supported via API: Gh3x2xDemoFunctionSampleRateSet */ + +/*config list*/ +#define __GH3X2X_CFG_LIST_MAX_NUM__ (8) /**< max num of config list(1 ~ 8) */ + +/* other config */ +#define __SUPPORT_HOOK_FUNC_CONFIG__ (1) /**< support hook func config */ +#define __SUPPORT_ALGO_INPUT_OUTPUT_DATA_HOOK_CONFIG__ (1) /**< enable it ,we can get algo input and output data **/ + +/* gh3x2x data buffer size config,this is related to gh3x2x fifo water mark config */ +#define __GH3X2X_RAWDATA_BUFFER_SIZE__ (100 * 4) /**< rawdata buffer size in byte */ +#define __GH3X2X_RAWDATA_SLAVE_BUFFER_SIZE__ (1 * 4) /**< rawdata buffer size in byte for slave chip*/ + +/* gsensor data buffer size config,every g sensor data has 6 bytes(x,y,z) */ +#define __GSENSOR_DATA_BUFFER_SIZE__ (100) /**< max num of gsensor data */ + +#define __CAP_DATA_BUFFER_SIZE__ (100) /**< max num of CAP data */ +#define __TEMP_DATA_BUFFER_SIZE__ (100) /**< max num of TEMP data */ + +/* function channel nunber config*/ +#define GH3X2X_ADT_CHNL_NUM (8) /**< ADT function channel num */ +#define GH3X2X_HR_CHNL_NUM (32) /**< HR function channel num */ +#define GH3X2X_HRV_CHNL_NUM (16) /**< HRV function channel num */ +#define GH3X2X_HSM_CHNL_NUM (16) /**< HSM function channel num */ +#define GH3X2X_BP_CHNL_NUM (16) /**< BP function channel num */ +#define GH3X2X_PWA_CHNL_NUM (16) /**< PWA function channel num */ +#define GH3X2X_SPO2_CHNL_NUM (32) /**< SPO2 function channel num */ +#define GH3X2X_ECG_CHNL_NUM (8) /**< ECG function channel num */ +#define GH3X2X_PWTT_CHNL_NUM (32) /**< PWTT function channel num */ +#define GH3X2X_SOFT_ADT_CHNL_NUM (16) /**< soft adt function channel num */ +#define GH3X2X_BT_CHNL_NUM (16) /**< BT function channel num */ +#define GH3X2X_RESP_CHNL_NUM (16) /**< RESP function channel num */ +#define GH3X2X_AF_CHNL_NUM (16) /**< AF function channel num */ +#define GH3X2X_TEST_CHNL_NUM (16) /**< TEST1 function channel num */ + +/*fifo monitor*/ +#define GH3X2X_FIFO_MONITOR_EN (1) +#define GH3X2X_FIFO_MONITOR_DECIMATION_SUPPORT (0) + + + +#define GH3X2X_SEND_MSG_ALGO_CFG_INIT(g_pstGh3x2xFrameInfo, g_uchGh3x2xRegCfgArrIndex) //add your code to send message to algorithm layer +#define GH3X2X_SEND_MSG_ALGO_START(unFuncMode) //add your code to send message to algorithm layer +#define GH3X2X_SEND_MSG_ALGO_STOP(unFuncMode) //add your code to send message to algorithm layer +#define GH3X2X_SEND_MSG_ALGO_CAL(unFunctionID) //add your code to send message to algorithm layer +#define GH3X2X_PRO_MSG_SOFT_WEAR_EVEVT() // if got soft wear event, GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF/GH3X2X_SOFT_EVENT_WEAR_ON) + + + + +/*********************************** DO NOT MODIFY FOLLOWING CODE *******************************/ +/* log def*/ +#if (__GH3X2X_INFO_LOG_LEVEL__ > __GH3X2X_INFO_LOG_LV_0__) +#if (__GH3X2X_INFO_LOG_LEVEL__ & __GH3X2X_INFO_LOG_LV_1__) +#define GH3X2X_INFO_LOG(...) do{\ + if(g_pSnprintfUserIn)\ + {\ + char gh3x2x_GH3X2X_INFO_LOG[GH3X2X_INFO_LOG_MAX_LEN] = {0};\ + g_pSnprintfUserIn(gh3x2x_GH3X2X_INFO_LOG, GH3X2X_INFO_LOG_MAX_LEN, "[LOG_I] " __VA_ARGS__);\ + GH3X2X_PlatformLog((GCHAR *)gh3x2x_GH3X2X_INFO_LOG);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn("[LOG_I] " __VA_ARGS__);\ + } while(0) +#else +#define GH3X2X_INFO_LOG(...) +#endif + +#if (__GH3X2X_INFO_LOG_LEVEL__ & __GH3X2X_INFO_LOG_LV_2__) +#define GH3X2X_DEBUG_LOG(...) do{\ + if(g_pSnprintfUserIn)\ + {\ + char gh3x2x_GH3X2X_INFO_LOG[GH3X2X_INFO_LOG_MAX_LEN] = {0};\ + g_pSnprintfUserIn(gh3x2x_GH3X2X_INFO_LOG, GH3X2X_INFO_LOG_MAX_LEN, "[LOG_D] " __VA_ARGS__);\ + GH3X2X_PlatformLog((GCHAR *)gh3x2x_GH3X2X_INFO_LOG);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn("[LOG_D] " __VA_ARGS__);\ + } while(0) +#else +#define GH3X2X_DEBUG_LOG(...) +#endif + +#if (__GH3X2X_INFO_LOG_LEVEL__ & __GH3X2X_INFO_LOG_LV_3__) +#define GH3X2X_WARNING_LOG(...) do{\ + if(g_pSnprintfUserIn)\ + {\ + char gh3x2x_GH3X2X_INFO_LOG[GH3X2X_INFO_LOG_MAX_LEN] = {0};\ + g_pSnprintfUserIn(gh3x2x_GH3X2X_INFO_LOG, GH3X2X_INFO_LOG_MAX_LEN, "[LOG_W] " __VA_ARGS__);\ + GH3X2X_PlatformLog((GCHAR *)gh3x2x_GH3X2X_INFO_LOG);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn("[LOG_W] " __VA_ARGS__);\ + } while(0) +#else +#define GH3X2X_WARNING_LOG(...) +#endif + +#if (__GH3X2X_INFO_LOG_LEVEL__ & __GH3X2X_INFO_LOG_LV_4__) +#define GH3X2X_ERROR_LOG(...) do{\ + if(g_pSnprintfUserIn)\ + {\ + char gh3x2x_GH3X2X_INFO_LOG[GH3X2X_INFO_LOG_MAX_LEN] = {0};\ + g_pSnprintfUserIn(gh3x2x_GH3X2X_INFO_LOG, GH3X2X_INFO_LOG_MAX_LEN,"[LOG_E] " __VA_ARGS__);\ + GH3X2X_PlatformLog((GCHAR *)gh3x2x_GH3X2X_INFO_LOG);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn("[LOG_E] " __VA_ARGS__);\ + } while(0) +#else +#define GH3X2X_ERROR_LOG(...) +#endif + +#else +#define GH3X2X_INFO_LOG(...) +#define GH3X2X_ERROR_LOG(...) +#define GH3X2X_DEBUG_LOG(...) +#define GH3X2X_WARNING_LOG(...) +#endif + + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) +#define __GH3X2X_MEM_POOL_CHECK_EN__ (0) +#endif + +#ifndef __FUNC_TYPE_SOFT_ADT_ENABLE__ +#define __FUNC_TYPE_SOFT_ADT_ENABLE__ (0) +#endif + + +#if __FUNC_TYPE_ECG_ENABLE__ == 0 +#define __FUNC_TYPE_PWTT_ENABLE__ (0) /**< pwtt algorithm tye */ +#define __FUNC_TYPE_BP_ENABLE__ (0) /**< bp algorithm tye */ +#define __SUPPORT_ECG_LEAD_OFF_DET_800HZ__ (0) +#endif + +#if(__GH3X2X_INTERFACE__ != __GH3X2X_INTERFACE_SPI__) +#define __GH3X2X_SPI_TYPE__ (__GH3X2X_SPI_TYPE_SOFTWARE_CS__) +#endif +#if(__GH3X2X_INTERFACE__ != __GH3X2X_INTERFACE_I2C__) +#define __GH3X2X_I2C_DEVICE_ID__ (GH3X2X_I2C_ID_SEL_1L0L) +#endif + +#ifdef GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_MAIN_FUNC_CHNL_NUM +#endif +#define GH3X2X_MAIN_FUNC_CHNL_NUM 1 +#if __SUPPORT_HARD_ADT_CONFIG__ +#if GH3X2X_ADT_CHNL_NUM > GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_MAIN_FUNC_CHNL_NUM +#define GH3X2X_MAIN_FUNC_CHNL_NUM GH3X2X_ADT_CHNL_NUM +#endif +#endif +#if __FUNC_TYPE_HR_ENABLE__ +#if GH3X2X_HR_CHNL_NUM > GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_MAIN_FUNC_CHNL_NUM +#define GH3X2X_MAIN_FUNC_CHNL_NUM GH3X2X_HR_CHNL_NUM +#endif +#endif +#if __FUNC_TYPE_HRV_ENABLE__ +#if GH3X2X_HRV_CHNL_NUM > GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_MAIN_FUNC_CHNL_NUM +#define GH3X2X_MAIN_FUNC_CHNL_NUM GH3X2X_HRV_CHNL_NUM +#endif +#endif +#if __FUNC_TYPE_SPO2_ENABLE__ +#if GH3X2X_SPO2_CHNL_NUM > GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_MAIN_FUNC_CHNL_NUM +#define GH3X2X_MAIN_FUNC_CHNL_NUM GH3X2X_SPO2_CHNL_NUM +#endif +#endif +#if __FUNC_TYPE_ECG_ENABLE__ +#if GH3X2X_ECG_CHNL_NUM > GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_MAIN_FUNC_CHNL_NUM +#define GH3X2X_MAIN_FUNC_CHNL_NUM GH3X2X_ECG_CHNL_NUM +#endif +#endif +#if __FUNC_TYPE_TEST_ENABLE__ +#if GH3X2X_TEST_CHNL_NUM > GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_MAIN_FUNC_CHNL_NUM +#define GH3X2X_MAIN_FUNC_CHNL_NUM GH3X2X_TEST_CHNL_NUM +#endif +#endif + + +#ifdef GH3X2X_FUNC_CHNL_NUM_MAX +#undef GH3X2X_FUNC_CHNL_NUM_MAX +#endif +#define GH3X2X_FUNC_CHNL_NUM_MAX GH3X2X_MAIN_FUNC_CHNL_NUM +#if __FUNC_TYPE_SOFT_ADT_ENABLE__ +#if GH3X2X_SOFT_ADT_CHNL_NUM > GH3X2X_MAIN_FUNC_CHNL_NUM +#undef GH3X2X_FUNC_CHNL_NUM_MAX +#define GH3X2X_FUNC_CHNL_NUM_MAX GH3X2X_SOFT_ADT_CHNL_NUM +#endif +#endif + + +#define __GS_EXTRA_BUF_LEN__ (0) +#if __GS_NONSYNC_READ_EN__ +#undef __GS_EXTRA_BUF_LEN__ +#define __GS_EXTRA_BUF_LEN__ (__GS_READ_POINT_NUM__ + __GS_READ_POINT_NUM_JITTER__) +#endif + + +#ifndef __GH3X2X_PROTOCOL_DATA_FUNCTION_INTERCEPT__ +#define __GH3X2X_PROTOCOL_DATA_FUNCTION_INTERCEPT__ 0 +#endif + +#ifndef __FIFO_PACKAGE_SEND_ENABLE__ +#define __FIFO_PACKAGE_SEND_ENABLE__ 0 +#endif + + + + +#if __ADT_ONLY_PARTICULAR_WM_CONFIG__ +#if __ADT_ONLY_PARTICULAR_WM_CONFIG__ < 4 +#error __ADT_ONLY_PARTICULAR_WM_CONFIG__ must be zero or bigger than 3 !!! +#endif +#endif + + + +#ifdef GOODIX_DEMO_PLATFORM +#include "Goodix_Platform_config.h" +#endif + +#endif /* _GH_DEMO_CONFIG_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_hook.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_hook.c new file mode 100644 index 000000000..8535f5519 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_hook.c @@ -0,0 +1,470 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_hook.c + * + * @brief gh3x2x driver lib demo code for hook + * + * @author Gooidx Iot Team + * + */ + +#include "gh_demo.h" +#include "gh_demo_config.h" +#include "gh_demo_inner.h" + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) +#include "gh3x2x_demo_algo_call.h" +#endif + +/* hook functions */ + +/** + * @fn void gh3x2x_init_hook_func(void) + * + * @brief gh3x2x init hook + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_init_hook_func(void) +{ +#if (__ADT_ONLY_PARTICULAR_WM_CONFIG__) + g_usCurrentConfigListFifoWmBak = 0; +#endif + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + if(0 == GH3x2x_GetChipResetRecoveringFlag()) + { + GH3X2X_AlgoCallConfigInit(g_pstGh3x2xFrameInfo, g_uchGh3x2xRegCfgArrIndex); + } +#endif + +#if __GH_MSG_WITH_ALGO_LAYER_EN__ + if(0 == GH3x2x_GetChipResetRecoveringFlag()) + { + GH3X2X_SEND_MSG_ALGO_CFG_INIT(g_pstGh3x2xFrameInfo, g_uchGh3x2xRegCfgArrIndex); + } +#endif + +} + +/** + * @fn void gh3x2x_sampling_start_hook_func(void) + * + * @brief gh3x2x start hook + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_sampling_start_hook_func(void) +{ + GOODIX_PLATFORM_SAMPLING_START_HOOK_ENTITY(); +} + +/** + * @fn void gh3x2x_sampling_stop_hook_func(void) + * + * @brief gh3x2x stop hook + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_sampling_stop_hook_func(void) +{ + + GOODIX_PLATFORM_SAMPLING_STOP_HOOK_ENTITY(); +} + +/** + * @fn void gh3x2x_get_rawdata_hook_func(GU8 *read_buffer_ptr, GU16 length) + * + * @brief gh3x2x get rawdata hook + * + * @attention None + * + * @param[in] read_buffer_ptr pointer to read rawdata buffer + * @param[in] length length + * @param[out] None + * + * @return None + */ + typedef struct +{ + GU32 uiAdcCode; //sampling rawdata of ADC + GU8 ubSlotNo; //slot number + GU8 ubAdcNo; //adc number + GU8 ubFlagLedAdjIsAgc_EcgRecover; //adj flag of ppg data or fast recover flag of ecg data + GU8 ubFlagLedAdjAgcUp; //adj down flag of ppg data 0: down 1:up +}StFifoDataInformation; +void gh3x2x_get_rawdata_hook_func(GU8 *read_buffer_ptr, GU16 length) +{ +#if (GH3X2X_FIFO_MONITOR_EN&(__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__)) + Gh3x2xFifoMonitorPro(&g_stFifoMonitorInfo, read_buffer_ptr, length); +#endif + + + /* code implement by user */ + /****************** FOLLOWING CODE IS EXAMPLE **********************************/ +#if 0 + StFifoDataInformation stTempFifoInfo = {0}; + if (length/4 > 0) + { + for (int i = 0; i < length; i += 4) + { + GU32 temp = 0; + // big endian to little endian + temp = ((GU32)read_buffer_ptr[i+ 0]) << 24; + temp += ((GU32)read_buffer_ptr[i+ 1])<< 16; + temp += ((GU32)read_buffer_ptr[i+ 2]) << 8; + temp += ((GU32)read_buffer_ptr[i+ 3]); + // pick rawdata and flag + stTempFifoInfo.uiAdcCode = ((temp >> 0) & 0x00FFFFFF); + stTempFifoInfo.ubSlotNo = ((temp >> 29) & 0x00000007); + stTempFifoInfo.ubAdcNo = ((temp >> 27) & 0x00000003); + stTempFifoInfo.ubFlagLedAdjIsAgc_EcgRecover = ((temp >> 26) & 0x00000001); + stTempFifoInfo.ubFlagLedAdjAgcUp = ((temp >> 25) & 0x00000001); + GH3X2X_INFO_LOG("Received rawdata:slot%d,adc%d,AdcCode = %d\r\n", stTempFifoInfo.ubSlotNo, stTempFifoInfo.ubAdcNo, \ + stTempFifoInfo.uiAdcCode); + } + } +#endif +} + +/** + * @fn void gh3x2x_algorithm_get_io_data_hook_func(const STGh3x2xFrameInfo * const pstFrameInfo) + * + * @brief get algorithm input and output data + * + * @attention None + * + * @param[in] pstFrameInfo + * @param[out] None + * + * @return None + */ +void gh3x2x_algorithm_get_io_data_hook_func(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + /* algo calculate */ +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + //GOODIX_PLATFORM_SAMPLING_START_HOOK_ENTITY(); + GH3X2X_AlgoCalculate(pstFrameInfo->unFunctionID); +#endif + +#if __GH_MSG_WITH_ALGO_LAYER_EN__ + GH3X2X_SEND_MSG_ALGO_CAL(pstFrameInfo->unFunctionID); +#endif + +#if (__SUPPORT_ALGO_INPUT_OUTPUT_DATA_HOOK_CONFIG__) + /****************** FOLLOWING CODE IS EXAMPLE **********************************/ +#if 0 + //function id and channel num + GH3X2X_INFO_LOG("[IO_DATA]Function ID: 0x%X, channel num = %d, frame cnt = %d\r\n",(int)(pstFrameInfo->unFunctionID),(int)(pstFrameInfo->pstFunctionInfo->uchChnlNum),(int)(pstFrameInfo->punFrameCnt[0])); + //gsensor data + GH3X2X_INFO_LOG("[IO_DATA]Gsensor: x = %d, y = %d, z = %d\r\n",\ + (int)(pstFrameInfo->pusFrameGsensordata[0]),\ + (int)(pstFrameInfo->pusFrameGsensordata[1]),\ + (int)(pstFrameInfo->pusFrameGsensordata[2])\ + ); + //rawdata + for(GU8 uchChnlCnt = 0; uchChnlCnt < pstFrameInfo->pstFunctionInfo->uchChnlNum; uchChnlCnt ++) + { + GH3X2X_INFO_LOG("[IO_DATA]Ch%d rawdata= %d\r\n",(int)(uchChnlCnt),(int)(pstFrameInfo->punFrameRawdata[uchChnlCnt])); + } +#endif +#endif +} + +void gh3x2x_frame_data_hook_func(const STGh3x2xFrameInfo * const pstFrameInfo) +{ +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + if (GH3X2X_TimestampSyncGetFrameDataFlag() == 0 && GH3X2X_GetGsensorEnableFlag()) + { + /* user set time stamp code here */ + GU32 unTimeStamp = 0; + //GU8 uchFuncOffsetID = 0; + //for(GU8 uchFunCnt = 0; uchFunCnt < __SYNC_FUNC_MAX__; uchFunCnt ++) + //{ + // if (((1<unFunctionID) == (1<> 1) + * + * @param[in] device_id device addr + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 hal_gh3x2x_i2c_write(GU8 device_id, const GU8 write_buffer[], GU16 length); + +/** + * @fn uint8_t hal_gh3x2x_i2c_read(uint8_t device_id, const uint8_t write_buffer[], uint16_t write_length, + * uint8_t read_buffer[], uint16_t read_length) + * + * @brief hal i2c read for gh3x2x + * + * @attention device_id is 8bits, if platform i2c use 7bits addr, should use (device_id >> 1) + * + * @param[in] device_id device addr + * @param[in] write_buffer write data buffer + * @param[in] write_length write data len + * @param[in] read_length read data len + * @param[out] read_buffer pointer to read buffer + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 hal_gh3x2x_i2c_read(GU8 device_id, const GU8 write_buffer[], GU16 write_length, GU8 read_buffer[], GU16 read_length); + +/* spi interface */ +/** + * @fn void hal_gh3x2x_spi_init(void) + * + * @brief hal spi init for gh3x2x + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void hal_gh3x2x_spi_init(void); + +/** + * @fn GU8 hal_gh3x2x_spi_write(GU8 write_buffer[], GU16 length) + * + * @brief hal spi write for gh3x2x + * + * @attention None + * + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +extern GU8 hal_gh3x2x_spi_write(GU8 write_buffer[], GU16 length); + +/** + * @fn GU8 hal_gh3x2x_spi_read(GU8 read_buffer[], GU16 length) + * + * @brief hal spi read for gh3x2x + * + * @attention None + * + * @param[in] read_length read data len + * @param[out] read_buffer pointer to read buffer + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +extern GU8 hal_gh3x2x_spi_read(GU8 read_buffer[], GU16 length); + +extern GU8 hal_gh3x2x_spi_write_F1_and_read(GU8 read_buf[], GU16 length); + + +/** + * @fn void hal_gh3x2x_spi_cs_ctrl(GU8 cs_pin_level) + * + * @brief hal spi cs pin ctrl for gh3x2x + * + * @attention pin level set 1 [high level] or 0 [low level] + * + * @param[in] cs_pin_level spi cs pin level + * @param[out] None + * + * @return None + */ +extern void hal_gh3x2x_spi_cs_ctrl(GU8 cs_pin_level); + +/** + * @fn void hal_gh3x2x_int_init(void) + * + * @brief gh3x2x int init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void hal_gh3x2x_reset_pin_init(void); + +/** + * @fn void hal_gh3x2x_reset_pin_ctrl(GU8 pin_level) + * + * @brief hal reset pin ctrl for gh3x2x + * + * @attention pin level set 1 [high level] or 0 [low level] + * + * @param[in] pin_level reset pin level + * @param[out] None + * + * @return None + */ +extern void hal_gh3x2x_reset_pin_ctrl(GU8 pin_level); + +/** + * @fn void hal_gh3x2x_int_init(void) + * + * @brief gh3x2x int init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void hal_gh3x2x_int_init(void); + +/** + * @fn void hal_gsensor_start_cache_data(void) + * + * @brief Start cache gsensor data for gh3x2x + * + * @attention This function will be called when start gh3x2x sampling. + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void hal_gsensor_start_cache_data(void); + +/** + * @fn void hal_gsensor_stop_cache_data(void) + * + * @brief Stop cache gsensor data for gh3x2x + * + * @attention This function will be called when stop gh3x2x sampling. + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void hal_gsensor_stop_cache_data(void); +extern void hal_cap_start_cache_data(void); +extern void hal_cap_stop_cache_data(void); +extern void hal_temp_start_cache_data(void); +extern void hal_temp_stop_cache_data(void); +/** + * @fn void hal_gsensor_drv_get_fifo_data(STGsensorRawdata gsensor_buffer[], GU16 *gsensor_buffer_index) + * + * @brief get gsensor fifo data + * + * @attention When read fifo data of GH3x2x,user should call this function to get gsensor data.And user must + * assure that these gsensor data is corresponding to GH3x2x fifo data + * + * @param[in] None + * @param[out] gsensor_buffer pointer to gsensor data buffer + * @param[out] gsensor_buffer_index pointer to number of gsensor data + * + * @return None + */ +extern void hal_gsensor_drv_get_fifo_data(STGsensorRawdata gsensor_buffer[], GU16 *gsensor_buffer_index); +extern void hal_cap_drv_get_fifo_data(STCapRawdata cap_data_buffer[], GU16 *cap_buffer_index); +extern void hal_temp_drv_get_fifo_data(STTempRawdata Temp_data_buffer[], GU16 *temp_buffer_index); +/** + * @fn void GH3X2X_PlatformLog(char *log_string) + * + * @brief for debug version, log + * + * @attention this function must define that use debug version lib + * + * @param[in] log_string pointer to log string + * @param[out] None + * + * @return None + */ +extern void GH3X2X_PlatformLog(GCHAR *log_string); +extern void GH3X2X_RegisterPrintf(int (**pPrintfUser)(const char *format, ...)); + +/** + * @fn void Gh3x2x_BspDelayUs(GU16 usUsec) + * + * @brief Delay in us,user should register this function into driver lib + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_BspDelayUs(GU16 usUsec); + +/** + * @fn void Gh3x2x_BspDelayMs(GU16 usMsec) + * + * @brief Delay in ms + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_BspDelayMs(GU16 usMsec); + +/** + * @fn void Gh3x2x_LeadOnEventHook(void) + * + * @brief Lead on event hook + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_LeadOnEventHook(void); + +/** + * @fn void Gh3x2x_LeadOffEventHook(void) + * + * @brief Lead off event hook + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_LeadOffEventHook(void); +/** + * @fn void Gh3x2x_BeforeWakeUpHook(void) + * + * @brief Before WakeUp Hook + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_BeforeWakeUpHook(void); + +/** + * @fn void Gh3x2x_WakeUpHook(void) + * + * @brief WakeUp Hook + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_WakeUpHook(void); + +/** + * @fn void Gh3x2x_WearEventHook(GU16 usGotEvent, GU8 uchType) + * + * @brief Wear event hook + * + * @attention None + * + * @param[in] wear event + * @param[in] wear off type 0: no object 1: nonliving object + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_WearEventHook(GU16 usGotEvent, GU8 uchType); +#if (__GH3X2X_CASCADE_EN__) +extern void Gh3x2x_WearEventCascadeEcgHandle(GU16 usGotEvent); +#endif + +/** + * @fn void Gh3x2x_UserHandleCurrentInfo(void) + * + * @brief handle gh3x2x chip current information for user + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2x_UserHandleCurrentInfo(void); + +/** + * @fn void Gh3x2xDemoAlgorithmCalculate(GU8* puchReadFifoBuffer, STGsensorRawdata *pstGsAxisValueArr, + * GU16 usGsDataNum, EMGsensorSensitivity emGsSensitivity) + * + * @brief Algorithm calculate.This function will be called in Gh3x2xDemoInterruptProcess() + * + * @attention None + * + * @param[in] puchReadFifoBuffer point to gh3x2x fifo data buffer + * @param[in] pstGsAxisValueArr point to gsensor data buffer + * @param[in] usGsDataNum gsensor data cnt + * @param[in] emGsSensitivity sensitivity of gsensor + * @param[out] None + * + * @return None + */ + +void Gh3x2xDemoFunctionProcess(GU8* puchReadFifoBuffer, GU16 usFifoBuffLen,STGsensorRawdata *pstGsAxisValueArr, GU16 usGsDataNum, + STCapRawdata* pstCapValueArr,GU16 usCapDataNum,STTempRawdata* pstTempValueArr,GU16 usTempDataNum); + +/** + * @fn void Gh3x2xDemoSamplingControl(EMUprotocolParseCmdType emSwitch) + * + * @brief Start/stop sampling of gh3x2x and sensor + * + * @attention None + * + * @param[in] unFuncMode function that will be started or stopped + * @param[in] emSwitch stop/start sampling + * @param[out] None + * + * @return None + */ +extern void Gh3x2xDemoSamplingControl(GU32 unFuncMode, EMUprotocolParseCmdType emSwitch); + +/// dump mode +extern GU16 g_usDumpMode; +extern GU8 g_uchGh3x2xRegCfgArrIndex; +extern GU16 g_usCurrentConfigListFifoWmBak; +extern void GH3X2X_LedAgcProcessExDump(GU8* puchReadFifoBuffer); +extern void GH3X2X_ReadElectrodeWearDumpData(void); +extern void GH3X2X_RecordDumpData(void); +extern void gh3x2x_init_hook_func(void); +extern void gh3x2x_sampling_start_hook_func(void); +extern void gh3x2x_sampling_stop_hook_func(void); +extern void gh3x2x_get_rawdata_hook_func(GU8 *read_buffer_ptr, GU16 length); +extern void gh3x2x_algorithm_get_io_data_hook_func(const STGh3x2xFrameInfo * const pstFrameInfo); +extern void gh3x2x_frame_data_hook_func(const STGh3x2xFrameInfo * const pstFrameInfo); +extern void gh3x2x_reset_by_protocol_hook(void); +extern void gh3x2x_config_set_start_hook(void); +extern void gh3x2x_config_set_stop_hook(void); +extern void gh3x2x_write_algo_config_hook(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); + +/** + * @fn void Gh3x2xDemoReportEvent(GU16 usEvent,GU8 uchWearType) + * + * @brief Report event to APP/EVK + * + * @attention None + * + * @param[in] usEvent GH3x2x event + * @param[out] None + * + * @return None + */ +extern void Gh3x2xDemoReportEvent(GU16 usEvent,GU8 uchWearType); + +/** + * @fn void Gh3x2x_HalSerialSendData(GU8* uchTxDataBuf, GU16 usBufLen) + * + * @brief Serial send data + * + * @attention None + * + * @param[in] uchTxDataBuf pointer to data buffer to be transmitted + * @param[in] usBufLen data buffer length + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_HalSerialSendData(GU8* uchTxDataBuf, GU16 usBufLen); + +/** + * @fn void Gh3x2x_StartAdtConfirmTimer(void) + * + * @brief Start time of adt confirm to get g sensor + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2xSerialSendTimerStop(void); +extern void Gh3x2xSerialSendTimerStart(void); +extern void Gh3x2x_StartMultiSensorTimer(void); +extern void Gh3x2xSerialSendTimerInit(GU8 uchPeriodMs); +/** + * @fn void Gh3x2x_StopAdtConfirmTimer(void) + * + * @brief Stop time of adt confirm + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +extern void Gh3x2x_StopMultiSensorTimer(void); +extern void Gh3x2xDemoSendWearOrLeadStateToUI(GU8 state); +extern void Gh3x2x_HalSerialFifoInit(void); +extern void Gh3x2xMemPoolCheckSumWrite(GU8 *lunMemPool); +extern GU16 Gh3x2xMemPoolCheckSumCheck(GU8 *lunMemPool); +extern void Gh3x2xCheckMemPollBeforeAlgoCal(void); +extern void Gh3x2xUpdataMemPollChkSumAfterAlgoCal(void); +extern void GH3x2xMaserControlFunctionLog(GU32 unFuncMode, EMUprotocolParseCmdType emCmdType); +#if ( __FUNC_TYPE_BP_ENABLE__ && (__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__)) +extern GS8 gh3x2x_write_pressure_parameters(GS32 *buffer); +extern GS8 gh3x2x_read_pressure_parameters(GS32 *buffer); +#endif +extern void* Gh3x2xMallocUser(GU32 unMemSize); +extern void Gh3x2xFreeUser(void* MemAddr); + +extern void Gh3x2xDemoStopAlgoInner(GU32 unFuncMode); +extern void Gh3x2xDemoStartAlgoInner(GU32 unFuncMode); + +extern void Gh3x2xDemoMoveDetectTimerHandler(GU32 unTimeIntervalMs); + + +#endif /* _GH3X2X_DEMO_INNER_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_protocol.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_protocol.c new file mode 100644 index 000000000..e1d591cf9 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_protocol.c @@ -0,0 +1,687 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_protocol.c + * + * @brief gh3x2x driver lib demo code for protocol + * + * @author Gooidx Iot Team + * + */ + +#include "gh_demo_inner.h" +#include "gh_multi_sen_pro.h" + + +GU8 gubUseZipProtocol = 0; + +GU32 Gh3x2xGetProtocolDataFunctionIntercept(void) +{ + return __GH3X2X_PROTOCOL_DATA_FUNCTION_INTERCEPT__ ; +} + +#if (__SUPPORT_PROTOCOL_ANALYZE__) + +#define GH3X2X_PROTOCOL_BUF_LEN (255) +#define GH3X2X_DEMO_USE_SERIAL_UART (1) +#define GH3X2X_DEMO_USE_SERIAL_BLE (2) + +/* use BLE */ +#define RX_BYTE_STREAM_STATE_WAIT_HEADER (0) +#define RX_BYTE_STREAM_STATE_WAIT_VERSION (1) +#define RX_BYTE_STREAM_STATE_WAIT_CMD (2) +#define RX_BYTE_STREAM_STATE_WAIT_LEN (3) +#define RX_BYTE_STREAM_STATE_WAIT_DATA (4) +#define RX_BYTE_STREAM_STATE_WAIT_CRC8 (5) + +#define GH3X2X_PROTOCOL_HEADER (0xAA) +#define GH3X2X_PROTOCOL_VERSION (0x11) +#define GH3X2X_PROTOCOL_LEN_INDEX (3) +#define GH3X2X_PROTOCOL_HEADER_LEN (4) + +/* use UART */ +#define RX_STREAM_STATE_WAIT_UART_HEADER_47 (0) +#define RX_STREAM_STATE_WAIT_UART_HEADER_44 (1) +#define RX_STREAM_STATE_WAIT_UART_LEN (2) +#define RX_STREAM_STATE_WAIT_UART_DATA (3) +#define RX_STREAM_STATE_WAIT_TAIL (4) + +#define GH3X2X_PROTOCOL_BLE_UART_47 (0x47) +#define GH3X2X_PROTOCOL_BLE_UART_44 (0x44) +#define GH3X2X_PROTOCOL_BLE_TAIL (0x0A) + +GU8 g_uchRxByteStreamState = 0; +GU16 g_usUartPayloadLen = 0; +GU16 g_usRxProtocolDataIndex = 0; +GU8 g_puchProtocolBufferRecv[GH3X2X_PROTOCOL_BUF_LEN] = {0}; + + + + + +STGh3x2xProtocolData g_stGh3x2xProtocolData ={0}; +STGh3x2xProtocolData * const g_pstGh3x2xProtocolData = &g_stGh3x2xProtocolData; + +#define GH3X2X_PROTOCOL_DATA_PKG_SIZE (255) +#define GH3X2X_PROTOCOL_EVENT_PKG_SIZE (4) +#define GH3X2X_ROTOCOL_TEMP_EVENT_BUF_SIZE (20) + + + +#define GH3X2X_SERIALSEND_TIMER_STATUS_STOP 0 +#define GH3X2X_SERIALSEND_TIMER_STATUS_START 1 + + +#define GH3X2X_PROTOCOL_EVENT_ACK_STATUS_NO_ACK 0 +#define GH3X2X_PROTOCOL_EVENT_ACK_STATUS_ACK 1 + + +volatile GU8 g_uchGh3x2xSerialSendTimerStatus; +GU8 g_puchGh3x2xProtocolDataSendBuf[__GH3X2X_PROTOCOL_DATA_FIFO_LEN__][GH3X2X_PROTOCOL_DATA_PKG_SIZE]; +volatile GU8 g_uchGh3x2xProtocolDataSendFifoWp; +GU8 g_uchGh3x2xProtocolDataSendFifoRp; + +GU8 g_puchGh3x2xProtocolEventSendBuf[__GH3X2X_PROTOCOL_EVENT_FIFO_LEN__][GH3X2X_PROTOCOL_EVENT_PKG_SIZE]; +volatile GU8 g_puchGh3x2xProtocolEventSendFifoWp; +GU8 g_uchGh3x2xProtocolEventSendFifoRp; +GU8 g_uchGh3x2xProtocolEventReportId; +GU8 g_uchGh3x2xProtocolEventReportRetryCnt; +GU8 g_uchGh3x2xProtocolEventAckStatus; +GU16 g_usGh3x2xProtocolEventWaitingAckTime; +GU8 g_uchGh3x2xProtocolEventAckId; +GU8 g_uchGh3x2xProtocolIdleFlag; + + + + + +void Gh3x2x_HalSerialFifoInit(void) +{ + g_uchGh3x2xSerialSendTimerStatus = GH3X2X_SERIALSEND_TIMER_STATUS_STOP; + g_uchGh3x2xProtocolDataSendFifoWp = 0; + g_uchGh3x2xProtocolDataSendFifoRp = 0; + g_uchGh3x2xProtocolEventReportId = 0; + g_uchGh3x2xProtocolEventReportRetryCnt = 0; + g_uchGh3x2xProtocolEventAckStatus = GH3X2X_PROTOCOL_EVENT_ACK_STATUS_NO_ACK; + g_usGh3x2xProtocolEventWaitingAckTime = 0; + g_uchGh3x2xProtocolIdleFlag = 0; + Gh3x2xSerialSendTimerInit(__GH3X2X_PROTOCOL_SEND_TIMER_PERIOD__); +} + + + + +#ifdef GOODIX_DEMO_PLATFORM +extern SemaphoreHandle_t UartTxFifoWritePower; +extern void UartSendIdlePkgGoodixPlanform(void); + +#endif + + +void Gh3x2x_HalSerialWriteDataToFifo(GU8 * lpubSource, GU8 lubLen) +{ + GU8 uchBufCnt; + if(0 == lubLen) + { + return ; + } + + if(g_uchGh3x2xProtocolDataSendFifoWp >= g_uchGh3x2xProtocolDataSendFifoRp) + { + uchBufCnt = g_uchGh3x2xProtocolDataSendFifoWp - g_uchGh3x2xProtocolDataSendFifoRp; + } + else + { + uchBufCnt = __GH3X2X_PROTOCOL_DATA_FIFO_LEN__ - (g_uchGh3x2xProtocolDataSendFifoRp - g_uchGh3x2xProtocolDataSendFifoWp); + } + +#ifdef GOODIX_DEMO_PLATFORM + if((uchBufCnt >= (__GH3X2X_PROTOCOL_DATA_FIFO_LEN__ - 1)) || (LP_MODE_DSLEEP == LP_GetLowPwrMode())) +#else + if((uchBufCnt >= (__GH3X2X_PROTOCOL_DATA_FIFO_LEN__ - 1)) ) +#endif + { + //GH3X2X_INFO_LOG("Warnning: Protocol Data fifo is overflow !!!\r\n"); + return ; + } + + +#ifdef GOODIX_DEMO_PLATFORM + xSemaphoreTake(UartTxFifoWritePower,portMAX_DELAY); +#endif + + if(lubLen > (GH3X2X_PROTOCOL_DATA_PKG_SIZE - 4)) + { + lubLen = (GH3X2X_PROTOCOL_DATA_PKG_SIZE - 4); + } + +#ifdef GOODIX_DEMO_PLATFORM + #if (!defined(GR5515_SK)) && (__PROTOCOL_SERIAL_TYPE__ != __PROTOCOL_SERIAL_USE_UART__) + GH3X2X_Memset(((u8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp])), 0xA0,GH3X2X_PROTOCOL_DATA_PKG_SIZE); + GH3X2X_Memcpy(((u8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp])) + 3,lpubSource,lubLen); + g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp][0] = 0x47; + g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp][1] = 0x44; + g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp][2] = GH3X2X_PROTOCOL_DATA_PKG_SIZE - 4; + g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp][254] = 0x0A; + #else + GH3X2X_Memset(((u8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp])), 0xA0,GH3X2X_PROTOCOL_DATA_PKG_SIZE); + GH3X2X_Memcpy(((u8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp])),lpubSource,lubLen); + #endif +#else + GH3X2X_Memcpy(((GU8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoWp])) + 0,lpubSource,lubLen); +#endif + + + + + g_uchGh3x2xProtocolDataSendFifoWp ++; + if(g_uchGh3x2xProtocolDataSendFifoWp >= __GH3X2X_PROTOCOL_DATA_FIFO_LEN__) + { + g_uchGh3x2xProtocolDataSendFifoWp = 0; + } + if(GH3X2X_SERIALSEND_TIMER_STATUS_STOP == g_uchGh3x2xSerialSendTimerStatus) + { + Gh3x2xSerialSendTimerStart(); + g_uchGh3x2xSerialSendTimerStatus = GH3X2X_SERIALSEND_TIMER_STATUS_START; + } + + +#ifdef GOODIX_DEMO_PLATFORM + xSemaphoreGive(UartTxFifoWritePower); +#endif + + return ; +} + + +void Gh3x2xSetProtocolEventAck(void) +{ + g_uchGh3x2xProtocolEventAckStatus = GH3X2X_PROTOCOL_EVENT_ACK_STATUS_ACK; +} + +GU8 Gh3x2xGetProtocolEventReportId(void) +{ + return g_puchGh3x2xProtocolEventSendBuf[g_uchGh3x2xProtocolEventSendFifoRp][2]; +} + + + + + +void Gh3x2x_HalSerialWriteEventToFifo(GU16 luwEvent,GU8 uchEventEx) +{ + GU8 uchBufCnt; + + if(g_puchGh3x2xProtocolEventSendFifoWp >= g_uchGh3x2xProtocolEventSendFifoRp) + { + uchBufCnt = g_puchGh3x2xProtocolEventSendFifoWp - g_uchGh3x2xProtocolEventSendFifoRp; + } + else + { + uchBufCnt = __GH3X2X_PROTOCOL_EVENT_FIFO_LEN__ - (g_uchGh3x2xProtocolEventSendFifoRp - g_puchGh3x2xProtocolEventSendFifoWp); + } + +#ifdef GOODIX_DEMO_PLATFORM + if((uchBufCnt >= (__GH3X2X_PROTOCOL_EVENT_FIFO_LEN__ - 1)) || (LP_MODE_DSLEEP == LP_GetLowPwrMode())) +#else + if((uchBufCnt >= (__GH3X2X_PROTOCOL_EVENT_FIFO_LEN__ - 1))) +#endif + { + GH3X2X_INFO_LOG("Warnning: Protocol event fifo is overflow !!!\r\n"); + return ; + } + + g_uchGh3x2xProtocolEventReportId ++; + g_puchGh3x2xProtocolEventSendBuf[g_puchGh3x2xProtocolEventSendFifoWp][0] = ((GU8*)(&luwEvent))[1]; + g_puchGh3x2xProtocolEventSendBuf[g_puchGh3x2xProtocolEventSendFifoWp][1] = ((GU8*)(&luwEvent))[0]; + g_puchGh3x2xProtocolEventSendBuf[g_puchGh3x2xProtocolEventSendFifoWp][2] = g_uchGh3x2xProtocolEventReportId; + g_puchGh3x2xProtocolEventSendBuf[g_puchGh3x2xProtocolEventSendFifoWp][3] = uchEventEx; + + + + g_puchGh3x2xProtocolEventSendFifoWp ++; + if(g_puchGh3x2xProtocolEventSendFifoWp >= __GH3X2X_PROTOCOL_EVENT_FIFO_LEN__) + { + g_puchGh3x2xProtocolEventSendFifoWp = 0; + } + if(GH3X2X_SERIALSEND_TIMER_STATUS_STOP == g_uchGh3x2xSerialSendTimerStatus) + { + Gh3x2xSerialSendTimerStart(); + g_uchGh3x2xSerialSendTimerStatus = GH3X2X_SERIALSEND_TIMER_STATUS_START; + } + + return ; +} + + + + + +void Gh3x2xSerialSendTimerHandle(void) +{ + GU8 uchHaveSendPkg = 0; +#ifdef GOODIX_DEMO_PLATFORM + GU8 puchTempEventSendBuf[GH3X2X_ROTOCOL_TEMP_EVENT_BUF_SIZE]; +#endif + GU8 uchStopTimerFlag = 0; + GU8 puchTempBuf2[GH3X2X_PROTOCOL_EVENT_PKG_SIZE + 5]; + + //check event fifo is empyty or not + if(g_puchGh3x2xProtocolEventSendFifoWp != g_uchGh3x2xProtocolEventSendFifoRp) + { + if(GH3X2X_PROTOCOL_EVENT_ACK_STATUS_ACK == g_uchGh3x2xProtocolEventAckStatus) //got ack + { + g_uchGh3x2xProtocolEventSendFifoRp ++; + if(g_uchGh3x2xProtocolEventSendFifoRp >= __GH3X2X_PROTOCOL_EVENT_FIFO_LEN__) + { + g_uchGh3x2xProtocolEventSendFifoRp = 0; + } + g_uchGh3x2xProtocolEventAckStatus = GH3X2X_PROTOCOL_EVENT_ACK_STATUS_NO_ACK; + g_usGh3x2xProtocolEventWaitingAckTime = 0; + } + else //have not got ack + { + if(g_usGh3x2xProtocolEventWaitingAckTime > __GH3X2X_PROTOCOL_EVENT_WAITING_ACK_TIME__) + { + if(g_uchGh3x2xProtocolEventReportRetryCnt < 255) + { + g_uchGh3x2xProtocolEventReportRetryCnt ++; + } + g_usGh3x2xProtocolEventWaitingAckTime = 0; + } + if(g_uchGh3x2xProtocolEventReportRetryCnt > __GH3X2X_PROTOCOL_EVENT_RESEND_NUM__) //retry cnt is enough + { + g_uchGh3x2xProtocolEventSendFifoRp ++; + if(g_uchGh3x2xProtocolEventSendFifoRp >= __GH3X2X_PROTOCOL_EVENT_FIFO_LEN__) + { + g_uchGh3x2xProtocolEventSendFifoRp = 0; + } + g_uchGh3x2xProtocolEventReportRetryCnt = 0; + } + } + } + + if(g_puchGh3x2xProtocolEventSendFifoWp != g_uchGh3x2xProtocolEventSendFifoRp) + { + if(0 == g_usGh3x2xProtocolEventWaitingAckTime) + { + if(0 == g_uchGh3x2xProtocolEventReportRetryCnt) + { + g_uchGh3x2xProtocolEventAckStatus = GH3X2X_PROTOCOL_EVENT_ACK_STATUS_NO_ACK; + } + + //send next event or no-ack event + + + puchTempBuf2[0] = 0xAA; + puchTempBuf2[1] = 0x11; + puchTempBuf2[2] = 0x16; + puchTempBuf2[3] = GH3X2X_PROTOCOL_EVENT_PKG_SIZE; + GH3X2X_Memcpy(puchTempBuf2 + 4,g_puchGh3x2xProtocolEventSendBuf[g_uchGh3x2xProtocolEventSendFifoRp],GH3X2X_PROTOCOL_EVENT_PKG_SIZE); + puchTempBuf2[GH3X2X_PROTOCOL_EVENT_PKG_SIZE + 5 - 1] = GH3X2X_CalcArrayCrc8Val(&(puchTempBuf2[0]),0,GH3X2X_PROTOCOL_EVENT_PKG_SIZE + 4); + +#ifdef GOODIX_DEMO_PLATFORM + #if (!defined(GR5515_SK)) && (__PROTOCOL_SERIAL_TYPE__ != __PROTOCOL_SERIAL_USE_UART__) + GH3X2X_Memcpy(puchTempEventSendBuf + 3,puchTempBuf2,GH3X2X_PROTOCOL_EVENT_PKG_SIZE + 5); + puchTempEventSendBuf[0] = 0x47; + puchTempEventSendBuf[1] = 0x44; + puchTempEventSendBuf[2] = GH3X2X_ROTOCOL_TEMP_EVENT_BUF_SIZE - 4; + puchTempEventSendBuf[GH3X2X_ROTOCOL_TEMP_EVENT_BUF_SIZE - 1] = 0x0A; + Gh3x2x_HalSerialSendData((u8*)puchTempEventSendBuf,GH3X2X_ROTOCOL_TEMP_EVENT_BUF_SIZE); + g_uchGh3x2xProtocolIdleFlag = 1; + #else + GH3X2X_Memcpy(puchTempEventSendBuf,puchTempBuf2,GH3X2X_PROTOCOL_EVENT_PKG_SIZE + 5); + Gh3x2x_HalSerialSendData((GU8*)puchTempBuf2,GH3X2X_PROTOCOL_EVENT_PKG_SIZE + 5); + g_uchGh3x2xProtocolIdleFlag = 1; + #endif +#else + Gh3x2x_HalSerialSendData((GU8*)puchTempBuf2,GH3X2X_PROTOCOL_EVENT_PKG_SIZE + 5); +#endif + uchHaveSendPkg = 1; + } + g_usGh3x2xProtocolEventWaitingAckTime += __GH3X2X_PROTOCOL_SEND_TIMER_PERIOD__; + } + + + + + + if(0 == uchHaveSendPkg) + { + if(g_uchGh3x2xProtocolDataSendFifoWp != g_uchGh3x2xProtocolDataSendFifoRp) + { + + + /************** send to master ************/ +#ifdef GOODIX_DEMO_PLATFORM + #if (!defined(GR5515_SK)) && (__PROTOCOL_SERIAL_TYPE__ != __PROTOCOL_SERIAL_USE_UART__) + Gh3x2x_HalSerialSendData(((u8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoRp])),GH3X2X_PROTOCOL_DATA_PKG_SIZE); + #else + Gh3x2x_HalSerialSendData(((u8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoRp])),5 + g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoRp][3]); + #endif + g_uchGh3x2xProtocolIdleFlag = 1; +#else + Gh3x2x_HalSerialSendData(((GU8*)(g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoRp])),5 + g_puchGh3x2xProtocolDataSendBuf[g_uchGh3x2xProtocolDataSendFifoRp][3]); +#endif + g_uchGh3x2xProtocolDataSendFifoRp ++; + if(g_uchGh3x2xProtocolDataSendFifoRp >= __GH3X2X_PROTOCOL_DATA_FIFO_LEN__) + { + g_uchGh3x2xProtocolDataSendFifoRp = 0; + } + uchHaveSendPkg = 1; + } + } + +#ifdef GOODIX_DEMO_PLATFORM + if(0 == uchHaveSendPkg) + { + if(g_uchGh3x2xProtocolIdleFlag) + { + g_uchGh3x2xProtocolIdleFlag = 0; + UartSendIdlePkgGoodixPlanform(); + + } + } +#endif + if((g_puchGh3x2xProtocolEventSendFifoWp == g_uchGh3x2xProtocolEventSendFifoRp)&&(g_uchGh3x2xProtocolDataSendFifoWp == g_uchGh3x2xProtocolDataSendFifoRp)) //event fifo and data fifo is empyt + { + //close timer +#ifdef GOODIX_DEMO_PLATFORM + if(0 == g_uchGh3x2xProtocolIdleFlag) +#endif + { + if(GH3X2X_SERIALSEND_TIMER_STATUS_START == g_uchGh3x2xSerialSendTimerStatus) + { + Gh3x2xSerialSendTimerStop(); + g_uchGh3x2xSerialSendTimerStatus = GH3X2X_SERIALSEND_TIMER_STATUS_STOP; + uchStopTimerFlag = 1; + } + } + + } + //check again for mulit-thread confict + if(uchStopTimerFlag) + { + if((g_puchGh3x2xProtocolEventSendFifoWp != g_uchGh3x2xProtocolEventSendFifoRp)||(g_uchGh3x2xProtocolDataSendFifoWp != g_uchGh3x2xProtocolDataSendFifoRp)) //event fifo and data fifo is empyt + { + Gh3x2xSerialSendTimerStart(); + g_uchGh3x2xSerialSendTimerStatus = GH3X2X_SERIALSEND_TIMER_STATUS_START; + } + } + + +} + +/** + * @fn void Gh3x2xDemoSendProtocolData(GU8* puchProtocolDataBuffer, GU16 usProtocolDataLen) + * + * @brief Copy protocol data to buffer that will be sent out to APP/EVK. + * + * @attention None + * + * @param[in] puchProtocolDataBuffer point to protocol data + * @param[in] usProtocolDataLen protocol data length + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoSendProtocolData(GU8* puchProtocolDataBuffer, GU16 usProtocolDataLen) +{ + if ((usProtocolDataLen > GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX) || (0 == usProtocolDataLen)) + { + return; + } + #if __SUPPORT_PROTOCOL_ANALYZE__ + Gh3x2x_HalSerialWriteDataToFifo(puchProtocolDataBuffer, usProtocolDataLen); + #endif +} + +/** + * @fn void Gh3x2xDemoOneFrameDataProcess(GU8* puchProtocolDataBuffer, GU16 usRecvLen) + * + * @brief Analyze protocol about GH3x2x,and pack protocol data to reply + * + * @attention None + * + * @param[out] puchProtocolDataBuffer pointer to protocol data buffer + * @param[out] usRecvLen protocol data buffer len + * + * @return None + */ +void Gh3x2xDemoOneFrameDataProcess(GU8* puchProtocolDataBuffer, GU16 usRecvLen) +{ + EMUprotocolParseCmdType emCmdType = UPROTOCOL_CMD_IGNORE; + GU8 puchRespondBuffer[GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX] = {0}; + GU16 usRespondLen = 0; + GU32 unFuncMode = 0; + emCmdType = GH3X2X_UprotocolParseHandler(puchRespondBuffer, &usRespondLen, puchProtocolDataBuffer, usRecvLen); + /* if respond buffer len is 0, and return value is UPROTOCOL_CMD_IGNORE, + it means driver lib can't analyze this protocol data */ + if ((0 == puchRespondBuffer[3]) && (UPROTOCOL_CMD_IGNORE == emCmdType)) + { +#ifdef GOODIX_DEMO_PLATFORM + GOODIX_PLATFORM_PROTOCOL_ANALYZE_ENTITY(); +#else + GH3X2X_INFO_LOG("Driver lib can't analyze this protocol,skip it,or you can add code to process it.\r\n"); + return; +#endif + } + else + { +#ifdef GOODIX_DEMO_PLATFORM + GOODIX_PLATFORM_CMD_PROCESS_ENTITY(); +#else + if ((UPROTOCOL_CMD_START == emCmdType) || (UPROTOCOL_CMD_STOP == emCmdType)) + { + unFuncMode = GH3X2X_GetTargetFuncMode(); + Gh3x2xDemoSamplingControl(unFuncMode, emCmdType); + GH3X2X_INFO_LOG("[%s]:function = 0x%08x, ctrl = %d\r\n", __FUNCTION__, unFuncMode, emCmdType); + } +#endif + if (UPROTOCOL_CMD_MPT_MODE == emCmdType) + { + g_uchDemoWorkMode = GH3X2X_DEMO_WORK_MODE_MPT; + GH3X2X_SetSingleChipModeEnableFlag(1); + } + if(g_uchDemoWorkMode != GH3X2X_DEMO_WORK_MODE_MPT) + { + GH3X2X_SetSingleChipModeEnableFlag(0); + } + Gh3x2xDemoSendProtocolData(puchRespondBuffer, usRespondLen); + } +} + +void Gh3x2xDemoHandleRecvUartData(GU8 uchRecvByte) +{ + switch (g_uchRxByteStreamState) + { + case RX_STREAM_STATE_WAIT_UART_HEADER_47: + if (GH3X2X_PROTOCOL_BLE_UART_47 == uchRecvByte) + { + g_uchRxByteStreamState++; + } + else + { + g_uchRxByteStreamState = RX_STREAM_STATE_WAIT_UART_HEADER_47; + } + break; + case RX_STREAM_STATE_WAIT_UART_HEADER_44: + if (GH3X2X_PROTOCOL_BLE_UART_44 == uchRecvByte) + { + g_uchRxByteStreamState++; + } + else + { + g_uchRxByteStreamState = RX_STREAM_STATE_WAIT_UART_HEADER_47; + } + /* code */ + break; + case RX_STREAM_STATE_WAIT_UART_LEN: + if (uchRecvByte > 0) + { + g_usUartPayloadLen = uchRecvByte; + g_usRxProtocolDataIndex = 0; + g_uchRxByteStreamState++; + } + else + { + g_uchRxByteStreamState = RX_STREAM_STATE_WAIT_UART_HEADER_47; + } + break; + case RX_STREAM_STATE_WAIT_UART_DATA: + g_puchProtocolBufferRecv[g_usRxProtocolDataIndex] = uchRecvByte; + g_usRxProtocolDataIndex++; + if (g_usRxProtocolDataIndex >= g_usUartPayloadLen) + { + g_uchRxByteStreamState++; + } + break; + case RX_STREAM_STATE_WAIT_TAIL: + if (GH3X2X_PROTOCOL_BLE_TAIL == uchRecvByte) + { + Gh3x2xDemoOneFrameDataProcess(g_puchProtocolBufferRecv, g_usRxProtocolDataIndex); + } + g_uchRxByteStreamState = RX_STREAM_STATE_WAIT_UART_HEADER_47; + break; + default: + g_usRxProtocolDataIndex = 0; + g_usUartPayloadLen = 0; + g_uchRxByteStreamState = RX_STREAM_STATE_WAIT_UART_HEADER_47; + break; + } +} + +void Gh3x2xDemoHandleRecvBleData(GU8 uchRecvByte) +{ + switch (g_uchRxByteStreamState) + { + case RX_BYTE_STREAM_STATE_WAIT_HEADER: + if (GH3X2X_PROTOCOL_HEADER == uchRecvByte) + { + g_puchProtocolBufferRecv[g_usRxProtocolDataIndex] = uchRecvByte; + g_uchRxByteStreamState++; + g_usRxProtocolDataIndex++; + } + else + { + g_usRxProtocolDataIndex = 0; + g_uchRxByteStreamState = RX_BYTE_STREAM_STATE_WAIT_HEADER; + } + break; + case RX_BYTE_STREAM_STATE_WAIT_VERSION: + if (GH3X2X_PROTOCOL_VERSION == uchRecvByte) + { + g_puchProtocolBufferRecv[g_usRxProtocolDataIndex] = uchRecvByte; + g_uchRxByteStreamState++; + g_usRxProtocolDataIndex++; + } + else + { + g_usRxProtocolDataIndex = 0; + g_uchRxByteStreamState = RX_BYTE_STREAM_STATE_WAIT_HEADER; + } + break; + case RX_BYTE_STREAM_STATE_WAIT_CMD: + g_puchProtocolBufferRecv[g_usRxProtocolDataIndex] = uchRecvByte; + g_uchRxByteStreamState++; + g_usRxProtocolDataIndex++; + break; + case RX_BYTE_STREAM_STATE_WAIT_LEN: + if (uchRecvByte > 0) + { + g_puchProtocolBufferRecv[g_usRxProtocolDataIndex] = uchRecvByte; + g_uchRxByteStreamState++; + g_usRxProtocolDataIndex++; + } + else + { + g_usRxProtocolDataIndex = 0; + g_uchRxByteStreamState = RX_BYTE_STREAM_STATE_WAIT_HEADER; + } + break; + case RX_BYTE_STREAM_STATE_WAIT_DATA: + g_puchProtocolBufferRecv[g_usRxProtocolDataIndex] = uchRecvByte; + g_usRxProtocolDataIndex++; + if (g_usRxProtocolDataIndex >= g_puchProtocolBufferRecv[GH3X2X_PROTOCOL_LEN_INDEX] + GH3X2X_PROTOCOL_HEADER_LEN) + { + g_uchRxByteStreamState++; + } + break; + case RX_BYTE_STREAM_STATE_WAIT_CRC8: + g_puchProtocolBufferRecv[g_usRxProtocolDataIndex] = uchRecvByte; + g_usRxProtocolDataIndex++; + Gh3x2xDemoOneFrameDataProcess(g_puchProtocolBufferRecv, g_usRxProtocolDataIndex); + g_usRxProtocolDataIndex = 0; + g_uchRxByteStreamState = RX_BYTE_STREAM_STATE_WAIT_HEADER; + break; + default: + g_usRxProtocolDataIndex = 0; + g_uchRxByteStreamState = RX_BYTE_STREAM_STATE_WAIT_HEADER; + break; + } +} + +/** + * @fn void Gh3x2xDemoProtocolProcess(GU8* puchProtocolDataBuffer, GU16 usRecvLen) + * + * @brief Analyze protocol about GH3x2x,and pack protocol data to reply + * + * @attention None + * + * @param[in] puchProtocolDataBuffer pointer to received protocol data buffer + * @param[in] usRecvLen protocol data buffer length + * + * @return None + */ +void Gh3x2xDemoProtocolProcess(GU8* puchProtocolDataBuffer, GU16 usRecvLen) +{ + GU16 uchIndex = 0; + for (uchIndex = 0; uchIndex < usRecvLen; uchIndex++) + { + #if (__PROTOCOL_SERIAL_TYPE__ == __PROTOCOL_SERIAL_USE_UART__) + //Gh3x2xDemoHandleRecvUartData(puchProtocolDataBuffer[uchIndex]); + Gh3x2xDemoHandleRecvBleData(puchProtocolDataBuffer[uchIndex]); + #else + Gh3x2xDemoHandleRecvBleData(puchProtocolDataBuffer[uchIndex]); + #endif + } +} + +/** + * @fn void Gh3x2xDemoReportEvent(GU16 usEvent,GU8 uchWearType) + * + * @brief Report event to APP/EVK + * + * @attention None + * + * @param[in] usEvent GH3x2x event + * @param[out] None + * + * @return None + */ + +void Gh3x2xDemoReportEvent(GU16 usEvent,GU8 uchEventEx) +{ + //GOODIX_PLATFORM_REPORT_EVRENT_ENTITY(); + //u16 usEventTemp = usEvent & (~GH3X2X_IRQ_MSK_FIFO_FULL_BIT); // fifo full event no need to report + + if(GhGsMoveDetecterIsEnable()) //is in multi-sensor wear det mode + { + usEvent &= ~(GH3X2X_IRQ_MSK_WEAR_ON_BIT); //ignore wear on event + } + usEvent &= (GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT|GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT|GH3X2X_IRQ_MSK_WEAR_ON_BIT|GH3X2X_IRQ_MSK_WEAR_OFF_BIT|GH3X2X_IRQ_MSK_CHIP_RESET_BIT|GH3X2X_IRQ_MSK_FIFO_FULL_BIT); + + if((usEvent != 0)||(uchEventEx & (GH3X2X_EVENT_EX_BIT_CHIP0_LEAD_ON|GH3X2X_EVENT_EX_BIT_CHIP0_LEAD_OFF|GH3X2X_EVENT_EX_BIT_CHIP1_LEAD_ON|GH3X2X_EVENT_EX_BIT_CHIP1_LEAD_OFF))) + { + Gh3x2x_HalSerialWriteEventToFifo(usEvent,uchEventEx); + } +} + +#else + +STGh3x2xProtocolData * const g_pstGh3x2xProtocolData = 0; +void Gh3x2xDemoSendProtocolData(GU8* puchProtocolDataBuffer, GU16 usProtocolDataLen){} +void Gh3x2x_HalSerialWriteDataToFifo(GU8 * lpubSource, GU8 lubLen){} +#endif + + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_reg_array.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_reg_array.c new file mode 100644 index 000000000..16cd29309 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_reg_array.c @@ -0,0 +1,219 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_reg_array.c + * + * @brief gh3x2x driver lib reg config array + * + * @author Gooidx Iot Team + * + */ + +#include "gh_demo_config.h" +#include "gh_demo_inner.h" + +/// HR+SPO2+NADT+ADT +const STGh3x2xReg gh3x2x_reg_list0[] = +{ + {0x0004, 0x001F}, {0x0006, 0x0005}, {0x000A, 0x00A0}, {0x000E, 0x000D}, {0x0100, 0x0100}, {0x0102, 0x0302}, + {0x0104, 0x0504}, {0x010A, 0x277C}, {0x0110, 0x0D14}, {0x0112, 0x5555}, {0x0114, 0x00AA}, {0x011E, 0x0019}, + {0x0120, 0x0400}, {0x0122, 0x0CBF}, {0x0126, 0x2744}, {0x0128, 0x0001}, {0x012A, 0x0000}, {0x012C, 0x0D16}, + {0x012E, 0x4441}, {0x0130, 0x0002}, {0x013A, 0x0219}, {0x013C, 0x0400}, {0x013E, 0x197F}, {0x0142, 0x2744}, + {0x0144, 0x0001}, {0x0146, 0x0000}, {0x0148, 0x0D16}, {0x014A, 0x4441}, {0x014C, 0x0002}, {0x0156, 0x0119}, + {0x0158, 0x0400}, {0x015A, 0x197F}, {0x015E, 0x2744}, {0x0160, 0x0001}, {0x0162, 0x0000}, {0x0164, 0x0C10}, + {0x0166, 0x4442}, {0x0168, 0x0002}, {0x0172, 0x010C}, {0x0174, 0x0400}, {0x017A, 0x2744}, {0x017C, 0x0001}, + {0x017E, 0x0000}, {0x0180, 0x0000}, {0x0182, 0x4442}, {0x0184, 0x0002}, {0x018E, 0x0400}, {0x0190, 0x0400}, + {0x0196, 0xC704}, {0x0198, 0x0001}, {0x019A, 0x0000}, {0x019C, 0x0C10}, {0x019E, 0x4442}, {0x01A0, 0x0002}, + {0x01A6, 0x0003}, {0x01AA, 0x010C}, {0x01AC, 0x0400}, {0x01EC, 0x0172}, {0x01EE, 0x034A}, {0x01F0, 0x034A}, + {0x01F2, 0x00E8}, {0x01F4, 0x006A}, {0x01F6, 0x00E8}, {0x0200, 0x0120}, {0x0280, 0x0A00}, {0x0282, 0xF530}, + {0x0284, 0x9388}, {0x0286, 0xC45C}, {0x0288, 0xA328}, {0x0408, 0x0001}, {0x0410, 0x49F0}, {0x0412, 0x0082}, + {0x0414, 0x49F0}, {0x0416, 0x0082}, {0x0422, 0x0011}, {0x0424, 0x0901}, {0x0426, 0x0102}, {0x0428, 0x0102}, + {0x0502, 0x4F60}, {0x0504, 0x000A}, {0x0506, 0x00A1}, {0x0588, 0x0008}, {0x0692, 0x0233}, {0x0694, 0x0400}, + {0x0698, 0x2310}, {0x0700, 0x0000}, {0x1000, 0x0000}, {0x1002, 0x3197}, {0x1004, 0x0000}, {0x1006, 0x6925}, + {0x1008, 0x2D17}, {0x100A, 0x0001}, {0x10E0, 0x0000}, {0x10E2, 0x0000}, {0x10E4, 0x00FF}, {0x10E6, 0xFFFF}, + {0x10E8, 0x0202}, {0x10EA, 0x0202}, {0x10EC, 0x0202}, {0x10EE, 0x0202}, {0x1120, 0x00A0}, {0x1122, 0x0005}, + {0x1124, 0x0000}, {0x1140, 0x0000}, {0x1142, 0x00C8}, {0x1144, 0x0001}, {0x1160, 0x0007}, {0x1162, 0x0000}, + {0x1164, 0x0402}, {0x1166, 0x4568}, {0x1168, 0x9940}, {0x116A, 0x00D9}, {0x116C, 0x8800}, {0x116E, 0x0093}, + {0x1170, 0x5C00}, {0x1172, 0x00C4}, {0x1174, 0x2800}, {0x1176, 0x00A3}, {0x2000, 0x0001}, {0x2002, 0x00A2}, + {0x2022, 0x0004}, {0x2024, 0x0901}, {0x2026, 0x1911}, {0x20CC, 0x0002}, {0x20CE, 0x4223}, {0x2132, 0x0003}, + {0x2134, 0x6201}, {0x2136, 0x0085}, {0x2880, 0x0005}, {0x2882, 0x0019}, {0x288C, 0x0019}, {0x2892, 0x0019}, + {0x3000, 0x0001}, {0x3002, 0x0000}, {0x3004, 0x49F0}, {0x3006, 0x0082}, {0xFFFF, 0x0001} +}; + +#if (__GH3X2X_CFG_LIST_MAX_NUM__ > 1) +//ecg +const STGh3x2xReg gh3x2x_reg_list1[] = +{ + //ecg single chip(256hz) + {0x0000, 0x0602}, {0x0004, 0x0018}, {0x0006, 0x0001}, {0x000A, 0x005F}, {0x000E, 0x000D}, {0x0074, 0x0050}, + {0x0100, 0x0100}, {0x010A, 0x0462}, {0x010C, 0x0000}, {0x010E, 0x0000}, {0x0110, 0x0000}, {0x011E, 0x0400}, + {0x0120, 0x0400}, {0x0126, 0xC704}, {0x0128, 0x0001}, {0x012A, 0x0000}, {0x012C, 0x0C10}, {0x012E, 0x4442}, + {0x0130, 0x0002}, {0x0136, 0x0003}, {0x013A, 0x010C}, {0x013C, 0x0400}, {0x01EA, 0x0033}, {0x01EC, 0x0030}, + {0x01EE, 0x00E8}, {0x0200, 0x1020}, {0x0402, 0x5555}, {0x0404, 0x4120}, {0x0406, 0x0041}, {0x0408, 0x0001}, + {0x0410, 0x49F0}, {0x0412, 0x0082}, {0x0414, 0x49F0}, {0x0416, 0x0082}, {0x0422, 0x0011}, {0x0424, 0x0901}, + {0x0426, 0x0109}, {0x0428, 0x0108}, {0x0480, 0x6550}, {0x0502, 0x4C66}, {0x0506, 0x0020}, {0x0588, 0x0008}, + {0x0692, 0x0233}, {0x0694, 0x0404}, {0x0698, 0x3310}, {0x069A, 0x1101}, {0x0700, 0x0000}, {0x0400, 0x5557}, + {0x1000, 0x0000}, {0x1002, 0x3197}, {0x1004, 0x0000}, {0x1006, 0xE016}, {0x1008, 0x2D04}, {0x100A, 0x0001}, + {0x10E0, 0x00FF}, {0x10E2, 0xFFFF}, {0x10E4, 0xFFFF}, {0x10E6, 0xFFFF}, {0x10E8, 0x0202}, {0x10EA, 0x0202}, + {0x10EC, 0x0202}, {0x10EE, 0x0202}, {0x1120, 0x005F}, {0x1122, 0x0005}, {0x1124, 0x0000}, {0x2000, 0x0001}, + {0x2002, 0x0022}, {0x20EE, 0x0001}, {0x20F0, 0x001C}, {0x2880, 0x0005}, {0x288E, 0x00FA}, {0x3000, 0x0101}, + {0x3002, 0x0000}, {0x3004, 0x49F0}, {0x3006, 0x0082}, {0x4500, 0x46C9}, {0x4502, 0x0F0F}, {0x4504, 0x0002}, + {0x4506, 0x0100}, {0xFFFF, 0x0001} +}; +#endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 1) */ + +#if (__GH3X2X_CFG_LIST_MAX_NUM__ > 2) +const STGh3x2xReg gh3x2x_reg_list2[] = +{ + //ecg master 500Hz Rtype 5M + #if __GH3X2X_ECG_RTYPE_5M__ + {0x0000, 0x0610}, {0x0004, 0x0013}, {0x000A, 0x005F}, {0x000E, 0x000D}, {0x0074, 0x0050}, {0x0100, 0x0100}, + {0x010A, 0x01E2}, {0x010C, 0x0000}, {0x010E, 0x0000}, {0x0110, 0x0000}, {0x0120, 0x0400}, {0x0126, 0xC73C}, + {0x012C, 0x0C10}, {0x012E, 0x2222}, {0x0130, 0x00AA}, {0x0136, 0x00FF}, {0x013C, 0x0400}, {0x01EA, 0x0033}, + {0x01EC, 0x0030}, {0x01EE, 0x0098}, {0x0200, 0x1020}, {0x0208, 0x0001}, {0x0402, 0x5555}, {0x0404, 0x4130}, + {0x0406, 0x0041}, {0x0408, 0x0001}, {0x0426, 0x0101}, {0x0428, 0x0101}, {0x0480, 0x6550}, {0x0502, 0x4C66}, + {0x0588, 0x0008}, {0x0692, 0x0233}, {0x0694, 0x0404}, {0x0698, 0x3310}, {0x069A, 0x1101}, {0x0700, 0x0000}, + {0x0400, 0x5557}, {0x1000, 0x0000}, {0x1002, 0x3190}, {0x1004, 0x0000}, {0x1006, 0xAB08}, {0x1008, 0x2937}, + {0x100A, 0x0001}, {0x10E0, 0x0000}, {0x10E2, 0xFFFF}, {0x10E4, 0xFFFF}, {0x10E6, 0xFFFF}, {0x10E8, 0x0202}, + {0x10EA, 0x0202}, {0x10EC, 0x0202}, {0x10EE, 0x0202}, {0x1120, 0x005F}, {0x1122, 0x0005}, {0x1124, 0x0000}, + {0x2000, 0x0004}, {0x2002, 0x2D25}, {0x2004, 0x3D35}, {0x20EE, 0x0001}, {0x20F0, 0x001C}, {0x2880, 0x0005}, + {0x288E, 0x01F4}, {0x3000, 0x0101}, {0x3002, 0x0000}, {0x3004, 0x0000}, {0x3006, 0x0000}, {0x4500, 0x46C9}, + {0x4502, 0x0F0F}, {0x4504, 0x000A}, {0x4506, 0x0320}, {0x45C0, 0x0000}, {0x45C2, 0x0000}, {0x45C4, 0x0000}, + {0x45C6, 0x0000}, {0xFFFF, 0x0001}, + #else + {0x0000, 0x0610}, {0x0004, 0x0013}, {0x000A, 0x005F}, {0x000E, 0x000D}, {0x0074, 0x0050}, {0x0100, 0x0100}, + {0x010A, 0x01E2}, {0x010C, 0x0000}, {0x010E, 0x0000}, {0x0110, 0x0000}, {0x0120, 0x0400}, {0x0126, 0xC73C}, + {0x012C, 0x0C10}, {0x012E, 0x2222}, {0x0130, 0x00AA}, {0x0136, 0x00FF}, {0x013C, 0x0400}, {0x01EA, 0x0033}, + {0x01EC, 0x0030}, {0x01EE, 0x0098}, {0x0200, 0x1020}, {0x0208, 0x0001}, {0x0402, 0x5555}, {0x0404, 0x4120}, + {0x0406, 0x0041}, {0x0408, 0x0001}, {0x0426, 0x0101}, {0x0428, 0x0101}, {0x0480, 0x6550}, {0x0502, 0x4C66}, + {0x0588, 0x0008}, {0x0692, 0x0233}, {0x0694, 0x0404}, {0x0698, 0x3310}, {0x069A, 0x1101}, {0x0700, 0x0000}, + {0x0400, 0x5557}, {0x1000, 0x0000}, {0x1002, 0x3190}, {0x1004, 0x0000}, {0x1006, 0x212D}, {0x1008, 0x293A}, + {0x100A, 0x0001}, {0x10E0, 0x0000}, {0x10E2, 0xFFFF}, {0x10E4, 0xFFFF}, {0x10E6, 0xFFFF}, {0x10E8, 0x0202}, + {0x10EA, 0x0202}, {0x10EC, 0x0202}, {0x10EE, 0x0202}, {0x1120, 0x005F}, {0x1122, 0x0005}, {0x1124, 0x0000}, + {0x2000, 0x0004}, {0x2002, 0x2D25}, {0x2004, 0x3D35}, {0x20EE, 0x0001}, {0x20F0, 0x001C}, {0x2880, 0x0005}, + {0x288E, 0x01F4}, {0x3000, 0x0101}, {0x3002, 0x0000}, {0x3004, 0x0000}, {0x3006, 0x0000}, {0x4500, 0x46C9}, + {0x4502, 0x0F0F}, {0x4504, 0x000A}, {0x4506, 0x0320}, {0x45C0, 0x0000}, {0x45C2, 0x0000}, {0x45C4, 0x0000}, + {0x45C6, 0x0000}, {0xFFFF, 0x0001}, + + #endif + +}; +#endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 2) */ + +#if (__GH3X2X_CFG_LIST_MAX_NUM__ > 3) +const STGh3x2xReg gh3x2x_reg_list3[] = +{ + {0,0}, +}; +#endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 3) */ + +#if (__GH3X2X_CFG_LIST_MAX_NUM__ > 4) +const STGh3x2xReg gh3x2x_reg_list4[] = +{ + {0,0}, +}; +#endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 4) */ + +#if (__GH3X2X_CFG_LIST_MAX_NUM__ > 5) +const STGh3x2xReg gh3x2x_reg_list5[] = +{ + {0,0}, +}; +#endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 5) */ + +#if (__GH3X2X_CFG_LIST_MAX_NUM__ > 6) +const STGh3x2xReg gh3x2x_reg_list6[] = +{ + {0,0}, +}; +#endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 6) */ + +#if (__GH3X2X_CFG_LIST_MAX_NUM__ > 7) +const STGh3x2xReg gh3x2x_reg_list7[] = +{ + {0,0}, +}; +#endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 7) */ + +const STGh3x2xInitConfig g_stGh3x2xCfgListArr[__GH3X2X_CFG_LIST_MAX_NUM__] = +{ + {gh3x2x_reg_list0,sizeof(gh3x2x_reg_list0) / sizeof(gh3x2x_reg_list0[0])}, + #if (__GH3X2X_CFG_LIST_MAX_NUM__ > 1) + {gh3x2x_reg_list1,sizeof(gh3x2x_reg_list1) / sizeof(gh3x2x_reg_list1[0])}, + #endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 1) */ + #if (__GH3X2X_CFG_LIST_MAX_NUM__ > 2) + {gh3x2x_reg_list2,sizeof(gh3x2x_reg_list2) / sizeof(gh3x2x_reg_list2[0])}, + #endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 2) */ + #if (__GH3X2X_CFG_LIST_MAX_NUM__ > 3) + {gh3x2x_reg_list3,sizeof(gh3x2x_reg_list3) / sizeof(gh3x2x_reg_list3[0])}, + #endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 3) */ + #if (__GH3X2X_CFG_LIST_MAX_NUM__ > 4) + {gh3x2x_reg_list4,sizeof(gh3x2x_reg_list4) / sizeof(gh3x2x_reg_list4[0])}, + #endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 4) */ + #if (__GH3X2X_CFG_LIST_MAX_NUM__ > 5) + {gh3x2x_reg_list5,sizeof(gh3x2x_reg_list5) / sizeof(gh3x2x_reg_list5[0])}, + #endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 5) */ + #if (__GH3X2X_CFG_LIST_MAX_NUM__ > 6) + {gh3x2x_reg_list6,sizeof(gh3x2x_reg_list6) / sizeof(gh3x2x_reg_list6[0])}, + #endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 6) */ + #if (__GH3X2X_CFG_LIST_MAX_NUM__ > 7) + {gh3x2x_reg_list7,sizeof(gh3x2x_reg_list7) / sizeof(gh3x2x_reg_list7[0])}, + #endif /* (__GH3X2X_CFG_LIST_MAX_NUM__ > 7) */ +}; + + +#if (__GH3X2X_CASCADE_EN__) +const STGh3x2xReg stGh3x2xEcgCascadeSlaveRealReglist[] = +{ + +/***Ecg Cascade Slaver: No lead detected****/ +#if 0 + {0x0000, 0x06B0}, {0x0004, 0x001F}, {0x000A, 0x0064}, {0x000E, 0x000D}, {0x0100, 0x0800}, {0x010A, 0x01E2}, + {0x010E, 0x0004}, {0x01EA, 0x0033}, {0x01EC, 0x0030}, {0x0200, 0x1020}, {0x0208, 0x0001}, {0x0480, 0x6550}, + {0x0502, 0x4060}, {0x0588, 0x0008}, {0x0692, 0x0233}, {0x0694, 0x0404}, {0x0698, 0x3310}, {0x069A, 0x1101}, + {0x0700, 0x0000}, +#endif + +/***Ecg Cascade Slaver: lead detected****/ +#if 1 + //internal 32K :{0x0000, 0x0630}, {0x0074, 0x0050}, + //external 32K :{0x0000, 0x06b0}, {0x0074, 0x00D0}, + #if __GH3X2X_ECG_RTYPE_5M__ + {0x0000, 0x0630}, {0x0004, 0x0013}, {0x000A, 0x005F}, {0x000E, 0x000D}, {0x0074, 0x0050}, {0x0100, 0x0100}, + {0x010A, 0x0162}, {0x010C, 0x0000}, {0x010E, 0x0000}, {0x0110, 0x0000}, {0x0120, 0x0400}, {0x0126, 0xC73C}, + {0x012C, 0x0C10}, {0x012E, 0x2222}, {0x0130, 0x00AA}, {0x0136, 0x00FF}, {0x013C, 0x0400}, {0x01EA, 0x0033}, + {0x01EC, 0x0030}, {0x01EE, 0x0098}, {0x0200, 0x1020}, {0x0402, 0x5555}, {0x0404, 0x4130}, {0x0406, 0x0041}, + {0x0408, 0x0001}, {0x0426, 0x0101}, {0x0428, 0x0101}, {0x0480, 0x6550}, {0x0502, 0x4C66}, {0x0588, 0x0008}, + {0x0692, 0x0233}, {0x0694, 0x0404}, {0x0698, 0x3310}, {0x069A, 0x1101}, {0x0700, 0x0000}, {0x0400, 0x5554}, + {0x1000, 0x0000}, {0x1002, 0x3190}, {0x1004, 0x0000}, {0x1006, 0x72E8}, {0x1008, 0x292F}, {0x100A, 0x0001}, + {0x10E0, 0x0000}, {0x10E2, 0xFFFF}, {0x10E4, 0xFFFF}, {0x10E6, 0xFFFF}, {0x10E8, 0x0202}, {0x10EA, 0x0202}, + {0x10EC, 0x0202}, {0x10EE, 0x0202}, {0x1120, 0x005F}, {0x1122, 0x0005}, {0x1124, 0x0000}, {0x2000, 0x0004}, + {0x2002, 0x2D25}, {0x2004, 0x3D35}, {0x20EE, 0x0001}, {0x20F0, 0x001C}, {0x2880, 0x0005}, {0x288E, 0x01F4}, + {0x3000, 0x0101}, {0x3002, 0x0000}, {0x3004, 0x0000}, {0x3006, 0x0000}, {0x4500, 0x46C9}, {0x4502, 0x0F0F}, + {0x4504, 0x000A}, {0x4506, 0x0320}, {0x45C0, 0x0000}, {0x45C2, 0x0000}, {0x45C4, 0x0000}, {0x45C6, 0x0000}, + {0xFFFF, 0x0001}, + #else + {0x0000, 0x0630}, {0x0004, 0x0013}, {0x000A, 0x005F}, {0x000E, 0x000D}, {0x0074, 0x0050}, {0x0100, 0x0100}, + {0x010A, 0x0162}, {0x010C, 0x0000}, {0x010E, 0x0000}, {0x0110, 0x0000}, {0x0120, 0x0400}, {0x0126, 0xC73C}, + {0x012C, 0x0C10}, {0x012E, 0x2222}, {0x0130, 0x00AA}, {0x0136, 0x00FF}, {0x013C, 0x0400}, {0x01EA, 0x0033}, + {0x01EC, 0x0030}, {0x01EE, 0x0098}, {0x0200, 0x1020}, {0x0402, 0x5555}, {0x0404, 0x4120}, {0x0406, 0x0041}, + {0x0408, 0x0001}, {0x0426, 0x0101}, {0x0428, 0x0101}, {0x0480, 0x6550}, {0x0502, 0x4C66}, {0x0588, 0x0008}, + {0x0692, 0x0233}, {0x0694, 0x0404}, {0x0698, 0x3310}, {0x069A, 0x1101}, {0x0700, 0x0000}, {0x0400, 0x5554}, + {0x1000, 0x0000}, {0x1002, 0x3190}, {0x1004, 0x0000}, {0x1006, 0x2184}, {0x1008, 0x293A}, {0x100A, 0x0001}, + {0x10E0, 0x0000}, {0x10E2, 0xFFFF}, {0x10E4, 0xFFFF}, {0x10E6, 0xFFFF}, {0x10E8, 0x0202}, {0x10EA, 0x0202}, + {0x10EC, 0x0202}, {0x10EE, 0x0202}, {0x1120, 0x005F}, {0x1122, 0x0005}, {0x1124, 0x0000}, {0x2000, 0x0004}, + {0x2002, 0x2D25}, {0x2004, 0x3D35}, {0x20EE, 0x0001}, {0x20F0, 0x001C}, {0x2880, 0x0005}, {0x288E, 0x01F4}, + {0x3000, 0x0101}, {0x3002, 0x0000}, {0x3004, 0x0000}, {0x3006, 0x0000}, {0x4500, 0x46C9}, {0x4502, 0x0F0F}, + {0x4504, 0x000A}, {0x4506, 0x0320}, {0x45C0, 0x0000}, {0x45C2, 0x0000}, {0x45C4, 0x0000}, {0x45C6, 0x0000}, + {0xFFFF, 0x0001}, + #endif +#endif + + +}; +const GU16 g_usEcgCascadeSlaveRealRegLen = sizeof(stGh3x2xEcgCascadeSlaveRealReglist) / sizeof(STGh3x2xReg); + +#else +const GU16 g_usEcgCascadeSlaveRealRegLen = 1; +const STGh3x2xReg stGh3x2xEcgCascadeSlaveRealReglist[1]; +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_user.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_user.c new file mode 100644 index 000000000..7c291fca0 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_user.c @@ -0,0 +1,774 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_user.c + * + * @brief gh3x2x driver lib demo code that user defined + * + * @author + * + */ + +/* includes */ +#include "stdint.h" +#include "string.h" +#include "gh_drv.h" +#include "gh_demo_config.h" +#include "gh_demo_inner.h" +#include "gh_demo.h" + +#include "pinctrl_porting.h" +#include "hal_gpio.h" +#include "i2c.h" +#include "custom_utils.h" + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) +#include "gh3x2x_demo_algo_call.h" +#endif + +#if (__GH3X2X_MP_MODE__) +#include "gh3x2x_mp_common.h" +#endif + +#if ( __GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__ ) + +#define GH3220_I2C_ADDR 0x14 +#define GH3220_I2C_BUS I2C_BUS_2 + +#define H_INT S_AGPIO_R6 + +/* i2c interface */ +/** + * @fn void hal_gh3x2x_i2c_init(void) + * + * @brief hal i2c init for gh3x2x + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void hal_gh3x2x_i2c_init(void) +{ + + /* code implement by user */ + GOODIX_PLATFORM_I2C_INIT_ENTITY(); + +} + +/** + * @fn uint8_t hal_gh3x2x_i2c_write(uint8_t device_id, const uint8_t write_buffer[], uint16_t length) + * + * @brief hal i2c write for gh3x2x + * + * @attention device_id is 8bits, if platform i2c use 7bits addr, should use (device_id >> 1) + * + * @param[in] device_id device addr + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 hal_gh3x2x_i2c_write(GU8 device_id, const GU8 write_buffer[], GU16 length) +{ + uint8_t ret = 1; + + /* code implement by user */ + + // GOODIX_PLATFORM_I2C_WRITE_ENTITY(device_id, write_buffer,length); + ret = custom_i2c_write_reg(GH3220_I2C_ADDR, 0, 0, write_buffer, length, GH3220_I2C_BUS); + if(ret == 0) + ret = 1; + else + ret = 0; + return ret; +} + +/** + * @fn uint8_t hal_gh3x2x_i2c_read(uint8_t device_id, const uint8_t write_buffer[], uint16_t write_length, + * uint8_t read_buffer[], uint16_t read_length) + * + * @brief hal i2c read for gh3x2x + * + * @attention device_id is 8bits, if platform i2c use 7bits addr, should use (device_id >> 1) + * + * @param[in] device_id device addr + * @param[in] write_buffer write data buffer + * @param[in] write_length write data len + * @param[in] read_length read data len + * @param[out] read_buffer pointer to read buffer + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 hal_gh3x2x_i2c_read(GU8 device_id, const GU8 write_buffer[], GU16 write_length, GU8 read_buffer[], GU16 read_length) +{ + uint8_t ret = 1; + + /* code implement by user */ + // custom_i2c_transfer(0x14,write_buffer, write_length, read_buffer, read_length, GH3X2X_I2C_BUS); + ret = custom_i2c_read_regs(GH3220_I2C_ADDR,write_buffer, write_length, read_buffer, read_length, GH3220_I2C_BUS); + // GOODIX_PLATFORM_I2C_READ_ENTITY(device_id, write_buffer, write_length, read_buffer, read_length); + if(ret == 0) + ret = 1; + else + ret = 0; + return ret; +} + +#else // __GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_SPI__ + +/* spi interface */ +/** + * @fn void hal_gh3x2x_spi_init(void) + * + * @brief hal spi init for gh3x2x + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ + +void hal_gh3x2x_spi_init(void) +{ + /* init spi and cs pin */ + GOODIX_PLATFORM_SPI_INIT_ENTITY(); +} + +/** + * @fn GU8 hal_gh3x2x_spi_write(GU8 write_buffer[], GU16 length) + * + * @brief hal spi write for gh3x2x + * + * @attention if __GH3X2X_SPI_TYPE__ == __GH3X2X_SPI_TYPE_SOFTWARE_CS__ , user need generate timming: write_buf[0](W) + write_buf[1](W) + ... + * @attention if __GH3X2X_SPI_TYPE__ == __GH3X2X_SPI_TYPE_HARDWARE_CS__ , user need generate timming: CS LOW + write_buf[0](W) + write_buf[1](W) + ... + CS HIGH + * + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 hal_gh3x2x_spi_write(GU8 write_buffer[], GU16 length) +{ + GU8 ret = 1; + + + GOODIX_PLATFORM_SPI_WRITE_ENTITY(write_buffer, length); + + return ret; +} + + +#if (__GH3X2X_SPI_TYPE__ == __GH3X2X_SPI_TYPE_SOFTWARE_CS__) +/** + * @fn GU8 hal_gh3x2x_spi_read(GU8 read_buffer[], GU16 length) + * + * @brief hal spi read for gh3x2x + * + * @attention user need generate timming: read_buf[0](R) + write_buf[1](R) + ... + * + * @param[in] read_length read data len + * @param[out] read_buffer pointer to read buffer + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 hal_gh3x2x_spi_read(GU8 read_buffer[], GU16 length) +{ + GU8 ret = 1; + + GOODIX_PLATFORM_SPI_READ_ENTITY(); + + return ret; +} +#elif (__GH3X2X_SPI_TYPE__ == __GH3X2X_SPI_TYPE_HARDWARE_CS__) +/** + * @fn GU8 hal_gh3x2x_spi_write_F1_and_read(GU8 read_buffer[], GU16 length) + * + * @brief hal spi write F1 and read for gh3x2x + * + * @attention user need generate timming: CS LOW + F1(W) + read_buf[0](R) + read_buf[1](R) + ... + CS HIGH + * + * @param[in] write_buf write data + * @param[in] length write data len + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 hal_gh3x2x_spi_write_F1_and_read(GU8 read_buffer[], GU16 length) +{ + GU8 ret = 1; + + GOODIX_PLATFORM_SPI_READ_ENTITY(); + + return ret; +} +#endif + +/** + * @fn void hal_gh3x2x_spi_cs_ctrl(GU8 cs_pin_level) + * + * @brief hal spi cs pin ctrl for gh3x2x + * + * @attention pin level set 1 [high level] or 0 [low level] + * + * @param[in] cs_pin_level spi cs pin level + * @param[out] None + * + * @return None + */ +#if (__GH3X2X_SPI_TYPE__ == __GH3X2X_SPI_TYPE_SOFTWARE_CS__) +void hal_gh3x2x_spi_cs_ctrl(GU8 cs_pin_level) +{ + + GOODIX_PLATFORM_SPI_CS_CTRL_ENTITY(); + +} +#endif + +#endif + +#if __SUPPORT_HARD_RESET_CONFIG__ + +/** + * @fn void hal_gh3x2x_int_init(void) + * + * @brief gh3x2x int init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ + + + +void hal_gh3x2x_reset_pin_init(void) +{ + GOODIX_PLATFORM_RESET_PIN_INIT_ENTITY(); +} + +/** + * @fn void hal_gh3x2x_reset_pin_ctrl(GU8 pin_level) + * + * @brief hal reset pin ctrl for gh3x2x + * + * @attention pin level set 1 [high level] or 0 [low level] + * + * @param[in] pin_level reset pin level + * @param[out] None + * + * @return None + */ + +void hal_gh3x2x_reset_pin_ctrl(GU8 pin_level) +{ + + GOODIX_PLATFORM_SPI_RESET_PIN_ENTITY(); +} + +#endif + +/** + * @fn void hal_gh3x2x_int_init(void) + * + * @brief gh3x2x int init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void hal_gh3x2x_int_init(void) +{ + // GOODIX_PLATFORM_INT_INIT_ENTITY(); + uapi_pin_set_ie(H_INT,HAL_PIO_IE_ENBALE); +} + +#if (__NORMAL_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__ || __MIX_INT_PROCESS_MODE__ == __INTERRUPT_PROCESS_MODE__) +/** + * @fn void hal_gh3x2x_int_handler_call_back(void) + * + * @brief call back of gh3x2x int handler + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void hal_gh3x2x_int_handler_call_back(void) +{ + if (Gh3x2xGetInterruptMode() == __NORMAL_INT_PROCESS_MODE__) + { + if(GH3X2X_DEMO_WORK_MODE_MPT != g_uchDemoWorkMode) + { + g_uchGh3x2xIntCallBackIsCalled = 1; + } +#if (__GH3X2X_MP_MODE__) + GH3X2X_MP_SET_INT_FLAG(); //gh3x2x mp test must call it +#endif + GOODIX_PLATFORM_INT_HANDLER_CALL_BACK_ENTITY(); + } +} +#endif + +/** + * @fn void hal_gsensor_start_cache_data(void) + * + * @brief Start cache gsensor data for gh3x2x + * + * @attention This function will be called when start gh3x2x sampling. + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void hal_gsensor_start_cache_data(void) +{ +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + GH3X2X_TimestampSyncAccInit(); +#endif + GOODIX_PLATFORM_INT_GS_START_CACHE_ENTITY(); +} + +/** + * @fn void hal_gsensor_stop_cache_data(void) + * + * @brief Stop cache gsensor data for gh3x2x + * + * @attention This function will be called when stop gh3x2x sampling. + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void hal_gsensor_stop_cache_data(void) +{ + + GOODIX_PLATFORM_INT_GS_STOP_CACHE_ENTITY(); +} + +void hal_cap_start_cache_data(void) +{ + GOODIX_PLATFORM_INT_CAP_START_CACHE_ENTITY(); +} + +void hal_cap_stop_cache_data(void) +{ + GOODIX_PLATFORM_INT_CAP_STOP_CACHE_ENTITY(); +} + +void hal_temp_start_cache_data(void) +{ + GOODIX_PLATFORM_INT_TEMP_START_CACHE_ENTITY(); +} + +void hal_temp_stop_cache_data(void) +{ + GOODIX_PLATFORM_INT_TEMP_STOP_CACHE_ENTITY(); +} + +void hal_gh3x2x_write_cap_to_flash(GS32 WearCap1,GS32 UnwearCap1,GS32 WearCap2,GS32 UnwearCap2) +{ + GOODIX_PLATFORM_WRITE_CAP_TO_FLASH_ENTITY(); +} +void hal_gh3x2x_read_cap_from_flash(GS32* WearCap1,GS32* UnwearCap1,GS32* WearCap2,GS32* UnwearCap2) +{ + GOODIX_PLATFORM_READ_CAP_FROM_FLASH_ENTITY(); +} + +/** + * @fn void hal_gsensor_drv_get_fifo_data(STGsensorRawdata gsensor_buffer[], GU16 *gsensor_buffer_index) + * + * @brief get gsensor fifo data + * + * @attention When read fifo data of GH3x2x, will call this function to get corresponding cached gsensor data. + * + * @param[in] None + * @param[out] gsensor_buffer pointer to gsensor data buffer + * @param[out] gsensor_buffer_index pointer to number of gsensor data(every gsensor data include x,y,z axis data) + * + * @return None + */ +void hal_gsensor_drv_get_fifo_data(STGsensorRawdata gsensor_buffer[], GU16 *gsensor_buffer_index) +{ +/**************************** WARNNING START***************************************************/ +/* (*gsensor_buffer_index) can not be allowed bigger than __GSENSOR_DATA_BUFFER_SIZE__ ****************/ +/* Be care for copying data to gsensor_buffer, length of gsensor_buffer is __GSENSOR_DATA_BUFFER_SIZE__ *****/ +/**************************** WARNNING END*****************************************************/ + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) + for (int i = 0; i < *gsensor_buffer_index; i++) + { + GU32 unTimeStamp = 0; + /* user set time stamp code here */ + GH3X2X_TimestampSyncFillAccSyncBuffer(unTimeStamp, gsensor_buffer[i].sXAxisVal, gsensor_buffer[i].sYAxisVal, gsensor_buffer[i].sZAxisVal); + } +#endif + + GOODIX_PLATFORM_INT_GET_GS_DATA_ENTITY(); + + +/**************************** WARNNING: DO NOT REMOVE OR MODIFY THIS CODE ---START***************************************************/ + if((*gsensor_buffer_index) > (__GSENSOR_DATA_BUFFER_SIZE__)) + { + while(1); // Fatal error !!! + } +/**************************** WARNNING: DO NOT REMOVE OR MODIFY THIS CODE ---END***************************************************/ +} + +void hal_cap_drv_get_fifo_data(STCapRawdata cap_data_buffer[], GU16 *cap_buffer_index) +{ + GOODIX_PLATFORM_INT_GET_CAP_DATA_ENTITY() ; + if((*cap_buffer_index) > (__CAP_DATA_BUFFER_SIZE__)) + { + while(1); // Fatal error !!! + } +} + +void hal_temp_drv_get_fifo_data(STTempRawdata temp_data_buffer[], GU16 *temp_buffer_index) +{ + GOODIX_PLATFORM_INT_GET_TEMP_DATA_ENTITY(); + if((*temp_buffer_index) > (__TEMP_DATA_BUFFER_SIZE__)) + { + while(1); // Fatal error !!! + } +} + +#if (__GH3X2X_INFO_LOG_TYPE__) +/** + * @fn void GH3X2X_PlatformLog(char *log_string) + * + * @brief for debug version, log + * + * @attention this function must define that use debug version lib + * + * @param[in] log_string pointer to log string + * @param[out] None + * + * @return None + */ + +#if __GH3X2X_INFO_LOG_TYPE__ == __GH3X2X_INFO_LOG_METHOD_0__ +void GH3X2X_PlatformLog(GCHAR *log_string) +{ + printf("%s",log_string); + // GOODIX_PLATFORM_LOG_ENTITY(); +} +#endif + +#if __GH3X2X_INFO_LOG_TYPE__ == __GH3X2X_INFO_LOG_METHOD_1__ +void GH3X2X_RegisterPrintf(int (**pPrintfUser)(const char *format, ...)) +{ + //(*pPrintfUser) = printf; //use printf in or use equivalent function in your platform + GOODIX_PLATFORM_PRINTF_ENTITY(); +} +#endif + + + + +#endif + +/** + * @fn void Gh3x2x_BspDelayUs(GU16 usUsec) + * + * @brief Delay in us,user should register this function into driver lib + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ + +void Gh3x2x_BspDelayUs(GU16 usUsec) +{ + // GOODIX_PLATFORM_DELAY_US_ENTITY(); + LOS_Udelay(usUsec); +} + + +/** + * @fn void Gh3x2x_BspDelayMs(GU16 usMsec) + * + * @brief Delay in ms + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2x_BspDelayMs(GU16 usMsec) +{ + // GOODIX_PLATFORM_DELAY_MS_ENTITY(); + LOS_Mdelay(usMsec); +} + +#if (__GH_MULTI_SENSOR_EVENT_PRO_CONIG__) + + +void Gh3x2x_CreateMultiSensorTimer(GU32 unPeriodMs) +{ + GOODIX_PLATFORM_CREAT_ADT_CONFIRM_ENTITY(unPeriodMs); +} + + + +/** + * @fn void Gh3x2x_StartMultiSensorTimer(void) + * + * @brief Start time of adt confirm to get g sensor + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2x_StartMultiSensorTimer(void) +{ + GH3X2X_DEBUG_LOG("Gh3x2x_StartMultiSensorTimer\r\n"); + GOODIX_PLATFORM_START_TIMER_ENTITY(); +} + + +/** + * @fn void Gh3x2x_StopMultiSensorTimer(void) + * + * @brief Stop time of adt confirm + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2x_StopMultiSensorTimer(void) +{ + GH3X2X_DEBUG_LOG("Gh3x2x_StopMultiSensorTimer\r\n"); + GOODIX_PLATFORM_STOP_TIMER_ENTITY(); +} + +void Gh3x2x_DeleteMultiSensorTimer(void) +{ + GOODIX_PLATFORM_DEL_TIMER_ENTITY(); +} + + +const STGhMultiSensorTimerOps g_stGhMultiSensorTimerOps = +{ + .TimerCreate = Gh3x2x_CreateMultiSensorTimer, + .TimerStart = Gh3x2x_StartMultiSensorTimer, + .TimerStop = Gh3x2x_StopMultiSensorTimer, + .TimerDelete = Gh3x2x_DeleteMultiSensorTimer, +}; +#endif + + + + +/** + * @fn void Gh3x2x_UserHandleCurrentInfo(void) + * + * @brief handle gh3x2x chip current information for user + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2x_UserHandleCurrentInfo(void) +{ + //read or write slotx current + + //GH3X2X_GetSlotLedCurrent(0,0); //read slot 0 drv 0 + //GH3X2X_GetSlotLedCurrent(1,0); // read slot 1 drv 0 + + //GH3X2X_SlotLedCurrentConfig(0,0,50); //set slot0 drv0 50 LSB + //GH3X2X_SlotLedCurrentConfig(1,0,50); //set slot1 drv0 50 LSB +} + +#if (__SUPPORT_PROTOCOL_ANALYZE__) +/** + * @fn void Gh3x2x_HalSerialSendData(GU8* uchTxDataBuf, GU16 usBufLen) + * + * @brief Serial send data + * + * @attention None + * + * @param[in] uchTxDataBuf pointer to data buffer to be transmitted + * @param[in] usBufLen data buffer length + * @param[out] None + * + * @return None + */ +void Gh3x2x_HalSerialSendData(GU8* uchTxDataBuf, GU16 usBufLen) +{ + GOODIX_PLATFORM_SERIAL_SEND_ENTITY(); +} + + +/** + * @fn void Gh3x2xSerialSendTimerInit(GU8 uchPeriodMs) + * + * @brief Gh3x2xSerialSendTimerInit + * + * @attention None + * + * @param[in] uchPeriodMs timer period (ms) + * @param[out] None + * + * @return None + */ +void Gh3x2xSerialSendTimerInit(GU8 uchPeriodMs) +{ + +} + + +/** + * @fn void Gh3x2xSerialSendTimerStop(void) + * + * @brief Serial send timer stop + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2xSerialSendTimerStop(void) +{ + GOODIX_PLATFORM_SERIAL_TIMER_STOP_ENTITY(); +} + + + +/** + * @fn void Gh3x2xSerialSendTimerStart(void) + * + * @brief Serial send timer start + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void Gh3x2xSerialSendTimerStart(void) +{ + GOODIX_PLATFORM_SERIAL_TIMER_START_ENTITY(); +} + +#endif + + + + + +void* Gh3x2xMallocUser(GU32 unMemSize) +{ +#if (__USER_DYNAMIC_DRV_BUF_EN__) +#ifdef GOODIX_DEMO_PLATFORM + GOODIX_PLATFORM_MALLOC_USER_ENTITY(); +#else + //return malloc(unMemSize); + return 0; +#endif +#else + return 0; +#endif +} + +void Gh3x2xFreeUser(void* MemAddr) +{ +#if (__USER_DYNAMIC_DRV_BUF_EN__) + GOODIX_PLATFORM_FREE_USER_ENTITY(); + //free(MemAddr); +#endif +} + + + + + + + + + +#if ( __FUNC_TYPE_BP_ENABLE__ && (__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_I2C__)) +/** + * @fn GS8 gh3x2x_write_pressure_parameters(GS32 *buffer) + * + * @brief gh3x2x get pressure value + * + * @attention None + * + * @param[out] buffer buffer[0] = rawdata_a0, + * buffer[1] = rawdata_a1, + * buffer[2] = pressure g value of rawdata_a1, + * + * @return error code + */ +GS8 gh3x2x_write_pressure_parameters(GS32 *buffer) +{ + return GOODIX_PLATFORM_PRESSURE_PARAS_WRITE_ENTITY(); +} + +/** + * @fn GS8 gh3x2x_read_pressure_parameters(GS32 *buffer) + * + * @brief gh3x2x get pressure value + * + * @attention None + * + * @param[out] buffer buffer[0] = area, + * buffer[1] = rawdata_a0, + * buffer[2] = rawdata_a1, + * buffer[3] = pressure g value, + * + * @return error code + */ +GS8 gh3x2x_read_pressure_parameters(GS32 *buffer) +{ + return GOODIX_PLATFORM_PRESSURE_PARAS_READ_ENTITY(); +} +#endif + + + + + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_version.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_version.h new file mode 100644 index 000000000..9c897eec4 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/kernel/gh_demo_version.h @@ -0,0 +1,41 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_version.h + * + * @brief gh3x2x demo code version + * + * @version ref gh3x2x_demo_version.h + * + */ + +#ifndef _GH3X2X_DEMO_VERSION_H_ +#define _GH3X2X_DEMO_VERSION_H_ + +#include "gh_demo_config.h" + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) +#include "gh3x2x_demo_algo_call_version.h" +#endif + +#define GH3X2X_DEMO_MAJOR_VERSION_NUMBER 1 /**< major version number */ +#define GH3X2X_DEMO_MINOR_VERSION_NUMBER 6 /**< minor version number */ + +#define GH3X2X_TO_STRING(x) #x /**< number to char */ +#define GH3X2X_STR(x) GH3X2X_TO_STRING(x) /**< number to char */ + +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) +#define GH3X2X_ALGOCALL_EXTRA_VERSION_STRING "_AC_"\ + "v"GH3X2X_STR(GOODIX_DEMO_MAJOR_VERSION_NUMBER)\ + "."GH3X2X_STR(GOODIX_DEMO_MINOR_VERSION_NUMBER) +#else +#define GH3X2X_ALGOCALL_EXTRA_VERSION_STRING "noAlgo" +#endif + +/// makeup version string +#define GH3X2X_DEMO_VERSION_STRING "GH(M)3X2X_DEMO_"\ + "v"GH3X2X_STR(GH3X2X_DEMO_MAJOR_VERSION_NUMBER)\ + "."GH3X2X_STR(GH3X2X_DEMO_MINOR_VERSION_NUMBER)\ + GH3X2X_ALGOCALL_EXTRA_VERSION_STRING\ + "(build:"__DATE__"_"__TIME__")" +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_agc/gh_agc.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_agc/gh_agc.c new file mode 100644 index 000000000..6ad192022 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_agc/gh_agc.c @@ -0,0 +1,1125 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_soft_led_agc.c + * + * @brief gh3x2x led agc process functions + * + * @version see gh3x2x_drv_version.h + * + */ + +#include +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" +#include "gh_uprotocol.h" +#include "gh_agc.h" + +#include "gh_drv_dump.h" +#include "gh_demo_config.h" + +//#define __SUPPORT_SOFT_AGC_CONFIG__ 1 + +#define __GH3X2X_AGC_GENERAL_TRIG_H_THD__ ((8388608 + 8388608*0.85f)) +#define __GH3X2X_AGC_GENERAL_TRIG_L_THD__ ((8388608 + 8388608*0.15f)) +#define __GH3X2X_AGC_GENERAL_IDEAL_VALUE__ ((8388608 + 8388608*0.56f)) +#define __GH3X2X_AGC_SPO2_TRIG_H_THD__ ((8388608 + 8388608*0.9f)) +#define __GH3X2X_AGC_SPO2_TRIG_L_THD__ ((8388608 + 8388608*0.5f)) +#define __GH3X2X_AGC_SPO2_IDEAL_VALUE__ ((8388608 + 8388608*0.7f)) +#define __GH3X2X_AGC_CONVERGENCE_LEVEL__ (8) // The values that can be set are 8, 16 and 32, and the recommended value is 16. The larger the value, the smaller the convergence range of AGC. + +//sub channel + +#define GH3X2X_NEW_AGC_SUB_CHNNL_ANAYLSIS_TIME_SEC 1 + +#define GH3X2X_AGC_REG_AGC_EN 0 +#define GH3X2X_AGC_REG_LED_CURRENT_UP_LIMIT 1 +#define GH3X2X_AGC_REG_LED_CURRENT_DOWN_LIMIT 2 +#define GH3X2X_AGC_REG_LED_CURRENT_DRV0 3 +#define GH3X2X_AGC_REG_LED_CURRENT_DRV1 4 +#define GH3X2X_AGC_REG_TIA_GAIN_RX0 5 +#define GH3X2X_AGC_REG_TIA_GAIN_RX1 6 +#define GH3X2X_AGC_REG_TIA_GAIN_RX2 7 +#define GH3X2X_AGC_REG_TIA_GAIN_RX3 8 +#define GH3X2X_AGC_REG_AGC_SRC 9 +#define GH3X2X_AGC_REG_BG_CANCEL_RX0 10 +#define GH3X2X_AGC_REG_BG_CANCEL_RX1 11 +#define GH3X2X_AGC_REG_BG_CANCEL_RX2 12 +#define GH3X2X_AGC_REG_BG_CANCEL_RX3 13 +#define GH3X2X_AGC_REG_SR_MULIPLIPER 14 +#define GH3X2X_AGC_ECG_PPG_RX_EN 15 + + +#if __SUPPORT_SOFT_AGC_CONFIG__ +//main chnl +STGh3x2xNewAgcMainChnlInfo g_pstGh3x2xNewAgcMainChnlInfoEntity[GH3X2X_NEW_AGC_SLOT_NUM_LIMIT]; +STGh3x2xNewAgcMainChnlMeanInfo g_pstGh3x2xNewAgcMainChnlMeanInfoEntity[GH3X2X_NEW_AGC_SLOT_NUM_LIMIT]; +STGh3x2xNewAgcMainChnlIdaelAdjInfo g_pstGh3x2xNewAgcMainChnlIdaelAdjInfoEntity[GH3X2X_NEW_AGC_SLOT_NUM_LIMIT]; +//sub chnl +#if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 +STGh3x2xNewAgcSubChnlRxInfo g_pstGh3x2xNewAgcSubChnlRxInfoEntity[GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT]; +#endif + + +STGh3x2xNewAgcMainChnlSat g_pstGh3x2xNewAgcMainChnlSat; +const GU32 g_unNewAgcSpo2Trig_H_Thd = __GH3X2X_AGC_SPO2_TRIG_H_THD__; +const GU32 g_unNewAgcSpo2Trig_L_Thd = __GH3X2X_AGC_SPO2_TRIG_L_THD__; +const GU32 g_unNewAgcSpo2Ideal_value = __GH3X2X_AGC_SPO2_IDEAL_VALUE__; +const GU32 g_unNewAgcGeneTrig_H_Thd = __GH3X2X_AGC_GENERAL_TRIG_H_THD__; +const GU32 g_unNewAgcGeneTrig_L_Thd = __GH3X2X_AGC_GENERAL_TRIG_L_THD__; +const GU32 g_unNewAgcGeneIdeal_value = __GH3X2X_AGC_GENERAL_IDEAL_VALUE__; +const GU8 g_uchAgcConvergence_level = __GH3X2X_AGC_CONVERGENCE_LEVEL__; + +// soft agc parameter +static STSoftAgcCfg g_stSoftAgcCfg; +extern const GU16 g_usGH3x2xSlotRegBase[8]; +extern const STGh3x2xAgcReg g_pstGH3x2xAgcReg[]; +extern const GU16 g_usGH3x2xTiaGainR[]; + +GU8 g_Gh3x2xNewAgcInitFlag = 0; + +void GH3X2X_StoreRxTiaGainAfterAgc(GU8 uchGain, GU8 uchSlotNo, GU8 uchAdcNo, GU8* puchGainRecord) +{ + puchGainRecord[uchSlotNo*4 + uchAdcNo] = uchGain; +} + +void GH3X2X_StoreDrvCurrentAfterAgc(GU8 DrvCurrent, GU8 uchSlotNo, GU8 uchDrvIndex, GU16* puchDrvCurrentRecord) +{ + if(!uchDrvIndex) + { + puchDrvCurrentRecord[uchSlotNo] = (puchDrvCurrentRecord[uchSlotNo]&0xFF00)|DrvCurrent; + } + else + { + puchDrvCurrentRecord[uchSlotNo] = (puchDrvCurrentRecord[uchSlotNo]&0x00FF)|(DrvCurrent<<8); + } +} + + +void GH3x2xNewAgcModuleReset(void) +{ + g_Gh3x2xNewAgcInitFlag = 0; + GH3X2X_Memset((GU8*)g_pstGh3x2xNewAgcMainChnlInfoEntity,0,(GU16)GH3X2X_NEW_AGC_SLOT_NUM_LIMIT*sizeof(STGh3x2xNewAgcMainChnlInfo)); + GH3X2X_Memset( (GU8*)(&g_pstGh3x2xNewAgcMainChnlSat),0,sizeof(STGh3x2xNewAgcMainChnlSat)); // init variable + GH3X2X_Memset((GU8*)g_pstGh3x2xNewAgcMainChnlMeanInfoEntity,0,(GU16)GH3X2X_NEW_AGC_SLOT_NUM_LIMIT*sizeof(STGh3x2xNewAgcMainChnlMeanInfo)); + GH3X2X_Memset((GU8*)g_pstGh3x2xNewAgcMainChnlIdaelAdjInfoEntity,0,(GU16)GH3X2X_NEW_AGC_SLOT_NUM_LIMIT*sizeof(STGh3x2xNewAgcMainChnlIdaelAdjInfo)); + + #if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 + Gh3x2xNewAgcSubChnlModuleReset(); + #endif +} + +void GH3X2X_NewAgcRecoveryAgcRegToMainChnl(GU8 uchSlotIdx, STGh3x2xNewAgcMainChnlInfo *pstAgcMainChnlInfo) +{ + GH3x2xSetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_UP_LIMIT, uchSlotIdx, pstAgcMainChnlInfo ->uchBakRegLedCurrentMax); + GH3x2xSetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_DOWN_LIMIT, uchSlotIdx, pstAgcMainChnlInfo ->uchBakRegLedCurrentMin); + GH3x2xSetAgcReg(GH3X2X_AGC_REG_AGC_SRC, uchSlotIdx, pstAgcMainChnlInfo ->uchBakRegAgcSrc); + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] recover agc src:agc_src = %d, SlotNo = %d\r\n",pstAgcMainChnlInfo ->uchBakRegAgcSrc,uchSlotIdx); +} + +GU8 GH3X2X_NewAgcFindSubChnlSlotInfo(GU8 uchSlot) +{ + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_NEW_AGC_SLOT_NUM_LIMIT; uchSlotCnt ++) + { + STGh3x2xNewAgcMainChnlInfo *pstAgcMainChnlInfo = &g_pstGh3x2xNewAgcMainChnlInfoEntity[uchSlotCnt]; + if(pstAgcMainChnlInfo ->uchEnable) + { + if(uchSlot == (pstAgcMainChnlInfo ->uchSlotAdc >> 2)) + { + return uchSlotCnt; + } + } + } + return 0; +} + +GU16 GH3x2xCalTrigerUpLimitForBiggerGain(GU8 uchCurrentGain ,GU8 uchSlotNo) +{ + GU32 unTempRawdata; + GU32 unTempTrigThd_H; + + GU8 uchSlotCnt = GH3X2X_NewAgcFindSubChnlSlotInfo(uchSlotNo); + STGh3x2xNewAgcMainChnlInfo *pstAgcMainChnlInfo = &g_pstGh3x2xNewAgcMainChnlInfoEntity[uchSlotCnt]; + if(pstAgcMainChnlInfo->uchSpo2ChnlIndex) + { + unTempTrigThd_H = g_unNewAgcSpo2Trig_H_Thd; + }else + { + unTempTrigThd_H = g_unNewAgcGeneTrig_H_Thd; + } + + if(12 <= uchCurrentGain) + { + return 0xFFFF; + } + else + { + unTempRawdata = unTempTrigThd_H - 8388608; + unTempRawdata = 8388608 + (GU32)(((float)unTempRawdata)/(float)1.3*(float)g_usGH3x2xTiaGainR[uchCurrentGain]/(float)g_usGH3x2xTiaGainR[uchCurrentGain + 1]); + return unTempRawdata>>8; + } +} + + +#if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 +void GH3x2xNewAgcSubChnlClearAnalysisCntAndSetGain(GU8 uchSlotNo, GU8 uchRxEn ,GU8 uchNextGain) +{ + for(GU8 uchRxCnt = 0; uchRxCnt < 4; uchRxCnt ++) + { + if(uchRxEn&(1 << uchRxCnt)) + { + for(GU8 uchChnlCnt = 0; uchChnlCnt < GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT; uchChnlCnt ++) + { + STGh3x2xNewAgcSubChnlRxInfo *pstSTGh3x2xNewAgcSubChnlRxInfo = &(g_pstGh3x2xNewAgcSubChnlRxInfoEntity[uchChnlCnt]); + if(pstSTGh3x2xNewAgcSubChnlRxInfo->uchEn) + { + if(((uchSlotNo << 2) + uchRxCnt) == pstSTGh3x2xNewAgcSubChnlRxInfo ->uchSlotAdcNo) + { + pstSTGh3x2xNewAgcSubChnlRxInfo ->usAnalysisCnt = 0; + if(0xFF != uchNextGain) + { + GH3x2xSetAgcReg(GH3X2X_AGC_REG_TIA_GAIN_RX0 + uchRxCnt, uchSlotNo, 0); + pstSTGh3x2xNewAgcSubChnlRxInfo ->uchCurrentGain = uchNextGain; + pstSTGh3x2xNewAgcSubChnlRxInfo ->usTrigeUpLimitForBiggerGain = GH3x2xCalTrigerUpLimitForBiggerGain(uchNextGain,pstSTGh3x2xNewAgcSubChnlRxInfo->uchSlotAdcNo >> 2); + } + } + } + } + } + } +} +#endif + + +void GH3x2xNewAgcMeanInfoReset(GU8 uchSlotEnChange) +{ + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt++) + { + if( uchSlotEnChange & (1<> 2) & 0x0f); + GU8 uchEnable = g_pstGh3x2xNewAgcMainChnlInfoEntity[uchAgcSlotCnt].uchEnable; + if( uchEnable ) + { + if( uchSlotIdx == uchSlotCnt) + { + g_pstGh3x2xNewAgcMainChnlMeanInfoEntity[uchAgcSlotCnt].usAnalysisCnt = 0; + #if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 + GH3x2xNewAgcSubChnlClearAnalysisCntAndSetGain(uchSlotIdx, 0x0F, 0xFF); //clear all rx analysis cnt in this slot + #endif + } + } + } + } + } +} + +GU8 GH3x2xGetDrvCurrent(GU8 uchSlotIdx ,GU8 uchAgcEn) +{ + GU8 uchTempDrv; + if(2 == uchAgcEn) + { + uchTempDrv = GH3x2xGetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_DRV1, uchSlotIdx); + } + else + { + uchTempDrv = GH3x2xGetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_DRV0, uchSlotIdx); + } + return uchTempDrv; +} + +void GH3x2xNewAgcChnlInfoInit(STGh3x2xAgcInfo *STGh3x2xAgcInfo) +{ + if(0 == GH3X2X_NEW_AGC_SLOT_NUM_LIMIT) + { + return; + } + if(0 == g_Gh3x2xNewAgcInitFlag) + { + GU8 uchNewAgcSlotCnt = 0; + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + if((g_stSoftAgcCfg.uchSlotxSoftAgcAdjEn & (1 << uchSlotCnt))) + { + if(uchNewAgcSlotCnt < GH3X2X_NEW_AGC_SLOT_NUM_LIMIT) + { + g_pstGh3x2xNewAgcMainChnlInfoEntity[uchNewAgcSlotCnt].uchEnable = 1; + g_pstGh3x2xNewAgcMainChnlInfoEntity[uchNewAgcSlotCnt].uchSlotAdc = (uchSlotCnt << 2); + + /******* slot function Distinguish START******************************************************/ + if((g_stSoftAgcCfg.uchSpo2RedSlotCfgEn & (1 << uchSlotCnt))||(g_stSoftAgcCfg.uchSpo2IrSlotCfgEn & (1 << uchSlotCnt))) + { + g_pstGh3x2xNewAgcMainChnlInfoEntity[uchNewAgcSlotCnt].uchSpo2ChnlIndex = 1; + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] uchNewAgcSpo2SlotCnt = %d\r\n",uchNewAgcSlotCnt); + } + /******* slot function Distinguish END******************************************************/ + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] uchNewAgcSlotCnt = %d\r\n",uchNewAgcSlotCnt); + uchNewAgcSlotCnt ++; + } + else + { + GH3X2X_DEBUG_LOG_PARAM("[NewAgc] error !!! main chnl info is no enough! \r\n"); + while(1); + } + } + } + g_Gh3x2xNewAgcInitFlag = 1; + } + + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_NEW_AGC_SLOT_NUM_LIMIT; uchSlotCnt ++) + { + STGh3x2xNewAgcMainChnlInfo *pstAgcMainChnlInfo = &g_pstGh3x2xNewAgcMainChnlInfoEntity[uchSlotCnt]; + GH3X2X_INFO_LOG_PARAM_AGC("AGC_InitValue %d: Enable = %d, AgcAdjEn = %d\r\n",uchSlotCnt, pstAgcMainChnlInfo->uchEnable,g_stSoftAgcCfg.uchSlotxSoftAgcAdjEn); + if(pstAgcMainChnlInfo->uchEnable) + { + GU8 uchSlotIdx; + uchSlotIdx = pstAgcMainChnlInfo ->uchSlotAdc >> 2; + GH3X2X_INFO_LOG_PARAM_AGC("AGC_InitFlag%d: SlotCfgX=%d, Vaule = %d\r\n",uchSlotCnt, uchSlotIdx, pstAgcMainChnlInfo->uchHaveBakRegFlag); + if(0 == pstAgcMainChnlInfo ->uchHaveBakRegFlag) + { + GU8 uchBgCancel; + GU8 uchGainLimit; + GU16 usSampleRate; + GU16 usEcgPpgRxEn; + + //bak reg + pstAgcMainChnlInfo ->uchBakRegAgcEn = GH3x2xGetAgcReg(GH3X2X_AGC_REG_AGC_EN, uchSlotIdx); + pstAgcMainChnlInfo ->uchBakRegAgcSrc = GH3x2xGetAgcReg(GH3X2X_AGC_REG_AGC_SRC, uchSlotIdx); + pstAgcMainChnlInfo ->uchSlotAdc = (uchSlotIdx << 2) + pstAgcMainChnlInfo ->uchBakRegAgcSrc; + pstAgcMainChnlInfo ->uchBakRegLedCurrentMax = GH3x2xGetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_UP_LIMIT, uchSlotIdx); + pstAgcMainChnlInfo ->uchBakRegLedCurrentMin = GH3x2xGetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_DOWN_LIMIT, uchSlotIdx); + pstAgcMainChnlInfo ->uchBakTiaGain = GH3x2xGetAgcReg(GH3X2X_AGC_REG_TIA_GAIN_RX0 + pstAgcMainChnlInfo ->uchBakRegAgcSrc, uchSlotIdx); + pstAgcMainChnlInfo ->uchCurrentTiaGain = pstAgcMainChnlInfo ->uchBakTiaGain; + pstAgcMainChnlInfo ->uchCurrentDrv = GH3x2xGetDrvCurrent(uchSlotIdx, pstAgcMainChnlInfo->uchBakRegAgcEn); + //GH3X2X_StoreDrvCurrentAfterAgc(pstAgcMainChnlInfo ->uchCurrentDrv, uchSlotIdx,g_pstGh3x2xAgcInfo->uchDrvCurrentAfterSoftAgc); + uchBgCancel = GH3x2xGetAgcReg(GH3X2X_AGC_REG_BG_CANCEL_RX0 + pstAgcMainChnlInfo ->uchBakRegAgcSrc, uchSlotIdx); + GH3X2X_StoreRxTiaGainAfterAgc(pstAgcMainChnlInfo->uchBakTiaGain, uchSlotIdx, pstAgcMainChnlInfo->uchBakRegAgcSrc, STGh3x2xAgcInfo->uchTiaGainAfterSoftAgc); + if(0 == uchBgCancel) + { + uchGainLimit = g_stSoftAgcCfg.stSoftAgcGainLimit.uchGainLimitBg32uA; + } + else if(1 == uchBgCancel) + { + uchGainLimit = g_stSoftAgcCfg.stSoftAgcGainLimit.uchGainLimitBg64uA; + } + else if(2 == uchBgCancel) + { + uchGainLimit = g_stSoftAgcCfg.stSoftAgcGainLimit.uchGainLimitBg128uA; + } + else + { + uchGainLimit = g_stSoftAgcCfg.stSoftAgcGainLimit.uchGainLimitBg256uA; + } + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] uchGainLimit = %d, uchSlotIdx = %d\r\n",uchGainLimit, uchSlotIdx); + pstAgcMainChnlInfo ->uchTiaGainUpLimit = uchGainLimit; + + usEcgPpgRxEn = GH3x2xGetAgcReg(GH3X2X_AGC_ECG_PPG_RX_EN, uchSlotIdx); + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] usEcgPpgRxEn = 0x%X\r\n",usEcgPpgRxEn); + if(usEcgPpgRxEn&0x0001) // ecg is enable + { + usEcgPpgRxEn = ((usEcgPpgRxEn>>1) & (~0x0008)); //clear RX3 enable bit + } + else + { + usEcgPpgRxEn = (usEcgPpgRxEn>>1); + } + usEcgPpgRxEn &= (~(1 << pstAgcMainChnlInfo ->uchBakRegAgcSrc)); //clear main channel RX enable bit + + GU16 usFastestSampleRate = GH3X2X_ReadRegBitField(GH3X2X_FASTEST_SAMPLERATE_ADDR,0,7); + usSampleRate = GH3X2X_SYS_SAMPLE_RATE/(usFastestSampleRate + 1)/(GH3x2xGetAgcReg(GH3X2X_AGC_REG_SR_MULIPLIPER, uchSlotIdx) + 1); + g_pstGh3x2xNewAgcMainChnlMeanInfoEntity[uchSlotCnt].usSampleRate = usSampleRate; //init + //sub channel slot +#if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 + GH3x2xNewAgcSetNewSubChnl(uchSlotIdx,usEcgPpgRxEn,STGh3x2xAgcInfo); +#endif + pstAgcMainChnlInfo ->uchHaveBakRegFlag = 1; + GH3x2xSetAgcReg(GH3X2X_AGC_REG_AGC_EN, uchSlotIdx, 0); // disable hardware agc + } + else + { + pstAgcMainChnlInfo ->uchCurrentTiaGain = GH3x2xGetAgcReg(GH3X2X_AGC_REG_TIA_GAIN_RX0 + pstAgcMainChnlInfo ->uchBakRegAgcSrc, uchSlotIdx); + pstAgcMainChnlInfo ->uchCurrentDrv = GH3x2xGetDrvCurrent(uchSlotIdx, pstAgcMainChnlInfo->uchBakRegAgcEn); + GH3X2X_INFO_LOG_PARAM_AGC("Drv Gian inite read %d: IniteDrv = %d, IniteGain = %d\r\n",uchSlotIdx, pstAgcMainChnlInfo ->uchCurrentDrv, pstAgcMainChnlInfo ->uchCurrentTiaGain); + ////get initial DRV and current in case them change before StartSampling() +// GH3X2X_NewAgcRecoveryAgcRegToMainChnl(uchSlotIdx,pstAgcMainChnlInfo); + } + } + } +} + + +GU32 GH32x2xMedSel(GU32 unData0, GU32 unData1, GU32 unData2) +{ + if((unData0 >= unData1)&&(unData0 <= unData2)) + { + return unData0; + } + if((unData0 >= unData2)&&(unData0 <= unData1)) + { + return unData0; + } + if((unData1 >= unData0)&&(unData1 <= unData2)) + { + return unData1; + } + if((unData1 >= unData2)&&(unData1 <= unData0)) + { + return unData1; + } + return unData2; +} + +float GH3X2X_CalcfRelativeVpp(GU32 unRawdata, GU8 uchDrv, GU8 uchGain) +{ + return ((float)unRawdata/(float)uchDrv/(float)g_usGH3x2xTiaGainR[uchGain]); +} + +void GH3X2X_StoreTiaGainAfterAgc(GU16 usGainRegValue, GU8 uchSlotNo, GU8* puchGainRecord) +{ + for(GU8 uchAdcCnt = 0; uchAdcCnt < 4; uchAdcCnt ++) + { + puchGainRecord[uchSlotNo*4 + uchAdcCnt] = (usGainRegValue>>(uchAdcCnt*4))&0x000F; + GH3X2X_INFO_LOG_PARAM_AGC("StoreTiaGainAfterAgc slot no = %d, adc no = %d, usGainRegValue = %d\r\n", uchSlotNo,uchAdcCnt,usGainRegValue); + } +} + +void GH3X_AgcGetThreshold( GU8 uchSpo2ChnlIndex, GU32* punTemp_H_Thd, GU32* punTemp_L_Thd ) +{ + if(uchSpo2ChnlIndex) // is spo2 slot + { + *punTemp_H_Thd = g_unNewAgcSpo2Trig_H_Thd; + *punTemp_L_Thd = g_unNewAgcSpo2Trig_L_Thd; + }else + { + *punTemp_H_Thd = g_unNewAgcGeneTrig_H_Thd; + *punTemp_L_Thd = g_unNewAgcGeneTrig_L_Thd; + } +} + +#if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 +void Gh3x2xNewAgcSubChnlModuleReset(void) +{ + #if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 + GH3X2X_Memset((GU8*)g_pstGh3x2xNewAgcSubChnlRxInfoEntity,0,(GU16)GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT*sizeof(STGh3x2xNewAgcSubChnlRxInfo)); + #endif +} + + +GU8 GH3x2xNewAgcSetNewSubChnl(GU8 uchSlotNo, GU8 uchRxEn, STGh3x2xAgcInfo *STGh3x2xAgcInfo) +{ + GU8 uchSetSuccess = 1; + for(GU8 uchRxCnt = 0; uchRxCnt < 4; uchRxCnt ++) + { + if(uchRxEn&(1 << uchRxCnt)) + { + uchSetSuccess = 0; + for(GU8 uchChnlCnt = 0; uchChnlCnt < GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT; uchChnlCnt ++) + { + STGh3x2xNewAgcSubChnlRxInfo *pstSTGh3x2xNewAgcSubChnlRxInfo = &(g_pstGh3x2xNewAgcSubChnlRxInfoEntity[uchChnlCnt]); + if(0 == pstSTGh3x2xNewAgcSubChnlRxInfo->uchEn) + { + pstSTGh3x2xNewAgcSubChnlRxInfo->uchEn = 1; + pstSTGh3x2xNewAgcSubChnlRxInfo->uchSlotAdcNo = (uchSlotNo << 2) + uchRxCnt; + //read current gain + pstSTGh3x2xNewAgcSubChnlRxInfo ->uchCurrentGain = GH3x2xGetAgcReg(GH3X2X_AGC_REG_TIA_GAIN_RX0 + uchRxCnt, uchSlotNo); + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] Sub chnl current Gain = %d, Slot = %d, Rx = %d\r\n",pstSTGh3x2xNewAgcSubChnlRxInfo ->uchCurrentGain,uchSlotNo,uchRxCnt); + pstSTGh3x2xNewAgcSubChnlRxInfo ->usTrigeUpLimitForBiggerGain = GH3x2xCalTrigerUpLimitForBiggerGain(pstSTGh3x2xNewAgcSubChnlRxInfo ->uchCurrentGain, uchSlotNo); + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] usTrigeUpLimitForBiggerGain = %d, Slot = %d, Rx = %d\r\n",((GU32)pstSTGh3x2xNewAgcSubChnlRxInfo ->usTrigeUpLimitForBiggerGain)<<8,uchSlotNo,uchRxCnt); + GH3X2X_StoreRxTiaGainAfterAgc(pstSTGh3x2xNewAgcSubChnlRxInfo ->uchCurrentGain, uchSlotNo, uchRxCnt, STGh3x2xAgcInfo->uchTiaGainAfterSoftAgc); + uchSetSuccess = 1; + break; + } + } + if(0 == uchSetSuccess) + { + GH3X2X_DEBUG_LOG_PARAM("[NewAgc] Set new sub chnl fail !!! Slot = %d, Rx = %d\r\n",uchSlotNo,uchRxCnt); + while(1); + } + } + } + return uchSetSuccess; +} + +#if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 +void GH3X2X_NewAgcSubChnlGainAdj(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo) +{ + for(GU8 uchChnlCnt = 0; uchChnlCnt < GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT; uchChnlCnt ++) + { + GU16 usAnalysisDiscardLen; + GU16 usAnalysisEndLen; + GU8 uchSlotCnt; + GU8 uchSlotIdx; + GU8 uchAdcNo; + GU32 unTempTrigThd_L; + GU32 unTempTrigThd_H; + STGh3x2xNewAgcSubChnlRxInfo *pstSTGh3x2xNewAgcSubChnlRxInfo = &(g_pstGh3x2xNewAgcSubChnlRxInfoEntity[uchChnlCnt]); + uchSlotIdx = pstSTGh3x2xNewAgcSubChnlRxInfo ->uchSlotAdcNo >> 2; + uchAdcNo = pstSTGh3x2xNewAgcSubChnlRxInfo ->uchSlotAdcNo&0x03; + uchSlotCnt = GH3X2X_NewAgcFindSubChnlSlotInfo(uchSlotIdx); + GU16 usSampleRate = g_pstGh3x2xNewAgcMainChnlMeanInfoEntity[uchSlotCnt].usSampleRate; + GU8 uchTiaGainLimit = g_pstGh3x2xNewAgcMainChnlInfoEntity[uchSlotCnt].uchTiaGainUpLimit; + usAnalysisDiscardLen = (usSampleRate<<1)/5; // 2/5 Fs + usAnalysisEndLen = usAnalysisDiscardLen + usSampleRate * GH3X2X_NEW_AGC_SUB_CHNNL_ANAYLSIS_TIME_SEC; + + GH3X_AgcGetThreshold(g_pstGh3x2xNewAgcMainChnlInfoEntity[uchSlotCnt].uchSpo2ChnlIndex,&unTempTrigThd_H, &unTempTrigThd_L); + + if(pstSTGh3x2xNewAgcSubChnlRxInfo ->uchEn) + { + // prevent unRawdataSum(GU32) overflow + if( (usAnalysisEndLen - usAnalysisDiscardLen) > 200 ) + { + usAnalysisDiscardLen = usAnalysisEndLen - 200; // maximum number of accumulated rawdata is 200 + } + + for (GU16 usIndex = 0; usIndex < usFifoLen; usIndex += GH3X2X_FIFO_RAWDATA_SIZE) + { + GU32 unFifoVal; + GU8 uchSlotAdcNo; + GU32 unDataRaw; + unFifoVal = GH3X2X_MAKEUP_DWORD(puchReadFifoBuffer[usIndex], puchReadFifoBuffer[usIndex + 1], + puchReadFifoBuffer[usIndex + 2], puchReadFifoBuffer[usIndex + 3]); + uchSlotAdcNo = ((unFifoVal >> 27)&0x0000001F); + unDataRaw = GH3X2X_RAWDATA_CLEAR_ALL_FLAG(unFifoVal); + if(uchSlotAdcNo == pstSTGh3x2xNewAgcSubChnlRxInfo ->uchSlotAdcNo) + { + if(usAnalysisDiscardLen == pstSTGh3x2xNewAgcSubChnlRxInfo->usAnalysisCnt) //init + { + pstSTGh3x2xNewAgcSubChnlRxInfo ->unRawdataSum = 0; + pstSTGh3x2xNewAgcSubChnlRxInfo ->unLastLastRawdata = unDataRaw; + pstSTGh3x2xNewAgcSubChnlRxInfo ->unLastRawdata = unDataRaw; + pstSTGh3x2xNewAgcSubChnlRxInfo ->usMoreThanUpLimitPointCnt = 0; + pstSTGh3x2xNewAgcSubChnlRxInfo ->usMoreThanUpLimitPointCntForBiggerGain = 0; + } + if(pstSTGh3x2xNewAgcSubChnlRxInfo->usAnalysisCnt < usAnalysisEndLen) //analysising + { + GU32 unTempRawdata = GH32x2xMedSel(pstSTGh3x2xNewAgcSubChnlRxInfo ->unLastLastRawdata, pstSTGh3x2xNewAgcSubChnlRxInfo ->unLastRawdata, unDataRaw); + if(usAnalysisDiscardLen == pstSTGh3x2xNewAgcSubChnlRxInfo->usAnalysisCnt) + { + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] sub chnl unTempRawdata = %d, Slot = %d, rx = %d\r\n",unTempRawdata, uchSlotIdx, uchAdcNo); + } + pstSTGh3x2xNewAgcSubChnlRxInfo ->unRawdataSum += unTempRawdata; + if(unTempRawdata > unTempTrigThd_H) + { + pstSTGh3x2xNewAgcSubChnlRxInfo->usMoreThanUpLimitPointCnt ++; + } + if((unTempRawdata >> 8) > pstSTGh3x2xNewAgcSubChnlRxInfo->usTrigeUpLimitForBiggerGain) + { + pstSTGh3x2xNewAgcSubChnlRxInfo->usMoreThanUpLimitPointCntForBiggerGain ++; + } + pstSTGh3x2xNewAgcSubChnlRxInfo ->unLastLastRawdata = pstSTGh3x2xNewAgcSubChnlRxInfo ->unLastRawdata; + pstSTGh3x2xNewAgcSubChnlRxInfo ->unLastRawdata = unDataRaw; + pstSTGh3x2xNewAgcSubChnlRxInfo->usAnalysisCnt ++; + } + else //anlysis finished + { + GU32 unAvaRawdata; + GU16 unRealAnaylsisNum = usAnalysisEndLen - usAnalysisDiscardLen; + GU8 uchNextGain = 0xFF; + GU8 uchCurrentGain = pstSTGh3x2xNewAgcSubChnlRxInfo ->uchCurrentGain; + unAvaRawdata = pstSTGh3x2xNewAgcSubChnlRxInfo ->unRawdataSum/unRealAnaylsisNum; + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] sub chnl rawdata ava = %d,DownLimit = %d, Slot = %d, rx = %d\r\n",unAvaRawdata, unTempTrigThd_L,uchSlotIdx, uchAdcNo); + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] usMoreThanUpLimitPointCnt = %d,UpLimit = %d, Slot = %d, rx = %d\r\n",pstSTGh3x2xNewAgcSubChnlRxInfo ->usMoreThanUpLimitPointCnt, unTempTrigThd_H,uchSlotIdx, uchAdcNo); + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] usMoreThanUpLimitPointCntForBiggerGain = %d,UpLimit = %d, Slot = %d, rx = %d\r\n",pstSTGh3x2xNewAgcSubChnlRxInfo ->usMoreThanUpLimitPointCntForBiggerGain, ((GU32)pstSTGh3x2xNewAgcSubChnlRxInfo->usTrigeUpLimitForBiggerGain)<<8, uchSlotIdx, uchAdcNo); + if(pstSTGh3x2xNewAgcSubChnlRxInfo ->usMoreThanUpLimitPointCnt > (unRealAnaylsisNum >> 3)) // 1/8 points is bigger than trige up limit + { + if(uchCurrentGain > 0) + { + uchNextGain = uchCurrentGain - 1; + } + } + if((pstSTGh3x2xNewAgcSubChnlRxInfo ->usMoreThanUpLimitPointCntForBiggerGain < (unRealAnaylsisNum >> 3))&&(unAvaRawdata < unTempTrigThd_L)) + { + if(uchCurrentGain < uchTiaGainLimit) + { + uchNextGain = uchCurrentGain + 1; + } + } + if(0xFF != uchNextGain) + { + GH3X2X_INFO_LOG_PARAM_AGC("[NewAgc] sub chnl gain change: NewGain = %d, OldGain = %d, Slot = %d, rx = %d\r\n",uchNextGain,uchCurrentGain, uchSlotIdx, uchAdcNo); + GH3x2xSetAgcReg(GH3X2X_AGC_REG_TIA_GAIN_RX0 + uchAdcNo, uchSlotIdx, uchNextGain); + pstSTGh3x2xNewAgcSubChnlRxInfo ->uchCurrentGain = uchNextGain; + pstSTGh3x2xNewAgcSubChnlRxInfo ->usTrigeUpLimitForBiggerGain = GH3x2xCalTrigerUpLimitForBiggerGain(uchNextGain, uchSlotIdx); + GH3X2X_StoreRxTiaGainAfterAgc(uchNextGain, uchSlotIdx, uchAdcNo, STGh3x2xAgcInfo->uchTiaGainAfterSoftAgc); + } + pstSTGh3x2xNewAgcSubChnlRxInfo->usAnalysisCnt = 0; + break;// 完成一次均值计算后面的数据丢弃 + } + } + } + } + } +} + +#endif +#endif + + +/*********************************************self-test function start*****************************************/ +#define GH3X2X_SPO2_SELF_TEST 0 + +#if GH3X2X_SPO2_SELF_TEST +const GU32 g_uchSpo2AgcSelftestSlotAdc = 0x01; //slot0, adc1 +const GU32 g_usSpo2AgcFifoLen = 25*4; +const GU32 g_unSpo2AgcRawdata[] = +{ + 10111744,9818116,10074798,9832931,10038819,9812989,10067119,9791632,10220862,9843610,9888564,9974512,10041146,10117796,9858828,10260863,9900963,10159857,10259720,10054459,10247477,9957985,10078474,9916146,9821879 +}; + +GU8 g_uchSpo2AgcFifoBuffer[4*100]; + +void GH3X2X_Spo2AgcFifoDataGen(void) +{ + for (GU16 usIndex = 0; usIndex < g_usSpo2AgcFifoLen; usIndex += GH3X2X_FIFO_RAWDATA_SIZE) + { + if(usIndex >= sizeof(g_uchSpo2AgcFifoBuffer)) + { + break; + } + g_uchSpo2AgcFifoBuffer[usIndex + 0] = (g_uchSpo2AgcSelftestSlotAdc<<3); + g_uchSpo2AgcFifoBuffer[usIndex + 1] = (0x000000FF&(g_unSpo2AgcRawdata[usIndex/4] >> 16)); + g_uchSpo2AgcFifoBuffer[usIndex + 2] = (0x000000FF&(g_unSpo2AgcRawdata[usIndex/4] >> 8)); + g_uchSpo2AgcFifoBuffer[usIndex + 3] = (0x000000FF&(g_unSpo2AgcRawdata[usIndex/4] >> 0)); + } +} +#endif +/*********************************************self-test function end*****************************************/ + + +/**************************************************************** +* Description: calculate mean value of main channel +* Input: rawdata +* Return: none +******************************************************************/ +static void GH3X2X_NewAgcMainChnlMeanValueCal(GU8* puchReadFifoBuffer, GU16 usFifoLen, GU32 *punRawdataMean, GU8 *pAdjFlag) +{ + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_NEW_AGC_SLOT_NUM_LIMIT; uchSlotCnt ++) + { + STGh3x2xNewAgcMainChnlInfo *pstAgcMainChnlInfo = &g_pstGh3x2xNewAgcMainChnlInfoEntity[uchSlotCnt]; + GU8 uchMainChnlSlotAdcNo = pstAgcMainChnlInfo ->uchSlotAdc; + + if(pstAgcMainChnlInfo ->uchEnable) // is enabled slot + { + GU32 unTemp_Trig_H_Thd; + GU32 unTemp_Trig_L_Thd; + GU32 unTemp_Ideal_value; + GU16 usAnalysisEndLen; + GU16 usAnalysisDiscardLenAdjust = 0; + GU16 usAnalysisDiscardLenTrige; + GU32 TrigeMean = 0; + + if(pstAgcMainChnlInfo->uchSpo2ChnlIndex) // is spo2 slot + { + unTemp_Ideal_value= g_unNewAgcSpo2Ideal_value; + }else + { + unTemp_Ideal_value= g_unNewAgcGeneIdeal_value; + } + GH3X_AgcGetThreshold( pstAgcMainChnlInfo->uchSpo2ChnlIndex, &unTemp_Trig_H_Thd, &unTemp_Trig_L_Thd); + + STGh3x2xNewAgcMainChnlMeanInfo *pstNewAgcMainChnlMeanInfo = &g_pstGh3x2xNewAgcMainChnlMeanInfoEntity[uchSlotCnt]; + STGh3x2xNewAgcMainChnlIdaelAdjInfo *pstNewAgcMainChnlIdaelAdjInfo = &g_pstGh3x2xNewAgcMainChnlIdaelAdjInfoEntity[uchSlotCnt]; + GU16 usSampleRate = pstNewAgcMainChnlMeanInfo->usSampleRate; + usAnalysisEndLen = (usSampleRate<<2)/5; // 4/5 Fs + usAnalysisDiscardLenTrige = (usSampleRate<<1)/5; // drop the first 2/5 data + //have agc motion at last fifo read period or first init + if(pstNewAgcMainChnlMeanInfo->uchHaveAgcAtLastReadPrd) + { + usAnalysisDiscardLenAdjust = (usSampleRate<<1)/5; // drop the first 2/5 data + //// After AGC, the previous data is drop to calcluate precise mean + if(!pstNewAgcMainChnlMeanInfo->uchDropFlag) + { // The frame count is only cleared for the first time to prevent data num cannot to be SampleRate + pstNewAgcMainChnlMeanInfo->usAnalysisCnt = 0; + pstNewAgcMainChnlMeanInfo->uchDropFlag = 1; + } + } + //The data fluctuates when initializing the early stage + if(!pstNewAgcMainChnlIdaelAdjInfo->uchIniteFirst) + { + usAnalysisDiscardLenAdjust = (usSampleRate<<1)/5; // drop the first 2/5 data + } + + // prevent unSumAdjust(GU32) overflow + if( (usAnalysisEndLen - usAnalysisDiscardLenAdjust) > 200 ) + { + usAnalysisDiscardLenAdjust = usAnalysisEndLen - 200; // maximum number of accumulated rawdata is 200 + } + + if( (usAnalysisEndLen - usAnalysisDiscardLenTrige) > 200 ) + { + usAnalysisDiscardLenTrige = usAnalysisEndLen - 200; + } + + for (GU16 usIndex = 0; usIndex < usFifoLen; usIndex += GH3X2X_FIFO_RAWDATA_SIZE) + { + GU32 unFifoVal; + GU8 uchSlotAdcNo; + GU32 unDataRaw; + unFifoVal = GH3X2X_MAKEUP_DWORD(puchReadFifoBuffer[usIndex], puchReadFifoBuffer[usIndex + 1], + puchReadFifoBuffer[usIndex + 2], puchReadFifoBuffer[usIndex + 3]); + uchSlotAdcNo = ((unFifoVal >> 27)&0x0000001F); + unDataRaw = GH3X2X_RAWDATA_CLEAR_ALL_FLAG(unFifoVal); + + if(uchSlotAdcNo == uchMainChnlSlotAdcNo) + { + // begin Saturation judge + { + GU16 usSat_Check_Num_Max = (usSampleRate<<2) + usSampleRate; //// 5 seconds window + g_pstGh3x2xNewAgcMainChnlSat.Sat_CheckCnt[uchSlotCnt]++; + if( unDataRaw > unTemp_Trig_H_Thd) + { + g_pstGh3x2xNewAgcMainChnlSat.Sat_cnt[uchSlotCnt]++; + } + //// as soon as posible set the Saturation flag + if( g_pstGh3x2xNewAgcMainChnlSat.Sat_cnt[uchSlotCnt] >= (usSat_Check_Num_Max>>4) ) // about 8% of all checked data + { + g_pstGh3x2xNewAgcMainChnlSat.Sat_flag |= (1<= usSat_Check_Num_Max ) + { + g_pstGh3x2xNewAgcMainChnlSat.Sat_cnt[uchSlotCnt] = 0; + g_pstGh3x2xNewAgcMainChnlSat.Sat_CheckCnt[uchSlotCnt] = 0; + } + } + // end Saturation judge + + //// begin mean calculate + GH3X2X_INFO_LOG_PARAM_AGC("slotCnt=%d,MainChnlSlotAdc=%d,SlotAdc=%d,Raw=%d\r\n",uchSlotCnt,uchMainChnlSlotAdcNo,uchSlotAdcNo,unDataRaw); + + if(usAnalysisDiscardLenAdjust == pstNewAgcMainChnlMeanInfo->usAnalysisCnt) //init + { + pstNewAgcMainChnlMeanInfo->unSumAdjust = 0; + pstNewAgcMainChnlMeanInfo->unMaxRawdata = 0; + pstNewAgcMainChnlMeanInfo->unMinRawdata = 16777216; + } + + if(usAnalysisDiscardLenTrige == pstNewAgcMainChnlMeanInfo->usAnalysisCnt) //init + { + pstNewAgcMainChnlMeanInfo->unSumTrige = 0; + } + + if(pstNewAgcMainChnlMeanInfo->usAnalysisCnt < usAnalysisEndLen) //analysising + { + pstNewAgcMainChnlMeanInfo->unSumAdjust += unDataRaw; + pstNewAgcMainChnlMeanInfo->unSumTrige += unDataRaw; + pstNewAgcMainChnlMeanInfo->usAnalysisCnt++; + pstNewAgcMainChnlMeanInfo->unMaxRawdata = ((unDataRaw > pstNewAgcMainChnlMeanInfo->unMaxRawdata)? unDataRaw: pstNewAgcMainChnlMeanInfo->unMaxRawdata ); // Max of rawdata + pstNewAgcMainChnlMeanInfo->unMinRawdata = ((unDataRaw < pstNewAgcMainChnlMeanInfo->unMinRawdata)? unDataRaw: pstNewAgcMainChnlMeanInfo->unMinRawdata ); // Min of rawdata + } + else //anlysis finished calculate mean and judge whether AGC + { + // mean value to calculate gain and current + if(usAnalysisEndLen > usAnalysisDiscardLenAdjust) + { + punRawdataMean[uchSlotCnt] = pstNewAgcMainChnlMeanInfo->unSumAdjust/(usAnalysisEndLen - usAnalysisDiscardLenAdjust); + TrigeMean = pstNewAgcMainChnlMeanInfo->unSumTrige / (usAnalysisEndLen - usAnalysisDiscardLenTrige); + }else // The normal case will not be executed, in case the division by 0 in abnormal case + { + punRawdataMean[uchSlotCnt] = unDataRaw; + TrigeMean = unDataRaw; + } + pstNewAgcMainChnlMeanInfo ->unRawdataMean = punRawdataMean[uchSlotCnt]; + pstNewAgcMainChnlMeanInfo->usAnalysisCnt=0; + // The mean calculation key variable is cleared (Prevent mean calculation from being too small:Accumulation lost some data, but numble of raw is all) + usAnalysisDiscardLenAdjust = 0; + pstNewAgcMainChnlMeanInfo->uchHaveAgcAtLastReadPrd = 0; // clear after caculate mean!!! + //// end mean calculate + + ///////////////////// whether AGC and adjust the mean value to calculate gain and current + if( (TrigeMean < unTemp_Trig_L_Thd) || (TrigeMean > unTemp_Trig_H_Thd) ) + { + *pAdjFlag |= (1<unMaxRawdata > unTemp_Trig_H_Thd) + { + /////////// Pay attention to data truncation, use 64-bi + unTempMean = (GS64)unTemp_Ideal_value*(GS64)(pstNewAgcMainChnlMeanInfo->unMaxRawdata)/15099494; // to adjust the max data to (0.8*2^23 + 2^23) + *pAdjFlag |= (1< unTemp_Ideal_value) + { + // adjust the mean value to calculate gain and current (reduce the DC amount) + punRawdataMean[uchSlotCnt] = ( (punRawdataMean[uchSlotCnt]>unTempMean)? punRawdataMean[uchSlotCnt]:unTempMean ); + *pAdjFlag |= (1<unMaxRawdata > unTemp_Trig_H_Thd) + { + punRawdataMean[uchSlotCnt] = unTempMean; // Increasing the mean value to reduce the DC amount + } + } + //////////////////////////////////////////////////// + //////////////begin ideal value adjust + if( (!((*pAdjFlag) & (1<unRawdataMean*g_uchAgcConvergence_level < (unTemp_Ideal_value*(g_uchAgcConvergence_level-1)) ) \ + || (pstNewAgcMainChnlMeanInfo->unRawdataMean*g_uchAgcConvergence_level > (unTemp_Ideal_value*(g_uchAgcConvergence_level+1)))) \ + &&( 10*pstNewAgcMainChnlMeanInfo->unMaxRawdata< 12*pstNewAgcMainChnlMeanInfo->unMinRawdata) ) + { + if( !pstNewAgcMainChnlIdaelAdjInfo->uchIniteFirst ) //// Inite First time + { + pstNewAgcMainChnlIdaelAdjInfo->uchIniteFirst = 1; + *pAdjFlag |= (1<uchSeconsCnt++; + if(pstNewAgcMainChnlIdaelAdjInfo->uchSeconsCnt >= 19) + { + *pAdjFlag |= (1<uchSeconsCnt = 0; + } + } + } + else + { + pstNewAgcMainChnlIdaelAdjInfo->uchSeconsCnt = 0; + } + } + else + { + pstNewAgcMainChnlIdaelAdjInfo->uchSeconsCnt = 0; + } + pstNewAgcMainChnlIdaelAdjInfo->uchIniteFirst = 1; //// Must be set to 1 after the first second!!! + ////end ideal value adjust + GH3X2X_INFO_LOG_PARAM_AGC("Mean cal: Slot_num = %d, Rawmean = %d, Adjmean = %d \r\n", uchSlotCnt,pstNewAgcMainChnlMeanInfo->unRawdataMean, punRawdataMean[uchSlotCnt]); + GH3X2X_INFO_LOG_PARAM_AGC("Sat flag: SatCnt = %d, SatCheck = %d, Satflag = %d\r\n", g_pstGh3x2xNewAgcMainChnlSat.Sat_cnt[uchSlotCnt], g_pstGh3x2xNewAgcMainChnlSat.Sat_CheckCnt[uchSlotCnt], g_pstGh3x2xNewAgcMainChnlSat.Sat_flag); + GH3X2X_INFO_LOG_PARAM_AGC("Ideal adjust: SeconsCnt = %d\r\n", pstNewAgcMainChnlIdaelAdjInfo->uchSeconsCnt); + GH3X2X_INFO_LOG_PARAM_AGC("Adj flag: Slot_num = %d, Trigmean = %d, L_Thd = %d, H_Thd = %d, Adjflag = %d\r\n", uchSlotCnt,TrigeMean, unTemp_Trig_L_Thd, unTemp_Trig_H_Thd, *pAdjFlag); + g_pstGh3x2xNewAgcMainChnlSat.Sat_flag &= (~(1<uchBakTiaGain; + GU8 uchGainUpLimit = pstAgcMainChnlInfo->uchTiaGainUpLimit; + GU8 uchLedCurrentMin = pstAgcMainChnlInfo->uchBakRegLedCurrentMin; + GU8 uchLedCurrentMax = pstAgcMainChnlInfo->uchBakRegLedCurrentMax; + GU8 uchCurrentDrv = pstAgcMainChnlInfo->uchCurrentDrv; + GU8 uchCurrentTiaGain = pstAgcMainChnlInfo->uchCurrentTiaGain; + + GU8 uchNewGain = uchDefaultGain; + GU32 unIdealRawdata_no; + GU32 unTempDrvCurrent; + GU8 uchChangeFlag = 0; //bit0: drv current flag bit1: gain flag + GU8 uchCalFinish = 0; + GU32 unTrigUpLimit; + GU8 unCalNum = 12; + + if(0 != pstAgcMainChnlInfo->uchSpo2ChnlIndex) // is spo2 slot + { + unTrigUpLimit = g_unNewAgcSpo2Trig_H_Thd; + unIdealRawdata_no= g_unNewAgcSpo2Ideal_value - 8388608; + }else + { + unTrigUpLimit = g_unNewAgcGeneTrig_H_Thd; + unIdealRawdata_no = g_unNewAgcGeneIdeal_value - 8388608; + } + + GH3X2X_INFO_LOG_PARAM_AGC("Drv cal: UpLimit = %d, Mean = %d, LastMean = %d\r\n",unTrigUpLimit, pstMainChnlExtralInfo->unRawdataMean, pstMainChnlExtralInfo->unLastRawdataMean); + // reduce rawdata as soon as posible + if((unTrigUpLimit < pstMainChnlExtralInfo->unRawdataMean)&&(unTrigUpLimit < pstMainChnlExtralInfo->unLastRawdataMean)&&(uchCurrentTiaGain > 0)) + { + uchNewGain = 0; + unTempDrvCurrent = uchLedCurrentMin; + uchCalFinish = 1; + } + pstMainChnlExtralInfo ->unLastRawdataMean = pstMainChnlExtralInfo ->unRawdataMean; + + if(0 == uchCalFinish) + { + //remove offset + if(CurRawdata > (8388608 + 2048)) //// Can't open DC Cance !!! + { + CurRawdata -= 8388608; + } + else + { + //The value may be less than 2^23, preventing division by 0 + CurRawdata = 2048; // Take an appropriately large number to prevent calculated DRV current overflow 32bit + } + //Rawdata stretch (The principle of magnification: the mean divided by the ideal target value is the data reduction factor ) + if(CurRawdata < 8000000) + { + } + else if(CurRawdata < 8100000) + { + CurRawdata = 8000000 + (CurRawdata - 8000000)*6; + } + else if(CurRawdata < 8200000) + { + CurRawdata = 8000000 + ((CurRawdata - 8000000)<<3); + } + else + { + // The more saturated the data, the bigger the stretch, the key is that the data is really saturated + CurRawdata = 8000000 + (CurRawdata - 8000000)*14; // Blood oxygen drops 1 times, heart rate drops 2.5 times + } + + //find new drv current and gain + do + { + unTempDrvCurrent = (GS64)(((GU32)uchCurrentDrv*(GU32)g_usGH3x2xTiaGainR[uchCurrentTiaGain]))* \ + (GS64)unIdealRawdata_no/g_usGH3x2xTiaGainR[uchNewGain]/CurRawdata; + + GH3X2X_INFO_LOG_PARAM_AGC("Drv cal %d: CurrentDrv=%d, CurrentGain=%d, IdealRawdata_no=%d\r\n",uchMainChnlInfoIndex, uchCurrentDrv, uchCurrentTiaGain, unIdealRawdata_no); + GH3X2X_INFO_LOG_PARAM_AGC("Drv cal %d: TempDrvCurrent=%d, NewGain=%d, Meanraw=%d, CurRawdata=%d\r\n",uchMainChnlInfoIndex,\ + unTempDrvCurrent, uchNewGain, pstMainChnlExtralInfo->unRawdataMean, CurRawdata); + + if(unTempDrvCurrent > uchLedCurrentMax) //drv is too big, need increase gain + { + if(uchNewGain < uchGainUpLimit) + { + uchNewGain ++ ; + } + else + { + unTempDrvCurrent = uchLedCurrentMax; + break; + } + } + else if(unTempDrvCurrent < uchLedCurrentMin) //drv is too small, need dncrease gain + { + if(uchNewGain > 0) + { + uchNewGain -- ; + } + else + { + unTempDrvCurrent = uchLedCurrentMin; + break; + } + } + else //got right drv + { + break; + } + unCalNum --; + } + while (unCalNum); + } + + puchIdealDrvCurrent[0] = (GU8)unTempDrvCurrent; + puchIdealGain[0] = (GU8)uchNewGain; + + if(puchIdealDrvCurrent[0] != uchCurrentDrv) + { + uchChangeFlag |= 0x01; +// GH3X2X_INFO_LOG_PARAM_AGC("Drv change %d: CurrentDrv=%d, IdealDrv=%d\r\n",uchMainChnlInfoIndex, uchCurrentDrv, puchIdealDrvCurrent[0]); + } + if(puchIdealGain[0] != uchCurrentTiaGain) + { + uchChangeFlag |= 0x02; +// GH3X2X_INFO_LOG_PARAM_AGC("Gain change %d: CurrentGain=%d, IdealGain=%d\r\n",uchMainChnlInfoIndex, uchCurrentTiaGain, puchIdealGain[0]); + } + + return uchChangeFlag; +} + +GU8 NewAgcMainChelFlag = 0; + +void GH3X2X_NewAgcMainChnlPro(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo) +{ + GU32 unNewAgcRawdataMeanChnl[8] = {0}; + GU8 uchAdjFlag = 0; // Local variables used as judgments must be initialized to 0 + GU8 uchNewDrvCurrent; + GU8 uchNewGain; + GU8 uchChangeFlag = 0; //bit0: drv current flag bit1: gain flag + + if(0 == GH3X2X_NEW_AGC_SLOT_NUM_LIMIT) + { + return; + } + +#if GH3X2X_SPO2_SELF_TEST + + GH3X2X_Spo2AgcFifoDataGen(); + puchReadFifoBuffer = g_uchSpo2AgcFifoBuffer; + usFifoLen = g_usSpo2AgcFifoLen; +#endif + + GH3X2X_NewAgcMainChnlMeanValueCal( puchReadFifoBuffer,usFifoLen,unNewAgcRawdataMeanChnl,&uchAdjFlag); // caculate mean and whther adjust gain current + + for(GU8 uchSlotCnt = 0; uchSlotCnt < GH3X2X_NEW_AGC_SLOT_NUM_LIMIT; uchSlotCnt ++) + { + if( uchAdjFlag & (1<uchSlotAdc >> 2) & 0x0f); + if(uchChangeFlag&0x02) //write tia gain to chip + { + GH3x2xSetAgcReg(GH3X2X_AGC_REG_TIA_GAIN_RX0 + pstAgcMainChnlInfo ->uchBakRegAgcSrc, uchSlotIdx, uchNewGain); + pstAgcMainChnlInfo->uchCurrentTiaGain = uchNewGain; + GH3X2X_StoreRxTiaGainAfterAgc(uchNewGain, uchSlotIdx, pstAgcMainChnlInfo ->uchBakRegAgcSrc, STGh3x2xAgcInfo->uchTiaGainAfterSoftAgc); + GH3X2X_INFO_LOG_PARAM_AGC("AGC Change gain Slotcfg=%d, AgcSrc=%d, NewGain=%d\r\n", uchSlotIdx,pstAgcMainChnlInfo->uchBakRegAgcSrc, uchNewGain); + } + if(uchChangeFlag&0x01) //write drv current to chip + { + //change drv0/1 + pstAgcMainChnlInfo ->uchCurrentDrv = uchNewDrvCurrent; + + if((pstAgcMainChnlInfo ->uchBakRegAgcEn)&0x01) + { + GH3x2xSetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_DRV0, uchSlotIdx, uchNewDrvCurrent); + GH3X2X_StoreDrvCurrentAfterAgc(pstAgcMainChnlInfo ->uchCurrentDrv, uchSlotIdx,0,STGh3x2xAgcInfo->uchDrvCurrentAfterSoftAgc); + } + if((pstAgcMainChnlInfo ->uchBakRegAgcEn)&0x02) + { + GH3x2xSetAgcReg(GH3X2X_AGC_REG_LED_CURRENT_DRV1, uchSlotIdx, uchNewDrvCurrent); + GH3X2X_StoreDrvCurrentAfterAgc(pstAgcMainChnlInfo ->uchCurrentDrv, uchSlotIdx,1,STGh3x2xAgcInfo->uchDrvCurrentAfterSoftAgc); + } + #if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 + GH3x2xNewAgcSubChnlClearAnalysisCntAndSetGain(uchSlotIdx, 0x0F, 0xFF); //clear all rx analysis cnt in this slot + #endif + GH3X2X_INFO_LOG_PARAM_AGC("AGC Change Current Slotcfg=%d, AgcEn=%d, NewCurrent=%d\r\n", uchSlotIdx,pstAgcMainChnlInfo->uchBakRegAgcEn, uchNewDrvCurrent); + } + if(uchChangeFlag) + { + g_pstGh3x2xNewAgcMainChnlMeanInfoEntity[uchSlotCnt].uchHaveAgcAtLastReadPrd = 1; // current or gain change at last time + g_pstGh3x2xNewAgcMainChnlMeanInfoEntity[uchSlotCnt].uchDropFlag = 0; + NewAgcMainChelFlag |= (1<> (8*uchByteCnt))&0x00FF); + usByteOffset = (usRegPosi * 2) + uchByteCnt; + if(usByteOffset < sizeof(g_stSoftAgcCfg)) + { + GH3X2X_Memcpy(((GU8 *)(&g_stSoftAgcCfg)) + usByteOffset, (GU8*)(&uchByteVal), 1); + } + } +} + +/** + * @fn void GH3X2X_LedAgcReset(void) + * + * @brief reset agc parameter + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_LedAgcReset(void) +{ + GH3X2X_Memset(&g_stSoftAgcCfg, 0, sizeof(STSoftAgcCfg)); + GH3x2xNewAgcModuleReset(); +} + +/** + * @fn void GH3X2X_LedAgcProcess(GU8* puchReadFifoBuffer, GU16 usFifoLen) + * + * @brief led agc process function + * + * @attention None + * + * @param[in] puchReadFifoBuffer pointer to read fifo data buffer + * @param[in] usFifoLen read fifo data buffer length + * @param[out] None + * + * @return None + */ + +void GH3X2X_LedAgcProcess(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo) +{ + GH3X2X_INFO_LOG_PARAM_AGC("GH3X2X_LedAgcProcess call \n"); + if(usFifoLen==0) + { + return; + } + + GH3X2X_NewAgcMainChnlPro(puchReadFifoBuffer, usFifoLen,STGh3x2xAgcInfo); + +#if GH3X2X_NEW_AGC_SUB_CHNL_NUM_LIMIT > 0 + GH3X2X_NewAgcSubChnlGainAdj(puchReadFifoBuffer, usFifoLen,STGh3x2xAgcInfo); +#endif + +} + +#define GH3X2X_SOFT_AGC_VERSION "SoftAgc_V4.2.0.0" + +char* GH3X2X_GetSoftAgcVersion(void) +{ + return GH3X2X_SOFT_AGC_VERSION; +} +#endif + +#endif +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_agc/gh_agc.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_agc/gh_agc.h new file mode 100644 index 000000000..a99ecaba8 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_agc/gh_agc.h @@ -0,0 +1,178 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_soft_led_agc.h + * + * @brief gh3x2x led agc process functions + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#ifndef _GH3X2X_DRV_SOFT_LED_AGC_H_ +#define _GH3X2X_DRV_SOFT_LED_AGC_H_ + + +#include "gh_drv_config.h" +#include "gh_drv.h" + +#define GH3X2X_LED_AGC_DISABLE (0) +#define GH3X2X_LED_AGC_ENABLE (1) + + +/// led agc adc num max +#define GH3X2X_AGC_ADC_NUM_MAX (4u) + +/// led agc gain limit number +#define GH3X2X_AGC_LIMIT_NUM_MAX (4u) + +/// raw data base line value +#define GH3X2X_DATA_BASE_LINE (8388608) //2^23 + +/// sys sample rate, 32kHz +#define GH3X2X_SYS_SAMPLE_RATE (32000) +#define GH3X2X_FASTEST_SAMPLERATE_ADDR 0x0004 + +/** + * @brief soft lead result + */ +typedef struct +{ + GU8 uchAmbSampleEn : 2; /**< AMB sampling enable */ + GU8 uchAmbSlot : 3; /**< slot of amb sampling */ + GU8 uchRes : 3; /**< reserved */ +} STAmbSlotCtrl; + + /** + * @brief gain limit + */ +typedef struct +{ + GU8 uchGainLimitBg32uA : 4; /**< gain limit bg current */ + GU8 uchGainLimitBg64uA : 4; + GU8 uchGainLimitBg128uA : 4; + GU8 uchGainLimitBg256uA : 4; +} STSoftAgcGainLimit; + + /** + * @brief soft agc parameter + */ +typedef struct +{ + GU8 uchSlotxSoftAgcAdjEn; /**< soft agc enable */ + GU8 uchSlotxSoftBgAdjEn; /**< soft bg cancel adjust enable */ + STAmbSlotCtrl stAmbSlotCtrl; /**< amb slot ctrl */ + GU8 uchRes0; /**< reserved */ + GU8 uchSpo2RedSlotCfgEn; + GU8 uchSpo2IrSlotCfgEn; + STSoftAgcGainLimit stSoftAgcGainLimit; /**< soft gain limit */ + GU32 unAgcTrigThd_H; /**< trig threshold(high) of soft agc */ + GU32 unAgcTrigThd_L; /**< trig threshold(low) of soft agc */ + GU32 unAgcRestrainThd_H; /**< restrain threshold(high) of soft agc */ + GU32 unAgcRestrainThd_L; /**< restrain threshold(low) of soft agc */ +} STSoftAgcCfg; + + +void GH3X2X_LedAgcReset(void); +void GH3X2X_LedAgcPramWrite(GU16 usRegAddr, GU16 usRegData); +void GH3X2X_LedAgcInit(STGh3x2xAgcInfo *STGh3x2xAgcInfo); +void GH3X2X_LedAgcProcess(GU8* puchReadFifoBuffer, GU16 usFifoLen, STGh3x2xAgcInfo *STGh3x2xAgcInfo); +void GH3X2X_LedAgc_Close(void); +void GH3X2X_LedAgc_Open(void); + + +///* slot register ctrl index */ +//#define GH3X2X_SLOT_REG_CTRL_0 (0) /**< slot x ctrl 0 reg */ +//#define GH3X2X_SLOT_REG_CTRL_1 (1) /**< slot x ctrl 1 reg */ +//#define GH3X2X_SLOT_REG_CTRL_2 (2) /**< slot x ctrl 2 reg */ +//#define GH3X2X_SLOT_REG_CTRL_3 (3) /**< slot x ctrl 3 reg */ +//#define GH3X2X_SLOT_REG_CTRL_4 (4) /**< slot x ctrl 4 reg */ +//#define GH3X2X_SLOT_REG_CTRL_5 (5) /**< slot x ctrl 5 reg */ +//#define GH3X2X_SLOT_REG_CTRL_6 (6) /**< slot x ctrl 6 reg */ +//#define GH3X2X_SLOT_REG_CTRL_7 (7) /**< slot x ctrl 7 reg */ +//#define GH3X2X_SLOT_REG_CTRL_8 (8) /**< slot x ctrl 8 reg */ +//#define GH3X2X_SLOT_REG_CTRL_9 (9) /**< slot x ctrl 9 reg */ +//#define GH3X2X_SLOT_REG_CTRL_10 (10) /**< slot x ctrl 10 reg */ +//#define GH3X2X_SLOT_REG_CTRL_11 (11) /**< slot x ctrl 11 reg */ +//#define GH3X2X_SLOT_REG_CTRL_12 (12) /**< slot x ctrl 12 reg */ +//#define GH3X2X_SLOT_REG_CTRL_13 (13) /**< slot x ctrl 13 reg */ + +//#define GH3X2X_BG_LEVEL_BIT_MASK (0x0030) +//#define GH3X2X_ADC_BG_CANCEL_32_UA (0x0) +//#define GH3X2X_ADC_BG_CANCEL_64_UA (0x1) +//#define GH3X2X_ADC_BG_CANCEL_128_UA (0x2) +//#define GH3X2X_ADC_BG_CANCEL_256_UA (0x3) + +///// amb slot select +//#define GH3X2X_AGC_AMB_SLOT_DISABLE (0x0) +//#define GH3X2X_AGC_AMB_SLOT_USER_DEFINED (0x1) +//#define GH3X2X_AGC_AMB_SLOT_FOLLOW_CFG (0x2) + +///// get bits data +//#define GH3X2X_GET_REG_BITS_U16(reg_data, lsb, msb) (((reg_data) & ((0xFFFF << (lsb)) & \ +// (0xFFFF >> (15 - (msb))))) >> (lsb)) + +///// set bits data +//#define GH3X2X_SET_REG_BITS_U16(reg, lsb, msb, value) ((reg) = (((reg) & ((0xFFFF << (lsb)) ^ \ +// (0xFFFF >> (15 - (msb))))) | ((value) << (lsb)))) + +///// get adc gain +//#define GH3X2X_GET_ADC_GAIN(reg_data, adc_no) GH3X2X_GET_REG_BITS_U16((reg_data), ((adc_no) * 4), \ +// ((adc_no) * 4 + 3)) + +///// set adc gain +//#define GH3X2X_SET_ADC_GAIN(reg_data, adc_no, gain) GH3X2X_SET_REG_BITS_U16((reg_data), ((adc_no) * 4), \ +// ((adc_no) * 4 + 3), (gain)) + +///// get bg cancel i_dacfs +//#define GH3X2X_GET_BGC_I_DACFS(reg_data, adc_no) GH3X2X_GET_REG_BITS_U16((reg_data), ((adc_no) << 1), \ +// ((adc_no) * 2 + 1)) + +///// set bg cancel i_dacfs +//#define GH3X2X_SET_BGC_I_DACFS(reg_data, adc_no, i_dacfs) GH3X2X_SET_REG_BITS_U16((reg_data), ((adc_no) * 2), \ +// ((adc_no) * 2 + 1), (i_dacfs)) +// +//#define ABS(x) ((x) > 0 ? (x) : -(x)) + +///// transfer int to float +//#define GH3X2X_TRANS_INT_TO_FLOAT (1.0f) + +///// agc calc seconds (250ms) +//#define GH3X2X_AGC_CALC_SECONDS (0.25f) + +///// agc bgc donw cnt, 5s +//#define GH3X2X_AGC_BGC_DOWN_CNT (20) + +///// slot tia gain val min +//#define GH3X2X_AGC_GAIN_MIN_VAL (0) + +///// slot tia gain val max, 5s, equal (GH3X2X_SLOT_TIA_GAIN_VAL_MAX - 1) +//#define GH3X2X_AGC_GAIN_MAX_VAL (12) + +///// Less than thr, include rawdata < thr +//#define GH3X2X_AGC_EXCD_FLAG_LESS (0x01) + +///// greater than thr, include rawdatamix > thr | rawdata > thr +//#define GH3X2X_AGC_EXCD_FLAG_GREATER (0x06) + +///// AGC failure reason +//#define GH3X2X_AGC_FAILURE_REASON_1 (0x1) +//#define GH3X2X_AGC_FAILURE_REASON_2 (0x2) +//#define GH3X2X_AGC_FAILURE_REASON_4 (0x4) +//#define GH3X2X_AGC_FAILURE_REASON_5 (0x5) +//#define GH3X2X_AGC_FAILURE_REASON_6 (0x6) + +//#define GH3X2X_AGC_CHECK_EN_BITS(x) (((x) & (0x03 << 8)) != 0) /**< check enable bits of ctrl3 */ +//#define GH3X2X_AGC_GET_SRC_BITS(x) (((x) >> 6) & 0x03) /**< get agc src bits of ctrl3 */ +//#define GH3X2X_AGC_CHECK_BG_2X2_BITS(x) (((x) & (0x03 << 4)) == 0x03) /**< check 2x2 bg lvl bits of ctrl3 */ +//#define GH3X2X_AGC_SET_SRC_BITS(x, n) (((x) & 0xFF3Fu) | ((n) << 6u)) /**< set agc src bits of ctrl3 */ + +//#define GH3X2X_AGC_GET_DONE_FAIL_BIT(x, i) (((x) >> (i)) & 0x01) /**< get tune done/fail bit of flag */ +//#define GH3X2X_AGC_REG_BIT(x, i) (((x) >> (i)) & 0x01) /**< get reg bit value */ +//#define GH3X2X_AGC_GET_RESULT_BITS(x, i) (((x) >> (i)) & 0x07) /**< get result bits of flag */ +//#define GH3X2X_AGC_RESULT_BITS_SIZE (3u) /**< one result 3 bits size of flag */ + +#endif // _GH3X2X_DRV_SOFT_LED_AGC_H_ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_ecg/gh_ecg.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_ecg/gh_ecg.c new file mode 100644 index 000000000..e77ef1b6d --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_ecg/gh_ecg.c @@ -0,0 +1,1691 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_soft_lead.c + * + * @brief gh3x2x lead process functions + * + * @version ref gh3x2x_drv_version.h + * + */ + +#include +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" +#include "gh_uprotocol.h" +#include "gh_ecg.h" +#include "gh_demo_config.h" +#include "gh_multi_sen_pro.h" + +#define GH3X2X_LEAD_OFF_SUPPORT_ECG (1) +#if GH3X2X_LEAD_OFF_SUPPORT_ECG +#define GH3X2X_LEAD_OFF_VERSION_DOUBLE 0 +#define GH3X2X_LEAD_OFF_VERSION_FLOAT 1 +#define GH3X2X_LEAD_OFF_VERSION_FIX_POINT 2 + +#define GH3X2X_LEAD_OFF_VERSION GH3X2X_LEAD_OFF_VERSION_FIX_POINT +#endif + +#define __SUPPORT_ECG_PPG_DOWNSAMP__ 1 + +#ifdef GOODIX_DEMO_PLATFORM +#define GH3X2X_DOWNSAMPLE_OPENALL 1 +#else +#define GH3X2X_DOWNSAMPLE_OPENALL 0 +#endif + + + +#if __FUNC_TYPE_ECG_ENABLE__ + +GU8 g_uchEcgCascadeEn = 0; +GU8 g_uchEcgCascadeWriteRegVerifyEn = 0; +///0: not init 1: initialized +extern GU8 g_uchEcgCascadeSlaveInitSuccess; + +//Ecg sample rate from hardware +static GU16 g_usEcgOutputFs = 0; + +/// LEADOFF_DET_DIF_THR_MV*Gain*RAWMAX/ADCRef, if GH3100 VDDTx=3.3V,ADCRef=1800,if VDDTx=1.8,ADCRef=1600; +__attribute__((used)) static GS32 g_nLeadoffDiffThrdRawData = SOFT_LEAD_OFF_DIFF_THR_DEFAULT_VAL; + +/// LEADOFF_DET_VAL_THR_MV*Gain*RAWMAX/ADCRef, if GH3100 VDDTx=3.3V,ADCRef=1800,if VDDTx=1.8,ADCRef=1600; +__attribute__((used)) static GS32 g_nLeadoffPeakThrdRawData = SOFT_LEAD_OFF_PEAK_THR_DEFAULT_VAL; + +/// lead off base thr +__attribute__((used)) static GS32 g_nLeadoffBaseThrdRawData = SOFT_LEAD_OFF_BASE_THR_DEFAULT_VAL; + +/// lead off detect moving buffer +GS32 g_nLeadOffDetEcgBuffer2Arr[LEADOFF_MOVING_NUM]; + +/// buffer to head +GS32 g_nBuf2Head = 0; + +/// valid counter +GU32 g_unValidCounter = 0; + +/// reset counter +GU32 g_unResetCounter = 0; + +/// current sum +GS32 g_nCurEcgSum = 0; + +/// lead off det init status +GU32 g_unLeadOffDetInitState2 = 0; + +/// ecg gain map, amplify 10x +static const GU8 g_uchEcgGainMapArr[] = +{ + 10, 25, 50, 100, 200 +}; + +/// adc ref map, amplify 10x +static const GU8 g_uchAdcRefMapArr[] = +{ + 16, 18 +}; + +/// lead state in soft lead module +static GU8 g_uchLeadStateInSoftLeadModule = LEAD_STATE_LEAD_OFF; + +/// down sample lead module(ECG PPG BT) +static GU8 g_uchDownSampleModule = DOWNSAMPLE_ECG; + +/// ecg or pwtt function enable +static GU8 g_uchEcgOrPwttFunctionEn = 0; + +/// ecg sampling status +GU8 g_uchEcgSampleStatus = 0; +GU8 g_uchLastEcgSampleFlag = 0; // 0: last time ecg is not sampling 1: last time ecg is sampling //G202008031001 wanpeng +GU8 g_uchIsItyp0nAPeriod = 0; // 0: current is not itype 0nA period //1: current is itype 0nA period //G202010311001 wanpeng +/// R type mode enable flag +GU8 g_uchRtypeModeEn = 1; + +STEcgLeadCfg g_stEcgLeadCfg; + +#endif + +extern void GH3X2X_CalRawdataBuf(GU8 *puchRawdata, GU16 usRawdataLen); +extern GU8 GH3X2X_CheckRawdataBuf(GU8 *puchRawdata, GU16 usRawdataLen); + +#if __FUNC_TYPE_ECG_ENABLE__ + +STAdtCfg g_stAdtModuleCfg; + +/** + * @fn void GH3X2X_AdtPramInit(void) + * + * @brief GH3X2X_AdtPramInit + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ + +void GH3X2X_AdtPramInit(void) +{ + GH3X2X_Memset(((GU8 *)(&g_stAdtModuleCfg)),0, sizeof(g_stAdtModuleCfg)); +} + +/** + * @fn void GH3X2X_AdtPramSet(GU16 usRegVal, GU8 uchRegPosi) + * + * @brief GH3X2X_AdtPramSet + * + * @attention None + * + * @param[in] usRegVal + * @param[in] uchRegPosi + * @param[out] None + * + * @return None + */ +void GH3X2X_AdtPramSet(GU16 usRegVal, GU8 uchRegPosi) +{ + + GU8 uchByteOffset; + GU8 uchByteVal; + GU8 uchByteCnt; + for(uchByteCnt = 0; uchByteCnt < 2; uchByteCnt ++) + { + uchByteVal = ((usRegVal >> (8*uchByteCnt))&0x00FF); + uchByteOffset = (uchRegPosi * 2) + uchByteCnt; + if(uchByteOffset < sizeof(g_stAdtModuleCfg)) + { + GH3X2X_Memcpy(((GU8 *)(&g_stAdtModuleCfg)) + uchByteOffset, (GU8*)(&uchByteVal), 1); + } + } +} + +void GH3X2X_WriteAdtDrvConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue) +{ + GU16 usValIndex; + switch (usVirtualRegAddr) + { + case 0x0144: + break; + case 0x0146: + break; + default: + usValIndex = (usVirtualRegAddr - GH3X2X_ADT_CONFIG0_ADDR) / GH3X2X_REG_ADDR_SIZE; + GH3X2X_AdtPramSet(usVirtualRegValue, usValIndex); + break; + } +} + +/** + * @fn GU8 GH3X2X_ElectrodeWearRevertDebugModeIsEnabled(void) + * + * @brief Check if electrode wear revert debug mode is enabled + * + * @attention In this mode,not need report wear event,need report the number of wear electrode revert. + * + * @param[in] None + * @param[out] None + * + * @return 1: enabled, 0:disabled + */ +GU8 GH3X2X_ElectrodeWearRevertDebugModeIsEnabled(void) +{ + return g_stAdtModuleCfg.stAdtCfgByte0.uchElectrodeWearRevCntEn; +} + +#if ((defined(GH3X2X_LEAD_OFF_VERSION)) && (GH3X2X_LEAD_OFF_VERSION == GH3X2X_LEAD_OFF_VERSION_DOUBLE)) +#elif ((defined(GH3X2X_LEAD_OFF_VERSION)) && (GH3X2X_LEAD_OFF_VERSION == GH3X2X_LEAD_OFF_VERSION_FIX_POINT)) + +#define ADCREF 1800 +#define ADC_OFFSET (1<<23) +//#define IS_BIG_ENDIAN 1 //data read from GH3100 FIFO is big endian? +#define PI 3.14159265 +#define ABS(x) ( (x)>0?(x):(-(x)) ) + +#define NEEDRESAMPLE 1 +#if GH3X2X_DOWNSAMPLE_OPENALL +#define RESAMPLE_800HZ_TO_500HZ 1 +#define RESAMPLE_800HZ_TO_250HZ 1 +#define RESAMPLE_320HZ_TO_250HZ 1 +#define RESAMPLE_256HZ_TO_250HZ 1 +#else +#define RESAMPLE_800HZ_TO_500HZ 1 +#define RESAMPLE_800HZ_TO_250HZ 0 +#define RESAMPLE_320HZ_TO_250HZ 0 +#define RESAMPLE_256HZ_TO_250HZ 0 +#endif + +#if __SUPPORT_ECG_PPG_DOWNSAMP__ +#define RESAMPLE_400HZ_TO_250HZ 1 +#else +#define RESAMPLE_400HZ_TO_250HZ 0 +#endif + +#define AMP_NUM 5 + +#if RESAMPLE_256HZ_TO_250HZ +#define IQ_NUM 48 +#else +#define IQ_NUM 48 +#endif + +const int winCoef[IQ_NUM / 2] = { 0, 9580474, 38150933, 85201535, 149892663, 231069901, 327284639, 436819923, 557721094, 687830666, 824826833, 966264894, 1109620882, 1252336609, 1391865307, 1525717084, 1651503351, 1766979451, 1870084709, 1958979209, 2032076627, 2088072537, 2125967693, 2145085852}; +#define winAmpCoef 4082 +//unsigned char gscFlagFrPrev = 0; +GU32 g_nLeadOffDetIqAmpThr;//unit: uv +long long g_lLeadOffDetIqAmp; +long long g_lLeadOffDetIqAmpThrRaw; +long long g_lLeadOffDetIqAmpFrThrRaw; + +GU32 g_nLeadOffDetIqAmpDiffThr;//unit: uv +long long g_lLeadOffDetIqAmpDiff; +long long g_lLeadOffDetIqAmpDiffThrRaw; +long long g_lLeadOffDetIqAmpDiffFrThrRaw; + +int COND_VAL_VALID_TIME = 1; +GU32 g_nLeadOffDetValThr;//unit: mv +int g_LeadOffDetValThrRaw; + +#if NEEDRESAMPLE + +#define SHIFTBITS 30 + +#if RESAMPLE_800HZ_TO_500HZ + const int rsFirCoef_800_500hz[] = { 58200, 102435, 156130, 215460, 274735, 326585, 362380, 372790, 348645, 281870, 166550, 0, -216285, -475850, -766815, -1071825, -1368460, -1630170, -1827760, -1931325, -1912605, + -1747635, -1419445, -920670, -255820, 557070, 1485515, 2482735, 3488860, 4433375, 5238695, 5824850, 6114965, 6041350, 5551740, 4615280, 3227790, 1415785, -761100, -3209770, -5805610, -8396875, -10811545, -12866385, + -14377925, -15174745, -15110485, -14076620, -12014295, -8924190, -4873605, 0, 5489625, 11323885, 17176845, 22682405, 27452740, 31100030, 33260510, 33619540, 31936265, 28066360, 21981325, 13782945, 3711580, -7852615, + -20396185, -33286830, -45795550, -57125820, -66448630, -72941905, -75832375, -74437800, -68207360, -56757870, -39903755, -17678885, 9651270, 41588185, 77410100, 116192965, 156841955, 198132190, 238757000, 277381455, 312698655, 343486005, 368658785, 387318230, 398791740, 402663190 }; +#endif +#if RESAMPLE_800HZ_TO_250HZ + const int rsFirCoef_800_250hz[] = { -74905, -95385, -116975, -138740, -159540, -178080, -192900, -202440, -205060, -199120, -183040, -155365, -114830, -60455, 8370, 91845, 189655, 300920, 424150, 557225, 697345, 841065, 984315, 1122440, 1250290, 1362325, + 1452720, 1515555, 1544935, 1535220, 1481220, 1378385, 1223050, 1012615, 745780, 422705, 45175, -383265, -857210, -1369370, -1910565, -2469770, -3034240, -3589685, -4120510, -4610090, -5041145, -5396125, -5657660, -5809045, -5834740, -5720895, -5455890, + -5030825, -4440010, -3681420, -2757070, -1673325, -441140, 923805, 2401100, 3965690, 5588100, 7234765, 8868540, 10449275, 11934545, 13280495, 14442770, 15377525, 16042520, 16398240, 16409055, 16044325, 15279560, 14097430, 12488725, 10453225, 8000385, + 5149865, 1931900, -1612575, -5431990, -9464450, -13638290, -17872830, -22079425, -26162660, -30021820, -33552510, -36648435, -39203325, -41112955, -42277200, -42602135, -42002095, -40401670, -37737600, -33960495, -29036370, -22947970, -15695790, + -7298825, 2204995, 12758710, 24286615, 36694830, 49872305, 63692080, 78012930, 92681285, 107533410, 122397830, 137097950, 151454790, 165289835, 178427925, 190700125, 201946505, 212018845, 220783110, 228121755, 233935695, 238146055, 240695490, 241549195 }; +#endif + +#if RESAMPLE_400HZ_TO_250HZ +//const int rsFirCoef_250hz1[] = { 0,-24495,-56710,-95045,-136775,-178125,-214440,-240490,-250920,-240760,-205965,-144050,-54555,60475,196250,345190,497105,639650,759070,841160,872410,841285,739500,563245,314150,0,-365010,-760510,-1160685,-1535620,-1853070,-2080745,-2188790,-2152475,-1954770,-1588670,-1058960,-383360,407260,1269625,2149850,2986210,3712890,4264415,4580525,4611280,4321835,3696680,2742865,1491895,0,-1653335,-3368750,-5032125,-6521320,-7714135,-8497040,-8774130,-8475685,-7565610,-6047220,-3966715,-1413955,1479820,4547350,7593800,10407850,12774895,14491705,15381495,15308470,14190830,12011055,8822720,4752940,0,-5174080,-10455925,-15497715,-19937805,-23423930,-25637735,-26318950,-25287690,-22463185,-17877445,-11682610,-4150955,4332910,13287805,22159230,30349170,37251070,42288110,44952645,44844420,41705155,35447110,26173540,14189250,0,-15699840,-32051440,-48066690,-62673020,-74765800,-83265770,-87178475,-85652480,-78033065,-63908265,-43144325,-15908305,17323970,55775495,98391360,143876925,190749335,237400000,282164985,323399855,359555130,389248460,411329760,424935830,429531605}; +const int rsFirCoef_250hz2[] = {-20165,29190,117750,248970,420650,623445,839855,1044105,1203060,1278285,1229350,1018175,614220,0,-823490,-1832200,-2975865,-4177020,-5332555,-6318335,-6996880,-7227970,-6881615,-5852620,-4075600,-1539030,1703020,5523035,9717440,14010255,18063685,21495860,23905235,24900525,24134595,21339975,16363405,9196555,0,-10882185,-22919440,-35404830,-47478995,-58167535,-66430495,-71221570,-71553685,-66566985,-55594615,-38221750,-14333265,15853795,51776230,92531020,136902815,183411755,230379530,276010140,318480795,356037520,387089565,410296710,424643805,429497860,}; +#endif + +#if RESAMPLE_320HZ_TO_250HZ + const int rsFirCoef_320_250hz[] = {79095,936340,341760,-2712470,-2547785,4817105,8099190,-5170865,-17933790,0,30974265,15517780,-42765395,-45670380,44706790,92106715,-24021395,-152053275,-36768905,217784250,166596045,-277901355,-451953470,320248390,1667310365,2147483647,}; +#endif +#if RESAMPLE_256HZ_TO_250HZ + const int rsFirCoef_256_250hz[]={194000,77770,-331070,-632290,-254280,769680,1439880,622640,-1454740,-2779600,-1303600,2436730,4847325,2461115,-3753755,-7872475,-4310105,5424840,12120690,7126740,-7444180,-17902495,-11265025,9777230,25594875,17187555,-12359260,-35689230,-25526795,15096890,48893725,37213545,-17872685,-66356185,-53763065,20552645,90184745,77974330,-22995885,-124828195,-115908245,25065740,181561700,183974820,-26641130,-299102515,-347934030,27626950,749679370,1463910805,1761638120,}; +#endif + +GS32* rsFirCoef; +GS32* rsFirCoef1; + +STGh3x2xDownSampleCalParamInfo pstECGDownSampCalParamInfo[1]; +#if __SUPPORT_ECG_PPG_DOWNSAMP__ +STGh3x2xDownSampleCalParamInfo pstPPGDownSampCalParamInfo[1]; +#endif + +void GH3X2X_DownSampleMarcoIni(GU16 usEcgSampleRate) +{ + switch (g_usEcgOutputFs) + { + case 800: + if( usEcgSampleRate == 500) + { + pstECGDownSampCalParamInfo->uchDownSampleType = DOWNSAMPLE_800HZ_TO_500HZ; + } + else + { + pstECGDownSampCalParamInfo->uchDownSampleType = DOWNSAMPLE_800HZ_TO_250HZ; + } + break; + case 320: + if( usEcgSampleRate == 250) + { + pstECGDownSampCalParamInfo->uchDownSampleType = DOWNSAMPLE_320HZ_TO_250HZ; + } + break; + case 256: + if( usEcgSampleRate == 250) + { + pstECGDownSampCalParamInfo->uchDownSampleType = DOWNSAMPLE_256HZ_TO_250HZ; + } + break; + default: // do nothing + break; + } + + // ppg downsample ini + #if __SUPPORT_ECG_PPG_DOWNSAMP__ + pstPPGDownSampCalParamInfo->uchDownSampleType = DOWNSAMPLE_400HZ_TO_250HZ; + #endif +} + +void RsFirResetSingle(GU8 uchChipIndex, GU8 uchMode) +{ + STGh3x2xRsInfo * pstRsInfo = NULL; + GU8 uchChnNum = 0; + #if __SUPPORT_ECG_PPG_DOWNSAMP__ + if(DOWNSAMPLE_PPG == uchMode) + { + pstRsInfo = g_pstGh3x2xPPGRsInfo; + uchChnNum = g_uchPPGDownSampleChnlNumLimit; + } + #endif + + if(DOWNSAMPLE_ECG == uchMode) + { + pstRsInfo = g_pstGh3x2xEcgRsInfo; + uchChnNum = uchChipIndex+1; + } + + for( GU8 i=0; ipstFunctionInfo->uchChnlNum > 1)&&(g_uchGh3x2xEcgChnlNumLimit > 1)) + { + RsFirResetSingle(1,uchMode); + } +} + +void GH3X2X_ECGResampleConfig(GU16 usEcgSampleRate) +{ + RsFirReset(DOWNSAMPLE_ECG); + GH3X2X_DownSampleMarcoIni(usEcgSampleRate); + if(usEcgSampleRate == 500) + { + #if RESAMPLE_800HZ_TO_500HZ + if(DOWNSAMPLE_800HZ_TO_500HZ == pstECGDownSampCalParamInfo->uchDownSampleType) + { + pstECGDownSampCalParamInfo->rsFirCoef= (GS32*)rsFirCoef_800_500hz; + pstECGDownSampCalParamInfo->uchRsFirOrder = 182; + pstECGDownSampCalParamInfo->uchRsI = 5; + pstECGDownSampCalParamInfo->uchRsD = 8; + pstECGDownSampCalParamInfo->uchRsEnable = 1; + } + #endif + } + else if(usEcgSampleRate == 250) + { + #if RESAMPLE_800HZ_TO_250HZ + if(DOWNSAMPLE_800HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType) + { + pstECGDownSampCalParamInfo->rsFirCoef= (GS32*)rsFirCoef_800_250hz; + pstECGDownSampCalParamInfo->uchRsFirOrder = 250; + pstECGDownSampCalParamInfo->uchRsI = 5; + pstECGDownSampCalParamInfo->uchRsD = 16; + pstECGDownSampCalParamInfo->uchRsEnable = 1; + } + #endif + + #if RESAMPLE_320HZ_TO_250HZ + if(DOWNSAMPLE_320HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType) + { + pstECGDownSampCalParamInfo->rsFirCoef= (GS32*)rsFirCoef_320_250hz; + pstECGDownSampCalParamInfo->uchRsFirOrder = 50; + pstECGDownSampCalParamInfo->uchRsI = 1; + pstECGDownSampCalParamInfo->uchRsD = 1; + pstECGDownSampCalParamInfo->uchRsEnable = 1; + pstECGDownSampCalParamInfo->ufStep = 128; + } + #endif + + #if RESAMPLE_256HZ_TO_250HZ + if(DOWNSAMPLE_256HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType) + { + pstECGDownSampCalParamInfo->rsFirCoef= (GS32*)rsFirCoef_256_250hz; + pstECGDownSampCalParamInfo->uchRsFirOrder = 100; + pstECGDownSampCalParamInfo->uchRsI = 1; + pstECGDownSampCalParamInfo->uchRsD = 1; + pstECGDownSampCalParamInfo->uchRsEnable = 1; + pstECGDownSampCalParamInfo->ufStep = 1024; + } + #endif + } + else + { + pstECGDownSampCalParamInfo->uchRsEnable = 0; + return; + } + + if(pstECGDownSampCalParamInfo->uchRsFirOrder % 2) + { + pstECGDownSampCalParamInfo->uchRsFirCoefNum = ((pstECGDownSampCalParamInfo->uchRsFirOrder+1)/2) ; + } + else + { + pstECGDownSampCalParamInfo->uchRsFirCoefNum = ((pstECGDownSampCalParamInfo->uchRsFirOrder+2)/2); + } + pstECGDownSampCalParamInfo->uchRsBufSize = (pstECGDownSampCalParamInfo->uchRsFirOrder / pstECGDownSampCalParamInfo->uchRsI + 1); +} +#if __SUPPORT_ECG_PPG_DOWNSAMP__ +void GH3X2X_PPGResampleConfig(GU16 usPPGSampleRate) +{ + RsFirReset(DOWNSAMPLE_PPG); + GH3X2X_DownSampleMarcoIni(usPPGSampleRate); + if(usPPGSampleRate == 250) + { + #if RESAMPLE_400HZ_TO_250HZ + pstPPGDownSampCalParamInfo->rsFirCoef = (GS32*)rsFirCoef_250hz2; + pstPPGDownSampCalParamInfo->uchRsFirOrder = 126; + pstPPGDownSampCalParamInfo->uchRsI = 5; + pstPPGDownSampCalParamInfo->uchRsD = 8; + pstPPGDownSampCalParamInfo->uchRsEnable = 1; + #else + pstPPGDownSampCalParamInfo->uchRsEnable = 0; + #endif + } + else + { + pstPPGDownSampCalParamInfo->uchRsEnable = 0; + return; + } + + if(pstPPGDownSampCalParamInfo->uchRsFirOrder % 2) + { + pstPPGDownSampCalParamInfo->uchRsFirCoefNum = ((pstPPGDownSampCalParamInfo->uchRsFirOrder+1)/2) ; + } + else + { + pstPPGDownSampCalParamInfo->uchRsFirCoefNum = ((pstPPGDownSampCalParamInfo->uchRsFirOrder+2)/2); + } + pstPPGDownSampCalParamInfo->uchRsBufSize = (pstPPGDownSampCalParamInfo->uchRsFirOrder / pstPPGDownSampCalParamInfo->uchRsI + 1); +} +#else +void GH3X2X_PPGResampleConfig(GU16 usPPGSampleRate) +{ + return; +} +#endif + +void GH3X2X_LeadOffDetectResetSingleChip(GU8 uchChipIndex) +{ + int i; + STGh3x2xSoftLeadOffDetInfo * pstSoftLeadOffDetInfo = g_pstGh3x2xSoftLeadOffDetInfo + uchChipIndex; + pstSoftLeadOffDetInfo -> snCounter = 0; + pstSoftLeadOffDetInfo -> sniqCounter = 0; + pstSoftLeadOffDetInfo -> snniVal = 0; + pstSoftLeadOffDetInfo -> snnqVal = 0; + pstSoftLeadOffDetInfo -> uchFastRecoryHistory = 0; + for (i = 0; i < AMP_NUM; i++) + pstSoftLeadOffDetInfo -> snniqAmp[i] = 0; +} + +void GH3X2X_LeadOffDetectReset(void) +{ + GH3X2X_LeadOffDetectResetSingleChip(0); + if((g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchChnlNum > 1)&&(g_uchGh3x2xEcgChnlNumLimit > 1)) + { + GH3X2X_LeadOffDetectResetSingleChip(1); + } +} + +GS32 GH3X2X_LeadOffDetectInit(void) +{ + GH3X2X_ECGResampleConfig(g_usEcgOutputFs); + GH3X2X_LeadOffDetectReset(); + return 0; +} + +/** + * @fn GU8 GH3X2X_LeadOffDetect(GU8* puchFifoBuffer, GU16 usFifoBufferLen) + * + * @brief Lead off Detection, suppose the increment of normal ECG value in LEADOFF_DET_POINT_NUM+1 samples point + * not exceed LEADOFF_DET_THR_mV + * + * @attention None + * + * @param[in] puchFifoBuffer pointer to read fifo data buffer + * @param[in] usFifoBufferLen read fifo buffer len + * @param[out] None + * + * @return lead off status output + * @retval #0 not detect lead off + * @retval bit0=1 AdcValue larger than thresh + * @retval bit1=1 IQ Value larger than thresh + */ + +GU8 GH3X2X_LeadOffDetectSingleChip(GU8* puchFifoBuffer, GU16* pusFifoBufferLen, GU8 unChipIndex) +{ + GU16 usByteIndexTmp = 0; + GS32 j = 0; + GU8 uchRet = 0; + GU32 fifoVal = 0; + GS32 adcVal = 0; + GU8 flagFastRecovery = 0; + GS32 absAdcVal = 0; //ABS of adcVal + GS64 temp = 0; + + STGh3x2xSoftLeadOffDetInfo * pstSoftLeadOffDetInfo = g_pstGh3x2xSoftLeadOffDetInfo + unChipIndex; + + for (usByteIndexTmp = 0; usByteIndexTmp < *pusFifoBufferLen; usByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE) + { + if (GH3X2X_CHANNEL_MAP_GET(puchFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pchChnlMap[unChipIndex] & GH3X2X_SLOT_ADC_NUM_BITS)) + { + fifoVal = GH3X2X_MAKEUP_DWORD(puchFifoBuffer[usByteIndexTmp], puchFifoBuffer[usByteIndexTmp + 1],puchFifoBuffer[usByteIndexTmp + 2], puchFifoBuffer[usByteIndexTmp + 3]); + adcVal = (GS32)((fifoVal & 0x00FFFFFF)) - ADC_OFFSET; + flagFastRecovery = (fifoVal >> 26) & 0x01; + if(flagFastRecovery) + { + pstSoftLeadOffDetInfo->uchFastRecoryHistory = 1; + GH3X2X_DEBUG_LOG_PARAM("has fast recovery!!!!\r\n"); + } + if(0 == pstSoftLeadOffDetInfo->uchFastRecoryHistory) + { + GH3X2X_DEBUG_LOG_PARAM("Warning: No fast recovery!!!!\r\n"); + continue; + } + if (pstSoftLeadOffDetInfo-> uchFlagFrPrev != flagFastRecovery) + { + GH3X2X_LeadOffDetectReset(); + pstSoftLeadOffDetInfo->uchFastRecoryHistory = 1; + } + pstSoftLeadOffDetInfo-> uchFlagFrPrev = flagFastRecovery; + + //sample counter + if (pstSoftLeadOffDetInfo -> snCounter < 20000) + pstSoftLeadOffDetInfo -> snCounter++; + + if (flagFastRecovery == 0 && pstSoftLeadOffDetInfo -> snCounter>COND_VAL_VALID_TIME) + { + absAdcVal = ABS(adcVal); + if (absAdcVal > g_LeadOffDetValThrRaw) + uchRet |= 0x01; + } + if (pstSoftLeadOffDetInfo -> sniqCounter < IQ_NUM / 2) + { + temp = (GS64)adcVal*winCoef[pstSoftLeadOffDetInfo -> sniqCounter]; + } + else + { + temp = (GS64)adcVal*winCoef[IQ_NUM-1 - pstSoftLeadOffDetInfo -> sniqCounter]; + } + switch (pstSoftLeadOffDetInfo -> sniqCounter%4) + { + case 0: + pstSoftLeadOffDetInfo -> snniVal += temp; + break; + case 1: + pstSoftLeadOffDetInfo -> snnqVal += temp; + break; + case 2: + pstSoftLeadOffDetInfo -> snniVal -= temp; + break; + case 3: + pstSoftLeadOffDetInfo -> snnqVal -= temp; + break; + default: + break; + } + if (pstSoftLeadOffDetInfo -> sniqCounter == (IQ_NUM - 1)) + { + for (j = AMP_NUM-1; j >0; j--) + { + pstSoftLeadOffDetInfo -> snniqAmp[j] = pstSoftLeadOffDetInfo -> snniqAmp[j - 1]; + } + pstSoftLeadOffDetInfo -> snniVal = pstSoftLeadOffDetInfo -> snniVal >> 31; + pstSoftLeadOffDetInfo -> snnqVal = pstSoftLeadOffDetInfo -> snnqVal >> 31; + pstSoftLeadOffDetInfo -> snniqAmp[0] = pstSoftLeadOffDetInfo -> snniVal*(int)pstSoftLeadOffDetInfo -> snniVal + pstSoftLeadOffDetInfo -> snnqVal*(int)pstSoftLeadOffDetInfo -> snnqVal; + pstSoftLeadOffDetInfo -> snniVal = 0; + pstSoftLeadOffDetInfo -> snnqVal = 0; + + if (flagFastRecovery == 0) + { + if (pstSoftLeadOffDetInfo -> snniqAmp[0] > g_lLeadOffDetIqAmpThrRaw && pstSoftLeadOffDetInfo -> snniqAmp[1] > g_lLeadOffDetIqAmpThrRaw) + uchRet |= 0x02; + + if ((pstSoftLeadOffDetInfo -> snniqAmp[0] - pstSoftLeadOffDetInfo -> snniqAmp[2]) > g_lLeadOffDetIqAmpDiffThrRaw && (pstSoftLeadOffDetInfo -> snniqAmp[1] - pstSoftLeadOffDetInfo -> snniqAmp[2]) > g_lLeadOffDetIqAmpDiffThrRaw) + { + if(pstSoftLeadOffDetInfo ->snCounter > 2 * IQ_NUM) + { + uchRet |= 0x04; + } + } + } + else + { + if (pstSoftLeadOffDetInfo -> snniqAmp[0] > g_lLeadOffDetIqAmpFrThrRaw && pstSoftLeadOffDetInfo -> snniqAmp[1] > g_lLeadOffDetIqAmpFrThrRaw) + uchRet |= 0x08; + } + } + pstSoftLeadOffDetInfo -> sniqCounter++; + pstSoftLeadOffDetInfo -> sniqCounter = pstSoftLeadOffDetInfo -> sniqCounter%(IQ_NUM); + } // end of if (GH3X2X_CHANNEL_MAP_GET(puchFifoBuffer[usByteIndexTmp]) == g_uchEcgLeadChannelMap) + } // end of for (usByteIndexTmp = 0; usByteIndexTmp < usFifoBufferLen; usByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE) + + return uchRet; +} + +#endif//end #elif((defined(GH3X2X_LEAD_OFF_VERSION)) && (GH3X2X_LEAD_OFF_VERSION == GH3X2X_LEAD_OFF_VERSION_FIX_POINT)) + + +GU8 GH3X2X_GetSoftLeadDetMode(void) +{ + return g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchSoftLeadDetMode; +} + +/** + * @fn void GH3X2X_SoftLeadOffEventProManalMode(void) + * + * @brief soft lead off evt process @ manal mode + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_SoftLeadOffEventProManalMode(void) +{ + ECG_LEAD_DET_EN_CONFIG(0); + ECG_LEAD_DET_EN_CONFIG(1); + GH3X2X_CascadeEcgSlaverLeadDectDisEx(); +} + +void GH3X2X_ConfigLeadOffThr(GU32 uIQAmpThr, GU32 uIQAmpDiffThr,GU32 uValThr) +{ + g_nLeadOffDetIqAmpThr = uIQAmpThr; + g_lLeadOffDetIqAmp = ((long long)g_nLeadOffDetIqAmpThr * 20 * ADC_OFFSET / ADCREF/1000*IQ_NUM*1000/winAmpCoef); + g_lLeadOffDetIqAmpThrRaw = (g_lLeadOffDetIqAmp*g_lLeadOffDetIqAmp); + g_lLeadOffDetIqAmpFrThrRaw = (g_lLeadOffDetIqAmp*g_lLeadOffDetIqAmp / 20 / 20); + + g_nLeadOffDetIqAmpDiffThr = uIQAmpDiffThr; + g_lLeadOffDetIqAmpDiff = ((long long)g_nLeadOffDetIqAmpDiffThr * 20 * ADC_OFFSET / ADCREF/1000*IQ_NUM*1000/winAmpCoef); + g_lLeadOffDetIqAmpDiffThrRaw = (g_lLeadOffDetIqAmpDiff*g_lLeadOffDetIqAmpDiff); + g_lLeadOffDetIqAmpDiffFrThrRaw = (g_lLeadOffDetIqAmpDiff*g_lLeadOffDetIqAmpDiff / 20 / 20); + + g_nLeadOffDetValThr = uValThr; + g_LeadOffDetValThrRaw = (g_nLeadOffDetValThr * (20 * ADC_OFFSET / ADCREF)); +} + +void GH3x2xSetEcgOutputFs(GU16 usEcgOutputFs) +{ + g_usEcgOutputFs = usEcgOutputFs; +} + +/** + * @fn void GH3X2X_SoftLeadOffEventPro(void) + * + * @brief soft lead off evt process + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_SoftLeadOffEventPro(void) +{ + if(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchDisItypeWhenEcgSample) + { + + } + else if (GET_LEAD_ON_AUTO_SWITCH_VAL()) + { + GH3X2X_SlotEnableConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchSlotBit, GH3X2X_SET_SLOT_DISABLE); // disable ecg or pwtt slot + ECG_LEAD_DET_EN_CONFIG(0); // disable lead detect + ECG_LEAD_DET_EN_CONFIG(1);// enable lead detect + GH3X2X_SlotEnableConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchSlotBit, GH3X2X_SET_SLOT_ENABLE); // enable ecg or pwtt slot + GH3X2X_CascadeEcgSlaverLeadDectDisEx(); + } +} + +/** + * @fn GU16 GH3X2X_SoftLeadOffDetPro(GU16 usCurrentIrqStatus, GU8 *puchFifoBuffer, GU16* pusFifoBufferLen) + * + * @brief soft lead detect process + * + * @attention None + * + * @param[in] usCurrentIrqStatus current irq status + * @param[in] puchFifoBuffer pointer to read fifo data buffer + * @param[in] usFifoBufferLen read fifo buffer len + * @param[out] None + * + * @return irq status ouput after handle + */ +GU16 GH3X2X_SoftLeadOffDetPro(GU16 usCurrentIrqStatus, GU8 *puchFifoBuffer, GU16* pusFifoBufferLen) +{ + if ((SOFT_LEAD_OFF_DET_MODE_DISABLE == g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchSoftLeadDetMode) || (0 == g_uchEcgOrPwttFunctionEn)) + { + //return usCurrentIrqStatus; + } + else + { + if (0 != (usCurrentIrqStatus & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT)) //lead on event + { + #if GH3X2X_LEAD_OFF_SUPPORT_ECG + if(g_usEcgOutputFs == 800 || g_usEcgOutputFs == 320 || g_usEcgOutputFs == 256) + { + GH3X2X_LeadOffDetectInit(); + } + #endif + } + + if (g_uchRtypeModeEn) + { + return usCurrentIrqStatus; + } + + if (SOFT_LEAD_OFF_DET_MODE_SW_AND_HW == g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchSoftLeadDetMode) + { + } + else + { + if (0 != (usCurrentIrqStatus & GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT)) //lead off event + { + if (SOFT_LEAD_OFF_DET_MODE_SW_ONLY == g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchSoftLeadDetMode) // SW only + { + GH3X2X_VAL_CLEAR_BIT(usCurrentIrqStatus, (GU16)GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT); // don't need lead off evt + } + } + if ((*pusFifoBufferLen) && (LEAD_STATE_LEAD_ON == g_uchLeadStateInSoftLeadModule)) + { + GU8 uchDetResult = 0; + if(g_usEcgOutputFs == 800 || g_usEcgOutputFs == 320 || g_usEcgOutputFs == 256) + { + uchDetResult = GH3X2X_LeadOffDetect(puchFifoBuffer, pusFifoBufferLen); + } + if (uchDetResult) + { + GH3X2X_DEBUG_LOG_PARAM("soft lead off, detect result = %d !\r\n", uchDetResult); + GH3X2X_VAL_SET_BIT(usCurrentIrqStatus, GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT); + GH3X2X_SoftLeadOffEventPro(); + } + } + } + + if(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchWearOffLogic) // wear off logic is ecg only + { + if((1 == g_uchLastEcgSampleFlag)&&(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchDisItypeWhenEcgSample)) //is ecg samping and itype is disable + { + usCurrentIrqStatus &= (~(GH3X2X_IRQ_MSK_WEAR_OFF_BIT)); //mask wear off event + } + } + } + + return usCurrentIrqStatus; +} +/** + * @fn STSoftLeadResult GH3X2X_LeadHandle(GU16 usIrqStatus, GU8 *puchReadFifoBuffer, GU16 usFifoBufferLen) + * + * @brief ecg soft lead handle + * + * @attention None + * + * @param[in] usIrqStatus irq status + * @param[in] puchReadFifoBuffer pointer to read fifo data buffer + * @param[in] usFifoBufferLen read fifo buffer len + * @param[out] None + * + * @return soft lead handle process, @ref STSoftLeadResult + */ +STSoftLeadResult GH3X2X_LeadHandle(GU16 usIrqStatus, GU8 *puchReadFifoBuffer, GU16* pusFifoBufferLen) +{ + STSoftLeadResult stLeadResult = {0, 0}; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (0 != (usIrqStatus & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT)) //got lead on event + { + GH3X2X_DEBUG_LOG_PARAM("handle lead on \r\n"); + GH3X2X_EcgSampleHookHandle(ECG_SAMPLE_EVENT_TYPE_LEAD, ECG_SAMPLE_EVENT_INFO_LEAD_ON); + } + if (0 != (usIrqStatus & GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT)) //got lead off event + { + GH3X2X_DEBUG_LOG_PARAM("handle lead off \r\n"); + GH3X2X_EcgSampleHookHandle(ECG_SAMPLE_EVENT_TYPE_LEAD, ECG_SAMPLE_EVENT_INFO_LEAD_OFF); + } + if (0 != (usIrqStatus & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT)) + { + g_uchLeadStateInSoftLeadModule = LEAD_STATE_LEAD_ON; + } + usIrqStatus = GH3X2X_SoftLeadOffDetPro(usIrqStatus, puchReadFifoBuffer, pusFifoBufferLen); + + if (0 != (usIrqStatus & GH3X2X_IRQ_MSK_LEAD_OFF_DET_BIT)) + { + g_uchLeadStateInSoftLeadModule = LEAD_STATE_LEAD_OFF; + if(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchAutoCtrlMode) + { + stLeadResult.uchNeedForceReadFifo = 1; + } + } + stLeadResult.usEvent = usIrqStatus; + return stLeadResult; +} + +GU8 GH3X2X_LeadOffDetect(GU8* puchFifoBuffer, GU16* pusFifoBufferLen) +{ + GU8 uchRet = 0; + if(0 == g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG] || GH3X2X_CheckRawdataBuf(puchFifoBuffer, *pusFifoBufferLen)) + { + return uchRet; + } + uchRet |= GH3X2X_LeadOffDetectSingleChip(puchFifoBuffer, pusFifoBufferLen, 0); + if((g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchChnlNum > 1)&&(g_uchGh3x2xEcgChnlNumLimit > 1)) + { + uchRet |= GH3X2X_LeadOffDetectSingleChip(puchFifoBuffer, pusFifoBufferLen, 1); + } + return uchRet; +} + +/** + * @fn void GH3X2X_SlaverSoftLeadPramInit(void) + * + * @brief slave soft lead off param init to default value + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void GH3X2X_SlaverSoftLeadPramInit(void) +{ + g_uchEcgOrPwttFunctionEn = 0; + GH3X2X_Memset((GU8 *)(&g_stEcgLeadCfg), 0, sizeof(g_stEcgLeadCfg)); + g_uchEcgSampleStatus = 0; + g_uchLastEcgSampleFlag = 0; + g_uchRtypeModeEn = 1; + g_uchIsItyp0nAPeriod = 0; +} + +/** + * @fn void GH3X2X_SlaverSoftLeadPramSet(GU16 usRegVal, GU8 uchRegPosi) + * + * @brief slave soft lead off param set from virtual reg + * + * @attention None + * + * @param[in] usRegVal reg value + * @param[in] uchRegPosi reg position + * @param[out] None + * + * @return None + */ +void GH3X2X_SlaverSoftLeadPramSet(GU16 usRegVal, GU8 uchRegPosi) +{ + + GU8 uchByteOffset; + GU8 uchByteVal; + GU8 uchByteCnt; + for(uchByteCnt = 0; uchByteCnt < 2; uchByteCnt ++) + { + uchByteVal = ((usRegVal >> (8*uchByteCnt))&0x00FF); + uchByteOffset = (uchRegPosi * 2) + uchByteCnt; + if(uchByteOffset < sizeof(g_stEcgLeadCfg)) + { + GH3X2X_Memcpy(((GU8 *)(&g_stEcgLeadCfg)) + uchByteOffset, (GU8*)(&uchByteVal), 1); + if(uchByteOffset == (GU8)((GU8*)(&(g_stEcgLeadCfg.uchLeadOffBaseVolt))- (GU8*)(&(g_stEcgLeadCfg)))) + { + g_nLeadoffPeakThrdRawData = (GS32)((GS64)g_stEcgLeadCfg.uchLeadOffPeakVolt * (((GS64)g_uchEcgGainMapArr[g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchEcgGainGrade] \ + * GH3X2X_RAWDATA_REAL_OFFSET) \ + / (GS64)(((GU16)g_uchAdcRefMapArr[g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchAdcRefGrade]) * (GU16)SOFT_LEAD_ADC_REF_AMP_NUM))); + g_nLeadoffDiffThrdRawData = (GS32)((GS64)g_stEcgLeadCfg.uchLeadOffDiffVolt * (((GS64)g_uchEcgGainMapArr[g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchEcgGainGrade] \ + * GH3X2X_RAWDATA_REAL_OFFSET) \ + / (GS64)(((GU16)g_uchAdcRefMapArr[g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchAdcRefGrade]) * (GU16)SOFT_LEAD_ADC_REF_AMP_NUM))); + g_nLeadoffBaseThrdRawData = (GS32)((GS64)g_stEcgLeadCfg.uchLeadOffBaseVolt * (((GS64)g_uchEcgGainMapArr[g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchEcgGainGrade] \ + * GH3X2X_RAWDATA_REAL_OFFSET) \ + / (GS64)(((GU16)g_uchAdcRefMapArr[g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchAdcRefGrade]) * (GU16)SOFT_LEAD_ADC_REF_AMP_NUM))); + + } + g_uchEcgOrPwttFunctionEn = 1; + } + + } +} + +/** + * @fn void GH3X2X_EcgSampleHookHandle(GU8 uchEventType, GU8 uchEventInfo) + * + * @brief ecg sample hook handle + * + * @attention None + * + * @param[in] uchEventType ecg sample event type, @ref ECG_SAMPLE_EVENT_TYPE_SAMPLE etc + * @param[in] uchEventInfo ecg sample event info, @ref ECG_SAMPLE_EVENT_INFO_SAMPLE_STOP etc + * @param[out] None + * + * @return None + */ +void GH3X2X_EcgSampleHookHandle(GU8 uchEventType, GU8 uchEventInfo) +{ + GU8 uchHandleCondition; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + if (0 == g_uchEcgOrPwttFunctionEn) // check flag + { + return; + } + + if (ECG_SAMPLE_EVENT_TYPE_SAMPLE == uchEventType) // if evt type equal sample config + { + if (ECG_SAMPLE_EVENT_INFO_SAMPLE_STOP == uchEventInfo) + { + GH3X2X_VAL_CLEAR_BIT(g_uchEcgSampleStatus, (GU8)ECG_SAMPLE_EVENT_TYPE_SAMPLE); // clear sample bit + } + else + { + GH3X2X_VAL_SET_BIT(g_uchEcgSampleStatus, ECG_SAMPLE_EVENT_TYPE_SAMPLE); // set sample bit + } + } + else if (ECG_SAMPLE_EVENT_TYPE_SLOT == uchEventType) // if evt type equal slot config + { + if ((uchEventInfo & g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->uchSlotBit) != 0) // if slot enable bit equal + { + GH3X2X_VAL_SET_BIT(g_uchEcgSampleStatus, ECG_SAMPLE_EVENT_TYPE_SLOT); + } + else + { + GH3X2X_VAL_CLEAR_BIT(g_uchEcgSampleStatus, (GU8)ECG_SAMPLE_EVENT_TYPE_SLOT); + } + } + else if (ECG_SAMPLE_EVENT_TYPE_LEAD == uchEventType) + { + if (ECG_SAMPLE_EVENT_INFO_LEAD_OFF == uchEventInfo) + { + GH3X2X_VAL_CLEAR_BIT(g_uchEcgSampleStatus, (GU8)ECG_SAMPLE_EVENT_TYPE_LEAD); + } + else + { + GH3X2X_VAL_SET_BIT(g_uchEcgSampleStatus, ECG_SAMPLE_EVENT_TYPE_LEAD); + } + } + + if ((0 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchAutoCtrlMode) || (2 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchAutoCtrlMode)) //disable or software + { + uchHandleCondition = (ECG_SAMPLE_EVENT_TYPE_SAMPLE | ECG_SAMPLE_EVENT_TYPE_SLOT); + } + else + { + uchHandleCondition = (ECG_SAMPLE_EVENT_TYPE_SAMPLE | ECG_SAMPLE_EVENT_TYPE_SLOT | ECG_SAMPLE_EVENT_TYPE_LEAD); + } + + if (uchHandleCondition == (uchHandleCondition & g_uchEcgSampleStatus)) //condition is match + { + if(0 == g_uchLastEcgSampleFlag) + { + if(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchForceRecover) + { + ECG_FAST_RECV_EN_CONFIG(1); + GH3X2X_CascadeEcgSlaverFastRecTrigEx(); + GH3X2X_DEBUG_LOG_PARAM("Fast recover !!! last event is %d\r\n", uchEventType); + } + if(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchDisItypeWhenEcgSample) + { + g_uchIsItyp0nAPeriod = 1; + ECG_LEAD_DET_EN_CONFIG(0); // disable lead detect + GH3X2X_CascadeEcgSlaverLeadDectDisEx(); + } + g_uchRtypeModeEn = 0; + g_uchLastEcgSampleFlag = 1; + } + } + else + { + if(1 == g_uchLastEcgSampleFlag) //ecg sample will be from sampling to stop sample + { + if(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchDisItypeWhenEcgSample) + { + if((g_uchEcgSampleStatus&ECG_SAMPLE_EVENT_TYPE_SAMPLE))// if sample is opening + { + ECG_LEAD_DET_EN_CONFIG(1); // enable lead detect + GH3X2X_CascadeEcgSlaverLeadDectDisEx(); + } + if((1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag2.uchWearOffLogic)) + { + GH3X2X_SetSoftEvent(GH3X2X_SOFT_EVENT_WEAR_OFF); + } + } + else + { + if(GET_ECG_LEAD_DET_EN_VAL()) //if detcet module is enable , reset detecet module + { + ECG_LEAD_DET_EN_CONFIG(0); + ECG_LEAD_DET_EN_CONFIG(1); + GH3X2X_CascadeEcgSlaverLeadDectDisEx(); + } + } + g_uchIsItyp0nAPeriod = 0; + } + g_uchLastEcgSampleFlag = 0; + g_uchRtypeModeEn = 1; + } +} + +/** + * @fn GH3X2X_LeadDetEnControl(GU8 uchEventInfo) + * + * @brief lead detect enable control + * + * @attention None + * + * @param[in] uchEventInfo control event, only ecg start/stop evt + * @param[out] None + * + * @return None + */ +void GH3X2X_LeadDetEnControl(GU8 uchEventInfo) +{ + if(1 == g_stEcgLeadCfg.uchEcgLeadCtrlFlag1.uchNeedHostEnableLeadDet) + { + if (ECG_SAMPLE_EVENT_INFO_SAMPLE_STOP == uchEventInfo) + { + ECG_LEAD_DET_EN_CONFIG(0);// disable lead detect + } + else + { + ECG_LEAD_DET_EN_CONFIG(1);// enable lead detect + } + GH3X2X_CascadeEcgSlaverLeadDectDisEx(); + } +} + + +void GH3X2X_LeadDetEnInHardAdt(GU8 uchEn) +{ + if(g_stAdtModuleCfg.stAdtCfgByte0.uchElectrodeAdtEn) + { + if(1 == uchEn) + { + if(0 == g_uchIsItyp0nAPeriod) + { + ECG_LEAD_DET_EN_CONFIG(1);// enable lead detect + } + } + else + { + ECG_LEAD_DET_EN_CONFIG(0);// disable lead detect + } + } + GH3X2X_CascadeEcgSlaverLeadDectDisEx(); +} + +/** + * @fn void GH3X2X_EcgSampleHookHandleAfterSlotCtrl(GU16 usSlotEnableConfig, GU8 uchSlotEnable) + * + * @brief ecg sample hook handle after ecg slot ctrl + * + * @attention None + * + * @param[in] usSlotEnableConfig slot enable index , @ref GH3X2X_SLOT_INDEX_0 ... GH3X2X_SLOT_INDEX_ALL + * @param[in] uchSlotEnable enable flag, #0 slot disable, #others slot enable + * @param[out] None + * + * @return None + */ +void GH3X2X_EcgSampleHookHandleAfterSlotCtrl(GU16 usSlotEnableConfig, GU8 uchSlotEnable) +{ + GU8 uchSlotEnableBitsTmp = (GU8)usSlotEnableConfig; + if (uchSlotEnable == 0) + { + uchSlotEnableBitsTmp = ~uchSlotEnableBitsTmp; // if disable + } + GH3X2X_EcgSampleHookHandle(ECG_SAMPLE_EVENT_TYPE_SLOT, uchSlotEnableBitsTmp); +} + +/** + * @fn GS8 GH3X2X_CalibrateECGGain(GU8 *puchReadFifoBuffer) + * + * @brief Calibrate ECG Gain + * + * @attention None + * + * @param[in] puchReadFifoBuffer pointer read data buffer + * @param[in] usFifoBufferLen fifo byte length + * @return error code + * @retval #GH3X2X_RET_OK return algorithm run successfully, but output hasn't refreshed + * @retval #GH3X2X_RET_GENERIC_ERROR return algorithm generic error + */ +GS8 GH3X2X_CalibrateECGGain(GU8 *puchReadFifoBuffer, GU16 usFifoBufferLen) +{ + GU16 usByteIndexTmp = 0; + GS8 chGainCode = 0; + GU32 unRawdataVal = 0; + GS64 nRawdatalVal = 0; + GS64 nRawdataRealVal = 0; + GS8 chRet = GH3X2X_RET_OK; + chGainCode = (GS8)GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_ReadReg(GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_2_ADDR)); + if (GH3X2X_CHECK_BIT_SET(g_unFuncStartedBitmap, GH3X2X_FUNCTION_ECG)) + { + if(GH3X2X_CheckRawdataBuf(puchReadFifoBuffer, usFifoBufferLen)) + { + return chRet; + } + + for(usByteIndexTmp = 0; usByteIndexTmp < usFifoBufferLen; usByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE) + { + if(GH3X2X_CHANNEL_MAP_GET(puchReadFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pchChnlMap[0] & GH3X2X_SLOT_ADC_NUM_BITS)) + { + unRawdataVal = GH3X2X_MAKEUP_DWORD(puchReadFifoBuffer[usByteIndexTmp], puchReadFifoBuffer[usByteIndexTmp + 1], + puchReadFifoBuffer[usByteIndexTmp + 2], puchReadFifoBuffer[usByteIndexTmp + 3]); + + nRawdatalVal = GH3X2X_RAWDATA_CLEAR_ALL_FLAG(unRawdataVal); + + nRawdataRealVal = ((GS64)nRawdatalVal - GH3X2X_RAWDATA_REAL_OFFSET) * 1024/((GS64)chGainCode + 1024) + GH3X2X_RAWDATA_REAL_OFFSET; + + puchReadFifoBuffer[usByteIndexTmp + 1] = GH3X2X_GET_BYTE2_FROM_DWORD(nRawdataRealVal); + puchReadFifoBuffer[usByteIndexTmp + 2] = GH3X2X_GET_BYTE1_FROM_DWORD(nRawdataRealVal); + puchReadFifoBuffer[usByteIndexTmp + 3] = GH3X2X_GET_BYTE0_FROM_DWORD(nRawdataRealVal); + } + } + GH3X2X_CalRawdataBuf(puchReadFifoBuffer, usFifoBufferLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("ecg hasn't started error!\r\n"); + } + return chRet; +} + + + +void GH3X2X_DownSampleCal( GU8 *puchFifoBuffer, GU16 usByteIndexTmp, GU16 *usRawdataBufIdx, STGh3x2xRsInfo * pstRsInfo ,STGh3x2xDownSampleCalParamInfo * pstDownSampCalParamInfo) +{ + GU32 unfifoVal = 0; + GS32 usadcVal = 0; + GU8 chNo = 0; + GU8 uchflagFastRecovery = 0; + GU32 unFirCoefIndex = 0; + unfifoVal = GH3X2X_MAKEUP_DWORD(puchFifoBuffer[usByteIndexTmp], puchFifoBuffer[usByteIndexTmp + 1], puchFifoBuffer[usByteIndexTmp + 2], puchFifoBuffer[usByteIndexTmp + 3]); + chNo = (unfifoVal >> 27); + usadcVal = (GS32)((unfifoVal & 0x00FFFFFF)) - ADC_OFFSET; + + if(g_uchDownSampleModule == DOWNSAMPLE_ECG) + { + uchflagFastRecovery = (unfifoVal >> 26) & 0x01; + if (pstRsInfo ->uchFlagFrPrev != uchflagFastRecovery) + { + GH3X2X_ECGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pstFunctionInfo->usSampleRate); + } + pstRsInfo ->uchFlagFrPrev = uchflagFastRecovery; + } + + #if __SUPPORT_ECG_PPG_DOWNSAMP__ + else if(g_uchDownSampleModule == DOWNSAMPLE_PPG) + { + uchflagFastRecovery = (unfifoVal >> 26) & 0x01; + if (pstRsInfo ->uchFlagFrPrev != 1) + { + if(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstFunctionInfo->usSampleRate) + { + GH3X2X_PPGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pstFunctionInfo->usSampleRate); + } + else if(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SPO2]->pstFunctionInfo->usSampleRate) + { + GH3X2X_PPGResampleConfig(g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SPO2]->pstFunctionInfo->usSampleRate); + } + } + pstRsInfo ->uchFlagFrPrev = 1; + } + #endif + + // ECG downsample + #if RESAMPLE_320HZ_TO_250HZ || RESAMPLE_256HZ_TO_250HZ + if((DOWNSAMPLE_320HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType) || (DOWNSAMPLE_256HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType)) + { + GS32 snLinerAdcVal; + if(pstDownSampCalParamInfo->uchRsEnable) + { + GS32 snRsXbufIndex; + GS64 snFirValueSum; + GS32 snFirValue; + + //滤波 + if (pstRsInfo ->snRsFirState > 0) + { + pstRsInfo ->snBufHead = pstRsInfo ->snBufHead - 1; + pstRsInfo ->snBufHead = pstRsInfo ->snBufHead < 0 ? (pstDownSampCalParamInfo->uchRsBufSize - 1) : pstRsInfo ->snBufHead; + pstRsInfo ->snRsXbuf[pstRsInfo ->snBufHead] = usadcVal; + } + else + { + for (GU8 i = 0; i < pstDownSampCalParamInfo->uchRsFirOrder / pstDownSampCalParamInfo->uchRsI + 1; i++) + pstRsInfo ->snRsXbuf[i] = usadcVal; + pstRsInfo ->snBufHead = pstDownSampCalParamInfo->uchRsBufSize - 1; + } + + snRsXbufIndex = pstRsInfo ->snBufHead; + snFirValueSum = 0; + snFirValue = 0; + for (unFirCoefIndex = 1; unFirCoefIndex < pstDownSampCalParamInfo->uchRsFirCoefNum; unFirCoefIndex = unFirCoefIndex + 1) // + { + snFirValueSum += ((GS64)pstRsInfo ->snRsXbuf[snRsXbufIndex] * pstDownSampCalParamInfo->rsFirCoef[unFirCoefIndex]); + snRsXbufIndex = (snRsXbufIndex + 1) % pstDownSampCalParamInfo->uchRsBufSize; + } + for (; unFirCoefIndex <(pstDownSampCalParamInfo->uchRsFirOrder+1); unFirCoefIndex = unFirCoefIndex + 1) // + { + snFirValueSum += ((GS64)pstRsInfo ->snRsXbuf[snRsXbufIndex] * pstDownSampCalParamInfo->rsFirCoef[pstDownSampCalParamInfo->uchRsFirOrder - unFirCoefIndex]); + snRsXbufIndex = (snRsXbufIndex + 1) % pstDownSampCalParamInfo->uchRsBufSize; + } + + snFirValue = (GS32)(snFirValueSum >> SHIFTBITS); + snFirValue = snFirValue + ADC_OFFSET; // + if (snFirValue < 0) + snFirValue = 0; + else if (snFirValue>=(ADC_OFFSET * 2)) + snFirValue = (ADC_OFFSET * 2-1); + + // 线性插值降采样 + if(pstRsInfo->uchLinearInterState >0) + { + #if RESAMPLE_320HZ_TO_250HZ + if(DOWNSAMPLE_320HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType) + { + if(pstRsInfo->fDownStep <=100) + { + snLinerAdcVal = ((GU32)snFirValue*pstRsInfo->fDownStep + (100-pstRsInfo->fDownStep)*pstRsInfo->nRsLastRaw)/100; + pstRsInfo->nRsLastRaw = (GU32)snFirValue; + pstRsInfo->fDownStep = pstRsInfo->fDownStep + pstDownSampCalParamInfo->ufStep - 100; + pstRsInfo->uchLinearDataUpdate = 1; + } + else + { + pstRsInfo->nRsLastRaw = (GU32)snFirValue; + pstRsInfo->fDownStep = pstRsInfo->fDownStep - 100; + pstRsInfo->uchLinearDataUpdate = 0; + } + } + #endif + + #if RESAMPLE_256HZ_TO_250HZ + if(DOWNSAMPLE_256HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType) + { + if(pstRsInfo->fDownStep <=1000) + { + snLinerAdcVal = (GU32)(((GS64)(snFirValue)*(GS64)(pstRsInfo->fDownStep) + (GS64)((1000-pstRsInfo->fDownStep)*(GS64)(pstRsInfo->nRsLastRaw)))/1000); + pstRsInfo->nRsLastRaw = (GU32)snFirValue; + pstRsInfo->fDownStep = pstRsInfo->fDownStep + pstDownSampCalParamInfo->ufStep - 1000; + pstRsInfo->uchLinearDataUpdate = 1; + } + else + { + pstRsInfo->nRsLastRaw = (GU32)snFirValue; + pstRsInfo->fDownStep = pstRsInfo->fDownStep - 1000; + pstRsInfo->uchLinearDataUpdate = 0; + } + } + #endif + } + else + { + snLinerAdcVal = (GU32)snFirValue; + pstRsInfo->nRsLastRaw = (GU32)snFirValue; + pstRsInfo->fDownStep = pstRsInfo->fDownStep + pstDownSampCalParamInfo->ufStep; + pstRsInfo->uchLinearInterState =1; + pstRsInfo->uchLinearDataUpdate = 1; + } + + if(pstRsInfo->uchLinearDataUpdate == 1) + { + unfifoVal = (((GU8)chNo)<<27) + (((GU8)uchflagFastRecovery)<<26) + ((GU32)snLinerAdcVal/5); + puchFifoBuffer[*usRawdataBufIdx] = GH3X2X_GET_BYTE3_FROM_DWORD(unfifoVal); + puchFifoBuffer[*usRawdataBufIdx + 1] = GH3X2X_GET_BYTE2_FROM_DWORD(unfifoVal); + puchFifoBuffer[*usRawdataBufIdx + 2] = GH3X2X_GET_BYTE1_FROM_DWORD(unfifoVal); + puchFifoBuffer[*usRawdataBufIdx + 3] = GH3X2X_GET_BYTE0_FROM_DWORD(unfifoVal); + + *usRawdataBufIdx += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + } + #endif + + #if RESAMPLE_800HZ_TO_500HZ ||RESAMPLE_800HZ_TO_250HZ || (RESAMPLE_400HZ_TO_250HZ & (__SUPPORT_ECG_PPG_DOWNSAMP__)) + if((DOWNSAMPLE_800HZ_TO_500HZ == pstECGDownSampCalParamInfo->uchDownSampleType)||(DOWNSAMPLE_800HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType)||(DOWNSAMPLE_400HZ_TO_250HZ == pstECGDownSampCalParamInfo->uchDownSampleType)) + { + if(pstDownSampCalParamInfo->uchRsEnable) + { + GS32 snRsXbufIndex; + GS64 snFirValueSum; + GS32 snFirValue; + GS32 sndelta; + if (pstRsInfo ->snRsFirState > 0) + { + pstRsInfo ->snBufHead = pstRsInfo ->snBufHead - 1; + pstRsInfo ->snBufHead = pstRsInfo ->snBufHead < 0 ? (pstDownSampCalParamInfo->uchRsBufSize - 1) : pstRsInfo ->snBufHead; + pstRsInfo ->snRsXbuf[pstRsInfo ->snBufHead] = usadcVal; + pstRsInfo ->nRsIcounter += pstDownSampCalParamInfo->uchRsI; + } + else + { + for (GU8 i = 0; i < pstDownSampCalParamInfo->uchRsFirOrder / pstDownSampCalParamInfo->uchRsI + 1; i++) + pstRsInfo ->snRsXbuf[i] = usadcVal; + pstRsInfo ->nRsIcounter = 0; + pstRsInfo ->snRsFirState = 1; + pstRsInfo ->snBufHead = pstDownSampCalParamInfo->uchRsBufSize - 1; + } + + if (pstRsInfo ->nRrsDcounter >= pstRsInfo ->nRsIcounter && pstRsInfo ->nRrsDcounter < (pstRsInfo ->nRsIcounter + pstDownSampCalParamInfo->uchRsI)) + { + sndelta = pstRsInfo ->nRrsDcounter - pstRsInfo ->nRsIcounter; + snRsXbufIndex = pstRsInfo ->snBufHead; + snFirValue = 0; + snFirValueSum = 0; + for (unFirCoefIndex = sndelta; unFirCoefIndex < pstDownSampCalParamInfo->uchRsFirCoefNum; unFirCoefIndex = unFirCoefIndex + pstDownSampCalParamInfo->uchRsI) + { + snFirValueSum += ((GS64)pstRsInfo ->snRsXbuf[snRsXbufIndex] * pstDownSampCalParamInfo->rsFirCoef[unFirCoefIndex]); + snRsXbufIndex = (snRsXbufIndex + 1) % pstDownSampCalParamInfo->uchRsBufSize; + } + for (; unFirCoefIndex <(pstDownSampCalParamInfo->uchRsFirOrder+1); unFirCoefIndex = unFirCoefIndex + pstDownSampCalParamInfo->uchRsI) + { + snFirValueSum += ((GS64)pstRsInfo ->snRsXbuf[snRsXbufIndex] * pstDownSampCalParamInfo->rsFirCoef[pstDownSampCalParamInfo->uchRsFirOrder - unFirCoefIndex]); + snRsXbufIndex = (snRsXbufIndex + 1) % pstDownSampCalParamInfo->uchRsBufSize; + } + pstRsInfo ->nRrsDcounter += pstDownSampCalParamInfo->uchRsD; + + snFirValue = (GS32)(snFirValueSum >> SHIFTBITS); + snFirValue = snFirValue + ADC_OFFSET; + if (snFirValue < 0) + snFirValue = 0; + else if (snFirValue>=(ADC_OFFSET * 2)) + snFirValue = (ADC_OFFSET * 2-1); + unfifoVal = (((GU8)chNo)<<27) + (((GU8)uchflagFastRecovery)<<26) + ((GU32)snFirValue); + puchFifoBuffer[*usRawdataBufIdx] = GH3X2X_GET_BYTE3_FROM_DWORD(unfifoVal); + puchFifoBuffer[*usRawdataBufIdx + 1] = GH3X2X_GET_BYTE2_FROM_DWORD(unfifoVal); + puchFifoBuffer[*usRawdataBufIdx + 2] = GH3X2X_GET_BYTE1_FROM_DWORD(unfifoVal); + puchFifoBuffer[*usRawdataBufIdx + 3] = GH3X2X_GET_BYTE0_FROM_DWORD(unfifoVal); + *usRawdataBufIdx += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + } +#endif +} +#endif + +void GH3X2X_EcgPPGRsHandleSingleChip(GU8 *puchFifoBuffer, GU16 *pusFifoBufferLen, GU8 uchChipIndex) +{ + GU16 usByteIndexTmp = 0; + GU16 usRawdataBufIdx = 0; + GU8 usCheckDataType = 0; // 1:ECG 2:PPG 0:other + + for (usByteIndexTmp = 0; usByteIndexTmp < *pusFifoBufferLen; usByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE) + { + if(GH3X2X_CHANNEL_MAP_GET(puchFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pchChnlMap[uchChipIndex] & GH3X2X_SLOT_ADC_NUM_BITS)) + { + STGh3x2xRsInfo * pstRsInfo_ECG = g_pstGh3x2xEcgRsInfo + uchChipIndex; + g_uchDownSampleModule = DOWNSAMPLE_ECG; + GH3X2X_DownSampleCal( puchFifoBuffer, usByteIndexTmp, &usRawdataBufIdx, pstRsInfo_ECG,pstECGDownSampCalParamInfo); + usCheckDataType =1; + } + + #if __SUPPORT_ECG_PPG_DOWNSAMP__ + if(g_uchPPGDownSampleChnlNumLimit && pstPPGDownSampCalParamInfo->uchRsEnable==1) + { + for(GU8 uchPPGSlotNumTmp = 0; uchPPGSlotNumTmp < g_uchPPGDownSampleChnlNumLimit; uchPPGSlotNumTmp++) + { + if(GH3X2X_CHANNEL_MAP_GET(puchFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_HR]->pchChnlMap[uchPPGSlotNumTmp] & GH3X2X_SLOT_ADC_NUM_BITS) +// || GH3X2X_CHANNEL_MAP_GET(puchFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SPO2]->pchChnlMap[uchPPGSlotNumTmp] & GH3X2X_SLOT_ADC_NUM_BITS) +// || GH3X2X_CHANNEL_MAP_GET(puchFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_GREEN]->pchChnlMap[uchPPGSlotNumTmp] & GH3X2X_SLOT_ADC_NUM_BITS) +// || GH3X2X_CHANNEL_MAP_GET(puchFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_SOFT_ADT_IR]->pchChnlMap[uchPPGSlotNumTmp] & GH3X2X_SLOT_ADC_NUM_BITS) + ) + { + STGh3x2xRsInfo * pstRsInfo_PPG = g_pstGh3x2xPPGRsInfo + uchPPGSlotNumTmp; + g_uchDownSampleModule = DOWNSAMPLE_PPG; + GH3X2X_DownSampleCal(puchFifoBuffer, usByteIndexTmp, &usRawdataBufIdx, pstRsInfo_PPG,pstPPGDownSampCalParamInfo); + usCheckDataType =2; + } + } + } + #endif + if(!usCheckDataType) + { + if(pstECGDownSampCalParamInfo->uchRsEnable) + { + //this rawdata is not ECG data + puchFifoBuffer[usRawdataBufIdx] = puchFifoBuffer[usByteIndexTmp]; + puchFifoBuffer[usRawdataBufIdx + 1] = puchFifoBuffer[usByteIndexTmp + 1]; + puchFifoBuffer[usRawdataBufIdx + 2] = puchFifoBuffer[usByteIndexTmp + 2]; + puchFifoBuffer[usRawdataBufIdx + 3] = puchFifoBuffer[usByteIndexTmp + 3]; + usRawdataBufIdx += GH3X2X_FIFO_RAWDATA_SIZE; + } + } + usCheckDataType = 0; + } // end of for (usByteIndexTmp = 0; usByteIndexTmp < usFifoBufferLen; usByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE) + *pusFifoBufferLen = usRawdataBufIdx; +} + +GU8 GH3X2X_EcgRsHandle(GU8* puchFifoBuffer, GU16* pusFifoBufferLen) +{ + if(pstECGDownSampCalParamInfo->uchRsEnable == 1) + { + GH3X2X_EcgPPGRsHandleSingleChip(puchFifoBuffer, pusFifoBufferLen, 0); + GH3X2X_CalRawdataBuf(puchFifoBuffer, *pusFifoBufferLen); + return 1; + } + else + { + return 0; + } +} + +#endif + +//---------------------cascade----------------------------- + +#if !__GH3X2X_CASCADE_EN__ +GU8 GH3X2X_CascadeGetEcgEnFlag(void){return 0;} +void GH3X2X_CascadeEcgSlaverLeadDectDisEx(void){} +void GH3X2X_CascadeEcgSlaverFastRecTrigEx(void){} +#else +GU8 guchChip1EcgLeadFlag = 0; //0:lead off 1:lead on +GU8 guchChip2EcgLeadFlag = 0; //0:lead off 1:lead on + +GS8 GH3X2X_CascadeCalibrateECGGain(GU8 *puchReadFifoBuffer, GU16 usFifoBufferLen) +{ + GU16 usByteIndexTmp = 0; + GS8 chGainCodeMaster = 0; + GS8 chGainCodeSlaver = 0; + GU32 unRawdataVal = 0; + GS64 nRawdatalVal = 0; + GS64 nRawdataRealVal = 0; + GS8 chRet = GH3X2X_RET_OK; + + + chGainCodeMaster = (GS8)GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_ReadReg(GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_2_ADDR)); + GH3X2X_CascadeOperationSlaverChip(); + chGainCodeSlaver = (GS8)GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_ReadReg(GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_2_ADDR)); + GH3X2X_CascadeOperationMasterChip(); + + //if (GH3X2X_CHECK_BIT_SET(GH3X2X_GET_FUNC_START_BITMAP, GH3X2X_STARTED_BITMAP_ECG)) + if (GH3X2X_CHECK_BIT_SET(g_unFuncStartedBitmap, GH3X2X_FUNCTION_ECG)) + { + if(GH3X2X_CheckRawdataBuf(puchReadFifoBuffer, usFifoBufferLen)) + { + return chRet; + } + + for(usByteIndexTmp = 0; usByteIndexTmp < usFifoBufferLen; usByteIndexTmp += GH3X2X_FIFO_RAWDATA_SIZE) + { + //if(GH3X2X_CHANNEL_MAP_GET(puchReadFifoBuffer[usByteIndexTmp]) == g_uchEcgChannelMap) + if(GH3X2X_CHANNEL_MAP_GET(puchReadFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pchChnlMap[0]& GH3X2X_SLOT_ADC_NUM_BITS)) + + { + unRawdataVal = GH3X2X_MAKEUP_DWORD(puchReadFifoBuffer[usByteIndexTmp], puchReadFifoBuffer[usByteIndexTmp + 1], + puchReadFifoBuffer[usByteIndexTmp + 2], puchReadFifoBuffer[usByteIndexTmp + 3]); + + nRawdatalVal = GH3X2X_RAWDATA_CLEAR_ALL_FLAG(unRawdataVal); + + nRawdataRealVal = ((GS64)nRawdatalVal - GH3X2X_RAWDATA_REAL_OFFSET) * 1024/((GS64)chGainCodeMaster + 1024) + GH3X2X_RAWDATA_REAL_OFFSET; + + puchReadFifoBuffer[usByteIndexTmp + 1] = GH3X2X_GET_BYTE2_FROM_DWORD(nRawdataRealVal); + puchReadFifoBuffer[usByteIndexTmp + 2] = GH3X2X_GET_BYTE1_FROM_DWORD(nRawdataRealVal); + puchReadFifoBuffer[usByteIndexTmp + 3] = GH3X2X_GET_BYTE0_FROM_DWORD(nRawdataRealVal); + + } + else if(GH3X2X_CHANNEL_MAP_GET(puchReadFifoBuffer[usByteIndexTmp]) == (g_pstGh3x2xFrameInfo[GH3X2X_FUNC_OFFSET_ECG]->pchChnlMap[1]& GH3X2X_SLOT_ADC_NUM_BITS)) + { + unRawdataVal = GH3X2X_MAKEUP_DWORD(puchReadFifoBuffer[usByteIndexTmp], puchReadFifoBuffer[usByteIndexTmp + 1], + puchReadFifoBuffer[usByteIndexTmp + 2], puchReadFifoBuffer[usByteIndexTmp + 3]); + + nRawdatalVal = GH3X2X_RAWDATA_CLEAR_ALL_FLAG(unRawdataVal); + + nRawdataRealVal = ((GS64)nRawdatalVal - GH3X2X_RAWDATA_REAL_OFFSET) * 1024/((GS64)chGainCodeSlaver + 1024) + GH3X2X_RAWDATA_REAL_OFFSET; + + puchReadFifoBuffer[usByteIndexTmp + 1] = GH3X2X_GET_BYTE2_FROM_DWORD(nRawdataRealVal); + puchReadFifoBuffer[usByteIndexTmp + 2] = GH3X2X_GET_BYTE1_FROM_DWORD(nRawdataRealVal); + puchReadFifoBuffer[usByteIndexTmp + 3] = GH3X2X_GET_BYTE0_FROM_DWORD(nRawdataRealVal); + } + } + GH3X2X_CalRawdataBuf(puchReadFifoBuffer, usFifoBufferLen); + } + else + { + chRet = GH3X2X_RET_GENERIC_ERROR; + GH3X2X_DEBUG_LOG_PARAM("ecg hasn't started error!\r\n"); + } + return chRet; +} + +void GH3X2X_CascadeEcgSlaverLeadDectDis(void) +{ + GH3X2X_DEBUG_LOG_PARAM("Chip222 Lead Dec Stop\r\n"); + GH3X2X_CascadeOperationSlaverChip(); + ECG_LEAD_DET_EN_CONFIG(0); + GH3X2X_CascadeOperationMasterChip(); +} + +void GH3X2X_CascadeEcgSlaverLeadDectEn(void) +{ + //ECG_LEAD_DET_EN_CONFIG(1); + GH3X2X_DEBUG_LOG_PARAM("Chip222 Lead Dec Start\r\n"); + GH3X2X_CascadeOperationSlaverChip(); + ECG_LEAD_DET_EN_CONFIG(1); + GH3X2X_CascadeOperationMasterChip(); +} + +void GH3X2X_CascadeSetChip1LeadSta(GU8 uchLeadOnStatus) +{ + guchChip1EcgLeadFlag = uchLeadOnStatus; +} + +GU8 GH3X2X_CascadeGetEcgMasterLeadStatus(GU8 *puchEvent) +{ + GU8 uchLastLeadFlag = guchChip1EcgLeadFlag; + guchChip1EcgLeadFlag = GH3X2X_ReadReg(0x50c) & 0x01; + if(uchLastLeadFlag != guchChip1EcgLeadFlag) + { + if(guchChip1EcgLeadFlag) + { + (*puchEvent) |= GH3X2X_EVENT_EX_BIT_CHIP0_LEAD_ON; + } + else + { + (*puchEvent) |= GH3X2X_EVENT_EX_BIT_CHIP0_LEAD_OFF; + } + } + return guchChip1EcgLeadFlag; +} + +void GH3X2X_CascadeSetChip2LeadSta(GU8 uchLeadOnStatus) +{ + guchChip2EcgLeadFlag = uchLeadOnStatus; +} + +GU8 GH3X2X_CascadeGetEcgSlaverLeadStatus(GU8 *puchEvent) +{ + GU8 uchLastLeadFlag = guchChip2EcgLeadFlag; + GH3X2X_CascadeOperationSlaverChip(); + guchChip2EcgLeadFlag = GH3X2X_ReadReg(0x50c) & 0x01; + if(uchLastLeadFlag != guchChip2EcgLeadFlag) + { + if(guchChip2EcgLeadFlag) + { + (*puchEvent) |= GH3X2X_EVENT_EX_BIT_CHIP1_LEAD_ON; + } + else + { + (*puchEvent) |= GH3X2X_EVENT_EX_BIT_CHIP1_LEAD_OFF; + } + } + GH3X2X_CascadeOperationMasterChip(); + + return guchChip2EcgLeadFlag; +} + +GU16 GH3X2X_CascadeLeadOnEventPreDeal(GU16 usIrqStatus,GU16 usIrqStatusChip2,GU8 *puchEventEx) +{ + GH3X2X_DEBUG_LOG_PARAM("GH3X2X_CascadeLeadOnEventPreDeal!!!!\r\n"); + GU8 uchMasterLeadStatus; //0: lead off 1: lead on + GU8 uchSlaveLeadStatus; //0: lead off 1: lead on + + if (0 != (usIrqStatus & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT)) //chip1 got lead on event + { + GH3X2X_CascadeEcgSlaverLeadDectEn(); + GH3X2X_DEBUG_LOG_PARAM("chip1 lead on!!!!\r\n"); + } + + if (0 != (usIrqStatusChip2 & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT)) //chip2 got lead on event + { + GH3X2X_DEBUG_LOG_PARAM("chip2 lead on!!!!\r\n"); + } + + uchMasterLeadStatus = GH3X2X_CascadeGetEcgMasterLeadStatus(puchEventEx); + uchSlaveLeadStatus = GH3X2X_CascadeGetEcgSlaverLeadStatus(puchEventEx); + + if ((0 != (usIrqStatus & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT)) || (0 != (usIrqStatusChip2 & GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT))) + { + if ( uchMasterLeadStatus & uchSlaveLeadStatus) + { + usIrqStatus |= GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT; + GH3X2X_DEBUG_LOG_PARAM("2ecg Lead On\r\n"); + } + else + { + usIrqStatus &= ~GH3X2X_IRQ_MSK_LEAD_ON_DET_BIT; + } + } + //GH3X2X_CascadeLeadEventReport(); + return usIrqStatus; +} + +void GH3X2X_CascadeLeadOffResultDeal(GU8 uchLeadoffRes) +{ + if(uchLeadoffRes == 0) + { + return; + } + + if( 0 != (uchLeadoffRes & 0x0f)) //chip1 lead off + { + GH3X2X_DEBUG_LOG_PARAM("chip1 Leadoff!!!!\r\n"); + } + + if( 0 != (uchLeadoffRes & 0xf0)) //chip2 lead off + { + GH3X2X_DEBUG_LOG_PARAM("Chip2 Leadoff!!!!\r\n"); + } + + if (0 != uchLeadoffRes) //As long as there is one chip lead off; restart + { + GH3X2X_CascadeEcgSlaverLeadDectDis(); + GH3X2X_DEBUG_LOG_PARAM("Leadoff uchLeadoffRes:0x%02x!!!!\r\n", uchLeadoffRes); + } + //report lead status + //GH3X2X_CascadeLeadEventReport(); +} + +void GH3X2X_CascadeSetEcgEnFlag(GU8 uchCascadeEnFlag) +{ + g_uchEcgCascadeEn = uchCascadeEnFlag; + GH3X2X_LeadOffDetectInit(); +} +// 1: init success 0: init fail +void GH3X2X_CascadeSetEcgSlaveInitSuccess(GU8 uchCascadeInitSuccess) +{ + g_uchEcgCascadeSlaveInitSuccess = uchCascadeInitSuccess; +} + + +GU8 GH3X2X_CascadeGetEcgSlaveInitSuccess(void) +{ + return g_uchEcgCascadeSlaveInitSuccess; +} + +GU8 GH3X2X_CascadeGetEcgEnFlag(void) +{ + return g_uchEcgCascadeEn; +} + +void GH3X2X_CascadeEcgSlaverLeadDectDisEx(void) +{ + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeEcgSlaverLeadDectDis(); + } +} + +void GH3X2X_CascadeEcgSlaverFastRecTrigEx(void) +{ + if (GH3X2X_CascadeGetEcgEnFlag()) + { + GH3X2X_CascadeOperationSlaverChip(); + ECG_FAST_RECV_EN_CONFIG(1); + GH3X2X_CascadeOperationSlaverChip(); + } +} + +#endif + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ + + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_ecg/gh_ecg.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_ecg/gh_ecg.h new file mode 100644 index 000000000..6730eb457 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_ecg/gh_ecg.h @@ -0,0 +1,268 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_ecg.h + * + * @brief gh3x2x lead process functions + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#ifndef _GH3X2X_DRV_ECG_H_ +#define _GH3X2X_DRV_ECG_H_ + + +#include "gh_drv_config.h" +#include "gh_drv.h" + + + + +/// difference threshold, unit: mV +#define LEADOFF_DET_DIF_THR_MV (15) + +/// Val threshold, unit:mV +#define LEADOFF_DET_VAL_THR_MV (70) + +/// detect sample point, if input volt v(n)-v(n- LEADOFF_DET_POINT_NUM) > LEADOFF_DET_THR_mV, assert lead off +#define LEADOFF_DET_POINT_NUM (3) + +/// base offset detect, unit:mV +#define LEADOFF_BASE_THR1_MV (5) + +/// lead off base hold samp +#define LEADOFF_BASE_HOLD_SAMP (400) + +/// lead off base rst samp +#define LEADOFF_BASE_RST_SAMP (100) + +/// lead off moving num +#define LEADOFF_MOVING_NUM (20) + +/* lead state */ +#define LEAD_STATE_LEAD_ON (1) /**< lead state lead on */ +#define LEAD_STATE_LEAD_OFF (0) /**< lead state lead off */ + +/* soft lead type */ +#define SOFT_LEAD_NULL_TYPE (0) /**< soft lead null type */ +#define SOFT_LEAD_RTYPE (1) /**< soft lead R type */ +#define SOFT_LEAD_ITYPE (2) /**< soft lead I type */ + +/* soft lead off detect mode */ +#define SOFT_LEAD_OFF_DET_MODE_DISABLE (0) /**< soft lead off detect mode disable */ +#define SOFT_LEAD_OFF_DET_MODE_SW_AND_HW (1) /**< soft lead off detect mode sw and hw */ +#define SOFT_LEAD_OFF_DET_MODE_SW_ONLY (2) /**< soft lead off detect mode sw only */ + +/// get ecg lead channel map from slot num +#define ECG_LEAD_GET_CHANNEL_MAP(n) (GH3X2X_CHANNEL_MAP(GH3X2X_VAL_LEFT_SHIFT((n), 5), \ + GH3X2X_CHANNEL_MAP_ADC3)) + +#define GET_ECG_LEAD_DET_EN_VAL() (GH3X2X_ReadRegBitField(GH3X2X_ADT_LEADON_CR_REG_ADDR, \ + GH3X2X_ECG_LEAD_DET_EN_LSB, GH3X2X_ECG_LEAD_DET_EN_MSB)) +/// ecg lead detect enable config +#define ECG_LEAD_DET_EN_CONFIG(en) do {\ + GH3X2X_WriteRegBitField(GH3X2X_ADT_LEADON_CR_REG_ADDR, \ + GH3X2X_ECG_LEAD_DET_EN_LSB, GH3X2X_ECG_LEAD_DET_EN_MSB, (en)); \ + } while (0) + +/// ecg fast recover enable config +#define ECG_FAST_RECV_EN_CONFIG(en) do {\ + GH3X2X_WriteRegBitField(GH3X2X_ECG_CTRL_REG_ADDR, \ + GH3X2X_ECG_FAST_RECV_EN_LSB, GH3X2X_ECG_FAST_RECV_EN_MSB, (en)); \ + } while (0) + +/// lead on auto switch bit field val +#define GET_LEAD_ON_AUTO_SWITCH_VAL() (GH3X2X_ReadRegBitField(GH3X2X_ECG_CTRL_REG_ADDR, \ + GH3X2X_LEAD_ON_AUTO_SWITCH_LSB, GH3X2X_LEAD_ON_AUTO_SWITCH_MSB)) + +/// lead off auto switch bit field val +#define GET_LEAD_OFF_AUTO_SWITCH_VAL() (GH3X2X_ReadRegBitField(GH3X2X_ECG_CTRL_REG_ADDR, \ + GH3X2X_LEAD_OFF_AUTO_SWITCH_LSB, GH3X2X_LEAD_OFF_AUTO_SWITCH_MSB)) + +/// soft lead adc ref amplify num +#define SOFT_LEAD_ADC_REF_AMP_NUM (1000) + +/// lead off diff thr default val +#define SOFT_LEAD_OFF_DIFF_THR_DEFAULT_VAL ((GS32)(15 * (20 * GH3X2X_RAWDATA_REAL_OFFSET / 1600))) + +/// lead off peak thr default val +#define SOFT_LEAD_OFF_PEAK_THR_DEFAULT_VAL ((GS32)(70 * (20 * GH3X2X_RAWDATA_REAL_OFFSET / 1600))) + +/// lead off base thr default val +#define SOFT_LEAD_OFF_BASE_THR_DEFAULT_VAL ((GS32)(5 * (20 * GH3X2X_RAWDATA_REAL_OFFSET / 1600))) + +/// soft lead buffer head index init val +#define SOFT_LEAD_BUFFER_HEAD_INIT_INDEX (-1) + +/* soft lead off detect function ret bit val */ +#define SOFT_LEAD_OFF_DETECT_RET_BIT0 (0x01) /**< bit0=1 absAdcValue larger than thresh */ +#define SOFT_LEAD_OFF_DETECT_RET_BIT1 (0x02) /**< bit1=1 diff larger than thresh */ +#define SOFT_LEAD_OFF_DETECT_RET_BIT2 (0x04) /**< bit2=1 adc value continuously larger than thresh */ + +/* soft lead cfg param reg posi */ +#define SOFT_LEAD_CFG_PARAM_REG_POSI_0 (0u) /**< soft lead cfg param reg posi 0 */ +#define SOFT_LEAD_CFG_PARAM_REG_POSI_1 (1u) /**< soft lead cfg param reg posi 1 */ +#define SOFT_LEAD_CFG_PARAM_REG_POSI_2 (2u) /**< soft lead cfg param reg posi 2 */ + +/* soft lead cfg of bit filed */ +#define SOFT_LEAD_CFG_ECG_FORCE_RECV_LSB (0) /**< cfg index for g_uchEcgForceRecover */ +#define SOFT_LEAD_CFG_ECG_FORCE_RECV_MASK (0x01) /**< cfg mask for g_uchEcgForceRecover */ +#define SOFT_LEAD_CFG_EX_EN_VIA_HOST_LSB (1) /**< cfg index for g_uchExtraLeadDetectEnableViaHost */ +#define SOFT_LEAD_CFG_EX_EN_VIA_HOST_MASK (0x01) /**< cfg mask for g_uchExtraLeadDetectEnableViaHost */ +#define SOFT_LEAD_CFG_OFF_DET_MODE_LSB (2) /**< cfg index for g_uchSoftLeadOffDetMode */ +#define SOFT_LEAD_CFG_OFF_DET_MODE_MASK (0x03) /**< cfg mask for g_uchSoftLeadOffDetMode */ +#define SOFT_LEAD_CFG_ECG_GAIN_GRADE_LSB (4) /**< cfg index for g_uchEcgGainGrade */ +#define SOFT_LEAD_CFG_ECG_GAIN_GRADE_MASK (0x07) /**< cfg mask for g_uchEcgGainGrade */ +#define SOFT_LEAD_CFG_ADC_REF_GRADE_LSB (7) /**< cfg index for g_uchAdcRefGrade */ +#define SOFT_LEAD_CFG_ADC_REF_GRADE_MASK (0x01) /**< cfg mask for g_uchAdcRefGrade */ +#define SOFT_LEAD_CFG_ECG_AUTO_CTRL_LSB (0) /**< cfg index for g_uchEcgAutoCtrlMode */ +#define SOFT_LEAD_CFG_ECG_AUTO_CTRL_MASK (0x03) /**< cfg mask for g_uchEcgAutoCtrlMode */ + +//G202008231001 wanpeng START +/****************************** ecg lead cfg ****************************************/ + +/** + * @brief Downsample Function +*/ +typedef enum +{ + DOWNSAMPLE_ECG = 0, + DOWNSAMPLE_PPG, +}EmDownSampleFunction; + +/** + * @brief Downsample type +*/ +typedef enum +{ + DOWNSAMPLE_DEFAULT = 0, + DOWNSAMPLE_800HZ_TO_500HZ = 1, + DOWNSAMPLE_800HZ_TO_250HZ = 2, + DOWNSAMPLE_400HZ_TO_250HZ = 3, + DOWNSAMPLE_320HZ_TO_250HZ = 4, + DOWNSAMPLE_256HZ_TO_250HZ = 5, +}EmDownSampleType; + +typedef struct +{ + GU8 uchElectrodeAdtEn : 1; //0:disable electrode adt 1:enable electrode adt + GU8 uchElectrodeWearRevCntEn : 1; //elctrode wear state reverse counter dis/en 0: disable 1: enable + GU8 uchSoftWearOffDetEn : 1; //software wear off detction enable 0: disable 1: enable + GU8 uchElectrodeSoftWearColor : 1; //software wear led color 0:green 1:ir + GU8 uchHardAdtCheckByAlgo : 1; //0: do not use algo to judge adt 1: use algo to judge adt + GU8 uchRes : 3; +}STAdtCfgByte0; + + + +typedef struct t_adt_cfg +{ + GU8 uchAdtSampleCtrlMode; // 0: wear state do not affect sample 1: wear off only open adt slot 2: wear on/off need switch cfg + STAdtCfgByte0 stAdtCfgByte0; + GU8 ubResByte2; + GU8 ubResByte3; +}STAdtCfg; + + + + +typedef struct +{ + GU8 uchForceRecover :1; /* 0: do not force recover when ecg starting sample 1: do force recover when ecg starting sample */ + GU8 uchNeedHostEnableLeadDet :1; /* 0: host no need extra enable lead detecting 1: host need extra enable lead detecting */ + GU8 uchSoftLeadDetMode :2; /* 0: disable lead off detect 1: SW&HW 2: SW only */ + GU8 uchEcgGainGrade :3; /* 0: 1x 1: 2.5x 2: 5x 3: 10x 4: 20x */ + GU8 uchAdcRefGrade :1; /* 0: 1.6 V 1: 1.8 V */ +} STEcgLeadCtrlFlag1; + + +typedef struct +{ + GU8 uchAutoCtrlMode :2; /* 0: disable 1: hardware 2: software */ + GU8 uchDisItypeWhenEcgSample :1; /* 0: do not disable Itype when ecg sample stating 1: disable Itype when ecg sample stating */ + GU8 uchWearOffLogic :1; /* 0:do not rest with ecg elctronde only 1: rest with ecg elctronde only */ + GU8 Res :4; +} STEcgLeadCtrlFlag2; + + + + +typedef struct +{ + STEcgLeadCtrlFlag1 uchEcgLeadCtrlFlag1; + GU8 uchLeadOffPeakVolt; + GU8 uchLeadOffDiffVolt; + GU8 uchLeadOffBaseVolt; + STEcgLeadCtrlFlag2 uchEcgLeadCtrlFlag2; + GU8 uchRes1; +} STEcgLeadCfg; + +typedef struct +{ + GU8 uchRsFirOrder; + GU8 uchRsI; + GU8 uchRsD; + GU8 uchRsFirCoefNum; + GU8 uchRsBufSize; + GU8 uchRsEnable; + GU32 ufStep; + GS32* rsFirCoef; + GU8 uchDownSampleType; +} STGh3x2xDownSampleCalParamInfo; + + + +/** + * @fn void GH3X2X_EcgForceRecoverAfterSlotCtrl(GU16 usSlotEnableConfig, GU8 uchSlotEnable) + * + * @brief ecg sample hook handle after ecg slot ctrl + * + * @attention None + * + * @param[in] usSlotEnableConfig slot enable index , @ref GH3X2X_SLOT_INDEX_0 ... GH3X2X_SLOT_INDEX_ALL + * @param[in] uchSlotEnable enable flag, #0 slot disable, #others slot enable + * @param[out] None + * + * @return None + */ +void GH3X2X_EcgSampleHookHandleAfterSlotCtrl(GU16 usSlotEnableConfig, GU8 uchSlotEnable); + + + +/** + * @fn void GH3X2X_EcgLeadSlotConfig(GU8 uchEcgSlotBit) + * + * @brief ecg lead slot config + * + * @attention None + * + * @param[in] uchEcgSlotBit ecg slot bit, @ref GH3X2X_SLOT_INDEX_0... + * @param[out] None + * + * @return None + */ +void GH3X2X_EcgLeadSlotConfig(GU8 uchEcgSlotBit); + +/** + * @fn GH3X2X_LeadDetEnControl(GU8 uchEventInfo) + * + * @brief lead detect enable control + * + * @attention None + * + * @param[in] uchEventInfo control event, only ecg start/stop evt + * @param[out] None + * + * @return None + */ +void GH3X2X_LeadDetEnControl(GU8 uchEventInfo); + +void GH3x2xSetEcgOutputFs(GU16 usEcgOutputFs); +void GH3X2X_WriteAdtDrvConfigWithVirtualReg(GU16 usVirtualRegAddr, GU16 usVirtualRegValue); + +#endif /* _GH3X2X_DRV_SOFT_LEAD_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_changeinttime.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_changeinttime.c new file mode 100644 index 000000000..32c20f8ba --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_changeinttime.c @@ -0,0 +1,106 @@ +#include "gh_drv.h" + +#define GH3X2X_SLOT0_CTRL_3_REG_ADDR (0x0110) +#define GH3X2X_SLOT_CTRL_OFFSET (0x001C) +#define GH3X2X_RG_SLOT_TMR0_REG_ADDR (0x01EC) +#define GH3X2X_SLOT_ADC_INT_TIME_LSB (0) +#define GH3X2X_SLOT_ADC_INT_TIME_MSB (3) +#define GH3X2X_SLOT_BG_LEVEL_LSB (4) +#define GH3X2X_SLOT_BG_LEVEL_MSB (5) +#define GH3X2X_SLOT_BG_CANCEL_LSB (10) +#define GH3X2X_SLOT_BG_CANCEL_MSB (10) + +static const GU16 gusSlotTimeList[3][7] = { +{26, 36, 46, 56, 95, 174, 331}, +{48, 67, 87, 107, 186, 343, 658}, +{69, 99, 128, 158, 276, 512, 985} +}; + + +static void GH3x2x_SetIntTime(GU8 uchSlotNo, GU8 uchIntTimeIndex) +{ + GH3X2X_WriteRegBitField(GH3X2X_SLOT0_CTRL_3_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotNo,GH3X2X_SLOT_ADC_INT_TIME_LSB,GH3X2X_SLOT_ADC_INT_TIME_MSB, uchIntTimeIndex); +} + +static void GH3x2x_SetSlotTime(GU8 uchSlotNo, GU16 usSlotTime) +{ + GH3X2X_WriteReg(GH3X2X_RG_SLOT_TMR0_REG_ADDR + 2*uchSlotNo, usSlotTime); +} + +/** + * @fn void GH3x2x_ChangeIntTime(GU8 uchSlotNo , GU8 chIntTimeIndex) + * @brief change slot int time + * + * @attention None. + * + * @param[in] uchSlotNo: slot number + * @param[in] uchIntTimeIndex: Int time index,0:10us 1:20us 2:30us 3:39us 4:79us 5:158us 6:316us + * @param[out] None + * + * @return None + */ +void GH3x2x_ChangeIntTime(GU8 uchSlotNo, GU8 uchIntTimeIndex) +{ + GU8 uchBglevel = 0; //slot bg level + GU8 uchBgCancel = 0; //slot bg cancel + GU16 usTimeSlot = 0; + GU8 uchCfgIndex = 0; + GU8 uchSlotIndex = 0; + + //read bg level + uchBglevel = GH3X2X_ReadRegBitField(GH3X2X_SLOT0_CTRL_3_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotNo,GH3X2X_SLOT_BG_LEVEL_LSB,GH3X2X_SLOT_BG_LEVEL_MSB); + //read bg cancel + uchBgCancel= GH3X2X_ReadRegBitField(GH3X2X_SLOT0_CTRL_3_REG_ADDR + GH3X2X_SLOT_CTRL_OFFSET*uchSlotNo,GH3X2X_SLOT_BG_CANCEL_LSB,GH3X2X_SLOT_BG_CANCEL_MSB); + + if(uchBglevel > 2) + { + uchBglevel = 2; + } + usTimeSlot = gusSlotTimeList[uchBglevel][uchIntTimeIndex]; + if(uchBgCancel > 0) + { + usTimeSlot += 104; + } + usTimeSlot += 80; + + //find cfg index + for(GU8 uchSlotCnt = 0; uchSlotCnt < 8; uchSlotCnt ++) + { + if(0 == (uchSlotCnt&0x01)) //0,2,4,6 + { + uchCfgIndex = GH3X2X_ReadRegBitField(0x0100 + (uchSlotCnt&0xFE), 0,3); + } + else //1,3,5,7 + { + uchCfgIndex = GH3X2X_ReadRegBitField(0x0100 + (uchSlotCnt&0xFE), 8,11); + } + + if(uchCfgIndex == uchSlotNo) + { + uchSlotIndex = uchSlotCnt; + } + } + + GH3x2x_SetIntTime(uchSlotNo,uchIntTimeIndex); + GH3x2x_SetSlotTime(uchSlotIndex,usTimeSlot); +} + +//示例代码 +#if 0 +void main() +{ + GU8 usStartReg; + usStartReg = GH3X2X_ReadReg(0x0000); //read start reg + + if(usStartReg & 0x0001) + { + GH3X2X_WriteReg(0x0000,usStartReg&(0xFFFE)); //停止采样,确保更改积分时间前停止采样 + GH3x2x_ChangeIntTime(0,1); + GH3X2X_WriteReg(0x0000,usStartReg|0x0001); //重新采样,更改积分时间后重新开始采样 + } + else + { + GH3x2x_ChangeIntTime(0,1); + } +} +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_movedetect.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_movedetect.c new file mode 100644 index 000000000..9ce885400 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_movedetect.c @@ -0,0 +1,192 @@ +/** +* @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. +* +* @file gh_movedetect.c +* +* @brief gh move detect functions +* +* @version ref gh3x2x_drv_version.h +* +*/ + + +#include +#include "gh_demo_config.h" +#include "gh_demo_inner.h" +#include "gh_drv.h" +#include "gh_movedetect.h" + + +//----------------------------------------------------- +typedef struct +{ + GS16 sXAxisVal; /**< x-axis value */ + GS16 sYAxisVal; /**< y-axis value */ + GS16 sZAxisVal; /**< z-axis value */ +} STGsAccRawdata; + +STGsAccRawdata g_LastPointAdtGsenorRawdata; + +typedef struct +{ + GS16 sXAxisVal; /**< x-axis value */ + GS16 sYAxisVal; /**< y-axis value */ + GS16 sZAxisVal; /**< z-axis value */ + GS16 sAccVal; /**< acc-axis value */ + GS16 sLastAccVal; /**< acc-axis value */ + GS16 sAccDifBuf[125]; + GU16 sAccThrNum; /**< acc-axis value */ + GU16 sAccThrMax; /**< acc-axis value */ + GU16 sAccThrMin; /**< acc-axis value */ + GU16 sAccThrScale; /**< acc-axis value */ + GU8 uchGsensorDifBufIndex; +} STGsAccMoverEventCheck; + +STGsAccMoverEventCheck g_MoveEventCheckStruct; +GU16 g_bufferlen; +GS32 g_siLastDirectionAngle = 0; + +/** +* @fn GetGsensorMoveEventCheckIni(GU8 usAccThrMax, GU8 usAccThrMin,GU8 usAccThrScale,GU8 usAccThrNum) +* +* @brief initialzation of GetGsensorMoveEventCheckExe. +* +* @attention None +* +* @param[in] Thr param +* @param[out] none +* +* @return none +*/ + +void GetGsensorMoveEventCheckIni(GU16 usAccThrMax, GU16 usAccThrMin, GU16 usAccThrScale, GU16 usAccThrNum) +{ + GH3X2X_Memset(g_MoveEventCheckStruct.sAccDifBuf, 0, 125 * sizeof(GS16)); + g_MoveEventCheckStruct.sAccThrMax = usAccThrMax; + g_MoveEventCheckStruct.sAccThrMin = usAccThrMin; + g_MoveEventCheckStruct.sAccThrNum = usAccThrNum; + g_MoveEventCheckStruct.sAccThrScale = usAccThrScale; + g_MoveEventCheckStruct.sAccVal = 0; + g_MoveEventCheckStruct.sLastAccVal = 0; + g_MoveEventCheckStruct.sXAxisVal = 0; + g_MoveEventCheckStruct.sYAxisVal = 0; + g_MoveEventCheckStruct.sZAxisVal = 0; + g_MoveEventCheckStruct.uchGsensorDifBufIndex = 0; + g_bufferlen = 125; + g_siLastDirectionAngle = 0; +} + +/** +* @fn GU8 GetGsensorMoveEventCheckExe(GS16* pusGsData) + +* +* @brief Get the movement event by software. +* +* @attention None +* +* @param[in] pusGsData gsensor data buffer +* @param[out] mN >= g_MoveEventCheckStruct.sAccThrNum +* +* @return //bit0 move flag bit1 direct abnormal flag +*/ +GU8 GetGsensorMoveEventCheckExe(GS16* pusGsData) +{ + GS32 sRmsAcc = 0.0; + GF32 fMeanAcc = 0.0; + GF32 fStdAcc = 0.0; + GF32 fSumX = 0.0; + GF32 fSumX2 = 0.0; + GU8 mN = 0; + GU8 lubMoveFlag = 0; //bit0 move flag bit1 direct abnormal flag + GS32 lsiDirectionAngle = 0; + GU8 uchFirstFrameFlag = 0; + g_MoveEventCheckStruct.sXAxisVal = pusGsData[0]; + g_MoveEventCheckStruct.sYAxisVal = pusGsData[0 + 1]; + g_MoveEventCheckStruct.sZAxisVal = pusGsData[0 + 2]; + + sRmsAcc = sqrt((GS32)g_MoveEventCheckStruct.sXAxisVal*g_MoveEventCheckStruct.sXAxisVal + (GS32)g_MoveEventCheckStruct.sYAxisVal*g_MoveEventCheckStruct.sYAxisVal + (GS32)g_MoveEventCheckStruct.sZAxisVal*g_MoveEventCheckStruct.sZAxisVal) / 3; + + if (0 == g_MoveEventCheckStruct.uchGsensorDifBufIndex) + { + uchFirstFrameFlag = 1; + g_MoveEventCheckStruct.sAccDifBuf[g_MoveEventCheckStruct.uchGsensorDifBufIndex] = 0; + ++g_MoveEventCheckStruct.uchGsensorDifBufIndex; + } + else + { + uchFirstFrameFlag = 0; + if (g_MoveEventCheckStruct.uchGsensorDifBufIndex < g_bufferlen) + { + g_MoveEventCheckStruct.sAccDifBuf[g_MoveEventCheckStruct.uchGsensorDifBufIndex] = (GS16)sRmsAcc - g_MoveEventCheckStruct.sLastAccVal; + ++g_MoveEventCheckStruct.uchGsensorDifBufIndex; + } + else + { + memmove(g_MoveEventCheckStruct.sAccDifBuf, g_MoveEventCheckStruct.sAccDifBuf + 1, (g_bufferlen - 1)*sizeof(GS16)); + g_MoveEventCheckStruct.sAccDifBuf[g_bufferlen - 1] = (GS16)sRmsAcc - g_MoveEventCheckStruct.sLastAccVal; + } + } + g_MoveEventCheckStruct.sLastAccVal = sRmsAcc; + + for (GU8 i = 0; i < g_MoveEventCheckStruct.uchGsensorDifBufIndex; i++) + { + fSumX = fSumX + g_MoveEventCheckStruct.sAccDifBuf[i]; + fSumX2 = fSumX2 + (GF32)g_MoveEventCheckStruct.sAccDifBuf[i] * g_MoveEventCheckStruct.sAccDifBuf[i]; + } + fMeanAcc = fSumX / g_MoveEventCheckStruct.uchGsensorDifBufIndex; + fStdAcc = sqrtf(((fSumX2 / g_MoveEventCheckStruct.uchGsensorDifBufIndex - fMeanAcc*fMeanAcc) >(0) ? (fSumX2 / g_MoveEventCheckStruct.uchGsensorDifBufIndex - fMeanAcc*fMeanAcc) : (0))); + + GF32 ftemp = ((g_MoveEventCheckStruct.sAccThrScale*fStdAcc) > (g_MoveEventCheckStruct.sAccThrMin) ? (g_MoveEventCheckStruct.sAccThrScale*fStdAcc) : (g_MoveEventCheckStruct.sAccThrMin)); + GF32 fThr = ((g_MoveEventCheckStruct.sAccThrMax) < (ftemp) ? (g_MoveEventCheckStruct.sAccThrMax) : (ftemp)); + + for (GU8 i = 0; i < g_MoveEventCheckStruct.uchGsensorDifBufIndex; i++) + { + if ((GF32)g_MoveEventCheckStruct.sAccDifBuf[i] - fMeanAcc > fThr || (GF32)fMeanAcc - g_MoveEventCheckStruct.sAccDifBuf[i] > fThr) + { + mN++; + } + } + //return (mN >= g_MoveEventCheckStruct.sAccThrNum); + if (mN >= g_MoveEventCheckStruct.sAccThrNum) + { + lubMoveFlag |= (((GU8)1) << 0); //set bit0 : move flag + } + + + //checak calculate direct is abnormal or not + lsiDirectionAngle = atan(sqrt(((GS32)g_MoveEventCheckStruct.sXAxisVal*g_MoveEventCheckStruct.sXAxisVal + (GS32)g_MoveEventCheckStruct.sYAxisVal*g_MoveEventCheckStruct.sYAxisVal)) / g_MoveEventCheckStruct.sZAxisVal) * 180 / 3.1416; + if (uchFirstFrameFlag) // first frame + { + g_siLastDirectionAngle = lsiDirectionAngle; //use the rawdata + } + else // do IIR filter + { + g_siLastDirectionAngle = (lsiDirectionAngle * 1 + g_siLastDirectionAngle * 3) / 4; // current data weight is 0.25 + } + if ((g_siLastDirectionAngle > 40) || (g_siLastDirectionAngle < 0)) // angle is too big or watch screen is downward + { + lubMoveFlag |= (((GU8)1) << 1); //set bit1 : abnormale angel + } + + return lubMoveFlag; +} + + +//source code +#if 0 +void main() +{ + GU16 usAccThrMax=30; + GU16 usAccThrMin=15; + GU16 usAccThrScale=4; + GU16 usAccThrNum=3; + GetGsensorMoveEventCheckIni(usAccThrMax, usAccThrMin, usAccThrScale, usAccThrNum); + + GS16 pusGsData[3] = {0}; + pusGsData[0] = 1; //x + pusGsData[1] = 2; //y + pusGsData[2] = 512; //z + GU8 result = GetGsensorMoveEventCheckExe(pusGsData); + +} +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_movedetect.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_movedetect.h new file mode 100644 index 000000000..c8ed125b6 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_other/gh_movedetect.h @@ -0,0 +1,24 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh_movedetect.h + * + * @brief move detect + * + * @version ref gh_drv_version.h + * + */ + + +#ifndef _GH_MOVEDETECT_H_ +#define _GH_MOVEDETECT_H_ + +#include "gh_drv.h" + +void GetGsensorMoveEventCheckIni(GU16 usAccThrMax, GU16 usAccThrMin,GU16 usAccThrScale,GU16 usAccThrNum); +GU8 GetGsensorMoveEventCheckExe(GS16* pusGsData); + +#endif /* _GH_MOVEDETECT_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_datatrans.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_datatrans.c new file mode 100644 index 000000000..df566fe3e --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_datatrans.c @@ -0,0 +1,536 @@ +#include "gh_drv.h" +#include "gh_drv_common.h" +#include "gh_datatrans.h" +//#include "goodix_mem.h" + +static GU8 g_uchPayloadHandleInitFlag = 0; +static GU8 g_uchProtocolCmd = 0; +static GU16 g_usPayloadBufferLength = 0; +static GU16 g_usPayloadBufferOffset = 0; +static GU8 *g_puchPayloadBuffer = GH3X2X_PTR_NULL; +static pfnSendProtocolDataFunc g_pGh3x2xProtocolSendFunc; +static pfnFrameDataOutputFunc g_pGh3x2xProtocolFrameDataOutputFunc; + +void* GH3X2X_UserMalloc(GU32 mem_len) +{ + void* addr = 0;//goodix_mem_malloc(mem_len); + return addr; +} + +void GH3X2X_UserFree(void* mem_addr) +{ + //goodix_mem_free(mem_addr); +} + +EMPayloadHandleRet GH3X2X_ProtocolSectionInit(GU8 uchProtocolCmd, + GU8 *puchPayloadDataBuffer, + GU16 usPayloadDataBufferLength, + void (*pfnSendProtocolDataFunc)(GU8 uchCmd, GU8* puchBuffer, GU16 usLen), + void (*pfnFrameDataOutputFunc)(GU8* puchFunctionID, + GU8* puchFrameID, + STProtocolPackInfo** pstReceivePackInfo, + GU8* puchPackNum)) +{ + if ((pfnSendProtocolDataFunc != GH3X2X_PTR_NULL) || + (pfnFrameDataOutputFunc != GH3X2X_PTR_NULL) || + (usPayloadDataBufferLength != 0) || + (g_puchPayloadBuffer != GH3X2X_PTR_NULL)) + { + g_uchProtocolCmd = uchProtocolCmd; + g_pGh3x2xProtocolSendFunc = pfnSendProtocolDataFunc; + g_puchPayloadBuffer = puchPayloadDataBuffer; + g_usPayloadBufferLength = usPayloadDataBufferLength; + g_usPayloadBufferOffset = usPayloadDataBufferLength; + g_pGh3x2xProtocolFrameDataOutputFunc = pfnFrameDataOutputFunc; + g_uchPayloadHandleInitFlag = 1; + return GH_PAYLOAD_HANDLE_CONTINUE; + } + else + { + g_uchPayloadHandleInitFlag = 0; + return GH_PAYLOAD_HANDLE_NOINIT; + } +} + +EMPayloadHandleRet GH3X2X_ProtocolPackCheck(STProtocolPackInfo *pstPackInfo) +{ + if (pstPackInfo != GH3X2X_PTR_NULL) + { + if ((pstPackInfo->uchByteType != 0) && + (pstPackInfo->uchDataNum != 0) && + (pstPackInfo->pSrc != GH3X2X_PTR_NULL)) + { + return GH_PAYLOAD_HANDLE_CONTINUE; + } + else + { + if (pstPackInfo->pSrc == GH3X2X_PTR_NULL) + { + return GH_PAYLOAD_HANDLE_ADDRNULL; + } + else + { + return GH_PAYLOAD_HANDLE_DATAERR; + } + } + } + else + { + return GH_PAYLOAD_HANDLE_ADDRNULL; + } +} + +EMPayloadHandleRet GH3X2X_ProtocolPackHandle(STProtocolPackInfo *pstPackInfo, + GU8 *puchPayloadDest, + GU16 *pusPayloadMaxLen, + GU8 uchSeparateFlag, + GU32 *punSeparateDataOffset) +{ + GU16 usPayloadMaxLen = *pusPayloadMaxLen; + GU32 unSeparateDataOffset = *punSeparateDataOffset; + GU8 uchHeaderLength = 0; + //pack id + puchPayloadDest[GH_PAYLOAD_PACKHEADER_OFFSET_PACKID] = pstPackInfo->uchPackID; + uchHeaderLength++; + //pack flag + puchPayloadDest[GH_PAYLOAD_PACKHEADER_OFFSET_FLAG] = pstPackInfo->uchFlag; + uchHeaderLength++; + //byte type + if (GH3X2X_CHECK_LEFT_BIT_SET(pstPackInfo->uchFlag, GH_PACK_FLAG_BYTETYPE)) + { + puchPayloadDest[GH_PAYLOAD_PACKHEADER_OFFSET_BYTETYPE] = pstPackInfo->uchByteType; + uchHeaderLength++; + } + //data num + if (GH3X2X_CHECK_LEFT_BIT_SET(pstPackInfo->uchFlag, GH_PACK_FLAG_DATANUM)) + { + puchPayloadDest[GH_PAYLOAD_PACKHEADER_OFFSET_DATANUM] = pstPackInfo->uchDataNum; + uchHeaderLength++; + } + if (uchHeaderLength >= usPayloadMaxLen) + { + SET_VAL_VIA_PTR(pusPayloadMaxLen, usPayloadMaxLen); + SET_VAL_VIA_PTR(punSeparateDataOffset, unSeparateDataOffset); + return GH_PAYLOAD_HANDLE_PAYLOADFULL; + } + usPayloadMaxLen -= uchHeaderLength; + GU16 usDataLength = pstPackInfo->uchByteType * pstPackInfo->uchDataNum; + if ((usPayloadMaxLen >= usDataLength) && (unSeparateDataOffset == 0)) + { + GH3X2X_Memcpy((puchPayloadDest + uchHeaderLength), + pstPackInfo->pSrc, + usDataLength); + usPayloadMaxLen -= usDataLength; + SET_VAL_VIA_PTR(pusPayloadMaxLen, usPayloadMaxLen); + SET_VAL_VIA_PTR(punSeparateDataOffset, unSeparateDataOffset); + return GH_PAYLOAD_HANDLE_CONTINUE; + } + else + { + if (uchSeparateFlag) + { + GU16 usCpyLength = 0; + usCpyLength = (usDataLength - unSeparateDataOffset) > usPayloadMaxLen ? usPayloadMaxLen : (usDataLength - unSeparateDataOffset); + GH3X2X_Memcpy((puchPayloadDest + uchHeaderLength), + &(((GU8*)pstPackInfo->pSrc)[unSeparateDataOffset]), + usCpyLength); + unSeparateDataOffset += usCpyLength; + usPayloadMaxLen -= usCpyLength; + if (unSeparateDataOffset == usDataLength) + { + unSeparateDataOffset = 0; + SET_VAL_VIA_PTR(pusPayloadMaxLen, usPayloadMaxLen); + SET_VAL_VIA_PTR(punSeparateDataOffset, unSeparateDataOffset); + return GH_PAYLOAD_HANDLE_CONTINUE; + } + } + SET_VAL_VIA_PTR(pusPayloadMaxLen, usPayloadMaxLen); + SET_VAL_VIA_PTR(punSeparateDataOffset, unSeparateDataOffset); + return GH_PAYLOAD_HANDLE_PAYLOADFULL; + } +} + +EMPayloadHandleRet GH3X2X_ProtocolPayloadHandle(EMProtocolSendMode emSendMode, + EMProtocolSendHandle emSendHandle, + GU8 uchFunctionID, + GU8 uchFrameID, + STProtocolPackInfo *pstPackInfo, + GU8 uchPackNum) +{ + if (g_uchPayloadHandleInitFlag != 1) + { + return GH_PAYLOAD_HANDLE_NOINIT; + } + + static GU8 uchSeparateID = 0; + + GU8 uchSeparateFlag = 0; + GU8 uchPackCnt = 0; + GU8 uchPackCntRecord = 0; + GU8 uchSeparateStatus = 1; + GU8 uchFrameHeaderLength = 0; + GU32 unPackSrcByteRecord = 0; + GU32 unAllPackByteNum = 0; + EMPayloadHandleRet emRet = GH_PAYLOAD_HANDLE_CONTINUE; + EMPayloadHandleProcess emHandleFlag = GH_PAYLOAD_HANDLE_FULL_HEADER; + + //check all packs + for (GU8 PackCnt = 0; PackCnt < uchPackNum; PackCnt++) + { + emRet = GH3X2X_ProtocolPackCheck(&pstPackInfo[PackCnt]); + if (emRet) + { + GH3X2X_DEBUG_LOG_PARAM("[%s]:pack %d is err, ret = %d\r\n", __FUNCTION__, uchPackCnt, (int)emRet); + return emRet; + } + STProtocolPackInfo* pstPackInfoTemp = &pstPackInfo[PackCnt]; + GU8 uchPackHeaderLength = 2 + \ + (GH3X2X_CHECK_LEFT_BIT_SET(pstPackInfoTemp->uchFlag, GH_PACK_FLAG_BYTETYPE)) + \ + (GH3X2X_CHECK_LEFT_BIT_SET(pstPackInfoTemp->uchFlag, GH_PACK_FLAG_DATANUM)); + unAllPackByteNum += (pstPackInfoTemp->uchByteType * pstPackInfoTemp->uchDataNum + uchPackHeaderLength); + } + + //pack + while(emHandleFlag != GH_PAYLOAD_HANDLE_OVER) + { + switch (emHandleFlag) + { + case GH_PAYLOAD_HANDLE_FULL_HEADER://full header + //flag + g_puchPayloadBuffer[GH_PAYLOADHEADER_OFFSET_FLAG] = 0; + g_usPayloadBufferOffset--; + //frame id + if (emSendMode != GH_PROTOCOL_SENDMODE_FAST) + { + g_puchPayloadBuffer[GH_PAYLOADHEADER_OFFSET_FLAG] |= ((0x1) << GH_PAYLOAD_FLAG_SEND_MODE); + g_puchPayloadBuffer[GH_PAYLOADHEADER_OFFSET_FUNCID] = uchFunctionID; + g_usPayloadBufferOffset--; + } + //check size + uchFrameHeaderLength = 2; + //separate flag + uchSeparateFlag = (unAllPackByteNum + uchFrameHeaderLength > g_usPayloadBufferOffset); + //separate payload id + if (uchSeparateFlag) + { + g_puchPayloadBuffer[GH_PAYLOADHEADER_OFFSET_FLAG] |= (0x1 << GH_PAYLOAD_FLAG_SEPARATE_ENABLE); + g_puchPayloadBuffer[GH_PAYLOADHEADER_OFFSET_FLAG] |= (uchSeparateStatus << GH_PAYLOAD_FLAG_SEPARATE_STATUS); + uchSeparateStatus = 0; + g_puchPayloadBuffer[g_usPayloadBufferLength - g_usPayloadBufferOffset] = uchSeparateID; + uchSeparateID++; + g_usPayloadBufferOffset--; + } + emHandleFlag = GH_PAYLOAD_HANDLE_FULL_DATA; + break; + case GH_PAYLOAD_HANDLE_FULL_DATA://full data + //frame id + if (emSendMode != GH_PROTOCOL_SENDMODE_FAST) + { + g_puchPayloadBuffer[g_usPayloadBufferLength - g_usPayloadBufferOffset] = uchFrameID; + g_usPayloadBufferOffset--; + } + g_puchPayloadBuffer[g_usPayloadBufferLength - g_usPayloadBufferOffset] = uchPackNum; + g_usPayloadBufferOffset--; + //pack pack + for (uchPackCnt = uchPackCntRecord; uchPackCnt < uchPackNum; uchPackCnt++) + { + emRet = GH3X2X_ProtocolPackHandle(&pstPackInfo[uchPackCnt], + &g_puchPayloadBuffer[g_usPayloadBufferLength - g_usPayloadBufferOffset], + &g_usPayloadBufferOffset, + uchSeparateFlag, + &unPackSrcByteRecord); + if (emRet == GH_PAYLOAD_HANDLE_PAYLOADFULL) + { + if (uchSeparateFlag) + { + uchPackCntRecord = uchPackCnt; + } + HOOK_FUNC_CALL(g_pGh3x2xProtocolSendFunc, (g_uchProtocolCmd, g_puchPayloadBuffer, g_usPayloadBufferLength - g_usPayloadBufferOffset)); + g_usPayloadBufferOffset = g_usPayloadBufferLength; + emHandleFlag = GH_PAYLOAD_HANDLE_FULL_HEADER; + break; + } + } + if (uchPackCnt == uchPackNum) + { + if (emSendMode != GH_PROTOCOL_SENDMODE_FRAME || (unAllPackByteNum + uchFrameHeaderLength > g_usPayloadBufferOffset)) + { + uchSeparateStatus = 2; + g_puchPayloadBuffer[GH_PAYLOADHEADER_OFFSET_FLAG] |= (uchSeparateStatus << GH_PAYLOAD_FLAG_SEPARATE_STATUS); + if (emRet == GH_PAYLOAD_HANDLE_CONTINUE) + { + HOOK_FUNC_CALL(g_pGh3x2xProtocolSendFunc, (g_uchProtocolCmd, g_puchPayloadBuffer, g_usPayloadBufferLength - g_usPayloadBufferOffset)); + g_usPayloadBufferOffset = g_usPayloadBufferLength; + } + uchSeparateStatus = 0; + uchPackCntRecord = 0; + uchSeparateID = 0; + emHandleFlag = GH_PAYLOAD_HANDLE_OVER; + } + } + break; + default: + break; + } + } + return GH_PAYLOAD_HANDLE_CONTINUE; +} + +GU8 malloc_flag = 0; + +EMPacyloadLostRet GH3X2X_PacketLossCheck(GU8 uchSeparateStatusRecord, + GU8 uchSeparateStatus, + GU8 uchSeparateIDRecord, + GU8 uchSeparateID, + GU8 uchFrameIDRecord, + GU8 uchFrameID) +{ + if (uchFrameID == 0 && uchSeparateID == 0 && uchFrameIDRecord == 0 && uchSeparateIDRecord == 0) + { + return GH_PAYLOAD_LOST_NOLOST; + } + if ((uchFrameID != uchFrameIDRecord && uchSeparateStatusRecord == 2 && uchSeparateStatus != 1)|| + (uchFrameID == uchFrameIDRecord && uchSeparateStatusRecord == 2)) + { + GH3X2X_DEBUG_LOG_PARAM("GH_PAYLOAD_LOST_PREVIOUS_LOST\n"); + return GH_PAYLOAD_LOST_PREVIOUS_LOST; + } + if (uchFrameID != uchFrameIDRecord && uchSeparateStatusRecord == 1 && (uchSeparateID != uchSeparateIDRecord + 1 || uchSeparateStatus == 1)) + { + GH3X2X_DEBUG_LOG_PARAM("GH_PAYLOAD_LOST_LAST_LOST\n"); + return GH_PAYLOAD_LOST_LAST_LOST; + } + if (uchFrameID == uchFrameIDRecord && uchSeparateID != uchSeparateIDRecord + 1) + { + GH3X2X_DEBUG_LOG_PARAM("GH_PAYLOAD_LOST_MID_LOST\n"); + return GH_PAYLOAD_LOST_MID_LOST; + } + if (uchFrameID != uchFrameIDRecord && uchSeparateStatusRecord != 2 && uchSeparateStatus != 1) + { + GH3X2X_DEBUG_LOG_PARAM("GH_PAYLOAD_LOST_DOUBLE_LOST\n"); + return GH_PAYLOAD_LOST_DOUBLE_LOST; + } + return GH_PAYLOAD_LOST_NOLOST; +} + +void GH3X2X_MallocPackStruct(GU8 uchPackNum, GU8* puchPackCntRecord, STProtocolPackInfo*** pstPackInfo, GU8** puchPackMallocFlag) +{ + *puchPackCntRecord = 0; + *pstPackInfo = GH3X2X_UserMalloc(uchPackNum * sizeof(STProtocolPackInfo*)); + GH3X2X_Memset(*pstPackInfo, 0, uchPackNum * sizeof(STProtocolPackInfo*)); + *puchPackMallocFlag = GH3X2X_UserMalloc(uchPackNum * sizeof(GU8)); + GH3X2X_Memset(*puchPackMallocFlag, 0, uchPackNum * sizeof(GU8)); + for (GU8 uchPackCnt = 0; uchPackCnt < uchPackNum; uchPackCnt++) + { + (*pstPackInfo)[uchPackCnt] = GH3X2X_UserMalloc(sizeof(STProtocolPackInfo)); + GH3X2X_Memset((*pstPackInfo)[uchPackCnt], 0, sizeof(STProtocolPackInfo)); + } +} + +void GH3X2X_FreePackStruct(GU8 uchPackNum, GU8* puchPackCntRecord, STProtocolPackInfo*** pstPackInfo, GU8** puchPackMallocFlag) +{ + for (GS8 uchPackCnt = uchPackNum - 1; uchPackCnt >= 0; uchPackCnt--) + { + + GH3X2X_UserFree((*pstPackInfo)[uchPackCnt]->pSrc); + } + for (GS8 uchPackCnt = uchPackNum - 1; uchPackCnt >= 0; uchPackCnt--) + { + GH3X2X_UserFree((*pstPackInfo)[uchPackCnt]); + } + GH3X2X_UserFree(*puchPackMallocFlag); + GH3X2X_UserFree(*pstPackInfo); + *pstPackInfo = GH3X2X_PTR_NULL; + *puchPackCntRecord = 0; +} + +EMPayloadReceiveRet GH3X2X_ProtocolPayloadDecode(GU8 *puchPayloadBuffer, + GU16 usPayloadLen) +{ + static GU8 uchPackCntRecord = 0; + static GU16 unPackSrcByteRecord = 0; + static GU8 *puchPackMallocFlag = 0; + static STProtocolPackInfo** pstPackInfo = GH3X2X_PTR_NULL; + + static GU8 uchFrameIDRecord = 0; + static GU8 uchSeparateIDRecord = 0; + static GU8 uchSeparateStatusRecord = 2; + static EMPacyloadLostRet emLostRet = GH_PAYLOAD_LOST_NOLOST; + + GU16 usPayloadOffset = 0; + GU8 uchSeparateID = 0; + GU8 uchPackNum = 0; + GU8 uchPackCnt = 0; + GU8 uchFunctionID = 0; + GU8 uchFrameID = 0; + + GU8 uchPayloadFlag = puchPayloadBuffer[GH_PAYLOADHEADER_OFFSET_FLAG]; + usPayloadOffset++; + GU8 uchSeparateFlag = GH3X2X_CHECK_LEFT_BIT_SET(uchPayloadFlag, GH_PAYLOAD_FLAG_SEPARATE_ENABLE); + GU8 uchSeparateStatus = GH3X2X_CHECK_LEFT_BIT_SET(uchPayloadFlag, GH_PAYLOAD_FLAG_SEPARATE_STATUS)| (GH3X2X_CHECK_LEFT_BIT_SET(uchPayloadFlag, GH_PAYLOAD_FLAG_SEPARATE_STATUS + 1) << 1); + EMProtocolSendMode emPayloadMode = (EMProtocolSendMode)GH3X2X_CHECK_LEFT_BIT_SET(uchPayloadFlag, GH_PAYLOAD_FLAG_SEND_MODE); + + if (emPayloadMode != GH_PROTOCOL_SENDMODE_FAST) + { + uchFunctionID = puchPayloadBuffer[usPayloadOffset]; + usPayloadOffset++; + } + + if (uchSeparateFlag) + { + uchSeparateID = puchPayloadBuffer[usPayloadOffset]; + usPayloadOffset++; + } + + if (emPayloadMode != GH_PROTOCOL_SENDMODE_FAST) + { + uchFrameID = puchPayloadBuffer[usPayloadOffset]; + usPayloadOffset++; + } + + //check lost payload + if (uchSeparateFlag) + { + EMPayloadReceiveRet emRet = GH_PAYLOAD_HANDLE_FRAME_LOST_PAYLOAD; + + if (uchSeparateID == 0) + { + emRet = GH_PAYLOAD_HANDLE_FRAME_NOT_FINISH;; + } + + switch (emLostRet) + { + case GH_PAYLOAD_LOST_MID_LOST: + case GH_PAYLOAD_LOST_DOUBLE_LOST: + case GH_PAYLOAD_LOST_PREVIOUS_LOST: + break; + default: + emRet = GH_PAYLOAD_HANDLE_FRAME_NOT_FINISH; + break; + } + + if (emRet == GH_PAYLOAD_HANDLE_FRAME_LOST_PAYLOAD) + { + return emRet; + } + + emLostRet = GH3X2X_PacketLossCheck(uchSeparateStatusRecord, + uchSeparateStatus, + uchSeparateIDRecord, + uchSeparateID, + uchFrameIDRecord, + uchFrameID); + + emRet = GH_PAYLOAD_HANDLE_FRAME_LOST_PAYLOAD; + switch (emLostRet) + { + case GH_PAYLOAD_LOST_LAST_LOST: + emRet = GH_PAYLOAD_HANDLE_FRAME_NOT_FINISH; + case GH_PAYLOAD_LOST_MID_LOST: + case GH_PAYLOAD_LOST_DOUBLE_LOST: + GH3X2X_FreePackStruct(uchPackNum, &uchPackCntRecord, &pstPackInfo, &puchPackMallocFlag); + if (malloc_flag == 1) + { + malloc_flag = 0; + } + unPackSrcByteRecord = 0; + break; + case GH_PAYLOAD_LOST_PREVIOUS_LOST: + break; + default: + emRet = GH_PAYLOAD_HANDLE_FRAME_NOT_FINISH; + break; + } + + if (emRet == GH_PAYLOAD_HANDLE_FRAME_LOST_PAYLOAD) + { + return emRet; + } + + uchSeparateStatusRecord = uchSeparateStatus; + uchFrameIDRecord = uchFrameID; + uchSeparateIDRecord = uchSeparateID; + } + + uchPackNum = puchPayloadBuffer[usPayloadOffset]; + + if ((uchSeparateFlag && uchSeparateStatus == 1) || (uchSeparateFlag == 0)) + { + GH3X2X_MallocPackStruct(uchPackNum, &uchPackCntRecord, &pstPackInfo, &puchPackMallocFlag); + if (malloc_flag == 0) + { + malloc_flag = 1; + } + } + + usPayloadOffset++; + + for (uchPackCnt = uchPackCntRecord; uchPackCnt < uchPackNum; uchPackCnt++) + { + //pack id + pstPackInfo[uchPackCnt]->uchPackID = puchPayloadBuffer[usPayloadOffset]; + usPayloadOffset++; + //pack flag + pstPackInfo[uchPackCnt]->uchFlag = puchPayloadBuffer[usPayloadOffset]; + usPayloadOffset++; + //byte type + if (GH3X2X_CHECK_LEFT_BIT_SET(pstPackInfo[uchPackCnt]->uchFlag, GH_PACK_FLAG_BYTETYPE)) + { + pstPackInfo[uchPackCnt]->uchByteType = puchPayloadBuffer[usPayloadOffset]; + usPayloadOffset++; + } + //data num + if (GH3X2X_CHECK_LEFT_BIT_SET(pstPackInfo[uchPackCnt]->uchFlag, GH_PACK_FLAG_DATANUM)) + { + pstPackInfo[uchPackCnt]->uchDataNum = puchPayloadBuffer[usPayloadOffset]; + usPayloadOffset++; + } + if (puchPackMallocFlag[uchPackCnt] == 0) + { + pstPackInfo[uchPackCnt]->pSrc = GH3X2X_UserMalloc(pstPackInfo[uchPackCnt]->uchByteType * pstPackInfo[uchPackCnt]->uchDataNum); + GH3X2X_Memset(pstPackInfo[uchPackCnt]->pSrc, 0, pstPackInfo[uchPackCnt]->uchByteType * pstPackInfo[uchPackCnt]->uchDataNum); + puchPackMallocFlag[uchPackCnt] = 1; + } + //src + GU16 usCpyLength = 0; + usCpyLength = ((pstPackInfo[uchPackCnt]->uchByteType * pstPackInfo[uchPackCnt]->uchDataNum - unPackSrcByteRecord) > (usPayloadLen - usPayloadOffset)\ + ? (usPayloadLen - usPayloadOffset) : (pstPackInfo[uchPackCnt]->uchByteType * pstPackInfo[uchPackCnt]->uchDataNum - unPackSrcByteRecord)); + GH3X2X_Memcpy(&(((GU8*)pstPackInfo[uchPackCnt]->pSrc)[unPackSrcByteRecord]), &puchPayloadBuffer[usPayloadOffset], usCpyLength); + unPackSrcByteRecord += usCpyLength; + usPayloadOffset += usCpyLength; + uchPackCntRecord = uchPackCnt; + if (pstPackInfo[uchPackCnt]->uchByteType * pstPackInfo[uchPackCnt]->uchDataNum == unPackSrcByteRecord) + { + if (usPayloadOffset == usPayloadLen) + { + uchPackCntRecord++; + } + unPackSrcByteRecord = 0; + } + if (pstPackInfo[uchPackCnt]->uchByteType * pstPackInfo[uchPackCnt]->uchDataNum == (usPayloadLen - usPayloadOffset)) + { + uchPackCntRecord++; + } + if (usPayloadOffset == usPayloadLen) + { + break; + } + } + if (uchPackCnt == uchPackNum || (unPackSrcByteRecord == 0 && uchPackCnt == (uchPackNum - 1))) + { + HOOK_FUNC_CALL(g_pGh3x2xProtocolFrameDataOutputFunc, (&uchFunctionID, &uchFrameID, pstPackInfo, &uchPackNum)); + GH3X2X_FreePackStruct(uchPackNum, &uchPackCntRecord, &pstPackInfo, &puchPackMallocFlag); + uchSeparateStatusRecord = 2; + uchFrameIDRecord = 0; + uchSeparateIDRecord = 0; + unPackSrcByteRecord = 0; + if (malloc_flag == 1) + { + malloc_flag = 0; + } + return GH_PAYLOAD_HANDLE_FRAME_FINISH; + } + return GH_PAYLOAD_HANDLE_FRAME_NOT_FINISH; +} + + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_datatrans.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_datatrans.h new file mode 100644 index 000000000..0db9f4fa5 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_datatrans.h @@ -0,0 +1,154 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_dump.h + * + * @brief gh3x2x data transform + * + * @version ref gh3x2x_drv_datatrans.h + * + */ + +#ifndef _GH3X2X_DEMO_COMMUNICATE_H_ +#define _GH3X2X_DEMO_COMMUNICATE_H_ + +#include "gh_drv.h" + +#define __PROTOCOL_PACK_ZIP_DISABLE__ (0) +#define __PROTOCOL_PACK_ZIP_ENABLE__ (1) + +#define PROTOCOL_RET_NEED_TO_SEND (1) +#define PROTOCOL_RET_CONTINUE (0) +#define PROTOCOL_RET_BUFFER_FULL (-1) + +#define PAYLOAD_INFO_FLAG_OFFSET_FUNCID (0) +#define PAYLOAD_INFO_FLAG_OFFSET_FLAG (1) +#define PAYLOAD_INFO_FLAG_OFFSET_FRAMEID (2) +#define PAYLOAD_INFO_FLAG_OFFSET_PAYLOADID (3) + +typedef enum +{ + GH_PROTOCOL_FUNCID_TOP_PACKTYPE_ID = 0, + GH_PROTOCOL_FUNCINFO_TOP_PACKTYPE_ID, + GH_PROTOCOL_CHNLMAP_TOP_PACKTYPE_ID, + GH_PROTOCOL_RAWDATA_FRAME_PACKTYPE_ID, + GH_PROTOCOL_AGC_INFO_FRAME_PACKTYPE_ID, + GH_PROTOCOL_AMB_DATA_FRAME_PACKTYPE_ID, + GH_PROTOCOL_FLAG_FRAME_PACKTYPE_ID, + GH_PROTOCOL_ALGO_RESULT_FRAME_PACKTYPE_ID, + GH_PROTOCOL_GS_FRAME_PACKTYPE_ID, + GH_PROTOCOL_CAP_FRAME_PACKTYPE_ID, + GH_PROTOCOL_TEMP_FRAME_PACKTYPE_ID, + GH_PROTOCOL_PACK_NUM_MAX, +} EMProtocolPacktypeID; + +typedef enum +{ + GH_PROTOCOL_SENDMODE_FAST = 0, + GH_PROTOCOL_SENDMODE_FRAME = 1, + GH_PROTOCOL_SENDMODE_FRAME_FAST = 2, +} EMProtocolSendMode; + +typedef enum +{ + GH_PROTOCOL_SENDHANDLE_FULLSEND = 0, + GH_PROTOCOL_SENDHANDLE_NOWSEND = 1, +} EMProtocolSendHandle; + +typedef enum +{ + GH_PAYLOAD_HANDLE_CONTINUE = 0, + GH_PAYLOAD_HANDLE_PAYLOADFULL, + GH_PAYLOAD_HANDLE_NOINIT, + GH_PAYLOAD_HANDLE_DATAERR, + GH_PAYLOAD_HANDLE_ADDRNULL, +} EMPayloadHandleRet; + +typedef enum +{ + GH_PAYLOAD_HANDLE_FRAME_NOT_FINISH = 0, + GH_PAYLOAD_HANDLE_FRAME_FINISH, + GH_PAYLOAD_HANDLE_FRAME_LOST_PAYLOAD, +} EMPayloadReceiveRet; + +typedef enum +{ + GH_PAYLOAD_LOST_NOLOST = 0, + GH_PAYLOAD_LOST_PREVIOUS_LOST, + GH_PAYLOAD_LOST_LAST_LOST, + GH_PAYLOAD_LOST_MID_LOST, + GH_PAYLOAD_LOST_DOUBLE_LOST, +} EMPacyloadLostRet; + +typedef enum +{ + GH_PAYLOAD_PACKHEADER_OFFSET_PACKID = 0, + GH_PAYLOAD_PACKHEADER_OFFSET_FLAG, + GH_PAYLOAD_PACKHEADER_OFFSET_BYTETYPE, + GH_PAYLOAD_PACKHEADER_OFFSET_DATANUM, +} EMPackHeaderByteOffset; + +typedef enum +{ + GH_PACK_FLAG_FRAME_START = 0, + GH_PACK_FLAG_ZIP_FLAG, + GH_PACK_FLAG_ZIP_TYPE, + GH_PACK_FLAG_BYTETYPE, + GH_PACK_FLAG_DATANUM, +} EMPackFlagBitOffset; + +typedef enum +{ + GH_PAYLOADHEADER_OFFSET_FLAG= 0, + GH_PAYLOADHEADER_OFFSET_FUNCID, + GH_PAYLOADHEADER_OFFSET_SEPARATEID, +} EMPayloadHeaderByteOffset; + +typedef enum +{ + GH_PAYLOAD_FLAG_SEPARATE_ENABLE = 0, + GH_PAYLOAD_FLAG_SEPARATE_STATUS = 1, + GH_PAYLOAD_FLAG_SEND_MODE = 3, +} EMPayloadFlagBitOffset; + +typedef enum +{ + GH_PAYLOAD_HANDLE_OVER = 0, + GH_PAYLOAD_HANDLE_FULL_HEADER, + GH_PAYLOAD_HANDLE_FULL_DATA, +} EMPayloadHandleProcess; + +typedef struct +{ + GU8 uchPackID; + GU8 uchFlag; + GU8 uchByteType; + GU8 uchDataNum; + GU8 *pSrc; +} STProtocolPackInfo; + +typedef void (*pfnSendProtocolDataFunc)(GU8 uchCmd, GU8* puchProtocolDataBuffer, GU16 usProtocolDataLen); +typedef void (*pfnFrameDataOutputFunc)(GU8* puchFunctionID, GU8* puchFrameID, STProtocolPackInfo** pstReceivePackInfo, GU8* puchPackNum); + +EMPayloadHandleRet GH3X2X_ProtocolSectionInit(GU8 uchProtocolCmd, + GU8 *puchPayloadDataBuffer, + GU16 usPayloadDataBufferLength, + void (*pfnSendProtocolDataFunc)(GU8 uchCmd, GU8* puchBuffer, GU16 usLen), + void (*pfnFrameDataOutputFunc)(GU8* puchFunctionID, + GU8* puchFrameID, + STProtocolPackInfo** pstReceivePackInfo, + GU8* puchPackNum)); + +EMPayloadHandleRet GH3X2X_ProtocolPayloadHandle(EMProtocolSendMode emSendMode, + EMProtocolSendHandle emSendHandle, + GU8 uchFunctionID, + GU8 uchFrameID, + STProtocolPackInfo* pstPackInfo, + GU8 uchPackNum); + +EMPayloadReceiveRet GH3X2X_ProtocolPayloadDecode(GU8 *puchPayloadBuffer, + GU16 usPayloadLen); + +#endif /* _GH3X2X_DRV_DUMP_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_uprotocol.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_uprotocol.c new file mode 100644 index 000000000..640ea2df4 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_uprotocol.c @@ -0,0 +1,2067 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_uprotocol.c + * + * @brief gh3x2x universal protocol functions + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#include +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_uprotocol.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" +#include "gh_drv_dump.h" +#include "gh_agc.h" +#include "gh_demo_config.h" + +/// packet payload +//GU8 g_pstGh3x2xProtocolData->puchPacketPayloadArr[GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX] = {0}; + + +// Zipmode Tempdata +#if 0 +STZipLastDataTemp g_stZipTempData; +#endif + + +#define GH3X2X_PROTOCOL_VERSION_STRING "Gh3x2x_Uprotocol_v0.4" +extern GU8 g_uchFifoPackageID; +extern GU8 g_uchFifoPackageMode; +extern GU8 g_uchResetFromProtocolFlag; + +/// packet payload +GU8 g_uchPacketPayloadIndex = 0; + +/// packet payload +GU8 g_uchPacketPayloadLen = 0; + +/// packet payload +GU8 g_uchPacketCmd = 0; + +/// packet crc8 val +GU8 g_uchPacketCalcCrc8Val = GH3X2X_CRC8_CLEAR_VAL; + +/// packet payload +EMUprotocolParseStatus g_emPacketParseStatus = UPROTOCOL_STATUS_IDLE; + +/// packet max len support +GU8 g_uchPacketMaxLenSupport = GH3X2X_UPROTOCOL_PACKET_LEN_MAX; + +/// chip version string +GCHAR g_szChipVerString[GH3X2X_CHIP_VER_STR_LEN] = {0}; + +/// get firmware version func ptr +static pfnGetFirmwareVersion g_pGh3x2xGetFirmwareVersionFunc = GH3X2X_PTR_NULL; +static pfnGetFirmwareVersion g_pGh3x2xGetDemoVersionFunc = GH3X2X_PTR_NULL; +static pfnGetFirmwareVersion g_pGh3x2xGetBootloaderVersionFunc = GH3X2X_PTR_NULL; + +/// current data index in raw data buf +GU16 g_usGh3x2xDataIndexInBuf = 0; + +GU8 g_uchGh3x2xUploadStatus = 0; +GU8 g_uchGh3x2xUploadBufUse = 0; + +/// current data index in raw data buf of every channel +GU16 g_usRawdataByteIndexArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + +/// current g sensor data index in g sensor data buf +GF32 g_fGsDataIndexInBuf = 0; + +/// current algo result index +GU16 g_usAlgoResIndex = 0; + +///frame id array +//GU8 g_uchFrameIdArr[CHANNEL_MAP_ID_NUM] = {0}; + +/// all function mode available +GU32 g_unAllFuncMode = 0; + +/// already opened function mode +GU32 g_unFuncModeOpened = 0; + +/// function mode will be closed or opened +GU32 g_unTargetFuncMode = 0; + +/// LastIncompleteMark +GU32 g_unLastIncompleteMark = 0; + +/// event need report +GU16 g_usGh3x2xEventNeedReport = 0; + +/// event report id +GU8 g_uchEventReportId = 0; + +/// received event report id +GU8 g_uchEventReportIdReceive = UPROTOCOL_REPORT_EVENT_ID_INIT; + +/// crc8 table +static const GU8 g_uchCrc8TabArr[] = +{ + 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, + 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, + 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, + 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD, + 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, + 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, + 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A, + 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, + 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, + 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4, + 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, + 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, + 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63, + 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, + 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, + 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3, +}; + + +GCHAR *GH3X2X_GetProtocolVersion(void) +{ + return (GCHAR *)GH3X2X_PROTOCOL_VERSION_STRING; +} + + +/** + * @fn GCHAR *GH3X2X_GetChipVersion(void) + * + * @brief Get chip version, only for protocol, format like v11_ev01(11: chip id, 01 efuse ver) + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return chip version string + */ +GCHAR *GH3X2X_GetChipVersion(void) +{ + GU8 uchChipVer = 0; + GU8 uchEfuseVer = 0; + + GH3X2X_CHIP_WAKEUP_NORET(); + uchChipVer = GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_ReadReg(GH3X2X_CHIP_ID_REG_ADDR)); + uchEfuseVer = GH3X2X_GET_LOW_BYTE_FROM_WORD(GH3X2X_ReadReg(GH3X2X_EFUSE_CTRL_EFUSE0_AUTOLOAD_3_ADDR)); + GH3X2X_CHIP_SLEEP_NORET(); + + if(g_pSnprintfUserIn) + { + g_pSnprintfUserIn(g_szChipVerString, GH3X2X_CHIP_VER_STR_LEN, "v%.2x_ev%.2x\r\n", uchChipVer, uchEfuseVer); + return (GCHAR *)g_szChipVerString; + } + return "no snprintf"; + +} + + + + + + +/** + * @fn GU8 GH3X2X_CalcArrayCrc8Val(GU8 uchDataArr[], GU16 usDataIndex, GU16 usDataLen) + * + * @brief Get crc8 data, only for protocol + * + * @attention None + * + * @param[in] uchDataArr pointer to data array + * @param[in] usDataIndex data index need to calc crc8 + * @param[in] usDataLen data len need to calc crc8 + * @param[out] None + * + * @return crc8 value + */ +GU8 GH3X2X_CalcArrayCrc8Val(GU8 uchDataArr[], GU16 usDataIndex, GU16 usDataLen) +{ + GU8 uchCrc8TabIndex; + GU8 uchCrc8 = GH3X2X_CRC8_CLEAR_VAL; + GU16 usIndex = 0; + for (usIndex = usDataIndex; usIndex < usDataLen; usIndex++) + { + uchCrc8TabIndex = (uchCrc8 ^ (uchDataArr[GH3X2X_GET_LOW_BYTE_FROM_WORD(usIndex)])) & GH3X2X_CRC8_CLEAR_VAL; + uchCrc8 = g_uchCrc8TabArr[uchCrc8TabIndex]; + } + return uchCrc8; +} + +/** + * @fn void GH3X2X_CalcByteCrc8Val(GU8 *puchCrc8Val, GU8 uchNeedCalcByte) + * + * @brief real time calc crc8 val, only for protocol, + * + * @attention None + * + * @param[in] uchNeedCalcByte data need calc crc8 + * @param[out] puchCrc8Val pointer to crc8 output & last val input + * + * @return crc8 value + */ +void GH3X2X_CalcByteCrc8Val(GU8 *puchCrc8Val, GU8 uchNeedCalcByte) +{ + GU8 uchCrc8TabIndex; + uchCrc8TabIndex = ((*puchCrc8Val) ^ uchNeedCalcByte) & GH3X2X_CRC8_CLEAR_VAL; + SET_VAL_VIA_PTR(puchCrc8Val, g_uchCrc8TabArr[uchCrc8TabIndex]); +} + +/** + * @fn static GU8 GH3X2X_UprotocolParseBuffer(GU16 *pusHasParseLen, GU8 uchRecvDataBufferArr[], GU16 usDataLen) + * + * @brief parse recv buffer data + * + * @attention only support parse 1 cmd + * + * @param[in] uchRecvDataBufferArr pointer to data array + * @param[in] usDataLen data length + * @param[out] pusHasParseLen pointer to has parse len of buffer + * + * @return got cmd or not + * @retval #GH3X2X_RET_GENERIC_ERROR no cmd has parse done + * @retval #GH3X2X_RET_OK a cmd has parse done + */ +static GS8 GH3X2X_UprotocolParseBuffer(GU16 *pusHasParseLen, GU8 uchRecvDataBufferArr[], GU16 usDataLen) +{ + GU16 usIndex = 0; + GS8 chRet = GH3X2X_RET_GENERIC_ERROR; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + for (usIndex = 0; usIndex < usDataLen; usIndex++) + { + switch (g_emPacketParseStatus) + { + case UPROTOCOL_STATUS_IDLE: + if (uchRecvDataBufferArr[usIndex] == GH3X2X_UPROTOCOL_FIXED_HEADER) + { + GH3X2X_CalcByteCrc8Val(&g_uchPacketCalcCrc8Val, uchRecvDataBufferArr[usIndex]); + g_emPacketParseStatus = UPROTOCOL_STATUS_GOT_FIXED; + } + break; + + case UPROTOCOL_STATUS_GOT_FIXED: + if (uchRecvDataBufferArr[usIndex] == GH3X2X_UPROTOCOL_VERSION) + { + GH3X2X_CalcByteCrc8Val(&g_uchPacketCalcCrc8Val, uchRecvDataBufferArr[usIndex]); + g_emPacketParseStatus = UPROTOCOL_STATUS_GOT_VER; + } + else + { + GH3X2X_CRC8_VAL_CLEAR(g_uchPacketCalcCrc8Val); + g_emPacketParseStatus = UPROTOCOL_STATUS_IDLE; + } + break; + + case UPROTOCOL_STATUS_GOT_VER: + g_uchPacketCmd = uchRecvDataBufferArr[usIndex]; + GH3X2X_CalcByteCrc8Val(&g_uchPacketCalcCrc8Val, uchRecvDataBufferArr[usIndex]); + g_emPacketParseStatus = UPROTOCOL_STATUS_GOT_CMD; + break; + + case UPROTOCOL_STATUS_GOT_CMD: + g_uchPacketPayloadIndex = 0; + if (uchRecvDataBufferArr[usIndex] == 0) + { + g_uchPacketPayloadLen = 0; + GH3X2X_CalcByteCrc8Val(&g_uchPacketCalcCrc8Val, uchRecvDataBufferArr[usIndex]); + g_emPacketParseStatus = UPROTOCOL_STATUS_GOT_PAYLOAD; // if payload len equl 0, goto verify crc8 + } + else if (uchRecvDataBufferArr[usIndex] <= GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX) + { + g_uchPacketPayloadLen = uchRecvDataBufferArr[usIndex]; + GH3X2X_CalcByteCrc8Val(&g_uchPacketCalcCrc8Val, uchRecvDataBufferArr[usIndex]); + g_emPacketParseStatus = UPROTOCOL_STATUS_GOT_LEN; + } + else + { + GH3X2X_CRC8_VAL_CLEAR(g_uchPacketCalcCrc8Val); + g_emPacketParseStatus = UPROTOCOL_STATUS_IDLE; + } + break; + + case UPROTOCOL_STATUS_GOT_LEN: + g_pstGh3x2xProtocolData->puchPacketPayloadArr[g_uchPacketPayloadIndex] = uchRecvDataBufferArr[usIndex]; + g_uchPacketPayloadIndex++; + GH3X2X_CalcByteCrc8Val(&g_uchPacketCalcCrc8Val, uchRecvDataBufferArr[usIndex]); + if (g_uchPacketPayloadIndex >= g_uchPacketPayloadLen) + { + g_emPacketParseStatus = UPROTOCOL_STATUS_GOT_PAYLOAD; + } + break; + + case UPROTOCOL_STATUS_GOT_PAYLOAD: + if (uchRecvDataBufferArr[usIndex] == g_uchPacketCalcCrc8Val) + { + chRet = GH3X2X_RET_OK; + } + GH3X2X_CRC8_VAL_CLEAR(g_uchPacketCalcCrc8Val); + g_emPacketParseStatus = UPROTOCOL_STATUS_IDLE; + break; + + default: + GH3X2X_CRC8_VAL_CLEAR(g_uchPacketCalcCrc8Val); + g_emPacketParseStatus = UPROTOCOL_STATUS_IDLE; + GH3X2X_DEBUG_LOG_PARAM("goto default error, crc8:0x%x\r\n", g_uchPacketCalcCrc8Val); + break; + } // end switch (stParseStatus.ParseState) + + /* if parse cmd done, break */ + if (chRet == GH3X2X_RET_OK) + { + break; + } + } // end for (usIndex = 0; usIndex < usDataLen; usIndex++) + + SET_VAL_VIA_PTR(pusHasParseLen, (GU16)(usIndex + 1)); // set has parse length + + return chRet; +} + +/** + * @fn GU8 GH3X2X_UprotocolPacketFormat(GU8 uchCmd, GU8 *puchPacketBuffer, + * GU8 *puchPayloadData, GU8 uchPayloadDataLen) + * + * @brief universal protocol format packet + * + * @attention None + * + * @param[out] puchPacketBuffer pointer to respond packet buffer + * @param[in] uchCmd cmd id + * @param[in] puchPayloadData pointer to payload buffer + * @param[in] uchPayloadDataLen payload len + * + * @return len after make packet + */ +GU8 GH3X2X_UprotocolPacketFormat(GU8 uchCmd, GU8 *puchPacketBuffer, GU8 *puchPayloadData, GU8 uchPayloadDataLen) +{ + GU8 uchPacketIndex = 0; + GU8 uchPacketPayloadRealLen = GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport); + + /* fixed real len */ + if (uchPacketPayloadRealLen > uchPayloadDataLen) + { + uchPacketPayloadRealLen = uchPayloadDataLen; + } + + puchPacketBuffer[GH3X2X_UPROTOCOL_PACKET_FIXED_INDEX] = GH3X2X_UPROTOCOL_FIXED_HEADER; + puchPacketBuffer[GH3X2X_UPROTOCOL_PACKET_VER_INDEX] = GH3X2X_UPROTOCOL_VERSION; + puchPacketBuffer[GH3X2X_UPROTOCOL_PACKET_CMD_INDEX] = uchCmd; + puchPacketBuffer[GH3X2X_UPROTOCOL_PACKET_LEN_INDEX] = uchPacketPayloadRealLen; + uchPacketIndex += GH3X2X_UPROTOCOL_PACKET_HEADER_LEN; + if (uchPacketPayloadRealLen != 0) + { + GH3X2X_Memcpy(&puchPacketBuffer[uchPacketIndex], puchPayloadData, uchPacketPayloadRealLen); + uchPacketIndex += uchPacketPayloadRealLen; + } + puchPacketBuffer[uchPacketIndex] = GH3X2X_CalcArrayCrc8Val(puchPacketBuffer, 0, + uchPacketPayloadRealLen + GH3X2X_UPROTOCOL_PACKET_HEADER_LEN); + uchPacketIndex++; + + return (uchPacketIndex); +} + +/** + * @fn static void GH3X2X_UprotocolHandleRegRwCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle reg rw cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleRegRwCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + if (g_uchPacketPayloadLen >= UPROTOCOL_REG_RW_HEADER_LENGTH) + { + GU8 uchIndex; + GU16 usRegDataTmp = 0; + GU8 uchRegRwMode = g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_MODE_INDEX]; + GU8 uchRegRwLen = g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_CNT_INDEX]; + GU16 usRegAddr = GH3X2X_MAKEUP_WORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_ADDR_H_INDEX], + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_ADDR_L_INDEX]); + + if (uchRegRwMode == UPROTOCOL_REG_RW_WRITE_MODE) + { + if ((uchRegRwLen > 0) + && ((uchRegRwLen * GH3X2X_REG_ADDR_SIZE) == (g_uchPacketPayloadLen - UPROTOCOL_REG_RW_HEADER_LENGTH))) + { + switch (GH3X2X_GET_BIT_IS_SET(usRegAddr)) + { + case GH3X2X_REG_IS_VIRTUAL0X0_BIT: + GH3X2X_CHIP_WAKEUP_PROTOCOL(); + for (uchIndex = 0; uchIndex < uchRegRwLen; uchIndex++) + { + usRegDataTmp = \ + GH3X2X_MAKEUP_WORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX \ + + (uchIndex * GH3X2X_REG_ADDR_SIZE)], + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX + 1 \ + + (uchIndex * GH3X2X_REG_ADDR_SIZE)]); + GH3X2X_WriteReg(GH3X2X_GET_REG_REAL_ADRR(usRegAddr + (uchIndex * GH3X2X_REG_ADDR_SIZE)), \ + usRegDataTmp); + GU16 usReadRegVal = GH3X2X_ReadReg(GH3X2X_GET_REG_REAL_ADRR(usRegAddr + (uchIndex * GH3X2X_REG_ADDR_SIZE))); + if (usReadRegVal != usRegDataTmp) + { + GH3X2X_DEBUG_LOG_PARAM("reg verify error! addr:0x%.4x,w_val:0x%.4x,r_val:0x%.4x\r\n", + GH3X2X_GET_REG_REAL_ADRR(usRegAddr + (uchIndex * GH3X2X_REG_ADDR_SIZE)), + usRegDataTmp, usReadRegVal); + } + } + GH3X2X_CHIP_SLEEP_PROTOCOL(); + break; + default: + for (uchIndex = 0; uchIndex < uchRegRwLen; uchIndex++) + { + usRegDataTmp = \ + GH3X2X_MAKEUP_WORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX \ + + (uchIndex * GH3X2X_REG_ADDR_SIZE)], + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX + 1 \ + + (uchIndex * GH3X2X_REG_ADDR_SIZE)]); + GH3X2X_WriteVirtualReg(usRegAddr + (uchIndex * GH3X2X_REG_ADDR_SIZE), + usRegDataTmp); + } + break; + } + } // end of if ((uchRegRwLen > 0) && ... + else + { + GH3X2X_DEBUG_LOG_PARAM("reg rw write len error!\r\n"); + } + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, g_uchPacketPayloadLen)); + } // end of if (uchRegRwMode == UPROTOCOL_REG_RW_WRITE_MODE) + else if (uchRegRwMode == UPROTOCOL_REG_RW_READ_MODE) + { + if (uchRegRwLen > 0) + { + GU8 uchMaxRegLen = (GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport) + - UPROTOCOL_REG_RW_HEADER_LENGTH) / GH3X2X_REG_ADDR_SIZE; + GU16 usRegType = 0; + if (uchRegRwLen > uchMaxRegLen) + { + uchRegRwLen = uchMaxRegLen; // fixed max len + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_CNT_INDEX] = uchRegRwLen; + } + usRegType = GH3X2X_GET_BIT_IS_SET(usRegAddr); + if(0xAAAA == usRegAddr) + { + usRegType = GH3X2X_REG_IS_VIRTUAL0X0_BIT; + } + switch (usRegType) + { + case GH3X2X_REG_IS_VIRTUAL0X0_BIT: + GH3X2X_CHIP_WAKEUP_PROTOCOL(); + + if(0xAAAA == usRegAddr) + { + GH3X2X_ReadFifo(&(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX]), uchRegRwLen*2); + } + else + { + for (uchIndex = 0; uchIndex < uchRegRwLen; uchIndex++) + { + + usRegDataTmp = GH3X2X_ReadReg(GH3X2X_GET_REG_REAL_ADRR(usRegAddr\ + + (uchIndex * GH3X2X_REG_ADDR_SIZE))); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX + (uchIndex * GH3X2X_REG_ADDR_SIZE)] = \ + GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegDataTmp); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX + 1 + (uchIndex * GH3X2X_REG_ADDR_SIZE)] = \ + GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegDataTmp); + } + } + GH3X2X_CHIP_SLEEP_PROTOCOL(); + break; + default: + #if GH3X2X_SUPPORT_READ_BACK_VIRTUAL_REG + for (uchIndex = 0; uchIndex < uchRegRwLen; uchIndex++) + { + usRegDataTmp = GH3X2X_ReadVirtualReg(usRegAddr\ + + (uchIndex * GH3X2X_REG_ADDR_SIZE)); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX + (uchIndex * GH3X2X_REG_ADDR_SIZE)] = \ + GH3X2X_GET_HIGH_BYTE_FROM_WORD(usRegDataTmp); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REG_RW_DATA_INDEX + 1 + (uchIndex * GH3X2X_REG_ADDR_SIZE)] = \ + GH3X2X_GET_LOW_BYTE_FROM_WORD(usRegDataTmp); + } + #endif + break; + } + } // end of if (uchRegRwLen > 0) + else + { + GH3X2X_DEBUG_LOG_PARAM("reg rw read len error!\r\n"); + } + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_REG_RW_HEADER_LENGTH + uchRegRwLen * GH3X2X_REG_ADDR_SIZE)); + } // end of else if (uchRegRwMode == UPROTOCOL_REG_RW_WRITE_MODE) + } // end if (g_uchPacketPayloadLen >= UPROTOCOL_REG_RW_HEADER_LENGTH) + else + { + GH3X2X_DEBUG_LOG_PARAM("reg rw payload error!\r\n"); + } +} + +/** + * @fn void GH3X2X_RegisterGetFirmwareVersionFunc(GCHAR* (*pGetFirmwareVersionFunc)(void)) + * + * @brief Register get firmware version function + * + * @attention None + * + * @param[in] pGetFirmwareVersionFunc pointer to get firmware versionn function + * @param[out] None + * + * @return None + */ +void GH3X2X_RegisterGetFirmwareVersionFunc(GCHAR* (*pGetFirmwareVersionFunc)(void), + GCHAR* (*pGetDemoVersionFunc)(void), + GCHAR* (*pGetBootloaderVersionFunc)(void)) +{ + g_pGh3x2xGetFirmwareVersionFunc = pGetFirmwareVersionFunc; + g_pGh3x2xGetDemoVersionFunc = pGetDemoVersionFunc; + g_pGh3x2xGetBootloaderVersionFunc = pGetBootloaderVersionFunc; + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); +} + +static void GH3X2X_UprotocolHandleGetOpenedFuncCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_GET_MAX_LEN_RESP_VAL_INDEX] = g_uchPacketMaxLenSupport; + + GU32 unFuncModeOpened = GH3X2X_GetFuncModeOpened(); + GU8 uchPayload[5]; + uchPayload[0] = 0; + uchPayload[1] = GH3X2X_GET_BYTE3_FROM_DWORD(unFuncModeOpened); + uchPayload[2] = GH3X2X_GET_BYTE2_FROM_DWORD(unFuncModeOpened); + uchPayload[3] = GH3X2X_GET_BYTE1_FROM_DWORD(unFuncModeOpened); + uchPayload[4] = GH3X2X_GET_BYTE0_FROM_DWORD(unFuncModeOpened); + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + uchPayload, 5)); +} + +extern void GH3X2X_AlgoVersion(GU8 uchFunctionID, GCHAR version[120]); +/** + * @fn static void GH3X2X_UprotocolHandleGetVerCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle get version cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +void GH3X2X_GetVersion(GU8 uchGetVersionType, GCHAR pszVersionString[150]) +{ + //GCHAR *pszVersionString = GH3X2X_PTR_NULL; + GH3X2X_Memcpy(pszVersionString, UPROTOCOL_GET_VER_DEFAULT_VER_STRING, GH3X2X_Strlen((const GCHAR *)UPROTOCOL_GET_VER_DEFAULT_VER_STRING) + 1); + switch (uchGetVersionType) + { + case UPROTOCOL_GET_VER_TYPE_FW_VER: + if (g_pGh3x2xGetFirmwareVersionFunc != GH3X2X_PTR_NULL) + { + GH3X2X_Memcpy(pszVersionString, g_pGh3x2xGetFirmwareVersionFunc(), GH3X2X_Strlen((const GCHAR *)g_pGh3x2xGetFirmwareVersionFunc()) + 1); + } + break; + case UPROTOCOL_GET_VER_TYPE_DEMO_VER: + if (g_pGh3x2xGetDemoVersionFunc != GH3X2X_PTR_NULL) + { + GH3X2X_Memcpy(pszVersionString, g_pGh3x2xGetDemoVersionFunc(), GH3X2X_Strlen((const GCHAR *)g_pGh3x2xGetDemoVersionFunc()) + 1); + } + break; + case UPROTOCOL_GET_VER_TYPE_BOOTLOADER_VER: + if (g_pGh3x2xGetBootloaderVersionFunc != GH3X2X_PTR_NULL) + { + GH3X2X_Memcpy(pszVersionString, g_pGh3x2xGetBootloaderVersionFunc(), GH3X2X_Strlen((const GCHAR *)g_pGh3x2xGetBootloaderVersionFunc()) + 1); + } + break; + case UPROTOCOL_GET_VER_TYPE_FUNC_SUPPORT: + break; + case UPROTOCOL_GET_VER_TYPE_CHIP_VER: + GH3X2X_Memcpy(pszVersionString, GH3X2X_GetChipVersion(), GH3X2X_Strlen((const GCHAR *)GH3X2X_GetChipVersion()) + 1); + break; + case UPROTOCOL_GET_VER_TYPE_PROTOCOL_VER: + GH3X2X_Memcpy(pszVersionString, GH3X2X_GetProtocolVersion(), GH3X2X_Strlen((const GCHAR *)GH3X2X_GetProtocolVersion()) + 1); + break; + case UPROTOCOL_GET_VER_TYPE_VIRTUAL_REG_VER: + GH3X2X_Memcpy(pszVersionString, GH3X2X_GetVirtualRegVersion(), GH3X2X_Strlen((const GCHAR *)GH3X2X_GetVirtualRegVersion()) + 1); + break; + case UPROTOCOL_GET_VER_TYPE_DRV_VER: + GH3X2X_Memcpy(pszVersionString, GH3X2X_GetDriverLibVersion(), GH3X2X_Strlen((const GCHAR *)GH3X2X_GetDriverLibVersion()) + 1); + break; + default: + #if __GOODIX_ALGO_CALL_MODE__ + if (uchGetVersionType >= UPROTOCOL_GET_VER_TYPE_ALGO_VER && uchGetVersionType <= UPROTOCOL_GET_VER_TYPE_ALGO_VER_END) + { + GU32 unFunctionOffset = (GU32)(uchGetVersionType - UPROTOCOL_GET_VER_TYPE_ALGO_VER); + GCHAR uchVersion[120] = {0}; + GH3X2X_AlgoVersion(unFunctionOffset, uchVersion); + GU32 len = GH3X2X_Strlen((const GCHAR *)uchVersion) + 1; + GH3X2X_Memcpy(pszVersionString, uchVersion, len); + } + #endif + break; + } +} + +static void GH3X2X_UprotocolHandleGetVerCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + GU8 uchGetVersionType = g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_GET_VER_TYPE_INDEX]; + GCHAR pszVersionString[150] = {0}; + GU8 uchVersionStringLen = 0; + if (g_uchPacketPayloadLen == 0) + { + uchGetVersionType = UPROTOCOL_GET_VER_TYPE_FW_VER; // fixed to get firmware version + } + GH3X2X_GetVersion(uchGetVersionType, (GCHAR*)pszVersionString); + uchVersionStringLen = (GU8)GH3X2X_Strlen(pszVersionString); + if (uchVersionStringLen > (GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport) \ + - UPROTOCOL_GET_VER_STRING_INDEX)) + { + uchVersionStringLen = GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport) \ + - UPROTOCOL_GET_VER_STRING_INDEX; // fixed max len + } + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_GET_VER_TYPE_INDEX] = uchGetVersionType; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_GET_VER_STRING_LEN_INDEX] = uchVersionStringLen; + GH3X2X_Memcpy((GCHAR *)&g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_GET_VER_STRING_INDEX], + pszVersionString, uchVersionStringLen); + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_GET_VER_STRING_INDEX + uchVersionStringLen)); +} + +/** + * @fn static void GH3X2X_UprotocolHandleFifoThrConfig(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle fifo thr config cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleFifoThrConfig(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + if (g_uchPacketPayloadLen == GH3X2X_REG_ADDR_SIZE) + { + GH3X2X_CHIP_WAKEUP_NORET(); + GH3X2X_FifoWatermarkThrConfig(GH3X2X_MAKEUP_WORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FIFO_THR_CFG_H_INDEX], + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FIFO_THR_CFG_L_INDEX])); + GH3X2X_CHIP_SLEEP_NORET(); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FIFO_THR_CFG_RESP_STATUS_INDEX] = UPROTOCOL_FIFO_THR_CFG_RESP_CFG_SUCCESS; + } + else + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FIFO_THR_CFG_RESP_STATUS_INDEX] = UPROTOCOL_FIFO_THR_CFG_RESP_CFG_FAIL; + } + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_FIFO_THR_CFG_RESP_LEN)); +} + +/** + * @fn static void GH3X2X_UprotocolHandleChipCtrl(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle chip ctrl cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleChipCtrl(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + if (g_uchPacketPayloadLen == 1) + { + GU8 uchCtrlType = g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_VAL_INDEX]; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX] = UPROTOCOL_CHIP_CTRL_RESP_NULL; + switch (uchCtrlType) + { + case UPROTOCOL_CHIP_CTRL_TYPE_HARD_RESET: + g_uchResetFromProtocolFlag = 1; + if (GH3X2X_HardReset() == GH3X2X_RET_OK) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX] = UPROTOCOL_CHIP_CTRL_RESP_CFG_SUCCESS; + } + break; + + case UPROTOCOL_CHIP_CTRL_TYPE_SOFT_RESET: + g_uchResetFromProtocolFlag = 1; + if (GH3X2X_SoftReset() == GH3X2X_RET_OK) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX] = UPROTOCOL_CHIP_CTRL_RESP_CFG_SUCCESS; + } + break; + +#if (GH3X2X_UPROTOCOL_CHIP_CTRL_CMD_WAKEUP_SLEEP_SUP) + case UPROTOCOL_CHIP_CTRL_TYPE_WAKEUP: + if (GH3X2X_ExitLowPowerMode() == GH3X2X_RET_OK) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX] = UPROTOCOL_CHIP_CTRL_RESP_CFG_SUCCESS; + } + break; + + case UPROTOCOL_CHIP_CTRL_TYPE_SLEEP: + if (GH3X2X_EnterLowPowerMode() == GH3X2X_RET_OK) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX] = UPROTOCOL_CHIP_CTRL_RESP_CFG_SUCCESS; + } + break; +#endif + + default: + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX] = UPROTOCOL_CHIP_CTRL_RESP_CFG_FAIL; + break; + } // end of switch (uchCtrlType) + } // end of if (g_uchPacketPayloadLen == 1) + else + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX] = UPROTOCOL_CHIP_CTRL_RESP_CFG_FAIL; + } + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_CHIP_CTRL_RESP_LEN)); +} + +/** + * @fn static void GH3X2X_UprotocolHandleGetSupprtLenCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle get max len support cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleGetSupprtLenCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_GET_MAX_LEN_RESP_VAL_INDEX] = g_uchPacketMaxLenSupport; + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_GET_MAX_LEN_RESP_LEN)); +} + +/** + * @fn static void GH3X2X_UprotocolHandleSwFunctionCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle switch slot and function cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static EMUprotocolParseCmdType GH3X2X_UprotocolHandleSwFunctionCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + EMUprotocolParseCmdType emUprotocolCmdType = UPROTOCOL_CMD_IGNORE; + + g_unTargetFuncMode = GH3X2X_MAKEUP_DWORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_SW_FUNC_FUNC_INDEX + 3], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_SW_FUNC_FUNC_INDEX + 2], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_SW_FUNC_FUNC_INDEX + 1], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_SW_FUNC_FUNC_INDEX]); + + if (g_unAllFuncMode == (g_unTargetFuncMode | g_unAllFuncMode)) + { + if (UPROTOCOL_START_SAMPLING == g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_SW_FUNC_ONOFF_INDEX]) + { + g_unFuncModeOpened |= g_unTargetFuncMode; + emUprotocolCmdType = UPROTOCOL_CMD_START; + } + else + { + g_unFuncModeOpened &= (~g_unTargetFuncMode); + emUprotocolCmdType = UPROTOCOL_CMD_STOP; + } + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_SW_FUNC_RESP_INDEX] = UPROTOCOL_SW_FUNC_SUCCESS; + } + else + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_SW_FUNC_RESP_INDEX] = UPROTOCOL_SW_FUNC_FAIL; + } + + GH3X2X_DEBUG_LOG_PARAM("[%s]:g_unTargetFuncMode = 0x%08x\r\n", __FUNCTION__, g_unTargetFuncMode); + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_SW_FUNC_RESP_LEN)); + return emUprotocolCmdType; +} + +/** + * @fn static void GH3X2X_UprotocolHandleLoadRegListCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle load reg list cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleLoadRegListCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + GU8 uchReglistCnt = g_uchPacketPayloadLen / UPROTOCOL_LOAD_REG_LIST_SIZEOF; + STGh3x2xReg *pstReglist = (STGh3x2xReg *)g_pstGh3x2xProtocolData->puchPacketPayloadArr; + GH3X2X_SwapLittleBigEndianData(g_pstGh3x2xProtocolData->puchPacketPayloadArr, g_uchPacketPayloadLen); + GH3X2X_CHIP_WAKEUP_PROTOCOL(); + if (GH3X2X_LoadNewRegConfigArr(pstReglist, uchReglistCnt, 0) == GH3X2X_RET_OK) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_LOAD_REG_LIST_RESP_STATUS_INDEX] = \ + UPROTOCOL_LOAD_REG_LIST_RESP_CFG_SUCCESS; + } + else + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_LOAD_REG_LIST_RESP_STATUS_INDEX] = UPROTOCOL_LOAD_REG_LIST_RESP_CFG_FAIL; + } + GH3X2X_CHIP_SLEEP_PROTOCOL(); + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_LOAD_REG_LIST_RESP_LEN)); +} + +/** + * @fn static void GH3X2X_UprotocolHandleDebugStatusCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle debug status cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleDebugStatusCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + GU8 uchDebugType = g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_TYPE_INDEX]; + GU8 uchBytesLen = UPROTOCOL_DEBUG_STATUS_RESP_BYTES_8; + GH3X2X_Memset(&g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_BYTES_INDEX], 0, + UPROTOCOL_DEBUG_STATUS_RESP_LEN - 1); + switch (uchDebugType) + { + case UPROTOCOL_DEBUG_STATUS_READ_INT_PIN: + READ_PIN_STATUS_CALL(g_pGh3x2xReadIntPinStatusFunc, + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_DATA_INDEX]); + break; + case UPROTOCOL_DEBUG_STATUS_READ_RST_PIN: + READ_PIN_STATUS_CALL(g_pGh3x2xReadResetPinStatusFunc, + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_DATA_INDEX]); + break; + case UPROTOCOL_DEBUG_STATUS_READ_SPCS_PIN: + READ_PIN_STATUS_CALL(g_pGh3x2xReadSpcsPinStatusFunc, + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_DATA_INDEX]); + break; + case UPROTOCOL_DEBUG_STATUS_READ_SPDO_PIN: + READ_PIN_STATUS_CALL(g_pGh3x2xReadSpdoPinStatusFunc, + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_DATA_INDEX]); + break; + case UPROTOCOL_DEBUG_STATUS_COMM_CONFIRM: + GH3X2X_CHIP_WAKEUP_NORET(); + if (GH3X2X_CommunicateConfirm() == GH3X2X_RET_OK) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_DATA_INDEX] = 0x01; + } + GH3X2X_CHIP_SLEEP_NORET(); + break; + + default: // include UPROTOCOL_DEBUG_STATUS_READ_WORK_STATUS + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_DATA_INDEX] = g_uchGh3x2xStatus; + break; + } // end of switch (uchDebugType) + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_DEBUG_STATUS_RESP_BYTES_INDEX] = uchBytesLen; + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_DEBUG_STATUS_RESP_LEN)); +} + +/** + * @fn static EMUprotocolParseCmdType GH3X2X_UprotocolHandleStartCtrlCmd(GU8 *puchRespondBuffer, + * GU16 *pusRespondLen) + * + * @brief handle start ctrl cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return @ref EMUprotocolParseCmdType + */ +static EMUprotocolParseCmdType GH3X2X_UprotocolHandleStartCtrlCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + EMUprotocolParseCmdType emUprotocolCmdType = UPROTOCOL_CMD_IGNORE; + g_unTargetFuncMode = GH3X2X_MAKEUP_DWORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_START_CTRL_FUNCTION_INDEX + 3], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_START_CTRL_FUNCTION_INDEX + 2], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_START_CTRL_FUNCTION_INDEX + 1], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_START_CTRL_FUNCTION_INDEX]); + + if (g_unAllFuncMode == (g_unTargetFuncMode | g_unAllFuncMode)) + { + if (UPROTOCOL_START_SAMPLING == g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_START_CTRL_INDEX]) + { + g_unFuncModeOpened |= g_unTargetFuncMode; + emUprotocolCmdType = UPROTOCOL_CMD_START; + } + else + { + g_unFuncModeOpened &= (~g_unTargetFuncMode); + emUprotocolCmdType = UPROTOCOL_CMD_STOP; + } + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_START_CTRL_RESP_INDEX] = UPROTOCOL_START_CTRL_SUCCESS; + } + else + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_START_CTRL_RESP_INDEX] = UPROTOCOL_START_CTRL_FAIL; + } + + GH3X2X_DEBUG_LOG_PARAM("[%s]:g_unTargetFuncMode = 0x%08x, emUprotocolCmdType = %d\r\n", __FUNCTION__, g_unTargetFuncMode, emUprotocolCmdType); + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_START_CTRL_RESP_LEN)); + return emUprotocolCmdType; +} + +/** + * @fn static EMUprotocolParseCmdType GH3X2X_UprotocolHandleWorkModeCmd(GU8 *puchRespondBuffer, + * GU16 *pusRespondLen) + * + * @brief handle work mode cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return @ref EMUprotocolParseCmdType + */ +static EMUprotocolParseCmdType GH3X2X_UprotocolHandleWorkModeCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + EMUprotocolParseCmdType emUprotocolCmdType = UPROTOCOL_CMD_IGNORE; + + emUprotocolCmdType = (EMUprotocolParseCmdType)(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_WORK_MODE_INDEX] + \ + UPROTOCOL_CMD_EVK_MODE); + + g_unAllFuncMode = GH3X2X_MAKEUP_DWORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FUNC_MODE_INDEX + 3], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FUNC_MODE_INDEX + 2], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FUNC_MODE_INDEX + 1], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_FUNC_MODE_INDEX]); + + GH3X2X_DEBUG_LOG_PARAM("[%s]:work mode = %d, function_enable = 0x%08x\r\n", __FUNCTION__, g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_WORK_MODE_INDEX], (int)g_unAllFuncMode); + + g_unFuncModeOpened = 0; + g_unTargetFuncMode = 0; + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_WORK_MODE_RESP_INDEX] = UPROTOCOL_WORK_MODE_SET_SUCCESS; + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_WORK_MODE_RESP_LEN)); + + return emUprotocolCmdType; +} + +/** + * @fn static void GH3X2X_UprotocolHandleReportEventSetCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle event report set cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleReportEventSetCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + g_usGh3x2xEventNeedReport = GH3X2X_MAKEUP_WORD(g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REPORT_EVENT_SET_INDEX], \ + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REPORT_EVENT_SET_INDEX + 1]); + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REPORT_EVENT_SET_RESP_INDEX] = UPROTOCOL_REPORT_EVENT_SET_SUCCESS; + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_REPORT_EVENT_SET_RESP_LEN)); +} + +/** + * @fn static void GH3X2X_UprotocolPackageTestCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle test package + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolPackageTestCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + GU8 uchPackageLen = g_pstGh3x2xProtocolData->puchPacketPayloadArr[0]; + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, uchPackageLen)); +} + +/** + * @fn static void GH3X2X_UprotocolEcgClassificationCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle test package + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +extern GU8 GH3x2xEcgAlgoClassification(void); +static void GH3X2X_UprotocolEcgClassificationCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + //if (g_pstGh3x2xProtocolData->puchPacketPayloadArr[0] == 1) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CONN_ECG_CLASSIFICATION_INDEX] = GH3x2xEcgAlgoClassification(); + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_CONN_ECG_CLASSIFICATION_LEN)); + } + //else if (puchRespondBuffer[0] == 2) + { + + } +} +static void GH3X2X_UprotocolEcgCascadeCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + GU8 uchOpCmd = g_pstGh3x2xProtocolData->puchPacketPayloadArr[0]; + switch (uchOpCmd) + { + //op0x01: set ecg cascade en; 1: enable, 0 :disable + case 0x01: + //GH3X2X_CascadeSetEcgEnFlag(g_pstGh3x2xProtocolData->puchPacketPayloadArr[1]); + GH3X2X_DEBUG_LOG_PARAM("pc set g_uchEcgCascadeEn:%d\r\n",GH3X2X_CascadeGetEcgEnFlag()); + if(g_pstGh3x2xProtocolData->puchPacketPayloadArr[1]) + { + Gh3x2xEnterCascadeMode(); + } + else + { + Gh3x2xExitCascadeMode(); + } + break; + case 0x02: + GH3X2X_CascadeSetLogicMasterChip(0); //chip0 + break; + case 0x03: + GH3X2X_CascadeSetLogicMasterChip(1); //chip1 + break; + default: + break; + } + + /* respond packet format */ + //SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer,g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_CONN_ECG_CLASSIFICATION_LEN)); +} + +/** + * @fn static void GH3X2X_UprotocolFpbpDataReceiveCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle test package + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +void GH3X2X_UprotocolFpbpDataReceiveCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + //GH3x2xBpAlgoInitSetting(g_pstGh3x2xProtocolData->puchPacketPayloadArr); + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_REPORT_EVENT_SET_RESP_INDEX] = UPROTOCOL_REPORT_EVENT_SET_SUCCESS; + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_WORK_MODE_RESP_LEN)); +} + + + +/** + * @fn static EMUprotocolParseCmdType GH3X2X_UprotocolHandleEventReportAckCmd(GU8 *puchRespondBuffer, + * GU16 *pusRespondLen) + * + * @brief handle event report cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static EMUprotocolParseCmdType GH3X2X_UprotocolHandleEventReportAckCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + /* + EMUprotocolParseCmdType emUprotocolCmdType = UPROTOCOL_CMD_IGNORE; + + if (g_uchEventReportIdReceive != g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_ACK_INDEX]) + { + if ((GU8)(g_uchEventReportId - 0x01) == g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_ACK_INDEX]) + { + emUprotocolCmdType = UPROTOCOL_CMD_IRQ_STATUS_REPORT_ACK; + g_uchEventReportIdReceive = g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_ACK_INDEX]; + } + + puchRespondBuffer[0] = g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_ACK_INDEX]; + puchRespondBuffer[1] = (GU8)(g_uchEventReportId - 0x01); + } + */ + if(Gh3x2xGetProtocolEventReportId() == g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_ACK_INDEX]) + { + Gh3x2xSetProtocolEventAck(); + } + SET_VAL_VIA_PTR(pusRespondLen, 0); + return UPROTOCOL_CMD_IGNORE; +} + + + +extern void Gh3x2xSetProtocolEventAck(void); +extern GU8 Gh3x2xGetProtocolEventReportId(void); + + +/** + * @fn static void GH3X2X_UprotocolHandleChipSetConnStaCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle get chipset connect status cmd + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return None + */ +static void GH3X2X_UprotocolHandleChipSetConnStaCmd(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + GU8 uchRet = UPROTOCOL_CONN_STA_FAIL; + + GH3X2X_CHIP_WAKEUP_NORET(); + if (GH3X2X_RET_OK == GH3X2X_CommunicateConfirm()) + { + uchRet = UPROTOCOL_CONN_STA_SUCCESS; + } + GH3X2X_CHIP_SLEEP_NORET(); + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CONN_STA_RESP_INDEX] = uchRet; + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_CONN_STA_RESP_LEN)); +} + +/** + * @fn EMUprotocolParseCmdType GH3X2X_UprotocolCmdHandler(GU8 *puchRespondBuffer, GU16 *pusRespondLen) + * + * @brief handle all cmds + * + * @attention None + * + * @param[in] None + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * + * @return @ref EMUprotocolParseCmdType + */ +EMUprotocolParseCmdType GH3X2X_UprotocolCmdHandler(GU8 *puchRespondBuffer, GU16 *pusRespondLen) +{ + EMUprotocolParseCmdType emUprotocolCmdType = UPROTOCOL_CMD_IGNORE; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + switch (g_uchPacketCmd) + { + case GH3X2X_UPROTOCOL_CMD_REG_RW: + GH3X2X_UprotocolHandleRegRwCmd(puchRespondBuffer, pusRespondLen); + break; + + case GH3X2X_UPROTOCOL_CMD_GET_VER: + GH3X2X_UprotocolHandleGetVerCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_GET_OPENED_FUNC: + GH3X2X_UprotocolHandleGetOpenedFuncCmd(puchRespondBuffer, pusRespondLen); + break; + // case GH3X2X_UPROTOCOL_CMD_LOAD_CONFIG: + // break; + case GH3X2X_UPROTOCOL_CMD_START_CTRL: + emUprotocolCmdType = GH3X2X_UprotocolHandleStartCtrlCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_WORK_MODE: + emUprotocolCmdType = GH3X2X_UprotocolHandleWorkModeCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_REPORT_EVENT_SET: + GH3X2X_UprotocolHandleReportEventSetCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_GET_CHIPSET_CONN_STA: + GH3X2X_UprotocolHandleChipSetConnStaCmd(puchRespondBuffer, pusRespondLen); + break; +#if (GH3X2X_UPROTOCOL_FIFO_THR_CFG_CMD_SUP) + case GH3X2X_UPROTOCOL_CMD_FIFO_THR_CONFIG: + GH3X2X_UprotocolHandleFifoThrConfig(puchRespondBuffer, pusRespondLen); + break; +#endif + + // case GH3X2X_UPROTOCOL_CMD_FUNC_MAP: + // break; + case GH3X2X_UPROTOCOL_CMD_CHIP_EVENT_REPORT: + emUprotocolCmdType = GH3X2X_UprotocolHandleEventReportAckCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_CHIP_CTRL: + GH3X2X_UprotocolHandleChipCtrl(puchRespondBuffer, pusRespondLen); + break; + + case GH3X2X_UPROTOCOL_CMD_GET_MAX_LEN: + GH3X2X_UprotocolHandleGetSupprtLenCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_SWITCH_SLOT_FUNC: + emUprotocolCmdType = GH3X2X_UprotocolHandleSwFunctionCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_LOAD_REG_LIST: + GH3X2X_UprotocolHandleLoadRegListCmd(puchRespondBuffer, pusRespondLen); + break; + + case GH3X2X_UPROTOCOL_CMD_DEBUG_STATUS: + GH3X2X_UprotocolHandleDebugStatusCmd(puchRespondBuffer, pusRespondLen); + break; + + case GH3X2X_UPROTOCOL_CMD_PACKAGE_TEST: + GH3X2X_UprotocolPackageTestCmd(puchRespondBuffer, pusRespondLen); + break; + + case GH3X2X_UPROTOCOL_CMD_ECG_CLASSIFICATION: + GH3X2X_UprotocolEcgClassificationCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_SET_ECG_CASCADE: + GH3X2X_UprotocolEcgCascadeCmd(puchRespondBuffer, pusRespondLen); + break; + case GH3X2X_UPROTOCOL_CMD_BP_DATA_TRANS: + GH3X2X_UprotocolFpbpDataReceiveCmd(puchRespondBuffer, pusRespondLen); + break; + + default: + GH3X2X_DEBUG_LOG_PARAM("unsupported cmd error!\r\n"); + + /* respond packet format */ + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(g_uchPacketCmd, puchRespondBuffer, + g_pstGh3x2xProtocolData->puchPacketPayloadArr, 0)); + break; + } // end of switch (g_uchPacketCmd) + return emUprotocolCmdType; +} + +/** + * @fn EMUprotocolParseCmdType GH3X2X_UprotocolParseHandler(GU8 *puchRespondBuffer, GU16 *pusRespondLen, + * GU8 *puchRecvDataBuffer, GU16 usRecvLen) + * + * @brief universal protocol parse handler, parse protocol receive data + * + * @attention None + * + * @param[out] puchRespondBuffer pointer to respond buffer + * @param[out] pusRespondLen pointer to respond length + * @param[in] puchRecvDataBuffer pointer to receive data buffer + * @param[in] usRecvLen receive data len + * + * @return @ref EMUprotocolParseCmdType + */ +EMUprotocolParseCmdType GH3X2X_UprotocolParseHandler(GU8 *puchRespondBuffer, GU16 *pusRespondLen, + GU8 *puchRecvDataBuffer, GU16 usRecvLen) +{ + EMUprotocolParseCmdType emUprotocolCmdType = UPROTOCOL_CMD_IGNORE; + GU16 usParseIndex = 0; + GU16 usHasParseLenOfBuffer = 0; + GU16 usRespondIndex = 0; + GU16 usCmdRespondLen = 0; + + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + while (usParseIndex < usRecvLen) + { + if (GH3X2X_UprotocolParseBuffer(&usHasParseLenOfBuffer, &puchRecvDataBuffer[usParseIndex], + usRecvLen - usParseIndex) == GH3X2X_RET_OK) + { + emUprotocolCmdType = GH3X2X_UprotocolCmdHandler(&puchRespondBuffer[usRespondIndex], &usCmdRespondLen); + usRespondIndex += usCmdRespondLen; + } + else + { + if (g_emPacketParseStatus == UPROTOCOL_STATUS_IDLE) + { + GH3X2X_DEBUG_LOG_PARAM("protocol parse buffer error!"); + } + } + usParseIndex += usHasParseLenOfBuffer; + } // end while (usParseIndex < usRecvLen) + + SET_VAL_VIA_PTR(pusRespondLen, usRespondIndex); + + return emUprotocolCmdType; +} + +/** + * @fn GU8 GH3X2X_UprotocolPacketMaxLenConfig(GU8 uchPacketMaxLen) + * + * @brief packet max len support, default len is 243 + * + * @attention uchPacketMaxLen val must at [20, 243] + * + * @param[out] None + * @param[in] uchPacketMaxLen packet max len + * + * @return packet max len after config + */ +GU8 GH3X2X_UprotocolPacketMaxLenConfig(GU8 uchPacketMaxLen) +{ + GH3X2X_DEBUG_LOG_PARAM("%s\r\n", __FUNCTION__); + + if (uchPacketMaxLen < GH3X2X_UPROTOCOL_PACKET_LEN_MIN) + { + g_uchPacketMaxLenSupport = GH3X2X_UPROTOCOL_PACKET_LEN_MIN; + } + else if (uchPacketMaxLen > GH3X2X_UPROTOCOL_PACKET_LEN_MAX) + { + g_uchPacketMaxLenSupport = GH3X2X_UPROTOCOL_PACKET_LEN_MAX; + } + else + { + g_uchPacketMaxLenSupport = uchPacketMaxLen; + } + + return g_uchPacketMaxLenSupport; +} + +/** + * @fn void GH3X2X_FillGsensorData(GU16* pusPayloadIndex, STGsensorRawdata* pstGsAxisValue, + * ) + *d + * @brief fill g sensor data to protocol data + * + * @attention None + * + * @param[in] pstGsAxisValue g sensor data + * @param[out] pusPayloadIndex current index of payload + * + * @return None + */ +#if 0 +void GH3X2X_FillGsensorData(GU16* pusPayloadIndex, STGsensorRawdata* pstGsAxisValue) +{ + //GS16 sGsensorRightShift = (1 << emGsSensitivity); + STGsensorRawdata stGsensorData = *pstGsAxisValue; + + //stGsensorData.sXAxisVal = (GS16)(stGsensorData.sXAxisVal / sGsensorRightShift); + //stGsensorData.sYAxisVal = (GS16)(stGsensorData.sYAxisVal / sGsensorRightShift); + //stGsensorData.sZAxisVal = (GS16)(stGsensorData.sZAxisVal / sGsensorRightShift); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(stGsensorData.sXAxisVal); //gs + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_LOW_BYTE_FROM_WORD(stGsensorData.sXAxisVal); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(stGsensorData.sYAxisVal); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_LOW_BYTE_FROM_WORD(stGsensorData.sYAxisVal); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(stGsensorData.sZAxisVal); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_LOW_BYTE_FROM_WORD(stGsensorData.sZAxisVal); + *pusPayloadIndex += 1; +} +#endif +/** + * @fn void GH3X2X_FillAlgoData(GU16* pusPayloadIndex, GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum) + * + * @brief fill algorithm data to protocol data + * + * @attention None + * + * @param[in] nAlgoCalcResultArr pointer to algorithm result + * @param[in] uchAlgoResNum algorithm data num + * @param[out] pusPayloadIndex current index of payload + * + * @return None + */ +void GH3X2X_FillAlgoData(GU16* pusPayloadIndex, GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum) +{ + GU8 uchAlgoCnt = 0; + GU8 uchResTagData = 0; + uchResTagData = GH3X2X_GET_LEFT_SHIFT_VAL(UPROTOCOL_RESULT_TYPE_BIT_FIELD); + for (uchAlgoCnt = 0; uchAlgoCnt < uchAlgoResNum; uchAlgoCnt++) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_SET_BIT(uchResTagData, uchAlgoCnt); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE0_FROM_DWORD(nAlgoCalcResultArr[uchAlgoCnt]); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE1_FROM_DWORD(nAlgoCalcResultArr[uchAlgoCnt]); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE2_FROM_DWORD(nAlgoCalcResultArr[uchAlgoCnt]); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE3_FROM_DWORD(nAlgoCalcResultArr[uchAlgoCnt]); + *pusPayloadIndex += 1; + } +} + +#if GH3X2X_ELECTRO_RRECER_OBSERVE_EN + + +/** + * @fn void GH3X2X_FillElectrodeWearRevertData(GU16* pusPayloadIndex) + * + * @brief fill electrode wear revert data to protocol data buf + * + * @attention None + * + * @param[in] pusPayloadIndex current index of payload + * @param[out] None + * + * @return None + */ +void GH3X2X_FillElectrodeWearRevertData(GU16* pusPayloadIndex) +{ + GU8 uchTagData = 0; + GU32 unWearRevertCnt = 0; + GH3X2X_VAL_CLEAR_LEFT_BIT(uchTagData, (GU8)UPROTOCOL_RESULT_TYPE_BIT_FIELD); + GH3X2X_VAL_SET_BIT(uchTagData, UPROTOCOL_UPLOAD_FLAG_INDEX3); + unWearRevertCnt = GH3X2X_GetAndClearElectrodeWearRevCnt(); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = uchTagData; + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE0_FROM_DWORD(unWearRevertCnt); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE1_FROM_DWORD(unWearRevertCnt); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE2_FROM_DWORD(unWearRevertCnt); + *pusPayloadIndex += 1; + g_pstGh3x2xProtocolData->puchPacketPayloadArr[*pusPayloadIndex] = GH3X2X_GET_BYTE3_FROM_DWORD(unWearRevertCnt); + *pusPayloadIndex += 1; +} + +#endif + +void GH3x2xSendFunctionInfo(const STGh3x2xFrameInfo * const pstFrameInfo) +{ + if ((*(pstFrameInfo->punFrameCnt)) == 0) + { + GU8 uchFunctionInfoBufferLen = 0; + GU8 *puchUploadBuf = g_pstGh3x2xProtocolData->puchPacketPayloadArr + 4; + GU8 uchFunctionIDForMaster = 0; + + for (int uchOffsetCnt = 0 ; uchOffsetCnt < GH3X2X_FUNC_OFFSET_MAX ; uchOffsetCnt ++) + { + if ((pstFrameInfo->unFunctionID >> uchOffsetCnt) & 0x1) + { + uchFunctionIDForMaster = uchOffsetCnt; + } + } + puchUploadBuf[uchFunctionInfoBufferLen] = uchFunctionIDForMaster; + uchFunctionInfoBufferLen += 1; + + GH3X2X_Memcpy(&puchUploadBuf[uchFunctionInfoBufferLen], pstFrameInfo->pstFunctionInfo, sizeof(STGh3x2xFunctionInfo)); + uchFunctionInfoBufferLen += sizeof(STGh3x2xFunctionInfo); + + GH3X2X_Memcpy(&puchUploadBuf[uchFunctionInfoBufferLen], pstFrameInfo->pchChnlMap, pstFrameInfo->pstFunctionInfo->uchChnlNum * sizeof(GU8)); + uchFunctionInfoBufferLen += pstFrameInfo->pstFunctionInfo->uchChnlNum * sizeof(GU8); + + GU16 usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_FUNCTION_INFO_UPDATE, puchUploadBuf - 4, + puchUploadBuf, uchFunctionInfoBufferLen); + Gh3x2xDemoSendProtocolData(puchUploadBuf, usRespondLen); + } +} + +void Gh2x2xPackPakcageHeader(GU8 *puchNeedContinue, GU8 uchFunctionIDForMaster, GU8 *puchUploadBuf, GU8 *puchTagArray, + GU8 uchGsEnable, GU8 uchAlgoResFlag, GU8 uchAgcEnable, GU8 uchAmbEnable, GU8 uchGsGyroEnable,GU8 uchCapEnable,GU8 uchTempEnable, + GU8 uchZipEnableFlag, GU8 uchOddEvenChangeFlag) +{ + *puchNeedContinue = 0; + g_uchGh3x2xUploadBufUse = 0; + g_uchGh3x2xUploadStatus = GH3X2X_UPLOAD_STATUS_HAVE_STORE_DATA; + + //section DATA_TYPE + puchUploadBuf[UPROTOCOL_FUNCTION_ID_INDEX] = uchFunctionIDForMaster; + g_uchGh3x2xUploadBufUse ++; + puchUploadBuf[UPROTOCOL_RAWDATA_TYPE_INDEX] = \ + GH3X2X_VAL_LEFT_SHIFT(uchGsEnable, UPROTOCOL_GS_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchAlgoResFlag, UPROTOCOL_ALGO_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchAgcEnable, UPROTOCOL_AGC_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchAmbEnable, UPROTOCOL_AMBIANCE_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchGsGyroEnable,UPROTOCOL_GS_GYRO_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchCapEnable,UPROTOCOL_CAP_ENABLE_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchTempEnable,UPROTOCOL_TEMP_ENABLE_ENABLE_FIELD); + + g_uchGh3x2xUploadBufUse ++; + + GU32 unCompeletMask = 0; + for (GU32 unCnt = 0 ; unCnt < 32 ; unCnt ++) + { + if (puchTagArray[unCnt] != 0xFF) + { + unCompeletMask |= (1 << unCnt); + } + } + + //chnl num + puchUploadBuf[UPROTOCOL_RAWDATA_CHNL_NUM] = (unCompeletMask >> 24) & 0xFF; + puchUploadBuf[UPROTOCOL_RAWDATA_CHNL_NUM + 1] = (unCompeletMask >> 16) & 0xFF; + puchUploadBuf[UPROTOCOL_RAWDATA_CHNL_NUM + 2] = (unCompeletMask >> 8) & 0xFF; + puchUploadBuf[UPROTOCOL_RAWDATA_CHNL_NUM + 3] = (unCompeletMask) & 0xFF; + g_uchGh3x2xUploadBufUse += 4; + + //pack type flag + puchUploadBuf[UPROTOCOL_PACKAGE_TYPE_INDEX] = \ + GH3X2X_VAL_LEFT_SHIFT(uchZipEnableFlag, UPROTOCOL_ZIP_ENABLE_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(uchOddEvenChangeFlag, UPROTOCOL_ODDEVEN_FLAG_FIELD) + | GH3X2X_VAL_LEFT_SHIFT(GH3X2X_GetFifoPackageMode(), UPROTOCOL_FUNCTION_MODE_FIELD); + g_uchGh3x2xUploadBufUse ++; + + //section DATA_LEN + puchUploadBuf[UPROTOCOL_RAWDATA_LEN_INDEX] = 0; + g_uchGh3x2xUploadBufUse ++; +} + +#if (__SUPPORT_PROTOCOL_ANALYZE__) +void Gh2x2xUploadDataToMaster(const STGh3x2xFrameInfo * const pstFrameInfo, GU16 usFrameCnt, GU16 usFrameNum, GU8* puchTagArray) +{ + GU8 uchChnlNum; + GU32 unFunctionID; + GU8 uchFunctionIDForMaster = 0xFF; + GU8 uchGsEnable; + GU8 uchGsGyroEnable; + GU8 uchCapEnable; + GU8 uchTempEnable; + GU8 uchAgcEnable; + GU8 uchAmbEnable; + GU8 uchAlgoResFlag; + GU16 uchOneFrameByteNum; + GU8 uchReslutByteNum; + GU8 uchNeedContinue; + GU8 *puchUploadBuf = g_pstGh3x2xProtocolData->puchPacketPayloadArr + 4; + GU16 usRespondLen; + GU8 uchFramePosi; + if(0 == pstFrameInfo) + { + return; + } + unFunctionID = pstFrameInfo->unFunctionID; + uchChnlNum = pstFrameInfo->pstFunctionInfo->uchChnlNum; + uchFramePosi = 0; + if(0 == usFrameCnt) + { + uchFramePosi |= GH3X2X_FRAME_POSI_HEAD; + } + if((usFrameNum - 1) == usFrameCnt) + { + uchFramePosi |= GH3X2X_FRAME_POSI_TAIL; + } + if((GH3X2X_FUNCTION_SOFT_ADT_GREEN | GH3X2X_FUNCTION_SOFT_ADT_IR) & unFunctionID) + { + //return; + } + + //function id transform + for (int uchOffsetCnt = 0 ; uchOffsetCnt < GH3X2X_FUNC_OFFSET_MAX ; uchOffsetCnt ++) + { + if ((unFunctionID >> uchOffsetCnt) & 0x1) + { + uchFunctionIDForMaster = uchOffsetCnt; + } + } + + if(0xFF == uchFunctionIDForMaster) //invalid function id + { + return; + } + uchGsEnable = g_uchGsensorEnable; + uchGsGyroEnable = (g_uchGyroEnable & uchGsEnable); + uchCapEnable = GH3X2X_GetCapEnableFlag(); + uchTempEnable = GH3X2X_GetTempEnableFlag(); + uchAgcEnable = 1; + if(unFunctionID == GH3X2X_FUNC_OFFSET_ECG) + { + uchAgcEnable = 0; + } + uchAmbEnable = 0; + uchAlgoResFlag = 1; + + /******** calculate how many bytes in one frame ******/ + uchOneFrameByteNum = 0; + //section FRAME_ID + uchOneFrameByteNum += 1; + //section GSENSOR_DATA + if(uchGsEnable) + { + uchOneFrameByteNum += 6; + } + if(uchGsEnable && uchGsGyroEnable) + { + uchOneFrameByteNum += 6; + } + + //section Cap and temp + if(uchCapEnable) + { + uchOneFrameByteNum += 12; + } + if(uchTempEnable) + { + uchOneFrameByteNum += 12; + } + + //section RAWDATA + if (g_uchFifoPackageMode) + { + uchOneFrameByteNum ++; + } + else + { + uchOneFrameByteNum += uchChnlNum*4; + } + //section AGC_INFO + if(uchAgcEnable) + { + uchOneFrameByteNum += uchChnlNum*4; + } + //section RESLUT + //result byte num + uchReslutByteNum = 0; + uchOneFrameByteNum += 1; + uchReslutByteNum += 1; + //FLAG 2 + uchOneFrameByteNum += 5; + uchReslutByteNum += 5; + //FLAG 3 (need upload on only first frame) + if(uchFramePosi&GH3X2X_FRAME_POSI_HEAD) + { + uchOneFrameByteNum += 5; + uchReslutByteNum += 5; + } + if (uchAlgoResFlag && 1 == pstFrameInfo->pstAlgoResult->uchUpdateFlag) + { + uchOneFrameByteNum += (5*pstFrameInfo->pstAlgoResult->uchResultNum); + uchReslutByteNum += (5*pstFrameInfo->pstAlgoResult->uchResultNum); + } + + #if GH3X2X_DIVIDE_ZERO_FLAG_UPLODE_EN + //flag4 + uchOneFrameByteNum += 5; + uchReslutByteNum += 5; + #endif + + GH3x2xSendFunctionInfo(pstFrameInfo); //send function info when first frame + + uchNeedContinue = 1; + while(uchNeedContinue) + { + if(GH3X2X_UPLOAD_STATUS_NULL == g_uchGh3x2xUploadStatus) + { + Gh2x2xPackPakcageHeader(&uchNeedContinue, uchFunctionIDForMaster,\ + puchUploadBuf, puchTagArray, uchGsEnable, uchAlgoResFlag,\ + uchAgcEnable, uchAmbEnable, uchGsGyroEnable,uchCapEnable,uchTempEnable, 0, 0); + } + if(GH3X2X_UPLOAD_STATUS_HAVE_STORE_DATA == g_uchGh3x2xUploadStatus) + { + if(((GU16)g_uchGh3x2xUploadBufUse + uchOneFrameByteNum) >= GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport)) //can not store more data + { + //send data + usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_NEW_STRUCT_RAWDATA, puchUploadBuf - 4, + puchUploadBuf, g_uchGh3x2xUploadBufUse); + Gh3x2xDemoSendProtocolData(puchUploadBuf - 4,usRespondLen); + + + g_uchGh3x2xUploadStatus = GH3X2X_UPLOAD_STATUS_NULL; + continue; + } + else + { + uchNeedContinue = 0; + puchUploadBuf[UPROTOCOL_RAWDATA_LEN_INDEX] += uchOneFrameByteNum; + + //section FRAME_ID + puchUploadBuf[g_uchGh3x2xUploadBufUse] = ((*(pstFrameInfo->punFrameCnt))&0x000000FF); + g_uchGh3x2xUploadBufUse ++; + //section GSENSOR_DATA + if(uchGsEnable) + { + GS16 *psGsensorData; + psGsensorData = pstFrameInfo->pusFrameGsensordata; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[0]); //gsx + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[0]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[1]); //gsy + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[1]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[2]); //gsz + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[2]); + g_uchGh3x2xUploadBufUse += 1; + if(uchGsGyroEnable) + { + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[3]); //gyrox + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[3]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[4]); //gyroy + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[4]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[5]); //gyroz + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[5]); + g_uchGh3x2xUploadBufUse += 1; + } + } + //section Cap and Temp + if(uchCapEnable) + { + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[0]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[0]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[0]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[1]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[1]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[1]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[2]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[2]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[2]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[3]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[3]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[3]); + g_uchGh3x2xUploadBufUse += 1; + + } + if(uchTempEnable) + { + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[0]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[0]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[0]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[1]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[1]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[1]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[2]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[2]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[2]); + g_uchGh3x2xUploadBufUse += 1; + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[3]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[3]); + g_uchGh3x2xUploadBufUse += 1; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[3]); + g_uchGh3x2xUploadBufUse += 1; + + } + + + //section RAWDATA + //set flag ,copy rawdata, clear flag + + if (GH3X2X_GetFifoPackageMode() == 1) + { + puchUploadBuf[g_uchGh3x2xUploadBufUse] = g_uchFifoPackageID; + g_uchGh3x2xUploadBufUse ++; + } + else + { + for(GU8 uchChnlCnt = 0; uchChnlCnt < uchChnlNum; uchChnlCnt ++) + { + //led adj flag 0 + if(pstFrameInfo->punFrameFlag[0]&((((GU32)1)) << uchChnlCnt)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 26); + } + // fast recovery + if ((GH3X2X_FUNCTION_ECG == unFunctionID)||(GH3X2X_FUNCTION_PWTT == unFunctionID)) + { + if(0 == uchChnlCnt) + { + if(pstFrameInfo->punFrameFlag[2]&((((GU32)1)) << 0)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 26); + } + } + } + //led adj flag 1 + if(pstFrameInfo->punFrameFlag[1]&((((GU32)1)) << uchChnlCnt)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 25); + } + + puchUploadBuf[g_uchGh3x2xUploadBufUse] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 24)&0x000000FF; + g_uchGh3x2xUploadBufUse ++; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 16)&0x000000FF; + g_uchGh3x2xUploadBufUse ++; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 8)&0x000000FF; + g_uchGh3x2xUploadBufUse ++; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 0)&0x000000FF; + g_uchGh3x2xUploadBufUse ++; + + pstFrameInfo->punFrameRawdata[uchChnlCnt] &= 0x00FFFFFF; + } + } + //section AGC_INFO + if(uchAgcEnable) + { + GH3X2X_Memcpy((GU8*)&(puchUploadBuf[g_uchGh3x2xUploadBufUse]), (GU8*)(pstFrameInfo->punFrameAgcInfo), uchChnlNum*4); + g_uchGh3x2xUploadBufUse += uchChnlNum*4; + } + //section AmbData + if(uchAmbEnable) + { + GH3X2X_Memcpy((GU8*)&(puchUploadBuf[g_uchGh3x2xUploadBufUse]), (GU8*)(pstFrameInfo->punFrameAgcInfo), uchChnlNum*3); + g_uchGh3x2xUploadBufUse += uchChnlNum*3; + } + + //section RESLUT_DATA + + //result byte num + puchUploadBuf[g_uchGh3x2xUploadBufUse] = uchReslutByteNum; + g_uchGh3x2xUploadBufUse ++; + + //flag2 + puchUploadBuf[g_uchGh3x2xUploadBufUse] = 2; + g_uchGh3x2xUploadBufUse ++; + GH3X2X_Memcpy((GU8*)&(puchUploadBuf[g_uchGh3x2xUploadBufUse]), (GU8*)(&(pstFrameInfo->punFrameFlag[2])), 4); + g_uchGh3x2xUploadBufUse += 4; + //flag3 + if(uchFramePosi&GH3X2X_FRAME_POSI_HEAD) + { + puchUploadBuf[g_uchGh3x2xUploadBufUse] = 3; + g_uchGh3x2xUploadBufUse ++; + GH3X2X_Memcpy((GU8*)&(puchUploadBuf[g_uchGh3x2xUploadBufUse]), (GU8*)(&(pstFrameInfo->punFrameFlag[3])), 4); + g_uchGh3x2xUploadBufUse += 4; + } + + #if GH3X2X_DIVIDE_ZERO_FLAG_UPLODE_EN + //flag4 + puchUploadBuf[g_uchGh3x2xUploadBufUse] = 4; + g_uchGh3x2xUploadBufUse ++; + GH3X2X_Memcpy((GU8*)&(puchUploadBuf[g_uchGh3x2xUploadBufUse]), (GU8*)(&(pstFrameInfo->punFrameFlag[4])), 4); + g_uchGh3x2xUploadBufUse += 4; + #endif + + //alg result + if (1 == uchAlgoResFlag) + { + //puchUploadBuf[g_uchGh3x2xUploadBufUse] = 0; + //g_uchGh3x2xUploadBufUse++; + if (1 == pstFrameInfo->pstAlgoResult->uchUpdateFlag) + { + GU8 uchResTagData = GH3X2X_GET_LEFT_SHIFT_VAL(UPROTOCOL_RESULT_TYPE_BIT_FIELD); + GU8 uchResultNumTemp = 0; + for(GU8 uchResultCnt = 0;uchResultCnt < GH3X2X_ALGO_RESULT_MAX_NUM;uchResultCnt++) + { + if ((pstFrameInfo->pstAlgoResult->usResultBit >> uchResultCnt) & 0x1) + { + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_SET_BIT(uchResTagData, uchResultCnt); + g_uchGh3x2xUploadBufUse ++ ; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + g_uchGh3x2xUploadBufUse ++ ; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + g_uchGh3x2xUploadBufUse ++ ; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + g_uchGh3x2xUploadBufUse ++ ; + puchUploadBuf[g_uchGh3x2xUploadBufUse] = GH3X2X_GET_BYTE3_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + g_uchGh3x2xUploadBufUse ++ ; + uchResultNumTemp ++; + if (uchResultNumTemp >= pstFrameInfo->pstAlgoResult->uchResultNum) + { + break; + } + } + } + } + // end of if (1 == uchAlgoResFlag) + } + + //modify uchReslutByteNum + puchUploadBuf[g_uchGh3x2xUploadBufUse - uchReslutByteNum] = uchReslutByteNum - 1; + + if(uchFramePosi&GH3X2X_FRAME_POSI_TAIL) + { + //send data + usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_NEW_STRUCT_RAWDATA, puchUploadBuf - 4, + puchUploadBuf, g_uchGh3x2xUploadBufUse); + Gh3x2xDemoSendProtocolData(puchUploadBuf - 4,usRespondLen); + + g_uchGh3x2xUploadStatus = GH3X2X_UPLOAD_STATUS_NULL; + } + } + } + } +} + + + +#else +void Gh2x2xUploadDataToMaster(const STGh3x2xFrameInfo * const pstFrameInfo, GU16 usFrameCnt, GU16 usFrameNum, GU8* puchTagArray){} +#endif + +/** + * @fn GU32 GH3X2X_GetFuncModeAvailable(void) + * + * @brief Get all function mode available + * + * @attention None + * + * @param[out] None + * @param[in] None + * @return function mode, @ref GH3X2X_NO_FUNCTION ... GH3X2X_FUNCTION_PWTT + */ +GU32 GH3X2X_GetFuncModeAvailable(void) +{ + return g_unAllFuncMode; +} + +/** + * @fn GU32 GH3X2X_GetFuncModeOpened(void) + * + * @brief Get function mode that already opened + * + * @attention None + * + * @param[out] None + * @param[in] None + * @return function mode, @ref GH3X2X_NO_FUNCTION ... GH3X2X_FUNCTION_PWTT + */ +GU32 GH3X2X_GetFuncModeOpened(void) +{ + return g_unFuncModeOpened; +} + +/** + * @fn GU32 GH3X2X_GetTargetFuncMode(void) + * + * @brief Get function mode that will be opened or closed + * + * @attention None + * + * @param[out] None + * @param[in] None + * @return function mode, @ref GH3X2X_NO_FUNCTION ... GH3X2X_FUNCTION_PWTT + */ +GU32 GH3X2X_GetTargetFuncMode(void) +{ + return g_unTargetFuncMode; +} + +/** + * @fn void GH3X2X_ReportIrqStatus(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU16 usIrqStatus) + * + * @brief report irq status of Gh3x2x + * + * @attention none + * + * @param[out] puchRespondBuffer pointer to protocol pkg data. + * @param[out] pusRespondLen pointer to protocol pkg data length + * @param[in] usIrqStatus irq status need report + * @return none + */ +void GH3X2X_ReportIrqStatus(GU8 *puchRespondBuffer, GU16 *pusRespondLen, GU16 usIrqStatus) +{ + GU16 usIrqStatusTmp = usIrqStatus & g_usGh3x2xEventNeedReport; + + if (usIrqStatusTmp != 0) + { + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_INDEX] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(usIrqStatus); + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_INDEX + 1] = GH3X2X_GET_LOW_BYTE_FROM_WORD(usIrqStatus); + + g_pstGh3x2xProtocolData->puchPacketPayloadArr[UPROTOCOL_CHIP_EVENT_REPORT_ID_INDEX] = g_uchEventReportId; + g_uchEventReportId++; + SET_VAL_VIA_PTR(pusRespondLen, GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_CHIP_EVENT_REPORT, + puchRespondBuffer, g_pstGh3x2xProtocolData->puchPacketPayloadArr, UPROTOCOL_CHIP_EVENT_REPORT_LEN)); + } + else + { + SET_VAL_VIA_PTR(pusRespondLen, 0); + } +} + +//__attribute__((weak)) void GH3X2X_PROTOCOL_FRAMID_CLEAN(GU8 uchFunctionID) +void GH3X2X_ProtocolFrameIdClean(GU8 uchFunctionID) +{ + g_pstGh3x2xProtocolData->uchFrameIdArr[uchFunctionID] = 0; +} + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_uprotocol.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_uprotocol.h new file mode 100644 index 000000000..351d16ae5 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_uprotocol.h @@ -0,0 +1,385 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_uprotocol.h + * + * @brief gh3x2x universal protocol define & declaration + * + * @version ref gh3x2x_drv_version.h + * + */ + +#ifndef _GH3X2X_DRV_UPROTOCOL_H_ +#define _GH3X2X_DRV_UPROTOCOL_H_ + + +#include "gh_drv_config.h" +#include "gh_drv.h" + + +/* function ptr typedef */ +typedef GCHAR* (*pfnGetFirmwareVersion)(void); /**< read pin status type */ + + +#define GH3X2X_FRAME_POSI_HEAD (0x01) +#define GH3X2X_FRAME_POSI_TAIL (0x02) +#define GH3X2X_UPLOAD_STATUS_NULL 0 +#define GH3X2X_UPLOAD_STATUS_HAVE_STORE_DATA 1 +#define GH3X2X_UPLOAD_PACKAGE_HEAD_SIZE 8 + +#define GH3X2X_SEND_STATUS_TAIL_MODE 1 +#define GH3X2X_SEND_STATUS_FULL_MODE 2 +#define GH3X2X_SEND_STATUS_SPLIC_PACK_MODE 3 + +/** + * @brief ZipMode Lastdata Temp + */ +typedef struct +{ + GU8 uchFlag; + GS16 sGsensorLastDataArr[GH3X2X_GSENSOR_MAX_SIZE]; + GU8 uchFifoLastRawdataTagArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastRawdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastAgcdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastAmbdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastResult; +} STZipLastDataTemp; + +/* universal protocol packet, but index no use */ +#define GH3X2X_UPROTOCOL_PACKET_FIXED_INDEX (0u) /**< fixed header index */ +#define GH3X2X_UPROTOCOL_PACKET_VER_INDEX (1u) /**< version index */ +#define GH3X2X_UPROTOCOL_PACKET_CMD_INDEX (2u) /**< cmd index */ +#define GH3X2X_UPROTOCOL_PACKET_LEN_INDEX (3u) /**< payload len index */ +#define GH3X2X_UPROTOCOL_PACKET_PAYLOAD_INDEX (4u) /**< payload index */ +#define GH3X2X_UPROTOCOL_PACKET_CRC8_INDEX (4u) /**< crc8 index not equl 4, index = len+4 */ +//#define GH3X2X_UPROTOCOL_PACKET_HEADER_LEN (4u) /**< packet header len */ +//#define GH3X2X_UPROTOCOL_PACKET_TAIL_LEN (1u) /**< packet tail len */ + + + +/// get packet payload len support +#define GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(val) ((val) - GH3X2X_UPROTOCOL_PACKET_HEADER_TAIL_LEN) + + +/* cmd id */ +#define GH3X2X_UPROTOCOL_CMD_NOP (0x00) /**< nop operation */ +#define GH3X2X_UPROTOCOL_CMD_CTRL_ACK (0x01) /**< ctrl ack */ +#define GH3X2X_UPROTOCOL_CMD_GET_STATUS (0x02) /**< get status */ +#define GH3X2X_UPROTOCOL_CMD_REG_RW (0x03) /**< register RW */ +#define GH3X2X_UPROTOCOL_CMD_LOAD_CONFIG (0x04) /**< load config array */ +#define GH3X2X_UPROTOCOL_CMD_PACKAGE_TEST (0x05) /**< package test */ +#define GH3X2X_UPROTOCOL_CMD_READ_OTP_REG (0x07) /**< Read Otp Reg */ +#define GH3X2X_UPROTOCOL_CMD_RAWDATA (0x08) /**< raw data package, only output */ + +#define GH3X2X_UPROTOCOL_CMD_ZIPEVENRAWDATA (0x09) /**< raw data package, only output */ +#define GH3X2X_UPROTOCOL_CMD_ZIPODDRAWDATA (0x0A) /**< raw data package, only output */ +#define GH3X2X_UPROTOCOL_CMD_NEW_STRUCT_RAWDATA (0x0B) /**< raw data package, only output */ + +#define GH3X2X_UPROTOCOL_CMD_START_CTRL (0x0C) /**< start ctrl */ +#define GH3X2X_UPROTOCOL_CMD_WORK_MODE (0x10) /**< work mode */ +#define GH3X2X_UPROTOCOL_CMD_FIFO_THR_CONFIG (0x12) /**< fifo thr config */ +#define GH3X2X_UPROTOCOL_CMD_REPORT_EVENT_SET (0x13) /**< set GH3X2X event need reporting */ +#define GH3X2X_UPROTOCOL_CMD_ECG_CLASSIFICATION (0x14) /**< ecg classification */ +#define GH3X2X_UPROTOCOL_CMD_FUNC_MAP (0x15) /**< function map */ +#define GH3X2X_UPROTOCOL_CMD_CHIP_EVENT_REPORT (0x16) /**< GH3X2X event report */ +#define GH3X2X_UPROTOCOL_CMD_CHIP_CTRL (0x17) /**< chip ctrl */ +#define GH3X2X_UPROTOCOL_CMD_GET_VER (0x19) /**< get ver */ +#define GH3X2X_UPROTOCOL_CMD_GET_CHIPSET_CONN_STA (0x1A) /**< get GH3X2X connect status */ +#define GH3X2X_UPROTOCOL_CMD_SWITCH_SLOT_FUNC (0x1C) /**< switch on or off some function */ +#define GH3X2X_UPROTOCOL_CMD_GET_OPENED_FUNC (0x25) /**< get Opened function */ +#define GH3X2X_UPROTOCOL_CMD_SET_ECG_CASCADE (0x26) /**< get Opened function */ +#define GH3X2X_UPROTOCOL_CMD_HSM_RESULT_UPDATE (0x29) /**< switch on or off some function */ +#define GH3X2X_UPROTOCOL_CMD_RAWDATA_FIFO_UPDATE (0x2A) /**< rawdata fifo update function */ +#define GH3X2X_UPROTOCOL_CMD_BP_DATA_TRANS (0x2B) /**< fpbp data transmit function */ +#define GH3X2X_UPROTOCOL_CMD_FUNCTION_INFO_UPDATE (0x2C) /**< function info transmit function */ +#define GH3X2X_UPROTOCOL_CMD_GET_MAX_LEN (0xA0) /**< get packet max len support */ +#define GH3X2X_UPROTOCOL_CMD_LOAD_REG_LIST (0xA1) /**< get load reg list */ +#define GH3X2X_UPROTOCOL_CMD_DEBUG_STATUS (0xA2) /**< debug status */ + +/* macro of reg rw cmd */ +#define UPROTOCOL_REG_RW_READ_MODE (0x00) /**< read mode */ +#define UPROTOCOL_REG_RW_WRITE_MODE (0x01) /**< write mode */ +#define UPROTOCOL_REG_RW_MODE_INDEX (0u) /**< mode */ +#define UPROTOCOL_REG_RW_CNT_INDEX (1u) /**< count */ +#define UPROTOCOL_REG_RW_ADDR_H_INDEX (2u) /**< addr_h */ +#define UPROTOCOL_REG_RW_ADDR_L_INDEX (3u) /**< addr_l */ +#define UPROTOCOL_REG_RW_DATA_INDEX (4u) /**< data */ +#define UPROTOCOL_REG_RW_HEADER_LENGTH (4u) /**< header len */ + + +/* macro of get version cmd */ +#define UPROTOCOL_GET_VER_TYPE_FW_VER (0x01) /**< get firmware version type */ +#define UPROTOCOL_GET_VER_TYPE_DEMO_VER (0x0A) /**< get algo call demo version type */ +#define UPROTOCOL_GET_VER_TYPE_VIRTUAL_REG_VER (0x0B) /**< get virtual reg version type */ +#define UPROTOCOL_GET_VER_TYPE_BOOTLOADER_VER (0x0C) /**< get BOOTLOADER version type */ +#define UPROTOCOL_GET_VER_TYPE_PROTOCOL_VER (0x0E) /**< get protocol version type */ +#define UPROTOCOL_GET_VER_TYPE_FUNC_SUPPORT (0x0F) /**< get driver func support type */ +#define UPROTOCOL_GET_VER_TYPE_DRV_VER (0x10) /**< get driver version type */ +#define UPROTOCOL_GET_VER_TYPE_CHIP_VER (0x11) /**< get chip version type */ +#define UPROTOCOL_GET_VER_TYPE_ALGO_VER (0x12) /**< get algorithm version type */ +#define UPROTOCOL_GET_VER_TYPE_ALGO_VER_END (0x12 + GH3X2X_FUNC_OFFSET_MAX) /**< get algorithm version type END*/ + +#define UPROTOCOL_GET_VER_TYPE_INDEX (0u) /**< type index */ +#define UPROTOCOL_GET_VER_STRING_LEN_INDEX (1u) /**< version string len index */ +#define UPROTOCOL_GET_VER_STRING_INDEX (2u) /**< version string index */ +#define UPROTOCOL_GET_VER_DEFAULT_VER_STRING "no_ver" /**< default version string */ +#define UPROTOCOL_GET_VER_CACHE_VER_MAX_LEN (64) /**< cache algo ver string, max len */ +#define UPROTOCOL_GET_VER_CACHE_VER_PAYLOAD_INDEX (GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX - \ + UPROTOCOL_GET_VER_CACHE_VER_MAX_LEN) /**< cache index */ + + +/* macro of get max len */ +#define UPROTOCOL_GET_MAX_LEN_RESP_VAL_INDEX (0u) /**< len index */ +#define UPROTOCOL_GET_MAX_LEN_RESP_LEN (1u) /**< respond len */ + + +/* macro of load reg list */ +#define UPROTOCOL_LOAD_REG_LIST_SIZEOF (4u) /**< sizeof reg */ +#define UPROTOCOL_LOAD_REG_LIST_RESP_STATUS_INDEX (0u) /**< respond status inex */ +#define UPROTOCOL_LOAD_REG_LIST_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_LOAD_REG_LIST_RESP_CFG_SUCCESS (0u) /**< config success */ +#define UPROTOCOL_LOAD_REG_LIST_RESP_CFG_FAIL (1u) /**< config fail */ + + +/* macro of fifo thr config */ +#define UPROTOCOL_FIFO_THR_CFG_H_INDEX (0u) /**< config val high byte inex */ +#define UPROTOCOL_FIFO_THR_CFG_L_INDEX (1u) /**< config val low byte inex */ +#define UPROTOCOL_FIFO_THR_CFG_RESP_STATUS_INDEX (0u) /**< respond status inex */ +#define UPROTOCOL_FIFO_THR_CFG_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_FIFO_THR_CFG_RESP_CFG_SUCCESS (0u) /**< config success */ +#define UPROTOCOL_FIFO_THR_CFG_RESP_CFG_FAIL (1u) /**< config fail */ + +/* macro of report event set */ +#define UPROTOCOL_REPORT_EVENT_SET_INDEX (0u) /**< report event set inex */ +#define UPROTOCOL_REPORT_EVENT_SET_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_REPORT_EVENT_SET_RESP_INDEX (0u) /**< report event set respond inex */ +#define UPROTOCOL_REPORT_EVENT_SET_SUCCESS (0u) /**< set success */ +#define UPROTOCOL_REPORT_EVENT_SET_FAIL (1u) /**< set fail */ +#define UPROTOCOL_REPORT_EVENT_ID_INIT (0xFF) /**< set fail */ + +/* macro of chip ctrl */ +#define UPROTOCOL_CHIP_CTRL_VAL_INDEX (0u) /**< ctrl val inex */ +#define UPROTOCOL_CHIP_CTRL_RESP_STATUS_INDEX (0u) /**< respond status inex */ +#define UPROTOCOL_CHIP_CTRL_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_CHIP_CTRL_RESP_CFG_SUCCESS (0u) /**< config success */ +#define UPROTOCOL_CHIP_CTRL_RESP_CFG_FAIL (1u) /**< config fail */ +#define UPROTOCOL_CHIP_CTRL_RESP_NULL (0xFF) /**< function ptr null */ +#define UPROTOCOL_CHIP_CTRL_TYPE_HARD_RESET (0x5A) /**< hard reset type */ +#define UPROTOCOL_CHIP_CTRL_TYPE_SOFT_RESET (0xC2) /**< soft reset type */ +#define UPROTOCOL_CHIP_CTRL_TYPE_WAKEUP (0xC3) /**< wakeup type */ +#define UPROTOCOL_CHIP_CTRL_TYPE_SLEEP (0xC4) /**< sleep type */ + +/* macro of chip event report */ +#define UPROTOCOL_CHIP_EVENT_REPORT_ACK_INDEX (0u) /**< event report ack inex */ +#define UPROTOCOL_CHIP_EVENT_REPORT_INDEX (0u) /**< event report inex */ +#define UPROTOCOL_CHIP_EVENT_REPORT_ID_INDEX (2u) /**< event report id inex */ +#define UPROTOCOL_CHIP_EVENT_REPORT_LEN (3u) /**< event report data length */ + +/* macro of debug status */ +#define UPROTOCOL_DEBUG_STATUS_TYPE_INDEX (0u) /**< type inex */ +#define UPROTOCOL_DEBUG_STATUS_RESP_BYTES_INDEX (1u) /**< respond bytes len inex */ +#define UPROTOCOL_DEBUG_STATUS_RESP_DATA_INDEX (2u) /**< respond data inex */ +#define UPROTOCOL_DEBUG_STATUS_RESP_LEN (6u) /**< respond len */ +#define UPROTOCOL_DEBUG_STATUS_RESP_BYTES_8 (1u) /**< respond bytes len 8 bits */ +#define UPROTOCOL_DEBUG_STATUS_RESP_BYTES_16 (2u) /**< respond bytes len 16 bits */ +#define UPROTOCOL_DEBUG_STATUS_RESP_BYTES_32 (4u) /**< respond bytes len 32 bits */ +#define UPROTOCOL_DEBUG_STATUS_READ_INT_PIN (0x00) /**< read int pin type */ +#define UPROTOCOL_DEBUG_STATUS_READ_RST_PIN (0x01) /**< read reset pin type */ +#define UPROTOCOL_DEBUG_STATUS_READ_SPCS_PIN (0x02) /**< read spcs pin type */ +#define UPROTOCOL_DEBUG_STATUS_READ_SPDO_PIN (0x03) /**< read spdo pin type */ +#define UPROTOCOL_DEBUG_STATUS_COMM_CONFIRM (0x04) /**< communicate confirm type */ +#define UPROTOCOL_DEBUG_STATUS_READ_WORK_STATUS (0x10) /**< read work status type */ + +/* macro of rawdata package*/ +#define UPROTOCOL_FUNCTION_ID_INDEX (0u) /**< function id inex */ +#define UPROTOCOL_RAWDATA_TYPE_INDEX (1u) /**< rawdata type inex */ +#define UPROTOCOL_RAWDATA_CHNL_NUM (2u) /**< rawdata channel num */ +#define UPROTOCOL_PACKAGE_TYPE_INDEX (6u) /**< package type index */ +#define UPROTOCOL_RAWDATA_LEN_INDEX (7u) /**< rawdata len index */ +#define UPROTOCOL_FRAME_DATA_INDEX (2u) /**< frame data inex */ +#define UPROTOCOL_GS_ENABLE_FIELD (0u) /**< g sensor enable field in data type */ +#define UPROTOCOL_ALGO_ENABLE_FIELD (1u) /**< algorithm result enable field in data type */ +#define UPROTOCOL_AGC_ENABLE_FIELD (2u) /**< gain current enable field in data type */ +#define UPROTOCOL_AMBIANCE_ENABLE_FIELD (3u) /**< ambiance enable field in data type */ +#define UPROTOCOL_GS_GYRO_ENABLE_FIELD (4u) /**< GYRO enable field in data type */ +#define UPROTOCOL_CAP_ENABLE_ENABLE_FIELD (5u) /**< CAP enable field in data type */ +#define UPROTOCOL_TEMP_ENABLE_ENABLE_FIELD (6u) /**< TEMP enable field in data type */ +#define UPROTOCOL_ZIP_ENABLE_FIELD (0u) /**< zip enable field in data type */ +#define UPROTOCOL_ODDEVEN_FLAG_FIELD (1u) /**< odd-even flag field in data type */ +#define UPROTOCOL_FUNCTION_MODE_FIELD (2u) /**< function mode field in data type */ +#define UPROTOCOL_SPLIC_PACK_CNT_FIELD (3u) /**< splic pack cnt in data type */ +#define UPROTOCOL_SPLIC_PACK_OVER_FIELD (5u) /**< splic pack over in data type */ +#define UPROTOCOL_NEW_DATA_FIELD (7u) /**< algorithm result enable field in data type */ +#define UPROTOCOL_RESULT_TYPE_BIT_FIELD (7u) /**< result type bit field in protocol data */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX0 (0u) /**< flag index0 that will upload */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX1 (1u) /**< flag index1 that will upload */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX2 (2u) /**< flag index2 that will upload */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX3 (3u) /**< flag index3 that will upload */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX4 (4u) /**< flag index4 that will upload */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX5 (5u) /**< flag index5 that will upload */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX6 (6u) /**< flag index6 that will upload */ +#define UPROTOCOL_UPLOAD_FLAG_INDEX7 (7u) /**< flag index7 that will upload */ + +/* macro of work mode set */ +#define UPROTOCOL_WORK_MODE_INDEX (0u) /**< work mode inex */ +#define UPROTOCOL_FUNC_MODE_INDEX (1u) /**< function mode inex */ +#define UPROTOCOL_WORK_MODE_RESP_INDEX (0u) /**< work mode respond index */ +#define UPROTOCOL_WORK_MODE_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_WORK_MODE_SET_SUCCESS (0u) /**< config success */ +#define UPROTOCOL_WORK_MODE_SET_FAIL (1u) /**< config fail */ + +/* macro of switch slot & function */ +#define UPROTOCOL_SW_FUNC_SLOT_INDEX (0u) /**< slot inex */ +#define UPROTOCOL_SW_FUNC_EXTRA_CMD_INDEX (1u) /**< extra cmd inex */ +#define UPROTOCOL_SW_FUNC_FUNC_INDEX (2u) /**< function inex */ +#define UPROTOCOL_SW_FUNC_ONOFF_INDEX (6u) /**< on or off index */ +#define UPROTOCOL_SW_FUNC_RESP_INDEX (0u) /**< switch function respond index */ +#define UPROTOCOL_SW_FUNC_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_SW_FUNC_SUCCESS (0u) /**< switch function success */ +#define UPROTOCOL_SW_FUNC_FAIL (1u) /**< switch function fail */ + +/* macro of start ctrl set */ +#define UPROTOCOL_START_CTRL_INDEX (0u) /**< start or stop index */ +#define UPROTOCOL_START_CTRL_MODE_INDEX (1u) /**< mode index */ +#define UPROTOCOL_START_CTRL_SLOT_EN_INDEX (2u) /**< slot en index */ +#define UPROTOCOL_START_CTRL_FUNCTION_INDEX (3u) /**< function index */ +#define UPROTOCOL_START_CTRL_RESP_INDEX (0u) /**< chipset connect status respond index */ +#define UPROTOCOL_START_CTRL_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_START_SAMPLING (0u) /**< start sampling */ +#define UPROTOCOL_STOP_SAMPLING (1u) /**< stop sampling */ +#define UPROTOCOL_START_CTRL_SUCCESS (0u) /**< start ctrl success */ +#define UPROTOCOL_START_CTRL_FAIL (1u) /**< start ctrl fail */ + +/* macro of chipset connect status set */ +#define UPROTOCOL_CONN_STA_RESP_INDEX (0u) /**< chipset connect status respond index */ +#define UPROTOCOL_CONN_STA_RESP_LEN (1u) /**< respond len */ +#define UPROTOCOL_CONN_STA_SUCCESS (0u) /**< connect ok*/ +#define UPROTOCOL_CONN_STA_FAIL (1u) /**< connect error */ + +/* macro of ecg classification set */ +#define UPROTOCOL_CONN_ECG_CLASSIFICATION_LEN (1u) /**< respond len */ +#define UPROTOCOL_CONN_ECG_CLASSIFICATION_INDEX (0u) /**< data index */ + +/* macro of GH3X2X_UprotocolEcgCascadeCmd set */ +#define UPROTOCOL_CONN_ECG_CASCADE_LEN (1u) /**< respond len */ +#define UPROTOCOL_CONN_ECG_CASCADE_INDEX (0u) /**< data index */ + +/// universal protocol fixed header +#define GH3X2X_UPROTOCOL_FIXED_HEADER (0xAA) + +/// universal protocol version byte +#define GH3X2X_UPROTOCOL_VERSION (0x11) + +/// chip version string len +#define GH3X2X_CHIP_VER_STR_LEN (24) + +/// crc8 clear val +#define GH3X2X_CRC8_CLEAR_VAL (0xFF) + +/// crc8 val clear +#define GH3X2X_CRC8_VAL_CLEAR(x) do { (x) = GH3X2X_CRC8_CLEAR_VAL; } while (0) + +/// size_t size +#define GH3X2X_UPROTOCOL_SIZE_T (4u) + +/// align num +#define GH3X2X_UPROTOCOL_ALIGN_LEFTSHIFT (30u) + +/// channel map id for user defined @ref EMFunctionID +#define GH3X2X_FUNC_OFFSET_USER_DEF_BASE (10) + +/// number of channel map id +//#define CHANNEL_MAP_ID_NUM (16) + +/// rawdata diff size +#define RAWDATA_DIFF_SIZE (8) + +/// rawdata diff byte size +#define RAWDATA_DIFF_BYTE_SIZE (4) + +/// rawdata diff type even +#define RAWDATA_DIFF_EVEN (2) + +/// rawdata diff type odd +#define RAWDATA_DIFF_ODD (1) + +/* universal protocol parse status */ +typedef enum +{ + UPROTOCOL_STATUS_IDLE = 0, /**< idle */ + UPROTOCOL_STATUS_GOT_FIXED, /**< got fixed header */ + UPROTOCOL_STATUS_GOT_VER, /**< got version */ + UPROTOCOL_STATUS_GOT_CMD, /**< got cmd */ + UPROTOCOL_STATUS_GOT_LEN, /**< got data len */ + UPROTOCOL_STATUS_GOT_PAYLOAD, /**< got pyload data */ + UPROTOCOL_STATUS_GOT_CRC8, /**< got crc8, but never goto this enum */ +} EMUprotocolParseStatus; + +/** + * @fn GU8 GH3X2X_UprotocolPacketFormat(GU8 uchCmd, GU8 *puchPacketBuffer, + * GU8 *puchPayloadData, GU8 uchPayloadDataLen) + * + * @brief universal protocol format packet + * + * @attention None + * + * @param[out] puchPacketBuffer pointer to respond packet buffer + * @param[in] uchCmd cmd id + * @param[in] puchPayloadData pointer to payload buffer + * @param[in] uchPayloadDataLen payload len + * + * @return len after make packet + */ +GU8 GH3X2X_UprotocolPacketFormat(GU8 uchCmd, GU8 *puchPacketBuffer, GU8 *puchPayloadData, GU8 uchPayloadDataLen); + +/** + * @fn void GH3X2X_FillGsensorData(GU16* pusPayloadIndex, STGsensorRawdata* pstGsAxisValue + * y) + * + * @brief fill g sensor data to protocol data + * + * @attention None + * + * @param[in] pstGsAxisValue g sensor data + * @param[in] emGsSensitivity g sensor sensitivity + * @param[out] pusPayloadIndex current index of payload + * + * @return None + */ +//void GH3X2X_FillGsensorData(GU16* pusPayloadIndex, STGsensorRawdata* pstGsAxisValue); + +/** + * @fn void GH3X2X_FillAlgoData(GU16* pusPayloadIndex, GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum) + * + * @brief fill algorithm data to protocol data + * + * @attention None + * + * @param[in] nAlgoCalcResultArr pointer to algorithm result array + * @param[in] uchAlgoResNum algorithm data num + * @param[out] pusPayloadIndex current index of payload + * + * @return None + */ +void GH3X2X_FillAlgoData(GU16* pusPayloadIndex, GS32 nAlgoCalcResultArr[], GU8 uchAlgoResNum); + +/** + * @fn void GH3X2X_FillElectrodeWearRevertData(GU16* pusPayloadIndex) + * + * @brief fill electrode wear revert data to protocol data buf + * + * @attention None + * + * @param[in] pusPayloadIndex current index of payload + * @param[out] None + * + * @return None + */ +void GH3X2X_FillElectrodeWearRevertData(GU16* pusPayloadIndex); + +void GH3X2X_GetVersion(GU8 uchGetVersionType, GCHAR pszVersionString[100]); + + +#endif /* _GH3X2X_DRV_UPROTOCOL_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_zip.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_zip.c new file mode 100644 index 000000000..fe3ffe2ed --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_zip.c @@ -0,0 +1,828 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_zip.c + * + * @brief gh3x2x extension control functions, using function map like evk + * + * @version ref gh3x2x_drv_ziphandle.h + * + */ + +#include +#include "gh_drv_version.h" +#include "gh_drv_common.h" +#include "gh_drv.h" +#include "gh_uprotocol.h" +#include "gh_drv_interface.h" +#include "gh_drv_control.h" +#include "gh_drv_dump.h" +#include "gh_agc.h" +#include "gh_zip.h" +#include "gh_demo_config.h" + +// Zipmode Tempdata +STZipLastDataStruct g_stZipLastData; + +GU32 g_unLastFrameFlag2 = 0; + +// Zip Package Num Even/Odd Flag +extern GU8 g_uchOddEvenChangeFlag; +extern GU8 g_puchGainBgCancelRecord[]; +extern GU16 g_pusDrvCurrentRecord[]; +extern GU8 g_uchPacketMaxLenSupport; +extern GU16 g_usGh3x2xDataIndexInBuf; +extern GF32 g_fGsDataIndexInBuf; +extern GU16 g_usAlgoResIndex; +extern GU32 g_unLastIncompleteMark; +extern GU8 g_uchFifoPackageID; +extern GU8 g_uchFifoPackageMode; +extern void Gh2x2xPackPakcageHeader(GU8 *puchNeedContinue, GU8 uchFunctionIDForMaster, GU8 *puchUploadBuf, GU8 *puchTagArray, + GU8 uchGsEnable, GU8 uchAlgoResFlag, GU8 uchAgcEnable, GU8 uchAmbEnable, GU8 uchGsGyroEnable,GU8 uchCapEnable,GU8 uchTempEnable, + GU8 uchZipEnableFlag, GU8 uchOddEvenChangeFlag); +extern void GH3x2xSendFunctionInfo(const STGh3x2xFrameInfo * const pstFrameInfo); + +/** + * @fn void GH3X2X_GetRawDataDiff(GU32 *punRawData, GU8 *puchRawdataTagTempArr, + GU8 uchChannelMapCnt, GU8 *puchZipDataArr, GU8 *puchZipDataArrSize) +* +* @brief Pack and Generate Zip RawData Data. +* +* @attention None +* +* @param[out] puchZipDataArr Zip Paclage Data. +* @param[out] puchZipDataArrSize Zip Package Size. +* @param[in] punRawData Current Gsensor Data. +* @param[in] puchRawdataTagTempArr Current Gsensor Data. +* @param[in] uchChannelMapCnt Current Gsensor Data. + +* @return None +*/ +void GH3X2X_GetRawDataDiff(GU32 *punRawData, GU8 *puchRawdataTagTempArr, + GU8 uchChannelMapCnt, GU8 *puchZipArr, GU8 *puchZipDataArrSize, + GU8 *uchFifoLastRawdataTagArr, GU32 *unFifoLastRawdataArr) +{ + GU8 uchDiffunittemp; + GS8 chNum; + GU8 uchChnum; + GU32 unChnum; + GU8 uchDifftemp; + GU8 uchDiffarrcnt8bit = 0; + GU8 uchDiffarrcnt4bit = 0; + GU8 uchDataType = 0; + + GU8 puchZipDataArr[255]; + GH3X2X_Memset(puchZipDataArr, 0, 255); + + if (puchRawdataTagTempArr[0] != uchFifoLastRawdataTagArr[0]) + { + uchDiffarrcnt8bit++; + puchZipDataArr[uchDiffarrcnt8bit] = RAWDATA_DIFF_ODD; + GH3X2X_Memcpy(&puchZipDataArr[uchDiffarrcnt8bit+RAWDATA_DIFF_ODD], puchRawdataTagTempArr, uchChannelMapCnt); + uchDiffarrcnt8bit += uchChannelMapCnt; + uchDiffarrcnt4bit += (GU8)(uchChannelMapCnt*RAWDATA_DIFF_EVEN); + } + else + { + uchDiffarrcnt8bit++; + puchZipDataArr[uchDiffarrcnt8bit] = 0; + } + + for (uchChnum = 0 ; uchChnum < uchChannelMapCnt ; uchChnum++) + { + if (punRawData[uchChnum] >= unFifoLastRawdataArr[uchChnum]) + { + unChnum = punRawData[uchChnum] - unFifoLastRawdataArr[uchChnum]; + } + else + { + unChnum = unFifoLastRawdataArr[uchChnum] - punRawData[uchChnum]; + } + + for (chNum = RAWDATA_DIFF_SIZE ; chNum >= 0 ; chNum--) + { + if (unChnum == 0) + { + uchDataType = 0; + break; + } + uchDifftemp = ((GU8)(GH3X2X_GET_FIRST_4BITS((unChnum) >> (chNum*RAWDATA_DIFF_BYTE_SIZE)))); + if (uchDifftemp != 0) + { + uchDataType = chNum * RAWDATA_DIFF_EVEN + GH3X2X_VAL_DIFF_STA(punRawData[uchChnum], \ + unFifoLastRawdataArr[uchChnum]); + break; + } + } + + if (uchDiffarrcnt4bit%RAWDATA_DIFF_EVEN) + { + puchZipDataArr[uchDiffarrcnt8bit] |= uchDataType; + } + + else + { + uchDiffarrcnt8bit++; + puchZipDataArr[uchDiffarrcnt8bit] |= (GU8)(uchDataType << RAWDATA_DIFF_BYTE_SIZE); + } + uchDiffarrcnt4bit++; + + for (chNum = (GU8)(uchDataType/RAWDATA_DIFF_EVEN) ; chNum >= 0 ; chNum--) + { + uchDiffunittemp = (GU8)(GH3X2X_GET_FIRST_4BITS((unChnum) >> (chNum*RAWDATA_DIFF_BYTE_SIZE))); + if (uchDiffarrcnt4bit%RAWDATA_DIFF_EVEN) + { + puchZipDataArr[uchDiffarrcnt8bit] |= uchDiffunittemp; + } + else + { + uchDiffarrcnt8bit++; + puchZipDataArr[uchDiffarrcnt8bit] |= (GU8)(uchDiffunittemp << RAWDATA_DIFF_BYTE_SIZE); + } + uchDiffarrcnt4bit++; + } + }// end of (for uchChnum=0;uchChnum= punZipTempData[uchChnum]) + { + unChnum = punData[uchChnum] - punZipTempData[uchChnum]; + } + else + { + unChnum = punZipTempData[uchChnum] - punData[uchChnum]; + } + + for (chNum = RAWDATA_DIFF_SIZE ; chNum >= 0 ; chNum--) + { + if (unChnum == 0) + { + uchDataType = 0; + break; + } + uchDifftemp = ((GU8)(GH3X2X_GET_FIRST_4BITS((unChnum) >> (chNum*RAWDATA_DIFF_BYTE_SIZE)))); + if (uchDifftemp != 0) + { + uchDataType = chNum * RAWDATA_DIFF_EVEN + GH3X2X_VAL_DIFF_STA(punData[uchChnum], \ + punZipTempData[uchChnum]); + break; + } + } + + if (uchDiffarrcnt4bit%RAWDATA_DIFF_EVEN) + { + puchZipDataArr[uchDiffarrcnt8bit] |= uchDataType; + } + + else + { + uchDiffarrcnt8bit++; + puchZipDataArr[uchDiffarrcnt8bit] |= (GU8)(uchDataType << RAWDATA_DIFF_BYTE_SIZE); + } + uchDiffarrcnt4bit++; + + for (chNum = (GS8)(uchDataType/RAWDATA_DIFF_EVEN) ; chNum >= 0 ; chNum--) + { + uchDiffunittemp = (GU8)(GH3X2X_GET_FIRST_4BITS((unChnum) >> (chNum*RAWDATA_DIFF_BYTE_SIZE))); + if (uchDiffarrcnt4bit%RAWDATA_DIFF_EVEN) + { + puchZipDataArr[uchDiffarrcnt8bit] |= uchDiffunittemp; + } + else + { + uchDiffarrcnt8bit++; + puchZipDataArr[uchDiffarrcnt8bit] |= (GU8)(uchDiffunittemp << RAWDATA_DIFF_BYTE_SIZE); + } + uchDiffarrcnt4bit++; + } + }// end of (for uchChnum=0;uchChnumpunFrameFlag[0]&((((GU32)1)) << uchChnlCnt)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 26); + } + // fast recovery + if ((GH3X2X_FUNCTION_ECG == unFunctionID)||(GH3X2X_FUNCTION_PWTT == unFunctionID)) + { + if(0 == uchChnlCnt) + { + if(pstFrameInfo->punFrameFlag[2]&((((GU32)1)) << 0)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 26); + } + } + } + //led adj flag 1 + if(pstFrameInfo->punFrameFlag[1]&((((GU32)1)) << uchChnlCnt)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 25); + } + + uchFifoLastRawdataTagArr[uchChnlCnt] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 24)&0x000000FF; + unFifoLastRawdataArr[uchChnlCnt] = pstFrameInfo->punFrameRawdata[uchChnlCnt]&0x00FFFFFF; + + pstFrameInfo->punFrameRawdata[uchChnlCnt] &= 0x00FFFFFF; + } +} + +void GH3X2X_ZipFillLastDataBuffer(GU32 *unCurrentData, GU8 uchChnlNum, GU32 *unLastdata) +{ + for(GU8 uchChnlCnt = 0; uchChnlCnt < uchChnlNum; uchChnlCnt ++) + { + unLastdata[uchChnlCnt] = unCurrentData[uchChnlCnt]; + } +} + + +extern GU8 g_uchGh3x2xUploadStatus; +extern GU8 g_uchGh3x2xUploadBufUse; +GU8 g_uchCurrentFunctionID = 0; + +#if (__SUPPORT_PROTOCOL_ANALYZE__) +void Gh2x2xUploadZipDataToMaster(const STGh3x2xFrameInfo * const pstFrameInfo, GU16 usFrameCnt, GU16 usFrameNum, GU8* puchTagArray) +{ + GU8 uchChnlNum; + GU32 unFunctionID; + GU8 uchFunctionIDForMaster = 0xFF; + GU8 uchGsEnable; + GU8 uchCapEnable; + GU8 uchTempEnable; + GU8 uchGsGyroEnable; + GU8 uchAgcEnable; + GU8 uchAmbEnable; + GU8 uchAlgoResFlag; + GU16 uchOneFrameByteNum = 0; + GU8 uchReslutByteNum; + GU8 uchNeedContinue; + GU8 *puchUploadBuf = g_pstGh3x2xProtocolData->puchPacketPayloadArr + 4; + GU8 puchTempFrameDataBuf[2 * (GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX + 8)]; + GU16 usRespondLen; + GU8 uchFramePosi; + GU8 uchEvenFirstFrameFlag = 0; + + GU8 uchZipRawdataArr[GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX] = {0}; + GU8 uchZipRawdataArrSize = 0; + GU8 uchZipAgcdataArr[GH3X2X_UPROTOCOL_PAYLOAD_LEN_MAX] = {0}; + GU8 uchZipAgcdataArrSize = 0; + GU8 uchFifoLastRawdataTagArr[CHANNEL_MAP_ID_NUM] = {0}; + GU32 unFrameRawdataArr[CHANNEL_MAP_ID_NUM] = {0}; + GU32 unAgcdataArr[CHANNEL_MAP_ID_NUM] = {0}; + + GU8 uchFirstFrameLen = 0; + GU8 uchFillLastFrameDataFlag = 0; + + GU8 uchFlag2ChangeFlag = 0; + + if(0 == pstFrameInfo) + { + return; + } + unFunctionID = pstFrameInfo->unFunctionID; + uchChnlNum = pstFrameInfo->pstFunctionInfo->uchChnlNum; + uchFramePosi = 0; + if(0 == usFrameCnt) + { + uchFramePosi |= GH3X2X_FRAME_POSI_HEAD; + } + if((usFrameNum - 1) == usFrameCnt) + { + uchFramePosi |= GH3X2X_FRAME_POSI_TAIL; + } + /* + if(GH3X2X_FUNCTION_SOFT_ADT_IR == unFunctionID) + { + unFunctionID = GH3X2X_FUNCTION_SOFT_ADT_GREEN; //adt ir and adt green store in one csv file + } + */ + + //function id transform + for (int uchOffsetCnt = 0 ; uchOffsetCnt < GH3X2X_FUNC_OFFSET_MAX ; uchOffsetCnt ++) + { + if ((unFunctionID >> uchOffsetCnt) & 0x1) + { + uchFunctionIDForMaster = uchOffsetCnt; + } + } + + + if (g_uchCurrentFunctionID != uchFunctionIDForMaster) + { + g_uchCurrentFunctionID = uchFunctionIDForMaster; + g_uchOddEvenChangeFlag = 1; + } + + if(0xFF == uchFunctionIDForMaster) //invalid function id + { + return; + } + uchGsEnable = g_uchGsensorEnable; + uchGsGyroEnable = (g_uchGyroEnable & uchGsEnable); + uchCapEnable = GH3X2X_GetCapEnableFlag(); + uchTempEnable = GH3X2X_GetTempEnableFlag(); + uchAgcEnable = 1; + if(unFunctionID == GH3X2X_FUNC_OFFSET_ECG) + { + uchAgcEnable = 0; + } + uchAmbEnable = 0; + uchAlgoResFlag = 1; + + + /******** calculate how many bytes in one frame ******/ + //result byte num + uchReslutByteNum = 0; + uchReslutByteNum += 1; + //flag 0 softAGC + uchReslutByteNum += 5; + //FLAG 2 + uchReslutByteNum += 5; + //FLAG 3 (need upload on only first frame) + if(uchFramePosi&GH3X2X_FRAME_POSI_HEAD) + { + uchReslutByteNum += 5; + } + + #if GH3X2X_DIVIDE_ZERO_FLAG_UPLODE_EN + //flag4 + uchReslutByteNum += 5; + #endif + + //section FRAME_ID + uchFirstFrameLen += 2; + uchFirstFrameLen += 1; + //section GSENSOR_DATA + if(uchGsEnable) + { + uchFirstFrameLen += 6; + if(uchGsGyroEnable) + { + uchFirstFrameLen += 6; + } + } + //section Cap and temp + if(uchCapEnable) + { + uchFirstFrameLen += 12; + } + if(uchTempEnable) + { + uchFirstFrameLen += 12; + } + + if (uchAlgoResFlag && 1 == pstFrameInfo->pstAlgoResult->uchUpdateFlag) + { + uchOneFrameByteNum += (5*pstFrameInfo->pstAlgoResult->uchResultNum); + uchReslutByteNum += (5*pstFrameInfo->pstAlgoResult->uchResultNum); + } + + GH3x2xSendFunctionInfo(pstFrameInfo); //send function info when first frame + + uchNeedContinue = 1; + while(uchNeedContinue) + { + if(GH3X2X_UPLOAD_STATUS_NULL == g_uchGh3x2xUploadStatus) + { + Gh2x2xPackPakcageHeader(&uchNeedContinue, uchFunctionIDForMaster,\ + puchUploadBuf, puchTagArray, uchGsEnable, uchAlgoResFlag,\ + uchAgcEnable, uchAmbEnable, uchGsGyroEnable, uchCapEnable,uchTempEnable,1, g_uchOddEvenChangeFlag); + } + + + if(GH3X2X_UPLOAD_STATUS_HAVE_STORE_DATA == g_uchGh3x2xUploadStatus && uchFillLastFrameDataFlag == 0) + { + + uchNeedContinue = 0; + uchOneFrameByteNum = 0; + + //section FRAME_ID + puchTempFrameDataBuf[uchOneFrameByteNum] = ((*(pstFrameInfo->punFrameCnt))&0x000000FF); + + + uchOneFrameByteNum ++; + //section GSENSOR_DATA + if(uchGsEnable) + { + GS16 *psGsensorData; + psGsensorData = pstFrameInfo->pusFrameGsensordata; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[0]); //gsx + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[0]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[1]); //gsy + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[1]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[2]); //gsz + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[2]); + uchOneFrameByteNum += 1; + if(uchGsGyroEnable) + { + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[3]); //gyrox + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[3]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[4]); //gyroy + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[4]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_HIGH_BYTE_FROM_WORD(psGsensorData[5]); //gyroz + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_LOW_BYTE_FROM_WORD(psGsensorData[5]); + uchOneFrameByteNum += 1; + } + } + if(uchCapEnable) + { + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[0]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[0]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[0]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[1]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[1]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[1]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[2]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[2]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[2]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[3]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[3]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameCapdata->unCapData[3]); + uchOneFrameByteNum += 1; + + } + if(uchTempEnable) + { + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[0]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[0]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[0]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[1]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[1]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[1]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[2]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[2]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[2]); + uchOneFrameByteNum += 1; + + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[3]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[3]); + uchOneFrameByteNum += 1; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstFrameTempdata->unTempData[3]); + uchOneFrameByteNum += 1; + + } + //section RAWDATA + //set flag ,copy rawdata, clear flag + + if (GH3X2X_GetFifoPackageMode() == 1) + { + if (g_uchOddEvenChangeFlag && g_uchGh3x2xUploadBufUse <= GH3X2X_UPLOAD_PACKAGE_HEAD_SIZE) + { + uchEvenFirstFrameFlag = 1; + } + puchTempFrameDataBuf[uchOneFrameByteNum] = g_uchFifoPackageID; + uchOneFrameByteNum ++; + } + else + { + if (g_uchOddEvenChangeFlag && g_uchGh3x2xUploadBufUse <= GH3X2X_UPLOAD_PACKAGE_HEAD_SIZE) + { + uchEvenFirstFrameFlag = 1; + for(GU8 uchChnlCnt = 0; uchChnlCnt < uchChnlNum; uchChnlCnt ++) + { + //led adj flag 0 + if(pstFrameInfo->punFrameFlag[0]&((((GU32)1)) << uchChnlCnt)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 26); + } + // fast recovery + if ((GH3X2X_FUNCTION_ECG == unFunctionID)||(GH3X2X_FUNCTION_PWTT == unFunctionID)) + { + if(0 == uchChnlCnt) + { + if(pstFrameInfo->punFrameFlag[2]&((((GU32)1)) << 0)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 26); + } + } + } + //led adj flag 1 + if(pstFrameInfo->punFrameFlag[1]&((((GU32)1)) << uchChnlCnt)) + { + pstFrameInfo->punFrameRawdata[uchChnlCnt] |= ((((GU32)1)) << 25); + } + + puchTempFrameDataBuf[uchOneFrameByteNum] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 24)&0x000000FF; + uchOneFrameByteNum ++; + + puchTempFrameDataBuf[uchOneFrameByteNum] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 16)&0x000000FF; + uchOneFrameByteNum ++; + + puchTempFrameDataBuf[uchOneFrameByteNum] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 8)&0x000000FF; + uchOneFrameByteNum ++; + + puchTempFrameDataBuf[uchOneFrameByteNum] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 0)&0x000000FF; + uchOneFrameByteNum ++; + + g_stZipLastData.uchFifoLastRawdataTagArr[uchFunctionIDForMaster][uchChnlCnt] = (pstFrameInfo->punFrameRawdata[uchChnlCnt] >> 24)&0x000000FF; + g_stZipLastData.unFifoLastRawdataArr[uchChnlCnt] = pstFrameInfo->punFrameRawdata[uchChnlCnt]&0x00FFFFFF; + + pstFrameInfo->punFrameRawdata[uchChnlCnt] &= 0x00FFFFFF; + } + } + else + { + GH3X2X_ZipFillLastRawdataBuffer(pstFrameInfo, unFunctionID, uchChnlNum, uchFifoLastRawdataTagArr, unFrameRawdataArr); + GH3X2X_GetRawDataDiff(unFrameRawdataArr, uchFifoLastRawdataTagArr,\ + uchChnlNum, uchZipRawdataArr, &uchZipRawdataArrSize,\ + g_stZipLastData.uchFifoLastRawdataTagArr[uchFunctionIDForMaster], g_stZipLastData.unFifoLastRawdataArr); + GH3X2X_Memcpy(&puchTempFrameDataBuf[uchOneFrameByteNum], uchZipRawdataArr, uchZipRawdataArrSize); + uchOneFrameByteNum += uchZipRawdataArrSize; + } + } + //section AGC_INFO + if(uchAgcEnable) + { + if (uchEvenFirstFrameFlag) + { + GH3X2X_ZipFillLastDataBuffer(pstFrameInfo->punFrameAgcInfo, uchChnlNum, g_stZipLastData.unFifoLastAgcdataArr); + GH3X2X_Memcpy((GU8*)&(puchTempFrameDataBuf[uchOneFrameByteNum]), (GU8*)(pstFrameInfo->punFrameAgcInfo), uchChnlNum*4); + uchOneFrameByteNum += uchChnlNum*4; + } + else + { + GH3X2X_ZipFillLastDataBuffer(pstFrameInfo->punFrameAgcInfo, uchChnlNum, unAgcdataArr); + GH3X2X_GetDataDiff(unAgcdataArr, uchChnlNum, uchZipAgcdataArr, + &uchZipAgcdataArrSize, g_stZipLastData.unFifoLastAgcdataArr); + GH3X2X_Memcpy(&puchTempFrameDataBuf[uchOneFrameByteNum], uchZipAgcdataArr, uchZipAgcdataArrSize); + uchOneFrameByteNum += uchZipAgcdataArrSize; + } + } + + //section AmbData + if(uchAmbEnable) + { + GH3X2X_Memcpy((GU8*)&(puchUploadBuf[uchOneFrameByteNum]), (GU8*)(pstFrameInfo->punFrameAgcInfo), uchChnlNum*3); + uchOneFrameByteNum += uchChnlNum*3; + } + + //section RESLUT_DATA + //result byte num + //puchTempFrameDataBuf[g_uchGh3x2xUploadBufUse] = 0; + GU8 uchRealReslutByteNum = uchReslutByteNum; + uchOneFrameByteNum ++; + // Soft AGC Flag + if (GH3X2X_FUNCTION_ECG != unFunctionID) + { + puchTempFrameDataBuf[uchOneFrameByteNum] = 0; + uchOneFrameByteNum ++; + #if __SUPPORT_SOFT_AGC_CONFIG__ + pstFrameInfo->punFrameFlag[0] = NewAgcMainChelFlag; + #endif + GH3X2X_Memcpy((GU8*)&(puchTempFrameDataBuf[uchOneFrameByteNum]), (GU8*)(&(pstFrameInfo->punFrameFlag[0])), 4); + uchOneFrameByteNum += 4; + #if __SUPPORT_SOFT_AGC_CONFIG__ + NewAgcMainChelFlag = 0; + #endif + + } + else + { + uchRealReslutByteNum -= 5; + } + //flag2 + if ((*(pstFrameInfo->punFrameCnt)) == 0 || pstFrameInfo->punFrameFlag[2] != g_unLastFrameFlag2 || uchFlag2ChangeFlag) + { + puchTempFrameDataBuf[uchOneFrameByteNum] = 2; + uchOneFrameByteNum ++; + GH3X2X_Memcpy((GU8*)&(puchTempFrameDataBuf[uchOneFrameByteNum]), (GU8*)(&(pstFrameInfo->punFrameFlag[2])), 4); + uchOneFrameByteNum += 4; + g_unLastFrameFlag2 = pstFrameInfo->punFrameFlag[2]; + uchFlag2ChangeFlag = 1; + } + else + { + uchFlag2ChangeFlag = 0; + uchRealReslutByteNum -= 5; + } + //flag3 + if(uchFramePosi&GH3X2X_FRAME_POSI_HEAD) + { + puchTempFrameDataBuf[uchOneFrameByteNum] = 3; + uchOneFrameByteNum ++; + GH3X2X_Memcpy((GU8*)&(puchTempFrameDataBuf[uchOneFrameByteNum]), (GU8*)(&(pstFrameInfo->punFrameFlag[3])), 4); + uchOneFrameByteNum += 4; + } + + #if GH3X2X_DIVIDE_ZERO_FLAG_UPLODE_EN + // flag4 div 0 flag + puchTempFrameDataBuf[uchOneFrameByteNum] = 4; + uchOneFrameByteNum ++; + GH3X2X_Memcpy((GU8*)&(puchTempFrameDataBuf[uchOneFrameByteNum]), (GU8*)(&(pstFrameInfo->punFrameFlag[4])), 4); + uchOneFrameByteNum += 4; + #endif + + //alg result + + if (1 == uchAlgoResFlag) + { + if (1 == pstFrameInfo->pstAlgoResult->uchUpdateFlag) + { + GU8 uchResTagData = GH3X2X_GET_LEFT_SHIFT_VAL(UPROTOCOL_RESULT_TYPE_BIT_FIELD); + GU8 uchResultNumTemp = 0; + for(GU8 uchResultCnt = 0;uchResultCnt < GH3X2X_ALGO_RESULT_MAX_NUM;uchResultCnt++) + { + if ((pstFrameInfo->pstAlgoResult->usResultBit >> uchResultCnt) & 0x1) + { + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_SET_BIT(uchResTagData, uchResultCnt); + uchOneFrameByteNum ++ ; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE0_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + uchOneFrameByteNum ++ ; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE1_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + uchOneFrameByteNum ++ ; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE2_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + uchOneFrameByteNum ++ ; + puchTempFrameDataBuf[uchOneFrameByteNum] = GH3X2X_GET_BYTE3_FROM_DWORD(pstFrameInfo->pstAlgoResult->snResult[uchResultCnt]); + uchOneFrameByteNum ++ ; + uchResultNumTemp ++; + if (uchResultNumTemp >= pstFrameInfo->pstAlgoResult->uchResultNum) + { + break; + } + } + } + } // end of if (1 == uchAlgoResFlag) + } + + //modify uchReslutByteNum + puchTempFrameDataBuf[uchOneFrameByteNum - uchRealReslutByteNum] = uchRealReslutByteNum - 1; + +#if 1 + GU8 uchSendFlag = 0; + if(((GU16)g_uchGh3x2xUploadBufUse + uchOneFrameByteNum) >= GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport)) //can not store more data + { + if (g_uchGh3x2xUploadBufUse <= GH3X2X_UPLOAD_PACKAGE_HEAD_SIZE) + { + uchSendFlag = GH3X2X_SEND_STATUS_SPLIC_PACK_MODE; + } + else + { + uchSendFlag = GH3X2X_SEND_STATUS_FULL_MODE; + } + } + else if (uchFramePosi&GH3X2X_FRAME_POSI_TAIL) + { + uchSendFlag = GH3X2X_SEND_STATUS_TAIL_MODE; + } + + if (uchSendFlag == GH3X2X_SEND_STATUS_SPLIC_PACK_MODE) + { + GU16 usMaxPackLen = GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport) - g_uchGh3x2xUploadBufUse; + GU16 usPackNum = uchOneFrameByteNum / usMaxPackLen; + GU16 usPackByteCnt = 0; + GU16 usExternPackLen = uchOneFrameByteNum % usMaxPackLen; + GU16 usPackCnt = 1; + + for (usPackCnt = 1 ; usPackCnt < usPackNum + 1 ; usPackCnt ++) + { + puchUploadBuf[UPROTOCOL_RAWDATA_LEN_INDEX] = g_uchGh3x2xUploadBufUse + usMaxPackLen; + puchUploadBuf[UPROTOCOL_PACKAGE_TYPE_INDEX] &= 0x7; + puchUploadBuf[UPROTOCOL_PACKAGE_TYPE_INDEX] |= GH3X2X_VAL_LEFT_SHIFT((GU8)usPackCnt, UPROTOCOL_SPLIC_PACK_CNT_FIELD); + GH3X2X_Memcpy(&puchUploadBuf[g_uchGh3x2xUploadBufUse], &puchTempFrameDataBuf[usPackByteCnt], usMaxPackLen); + usPackByteCnt += usMaxPackLen; + usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_NEW_STRUCT_RAWDATA, puchUploadBuf - 4, + puchUploadBuf, g_uchGh3x2xUploadBufUse + usMaxPackLen); + Gh3x2xDemoSendProtocolData(puchUploadBuf - 4,usRespondLen); + } + puchUploadBuf[UPROTOCOL_RAWDATA_LEN_INDEX] = g_uchGh3x2xUploadBufUse + usExternPackLen; + puchUploadBuf[UPROTOCOL_PACKAGE_TYPE_INDEX] &= 0x7; + puchUploadBuf[UPROTOCOL_PACKAGE_TYPE_INDEX] |= GH3X2X_VAL_LEFT_SHIFT((GU8)usPackCnt, UPROTOCOL_SPLIC_PACK_CNT_FIELD); + puchUploadBuf[UPROTOCOL_PACKAGE_TYPE_INDEX] |= GH3X2X_VAL_LEFT_SHIFT(1, UPROTOCOL_SPLIC_PACK_OVER_FIELD); + GH3X2X_Memcpy(&puchUploadBuf[g_uchGh3x2xUploadBufUse], &puchTempFrameDataBuf[usPackByteCnt], usExternPackLen); + usPackByteCnt += usExternPackLen; + usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_NEW_STRUCT_RAWDATA, puchUploadBuf - 4, + puchUploadBuf, g_uchGh3x2xUploadBufUse + usExternPackLen); + Gh3x2xDemoSendProtocolData(puchUploadBuf - 4,usRespondLen); + + g_uchOddEvenChangeFlag =! g_uchOddEvenChangeFlag; + g_uchGh3x2xUploadStatus = GH3X2X_UPLOAD_STATUS_NULL; + return; + } +#endif + + if(((GU16)g_uchGh3x2xUploadBufUse + uchOneFrameByteNum) >= GH3X2X_UPROTOCOL_GET_PAYLOAD_LEN_SUPPORT(g_uchPacketMaxLenSupport)) //can not store more data + { + //send data + usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_NEW_STRUCT_RAWDATA, puchUploadBuf - 4, + puchUploadBuf, g_uchGh3x2xUploadBufUse); + Gh3x2xDemoSendProtocolData(puchUploadBuf - 4,usRespondLen); + g_uchOddEvenChangeFlag = !g_uchOddEvenChangeFlag; + g_uchGh3x2xUploadStatus = GH3X2X_UPLOAD_STATUS_NULL; + uchNeedContinue = 1; + continue; + } + + GH3X2X_Memcpy(&puchUploadBuf[g_uchGh3x2xUploadBufUse], puchTempFrameDataBuf, uchOneFrameByteNum); + g_uchGh3x2xUploadBufUse += uchOneFrameByteNum; + if (uchEvenFirstFrameFlag != 1) + { + GH3X2X_Memcpy(g_stZipLastData.unFifoLastRawdataArr, unFrameRawdataArr, uchChnlNum*4); + GH3X2X_Memcpy(g_stZipLastData.uchFifoLastRawdataTagArr[uchFunctionIDForMaster], uchFifoLastRawdataTagArr, uchChnlNum); + GH3X2X_Memcpy(g_stZipLastData.unFifoLastAgcdataArr, unAgcdataArr, uchChnlNum*4); + } + puchUploadBuf[UPROTOCOL_RAWDATA_LEN_INDEX] += uchOneFrameByteNum; + + if(uchFramePosi&GH3X2X_FRAME_POSI_TAIL) + { + //send data + usRespondLen = GH3X2X_UprotocolPacketFormat(GH3X2X_UPROTOCOL_CMD_NEW_STRUCT_RAWDATA, puchUploadBuf - 4, + puchUploadBuf, g_uchGh3x2xUploadBufUse); + Gh3x2xDemoSendProtocolData(puchUploadBuf - 4,usRespondLen); + g_uchOddEvenChangeFlag = !g_uchOddEvenChangeFlag; + g_uchGh3x2xUploadStatus = GH3X2X_UPLOAD_STATUS_NULL; + } + } + } +} +#else +void Gh2x2xUploadZipDataToMaster(const STGh3x2xFrameInfo * const pstFrameInfo, GU16 usFrameCnt, GU16 usFrameNum, GU8* puchTagArray){} +#endif diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_zip.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_zip.h new file mode 100644 index 000000000..c2efe3e21 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_protocol/gh_zip.h @@ -0,0 +1,38 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_zip.h + * + * @brief gh3x2x universal protocol define & declaration + * + * @version ref gh3x2x_drv_zip.h + * + */ +#ifndef _GH3X2X_DRV_ZIPHANDLE_H_ +#define _GH3X2X_DRV_ZIPHANDLE_H_ + + +/** + * @brief ZipMode Lastdata Temp + */ +typedef struct +{ + GU8 uchFifoLastRawdataTagArr[GH3X2X_FUNC_OFFSET_MAX][GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastRawdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; + GU32 unFifoLastAgcdataArr[GH3X2X_CHANNEL_MAP_MAX_CH]; +} STZipLastDataStruct; + + + + +extern void GH3X2X_GetRawDataDiff(GU32 *punRawData, GU8 *puchRawdataTagTempArr, + GU8 uchChannelMapCnt, GU8 *puchZipDataArr, GU8 *puchZipDataArrSize, + GU8 *uchFifoLastRawdataTagArr, GU32 *unFifoLastRawdataArr); + +extern void GH3X2X_GetDataDiff(GU32 *punData, GU8 uchChannelMapCnt, GU8 *puchZipDataArr, + GU8 *puchZipDataArrSize, GU32 *punZipTempData); + +extern void GH3X2X_ZipmodeInit(void); + +#endif + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_soft_adt/gh_multi_sen_pro.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_soft_adt/gh_multi_sen_pro.c new file mode 100644 index 000000000..25c29e794 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_soft_adt/gh_multi_sen_pro.c @@ -0,0 +1,691 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_drv_adt.c + * + * @brief gh3x2x adt functions + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#include +#include "gh_demo_config.h" +#include "gh_demo_inner.h" +#include "gh_drv.h" +#include "gh_multi_sen_pro.h" + +#if __GH_MULTI_SENSOR_EVENT_PRO_CONIG__ + +STGhMultiSensorTimer g_stGhMultiSensorTimer; + +void GhMultiSensorTimerInit(void) +{ + GH3X2X_Memset((GU8*)(&g_stGhMultiSensorTimer), 0, sizeof(g_stGhMultiSensorTimer)); +} + +void GhMultiSensorTimerOpsRegister(const STGhMultiSensorTimerOps *pstTimerOps) +{ + g_stGhMultiSensorTimer.pstTimerOps = pstTimerOps; + + if(g_stGhMultiSensorTimer.pstTimerOps) + { + g_stGhMultiSensorTimer.pstTimerOps->TimerCreate(__GH_MULTI_SENSOR_TIMER_PERIOD_MS__); + } +} + +void GhMultiSensorTimerOpsUnregister(void) +{ + if(g_stGhMultiSensorTimer.pstTimerOps) + { + g_stGhMultiSensorTimer.pstTimerOps->TimerDelete(); + } + g_stGhMultiSensorTimer.pstTimerOps = 0; +} + +void GhMultiSensorTimerStart(void) +{ + if(g_stGhMultiSensorTimer.pstTimerOps) + { + g_stGhMultiSensorTimer.pstTimerOps->TimerStart(); + } +} + +void GhMultiSensorTimerStop(void) +{ + if(g_stGhMultiSensorTimer.pstTimerOps) + { + g_stGhMultiSensorTimer.pstTimerOps->TimerStop(); + } +} + +void GhMultiSensorTimerUserRegister(GU8 uchUserId, void (*TimerHandle) (GU32)) +{ + if(uchUserId < GH_MULTI_SENSOR_TIMER_USER_NUM_MAX) + { + g_stGhMultiSensorTimer.stTimerUsers[uchUserId].TimerHandle = TimerHandle; + } +} + +void GhMultiSensorTimerUserUnregister(GU8 uchUserId) +{ + if(uchUserId < GH_MULTI_SENSOR_TIMER_USER_NUM_MAX) + { + g_stGhMultiSensorTimer.stTimerUsers[uchUserId].TimerHandle = 0; + } +} + +void GhMultiSensorTimerHandle(void) +{ + for(GU8 uchUserCnt = 0; uchUserCnt < GH_MULTI_SENSOR_TIMER_USER_NUM_MAX; uchUserCnt ++) + { + if(g_stGhMultiSensorTimer.stTimerUsers[uchUserCnt].TimerHandle) + { + g_stGhMultiSensorTimer.stTimerUsers[uchUserCnt].TimerHandle(__GH_MULTI_SENSOR_TIMER_PERIOD_MS__); + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + +typedef struct +{ + GU64 unnTimeStamp; //64bit unix timestamp + GU8 uchNext; // 0~254 point to newer event 255:invalid +}STMultiSensorWearEvent; + +typedef struct +{ + GU8 En; // 0: Manager is disabled 1: Manger is enabled + GU8 uchHead; // linked list head + volatile GU64 unnCurrentTimeStamp; + STMultiSensorWearEvent pstMultiSensorWearEvent[GH3X2X_MULTI_SENSOR_EVENT_NUM_MAX]; //linked list members + void (*WearEventHook) (GU32 uchNewEvent); +}STMultiSensorWearEventManager; //linked list + +STMultiSensorWearEventManager g_stMultiSensorWearEventManager; + +/// @brief get current timestamp +/// @param +/// @return +static GU64 GhMultSensorWearEventManagerGetCurTs(void) +{ + return g_stMultiSensorWearEventManager.unnCurrentTimeStamp; //it maybe is not atomic opration, this function must add lock !!! +} + +/// @brief update timestamp for wear event manager, this function will be call at timer handle +/// @param unTimeIntervalMs the interval of timer (unit: ms) +static void GhMultSensorWearEventManagerUpdataCurTs(GU32 unTimeIntervalMs) +{ + g_stMultiSensorWearEventManager.unnCurrentTimeStamp += unTimeIntervalMs; //it maybe is not atomic opration, this function must add lock !!! +} + +static void GhMultSensorWearEventManagerTimerHandle(GU32 unTimeIntervalMs) +{ + GH3X2X_INFO_LOG("GhMultSensorWearEventManagerTimerHandle.\r\n"); + GhMultSensorWearEventManagerUpdataCurTs(unTimeIntervalMs); +} + +/// @brief Init multi-sensor wear event manager +/// @param +void GhMultSensorWearEventManagerInit(void) +{ + GH3X2X_Memset((GU8*)(&g_stMultiSensorWearEventManager), 0, sizeof(STMultiSensorWearEventManager)); + g_stMultiSensorWearEventManager.uchHead = GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID; // point to NULL + //clear linked list members + for(GU8 uchEventCnt = 0; uchEventCnt < GH3X2X_MULTI_SENSOR_EVENT_NUM_MAX; uchEventCnt ++) + { + g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[uchEventCnt].uchNext = GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID; + } + +} + +/// @brief register hook function for wear event hook +/// @param WearEventHook hook funcion +void GhMultSensorWearEventManagerHookRegister(void (*WearEventHook) (GU32 uchNewEvent)) +{ + g_stMultiSensorWearEventManager.WearEventHook = WearEventHook; +} + +/// @brief enable wear event manager +/// @param +void GhMultSensorWearEventManagerEnable(void) +{ + g_stMultiSensorWearEventManager.En = 1; + GhMultiSensorTimerUserRegister(GH_MULTI_SENSOR_TIMER_USER_TIME_STAMP, GhMultSensorWearEventManagerTimerHandle); //register timer user +} + +/// @brief disable wear event manager +/// @param +void GhMultSensorWearEventManagerDisable(void) +{ + GhMultSensorWearEventManagerInit(); + GhMultiSensorTimerUserUnregister(GH_MULTI_SENSOR_TIMER_USER_TIME_STAMP); +} + +GU8 GhMultSensorWearEventManagerIsEnable(void) +{ + return g_stMultiSensorWearEventManager.En; +} + + + + + +/// @brief get the pointer of next member +/// @param[in] uchCurEventPointer this point points current event member's uchNext +/// @return the pointer of next member, this point points next event member's uchNext +static GU8* GetNextEventPointer(GU8* uchCurEventPointer) +{ + if(0 != uchCurEventPointer) + { + return &(g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[*uchCurEventPointer].uchNext); + } + else + { + return 0; + } +} + +/// @brief get the pointer of previous member of event uchEvtOffset +/// @param uchEvtOffset offset of event +/// @return the pointer of previous member of event uchEvtOffset, this point points uchHead or previous member's uchNext. 0: can not find this member +static GU8* GetPreviousEventPointer(GU8 uchEvtOffset) +{ + GU8* pTemp = 0; + + GU8* pNext = &(g_stMultiSensorWearEventManager.uchHead); + + do{ + if(GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID == *pNext) + { + break; + } + if(uchEvtOffset == (*pNext)) + { + pTemp = pNext; + break; + } + pNext = GetNextEventPointer(pNext); + }while(1); + + return pTemp; +} + +/// @brief get the pointer of tail in linker list +/// @param +/// @return the pointer of tail in linker list, the poiniter points to g_stMultiSensorWearEventManager.uchHead or pstMultiSensorWearEvent[N].uchNext +static GU8* GetTailEventPointer(void) +{ + GU8* pTemp = &(g_stMultiSensorWearEventManager.uchHead); + + do{ + if(GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID == *pTemp) + { + break; + } + pTemp = GetNextEventPointer(pTemp); + }while(1); + + return pTemp; +} + +/// @brief get oldest and newest event(in range of unEventComb) information +/// @param unEventComb Event combination you need check +/// @param[out] pOldestTs pointer of oldest event timestamp +/// @param[out] pNewestTs pointer of newest event timestamp +/// @param[out] pOldestEvt pointer of oldest event, *pOldestEvt = 0 means this event cannot find +/// @param[out] pONewestEvt pointer of newest event, *pONewestEvt = 0 means this event cannot find +/// @return +static void GetOldestAndNewestEvtInfo(GU32 unEventComb, GU64* pOldestTs, GU64* pNewestTs, GU32* pOldestEvt, GU32* pONewestEvt) +{ + GU32 unCurEvt; + GU32 unRemainEventComb = unEventComb; + (*pOldestEvt) = 0; + (*pONewestEvt) = 0; + + GU8* pTemp = &(g_stMultiSensorWearEventManager.uchHead); + + do{ + if(GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID == *pTemp) + { + break; + } + unCurEvt = ((GU32)1 << (*pTemp)); + if(unEventComb & unCurEvt) + { + if(unEventComb == unRemainEventComb) //first event we finded + { + (*pOldestTs) = (g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[*pTemp].unnTimeStamp); + (*pOldestEvt) = unCurEvt; + } + (*pNewestTs) = (g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[*pTemp].unnTimeStamp); + (*pONewestEvt) = unCurEvt; + unRemainEventComb &= (~unCurEvt); //clear event we finded + if(0 == unRemainEventComb) //last event we finded + { + break; + } + } + pTemp = GetNextEventPointer(pTemp); + }while(1); + +} + +/// @brief print all events in linked list +/// @param +static void GhMultiSensorPrintAllEvt(void) +{ + GU8* pTemp = &(g_stMultiSensorWearEventManager.uchHead); + GU8 uchEvtNum = 0; + GH3X2X_INFO_LOG("[MultiSensor] print events start...\r\n"); + do{ + if(GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID == *pTemp) + { + break; + } + GH3X2X_INFO_LOG("[MultiSensor] EvtPosi = %d, Evt = 0x%X, Ts = %llu.\r\n", (int)uchEvtNum, (((GU32)1) << (*pTemp)), g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[*pTemp].unnTimeStamp); + uchEvtNum ++; + pTemp = GetNextEventPointer(pTemp); + }while(1); + GH3X2X_INFO_LOG("[MultiSensor] print events end, uchEvtNum = %d.\r\n", (int)uchEvtNum); +} + +/// @brief check event combination is in this time window or not +/// @param unEventComb event combination +/// @param unWindow time window (unit: ms) +/// @param uchNowTimeNeedInWin current timestamp is include or not (0: is include 1: is NOT include) +/// @return 0: no 1: yes +GU8 GhMultiSensorConditionCheckInWindow (GU32 unEventComb, GU32 unWindow, GU8 uchNowTimeNeedInWin) +{ + GU64 nnOldestTs; + GU64 nnNewestTs; + GU32 nnOldestEvt; + GU32 nnNewestEvt; + + GetOldestAndNewestEvtInfo(unEventComb, &nnOldestTs, &nnNewestTs, &nnOldestEvt, &nnNewestEvt); + if((0 == nnOldestEvt)||(0 == nnNewestEvt)) //can NOT find any event in unEventComb + { + return 0; + } + if(1 == uchNowTimeNeedInWin) + { + nnNewestTs = GhMultSensorWearEventManagerGetCurTs(); + } + if((nnNewestTs - nnOldestTs) < unWindow) + { + return 1; + } + else + { + return 0; + } +} + +/// @brief check unEventNew is new than unEventOld or not +/// @param unEventNew new event we hope for +/// @param unEventOld old event we hope for +/// @return 0: no or there is no unEventNew 1: yes or there is only unEventNew +GU8 GhMultiSensorConditionCheckIsNew (GU32 unEventNew, GU32 unEventOld) +{ + GU64 nntTs; + GU32 unOldestEvt; + GU32 unNewestEvt; + GetOldestAndNewestEvtInfo(unEventNew|unEventOld, &nntTs, &nntTs, &unOldestEvt, &unNewestEvt); + if(unNewestEvt == unEventNew) + { + return 1; + } + else + { + return 0; + } +} + +/// @brief send evet to Multi-sensor wear event manager +/// @param unEvent such as: GH3X2X_MULTI_SENSOR_EVENT_GH_WEAR_ON +void GhMultSensorWearEventSend(GU32 unEvent) +{ + GU64 unnCurTs; + GU8* puchPreMemberPointer; + GU8* puchTailPointer; + GU8 uchNewEvtOffset = GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID; + + //get current time stamp + unnCurTs = GhMultSensorWearEventManagerGetCurTs(); + //get offset of this new event + for(GU8 uchEvtCnt = 0; uchEvtCnt < GH3X2X_MULTI_SENSOR_EVENT_NUM_MAX; uchEvtCnt ++) + { + if(((GU32)1 << uchEvtCnt) == unEvent) + { + uchNewEvtOffset = uchEvtCnt; + break; + } + } + if((GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID == uchNewEvtOffset) || (0 == g_stMultiSensorWearEventManager.En)) //invalid event or event manager is disable + { + return; + } + //remove outdated event member in linked list + puchPreMemberPointer = GetPreviousEventPointer(uchNewEvtOffset); + if(puchPreMemberPointer) + { + (*puchPreMemberPointer) = g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[uchNewEvtOffset].uchNext; + } + //add new event to link tail + puchTailPointer = GetTailEventPointer(); + (*puchTailPointer) = uchNewEvtOffset; + //fill timestamp and next for this new event + g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[uchNewEvtOffset].unnTimeStamp = unnCurTs; + g_stMultiSensorWearEventManager.pstMultiSensorWearEvent[uchNewEvtOffset].uchNext = GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID; + //print new event + GH3X2X_INFO_LOG("[MultiSensor] new event received, Evt = 0x%X.\r\n", unEvent); + //print all event + GhMultiSensorPrintAllEvt(); + //call event hook + if(g_stMultiSensorWearEventManager.WearEventHook)g_stMultiSensorWearEventManager.WearEventHook(unEvent); +} + + +#endif + +typedef struct +{ + GS16 sXAxisVal; /**< x-axis value */ + GS16 sYAxisVal; /**< y-axis value */ + GS16 sZAxisVal; /**< z-axis value */ +} STGsAccRawdata; + + +#if __GSENSOE_MOVE_DETECT_SUPPORT__ + + +typedef struct +{ + GU8 uchMoveDetEnable; //enable gs movement detect or not + GU8 uchGsensorStatus; // movement status of g sensor + GU16 usGsMoveDetectCnt; // count how many times of movement detected by g sensor + GU16 usGsNotMoveDetectCnt; // count how many times of not movement detected by g sensor + GU8 uchGsMoveDetectNotFirstTime; // 0: the first time of G sensor move detection 1: is not first time of G sensor move detection + STGsAccRawdata stLastPointMoveDetGsenorRawdata; + GU16 usNotMoveTimeCnt; //the counter of not move, 0: time out has trigled or initial state, 1: is moving state, >1: the conter of not move, unit: ms +}STGsMoveDetecter; + +STGsMoveDetecter g_stGhGsMoveDetecter; + + + + +extern void GH3X2X_RedetectWearOn(void); + + + +void GhGsMoveDetecterInit(void) +{ + GH3X2X_Memset((GU8*)(&g_stGhGsMoveDetecter), 0, sizeof(STGsMoveDetecter)); + +} + +void GhGsMoveDetecterEnable(void) +{ + g_stGhGsMoveDetecter.uchMoveDetEnable = 1; + #if __GH_MULTI_SENSOR_EVENT_PRO_CONIG__ + GhMultiSensorTimerUserRegister(GH_MULTI_SENSOR_TIMER_USER_MOVE_DET, Gh3x2xDemoMoveDetectTimerHandler); //register timer user + #endif +} + +void GhGsMoveDetecterDisable(void) +{ + GhGsMoveDetecterInit(); + #if __GH_MULTI_SENSOR_EVENT_PRO_CONIG__ + GhMultiSensorTimerUserUnregister(GH_MULTI_SENSOR_TIMER_USER_MOVE_DET); + #endif +} + +GU8 GhGsMoveDetecterIsEnable(void) +{ + return g_stGhGsMoveDetecter.uchMoveDetEnable; +} + + + + + + + +/// function started bitmap, use for sampling control +#if 1 +#if (__DRIVER_LIB_MODE__ == __DRV_LIB_WITH_ALGO__) && __USE_GOODIX_SOFT_ADT_ALGORITHM__ +extern GU8 NADTWearDetectByCap(GS32 lPacketInfoArr[]); +void GH3X2X_MoveDetectByCapData(STCapRawdata* pusCapData, GU16 usCapDataCnt) +{ + if( 0 == GH3X2X_GetCapEnableFlag()) + { + return; + } + GS32 lPacketInfoArr[4]; + for(GU16 i = 0; i < usCapDataCnt;i++) + { + lPacketInfoArr[0] = pusCapData[i].unCapData[0]; + lPacketInfoArr[1] = pusCapData[i].unCapData[1]; + lPacketInfoArr[2] = pusCapData[i].unCapData[2]; + lPacketInfoArr[3] = pusCapData[i].unCapData[3]; + + if(1 == NADTWearDetectByCap(lPacketInfoArr)) + { + return; + } + } +} +#else +void GH3X2X_MoveDetectByCapData(STCapRawdata* pusCapData, GU16 usCapDataCnt) +{ + return; +} +#endif +#endif +/** + * @fn void GhMoveDetectByGsData(STGsensorRawdata* stGsData, GU16 usGsDataCnt, GU8 uchCheckWindowSize) + + * + * @brief Move detection by software. + * + * @attention None + * + * @param[in] stGsData gsensor data buffer + * @param[in] usGsDataCnt gsensor data count + * @param[in] uchCheckWindowSize the window size of cheak moving peak num + * @param[out] None + * + * @return None + */ +//extern void SlaverLog(const char * lpsbLog, ...); +void GhMoveDetectByGsData(GS16* pusGsData, GU16 usGsDataCnt) +{ + GS16 sXAxisVal = 0; + GS16 sYAxisVal = 0; + GS16 sZAxisVal = 0; + GU8 uchGyroEnable = g_uchGyroEnable; + GU32 unSumOfSquare = 0; + GU16 usGsDataIndex = 0; + if ((GH3X2X_PTR_NULL == pusGsData) || (0 == usGsDataCnt)) + { + GH3X2X_DEBUG_LOG("[GhMoveDetectByGsData] return; pusGsData[0] = %d , usGsDataCnt = %d \r\n",pusGsData[0],usGsDataCnt); + return; + } + + { + if (g_stGhGsMoveDetecter.uchMoveDetEnable) + { + if(0 == g_stGhGsMoveDetecter.uchGsMoveDetectNotFirstTime) + { + g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sXAxisVal = pusGsData[0]; + g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sYAxisVal = pusGsData[0+1]; + g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sZAxisVal = pusGsData[0+2]; + g_stGhGsMoveDetecter.uchGsMoveDetectNotFirstTime = 1; + } + //calculate average of x, y, z + for (usGsDataIndex = 0; usGsDataIndex < usGsDataCnt; usGsDataIndex++) + { + //GH3X2X_DEBUG_LOG("[GhMoveDetectByGsData] x=%d, y=%d, z =%d\r\n", pusGsData[usGsDataIndex*(3+3*uchGyroEnable)], pusGsData[usGsDataIndex*(3+3*uchGyroEnable) + 1], pusGsData[usGsDataIndex*(3+3*uchGyroEnable) + 2]); + sXAxisVal = pusGsData[usGsDataIndex*(3+3*uchGyroEnable)] - g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sXAxisVal; + sYAxisVal = pusGsData[usGsDataIndex*(3+3*uchGyroEnable) + 1] - g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sYAxisVal; + sZAxisVal = pusGsData[usGsDataIndex*(3+3*uchGyroEnable) + 2] - g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sZAxisVal; + + g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sXAxisVal = pusGsData[usGsDataIndex*(3+3*uchGyroEnable)]; + g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sYAxisVal = pusGsData[usGsDataIndex*(3+3*uchGyroEnable) + 1]; + g_stGhGsMoveDetecter.stLastPointMoveDetGsenorRawdata.sZAxisVal = pusGsData[usGsDataIndex*(3+3*uchGyroEnable) + 2]; + + + unSumOfSquare = (GU32)((GS32)sXAxisVal * sXAxisVal) + (GU32)((GS32)sYAxisVal * sYAxisVal) + (GU32)((GS32)sZAxisVal * sZAxisVal); + + if(unSumOfSquare > ((GU32)__GSENSOR_MOVE_THRESHOLD__ * __GSENSOR_MOVE_THRESHOLD__)) + { + GH3X2X_DEBUG_LOG("[GhMoveDetectByGsData] g_stGhGsMoveDetecter.usGsMoveDetectCnt = %d \r\n", g_stGhGsMoveDetecter.usGsMoveDetectCnt); + g_stGhGsMoveDetecter.usGsNotMoveDetectCnt = 0; + if (g_stGhGsMoveDetecter.usGsMoveDetectCnt >= __GSENSOR_MOVE_CNT_THRESHOLD__) + { + GH3X2X_DEBUG_LOG("[GhMoveDetectByGsData] over __GSENSOR_MOVE_CNT_THRESHOLD__!!! \r\n"); + g_stGhGsMoveDetecter.uchGsensorStatus = GH3X2X_SENSOR_IS_MOVING; + GH3X2X_DEBUG_LOG("[GhMoveDetectByGsData] Move detect effect!!! \r\n"); + } + else + { + g_stGhGsMoveDetecter.usGsMoveDetectCnt ++; + } + } + else + { + if (g_stGhGsMoveDetecter.usGsMoveDetectCnt != 0) + { + GH3X2X_DEBUG_LOG("[GhMoveDetectByGsData] g_stGhGsMoveDetecter.usGsNotMoveDetectCnt = %d \r\n", g_stGhGsMoveDetecter.usGsNotMoveDetectCnt); + + if (g_stGhGsMoveDetecter.usGsNotMoveDetectCnt >= __GSENSOR_NOT_MOVE_CNT_THRESHOLD__) + { + g_stGhGsMoveDetecter.usGsMoveDetectCnt = 0; + g_stGhGsMoveDetecter.uchGsensorStatus = GH3X2X_SENSOR_IS_NOT_MOVING; + GH3X2X_DEBUG_LOG("[GhMoveDetectByGsData] Move detect is not effect!!! \r\n"); + } + else + { + g_stGhGsMoveDetecter.usGsNotMoveDetectCnt ++; + } + } + } + } + + + + if(GH3X2X_SENSOR_IS_MOVING == g_stGhGsMoveDetecter.uchGsensorStatus) + { + #if __GH_MULTI_SENSOR_EVENT_PRO_CONIG__ + GhMultSensorWearEventSend(GH3X2X_MULTI_SENSOR_EVENT_GS_MOVE); + #endif + g_stGhGsMoveDetecter.usNotMoveTimeCnt = 1; + } + if((GH3X2X_SENSOR_IS_NOT_MOVING == g_stGhGsMoveDetecter.uchGsensorStatus) && (g_stGhGsMoveDetecter.usNotMoveTimeCnt >= 1)) + { + GU32 unTempCnt; + unTempCnt = ((GU32)g_stGhGsMoveDetecter.usNotMoveTimeCnt + __GH_MULTI_SENSOR_TIMER_PERIOD_MS__); + if(unTempCnt > 0xFFFF) + { + unTempCnt = 0xFFFF; + } + if(unTempCnt > __GSENSOR_MOVE_TIME_OUT_THRESHOLD_MS__) + { + #if __GH_MULTI_SENSOR_EVENT_PRO_CONIG__ + GhMultSensorWearEventSend(GH3X2X_MULTI_SENSOR_EVENT_GS_MOVE_TIME_OUT); + #endif + unTempCnt = 0; + } + g_stGhGsMoveDetecter.usNotMoveTimeCnt = (GU16)unTempCnt; + } + } + } +} + + + + +/** + * @fn GU8 Gh3x2x_GetMoveDetStatus(void) + * + * @brief Get status of movement detected + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return GH3X2X_SENSOR_IS_NOT_MOVING/GH3X2X_SENSOR_IS_MOVING + */ +GU8 Gh3x2x_GetMoveDetStatus(void) +{ + return g_stGhGsMoveDetecter.uchGsensorStatus; +} + + + + + +#endif + + + + + + + + + + + + + + + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ + + + + + + +extern void hal_gh3x2x_write_cap_to_flash(GS32 WearCap1,GS32 UnwearCap1,GS32 WearCap2,GS32 UnwearCap2); +extern void hal_gh3x2x_read_cap_from_flash(GS32* WearCap1,GS32* UnwearCap1,GS32* WearCap2,GS32* UnwearCap2); + +void GH3x2xWriteCapToFlash(void) +{ +// hal_gh3x2x_write_cap_to_flash(lWearCap1,lUnwearCap1,lWearCap2,lUnwearCap2); +} + +void GH3x2xReadCapFromFlash(void) +{ +// hal_gh3x2x_read_cap_from_flash(&lWearCap1,&lUnwearCap1,&lWearCap2,&lUnwearCap2); +} + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_soft_adt/gh_multi_sen_pro.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_soft_adt/gh_multi_sen_pro.h new file mode 100644 index 000000000..8e55180ce --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_kernel_code/module/gh_soft_adt/gh_multi_sen_pro.h @@ -0,0 +1,208 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh_demo_multi_sen_pro.h + * + * @brief gh3x2x adt + * + * @version ref gh3x2x_drv_version.h + * + */ + + +#ifndef _gh_demo_multi_sen_pro_H_ +#define _gh_demo_multi_sen_pro_H_ + + +#include "gh_drv.h" + +/// wear on event en set +#define WEAR_ON_EVENT_EN_CONFIG(en) do {\ + GH3X2X_WriteRegBitField(GH3X2X_INT_CR2_REG_ADDR, \ + GH3X2X_WEAR_ON_EVENT_EN_LSB, GH3X2X_WEAR_ON_EVENT_EN_MSB, (en)); \ + } while (0) + +/// wear off event en set +#define WEAR_OFF_EVENT_EN_CONFIG(en) do {\ + GH3X2X_WriteRegBitField(GH3X2X_INT_CR2_REG_ADDR, \ + GH3X2X_WEAR_OFF_EVENT_EN_LSB, GH3X2X_WEAR_OFF_EVENT_EN_MSB, (en)); \ + } while (0) + + + +#define SOFT_WEAR_INPUT_DATA_CHNL0_INDEX (0) +#define SOFT_WEAR_INPUT_DATA_ACCX_INDEX (1) +#define SOFT_WEAR_INPUT_DATA_ACCY_INDEX (2) +#define SOFT_WEAR_INPUT_DATA_ACCZ_INDEX (3) +#define SOFT_WEAR_INPUT_COLOR_INDEX (4) +#define SOFT_WEAR_INPUT_DATA_ADT_INDEX (5) //ir adt data +#define SOFT_WEAR_INPUT_DATA_BG_INDEX (6) +#define SOFT_WEAR_INPUT_DATA_CAP0_INDEX (7) +#define SOFT_WEAR_INPUT_DATA_CAP1_INDEX (8) +#define SOFT_WEAR_INPUT_DATA_CAP2_INDEX (9) +#define SOFT_WEAR_INPUT_DATA_CAP3_INDEX (10) + + +#define SOFT_WEAR_INPUT_DATA_INDEX_TOTAL (11) +#define SOFT_WEAR_OUTPUT_DATA_INDEX_TOTAL (8) + + +#define SOFT_WEAR_OUTPUT_WEAR_STATE_BIT (3) + + +#define NADTCAP_BYTE_TRUE (GU8)1 +#define NADTCAP_BYTE_FALSE (GU8)0 + + + +#define NADT_SAMPLE_FREQ 25 +#define NADT_WWD_IIR_LEN 4 + +#define NADT_WEAR_LIVE_DETECTION +#ifdef NADT_WEAR_LIVE_DETECTION // this is wear live dection, full wear dection,can distinguish body and other thing; more Ram +#define NADT_PPG_BUFF_LEN (4) //4 +#else +#define NADT_PPG_BUFF_LEN (2) //lite +#endif // NADT_WEAR_LIVE_DETECTION + +#define NADT_WWD_FILTER_BUFF_LEN (NADT_PPG_BUFF_LEN*NADT_SAMPLE_FREQ) +#define NADT_MATH_ROUND(v) round(v) +#define NADT_MATH_ABSF(v) fabs(v) +#define NADT_MATH_ABS(v) abs(v) +#define NADT_MATH_ROUNDF(v) roundf(v) +#define NADT_ABS_GS32(v) abs((GS32)(v)) +#define NADT_MIN(a,b) ((a) > (b) ? (b) : (a)) + + + +#define NADT_PV_PEAK (1) +#define NADT_PV_VALLEY (2) +#define NADT_PV_PV_INTER (4) +#define NADT_ACC_TRUNCATE (5) + +#define GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GH_WEAR_ON 0 //index of member in linked list for gh senosr wear on +#define GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GH_WEAR_OFF 1 //index of member in linked list for gh senosr wear off +#define GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GS_MOVE 2 //index of member in linked list for gsensor move +#define GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GS_MOVE_TIME_OUT 3 //index of member in linked list for gsenosr move time out + +#define GH3X2X_MULTI_SENSOR_EVENT_NUM_MAX 4 +#define GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_INVALID 255 + +#define GH3X2X_MULTI_SENSOR_EVENT_GH_WEAR_ON (1 << GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GH_WEAR_ON) // gh sensor wear on +#define GH3X2X_MULTI_SENSOR_EVENT_GH_WEAR_OFF (1 << GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GH_WEAR_OFF) // gh sensor wear off +#define GH3X2X_MULTI_SENSOR_EVENT_GS_MOVE (1 << GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GS_MOVE) // gsensor move +#define GH3X2X_MULTI_SENSOR_EVENT_GS_MOVE_TIME_OUT (1 << GH3X2X_MULTI_SENSOR_EVENT_LL_INDEX_GS_MOVE_TIME_OUT) //gs move time out + + + + + +typedef struct +{ + GS32 *pData; + GS32 nLength; + GS32 nPos; +}NADT_QUEUE_BUFFER_S32; + +typedef struct +{ + GS16 *pData; + GS32 nLength; + GS32 nPos; +}NADT_QUEUE_BUFFER_S16; + +typedef struct +{ + const GF32 *pfCoefB; + const GF32 *pfCoefA; + GF32 *pfXbuff; + GF32 *pfYbuff; + GS32 lLen; + GF32 fThr; +}NADT_ST_IIR_PARAM; + +typedef struct +{ + GS32 *pfFftValue; + GS16 *psPeakIndex; + GS16 *psValleyIndex; + GS16 *psPeakValleyIndex; + GS32 lPeakValleyLen; + GS32 lPeakLen; + GS32 lValleyLen; + GS32 lDataLen; +}NADT_ST_PEAK_VALLEY_INFO; + +typedef struct +{ + GBOOL bSearchMax; + GS32 fExtremumValue; + GS32 lPreExtremumPos; + GS32 lExtremumPos; + GS32 lDataCount; +}NADT_ST_PEAKX_DET; + + + + + +void GhMultSensorWearEventManagerInit(void); +void GhMultSensorWearEventManagerHookRegister(void (*WearEventHook) (GU32 uchNewEvent)); +void GhMultSensorWearEventManagerEnable(void); +void GhMultSensorWearEventManagerDisable(void); +GU8 GhMultSensorWearEventManagerIsEnable(void); +void GhMultSensorWearEventSend(GU32 unEvent); +GU8 GhMultiSensorConditionCheckIsNew (GU32 unEventNew, GU32 unEventOld); +GU8 GhMultiSensorConditionCheckInWindow (GU32 unEventComb, GU32 unWindow, GU8 uchNowTimeNeedInWin); + + + + + +#define GH_MULTI_SENSOR_TIMER_USER_TIME_STAMP 0 +#define GH_MULTI_SENSOR_TIMER_USER_MOVE_DET 1 + +#define GH_MULTI_SENSOR_TIMER_USER_NUM_MAX 2 + + +typedef struct +{ + void (*TimerCreate)(GU32 unTimerPeriodMs); + void (*TimerStart)(void); + void (*TimerStop)(void); + void (*TimerDelete)(void); +}STGhMultiSensorTimerOps; + +typedef struct +{ + void (*TimerHandle)(GU32 unTimeIntervalMs); +}STGhMultiSensorTimerUser; + + +typedef struct +{ + const STGhMultiSensorTimerOps *pstTimerOps; + STGhMultiSensorTimerUser stTimerUsers[GH_MULTI_SENSOR_TIMER_USER_NUM_MAX]; +}STGhMultiSensorTimer; + + + + +void GhMultiSensorTimerInit(void); +void GhMultiSensorTimerStart(void); +void GhMultiSensorTimerStop(void); +void GhMultiSensorTimerOpsRegister(const STGhMultiSensorTimerOps *pstTimerOps); +void GhMultiSensorTimerOpsUnregister(void); +void GhMultiSensorTimerHandle(void); + + + +void GhGsMoveDetecterInit(void); +void GhGsMoveDetecterEnable(void); +void GhGsMoveDetecterDisable(void); +GU8 GhGsMoveDetecterIsEnable(void); + +#endif /* _GH3X2X_DRV_SOFT_LEAD_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ + diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_demo_mp.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_demo_mp.h new file mode 100644 index 000000000..bbd57d972 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_demo_mp.h @@ -0,0 +1,193 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_mp.h + * + * @brief header file of gh3x2x demo mp test + * + * @author Goodix Product Tools Development Team + * + */ + +#ifndef _GH3X2X_DEMO_MP_H_ +#define _GH3X2X_DEMO_MP_H_ + +#include "gh3x2x_mp_config.h" +#include "gh3x2x_mp_define.h" + +#ifndef GH3X2X_MP_UNUSED_VAR +#define GH3X2X_MP_UNUSED_VAR(X) ((void)(X)) +#endif // GH3X2X_UNUSED_VAR + +/** + * @fn void Gh3x2xDemoMp_Init() + * + * @brief GH3x2x mp init + * + * @attention None + * + * @param[in] none + * @param[out] None + * + * @return none + */ +void Gh3x2xDemoMp_Init(void); + +/** + * @fn GU8 Gh3x2xDemoMp_StartTest() + * + * @brief GH3x2x mp start test + * + * @attention None + * + * @param[in] none + * @param[out] None + * + * @return 0:test ok, other:error code + */ +GU8 Gh3x2xDemoMp_StartTest(void); + +/** + * @fn void Gh3x2xDemoMp_SetTestParam_PPG(stGh3x2xMp_TestParam *stTestParam) + * + * @brief GH3x2x MP set PPG test items param + * + * @attention None + * + * @param[in] stGh3x2xMp_PPGTestParam *stPPG_TestParam + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoMp_SetTestParam_PPG(stGh3x2xMp_PPGTestParam *stPPG_TestParam); + +/** + * @fn void Gh3x2xDemoMp_SetTestParam_ECG(stGh3x2xMp_ECGTestParam *stECG_TestParam) + * + * @brief GH3x2x MP set ECG test items param + * + * @attention None + * + * @param[in] stGh3x2xMp_ECGTestParam *stECG_TestParam + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoMp_SetTestParam_ECG(stGh3x2xMp_ECGTestParam *stECG_TestParam); + +/** + * @fn void Gh3x2xDemoMp_SetTestParam(stGh3x2xMp_TestParam *stTestParam) + * + * @brief GH3x2x MP set all test items param. + * + * @attention None + * + * @param[in] stGh3x2xMp_TestParam *stTestParam + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoMp_SetTestParam(stGh3x2xMp_TestParam *stTestParam); + +/** + * @fn void Gh3x2xDemoMp_PrintTestResult(stGh3x2xMp_TestParam *stTestParam, stGh3x2xMp_TestResult *stTestResult) + * + * @brief GH3x2x mp print all test result + * + * @attention It must be called after the test ends + * + * @param[in] stGh3x2xMp_TestParam *stTestParam, stGh3x2xMp_TestResult *stTestResult + * @param[out] None + * + * @return none + */ +void Gh3x2xDemoMp_PrintTestResult(stGh3x2xMp_TestParam *stTestParam, stGh3x2xMp_TestResult *stTestResult); + +/** + * @fn GU8 Gh3x2xDemoMp_CommunicationTest(GCHAR *para, GCHAR *TestResult) + * + * @brief GH3x2x MP Communication Test. + * + * @attention None + * + * @param[in] GU8 *puchPara, GU8 *pushTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_CommunicationTest(GU8 *puchPara, GU8 *pstTestResult); + +/** + * @fn GU8 Gh3x2xDemoMp_CheckChipIDTest(GU8 *puchPara, GU8 *puchTestResult) + * + * @brief GH3x2x MP Check Chip ID Test. + * + * @attention None + * + * @param[in] GU8 *puchPara, GU8 *pushTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_CheckChipIDTest(GU8 *puchPara, GU8 *puchTestResult); + +/** + * @fn GU8 Gh3x2xDemoMp_RstIntTest(GCHAR *para, GCHAR *TestResult) + * + * @brief GH3x2x MP Communication Test. + * + * @attention None + * + * @param[in] GU8 *puchPara, GU8 *pushTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_RstIntTest(GU8 *puchPara, GU8 *pstTestResult); + +/** + * @fn GU8 Gh3x2xDemoMp_EfuseTest(GU8 *puchPara, stGh3x2xMp_EfuseTestResult *pstTestResult) + * + * @brief GH3x2x MP efuse Test, check FT/CP and crc, and get chipUid + * + * @attention None + * + * @param[in] GU8 *puchPara, stGh3x2xMp_EfuseTestResult *pstTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_EfuseTest(GU8 *puchPara, stGh3x2xMp_EfuseTestResult *pstTestResult); + +/** + * @fn GU8 Gh3x2xDemoMp_PPGTest(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief GH3x2x MP PPG Test + * + * @attention None + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_PPGTest(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult); + +/** + * @fn GU8 Gh3x2xDemoMp_ECGTest(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief GH3x2x MP ECG Test + * + * @attention None + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_ECGTest(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + + +#endif /* _GH3X2X_DEMO_MP_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_demo_mp_process.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_demo_mp_process.h new file mode 100644 index 000000000..756327290 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_demo_mp_process.h @@ -0,0 +1,537 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_mp_process.h + * + * @brief header file of gh3x2x_demo_mp_process + * + * @author Goodix Product Tools Development Team + * + */ + +#ifndef _GH3X2X_DEMO_MP_PROCESS_H_ +#define _GH3X2X_DEMO_MP_PROCESS_H_ + +#include "gh3x2x_mp_config.h" +#include "gh3x2x_mp_reg_config.h" +#include "gh3x2x_mp_define.h" + + +/** + * @fn gh3x2x_demo_mp_write_reg(GU16 usReg_Addr, GU16 usReg_Value) + * + * @brief GH3x2x mp write reg + * + * @attention None + * + * @param[in] GU16 usReg_Addr, GU16 usReg_Value + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_write_reg(GU16 usReg_Addr, GU16 usReg_Value); + +/** + * @fn GU16 gh3x2x_demo_mp_read_reg(GU16 usReg_Addr) + * + * @brief GH3x2x mp read reg + * + * @attention None + * + * @param[in] GU16 usReg_Addr + * @param[out] None + * + * @return read reg value + */ +GU16 gh3x2x_demo_mp_read_reg(GU16 usReg_Addr); + +/** + * @fn GU8 gh3x2x_demo_mp_write_regs(GU16 usReg_Addr, GU8 uchRegs_Write[], GU16 usLength) + * + * @brief GH3x2x mp write regs + * + * @attention None + * + * @param[in] GU16 usReg_Addr, GU8 uchRegs_Write[], GU16 usLength + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_write_regs(GU16 usReg_Addr, GU8 uchRegs_Write[], GU16 usLength); + +/** + * @fn GU8 gh3x2x_demo_mp_read_regs(GU16 usReg_Addr, GU8 uchRegs_Read[], GU16 usLength) + * + * @brief GH3x2x mp read regs + * + * @attention None + * + * @param[in] GU16 usReg_Addr, GU16 usLength + * @param[out] GU8 uchRegs_Read[] + * + * @return ret + */ +GU8 gh3x2x_demo_mp_read_regs(GU16 usReg_Addr, GU8 uchRegs_Read[], GU16 usLength); + +/** + * @fn GU8 gh3x2x_demo_mp_write_reg_mask(GU16 usRegAddr, GU16 usMask, GU16 usRegVal) + * + * @brief GH3x2x mp write reg mask + * + * @attention None + * + * @param[in] GU16 usReg_Addr + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_write_reg_mask(GU16 usRegAddr, GU16 usMask, GU16 usRegVal); + +/** + * @fn void gh3x2x_demo_mp_send_cmd(GU8 uchCmd) + * + * @brief send cmd to gh3x2x chip + * + * @attention None + * + * @param[in] GU8 uchCmd + * @param[out] None + * + * @return ret + */ +void gh3x2x_demo_mp_send_cmd(GU8 uchCmd); + +/** + * @fn void gh3x2x_demo_mp_reset_operation(void) + * + * @brief reset gh3x2x chip + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_demo_mp_reset_operation(void); + +/** + * @fn GU8 gh3x2x_demo_mp_wait_for_int(GU16 usDutFlag, GU16 usTimeOut_ms) + * + * @brief wait for int + * + * @attention None + * + * @param[in] GU16 usDutFlag, GU16 usTimeOut + * @param[out] none + * + * @return ret + */ +GU8 gh3x2x_demo_mp_wait_for_int(GU16 usDutFlag, GU16 usTimeOut_ms); + +/** + * @fn GU8 gh3x2x_demo_mp_set_chip_config(const stGh3x2xReg stGh3x2xMpRegConfig[], GU16 usConfigLen) + * + * @brief GH3x2x mp write chip reg config + * + * @attention None + * + * @param[in] const stGh3x2xReg stGh3x2xMpRegConfig[], GU16 usConfigLen + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_chip_config(const stGh3x2xReg stGh3x2xMpRegConfig[], GU16 usConfigLen); + +/** + * @fn GU8 gh3x2x_demo_mp_set_slot_config(stGh3x2xMp_SlotConfig stSlotConfig) + * + * @brief GH3x2x mp set slot config + * + * @attention None + * + * @param[in] stGh3x2xMp_SlotConfig stSlotConfig + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_slot_config(stGh3x2xMp_SlotConfig stSlotConfig); + +/** + * @fn GU8 gh3x2x_demo_mp_set_slot_enable(GU8 uchSlotConfigEnable) + * + * @brief Calculate which slots need to be enabled according to SLOT_CFG_EN, + * @brief enable the corresponding slot, and output the number of enabled slots + * + * @attention None + * + * @param[in] GU8 uchSlotConfigEnable + * @param[out] GU8 *uchSlotEnableNum + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_slot_enable(GU8 uchSlotConfigEnable, GU8 *uchSlotEnableNum); + +/** + * @fn GU8 gh3x2x_demo_mp_set_LED_ACG_cfg(GU8 uchLED_N, GU8 uchLED_ACG_FS, stGh3x2xMp_PPGTestParam *pstTestPara) + * + * @brief The automatic dimming test needs to adjust the LED driver gear to avoid the failure of the automatic dimming step by too large + * + * @attention None + * + * @param[in] GU8 uchSlotConfigEnable + * @param[out] GU8 *uchSlotEnableNum + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_LED_ACG_cfg(GU8 uchLED_N, GU8 uchLED_ACG_FS, stGh3x2xMp_PPGTestParam *pstTestPara); + +/** + * @fn void gh3x2x_demo_mp_sampling_mode(GU8 uchMode) + * + * @brief rawdata sampling start / stop + * + * @attention None + * + * @param[in] GU8 uchMode + * @param[out] + * + * @return None + */ +void gh3x2x_demo_mp_sampling_mode(GU8 uchMode); + +/** + * @fn GU8 gh3x2x_demo_mp_get_rawdata(GU16 uchRegAddr, GU8 uchRawdataArr[], GU32 usLength) + * + * @brief get rawdata + * + * @attention None + * + * @param[in] GU16 uchRegAddr, GU32 usLength + * @param[out] GU8 uchRawdataArr[] + * + * @return ret + */ +GU8 gh3x2x_demo_mp_get_rawdata(GU16 uchRegAddr, GU8 uchRawdataArr[], GU32 usLength); + +/** + * @fn GU8 gh3x2x_demo_mp_handle_rawdata(GU8 uchMode, GS32 nHandleRawdataArr[], GU32 unHandleRawdataSkipLength, GU8 uchSlot_N, GU8 uchADC_N, \ + GU8 uchRawdataArr[], GU32 unRawdataArrLength, GU8 uchSampleStep) + * + * @brief handle rawdata + * + * @attention None + * + * @param[in] GU8 uchMode, GU32 unHandleRawdataSkipLength, GU8 uchSlot_N, GU8 uchADC_N, GU8 uchRawdataArr[], GU32 unRawdataArrLength, GU8 uchSampleStep + * @param[out] GS32 nHandleRawdataArr[] + * + * @return ret + */ +GU8 gh3x2x_demo_mp_handle_rawdata(GU8 uchMode, GS32 nHandleRawdataArr[], GU32 unHandleRawdataSkipLength, GU8 uchSlot_N, GU8 uchADC_N, \ + GU8 uchRawdataArr[], GU32 unRawdataArrLength, GU8 uchSampleStep); + +/** + * @fn gh3x2x_demo_mp_ppg_get_rawdata(GU8 uchMode, GU32 uchRawdataArr[][MAX_ADC_NUM][MAX_PPG_RAWDATA_SAMPLE_NUM], GU16 usRawdataLen, GU16 usRawdataSkipLen, GU16 usLED_PD_Num) + * + * @brief ppg test get rawdata + * + * @attention None + * + * @param[in] GU16 usRawdataLen, GU16 usRawdataSkipLen, GU16 usLED_PD_Num + * @param[out] GU32 unRawdataArr[][MAX_ADC_NUM][MAX_PPG_RAWDATA_SAMPLE_NUM] + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ppg_get_rawdata(GS32 unRawdataArr[][MAX_ADC_NUM][MAX_PPG_RAWDATA_SAMPLE_NUM], GU16 usRawdataLen, GU16 usRawdataSkipLen, GU16 usLED_PD_Num); + +/** + * @fn void gh3x2x_demo_mp_calc_noise(GS32 nRawdataArr[], GU16 usLength, GF32 *fAvergeRawdata, GF32 *fNoise) + * + * @brief cal noise + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength + * @param[out] GF32 *fAvergeRawdata, GF32 *fNoise + * + * @return none + */ +void gh3x2x_demo_mp_calc_noise(GS32 nRawdataArr[], GU16 usLength, GF32 *fAvergeRawdata, GF32 *fNoise); + +/** + * @fn GF32 gh3x2x_demo_mp_calc_LPCTR(GF32 fAverageRawdata, GU32 unTIA, GU32 unILed) + * + * @brief cal LP CTR + * + * @attention None + * + * @param[in] GF32 fAverageRawdata, GU32 unTIA, GU32 unILed + * @param[out] + * + * @return CTR + */ +GF32 gh3x2x_demo_mp_calc_LPCTR(GF32 fAverageRawdata, GU32 unTIA, GU32 unILed); + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_signal_filter(GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType) + * + * @brief ECG signal filter + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType + uchLpType:Low pass filter cut-off frequency + uchHpType:High pass filter cut-off frequency + uchFsType:Sampling rate of rawdata,0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + * @param[out] GS32 nRawdataArr[]: filter data + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_signal_filter(GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType); + +/** + * @fn GF32 gh3x2x_demo_mp_ecg_cal_HPF_Ratio(GS32 nRawdataArr[], GU16 usLength) + * + * @brief cal HPF amplitude ratio + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength + * @param[out] + * + * @return HPF_Ratio + */ +GF32 gh3x2x_demo_mp_ecg_cal_HPF_Ratio(GS32 nRawdataArr[], GU16 usLength); + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_cal_signal_amp_freq(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GF32 *fFreq, \ + GU8 uchLpType, GU8 uchHpType, GU8 uchFsType, GS16 sCalStart, GS16 sCalEnd, GF32 fRefFreq, GU8 uchStep) + * + * @brief Cal the amplitude and frequency of the signal + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType, GS16 sCalStart, GS16 sCalEnd, GF32 fRefFreq, GU8 uchStep + nRawdataArr:Data to be processed + usLength:Data len + uchLpType:Low pass filter cut-off frequency + uchHpType:High pass filter cut-off frequency + uchFsType:Sampling rate type of rawdata, 0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + sCalStart:FFT start begin point + sCalEnd:FFT start end point + fRefFreq:For reference frequency, find the maximum value near fref±5hz; if <0, find the maximum value between 0.1hz~fs/2 + * @param[out] GF32 *fAmp, GF32 *fFreq + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_cal_signal_amp_freq(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GF32 *fFreq, GU8 uchLpType, \ + GU8 uchHpType, GU8 uchFsType, GS16 sCalStart, GS16 sCalEnd, GF32 fRefFreq, GU8 uchStep); + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_cmmr_calculate(GS32 nRawdataArr[], GU16 usLength, GF32 *fCmmr, GU8 uchFsType, GF32 fRefFreq) + * + * @brief Cal the ecg-cmmr + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GU8 uchFsType, GF32 fRefFreq + nRawdataArr:Data to be processed + usLength:Data len + uchFsType:Sampling rate type of rawdata, 0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + fRefFreq:For reference frequency, find the maximum value near fref±5hz; if <0, find the maximum value between 0.1hz~fs/2 + * @param[out] GF32 *fCmmr + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_cmmr_calculate(GS32 nRawdataArr[], GU16 usLength, GF32 *fCmmr, GU8 uchFsType, GF32 fRefFreq); + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_cal_signal_WaveTimeDomin_Amp(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GU8 uchFsType, GF32 fRefFreq) + * + * @brief Cal ecg-DCRange WaveTimeDomin Amp + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GU8 uchFsType, GF32 fRefFreq + nRawdataArr:Data to be processed + usLength:Data len + uchFsType:Sampling rate type of rawdata, 0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + fRefFreq: Reference frequency + * @param[out] GF32 *fAmp + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_cal_signal_WaveTimeDomin_Amp(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GU8 uchFsType, GF32 fRefFreq); + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_LPCTR_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ---- LP CTR test + * + * @attention None + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_PPG_LPCTR_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_Noise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ---- noise test + * + * @attention PPG Noise test requires automatic dimming. + * @attention It is not possible to test all leds in parallel using multi-channel mode, only serial test + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_PPG_Noise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_BaseNoise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ----base noise test + * + * @attention base noise test has nothing to do with LEDs, so only one slot is needed to test the data of 4 PDs. + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_PPG_BaseNoise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_LeakLight_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ----leak light test + * + * @attention + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_PPG_LeakLight_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_LeadOnOff_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----Lead on/off test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_LeadOnOff_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_Noise_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----Noise test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_Noise_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_HPF_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----HPF test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_HPF_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_SIGNAL_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----SIGNAL test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_SIGNAL_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_RLD_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----RLD test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_RLD_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_CMRR_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----CMRR test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_CMRR_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_LIN_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----LIN test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_LIN_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_DCRange_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----DCRange test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_DCRange_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult); + +#endif /* _GH3X2X_DEMO_MP_PROCESS_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_algorithm.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_algorithm.h new file mode 100644 index 000000000..59d1bdb7b --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_algorithm.h @@ -0,0 +1,184 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_algorithm.h + * + * @brief header file of gh3x2x_mp_algorithm + * + * @author Goodix Product Tools Development Team + * + */ + +#ifndef _GH3X2X_MP_ALGORITHM_H_ +#define _GH3X2X_MP_ALGORITHM_H_ + +#include "gh3x2x_mp_config.h" +#include "gh3x2x_mp_define.h" + +//IIR struct +typedef struct +{ + GS32 stages; + const GD64(*sos)[6]; + const GD64 *gain; + double x[8][3]; + double y[8][2]; +}IIR_State_Def; + + +/** + * @fn GU8 gh3x2x_mp_crc_cal(GU8 *puchData, GU32 unLen) + * + * @brief GH3x2x mp start test + * + * @attention None + * + * @param[in] none + * @param[out] None + * + * @return CRC + */ +GU8 gh3x2x_mp_crc_cal(GU8 *puchData, GU32 unLen); + +/** + * @fn GD64 gh3x2x_mp_high_pass_filter(GD64 fData) + * + * @brief GH3x2x mp high-pass filter + * + * @attention None + * + * @param[in] GD64 fData + * @param[out] None + * + * @return Filtered data + */ +GD64 gh3x2x_mp_high_pass_filter(GD64 fData); + +/** + * @fn GU8 gh3x2x_mp_ecg_lead_off_dectection(GS32 nRawdataArr[], GU16 usRawdataLen, GU8 uchECGChannel_N, GU16 *usReSampleData_Len) + * + * @brief dectect ecg lead off algorithm + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usRawdataLen, GU8 uchECGChannel_N, GU16 usReSampleData_Len + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_mp_ecg_lead_off_dectection(GS32 nRawdataArr[], GU16 usRawdataLen, GU8 uchECGChannel_N, GU16 *usReSampleData_Len); + +/** + * @fn GD64 gh3x2x_mp_signal_IIR_filter(IIR_State_Def *stIIR_State, GD64 dData) + * + * @brief GH3x2x mp signal IIR filter + * + * @attention None + * + * @param[in] IIR_State_Def *stIIR_State, GD64 dData + * @param[out] None + * + * @return Filtered data + */ +GD64 gh3x2x_mp_signal_IIR_filter(IIR_State_Def *stIIR_State, GD64 dData); + +/** + * @fn void gh3x2x_mp_signal_filter(GS32 nFilterArr[], GU16 usLength, GU8 uchHpType, GU8 uchLpType, GU8 uchFsType) + * + * @brief GH3x2x mp signal hp and lp filter for ecg + * + * @attention None + * + * @param[in] GS32 nFilterArr[], GU16 usLength, GU8 uchHpType, GU8 uchLpType, GU8 uchFsType + uchLpType:Low pass filter cut-off frequency + uchHpType:High pass filter cut-off frequency + uchFsType:Sampling rate of rawdata + * @param[out] GS32 nFilterArr[] + * + * @return None + */ +void gh3x2x_mp_signal_filter(GS32 nFilterArr[], GU16 usLength, GU8 uchHpType, GU8 uchLpType, GU8 uchFsType); + +/** + * @fn gh3x2x_mp_signal_fft(GS32 nFFT_InArr[], GS32 nFFT_OutArr[], GU32 unLength, GU32 step) + * + * @brief fft + * + * @attention None + * + * @param[in] GD64 dFFT_InArr[], GS32 nFFT_OutArr[], GU32 unLength, GU32 step + * @param[out] GD64 dFFTArr[] + * + * @return ret + */ +void gh3x2x_mp_signal_fft(GF32 nFFT_InArr[], GF32 nFFT_OutArr[], GU32 unLength, GU32 unStep); + +/** + * @fn void gh3x2x_mp_signal_quick_fft(GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], GU32 unLength, GU32 unPower_2, \ + GF32 fFFTOutArr_real[], GF32 fFFTOutArr_image[], GU8 uchFFTMode, GU32 uchCalModulus_Angle) + * + * @brief more quick do fft process + * + * @attention None + * + * @param[in] GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], GU32 unLength, GU32 unPower_2, GU8 uchFFTMode, GU32 uchCalModulus_Angle + uchFFTMode: 0, Fourier transform; 1, inverse Fourier transform + uchCalModulus_Angle: 0, do not calculate Fourier transform or inverse transform mode and amplitude Angle;1, calculate the modulus and amplitude Angle + unLength: the number of points entered, which is an even number, is generally 32,64,128...1024, etc. + unPower_2: satisfy n=2^unPower_2(unPower_2>0) + fFFTInArr_real: 0,store the real part of the sampled data at N points; 1,store N real parts of the Fourier transform + fFFTInArr_image: 0,store the imaginary part of the sampled data at N points; 1,store N imaginary parts of the Fourier transform + + * @param[out] GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], + fFFTOutArr_real: uchFFTMode=0, return the real part of the Fourier transform + uchFFTMode=1, return the real part of the inverse Fourier transform + fFFTOutArr_image:uchFFTMode=0, return the imaginary part of the Fourier transform + uchFFTMode=1, return the imaginary part of the inverse Fourier transform + fFFTInArr_real: uchCalModulus_Angle = 1, uchFFTMode = 0, return the modulus of Fourier transform + uchCalModulus_Angle = 1, uchFFTMode = 1, return the inverse Fourier transform modulus + fFFTInArr_image:uchCalModulus_Angle = 1, uchFFTMode = 0, return the amplitude Angle of the Fourier transform + uchCalModulus_Angle = 1, uchFFTMode = 1, return the amplitude Angle of the inverse Fourier transform + * + * @return none + */ +void gh3x2x_mp_signal_quick_fft(GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], GU32 unLength, GU32 unPower_2, \ + GF32 fFFTOutArr_real[], GF32 fFFTOutArr_image[], GU8 uchFFTMode, GU32 uchCalModulus_Angle); + +/** + * @fn GU8 gh3x2x_mp_signal_fft_process(GS32 nFFTArr[] GU32 unLength) + * + * @brief Perform FFT transformation on the data and then calculate the power spectrum + * + * @attention None + * + * @param[in] GS32 nFFTArr[], GU32 unLength + * @param[out] GS32 nFFTArr[] + * + * @return ret + */ +GU8 gh3x2x_mp_signal_fft_process(GF32 nFFTArr[], GU32 unLength); + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_fft_cal_amp_freq(GF32 fRawdataArr[], GU16 usLength, GU32 unFFTLength, GU32 unSampleRate, GF32 *fAmp, GF32 *fFreq, \ + GF32 fRefFreq, GU8 uchWintype) + * + * @brief cal amp and freq after fft + * + * @attention None + * + * @param[in] GF32 fRawdataArr[], GU16 usLength, GU32 unFFTLength, GU32 unSampleRate, GU8 uchWintype, GF32 fRefFreq + unSampleRate: Sampling frequency + winType:Window type, 0: rectangular window; 1: flattop window, used to accurately estimate the amplitude; 2: hanning window + fRefFreq:For reference frequency, find the maximum value near fref±5hz; if <0, find the maximum value between 0.1hz~fs/2 + * @param[out] GF32 *fAmp, GF32 *fFreq + fAmp: peak-to-peak value + fFreq:freq, unit Hz + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_fft_cal_amp_freq(GF32 fRawdataArr[], GU16 usLength, GU32 unFFTLength, GU32 unSampleRate, GF32 *fAmp, GF32 *fFreq, \ + GF32 fRefFreq, GU8 uchWintype); + +#endif /* _GH3X2X_MP_ALGORITHM_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_common.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_common.h new file mode 100644 index 000000000..a49044e2f --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_common.h @@ -0,0 +1,459 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_common.h + * + * @brief header file of gh3x2x mp test common port + * + * @author Goodix Product Tools Development Team + * + */ + +#ifndef _GH3X2X_MP_COMMON_H_ +#define _GH3X2X_MP_COMMON_H_ + +#include "gh3x2x_mp_config.h" +#include "gh3x2x_mp_define.h" +#include + +#if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + #include "gh_demo_inner.h" + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + #include "gh3x2x_afe_drv.h" + #endif + +#endif + +#if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) +#define GH3X2X_MP_DRV_LIB_LOG(...) do{\ + if(g_pSnprintfUserIn)\ + {\ + char gh3x2x_GH3X2X_INFO_LOG[GH3X2X_INFO_LOG_MAX_LEN] = {0};\ + g_pSnprintfUserIn(gh3x2x_GH3X2X_INFO_LOG, GH3X2X_INFO_LOG_MAX_LEN, __VA_ARGS__);\ + GH3X2X_PlatformLog((GCHAR *)gh3x2x_GH3X2X_INFO_LOG);\ + }\ + if(g_pPrintfUserIn)g_pPrintfUserIn(__VA_ARGS__);\ + } while(0) + + +#define GH3X2X_MP_LOG_L1_INNER(...) GH3X2X_MP_DRV_LIB_LOG("[gh3x2x mp error]: "__VA_ARGS__) +#define GH3X2X_MP_LOG_L2_INNER(...) GH3X2X_MP_DRV_LIB_LOG("[gh3x2x mp info]: "__VA_ARGS__) +#define GH3X2X_MP_LOG_INNER(...) GH3X2X_MP_DRV_LIB_LOG(__VA_ARGS__) + + +#else +#define GH3X2X_MP_AFE_LOG(...) do {\ + char gh3x2x_log_string[GH3X2X_MP_LOG_MAX_LEN] = {0};\ + snprintf(gh3x2x_log_string, GH3X2X_MP_LOG_MAX_LEN, __VA_ARGS__);\ + gh3x2x_mp_log((GCHAR *)gh3x2x_log_string);\ + } while(0) + + + +#define GH3X2X_MP_LOG_L1_INNER(...) GH3X2X_MP_AFE_LOG("[gh3x2x mp error]: "__VA_ARGS__) +#define GH3X2X_MP_LOG_L2_INNER(...) GH3X2X_MP_AFE_LOG("[gh3x2x mp info]: "__VA_ARGS__) +#define GH3X2X_MP_LOG_INNER(...) GH3X2X_MP_AFE_LOG(__VA_ARGS__) + + +#endif + + + + + + + + + + + +/* log def*/ +#if (__GH3X2X_MP_LOG_LVL__) //log level, =0 not print log + + #define GH3X2X_MP_LOG_L1(...) GH3X2X_MP_LOG_L1_INNER(__VA_ARGS__) + #if(__GH3X2X_MP_LOG_LVL__ > 1) + #define GH3X2X_MP_LOG_L2(...) GH3X2X_MP_LOG_L2_INNER(__VA_ARGS__) + #else + #define GH3X2X_MP_LOG_L2(...) + #endif + +#else //log level == 0, not print log + #define GH3X2X_MP_LOG_L1(...) + #define GH3X2X_MP_LOG_L2(...) +#endif + +#define GH3X2X_MP_LOG(...) GH3X2X_MP_LOG_INNER(__VA_ARGS__) + +extern GU8 GH3x2xMp_IntFlag; //use for mp +#define GH3X2X_MP_SET_INT_FLAG() {GH3x2xMp_IntFlag = 1;} + +#ifdef GOODIX_DEMO_MP_PLANFORM +#include "gh3x2x_demo_mp_goodix_platform.h" +#else +#define GOODIX_MP_PLATFORM_I2C_INIT_ENTITY() +#define GOODIX_MP_PLATFORM_I2C_WRITE_ENTITY(device_id, write_buffer, length) +#define GOODIX_MP_PLATFORM_I2C_READ_ENTITY(device_id, write_buffer, write_length, read_buffer, read_length) +#define GOODIX_MP_PLATFORM_I2C_SEND_CMD_ENTITY(device_id, uchCmd) +#define GOODIX_MP_PLATFORM_SPI_INIT_ENTITY() +#define GOODIX_MP_PLATFORM_SPI_WRITE_ENTITY(write_buffer, length) +#define GOODIX_MP_PLATFORM_SPI_READ_ENTITY(uchWriteBuffer, usWriteLength, uchReadBuffer, usReadLength) +#define GOODIX_MP_PLATFORM_SPI_SEND_CMD_ENTITY(uchCmd) +#define GOODIX_MP_PLATFORM_RESET_PIN_INIT_ENTITY() +#define GOODIX_MP_PLATFORM_RESET_PIN_CTRL_ENTITY(pin_level) +#define GOODIX_MP_PLATFORM_INT_INIT_ENTITY() +#define GOODIX_MP_PLATFORM_INT_HANDLER_CALL_BACK_ENTITY() +#define GOODIX_MP_PLATFORM_LED_POWER_PIN_INIT_ENTITY() +#define GOODIX_MP_PLATFORM_LED_POWER_ON_ENTITY() +#define GOODIX_MP_PLATFORM_LED_POWER_OFF_ENTITY() +#define GOODIX_MP_PLATFORM_PROMPT_UP_RUBBER_ENTITY() +#define GOODIX_MP_PLATFORM_PROMPT_TEST_OK_ENTITY() +#define GOODIX_MP_PLATFORM_PROMPT_TEST_NG_ENTITY() +#define GOODIX_MP_PLATFORM_ECG_UART_SEND_ENTITY(uchSendBuffer, usLength) 1 +#define GOODIX_MP_PLATFORM_ECG_UART_RECEIVE_ENTITY(uchRevBuffer, usTimeout_ms) 1 +#define GOODIX_MP_PLATFORM_ECG_SIGNAL_AND_IO_STATUS_SET_ENTITY(emECG_Status, stECGSignalSetting, uchSpec) 1 +#define GOODIX_MP_PLATFORM_LOG_ENTITY(log_string) +#define GOODIX_MP_PLATFORM_DELAY_US_ENTITY(usUsec) +#define GOODIX_MP_PLATFORM_DELAY_MS_ENTITY(usMsec) + + +#endif + +/* i2c interface */ +/** + * @fn void gh3x2x_mp_i2c_init(void) + * + * @brief i2c init for gh3x2x mp + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_i2c_init(void); + +/** + * @fn GU8 gh3x2x_mp_i2c_write(GU8 device_id, const GU8 write_buffer[], GU16 length) + * + * @brief i2c write for gh3x2x mp + * + * @attention + * + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_i2c_write(GU8 device_id, const GU8 write_buffer[], GU16 length); + +/** + * @fn uint8_t gh3x2x_mp_i2c_read(uint8_t device_id, const uint8_t write_buffer[], uint16_t write_length, + * uint8_t read_buffer[], uint16_t read_length) + * + * @brief i2c read for gh3x2x mp + * + * @attention + * + * @param[in] device_id device addr + * @param[in] write_buffer write data buffer + * @param[in] write_length write data len + * @param[in] read_length read data len + * @param[out] read_buffer pointer to read buffer + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_i2c_read(GU8 device_id, const GU8 write_buffer[], GU16 write_length, GU8 read_buffer[], GU16 read_length); + +/** + * @fn GU8 gh3x2x_mp_i2c_send_cmd(GU8 device_id, GU8 uchCmd) + * + * @brief i2c send cmd to gh3x2x mp + * + * @attention + * + * @param[in] GU8 device_id, GU8 uchCmd + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_i2c_send_cmd(GU8 device_id, GU8 uchCmd); + +/* spi interface */ +/** + * @fn void gh3x2x_mp_spi_init(void) + * + * @brief spi init for gh3x2x mp + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_spi_init(void); + +/** + * @fn GU8 gh3x2x_mp_spi_write(GU8 write_buffer[], GU16 length) + * + * @brief spi write for gh3x2x mp + * + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_spi_write(GU8 write_buffer[], GU16 length); + +/** + * @fn GU8 gh3x2x_mp_spi_read(GU8 uchWriteBuffer[], GU16 usWriteLength, GU8 uchReadBuffer[], GU16 usReadLength) + * + * @brief spi read for gh3x2x mp + * + * @attention + * + * @param[in] GU8 uchWriteBuffer[], GU16 usWriteLength + * @param[out] GU8 uchReadBuffer[], GU16 usReadLength + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_spi_read(GU8 uchWriteBuffer[], GU16 usWriteLength, GU8 uchReadBuffer[], GU16 usReadLength); + +/** + * @fn GU8 gh3x2x_mp_spi_send_cmd(GU8 uchCmd) + * + * @brief spi send cmd to gh3x2x + * + * @attention + * + * @param[in] GU8 uchCmd + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_spi_send_cmd(GU8 uchCmd); + +/** + * @fn void gh3x2x_mp_reset_pin_init(void) + * + * @brief reset pin init for gh3x2x mp + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_reset_pin_init(void); + +/** + * @fn void gh3x2x_mp_reset_pin_ctrl(GU8 pin_level) + * + * @brief hal reset pin ctrl for gh3x2x + * + * @attention pin level set 1 [high level] or 0 [low level] + * + * @param[in] pin_level reset pin level + * @param[out] None + * + * @return None + */ + +void gh3x2x_mp_reset_pin_ctrl(GU8 pin_level); + + +/** + * @fn void gh3x2x_mp_int_init(void) + * + * @brief gh3x2x int init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_int_init(void); + +/** + * @fn void gh3x2x_mp_int_handler_call_back(void) + * + * @brief call back of gh3x2x int handler, mp lib need make GH3x2xMp_IntFlag = 1 + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_int_handler_call_back(void); + +/** + * @fn void gh3x2x_mp_led_power_pin_init(void) + * + * @brief init led power pin + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_led_power_pin_init(void); + +/** + * @fn gh3x2x_mp_led_power_on(void) + * + * @brief led power on + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_led_power_on(void); + +/** + * @fn void gh3x2x_mp_led_power_off(void) + * + * @brief led power off + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_led_power_off(void); + +/** + * @fn GU8 gh3x2x_mp_ecg_uart_send(GU8 uchSendBuffer[], GU16 usLength) + * + * @brief Communicates with the ECG signal generator board through uart + * + * @attention None + * + * @param[in] GU8 uchSendBuffer[], GU16 usLength + + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_mp_ecg_uart_send(GU8 uchSendBuffer[], GU16 usLength); + +/** + * @fn GU8 gh3x2x_mp_ecg_uart_receive(GU8 uchRevBuffer[], GU16 Timeout_ms) + * + * @brief Communicates with the ECG signal generator board through uart + * + * @attention None + * + * @param[in] GU8 uchRevBuffer[], GU16 Timeout_ms + + * @param[out] None + * + * @return usLength: The length of the data rev + */ +GU16 gh3x2x_mp_ecg_uart_receive(GU8 uchRevBuffer[], GU16 usTimeout_ms); + + +/** + * @fn GU8 gh3x2x_mp_ecg_signal_and_io_status_set(emECG_SIGNAL_AND_IO_STATUS_SET emECG_Status, stGh3x2xMp_ECGSignalSetting stECGSignalSetting, emECG_SET_SIGNAL_SPEC uchSpec) + * + * @brief Set ECG signal and IO status according to ECG test item + * + * @attention + * + * @param[in] emECG_SIGNAL_AND_IO_STATUS_SET emECG_Status, stGh3x2xMp_ECGSignalSetting stECGSignalSetting, emECG_SET_SIGNAL_SPEC uchSpec + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_mp_ecg_signal_and_io_status_set(emECG_SIGNAL_AND_IO_STATUS_SET emECG_Status, stGh3x2xMp_ECGSignalSetting stECGSignalSetting, emECG_SET_SIGNAL_SPEC uchSpec); + +/** + * @fn void gh3x2x_mp_prompt_message(GU8 uchMsg[], GU16 usMsglen) + * + * @brief prompt message to do something + * + * @attention None + * + * @param[in] GU8 uchMsg, GU16 usMsglen + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_prompt_message(GU8 uchMsg[], GU16 usMsglen); + +/** + * @fn void gh3x2x_mp_log(char *log_string) + * + * @brief for print mp log + * + * @attention this function must define that print mp test log + * + * @param[in] log_string pointer to log string + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_log(GCHAR *log_string); + +/** + * @fn void gh3x2x_mp_delay_us(GU16 usUsec) + * + * @brief Delay in us,user must register this function + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ + +void gh3x2x_mp_delay_us(GU16 usUsec); + + +/** + * @fn void Gh3x2x_mp_delay_ms(GU16 usMsec) + * + * @brief Delay in ms + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_delay_ms(GU16 usMsec); + + + +#endif /* _GH3X2X_MP_COMMON_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_config.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_config.h new file mode 100644 index 000000000..d886fc6fd --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_config.h @@ -0,0 +1,86 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-06-25 13:57:13 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-06-25 15:52:04 + * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_config.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_config.h + * + * @brief header file of gh3x2x_mp_config.c + * + * @author Goodix Product Tools Development Team + * + */ +#include "gh_drv.h" + +#ifndef _GH3X2X_MP_CONFIG_H_ +#define _GH3X2X_MP_CONFIG_H_ + +/* communicate interface macro */ +#define __GH3X2X_MP_INTERFACE_I2C__ (1) /**< interface use i2c >**/ +#define __GH3X2X_MP_INTERFACE_SPI__ (2) /**< interface use spi >**/ + +/* code type type macro */ +#define __GH3X2X_DRV_MODE__ (1) /**< include drv code >**/ +#define __GH3X2X_MP_MODE_ (0) /**< just mp code >**/ + +/* drv interface type macro */ +#define __GH3X2X_DRV_LIB_INTERFACE__ (1) /**< mp test use drv lib interface >**/ +#define __GH3X2X_AFE_DRV_INTERFACE__ (2) /**< mp test use afe drv interface >**/ + +/* type redefine */ +// typedef unsigned char GU8; /**< 8bit unsigned integer type */ +// typedef signed char GS8; /**< 8bit signed integer type */ +// typedef unsigned short GU16; /**< 16bit unsigned integer type */ +// typedef signed short GS16; /**< 16bit signed integer type */ +// typedef int GS32; /**< 32bit signed integer type */ +// typedef unsigned int GU32; /**< 32bit unsigned integer type */ +// typedef float GF32; /**< float type */ +// typedef double GD64; /**< double type */ +// typedef char GCHAR; /**< char type */ +// typedef unsigned char GBOOL; /**< bool type */ +// typedef long long GS64; /**< 64bit signed integer type */ + + +//config +#define __GH3X2X_MP_USE_DRV_INTERFACE__ (__GH3X2X_DRV_MODE__) /**< use drv or mp iterface define, 0:use mp lib interface i2c/spi, 1:use drv interface i2c/spi >**/ + +#if(__GH3X2X_MP_USE_DRV_INTERFACE__) +#define __GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ (__GH3X2X_DRV_LIB_INTERFACE__) /**< drv interface config __GH3X2X_DRV_LIB_INTERFACE__ /__GH3X2X_AFE_DRV_INTERFACE__ >**/ +#else +#define __GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ (0) /**< drv interface config __GH3X2X_DRV_LIB_INTERFACE__ /__GH3X2X_AFE_DRV_INTERFACE__ >**/ +#endif + +#define __GH3X2X_MP_INTERFACE__ (__GH3X2X_MP_INTERFACE_SPI__) /**< interface config __GH3X2X_MP_INTERFACE_I2C__ /__GH3X2X_MP_INTERFACE_SPI__ >**/ + +#define __GH3X2X_MP_LOG_LVL__ (2) /**< gh3x2x mp log level, <==0>off, <==1>error log, <==2>info log >**/ + +#define __GH3X2X_MP_PRINT_RAWDATA__ (0) /**< 0:close print rawdata, 1:open print rawdata >**/ +#define __GH3X2X_MP_PRINT_TEST_RESULT__ (1) /**< 0:close print test result, 1:open print test result >**/ + +#define GH3X2X_MP_LOG_MAX_LEN (256) /**< gh3x2x mp log max len >**/ + +#define MAX_PPG_RAWDATA_SAMPLE_NUM (550) /**< ppg max rawdata sample, not more than MAX_RAWDATA_SAMPLE_NUM >**/ +#define MAX_RAWDATA_SAMPLE_NUM (4096) /**< ECG max rawdata sample >**/ +#define MAX_FFT_LENGTH (4096) /**< ECG FFT process data max length, must(MAX_FFT_LENGTH*2*4) < (RAWDATA_BUF_SIZE / 2) >**/ + +/*********************************** DO NOT MODIFY FOLLOWING CODE *******************************/ + +#ifdef GOODIX_DEMO_PLATFORM +#undef __GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ +#define __GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ (__GH3X2X_DRV_LIB_INTERFACE__) +#endif + +#ifdef GH3X2X_AFE_DRV_CODE +#undef __GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ +#define __GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ (__GH3X2X_AFE_DRV_INTERFACE__) +#endif + +#endif /* _GH3X2X_MP_CONFIG_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_define.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_define.h new file mode 100644 index 000000000..8861aee8c --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_define.h @@ -0,0 +1,297 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_define.h + * + * @brief define test items para, error code and so on + * + * @author Goodix Product Tools Development Team + * + */ + +#ifndef _GH3X2X_MP_DEFINE_H_ +#define _GH3X2X_MP_DEFINE_H_ + +#include "gh3x2x_mp_config.h" + +/*******GH3x2x test fw version define************/ +#define GH3X2X_MP_LIB_VERSION ("GH3x2x_MP_Lib_V1.0.0.0.0") +/***END****GH3x2x test fw version define*********/ + +/*******test error code define************/ +#define MT_TEST_PASS 0x00 + +#define MT_ERROR_COMMUNICATION_TEST_ERROR 0x01 +#define MT_ERROR_EFUSE_ERROR 0x04 +#define MT_ERROR_LP_NOISE_ABNORMAL 0x07 +#define MT_ERROR_LPBASE_NOISE_ABNORMAL 0x08 +#define MT_ERROR_LPBASE_DC_OFFSET_ABNORMAL 0x09 +#define MT_ERROR_LED_LP_RAWDATA_ABNORMAL 0x10 + +#define MT_ERROR_LEAK_LEDLP_RAWDATA_ABNORMAL 0x30 +#define MT_ERROR_LEAK_AVGER_ERR 0x40 + +#define MT_ERROR_COMMUNICATE_FAIL 0x18 +#define MT_ERROR_CHECK_CHIPID_ERROR 0x20 + +#define MT_ERROR_ECG_LEADONOFF_ERR 0x60 +#define MT_ERROR_ECG_NOISE_ERR 0x61 +#define MT_ERROR_ECG_HPF_ERR 0x62 +#define MT_ERROR_ECG_SIGNAL_ERR 0x63 +#define MT_ERROR_ECG_CMMR_ERR 0x64 +#define MT_ERROR_ECG_RLD_ERR 0x65 +#define MT_ERROR_ECG_LIN_ERR 0x66 +#define MT_ERROR_ECG_DCRANGE_ERR 0x67 +/***END****test error code define*********/ + + +/*******test cmd define************/ +#define GH3X2X_MP_CMD_RESUME (0xC3) //chip resume cmd +/***END****test cmd define*********/ + + +/*******test related information define************/ +#define READ_RAWDATA_FIFO_MAX_BYTE_NUM 3200 +#define RAWDATA_BUF_SIZE MAX_SLOT_NUM*MAX_ADC_NUM*MAX_PPG_RAWDATA_SAMPLE_NUM*4 + + +#define GH3X2X_DEMO_MP_EFUSE_MAX_LEN 32 +#define CHIP_UID_LENGTH 12 + +#define START_SAMPLING 0 +#define STOP_SAMPLING 1 + +#define MAX_SLOT_NUM 8 +#define MAX_LED_NUM 8 +#define MAX_ADC_NUM 4 + +#define SPEC_MODE_PPG 0 +#define SPEC_MODE_ECG 1 + +#define SLOT_ONECH_MODE 0 //Using single-channel mode, only one PD is collected per slot +#define SLOT_MULTICH_MODE 1 //Using multi-channel mode, each slot can collect multiple PDs, but does not support automatic dimming +#define SLOT_CFG_INDEX 0x1C //Each slot register address offset + +#define ADC_OFFSET 8388608 +#define RAWDATA_TO_VOL(x) ((x)*1.8*1000000 / ADC_OFFSET) //rawdata to voltage value, unit uV +#define ADC_MAX (GF32)(0x800000) // ADC full offset value +#define ADC_REFER 1800.0f // ADC reference voltage +#define GAIN 20.0f // System gain + +#define LED_POWER_OFF 0 +#define LED_POWER_ON 1 + +#define LED0_LLPRAWDATA_INDEX 32 + +#define ECG_MAX_SIGNAL_NUM 5 +#define ECGBOARD_DAC_CHANNELA 0x01 +#define ECGBOARD_DAC_CHANNELB 0x08 +#define UART_CMD_GETADC 0x13 +/***END****test related information define*********/ + +/*******test prompt message define************/ +#define PPG_PROMPT_UP_RUBBER_MSG "Please up the Rubber!" +#define GH3X2X_MP_TEST_OK_MSG "Gh3x2x mp test is OK!" +#define GH3X2X_MP_TEST_NG_MSG "Gh3x2x mp test is NG!" +/***END****test prompt message define*********/ + + +/*******test param define************/ +//define gh3x2x mp slot config struct +typedef struct +{ + GU8 Slot_Cfg_N; //Configure the corresponding slot cfg number + GU8 Slot_Mutiple; //Current slot period multiple + GU8 ADC_N; //ADC number used + GU8 ADC_IntTimes; //ADC integration times + GU8 PD_N; //PD number, can be set to multi-channel, such as PD0|PD1 + GU8 LED_N; //LED number, greater than 8 means not connect any LED + GU8 LED_ACG; //Automatic dimming enable configuration + GU8 LED_Drv; //LED current configuration, this configuration is invalid after turning on automatic dimming + GU8 TIA_RF; //TIA gain resistor configuration + GU8 TIA_CF; //TIA capacitor configuration + GU8 BG_Level; //bg suppression level, 0:only led, 1:1st order amb cancel, 2:2nd order amb cancel, 3:2x 2nd order amb cancel, 4: ECG mode + GU16 Slot_TMR; //Slot running time, unit 1us + GU8 Slot_Mode; //SLOT_MULTICH_MODE or SLOT_ONECH_MODE +}stGh3x2xMp_SlotConfig; + +//LED&PD channel enable config struct +typedef struct{ + GU8 PD_Channel[MAX_LED_NUM]; //PD location to be tested for each slot + GU8 PD_Num[MAX_LED_NUM]; //The number of PDs to be tested for each slot, the maximum is MAX_ADC_NUM + GU8 PD_Channel_AllSlot; //PD positions to be tested for all slots + GU8 PD_Num_AllSlot; //The number of PDs to be tested for all slots, the maximum is MAX_ADC_NUM + GU8 LED_PD_Num; //The number of LED*PD to be tested, the maximum is MAX_ADC_NUM*MAX_LED_NUM + GU8 LED_Channel; //LED location to be tested + GU8 LED_Num; //The number of LEDs to be tested, the maximum is MAX_LED_NUM +}stGh3x2xMp_LEDPDConfig; + + +//define gh3x2x mp PPG test param +typedef struct +{ + GU32 PPG_CTRRawdata_Num; //need get nums, max is MAX_PPG_RAWDATA_SAMPLE_NUM + GU32 PPG_CTRRawdata_SkipNum; //need skip num + GU32 PPG_NoiseRawdata_Num; + GU32 PPG_NoiseRawdata_SkipNum; + GU32 PPG_BaseNoiseRawdata_Num; + GU32 PPG_BaseNoiseRawdata_SkipNum; + GU32 PPG_LeakLightRawdata_Num; + GU32 PPG_LeakLightRawdata_SkipNum; + + //test items slot config + stGh3x2xMp_SlotConfig stCTRSlotConfig; + stGh3x2xMp_SlotConfig stNoiseSlotConfig; + stGh3x2xMp_SlotConfig stBaseNoiseSlotConfig; + stGh3x2xMp_SlotConfig stLeakLightSlotConfig; + + stGh3x2xMp_LEDPDConfig stLEDPDConfig; //LED&PD channel enable config + +}stGh3x2xMp_PPGTestParam; + + +//Set ECG IO status according to ECG test item +typedef enum +{ + ECG_SIGNAL_AND_IO_STATUS_DEFAULT = 0x00, + ECG_SIGNAL_AND_IO_STATUS_LEAD_ON = 0x01, + ECG_SIGNAL_AND_IO_STATUS_LEAD_OFF = 0x02, + ECG_SIGNAL_AND_IO_STATUS_NOISE = 0x03, + ECG_SIGNAL_AND_IO_STATUS_HPF = 0x04, + ECG_SIGNAL_AND_IO_STATUS_SIGNAL = 0x05, + ECG_SIGNAL_AND_IO_STATUS_RLD = 0x06, + ECG_SIGNAL_AND_IO_STATUS_CMMR = 0x07, + ECG_SIGNAL_AND_IO_STATUS_LIN = 0x08, + ECG_SIGNAL_AND_IO_STATUS_DC_RANGE = 0x09, + +}emECG_SIGNAL_AND_IO_STATUS_SET; + +//define Special treatment for ECG items set signal and io status +typedef enum +{ + NONE_SPEC = 0, + ECG_HPF_SPEC = 1, + +}emECG_SET_SIGNAL_SPEC; + +//Set ECG signal type +typedef enum +{ + NONE_MODE = 0, + DC_MODE, + AC_MODE, + ANG_MODE, + +}emECG_Signal_Type; + +//define gh3x2x mp ECG signal struct param +typedef struct +{ + GU16 Rawdata_Num; + GU16 Rawdata_SkipNum; + GU8 Sampling_Step; //rawdata sampling step length, must need > 0 + + GBOOL bECG_NegativeSignal;//Positive or negative signals + GBOOL bECG_HighImpedance;//whether High impedance + GF32 ECG_Freq;//signal freq + GF32 ECG_Vol; //Signal amplitude + GF32 ECG_ACOffset;//AC signal offset + GF32 ECG_DCOffset;//DC signal offset + emECG_Signal_Type ECG_SignalType;//Signal type, sine wave, triangle wave +}stGh3x2xMp_ECGSignalSetting; + +//define gh3x2x mp ECG test param +typedef struct +{ + //test item signal num setting, only setting HPF,SIGNAL,CMRR,LIN and DCRange + GU8 HPF_ECGSignalNum; //must 2 signals in a group + GU8 SIGNAL_ECGSignalNum; + GU8 CMRR_ECGSignalNum; + GU8 LIN_ECGSignalNum; //must 2 signals in a group + GU8 DCRange_ECGSignalNum; //must 3 signals in a group + + //setting HPF,SIGNAL,CMRR,LIN and DCRange signal config + stGh3x2xMp_ECGSignalSetting stECGSignal_HPF[ECG_MAX_SIGNAL_NUM]; //rawdata num need >= 200 + stGh3x2xMp_ECGSignalSetting stECGSignal_SIGNAL[ECG_MAX_SIGNAL_NUM]; + stGh3x2xMp_ECGSignalSetting stECGSignal_CMRR[ECG_MAX_SIGNAL_NUM]; //rawdata num need >= 200 + stGh3x2xMp_ECGSignalSetting stECGSignal_LIN[ECG_MAX_SIGNAL_NUM]; + stGh3x2xMp_ECGSignalSetting stECGSignal_DCRange[ECG_MAX_SIGNAL_NUM]; + + //setting LeadOnOff, Noise and RLD signal config, only need set Rawdata_Num and Rawdata_SkipNum + stGh3x2xMp_ECGSignalSetting stECGSignal_LeadOnOff; + stGh3x2xMp_ECGSignalSetting stECGSignal_Noise; //rawdata num need >= 600 + stGh3x2xMp_ECGSignalSetting stECGSignal_RLD; + +}stGh3x2xMp_ECGTestParam; + +//define gh3x2x mp all test param +typedef struct +{ + //PPG and ECG test param set + stGh3x2xMp_PPGTestParam stPPG_TestParam; + stGh3x2xMp_ECGTestParam stECG_TestParam; + +}stGh3x2xMp_TestParam; +/***END****test param define*********/ + + +/*******test result define************/ +//define gh3x2x mp Efuse test result +typedef struct +{ + GU8 uchChipUid[CHIP_UID_LENGTH]; + +}stGh3x2xMp_EfuseTestResult; + +//define gh3x2x mp rawdata handle data result +typedef struct +{ + GF32 Noise[MAX_LED_NUM*MAX_SLOT_NUM]; + GF32 AvergeRawdata[MAX_LED_NUM*MAX_SLOT_NUM]; + +}stGh3x2xMp_RawdataHandleResult; + +//define gh3x2x mp PPG test result +typedef struct +{ + GF32 LED_Noise[MAX_LED_NUM*MAX_ADC_NUM]; + GF32 LED_BaseNoise[MAX_LED_NUM*MAX_ADC_NUM]; + GF32 LED_LPCTR[MAX_LED_NUM*MAX_ADC_NUM]; + GF32 LED_DCOffset[MAX_LED_NUM*MAX_ADC_NUM]; + GF32 LED_LLPCTR[MAX_LED_NUM*MAX_ADC_NUM]; + GF32 LED_LeakRatio[MAX_LED_NUM*MAX_ADC_NUM]; + + stGh3x2xMp_RawdataHandleResult stCTRRawHandleResult; + stGh3x2xMp_RawdataHandleResult stNoiseRawHandleResult; + stGh3x2xMp_RawdataHandleResult stBaseNoiseRawHandleResult; + stGh3x2xMp_RawdataHandleResult stLeakLightRawHandleResult; + +}stGh3x2xMp_PPGTestResult; + +//define gh3x2x mp ECG test result +typedef struct +{ + GF32 ECG_Noise; + GF32 ECG_HPFRatio[ECG_MAX_SIGNAL_NUM]; + GF32 ECG_Amp[ECG_MAX_SIGNAL_NUM]; + GF32 ECG_Freq[ECG_MAX_SIGNAL_NUM]; + GF32 ECG_RLD; + GF32 ECG_CMRR[ECG_MAX_SIGNAL_NUM]; + GF32 ECG_LIN_Ratio[ECG_MAX_SIGNAL_NUM]; + GF32 ECG_DCRange_Ratio[ECG_MAX_SIGNAL_NUM]; + GF32 ECG_DCRange_Amp[ECG_MAX_SIGNAL_NUM]; + +}stGh3x2xMp_ECGTestResult; + +//define gh3x2x mp all test result +typedef struct +{ + stGh3x2xMp_EfuseTestResult stEfuse_TestResult; + stGh3x2xMp_PPGTestResult stPPG_TestResult; + stGh3x2xMp_ECGTestResult stECG_TestResult; +}stGh3x2xMp_TestResult; +/***END****test result define************/ + +#endif /* _GH3X2X_MP_DEFINE_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_param_config.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_param_config.h new file mode 100644 index 000000000..45a87d021 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_param_config.h @@ -0,0 +1,130 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_param_config.h + * + * @brief header file of gh3x2x_mp_param_config.c + * + * @author Goodix Product Tools Development Team + * + */ +#ifndef _GH3X2X_MP_PARAM_CONFIG_H_ +#define _GH3X2X_MP_PARAM_CONFIG_H_ + +#include "gh3x2x_mp_define.h" + +//define test items select/not select test +typedef enum +{ + SKIP = 0, + TEST = 1, + NG_CONTINUE = 2, +}emMpTestItemStatus; + +//define enable/disable +typedef enum +{ + MP_DISABLE = 0, + MP_ENABLE = 1, +}emMp_Enable; + +//define LED full-scale gear +typedef enum +{ + LED_DRIVE_25MA = 0x00, + LED_DRIVE_50MA = 0x01, + LED_DRIVE_100MA = 0x10, + LED_DRIVE_200MA = 0x11, +}emAutoDimming_Gear; + +//define gh3x2x all test items +typedef struct +{ + //all test items + emMpTestItemStatus COMMUNICATION_TEST; + emMpTestItemStatus CHECK_CHIPID_TEST; + emMpTestItemStatus RST_INT_TEST; + emMpTestItemStatus EFUSE_TEST; + emMpTestItemStatus PPG_TEST; + emMpTestItemStatus ECG_TEST; + +}stMpItemsConfig; + +//define PPG test items +typedef struct +{ + emMpTestItemStatus PPG_LPCTR_TEST; + emMpTestItemStatus PPG_NOISE_TEST; + emMpTestItemStatus PPG_BASENOISE_TEST; + emMpTestItemStatus PPG_LEAKLIGHT_TEST; + +}stMpPPGItemsConfig; + +//define ECG test items +typedef struct +{ + + emMpTestItemStatus ECG_LEADONOFF_TEST; + emMpTestItemStatus ECG_NOISE_TEST; + emMpTestItemStatus ECG_HPF_TEST; + emMpTestItemStatus ECG_SIGNAL_TEST; + emMpTestItemStatus ECG_RLD_TEST; + emMpTestItemStatus ECG_CMRR_TEST; + emMpTestItemStatus ECG_LIN_TEST; + emMpTestItemStatus ECG_DCRANGE_TEST; + +}stMpECGItemsConfig; + +//define LED automatic dimming config +typedef struct +{ + emAutoDimming_Gear LED_ACG_FS[MAX_LED_NUM];//set LED full-scale gear ,00:25mA,01:50mA,10:100mA,11:200mA, + GU32 LED_Max_Rawdata;//LED automatic dimming threshold dimming + GU32 LED_Min_Rawdata; + GU32 LED_Ref_Up; + GU32 LED_Ref_Down; + +}stMpAutoDimmingConfig; + + +//define gh3x2x test limit +typedef struct +{ + GF32 PPG_CTR_MinLimit[MAX_SLOT_NUM*MAX_ADC_NUM]; + GF32 PPG_LeakCTR_MaxLimit[MAX_SLOT_NUM*MAX_ADC_NUM]; + GF32 PPG_LeakRatio_Throld[MAX_SLOT_NUM*MAX_ADC_NUM]; + GF32 PPG_Noise_MaxLimit; + GF32 PPG_BaseNoise_MaxLimit; + GF32 PPG_DCOffset_MaxLimit; + GF32 PPG_DCOffset_MinLimit; + + + GF32 ECG_Noise_MaxLimit; + GF32 ECG_HPF_MinLimit; + GF32 ECG_HPF_MaxLimit; + GF32 ECG_MaxAMP; + GF32 ECG_MaxFreq; + GF32 ECG_SIGNAL_MaxLimit; + GF32 ECG_RLD_MaxAmp; + GF32 ECG_CMRR_MinLimit; + GF32 ECG_LIN_MaxLimit; + GF32 ECG_DCRange_MaxLimit; + +}stMpItemsLimitConfig; + +extern const stMpItemsConfig stGh3x2xMpTestItemsSatus; + +extern const stMpPPGItemsConfig stGh3x2xMpPPGItemsSatus; + +extern const stMpECGItemsConfig stGh3x2xMpECGItemsSatus; + +extern const emMp_Enable PPG_LEDPD_EN[MAX_LED_NUM][MAX_ADC_NUM]; + +//LED automatic dimming threshold dimming +extern const stMpAutoDimmingConfig stGh3x2xPPG_AutoDimming; + +extern const stMpItemsLimitConfig stGh3x2xMpLimit; + +#endif /* _GH3X2X_MP_PARAM_CONFIG_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_reg_config.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_reg_config.h new file mode 100644 index 000000000..53f438720 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/inc/gh3x2x_mp_reg_config.h @@ -0,0 +1,31 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_reg_config.h + * + * @brief header file of gh3x2x_mp_reg_config.c + * + * @author Goodix Product Tools Development Team + * + */ +#ifndef _GH3X2X_MP_REG_CONFIG_H_ +#define _GH3X2X_MP_REG_CONFIG_H_ + +#include "gh3x2x_mp_config.h" + +typedef struct +{ + GU16 usRegAddr; + GU16 usRegValue; + +}stGh3x2xReg; + + +extern const stGh3x2xReg stGh3x2xMpRegConfigDefault[24]; +extern const stGh3x2xReg stGh3x2xMpRegPPGConfig[15]; +extern const stGh3x2xReg stGh3x2xMpRegECGLeadConfg[41]; +extern const stGh3x2xReg stGh3x2xMpRegECGConfgDefault[23]; + +#endif /* _GH3X2X_MP_REG_CONFIG_H_ */ + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp.c new file mode 100644 index 000000000..54c7be744 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp.c @@ -0,0 +1,1210 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_mp.c + * + * @brief gh3x2x mp test example + * + * @author Goodix Product Tools Development Team + * + */ + +/* includes */ +#include +#include +#include "gh3x2x_demo_mp.h" +#include "gh3x2x_mp_reg_config.h" +#include "gh3x2x_mp_common.h" +#include "gh3x2x_mp_algorithm.h" +#include "gh3x2x_demo_mp_process.h" +#include "gh3x2x_mp_param_config.h" + +extern GU8 GH3x2xMp_IntFlag; + +/** + * @fn void Gh3x2xDemoMp_Init() + * + * @brief GH3x2x mp init + * + * @attention None + * + * @param[in] none + * @param[out] None + * + * @return none + */ +void Gh3x2xDemoMp_Init(void) +{ + +#if( __GH3X2X_MP_USE_DRV_INTERFACE__ ) + //use drv lib interface + +#else +#if ( __GH3X2X_MP_INTERFACE__ == __GH3X2X_MP_INTERFACE_I2C__ ) + gh3x2x_mp_i2c_init(); +#else + gh3x2x_mp_spi_init(); +#endif //__GH3X2X_MP_INTERFACE__ + + gh3x2x_mp_reset_pin_init(); + gh3x2x_mp_int_init(); +#endif //__GH3X2X_MP_USE_DRV_INTERFACE__ + + gh3x2x_mp_led_power_pin_init(); + gh3x2x_mp_led_power_off(); //need do it + +} + +/** + * @fn GU8 Gh3x2xDemoMp_StartTest() + * + * @brief GH3x2x mp start test + * + * @attention None + * + * @param[in] none + * @param[out] None + * + * @return 0:test ok, other:error code + */ + +GU8 Gh3x2xDemoMp_StartTest() +{ + GU8 gh3x2x_mp_test_code = 0; //Save the first NG error code + GU8 test_code_tmp = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp start! \r\n"); + //print version + GH3X2X_MP_LOG_L2("Gh3x2x mp lib version: %s \r\n", GH3X2X_MP_LIB_VERSION); + + stGh3x2xMp_TestParam stTestParam; + stGh3x2xMp_TestResult stTestResult; + memset(&stTestParam, 0, sizeof(stGh3x2xMp_TestParam)); + memset(&stTestResult, 0, sizeof(stGh3x2xMp_TestResult)); + + //set test param + Gh3x2xDemoMp_SetTestParam(&stTestParam); + + //reset + gh3x2x_demo_mp_reset_operation(); + + do + { + // Communication Test + if(stGh3x2xMpTestItemsSatus.COMMUNICATION_TEST) + { + test_code_tmp = Gh3x2xDemoMp_CommunicationTest(NULL, NULL); + if(!gh3x2x_mp_test_code) //Save the first NG error code + gh3x2x_mp_test_code = test_code_tmp; + if(test_code_tmp && (NG_CONTINUE != stGh3x2xMpTestItemsSatus.COMMUNICATION_TEST)) + break; + } + + //Check Chip ID Test + //need use drv interface to check, at present Only need to test this item when the driver is AFE +#if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + //No need to do at the moment + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + if(stGh3x2xMpTestItemsSatus.CHECK_CHIPID_TEST) + { + test_code_tmp = Gh3x2xDemoMp_CheckChipIDTest(NULL, NULL); + if(!gh3x2x_mp_test_code) //Save the first NG error code + gh3x2x_mp_test_code = test_code_tmp; + if(test_code_tmp) + break; + } + #endif +#endif + + //RstInt Test + if(stGh3x2xMpTestItemsSatus.RST_INT_TEST) + { + test_code_tmp = Gh3x2xDemoMp_RstIntTest(NULL, NULL); + if(!gh3x2x_mp_test_code) //Save the first NG error code + gh3x2x_mp_test_code = test_code_tmp; + if(test_code_tmp && (NG_CONTINUE != stGh3x2xMpTestItemsSatus.RST_INT_TEST)) + break; + } + + //Efuse Test + if(stGh3x2xMpTestItemsSatus.EFUSE_TEST) + { + test_code_tmp = Gh3x2xDemoMp_EfuseTest(NULL, &stTestResult.stEfuse_TestResult); + if(!gh3x2x_mp_test_code) //Save the first NG error code + gh3x2x_mp_test_code = test_code_tmp; + if(test_code_tmp && (NG_CONTINUE != stGh3x2xMpTestItemsSatus.EFUSE_TEST)) + break; + } + + //PPG Test + if(stGh3x2xMpTestItemsSatus.PPG_TEST) + { + test_code_tmp = Gh3x2xDemoMp_PPGTest(&stTestParam.stPPG_TestParam, &stTestResult.stPPG_TestResult); + if(!gh3x2x_mp_test_code) //Save the first NG error code + gh3x2x_mp_test_code = test_code_tmp; + if(test_code_tmp && (NG_CONTINUE != stGh3x2xMpTestItemsSatus.PPG_TEST)) + break; + } + + //ECGTest + if(stGh3x2xMpTestItemsSatus.ECG_TEST) + { + test_code_tmp = Gh3x2xDemoMp_ECGTest(&stTestParam.stECG_TestParam, &stTestResult.stECG_TestResult); + if(!gh3x2x_mp_test_code) //Save the first NG error code + gh3x2x_mp_test_code = test_code_tmp; + if(test_code_tmp && (NG_CONTINUE != stGh3x2xMpTestItemsSatus.ECG_TEST)) + break; + } + + }while(0); + + GH3X2X_MP_LOG_L2("Gh3x2x mp end! \r\n"); + + if(!gh3x2x_mp_test_code) + { + //test ok,OK light comes on + GU8 prompt_msg[] = GH3X2X_MP_TEST_OK_MSG; + gh3x2x_mp_prompt_message(prompt_msg, sizeof(prompt_msg) / sizeof(GU8)); + GH3X2X_MP_LOG_L2("\r\n ************************************************************ \r\n"); + GH3X2X_MP_LOG_L2("\r\n Gh3x2x mp test is OK! \r\n"); + GH3X2X_MP_LOG_L2("\r\n ************************************************************ \r\n"); + } + else + { + //test NG,NG light comes on + GU8 prompt_msg[] = GH3X2X_MP_TEST_NG_MSG; + gh3x2x_mp_prompt_message(prompt_msg, sizeof(prompt_msg) / sizeof(GU8)); + GH3X2X_MP_LOG_L2("\r\n ************************************************************ \r\n"); + GH3X2X_MP_LOG_L2("\r\n Gh3x2x mp test is NG, error code is: %d!\r\n", gh3x2x_mp_test_code); + GH3X2X_MP_LOG_L2("\r\n ************************************************************ \r\n"); + } + + if(__GH3X2X_MP_PRINT_TEST_RESULT__) + Gh3x2xDemoMp_PrintTestResult(&stTestParam, &stTestResult); + + return gh3x2x_mp_test_code; +} + +/** + * @fn void Gh3x2xDemoMp_SetTestParam_PPG(stGh3x2xMp_TestParam *stTestParam) + * + * @brief GH3x2x MP set PPG test items param + * + * @attention None + * + * @param[in] stGh3x2xMp_PPGTestParam *stPPG_TestParam + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoMp_SetTestParam_PPG(stGh3x2xMp_PPGTestParam *stPPG_TestParam) +{ + GU8 i = 0; + GU8 j = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp start set ppg test param! \r\n"); + + //CTR test slot config + memset(&stPPG_TestParam->stCTRSlotConfig, 0, sizeof(stGh3x2xMp_SlotConfig)); + stPPG_TestParam->stCTRSlotConfig.Slot_Mutiple = 9; + stPPG_TestParam->stCTRSlotConfig.TIA_RF = 0; + stPPG_TestParam->stCTRSlotConfig.TIA_CF = 0; + stPPG_TestParam->stCTRSlotConfig.ADC_N = 5; + stPPG_TestParam->stCTRSlotConfig.ADC_IntTimes = stPPG_TestParam->stCTRSlotConfig.ADC_N; + stPPG_TestParam->stCTRSlotConfig.BG_Level = 2; + stPPG_TestParam->stCTRSlotConfig.LED_ACG = 0; + stPPG_TestParam->stCTRSlotConfig.LED_Drv = 51; + stPPG_TestParam->stCTRSlotConfig.Slot_TMR = 985; + stPPG_TestParam->stCTRSlotConfig.Slot_Mode = SLOT_MULTICH_MODE; + + //Noise test slot config + memset(&stPPG_TestParam->stNoiseSlotConfig, 0, sizeof(stGh3x2xMp_SlotConfig)); + stPPG_TestParam->stNoiseSlotConfig.Slot_Mutiple = 9; + stPPG_TestParam->stNoiseSlotConfig.TIA_RF = 4; + stPPG_TestParam->stNoiseSlotConfig.TIA_CF = 0; + stPPG_TestParam->stNoiseSlotConfig.ADC_N = 5; + stPPG_TestParam->stNoiseSlotConfig.ADC_IntTimes = stPPG_TestParam->stNoiseSlotConfig.ADC_N; + stPPG_TestParam->stNoiseSlotConfig.BG_Level = 1; + stPPG_TestParam->stNoiseSlotConfig.LED_ACG = 3; + stPPG_TestParam->stNoiseSlotConfig.LED_Drv = 0; + stPPG_TestParam->stNoiseSlotConfig.Slot_TMR = 985; + stPPG_TestParam->stNoiseSlotConfig.Slot_Mode = SLOT_ONECH_MODE; //Single channel mode is required when using automatic dimming + + //BaseNoise test slot config + memset(&stPPG_TestParam->stBaseNoiseSlotConfig, 0, sizeof(stGh3x2xMp_SlotConfig)); + stPPG_TestParam->stBaseNoiseSlotConfig.Slot_Mutiple = 9; + stPPG_TestParam->stBaseNoiseSlotConfig.TIA_RF = 4; + stPPG_TestParam->stBaseNoiseSlotConfig.TIA_CF = 0; + stPPG_TestParam->stBaseNoiseSlotConfig.ADC_N = 6; + stPPG_TestParam->stBaseNoiseSlotConfig.ADC_IntTimes = stPPG_TestParam->stBaseNoiseSlotConfig.ADC_N; + stPPG_TestParam->stBaseNoiseSlotConfig.BG_Level = 0; + stPPG_TestParam->stBaseNoiseSlotConfig.LED_ACG = 0; + stPPG_TestParam->stBaseNoiseSlotConfig.LED_Drv = 0; + stPPG_TestParam->stBaseNoiseSlotConfig.Slot_TMR = 985; + stPPG_TestParam->stBaseNoiseSlotConfig.Slot_Mode = SLOT_MULTICH_MODE; + + //LeakLight test slot config + memset(&stPPG_TestParam->stLeakLightSlotConfig, 0, sizeof(stGh3x2xMp_SlotConfig)); + stPPG_TestParam->stLeakLightSlotConfig.Slot_Mutiple = 9; + stPPG_TestParam->stLeakLightSlotConfig.TIA_RF = 4; + stPPG_TestParam->stLeakLightSlotConfig.TIA_CF = 0; + stPPG_TestParam->stLeakLightSlotConfig.ADC_N = 5; + stPPG_TestParam->stLeakLightSlotConfig.ADC_IntTimes = stPPG_TestParam->stLeakLightSlotConfig.ADC_N; + stPPG_TestParam->stLeakLightSlotConfig.BG_Level = 2; + stPPG_TestParam->stLeakLightSlotConfig.LED_ACG = 0; + stPPG_TestParam->stLeakLightSlotConfig.LED_Drv = 51; + stPPG_TestParam->stLeakLightSlotConfig.Slot_TMR = 985; + stPPG_TestParam->stLeakLightSlotConfig.Slot_Mode = SLOT_MULTICH_MODE; + + //get rawdata num + stPPG_TestParam->PPG_CTRRawdata_Num = 100; //not more than MAX_PPG_RAWDATA_SAMPLE_NUM + stPPG_TestParam->PPG_NoiseRawdata_Num = 100; //not more than MAX_PPG_RAWDATA_SAMPLE_NUM + stPPG_TestParam->PPG_BaseNoiseRawdata_Num = 100; //not more than MAX_PPG_RAWDATA_SAMPLE_NUM + stPPG_TestParam->PPG_LeakLightRawdata_Num = 20; //not more than MAX_PPG_RAWDATA_SAMPLE_NUM + stPPG_TestParam->PPG_CTRRawdata_SkipNum = 0; + stPPG_TestParam->PPG_NoiseRawdata_SkipNum = 100; + stPPG_TestParam->PPG_BaseNoiseRawdata_SkipNum = 0; + stPPG_TestParam->PPG_LeakLightRawdata_SkipNum = 0; + + //LEDPDConfig + memset(stPPG_TestParam->stLEDPDConfig.PD_Channel, 0, sizeof(stPPG_TestParam->stLEDPDConfig.PD_Channel)); + memset(stPPG_TestParam->stLEDPDConfig.PD_Num, 0, sizeof(stPPG_TestParam->stLEDPDConfig.PD_Channel)); + stPPG_TestParam->stLEDPDConfig.PD_Channel_AllSlot = 0; + stPPG_TestParam->stLEDPDConfig.PD_Num_AllSlot = 0; + stPPG_TestParam->stLEDPDConfig.LED_PD_Num = 0; + stPPG_TestParam->stLEDPDConfig.LED_Channel = 0; + stPPG_TestParam->stLEDPDConfig.LED_Num = 0; + for (i = 0; i < MAX_LED_NUM; i++) + { + for (j = 0; j < MAX_ADC_NUM; j++) + { + if (PPG_LEDPD_EN[i][j]) + { + stPPG_TestParam->stLEDPDConfig.PD_Channel[i] |= 1 << j; + stPPG_TestParam->stLEDPDConfig.PD_Num[i]++; + stPPG_TestParam->stLEDPDConfig.LED_Channel |= 1 << i; + stPPG_TestParam->stLEDPDConfig.LED_PD_Num++; + } + } + stPPG_TestParam->stLEDPDConfig.PD_Channel_AllSlot |= stPPG_TestParam->stLEDPDConfig.PD_Channel[i]; + } + for (i = 0; i < MAX_LED_NUM; i++) + { + if (stPPG_TestParam->stLEDPDConfig.PD_Channel_AllSlot & (1 << i)) + stPPG_TestParam->stLEDPDConfig.PD_Num_AllSlot++; + if (stPPG_TestParam->stLEDPDConfig.LED_Channel & (1 << i)) + stPPG_TestParam->stLEDPDConfig.LED_Num++; + } + +} + +/** + * @fn void Gh3x2xDemoMp_SetTestParam_ECG(stGh3x2xMp_ECGTestParam *stECG_TestParam) + * + * @brief GH3x2x MP set ECG test items param + * + * @attention None + * + * @param[in] stGh3x2xMp_ECGTestParam *stECG_TestParam + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoMp_SetTestParam_ECG(stGh3x2xMp_ECGTestParam *stECG_TestParam) +{ + GH3X2X_MP_LOG_L2("Gh3x2x mp start set ecg test param! \r\n"); + + //ecg signal num + stECG_TestParam->HPF_ECGSignalNum = 2; + stECG_TestParam->SIGNAL_ECGSignalNum = 3; + stECG_TestParam->CMRR_ECGSignalNum = 1; + stECG_TestParam->LIN_ECGSignalNum = 2; + stECG_TestParam->DCRange_ECGSignalNum = 3; + + //LeadOnOff param set + stECG_TestParam->stECGSignal_LeadOnOff.Rawdata_Num = 1000; + stECG_TestParam->stECGSignal_LeadOnOff.Rawdata_SkipNum = 100; + + //Noise param set + stECG_TestParam->stECGSignal_Noise.Rawdata_Num = 1000; //need >= 600 + stECG_TestParam->stECGSignal_Noise.Rawdata_SkipNum = 500; + + //HPF0 signal param set + stECG_TestParam->stECGSignal_HPF[0].Rawdata_Num = 200; //num need >= 200 + stECG_TestParam->stECGSignal_HPF[0].Rawdata_SkipNum = 0; + stECG_TestParam->stECGSignal_HPF[0].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_HPF[0].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_HPF[0].ECG_SignalType = NONE_MODE; + stECG_TestParam->stECGSignal_HPF[0].ECG_Freq = 0; + stECG_TestParam->stECGSignal_HPF[0].ECG_Vol = 0; + stECG_TestParam->stECGSignal_HPF[0].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_HPF[0].ECG_DCOffset = 810; + //HPF1 signal param set + stECG_TestParam->stECGSignal_HPF[1].Rawdata_Num = 200; //num need >= 200 + stECG_TestParam->stECGSignal_HPF[1].Rawdata_SkipNum = 0; + stECG_TestParam->stECGSignal_HPF[1].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_HPF[1].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_HPF[1].ECG_SignalType = NONE_MODE; + stECG_TestParam->stECGSignal_HPF[1].ECG_Freq = 0; + stECG_TestParam->stECGSignal_HPF[1].ECG_Vol = 0; + stECG_TestParam->stECGSignal_HPF[1].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_HPF[1].ECG_DCOffset = 860; + + //SIGNAL TEST signal0 param set + stECG_TestParam->stECGSignal_SIGNAL[0].Rawdata_Num = 2048; + stECG_TestParam->stECGSignal_SIGNAL[0].Rawdata_SkipNum = 300; + stECG_TestParam->stECGSignal_SIGNAL[0].Sampling_Step = 4; //must > 0 + stECG_TestParam->stECGSignal_SIGNAL[0].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_SIGNAL[0].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_SIGNAL[0].ECG_SignalType = AC_MODE; + stECG_TestParam->stECGSignal_SIGNAL[0].ECG_Freq = 5; + stECG_TestParam->stECGSignal_SIGNAL[0].ECG_Vol = 57; + stECG_TestParam->stECGSignal_SIGNAL[0].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_SIGNAL[0].ECG_DCOffset = 815; + //SIGNAL TEST signal1 param set + stECG_TestParam->stECGSignal_SIGNAL[1].Rawdata_Num = 14336; + stECG_TestParam->stECGSignal_SIGNAL[1].Rawdata_SkipNum = 300; + stECG_TestParam->stECGSignal_SIGNAL[1].Sampling_Step = 4; //must > 0 + stECG_TestParam->stECGSignal_SIGNAL[1].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_SIGNAL[1].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_SIGNAL[1].ECG_SignalType = AC_MODE; + stECG_TestParam->stECGSignal_SIGNAL[1].ECG_Freq = 0.67; + stECG_TestParam->stECGSignal_SIGNAL[1].ECG_Vol = 57; + stECG_TestParam->stECGSignal_SIGNAL[1].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_SIGNAL[1].ECG_DCOffset = 815; + //SIGNAL TEST signal2 param set + stECG_TestParam->stECGSignal_SIGNAL[2].Rawdata_Num = 512; + stECG_TestParam->stECGSignal_SIGNAL[2].Rawdata_SkipNum = 300; + stECG_TestParam->stECGSignal_SIGNAL[2].Sampling_Step = 1; //must > 0 + stECG_TestParam->stECGSignal_SIGNAL[2].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_SIGNAL[2].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_SIGNAL[2].ECG_SignalType = AC_MODE; + stECG_TestParam->stECGSignal_SIGNAL[2].ECG_Freq = 40; + stECG_TestParam->stECGSignal_SIGNAL[2].ECG_Vol = 57; + stECG_TestParam->stECGSignal_SIGNAL[2].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_SIGNAL[2].ECG_DCOffset = 815; + + //RLD param set + stECG_TestParam->stECGSignal_RLD.Rawdata_Num = 100; + stECG_TestParam->stECGSignal_RLD.Rawdata_SkipNum = 0; + + //CMRR0 signal param set + stECG_TestParam->stECGSignal_CMRR[0].Rawdata_Num = 712; //need >= 200 + stECG_TestParam->stECGSignal_CMRR[0].Rawdata_SkipNum = 300; + stECG_TestParam->stECGSignal_CMRR[0].bECG_NegativeSignal = 1; + stECG_TestParam->stECGSignal_CMRR[0].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_CMRR[0].ECG_SignalType = AC_MODE; + stECG_TestParam->stECGSignal_CMRR[0].ECG_Freq = 50; + stECG_TestParam->stECGSignal_CMRR[0].ECG_Vol = 1000; + stECG_TestParam->stECGSignal_CMRR[0].ECG_ACOffset = 410; + stECG_TestParam->stECGSignal_CMRR[0].ECG_DCOffset = 10; + + //LIN0 signal param set + stECG_TestParam->stECGSignal_LIN[0].Rawdata_Num = 512; + stECG_TestParam->stECGSignal_LIN[0].Rawdata_SkipNum = 300; + stECG_TestParam->stECGSignal_LIN[0].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_LIN[0].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_LIN[0].ECG_SignalType = AC_MODE; + stECG_TestParam->stECGSignal_LIN[0].ECG_Freq = 5; + stECG_TestParam->stECGSignal_LIN[0].ECG_Vol = 285; + stECG_TestParam->stECGSignal_LIN[0].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_LIN[0].ECG_DCOffset = 835; + //LIN1 signal param set + stECG_TestParam->stECGSignal_LIN[1].Rawdata_Num = 512; + stECG_TestParam->stECGSignal_LIN[1].Rawdata_SkipNum = 300; + stECG_TestParam->stECGSignal_LIN[1].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_LIN[1].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_LIN[1].ECG_SignalType = AC_MODE; + stECG_TestParam->stECGSignal_LIN[1].ECG_Freq = 5; + stECG_TestParam->stECGSignal_LIN[1].ECG_Vol = 285; + stECG_TestParam->stECGSignal_LIN[1].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_LIN[1].ECG_DCOffset = 835; + + //DCRange0 signal param set + stECG_TestParam->stECGSignal_DCRange[0].Rawdata_Num = 500; + stECG_TestParam->stECGSignal_DCRange[0].Rawdata_SkipNum = 500; + stECG_TestParam->stECGSignal_DCRange[0].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_DCRange[0].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_DCRange[0].ECG_SignalType = ANG_MODE; + stECG_TestParam->stECGSignal_DCRange[0].ECG_Freq = 10.4; + stECG_TestParam->stECGSignal_DCRange[0].ECG_Vol = 57; + stECG_TestParam->stECGSignal_DCRange[0].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_DCRange[0].ECG_DCOffset = 815; + //DCRange1 signal param set + stECG_TestParam->stECGSignal_DCRange[1].Rawdata_Num = 500; + stECG_TestParam->stECGSignal_DCRange[1].Rawdata_SkipNum = 500; + stECG_TestParam->stECGSignal_DCRange[1].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_DCRange[1].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_DCRange[1].ECG_SignalType = ANG_MODE; + stECG_TestParam->stECGSignal_DCRange[1].ECG_Freq = 10.4; + stECG_TestParam->stECGSignal_DCRange[1].ECG_Vol = 57; + stECG_TestParam->stECGSignal_DCRange[1].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_DCRange[1].ECG_DCOffset = 315; + //DCRange2 signal param set + stECG_TestParam->stECGSignal_DCRange[2].Rawdata_Num = 500; + stECG_TestParam->stECGSignal_DCRange[2].Rawdata_SkipNum = 500; + stECG_TestParam->stECGSignal_DCRange[2].bECG_NegativeSignal = 0; + stECG_TestParam->stECGSignal_DCRange[2].bECG_HighImpedance = 0; + stECG_TestParam->stECGSignal_DCRange[2].ECG_SignalType = ANG_MODE; + stECG_TestParam->stECGSignal_DCRange[2].ECG_Freq = 10.4; + stECG_TestParam->stECGSignal_DCRange[2].ECG_Vol = 57; + stECG_TestParam->stECGSignal_DCRange[2].ECG_ACOffset = 57; + stECG_TestParam->stECGSignal_DCRange[2].ECG_DCOffset = 1315; + + +} + +/** + * @fn GU8 Gh3x2xDemoMp_SetTestParam(stGh3x2xMp_TestParam *stTestParam) + * + * @brief GH3x2x MP set all test items param. + * + * @attention None + * + * @param[in] stGh3x2xMp_TestParam *stTestParam + * @param[out] None + * + * @return None + */ +void Gh3x2xDemoMp_SetTestParam(stGh3x2xMp_TestParam *stTestParam) +{ + + Gh3x2xDemoMp_SetTestParam_PPG(&stTestParam->stPPG_TestParam); + Gh3x2xDemoMp_SetTestParam_ECG(&stTestParam->stECG_TestParam); + +} + +/** + * @fn void Gh3x2xDemoMp_PrintTestResult(stGh3x2xMp_TestParam *stTestParam, stGh3x2xMp_TestResult *stTestResult) + * + * @brief GH3x2x mp print all test result + * + * @attention It must be called after the test ends + * + * @param[in] stGh3x2xMp_TestParam *stTestParam, stGh3x2xMp_TestResult *stTestResult + * @param[out] None + * + * @return none + */ +void Gh3x2xDemoMp_PrintTestResult(stGh3x2xMp_TestParam *stTestParam, stGh3x2xMp_TestResult *stTestResult) +{ + GU32 i = 0; + //GCHAR Gh3x2xDemoMp_TestResultLog[GH3X2X_MP_LOG_MAX_LEN] = {0}; + GH3X2X_MP_LOG("\r\n *************************Start print Gh3x2x mp test all result info!*********************************** \r\n"); + + //print efuse test result + if(stGh3x2xMpTestItemsSatus.EFUSE_TEST) + { + + GH3X2X_MP_LOG("\r\n *************************Start print chip uid*********************************** \r\n"); + GH3X2X_MP_LOG("\r\n Gh3x2x mp efuse test result, chip uid is: "); + for(i = 0; i < CHIP_UID_LENGTH; i++) + { + GH3X2X_MP_LOG("%02X \r\n", stTestResult->stEfuse_TestResult.uchChipUid[i]); + } + GH3X2X_MP_LOG("\r\n"); + GH3X2X_MP_LOG("\r\n *************************End print chip uid*********************************** \r\n"); + } + + //print ppg tset result + if(stGh3x2xMpTestItemsSatus.PPG_TEST) + { + GH3X2X_MP_LOG("\r\n *************************Start print ppg test result*********************************** \r\n"); + if(stGh3x2xMpPPGItemsSatus.PPG_LPCTR_TEST) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < MAX_LED_NUM*MAX_ADC_NUM; i++) + { + GH3X2X_MP_LOG("LPCTR[%d]: %.5f, \r\n", i, stTestResult->stPPG_TestResult.LED_LPCTR[i]); + } + } + + if(stGh3x2xMpPPGItemsSatus.PPG_NOISE_TEST) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < MAX_LED_NUM*MAX_ADC_NUM; i++) + { + GH3X2X_MP_LOG("Noise[%d]: %.5f, \r\n", i, stTestResult->stPPG_TestResult.LED_Noise[i]); + } + } + + if(stGh3x2xMpPPGItemsSatus.PPG_BASENOISE_TEST) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < MAX_LED_NUM*MAX_ADC_NUM; i++) + { + GH3X2X_MP_LOG("BaseNoise[%d]: %.5f, \r\n", i, stTestResult->stPPG_TestResult.LED_BaseNoise[i]); + } + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < MAX_LED_NUM*MAX_ADC_NUM; i++) + { + GH3X2X_MP_LOG("DC_Offset[%d]: %.5f, \r\n", i, stTestResult->stPPG_TestResult.LED_DCOffset[i]); + } + } + + if(stGh3x2xMpPPGItemsSatus.PPG_LEAKLIGHT_TEST) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < MAX_LED_NUM*MAX_ADC_NUM; i++) + { + GH3X2X_MP_LOG("LeakLight_CTR[%d]: %.5f, \r\n", i, stTestResult->stPPG_TestResult.LED_LLPCTR[i]); + } + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < MAX_LED_NUM*MAX_ADC_NUM; i++) + { + GH3X2X_MP_LOG("LeakLight_Ratio[%d]: %.5f, \r\n", i, stTestResult->stPPG_TestResult.LED_LeakRatio[i]); + } + } + GH3X2X_MP_LOG("\r\n *************************End print ppg test result*********************************** \r\n"); + } + + + + //print ppg tset result + if(stGh3x2xMpTestItemsSatus.ECG_TEST) + { + GH3X2X_MP_LOG("\r\n *************************Start print ecg test result*********************************** \r\n"); + if(stGh3x2xMpECGItemsSatus.ECG_NOISE_TEST) + { + GH3X2X_MP_LOG("\r\n"); + GH3X2X_MP_LOG("ECG_Noise: %.5f, \r\n", stTestResult->stECG_TestResult.ECG_Noise); + } + + if(stGh3x2xMpECGItemsSatus.ECG_HPF_TEST) + { + if(stTestParam->stECG_TestParam.HPF_ECGSignalNum < ECG_MAX_SIGNAL_NUM) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < stTestParam->stECG_TestParam.HPF_ECGSignalNum / 2; i++) //2 signals in a group, ratio is Calculate the latter one + { + GH3X2X_MP_LOG("ECG_HPFRatio[%d]: %.5f, \r\n", i, stTestResult->stECG_TestResult.ECG_HPFRatio[i]); + } + } + } + + if(stGh3x2xMpECGItemsSatus.ECG_SIGNAL_TEST) + { + if(stTestParam->stECG_TestParam.SIGNAL_ECGSignalNum < ECG_MAX_SIGNAL_NUM) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < stTestParam->stECG_TestParam.SIGNAL_ECGSignalNum; i++) + { + GH3X2X_MP_LOG("ECG_SIGNAL_Amp[%d]: %.5fmV, \r\n", i, stTestResult->stECG_TestResult.ECG_Amp[i]); + } + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < stTestParam->stECG_TestParam.SIGNAL_ECGSignalNum; i++) + { + GH3X2X_MP_LOG("ECG_SIGNAL_Freq[%d]: %.5fHz, \r\n", i, stTestResult->stECG_TestResult.ECG_Freq[i]); + } + } + } + + if(stGh3x2xMpECGItemsSatus.ECG_RLD_TEST) + { + GH3X2X_MP_LOG("\r\n"); + GH3X2X_MP_LOG("ECG_RLD_Amp: %.5fmV, \r\n", stTestResult->stECG_TestResult.ECG_RLD); + } + + if(stGh3x2xMpECGItemsSatus.ECG_CMRR_TEST) + { + if(stTestParam->stECG_TestParam.CMRR_ECGSignalNum < ECG_MAX_SIGNAL_NUM) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < stTestParam->stECG_TestParam.CMRR_ECGSignalNum; i++) + { + GH3X2X_MP_LOG("ECG_CMRR[%d]: %.5f, \r\n", i, stTestResult->stECG_TestResult.ECG_CMRR[i]); + } + } + } + + if(stGh3x2xMpECGItemsSatus.ECG_LIN_TEST) + { + if(stTestParam->stECG_TestParam.LIN_ECGSignalNum < ECG_MAX_SIGNAL_NUM) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < stTestParam->stECG_TestParam.LIN_ECGSignalNum / 2; i++) //2 signals in a group to cal one ratio + { + GH3X2X_MP_LOG("ECG_LIN_Ratio[%d]: %.5f, \r\n", i, stTestResult->stECG_TestResult.ECG_LIN_Ratio[i]); + } + } + } + + if(stGh3x2xMpECGItemsSatus.ECG_DCRANGE_TEST) + { + if(stTestParam->stECG_TestParam.DCRange_ECGSignalNum < ECG_MAX_SIGNAL_NUM) + { + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < stTestParam->stECG_TestParam.DCRange_ECGSignalNum; i++) //3 signals in a group to cal two ratio + { + GH3X2X_MP_LOG("ECG_DCRange_Ratio[%d]: %.5f, \r\n", i, stTestResult->stECG_TestResult.ECG_DCRange_Ratio[i]); + } + GH3X2X_MP_LOG("\r\n"); + for(i = 0; i < stTestParam->stECG_TestParam.DCRange_ECGSignalNum; i++) //3 signals in a group to cal two ratio + { + GH3X2X_MP_LOG("ECG_DCRange_Amp[%d]: %.5f, \r\n", i, stTestResult->stECG_TestResult.ECG_DCRange_Amp[i]); + } + } + } + GH3X2X_MP_LOG("\r\n *************************End print ecg test result*********************************** \r\n"); + + } + + + + GH3X2X_MP_LOG("\r\n *************************End print Gh3x2x mp test all result info!*********************************** \r\n"); +} + +/** + * @fn GU8 Gh3x2xDemoMp_CommunicationTest(GU8 *puchPara, GU8 *puchTestResult) + * + * @brief GH3x2x MP Communication Test. + * + * @attention None + * + * @param[in] GU8 *puchPara, GU8 *pushTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_CommunicationTest(GU8 *puchPara, GU8 *puchTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GU8 retry_time = 3; + GH3X2X_MP_LOG_L2("Gh3x2x mp Communication test start! \r\n"); + + for(i = 0; i < retry_time; i++) + { + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + //communication test + for(GU32 i = 0; i < sizeof(stGh3x2xMpRegConfigDefault) / sizeof(stGh3x2xMpRegConfigDefault[0]); i++) + { + if(stGh3x2xMpRegConfigDefault[i].usRegAddr && (stGh3x2xMpRegConfigDefault[i].usRegAddr < 0x780)) + { + gh3x2x_demo_mp_write_reg(stGh3x2xMpRegConfigDefault[i].usRegAddr, stGh3x2xMpRegConfigDefault[i].usRegValue); + gh3x2x_mp_delay_ms(2); + + if(stGh3x2xMpRegConfigDefault[i].usRegValue != gh3x2x_demo_mp_read_reg(stGh3x2xMpRegConfigDefault[i].usRegAddr)) + { + test_code = MT_ERROR_COMMUNICATION_TEST_ERROR; + GH3X2X_MP_LOG_L1("Gh3x2x mp Communication test fail, error code is: %d!\r\n", test_code); + break; + } + } + } + if(!test_code) + { + GH3X2X_MP_LOG_L2("Gh3x2x mp Communication test is pass! \r\n"); + break; + } + + } + if(i == retry_time) + { + test_code = MT_ERROR_COMMUNICATION_TEST_ERROR; + GH3X2X_MP_LOG_L1("Gh3x2x mp Communication test fail, error code is: %d!\r\n", test_code); + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp Communication test end! \r\n"); + + return test_code; +} + +/** + * @fn GU8 Gh3x2xDemoMp_CheckChipIDTest(GU8 *puchPara, GU8 *puchTestResult) + * + * @brief GH3x2x MP Check Chip ID Test. + * + * @attention None + * + * @param[in] GU8 *puchPara, GU8 *pushTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_CheckChipIDTest(GU8 *puchPara, GU8 *puchTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GU8 retry_time = 3; + GH3X2X_MP_LOG_L2("Gh3x2x mp Check ChipID test start! \r\n"); + + for(i = 0; i < retry_time; i++) + { + //need use drv interface to check, at present Only need to test this item when the driver is AFE + #if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + //No need to do at the moment + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + if(GH3X2X_CHIP_ID == GH3X2X_AFE_GetChipId()) + { + GH3X2X_MP_LOG_L2("Gh3x2x mp Check ChipID test is pass! \r\n"); + break; + } + else + continue; + #endif + #endif + + } + if(i == retry_time) + { + test_code = MT_ERROR_CHECK_CHIPID_ERROR; + GH3X2X_MP_LOG_L1("Gh3x2x mp Check ChipID test fail--Chip ID error, error code is: %d!\r\n", test_code); + } + + + GH3X2X_MP_LOG_L2("Gh3x2x mp Check ChipID test end! \r\n"); + + return test_code; + +} + +/** + * @fn GU8 Gh3x2xDemoMp_RstIntTest(GU8 *puchPara, GU8 *puchTestResult) + * + * @brief GH3x2x MP Communication Test. + * + * @attention None + * + * @param[in] GU8 *puchPara, GU8 *pushTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_RstIntTest(GU8 *puchPara, GU8 *puchTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GU8 retry_time = 3; + GU16 time_out = 200; + GH3X2X_MP_LOG_L2("Gh3x2x mp RST&INT test start! \r\n"); + + for(i = 0; i < retry_time; i++) + { + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + //rst gh3x2x,set low and set high later + gh3x2x_demo_mp_reset_operation(); + + //wait int + if(gh3x2x_demo_mp_wait_for_int(0x4000, time_out)) + { + GH3X2X_MP_LOG_L2("Gh3x2x mp RST&INT test is pass! \r\n"); + break; + } + } + if(i == retry_time) + { + test_code = MT_ERROR_COMMUNICATION_TEST_ERROR; + GH3X2X_MP_LOG_L1("Gh3x2x mp RST&INT test fail, error code is: %d!\r\n", test_code); + } + + + GH3X2X_MP_LOG_L2("Gh3x2x mp RST&INT test end! \r\n"); + + return test_code; + +} + +/** + * @fn GU8 Gh3x2xDemoMp_EfuseTest(GU8 *puchPara, stGh3x2xMp_EfuseTestResult *pstTestResult) + * + * @brief GH3x2x MP efuse Test, check FT/CP and crc, and get chipUid + * + * @attention None + * + * @param[in] GU8 *puchPara, stGh3x2xMp_EfuseTestResult *pstTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_EfuseTest(GU8 *puchPara, stGh3x2xMp_EfuseTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 retry_time = 3; + GU8 i = 0; + GU8 j = 0; + GU16 usTimeOut_ms = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp eFuse test start! \r\n"); + + memset(pstTestResult->uchChipUid, 0, 12); + + //read efuse, check FT/CP and get chip uid + GU8 eFuse_data[GH3X2X_DEMO_MP_EFUSE_MAX_LEN] = {0}; + GU16 eFuse_block[3] = {0x0030, 0x0034, 0x0038}; + GU8 eFuseReadPass = 1; + for(i = 0; i < retry_time; i++) + { + eFuseReadPass = 1; + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + gh3x2x_demo_mp_write_reg(0x700, 0x0020); + GU8 tmp_data[24] = {0}; + for(j = 0; j < 3; j++) + { + gh3x2x_demo_mp_write_reg(0x700, eFuse_block[j]); + usTimeOut_ms = 200; + while(usTimeOut_ms--) + { + if((gh3x2x_demo_mp_read_reg(0x718) & 0x0001)) + break; + gh3x2x_mp_delay_ms(1); + } + if(0 == usTimeOut_ms) + { + eFuseReadPass = 0; + break; + } + memset(tmp_data, 0, 24); + gh3x2x_demo_mp_read_regs(0x710, tmp_data, 8); + for(GU16 k = 0; k < 4; k++) + { + eFuse_data[8*j + 2*k] = tmp_data[2*k + 1]; + eFuse_data[8*j + 2*k + 1] = tmp_data[2*k]; + } + } + if(!eFuseReadPass) + continue; + + //check FT/CP + GU8 FT_Result = eFuse_data[23] & (0x0C >> 2); + GU8 CP_Result = eFuse_data[23] & 0x03; + if((0x01 == FT_Result) && (0x01 == CP_Result)) + { + GU8 FT_CRC = eFuse_data[7]; + GU8 CP_CRC = eFuse_data[11]; + GU8 FT_CRC_Check[24] = {0}; + GU8 CP_CRC_Check[24] = {0}; + GH3X2X_Memcpy(&FT_CRC_Check[1], eFuse_data, 7); + GH3X2X_Memcpy(&CP_CRC_Check[1], &eFuse_data[8], 3); + FT_CRC_Check[0] = gh3x2x_mp_crc_cal(&FT_CRC_Check[1], 7); //cal FT crc + CP_CRC_Check[0] = gh3x2x_mp_crc_cal(&CP_CRC_Check[1], 3); //cal CP crc + + if((FT_CRC != FT_CRC_Check[0]) || (CP_CRC != CP_CRC_Check[0])) + { + GH3X2X_MP_LOG_L1("Gh3x2x mp efuse test fail, FT or CP check crc error\r\n "); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp eFuse test is pass! \r\n"); + break; + } + } + else + GH3X2X_MP_LOG_L1("Gh3x2x mp efuse test fail, FT or CP check result error\r\n "); + } + if(i == retry_time) + { + test_code = MT_ERROR_EFUSE_ERROR; + GH3X2X_MP_LOG_L1("Gh3x2x mp efuse test fail, error code is: %d!\r\n", test_code); + } + + //get chip uid + for(GU8 j = 0; j < 12; j++) + { + if(GH3X2X_DEMO_MP_EFUSE_MAX_LEN > 12) + pstTestResult->uchChipUid[j] = eFuse_data[j]; + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp eFuse test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 Gh3x2xDemoMp_PPGTest(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief GH3x2x MP PPG Test + * + * @attention None + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_PPGTest(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) +{ + GU8 test_code = 0; //Save the first NG error code + GU8 test_code_tmp = 0; + GU8 retry_times = 3; + GU8 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG test start! \r\n"); + + //init pstTestResult + for(i = 0; i < (MAX_LED_NUM*MAX_ADC_NUM); i++) + { + pstTestResult->LED_BaseNoise[i] = 0.0; + pstTestResult->LED_Noise[i] = 0.0; + pstTestResult->LED_LPCTR[i] = 0.0; + pstTestResult->LED_DCOffset[i] = 0.0; + pstTestResult->LED_LLPCTR[i] = 0.0; + pstTestResult->LED_LeakRatio[i] = 0.0; + } + memset(&pstTestResult->stCTRRawHandleResult, 0, sizeof(stGh3x2xMp_RawdataHandleResult)); + memset(&pstTestResult->stNoiseRawHandleResult, 0, sizeof(stGh3x2xMp_RawdataHandleResult)); + memset(&pstTestResult->stBaseNoiseRawHandleResult, 0, sizeof(stGh3x2xMp_RawdataHandleResult)); + memset(&pstTestResult->stLeakLightRawHandleResult, 0, sizeof(stGh3x2xMp_RawdataHandleResult)); + + //power on led, + gh3x2x_mp_led_power_on(); + + do + { + //LP_CTR test + if(stGh3x2xMpPPGItemsSatus.PPG_LPCTR_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_PPG_LPCTR_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG-CTR test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpPPGItemsSatus.PPG_LPCTR_TEST)) + break; + } + //Noise test + if(stGh3x2xMpPPGItemsSatus.PPG_NOISE_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_PPG_Noise_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG-Noise test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpPPGItemsSatus.PPG_NOISE_TEST)) + break; + } + //Base_Noise test + if(stGh3x2xMpPPGItemsSatus.PPG_BASENOISE_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_PPG_BaseNoise_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG-BaseNoise test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpPPGItemsSatus.PPG_BASENOISE_TEST)) + break; + } + //LeakLight test + if(stGh3x2xMpPPGItemsSatus.PPG_LEAKLIGHT_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_PPG_LeakLight_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG-LeakLight test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpPPGItemsSatus.PPG_LEAKLIGHT_TEST)) + break; + } + + }while(0); + + //power off led + gh3x2x_mp_led_power_off(); + + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 Gh3x2xDemoMp_ECGTest(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief GH3x2x MP ECG Test + * + * @attention None + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] None + * + * @return error code + */ +GU8 Gh3x2xDemoMp_ECGTest(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; //Save the first NG error code + GU8 test_code_tmp = 0; + GU8 retry_times = 3; + GU8 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test start! \r\n"); + + //init pstTestResult + pstTestResult->ECG_Noise = 0; + pstTestResult->ECG_RLD = 0; + for(i = 0; i < ECG_MAX_SIGNAL_NUM; i++) + { + pstTestResult->ECG_HPFRatio[i] = 0; + pstTestResult->ECG_Amp[i] = 0; + pstTestResult->ECG_CMRR[i] = 0; + pstTestResult->ECG_DCRange_Amp[i] = 0; + pstTestResult->ECG_DCRange_Ratio[i] = 0; + pstTestResult->ECG_Freq[i] = 0; + pstTestResult->ECG_LIN_Ratio[i] = 0; + } + + //rst gh3x2x,set low and set high later + gh3x2x_demo_mp_reset_operation(); + + do + { + //Lead on/off test + if(stGh3x2xMpECGItemsSatus.ECG_LEADONOFF_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_LeadOnOff_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-LeadOnOff test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_LEADONOFF_TEST)) + break; + } + //Noise test + if(stGh3x2xMpECGItemsSatus.ECG_NOISE_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_Noise_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-Noise test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_NOISE_TEST)) + break; + } + //HPF test + if(stGh3x2xMpECGItemsSatus.ECG_HPF_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_HPF_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-HPF test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_HPF_TEST)) + break; + } + //SIGNAL test + if(stGh3x2xMpECGItemsSatus.ECG_SIGNAL_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_SIGNAL_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-SIGNAL test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_SIGNAL_TEST)) + break; + } + //RLD test + if(stGh3x2xMpECGItemsSatus.ECG_RLD_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_RLD_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-RLD test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_RLD_TEST)) + break; + } + //CMRR test + if(stGh3x2xMpECGItemsSatus.ECG_CMRR_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_CMRR_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-CMRR test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_CMRR_TEST)) + break; + } + //LIN test + if(stGh3x2xMpECGItemsSatus.ECG_LIN_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_LIN_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-LIN test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_LIN_TEST)) + break; + } + //DC_Range test + if(stGh3x2xMpECGItemsSatus.ECG_DCRANGE_TEST) + { + for(i = 0; i < retry_times; i++) + { + test_code_tmp = gh3x2x_demo_mp_ECG_DCRange_Test(pstTestPara, pstTestResult); + if(!test_code_tmp) + break; + else + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG-DCRange test retry:%d !\r\n", i+1); + } + if(!test_code) //Save the first NG error code + test_code = test_code_tmp; + if((i == retry_times) && (NG_CONTINUE != stGh3x2xMpECGItemsSatus.ECG_DCRANGE_TEST)) + break; + } + + + }while(0); + + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test end! \r\n"); + return test_code; +} + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp_process.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp_process.c new file mode 100644 index 000000000..13ddf8075 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp_process.c @@ -0,0 +1,2852 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_mp_process.c + * + * @brief process function of mp test + * + * @author Goodix Product Tools Development Team + * + */ + +#include +#include +#include +#include "gh3x2x_demo_mp_process.h" +#include "gh3x2x_mp_common.h" +#include "gh3x2x_mp_algorithm.h" +#include "gh3x2x_mp_param_config.h" + +#if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + #include "gh_drv.h" + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + #include "gh3x2x_afe_drv.h" + #endif +#endif + + +GU8 GH3x2xMp_IntFlag = 0; //int event flag + +GS32 GH3x2xMp_RawdataHandleArr[MAX_RAWDATA_SAMPLE_NUM] = {0}; +GU8 GH3x2xMp_RawdataBuf[RAWDATA_BUF_SIZE] = {0}; +GF32 *fArrHandle_Temp = NULL; + +GU32 Tia_Switch(GU32 tia) +{ + switch (tia) + { + case 0: + return 10 ; + case 1: + return 25 ; + case 2: + return 50 ; + case 3: + return 75 ; + case 4: + return 100 ; + case 5: + return 250 ; + case 6: + return 500 ; + case 7: + return 750 ; + case 8: + return 1000; + case 9: + return 1250 ; + case 10: + return 1500 ; + case 11: + return 1750 ; + case 12: + return 2000 ; + + default: + return 1; + } +} + + +/** + * @fn gh3x2x_demo_mp_write_reg(GU16 usReg_Addr, GU16 usReg_Value) + * + * @brief GH3x2x mp write reg + * + * @attention None + * + * @param[in] GU16 usReg_Addr, GU16 usReg_Value + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_write_reg(GU16 usReg_Addr, GU16 usReg_Value) +{ + GU8 ret = 1; + + + #if(__GH3X2X_MP_USE_DRV_INTERFACE__) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + GH3X2X_WriteReg(usReg_Addr, usReg_Value); + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + GH3X2X_AFE_WRITE_REG(usReg_Addr, usReg_Value); + #endif + + #else //__GH3X2X_MP_USE_DRV_INTERFACE__ == 0, use mp lib interface + GU8 uchBuffArr[4] = {0}; + uchBuffArr[0] = usReg_Addr >> 8; + uchBuffArr[1] = usReg_Addr & 0xFF; + uchBuffArr[2] = usReg_Value & 0xFF; + uchBuffArr[3] = usReg_Value >> 8; + #if ( __GH3X2X_MP_INTERFACE__ == __GH3X2X_INTERFACE_I2C__ ) + gh3x2x_mp_i2c_write(device_id, uchBuffArr, 4); + #else //__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_SPI__ + gh3x2x_mp_spi_write(uchBuffArr, 4); + #endif + #endif + + return ret; +} + +/** + * @fn GU16 gh3x2x_demo_mp_read_reg(GU16 usReg_Addr) + * + * @brief GH3x2x mp read reg + * + * @attention None + * + * @param[in] GU16 usReg_Addr + * @param[out] None + * + * @return read reg value + */ +GU16 gh3x2x_demo_mp_read_reg(GU16 usReg_Addr) +{ + GU16 usRegData = 0; + + #if(__GH3X2X_MP_USE_DRV_INTERFACE__) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + usRegData = GH3X2X_ReadReg(usReg_Addr); + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + usRegData = GH3X2X_AFE_READ_REG(usReg_Addr); + #endif + #else //__GH3X2X_MP_USE_DRV_INTERFACE__ == 0, use mp lib interface + GU8 uchCmdBuffArr[2] = {0}; + GU8 uchReadBuffArr[2] = {0}; + + uchCmdBuffArr[0] = usReg_Addr >> 8; + uchCmdBuffArr[1] = usReg_Addr & 0xFF; + + #if ( __GH3X2X_MP_INTERFACE__ == __GH3X2X_INTERFACE_I2C__ ) + gh3x2x_mp_i2c_read(device_id, uchCmdBuffArr, 2, uchReadBuffArr, 2); + #else //__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_SPI__ + gh3x2x_mp_spi_read(uchCmdBuffArr, 2, uchReadBuffArr, 2); + #endif + usRegData = (uchReadBuffArr[0] << 8) + uchReadBuffArr[1]; + #endif + + return usRegData; +} + +/** + * @fn GU8 gh3x2x_demo_mp_read_regs(GU16 usReg_Addr, GU8 uchRegs_Read[], GU16 usLength) + * + * @brief GH3x2x mp read regs + * + * @attention None + * + * @param[in] GU16 usReg_Addr, GU16 usLength + * @param[out] GU8 uchRegs_Read[] + * + * @return ret + */ +GU8 gh3x2x_demo_mp_read_regs(GU16 usReg_Addr, GU8 uchRegs_Read[], GU16 usLength) +{ + GU8 ret = 1; + + #if(__GH3X2X_MP_USE_DRV_INTERFACE__) + GU16 length_temp = usLength / 2; + + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + GH3X2X_ReadRegs(usReg_Addr, (GU16 *)uchRegs_Read, length_temp); + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + GH3X2X_AFE_READ_REGS(usReg_Addr, (GU16 *)uchRegs_Read, length_temp); + #endif + for(GU16 i = 0; i < length_temp; i++) + { + GU8 swap_val = uchRegs_Read[2*i]; + uchRegs_Read[2*i] = uchRegs_Read[2*i + 1]; + uchRegs_Read[2*i + 1] = swap_val; + } + #else //__GH3X2X_MP_USE_DRV_INTERFACE__ == 0, use mp lib interface + GU8 uchCmdBuffArr[2] = {0}; + + uchCmdBuffArr[0] = usReg_Addr >> 8; + uchCmdBuffArr[1] = usReg_Addr & 0xFF; + #if ( __GH3X2X_MP_INTERFACE__ == __GH3X2X_INTERFACE_I2C__ ) + gh3x2x_mp_i2c_read(uchCmdBuffArr, 2, uchReadBuffArr, 2); + #else //__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_SPI__ + gh3x2x_mp_spi_read(uchCmdBuffArr, 2, uchRegs_Read, usLength); + #endif + #endif + + + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_write_reg_mask(GU16 usRegAddr, GU16 usMask, GU16 usRegVal) + * + * @brief GH3x2x mp write reg mask + * + * @attention None + * + * @param[in] GU16 usReg_Addr + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_write_reg_mask(GU16 usRegAddr, GU16 usMask, GU16 usRegVal) +{ + GU8 ret = 1; + + GU16 temp_val = gh3x2x_demo_mp_read_reg(usRegAddr); + + //temp_val |= 0x0602;//no sleep + temp_val &= ~usMask; + temp_val |= usRegVal & usMask; + + gh3x2x_demo_mp_write_reg(usRegAddr, temp_val); + + return ret; +} + +/** + * @fn void gh3x2x_demo_mp_send_cmd(GU8 uchCmd) + * + * @brief send cmd to gh3x2x chip + * + * @attention None + * + * @param[in] GU8 uchCmd + * @param[out] None + * + * @return ret + */ +void gh3x2x_demo_mp_send_cmd(GU8 uchCmd) +{ + #if(__GH3X2X_MP_USE_DRV_INTERFACE__) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + GH3X2X_SendCmd(uchCmd); + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + GH3X2X_AFE_SEND_CMD(uchCmd); + #endif + #else //__GH3X2X_MP_USE_DRV_INTERFACE__ == 0, use mp lib interface + #if ( __GH3X2X_MP_INTERFACE__ == __GH3X2X_INTERFACE_I2C__ ) + gh3x2x_mp_i2c_send_cmd(device_id, uchCmd); + #else //__GH3X2X_INTERFACE__ == __GH3X2X_INTERFACE_SPI__ + gh3x2x_mp_spi_send_cmd(uchCmd); + #endif + #endif +} + +/** + * @fn void gh3x2x_demo_mp_reset_operation(void) + * + * @brief reset gh3x2x chip + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_demo_mp_reset_operation(void) +{ + //rst gh3x2x,set low and set high later + #if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + #if __SUPPORT_HARD_RESET_CONFIG__ + GH3X2X_HardReset(); + #else + GH3X2X_SoftReset(); + #endif + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + GH3X2X_AFE_Reset(); + #endif + + #else + gh3x2x_mp_reset_pin_ctrl(0); + gh3x2x_mp_delay_ms(5); + gh3x2x_mp_reset_pin_ctrl(1); + #endif + + gh3x2x_mp_delay_ms(10); //must delay +} + +/** + * @fn GU8 gh3x2x_demo_mp_wait_for_int(GU16 usDutFlag, GU16 usTimeOut_ms) + * + * @brief wait for int + * + * @attention None + * + * @param[in] GU16 usDutFlag, GU16 usTimeOut + * @param[out] none + * + * @return ret + */ +GU8 gh3x2x_demo_mp_wait_for_int(GU16 usDutFlag, GU16 usTimeOut_ms) +{ + GU8 ret = 1; + GU32 time_count = 0; + usTimeOut_ms *= 100; + GH3x2xMp_IntFlag = 0; + + while(time_count++ < usTimeOut_ms) + { + gh3x2x_mp_delay_us(10); + if(GH3x2xMp_IntFlag) + { + GH3x2xMp_IntFlag = 0; + //clear int + GU16 temp_read_val = gh3x2x_demo_mp_read_reg(0x508); + gh3x2x_demo_mp_write_reg(0x508, temp_read_val); + + if(usDutFlag & temp_read_val) + { + return ret; + } + } + } + + ret = 0; + GH3X2X_MP_LOG_L1("Gh3x2x mp no interruption!\r\n "); + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_set_chip_config(const stGh3x2xReg stGh3x2xMpRegConfig[], GU16 usConfigLen) + * + * @brief GH3x2x mp write chip reg config + * + * @attention None + * + * @param[in] const stGh3x2xReg stGh3x2xMpRegConfig[], GU16 usConfigLen + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_chip_config(const stGh3x2xReg stGh3x2xMpRegConfig[], GU16 usConfigLen) +{ + GU8 ret = 1; + GU8 retry_times = 3; + GU8 i = 0; + GU8 isWriteNormal = 1; + + for(i = 0; i < retry_times; i++) + { + isWriteNormal = 1; + for(GU32 j = 0; j < usConfigLen; j++) + { + if((0 == stGh3x2xMpRegConfig[j].usRegAddr) && (0 == stGh3x2xMpRegConfig[j].usRegValue)) + continue; + + gh3x2x_demo_mp_write_reg(stGh3x2xMpRegConfig[j].usRegAddr, stGh3x2xMpRegConfig[j].usRegValue); + + if(stGh3x2xMpRegConfig[j].usRegValue != gh3x2x_demo_mp_read_reg(stGh3x2xMpRegConfig[j].usRegAddr)) + { + isWriteNormal = 0; + break; + } + } + if(isWriteNormal) + { + break; + } + } + if(i == retry_times) + { + GH3X2X_MP_LOG_L1("Gh3x2x mp set chip reg config fail! \r\n "); + ret = 0; + } + + + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_set_slot_config(stGh3x2xMp_SlotConfig stSlotConfig) + * + * @brief GH3x2x mp set slot config + * + * @attention None + * + * @param[in] stGh3x2xMp_SlotConfig stSlotConfig + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_slot_config(stGh3x2xMp_SlotConfig stSlotConfig) +{ + GU8 ret = 1; + GU8 index = 0; + GU16 i = 0; + stGh3x2xReg stCofigRegArr[20] = {0}; + + if(SLOT_ONECH_MODE == stSlotConfig.Slot_Mode) + { + //Slot_cfgN refresh cycle is the system (sr_multiplier+1) times, RxN (ADCN) channel is enabled, data is written into FIFO + stCofigRegArr[index].usRegAddr = 0x010A + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0040 | (stSlotConfig.Slot_Mutiple << 8) | (1 << (stSlotConfig.ADC_N + 2)); + + //Clear all ADC channel connections + stCofigRegArr[index].usRegAddr = 0x010C + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0000; + + stCofigRegArr[index].usRegAddr = 0x010E + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0000; + + //ADC_N is mapped to PD_N, only one PD channel can be opened at a time + stCofigRegArr[index].usRegAddr = 0x010C + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N + (stSlotConfig.ADC_N / 2) * 2; + stCofigRegArr[index++].usRegValue = stSlotConfig.PD_N << ((stSlotConfig.ADC_N % 2) * 8); + + //slot_cfgN ADCN TIA gain is TIA_RF + stCofigRegArr[index].usRegAddr = 0x0112 + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = (stSlotConfig.TIA_RF & 0x0F) << (stSlotConfig.ADC_N * 4); + + //slot_cfgN ADCN TIA capacitance is TIA_CF + stCofigRegArr[index].usRegAddr = 0x0114 + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = (stSlotConfig.TIA_CF & 0x0F) << (stSlotConfig.ADC_N * 4); + } + else //SLOT_MULTICH_MODE + { + //Slot_cfgN refresh cycle is the system (sr_multiplier+1) times, PDN (RxN) channel is enabled, data is written into FIFO + stCofigRegArr[index].usRegAddr = 0x010A + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0040 | (stSlotConfig.Slot_Mutiple << 8) | (stSlotConfig.PD_N << 2); + + //Set ADC and PD one-to-one correspondence connection, ADCx is connected to PDx + stCofigRegArr[index].usRegAddr = 0x010C + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0201; + + stCofigRegArr[index].usRegAddr = 0x010E + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0804; + + GU16 temp = 0; + for (temp = 0, i = 0; i < MAX_ADC_NUM; i++) + temp |= stSlotConfig.TIA_RF << (4 * i); + //slot_cfgN ADCN TIA gain is TIA_RF + stCofigRegArr[index].usRegAddr = 0x0112 + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = temp; + + for (temp = 0, i = 0; i < MAX_ADC_NUM; i++) + temp |= stSlotConfig.TIA_CF << (4 * i); + //slot_cfgN ADCN TIA capacitance is TIA_CF + stCofigRegArr[index].usRegAddr = 0x0114 + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = temp; + } + + //ADC integration times is ADC_int, bg suppression is bg_level, automatically dimming LED_ACG, turning off DC cancel and BG cancel + stCofigRegArr[index].usRegAddr = 0x0110 + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = (stSlotConfig.LED_ACG << 8) | (stSlotConfig.ADC_N << 6) | (stSlotConfig.BG_Level << 4) | stSlotConfig.ADC_IntTimes; + + //LED DRV0 current is 0, not mapped to led + stCofigRegArr[index].usRegAddr = 0x011E + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0400; + + //LED DRV1 current is 0, not mapped to led + stCofigRegArr[index].usRegAddr = 0x0120 + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = 0x0400; + + //LEDN current is LED_DRV + stCofigRegArr[index].usRegAddr = 0x011E + SLOT_CFG_INDEX*stSlotConfig.Slot_Cfg_N + (stSlotConfig.LED_N / 4) * 2; + stCofigRegArr[index++].usRegValue = ((stSlotConfig.LED_N % 4) << 8) | stSlotConfig.LED_Drv; + + //slot running time + stCofigRegArr[index].usRegAddr = 0x01EC + 2 * stSlotConfig.Slot_Cfg_N; + stCofigRegArr[index++].usRegValue = stSlotConfig.Slot_TMR; + + ret = gh3x2x_demo_mp_set_chip_config(stCofigRegArr, index); + + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_set_slot_enable(GU8 uchSlotConfigEnable) + * + * @brief Calculate which slots need to be enabled according to SLOT_CFG_EN, + * @brief enable the corresponding slot, and output the number of enabled slots + * + * @attention None + * + * @param[in] GU8 uchSlotConfigEnable + * @param[out] GU8 uchSlotEnableNum + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_slot_enable(GU8 uchSlotConfigEnable, GU8 *uchSlotEnableNum) +{ + GU8 ret = 1; + GU16 i = 0; + GU8 index = 0; + GU8 SlotMap[MAX_SLOT_NUM]; + stGh3x2xReg stCofigRegArr[20] = {0}; + + memset(SlotMap, 0x08, MAX_SLOT_NUM); //init close all slot + + for (i = 0; i < MAX_SLOT_NUM; i++) + { + //Enable the corresponding slot according to the value of SLOT_CFG_EN + if (uchSlotConfigEnable & (1 << i)) + SlotMap[(*uchSlotEnableNum)++] = i; + } + + for (i = 0; i < MAX_SLOT_NUM / 2; i++) + { + //set slot_index + stCofigRegArr[index].usRegAddr = 0x0100 + i * 2; + stCofigRegArr[index++].usRegValue = ((SlotMap[1 + 2 * i] & 0x0F) << 8) | (SlotMap[0 + 2 * i] & 0x0F); + } + //slot_cfg enable + stCofigRegArr[index].usRegAddr = 0x0108; + stCofigRegArr[index++].usRegValue = uchSlotConfigEnable; + + if(!gh3x2x_demo_mp_set_chip_config(stCofigRegArr, index)) + { + ret = 0; + GH3X2X_MP_LOG_L1("Gh3x2x mp set chip reg config fail! \r\n "); + } + + return ret; + +} + +/** + * @fn GU8 gh3x2x_demo_mp_set_LED_ACG_cfg(GU8 uchLED_N, GU8 uchLED_ACG_FS, stGh3x2xMp_PPGTestParam *pstTestPara) + * + * @brief The automatic dimming test needs to adjust the LED driver gear to avoid the failure of the automatic dimming step by too large + * + * @attention None + * + * @param[in] GU8 uchSlotConfigEnable + * @param[out] GU8 *uchSlotEnableNum + * + * @return ret + */ +GU8 gh3x2x_demo_mp_set_LED_ACG_cfg(GU8 uchLED_N, GU8 uchLED_ACG_FS, stGh3x2xMp_PPGTestParam *pstTestPara) +{ + GU8 ret = 1; + GU8 fs_temp = uchLED_ACG_FS & 0x03;//LED_ACG_FS range is 0~3 + stGh3x2xReg stCofigRegArr[20] = { 0 }; + int index = 0; + + if (uchLED_N < 4) + { + stCofigRegArr[index].usRegAddr = 0x0692; + stCofigRegArr[index++].usRegValue = 0x0202 | (fs_temp << 4); + } + else + { + stCofigRegArr[index].usRegAddr = 0x0692; + stCofigRegArr[index++].usRegValue = 0x0220 | fs_temp ; + } + + //mixdata trigger down dimming threshold + stCofigRegArr[index].usRegAddr = 0x0282; + stCofigRegArr[index++].usRegValue = stGh3x2xPPG_AutoDimming.LED_Max_Rawdata; + + //rawdata triggers the upward dimming threshold + stCofigRegArr[index].usRegAddr = 0x0284; + stCofigRegArr[index++].usRegValue = stGh3x2xPPG_AutoDimming.LED_Min_Rawdata; + + //Dimming end upper threshold + stCofigRegArr[index].usRegAddr = 0x0286; + stCofigRegArr[index++].usRegValue = stGh3x2xPPG_AutoDimming.LED_Ref_Up; + + //Lower threshold of dimming end + stCofigRegArr[index].usRegAddr = 0x0288; + stCofigRegArr[index++].usRegValue = stGh3x2xPPG_AutoDimming.LED_Ref_Down; + + ret = gh3x2x_demo_mp_set_chip_config(stCofigRegArr, index); + + return ret; +} + +/** + * @fn void gh3x2x_demo_mp_sampling_mode(GU8 uchMode) + * + * @brief rawdata sampling start / stop + * + * @attention None + * + * @param[in] GU8 uchMode + * @param[out] + * + * @return None + */ +void gh3x2x_demo_mp_sampling_mode(GU8 uchMode) +{ + if(START_SAMPLING == uchMode) //start + { + gh3x2x_demo_mp_write_reg(0x0508, 0x7FFF); //clear int + gh3x2x_mp_delay_ms(10); + GH3x2xMp_IntFlag = 0; + gh3x2x_demo_mp_write_reg_mask(0x00, 0x01, 0x01); //Trigger the chip to start collecting rawdata + } + else //stop + { + gh3x2x_demo_mp_write_reg_mask(0x00, 0x01, 0x00); //stop get rawdata + } +} + +/** + * @fn GU8 gh3x2x_demo_mp_get_rawdata(GU16 uchRegAddr, GU8 uchRawdataArr[], GU32 usLength) + * + * @brief get rawdata + * + * @attention None + * + * @param[in] GU16 uchRegAddr, GU32 usLength + * @param[out] GU8 uchRawdataArr[] + * + * @return ret + */ +GU8 gh3x2x_demo_mp_get_rawdata(GU16 uchRegAddr, GU8 uchRawdataArr[], GU32 usLength) +{ + GU8 ret = 1; + GU32 i = 0; + GU16 read_len = 0; + GU16 read_byte_num = 0; + + if(usLength > RAWDATA_BUF_SIZE) + { + //error, over max read_byte_num + GH3X2X_MP_LOG_L1("Gh3x2x mp get rawdata error, over read rawdata max num! \r\n "); + ret = 0; + return ret; + } + + + //get rawdata + for(i = 0; i < usLength; i += read_byte_num) + { + if(!gh3x2x_demo_mp_wait_for_int(0x30, 200)) + { + //error, wait for no int, exit the loop + GH3X2X_MP_LOG_L1("Gh3x2x mp get rawdata error, wait int over time! \r\n "); + ret = 0; + break; + } + read_len = gh3x2x_demo_mp_read_reg(0x050A); //read rawdata len from fifo cache + read_byte_num = read_len*4; //One sample rawdata has 4 bytes + gh3x2x_demo_mp_read_regs(uchRegAddr, uchRawdataArr + i, read_byte_num); + + if(0 == read_byte_num) + { + //error, read num ==0 + GH3X2X_MP_LOG_L1("Gh3x2x mp get rawdata error, read rawdata num equal 0! \r\n "); + ret = 0; + break; + } + if(read_byte_num > READ_RAWDATA_FIFO_MAX_BYTE_NUM) + { + //error, over max read_byte_num + GH3X2X_MP_LOG_L1("Gh3x2x mp get rawdata error, over max read rawdata fifo byte num! \r\n "); + ret = 0; + break; + } + } + + + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_handle_rawdata(GU8 uchMode, GS32 nHandleRawdataArr[], GU32 unHandleRawdataSkipLength, GU8 uchSlot_N, GU8 uchADC_N, \ + GU8 uchRawdataArr[], GU32 unRawdataArrLength, GU8 uchSampleStep) + * + * @brief handle rawdata + * + * @attention None + * + * @param[in] GU8 uchMode, GU32 unHandleRawdataSkipLength, GU8 uchSlot_N, GU8 uchADC_N, GU8 uchRawdataArr[], GU32 unRawdataArrLength,GU8 uchSampleStep + * @param[out] GS32 nHandleRawdataArr[] + * + * @return ret + */ +GU8 gh3x2x_demo_mp_handle_rawdata(GU8 uchMode, GS32 nHandleRawdataArr[], GU32 unHandleRawdataSkipLength, GU8 uchSlot_N, GU8 uchADC_N, \ + GU8 uchRawdataArr[], GU32 unRawdataArrLength, GU8 uchSampleStep) +{ + GU8 ret = 1; + GU32 i = 0; + GU8 cfg_temp = 0; + GU8 ADC_temp = 0; + GU8 ACG_temp = 0; + GU32 rawdata_buf_pt[MAX_SLOT_NUM][MAX_ADC_NUM] = {0}; + + + for(i = 0; i < unRawdataArrLength; i++) + { + cfg_temp = (uchRawdataArr[4 * i] >> 5) & 0x07; + ADC_temp = (uchRawdataArr[4 * i] >> 3) & 0x03; + ACG_temp = (uchRawdataArr[4 * i] >> 1) & 0x03; + + if((cfg_temp == uchSlot_N) && (ADC_temp == uchADC_N)) + { + if (cfg_temp >= MAX_SLOT_NUM || ADC_temp >= MAX_ADC_NUM)//Check if the rawdata format read is correct + { + ret = 0; + break; + } + if(__GH3X2X_MP_PRINT_RAWDATA__) + GH3X2X_MP_LOG("Gh3x2x mp handle rawdata, cfg: %d, adc: %d, acg: %d, rawdata number %d is: %d \r\n", cfg_temp, ADC_temp, ACG_temp, rawdata_buf_pt[cfg_temp][ADC_temp], (uchRawdataArr[4 * i + 1] << 16) | (uchRawdataArr[4 * i + 2] << 8) | (uchRawdataArr[4 * i + 3])); + + if (rawdata_buf_pt[cfg_temp][ADC_temp] >= unHandleRawdataSkipLength) + { + if(uchMode == SPEC_MODE_PPG) + { + if((rawdata_buf_pt[cfg_temp][ADC_temp] - unHandleRawdataSkipLength) < MAX_PPG_RAWDATA_SAMPLE_NUM) + nHandleRawdataArr[rawdata_buf_pt[cfg_temp][ADC_temp] - unHandleRawdataSkipLength] = (uchRawdataArr[4 * i + 1] << 16) | (uchRawdataArr[4 * i + 2] << 8) | (uchRawdataArr[4 * i + 3]); + else + { + GH3X2X_MP_LOG_L1("Gh3x2x mp handle ppg rawdata error, over max number of the rawdata sample! \r\n"); + ret = 0; + break; + } + } + else + { + if((rawdata_buf_pt[cfg_temp][ADC_temp] - unHandleRawdataSkipLength) < MAX_RAWDATA_SAMPLE_NUM) + nHandleRawdataArr[rawdata_buf_pt[cfg_temp][ADC_temp] - unHandleRawdataSkipLength] = (uchRawdataArr[4 * i + 1] << 16) | (uchRawdataArr[4 * i + 2] << 8) | (uchRawdataArr[4 * i + 3]); + else + { + GH3X2X_MP_LOG_L1("Gh3x2x mp handle ecg rawdata error, over max number of the rawdata sample! \r\n"); + ret = 0; + break; + } + i += (uchSampleStep - 1); + } + } + + (rawdata_buf_pt[cfg_temp][ADC_temp])++; + } + + } + + return ret; +} + +/** + * @fn gh3x2x_demo_mp_ppg_get_rawdata(GS32 unRawdataArr[][MAX_ADC_NUM][MAX_PPG_RAWDATA_SAMPLE_NUM], GU16 usRawdataLen, GU16 usRawdataSkipLen, GU16 usLED_PD_Num) + * + * @brief ppg test get rawdata + * + * @attention None + * + * @param[in] GU16 usRawdataLen, GU16 usRawdataSkipLen, GU16 usLED_PD_Num + * @param[out] GU32 unRawdataArr[][MAX_ADC_NUM][MAX_PPG_RAWDATA_SAMPLE_NUM] + * + * @return ret + */ +//GU8 cfg_temp[1200] = {0}; +//GU8 ADC_temp[1200] = {0}; +//GU8 ACG_temp[1200] = {0}; +//GU8 gh3x2x_demo_mp_ppg_get_rawdata(GS32 unRawdataArr[][MAX_ADC_NUM][MAX_PPG_RAWDATA_SAMPLE_NUM], GU16 usRawdataLen, GU16 usRawdataSkipLen, GU16 usLED_PD_Num) +//{ +// GU8 ret = 1; +// GU32 i = 0; +// GU32 rawdata_buf_pt[MAX_SLOT_NUM][MAX_ADC_NUM] = {0}; +// GU8 rawdata_buf[RAWDATA_BUF_SIZE] = {0}; +// if(usRawdataLen > MAX_PPG_RAWDATA_SAMPLE_NUM) +// usRawdataLen = MAX_PPG_RAWDATA_SAMPLE_NUM; //max is 500 +// GU32 rawdata_total_len = (usRawdataLen + usRawdataSkipLen)*usLED_PD_Num; + +// do +// { +// gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start +// if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, rawdata_buf, rawdata_total_len*4)) //every rawdata have 4 bytes +// { +// ret = 0; +// gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop +// GH3X2X_MP_LOG_L1("Gh3x2x mp ppg get rawdata error! \r\n "); +// break; +// } +// gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop +// +// //handle rawdata_buf +// GU8 cfg_temp = 0; +// GU8 ADC_temp = 0; +// GU8 ACG_temp = 0; +// +// for(i = 0; i < rawdata_total_len; i++) +// { +// cfg_temp = (rawdata_buf[4 * i] >> 5) & 0x07; +// ADC_temp = (rawdata_buf[4 * i] >> 3) & 0x03; +// ACG_temp = (rawdata_buf[4 * i] >> 1) & 0x03; +// +// if (cfg_temp >= MAX_SLOT_NUM || ADC_temp >= MAX_ADC_NUM)//Check if the rawdata format read is correct +// { +// ret = 0; +// break; +// } +// if(__GH3X2X_MP_PRINT_RAWDATA__) +// GH3X2X_MP_LOG("Gh3x2x mp rawdata cfg: %d, adc: %d, acg: %d, rawdata: %d \r\n", cfg_temp, ADC_temp, ACG_temp, (rawdata_buf[4 * i + 1] << 16) | (rawdata_buf[4 * i + 2] << 8) | (rawdata_buf[4 * i + 3])); +// +// if (rawdata_buf_pt[cfg_temp][ADC_temp] >= usRawdataSkipLen) +// unRawdataArr[cfg_temp][ADC_temp][rawdata_buf_pt[cfg_temp][ADC_temp] - usRawdataSkipLen] = (rawdata_buf[4 * i + 1] << 16) | (rawdata_buf[4 * i + 2] << 8) | (rawdata_buf[4 * i + 3]); +// +// (rawdata_buf_pt[cfg_temp][ADC_temp])++; +// } +// +// }while(0); +// +// return ret; +//} + +/** + * @fn void gh3x2x_demo_mp_calc_noise(GS32 nRawdataArr[], GU16 usLength, GF32 *fAvergeRawdata, GF32 *fNoise) + * + * @brief cal noise + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength + * @param[out] GF32 *fAvergeRawdata, GF32 *fNoise + * + * @return none + */ +void gh3x2x_demo_mp_calc_noise(GS32 nRawdataArr[], GU16 usLength, GF32 *fAvergeRawdata, GF32 *fNoise) +{ + GU32 i = 0; + + GD64 rawdata_sum = 0; + GD64 tmp_sum = 0.0; + + if(0 == usLength) + { + GH3X2X_MP_LOG_L1("Gh3x2x mp cal noise error, rawdata length == 0! \r\n"); + *fNoise = (float)0x7FFFFFFF; + return; + } + + for(i = 0; i < usLength; i++) + { + rawdata_sum += nRawdataArr[i]; + } + *fAvergeRawdata = 1.0 * rawdata_sum / usLength; + + for(i = 0; i < usLength; i++) + { + tmp_sum += pow(nRawdataArr[i] - (*fAvergeRawdata), 2); + } + *fNoise = 6.0 * sqrt(tmp_sum / usLength); + +} + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_signal_filter(GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType) + * + * @brief ECG signal filter + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType + uchLpType:Low pass filter cut-off frequency + uchHpType:High pass filter cut-off frequency + uchFsType:Sampling rate of rawdata,0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + * @param[out] GS32 nRawdataArr[]: filter data + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_signal_filter(GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType) +{ + GU32 i = 0; + GU8 ret = 1; + + GD64 filter_temp = nRawdataArr[0]; + for(i = 0; i < usLength; i++) + { + nRawdataArr[i] = nRawdataArr[i] - filter_temp; + } + + //filter + gh3x2x_mp_signal_filter(nRawdataArr, usLength, uchHpType, uchLpType, uchFsType); + + return ret; +} + +/** + * @fn GF32 gh3x2x_demo_mp_calc_LPCTR(GF32 fAverageRawdata, GU32 unTIA, GU32 unILed) + * + * @brief cal LP CTR + * + * @attention None + * + * @param[in] GF32 fAverageRawdata, GU32 unTIA, GU32 unILed + * @param[out] + * + * @return CTR + */ +GF32 gh3x2x_demo_mp_calc_LPCTR(GF32 fAverageRawdata, GU32 unTIA, GU32 unILed) +{ + GF32 fLP_CTR = 0.0; + fLP_CTR = 1.0 * (RAWDATA_TO_VOL((GD64)fAverageRawdata - ADC_OFFSET) / (2*Tia_Switch(unTIA)) / (unILed*100.0 / 255)); + + if((GD64)fLP_CTR < 0.00001) + fLP_CTR = 0.0; + + return fLP_CTR; +} + +/** + * @fn GF32 gh3x2x_demo_mp_ecg_cal_HPF_Ratio(GS32 nRawdataArr[], GU16 usLength) + * + * @brief cal HPF amplitude ratio + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength + * @param[out] + * + * @return HPF_Ratio + */ +GF32 gh3x2x_demo_mp_ecg_cal_HPF_Ratio(GS32 nRawdataArr[], GU16 usLength) +{ + GU16 i = 0; + GF32 fHPF_Ratio = 0.0; + GU32 sum[2] = { 0 }; + GU32 max = 0; + + GU16 start_index = 0; + + max = nRawdataArr[0]; + for (i = 0; i < usLength / 2 - 10; i++) + { + if (nRawdataArr[i] > max) + { + max = nRawdataArr[i]; + start_index = i; + } + } + for (i = start_index; i < start_index + 3; i++) + { + sum[0] += nRawdataArr[i]; + sum[1] += nRawdataArr[usLength / 2 + i]; + } + sum[0] = sum[0] / 3; + sum[1] = sum[1] / 3; + + fHPF_Ratio = (GF32)(sum[1] - 8388608.0) / (GF32)(sum[0] - 8388608); + + return fHPF_Ratio; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_cal_signal_amp_freq(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GF32 *fFreq, \ + GU8 uchLpType, GU8 uchHpType, GU8 uchFsType, GS16 sCalStart, GS16 sCalEnd, GF32 fRefFreq, GU8 uchStep) + * + * @brief Cal the amplitude and frequency of the signal + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GU8 uchLpType, GU8 uchHpType, GU8 uchFsType, GS16 sCalStart, GS16 sCalEnd, GF32 fRefFreq, GU8 uchStep + nRawdataArr:Data to be processed + usLength:Data len + uchLpType:Low pass filter cut-off frequency + uchHpType:High pass filter cut-off frequency + uchFsType:Sampling rate type of rawdata, 0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + sCalStart:FFT start begin point + sCalEnd:FFT start end point + fRefFreq:For reference frequency, find the maximum value near fref±5hz; if <0, find the maximum value between 0.1hz~fs/2 + * @param[out] GF32 *fAmp, GF32 *fFreq + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_cal_signal_amp_freq(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GF32 *fFreq, GU8 uchLpType, \ + GU8 uchHpType, GU8 uchFsType, GS16 sCalStart, GS16 sCalEnd, GF32 fRefFreq, GU8 uchStep) +{ + GU16 i = 0; + GU8 ret = 1; + GU16 fftlen = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); //Reuse GH3x2xMp_RawdataBuf memory + fArrHandle_Temp = (GF32 *)GH3x2xMp_RawdataBuf; //Reuse GH3x2xMp_RawdataBuf memory + + if(uchStep <= 0) + uchStep = 1; + + usLength = usLength / uchStep; //sampling + + if(usLength > MAX_RAWDATA_SAMPLE_NUM) + usLength = MAX_RAWDATA_SAMPLE_NUM; + + gh3x2x_demo_mp_ecg_signal_filter(nRawdataArr, usLength, uchLpType, uchHpType, uchFsType); + + for(i = 0; i < usLength; i++) + { + nRawdataArr[i] *= 100; //in order to keep two decimal places + } + + for(i = 0; i < usLength; i++) + { + nRawdataArr[i] = nRawdataArr[i]* ADC_REFER / ADC_MAX / GAIN * 1000; //uV + } + + + GU32 sampleRate = 500; + if (uchFsType == 0) + { + sampleRate = 250; + } + else if (uchFsType == 1) + { + sampleRate = 500; + } + else if (uchFsType == 2) + { + sampleRate = 1000; + } + else + { + sampleRate = 500; + } + sampleRate /= uchStep; + + + if (sCalEnd >= usLength || sCalEnd < sCalStart) + fftlen = usLength - sCalStart; + else + fftlen = sCalEnd - sCalStart; + + for(i = 0; i < fftlen; i++) + { + fArrHandle_Temp[i] = (GF32)nRawdataArr[i + sCalStart] / 100; + } + + //cal amp + GF32 amp_1=0; + GF32 freq_1=0; + gh3x2x_demo_mp_ecg_fft_cal_amp_freq(fArrHandle_Temp, fftlen, fftlen, sampleRate, &_1, &freq_1, fRefFreq, 1); + + //memset(fArrHandle_Temp, 0, 2*MAX_FFT_LENGTH*sizeof(GF32)); + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); //fArrHandle_Temp reuse GH3x2xMp_RawdataBuf memory + for(i = 0; i < fftlen; i++) + { + fArrHandle_Temp[i] = (GF32)nRawdataArr[i + sCalStart] / 100; + } + + //cal freq + GF32 amp_2=0; + GF32 freq_2=0; + GU32 fftlen_2 = MAX_FFT_LENGTH; + gh3x2x_demo_mp_ecg_fft_cal_amp_freq(fArrHandle_Temp, fftlen, fftlen_2, sampleRate, &_2, &freq_2, fRefFreq, 2); + + *fAmp = amp_1; + *fFreq = freq_2; + + fArrHandle_Temp = NULL; + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_cmmr_calculate(GS32 nRawdataArr[], GU16 usLength, GF32 *fCmmr, GU8 uchFsType, GF32 fRefFreq) + * + * @brief Cal the ecg-cmmr + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GU8 uchFsType, GF32 fRefFreq + nRawdataArr:Data to be processed + usLength:Data len + uchFsType:Sampling rate type of rawdata, 0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + fRefFreq:For reference frequency, find the maximum value near fref±5hz; if <0, find the maximum value between 0.1hz~fs/2 + * @param[out] GF32 *fCmmr + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_cmmr_calculate(GS32 nRawdataArr[], GU16 usLength, GF32 *fCmmr, GU8 uchFsType, GF32 fRefFreq) +{ + GU8 ret = 1; + + GF32 amp = 0; + GF32 freq = 0; + + gh3x2x_demo_mp_ecg_cal_signal_amp_freq(nRawdataArr, usLength, &, &freq, 1, 5, uchFsType, 200, -1, fRefFreq, 1); + + if (amp) + *fCmmr = (20 * log10((GF32)1e6 / amp)); + else + *fCmmr = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp cal cmmr freq: %.5f \r\n", freq); + + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_cal_signal_WaveTimeDomin_Amp(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GU8 uchFsType, GF32 fRefFreq) + * + * @brief Cal ecg-DCRange WaveTimeDomin Amp + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GU8 uchFsType, GF32 fRefFreq + nRawdataArr:Data to be processed + usLength:Data len + uchFsType:Sampling rate type of rawdata, 0,250Hz; 1,500Hz; 2,1000Hz; others, 500Hz + fRefFreq: Reference frequency + * @param[out] GF32 *fAmp + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_cal_signal_WaveTimeDomin_Amp(GS32 nRawdataArr[], GU16 usLength, GF32 *fAmp, GU8 uchFsType, GF32 fRefFreq) +{ + GU8 ret = 1; + GS32 i = 0; + GS32 j = 0; + + GU32 peakMax = 0; + GU32 peakMin = 0; + GU32 counter = 0; + GU32 temp = 0; + GU32 unT = 0, unT_0 = 0; + + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); //Reuse GH3x2xMp_RawdataBuf memory + fArrHandle_Temp = (GF32 *)GH3x2xMp_RawdataBuf; //Reuse GH3x2xMp_RawdataBuf memory + + + //Sampling rate selection + GU32 sampleRate = 500; + if(uchFsType == 0) + { + sampleRate = 250; + } + else if (uchFsType == 1) + { + sampleRate = 500; + } + else if(uchFsType == 2) + { + sampleRate = 1000; + } + else + { + sampleRate = 500; + } + + unT_0 = (GU32)sampleRate / fRefFreq; + unT = unT_0 + unT_0 / 4; + //find from the end + for (i = usLength - 1; i >= unT; i -= unT_0) + { + counter++; + //find min and max + peakMax = nRawdataArr[i]; + peakMin = nRawdataArr[i]; + for (j = 0; j < unT; j++) + { + temp = nRawdataArr[i - j]; + if (temp > peakMax) + peakMax = temp; + if (temp < peakMin) + peakMin = temp; + } + fArrHandle_Temp[counter - 1] = (GF32)(peakMax - peakMin); + } + + + //Minimum output amplitude + GF32 ampMin = 0; + for(i = 0; i < counter; i++) + { + ampMin += fArrHandle_Temp[i]; + } + ampMin = ampMin / counter; + + *fAmp = (GF32)ampMin * ADC_REFER / ADC_MAX / GAIN * 1000; //uV + + fArrHandle_Temp = NULL; + + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_LPCTR_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ---- LP CTR test + * + * @attention None + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_PPG_LPCTR_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 retry_time = 3; + GU8 i = 0; + GU8 LP_CTR_is_ok = 1; + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG CTR test start! \r\n"); + + //GS32 PPG_RawdataArr[MAX_PPG_RAWDATA_SAMPLE_NUM] = {0}; + GU32 RawdataBuf_Len = 0; + if((pstTestPara->PPG_CTRRawdata_Num > MAX_PPG_RAWDATA_SAMPLE_NUM) \ + || (0 == pstTestPara->PPG_CTRRawdata_Num)) //max is MAX_PPG_RAWDATA_SAMPLE_NUM + { + test_code = MT_ERROR_LED_LP_RAWDATA_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, CTR test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + + GU8 Slot_Cfg_EN = pstTestPara->stLEDPDConfig.LED_Channel; + GU8 LED_PD_NUM = 0; //Number of LED*PD to be tested + + if(SLOT_ONECH_MODE == pstTestPara->stCTRSlotConfig.Slot_Mode) + LED_PD_NUM = pstTestPara->stLEDPDConfig.PD_Num[0]; + else //SLOT_MULTICH_MODE + LED_PD_NUM = pstTestPara->stLEDPDConfig.LED_PD_Num; + + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + //write config to gh3x2x + for(i = 0; i < retry_time; i++) + { + if(gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegPPGConfig, sizeof(stGh3x2xMpRegPPGConfig) / sizeof(stGh3x2xMpRegPPGConfig[0]))) + { + break; + } + } + if( i == retry_time) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, CTR test set reg config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + //according to SLOT_CFG_EN cal which slots need to be enabled, and enable slot + GU8 SlotEnableNum = 0; + if(!gh3x2x_demo_mp_set_slot_enable(Slot_Cfg_EN, &SlotEnableNum) || SlotEnableNum < 1) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, CTR test set slot enable fail, error code is: %d! \r\n", test_code); + return test_code; + } + + //set slot config + for(i = 0; i < MAX_SLOT_NUM; i++) + { + //set the enabled slot config + if((Slot_Cfg_EN >> i) & 0x01) + { + pstTestPara->stCTRSlotConfig.Slot_Cfg_N = i; + pstTestPara->stCTRSlotConfig.PD_N = pstTestPara->stLEDPDConfig.PD_Channel[i]; + pstTestPara->stCTRSlotConfig.ADC_N = i % 4; //ADC value can only be 0~3 + pstTestPara->stCTRSlotConfig.LED_N = i; + + if(!gh3x2x_demo_mp_set_slot_config(pstTestPara->stCTRSlotConfig)) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, CTR test set slot config fail, error code is: %d! \r\n", test_code); + return test_code; + } + } + } + + //get rawdata + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + RawdataBuf_Len = (pstTestPara->PPG_CTRRawdata_Num + pstTestPara->PPG_CTRRawdata_SkipNum)*LED_PD_NUM; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, CTR test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //start cal noise and CTR, check CTR + GU16 usChannel = 0; //only 0~31, LED(x) PD(y) channel is:x*MAX_ADC_NUM + y + for(i = 0; i < MAX_SLOT_NUM; i++) + { + if(!((Slot_Cfg_EN >> i) & 0x01))//Only cal the slots that need to be tested + { + continue; + } + for(GU32 j = 0; j < MAX_ADC_NUM; j++) + { + if (!((pstTestPara->stLEDPDConfig.PD_Channel[i] >> j) & 0x01))//Only cal the PD that needs to be tested + { + continue; + } + + if(SLOT_MULTICH_MODE == pstTestPara->stCTRSlotConfig.Slot_Mode) + usChannel = i*MAX_ADC_NUM + j; + else + usChannel = j; + + //handle rawdata + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_PPG_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_PPG, GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_CTRRawdata_SkipNum, \ + i, j, GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_LED_LP_RAWDATA_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LP CTR handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + //calc noise, averge rawdata + gh3x2x_demo_mp_calc_noise(GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_CTRRawdata_Num, \ + &pstTestResult->stCTRRawHandleResult.AvergeRawdata[usChannel], &pstTestResult->stCTRRawHandleResult.Noise[usChannel]); + //calc CTR + pstTestResult->LED_LPCTR[usChannel] = gh3x2x_demo_mp_calc_LPCTR(pstTestResult->stCTRRawHandleResult.AvergeRawdata[usChannel], \ + pstTestPara->stCTRSlotConfig.TIA_RF, pstTestPara->stCTRSlotConfig.LED_Drv); + + //check + if(pstTestResult->LED_LPCTR[usChannel] < stGh3x2xMpLimit.PPG_CTR_MinLimit[usChannel]) + { + LP_CTR_is_ok = 0; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LP_CTR[%d]: %.5f less than min limit: %.5f !\r\n", usChannel, \ + pstTestResult->LED_LPCTR[usChannel], stGh3x2xMpLimit.PPG_CTR_MinLimit[usChannel]); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG test result info, LP_CTR[%d] is: %.5f, min limit is: %.5f, LP_CTR test is pass! \r\n", usChannel, \ + pstTestResult->LED_LPCTR[usChannel], stGh3x2xMpLimit.PPG_CTR_MinLimit[usChannel]); + } + } + } + if(!LP_CTR_is_ok) + { + test_code = MT_ERROR_LED_LP_RAWDATA_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LP CTR over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG--CTR test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_Noise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ---- noise test + * + * @attention PPG Noise test requires automatic dimming. + * @attention It is not possible to test all leds in parallel using multi-channel mode, only serial test + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +extern GU8 HPF_FirstFlag; +GU8 gh3x2x_demo_mp_PPG_Noise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GU8 L = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG--Noise test start! \r\n"); + + //GS32 PPG_RawdataArr[MAX_PPG_RAWDATA_SAMPLE_NUM] = {0}; + GU32 RawdataBuf_Len = 0; + if((pstTestPara->PPG_NoiseRawdata_Num > MAX_PPG_RAWDATA_SAMPLE_NUM) \ + || (0 == pstTestPara->PPG_NoiseRawdata_Num)) //max is MAX_PPG_RAWDATA_SAMPLE_NUM + { + test_code = MT_ERROR_LP_NOISE_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + GU8 Slot_Cfg_EN = 0; + GU8 LED_PD_NUM = 0; //Number of LED*PD to be tested + + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegPPGConfig, sizeof(stGh3x2xMpRegPPGConfig) / sizeof(stGh3x2xMpRegPPGConfig[0]))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise test set reg config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + for(L = 0; L < MAX_LED_NUM; L++) + { + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + Slot_Cfg_EN = pstTestPara->stLEDPDConfig.PD_Channel[L]; + if(0 == Slot_Cfg_EN) //judge current LED whether need test + continue; + LED_PD_NUM = pstTestPara->stLEDPDConfig.PD_Num[L]; + + //according to SLOT_CFG_EN cal which slots need to be enabled, and enable slot + GU8 SlotEnableNum = 0; + if(!gh3x2x_demo_mp_set_slot_enable(Slot_Cfg_EN, &SlotEnableNum) || SlotEnableNum < 1) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise test set slot enable fail, error code is: %d! \r\n", test_code); + return test_code; + } + + + if(!gh3x2x_demo_mp_set_LED_ACG_cfg(L, stGh3x2xPPG_AutoDimming.LED_ACG_FS[L], pstTestPara)) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise test set LED ACG config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + for (int j = 0; j < MAX_ADC_NUM; j++)//Configure each slot reg, because there are 4 PDs at most, so 4 slots are used at most + { + if ((Slot_Cfg_EN >> j) & 0x01) + { + pstTestPara->stNoiseSlotConfig.Slot_Cfg_N = j; + pstTestPara->stNoiseSlotConfig.PD_N = 1 << j; + pstTestPara->stNoiseSlotConfig.ADC_N = j % 4; //ADC only value is 0~3 + pstTestPara->stNoiseSlotConfig.LED_N = L; //Use the same LED for different slots in the same test + + if(!gh3x2x_demo_mp_set_slot_config(pstTestPara->stNoiseSlotConfig)) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise test set slot config fail, error code is: %d! \r\n", test_code); + return test_code; + } + } + } + + //get rawdata + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + RawdataBuf_Len = (pstTestPara->PPG_NoiseRawdata_Num + pstTestPara->PPG_NoiseRawdata_SkipNum)*LED_PD_NUM; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + GU16 usChannel = 0; //only 0~31, LED(x) PD(y) channel is:x*MAX_ADC_NUM + y + GF32 Noise_temp = 0; + GF32 AvergeRawdata_temp = 0; + for (i = 0; i < MAX_SLOT_NUM; i++) + { + if((Slot_Cfg_EN >> i) & 0x01) + { + usChannel = L*MAX_ADC_NUM + i; + //handle rawdata + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_PPG_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_PPG, GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_NoiseRawdata_SkipNum, \ + i, i, GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_LP_NOISE_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + //calc noise, averge rawdata + gh3x2x_demo_mp_calc_noise(GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_NoiseRawdata_Num, &pstTestResult->stNoiseRawHandleResult.AvergeRawdata[usChannel], \ + &pstTestResult->stNoiseRawHandleResult.Noise[usChannel]); + HPF_FirstFlag = 1; + for(int k = 0; k < pstTestPara->PPG_NoiseRawdata_Num; k++) + { + GH3x2xMp_RawdataHandleArr[k] = gh3x2x_mp_high_pass_filter((GD64)GH3x2xMp_RawdataHandleArr[k]); //filter + } + //calc noise, averge rawdata after filter + gh3x2x_demo_mp_calc_noise(GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_NoiseRawdata_Num, &AvergeRawdata_temp, &Noise_temp); + + //only need noise in filter + pstTestResult->stNoiseRawHandleResult.Noise[usChannel] = RAWDATA_TO_VOL((GD64)Noise_temp); + pstTestResult->LED_Noise[usChannel] = pstTestResult->stNoiseRawHandleResult.Noise[usChannel]; + + //check noise whether over limit + if((pstTestResult->LED_Noise[usChannel] > stGh3x2xMpLimit.PPG_Noise_MaxLimit) \ + || ((GD64)pstTestResult->LED_Noise[usChannel] <= 0.00001)) + { + test_code = MT_ERROR_LP_NOISE_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, Noise[%d]: %.5f more than max limit: %.5f or less than 0.00001, error code is: %d! \r\n", usChannel, \ + pstTestResult->LED_Noise[usChannel], stGh3x2xMpLimit.PPG_Noise_MaxLimit, test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG test result info, Noise[%d] is: %.5f, max limit is: %.5f, Noise test is pass! \r\n", usChannel, \ + pstTestResult->LED_Noise[usChannel], stGh3x2xMpLimit.PPG_Noise_MaxLimit); + } + } + } + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG--Noise test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_BaseNoise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ----base noise test + * + * @attention base noise test has nothing to do with LEDs, so only one slot is needed to test the data of 4 PDs. + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_PPG_BaseNoise_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GU8 j = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG--BaseNoise test start! \r\n"); + + //GS32 PPG_RawdataArr[MAX_PPG_RAWDATA_SAMPLE_NUM] = {0}; + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + if((pstTestPara->PPG_BaseNoiseRawdata_Num > MAX_PPG_RAWDATA_SAMPLE_NUM) \ + || (0 == pstTestPara->PPG_BaseNoiseRawdata_Num)) //max is MAX_PPG_RAWDATA_SAMPLE_NUM + { + test_code = MT_ERROR_LPBASE_NOISE_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseNoise test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + GU8 Slot_Cfg_EN = 0x01; //only open one slot + GU8 PD_Channel_EN = pstTestPara->stLEDPDConfig.PD_Channel_AllSlot; //PD channel to be tested + GU8 LED_PD_NUM = pstTestPara->stLEDPDConfig.PD_Num_AllSlot; //Number of PD to be tested + + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegPPGConfig, sizeof(stGh3x2xMpRegPPGConfig) / sizeof(stGh3x2xMpRegPPGConfig[0]))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseNoise test set reg config fail, error code is: %d! \r\n", test_code); + return test_code; + } + //according to SLOT_CFG_EN cal which slots need to be enabled, and enable slot + GU8 SlotEnableNum = 0; + if(!gh3x2x_demo_mp_set_slot_enable(Slot_Cfg_EN, &SlotEnableNum) || SlotEnableNum < 1) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseNoise test set slot enable fail, error code is: %d! \r\n", test_code); + return test_code; + } + + for(i = 0; i < MAX_SLOT_NUM; i++) //Timeslot register configuration, slot_cfgx corresponds to LEDx + { + if ((Slot_Cfg_EN >> i) & 0x01) + { + pstTestPara->stBaseNoiseSlotConfig.Slot_Cfg_N = i; + pstTestPara->stBaseNoiseSlotConfig.PD_N = PD_Channel_EN; + pstTestPara->stBaseNoiseSlotConfig.ADC_N = i % 4; //ADC only value is 0~3 + pstTestPara->stBaseNoiseSlotConfig.LED_N = i; //Use the same LED for different slots in the same test + + if(!gh3x2x_demo_mp_set_slot_config(pstTestPara->stBaseNoiseSlotConfig)) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseNoise test set slot config fail, error code is: %d! \r\n", test_code); + return test_code; + } + } + } + + //get rawdata + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + RawdataBuf_Len = (pstTestPara->PPG_BaseNoiseRawdata_Num + pstTestPara->PPG_BaseNoiseRawdata_SkipNum)*LED_PD_NUM; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseNoise test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + GU16 usChannel = 0; //only 0~31, LED(x) PD(y) channel is:x*MAX_ADC_NUM + y + for (i = 0; i < MAX_SLOT_NUM; i++) + { + if (!((Slot_Cfg_EN >> i) & 0x01))//Only calculate the slots that need to be tested + { + continue; + } + for(j = 0; j < MAX_ADC_NUM; j++) + { + if((PD_Channel_EN >> j) & 0x01) //Only calculate the PD that needs to be tested + { + if(SLOT_MULTICH_MODE == pstTestPara->stBaseNoiseSlotConfig.Slot_Mode) + usChannel = i*MAX_ADC_NUM + j; + else + usChannel = j; + + //handle rawdata + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_PPG_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_PPG, GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_BaseNoiseRawdata_SkipNum, \ + i, j, GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_LPBASE_NOISE_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseNoise test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + //calc noise, averge rawdata + gh3x2x_demo_mp_calc_noise(GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_BaseNoiseRawdata_Num, \ + &pstTestResult->stBaseNoiseRawHandleResult.AvergeRawdata[usChannel], &pstTestResult->stBaseNoiseRawHandleResult.Noise[usChannel]); + pstTestResult->stBaseNoiseRawHandleResult.Noise[usChannel] = RAWDATA_TO_VOL((GD64)pstTestResult->stBaseNoiseRawHandleResult.Noise[usChannel]); + + pstTestResult->LED_BaseNoise[usChannel] = pstTestResult->stBaseNoiseRawHandleResult.Noise[usChannel]; + pstTestResult->LED_DCOffset[usChannel] = RAWDATA_TO_VOL((GD64)pstTestResult->stBaseNoiseRawHandleResult.AvergeRawdata[usChannel] - ADC_OFFSET) / 1000; //Unit is mV + + //check base noise + if((pstTestResult->LED_BaseNoise[usChannel] > stGh3x2xMpLimit.PPG_BaseNoise_MaxLimit) \ + || ((GD64)pstTestResult->LED_BaseNoise[usChannel] <= 0.00001)) + { + test_code = MT_ERROR_LPBASE_NOISE_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseNoise[%d]: %.5f more than max limit: %.5f or less than 0.00001, error code is: %d! \r\n", usChannel, \ + pstTestResult->LED_BaseNoise[usChannel], stGh3x2xMpLimit.PPG_BaseNoise_MaxLimit, test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG test result info, BaseNoise[%d] is: %.5f, max limit is: %.5f, BaseNoise test is pass! \r\n", usChannel, \ + pstTestResult->LED_BaseNoise[usChannel], stGh3x2xMpLimit.PPG_BaseNoise_MaxLimit); + } + + //check dc_offset + if((pstTestResult->LED_DCOffset[usChannel] < stGh3x2xMpLimit.PPG_DCOffset_MinLimit) \ + || (pstTestResult->LED_DCOffset[usChannel] > stGh3x2xMpLimit.PPG_DCOffset_MaxLimit)) + { + test_code = MT_ERROR_LPBASE_DC_OFFSET_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, BaseDCOffset[%d]: %.5f more than max limit: %.5f or less than min limit: %.5f, error code is: %d! \r\n", \ + usChannel, pstTestResult->LED_DCOffset[usChannel], stGh3x2xMpLimit.PPG_DCOffset_MaxLimit, \ + stGh3x2xMpLimit.PPG_DCOffset_MinLimit, test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG test result info, BaseDCOffset[%d] is: %.5f, max limit is: %.5f and min limit is: %.5f, BaseDCOffset test is pass! \r\n", \ + usChannel, pstTestResult->LED_DCOffset[usChannel], stGh3x2xMpLimit.PPG_DCOffset_MaxLimit, stGh3x2xMpLimit.PPG_DCOffset_MinLimit); + } + } + } + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG--BaseNoise test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_PPG_LeakLight_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) + * + * @brief PPG test items ----leak light test + * + * @attention + * + * @param[in] stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_PPG_LeakLight_Test(stGh3x2xMp_PPGTestParam *pstTestPara, stGh3x2xMp_PPGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GU8 j = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG--LeakLight test start! \r\n"); + + //GS32 PPG_RawdataArr[MAX_PPG_RAWDATA_SAMPLE_NUM] = {0}; + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + if((pstTestPara->PPG_LeakLightRawdata_Num > MAX_PPG_RAWDATA_SAMPLE_NUM) \ + || (0 == pstTestPara->PPG_LeakLightRawdata_Num)) //max is MAX_PPG_RAWDATA_SAMPLE_NUM + { + test_code = MT_ERROR_LEAK_LEDLP_RAWDATA_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LeakLight test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + GU8 Slot_Cfg_EN = 0; + GU8 LED_PD_NUM = 0; //Number of LED*PD to be tested + if(SLOT_ONECH_MODE == pstTestPara->stLeakLightSlotConfig.Slot_Mode) + LED_PD_NUM = pstTestPara->stLEDPDConfig.PD_Num[0]; + else //SLOT_MULTICH_MODE + LED_PD_NUM = pstTestPara->stLEDPDConfig.LED_PD_Num; + + //must up the rubber before test + GU8 prompt_msg[] = PPG_PROMPT_UP_RUBBER_MSG; + gh3x2x_mp_prompt_message(prompt_msg, sizeof(prompt_msg) / sizeof(GU8)); + + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegPPGConfig, sizeof(stGh3x2xMpRegPPGConfig) / sizeof(stGh3x2xMpRegPPGConfig[0]))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LeakLight test set reg config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + //according to SLOT_CFG_EN cal which slots need to be enabled, and enable slot + GU8 SlotEnableNum = 0; + Slot_Cfg_EN = pstTestPara->stLEDPDConfig.LED_Channel; + if(!gh3x2x_demo_mp_set_slot_enable(Slot_Cfg_EN, &SlotEnableNum) || SlotEnableNum < 1) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LeakLight test set slot enable fail, error code is: %d! \r\n", test_code); + return test_code; + } + + for (i = 0; i < MAX_SLOT_NUM; i++) ////Timeslot register configuration, slot_cfgx corresponds to LEDx + { + if ((Slot_Cfg_EN >> i) & 0x01) + { + pstTestPara->stLeakLightSlotConfig.Slot_Cfg_N = i; + pstTestPara->stLeakLightSlotConfig.PD_N = pstTestPara->stLEDPDConfig.PD_Channel[i]; + pstTestPara->stLeakLightSlotConfig.ADC_N = i % 4; //ADC only value is 0~3 + pstTestPara->stLeakLightSlotConfig.LED_N = i; //Use the same LED for different slots in the same test + + if(!gh3x2x_demo_mp_set_slot_config(pstTestPara->stLeakLightSlotConfig)) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LeakLight test set slot config fail, error code is: %d! \r\n", test_code); + return test_code; + } + } + } + + //get rawdata + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + RawdataBuf_Len = (pstTestPara->PPG_LeakLightRawdata_Num + pstTestPara->PPG_LeakLightRawdata_SkipNum)*LED_PD_NUM; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LeakLight test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + GU16 usChannel = 0; //only 0~31, LED(x) PD(y) channel is:x*MAX_ADC_NUM + y + for (i = 0; i < MAX_SLOT_NUM; i++) + { + if (!((Slot_Cfg_EN >> i) & 0x01))//Only calculate the slots that need to be tested + { + continue; + } + for(j = 0; j < MAX_ADC_NUM; j++) + { + if((pstTestPara->stLEDPDConfig.PD_Channel[i] >> j) & 0x01) //Only calculate the PD that needs to be tested + { + if(SLOT_MULTICH_MODE == pstTestPara->stLeakLightSlotConfig.Slot_Mode) + usChannel = i*MAX_ADC_NUM + j; + else + usChannel = j; + + //handle rawdata + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_PPG_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_PPG, GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_LeakLightRawdata_SkipNum, \ + i, j, GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_LEAK_LEDLP_RAWDATA_ABNORMAL; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LeakLight test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + + //calc noise, averge rawdata + gh3x2x_demo_mp_calc_noise(GH3x2xMp_RawdataHandleArr, pstTestPara->PPG_LeakLightRawdata_Num, \ + &pstTestResult->stLeakLightRawHandleResult.AvergeRawdata[usChannel + LED0_LLPRAWDATA_INDEX], &pstTestResult->stLeakLightRawHandleResult.Noise[usChannel + LED0_LLPRAWDATA_INDEX]); + //calc leak light CTR + pstTestResult->LED_LLPCTR[usChannel] = gh3x2x_demo_mp_calc_LPCTR(pstTestResult->stLeakLightRawHandleResult.AvergeRawdata[usChannel + LED0_LLPRAWDATA_INDEX], \ + pstTestPara->stLeakLightSlotConfig.TIA_RF, pstTestPara->stLeakLightSlotConfig.LED_Drv); + + if(((GD64)pstTestResult->LED_LPCTR[usChannel] > 0.00001) \ + && ((GD64)stGh3x2xMpLimit.PPG_LeakRatio_Throld[usChannel] > 0.00001)) //check LPCTR and LeakRatio limit whether > 0 + { + pstTestResult->LED_LeakRatio[usChannel] = pstTestResult->LED_LLPCTR[usChannel] / pstTestResult->LED_LPCTR[usChannel]; + if(pstTestResult->LED_LeakRatio[usChannel] > stGh3x2xMpLimit.PPG_LeakRatio_Throld[usChannel] \ + && pstTestResult->LED_LLPCTR[usChannel] > stGh3x2xMpLimit.PPG_LeakCTR_MaxLimit[usChannel]) + { + //Requires two conditions to over limit, the test is fail + test_code = MT_ERROR_LEAK_AVGER_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LeakCTR[%d]: %.5f more than max limit: %.5f and LeakRadio[%d]: %.5f more than max limit: %.5f, error code is: %d! \r\n", \ + usChannel, pstTestResult->LED_LLPCTR[usChannel], stGh3x2xMpLimit.PPG_LeakCTR_MaxLimit[usChannel], \ + usChannel, pstTestResult->LED_LeakRatio[usChannel], stGh3x2xMpLimit.PPG_LeakRatio_Throld[usChannel], test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG test result info, LeakCTR[%d] is: %.5f, max limit is: %.5f, and LeakRadio[%d] is: %.5f, max limit: %.5f, LeakLight test is pass! \r\n", \ + usChannel, pstTestResult->LED_LLPCTR[usChannel], stGh3x2xMpLimit.PPG_LeakCTR_MaxLimit[usChannel], \ + usChannel, pstTestResult->LED_LeakRatio[usChannel], stGh3x2xMpLimit.PPG_LeakRatio_Throld[usChannel]); + } + } + else + { + test_code = MT_ERROR_LEAK_AVGER_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp PPG test fail, LPCTR: %.5f or LeakRatio_Throld: %.3f less than 0.00001, error code is: %d! \r\n", \ + pstTestResult->LED_LPCTR[usChannel], stGh3x2xMpLimit.PPG_LeakRatio_Throld[usChannel], test_code); + pstTestResult->LED_LeakRatio[usChannel] = 0; + } + + } + } + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp PPG--LeakLight test end! \r\n"); + return test_code; + +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_LeadOnOff_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----Lead on/off test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_LeadOnOff_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GU8 retry_times = 3; + GU8 ret_lead_on = 1; + GU8 ret_lead_off = 1; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--LeadOnOff test start! \r\n"); + + GU32 sample_num = pstTestPara->stECGSignal_LeadOnOff.Rawdata_Num; + GU32 skip_num = pstTestPara->stECGSignal_LeadOnOff.Rawdata_SkipNum; + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + + if((sample_num > MAX_RAWDATA_SAMPLE_NUM) || (sample_num <= 0)) + { + test_code = MT_ERROR_ECG_LEADONOFF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead on/off test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + //lead on test + //set ecg relay io status---lead on + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_LEAD_ON, pstTestPara->stECGSignal_LeadOnOff, NONE_SPEC)) + { + test_code = MT_ERROR_ECG_NOISE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead on test set ecg io status fail, error code is: %d! \r\n", test_code); + return test_code; + } + + //rst gh3x2x,set low and set high later + gh3x2x_demo_mp_reset_operation(); + + //wait int + //ret_lead_on = gh3x2x_demo_mp_wait_for_int(0x00, 100); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead on/off test set reg config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + + if(!gh3x2x_demo_mp_wait_for_int(0x02, 500)) + { + ret_lead_on = 0; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead on fail! \r\n"); + } + + //lead off test + //write reg + for(i = 0; i < retry_times; i++) + { + gh3x2x_demo_mp_write_reg(0x000A, 0x0020); //Test FIFO threshold can be adjusted down + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + if((0x0020 == gh3x2x_demo_mp_read_reg(0x000A)) && (0x0001 == gh3x2x_demo_mp_read_reg(0x0108))) + { + break; + } + } + if( i == retry_times) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead on/off test write reg fail, error code is: %d! \r\n", test_code); + return test_code; + } + + //set ecg relay io status---lead off + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_LEAD_OFF, pstTestPara->stECGSignal_LeadOnOff, NONE_SPEC)) + { + test_code = MT_ERROR_ECG_NOISE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead off test set ecg io status fail, error code is: %d! \r\n", test_code); + return test_code; + } + + //get rawdata + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + RawdataBuf_Len = sample_num + skip_num; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead on/off test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //lead off test according to GH3x2xMp_RawdataBuf + GH3X2X_Memcpy(GH3x2xMp_RawdataHandleArr, GH3x2xMp_RawdataBuf + skip_num*4, sample_num*sizeof(GS32)); + GU16 temp = 0; + if(0 == gh3x2x_mp_ecg_lead_off_dectection(GH3x2xMp_RawdataHandleArr, sample_num, 3, &temp)) + { + ret_lead_off = 0; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead off detect fail! \r\n"); + } + + //print rawdata + gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_ECG, GH3x2xMp_RawdataHandleArr, skip_num, 0, 3, GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1); + + if(!ret_lead_on || !ret_lead_off) + { + test_code = MT_ERROR_ECG_LEADONOFF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, lead on/off test fail, error code is: %d! \r\n", test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, lead on/off test pass! \r\n"); + } + + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--LeadOnOff test end! \r\n"); + return test_code; + +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_Noise_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----Noise test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_Noise_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + //GU8 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--Noise test start! \r\n"); + + GU32 sample_num = pstTestPara->stECGSignal_Noise.Rawdata_Num; + GU32 skip_num = pstTestPara->stECGSignal_Noise.Rawdata_SkipNum; + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + + //check noise test sample num must > 500 or < MAX_RAWDATA_SAMPLE_NUM + if((sample_num <= 500) || (sample_num > MAX_RAWDATA_SAMPLE_NUM)) + { + test_code = MT_ERROR_ECG_NOISE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, Noise test set the number of samples over limit(must greater than 500, \ + less than MAX_RAWDATA_SAMPLE_NUM), error code is: %d! \r\n", test_code); + return test_code; + } + + //set ecg io status---noise test + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_NOISE, pstTestPara->stECGSignal_Noise, NONE_SPEC)) + { + test_code = MT_ERROR_ECG_NOISE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, Noise test set ecg io status fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_mp_delay_ms(100); + + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, Noise test set reg lead config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGConfgDefault, sizeof(stGh3x2xMpRegECGConfgDefault) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, Noise test set reg default config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + + //get rawdata, The ECG test only collects data from one slot and ADC at a time, and LEDPDnum is fixed at 1. + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + gh3x2x_demo_mp_write_reg(0x1EA, 0x433); //Fast recovery, after sampling starts + RawdataBuf_Len = sample_num + skip_num; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, noise test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //ECG collection is fixed to slot0 ADC3, + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_ECG, GH3x2xMp_RawdataHandleArr, skip_num, 0, 3, \ + GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_ECG_NOISE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, noise test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + + //filter + gh3x2x_demo_mp_ecg_signal_filter(GH3x2xMp_RawdataHandleArr, sample_num, 1, 4, 1); + + //cal noise + GF32 avg_temp = 0; + gh3x2x_demo_mp_calc_noise(&GH3x2xMp_RawdataHandleArr[500], sample_num - 500, &avg_temp, &pstTestResult->ECG_Noise); + pstTestResult->ECG_Noise = pstTestResult->ECG_Noise * ADC_REFER / ADC_MAX * 1000 / GAIN;// /20; //? /GAIN + + //judge ECG_Noise whether over limit + if(pstTestResult->ECG_Noise > stGh3x2xMpLimit.ECG_Noise_MaxLimit) + { + test_code = MT_ERROR_ECG_NOISE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, Noise: %.5f more than max limit: %.5f, error code is: %d! \r\n", \ + pstTestResult->ECG_Noise, stGh3x2xMpLimit.ECG_Noise_MaxLimit, test_code); + return test_code; + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, Noise is: %.5f, max limit is: %.5f, Noise test is pass! \r\n", \ + pstTestResult->ECG_Noise, stGh3x2xMpLimit.ECG_Noise_MaxLimit); + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--Noise test end! \r\n"); + return test_code; + +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_HPF_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----HPF test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_HPF_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--HPF test start! \r\n"); + + GU16 sample_num = 0; + GU16 skip_num = 0; + + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + GU8 HPFRatio_cnt = 0; + + //HPF test must 2 signals in a group + if((pstTestPara->HPF_ECGSignalNum > ECG_MAX_SIGNAL_NUM) || (0 == pstTestPara->HPF_ECGSignalNum) \ + || (0 != (pstTestPara->HPF_ECGSignalNum % 2))) //must greater than 0 and a multiple of 2, not greater than ECG_MAX_SIGNAL_NUM + { + test_code = MT_ERROR_ECG_HPF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test set signal num error, error code is: %d! \r\n", test_code); + return test_code; + } + + + for(i = 0; i < pstTestPara->HPF_ECGSignalNum; i++) + { + sample_num = pstTestPara->stECGSignal_HPF[i].Rawdata_Num; + skip_num = pstTestPara->stECGSignal_HPF[i].Rawdata_SkipNum; + //check HPF test sample num must > 200 + if((sample_num < 200) || (sample_num > MAX_RAWDATA_SAMPLE_NUM)) + { + test_code = MT_ERROR_ECG_HPF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test set the number of samples over limit(must greater than 200, less than MAX_RAWDATA_SAMPLE_NUM), error code is: %d! \r\n", test_code); + return test_code; + } + + + //set ecg io status---HPF test + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_HPF, pstTestPara->stECGSignal_HPF[i], NONE_SPEC)) + { + test_code = MT_ERROR_ECG_HPF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test set ecg io status or signal voltage error, error code is: %d! \r\n", test_code); + return test_code; + } + + //tset before operation, chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test set reg lead config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGConfgDefault, sizeof(stGh3x2xMpRegECGConfgDefault) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test set reg default config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + + //get rawdata, The ECG test only collects data from one slot and ADC at a time, and LEDPDnum is fixed at 1. + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + //generation the other one signal channel + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_HPF, pstTestPara->stECGSignal_HPF[i], ECG_HPF_SPEC)) + { + test_code = MT_ERROR_ECG_HPF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test set signal voltage fail, error code is: %d! \r\n", test_code); + return test_code; + } + RawdataBuf_Len = sample_num + skip_num; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //ECG collection is fixed to slot0 ADC3, + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_ECG, GH3x2xMp_RawdataHandleArr, skip_num, 0, 3, \ + GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_ECG_HPF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + + //2 signals in a group, Calculate the latter one + if (0 == ((i + 1) % 2)) + { + GF32 ratio = gh3x2x_demo_mp_ecg_cal_HPF_Ratio(GH3x2xMp_RawdataHandleArr, sample_num); + pstTestResult->ECG_HPFRatio[HPFRatio_cnt++] = ratio; + if((ratio < stGh3x2xMpLimit.ECG_HPF_MinLimit) \ + || (ratio > stGh3x2xMpLimit.ECG_HPF_MaxLimit)) + { + test_code = MT_ERROR_ECG_HPF_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, HPF ratio%d: %.5f less than min limit: %.5f or more than max limit: %.5f, error code is: %d! \r\n", \ + HPFRatio_cnt-1, ratio, stGh3x2xMpLimit.ECG_HPF_MinLimit, stGh3x2xMpLimit.ECG_HPF_MaxLimit, test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, HPF ratio%d is: %.5f, min limit is: %.5f and max limit is: %.5f, HPF test is pass! \r\n", \ + HPFRatio_cnt-1, ratio, stGh3x2xMpLimit.ECG_HPF_MinLimit, stGh3x2xMpLimit.ECG_HPF_MaxLimit); + } + } + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--HPF test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_SIGNAL_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----SIGNAL test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_SIGNAL_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU32 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--SIGNAL test start! \r\n"); + + GU16 sample_num = 0; + GU16 skip_num = 0; + GU16 sampling_step = 1; + + GU32 RawdataBuf_Len[ECG_MAX_SIGNAL_NUM] = {0}; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + + GF32 nStandardAmp = 0.0; + + //not greater than ECG_MAX_SIGNAL_NUM + if((pstTestPara->SIGNAL_ECGSignalNum > ECG_MAX_SIGNAL_NUM) || (0 == pstTestPara->SIGNAL_ECGSignalNum)) + { + test_code = MT_ERROR_ECG_SIGNAL_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test set signal num error, error code is: %d! \r\n", test_code); + return test_code; + } + + + for(i = 0; i < pstTestPara->SIGNAL_ECGSignalNum; i++) + { + sample_num = pstTestPara->stECGSignal_SIGNAL[i].Rawdata_Num; + skip_num = pstTestPara->stECGSignal_SIGNAL[i].Rawdata_SkipNum; + sampling_step = pstTestPara->stECGSignal_SIGNAL[i].Sampling_Step; + + //check noise test sample num + if((sample_num <= 0) || (sampling_step <= 0)) + { + test_code = MT_ERROR_ECG_SIGNAL_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test set the number of samples or sampling step <= 0, error code is: %d! \r\n", test_code); + return test_code; + } + + //Check whether fft array need used space is in the range of GH3x2xMp_RawdataBuf + //fft array space reuse GH3x2xMp_RawdataBuf memory + if((MAX_FFT_LENGTH * 2 * 4) > (RAWDATA_BUF_SIZE / 2)) + { + test_code = MT_ERROR_ECG_SIGNAL_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test fft array need used space more than GH3x2xMp_RawdataBuf memory, error code is: %d! \r\n", test_code); + return test_code; + } + + //set ecg io status---SIGNAL test + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_SIGNAL, pstTestPara->stECGSignal_SIGNAL[i], NONE_SPEC)) + { + test_code = MT_ERROR_ECG_SIGNAL_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test set ecg io status or signal fail, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_mp_delay_ms(20); //wait + + //chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test set reg lead config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGConfgDefault, sizeof(stGh3x2xMpRegECGConfgDefault) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test set reg default config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + + //get rawdata, The ECG test only collects data from one slot and ADC at a time, and LEDPDnum is fixed at 1. + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + gh3x2x_demo_mp_write_reg(0x1EA, 0x433); //Fast recovery, after sampling starts + RawdataBuf_Len[i] = sample_num + skip_num; + + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len[i]*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //ECG collection is fixed to slot0 ADC3, + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_ECG, GH3x2xMp_RawdataHandleArr, skip_num, 0, 3, GH3x2xMp_RawdataBuf, \ + RawdataBuf_Len[i], sampling_step)) + { + test_code = MT_ERROR_ECG_SIGNAL_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + + //cal + gh3x2x_demo_mp_ecg_cal_signal_amp_freq(GH3x2xMp_RawdataHandleArr, sample_num, &pstTestResult->ECG_Amp[i], &pstTestResult->ECG_Freq[i], \ + 0, 0, 1, 0, sample_num, pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq, sampling_step); + + //check limit + if(i==0) //The first frequency data is processed separately + { + GF32 fTargetVpp = pstTestPara->stECGSignal_SIGNAL[i].ECG_Vol * 1000 / (GF32)5.7; + GF32 amp_difference = fabs(1 - pstTestResult->ECG_Amp[i] / fTargetVpp); + GF32 freq_difference = fabs(1 - pstTestResult->ECG_Freq[i] / pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq); + nStandardAmp = pstTestResult->ECG_Amp[i]; + if((amp_difference > stGh3x2xMpLimit.ECG_MaxAMP) \ + || (freq_difference > stGh3x2xMpLimit.ECG_MaxFreq)) + { + test_code = MT_ERROR_ECG_SIGNAL_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL %.2fHz test difference between amp: %.5fmV or freq: %.5fHz with target amp: %.5fmV or freq: %.2f more than MaxAmpRange: %.5f or MaxFreqRange: %.5f, error code is: %d! \r\n", \ + pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq, pstTestResult->ECG_Amp[i], pstTestResult->ECG_Freq[i], fTargetVpp, \ + pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq, stGh3x2xMpLimit.ECG_MaxAMP, stGh3x2xMpLimit.ECG_MaxFreq, test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, SIGNAL %.2fHz test difference between amp: %.5fmV freq: %.5fHz with target amp: %.5fmV freq: %.2f is pass, MaxAmpRange is: %.5f or MaxFreqRange is: %.5f !\r\n", \ + pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq, pstTestResult->ECG_Amp[i], pstTestResult->ECG_Freq[i], fTargetVpp, \ + pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq, stGh3x2xMpLimit.ECG_MaxAMP, stGh3x2xMpLimit.ECG_MaxFreq); + } + + } + else + { + GF32 amp_difference = fabs(1 - pstTestResult->ECG_Amp[i] / nStandardAmp); + if(amp_difference > stGh3x2xMpLimit.ECG_SIGNAL_MaxLimit) + { + test_code = MT_ERROR_ECG_SIGNAL_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, SIGNAL %.2fHz test difference between amp: %.5fmV with Standard amp: %.5fmV over more than MaxRange: %.5f, freq cal is: %.5fHz, error code is: %d! \r\n", \ + pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq, pstTestResult->ECG_Amp[i], nStandardAmp, \ + stGh3x2xMpLimit.ECG_SIGNAL_MaxLimit, pstTestResult->ECG_Freq[i], test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, SIGNAL %.2fHz test difference between amp: %.5fmV with Standard amp: %.5fmV is pass, MaxRange is: %.5f, freq cal is: %.5fHz! \r\n", \ + pstTestPara->stECGSignal_SIGNAL[i].ECG_Freq, pstTestResult->ECG_Amp[i], nStandardAmp, \ + stGh3x2xMpLimit.ECG_SIGNAL_MaxLimit, pstTestResult->ECG_Freq[i]); + } + } + } + + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--SIGNAL test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_RLD_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----RLD test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_RLD_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--RLD test start! \r\n"); + + GU32 sample_num = pstTestPara->stECGSignal_RLD.Rawdata_Num; + //GU32 skip_num = pstTestPara->stECGSignal_RLD.Rawdata_SkipNum; + //GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + + //check RLD test sample num + if((sample_num > MAX_RAWDATA_SAMPLE_NUM) || (sample_num <= 0)) + { + test_code = MT_ERROR_ECG_RLD_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, RLD test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + //set ecg io status---RLD test + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_RLD, pstTestPara->stECGSignal_RLD, NONE_SPEC)) + { + test_code = MT_ERROR_ECG_RLD_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, RLD test set ecg io status fail, error code is: %d! \r\n", test_code); + return test_code; + } + + //chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, RLD test set reg lead config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + gh3x2x_mp_delay_ms(100); //Discard a frame of data + + //send cmd to ecg_board for get adc, reuse GH3x2xMp_RawdataBuf array + GH3x2xMp_RawdataBuf[0] = 0x55; + GH3x2xMp_RawdataBuf[1] = UART_CMD_GETADC; + GH3x2xMp_RawdataBuf[2] = 0; + GH3x2xMp_RawdataBuf[3] = 0; + gh3x2x_mp_ecg_uart_send(GH3x2xMp_RawdataBuf, 4); + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + //time out 10ms for rev data + GU16 rev_len = gh3x2x_mp_ecg_uart_receive(GH3x2xMp_RawdataBuf, 10); + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + if(rev_len < 4) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, RLD test rev data error through uart, error code is: %d! \r\n", test_code); + return test_code; + } + + //check limit + pstTestResult->ECG_RLD = (GF32)(GH3x2xMp_RawdataBuf[5] << 8) + GH3x2xMp_RawdataBuf[4]; + GF32 MinRLDThrshold = stGh3x2xMpLimit.ECG_RLD_MaxAmp * (1 - 0.2); + GF32 MaxRLDThrshold = stGh3x2xMpLimit.ECG_RLD_MaxAmp * (1 + 0.2); + if((pstTestResult->ECG_RLD > MaxRLDThrshold) || (pstTestResult->ECG_RLD < MinRLDThrshold)) + { + test_code = MT_ERROR_ECG_RLD_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, RLD test amp: %.2fmV less than min limit: %.2fmV or more than max limit: %.2fmV, error code is: %d! \r\n", \ + pstTestResult->ECG_RLD, MinRLDThrshold, MaxRLDThrshold, test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, RLD amp is: %.2fmV, min limit is: %.2fmV and max limit is: %.2fmV, RLD test is pass! \r\n", \ + pstTestResult->ECG_RLD, MinRLDThrshold, MaxRLDThrshold); + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--RLD test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_CMRR_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----CMRR test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_CMRR_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--CMRR test start! \r\n"); + + GU32 sample_num = 0; + GU32 skip_num = 0; + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + + //not greater than ECG_MAX_SIGNAL_NUM + if((pstTestPara->CMRR_ECGSignalNum > ECG_MAX_SIGNAL_NUM) || (0 == pstTestPara->CMRR_ECGSignalNum)) + { + test_code = MT_ERROR_ECG_CMMR_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test set signal num error, error code is: %d! \r\n", test_code); + return test_code; + } + + //Check whether fft array need used space is in the range of GH3x2xMp_RawdataBuf + //fft array space reuse GH3x2xMp_RawdataBuf memory + if((MAX_FFT_LENGTH * 2 * 4) > (RAWDATA_BUF_SIZE / 2)) + { + test_code = MT_ERROR_ECG_CMMR_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test fft array need used space more than GH3x2xMp_RawdataBuf memory, error code is: %d! \r\n", test_code); + return test_code; + } + + + for(i = 0; i < pstTestPara->CMRR_ECGSignalNum; i++) + { + sample_num = pstTestPara->stECGSignal_CMRR[i].Rawdata_Num; + skip_num = pstTestPara->stECGSignal_CMRR[i].Rawdata_SkipNum; + //check RLD test sample num must > 200, < MAX_RAWDATA_SAMPLE_NUM + if((sample_num > MAX_RAWDATA_SAMPLE_NUM) || (sample_num <= 200)) + { + test_code = MT_ERROR_ECG_CMMR_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test set the number of samples over limit(must greater than 200, less than MAX_RAWDATA_SAMPLE_NUM), error code is: %d! \r\n", test_code); + return test_code; + } + + //set ecg io status---CMRR test + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_CMMR, pstTestPara->stECGSignal_CMRR[i], NONE_SPEC)) + { + test_code = MT_ERROR_ECG_CMMR_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test set io status or signal fail, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_mp_delay_ms(20); //wait + + //chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test set reg lead config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGConfgDefault, sizeof(stGh3x2xMpRegECGConfgDefault) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test set reg default config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + + //get rawdata, The ECG test only collects data from one slot and ADC at a time, and LEDPDnum is fixed at 1. + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + gh3x2x_demo_mp_write_reg(0x1EA, 0x433); //Fast recovery, after sampling starts + RawdataBuf_Len = sample_num + skip_num; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //ECG collection is fixed to slot0 ADC3, + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_ECG, GH3x2xMp_RawdataHandleArr, skip_num, 0, 3, \ + GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_ECG_CMMR_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_ecg_cmmr_calculate(GH3x2xMp_RawdataHandleArr, sample_num, &pstTestResult->ECG_CMRR[i], \ + 1, pstTestPara->stECGSignal_CMRR[i].ECG_Freq); + + //check limit + if ((pstTestResult->ECG_CMRR[i] < stGh3x2xMpLimit.ECG_CMRR_MinLimit) \ + || (pstTestResult->ECG_CMRR[i] >= 1000)) + { + test_code = MT_ERROR_ECG_CMMR_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, CMRR%d is: %.5f less than min limit:%.5f or more than 1000, error code is: %d! \r\n", \ + i, pstTestResult->ECG_CMRR[i], stGh3x2xMpLimit.ECG_CMRR_MinLimit, test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, CMRR%d is: %.5f, min limit is:%.5f and max limit is 1000, CMRR test is pass! \r\n", \ + i, pstTestResult->ECG_CMRR[i], stGh3x2xMpLimit.ECG_CMRR_MinLimit); + } + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--CMRR test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_LIN_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----LIN test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_LIN_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--LIN test start! \r\n"); + + GU32 sample_num = 0; + GU32 skip_num = 0; + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + + GF32 LIN_Amp[ECG_MAX_SIGNAL_NUM] = {0}; //LIN test must two signals in a group + GF32 LIN_Freq = 0; + GF32 LIN_Ratio = 0; + GU8 LIN_RatioCnt = 0; + + if((pstTestPara->LIN_ECGSignalNum > ECG_MAX_SIGNAL_NUM) || (0 == pstTestPara->LIN_ECGSignalNum) \ + || (0 != (pstTestPara->LIN_ECGSignalNum % 2))) //must greater than 0 and a multiple of 2, not greater than ECG_MAX_SIGNAL_NUM + { + test_code = MT_ERROR_ECG_LIN_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test set signal num error, error code is: %d! \r\n", test_code); + return test_code; + } + + //Check whether fft array need used space is in the range of GH3x2xMp_RawdataBuf + //fft array space reuse GH3x2xMp_RawdataBuf memory + if((MAX_FFT_LENGTH * 2 * 4) > (RAWDATA_BUF_SIZE / 2)) + { + test_code = MT_ERROR_ECG_LIN_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test fft array need used space more than GH3x2xMp_RawdataBuf memory, error code is: %d! \r\n", test_code); + return test_code; + } + + for(i = 0; i < pstTestPara->LIN_ECGSignalNum; i++) + { + sample_num = pstTestPara->stECGSignal_LIN[i].Rawdata_Num; + skip_num = pstTestPara->stECGSignal_LIN[i].Rawdata_SkipNum; + //check LIN test sample num + if((sample_num > MAX_RAWDATA_SAMPLE_NUM) || (sample_num <= 0)) + { + test_code = MT_ERROR_ECG_LIN_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + //set ecg io status---LIN test + GU16 HighImpedance = (i % 2) ? 1 : 0; + pstTestPara->stECGSignal_LIN[i].bECG_HighImpedance = HighImpedance; + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_LIN, pstTestPara->stECGSignal_LIN[i], NONE_SPEC)) + { + test_code = MT_ERROR_ECG_LIN_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test set io status or signal fail, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_mp_delay_ms(20); //wait + + //chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test set reg lead config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGConfgDefault, sizeof(stGh3x2xMpRegECGConfgDefault) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test set reg default config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + + //get rawdata, The ECG test only collects data from one slot and ADC at a time, and LEDPDnum is fixed at 1. + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + gh3x2x_demo_mp_write_reg(0x1EA, 0x433); //Fast recovery, after sampling starts + RawdataBuf_Len = sample_num + skip_num; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //ECG collection is fixed to slot0 ADC3, + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_ECG, GH3x2xMp_RawdataHandleArr, skip_num, 0, 3, \ + GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_ECG_LIN_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + + //cal + gh3x2x_demo_mp_ecg_cal_signal_amp_freq(GH3x2xMp_RawdataHandleArr, sample_num, &LIN_Amp[i], &LIN_Freq, 0, 0, 1, \ + 0, sample_num, pstTestPara->stECGSignal_LIN[i].ECG_Freq, 1); + + GH3X2X_MP_LOG_L2("Gh3x2x mp LIN freq:%.5f \r\n", LIN_Freq); + if(i && (i % 2)) + { + if(LIN_Amp[i] > 0) + LIN_Ratio = fabs(LIN_Amp[i - 1] - LIN_Amp[i]) / LIN_Amp[i]; + else + LIN_Ratio = 1; + pstTestResult->ECG_LIN_Ratio[LIN_RatioCnt++] = LIN_Ratio; + + //check limit + if(LIN_Ratio > stGh3x2xMpLimit.ECG_LIN_MaxLimit) + { + test_code = MT_ERROR_ECG_LIN_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, LIN ratio%d: %.5f more than max limit: %.5f, amp[0] is: %.3f and amp[1] is: %.3f, error code is: %d! \r\n", \ + LIN_RatioCnt-1, LIN_Ratio, stGh3x2xMpLimit.ECG_LIN_MaxLimit, LIN_Amp[i - 1], LIN_Amp[i], test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, LIN ratio%d is: %.5f, max limit is: %.5f, LIN test is pass, amp[0] is: %.3f and amp[1] is: %.3f ! \r\n", \ + LIN_RatioCnt-1, LIN_Ratio, stGh3x2xMpLimit.ECG_LIN_MaxLimit, LIN_Amp[i - 1], LIN_Amp[i]); + } + } + } + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--LIN test end! \r\n"); + return test_code; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ECG_DCRange_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) + * + * @brief ECG test items ----DCRange test + * + * @attention + * + * @param[in] stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult + * @param[out] + * + * @return error code + */ +GU8 gh3x2x_demo_mp_ECG_DCRange_Test(stGh3x2xMp_ECGTestParam *pstTestPara, stGh3x2xMp_ECGTestResult *pstTestResult) +{ + GU8 test_code = 0; + GU8 i = 0; + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--DCRange test start! \r\n"); + + GU32 sample_num = 0; + GU32 skip_num = 0; + GU32 RawdataBuf_Len = 0; + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + + GF32 DCRange_Amp[ECG_MAX_SIGNAL_NUM] = {0}; //DCRange test must 3 signals in a group + GU8 DCRange_AmpCnt = 0; + //GF32 DCRange_Freq = 0; + GF32 DCRange_Ratio[2] = {0}; + GU8 DCRange_RatioCnt = 0; + + + //DCRange test must 3 signals in a group + if((pstTestPara->DCRange_ECGSignalNum > ECG_MAX_SIGNAL_NUM) || (0 == pstTestPara->DCRange_ECGSignalNum) \ + || (0 != (pstTestPara->DCRange_ECGSignalNum % 3))) //must greater than 0 and a multiple of 3, not greater than ECG_MAX_SIGNAL_NUM + { + test_code = MT_ERROR_ECG_DCRANGE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange test set signal num error, error code is: %d! \r\n", test_code); + return test_code; + } + + for(i = 0; i < pstTestPara->DCRange_ECGSignalNum; i++) + { + sample_num = pstTestPara->stECGSignal_DCRange[i].Rawdata_Num; + skip_num = pstTestPara->stECGSignal_DCRange[i].Rawdata_SkipNum; + //check DCRange test sample num + if((sample_num > MAX_RAWDATA_SAMPLE_NUM) || (sample_num <= 0)) + { + test_code = MT_ERROR_ECG_DCRANGE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange test set the number of samples over limit, error code is: %d! \r\n", test_code); + return test_code; + } + + //set ecg io status---LIN test + if(!gh3x2x_mp_ecg_signal_and_io_status_set(ECG_SIGNAL_AND_IO_STATUS_DC_RANGE, pstTestPara->stECGSignal_DCRange[i], NONE_SPEC)) + { + test_code = MT_ERROR_ECG_DCRANGE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange test set io status or signal fail, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_mp_delay_ms(20); //wait + + //chip resume + gh3x2x_demo_mp_send_cmd(GH3X2X_MP_CMD_RESUME); + gh3x2x_mp_delay_ms(5); + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGLeadConfg, sizeof(stGh3x2xMpRegECGLeadConfg) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange test set reg lead config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + if(!gh3x2x_demo_mp_set_chip_config(stGh3x2xMpRegECGConfgDefault, sizeof(stGh3x2xMpRegECGConfgDefault) / sizeof(stGh3x2xReg))) + { + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange test set reg default config fail, error code is: %d! \r\n", test_code); + return test_code; + } + + gh3x2x_demo_mp_write_reg(0x0108, 0x0001); //slotcfg0 enable + + //get rawdata, The ECG test only collects data from one slot and ADC at a time, and LEDPDnum is fixed at 1. + memset(GH3x2xMp_RawdataBuf, 0, RAWDATA_BUF_SIZE*sizeof(GU8)); + memset(GH3x2xMp_RawdataHandleArr, 0, MAX_RAWDATA_SAMPLE_NUM*sizeof(GS32)); + gh3x2x_demo_mp_sampling_mode(START_SAMPLING); //start + gh3x2x_demo_mp_write_reg(0x1EA, 0x433); //Fast recovery, after sampling starts + RawdataBuf_Len = sample_num + skip_num; + if(!gh3x2x_demo_mp_get_rawdata(0xAAAA, GH3x2xMp_RawdataBuf, RawdataBuf_Len*4)) //every rawdata have 4 bytes + { + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + test_code = MT_ERROR_COMMUNICATE_FAIL; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange test read rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + gh3x2x_demo_mp_sampling_mode(STOP_SAMPLING); //stop + + //ECG collection is fixed to slot0 ADC3, + if(!gh3x2x_demo_mp_handle_rawdata(SPEC_MODE_ECG, GH3x2xMp_RawdataHandleArr, skip_num, 0, 3, \ + GH3x2xMp_RawdataBuf, RawdataBuf_Len, 1)) + { + test_code = MT_ERROR_ECG_DCRANGE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange test handle rawdata error, error code is: %d! \r\n", test_code); + return test_code; + } + + //cal amp + gh3x2x_demo_mp_ecg_cal_signal_WaveTimeDomin_Amp(GH3x2xMp_RawdataHandleArr, sample_num, &DCRange_Amp[i], 1, \ + pstTestPara->stECGSignal_DCRange[i].ECG_Freq); + if(0 == ((i + 1) % 3)) + { + if(DCRange_Amp[i - 2] > (GF32)0.1) + { + DCRange_Ratio[0] = fabs(DCRange_Amp[i - 2] - DCRange_Amp[i - 1]) / DCRange_Amp[i - 2]; + DCRange_Ratio[1] = fabs(DCRange_Amp[i - 2] - DCRange_Amp[i]) / DCRange_Amp[i - 2]; + } + else + { + DCRange_Ratio[0] = 1; + DCRange_Ratio[1] = 1; + } + pstTestResult->ECG_DCRange_Ratio[DCRange_RatioCnt++] = DCRange_Ratio[0]; + pstTestResult->ECG_DCRange_Ratio[DCRange_RatioCnt++] = DCRange_Ratio[1]; + pstTestResult->ECG_DCRange_Amp[DCRange_AmpCnt++] = DCRange_Amp[i - 2]; + pstTestResult->ECG_DCRange_Amp[DCRange_AmpCnt++] = DCRange_Amp[i - 1]; + pstTestResult->ECG_DCRange_Amp[DCRange_AmpCnt++] = DCRange_Amp[i]; + + if(DCRange_Ratio[0] > stGh3x2xMpLimit.ECG_DCRange_MaxLimit \ + || DCRange_Ratio[1] > stGh3x2xMpLimit.ECG_DCRange_MaxLimit) + { + test_code = MT_ERROR_ECG_DCRANGE_ERR; + GH3X2X_MP_LOG_L1("Gh3x2x mp ECG test fail, DCRange ratio[%d]: %.5f and ratio[%d]: %.5f more than max limit: %.5f, amp[0] is: %.3f and amp[1] is: %.3f and amp[2] is: %.3f, error code is: %d! \r\n", \ + DCRange_RatioCnt-2, DCRange_Ratio[0], DCRange_RatioCnt-1, DCRange_Ratio[1], stGh3x2xMpLimit.ECG_DCRange_MaxLimit, \ + DCRange_Amp[i - 2], DCRange_Amp[i - 1], DCRange_Amp[i], test_code); + } + else + { + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG test result info, DCRange ratio[%d] is: %.5f and ratio[%d] is: %.5f, max limit is: %.5f, DCRange test is pass, amp[0] is: %.3f and amp[1] is: %.3f and amp[2] is: %.3f! \r\n", \ + DCRange_RatioCnt-2, DCRange_Ratio[0], DCRange_RatioCnt-1, DCRange_Ratio[1], stGh3x2xMpLimit.ECG_DCRange_MaxLimit, \ + DCRange_Amp[i - 2], DCRange_Amp[i - 1], DCRange_Amp[i]); + } + } + } + + + GH3X2X_MP_LOG_L2("Gh3x2x mp ECG--DCRange test end! \r\n"); + return test_code; + +} + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp_user.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp_user.c new file mode 100644 index 000000000..a4af30307 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_demo_mp_user.c @@ -0,0 +1,558 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_demo_mp_user.c + * + * @brief gh3x2x mp code must implemented interface by user + * + * @author Goodix Product Tools Development Team + * + */ + +/* includes */ +#include "stdint.h" +#include "string.h" +#include "gh3x2x_mp_config.h" +#include "gh3x2x_mp_common.h" + +#if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + + //use drv lib some interface + +#else //__GH3X2X_MP_USE_DRV_INTERFACE__ == 0, use mp lib interface define + +#if ( __GH3X2X_MP_INTERFACE__ == __GH3X2X_MP_INTERFACE_I2C__ ) + +/* i2c interface */ +/** + * @fn void gh3x2x_mp_i2c_init(void) + * + * @brief i2c init for gh3x2x mp + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_i2c_init(void) +{ + + /* code implement by user */ + GH3X2X_MP_LOG_L2("gh3x2x_mp i2c start init!"); + + GOODIX_MP_PLATFORM_I2C_INIT_ENTITY(); + + +} + +/** + * @fn GU8 gh3x2x_mp_i2c_write(GU8 device_id, const GU8 write_buffer[], GU16 length) + * + * @brief i2c write for gh3x2x mp + * + * @attention + * + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_i2c_write(GU8 device_id, const GU8 write_buffer[], GU16 length); +{ + GU8 ret = 1; + + /* code implement by user */ + + GOODIX_MP_PLATFORM_I2C_WRITE_ENTITY(device_id, write_buffer, length); + + return ret; +} + + +/** + * @fn uint8_t gh3x2x_mp_i2c_read(uint8_t device_id, const uint8_t write_buffer[], uint16_t write_length, + * uint8_t read_buffer[], uint16_t read_length) + * + * @brief i2c read for gh3x2x mp + * + * @attention + * + * @param[in] device_id device addr + * @param[in] write_buffer write data buffer + * @param[in] write_length write data len + * @param[in] read_length read data len + * @param[out] read_buffer pointer to read buffer + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_i2c_read(GU8 device_id, const GU8 write_buffer[], GU16 write_length, GU8 read_buffer[], GU16 read_length) +{ + GU8 ret = 1; + + /* code implement by user */ + + GOODIX_MP_PLATFORM_I2C_READ_ENTITY(device_id, write_buffer, write_length, read_buffer, read_length); + + return ret; +} + +/** + * @fn GU8 gh3x2x_mp_i2c_send_cmd(GU8 device_id, GU8 uchCmd) + * + * @brief i2c send cmd to gh3x2x mp + * + * @attention + * + * @param[in] GU8 device_id, GU8 uchCmd + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_i2c_send_cmd(GU8 device_id, GU8 uchCmd) +{ + GU8 ret = 1; + /* code implement by user */ + + GOODIX_MP_PLATFORM_I2C_SEND_CMD_ENTITY(device_id, uchCmd); + + return ret; +} + +#else // __GH3X2X_MP_INTERFACE__ == __GH3X2X_MP_INTERFACE_SPI__ + +/* spi interface */ +/** + * @fn void gh3x2x_mp_spi_init(void) + * + * @brief spi init for gh3x2x mp + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_spi_init(void) +{ + /* code implement by user */ + GH3X2X_MP_LOG_L2("gh3x2x_mp spi start init! \r\n"); + + GOODIX_MP_PLATFORM_SPI_INIT_ENTITY(); +} + +/** + * @fn GU8 gh3x2x_mp_spi_write(GU8 write_buffer[], GU16 length) + * + * @brief spi write for gh3x2x mp + * + * @param[in] write_buffer write data buffer + * @param[in] length write data len + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_spi_write(GU8 write_buffer[], GU16 length) +{ + GU8 ret = 1; + /* code implement by user */ + + + GOODIX_MP_PLATFORM_SPI_WRITE_ENTITY(write_buffer, length); + + return ret; +} + + +/** + * @fn GU8 gh3x2x_mp_spi_read(GU8 uchWriteBuffer[], GU16 usWriteLength, GU8 uchReadBuffer[], GU16 usReadLength) + * + * @brief spi read for gh3x2x mp + * + * @attention + * + * @param[in] GU8 uchWriteBuffer[], GU16 usWriteLength + * @param[out] GU8 uchReadBuffer[], GU16 usReadLength + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_spi_read(GU8 uchWriteBuffer[], GU16 usWriteLength, GU8 uchReadBuffer[], GU16 usReadLength) +{ + GU8 ret = 1; + + /* code implement by user */ + + GOODIX_MP_PLATFORM_SPI_READ_ENTITY(uchWriteBuffer, usWriteLength, uchReadBuffer, usReadLength); + + return ret; +} + + +/** + * @fn GU8 gh3x2x_mp_spi_send_cmd(GU8 uchCmd) + * + * @brief spi send cmd to gh3x2x + * + * @attention + * + * @param[in] GU8 uchCmd + * @param[out] None + * + * @return status + * @retval #1 return successfully + * @retval #0 return error + */ +GU8 gh3x2x_mp_spi_send_cmd(GU8 uchCmd) +{ + GU8 ret = 1; + /* code implement by user */ + + GOODIX_MP_PLATFORM_SPI_SEND_CMD_ENTITY(uchCmd); + + return ret; + +} + +#endif // __GH3X2X_MP_INTERFACE__ + + +/** + * @fn void gh3x2x_mp_reset_pin_init(void) + * + * @brief reset pin init for gh3x2x mp + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_reset_pin_init(void) +{ + /* code implement by user */ + GH3X2X_MP_LOG_L2("gh3x2x_mp reset pin start init! \r\n"); + + GOODIX_MP_PLATFORM_RESET_PIN_INIT_ENTITY(); +} + +/** + * @fn void gh3x2x_mp_reset_pin_ctrl(GU8 pin_level) + * + * @brief reset pin ctrl for gh3x2x + * + * @attention pin level set 1 [high level] or 0 [low level] + * + * @param[in] pin_level reset pin level + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_reset_pin_ctrl(GU8 pin_level) +{ + /* code implement by user */ + + GOODIX_MP_PLATFORM_RESET_PIN_CTRL_ENTITY(pin_level); + +} + +/** + * @fn void gh3x2x_mp_int_init(void) + * + * @brief gh3x2x int init + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_int_init(void) +{ + /* code implement by user */ + GH3X2X_MP_LOG_L2("gh3x2x_mp int pin start init! \r\n"); + + GOODIX_MP_PLATFORM_INT_INIT_ENTITY(); + +} + +/** + * @fn void gh3x2x_mp_int_handler_call_back(void) + * + * @brief call back of gh3x2x int handler, mp lib need make GH3x2xMp_IntFlag = 1 + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_int_handler_call_back(void) +{ +/****************** DO NOT MODITY ****************************************************************/ + GH3x2xMp_IntFlag = 1; //need do this +/****************** DO NOT MODITY ****************************************************************/ + + GOODIX_MP_PLATFORM_INT_HANDLER_CALL_BACK_ENTITY();//do nothing currently +} + +#endif //__GH3X2X_MP_USE_DRV_INTERFACE__ + +/** + * @fn void gh3x2x_mp_led_power_pin_init(void) + * + * @brief init led power pin + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_led_power_pin_init() +{ + /* code implement by user */ + + GOODIX_MP_PLATFORM_LED_POWER_PIN_INIT_ENTITY(); +} + +/** + * @fn gh3x2x_mp_led_power_on(void) + * + * @brief led power on + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_led_power_on() +{ + /* code implement by user */ + + GOODIX_MP_PLATFORM_LED_POWER_ON_ENTITY(); +} + +/** + * @fn void gh3x2x_mp_led_power_off(void) + * + * @brief led power off + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_led_power_off(void) +{ + /* code implement by user */ + + GOODIX_MP_PLATFORM_LED_POWER_OFF_ENTITY(); +} + +/** + * @fn void gh3x2x_mp_prompt_message(GU8 uchMsg[], GU16 usMsglen) + * + * @brief prompt message to do something + * + * @attention None + * + * @param[in] GU8 uchMsg[], GU16 usMsglen + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_prompt_message(GU8 uchMsg[], GU16 usMsglen) +{ + /* code implement by user */ + + GH3X2X_MP_LOG_L2("gh3x2x_mp prompt message: %s! \r\n", uchMsg); + + if(0 == memcmp(uchMsg, PPG_PROMPT_UP_RUBBER_MSG, usMsglen)) + GOODIX_MP_PLATFORM_PROMPT_UP_RUBBER_ENTITY(); /* code implement by user */ + + //test is OK msg + if(0 == memcmp(uchMsg, GH3X2X_MP_TEST_OK_MSG, usMsglen)) + GOODIX_MP_PLATFORM_PROMPT_TEST_OK_ENTITY(); /* code implement by user */ + + //test is NG msg + if(0 == memcmp(uchMsg, GH3X2X_MP_TEST_NG_MSG, usMsglen)) + GOODIX_MP_PLATFORM_PROMPT_TEST_NG_ENTITY(); /* code implement by user */ +} + +/** + * @fn GU8 gh3x2x_mp_ecg_uart_send(GU8 uchSendBuffer[], GU16 usLength) + * + * @brief Communicates with the ECG signal generator board through uart + * + * @attention None + * + * @param[in] GU8 uchSendBuffer[], GU16 usLength + + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_mp_ecg_uart_send(GU8 uchSendBuffer[], GU16 usLength) +{ + GU8 ret = 1; + /* code implement by user */ + + + ret = GOODIX_MP_PLATFORM_ECG_UART_SEND_ENTITY(uchSendBuffer, usLength); + + return ret; + +} + +/** + * @fn GU8 gh3x2x_mp_ecg_uart_receive(GU8 uchRevBuffer[], GU16 Timeout_ms) + * + * @brief Communicates with the ECG signal generator board through uart + * + * @attention None + * + * @param[in] GU8 uchRevBuffer[], GU16 Timeout_ms + + * @param[out] None + * + * @return usLength: The length of the data rev + */ +GU16 gh3x2x_mp_ecg_uart_receive(GU8 uchRevBuffer[], GU16 usTimeout_ms) +{ + GU16 usRevLength = 0; + /* code implement by user */ + + usRevLength = GOODIX_MP_PLATFORM_ECG_UART_RECEIVE_ENTITY(uchRevBuffer, usTimeout_ms); + + return usRevLength; +} + +/** + * @fn GU8 gh3x2x_mp_ecg_signal_and_io_status_set(emECG_SIGNAL_AND_IO_STATUS_SET emECG_Status, stGh3x2xMp_ECGSignalSetting stECGSignalSetting, emECG_SET_SIGNAL_SPEC uchSpec) + * + * @brief Set ECG signal and IO status according to ECG test item + * + * @attention + * + * @param[in] emECG_SIGNAL_AND_IO_STATUS_SET emECG_Status, stGh3x2xMp_ECGSignalSetting stECGSignalSetting, emECG_SET_SIGNAL_SPEC uchSpec + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_mp_ecg_signal_and_io_status_set(emECG_SIGNAL_AND_IO_STATUS_SET emECG_Status, stGh3x2xMp_ECGSignalSetting stECGSignalSetting, emECG_SET_SIGNAL_SPEC uchSpec) +{ + GU8 ret = 1; + /* code implement by user */ + + ret = GOODIX_MP_PLATFORM_ECG_SIGNAL_AND_IO_STATUS_SET_ENTITY(emECG_Status, stECGSignalSetting, uchSpec); + + return ret; +} + +/** + * @fn void gh3x2x_mp_log(GCHAR *log_string) + * + * @brief for print mp log + * + * @attention this function must define that print mp test log + * + * @param[in] log_string pointer to log string + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_log(GCHAR *log_string) +{ + +#if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + GH3X2X_PlatformLog(log_string); + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + GH3X2X_AFE_Log(log_string); + #endif +#else + GOODIX_MP_PLATFORM_LOG_ENTITY(log_string); +#endif + +} + +/** + * @fn void gh3x2x_mp_delay_us(GU16 usUsec) + * + * @brief Delay in us,user must register this function + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_delay_us(GU16 usUsec) +{ + +#if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + Gh3x2x_BspDelayUs(usUsec); + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + hal_gh3x2x_afe_DelayUs(usUsec); + #endif +#else + GOODIX_MP_PLATFORM_DELAY_US_ENTITY(usUsec); +#endif + +} + + +/** + * @fn void Gh3x2x_mp_delay_ms(GU16 usMsec) + * + * @brief Delay in ms + * + * @attention None + * + * @param[in] None + * @param[out] None + * + * @return None + */ +void gh3x2x_mp_delay_ms(GU16 usMsec) +{ + +#if ( __GH3X2X_MP_USE_DRV_INTERFACE__ == __GH3X2X_DRV_MODE__ ) + #if (__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_DRV_LIB_INTERFACE__) + Gh3x2x_BspDelayMs(usMsec); + #else //__GH3X2X_MP_USE_DRV_INTERFACE_TYPE__ == __GH3X2X_AFE_DRV_INTERFACE__ + hal_gh3x2x_afe_DelayMs(usMsec); + #endif +#else + GOODIX_MP_PLATFORM_DELAY_MS_ENTITY(usMsec); +#endif + + +} + + + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_algorithm.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_algorithm.c new file mode 100644 index 000000000..cb154f928 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_algorithm.c @@ -0,0 +1,1516 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_algorithm.c + * + * @brief algorithms needed for gh3x2x mp test + * + * @author Goodix Product Tools Development Team + * + */ + +#include "gh3x2x_mp_algorithm.h" +#include +#include +#include + +//high-pass-filter config +#define HIGH_PASS_FILTER_COEF_SIZE 7 +GU8 HPF_FirstFlag = 0; +GD64 HPF_CoefA[HIGH_PASS_FILTER_COEF_SIZE + 1] = {1.00000000000000, -5.80579309703828, 14.04773386830920, -18.13186088426856, 13.16715655966765, -5.10069928436602, 0.82346285235115, 0}; +GD64 HPF_CoefB[HIGH_PASS_FILTER_COEF_SIZE + 1] = {0.90744853978126, -5.44469123868758, 13.61172809671895, -18.14897079562527, 13.61172809671895, -5.44469123868758, 0.90744853978126, 0}; +GD64 HPF_ArrDataIn[HIGH_PASS_FILTER_COEF_SIZE] = {0}; +GD64 HPF_ArrDataOut[HIGH_PASS_FILTER_COEF_SIZE] = {0}; + +#define PI 3.14159265358979 + +//ECG signal filter define +// static const GS32 LP150HZ_STAGE_FS500 = 4; +#define LP150HZ_STAGE_FS500 4 +static const GD64 LP150HZ_SOS_FS500[LP150HZ_STAGE_FS500][6] = { + { 1,2,1,1,0.521309265637001,0.686992220901831 }, + { 1,2,1,1,0.404372288519084,0.308576213864916 }, + { 1,2,1,1,0.345121039357246,0.116835143825427 }, + { 1,2,1,1,0.319763902271563,0.034777724501379 }, +}; +static const GD64 LP150HZ_G_FS500[LP150HZ_STAGE_FS500 + 1] = { + 0.552075371634708, + 0.428237125596000, + 0.365489045795668, + 0.338635406693236, + 1.000000000000000 +}; + +// static const GS32 LP150HZ_STAGE_FS1000 = 4; +#define LP150HZ_STAGE_FS1000 4 +static const GD64 LP150HZ_SOS_FS1000[LP150HZ_STAGE_FS1000][6] = { + { 1,2,1,1,-1.015320986156612,0.727367235221825 }, + { 1,2,1,1,-0.811037098605681,0.379818727064831 }, + { 1,2,1,1,-0.702809498205855,0.195690935532604 }, + { 1,2,1,1,-0.655471917606866,0.115155433128685 }, +}; +static const GD64 LP150HZ_G_FS1000[LP150HZ_STAGE_FS1000 + 1] = { + 0.178011562266303, + 0.142195407114788, + 0.123220359331687, + 0.114920878880455, + 1.000000000000000 +}; + +static const GS32 LP120HZ_STAGE_FS1000 = 4; +#define LP120HZ_STAGE_FS1000 4 +static const GD64 LP120HZ_SOS_FS1000[LP120HZ_STAGE_FS1000][6] = { + { 1,2,1,1,-1.286171024111227,0.764370887483613 }, + { 1,2,1,1,-1.056235943388000,0.448945679767090 }, + { 1,2,1,1,-0.929107652628456,0.274550944551617 }, + { 1,2,1,1,-0.872288338066881,0.196606143603788 }, +}; +static const GD64 LP120HZ_G_FS1000[LP120HZ_STAGE_FS1000 + 1] = { + 0.119549965843096, + 0.098177434094773, + 0.086360822980790, + 0.081079451384227, + 1.000000000000000 +}; + +// static const GS32 LP120HZ_STAGE_FS500 = 4; +#define LP120HZ_STAGE_FS500 4 +static const GD64 LP120HZ_SOS_FS500[LP120HZ_STAGE_FS500][6] = { + {1,2,1,1,-0.105114653119978,0.674052928816841}, + {1,2,1,1,-0.080786840911068,0.286608894410455}, + {1,2,1,1,-0.068629935436961,0.092998369043934}, + {1,2,1,1,-0.063461628641803,0.010688064337096}, +}; +static const GD64 LP120HZ_G_FS500[LP120HZ_STAGE_FS500 + 1] = { + 0.392234568924216, + 0.301455513374847, + 0.256092108401743, + 0.236806608923823, + 1.000000000000000 +}; + +// static const GS32 LP120HZ_STAGE_FS250 = 4; +#define LP120HZ_STAGE_FS250 4 +static const GD64 LP120HZ_SOS_FS250[LP120HZ_STAGE_FS250][6] = { + { 1,2,1,1,1.936870401643021,0.952264591056672 }, + { 1,2,1,1,1.855059020399814,0.869802975343476 }, + { 1,2,1,1,1.796966165642348,0.811248400272168 }, + { 1,2,1,1,1.767018651463263,0.781062864124577 }, +}; +static const GD64 LP120HZ_G_FS250[LP120HZ_STAGE_FS250 + 1] = { + 0.972283748174923, + 0.931215498935822, + 0.902053641478629, + 0.887020378896960, + 1.000000000000000 +}; + +// static const GS32 LP55HZ_STAGE_FS1000 = 4; +#define LP55HZ_STAGE_FS1000 4 +static const GD64 LP55HZ_SOS_FS1000[LP55HZ_STAGE_FS1000][6] = { + { 1,2,1,1,-1.765114825012452,0.876023916371837 }, + { 1,2,1,1,-1.583717463961252,0.683228647261576 }, + { 1,2,1,1,-1.468233227639895,0.560488083173189 }, + { 1,2,1,1,-1.412490873045438,0.501243217687826 }, +}; +static const GD64 LP55HZ_G_FS1000[LP55HZ_STAGE_FS1000 + 1] = { + 0.027727272839846, + 0.024877795825081, + 0.023063713883323, + 0.022188086160597, + 1.000000000000000, +}; + +// static const GS32 LP55HZ_STAGE_FS500 = 4; +#define LP55HZ_STAGE_FS500 4 +static const GD64 LP55HZ_SOS_FS500[LP55HZ_STAGE_FS500][6] = { + { 1,2,1,1,-1.370586817292972,0.778797223984633 }, + { 1,2,1,1,-1.138016414472014,0.476958929832650 }, + { 1,2,1,1,-1.007207723826262,0.307190672281993 }, + { 1,2,1,1,-0.948221252636367,0.230635893057958 }, +}; +static const GD64 LP55HZ_G_FS500[LP55HZ_STAGE_FS500 + 1] = { + 0.102052601672915, + 0.084735628840159, + 0.074995737113933, + 0.070603660105398, + 1.000000000000000, +}; + +// static const GS32 LP55HZ_STAGE_FS250 = 4; +#define LP55HZ_STAGE_FS250 4 +static const GD64 LP55HZ_SOS_FS250[LP55HZ_STAGE_FS250][6] = { + { 1,2,1,1,-0.314494549237044,0.678366650017106 }, + { 1,2,1,1,-0.242450322262230,0.293887401730828 }, + { 1,2,1,1,-0.206282801447734,0.100871780645782 }, + { 1,2,1,1,-0.190873062731622,0.018634452179060 }, +}; +static const GD64 LP55HZ_G_FS250[LP55HZ_STAGE_FS250 + 1] = { + 0.340968025195015, + 0.262859269867149, + 0.223647244799512, + 0.206940347361860, + 1.000000000000000, +}; + +// static const GS32 LP45HZ_STAGE_FS1000 = 4; +#define LP45HZ_STAGE_FS1000 4 +static const GD64 LP45HZ_SOS_FS1000[LP45HZ_STAGE_FS1000][6] = { + { 1,2,1,1,-0.314494549237044,0.678366650017106 }, + { 1,2,1,1,-0.242450322262230,0.293887401730828 }, + { 1,2,1,1,-0.206282801447734,0.100871780645782 }, + { 1,2,1,1,-0.190873062731622,0.018634452179060 }, +}; +static const GD64 LP45HZ_G_FS1000[LP45HZ_STAGE_FS1000 + 1] = { + 0.340968025195015, + 0.262859269867149, + 0.223647244799512, + 0.206940347361860, + 1.000000000000000 +}; + +// static const GS32 LP45HZ_STAGE_FS500 = 4; +#define LP45HZ_STAGE_FS500 4 +static const GD64 LP45HZ_SOS_FS500[LP45HZ_STAGE_FS500][6] = { + { 1,2,1,1,-1.528839220975276,0.810717346659200 }, + { 1,2,1,1,-1.301278894960406,0.541200824533548 }, + { 1,2,1,1,-1.168196587814481,0.383581606779027 }, + { 1,2,1,1,-1.106929858571015,0.311018888677482 }, +}; +static const GD64 LP45HZ_G_FS500[LP45HZ_STAGE_FS500 + 1] = { + 0.070469531420981, + 0.059980482393286, + 0.053846254741137, + 0.051022257526617, + 1.000000000000000 +}; + +// static const GS32 LP45HZ_STAGE_FS250 = 4; +#define LP45HZ_STAGE_FS250 4 +static const GD64 LP45HZ_SOS_FS250[LP45HZ_STAGE_FS250][6] = { + { 1,2,1,1,-0.314494549237044,0.678366650017106 }, + { 1,2,1,1,-0.242450322262230,0.293887401730828 }, + { 1,2,1,1,-0.206282801447734,0.100871780645782 }, + { 1,2,1,1,-0.190873062731622,0.018634452179060 }, +}; +static const GD64 LP45HZ_G_FS250[LP45HZ_STAGE_FS250 + 1] = { + 0.340968025195015, + 0.262859269867149, + 0.223647244799512, + 0.206940347361860, + 1.000000000000000 +}; + +// static const GS32 HP0D05HZ_STAGE_FS1000 = 2; +#define HP0D05HZ_STAGE_FS1000 2 +static const GD64 HP0D05HZ_SOS_FS1000[HP0D05HZ_STAGE_FS1000][6] = { + { 1,-2,1,1,-1.999759483131749,0.999759581815928 }, + { 1,-2,1,1,-1.999419579147508,0.999419677814913 }, +}; +static const GD64 HP0D05HZ_G_FS1000[HP0D05HZ_STAGE_FS1000 + 1] = { + 0.999879766236919, + 0.999709814240605, + 1.000000000000000 +}; + +// static const GS32 HP0D05HZ_STAGE_FS500 = 2; +#define HP0D05HZ_STAGE_FS500 2 +static const GD64 HP0D05HZ_SOS_FS500[HP0D05HZ_STAGE_FS500][6] = { + { 1,-2,1,1,-1.999518826760270,0.999519221449531 }, + { 1,-2,1,1,-1.998839297808073,0.998839692363201 }, +}; +static const GD64 HP0D05HZ_G_FS500[HP0D05HZ_STAGE_FS500 + 1] = { + 0.999759512052450, + 0.999419747542819, + 1.000000000000000 +}; + +// static const GS32 HP0D05HZ_STAGE_FS250 = 2; +#define HP0D05HZ_STAGE_FS250 2 +static const GD64 HP0D05HZ_SOS_FS250[HP0D05HZ_STAGE_FS250][6] = { + { 1,-2,1,1,-1.999037095803727,0.999038674181191 }, + { 1,-2,1,1,-1.997679153411597,0.997680730716872 }, +}; +static const GD64 HP0D05HZ_G_FS250[HP0D05HZ_STAGE_FS250 + 1] = { + 0.999518942496230, + 0.998839971032118, + 1.000000000000000 +}; + +// static const GS32 HP0D5HZ_STAGE_FS1000 = 2; +#define HP0D5HZ_STAGE_FS1000 2 +static const GD64 HP0D5HZ_SOS_FS1000[HP0D5HZ_STAGE_FS1000][6] = { + { 1,-2,1,1,-1.997588562550215,0.997598420295188 }, + { 1,-2,1,1,-1.994202061864258,0.994211902897450 }, +}; +static const GD64 HP0D5HZ_G_FS1000[HP0D5HZ_STAGE_FS1000 + 1] = { + 0.998796745711351, + 0.997103491190427, + 1.000000000000000 +}; + +// static const GS32 HP0D5HZ_STAGE_FS500 = 2; +#define HP0D5HZ_STAGE_FS500 2 +static const GD64 HP0D5HZ_SOS_FS500[HP0D5HZ_STAGE_FS500][6] = { + { 1,-2,1,1,-1.995163241283863,0.995202624875511 }, + { 1,-2,1,1,-1.988418017374659,0.988457267818733 }, +}; +static const GD64 HP0D5HZ_G_FS500[HP0D5HZ_STAGE_FS500 + 1] = { + 0.997591466539843, + 0.994218821298348, + 1.000000000000000 +}; + +// static const GS32 HP0D5HZ_STAGE_FS250 = 2; +#define HP0D5HZ_STAGE_FS250 2 +static const GD64 HP0D5HZ_SOS_FS250[HP0D5HZ_STAGE_FS250][6] = { + { 1,-2,1,1,-1.990271241661729,0.990428397520602 }, + { 1,-2,1,1,-1.976891354287120,0.977047453642916 }, +}; +static const GD64 HP0D5HZ_G_FS250[HP0D5HZ_STAGE_FS250 + 1] = { + 0.995174909795583, + 0.988484701982509, + 1.000000000000000 +}; + +// static const GS32 HP0D67HZ_STAGE_FS1000 = 2; +#define HP0D67HZ_STAGE_FS1000 2 +static const GD64 HP0D67HZ_SOS_FS1000[HP0D67HZ_STAGE_FS1000][6] = { + { 1,-2,1,1,-1.996765507386640,0.996783200718337 }, + { 1,-2,1,1,-1.992233931075327,0.992251584252743 }, +}; +static const GD64 HP0D67HZ_G_FS1000[HP0D67HZ_STAGE_FS1000 + 1] = { + 0.998387177026244, + 0.996121378832018, + 1.000000000000000 +}; + +// static const GS32 HP0D67HZ_STAGE_FS500 = 2; +#define HP0D67HZ_STAGE_FS500 2 +static const GD64 HP0D67HZ_SOS_FS500[HP0D67HZ_STAGE_FS500][6] = { + { 1,-2,1,1,-1.993506129984135,0.993576789350877 }, + { 1,-2,1,1,-1.984492770590399,0.984563110480689 }, +}; +static const GD64 HP0D67HZ_G_FS500[HP0D67HZ_STAGE_FS500 + 1] = { + 0.996770729833753, + 0.992263970267772, + 1.000000000000000 +}; + +// static const GS32 HP0D67HZ_STAGE_FS250 = 2; +#define HP0D67HZ_STAGE_FS250 2 +static const GD64 HP0D67HZ_SOS_FS250[HP0D67HZ_STAGE_FS250][6] = { + { 1,-2,1,1,-1.986913427492570,0.987195155216588 }, + { 1,-2,1,1,-1.969084562840559,0.969363762580524 }, +}; +static const GD64 HP0D67HZ_G_FS250[HP0D67HZ_STAGE_FS250 + 1] = { + 0.993527145677289, + 0.984612081355271, + 1.000000000000000 +}; + +// static const GS32 HP3HZ_STAGE_FS1000 = 2; +#define HP3HZ_STAGE_FS1000 2 +static const GD64 HP3HZ_SOS_FS1000[HP3HZ_STAGE_FS1000][6] = { + { 1, - 2, 1, 1, - 1.98532458709362, 0.985677337945189 }, + { 1, - 2, 1, 1, - 1.96541950338359, 0.965768717516138 } + +}; +static const GD64 HP3HZ_G_FS1000[HP3HZ_STAGE_FS1000 + 1] = { + 0.992750481259703, + 0.982797055224932, + 1 +}; + +// static const GS32 HP3HZ_STAGE_FS500 = 2; +#define HP3HZ_STAGE_FS500 2 +static const GD64 HP3HZ_SOS_FS500[HP3HZ_STAGE_FS500][6] = { + {1, - 2, 1, 1, - 1.97016248697805, 0.971563336669560 }, + {1, - 2, 1, 1, - 1.93132781565559, 0.932701052631051 } + +}; +static const GD64 HP3HZ_G_FS500[HP3HZ_STAGE_FS500 + 1] = { + 0.985431455911901, + 0.966007217071661, + 1 +}; + +// static const GS32 HP3HZ_STAGE_FS250 = 2; +#define HP3HZ_STAGE_FS250 2 +static const GD64 HP3HZ_SOS_FS250[HP3HZ_STAGE_FS250][6] = { + {1, - 2, 1, 1, - 1.93843971601956, 0.943962707962528 }, + {1, - 2, 1, 1, - 1.86455782563483, 0.869870313695752 } + +}; +static const GD64 HP3HZ_G_FS250[HP3HZ_STAGE_FS250 + 1] = { + 0.970600605995522, + 0.933607034832644, + 1 +}; + +// static const GS32 HP5HZ_STAGE_FS1000 = 2; +#define HP5HZ_STAGE_FS1000 2 +static const GD64 HP5HZ_SOS_FS1000[HP5HZ_STAGE_FS1000][6] = { + {1, - 2, 1, 1, - 1.97526963485187, 0.976244792359440 }, + {1, - 2, 1, 1, - 1.94263823054011, 0.943597278470367 } + +}; +static const GD64 HP5HZ_G_FS1000[HP5HZ_STAGE_FS1000 + 1] = { + 0.987878606802828, + 0.971558877252620, + 1 +}; + +// static const GS32 HP5HZ_STAGE_FS500 = 2; +#define HP5HZ_STAGE_FS500 2 +static const GD64 HP5HZ_SOS_FS500[HP5HZ_STAGE_FS500][6] = { + {1, - 2, 1, 1, - 1.97526963485187, 0.976244792359440 }, + {1, - 2, 1, 1, - 1.94263823054011, 0.943597278470367 } + +}; +static const GD64 HP5HZ_G_FS500[HP5HZ_STAGE_FS500 + 1] = { + 0.987878606802828, + 0.971558877252620, + 1 +}; + +// static const GS32 HP5HZ_STAGE_FS250 = 2; +#define HP5HZ_STAGE_FS250 2 +static const GD64 HP5HZ_SOS_FS250[HP5HZ_STAGE_FS250][6] = { + { 1, - 2, 1, 1, - 1.89341560102250, 0.908464412949295 }, + { 1, - 2, 1, 1, - 1.77831348813944, 0.792447471832947 } +}; +static const GD64 HP5HZ_G_FS250[HP5HZ_STAGE_FS250 + 1] = { + 0.950470003492949, + 0.892690239993096, + 1 +}; +//END define ecg signal filter + + +/** + * @fn GU8 gh3x2x_mp_crc_cal(GU8 *puchData, GU32 unLen) + * + * @brief GH3x2x mp start test + * + * @attention None + * + * @param[in] none + * @param[out] None + * + * @return CRC + */ +GU8 gh3x2x_mp_crc_cal(GU8 *puchData, GU32 unLen) +{ + int i; + GU8 crc = 0x00; + + while (unLen--) + { + crc ^= *puchData++; + for (i = 8; i>0; --i) + { + if (crc & 0x80) + { + crc = (crc << 1) ^ 0x31; + } + else + { + crc = (crc << 1); + } + crc = crc & 0xff; + } + } + return(crc); +} + +/** + * @fn GD64 gh3x2x_mp_high_pass_filter(GD64 fData) + * + * @brief GH3x2x mp high-pass filter + * + * @attention None + * + * @param[in] GD64 fData + * @param[out] None + * + * @return Filtered data + */ +GD64 gh3x2x_mp_high_pass_filter(GD64 fData) +{ + GU32 i = 0; + + if(HPF_FirstFlag) + { + memset(HPF_ArrDataIn, 0, HIGH_PASS_FILTER_COEF_SIZE*sizeof(GD64)); + memset(HPF_ArrDataOut, 0, HIGH_PASS_FILTER_COEF_SIZE*sizeof(GD64)); + + GD64 skip = fData - HPF_ArrDataIn[HIGH_PASS_FILTER_COEF_SIZE - 1]; + for(i = 0; i < HIGH_PASS_FILTER_COEF_SIZE; i++) + { + HPF_ArrDataIn[i] += skip; + } + HPF_FirstFlag = 0; + } + + GD64 sum = 0; + for (i = 0; i < HIGH_PASS_FILTER_COEF_SIZE; i++) + { + sum += (HPF_CoefB[i + 1] * HPF_ArrDataIn[HIGH_PASS_FILTER_COEF_SIZE - i - 1]); + } + GD64 dataBuffer_1 = HPF_CoefB[0] * fData + sum; + + sum = 0; + for (i = 0; i < HIGH_PASS_FILTER_COEF_SIZE; i++) + { + sum += (HPF_CoefA[i + 1] * HPF_ArrDataOut[HIGH_PASS_FILTER_COEF_SIZE - i - 1]); + } + GD64 dataBuffer_2 = sum; + + GD64 dataOut = (dataBuffer_1 - dataBuffer_2) / HPF_CoefA[0]; + + for(i = 0; i < HIGH_PASS_FILTER_COEF_SIZE - 1; i++) + { + HPF_ArrDataIn[i] = HPF_ArrDataIn[i + 1]; + } + HPF_ArrDataIn[i] = fData; + + for(i = 0; i < HIGH_PASS_FILTER_COEF_SIZE - 1; i++) + { + HPF_ArrDataOut[i] = HPF_ArrDataOut[i + 1]; + } + HPF_ArrDataOut[i] = dataOut; + + return dataOut; +} + +/** + * @fn GU8 gh3x2x_mp_ecg_lead_off_dectection(GS32 nRawdataArr[], GU16 usRawdataLen, GU8 uchECGChannel_N, GU16 *usReSampleData_Len) + * + * @brief dectect ecg lead off algorithm + * + * @attention None + * + * @param[in] GS32 nRawdataArr[], GU16 usRawdataLen, GU8 uchECGChannel_N, GU16 usReSampleData_Len + * @param[out] None + * + * @return ret + */ +GU8 gh3x2x_mp_ecg_lead_off_dectection(GS32 nRawdataArr[], GU16 usRawdataLen, GU8 uchECGChannel_N, GU16 *usReSampleData_Len) +{ + + //ECG LeadOff detection algorithm define +#define ADCREF 1800 //ref +#define IS_BIG_ENDIAN 1 //data read from GH3100 FIFO is big endian? +//#define PI 3.14159265 + +#define ABS(x) ( (x)>0?(x):(-(x)) ) //Abs value + +#define AMP_NUM 5 //IQ amplitude +#define IQ_NUM 48 //IQ cumulative points +#define winAmpCoef 4082 // +#define LEADOFF_DET_IQ_AMP_THR_uV 1500 //IQ lead off threshold (Vpp/2), unit uV +#define LEADOFF_DET_IQ_AMP ((long long)LEADOFF_DET_IQ_AMP_THR_uV * 20 * ADC_OFFSET / ADCREF/1000*IQ_NUM*1000/winAmpCoef) +#define LEADOFF_DET_IQ_AMP_DIFF_THR_uV 1000 //IQ lead off jump threshold (Vpp/2), unit uV +#define LEADOFF_DET_IQ_AMP_DIFF ((long long)LEADOFF_DET_IQ_AMP_DIFF_THR_uV * 20 * ADC_OFFSET / ADCREF/1000*IQ_NUM*1000/winAmpCoef) +#define LEADOFF_DET_VAL_THR_mV 80 //Amplitude detection threshold, unit mV, more than 80mV is considered leadoff, +#define RESAMPLE_800HZ_TO_500HZ 1 //re-sampling switch + + +#if RESAMPLE_800HZ_TO_500HZ + +#define RS_FIR_ORDER 182 //Resample FIR filter order +#define RS_I 5 //Insertion factor +#define RS_D 8 //Decimation factor + +#if RS_FIR_ORDER%2 //Odd order, even coefficients + +#define RS_FIR_COEF_NUM ((RS_FIR_ORDER+1)/2) //The number of coefficients that need to be stored +#else//Even order, odd coefficients +#define RS_FIR_COEF_NUM ((RS_FIR_ORDER+2)/2) + +#endif +//Resampling filter coefficients +#define SHIFTBITS 30 + const GS32 rsFirCoef[RS_FIR_COEF_NUM] = { 58200, 102435, 156130, 215460, 274735, 326585, 362380, 372790, 348645, 281870, 166550, 0, -216285, -475850, \ + -766815, -1071825, -1368460, -1630170, -1827760, -1931325, -1912605, -1747635, -1419445, -920670, -255820, \ + 557070, 1485515, 2482735, 3488860, 4433375, 5238695, 5824850, 6114965, 6041350, 5551740, 4615280, 3227790, \ + 1415785, -761100, -3209770, -5805610, -8396875, -10811545, -12866385, -14377925, -15174745, -15110485, -14076620, \ + -12014295, -8924190, -4873605, 0, 5489625, 11323885, 17176845, 22682405, 27452740, 31100030, 33260510, 33619540, \ + 31936265, 28066360, 21981325, 13782945, 3711580, -7852615, -20396185, -33286830, -45795550, -57125820, -66448630, \ + -72941905, -75832375, -74437800, -68207360, -56757870, -39903755, -17678885, 9651270, 41588185, 77410100, 116192965, \ + 156841955, 198132190, 238757000, 277381455, 312698655, 343486005, 368658785, 387318230, 398791740, 402663190 }; +#define RS_BUF_SIZE (RS_FIR_ORDER / RS_I + 1) + GS32 rsXbuf[RS_BUF_SIZE];//Filtered data buffer + GS32 bufHead = -1; //Reverse circular buffer head position + GS32 rsFirState = 0; //Resampling filter state + GU32 rsIcounter = 0; //Insert data sequence number count,4khz sample rate + GU32 rsDcounter = 0; //Extracted data sequence number count,4khz sample rate + +#endif + + //IQ detection variables + GU32 guiCounter = 0; //Global counter + GU32 iqCounter = 0; //iq integral counter + GS64 iVal = 0; //I Accumulate + GS64 qVal = 0; //Q Accumulate + GS64 iqAmp[AMP_NUM] = {0}; //IQ amplitude value buffer + const GS32 winCoef[IQ_NUM / 2] = { 0, 9580474, 38150933, 85201535, 149892663, 231069901, 327284639, 436819923, 557721094, 687830666, 824826833, 966264894, \ + 1109620882, 1252336609, 1391865307, 1525717084, 1651503351, 1766979451, 1870084709, 1958979209, 2032076627, 2088072537, \ + 2125967693, 2145085852 }; + + GU8 gscFlagFrPrev = 0; // Fast recovery marks the cache, after fast recovery, reset the IQ detection and resampling module + GS64 LEADOFF_DET_IQ_AMP_THR_RAW = (LEADOFF_DET_IQ_AMP*LEADOFF_DET_IQ_AMP); //Threshold during normal sampling + GS64 LEADOFF_DET_IQ_AMP_FR_THR_RAW = (LEADOFF_DET_IQ_AMP*LEADOFF_DET_IQ_AMP / 20 / 20); //Threshold during Fast recovery, at this time the gain is only 1 + + GS64 LEADOFF_DET_IQ_AMP_DIFF_THR_RAW = (LEADOFF_DET_IQ_AMP_DIFF*LEADOFF_DET_IQ_AMP_DIFF);//Threshold during normal sampling + GS64 LEADOFF_DET_IQ_AMP_DIFF_FR_THR_RAW = (LEADOFF_DET_IQ_AMP_DIFF*LEADOFF_DET_IQ_AMP_DIFF / 20 / 20); //Threshold during Fast recovery, at this time the gain is only 1 + + // Amplitude detection variable + GS32 COND_VAL_VALID_TIME = 1; //Effective time of amplitude detection + GS32 LEADOFF_DET_VAL_THR_RAW = (LEADOFF_DET_VAL_THR_mV * (20 * ADC_OFFSET / ADCREF)); // + + + //start + GU32 i = 0; + GU32 j = 0; + + //reset + guiCounter = 0; + iqCounter = 0; + iVal = 0; + qVal = 0; + for (i = 0; i < AMP_NUM; i++) + iqAmp[i] = 0; + +#if RESAMPLE_800HZ_TO_500HZ + bufHead = -1; + rsFirState = 0; + rsIcounter = 0; + rsDcounter = 0; +#endif + + //detect + GU32 fifoVal; + GS32 adcVal; + GU8 flagFastRecovery; + GU8 chNo; + GS32 absAdcVal; //ABS of adcVal + GS64 temp; + GS32 rstValue = 0; + +#if RESAMPLE_800HZ_TO_500HZ + GU16 rsFifoDataNum = 0; + GS32 k; + GS64 y; + GS32 delta; +#endif + + for(i = 0; i < usRawdataLen; i++) + { + fifoVal = (GU32)nRawdataArr[i]; + #if IS_BIG_ENDIAN + //big endian to little endian + fifoVal = ((fifoVal & 0xFF) << 24) | ((fifoVal & 0x0000FF00) << 8) | ((fifoVal & 0x00FF0000) >> 8) | ((fifoVal & 0xFF000000) >> 24); + #endif + chNo = (fifoVal >> 27); //Channel number + if(chNo != uchECGChannel_N) + { + continue; + } + adcVal = (int)(fifoVal & 0x00FFFFFF) - ADC_OFFSET; //adc Sample value extraction + flagFastRecovery = (fifoVal >> 26) & 0x01; + + //Reset IQ test after fast recovery is over + if(gscFlagFrPrev != flagFastRecovery) + { + //reset + guiCounter = 0; + iqCounter = 0; + iVal = 0; + qVal = 0; + for (i = 0; i < AMP_NUM; i++) + iqAmp[i] = 0; + + #if RESAMPLE_800HZ_TO_500HZ + bufHead = -1; + rsFirState = 0; + rsIcounter = 0; + rsDcounter = 0; + #endif + } + gscFlagFrPrev = flagFastRecovery; + + //sample counter + if(guiCounter < 20000) + guiCounter++; + + //Absolute value judgment of amplitude + if(flagFastRecovery == 0 && guiCounter>COND_VAL_VALID_TIME) + { + absAdcVal = ABS(adcVal); + if(absAdcVal > LEADOFF_DET_VAL_THR_RAW) + rstValue |= 0x01; + } + + //Add window + if(iqCounter < IQ_NUM / 2) //Front half window + { + temp = (long long)adcVal*winCoef[iqCounter]; + } + else //Back half window + { + temp = (long long)adcVal*winCoef[IQ_NUM - 1 - iqCounter]; + } + + //IQ integral + switch (iqCounter % 4) + { + case 0: + iVal += temp; + break; + case 1: + qVal += temp; + break; + case 2: + iVal -= temp; + break; + case 3: + qVal -= temp; + break; + default: + break; + } + + if(iqCounter == (IQ_NUM - 1)) + { + for (j = AMP_NUM - 1; j >0; j--) + { + iqAmp[j] = iqAmp[j - 1]; + } + iVal = iVal >> 31; + qVal = qVal >> 31; + iqAmp[0] = iVal*(int)iVal + qVal*(int)qVal; + iVal = 0; + qVal = 0; + + //judge leadoff + if(flagFastRecovery == 0) // During normal ECG + { + //IQ Absolute amplitude + if(iqAmp[0] > LEADOFF_DET_IQ_AMP_THR_RAW && iqAmp[1] > LEADOFF_DET_IQ_AMP_THR_RAW) + rstValue |= 0x02; + //IQ Jump amplitude + if((iqAmp[0] - iqAmp[2]) > LEADOFF_DET_IQ_AMP_DIFF_THR_RAW && (iqAmp[1] - iqAmp[2]) > LEADOFF_DET_IQ_AMP_DIFF_THR_RAW) + rstValue |= 0x04; + + } + else//during Fast Recovery + { + //IQ Absolute amplitude + if(iqAmp[0] > LEADOFF_DET_IQ_AMP_FR_THR_RAW && iqAmp[1] > LEADOFF_DET_IQ_AMP_FR_THR_RAW) + rstValue |= 0x02; + //IQ Jump amplitude + if((iqAmp[0] - iqAmp[1]) > LEADOFF_DET_IQ_AMP_DIFF_FR_THR_RAW) + rstValue |= 0x04; + } + } + + //IQ counter + iqCounter++; + iqCounter = iqCounter % (IQ_NUM); + + //re samping + #if RESAMPLE_800HZ_TO_500HZ + //Data cache + if(rsFirState > 0) + { + bufHead = bufHead - 1; + bufHead = bufHead < 0 ? (RS_BUF_SIZE - 1) : bufHead; + rsXbuf[bufHead] = adcVal; + rsIcounter += RS_I; + } + else //The first point fills the data array + { + for (j = 0; j < RS_FIR_ORDER / RS_I + 1; j++) + rsXbuf[j] = adcVal; + rsIcounter = 0; + rsFirState = 1; + bufHead = RS_BUF_SIZE - 1; + } + + //Extract + if(rsDcounter >= rsIcounter && rsDcounter < (rsIcounter + RS_I)) //Meet the extraction conditions + { + + delta = rsDcounter - rsIcounter; + k = bufHead; + y = 0; + for(j = delta; j < RS_FIR_COEF_NUM; j = j + RS_I) //Multiply and add the first half of the filter + { + y += ((long long)rsXbuf[k] * rsFirCoef[j]); + k = (k + 1) % RS_BUF_SIZE; + } + for(; j <(RS_FIR_ORDER + 1); j = j + RS_I) //Multiply and add the second half + { + y += ((long long)rsXbuf[k] * rsFirCoef[RS_FIR_ORDER - j]); + k = (k + 1) % RS_BUF_SIZE; + } + //y *= RS_I; + rsDcounter += RS_D; + + y = y >> SHIFTBITS; + k = (int)y + ADC_OFFSET; //k is used as a temporary variable + if(k < 0) + k = 0; + else if(k >= (ADC_OFFSET * 2)) + k = (ADC_OFFSET * 2 - 1); + fifoVal = (((unsigned int)chNo) << 27) + (((unsigned int)flagFastRecovery) << 26) + ((unsigned int)k); //Assemble output data + #if IS_BIG_ENDIAN + fifoVal = ((fifoVal & 0xFF) << 24) | ((fifoVal & 0x0000FF00) << 8) | ((fifoVal & 0x00FF0000) >> 8) | ((fifoVal & 0xFF000000) >> 24); //endian reverse + #endif + nRawdataArr[rsFifoDataNum] = fifoVal; + rsFifoDataNum++; //Add 1 to the extracted data count + }//Complete extraction + + #endif //RESAMPLE_800HZ_TO_500HZ + + + } + + +#if RESAMPLE_800HZ_TO_500HZ + *usReSampleData_Len = rsFifoDataNum; +#else + *usReSampleData_Len = usRawdataLen; +#endif + + + return rstValue; + +} + +/** + * @fn GD64 gh3x2x_mp_signal_IIR_filter(IIR_State_Def *stIIR_State, GD64 dData) + * + * @brief GH3x2x mp signal IIR filter + * + * @attention None + * + * @param[in] IIR_State_Def *stIIR_State, GD64 dData + * @param[out] None + * + * @return Filtered data + */ +GD64 gh3x2x_mp_signal_IIR_filter(IIR_State_Def *stIIR_State, GD64 dData) +{ + GD64 x = dData; + GD64 y = 0; + + for (int i = 0; i < stIIR_State->stages; i++) + { + stIIR_State->x[i][2] = stIIR_State->x[i][1]; + stIIR_State->x[i][1] = stIIR_State->x[i][0]; + stIIR_State->x[i][0] = x; + + y = (stIIR_State->x[i][0] * stIIR_State->sos[i][0] + stIIR_State->x[i][1] * stIIR_State->sos[i][1] + + stIIR_State->x[i][2] * stIIR_State->sos[i][2]) * stIIR_State->gain[i] - stIIR_State->y[i][0] * stIIR_State->sos[i][4] - + stIIR_State->y[i][1] * stIIR_State->sos[i][5]; + stIIR_State->y[i][1] = stIIR_State->y[i][0]; + stIIR_State->y[i][0] = y; + + x = y; // Output to the next node + } + + return y; +} + +/** + * @fn void gh3x2x_mp_signal_filter(GS32 nFilterArr[], GU16 usLength, GU8 uchHpType, GU8 uchLpType, GU8 uchFsType) + * + * @brief GH3x2x mp signal hp and lp filter for ecg + * + * @attention None + * + * @param[in] GS32 nFilterArr[], GU16 usLength, GU8 uchHpType, GU8 uchLpType, GU8 uchFsType + uchLpType:Low pass filter cut-off frequency + uchHpType:High pass filter cut-off frequency + uchFsType:Sampling rate of rawdata + * @param[out] GS32 nFilterArr[] + * + * @return None + */ +void gh3x2x_mp_signal_filter(GS32 nFilterArr[], GU16 usLength, GU8 uchHpType, GU8 uchLpType, GU8 uchFsType) +{ + GU16 i = 0; + IIR_State_Def stState; + + + if(uchLpType != 0) + { + //init lp filter + memset(&stState, 0, sizeof(IIR_State_Def)); + if(uchLpType == 1) // LP150Hz + { + if(uchFsType == 0) //150Hz cut-off frequency cannot be selected for 250Hz sampling, here is forced to choose 120Hz + { + stState.gain = LP120HZ_G_FS250; + stState.sos = LP120HZ_SOS_FS250; + stState.stages = LP120HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = LP150HZ_G_FS500; + stState.sos = LP150HZ_SOS_FS500; + stState.stages = LP150HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = LP150HZ_G_FS1000; + stState.sos = LP150HZ_SOS_FS1000; + stState.stages = LP150HZ_STAGE_FS1000; + } + else + { + stState.gain = LP150HZ_G_FS500; + stState.sos = LP150HZ_SOS_FS500; + stState.stages = LP150HZ_STAGE_FS500; + } + } + else if(uchLpType == 2) // LP120Hz + { + if(uchFsType == 0) + { + stState.gain = LP120HZ_G_FS250; + stState.sos = LP120HZ_SOS_FS250; + stState.stages = LP120HZ_STAGE_FS250; + + } + else if(uchFsType == 1) + { + stState.gain = LP120HZ_G_FS500; + stState.sos = LP120HZ_SOS_FS500; + stState.stages = LP120HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = LP120HZ_G_FS1000; + stState.sos = LP120HZ_SOS_FS1000; + stState.stages = LP120HZ_STAGE_FS1000; + } + else + { + stState.gain = LP120HZ_G_FS500; + stState.sos = LP120HZ_SOS_FS500; + stState.stages = LP120HZ_STAGE_FS500; + } + } + else if(uchLpType == 3) + { + if (uchFsType == 0) + { + stState.gain = LP55HZ_G_FS250; + stState.sos = LP55HZ_SOS_FS250; + stState.stages = LP55HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = LP55HZ_G_FS500; + stState.sos = LP55HZ_SOS_FS500; + stState.stages = LP55HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = LP55HZ_G_FS1000; + stState.sos = LP55HZ_SOS_FS1000; + stState.stages = LP55HZ_STAGE_FS1000; + } + else + { + stState.gain = LP55HZ_G_FS500; + stState.sos = LP55HZ_SOS_FS500; + stState.stages = LP55HZ_STAGE_FS500; + } + } + else if(uchLpType == 4) // LP45Hz + { + if(uchFsType == 0) + { + stState.gain = LP45HZ_G_FS250; + stState.sos = LP45HZ_SOS_FS250; + stState.stages = LP45HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = LP45HZ_G_FS500; + stState.sos = LP45HZ_SOS_FS500; + stState.stages = LP45HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = LP45HZ_G_FS1000; + stState.sos = LP45HZ_SOS_FS1000; + stState.stages = LP45HZ_STAGE_FS1000; + } + else + { + stState.gain = LP45HZ_G_FS500; + stState.sos = LP45HZ_SOS_FS500; + stState.stages = LP45HZ_STAGE_FS500; + } + } + else + { + if(uchFsType == 0) + { + stState.gain = LP120HZ_G_FS500; + stState.sos = LP120HZ_SOS_FS500; + stState.stages = LP120HZ_STAGE_FS500; + } + else if(uchFsType == 1) + { + stState.gain = LP150HZ_G_FS500; + stState.sos = LP150HZ_SOS_FS500; + stState.stages = LP150HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = LP150HZ_G_FS1000; + stState.sos = LP150HZ_SOS_FS1000; + stState.stages = LP150HZ_STAGE_FS1000; + } + else + { + stState.gain = LP150HZ_G_FS500; + stState.sos = LP150HZ_SOS_FS500; + stState.stages = LP150HZ_STAGE_FS500; + } + } + + + for(i = 0; i < usLength; i++) + { + nFilterArr[i] = gh3x2x_mp_signal_IIR_filter(&stState, (GD64)nFilterArr[i]); + } + + } + + if(uchHpType != 0) + { + //init hp filter + memset(&stState, 0, sizeof(IIR_State_Def)); + if(uchHpType == 1) //0.05hz + { + if(uchFsType == 0) + { + stState.gain = HP0D05HZ_G_FS250; + stState.sos = HP0D05HZ_SOS_FS250; + stState.stages = HP0D05HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = HP0D05HZ_G_FS500; + stState.sos = HP0D05HZ_SOS_FS500; + stState.stages = HP0D05HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = HP0D05HZ_G_FS1000; + stState.sos = HP0D05HZ_SOS_FS1000; + stState.stages = HP0D05HZ_STAGE_FS1000; + } + else + { + stState.gain = HP0D05HZ_G_FS500; + stState.sos = HP0D05HZ_SOS_FS500; + stState.stages = HP0D05HZ_STAGE_FS500; + } + } + else if(uchHpType == 2)//0.5hz + { + if(uchFsType == 0) + { + stState.gain = HP0D5HZ_G_FS250; + stState.sos = HP0D5HZ_SOS_FS250; + stState.stages = HP0D5HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = HP0D5HZ_G_FS500; + stState.sos = HP0D5HZ_SOS_FS500; + stState.stages = HP0D5HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = HP0D5HZ_G_FS1000; + stState.sos = HP0D5HZ_SOS_FS1000; + stState.stages = HP0D5HZ_STAGE_FS1000; + } + else + { + stState.gain = HP0D5HZ_G_FS500; + stState.sos = HP0D5HZ_SOS_FS500; + stState.stages = HP0D5HZ_STAGE_FS500; + } + } + else if(uchHpType == 3)//0.67hz + { + if(uchFsType == 0) + { + stState.gain = HP0D67HZ_G_FS250; + stState.sos = HP0D67HZ_SOS_FS250; + stState.stages = HP0D67HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = HP0D67HZ_G_FS500; + stState.sos = HP0D67HZ_SOS_FS500; + stState.stages = HP0D67HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = HP0D67HZ_G_FS1000; + stState.sos = HP0D67HZ_SOS_FS1000; + stState.stages = HP0D67HZ_STAGE_FS1000; + } + else + { + stState.gain = HP0D67HZ_G_FS500; + stState.sos = HP0D67HZ_SOS_FS500; + stState.stages = HP0D67HZ_STAGE_FS500; + } + } + else if(uchHpType == 4)//3hz + { + if(uchFsType == 0) + { + stState.gain = HP3HZ_G_FS250; + stState.sos = HP3HZ_SOS_FS250; + stState.stages = HP3HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = HP3HZ_G_FS500; + stState.sos = HP3HZ_SOS_FS500; + stState.stages = HP3HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = HP3HZ_G_FS1000; + stState.sos = HP3HZ_SOS_FS1000; + stState.stages = HP3HZ_STAGE_FS1000; + } + else + { + stState.gain = HP3HZ_G_FS500; + stState.sos = HP3HZ_SOS_FS500; + stState.stages = HP3HZ_STAGE_FS500; + } + } + else if(uchHpType == 5)//5hz + { + if(uchFsType == 0) + { + stState.gain = HP5HZ_G_FS250; + stState.sos = HP5HZ_SOS_FS250; + stState.stages = HP5HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = HP5HZ_G_FS500; + stState.sos = HP5HZ_SOS_FS500; + stState.stages = HP5HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = HP5HZ_G_FS1000; + stState.sos = HP5HZ_SOS_FS1000; + stState.stages = HP5HZ_STAGE_FS1000; + } + else + { + stState.gain = HP5HZ_G_FS500; + stState.sos = HP5HZ_SOS_FS500; + stState.stages = HP5HZ_STAGE_FS500; + } + } + else + { + if(uchFsType == 0) + { + stState.gain = HP0D05HZ_G_FS250; + stState.sos = HP0D05HZ_SOS_FS250; + stState.stages = HP0D05HZ_STAGE_FS250; + } + else if(uchFsType == 1) + { + stState.gain = HP0D05HZ_G_FS500; + stState.sos = HP0D05HZ_SOS_FS500; + stState.stages = HP0D05HZ_STAGE_FS500; + } + else if(uchFsType == 2) + { + stState.gain = HP0D05HZ_G_FS1000; + stState.sos = HP0D05HZ_SOS_FS1000; + stState.stages = HP0D05HZ_STAGE_FS1000; + } + else + { + stState.gain = HP0D05HZ_G_FS500; + stState.sos = HP0D05HZ_SOS_FS500; + stState.stages = HP0D05HZ_STAGE_FS500; + } + } + + for(i = 0; i < usLength; i++) + { + nFilterArr[i] = gh3x2x_mp_signal_IIR_filter(&stState, (GD64)nFilterArr[i]); + } + + } + +} + +/** + * @fn void gh3x2x_mp_signal_fft(GF32 fFFT_InArr[], GF32 fFFT_OutArr[], GU32 unLength, GU32 unStep) + * + * @brief fft + * + * @attention None + * + * @param[in] GF32 fFFT_InArr[], GS32 nFFT_OutArr[], GU32 unLength, GU32 step + * @param[out] GF32 fFFT_InArr[] + * + * @return ret + */ +void gh3x2x_mp_signal_fft(GF32 fFFT_InArr[], GF32 fFFT_OutArr[], GU32 unLength, GU32 unStep) +{ + GU32 i; + GF32 real = 0.0; + GF32 image = 0.0; + GF32 a, b, c, d, theta; + + if (unStep < unLength) + { + gh3x2x_mp_signal_fft(fFFT_OutArr, fFFT_InArr, unLength, unStep * 2); + gh3x2x_mp_signal_fft(fFFT_OutArr + 2*unStep, fFFT_InArr + 2*unStep, unLength, unStep * 2); + + for (i = 0; i < unLength; i += 2 * unStep) + { + theta = -PI * i / unLength; + a = cos(theta); + b = sin(theta); + c = fFFT_OutArr[2*(i + unStep)]; + d = fFFT_OutArr[2*(i + unStep) + 1]; + real = a * c - b * d; + image = b * c + a * d; + fFFT_InArr[i] = fFFT_OutArr[2*i] + real; + fFFT_InArr[i+1] = fFFT_OutArr[2*i + 1] + image; + fFFT_InArr[i + unLength] = fFFT_OutArr[2*i] - real; + fFFT_InArr[i + unLength + 1] = fFFT_OutArr[2*i + 1] - image; + } + } + +} + +/** + * @fn void gh3x2x_mp_signal_quick_fft(GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], GU32 unLength, GU32 unPower_2, \ + GF32 fFFTOutArr_real[], GF32 fFFTOutArr_image[], GU8 uchFFTMode, GU32 uchCalModulus_Angle) + * + * @brief more quick do fft process + * + * @attention None + * + * @param[in] GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], GU32 unLength, GU32 unPower_2, GU8 uchFFTMode, GU32 uchCalModulus_Angle + uchFFTMode: 0, Fourier transform; 1, inverse Fourier transform + uchCalModulus_Angle: 0, do not calculate Fourier transform or inverse transform mode and amplitude Angle;1, calculate the modulus and amplitude Angle + unLength: the number of points entered, which is an even number, is generally 32,64,128...1024, etc. + unPower_2: satisfy n=2^unPower_2(unPower_2>0) + fFFTInArr_real: 0,store the real part of the sampled data at N points; 1,store N real parts of the Fourier transform + fFFTInArr_image: 0,store the imaginary part of the sampled data at N points; 1,store N imaginary parts of the Fourier transform + + * @param[out] GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], + fFFTOutArr_real: uchFFTMode=0, return the real part of the Fourier transform + uchFFTMode=1, return the real part of the inverse Fourier transform + fFFTOutArr_image:uchFFTMode=0, return the imaginary part of the Fourier transform + uchFFTMode=1, return the imaginary part of the inverse Fourier transform + fFFTInArr_real: uchCalModulus_Angle = 1, uchFFTMode = 0, return the modulus of Fourier transform + uchCalModulus_Angle = 1, uchFFTMode = 1, return the inverse Fourier transform modulus + fFFTInArr_image:uchCalModulus_Angle = 1, uchFFTMode = 0, return the amplitude Angle of the Fourier transform + uchCalModulus_Angle = 1, uchFFTMode = 1, return the amplitude Angle of the inverse Fourier transform + * + * @return none + */ +void gh3x2x_mp_signal_quick_fft(GF32 fFFTInArr_real[], GF32 fFFTInArr_image[], GU32 unLength, GU32 unPower_2, \ + GF32 fFFTOutArr_real[], GF32 fFFTOutArr_image[], GU8 uchFFTMode, GU32 uchCalModulus_Angle) +{ + GS32 it,m,is,i,j,nv,l0; + GF32 p,q,s,vr,vi,poddr,poddi; + + for (it=0; it<=unLength-1; it++) + { + m = it; + is = 0; + for(i=0; i<=unPower_2-1; i++) + { + j = m/2; + is = 2*is+(m-2*j); + m = j; + } + fFFTOutArr_real[it] = fFFTInArr_real[is]; + fFFTOutArr_image[it] = fFFTInArr_image[is]; + } + + fFFTInArr_real[0] = 1.0; + fFFTInArr_image[0] = 0.0; + p = 6.283185306/(1.0*unLength); + fFFTInArr_real[1] = cos(p); + fFFTInArr_image[1] = -sin(p); + + if (uchFFTMode!=0) + fFFTInArr_image[1]=-fFFTInArr_image[1]; + + for (i=2; i<=unLength-1; i++) + { + p = fFFTInArr_real[i-1]*fFFTInArr_real[1]; + q = fFFTInArr_image[i-1]*fFFTInArr_image[1]; + s = (fFFTInArr_real[i-1]+fFFTInArr_image[i-1])*(fFFTInArr_real[1]+fFFTInArr_image[1]); + fFFTInArr_real[i] = p-q; + fFFTInArr_image[i] = s-p-q; + } + + for (it=0; it<=unLength-2; it=it+2) + { + vr = fFFTOutArr_real[it]; + vi = fFFTOutArr_image[it]; + fFFTOutArr_real[it] = vr+fFFTOutArr_real[it+1]; + fFFTOutArr_image[it] = vi+fFFTOutArr_image[it+1]; + fFFTOutArr_real[it+1] = vr-fFFTOutArr_real[it+1]; + fFFTOutArr_image[it+1] = vi-fFFTOutArr_image[it+1]; + } + m = unLength/2; + nv = 2; + + for (l0=unPower_2-2; l0>=0; l0--) + { + m = m/2; + nv = 2*nv; + for(it=0; it<=(m-1)*nv; it=it+nv) + for (j=0; j<=(nv/2)-1; j++) + { + p = fFFTInArr_real[m*j]*fFFTOutArr_real[it+j+nv/2]; + q = fFFTInArr_image[m*j]*fFFTOutArr_image[it+j+nv/2]; + s = fFFTInArr_real[m*j]+fFFTInArr_image[m*j]; + s = s*(fFFTOutArr_real[it+j+nv/2]+fFFTOutArr_image[it+j+nv/2]); + poddr = p-q; + poddi = s-p-q; + fFFTOutArr_real[it+j+nv/2] = fFFTOutArr_real[it+j]-poddr; + fFFTOutArr_image[it+j+nv/2] = fFFTOutArr_image[it+j]-poddi; + fFFTOutArr_real[it+j] = fFFTOutArr_real[it+j]+poddr; + fFFTOutArr_image[it+j] = fFFTOutArr_image[it+j]+poddi; + } + } + + if(uchFFTMode!=0) + for(i=0; i<=unLength-1; i++) + { + fFFTOutArr_real[i] = fFFTOutArr_real[i]/(1.0*unLength); + fFFTOutArr_image[i] = fFFTOutArr_image[i]/(1.0*unLength); + } + + if(uchCalModulus_Angle!=0) + for(i=0; i<=unLength-1; i++) + { + fFFTInArr_real[i] = sqrt(fFFTOutArr_real[i]*fFFTOutArr_real[i]+fFFTOutArr_image[i]*fFFTOutArr_image[i]); + if(fabs(fFFTOutArr_real[i])<0.000001*fabs(fFFTOutArr_image[i])) + { + if ((fFFTOutArr_image[i]*fFFTOutArr_real[i])>0) + fFFTInArr_image[i] = 90.0; + else + fFFTInArr_image[i] = -90.0; + } + else + fFFTInArr_image[i] = atan(fFFTOutArr_image[i]/fFFTOutArr_real[i])*360.0/6.283185306; + } + return; +} + +/** + * @fn GU8 gh3x2x_mp_signal_fft_process(GS32 nFFTArr[] GU32 unLength) + * + * @brief Perform FFT transformation on the data and then calculate the power spectrum + * + * @attention None + * + * @param[in] GS32 nFFTArr[], GU32 unLength + * @param[out] GS32 nFFTArr[] + * + * @return ret + */ +GF32 *fFFT_HandleArr = NULL; +extern GU8 GH3x2xMp_RawdataBuf[RAWDATA_BUF_SIZE]; +GU8 gh3x2x_mp_signal_fft_process(GF32 fFFTArr[], GU32 unLength) +{ + GU8 ret = 1; + GS32 i = 0; + //memset(fFFT_HandleArr, 0, 2*MAX_FFT_LENGTH*sizeof(GF32)); + fFFT_HandleArr = (GF32 *)(GH3x2xMp_RawdataBuf) + 2*MAX_FFT_LENGTH + 1; //Reuse GH3x2xMp_RawdataBuf memory + + //find the smallest 2^n from unLength + GU32 fft_len = 0; + i = 0; + while(fft_len < MAX_FFT_LENGTH) + { + if(fft_len >= unLength) + break; + fft_len = pow(2, i); + i++; + } + unLength = fft_len; + +// for(i = 2*unLength - 2; i >= 0; i -= 2) +// { +// fFFTArr[i] = fFFTArr[i / 2]; +// fFFTArr[i+1] = 0; +// } +// +// for(i = 0; i < 2*unLength; i++) +// { +// fFFT_HandleArr[i] = fFFTArr[i]; +// } + + +// gh3x2x_mp_signal_fft(fFFTArr, fFFT_HandleArr, unLength, 1); + +// for(i = 0; i < unLength; i++) +// fFFTArr[i] = sqrt(fFFTArr[2*i] * fFFTArr[2*i] + fFFTArr[2*i + 1] * fFFTArr[2*i + 1]); + + gh3x2x_mp_signal_quick_fft(fFFTArr, fFFTArr+MAX_FFT_LENGTH, unLength, i-1, fFFT_HandleArr, fFFT_HandleArr+MAX_FFT_LENGTH, 0, 1); + + fFFT_HandleArr = NULL; + return ret; +} + +/** + * @fn GU8 gh3x2x_demo_mp_ecg_fft_cal_amp_freq(GF32 fRawdataArr[], GU16 usLength, GU32 unFFTLength, GU32 unSampleRate, GF32 *fAmp, GF32 *fFreq, \ + GF32 fRefFreq, GU8 uchWintype) + * + * @brief cal amp and freq after fft + * + * @attention None + * + * @param[in] GF32 fRawdataArr[], GU16 usLength, GU32 unFFTLength, GU32 unSampleRate, GU8 uchWintype, GF32 fRefFreq + unSampleRate: Sampling frequency + winType:Window type, 0: rectangular window; 1: flattop window, used to accurately estimate the amplitude; 2: hanning window + fRefFreq:For reference frequency, find the maximum value near fref±5hz; if <0, find the maximum value between 0.1hz~fs/2 + * @param[out] GF32 *fAmp, GF32 *fFreq + fAmp: peak-to-peak value + fFreq:freq, unit Hz + * + * @return ret + */ +GU8 gh3x2x_demo_mp_ecg_fft_cal_amp_freq(GF32 fRawdataArr[], GU16 usLength, GU32 unFFTLength, GU32 unSampleRate, GF32 *fAmp, GF32 *fFreq, \ + GF32 fRefFreq, GU8 uchWintype) +{ + GU8 ret = 1; + GU32 i = 0; + + GD64 sum = 0; + GD64 mean = 0; + + if(unFFTLength > MAX_FFT_LENGTH) + unFFTLength = MAX_FFT_LENGTH; + + if(usLength > unFFTLength) + usLength = unFFTLength; + + + for(i = 0; i < usLength; i++) + sum += fRawdataArr[i]; + mean = sum / usLength; + + // Subtract the mean value of the signal and add a window + GD64 N = usLength - 1; + GD64 win = 0; + GD64 a0 = 0.21557895; + GD64 a1 = 0.41663158; + GD64 a2 = 0.277263158; + GD64 a3 = 0.083578947; + GD64 a4 = 0.006947368; + + if(uchWintype == 1) + { + for (i = 0; i < usLength; i++) + { + win = a0 - a1*cos(2 * PI*i / N) + a2*cos(4 * PI*i / N) - a3*cos(6 * PI*i / N) + a4*cos(8 * PI*i / N); //flattopwin + fRawdataArr[i] = (fRawdataArr[i] - mean)*win; + } + } + else if(uchWintype == 2) + { + for(i = 0; i < usLength; i++) + { + win = 0.5*(1-cos(2*PI*i/N)); //hanning + fRawdataArr[i] = (fRawdataArr[i] - mean)*win; + } + + } + else + { + for(i = 0; i < usLength; i++) + { + fRawdataArr[i] = (fRawdataArr[i] - mean); + } + + } + + + gh3x2x_mp_signal_fft_process(fRawdataArr, unFFTLength); + + //find peak + GS32 start = 0; + GS32 end = 0; + + if(fRefFreq > 0) //If the frequency is specified, look for it near the frequency + { + if((fRefFreq - 5) > (GF32)0.1) + start = (GS32)((fRefFreq - 5)* unFFTLength / unSampleRate); + else + start = (GS32)(0.1*unFFTLength / unSampleRate); + + if((fRefFreq + 5) * 2 < unSampleRate) + end = (GS32)((fRefFreq + 5) * unFFTLength / unSampleRate); + else + end = (GS32)(0.5*unFFTLength); + } + else //If the frequency is not specified, it will be found in the full frequency range. + { + start = (GS32)(0.1*unFFTLength / unSampleRate); + end = (GS32)(0.5*unFFTLength); + } + + GS32 peakPos = start; + GD64 peak = fRawdataArr[start]; + for(i = start + 1; i <= end; i++) + { + if (peak < fRawdataArr[i]) + { + peakPos = i; + peak = fRawdataArr[i]; + } + } + + //cal freq + *fFreq = (GF32)peakPos* unSampleRate / unFFTLength; + + //calculate signal amplitude through frequency domain + if (uchWintype == 1) + peak = peak / unFFTLength * 9.2792; // Cal the amp, 9.2792 is amp correction coefficient of flattopwin + else + peak = peak / unFFTLength * 2; //2 is rectangular window amplitude correction factor + *fAmp = peak * 2; // To calculate the peak-to-peak value must be multiplied by 2 + + return ret; +} + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_param_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_param_config.c new file mode 100644 index 000000000..953856908 --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_param_config.c @@ -0,0 +1,144 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_param_config.c + * + * @brief gh3x2x mp test param config + * + * @author Goodix Product Tools Development Team + * + */ + +#include "gh3x2x_mp_param_config.h" + +//test items select SKIP or TEST or NG_CONTINUE +const stMpItemsConfig stGh3x2xMpTestItemsSatus = +{ + //SKIP:item skip, not test; TEST:item need test; NG_CONTINUE: test item NG, continue to test + .COMMUNICATION_TEST = TEST, + .CHECK_CHIPID_TEST = TEST, //need use drv interface to check, at present Only need to test this item when the driver is AFE + .RST_INT_TEST = TEST, + .EFUSE_TEST = TEST, + .PPG_TEST = TEST, + .ECG_TEST = TEST, +}; + +//PPG test items select SKIP or TEST or NG_CONTINUE +const stMpPPGItemsConfig stGh3x2xMpPPGItemsSatus = +{ + .PPG_LPCTR_TEST = TEST, + .PPG_NOISE_TEST = TEST, + .PPG_BASENOISE_TEST = TEST, + .PPG_LEAKLIGHT_TEST = SKIP, + +}; + +//ECG test items select SKIP or TEST or NG_CONTINUE +const stMpECGItemsConfig stGh3x2xMpECGItemsSatus = +{ + + .ECG_LEADONOFF_TEST = TEST, + .ECG_NOISE_TEST = TEST, + .ECG_HPF_TEST = TEST, + .ECG_SIGNAL_TEST = TEST, + .ECG_RLD_TEST = TEST, + .ECG_CMRR_TEST = TEST, + .ECG_LIN_TEST = TEST, + .ECG_DCRANGE_TEST = TEST, +}; + +//LED and PD enable/disable config +const emMp_Enable PPG_LEDPD_EN[MAX_LED_NUM][MAX_ADC_NUM] = +{ + //every led can enable/disable 4 pd + //PD0, PD1, PD2, PD3 + {MP_ENABLE, MP_ENABLE, MP_ENABLE, MP_ENABLE}, //led 0 + {MP_ENABLE, MP_ENABLE, MP_ENABLE, MP_ENABLE}, //led 1 + {MP_ENABLE, MP_ENABLE, MP_ENABLE, MP_ENABLE}, //led 2 + {MP_DISABLE, MP_DISABLE, MP_DISABLE, MP_DISABLE}, //led 3 + {MP_DISABLE, MP_DISABLE, MP_DISABLE, MP_DISABLE}, //led 4 + {MP_DISABLE, MP_DISABLE, MP_DISABLE, MP_DISABLE}, //led 5 + {MP_DISABLE, MP_DISABLE, MP_DISABLE, MP_DISABLE}, //led 6 + {MP_DISABLE, MP_DISABLE, MP_DISABLE, MP_DISABLE} //led 7 +}; + +//PPG test auto Dimming Config +const stMpAutoDimmingConfig stGh3x2xPPG_AutoDimming = +{ + .LED_ACG_FS = { + LED_DRIVE_50MA, //led 0 + LED_DRIVE_25MA, //led 1 + LED_DRIVE_25MA, //led 2 + LED_DRIVE_25MA, //led 3 + LED_DRIVE_25MA, //led 4 + LED_DRIVE_25MA, //led 5 + LED_DRIVE_25MA, //led 6 + LED_DRIVE_25MA, //led 7 + }, + .LED_Max_Rawdata = 48787, + .LED_Min_Rawdata = 45874, + .LED_Ref_Up = 47816, + .LED_Ref_Down = 46845, +}; + +//test limit config +const stMpItemsLimitConfig stGh3x2xMpLimit = +{ + //PPG test limit + .PPG_CTR_MinLimit = { //PPG CTR test limit + //PD0, PD1, PD2, PD3 + 11.0, 11.0, 11.0, 11.0, //led 0 + 24.0, 24.0, 24.0, 24.0, //led 1 + 24.0, 24.0, 24.0, 24.0, //led 2 + 24.0, 24.0, 24.0, 24.0, //led 3 + 24.0, 24.0, 24.0, 24.0, //led 4 + 24.0, 24.0, 24.0, 24.0, //led 5 + 24.0, 24.0, 24.0, 24.0, //led 6 + 24.0, 24.0, 24.0, 24.0, //led 7 + }, + + .PPG_LeakCTR_MaxLimit = { //PPG leak light test limit + //PD0, PD1, PD2, PD3 + 1.0, 1.0, 1.0, 1.0, //led 0 + 0.8, 0.8, 0.8, 0.8, //led 1 + 0.8, 0.8, 0.8, 0.8, //led 2 + 0.8, 0.8, 0.8, 0.8, //led 3 + 0.8, 0.8, 0.8, 0.8, //led 4 + 0.8, 0.8, 0.8, 0.8, //led 5 + 0.8, 0.8, 0.8, 0.8, //led 6 + 0.8, 0.8, 0.8, 0.8, //led 7 + }, + + .PPG_LeakRatio_Throld = { //PPG leak light test limit + //PD0, PD1, PD2, PD3 + 0.037, 0.037, 0.037, 0.037, //led 0 + 0.015, 0.015, 0.015, 0.015, //led 1 + 0.015, 0.015, 0.015, 0.015, //led 2 + 0.015, 0.015, 0.015, 0.015, //led 3 + 0.015, 0.015, 0.015, 0.015, //led 4 + 0.015, 0.015, 0.015, 0.015, //led 5 + 0.015, 0.015, 0.015, 0.015, //led 6 + 0.015, 0.015, 0.015, 0.015, //led 7 + }, + + .PPG_Noise_MaxLimit = 280, //PPG Noise test limit + .PPG_BaseNoise_MaxLimit = 97, //PPG BaseNoise noise test limit + .PPG_DCOffset_MaxLimit = 1.60, //PPG BaseNoise test limit + .PPG_DCOffset_MinLimit = -7.7, //PPG BaseNoise test limit + + + //ECG test limit + .ECG_Noise_MaxLimit = 35, //ECG Noise test limit + .ECG_HPF_MaxLimit = 0.87, //ECG HPF test limit + .ECG_HPF_MinLimit = 0.67, //ECG HPF test limit + .ECG_MaxAMP = 0.05, //ECG SIGNAL test limit + .ECG_MaxFreq = 0.012, //ECG SIGNAL test limit + .ECG_SIGNAL_MaxLimit = 0.25, //ECG SIGNAL test limit + .ECG_RLD_MaxAmp = 900.0, //ECG RLD test limit + .ECG_CMRR_MinLimit = 85.0, //ECG CMRR test limit + .ECG_LIN_MaxLimit = 0.0470, //ECG LIN test limit + .ECG_DCRange_MaxLimit = 0.060, //ECG DCRange test limit + +}; + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_reg_config.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_reg_config.c new file mode 100644 index 000000000..e0397285a --- /dev/null +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/demo_mp_code/src/gh3x2x_mp_reg_config.c @@ -0,0 +1,48 @@ +/** + * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved. + * + * @file gh3x2x_mp_reg_config.c + * + * @brief gh3x2x mp test reg config + * + * @author Goodix Product Tools Development Team + * + */ + +#include "gh3x2x_mp_reg_config.h" + +const stGh3x2xReg stGh3x2xMpRegConfigDefault[] = +{ + { 0x0004, 0x001F }, { 0x000A, 0x000A }, { 0x000E, 0x000D }, { 0x0100, 0x0800 }, { 0x010A, 0x0644 }, { 0x010C, 0x0001 }, + { 0x010E, 0x0000 }, { 0x0110, 0x0015 }, { 0x0112, 0x4440 }, { 0x011E, 0x0200 }, { 0x0120, 0x0100 }, { 0x01EC, 0x03D9 }, + { 0x0280, 0x0A00 }, { 0x0282, 0xBE93 }, { 0x0284, 0xB332 }, { 0x0286, 0xBAC8 }, { 0x0288, 0xB6FD }, { 0x0502, 0x4F60 }, + { 0x0504, 0x000A }, { 0x0588, 0x0008 }, { 0x0692, 0x0222 }, { 0x0694, 0x0400 }, { 0x0698, 0x2310 }, { 0x0700, 0x0000 }, +}; + +const stGh3x2xReg stGh3x2xMpRegPPGConfig[] = +{ + { 0x0004, 0x001F }, { 0x000A, 0x0020 }, { 0x000E, 0x000D }, { 0x0280, 0x0A00 }, { 0x0282, 0xBE93 }, { 0x0284, 0xB332 }, + { 0x0286, 0xBAC8 }, { 0x0288, 0xB6FD }, { 0x0502, 0x4F60 }, { 0x0504, 0x000A }, { 0x0588, 0x0008 }, { 0x0692, 0x0222 }, + { 0x0694, 0x0400 }, { 0x0698, 0x2310 }, { 0x0700, 0x0000 }, +}; + +const stGh3x2xReg stGh3x2xMpRegECGLeadConfg[] = +{ + { 0x0004, 0x0013 }, { 0x0006, 0x0101 }, { 0x000A, 0x0096 }, { 0x000E, 0x000D }, { 0x0074, 0x0050 }, { 0x0100, 0x0100 }, + { 0x010A, 0x0162 }, { 0x010C, 0x0000 }, { 0x010E, 0x0000 }, { 0x0126, 0xC73C }, { 0x012C, 0x0C10 }, { 0x012E, 0x2222 }, + { 0x0130, 0x00AA }, { 0x0136, 0x00FF }, { 0x013A, 0x000C }, { 0x013C, 0x0400 }, { 0x01EA, 0x0033 }, { 0x01EC, 0x0030 }, + { 0x01EE, 0x0098 }, { 0x0200, 0x1020 }, { 0x0402, 0x5555 }, { 0x0404, 0x4130 }, { 0x0406, 0x0041 }, { 0x0408, 0x0001 }, + { 0x0410, 0x49F0 }, { 0x0412, 0x0082 }, { 0x0414, 0x49F0 }, { 0x0416, 0x0082 }, { 0x0422, 0x0011 }, { 0x0424, 0x0901 }, + { 0x0426, 0x0101 }, { 0x0428, 0x0104 }, { 0x0480, 0x6550 }, { 0x0502, 0x4C66 }, { 0x0588, 0x0008 }, { 0x0692, 0x0233 }, + { 0x0694, 0x0404 }, { 0x0698, 0x3310 }, { 0x069A, 0x1101 }, { 0x0700, 0x0000 }, { 0x0400, 0x5557 }, +}; + +const stGh3x2xReg stGh3x2xMpRegECGConfgDefault[] = +{ + { 0x0004, 0x001F }, { 0x000A, 0x0019 }, { 0x0074, 0x0058 }, { 0x0100, 0x0800 }, { 0x010A, 0x0062 }, { 0x010E, 0x0004 }, + { 0x01EA, 0x0033 }, { 0x01EC, 0x0064 }, { 0x0300, 0x0001 }, { 0x0302, 0x0103 }, { 0x0400, 0x5550 }, { 0x0402, 0x5555 }, + { 0x0404, 0x4120 }, { 0x0406, 0x0051 }, { 0x0408, 0x0001 }, { 0x0426, 0x0101 }, { 0x0428, 0x0101 }, { 0x0480, 0x6551 }, + { 0x0504, 0x001E }, { 0x0506, 0x001E }, { 0x0694, 0x0404 }, { 0x0698, 0x2310 }, { 0x0700, 0x0000 }, +}; + +/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/inc/gh3x2x_afe_drv.h b/code/sdk/drivers/peripheral/ppg/gh3x2x/inc/gh3x2x_afe_drv.h index 95f900cf5..09703eb7f 100644 --- a/code/sdk/drivers/peripheral/ppg/gh3x2x/inc/gh3x2x_afe_drv.h +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/inc/gh3x2x_afe_drv.h @@ -176,7 +176,7 @@ typedef long long GS64; /**< 64bit signed integer type */ #define GH3X2X_VAL_GET_BIT(x, b) ((x) &= (b)) -#define GH3X2X_AFE_I2C_DEVICE_BASE (0x28) +#define GH3X2X_AFE_I2C_DEVICE_BASE (0x14) #define GH3X2X_AFE_I2C_DEVICE_ADDR (GH3X2X_AFE_I2C_DEVICE_BASE | (GH3X2X_AFE_I2C_DEVICE_CTRL_PIN_STATUS << 1)) @@ -423,7 +423,7 @@ void *GH3X2X_Memset(void* pDest, GCHAR chVal, GU32 unByteSize); void GH3X2X_RecordAgcInfo(void); void GH3X2X_UpdateAgcInfo(void); -void gh3x2x_control(char* mode, uint8_t enable); +// void gh3x2x_control(char* mode, uint8_t enable); /*********************************************** master-slaver interface lib function *********************************/ #define GH3X2X_INFO_LOG(...) do {\ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/dl.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/dl.a new file mode 100644 index 000000000..12e912460 Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/dl.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/drv_common.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/drv_common.a new file mode 100644 index 000000000..f88e7fae7 Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/drv_common.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/dsp.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/dsp.a new file mode 100644 index 000000000..936d2caf9 Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/dsp.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/ecg.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/ecg.a new file mode 100644 index 000000000..d42d0c8a2 Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/ecg.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/hr.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/hr.a new file mode 100644 index 000000000..f53ad2753 Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/hr.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/hrv.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/hrv.a new file mode 100644 index 000000000..eaaf4de1d Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/hrv.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/nadt.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/nadt.a new file mode 100644 index 000000000..0612b9a0b Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/nadt.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/spo2.a b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/spo2.a new file mode 100644 index 000000000..ab2516f7a Binary files /dev/null and b/code/sdk/drivers/peripheral/ppg/gh3x2x/lib/spo2.a differ diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_drv.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_drv.c index 5fe8a90d6..5ccb75ca7 100644 --- a/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_drv.c +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_drv.c @@ -19,7 +19,7 @@ #include "gh3x2x_afe_demo.h" #include "custom_utils.h" - +// #include "gh_demo.h" #define SWAP_SIZE_OF_GU16 (2) #define SWAP_INDEX_OF_NEXT_BYTE (1) @@ -1311,7 +1311,16 @@ GCHAR *GH3X2X_GetAfeLibVersion(void) GU8 GH3X2X_AFE_GetChipId(void) { - return (GU8)GH3X2X_AFE_ReadRegBitField(GH3X2X_WHO_AM_I_REG_ADDR,GH3X2X_WHO_AM_I_LSB,GH3X2X_WHO_AM_I_MSB); + GU8 chipd_id = (GU8)GH3X2X_AFE_ReadRegBitField(GH3X2X_WHO_AM_I_REG_ADDR,GH3X2X_WHO_AM_I_LSB,GH3X2X_WHO_AM_I_MSB); + if(GH3X2X_CHIP_ID != chipd_id) + { + GH3X2X_INFO_LOG("wrong chip id!! 0x%x\r\n",chipd_id); + } + else + { + GH3X2X_INFO_LOG("check chip id success!! 0x%x\r\n",chipd_id); + } + return chipd_id; } GS8 GH3X2X_AFE_CheckChipId(void) @@ -1498,44 +1507,44 @@ GS8 GH3X2X_AFE_CheckEfuseCrc(void) return chRet; } -void gh3x2x_control(char* mode, uint8_t enable) -{ - - uint32_t md = 1; - if (strcmp(mode, "hrs") == 0) { - md = 0; - } else if (strcmp(mode, "hrv") == 0) { - md = 1; - } else if (strcmp(mode, "spo2") == 0) { - md = 2; - } else if (strcmp(mode, "leaklight") == 0) { - md = 4; - } else if (strcmp(mode, "graycard") == 0) { - md = 8; - } else if (strcmp(mode, "ledoff") == 0) { - md = 16; - } else if (strcmp(mode, "wear") == 0) { - md = 32; - } else if (strcmp(mode, "single") == 0) { - md = 64; - }else if (strcmp(mode, "factory") == 0) { - md = 128; - }else if (strcmp(mode, "fpc") == 0) { - // md = WORK_MODE_UNDEFINED; - }else if (strcmp(mode, "int") == 0) { - } - - if (enable == 1) - { - // ppg_service_running_stat = true; - // uapi_pm_control(PM_APP_WAKE_NEEDED); - // GH3X2X_AFE_StartFunction(mode); - GH3X2X_AFE_Init(); - GH3X2X_AFE_StartSampling(1); - - } else { +// void gh3x2x_control(char* mode, uint8_t enable) +// { + +// uint32_t md = 1; +// if (strcmp(mode, "hrs") == 0) { +// md = 0; +// } else if (strcmp(mode, "hrv") == 0) { +// md = 1; +// } else if (strcmp(mode, "spo2") == 0) { +// md = 2; +// } else if (strcmp(mode, "leaklight") == 0) { +// md = 4; +// } else if (strcmp(mode, "graycard") == 0) { +// md = 8; +// } else if (strcmp(mode, "ledoff") == 0) { +// md = 16; +// } else if (strcmp(mode, "wear") == 0) { +// md = 32; +// } else if (strcmp(mode, "single") == 0) { +// md = 64; +// }else if (strcmp(mode, "factory") == 0) { +// md = 128; +// }else if (strcmp(mode, "fpc") == 0) { +// // md = WORK_MODE_UNDEFINED; +// }else if (strcmp(mode, "int") == 0) { +// } + +// if (enable == 1) +// { +// // ppg_service_running_stat = true; +// // uapi_pm_control(PM_APP_WAKE_NEEDED); +// // GH3X2X_AFE_StartFunction(mode); +// // GH3X2X_AFE_Init(); +// // GH3X2X_AFE_StartSampling(1); +// Gh3x2xDemoInit(); +// } else { - // uapi_pm_control(PM_APP_WAKE_NONEED); - GH3X2X_AFE_StopSampling(); - } -} \ No newline at end of file +// // uapi_pm_control(PM_APP_WAKE_NONEED); +// // GH3X2X_AFE_StopSampling(); +// } +// } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_user.c b/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_user.c index 72781f957..fd28f6856 100644 --- a/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_user.c +++ b/code/sdk/drivers/peripheral/ppg/gh3x2x/src/gh3x2x_afe_user.c @@ -466,6 +466,6 @@ void GH3X2X_AFE_Log(GCHAR *log_string) { // GH3X2X_AFE_UNUSED_VAR(log_string); // GOODIX_PLATFORM_LOG_ENTITY(); - PRINT("%s", log_string); + printf("%s", log_string); } diff --git a/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.c b/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.c index aa7e24ccb..770034a80 100644 --- a/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.c +++ b/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-03-13 15:08:38 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-07-16 15:34:10 + * @LastEditTime: 2025-08-21 18:01:32 * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c * @Description: * @@ -35,6 +35,7 @@ #ifdef PPG_GH3X2X #include "gh3x2x_afe_drv.h" +// #include "gh_demo.h" #endif @@ -111,7 +112,7 @@ uint16_t ppg_get_chip_id(void) #elif defined PPG_PAH8009 chip_id = pah8009_get_chip_id(); #elif defined PPG_GH3X2X - // chip_id = GH3X2X_AFE_GetChipId(); + chip_id = GH3X2X_AFE_GetChipId(); #endif ppg_power_off(); return chip_id; @@ -137,9 +138,6 @@ void ppg_int_handler(void) { #ifdef PPG_PAH8009 pah8009_int_handler(); -#elif defined PPG_PAH8009 - hal_gh3x2x_afe_int_handler_call_back(); - GH3X2X_AFE_ChipPro(); #endif } @@ -153,7 +151,7 @@ void ppg_send_cmd_to_driver(char* mode, uint8_t enable) #elif defined PPG_PAH8009 pah8009_control(mode,enable); #elif defined PPG_GH3X2X - gh3x2x_control(mode,enable); + // gh3x2x_control(mode,enable); #endif if(!enable) ppg_power_off(); diff --git a/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.h b/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.h index a1623dee7..d9346d3ca 100644 --- a/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.h +++ b/code/sdk/drivers/peripheral/ppg/hal/ppg_hal.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-06-07 11:18:26 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-07-16 15:35:58 + * @LastEditTime: 2025-07-25 17:25:29 * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/ppg/ppg_hal.h * @Description: * diff --git a/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah800x_main.c b/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah800x_main.c index 6147c8243..b1659c906 100644 --- a/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah800x_main.c +++ b/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah800x_main.c @@ -86,11 +86,25 @@ static uint8_t work_mode = 0; static osTimerId_t g_pah8009_timer = NULL; static uint8_t time_cnt = 0; +static uint8_t wear_cnt = 0; static int history_wear_status = -1; static int data_cnt = 0; +#if POLLING_MODE +static int time_out = 40; +#endif + +static uint8_t hrs_num = 0; +static int32_t sum_hrs = 0; +static int8_t hrs_data[7] = {0}; +static uint8_t left = 0; +static uint8_t right = -1; +static uint8_t avg_hrs = 0; + +static uint8_t timeout = 0; + //============================================================================ // Private function //============================================================================ @@ -112,34 +126,47 @@ static void error_handle(void); static void pah8009_unwearstatus_update(void) { -#ifdef SUPPORT_PPG_SERVICE - ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); uint8_t data = 0; - if(func != NULL && !uapi_dev_runtime_get_train_status()) + printf("uapi_dev_runtime_get_train_status() : %d\n",uapi_dev_runtime_get_train_status()); + if(uapi_dev_runtime_get_train_status()) { - //为了主界面脱腕灵敏;需要增加未佩戴 - func(PPG_MSG_TYPE_HRS_UPDATE, &data, 1); - func(PPG_MSG_TYPE_WEARSTAT_UPDATE, &data,1); - func(PPG_MSG_TYPE_WEARSTAT_UPDATE,&data,1); - func(PPG_MSG_TYPE_WEARSTAT_UPDATE,&data,1); +#ifdef SUPPORT_CYWEE_SERVICE + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_HRS_CHANGE,&data); +#endif } + else + { +#ifdef SUPPORT_PPG_SERVICE + ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); + if(func != NULL) + { + //为了主界面脱腕灵敏;需要增加未佩戴 + func(PPG_MSG_TYPE_HRS_UPDATE, &data, 1); + func(PPG_MSG_TYPE_WEARSTAT_UPDATE, &data,1); + func(PPG_MSG_TYPE_WEARSTAT_UPDATE,&data,1); + func(PPG_MSG_TYPE_WEARSTAT_UPDATE,&data,1); + } #endif + } + } static void pah8009_wearstatus_update(int wear_status) { if(history_wear_status != wear_status) { + wear_cnt++; + history_wear_status = wear_status; #ifdef SUPPORT_CYWEE_SERVICE do_cywee_service_check_msg(CYWEE_SERVICE_CMD_WEAR_STATUS_CHANGE,(uint8_t *)&history_wear_status); #endif + if(wear_status != 1) + { + pah8009_unwearstatus_update(); + } } - if(wear_status != 1) - { - pah8009_unwearstatus_update(); - } } static void bubblesort(float *input,int count) @@ -358,6 +385,13 @@ void pah_sensor_stop(void) pah_800x_deinit(&_main.pah_800x); hr = 0; + hrs_num = 0; + sum_hrs = 0; + memset(hrs_data,0,7); + + left = 0; + right = -1; + avg_hrs = 0; } void ppg_interrupt_handle(void) @@ -447,7 +481,41 @@ void hr_algorithm_disable(void) _main.hr_is_enabled = false; } +static void get_avg_hrs(uint8_t hrs) +{ + int32_t min_hrs = 0; + int32_t max_hrs = 0; + if(hrs_num == 7) + { + sum_hrs -= hrs_data[left]; + hrs_data[left] = 0; + left++; + left = left % 7; + hrs_num--; + } + hrs_num++; + right++; + right = right % 7; + + hrs_data[right] = hrs; + sum_hrs += hrs_data[right]; + + if(hrs_num > 2) + { + min_hrs = hrs_data[0]; + max_hrs = hrs_data[0]; + for (int i = 0;i < hrs_num; i++) + { + if (hrs_data[i] < min_hrs) + min_hrs = hrs_data[i]; + if (hrs_data[i] > max_hrs) + max_hrs = hrs_data[i]; + } + avg_hrs = (sum_hrs - max_hrs - min_hrs) / (hrs_num - 2); + // printf("max_hrs[%d],min_hrs[%d],avg_hrs[%d]\n",max_hrs,min_hrs,avg_hrs); + } +} void hr_alg_task(void) { @@ -468,7 +536,12 @@ void hr_alg_task(void) if(pah_pop(&ppg_mems_data_alg)) //Get data from FIFO { if(_main.hr_is_enabled) - { + { + ppg_mems_data_alg.ppg_data.has_overflow = 0; + ppg_mems_data_alg.ppg_data.overflow_num = 0; + + + // 13Bytes format to hr lib; sRaw_Data_13Bytes hr_data; @@ -483,8 +556,7 @@ void hr_alg_task(void) hr_data.rsv = 0; hr_data.touch = (ppg_mems_data_alg.touch_flag > 0 ? 0x80 : 0x00); hr_data.rsv2 = 0; - - + int32_t ret = PxiAlg_Process_Expo((uint8_t*)&hr_data, ppg_mems_data_alg.MEMS_Data, ppg_mems_data_alg.ppg_data.exposure_time[1]); @@ -504,56 +576,33 @@ void hr_alg_task(void) #ifdef SUPPORT_PPG_SERVICE time_cnt++; - ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); - int ii=0; - if(func != NULL && time_cnt >= 25) + if(time_cnt >= 25) { - uint8_t data = (uint8_t)hr; - func(PPG_MSG_TYPE_HRS_UPDATE, &data, 1); - // data = cywee_wear_status; - // func(PPG_MSG_TYPE_WEARSTAT_UPDATE, &data, 1); - time_cnt = 0; + ppg_msg_callback_t func = ppg_get_send_msg_callback_func(); - data_cnt+=8; - - if(uapi_dev_runtime_get_hrs_ble_status()) - { - uint8_t encoded_hrm[17] = {0};//PPG_DATA_LEN_MAX>17会导致APP连接提示定义设备与所选类型不匹配 - - for(ii = 0; ii<8; ii++) + if(func != NULL) { + uint8_t data = (uint8_t)hr; - encoded_hrm[0] = 0x55;//心率标志位,一定要设置正确 - encoded_hrm[1] = (uint8_t)(data_cnt - 8 + ii) % 256;//原始data_cnt会一直自加,但是这里只有一个字节,0-255循环 - encoded_hrm[2] = (uint8_t)hr;//心率值 - - encoded_hrm[3] = 0; //绿灯原始数据 - encoded_hrm[4] = 0; //绿灯原始数据 - encoded_hrm[5] = 0; //绿灯原始数据 - - encoded_hrm[6] = 0; //ir原始数据 - encoded_hrm[7] = 0; //ir原始数据 - encoded_hrm[8] = 0; //ir原始数据 + if(data > 30 && data < 220) + get_avg_hrs(data); - encoded_hrm[9] = 0;//模拟x,1234换成填入自己的x数据 - encoded_hrm[10] = 0; - encoded_hrm[11] = 0;//模拟y,-1234换成填入自己的y数据 - encoded_hrm[12] = 0; - encoded_hrm[13] = 0;//模拟z,3987换成填入自己的z数据 - encoded_hrm[14] = 0; - - encoded_hrm[15] = 0;//绿灯电流 - encoded_hrm[16] = 0;//红外电流 + // printf("func(PPG_MSG_TYPE_HRS_UPDATE, &avg_hrs, 1); :%d\n",avg_hrs); + // func(PPG_MSG_TYPE_HRS_UPDATE, &avg_hrs, 1); - // if(cm_custom_ble_service_on_flag()) - ble_ppgtest_server_send_input_report(encoded_hrm,17); + // data = cywee_wear_status; + // func(PPG_MSG_TYPE_WEARSTAT_UPDATE, &data, 1); + time_cnt = 0; + + if(uapi_dev_runtime_get_hrs_ble_status()) + { + ble_ppgtest_server_send_input_report(&avg_hrs,1); + } - // ble_op_att_send_data(ATT_CHARACTERISTIC_2a37_01_VALUE_HANDLE,encoded_hrm, \ - // sizeof(encoded_hrm)/sizeof(encoded_hrm[0]), ATT_OP_NOTIFY);//heartrate } } - } + #endif @@ -1667,6 +1716,7 @@ int32_t pah8009_get_factory_data(void) void pah8009_int_handler(void) { + timeout = 1; ppg_interrupt_handle(); ppg_sensor_task_interrupt(); @@ -1702,6 +1752,7 @@ void pah8009_timer_handler(void) static void pah8009_timer_callback(void) { + // printf("pah8009_timer_callback \n"); #ifdef SUPPORT_PPG_SERVICE send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_HRS_TIMER_CALLBACK); #endif @@ -1713,6 +1764,33 @@ static void pah8009_timer_init(void) g_pah8009_timer = osTimerNew((osTimerFunc_t)pah8009_timer_callback, osTimerPeriodic, NULL, NULL); } +void pah8009_check_int(void) +{ +#if INTERRUPT_MODE + if(work_mode != 1) + { + // printf("work_mode != 1\n"); + return; + } + + if(!timeout) + { + // printf("pah8009_check_int \n"); + pah8009_int_handler(); + } + else + { + timeout = 0; + } +#endif +} + +void pah8009_reset(void) +{ + pah_sensor_stop(); + pah_sensor_init(diw_4mm_g_ir_hrd); + ppg_only_sensor_start(); +} void pah8009_control(char *mode,uint8_t enable) { @@ -1724,6 +1802,7 @@ void pah8009_control(char *mode,uint8_t enable) osTimerStop(g_pah8009_timer); #endif pah_sensor_stop(); + work_mode = 0; if(uapi_dev_runtime_get_sleep_monitoring_status() && uapi_dev_runtime_get_hrs_passivity_flag()) { pah8009_wearstatus_update(history_wear_status); @@ -1744,6 +1823,9 @@ void pah8009_control(char *mode,uint8_t enable) work_mode = 1; // touch_only_sensor_start(); ppg_only_sensor_start(); +#if POLLING_MODE + time_out = 20; +#endif } else if (strcmp(mode, "hrv") == 0) { // md = HRV_MODE; } else if (strcmp(mode, "spo2") == 0) { @@ -1751,6 +1833,9 @@ void pah8009_control(char *mode,uint8_t enable) pah_sensor_init(diw_4mm_ir_r_ir_spo2); ppg_only_sensor_start(); work_mode = 2; +#if POLLING_MODE + time_out = 20; +#endif } else if (strcmp(mode, "leaklight") == 0) { // md = FT_LEAK_LIGHT_MODE; factory_test_mode(factory_test_leak_light_target_sample, 0, 0, 0, 0); @@ -1759,10 +1844,13 @@ void pah8009_control(char *mode,uint8_t enable) } else if (strcmp(mode, "wear") == 0) { pah_sensor_init(diw_4mm_g_ir_hrd); touch_only_sensor_start(); +#if POLLING_MODE + time_out = 5000; +#endif } #if POLLING_MODE if(g_pah8009_timer != NULL) - osTimerStart(g_pah8009_timer,40); + osTimerStart(g_pah8009_timer,time_out); #endif } } \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah_800x_config.h b/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah_800x_config.h index 170110e0a..eb3a5ea7f 100644 --- a/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah_800x_config.h +++ b/code/sdk/drivers/peripheral/ppg/pah8009/sensor/pah_800x_config.h @@ -64,8 +64,8 @@ * This definition will enable the corresponding demo functionin main.c * If select INT mode, then slect following INT configuration type */ -#define INTERRUPT_MODE 1 -#define POLLING_MODE 0 +#define INTERRUPT_MODE 0 +#define POLLING_MODE 1 #define Test_pattern_mode 0 /* diff --git a/code/sdk/drivers/peripheral/ppg/ppgBleService/ppgBleService.c b/code/sdk/drivers/peripheral/ppg/ppgBleService/ppgBleService.c index fc1668d6b..9ae41320f 100644 --- a/code/sdk/drivers/peripheral/ppg/ppgBleService/ppgBleService.c +++ b/code/sdk/drivers/peripheral/ppg/ppgBleService/ppgBleService.c @@ -114,13 +114,13 @@ errcode_t ble_ppgtest_server_send_input_report(const uint8_t *data, uint8_t len) // printf("ble_hid_server_send_input_report:%d %d %d",data[0],data[1],len); gatts_ntf_ind_t param = {0}; param.attr_handle = (uint16_t)g_ppgtest_notify_report_att_hdl; - param.value_len = len; - param.value = bt_os_new(len); + param.value_len = len + 1; + param.value = bt_os_new(param.value_len); if (param.value == NULL) { printf( "[ppgtest][ERROR]send input report new fail\r\n"); return ERRCODE_BT_MALLOC_FAIL; } - if (memcpy_s(param.value, param.value_len, data, len) != EOK) { + if (memcpy_s(param.value + 1, param.value_len, data, len) != EOK) { printf( "[ppgtest][ERROR]send input report memcpy fail\r\n"); bt_os_free(param.value); return ERRCODE_BT_FAIL; diff --git a/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp b/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp index 08cb73371..4d858cac2 100644 --- a/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp +++ b/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp @@ -396,11 +396,7 @@ errcode_t uapi_ppg_service_init(void) app_task_definition_t taskcfg={0}; taskcfg.create_queue_handle = create_ppg_queue; taskcfg.attr.name="ppg_service"; -#ifdef BOARD_FD230 taskcfg.attr.priority = osPriorityBelowNormal4; -#else - taskcfg.attr.priority = osPriorityAboveNormal3; -#endif taskcfg.attr.stack_size = PPG_SERVICE_TASK_SIZE; taskcfg.func = ppg_service_check_task; taskcfg.use_mem = USE_EXTEND_MEM; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index dd891de02..b77e991f1 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -2035,10 +2035,10 @@ void get_gsensor_single(uint8_t *databuf) { gsenson_t t; get_gsonsen_xyz(&t); - uint16_t x,y,z; - x = t.x*2048; - y = t.y*2048; - z = t.z*2048; + int16_t x, y, z; + x = (int16_t)(t.x * 2048); + y = (int16_t)(t.y * 2048); + z = (int16_t)(t.z * 2048); databuf[0] = (uint8_t)((x & 0xFF00) >> 8); databuf[1] = (uint8_t)(x & 0x00FF); diff --git a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp index d165483be..104a6d063 100644 --- a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp +++ b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-08-08 16:33:23 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-12-19 18:04:22 + * @LastEditTime: 2025-08-21 16:11:55 * @FilePath: /FD230/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp * @Description: * @@ -29,28 +29,8 @@ extern "C" { #endif /* __cplusplus */ -#include "pinctrl.h" #include "debug_print.h" -#include "soc_osal.h" -#include "tcxo.h" -#include "irmalloc.h" -#include "errcode.h" #include "common_def.h" - -#include "chip_core_irq.h" -#include "chip_io.h" -#include "gpio.h" -#include "pm_veto.h" - -#include "rtc.h" -#include "timer.h" -#include "systick.h" - - -static bool g_batter_service_initialled = false; - -#include "tcxo.h" - #include "cmsis_os2.h" #include "input_app.h" @@ -223,7 +203,7 @@ errcode_t uapi_vibrator_service_init(void) OHOS::VibratorManager::GetInstance()->RegisterVibratorFunc(custom_VibratorFunc); /* ---------------------------------- 开机震动一次 ---------------------------------- */ - ui_api_vibrate_once_func(); + custom_VibratorFunc_int(0); /* -------------------------------------------------------------------------- */ return ERRCODE_SUCC; diff --git a/code/sdk/middleware/services/media/hal/audio/plugins/brandy/primary/primary_sub_port_in.c b/code/sdk/middleware/services/media/hal/audio/plugins/brandy/primary/primary_sub_port_in.c index 9e100707f..846254448 100755 --- a/code/sdk/middleware/services/media/hal/audio/plugins/brandy/primary/primary_sub_port_in.c +++ b/code/sdk/middleware/services/media/hal/audio/plugins/brandy/primary/primary_sub_port_in.c @@ -191,8 +191,11 @@ static int32_t AIDevOpen(td_handle *aiHandle, enum AudioCategory audioCategory) uapi_ai_gain gain = {}; MEDIA_HAL_DOFUNC_TIME(ret = uapi_ai_get_volume(*aiHandle, &gain)); CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "uapi_ai_get_volume failed"); - +#if defined(BOARD_N9) || defined(BOARD_W9) + gain.integer = gain.integer + 10; // 前端mic灵敏度不同可通过此处调增,增加4db增益 默认gain.integer = gain.integer+4 +#elif defined(BOARD_FD230) gain.integer = gain.integer - 9; // 前端mic灵敏度不同可通过此处调增,增加4db增益 默认gain.integer = gain.integer+4 +#endif MEDIA_HAL_DOFUNC_TIME(ret = uapi_ai_set_volume(*aiHandle, &gain)); CHK_FAILED_RETURN(ret, MEDIA_HAL_OK, ret, "uapi_ai_set_volume failed"); g_subPortTrackInOpened = true;