Merge pull request #2492 from misonyo/rttdev
[components]add rt_device_ops for adc device and fix finsh_getchar() bug.
This commit is contained in:
commit
485f077fdc
|
@ -60,19 +60,37 @@ static rt_err_t _adc_control(rt_device_t dev, int cmd, void *args)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RT_USING_DEVICE_OPS
|
||||||
|
const static struct rt_device_ops adc_ops =
|
||||||
|
{
|
||||||
|
RT_NULL,
|
||||||
|
RT_NULL,
|
||||||
|
RT_NULL,
|
||||||
|
_adc_read,
|
||||||
|
RT_NULL,
|
||||||
|
_adc_control,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
rt_err_t rt_hw_adc_register(rt_adc_device_t device, const char *name, const struct rt_adc_ops *ops, const void *user_data)
|
rt_err_t rt_hw_adc_register(rt_adc_device_t device, const char *name, const struct rt_adc_ops *ops, const void *user_data)
|
||||||
{
|
{
|
||||||
rt_err_t result = RT_EOK;
|
rt_err_t result = RT_EOK;
|
||||||
RT_ASSERT(ops != RT_NULL && ops->convert != RT_NULL);
|
RT_ASSERT(ops != RT_NULL && ops->convert != RT_NULL);
|
||||||
|
|
||||||
device->parent.type = RT_Device_Class_Miscellaneous;
|
device->parent.type = RT_Device_Class_Miscellaneous;
|
||||||
|
device->parent.rx_indicate = RT_NULL;
|
||||||
|
device->parent.tx_complete = RT_NULL;
|
||||||
|
|
||||||
|
#ifdef RT_USING_DEVICE_OPS
|
||||||
|
device->parent.ops = &adc_ops;
|
||||||
|
#else
|
||||||
device->parent.init = RT_NULL;
|
device->parent.init = RT_NULL;
|
||||||
device->parent.open = RT_NULL;
|
device->parent.open = RT_NULL;
|
||||||
device->parent.close = RT_NULL;
|
device->parent.close = RT_NULL;
|
||||||
device->parent.read = _adc_read;
|
device->parent.read = _adc_read;
|
||||||
device->parent.write = RT_NULL;
|
device->parent.write = RT_NULL;
|
||||||
device->parent.control = _adc_control;
|
device->parent.control = _adc_control;
|
||||||
|
#endif
|
||||||
device->ops = ops;
|
device->ops = ops;
|
||||||
device->parent.user_data = (void *)user_data;
|
device->parent.user_data = (void *)user_data;
|
||||||
|
|
||||||
|
|
|
@ -139,13 +139,13 @@ static int finsh_getchar(void)
|
||||||
#ifdef RT_USING_POSIX
|
#ifdef RT_USING_POSIX
|
||||||
return getchar();
|
return getchar();
|
||||||
#else
|
#else
|
||||||
int ch = 0;
|
char ch = 0;
|
||||||
|
|
||||||
RT_ASSERT(shell != RT_NULL);
|
RT_ASSERT(shell != RT_NULL);
|
||||||
while (rt_device_read(shell->device, -1, &ch, 1) != 1)
|
while (rt_device_read(shell->device, -1, &ch, 1) != 1)
|
||||||
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
|
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
return ch;
|
return (int)ch;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue