diff --git a/AlarmClock/AlarmClock.pde b/AlarmClock/AlarmClock.pde index 292a1465..5fbdac3b 100644 --- a/AlarmClock/AlarmClock.pde +++ b/AlarmClock/AlarmClock.pde @@ -24,16 +24,16 @@ #include #include #include -#include +#include #include #include // I/O pins that are used by this sketch. #define BUZZER 12 #define SENSE_BATTERY A1 -#define RTC_DATA A3 -#define RTC_CLOCK A4 -#define RTC_ONE_HZ A5 +#define RTC_DATA A4 +#define RTC_CLOCK A5 +#define RTC_ONE_HZ A3 // Value to adjust for the voltage drop on D2. #define VOLTAGE_DROP_ADJUST 70 // 0.7 volts @@ -52,7 +52,7 @@ FreetronicsLCD lcd; // Activate the realtime clock chip. -BitBangI2C bus(RTC_DATA, RTC_CLOCK); +SoftI2C bus(RTC_DATA, RTC_CLOCK); DS1307RTC rtc(bus, RTC_ONE_HZ); // Melody to play when the alarm sounds. diff --git a/doc/mainpage.dox b/doc/mainpage.dox index 6015fd3c..605cf4c1 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -51,8 +51,8 @@ Enterprise model kit. \li I2CMaster abstract class that provides an improved API for implementing an I2C master. The following two classes inherit from I2CMaster: -\li BitBangI2C class that implements the master side of the I2C protocol -using "bit-banging" on any arbitrary pair of pins for DATA and CLOCK. +\li SoftI2C class that implements the master side of the I2C protocol +in software on any arbitrary pair of pins for DATA and CLOCK. 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 diff --git a/libraries/I2C/I2CMaster.cpp b/libraries/I2C/I2CMaster.cpp index 9259cbc9..dfff9ab3 100644 --- a/libraries/I2C/I2CMaster.cpp +++ b/libraries/I2C/I2CMaster.cpp @@ -26,7 +26,7 @@ * \class I2CMaster I2CMaster.h * \brief Abstract base class for I2C master implementations. * - * \sa BitBangI2C, WireI2C + * \sa SoftI2C, WireI2C */ /** diff --git a/libraries/I2C/BitBangI2C.cpp b/libraries/I2C/SoftI2C.cpp similarity index 87% rename from libraries/I2C/BitBangI2C.cpp rename to libraries/I2C/SoftI2C.cpp index 862e31c6..d0dfc4c0 100644 --- a/libraries/I2C/BitBangI2C.cpp +++ b/libraries/I2C/SoftI2C.cpp @@ -20,11 +20,11 @@ * DEALINGS IN THE SOFTWARE. */ -#include "BitBangI2C.h" +#include "SoftI2C.h" #include /** - * \class BitBangI2C BitBangI2C.h + * \class SoftI2C SoftI2C.h * \brief Bit-banged implementation of an I2C master. * * This class implements the I2C master protocol on any arbitrary pair @@ -41,9 +41,9 @@ #define i2cDelay() delayMicroseconds(5) /** - * \brief Constructs a new bit-banged I2C master on \a dataPin and \a clockPin. + * \brief Constructs a new software I2C master on \a dataPin and \a clockPin. */ -BitBangI2C::BitBangI2C(uint8_t dataPin, uint8_t clockPin) +SoftI2C::SoftI2C(uint8_t dataPin, uint8_t clockPin) : _dataPin(dataPin) , _clockPin(clockPin) , started(false) @@ -58,12 +58,12 @@ BitBangI2C::BitBangI2C(uint8_t dataPin, uint8_t clockPin) digitalWrite(_dataPin, HIGH); } -unsigned int BitBangI2C::maxTransferSize() const +unsigned int SoftI2C::maxTransferSize() const { return 0xFFFF; } -void BitBangI2C::start() +void SoftI2C::start() { pinMode(_dataPin, OUTPUT); if (started) { @@ -80,7 +80,7 @@ void BitBangI2C::start() acked = true; } -void BitBangI2C::stop() +void SoftI2C::stop() { pinMode(_dataPin, OUTPUT); digitalWrite(_dataPin, LOW); @@ -97,7 +97,7 @@ void BitBangI2C::stop() #define I2C_READ 0x01 #define I2C_READ10 0xF1 -void BitBangI2C::startWrite(unsigned int address) +void SoftI2C::startWrite(unsigned int address) { start(); inWrite = true; @@ -111,7 +111,7 @@ void BitBangI2C::startWrite(unsigned int address) } } -void BitBangI2C::write(uint8_t value) +void SoftI2C::write(uint8_t value) { uint8_t mask = 0x80; while (mask != 0) { @@ -122,13 +122,13 @@ void BitBangI2C::write(uint8_t value) acked = false; } -bool BitBangI2C::endWrite() +bool SoftI2C::endWrite() { stop(); return acked; } -bool BitBangI2C::startRead(unsigned int address, unsigned int count) +bool SoftI2C::startRead(unsigned int address, unsigned int count) { start(); inWrite = false; @@ -148,12 +148,12 @@ bool BitBangI2C::startRead(unsigned int address, unsigned int count) return true; } -unsigned int BitBangI2C::available() +unsigned int SoftI2C::available() { return readCount; } -uint8_t BitBangI2C::read() +uint8_t SoftI2C::read() { uint8_t value = 0; for (uint8_t bit = 0; bit < 8; ++bit) @@ -171,7 +171,7 @@ uint8_t BitBangI2C::read() return value; } -void BitBangI2C::writeBit(bool bit) +void SoftI2C::writeBit(bool bit) { pinMode(_dataPin, OUTPUT); if (bit) @@ -185,7 +185,7 @@ void BitBangI2C::writeBit(bool bit) i2cDelay(); } -bool BitBangI2C::readBit() +bool SoftI2C::readBit() { pinMode(_dataPin, INPUT); digitalWrite(_dataPin, HIGH); diff --git a/libraries/I2C/BitBangI2C.h b/libraries/I2C/SoftI2C.h similarity index 92% rename from libraries/I2C/BitBangI2C.h rename to libraries/I2C/SoftI2C.h index aa0be8c5..0b69d061 100644 --- a/libraries/I2C/BitBangI2C.h +++ b/libraries/I2C/SoftI2C.h @@ -20,14 +20,14 @@ * DEALINGS IN THE SOFTWARE. */ -#ifndef BitBangI2C_h -#define BitBangI2C_h +#ifndef SoftI2C_h +#define SoftI2C_h #include "I2CMaster.h" -class BitBangI2C : public I2CMaster { +class SoftI2C : public I2CMaster { public: - BitBangI2C(uint8_t dataPin, uint8_t clockPin); + SoftI2C(uint8_t dataPin, uint8_t clockPin); unsigned int maxTransferSize() const; diff --git a/libraries/I2C/WireI2C.cpp b/libraries/I2C/WireI2C.cpp index 0ba4a21a..7052f600 100644 --- a/libraries/I2C/WireI2C.cpp +++ b/libraries/I2C/WireI2C.cpp @@ -46,12 +46,12 @@ namespace wireI2C { * * 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 BitBangI2C class instead. + * 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, BitBangI2C + * \sa I2CMaster, SoftI2C */ /** diff --git a/libraries/I2C/keywords.txt b/libraries/I2C/keywords.txt index 1a81d35d..ac3390c8 100644 --- a/libraries/I2C/keywords.txt +++ b/libraries/I2C/keywords.txt @@ -1,8 +1,11 @@ -BitBangI2C KEYWORD1 +I2CMaster KEYWORD1 +SoftI2C KEYWORD1 +WireI2C KEYWORD1 -start KEYWORD2 -stop KEYWORD2 -startRead KEYWORD2 +maxTransferSize KEYWORD2 startWrite KEYWORD2 -read KEYWORD2 write KEYWORD2 +endWrite KEYWORD2 +startRead KEYWORD2 +available KEYWORD2 +read KEYWORD2