-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi.h
82 lines (67 loc) · 4.26 KB
/
spi.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
#ifndef _SPI_H_
#define _SPI_H_
#ifdef __cplusplus // If we are including to a C++
extern "C" { // Put extern C directive wrapper around
#endif
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{ }
{ Filename: spi.h }
{ Copyright(c): Leon de Boer(LdB) 2019, 2020 }
{ Version: 1.10 }
{ }
{***************************************************************************}
{ }
{ Defines an API interface for the SPI devices on Linux }
{ }
{++++++++++++++++++++++++[ REVISIONS ]++++++++++++++++++++++++++++++++++++++}
{ 1.00 Initial version }
{ 1.10 Compacted stuct fields }
{++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include <stdbool.h> // C standard unit for bool, true, false
#include <stdint.h> // C standard unit for uint32_t etc
#define SPI_DRIVER_VERSION 1100 // Version number 1.10 build 0
typedef struct spi_device* SPI_HANDLE; // Define an SPI_HANDLE pointer to opaque internal struct
#define NSPI 2 // 2 SPI devices supported
/*-[ SpiOpenPort ]----------------------------------------------------------}
. Creates a SPI handle which provides access to the SPI device number.
. The SPI device is setup to the bits, speed and mode provided.
. RETURN: valid SPI_HANDLE for success, NULL for any failure
.--------------------------------------------------------------------------*/
SPI_HANDLE SpiOpenPort (uint8_t spi_devicenum, uint8_t spi_port, uint16_t bit_exchange_size, uint32_t speed, uint8_t mode, bool useLock);
/*-[ SpiClosePort ]---------------------------------------------------------}
. Given a valid SPI handle the access is released and the handle freed.
. RETURN: true for success, false for any failure
.--------------------------------------------------------------------------*/
bool SpiClosePort (SPI_HANDLE spiHandle);
/*-[ SpiWriteAndRead ]------------------------------------------------------}
. Given a valid SPI handle and valid data pointers the call will send and
. receive data to and from the buffer pointers. As the write occurs before
. the read the buffer pointers can be the same buffer space.
. RETURN: >= 0 transfer count for success, < 0 for any error
.--------------------------------------------------------------------------*/
int SpiWriteAndRead (SPI_HANDLE spiHandle, uint8_t* TxData, uint8_t* RxData, uint8_t Length, bool LeaveCsLow);
/*-[ SpiWriteAndRead16 ]------------------------------------------------------}
. Given a valid SPI handle and valid data pointers the call will send and
. receive data to and from the buffer pointers. As the write occurs before
. the read the buffer pointers can be the same buffer space.
. RETURN: >= 0 transfer count for success, < 0 for any error
.--------------------------------------------------------------------------*/
int SpiWriteAndRead16 (SPI_HANDLE spiHandle, uint16_t* TxData, uint16_t* RxData, uint8_t Length, bool LeaveCsLow);
/*-[ SpiWriteAndRead32 ]------------------------------------------------------}
. Given a valid SPI handle and valid data pointers the call will send and
. receive data to and from the buffer pointers. As the write occurs before
. the read the buffer pointers can be the same buffer space.
. RETURN: >= 0 transfer count for success, < 0 for any error
.--------------------------------------------------------------------------*/
int SpiWriteAndRead32 (SPI_HANDLE spiHandle, uint32_t* TxData, uint32_t* RxData, uint8_t Length, bool LeaveCsLow);
/*-[ SpiWriteBlockRepeat ]--------------------------------------------------}
. Given a valid SPI handle and valid data pointers the call will send the
. data block count times. It is used to speed up things like writing LCD
. SPI screen areas a fixed colour.
. RETURN: >= 0 blocks transfered for success, < 0 for any error
.--------------------------------------------------------------------------*/
int SpiWriteBlockRepeat (SPI_HANDLE spiHandle, uint16_t* TxBlock, uint16_t TxBlockLen, uint32_t Repeats, bool LeaveCsLow);
#ifdef __cplusplus // If we are including to a C++ file
} // Close the extern C directive wrapper
#endif
#endif