Skip to content

Commit cd701a2

Browse files
committed
port to RTduino
1 parent e89ae64 commit cd701a2

10 files changed

+229
-429
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/githubci.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

Adafruit_BusIO_Register.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
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+
*/
214

3-
#if !defined(SPI_INTERFACES_COUNT) || \
4-
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
15+
#include <Adafruit_BusIO_Register.h>
516

17+
#ifdef RTDUINO_USING_WIRE
618
/*!
719
* @brief Create a register we access over an I2C Device (which defines the
820
* bus and address)
@@ -21,13 +33,18 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
2133
uint8_t byteorder,
2234
uint8_t address_width) {
2335
_i2cdevice = i2cdevice;
24-
_spidevice = nullptr;
36+
#ifdef RTDUINO_USING_SPI
37+
_spidevice = NULL;
38+
#endif /* RTDUINO_USING_SPI */
2539
_addrwidth = address_width;
2640
_address = reg_addr;
2741
_byteorder = byteorder;
2842
_width = width;
43+
_cached = 0;
2944
}
45+
#endif /* RTDUINO_USING_WIRE */
3046

47+
#ifdef RTDUINO_USING_SPI
3148
/*!
3249
* @brief Create a register we access over an SPI Device (which defines the
3350
* bus and CS pin)
@@ -50,11 +67,12 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
5067
uint8_t address_width) {
5168
_spidevice = spidevice;
5269
_spiregtype = type;
53-
_i2cdevice = nullptr;
70+
_i2cdevice = NULL;
5471
_addrwidth = address_width;
5572
_address = reg_addr;
5673
_byteorder = byteorder;
5774
_width = width;
75+
_cached = 0;
5876
}
5977

6078
/*!
@@ -86,7 +104,9 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(
86104
_address = reg_addr;
87105
_byteorder = byteorder;
88106
_width = width;
107+
_cached = 0;
89108
}
109+
#endif /* RTDUINO_USING_SPI */
90110

91111
/*!
92112
* @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) {
99119

100120
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
101121
(uint8_t)(_address >> 8)};
102-
122+
#ifdef RTDUINO_USING_WIRE
103123
if (_i2cdevice) {
104124
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
105125
}
126+
#endif /* RTDUINO_USING_WIRE */
127+
#ifdef RTDUINO_USING_SPI
106128
if (_spidevice) {
107129
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
108130
// very special case!
@@ -129,6 +151,7 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
129151
}
130152
return _spidevice->write(buffer, len, addrbuffer, _addrwidth);
131153
}
154+
#endif /* RTDUINO_USING_SPI */
132155
return false;
133156
}
134157

@@ -168,7 +191,7 @@ bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) {
168191
*/
169192
uint32_t Adafruit_BusIO_Register::read(void) {
170193
if (!read(_buffer, _width)) {
171-
return -1;
194+
return (uint32_t)-1;
172195
}
173196

174197
uint32_t value = 0;
@@ -201,10 +224,12 @@ uint32_t Adafruit_BusIO_Register::readCached(void) { return _cached; }
201224
bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
202225
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
203226
(uint8_t)(_address >> 8)};
204-
227+
#ifdef RTDUINO_USING_WIRE
205228
if (_i2cdevice) {
206229
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
207230
}
231+
#endif /* RTDUINO_USING_WIRE */
232+
#ifdef RTDUINO_USING_SPI
208233
if (_spidevice) {
209234
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
210235
// very special case!
@@ -230,6 +255,7 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
230255
}
231256
return _spidevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
232257
}
258+
#endif /* RTDUINO_USING_SPI */
233259
return false;
234260
}
235261

@@ -361,5 +387,3 @@ void Adafruit_BusIO_Register::setAddress(uint16_t address) {
361387
void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) {
362388
_addrwidth = address_width;
363389
}
364-
365-
#endif // SPI exists

Adafruit_BusIO_Register.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
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+
*/
14+
115
#ifndef Adafruit_BusIO_Register_h
216
#define Adafruit_BusIO_Register_h
317

418
#include <Arduino.h>
519

6-
#if !defined(SPI_INTERFACES_COUNT) || \
7-
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
8-
20+
#ifdef RTDUINO_USING_WIRE
921
#include <Adafruit_I2CDevice.h>
22+
#endif /* RTDUINO_USING_WIRE */
23+
#ifdef RTDUINO_USING_SPI
1024
#include <Adafruit_SPIDevice.h>
25+
#endif /* RTDUINO_USING_SPI */
1126

1227
typedef enum _Adafruit_BusIO_SPIRegType {
1328
ADDRBIT8_HIGH_TOREAD = 0,
@@ -42,10 +57,12 @@ typedef enum _Adafruit_BusIO_SPIRegType {
4257
*/
4358
class Adafruit_BusIO_Register {
4459
public:
60+
#ifdef RTDUINO_USING_WIRE
4561
Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr,
4662
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
4763
uint8_t address_width = 1);
48-
64+
#endif /* RTDUINO_USING_WIRE */
65+
#ifdef RTDUINO_USING_SPI
4966
Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr,
5067
Adafruit_BusIO_SPIRegType type, uint8_t width = 1,
5168
uint8_t byteorder = LSBFIRST,
@@ -56,7 +73,7 @@ class Adafruit_BusIO_Register {
5673
Adafruit_BusIO_SPIRegType type, uint16_t reg_addr,
5774
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
5875
uint8_t address_width = 1);
59-
76+
#endif /* RTDUINO_USING_SPI */
6077
bool read(uint8_t *buffer, uint8_t len);
6178
bool read(uint8_t *value);
6279
bool read(uint16_t *value);
@@ -75,14 +92,17 @@ class Adafruit_BusIO_Register {
7592
void println(Stream *s = &Serial);
7693

7794
private:
95+
#ifdef RTDUINO_USING_WIRE
7896
Adafruit_I2CDevice *_i2cdevice;
97+
#endif /* RTDUINO_USING_WIRE */
98+
#ifdef RTDUINO_USING_SPI
7999
Adafruit_SPIDevice *_spidevice;
80100
Adafruit_BusIO_SPIRegType _spiregtype;
101+
#endif /* RTDUINO_USING_SPI */
81102
uint16_t _address;
82103
uint8_t _width, _addrwidth, _byteorder;
83-
uint8_t _buffer[4]; // we won't support anything larger than uint32 for
84-
// non-buffered read
85-
uint32_t _cached = 0;
104+
uint8_t _buffer[4]; // we won't support anything larger than uint32 for non-buffered read
105+
uint32_t _cached;
86106
};
87107

88108
/*!
@@ -101,5 +121,4 @@ class Adafruit_BusIO_RegisterBits {
101121
uint8_t _bits, _shift;
102122
};
103123

104-
#endif // SPI exists
105124
#endif // BusIO_Register_h

0 commit comments

Comments
 (0)