1.配置方式修改。
This commit is contained in:
@@ -16,27 +16,49 @@ static mr_err_t mr_adc_open(mr_device_t device)
|
||||
{
|
||||
mr_adc_t adc = (mr_adc_t)device;
|
||||
|
||||
return adc->ops->configure(adc, MR_ADC_STATE_ENABLE);
|
||||
return adc->ops->configure(adc, MR_ENABLE);
|
||||
}
|
||||
|
||||
static mr_err_t mr_adc_close(mr_device_t device)
|
||||
{
|
||||
mr_adc_t adc = (mr_adc_t)device;
|
||||
|
||||
return adc->ops->configure(adc, MR_ADC_STATE_DISABLE);
|
||||
/* Disable all channel */
|
||||
adc->config._channel_mask = 0;
|
||||
|
||||
return adc->ops->configure(adc, MR_DISABLE);
|
||||
}
|
||||
|
||||
static mr_err_t mr_adc_ioctl(mr_device_t device, int cmd, void *args)
|
||||
{
|
||||
mr_adc_t adc = (mr_adc_t)device;
|
||||
struct mr_adc_config *config = MR_NULL;
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
switch (cmd & _MR_CTRL_FLAG_MASK)
|
||||
{
|
||||
case MR_CTRL_CONFIG:
|
||||
case MR_CTRL_SET_CONFIG:
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
return adc->ops->channel_configure(adc, (struct mr_adc_config *)args);
|
||||
config = (struct mr_adc_config *)args;
|
||||
ret = adc->ops->channel_configure(adc, (struct mr_adc_config *)args);
|
||||
if (ret == MR_ERR_OK)
|
||||
{
|
||||
adc->config = *config;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
|
||||
case MR_CTRL_GET_CONFIG:
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
config = (struct mr_adc_config *)args;
|
||||
*config = adc->config;
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
@@ -57,6 +79,12 @@ static mr_ssize_t mr_adc_read(mr_device_t device, mr_pos_t pos, void *buffer, mr
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
|
||||
/* Check whether the channel is enabled */
|
||||
if (!((1 << pos) & adc->config._channel_mask))
|
||||
{
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
|
||||
for (recv_size = 0; recv_size < size; recv_size += sizeof(*recv_buffer))
|
||||
{
|
||||
*recv_buffer = adc->ops->read(adc, pos);
|
||||
@@ -104,6 +132,8 @@ mr_err_t mr_adc_device_add(mr_adc_t adc, const char *name, void *data, struct mr
|
||||
adc->device.data = data;
|
||||
adc->device.ops = &device_ops;
|
||||
|
||||
adc->config._channel_mask = 0;
|
||||
|
||||
/* Set operations as protection-ops if ops is null */
|
||||
ops->configure = ops->configure ? ops->configure : _err_io_adc_configure;
|
||||
ops->channel_configure = ops->channel_configure ? ops->channel_configure : _err_io_adc_channel_configure;
|
||||
|
||||
@@ -15,13 +15,50 @@
|
||||
|
||||
#if (MR_CONF_ADC == MR_CONF_ENABLE)
|
||||
|
||||
#define MR_ADC_STATE_DISABLE 0
|
||||
#define MR_ADC_STATE_ENABLE 1
|
||||
#define MR_ADC_CHANNEL_DISABLE MR_DISABLE
|
||||
#define MR_ADC_CHANNEL_ENABLE MR_ENABLE
|
||||
|
||||
struct mr_adc_config
|
||||
{
|
||||
mr_pos_t channel;
|
||||
mr_state_t state;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
mr_pos_t channel0: 1;
|
||||
mr_pos_t channel1: 1;
|
||||
mr_pos_t channel2: 1;
|
||||
mr_pos_t channel3: 1;
|
||||
mr_pos_t channel4: 1;
|
||||
mr_pos_t channel5: 1;
|
||||
mr_pos_t channel6: 1;
|
||||
mr_pos_t channel7: 1;
|
||||
mr_pos_t channel8: 1;
|
||||
mr_pos_t channel9: 1;
|
||||
mr_pos_t channel10: 1;
|
||||
mr_pos_t channel11: 1;
|
||||
mr_pos_t channel12: 1;
|
||||
mr_pos_t channel13: 1;
|
||||
mr_pos_t channel14: 1;
|
||||
mr_pos_t channel15: 1;
|
||||
mr_pos_t channel16: 1;
|
||||
mr_pos_t channel17: 1;
|
||||
mr_pos_t channel18: 1;
|
||||
mr_pos_t channel19: 1;
|
||||
mr_pos_t channel20: 1;
|
||||
mr_pos_t channel21: 1;
|
||||
mr_pos_t channel22: 1;
|
||||
mr_pos_t channel23: 1;
|
||||
mr_pos_t channel24: 1;
|
||||
mr_pos_t channel25: 1;
|
||||
mr_pos_t channel26: 1;
|
||||
mr_pos_t channel27: 1;
|
||||
mr_pos_t channel28: 1;
|
||||
mr_pos_t channel29: 1;
|
||||
mr_pos_t channel30: 1;
|
||||
mr_pos_t channel31: 1;
|
||||
};
|
||||
mr_pos_t _channel_mask;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct mr_adc *mr_adc_t;
|
||||
@@ -37,6 +74,8 @@ struct mr_adc
|
||||
{
|
||||
struct mr_device device;
|
||||
|
||||
struct mr_adc_config config;
|
||||
|
||||
const struct mr_adc_ops *ops;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,27 +16,49 @@ static mr_err_t mr_dac_open(mr_device_t device)
|
||||
{
|
||||
mr_dac_t dac = (mr_dac_t)device;
|
||||
|
||||
return dac->ops->configure(dac, MR_DAC_STATE_ENABLE);
|
||||
return dac->ops->configure(dac, MR_ENABLE);
|
||||
}
|
||||
|
||||
static mr_err_t mr_dac_close(mr_device_t device)
|
||||
{
|
||||
mr_dac_t dac = (mr_dac_t)device;
|
||||
|
||||
return dac->ops->configure(dac, MR_DAC_STATE_DISABLE);
|
||||
/* Disable all channel */
|
||||
dac->config._channel_mask = 0;
|
||||
|
||||
return dac->ops->configure(dac, MR_DISABLE);
|
||||
}
|
||||
|
||||
static mr_err_t mr_dac_ioctl(mr_device_t device, int cmd, void *args)
|
||||
{
|
||||
mr_dac_t dac = (mr_dac_t)device;
|
||||
struct mr_dac_config *config = MR_NULL;
|
||||
mr_err_t ret = MR_ERR_OK;
|
||||
|
||||
switch (cmd & _MR_CTRL_FLAG_MASK)
|
||||
{
|
||||
case MR_CTRL_CONFIG:
|
||||
case MR_CTRL_SET_CONFIG:
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
return dac->ops->channel_configure(dac, (struct mr_dac_config *)args);
|
||||
config = (struct mr_dac_config *)args;
|
||||
ret = dac->ops->channel_configure(dac, config);
|
||||
if (ret == MR_ERR_OK)
|
||||
{
|
||||
dac->config = *config;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
|
||||
case MR_CTRL_GET_CONFIG:
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
config = (struct mr_dac_config *)args;
|
||||
*config = dac->config;
|
||||
return MR_ERR_OK;
|
||||
}
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
@@ -57,6 +79,12 @@ static mr_ssize_t mr_dac_write(mr_device_t device, mr_pos_t pos, const void *buf
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
|
||||
/* Check whether the channel is enabled */
|
||||
if (!((1 << pos) & dac->config._channel_mask))
|
||||
{
|
||||
return -MR_ERR_INVALID;
|
||||
}
|
||||
|
||||
for (send_size = 0; send_size < size; send_size += sizeof(*send_buffer))
|
||||
{
|
||||
dac->ops->write(dac, pos, *send_buffer);
|
||||
@@ -103,6 +131,8 @@ mr_err_t mr_dac_device_add(mr_dac_t dac, const char *name, void *data, struct mr
|
||||
dac->device.data = data;
|
||||
dac->device.ops = &device_ops;
|
||||
|
||||
dac->config._channel_mask = 0;
|
||||
|
||||
/* Set operations as protection-ops if ops is null */
|
||||
ops->configure = ops->configure ? ops->configure : _err_io_dac_configure;
|
||||
ops->channel_configure = ops->channel_configure ? ops->channel_configure : _err_io_dac_channel_configure;
|
||||
|
||||
@@ -15,13 +15,50 @@
|
||||
|
||||
#if (MR_CONF_DAC == MR_CONF_ENABLE)
|
||||
|
||||
#define MR_DAC_STATE_DISABLE 0
|
||||
#define MR_DAC_STATE_ENABLE 1
|
||||
#define MR_DAC_CHANNEL_DISABLE MR_DISABLE
|
||||
#define MR_DAC_CHANNEL_ENABLE MR_ENABLE
|
||||
|
||||
struct mr_dac_config
|
||||
{
|
||||
mr_pos_t channel;
|
||||
mr_state_t state;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
mr_pos_t channel0: 1;
|
||||
mr_pos_t channel1: 1;
|
||||
mr_pos_t channel2: 1;
|
||||
mr_pos_t channel3: 1;
|
||||
mr_pos_t channel4: 1;
|
||||
mr_pos_t channel5: 1;
|
||||
mr_pos_t channel6: 1;
|
||||
mr_pos_t channel7: 1;
|
||||
mr_pos_t channel8: 1;
|
||||
mr_pos_t channel9: 1;
|
||||
mr_pos_t channel10: 1;
|
||||
mr_pos_t channel11: 1;
|
||||
mr_pos_t channel12: 1;
|
||||
mr_pos_t channel13: 1;
|
||||
mr_pos_t channel14: 1;
|
||||
mr_pos_t channel15: 1;
|
||||
mr_pos_t channel16: 1;
|
||||
mr_pos_t channel17: 1;
|
||||
mr_pos_t channel18: 1;
|
||||
mr_pos_t channel19: 1;
|
||||
mr_pos_t channel20: 1;
|
||||
mr_pos_t channel21: 1;
|
||||
mr_pos_t channel22: 1;
|
||||
mr_pos_t channel23: 1;
|
||||
mr_pos_t channel24: 1;
|
||||
mr_pos_t channel25: 1;
|
||||
mr_pos_t channel26: 1;
|
||||
mr_pos_t channel27: 1;
|
||||
mr_pos_t channel28: 1;
|
||||
mr_pos_t channel29: 1;
|
||||
mr_pos_t channel30: 1;
|
||||
mr_pos_t channel31: 1;
|
||||
};
|
||||
mr_pos_t _channel_mask;
|
||||
};
|
||||
};
|
||||
|
||||
typedef struct mr_dac *mr_dac_t;
|
||||
@@ -37,7 +74,8 @@ struct mr_dac
|
||||
{
|
||||
struct mr_device device;
|
||||
|
||||
mr_size_t delay;
|
||||
struct mr_dac_config config;
|
||||
|
||||
const struct mr_dac_ops *ops;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user