Critical update

main
lightaprs 2022-06-29 23:01:39 +03:00
rodzic 4b32fa49cc
commit 8565303f14
13 zmienionych plików z 205 dodań i 107 usunięć

Wyświetl plik

@ -16,17 +16,17 @@ jobs:
repository: adafruit/ci-arduino repository: adafruit/ci-arduino
path: ci path: ci
- name: pre-install - name: Install the prerequisites
run: bash ci/actions_install.sh run: bash ci/actions_install.sh
- name: test platforms - name: Check for correct code formatting with clang-format
run: python3 ci/build_platform.py main_platforms run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
- name: clang - name: Check for correct documentation with doxygen
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
- name: doxygen
env: env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit Bus IO Library" PRETTYNAME : "Adafruit Bus IO Library"
run: bash ci/doxy_gen_and_deploy.sh run: bash ci/doxy_gen_and_deploy.sh
- name: Test the code on supported platforms
run: python3 ci/build_platform.py main_platforms zero feather32u4

Wyświetl plik

@ -21,7 +21,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice,
uint8_t byteorder, uint8_t byteorder,
uint8_t address_width) { uint8_t address_width) {
_i2cdevice = i2cdevice; _i2cdevice = i2cdevice;
_spidevice = NULL; _spidevice = nullptr;
_addrwidth = address_width; _addrwidth = address_width;
_address = reg_addr; _address = reg_addr;
_byteorder = byteorder; _byteorder = byteorder;
@ -50,7 +50,7 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
uint8_t address_width) { uint8_t address_width) {
_spidevice = spidevice; _spidevice = spidevice;
_spiregtype = type; _spiregtype = type;
_i2cdevice = NULL; _i2cdevice = nullptr;
_addrwidth = address_width; _addrwidth = address_width;
_address = reg_addr; _address = reg_addr;
_byteorder = byteorder; _byteorder = byteorder;
@ -59,12 +59,12 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice,
/*! /*!
* @brief Create a register we access over an I2C or SPI Device. This is a * @brief Create a register we access over an I2C or SPI Device. This is a
* handy function because we can pass in NULL for the unused interface, allowing * handy function because we can pass in nullptr for the unused interface,
* libraries to mass-define all the registers * allowing libraries to mass-define all the registers
* @param i2cdevice The I2CDevice to use for underlying I2C access, if NULL * @param i2cdevice The I2CDevice to use for underlying I2C access, if
* we use SPI * nullptr we use SPI
* @param spidevice The SPIDevice to use for underlying SPI access, if NULL * @param spidevice The SPIDevice to use for underlying SPI access, if
* we use I2C * nullptr we use I2C
* @param reg_addr The address pointer value for the I2C/SMBus/SPI register, * @param reg_addr The address pointer value for the I2C/SMBus/SPI register,
* can be 8 or 16 bits * can be 8 or 16 bits
* @param type The method we use to read/write data to SPI (which is not * @param type The method we use to read/write data to SPI (which is not

Wyświetl plik

@ -1,12 +1,13 @@
#include <Adafruit_I2CDevice.h> #ifndef Adafruit_BusIO_Register_h
#include <Adafruit_SPIDevice.h> #define Adafruit_BusIO_Register_h
#include <Arduino.h> #include <Arduino.h>
#if !defined(SPI_INTERFACES_COUNT) || \ #if !defined(SPI_INTERFACES_COUNT) || \
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
#ifndef Adafruit_BusIO_Register_h #include <Adafruit_I2CDevice.h>
#define Adafruit_BusIO_Register_h #include <Adafruit_SPIDevice.h>
typedef enum _Adafruit_BusIO_SPIRegType { typedef enum _Adafruit_BusIO_SPIRegType {
ADDRBIT8_HIGH_TOREAD = 0, ADDRBIT8_HIGH_TOREAD = 0,
@ -79,7 +80,7 @@ private:
Adafruit_BusIO_SPIRegType _spiregtype; Adafruit_BusIO_SPIRegType _spiregtype;
uint16_t _address; uint16_t _address;
uint8_t _width, _addrwidth, _byteorder; uint8_t _width, _addrwidth, _byteorder;
uint8_t _buffer[4]; // we wont support anything larger than uint32 for uint8_t _buffer[4]; // we won't support anything larger than uint32 for
// non-buffered read // non-buffered read
uint32_t _cached = 0; uint32_t _cached = 0;
}; };
@ -100,6 +101,5 @@ private:
uint8_t _bits, _shift; uint8_t _bits, _shift;
}; };
#endif // BusIO_Register_h
#endif // SPI exists #endif // SPI exists
#endif // BusIO_Register_h

Wyświetl plik

@ -1,5 +1,4 @@
#include <Adafruit_I2CDevice.h> #include "Adafruit_I2CDevice.h"
#include <Arduino.h>
//#define DEBUG_SERIAL Serial //#define DEBUG_SERIAL Serial
@ -14,6 +13,8 @@ Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) {
_begun = false; _begun = false;
#ifdef ARDUINO_ARCH_SAMD #ifdef ARDUINO_ARCH_SAMD
_maxBufferSize = 250; // as defined in Wire.h's RingBuffer _maxBufferSize = 250; // as defined in Wire.h's RingBuffer
#elif defined(ESP32)
_maxBufferSize = I2C_BUFFER_LENGTH;
#else #else
_maxBufferSize = 32; _maxBufferSize = 32;
#endif #endif
@ -36,6 +37,23 @@ bool Adafruit_I2CDevice::begin(bool addr_detect) {
return true; return true;
} }
/*!
* @brief De-initialize device, turn off the Wire interface
*/
void Adafruit_I2CDevice::end(void) {
// Not all port implement Wire::end(), such as
// - ESP8266
// - AVR core without WIRE_HAS_END
// - ESP32: end() is implemented since 2.0.1 which is latest at the moment.
// Temporarily disable for now to give time for user to update.
#if !(defined(ESP8266) || \
(defined(ARDUINO_ARCH_AVR) && !defined(WIRE_HAS_END)) || \
defined(ARDUINO_ARCH_ESP32))
_wire->end();
_begun = false;
#endif
}
/*! /*!
* @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
@ -90,7 +108,7 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
_wire->beginTransmission(_addr); _wire->beginTransmission(_addr);
// Write the prefix data (usually an address) // Write the prefix data (usually an address)
if ((prefix_len != 0) && (prefix_buffer != NULL)) { if ((prefix_len != 0) && (prefix_buffer != nullptr)) {
if (_wire->write(prefix_buffer, prefix_len) != prefix_len) { if (_wire->write(prefix_buffer, prefix_len) != prefix_len) {
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
DEBUG_SERIAL.println(F("\tI2CDevice failed to write")); DEBUG_SERIAL.println(F("\tI2CDevice failed to write"));
@ -112,7 +130,7 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
DEBUG_SERIAL.print(F("\tI2CWRITE @ 0x")); DEBUG_SERIAL.print(F("\tI2CWRITE @ 0x"));
DEBUG_SERIAL.print(_addr, HEX); DEBUG_SERIAL.print(_addr, HEX);
DEBUG_SERIAL.print(F(" :: ")); DEBUG_SERIAL.print(F(" :: "));
if ((prefix_len != 0) && (prefix_buffer != NULL)) { if ((prefix_len != 0) && (prefix_buffer != nullptr)) {
for (uint16_t i = 0; i < prefix_len; i++) { for (uint16_t i = 0; i < prefix_len; i++) {
DEBUG_SERIAL.print(F("0x")); DEBUG_SERIAL.print(F("0x"));
DEBUG_SERIAL.print(prefix_buffer[i], HEX); DEBUG_SERIAL.print(prefix_buffer[i], HEX);
@ -127,22 +145,21 @@ bool Adafruit_I2CDevice::write(const uint8_t *buffer, size_t len, bool stop,
DEBUG_SERIAL.println(); DEBUG_SERIAL.println();
} }
} }
DEBUG_SERIAL.println();
#endif
#ifdef DEBUG_SERIAL if (stop) {
DEBUG_SERIAL.print("Stop: "); DEBUG_SERIAL.print("\tSTOP");
DEBUG_SERIAL.println(stop); }
#endif #endif
if (_wire->endTransmission(stop) == 0) { if (_wire->endTransmission(stop) == 0) {
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
DEBUG_SERIAL.println();
// DEBUG_SERIAL.println("Sent!"); // DEBUG_SERIAL.println("Sent!");
#endif #endif
return true; return true;
} else { } else {
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
DEBUG_SERIAL.println("Failed to send!"); DEBUG_SERIAL.println("\tFailed to send!");
#endif #endif
return false; return false;
} }

Wyświetl plik

@ -1,19 +1,21 @@
#include <Wire.h>
#ifndef Adafruit_I2CDevice_h #ifndef Adafruit_I2CDevice_h
#define Adafruit_I2CDevice_h #define Adafruit_I2CDevice_h
#include <Arduino.h>
#include <Wire.h>
///< The class which defines how we will talk to this device over I2C ///< The class which defines how we will talk to this device over I2C
class Adafruit_I2CDevice { class Adafruit_I2CDevice {
public: public:
Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire); Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
uint8_t address(void); uint8_t address(void);
bool begin(bool addr_detect = true); bool begin(bool addr_detect = true);
void end(void);
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(const uint8_t *buffer, size_t len, bool stop = true, bool write(const uint8_t *buffer, size_t len, bool stop = true,
const uint8_t *prefix_buffer = NULL, size_t prefix_len = 0); const uint8_t *prefix_buffer = nullptr, size_t prefix_len = 0);
bool write_then_read(const uint8_t *write_buffer, size_t write_len, bool write_then_read(const uint8_t *write_buffer, size_t write_len,
uint8_t *read_buffer, size_t read_len, uint8_t *read_buffer, size_t read_len,
bool stop = false); bool stop = false);

Wyświetl plik

@ -1,7 +1,9 @@
#include "Adafruit_BusIO_Register.h"
#ifndef _ADAFRUIT_I2C_REGISTER_H_ #ifndef _ADAFRUIT_I2C_REGISTER_H_
#define _ADAFRUIT_I2C_REGISTER_H_ #define _ADAFRUIT_I2C_REGISTER_H_
#include <Adafruit_BusIO_Register.h>
#include <Arduino.h>
typedef Adafruit_BusIO_Register Adafruit_I2CRegister; typedef Adafruit_BusIO_Register Adafruit_I2CRegister;
typedef Adafruit_BusIO_RegisterBits Adafruit_I2CRegisterBits; typedef Adafruit_BusIO_RegisterBits Adafruit_I2CRegisterBits;

Wyświetl plik

@ -1,5 +1,4 @@
#include <Adafruit_SPIDevice.h> #include "Adafruit_SPIDevice.h"
#include <Arduino.h>
#if !defined(SPI_INTERFACES_COUNT) || \ #if !defined(SPI_INTERFACES_COUNT) || \
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0)) (defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))
@ -7,7 +6,7 @@
//#define DEBUG_SERIAL Serial //#define DEBUG_SERIAL Serial
/*! /*!
* @brief Create an SPI device with the given CS pin and settins * @brief Create an SPI device with the given CS pin and settings
* @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, * @param dataOrder The SPI data order to use for bits within each byte,
@ -29,7 +28,7 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, uint32_t freq,
} }
/*! /*!
* @brief Create an SPI device with the given CS pin and settins * @brief Create an SPI device with the given CS pin and settings
* @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 * @param misopin The arduino pin number to use for MISO, set to -1 if not
@ -70,18 +69,13 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, int8_t sckpin,
_dataMode = dataMode; _dataMode = dataMode;
_begun = false; _begun = false;
_spiSetting = new SPISettings(freq, dataOrder, dataMode); _spiSetting = new SPISettings(freq, dataOrder, dataMode);
_spi = NULL; _spi = nullptr;
} }
/*! /*!
* @brief Release memory allocated in constructors * @brief Release memory allocated in constructors
*/ */
Adafruit_SPIDevice::~Adafruit_SPIDevice() { Adafruit_SPIDevice::~Adafruit_SPIDevice() { delete _spiSetting; }
if (_spiSetting) {
delete _spiSetting;
_spiSetting = nullptr;
}
}
/*! /*!
* @brief Initializes SPI bus and sets CS pin high * @brief Initializes SPI bus and sets CS pin high
@ -89,8 +83,10 @@ Adafruit_SPIDevice::~Adafruit_SPIDevice() {
* init * init
*/ */
bool Adafruit_SPIDevice::begin(void) { bool Adafruit_SPIDevice::begin(void) {
pinMode(_cs, OUTPUT); if (_cs != -1) {
digitalWrite(_cs, HIGH); pinMode(_cs, OUTPUT);
digitalWrite(_cs, HIGH);
}
if (_spi) { // hardware SPI if (_spi) { // hardware SPI
_spi->begin(); _spi->begin();
@ -118,7 +114,8 @@ bool Adafruit_SPIDevice::begin(void) {
} }
/*! /*!
* @brief Transfer (send/receive) one byte over hard/soft SPI * @brief Transfer (send/receive) a buffer over hard/soft SPI, without
* transaction management
* @param buffer The buffer to send and receive at the same time * @param buffer The buffer to send and receive at the same time
* @param len The number of bytes to transfer * @param len The number of bytes to transfer
*/ */
@ -127,7 +124,7 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
// hardware SPI is easy // hardware SPI is easy
#if defined(SPARK) #if defined(SPARK)
_spi->transfer(buffer, buffer, len, NULL); _spi->transfer(buffer, buffer, len, nullptr);
#elif defined(STM32) #elif defined(STM32)
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
_spi->transfer(buffer[i]); _spi->transfer(buffer[i]);
@ -255,7 +252,8 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
} }
/*! /*!
* @brief Transfer (send/receive) one byte over hard/soft SPI * @brief Transfer (send/receive) one byte over hard/soft SPI, without
* transaction management
* @param send The byte to send * @param send The byte to send
* @return The byte received while transmitting * @return The byte received while transmitting
*/ */
@ -285,7 +283,38 @@ void Adafruit_SPIDevice::endTransaction(void) {
} }
/*! /*!
* @brief Write a buffer or two to the SPI device. * @brief Assert/Deassert the CS pin if it is defined
* @param value The state the CS is set to
*/
void Adafruit_SPIDevice::setChipSelect(int value) {
if (_cs != -1) {
digitalWrite(_cs, value);
}
}
/*!
* @brief Write a buffer or two to the SPI device, with transaction
* management.
* @brief Manually begin a transaction (calls beginTransaction if hardware
* SPI) with asserting the CS pin
*/
void Adafruit_SPIDevice::beginTransactionWithAssertingCS() {
beginTransaction();
setChipSelect(LOW);
}
/*!
* @brief Manually end a transaction (calls endTransaction if hardware SPI)
* with deasserting the CS pin
*/
void Adafruit_SPIDevice::endTransactionWithDeassertingCS() {
setChipSelect(HIGH);
endTransaction();
}
/*!
* @brief Write a buffer or two to the SPI device, with transaction
* management.
* @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 * @param prefix_buffer Pointer to optional array of data to write before
@ -294,29 +323,35 @@ void Adafruit_SPIDevice::endTransaction(void) {
* @return Always returns true because there's no way to test success of SPI * @return Always returns true because there's no way to test success of SPI
* writes * writes
*/ */
bool Adafruit_SPIDevice::write(uint8_t *buffer, size_t len, bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
uint8_t *prefix_buffer, size_t prefix_len) { const uint8_t *prefix_buffer,
if (_spi) { size_t prefix_len) {
_spi->beginTransaction(*_spiSetting); beginTransactionWithAssertingCS();
}
digitalWrite(_cs, LOW);
// do the writing // do the writing
for (size_t i = 0; i < prefix_len; i++) { #if defined(ARDUINO_ARCH_ESP32)
transfer(prefix_buffer[i]);
}
for (size_t i = 0; i < len; i++) {
transfer(buffer[i]);
}
digitalWrite(_cs, HIGH);
if (_spi) { if (_spi) {
_spi->endTransaction(); if (prefix_len > 0) {
_spi->transferBytes(prefix_buffer, nullptr, prefix_len);
}
if (len > 0) {
_spi->transferBytes(buffer, nullptr, len);
}
} else
#endif
{
for (size_t i = 0; i < prefix_len; i++) {
transfer(prefix_buffer[i]);
}
for (size_t i = 0; i < len; i++) {
transfer(buffer[i]);
}
} }
endTransactionWithDeassertingCS();
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("\tSPIDevice Wrote: ")); DEBUG_SERIAL.print(F("\tSPIDevice Wrote: "));
if ((prefix_len != 0) && (prefix_buffer != NULL)) { if ((prefix_len != 0) && (prefix_buffer != nullptr)) {
for (uint16_t i = 0; i < prefix_len; i++) { for (uint16_t i = 0; i < prefix_len; i++) {
DEBUG_SERIAL.print(F("0x")); DEBUG_SERIAL.print(F("0x"));
DEBUG_SERIAL.print(prefix_buffer[i], HEX); DEBUG_SERIAL.print(prefix_buffer[i], HEX);
@ -338,7 +373,8 @@ bool Adafruit_SPIDevice::write(uint8_t *buffer, size_t len,
} }
/*! /*!
* @brief Read from SPI into a buffer from the SPI device. * @brief Read from SPI into a buffer from the SPI device, with transaction
* management.
* @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, * @param sendvalue The 8-bits of data to write when doing the data read,
@ -348,16 +384,10 @@ bool Adafruit_SPIDevice::write(uint8_t *buffer, size_t len,
*/ */
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
if (_spi) {
_spi->beginTransaction(*_spiSetting);
}
digitalWrite(_cs, LOW);
transfer(buffer, len);
digitalWrite(_cs, HIGH);
if (_spi) { beginTransactionWithAssertingCS();
_spi->endTransaction(); transfer(buffer, len);
} endTransactionWithDeassertingCS();
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
DEBUG_SERIAL.print(F("\tSPIDevice Read: ")); DEBUG_SERIAL.print(F("\tSPIDevice Read: "));
@ -376,9 +406,9 @@ bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
} }
/*! /*!
* @brief Write some data, then read some data from SPI into another buffer. * @brief Write some data, then read some data from SPI into another buffer,
* The buffers can point to same/overlapping locations. This does not * with transaction management. The buffers can point to same/overlapping
* transmit-receive at the same time! * 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.
@ -388,17 +418,22 @@ bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
* @return Always returns true because there's no way to test success of SPI * @return Always returns true because there's no way to test success of SPI
* writes * writes
*/ */
bool Adafruit_SPIDevice::write_then_read(uint8_t *write_buffer, bool Adafruit_SPIDevice::write_then_read(const uint8_t *write_buffer,
size_t write_len, uint8_t *read_buffer, size_t write_len, uint8_t *read_buffer,
size_t read_len, uint8_t sendvalue) { size_t read_len, uint8_t sendvalue) {
if (_spi) { beginTransactionWithAssertingCS();
_spi->beginTransaction(*_spiSetting);
}
digitalWrite(_cs, LOW);
// do the writing // do the writing
for (size_t i = 0; i < write_len; i++) { #if defined(ARDUINO_ARCH_ESP32)
transfer(write_buffer[i]); if (_spi) {
if (write_len > 0) {
_spi->transferBytes(write_buffer, nullptr, write_len);
}
} else
#endif
{
for (size_t i = 0; i < write_len; i++) {
transfer(write_buffer[i]);
}
} }
#ifdef DEBUG_SERIAL #ifdef DEBUG_SERIAL
@ -432,11 +467,25 @@ bool Adafruit_SPIDevice::write_then_read(uint8_t *write_buffer,
DEBUG_SERIAL.println(); DEBUG_SERIAL.println();
#endif #endif
digitalWrite(_cs, HIGH); endTransactionWithDeassertingCS();
if (_spi) { return true;
_spi->endTransaction(); }
}
/*!
* @brief Write some data and read some data at the same time from SPI
* into the same buffer, with transaction management. This is basicaly a wrapper
* for transfer() with CS-pin and transaction management. This /does/
* transmit-receive at the same time!
* @param buffer Pointer to buffer of data to write/read to/from
* @param len Number of bytes from buffer to write/read.
* @return Always returns true because there's no way to test success of SPI
* writes
*/
bool Adafruit_SPIDevice::write_and_read(uint8_t *buffer, size_t len) {
beginTransactionWithAssertingCS();
transfer(buffer, len);
endTransactionWithDeassertingCS();
return true; return true;
} }

Wyświetl plik

@ -1,3 +1,6 @@
#ifndef Adafruit_SPIDevice_h
#define Adafruit_SPIDevice_h
#include <Arduino.h> #include <Arduino.h>
#if !defined(SPI_INTERFACES_COUNT) || \ #if !defined(SPI_INTERFACES_COUNT) || \
@ -5,9 +8,6 @@
#include <SPI.h> #include <SPI.h>
#ifndef 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)) || \ #if (defined(__AVR__) && !defined(ARDUINO_ARCH_MEGAAVR)) || \
defined(ESP8266) || defined(TEENSYDUINO) || defined(SPARK) || \ defined(ESP8266) || defined(TEENSYDUINO) || defined(SPARK) || \
@ -23,7 +23,7 @@ typedef enum _BitOrder {
SPI_BITORDER_LSBFIRST = LSBFIRST, SPI_BITORDER_LSBFIRST = LSBFIRST,
} BusIOBitOrder; } BusIOBitOrder;
#elif defined(ESP32) || defined(__ASR6501__) #elif defined(ESP32) || defined(__ASR6501__) || defined(__ASR6502__)
// some modern SPI definitions don't have BitOrder enum and have different SPI // some modern SPI definitions don't have BitOrder enum and have different SPI
// mode defines // mode defines
@ -39,7 +39,19 @@ typedef enum _BitOrder {
typedef BitOrder BusIOBitOrder; typedef BitOrder BusIOBitOrder;
#endif #endif
#if defined(__AVR__) || defined(TEENSYDUINO) #if defined(__IMXRT1062__) // Teensy 4.x
// *Warning* I disabled the usage of FAST_PINIO as the set/clear operations
// used in the cpp file are not atomic and can effect multiple IO pins
// and if an interrupt happens in between the time the code reads the register
// and writes out the updated value, that changes one or more other IO pins
// on that same IO port, those change will be clobbered when the updated
// values are written back. A fast version can be implemented that uses the
// ports set and clear registers which are atomic.
// typedef volatile uint32_t BusIO_PortReg;
// typedef uint32_t BusIO_PortMask;
//#define BUSIO_USE_FAST_PINIO
#elif defined(__AVR__) || defined(TEENSYDUINO)
typedef volatile uint8_t BusIO_PortReg; typedef volatile uint8_t BusIO_PortReg;
typedef uint8_t BusIO_PortMask; typedef uint8_t BusIO_PortMask;
#define BUSIO_USE_FAST_PINIO #define BUSIO_USE_FAST_PINIO
@ -54,7 +66,7 @@ typedef uint32_t BusIO_PortMask;
!defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_RP2040) !defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_RP2040)
typedef volatile uint32_t BusIO_PortReg; typedef volatile uint32_t BusIO_PortReg;
typedef uint32_t BusIO_PortMask; typedef uint32_t BusIO_PortMask;
#if not defined(__ASR6501__) #if !defined(__ASR6501__) && !defined(__ASR6502__)
#define BUSIO_USE_FAST_PINIO #define BUSIO_USE_FAST_PINIO
#endif #endif
@ -77,16 +89,19 @@ public:
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, bool write(const uint8_t *buffer, size_t len,
size_t prefix_len = 0); const uint8_t *prefix_buffer = nullptr, size_t prefix_len = 0);
bool write_then_read(uint8_t *write_buffer, size_t write_len, bool write_then_read(const uint8_t *write_buffer, size_t write_len,
uint8_t *read_buffer, size_t read_len, uint8_t *read_buffer, size_t read_len,
uint8_t sendvalue = 0xFF); uint8_t sendvalue = 0xFF);
bool write_and_read(uint8_t *buffer, size_t len);
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);
void beginTransaction(void); void beginTransaction(void);
void endTransaction(void); void endTransaction(void);
void beginTransactionWithAssertingCS();
void endTransactionWithDeassertingCS();
private: private:
SPIClass *_spi; SPIClass *_spi;
@ -94,6 +109,7 @@ private:
uint32_t _freq; uint32_t _freq;
BusIOBitOrder _dataOrder; BusIOBitOrder _dataOrder;
uint8_t _dataMode; uint8_t _dataMode;
void setChipSelect(int value);
int8_t _cs, _sck, _mosi, _miso; int8_t _cs, _sck, _mosi, _miso;
#ifdef BUSIO_USE_FAST_PINIO #ifdef BUSIO_USE_FAST_PINIO
@ -103,5 +119,5 @@ private:
bool _begun; bool _begun;
}; };
#endif // Adafruit_SPIDevice_h
#endif // has SPI defined #endif // has SPI defined
#endif // Adafruit_SPIDevice_h

Wyświetl plik

@ -0,0 +1,11 @@
# Adafruit Bus IO Library
# https://github.com/adafruit/Adafruit_BusIO
# MIT License
cmake_minimum_required(VERSION 3.5)
idf_component_register(SRCS "Adafruit_I2CDevice.cpp" "Adafruit_BusIO_Register.cpp" "Adafruit_SPIDevice.cpp"
INCLUDE_DIRS "."
REQUIRES arduino)
project(Adafruit_BusIO)

Wyświetl plik

@ -1,7 +1,7 @@
# 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) # 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)
This is a helper libary to abstract away I2C & SPI transactions and registers This is a helper library to abstract away I2C & SPI transactions and registers
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Wyświetl plik

@ -0,0 +1 @@
COMPONENT_ADD_INCLUDEDIRS = .

Wyświetl plik

@ -139,7 +139,7 @@ void setup() {
void loop() { void loop() {
#if (defined( MAX31865_READY_PIN ) && (MAX31865_1_READY_PIN != -1)) #if (defined( MAX31865_READY_PIN ) && (MAX31865_1_READY_PIN != -1))
// Is converstion ready? // Is conversion ready?
if (!digitalRead(MAX31865_READY_PIN)) if (!digitalRead(MAX31865_READY_PIN))
#else #else
// Warant conversion is ready. // Warant conversion is ready.

Wyświetl plik

@ -1,5 +1,5 @@
name=Adafruit BusIO name=Adafruit BusIO
version=1.9.3 version=1.12.0
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