Skip to content

Commit 29f12e3

Browse files
committed
Update working libraries
1 parent 65a1c15 commit 29f12e3

File tree

7,685 files changed

+6351837
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,685 files changed

+6351837
-534
lines changed

libraries/Adafruit_BusIO/Adafruit_BusIO_Register.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(
8888
_width = width;
8989
}
9090

91+
/*!
92+
* @brief Create a register we access over a GenericDevice
93+
* @param genericdevice Generic device to use
94+
* @param reg_addr Register address we will read/write
95+
* @param width Width of the register in bytes (1-4)
96+
* @param byteorder Byte order of register data (LSBFIRST or MSBFIRST)
97+
* @param address_width Width of the register address in bytes (1 or 2)
98+
*/
99+
Adafruit_BusIO_Register::Adafruit_BusIO_Register(
100+
Adafruit_GenericDevice *genericdevice, uint16_t reg_addr, uint8_t width,
101+
uint8_t byteorder, uint8_t address_width) {
102+
_i2cdevice = nullptr;
103+
_spidevice = nullptr;
104+
_genericdevice = genericdevice;
105+
_addrwidth = address_width;
106+
_address = reg_addr;
107+
_byteorder = byteorder;
108+
_width = width;
109+
}
110+
91111
/*!
92112
* @brief Write a buffer of data to the register location
93113
* @param buffer Pointer to data to write
@@ -96,17 +116,14 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(
96116
* uncheckable)
97117
*/
98118
bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
99-
100119
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
101120
(uint8_t)(_address >> 8)};
102-
103121
if (_i2cdevice) {
104122
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
105123
}
106124
if (_spidevice) {
107125
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
108126
// very special case!
109-
110127
// pass the special opcode address which we set as the high byte of the
111128
// regaddr
112129
addrbuffer[0] =
@@ -116,7 +133,6 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
116133
// the address appears to be a byte longer
117134
return _spidevice->write(buffer, len, addrbuffer, _addrwidth + 1);
118135
}
119-
120136
if (_spiregtype == ADDRBIT8_HIGH_TOREAD) {
121137
addrbuffer[0] &= ~0x80;
122138
}
@@ -129,6 +145,9 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
129145
}
130146
return _spidevice->write(buffer, len, addrbuffer, _addrwidth);
131147
}
148+
if (_genericdevice) {
149+
return _genericdevice->writeRegister(addrbuffer, _addrwidth, buffer, len);
150+
}
132151
return false;
133152
}
134153

@@ -192,23 +211,20 @@ uint32_t Adafruit_BusIO_Register::read(void) {
192211
uint32_t Adafruit_BusIO_Register::readCached(void) { return _cached; }
193212

194213
/*!
195-
* @brief Read a buffer of data from the register location
196-
* @param buffer Pointer to data to read into
197-
* @param len Number of bytes to read
198-
* @return True on successful write (only really useful for I2C as SPI is
199-
* uncheckable)
200-
*/
214+
@brief Read a number of bytes from a register into a buffer
215+
@param buffer Buffer to read data into
216+
@param len Number of bytes to read into the buffer
217+
@return true on successful read, otherwise false
218+
*/
201219
bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
202220
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
203221
(uint8_t)(_address >> 8)};
204-
205222
if (_i2cdevice) {
206223
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
207224
}
208225
if (_spidevice) {
209226
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
210227
// very special case!
211-
212228
// pass the special opcode address which we set as the high byte of the
213229
// regaddr
214230
addrbuffer[0] =
@@ -230,6 +246,9 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
230246
}
231247
return _spidevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
232248
}
249+
if (_genericdevice) {
250+
return _genericdevice->readRegister(addrbuffer, _addrwidth, buffer, len);
251+
}
233252
return false;
234253
}
235254

libraries/Adafruit_BusIO/Adafruit_BusIO_Register.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#if !defined(SPI_INTERFACES_COUNT) || \
77
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
88

9+
#include <Adafruit_GenericDevice.h>
910
#include <Adafruit_I2CDevice.h>
1011
#include <Adafruit_SPIDevice.h>
1112

@@ -57,6 +58,11 @@ class Adafruit_BusIO_Register {
5758
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
5859
uint8_t address_width = 1);
5960

61+
Adafruit_BusIO_Register(Adafruit_GenericDevice *genericdevice,
62+
uint16_t reg_addr, uint8_t width = 1,
63+
uint8_t byteorder = LSBFIRST,
64+
uint8_t address_width = 1);
65+
6066
bool read(uint8_t *buffer, uint8_t len);
6167
bool read(uint8_t *value);
6268
bool read(uint16_t *value);
@@ -77,6 +83,7 @@ class Adafruit_BusIO_Register {
7783
private:
7884
Adafruit_I2CDevice *_i2cdevice;
7985
Adafruit_SPIDevice *_spidevice;
86+
Adafruit_GenericDevice *_genericdevice;
8087
Adafruit_BusIO_SPIRegType _spiregtype;
8188
uint16_t _address;
8289
uint8_t _width, _addrwidth, _byteorder;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Written with help by Claude!
3+
https://claude.ai/chat/335f50b1-3dd8-435e-9139-57ec7ca26a3c (at this time
4+
chats are not shareable :(
5+
*/
6+
7+
#include "Adafruit_GenericDevice.h"
8+
9+
/*!
10+
* @brief Create a Generic device with the provided read/write functions
11+
* @param obj Pointer to object instance
12+
* @param read_func Function pointer for reading raw data
13+
* @param write_func Function pointer for writing raw data
14+
* @param readreg_func Function pointer for reading registers (optional)
15+
* @param writereg_func Function pointer for writing registers (optional) */
16+
Adafruit_GenericDevice::Adafruit_GenericDevice(
17+
void *obj, busio_genericdevice_read_t read_func,
18+
busio_genericdevice_write_t write_func,
19+
busio_genericdevice_readreg_t readreg_func,
20+
busio_genericdevice_writereg_t writereg_func) {
21+
_obj = obj;
22+
_read_func = read_func;
23+
_write_func = write_func;
24+
_readreg_func = readreg_func;
25+
_writereg_func = writereg_func;
26+
_begun = false;
27+
}
28+
29+
/*! @brief Simple begin function (doesn't do much at this time)
30+
@return true always
31+
*/
32+
bool Adafruit_GenericDevice::begin(void) {
33+
_begun = true;
34+
return true;
35+
}
36+
37+
/*! @brief Write a buffer of data
38+
@param buffer Pointer to buffer of data to write
39+
@param len Number of bytes to write
40+
@return true if write was successful, otherwise false */
41+
bool Adafruit_GenericDevice::write(const uint8_t *buffer, size_t len) {
42+
if (!_begun)
43+
return false;
44+
return _write_func(_obj, buffer, len);
45+
}
46+
47+
/*! @brief Read data into a buffer
48+
@param buffer Pointer to buffer to read data into
49+
@param len Number of bytes to read
50+
@return true if read was successful, otherwise false */
51+
bool Adafruit_GenericDevice::read(uint8_t *buffer, size_t len) {
52+
if (!_begun)
53+
return false;
54+
return _read_func(_obj, buffer, len);
55+
}
56+
57+
/*! @brief Read from a register location
58+
@param addr_buf Buffer containing register address
59+
@param addrsiz Size of register address in bytes
60+
@param buf Buffer to store read data
61+
@param bufsiz Size of data to read in bytes
62+
@return true if read was successful, otherwise false */
63+
bool Adafruit_GenericDevice::readRegister(uint8_t *addr_buf, uint8_t addrsiz,
64+
uint8_t *buf, uint16_t bufsiz) {
65+
if (!_begun || !_readreg_func)
66+
return false;
67+
return _readreg_func(_obj, addr_buf, addrsiz, buf, bufsiz);
68+
}
69+
70+
/*! @brief Write to a register location
71+
@param addr_buf Buffer containing register address
72+
@param addrsiz Size of register address in bytes
73+
@param buf Buffer containing data to write
74+
@param bufsiz Size of data to write in bytes
75+
@return true if write was successful, otherwise false */
76+
bool Adafruit_GenericDevice::writeRegister(uint8_t *addr_buf, uint8_t addrsiz,
77+
const uint8_t *buf,
78+
uint16_t bufsiz) {
79+
if (!_begun || !_writereg_func)
80+
return false;
81+
return _writereg_func(_obj, addr_buf, addrsiz, buf, bufsiz);
82+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#ifndef ADAFRUIT_GENERICDEVICE_H
2+
#define ADAFRUIT_GENERICDEVICE_H
3+
4+
#include <Arduino.h>
5+
6+
typedef bool (*busio_genericdevice_read_t)(void *obj, uint8_t *buffer,
7+
size_t len);
8+
typedef bool (*busio_genericdevice_write_t)(void *obj, const uint8_t *buffer,
9+
size_t len);
10+
typedef bool (*busio_genericdevice_readreg_t)(void *obj, uint8_t *addr_buf,
11+
uint8_t addrsiz, uint8_t *data,
12+
uint16_t datalen);
13+
typedef bool (*busio_genericdevice_writereg_t)(void *obj, uint8_t *addr_buf,
14+
uint8_t addrsiz,
15+
const uint8_t *data,
16+
uint16_t datalen);
17+
18+
/*!
19+
* @brief Class for communicating with a device via generic read/write functions
20+
*/
21+
class Adafruit_GenericDevice {
22+
public:
23+
Adafruit_GenericDevice(
24+
void *obj, busio_genericdevice_read_t read_func,
25+
busio_genericdevice_write_t write_func,
26+
busio_genericdevice_readreg_t readreg_func = nullptr,
27+
busio_genericdevice_writereg_t writereg_func = nullptr);
28+
29+
bool begin(void);
30+
31+
bool read(uint8_t *buffer, size_t len);
32+
bool write(const uint8_t *buffer, size_t len);
33+
bool readRegister(uint8_t *addr_buf, uint8_t addrsiz, uint8_t *buf,
34+
uint16_t bufsiz);
35+
bool writeRegister(uint8_t *addr_buf, uint8_t addrsiz, const uint8_t *buf,
36+
uint16_t bufsiz);
37+
38+
protected:
39+
/*! @brief Function pointer for reading raw data from the device */
40+
busio_genericdevice_read_t _read_func;
41+
/*! @brief Function pointer for writing raw data to the device */
42+
busio_genericdevice_write_t _write_func;
43+
/*! @brief Function pointer for reading a 'register' from the device */
44+
busio_genericdevice_readreg_t _readreg_func;
45+
/*! @brief Function pointer for writing a 'register' to the device */
46+
busio_genericdevice_writereg_t _writereg_func;
47+
48+
bool _begun; ///< whether we have initialized yet (in case the function needs
49+
///< to do something)
50+
51+
private:
52+
void *_obj; ///< Pointer to object instance
53+
};
54+
55+
#endif // ADAFRUIT_GENERICDEVICE_H

libraries/Adafruit_BusIO/Adafruit_I2CDevice.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Adafruit_I2CDevice.h"
22

3-
//#define DEBUG_SERIAL Serial
3+
// #define DEBUG_SERIAL Serial
44

55
/*!
66
* @brief Create an I2C device at a given address
@@ -69,7 +69,10 @@ bool Adafruit_I2CDevice::detected(void) {
6969
_wire->beginTransmission(_addr);
7070
#ifdef DEBUG_SERIAL
7171
DEBUG_SERIAL.print(F("Address 0x"));
72-
DEBUG_SERIAL.print(_addr);
72+
DEBUG_SERIAL.print(_addr, HEX);
73+
#endif
74+
#ifdef ARDUINO_ARCH_MBED
75+
_wire->write(0); // forces a write request instead of a read
7376
#endif
7477
if (_wire->endTransmission() == 0) {
7578
#ifdef DEBUG_SERIAL

libraries/Adafruit_BusIO/Adafruit_SPIDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Adafruit_SPIDevice.h"
22

3-
//#define DEBUG_SERIAL Serial
3+
// #define DEBUG_SERIAL Serial
44

55
/*!
66
* @brief Create an SPI device with the given CS pin and settings

libraries/Adafruit_BusIO/Adafruit_SPIDevice.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef uint8_t SPIClass;
2323
defined(ARDUINO_AVR_ATmega3208) || defined(ARDUINO_AVR_ATmega1609) || \
2424
defined(ARDUINO_AVR_ATmega1608) || defined(ARDUINO_AVR_ATmega809) || \
2525
defined(ARDUINO_AVR_ATmega808) || defined(ARDUINO_ARCH_ARC32) || \
26-
defined(ARDUINO_ARCH_XMC) || defined(ARDUINO_SILABS)
26+
defined(ARDUINO_ARCH_XMC)
2727

2828
typedef enum _BitOrder {
2929
SPI_BITORDER_MSBFIRST = MSBFIRST,
@@ -56,7 +56,12 @@ typedef BitOrder BusIOBitOrder;
5656
// ports set and clear registers which are atomic.
5757
// typedef volatile uint32_t BusIO_PortReg;
5858
// typedef uint32_t BusIO_PortMask;
59-
//#define BUSIO_USE_FAST_PINIO
59+
// #define BUSIO_USE_FAST_PINIO
60+
61+
#elif defined(__MBED__) || defined(__ZEPHYR__)
62+
// Boards based on RTOS cores like mbed or Zephyr are not going to expose the
63+
// low level registers needed for fast pin manipulation
64+
#undef BUSIO_USE_FAST_PINIO
6065

6166
#elif defined(ARDUINO_ARCH_XMC)
6267
#undef BUSIO_USE_FAST_PINIO
@@ -73,8 +78,8 @@ typedef uint32_t BusIO_PortMask;
7378
#define BUSIO_USE_FAST_PINIO
7479

7580
#elif (defined(__arm__) || defined(ARDUINO_FEATHER52)) && \
76-
!defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_RP2040) && \
77-
!defined(ARDUINO_SILABS)
81+
!defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_SILABS) && \
82+
!defined(ARDUINO_UNOR4_MINIMA) && !defined(ARDUINO_UNOR4_WIFI)
7883
typedef volatile uint32_t BusIO_PortReg;
7984
typedef uint32_t BusIO_PortMask;
8085
#if !defined(__ASR6501__) && !defined(__ASR6502__)

libraries/Adafruit_BusIO/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ cmake_minimum_required(VERSION 3.5)
66

77
idf_component_register(SRCS "Adafruit_I2CDevice.cpp" "Adafruit_BusIO_Register.cpp" "Adafruit_SPIDevice.cpp"
88
INCLUDE_DIRS "."
9-
REQUIRES arduino)
9+
REQUIRES arduino-esp32)
1010

1111
project(Adafruit_BusIO)

libraries/Adafruit_BusIO/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Adafruit Bus IO Library [![Build Status](https://github.com/adafruit/Adafruit_BusIO/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_BusIO/actions)
22

33

4-
This is a helper library to abstract away I2C & SPI transactions and registers
4+
This is a helper library to abstract away I2C, SPI, and 'generic transport' (e.g. UART) transactions and registers
55

66
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
77

0 commit comments

Comments
 (0)