RasPi Direct Hardware Access
Integrated peripheral access without operating system drivers.
Main Page
Modules
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Macros
Groups
Pages
spi.h
Go to the documentation of this file.
1
36
#ifndef RASPI_SPI_H
37
#define RASPI_SPI_H
38
39
#include "
raspi/hw.h
"
40
#include <stdint.h>
41
43
#define raspi_SPI_FIFOSIZE 16
44
45
47
static
inline
void
spi_init
(uint32_t speed)
48
{
49
int
i;
50
uint32_t div =
CORE_CLOCK
/ speed;
51
52
if
(div >= 65536) div = 0;
53
if
(div < 2) div = 2;
54
HW
.SPI0.CLK.B.CDIV = div;
55
HW
.SPI0.CS.B.CPHA = 1;
56
57
memory_barrier
();
58
for
(i = 7; i <= 11; i++)
gpio_configure
(i, Alt0);
59
memory_barrier
();
60
}
61
62
65
static
inline
void
spi_start
(
int
destination)
66
{
67
HW
.SPI0.CS.B.CS = destination;
68
HW
.SPI0.CS.B.CLEAR = 2;
69
HW
.SPI0.CS.B.TA = 1;
70
}
71
72
74
static
inline
void
spi_stop
(
void
)
75
{
76
while
(!
HW
.SPI0.CS.B.DONE);
77
HW
.SPI0.CS.B.TA = 0;
78
}
79
80
84
static
inline
int
spi_poll
(
int
num)
85
{
86
if
(num <= 0)
return
1;
87
if
(num <
raspi_SPI_FIFOSIZE
*3/4)
return
HW
.SPI0.CS.B.RXD;
88
if
(num <
raspi_SPI_FIFOSIZE
)
return
HW
.SPI0.CS.B.RXR;
89
return
HW
.SPI0.CS.B.RXF;
90
}
91
92
96
static
inline
uint8_t
spi_read
(
void
)
97
{
98
while
(!
HW
.SPI0.CS.B.RXD);
99
return
HW
.SPI0.FIFO;
100
}
101
102
105
static
inline
void
spi_write
(uint8_t data)
106
{
107
while
(!
HW
.SPI0.CS.B.TXD);
108
HW
.SPI0.FIFO = data;
109
}
110
111
113
static
inline
void
spi_flush
(
void
)
114
{
115
while
(
HW
.SPI0.CS.B.TA && !
HW
.SPI0.CS.B.DONE);
116
}
117
118
#endif
119
Generated on Fri Jan 17 2014 13:43:08 for RasPi Direct Hardware Access by
1.8.3.1