From 1e2351fb71181994b5c79820016df84c8167a6c2 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Wed, 19 Jun 2024 17:56:50 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E9=A9=AC=E8=BE=BE=E9=9C=87?= =?utf8?q?=E5=8A=A8=EF=BC=8C=E4=BC=98=E5=8C=96=E8=93=9D=E7=89=99=E4=BA=A7?= =?utf8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/ohos_startup/ohosfwk_startup.c | 2 +- .../factorytest_protocol.c | 100 +++++++------- .../config/target_config/brandy/config.py | 2 + .../brandy_evb/board_config/board_evb.h | 4 +- .../peripheral/mag/mmc5603/mmc5603_main.c | 1 - .../vibrator/service/vibrator_service.cpp | 16 +-- .../drivers/peripheral/vibrator/vibrator.c | 128 ++++++++++++------ .../service/src/graphic_service_wrapper.cpp | 35 ++--- 8 files changed, 170 insertions(+), 118 deletions(-) diff --git a/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c b/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c index 9ae7b2729..abdfc2c8e 100755 --- a/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c +++ b/code/sdk/application/wearable/ohos_startup/ohosfwk_startup.c @@ -84,8 +84,8 @@ void ohos_startup() mount_user_res_partition(); #endif - wait_animation_stop(); +boot_animation_init_deinit(); #if defined(CONFIG_OTA_UPDATE_SUPPORT) && defined(ENABLE_UIKIT) //如果在升级状态,则不进入系统 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 64073c01f..cb08cb76c 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-06-17 14:31:08 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-06-17 17:51:27 + * @LastEditTime: 2024-06-19 17:07:52 * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c * @Description: * @@ -79,9 +79,6 @@ static osTimerId_t g_ble_vibrator_timer = NULL; static osTimerId_t g_ble_acc_timer = NULL; -static osTimerId_t g_ble_microhone_timer = NULL; -static osTimerId_t g_ble_spk_timer = NULL; - static uint32_t aging_time = 0; static uint8_t pwr_button_result = 0; @@ -178,37 +175,6 @@ void ble_acc_check_timer_callback(void) 6); } -void ble_microhone_check_timer_callback(void) -{ - PRINT("ble_microhone_check_timer_callback \r\n"); - uint8_t send_data= 0; - - uapi_microhone_switch(0); - - osTimerStop(g_ble_microhone_timer); - osTimerDelete(g_ble_microhone_timer); - factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, - BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, - 0x01, - &send_data, - 1); - -} - -void ble_spk_check_timer_callback(void) -{ - uint8_t send_data= 0; - - uapi_check_spk(0); - osTimerStop(g_ble_spk_timer); - osTimerDelete(g_ble_spk_timer); - factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, - BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, - 0x02, - &send_data, - 1); -} - void aging_task(void) { while(aging_t.flag == 0xfdfd0002 && aging_time) @@ -745,7 +711,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint (data[2] & 0XFF) << 8 | (data[3] & 0XFF) << 0 ; PRINT("rtc set time : %X \r\n",timestamp); - uaip_set_time_local(timestamp); + uaip_sntp_set_time_utc(timestamp); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_RTC, 0x01, @@ -1000,6 +966,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { uint8_t send_data = 0; uint32_t timeout = *data; + PRINT("ScreenDurationTime : %d \r\n",*data); //修改自动灭屏时间 uapi_setScreenDuration(timeout); @@ -1488,10 +1455,6 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //查看网络类型 uint8_t send_data[2] = {0}; - - cat1_getsignal(); - msleep(1000); - send_data[1] = uapi_dev_runtime_get_cat1_networtype(); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, @@ -1500,6 +1463,17 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint send_data, 2); } else if(testitem == 0x06) + { + //查看iMei号 + char* imei = uapi_dev_runtime_get_cat1_imei(); + PRINT("imei : %s \r\n",imei); + + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, + 0x06, + (uint8_t *)imei, + strlen(imei)); + }else if(testitem == 0x07) { //拨打电话 @@ -1508,11 +1482,11 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint cat1_call_dial((char *)data); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, - 0x06, + 0x07, &send_data, 1); - } else if(testitem == 0x07) + } else if(testitem == 0x08) { //接听电话 uint8_t send_data = 0x00; @@ -1521,12 +1495,12 @@ 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_CAT1, - 0x07, + 0x08, &send_data, 1); } - else if(testitem == 0x08) + else if(testitem == 0x09) { //挂断电话 uint8_t send_data = 0x00; @@ -1534,7 +1508,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_CAT1, - 0x08, + 0x09, &send_data, 1); } @@ -1576,16 +1550,44 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint if(testitem == 0x01) { //开始录音 + uint8_t send_data= 0; uapi_microhone_switch(1); - g_ble_microhone_timer = osTimerNew((osTimerFunc_t)ble_microhone_check_timer_callback, osTimerPeriodic, NULL, NULL); - osStatus_t ret = osTimerStart(g_ble_microhone_timer,5000); + 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_microhone_switch(0); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, + 0x02, + &send_data, + 1); + } else if(testitem == 0x03) { //播放录音 + uint8_t send_data= 0; uapi_check_spk(1); - g_ble_spk_timer = osTimerNew((osTimerFunc_t)ble_spk_check_timer_callback, osTimerPeriodic, NULL, NULL); - osTimerStart(g_ble_spk_timer,5000); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, + 0x03, + &send_data, + 1); + } else if(testitem == 0x04) + { + //停止播放 + uint8_t send_data= 0; + uapi_check_spk(0); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, + BLE_TEST_CMD_SOFT_TEST_SUB_MODE_SPEAKER, + 0x04, + &send_data, + 1); } break; diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 086dbcf2a..f53c96a89 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -119,6 +119,8 @@ target = { # 'WEARABLE_LOG_DEBUG', 'SUPPORT_RC_CALIBRATION', 'PPG_HX3695', + 'VIB_USE_PWM', + 'CONFIG_PWM_SUPPORT', # 'ACC_LIS2DOC', 'ENABLE_CYWEE', 'ENABLE_CUSTOM_I2C', diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h index 6427ec60c..622ec8c52 100755 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h @@ -196,8 +196,8 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R0 PRG_LED_POWER ON 心率等电源控制脚 { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R1 SE_REST 安全芯片复位唤醒脚 #if VIB_USE_PWM - // { HAL_PIO_FUNC_PWMP1_M2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_NONE, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 VIBR_PWM 马达控制脚 兼容预留马达驱动复位脚 - // { HAL_PIO_FUNC_PWMN1_M3, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_NONE, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 VIBR_PWM 马达控制脚 兼容预留马达驱动复位脚 + // { HAL_PIO_FUNC_PWMP1_M2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 VIBR_PWM 马达控制脚 兼容预留马达驱动复位脚 + { HAL_PIO_FUNC_PWMN1_M3, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 VIBR_PWM 马达控制脚 兼容预留马达驱动复位脚 #else { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 VIBR_PWM 马达控制脚 兼容预留马达驱动复位脚 #endif diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_main.c b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_main.c index 187b61538..422b68b19 100644 --- a/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_main.c +++ b/code/sdk/drivers/peripheral/mag/mmc5603/mmc5603_main.c @@ -96,7 +96,6 @@ int mmc5603_start(void) { for(i=0;i<4;i++) { - PRINT("saveData[%d] : %f \r\n",i,saveData[i]); mag_hmm[i] = saveData[i]; } } diff --git a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp index 7b2cc2365..ab5645a2a 100644 --- a/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp +++ b/code/sdk/drivers/peripheral/vibrator/service/vibrator_service.cpp @@ -81,18 +81,18 @@ void custom_VibratorFunc_int(int vibratorType) switch (vibratorType) { case 3: - mail.cycle_time_ms = 200; - mail.duty = 20; - mail.duration_time_ms = 500; + mail.cycle_time_ms = 235; + mail.duty = 50; + mail.duration_time_ms = 100; break; case 2: - mail.cycle_time_ms = 200; - mail.duty = 20; - mail.duration_time_ms = 200; + mail.cycle_time_ms = 235; + mail.duty = 30; + mail.duration_time_ms = 100; break; case 1: - mail.cycle_time_ms = 200; - mail.duty = 20; + mail.cycle_time_ms = 235; + mail.duty = 10; mail.duration_time_ms = 100; break; default: diff --git a/code/sdk/drivers/peripheral/vibrator/vibrator.c b/code/sdk/drivers/peripheral/vibrator/vibrator.c index c13f35f57..89ef5dc5c 100644 --- a/code/sdk/drivers/peripheral/vibrator/vibrator.c +++ b/code/sdk/drivers/peripheral/vibrator/vibrator.c @@ -22,8 +22,6 @@ #include "pinctrl.h" #include "vibrator.h" - - #ifdef VIB_USE_PWM #define VIBRATOR_GPIOPPIN S_AGPIO_R2 // #define VIBRATORPIN_MODE HAL_PIO_FUNC_PWMP1_M2 @@ -36,7 +34,7 @@ static pwm_channel_t channel = PWM_1; static pin_t pin = VIBRATOR_GPIOPPIN; static pin_mode_t mode = VIBRATORPIN_MODE; -static uint32_t delay_ms = 500; +static uint32_t delay_ms = 5; static pwm_config_t cfg_repeat = { 100, 100, 0xFF, 0xFF, true }; static uint32_t param_index = 0; static uint16_t repeat_times = 0; @@ -47,7 +45,19 @@ static errcode_t pwm_test_callback(uint8_t channel) return ERRCODE_SUCC; } static uint8_t pwm_started = 0; -static int test_pwm_repeat(int vibratorType) + +#define IOT_PWM_MIN_DUTY 0 +#define IOT_PWM_MAX_DUTY 100 +#define IOT_PWM_DUTY_PART 10 +#define IOT_PWM_FREQ_PART 2 +#define IOT_PWM_MAX_DIV_NUM_MAX 8 +#define IOT_PWM_CFG_OFFEST_TIME 0 +#define IOT_PWM_CFG_REPEAT_CYCLE 100 +#define IOT_PWM_CFG_REPEAT_STATE true +#define IOT_SUCCESS 0 +#define IOT_FAILURE (-1) + +static int pwm_start(uint16_t duty , uint16_t freq) { if (pwm_started == 1) @@ -61,61 +71,99 @@ static int test_pwm_repeat(int vibratorType) PRINT("Paremeter Error. PWM max number is 5. \r\n"); return -1; } + + errcode_t ret = 0; pwm_started = 1; - repeat_times = 0; uapi_pwm_init(); uapi_pin_set_mode(pin, mode); - PRINT("+++++++ pwm init success +++++++ \r\n"); - uint32_t pwm_frequency = uapi_pwm_get_frequency(channel); + // PRINT("+++++++ pwm init success +++++++ \r\n"); + /* test for repeat, interrupt only be call when stop or close */ - PRINT("+++++++ Start pwm repeat test +++++++ pwm_frequency %u\r\n",pwm_frequency); - // LOS_Msleep((uint32_t)TEST_TCXO_DELAY_1000MS); - // cfg_repeat.high_time = pwm_frequency/2; - // cfg_repeat.low_time = pwm_frequency/2; - uapi_pwm_open(channel, &cfg_repeat); + uint32_t clk_freq = uapi_pwm_get_frequency(channel); + uint32_t div_num = (clk_freq + freq / IOT_PWM_FREQ_PART) / freq; + if (div_num < IOT_PWM_MAX_DIV_NUM_MAX) { + return IOT_FAILURE; + } + uint32_t high_time = div_num * duty / IOT_PWM_MAX_DUTY; + if (high_time * IOT_PWM_MAX_DUTY / div_num >= (uint32_t)(duty - duty * IOT_PWM_DUTY_PART / IOT_PWM_MAX_DUTY)) { + } else if ((high_time + 1) * IOT_PWM_MAX_DUTY / div_num <= + (uint32_t)(duty + duty * IOT_PWM_DUTY_PART / IOT_PWM_MAX_DUTY)) { + high_time++; + } else { + return IOT_FAILURE; + } + uint32_t low_time = div_num - high_time; + pwm_config_t cfg = { + .low_time = low_time, + .high_time = high_time, + .offset_time = IOT_PWM_CFG_OFFEST_TIME, + .cycles = IOT_PWM_CFG_REPEAT_CYCLE, + .repeat = IOT_PWM_CFG_REPEAT_STATE + }; + // PRINT("+++++++ Start pwm clk_freq %u , cycles %u , high_time %u , low_time %u\r\n", + // clk_freq, + // cfg.cycles, + // cfg.high_time, + // cfg.low_time + // ); + + ret = uapi_pwm_open(channel, &cfg); + // PRINT("uapi_pwm_open %d\n",ret); uapi_pwm_unregister_interrupt(channel); uapi_pwm_register_interrupt(channel, pwm_test_callback); + #if defined(CONFIG_PWM_USING_V151) uapi_pwm_set_group(0, 1u << channel); uapi_pwm_start(0); #else - uapi_pwm_start(channel); -#endif - // LOS_Msleep((uint32_t)TEST_TCXO_DELAY_1000MS); - LOS_Msleep(delay_ms); + ret = uapi_pwm_start(channel); + // PRINT("uapi_pwm_start %d\n",ret); - for (uint32_t test_times = 1; test_times <= vibratorType; test_times++) { - - // uapi_pwm_check(channel) - PRINT("+++++++ pwm repeat interrupt +++++++ \r\n"); - if (test_times == vibratorType) { - PRINT("+++++++ pwm repeat ready to trigger interrupt +++++++ \r\n"); - uapi_pwm_close(channel); - break; - PRINT("+++++++ pwm repeat exit interrupt +++++++ \r\n"); - } - LOS_Msleep(delay_ms); - } - - uapi_pwm_close(channel); +#endif + + return 0; +} + +static int pwm_stop(void) +{ + + errcode_t ret = uapi_pwm_close(channel); + // PRINT("uapi_pwm_close %d\n",ret); // LOS_Msleep((uint32_t)TEST_TCXO_DELAY_1000MS); - LOS_Msleep(delay_ms); - uapi_pwm_deinit(); - pwm_started = 0; - PRINT("+++++++ pwm stoped +++++++ \r\n"); + LOS_Msleep(delay_ms); + uapi_pwm_deinit(); + pwm_started = 0; + // PRINT("+++++++ pwm stoped +++++++ \r\n"); return 0; } -void g_VibratorFunc(uint8_t vibratorType , uint16_t vibtime_ms,uint16_t delaytime_ms) + +static uint8_t vibrating = 0; +static uint8_t switch_flag = 1; + +void g_VibratorFunc(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms) { - if(vibratorType <1 || vibratorType > 3) + if( duty>100 || duty ==0 ||cycle_time_ms == 0 || duration_time_ms == 0) { - PRINT("g_VibratorFunc vib times should in 1~3 \r\n",vibratorType); + PRINT("Not Supported param duty %u cycle_time_ms %u duration_time_ms %u !\r\n",duty,cycle_time_ms,duration_time_ms ); }else{ - PRINT("g_VibratorFunc vib %d times , delaytime_ms %d\r\n",vibratorType , delaytime_ms); - delay_ms = delaytime_ms; - test_pwm_repeat(vibratorType); + // PRINT("g_VibratorFunc duration_time_ms %u , duty %u , cycle_time_ms %u\r\n",duration_time_ms ,duty, cycle_time_ms); + + if (vibrating == 1) + { + PRINT("vibrating skip\r\n"); + return ; + } + vibrating = 1; + + pwm_start(duty,cycle_time_ms); + + LOS_Msleep(duration_time_ms); + + pwm_stop(); + + vibrating = 0; } } diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp index 116cd64e6..693e97cd6 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp @@ -123,23 +123,6 @@ private: OHOS::RootView::GetInstance()->Remove(boot_group); delete boot_group; boot_group = nullptr; - - - - errcode_t ret = uapi_terminate_thread(taskcfg.task_handle); - - if(ret != ERRCODE_SUCC) - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"kill boot_animation_task failed %d!",ret); - else - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"kill boot_animation_task succed !"); - - if(taskcfg.attr.stack_mem != NULL) - { - free(taskcfg.attr.stack_mem); - taskcfg.attr.stack_mem = NULL; - } - if(taskcfg.task_handle != NULL) - taskcfg.task_handle = NULL; } }; @@ -433,6 +416,24 @@ void ShowGraphicOTALogo(void) LOS_Msleep(500); } +void boot_animation_init_deinit(void) +{ + errcode_t ret = uapi_terminate_thread(taskcfg.task_handle); + + if(ret != ERRCODE_SUCC) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"kill boot_animation_task failed %d!",ret); + else + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"kill boot_animation_task succed !"); + + if(taskcfg.attr.stack_mem != NULL) + { + free(taskcfg.attr.stack_mem); + taskcfg.attr.stack_mem = NULL; + } + if(taskcfg.task_handle != NULL) + taskcfg.task_handle = NULL; +} + void boot_animation_init(void) { taskcfg.task_handle = g_boot_animation_task_handle; -- 2.17.1