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