Skip to content

Commit 061afa0

Browse files
committed
V1.2.0
1 parent 0f46c3c commit 061afa0

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
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.
1212

1313
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).
14+
15+
**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.

changelog.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
CHANGELOG for FlexWire
2+
V1.2.0 (15.1.2024)
3+
- changed BUFFER_LENGTH to I2C_BUFFER_LENGTH for ESP32 in order to be compatible with ESP32 Wire lib
4+
- BUFFER_LENGTH and I2C_BUFFER_LENGTH are now synonyms for all other
5+
architectures (which might create problems)
6+
- set I2C_BUFFER_LENGTH to 128 for ESP32
7+
- set I2C_BUFFER_LENGTH to 250 for ARDUINO_ARCH_SAMD
8+
- it is still 32 for all other architectures
9+
210
V1.1.2 (16.12.2023)
311
- added state vars for sda and scl in order to speed up and to avoid
412
glitches when running on RP2040.
513
- tested on Zero, Due, and RP2040; for the latter one should use the
614
Arduino core by earlephilhower; the official core is very slow
715
when it comes to digital I/O.
816
- added the above to the LibraryBuild file
17+
- changed all examples: A4 -> 2, A5 -> 3 (because RP2040 does not
18+
have A4 and A5)
919

1020
V1.1.1 (15.12.2023)
1121
- Fixed: setClock fixed so that the specified value is always an

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=FlexWire
2-
version=1.1.2
2+
version=1.2.0
33
author=Bernhard Nebel
44
maintainer=Bernhard Nebel <[email protected]>
55
sentence=This library implements the master side of the I2C protocol in a platform independent way.

src/FlexWire.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ size_t FlexWire::write(const uint8_t *data, size_t quantity) {
116116
uint8_t FlexWire::requestFrom(uint8_t address, uint8_t quantity, bool sendStop) {
117117
uint8_t localerror = 0;
118118
// clamp to buffer length
119-
if(quantity > BUFFER_LENGTH){
120-
quantity = BUFFER_LENGTH;
119+
if(quantity > I2C_BUFFER_LENGTH){
120+
quantity = I2C_BUFFER_LENGTH;
121121
}
122122
localerror = !i2c_rep_start((address<<1) | I2C_READ);
123123
if (_error == 0 && localerror) _error = 2;

src/FlexWire.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#ifndef FLEXWIRE_h
44
#define FLEXWIRE_h
5-
#define FLEXWIRE_VERSION 1.1.2
5+
#define FLEXWIRE_VERSION 1.2.0
66

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

@@ -22,12 +22,24 @@
2222
#else
2323
#define I2C_DEFAULT_DELAY 0 // usec delay
2424
#endif
25+
26+
#ifdef ESP32
27+
#define I2C_BUFFER_LENGTH 128
28+
#else
29+
#ifdef ARDUINO_ARCH_SAMD
30+
#define BUFFER_LENGTH 250
31+
#define I2C_BUFFER_LENGTH BUFFER_LENGTH
32+
#else // ordinary AVRs
2533
#define BUFFER_LENGTH 32
34+
#define I2C_BUFFER_LENGTH BUFFER_LENGTH
35+
#endif
36+
#endif
37+
2638
#define I2C_MAXWAIT 5000
2739

2840
class FlexWire {
2941
protected:
30-
uint8_t _rxBuffer[BUFFER_LENGTH];
42+
uint8_t _rxBuffer[I2C_BUFFER_LENGTH];
3143
uint8_t _rxBufferIndex;
3244
uint8_t _rxBufferLength;
3345
uint8_t _transmitting;

0 commit comments

Comments
 (0)