1.修改函数传参类型。
This commit is contained in:
@@ -51,45 +51,45 @@ mr_err_t ch32_adc_configure(mr_adc_t adc, mr_state_t state)
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
mr_err_t ch32_adc_channel_configure(mr_adc_t adc, mr_uint16_t channel, mr_state_t state)
|
||||
mr_err_t ch32_adc_channel_configure(mr_adc_t adc, struct mr_adc_config *config)
|
||||
{
|
||||
struct ch32_adc *hw = (struct ch32_adc *)adc->device.data;
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
GPIO_TypeDef *GPIOx = {0};
|
||||
|
||||
if (channel <= 7)
|
||||
if (config->channel <= 7)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
GPIOx = GPIOA;
|
||||
} else if (channel <= 10)
|
||||
} else if (config->channel <= 10)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
GPIOx = GPIOB;
|
||||
} else if (channel <= 15)
|
||||
} else if (config->channel <= 15)
|
||||
{
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
GPIOx = GPIOC;
|
||||
}
|
||||
else if(channel <= 17)
|
||||
else if(config->channel <= 17)
|
||||
{
|
||||
ADC_TempSensorVrefintCmd(ENABLE);
|
||||
}
|
||||
else
|
||||
return -MR_ERR_INVALID;
|
||||
|
||||
if (state == MR_ENABLE)
|
||||
if (config->state == MR_ENABLE)
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||
else
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = (1 << channel);
|
||||
GPIO_InitStructure.GPIO_Pin = (1 << config->channel);
|
||||
GPIO_Init(GPIOx, &GPIO_InitStructure);
|
||||
|
||||
MR_LOG_D(LOG_TAG,
|
||||
"Config %s %d %d\r\n",
|
||||
hw->name,
|
||||
channel,
|
||||
state);
|
||||
config->channel,
|
||||
config->state);
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ mr_err_t ch32_dac_configure(mr_dac_t dac, mr_state_t state)
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
mr_err_t ch32_dac_channel_configure(mr_dac_t dac, mr_uint16_t channel, mr_state_t state)
|
||||
mr_err_t ch32_dac_channel_configure(mr_dac_t dac, struct mr_dac_config *config)
|
||||
{
|
||||
struct ch32_dac *hw = (struct ch32_dac *)dac->device.data;
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
@@ -83,8 +83,8 @@ mr_err_t ch32_dac_channel_configure(mr_dac_t dac, mr_uint16_t channel, mr_state_
|
||||
MR_LOG_D(LOG_TAG,
|
||||
"Config %s %d %d\r\n",
|
||||
hw->name,
|
||||
channel,
|
||||
state);
|
||||
config->channel,
|
||||
config->state);
|
||||
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
@@ -39,9 +39,7 @@ static mr_err_t mr_adc_ioctl(mr_device_t device, int cmd, void *args)
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
return adc->ops->channel_configure(adc,
|
||||
((struct mr_adc_config *)args)->channel,
|
||||
((struct mr_adc_config *)args)->state);
|
||||
return adc->ops->channel_configure(adc, (struct mr_adc_config *)args);
|
||||
}
|
||||
return - MR_ERR_INVALID;
|
||||
}
|
||||
@@ -58,7 +56,7 @@ static mr_ssize_t mr_adc_read(mr_device_t device, mr_off_t pos, void *buffer, mr
|
||||
|
||||
if (size < sizeof(*recv_buffer))
|
||||
{
|
||||
MR_LOG_E(LOG_TAG, "Device %s: Invalid read size %d\r\n", device->object.name, size);
|
||||
MR_LOG_E(LOG_TAG, "Device %s: Invalid read bufsz %d\r\n", device->object.name, size);
|
||||
return - MR_ERR_INVALID;
|
||||
}
|
||||
|
||||
@@ -77,7 +75,7 @@ static mr_err_t _err_io_adc_configure(mr_adc_t adc, mr_state_t state)
|
||||
return - MR_ERR_IO;
|
||||
}
|
||||
|
||||
static mr_err_t _err_io_adc_channel_configure(mr_adc_t adc, mr_uint16_t channel, mr_state_t state)
|
||||
static mr_err_t _err_io_adc_channel_configure(mr_adc_t adc, struct mr_adc_config *config)
|
||||
{
|
||||
MR_ASSERT(0);
|
||||
return - MR_ERR_IO;
|
||||
|
||||
@@ -25,7 +25,7 @@ typedef struct mr_adc *mr_adc_t;
|
||||
struct mr_adc_ops
|
||||
{
|
||||
mr_err_t (*configure)(mr_adc_t adc, mr_state_t state);
|
||||
mr_err_t (*channel_configure)(mr_adc_t adc, mr_uint16_t channel, mr_state_t state);
|
||||
mr_err_t (*channel_configure)(mr_adc_t adc, struct mr_adc_config *config);
|
||||
mr_uint32_t (*read)(mr_adc_t adc, mr_uint16_t channel);
|
||||
};
|
||||
|
||||
|
||||
@@ -39,9 +39,7 @@ static mr_err_t mr_dac_ioctl(mr_device_t device, int cmd, void *args)
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
return dac->ops->channel_configure(dac,
|
||||
((struct mr_dac_config *)args)->channel,
|
||||
((struct mr_dac_config *)args)->state);
|
||||
return dac->ops->channel_configure(dac, (struct mr_dac_config *)args);
|
||||
}
|
||||
return - MR_ERR_INVALID;
|
||||
}
|
||||
@@ -77,7 +75,7 @@ static mr_err_t _err_io_dac_configure(mr_dac_t dac, mr_state_t state)
|
||||
return - MR_ERR_IO;
|
||||
}
|
||||
|
||||
static mr_err_t _err_io_dac_channel_configure(mr_dac_t dac, mr_uint16_t channel, mr_state_t state)
|
||||
static mr_err_t _err_io_dac_channel_configure(mr_dac_t dac, struct mr_dac_config *config)
|
||||
{
|
||||
MR_ASSERT(0);
|
||||
return - MR_ERR_IO;
|
||||
@@ -117,4 +115,4 @@ mr_err_t mr_hw_dac_add(mr_dac_t dac, const char *name, struct mr_dac_ops *ops, v
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -25,7 +25,7 @@ typedef struct mr_dac *mr_dac_t;
|
||||
struct mr_dac_ops
|
||||
{
|
||||
mr_err_t (*configure)(mr_dac_t dac, mr_state_t state);
|
||||
mr_err_t (*channel_configure)(mr_dac_t dac, mr_uint16_t channel, mr_state_t state);
|
||||
mr_err_t (*channel_configure)(mr_dac_t dac, struct mr_dac_config *config);
|
||||
void (*write)(mr_dac_t dac, mr_uint16_t channel, mr_uint32_t value);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user