Skip to content

Commit 7e16b25

Browse files
authored
Merge pull request #500 from MX682X/master
Wire rework
2 parents 52fae98 + 1d47bd2 commit 7e16b25

File tree

7 files changed

+838
-1091
lines changed

7 files changed

+838
-1091
lines changed

megaavr/libraries/Wire/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ uint8_t checkPinLevels();
208208
```
209209
This function returns the level of the master TWI pins, depending on the used TWI module and port multiplexer settings. Bit 0 represents SDA line and bit 1 represents SCL line. This is useful on initialisation, where you want to make sure that all devices have their pins ready in open-drain mode. A value of 0x03 indicates that both lines have a HIGH level and the bus is ready.
210210

211+
#### `uint8_t masterTransmit()`
212+
```c++
213+
uint8_t masterTransmit(auto *length, uint8_t *buffer, uint8_t addr, uint8_t sendStop);
214+
```
215+
This functions allows to transmit a buffer of data without having to copy the data to the internal buffer of the library. This allows transmission lengths as long as the RAM size without having to define the TWI_BUFFER_SIZE in the platform.txt. The return value is the same as endTransmission(). length will be overwritten with the actual amount of written bytes.
216+
217+
#### `uint8_t masterReceive()`
218+
```c++
219+
uint8_t masterReceive(auto *length, uint8_t *buffer, uint8_t addr, uint8_t sendStop);
220+
```
221+
This functions allows to receive a buffer of data without having to copy the data from the internal buffer of the library. This allows transmission lengths as long as the RAM size without having to define the TWI_BUFFER_SIZE in the platform.txt. The return value is the same as endTransmission(). length will be overwritten with the actual amount of received bytes.
222+
211223
### Additional New Methods not available on all parts
212224
These new methods are available exclusively for parts with certain specialized hardware; Most full-size parts support enableDualMode (but tinyAVR does not), while only the DA and DB-series parts have the second TWI interface that swapModule requires.
213225
#### `void swapModule()`
@@ -323,6 +335,8 @@ When the second or third argument was used, `Wire.getIncomingAddress()` should b
323335

324336
If (and only if) the Master and Slave option is selected in the Tools -> Wire mode, the Wire interface can be enabled for both master and slave. Even when Dual Mode is used, the correct option must still be selected to enable acting as both master and slave.
325337

338+
The Arduino library defines the array lengths as `BUFFER_LENGTH`, however, this define name might create conflicts, as the name is quite arbitrary. The newest library version uses the name `TWI_BUFFER_LENGTH` instead. However, it is still backwards compatible, as the `BUFFER_LENGTH` is still applied, but a compiler warning is generated to notify about the change.
339+
326340
#### `void setClock()`
327341
```c++
328342
void setClock(uint32_t);

megaavr/libraries/Wire/keywords.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#######################################
66
# Datatypes (KEYWORD1)
77
#######################################
8+
twi_buf_index_t KEYWORD1
9+
TWI_t KEYWORD1
810

911
#######################################
1012
# Methods and Functions (KEYWORD2)
@@ -18,13 +20,17 @@ setClock KEYWORD2
1820
beginTransmission KEYWORD2
1921
endTransmission KEYWORD2
2022
requestFrom KEYWORD2
23+
masterTransmit KEYWORD2
24+
masterReceive KEYWORD2
2125
onReceive KEYWORD2
2226
onRequest KEYWORD2
2327
getIncomingAddress KEYWORD2
2428
getBytesRead KEYWORD2
2529
slaveTransactionOpen KEYWORD2
2630
checkPinLevels KEYWORD2
2731
specialConfig KEYWORD2
32+
enableDualMode KEYWORD2
33+
returnError KEYWORD2
2834
WIRE_SDA_HOLD_OFF KEYWORD2
2935
WIRE_SDA_HOLD_50 KEYWORD2
3036
WIRE_SDA_HOLD_300 KEYWORD2

megaavr/libraries/Wire/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Wire
2-
version=2.0.10
2+
version=2.0.11
33
author=@MX682X, with contributions by @SpenceKonde. Original library, mostly reimplemented, was by Arduino.
44
maintainer=Spence Konde <spencekonde@gmail.com>
55
sentence=This library allows you to communicate with I2C devices, acting as either a master, slave, or both master and slave.

0 commit comments

Comments
 (0)