From 068748fd9c4d9bf174e2d6268984da0a01298480 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Thu, 25 Dec 2025 12:10:59 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E8=A1=A8=E5=86=A0=E6=A0=A1?= =?utf8?q?=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../drivers/rotary_encoder/hx3508/hx3508.c | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c index fe0e6298f..3a14be9d6 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c @@ -75,6 +75,8 @@ extern encoder_callback g_encoder_callback; static uint8_t ost_init = 0; +static uint8_t ost_start_flag = 0; + static uint16_t timer_cnt = 0; static float g_sum_y = 0; @@ -101,6 +103,10 @@ static void report_zero_data_for_start_stop_flag(void) void hx3508_set_factory_test_mode(uint8_t cmd) { factory_flag = cmd; + if(factory_flag == 1) + ots_write_reg(RA_DSP_EN,0x03); //进入校准模式前将这个寄存器写成0x03 + else + ots_write_reg(RA_DSP_EN,0x01); //退出校准模式后将这个寄存器写成0x01 } void hx3508_set_coffy(float data) @@ -132,7 +138,7 @@ static void hx3508_get_coffy(void) void hx3508_get_sum_y(float *data) { - if(sum_deltay && coffy!= 0 && data != 0 && sum_deltay != 0) + if(coffy!= 0 && data != 0 && sum_deltay != 0) { printf("sum_deltay : %d coffy : %.3f\n",sum_deltay,coffy); // g_sum_y = 360/(float)sum_deltay * 1200 * coffy; @@ -549,8 +555,9 @@ void ots_data_handler(void *p_event_data, uint16_t event_size) stand_still = 0; //X Y的数据必须全部被读出,但是我们只需要X的结果来判断方向和速度 deltax = ots_read_reg(RA_ACC_DELTA_X_LOW) |(ots_read_reg(RA_ACC_DELTA_X_HIG)<<8); - deltay = ots_read_reg(RA_ACC_DELTA_Y_LOW) |(ots_read_reg(RA_ACC_DELTA_Y_HIG)<<8); - TYHX_LOG("Deltay = %d \r\n",deltay);//djd0305 + deltay = ots_read_reg(RA_ACC_DELTA_Y_LOW) |(ots_read_reg(RA_ACC_DELTA_Y_HIG)<<8); + //下面这一行日志加时间戳打印 + TYHX_LOG("Deltay = %d, pic qulity =%d, agc num=%d, dsp en=%d\r\n",deltay, ots_read_reg(RA_DATA_2AGC), ots_read_reg(RA_EXP_NUM_SEL)&0x7F, ots_read_reg(RA_DSP_EN));//djd0305 // printf("deltay:%d,coffy:%.3f\n",deltay,coffy); // if(deltay && coffy) // deltay = (float)deltay * coffy; @@ -767,13 +774,12 @@ void ots_init(void) } void hx3508l_calibration(void) { - uint8_t cali75,cali74; - LOS_Mdelay(2);//必须有这个delay + uint8_t cali75; + LOS_Mdelay(10);//必须有这个delay ots_write_reg(RA_DEBUG_CAS0,0x41); cali75 = ots_read_reg(0x75); - cali74 = ots_read_reg(0x74); - if((cali75!=0x84) || (cali74 < 0x42)) + if((cali75&0x80)!=0x80) { ots_write_reg(RA_DEBUG_CAS0,0x41); LOS_Mdelay(2); @@ -793,6 +799,10 @@ void hx3508l_calibration(void) */ void ots_start(void) { + if(ost_start_flag == 1) + return; + + ost_start_flag = 1; //bool ret = true; ots_write_reg(RA_DEBUG_CAS0,0x43); LOS_Mdelay(2); //delay about 1ms @@ -862,6 +872,11 @@ void ots_start(void) */ void ots_stop(void) { + if(ost_start_flag == 0) + return; + + ost_start_flag = 0; + #ifdef MOT_NO_USE_MODE ots_timer_stop(); // uapi_pin_set_ie(INT_PIN,HAL_PIO_IE_DISABLE); -- 2.17.1