diff options
author | Cristian Maglie <c.maglie@bug.st> | 2012-06-27 13:51:16 +0200 |
---|---|---|
committer | Cristian Maglie <c.maglie@bug.st> | 2012-06-27 13:51:16 +0200 |
commit | 2d2050eabeaff7109ba89fdd0100556c981cf373 (patch) | |
tree | 1f6d9725b59aa02e5400a8117eeec3206d88047d /libraries/Wire/Wire.cpp | |
parent | 324023a67afd1691f12ead4388d7cdf1a9d1a6ef (diff) | |
parent | 31c24577835b0a9c7a1291ffbda1b61d96818511 (diff) |
Merged master
Diffstat (limited to 'libraries/Wire/Wire.cpp')
-rwxr-xr-x | libraries/Wire/Wire.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index d83f478..4e7a17c 100755 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -15,6 +15,8 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts */ extern "C" { @@ -73,14 +75,14 @@ void TwoWire::begin(int address) begin((uint8_t)address); } -uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) +uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) { // clamp to buffer length if(quantity > BUFFER_LENGTH){ quantity = BUFFER_LENGTH; } // perform blocking read into buffer - uint8_t read = twi_readFrom(address, rxBuffer, quantity); + uint8_t read = twi_readFrom(address, rxBuffer, quantity, sendStop); // set rx buffer iterator vars rxBufferIndex = 0; rxBufferLength = read; @@ -88,9 +90,19 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) return read; } +uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) +{ + return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true); +} + uint8_t TwoWire::requestFrom(int address, int quantity) { - return requestFrom((uint8_t)address, (uint8_t)quantity); + return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true); +} + +uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop) +{ + return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop); } void TwoWire::beginTransmission(uint8_t address) @@ -109,10 +121,23 @@ void TwoWire::beginTransmission(int address) beginTransmission((uint8_t)address); } -uint8_t TwoWire::endTransmission(void) +// +// Originally, 'endTransmission' was an f(void) function. +// It has been modified to take one parameter indicating +// whether or not a STOP should be performed on the bus. +// Calling endTransmission(false) allows a sketch to +// perform a repeated start. +// +// WARNING: Nothing in the library keeps track of whether +// the bus tenure has been properly ended with a STOP. It +// is very possible to leave the bus in a hung state if +// no call to endTransmission(true) is made. Some I2C +// devices will behave oddly if they do not see a STOP. +// +uint8_t TwoWire::endTransmission(uint8_t sendStop) { // transmit buffer (blocking) - int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1); + int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1, sendStop); // reset tx buffer iterator vars txBufferIndex = 0; txBufferLength = 0; @@ -121,6 +146,14 @@ uint8_t TwoWire::endTransmission(void) return ret; } +// This provides backwards compatibility with the original +// definition, and expected behaviour, of endTransmission +// +uint8_t TwoWire::endTransmission(void) +{ + return endTransmission(true); +} + // must be called in: // slave tx event callback // or after beginTransmission(address) |