-
Notifications
You must be signed in to change notification settings - Fork 198
/
spi.c
56 lines (50 loc) · 1.04 KB
/
spi.c
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
/*
* spi.c
*
* Helper functions for STM32F10x SPI interfaces.
*
* Written & released by Keir Fraser <[email protected]>
*
* This is free and unencumbered software released into the public domain.
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/
void spi_quiesce(SPI spi)
{
while ((spi->sr & (SPI_SR_TXE|SPI_SR_BSY)) != SPI_SR_TXE)
cpu_relax();
(void)spi->dr; /* flush the rx buffer */
}
void spi_16bit_frame(SPI spi)
{
spi_quiesce(spi);
spi->cr1 |= SPI_CR1_DFF;
}
void spi_8bit_frame(SPI spi)
{
spi_quiesce(spi);
spi->cr1 &= ~SPI_CR1_DFF;
}
void spi_xmit16(SPI spi, uint16_t out)
{
while (!(spi->sr & SPI_SR_TXE))
cpu_relax();
spi->dr = out;
}
uint16_t spi_xchg16(SPI spi, uint16_t out)
{
while (!(spi->sr & SPI_SR_TXE))
cpu_relax();
spi->dr = out;
while (!(spi->sr & SPI_SR_RXNE))
continue;
return spi->dr;
}
/*
* Local variables:
* mode: C
* c-file-style: "Linux"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/