re-format the coding style in spi.h
1, Tabs to Spaces 2, File Format(CR/LF) using UNIX style 3, maximum line length = 80 git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2275 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
20de2ffa18
commit
fd425e792d
|
@ -1,9 +1,21 @@
|
||||||
|
/*
|
||||||
|
* File : spi.h
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef __SPI_H__
|
#ifndef __SPI_H__
|
||||||
#define __SPI_H__
|
#define __SPI_H__
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
|
||||||
#define RT_SPI_CPHA (1<<0) /* bit[0]:CPHA, clock phase */
|
#define RT_SPI_CPHA (1<<0) /* bit[0]:CPHA, clock phase */
|
||||||
#define RT_SPI_CPOL (1<<1) /* bit[1]:CPOL, clock polarity */
|
#define RT_SPI_CPOL (1<<1) /* bit[1]:CPOL, clock polarity */
|
||||||
/**
|
/**
|
||||||
|
@ -36,13 +48,13 @@
|
||||||
*/
|
*/
|
||||||
struct rt_spi_message
|
struct rt_spi_message
|
||||||
{
|
{
|
||||||
const void* send_buf;
|
const void *send_buf;
|
||||||
void* recv_buf;
|
void *recv_buf;
|
||||||
rt_size_t length;
|
rt_size_t length;
|
||||||
struct rt_spi_message* next;
|
struct rt_spi_message *next;
|
||||||
|
|
||||||
unsigned cs_take:1;
|
unsigned cs_take : 1;
|
||||||
unsigned cs_release:1;
|
unsigned cs_release : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +76,7 @@ struct rt_spi_bus
|
||||||
const struct rt_spi_ops *ops;
|
const struct rt_spi_ops *ops;
|
||||||
|
|
||||||
struct rt_mutex lock;
|
struct rt_mutex lock;
|
||||||
struct rt_spi_device* owner;
|
struct rt_spi_device *owner;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,8 +84,8 @@ struct rt_spi_bus
|
||||||
*/
|
*/
|
||||||
struct rt_spi_ops
|
struct rt_spi_ops
|
||||||
{
|
{
|
||||||
rt_err_t (*configure)(struct rt_spi_device* device, struct rt_spi_configuration* configuration);
|
rt_err_t (*configure)(struct rt_spi_device *device, struct rt_spi_configuration *configuration);
|
||||||
rt_uint32_t (*xfer)(struct rt_spi_device* device, struct rt_spi_message* message);
|
rt_uint32_t (*xfer)(struct rt_spi_device *device, struct rt_spi_message *message);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,14 +98,19 @@ struct rt_spi_device
|
||||||
|
|
||||||
struct rt_spi_configuration config;
|
struct rt_spi_configuration config;
|
||||||
};
|
};
|
||||||
#define SPI_DEVICE(dev) ((struct rt_spi_device*)(dev))
|
#define SPI_DEVICE(dev) ((struct rt_spi_device *)(dev))
|
||||||
|
|
||||||
/* register a SPI bus */
|
/* register a SPI bus */
|
||||||
rt_err_t rt_spi_bus_register(struct rt_spi_bus* bus, const char* name,
|
rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
|
||||||
const struct rt_spi_ops* ops);
|
const char *name,
|
||||||
|
const struct rt_spi_ops *ops);
|
||||||
|
|
||||||
/* attach a device on SPI bus */
|
/* attach a device on SPI bus */
|
||||||
rt_err_t rt_spi_bus_attach_device(struct rt_spi_device* device, const char* name,
|
rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device,
|
||||||
const char* bus_name, void* user_data);
|
const char *name,
|
||||||
|
const char *bus_name,
|
||||||
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function takes SPI bus.
|
* This function takes SPI bus.
|
||||||
*
|
*
|
||||||
|
@ -101,7 +118,8 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device* device, const char* name
|
||||||
*
|
*
|
||||||
* @return RT_EOK on taken SPI bus successfully. others on taken SPI bus failed.
|
* @return RT_EOK on taken SPI bus successfully. others on taken SPI bus failed.
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_spi_take_bus(struct rt_spi_device* device);
|
rt_err_t rt_spi_take_bus(struct rt_spi_device *device);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function releases SPI bus.
|
* This function releases SPI bus.
|
||||||
*
|
*
|
||||||
|
@ -109,7 +127,7 @@ rt_err_t rt_spi_take_bus(struct rt_spi_device* device);
|
||||||
*
|
*
|
||||||
* @return RT_EOK on release SPI bus successfully.
|
* @return RT_EOK on release SPI bus successfully.
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_spi_release_bus(struct rt_spi_device* device);
|
rt_err_t rt_spi_release_bus(struct rt_spi_device *device);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function take SPI device (takes CS of SPI device).
|
* This function take SPI device (takes CS of SPI device).
|
||||||
|
@ -118,7 +136,7 @@ rt_err_t rt_spi_release_bus(struct rt_spi_device* device);
|
||||||
*
|
*
|
||||||
* @return RT_EOK on release SPI bus successfully. others on taken SPI bus failed.
|
* @return RT_EOK on release SPI bus successfully. others on taken SPI bus failed.
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_spi_take(struct rt_spi_device* device);
|
rt_err_t rt_spi_take(struct rt_spi_device *device);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function releases SPI device (releases CS of SPI device).
|
* This function releases SPI device (releases CS of SPI device).
|
||||||
|
@ -127,17 +145,24 @@ rt_err_t rt_spi_take(struct rt_spi_device* device);
|
||||||
*
|
*
|
||||||
* @return RT_EOK on release SPI device successfully.
|
* @return RT_EOK on release SPI device successfully.
|
||||||
*/
|
*/
|
||||||
rt_err_t rt_spi_release(struct rt_spi_device* device);
|
rt_err_t rt_spi_release(struct rt_spi_device *device);
|
||||||
|
|
||||||
/* set configuration on SPI device */
|
/* set configuration on SPI device */
|
||||||
rt_err_t rt_spi_configure(struct rt_spi_device* device, struct rt_spi_configuration* cfg);
|
rt_err_t rt_spi_configure(struct rt_spi_device *device,
|
||||||
|
struct rt_spi_configuration *cfg);
|
||||||
|
|
||||||
/* send data then receive data from SPI device */
|
/* send data then receive data from SPI device */
|
||||||
rt_err_t rt_spi_send_then_recv(struct rt_spi_device* device, const void *send_buf, rt_size_t send_length,
|
rt_err_t rt_spi_send_then_recv(struct rt_spi_device *device,
|
||||||
void* recv_buf, rt_size_t recv_length);
|
const void *send_buf,
|
||||||
|
rt_size_t send_length,
|
||||||
|
void *recv_buf,
|
||||||
|
rt_size_t recv_length);
|
||||||
|
|
||||||
rt_err_t rt_spi_send_then_send(struct rt_spi_device* device, const void *send_buf1, rt_size_t send_length1,
|
rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
|
||||||
const void* send_buf2, rt_size_t send_length2);
|
const void *send_buf1,
|
||||||
|
rt_size_t send_length1,
|
||||||
|
const void *send_buf2,
|
||||||
|
rt_size_t send_length2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function transmits data to SPI device.
|
* This function transmits data to SPI device.
|
||||||
|
@ -149,8 +174,10 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device* device, const void *send_bu
|
||||||
*
|
*
|
||||||
* @return the actual length of transmitted.
|
* @return the actual length of transmitted.
|
||||||
*/
|
*/
|
||||||
rt_size_t rt_spi_transfer(struct rt_spi_device* device, const void *send_buf,
|
rt_size_t rt_spi_transfer(struct rt_spi_device *device,
|
||||||
void* recv_buf, rt_size_t length);
|
const void *send_buf,
|
||||||
|
void *recv_buf,
|
||||||
|
rt_size_t length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function transfers a message list to the SPI device.
|
* This function transfers a message list to the SPI device.
|
||||||
|
@ -161,32 +188,40 @@ rt_size_t rt_spi_transfer(struct rt_spi_device* device, const void *send_buf,
|
||||||
* @return RT_NULL if transmits message list successfully,
|
* @return RT_NULL if transmits message list successfully,
|
||||||
* SPI message which be transmitted failed.
|
* SPI message which be transmitted failed.
|
||||||
*/
|
*/
|
||||||
struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device* device,
|
struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,
|
||||||
struct rt_spi_message *message);
|
struct rt_spi_message *message);
|
||||||
|
|
||||||
rt_inline rt_size_t rt_spi_recv(struct rt_spi_device* device, void* recv_buf, rt_size_t length)
|
rt_inline rt_size_t rt_spi_recv(struct rt_spi_device *device,
|
||||||
|
void *recv_buf,
|
||||||
|
rt_size_t length)
|
||||||
{
|
{
|
||||||
return rt_spi_transfer(device, RT_NULL, recv_buf, length);
|
return rt_spi_transfer(device, RT_NULL, recv_buf, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_inline rt_size_t rt_spi_send(struct rt_spi_device* device, const void* send_buf, rt_size_t length)
|
rt_inline rt_size_t rt_spi_send(struct rt_spi_device *device,
|
||||||
|
const void *send_buf,
|
||||||
|
rt_size_t length)
|
||||||
{
|
{
|
||||||
return rt_spi_transfer(device, send_buf, RT_NULL, length);
|
return rt_spi_transfer(device, send_buf, RT_NULL, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_inline rt_uint8_t rt_spi_sendrecv8(struct rt_spi_device* device, rt_uint8_t data)
|
rt_inline rt_uint8_t rt_spi_sendrecv8(struct rt_spi_device *device,
|
||||||
|
rt_uint8_t data)
|
||||||
{
|
{
|
||||||
rt_uint8_t value;
|
rt_uint8_t value;
|
||||||
|
|
||||||
rt_spi_send_then_recv(device, &data, 1, &value, 1);
|
rt_spi_send_then_recv(device, &data, 1, &value, 1);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
rt_inline rt_uint16_t rt_spi_sendrecv16(struct rt_spi_device* device, rt_uint16_t data)
|
rt_inline rt_uint16_t rt_spi_sendrecv16(struct rt_spi_device *device,
|
||||||
|
rt_uint16_t data)
|
||||||
{
|
{
|
||||||
rt_uint16_t value;
|
rt_uint16_t value;
|
||||||
|
|
||||||
rt_spi_send_then_recv(device, &data, 2, &value, 2);
|
rt_spi_send_then_recv(device, &data, 2, &value, 2);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,10 +231,12 @@ rt_inline rt_uint16_t rt_spi_sendrecv16(struct rt_spi_device* device, rt_uint16_
|
||||||
* @param list the SPI message list header.
|
* @param list the SPI message list header.
|
||||||
* @param message the message pointer to be appended to the message list.
|
* @param message the message pointer to be appended to the message list.
|
||||||
*/
|
*/
|
||||||
rt_inline void rt_spi_message_append(struct rt_spi_message* list, struct rt_spi_message* message)
|
rt_inline void rt_spi_message_append(struct rt_spi_message *list,
|
||||||
|
struct rt_spi_message *message)
|
||||||
{
|
{
|
||||||
RT_ASSERT(list != RT_NULL);
|
RT_ASSERT(list != RT_NULL);
|
||||||
if (message == RT_NULL) return; /* not append */
|
if (message == RT_NULL)
|
||||||
|
return; /* not append */
|
||||||
|
|
||||||
while (list->next != RT_NULL)
|
while (list->next != RT_NULL)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue