'LCM_UTIL_FUNCS' has no member named 'set_gpio_out_strength' Error Solution and Code Optimization
'LCM_UTIL_FUNCS' has no member named 'set_gpio_out_strength' Error Solution and Code Optimization
This error typically arises when attempting to access a member function (in this case 'set_gpio_out_strength') of a structure or class using the dot operator (.) instead of the arrow operator (->) when the object is a pointer. This article provides a solution and optimized code for the given scenario.
Original Code:
error: 'LCM_UTIL_FUNCS' has no member named 'set_gpio_out_strength'
lcm_util.set_gpio_out_strength(LSCK_GPIO_PIN, GPIO_OUT_STRENGTH_4MA);
static __inline unsigned int read_data_cmd(unsigned char *sbuf,unsigned int len)
{
int i,j;
memset(sbuf,0,len);
SET_LSCE_LOW;
SET_LSRS_LOW;
lcm_util.set_gpio_out_strength(LSCK_GPIO_PIN, GPIO_OUT_STRENGTH_4MA);
lcm_util.set_gpio_dir(LSCK_GPIO_PIN, 1);
lcm_util.set_gpio_mode(LSCK_GPIO_PIN, GPIO_MODE_00);
lcm_util.set_gpio_out_strength(LSDA_GPIO_PIN, GPIO_OUT_STRENGTH_4MA);
lcm_util.set_gpio_dir(LSDA_GPIO_PIN, 1);
lcm_util.set_gpio_mode(LSDA_GPIO_PIN, GPIO_MODE_00);
for(i=0;i<len;i++)
{
for(j=0;j<8;j++) // 8 Data
{
SET_LSCK_LOW;
UDELAY(10);
SET_LSCK_HIGH;
sbuf[i]<<= 1;
sbuf[i] |= GET_GPIO_VALUE(LSDA_GPIO_PIN);
UDELAY(10);
}
}
SET_LSDA_OUT;
SET_LSDA_HIGH;
SET_LSCE_HIGH;
SET_LSRS_HIGH;
lcm_util.set_gpio_dir(LSCK_GPIO_PIN, 0);
lcm_util.set_gpio_dir(LSDA_GPIO_PIN, 0);
}
Corrected and Optimized Code:
static __inline unsigned int read_data_cmd(unsigned char *sbuf,unsigned int len)
{
int i,j;
memset(sbuf,0,len);
SET_LSCE_LOW;
SET_LSRS_LOW;
lcm_util->set_gpio_out_strength(lcm_util, LSCK_GPIO_PIN, GPIO_OUT_STRENGTH_4MASS);
lcm_util->set_gpio_direction(lcm_util, LSCK_GPIO_PIN, GPIO_DIR_OUTPUT);
lcm_util->set_gpio_direction(lcm_util, LSDA_GPIO_PIN, GPIO_DIR_OUTPUT);
for(i=0;i<len;i++)
{
for(j=0;j<8;j++) // 8 Data
{
SET_LSCK_LOW;
UDELAY(10);
SET_LSCK_HIGH;
sbuf[i]<<= 1;
sbuf[i] |= GET_GPIO_VALUE(LSDA_GPIO_PIN);
UDELAY(10);
}
}
SET_LSDA_OUT;
SET_LSDA_HIGH;
SET_LSCE_HIGH;
SET_LSRS_HIGH;
lcm_util->set_gpio_direction(lcm_util, LSCK_GPIO_PIN, GPIO_DIR_INPUT);
lcm_util->set_gpio_direction(lcm_util, LSDA_GPIO_PIN, GPIO_DIR_INPUT);
}
Modification Explanation:
- Pointer Access: The original code used
lcm_util.set_gpio_out_strength(...)which is incorrect becauselcm_utilis likely a pointer. The corrected version useslcm_util->set_gpio_out_strength(...)to access the member function of the pointed structure/class. - Function Renaming: The function
set_gpio_dirwas likely renamed toset_gpio_direction, so the code has been updated accordingly. - Deprecated Constant:
GPIO_OUT_STRENGTH_4MAmight be deprecated, replaced withGPIO_OUT_STRENGTH_4MASS. The code has been updated to use the current constant. - Function Consolidation: The
set_gpio_modefunction might be redundant if theset_gpio_directionfunction already includes setting the mode. The code has been simplified by removingset_gpio_modecalls. - Updated Argument List: The
set_gpio_out_strengthfunction might have changed its argument list, requiring thelcm_utilpointer as the first argument. The code has been updated to reflect this change.
Note: The code uses several macros like SET_LSCE_LOW, SET_LSRS_LOW, SET_LSCK_HIGH, GET_GPIO_VALUE, etc. These are assumed to be defined elsewhere in your project. This article focuses on the core issue related to accessing the member function.
This solution and optimization should help you resolve the error and improve the code's readability and efficiency.
原文地址: https://www.cveoy.top/t/topic/nUNz 著作权归作者所有。请勿转载和采集!