Skip to content

Commit

Permalink
Add Wire.end()
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Feb 5, 2016
1 parent a1fa3e0 commit 37f7d78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Wire.cpp
Expand Up @@ -167,6 +167,15 @@ void TwoWire::begin(uint8_t address)
NVIC_ENABLE_IRQ(IRQ_I2C0);
}

void TwoWire::end()
{
NVIC_DISABLE_IRQ(IRQ_I2C0);
I2C0_C1 = 0;
CORE_PIN18_CONFIG = 0;
CORE_PIN19_CONFIG = 0;
SIM_SCGC4 &= ~SIM_SCGC4_I2C0; // TODO: use bitband
}

void i2c0_isr(void)
{
uint8_t status, c1, data;
Expand Down Expand Up @@ -628,6 +637,13 @@ void TwoWire::begin(int address)
begin((uint8_t)address);
}

void TwoWire::end()
{
TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));
digitalWrite(SDA, 0);
digitalWrite(SCL, 0);
}

void TwoWire::setClock(uint32_t frequency)
{
TWBR = ((F_CPU / frequency) - 16) / 2;
Expand Down
2 changes: 2 additions & 0 deletions Wire.h
Expand Up @@ -26,6 +26,7 @@
#include "Arduino.h"

#define BUFFER_LENGTH 32
#define WIRE_HAS_END 1

extern "C" void i2c0_isr(void);

Expand Down Expand Up @@ -53,6 +54,7 @@ class TwoWire : public Stream
void begin();
void begin(uint8_t);
void begin(int);
void end();
void setClock(uint32_t);
void beginTransmission(uint8_t);
void beginTransmission(int);
Expand Down

0 comments on commit 37f7d78

Please sign in to comment.