From: penglei <1624952103@qq.com> Date: Thu, 15 May 2025 03:10:25 +0000 (+0800) Subject: w9添加陀螺仪和表冠底层驱动服务,产测UI加入陀螺仪测试UI,优化w9底层服务 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=8a8ed92e7dcaefbc2caa3330f5a22fc07bf1079a;p=mirrors%2FFD230.git w9添加陀螺仪和表冠底层驱动服务,产测UI加入陀螺仪测试UI,优化w9底层服务 --- 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 fece0ba84..cc5570e4b 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -127,6 +127,14 @@ #include "bp_service.h" #endif +#ifdef ENABLE_GYRO +#include "gyro_service.h" +#endif + +#ifdef ROTARYENCODER_MIXO +#include "mixo_service.h" +#endif + #define EMMC_BASE_ADDR 0x52062000 #define TASK_PRIORITY_APP (osPriority_t)(17) #define TICK_TEN_MS (10U) @@ -504,8 +512,6 @@ uapi_pm_remove_sleep_veto(PM_ID_DEBUG); #endif #ifdef ENABLE_CUSTOM_I2C - custom_i2c_init(I2C_BUS_3); - custom_i2c_init(I2C_BUS_0); custom_i2c_init(I2C_BUS_2); #ifdef MAG_MMC5603 @@ -528,10 +534,14 @@ uapi_pm_remove_sleep_veto(PM_ID_DEBUG); uapi_bp_service_init(); #endif +#ifdef ENABLE_GYRO + uapi_gyro_service_init(); +#endif + +#ifdef ROTARYENCODER_MIXO + uapi_mixo_service_init(); #endif -#ifdef ENABLE_CUSTOM_SPI - custom_spi_init(SPI_BUS_0); #endif /*启动蓝牙ble服务,cywee有重置 mac地址的操作,会需要把 蓝牙服务开启放在cywee服务之后*/ diff --git a/code/sdk/application/wearable/fd230/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/fd230/service/broadcast/include/broadcast_feature.h index 230fd4a72..405a2356f 100644 --- a/code/sdk/application/wearable/fd230/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/fd230/service/broadcast/include/broadcast_feature.h @@ -19,9 +19,9 @@ extern "C" { #endif #endif -#ifdef SUPPORT_CAT1_SERVICE -#define SUPPORT_CAT1_MODEM -#endif +// #ifdef SUPPORT_CAT1_SERVICE +// #define SUPPORT_CAT1_SERVICE +// #endif #ifndef BROADCAST_FEATURE_NAME #define BROADCAST_FEATURE_NAME "BROADCAST" @@ -74,7 +74,7 @@ typedef enum { TOPIC_EVENT_GRAYCARD_UPDATA, TOPIC_EVENT_LEAKLIGHT_UPDATA, #endif -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE TOPIC_EVENT_CAT1_INCOMMING, TOPIC_EVENT_CAT1_CALLCONNTED, TOPIC_EVENT_CAT1_CALLENDED, diff --git a/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c index 7404f171f..f12386de7 100644 --- a/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c @@ -77,7 +77,7 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_SLEEPNOTE,A_CORE_MASK, 1}, {TOPIC_EVENT_DEBUGOUTPUT,A_CORE_MASK, 1}, {TOPIC_EVENT_SHUTDOWN_ANIMATIOR,A_CORE_MASK, 1}, -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE {TOPIC_EVENT_CAT1_INCOMMING, A_CORE_MASK, 1}, {TOPIC_EVENT_CAT1_CALLCONNTED, A_CORE_MASK, 1}, {TOPIC_EVENT_CAT1_CALLENDED, A_CORE_MASK, 1}, diff --git a/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp index 726570944..a0af7881d 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp @@ -135,7 +135,7 @@ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_HFP_PHONE_TO_WATCH, PRIORITY_ONE}, {TOPIC_EVENT_HFP_HINT, PRIORITY_ONE}, -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE {TOPIC_EVENT_CAT1_INCOMMING, PRIORITY_ONE}, {TOPIC_EVENT_CAT1_CALLCONNTED, PRIORITY_ONE}, {TOPIC_EVENT_CAT1_CALLENDED, PRIORITY_ONE}, @@ -224,7 +224,7 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_GRAYCARD_UPDATA); MsgCenterSubscribeTopic(TOPIC_EVENT_LEAKLIGHT_UPDATA); #endif -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_INCOMMING); MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_CALLCONNTED); MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_CALLENDED); @@ -1068,7 +1068,7 @@ void MsgCenterNotifySleepProc(const Topic topic, Request* req) } #endif -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE //来电处理函数 void MsgCenterNotifyCatIncomingCallProc(const Topic topic, Request* req) { @@ -1914,7 +1914,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_GRAYCARD_UPDATA, MsgCenterNotifyCardProc}, {TOPIC_EVENT_LEAKLIGHT_UPDATA, MsgCenterNotifyleaklightProc}, #endif -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE {TOPIC_EVENT_CAT1_INCOMMING, MsgCenterNotifyCatIncomingCallProc}, {TOPIC_EVENT_CAT1_CALLCONNTED, MsgCenterNotifyCat1CallConnectedProc}, {TOPIC_EVENT_CAT1_CALLENDED, MsgCenterNotifyCat1CallEndedProc}, diff --git a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h index 3c9fcf0f3..bd1d06501 100644 --- a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h @@ -19,7 +19,7 @@ extern "C" { #endif #endif -#define SUPPORT_CAT1_MODEM +#define SUPPORT_CAT1_SERVICE #ifndef BROADCAST_FEATURE_NAME #define BROADCAST_FEATURE_NAME "BROADCAST" @@ -72,7 +72,7 @@ typedef enum { TOPIC_EVENT_GRAYCARD_UPDATA, TOPIC_EVENT_LEAKLIGHT_UPDATA, #endif -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE TOPIC_EVENT_CAT1_INCOMMING, TOPIC_EVENT_CAT1_CALLCONNTED, TOPIC_EVENT_CAT1_CALLENDED, diff --git a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c index 7404f171f..f12386de7 100644 --- a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c @@ -77,7 +77,7 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_SLEEPNOTE,A_CORE_MASK, 1}, {TOPIC_EVENT_DEBUGOUTPUT,A_CORE_MASK, 1}, {TOPIC_EVENT_SHUTDOWN_ANIMATIOR,A_CORE_MASK, 1}, -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE {TOPIC_EVENT_CAT1_INCOMMING, A_CORE_MASK, 1}, {TOPIC_EVENT_CAT1_CALLCONNTED, A_CORE_MASK, 1}, {TOPIC_EVENT_CAT1_CALLENDED, A_CORE_MASK, 1}, diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 2e40b9edb..1312d53d4 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -568,12 +568,13 @@ target = { 'SUPPORT_AT_CUSTOMUTILS', 'CYWEE_SPORT', 'CYWEE_MAC_ACTIVE', + 'SUPPORT_CAT1_SERVICE', 'SUPPORT_TCPIP', 'SUPPORT_HID_SERVICE', 'SUPPORT_BAIDU_MAP', - 'CFG_FLASH_SIZE=8', + 'CFG_FLASH_SIZE=16', 'SUPPORT_BLE_SERVICE', - # 'FD230', + 'FD230', #"MEM_CHECK", #'ENABLE_WEBSOCKET', 'SINGLE_USER_PARTITION', @@ -588,9 +589,11 @@ target = { 'TEST_4G_UI', 'TEST_GPS_UI', 'NANDFLASH_F35UQA', - #'BLE_INSTRUCT', + 'BLE_INSTRUCT', 'FACTORYTEST_SERVICE', 'PPG_GH3X2X', + 'GYRO_SH5001', + 'ROTARYENCODER_MIXO', ], 'ram_component': [ #'baidumapsdk', @@ -605,7 +608,7 @@ target = { "slip", "cat1_service", "audio_manager", - #"CustomUIcomponentTool", + "CustomUIcomponentTool", "custom_utils", "custom_utilscpp", "custom_config", @@ -615,19 +618,20 @@ target = { "gnss", "gnss_sample", # "acc_sensor", - "batterry_service", - "bleservice", - "ppgBleService", - #"blemoder", - "factorytest_service", - "hid_service", - "producttest", + "batterry_service", + "bleservice", + "ppgBleService", + "blemoder", + "factorytest_service", + "hid_service", + "producttest", "cywee", "ppg_sensor_gh3x2x", "bp_sensor", + 'gyro', ], 'image_analysis': False, - 'fs_image_path':'evb', + 'fs_image_path':'fd230', 'fs_image': True }, 'brandy-native-js-w9-r': { @@ -635,9 +639,9 @@ target = { #自定义配置项,选择硬件及功能参数 'defines': [ 'BOARD_W9', - 'CFG_FLASH_SIZE=8', + 'FD230', + 'CFG_FLASH_SIZE=16', 'FT_SINGLE_UART', - 'CFG_FLASH_SIZE=8', 'SINGLE_USER_PARTITION', 'TPTYPE_CST86XX', 'NANDFLASH_F35UQA' @@ -649,12 +653,13 @@ target = { #自定义配置项,选择硬件及功能参数 'defines': [ 'BOARD_W9', + 'FD230', 'FT_SINGLE_UART', 'ENABLE_ECC', 'CFG_DRIVERS_NANDFLASH', 'SINGLE_USER_PARTITION', 'GPIO_POWERON_FLASH', - 'CFG_FLASH_SIZE=8', + 'CFG_FLASH_SIZE=16', 'NANDFLASH_F35UQA' ] }, 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 b506e9cd8..d43bff4a8 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 @@ -19,6 +19,15 @@ extern void bp_int_callback(pin_t pin, uintptr_t param); extern void ppg_int_callback(pin_t pin, uintptr_t param); #endif +#ifdef ENABLE_GYRO +extern void gyro_int_callback(pin_t pin, uintptr_t param); +#endif + +#ifdef ROTARYENCODER_MIXO +extern void mixo_int_callback(pin_t pin, uintptr_t param); +#endif + + /** * @addtogroup connectivity_config_boards * @{ @@ -153,6 +162,7 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO37 uart tx NC { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO38 uart rx NC #endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L0 NC { HAL_PIO_FUNC_I2S1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_L1 i2s1 @@ -320,7 +330,7 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { #endif #ifdef ENABLE_GYRO - { S_AGPIO_R8, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, + { S_AGPIO_R8, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, gyro_int_callback }, #else /**S_AGPIO_L32 GPO gps reset*/ // { S_AGPIO_L32, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, @@ -331,6 +341,9 @@ 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}, #endif +#ifdef ROTARYENCODER_MIXO + // { S_AGPIO_L0, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_DEDGE, mixo_int_callback}, +#endif }; /** * @} diff --git a/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c b/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c index aa6f91c5d..d5b389424 100644 --- a/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c +++ b/code/sdk/drivers/drivers/driver/touch/ft6x46_touch/ft6x46_touch1.c @@ -392,15 +392,15 @@ static ext_errno ft6x46_power_sequence(void) /*get chip id*/ ret = tp_ft6x46_i2c_data_read(FTS_REG_CHIP_ID, &chip_id[0], 1); if (ret != EXT_ERR_SUCCESS) { - tp_err("222222222get ic information, error1"); + tp_err("get ic information, error1"); return EXT_ERR_TP_ZTW523_POWERUP_READ_CHIPID; } ret = tp_ft6x46_i2c_data_read(FTS_REG_CHIP_ID2, &chip_id[1], 1); if (ret != EXT_ERR_SUCCESS) { - tp_err("3333333get ic information, error2"); + tp_err("get ic information, error2"); return EXT_ERR_TP_ZTW523_POWERUP_READ_CHIPID; } - // tp_print("11111111111111get ic information, chip id = 0x%02x%02x", chip_id[0], chip_id[1]); + // tp_print("get ic information, chip id = 0x%02x%02x", chip_id[0], chip_id[1]); if ((FTS_CHIP_IDH == chip_id[0]) && (FTS_CHIP_IDL == chip_id[1])) { tp_warning("get ic information, chip id = 0x%02x%02x", chip_id[0], chip_id[1]); return EXT_ERR_SUCCESS; diff --git a/code/sdk/zhihui/UI/producttest/CMakeLists.txt b/code/sdk/zhihui/UI/producttest/CMakeLists.txt index e3e73c1c0..b4b984b99 100644 --- a/code/sdk/zhihui/UI/producttest/CMakeLists.txt +++ b/code/sdk/zhihui/UI/producttest/CMakeLists.txt @@ -27,6 +27,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/testPing.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/testGPS.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/testpressure.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/testgyro.cpp ) diff --git a/code/sdk/zhihui/UI/producttest/include/testPresenter.h b/code/sdk/zhihui/UI/producttest/include/testPresenter.h index e1aedea50..15eeac51c 100644 --- a/code/sdk/zhihui/UI/producttest/include/testPresenter.h +++ b/code/sdk/zhihui/UI/producttest/include/testPresenter.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-08-23 10:50:37 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-11-05 14:34:43 + * @LastEditTime: 2025-05-13 18:35:42 * @FilePath: /FD230/code/sdk/application/wearable/fd230/nativeapp/nativeui/producttest/include/testPresenter.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -37,7 +37,7 @@ namespace OHOS CHARG, SPEAK, MOTOR, -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE CAT1, #endif BUTTON, @@ -47,10 +47,15 @@ namespace OHOS BTTEST, SEChipTest, PingTest, - +#ifdef SUPPORT_GNSS GPSTEST, - // pressuretest, +#endif +#ifdef ENABLE_LQBP002TA PRESSURETEST, +#endif +#ifdef ENABLE_GYRO + GYROTEST, +#endif OLDTEST, DEEPSLEEP, diff --git a/code/sdk/zhihui/UI/producttest/include/testView.h b/code/sdk/zhihui/UI/producttest/include/testView.h index 9c0d29c98..5899ada9c 100644 --- a/code/sdk/zhihui/UI/producttest/include/testView.h +++ b/code/sdk/zhihui/UI/producttest/include/testView.h @@ -31,6 +31,7 @@ #include "producttest/include/testPing.h" #include "producttest/include/testGPS.h" #include "producttest/include/testpressure.h" +#include "producttest/include/testgyro.h" #ifdef SUPPORT_A5133_SERVICE #include "producttest/include/testA5133.h" @@ -101,6 +102,7 @@ namespace OHOS bool ChangePingTESTView(int16_t thisView); bool ChangeGPSTESTView(int16_t thisView); bool ChangepressureTestTESTView(int16_t thisView); + bool ChangegyroTestTESTView(int16_t thisView); #ifdef SUPPORT_A5133_SERVICE bool ChangeA5133TESTView(int16_t thisView); #endif @@ -128,7 +130,7 @@ namespace OHOS testCHANINGView *test_charging_view{nullptr}; testSPEAKView *test_speak_view{nullptr}; testMOTORView *test_motor_view{nullptr}; - // #ifdef SUPPORT_CAT1_MODEM + // #ifdef SUPPORT_CAT1_SERVICE testcat1View *test_cat1_view{nullptr}; // #endif testbuttonView *test_KEY_view{nullptr}; @@ -144,6 +146,7 @@ namespace OHOS testPingView *test_Ping_view{nullptr}; testGPSView *test_GPS_view{nullptr}; testpressureView * test_pressure_view{nullptr}; + testgyroView * test_gyro_view{nullptr}; #ifdef SUPPORT_A5133_SERVICE testA5133View *test_A5133_view{nullptr}; diff --git a/code/sdk/zhihui/UI/producttest/include/testgyro.h b/code/sdk/zhihui/UI/producttest/include/testgyro.h new file mode 100644 index 000000000..cc4b8faa9 --- /dev/null +++ b/code/sdk/zhihui/UI/producttest/include/testgyro.h @@ -0,0 +1,88 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-05-12 15:44:33 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-13 15:38:45 + * @FilePath: /sdk615/code/sdk/zhihui/UI/producttest/include/testgyro.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef TEST_GYRO_VIEW_H +#define TEST_GYRO_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button_ext.h" + +//#include "cmsis_os.h" +#include +namespace OHOS +{ + + class testgyroView + { + + public: + struct ButtonConfig_ext_t + { + int x; + int y; + int w; + int h; + const char *str; + const char *ViewId; + const char *ImageSrc; + + //label + int label_x; + int label_y; + uint8_t ALIGN; + int Fontsize; + + }; + + + + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + char *text; // 文本 + uint8_t lineBreakMode; // 断行模式。 + }; + + + + + testgyroView(); + virtual ~testgyroView(); + static testgyroView *GetInstance(void); + + UIScrollView *testgyroInitIView(uint8_t); + void gyrodataTimerCallBack(void); + + void ClearAll(void); + private: + UILabelButtonExt *SetTheButton_ext(ButtonConfig_ext_t &buttonconfig);//, UIView::OnTouchListener *clickListener); + UILabel *InitLabel(LabelConfig &labelConfig); + bool testgyroScrollViewcrollViewinit(uint8_t); + UIScrollView *testgyroScrollView{nullptr}; + UILabel *label_1_MSG=NULL; + UILabel *label_2_MSG{nullptr}; + UILabel *label_3_MSG{nullptr}; + + UILabelButtonExt* labelButton_next = nullptr; + bool initViewStatus{false}; + UILabel *Title{nullptr}; // 标题 + + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/zhihui/UI/producttest/src/testView.cpp b/code/sdk/zhihui/UI/producttest/src/testView.cpp index bbb64bdab..e7072d1ce 100644 --- a/code/sdk/zhihui/UI/producttest/src/testView.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testView.cpp @@ -33,7 +33,7 @@ namespace OHOS {SPEAK,"speakButton","speak","speakButton_next" ,&testView::ChangspeakTESTView,true}, {MOTOR,"motorButton","motor","motorButton_next" ,&testView::ChangmotorTESTView,true}, - #ifdef SUPPORT_CAT1_MODEM + #ifdef SUPPORT_CAT1_SERVICE {CAT1,"cat1button","CAT1", "cat1button_next",&testView::ChangeCAT1TESTView,true}, #endif {BUTTON,"buttonbutton","button" ,"buttonbutton_next",&testView::ChangKEYTESTView,true}, @@ -47,10 +47,15 @@ namespace OHOS #if defined(SUPPORT_GNSS) {GPSTEST,"GPSTestbutton","GPSTest","GPSTestbutton_next" ,&testView::ChangeGPSTESTView,true}, #endif +#if defined(ENABLE_LQBP002TA) {PRESSURETEST,"pressureTestbutton","pressureTest","pressureTestbutton_next" ,&testView::ChangepressureTestTESTView,true}, - #ifdef AGINGTEST +#endif +#if defined(ENABLE_GYRO) + {GYROTEST,"gyroTestbutton","gyroTest","gyroTestbutton_next" ,&testView::ChangegyroTestTESTView,true}, +#endif +#ifdef AGINGTEST {OLDTEST,"oldtestbutton","aging" ,"oldtestexit",&testView::ChangeoldTESTView,true}, - #endif +#endif {DEEPSLEEP,"deepsleep","DeepSleepCurrent","xxxxxxxxx" ,&testView::ChangeoldTESTView,true}, {shutdown,"shutdown","shutdown", "xxxxxxxxx",&testView::ChangeoldTESTView,true}, {RESET,"reset","reset", "xxxxxxxxx",&testView::ChangeoldTESTView,true}, @@ -129,7 +134,7 @@ namespace OHOS delete test_motor_view;//7 test_motor_view = nullptr; } -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE if(test_cat1_view) { delete test_cat1_view;//8 @@ -650,7 +655,7 @@ SystemScrollView[TESTVIEW]->SetStyle(STYLE_BORDER_RADIUS, 0); bool testView::ChangepressureTestTESTView(int16_t thisView) { - +#if defined(ENABLE_LQBP002TA) if (SystemScrollView[thisView] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSEChipTESTView"); @@ -664,6 +669,26 @@ SystemScrollView[TESTVIEW]->SetStyle(STYLE_BORDER_RADIUS, 0); RootView::GetInstance()->Add(SystemScrollView[thisView]); } +#endif + return true; + } + + bool testView::ChangegyroTestTESTView(int16_t thisView) + { +#if defined(ENABLE_GYRO) + if (SystemScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSEChipTESTView"); + test_gyro_view = new testgyroView(); + if (test_gyro_view == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: new scrollView[%d] fail", thisView); + return false; + } + SystemScrollView[thisView] = test_gyro_view->testgyroInitIView((uint8_t)thisView); + RootView::GetInstance()->Add(SystemScrollView[thisView]); + } +#endif return true; } @@ -784,7 +809,7 @@ SystemScrollView[TESTVIEW]->SetStyle(STYLE_BORDER_RADIUS, 0); test_motor_view = nullptr; SystemScrollView[hideView]=nullptr; break; -#ifdef SUPPORT_CAT1_MODEM +#ifdef SUPPORT_CAT1_SERVICE case CAT1: RootView::GetInstance()->Remove(SystemScrollView[hideView]); delete test_cat1_view; @@ -856,12 +881,22 @@ SystemScrollView[TESTVIEW]->SetStyle(STYLE_BORDER_RADIUS, 0); SystemScrollView[hideView]=nullptr; break; #endif +#if defined(ENABLE_LQBP002TA) case PRESSURETEST: RootView::GetInstance()->Remove(SystemScrollView[hideView]); delete test_pressure_view; test_pressure_view = nullptr; SystemScrollView[hideView]=nullptr; break; +#endif +#if defined(ENABLE_GYRO) + case GYROTEST: + RootView::GetInstance()->Remove(SystemScrollView[hideView]); + delete test_gyro_view; + test_gyro_view = nullptr; + SystemScrollView[hideView]=nullptr; + break; +#endif default: break; diff --git a/code/sdk/zhihui/UI/producttest/src/testgyro.cpp b/code/sdk/zhihui/UI/producttest/src/testgyro.cpp new file mode 100644 index 000000000..1cd72779b --- /dev/null +++ b/code/sdk/zhihui/UI/producttest/src/testgyro.cpp @@ -0,0 +1,291 @@ +#include "wearable_log.h" +#include "custom_utils.h" +#include "producttest/include/testPresenter.h" + +#include "cmsis_os2.h" +#include "producttest/include/testView.h" +#include "producttest/include/testgyro.h" +// #include "gnss_sample.h" +#include "graphic_service.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif +#ifdef ENABLE_GYRO +#include "gyro_service.h" +#include "gyro_hal.h" +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + + + +namespace OHOS +{ + + static testgyroView *g_pSystemAboutTheWatchView{nullptr}; + + testgyroView::testgyroView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::SystemAboutTheWatchView"); + g_pSystemAboutTheWatchView = this; + } + + testgyroView::~testgyroView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testgyroView::~testgyroView"); + ClearAll(); + //g_pSystemAboutTheWatchView = nullptr; + } + + testgyroView *testgyroView::GetInstance() + { + + return g_pSystemAboutTheWatchView; + } + static osTimerId_t P_TEST_timer=NULL; + + void testgyroView::ClearAll() + { +#ifdef ENABLE_GYRO + gyro_stop(); +#endif + if(testgyroScrollView) + { + testgyroScrollView->RemoveAll(); + + if (P_TEST_timer != NULL) { + osTimerStop(P_TEST_timer); + osTimerDelete(P_TEST_timer); + P_TEST_timer = NULL; + } + if(labelButton_next) + { + delete labelButton_next; + labelButton_next=nullptr; + } + if(label_1_MSG) + { + delete label_1_MSG; + label_1_MSG=nullptr; + } + + if(label_2_MSG) + { + delete label_2_MSG; + label_2_MSG=nullptr; + } + + if(label_3_MSG) + { + delete label_3_MSG; + label_3_MSG=nullptr; + } + + if(Title) + { + delete Title; + Title=nullptr; + } + + delete testgyroScrollView; + testgyroScrollView=nullptr; + } + } + + UILabelButtonExt *testgyroView::SetTheButton_ext(ButtonConfig_ext_t &buttonconfig) + { + UILabelButtonExt *button = new UILabelButtonExt(); + if (button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::SetTheButton: button new fail!"); + return nullptr; + } + button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); + button->SetViewId(buttonconfig.ViewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + //button->SetStyle(STYLE_BORDER_RADIUS,0); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); + //button->SetStyleForState(STYLE_BORDER_RADIUS,0, UIButton::PRESSED); + button->SetTouchable(true); + button->SetStyle(STYLE_BACKGROUND_OPA, 0x80); + button->SetText(buttonconfig.str); + button->SetAlign(TEXT_ALIGNMENT_LEFT); + button->SetLabelPosition(buttonconfig.label_x,buttonconfig.label_y ); + button->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, buttonconfig.Fontsize); + UIView:: OnClickListener *touchListener = static_cast(testPresenter::GetInstance()); + button->SetOnClickListener(touchListener); + + return button; + } + + UILabel *testgyroView::InitLabel(LabelConfig &labelConfig) + { + UILabel *label = new UILabel(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(labelConfig.left, labelConfig.top, labelConfig.width, labelConfig.height); // 位置大小 + label->SetStyle(STYLE_TEXT_FONT, labelConfig.fontSize); // 字体大小 + label->SetStyle(STYLE_LINE_HEIGHT, labelConfig.lineHeigh); // 字体行高 + label->SetText(labelConfig.text); // 内容 + label->SetLineBreakMode(labelConfig.lineBreakMode); // 断行模式。 + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, labelConfig.fontSize); + label->SetAlign(TEXT_ALIGNMENT_LEFT); + return label; + } + + + void testgyroView:: gyrodataTimerCallBack(void) + { + //此处实现数据刷新 + char buf1[32]={0}; + char buf2[32]={0}; + char buf3[32]={0}; +#ifdef ENABLE_GYRO + gyro_data_t data = gyro_get_data(); + + // printf("gyro.x:%.2f gyro.y:%.2f gyro.z:%.2f \n",data.x,data.y,data.z); + + sprintf(buf1,"gyro.x:%.2f",data.x); + sprintf(buf2,"gyro.y:%.2f",data.y); + sprintf(buf3,"gyro.z:%.2f",data.z); +#endif + label_1_MSG->SetText(buf1); + label_2_MSG->SetText(buf2); + label_3_MSG->SetText(buf3); + RootView::GetInstance()->Invalidate(); + } + + void gyrodataTimerCallBackproc() + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&testgyroView::gyrodataTimerCallBack,testgyroView::GetInstance())); + } + + + bool testgyroView::testgyroScrollViewcrollViewinit(uint8_t id) + { + + testgyroScrollView = new UIScrollView(); + if (testgyroScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::testgyroScrollView new fail!"); + return false; + } + testgyroScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + testgyroScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + testgyroScrollView->SetStyle(STYLE_BORDER_RADIUS, 0); + testgyroScrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + testgyroScrollView->SetStyle(STYLE_BORDER_COLOR, Color::Yellow().blue); + + + UIView::OnDragListener *draglistener = static_cast(testPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::draglistener can not be nullptr!"); + return false; + } + testgyroScrollView->SetOnDragListener(draglistener); + + LabelConfig Config = { + .left = 100, + .top = 100, + .width = 300, + .height = 35, + .fontSize = 40, + .lineHeigh = 35, + .text = "", + .lineBreakMode = UILabel::LINE_BREAK_WRAP, + }; + label_1_MSG= InitLabel(Config); + if (label_1_MSG == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!"); + return false; + } + testgyroScrollView->Add(label_1_MSG); + + Config = { + .left = 100, + .top = 180, + .width = 300, + .height = 35, + .fontSize = 40, + .lineHeigh = 35, + .text = "", + .lineBreakMode = UILabel::LINE_BREAK_WRAP, + }; + label_2_MSG= InitLabel(Config); + if (label_2_MSG == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!"); + return false; + } + testgyroScrollView->Add(label_2_MSG); + + Config = { + .left = 100, + .top = 260, + .width = 300, + .height = 35, + .fontSize = 40, + .lineHeigh = 35, + .text = "", + .lineBreakMode = UILabel::LINE_BREAK_WRAP, + }; + label_3_MSG= InitLabel(Config); + if (label_3_MSG == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!"); + return false; + } + testgyroScrollView->Add(label_3_MSG); + + labelButton_next= testAboutView::GetInstance()->init_button_next(267,320,Test_ViewMapper_t[id].viewid_str_next); + testgyroScrollView->Add(labelButton_next); + + Title= testAboutView::GetInstance()->init_title(125,45,"GYRO_TEST"); + testgyroScrollView->Add(Title); + + + testgyroScrollView->SetTouchable(true); + testgyroScrollView->SetDraggable(true); + +#ifdef ENABLE_GYRO + gyro_start(); +#endif + + uint32_t tick; + osStatus_t retTimer; + P_TEST_timer = osTimerNew((osTimerFunc_t)gyrodataTimerCallBackproc, osTimerPeriodic, NULL, NULL); + tick =2000;// osMs2Tick(1000); + retTimer = osTimerStart(P_TEST_timer, tick); + if (retTimer != osOK && P_TEST_timer != NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", retTimer); + osTimerDelete(P_TEST_timer); + P_TEST_timer = NULL; + return false; + } + return true; + } + + UIScrollView *testgyroView::testgyroInitIView(uint8_t id) + { + if (!testgyroScrollViewcrollViewinit(id)) + { + return nullptr; + } + return testgyroScrollView; + } +} + +// #endif diff --git a/code/sdk/zhihui/drivers/charge/CMakeLists.txt b/code/sdk/zhihui/drivers/charge/CMakeLists.txt index 97149a107..7648073a0 100644 --- a/code/sdk/zhihui/drivers/charge/CMakeLists.txt +++ b/code/sdk/zhihui/drivers/charge/CMakeLists.txt @@ -26,7 +26,7 @@ set(PRIVATE_DEFINES set(PUBLIC_DEFINES SUPPORT_AT_CHARGE -ENABLE_HP4507 +ENABLE_HP4570 ) # use this when you want to add ccflags like -include xxx diff --git a/code/sdk/zhihui/drivers/cywee/Inc/cywee_hal.h b/code/sdk/zhihui/drivers/cywee/Inc/cywee_hal.h index 4a86e89a9..216fd977b 100644 --- a/code/sdk/zhihui/drivers/cywee/Inc/cywee_hal.h +++ b/code/sdk/zhihui/drivers/cywee/Inc/cywee_hal.h @@ -527,7 +527,7 @@ cywee_msg_callback_t cywee_get_send_msg_callback_func(void); void activity_mode_setstatus(int cmd); void cywee_oncharging_update(int oncharging_status); void cywee_wearstatus_update(int wearstatus); -void cywee_hrs_update(int hrs_data); +void cywee_hrs_update(void); void cywee_set_user_info(void); void cywee_get_sleep_data(int cmd); void cywee_reset_daily_data(void); diff --git a/code/sdk/zhihui/drivers/cywee/service/cywee_service.c b/code/sdk/zhihui/drivers/cywee/service/cywee_service.c index b40f7a25b..85ccbd381 100644 --- a/code/sdk/zhihui/drivers/cywee/service/cywee_service.c +++ b/code/sdk/zhihui/drivers/cywee/service/cywee_service.c @@ -321,7 +321,7 @@ static void cywee_service_check_task(void const *arg) break; case CYWEE_SERVICE_CMD_HRS_CHANGE: - cywee_hrs_update(mail.data); + // cywee_hrs_update(mail.data); break; case CYWEE_SERVICE_CMD_SEDENTARY_MODE: @@ -462,7 +462,7 @@ errcode_t uapi_cywee_service_init(void) void cywee_int_callback(pin_t pin, uintptr_t param) { - //PRINT("cywee_int1_callback %d 0x%X\n",pin,param); + // PRINT("cywee_int1_callback %d 0x%X\n",pin,param); uapi_gpio_clear_interrupt(pin); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_TIMER_CHECK, NULL); } diff --git a/code/sdk/zhihui/drivers/cywee/src/main_dml.c b/code/sdk/zhihui/drivers/cywee/src/main_dml.c index 38ea99f13..c21b2b703 100644 --- a/code/sdk/zhihui/drivers/cywee/src/main_dml.c +++ b/code/sdk/zhihui/drivers/cywee/src/main_dml.c @@ -23,6 +23,15 @@ #endif #include "custom_save_runtime.h" +#ifdef SUPPORT_GNSS +#include "gnss_ctl.h" +#include "NMEA0183.h" +#endif + +#ifdef PPG_HX3695 +#include "hx3695.h" +#endif + #define AP_ENABLE_DML_SDO_LISTEN #define GSENSON_MSG_COUNT 64 @@ -128,6 +137,85 @@ static uint8_t timeout = 0; static uint8_t wake_up_flag = 0; +static osTimerId_t g_sport_timer = NULL; +static bool g_sport_stat = false; +#define SPORT_CHECK_MS 1000 + +void cywee_gnss_update(void) +{ +#ifdef SUPPORT_GNSS + gps_data_t *gps_data = getGPSGlobaldata(); + if(gps_data == NULL) + { + PRINT("gps_data == NULL \n"); + return; + } + + if(gps_data->status < 1) + return; + + memset(&csd, 0, sizeof(CUSTOM_GNSS)); + csd.sensorType = CUSTOM_GNSS; + csd.dData[0] = gps_data->location.lat;//latitude (degrees) (range: -90~90); //纬度 + csd.dData[1] = gps_data->location.lng;//longitude (degrees) (range: -180~180) //经度 + csd.dData[2] = gps_data->location.alt;//altitude (meters) //海拔 + csd.dData[3] = gps_data->ground_course;//bearing (heading in degrees) //方位角 + csd.dData[4] = gps_data->ground_speed;//speed (m/s) //速度 + csd.dData[5] = gps_data->hdop;//Horizontal_Accuracy (meters) //水平精度 + csd.dData[6] = gps_data->vdop;//Vertical_Accuracy (meters) //垂直精度 + csd.dData[7] = 0; //水平精度衰减因子 + csd.dData[8] = 0; //垂直精度衰减因子 + CWM_CustomSensorInput(&csd); +#endif +} + + +void cywee_hrs_update(void) +{ + uint8_t hrs_data = 0; +#ifdef PPG_HX3695 + // hrs = hrs_data; + // CWM_OS_dbgPrintf("hrs_data : %d\r\n",hrs_data); + hrs_data = hx3695_get_hrs(); +#endif + memset(&csd, 0, sizeof(CUSTOM_HEARTRATE)); + csd.sensorType = CUSTOM_HEARTRATE; + csd.fData[0] = hrs_data; + CWM_CustomSensorInput(&csd); +} + +static void cywee_service_check_timer_callback(void) +{ + cywee_hrs_update(); + cywee_gnss_update(); +} + +static void cywee_sport_timer_start_check(uint32_t rtc_ms) +{ + if (g_sport_timer == NULL) + return; + + if (!g_sport_stat) + { + osTimerStart(g_sport_timer, rtc_ms); + g_sport_stat = true; + } + +} + +static void cywee_sport_timer_stop_check(void) +{ + if (g_sport_timer == NULL) + return; + + if (g_sport_stat) + { + osTimerStop(g_sport_timer); + g_sport_stat = false; + } +} + + #ifdef CYWEE_MAC_ACTIVE int cm__hs1__mac_c1_init(void); int cm__hs1__deinit(void); @@ -842,16 +930,6 @@ void cywee_time_sync(void) uapi_create_folder(dir_path); } -void cywee_hrs_update(int hrs_data) -{ - // hrs = hrs_data; - // CWM_OS_dbgPrintf("hrs_data : %d\r\n",hrs_data); - memset(&csd, 0, sizeof(CUSTOM_HEARTRATE)); - csd.sensorType = CUSTOM_HEARTRATE; - csd.fData[0] = hrs_data; - CWM_CustomSensorInput(&csd); -} - void cywee_oncharging_update(int oncharging_status) { // CWM_OS_dbgPrintf("oncharging : %d\r\n",oncharging_status); @@ -972,6 +1050,11 @@ void cywee_inactivity_mode_change(int mode) void cywee_activity_mode_change(int mode) { + if(mode != SPORT_ACTIVE_MODE_NORMAL) + cywee_sport_timer_start_check(SPORT_CHECK_MS); + else + cywee_sport_timer_stop_check(); + switch (mode) { //一般模式(生活模式) @@ -1089,11 +1172,11 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { gxyz_t.y = sensorEVT->fData[1]; gxyz_t.z = sensorEVT->fData[2]; - // CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", - // sensorEVT->fData[0], - // sensorEVT->fData[1], - // sensorEVT->fData[2] - // ); + CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", + sensorEVT->fData[0], + sensorEVT->fData[1], + sensorEVT->fData[2] + ); if(num_falg==GSENSON_MSG_COUNT) { @@ -1208,6 +1291,21 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { hrs_mode_state = 0; uapi_save_runtime_log(RUNTIME_LOG_OXYGEN_SPORT_MEASURE_END); } + } + if((int)sensorEVT->fData[1] == CUSTOM_GNSS) + { + CWM_OS_dbgPrintf("CUSTOM_GNSS !!! \r\n"); +#ifdef SUPPORT_GNSS + if((int)sensorEVT->fData[2] == 1) + { + + gnss_start(); + } + else + { + gnss_stop(); + } +#endif } break; case IDX_ALGO_SHAKE: @@ -1864,6 +1962,8 @@ int cywee_main_dml(void) cywee_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL); cywee_oncharging_update(get_charge_stat()); //初始化时检查充电状态 + + g_sport_timer = osTimerNew((osTimerFunc_t)cywee_service_check_timer_callback, osTimerPeriodic, NULL, NULL); //cywee_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY_AND_NAP); //cywee_inactivity_mode_change(INACTIVITY_MODE_SLEEPING); diff --git a/code/sdk/zhihui/drivers/gyro/CMakeLists.txt b/code/sdk/zhihui/drivers/gyro/CMakeLists.txt index 161f02e88..68110308c 100644 --- a/code/sdk/zhihui/drivers/gyro/CMakeLists.txt +++ b/code/sdk/zhihui/drivers/gyro/CMakeLists.txt @@ -8,6 +8,7 @@ set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/sh5001/sh5001.c ${CMAKE_CURRENT_SOURCE_DIR}/service/gyro_at_cmd.c ${CMAKE_CURRENT_SOURCE_DIR}/service/gyro_service.c + ${CMAKE_CURRENT_SOURCE_DIR}/service/gyro_hal.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/sh5001 diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c index 300f46f8d..ef0237f5d 100644 --- a/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c @@ -2,14 +2,14 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-16 20:49:09 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-01-04 17:01:37 + * @LastEditTime: 2025-05-12 17:47:30 * @FilePath: /sdk615/code/sdk/drivers/peripheral/GYRO/service/lqbp_at_cmd.c * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #include "at_cmd_api.h" #include "pm_control.h" #include "gyro_service.h" -#include "sh5001.h" +#include "gyro_hal.h" #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) #define GYRO_MAX_ARGC 8 @@ -52,8 +52,7 @@ static uint32_t gyro_start_test(uint8_t *para, uint32_t paraLen, char *strCommon UNUSED(strCommonCmd); UNUSED(paraLen); UNUSED(para); - // do_lqbp_service_check_msg(GYRO_SERVICE_CMD_START_CHECK); - SH5001_init(); + gyro_start(); return ERRCODE_SUCC; } static uint32_t gyro_stop_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) @@ -61,7 +60,7 @@ static uint32_t gyro_stop_test(uint8_t *para, uint32_t paraLen, char *strCommonC UNUSED(strCommonCmd); UNUSED(paraLen); UNUSED(para); - // do_lqbp_service_check_msg(GYRO_SERVICE_CMD_STOP_CHECK); + gyro_stop(); return ERRCODE_SUCC; } static const at_cmd_table_t g_gyro_cmd[] = { diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c new file mode 100644 index 000000000..9e0f083f1 --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c @@ -0,0 +1,76 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-05-12 09:59:09 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-12 17:45:29 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/gyro/service/gyro_hal.c + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEin + */ +#include +#include +#include "gyro_hal.h" + +#ifdef GYRO_SH5001 +#include "sh5001.h" +#endif + +void gyro_power_on(void) +{ +#ifdef GYRO_SH5001 + if(SH5001_init() == SH5001_TRUE) + printf("sh5001 init successful \n"); + else + printf("sh5001 init failed \n"); + + if(SH5001_SwitchPowerMode(SH5001_NORMAL_MODE) == SH5001_TRUE) + printf("sh5001 start successful \n"); + else + printf("sh5001 start failed \n"); +#endif +} + +void gyro_power_off(void) +{ +#ifdef GYRO_SH5001 + if(SH5001_SwitchPowerMode(SH5001_POWERDOWN_MODE) == SH5001_TRUE) + printf("sh5001 stop successful \n"); + else + printf("sh5001 stop failed \n"); +#endif +} + +void gyro_check(void) +{ +#ifdef GYRO_SH5001 + SH5001_ReadFIFO(); +#endif +} + +bool gyro_check_exist(void) +{ +#ifdef GYRO_SH5001 + if(gyro_get_chip_id() != SH5001_ID) + return false; + else + return true; +#endif + return false; +} + +gyro_data_t gyro_get_data(void) +{ + gyro_data_t data = {0}; +#ifdef GYRO_SH5001 + data = sh5001_get_gyro_data(); + // printf("%.3f %.3f %.3f\r\n",data.x,data.y,data.z); +#endif + return data; +} + +uint8_t gyro_get_chip_id(void) +{ +#ifdef GYRO_SH5001 + return SH5001_get_chip_id(); +#endif + return 0; +} \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h new file mode 100644 index 000000000..0caa9615e --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h @@ -0,0 +1,40 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-05-12 10:00:46 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-12 17:52:36 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/gyro/service/gyro_hal.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef GYRO_HAL_H__ +#define GYRO_HAL_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + +typedef struct { + float x; + float y; + float z; +} gyro_data_t; + + +void gyro_power_on(void); +void gyro_power_off(void); +void gyro_check(void); +gyro_data_t gyro_get_data(void); +uint8_t gyro_get_chip_id(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_service.c b/code/sdk/zhihui/drivers/gyro/service/gyro_service.c index ef6bae79d..521391dc0 100644 --- a/code/sdk/zhihui/drivers/gyro/service/gyro_service.c +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_service.c @@ -9,71 +9,28 @@ #include "input_app.h" #include "cmsis_os2.h" #include "custom_utils.h" -#include "sh5001.h" +#include "gyro_hal.h" #include "gyro_service.h" +#ifdef ROTARYENCODER_MIXO +#include "mixo_service.h" +#endif // #include "custom_runtime.h" /*** * 其他cmd在Header里定义,对外开放 */ #define GYRO_SERVICE_CMD_TIMER_CHECK 0x11 -#define GYRO_CHECK_MS 30 - static bool g_gyro_service_initialled = false; -osTimerId_t g_gyro_service_timer = NULL; static bool g_gyro_sensor_exist = false; -static bool g_bat_timer_is_running = false; static unsigned long g_app_queue= 0xFFFFFFFF; -static bool gyro_service_running_stat = false; - -static void gyro_service_check_timer_callback(void* data); -static void gyro_service_timer_start_check(uint32_t rtc_ms) -{ - - if (g_bat_timer_is_running ) - osTimerStop(g_gyro_service_timer); - - if (gyro_service_running_stat == true) - osTimerStart(g_gyro_service_timer, rtc_ms); - - g_bat_timer_is_running = true; - -} void do_gyro_service_check_msg(int cmd); -static void gyro_service_check_timer_callback(void * data) -{ - unused(data); - - g_bat_timer_is_running = false; - - if(gyro_service_running_stat == true){ - // mmc5603_check(); //此处只能直接加到timer callback中,采用queue的话,新能跟不上,系统资源会挂掉。 - do_gyro_service_check_msg(GYRO_SERVICE_CMD_TIMER_CHECK); - // gyro_service_timer_start_check(gyro_CHECK_MS); - } - - - -} -void uapi_gyro_service_deinit(void) -{ - /* Stop the time and clear the pin map */ - osTimerStop(g_gyro_service_timer); - osTimerDelete(g_gyro_service_timer); - - g_bat_timer_is_running = false; - g_gyro_service_timer = NULL; -} - - - void do_gyro_service_check_msg(int cmd) { int ret; @@ -105,15 +62,9 @@ static void gyro_service_check_task(void const *arg) if (mail.comm.app == GYRO_SERVICE_CMD_TIMER_CHECK) { gyro_check(); }else if (mail.comm.app == GYRO_SERVICE_CMD_START_CHECK){ - gyro_start(); - LOS_Mdelay(30); - gyro_service_running_stat = true; - gyro_service_timer_start_check(GYRO_CHECK_MS); + gyro_power_on(); }else if (mail.comm.app == GYRO_SERVICE_CMD_STOP_CHECK){ - gyro_service_running_stat = false; - osTimerStop(g_gyro_service_timer); - gyro_stop(); - LOS_Mdelay(20); + gyro_power_off(); } @@ -135,7 +86,7 @@ errcode_t uapi_gyro_service_init(void) if(!gyro_check_exist()) { - //TODO 设置气压计检测是否存在标识 + //TODO 设置陀螺仪检测是否存在标识 PRINT("gyro not found!\r\n"); return ERRCODE_FAIL; } @@ -156,18 +107,28 @@ errcode_t uapi_gyro_service_init(void) return ERRCODE_FAIL; } - g_gyro_service_timer = osTimerNew((osTimerFunc_t)gyro_service_check_timer_callback, osTimerPeriodic, NULL, NULL); - - return ERRCODE_SUCC; } -// void gyro_service_service_resume(void) -// { -// MMC_LOG("gyro_service_service resume!\r\n"); -// gyro_service_check_timer_callback(0); -// } -// void gyro_service_service_suspend(void) -// { -// MMC_LOG("gyro_service_service suspend!\r\n"); -// } \ No newline at end of file +void gyro_int_callback(pin_t pin, uintptr_t param) +{ + // PRINT("gyro_int_callback %d 0x%X\n",pin,param); + uapi_gpio_clear_interrupt(pin); + do_gyro_service_check_msg(GYRO_SERVICE_CMD_TIMER_CHECK); +} + +void gyro_start(void) +{ + do_gyro_service_check_msg(GYRO_SERVICE_CMD_START_CHECK); +#ifdef ROTARYENCODER_MIXO + mixo_stop(); +#endif +} + +void gyro_stop(void) +{ + do_gyro_service_check_msg(GYRO_SERVICE_CMD_STOP_CHECK); +#ifdef ROTARYENCODER_MIXO + mixo_start(); +#endif +} diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_service.h b/code/sdk/zhihui/drivers/gyro/service/gyro_service.h index 27f9f1d4a..3dd128822 100644 --- a/code/sdk/zhihui/drivers/gyro/service/gyro_service.h +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_service.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-23 15:12:01 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-12 17:47:11 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/gyro/service/gyro_service.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /** * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n * @@ -18,7 +26,7 @@ extern "C" { #include "stdint.h" #include "errcode.h" - +#include "platform_core.h" #define GYRO_SERVICE_CMD_START_CHECK 0x12 #define GYRO_SERVICE_CMD_STOP_CHECK 0x13 @@ -26,8 +34,9 @@ extern "C" { errcode_t uapi_gyro_service_init(void); void uapi_gyro_service_deinit(void); void do_gyro_service_check_msg(int cmd); - - +void gyro_int_callback(pin_t pin, uintptr_t param); +void gyro_start(void); +void gyro_stop(void); #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c index 77ff6b803..27035beb4 100644 --- a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c +++ b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c @@ -23,6 +23,8 @@ #define SH5001_I2C_BUS I2C_BUS_2 +static gyro_data_t gyro_data = {0}; + /****************************************************************** * Description: I2C or SPI bus interface functions and delay time function * @@ -1920,7 +1922,7 @@ void SH5001_ReadFIFO(void) SH5001_FIFO_Read_Data(fifoData, fifoEntriesCount); - printf("fc %d\r\n", fifoEntriesCount); + // printf("fc %d\r\n", fifoEntriesCount); for(i = 0; i < dataGroup; i++) { @@ -1931,14 +1933,18 @@ void SH5001_ReadFIFO(void) gyroData[1] = ((short)fifoData[j+9] << 8) | fifoData[j+8]; gyroData[2] = ((short)fifoData[j+11] << 8) | fifoData[j+10]; - printf("%d %d %d %d %d %d\r\n", accData[0], accData[1], accData[2],gyroData[0], gyroData[1], gyroData[2]); + gyro_data.x = (float)gyroData[0]; + gyro_data.y = (float)gyroData[1]; + gyro_data.z = (float)gyroData[2]; + + // printf("%d %d %d %d %d %d\r\n", accData[0], accData[1], accData[2],gyroData[0], gyroData[1], gyroData[2]); j = j + SH5001_WATERMARK_DIV; } // clear INT - // SH5001_INT_Read_Status01(); + SH5001_INT_Read_Status01(); } @@ -2077,6 +2083,26 @@ void SH5001_Get_Otpoffset(short vacc[3]) * return: SH5001_TRUE or SH5001_FALSE * ******************************************************************/ + +uint8_t SH5001_get_chip_id(void) +{ + unsigned char regData = 0; + unsigned char i = 0; + + // SH5001 chipID = 0xA1; + while((regData != 0xA1U) && (i++ < 3U)) + { + SH5001_read(SH5001_ADDRESS, SH5001_CHIP_ID, 1, ®Data); + if((i == 3) && (regData != 0xA1U)) + { + printf("SH5001 init fail, Chip ID = 0x%x\r\n", regData); + return SH5001_FALSE; + } + } + printf("SH5001 Chip ID = 0x%x\r\n", regData); + return regData; +} + unsigned char SH5001_init(void) { unsigned char regData = 0; @@ -3051,4 +3077,10 @@ void SH5001_Get_Adc_Polarity(short gyroPolarity[3]) int sh5001_get_version(void) { return MCU_VERSION_SH5001; +} + +gyro_data_t sh5001_get_gyro_data(void) +{ + gyro_data_t data = gyro_data; + return data; } \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h index 58ee98b5f..08cd2cd85 100644 --- a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h +++ b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h @@ -1,7 +1,9 @@ #ifndef __SH5001_H #define __SH5001_H -//#define SH5001_FIFO_WM_INT +#include "gyro_hal.h" + +#define SH5001_FIFO_WM_INT //#define SH5001_ACTIVITY_INT //#define SH5001_DATA_READY_INT @@ -12,6 +14,7 @@ ******************************************************************/ #define SH5001_ADDRESS (0x36U) #define SENODIA_VDD_3V3 1 +#define SH5001_ID 0xA1 /****************************************************************** * SH5001 Registers Macro Definitions @@ -690,6 +693,8 @@ extern void SH5001_FastOffsetComp(unsigned char SH5001Positon); extern void SH5001_initFIFO(void); extern void SH5001_ReadFIFO(void); - + +unsigned char SH5001_get_chip_id(void); +gyro_data_t sh5001_get_gyro_data(void); #endif diff --git a/code/sdk/zhihui/drivers/ppg/gh3x2x/src/gh3x2x_hal.c b/code/sdk/zhihui/drivers/ppg/gh3x2x/src/gh3x2x_hal.c index 5a6f1ec43..2a84d343e 100644 --- a/code/sdk/zhihui/drivers/ppg/gh3x2x/src/gh3x2x_hal.c +++ b/code/sdk/zhihui/drivers/ppg/gh3x2x/src/gh3x2x_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-02-18 14:35:27 + * @LastEditTime: 2025-05-13 16:48:04 * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c * @Description: * @@ -30,15 +30,7 @@ uint32_t tyhx_poweron(void) uapi_pin_set_mode(GPIO_PIN_PRG_LED_ON, (pin_mode_t)HAL_PIO_FUNC_GPIO); uapi_gpio_set_dir(GPIO_PIN_PRG_LED_ON, GPIO_DIRECTION_OUTPUT); uapi_gpio_set_val(GPIO_PIN_PRG_LED_ON, GPIO_LEVEL_HIGH); - LOS_Mdelay(10); - uapi_pin_set_mode(S_AGPIO_L24, (pin_mode_t)HAL_PIO_FUNC_GPIO); - uapi_gpio_set_dir(S_AGPIO_L24, GPIO_DIRECTION_OUTPUT); - uapi_gpio_set_val(S_AGPIO_L24, GPIO_LEVEL_LOW); - LOS_Mdelay(10); - uapi_pin_set_mode(S_MGPIO0, (pin_mode_t)HAL_PIO_FUNC_GPIO); - uapi_gpio_set_dir(S_MGPIO0, GPIO_DIRECTION_OUTPUT); - uapi_gpio_set_val(S_MGPIO0, GPIO_LEVEL_LOW); - LOS_Mdelay(10); + uapi_pin_set_mode(GPIO_PIN_PRG_RESET, (pin_mode_t)HAL_PIO_FUNC_GPIO); uapi_gpio_set_dir(GPIO_PIN_PRG_RESET, GPIO_DIRECTION_OUTPUT); uapi_gpio_set_val(GPIO_PIN_PRG_RESET, GPIO_LEVEL_HIGH); diff --git a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c index 224305c94..a847f5aa6 100644 --- a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c +++ b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.c @@ -125,7 +125,7 @@ uint8_t alg_ram[11 * 1024] __attribute__((aligned(4))); //uint8_t alg_ram[10] = {0}; ppg_sensor_data_t ppg_s_data; -static int cywee_data = 0; +static int cywee_hrs_data = 0; static int history_wear_status = -1; static int cywee_wear_status = 0; @@ -2715,6 +2715,11 @@ static void get_avg_hrs(int32_t hrs) } } +uint8_t hx3695_get_hrs(void) +{ + return cywee_hrs_data; +} + void hx3695_set_hrs_ble_swtich(uint8_t cmd) { hrs_ble_falg = cmd; @@ -2732,8 +2737,7 @@ void hx3695_wearstatus_update(void) if(history_wear_status != cywee_wear_status) { history_wear_status = cywee_wear_status; - cywee_data = history_wear_status; - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_WEAR_STATUS_CHANGE,&cywee_data); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_WEAR_STATUS_CHANGE,&cywee_wear_status); } } //脱腕上报未佩戴信息 @@ -2755,8 +2759,8 @@ void hx3695_unwearstatus_update(void) { cywee_wear_status = 0; hx3695_wearstatus_update(); - cywee_data = 0; - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_HRS_CHANGE,&cywee_data); + cywee_hrs_data = 0; + // do_cywee_service_check_msg(CYWEE_SERVICE_CMD_HRS_CHANGE,&cywee_data); } } @@ -3027,8 +3031,8 @@ void hx3695_hrs_ppg_Int_handle(void) if(uapi_dev_runtime_get_train_status()) { hx3695_wearstatus_update(); - cywee_data = hrsresult.lastesthrs; - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_HRS_CHANGE,&cywee_data); + cywee_hrs_data = hrsresult.lastesthrs; + // do_cywee_service_check_msg(CYWEE_SERVICE_CMD_HRS_CHANGE,&cywee_data); } } diff --git a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.h b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.h index 228abb14b..0e78bf5d0 100644 --- a/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.h +++ b/code/sdk/zhihui/drivers/ppg/hx3695/hx3695.h @@ -301,6 +301,7 @@ void hx3695_wearstatus_update(void); void hx3695_unwearstatus_update(void); void hx3695_set_hrs_ble_swtich(uint8_t cmd); uint8_t hx3695_get_hrs_ble_swtich(void); +uint8_t hx3695_get_hrs(void); #include "hx3695_hal.h" #endif diff --git a/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt b/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt index 25532568e..8fbccd694 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt +++ b/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt @@ -48,6 +48,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mixo/mixo_ots_driver.c ${CMAKE_CURRENT_SOURCE_DIR}/mixo/mixo_ots_access.c ${CMAKE_CURRENT_SOURCE_DIR}/mixo/mixo_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/mixo/mixo_hal.c + ${CMAKE_CURRENT_SOURCE_DIR}/mixo/mixo_service.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/mixo diff --git a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508_hal.h b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508_hal.h index 740d4f325..9b357fc2d 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508_hal.h +++ b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508_hal.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-23 15:11:25 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-01-02 19:43:35 + * @LastEditTime: 2025-05-13 17:09:24 * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508_hal.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE; */ @@ -14,8 +14,8 @@ * History: \n * 2022-07-20, Create file. \n */ -#ifndef HX3507_HAL_H -#define HX3507_HAL_H +#ifndef HX3508_HAL_H +#define HX3508_HAL_H #include #include diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.c b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.c index b81485df0..95cf9beab 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-18 10:23:22 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-01-04 11:21:49 + * @LastEditTime: 2025-05-14 16:30:48 * @FilePath: /sdk615/code/sdk/drivers/peripheral/rotary_encoder/mixo/mixo_at_cmd.c * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -15,6 +15,7 @@ #include "debug_print.h" #include "mixo_ots_driver.h" #include "custom_utils.h" +#include "mixo_service.h" #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) @@ -78,7 +79,7 @@ static uint32_t mixo_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) // PRINT("SKIP mixotest start, already started\r\n"); // return 0; // } - mixo_ots_init(); + mixo_start(); // mixo_start(); g_mixo_test_started = 1; }else if (start == 2){ @@ -87,7 +88,7 @@ static uint32_t mixo_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) PRINT("SKIP mixotest stop, already stopped\r\n"); return 0; } - // mixo_stop(); + mixo_stop(); g_mixo_test_started = 0 ; } return ERRCODE_SUCC; diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_hal.c b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_hal.c new file mode 100644 index 000000000..551e98e85 --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_hal.c @@ -0,0 +1,151 @@ +#include "at_cmd_api.h" +#include "pm_control.h" +#include "rotary_encoder_def.h" +#include "debug_print.h" +#include "mixo_ots_driver.h" +#include "custom_utils.h" +#include "pinctrl_porting.h" +#include "mixo_service.h" + +#define MIXO_INT_PIN S_AGPIO_L0 +#define INT_MODE 1 +#define TIMER_MODE 0 + +static uint8_t g_mixo_test_started = 0; +encoder_callback g_encoder_callback = NULL; + +void mixo_int_callback(pin_t pin, uintptr_t param) +{ + PRINT("mixo_int_callback %d 0x%X\n",pin,param); + uapi_gpio_clear_interrupt(pin); + // uapi_pin_set_ie(MIXO_INT_PIN,HAL_PIO_IE_DISABLE); + mixo_start(); // 启动定时器 +} + +void mixo_check(void) +{ + if(mixo_get_check_mode() == TIMER_MODE) + mixo_ots_timer_callback(); + // else if(mixo_get_check_mode() == INT_MODE) + // { + // mixo_stop(); // 关闭定时器 + // // uapi_pin_set_ie(MIXO_INT_PIN,HAL_PIO_IE_ENBALE); + // } +} + + +void mixo_suspend(void) +{ + mixo_ots_enter_suspend_mode(1); +} + +void mixo_resume(void) +{ + mixo_ots_enter_suspend_mode(0); +} + + +uint32_t mixo_init(void) +{ + if(mixo_ots_init() != ERRCODE_SUCC) + return ERRCODE_FAIL; + + return ERRCODE_SUCC; +} + +static ext_errno mixo_encoder_init(void *attr) +{ + re_print("mixo_encoder_init\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_encoder_deinit(void) +{ + re_print("mixo_encoder_deinit\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_encoder_get_encoderinfo(uint8_t *data, uint8_t data_len) +{; + if (data_len != sizeof(re_input_event_info)) + return EXT_ERR_NOT_SUPPORT; + re_input_event_info *encoder_info = (re_input_event_info*)data; + int16_t diff = mixo_get_crown_result(); + int16_t stand_still = mixo_get_stand_still(); + // re_print("mixo_encoder_get_encoderinfo diff %d stand_still %d\n",diff,stand_still); + if (stand_still == 1 ) + { + encoder_info->re_event = MC_RE_COVER; + }else { + encoder_info->re_event = MC_RE_MOVE; + } + encoder_info->re_event_info.x_axis[0] = diff; + encoder_info->re_event_info.y_axis[0] = diff; + encoder_info->re_event_info.z_axis[0] = diff; + encoder_info->finger_id = 0 ; + encoder_info->point_num = 0 ; + encoder_info->tv_usec = (uint32_t)uapi_tcxo_get_ms(); + //re_print("mixo_encoder_get_encoderinfo %s rotate %d\r\n",encoder_info->re_event == MC_RE_SLIDE_UP?"MC_RE_SLIDE_UP":"MC_RE_SLIDE_DOWN",diff); + + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_encoder_suspend(void) +{ + re_print("mixo_encoder_suspend\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_encoder_resume(void) +{ + re_print("mixo_encoder_resume\r\n"); + mixo_start(); + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_encoder_sleep(void) +{ + re_print("mixo_encoder_sleep\r\n"); + mixo_stop(); + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_encoder_reset(void) +{ + re_print("mixo_encoder_reset\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_encoder_bus_init(void *private_data) +{ + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_register_callback(void *peri_data, encoder_callback func) +{ + re_print("mixo_register_callback\r\n"); + g_encoder_callback = func; + return EXT_ERR_SUCCESS; +} +static ext_errno mixo_unregister_callback(void *peri_data) +{ + re_print("mixo_unregister_callback\r\n"); + g_encoder_callback = NULL; + return EXT_ERR_SUCCESS; +} + +encoder_peripheral_api g_mixo_api = { + .encoder_init = mixo_encoder_init, + .encoder_deinit = mixo_encoder_deinit, + .encoder_get_encoderinfo = mixo_encoder_get_encoderinfo, + .encoder_suspend = mixo_encoder_suspend, + .encoder_resume = mixo_encoder_resume, + .encoder_sleep = mixo_encoder_sleep, + .encoder_reset = mixo_encoder_reset, + .encoder_bus_init = mixo_encoder_bus_init, + .register_callback = mixo_register_callback, + .unregister_callback = mixo_unregister_callback, +}; + + +void *rotary_encoder_get_mixo_api(void) +{ + return ((void *)&g_mixo_api); +} + +void *rotary_encoder_get_mixo_peri_attr(void) +{ + return ((void *)NULL); +} \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_hal.h b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_hal.h new file mode 100644 index 000000000..7b677adff --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_hal.h @@ -0,0 +1,47 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-23 15:11:25 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-14 16:37:32 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508_hal.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE; + */ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Provides at cmd register func \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-07-20, Create file. \n + */ +#ifndef MIXO_HAL_H +#define MIXO_HAL_H + +#include +#include +#include "errcode.h" +#include "soc_osal.h" +#include "rotary_encoder_def.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +void *rotary_encoder_get_mixo_api(void); +void *rotary_encoder_get_mixo_peri_attr(void); + +uint32_t mixo_init(void); + +void mixo_check(void); + +void mixo_suspend(void); +void mixo_resume(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c index 21e6ed824..d5021322b 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c @@ -1,10 +1,10 @@ #include "mixo_ots_driver.h" - #include #include - #include "mixo_ots_access.h" #include "cmsis_os2.h" +#include "debug_print.h" +#include "mixo_hal.h" #ifndef ABS #define ABS(x) ((x) > 0 ? (x) : -(x)) @@ -16,17 +16,52 @@ static int dx_sum = 0; -static bool ots_timer_running = false; //ots定时器是否运行标志 +static uint16_t timer_cnt = 0; + +static int16_t ots_result = 0;//ots结果 +static int16_t stand_still = 1; //静止标志 1 静止,0 转动 + +static uint8_t int_mode = 0; + +extern encoder_callback g_encoder_callback; + + +static void put_crown_result(int16_t x) +{ + if(abs(x)<=1 ) + { + return; + } + if(abs(x)>=4 ) + { + ots_result += x/4; //大于4的值除以4, 代表角度, 单位0.5° + } + else + { + if(x>0) + { + ots_result+=1; //2~4 默认一个单位, 0.5° + } + else + { + ots_result-=1; //2~4 默认一个单位, 0.5° + } + } -static osTimerId_t g_ots_timer = NULL; + if (g_encoder_callback != NULL) + g_encoder_callback(); +} -static void ots_timer_callback(void) +void mixo_ots_timer_callback(void) { uint8_t mot_status = 0x00; mixo_ots_get_mot_status(&mot_status); + if ((mot_status & 0x80) == 0x80) { + timer_cnt = 0; + int_mode = 0; // Get raw datas raw_data_t raw_data; mixo_ots_get_raw_data(&raw_data); @@ -34,35 +69,33 @@ static void ots_timer_callback(void) // Output raw data // printf("%ld,%d,%d,%d,%d\r\n", timestamp, raw_data.dx, raw_data.dy, mot_status, dx_sum); - } -} + // PRINT("%d,%d,%d,%d\r\n",raw_data.dx, raw_data.dy, mot_status, dx_sum); -void mixo_ots_start(void) -{ - if(ots_timer_running == false && g_ots_timer) - { - osTimerStart(g_ots_timer,10); - ots_timer_running = true; - } -} + put_crown_result(raw_data.dx); + stand_still = 0; -void mixo_ots_stop(void) -{ - if(ots_timer_running == true && g_ots_timer) + if (g_encoder_callback != NULL) + g_encoder_callback(); + + } + else { - osTimerStop(g_ots_timer); - ots_timer_running = false; + // timer_cnt++; + // if (timer_cnt == 20) // 20*10 = // 200ms:200ms内sensor没有检测到表冠转动就会关闭定时器重新开启中断响应 + // { + // printf("mixo enter int mode\n"); + // /** + // * 此处注意 mixo_ots_forced_clear_int + // * 必须放在 external_int_init 之前去做 + // * 否则可能造成功耗异常的问题 + // */ + // mixo_ots_forced_clear_int(); // 强制拉高MOT脚 + // int_mode = 1; + // } + stand_still = 1; } } -void mixo_ots_timer_init(void) -{ - g_ots_timer = osTimerNew((osTimerFunc_t)ots_timer_callback, osTimerPeriodic, NULL, NULL); - - if(!g_ots_timer) - PRINT("g_ots_timer init failed \n"); -} - /** * @brief 接收1byte数据 @@ -142,7 +175,7 @@ int mixo_ots_get_raw_data(raw_data_t* raw_data) // If overflowed, clear out the data if ((ABS(raw_data->dx) == 2047) || (ABS(raw_data->dy) == 2047)) { - printf("dy/dx overflowed."); + // printf("dy/dx overflowed."); mixo_ots_reg_read(0x02, &tmp); mixo_ots_reg_read(0x02, &tmp); @@ -246,10 +279,13 @@ int callisto_2x_init(void) return ret; } - +static uint8_t mixo_installized = 0; int mixo_ots_init(void) { + if(mixo_installized) + return 0; + int rc = 0; uint8_t HardWareId = 0; @@ -269,11 +305,13 @@ int mixo_ots_init(void) break; default: printf("OTS Sensor Not Support!\n"); + rc = -1; break; } if(rc == 0) { + mixo_installized = 1; printf("mixo_ots_init succed !!! \n"); } else @@ -283,3 +321,26 @@ int mixo_ots_init(void) return rc; } +int16_t mixo_get_stand_still(void) +{ + return stand_still; +} + +void mixo_clean_result(void) +{ + ots_result = 0; +} + + +int16_t mixo_get_crown_result(void) +{ + int16_t resulttemp; + resulttemp=ots_result; + ots_result = 0; + return resulttemp; +} + +uint8_t mixo_get_check_mode(void) +{ + return int_mode; +} diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.h b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.h index 5093bb2ee..a991947ec 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.h +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-01-04 10:53:54 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-14 17:13:14 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /* * Copyright (c) 2019 MixoSense Technology Ltd . * @@ -26,4 +34,13 @@ int mixo_ots_get_raw_data(raw_data_t* raw_data); void mixo_ots_forced_clear_int(void); void mixo_ots_enter_suspend_mode(uint8_t true_or_false); +void mixo_ots_start(void); +void mixo_ots_stop(void); + +int16_t mixo_get_stand_still(void); +int16_t mixo_get_crown_result(void); +void mixo_ots_timer_callback(void); +void mixo_clean_result(void); +uint8_t mixo_get_check_mode(void); + #endif //_MXS_DRIVER_H_ diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_service.c b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_service.c new file mode 100644 index 000000000..c918c7390 --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_service.c @@ -0,0 +1,157 @@ + +#include "debug_print.h" +#include "soc_osal.h" +#include "tcxo.h" +#include "irmalloc.h" +#include "errcode.h" +#include "common_def.h" +#include "tcxo.h" +#include "input_app.h" +#include "cmsis_os2.h" +#include "custom_utils.h" +#include "mixo_hal.h" +#include "mixo_service.h" +#include "pinctrl_porting.h" + +// #include "custom_runtime.h" +/*** + * 其他cmd在Header里定义,对外开放 +*/ +#define MIXO_SERVICE_CMD_TIMER_CHECK 0x11 + +#define MIXO_SERVICE_TIMER_CHECK_MS 40 + +static bool g_mixo_service_initialled = false; + +static bool g_mixo_sensor_exist = false; + +static unsigned long g_app_queue= 0xFFFFFFFF; + +static bool mixo_service_timer_running = false; //ots定时器是否运行标志 + +static osTimerId_t g_mixo_service_timer = NULL; + +void do_mixo_service_check_msg(int cmd); + +static void mixo_service_timer_callback(void) +{ + do_mixo_service_check_msg(MIXO_SERVICE_CMD_TIMER_CHECK); +} + +void mixo_service_timer_start(void) +{ + if(mixo_service_timer_running == false && g_mixo_service_timer) + { + mixo_resume(); + osTimerStart(g_mixo_service_timer,MIXO_SERVICE_TIMER_CHECK_MS); + mixo_service_timer_running = true; + } +} + +void mixo_service_timer_stop(void) +{ + if(mixo_service_timer_running == true && g_mixo_service_timer) + { + mixo_suspend(); + mixo_clean_result(); + osTimerStop(g_mixo_service_timer); + mixo_service_timer_running = false; + } +} + +void mixo_start(void) +{ + do_mixo_service_check_msg(MIXO_SERVICE_CMD_START_CHECK); +} + +void mixo_stop(void) +{ + do_mixo_service_check_msg(MIXO_SERVICE_CMD_STOP_CHECK); +} + + +void do_mixo_service_check_msg(int cmd) +{ + int ret; + if (g_mixo_sensor_exist == false) + return ; + common_notify_mail_t mail = {0}; + mail.comm.app = cmd; + ret = osal_msg_queue_write_copy(g_app_queue, (void *)&mail, + sizeof(common_notify_mail_t), 0); + if (ret != OSAL_SUCCESS) { + PRINT("Error mixo Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret); + } + +} + +static void mixo_service_check_task(void const *arg) +{ + unused(arg); + int32_t ret; + common_notify_mail_t mail; + uint32_t msgsize = (uint32_t)sizeof(common_notify_mail_t); + while (1) { + ret = osal_msg_queue_read_copy(g_app_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) { + continue; + } + + if (mail.comm.app == MIXO_SERVICE_CMD_TIMER_CHECK) { + mixo_check(); + }else if (mail.comm.app == MIXO_SERVICE_CMD_START_CHECK){ + mixo_service_timer_start(); + }else if (mail.comm.app == MIXO_SERVICE_CMD_STOP_CHECK){ + mixo_service_timer_stop(); + } + + + } +} +void create_mixo_queue(void) +{ + + if (osal_msg_queue_create("mixo_service_queue", APP_BOARD_MSG_COUNT, &g_app_queue, + 0, sizeof(common_notify_mail_t)) != ERRCODE_SUCC) { + PRINT("[mixo][service] app create mail fail\n"); + } +} + +#define MIXO_BOARD_TASK_SIZE 0x1000 +errcode_t uapi_mixo_service_init(void) +{ + PRINT("uapi_mixo_service_init !\r\n"); + + if(mixo_init() != ERRCODE_SUCC) + { + //TODO 设置光电编码器检测是否存在标识 + PRINT("mixo not found!\r\n"); + return ERRCODE_FAIL; + } + g_mixo_sensor_exist = true; + + app_task_definition_t taskcfg={0}; + taskcfg.create_queue_handle = create_mixo_queue; + taskcfg.attr.name="mixo_service"; + taskcfg.attr.priority = osPriorityBelowNormal5; + taskcfg.attr.stack_size = MIXO_BOARD_TASK_SIZE; + taskcfg.func = mixo_service_check_task; + taskcfg.use_mem = USE_EXTEND_MEM; + + errcode_t ret=uapi_create_osThread_custom(&taskcfg); + if(ret != ERRCODE_SUCC) + { + PRINT("create mixo_service failed %d!\r\n",ret); + return ERRCODE_FAIL; + } + + mixo_init(); + + g_mixo_service_timer = osTimerNew((osTimerFunc_t)mixo_service_timer_callback, osTimerPeriodic, NULL, NULL); + + mixo_start(); + + return ERRCODE_SUCC; +} + diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_service.h b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_service.h new file mode 100644 index 000000000..60ded8314 --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_service.h @@ -0,0 +1,45 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-23 15:12:01 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-05-14 16:29:38 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/mixo/service/mixo_service.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Test adc header \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-08-16, Create file. \n + */ + +#ifndef MIXO_SERVICE_H__ +#define MIXO_SERVICE_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" +#include "platform_core.h" + +#define MIXO_SERVICE_CMD_START_CHECK 0x12 +#define MIXO_SERVICE_CMD_STOP_CHECK 0x13 + +errcode_t uapi_mixo_service_init(void); +void uapi_mixo_service_deinit(void); +void do_mixo_service_check_msg(int cmd); +void mixo_start(void); +void mixo_stop(void); +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c b/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c index 6d1e53190..e20f8679d 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c @@ -24,6 +24,11 @@ #ifdef ROTARYENCODER_U8 #include "crown_hal.h" #endif + +#ifdef ROTARYENCODER_MIXO +#include "mixo_hal.h" +#endif + // #if defined(TPTYPE_TMA525B) // #include "tma525b_drv1.h" // #include "tma525b_ctrl.h" @@ -431,6 +436,9 @@ uint32_t re_init(void) #elif defined ROTARYENCODER_U8 g_encoder_drv.private_data = rotary_encoder_get_crown_peri_attr(); g_encoder_drv.encoder_api = rotary_encoder_get_crown_api(); +#elif defined ROTARYENCODER_MIXO + g_encoder_drv.private_data = rotary_encoder_get_mixo_peri_attr(); + g_encoder_drv.encoder_api = rotary_encoder_get_mixo_api(); #endif g_encoder_drv.ops = &g_re_status_ops; redd = rotary_encoder_get_driver_data(); @@ -475,6 +483,8 @@ void rotary_encoder_suspend(void) encoder_ptr = rotary_encoder_get_hx3508_api(); #elif defined ROTARYENCODER_U8 encoder_ptr = rotary_encoder_get_crown_api(); +#elif defined ROTARYENCODER_MIXO + encoder_ptr = rotary_encoder_get_mixo_api(); #endif if(encoder_ptr == NULL) return; @@ -492,6 +502,8 @@ void rotary_encoder_resume(void) encoder_ptr = (encoder_peripheral_api*)rotary_encoder_get_hx3508_api(); #elif defined ROTARYENCODER_U8 encoder_ptr = (encoder_peripheral_api*)rotary_encoder_get_crown_api(); +#elif defined ROTARYENCODER_MIXO + encoder_ptr = (encoder_peripheral_api*)rotary_encoder_get_mixo_api(); #endif if(encoder_ptr == NULL) return; diff --git a/code/sdk/zhihui/services/battery/service/battery_driver.cpp b/code/sdk/zhihui/services/battery/service/battery_driver.cpp index 0ee9844da..8209abde4 100644 --- a/code/sdk/zhihui/services/battery/service/battery_driver.cpp +++ b/code/sdk/zhihui/services/battery/service/battery_driver.cpp @@ -231,29 +231,6 @@ float battery_ntc_map[][2]={ float battery_percent_map[][2]={ -#ifdef BOARD_U8 - {3.8, 100}, - {3.782, 95}, - {3.764, 90}, - {3.746, 85}, - {3.728, 80}, - {3.71, 75}, - {3.692, 70}, - {3.674, 65}, - {3.656, 60}, - {3.638, 55}, - {3.62, 50}, - {3.602, 45}, - {3.584, 40}, - {3.566, 35}, - {3.548, 30}, - {3.53, 25}, - {3.512, 20}, - {3.494, 15}, - {3.476, 10}, - {3.405, 5}, - {3.3, 0} -#else {4.3,100}, {4.264,95}, {4.228,90}, @@ -275,7 +252,6 @@ float battery_percent_map[][2]={ {3.652,10}, {3.41,5}, {3.3,0} -#endif }; #ifdef BOARD_U8 @@ -818,10 +794,12 @@ void enable_02c(void) uint8_t get_02c_value(void) { +#if defined(BOARD_FD230) || defined(BOARD_W9) if (GPIO_LEVEL_LOW == uapi_gpio_get_output_val(GPIO_PIN_ENABLE_CHARGE_0_2C)) return 0; else return 1; +#endif } void disable_02c(void) { diff --git a/code/sdk/zhihui/services/battery/service/battery_service.cpp b/code/sdk/zhihui/services/battery/service/battery_service.cpp index b7567ff32..eda3da9f5 100644 --- a/code/sdk/zhihui/services/battery/service/battery_service.cpp +++ b/code/sdk/zhihui/services/battery/service/battery_service.cpp @@ -45,6 +45,10 @@ extern "C" { #include "cywee_service.h" +#ifdef ENABLE_HP4570 +#include "hp4570.h" +#endif + #define BAT_FILE_COUNT 180 #define BAT_FILE_PATH "user/log/bat_data.bin" @@ -274,10 +278,13 @@ void send_battery_svr_cmd_msg(uint8_t cmd) */ uint8_t get_charge_stat(void) { - if(uapi_get_charger_plug_status()) - return 1; - else - return 0; + uint8_t stat = 0; +#ifdef ENABLE_HP4570 + stat = !hp45xxx_read_chrg_stat_not_chrg(); +#else + stat = uapi_get_charger_plug_status(); +#endif + return stat; } static uint8_t bat_temp_cnt = 0; @@ -685,6 +692,16 @@ void uapi_battery_create_queue(void) #define BATTERY_TASK_SIZE 0x1C00 errcode_t uapi_battery_init(void) { + +#ifdef ENABLE_HP4570 +#ifdef BOARD_L22 + custom_i2c_init(I2C_BUS_0); +#elif defined BOARD_U8 + custom_i2c_init(I2C_BUS_3); +#endif + hp45xxx_init(HP4570C9); +#endif + battery_check_voltage(); battery_percent_init(0); //先读历史电量 diff --git a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c index 14a98d4c8..6f714c6a5 100644 --- a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c +++ b/code/sdk/zhihui/services/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-02-20 18:34:13 + * @LastEditTime: 2025-05-12 18:56:38 * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c * @Description: * @@ -58,7 +58,7 @@ #include "lqbp_service.h" #include "lqbp002ta.h" #endif -#ifdef ENABLE_HP4507 +#ifdef ENABLE_HP4570 #include "hp4570.h" #endif #ifdef PPG_VC9202 @@ -74,6 +74,11 @@ static gps_data_t send_gps_data = {0}; #include "bp_ble_service.h" #endif +#ifdef ENABLE_GYRO +#include "gyro_service.h" +#include "gyro_hal.h" +#endif + #pragma pack(1) typedef struct factorytest_cmd_header_t { @@ -403,7 +408,7 @@ void aging_task(void) } uapi_get_timestampe_ss(¤t_time); send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_SINGLE_CHECK_MODE_TEST); - LOS_Msleep(200); + LOS_Msleep(1000); #ifdef PPG_HX3695 FT_RESULTS_t ft_result = hx3695_factroy_test(SINGLE_CHECK_TEST); #endif @@ -1480,7 +1485,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint #elif defined PPG_VC9202 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_TEST); #endif - LOS_Msleep(500); + LOS_Msleep(1000); uint8_t databuf[4] = {0}; #ifdef PPG_HX3695 FT_RESULTS_t ft_result = hx3695_factroy_test(SINGLE_CHECK_TEST); @@ -1490,6 +1495,12 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint databuf[3] = (uint8_t)((ft_result.gr_data_final & 0x000000FF) >> 0); #elif defined PPG_VC9202 uint32_t ppg_data = vc9202_get_hr_ppg_data(); + if(!ppg_data) + { + LOS_Msleep(1000); + ppg_data = vc9202_get_hr_ppg_data(); + } + PRINT("ppg_data : %d \n",ppg_data); databuf[0] = (uint8_t)((ppg_data & 0xFF000000) >> 24); databuf[1] = (uint8_t)((ppg_data & 0x00FF0000) >> 16); @@ -1515,7 +1526,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint #elif defined PPG_VC9202 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST); #endif - LOS_Msleep(500); + LOS_Msleep(1000); uint8_t databuf[8] = {0}; #ifdef PPG_HX3695 FT_RESULTS_t ft_result = hx3695_factroy_test(SINGLE_CHECK_TEST); @@ -1525,9 +1536,16 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint databuf[3] = (uint8_t)((ft_result.red_data_final & 0x000000FF) >> 0); #elif defined PPG_VC9202 uint32_t red_data = 0; - uint32_t ir_data = 9; + uint32_t ir_data = 0; vc9202_get_spo2_ppg_data(&ir_data,&red_data); PRINT("ir_data : %d ,red_data : %d \n",ir_data,red_data); + + if(!ir_data && !red_data) + { + LOS_Msleep(1000); + vc9202_get_spo2_ppg_data(&ir_data,&red_data); + } + databuf[0] = (uint8_t)((ir_data & 0xFF000000) >> 24); databuf[1] = (uint8_t)((ir_data & 0x00FF0000) >> 16); databuf[2] = (uint8_t)((ir_data & 0x0000FF00) >> 8); @@ -1552,7 +1570,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //灰卡测试 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_GRAYCARD_TEST); - LOS_Msleep(500); + LOS_Msleep(1000); #ifdef PPG_HX3695 uint8_t databuf[12] = {0}; FT_RESULTS_t ft_result = hx3695_factroy_test(GRAY_CARD_TEST); @@ -1610,7 +1628,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //漏光测试 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_LEAKLIGHT_TEST); - LOS_Msleep(500); + LOS_Msleep(1000); uint8_t databuf[12] = {0}; #ifdef PPG_HX3695 FT_RESULTS_t ft_result = hx3695_factroy_test(LEAK_LIGHT_TEST); @@ -1635,6 +1653,13 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint uint32_t aps_val = 9; vc9202_get_leaklight_data(&led_cur,&apre_val,&aps_val); PRINT("led_cur : %d ,apre_val : %d ,aps_val : %d \n",led_cur,apre_val,aps_val); + + if(!led_cur && !apre_val && !aps_val) + { + LOS_Msleep(1000); + vc9202_get_leaklight_data(&led_cur,&apre_val,&aps_val); + } + databuf[0] = (uint8_t)((led_cur & 0xFF000000) >> 24); databuf[1] = (uint8_t)((led_cur & 0x00FF0000) >> 16); databuf[2] = (uint8_t)((led_cur & 0x0000FF00) >> 8); @@ -1709,7 +1734,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //获取充电IC ID uint8_t chip_id = 0; -#ifdef ENABLE_HP4507 +#ifdef ENABLE_HP4570 chip_id = hp4507_get_id(); PRINT("chip id = 0x%x\n",chip_id); #endif @@ -1779,13 +1804,17 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //切换vbus供电测电流 uint8_t send_data = 0x00; -#ifdef ENABLE_HP4507 - hp45xxx_init(HP4570C9); +#ifdef ENABLE_HP4570 + // hp45xxx_init(HP4570C9); hp45xxx_set_batfet_dis(true); - // hp45xxx_set_ceb_en(true); + LOS_Mdelay(50); + hp45xxx_set_ceb_en(false); + LOS_Mdelay(50); hp45xxx_set_hiz_en(false); LOS_Mdelay(50); - if (hp45xxx_read_status_vbus_pg()) + + send_data = hp45xxx_read_status_vbus_pg(); + if (send_data) PRINT("VBUS is in Power Good state\n"); else PRINT("VBUS is not in Power Good state\n"); @@ -1796,6 +1825,31 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint 0x06, &send_data, 1); + } else if(testitem == 0x07) + { + //切换电池供电 + uint8_t send_data = 0x00; +#ifdef ENABLE_HP4570 + hp45xxx_set_batfet_dis(false); + LOS_Mdelay(50); + hp45xxx_set_hiz_en(true); + LOS_Mdelay(50); + hp45xxx_set_ceb_en(true); + LOS_Mdelay(50); + send_data = hp45xxx_read_status_vbus_pg(); + + if (send_data) + PRINT("VBUS is in Power Good state\n"); + else + PRINT("VBUS is not in Power Good state\n"); + + send_data = !send_data; +#endif + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, + 0x07, + &send_data, + 1); } @@ -2371,6 +2425,40 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint break; + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_GYRO: + + if (testitem == 0x01) + { + uint8_t send_data = 0x00; +#ifdef ENABLE_GYRO + send_data = gyro_get_chip_id(); + PRINT("send_data : 0x%x \n",send_data); +#endif + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_GYRO, + 0x01, + &send_data, + 1); + } else if(testitem == 0x02) + { +#ifdef ENABLE_GYRO + uint8_t databuf[6]; + get_gsensor_single(databuf); + for(int i = 0; i < 5 ; i++) + { + get_gyro_single(databuf); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_GYRO, + 0x02, + databuf, + 6); + LOS_Msleep(1000); + } +#endif + } + break; + default: printf(""); break; diff --git a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h index b2cbec6f1..5e6f31e32 100644 --- a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h +++ b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h @@ -97,6 +97,8 @@ extern "C" { #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LQBP 0x1C //软件测试 子模式ID GPS #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_GPS 0x1D +//软件测试 子模式ID 陀螺仪 +#define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_GYRO 0x1E //软件测试 子模式ID 通讯录 #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CONTACTS 0x30 diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index 91d30d3e1..93c4bffb2 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -103,6 +103,10 @@ void system_init_uart(void){} #include "bleEvent.h" #endif +#ifdef ENABLE_GYRO +#include "gyro_hal.h" +#endif + errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg) { if (task_cfg==NULL) @@ -1471,7 +1475,7 @@ int uapi_callVolumeGet(void) void power_on_cat1(void) { - #ifdef FD230 + #if defined(FD230) && !defined(BOARD_W9) uapi_cat1_power_on(1); uapi_cat1_reset(0); #else @@ -1522,6 +1526,11 @@ void uapi_set4GCapability(bool isopen) // uapi_custom_set_uart_rx_enable_flag(false); #ifdef SUPPORT_TCPIP + if(tcp_thread_id == NULL) + { + PRINT("tcp_thread_id is NULL\n"); + return; + } tcp_thread_id = tcp_get_thread_id(); ret = uapi_resume_thread(tcp_thread_id); if(ret != ERRCODE_SUCC) @@ -1547,6 +1556,11 @@ void uapi_set4GCapability(bool isopen) } #ifdef SUPPORT_TCPIP + if(tcp_thread_id == NULL) + { + PRINT("tcp_thread_id is NULL\n"); + return; + } tcp_thread_id = tcp_get_thread_id(); ret = uapi_suspend_thread(tcp_thread_id); if(ret != ERRCODE_SUCC) @@ -2066,6 +2080,34 @@ void get_gsensor_single(uint8_t *databuf) { PRINT("GSENSOR: %02X %02X %02X %02X %02X %02X\r\n", databuf[0], databuf[1], databuf[2], databuf[3], databuf[4], databuf[5]); } +void get_gyro_single(uint8_t *databuf) +{ + + if(databuf == NULL) + return; + +#ifdef ENABLE_GYRO + gyro_data_t data = gyro_get_data(); + + int16_t x, y, z; + x = data.x * 2048; + y = data.y * 2048; + z = data.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); + + PRINT("x : %.2f, y : %.2f, z : %.2f \r\n",data.x,data.y,data.z); + PRINT("x : %d, y : %d, z : %d \r\n", x, y, z); + PRINT("gyro: %02X %02X %02X %02X %02X %02X\r\n", databuf[0], databuf[1], databuf[2], databuf[3], databuf[4], databuf[5]); +#endif +} + void gsensor_get_single_data(gsenson_t *t) { get_gsonsen_xyz(t); @@ -2512,7 +2554,8 @@ void custom_i2c_reset(uint8_t i2cbus, uint16_t i2c_clock) errcode_t custom_i2c_init(uint8_t bus_index) { - errcode_t result; + if(i2c_installed == 1) + return ERRCODE_SUCC; // #ifdef CONFIG_I2C_SUPPORT_DMA // #if CONFIG_I2C_SUPPORT_DMA @@ -2521,18 +2564,17 @@ errcode_t custom_i2c_init(uint8_t bus_index) // #warning CONFIG_I2C_SUPPORT_DMA = 0 // #endif // #endif - // if(i2c_installed == 0) - // { - result = uapi_i2c_master_init(bus_index, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ + + errcode_t result = uapi_i2c_master_init(bus_index, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ if (result != ERRCODE_SUCC) { PRINT("cywee i2c init fail! ret=0x%x\n", result); return ERRCODE_FAIL; } - // i2c_installed = 1; + i2c_installed = 1; return ERRCODE_SUCC; - // } + // else // return ERRCODE_FAIL; } diff --git a/code/sdk/zhihui/utils/custom_utils.h b/code/sdk/zhihui/utils/custom_utils.h index ed203beca..1ee8c8cb4 100644 --- a/code/sdk/zhihui/utils/custom_utils.h +++ b/code/sdk/zhihui/utils/custom_utils.h @@ -454,6 +454,8 @@ uint8_t get_crc_from_lrc(uint8_t lrcValue); uint8_t calculate_lrc(uint8_t *data,uint16_t len,uint8_t _lrcValue); +void get_gyro_single(uint8_t *databuf); + #include "custom_utilscpp.h"