From fce524e340a0e8aed6b60007b9de35b4a8203a06 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Wed, 12 Nov 2025 17:20:37 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96hx3508=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../brandy_evb/board_config/board_fd272.h | 17 +++--- .../drivers/rotary_encoder/hx3508/hx3508.c | 54 ++++++++++++++++--- .../drivers/rotary_encoder/hx3508/hx3508.h | 1 + .../rotary_encoder/mixo/mixo_ots_driver.c | 2 +- .../rotary_encoder/rotary_encoder_drv.c | 4 +- .../rotary_encoder/rotary_encoder_drv.h | 10 ++++ code/sdk/zhihui/utils/custom_cmd_service.c | 11 +++- code/sdk/zhihui/utils/custom_utils.h | 2 + 8 files changed, 84 insertions(+), 17 deletions(-) diff --git a/code/sdk/drivers/boards/brandy_evb/board_config/board_fd272.h b/code/sdk/drivers/boards/brandy_evb/board_config/board_fd272.h index c67c325a1..8c1942b48 100644 --- a/code/sdk/drivers/boards/brandy_evb/board_config/board_fd272.h +++ b/code/sdk/drivers/boards/brandy_evb/board_config/board_fd272.h @@ -31,6 +31,11 @@ extern void mixo_int_callback(pin_t pin, uintptr_t param); extern void cywee_int_callback(pin_t pin, uintptr_t param); #endif +#ifdef ROTARYENCODER_HX3508 +extern void hx3508_int_callback(pin_t pin, uintptr_t param); +#endif + + /** * @addtogroup connectivity_config_boards * @{ @@ -215,11 +220,9 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { // #else { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_R2 VIBR_PWM 马达控制脚 兼容预留马达驱动复位脚 // #endif -#ifdef BOARD_N9 + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_ENBALE }, // S_AGPIO_R3 NC -#else - { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, -#endif + { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_AGPIO_R4 tp reset { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R5 touch int { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_AGPIO_R6 PRG_INT 心率中断 @@ -334,9 +337,6 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { /**S_AGPIO_L32 GPO gps reset*/ // { S_AGPIO_L32, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL }, #endif -#ifdef ENABLE_BN02 - { S_AGPIO_R3, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, bp_int_callback }, -#endif #ifdef SUPPORT_PPG_SERVICE #ifdef PPG_GH3X2X { S_AGPIO_R6, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE, ppg_int_callback}, @@ -347,6 +347,9 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { #ifdef ROTARYENCODER_MIXO { S_AGPIO_L0, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_FALLING_EDGE, mixo_int_callback}, #endif +#ifdef ROTARYENCODER_HX3508 + { S_AGPIO_R3, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_FALLING_EDGE, hx3508_int_callback}, +#endif }; /** * @} diff --git a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c index ed2a2a697..dc9451347 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.c @@ -46,6 +46,8 @@ //custom to do here #endif //NORDIC_SDK +#define INT_PIN S_AGPIO_R3 + #define HX3508_I2C_BUS I2C_BUS_2 #define HAISI_SDK @@ -71,6 +73,8 @@ extern encoder_callback g_encoder_callback; static uint8_t ost_init = 0; +static uint16_t timer_cnt = 0; + /*--------以下为定时函数相关定义 建立/启动/停止定时器//定时中断处理-----------*/ @@ -103,10 +107,12 @@ void ots_timer_creat(void) */ void ots_timer_start(void) { - if(ots_timer_running == false) + // printf("ots_timer_running:%d\n",ots_timer_running); + if(ots_timer_running == false && g_hx3508_timer) { // app_timer_start(g_hx3508_timer, APP_TIMER_TICKS(50), NULL);//定义为50ms定时器间隔 - osTimerStart(g_hx3508_timer,50); + int ret = osTimerStart(g_hx3508_timer,20); + // printf("ret:%d\n",ret); ots_timer_running = true; } } @@ -118,8 +124,12 @@ void ots_timer_start(void) void ots_timer_stop(void) { // app_timer_stop(g_hx3508_timer); - osTimerStop(g_hx3508_timer); - ots_timer_running = false; + if(ots_timer_running == true && g_hx3508_timer) + { + osTimerStop(g_hx3508_timer); + ots_timer_running = false; + } + } /** * 定时器超时处理函数 @@ -468,6 +478,7 @@ void ots_write_reg(uint8_t regaddr, uint8_t regvalue) void ots_data_handler(void *p_event_data, uint16_t event_size) { + // printf("ots_data_handler \n"); int16_t deltax = 0; int16_t deltay = 0; uint8_t sleepstatus = 0; @@ -477,6 +488,7 @@ void ots_data_handler(void *p_event_data, uint16_t event_size) // if((ots_read_reg(RA_MOTION_BIT)&0x80)||(nrf_gpio_pin_read(PIN_TYHX_MOT)==false)) if((ots_read_reg(RA_MOTION_BIT)&0x80)) { + timer_cnt = 0; stand_still = 0; //X Y的数据必须全部被读出,但是我们只需要X的结果来判断方向和速度 deltax = ots_read_reg(RA_ACC_DELTA_X_LOW) |(ots_read_reg(RA_ACC_DELTA_X_HIG)<<8); @@ -493,10 +505,17 @@ void ots_data_handler(void *p_event_data, uint16_t event_size) //用户添加程序, deltay 是表冠产生数据, 上报给UI, 如果需要数据变化, // 积攒到一定值再上报UI, 可以调用 ots_result_deal()函数处理. - ots_result_deal(deltax); + ots_result_deal(deltay); } else { + timer_cnt++; + if (timer_cnt >= 200) // 20*10 = // 200ms:200ms内sensor没有检测到表冠转动就会关闭定时器重新开启中断响应 + { + // printf("hx3508 enter int mode\n"); + ots_timer_stop(); // 关闭定时器 + uapi_pin_set_ie(INT_PIN,HAL_PIO_IE_ENBALE); + } if (stand_still == 0) { //上次是转动,上报状态改变 @@ -504,6 +523,11 @@ void ots_data_handler(void *p_event_data, uint16_t event_size) } stand_still = 1; + //冠轴静止的时候, 打印图像的质量和PD的饱和度, 这两个参数读取要放在出货测试的程序里面, + // 图像质量应该>=80, 否则可能代表芯片表面有脏污等或者装配问题或者有漏光 + // PD的饱和度应该>=100 且 <=180, 如果有漏光等问题, 结果>=240以上, 相关漏光等要处理 + // TYHX_LOG("pic qulity =%d, pd saturation=%d\r\n",crown_read_reg(Img_Qa),crown_read_reg(PD_SAT)); + //debug的时候, 可能用到, 看一下图像质量 TYHX_LOG("pic qulity =%d, agc num=%d\r\n",ots_read_reg(RA_DATA_2AGC),ots_read_reg(RA_EXP_NUM_SEL)&0x7F); } @@ -627,6 +651,9 @@ void ots_init(void) uapi_gpio_set_dir(POWER_3V3_PIN,GPIO_DIRECTION_OUTPUT); uapi_gpio_set_val(POWER_3V3_PIN,GPIO_LEVEL_HIGH); + // uapi_gpio_set_dir(INT_PIN,GPIO_DIRECTION_INPUT); + // uapi_pin_set_ie(INT_PIN,HAL_PIO_IE_ENBALE); + LOS_Mdelay(20); int i; @@ -750,6 +777,7 @@ void ots_start(void) ots_timer_start(); #endif + // uapi_pin_set_ie(INT_PIN,HAL_PIO_IE_ENBALE); } /** * 停止OTS 的工作, 并进入power down, 功耗<4uA @@ -763,7 +791,7 @@ void ots_stop(void) ots_write_reg(RA_DEBUG_CAS0,0x20); //power down //LOS_Mdelay(20); TYHX_LOG("[ots_stop]\r\n"); - + // uapi_pin_set_ie(INT_PIN,HAL_PIO_IE_DISABLE); #endif } /** @@ -885,6 +913,20 @@ void hx3508_get_chip_id(uint16_t *id) } } +void hx3508_int_callback(pin_t pin, uintptr_t param) +{ + // printf("hx3508_int_callback %d 0x%X\n",pin,param); + uapi_gpio_clear_interrupt(pin); + uapi_pin_set_ie(INT_PIN,HAL_PIO_IE_DISABLE); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_ROTARY_OPEN,NULL,0); +} + +void hx3508_open(void) +{ + ots_init(); + ots_start(); // 启动定时器 +} + #else //其他平台,由用户自行添加上面对应的程序 //custom to do here diff --git a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.h b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.h index e91575dee..9e6b813b5 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.h +++ b/code/sdk/zhihui/drivers/rotary_encoder/hx3508/hx3508.h @@ -189,5 +189,6 @@ bool ots_factory_test(void); int16_t hx3508_get_crown_result(void); int16_t hx3508_get_stand_still(void); void hx3508_get_chip_id(uint16_t *id); +void hx3508_open(void); #endif //_TYHX__OTS_hx3508_CUSTOM_H diff --git a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c index 0979449e4..2364c3486 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/mixo/mixo_ots_driver.c @@ -96,7 +96,7 @@ void mixo_ots_timer_callback(void) else { timer_cnt++; - if (timer_cnt == 200) // 20*10 = // 200ms:200ms内sensor没有检测到表冠转动就会关闭定时器重新开启中断响应 + if (timer_cnt >= 200) // 20*10 = // 200ms:200ms内sensor没有检测到表冠转动就会关闭定时器重新开启中断响应 { // printf("mixo enter int mode\n"); /** diff --git a/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c b/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c index 1833759c5..61e6d855e 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c +++ b/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.c @@ -17,8 +17,8 @@ #include "mixo_hal.h" #elif defined ROTARYENCODER_HX3507 #include "hx3507_hal.h" -#elif defined ROTARYENCODER_HX350 -#include "hx350_hal.h" +#elif defined ROTARYENCODER_HX3508 +#include "hx3508_hal.h" #endif // #if defined(TPTYPE_TMA525B) diff --git a/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.h b/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.h index ba50d8c61..ef038ee49 100644 --- a/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.h +++ b/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-07-29 10:06:52 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-11-12 12:29:12 + * @FilePath: /FD230/code/sdk/zhihui/drivers/rotary_encoder/rotary_encoder_drv.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /* * Copyright (c) @CompanyNameMagicTag 2021-2022. All rights reserved. * Description: header of touch screen driver. @@ -15,6 +23,8 @@ #define ROTARY_CHIP_ID 0x30 #elif defined ROTARYENCODER_MIXO #define ROTARY_CHIP_ID 0x585b +#elif defined ROTARYENCODER_HX3508 +#define ROTARY_CHIP_ID 0x35 #else #define ROTARY_CHIP_ID 0 #endif diff --git a/code/sdk/zhihui/utils/custom_cmd_service.c b/code/sdk/zhihui/utils/custom_cmd_service.c index ed6c1b97c..0ecad6473 100644 --- a/code/sdk/zhihui/utils/custom_cmd_service.c +++ b/code/sdk/zhihui/utils/custom_cmd_service.c @@ -68,6 +68,10 @@ // void cat1_start_SCO_audio_(void){} #endif +#ifdef ROTARYENCODER_HX3508 +#include "hx3508.h" +#endif + #ifdef SUPPORT_BLE_SERVICE #include "bleService.h" #ifdef BLE_INSTRUCT @@ -475,8 +479,13 @@ case CUSTOM_CMD_MSG_START_AI_ASR: case CUSTOM_CMD_MSG_AUDIO_DEINIT: PRINT("Audio deinit via custom cmd\n"); ln_ws_audio_deinit(); - break; #endif + break; + case CUSTOM_CMD_MSG_ROTARY_OPEN: +#ifdef ROTARYENCODER_HX3508 + hx3508_open(); +#endif + break; default: PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd); break; diff --git a/code/sdk/zhihui/utils/custom_utils.h b/code/sdk/zhihui/utils/custom_utils.h index 2c9642138..cbaa5687c 100644 --- a/code/sdk/zhihui/utils/custom_utils.h +++ b/code/sdk/zhihui/utils/custom_utils.h @@ -261,6 +261,8 @@ uint32_t uapi_calendar_store_date(void); #define CUSTOM_CMD_MSG_AUDIO_INIT 0x27 +#define CUSTOM_CMD_MSG_ROTARY_OPEN 0x28 + typedef enum { BR_HFP_CONNECT=1, BR_HFP_DISCONNECT, -- 2.17.1