Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ TwoWire::TwoWire(uint32_t sda, uint32_t scl)
_i2c.scl = digitalPinToPinName(scl);
}

/**
* @brief TwoWire destructor
* @retval None
*/
TwoWire::~TwoWire()
{
end();
}

// Public Methods //////////////////////////////////////////////////////////////

void TwoWire::begin(uint32_t sda, uint32_t scl)
Expand Down Expand Up @@ -106,11 +115,15 @@ void TwoWire::begin(int address, bool generalCall, bool NoStretchMode)
void TwoWire::end(void)
{
i2c_deinit(&_i2c);
free(txBuffer);
txBuffer = nullptr;
if (txBuffer != nullptr) {
free(txBuffer);
txBuffer = nullptr;
}
txBufferAllocated = 0;
free(rxBuffer);
rxBuffer = nullptr;
if (rxBuffer != nullptr) {
free(rxBuffer);
rxBuffer = nullptr;
}
rxBufferAllocated = 0;
}

Expand Down
1 change: 1 addition & 0 deletions libraries/Wire/src/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TwoWire : public Stream {
public:
TwoWire();
TwoWire(uint32_t sda, uint32_t scl);
~TwoWire();
// setSCL/SDA have to be called before begin()
void setSCL(uint32_t scl)
{
Expand Down