[MOD] Port 16-bit address from ax5x43 dev
This commit is contained in:
parent
e07d1d9dc1
commit
308ad87320
2 changed files with 26 additions and 15 deletions
|
@ -129,7 +129,7 @@ void Module::term() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Module::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) {
|
int16_t Module::SPIgetRegValue(uint16_t reg, uint8_t msb, uint8_t lsb) {
|
||||||
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
||||||
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
|
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ int16_t Module::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) {
|
||||||
return(maskedValue);
|
return(maskedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t lsb, uint8_t checkInterval, uint8_t checkMask) {
|
int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t lsb, uint8_t checkInterval, uint8_t checkMask) {
|
||||||
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
||||||
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
|
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
|
||||||
}
|
}
|
||||||
|
@ -188,25 +188,25 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes) {
|
void Module::SPIreadRegisterBurst(uint16_t reg, uint8_t numBytes, uint8_t* inBytes) {
|
||||||
SPItransfer(SPIreadCommand, reg, NULL, inBytes, numBytes);
|
SPItransfer(SPIreadCommand, reg, NULL, inBytes, numBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Module::SPIreadRegister(uint8_t reg) {
|
uint8_t Module::SPIreadRegister(uint16_t reg) {
|
||||||
uint8_t resp = 0;
|
uint8_t resp = 0;
|
||||||
SPItransfer(SPIreadCommand, reg, NULL, &resp, 1);
|
SPItransfer(SPIreadCommand, reg, NULL, &resp, 1);
|
||||||
return(resp);
|
return(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, uint8_t numBytes) {
|
void Module::SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, uint8_t numBytes) {
|
||||||
SPItransfer(SPIwriteCommand, reg, data, NULL, numBytes);
|
SPItransfer(SPIwriteCommand, reg, data, NULL, numBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SPIwriteRegister(uint8_t reg, uint8_t data) {
|
void Module::SPIwriteRegister(uint16_t reg, uint8_t data) {
|
||||||
SPItransfer(SPIwriteCommand, reg, &data, NULL, 1);
|
SPItransfer(SPIwriteCommand, reg, &data, NULL, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
|
void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
|
||||||
// start SPI transaction
|
// start SPI transaction
|
||||||
this->SPIbeginTransaction();
|
this->SPIbeginTransaction();
|
||||||
|
|
||||||
|
@ -214,7 +214,13 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da
|
||||||
this->digitalWrite(_cs, LOW);
|
this->digitalWrite(_cs, LOW);
|
||||||
|
|
||||||
// send SPI register address with access command
|
// send SPI register address with access command
|
||||||
|
if(this->SPIaddrWidth <= 8) {
|
||||||
this->SPItransfer(reg | cmd);
|
this->SPItransfer(reg | cmd);
|
||||||
|
} else {
|
||||||
|
this->SPItransfer((reg >> 8) | cmd);
|
||||||
|
this->SPItransfer(reg & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(RADIOLIB_VERBOSE)
|
#if defined(RADIOLIB_VERBOSE)
|
||||||
if(cmd == SPIwriteCommand) {
|
if(cmd == SPIwriteCommand) {
|
||||||
RADIOLIB_VERBOSE_PRINT('W');
|
RADIOLIB_VERBOSE_PRINT('W');
|
||||||
|
|
19
src/Module.h
19
src/Module.h
|
@ -139,6 +139,11 @@ class Module {
|
||||||
*/
|
*/
|
||||||
uint8_t SPIwriteCommand = 0b10000000;
|
uint8_t SPIwriteCommand = 0b10000000;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief SPI address width. Defaults to 8, currently only supports 8 and 16-bit addresses.
|
||||||
|
*/
|
||||||
|
uint8_t SPIaddrWidth = 8;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Whether the SPI interface is stream-type (e.g. SX126x) or register-type (e.g. SX127x).
|
\brief Whether the SPI interface is stream-type (e.g. SX126x) or register-type (e.g. SX127x).
|
||||||
Defaults to register-type SPI interfaces.
|
Defaults to register-type SPI interfaces.
|
||||||
|
@ -200,7 +205,7 @@ class Module {
|
||||||
|
|
||||||
\returns Masked register value or status code.
|
\returns Masked register value or status code.
|
||||||
*/
|
*/
|
||||||
int16_t SPIgetRegValue(uint8_t reg, uint8_t msb = 7, uint8_t lsb = 0);
|
int16_t SPIgetRegValue(uint16_t reg, uint8_t msb = 7, uint8_t lsb = 0);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism.
|
\brief Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism.
|
||||||
|
@ -219,7 +224,7 @@ class Module {
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2, uint8_t checkMask = 0xFF);
|
int16_t SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2, uint8_t checkMask = 0xFF);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI burst read method.
|
\brief SPI burst read method.
|
||||||
|
@ -230,7 +235,7 @@ class Module {
|
||||||
|
|
||||||
\param inBytes Pointer to array that will hold the read data.
|
\param inBytes Pointer to array that will hold the read data.
|
||||||
*/
|
*/
|
||||||
void SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes);
|
void SPIreadRegisterBurst(uint16_t reg, uint8_t numBytes, uint8_t* inBytes);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
|
\brief SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
|
||||||
|
@ -239,7 +244,7 @@ class Module {
|
||||||
|
|
||||||
\returns Value that was read from register.
|
\returns Value that was read from register.
|
||||||
*/
|
*/
|
||||||
uint8_t SPIreadRegister(uint8_t reg);
|
uint8_t SPIreadRegister(uint16_t reg);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI burst write method.
|
\brief SPI burst write method.
|
||||||
|
@ -250,7 +255,7 @@ class Module {
|
||||||
|
|
||||||
\param numBytes Number of bytes that will be written.
|
\param numBytes Number of bytes that will be written.
|
||||||
*/
|
*/
|
||||||
void SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, uint8_t numBytes);
|
void SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, uint8_t numBytes);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
|
\brief SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
|
||||||
|
@ -259,7 +264,7 @@ class Module {
|
||||||
|
|
||||||
\param data Value that will be written to the register.
|
\param data Value that will be written to the register.
|
||||||
*/
|
*/
|
||||||
void SPIwriteRegister(uint8_t reg, uint8_t data);
|
void SPIwriteRegister(uint16_t reg, uint8_t data);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI single transfer method.
|
\brief SPI single transfer method.
|
||||||
|
@ -274,7 +279,7 @@ class Module {
|
||||||
|
|
||||||
\param numBytes Number of bytes to transfer.
|
\param numBytes Number of bytes to transfer.
|
||||||
*/
|
*/
|
||||||
void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes);
|
void SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief SPI single transfer method for modules with stream-type SPI interface (SX126x, SX128x etc.).
|
\brief SPI single transfer method for modules with stream-type SPI interface (SX126x, SX128x etc.).
|
||||||
|
|
Loading…
Add table
Reference in a new issue