-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi_device.h
136 lines (106 loc) · 4.22 KB
/
spi_device.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef _SPI_DEVICE_
#define _SPI_DEVICE_
/* -------------------------------------------------------------------------- */
/* NAME: SPI Device H - Raspberry Pi Zero W */
/* -------------------------------------------------------------------------- */
/* AUTHOR: Alessandro Rossetti */
/* VERSION: 0000 */
/* SOC: BCM2835 */
/* DOCUMENT REFERENCE: BCM2835-ARM-Peripherals.pdf */
/* -------------------------------------------------------------------------- */
#include <stdint.h>
#include <linux/spi/spidev.h>
/*
Handles
REFERNECE DOCUMENTATION
-----------------------
https://www.kernel.org/doc/Documentation/spi/spidev
SPI MODES
---------
SPI_MODE_0 (0,0) CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge, output data (change) on falling edge
SPI_MODE_1 (0,1) CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge
SPI_MODE_2 (1,0) CPOL = 1, CPHA = 0, Clock idle high, data is clocked in on falling edge, output data (change) on rising edge
SPI_MODE_3 (1,1) CPOL = 1, CPHA = 1, Clock idle high, data is clocked in on rising, edge output data (change) on falling edge
SPI DEVICES
-----------
/dev/spidev0.0
/dev/spidev0.1
*/
class spi_device {
public:
/* ------------------------------ */
/* Constructor */
/* ------------------------------ */
/* spi_device: one of SPI DEVICES */
/* spi_mode: one of SPI MODES */
/* spi_bitn: bits per transfer */
/* spi_speed: speed in HZ */
/* ------------------------------ */
spi_device(
char* spi_device,
uint8_t spi_mode,
uint8_t spi_bitn,
uint32_t spi_speed
);
/* ------------------------------ */
/* Half duplex write */
/* ------------------------------ */
void writeBuf(uint8_t *bufdata, uint32_t bufsize);
/* ------------------------------ */
/* Half duplex read */
/* ------------------------------ */
void readBuf(uint8_t *bufdata, uint32_t bufsize);
/* ------------------------------ */
/* Full duplex trasfer */
/* ------------------------------ */
void transferBuf(uint8_t *rdata, uint8_t *wdata, uint32_t bufsize);
/* ------------------------------ */
/* Half duplex write */
/* ------------------------------ */
void writeSingle(uint8_t to_transfer);
/* ------------------------------ */
/* Half duplex read */
/* ------------------------------ */
uint8_t readSingle(void);
/* ------------------------------ */
/* Full duplex trasfer */
/* ------------------------------ */
uint8_t transferSingle(uint8_t to_transfer);
/* ------------------------------ */
/* Destructor */
/* ------------------------------ */
~spi_device();
private:
/* ------------------------------ */
/* File descriptor */
/* ------------------------------ */
/* Contains the posix file */
/* descripor for the initialized */
/* device */
/* ------------------------------ */
int fd;
/* ------------------------------ */
/* Devide mode */
/* ------------------------------ */
/* One of the device modes as */
/* available in the linux kernel */
/* header file */
/* ------------------------------ */
uint8_t dev_mode;
/* ------------------------------ */
/* Devide word bits count */
/* ------------------------------ */
/* Number of bits in a single */
/* transfer (word of a transfer */
/* to be precise */
/* ------------------------------ */
uint8_t dev_bitn;
/* ------------------------------ */
/* Device speed */
/* ------------------------------ */
/* Speed in Hz of the clock for */
/* the device */
/* ------------------------------ */
uint32_t dev_speed;
};
#endif