drivers/spi: Add SPI Slave character device driver

This commit is contained in:
Gustavo Henrique Nihei
2021-05-14 22:41:15 -03:00
committed by Alan Carvalho de Assis
parent e29da149e3
commit 57723eaedf
4 changed files with 728 additions and 4 deletions
+64 -4
View File
@@ -26,21 +26,81 @@ menuconfig SPI
if SPI
config SPI_SLAVE
bool "SPI slave"
bool "SPI Slave"
default n
---help---
Enable support for SPI slave features
Enable support for SPI Slave features
if SPI_SLAVE
config SPI_SLAVE_DRIVER
bool "SPI Slave character driver"
default n
---help---
Built-in support for a character driver at /dev/spislv[N] that may be
used to perform SPI bus transfers from applications.
The intent of this driver is to support SPI Slave testing.
if SPI_SLAVE_DRIVER
config SPI_SLAVE_DRIVER_MODE
int "SPI Slave character driver default mode"
default 0
---help---
Default SPI Slave character driver mode, where:
0 = CPOL=0, CPHA=0
1 = CPOL=0, CPHA=1
2 = CPOL=1, CPHA=0
3 = CPOL=1, CPHA=1
config SPI_SLAVE_DRIVER_WIDTH
int "SPI Slave character driver default bit width"
default 8
---help---
Number of bits per SPI Slave transfer (default 8).
config SPI_SLAVE_DRIVER_BUFFER_SIZE
int "SPI Slave character driver TX and RX buffer sizes"
default 128
---help---
Size of the internal TX and RX buffers of the SPI Slave
character driver.
config SPI_SLAVE_DRIVER_COLORIZE_TX_BUFFER
bool "SPI Slave character driver colorize TX buffer"
default n
---help---
Initialize entries of the TX buffer with a given pattern.
If the SPI Slave controller performs a call to "getdata" API during
the "bind" operation, the colorized buffer may be sent as part of the
first TX transfer of the SPI Slave controller.
This feature might be useful for a quick communication test between
Master and Slave.
config SPI_SLAVE_DRIVER_COLORIZE_PATTERN
hex "SPI Slave character driver colorize pattern"
default 0xa5
depends on SPI_SLAVE_DRIVER_COLORIZE_TX_BUFFER
---help---
Pattern to be used as the coloration of the TX buffer.
config SPI_SLAVE_DRIVER_COLORIZE_NUM_BYTES
int "SPI Slave character driver colorize number of bytes"
default 4
depends on SPI_SLAVE_DRIVER_COLORIZE_TX_BUFFER
---help---
Number of bytes of the TX buffer to be colorized.
endif # SPI_SLAVE_DRIVER
config SPI_SLAVE_DMA
bool "SPI slave DMA"
bool "SPI Slave DMA"
default n
depends on ARCH_DMA && EXPERIMENTAL
---help---
Enable support for DMA data transfers (not yet implemented).
endif
endif # SPI_SLAVE
config SPI_EXCHANGE
bool "SPI exchange"
+4
View File
@@ -29,6 +29,10 @@ ifeq ($(CONFIG_SPI_EXCHANGE),y)
endif
endif
ifeq ($(CONFIG_SPI_SLAVE_DRIVER),y)
CSRCS += spi_slave_driver.c
endif
# Include the selected SPI drivers
ifeq ($(CONFIG_SPI_BITBANG),y)
File diff suppressed because it is too large Load Diff
+31
View File
@@ -534,6 +534,36 @@ struct spi_sdev_s
* Public Data
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Functions Definitions
****************************************************************************/
/****************************************************************************
* Name: spislv_register
*
* Description:
* Register the SPI Slave echo character device as 'devpath'.
*
* Input Parameters:
* sctrlr - An instance of the SPI Slave interface to use to communicate
* with the SPI Slave echo device
* bus - The SPI Slave bus number. This will be used as the SPI device
* minor number. The SPI Slave character device will be
* registered as /dev/spislvN where N is the minor number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_SPI_SLAVE_DRIVER
int spislv_register(FAR struct spi_sctrlr_s *sctrlr, int bus);
#endif /* CONFIG_SPI_SLAVE_DRIVER */
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
@@ -547,4 +577,5 @@ extern "C"
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_NUTTX_SPI_SLAVE_H */