re-format the coding style in spi_dev.c
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2272 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
cd053e7737
commit
c1a64657f6
|
@ -1,145 +1,174 @@
|
||||||
|
/*
|
||||||
|
* File : spi_dev.c
|
||||||
|
* This file is part of RT-Thread RTOS
|
||||||
|
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* The license and distribution terms for this file may be
|
||||||
|
* found in the file LICENSE in this distribution or at
|
||||||
|
* http://www.rt-thread.org/license/LICENSE
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
*/
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <drivers/spi.h>
|
#include <drivers/spi.h>
|
||||||
|
|
||||||
/* SPI bus device interface, compatible with RT-Thread 0.3.x/1.0.x */
|
/* SPI bus device interface, compatible with RT-Thread 0.3.x/1.0.x */
|
||||||
static rt_err_t _spi_bus_device_init(rt_device_t dev)
|
static rt_err_t _spi_bus_device_init(rt_device_t dev)
|
||||||
{
|
{
|
||||||
struct rt_spi_bus* bus;
|
struct rt_spi_bus *bus;
|
||||||
|
|
||||||
bus = (struct rt_spi_bus*) dev;
|
bus = (struct rt_spi_bus *)dev;
|
||||||
RT_ASSERT(bus != RT_NULL);
|
RT_ASSERT(bus != RT_NULL);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_size_t _spi_bus_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
static rt_size_t _spi_bus_device_read(rt_device_t dev,
|
||||||
|
rt_off_t pos,
|
||||||
|
void *buffer,
|
||||||
|
rt_size_t size)
|
||||||
{
|
{
|
||||||
struct rt_spi_bus* bus;
|
struct rt_spi_bus *bus;
|
||||||
|
|
||||||
bus = (struct rt_spi_bus*) dev;
|
bus = (struct rt_spi_bus *)dev;
|
||||||
RT_ASSERT(bus != RT_NULL);
|
RT_ASSERT(bus != RT_NULL);
|
||||||
RT_ASSERT(bus->owner != RT_NULL);
|
RT_ASSERT(bus->owner != RT_NULL);
|
||||||
|
|
||||||
return rt_spi_transfer(bus->owner, RT_NULL, buffer, size);
|
return rt_spi_transfer(bus->owner, RT_NULL, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_size_t _spi_bus_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
static rt_size_t _spi_bus_device_write(rt_device_t dev,
|
||||||
|
rt_off_t pos,
|
||||||
|
const void *buffer,
|
||||||
|
rt_size_t size)
|
||||||
{
|
{
|
||||||
struct rt_spi_bus* bus;
|
struct rt_spi_bus *bus;
|
||||||
|
|
||||||
bus = (struct rt_spi_bus*) dev;
|
bus = (struct rt_spi_bus *)dev;
|
||||||
RT_ASSERT(bus != RT_NULL);
|
RT_ASSERT(bus != RT_NULL);
|
||||||
RT_ASSERT(bus->owner != RT_NULL);
|
RT_ASSERT(bus->owner != RT_NULL);
|
||||||
|
|
||||||
return rt_spi_transfer(bus->owner, buffer, RT_NULL, size);
|
return rt_spi_transfer(bus->owner, buffer, RT_NULL, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t _spi_bus_device_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
static rt_err_t _spi_bus_device_control(rt_device_t dev,
|
||||||
|
rt_uint8_t cmd,
|
||||||
|
void *args)
|
||||||
{
|
{
|
||||||
struct rt_spi_bus* bus;
|
struct rt_spi_bus *bus;
|
||||||
|
|
||||||
bus = (struct rt_spi_bus*) dev;
|
bus = (struct rt_spi_bus *)dev;
|
||||||
RT_ASSERT(bus != RT_NULL);
|
RT_ASSERT(bus != RT_NULL);
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case 0: /* set device */
|
case 0: /* set device */
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_err_t rt_spi_bus_device_init(struct rt_spi_bus* bus, const char* name)
|
rt_err_t rt_spi_bus_device_init(struct rt_spi_bus *bus, const char *name)
|
||||||
{
|
{
|
||||||
struct rt_device *device;
|
struct rt_device *device;
|
||||||
RT_ASSERT(bus != RT_NULL);
|
RT_ASSERT(bus != RT_NULL);
|
||||||
|
|
||||||
device = &bus->parent;
|
device = &bus->parent;
|
||||||
|
|
||||||
/* set device type */
|
/* set device type */
|
||||||
device->type = RT_Device_Class_SPIBUS;
|
device->type = RT_Device_Class_SPIBUS;
|
||||||
/* initialize device interface */
|
/* initialize device interface */
|
||||||
device->init = _spi_bus_device_init;
|
device->init = _spi_bus_device_init;
|
||||||
device->open = RT_NULL;
|
device->open = RT_NULL;
|
||||||
device->close = RT_NULL;
|
device->close = RT_NULL;
|
||||||
device->read = _spi_bus_device_read;
|
device->read = _spi_bus_device_read;
|
||||||
device->write = _spi_bus_device_write;
|
device->write = _spi_bus_device_write;
|
||||||
device->control = _spi_bus_device_control;
|
device->control = _spi_bus_device_control;
|
||||||
|
|
||||||
/* register to device manager */
|
/* register to device manager */
|
||||||
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR);
|
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SPI Dev device interface, compatible with RT-Thread 0.3.x/1.0.x */
|
/* SPI Dev device interface, compatible with RT-Thread 0.3.x/1.0.x */
|
||||||
static rt_err_t _spidev_device_init(rt_device_t dev)
|
static rt_err_t _spidev_device_init(rt_device_t dev)
|
||||||
{
|
{
|
||||||
struct rt_spi_device* device;
|
struct rt_spi_device *device;
|
||||||
|
|
||||||
device = (struct rt_spi_device*) dev;
|
device = (struct rt_spi_device *)dev;
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_size_t _spidev_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
static rt_size_t _spidev_device_read(rt_device_t dev,
|
||||||
|
rt_off_t pos,
|
||||||
|
void *buffer,
|
||||||
|
rt_size_t size)
|
||||||
{
|
{
|
||||||
struct rt_spi_device* device;
|
struct rt_spi_device *device;
|
||||||
|
|
||||||
device = (struct rt_spi_device*) dev;
|
device = (struct rt_spi_device *)dev;
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
RT_ASSERT(device->bus != RT_NULL);
|
RT_ASSERT(device->bus != RT_NULL);
|
||||||
|
|
||||||
return rt_spi_transfer(device, RT_NULL, buffer, size);
|
return rt_spi_transfer(device, RT_NULL, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_size_t _spidev_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
static rt_size_t _spidev_device_write(rt_device_t dev,
|
||||||
|
rt_off_t pos,
|
||||||
|
const void *buffer,
|
||||||
|
rt_size_t size)
|
||||||
{
|
{
|
||||||
struct rt_spi_device* device;
|
struct rt_spi_device *device;
|
||||||
|
|
||||||
device = (struct rt_spi_device*) dev;
|
device = (struct rt_spi_device *)dev;
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
RT_ASSERT(device->bus != RT_NULL);
|
RT_ASSERT(device->bus != RT_NULL);
|
||||||
|
|
||||||
return rt_spi_transfer(device, buffer, RT_NULL, size);
|
return rt_spi_transfer(device, buffer, RT_NULL, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_err_t _spidev_device_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
static rt_err_t _spidev_device_control(rt_device_t dev,
|
||||||
|
rt_uint8_t cmd,
|
||||||
|
void *args)
|
||||||
{
|
{
|
||||||
struct rt_spi_device* device;
|
struct rt_spi_device *device;
|
||||||
|
|
||||||
device = (struct rt_spi_device*) dev;
|
device = (struct rt_spi_device *)dev;
|
||||||
RT_ASSERT(device != RT_NULL);
|
RT_ASSERT(device != RT_NULL);
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case 0: /* set device */
|
case 0: /* set device */
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_err_t rt_spidev_device_init(struct rt_spi_device* dev, const char* name)
|
rt_err_t rt_spidev_device_init(struct rt_spi_device *dev, const char *name)
|
||||||
{
|
{
|
||||||
struct rt_device* device;
|
struct rt_device *device;
|
||||||
RT_ASSERT(dev != RT_NULL);
|
RT_ASSERT(dev != RT_NULL);
|
||||||
|
|
||||||
device = &(dev->parent);
|
device = &(dev->parent);
|
||||||
|
|
||||||
/* set device type */
|
/* set device type */
|
||||||
device->type = RT_Device_Class_SPIDevice;
|
device->type = RT_Device_Class_SPIDevice;
|
||||||
device->init = _spidev_device_init;
|
device->init = _spidev_device_init;
|
||||||
device->open = RT_NULL;
|
device->open = RT_NULL;
|
||||||
device->close = RT_NULL;
|
device->close = RT_NULL;
|
||||||
device->read = _spidev_device_read;
|
device->read = _spidev_device_read;
|
||||||
device->write = _spidev_device_write;
|
device->write = _spidev_device_write;
|
||||||
device->control = _spidev_device_control;
|
device->control = _spidev_device_control;
|
||||||
|
|
||||||
/* register to device manager */
|
/* register to device manager */
|
||||||
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR);
|
return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue