forked from gicking/stm8gal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi_spidev_comm.h
71 lines (51 loc) · 1.8 KB
/
spi_spidev_comm.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
/**
\file spi_spidev_comm.h
\author G. Icking-Konert
\date 2017-12-10
\version 0.1
\brief declaration of SPI comm routines via spidev library
declaration of routines for SPI communication using the spidev library.
*/
// for including file only once
#ifndef _SPI_SPIDEV_COMM_H_
#define _SPI_SPIDEV_COMM_H_
// generic ANSI
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
// only if SPI via spidev is set in Makefile
#if defined(USE_SPIDEV)
// OS specific: Windows
#if defined(WIN32) || defined(WIN64)
#error Windows not supported
// OS specific: Posix
#elif defined(__APPLE__) || defined(__unix__)
#define HANDLE int // comm port handler is int
#include <fcntl.h> // File control definitions
#include <termios.h> // Posix terminal control definitions
#include <errno.h> // error number definitions
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#else
#error OS not supported
#endif
/// init SPI port
HANDLE init_spi_spidev(const char *port, uint32_t baudrate);
/// close SPI port
void close_spi_spidev(HANDLE *fp);
/// send data via SPI (no parallel receive)
uint32_t send_spi_spidev(HANDLE fp, uint32_t lenTx, char *Tx);
/// receive data via SPI (no parallel send)
uint32_t receive_spi_spidev(HANDLE fp, uint32_t lenRx, char *Rx);
/// send & receive data via SPI (parallel send)
void spi_transfer(HANDLE fp, int len, uint8_t *Tx, uint8_t *Rx);
#endif // USE_SPIDEV
#endif // _SPI_SPIDEV_COMM_H_
// end of file