1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Remove WireI2C for now - it is a bit broken

This commit is contained in:
Rhys Weatherley 2012-05-25 14:48:19 +10:00
parent c2fdaee863
commit a76141c56d
6 changed files with 4 additions and 185 deletions

View File

@ -50,14 +50,10 @@ Enterprise model kit.
\section main_I2C I2C Utility Library \section main_I2C I2C Utility Library
\li I2CMaster abstract class that provides an improved API for implementing an \li I2CMaster abstract class that provides an improved API for implementing an
I2C master. The following two classes inherit from I2CMaster: I2C master.
\li SoftI2C class that implements the master side of the I2C protocol \li SoftI2C class that implements the master side of the I2C protocol
in software on any arbitrary pair of pins for DATA and CLOCK. in software on any arbitrary pair of pins for DATA and CLOCK.
This class supports both 7-bit and 10-bit I2C addresses. This class supports both 7-bit and 10-bit I2C addresses.
\li WireI2C class that uses the Arduino Wire library to implement the
master side of the I2C protocol. This class only supports 7-bit addresses
and runs on predefined DATA and CLOCK pins (A4 and A5 on most boards,
D20 and D21 for Arduino Mega).
\section main_RTC Realtime Clock Library \section main_RTC Realtime Clock Library

View File

@ -26,7 +26,7 @@
* \class I2CMaster I2CMaster.h <I2CMaster.h> * \class I2CMaster I2CMaster.h <I2CMaster.h>
* \brief Abstract base class for I2C master implementations. * \brief Abstract base class for I2C master implementations.
* *
* \sa SoftI2C, WireI2C * \sa SoftI2C
*/ */
/** /**

View File

@ -29,13 +29,13 @@
* *
* This class implements the I2C master protocol on any arbitrary pair * This class implements the I2C master protocol on any arbitrary pair
* of data and clock pins. It is not restricted to pre-defined pins as * of data and clock pins. It is not restricted to pre-defined pins as
* is the case for WireI2C. * is the case for the standard Arduino two-wire interface.
* *
* This implementation only implements the master side of the protocol. * This implementation only implements the master side of the protocol.
* It assumes that there is a single bus master, no arbitration, and * It assumes that there is a single bus master, no arbitration, and
* no clock stretching. * no clock stretching.
* *
* \sa I2CMaster, WireI2C * \sa I2CMaster
*/ */
#define i2cDelay() delayMicroseconds(5) #define i2cDelay() delayMicroseconds(5)

View File

@ -1,127 +0,0 @@
/*
* Copyright (C) 2012 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "WireI2C.h"
#include <WProgram.h>
namespace wireI2C {
// XXX: Apparently Arduino libraries cannot directly include each other,
// so we need to work around that by directly pulling in the twi code.
// We hide it in its own namespace just in case the application uses
// Wire directly. Take advantage of the include path to find the
// system-installed twi library.
#include "../../../../libraries/Wire/utility/twi.c"
};
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define SDA_PIN 20
#define SCL_PIN 21
#else
#define SDA_PIN A4
#define SCL_PIN A5
#endif
/**
* \class WireI2C WireI2C.h <WireI2C.h>
* \brief Implementation of an I2C master using the Arduino two-wire interface.
*
* This class implements the I2C master protocol on pre-defined DATA and
* CLOCK pins (A4 and A5 on most boards, D20 and D21 for Arduino Mega).
* For other non-standard pins, use the SoftI2C class instead.
*
* This implementation only implements the master side of the protocol.
* Use the standard Arduino Wire library for slave I2C implementations.
*
* \sa I2CMaster, SoftI2C
*/
/**
* \brief Constructs a new I2C bus master using the Arduino two-wire interface.
*
* If \a useInternalPullups is true (the default) then internal pullups
* will be enabled on the DATA and CLOCK pins. If \a useInternalPullups
* is false, then the external circuit will need to provide pullup resistors.
*/
WireI2C::WireI2C(bool useInternalPullups)
: slaveAddr(0xFF)
, buflen(0)
, bufposn(0)
{
pinMode(SDA_PIN, INPUT);
pinMode(SCL_PIN, INPUT);
if (useInternalPullups) {
digitalWrite(SDA_PIN, HIGH);
digitalWrite(SCL_PIN, HIGH);
}
wireI2C::twi_init();
}
unsigned int WireI2C::maxTransferSize() const
{
return sizeof(buffer);
}
void WireI2C::startWrite(unsigned int address)
{
slaveAddr = (uint8_t)address;
buflen = 0;
}
void WireI2C::write(uint8_t value)
{
if (buflen < sizeof(buffer))
buffer[buflen++] = value;
}
bool WireI2C::endWrite()
{
uint8_t result = wireI2C::twi_writeTo(slaveAddr, buffer, buflen, 1);
slaveAddr = 0xFF;
return result == 0;
}
bool WireI2C::startRead(unsigned int address, unsigned int count)
{
if (slaveAddr != 0xFF) {
// There is a write operation open, so flush it first.
if (!endWrite())
return false;
}
if (count > sizeof(buffer))
count = sizeof(buffer);
bufposn = 0;
buflen = wireI2C::twi_readFrom((uint8_t)address, buffer, (uint8_t)count);
return true;
}
unsigned int WireI2C::available()
{
return buflen - bufposn;
}
uint8_t WireI2C::read()
{
if (bufposn < buflen)
return buffer[bufposn++];
else
return 0;
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (C) 2012 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef WireI2C_h
#define WireI2C_h
#include "I2CMaster.h"
class WireI2C : public I2CMaster {
public:
explicit WireI2C(bool useInternalPullups = true);
unsigned int maxTransferSize() const;
void startWrite(unsigned int address);
void write(uint8_t value);
bool endWrite();
bool startRead(unsigned int address, unsigned int count);
unsigned int available();
uint8_t read();
private:
uint8_t slaveAddr;
uint8_t buffer[32];
uint8_t buflen;
uint8_t bufposn;
};
#endif

View File

@ -1,6 +1,5 @@
I2CMaster KEYWORD1 I2CMaster KEYWORD1
SoftI2C KEYWORD1 SoftI2C KEYWORD1
WireI2C KEYWORD1
maxTransferSize KEYWORD2 maxTransferSize KEYWORD2
startWrite KEYWORD2 startWrite KEYWORD2