Skip to content

Commit 6a0f8ad

Browse files
committed
Merge upstream to get updates to version 1.12.0.
2 parents 65f13b3 + c421326 commit 6a0f8ad

15 files changed

+344
-137
lines changed

.github/workflows/githubci.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [pull_request, push, repository_dispatch]
55
jobs:
66
build:
77
runs-on: ubuntu-latest
8-
8+
99
steps:
1010
- uses: actions/setup-python@v1
1111
with:
@@ -16,17 +16,17 @@ jobs:
1616
repository: adafruit/ci-arduino
1717
path: ci
1818

19-
- name: pre-install
19+
- name: Install the prerequisites
2020
run: bash ci/actions_install.sh
2121

22-
- name: test platforms
23-
run: python3 ci/build_platform.py main_platforms
22+
- name: Check for correct code formatting with clang-format
23+
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
2424

25-
- name: clang
26-
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
25+
- name: Check for correct documentation with doxygen
26+
env:
27+
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
28+
PRETTYNAME : "Adafruit Bus IO Library"
29+
run: bash ci/doxy_gen_and_deploy.sh
2730

28-
# - name: doxygen
29-
# env:
30-
# GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
31-
# PRETTYNAME : "Adafruit Bus IO Library"
32-
# run: bash ci/doxy_gen_and_deploy.sh
31+
- name: Test the code on supported platforms
32+
run: python3 ci/build_platform.py main_platforms zero feather32u4

CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Adafruit Bus IO Library
2+
# https://github.com/adafruit/Adafruit_BusIO
3+
# MIT License
4+
5+
cmake_minimum_required(VERSION 3.5)
6+
7+
idf_component_register(SRCS "Adafruit_I2CDevice.cpp" "Adafruit_BusIO_Register.cpp" "Adafruit_SPIDevice.cpp"
8+
INCLUDE_DIRS "."
9+
REQUIRES arduino)
10+
11+
project(Adafruit_BusIO)

README.md

+1-1
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 libary to abstract away I2C & SPI transactions and registers
4+
This is a helper library to abstract away I2C & SPI 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

component.mk

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMPONENT_ADD_INCLUDEDIRS = .

examples/i2corspi_register/i2corspi_register.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ void setup() {
2828
}
2929

3030
Adafruit_BusIO_Register id_reg = Adafruit_BusIO_Register(i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, 0x0F);
31-
uint8_t id;
31+
uint8_t id=0;
3232
id_reg.read(&id);
3333
Serial.print("ID register = 0x"); Serial.println(id, HEX);
3434
}
3535

3636
void loop() {
3737

38-
}
38+
}

examples/spi_register_bits/spi_register_bits.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void setup() {
139139

140140
void loop() {
141141
#if (defined( MAX31865_READY_PIN ) && (MAX31865_1_READY_PIN != -1))
142-
// Is converstion ready?
142+
// Is conversion ready?
143143
if (!digitalRead(MAX31865_READY_PIN))
144144
#else
145145
// Warant conversion is ready.

examples/spi_registers/spi_registers.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ void setup() {
1515
}
1616

1717
Adafruit_BusIO_Register id_reg = Adafruit_BusIO_Register(&spi_dev, 0x0F, ADDRBIT8_HIGH_TOREAD);
18-
uint8_t id;
18+
uint8_t id = 0;
1919
id_reg.read(&id);
2020
Serial.print("ID register = 0x"); Serial.println(id, HEX);
2121

2222
Adafruit_BusIO_Register thresh_reg = Adafruit_BusIO_Register(&spi_dev, 0x0C, ADDRBIT8_HIGH_TOREAD, 2, LSBFIRST);
23-
uint16_t thresh;
23+
uint16_t thresh = 0;
2424
thresh_reg.read(&thresh);
2525
Serial.print("Initial threshold register = 0x"); Serial.println(thresh, HEX);
2626

@@ -31,4 +31,4 @@ void setup() {
3131

3232
void loop() {
3333

34-
}
34+
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit BusIO
2-
version=1.7.2
2+
version=1.12.0
33
author=Adafruit
44
maintainer=Adafruit <info@adafruit.com>
55
sentence=This is a library for abstracting away UART, I2C and SPI interfacing

src/Adafruit_BusIO_Register.cpp

+61-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <Adafruit_BusIO_Register.h>
22

3+
#if !defined(SPI_INTERFACES_COUNT) || \
4+
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
5+
36
/*!
47
* @brief Create a register we access over an I2C Device (which defines the
58
* bus and address)
@@ -18,7 +21,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
1821
uint8_t byteorder,
1922
uint8_t address_width) {
2023
_i2cdevice = i2cdevice;
21-
_spidevice = NULL;
24+
_spidevice = nullptr;
2225
_addrwidth = address_width;
2326
_address = reg_addr;
2427
_byteorder = byteorder;
@@ -47,7 +50,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
4750
uint8_t address_width) {
4851
_spidevice = spidevice;
4952
_spiregtype = type;
50-
_i2cdevice = NULL;
53+
_i2cdevice = nullptr;
5154
_addrwidth = address_width;
5255
_address = reg_addr;
5356
_byteorder = byteorder;
@@ -56,12 +59,12 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
5659

5760
/*!
5861
* @brief Create a register we access over an I2C or SPI Device. This is a
59-
* handy function because we can pass in NULL for the unused interface, allowing
60-
* libraries to mass-define all the registers
61-
* @param i2cdevice The I2CDevice to use for underlying I2C access, if NULL
62-
* we use SPI
63-
* @param spidevice The SPIDevice to use for underlying SPI access, if NULL
64-
* we use I2C
62+
* handy function because we can pass in nullptr for the unused interface,
63+
* allowing libraries to mass-define all the registers
64+
* @param i2cdevice The I2CDevice to use for underlying I2C access, if
65+
* nullptr we use SPI
66+
* @param spidevice The SPIDevice to use for underlying SPI access, if
67+
* nullptr we use I2C
6568
* @param reg_addr The address pointer value for the I2C/SMBus/SPI register,
6669
* can be 8 or 16 bits
6770
* @param type The method we use to read/write data to SPI (which is not
@@ -101,6 +104,19 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
101104
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
102105
}
103106
if (_spidevice) {
107+
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
108+
// very special case!
109+
110+
// pass the special opcode address which we set as the high byte of the
111+
// regaddr
112+
addrbuffer[0] =
113+
(uint8_t)(_address >> 8) & ~0x01; // set bottom bit low to write
114+
// the 'actual' reg addr is the second byte then
115+
addrbuffer[1] = (uint8_t)(_address & 0xFF);
116+
// the address appears to be a byte longer
117+
return _spidevice->write(buffer, len, addrbuffer, _addrwidth + 1);
118+
}
119+
104120
if (_spiregtype == ADDRBIT8_HIGH_TOREAD) {
105121
addrbuffer[0] &= ~0x80;
106122
}
@@ -190,6 +206,19 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
190206
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
191207
}
192208
if (_spidevice) {
209+
if (_spiregtype == ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE) {
210+
// very special case!
211+
212+
// pass the special opcode address which we set as the high byte of the
213+
// regaddr
214+
addrbuffer[0] =
215+
(uint8_t)(_address >> 8) | 0x01; // set bottom bit high to read
216+
// the 'actual' reg addr is the second byte then
217+
addrbuffer[1] = (uint8_t)(_address & 0xFF);
218+
// the address appears to be a byte longer
219+
return _spidevice->write_then_read(addrbuffer, _addrwidth + 1, buffer,
220+
len);
221+
}
193222
if (_spiregtype == ADDRBIT8_HIGH_TOREAD) {
194223
addrbuffer[0] |= 0x80;
195224
}
@@ -310,3 +339,27 @@ bool Adafruit_BusIO_RegisterBits::write(uint32_t data) {
310339
* @returns The data width used when initializing the register
311340
*/
312341
uint8_t Adafruit_BusIO_Register::width(void) { return _width; }
342+
343+
/*!
344+
* @brief Set the default width of data
345+
* @param width the default width of data read from register
346+
*/
347+
void Adafruit_BusIO_Register::setWidth(uint8_t width) { _width = width; }
348+
349+
/*!
350+
* @brief Set register address
351+
* @param address the address from register
352+
*/
353+
void Adafruit_BusIO_Register::setAddress(uint16_t address) {
354+
_address = address;
355+
}
356+
357+
/*!
358+
* @brief Set the width of register address
359+
* @param address_width the width for register address
360+
*/
361+
void Adafruit_BusIO_Register::setAddressWidth(uint16_t address_width) {
362+
_addrwidth = address_width;
363+
}
364+
365+
#endif // SPI exists

src/Adafruit_BusIO_Register.h

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
#include <Adafruit_I2CDevice.h>
2-
#include <Adafruit_SPIDevice.h>
3-
#include <Arduino.h>
4-
51
#ifndef Adafruit_BusIO_Register_h
62
#define Adafruit_BusIO_Register_h
73

4+
#include <Arduino.h>
5+
6+
#if !defined(SPI_INTERFACES_COUNT) || \
7+
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
8+
9+
#include <Adafruit_I2CDevice.h>
10+
#include <Adafruit_SPIDevice.h>
11+
812
typedef enum _Adafruit_BusIO_SPIRegType {
913
ADDRBIT8_HIGH_TOREAD = 0,
1014
/*!<
@@ -15,13 +19,21 @@ typedef enum _Adafruit_BusIO_SPIRegType {
1519
*/
1620
AD8_HIGH_TOREAD_AD7_HIGH_TOINC = 1,
1721

18-
ADDRBIT8_HIGH_TOWRITE = 2,
1922
/*!<
2023
* ADDRBIT8_HIGH_TOWRITE
2124
* When writing to a register you must actually send the value 0x80 +
2225
* the register address to the device. e.g. To write to the register 0x19 the
2326
* register value 0x99 is sent and to read 0x19 is sent.
2427
*/
28+
ADDRBIT8_HIGH_TOWRITE = 2,
29+
30+
/*!<
31+
* ADDRESSED_OPCODE_LOWBIT_TO_WRITE
32+
* Used by the MCP23S series, we send 0x40 |'rd with the opcode
33+
* Then set the lowest bit to write
34+
*/
35+
ADDRESSED_OPCODE_BIT0_LOW_TO_WRITE = 3,
36+
2537
} Adafruit_BusIO_SPIRegType;
2638

2739
/*!
@@ -33,6 +45,7 @@ class Adafruit_BusIO_Register {
3345
Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr,
3446
uint8_t width = 1, uint8_t byteorder = LSBFIRST,
3547
uint8_t address_width = 1);
48+
3649
Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr,
3750
Adafruit_BusIO_SPIRegType type, uint8_t width = 1,
3851
uint8_t byteorder = LSBFIRST,
@@ -54,6 +67,10 @@ class Adafruit_BusIO_Register {
5467

5568
uint8_t width(void);
5669

70+
void setWidth(uint8_t width);
71+
void setAddress(uint16_t address);
72+
void setAddressWidth(uint16_t address_width);
73+
5774
void print(Stream *s = &Serial);
5875
void println(Stream *s = &Serial);
5976

@@ -63,7 +80,7 @@ class Adafruit_BusIO_Register {
6380
Adafruit_BusIO_SPIRegType _spiregtype;
6481
uint16_t _address;
6582
uint8_t _width, _addrwidth, _byteorder;
66-
uint8_t _buffer[4]; // we wont support anything larger than uint32 for
83+
uint8_t _buffer[4]; // we won't support anything larger than uint32 for
6784
// non-buffered read
6885
uint32_t _cached = 0;
6986
};
@@ -84,4 +101,5 @@ class Adafruit_BusIO_RegisterBits {
84101
uint8_t _bits, _shift;
85102
};
86103

104+
#endif // SPI exists
87105
#endif // BusIO_Register_h

0 commit comments

Comments
 (0)