Skip to content

Commit

Permalink
V1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
felias-fogg committed Jan 15, 2024
1 parent 0f46c3c commit 061afa0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
Why would you like to use this library? Well, it is a true drop-in replacement for the Wire library (master part). When you include it in your sketch file before any other library, then it will take over the part of the Wire library. In other words, you can simply use any sensor/actuator library that makes use of the Wire library, and it will work ([magically!](https://arduino-craft-corner.de/index.php/2023/11/29/replacing-the-wire-library-sometimes/)). Further, since you can dynamically change the pins for SDA and SCL, you can have as many I2C buses as you want. This means you can implement a sort of software I2C multiplexer, communicating with several I2C devices that have the same I2C address ([see my blog post on that](https://arduino-craft-corner.de/index.php/2023/12/14/software-i2c-multiplexer/)). Furthermore, since it uses only high-level Arduino built-in functions, it should work on all architectures supported by Arduino.

The only disadvantage is that it is somewhat slow. Since V1.1.0, on AVR MCUs bit-banging is implemented using port manipulation, which means that on an AVR MCU running at 16 MHz, you can get up to 140 kHz bus frequency. The default is 90 kHz. For other architectures, I have not measured the speed (yet).

**Note:** When you have compiled your sketch before using the standard Wire library, it may be necessary to exit and restart the Arduino IDE. Otherwise, the IDE might reuse the precompiled Wire library.
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
CHANGELOG for FlexWire
V1.2.0 (15.1.2024)
- changed BUFFER_LENGTH to I2C_BUFFER_LENGTH for ESP32 in order to be compatible with ESP32 Wire lib
- BUFFER_LENGTH and I2C_BUFFER_LENGTH are now synonyms for all other
architectures (which might create problems)
- set I2C_BUFFER_LENGTH to 128 for ESP32
- set I2C_BUFFER_LENGTH to 250 for ARDUINO_ARCH_SAMD
- it is still 32 for all other architectures

V1.1.2 (16.12.2023)
- added state vars for sda and scl in order to speed up and to avoid
glitches when running on RP2040.
- tested on Zero, Due, and RP2040; for the latter one should use the
Arduino core by earlephilhower; the official core is very slow
when it comes to digital I/O.
- added the above to the LibraryBuild file
- changed all examples: A4 -> 2, A5 -> 3 (because RP2040 does not
have A4 and A5)

V1.1.1 (15.12.2023)
- Fixed: setClock fixed so that the specified value is always an
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=FlexWire
version=1.1.2
version=1.2.0
author=Bernhard Nebel
maintainer=Bernhard Nebel <[email protected]>
sentence=This library implements the master side of the I2C protocol in a platform independent way.
Expand Down
4 changes: 2 additions & 2 deletions src/FlexWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ size_t FlexWire::write(const uint8_t *data, size_t quantity) {
uint8_t FlexWire::requestFrom(uint8_t address, uint8_t quantity, bool sendStop) {
uint8_t localerror = 0;
// clamp to buffer length
if(quantity > BUFFER_LENGTH){
quantity = BUFFER_LENGTH;
if(quantity > I2C_BUFFER_LENGTH){
quantity = I2C_BUFFER_LENGTH;
}
localerror = !i2c_rep_start((address<<1) | I2C_READ);
if (_error == 0 && localerror) _error = 2;
Expand Down
16 changes: 14 additions & 2 deletions src/FlexWire.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#ifndef FLEXWIRE_h
#define FLEXWIRE_h
#define FLEXWIRE_VERSION 1.1.2
#define FLEXWIRE_VERSION 1.2.0

// #define AVR_OPTIMIZATION 0 // without optimizations, less code, but much slower (55 kHz)

Expand All @@ -22,12 +22,24 @@
#else
#define I2C_DEFAULT_DELAY 0 // usec delay
#endif

#ifdef ESP32
#define I2C_BUFFER_LENGTH 128
#else
#ifdef ARDUINO_ARCH_SAMD
#define BUFFER_LENGTH 250
#define I2C_BUFFER_LENGTH BUFFER_LENGTH
#else // ordinary AVRs
#define BUFFER_LENGTH 32
#define I2C_BUFFER_LENGTH BUFFER_LENGTH
#endif
#endif

#define I2C_MAXWAIT 5000

class FlexWire {
protected:
uint8_t _rxBuffer[BUFFER_LENGTH];
uint8_t _rxBuffer[I2C_BUFFER_LENGTH];
uint8_t _rxBufferIndex;
uint8_t _rxBufferLength;
uint8_t _transmitting;
Expand Down

0 comments on commit 061afa0

Please sign in to comment.