Skip to content

Commit 2e88f1c

Browse files
committed
Merge branch 'add-spi-aberridg' into modify-state-management-aberridg
2 parents aa4af6f + cb24b64 commit 2e88f1c

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ end KEYWORD2
5555
setI2CpollingWait KEYWORD2
5656
setI2CTransactionSize KEYWORD2
5757
getI2CTransactionSize KEYWORD2
58+
setSpiTransactionSize KEYWORD2
59+
getSpiTransactionSize KEYWORD2
5860
isConnected KEYWORD2
5961
enableDebugging KEYWORD2
6062
disableDebugging KEYWORD2

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,19 @@ uint8_t SFE_UBLOX_GNSS::getI2CTransactionSize(void)
505505
return (i2cTransactionSize);
506506
}
507507

508+
//Sets the global size for the SPI buffer/transactions.
509+
//Call this before begin()!
510+
//Note: if the buffer size is too small, incoming characters may be lost if the message sent
511+
//is larger than this buffer. If too big, you may run out of SRAM on constrained architectures!
512+
void SFE_UBLOX_GNSS::setSpiTransactionSize(uint8_t transactionSize)
513+
{
514+
spiTransactionSize = transactionSize;
515+
}
516+
uint8_t SFE_UBLOX_GNSS::getSpiTransactionSize(void)
517+
{
518+
return (spiTransactionSize);
519+
}
520+
508521
//Returns true if I2C device ack's
509522
boolean SFE_UBLOX_GNSS::isConnected(uint16_t maxWait)
510523
{
@@ -2784,7 +2797,7 @@ void SFE_UBLOX_GNSS::sendSerialCommand(ubxPacket *outgoingUBX)
27842797
void SFE_UBLOX_GNSS::spiTransfer(uint8_t byteToTransfer)
27852798
{
27862799
uint8_t returnedByte = _spiPort->transfer(byteToTransfer);
2787-
if (returnedByte != 0xFF || currentSentence != NONE)
2800+
if ((spiBufferIndex < getSpiTransactionSize()) && (returnedByte != 0xFF || currentSentence != NONE))
27882801
{
27892802
spiBuffer[spiBufferIndex] = returnedByte;
27902803
spiBufferIndex++;
@@ -2796,13 +2809,13 @@ void SFE_UBLOX_GNSS::sendSpiCommand(ubxPacket *outgoingUBX)
27962809
{
27972810
if (spiBuffer == NULL) //Memory has not yet been allocated - so use new
27982811
{
2799-
spiBuffer = new uint8_t[SPI_BUFFER_SIZE];
2812+
spiBuffer = new uint8_t[getSpiTransactionSize()];
28002813
}
28012814

28022815
if (spiBuffer == NULL) {
28032816
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
28042817
{
2805-
_debugSerial->print(F("process: memory allocation failed for SPI Buffer!"));
2818+
_debugSerial->print(F("sendSpiCommand: memory allocation failed for SPI Buffer!"));
28062819
}
28072820
}
28082821

src/SparkFun_u-blox_GNSS_Arduino_Library.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ class SFE_UBLOX_GNSS
584584
void setI2CTransactionSize(uint8_t bufferSize);
585585
uint8_t getI2CTransactionSize(void);
586586

587+
//Control the size of the spi buffer. If the buffer isn't big enough, we'll start to lose bytes
588+
//That we receive if the buffer is full!
589+
void setSpiTransactionSize(uint8_t bufferSize);
590+
uint8_t getSpiTransactionSize(void);
591+
587592
//Set the max number of bytes set in a given I2C transaction
588593
uint8_t i2cTransactionSize = 32; //Default to ATmega328 limit
589594

@@ -1318,6 +1323,7 @@ class SFE_UBLOX_GNSS
13181323

13191324
uint8_t *spiBuffer = NULL; // A buffer to store any bytes being recieved back from the device while we are sending via SPI
13201325
uint8_t spiBufferIndex = 0; // Index into the SPI buffer
1326+
uint8_t spiTransactionSize = SPI_BUFFER_SIZE; //Default size of the SPI buffer
13211327

13221328
//Init the packet structures and init them with pointers to the payloadAck, payloadCfg, payloadBuf and payloadAuto arrays
13231329
ubxPacket packetAck = {0, 0, 0, 0, 0, payloadAck, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};

0 commit comments

Comments
 (0)