diff options
author | Sandeep Mistry <s.mistry@arduino.cc> | 2015-08-25 10:24:24 -0400 |
---|---|---|
committer | Sandeep Mistry <s.mistry@arduino.cc> | 2015-08-25 10:24:24 -0400 |
commit | eab6601ebc4ff975086fe9a69a816f550b22b8f0 (patch) | |
tree | e0c4b603ae0d062dd575df48f2e7e03ba2e28665 /libraries/Wire | |
parent | c25e80e27c013f5cb1a98b246f69d35b7e969b5a (diff) |
implement Wire.end() for AVR core
Diffstat (limited to 'libraries/Wire')
-rw-r--r-- | libraries/Wire/Wire.cpp | 5 | ||||
-rw-r--r-- | libraries/Wire/Wire.h | 4 | ||||
-rw-r--r-- | libraries/Wire/utility/twi.c | 16 | ||||
-rw-r--r-- | libraries/Wire/utility/twi.h | 1 |
4 files changed, 26 insertions, 0 deletions
diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 835b794..2bd48ed 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -75,6 +75,11 @@ void TwoWire::begin(int address) begin((uint8_t)address); } +void TwoWire::end(void) +{ + twi_disable(); +} + void TwoWire::setClock(uint32_t frequency) { TWBR = ((F_CPU / frequency) - 16) / 2; diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index 7d00959..702f37d 100644 --- a/libraries/Wire/Wire.h +++ b/libraries/Wire/Wire.h @@ -27,6 +27,9 @@ #define BUFFER_LENGTH 32 +// WIRE_HAS_END means Wire has end() +#define WIRE_HAS_END 1 + class TwoWire : public Stream { private: @@ -49,6 +52,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); diff --git a/libraries/Wire/utility/twi.c b/libraries/Wire/utility/twi.c index 201d7d1..d7d72bc 100644 --- a/libraries/Wire/utility/twi.c +++ b/libraries/Wire/utility/twi.c @@ -91,6 +91,22 @@ void twi_init(void) } /* + * Function twi_disable + * Desc disables twi pins + * Input none + * Output none + */ +void twi_disable(void) +{ + // disable twi module, acks, and twi interrupt + TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA)); + + // deactivate internal pullups for twi. + digitalWrite(SDA, 0); + digitalWrite(SCL, 0); +} + +/* * Function twi_slaveInit * Desc sets slave address and enables interrupt * Input none diff --git a/libraries/Wire/utility/twi.h b/libraries/Wire/utility/twi.h index 6526593..4c52bc5 100644 --- a/libraries/Wire/utility/twi.h +++ b/libraries/Wire/utility/twi.h @@ -39,6 +39,7 @@ #define TWI_STX 4 void twi_init(void); + void twi_disable(void); void twi_setAddress(uint8_t); uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t); uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t); |