mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
Statically allocating buffers in Wire library (issue #351).
This commit is contained in:
parent
27cfd22066
commit
bf88db8484
@ -28,12 +28,12 @@ extern "C" {
|
||||
|
||||
// Initialize Class Variables //////////////////////////////////////////////////
|
||||
|
||||
uint8_t* TwoWire::rxBuffer = 0;
|
||||
uint8_t TwoWire::rxBuffer[BUFFER_LENGTH];
|
||||
uint8_t TwoWire::rxBufferIndex = 0;
|
||||
uint8_t TwoWire::rxBufferLength = 0;
|
||||
|
||||
uint8_t TwoWire::txAddress = 0;
|
||||
uint8_t* TwoWire::txBuffer = 0;
|
||||
uint8_t TwoWire::txBuffer[BUFFER_LENGTH];
|
||||
uint8_t TwoWire::txBufferIndex = 0;
|
||||
uint8_t TwoWire::txBufferLength = 0;
|
||||
|
||||
@ -51,13 +51,9 @@ TwoWire::TwoWire()
|
||||
|
||||
void TwoWire::begin(void)
|
||||
{
|
||||
// init buffer for reads
|
||||
rxBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
|
||||
rxBufferIndex = 0;
|
||||
rxBufferLength = 0;
|
||||
|
||||
// init buffer for writes
|
||||
txBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
|
||||
txBufferIndex = 0;
|
||||
txBufferLength = 0;
|
||||
|
||||
|
@ -27,12 +27,12 @@
|
||||
class TwoWire
|
||||
{
|
||||
private:
|
||||
static uint8_t* rxBuffer;
|
||||
static uint8_t rxBuffer[];
|
||||
static uint8_t rxBufferIndex;
|
||||
static uint8_t rxBufferLength;
|
||||
|
||||
static uint8_t txAddress;
|
||||
static uint8_t* txBuffer;
|
||||
static uint8_t txBuffer[];
|
||||
static uint8_t txBufferIndex;
|
||||
static uint8_t txBufferLength;
|
||||
|
||||
|
@ -40,15 +40,15 @@ static uint8_t twi_slarw;
|
||||
static void (*twi_onSlaveTransmit)(void);
|
||||
static void (*twi_onSlaveReceive)(uint8_t*, int);
|
||||
|
||||
static uint8_t* twi_masterBuffer;
|
||||
static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH];
|
||||
static volatile uint8_t twi_masterBufferIndex;
|
||||
static uint8_t twi_masterBufferLength;
|
||||
|
||||
static uint8_t* twi_txBuffer;
|
||||
static uint8_t twi_txBuffer[TWI_BUFFER_LENGTH];
|
||||
static volatile uint8_t twi_txBufferIndex;
|
||||
static volatile uint8_t twi_txBufferLength;
|
||||
|
||||
static uint8_t* twi_rxBuffer;
|
||||
static uint8_t twi_rxBuffer[TWI_BUFFER_LENGTH];
|
||||
static volatile uint8_t twi_rxBufferIndex;
|
||||
|
||||
static volatile uint8_t twi_error;
|
||||
@ -88,11 +88,6 @@ void twi_init(void)
|
||||
|
||||
// enable twi module, acks, and twi interrupt
|
||||
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);
|
||||
|
||||
// allocate buffers
|
||||
twi_masterBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
|
||||
twi_txBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
|
||||
twi_rxBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user