32 #include <sys/ioctl.h>
33 #include <linux/spi/spidev.h>
46 #pragma GCC diagnostic push
47 #pragma GCC diagnostic ignored "-Wcast-qual"
52 struct spi_ioc_transfer xfer;
53 memset(&xfer, 0,
sizeof xfer);
61 memset(tx_buf, 0,
sizeof tx_buf);
64 xfer.tx_buf = (
unsigned long)tx_buf;
71 memset(rx_buf, 0,
sizeof rx_buf);
72 xfer.rx_buf = (
unsigned long)rx_buf;
74 xfer.rx_buf = (
unsigned long)t->
input_buf;
82 xfer.bits_per_word = 16;
84 xfer.bits_per_word = 8;
90 if (ioctl(fd, SPI_IOC_MESSAGE(1), &xfer) < 0) {
103 #pragma GCC diagnostic pop
121 #define SPI0_MODE (SPI_CPOL | SPI_CPHA)
124 #ifndef SPI0_LSB_FIRST
125 #define SPI0_LSB_FIRST 0
128 #ifndef SPI0_BITS_PER_WORD
129 #define SPI0_BITS_PER_WORD 8
132 #ifndef SPI0_MAX_SPEED_HZ
133 #define SPI0_MAX_SPEED_HZ 1000000
138 int fd = open(
"/dev/spidev1.0", O_RDWR);
141 perror(
"Could not open SPI device /dev/spidev1.0");
149 if (ioctl(fd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
150 perror(
"SPI0: can't set spi mode");
155 if (ioctl(fd, SPI_IOC_WR_LSB_FIRST, &spi_order) < 0) {
156 perror(
"SPI0: can't set spi bit justification");
161 if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits_per_word) < 0) {
162 perror(
"SPI0: can't set bits per word");
167 if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed) < 0) {
168 perror(
"SPI0: can't set max speed hz");
177 #define SPI1_MODE (SPI_CPOL | SPI_CPHA)
180 #ifndef SPI1_LSB_FIRST
181 #define SPI1_LSB_FIRST 0
184 #ifndef SPI1_BITS_PER_WORD
185 #define SPI1_BITS_PER_WORD 8
188 #ifndef SPI1_MAX_SPEED_HZ
189 #define SPI1_MAX_SPEED_HZ 1000000
194 int fd = open(
"/dev/spidev1.1", O_RDWR);
197 perror(
"Could not open SPI device /dev/spidev1.1");
198 spi1.reg_addr = NULL;
201 spi1.reg_addr = (
void *)fd;
205 if (ioctl(fd, SPI_IOC_WR_MODE, &spi_mode) < 0) {
206 perror(
"SPI1: can't set spi mode");
211 if (ioctl(fd, SPI_IOC_WR_LSB_FIRST, &spi_order) < 0) {
212 perror(
"SPI1: can't set spi bit justification");
217 if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &spi_bits_per_word) < 0) {r
218 perror(
"SPI1: can't set bits per word");
223 if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &spi_speed) < 0) {
224 perror(
"SPI1: can't set max speed hz");
uint16_t output_length
number of data words to write
void spi1_arch_init(void)
Architecture dependent SPI1 initialization.
slave is not selected but unselected after transaction
SPI transaction structure.
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
#define SPI0_BITS_PER_WORD
volatile uint8_t * output_buf
pointer to transmit buffer for DMA
enum SPISlaveSelect select
slave selection behavior
Architecture independent SPI (Serial Peripheral Interface) API.
bool spi_lock(struct spi_periph *p, uint8_t slave)
spi_lock() function
SPI peripheral structure.
#define SPI1_MAX_SPEED_HZ
#define SPI0_MAX_SPEED_HZ
uint16_t input_length
number of data words to read
bool spi_resume(struct spi_periph *p, uint8_t slave)
spi_resume() function
slave is selected before transaction and unselected after
enum SPIDataSizeSelect dss
data transfer word size
volatile uint8_t * input_buf
pointer to receive buffer for DMA
#define SPI1_BITS_PER_WORD
void spi_init_slaves(void)
spi_init_slaves() function
void spi0_arch_init(void)
Architecture dependent SPI0 initialization.
process_rx_dma_interrupt & spi1
receive transferred over DMA
enum SPITransactionStatus status
if(PrimarySpektrumState.SpektrumTimer)