fb11e647
vrobic
reseau statique a...
|
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
|
/*
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup drivers
* @{
*
* @file
* @brief common SPI function fallback implementations
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stddef.h>
#include "board.h"
#include "cpu.h"
#include "periph/spi.h"
#include "periph_cpu.h"
#if SPI_NUMOF
#ifdef PERIPH_SPI_NEEDS_TRANSFER_BYTES
int spi_transfer_bytes(spi_t dev, char *out, char *in, unsigned int length)
{
int trans_ret;
unsigned trans_bytes = 0;
char in_temp;
for (trans_bytes = 0; trans_bytes < length; trans_bytes++) {
if (out != NULL) {
trans_ret = spi_transfer_byte(dev, out[trans_bytes], &in_temp);
}
else {
trans_ret = spi_transfer_byte(dev, 0, &in_temp);
}
if (trans_ret < 0) {
return -1;
}
if (in != NULL) {
in[trans_bytes] = in_temp;
}
}
return trans_bytes;
}
#endif
#ifdef PERIPH_SPI_NEEDS_TRANSFER_BYTE
int spi_transfer_byte(spi_t dev, char out, char *in)
{
return spi_transfer_bytes(dev, &out, in, 1);
}
#endif
#ifdef PERIPH_SPI_NEEDS_TRANSFER_REG
int spi_transfer_reg(spi_t dev, uint8_t reg, char out, char *in)
{
int trans_ret;
trans_ret = spi_transfer_byte(dev, reg, in);
if (trans_ret < 0) {
return -1;
}
trans_ret = spi_transfer_byte(dev, out, in);
if (trans_ret < 0) {
return -1;
}
return 1;
}
#endif
#ifdef PERIPH_SPI_NEEDS_TRANSFER_REGS
int spi_transfer_regs(spi_t dev, uint8_t reg, char *out, char *in, unsigned int length)
{
int trans_ret;
trans_ret = spi_transfer_byte(dev, reg, in);
if (trans_ret < 0) {
return -1;
}
trans_ret = spi_transfer_bytes(dev, out, in, length);
if (trans_ret < 0) {
return -1;
}
return trans_ret;
}
#endif
#endif /* SPI_NUMOF */
|