Skip to content

Commit

Permalink
Merge pull request #500 from MX682X/master
Browse files Browse the repository at this point in the history
Wire rework
  • Loading branch information
SpenceKonde committed Dec 5, 2023
2 parents 52fae98 + 1d47bd2 commit 7e16b25
Show file tree
Hide file tree
Showing 7 changed files with 838 additions and 1,091 deletions.
14 changes: 14 additions & 0 deletions megaavr/libraries/Wire/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ uint8_t checkPinLevels();
```
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.

#### `uint8_t masterTransmit()`
```c++
uint8_t masterTransmit(auto *length, uint8_t *buffer, uint8_t addr, uint8_t sendStop);
```
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.
#### `uint8_t masterReceive()`
```c++
uint8_t masterReceive(auto *length, uint8_t *buffer, uint8_t addr, uint8_t sendStop);
```
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.

### Additional New Methods not available on all parts
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.
#### `void swapModule()`
Expand Down Expand Up @@ -323,6 +335,8 @@ When the second or third argument was used, `Wire.getIncomingAddress()` should b

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.

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.

#### `void setClock()`
```c++
void setClock(uint32_t);
Expand Down
6 changes: 6 additions & 0 deletions megaavr/libraries/Wire/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#######################################
# Datatypes (KEYWORD1)
#######################################
twi_buf_index_t KEYWORD1
TWI_t KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
Expand All @@ -18,13 +20,17 @@ setClock KEYWORD2
beginTransmission KEYWORD2
endTransmission KEYWORD2
requestFrom KEYWORD2
masterTransmit KEYWORD2
masterReceive KEYWORD2
onReceive KEYWORD2
onRequest KEYWORD2
getIncomingAddress KEYWORD2
getBytesRead KEYWORD2
slaveTransactionOpen KEYWORD2
checkPinLevels KEYWORD2
specialConfig KEYWORD2
enableDualMode KEYWORD2
returnError KEYWORD2
WIRE_SDA_HOLD_OFF KEYWORD2
WIRE_SDA_HOLD_50 KEYWORD2
WIRE_SDA_HOLD_300 KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion megaavr/libraries/Wire/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Wire
version=2.0.10
version=2.0.11
author=@MX682X, with contributions by @SpenceKonde. Original library, mostly reimplemented, was by Arduino.
maintainer=Spence Konde <spencekonde@gmail.com>
sentence=This library allows you to communicate with I2C devices, acting as either a master, slave, or both master and slave.
Expand Down
Loading

0 comments on commit 7e16b25

Please sign in to comment.