mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-03 00:29:21 +01:00
Updated Wire library. Latest API not yet implemented.
This commit is contained in:
parent
8140a47bb9
commit
3062c550b0
@ -113,7 +113,7 @@ void TwoWire::begin(int address) {
|
|||||||
begin((uint8_t) 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) {
|
||||||
if (quantity > BUFFER_LENGTH)
|
if (quantity > BUFFER_LENGTH)
|
||||||
quantity = BUFFER_LENGTH;
|
quantity = BUFFER_LENGTH;
|
||||||
|
|
||||||
@ -137,8 +137,16 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) {
|
|||||||
return readed;
|
return readed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
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) {
|
void TwoWire::beginTransmission(uint8_t address) {
|
||||||
@ -153,7 +161,20 @@ void TwoWire::beginTransmission(int address) {
|
|||||||
beginTransmission((uint8_t) 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)
|
// transmit buffer (blocking)
|
||||||
TWI_StartWrite(twi, txAddress, 0, 0, txBuffer[0]);
|
TWI_StartWrite(twi, txAddress, 0, 0, txBuffer[0]);
|
||||||
TWI_WaitByteSent(twi, XMIT_TIMEOUT);
|
TWI_WaitByteSent(twi, XMIT_TIMEOUT);
|
||||||
@ -172,36 +193,43 @@ uint8_t TwoWire::endTransmission(void) {
|
|||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoWire::write(uint8_t data) {
|
// This provides backwards compatibility with the original
|
||||||
|
// definition, and expected behaviour, of endTransmission
|
||||||
|
//
|
||||||
|
uint8_t TwoWire::endTransmission(void)
|
||||||
|
{
|
||||||
|
return endTransmission(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t TwoWire::write(uint8_t data) {
|
||||||
if (status == MASTER_SEND) {
|
if (status == MASTER_SEND) {
|
||||||
if (txBufferLength >= BUFFER_LENGTH)
|
if (txBufferLength >= BUFFER_LENGTH)
|
||||||
return;
|
return 0;
|
||||||
txBuffer[txBufferLength++] = data;
|
txBuffer[txBufferLength++] = data;
|
||||||
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
if (srvBufferLength >= BUFFER_LENGTH)
|
if (srvBufferLength >= BUFFER_LENGTH)
|
||||||
return;
|
return 0;
|
||||||
srvBuffer[srvBufferLength++] = data;
|
srvBuffer[srvBufferLength++] = data;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoWire::write(const uint8_t *data, size_t quantity) {
|
size_t TwoWire::write(const uint8_t *data, size_t quantity) {
|
||||||
if (status == MASTER_SEND) {
|
if (status == MASTER_SEND) {
|
||||||
for (size_t i = 0; i < quantity; ++i) {
|
for (size_t i = 0; i < quantity; ++i) {
|
||||||
if (txBufferLength >= BUFFER_LENGTH)
|
if (txBufferLength >= BUFFER_LENGTH)
|
||||||
return;
|
return i;
|
||||||
txBuffer[txBufferLength++] = data[i];
|
txBuffer[txBufferLength++] = data[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < quantity; ++i) {
|
for (size_t i = 0; i < quantity; ++i) {
|
||||||
if (srvBufferLength >= BUFFER_LENGTH)
|
if (srvBufferLength >= BUFFER_LENGTH)
|
||||||
return;
|
return i;
|
||||||
srvBuffer[srvBufferLength++] = data[i];
|
srvBuffer[srvBufferLength++] = data[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return quantity;
|
||||||
|
|
||||||
void TwoWire::write(const char *data) {
|
|
||||||
write((uint8_t*) data, strlen(data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TwoWire::available(void) {
|
int TwoWire::available(void) {
|
||||||
@ -303,12 +331,14 @@ void TwoWire::onService(void) {
|
|||||||
|
|
||||||
#if WIRE_INTERFACES_COUNT > 0
|
#if WIRE_INTERFACES_COUNT > 0
|
||||||
static void Wire_Init(void) {
|
static void Wire_Init(void) {
|
||||||
PMC_EnablePeripheral( WIRE_INTERFACE_ID);
|
pmc_enable_periph_clk(WIRE_INTERFACE_ID);
|
||||||
PIO_Configure(g_APinDescription[PIN_WIRE_SDA].pPort,
|
PIO_Configure(
|
||||||
|
g_APinDescription[PIN_WIRE_SDA].pPort,
|
||||||
g_APinDescription[PIN_WIRE_SDA].ulPinType,
|
g_APinDescription[PIN_WIRE_SDA].ulPinType,
|
||||||
g_APinDescription[PIN_WIRE_SDA].ulPin,
|
g_APinDescription[PIN_WIRE_SDA].ulPin,
|
||||||
g_APinDescription[PIN_WIRE_SDA].ulPinConfiguration);
|
g_APinDescription[PIN_WIRE_SDA].ulPinConfiguration);
|
||||||
PIO_Configure(g_APinDescription[PIN_WIRE_SCL].pPort,
|
PIO_Configure(
|
||||||
|
g_APinDescription[PIN_WIRE_SCL].pPort,
|
||||||
g_APinDescription[PIN_WIRE_SCL].ulPinType,
|
g_APinDescription[PIN_WIRE_SCL].ulPinType,
|
||||||
g_APinDescription[PIN_WIRE_SCL].ulPin,
|
g_APinDescription[PIN_WIRE_SCL].ulPin,
|
||||||
g_APinDescription[PIN_WIRE_SCL].ulPinConfiguration);
|
g_APinDescription[PIN_WIRE_SCL].ulPinConfiguration);
|
||||||
@ -328,12 +358,14 @@ void WIRE_ISR_HANDLER(void) {
|
|||||||
|
|
||||||
#if WIRE_INTERFACES_COUNT > 1
|
#if WIRE_INTERFACES_COUNT > 1
|
||||||
static void Wire1_Init(void) {
|
static void Wire1_Init(void) {
|
||||||
PMC_EnablePeripheral( WIRE1_INTERFACE_ID);
|
pmc_enable_periph_clk(WIRE1_INTERFACE_ID);
|
||||||
PIO_Configure(g_APinDescription[PIN_WIRE1_SDA].pPort,
|
PIO_Configure(
|
||||||
|
g_APinDescription[PIN_WIRE1_SDA].pPort,
|
||||||
g_APinDescription[PIN_WIRE1_SDA].ulPinType,
|
g_APinDescription[PIN_WIRE1_SDA].ulPinType,
|
||||||
g_APinDescription[PIN_WIRE1_SDA].ulPin,
|
g_APinDescription[PIN_WIRE1_SDA].ulPin,
|
||||||
g_APinDescription[PIN_WIRE1_SDA].ulPinConfiguration);
|
g_APinDescription[PIN_WIRE1_SDA].ulPinConfiguration);
|
||||||
PIO_Configure(g_APinDescription[PIN_WIRE1_SCL].pPort,
|
PIO_Configure(
|
||||||
|
g_APinDescription[PIN_WIRE1_SCL].pPort,
|
||||||
g_APinDescription[PIN_WIRE1_SCL].ulPinType,
|
g_APinDescription[PIN_WIRE1_SCL].ulPinType,
|
||||||
g_APinDescription[PIN_WIRE1_SCL].ulPin,
|
g_APinDescription[PIN_WIRE1_SCL].ulPin,
|
||||||
g_APinDescription[PIN_WIRE1_SCL].ulPinConfiguration);
|
g_APinDescription[PIN_WIRE1_SCL].ulPinConfiguration);
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define BUFFER_LENGTH 32
|
#define BUFFER_LENGTH 32
|
||||||
|
|
||||||
class TwoWire: public Stream {
|
class TwoWire : public Stream {
|
||||||
public:
|
public:
|
||||||
TwoWire(Twi *twi, void(*begin_cb)(void));
|
TwoWire(Twi *twi, void(*begin_cb)(void));
|
||||||
void begin();
|
void begin();
|
||||||
@ -38,11 +38,13 @@ public:
|
|||||||
void beginTransmission(uint8_t);
|
void beginTransmission(uint8_t);
|
||||||
void beginTransmission(int);
|
void beginTransmission(int);
|
||||||
uint8_t endTransmission(void);
|
uint8_t endTransmission(void);
|
||||||
|
uint8_t endTransmission(uint8_t);
|
||||||
uint8_t requestFrom(uint8_t, uint8_t);
|
uint8_t requestFrom(uint8_t, uint8_t);
|
||||||
|
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
|
||||||
uint8_t requestFrom(int, int);
|
uint8_t requestFrom(int, int);
|
||||||
virtual void write(uint8_t);
|
uint8_t requestFrom(int, int, int);
|
||||||
virtual void write(const char *);
|
virtual size_t write(uint8_t);
|
||||||
virtual void write(const uint8_t *, size_t);
|
virtual size_t write(const uint8_t *, size_t);
|
||||||
virtual int available(void);
|
virtual int available(void);
|
||||||
virtual int read(void);
|
virtual int read(void);
|
||||||
virtual int peek(void);
|
virtual int peek(void);
|
||||||
@ -50,6 +52,12 @@ public:
|
|||||||
void onReceive(void(*)(int));
|
void onReceive(void(*)(int));
|
||||||
void onRequest(void(*)(void));
|
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;
|
||||||
|
|
||||||
void onService(void);
|
void onService(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user