ClusterDuck Protocol
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Module Class Reference

Implements all common low-level SPI/UART/I2C methods to control the wireless module. Every module class contains one private instance of this class. More...

#include <Module.h>

Public Member Functions

 Module (int16_t tx, int16_t rx, HardwareSerial *serial=&Serial1, int16_t rst=NC)
 UART-based module constructor. More...
 
 Module (int16_t tx, int16_t rx, HardwareSerial *serial=nullptr, int16_t rst=NC)
 
 Module (int16_t cs, int16_t irq, int16_t rst)
 SPI-based module constructor. Will use the default SPI interface automatically initialize it. More...
 
 Module (int16_t cs, int16_t irq, int16_t rst, int16_t gpio)
 Extended SPI-based module constructor. Will use the default SPI interface automatically initialize it. More...
 
 Module (int16_t cs, int16_t irq, int16_t rst, SPIClass &spi, SPISettings spiSettings)
 SPI-based module constructor. More...
 
 Module (int16_t cs, int16_t irq, int16_t rst, int16_t gpio, SPIClass &spi, SPISettings spiSettings)
 Extended SPI-based module constructor. More...
 
 Module (int16_t cs, int16_t irq, int16_t rst, int16_t rx, int16_t tx, SPIClass &spi=SPI, SPISettings spiSettings=SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial *serial=&Serial1)
 Generic module constructor. More...
 
 Module (int16_t cs, int16_t irq, int16_t rst, int16_t rx, int16_t tx, SPIClass &spi=SPI, SPISettings spiSettings=SPISettings(2000000, MSBFIRST, SPI_MODE0), HardwareSerial *serial=nullptr)
 
void init (uint8_t interface)
 Initialize low-level module control. More...
 
void term ()
 Terminate low-level module control.
 
void ATemptyBuffer ()
 Empty internal AT buffer.
 
bool ATgetResponse ()
 Get response after sending AT command. More...
 
bool ATsendCommand (const char *cmd)
 Send AT command. Will also call ATgetResponse. More...
 
bool ATsendData (uint8_t *data, uint32_t len)
 Send raw AT data. Will also call ATgetResponse. More...
 
int16_t SPIgetRegValue (uint8_t reg, uint8_t msb=7, uint8_t lsb=0)
 SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism. More...
 
int16_t SPIsetRegValue (uint8_t reg, uint8_t value, uint8_t msb=7, uint8_t lsb=0, uint8_t checkInterval=2)
 Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism. More...
 
void SPIreadRegisterBurst (uint8_t reg, uint8_t numBytes, uint8_t *inBytes)
 SPI burst read method. More...
 
uint8_t SPIreadRegister (uint8_t reg)
 SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead. More...
 
void SPIwriteRegisterBurst (uint8_t reg, uint8_t *data, uint8_t numBytes)
 SPI burst write method. More...
 
void SPIwriteRegister (uint8_t reg, uint8_t data)
 SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead. More...
 
void SPItransfer (uint8_t cmd, uint8_t reg, uint8_t *dataOut, uint8_t *dataIn, uint8_t numBytes)
 SPI single transfer method. More...
 
int16_t getCs () const
 Access method to get the pin number of SPI chip select. More...
 
int16_t getIrq () const
 Access method to get the pin number of interrupt/GPIO. More...
 
int16_t getRst () const
 Access method to get the pin number of hardware reset pin. More...
 
int16_t getGpio () const
 Access method to get the pin number of second interrupt/GPIO. More...
 
int16_t getRx () const
 Access method to get the pin number of UART Rx. More...
 
int16_t getTx () const
 Access method to get the pin number of UART Rx. More...
 
SPIClass * getSpi () const
 Access method to get the SPI interface. More...
 
SPISettings getSpiSettings () const
 Access method to get the SPI interface settings. More...
 

Static Public Member Functions

static void pinMode (int16_t pin, uint8_t mode)
 Arduino core pinMode override that checks -1 as alias for unused pin. More...
 
static void digitalWrite (int16_t pin, uint8_t value)
 Arduino core digitalWrite override that checks -1 as alias for unused pin. More...
 

Public Attributes

HardwareSerial * ModuleSerial
 Internal SoftwareSerial instance.
 
SoftwareSerial * ModuleSerial
 
uint32_t baudrate = 9600
 Baud rate of SoftwareSerial UART communication. Defaults to 9600 baud.
 
const char * AtLineFeed = "\r\n"
 Line feed to be used when sending AT commands. Defaults to CR+LF.
 
uint8_t SPIreadCommand = 0b00000000
 Basic SPI read command. Defaults to 0x00.
 
uint8_t SPIwriteCommand = 0b10000000
 Basic SPI write command. Defaults to 0x80.
 

Detailed Description

Implements all common low-level SPI/UART/I2C methods to control the wireless module. Every module class contains one private instance of this class.

Constructor & Destructor Documentation

◆ Module() [1/6]

Module::Module ( int16_t  tx,
int16_t  rx,
HardwareSerial *  serial = &Serial1,
int16_t  rst = NC 
)

UART-based module constructor.

Parameters
txArduino pin to be used as Tx pin for SoftwareSerial communication.
rxArduino pin to be used as Rx pin for SoftwareSerial communication.
serialHardwareSerial to be used on platforms that do not support SoftwareSerial. Defaults to Serial1.
rstArduino pin to be used as hardware reset for the module. Defaults to NC (unused).

◆ Module() [2/6]

Module::Module ( int16_t  cs,
int16_t  irq,
int16_t  rst 
)

SPI-based module constructor. Will use the default SPI interface automatically initialize it.

Parameters
csArduino pin to be used as chip select.
irqArduino pin to be used as interrupt/GPIO.
rstArduino pin to be used as hardware reset for the module.

◆ Module() [3/6]

Module::Module ( int16_t  cs,
int16_t  irq,
int16_t  rst,
int16_t  gpio 
)

Extended SPI-based module constructor. Will use the default SPI interface automatically initialize it.

Parameters
csArduino pin to be used as chip select.
irqArduino pin to be used as interrupt/GPIO.
rstArduino pin to be used as hardware reset for the module.
gpioArduino pin to be used as additional interrupt/GPIO.

◆ Module() [4/6]

Module::Module ( int16_t  cs,
int16_t  irq,
int16_t  rst,
SPIClass &  spi,
SPISettings  spiSettings 
)

SPI-based module constructor.

Parameters
csArduino pin to be used as chip select.
irqArduino pin to be used as interrupt/GPIO.
rstArduino pin to be used as hardware reset for the module.
spiSPI interface to be used, can also use software SPI implementations.
spiSettingsSPI interface settings.

◆ Module() [5/6]

Module::Module ( int16_t  cs,
int16_t  irq,
int16_t  rst,
int16_t  gpio,
SPIClass &  spi,
SPISettings  spiSettings 
)

Extended SPI-based module constructor.

Parameters
csArduino pin to be used as chip select.
irqArduino pin to be used as interrupt/GPIO.
rstArduino pin to be used as hardware reset for the module.
gpioArduino pin to be used as additional interrupt/GPIO.
spiSPI interface to be used, can also use software SPI implementations.
spiSettingsSPI interface settings.

◆ Module() [6/6]

Module::Module ( int16_t  cs,
int16_t  irq,
int16_t  rst,
int16_t  rx,
int16_t  tx,
SPIClass &  spi = SPI,
SPISettings  spiSettings = SPISettings(2000000, MSBFIRST, SPI_MODE0),
HardwareSerial *  serial = &Serial1 
)

Generic module constructor.

Parameters
csArduino pin to be used as chip select.
irqArduino pin to be used as interrupt/GPIO.
rstArduino pin to be used as hardware reset for the module.
txArduino pin to be used as Tx pin for SoftwareSerial communication.
rxArduino pin to be used as Rx pin for SoftwareSerial communication.
spiSPI interface to be used. Defaults to Arduino hardware SPI interface, can also use software SPI implementations.
spiSettingsSPI interface settings. Defaults to 2 MHz clock, MSB first, mode 0.
serialHardwareSerial to be used on ESP32 and SAMD. Defaults to 1

Member Function Documentation

◆ ATgetResponse()

bool Module::ATgetResponse ( )

Get response after sending AT command.

Returns
True if AT response contains the string "OK", false otehrwise.

◆ ATsendCommand()

bool Module::ATsendCommand ( const char *  cmd)

Send AT command. Will also call ATgetResponse.

Parameters
cmdAT command to be sent. Line feed characters are added automatically.
Returns
True if AT response contains the string "OK", false otherwise.

◆ ATsendData()

bool Module::ATsendData ( uint8_t *  data,
uint32_t  len 
)

Send raw AT data. Will also call ATgetResponse.

Parameters
dataData to be sent.
lenNumber of bytes to send.
Returns
True if AT response contains the string "OK", false otherwise.

◆ digitalWrite()

void Module::digitalWrite ( int16_t  pin,
uint8_t  value 
)
static

Arduino core digitalWrite override that checks -1 as alias for unused pin.

Parameters
pinPin to write to.
valueWhether to set the pin high or low.

◆ getCs()

int16_t Module::getCs ( ) const
inline

Access method to get the pin number of SPI chip select.

Returns
Pin number of SPI chip select configured in the constructor.

◆ getGpio()

int16_t Module::getGpio ( ) const
inline

Access method to get the pin number of second interrupt/GPIO.

Returns
Pin number of second interrupt/GPIO configured in the constructor.

◆ getIrq()

int16_t Module::getIrq ( ) const
inline

Access method to get the pin number of interrupt/GPIO.

Returns
Pin number of interrupt/GPIO configured in the constructor.

◆ getRst()

int16_t Module::getRst ( ) const
inline

Access method to get the pin number of hardware reset pin.

Returns
Pin number of hardware reset pin configured in the constructor.

◆ getRx()

int16_t Module::getRx ( ) const
inline

Access method to get the pin number of UART Rx.

Returns
Pin number of UART Rx configured in the constructor.

◆ getSpi()

SPIClass* Module::getSpi ( ) const
inline

Access method to get the SPI interface.

Returns
SPI interface configured in the constructor.

◆ getSpiSettings()

SPISettings Module::getSpiSettings ( ) const
inline

Access method to get the SPI interface settings.

Returns
SPI interface settings configured in the constructor.

◆ getTx()

int16_t Module::getTx ( ) const
inline

Access method to get the pin number of UART Rx.

Returns
Pin number of UART Rx configured in the constructor.

◆ init()

void Module::init ( uint8_t  interface)

Initialize low-level module control.

Parameters
interfaceInterface to be used on the module. See Shield Configuration for details.

◆ pinMode()

void Module::pinMode ( int16_t  pin,
uint8_t  mode 
)
static

Arduino core pinMode override that checks -1 as alias for unused pin.

Parameters
pinPin to change the mode of.
modeWhich mode to set.

◆ SPIgetRegValue()

int16_t Module::SPIgetRegValue ( uint8_t  reg,
uint8_t  msb = 7,
uint8_t  lsb = 0 
)

SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism.

Parameters
regAddress of SPI register to read.
msbMost significant bit of the register variable. Bits above this one will be masked out.
lsbLeast significant bit of the register variable. Bits below this one will be masked out.
Returns
Masked register value or status code.

◆ SPIreadRegister()

uint8_t Module::SPIreadRegister ( uint8_t  reg)

SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.

Parameters
regAddress of SPI register to read.
Returns
Value that was read from register.

◆ SPIreadRegisterBurst()

void Module::SPIreadRegisterBurst ( uint8_t  reg,
uint8_t  numBytes,
uint8_t *  inBytes 
)

SPI burst read method.

Parameters
regAddress of SPI register to read.
numBytesNumber of bytes that will be read.
inBytesPointer to array that will hold the read data.

◆ SPIsetRegValue()

int16_t Module::SPIsetRegValue ( uint8_t  reg,
uint8_t  value,
uint8_t  msb = 7,
uint8_t  lsb = 0,
uint8_t  checkInterval = 2 
)

Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism.

Parameters
regAddress of SPI register to write.
valueSingle byte value that will be written to the SPI register.
msbMost significant bit of the register variable. Bits above this one will not be affected by the write operation.
lsbLeast significant bit of the register variable. Bits below this one will not be affected by the write operation.
checkIntervalNumber of milliseconds between register writing and verification reading. Some registers need up to 10ms to process the change.
Returns
Status Codes

◆ SPItransfer()

void Module::SPItransfer ( uint8_t  cmd,
uint8_t  reg,
uint8_t *  dataOut,
uint8_t *  dataIn,
uint8_t  numBytes 
)

SPI single transfer method.

Parameters
cmdSPI access command (read/write/burst/...).
regAddress of SPI register to transfer to/from.
dataOutData that will be transfered from master to slave.
dataInData that was transfered from slave to master.
numBytesNumber of bytes to transfer.

◆ SPIwriteRegister()

void Module::SPIwriteRegister ( uint8_t  reg,
uint8_t  data 
)

SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.

Parameters
regAddress of SPI register to write.
dataValue that will be written to the register.

◆ SPIwriteRegisterBurst()

void Module::SPIwriteRegisterBurst ( uint8_t  reg,
uint8_t *  data,
uint8_t  numBytes 
)

SPI burst write method.

Parameters
regAddress of SPI register to write.
dataPointer to array that holds the data that will be written.
numBytesNumber of bytes that will be written.

The documentation for this class was generated from the following files: