drivers/spi: Add an SPI character driver that will permit access to the SPI bus for testing purposes. This driver is a simple wrapper around spi_transfer().

This commit is contained in:
Gregory Nutt
2016-08-05 11:07:35 -06:00
parent 7da67bc80a
commit 7048d08123
6 changed files with 489 additions and 10 deletions
+10 -2
View File
@@ -83,9 +83,10 @@
#define _LOOPBASE (0x1e00) /* Loop device commands */
#define _MODEMBASE (0x1f00) /* Modem ioctl commands */
#define _I2CBASE (0x2000) /* I2C driver commands */
#define _GPIOBASE (0x2100) /* GPIO driver commands */
#define _SPIBASE (0x2100) /* SPI driver commands */
#define _GPIOBASE (0x2200) /* GPIO driver commands */
/* boardctl commands share the same number space */
/* boardctl() commands share the same number space */
#define _BOARDBASE (0xff00) /* boardctl commands */
@@ -385,7 +386,14 @@
#define _I2CIOCVALID(c) (_IOC_TYPE(c)==_I2CBASE)
#define _I2CIOC(nr) _IOC(_I2CBASE,nr)
/* SPI driver ioctl definitions **********************************************/
/* see nuttx/include/spi/spi_transfer.h */
#define _SPIIOCVALID(c) (_IOC_TYPE(c)==_SPIBASE)
#define _SPIIOC(nr) _IOC(_SPIBASE,nr)
/* GPIO driver command definitions ******************************************/
/* see nuttx/include/ioexpander/gpio.h */
#define _GPIOCVALID(c) (_IOC_TYPE(c)==_GPIOBASE)
#define _GPIOC(nr) _IOC(_GPIOBASE,nr)
+42
View File
@@ -46,10 +46,26 @@
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/spi/spi.h>
#ifdef CONFIG_SPI_EXCHANGE
/* SPI Character Driver IOCTL Commands **************************************/
/* The SPI driver is intended to support application testing of the SPI bus.
* The SPI driver simply provides a user-accessible wrapper around the
* OS internal spi_transfer() function. The following IOCTL commands to
* supported by the SPI driver to perform SPI transfers
*/
/* Command: SPIIOC_TRANSFER
* Description: Perform a sequence of SPI transfers
* Argument: A reference to an instance of struct spi_sequence_s.
* Dependencies: CONFIG_SPI_DRIVER
*/
#define SPIIOC_TRANSFER _SPIIOC(0x0001)
/****************************************************************************
* Public Types
****************************************************************************/
@@ -129,6 +145,32 @@ struct spi_sequence_s
int spi_transfer(FAR struct spi_dev_s *spi, FAR struct spi_sequence_s *seq);
/****************************************************************************
* Name: spi_register
*
* Description:
* Create and register the SPI character driver.
*
* The SPI character driver is a simple character driver that supports SPI
* transfers. The intent of this driver is to support SPI testing. It is
* not suitable for use in any real driver application.
*
* Input Parameters:
* spi - An instance of the lower half SPI driver
* bus - The SPI bus number. This will be used as the SPI device minor
* number. The SPI character device will be registered as /dev/spiN
* where N is the minor number
*
* Returned Value:
* OK if the driver was successfully register; A negated errno value is
* returned on any failure.
*
****************************************************************************/
#ifdef CONFIG_SPI_DRIVER
int spi_register(FAR struct spi_dev_s *spi, int bus);
#endif
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"