From cb5aede3d3d0b6e120f801badb81a7f196aa89a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Thu, 9 Jan 2025 13:37:24 +0000 Subject: [PATCH] Merge #1616 into sdk602patch1126 from refs/changes/1616/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit w9添加光电编码器,陀螺仪驱动。u8添加蓝牙产测 * refs/changes/1616/head: (1 commits squashed) - w9添加光电编码器,陀螺仪驱动。u8添加蓝牙产测 Signed-off-by: aliyun6865282430 <1624952103@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1616 --- .../brandy/brandy_standard/input_app.h | 4 +- .../brandy/brandy_standard/service_init.c | 16 + .../brandy/brandy_standard/thread_pri_init.c | 49 +- .../config/target_config/brandy/config.py | 19 +- .../boards/brandy_evb/board_config/board_w9.h | 24 +- .../touch/cst86xx_touch/cst86xx_touch1.c | 5 + .../touch/cst86xx_touch/cst86xx_touch1.h | 3 + .../UI/producttest/src/testPresenter.cpp | 58 +- code/sdk/zhihui/UI/producttest/src/testbt.cpp | 2 + .../zhihui/UI/producttest/src/testbutton.cpp | 55 +- code/sdk/zhihui/drivers/CMakeLists.txt | 1 + .../drivers/barometer/driver/lqbp002ta.c | 44 +- .../drivers/barometer/driver/lqbp002ta.h | 7 +- .../sdk/zhihui/drivers/charge/hp4570/hp4570.c | 10 +- .../sdk/zhihui/drivers/charge/hp4570/hp4570.h | 4 + code/sdk/zhihui/drivers/gyro/CMakeLists.txt | 44 + .../zhihui/drivers/gyro/service/gyro_at_cmd.c | 76 + .../zhihui/drivers/gyro/service/gyro_at_cmd.h | 40 + .../drivers/gyro/service/gyro_service.c | 173 + .../drivers/gyro/service/gyro_service.h | 37 + code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c | 3054 +++++++++++++++++ code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h | 695 ++++ .../zhihui/drivers/mag/mmc5603/mmc5603_main.c | 8 +- .../zhihui/drivers/ppg/service/ppg_at_cmd.cpp | 2 + .../drivers/ppg/service/ppg_service.cpp | 8 +- .../zhihui/drivers/ppg/service/ppg_service.h | 3 +- .../drivers/ppg/vc9202/inc/vc9202_user.h | 7 +- .../drivers/ppg/vc9202/src/vc9202_driver.c | 36 +- .../drivers/ppg/vc9202/src/vc9202_hal.c | 4 +- .../drivers/ppg/vc9202/src/vc9202_user.c | 123 +- .../drivers/rotary_encoder/CMakeLists.txt | 15 + .../drivers/rotary_encoder/crown/crown.c | 51 +- .../drivers/rotary_encoder/crown/crown.h | 2 +- .../drivers/rotary_encoder/crown/crown_hal.c | 138 + .../drivers/rotary_encoder/crown/crown_hal.h | 40 + .../drivers/rotary_encoder/hx3507/hx3507.c | 4 +- .../drivers/rotary_encoder/hx3507/hx3507.h | 12 +- .../rotary_encoder/hx3507/hx3507_hal.c | 6 +- .../drivers/rotary_encoder/mixo/mixo_at_cmd.c | 103 + .../drivers/rotary_encoder/mixo/mixo_at_cmd.h | 40 + .../rotary_encoder/mixo/mixo_ots_access.c | 62 + .../rotary_encoder/mixo/mixo_ots_access.h | 79 + .../rotary_encoder/mixo/mixo_ots_driver.c | 285 ++ .../rotary_encoder/mixo/mixo_ots_driver.h | 29 + .../rotary_encoder/rotary_encoder_drv.c | 15 + .../drivers/slip/cat1Service/cat1_ctl.cpp | 5 +- .../factorytest_protocol.c | 312 +- .../factorytest_protocol.h | 2 + code/sdk/zhihui/utils/custom_cmd_service.c | 10 +- code/sdk/zhihui/utils/custom_utils.c | 79 +- code/sdk/zhihui/utils/custom_utils.h | 9 +- code/sdk/zhihui/utils/custom_utils_at_cmd.c | 4 +- 52 files changed, 5659 insertions(+), 254 deletions(-) create mode 100644 code/sdk/zhihui/drivers/gyro/CMakeLists.txt create mode 100644 code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c create mode 100644 code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.h create mode 100644 code/sdk/zhihui/drivers/gyro/service/gyro_service.c create mode 100644 code/sdk/zhihui/drivers/gyro/service/gyro_service.h create mode 100644 code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c create mode 100644 code/sdk/zhihui/drivers/gyro/sh5001/sh5001.h create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.c create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.h create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.c create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.h create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.c create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.h create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c create mode 100644 code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.h diff --git a/code/sdk/application/brandy/brandy_standard/input_app.h b/code/sdk/application/brandy/brandy_standard/input_app.h index 0c8b1a739..bb7e3c541 100644 --- a/code/sdk/application/brandy/brandy_standard/input_app.h +++ b/code/sdk/application/brandy/brandy_standard/input_app.h @@ -110,7 +110,6 @@ typedef enum { BUTTON1_LONGPRESS_9S_OVER, BUTTON1_INVALID, -#ifdef BOARD_U8 BUTTON2_START, BUTTON2_PRESS, BUTTON2_CLICKUP, @@ -134,8 +133,7 @@ typedef enum { BUTTON2_LONGPRESS_8S_OVER, BUTTON2_LONGPRESS_9S_OVER, BUTTON2_INVALID, -#endif - + BUTTON_BUTT } event_button_t; diff --git a/code/sdk/application/brandy/brandy_standard/service_init.c b/code/sdk/application/brandy/brandy_standard/service_init.c index a30b1a8b9..dd608c90c 100644 --- a/code/sdk/application/brandy/brandy_standard/service_init.c +++ b/code/sdk/application/brandy/brandy_standard/service_init.c @@ -89,6 +89,12 @@ #ifdef SUPPORT_AT_CROWN #include "crown_at_cmd.h" #endif +#ifdef SUPPORT_AT_MIXO +#include "mixo_at_cmd.h" +#endif +#ifdef SUPPORT_AT_GYRO +#include "gyro_at_cmd.h" +#endif static void register_at_service(void) { #ifdef SUPPORT_AT_GRAPHIC @@ -202,6 +208,16 @@ static void register_at_service(void) at_cmd_table_t *crown_table = get_crown_cmd_table(&crown_cmd_count); at_cmd_add_moudle(crown_table, crown_cmd_count); #endif +#ifdef SUPPORT_AT_MIXO + uint32_t mixo_cmd_count; + at_cmd_table_t *mixo_table = get_mixo_cmd_table(&mixo_cmd_count); + at_cmd_add_moudle(mixo_table, mixo_cmd_count); +#endif +#ifdef SUPPORT_AT_GYRO + uint32_t gyro_cmd_count; + at_cmd_table_t *gyro_table = get_gyro_cmd_table(&gyro_cmd_count); + at_cmd_add_moudle(gyro_table, gyro_cmd_count); +#endif } #ifdef CONFIG_OTA_UPDATE_SUPPORT 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 d42928649..5304530e9 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -500,28 +500,33 @@ uapi_pm_remove_sleep_veto(PM_ID_DEBUG); #endif #ifdef ENABLE_CUSTOM_I2C - errcode_t result = custom_i2c_init(I2C_BUS_2); - if(result != SUCC) - PRINT("custom_iic_init failed !!! \r\n"); - else - { - PRINT("custom_iic_init succed !!! \r\n"); - #ifdef MAG_MMC5603 - uapi_mag_service_init(); - #endif - - #ifdef SUPPORT_PPG_SERVICE - uapi_ppg_service_init(); - #endif - - #ifdef ENABLE_CYWEE - uapi_cywee_service_init(); - #endif - - #ifdef ENABLE_LQBP002TA - uapi_lqbp_service_init(); - #endif - } + +#ifdef ENABLE_HP4507 +#ifdef BOARD_L22 +#define HP4570_I2C_BUS I2C_BUS_0 +#elif defined BOARD_U8 +#define HP4570_I2C_BUS I2C_BUS_3 +#endif + custom_i2c_init(HP4570_I2C_BUS); +#endif + custom_i2c_init(I2C_BUS_2); + +#ifdef MAG_MMC5603 + uapi_mag_service_init(); +#endif + +#ifdef SUPPORT_PPG_SERVICE + uapi_ppg_service_init(); +#endif + +#ifdef ENABLE_CYWEE + uapi_cywee_service_init(); +#endif + +#ifdef ENABLE_LQBP002TA + uapi_lqbp_service_init(); +#endif + #endif /*启动蓝牙ble服务,cywee有重置 mac地址的操作,会需要把 蓝牙服务开启放在cywee服务之后*/ diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 556613d0f..bafc22cf3 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -474,7 +474,6 @@ target = { 'PPG_VC9202', #'ROTARYENCODER_HX3507', 'ROTARYENCODER_U8', - 'FUNC_KEY2', 'NANDFLASH_DS35X', 'BLE_INSTRUCT', 'FACTORYTEST_SERVICE', @@ -572,7 +571,7 @@ target = { 'SUPPORT_HID_SERVICE', 'SUPPORT_BAIDU_MAP', 'CFG_FLASH_SIZE=8', - # 'SUPPORT_BLE_SERVICE', + 'SUPPORT_BLE_SERVICE', # 'FD230', #"MEM_CHECK", #'ENABLE_WEBSOCKET', @@ -584,7 +583,9 @@ target = { 'TPTYPE_CST86XX', 'TEST_4G_UI', 'TEST_GPS_UI', - 'NANDFLASH_F35UQA' + 'NANDFLASH_F35UQA', + #'BLE_INSTRUCT', + 'FACTORYTEST_SERVICE', ], 'ram_component': [ #'baidumapsdk', @@ -599,7 +600,7 @@ target = { "slip", "cat1_service", "audio_manager", - # "CustomUIcomponentTool", + #"CustomUIcomponentTool", "custom_utils", "custom_utilscpp", "custom_config", @@ -610,11 +611,11 @@ target = { "gnss_sample", # "acc_sensor", "batterry_service", - # "bleservice", - # "ppgBleService", - # "blemoder", - # "factorytest_service", - # "hid_service", + "bleservice", + "ppgBleService", + #"blemoder", + "factorytest_service", + "hid_service", "producttest", "cywee" ], 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 261352774..73b7d58e7 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 @@ -76,8 +76,13 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_EMMC, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_HGPIO15 emmc clk #endif { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO0 NC +#ifdef BOARD_W9 + { HAL_PIO_FUNC_I2C2_M3, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO1 I2C2 SCL Sensor 6è½´ 指南针 心率 + { HAL_PIO_FUNC_I2C2_M3, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO2 I2C2 SDA Sensor +#else { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO1 NC { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO2 NC +#endif { HAL_PIO_FUNC_SPI0, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO3 NC // #if (defined BRANDY_PRODUCT_EVB4) @@ -97,8 +102,13 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_I2C0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO12 I2C0 SDA { HAL_PIO_FUNC_I2C1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO13 I2C1 SCL touch i2c { HAL_PIO_FUNC_I2C1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO14 I2C1 SDA - { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO15 I2C2 SCL Sensor 6è½´ 指南针 心率 - { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO16 I2C2 SDA Sensor +#ifdef BOARD_W9 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO15 I2C2 SCL Sensor 6è½´ 指南针 心率 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_MGPIO16 I2C2 SDA Sensor +#else + { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO15 I2C2 SCL Sensor 6è½´ 指南针 心率 + { HAL_PIO_FUNC_I2C2_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_MGPIO16 I2C2 SDA Sensor +#endif { HAL_PIO_FUNC_I2C3_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO17 i2c3 SCL smart pa\ 预留马达控制 \安全芯片 { HAL_PIO_FUNC_I2C3_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO18 I2C3 SDA { HAL_PIO_FUNC_UART1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_MGPIO19 uart1 tx @@ -199,7 +209,12 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R5 touch int { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R6 PRG_INT 心率中断 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R7 GYRO_INT2 +#ifdef ENABLE_GYRO + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R8 GYRO_INT1 +#else { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R8 GYRO_INT1 +#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R9 BAT_CHARGE_OFF 关掉充电 温度高的时候 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R10 Key2 ///////////////////HAL_PIO_IE_ENBALE input enable @@ -296,9 +311,12 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { // { S_AGPIO_L31, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, cat1_ring_isr_callback}, #endif +#ifdef ENABLE_GYRO + { S_AGPIO_R8, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL }, +#else /**S_AGPIO_L32 GPO gps reset*/ // { S_AGPIO_L32, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, - +#endif }; /** * @} diff --git a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c index d856beb59..9a0f08480 100644 --- a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c +++ b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.c @@ -402,6 +402,11 @@ ext_errno cst86xx_deinit(void) return EXT_ERR_SUCCESS; } +void cst86xx_get_chip_id(uint16_t *chip_id) +{ + *chip_id = g_cst86xx_drv.chip_id; +} + #ifdef __cplusplus } #endif diff --git a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.h b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.h index 40f0a10ac..e2f5c200b 100644 --- a/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.h +++ b/code/sdk/drivers/drivers/driver/touch/cst86xx_touch/cst86xx_touch1.h @@ -348,6 +348,9 @@ ext_errno cst86xx_get_power_mode(uint32_t *power_mode); ext_errno cst86xx_resume(void); ext_errno cst86xx_irq_callback(uint8_t *data_buf, uint8_t data_len); ext_errno cst86xx_host_init_sample(void); + +void cst86xx_get_chip_id(uint16_t *chip_id); + #ifdef __cplusplus } #endif diff --git a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp index 58f623ac8..b5abaf2fb 100644 --- a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp @@ -375,25 +375,38 @@ namespace OHOS if(testbuttonView::GetInstance()) { if (keyID == 41 ) - { + { + if(keystate) + testbuttonView::GetInstance()-> Changbutton(0,true); + else + testbuttonView::GetInstance()-> Changbutton(0,false); + + // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + if (keyID == 0) + { if(keystate) - testbuttonView::GetInstance()-> Changbutton(0,true); - else - testbuttonView::GetInstance()-> Changbutton(0,false); - - // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - } - if (keyID == 0) - { - if(keystate) - testbuttonView::GetInstance()-> Changbutton(1,true); - else - testbuttonView::GetInstance()-> Changbutton(1,false); - - // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - } + testbuttonView::GetInstance()-> Changbutton(1,true); + else + testbuttonView::GetInstance()-> Changbutton(1,false); + + // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + +#ifdef BOARD_U8 + if (keyID == 2) + { + if(keystate) + testbuttonView::GetInstance()-> Changbutton(2,true); + else + testbuttonView::GetInstance()-> Changbutton(2,false); + + // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } +#endif } @@ -445,15 +458,18 @@ extern "C" void factorytest_enter_test_tp_view(void) { - testView::GetInstance()->ChangeView(TESTVIEW,TP); + if(testView::GetInstance()) + testView::GetInstance()->ChangeView(TESTVIEW,TP); + else + printf("xxxxxxxxxxxxxxxxxxxxx\r\n"); } void factorytest_enter_test_lcd_view(void) { if( testView::GetInstance()) - testView::GetInstance()->ChangeView(TESTVIEW,LCD); + testView::GetInstance()->ChangeView(TESTVIEW,LCD); else - printf("xxxxxxxxxxxxxxxxxxxxx\r\n"); + printf("xxxxxxxxxxxxxxxxxxxxx\r\n"); } void factorytest_enter_test_button_view(void) diff --git a/code/sdk/zhihui/UI/producttest/src/testbt.cpp b/code/sdk/zhihui/UI/producttest/src/testbt.cpp index 61fa663e7..327e91ac1 100644 --- a/code/sdk/zhihui/UI/producttest/src/testbt.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testbt.cpp @@ -13,7 +13,9 @@ #include "bts_br_gap.h" #include "bts_le_gap.h" +#ifdef SUPPORT_BLE_SERVICE #include "bleService.h" +#endif #include "BluetoothModel.h" #include "producttest/include/testView.h" diff --git a/code/sdk/zhihui/UI/producttest/src/testbutton.cpp b/code/sdk/zhihui/UI/producttest/src/testbutton.cpp index f6aae6542..a84ca8ee4 100644 --- a/code/sdk/zhihui/UI/producttest/src/testbutton.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testbutton.cpp @@ -149,9 +149,25 @@ namespace OHOS { button[1]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); button[1]->SetText("DOWN_KEY::\nraise"); + } + } +#ifdef BOARD_U8 + if(i==2) + { + + if(falg==true) + { + button[3]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); + button[3]->SetText("DOWN_KEY::\npress"); + } + else + { + button[3]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + button[3]->SetText("DOWN_KEY::\nraise"); } } +#endif RootView::GetInstance()->Invalidate(); @@ -234,8 +250,8 @@ namespace OHOS buttonconfig.label_x=40; buttonconfig.label_y=0; buttonconfig.Fontsize=25; - buttonconfig.ViewId="UP_KEY::"; - buttonconfig.str="UP_KEY"; + buttonconfig.ViewId="POWER_KEY:"; + buttonconfig.str="POWER_KEY:"; buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT; button[0]=SetTheButton_ext(buttonconfig); testBUTTONScrollView->Add(button[0]); @@ -247,12 +263,41 @@ namespace OHOS buttonconfig.label_x=40; buttonconfig.label_y=0; buttonconfig.Fontsize=25; - buttonconfig.ViewId="DOWN_KEY::"; - buttonconfig.str="DOWN_KEY"; + buttonconfig.ViewId="FUNC_KEY:"; + buttonconfig.str="FUNC_KEY:"; buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT; button[1]=SetTheButton_ext(buttonconfig); testBUTTONScrollView->Add(button[1]); +#ifdef BOARD_U8 + buttonconfig.x = 80; + buttonconfig.y = 300; + buttonconfig.w = 200; + buttonconfig.h = 80; + buttonconfig.label_x=40; + buttonconfig.label_y=0; + buttonconfig.Fontsize=25; + buttonconfig.ViewId="FUNC_KEY2:"; + buttonconfig.str="FUNC_KEY2:"; + buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT; + button[3]=SetTheButton_ext(buttonconfig); + testBUTTONScrollView->Add(button[3]); + + buttonconfig.x = 80; + buttonconfig.y = 600; + buttonconfig.w = 200; + buttonconfig.h = 80; + buttonconfig.label_x=40; + buttonconfig.label_y=0; + buttonconfig.Fontsize=25; + buttonconfig.ViewId="crown::"; + buttonconfig.str="crown::"; + buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT; + button[2]=SetTheButton_ext(buttonconfig); + testBUTTONScrollView->Add(button[2]); + +#else + buttonconfig.x = 80; buttonconfig.y = 400; buttonconfig.w = 200; @@ -265,6 +310,8 @@ namespace OHOS buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT; button[2]=SetTheButton_ext(buttonconfig); testBUTTONScrollView->Add(button[2]); +#endif + diff --git a/code/sdk/zhihui/drivers/CMakeLists.txt b/code/sdk/zhihui/drivers/CMakeLists.txt index db812e45f..5ce5f283c 100644 --- a/code/sdk/zhihui/drivers/CMakeLists.txt +++ b/code/sdk/zhihui/drivers/CMakeLists.txt @@ -19,3 +19,4 @@ add_subdirectory_if_exist(entest) add_subdirectory_if_exist(barometer) add_subdirectory_if_exist(charge) add_subdirectory_if_exist(charge/hp4570) +add_subdirectory_if_exist(gyro) diff --git a/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.c b/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.c index 930518b46..5833997db 100644 --- a/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.c +++ b/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.c @@ -7,6 +7,9 @@ static struct LQBP002TA_t LQBP002TA = {0}; static struct LQBP002TA_t *p_LQBP002TA = NULL; +static float Temp = 0.0f; +static float Pressure = 0.0f; + void LQBP002TA_write(uint8_t hwadr, uint8_t regadr, uint8_t val); uint8_t LQBP002TA_read(uint8_t hwadr, uint8_t regadr); void LQBP002TA_get_calib_param(void); @@ -434,7 +437,12 @@ float LQBP002TA_get_temperature(void) //printf("(float)p_LQBP002TA->calib_param.c0 * 0.5f : %f\n",(float)p_LQBP002TA->calib_param.c0 * 0.5f); //printf("((float)p_LQBP002TA->calib_param.c1) * fTsc : %f\n",((float)p_LQBP002TA->calib_param.c1) * fTsc); //printf("fTsc : %f\n",fTsc); - printf("fTCompensate : %f\n",fTCompensate); + // printf("fTCompensate : %f\n",fTCompensate); + + Temp = fTCompensate; + + // printf("Temp : %f\n",Temp); + return fTCompensate; } @@ -463,7 +471,12 @@ float LQBP002TA_get_pressure(void) else qua3 = fTsc * fPsc * (p_LQBP002TA->calib_param.c11 + fPsc * p_LQBP002TA->calib_param.c21); fPCompensate = p_LQBP002TA->calib_param.c00 + fPsc * qua2 + fTsc * p_LQBP002TA->calib_param.c01 + qua3; - printf("fPCompensate : %f\n",fPCompensate); + // printf("fPCompensate : %f\n",fPCompensate); + + Pressure = fPCompensate; + + // printf("Pressure : %f\n",Pressure); + return fPCompensate; } @@ -481,12 +494,10 @@ void lqbp002ta_start(void) void lqbp002ta_check(void) { - float fSplTemp = 0.0f; - float fSplPressure = 0.0f; LQBP002TA_get_raw_temp(); LQBP002TA_get_raw_pressure(); - fSplTemp = LQBP002TA_get_temperature(); - fSplPressure = LQBP002TA_get_pressure(); + LQBP002TA_get_temperature(); + LQBP002TA_get_pressure(); } @@ -494,3 +505,24 @@ void lqbp002ta_stop(void) { LQBP002TA_stop(); } + +float lqbp002ta_get_temp(void) +{ + float temp = Temp; + Temp = 0; + // printf("temp : %f\n",temp); + return temp; +} + +float lqbp002ta_get_pressure(void) +{ + float pressure = Pressure; + Pressure = 0; + // printf("pressure : %f\n",pressure); + return pressure; +} + +uint8_t lqbp002ta_get_id(void) +{ + return LQBP002TA_read(HW_ADR, 0x0D); +} \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.h b/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.h index 989afd32a..318b0ab02 100644 --- a/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.h +++ b/code/sdk/zhihui/drivers/barometer/driver/lqbp002ta.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-16 20:03:01 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-12-17 21:05:56 + * @LastEditTime: 2025-01-04 15:43:49 * @FilePath: /sdk615/code/sdk/drivers/peripheral/LQBP002TA/driver/lqbp002ta.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE; */ @@ -58,5 +58,10 @@ void lqbp002ta_check(void); void lqbp002ta_stop(void); uint8_t lqbp002ta_check_exist(void); +float lqbp002ta_get_temp(void); +float lqbp002ta_get_pressure(void); + +uint8_t lqbp002ta_get_id(void); + #endif diff --git a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c index 72baf7ec8..a4dd2ea9f 100644 --- a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c +++ b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.c @@ -70,8 +70,6 @@ bool hp45xxx_read_reg(uint8_t reg, uint8_t *value) // Initialize HP4570 chip bool hp45xxx_init(uint8_t chip_ver) { - custom_i2c_init(I2C_BUS_0); - switch (chip_ver){ case HP4570K: hp45xxx_i2c_addr = HP4570K_I2C_ADDR; @@ -766,4 +764,12 @@ bool hp45xxx_read_status_watchdog_int(void){ uint8_t value; hp45xxx_read_reg(HP45XXX_REG_INT0_STAT, &value); return (value & HP45XXX_WATCHDOG_INT_MASK) ? true : false; +} + +uint8_t hp4507_get_id(void) +{ + uint8_t id = 0; + hp45xxx_i2c_addr = HP45XXX_I2C_ADDR; + hp45xxx_read_reg(HP45XXX_REG_CHIP_VER, &id); + return id; } \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h index 57d9318c4..320625dca 100644 --- a/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h +++ b/code/sdk/zhihui/drivers/charge/hp4570/hp4570.h @@ -502,4 +502,8 @@ bool hp45xxx_read_status_pwrkey_wk(void);// PWRKEY 2S low time wake up from ship bool hp45xxx_read_status_vbus_wk(void);// VBUS plug in wake up from ship mode bool hp45xxx_read_status_watchdog_int(void);// Watch dog time expire IRQ + +uint8_t hp4507_get_id(void); + + #endif // HP4570_CHARGER_H \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/CMakeLists.txt b/code/sdk/zhihui/drivers/gyro/CMakeLists.txt new file mode 100644 index 000000000..161f02e88 --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/CMakeLists.txt @@ -0,0 +1,44 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. +#=============================================================================== +set(COMPONENT_NAME "gyro") + +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 +) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/sh5001 + ${CMAKE_CURRENT_SOURCE_DIR}/service +) +set(PUBLIC_DEFINES + SUPPORT_AT_GYRO + ENABLE_GYRO +) + +set(PRIVATE_HEADER +) + +set(PRIVATE_DEFINES +) + +# use this when you want to add ccflags like -include xxx +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -Wno-incompatible-function-pointer-types + -Wno-unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +build_component() \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c new file mode 100644 index 000000000..300f46f8d --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.c @@ -0,0 +1,76 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-16 20:49:09 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-01-04 17:01:37 + * @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" + +#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) +#define GYRO_MAX_ARGC 8 +#define GYRO_MAX_ARGV_LEN 64 + +#define GYRO_SUCCESS 0 +#define GYRO_FAILED (-1) + +static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen, + uint8_t argv[GYRO_MAX_ARGC][GYRO_MAX_ARGV_LEN], uint32_t* argc) +{ + uint32_t pos = 0; + *argc = 0; + + for (uint32_t i = 0; i < paraLen; i++) { + if ((para[i] == ' ' || para[i] == '\n') && pos != 0) { + argv[*argc][pos] = '\0'; + *argc += 1; + pos = 0; + if (*argc >= GYRO_MAX_ARGC) { + return GYRO_FAILED; + } + } else { + argv[*argc][pos] = para[i]; + pos++; + if (pos >= GYRO_MAX_ARGV_LEN) { + return GYRO_FAILED; + } + } + } + if (pos != 0) { + *argc += 1; + } + + return GYRO_SUCCESS; +} + +static uint32_t gyro_start_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + UNUSED(paraLen); + UNUSED(para); + // do_lqbp_service_check_msg(GYRO_SERVICE_CMD_START_CHECK); + SH5001_init(); + return ERRCODE_SUCC; +} +static uint32_t gyro_stop_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + UNUSED(paraLen); + UNUSED(para); + // do_lqbp_service_check_msg(GYRO_SERVICE_CMD_STOP_CHECK); + return ERRCODE_SUCC; +} +static const at_cmd_table_t g_gyro_cmd[] = { + { (char *)"AT^GYROTESTSTART", gyro_start_test, (char *)"1" }, + { (char *)"AT^GYROTESTSTOP", gyro_stop_test, (char *)"1" }, +}; + +at_cmd_table_t *get_gyro_cmd_table(uint32_t *cmd_count) +{ + *cmd_count = ARRAY_COUNT(g_gyro_cmd); + return (at_cmd_table_t *)g_gyro_cmd; +} diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.h b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.h new file mode 100644 index 000000000..e6bd34caa --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_at_cmd.h @@ -0,0 +1,40 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-16 20:49:19 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-01-04 16:47:46 + * @FilePath: /sdk615/code/sdk/drivers/peripheral/GYRO002TA/service/gyro_at_cmd.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 GYRO_AT_PROCESS_H +#define GYRO_AT_PROCESS_H + +#include +#include +#include "errcode.h" +#include "soc_osal.h" +#include "at_cmd_api.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +at_cmd_table_t *get_gyro_cmd_table(uint32_t *cmd_count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_service.c b/code/sdk/zhihui/drivers/gyro/service/gyro_service.c new file mode 100644 index 000000000..ef6bae79d --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_service.c @@ -0,0 +1,173 @@ + +#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 "sh5001.h" +#include "gyro_service.h" +// #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; + if (g_gyro_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 gyro Check MSG 0x%02X send failed! err=0x%x! \r\n",cmd, ret); + } + +} + +static void gyro_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 == 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); + }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); + } + + + } +} +void create_gyro_queue(void) +{ + + if (osal_msg_queue_create("gyro_service_queue", APP_BOARD_MSG_COUNT, &g_app_queue, + 0, sizeof(common_notify_mail_t)) != ERRCODE_SUCC) { + PRINT("[gyro][service] app create mail fail\n"); + } +} + +#define GYRO_BOARD_TASK_SIZE 0x1000 +errcode_t uapi_gyro_service_init(void) +{ + PRINT("uapi_gyro_service_init !\r\n"); + + if(!gyro_check_exist()) + { + //TODO 设置气压计检测是否存在标识 + PRINT("gyro not found!\r\n"); + return ERRCODE_FAIL; + } + g_gyro_sensor_exist = true; + + app_task_definition_t taskcfg={0}; + taskcfg.create_queue_handle = create_gyro_queue; + taskcfg.attr.name="gyro_service"; + taskcfg.attr.priority = osPriorityBelowNormal4; + taskcfg.attr.stack_size = GYRO_BOARD_TASK_SIZE; + taskcfg.func = gyro_service_check_task; + taskcfg.use_mem = USE_EXTEND_MEM; + + errcode_t ret=uapi_create_osThread_custom(&taskcfg); + if(ret != ERRCODE_SUCC) + { + PRINT("create gyro_service failed %d!\r\n",ret); + 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 diff --git a/code/sdk/zhihui/drivers/gyro/service/gyro_service.h b/code/sdk/zhihui/drivers/gyro/service/gyro_service.h new file mode 100644 index 000000000..27f9f1d4a --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/service/gyro_service.h @@ -0,0 +1,37 @@ +/** + * 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 GYRO_SERVICE_H__ +#define GYRO_SERVICE_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + + +#define GYRO_SERVICE_CMD_START_CHECK 0x12 +#define GYRO_SERVICE_CMD_STOP_CHECK 0x13 + +errcode_t uapi_gyro_service_init(void); +void uapi_gyro_service_deinit(void); +void do_gyro_service_check_msg(int cmd); + + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c new file mode 100644 index 000000000..77ff6b803 --- /dev/null +++ b/code/sdk/zhihui/drivers/gyro/sh5001/sh5001.c @@ -0,0 +1,3054 @@ +/****************************************************************** +* Senodia 6D IMU(Gyroscope+Accelerometer) SH5001 driver, By Senodia AE@20220505; +* +* +* 1. SH5001_init() : SH5001 initialize function +* 2. SH5001_GetImuData( ... ): SH5001 read gyro and accel data function +* 3. SH5001_GetTempData(): SH5001 read termperature function +* 4. delay_ms(x): delay x millisecond. +* 5. SH5001_initFIFO(): initialize FIFO function +* 6. SH5001_ReadFIFO(): read FIFO data +* +******************************************************************/ + +#include "sh5001.h" +#include "custom_utils.h" +#include "los_base.h" + +// 32-bit version number represented as major[31:16].minor[15:0] +#define SH5001_MAJOR 1 +#define SH5001_MINOR 01 +#define SH5001_REV 31 +#define MCU_VERSION_SH5001 ((SH5001_MAJOR<<16) | (SH5001_MINOR<<8) | SH5001_REV) + +#define SH5001_I2C_BUS I2C_BUS_2 + +/****************************************************************** +* Description: I2C or SPI bus interface functions and delay time function +* +* Parameters: +* devAddr: I2C device address, modify the macro(SH5001_ADDRESS @SH5001.h) based on your I2C function. +* If SPI interface, please ingnore the parameter. +* regAddr: register address +* readLen: data length to read +* *readBuf: data buffer to read; If using FIFO function, the max buffer size is 1024; +* writeLen: data length to write +* *writeBuf: data buffer to write +* +* Note: I2C interface, define USER_INTERFACE_I2C (1) +* SPI interface, define USER_INTERFACE_I2C (0) +* SPI 3 Wire interface, define SH5001_SPI_3WIRE_MODE (1) +* SPI 4 Wire interface, define SH5001_SPI_3WIRE_MODE (0) +* +******************************************************************/ +#define USER_INTERFACE_I2C (1) + +#if USER_INTERFACE_I2C + +unsigned char I2C_ReadNBytes( unsigned char devAddr, + unsigned char regAddr, + unsigned short readLen, + unsigned char *readBuf) +{ + //your I2C interface code: + //...... + custom_i2c_read_regs(devAddr, regAddr, 1, readBuf, readLen,SH5001_I2C_BUS); + return (SH5001_TRUE); +} + +unsigned char I2C_WriteNBytes( unsigned char devAddr, + unsigned char regAddr, + unsigned short writeLen, + unsigned char *writeBuf) +{ + //your I2C interface code: + //...... + custom_i2c_write_reg(devAddr, regAddr, 1, writeBuf, writeLen,SH5001_I2C_BUS); + return (SH5001_TRUE); +} + +IMU_read SH5001_read = I2C_ReadNBytes; +IMU_write SH5001_write = I2C_WriteNBytes; + +#else + +#define SH5001_SPI_3WIRE_MODE (0) + +unsigned char SPI_readNBytes ( unsigned char devAddr, + unsigned char regAddr, + unsigned short readLen, + unsigned char *readBuf) +{ + //your SPI interface code: + + //For example: + //unsigned char u8Data; + //devAddr = devAddr; + //u8Data = (regAddr > 0x7F) ? 0x01 : 0x00; + //SPIWrite(SH5001_SPI_REG_ACCESS, &u8Data, 1); + + //SPIRead((regAddr | 0x80), readBuf, readLen); + return (SH5001_TRUE); +} + +unsigned char SPI_writeNBytes( unsigned char devAddr, + unsigned char regAddr, + unsigned short writeLen, + unsigned char *writeBuf) +{ + //your SPI interface code: + + //For example: + //unsigned char u8Data; + //devAddr = devAddr; + //u8Data = (regAddr > 0x7F) ? 0x01 : 0x00; + //SPIWrite(SH5001_SPI_REG_ACCESS, &u8Data, 1); + + //SPIWrite((regAddr & 0x7F), writeBuf, writeLen); + return (SH5001_TRUE); +} + +IMU_read SH5001_read = SPI_readNBytes; +IMU_write SH5001_write = SPI_writeNBytes; + +#endif + + +static void delay_ms(unsigned short mSecond) +{ + //your delay code(mSecond: millisecond): + //...... + LOS_Mdelay(mSecond); + // HAL_Delay(mSecond); +} + + +#if SH5001_OIS_ENABLE +unsigned char SH5001_OIS_read( unsigned char devAddr, + unsigned char regAddr, + unsigned short readLen, + unsigned char *readBuf) +{ + //your SPI interface code: + + + //SPIRead((regAddr | 0x80), readBuf, readLen); + return (SH5001_TRUE); +} + +#endif + + +/****************************************************************** +* Description: Local Variable +******************************************************************/ + + +/****************************************************************** +* Description: Local Function Prototypes +******************************************************************/ +static void SH5001_ModuleReset(void); +static void SH5001_Acc_Config(unsigned char accODR, + unsigned char accRange, + unsigned char accCutOffFreq, + unsigned char accFilter, + unsigned char accByPass); + +static void SH5001_Gyro_Config( unsigned char gyroODR, + unsigned char gyroRange, + unsigned char gyroCutOffFreq, + unsigned char gyroFilter, + unsigned char gyroByPass); + +static void SH5001_TimeStamp_Config(unsigned char timeStampODR, + unsigned char timeStampEnable); + +static void SH5001_Temp_Config( unsigned char tempODR, + unsigned char tempEnable); + + + +static void SH5001_SoftReset(void) +{ + unsigned char regData = 0; + + regData = 0x01; + SH5001_write(SH5001_ADDRESS, 0x2B, 1, ®Data); + regData = 0x73; + SH5001_write(SH5001_ADDRESS, 0x00, 1, ®Data); + + delay_ms(50); +} + +static void SH5001_DriveStart(void) +{ + unsigned char regData = 0; + //Driver start + regData = 0x01; + SH5001_write(SH5001_ADDRESS, 0x2B, 1, ®Data); + + delay_ms(2); + + regData = 0x00; + SH5001_write(SH5001_ADDRESS, 0x2B, 1, ®Data); + + delay_ms(1); + +} + +static void SH5001_ADCReset(void) +{ + unsigned char regData = 0; + + regData = 0x08; + SH5001_write(SH5001_ADDRESS, 0x30, 1, ®Data); + + regData = 0x00; + SH5001_write(SH5001_ADDRESS, 0xD2, 1, ®Data); + + regData = 0x6B; + SH5001_write(SH5001_ADDRESS, 0xD1, 1, ®Data); + + regData = 0x02; + SH5001_write(SH5001_ADDRESS, 0xD5, 1, ®Data); + delay_ms(5); + + regData = 0x68; + SH5001_write(SH5001_ADDRESS, 0xD1, 1, ®Data); + delay_ms(2); + + regData = 0x00; + SH5001_write(SH5001_ADDRESS, 0xD5, 1, ®Data); + + regData = 0x00; + SH5001_write(SH5001_ADDRESS, 0x30, 1, ®Data); + + regData = 0x08; + SH5001_write(SH5001_ADDRESS, 0x30, 1, ®Data); + + regData = 0xE0; + SH5001_write(SH5001_ADDRESS, 0xD8, 1, ®Data); + + delay_ms(5); + + regData = 0x00; + SH5001_write(SH5001_ADDRESS, 0xD8, 1, ®Data); + + regData = 0x00; + SH5001_write(SH5001_ADDRESS, 0x30, 1, ®Data); +} + +static void SH5001_CVAReset(void) +{ + unsigned char regData = 0; + + regData = 0x12; + SH5001_write(SH5001_ADDRESS, 0xCD, 1, ®Data); + regData = 0x12; + SH5001_write(SH5001_ADDRESS, 0xCE, 1, ®Data); + regData = 0x12; + SH5001_write(SH5001_ADDRESS, 0xCF, 1, ®Data); + + delay_ms(1); + + regData = 0x2; + SH5001_write(SH5001_ADDRESS, 0xCD, 1, ®Data); + regData = 0x2; + SH5001_write(SH5001_ADDRESS, 0xCE, 1, ®Data); + regData = 0x2; + SH5001_write(SH5001_ADDRESS, 0xCF, 1, ®Data); + +} + + +/****************************************************************** +* Description: reset some internal modules; +* +* Parameters: void +* +* return: void +* +******************************************************************/ +static void SH5001_ModuleReset(void) +{ + unsigned char regData = 0; + + // soft reset + SH5001_SoftReset(); + +#if SH5001_SPI_3WIRE_MODE + SH5001_SPI_Config(SH5001_SPI_3_WIRE); +#endif + + //Driver start + SH5001_DriveStart(); + + + // ADC reset + SH5001_ADCReset(); + + //CVA Reset + SH5001_CVAReset(); + + delay_ms(250); +} + + +/****************************************************************** +* Description: 1.set accelerometer parameters; +* 2.accCutOffRreq = accODR * 0.40 or accODR * 0.25 or accODR * 0.11 or accODR * 0.04 or accODR * 0.02; +* +* Parameters: accODR accRange accCutOffFreq accFilter accByPass +* SH5001_ACC_ODR_1000HZ SH5001_ACC_RANGE_16G SH5001_ACC_ODRX040 SH5001_ACC_FILTER_EN SH5001_ACC_BYPASS_EN +* SH5001_ACC_ODR_500HZ SH5001_ACC_RANGE_8G SH5001_ACC_ODRX025 SH5001_ACC_FILTER_DIS SH5001_ACC_BYPASS_DIS +* SH5001_ACC_ODR_250HZ SH5001_ACC_RANGE_4G SH5001_ACC_ODRX011 +* SH5001_ACC_ODR_125HZ SH5001_ACC_RANGE_2G SH5001_ACC_ODRX004 +* SH5001_ACC_ODR_63HZ SH5001_ACC_ODRX002 +* SH5001_ACC_ODR_31HZ +* SH5001_ACC_ODR_16HZ +* SH5001_ACC_ODR_2000HZ +* SH5001_ACC_ODR_4000HZ +* SH5001_ACC_ODR_8000HZ +* +* return: void +* +******************************************************************/ +unsigned char storeAccODR; +static void SH5001_Acc_Config(unsigned char accODR, + unsigned char accRange, + unsigned char accCutOffFreq, + unsigned char accFilter, + unsigned char accByPass) +{ + unsigned char regData = 0; + + // enable acc digital filter and bypass or not + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF0, 1, ®Data); + regData = (regData & 0xFCU) | accFilter | accByPass; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF0, 1, ®Data); + + // set acc ODR range + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF1, 1, ®Data); + regData = (regData & 0x80U) | accODR | accRange; + storeAccODR = regData; + //regData = (regData & 0x80U)| accRange | accODR; + //regData = (regData & 0x80U)| 0x38; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF1, 1, ®Data); + + // set acc low pass filter cut-off frequency + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + regData = (regData & 0xF0U) | accCutOffFreq; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + +} + + + + +/****************************************************************** +* Description: 1.set accelerometer parameters; +* 2.accCutOffRreq = accODR * 0.40 or accODR * 0.25 or accODR * 0.11 or accODR * 0.04 or accODR * 0.02; +* +* Parameters: accODR accRange accCutOffFreq accOisEnable + +* return: void +* +******************************************************************/ +static void SH5001_Acc_OIS_Config(unsigned char accODR, + unsigned char accRange, + unsigned char accCutOffFreq, + unsigned char accOisEnable) +{ + unsigned char regData = 0; + + regData = accODR | accRange | accCutOffFreq | accOisEnable; + SH5001_write(SH5001_ADDRESS, SH5001_OIS_ACC_CONF, 1, ®Data); + +} + +/****************************************************************** +* Description: 1.set gyroscope parameters; +* 2.gyroCutOffRreq is at Page 33 of SH5001 datasheet. +* +* Parameters: gyroODR gyroRangeX,Y,Z gyroCutOffFreq gyroFilter gyroByPass +* SH5001_GYRO_ODR_800HZ SH5001_GYRO_RANGE_125 SH5001_GYRO_ODRX00 SH5001_GYRO_FILTER_EN SH5001_GYRO_BYPASS_EN +* SH5001_GYRO_ODR_400HZ SH5001_GYRO_RANGE_250 SH5001_GYRO_ODRX01 SH5001_GYRO_FILTER_DIS SH5001_GYRO_BYPASS_DIS +* SH5001_GYRO_ODR_200HZ SH5001_GYRO_RANGE_500 SH5001_GYRO_ODRX02 +* SH5001_GYRO_ODR_100HZ SH5001_GYRO_RANGE_1000 SH5001_GYRO_ODRX03 +* SH5001_GYRO_ODR_50HZ SH5001_GYRO_RANGE_2000 +* SH5001_GYRO_ODR_25HZ +* SH5001_GYRO_ODR_1600HZ +* SH5001_GYRO_ODR_3200HZ +* SH5001_GYRO_ODR_6400HZ +* SH5001_GYRO_ODR_12800HZ +* SH5001_GYRO_ODR_25600HZ +* +* gyroOnOff +* SH5001_GYRO_OFF_INACT +* SH5001_GYRO_ON_INACT +* return: void +* +******************************************************************/ +/* +static void SH5001_Gyro_Config( unsigned char gyroODR, + unsigned char gyroRange, + unsigned char gyroCutOffFreq, + unsigned char gyroFilter, + unsigned char gyroByPass, + unsigned char gyroOnOff) +{ + unsigned char regData = 0; + + // enable gyro digital filter + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF0, 1, ®Data); + regData = (regData & 0x7CU) | gyroFilter | gyroByPass | gyroOnOff; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF0, 1, ®Data); + + // set gyro ODR + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF1, 1, ®Data); + regData = (regData & 0xF0U) | gyroODR; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF1, 1, ®Data); + + // set gyro low pass filter cut-off frequency + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF2, 1, ®Data); + regData = (regData & 0xFCU) | gyroCutOffFreq; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF2, 1, ®Data); + + + // set gyro range + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF3, 1, ®Data); + regData = (regData & 0xF8U) | gyroRange; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF3, 1, ®Data); + +} + +*/ +static void SH5001_Gyro_Config( unsigned char gyroODR, + unsigned char gyroRange, + unsigned char gyroCutOffFreq, + unsigned char gyroFilter, + unsigned char gyroByPass) +{ + unsigned char regData = 0; + + // enable gyro digital filter + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF0, 1, ®Data); + regData = (regData & 0x7CU) | gyroFilter | gyroByPass; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF0, 1, ®Data); + + // set gyro ODR Range + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF1, 1, ®Data); + regData = (regData & 0x80U) | gyroODR | gyroRange; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF1, 1, ®Data); + + // set gyro low pass filter cut-off frequency + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF2, 1, ®Data); + regData = (regData & 0xF0U) | gyroCutOffFreq; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF2, 1, ®Data); + +} + +//Jin: Modify +/* */ + + +static void SH5001_Gyro_OIS_Config( unsigned char gyroODR, + unsigned char gyroRange, + unsigned char gyroCutOffFreq, + unsigned char gyroOisEnable) +{ + unsigned char regData = 0; + + regData = gyroODR | gyroRange | gyroCutOffFreq | gyroOisEnable; + SH5001_write(SH5001_ADDRESS, SH5001_OIS_GYRO_CONF, 1, ®Data); + +} + + +/****************************************************************** +* Description: set time stamp parameters; +* +* Parameters: timeStampODR timeStampEnable +* SH5001_TS_ODR_25KHZ SH5001_TS_EN +* SH5001_TS_ODR_1KHZ SH5001_TS_DIS +* +* return: void +* +******************************************************************/ +static void SH5001_TimeStamp_Config(unsigned char timeStampODR, + unsigned char timeStampEnable) +{ + unsigned char regData = 0; + + // config time stamp + SH5001_read(SH5001_ADDRESS, SH5001_TIMESTAMP_CONF, 1, ®Data); + regData = (regData & 0x9FU) | timeStampODR | timeStampEnable; + SH5001_write(SH5001_ADDRESS, SH5001_TIMESTAMP_CONF, 1, ®Data); +} + + +/****************************************************************** +* Description: set temperature parameters; +* +* Parameters: tempODR tempEnable +* SH5001_TEMP_ODR_500HZ SH5001_TEMP_EN +* SH5001_TEMP_ODR_250HZ SH5001_TEMP_DIS +* SH5001_TEMP_ODR_125HZ +* SH5001_TEMP_ODR_63HZ +* +* return: void +* +******************************************************************/ +static void SH5001_Temp_Config( unsigned char tempODR, + unsigned char tempEnable) +{ + unsigned char regData = 0; + + // enable temperature, set ODR + SH5001_read(SH5001_ADDRESS, SH5001_TEMP_CONF0, 1, ®Data); + regData = (regData & 0xF8U) | tempODR | tempEnable; + SH5001_write(SH5001_ADDRESS, SH5001_TEMP_CONF0, 1, ®Data); +} + + +/****************************************************************** +* Description: read temperature parameters; +* +* Parameters: void +* +* return: temperature data(deg); +* +******************************************************************/ +float SH5001_GetTempData(void) +{ + unsigned char regData[2] = {0}; + unsigned short int tempref[2] = {0}; + + // read temperature data, unsigned 12bits; SH5001_TEMP_CONF2..SH5001_TEMP_CONF1 + SH5001_read(SH5001_ADDRESS, SH5001_TEMP_CONF1, 2, ®Data[0]); + tempref[0] = ((unsigned short int)(regData[1] & 0x0FU) << 8U) | regData[0]; + + SH5001_read(SH5001_ADDRESS, SH5001_TEMP_ZL, 2, ®Data[0]); + tempref[1] = ((unsigned short int)(regData[1] & 0x0FU) << 8U) | regData[0]; + + return ( (((float)(tempref[1] - tempref[0]))/14.0f) + 25.0f ); +} + + + +/****************************************************************** +* Description: enable or disable INT, mapping interrupt to INT pin or INT1 pin +* +* Parameters: intType intEnable intPinSel +* SH5001_INT_LOWG SH5001_INT_EN SH5001_INT_MAP_INT0 +* SH5001_INT_HIGHG SH5001_INT_DIS SH5001_INT_MAP_INT1 +* SH5001_INT_INACT +* SH5001_INT_ACT +* SH5001_INT_DOUBLE_TAP +* SH5001_INT_SINGLE_TAP +* SH5001_INT_FLAT +* SH5001_INT_ORIENTATION +* SH5001_INT_TAP (Only INT/INT1 Map) +* SH5001_INT_SMD +* SH5001_INT_FIFO_WATERMARK +* SH5001_INT_GYRO_READY +* SH5001_INT_ACC_READY +* SH5001_INT_FREE_FALL +* SH5001_INT_UP_DOWN_Z +* return: void +* +******************************************************************/ +void SH5001_INT_Enable( unsigned short intType, + unsigned char intEnable, + unsigned char intPinSel) +{ + unsigned char regData[2] = {0}; + unsigned short int u16IntVal = 0; + + // Z axis change between UP to DOWN + if((intType & 0x0040U) == SH5001_INT_UP_DOWN_Z) + { + SH5001_read(SH5001_ADDRESS, SH5001_ORIEN_INTCONF0, 1, ®Data[0]); + regData[0] = (intEnable == SH5001_INT_EN) \ + ? (regData[0] & 0xBFU) : (regData[0] | 0x40U); + SH5001_write(SH5001_ADDRESS, SH5001_ORIEN_INTCONF0, 1, ®Data[0]); + } + + if(intType & 0xFF3FU) + { + // enable or disable INT + SH5001_read(SH5001_ADDRESS, SH5001_INT_ENABLE0, 2, ®Data[0]); + + u16IntVal = ((unsigned short int)regData[0] << 8U) | regData[1]; + + u16IntVal = u16IntVal & 0xFF1FU; + u16IntVal = (intEnable == SH5001_INT_EN) \ + ? (u16IntVal | intType) : (u16IntVal & ~intType); + + regData[0] = (unsigned char)(u16IntVal >> 8U); + regData[1] = (unsigned char)(u16IntVal); + //SH5001_write(SH5001_ADDRESS, SH5001_INT_ENABLE0, 2, ®Data[0]); + SH5001_write(SH5001_ADDRESS, SH5001_INT_ENABLE0, 1, ®Data[0]); + SH5001_write(SH5001_ADDRESS, SH5001_INT_ENABLE1, 1, ®Data[1]); + + // mapping interrupt to INT0 pin or INT1 pin + SH5001_read(SH5001_ADDRESS, SH5001_INT_PIN_MAP0, 2, ®Data[0]); + u16IntVal = ((unsigned short int)regData[0] << 8U) | regData[1]; + + u16IntVal = u16IntVal & 0xFF3FU; + u16IntVal = (intPinSel == SH5001_INT_MAP_INT1) \ + ? (u16IntVal | intType) : (u16IntVal & ~intType); + + regData[0] = (unsigned char)(u16IntVal >> 8U); + regData[1] = (unsigned char)(u16IntVal); + SH5001_write(SH5001_ADDRESS, SH5001_INT_PIN_MAP0, 1, ®Data[0]); + SH5001_write(SH5001_ADDRESS, SH5001_INT_PIN_MAP1, 1, ®Data[1]); + } +} + + +/****************************************************************** +* Description: 1.config INT function +* 2.intCount is valid only when intLatch is equal to SH5001_INT_NO_LATCH; +* +* Parameters: intLevel intLatch intClear +* SH5001_INT_LEVEL_HIGH SH5001_INT_NO_LATCH SH5001_INT_CLEAR_ANY +* SH5001_INT_LEVEL_LOW SH5001_INT_LATCH SH5001_INT_CLEAR_STATUS +* +* intTime +* Unit: 2mS +* +* int1Mode int0Mode +* SH5001_INT1_NORMAL SH5001_INT0_NORMAL +* SH5001_INT1_OD SH5001_INT0_OD +* +* int1OE int0OE +* SH5001_INT1_OUTPUT SH5001_INT0_OUTPUT +* SH5001_INT1_INPUT SH5001_INT1_INPUT +* +* return: void +* +******************************************************************/ + + +void SH5001_INT_Config( unsigned char intLevel, + unsigned char intLatch, + unsigned char intClear, + unsigned char intTime, + unsigned char int1Mode, + unsigned char int0Mode, + unsigned char int1OE, + unsigned char int0OE) +{ + unsigned char regData = 0; + + //SH5001_read(SH5001_ADDRESS, SH5001_INT_CONF, 1, ®Data); + + regData = (intLevel == SH5001_INT0_LEVEL_LOW) \ + ? (regData | SH5001_INT0_LEVEL_LOW) : (regData & SH5001_INT0_LEVEL_HIGH); + + regData = (intLatch == SH5001_INT_NO_LATCH) \ + ? (regData | SH5001_INT_NO_LATCH) : (regData & SH5001_INT_LATCH); + + regData = (intClear == SH5001_INT_CLEAR_ANY) \ + ? (regData | SH5001_INT_CLEAR_ANY) : (regData & SH5001_INT_CLEAR_STATUS); + + regData = (int1Mode == SH5001_INT1_OD) \ + ? (regData | SH5001_INT1_OD) : (regData & SH5001_INT1_NORMAL); + + regData = (int1OE == SH5001_INT1_OUTPUT) \ + ? (regData | SH5001_INT1_OUTPUT) : (regData & SH5001_INT1_INPUT); + + regData = (int0Mode == SH5001_INT0_OD) \ + ? (regData | SH5001_INT0_OD) : (regData & SH5001_INT0_NORMAL); + + regData = (int0OE == SH5001_INT0_OUTPUT) \ + ? (regData | SH5001_INT0_OUTPUT) : (regData & SH5001_INT0_INPUT); + + SH5001_write(SH5001_ADDRESS, SH5001_INT_CONF, 1, ®Data); + + if(intLatch == SH5001_INT_NO_LATCH) + { + regData = intTime; + SH5001_write(SH5001_ADDRESS, SH5001_INT_LIMIT, 1, ®Data); + } +} + + + + +/****************************************************************** +* Description: 1.config INT0 & INT1 function +* +* Parameters: int1Mode int0Mode +* SH5001_INT1_NORMAL SH5001_INT0_NORMAL +* SH5001_INT1_OD SH5001_INT0_OD +* +* int1OE int0OE +* SH5001_INT1_OUTPUT SH5001_INT0_OUTPUT +* SH5001_INT1_INPUT SH5001_INT1_INPUT +* +* return: void +* +******************************************************************/ +void SH5001_INT_Output_Config( unsigned char int1Mode, + unsigned char int0Mode, + unsigned char int1OE, + unsigned char int0OE) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_INT_CONF, 1, ®Data); + + regData = (int1Mode == SH5001_INT1_OD) \ + ? (regData | SH5001_INT1_OD) : (regData & SH5001_INT1_NORMAL); + + regData = (int1OE == SH5001_INT1_OUTPUT) \ + ? (regData | SH5001_INT1_OUTPUT) : (regData & SH5001_INT1_INPUT); + + regData = (int0Mode == SH5001_INT0_OD) \ + ? (regData | SH5001_INT0_OD) : (regData & SH5001_INT0_NORMAL); + + regData = (int0OE == SH5001_INT0_OUTPUT) \ + ? (regData | SH5001_INT0_OUTPUT) : (regData & SH5001_INT1_INPUT); + + SH5001_write(SH5001_ADDRESS, SH5001_INT_CONF, 1, ®Data); +} + + +/****************************************************************** +* Description: orientation config; +* +* Parameters: orientBlockMode orientMode orientTheta +* SH5001_ORIENT_BLOCK_MODE0 SH5001_ORIENT_SYMM (1 Byte) +* SH5001_ORIENT_BLOCK_MODE1 SH5001_ORIENT_HIGH_ASYMM +* SH5001_ORIENT_BLOCK_MODE2 SH5001_ORIENT_LOW_ASYMM +* SH5001_ORIENT_BLOCK_MODE3 +* +* orientG1point5 orientSlope orientHyst +* (2 Bytes) (2 Bytes) (2 Bytes) +* +* return: void +* +******************************************************************/ +void SH5001_INT_Orient_Config( unsigned char orientBlockMode, + unsigned char orientMode, + unsigned char orientTheta, + unsigned short orientG1point5, + unsigned short orientSlope, + unsigned short orientHyst) +{ + unsigned char regData[2] = {0}; + + SH5001_read(SH5001_ADDRESS, SH5001_ORIEN_INTCONF0, 1, ®Data[0]); + regData[0] |= (regData[0] & 0xC0U) | (orientTheta & 0x3FU); + SH5001_write(SH5001_ADDRESS, SH5001_ORIEN_INTCONF0, 1, ®Data[0]); + + SH5001_read(SH5001_ADDRESS, SH5001_ORIEN_INTCONF1, 1, ®Data[0]); + regData[0] |= (regData[0] & 0xF0U) | (orientBlockMode & 0x0CU) | (orientMode & 0x03U); + SH5001_write(SH5001_ADDRESS, SH5001_ORIEN_INTCONF1, 1, ®Data[0]); + + regData[0] = (unsigned char)orientG1point5; + regData[1] = (unsigned char)(orientG1point5 >> 8U); + SH5001_write(SH5001_ADDRESS, SH5001_ORIEN_INT_1G5_LOW, 2, ®Data[0]); + + regData[0] = (unsigned char)orientSlope; + regData[1] = (unsigned char)(orientSlope >> 8U); + SH5001_write(SH5001_ADDRESS, SH5001_ORIEN_INT_SLOPE_LOW, 2, ®Data[0]); + + regData[0] = (unsigned char)orientHyst; + regData[1] = (unsigned char)(orientHyst >> 8U); + SH5001_write(SH5001_ADDRESS, SH5001_ORIEN_INT_HYST_LOW, 2, ®Data[0]); +} + + + +// Jin: flatTimeTH 200,400,800,000, sure? + +/****************************************************************** +* Description: flat INT time threshold, unit: mS; +* +* Parameters: flatTimeTH flatTanHeta2 +* SH5001_FLAT_TIME_200MS 0 ~ 63 +* SH5001_FLAT_TIME_400MS +* SH5001_FLAT_TIME_800MS +* SH5001_FLAT_TIME_000MS +* +* return: void +* +******************************************************************/ +void SH5001_INT_Flat_Config(unsigned char flatTimeTH, + unsigned char flatTanHeta2) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_ORIEN_INTCONF1, 1, ®Data); + regData = (regData & 0xF3U) | SH5001_ORIENT_BLOCK_MODE1; + SH5001_write(SH5001_ADDRESS, SH5001_ORIEN_INTCONF1, 1, ®Data); + + SH5001_read(SH5001_ADDRESS, SH5001_FLAT_INT_CONF, 1, ®Data); + regData = (flatTimeTH & 0xC0U) | (flatTanHeta2 & 0x3FU); + SH5001_write(SH5001_ADDRESS, SH5001_FLAT_INT_CONF, 1, ®Data); +} + +// Jin: Act and inAct function --- actIntClear ? + +/****************************************************************** +* Description: activity INT config; +* actIntThres: 1 LSB is 0.24mg@+/-2G, 0.48mg@+/-4G, 0.97mg@+/-8G, 1.95mg@+/-16G +* +* Parameters: actEnDisIntX actEnDisIntY actEnDisIntZ +* SH5001_ACT_X_INT_EN SH5001_ACT_Y_INT_EN SH5001_ACT_Z_INT_EN +* SH5001_ACT_X_INT_DIS SH5001_ACT_Y_INT_DIS SH5001_ACT_Z_INT_DIS +* +* +* actTimeNum actIntThres actLinkStatus actIntClear +* (1 Byte) (2 Byte2) SH5001_LINK_PRE_STA SH5001_ACT_INACT_CLR_STATUS1 +* SH5001_LINK_PRE_STA_NO SH5001_ACT_INACT_CLR_STATUS3 +* +* return: void +* +******************************************************************/ +void SH5001_INT_Act_Config( unsigned char actEnDisIntX, + unsigned char actEnDisIntY, + unsigned char actEnDisIntZ, + unsigned char actTimeNum, + unsigned short actIntThres, + unsigned char actLinkStatus, + unsigned char actIntClear) +{ + unsigned char regData[2] = {0}; + + SH5001_read(SH5001_ADDRESS, SH5001_ACT_INACT_INT_CONF, 1, ®Data[0]); + regData[0] |= (regData[0] & 0x8FU) | actEnDisIntX | actEnDisIntY | actEnDisIntZ; + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INACT_INT_CONF, 1, ®Data[0]); + + regData[0] = (unsigned char)actIntThres; + regData[1] = (unsigned char)(actIntThres >> 8U); + //SH5001_write(SH5001_ADDRESS, SH5001_ACT_INT_THRESHOLDL, 2, ®Data[0]); + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INT_THRESHOLDL, 1, ®Data[0]); + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INT_THRESHOLDH, 1, ®Data[1]); + + regData[0] = actTimeNum; + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INT_TIME, 1, ®Data[0]); + + SH5001_read(SH5001_ADDRESS, SH5001_ACT_INACT_INT_LINK, 1, ®Data[0]); + regData[0] |= (regData[0] & 0x7EU) | actLinkStatus | actIntClear; + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INACT_INT_LINK, 1, ®Data[0]); +} + + +/****************************************************************** +* Description: inactivity INT config; +* +* Parameters: inactEnDisIntX inactEnDisIntY inactEnDisIntZ +* SH5001_INACT_X_INT_EN SH5001_INACT_Y_INT_EN SH5001_INACT_Z_INT_EN +* SH5001_INACT_X_INT_DIS SH5001_INACT_Y_INT_DIS SH5001_INACT_Z_INT_DIS +* +* inactLinkStatus inactTimeMs inactIntThres +* SH5001_LINK_PRE_STA Unit: mS (2 Bytes) +* SH5001_LINK_PRE_STA_NO +* +* inactG1 inactIntClear +* (2 Bytes) SH5001_ACT_INACT_CLR_STATUS1 +* SH5001_ACT_INACT_CLR_STATUS3 +* +* return: void +* +******************************************************************/ +void SH5001_INT_Inact_Config( unsigned char inactEnDisIntX, + unsigned char inactEnDisIntY, + unsigned char inactEnDisIntZ, + unsigned char inactLinkStatus, + unsigned char inactTimeMs, + unsigned short inactIntThres, + unsigned short inactG1, + unsigned char inactIntClear) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_ACT_INACT_INT_CONF, 1, ®Data); + regData |= (regData & 0xF8U) | inactEnDisIntX | inactEnDisIntY | inactEnDisIntZ; + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INACT_INT_CONF, 1, ®Data); + + regData = (unsigned char)inactIntThres; + SH5001_write(SH5001_ADDRESS, SH5001_INACT_INT_THRESHOLDL, 1, ®Data); + regData = (unsigned char)(inactIntThres >> 8U); + SH5001_write(SH5001_ADDRESS, SH5001_INACT_INT_THRESHOLDH, 1, ®Data); + + regData = inactTimeMs; + SH5001_write(SH5001_ADDRESS, SH5001_INACT_INT_TIME, 1, ®Data); + + /* + regData = (unsigned char)inactG1; + SH5001_write(SH5001_ADDRESS, SH5001_INACT_INT_1G_REFL, 1, ®Data); + regData = (unsigned char)(inactG1 >> 8U); + SH5001_write(SH5001_ADDRESS, SH5001_INACT_INT_1G_REFH, 1, ®Data); + + SH5001_read(SH5001_ADDRESS, SH5001_ACT_INACT_INT_LINK, 1, ®Data); + regData |= (regData & 0x7EU) | inactLinkStatus | inactIntClear; + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INACT_INT_LINK, 1, ®Data); + */ +} + + +/****************************************************************** +* Description: 1.tap INT config; +* 2.tapIntThres is between 0 and 8191; +* 3.tapWaitTimeWindowMs is more than tapWaitTimeMs; +* +* Parameters: tapEnDisIntX tapEnDisIntY tapEnDisIntZ +* SH5001_TAP_X_INT_EN SH5001_TAP_Y_INT_EN SH5001_TAP_Z_INT_EN +* SH5001_TAP_X_INT_DIS SH5001_TAP_Y_INT_DIS SH5001_TAP_Z_INT_DIS +* +* tapIntThres tapTimeMs tapWaitTimeMs tapWaitTimeWindowMs +* (13 bits) Unit: mS Unit: mS Unit: 2mS +* +* return: void +* +******************************************************************/ +void SH5001_INT_Tap_Config( unsigned char tapEnDisIntX, + unsigned char tapEnDisIntY, + unsigned char tapEnDisIntZ, + unsigned char tapIntThres, + unsigned char tapTimeMs, + unsigned char tapWaitTimeMs, + unsigned char tapWaitTimeWindowMs) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_ACT_INACT_INT_LINK, 1, ®Data); + regData |= (regData & 0xF1U) | tapEnDisIntX | tapEnDisIntY | tapEnDisIntZ; + SH5001_write(SH5001_ADDRESS, SH5001_ACT_INACT_INT_LINK, 1, ®Data); + + regData = (unsigned char)tapIntThres; + SH5001_write(SH5001_ADDRESS, SH5001_TAP_INT_THRESHOLDL, 1, ®Data); + SH5001_read(SH5001_ADDRESS, SH5001_TAP_INT_THRESHOLDH, 1, ®Data); + regData = ((unsigned char)(tapIntThres >> 8U) & 0x1FU) | (regData & 0xE0U); + SH5001_write(SH5001_ADDRESS, SH5001_TAP_INT_THRESHOLDH, 1, ®Data); + + regData = tapTimeMs; + SH5001_write(SH5001_ADDRESS, SH5001_TAP_INT_DURATION, 1, ®Data); + + regData = tapWaitTimeMs; + SH5001_write(SH5001_ADDRESS, SH5001_TAP_INT_LATENCY, 1, ®Data); + + regData = tapWaitTimeWindowMs; + SH5001_write(SH5001_ADDRESS, SH5001_DTAP_INT_WINDOW, 1, ®Data); +} + + +/****************************************************************** +* Description: 1.SMD INT config; +* 2.smdBlockTimeS:0-0.5S; 1-1.0S; 2-1.5S; 3-2.0S; +* 4-3.0S; 5-4.0S; 6-5.0S; 7-6.0S; +* 8-7.0S; 9-8.0S; A-9.0S; B-10S; +* C-12S; D-14S; E-15S; F-16S; +* +* 3.smdProofTimeS:0-0.2S; 1-0.25S; 2-0.3S; 3-0.4S; +* 4-0.5S; 5-0.6S; 6-0.7S; 7-0.8S; +* 8-0.9S; 9-1.0S; A-1.2S; B-1.5S; +* C-1.8S; D-2.1S; E-2.4S; F-2.8S; +* +* Parameters: smdThres smdBlockTimeS smdProofTimeS +* 2 Bytes Unit: S Unit: S +* +* return: void +* +******************************************************************/ +void SH5001_INT_SMD_Config( unsigned short smdThres, + unsigned char smdBlockTimeS, + unsigned char smdProofTimeS) +{ + unsigned char regData[2] = {0}; + + regData[0] = (unsigned char)smdThres; + regData[1] = (unsigned char)(smdThres >> 8U); + SH5001_write(SH5001_ADDRESS, SH5001_SMD_INT_THRESHOLDL, 2, ®Data[0]); + + regData[0] |= (unsigned char)((smdBlockTimeS & 0xF0U) << 4U) | (smdProofTimeS & 0xF0U); + SH5001_write(SH5001_ADDRESS, SH5001_HIGHG_INT_CONF, 1, ®Data[0]); +} + + +/****************************************************************** +* Description: 1.highG INT config; +* 2.highGThres is between 0 and 8191; +* 3.highGThres: x=0.5mG@2G, x=1mG@4G, x=2mG@8G, x=4mG@16G +* +* Parameters: highGEnDisIntX highGEnDisIntY highGEnDisIntZ +* SH5001_HIGHG_X_INT_EN SH5001_HIGHG_Y_INT_EN SH5001_HIGHG_Z_INT_EN +* SH5001_HIGHG_X_INT_DIS SH5001_HIGHG_Y_INT_DIS SH5001_HIGHG_Z_INT_DIS +* +* highGEnDisIntAll highGThres highGTimeMs +* SH5001_HIGHG_ALL_INT_EN Unit: x*8mG Unit: 2mS +* SH5001_HIGHG_ALL_INT_DIS (13 bits) +* +* return: void +* +******************************************************************/ +void SH5001_INT_HighG_Config( unsigned char highGEnDisIntX, + unsigned char highGEnDisIntY, + unsigned char highGEnDisIntZ, + unsigned char highGEnDisIntAll, + unsigned short highGThres, + unsigned char highGTimeMs) +{ + unsigned char regData[2] = {0}; + + SH5001_read(SH5001_ADDRESS, SH5001_HIGHG_INT_CONF, 1, ®Data[0]); + regData[0] |= (regData[0] & 0x0FU) | highGEnDisIntX | highGEnDisIntY | highGEnDisIntZ | highGEnDisIntAll; + SH5001_write(SH5001_ADDRESS, SH5001_HIGHG_INT_CONF, 1, ®Data[0]); + + SH5001_read(SH5001_ADDRESS, SH5001_HIGHG_INT_THRESHOLDL, 2, ®Data[0]); + regData[0] = (unsigned char)highGThres; + regData[1] = (regData[1] & 0xE0U) | ((unsigned char)(highGThres >> 8U) & 0x1FU); + SH5001_write(SH5001_ADDRESS, SH5001_HIGHG_INT_THRESHOLDL, 2, ®Data[0]); + + regData[0] = highGTimeMs; + SH5001_write(SH5001_ADDRESS, SH5001_HIGHG_INT_TIME, 1, ®Data[0]); +} + + +/****************************************************************** +* Description: 1.lowG INT config; +* 2.lowGThres is between 0 and 8191; +* 3.lowGThres: x=0.5mG@2G or x=1mG@4G or x=2mG@8G or x=4mG@16G +* +* Parameters: lowGEnDisIntAll lowGThres lowGTimeMs +* SH5001_LOWG_ALL_INT_EN Unit: x*8mG Unit: 2mS +* SH5001_LOWG_ALL_INT_DIS (13 bits) +* +* return: void +* +******************************************************************/ +void SH5001_INT_LowG_Config( unsigned char lowGEnDisIntAll, + unsigned short lowGThres, + unsigned char lowGTimeMs) +{ + unsigned char regData[2] = {0}; + + SH5001_read(SH5001_ADDRESS, SH5001_HIGHG_INT_CONF, 1, ®Data[0]); + regData[0] |= (regData[0] & 0xFEU) | lowGEnDisIntAll; + SH5001_write(SH5001_ADDRESS, SH5001_HIGHG_INT_CONF, 1, ®Data[0]); + + SH5001_read(SH5001_ADDRESS, SH5001_LOWG_INT_THRESHOLDL, 2, ®Data[0]); + regData[0] = (unsigned char)lowGThres; + regData[1] = (regData[1] & 0xE0U) | ((unsigned char)(lowGThres >> 8U) & 0x1FU); + SH5001_write(SH5001_ADDRESS, SH5001_LOWG_INT_THRESHOLDL, 2, ®Data[0]); + + regData[0] = lowGTimeMs; + SH5001_write(SH5001_ADDRESS, SH5001_LOWG_INT_TIME, 1, ®Data[0]); +} + + +/****************************************************************** +* Description: 1.freeFall INT config; +* 2.freeFallThres: x=0.5mG@2G or x=1mG@4G or x=2mG@8G or x=4mG@16G +* +* Parameters: freeFallThres freeFallTimeMs +* Unit: x*8mG Unit: 2mS +* +* return: void +* +******************************************************************/ +void SH5001_INT_FreeFall_Config( unsigned char freeFallThres, + unsigned char freeFallTimeMs) +{ + unsigned char regData = 0; + + regData = freeFallThres; + SH5001_write(SH5001_ADDRESS, SH5001_FREEFALL_INT_THRES, 1, ®Data); + + regData = freeFallTimeMs; + SH5001_write(SH5001_ADDRESS, SH5001_FREEFALL_INT_TIME, 1, ®Data); +} + + + +/****************************************************************** +* Description: 1.read INT status0 +* +* Parameters: void +* +* return: unsigned short +* bit 13: Tap, Single or Double Tap Interrupt status +* bit 12: SMD Interrupt status +* bit 11: FIFO Watermark Interrupt status +* bit 10: Gyro Data Ready Interrupt status +* bit 9: Acc Data Ready Interrupt status +* bit 8: Free-fall Interrupt status +* bit 7: Low-G Interrupt status +* bit 6: High-G Interrupt status +* bit 5: Inactivity Interrupt status +* bit 4: Activity Interrupt status +* bit 3: Double Tap Interrupt status +* bit 2: Single Tap Interrupt status +* bit 1: Flat Interrupt status +* bit 0: Orientation Interrupt status +* 0: Not Active +* 1: Active +* +******************************************************************/ +unsigned short SH5001_INT_Read_Status01(void) +{ + unsigned char regData[3] = {0}; + + SH5001_read(SH5001_ADDRESS, SH5001_INT_STA0, 3, ®Data[0]); + + return( ((unsigned short)(regData[1] & 0x3FU) << 8U) | regData[0] ); +} + + +/****************************************************************** +* Description: 1.read INT status2 +* +* Parameters: void +* +* return: unsigned char +* bit 7: High-G Sign +* 0: Positive +* 1: Negative +* bit 6: High-G X-axis Interrupt status +* bit 5: High-G Y-axis Interrupt status +* bit 4: High-G Z-axis Interrupt status +* 0: No Active +* 1: Active +* bit 3: Reserved +* bit 2: Reserved +* bit 1: Reserved +* bit 0: Low-G Interrupt status +* 0: Not Active +* 1: Active +* +******************************************************************/ +unsigned char SH5001_INT_Read_Status2(void) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_INT_STA2, 1, ®Data); + + return( (regData & 0xF1U)); +} + + +/****************************************************************** +* Description: 1.read INT status3 +* +* Parameters: void +* +* return: unsigned char +* bit 7: Activity-Inactivity Sign +* 0: Positive +* 1: Negative +* bit 6: Activity-Inactivity X-axis Interrupt Status +* bit 5: Activity-Inactivity Y-axis Interrupt Status +* bit 4: Activity-Inactivity Z-axis Interrupt Status +* 0: No Active +* 1: Active +* bit 3: Sign of acceleration that trigger Single or Double Tap Interrup +* 0: Positive +* 1: Negative +* bit 2: Whether Single or Double Tap Interrupt is triggered by X axis +* bit 1: Whether Single or Double Tap Interrupt is triggered by Y axis +* bit 0: Whether Single or Double Tap Interrupt is triggered by Z axis +* 0: No +* 1: Yes +******************************************************************/ +unsigned char SH5001_INT_Read_Status3(void) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_INT_STA3, 1, ®Data); + + return(regData); +} + + +/****************************************************************** +* Description: 1.read INT status4 +* +* Parameters: void +* +* return: unsigned char +* bit 7: Reserved +* bit 6: Reserved +* bit 5: Reserved +* bit 4: Reserved +* bit 3: Reserved +* bit 2: Orientation Interrupt Value of Z-axis +* 0: Upward +* 1: Downward +* bit 1..0: Orientation Interrupt Value of X and Y-axis +* 00: Landscape left +* 01: Landscape right +* 10: Portrait upside down +* 11: Portrait upright +* +******************************************************************/ +unsigned char SH5001_INT_Read_Status4(void) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_INT_STA4, 1, ®Data); + + return(regData & 0x07U); +} + + + +/****************************************************************** +* Description: reset FIFO controller; +* +* Parameters: fifoMode +* SH5001_FIFO_MODE_DIS +* SH5001_FIFO_MODE_FIFO +* SH5001_FIFO_MODE_STREAM +* SH5001_FIFO_MODE_TRIGGER +* +* return: void +* +******************************************************************/ +void SH5001_FIFO_Mode_Set(unsigned char fifoMode) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_FIFO_CONF0, 1, ®Data); + regData &= 0x7F; + SH5001_write(SH5001_ADDRESS, SH5001_FIFO_CONF0, 1, ®Data); + + regData = fifoMode & 0x03; + SH5001_write(SH5001_ADDRESS, SH5001_FIFO_CONF0, 1, ®Data); +} + +void SH5001_FIFO_Reset(void) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_FIFO_CONF0, 1, ®Data); + regData |= 0x80; + SH5001_write(SH5001_ADDRESS, SH5001_FIFO_CONF0, 1, ®Data); +} + + + +/****************************************************************** +* Description: 1.FIFO down sample frequency config; +* 2.fifoAccFreq: accODR*1/2, *1/4, *1/8, *1/16, *1/32, *1/64, *1/128, *1/256 +* 3.fifoGyroFreq: gyroODR*1/2, *1/4, *1/8, *1/16, *1/32, *1/64, *1/128, *1/256 +* +* Parameters: fifoAccDownSampleEnDis fifoAccFreq/fifoGyroFreq fifoGyroDownSampleEnDis +* SH5001_FIFO_ACC_DOWNS_EN SH5001_FIFO_FREQ_X1_2 SH5001_FIFO_GYRO_DOWNS_EN +* SH5001_FIFO_ACC_DOWNS_DIS SH5001_FIFO_FREQ_X1_4 SH5001_FIFO_GYRO_DOWNS_DIS +* SH5001_FIFO_FREQ_X1_8 +* SH5001_FIFO_FREQ_X1_16 +* SH5001_FIFO_FREQ_X1_32 +* SH5001_FIFO_FREQ_X1_64 +* SH5001_FIFO_FREQ_X1_128 +* SH5001_FIFO_FREQ_X1_256 +* return: void +* +******************************************************************/ +void SH5001_FIFO_Freq_Config( unsigned char fifoAccDownSampleEnDis, + unsigned char fifoAccFreq, + unsigned char fifoGyroDownSampleEnDis, + unsigned char fifoGyroFreq) +{ + unsigned char regData = 0; + + regData |= fifoAccDownSampleEnDis | fifoGyroDownSampleEnDis; + regData |= (fifoAccFreq << 4) | fifoGyroFreq; + SH5001_write(SH5001_ADDRESS, SH5001_FIFO_CONF4, 1, ®Data); +} + + +// Jin: fifoWaterMarkLevel??? +/****************************************************************** +* Description: 1.config data type in FIFO; +* 2.fifoWaterMarkLevel <= channelNum*2*(INT(1024/(channelNum*2))-1) +* eg. fifomode = SH5001_FIFO_ACC_X_EN | SH5001_FIFO_ACC_Y_EN | SH5001_FIFO_ACC_Z_EN +* then fifoWaterMarkLevel maximum is 1014 +* +* Parameters: fifoMode fifoWaterMarkLevel + SH5001_FIFO_TIMESTAMP_EN <=1024 +* SH5001_FIFO_EXT_Z_EN +* SH5001_FIFO_EXT_Y_EN +* SH5001_FIFO_EXT_X_EN +* SH5001_FIFO_TEMPERATURE_EN +* SH5001_FIFO_GYRO_Z_EN +* SH5001_FIFO_GYRO_Y_EN +* SH5001_FIFO_GYRO_X_EN +* SH5001_FIFO_ACC_Z_EN +* SH5001_FIFO_ACC_Y_EN +* SH5001_FIFO_ACC_X_EN +* SH5001_FIFO_ALL_DIS +* +* return: void +* +******************************************************************/ +void SH5001_FIFO_Data_Config( unsigned short fifoMode, + unsigned short fifoWaterMarkLevel) +{ + unsigned char regData = 0; + + if(fifoWaterMarkLevel > 1024U) + { + fifoWaterMarkLevel = 1024U; + } + + SH5001_read(SH5001_ADDRESS, SH5001_FIFO_CONF2, 1, ®Data); + regData = (regData & 0x88U) \ + | ((unsigned char)(fifoMode >> 8U) & 0x70U) \ + | (((unsigned char)(fifoWaterMarkLevel >> 8U)) & 0x07U); + SH5001_write(SH5001_ADDRESS, SH5001_FIFO_CONF2, 1, ®Data); + + regData = (unsigned char)fifoMode; + SH5001_write(SH5001_ADDRESS, SH5001_FIFO_CONF3, 1, ®Data); + + regData = (unsigned char)fifoWaterMarkLevel; + SH5001_write(SH5001_ADDRESS, SH5001_FIFO_CONF1, 1, ®Data); +} + + + +/****************************************************************** +* Description: 1. read Fifo status and fifo entries count +* +* Parameters: *fifoEntriesCount, store fifo entries count, less than or equal to 1024; +* +* +* return: unsigned char +* bit 7: 0 +* bit 6: 0 +* bit 5: Whether FIFO Watermark has been reached +* bit 4: Whether FIFO is full +* bit 3: Whether FIFO is empty +* 0: No +* 1: Yes +* bit 2: 0 +* bit 1: 0 +* bit 0: 0 +* +* +******************************************************************/ +unsigned char SH5001_FIFO_Read_Status(unsigned short int *fifoEntriesCount) +{ + unsigned char regData[2] = {0}; + + SH5001_read(SH5001_ADDRESS, SH5001_FIFO_STA0, 2, ®Data[0]); + + *fifoEntriesCount = ((unsigned short int)(regData[1] & 0x0FU) << 8U) | regData[0]; + + + return (regData[1] & 0x70U); +} + + +/****************************************************************** +* Description: 1. read Fifo data +* +* Parameters: *fifoReadData fifoDataLength +* data data length +* +* return: void +* +* +******************************************************************/ +void SH5001_FIFO_Read_Data(unsigned char *fifoReadData, unsigned short int fifoDataLength) +{ + if(fifoDataLength == 0) + { + return; + } + + if(fifoDataLength > 1024U) + { + fifoDataLength = 1024U; + } + + SH5001_read(SH5001_ADDRESS, SH5001_FIFO_DATA, fifoDataLength, fifoReadData); + /* + while(fifoDataLength--) + { + SH5001_read(SH5001_ADDRESS, SH5001_FIFO_DATA, 1, fifoReadData); + fifoReadData++; + } + */ +} + + +/****************************************************************** +* Description: reset Mater I2C; +* +* Parameters: void +* +* return: void +* +******************************************************************/ +void SH5001_MI2C_Reset(void) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + regData |= 0x80U; + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + regData &= 0x7FU; + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + +} + + +/****************************************************************** +* Description: 1.master I2C config; +* 2.master I2C clock frequency is (1MHz/(6+3*mi2cFreq)); +* 3.mi2cSlaveAddr: slave device address, 7 bits; +* +* +* Parameters: mi2cReadMode mi2cODR mi2cFreq +* SH5001_MI2C_READ_MODE_AUTO SH5001_MI2C_READ_ODR_200HZ <=15 +* SH5001_MI2C_READ_MODE_MANUAL SH5001_MI2C_READ_ODR_100HZ +* SH5001_MI2C_READ_ODR_50HZ +* SH5001_MI2C_READ_ODR_25HZ +* return: void +* +******************************************************************/ +void SH5001_MI2C_Bus_Config( unsigned char mi2cReadMode, + unsigned char mi2cODR, + unsigned char mi2cFreq) +{ + unsigned char regData = 0; + + if(mi2cFreq > 15U) + { + mi2cFreq = 15U; + } + + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF1, 1, ®Data); + regData = (regData & 0xC0U) | (mi2cODR & 0x30U) | mi2cFreq; + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CONF1, 1, ®Data); + + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + regData = (regData & 0xBFU) | mi2cReadMode; + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); +} + + +/****************************************************************** +* Description: 1.master I2C address and command config; +* 2.mi2cSlaveAddr: slave device address, 7 bits; +* +* Parameters: mi2cSlaveAddr mi2cSlaveCmd mi2cReadMode +* (1 Byte) (1 Byte) SH5001_MI2C_READ_MODE_AUTO +* SH5001_MI2C_READ_MODE_MANUAL +* +* return: void +* +******************************************************************/ +void SH5001_MI2C_Cmd_Config( unsigned char mi2cSlaveAddr, + unsigned char mi2cSlaveCmd, + unsigned char mi2cReadMode) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + regData = (regData & 0xBFU) | mi2cReadMode; + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CMD0, 1, ®Data); + regData |= (mi2cSlaveAddr << 1U); + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CMD0, 1, ®Data); + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CMD1, 1, &mi2cSlaveCmd); +} + + +/****************************************************************** +* Description: 1.master I2C write data fucntion; +* 2.mi2cWriteData: write data; +* +* Parameters: mi2cWriteData +* +* return: SH5001_TRUE or SH5001_FALSE +* +******************************************************************/ +unsigned char SH5001_MI2C_Write(unsigned char mi2cWriteData) +{ + unsigned char regData = 0; + unsigned char i = 0; + + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_WR, 1, &mi2cWriteData); + + //Master I2C enable, write-operation + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + regData = (regData & 0xFCU) | 0x02U; + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + + // wait write-operation to end + while(i++ < 20U) + { + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + if(regData & 0x30U) + break; + } + + if((regData & 0x30U) == SH5001_MI2C_SUCCESS) + { + return (SH5001_TRUE); + } + else + { + return (SH5001_FALSE); + } +} + + +/****************************************************************** +* Description: 1.master I2C read data fucntion; +* 2.*mi2cReadData: read data; +* +* Parameters: *mi2cReadData +* +* return: SH5001_TRUE or SH5001_FALSE +* +******************************************************************/ +unsigned char SH5001_MI2C_Read(unsigned char *mi2cReadData) +{ + unsigned char regData = 0; + unsigned char i = 0; + + + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + if((regData & 0x40U) == 0) + { + //Master I2C enable, read-operation + regData |= 0x03U; + SH5001_write(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + } + + // wait read-operation to end + while(i++ < 20U) + { + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + if(regData & 0x30U) + break; + } + + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_CONF0, 1, ®Data); + if((regData & 0x30U) == SH5001_MI2C_SUCCESS) + { + SH5001_read(SH5001_ADDRESS, SH5001_MI2C_RD, 1, ®Data); + *mi2cReadData = regData; + + return (SH5001_TRUE); + } + else + { + return (SH5001_FALSE); + } +} + + +/****************************************************************** +* Description: 1.SPI interface config; Default: SH5001_SPI_4_WIRE +* +* Parameters: spiInterfaceMode +* SH5001_SPI_3_WIRE +* SH5001_SPI_4_WIRE +* +* return: void +* +******************************************************************/ +void SH5001_SPI_Config( unsigned char spiInterfaceMode) +{ + #if 0 + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_SPI_CONF, 1, ®Data); + regData = (regData & 0xDFU) | spiInterfaceMode; + #endif + unsigned char regData = spiInterfaceMode; + + SH5001_write(SH5001_ADDRESS, SH5001_SPI_CONF, 1, ®Data); +} + + +/****************************************************************** +* Description: 1.I2C interface config; Default: SH5001_I2C_EN +* +* Parameters: i2cInterfaceEnDis +* SH5001_I2C_EN +* SH5001_I2C_DIS +* +* return: void +* +******************************************************************/ +void SH5001_I2C_Config(unsigned char i2cInterfaceEnDis) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_I2C_CONF, 1, ®Data); + regData = (regData & 0x7FU) | i2cInterfaceEnDis; + SH5001_write(SH5001_ADDRESS, SH5001_I2C_CONF, 1, ®Data); +} + + + +// Jin +/****************************************************************** +* Description: 1.I2C loop mode config; +* 2.SH5001_I2C_LP_06BYTE: ACC_X ACC_Y ACC_Z +* 3.SH5001_I2C_LP_12BYTE: ACC_X ACC_Y ACC_Z GYRO_X GYRO_Y GYRO_Z +* 4.SH5001_I2C_LP_14BYTE: ACC_X ACC_Y ACC_Z GYRO_X GYRO_Y GYRO_Z TEMPERATURE +* +* Parameters: i2cReadLoopMode +* SH5001_I2C_LP_06BYTE +* SH5001_I2C_LP_12BYTE +* SH5001_I2C_LP_14BYTE +* SH5001_I2C_LP_DISABLE +* +* return: void +* +******************************************************************/ +void SH5001_I2C_LP_Config(unsigned char i2cReadLoopMode) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_I2C_CONF, 1, ®Data); + regData = (regData & 0xF8U) | i2cReadLoopMode; + SH5001_write(SH5001_ADDRESS, SH5001_I2C_CONF, 1, ®Data); +} + + +/****************************************************************** +* Description: 1.OIS SPI interface config; Default: SH5001_OIS_SPI_DIS +* +* Parameters: oisSpiInterfaceMode oisSpiInterfaceEnDis +* SH5001_OIS_SPI_3WIRE SH5001_OIS_SPI_EN +* SH5001_OIS_SPI_4WIRE SH5001_OIS_SPI_DIS +* +* return: void +* +******************************************************************/ + +void SH5001_OIS_SPI_Config(unsigned char oisSpiInterfaceEnDis) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, SH5001_OIS_SPI_CONF, 1, ®Data); + regData = (regData & 0xEFU) | oisSpiInterfaceEnDis; + SH5001_write(SH5001_ADDRESS, SH5001_OIS_SPI_CONF, 1, ®Data); +} + + +/****************************************************************** +* Description: 1.Switch SH5001 power mode; +* 2.SH5001_NORMAL_MODE +* 3.SH5001_ACC_HP_MODE +* 4.SH5001_ACC_LP_MODE +* 5.SH5001_POWERDOWN_MODE +* +* Parameters: powerMode +* SH5001_NORMAL_MODE +* SH5001_ACC_HP_MODE +* SH5001_ACC_LP_MODE +* SH5001_POWERDOWN_MODE +* +* return: SH5001_FALSE or SH5001_TRUE +* +******************************************************************/ +unsigned char SH5001_SwitchPowerMode(unsigned char powerMode) +{ + + int i = 0; + unsigned char reg_addr[SH5001_POWMODE_REG_NUM] = { 0x30, 0x20, 0x2B, 0xBD, 0xD9, 0xD1, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8}; + unsigned char reg_data_normal[SH5001_POWMODE_REG_NUM] = { 0x08, 0x23, 0x00, 0x0C, 0x99, 0x68, 0x00, 0x00, 0x01, 0x50, 0x00}; + unsigned char reg_data_acc_hp[SH5001_POWMODE_REG_NUM] = { 0x08, 0x23, 0x01, 0x0C, 0x98, 0x6B, 0x00, 0x7A, 0xFF, 0xFC, 0x00}; + unsigned char reg_data_acc_lp[SH5001_POWMODE_REG_NUM] = { 0x08, 0xA1, 0x01, 0x0E, 0x98, 0x6B, 0x90, 0xFA, 0xFF, 0xFC, 0x00}; + unsigned char reg_data_powerdown[SH5001_POWMODE_REG_NUM] = { 0x08, 0xA1, 0x01, 0x0E, 0x98, 0x6B, 0xF1, 0xFE, 0xFF, 0xFC, 0xE2}; + unsigned char accODR = SH5001_ACC_ODR_2000HZ; + unsigned char regData = 0; + + if(powerMode > 0x03) + { + return (SH5001_FALSE); + } + + switch(powerMode) + { + case SH5001_NORMAL_MODE: + + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + regData = regData & 0x7F; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF1, 1, &storeAccODR); + for(i = 0; i < SH5001_POWMODE_REG_NUM; i++) + { + SH5001_write(SH5001_ADDRESS, reg_addr[i], 1, ®_data_normal[i]); + } + + SH5001_DriveStart(); + SH5001_ADCReset(); + SH5001_CVAReset(); + delay_ms(100);// or discard 10 + + return (SH5001_TRUE); + + case SH5001_ACC_HP_MODE: + + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + regData = regData | 0x80; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF1, 1, &storeAccODR); + for(i = 0; i < SH5001_POWMODE_REG_NUM; i++) + { + SH5001_write(SH5001_ADDRESS, reg_addr[i], 1, ®_data_acc_hp[i]); + } + + delay_ms(30); // or discard 2 + + return (SH5001_TRUE); + + case SH5001_ACC_LP_MODE: + + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + regData = regData & 0x7F; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + + regData = (storeAccODR & 0xF0) | accODR; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF1, 1, ®Data); + for(i = 0; i < SH5001_POWMODE_REG_NUM; i++) + { + SH5001_write(SH5001_ADDRESS, reg_addr[i], 1, ®_data_acc_lp[i]); + } + + delay_ms(30); // or discard 2 + return (SH5001_TRUE); + + case SH5001_POWERDOWN_MODE: + + for(i = 0; i < SH5001_POWMODE_REG_NUM; i++) + { + SH5001_write(SH5001_ADDRESS, reg_addr[i], 1, ®_data_powerdown[i]); + } + + return (SH5001_TRUE); + + default: + return (SH5001_FALSE); + } +} + +/****************************************************************** +* Description: 1. fast compensate offset +* +* Parameters: SH5001Positon +* SH5001_X_UP +* SH5001_X_DOWN +* SH5001_Y_UP +* SH5001_Y_DOWN +* SH5001_Z_UP +* SH5001_Z_DOWN +* +* return: SH5001_FALSE or SH5001_TRUE +* +******************************************************************/ +void SH5001_FastOffsetComp(unsigned char SH5001Positon) +{ + unsigned char regData = 0; + + switch(SH5001Positon) + { + case SH5001_X_UP: + regData = 0x90U; + break; + case SH5001_X_DOWN: + regData = 0x91U; + break; + case SH5001_Y_UP: + regData = 0x92U; + break; + case SH5001_Y_DOWN: + regData = 0x93U; + break; + case SH5001_Z_UP: + regData = 0x94U; + break; + case SH5001_Z_DOWN: + regData = 0x95U; + break; + default: + regData = 0x94U; + break; + } + +// SH5001_write(SH5001_ADDRESS, SH5001_FAST_COMP, 1, ®Data); +} + + +#ifdef SH5001_ACTIVITY_INT + +void SH5001_Init_Activity_Int(void) +{ + + unsigned char regData = 0; + + SH5001_INT_Config(SH5001_INT0_LEVEL_HIGH, + SH5001_INT_LATCH, //SH5001_INT_NO_LATCH, SH5001_INT_LATCH + SH5001_INT_CLEAR_STATUS, //SH5001_INT_CLEAR_ANY, SH5001_INT_CLEAR_STATUS + 1, + SH5001_INT1_NORMAL, + SH5001_INT0_NORMAL, + SH5001_INT1_OUTPUT, + SH5001_INT0_OUTPUT); + + SH5001_INT_Act_Config(SH5001_ACT_X_INT_EN, + SH5001_ACT_Y_INT_EN, + SH5001_ACT_Z_INT_EN, + 2, + 20, + SH5001_LINK_PRE_STA_NO, + SH5001_ACT_INACT_CLR_STATUS1); + + SH5001_INT_Enable(SH5001_INT_ACT, + SH5001_INT_EN, + SH5001_INT_MAP_INT0); + //TODO + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + regData = regData & 0x7F; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF2, 1, ®Data); + + SH5001_read(SH5001_ADDRESS, 0xBD, 1, ®Data); + regData = (regData & 0x7F); + SH5001_write(SH5001_ADDRESS, 0xBD, 1, ®Data); +} + +#endif + +#ifdef SH5001_DATA_READY_INT +void SH5001_Init_Data_Ready_Int(void) +{ + + unsigned char regData = 0; + + SH5001_INT_Config(SH5001_INT0_LEVEL_HIGH, + SH5001_INT_LATCH, //SH5001_INT_NO_LATCH, SH5001_INT_LATCH + SH5001_INT_CLEAR_STATUS, //SH5001_INT_CLEAR_ANY, SH5001_INT_CLEAR_STATUS + 1, + SH5001_INT1_NORMAL, + SH5001_INT0_NORMAL, + SH5001_INT1_OUTPUT, + SH5001_INT0_OUTPUT); + + SH5001_INT_Enable(SH5001_INT_ACC_READY, //SH5001_INT_GYRO_READY SH5001_INT_ACC_READY + SH5001_INT_EN, + SH5001_INT_MAP_INT0); + +} + +#endif + +/****************************************************************** +* Description: 1. SH5001 initialization FIFO +* 2. INT mode +* 3. Enable ACC_X, ACC_Y, ACC_Z, GYRO_X, GYRO_Y, GYRO_Z +* +* Parameters: void +* +* return: void +* +******************************************************************/ +void SH5001_InitFIFO(void) +{ + + SH5001_INT_Config(SH5001_INT0_LEVEL_HIGH, + SH5001_INT_LATCH, //SH5001_INT_NO_LATCH, SH5001_INT_LATCH + SH5001_INT_CLEAR_STATUS, //SH5001_INT_CLEAR_ANY, SH5001_INT_CLEAR_STATUS + 1, + SH5001_INT1_NORMAL, + SH5001_INT0_NORMAL, + SH5001_INT1_OUTPUT, + SH5001_INT0_OUTPUT); + + SH5001_FIFO_Reset(); + + SH5001_FIFO_Freq_Config(SH5001_FIFO_ACC_DOWNS_DIS, + SH5001_FIFO_FREQ_X1_32, + SH5001_FIFO_GYRO_DOWNS_DIS, + SH5001_FIFO_FREQ_X1_32); + + SH5001_FIFO_Data_Config(SH5001_FIFO_ACC_X_EN + | SH5001_FIFO_ACC_Y_EN + | SH5001_FIFO_ACC_Z_EN + | SH5001_FIFO_GYRO_X_EN + | SH5001_FIFO_GYRO_Y_EN + | SH5001_FIFO_GYRO_Z_EN, + 120); + + SH5001_FIFO_Mode_Set(SH5001_FIFO_MODE_FIFO); + + SH5001_INT_Enable(SH5001_INT_FIFO_WATERMARK, + SH5001_INT_EN, + SH5001_INT_MAP_INT0); + +} + + + +/****************************************************************** +* Description: 1. SH5001 read ACC_X, ACC_Y, ACC_Z, GYRO_X, GYRO_Y, GYRO_Z @FIFO +* 2. clear FIFO Watermark INT +* +* Parameters: void +* +* return: void +* +******************************************************************/ +void SH5001_ReadFIFO(void) +{ + unsigned short fifoEntriesCount = 0; + unsigned char fifoData[SH5001_FIFO_BUFFER] = {0}; + unsigned short i = 0, j = 0, dataGroup = 0; + short accData[3], gyroData[3]; + unsigned char regData = 0; + + // read FIFO entries count + SH5001_FIFO_Read_Status(&fifoEntriesCount); + + dataGroup = (unsigned short)(fifoEntriesCount/SH5001_WATERMARK_DIV); + fifoEntriesCount = dataGroup * SH5001_WATERMARK_DIV; + + SH5001_FIFO_Read_Data(fifoData, fifoEntriesCount); + + printf("fc %d\r\n", fifoEntriesCount); + + for(i = 0; i < dataGroup; i++) + { + accData[0] = ((short)fifoData[j+1] << 8) | fifoData[j]; + accData[1] = ((short)fifoData[j+3] << 8) | fifoData[j+2]; + accData[2] = ((short)fifoData[j+5] << 8) | fifoData[j+4]; + gyroData[0] = ((short)fifoData[j+7] << 8) | fifoData[j+6]; + 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]); + + j = j + SH5001_WATERMARK_DIV; + } + + + // clear INT + // SH5001_INT_Read_Status01(); + + +} + + #define SH5001_REGISTER_SETTING_TOTAL 18 +static int sh5001DumpReg(void) +{ + int i = 0; + int ret = 0; + uint8_t reg = 0; + uint8_t regData = 0; + + //uint8_t SH5001Reg[SH5001_REGISTER_SETTING_TOTAL] = {0x20, 0x21,0x22, 0x23, 0x24, 0x25}; + + //uint8_t SH5001Reg[SH5001_REGISTER_SETTING_TOTAL] = {0x20, 0x21,0x22, 0x23, 0x24, 0x25, 0x40, 0x41, 0x42, 0x43, 0x66}; //FIFO wm int + uint8_t SH5001Reg[SH5001_REGISTER_SETTING_TOTAL] = {0x20, 0x21,0x22, 0x23, 0x24, 0x25,0x40, 0x41, 0x42, 0x43, 0x66, 0x4D, 0x4E, 0x54,0x55, 0x56, 0xBD}; //Activity int + + //uint8_t SH3001Reg[SH3001_REGISTER_SETTING_TOTAL] = {0x28, 0x29, 0x2B, 0x23, 0x26, 0xdd}; //lpf setting + // uint8_t SH3001Reg[SH3001_REGISTER_SETTING_TOTAL] = {0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,0x2A, 0x2B}; + //uint8_t SH3001Reg[SH3001_REGISTER_SETTING_TOTAL] = {0x22, 0x23, 0x24, 0x25, 0x26, 0x35,0x36,0x37, 0x38,0x39}; + //uint8_t ST3001RegData[SH3001_REGISTER_SETTING_TOTAL] = {0x00,0x1F,0x00,0x2B,0x00}; + //uint8_t SH3001INTFIFOReg[SH3001_REGISTER_SETTING_TOTAL] = {0x35, 0x36, 0x37, 0x38, 0x39, 0x40,0x41,0x44, 0x45,0x46, 0x47, 0x4d,0x79,0x7A,0x0F,0x8F,0x9F,0xAF}; + //uint8_t SH3001Reg[SH3001_REGISTER_SETTING_TOTAL] = {0x35, 0x36, 0x37, 0x38, 0x39, 0x40,0x41,0x42, 0x43,0x44, 0x45,0x46, 0x47, 0xFE}; + //uint8_t SH3001Reg[SH3001_REGISTER_SETTING_TOTAL] = {0x20, 0x21, 0x0c, 0x0d}; + + for( i = 0 ; i < SH5001_REGISTER_SETTING_TOTAL ; i++ ) + { + + //read + reg = SH5001Reg[i]; + + ret = SH5001_read(SH5001_ADDRESS, reg, 1, ®Data); + if(ret != 0) + { + printf("Senodia Dump Reg 0x%x read error\r\n", reg); + return -1; + } + + printf("Senodia DR >>>>> 0x%x = 0x%x\r\n", reg, regData); + + } + + + return ret; + +} + +static void SH5001_IMU_Data_Stablize(void) +{ + unsigned char regData = 0; + + //TODO Three times maybe + //acc + SH5001_read(SH5001_ADDRESS, SH5001_ACC_CONF0, 1, ®Data); + regData &= 0xFE; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF0, 1, ®Data); + regData |= 0x1; + SH5001_write(SH5001_ADDRESS, SH5001_ACC_CONF0, 1, ®Data); + + + //gyro + SH5001_read(SH5001_ADDRESS, SH5001_GYRO_CONF0, 1, ®Data); + regData &= 0xFE; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF0, 1, ®Data); + regData |= 0x1; + SH5001_write(SH5001_ADDRESS, SH5001_GYRO_CONF0, 1, ®Data); +} + +static void SH5001_OSC_FREQ(void) +{ + unsigned char regData = 0; + + SH5001_read(SH5001_ADDRESS, 0xDA, 1, ®Data); + if((regData & 0x07) != 0x07) + { + regData |= 0x07; + SH5001_write(SH5001_ADDRESS, 0xDA, 1, ®Data); + } + +} + +#if SENODIA_VDD_3V3 +short v3_acc[3] = {0}; +unsigned char use_otp_comp = 0; + +void SH5001_Get_Otpoffset(short vacc[3]) +{ + unsigned char regData[3]={0}; + unsigned char data = 0; + + //entry otp read mode + data = 0x72; + SH5001_write(SH5001_ADDRESS, 0x02, 1, &data); + + //read otp page + data = 0; + SH5001_read(SH5001_ADDRESS, 0x0, 1, &data); + printf("otp page data:0x%x\n", data); + if(data == 0x70){ + //exit otp mode + data = 0x71; + SH5001_write(SH5001_ADDRESS, 0x03, 1, &data); + + //entry otp page 2 + data = 0x70; + SH5001_write(SH5001_ADDRESS, 0x05, 1, &data); + + //entry otp read mode + data = 0x72; + SH5001_write(SH5001_ADDRESS, 0x02, 1, &data); + + } + //otp read data + SH5001_read(SH5001_ADDRESS, 0x08, 3, regData); + + //exit otp mode + data = 0x71; + SH5001_write(SH5001_ADDRESS, 0x03, 1, &data); + + if(regData[0] == 0x5f && regData[1] == 0x0 && regData[2] == 0x48) + use_otp_comp = 0; + else + use_otp_comp = 1; + printf("use_otp_comp:%d\n", use_otp_comp); + vacc[0] = ((signed char)regData[0]) * 8; + vacc[1] = ((signed char)regData[1]) * 8; + vacc[2] = ((signed char)regData[2]) * 8; + printf("%d %d %d %d %d %d \r\n", regData[0], regData[1], regData[2], vacc[0], vacc[1], vacc[2]); +} +#endif +/****************************************************************** +* Description: SH5001 initialization function +* +* Parameters: void +* +* return: SH5001_TRUE or SH5001_FALSE +* +******************************************************************/ +unsigned char SH5001_init(void) +{ + unsigned char regData = 0; + unsigned char i = 0; + +#if SH5001_SPI_3WIRE_MODE + SH5001_SPI_Config(SH5001_SPI_3_WIRE); +#endif + + // 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); + + // reset internal module, don't modify it + SH5001_ModuleReset(); + + SH5001_OSC_FREQ(); + + #if SH5001_OIS_ENABLE + SH5001_OIS_SPI_Config(SH5001_OIS_SPI_EN); + #endif + + // 500Hz, 16G, cut off Freq(BW)=500*0.25Hz=125Hz, enable filter; + SH5001_Acc_Config(SH5001_ACC_ODR_125HZ, + SH5001_ACC_RANGE_16G, //SH5001_ACC_RANGE_8G SH5001_ACC_RANGE_16G + SH5001_ACC_ODRX040, + SH5001_ACC_FILTER_EN, + SH5001_ACC_BYPASS_EN); + + printf("SH5001 acc config ok\r\n"); + + // 800Hz, X\Y\Z 2000deg/s, cut off Freq(BW)=291Hz, enable filter; + SH5001_Gyro_Config( SH5001_GYRO_ODR_125HZ, + SH5001_GYRO_RANGE_2000, + SH5001_GYRO_ODRX040, + SH5001_GYRO_FILTER_EN, + SH5001_GYRO_BYPASS_EN); + + SH5001_IMU_Data_Stablize(); + + #if SH5001_OIS_ENABLE + SH5001_Acc_OIS_Config(SH5001_ACC_OIS_ODR_1000HZ, + SH5001_ACC_OIS_RANGE_8G, + SH5001_ACC_OIS_ODRX004, + SH5001_ACC_OIS_ENABLE); + + SH5001_Gyro_OIS_Config(SH5001_GYRO_OIS_ODR_8000HZ, + SH5001_GYRO_OIS_RANGE_2000, + SH5001_GYRO_OIS_ODRX004, + SH5001_GYRO_OIS_ENABLE); + #endif + + #if SH5001_TS_ENABLE + SH5001_TimeStamp_Config(SH5001_TS_ODR_1KHZ, SH5001_TS_EN); + #endif + + // temperature ODR is 63Hz, enable temperature measurement + SH5001_Temp_Config(SH5001_TEMP_ODR_63HZ, SH5001_TEMP_EN); + + //sh5001DumpReg(); + #ifdef SH5001_FIFO_WM_INT + SH5001_InitFIFO(); + #endif + + #ifdef SH5001_ACTIVITY_INT + SH5001_Init_Activity_Int(); + #endif + + #ifdef SH5001_DATA_READY_INT + SH5001_Init_Data_Ready_Int(); + #endif + +#if SENODIA_VDD_3V3 + SH5001_Get_Otpoffset(v3_acc); +#endif + //sh5001DumpReg(); + //sh5001DumpRegAll(); + + return SH5001_TRUE; +} + + + +/****************************************************************** +* Description: Read SH5001 gyroscope and accelerometer data +* +* Parameters: accData[3]: acc X,Y,Z; gyroData[3]: gyro X,Y,Z; +* +* return: void +* +******************************************************************/ +void SH5001_GetImuData( short accData[3], short gyroData[3] ) +{ + unsigned char regData[12]={0}; + + SH5001_read(SH5001_ADDRESS, SH5001_ACC_XL, 12, regData); + + accData[0] = ((short)regData[1] << 8) | regData[0]; + accData[1] = ((short)regData[3] << 8) | regData[2]; + accData[2] = ((short)regData[5] << 8) | regData[4]; + + gyroData[0] = ((short)regData[7] << 8) | regData[6]; + gyroData[1] = ((short)regData[9] << 8) | regData[8]; + gyroData[2] = ((short)regData[11] << 8) | regData[10]; + +#if SENODIA_VDD_3V3 + if(use_otp_comp){ + accData[0] -= v3_acc[0]; + accData[1] -= v3_acc[1]; + accData[2] -= v3_acc[2]; + } +#endif + + printf("%d %d %d %d %d %d\r\n", accData[0], accData[1], accData[2], gyroData[0], gyroData[1], gyroData[2]); +} + +void SH5001_OIS_GetTS(int timestamp[1]) +{ + unsigned char regData[3]={0}; + + SH5001_read(SH5001_ADDRESS, 0xE, 3, regData); + + timestamp[0] = ((int)regData[2] << 16) | ((int)regData[1] << 8) | regData[0]; + +} + +#if SH5001_OIS_ENABLE +void SH5001_OIS_GetImuData( short accData[3], short gyroData[3] ) +{ + unsigned char regData[12]={0}; + int i = 0; + + SH5001_OIS_read(SH5001_ADDRESS, SH5001_ACC_XL, 12, regData); + + accData[0] = ((short)regData[1] << 8) | regData[0]; + accData[1] = ((short)regData[3] << 8) | regData[2]; + accData[2] = ((short)regData[5] << 8) | regData[4]; + + gyroData[0] = ((short)regData[7] << 8) | regData[6]; + gyroData[1] = ((short)regData[9] << 8) | regData[8]; + gyroData[2] = ((short)regData[11] << 8) | regData[10]; + + //printf("%d %d %d %d %d %d\r\n", accData[0], accData[1], accData[2], gyroData[0], gyroData[1], gyroData[2]); +} +#endif + +#define SH5001_OFFSET_REG_NUM 13 +void offset_comp_save_reg(float offset[3]) +{ + unsigned char offsetData[SH5001_OFFSET_REG_NUM] = {0}; + + short offset_otp[3] = {0}; + short gain_otp[3] = {0}; + unsigned int range = 1; + + int offset_temp[3] = {0}; + short offset_new[3] = {0}; + unsigned short s_offset_new[3] = {0}; + + unsigned char i; + + + unsigned char offsetRegister[SH5001_OFFSET_REG_NUM] = { 0x8C, 0x8D, 0x8E, 0x8F, 0x98, 0x99, 0x9A, 0x9B, 0xA4, 0xA5 , 0xA6, + 0xA7, 0x24}; + + for(i=0; i> 4; + + if(offsetData[12] != 0) + { + for(i=0; i < offsetData[12] + 7; i++) + { + range = range * 2; + } + } + + #ifdef SH5001_OT_DEBUG + printf("range %d \r\n", range); + #endif + + for(i = 0; i < 3; i++) + { + offset_temp[i] = offset_otp[i] + (int)(offset[i] * ((float)range) / ((float)gain_otp[i])); // + //offset_new[i] = offset_otp[i] + (offset[i] * range / gain_otp[i]); // + } + + if(offset_temp[0] > 32767) + offset_temp[0] = 32767; + else if(offset_temp[0] < -32768) + offset_temp[0] = -32768; + if(offset_temp[1] > 32767) + offset_temp[1] = 32767; + else if(offset_temp[1] < -32768) + offset_temp[1] = -32768; + if(offset_temp[2] > 32767) + offset_temp[2] = 32767; + else if(offset_temp[2] < -32768) + offset_temp[2] = -32768; + + offset_new[0] = (short)offset_temp[0]; + offset_new[1] = (short)offset_temp[1]; + offset_new[2] = (short)offset_temp[2]; + + #ifdef SH5001_OT_DEBUG + printf("offset_new %d %d %d \r\n", offset_new[0], offset_new[1],offset_new[2]); + #endif + + s_offset_new[0] = (unsigned short)offset_new[0]; + s_offset_new[1] = (unsigned short)offset_new[1]; + s_offset_new[2] = (unsigned short)offset_new[2]; + + offsetData[3] = (unsigned char)((s_offset_new[0] & 0xFF00)>>8); + offsetData[7] = (unsigned char)((s_offset_new[1] & 0xFF00)>>8); + offsetData[11] = (unsigned char)((offset_new[2] & 0xFF00)>>8); + offsetData[2] = (unsigned char)((s_offset_new[0] & 0x00FF)); + offsetData[6] = (unsigned char)((s_offset_new[1] & 0x00FF)); + offsetData[10] = (unsigned char)((s_offset_new[2] & 0x00FF)); + + #ifdef SH5001_OT_DEBUG + printf("offsetData %x %x %x %x %x %x\r\n", offsetData[2], offsetData[3],offsetData[6], offsetData[7], offsetData[10], offsetData[11]); + #endif + + SH5001_write(SH5001_ADDRESS, 0x8E, 1, &offsetData[2]); + SH5001_write(SH5001_ADDRESS, 0x8F, 1, &offsetData[3]); + SH5001_write(SH5001_ADDRESS, 0x9A, 1, &offsetData[6]); + SH5001_write(SH5001_ADDRESS, 0x9B, 1, &offsetData[7]); + SH5001_write(SH5001_ADDRESS, 0xA6, 1, &offsetData[10]); + SH5001_write(SH5001_ADDRESS, 0xA7, 1, &offsetData[11]); + + //for test + #if 0 + for(i=0; i> 4; + + #ifdef SH5001_OT_DEBUG + printf("gain_otp %d %d %d \r\n", gain_otp[0], gain_otp[1],gain_otp[2]); + printf("temp_otp %d %d %d \r\n", beta_otp[0], beta_otp[1],beta_otp[2]); + printf("range 0x%x \r\n", tempCompData[9]); + #endif + + if(tempCompData[9] != 0) + { + for(i=0; i < tempCompData[9] + 14; i++) + { + range = range * 2; + } + } + + #ifdef SH5001_OT_DEBUG + printf("range222 %d \r\n", range); + #endif + //TODO + for(i = 0; i < 3; i++) + { + s_beta_temp[i] = beta_otp[i] - (int)(k[i] * ((float)range) / ((float)gain_otp[i])); + #ifdef SH5001_OT_DEBUG + printf("beta_ 111 %f %d\r\n", k[i] * range / gain_otp[i], (int)(k[i] * range / gain_otp[i])); + #endif + } + + if(s_beta_temp[0] > 127) + s_beta_temp[0] = 127; + else if(s_beta_temp[0] < -128) + s_beta_temp[0] = -128; + if(s_beta_temp[1] > 127) + s_beta_temp[1] = 127; + else if(s_beta_temp[1] < -128) + s_beta_temp[1] = -128; + if(s_beta_temp[2] > 127) + s_beta_temp[2] = 127; + else if(s_beta_temp[2] < -128) + s_beta_temp[2] = -128; + + s_beta_new[0] = (char)s_beta_temp[0]; + s_beta_new[1] = (char)s_beta_temp[1]; + s_beta_new[2] = (char)s_beta_temp[2]; + + beta_new[0] = (unsigned char)s_beta_new[0]; + beta_new[1] = (unsigned char)s_beta_new[1]; + beta_new[2] = (unsigned char)s_beta_new[2]; + + #ifdef SH5001_OT_DEBUG + printf("s_beta_new %d %d %d \r\n", s_beta_new[0], s_beta_new[1],s_beta_new[2]); + printf("beta_new %x %x %x \r\n", beta_new[0], beta_new[1],beta_new[2]); + #endif + + SH5001_write(SH5001_ADDRESS, 0x92, 1, &beta_new[0]); + SH5001_write(SH5001_ADDRESS, 0x9e, 1, &beta_new[1]); + SH5001_write(SH5001_ADDRESS, 0xAA, 1, &beta_new[2]); +} + +#define SH5001_ACC_REG_NUM 4 +void acc_temp_comp_save_reg(float k[3]) +{ + unsigned char tempCompData[SH5001_ACC_REG_NUM] = {0}; + signed char beta_otp[3] = {0}; + short gain_otp[3] = {0}; + unsigned int range = 1; + float rangek = 1; + unsigned char beta_new[3] = {0}; + signed char s_beta_new[3] = {0}; + int s_beta_temp[3] = {0}; + unsigned char i; + unsigned char tempCompRegister[SH5001_ACC_REG_NUM] = {0x71, 0x7c, 0x88, 0x21}; + for(i=0; i> 4; + #ifdef SH5001_OT_DEBUG + printf("temp_otp %d %d %d \r\n", beta_otp[0], beta_otp[1],beta_otp[2]); + printf("range 0x%x \r\n", tempCompData[3]); + #endif + if(tempCompData[3] != 0) + { + for(i=0; i < 6 - tempCompData[3]; i++) + { + range = range * 2; + } + } + for(i=0; i<3; i++) + { + k[i] = k[i] * range * 2.048 / 14; + } + #ifdef SH5001_OT_DEBUG + printf("k %f %f %f \r\n", k[0], k[1],k[2]); + #endif + if(tempCompData[3] != 0) + { + for(i=0; i < tempCompData[3] + 1; i++) + { + rangek = rangek * 2; + } + } + #ifdef SH5001_OT_DEBUG + printf("range222 %f \r\n", rangek); + #endif + for(i = 0; i < 3; i++) + { + s_beta_temp[i] = beta_otp[i] - (int)(k[i] * rangek); + #ifdef SH5001_OT_DEBUG + printf("beta_111 %f %d\r\n", k[i] * rangek , (int)(k[i] * rangek)); + #endif + } + if(s_beta_temp[0] > 127) + s_beta_temp[0] = 127; + else if(s_beta_temp[0] < -128) + s_beta_temp[0] = -128; + if(s_beta_temp[1] > 127) + s_beta_temp[1] = 127; + else if(s_beta_temp[1] < -128) + s_beta_temp[1] = -128; + if(s_beta_temp[2] > 127) + s_beta_temp[2] = 127; + else if(s_beta_temp[2] < -128) + s_beta_temp[2] = -128; + s_beta_new[0] = (char)s_beta_temp[0]; + s_beta_new[1] = (char)s_beta_temp[1]; + s_beta_new[2] = (char)s_beta_temp[2]; + beta_new[0] = (unsigned char)s_beta_new[0]; + beta_new[1] = (unsigned char)s_beta_new[1]; + beta_new[2] = (unsigned char)s_beta_new[2]; + #ifdef SH5001_OT_DEBUG + printf("s_beta_new %d %d %d \r\n", s_beta_new[0], s_beta_new[1],s_beta_new[2]); + printf("beta_new %x %x %x \r\n", beta_new[0], beta_new[1],beta_new[2]); + #endif + SH5001_write(SH5001_ADDRESS, 0x71, 1, &beta_new[0]); + SH5001_write(SH5001_ADDRESS, 0x7c, 1, &beta_new[1]); + SH5001_write(SH5001_ADDRESS, 0x88, 1, &beta_new[2]); +} + +#define SH5001_QUAD_REG_NUM 10 +#define SH5001_QUAD_DEBUG + +void sh5001_gyro_trim_quad(unsigned char quadval[6]) +{ + short S_Gyro_Quad[3] = {0}; + short C_Gyro_Quad[3] = {0}; + unsigned char quadData[SH5001_QUAD_REG_NUM] = {0}; + int sumGyroData[3] = {0}; + short avgGyroData[3] = {0}; + short GyroData[3] = {0}; + unsigned char temp[6]= {0}; + unsigned char i; + double Slope[3] = {560, 560, 560}; + + unsigned char quadRegister[SH5001_QUAD_REG_NUM] = {0x8B, 0x97, 0xA3, 0xD9, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC}; + unsigned char RegWrt_1[SH5001_QUAD_REG_NUM] = {0xFF, 0xFF, 0xFF, 0x91, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + for(i=0; i0; i--) + { + delay_ms(1); + + SH5001_read(SH5001_ADDRESS, 0x06, 6, temp); + GyroData[0]=((short)(temp[1]<<8))|temp[0]; + GyroData[1]=((short)(temp[3]<<8))|temp[2]; + GyroData[2]=((short)(temp[5]<<8))|temp[4]; + + sumGyroData[0] += GyroData[0]; + sumGyroData[1] += GyroData[1]; + sumGyroData[2] += GyroData[2]; + + #ifdef SH5001_QUAD_DEBUG + printf("sumGyroData %d %d %d\r\n",GyroData[0], GyroData[1], GyroData[2]); + #endif + } + + for(i = 0; i < 3; i++) + { + avgGyroData[i] = sumGyroData[i] / 20; + } + + #ifdef SH5001_QUAD_DEBUG + printf("avgGyroData %d %d %d\r\n",avgGyroData[0], avgGyroData[1], avgGyroData[2]); + #endif + + for (i = 0; i < 3; i++) + { + S_Gyro_Quad[i] = (quadData[i + 7] & 0x04) >> 2; + C_Gyro_Quad[i] = quadData[i + 4] + (quadData[i + 7] & 0x03) * 256; + + #ifdef SH5001_QUAD_DEBUG + printf("raw S_Gyro_Quad[%d] : %d C_Gyro_Quad[%d]: %d \r\n",i, S_Gyro_Quad[i], i, C_Gyro_Quad[i]); + #endif + + C_Gyro_Quad[i] = (S_Gyro_Quad[i] == 0) ? C_Gyro_Quad[i]: (C_Gyro_Quad[i] * (-1) - 1); + C_Gyro_Quad[i] = (int)(C_Gyro_Quad[i] - avgGyroData[i] / Slope[i]); + + S_Gyro_Quad[i] = C_Gyro_Quad[i] >= 0 ? 0 : 1; + C_Gyro_Quad[i] = C_Gyro_Quad[i] >= 0 ? C_Gyro_Quad[i]: (C_Gyro_Quad[i] * (-1) - 1); + + RegWrt_1[i + 4] = C_Gyro_Quad[i] & 0x00FF; + RegWrt_1[i + 7] = (quadData[i + 7] & 0xF8) + S_Gyro_Quad[i] * 4 + ((C_Gyro_Quad[i] & 0x0300) >> 8); + + } + #ifdef SH5001_QUAD_DEBUG + printf("mod S_Gyro_Quad %d %d %d C_Gyro_Quad %d %d %d RegWrt_1 %d %d %d %d %d %d\r\n",S_Gyro_Quad[0], + S_Gyro_Quad[1],S_Gyro_Quad[2],C_Gyro_Quad[0],C_Gyro_Quad[1],C_Gyro_Quad[2], RegWrt_1[4], RegWrt_1[5], RegWrt_1[6], RegWrt_1[7], RegWrt_1[8], RegWrt_1[9]); + #endif + + + //TODO Save Reg + for(i=0; i<6; i++) { + SH5001_write(SH5001_ADDRESS, quadRegister[i + 4], 1, &RegWrt_1[i + 4]); + quadval[i] = RegWrt_1[i + 4]; + } + + for(i=0; i<4; i++) + SH5001_write(SH5001_ADDRESS, quadRegister[i], 1, &quadData[i]); +} + + +/****************************************************************** +* Description: SH5001 Acc self-test function +* +* Parameters: void +* +* return: SH3001_TRUE or SH3001_FALSE +* +******************************************************************/ + +#define SH5001_ACC_SELFTEST_REGNUM 7 +#define SH5001_ACC_SELFTEST_DEBUG + +unsigned char SH5001_AccSelfTest(void) +{ + unsigned char regAddr[SH5001_ACC_SELFTEST_REGNUM] = {0x21, 0x69, 0x74, 0x80, 0xB9, 0xBA, 0xBB}; + unsigned char regInit[SH5001_ACC_SELFTEST_REGNUM] = {0x30, 0xFF, 0xFF, 0xFF, 0x40, 0x45, 0x45}; + unsigned char regBack[SH5001_ACC_SELFTEST_REGNUM] = {0}; + unsigned char accTemp[6] = {0}; + signed int accSum[3] = {0}; + signed short accAvg1[3] = {0}, accAvg2[3] = {0}; + unsigned char i = 0; + signed short accRange[3] = {0}; + + + for(i=0; i 3900) && (accRange[0] < 9200)) + && ((accRange[1] > 4100) && (accRange[1] < 9600)) + && ((accRange[2] > 4500) && (accRange[2] < 10900))) + { + return(SH5001_TRUE); + } + else + { + return(SH5001_FALSE); + } +} + + +/****************************************************************** +* Description: SH5001 Gyro self-test function +* +* Parameters: void +* +* return: SH3001_TRUE or SH3001_FALSE +* +******************************************************************/ + +#define SH5001_GYRO_SELFTEST_REGNUM 11 +#define SH5001_GYRO_SELFTEST_DEBUG + +unsigned char SH5001_GyroSelfTest(void) +{ + unsigned char regAddr[SH5001_GYRO_SELFTEST_REGNUM] = {0x24, 0x8B, 0x97, 0xA3, 0xCA, 0xCB, 0xCC, 0xCD,\ + 0xCE, 0xCF, 0xD9}; + unsigned char regInit[SH5001_GYRO_SELFTEST_REGNUM] = {0x60, 0xFF, 0xFF, 0xFF, 0x60, 0x60, 0x60, 0x02,\ + 0x02, 0x02, 0x91}; + unsigned char regBack[SH5001_GYRO_SELFTEST_REGNUM] = {0}; + unsigned char gyroTemp[6] = {0}; + signed int gyroSum[3] = {0}; + signed short gyroAvg1[3] = {0}, gyroAvg2[3] = {0}; + unsigned char i = 0; + signed short gyroRange[3] = {0}; + + for(i=0; i -4500) && (gyroRange[0] < 7100)) + && ((gyroRange[1] > -6900) && (gyroRange[1] < 8200)) + && ((gyroRange[2] > -9300) && (gyroRange[2] < 4600))) + { + return(SH5001_TRUE); + } + else + { + return(SH5001_FALSE); + } +} + +void sh5001_adc_phase(void) +{ + unsigned char addr = 0xD0; + unsigned char regData; + + SH5001_read(SH5001_ADDRESS, addr, 1, ®Data); + //printf("0xD0 = 0x%x\r\n", regData); + + if((regData & 0x02) == 0x02) + regData &= 0xFD; + else + regData |= 0x02; + SH5001_write(SH5001_ADDRESS, addr, 1, ®Data); + //printf("0xD0 = 0x%x\r\n", regData); + +} + +#define SH5001_GYRO_ADC_S1_REGNUM 5 +#define SH5001_GYRO_ADC_S2_REGNUM 1 +//#define SH5001_GYRO_ADC__DEBUG +int adc_count = 0; +int err_count = 0; +void SH5001_Get_Adc_Polarity(short gyroPolarity[3]) +{ + unsigned char regAddrS1[SH5001_GYRO_ADC_S1_REGNUM] = {0xA3, 0xC6, 0xCC, 0xCF, 0xD0}; + unsigned char regInitS1[SH5001_GYRO_ADC_S1_REGNUM] = {0xFF, 0x00, 0x69, 0x1A, 0x0A}; + unsigned char regAddrS2[SH5001_GYRO_ADC_S2_REGNUM] = {0xD0}; + unsigned char regInitS2[SH5001_GYRO_ADC_S2_REGNUM] = {0x08}; + unsigned char regBackS1[SH5001_GYRO_ADC_S1_REGNUM] = {0}; + unsigned char gyroTemp[6] = {0}; + signed int gyroSum[3] = {0}; + signed short gyroAvg1[3] = {0}, gyroAvg2[3] = {0}; + unsigned char i = 0; + //signed short gyroPolarity[3] = {0}; + + for(i=0; iwear_status) { case WEAR_STA_DROP: - printf("WEAR_STA_DROP ps : %d , env : %d , ret_bio_algo : %d , alg_wear_status : %d , gsnesor_axis_diff : %d , BIO_HOLD_DROP_FLAG : %d\n",ps,env,ret_bio_algo,alg_wear_status,gsnesor_axis_diff,BIO_HOLD_DROP_FLAG); + // printf("WEAR_STA_DROP ps : %d , env : %d , ret_bio_algo : %d , alg_wear_status : %d , gsnesor_axis_diff : %d , BIO_HOLD_DROP_FLAG : %d\n",ps,env,ret_bio_algo,alg_wear_status,gsnesor_axis_diff,BIO_HOLD_DROP_FLAG); if ((ps >= VC9202_CFG_WEAR_PARAM_PS) && (env <= VC9202_CFG_WEAR_PARAM_ENVMIN) && (VC9202_BIO_STA_HOLD == ret_bio_algo) && (WEAR_STA_HOLD == alg_wear_status) && (1 == gsnesor_axis_diff) && (BIO_HOLD_DROP_FLAG == 2)) { @@ -292,7 +292,7 @@ static VC9202WearChangeTypeDef vc9202_drv_wear_status_identify(VC9202WearInfoTyp break; case WEAR_STA_HOLD: - printf("WEAR_STA_HOLD ps : %d , env : %d , ret_bio_algo : %d , alg_wear_status : %d , BIO_HOLD_DROP_FLAG : %d\n",ps,env,ret_bio_algo,alg_wear_status,BIO_HOLD_DROP_FLAG); + // printf("WEAR_STA_HOLD ps : %d , env : %d , ret_bio_algo : %d , alg_wear_status : %d , BIO_HOLD_DROP_FLAG : %d\n",ps,env,ret_bio_algo,alg_wear_status,BIO_HOLD_DROP_FLAG); if ((ps < VC9202_CFG_WEAR_PARAM_PS) || (env > VC9202_CFG_WEAR_PARAM_ENVMIN) || (VC9202_BIO_STA_DROP == ret_bio_algo) || (WEAR_STA_DROP == alg_wear_status) || (BIO_HOLD_DROP_FLAG == 1)) { if ((WEAR_STA_DROP == alg_wear_status) || (ret_bio_algo == VC9202_BIO_STA_DROP)) @@ -868,24 +868,24 @@ static VC9202DrvRetTypeDef vc9202_drv_status_event_verify(unsigned char status, /* over load, max current */ if (event & VC9202_EVENT_OV_MARK) { - printf("event & VC9202_EVENT_OV_MARK \n"); + // printf("event & VC9202_EVENT_OV_MARK \n"); vc_ret |= vc9202_drv_adjust_over_load_configure(&dev9202_adjust[index_slot], index_slot, status); } /* env, max res */ if (event & VC9202_EVENT_ENV_MARK) { - printf("event & VC9202_EVENT_ENV_MARK \n"); + // printf("event & VC9202_EVENT_ENV_MARK \n"); vc_ret |= vc9202_drv_adjust_env_configure(&dev9202_adjust[index_slot], index_slot); } /* ppg interruput */ if (event & VC9202_EVENT_PPG_MARK) { vc_ret |= vc9202_drv_adjust_ppg_configure(&dev9202_adjust[index_slot], index_slot, dev9202_info.enfifo_div, dev9202_info.slot_number); - printf("event & VC9202_EVENT_PPG_MARK vc_ret : 0x%x\n",vc_ret); + // printf("event & VC9202_EVENT_PPG_MARK vc_ret : 0x%x\n",vc_ret); } else { - printf("event : 0x%x \n",event); + // printf("event : 0x%x \n",event); dev9202_adjust[index].info.dir = AGC_DIR_NULL; dev9202_adjust[index].info.last_dir = AGC_DIR_NULL; } @@ -1253,14 +1253,14 @@ void vc9202_drv_system_param_init(unsigned char fifo_div, unsigned char enslot) bio_result = VC9202_BIO_STA_NONE; } #else - printf("fifo_div : %d, enslot : %d \n", fifo_div, enslot ); - printf("f_BIOedgeinit(%d, %d) \n", VC9202_CFG_WEAR_PARAM_BIOIN, VC9202_CFG_WEAR_PARAM_PSIN ); + // printf("fifo_div : %d, enslot : %d \n", fifo_div, enslot ); + // printf("f_BIOedgeinit(%d, %d) \n", VC9202_CFG_WEAR_PARAM_BIOIN, VC9202_CFG_WEAR_PARAM_PSIN ); if (VC9202_BIO_STA_NONE == bio_result) { uint32_t irq_sts = osal_irq_lock(); f_BIOInit(VC9202_CFG_WEAR_PARAM_BIOIN, VC9202_CFG_WEAR_PARAM_PSIN); osal_irq_restore(irq_sts); - printf(" VC9202_BIO_STA_DROP == bio_result f_BIOedgeinit(%d, %d) \n", VC9202_CFG_WEAR_PARAM_BIOIN, VC9202_CFG_WEAR_PARAM_PSIN ); + // printf(" VC9202_BIO_STA_DROP == bio_result f_BIOedgeinit(%d, %d) \n", VC9202_CFG_WEAR_PARAM_BIOIN, VC9202_CFG_WEAR_PARAM_PSIN ); } #endif } @@ -1278,7 +1278,7 @@ unsigned char vc9202_drv_get_chip_id(void) { unsigned char chip_id = 0; usr_iic_read_bytes(0x00, &chip_id, 1); - printf("vc9202 chip id : 0x%x\n",chip_id); + // printf("vc9202 chip id : 0x%x\n",chip_id); return chip_id; } @@ -1601,17 +1601,17 @@ unsigned char vc9202_drv_get_sampling_data(SamplingDataTypeDef *pSamplingData, u usr_iic_read_bytes(0x01, &dev9202_info.work_status, 1); usr_iic_read_bytes(0x02, (unsigned char *)&dev9202_info.int_event, 1); - printf("dev9202_info.work_status : 0x%x ,dev9202_info.int_event : 0x%x\n",dev9202_info.work_status,dev9202_info.int_event); + // printf("dev9202_info.work_status : 0x%x ,dev9202_info.int_event : 0x%x\n",dev9202_info.work_status,dev9202_info.int_event); if (dev9202_info.work_status & 0xf8) /* 防止insample和conflict时数据错误,则不对设备进行处理 */ { - printf("dev9202_info.work_status & 0xf8 \n"); + // printf("dev9202_info.work_status & 0xf8 \n"); dev9202_info.int_event = 0; /* 异常时,避免执行佩戴检测 */ return 1; } if (-1 == vc9202_drv_check_running_gaptime()) { - printf("-1 == vc9202_drv_check_running_gaptime() \n"); + // printf("-1 == vc9202_drv_check_running_gaptime() \n"); dev9202_info.int_event = 0; /* 异常时,避免执行佩戴检测 */ return 1; } diff --git a/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_hal.c b/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_hal.c index 907333c35..5e2d2341f 100644 --- a/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_hal.c +++ b/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_hal.c @@ -111,13 +111,13 @@ void ppg_send_cmd_to_vc9202_driver(char* mode, uint8_t enable) #endif } else if (strcmp(mode, "leaklight") == 0) { #ifdef PPG_VC9202 - md = WORK_MODE_NONE; + md = WORK_MODE_FACTORY; #elif defined PPG_HX3695 md = FT_LEAK_LIGHT_MODE; #endif } else if (strcmp(mode, "graycard") == 0) { #ifdef PPG_VC9202 - md = WORK_MODE_NONE; + md = WORK_MODE_FACTORY; #elif defined PPG_HX3695 md = FT_GRAY_CARD_MODE; #endif diff --git a/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_user.c b/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_user.c index 5d5fbbc10..9cd777c2d 100644 --- a/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_user.c +++ b/code/sdk/zhihui/drivers/ppg/vc9202/src/vc9202_user.c @@ -34,6 +34,17 @@ extern void vc9202_debug_send_spo2_data( SamplingDataTypeDef* presult ,GsensorTy #define CHIP_I2C_ADDRESS 0x33 #define VC9202_I2C_BUS I2C_BUS_2 +static uint32_t gr_ppg_data = 0; +static uint32_t red_ppg_data = 0; +static uint32_t ir_ppg_data = 0; + +static uint32_t leaklight_led_cur = 0; //最大电流,黑箱通道2 +static uint32_t leaklight_apre_val = 0;//绿灯强度,漏光模式通道1 +static uint32_t leaklight_aps_val = 0;//红外强度,灰卡模式通道3 + +static uint32_t graycard_apre_val = 0;//绿灯强度,漏光模式通道1 +static uint32_t graycard_aps_val = 0;//红外强度,灰卡模式通道3 + /** * @brief iic多字节写 * @param @@ -84,8 +95,10 @@ unsigned int usr_get_clock_ticks(void) */ void vc9202_usr_get_chip_id( unsigned char *pchip_id, unsigned char *pvers_id ) { + tyhx_poweron(); usr_iic_read_bytes( 0x00, pchip_id, 1 ); usr_iic_read_bytes( 0x40, pvers_id, 1 ); + tyhx_poweroff(); } /** @@ -326,6 +339,7 @@ static short int alg_calculate_hr_handler( short int last_hr_val, SamplingDataTy alg_i_data.axes.y = pgsensor->gsensor_y_axis[i]; alg_i_data.axes.z = pgsensor->gsensor_z_axis[i]; alg_i_data.ppgSample = pdata->ppg_data[i]; + gr_ppg_data = (uint32_t)pdata->ppg_data[i]; printf("pdata->ppg_data[%d] : %d \n",i,pdata->ppg_data[i]); // printf(" i : alg_i_data.axes.x : %d ,alg_i_data.axes.y : %d , alg_i_data.axes.z : %d \n",i,alg_i_data.axes.x,alg_i_data.axes.y,alg_i_data.axes.z); Algo_Input( &alg_i_data, 1000/25, hr_alg_mode, 1, 1 ); @@ -360,6 +374,9 @@ static unsigned char alg_calculate_spo2_handler( unsigned char last_spo2_val , S { ir_PPG = (float)pdata->ppg_data[i*2]; red_PPG = (float)pdata->ppg_data[i*2+1]; + red_ppg_data = (uint32_t)red_PPG; + ir_ppg_data = (uint32_t)ir_PPG; + // printf("ir_PPG : %.3f , red_PPG : %.3f \n",ir_PPG,red_PPG); // ret_spo2 = vcSpo2Calculate( red_PPG, ir_PPG ); ret_spo2 = spo2Algo(red_PPG,ir_PPG,1); sport_flag = vcSportMotionCalculate( pgsensor->gsensor_x_axis[i], pgsensor->gsensor_y_axis[i], pgsensor->gsensor_z_axis[i] ); @@ -371,19 +388,50 @@ static unsigned char alg_calculate_spo2_handler( unsigned char last_spo2_val , S return spo2_value; } -static void factory_test_function( SamplingDataTypeDef *pdata ) +static void factory_test_function( SamplingDataTypeDef *pdata ,uint16_t size) { - // /* 最大电流 */ - // unsigned char ledMaxCur = pdata->led_cur[0]; //最大电流,黑箱通道2 - // /* 获取测试数据 */ - // unsigned int pre0 = pdata->apre_val[0];//绿灯强度,漏光模式通道1 - // unsigned int ps = pdata->aps_val;//红外强度,灰卡模式通道3 - // /* 温度 */ - // signed short int temp0 = pdata->temp_val_i; - // signed short int temp1 = pdata->temp_val_o; - // /* compare abs(bio0,bio1) */ - // unsigned short int bio0 = pdata->bio_val_o; - // unsigned short int bio1 = pdata->bio_val_o; + /* 最大电流 */ + unsigned char ledMaxCur = pdata->led_cur[0]; //最大电流,黑箱通道2 + /* 获取测试数据 */ + unsigned int pre0 = pdata->apre_val[0];//绿灯强度,漏光模式通道1 + unsigned int ps = pdata->aps_val;//红外强度,灰卡模式通道3 + /* 温度 */ + signed short int temp0 = pdata->temp_val_i; + signed short int temp1 = pdata->temp_val_o; + /* compare abs(bio0,bio1) */ + unsigned short int bio0 = pdata->bio_val_o; + unsigned short int bio1 = pdata->bio_val_o; + + // uint8_t leak_light_pass = 0; + // uint8_t gray_card_pass = 0; + // 黑箱测试: + printf("pdata->led_cur[0] : %d , pdata->apre_val[0] : %d , pdata->aps_val : %d \n",pdata->led_cur[0],pdata->apre_val[0],pdata->aps_val); + leaklight_led_cur = pdata->led_cur[0]; + leaklight_apre_val = pdata->apre_val[0]; + leaklight_aps_val = pdata->aps_val; + // if(pdata->led_cur[0] >= 100 && pdata->apre_val[0] <= 64 && pdata->aps_val <= 64) + // { + // leak_light_pass = 1; + // } + // else + // { + // leak_light_pass = 0; + // } + + // 灰卡测试: + printf("pdata->apre_val[0] : %d , pdata->aps_val : %d\n",pdata->apre_val[0],pdata->aps_val); + graycard_apre_val = pdata->apre_val[0]; + graycard_aps_val = pdata->aps_val; + + // if(pdata->apre_val[0] >= 210 && pdata->aps_val >= 210) + // { + // gray_card_pass = 1; + // } + // else + // { + // gray_card_pass = 0; + // } + } static void fpc_test_function(SamplingDataTypeDef *pdata) { @@ -433,15 +481,15 @@ void vc9202_usr_interrupt_handler( AlgoSportMode hr_alg_mode, unsigned char spo2 unsigned char gsensor_size = 0; unsigned char ppg_size = 0; VC9202DrvRetTypeDef ret = vc9202_drv_get_sampling_data( &data, &ppg_size ); - printf("ppg_size : %d work_mode : %d ret : %d\n",ppg_size,work_mode,ret); + // printf("ppg_size : %d work_mode : %d ret : %d\n",ppg_size,work_mode,ret); switch ( work_mode ) { case WORK_MODE_HR: - printf("11111 vc9202_usr_get_int_reason : 0x%x \n",vc9202_usr_get_int_reason()); + // printf("11111 vc9202_usr_get_int_reason : 0x%x \n",vc9202_usr_get_int_reason()); if( vc9202_usr_get_int_reason()&(VC9202_EVENT_PS_MARK|VC9202_EVENT_FIFO_MARK) ) { wear_status = vc9202_usr_get_wear_status(); - printf("11111 wear_status : %d \n",wear_status); + // printf("11111 wear_status : %d \n",wear_status); get_gsensor_data(&gsensor_data, &gsensor_size, ppg_size); if( gsensor_size>0 ) { @@ -450,7 +498,7 @@ void vc9202_usr_interrupt_handler( AlgoSportMode hr_alg_mode, unsigned char spo2 if(wear_status) { vc9202_alg_results.hr_rate = alg_calculate_hr_handler( vc9202_alg_results.hr_rate, &data, ppg_size, &gsensor_data, hr_alg_mode ); - printf("vc9202_alg_results.hr_rate : %d \n",vc9202_alg_results.hr_rate); + // printf("vc9202_alg_results.hr_rate : %d \n",vc9202_alg_results.hr_rate); vc9202_debug_send_heart_rate_data( &data, &gsensor_data, vc9202_alg_results.hr_rate, hr_alg_mode, ppg_size ); } else @@ -469,7 +517,7 @@ void vc9202_usr_interrupt_handler( AlgoSportMode hr_alg_mode, unsigned char spo2 if(wear_status) { vc9202_alg_results.spo2_val = alg_calculate_spo2_handler( vc9202_alg_results.spo2_val, &data, ppg_size/2, &gsensor_data, spo2_alg_mode ); - printf("vc9202_alg_results.spo2_val : %d \n",vc9202_alg_results.spo2_val); + // printf("vc9202_alg_results.spo2_val : %d \n",vc9202_alg_results.spo2_val); vc9202_debug_send_spo2_data( &data, &gsensor_data, vc9202_alg_results.spo2_val, ppg_size/2 ); } else @@ -529,16 +577,16 @@ void vc9202_usr_interrupt_handler( AlgoSportMode hr_alg_mode, unsigned char spo2 /* 根据佩戴状态添加对应的处理代码 */ if(wear_status) { - printf("111 wear \n"); + // printf("111 wear \n"); } else { - printf("222 nowear \n"); + // printf("222 nowear \n"); } } break; case WORK_MODE_FACTORY: - factory_test_function( &data ); + factory_test_function( &data ,ppg_size); break; case WORK_MODE_FPC_TEST: fpc_test_function(&data); @@ -549,6 +597,41 @@ void vc9202_usr_interrupt_handler( AlgoSportMode hr_alg_mode, unsigned char spo2 } } +uint32_t vc9202_get_hr_ppg_data(void) +{ + uint32_t ppg_data = gr_ppg_data; + gr_ppg_data = 0; + return ppg_data; +} + +void vc9202_get_spo2_ppg_data(uint32_t *ir_data,uint32_t *red_data) +{ + *ir_data = ir_ppg_data; + *red_data = red_ppg_data; + red_ppg_data = 0; + ir_ppg_data = 0; +} + +void vc9202_get_leaklight_data(uint32_t *led_cur,uint32_t *apre_val,uint32_t *aps_val) +{ + *led_cur = leaklight_led_cur; + *apre_val = leaklight_apre_val; + *aps_val = leaklight_aps_val; + + leaklight_led_cur = 0; + leaklight_apre_val = 0; + leaklight_aps_val = 0; +} + +void vc9202_get_graycard_data(uint32_t *apre_val,uint32_t *aps_val) +{ + *apre_val = graycard_apre_val; + *aps_val = graycard_aps_val; + + graycard_apre_val = 0; + graycard_aps_val = 0; +} + #if 0 int main(int argc, char *argv[]) { diff --git a/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt b/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt index 153476ef0..3c8a50168 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt +++ b/code/sdk/zhihui/drivers/rotary_encoder/CMakeLists.txt @@ -34,6 +34,7 @@ elseif("ROTARYENCODER_U8" IN_LIST DEFINES) set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crown/crown.c ${CMAKE_CURRENT_SOURCE_DIR}/crown/crown_at_cmd.c + ${CMAKE_CURRENT_SOURCE_DIR}/crown/crown_hal.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/crown @@ -41,6 +42,20 @@ set(PUBLIC_HEADER set(PUBLIC_DEFINES SUPPORT_AT_CROWN ) + +elseif("ROTARYENCODER_MIXO" IN_LIST DEFINES) +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 +) +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/mixo +) +set(PUBLIC_DEFINES +SUPPORT_AT_MIXO +) + endif() set(SOURCES diff --git a/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.c b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.c index 9b2804e0a..a087b32d6 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-31 10:20:16 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-01-02 20:18:27 + * @LastEditTime: 2025-01-09 15:39:10 * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.c * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -21,7 +21,9 @@ #include "pm_veto.h" #include "crown.h" #include "cmsis_os2.h" +#include "crown_hal.h" +static int16_t crown_diff = 0; static int16_t crown_result = 0; static uint8_t stand_still = 1; //静止标志 1 静止,0 转动 static uint8_t direction = 0; //方向标志 1 顺时针,2 逆时针 @@ -30,6 +32,10 @@ bool crown_timer_running = false; //ots定时器是否运行标志 static osTimerId_t g_crown_timer = NULL; +static pin_t his_pin = 0; + +extern encoder_callback g_encoder_callback; + void crown_int_callback(pin_t pin, uintptr_t param) { uapi_gpio_clear_interrupt(pin); @@ -38,21 +44,21 @@ void crown_int_callback(pin_t pin, uintptr_t param) { if (uapi_gpio_get_val(PIN_TYHX_SCLK)) { - direction = 1; // 顺时针旋转 - crown_result++; + direction = 2; // 顺时针旋转 + crown_diff--; } } else if (pin == PIN_TYHX_SCLK) { if (uapi_gpio_get_val(PIN_TYHX_SDIO)) { - direction = 2; // 逆时针旋转 - crown_result--; + direction = 1; // 逆时针旋转 + crown_diff++; } } - PRINT("pin : %d , direction : %d , crown_result : %d \n",pin,direction,crown_result); -} + PRINT("pin : %d , direction : %d , crown_diff : %d \n",pin,direction,crown_diff); +} int16_t crown_get_stand_still(void) { @@ -62,7 +68,7 @@ int16_t crown_get_stand_still(void) * 获取表冠的数据结果接口函数 * @param NULL */ -int16_t crown_get_crown_result(void) +int16_t crown_get_result(void) { int16_t resulttemp; resulttemp=crown_result; @@ -72,8 +78,10 @@ int16_t crown_get_crown_result(void) void crown_start(void) { - if(crown_timer_running == false) + if(crown_timer_running == false && g_crown_timer) { + uapi_pin_set_ie(PIN_TYHX_SDIO,HAL_PIO_IE_ENBALE); + uapi_pin_set_ie(PIN_TYHX_SCLK,HAL_PIO_IE_ENBALE); // app_timer_start(g_hx3509_timer, APP_TIMER_TICKS(50), NULL);//定义为50ms定时器间隔 osTimerStart(g_crown_timer,50); crown_timer_running = true; @@ -82,8 +90,10 @@ void crown_start(void) void crown_stop(void) { - if(crown_timer_running == true) + if(crown_timer_running == true && g_crown_timer) { + uapi_pin_set_ie(PIN_TYHX_SDIO,HAL_PIO_IE_DISABLE); + uapi_pin_set_ie(PIN_TYHX_SCLK,HAL_PIO_IE_DISABLE); osTimerStop(g_crown_timer); crown_timer_running = false; } @@ -91,8 +101,22 @@ void crown_stop(void) void crown_timer_handler(void) { - PRINT("crown_result : %d \n",crown_result); - crown_result = 0; + if(!crown_diff) + { + stand_still = 1; + } + else + { + stand_still = 0; + crown_result = crown_diff * 30; + crown_diff = 0; + // PRINT("crown_result : %d direction : %d\n",crown_result,direction); + if (g_encoder_callback != NULL) + g_encoder_callback(); + else + PRINT("no call back crown_result = %d\r\n",crown_result); + } + } @@ -100,6 +124,9 @@ void crown_init(void) { if(!g_crown_timer) g_crown_timer = osTimerNew((osTimerFunc_t)crown_timer_handler, osTimerPeriodic, NULL, NULL); + + if(!g_crown_timer) + PRINT("g_crown_timer init failed \n"); } // #endif diff --git a/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.h b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.h index dce7d2bee..63b9f555a 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.h +++ b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-31 10:20:24 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-01-02 19:57:42 + * @LastEditTime: 2025-01-08 15:13:01 * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/crown/crown.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ diff --git a/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.c b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.c new file mode 100644 index 000000000..323d7f2e7 --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.c @@ -0,0 +1,138 @@ +#include "at_cmd_api.h" +#include "pm_control.h" +#include "crown.h" +#include "crown_hal.h" + +#include "rotary_encoder_def.h" +#include "i2c.h" +#include "debug_print.h" +#include "hal_i2c.h" + +static uint8_t g_crown_test_started = 0; +encoder_callback g_encoder_callback = NULL; +uint32_t rotary_crown_start(void) +{ + if (g_crown_test_started == 1) + { + re_print("SKIP crowntest start, already started\r\n"); + return 0; + } + crown_init(); + crown_start(); + g_crown_test_started = 1; + return ERRCODE_SUCC; +} +uint32_t rotary_crown_stop(void) +{ + if (g_crown_test_started == 0) + { + re_print("SKIP crowntest stop, already stopped\r\n"); + return 0; + } + crown_stop(); + g_crown_test_started = 0 ; + return ERRCODE_SUCC; +} + +static ext_errno crown_encoder_init(void *attr) +{ + re_print("crown_encoder_init\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno crown_encoder_deinit(void) +{ + re_print("crown_encoder_deinit\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno crown_encoder_get_encoderinfo(uint8_t *data, uint8_t data_len) +{ + + if (data_len != sizeof(re_input_event_info)) + { + re_print("data_len != sizeof(re_input_event_info) \n"); + return EXT_ERR_NOT_SUPPORT; + } + + re_input_event_info *encoder_info = (re_input_event_info*)data; + int16_t diff = crown_get_result(); + int16_t stand_still = crown_get_stand_still(); + // re_print("crown_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("crown_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 crown_encoder_suspend(void) +{ + re_print("crown_encoder_suspend\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno crown_encoder_resume(void) +{ + re_print("crown_encoder_resume\r\n"); + crown_init(); + crown_start(); + return EXT_ERR_SUCCESS; +} +static ext_errno crown_encoder_sleep(void) +{ + re_print("crown_encoder_sleep\r\n"); + crown_stop(); + return EXT_ERR_SUCCESS; +} +static ext_errno crown_encoder_reset(void) +{ + re_print("crown_encoder_reset\r\n"); + return EXT_ERR_SUCCESS; +} +static ext_errno crown_encoder_bus_init(void *private_data) +{ + return EXT_ERR_SUCCESS; +} +static ext_errno crown_register_callback(void *peri_data, encoder_callback func) +{ + re_print("crown_register_callback\r\n"); + g_encoder_callback = func; + return EXT_ERR_SUCCESS; +} +static ext_errno crown_unregister_callback(void *peri_data) +{ + re_print("crown_unregister_callback\r\n"); + g_encoder_callback = NULL; + return EXT_ERR_SUCCESS; +} + +encoder_peripheral_api g_crown_api = { + .encoder_init = crown_encoder_init, + .encoder_deinit = crown_encoder_deinit, + .encoder_get_encoderinfo = crown_encoder_get_encoderinfo, + .encoder_suspend = crown_encoder_suspend, + .encoder_resume = crown_encoder_resume, + .encoder_sleep = crown_encoder_sleep, + .encoder_reset = crown_encoder_reset, + .encoder_bus_init = crown_encoder_bus_init, + .register_callback = crown_register_callback, + .unregister_callback = crown_unregister_callback, +}; + + +void *rotary_encoder_get_crown_api(void) +{ + return ((void *)&g_crown_api); +} + +void *rotary_encoder_get_crown_peri_attr(void) +{ + return ((void *)NULL); +} \ No newline at end of file diff --git a/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.h b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.h new file mode 100644 index 000000000..28297585c --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_hal.h @@ -0,0 +1,40 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-01-07 16:44:07 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-01-07 17:01:25 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_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 CROWN_HAL_H +#define CROWN_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_crown_api(void); +void *rotary_encoder_get_crown_peri_attr(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.c b/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.c index 40964636a..18a0955d2 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.c @@ -62,7 +62,7 @@ static int16_t crown_result = 0; static int16_t stand_still = 1; //静止标志 1 静止,0 转动 /*----------------------以下为定时函数相关定义 建立/启动/停止定时器//定时中断处理-------------------------------*/ -int16_t get_stand_still(void) +int16_t hx3507_get_stand_still(void) { return stand_still; } @@ -594,7 +594,7 @@ void report_zero_data_for_start_stop_flag(void) * 获取表冠的数据结果接口函数 * @param NULL */ -int16_t get_crown_result(void) +int16_t hx3507_get_crown_result(void) { int16_t resulttemp; resulttemp=crown_result; diff --git a/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.h b/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.h index 565d54d02..145a54407 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.h +++ b/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-23 14:24:09 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-01-07 17:04:23 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /** * Copyright (c) 2014 - 2023, 南京天易合芯电子有限公司 * @@ -85,9 +93,9 @@ void crown_com_resync(void); //把读出的数据转换为大概角度函数 void put_crown_result(int16_t x); -int16_t get_stand_still(void); +int16_t hx3507_get_stand_still(void); void report_zero_data_for_start_stop_flag(void); //把角度结果上报的函数 -int16_t get_crown_result(void); +int16_t hx3507_get_crown_result(void); #endif //_TYHX_CROWN_CUSTOM_H_ diff --git a/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507_hal.c b/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507_hal.c index 3bfc6a29e..3513d81ea 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507_hal.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507_hal.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-12-23 14:24:09 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-12-30 17:28:09 + * @LastEditTime: 2025-01-09 18:35:13 * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/hx3507/hx3507_hal.c * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -62,8 +62,8 @@ static ext_errno hx3507_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 = get_crown_result(); - int16_t stand_still = get_stand_still(); + int16_t diff = hx3507_get_crown_result(); + int16_t stand_still = hx3507_get_stand_still(); // re_print("hx3507_encoder_get_encoderinfo diff %d stand_still %d\n",diff,stand_still); if (stand_still == 1 ) { 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 new file mode 100644 index 000000000..b81485df0 --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.c @@ -0,0 +1,103 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-12-18 10:23:22 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-01-04 11:21:49 + * @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 + */ + +// #include "mixo.h" + + +#include "at_cmd_api.h" +#include "pm_control.h" +#include "debug_print.h" +#include "mixo_ots_driver.h" +#include "custom_utils.h" + + +#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) +#define MIXO_MAX_ARGC 8 +#define MIXO_MAX_ARGV_LEN 64 + +#define MIXO_SUCCESS 0 +#define MIXO_FAILED (-1) + +static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen, + uint8_t argv[MIXO_MAX_ARGC][MIXO_MAX_ARGV_LEN], uint32_t* argc) +{ + uint32_t pos = 0; + *argc = 0; + + for (uint32_t i = 0; i < paraLen; i++) { + if ((para[i] == ' ' || para[i] == '\n') && pos != 0) { + argv[*argc][pos] = '\0'; + *argc += 1; + pos = 0; + if (*argc >= MIXO_MAX_ARGC) { + return MIXO_FAILED; + } + } else { + argv[*argc][pos] = para[i]; + pos++; + if (pos >= MIXO_MAX_ARGV_LEN) { + return MIXO_FAILED; + } + } + } + if (pos != 0) { + *argc += 1; + } + + return MIXO_SUCCESS; +} + +static uint8_t g_mixo_test_started = 0; +static uint32_t mixo_test(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[MIXO_MAX_ARGC][MIXO_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != MIXO_SUCCESS) { + PRINT("MIXOTEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 1) { + PRINT("MIXOTEST ATCMD Set Parameter Failed argc %d\n",argc); + return ERRCODE_FAIL; + } + uint8_t start = (uint8_t)atoi((char*)argv[0]); + if (start == 1) + { + // if (g_mixo_test_started == 1) + // { + // PRINT("SKIP mixotest start, already started\r\n"); + // return 0; + // } + mixo_ots_init(); + // mixo_start(); + g_mixo_test_started = 1; + }else if (start == 2){ + if (g_mixo_test_started == 0) + { + PRINT("SKIP mixotest stop, already stopped\r\n"); + return 0; + } + // mixo_stop(); + g_mixo_test_started = 0 ; + } + return ERRCODE_SUCC; +} +static const at_cmd_table_t g_mixo_cmd[] = { + { (char *)"AT^MIXOTEST", mixo_test, (char *)"1" }, +}; + +at_cmd_table_t *get_mixo_cmd_table(uint32_t *cmd_count) +{ + *cmd_count = ARRAY_COUNT(g_mixo_cmd); + return (at_cmd_table_t *)g_mixo_cmd; +} diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.h b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.h new file mode 100644 index 000000000..e8824453b --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_at_cmd.h @@ -0,0 +1,40 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-01-02 19:52:36 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-01-04 11:27:51 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/crown/crown_at_cmd.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_AT_PROCESS_H +#define MIXO_AT_PROCESS_H + +#include +#include +#include "errcode.h" +#include "soc_osal.h" +#include "at_cmd_api.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +at_cmd_table_t *get_mixo_cmd_table(uint32_t *cmd_count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.c b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.c new file mode 100644 index 000000000..60782603f --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.c @@ -0,0 +1,62 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-01-04 10:53:54 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-01-04 16:38:46 + * @FilePath: /sdk615/code/sdk/zhihui/drivers/rotary_encoder/mixo/src/mixo_ots_access.c + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/* + * Copyright (c) 2022 MixoSense Technology Ltd . + * + * All rights are reserved. + * Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Any use is subject to an appropriate license granted by MixoSense Technology + * Ltd. + * + */ + +/*----------------------------------------------------------------------------- + * HEADER FILES + *---------------------------------------------------------------------------*/ +#include "mixo_ots_access.h" +#include "custom_utils.h" + + +static uint8_t slave_addr = 0x74; + +#define MIXO_OTS_I2C_BUS I2C_BUS_2 + +void mixo_ots_set_slave_id(uint8_t slave_id) +{ + slave_addr = slave_id; +} +int mixo_ots_reg_read(uint8_t regAddr, uint8_t* regData) +{ + *regData = 0x00; // 清空数据 + // printf("<-%02X,%02X,%02X\r\n",slave_addr,regAddr,*regData); + // return mixo_gpio_i2c_write_read(slave_addr, ®Addr, 1, regData, 1); + return custom_i2c_read_regs(slave_addr, regAddr, 1, regData, 1,MIXO_OTS_I2C_BUS); +} + +int mixo_ots_reg_consecutive_read(uint8_t regStartAddr,int len,uint8_t* regData) +{ + int rc = 0; + // rc = mixo_gpio_i2c_write_read(slave_addr, ®StartAddr, 1, regData, len); + rc = custom_i2c_read_regs(slave_addr, regStartAddr, 1, regData, len,MIXO_OTS_I2C_BUS); + // for(int i=0;i%02X,%02X,%02X\r\n",slave_addr,regAddr,regData); + // return mixo_gpio_i2c_write_read(slave_addr, tmp, 2, NULL, 0); + return custom_i2c_write_reg(slave_addr, regAddr, 1, ®Data, 1,MIXO_OTS_I2C_BUS); +} + diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.h b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.h new file mode 100644 index 000000000..4c2e504d7 --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_access.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 MixoSense Technology Ltd . + * + * All rights are reserved. + * Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Any use is subject to an appropriate license granted by MixoSense Technology + * Ltd. + * + */ + +#ifndef _MXS_REG_ACCESS_H_ +#define _MXS_REG_ACCESS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*----------------------------------------------------------------------------- + * HEADER FILES + *---------------------------------------------------------------------------*/ +#include +#include +#include + +/*----------------------------------------------------------------------------- + * MACRO DEFINITION + *---------------------------------------------------------------------------*/ +#ifdef _WIN32 +#ifdef MXS_DLL_EXPORTS +#define MXS_API __declspec(dllexport) +#else +#define MXS_API +#endif +#else +#define MXS_API +#endif + +/*----------------------------------------------------------------------------- + * FUNCTIONS DEFINITION + *---------------------------------------------------------------------------*/ + +/** + * @brief mxs配置I2C从设备地址 + * + * @param {uint8_t} slave_id + * + * @return {*} + */ +void mixo_ots_set_slave_id(uint8_t slave_id); + +/** + * @brief mxs寄存器写入接口 + * + * @param {uint8_t} regAddr + * @param {uint8_t} regData + * + * @return {*} + */ +int mixo_ots_reg_write(uint8_t regAddr, uint8_t regData); + +/** + * @brief mxs寄存器读取接口 + * + * @param {uint8_t} regAddr + * @param {uint8_t} *regData + * + * @return {*} + */ +int mixo_ots_reg_read(uint8_t regAddr, uint8_t* regData); +int mixo_ots_reg_consecutive_read(uint8_t regStartAddr, + int len, + uint8_t* regData); + +#ifdef __cplusplus +} +#endif + +#endif //_MXS_REG_ACCESS_H_ 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 new file mode 100644 index 000000000..21e6ed824 --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c @@ -0,0 +1,285 @@ +#include "mixo_ots_driver.h" + +#include +#include + +#include "mixo_ots_access.h" +#include "cmsis_os2.h" + +#ifndef ABS +#define ABS(x) ((x) > 0 ? (x) : -(x)) +#endif + +// macro definitions about reigster data +#define REG_PROTECT_ID_HIGH 0x58 +#define REG_PROTECT_ID_LOW 0x5B + +static int dx_sum = 0; + +static bool ots_timer_running = false; //ots定时器是否运行标志 + +static osTimerId_t g_ots_timer = NULL; + + +static void ots_timer_callback(void) +{ + uint8_t mot_status = 0x00; + mixo_ots_get_mot_status(&mot_status); + if ((mot_status & 0x80) == 0x80) + { + // Get raw datas + raw_data_t raw_data; + mixo_ots_get_raw_data(&raw_data); + dx_sum += raw_data.dx; + + // Output raw data + // printf("%ld,%d,%d,%d,%d\r\n", timestamp, 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; + } +} + +void mixo_ots_stop(void) +{ + if(ots_timer_running == true && g_ots_timer) + { + osTimerStop(g_ots_timer); + ots_timer_running = false; + } +} + +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数据 + * @param[in] original_dx 低8bit的dx数据 + * @param[in] original_dy 低8bit的dy数据 + * @param[in] high_bit 高4bit的dx/dy数据 + * @param[out] dx 合成后的dx数据 + * @param[out] dx 合成后的dy数据 + * */ +static void data_synthesis(uint8_t original_dx, + uint8_t original_dy, + uint8_t high_bit, + int16_t* dx, + int16_t* dy) +{ + // move high 4 bits to bit 11 ~ bit 8 + int16_t dx_high = (high_bit << 4) & 0x0F00; + int16_t dy_high = (high_bit << 8) & 0x0F00; + + // sign extension + if (dx_high & 0x0800) + { + dx_high |= 0xF000; + } + if (dy_high & 0x0800) + { + dy_high |= 0xF000; + } + + // move low 8 bits to bit 7 ~ bit 0 + *dx = dx_high | (int16_t)original_dx; + *dy = dy_high | (int16_t)original_dy; + + // overflow of 12-bit data + *dx = (*dx == 2048) ? 0 : *dx; + *dy = (*dy == 2048) ? 0 : *dy; +} + +int mixo_ots_get_mot_status(uint8_t* mot_status) +{ + int ret = 0; + uint8_t tmp_mot_status = 0x00; + ret = mixo_ots_reg_read(0x02, &tmp_mot_status); // get MOTION STATUS + if (ret != 0) goto Exit; + *mot_status = tmp_mot_status; + +Exit: + return ret; +} + +int mixo_ots_get_raw_data(raw_data_t* raw_data) +{ + int ret = 0; + uint8_t tmp = 0x00; + + uint8_t tmp_dx = 0x00; + uint8_t tmp_dy = 0x00; + uint8_t tmp_dx_dy_hight = 0x00; + + if (raw_data == NULL) + { + printf("null `raw_data`!"); + ret = -1; + goto Exit; + } + + ret = mixo_ots_reg_read(0x12, &tmp_dx_dy_hight); // get DELTA XY HIGH + if (ret != 0) goto Exit; + ret = mixo_ots_reg_read(0x03, &tmp_dx); // get DELTA X + if (ret != 0) goto Exit; + ret = mixo_ots_reg_read(0x04, &tmp_dy); // get DELTA Y + if (ret != 0) goto Exit; + + data_synthesis( + tmp_dx, tmp_dy, tmp_dx_dy_hight, &(raw_data->dx), &(raw_data->dy)); + + // If overflowed, clear out the data + if ((ABS(raw_data->dx) == 2047) || (ABS(raw_data->dy) == 2047)) + { + printf("dy/dx overflowed."); + mixo_ots_reg_read(0x02, &tmp); + + mixo_ots_reg_read(0x02, &tmp); + } + +Exit: + return ret; +} + +/* 强制清除MOT的中断信号 */ +void mixo_ots_forced_clear_int(void) +{ + uint8_t tmp = 0x00; + mixo_ots_reg_read(0x02, &tmp); + mixo_ots_reg_read(0x02, &tmp); +} + +/* 进入/退出Suspend模式 */ +void mixo_ots_enter_suspend_mode(uint8_t true_or_false) +{ + uint8_t tmp = 0; + // 将数据从寄存器中读出后进行位操作,再重新写回 + if (true_or_false) + { + // bit 3 写 1, 进入Suspend + mixo_ots_reg_read(0x06, &tmp); + mixo_ots_reg_write(0x06, (tmp | 0x08)); + } + else + { + // bit 3 写 0, 退出Suspend + mixo_ots_reg_read(0x06, &tmp); + mixo_ots_reg_write(0x06, (tmp & 0xF7)); + } +} + + +int callisto_2x_init(void) +{ + int ret = 0; + int read_id_ok = 0; + uint8_t id_high = 0x00; + uint8_t id_low = 0x00; + uint8_t tmp_read = 0x00; + uint8_t sensor_option = 0x04; // sensor_option default is 0x04 + + printf("CONFIG_CALLISTO_2X\n"); + mixo_ots_reg_write(0x09, 0x5A); // write_protect, WO, Disable write protect + mixo_ots_reg_write(0x3C, 0xAC); // bank_switch, WO, Banck switch + mixo_ots_reg_write(0x09, 0xA5); // write_protect, WO, Disable write protect + mixo_ots_reg_write(0x6D, 0x39); // read_protect, WO, Disable read protect + mixo_ots_reg_read(0x00, &id_high); // Read chip-id high byte + mixo_ots_reg_read(0x01, &id_low); // Read chip-id low byte + if (id_high == REG_PROTECT_ID_HIGH && id_low == REG_PROTECT_ID_LOW) + { + read_id_ok = 1; + } + + if (read_id_ok) + { + mixo_ots_reg_write(0x19, + sensor_option); // sensor_option default is 0x04, WO, Enable 12bit mode; Disable x-y swap + mixo_ots_reg_write(0x3E, 0x73); // comm_mode, WO, Switch to LED CC mode, and bypass AVDD + mixo_ots_reg_write(0x48, 0x2F); // led_current, WO, Control LDP driven current + mixo_ots_reg_write(0x1F, 0xFE); // led_current, WO, Control LDP driven current + mixo_ots_reg_write(0x73, 0x08); // 2a3_motion, WO, To be compatible with 2A3 module + mixo_ots_reg_write(0x68, 0x67); // col_counter, WO, Adjust the reference voltage for the Bandgap output; Adjust + // the output voltage of the 1.8V in sleep mode + mixo_ots_reg_write(0x7D, 0x60); // trb_osch, WO, Adjust the output frequency of OSCH + mixo_ots_reg_write(0x60, 0x00); // col_bias_and_output_drive, WO, Adjust the magnitude of the bias current in + // the sensor column; Adjust the sensor output drive strength + + // TO DO, if need calibration + } + + if (read_id_ok) + { + mixo_ots_reg_write(0x0D, 0x20); // If cpi value is not assigned, use default value + mixo_ots_reg_write(0x0E, 0x20); // If cpi value is not assigned, use default value + + /** + * Enable 12bit mode Read the original value + * If swap_xy is true, swap dx and dy + * If inv_x is true, invert dx's output + * If inv_y is true, invert dy's output + */ + mixo_ots_reg_read(0x19, &tmp_read); + if (tmp_read != sensor_option) + { + printf("sensor_option init failed!(The expected %02X, and the actual %02X)\r\n", sensor_option, tmp_read); + } + + ret = 0; + } + else + { + ret = -1; + printf("callisto_2x init failed!\r\n"); + } + + return ret; +} + + + +int mixo_ots_init(void) +{ + int rc = 0; + uint8_t HardWareId = 0; + + mixo_ots_reg_read(0x1B, &HardWareId); + printf("Address: %x, Data: %x\r\n", 0x1B, HardWareId); + + switch (HardWareId) + { + case 0xA1: + rc = callisto_2x_init(); + break; + case 0xB1: + rc = callisto_2x_init(); + break; + case 0xC1: + rc = callisto_2x_init(); + break; + default: + printf("OTS Sensor Not Support!\n"); + break; + } + + if(rc == 0) + { + printf("mixo_ots_init succed !!! \n"); + } + else + { + printf("mixo_ots_init failed !!! \n"); + } + return rc; +} + 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 new file mode 100644 index 000000000..5093bb2ee --- /dev/null +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 MixoSense Technology Ltd . + * + * All rights are reserved. + * Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Any use is subject to an appropriate license granted by MixoSense Technology + * Ltd. + * + */ + +#ifndef _MXS_DRIVER_H_ +#define _MXS_DRIVER_H_ + +#include + +typedef struct +{ + int16_t dx; + int16_t dy; +} raw_data_t; + +int mixo_ots_init(void); +int mixo_ots_get_mot_status(uint8_t* mot_status); +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); + +#endif //_MXS_DRIVER_H_ 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 bc963102f..7cb61bcc9 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c @@ -16,6 +16,14 @@ #ifdef ROTARYENCODER_HX3507 #include "hx3507_hal.h" #endif + +#ifdef ROTARYENCODER_HX3509 +#include "hx3509_hal.h" +#endif + +#ifdef ROTARYENCODER_U8 +#include "crown_hal.h" +#endif // #if defined(TPTYPE_TMA525B) // #include "tma525b_drv1.h" // #include "tma525b_ctrl.h" @@ -420,6 +428,9 @@ uint32_t re_init(void) #elif defined ROTARYENCODER_HX3509 g_encoder_drv.private_data = rotary_encoder_get_hx3509_peri_attr(); g_encoder_drv.encoder_api = rotary_encoder_get_hx3509_api(); +#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(); #endif g_encoder_drv.ops = &g_re_status_ops; redd = rotary_encoder_get_driver_data(); @@ -462,6 +473,8 @@ void rotary_encoder_suspend(void) encoder_ptr = rotary_encoder_get_hx3507_api(); #elif defined ROTARYENCODER_HX3509 encoder_ptr = rotary_encoder_get_hx3509_api(); +#elif defined ROTARYENCODER_U8 + encoder_ptr = rotary_encoder_get_crown_api(); #endif if(encoder_ptr == NULL) return; @@ -477,6 +490,8 @@ void rotary_encoder_resume(void) encoder_ptr = (encoder_peripheral_api*)rotary_encoder_get_hx3507_api(); #elif defined ROTARYENCODER_HX3509 encoder_ptr = (encoder_peripheral_api*)rotary_encoder_get_hx3509_api(); +#elif defined ROTARYENCODER_U8 + encoder_ptr = (encoder_peripheral_api*)rotary_encoder_get_crown_api(); #endif if(encoder_ptr == NULL) return; diff --git a/code/sdk/zhihui/drivers/slip/cat1Service/cat1_ctl.cpp b/code/sdk/zhihui/drivers/slip/cat1Service/cat1_ctl.cpp index 51597f32d..cc4bc6c0b 100644 --- a/code/sdk/zhihui/drivers/slip/cat1Service/cat1_ctl.cpp +++ b/code/sdk/zhihui/drivers/slip/cat1Service/cat1_ctl.cpp @@ -31,8 +31,11 @@ extern "C" { uint32_t uapi_cat1_bat_on(uint32_t pwron) { -#if defined(BOARD_L22) || defined(BOARD_W9) +#if defined(BOARD_L22) pin_t bat_en_pin = S_AGPIO_L14; +#elif defined(BOARD_W9) + pin_t bat_en_pin = S_AGPIO_L17; + if( pwron == 0) { uapi_gpio_set_dir(bat_en_pin, GPIO_DIRECTION_OUTPUT); diff --git a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.c index bef190ae5..a590391c7 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: 2024-12-31 15:39:53 + * @LastEditTime: 2025-01-09 16:57:54 * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c * @Description: * @@ -54,6 +54,14 @@ #ifdef FD230 #include "PhoneServiceC.h" #endif +#ifdef ENABLE_LQBP002TA +#include "lqbp_service.h" +#include "lqbp002ta.h" +#endif +#ifdef ENABLE_HP4507 +#include "hp4570.h" +#endif + #pragma pack(1) typedef struct factorytest_cmd_header_t { @@ -81,7 +89,8 @@ static osTimerId_t g_ble_acc_timer = NULL; static int aging_time = 0; static uint8_t pwr_button_result = 0; -static uint8_t func_button_result = 1; +static uint8_t func_button_result = 0; +static uint8_t func2_button_result = 0; errcode_t factorytest_protocol_replymsg(uint8_t mode, uint8_t submode,uint8_t testitem, uint8_t *input_data,uint16_t input_len) @@ -142,6 +151,19 @@ static void func_button_callback_long_press_2s(void) func_button_result = 2; } +static void func2_button_callback_press(void) +{ + func2_button_result = 1; +} +static void func2_button_callback_click_2(void) +{ + func2_button_result = 3; +} +static void func2_button_callback_long_press_2s(void) +{ + func2_button_result = 2; +} + void ble_vibrator_check_timer_callback(void) { // uapi_vibrationModeSet(3); @@ -415,7 +437,7 @@ void aging_task(void) PRINT("gsensor失败次数 : %d \r\n",aging_t.gsensor_error); /*********************磁力计 老化测试*****************************/ - float fAzimuth,fPitch,fRoll; + float fAzimuth = 0; total_time = 2 * 60; enter_time = 0; @@ -430,7 +452,7 @@ void aging_task(void) return; } uapi_get_timestampe_ss(¤t_time); - mmc5603_getdata(&fAzimuth,&fPitch,&fRoll); + mmc5603_getdata(&fAzimuth); if(fAzimuth < 0) { aging_t.mag_error++; @@ -510,21 +532,21 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t factorytest_mode_flag = 1; +#ifdef FD230 ChargerEventPublish(TOPIC_EVENT_CHARGE_UNPLUG,0); //进入产测模式 关闭充电弹窗 uapi_dev_runtime_set_factory_test_status(1); //设置产测模式runtime svr_ble_adv_factory_test_start_param(); //设置蓝牙广播 避免出现连接问题 - +#endif factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, BLE_TEST_CMD_COMMON_SUB_MODE_SWITCH_MODE, 0x01, &send_data, 1); - #ifdef FD230 +#ifdef FD230 uapi_hfp_connect_(); LOS_Msleep(500); uapi_a2dp_snk_connect_(); - #endif - +#endif } else if (testitem == 0x02) { @@ -782,9 +804,11 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //打开马达 uint8_t send_data = 0x00; - g_ble_vibrator_timer = osTimerNew((osTimerFunc_t)ble_vibrator_check_timer_callback, osTimerPeriodic, NULL, NULL); + if(g_ble_vibrator_timer == NULL) + g_ble_vibrator_timer = osTimerNew((osTimerFunc_t)ble_vibrator_check_timer_callback, osTimerPeriodic, NULL, NULL); - osTimerStart(g_ble_vibrator_timer,500); + if(g_ble_vibrator_timer) + osTimerStart(g_ble_vibrator_timer,500); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, @@ -797,8 +821,9 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //关闭马达 uint8_t send_data = 0x00; - osTimerStop(g_ble_vibrator_timer); - osTimerDelete(g_ble_vibrator_timer); + if(g_ble_vibrator_timer) + osTimerStop(g_ble_vibrator_timer); + // osTimerDelete(g_ble_vibrator_timer); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, @@ -825,7 +850,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint if(g_ble_vibrator_timer != NULL) { osTimerStop(g_ble_vibrator_timer); - osTimerDelete(g_ble_vibrator_timer); + // osTimerDelete(g_ble_vibrator_timer); } factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, @@ -841,6 +866,9 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { uint8_t send_data = 0; + pwr_button_result = 0; + func_button_result = 0; + func2_button_result = 0; factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_KEY, 0x01, @@ -923,6 +951,34 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint &send_data, 1); } + else if(testitem == 0x08) + { + //开启功能键2测试 + uint8_t send_data = 0; + + uapi_button_unregister_event_cb(BUTTON2_CLICKUP_2); + uapi_button_unregister_event_cb(BUTTON2_LONGPRESS_2S); + + uapi_button_register_event_cb(func2_button_callback_press, BUTTON2_CLICKUP); + uapi_button_register_event_cb(func2_button_callback_click_2, BUTTON2_CLICKUP_2); + uapi_button_register_event_cb(func2_button_callback_long_press_2s, BUTTON2_LONGPRESS_2S); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_KEY, + 0x08, + &send_data, + 1); + } else if(testitem == 0x09) + { + //查询功能键2测试结果 + uint8_t send_data = func2_button_result; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_KEY, + 0x09, + &send_data, + 1); + } break; @@ -1377,6 +1433,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //获取 ppg_id uint8_t ppg_id; uapi_ppg_get_id(&ppg_id); + PRINT("0x%x\n",ppg_id); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, 0x01, @@ -1396,7 +1453,11 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint } else if(testitem == 0x03) { //打开心率检测 +#ifdef PPG_HX3695 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_SINGLE_CHECK_MODE_TEST); +#elif defined PPG_VC9202 + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_PPG_TEST); +#endif LOS_Msleep(500); uint8_t databuf[4] = {0}; #ifdef PPG_HX3695 @@ -1405,7 +1466,15 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint databuf[1] = (uint8_t)((ft_result.gr_data_final & 0x00FF0000) >> 16); databuf[2] = (uint8_t)((ft_result.gr_data_final & 0x0000FF00) >> 8); databuf[3] = (uint8_t)((ft_result.gr_data_final & 0x000000FF) >> 0); +#elif defined PPG_VC9202 + uint32_t 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); + databuf[2] = (uint8_t)((ppg_data & 0x0000FF00) >> 8); + databuf[3] = (uint8_t)((ppg_data & 0x000000FF) >> 0); #endif + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST); PRINT("%2X %2X %2X %2X \r\n",databuf[0],databuf[1],databuf[2],databuf[3]); @@ -1419,32 +1488,51 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint } else if(testitem == 0x04) { //打开血氧检测 +#ifdef PPG_HX3695 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_SINGLE_CHECK_MODE_TEST); +#elif defined PPG_VC9202 + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST); +#endif LOS_Msleep(500); - uint8_t databuf[4] = {0}; + uint8_t databuf[8] = {0}; #ifdef PPG_HX3695 FT_RESULTS_t ft_result = hx3695_factroy_test(SINGLE_CHECK_TEST); databuf[0] = (uint8_t)((ft_result.red_data_final & 0xFF000000) >> 24); databuf[1] = (uint8_t)((ft_result.red_data_final & 0x00FF0000) >> 16); databuf[2] = (uint8_t)((ft_result.red_data_final & 0x0000FF00) >> 8); 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; + vc9202_get_spo2_ppg_data(&ir_data,&red_data); + PRINT("ir_data : %d ,red_data : %d \n",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); + databuf[3] = (uint8_t)((ir_data & 0x000000FF) >> 0); + + databuf[4] = (uint8_t)((red_data & 0xFF000000) >> 24); + databuf[5] = (uint8_t)((red_data & 0x00FF0000) >> 16); + databuf[6] = (uint8_t)((red_data & 0x0000FF00) >> 8); + databuf[7] = (uint8_t)((red_data & 0x000000FF) >> 0); #endif send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST); PRINT("%2X %2X %2X %2X \r\n",databuf[0],databuf[1],databuf[2],databuf[3]); + PRINT("%2X %2X %2X %2X \r\n",databuf[4],databuf[5],databuf[6],databuf[7]); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, 0x04, databuf, - 4); + sizeof(databuf)); } else if(testitem == 0x05) { //灰卡测试 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_GRAYCARD_TEST); LOS_Msleep(500); - uint8_t databuf[12] = {0}; #ifdef PPG_HX3695 + uint8_t databuf[12] = {0}; FT_RESULTS_t ft_result = hx3695_factroy_test(GRAY_CARD_TEST); databuf[0] = (uint8_t)((ft_result.gr_data_final & 0xFF000000) >> 24); databuf[1] = (uint8_t)((ft_result.gr_data_final & 0x00FF0000) >> 16); @@ -1460,26 +1548,47 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint databuf[9] = (uint8_t)((ft_result.ir_data_final & 0x00FF0000) >> 16); databuf[10] = (uint8_t)((ft_result.ir_data_final & 0x0000FF00) >> 8); databuf[11] = (uint8_t)((ft_result.ir_data_final & 0x000000FF) >> 0); -#endif - send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST); - PRINT("%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\r\n", - databuf[0],databuf[1],databuf[2],databuf[3], - databuf[4],databuf[5],databuf[6],databuf[7], - databuf[8],databuf[9],databuf[10],databuf[11] - ); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, + 0x05, + databuf, + 12); +#elif defined PPG_VC9202 + uint8_t databuf[8] = {0}; + uint32_t apre_val = 0; + uint32_t aps_val = 9; + vc9202_get_graycard_data(&apre_val,&aps_val); + PRINT("apre_val : %d ,aps_val : %d \n",apre_val,aps_val); + databuf[0] = (uint8_t)((apre_val & 0xFF000000) >> 24); + databuf[1] = (uint8_t)((apre_val & 0x00FF0000) >> 16); + databuf[2] = (uint8_t)((apre_val & 0x0000FF00) >> 8); + databuf[3] = (uint8_t)((apre_val & 0x000000FF) >> 0); + + databuf[4] = (uint8_t)((aps_val & 0xFF000000) >> 24); + databuf[5] = (uint8_t)((aps_val & 0x00FF0000) >> 16); + databuf[6] = (uint8_t)((aps_val & 0x0000FF00) >> 8); + databuf[7] = (uint8_t)((aps_val & 0x000000FF) >> 0); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, 0x05, databuf, - 12); + 8); +#endif + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST); + // PRINT("%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\r\n", + // databuf[0],databuf[1],databuf[2],databuf[3], + // databuf[4],databuf[5],databuf[6],databuf[7], + // databuf[8],databuf[9],databuf[10],databuf[11] + // ); + } else if(testitem == 0x06) { //漏光测试 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_DO_LEAKLIGHT_TEST); - LOS_Msleep(200); + LOS_Msleep(500); uint8_t databuf[12] = {0}; #ifdef PPG_HX3695 FT_RESULTS_t ft_result = hx3695_factroy_test(LEAK_LIGHT_TEST); @@ -1498,6 +1607,26 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint databuf[9] = (uint8_t)((ft_result.ir_data_final & 0x00FF0000) >> 16); databuf[10] = (uint8_t)((ft_result.ir_data_final & 0x0000FF00) >> 8); databuf[11] = (uint8_t)((ft_result.ir_data_final & 0x000000FF) >> 0); +#elif defined PPG_VC9202 + uint32_t led_cur = 0; + uint32_t apre_val = 0; + 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); + databuf[0] = (uint8_t)((led_cur & 0xFF000000) >> 24); + databuf[1] = (uint8_t)((led_cur & 0x00FF0000) >> 16); + databuf[2] = (uint8_t)((led_cur & 0x0000FF00) >> 8); + databuf[3] = (uint8_t)((led_cur & 0x000000FF) >> 0); + + databuf[4] = (uint8_t)((apre_val & 0xFF000000) >> 24); + databuf[5] = (uint8_t)((apre_val & 0x00FF0000) >> 16); + databuf[6] = (uint8_t)((apre_val & 0x0000FF00) >> 8); + databuf[7] = (uint8_t)((apre_val & 0x000000FF) >> 0); + + databuf[8] = (uint8_t)((aps_val & 0xFF000000) >> 24); + databuf[9] = (uint8_t)((aps_val & 0x00FF0000) >> 16); + databuf[10] = (uint8_t)((aps_val & 0x0000FF00) >> 8); + databuf[11] = (uint8_t)((aps_val & 0x000000FF) >> 0); #endif send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_PPG_TEST); @@ -1532,37 +1661,47 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint } else if(testitem == 0x02) { //地磁sensor测试 - float fAzimuth,fPitch,fRoll; - mmc5603_getdata(&fAzimuth,&fPitch,&fRoll); - - uint8_t databuf[6] = {0}; + float fAzimuth = 0; + do_mag_service_check_msg(MAG_SERVICE_CMD_START_CHECK); + LOS_Msleep(500); + mmc5603_getdata(&fAzimuth); + do_mag_service_check_msg(MAG_SERVICE_CMD_STOP_CHECK); + uint8_t databuf[2] = {0}; databuf[0] = (uint8_t)(((uint32_t)fAzimuth & 0xFF00) >> 8); databuf[1] = (uint8_t)((uint32_t)fAzimuth & 0x00FF); - databuf[2] = (uint8_t)(((uint32_t)fPitch & 0xFF00) >> 8); - databuf[3] = (uint8_t)((uint32_t)fPitch & 0x00FF); - - databuf[4] = (uint8_t)(((uint32_t)fRoll & 0xFF00) >> 8); - databuf[5] = (uint8_t)((uint32_t)fRoll & 0x00FF); - - PRINT("%2X %2X %2X %2X %2X %2X\r\n",databuf[0],databuf[1],databuf[2],databuf[3],databuf[4],databuf[5]); + // PRINT("%2X %2X %2X %2X %2X %2X\r\n",databuf[0],databuf[1],databuf[2],databuf[3],databuf[4],databuf[5]); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_COMPASS, 0x02, databuf, - 6); + sizeof(databuf)); } break; case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM: - if(testitem == 0x02) + if(testitem == 0x01) + { + //获取充电IC ID + uint8_t chip_id = 0; +#ifdef ENABLE_HP4507 + chip_id = hp4507_get_id(); + PRINT("chip id = 0x%x\n",chip_id); +#endif + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, + 0x01, + &chip_id, + 1); + } + else if(testitem == 0x02) { //获取充电状态 bool state; - state = uapi_get_charger_plug_status(); + state = get_charge_stat(); uint8_t send_data[2] = {0}; send_data[1] = state; factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, @@ -1574,12 +1713,12 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint } else if(testitem == 0x03) { //获取电量 - uint8_t power; - battery_getvolpower(&power); - + float voltage; + uint8_t power = battery_get_voltage(&voltage); + uint8_t send_data[3] = {0}; send_data[2] = power & 0XFF; - + PRINT("power : %d \n",power); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, 0x03, @@ -1590,13 +1729,13 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //获取电压 float voltage; uint16_t vol; - battery_getvoltage(&voltage); + battery_get_voltage(&voltage); uint8_t send_data[3] = {0}; vol = voltage * 1000; send_data[1] = (vol >> 8) ; send_data[2] = vol; - + PRINT("vol : %d \n",vol); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_PM, 0x04, @@ -1984,20 +2123,89 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint if (testitem == 0x06) { - #ifdef FD230 - + uint8_t send_data = 0x00; +#ifdef FD230 uapi_hfp_connect_(); LOS_Msleep(500); uapi_a2dp_snk_connect_(); - #endif - - uint8_t send_data = 0x00; +#endif factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, 0x03, &send_data, 1); - + } + + break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LQBP: + + if (testitem == 0x01) + { + uint8_t send_data = 0x00; +#ifdef ENABLE_LQBP002TA + send_data = lqbp002ta_get_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_LQBP, + 0x01, + &send_data, + 1); + } else if(testitem == 0x02) + { + //获取温度 + uint8_t databuf[4] = {0}; + float temp = 0; +#ifdef ENABLE_LQBP002TA + do_lqbp_service_check_msg(LQBP_SERVICE_CMD_START_CHECK); + LOS_Msleep(100); + temp = lqbp002ta_get_temp(); + do_lqbp_service_check_msg(LQBP_SERVICE_CMD_STOP_CHECK); +#endif + PRINT("temp : %f\n",temp); + + int integer_part = (int)temp; + + int decimal_part = (int)((temp - integer_part) * 100); + + PRINT("integer_part : %d , decimal_part : %d\n",integer_part,decimal_part); + + databuf[0] = (uint8_t)((integer_part >> 8) & 0xFF); + databuf[1] = (uint8_t)(integer_part & 0xFF); + + databuf[2] = (uint8_t)((decimal_part >> 8) & 0xFF); + databuf[3] = (uint8_t)(decimal_part & 0xFF); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LQBP, + 0x02, + databuf, + sizeof(databuf)); + } else if(testitem == 0x03) + { + //获取气压 + uint8_t databuf[4] = {0}; + int pressure = 0; +#ifdef ENABLE_LQBP002TA + do_lqbp_service_check_msg(LQBP_SERVICE_CMD_START_CHECK); + LOS_Msleep(100); + pressure = (int)lqbp002ta_get_pressure(); + do_lqbp_service_check_msg(LQBP_SERVICE_CMD_STOP_CHECK); +#endif + PRINT("pressure : %d\n",pressure); + + // memcpy(databuf, &pressure, sizeof(pressure)); + databuf[0] = (uint8_t)((pressure & 0xFF000000) >> 24); + databuf[1] = (uint8_t)((pressure & 0x00FF0000) >> 16); + databuf[2] = (uint8_t)((pressure & 0x0000FF00) >> 8); + databuf[3] = (uint8_t)((pressure & 0x000000FF) >> 0); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LQBP, + 0x03, + databuf, + sizeof(databuf)); } break; @@ -2039,7 +2247,7 @@ errcode_t factorytest_protocol_decode(uint8_t *buf, uint16_t event_size) printf("crc16 0x%04X vs 0x%04X\n",crc16,crc16_2); - if( crc16 == crc16_2) //校验通过,开始正式解析 + // if( crc16 == crc16_2) //校验通过,开始正式解析 { if(factorytest_mode_flag == 0 && header.submod != BLE_TEST_CMD_COMMON_SUB_MODE_SWITCH_MODE) return ERRCODE_FAIL; diff --git a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h index f4eae3bbe..b8198b4fc 100644 --- a/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h +++ b/code/sdk/zhihui/services/factorytest_service/factorytest_protocol.h @@ -93,6 +93,8 @@ extern "C" { #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1 0x1A //软件测试 子模式ID SPEAKER #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER 0x1B +//软件测试 子模式ID 气压计 +#define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LQBP 0x1C //软件测试 子模式ID 通讯录 #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CONTACTS 0x30 //软件测试 子模式ID 支付宝 diff --git a/code/sdk/zhihui/utils/custom_cmd_service.c b/code/sdk/zhihui/utils/custom_cmd_service.c index 6db2a03ce..052976c05 100644 --- a/code/sdk/zhihui/utils/custom_cmd_service.c +++ b/code/sdk/zhihui/utils/custom_cmd_service.c @@ -264,11 +264,11 @@ static void custom_cmd_service_check_task(void const *arg) case CUSTOM_CMD_MSG_TYPE_TP_TEST: if(mail.data[0] == 1) { - //uapi_set_screen_on_api(); - //uapi_factorytest_enter_test_view(1); - //uapi_factorytest_enter_test_tp_view(); - HandleUpdatelcdMode(2); - //uapi_factorytest_hide_test_tp_button(); + uapi_set_screen_on_api(); + uapi_factorytest_enter_test_view(1); + uapi_factorytest_enter_test_tp_view(); + // HandleUpdatelcdMode(2); + uapi_factorytest_hide_test_tp_button(); } else { diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index 9e12fc3d1..5d81c5cef 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -92,7 +92,12 @@ void system_init_uart(void){} #ifdef FD230 #include "bluetooth/include/BluetoothModelC.h" #endif - +#ifdef PPG_VC9202 +#include "vc9202_user.h" +#endif +#ifdef TPTYPE_CST86XX +#include "cst86xx_touch1.h" +#endif errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg) { if (task_cfg==NULL) @@ -1960,9 +1965,16 @@ void get_tp_info(int16_t *x,int16_t *y) } } +#else +void get_tp_info(int16_t *x,int16_t *y) +{ + +} +#endif void touch_getid(uint16_t *id) { +#ifdef TPTYPE_FT6X46 ext_errno ret; uint8_t chip_id[2] = { 0 }; /*get chip id*/ @@ -1980,19 +1992,11 @@ void touch_getid(uint16_t *id) //sprintf(id,"0x%02x%02x", chip_id[0], chip_id[1]); } } -} - -#else -void get_tp_info(int16_t *x,int16_t *y) -{ - -} -void touch_getid(uint16_t *id) -{ - -} +#elif defined TPTYPE_CST86XX + cst86xx_get_chip_id(id); #endif +} void touch_getstate(void) { @@ -2006,38 +2010,15 @@ void touch_getstate(void) #include "mag_service.h" void mmc5603_getid(unsigned char *id) { + mmc5603_poweron(); CUSTOM_MMC5603_GETID(id); + mmc5603_poweroff(); } -void mmc5603_getdata(float *fAzimuth,float *fPitch,float *fRoll) +void mmc5603_getdata(float *fAzimuth) { - mmc5603_check(); *fAzimuth = mag_service_get_fAzimuth(); - *fPitch = mag_service_get_fPitch(); - *fRoll = mag_service_get_fRoll(); - PRINT("Azimuth : %f, fPitch : %f , fRoll : %f \r\n",*fAzimuth,*fPitch,*fRoll); -} - - -#include "battery_hal.h" -void charge_getstate(void) -{ - if(get_charge_stat()) - PRINT("charging\r\n"); - else - PRINT("uncharged\r\n"); -} - - -void battery_getvolpower(uint8_t *power) -{ - float voltage; - *power = battery_get_voltage(&voltage); -} - -void battery_getvoltage(float *voltage) -{ - battery_get_voltage(voltage); + PRINT("Azimuth : %f\n",*fAzimuth); } @@ -2059,27 +2040,25 @@ void flash_erase(void) -void get_gsensor_single(uint8_t *databuf) -{ +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 = 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); PRINT("x : %.2f, y : %.2f, z : %.2f \r\n",t.x,t.y,t.z); - PRINT("GSENSOR: %2X %2X %2X %2X %2X %2X\r\n",databuf[0],databuf[1],databuf[2],databuf[3],databuf[4],databuf[5]); - + PRINT("x : %d, y : %d, z : %d \r\n", x, y, z); + PRINT("GSENSOR: %02X %02X %02X %02X %02X %02X\r\n", databuf[0], databuf[1], databuf[2], databuf[3], databuf[4], databuf[5]); } void gsensor_get_single_data(gsenson_t *t) @@ -2467,6 +2446,10 @@ void uapi_ppg_get_id(uint8_t *chip_id) #ifdef PPG_HX3695 hx3695_get_id(chip_id); #endif +#ifdef PPG_VC9202 + uint8_t id = 0; + vc9202_usr_get_chip_id(chip_id,&id); +#endif } #include "hal_i2c.h" diff --git a/code/sdk/zhihui/utils/custom_utils.h b/code/sdk/zhihui/utils/custom_utils.h index 1bff5fd13..f119a67e4 100644 --- a/code/sdk/zhihui/utils/custom_utils.h +++ b/code/sdk/zhihui/utils/custom_utils.h @@ -183,14 +183,7 @@ void touch_getstate(void); //获取MMC5063 ID void mmc5603_getid(unsigned char *id); -void mmc5603_getdata(float *fAzimuth,float *fPitch,float *fRoll); - -//获取充电状态 -void charge_getstate(void); - -//获取电压 -void battery_getvoltage(float *voltage); -void battery_getvolpower(uint8_t *power); +void mmc5603_getdata(float *fAzimuth); //flash整片擦除 void flash_getid(uint32_t *id); diff --git a/code/sdk/zhihui/utils/custom_utils_at_cmd.c b/code/sdk/zhihui/utils/custom_utils_at_cmd.c index b4b1865c9..0f1f7afed 100644 --- a/code/sdk/zhihui/utils/custom_utils_at_cmd.c +++ b/code/sdk/zhihui/utils/custom_utils_at_cmd.c @@ -366,8 +366,8 @@ static uint32_t custom_mmc5603_getdata(uint8_t *para, uint32_t paraLen, char *st UNUSED(strCommonCmd); - float fAzimuth,fPitch,fRoll; - mmc5603_getdata(&fAzimuth,&fPitch,&fRoll); + // float fAzimuth,fPitch,fRoll; + // mmc5603_getdata(&fAzimuth,&fPitch,&fRoll); return ERRCODE_SUCC; } -- 2.17.1