diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..f0e2614 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -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** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..7b641eb --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -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. diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..bb67855 --- /dev/null +++ b/.github/workflows/githubci.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4075405..0000000 --- a/.travis.yml +++ /dev/null @@ -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) \ No newline at end of file diff --git a/Adafruit_BusIO_Register.cpp b/Adafruit_BusIO_Register.cpp index 259c76b..5c742cf 100644 --- a/Adafruit_BusIO_Register.cpp +++ b/Adafruit_BusIO_Register.cpp @@ -1,15 +1,22 @@ #include /*! - * @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 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 bitorder The bit order of the register (used when width is > 1), defaults to LSBFIRST - * @param address_width The width of the register address itself, defaults to 1 byte + * @param bitorder The bit order of the register (used when width is > 1), + * 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, - uint8_t width, uint8_t bitorder, uint8_t address_width) { +Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, + uint16_t reg_addr, + uint8_t width, + uint8_t bitorder, + uint8_t address_width) { _i2cdevice = i2cdevice; _spidevice = NULL; _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 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 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 bitorder The bit order of the register (used when width is > 1), defaults to LSBFIRST - * @param address_width The width of the register address itself, defaults to 1 byte + * @param bitorder The bit order of the register (used when width is > 1), + * 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_SPIRegType type, - uint8_t width, uint8_t bitorder, uint8_t address_width) { +Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, + uint16_t reg_addr, + Adafruit_BusIO_SPIRegType type, + uint8_t width, + uint8_t bitorder, + uint8_t address_width) { _spidevice = spidevice; _spiregtype = type; _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 - * can pass in NULL for the unused interface, allowing libraries to mass-define all the registers - * @param i2cdevice The I2CDevice to use for underlying I2C access, if NULL we use SPI - * @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) + * @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 + * libraries to mass-define all the registers + * @param i2cdevice The I2CDevice to use for underlying I2C access, if NULL + * we use SPI + * @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 bitorder The bit order of the register (used when width is > 1), defaults to LSBFIRST - * @param address_width The width of the register address itself, defaults to 1 byte + * @param bitorder The bit order of the register (used when width is > 1), + * 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_SPIRegType type, uint16_t reg_addr, - uint8_t width, uint8_t bitorder, uint8_t address_width) { +Adafruit_BusIO_Register::Adafruit_BusIO_Register( + Adafruit_I2CDevice *i2cdevice, Adafruit_SPIDevice *spidevice, + Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, uint8_t width, + uint8_t bitorder, uint8_t address_width) { _spidevice = spidevice; _i2cdevice = i2cdevice; _spiregtype = type; @@ -62,16 +85,17 @@ Adafruit_BusIO_Register::Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, _width = width; } - /*! * @brief Write a buffer of data to the register location * @param buffer Pointer to data 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) { - 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) { return _i2cdevice->write(buffer, len, true, addrbuffer, _addrwidth); @@ -84,7 +108,7 @@ bool Adafruit_BusIO_Register::write(uint8_t *buffer, uint8_t len) { addrbuffer[0] &= ~0x80; addrbuffer[0] |= 0x40; } - return _spidevice->write( buffer, len, addrbuffer, _addrwidth); + return _spidevice->write(buffer, len, addrbuffer, _addrwidth); } return false; } @@ -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 * @param value Data 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) { if (numbytes == 0) { @@ -103,11 +128,11 @@ bool Adafruit_BusIO_Register::write(uint32_t value, uint8_t numbytes) { return false; } - for (int i=0; i>= 8; } @@ -115,37 +140,39 @@ 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 */ uint32_t Adafruit_BusIO_Register::read(void) { - if (! read(_buffer, _width)) { + if (!read(_buffer, _width)) { return -1; } uint32_t value = 0; - for (int i=0; i < _width; i++) { - value <<= 8; - if (_bitorder == LSBFIRST) { - value |= _buffer[_width-i-1]; - } else { - value |= _buffer[i]; - } - } + for (int i = 0; i < _width; i++) { + value <<= 8; + if (_bitorder == LSBFIRST) { + value |= _buffer[_width - i - 1]; + } else { + value |= _buffer[i]; + } + } - return value; + return value; } - /*! * @brief Read a buffer of data from the register location * @param buffer Pointer to data to read into * @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) { - 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) { return _i2cdevice->write_then_read(addrbuffer, _addrwidth, buffer, len); @@ -165,10 +192,11 @@ bool Adafruit_BusIO_Register::read(uint8_t *buffer, uint8_t len) { /*! * @brief Read 2 bytes of data from the register location * @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) { - if (! read(_buffer, 2)) { + if (!read(_buffer, 2)) { return false; } @@ -187,10 +215,11 @@ bool Adafruit_BusIO_Register::read(uint16_t *value) { /*! * @brief Read 1 byte of data from the register location * @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) { - if (! read(_buffer, 1)) { + if (!read(_buffer, 1)) { return false; } @@ -204,7 +233,8 @@ bool Adafruit_BusIO_Register::read(uint8_t *value) { */ void Adafruit_BusIO_Register::print(Stream *s) { 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(); } - /*! - * @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 bits The number of bits wide we are slicing * @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; _bits = bits; _shift = shift; @@ -239,7 +270,6 @@ uint32_t Adafruit_BusIO_RegisterBits::read(void) { return val & ((1 << (_bits)) - 1); } - /*! * @brief Write 4 bytes of data to the register * @param data The 4 bytes to write @@ -252,9 +282,9 @@ void Adafruit_BusIO_RegisterBits::write(uint32_t data) { data &= mask; mask <<= _shift; - val &= ~mask; // remove the current data at that spot + val &= ~mask; // remove the current data at that spot val |= data << _shift; // and add in the new data - + _register->write(val, _register->width()); } diff --git a/Adafruit_BusIO_Register.h b/Adafruit_BusIO_Register.h index 1509d6f..19152ea 100644 --- a/Adafruit_BusIO_Register.h +++ b/Adafruit_BusIO_Register.h @@ -2,7 +2,6 @@ #include #include - #ifndef Adafruit_BusIO_Register_h #define Adafruit_BusIO_Register_h @@ -12,59 +11,61 @@ typedef enum _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 { - public: - Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr, - uint8_t width=1, uint8_t bitorder=LSBFIRST, - uint8_t address_width=1); - Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, - Adafruit_BusIO_SPIRegType type, - uint8_t width=1, uint8_t bitorder=LSBFIRST, - uint8_t address_width=1); +public: + Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, uint16_t reg_addr, + uint8_t width = 1, uint8_t bitorder = LSBFIRST, + uint8_t address_width = 1); + Adafruit_BusIO_Register(Adafruit_SPIDevice *spidevice, uint16_t reg_addr, + Adafruit_BusIO_SPIRegType type, uint8_t width = 1, + uint8_t bitorder = LSBFIRST, + uint8_t address_width = 1); Adafruit_BusIO_Register(Adafruit_I2CDevice *i2cdevice, - Adafruit_SPIDevice *spidevice, - Adafruit_BusIO_SPIRegType type, - uint16_t reg_addr, - uint8_t width=1, uint8_t bitorder=LSBFIRST, - uint8_t address_width=1); + Adafruit_SPIDevice *spidevice, + Adafruit_BusIO_SPIRegType type, uint16_t reg_addr, + uint8_t width = 1, uint8_t bitorder = LSBFIRST, + uint8_t address_width = 1); bool read(uint8_t *buffer, uint8_t len); bool read(uint8_t *value); bool read(uint16_t *value); uint32_t read(void); bool write(uint8_t *buffer, uint8_t len); - bool write(uint32_t value, uint8_t numbytes=0); + bool write(uint32_t value, uint8_t numbytes = 0); uint8_t width(void); - void print(Stream *s=&Serial); - void println(Stream *s=&Serial); + void print(Stream *s = &Serial); + void println(Stream *s = &Serial); - private: +private: Adafruit_I2CDevice *_i2cdevice; Adafruit_SPIDevice *_spidevice; Adafruit_BusIO_SPIRegType _spiregtype; uint16_t _address; 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 { - public: - Adafruit_BusIO_RegisterBits(Adafruit_BusIO_Register *reg, uint8_t bits, uint8_t shift); +public: + Adafruit_BusIO_RegisterBits(Adafruit_BusIO_Register *reg, uint8_t bits, + uint8_t shift); void write(uint32_t value); uint32_t read(void); - private: + +private: Adafruit_BusIO_Register *_register; uint8_t _bits, _shift; }; - -#endif //BusIO_Register_h +#endif // BusIO_Register_h diff --git a/Adafruit_I2CDevice.cpp b/Adafruit_I2CDevice.cpp index dfa1394..316e2f8 100644 --- a/Adafruit_I2CDevice.cpp +++ b/Adafruit_I2CDevice.cpp @@ -21,21 +21,21 @@ Adafruit_I2CDevice::Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire) { /*! * @brief Initializes and does basic address detection - * @param addr_detect Whether we should attempt to detect the I2C address with a scan. - * 99% of sensors/devices don't mind but once in a while, they spaz on a scan! + * @param addr_detect Whether we should attempt to detect the I2C address + * 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 */ bool Adafruit_I2CDevice::begin(bool addr_detect) { _wire->begin(); _begun = true; - + if (addr_detect) { return detected(); } return true; } - /*! * @brief Scans I2C for the address - note will give a false-positive * if there's no pullups on I2C @@ -49,24 +49,26 @@ bool Adafruit_I2CDevice::detected(void) { // A basic scanner, see if it ACK's _wire->beginTransmission(_addr); - if (_wire->endTransmission () == 0) { + if (_wire->endTransmission() == 0) { return true; } return false; } /*! - * @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 len Number of bytes from buffer to write - * @param prefix_buffer Pointer to optional array of data to write before buffer. - * Cannot be more than maxBufferSize() bytes. + * @param prefix_buffer Pointer to optional array of data to write before + * buffer. Cannot be more than maxBufferSize() bytes. * @param prefix_len Number of bytes from prefix buffer to write * @param stop Whether to send an I2C STOP signal on write * @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) { - if ((len+prefix_len) > maxBufferSize()) { +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()) { // currently not guaranteed to work if more than 32 bytes! // we will need to find out if some platforms have larger // I2C buffer sizes :/ @@ -99,15 +101,15 @@ bool Adafruit_I2CDevice::write(uint8_t *buffer, size_t len, bool stop, uint8_t * #ifdef DEBUG_SERIAL DEBUG_SERIAL.print(F("\tI2CDevice Wrote: ")); if ((prefix_len != 0) && (prefix_buffer != NULL)) { - for (uint16_t i=0; iendTransmission(stop) == 0) { #ifdef DEBUG_SERIAL - //DEBUG_SERIAL.println("Sent!"); + // DEBUG_SERIAL.println("Sent!"); #endif return true; } else { @@ -133,9 +135,8 @@ 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. * @param buffer Pointer to buffer of data to read into * @param len Number of bytes from buffer to read. @@ -163,15 +164,15 @@ bool Adafruit_I2CDevice::read(uint8_t *buffer, size_t len, bool stop) { return false; } - for (uint16_t i=0; iread(); } #ifdef DEBUG_SERIAL DEBUG_SERIAL.print(F("\tI2CDevice Read: ")); - for (uint16_t i=0; i> b) & 0x1) << (7-b); + for (uint8_t b = 0; b < 8; b++) { + temp |= ((send >> b) & 0x1) << (7 - b); } send = temp; } - for (int b=7; b>=0; b--) { + for (int b = 7; b >= 0; b--) { reply <<= 1; if (_dataMode == SPI_MODE0) { - digitalWrite(_sck, LOW); - digitalWrite(_mosi, send & (1<> b) & 0x1) << (7-b); + for (uint8_t b = 0; b < 8; b++) { + temp |= ((reply >> b) & 0x1) << (7 - b); } reply = temp; } @@ -139,8 +146,6 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) { return; } - - /*! * @brief Transfer (send/receive) one byte over hard/soft SPI * @param send The byte to send @@ -152,26 +157,28 @@ uint8_t Adafruit_SPIDevice::transfer(uint8_t send) { return data; } - /*! * @brief Write a buffer or two to the SPI device. * @param buffer Pointer to buffer of data 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 - * @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) { _spi->beginTransaction(*_spiSetting); } digitalWrite(_cs, LOW); // do the writing - for (size_t i=0; ibeginTransaction(*_spiSetting); } digitalWrite(_cs, LOW); - transfer(buffer, len); + transfer(buffer, len); digitalWrite(_cs, HIGH); if (_spi) { @@ -225,9 +234,9 @@ bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) { #ifdef DEBUG_SERIAL DEBUG_SERIAL.print(F("\tSPIDevice Read: ")); - for (uint16_t i=0; ibeginTransaction(*_spiSetting); } digitalWrite(_cs, LOW); // do the writing - for (size_t i=0; i sentence=This is a library for abstracting away UART, I2C and SPI interfacing