aboutsummaryrefslogtreecommitdiff
path: root/libraries/Wire
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/Wire')
-rwxr-xr-xlibraries/Wire/Wire.cpp17
-rwxr-xr-xlibraries/Wire/Wire.h11
-rwxr-xr-xlibraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino (renamed from libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.pde)0
-rw-r--r--libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino (renamed from libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde)0
-rw-r--r--libraries/Wire/examples/master_reader/master_reader.ino (renamed from libraries/Wire/examples/master_reader/master_reader.pde)0
-rw-r--r--libraries/Wire/examples/master_writer/master_writer.ino (renamed from libraries/Wire/examples/master_writer/master_writer.pde)0
-rw-r--r--libraries/Wire/examples/slave_receiver/slave_receiver.ino (renamed from libraries/Wire/examples/slave_receiver/slave_receiver.pde)0
-rw-r--r--libraries/Wire/examples/slave_sender/slave_sender.ino (renamed from libraries/Wire/examples/slave_sender/slave_sender.pde)0
-rw-r--r--libraries/Wire/utility/twi.c18
9 files changed, 20 insertions, 26 deletions
diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp
index 5818bee..d83f478 100755
--- a/libraries/Wire/Wire.cpp
+++ b/libraries/Wire/Wire.cpp
@@ -124,13 +124,14 @@ uint8_t TwoWire::endTransmission(void)
// must be called in:
// slave tx event callback
// or after beginTransmission(address)
-void TwoWire::write(uint8_t data)
+size_t TwoWire::write(uint8_t data)
{
if(transmitting){
// in master transmitter mode
// don't bother if buffer is full
if(txBufferLength >= BUFFER_LENGTH){
- return;
+ setWriteError();
+ return 0;
}
// put byte in tx buffer
txBuffer[txBufferIndex] = data;
@@ -142,12 +143,13 @@ void TwoWire::write(uint8_t data)
// reply to master
twi_transmit(&data, 1);
}
+ return 1;
}
// must be called in:
// slave tx event callback
// or after beginTransmission(address)
-void TwoWire::write(const uint8_t *data, size_t quantity)
+size_t TwoWire::write(const uint8_t *data, size_t quantity)
{
if(transmitting){
// in master transmitter mode
@@ -159,14 +161,7 @@ void TwoWire::write(const uint8_t *data, size_t quantity)
// reply to master
twi_transmit(data, quantity);
}
-}
-
-// must be called in:
-// slave tx event callback
-// or after beginTransmission(address)
-void TwoWire::write(const char *data)
-{
- write((uint8_t*)data, strlen(data));
+ return quantity;
}
// must be called in:
diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h
index 51df04e..9ea4afd 100755
--- a/libraries/Wire/Wire.h
+++ b/libraries/Wire/Wire.h
@@ -52,15 +52,20 @@ class TwoWire : public Stream
uint8_t endTransmission(void);
uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(int, int);
- virtual void write(uint8_t);
- virtual void write(const char *);
- virtual void write(const uint8_t *, size_t);
+ virtual size_t write(uint8_t);
+ virtual size_t write(const uint8_t *, size_t);
virtual int available(void);
virtual int read(void);
virtual int peek(void);
virtual void flush(void);
void onReceive( void (*)(int) );
void onRequest( void (*)(void) );
+
+ inline size_t write(unsigned long n) { return write((uint8_t)n); }
+ inline size_t write(long n) { return write((uint8_t)n); }
+ inline size_t write(unsigned int n) { return write((uint8_t)n); }
+ inline size_t write(int n) { return write((uint8_t)n); }
+ using Print::write;
};
extern TwoWire Wire;
diff --git a/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.pde b/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino
index 9c41c18..9c41c18 100755
--- a/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.pde
+++ b/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino
diff --git a/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde b/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino
index 38da1c5..38da1c5 100644
--- a/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde
+++ b/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino
diff --git a/libraries/Wire/examples/master_reader/master_reader.pde b/libraries/Wire/examples/master_reader/master_reader.ino
index 4124d7d..4124d7d 100644
--- a/libraries/Wire/examples/master_reader/master_reader.pde
+++ b/libraries/Wire/examples/master_reader/master_reader.ino
diff --git a/libraries/Wire/examples/master_writer/master_writer.pde b/libraries/Wire/examples/master_writer/master_writer.ino
index ccaa036..ccaa036 100644
--- a/libraries/Wire/examples/master_writer/master_writer.pde
+++ b/libraries/Wire/examples/master_writer/master_writer.ino
diff --git a/libraries/Wire/examples/slave_receiver/slave_receiver.pde b/libraries/Wire/examples/slave_receiver/slave_receiver.ino
index 60dd4bd..60dd4bd 100644
--- a/libraries/Wire/examples/slave_receiver/slave_receiver.pde
+++ b/libraries/Wire/examples/slave_receiver/slave_receiver.ino
diff --git a/libraries/Wire/examples/slave_sender/slave_sender.pde b/libraries/Wire/examples/slave_sender/slave_sender.ino
index d3b238a..d3b238a 100644
--- a/libraries/Wire/examples/slave_sender/slave_sender.pde
+++ b/libraries/Wire/examples/slave_sender/slave_sender.ino
diff --git a/libraries/Wire/utility/twi.c b/libraries/Wire/utility/twi.c
index cef8373..d80114b 100644
--- a/libraries/Wire/utility/twi.c
+++ b/libraries/Wire/utility/twi.c
@@ -23,6 +23,7 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <compat/twi.h>
+#include "Arduino.h" // for digitalWrite
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
@@ -32,6 +33,7 @@
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
+#include "pins_arduino.h"
#include "twi.h"
static volatile uint8_t twi_state;
@@ -63,18 +65,10 @@ void twi_init(void)
{
// initialize state
twi_state = TWI_READY;
-
- #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__)
- // activate internal pull-ups for twi
- // as per note from atmega8 manual pg167
- sbi(PORTC, 4);
- sbi(PORTC, 5);
- #else
- // activate internal pull-ups for twi
- // as per note from atmega128 manual pg204
- sbi(PORTD, 0);
- sbi(PORTD, 1);
- #endif
+
+ // activate internal pullups for twi.
+ digitalWrite(SDA, 1);
+ digitalWrite(SCL, 1);
// initialize twi prescaler and bit rate
cbi(TWSR, TWPS0);