From 06efb1f19785eb44d009efa59c89e2335f911d90 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Thu, 6 Jun 2024 21:13:47 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E8=93=9D=E7=89=99=E4=BA=A7?= =?utf8?q?=E6=B5=8B=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E6=B5=8B?= =?utf8?q?=E8=AF=95=E9=A1=B9=EF=BC=8C=E4=BC=98=E5=8C=96=E4=B9=85=E5=9D=90?= =?utf8?q?=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../battery/service/battery_service.cpp | 2 +- .../producttest/include/testspeakerC.h | 16 ++ .../nativeui/producttest/src/testspeak.cpp | 22 ++- .../factorytest_protocol.c | 167 +++++++++++++--- .../factorytest_protocol.h | 2 + .../drivers/peripheral/cywee/CMakeLists.txt | 7 +- .../peripheral/cywee/Inc/custom_factory.h | 63 ++++++ .../cywee/src/custom_factory_core.c | 184 ++++++++++++++++++ .../cywee/src/custom_factory_impl.c | 101 ++++++++++ .../drivers/peripheral/cywee/src/main_dml.c | 14 +- .../drivers/peripheral/ppg/hx3695/hx3695.c | 2 +- .../drivers/peripheral/utils/custom_utils.c | 38 ++-- .../drivers/peripheral/utils/custom_utils.h | 11 +- .../peripheral/utils/custom_utils_at_cmd.c | 20 +- 14 files changed, 568 insertions(+), 81 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/producttest/include/testspeakerC.h create mode 100644 code/sdk/drivers/peripheral/cywee/Inc/custom_factory.h create mode 100644 code/sdk/drivers/peripheral/cywee/src/custom_factory_core.c create mode 100644 code/sdk/drivers/peripheral/cywee/src/custom_factory_impl.c diff --git a/code/sdk/application/battery/service/battery_service.cpp b/code/sdk/application/battery/service/battery_service.cpp index 06128c4bc..68c9191db 100644 --- a/code/sdk/application/battery/service/battery_service.cpp +++ b/code/sdk/application/battery/service/battery_service.cpp @@ -90,7 +90,7 @@ static unsigned long g_app_queue; static uint8_t g_check_count = 0; -static int oncharging_status = 0; +static int oncharging_status = -1; static void battery_check_timer_callback(void* data); errcode_t charger_plug_event_notify(uint8_t plugged); diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testspeakerC.h b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testspeakerC.h new file mode 100644 index 000000000..c2f411c4b --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testspeakerC.h @@ -0,0 +1,16 @@ +#ifndef TEST_SPEAKERC_H +#define TEST_SPEAKERC_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif + int check_speaker(bool isopen); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp index 5608cdccc..75fa9966d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/producttest/src/testspeak.cpp @@ -228,4 +228,24 @@ namespace OHOS } return testSPEAKScrollView; } -} \ No newline at end of file + + #ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif /* __cplusplus */ +#endif /* __cplusplus */ + + int check_speaker(bool isopen) + { + if(isopen) + return AlarmClockModel::GetInstance()->AlarmPlayerStart(); + else + return AlarmClockModel::GetInstance()->AlarmPlayerStop(); + } +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +} diff --git a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c index 32bdddaef..d4ced75e7 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -74,9 +74,6 @@ static osTimerId_t g_ble_leaklight_timer; static uint8_t graycard_flag = 0; static uint8_t leaklight_flag = 0; -static uint16_t cycle_time_ms = 200; -static uint16_t duty = 20; - static uint32_t aging_time = 0; static int CRC16_XMODEM(uint8_t *bytes,uint16_t length) { @@ -129,7 +126,7 @@ errcode_t factorytest_protocol_replymsg(uint8_t mode, uint8_t submode,uint8_t te void ble_vibrator_check_timer_callback(void) { - vibrator_cyclicity(duty,cycle_time_ms,200); + uapi_vibrationModeSet(3); } void ble_acc_check_timer_callback(void) @@ -193,7 +190,7 @@ void ble_spo2_check_timer_callback(void) return; } - if(ble_hrs_data > 10000) + if(ble_spo2_data > 10000) { red_buf = ble_spo2_data; @@ -379,7 +376,7 @@ void aging_task(void) } PRINT("aging_t.mag_error : %d \r\n",aging_t.mag_error); - vibrator_cyclicity(20,200,2000); + uapi_vibrationModeSet(3); aging_t.motor_error = 0; PRINT("aging_t.motor_error : %d \r\n",aging_t.motor_error); @@ -456,7 +453,23 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t switch(submode) { case BLE_TEST_CMD_COMMON_SUB_MODE_SYSTEM_VERSION: - if (testitem == 0x02) + if (testitem == 0x01) + { + + uint8_t send_data[4]={0}; + + uint8_t _major,_mid,_minor; + uapi_get_fw_version(&_major,&_mid,&_minor); + send_data[1] = _major; + send_data[2] = _mid; + send_data[3] = _minor; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_SYSTEM_VERSION, + 0x01, + send_data, + 4); + } else if (testitem == 0x02) { //获取软件版本 uint8_t buildversion[128]={0}; @@ -474,7 +487,37 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t if(testitem == 0x01) { - //系统自检(未完成) + uint8_t send_data[2] = {0}; + uint8_t id; + uint16_t tp_id; + uint32_t chip_id; + //系统自检 + uapi_cywee_get_id(&id); + if(id != 0x44) + send_data[1] |= 1 << 1; + + touch_getid(&tp_id); + PRINT("touch_getid : %2X \r\n",tp_id); + if(tp_id != 0x6456) + send_data[1] |= 1 << 4; + + uapi_ppg_get_id(&id); + if(id != 0x65) + send_data[1] |= 1 << 3; + + lcd_getid(&chip_id); + if(chip_id != 0x1133) + send_data[1] |= 1 << 5; + + flash_getid(&chip_id); + if(chip_id == 0) + send_data[1] |= 1 << 6; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_POWER_ON_OFF_DEVICE, + 0x01, + send_data, + 2); } if(testitem == 0x02) @@ -499,12 +542,26 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t 0x03, &send_data, 1); + } else if(testitem == 0x04) + { + //进入ship mode + uint8_t send_data = 0x00; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_POWER_ON_OFF_DEVICE, + 0x04, + &send_data, + 1); + LOS_Mdelay(100); + uapi_sys_shipmode(); + } else if(testitem == 0x05) { - //恢复出厂设置(未完成) + //恢复出厂设置 uint8_t send_data = 0x00; - //bluetooth_factory_reset(); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING, NULL, 0); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, BLE_TEST_CMD_COMMON_SUB_MODE_POWER_ON_OFF_DEVICE, 0x05, @@ -514,6 +571,32 @@ void factorytest_protocol_common_decode(uint8_t submode,uint8_t testitem,uint8_t break; case BLE_TEST_CMD_COMMON_SUB_MODE_POWERCONSUMPTION: + if(testitem == 0x01) + { + uint8_t send_data = 0x00; + + power_on_cat1(); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_POWERCONSUMPTION, + 0x01, + &send_data, + 1); + } else if(testitem == 0x02) + { + uint8_t send_data = 0x00; + + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_WEAR_MODE_TEST); + send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST); + + power_off_cat1(); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_COMMON, + BLE_TEST_CMD_COMMON_SUB_MODE_POWERCONSUMPTION, + 0x02, + &send_data, + 1); + } break; case BLE_TEST_CMD_COMMON_SUB_MODE_OTA: @@ -597,7 +680,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint g_ble_vibrator_timer = osTimerNew((osTimerFunc_t)ble_vibrator_check_timer_callback, osTimerPeriodic, NULL, NULL); - osTimerStart(g_ble_vibrator_timer,200); + osTimerStart(g_ble_vibrator_timer,1000); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, @@ -610,8 +693,6 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //关闭马达 uint8_t send_data = 0x00; - cycle_time_ms = 200; - duty = 20; osTimerStop(g_ble_vibrator_timer); osTimerDelete(g_ble_vibrator_timer); @@ -625,12 +706,9 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //打开周期性马达 uint8_t send_data = 0x00; - cycle_time_ms = data[1]; - duty = data[0]; - g_ble_vibrator_timer = osTimerNew((osTimerFunc_t)ble_vibrator_check_timer_callback, osTimerPeriodic, NULL, NULL); - osTimerStart(g_ble_vibrator_timer,200); + osTimerStart(g_ble_vibrator_timer,1000); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_VIBRATOR, @@ -885,7 +963,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint } factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_LCD, - 0x04, + *data, &send_data, 1); } else if(testitem == 0x05) @@ -923,6 +1001,18 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint 0x01, tp_id, 3); + } else if(testitem == 0x02) + { + //触摸版本 + uint8_t send_data = 0x01; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_TP, + 0x02, + &send_data, + 1); + + } else if(testitem == 0x03) { //触摸测试 @@ -969,13 +1059,13 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC: if(testitem == 0x01) { - //acc ID(未完成) + //acc ID uint8_t acc_id[2] = {0}; - acc_id[1] = 0x44; + uapi_cywee_get_id(&acc_id[1]); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ACC, 0x01, - &acc_id, + acc_id, 2); } else if(testitem == 0x04) @@ -1233,8 +1323,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //打开cat1 uint8_t send_data = 0x00; - uapi_cat1_power_on(1); - uapi_cat1_reset(0); + power_on_cat1(); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, @@ -1247,8 +1336,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //关闭cat1 uint8_t send_data = 0x00; - uapi_cat1_power_on(0); - uapi_cat1_reset(1); + power_off_cat1(); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, @@ -1374,6 +1462,35 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint 2); } break; + + case BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER: + if(testitem == 0x01) + { + + uint8_t send_data= 0; + + uapi_check_speaker(1); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, + 0x01, + &send_data, + 1); + } else if(testitem == 0x02) + { + + uint8_t send_data = 0; + + uapi_check_speaker(0);; + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, + 0x02, + &send_data, + 1); + } + break; + default: printf(""); break; diff --git a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.h b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.h index c2478b8ff..47cc3f500 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.h +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.h @@ -95,6 +95,8 @@ extern "C" { #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CONTACTS 0x30 //软件测试 子模式ID 支付宝 #define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_ALIPAY 0x31 +//软件测试 子模式ID SPEAKER +#define BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER 0x32 /** * * encode cmd msg string and send to ble diff --git a/code/sdk/drivers/peripheral/cywee/CMakeLists.txt b/code/sdk/drivers/peripheral/cywee/CMakeLists.txt index 05b6d8379..30b939966 100644 --- a/code/sdk/drivers/peripheral/cywee/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/cywee/CMakeLists.txt @@ -9,9 +9,12 @@ set(SOURCES ${SOURCES} ${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}/src/custom_factory_core.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/custom_factory_impl.c ${CMAKE_CURRENT_SOURCE_DIR}/service/cywee_service.c ${CMAKE_CURRENT_SOURCE_DIR}/service/cywee_at_cmd.c ${CMAKE_CURRENT_SOURCE_DIR}/service/cywee_hal.c + # ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/examples/lis2doc_read_data_single.c # ${CMAKE_CURRENT_SOURCE_DIR}/../acc/lis2doc_STdC/lis2doc_porting.c ) @@ -46,11 +49,11 @@ set(MAIN_COMPONENT false ) - 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}) target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_CWM_LIB_DML} ${LIB_PATH_CWM_LIB} PRIVATE -Wl,--whole-archive) endif() - + #target_link_libraries(${TARGET_NAME} PRIVATE -Wl,--whole-archive ${LIB_PATH_CWM_LIB} PRIVATE -Wl,--whole-archive) +#endif() build_component() diff --git a/code/sdk/drivers/peripheral/cywee/Inc/custom_factory.h b/code/sdk/drivers/peripheral/cywee/Inc/custom_factory.h new file mode 100644 index 000000000..fe7749c9b --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/Inc/custom_factory.h @@ -0,0 +1,63 @@ +#ifndef __CUSTOM_FACTORY_H__ +#define __CUSTOM_FACTORY_H__ +#include + + +#ifndef __CWM_LIB_H__ +//Needed by custom_factory_core.c + +#define SCL_GET_CHIP_INFO 8 +#define SCL_GET_LIB_INFO 12 +#define SCL_CHIP_VENDOR_CONFIG 17 + +typedef struct { + int iData[16]; +} SettingControl_t; + +int CWM_SettingControl(int CtrId, SettingControl_t *pData); + +typedef struct { + unsigned int sensorType; + unsigned int index; + float fData[16]; + unsigned long timestamp_ns; + void *memData; +} SensorEVT_t, *pSensorEVT_t; + +typedef void (*FN_SENSOR_LISTEN)(pSensorEVT_t); + +//void CWM_LibPostInit(FN_SENSOR_LISTEN pfn); +#endif //__CWM_LIB_H__ + + + + +typedef struct { + int sec_write_len; + int sec_empty_value; + int sec_rewritable; + char *chip_name; +} reburn_prepare_t; + +typedef struct { + void (*log_print)(const char* str); +} print_api_t; + +int secFactory_init(int rand_seed); +int secFactory_make_sec(char version, char *code, int *pCode); +int secFactory_make_chipInfo(char *strChipInfo); + +void reburn_log_printf(const char* fmt, ...); + +int impl_prepare(reburn_prepare_t *var_out); +int impl_checkMcuModel(void); +int impl_stick_env_init(void); +int impl_stick_env_deinit(void); +int impl_sec_env_init(void); +int impl_sec_env_deinit(void); +int impl_sec_is_locked(void); +int impl_sec_read(unsigned char *buf, unsigned int len); +int impl_sec_erase(void); +int impl_sec_write(unsigned char *buf, unsigned int len); + +#endif //__CM_SIMPLE_FACTORY_H__ diff --git a/code/sdk/drivers/peripheral/cywee/src/custom_factory_core.c b/code/sdk/drivers/peripheral/cywee/src/custom_factory_core.c new file mode 100644 index 000000000..5107e1e16 --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/src/custom_factory_core.c @@ -0,0 +1,184 @@ +#include +#include +#include +#include +#include + +#include "custom_factory.h" + +#define STS_OK 0 +#define STS_ERR_WRONG_MODEL -1 +#define STS_ERR_INVALID_LIB -2 +#define STS_ERR_SEC_READ_FAIL -3 +#define STS_ERR_MEDIUM_LOCKED -4 +#define STS_ERR_BLOCK_NOT_EMPTY -5 +#define STS_ERR_ERASE_FAILED -6 +#define STS_ERR_SEC_INIT -7 +#define STS_ERR_SEC_MAKE_CHIPINFO -8 +#define STS_ERR_SEC_MAKE_SEC -9 +#define STS_ERR_SEC_WRITE_LEN -10 +#define STS_ERR_SEC_WRITE -11 + +static print_api_t m_reburn_print_api; +static reburn_prepare_t m_var; + + + +void reburn_setup_api(print_api_t *api) { + m_reburn_print_api.log_print = api->log_print; +} + +void reburn_log_printf(const char* fmt, ...) { + va_list argList; + uint8_t localBuf[255]; + + if (!m_reburn_print_api.log_print) + return; + + va_start(argList, fmt); + vsnprintf((char *)localBuf, sizeof(localBuf), fmt,argList); + va_end(argList); + + m_reburn_print_api.log_print((const char*)localBuf); +} + +static int is_sec_empty(uint8_t* buf, uint32_t len) { + for (int i = 0 ; i < len ; i++) { + if (buf[i] != m_var.sec_empty_value) { + reburn_log_printf("is_sec_empty(): block %d not empty(0x%02x)\n", i, buf[i]); + return 0; + } + } + + return 1; +} + +static void dump_sec(uint8_t* buf, uint32_t len) { + uint32_t offset = 0, remainBytes = len; + + if (len % 16 != 0) + return; + + while (remainBytes >= 16) { + reburn_log_printf("%08x | %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", offset, + *(buf + (offset) + 0 ), *(buf + (offset) + 1 ), *(buf + (offset) + 2 ), *(buf + (offset) + 3 ), + *(buf + (offset) + 4 ), *(buf + (offset) + 5 ), *(buf + (offset) + 6 ), *(buf + (offset) + 7 ), + *(buf + (offset) + 8 ), *(buf + (offset) + 9 ), *(buf + (offset) + 10), *(buf + (offset) + 11), + *(buf + (offset) + 12), *(buf + (offset) + 13), *(buf + (offset) + 14), *(buf + (offset) + 15)); + offset += 16; + remainBytes -= 16; + } +} + +int reburn_second_dev(void) { + SettingControl_t scl; + char str_chipInfo[48]; + unsigned char buf[256]; + char EncodeData[512]; + int len = 0, ret = 0; + + impl_prepare(&m_var); + + reburn_log_printf("[reburn_second_dev] Built at %s %s\n", __DATE__, __TIME__); + printf("[reburn_second_dev] Built at \r\n"); + if (!impl_checkMcuModel()) { + reburn_log_printf("cannot reburn: wrong model\n"); + printf("cannot reburn: wrong model \r\n"); + return STS_ERR_WRONG_MODEL; + } + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + CWM_SettingControl(SCL_GET_LIB_INFO, &scl); + if (scl.iData[5] < 3000) { + reburn_log_printf("%d Not a valid reburn library\n", scl.iData[5]); + printf("%d Not a valid reburn library\n", scl.iData[5]); + return STS_ERR_INVALID_LIB; + } + reburn_log_printf("model:%s version:%d.%d.%d.%d product:%d\n", m_var.chip_name, scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5]); + printf("model:%s version:%d.%d.%d.%d product:%d\n", m_var.chip_name, scl.iData[1], scl.iData[2], scl.iData[3], scl.iData[4], scl.iData[5]); + + impl_sec_env_init(); + + impl_stick_env_init(); + + CWM_LibPostInit(NULL); + + if (secFactory_init(0) != 1) { + printf("secFactory_init fail\n"); + return STS_ERR_SEC_INIT; + } + + impl_stick_env_deinit(); + + impl_sec_env_deinit(); + + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 1; + scl.iData[2] = (int)&str_chipInfo[0]; + scl.iData[3] = sizeof(str_chipInfo); + scl.iData[4] = 0; + scl.iData[5] = 0; + scl.iData[6] = 0; + CWM_SettingControl(SCL_GET_CHIP_INFO, &scl); + printf("have_security = %d.%d ret_buff_size = %d\n", scl.iData[5], scl.iData[6], scl.iData[4]); + printf("[getinfo]chipInfo=%s\n", str_chipInfo); + if (scl.iData[5] == 1) { + printf("valid security found\n"); + return STS_OK; + } + + memset(buf, 0x0, sizeof(buf)); + ret = impl_sec_read(buf, m_var.sec_write_len); + if (ret != 1) { + printf("cannot reburn: read error(%d)\n", ret); + return STS_ERR_SEC_READ_FAIL; + } + dump_sec(buf, m_var.sec_write_len); + + if (impl_sec_is_locked()) { + printf("cannot reburn: locked\n"); + return STS_ERR_MEDIUM_LOCKED; + } + + if (!is_sec_empty(buf, m_var.sec_write_len)) { + if (!m_var.sec_rewritable) { + printf("cannot reburn: block not empty\n"); + return STS_ERR_BLOCK_NOT_EMPTY; + } + ret = impl_sec_erase(); + if (ret != 1) { + printf("cannot reburn: erase error(%d)\n", ret); + return STS_ERR_ERASE_FAILED; + } + } + + if (secFactory_make_chipInfo(str_chipInfo) != 1) { + printf("secFactory_make_chipInfo fail\n"); + return STS_ERR_SEC_MAKE_CHIPINFO; + } + printf("[makesec]chipInfo=%s\n", str_chipInfo); + + memset(EncodeData, 0, sizeof(EncodeData)); + ret = secFactory_make_sec(0x01, EncodeData, &len); + if (ret != 1) { + printf("secFactory_make_sec fail\n"); + return STS_ERR_SEC_MAKE_SEC; + } + + if (len < m_var.sec_write_len) { + printf("sec length error(%d/%d)\n", len, m_var.sec_write_len); + return STS_ERR_SEC_WRITE_LEN; + } + + ret = impl_sec_write((uint8_t*)&EncodeData[0], len); + if (ret != 1) { + printf("cannot reburn: write error(%d)\n", ret); + return STS_ERR_SEC_WRITE; + } + + printf("reburn complete\n"); + + return STS_OK; +} diff --git a/code/sdk/drivers/peripheral/cywee/src/custom_factory_impl.c b/code/sdk/drivers/peripheral/cywee/src/custom_factory_impl.c new file mode 100644 index 000000000..0e88bc3b3 --- /dev/null +++ b/code/sdk/drivers/peripheral/cywee/src/custom_factory_impl.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include "custom_factory.h" + +#include "osal_interrupt.h" +#include "gpio.h" +#include "flash.h" + +extern int cm__hs1__init(void); +extern int cm__hs1__deinit(void); + +#define OTP_RW_OFFSET (0x100) + +static reburn_prepare_t m_chipCfg = { + .sec_write_len = 16, + .sec_empty_value = 0x00, + .sec_rewritable = 0, + .chip_name = "YH601S" +}; + +static uint32_t irqMask = 0; + +int impl_prepare(reburn_prepare_t *var_out) { + memcpy(var_out, (void*)&m_chipCfg, sizeof(m_chipCfg)); + + return 1; +} + +int impl_checkMcuModel() { + return 1; +} + +int impl_sec_env_init() { + return 1; +} + +int impl_stick_env_init() { + SettingControl_t scl; + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[1] = 31010100; + CWM_SettingControl(SCL_CHIP_VENDOR_CONFIG, &scl); + + irqMask = osal_irq_lock(); + + if (cm__hs1__init() != 1) { + reburn_log_printf("%s: failed\n", __FUNCTION__); + return -1; + } + return 1; +} + +int impl_sec_is_locked() { + return 0; +} + +int impl_stick_env_deinit() { + if (cm__hs1__deinit() != 1) { + reburn_log_printf("%s: failed\n", __FUNCTION__); + return -1; + } + + osal_irq_restore(irqMask); + + return 1; +} + +int impl_sec_env_deinit() { + return 1; +} + +int impl_sec_read(unsigned char *buf, unsigned int len) { + if (!buf) { + reburn_log_printf("[read_security] null buf\n"); + return -1; + } + + if (uapi_efuse_read_buffer(buf, OTP_RW_OFFSET, m_chipCfg.sec_write_len) != 0) { + return -2; + } + + return 1; +} + +int impl_sec_write(unsigned char *buf, unsigned int len) { + if (!buf) { + reburn_log_printf("[write_security] null buf\n"); + return -1; + } + + if (uapi_efuse_write_buffer(OTP_RW_OFFSET, buf, m_chipCfg.sec_write_len) != 0) { + return -2; + } + + return 1; +} + +int impl_sec_erase() { + return 1; +} diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 317d8fe88..8fb6c3025 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -325,9 +325,9 @@ void get_gsonsen_xyz(gsenson_t *t) // CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n"); // return; // } - t->x = gxyz_t_queue[left_falg].x; - t->y = gxyz_t_queue[left_falg].y; - t->z = gxyz_t_queue[left_falg].z; + t->x = gxyz_t.x; + t->y = gxyz_t.y; + t->z = gxyz_t.z; //osal_mutex_unlock(&mutex_gsenson_queue); } @@ -362,15 +362,18 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { cywee_msg_callback_t cywee_func; switch (sensorEVT->sensorType) { case IDX_ACCEL: + gxyz_t.x = sensorEVT->fData[0]; + gxyz_t.y = sensorEVT->fData[1]; + gxyz_t.z = sensorEVT->fData[2]; - if(get_acc_swtich) - { // CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n", // sensorEVT->fData[0], // sensorEVT->fData[1], // sensorEVT->fData[2] // ); + if(get_acc_swtich) + { if(num_falg==25) { left_falg++; @@ -712,6 +715,7 @@ int cywee_main_dml(void) } cywee_installized = 1; + //reburn_second_dev(); int i; memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 94df49022..6fc1c9636 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -125,7 +125,7 @@ ppg_sensor_data_t ppg_s_data; int cywee_data[2] = {0}; -int wear_mode_status = 0; +int wear_mode_status = -1; //////// spo2 para and switches const uint8_t COUNT_BLOCK_NUM = 25; //delay the block of some single good signal after a series of bad signal diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 1d11fb7aa..dd06ace0e 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -27,6 +27,7 @@ #ifdef FD230 #include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h" #include "networkandcall/include/NetworkAndCallC.h" +#include "producttest/include/testspeakerC.h" #endif #include #include @@ -1305,13 +1306,6 @@ errcode_t uapi_get_fw_version(uint8_t *_major, uint8_t *_mid,uint8_t *_minor) return ERRCODE_SUCC; } -#include "vibrator.h" - -void vibrator_cyclicity(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms) -{ - g_VibratorFunc(duty,cycle_time_ms,duration_time_ms); -} - void uapi_take_to_wake(int cmd) { @@ -1679,13 +1673,12 @@ void test_bandy_time(uint32_t timestamp) #include "tyhx_hrs_custom.h" -void get_ppg_id(void) +void uapi_ppg_get_id(uint8_t *chip_id) { - tyhx_poweron(); - hx3695_chip_check(); - tyhx_poweroff(); + custom_i2c_read_regs(HX3695_I2C_DEV_8ADDR,0x00,1,chip_id,1,I2C_BUS_2); } + #include "hal_i2c.h" #include "i2c.h" #define CUSTOM_I2C_TIME_MAX 3 @@ -1936,8 +1929,7 @@ void uapi_enter_power_saving_mode(void) stop_custom_ble_service(); //关闭cat1 - uapi_cat1_power_on(0); - uapi_cat1_reset(1); + power_off_cat1(); //停止心率周期检测 @@ -1954,9 +1946,7 @@ void uapi_exit_power_saving_mode(void) start_custom_ble_service(); //打开cat1 - uapi_cat1_power_on(1); - uapi_cat1_reset(0); - + power_on_cat1(); //开启心率周期检测 } @@ -1993,13 +1983,12 @@ void uapi_cywee_time_sync(void) do_cywee_service_check_msg(CYWEE_SERVICE_CMD_TIME_SYNC,NULL); } -void uapi_cywee_get_id(void) +void uapi_cywee_get_id(uint8_t *id) { - uint8_t id = 0; - custom_i2c_read_regs(0x19,0x0FU,1,&id,1,I2C_BUS_2); - PRINT("cywee id : 0x%X \r\n",id); + custom_i2c_read_regs(0x19,0x0FU,1,id,1,I2C_BUS_2); } + void uapi_cywee_get_chipinfo(char *databuf,uint8_t len) { cywee_get_chipinfo(databuf,len); @@ -2020,4 +2009,11 @@ int custom_exit_lpm(void) return ret; } -#endif \ No newline at end of file +#endif + +int uapi_check_speaker(bool isopen) +{ + #ifdef FD230 + return check_speaker(isopen); + #endif +} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 5bd5c3b68..7ee0031d5 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -117,8 +117,6 @@ errcode_t uapi_get_fw_version(uint8_t *_major, uint8_t *_mid,uint8_t *_minor); //抬腕亮屏 void uapi_take_to_wake(int cmd); -//开关马达 -void vibrator_cyclicity(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms); //获取lcd id void lcd_getid(uint32_t *id); @@ -145,11 +143,6 @@ void battery_getvolpower(uint8_t *power); void flash_getid(uint32_t *id); void flash_erase(void); -//进入recovery -int enter_recovery(void); -//设置bmp图片 -int set_bmp(void); - void get_gsensor_single(uint8_t *databuf); @@ -192,14 +185,14 @@ errcode_t custom_i2c_transfer(uint16_t slaveAddr, uint16_t reg, int regLength, u uint32_t custom_i2c_suspend(void); uint32_t custom_i2c_resume(void); -void uapi_cywee_get_id(void); +void uapi_cywee_get_id(uint8_t *id); int custom_exit_lpm(void); void uapi_cywee_get_sleep_data(void); void uapi_cywee_set_user_info(int user_info[5]); void uapi_cywee_time_sync(void); void uapi_cywee_get_chipinfo(char *databuf,uint8_t len); - +void uapi_ppg_get_id(uint8_t *chip_id); #include "custom_utilscpp.h" diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index cda26d514..851b4b1a1 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -279,16 +279,6 @@ static uint32_t custom_touch_getstate(uint8_t *para, uint32_t paraLen, char *str return ERRCODE_SUCC; } -static uint32_t custom_mmc5603_getid(uint8_t *para, uint32_t paraLen, char *strCommonCmd) -{ - - UNUSED(strCommonCmd); - - //mmc5603_getid(); - - return ERRCODE_SUCC; -} - static uint32_t custom_mmc5603_getdata(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { @@ -409,8 +399,8 @@ static uint32_t custom_get_ppg_id(uint8_t *para, uint32_t paraLen, char *strComm { UNUSED(strCommonCmd); - - get_ppg_id(); + uint8_t chip_id; + uapi_ppg_get_id(&chip_id); return ERRCODE_SUCC; } @@ -451,8 +441,8 @@ static uint32_t custom_get_cywee_id(uint8_t *para, uint32_t paraLen, char *strCo { UNUSED(strCommonCmd); - - uapi_cywee_get_id(); + uint8_t id; + uapi_cywee_get_id(&id); return ERRCODE_SUCC; } @@ -613,8 +603,6 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^SCREENSTATE", custom_touch_getstate, (char *)" " }, - { (char *)"AT^MMC5603ID", custom_mmc5603_getid, (char *)" " }, - { (char *)"AT^MMC5603GETDATA", custom_mmc5603_getdata, (char *)" " }, { (char *)"AT^CHARGESTATE", custom_charge_getstate, (char *)" " }, -- 2.17.1