Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
spidev.h
Go to the documentation of this file.
1
34#ifndef _INCLUDE_SPI_SPIDEV_H_
35#define _INCLUDE_SPI_SPIDEV_H_
36
37#if defined (__linux__)
38 #include <linux/spi/spidev.h>
39#elif defined (__FreeRTOS__)
40 #include <stdint.h>
41
44 #define SPI_CPHA 0x01
45
48 #define SPI_CPOL 0x02
49
52 #define SPI_MODE_0 (0 | 0)
53
56 #define SPI_MODE_1 (0 | SPI_CPHA)
57
60 #define SPI_MODE_2 (SPI_CPOL | 0)
61
64 #define SPI_MODE_3 (SPI_CPOL | SPI_CPHA)
65
67 #define SPI_IOC_MAGIC ('s')
68
70 struct spi_ioc_transfer
71 {
73 uint64_t tx_buf;
74
76 uint64_t rx_buf;
77
78 uint32_t len;
79 uint32_t speed_hz;
84 uint32_t delay_usec;
85 uint8_t bits_per_word;
88 uint8_t cs_change;
89 uint32_t pad;
90 };
91
93 #define SPI_MSGSIZE(N) \
94 ((((N)*(sizeof (struct spi_ioc_transfer))) < (1 << IOC_SIZEBITS)) \
95 ? ((N)*(sizeof (struct spi_ioc_transfer))) : 0)
96
98 #define SPI_IOC_MESSAGE(N) \
99 IOW(SPI_IOC_MAGIC, 0, sizeof(char[SPI_MSGSIZE(N)]))
100
104 #define SPI_IOC_RD_MODE IOR(SPI_IOC_MAGIC, 1, sizeof(uint8_t))
105
109 #define SPI_IOC_WR_MODE IOW(SPI_IOC_MAGIC, 1, sizeof(uint8_t))
110
113 #define SPI_IOC_RD_LSB_FIRST IOR(SPI_IOC_MAGIC, 2, sizeof(uint8_t))
114
117 #define SPI_IOC_WR_LSB_FIRST IOW(SPI_IOC_MAGIC, 2, sizeof(uint8_t))
118
121 #define SPI_IOC_RD_BITS_PER_WORD IOR(SPI_IOC_MAGIC, 3, sizeof(uint8_t))
122
125 #define SPI_IOC_WR_BITS_PER_WORD IOW(SPI_IOC_MAGIC, 3, sizeof(uint8_t))
126
129 #define SPI_IOC_RD_MAX_SPEED_HZ IOR(SPI_IOC_MAGIC, 4, sizeof(uint32_t))
130
133 #define SPI_IOC_WR_MAX_SPEED_HZ IOW(SPI_IOC_MAGIC, 4, sizeof(uint32_t))
134
137 #define SPI_IOC_GET_OBJECT_REFERENCE IOR(SPI_IOC_MAGIC, 5, sizeof(void*))
138
139#else
140 #error SPI drivers not supported on this OS
141#endif
142
143#endif /* _INCLUDE_SPI_SPIDEV_H_ */