fixed a eclipse compiling warning.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2163 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
72bce28791
commit
9e3c72a635
@ -212,12 +212,12 @@ static rt_size_t i2c_send_bytes(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
|
||||
}
|
||||
else if (ret == 0)
|
||||
{
|
||||
rt_kprintf("send bytes: NACK.\n");
|
||||
return -RT_ERROR;
|
||||
i2c_dbg("send bytes: NACK.\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("send bytes: error %d\n", ret);
|
||||
i2c_dbg("send bytes: error %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -233,7 +233,7 @@ static rt_err_t i2c_send_ack_or_nack(struct rt_i2c_bus_device *bus, int ack)
|
||||
i2c_delay(ops);
|
||||
if (SCL_H(ops) < 0)
|
||||
{
|
||||
rt_kprintf("ACK or NACK timeout\n");
|
||||
bit_dbg("ACK or NACK timeout\n");
|
||||
return -RT_ETIMEOUT;
|
||||
}
|
||||
SCL_L(ops);
|
||||
@ -322,14 +322,14 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus, struct rt_i2
|
||||
ret = i2c_send_address(bus, addr1, retries);
|
||||
if ((ret != 1) && !ignore_nack)
|
||||
{
|
||||
rt_kprintf("NACK: sending first addr\n");
|
||||
bit_dbg("NACK: sending first addr\n");
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
ret = i2c_writeb(bus, addr2);
|
||||
if ((ret != 1) && !ignore_nack)
|
||||
{
|
||||
rt_kprintf("NACK: sending second addr\n");
|
||||
bit_dbg("NACK: sending second addr\n");
|
||||
return -RT_EIO;
|
||||
}
|
||||
if (flags & RT_I2C_RD)
|
||||
@ -340,13 +340,14 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus, struct rt_i2
|
||||
ret = i2c_send_address(bus, addr1, retries);
|
||||
if ((ret != 1) && !ignore_nack)
|
||||
{
|
||||
rt_kprintf("NACK: sending repeated addr\n");
|
||||
bit_dbg("NACK: sending repeated addr\n");
|
||||
return -RT_EIO;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* 7-bit addr */
|
||||
{
|
||||
/* 7-bit addr */
|
||||
addr1 = msg->addr << 1;
|
||||
if (flags & RT_I2C_RD)
|
||||
addr1 |= 1;
|
||||
@ -424,7 +425,8 @@ out:
|
||||
}
|
||||
|
||||
|
||||
static const struct rt_i2c_bus_device_ops i2c_bit_bus_ops = {
|
||||
static const struct rt_i2c_bus_device_ops i2c_bit_bus_ops =
|
||||
{
|
||||
i2c_bit_xfer,
|
||||
RT_NULL,
|
||||
RT_NULL
|
||||
@ -433,8 +435,6 @@ static const struct rt_i2c_bus_device_ops i2c_bit_bus_ops = {
|
||||
|
||||
rt_err_t rt_i2c_bit_add_bus(struct rt_i2c_bus_device *bus, const char *bus_name)
|
||||
{
|
||||
rt_err_t err;
|
||||
|
||||
struct rt_i2c_bit_ops *bit_ops = bus->priv;
|
||||
RT_ASSERT(bit_ops != RT_NULL);
|
||||
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
static struct rt_mutex i2c_core_lock;
|
||||
|
||||
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus, const char *bus_name)
|
||||
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
|
||||
const char *bus_name)
|
||||
{
|
||||
rt_err_t res = RT_EOK;
|
||||
|
||||
@ -52,7 +53,9 @@ struct rt_i2c_bus_device* rt_i2c_bus_device_find(const char *bus_name)
|
||||
}
|
||||
|
||||
|
||||
rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
|
||||
rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
|
||||
struct rt_i2c_msg msgs[],
|
||||
rt_uint32_t num)
|
||||
{
|
||||
rt_size_t ret;
|
||||
|
||||
@ -75,14 +78,16 @@ rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("I2C bus operation not supported\n");
|
||||
return -RT_ERROR;
|
||||
i2c_dbg("I2C bus operation not supported\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus, rt_uint16_t addr,
|
||||
rt_uint16_t flags, const rt_uint8_t *buf,
|
||||
rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
|
||||
rt_uint16_t addr,
|
||||
rt_uint16_t flags,
|
||||
const rt_uint8_t *buf,
|
||||
rt_uint32_t count)
|
||||
{
|
||||
rt_size_t ret;
|
||||
@ -100,8 +105,10 @@ rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus, rt_uint16_t addr,
|
||||
|
||||
|
||||
|
||||
rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus, rt_uint16_t addr,
|
||||
rt_uint16_t flags, rt_uint8_t *buf,
|
||||
rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
|
||||
rt_uint16_t addr,
|
||||
rt_uint16_t flags,
|
||||
rt_uint8_t *buf,
|
||||
rt_uint32_t count)
|
||||
{
|
||||
rt_size_t ret;
|
||||
@ -123,7 +130,6 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus, rt_uint16_t addr,
|
||||
rt_err_t rt_i2c_core_init(void)
|
||||
{
|
||||
|
||||
rt_mutex_init (&i2c_core_lock, "i2c_core_lock", RT_IPC_FLAG_FIFO);
|
||||
|
||||
return rt_mutex_init (&i2c_core_lock, "i2c_core_lock", RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <rtdevice.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
static rt_err_t i2c_bus_device_init(rt_device_t dev)
|
||||
{
|
||||
@ -8,7 +8,10 @@ static rt_err_t i2c_bus_device_init(rt_device_t dev)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_size_t i2c_bus_device_read (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t count)
|
||||
static rt_size_t i2c_bus_device_read (rt_device_t dev,
|
||||
rt_off_t pos,
|
||||
void *buffer,
|
||||
rt_size_t count)
|
||||
{
|
||||
rt_uint16_t addr;
|
||||
rt_uint16_t flags;
|
||||
@ -26,7 +29,10 @@ static rt_size_t i2c_bus_device_read (rt_device_t dev, rt_off_t pos, void *buffe
|
||||
}
|
||||
|
||||
|
||||
static rt_size_t i2c_bus_device_write (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t count)
|
||||
static rt_size_t i2c_bus_device_write (rt_device_t dev,
|
||||
rt_off_t pos,
|
||||
const void *buffer,
|
||||
rt_size_t count)
|
||||
{
|
||||
rt_uint16_t addr;
|
||||
rt_uint16_t flags;
|
||||
@ -43,7 +49,9 @@ static rt_size_t i2c_bus_device_write (rt_device_t dev, rt_off_t pos, const void
|
||||
return rt_i2c_master_send(bus, addr, flags, buffer, count);
|
||||
}
|
||||
|
||||
static rt_err_t i2c_bus_device_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
static rt_err_t i2c_bus_device_control(rt_device_t dev,
|
||||
rt_uint8_t cmd,
|
||||
void *args)
|
||||
{
|
||||
rt_err_t ret;
|
||||
struct rt_i2c_priv_data *priv_data;
|
||||
@ -70,14 +78,16 @@ static rt_err_t i2c_bus_device_control(rt_device_t dev, rt_uint8_t cmd, void *ar
|
||||
return -RT_EIO;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
||||
rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device* bus, const char* name)
|
||||
rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device* bus,
|
||||
const char* name)
|
||||
{
|
||||
struct rt_device *device;
|
||||
RT_ASSERT(bus != RT_NULL);
|
||||
@ -101,5 +111,3 @@ rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device* bus, const char
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,7 +19,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct rt_i2c_bit_ops {
|
||||
struct rt_i2c_bit_ops
|
||||
{
|
||||
void *data; /* private data for lowlevel routines */
|
||||
void (*set_sda) (void *data, rt_int32_t state);
|
||||
void (*set_scl) (void *data, rt_int32_t state);
|
||||
@ -32,7 +33,8 @@ struct rt_i2c_bit_ops {
|
||||
rt_uint32_t timeout; /* in tick */
|
||||
};
|
||||
|
||||
rt_err_t rt_i2c_bit_add_bus(struct rt_i2c_bus_device *bus, const char *bus_name);
|
||||
rt_err_t rt_i2c_bit_add_bus(struct rt_i2c_bus_device *bus,
|
||||
const char *bus_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ extern "C" {
|
||||
#define RT_I2C_IGNORE_NACK (1u << 5)
|
||||
#define RT_I2C_NO_READ_ACK (1u << 6) /* when I2C reading, we do not ACK */
|
||||
|
||||
struct rt_i2c_msg {
|
||||
struct rt_i2c_msg
|
||||
{
|
||||
rt_uint16_t addr;
|
||||
rt_uint16_t flags;
|
||||
rt_uint16_t len;
|
||||
@ -37,14 +38,22 @@ struct rt_i2c_msg {
|
||||
|
||||
struct rt_i2c_bus_device;
|
||||
|
||||
struct rt_i2c_bus_device_ops {
|
||||
rt_size_t (*master_xfer) (struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num);
|
||||
rt_size_t (*slave_xfer) (struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num);
|
||||
rt_err_t (*i2c_bus_control) (struct rt_i2c_bus_device *bus, rt_uint32_t, rt_uint32_t);
|
||||
struct rt_i2c_bus_device_ops
|
||||
{
|
||||
rt_size_t (*master_xfer) (struct rt_i2c_bus_device *bus,
|
||||
struct rt_i2c_msg msgs[],
|
||||
rt_uint32_t num);
|
||||
rt_size_t (*slave_xfer) (struct rt_i2c_bus_device *bus,
|
||||
struct rt_i2c_msg msgs[],
|
||||
rt_uint32_t num);
|
||||
rt_err_t (*i2c_bus_control) (struct rt_i2c_bus_device *bus,
|
||||
rt_uint32_t,
|
||||
rt_uint32_t);
|
||||
};
|
||||
|
||||
/*for i2c bus driver*/
|
||||
struct rt_i2c_bus_device {
|
||||
struct rt_i2c_bus_device
|
||||
{
|
||||
struct rt_device parent;
|
||||
const struct rt_i2c_bus_device_ops *ops;
|
||||
rt_uint16_t flags;
|
||||
@ -61,14 +70,21 @@ struct rt_i2c_bus_device {
|
||||
#define i2c_dbg(fmt, ...)
|
||||
#endif
|
||||
|
||||
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus, const char *bus_name);
|
||||
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
|
||||
const char *bus_name);
|
||||
struct rt_i2c_bus_device* rt_i2c_bus_device_find(const char *bus_name);
|
||||
rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num);
|
||||
rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus, rt_uint16_t addr,
|
||||
rt_uint16_t flags, const rt_uint8_t *buf,
|
||||
rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
|
||||
struct rt_i2c_msg msgs[],
|
||||
rt_uint32_t num);
|
||||
rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
|
||||
rt_uint16_t addr,
|
||||
rt_uint16_t flags,
|
||||
const rt_uint8_t *buf,
|
||||
rt_uint32_t count);
|
||||
rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus, rt_uint16_t addr,
|
||||
rt_uint16_t flags, rt_uint8_t *buf,
|
||||
rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
|
||||
rt_uint16_t addr,
|
||||
rt_uint16_t flags,
|
||||
rt_uint8_t *buf,
|
||||
rt_uint32_t count);
|
||||
rt_err_t rt_i2c_core_init(void);
|
||||
|
||||
|
@ -12,12 +12,14 @@ extern "C" {
|
||||
#define RT_I2C_DEV_CTRL_TIMEOUT 0x22
|
||||
#define RT_I2C_DEV_CTRL_RW 0x23
|
||||
|
||||
struct rt_i2c_priv_data {
|
||||
struct rt_i2c_priv_data
|
||||
{
|
||||
struct rt_i2c_msg *msgs;
|
||||
rt_size_t number;
|
||||
};
|
||||
|
||||
rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device* bus, const char* name);
|
||||
rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device* bus,
|
||||
const char* name);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -26,7 +26,8 @@ struct rt_ringbuffer
|
||||
* Completion
|
||||
*/
|
||||
void rt_completion_init(struct rt_completion* completion);
|
||||
rt_err_t rt_completion_wait(struct rt_completion* completion, rt_int32_t timeout);
|
||||
rt_err_t rt_completion_wait(struct rt_completion* completion,
|
||||
rt_int32_t timeout);
|
||||
void rt_completion_done(struct rt_completion* completion);
|
||||
|
||||
/**
|
||||
@ -36,44 +37,52 @@ void rt_completion_done(struct rt_completion* completion);
|
||||
/**
|
||||
* RingBuffer for DeviceDriver
|
||||
*/
|
||||
void rt_ringbuffer_init(struct rt_ringbuffer* rb, rt_uint8_t *pool, rt_uint16_t size);
|
||||
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer* rb, const rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer* rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer* rb, rt_uint8_t *ptr, rt_uint16_t length);
|
||||
void rt_ringbuffer_init(struct rt_ringbuffer* rb,
|
||||
rt_uint8_t *pool,
|
||||
rt_uint16_t size);
|
||||
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer* rb,
|
||||
const rt_uint8_t *ptr,
|
||||
rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer* rb,
|
||||
const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer* rb,
|
||||
rt_uint8_t *ptr,
|
||||
rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_available_size(struct rt_ringbuffer* rb);
|
||||
rt_size_t rt_ringbuffer_emptry_size(struct rt_ringbuffer* rb);
|
||||
|
||||
#ifdef RT_USING_SPI
|
||||
#include "drivers/spi.h"
|
||||
#endif
|
||||
#endif /* RT_USING_SPI */
|
||||
|
||||
#ifdef RT_USING_MTD_NOR
|
||||
#include "drivers/mtd_nor.h"
|
||||
#endif
|
||||
#endif /* RT_USING_MTD_NOR */
|
||||
|
||||
#ifdef RT_USING_MTD_NAND
|
||||
#include "drivers/mtd_nand.h"
|
||||
#endif
|
||||
#endif /* RT_USING_MTD_NAND */
|
||||
|
||||
#ifdef RT_USING_USB_DEVICE
|
||||
#include "drivers/usb_device.h"
|
||||
#endif
|
||||
#endif /* RT_USING_USB_DEVICE */
|
||||
|
||||
#ifdef RT_USING_USB_HOST
|
||||
#include "drivers/usb_host.h"
|
||||
#endif
|
||||
#endif /* RT_USING_USB_HOST */
|
||||
|
||||
#ifdef RT_USING_SERIAL
|
||||
#include "drivers/serial.h"
|
||||
#endif
|
||||
#endif /* RT_USING_SERIAL */
|
||||
|
||||
#ifdef RT_USING_I2C
|
||||
#include "drivers/i2c.h"
|
||||
#include "drivers/i2c_dev.h"
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_I2C_BITOPS
|
||||
#include "drivers/i2c-bit-ops.h"
|
||||
#endif
|
||||
#endif /* RT_USING_I2C_BITOPS */
|
||||
|
||||
#endif
|
||||
#endif /* RT_USING_I2C */
|
||||
|
||||
#endif /* __RT_DEVICE_H__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user