From: penglei <1624952103@qq.com> Date: Tue, 30 Apr 2024 06:22:32 +0000 (+0800) Subject: 统一cywee、磁力计、ppg的I2C通信接口,解决冲突问题。产测部分代码。 X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~42^2~2 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=f4d916c4c708c447a940334e003613aa1d0251b9;p=mirrors%2FFD230.git 统一cywee、磁力计、ppg的I2C通信接口,解决冲突问题。产测部分代码。 --- diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index a2dbe4884..a4a53d4f2 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -91,6 +91,10 @@ #include "uart_slip.h" #endif +#ifdef ENABLE_CUSTOM_I2C +#include "custom_utils.h" +#endif + #define EMMC_BASE_ADDR 0x52062000 #define TASK_PRIORITY_APP (osPriority_t)(17) #define TICK_TEN_MS (10U) @@ -348,17 +352,40 @@ static void thread_main(const void *unused) uapi_battery_init(); #endif -#ifdef MAG_MMC5603 - uapi_mag_service_init(); +#ifdef ENABLE_CUSTOM_I2C + errcode_t result = custom_iic_init(); + if(result != SUCC) + PRINT("custom_iic_init failed !!! \r\n"); + else + { + PRINT("custom_iic_init succed !!! \r\n"); + #ifdef MAG_MMC5603 + uapi_mag_service_init(); + #endif + + #ifdef SUPPORT_PPG_SERVICE + uapi_ppg_service_init(); + #endif + + #ifdef ENABLE_CYWEE + uapi_cywee_service_init(); + #endif + + } + #endif + +// #ifdef MAG_MMC5603 +// uapi_mag_service_init(); +// #endif #ifdef ACC_LIS2DOC uapi_acc_service_init(); #endif -#ifdef SUPPORT_PPG_SERVICE - uapi_ppg_service_init(); -#endif +// #ifdef SUPPORT_PPG_SERVICE +// uapi_ppg_service_init(); +// #endif #ifdef ENABLE_SLIP slip_uart_init(); @@ -366,9 +393,9 @@ static void thread_main(const void *unused) uapi_custom_cmd_service_init(); -#ifdef ENABLE_CYWEE - uapi_cywee_service_init(); -#endif +// #ifdef ENABLE_CYWEE +// uapi_cywee_service_init(); +// #endif #ifdef SUPPORT_ALIPAY_SEC uapi_alipay_svr_init(); diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index cee04da9f..340124cb7 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -58,19 +58,38 @@ char * struct_to_json_buf_malloc_() cJSON *data; } -void add_addressbookToRead(char *data)//转化用于·c文件 +void add_addressbookToRead(char *data) { - char *name=NULL; - char *phone=NULL; - name=strtok(data,","); - phone=strtok(NULL,NULL);//data+strlen(name); - PRINT("phone : %s \r\n",phone); - OHOS::add_addressbook_by_AT(name,phone); - return; -} + if(data == NULL) + { + printf("Error: data is NULL\n"); + return; + } + + char *name = NULL; + char *phone = NULL; + name = strtok(data, ","); + + if(name == NULL) + { + printf("Error: Unable to get name\n"); + return; + } + + phone = strtok(NULL, ","); + if(phone == NULL) + { + printf("Error: Unable to get phone number\n"); + return; + } + PRINT("phone : %s \r\n", phone); + OHOS::add_addressbook_by_AT(name, phone); + + return; +} void set_languaage(uint32_t id) { 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 346ac7fd4..3f1982b83 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -307,7 +307,7 @@ void aging_task(void) //while(aging_t.flag == 0xfdfd0002) { uint32_t msc; - get_rtc(&msc); + uapi_get_timestampe_ss(&msc); aging_t.enter_age_time = msc; PRINT("aging_t.enter_age_time : %d \r\n",aging_t.enter_age_time); aging_t.executions_num++; @@ -319,7 +319,7 @@ void aging_task(void) aging_t.restart_num = 0; PRINT("aging_t.restart_num : %d \r\n",aging_t.restart_num); - uint16_t before_block_num; + uint16_t before_block_num = 0; struct nand_driver_struct *nandflash_driver; nandflash_driver = get_nand_flash(); for (uint32_t i = 0; i < nandflash_driver->total_block; i++) @@ -396,7 +396,7 @@ void aging_task(void) } PRINT("aging_t.flash_res_error : %d \r\n",aging_t.flash_res_error); - uint16_t after_block_num; + uint16_t after_block_num = 0; nandflash_driver = get_nand_flash(); for (uint32_t i = 0; i < nandflash_driver->total_block; i++) { @@ -408,7 +408,7 @@ void aging_task(void) aging_t.flash_bad_block_num = after_block_num - before_block_num; - get_rtc(&msc); + uapi_get_timestampe_ss(&msc); aging_t.age_time = msc; PRINT("aging_t.age_time : %d \r\n",aging_t.age_time); aging_time -= (aging_t.age_time - aging_t.enter_age_time); @@ -676,7 +676,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint //获取RTC uint8_t time_stamp[5] = {0}; uint32_t msc = 0; - get_rtc(&msc); + uapi_get_timestampe_ss(&msc); time_stamp[1] = (uint8_t)((msc & 0XFF000000) >> 24); time_stamp[2] = (uint8_t)((msc & 0X00FF0000) >> 16); diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index ac6a2c94e..63ecd8443 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -120,6 +120,7 @@ target = { 'PPG_HX3695', # 'ACC_LIS2DOC', 'ENABLE_CYWEE', + 'ENABLE_CUSTOM_I2C', 'SUPPORT_AT_CYWEE', 'MAG_MMC5603', 'ENABLE_VIBRATOR', 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 f0951098f..7c2bf4a39 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 @@ -244,7 +244,7 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = { //默认开启Cat1 然后再根据配置决定是否关闭. //默认不开启 ppg checkid失败,原因未知,暂时开机开启cat1 -#define DEFAULT_POWERON_CAT1 1 +#define DEFAULT_POWERON_CAT1 0 //需要配置默认输出的,以及需要配置默认输入中断函数的。 const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = { diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index 851eba7af..0054c7392 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -102,172 +102,106 @@ int gpio_int_pin_init(void) -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) { - CWM_OS_dbgPrintf("cywee i2c init fail! ret=0x%x\n", result); - return ERRCODE_FAIL; - } - - CWM_OS_dbgPrintf("cywee:i2c_id = %d i2c_speed = %d \r\n", CYWEE_I2C_BUS, 400000); - - g_cywee_installed = 1; - - return ERRCODE_SUCC; -} - -int CWM_OS_i2cRead(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex) -{ - errcode_t ret; - uint32_t retry; - i2c_data_t data; - uint8_t *write_data = NULL; - cywee_i2c_init(); - - write_data = (uint8_t *)osal_kmalloc(regLength, OSAL_GFP_KERNEL); - if (write_data == NULL) { - CWM_OS_dbgPrintf("cywee send buff malloc fail! %d\n",regLength); - goto error; - } - - if( regLength == 2) - { - write_data[0] = ((uint8_t*)®)[0]; - write_data[1] = ((uint8_t*)®)[1]; - }else{ - write_data[0] = (uint8_t)reg; - } - - - data.send_buf = write_data; - data.send_len = regLength; - data.receive_buf = readData; - data.receive_len = readDataSize; - - for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { - ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, slaveAddr, &data); - if (ret == ERRCODE_SUCC) { - break; - } - } - if (ret != ERRCODE_SUCC) { - 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: - return (ret>0) ? ret*-1: ret; -} - -int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) -{ - errcode_t ret; - uint32_t retry; - i2c_data_t data; - uint8_t *write_data = NULL; - uint16_t send_len; - uint8_t *data_buf=writeData; - uint16_t data_len=writeDataSize; +// int CWM_OS_i2cWrite(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) +// { +// errcode_t ret; +// uint32_t retry; +// i2c_data_t data; +// uint8_t *write_data = NULL; +// uint16_t send_len; +// uint8_t *data_buf=writeData; +// uint16_t data_len=writeDataSize; - cywee_i2c_init(); - send_len = data_len + regLength; - write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); - if (write_data == NULL) { - CWM_OS_dbgPrintf("cywee CWM_OS_i2cWrite send buff malloc fail %d!\n",send_len); - goto error; - } - - if( regLength == 2) - { - write_data[0] = ((uint8_t*)®)[0]; - write_data[1] = ((uint8_t*)®)[1]; - }else{ - write_data[0] = (uint8_t)reg; - } - ret = (uint32_t)memcpy_s(write_data + regLength, send_len - regLength, data_buf, data_len); - if (ret != EOK) { - CWM_OS_dbgPrintf("cywee send_buf content copy fail! ret=0x%x\n", ret); - goto free_mem; - } - - data.send_buf = write_data; - data.send_len = send_len; - data.receive_buf = NULL; - data.receive_len = 0; - - for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { - ret = uapi_i2c_master_write(CYWEE_I2C_BUS, slaveAddr, &data); - if (ret == ERRCODE_SUCC) { - break; - } - } - if (ret != ERRCODE_SUCC) { - CWM_OS_dbgPrintf("CWM_OS_i2cWrite cywee data write fail! ret=0x%x\n", ret); - } -free_mem: - osal_kfree(write_data); -error: - return (ret>0) ? ret*-1: ret; -} - -int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex) -{ - errcode_t ret; - uint32_t retry; - i2c_data_t data; - uint8_t *write_data = NULL; - int16_t write_len = 0; - - cywee_i2c_init(); - write_len = regLength + writeDataSize; - write_data = (uint8_t *)osal_kmalloc(write_len, OSAL_GFP_KERNEL); - if (write_data == NULL) { - PRINT_ERR("cywee send buff malloc fail!"); - goto error; - } - - if( regLength == 2) - { - write_data[0] = ((uint8_t*)®)[0]; - write_data[1] = ((uint8_t*)®)[1]; - }else{ - write_data[0] = (uint8_t)reg; - } - - ret = (uint32_t)memcpy_s(write_data + regLength, writeDataSize, writeData, writeDataSize); - if (ret != EOK) { - CWM_OS_dbgPrintf("cywee send_buf content copy fail! ret=0x%x\n", ret); - goto free_mem; - } - data.send_buf = write_data; - data.send_len = write_len; - data.receive_buf = readData; - data.receive_len = readDataSize; - - for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { - ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, slaveAddr, &data); - if (ret == ERRCODE_SUCC) { - break; - } - } - if (ret != ERRCODE_SUCC) { - CWM_OS_dbgPrintf("CWM_OS_i2cTransfer cywee data read fail! ret=0x%x\n", ret); - } +// cywee_i2c_init(); +// send_len = data_len + regLength; +// write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); +// if (write_data == NULL) { +// CWM_OS_dbgPrintf("cywee CWM_OS_i2cWrite send buff malloc fail %d!\n",send_len); +// goto error; +// } + +// if( regLength == 2) +// { +// write_data[0] = ((uint8_t*)®)[0]; +// write_data[1] = ((uint8_t*)®)[1]; +// }else{ +// write_data[0] = (uint8_t)reg; +// } +// ret = (uint32_t)memcpy_s(write_data + regLength, send_len - regLength, data_buf, data_len); +// if (ret != EOK) { +// CWM_OS_dbgPrintf("cywee send_buf content copy fail! ret=0x%x\n", ret); +// goto free_mem; +// } + +// data.send_buf = write_data; +// data.send_len = send_len; +// data.receive_buf = NULL; +// data.receive_len = 0; + +// for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { +// ret = uapi_i2c_master_write(CYWEE_I2C_BUS, slaveAddr, &data); +// if (ret == ERRCODE_SUCC) { +// break; +// } +// } +// if (ret != ERRCODE_SUCC) { +// CWM_OS_dbgPrintf("CWM_OS_i2cWrite cywee data write fail! ret=0x%x\n", ret); +// } +// free_mem: +// osal_kfree(write_data); +// error: +// return (ret>0) ? ret*-1: ret; +// } -free_mem: - osal_kfree(write_data); -error: - return (ret>0) ? ret*-1: ret; -} +// int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex) +// { +// errcode_t ret; +// uint32_t retry; +// i2c_data_t data; +// uint8_t *write_data = NULL; +// int16_t write_len = 0; + +// cywee_i2c_init(); +// write_len = regLength + writeDataSize; +// write_data = (uint8_t *)osal_kmalloc(write_len, OSAL_GFP_KERNEL); +// if (write_data == NULL) { +// PRINT_ERR("cywee send buff malloc fail!"); +// goto error; +// } + +// if( regLength == 2) +// { +// write_data[0] = ((uint8_t*)®)[0]; +// write_data[1] = ((uint8_t*)®)[1]; +// }else{ +// write_data[0] = (uint8_t)reg; +// } + +// ret = (uint32_t)memcpy_s(write_data + regLength, writeDataSize, writeData, writeDataSize); +// if (ret != EOK) { +// CWM_OS_dbgPrintf("cywee send_buf content copy fail! ret=0x%x\n", ret); +// goto free_mem; +// } +// data.send_buf = write_data; +// data.send_len = write_len; +// data.receive_buf = readData; +// data.receive_len = readDataSize; + +// for (retry = 0; retry < CYWEE_I2C_RETRY_TIME_MAX; retry++) { +// ret = uapi_i2c_master_writeread(CYWEE_I2C_BUS, slaveAddr, &data); +// if (ret == ERRCODE_SUCC) { +// break; +// } +// } +// if (ret != ERRCODE_SUCC) { +// CWM_OS_dbgPrintf("CWM_OS_i2cTransfer cywee data read fail! ret=0x%x\n", ret); +// } + +// free_mem: +// osal_kfree(write_data); +// error: +// return (ret>0) ? ret*-1: ret; +// } //实际精度只能到1ms void CWM_OS_uSleep(uint32_t time) diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 57509ea1e..c1ad8c0ba 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -70,7 +70,7 @@ void cywee_set_user_info(int age,int gender,int weight,int height,int wearing_me CWM_SettingControl(SCL_USER_INFO, &scl); } -void time_sync(void) +void cywee_inactivity_time_sync(void) { time_t rawtime; struct tm* timeinfo; @@ -140,7 +140,7 @@ void activity_mode_setstatus(int cmd) void cyw_inactivity_mode_change(int mode) { - time_sync(); + cywee_inactivity_time_sync(); switch (mode) { //無作用 @@ -279,7 +279,7 @@ void gsensor_get_n_data(uint8_t cnt,gsenson_t t[]) // CWM_OS_dbgPrintf("get_gsonsen_xyz_fail\n"); // return; // } - CWM_OS_dbgPrintf("x=%.3f, y=%.3f, z=%.3f\n", gxyz_t_queue[left_falg].x, gxyz_t_queue[left_falg].y, gxyz_t_queue[left_falg].z); + //CWM_OS_dbgPrintf("x=%.3f, y=%.3f, z=%.3f\n", gxyz_t_queue[left_falg].x, gxyz_t_queue[left_falg].y, gxyz_t_queue[left_falg].z); t[i].x= gxyz_t_queue[left_falg].x; t[i].y= gxyz_t_queue[left_falg].y; t[i].z= gxyz_t_queue[left_falg].z; @@ -658,8 +658,8 @@ int cywee_main_dml(void) os_api api = { .GetTimeNs = CWM_OS_GetTimeNs, .dbgOutput = CWM_OS_dbgOutput, - .i2cRead = CWM_OS_i2cRead, - .i2cWrite = CWM_OS_i2cWrite, + .i2cRead = custom_i2c_read_regs, + .i2cWrite = custom_i2c_write_reg, .uSleep = CWM_OS_uSleep, .free = CWM_OS_free, .malloc = CWM_OS_malloc, @@ -672,12 +672,12 @@ int cywee_main_dml(void) OsAPI apiOS = { .GetTimeNs = CWM_OS_GetTimeNs, .dbgOutput = CWM_OS_dbgOutput, - .i2cRead = CWM_OS_i2cRead, - .i2cWrite = CWM_OS_i2cWrite, + .i2cRead = custom_i2c_read_regs, + .i2cWrite = custom_i2c_write_reg, .uSleep = CWM_OS_uSleep, .free = CWM_OS_free, .malloc = CWM_OS_malloc, - .i2cTransfer = CWM_OS_i2cTransfer, + .i2cTransfer = custom_i2c_transfer, .restoreData = CWM_OS_restoreData, .saveData = CWM_OS_saveData, .spiRead = NULL, diff --git a/code/sdk/drivers/peripheral/mag/mmc5603/mmc_customer.c b/code/sdk/drivers/peripheral/mag/mmc5603/mmc_customer.c index 89c794354..f43ba38c9 100644 --- a/code/sdk/drivers/peripheral/mag/mmc5603/mmc_customer.c +++ b/code/sdk/drivers/peripheral/mag/mmc5603/mmc_customer.c @@ -1,3 +1,13 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-03-27 09:07:00 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-04-30 09:36:57 + * @FilePath: /FD230/code/sdk/drivers/peripheral/mag/mmc5603/mmc_customer.c + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ #include "mmc_customer.h" #include "osal_timer.h" #include "osal_mutex.h" @@ -10,8 +20,8 @@ #include "hal_i2c.h" #include "soc_osal.h" #include "tcxo.h" -#define MMC5603_I2C_BUS I2C_BUS_2 -#define MMC5603_I2C_TIME_MAX 3 +#include "custom_utils.h" + void mmc5603_Delay_Ms(int cnt) { /* cnt is the time to wait */ @@ -27,122 +37,7 @@ void mmc5603_Delay_Us(int cnt) return; } -static uint8_t g_mmc_installed = 0; -/* - * @brief platform specific initialization (platform dependent) - */ -static void mmc5603_i2c_init(void) -{ - errcode_t result; - /* init i2c */ - if ( g_mmc_installed == 1 ) - return ; - - result = uapi_i2c_master_init(MMC5603_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ - if (result != ERRCODE_SUCC) { - MMC_ERROR("mmc5603 i2c init fail! ret=0x%x", result); - return ; - } - - MMC_WARNING("mmc5603:i2c_id = %d i2c_speed = %d \r\n", - MMC5603_I2C_BUS, 400000); - g_mmc_installed = 1; - return ; -} -/* - * @brief Write generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to write - * @param bufp pointer to data to write in register reg - * @param len number of consecutive register to write - * - */ -static int32_t mmc5603_platform_write(unsigned char i2c_add, uint8_t reg, const uint8_t *bufp, - uint16_t len) -{ - - errcode_t ret; - uint32_t retry; - i2c_data_t data; - uint8_t *write_data = NULL; - uint16_t send_len; - uint8_t *data_buf=bufp; - uint16_t data_len=len; - - mmc5603_i2c_init(); - send_len = data_len + sizeof(uint8_t); - write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); - if (write_data == NULL) { - MMC_ERROR("mmc5603 send buff malloc fail!"); - return ERRCODE_FAIL; - } - write_data[0] = reg; - ret = (uint32_t)memcpy_s(write_data + sizeof(uint8_t), send_len - sizeof(uint8_t), data_buf, data_len); - if (ret != EOK) { - MMC_ERROR("mmc5603 send_buf content copy fail! ret=0x%x", ret); - return ret; - } - - data.send_buf = write_data; - data.send_len = send_len; - data.receive_buf = NULL; - data.receive_len = 0; - - for (retry = 0; retry < MMC5603_I2C_TIME_MAX; retry++) { - ret = uapi_i2c_master_write(MMC5603_I2C_BUS, i2c_add, &data); - if (ret == ERRCODE_SUCC) { - break; - } - } - if (ret != ERRCODE_SUCC) { - MMC_ERROR("mmc5603 data write fail! ret=0x%x", ret); - return ret; - } - - osal_kfree(write_data); - return 0; -} - -/* - * @brief Read generic device register (platform dependent) - * - * @param handle customizable argument. In this examples is used in - * order to select the correct sensor bus handler. - * @param reg register to read - * @param bufp pointer to buffer that store the data read - * @param len number of consecutive register to read - * - */ -static int32_t mmc5603_platform_read( unsigned char i2c_add,uint8_t reg, uint8_t *bufp, - uint16_t len) -{ - errcode_t ret; - uint32_t retry; - i2c_data_t data; - - mmc5603_i2c_init(); - memset_s(bufp, len, 0, len); - data.send_buf = ® - data.send_len = 1; - data.receive_buf = bufp; - data.receive_len = len; - - for (retry = 0; retry < MMC5603_I2C_TIME_MAX; retry++) { - ret = uapi_i2c_master_writeread(MMC5603_I2C_BUS, i2c_add, &data); - if (ret == ERRCODE_SUCC) { - break; - } - } - if (ret != ERRCODE_SUCC) { - MMC_ERROR("mmc5603 data read fail! ret=0x%x", ret); - return ret; - } - - return ERRCODE_SUCC; -} int I2C_Write_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char cmd) { /* i2c_add is the 7-bit i2c address of the sensor @@ -151,7 +46,7 @@ int I2C_Write_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char cm * I2C operating successfully, return 1, otherwise return 0; */ - if ( ERRCODE_SUCC == mmc5603_platform_write(i2c_add,reg_add,&cmd,1)) + if ( ERRCODE_SUCC == custom_i2c_write_reg(i2c_add,reg_add,1,&cmd,1,I2C_BUS_2)) { return 1; }else{ @@ -165,8 +60,8 @@ int I2C_Read_Reg(unsigned char i2c_add, unsigned char reg_add, unsigned char *da * data is the first address of the buffer that need to store the register value * I2C operating successfully, return 1, otherwise return 0; */ - - if ( ERRCODE_SUCC == mmc5603_platform_read(i2c_add,reg_add,data,1)) + + if ( ERRCODE_SUCC == custom_i2c_read_regs(i2c_add,reg_add,1,data,1,I2C_BUS_2)) { return 1; }else{ @@ -183,7 +78,7 @@ int I2C_MultiRead_Reg(unsigned char i2c_add, unsigned char reg_add, int num, uns * I2C operating successfully, return 1, otherwise return 0; */ - if ( ERRCODE_SUCC == mmc5603_platform_read(i2c_add,reg_add,data,num)) + if ( ERRCODE_SUCC == custom_i2c_read_regs(i2c_add,reg_add,1,data,num,I2C_BUS_2)) { return 1; }else{ diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 5c396a8fd..55dc43c02 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -34,6 +34,8 @@ #include "cywee_hal.h" #include "cywee_service.h" +#include "custom_utils.h" + FT_CUSTOM_RESULTS_t hrsresult ={0}; @@ -180,8 +182,7 @@ void hx3695_delay_ms(uint32_t ms) // i2c 写函数, 客户需填写, 地址0x44(7bit) bool hx3695_write_reg(uint8_t addr, uint8_t data) { - - tyhx_write_reg(addr,data); + custom_i2c_write_reg(HX3695_I2C_DEV_8ADDR,addr,1,&data,1,I2C_BUS_2); return true; } @@ -190,7 +191,7 @@ uint8_t hx3695_read_reg(uint8_t addr) { uint8_t data_buf = 0; - tyhx_read_regs(addr,&data_buf,1); + custom_i2c_read_regs(HX3695_I2C_DEV_8ADDR,addr,1,&data_buf,1,I2C_BUS_2); return data_buf; } @@ -198,7 +199,7 @@ uint8_t hx3695_read_reg(uint8_t addr) bool hx3695_brust_read_reg(uint8_t addr, uint8_t *buf, uint16_t length) { //TYHX_LOG("brust read\r\n"); - tyhx_read_regs(addr,buf,length); + custom_i2c_read_regs(HX3695_I2C_DEV_8ADDR,addr,1,buf,length,I2C_BUS_2); return true; } @@ -397,13 +398,10 @@ uint8_t hx3695_get_chip_id(void) if (chip_id == 0x65) { - printf("hx3695_chip_check ok chip_id: 0x%x \r\n",chip_id); return chip_id; } } - printf(" hx3695_chip_check fail! chip_id: 0x%x \r\n", chip_id); - return chip_id; } diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c index 79acd5f63..7108c5491 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-03-13 15:08:38 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-04-22 21:03:16 + * @LastEditTime: 2024-04-30 09:36:27 * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hal.c * @Description: * @@ -66,6 +66,7 @@ void ppg_send_cmd_to_driver(char* mode, uint8_t enable) // ppg_service_running_stat = true; uapi_pm_control(PM_APP_WAKE_NEEDED); tyhx_poweron(); + custom_i2c_reset(); hx3695_init(md); } else { diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c index c6337d8a6..c78766d96 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_custom.c @@ -25,107 +25,6 @@ uint8_t hr_no_living_dur = 0; //used to increase no living dur, when no living s uint8_t spo2_no_living_dur = 0; //used to increase no living dur, when no living status detected int tyhx_long_timer_tick = 400; - -typedef struct { - i2c_bus_t i2c_id; - uint32_t i2c_speed; -} hx3695_ctrl_attr; - -static hx3695_ctrl_attr g_hx3695_ctl_handler={HX3695_I2C_BUS,400000}; -static uint8_t g_hx3695_installed = 0; -static errcode_t hx3695_i2c_init(void) -{ - errcode_t result; - /* init i2c */ - if ( g_hx3695_installed == 1 ) - return ERRCODE_SUCC; - - result = uapi_i2c_master_init(HX3695_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ - if (result != ERRCODE_SUCC) { - TYHX_ERROR("hx3695 i2c init fail! ret=0x%x", result); - return ERRCODE_FAIL; - } - - TYHX_WARNING("hx3695:i2c_id = %d i2c_speed = %d slave_addr = 0x%x \r\n", - HX3695_I2C_BUS, 400000, HX3695_I2C_DEV_8ADDR); - - g_hx3695_installed = 1; - - return ERRCODE_SUCC; -} - -uint32_t tyhx_write_reg(uint8_t reg_addr, uint8_t reg) -{ - errcode_t ret; - uint32_t retry; - i2c_data_t data; - uint8_t *write_data = NULL; - uint16_t send_len; - uint8_t *data_buf=® - uint16_t data_len=1; - - hx3695_i2c_init(); - send_len = data_len + sizeof(uint8_t); - write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); - if (write_data == NULL) { - TYHX_ERROR("hx3695 send buff malloc fail!"); - return ERRCODE_FAIL; - } - write_data[0] = reg_addr; - ret = (uint32_t)memcpy_s(write_data + sizeof(uint8_t), send_len - sizeof(uint8_t), data_buf, data_len); - if (ret != EOK) { - TYHX_ERROR("hx3695 send_buf content copy fail! ret=0x%x", ret); - return ret; - } - - data.send_buf = write_data; - data.send_len = send_len; - data.receive_buf = NULL; - data.receive_len = 0; - - for (retry = 0; retry < HX3695_I2C_TIME_MAX; retry++) { - ret = uapi_i2c_master_write(HX3695_I2C_BUS, HX3695_I2C_DEV_8ADDR, &data); - if (ret == ERRCODE_SUCC) { - break; - } - } - if (ret != ERRCODE_SUCC) { - TYHX_ERROR("hx3695 data write fail! ret=0x%x", ret); - return ret; - } - - osal_kfree(write_data); - return ERRCODE_SUCC; -} - -uint32_t tyhx_read_regs(uint8_t reg_addr, uint8_t *data_buf, uint16_t data_len) -{ - errcode_t ret; - uint32_t retry; - i2c_data_t data; - - hx3695_i2c_init(); - memset_s(data_buf, data_len, 0, data_len); - data.send_buf = ®_addr; - data.send_len = 1; - data.receive_buf = data_buf; - data.receive_len = data_len; - - for (retry = 0; retry < HX3695_I2C_TIME_MAX; retry++) { - ret = uapi_i2c_master_writeread(HX3695_I2C_BUS, HX3695_I2C_DEV_8ADDR, &data); - if (ret == ERRCODE_SUCC) { - break; - } - } - if (ret != ERRCODE_SUCC) { - TYHX_ERROR("hx3695 data read fail! ret=0x%x", ret); - return ret; - } - - return ERRCODE_SUCC; -} - - // us 延时函数, 客户需填写 void tyhx_delay_us(uint32_t us) { @@ -217,17 +116,6 @@ bool tyhx_timer_stop(uint32_t ms) return 1; } -uint32_t tyhx_suspend(void) -{ - i2c_save_reg(HX3695_I2C_BUS); - return 0; -} -uint32_t tyhx_resume(void) -{ - i2c_recovery_reg(HX3695_I2C_BUS); - return 0; -} - // S_AGPIO_L26 心率复位 PPG reset #define GPIO_PIN_PRG_RESET S_AGPIO_L26 // S_AGPIO_R0 PRG_LED_POWER ON 心率等电源控制脚 diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h b/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h index 6d40324f6..0abec51b1 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h +++ b/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-03-26 20:29:58 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-04-22 09:28:45 + * @LastEditTime: 2024-04-30 09:31:34 * @FilePath: /FD230/code/sdk/drivers/peripheral/ppg/hx3695/tyhx_hrs_custom.h * @Description: * @@ -76,10 +76,6 @@ uint32_t tyhx_read_regs( uint8_t reg_addr,uint8_t *readbuf,uint16_t readlen); bool tyhx_timer_start(uint32_t ms); bool tyhx_timer_stop(uint32_t ms); -uint32_t tyhx_suspend(void); -uint32_t tyhx_resume(void); - - uint32_t tyhx_poweron(void); uint32_t tyhx_poweroff(void); diff --git a/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp b/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp index 2ce4175b3..a6d51705c 100644 --- a/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp +++ b/code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp @@ -251,15 +251,13 @@ void uapi_ppg_service_deinit(void) ppg_service_running_stat = false; } -#include "tyhx_hrs_custom.h" - uint32_t ppg_suspend(void) { - return tyhx_suspend(); + return custom_i2c_suspend(); } uint32_t ppg_resume(void) { - return tyhx_resume(); + return custom_i2c_resume(); } diff --git a/code/sdk/drivers/peripheral/touch/touch_screen_drv.c b/code/sdk/drivers/peripheral/touch/touch_screen_drv.c index 660f2bb73..de2ac5c94 100644 --- a/code/sdk/drivers/peripheral/touch/touch_screen_drv.c +++ b/code/sdk/drivers/peripheral/touch/touch_screen_drv.c @@ -477,7 +477,7 @@ void touch_resume_for_i2c(void) void touch_screen_restart(void) { uapi_i2c_deinit(TOUCH_I2C_BUS); - uapi_i2c_master_init(TOUCH_I2C_BUS, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ + uapi_i2c_master_init(TOUCH_I2C_BUS, 100000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ #if defined(TPTYPE_TMA525B) tma525b_resume(); #elif defined(TPTYPE_ZTW523) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 6549d3630..411db41e5 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -25,6 +25,10 @@ // #include "config/include/ConfigModelC.h" #include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h" #include "networkandcall/include/NetworkAndCallC.h" +#include +#include + + #define SUPPORT_NV @@ -1118,7 +1122,8 @@ void touch_getstate(void) #include "mag_service.h" void mmc5603_getid(unsigned char *id) { - MMC5603_GETID(id); + //MMC5603_GETID(id); + MMC5603_CheckID(); } void mmc5603_getdata(float *fAzimuth,float *fPitch,float *fRoll) @@ -1200,219 +1205,6 @@ void gsensor_get_single_data(gsenson_t *t) get_gsonsen_xyz(t); } - -// 判断是否为闰年 -int isLeapYear(int year) { - return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); -} - -// 计算某年某月的天数 -int daysInMonth(int year, int month) { - const int days[12] = {31, 28 + isLeapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - return days[month - 1]; -} - -// 计算时间距离1970å¹´1月1日00:00:00的秒数 -uint32_t secondsSinceEpoch(int year,int month,int day,int hour,int min,int sec) { - const int secondsPerMinute = 60; - const int secondsPerHour = 3600; - const int secondsPerDay = 86400; - const int secondsPerYear = 31536000; // 不考虑闰秒 - - long long seconds = 0; - - // 计算年份之间的秒数 - for (int i = 1970; i < year; ++i) { - seconds += isLeapYear(i) ? secondsPerYear + secondsPerDay : secondsPerYear; - } - - // 计算月份之间的秒数 - for (int i = 1; i < month; ++i) { - seconds += daysInMonth(year, i) * secondsPerDay; - } - - // 计算当月的秒数 - seconds += (day - 1) * secondsPerDay; - seconds += hour * secondsPerHour; - seconds += min * secondsPerMinute; - seconds += sec; - - return seconds; -} - -void get_rtc(uint32_t *seconds) -{ - - time_t rawtime; - struct tm* timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - *seconds = secondsSinceEpoch(timeinfo->tm_year + 1900, - timeinfo->tm_mon + 1, - timeinfo->tm_mday, - timeinfo->tm_hour, - timeinfo->tm_min, - timeinfo->tm_sec); - PRINT("msc : %d \r\n",*seconds); -} - -//#include "lis2doc_reg.h" - -#include "stdio.h" - -/**** 静态全局变量 ****/ -static int width = 200; //LCD X 分辨率 -static int height = 200; //LCD Y 分辨率 -static uint32_t *bmp_buf = NULL; //bmp_buf -static unsigned long line_length; //LCD 一行的长度(字节为单位) - -/**** BMP 文件头数据结构 ****/ -typedef struct { - unsigned char type[2]; //文件类型 - unsigned int size; //文件大小 - unsigned short reserved1; //保留字段 1 - unsigned short reserved2; //保留字段 2 - unsigned int offset; //到位图数据的偏移量 -} __attribute__ ((packed)) bmp_file_header; - -/**** 位图信息头数据结构 ****/ -typedef struct { - unsigned int size; //位图信息头大小 - int width; //图像宽度 - int height; //图像高度 - unsigned short planes; //位面数 - unsigned short bpp; //像素深度 - unsigned int compression; //压缩方式 - unsigned int image_size; //图像大小 - int x_pels_per_meter; //像素/ç±³ - int y_pels_per_meter; //像素/ç±³ - unsigned int clr_used; - unsigned int clr_omportant; -} __attribute__ ((packed)) bmp_info_header; - -int set_bmp(void) -{ - unsigned short *line_buf = NULL; //行缓冲区 - unsigned long line_bytes; //BMP 图像一行的字节的大小 - unsigned int min_h, min_bytes; - - const char *path = {"/system/1.bmp"}; - bmp_file_header file_h; - bmp_info_header info_h; - - int j; - - /* 打开BMP 文件 */ - FILE *fp = fopen(path, "r"); - if (fp == NULL) { - fclose(fp); - PRINT("file open failed !!!\r\n"); - return -1; - } - PRINT("file open succ !!!\r\n"); - /* 读取 BMP 文件头 */ - if (sizeof(bmp_file_header) != fread(&file_h, 1, sizeof(bmp_file_header),fp) ) - { - PRINT(" read bmp_file_header failed !!!\r\n"); - fclose(fp); - return -1; - } - PRINT("file read succ !!!\r\n"); - if (0 != memcmp(file_h.type, "BM", 2)) - { - PRINT("it's not a BMP file !!!\r\n"); - fclose(fp); - return -1; - } - - /* 读取位图信息头 */ - if (sizeof(bmp_info_header) != fread(&info_h, 1,sizeof(bmp_info_header),fp) ) - { - PRINT("read bmp_info_header error !!!\r\n"); - fclose(fp); - return -1; - } - /* 打印信息 */ - PRINT("文件大小: %d\n" - "位图数据的偏移量: %d\n" - "位图信息头大小: %d\n" - "图像分辨率: %d*%d\n" - "像素深度: %d\n", file_h.size, file_h.offset, - info_h.size, info_h.width, info_h.height, - info_h.bpp); - - /* 将文件读写位置移动到图像数据开始处 */ - if (-1 == fseek(fp, file_h.offset, SEEK_SET)) - { - PRINT("file lseek error !!!\r\n"); - fclose(fp); - return -1; - } - PRINT("file lseek succ !!!\r\n"); - - /* 申请一个 buf、暂存 bmp 图像的一行数据 */ - line_bytes = info_h.width * info_h.bpp / 8; - line_buf = malloc(line_bytes); - bmp_buf = malloc(file_h.size); - if (NULL == line_buf) - { - fclose(fp); - return -1; - } - else - PRINT("malloc succ !!!\r\n"); - - - if (line_length > line_bytes) - min_bytes = line_bytes; - else - min_bytes = line_length; - - if (0 < info_h.height) - {//倒向位图 - if (info_h.height > height) - { - min_h = height; - fseek(fp, (info_h.height - height) * line_bytes, SEEK_CUR); - bmp_buf += width * (height - 1); //定位到屏幕左下角位置 - } - else - { - min_h = info_h.height; - bmp_buf += width * (info_h.height - 1); - } - for (j = min_h; j > 0; bmp_buf -= width, j--) - { - fread( line_buf, 1, line_bytes ,fp); //读取出图像数据 - memcpy(bmp_buf, line_buf, min_bytes);// - } - } - else - { //正向位图 - int temp = 0 - info_h.height; //负数转成正数 - if (temp > height) - min_h = height; - else - min_h = temp; - for (j = 0; j < min_h; j++, bmp_buf += width) - { - fread(line_buf, 1 ,line_bytes , fp); - memcpy(bmp_buf, line_buf, min_bytes); - } - } - - int size = strlen(bmp_buf); - PRINT("bmp_buf size : %d\r\n",size); - - /* 关闭文件、函数返回 */ - fclose(fp); - free(line_buf); - return 1; -} - -#include -#include - int removeFilesInFolder(const char *folderPath) { DIR *dir; @@ -1487,17 +1279,6 @@ void uapi_delete_files(void) } } -int enter_recovery(void) -{ - // if(set_bmp() == -1) - // { - // PRINT("set bmp failed !!! \r\n"); - // return -1; - // } - return 1; - //upg_reboot(); -} - #include "driver/calendar.h" uint32_t uapi_calendar_store_date(void) @@ -1556,3 +1337,236 @@ uint32_t uapi_calendar_recover_date(void) return ret; } +#include "tyhx_hrs_custom.h" + +void get_ppg_id(void) +{ + tyhx_poweron(); + hx3695_chip_check(); + tyhx_poweroff(); +} + +#include "hal_i2c.h" +#include "i2c.h" +#define CUSTOM_I2C_TIME_MAX 3 + +static uint8_t i2c_installed = 0; +static uint8_t i2c_mutex_installed = 0; +static osal_mutex i2c_mutex; + +void custom_i2c_reset(void) +{ + errcode_t result; + if(i2c_mutex_installed == 0) + { + osal_mutex_init(&i2c_mutex); + i2c_mutex_installed = 1; + } + + result = osal_mutex_lock(&i2c_mutex); + if (result != ERRCODE_SUCC) + { + PRINT(" i2c lock fail! ret=0x%x\n", result); + return ; + } + + if(i2c_installed == 1) + { + result = uapi_i2c_deinit(I2C_BUS_2); + if (result != ERRCODE_SUCC) + { + PRINT(" i2c deinit fail! ret=0x%x\n", result); + return ; + } + i2c_installed = 0; + } + + LOS_Mdelay(5); + + if(i2c_installed == 0) + { + result = uapi_i2c_master_init(I2C_BUS_2, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ + if (result != ERRCODE_SUCC) { + PRINT(" i2c init fail! ret=0x%x\n", result); + return ; + } + i2c_installed = 1; + } + + LOS_Mdelay(5); + + osal_mutex_unlock(&i2c_mutex); +} + +errcode_t custom_iic_init(void) +{ + errcode_t result; + if(i2c_installed == 0) + { + result = uapi_i2c_master_init(I2C_BUS_2, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ + + if (result != ERRCODE_SUCC) { + PRINT("cywee i2c init fail! ret=0x%x\n", result); + return ERRCODE_FAIL; + } + + i2c_installed = 1; + return ERRCODE_SUCC; + } + else + return ERRCODE_FAIL; +} + +errcode_t custom_i2c_read_regs(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + // custom_iic_init(); + + write_data = (uint8_t *)osal_kmalloc(regLength, OSAL_GFP_KERNEL); + if (write_data == NULL) { + PRINT("send buff malloc fail! %d\n",regLength); + goto error; + } + + if( regLength == 2) + { + write_data[0] = ((uint8_t*)®)[0]; + write_data[1] = ((uint8_t*)®)[1]; + }else{ + write_data[0] = (uint8_t)reg; + } + + + data.send_buf = write_data; + data.send_len = regLength; + data.receive_buf = readData; + data.receive_len = readDataSize; + + for (retry = 0; retry < CUSTOM_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(busIndex, slaveAddr, &data); + if (ret == ERRCODE_SUCC) { + break; + } + } + if (ret != ERRCODE_SUCC) { + PRINT("i2cRead 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: + return (ret>0) ? ret*-1: ret; +} + +errcode_t custom_i2c_write_reg(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + uint16_t send_len; + uint8_t *data_buf=writeData; + uint16_t data_len=writeDataSize; + + //custom_iic_init(); + send_len = data_len + regLength; + write_data = (uint8_t *)osal_kmalloc(send_len, OSAL_GFP_KERNEL); + if (write_data == NULL) { + PRINT("i2cWrite send buff malloc fail %d!\n",send_len); + goto error; + } + + if( regLength == 2) + { + write_data[0] = ((uint8_t*)®)[0]; + write_data[1] = ((uint8_t*)®)[1]; + }else{ + write_data[0] = (uint8_t)reg; + } + ret = (uint32_t)memcpy_s(write_data + regLength, send_len - regLength, data_buf, data_len); + if (ret != EOK) { + PRINT("send_buf content copy fail! ret=0x%x\n", ret); + goto free_mem; + } + + data.send_buf = write_data; + data.send_len = send_len; + data.receive_buf = NULL; + data.receive_len = 0; + + for (retry = 0; retry < CUSTOM_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_write(busIndex, slaveAddr, &data); + if (ret == ERRCODE_SUCC) { + break; + } + } + if (ret != ERRCODE_SUCC) { + PRINT("i2cWrite cywee data write fail! ret=0x%x\n", ret); + } +free_mem: + osal_kfree(write_data); +error: + return (ret>0) ? ret*-1: ret; +} + +errcode_t custom_i2c_transfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex) +{ + errcode_t ret; + uint32_t retry; + i2c_data_t data; + uint8_t *write_data = NULL; + int16_t write_len = 0; + + //custom_iic_init(); + write_len = regLength + writeDataSize; + write_data = (uint8_t *)osal_kmalloc(write_len, OSAL_GFP_KERNEL); + if (write_data == NULL) { + PRINT(" send buff malloc fail!"); + goto error; + } + + if( regLength == 2) + { + write_data[0] = ((uint8_t*)®)[0]; + write_data[1] = ((uint8_t*)®)[1]; + }else{ + write_data[0] = (uint8_t)reg; + } + + ret = (uint32_t)memcpy_s(write_data + regLength, writeDataSize, writeData, writeDataSize); + if (ret != EOK) { + PRINT("send_buf content copy fail! ret=0x%x\n", ret); + goto free_mem; + } + data.send_buf = write_data; + data.send_len = write_len; + data.receive_buf = readData; + data.receive_len = readDataSize; + + for (retry = 0; retry < CUSTOM_I2C_TIME_MAX; retry++) { + ret = uapi_i2c_master_writeread(busIndex, slaveAddr, &data); + if (ret == ERRCODE_SUCC) { + break; + } + } + if (ret != ERRCODE_SUCC) { + PRINT("data read fail! ret=0x%x\n", ret); + } + +free_mem: + osal_kfree(write_data); +error: + return (ret>0) ? ret*-1: ret; +} + +uint32_t custom_i2c_suspend(void) +{ + i2c_save_reg(I2C_BUS_2); + return 0; +} +uint32_t custom_i2c_resume(void) +{ + i2c_recovery_reg(I2C_BUS_2); + return 0; +} diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 6623aebac..642054f5d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -119,8 +119,6 @@ void battery_getvolpower(uint8_t *power); void flash_getid(uint32_t *id); void flash_erase(void); -void get_rtc(uint32_t *seconds); - //进入recovery int enter_recovery(void); //设置bmp图片 @@ -156,6 +154,13 @@ errcode_t uapi_custom_cmd_service_init(void); void do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen); void uapi_delete_files(void); +void custom_i2c_reset(void); +errcode_t custom_i2c_write_reg(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex); +errcode_t custom_i2c_read_regs(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex); +errcode_t custom_i2c_transfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex); + +uint32_t custom_i2c_suspend(void); +uint32_t custom_i2c_resume(void); #ifdef __cplusplus } 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 a899a8a63..c780737f5 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -287,17 +287,6 @@ static uint32_t custom_flash_erase(uint8_t *para, uint32_t paraLen, char *strCom return ERRCODE_SUCC; } -static uint32_t custom_enter_recovery(uint8_t *para, uint32_t paraLen, char *strCommonCmd) -{ - - UNUSED(strCommonCmd); - - if(enter_recovery() == -1) - return ERRCODE_FAIL; - - return ERRCODE_SUCC; -} - #include "cywee_hal.h" #include "hx3695_hrs_agc.h" static uint32_t custom_gsensor_getdata(uint8_t *para, uint32_t paraLen, char *strCommonCmd) @@ -354,6 +343,27 @@ static uint32_t custom_bleservice_test(uint8_t *para, uint32_t paraLen, char *st return ERRCODE_SUCC; } +static uint32_t custom_get_ppg_id(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + + UNUSED(strCommonCmd); + + get_ppg_id(); + + return ERRCODE_SUCC; +} + +static uint32_t custom_get_mmc_id(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + + UNUSED(strCommonCmd); + + unsigned char id; + mmc5603_getid(&id); + + return ERRCODE_SUCC; +} + static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^CUSTOM_SN", custom_utils_setsn, (char *)"123456789ABCDEF2345678" }, { (char *)"AT^CUSTOM_SN_REQ", custom_utils_getsn, (char *)" " }, @@ -377,14 +387,16 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^FLASHERASE", custom_flash_erase, (char *)" " }, - { (char *)"AT^RECOVERY", custom_enter_recovery, (char *)" " }, - { (char *)"AT^GSENSOR", custom_gsensor_getdata, (char *)" " }, { (char *)"AT^GETTP", custom_get_tpinfo, (char *)" " }, { (char *)"AT^BLESERVICE", custom_bleservice_test, (char *)" " }, { (char *)"AT^DSPPWR", custom_dsp_power_test, (char *)" " }, + { (char *)"AT^GETPPGID", custom_get_ppg_id, (char *)" " }, + + { (char *)"AT^GETMMCID", custom_get_mmc_id, (char *)" " }, + }; at_cmd_table_t *get_custom_utils_cmd_table(uint32_t *cmd_count)