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

Rename BitBangI2C to SoftI2C

This commit is contained in:
Rhys Weatherley 2012-05-18 10:17:48 +10:00
parent 2cdadae890
commit a265ef1755
7 changed files with 37 additions and 34 deletions

View File

@ -24,16 +24,16 @@
#include <FreetronicsLCD.h> #include <FreetronicsLCD.h>
#include <Form.h> #include <Form.h>
#include <Field.h> #include <Field.h>
#include <BitBangI2C.h> #include <SoftI2C.h>
#include <DS1307RTC.h> #include <DS1307RTC.h>
#include <Melody.h> #include <Melody.h>
// I/O pins that are used by this sketch. // I/O pins that are used by this sketch.
#define BUZZER 12 #define BUZZER 12
#define SENSE_BATTERY A1 #define SENSE_BATTERY A1
#define RTC_DATA A3 #define RTC_DATA A4
#define RTC_CLOCK A4 #define RTC_CLOCK A5
#define RTC_ONE_HZ A5 #define RTC_ONE_HZ A3
// Value to adjust for the voltage drop on D2. // Value to adjust for the voltage drop on D2.
#define VOLTAGE_DROP_ADJUST 70 // 0.7 volts #define VOLTAGE_DROP_ADJUST 70 // 0.7 volts
@ -52,7 +52,7 @@
FreetronicsLCD lcd; FreetronicsLCD lcd;
// Activate the realtime clock chip. // Activate the realtime clock chip.
BitBangI2C bus(RTC_DATA, RTC_CLOCK); SoftI2C bus(RTC_DATA, RTC_CLOCK);
DS1307RTC rtc(bus, RTC_ONE_HZ); DS1307RTC rtc(bus, RTC_ONE_HZ);
// Melody to play when the alarm sounds. // Melody to play when the alarm sounds.

View File

@ -51,8 +51,8 @@ Enterprise model kit.
\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. The following two classes inherit from I2CMaster:
\li BitBangI2C class that implements the master side of the I2C protocol \li SoftI2C class that implements the master side of the I2C protocol
using "bit-banging" 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 \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 master side of the I2C protocol. This class only supports 7-bit addresses

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 BitBangI2C, WireI2C * \sa SoftI2C, WireI2C
*/ */
/** /**

View File

@ -20,11 +20,11 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#include "BitBangI2C.h" #include "SoftI2C.h"
#include <WProgram.h> #include <WProgram.h>
/** /**
* \class BitBangI2C BitBangI2C.h <BitBangI2C.h> * \class SoftI2C SoftI2C.h <SoftI2C.h>
* \brief Bit-banged implementation of an I2C master. * \brief Bit-banged implementation of an I2C master.
* *
* This class implements the I2C master protocol on any arbitrary pair * This class implements the I2C master protocol on any arbitrary pair
@ -41,9 +41,9 @@
#define i2cDelay() delayMicroseconds(5) #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) : _dataPin(dataPin)
, _clockPin(clockPin) , _clockPin(clockPin)
, started(false) , started(false)
@ -58,12 +58,12 @@ BitBangI2C::BitBangI2C(uint8_t dataPin, uint8_t clockPin)
digitalWrite(_dataPin, HIGH); digitalWrite(_dataPin, HIGH);
} }
unsigned int BitBangI2C::maxTransferSize() const unsigned int SoftI2C::maxTransferSize() const
{ {
return 0xFFFF; return 0xFFFF;
} }
void BitBangI2C::start() void SoftI2C::start()
{ {
pinMode(_dataPin, OUTPUT); pinMode(_dataPin, OUTPUT);
if (started) { if (started) {
@ -80,7 +80,7 @@ void BitBangI2C::start()
acked = true; acked = true;
} }
void BitBangI2C::stop() void SoftI2C::stop()
{ {
pinMode(_dataPin, OUTPUT); pinMode(_dataPin, OUTPUT);
digitalWrite(_dataPin, LOW); digitalWrite(_dataPin, LOW);
@ -97,7 +97,7 @@ void BitBangI2C::stop()
#define I2C_READ 0x01 #define I2C_READ 0x01
#define I2C_READ10 0xF1 #define I2C_READ10 0xF1
void BitBangI2C::startWrite(unsigned int address) void SoftI2C::startWrite(unsigned int address)
{ {
start(); start();
inWrite = true; 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; uint8_t mask = 0x80;
while (mask != 0) { while (mask != 0) {
@ -122,13 +122,13 @@ void BitBangI2C::write(uint8_t value)
acked = false; acked = false;
} }
bool BitBangI2C::endWrite() bool SoftI2C::endWrite()
{ {
stop(); stop();
return acked; return acked;
} }
bool BitBangI2C::startRead(unsigned int address, unsigned int count) bool SoftI2C::startRead(unsigned int address, unsigned int count)
{ {
start(); start();
inWrite = false; inWrite = false;
@ -148,12 +148,12 @@ bool BitBangI2C::startRead(unsigned int address, unsigned int count)
return true; return true;
} }
unsigned int BitBangI2C::available() unsigned int SoftI2C::available()
{ {
return readCount; return readCount;
} }
uint8_t BitBangI2C::read() uint8_t SoftI2C::read()
{ {
uint8_t value = 0; uint8_t value = 0;
for (uint8_t bit = 0; bit < 8; ++bit) for (uint8_t bit = 0; bit < 8; ++bit)
@ -171,7 +171,7 @@ uint8_t BitBangI2C::read()
return value; return value;
} }
void BitBangI2C::writeBit(bool bit) void SoftI2C::writeBit(bool bit)
{ {
pinMode(_dataPin, OUTPUT); pinMode(_dataPin, OUTPUT);
if (bit) if (bit)
@ -185,7 +185,7 @@ void BitBangI2C::writeBit(bool bit)
i2cDelay(); i2cDelay();
} }
bool BitBangI2C::readBit() bool SoftI2C::readBit()
{ {
pinMode(_dataPin, INPUT); pinMode(_dataPin, INPUT);
digitalWrite(_dataPin, HIGH); digitalWrite(_dataPin, HIGH);

View File

@ -20,14 +20,14 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#ifndef BitBangI2C_h #ifndef SoftI2C_h
#define BitBangI2C_h #define SoftI2C_h
#include "I2CMaster.h" #include "I2CMaster.h"
class BitBangI2C : public I2CMaster { class SoftI2C : public I2CMaster {
public: public:
BitBangI2C(uint8_t dataPin, uint8_t clockPin); SoftI2C(uint8_t dataPin, uint8_t clockPin);
unsigned int maxTransferSize() const; unsigned int maxTransferSize() const;

View File

@ -46,12 +46,12 @@ namespace wireI2C {
* *
* This class implements the I2C master protocol on pre-defined DATA and * 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). * 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. * This implementation only implements the master side of the protocol.
* Use the standard Arduino Wire library for slave I2C implementations. * Use the standard Arduino Wire library for slave I2C implementations.
* *
* \sa I2CMaster, BitBangI2C * \sa I2CMaster, SoftI2C
*/ */
/** /**

View File

@ -1,8 +1,11 @@
BitBangI2C KEYWORD1 I2CMaster KEYWORD1
SoftI2C KEYWORD1
WireI2C KEYWORD1
start KEYWORD2 maxTransferSize KEYWORD2
stop KEYWORD2
startRead KEYWORD2
startWrite KEYWORD2 startWrite KEYWORD2
read KEYWORD2
write KEYWORD2 write KEYWORD2
endWrite KEYWORD2
startRead KEYWORD2
available KEYWORD2
read KEYWORD2