Added spi transaction size :-) It still defaults to 128... please adjust downwards if you feel necessary.

This commit is contained in:
Andrew Berridge
2021-06-27 14:53:01 +01:00
parent b7e90c6925
commit cb24b642de
3 changed files with 24 additions and 3 deletions
+2
View File
@@ -55,6 +55,8 @@ end KEYWORD2
setI2CpollingWait KEYWORD2
setI2CTransactionSize KEYWORD2
getI2CTransactionSize KEYWORD2
setSpiTransactionSize KEYWORD2
getSpiTransactionSize KEYWORD2
isConnected KEYWORD2
enableDebugging KEYWORD2
disableDebugging KEYWORD2
+16 -3
View File
@@ -505,6 +505,19 @@ uint8_t SFE_UBLOX_GNSS::getI2CTransactionSize(void)
return (i2cTransactionSize);
}
//Sets the global size for the SPI buffer/transactions.
//Call this before begin()!
//Note: if the buffer size is too small, incoming characters may be lost if the message sent
//is larger than this buffer. If too big, you may run out of SRAM on constrained architectures!
void SFE_UBLOX_GNSS::setSpiTransactionSize(uint8_t transactionSize)
{
spiTransactionSize = transactionSize;
}
uint8_t SFE_UBLOX_GNSS::getSpiTransactionSize(void)
{
return (spiTransactionSize);
}
//Returns true if I2C device ack's
boolean SFE_UBLOX_GNSS::isConnected(uint16_t maxWait)
{
@@ -2851,7 +2864,7 @@ void SFE_UBLOX_GNSS::sendSerialCommand(ubxPacket *outgoingUBX)
void SFE_UBLOX_GNSS::spiTransfer(uint8_t byteToTransfer)
{
uint8_t returnedByte = _spiPort->transfer(byteToTransfer);
if (returnedByte != 0xFF || currentSentence != NONE)
if ((spiBufferIndex < getSpiTransactionSize()) && (returnedByte != 0xFF || currentSentence != NONE))
{
spiBuffer[spiBufferIndex] = returnedByte;
spiBufferIndex++;
@@ -2863,13 +2876,13 @@ void SFE_UBLOX_GNSS::sendSpiCommand(ubxPacket *outgoingUBX)
{
if (spiBuffer == NULL) //Memory has not yet been allocated - so use new
{
spiBuffer = new uint8_t[SPI_BUFFER_SIZE];
spiBuffer = new uint8_t[getSpiTransactionSize()];
}
if (spiBuffer == NULL) {
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
{
_debugSerial->print(F("process: memory allocation failed for SPI Buffer!"));
_debugSerial->print(F("sendSpiCommand: memory allocation failed for SPI Buffer!"));
}
}
@@ -576,6 +576,11 @@ public:
void setI2CTransactionSize(uint8_t bufferSize);
uint8_t getI2CTransactionSize(void);
//Control the size of the spi buffer. If the buffer isn't big enough, we'll start to lose bytes
//That we receive if the buffer is full!
void setSpiTransactionSize(uint8_t bufferSize);
uint8_t getSpiTransactionSize(void);
//Set the max number of bytes set in a given I2C transaction
uint8_t i2cTransactionSize = 32; //Default to ATmega328 limit
@@ -1310,6 +1315,7 @@ private:
uint8_t *spiBuffer = NULL; // A buffer to store any bytes being recieved back from the device while we are sending via SPI
uint8_t spiBufferIndex = 0; // Index into the SPI buffer
uint8_t spiTransactionSize = SPI_BUFFER_SIZE; //Default size of the SPI buffer
//Init the packet structures and init them with pointers to the payloadAck, payloadCfg, payloadBuf and payloadAuto arrays
ubxPacket packetAck = {0, 0, 0, 0, 0, payloadAck, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};