提交 1bb425e8 编写于 作者: B Bernard Xiong

[DeviceDrivers] code cleanup for hardware pin

上级 765ac35e
......@@ -59,18 +59,18 @@ struct rt_device_pin_status
struct rt_pin_ops
{
void (*pin_mode) (struct rt_device* device, rt_base_t pin, rt_base_t mode);
void (*pin_write)(struct rt_device* device, rt_base_t pin, rt_base_t value);
int (*pin_read) (struct rt_device* device, rt_base_t pin);
void (*pin_mode)(struct rt_device *device, rt_base_t pin, rt_base_t mode);
void (*pin_write)(struct rt_device *device, rt_base_t pin, rt_base_t value);
int (*pin_read)(struct rt_device *device, rt_base_t pin);
/* TODO: add GPIO interrupt */
};
int rt_device_pin_register(const char* name, const struct rt_pin_ops* ops, void* user_data);
int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data);
void rt_pin_mode(rt_base_t pin, rt_base_t mode);
void rt_pin_write(rt_base_t pin, rt_base_t value);
int rt_pin_read (rt_base_t pin);
int rt_pin_read(rt_base_t pin);
#ifdef __cplusplus
}
......
......@@ -29,30 +29,30 @@
#endif
static struct rt_device_pin _hw_pin;
static rt_size_t _pin_read (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
static rt_size_t _pin_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
{
struct rt_device_pin_status* status;
struct rt_device_pin* pin = (struct rt_device_pin*)dev;
struct rt_device_pin_status *status;
struct rt_device_pin *pin = (struct rt_device_pin *)dev;
/* check parameters */
RT_ASSERT(pin != RT_NULL);
status = (struct rt_device_pin_status*) buffer;
status = (struct rt_device_pin_status *) buffer;
if (status == RT_NULL || size != sizeof(*status)) return 0;
status->status = pin->ops->pin_read(dev, status->pin);
return size;
}
static rt_size_t _pin_write (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
static rt_size_t _pin_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
struct rt_device_pin_status* status;
struct rt_device_pin* pin = (struct rt_device_pin*)dev;
struct rt_device_pin_status *status;
struct rt_device_pin *pin = (struct rt_device_pin *)dev;
/* check parameters */
RT_ASSERT(pin != RT_NULL);
status = (struct rt_device_pin_status*) buffer;
status = (struct rt_device_pin_status *) buffer;
if (status == RT_NULL || size != sizeof(*status)) return 0;
pin->ops->pin_write(dev, (rt_base_t)status->pin, (rt_base_t)status->status);
......@@ -62,13 +62,13 @@ static rt_size_t _pin_write (rt_device_t dev, rt_off_t pos, const void *buffer,
static rt_err_t _pin_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
struct rt_device_pin_mode* mode;
struct rt_device_pin* pin = (struct rt_device_pin*)dev;
struct rt_device_pin_mode *mode;
struct rt_device_pin *pin = (struct rt_device_pin *)dev;
/* check parameters */
RT_ASSERT(pin != RT_NULL);
mode = (struct rt_device_pin_mode*) args;
mode = (struct rt_device_pin_mode *) args;
if (mode == RT_NULL) return -RT_ERROR;
pin->ops->pin_mode(dev, (rt_base_t)mode->pin, (rt_base_t)mode->mode);
......@@ -76,7 +76,7 @@ static rt_err_t _pin_control(rt_device_t dev, rt_uint8_t cmd, void *args)
return 0;
}
int rt_device_pin_register(const char* name, const struct rt_pin_ops* ops, void* user_data)
int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data)
{
_hw_pin.parent.type = RT_Device_Class_Miscellaneous;
_hw_pin.parent.rx_indicate = RT_NULL;
......@@ -111,7 +111,7 @@ void rt_pin_write(rt_base_t pin, rt_base_t value)
}
FINSH_FUNCTION_EXPORT_ALIAS(rt_pin_write, pinWrite, write value to hardware pin);
int rt_pin_read (rt_base_t pin)
int rt_pin_read(rt_base_t pin)
{
return _hw_pin.ops->pin_read(&_hw_pin.parent, pin);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册