remove travis, add actions, clang, bump version

This commit is contained in:
Lady Ada 2019-12-27 19:49:16 -05:00
parent 430a12c041
commit ddee2a2339
11 changed files with 366 additions and 234 deletions

46
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,46 @@
Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
- **For Arduino projects check these very common issues to ensure they don't apply**:
- For uploading sketches or communicating with the board make sure you're using
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
very hard to tell the difference between a data and charge cable! Try using the
cable with other devices or swapping to another cable to confirm it is not
the problem.
- **Be sure you are supplying adequate power to the board.** Check the specs of
your board and plug in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
- **Double check all soldering joints and connections.** Flakey connections
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
- **Ensure you are using an official Arduino or Adafruit board.** We can't
guarantee a clone board will have the same functionality and work as expected
with this code and don't support them.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
VERSION HERE**
- List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): **LIST REPRO STEPS BELOW**

26
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,26 @@
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
Before you open the request please review the following guidelines and tips to
help it be more easily integrated:
- **Describe the scope of your change--i.e. what the change does and what parts
of the code were modified.** This will help us understand any risks of integrating
the code.
- **Describe any known limitations with your change.** For example if the change
doesn't apply to a supported platform of the library please mention it.
- **Please run any tests or examples that can exercise your modified code.** We
strive to not break users of the code and running tests/examples helps with this
process.
Thank you again for contributing! We will try to test and integrate the change
as soon as we can, but be aware we have many GitHub repositories to manage and
can't immediately respond to every request. There is no need to bump or check in
on a pull request (it will clutter the discussion of the request).
Also don't be worried if the request is closed or not integrated--sometimes the
priorities of Adafruit's GitHub code (education, ease of use) might not match the
priorities of the pull request. Don't fret, the open source community thrives on
forks and GitHub makes it easy to keep your changes in a forked repo.
After reviewing the guidelines above you can delete this text from the pull request.

32
.github/workflows/githubci.yml vendored Normal file
View File

@ -0,0 +1,32 @@
name: Arduino Library CI
on: [pull_request, push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: adafruit/ci-arduino
path: ci
- name: pre-install
run: bash ci/actions_install.sh
- name: test platforms
run: python3 ci/build_platform.py main_platforms
- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit Bus IO Library"
run: bash ci/doxy_gen_and_deploy.sh

View File

@ -1,23 +0,0 @@
language: c
sudo: false
cache:
directories:
- ~/arduino_ide
- ~/.arduino15/packages/
git:
depth: false
quiet: true
env:
global:
- PRETTYNAME="Adafruit BusIO Library"
before_install:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
script:
- build_main_platforms
# Generate and deploy documentation
after_success:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh)
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)

View File

@ -1,15 +1,22 @@
#include <Adafruit_BusIO_Register.h> #include <Adafruit_BusIO_Register.h>
/*! /*!
* @brief Create a register we access over an I2C Device (which defines the bus and address) * @brief Create a register we access over an I2C Device (which defines the
* bus and address)
* @param i2cdevice The I2CDevice to use for underlying I2C access * @param i2cdevice The I2CDevice to use for underlying I2C access
* @param reg_addr The address pointer value for the I2C/SMBus register, can be 8 or 16 bits * @param reg_addr The address pointer value for the I2C/SMBus register, can
* be 8 or 16 bits
* @param width The width of the register data itself, defaults to 1 byte * @param width The width of the register data itself, defaults to 1 byte
* @param bitorder The bit order of the register (used when width is > 1), defaults to LSBFIRST * @param bitorder The bit order of the register (used when width is > 1),
* @param address_width The width of the register address itself, defaults to 1 byte * defaults to LSBFIRST
* @param address_width The width of the register address itself, defaults
* to 1 byte
*/ */
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr, Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
uint8_t width, uint8_t bitorder, uint8_t address_width) { uint16_t reg_addr,
uint8_t width,
uint8_t bitorder,
uint8_t address_width) {
_i2cdevice = i2cdevice; _i2cdevice = i2cdevice;
_spidevice = NULL; _spidevice = NULL;
_addrwidth = address_width; _addrwidth = address_width;
@ -19,17 +26,25 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
} }
/*! /*!
* @brief Create a register we access over an SPI Device (which defines the bus and CS pin) * @brief Create a register we access over an SPI Device (which defines the
* bus and CS pin)
* @param spidevice The SPIDevice to use for underlying I2C access * @param spidevice The SPIDevice to use for underlying I2C access
* @param reg_addr The address pointer value for the I2C/SMBus register, can be 8 or 16 bits * @param reg_addr The address pointer value for the I2C/SMBus register, can
* @param type The method we use to read/write data to SPI (which is not as well defined as I2C) * be 8 or 16 bits
* @param type The method we use to read/write data to SPI (which is not
* as well defined as I2C)
* @param width The width of the register data itself, defaults to 1 byte * @param width The width of the register data itself, defaults to 1 byte
* @param bitorder The bit order of the register (used when width is > 1), defaults to LSBFIRST * @param bitorder The bit order of the register (used when width is > 1),
* @param address_width The width of the register address itself, defaults to 1 byte * defaults to LSBFIRST
* @param address_width The width of the register address itself, defaults
* to 1 byte
*/ */
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
uint16_t reg_addr,
Adafruit_BusIO_SPIRegType type, Adafruit_BusIO_SPIRegType type,
uint8_t width, uint8_t bitorder, uint8_t address_width) { uint8_t width,
uint8_t bitorder,
uint8_t address_width) {
_spidevice = spidevice; _spidevice = spidevice;
_spiregtype = type; _spiregtype = type;
_i2cdevice = NULL; _i2cdevice = NULL;
@ -40,19 +55,27 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
} }
/*! /*!
* @brief Create a register we access over an I2C or SPI Device. This is a handy function because we * @brief Create a register we access over an I2C or SPI Device. This is a
* can pass in NULL for the unused interface, allowing libraries to mass-define all the registers * handy function because we can pass in NULL for the unused interface, allowing
* @param i2cdevice The I2CDevice to use for underlying I2C access, if NULL we use SPI * libraries to mass-define all the registers
* @param spidevice The SPIDevice to use for underlying I2C access, if NULL we use I2C * @param i2cdevice The I2CDevice to use for underlying I2C access, if NULL
* @param reg_addr The address pointer value for the I2C/SMBus register, can be 8 or 16 bits * we use SPI
* @param type The method we use to read/write data to SPI (which is not as well defined as I2C) * @param spidevice The SPIDevice to use for underlying I2C access, if NULL
* we use I2C
* @param reg_addr The address pointer value for the I2C/SMBus register, can
* be 8 or 16 bits
* @param type The method we use to read/write data to SPI (which is not
* as well defined as I2C)
* @param width The width of the register data itself, defaults to 1 byte * @param width The width of the register data itself, defaults to 1 byte
* @param bitorder The bit order of the register (used when width is > 1), defaults to LSBFIRST * @param bitorder The bit order of the register (used when width is > 1),
* @param address_width The width of the register address itself, defaults to 1 byte * defaults to LSBFIRST
* @param address_width The width of the register address itself, defaults
* to 1 byte
*/ */
Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, Adafruit_SPIDevice *spidevice, Adafruit_BusIO_Register::Adafruit_BusIO_Register(
Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, Adafruit_I2CDevice *i2cdevice, Adafruit_SPIDevice *spidevice,
uint8_t width, uint8_t bitorder, uint8_t address_width) { Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, uint8_t width,
uint8_t bitorder, uint8_t address_width) {
_spidevice = spidevice; _spidevice = spidevice;
_i2cdevice = i2cdevice; _i2cdevice = i2cdevice;
_spiregtype = type; _spiregtype = type;
@ -62,16 +85,17 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
_width = width; _width = width;
} }
/*! /*!
* @brief Write a buffer of data to the register location * @brief Write a buffer of data to the register location
* @param buffer Pointer to data to write * @param buffer Pointer to data to write
* @param len Number of bytes to write * @param len Number of bytes to write
* @return True on successful write (only really useful for I2C as SPI is uncheckable) * @return True on successful write (only really useful for I2C as SPI is
* uncheckable)
*/ */
bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) { bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF), (uint8_t)(_address>>8)}; uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
(uint8_t)(_address >> 8)};
if (_i2cdevice) { if (_i2cdevice) {
return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth); return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth);
@ -93,7 +117,8 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) {
* @brief Write up to 4 bytes of data to the register location * @brief Write up to 4 bytes of data to the register location
* @param value Data to write * @param value Data to write
* @param numbytes How many bytes from 'value' to write * @param numbytes How many bytes from 'value' to write
* @return True on successful write (only really useful for I2C as SPI is uncheckable) * @return True on successful write (only really useful for I2C as SPI is
* uncheckable)
*/ */
bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) { bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) {
if (numbytes == 0) { if (numbytes == 0) {
@ -115,7 +140,8 @@ bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) {
} }
/*! /*!
* @brief Read data from the register location. This does not do any error checking! * @brief Read data from the register location. This does not do any error
* checking!
* @return Returns 0xFFFFFFFF on failure, value otherwise * @return Returns 0xFFFFFFFF on failure, value otherwise
*/ */
uint32_t Adafruit_BusIO_Register::read(void) { uint32_t Adafruit_BusIO_Register::read(void) {
@ -137,15 +163,16 @@ uint32_t Adafruit_BusIO_Register::read(void) {
return value; return value;
} }
/*! /*!
* @brief Read a buffer of data from the register location * @brief Read a buffer of data from the register location
* @param buffer Pointer to data to read into * @param buffer Pointer to data to read into
* @param len Number of bytes to read * @param len Number of bytes to read
* @return True on successful write (only really useful for I2C as SPI is uncheckable) * @return True on successful write (only really useful for I2C as SPI is
* uncheckable)
*/ */
bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) { bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF), (uint8_t)(_address>>8)}; uint8_t addrbuffer[2] = {(uint8_t)(_address & 0xFF),
(uint8_t)(_address >> 8)};
if (_i2cdevice) { if (_i2cdevice) {
return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len); return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len);
@ -165,7 +192,8 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) {
/*! /*!
* @brief Read 2 bytes of data from the register location * @brief Read 2 bytes of data from the register location
* @param value Pointer to uint16_t variable to read into * @param value Pointer to uint16_t variable to read into
* @return True on successful write (only really useful for I2C as SPI is uncheckable) * @return True on successful write (only really useful for I2C as SPI is
* uncheckable)
*/ */
bool Adafruit_BusIO_Register::read(uint16_t *value) { bool Adafruit_BusIO_Register::read(uint16_t *value) {
if (!read(_buffer, 2)) { if (!read(_buffer, 2)) {
@ -187,7 +215,8 @@ bool Adafruit_BusIO_Register::read(uint16_t *value) {
/*! /*!
* @brief Read 1 byte of data from the register location * @brief Read 1 byte of data from the register location
* @param value Pointer to uint8_t variable to read into * @param value Pointer to uint8_t variable to read into
* @return True on successful write (only really useful for I2C as SPI is uncheckable) * @return True on successful write (only really useful for I2C as SPI is
* uncheckable)
*/ */
bool Adafruit_BusIO_Register::read(uint8_t *value) { bool Adafruit_BusIO_Register::read(uint8_t *value) {
if (!read(_buffer, 1)) { if (!read(_buffer, 1)) {
@ -204,7 +233,8 @@ bool Adafruit_BusIO_Register::read(uint8_t *value) {
*/ */
void Adafruit_BusIO_Register::print(Stream *s) { void Adafruit_BusIO_Register::print(Stream *s) {
uint32_t val = read(); uint32_t val = read();
s->print("0x"); s->print(val, HEX); s->print("0x");
s->print(val, HEX);
} }
/*! /*!
@ -216,14 +246,15 @@ void Adafruit_BusIO_Register::println(Stream *s) {
s->println(); s->println();
} }
/*! /*!
* @brief Create a slice of the register that we can address without touching other bits * @brief Create a slice of the register that we can address without
* touching other bits
* @param reg The Adafruit_BusIO_Register which defines the bus/register * @param reg The Adafruit_BusIO_Register which defines the bus/register
* @param bits The number of bits wide we are slicing * @param bits The number of bits wide we are slicing
* @param shift The number of bits that our bit-slice is shifted from LSB * @param shift The number of bits that our bit-slice is shifted from LSB
*/ */
Adafruit_BusIO_RegisterBits::Adafruit_BusIO_RegisterBits(Adafruit_BusIO_Register *reg, uint8_t bits, uint8_t shift) { Adafruit_BusIO_RegisterBits::Adafruit_BusIO_RegisterBits(
Adafruit_BusIO_Register *reg, uint8_t bits, uint8_t shift) {
_register = reg; _register = reg;
_bits = bits; _bits = bits;
_shift = shift; _shift = shift;
@ -239,7 +270,6 @@ uint32_t Adafruit_BusIO_RegisterBits::read(void) {
return val & ((1 << (_bits)) - 1); return val & ((1 << (_bits)) - 1);
} }
/*! /*!
* @brief Write 4 bytes of data to the register * @brief Write 4 bytes of data to the register
* @param data The 4 bytes to write * @param data The 4 bytes to write

View File

@ -2,7 +2,6 @@
#include <Adafruit_SPIDevice.h> #include <Adafruit_SPIDevice.h>
#include <Arduino.h> #include <Arduino.h>
#ifndef Adafruit_BusIO_Register_h #ifndef Adafruit_BusIO_Register_h
#define Adafruit_BusIO_Register_h #define Adafruit_BusIO_Register_h
@ -12,7 +11,8 @@ typedef enum _Adafruit_BusIO_SPIRegType {
} Adafruit_BusIO_SPIRegType; } Adafruit_BusIO_SPIRegType;
/*! /*!
* @brief The class which defines a device register (a location to read/write data from) * @brief The class which defines a device register (a location to read/write
* data from)
*/ */
class Adafruit_BusIO_Register { class Adafruit_BusIO_Register {
public: public:
@ -20,14 +20,13 @@ class Adafruit_BusIO_Register {
uint8_t width = 1, uint8_t bitorder = LSBFIRST, uint8_t width = 1, uint8_t bitorder = LSBFIRST,
uint8_t address_width = 1); uint8_t address_width = 1);
Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr,
Adafruit_BusIO_SPIRegType type, Adafruit_BusIO_SPIRegType type, uint8_t width = 1,
uint8_t width=1, uint8_t bitorder=LSBFIRST, uint8_t bitorder = LSBFIRST,
uint8_t address_width = 1); uint8_t address_width = 1);
Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
Adafruit_SPIDevice *spidevice, Adafruit_SPIDevice *spidevice,
Adafruit_BusIO_SPIRegType type, Adafruit_BusIO_SPIRegType type, uint16_t reg_addr,
uint16_t reg_addr,
uint8_t width = 1, uint8_t bitorder = LSBFIRST, uint8_t width = 1, uint8_t bitorder = LSBFIRST,
uint8_t address_width = 1); uint8_t address_width = 1);
@ -49,22 +48,24 @@ class Adafruit_BusIO_Register {
Adafruit_BusIO_SPIRegType _spiregtype; Adafruit_BusIO_SPIRegType _spiregtype;
uint16_t _address; uint16_t _address;
uint8_t _width, _addrwidth, _bitorder; uint8_t _width, _addrwidth, _bitorder;
uint8_t _buffer[4]; // we wont support anything larger than uint32 for non-buffered read uint8_t _buffer[4]; // we wont support anything larger than uint32 for
// non-buffered read
}; };
/*! /*!
* @brief The class which defines a slice of bits from within a device register (a location to read/write data from) * @brief The class which defines a slice of bits from within a device register
* (a location to read/write data from)
*/ */
class Adafruit_BusIO_RegisterBits { class Adafruit_BusIO_RegisterBits {
public: public:
Adafruit_BusIO_RegisterBits(Adafruit_BusIO_Register *reg, uint8_t bits, uint8_t shift); Adafruit_BusIO_RegisterBits(Adafruit_BusIO_Register *reg, uint8_t bits,
uint8_t shift);
void write(uint32_t value); void write(uint32_t value);
uint32_t read(void); uint32_t read(void);
private: private:
Adafruit_BusIO_Register *_register; Adafruit_BusIO_Register *_register;
uint8_t _bits, _shift; uint8_t _bits, _shift;
}; };
#endif // BusIO_Register_h #endif // BusIO_Register_h

View File

@ -21,8 +21,9 @@ Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) {
/*! /*!
* @brief Initializes and does basic address detection * @brief Initializes and does basic address detection
* @param addr_detect Whether we should attempt to detect the I2C address with a scan. * @param addr_detect Whether we should attempt to detect the I2C address
* 99% of sensors/devices don't mind but once in a while, they spaz on a scan! * with a scan. 99% of sensors/devices don't mind but once in a while, they spaz
* on a scan!
* @return True if I2C initialized and a device with the addr found * @return True if I2C initialized and a device with the addr found
*/ */
bool Adafruit_I2CDevice::begin(bool addr_detect) { bool Adafruit_I2CDevice::begin(bool addr_detect) {
@ -35,7 +36,6 @@ bool Adafruit_I2CDevice::begin(bool addr_detect) {
return true; return true;
} }
/*! /*!
* @brief Scans I2C for the address - note will give a false-positive * @brief Scans I2C for the address - note will give a false-positive
* if there's no pullups on I2C * if there's no pullups on I2C
@ -56,16 +56,18 @@ bool Adafruit_I2CDevice::detected(void) {
} }
/*! /*!
* @brief Write a buffer or two to the I2C device. Cannot be more than maxBufferSize() bytes. * @brief Write a buffer or two to the I2C device. Cannot be more than
* maxBufferSize() bytes.
* @param buffer Pointer to buffer of data to write * @param buffer Pointer to buffer of data to write
* @param len Number of bytes from buffer to write * @param len Number of bytes from buffer to write
* @param prefix_buffer Pointer to optional array of data to write before buffer. * @param prefix_buffer Pointer to optional array of data to write before
* Cannot be more than maxBufferSize() bytes. * buffer. Cannot be more than maxBufferSize() bytes.
* @param prefix_len Number of bytes from prefix buffer to write * @param prefix_len Number of bytes from prefix buffer to write
* @param stop Whether to send an I2C STOP signal on write * @param stop Whether to send an I2C STOP signal on write
* @return True if write was successful, otherwise false. * @return True if write was successful, otherwise false.
*/ */
bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, uint8_t *prefix_buffer, size_t prefix_len) { bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop,
uint8_t *prefix_buffer, size_t prefix_len) {
if ((len + prefix_len) > maxBufferSize()) { if ((len + prefix_len) > maxBufferSize()) {
// currently not guaranteed to work if more than 32 bytes! // currently not guaranteed to work if more than 32 bytes!
// we will need to find out if some platforms have larger // we will need to find out if some platforms have larger
@ -133,7 +135,6 @@ bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, uint8_t *
} }
} }
/*! /*!
* @brief Read from I2C into a buffer from the I2C device. * @brief Read from I2C into a buffer from the I2C device.
* Cannot be more than maxBufferSize() bytes. * Cannot be more than maxBufferSize() bytes.
@ -183,7 +184,6 @@ bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) {
return true; return true;
} }
/*! /*!
* @brief Write some data, then read some data from I2C into another buffer. * @brief Write some data, then read some data from I2C into another buffer.
* Cannot be more than maxBufferSize() bytes. The buffers can point to * Cannot be more than maxBufferSize() bytes. The buffers can point to
@ -195,7 +195,9 @@ bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) {
* @param stop Whether to send an I2C STOP signal between the write and read * @param stop Whether to send an I2C STOP signal between the write and read
* @return True if write & read was successful, otherwise false. * @return True if write & read was successful, otherwise false.
*/ */
bool Adafruit_I2CDevice::write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop) { bool Adafruit_I2CDevice::write_then_read(uint8_t *write_buffer,
size_t write_len, uint8_t *read_buffer,
size_t read_len, bool stop) {
if (!write(write_buffer, write_len, stop)) { if (!write(write_buffer, write_len, stop)) {
return false; return false;
} }
@ -203,11 +205,8 @@ bool Adafruit_I2CDevice::write_then_read(uint8_t *write_buffer, size_t write_len
return read(read_buffer, read_len); return read(read_buffer, read_len);
} }
/*! /*!
* @brief Returns the 7-bit address of this device * @brief Returns the 7-bit address of this device
* @return The 7-bit address of this device * @return The 7-bit address of this device
*/ */
uint8_t Adafruit_I2CDevice::address(void) { uint8_t Adafruit_I2CDevice::address(void) { return _addr; }
return _addr;
}

View File

@ -12,8 +12,11 @@ class Adafruit_I2CDevice {
bool detected(void); bool detected(void);
bool read(uint8_t *buffer, size_t len, bool stop = true); bool read(uint8_t *buffer, size_t len, bool stop = true);
bool write(uint8_t *buffer, size_t len, bool stop=true, uint8_t *prefix_buffer=NULL, size_t prefix_len=0); bool write(uint8_t *buffer, size_t len, bool stop = true,
bool write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop=false); uint8_t *prefix_buffer = NULL, size_t prefix_len = 0);
bool write_then_read(uint8_t *write_buffer, size_t write_len,
uint8_t *read_buffer, size_t read_len,
bool stop = false);
/*! @brief How many bytes we can read in a transaction /*! @brief How many bytes we can read in a transaction
* @return The size of the Wire receive/transmit buffer */ * @return The size of the Wire receive/transmit buffer */

View File

@ -7,11 +7,14 @@
* @brief Create an SPI device with the given CS pin and settins * @brief Create an SPI device with the given CS pin and settins
* @param cspin The arduino pin number to use for chip select * @param cspin The arduino pin number to use for chip select
* @param freq The SPI clock frequency to use, defaults to 1MHz * @param freq The SPI clock frequency to use, defaults to 1MHz
* @param dataOrder The SPI data order to use for bits within each byte, defaults to SPI_BITORDER_MSBFIRST * @param dataOrder The SPI data order to use for bits within each byte,
* defaults to SPI_BITORDER_MSBFIRST
* @param dataMode The SPI mode to use, defaults to SPI_MODE0 * @param dataMode The SPI mode to use, defaults to SPI_MODE0
* @param theSPI The SPI bus to use, defaults to &theSPI * @param theSPI The SPI bus to use, defaults to &theSPI
*/ */
Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, uint32_t freq, BitOrder dataOrder, uint8_t dataMode, SPIClass *theSPI) { Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, uint32_t freq,
BitOrder dataOrder, uint8_t dataMode,
SPIClass *theSPI) {
_cs = cspin; _cs = cspin;
_sck = _mosi = _miso = -1; _sck = _mosi = _miso = -1;
_spi = theSPI; _spi = theSPI;
@ -26,14 +29,19 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, uint32_t freq, BitOrder dat
* @brief Create an SPI device with the given CS pin and settins * @brief Create an SPI device with the given CS pin and settins
* @param cspin The arduino pin number to use for chip select * @param cspin The arduino pin number to use for chip select
* @param sckpin The arduino pin number to use for SCK * @param sckpin The arduino pin number to use for SCK
* @param misopin The arduino pin number to use for MISO, set to -1 if not used * @param misopin The arduino pin number to use for MISO, set to -1 if not
* @param mosipin The arduino pin number to use for MOSI, set to -1 if not used * used
* @param mosipin The arduino pin number to use for MOSI, set to -1 if not
* used
* @param freq The SPI clock frequency to use, defaults to 1MHz * @param freq The SPI clock frequency to use, defaults to 1MHz
* @param dataOrder The SPI data order to use for bits within each byte, defaults to SPI_BITORDER_MSBFIRST * @param dataOrder The SPI data order to use for bits within each byte,
* defaults to SPI_BITORDER_MSBFIRST
* @param dataMode The SPI mode to use, defaults to SPI_MODE0 * @param dataMode The SPI mode to use, defaults to SPI_MODE0
*/ */
Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, int8_t sckpin, int8_t misopin, int8_t mosipin, Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, int8_t sckpin,
uint32_t freq, BitOrder dataOrder, uint8_t dataMode) { int8_t misopin, int8_t mosipin,
uint32_t freq, BitOrder dataOrder,
uint8_t dataMode) {
_cs = cspin; _cs = cspin;
_sck = sckpin; _sck = sckpin;
_miso = misopin; _miso = misopin;
@ -46,10 +54,10 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, int8_t sckpin, int8_t misop
_spi = NULL; _spi = NULL;
} }
/*! /*!
* @brief Initializes SPI bus and sets CS pin high * @brief Initializes SPI bus and sets CS pin high
* @return Always returns true because there's no way to test success of SPI init * @return Always returns true because there's no way to test success of SPI
* init
*/ */
bool Adafruit_SPIDevice::begin(void) { bool Adafruit_SPIDevice::begin(void) {
pinMode(_cs, OUTPUT); pinMode(_cs, OUTPUT);
@ -78,7 +86,6 @@ bool Adafruit_SPIDevice::begin(void) {
return true; return true;
} }
/*! /*!
* @brief Transfer (send/receive) one byte over hard/soft SPI * @brief Transfer (send/receive) one byte over hard/soft SPI
* @param buffer The buffer to send and receive at the same time * @param buffer The buffer to send and receive at the same time
@ -139,8 +146,6 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
return; return;
} }
/*! /*!
* @brief Transfer (send/receive) one byte over hard/soft SPI * @brief Transfer (send/receive) one byte over hard/soft SPI
* @param send The byte to send * @param send The byte to send
@ -152,16 +157,18 @@ uint8_t Adafruit_SPIDevice::transfer(uint8_t send) {
return data; return data;
} }
/*! /*!
* @brief Write a buffer or two to the SPI device. * @brief Write a buffer or two to the SPI device.
* @param buffer Pointer to buffer of data to write * @param buffer Pointer to buffer of data to write
* @param len Number of bytes from buffer to write * @param len Number of bytes from buffer to write
* @param prefix_buffer Pointer to optional array of data to write before buffer. * @param prefix_buffer Pointer to optional array of data to write before
* buffer.
* @param prefix_len Number of bytes from prefix buffer to write * @param prefix_len Number of bytes from prefix buffer to write
* @return Always returns true because there's no way to test success of SPI writes * @return Always returns true because there's no way to test success of SPI
* writes
*/ */
bool Adafruit_SPIDevice::write(uint8_t *buffer, size_t len, uint8_t *prefix_buffer, size_t prefix_len) { bool Adafruit_SPIDevice::write(uint8_t *buffer, size_t len,
uint8_t *prefix_buffer, size_t prefix_len) {
if (_spi) { if (_spi) {
_spi->beginTransaction(*_spiSetting); _spi->beginTransaction(*_spiSetting);
} }
@ -207,8 +214,10 @@ bool Adafruit_SPIDevice::write(uint8_t *buffer, size_t len, uint8_t *prefix_buff
* @brief Read from SPI into a buffer from the SPI device. * @brief Read from SPI into a buffer from the SPI device.
* @param buffer Pointer to buffer of data to read into * @param buffer Pointer to buffer of data to read into
* @param len Number of bytes from buffer to read. * @param len Number of bytes from buffer to read.
* @param sendvalue The 8-bits of data to write when doing the data read, defaults to 0xFF * @param sendvalue The 8-bits of data to write when doing the data read,
* @return Always returns true because there's no way to test success of SPI writes * defaults to 0xFF
* @return Always returns true because there's no way to test success of SPI
* writes
*/ */
bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) { bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
memset(buffer, sendvalue, len); // clear out existing buffer memset(buffer, sendvalue, len); // clear out existing buffer
@ -239,17 +248,22 @@ bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
return true; return true;
} }
/*! /*!
* @brief Write some data, then read some data from SPI into another buffer. The buffers can point to same/overlapping locations. This does not transmit-receive at the same time! * @brief Write some data, then read some data from SPI into another buffer.
* The buffers can point to same/overlapping locations. This does not
* transmit-receive at the same time!
* @param write_buffer Pointer to buffer of data to write from * @param write_buffer Pointer to buffer of data to write from
* @param write_len Number of bytes from buffer to write. * @param write_len Number of bytes from buffer to write.
* @param read_buffer Pointer to buffer of data to read into. * @param read_buffer Pointer to buffer of data to read into.
* @param read_len Number of bytes from buffer to read. * @param read_len Number of bytes from buffer to read.
* @param sendvalue The 8-bits of data to write when doing the data read, defaults to 0xFF * @param sendvalue The 8-bits of data to write when doing the data read,
* @return Always returns true because there's no way to test success of SPI writes * defaults to 0xFF
* @return Always returns true because there's no way to test success of SPI
* writes
*/ */
bool Adafruit_SPIDevice::write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, uint8_t sendvalue) { bool Adafruit_SPIDevice::write_then_read(uint8_t *write_buffer,
size_t write_len, uint8_t *read_buffer,
size_t read_len, uint8_t sendvalue) {
if (_spi) { if (_spi) {
_spi->beginTransaction(*_spiSetting); _spi->beginTransaction(*_spiSetting);
} }

View File

@ -4,14 +4,16 @@
#define Adafruit_SPIDevice_h #define Adafruit_SPIDevice_h
// some modern SPI definitions don't have BitOrder enum // some modern SPI definitions don't have BitOrder enum
#if (defined(__AVR__) && !defined(ARDUINO_ARCH_MEGAAVR)) || defined(ESP8266) || defined(TEENSYDUINO) #if (defined(__AVR__) && !defined(ARDUINO_ARCH_MEGAAVR)) || \
defined(ESP8266) || defined(TEENSYDUINO)
typedef enum _BitOrder { typedef enum _BitOrder {
SPI_BITORDER_MSBFIRST = MSBFIRST, SPI_BITORDER_MSBFIRST = MSBFIRST,
SPI_BITORDER_LSBFIRST = LSBFIRST, SPI_BITORDER_LSBFIRST = LSBFIRST,
} BitOrder; } BitOrder;
#endif #endif
// some modern SPI definitions don't have BitOrder enum and have different SPI mode defines // some modern SPI definitions don't have BitOrder enum and have different SPI
// mode defines
#if defined(ESP32) #if defined(ESP32)
typedef enum _BitOrder { typedef enum _BitOrder {
SPI_BITORDER_MSBFIRST = SPI_MSBFIRST, SPI_BITORDER_MSBFIRST = SPI_MSBFIRST,
@ -20,7 +22,9 @@ typedef enum _BitOrder {
#endif #endif
// Some platforms have a BitOrder enum but its named MSBFIRST/LSBFIRST // Some platforms have a BitOrder enum but its named MSBFIRST/LSBFIRST
#if defined(ARDUINO_ARCH_SAMD) || defined(__SAM3X8E__) || defined(NRF52_SERIES) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) || defined(ARDUINO_ARCH_MEGAAVR) || defined(_STM32_DEF_) #if defined(ARDUINO_ARCH_SAMD) || defined(__SAM3X8E__) || \
defined(NRF52_SERIES) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) || \
defined(ARDUINO_ARCH_MEGAAVR) || defined(_STM32_DEF_)
#define SPI_BITORDER_MSBFIRST MSBFIRST #define SPI_BITORDER_MSBFIRST MSBFIRST
#define SPI_BITORDER_LSBFIRST LSBFIRST #define SPI_BITORDER_LSBFIRST LSBFIRST
#endif #endif
@ -28,11 +32,9 @@ typedef enum _BitOrder {
///< The class which defines how we will talk to this device over SPI ///< The class which defines how we will talk to this device over SPI
class Adafruit_SPIDevice { class Adafruit_SPIDevice {
public: public:
Adafruit_SPIDevice(int8_t cspin, Adafruit_SPIDevice(int8_t cspin, uint32_t freq = 1000000,
uint32_t freq=1000000,
BitOrder dataOrder = SPI_BITORDER_MSBFIRST, BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
uint8_t dataMode=SPI_MODE0, uint8_t dataMode = SPI_MODE0, SPIClass *theSPI = &SPI);
SPIClass *theSPI=&SPI);
Adafruit_SPIDevice(int8_t cspin, int8_t sck, int8_t miso, int8_t mosi, Adafruit_SPIDevice(int8_t cspin, int8_t sck, int8_t miso, int8_t mosi,
uint32_t freq = 1000000, uint32_t freq = 1000000,
@ -41,14 +43,16 @@ class Adafruit_SPIDevice {
bool begin(void); bool begin(void);
bool read(uint8_t *buffer, size_t len, uint8_t sendvalue = 0xFF); bool read(uint8_t *buffer, size_t len, uint8_t sendvalue = 0xFF);
bool write(uint8_t *buffer, size_t len, uint8_t *prefix_buffer=NULL, size_t prefix_len=0); bool write(uint8_t *buffer, size_t len, uint8_t *prefix_buffer = NULL,
bool write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, uint8_t sendvalue=0xFF); size_t prefix_len = 0);
bool write_then_read(uint8_t *write_buffer, size_t write_len,
uint8_t *read_buffer, size_t read_len,
uint8_t sendvalue = 0xFF);
uint8_t transfer(uint8_t send); uint8_t transfer(uint8_t send);
void transfer(uint8_t *buffer, size_t len); void transfer(uint8_t *buffer, size_t len);
private: private:
SPIClass *_spi; SPIClass *_spi;
SPISettings *_spiSetting; SPISettings *_spiSetting;
uint32_t _freq; uint32_t _freq;

View File

@ -1,5 +1,5 @@
name=Adafruit BusIO name=Adafruit BusIO
version=1.1.0 version=1.1.1
author=Adafruit author=Adafruit
maintainer=Adafruit <info@adafruit.com> maintainer=Adafruit <info@adafruit.com>
sentence=This is a library for abstracting away UART, I2C and SPI interfacing sentence=This is a library for abstracting away UART, I2C and SPI interfacing