Browse Source

Inline all trivial functions

main
PaulStoffregen 7 years ago
parent
commit
edcffbc7cd
2 changed files with 49 additions and 89 deletions
  1. +2
    -70
      WireKinetis.cpp
  2. +47
    -19
      WireKinetis.h

+ 2
- 70
WireKinetis.cpp View File

@@ -21,7 +21,7 @@

#include "Wire.h"

#if defined(__arm__) && defined(CORE_TEENSY)
#if defined(__arm__) && defined(TEENSYDUINO)

#include "kinetis.h"
#include <string.h> // for memcpy
@@ -518,13 +518,6 @@ static void i2c_wait(void)
I2C0_S = I2C_S_IICIF;
}

void TwoWire::beginTransmission(uint8_t address)
{
txBuffer[0] = (address << 1);
transmitting = 1;
txBufferLength = 1;
}

size_t TwoWire::write(uint8_t data)
{
if (transmitting || slave_mode) {
@@ -553,10 +546,6 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity)
return 0;
}

void TwoWire::flush(void)
{
}


uint8_t TwoWire::endTransmission(uint8_t sendStop)
{
@@ -705,67 +694,10 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t length, uint8_t sendStop)
return count;
}

int TwoWire::available(void)
{
return rxBufferLength - rxBufferIndex;
}

int TwoWire::read(void)
{
if (rxBufferIndex >= rxBufferLength) return -1;
return rxBuffer[rxBufferIndex++];
}

int TwoWire::peek(void)
{
if (rxBufferIndex >= rxBufferLength) return -1;
return rxBuffer[rxBufferIndex];
}





// alternate function prototypes

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)
{
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(int address)
{
beginTransmission((uint8_t)address);
}

uint8_t TwoWire::endTransmission(void)
{
return endTransmission(true);
}

void TwoWire::onReceive( void (*function)(int) )
{
user_onReceive = function;
}

void TwoWire::onRequest( void (*function)(void) )
{
user_onRequest = function;
}

//TwoWire Wire = TwoWire();
TwoWire Wire;


#endif // __MK20DX128__ || __MK20DX256__

#endif // __arm__ && TEENSYDUINO

+ 47
- 19
WireKinetis.h View File

@@ -49,25 +49,53 @@ public:
begin((uint8_t)address);
}
void end();
void setClock(uint32_t);
void setSDA(uint8_t);
void setSCL(uint8_t);
void beginTransmission(uint8_t);
void beginTransmission(int);
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);
uint8_t requestFrom(int, int);
uint8_t requestFrom(int, int, int);
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 (*function)(int));
void onRequest(void (*function)(void));
void setClock(uint32_t frequency);
void setSDA(uint8_t pin);
void setSCL(uint8_t pin);
void beginTransmission(uint8_t address) {
txBuffer[0] = (address << 1);
transmitting = 1;
txBufferLength = 1;
}
void beginTransmission(int address) {
beginTransmission((uint8_t)address);
}
uint8_t endTransmission(uint8_t sendStop);
uint8_t endTransmission(void) {
return endTransmission(1);
}
uint8_t requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop);
uint8_t requestFrom(uint8_t address, uint8_t quantity) {
return requestFrom(address, quantity, (uint8_t)1);
}
uint8_t requestFrom(int address, int quantity, int sendStop) {
return requestFrom((uint8_t)address, (uint8_t)quantity,
(uint8_t)(sendStop ? 1 : 0));
}
uint8_t requestFrom(int address, int quantity) {
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)1);
}
virtual size_t write(uint8_t data);
virtual size_t write(const uint8_t *data, size_t quantity);
virtual int available(void) {
return rxBufferLength - rxBufferIndex;
}
virtual int read(void) {
if (rxBufferIndex >= rxBufferLength) return -1;
return rxBuffer[rxBufferIndex++];
}
virtual int peek(void) {
if (rxBufferIndex >= rxBufferLength) return -1;
return rxBuffer[rxBufferIndex];
}
virtual void flush(void) {
}
void onReceive(void (*function)(int numBytes)) {
user_onReceive = function;
}
void onRequest(void (*function)(void)) {
user_onRequest = function;
}
// send() for compatibility with very old sketches and libraries
void send(uint8_t b) {
write(b);

Loading…
Cancel
Save