Add support for SPI interface

This commit is contained in:
Andrew Berridge
2021-06-27 06:00:16 +01:00
parent 46340eaa9c
commit 48ace0a29f
2 changed files with 138 additions and 1 deletions
+17 -1
View File
@@ -51,6 +51,8 @@
#include <Wire.h>
#include <SPI.h>
#include "u-blox_config_keys.h"
#include "u-blox_structs.h"
@@ -560,6 +562,8 @@ public:
boolean begin(TwoWire &wirePort = Wire, uint8_t deviceAddress = 0x42); //Returns true if module is detected
//serialPort needs to be perviously initialized to correct baud rate
boolean begin(Stream &serialPort); //Returns true if module is detected
//SPI - supply instance of SPIClass, slave select pin and SPI speed (in Hz)
boolean begin(SPIClass &spiPort, uint8_t ssPin, int spiSpeed);
void end(void); //Stop all automatic message processing. Free all used RAM
@@ -612,6 +616,7 @@ public:
boolean checkUbloxI2C(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Method for I2C polling of data, passing any new bytes to process()
boolean checkUbloxSerial(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Method for serial polling of data, passing any new bytes to process()
boolean checkUbloxSpi(ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Method for spi polling of data, passing any new bytes to process()
// Process the incoming data
@@ -622,12 +627,13 @@ public:
void processUBX(uint8_t incoming, ubxPacket *incomingUBX, uint8_t requestedClass, uint8_t requestedID); //Given a character, file it away into the uxb packet structure
void processUBXpacket(ubxPacket *msg); //Once a packet has been received and validated, identify this packet's class/id and update internal flags
// Send I2C/Serial commands to the module
// Send I2C/Serial/SPI commands to the module
void calcChecksum(ubxPacket *msg); //Sets the checksumA and checksumB of a given messages
sfe_ublox_status_e sendCommand(ubxPacket *outgoingUBX, uint16_t maxWait = defaultMaxWait, boolean expectACKonly = false); //Given a packet and payload, send everything including CRC bytes, return true if we got a response
sfe_ublox_status_e sendI2cCommand(ubxPacket *outgoingUBX, uint16_t maxWait = defaultMaxWait);
void sendSerialCommand(ubxPacket *outgoingUBX);
void sendSpiCommand(ubxPacket *outgoingUBX);
void printPacket(ubxPacket *packet, boolean alwaysPrintPayload = false); //Useful for debugging
@@ -1235,6 +1241,9 @@ private:
//Calculate how much RAM is needed to store the payload for a given automatic message
uint16_t getMaxPayloadSize(uint8_t Class, uint8_t ID);
//Do the actual transfer to SPI
void spiTransfer(uint8_t byteToTransfer);
boolean initGeofenceParams(); // Allocate RAM for currentGeofenceParams and initialize it
boolean initModuleSWVersion(); // Allocate RAM for moduleSWVersion and initialize it
@@ -1273,6 +1282,10 @@ private:
Stream *_nmeaOutputPort = NULL; //The user can assign an output port to print NMEA sentences if they wish
Stream *_debugSerial; //The stream to send debug messages to if enabled
SPIClass *_spiPort; //The instance of SPIClass
uint8_t _ssPin; //The slave select pin
int _spiSpeed; //The speed to use for SPI (Hz)
uint8_t _gpsI2Caddress = 0x42; //Default 7-bit unshifted address of the ublox 6/7/8/M8/F9 series
//This can be changed using the ublox configuration software
@@ -1292,6 +1305,9 @@ private:
uint8_t *payloadCfg = NULL;
uint8_t *payloadAuto = NULL;
uint8_t spiBuffer[20]; // A small buffer to store any bytes being recieved back from the device while we are sending via SPI
uint8_t spiBufferIndex = 0; // The index into 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};
ubxPacket packetBuf = {0, 0, 0, 0, 0, payloadBuf, 0, 0, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED, SFE_UBLOX_PACKET_VALIDITY_NOT_DEFINED};