1
- #include < Adafruit_BusIO_Register.h>
1
+ /*
2
+ * Copyright (c) 2021-2022, RTduino Development Team
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * https://github.com/RTduino/RTduino
7
+ * https://gitee.com/rtduino/RTduino
8
+ *
9
+ * Change Logs:
10
+ * Date Author Notes
11
+ * Adafruit Team First version
12
+ * 2022-02-19 Meco Man port to RTduino
13
+ */
2
14
3
- #if !defined(SPI_INTERFACES_COUNT) || \
4
- (defined (SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0 ))
15
+ #include < Adafruit_BusIO_Register.h>
5
16
17
+ #ifdef RTDUINO_USING_WIRE
6
18
/* !
7
19
* @brief Create a register we access over an I2C Device (which defines the
8
20
* bus and address)
@@ -21,13 +33,18 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
21
33
uint8_t byteorder,
22
34
uint8_t address_width) {
23
35
_i2cdevice = i2cdevice;
24
- _spidevice = nullptr ;
36
+ #ifdef RTDUINO_USING_SPI
37
+ _spidevice = NULL ;
38
+ #endif /* RTDUINO_USING_SPI */
25
39
_addrwidth = address_width;
26
40
_address = reg_addr;
27
41
_byteorder = byteorder;
28
42
_width = width;
43
+ _cached = 0 ;
29
44
}
45
+ #endif /* RTDUINO_USING_WIRE */
30
46
47
+ #ifdef RTDUINO_USING_SPI
31
48
/* !
32
49
* @brief Create a register we access over an SPI Device (which defines the
33
50
* bus and CS pin)
@@ -50,11 +67,12 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
50
67
uint8_t address_width) {
51
68
_spidevice = spidevice;
52
69
_spiregtype = type;
53
- _i2cdevice = nullptr ;
70
+ _i2cdevice = NULL ;
54
71
_addrwidth = address_width;
55
72
_address = reg_addr;
56
73
_byteorder = byteorder;
57
74
_width = width;
75
+ _cached = 0 ;
58
76
}
59
77
60
78
/* !
@@ -86,7 +104,9 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(
86
104
_address = reg_addr;
87
105
_byteorder = byteorder;
88
106
_width = width;
107
+ _cached = 0 ;
89
108
}
109
+ #endif /* RTDUINO_USING_SPI */
90
110
91
111
/* !
92
112
* @brief Write a buffer of data to the register location
@@ -99,10 +119,12 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
99
119
100
120
uint8_t addrbuffer[2 ] = {(uint8_t )(_address & 0xFF ),
101
121
(uint8_t )(_address >> 8 )};
102
-
122
+ # ifdef RTDUINO_USING_WIRE
103
123
if (_i2cdevice) {
104
124
return _i2cdevice->write (buffer, len, true , addrbuffer, _addrwidth);
105
125
}
126
+ #endif /* RTDUINO_USING_WIRE */
127
+ #ifdef RTDUINO_USING_SPI
106
128
if (_spidevice) {
107
129
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
108
130
// very special case!
@@ -129,6 +151,7 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
129
151
}
130
152
return _spidevice->write (buffer, len, addrbuffer, _addrwidth);
131
153
}
154
+ #endif /* RTDUINO_USING_SPI */
132
155
return false ;
133
156
}
134
157
@@ -168,7 +191,7 @@ bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) {
168
191
*/
169
192
uint32_t Adafruit_BusIO_Register::read (void ) {
170
193
if (!read (_buffer, _width)) {
171
- return -1 ;
194
+ return ( uint32_t ) -1 ;
172
195
}
173
196
174
197
uint32_t value = 0 ;
@@ -201,10 +224,12 @@ uint32_t Adafruit_BusIO_Register::readCached(void) { return _cached; }
201
224
bool Adafruit_BusIO_Register::read (uint8_t *buffer, uint8_t len) {
202
225
uint8_t addrbuffer[2 ] = {(uint8_t )(_address & 0xFF ),
203
226
(uint8_t )(_address >> 8 )};
204
-
227
+ # ifdef RTDUINO_USING_WIRE
205
228
if (_i2cdevice) {
206
229
return _i2cdevice->write_then_read (addrbuffer, _addrwidth, buffer, len);
207
230
}
231
+ #endif /* RTDUINO_USING_WIRE */
232
+ #ifdef RTDUINO_USING_SPI
208
233
if (_spidevice) {
209
234
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
210
235
// very special case!
@@ -230,6 +255,7 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
230
255
}
231
256
return _spidevice->write_then_read (addrbuffer, _addrwidth, buffer, len);
232
257
}
258
+ #endif /* RTDUINO_USING_SPI */
233
259
return false ;
234
260
}
235
261
@@ -361,5 +387,3 @@ void Adafruit_BusIO_Register::setAddress(uint16_t address) {
361
387
void Adafruit_BusIO_Register::setAddressWidth (uint16_t address_width) {
362
388
_addrwidth = address_width;
363
389
}
364
-
365
- #endif // SPI exists
0 commit comments