Skip to content

Commit 1a240e4

Browse files
committed
feat(wire): Add access method to get the I2C bus number
1 parent 9eb66f3 commit 1a240e4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern "C" {
3939
#include "Arduino.h"
4040

4141
TwoWire::TwoWire(uint8_t bus_num)
42-
: num(bus_num & 1), sda(-1), scl(-1), bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size
42+
: num(bus_num), sda(-1), scl(-1), bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size
4343
,
4444
rxBuffer(NULL), rxIndex(0), rxLength(0), txBuffer(NULL), txLength(0), txAddress(0), _timeOutMillis(50), nonStop(false)
4545
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -62,6 +62,10 @@ TwoWire::~TwoWire() {
6262
#endif
6363
}
6464

65+
uint8_t TwoWire::getBusNum() {
66+
return num;
67+
}
68+
6569
bool TwoWire::initPins(int sdaPin, int sclPin) {
6670
if (sdaPin < 0) { // default param passed
6771
if (num == 0) {

libraries/Wire/src/Wire.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class TwoWire : public HardwareI2C {
105105

106106
bool end() override;
107107

108+
uint8_t getBusNum();
109+
108110
bool setClock(uint32_t freq) override;
109111

110112
void beginTransmission(uint8_t address) override;

0 commit comments

Comments
 (0)