From: SnickerSun Date: Sat, 23 Mar 2024 07:32:04 +0000 (+0800) Subject: cywee using p813 version lib, can report step no-move and some other event now X-Git-Tag: release_V1.2.70_20241020_135402~1273 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=68d41e4e6d5b6591697fb6cbef44ffb00bcffa05;p=mirrors%2FFD230.git cywee using p813 version lib, can report step no-move and some other event now --- diff --git a/code/sdk/drivers/peripheral/cywee/CMakeLists.txt b/code/sdk/drivers/peripheral/cywee/CMakeLists.txt index 72d1eb933..bde9d556c 100644 --- a/code/sdk/drivers/peripheral/cywee/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/cywee/CMakeLists.txt @@ -5,22 +5,22 @@ set(COMPONENT_NAME "cywee") set(SOURCES ${SOURCES} - ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + # ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/main_dml.c ${CMAKE_CURRENT_SOURCE_DIR}/src/test_api.c ${CMAKE_CURRENT_SOURCE_DIR}/src/board_yh601s.c ${CMAKE_CURRENT_SOURCE_DIR}/service/cywee_service.c ${CMAKE_CURRENT_SOURCE_DIR}/service/cywee_at_cmd.c - ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/examples/lis2doc_read_data_single.c - ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/lis2doc_porting.c + # ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/examples/lis2doc_read_data_single.c + # ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/lis2doc_porting.c ) set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/Inc ) set(PRIVATE_HEADER - ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/driver - ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC + # ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/driver + # ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC ) set(PRIVATE_DEFINES @@ -49,7 +49,7 @@ set(MAIN_COMPONENT if("SUPPORT_AT_CYWEE" IN_LIST DEFINES) find_library(LIB_PATH_CWM_LIB_DML Lib/CWM_LIB_DML_clang_riscv.a ${CMAKE_CURRENT_SOURCE_DIR}) - find_library(LIB_PATH_CWM_LIB Lib/CWM_LIB_clang_riscv.a ${CMAKE_CURRENT_SOURCE_DIR}) + find_library(LIB_PATH_CWM_LIB Lib/CWM_LIB_clang_riscv.p813.a ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_CWM_LIB_DML} ${LIB_PATH_CWM_LIB} PRIVATE -Wl,--whole-archive) endif() diff --git a/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h b/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h index 28edf6d0b..753b23057 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/OsApi.h @@ -26,6 +26,19 @@ typedef struct{ int (*spiWrite)(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); } OsAPI, *pOsAPI; -typedef OsAPI os_api; + +typedef struct{ + int (*dbgOutput)(const char*); + uint64_t (*GetTimeNs)(void); + void (*uSleep)(uint32_t); + int (*i2cRead)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); + int (*i2cWrite)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); + void *(*malloc)(int size); + void (*free)(void* ptr); + int (*spiRead)(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); + int (*spiWrite)(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); +} os_api; + +// typedef OsAPI os_api; #endif /* __OS_API_H__ */ diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.bk.h b/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.bk.h deleted file mode 100644 index 173a4775f..000000000 --- a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.bk.h +++ /dev/null @@ -1,264 +0,0 @@ -#ifndef __CWM_LIB_H__ -#define __CWM_LIB_H__ - -#include "CWM_EventStructure.h" -#include "OsApi.h" -#include "CWM_CustomDataStruct.h" - -/** - * @brief Setting Control control ID - * @api CWM_SettingControl - * @param CtrId - */ -#define SCL_LOG 0 -#define SCL_USER_INFO 1 -#define SCL_DATE_TIME 2 -#define SCL_SEDENTARY 3 -#define SCL_PEDO_RESET 4 // old -#define SCL_RESET_DAILY_INFO 4 // new -#define SCL_REQ_SLEEPING_DATA 5 -#define SCL_LOW_POWER_MODE 6 -#define SCL_SET_ACTIVITY_MODE 7 -#define SCL_GET_CHIP_INFO 8 -#define SCL_ACTIVITY_CONFIG 9 -#define SCL_LIB_DEBUG 10 -#define SCL_PEDO_CONFIG 11 -#define SCL_GET_LIB_INFO 12 -#define SCL_SWIM_CONFIG 13 -#define SCL_BIKING_CONFIG 14 -#define SCL_ACTIVITY_PAUSE 15 -#define SCL_HAND_UPDOWN_CONFIG 16 -#define SCL_CHIP_VENDOR_CONFIG 17 -#define SCL_SLEEP_CONFIG 18 -#define SCL_ABS_STATIC_CONFIG 19 -#define SCL_HEART_RATE_CONFIG 20 -#define SCL_REQ_SWIM_EXIT 21 -#define SCL_WATCH_FALL_CONFIG 22 -#define SCL_AR_ALERT_CONFIG 23 -#define SCL_WM_CONFIG 25 -#define SCL_INACTIVITY_CONFIG 26 -#define SCL_SET_INACTIVITY_MODE 27 -#define SCL_STAND_CONFIG 28 -#define SCL_SS_CONFIG 29 -#define SCL_ACT_INFO_CONFIG 30 -#define SCL_REQ_ACTIVITY_EXIT 31 -#define SCL_ACT_PAI_INFO 33 -#define SCL_ACT_INTSY_INFO 35 -#define SCL_DUMP_WI_INFO 36 -#define SCL_ACT_ZONE_TIME 37 -#define SCL_ACT_TRAINING_INFO 38 -#define SCL_WATCH_INTF_RESET 40 -#define SCL_PEDO_CONFIG2 42 -#define SCL_HG_INTF_CONFIG 43 -#define SCL_ACT_AUTO_PAUSE_CFG 44 -#define SCL_AR_ALERT2_CONFIG 45 -#define SCL_WI_SENS_REQ_CFG 46 -#define SCL_ACT_SA_METR_INFO 47 -#define SCL_SLEEP_ALARM_CFG 48 -#define SCL_FITNESS_INFO 49 -#define SCL_SZ_BREACH_CONFIG 50 -#define SCL_ACT_PAI_INFO2 51 - -#define SCL_ALGO_PROC_CONFIG 100 -#define SCL_INPUT_SENSOR_CONFIG 101 -#define SCL_INPUT_DT_CONFIG 102 -#define SCL_SENS_RANGE_DETECT_CONFIG 103 -#define SCL_SENS_CALI_CONFIG 110 -#define SCL_SENS_CALI_CTRL_MAG 111 -#define SCL_SENS_CALI_CTRL_A 112 -#define SCL_SPV_CONFIG 113 -#define SCL_SPV_MODE 114 -#define SCL_SENS_CALI_SET_MAG 115 -#define SCL_SENS_CALI_SET_A 116 - -#define SCL_SIN_HR_EXT 200 - -/** - * @brief Custom Sensor Input sensorId - * @api CWM_CustomSensorInput - * @param CustomSensorData.sensorType extSensorId - * @ - * @api CWM_CustomSensorInput_Fifo_Start CWM_CustomSensorInput_Fifo_End - * @param extSensorId - */ -#define CUSTOM_ACC 0 -#define CUSTOM_GYRO 1 -#define CUSTOM_MAG 2 -#define CUSTOM_BARO 3 -#define CUSTOM_TEMP 4 -#define CUSTOM_HEARTRATE 5 -#define CUSTOM_GNSS 6 -#define CUSTOM_OFFBODY_DETECT 7 -#define CUSTOM_ON_CHARGING 8 -#define CUSTOM_ACC_ANY_MOTION 9 -#define CUSTOM_SENS1 10 - - -/** - * @brief sensor enable/disable - * @api CWM_Sensor_Enable CWM_Sensor_Disable - * @param sensorId - */ -#define IDX_ACCEL 0 -#define IDX_GYRO 1 -#define IDX_MAG 2 -#define IDX_BARO 3 -#define IDX_TEMP 4 -#define IDX_HEARTRATE 5 -#define IDX_GNSS 6 -#define IDX_OFFBODY_DETECT 7 -#define IDX_ALGO_SEDENTARY 8 -#define IDX_ALGO_WATCH_HANDUP 9 -#define IDX_ALGO_SLEEP 10 -#define IDX_REQUEST_SENSOR 11 -#define IDX_ALGO_SHAKE 13 -#define IDX_ALGO_ACTIVITY_OUTPUT 14 -#define IDX_ALGO_ANY_MOTION 15 -#define IDX_ALGO_NO_MOTION 16 -#define IDX_ALGO_FALLING 17 -#define IDX_ONCHARGING_DETECT 18 -#define IDX_ALGO_ABSOLUTE_STATIC 19 -#define IDX_ALGO_SPV 20 -#define IDX_ALGO_SENS_CALIBRATION 21 -#define IDX_ALGO_INACTIVITY_OUTPUT 22 -#define IDX_ALGO_STAND 23 -#define IDX_ALGO_SENS_RANGE_DETECT 24 - -/** - * @brief activity mode setting - * @api CWM_SettingControl - * @param SCL_SET_ACTIVITY_MODE - */ -#define ACTIVITY_MODE_NORMAL 1001 - -typedef struct { - int iData[16]; -} SettingControl_t; - -typedef void (*FN_SENSOR_LISTEN)(pSensorEVT_t); - - -#define LOS_DATA_TYPE_INT 0 -#define LOS_DATA_TYPE_STR 1 - -/** - * @brief - * @param dataType: cmd data type indicater - * 0 (LOS_DATA_TYPE_INT): int type data, dataInt accessible - * 1 (LOS_DATA_TYPE_STR): string type data, *dataStr and dataStr_length accessible - */ -typedef struct { - const char *optionString; - const char *sectionName; - const char *apiName; - int cmdId; - int dataType; - int dataInt[16]; - const char *dataStr; - int dataStr_length; -} los_cmd_data_t; - -typedef void (*FN_LOS_CMD_EXECUTE)(los_cmd_data_t *); - -/** - * @brief CyweeMotion internal process Initial - */ -void CWM_LibPreInit(OsAPI *api); - -/** - * @brief Sensor Event register callback, when sensor event is triggered, - * this function will be called to notify - */ -void CWM_LibPostInit(FN_SENSOR_LISTEN pfn); - -/** - * @brief lib deinit for special case. Not any situation can be used normally - */ -void CWM_LibDeinit(void); - -/** - * @brief Sensor enable based on sensor index provided - * @param sensorId: sensor register handle, if not setup this handle don't care - * @retval 0 is success, otherwise is failed - */ -int CWM_Sensor_Enable(uint32_t sensorId); - -/** - * @brief Sensor disable based on sensor index provided - * @param sensorId: sensor register handle, if not setup this handle don't care - * @retval 0 is success, otherwise is failed - */ -int CWM_Sensor_Disable(uint32_t sensorId); - -/** - * @brief Read sensor data and output through sensor call-back function - * @retval 0 is no data to process, mcu can enter low power mode, - otherwise has some data needs process this function again. - */ -int CWM_process(void); - -/** - * @brief Read sensor data and output through sensor call-back function - */ -int CWM_process2(int dt_us); - -/** - * @brief Get how many event in CyweeMotion Library to be processed - * @retval 0 is no data to process, mcu can enter low power mode, - otherwise has some data - */ -int CWM_IsReadyForProcess(void); - -/** - * @brief Put custom sensor data. - * @param SensorDataInput: sensor data input handle, input format as below: - * sensorType= CustomSensorDataIndex - * fData = sensor raw data - * @retval 0 is success, otherwise is failed - */ -int CWM_CustomSensorInput(CustomSensorData *SensorDataInput); - -/** - * @brief Get the duration time of the next event - * @retval the duration time (unit nanosecond) - */ -int64_t CWM_GetNextActionDuration_ns(void); - -/** - * @brief set lib config - * @param Control ID - * @param Setting control array - * @retval 0 is success, otherwise is failed - */ -int CWM_SettingControl(int CtrId, SettingControl_t *pData); - -/** - * @brief Fifo initial - * @param max recored number of acc fifo - */ -void CWM_CustomSensorInput_Fifo_Init(int maxRecords_Acc); - -/** - * @brief setting lib can start input fifo - * @param sensor ID - * @param timestamp that interrupt trigger to read hw fifo data - * @param fifo delta_time - * @retval 0 is success, otherwise is failed - */ -int CWM_CustomSensorInput_Fifo_Start(uint32_t extSensorId, uint64_t triggerFifoRead_timeStamp_ns, uint64_t dt_ns); - -/** - * @brief setting lib to stop input fifo - * @param sensor ID - */ -void CWM_CustomSensorInput_Fifo_End(uint32_t extSensorId); - -/** - * @brief Execute option string - * @param optionString - * @param sectionString section execute order - * @param custCallbackFunc custom option string execute function - * @param skipExeDefault don't execute default command - */ -void CWM_LoadOptionString(const char *optionString, const char *sectionString, FN_LOS_CMD_EXECUTE custCallbackFunc, int skipExeDefault); -#endif diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h b/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h index 14a6137bf..266e87656 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib.h @@ -1,16 +1,21 @@ -#ifndef ___CWM_LIB__H_ -#define ___CWM_LIB__H_ - +#ifndef __CWM_LIB_H__ +#define __CWM_LIB_H__ #include -#include "os_api.h" +#include "OsApi.h" #include "CWM_EventStructure.h" #include "CWM_CustomDataStruct.h" +/** + * @brief Setting Control control ID + * @api CWM_SettingControl + * @param CtrId + */ #define SCL_LOG 0 #define SCL_USER_INFO 1 #define SCL_DATE_TIME 2 #define SCL_SEDENTARY 3 -#define SCL_PEDO_RESET 4 +#define SCL_PEDO_RESET 4 // old +#define SCL_RESET_DAILY_INFO 4 // new #define SCL_REQ_SLEEPING_DATA 5 #define SCL_LOW_POWER_MODE 6 #define SCL_SET_ACTIVITY_MODE 7 @@ -30,7 +35,6 @@ #define SCL_REQ_SWIM_EXIT 21 #define SCL_WATCH_FALL_CONFIG 22 #define SCL_AR_ALERT_CONFIG 23 -#define SCL_ACT_PAUSE_DETECT 24 #define SCL_WM_CONFIG 25 #define SCL_INACTIVITY_CONFIG 26 #define SCL_SET_INACTIVITY_MODE 27 @@ -38,16 +42,12 @@ #define SCL_SS_CONFIG 29 #define SCL_ACT_INFO_CONFIG 30 #define SCL_REQ_ACTIVITY_EXIT 31 -#define SCL_TAP_CONFIG 32 #define SCL_ACT_PAI_INFO 33 -#define SCL_HAND_WRIST_CONFIG 34 #define SCL_ACT_INTSY_INFO 35 #define SCL_DUMP_WI_INFO 36 #define SCL_ACT_ZONE_TIME 37 #define SCL_ACT_TRAINING_INFO 38 -#define SCL_HAND_SHAKE_CONFIG 39 #define SCL_WATCH_INTF_RESET 40 -#define SCL_HAND_RUB_CONFIG 41 #define SCL_PEDO_CONFIG2 42 #define SCL_HG_INTF_CONFIG 43 #define SCL_ACT_AUTO_PAUSE_CFG 44 @@ -62,52 +62,24 @@ #define SCL_ALGO_PROC_CONFIG 100 #define SCL_INPUT_SENSOR_CONFIG 101 #define SCL_INPUT_DT_CONFIG 102 -#define SCL_SENS_RANGE_DETECT_CONFIG 103 +#define SCL_SENS_RANGE_DETECT_CONFIG 103 #define SCL_SENS_CALI_CONFIG 110 #define SCL_SENS_CALI_CTRL_MAG 111 #define SCL_SENS_CALI_CTRL_A 112 #define SCL_SPV_CONFIG 113 -#define SCL_FACTORY_CALI_CONFIG 113 #define SCL_SPV_MODE 114 -#define SCL_FACTORY_CALI_MODE 114 #define SCL_SENS_CALI_SET_MAG 115 #define SCL_SENS_CALI_SET_A 116 -#define SCL_SENS_CALI_CTRL_A2 117 - -#define SCL_GET_HEAP_INFO 120 -#define SCL_SEC_VERIFY_CLIENT 150 -#define SCL_SEC_VERIFY_SERVER 151 #define SCL_SIN_HR_EXT 200 -#define SCL_HS_ORIEN_CONFIG 300 -#define SCL_HS_ORIEN_CTRL_EXC 301 -#define SCL_HS_ORIEN_RESET 302 -#define SCL_HS_PHONE_CONFIG 303 -#define SCL_EAR_FALL_CONFIG 304 -#define SCL_HS_PHONE_CONFIG2 305 -#define SCL_HS_RUN_INIT_ANGLE 306 -#define SCL_HS_INTF_CONFIG 307 -#define SCL_HS_INTF_RESTART 308 -#define SCL_HS_GESTURE_CONFIG 309 -#define SCL_HS_NECK_HT_CONFIG 310 -#define SCL_HS_ORIEN_CTRL_SYNC 311 - -#define SCL_FUSION_MOUSE_CONFIG 501 -#define SCL_PEDO_POD_CONFIG 502 -#define SCL_PEDO_POD_TR_CALI 503 -#define SCL_PEDO_POD_RUN_CMD 504 - -#define SCL_GLASSES_MOT_CONFIG 510 -#define SCL_GLASSES_MOT_LEVEL 511 -#define SCL_GLASSES_MOT_CALI_CTRL 512 -#define SCL_GLASSES_MOT_CMD 513 - /** * @brief Custom Sensor Input sensorId * @api CWM_CustomSensorInput * @param CustomSensorData.sensorType extSensorId * @ + * @api CWM_CustomSensorInput_Fifo_Start CWM_CustomSensorInput_Fifo_End + * @param extSensorId */ #define CUSTOM_ACC 0 #define CUSTOM_GYRO 1 @@ -135,21 +107,34 @@ #define IDX_HEARTRATE 5 #define IDX_GNSS 6 #define IDX_OFFBODY_DETECT 7 +#define IDX_ALGO_SEDENTARY 8 +#define IDX_ALGO_WATCH_HANDUP 9 +#define IDX_ALGO_SLEEP 10 #define IDX_REQUEST_SENSOR 11 +#define IDX_ALGO_SHAKE 13 +#define IDX_ALGO_ACTIVITY_OUTPUT 14 #define IDX_ALGO_ANY_MOTION 15 #define IDX_ALGO_NO_MOTION 16 +#define IDX_ALGO_FALLING 17 #define IDX_ONCHARGING_DETECT 18 #define IDX_ALGO_ABSOLUTE_STATIC 19 #define IDX_ALGO_SPV 20 -#define IDX_ALGO_FACTORY_CALI 20 #define IDX_ALGO_SENS_CALIBRATION 21 +#define IDX_ALGO_INACTIVITY_OUTPUT 22 +#define IDX_ALGO_STAND 23 #define IDX_ALGO_SENS_RANGE_DETECT 24 +/** + * @brief activity mode setting + * @api CWM_SettingControl + * @param SCL_SET_ACTIVITY_MODE + */ +#define ACTIVITY_MODE_NORMAL 1001 + typedef struct { int iData[16]; } SettingControl_t; - typedef void (*FN_SENSOR_LISTEN)(pSensorEVT_t); @@ -175,18 +160,22 @@ typedef struct { typedef void (*FN_LOS_CMD_EXECUTE)(los_cmd_data_t *); - /** * @brief CyweeMotion internal process Initial */ -void CWM_LibPreInit(os_api *api); +void CWM_LibPreInit(OsAPI *api); /** - * @brief Sensor Event register callback, when sensor event is triggered, + * @brief Sensor Event register callback, when sensor event is triggered, * this function will be called to notify */ void CWM_LibPostInit(FN_SENSOR_LISTEN pfn); +/** + * @brief lib deinit for special case. Not any situation can be used normally + */ +void CWM_LibDeinit(void); + /** * @brief Sensor enable based on sensor index provided * @param sensorId: sensor register handle, if not setup this handle don't care @@ -201,11 +190,25 @@ int CWM_Sensor_Enable(uint32_t sensorId); */ int CWM_Sensor_Disable(uint32_t sensorId); +/** + * @brief Read sensor data and output through sensor call-back function + * @retval 0 is no data to process, mcu can enter low power mode, + otherwise has some data needs process this function again. + */ +int CWM_process(void); + /** * @brief Read sensor data and output through sensor call-back function */ int CWM_process2(int dt_us); +/** + * @brief Get how many event in CyweeMotion Library to be processed + * @retval 0 is no data to process, mcu can enter low power mode, + otherwise has some data + */ +int CWM_IsReadyForProcess(void); + /** * @brief Put custom sensor data. * @param SensorDataInput: sensor data input handle, input format as below: @@ -216,13 +219,40 @@ int CWM_process2(int dt_us); int CWM_CustomSensorInput(CustomSensorData *SensorDataInput); /** - * @brief Switch log output by input parameters + * @brief Get the duration time of the next event + * @retval the duration time (unit nanosecond) + */ +int64_t CWM_GetNextActionDuration_ns(void); + +/** + * @brief set lib config * @param Control ID * @param Setting control array * @retval 0 is success, otherwise is failed */ int CWM_SettingControl(int CtrId, SettingControl_t *pData); +/** + * @brief Fifo initial + * @param max recored number of acc fifo + */ +void CWM_CustomSensorInput_Fifo_Init(int maxRecords_Acc); + +/** + * @brief setting lib can start input fifo + * @param sensor ID + * @param timestamp that interrupt trigger to read hw fifo data + * @param fifo delta_time + * @retval 0 is success, otherwise is failed + */ +int CWM_CustomSensorInput_Fifo_Start(uint32_t extSensorId, uint64_t triggerFifoRead_timeStamp_ns, uint64_t dt_ns); + +/** + * @brief setting lib to stop input fifo + * @param sensor ID + */ +void CWM_CustomSensorInput_Fifo_End(uint32_t extSensorId); + /** * @brief Execute option string * @param optionString @@ -230,9 +260,5 @@ int CWM_SettingControl(int CtrId, SettingControl_t *pData); * @param custCallbackFunc custom option string execute function * @param skipExeDefault don't execute default command */ -void CWM_LoadOptionString(const char *optionString, \ - const char *sectionString, \ - FN_LOS_CMD_EXECUTE custCallbackFunc, \ - int skipExeDefault); - -#endif //___CWM_LIB__H_ +void CWM_LoadOptionString(const char *optionString, const char *sectionString, FN_LOS_CMD_EXECUTE custCallbackFunc, int skipExeDefault); +#endif diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib_dml.h b/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib_dml.h index ca7a5b806..4704973b0 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib_dml.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cwm_lib_dml.h @@ -1,11 +1,107 @@ #ifndef __CWM_LIB_DML_H__ #define __CWM_LIB_DML_H__ + + +/** + * @param int[0] =1 + * @param int[1] = [in/out] enable_method (default: manual_enable) + * (0: default, 1: manual_enable, 2: auto_enable, -1: 取得參數值) + * @param int[2] = [in/out] manual_enable_sensorData (default: all_off) + * ( bit control 0: manual_all_off, 1: acc, 2: gyro, 4: mag, 8: acc_temp) + * @param int[3] = [out] 取得手動或自動模式的enable_sensorData設定值 + * ( bit control 0: all_off, 1: acc, 2: gyro, 4: mag, 16: acc_temp) + * @param int[4] = [in/out] manual_enable_embdedFeature (default: all_off) + * ( bit control 0: manual_all_off, 1: acc_any_motion) + * @param int[5] = [out] 取得手動或自動模式的enable_embdedFeature設定值 + * ( bit control 0: all_off, 1: acc_any_motion) + * +*/ #define SCL_DML_DRV_ENABLE 400 +/** + * @param int[0] = 1 + * @param int[1] = [in/out] lib_process_method (default: auto) + * (0: default, -1: 取得所有指令參數值, 1: auto, 2: CWM_process, 3: CWM_process2) + * @param int[2] = [out] 找到硬體的數量 + * (-1: 未初始化, 0: 失敗, 1 - 8) + * @param int[3] = [in/out] enable_function (default: 0) + * (bit control, 0:default, 1: enable_reg_access_cmd) +*/ #define SCL_DML_DRV_INIT 401 + + +/** + * @brief 注册硬件 + * @param int[0] = 1 + * @param int[1] = register_type (default: all_hardware) + * (0: default, 1: all_hardware, 2: select_hardware) + * @param int[2] = all_hardware_attr (屬性)(default: 依照driver的實現) + * (bit control, 0: default + * 1: primary, 2: aux + * 4: i2c_address_0, 8: i2c_address_1, + * 16: i2c_address_2, 32: i2c_address_3, + * 64: bus_0, 128: bus_1, + * 256: bus_2, 512: bus_3 + * 1024: interface_i2c, 2048: interface_spi_4w) + * @param int[3] = 0 + * @param int[4] = 0 + * @param int[5] = 0 + * @param int[6] = 1_hw_id (型號) + * @param int[7] = 1_hw_attr (屬性)(default: 依照driver的實現) + * @param int[8] = 2_hw_id + * @param int[9] = 2_hw_attr + * @param int[10] = 3_hw_id + * @param int[11] = 3_hw_attr + * @param int[12] = 4_hw_id + * @param int[13] = 4_hw_attr + * @param int[14] = 5_hw_id + * @param int[15] = 5_hw_attr +*/ #define SCL_DML_DRV_HW_CONFIG 402 +/** + * @brief SCL_DML_DRV_AG_CONFIG + * @param int[0] = 1 + * @param int[1] = 設定或取得參數值(default: 設定參數值) + * (0: default, 1: 設定參數值, 2: 取得參數值) + * @param int[2] = 多顆同樣硬體時設定對象 (default: primary) + * (0: default, 1: primary(主要), 2: aux(輔助)) + * @param int[3] = [in/out] get_data_mode (有支援才會生效)(default: polling) + * (0: default, 1: polling, 2: fifo) + * @param int[4] = [in/out] get_data_period (default: any_time) + * (0: default, 1: any_time, 2: dt_or_fifo_max, 3: custom_data_period) + * @param int[5] = [in/out] custom_data_period (default: 0) + * (0: default, 1 - 1000000000) + * @param int[6] = [in/out] fifo_max_count (default: 1) + * (0: default, 1 - 25) + * @param int[7] = [in/out] axis mode (default: 1) + * (0: default, 1-24: axis_mode) + * @param int[8] = [in/out] sensorData_ODR (default: 52) + * (0: default, 1 - 10000) + * @param int[9] = [in/out] acc range (default: 16) + * (0: default, 1 - 64) + * @param int[10] = [in/out] gyro range (default: 2000) + * (0: default, 1 - 8000) + * @param int[11] = [in/out] interrupt_mode_pin1 (有支援才會生效)(default: nothing) + * (bit control, 0: nothing, 1: data_ready_acc, 2: any_motion) + * @param int[12] = [in/out] interrupt_mode_pin2 (有支援才會生效)(default: nothing) + * (bit control, 0: nothing, 1: data_ready_acc, 2: any_motion) + * @param int[13] = [in/out] only_embedFeature_ODR (default: 26) + * (0: default, 1 - 10000) + * @param int[14] = [in/out] only_embedFeature_acc range (default: 2) + * (0: default, 1 - 64) +*/ #define SCL_DML_DRV_AG_CONFIG 403 #define SCL_DML_DRV_M_CONFIG 404 +/** + * @brief SCL_DML_DEBUG config data + * @param int[0] =1 + * @param int[1] = log_option + * (bit control 0: no_log, 1: mgr_flow, 2: si_data, 4: i2c_spi_data, 8: si_api, 16: dml_proc, 32: get_data_enter, 64: get_data_ok, 128: uSleep) + * @param int[2] = skip_option + * (bit control 0: no_skip, 1: skip_dml_proc, 2: skip_cwm_proc, 4: skip_cwm_proc2, 8: skip_get_data) + * @param int[3] = skip_sensorData (筆數)(defalt: 驅動預設值) + * (0: default, -2: 不略過, -1: 驅動預設值, 1-10000) +*/ #define SCL_DML_DEBUG 405 #define SCL_DML_GET_LIB_INFO 406 #define SCL_DML_GET_INITED_LIST 407 diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 0905eed2f..979346879 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -19,6 +19,421 @@ extern "C" { #include "stdint.h" #include "errcode.h" +extern uint64_t CWM_OS_GetTimeNs(void); +extern int CWM_OS_dbgOutput(const char * format); +extern int CWM_OS_dbgPrintf(const char * format,...); +extern void CWM_OS_uSleep(unsigned int udelay); +extern void CWM_OS_uSleep(uint32_t time); +extern uint64_t CWM_OS_GetTimeNs(void); +extern int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); +extern int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); +extern int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex); +extern void* CWM_OS_malloc(int size); +extern void CWM_OS_free(void *ptr); +extern void CWM_OS_saveData(uint8_t* data, uint32_t len); +extern void CWM_OS_restoreData(uint8_t* data, uint32_t len); +/********************CYWEE LIB*************************/ + +#define SPORT_ACTIVE_MODE_NORMAL 1001 // 一般模式(生活模式) normal(base) 1001 +#define SPORT_ACTIVE_MODE_TREADMILL 1002 // 跑步機 treadmill 1002 +#define SPORT_ACTIVE_MODE_OUTDORR_RUNNING 1003 // 戶外跑步 outdoor running 1003 +#define SPORT_ACTIVE_MODE_INDOR_RUNNING 1006 // 室內跑步 indoor running 1006 +#define SPORT_ACTIVE_MODE_FITNESS_PEDOMETERR 1008 // 防誤觸計步 fitness_pedometer 1008 +#define SPORT_ACTIVE_MODE_FREE_TRAINING 5001 // 自由運動 FreeTraining 5001 +#define SPORT_ACTIVE_MODE_AR_ALERT 1001 // 長時間動作偵測 AR alert 1001 + +#pragma pack(1) + +/** + * @brief user_info_t define + * @param header int[0] = 1 + * @param age int[1] = age (年紀)(default: 30) (1 - 99) +*/ +typedef struct +{ + int header;// = 1; //int[0] = 1 + int age;//int[1] = age (年紀)(default: 30) (1 - 99) + int gender;//int[2] = gender (性別)(default: 男性) (0:女性, 1:男性) + int weight;// int[3] = weight (kg)(體重)(default: 70)(10 - 300) + int height;// int[4] = height (cm)(身高)(default: 175) (30 - 300) + int Wearing_method;//int[5] = Wearing method (配戴方式) (default: 左手) (0: 左手 1: 右手) +}user_info_t; +typedef struct +{ + int header ;// int[0] = 1 + int header2 ;// int[1] = 0 + int one_line_max_length;// int[2] = one_line_max_length (default: 160) (0: defalut, 1 - 256) + int amh;// int[3] = amh (default: 0) (bit control, 0: turn off, 1: dlog, 2: dlog_sens_high_accuracy, 4:disable_dlog_zk, 8:aglog 16:enable_dlog_one_line_multi-log, 32: dlog_sens_low_accuracy, 64: dlog_low_sn_dt, 128: rlog) + int aml_hub;// int[4] = aml,hub (default: 0) (bit control, 0: turn off, 1: control API, 2: custom_input_sensor, 4: output_sensor_report, 8: cwm_process, 16: drv_input_sensor, 32: high_accuracy_custom_input_sensor, 64: high_accuracy_output_sensor_report) + int dlog_enable_special_output;// int[5] = dlog_enable_special_output (default: 0) (bit control, 0:default, 1:V_acc_uncalibration, 2:Y_gyro_uncalibration, 4:N_mag_uncalibration, 8:D_time_second, 16: DTO_dt_original) + int dlog_disable_output;// int[6] = dlog_disable_output (default: 0) (bit control, 0:default, 1:tag, 2:sn, 4:ts, 8:dt, 16:A_acc, 32:G_gyro, 64:M_mag, 128:P_baro, 256:T_temp, 512:H_hr_bpm, 1024:I_hr_range, 2048:S_gps, 4096:X_gps_info, 8192:B_off_body, 16384:C_on_charging, 32768:Z_cust_sens1) + int aglog_option;// int[7] = aglog_option (default: 0) + int accuracy_and_column_option;// int[8] = accuracy_and_column_option (defalut: 0) + int csi_disable_output;// int[9] = csi_disable_output (default: 0) (bit control, 0:default, 1:acc, 2:gyro, 4:mag, 8:baro, 16:Temp, 32:Heart_Rate, 64:GNSS, 128:off_body, 256:on_charging, 512:acc_any_motion, 1024:sens1) +}log_control_t; +typedef struct +{ + int header;// int[0] = 1 + int year ;// int[1] = year (1900 - 2100) + int month;// int[2] = month (1 - 12) + int day;// int[3] = day (1 - 31) + int hour;// int[4] = hour (0 - 23) + int minute;// int[5] = minute (0 - 59) + int second;// int[6] = second (0 - 59) +}date_time_t; + +typedef struct +{ + int header;// int[0] = 1 + int reserved;// int[1] = reserved + int is_reminder_on;// int[2] = is_reminder_on (提醒功能)(default: turn_off) (0: default, 1: turn on, 2: turn off) + int reminder_time;// int[3] = reminder_time (minutes)(提醒時間)(default: 5) (0:default, 1 - 10) + int release_level;// int[4] = release_level (解除久坐狀態的等級)(default: 3) (0:default, 1:容易解除, 2, 3, 4, 5:不容易解除) + int release_mode;// int[5] = release_mode (解除久坐的算法模式)(default: 行走模式) (0: default, 1: 行走模式, 2: 活動量模式) +}sedentary_t; + +typedef struct +{ + int header ;// int[0] = 1 + int terminate_sleep_and_output_result ;// int[1] = terminate_sleep (0: 立刻輸出狀態,但不中止此段睡眠偵測, 1: 立刻輸出狀態,並中止此段睡眠偵測 ) +}req_output_sleeping_data_t; +typedef struct +{ + int header ;// int[0] = 1 + int mode_number;// int[1] = mode_number (需填值) + // 一般模式(生活模式) normal(base) 1001 + // 跑步機 treadmill 1002 + // 戶外跑步 outdoor running 1003 + // 室內跑步 indoor running 1006 + // 防誤觸計步 fitness_pedometer 1008 + // 自由運動 FreeTraining 5001 + // 特別輸出功能 info mode_number + // 長時間動作偵測 AR alert 1001 + int sub_mode_number;// int[2] = sub_mode_number (預設: 0) +}set_activity_mode_t; + +#if 1 + +/** +* @brief get_chip_info_t +* @param int[0] = 1 +* @param int[1] = 1 +* @param int[2] = [in/out]output buffer address (buffer的位址,用來接收CHIP_INFO字串) +* @param int[3] = output buffer size (buffer的最大長度) +* @param int[4] = [out] return buffer length (回傳buffer的使用長度) +* @param int[5] = [out] return security_code_verify_status +* ( +* 0: this chip_model not supprt security_code (這個晶片不支援此api,標示為不合法晶片), +* 1: existing security_code (合法的security_code), +* 2: not existing security_code (晶片未寫入security_code,標示為不合法晶片), +* 3: invalid_security_code (晶片有寫入security_code,但驗證後不合法), +* 4: skip_security_check(略過security_code的驗證,標示為不合法晶片), +* 5: invalid_security_file_address(有輸入認證檔的位址,但是檔案不合法,) +* 6: id_not_in_security_file(有輸入認證檔的位址,但是uid/mac不在認證檔的清單裡面), +* ) +* @param int[6] = [out] security_code_type (for cyweeMotion debug) +* @param int[7] = [out] security_file_id (認證檔的號碼)(for cyweeMotion debug) +* @param int[8] = reserved +* @param int[9] = [out] chip_vendor +* @param int[10] = [out] cust_id_1 +* @param int[11] = [out] cust_id_2 +*/ +typedef struct get_chip_info_t +{ + + int header ; + int header2 ; + int output_buffer_address; + int output_buffer_size; + int return_buffer_length; + int return_security_code_verify_status; + int security_code_type; + int security_file_id; + int reserved; + int chip_vendor; + int cust_id_1; + int cust_id_2; +}get_chip_info_t; +#else +typedef struct get_chip_info_t +{ + + int header = 1; //( int[0] = 1 + int header2 = 1; // int[1] = 1 + int output_buffer_address; // int[2] = [in/out]output buffer address (buffer的位址,用來接收CHIP_INFO字串) + int output_buffer_size; // int[3] = output buffer size (buffer的最大長度) + int return_buffer_length; + // int[4] = [out] return buffer length (回傳buffer的使用長度) + int return_security_code_verify_status; + // int[5] = [out] return security_code_verify_status ) + // ( + // 0: this chip_model not supprt security_code (這個晶片不支援此api,標示為不合法晶片), + // 1: existing security_code (合法的security_code), + // 2: not existing security_code (晶片未寫入security_code,標示為不合法晶片), + // 3: invalid_security_code (晶片有寫入security_code,但驗證後不合法), + // 4: skip_security_check(略過security_code的驗證,標示為不合法晶片), + // 5: invalid_security_file_address(有輸入認證檔的位址,但是檔案不合法,) + // 6: id_not_in_security_file(有輸入認證檔的位址,但是uid/mac不在認證檔的清單裡面), + // ) + int security_code_type; // int[6] = [out] security_code_type (for cyweeMotion debug) + int security_file_id; // int[7] = [out] security_file_id (認證檔的號碼)(for cyweeMotion debug) + int reserved; // int[8] = reserved + int chip_vendor; // int[9] = [out] chip_vendor + int cust_id_1; // int[10] = [out] cust_id_1 + int cust_id_2; // int[11] = [out] cust_id_2 +}get_chip_info_t; +#endif +/** + * @struct activity_config_t + * +*/ +typedef struct +{ + int header ;// int[0] = 1 + int include_base_calorie;// int[1] = 卡路里計算是否包含基礎卡路里 (default: 不包含基礎卡路里) (0: default, 1:包含基礎卡路里, 2:不包含基礎卡路里) + int use_hrs_calc_calorie;// int[2] = 一般模式1001是否使用心率來計算卡路里 (default: 不使用心率) (0: default, 1: 使用心率, 2:不使用心率) + int calc_calorie_in_static_exercise;// int[3] = 靜態運動時是否持續計算卡路里 (default: 停止計算) (0: default, 1: 持續計算, 2: 停止計算) + int calc_calorie_unwear;// int[4] = 運動模式(包含一般模式1001)時,脫錶後是否持續計算卡路里 (default: 持續計算) (0: default, 1: 持續計算, 2: 停止計算) + int ar_model;// int[5] = ar_model (default: on) (0: default, 1: on, 2: off) + int ar_pedo_mode;// int[6] = ar_pedo_mode (default: 平衡) (0: 平衡, 1: 計步優先, 2: 防誤觸優先) + int calc_calorie_still;// int[7] = 靜止時是否持續計算卡路里 (default: 持續計算) (0: default, 1: 持續計算, 2: 停止計算) + int motionSensScale ;// int[8] = motionSensScale活動量的靈敏度 (default: 4) (0: default, 1: 最靈敏, 2, 3, 4, 5, 6, 7: 最不靈敏) + int axial_direction_judgement ;// int[9] = 軸向判斷 (default: 有軸向判斷) (0: default, 1: 無軸向判斷, 2: 有軸向判斷) + int sensor_noise_level ;// int[10] = 感測器雜訊度等級 (default: 低雜訊) (0: 低雜訊, 1: 高雜訊A, 2 - 4, 5: 高雜訊E) +}activity_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int Lib_Porting_debug ;// int[1] = Lib Porting debug (default: turn_off) (bit control, 0: turn_off, 1: show_heap_malloc_max_used_size, 2: show_stack_max_used_size, 4: skip_custom_input_sensor, 8: skip_output_sensor_callback, 16: skip_drv_input_sensor, 32: skip_other_output_sensor_callback) + int Lib_infomation;// int[2] = Lib infomation (default: turn_off) (bit control, 0: turn off, 1: show_mem_action, 2: show_sensorRegister, 4: show_tid, 8: show_timer) + int Lib_Custom_Option;// int[3] = Lib Custom Option (default: turn_off) (bit control, 0: trun_off, 1: timer_expired_no_catch_up) + int sal_lib_disable_external_user_malloc_api ;// int[4] = sal_lib disable external user malloc api (default: turn_off) (0: turn_off, 1: turn_on) + int reserved;// int[5] = reserved + +}library_debug_control_t; + +typedef struct +{ + int header ;// int[0] = 1 + int floor_Height ;// int[1] = floor_Height (cm)(設定樓層高度)(default: 380cm = 3.8m) (0: default, 150 - 1000) + int Anti_misoperation;// int[2] = Anti-misoperation (一般模式時的防誤計步等級) (default: 4) (0: default, 1: 最容易誤計步, 2, 3, 4:預設等級, 5, 6, 7: 最不容易誤計步) + int distance_pace_step_adjust ;// int[3] = 戶外跑步和一般模式時距離、配速和步距的調整 (default: 4) (0: default, 1: 距離最短, 2, 3, 4:預設, 5, 6, 7:距離最長) + int enable_extra_packet ;// int[4] = enable_extra_packet (default: 不發送) (0: default, 1: 發送, 2: 不發送) + int Treadmill__steps;// int[5] = Treadmill__steps (跑步機校正參數)(steps) (default: 不校正) (0: 不校正) + int Treadmill__average_step_frequency ;// int[6] = Treadmill__average_step_frequency (跑步機校正參數) (steps/minute) (default: 不校正) (0: 不校正) + int Treadmill__uncalibration_distanc;// int[7] = Treadmill__uncalibration_distance (跑步機校正參數)(meters) (default: 不校正) (0: 不校正) + int Treadmill__ground_truth_distance;// int[8] = Treadmill__ground_truth_distance (跑步機校正參數: 真實的跑步距離)(meters) (default: 不校正) (0: 不校正) + int floor_sensitivity;// int[9] = floor_sensitivity (樓層計算嚴謹度)(default: 3) (0: default, 1:寬容, 2, 3, 4, 5, 7: 嚴格) + int avoid_hi_freq_mistouch;// int[10] = 防高頻誤觸 (default: 開啟) (0: default, 1: 開啟, 2: 關閉) + int hi_pace_adjust ;// int[11] = 高步頻走路步距修正 (default: 開啟) (0: default, 1: 開啟, 2: 關閉) + int mid_active_pace_threshold ;// int[12] = 活動程度區間的中度活動步頻 (default: 60) (0: default, 60 - 270) + int hi_active_pace_threshold ;// int[13] = 活動程度區間的高度活動步頻 (default: 120) (0: default, 60 - 270) +}pedometer_config_t; +typedef struct +{ + int header ;// int[0] = 1 + int version1;// int[1] = [out] version1 + int version2;// int[2] = [out] version2 + int version3;// int[3] = [out] version3 + int version4;// int[4] = [out] version4 + int product;// int[5] = [out] product + int model;// int[6] = [out] model + int arch;// int[7] = [out] arch (0: unknown, 1: aml, 2: sal) +}get_lib_version_t; + +typedef struct +{ + int header ;// int[0] = 1 + int ctl_activity_mode;// int[1] = pause/resume activity mode (0: resume, 1: pause) +}activity_pause_t; + +typedef struct +{ + int header ;// int[0] = 1 + int up_range ;// int[1] = up_range (抬手反應範圍)(default: 5) (0: default, 3: 範圍大, 4, 5, 6: 範圍小) + int down_range ;// int[2] = down_range (放手反應範圍)(default: 5) (0: default, 3: 範圍大, 4, 5, 6: 範圍小) + int sensitivity ;// int[3] = sensitivity (反應速度)(default: 5) (0: default, 3: 反應速度快, 4, 5, 6: 反應速度慢) + int horizontal_range ;// int[4] = horizontal_range (亮屏手肘傾斜範圍)(default: 5) (0: default, 1: 範圍大, 2, 3, 4, 5, 6, 7, 8, 9: 範圍小) +}watch_hand_up_down_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int chip_vendor ;// int[1] = chip_vendor (default: auto_detect) (0: default, 1: auto_detect 2: skip_auto_detect) + int cust_id_1 ;// int[2] = cust_id_1 (default: 0) + int cust_id_2 ;// int[3] = cust_id_2 (default: 0) + int reserved;// int[4] = reserved + int security_file_address;// int[5] = security_file_address (驗證檔的記憶體位址) +}chip_vendor_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int reserved;// int[1] = reserved + int use_hrs_judge_sleep_status ;// int[2] = 是否使用心率來判斷睡眠狀態 (default: 不使用心率)(0: default, 1: 使用心率, 2: 不使用心率) + int difficulty_for_falling_asleep ;// int[3] = 入睡難易度 (default: 4)(0: default, 1:不容易入睡, 2, 3, 4:標準, 5, 6, 7:容易入睡) + int difficulty_for_wakeup ;// int[4] = 出睡難易度 (default: 4)(0: default, 1:不容易出睡, 2, 3, 4:標準, 5, 6, 7:容易出睡) + int reserved1;// int[5] = reserved + int difficulty_for_sober ;// int[6] = 清醒難易度 (default: 4)(0: default, 1:不容易清醒, 2, 3, 4:標準, 5, 6, 7:容易清醒) + int hw_sig_level ;// int[7] = 硬體訊號等級 (default: 1) (0: default, 1: 低雜訊, 2, 3, 4, 5, 6, 7: 高雜訊) + int reserved2;// int[8] = reserved + int sleep_interval ;// int[9] = 睡眠間距 (default: 60) (0: default, 1 - 180) + int output_REM_without_hrs;// int[10] = 無心率時是否輸出REM (default: 會輸出REM) (0: default, 1: 禁止輸出REM, 2: 會輸出REM) + int long_nap ;// int[11] = 長時間小睡 (default: turn_off) (0: default, 1: turn_on, 2: turn_off) + int static_active_angle_sensitive;// int[12] = 靜態活動角度靈敏度 (default: 13) (0: default, 1: 較難入睡 - 30: 容易入睡) +}sleep_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int absolute_still_time ;// int[1] = 絕對靜止時間 (seconds) (default: 60) (0: default, 5 - 28800) + int sensitive_level ;// int[2] = 靈敏度等級 (default: 3) (0: default, 1:不容易觸發 - 50:容易觸發) + int AOI_mode_level ;// int[3] = AOI_模式等級 (default: disable) (0: disable, 1 - 30) + int AOI_sensitive_level ;// int[4] = AOI_靈敏度等級 (default: 3) (0: default, 1:不容易觸發 - 50:容易觸發) + int spike_blokcer_cnt ;// int[5] = spike_blokcer_cnt (default: 1)(雜訊屏蔽時間) (0: default, 1:雜訊屏蔽時間短 - 5:雜訊屏蔽時間長) + int spike_blokcer_level ;// int[6] = spike_blokcer_level (default: 1)(雜訊屏蔽等級) (0: default, 1:雜訊屏蔽效果弱 - 99:雜訊屏蔽效果強) +}absolute_static_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int hrs_get_set_flag ;// int[1] = 設定或取得心率極值(default: 設定心率極值) (0: default, 1: 設定心率極值, 2: 取得心率極值) + int max_bpm ;// int[2] = [in/out] 心率最大值(bpm) (default: 不設定) (0: default, 30 - 220) + int min_bpm ;// int[3] = [in/out] 心率最小值(bpm) (default: 不設定) (0: default, 30 - 220) +}heart_rate_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int notify_sport_mode ;// int[1] = 開關動作類型通知功能 (default: turn_off) (0: default, 1: turn on, 2: turn off) + int reserved;// int[2] = reserved + int reserved1;// int[3] = reserved + int alert_ride_time ;// int[4] = alert_ride_time (mintues)(default: 10) (0: default, 5 - 15) + int reserved2;// int[5] = reserved + int reserved3;// int[6] = reserved + int reserved4;// int[7] = reserved + int reserved5;// int[8] = reserved +}ar_alert_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int enable_extra_info_packet;// int[1] = enable_extra_info_packet (default: 不發送) (0: default, 1: 發送, 2: 不發送) + int reserved;// int[2] = reserved + int freq_curve_smooth_grade;// int[3] = 頻率曲線平滑等級 (default: 5) (0: default, 1: 最不平滑, 2, 3, 4, 5, 6, 7, 8, 9, 10: 最平滑) +}workout_machine_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int sensor_noise_level;// int[1] = 感測器雜訊度等級 (default: 低雜訊) (0: 低雜訊, 1: 高雜訊) +}inactivity_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int mode_number;// int[1] = mode_number (需填值) + int auto_time_sleep_on_sed_off;// int[2] = auto_time_sleep_on_sed_off (hours) (0: disable, 1 - 24) + int auto_time_sleep_off_sed_on;// int[3] = auto_time_sleep_off_sed_on (hours) (0: disable, 1 - 24) + int auto_time_sed_off_nap_on;// int[4] = auto_time_sed_off_nap_on (hours) (0: disable, 1 - 24) + int auto_time_nap_off_sed_on;// int[5] = auto_time_nap_off_sed_on (hours) (0: disable, 1 - 24) +}set_inactivity_mode_t; + +typedef struct +{ + int header ; +}activity_exit_t; + +typedef struct +{ + int header ;// int[0] = 1 + int input_odr ;// int[1] = [in/out] 感測器輸入ODR (Hz)(input_odr)(default: 50) (0: default, ODR: 25 - 10000) + int restart_sampling_stage ;// int[2] = 啟用重新取樣流程 (default: turn_on) (0: default, 1: turn_on, 2: turn_off) + int reset_sampling_ODR;// int[3] = [in/out] 重新取樣後ODR (Hz)(default: 依算法而不同) (0: default, ODR: 25 , 50, 100) + int force_restart_sampling ;// int[4] = 強制使用重新取樣 (default: turn_off) (0: default, 1: turn_on, 2: turn_off) + int setting_flag ;// int[5] = 設定欄位 (default: 全部) (bit control 0: default, -1: 全部, 1: input_odr, 2: resample) +}algo_proc_config_t; + +typedef struct +{ + int header ;// int[0] = 1 + int sensor_calibarion_ctl;// int[1] = 啟用感測器校正流程 (default: turn_on) (0: default, 1: turn_on, 2: turn_off) + int sensor_enable_calibration;// int[2] = 感測器強制校正 (default: default_fow) (bit control 0: default_flow, 1: acc, 2:gyro, 4:mag) + int sensor_disable_calibraion;// int[3] = 感測器取消校正 (default: default_fow) (bit control 0: default_flow, 1: acc, 2:gyro, 4:mag) +}sensor_calibration_flow_config_t; + + +typedef struct +{ + int header ;// int[0] =1 + int calibration_data_set_get_flag;// int[1] = 設定或取得校正值(default: 取得校正值) (0: default, 1: 取得校正值, 2: 設定校正值) + int acc_calvalue_x;// int[2] = [in/out] acc_calvalue_x + int acc_calvalue_y;// int[3] = [in/out] acc_calvalue_y + int acc_calvalue_z;// int[4] = [in/out] acc_calvalue_z + int gyro_calvalue_x;// int[5] = [in/out] gyro_calvalue_x + int gyro_calvalue_y;// int[6] = [in/out] gyro_calvalue_y + int gyro_calvalue_z;// int[7] = [in/out] gyro_calvalue_z +}sensor_calibration_control_a_t; + + +typedef struct +{ + int header ;// int[0] = 1 + int setting_flag ;// int[1] = 設定欄位 (default: 全部) (bit control 0: default, -1: 全部, 1: noise_bias_batch, 2: LSB_DPS, 4: stlLevel) + int reserved1 ;// int[2] = 0 + int reserved2 ;// int[3] = 0 + int gyro_Lsb_Dps;// int[4] = gyro_Lsb_Dps (default: 16383750) (0: default, 1 - 1000000000) + int acc_noise;// int[5] = acc_noise (default: 2600) (0: default, 1 - 1000000000) + int gyr_noise;// int[6] = gyr_noise (default: 150000) (0: default, 1 - 1000000000) + int acc_bias;// int[7] = acc_bias (default: 200000) (0: default, 1 - 1000000000) + int gyr_bias;// int[8] = gyr_bias (default: 20000000) (0: default, 1 - 1000000000) + int acc_min_batch_ms;// int[9] = acc_min_batch_ms (default: 1000) (0: default, 1 - 100000) + int gyr_min_batch_ms;// int[10] = gyr_min_batch_ms (default: 4000) (0: default, 1 - 100000) + int acc_stl_level;// int[11] = acc_stl_level (default: 6000000) (0: default, 1 - 1000000000) + int gyr_stl_level;// int[12] = gyr_stl_level (default: 3000000) (0: default, 1 - 1000000000) +}sensor_calibration_set_a_t; + + +typedef struct +{ + int header ;// int[0] =1 + int adjust_value_set_get_flag;// int[1] = 設定或取得校正值(default: 取得校正值) (0: default, 1: 取得校正值, 2: 設定校正值) + int gyro_sens_0;// int[2] = [in/out] gyro_sens_0 + int gyro_sens_1;// int[3] = [in/out] gyro_sens_1 + int gyro_sens_2;// int[4] = [in/out] gyro_sens_2 + int gyro_sens_3;// int[5] = [in/out] gyro_sens_3 + int gyro_sens_4;// int[6] = [in/out] gyro_sens_4 + int gyro_sens_5;// int[7] = [in/out] gyro_sens_5 + int gyro_sens_6;// int[8] = [in/out] gyro_sens_6 + int gyro_sens_7;// int[9] = [in/out] gyro_sens_7 + int gyro_sens_8;// int[10] = [in/out] gyro_sens_8 +}sensor_calibration_control_a2_t; + +typedef struct +{ + int header ;// int[0] =1 + int acc_axis_setting;// int[1] = acc_axis setting (0: default, 1-24: axis_mode) + int mag_axis_setting;// int[2] = mag_axis setting (0: default, 1-24: axis_mode) +}input_sensor_config_t; + +#pragma pack() + + + + + + +/********************CYWEE DML*********************/ + + + + + + + + + int cywee_main_dml(void); void cywee_int_handler(void); diff --git a/code/sdk/drivers/peripheral/cywee/Inc/os_api.h b/code/sdk/drivers/peripheral/cywee/Inc/os_api.h deleted file mode 100644 index 8bdd926e7..000000000 --- a/code/sdk/drivers/peripheral/cywee/Inc/os_api.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __OS_API_H__ -#define __OS_API_H__ - -typedef struct{ - int (*dbgOutput)(const char*); - uint64_t (*GetTimeNs)(void); - void (*uSleep)(uint32_t); - int (*i2cRead)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); - int (*i2cWrite)(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); - void *(*malloc)(int size); - void (*free)(void* ptr); - int (*spiRead)(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); - int (*spiWrite)(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); -} os_api; - -typedef os_api OsAPI; - -#endif /* __OS_API_H__ */ diff --git a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.bk.a b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p3.a similarity index 85% rename from code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.bk.a rename to code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p3.a index 689b04914..4275ca2fb 100644 Binary files a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.bk.a and b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p3.a differ diff --git a/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a b/code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p813.a similarity index 100% rename from code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.a rename to code/sdk/drivers/peripheral/cywee/Lib/CWM_LIB_clang_riscv.p813.a diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c index cc5f976b8..afab4caab 100644 --- a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -39,7 +39,7 @@ typedef struct * 其他cmd在Header里定义,对外开放 */ -#define CYWEE_CHECK_MS 200 +#define CYWEE_CHECK_MS 20 osTimerId_t g_cywee_service_timer = NULL; static bool g_batter_service_initialled = false; @@ -114,7 +114,7 @@ static void cywee_service_check_task(void const *arg) if (mail.cmd == CYWEE_SERVICE_CMD_TIMER_CHECK) { cywee_int_handler(); // lis2doc_read_data(); - printf("CYWEE_SERVICE_CMD_TIMER_CHECK\r\n"); + // printf("CYWEE_SERVICE_CMD_TIMER_CHECK\r\n"); }else if (mail.cmd == CYWEE_SERVICE_CMD_TEST){ test_api(); }else if (mail.cmd == CYWEE_SERVICE_CMD_START_CHECK){ diff --git a/code/sdk/drivers/peripheral/cywee/src/board_apollo3.c b/code/sdk/drivers/peripheral/cywee/src/board_apollo3.c deleted file mode 100644 index 217227327..000000000 --- a/code/sdk/drivers/peripheral/cywee/src/board_apollo3.c +++ /dev/null @@ -1,319 +0,0 @@ -/*********************/ -/*** Include Files ***/ -/*********************/ -#include -#include -#include "am_mcu_apollo.h" -#include "am_bsp.h" -#include "am_util.h" -#include "am_devices_i2c.h" -#include "cwm_lib.h" -#include "config.h" - -/*********************/ -/*** Macro Defines ***/ -/*********************/ -#define CLOCK_FREQ 1000 //It is clock frequency setting. -#define IOM_MODULE_NUMBER 0 -#define IOM_IRQn ((IRQn_Type)(IOMSTR0_IRQn + IOM_MODULE_NUMBER)) - -// -// Take over the interrupt handler for whichever IOM we're using. -// -#define iom_isr \ - am_iom_isr1(IOM_MODULE_NUMBER) -#define am_iom_isr1(n) \ - am_iom_isr(n) -#define am_iom_isr(n) \ - am_iomaster ## n ## _isr - - -/*************************/ -/*** Variables Defines ***/ -/*************************/ -uint32_t DMATCBBuffer[256]; -void *g_pIOMHandle; - -am_hal_iom_config_t g_sIomCfg = -{ - .eInterfaceMode = AM_HAL_IOM_I2C_MODE, - .ui32ClockFreq = AM_HAL_IOM_100KHZ, -}; - -static uint32_t m_tickLast = 0; -static uint64_t m_elpsedTime_us = 0; - - -/************************/ -/*** Function Defines ***/ -/************************/ -int CWM_OS_dbgPrintf(const char * format,...); - - -/********************************/ -/*** Function Implementations ***/ -/********************************/ -void iom_isr(void) -{ - uint32_t ui32Status; - - if (!am_hal_iom_interrupt_status_get(g_pIOMHandle, true, &ui32Status)) - { - if ( ui32Status ) - { - am_hal_iom_interrupt_clear(g_pIOMHandle, ui32Status); - am_hal_iom_interrupt_service(g_pIOMHandle, ui32Status); - } - } -} - -static void I2C_init(void) -{ - g_sIomCfg.ui32NBTxnBufLength = sizeof(DMATCBBuffer) / 4; - g_sIomCfg.pNBTxnBuf = &DMATCBBuffer[0]; - - am_devices_i2c_init(IOM_MODULE_NUMBER, &g_sIomCfg, &g_pIOMHandle); - - return; -} - -static void am_i2c_setting(void) -{ - I2C_init(); - NVIC_EnableIRQ(IOM_IRQn); -} - -static void am_i2c_deinit(void) -{ - am_devices_i2c_term(0); - NVIC_DisableIRQ(IOM_IRQn); -} - -static void APOLLO_I2C_Reset(void) -{ - am_i2c_deinit(); - am_util_delay_ms(20); - am_i2c_setting(); -} - -static void stimer_init(void) -{ - am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREA); - NVIC_EnableIRQ(STIMER_CMPR0_IRQn); - am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE); - am_hal_stimer_compare_delta_set(0, CLOCK_FREQ);//1 second timer - am_hal_stimer_config(AM_HAL_STIMER_LFRC_1KHZ | - AM_HAL_STIMER_CFG_COMPARE_A_ENABLE); - m_tickLast = am_hal_stimer_counter_get(); -} - -static uint64_t platsystickTicksToUs(uint64_t tick) { - return (uint64_t)(tick * 1000000/CLOCK_FREQ); -} - -static inline uint64_t calcElapsedTicks(uint64_t tickNow, uint64_t tickLast) -{ - if(tickNow >= tickLast) - return tickNow - tickLast; - else - return 0xFFFFFFFF - tickLast + tickNow; -} - -static void systickUpdate(void) -{ - //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second - uint64_t tickNow; - uint64_t delta_ticks; - - tickNow = am_hal_stimer_counter_get(); - delta_ticks = calcElapsedTicks(tickNow, m_tickLast); - m_elpsedTime_us += platsystickTicksToUs(delta_ticks); - - m_tickLast = tickNow; -} - -void am_stimer_cmpr0_isr(void) -{ - //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second - systickUpdate(); - - am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREA); - am_hal_stimer_compare_delta_set(0, CLOCK_FREQ);//1 second timer -} - -#define BUS_RETRY_TIMES 3 -#define BUS_RECOVER_TIMES 1 - -int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int argument) -{ - int res; - int rty = BUS_RETRY_TIMES; - int rcovery = BUS_RECOVER_TIMES; - - do{ - res = am_devices_i2c_blocking_read(slaveAddr, reg, readData, readDataSize); - - if(res == 0) - break; - - rty --; - if(rcovery > 0) - { - if(rty == 0) - { - rty = BUS_RETRY_TIMES; - rcovery --; - APOLLO_I2C_Reset(); - } - } - }while(rty > 0); - - - return (res>0) ? res*-1: res; -} - -int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int argument) -{ - int res; - int rty = BUS_RETRY_TIMES; - int rcovery = BUS_RECOVER_TIMES; - - do{ - res = am_devices_i2c_blocking_write(slaveAddr, reg, writeData, writeDataSize); - - if(res == 0) - break; - - rty --; - if(rcovery > 0) - { - if(rty == 0) - { - rty = BUS_RETRY_TIMES; - rcovery --; - APOLLO_I2C_Reset(); - } - } - }while(rty > 0); - - return (res>0) ? res*-1: res; -} - -int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int argument) -{ - am_hal_iom_transfer_t desc; - memset(&desc, 0, sizeof(am_hal_iom_transfer_t)); - - desc.ui32InstrLen = regLength; - desc.ui32Instr = reg; - desc.uPeerInfo.ui32I2CDevAddr = slaveAddr >> 1; - desc.ui8RepeatCount = 0; - desc.ui32PauseCondition = 0; - desc.ui32StatusSetClr = 0; - desc.bContinue = false; - - if (readDataSize == 0) { - if (writeDataSize == 0 || writeData == NULL) - return -1; - - // write mode - desc.eDirection = AM_HAL_IOM_TX; - desc.ui32NumBytes = writeDataSize; - desc.pui32TxBuffer = (uint32_t *) writeData; - } - else { - if (readData == NULL) - return -1; - - // read mode - desc.eDirection = AM_HAL_IOM_RX; - desc.ui32NumBytes = readDataSize; - desc.pui32RxBuffer = (uint32_t *) readData; - } - - return am_hal_iom_blocking_transfer(g_pIOMHandle, &desc); -} - -void CWM_OS_uSleep(uint32_t time) -{ - uint32_t ms = time / 1000; - - if (ms == 0) - ms = 1; - am_util_delay_ms(ms); -} - -uint64_t CWM_OS_GetTimeNs(void) -{ - uint64_t tickNow; - uint64_t delta_ticks; - uint64_t timeNow_us; - - tickNow = am_hal_stimer_counter_get(); - delta_ticks = calcElapsedTicks(tickNow, m_tickLast); - timeNow_us = m_elpsedTime_us + platsystickTicksToUs(delta_ticks); - - return timeNow_us * 1000; -} - -void* CWM_OS_malloc(int size) -{ - if (size == 0) - size = 1; - return malloc(size); -} - -void CWM_OS_free(void *ptr) -{ - if (ptr == NULL) - return; - - free(ptr); -} - -int CWM_OS_dbgOutput(const char * format) -{ - am_util_stdio_printf("%s", format); - return 0; -} - -int CWM_OS_dbgOutput_checkLog(const char * format) -{ - static int s_sn = 0; - - am_util_stdio_printf("#_#|%d|%s", s_sn, format); - s_sn ++; - return 0; -} - -int CWM_OS_dbgPrintf(const char * format,...) -{ - char InputBuff[255]; - va_list args; - - va_start(args, format); - am_util_stdio_vsprintf(InputBuff, format, args); - va_end(args); - CWM_OS_dbgOutput(InputBuff); - return 0; -} - -void board_init(void) -{ - am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_SYSCLK_MAX, 0); //Set the clock frequency. - am_hal_cachectrl_config(&am_hal_cachectrl_defaults); //default cache configuration - am_hal_cachectrl_enable(); - am_bsp_low_power_init(); //Configure the board for low power operation. - -#ifdef PRINTF_FROM_UART - am_bsp_uart_printf_enable(); //Enable the UART print interface. -#else - am_bsp_itm_printf_enable(); //Enable the ITM print interface. Using "SWO Viewer" to show log -#endif - am_util_stdio_terminal_clear(); //Clear the terminal and print the banner. - am_i2c_setting(); - am_hal_interrupt_master_enable(); - - stimer_init(); //Timer Init -} - diff --git a/code/sdk/drivers/peripheral/cywee/src/board_nordic.c b/code/sdk/drivers/peripheral/cywee/src/board_nordic.c deleted file mode 100644 index 1e1373eff..000000000 --- a/code/sdk/drivers/peripheral/cywee/src/board_nordic.c +++ /dev/null @@ -1,479 +0,0 @@ -/*********************/ -/*** Include Files ***/ -/*********************/ -#include -#include "boards.h" -#include "app_util_platform.h" -#include "nrf_delay.h" -#include "nrf_drv_timer.h" -#include "nrf_log.h" -#include "nrf_log_ctrl.h" -#include "nrf_log_default_backends.h" -#include "nrf_drv_twi.h" -#include "pca10040.h" -#include "cwm_lib.h" -#include "config.h" -#include "nrf_drv_clock.h" -#include "app_timer.h" -#include "nrf_drv_gpiote.h" - - -/*********************/ -/*** Macro Defines ***/ -/*********************/ -#define PCA10040_PIN_25 25 -#define PCA10040_PIN_28 28 -#define BUS_RETRY_TIMES 3 -#define BUS_RECOVER_TIMES 1 -#define TWI_INSTANCE_ID 0 -#define TIMER_PERIOD_1_SEC APP_TIMER_TICKS(1000) - -/*************************/ -/*** Variables Defines ***/ -/*************************/ -nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID); - -static uint64_t m_tickLast = 0; -static uint64_t m_elpsedTime_us = 0; -APP_TIMER_DEF(m_one_sec_timer); - -typedef struct -{ - uint16_t sensorType; - uint16_t sensorPin; - uint16_t mcuPin; - uint16_t mcu_int_method; - uint16_t mcu_int_connect; - PFN_IRQHANDLE callback; -} irq_item; - -typedef struct -{ - uint16_t sensorType; - uint16_t sensorPin; -} irq_argument; - -static irq_item m_irqHandler[] = -{ - { - .sensorType = CUSTOM_ACC, - .sensorPin = PIN_INT1, - .mcuPin = PCA10040_PIN_25, - .mcu_int_method = INT_TRIGGER_TYPE_FALLING, - .mcu_int_connect = INT_RESISTOR_NOPULL, - .callback = NULL, - }, - { - .sensorType = CUSTOM_ACC, - .sensorPin = PIN_INT2, - .mcuPin = PCA10040_PIN_28, - .mcu_int_method = INT_TRIGGER_TYPE_RISING, - .mcu_int_connect = INT_RESISTOR_PULLDOWN, - .callback = NULL, - }, -}; - - -/************************/ -/*** Function Defines ***/ -/************************/ -int CWM_OS_dbgPrintf(const char * format,...); - - -/********************************/ -/*** Function Implementations ***/ -/********************************/ -static void I2C_Init_Nordic(void) -{ - const nrf_drv_twi_config_t twi_config = { - .scl = ARDUINO_SCL_PIN, - .sda = ARDUINO_SDA_PIN, - .frequency = NRF_DRV_TWI_FREQ_400K, - .interrupt_priority = APP_IRQ_PRIORITY_HIGH, - .clear_bus_init = false - }; - - nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL); - nrf_drv_twi_enable(&m_twi); -} - -static void I2C_Uninit_Nordic(void) -{ - nrf_drv_twi_uninit(&m_twi); - *(volatile uint32_t *)0x40003FFC = 0; - *(volatile uint32_t *)0x40003FFC; - *(volatile uint32_t *)0x40003FFC = 1; -} - -static void I2C_Reset_Nordic(void) -{ - I2C_Uninit_Nordic(); - I2C_Init_Nordic(); -} - -static inline uint64_t calcElapsedTicks(uint64_t tickNow, uint64_t tickLast) -{ - if(tickNow >= tickLast) - return tickNow - tickLast; - else - return APP_TIMER_MAX_CNT_VAL - tickLast + tickNow; //Nordic RTC resolution is 24 bit, APP_TIMER_MAX_CNT_VAL = 0x00FFFFFF -} - -static uint64_t platsystickTicksToUs(uint64_t tick) { - return (uint64_t)(tick * 1000000 / APP_TIMER_CLOCK_FREQ); -} - -static void systickUpdate() -{ - //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second - uint64_t tickNow; - uint64_t delta_ticks; - - tickNow = app_timer_cnt_get(); - delta_ticks = calcElapsedTicks(tickNow, m_tickLast); - m_elpsedTime_us += platsystickTicksToUs(delta_ticks); - m_tickLast = tickNow; -} - -static void one_sec_timer_handle(void * p_context) -{ - //To implement the CWM_OS_GetTimeNs(), this function needs to be triggered every second - systickUpdate(); -} - -static void timer_init(void) -{ - ret_code_t ret; - - ret = nrf_drv_clock_init(); - APP_ERROR_CHECK(ret); - - nrf_drv_clock_lfclk_request(NULL); - - ret = app_timer_init(); - APP_ERROR_CHECK(ret); - - ret = app_timer_create(&m_one_sec_timer, APP_TIMER_MODE_REPEATED, one_sec_timer_handle); - APP_ERROR_CHECK(ret); - - ret = app_timer_start(m_one_sec_timer, TIMER_PERIOD_1_SEC, NULL);//1 second timer - APP_ERROR_CHECK(ret); -} - -static void nordic_system_init(void) -{ - bsp_board_init(BSP_INIT_NONE); - APP_ERROR_CHECK(NRF_LOG_INIT(NULL)); - NRF_LOG_DEFAULT_BACKENDS_INIT(); - I2C_Init_Nordic(); -} - -void Irq_callback(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) -{ - for (int i=0; i> 1, (uint8_t*) ®, regLength, true); - if (res == NRF_SUCCESS) { - nrf_drv_twi_rx(&m_twi, slaveAddr >> 1, readData, readDataSize); - } - - if(res != 0) - break; - - rty --; - if(rcovery > 0) - { - if(rty == 0) - { - rty = BUS_RETRY_TIMES; - rcovery --; - I2C_Reset_Nordic(); - } - } - }while(rty > 0); - - - return (res>0) ? res*-1: res; -} - -int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int argument) -{ - int res; - int rty = BUS_RETRY_TIMES; - int rcovery = BUS_RECOVER_TIMES; - - do{ - uint8_t data[20]; - memset(data, 0, sizeof(data)); - - if (writeDataSize + 1 > sizeof(data)) { - return -1; - } - - memcpy(data, ®, regLength); - memcpy(&data[regLength], writeData, writeDataSize); - res = nrf_drv_twi_tx(&m_twi, slaveAddr >> 1, data, writeDataSize + regLength, false); - - if(res != 0) - break; - - rty --; - if(rcovery > 0) - { - if(rty == 0) - { - rty = BUS_RETRY_TIMES; - rcovery --; - I2C_Reset_Nordic(); - } - } - }while(rty > 0); - - return (res>0) ? res*-1: res; -} - -int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int argument) -{ - uint8_t writeBuf[20]; - memset(writeBuf, 0, sizeof(writeBuf)); - - nrf_drv_twi_xfer_desc_t desc; - memset(&desc, 0, sizeof(nrf_drv_twi_xfer_desc_t)); - - desc.address = slaveAddr >> 1; - memcpy(writeBuf, ®, regLength); - desc.primary_length = regLength; - - if (readDataSize == 0) { - if (writeDataSize == 0 || writeData == NULL) - return -1; - - // write mode - memcpy(writeBuf + regLength, writeData, writeDataSize); - desc.primary_length += writeDataSize; - desc.type = NRF_DRV_TWI_XFER_TX; - } else { - if (readData == NULL) - return -1; - - // read mode - desc.type = NRF_DRV_TWI_XFER_TXRX; - } - - desc.p_primary_buf = writeBuf; - desc.secondary_length = readDataSize; - desc.p_secondary_buf = readData; - - return nrf_drv_twi_xfer(&m_twi, &desc, 0); -} - -void CWM_OS_uSleep(uint32_t time) -{ - uint32_t ms = time / 1000; - - if (ms == 0) - ms = 1; - nrf_delay_ms(ms); -} - -uint64_t CWM_OS_GetTimeNs(void) -{ - uint64_t tick; - uint64_t delta_ticks; - uint64_t timeNow_us; - - tick = app_timer_cnt_get(); - delta_ticks = calcElapsedTicks(tick, m_tickLast); - timeNow_us = m_elpsedTime_us + platsystickTicksToUs(delta_ticks); - - return timeNow_us * 1000; -} - -void* CWM_OS_malloc(int size) -{ - if (size == 0) - size = 1; - return malloc(size); -} - -void CWM_OS_free(void *ptr) -{ - if (ptr == NULL) - return; - - free(ptr); -} - -int CWM_OS_dbgOutput(const char * format) -{ - NRF_LOG_INFO("%s", format); - NRF_LOG_FLUSH(); - - return 0; -} - -int CWM_OS_dbgOutput_checkLog(const char * format) -{ - static int s_sn = 0; - - NRF_LOG_INFO("#_#|%d|%s", s_sn, format); - s_sn ++; - NRF_LOG_FLUSH(); - - return 0; -} - -int CWM_OS_dbgPrintf(const char * format,...) -{ - char InputBuff[255]; - va_list args; - - va_start(args, format); - - vsprintf(InputBuff, format, args); - - va_end(args); - CWM_OS_dbgOutput(InputBuff); - return 0; -} - -void board_init(void) -{ - nordic_system_init(); - timer_init(); -} diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index e2802261a..495c3848b 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -63,13 +63,13 @@ int gpio_int_pin_init(void) if ((uapi_pin_set_mode(G_INT1_PIN, (pin_mode_t)HAL_PIO_FUNC_GPIO) != ERRCODE_SUCC) || (uapi_pin_set_pull(G_INT1_PIN, (pin_pull_t)HAL_PIO_PULL_UP) != ERRCODE_SUCC) || (uapi_gpio_set_dir(G_INT1_PIN, GPIO_DIRECTION_INPUT) != ERRCODE_SUCC)) { - PRINT_ERR("gpio G_INT1_PIN config failed\r\n"); + CWM_OS_dbgPrintf("gpio G_INT1_PIN config failed\r\n"); return ERRCODE_FAIL; } if ((uapi_pin_set_mode(G_INT2_PIN, (pin_mode_t)HAL_PIO_FUNC_GPIO) != ERRCODE_SUCC) || (uapi_pin_set_pull(G_INT2_PIN, (pin_pull_t)HAL_PIO_PULL_UP) != ERRCODE_SUCC) || (uapi_gpio_set_dir(G_INT2_PIN, GPIO_DIRECTION_INPUT) != ERRCODE_SUCC)) { - PRINT_ERR("gpio G_INT2_PIN config failed\r\n"); + CWM_OS_dbgPrintf("gpio G_INT2_PIN config failed\r\n"); return ERRCODE_FAIL; } return ERRCODE_SUCC; @@ -95,15 +95,19 @@ static errcode_t cywee_i2c_init(void) errcode_t result; /* init i2c */ if ( g_cywee_installed == 1 ) + { + // CWM_OS_dbgPrintf("cywee cywee_i2c_init already installed \n"); return ERRCODE_SUCC; + } + result = uapi_i2c_master_init(CYWEE_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ if (result != ERRCODE_SUCC) { - PRINT_ERR("cywee i2c init fail! ret=0x%x", result); + CWM_OS_dbgPrintf("cywee i2c init fail! ret=0x%x\n", result); return ERRCODE_FAIL; } - PRINT_DEBUG("cywee:i2c_id = %d i2c_speed = %d \r\n", CYWEE_I2C_BUS, 400000); + CWM_OS_dbgPrintf("cywee:i2c_id = %d i2c_speed = %d \r\n", CYWEE_I2C_BUS, 400000); g_cywee_installed = 1; @@ -120,7 +124,7 @@ int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *rea write_data = (uint8_t *)osal_kmalloc(regLength, OSAL_GFP_KERNEL); if (write_data == NULL) { - PRINT_ERR("cywee send buff malloc fail!"); + CWM_OS_dbgPrintf("cywee send buff malloc fail! %d\n",regLength); goto error; } @@ -139,13 +143,13 @@ int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *rea data.receive_len = readDataSize; for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { - ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, CYWEE_I2C_RETRY_TIME_MAX, &data); + ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, slaveAddr, &data); if (ret == ERRCODE_SUCC) { break; } } if (ret != ERRCODE_SUCC) { - PRINT_ERR("cywee data read fail! ret=0x%x", ret); + CWM_OS_dbgPrintf("CWM_OS_i2cRead cywee data read fail! busIndex %d, slaveAddr 0x%x, regaddr 0x%X,reglength %d, ret=0x%x\n",busIndex, slaveAddr,reg,regLength, ret); } osal_kfree(write_data); error: @@ -166,7 +170,7 @@ int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *wr send_len = data_len + regLength; write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); if (write_data == NULL) { - PRINT_ERR("cywee send buff malloc fail!"); + CWM_OS_dbgPrintf("cywee CWM_OS_i2cWrite send buff malloc fail %d!\n",send_len); goto error; } @@ -179,7 +183,7 @@ int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *wr } ret = (uint32_t)memcpy_s(write_data + regLength, send_len - regLength, data_buf, data_len); if (ret != EOK) { - PRINT_ERR("cywee send_buf content copy fail! ret=0x%x", ret); + CWM_OS_dbgPrintf("cywee send_buf content copy fail! ret=0x%x\n", ret); goto free_mem; } @@ -195,7 +199,7 @@ int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *wr } } if (ret != ERRCODE_SUCC) { - PRINT_ERR("cywee data write fail! ret=0x%x", ret); + CWM_OS_dbgPrintf("CWM_OS_i2cWrite cywee data write fail! ret=0x%x\n", ret); } free_mem: osal_kfree(write_data); @@ -229,7 +233,7 @@ int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t ret = (uint32_t)memcpy_s(write_data + regLength, writeDataSize, writeData, writeDataSize); if (ret != EOK) { - PRINT_ERR("cywee send_buf content copy fail! ret=0x%x", ret); + CWM_OS_dbgPrintf("cywee send_buf content copy fail! ret=0x%x\n", ret); goto free_mem; } data.send_buf = write_data; @@ -238,13 +242,13 @@ int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t data.receive_len = readDataSize; for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { - ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, CYWEE_I2C_RETRY_TIME_MAX, &data); + ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, slaveAddr, &data); if (ret == ERRCODE_SUCC) { break; } } if (ret != ERRCODE_SUCC) { - PRINT_ERR("cywee data read fail! ret=0x%x", ret); + CWM_OS_dbgPrintf("CWM_OS_i2cTransfer cywee data read fail! ret=0x%x\n", ret); } free_mem: @@ -311,13 +315,9 @@ int CWM_OS_dbgPrintf(const char * format,...) return 0; } -int CWM_OS_spiRead(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex) { - uint8_t ret; - return ret; -} - -int CWM_OS_spiWrite(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) { - uint8_t ret; +void CWM_OS_saveData(uint8_t* data, uint32_t len){ - return ret; } +void CWM_OS_restoreData(uint8_t* data, uint32_t len){ + +} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/cywee/src/main.c b/code/sdk/drivers/peripheral/cywee/src/main.c index f465b6cf7..d2528c48a 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main.c +++ b/code/sdk/drivers/peripheral/cywee/src/main.c @@ -1,184 +1,56 @@ -/*********************/ -/*** Include Files ***/ -/*********************/ - - -#if 1 - -#include "cwm_lib.h" -#include "CWM_EventStructure.h" -#include "CWM_CustomDataStruct.h" -#include "os_api.h" -#include -#include -#include - -/*********************/ -/*** Macro Defines ***/ -/*********************/ - - -/*************************/ -/*** Variables Defines ***/ -/*************************/ - - -/************************/ -/*** Function Defines ***/ -/************************/ -extern int CWM_OS_dbgOutput(const char * format); -extern int CWM_OS_dbgPrintf(const char * format,...); -#define IDX_ALGO_ACTIVITY_OUTPUT 14 - -extern void CWM_AP_SensorListen(SensorEVT_t *sensorEVT) ; - -void CWM_lib_init(void) { - os_api api = { - .dbgOutput = CWM_OS_dbgOutput, - }; - CWM_LibPreInit(&api); - - - SettingControl_t scl; - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - // scl.iData[3] = 1; - scl.iData[4] = 1 + 4; - CWM_SettingControl(SCL_LOG, &scl); - - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - CWM_SettingControl(SCL_GET_LIB_INFO, &scl); - printf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]); - - printf("[DBG] ach: %d\n", scl.iData[7]); - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 2; //chip vendor, 0:defualt auto detect, 1:auto detect, 2:skip auto detect - CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl); - - CWM_LibPostInit(CWM_AP_SensorListen); - // CWM_LibPostInit(NULL); - - CWM_Sensor_Enable(IDX_REQUEST_SENSOR); - CWM_Sensor_Enable(IDX_ACCEL); - CWM_Sensor_Enable(IDX_GYRO); - CWM_Sensor_Enable(IDX_ALGO_ACTIVITY_OUTPUT); - - memset(&scl, 0, sizeof(scl)); - scl.iData[0] = 1; - scl.iData[1] = 1001; - CWM_SettingControl(SCL_SET_ACTIVITY_MODE, &scl); -} - - - -#else - +#include #include -#include #include +#include #include "cwm_lib.h" -#include "config.h" -#ifdef SIGNAL_SIMULATE_PROCESS -#include "simulate_signal.h" -#endif - - -/*************************/ -/*** Variables Defines ***/ -/*************************/ +int CWM_OS_dbgOutput(const char * format) { + printf("%s", format); + return 0; +} -static const char* REQ_SENS_NAME[] = {"acc", "gyro", "mag", "baro", "temp", "hr", "gnss", "ob", "oc", "accany"}; -static int m_req_sensor_state = 0; +int CWM_OS_dbgPrintf(const char * format,...) { + va_list argList; + int size = 0; + static char tBuffer[256]; + va_start(argList, format); + size = vsnprintf(tBuffer, sizeof(tBuffer), format, argList); + va_end(argList); + //strcat(tBuffer, "\n"); + CWM_OS_dbgOutput(tBuffer); + return size; +} -/************************/ -/*** Function Defines ***/ -/************************/ +uint64_t CWM_OS_GetTimeNs(void) { + uint64_t timeNow_us; -extern void board_init(void); -extern void CWM_OS_uSleep(uint32_t time); -extern uint64_t CWM_OS_GetTimeNs(void); -extern void* CWM_OS_malloc(int size); -extern void CWM_OS_free(void *ptr); -extern int CWM_OS_dbgOutput(const char * format); -extern int CWM_OS_dbgOutput_checkLog(const char * format); -extern int CWM_OS_dbgPrintf(const char * format,...); -extern void test_api(void); + timeNow_us = 0; -/********************************/ -/*** Function Implementations ***/ -/********************************/ -int getReqSensor(int index) { - if (m_req_sensor_state & (1<sensorType) { - case IDX_REQUEST_SENSOR: - if (sensorEVT->fData[2] != 0) - m_req_sensor_state |= (1<<(int)sensorEVT->fData[1]); - else - m_req_sensor_state &= ~(1<<(int)sensorEVT->fData[1]); - - CWM_OS_dbgPrintf("req_sensor input_sensor: %s(%.1f), switch: %.1f\n",\ - REQ_SENS_NAME[(int)sensorEVT->fData[1]], sensorEVT->fData[1], sensorEVT->fData[2]); - CWM_OS_dbgPrintf("input_sensor now: acc=%d gyro=%d mag=%d baro=%d temp=%d hr=%d gnss=%d ob=%d oc=%d accany=%d\n",\ - getReqSensor(0), getReqSensor(1), getReqSensor(2), getReqSensor(3), getReqSensor(4),\ - getReqSensor(5), getReqSensor(6), getReqSensor(7), getReqSensor(8), getReqSensor(9)); - break; - - case IDX_ACCEL: - CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f\n", "accel", + case 0: + CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", sensorEVT->fData[0], sensorEVT->fData[1], - sensorEVT->fData[2]); - break; + sensorEVT->fData[2] + ); + break; - case IDX_ALGO_ACTIVITY_OUTPUT: - CWM_OS_dbgPrintf("%s: %.4f, %.4f, %.4f, %.4f, "\ - "%.4f, %.4f, %.4f, %.4f, "\ - "%.4f, %.4f, %.4f, %.4f, "\ - "%.4f, %.4f, %.4f, %.4f\n", "activity output", + case 1: + CWM_OS_dbgPrintf("gyro: x=%.3f, y=%.3f, z=%.3f\n", sensorEVT->fData[0], sensorEVT->fData[1], - sensorEVT->fData[2], - sensorEVT->fData[3], - sensorEVT->fData[4], - sensorEVT->fData[5], - sensorEVT->fData[6], - sensorEVT->fData[7], - sensorEVT->fData[8], - sensorEVT->fData[9], - sensorEVT->fData[10], - sensorEVT->fData[11], - sensorEVT->fData[12], - sensorEVT->fData[13], - sensorEVT->fData[14], - sensorEVT->fData[15]); - break; + sensorEVT->fData[2] + ); + break; default: - CWM_OS_dbgPrintf("%d: %.4f, %.4f, %.4f, %.4f, "\ - "%.4f, %.4f, %.4f, %.4f, "\ - "%.4f, %.4f, %.4f, %.4f, "\ - "%.4f, %.4f, %.4f, %.4f", sensorEVT->sensorType, + CWM_OS_dbgPrintf("IDX[%d]: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", sensorEVT->sensorType, sensorEVT->fData[0], sensorEVT->fData[1], sensorEVT->fData[2], @@ -186,137 +58,32 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { sensorEVT->fData[4], sensorEVT->fData[5], sensorEVT->fData[6], - sensorEVT->fData[7], - sensorEVT->fData[8], - sensorEVT->fData[9], - sensorEVT->fData[10], - sensorEVT->fData[11], - sensorEVT->fData[12], - sensorEVT->fData[13], - sensorEVT->fData[14], - sensorEVT->fData[15]); - break; + sensorEVT->fData[7] + ); } } -#ifdef SIGNAL_SIMULATE_PROCESS -#define SIGNAL_SIMULATE_FIFO_COUNT 10 - -static void sample_fifo_input_data(time_axis_data *taxis) { - int i; - float acc[3]; - CWM_CustomSensorInput_Fifo_Start(CUSTOM_ACC, - simulate_fake_get_time_ns(), - 20 * 1000000); - - for (i=0; i 0) { - /* Do Low power process here - */ - - CWM_OS_uSleep(next_duration / 1000); + scl.iData[3] = 3; + scl.iData[4] = 15 + 64; + //scl.iData[6] = 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384; + //CWM_SettingControl(SCL_LOG, &scl); + + CWM_Sensor_Enable(0); //IDX_ACCEL + CWM_Sensor_Enable(1); //IDX_GYRO + +/* + CWM_Sensor_Disable(0); + CWM_Sensor_Disable(1); +*/ + + for (loopIndex = 0; loopIndex < 101; loopIndex ++) { + int dt_us; + + dt_us = 20000; + + CustomSensorData csd; + + memset(&csd, 0, sizeof(CustomSensorData)); + csd.sensorType = CUSTOM_ACC; + csd.fData[0] = 0; + csd.fData[1] = 0; + csd.fData[2] = 9.80665; + CWM_CustomSensorInput(&csd); + + memset(&csd, 0, sizeof(CustomSensorData)); + csd.sensorType = CUSTOM_GYRO; + csd.fData[0] = 0; + csd.fData[1] = 0; + csd.fData[2] = -3.1415926; + CWM_CustomSensorInput(&csd); + + ret = CWM_process2(dt_us); + if (ret < 0) { + CWM_OS_dbgPrintf("FATAL ERROR! ret=%d\n", ret); } - - CWM_process(); } + + return 0; } -#endif diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index e71c3e729..3015059e7 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -4,37 +4,149 @@ #include #include #include - +#include "cywee_hal.h" #define AP_ENABLE_DML_SDO_LISTEN -extern uint64_t CWM_OS_GetTimeNs(void); -extern int CWM_OS_dbgOutput(const char * format); -extern int CWM_OS_dbgPrintf(const char * format,...); -extern void CWM_OS_uSleep(unsigned int udelay); -extern int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); -extern int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); -extern int CWM_OS_spiRead(uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); -extern int CWM_OS_spiWrite(uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { switch (sensorEVT->sensorType) { - case 0: + case IDX_ACCEL: + #if 0 CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", sensorEVT->fData[0], sensorEVT->fData[1], sensorEVT->fData[2] ); + #endif break; - case 1: + case IDX_GYRO: CWM_OS_dbgPrintf("gyro: x=%.3f, y=%.3f, z=%.3f\n", sensorEVT->fData[0], sensorEVT->fData[1], sensorEVT->fData[2] ); break; + case IDX_MAG: + CWM_OS_dbgPrintf("mag:x=%.3f , y=%.3f, z=%.3f, accuracy=%.3f\n",sensorEVT->fData[0], + sensorEVT->fData[1], + sensorEVT->fData[2], + sensorEVT->fData[3]); + + break; + case IDX_HEARTRATE: + CWM_OS_dbgPrintf("IDX_HEARTRATE\n"); + break; + case IDX_OFFBODY_DETECT: + CWM_OS_dbgPrintf("IDX_OFFBODY_DETECT\n"); + break; + case IDX_ALGO_SEDENTARY: + CWM_OS_dbgPrintf("IDX_ALGO_SEDENTARY\n"); + + break; + case IDX_ALGO_WATCH_HANDUP: + CWM_OS_dbgPrintf("HANDUP_DOWN MSG [%d]\n",(int)sensorEVT->fData[1]); + + break; + case IDX_ALGO_SLEEP: + CWM_OS_dbgPrintf("IDX_ALGO_SLEEP\n"); + break; + case IDX_REQUEST_SENSOR: + CWM_OS_dbgPrintf("IDX_REQUEST_SENSOR input_sensor[%d][%s] (0: acc, 1: gyro, 2: mag, 3: baro, 4: temperature, 5: heart_rate, 6: GNSS(GPS), 7: off-body detect 8: on-charging detect 9: acc_any_motion)\n", + (int)sensorEVT->fData[1], + (int)sensorEVT->fData[2]==0?"off":"on"); + CustomSensorData csd; + if((int)sensorEVT->fData[1] == CUSTOM_OFFBODY_DETECT) + { + // [0] = off-body state +// (0: device is off-body(未戴身上) , 1: device is on-body(戴在身上)) + memset(&csd, 0, sizeof(CustomSensorData)); + csd.sensorType = CUSTOM_OFFBODY_DETECT; + csd.fData[0] = 1; + CWM_CustomSensorInput(&csd); + } + if((int)sensorEVT->fData[1] == CUSTOM_ON_CHARGING) + { + // [0] = On-Charging state +// (0: 裝置未連接充電裝置, 1: 裝置連接充電裝置) + memset(&csd, 0, sizeof(CustomSensorData)); + csd.sensorType = CUSTOM_ON_CHARGING; + csd.fData[0] = 0; + CWM_CustomSensorInput(&csd); + } + + break; + case IDX_ALGO_SHAKE: + CWM_OS_dbgPrintf("IDX_ALGO_SHAKE\n"); + break; + case IDX_ALGO_ACTIVITY_OUTPUT: + if((int)sensorEVT->fData[0] == 100) + { + CWM_OS_dbgPrintf("average step frequency[%d], average step length[%d], average pace[%d], max step frequency[%d], max pace[%d]\n", + (int)sensorEVT->fData[1], + (int)sensorEVT->fData[2], + (int)sensorEVT->fData[3], + (int)sensorEVT->fData[4], + (int)sensorEVT->fData[5]); + }else{ + CWM_OS_dbgPrintf("activity_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d]\n", + (int)sensorEVT->fData[0], + (int)sensorEVT->fData[1], + (int)sensorEVT->fData[2], + (int)sensorEVT->fData[3], + (int)sensorEVT->fData[5], + (int)sensorEVT->fData[6], + (int)sensorEVT->fData[7], + (int)sensorEVT->fData[8], + (int)sensorEVT->fData[14]); + } + +// [0] = activity_mode (1001~1xxx) +// [1] = steps (steps)(步數) +// [2] = distance (meters)(距離) +// [3] = calories (Kcal)(卡路里) +// [4] = reserved +// [5] = step frequency (steps/minute)(步頻) +// [6] = step length (meters)(步長)(步幅) +// [7] = pace (minutes/Km)(配速) +// [8] = BMR calories (Kcal)(基礎卡路里) +// [9] = current elevation (meters) (海拔高度,需要氣壓計) +// [10] = floors up (floors) (爬升樓層,需要氣壓計) +// [11] = floors down (floors) (下降樓層,需要氣壓計) +// [12] = elevation up (meters) (爬升高度,需要氣壓計) +// [13] = elevation down (meters) (下降高度,需要氣壓計) +// [14] = is_pause (是否暫停活動) +// (0: 活動中, 1: 暫停活動) + break; + case IDX_ALGO_ANY_MOTION: + CWM_OS_dbgPrintf("IDX_ALGO_ANY_MOTION\n"); + break; + case IDX_ALGO_NO_MOTION: + CWM_OS_dbgPrintf("IDX_ALGO_NO_MOTION\n"); + break; + case IDX_ALGO_FALLING: + CWM_OS_dbgPrintf("IDX_ALGO_FALLING\n"); + break; + case IDX_ONCHARGING_DETECT: + CWM_OS_dbgPrintf("IDX_ONCHARGING_DETECT\n"); + break; + case IDX_ALGO_ABSOLUTE_STATIC: + CWM_OS_dbgPrintf("IDX_ALGO_ABSOLUTE_STATIC\n"); + break; + case IDX_ALGO_SPV: + CWM_OS_dbgPrintf("IDX_ALGO_SPV\n"); + break; + case IDX_ALGO_SENS_CALIBRATION: + CWM_OS_dbgPrintf("IDX_ALGO_SENS_CALIBRATION\n"); + break; + case IDX_ALGO_STAND: + CWM_OS_dbgPrintf("IDX_ALGO_STAND\n"); + break; + case IDX_ALGO_SENS_RANGE_DETECT: + CWM_OS_dbgPrintf("IDX_ALGO_SENS_RANGE_DETECT\n"); + break; default: CWM_OS_dbgPrintf("IDX[%d]: %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\n", sensorEVT->sensorType, sensorEVT->fData[0], @@ -53,10 +165,10 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo) { if (pSdo->validData & DML_SENSOR_DATA_VALID_DT) - CWM_OS_dbgPrintf("dt: %d us\n", pSdo->dt_us); + CWM_OS_dbgPrintf("==dt: %d us\n", pSdo->dt_us); if (pSdo->validData & DML_SENSOR_DATA_VALID_ACC) - CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", pSdo->acc_data[0], pSdo->acc_data[1], pSdo->acc_data[2]); + CWM_OS_dbgPrintf("==acc: x=%.3f, y=%.3f, z=%.3f\n", pSdo->acc_data[0], pSdo->acc_data[1], pSdo->acc_data[2]); } #endif static int cywee_installized = 0 ; @@ -76,28 +188,53 @@ int cywee_main_dml(void) { scl.iData[0] = 1; CWM_SettingControl(SCL_GET_LIB_INFO, &scl); CWM_OS_dbgPrintf("version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]); - + CWM_OS_dbgPrintf("[DBG] ach: %d\n", scl.iData[7]); os_api api = { .GetTimeNs = CWM_OS_GetTimeNs, .dbgOutput = CWM_OS_dbgOutput, .i2cRead = CWM_OS_i2cRead, .i2cWrite = CWM_OS_i2cWrite, - .spiRead = CWM_OS_spiRead, - .spiWrite = CWM_OS_spiWrite, .uSleep = CWM_OS_uSleep, + .free = CWM_OS_free, + .malloc = CWM_OS_malloc, + .spiRead = NULL, + .spiWrite = NULL, + }; + OsAPI apiOS = { + .GetTimeNs = CWM_OS_GetTimeNs, + .dbgOutput = CWM_OS_dbgOutput, + .i2cRead = CWM_OS_i2cRead, + .i2cWrite = CWM_OS_i2cWrite, + .uSleep = CWM_OS_uSleep, + .free = CWM_OS_free, + .malloc = CWM_OS_malloc, + .i2cTransfer = CWM_OS_i2cTransfer, + .restoreData = CWM_OS_restoreData, + .saveData = CWM_OS_saveData, + .spiRead = NULL, + .spiWrite = NULL, + .securityCodeWrite = NULL, + .setGpio = NULL, + .enableGpioIRQ = NULL, + .disableGpioIRQ = NULL, }; - CWM_LibPreInit(&api); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); //set mcu_chip information, must call this before CWM_LibPostInit() + memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = 2; // 0: mcu_auto_detect 2: skip_mcu_auto_detect CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + CWM_LibPostInit(CWM_AP_SensorListen); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); //get chip information + char chipInfo[64]; memset(&scl, 0, sizeof(scl)); @@ -111,10 +248,10 @@ int cywee_main_dml(void) { CWM_SettingControl(SCL_GET_CHIP_INFO, &scl); CWM_OS_dbgPrintf("have_security = %d.%d ret_buff_size = %d chipInfo = %s\n", scl.iData[5], scl.iData[6], scl.iData[4], chipInfo); CWM_OS_dbgPrintf("chip_settings = %d, %d, %d\n", scl.iData[9], scl.iData[10], scl.iData[11]); - - + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); CWM_Dml_LibInit(); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); #ifdef AP_ENABLE_DML_SDO_LISTEN // This API allows customers to develop custom features. @@ -122,17 +259,19 @@ int cywee_main_dml(void) { // No need to enable or implement this function for general usage. CWM_Dml_sensorDataOutput_register(CWM_AP_dmlSensorDataOutput_listen); #endif + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; CWM_SettingControl(SCL_DML_GET_LIB_INFO, &scl); CWM_OS_dbgPrintf("dml version:%d.%d.%d.%d product:%d model:%d\n", scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5], scl.iData[6]); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; - scl.iData[1] = 1; - //CWM_SettingControl(SCL_DML_DEBUG, &scl); + scl.iData[1] = 18; //00000000000000000000000000010010 高位在前 + // CWM_SettingControl(SCL_DML_DEBUG, &scl); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; @@ -140,17 +279,27 @@ int cywee_main_dml(void) { scl.iData[4] = 2; scl.iData[8] = 52; // for st sensor(52Hz) CWM_SettingControl(SCL_DML_DRV_AG_CONFIG, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 2; + scl.iData[6] = 3002502; + scl.iData[7] = (0|1|8|256|1024); + CWM_SettingControl(SCL_DML_DRV_HW_CONFIG, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = 1; CWM_SettingControl(SCL_DML_DRV_INIT, &scl); - CWM_OS_dbgPrintf("DML device=%d\n", scl.iData[2]); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; CWM_SettingControl(SCL_DML_GET_INITED_LIST, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); for (i = 0; i < scl.iData[2]; i ++) { @@ -160,17 +309,39 @@ int cywee_main_dml(void) { memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = 1; - scl.iData[2] = 3; + scl.iData[2] = 1; CWM_SettingControl(SCL_DML_DRV_ENABLE, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[3] = 3; scl.iData[4] = 5; - CWM_SettingControl(SCL_LOG, &scl); + // CWM_SettingControl(SCL_LOG, &scl); + + + CWM_Sensor_Enable(IDX_REQUEST_SENSOR); + // //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); - CWM_Sensor_Enable(CUSTOM_ACC); - // CWM_Sensor_Enable(CUSTOM_GYRO); + CWM_Sensor_Enable(IDX_ALGO_INACTIVITY_OUTPUT); + + CWM_Sensor_Enable(IDX_ALGO_ACTIVITY_OUTPUT); + + CWM_Sensor_Enable(IDX_ACCEL); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + // CWM_Sensor_Enable(IDX_GYRO); + CWM_Sensor_Enable(IDX_ALGO_NO_MOTION); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + // CWM_Sensor_Enable(IDX_ALGO_ANY_MOTIOIN); + CWM_Sensor_Enable(IDX_ALGO_ABSOLUTE_STATIC); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = SPORT_ACTIVE_MODE_NORMAL; //ACTIVITY_MODE_NORMAL 1001 + CWM_SettingControl(SCL_SET_ACTIVITY_MODE, &scl); + // CWM_SettingControl(SCL_SET_INACTIVITY_MODE, &scl); + //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__); return 0; }