[LR11x0] Move functions common with LR2021

lr2021
jgromes 2025-10-12 21:12:27 +02:00
rodzic 3e57c27467
commit e60d2624f2
5 zmienionych plików z 55 dodań i 44 usunięć

Wyświetl plik

@ -301,8 +301,8 @@
// RADIOLIB_LR11X0_CMD_SET_SLEEP
#define RADIOLIB_LR11X0_SLEEP_RETENTION_DISABLED (0x00UL << 0) // 0 0 configuration retention in sleep mode: disabled
#define RADIOLIB_LR11X0_SLEEP_RETENTION_ENABLED (0x01UL << 0) // 0 0 enabled
#define RADIOLIB_LR11X0_SLEEP_WAKEUP_DISABLED (0x00UL << 0) // 1 1 automated wakeup: disabled
#define RADIOLIB_LR11X0_SLEEP_WAKEUP_ENABLED (0x01UL << 0) // 1 1 enabled
#define RADIOLIB_LR11X0_SLEEP_WAKEUP_DISABLED (0x00UL << 1) // 1 1 automated wakeup: disabled
#define RADIOLIB_LR11X0_SLEEP_WAKEUP_ENABLED (0x01UL << 1) // 1 1 enabled
// RADIOLIB_LR11X0_CMD_SET_STANDBY
#define RADIOLIB_LR11X0_STANDBY_RC (0x00UL << 0) // 7 0 standby mode: RC oscillator
@ -1881,7 +1881,6 @@ class LR11x0: public PhysicalLayer {
// common methods to avoid some copy-paste
int16_t bleBeaconCommon(uint16_t cmd, uint8_t chan, const uint8_t* payload, size_t len);
int16_t writeCommon(uint16_t cmd, uint32_t addrOffset, const uint32_t* data, size_t len, bool nonvolatile);
int16_t cryptoCommon(uint16_t cmd, uint8_t keyId, const uint8_t* dataIn, size_t len, uint8_t* dataOut);
};

Wyświetl plik

@ -2,6 +2,7 @@
#include "../../utils/CRC.h"
#include "../../utils/Cryptography.h"
#include "LR_common.h"
#include <string.h>
#include <math.h>
@ -55,7 +56,7 @@ int16_t LR11x0::writeRegMem32(uint32_t addr, const uint32_t* data, size_t len) {
if(len > (RADIOLIB_LR11X0_SPI_MAX_READ_WRITE_LEN/sizeof(uint32_t))) {
return(RADIOLIB_ERR_SPI_CMD_INVALID);
}
return(this->writeCommon(RADIOLIB_LR11X0_CMD_WRITE_REG_MEM, addr, data, len, false));
return(LR_writeCommon(this->mod, RADIOLIB_LR11X0_CMD_WRITE_REG_MEM, addr, data, len, false));
}
int16_t LR11x0::readRegMem32(uint32_t addr, uint32_t* data, size_t len) {
@ -829,7 +830,7 @@ int16_t LR11x0::bootWriteFlashEncrypted(uint32_t offset, const uint32_t* data, s
if(len > (RADIOLIB_LR11X0_SPI_MAX_READ_WRITE_LEN/sizeof(uint32_t))) {
return(RADIOLIB_ERR_SPI_CMD_INVALID);
}
return(this->writeCommon(RADIOLIB_LR11X0_CMD_BOOT_WRITE_FLASH_ENCRYPTED, offset, data, len, nonvolatile));
return(LR_writeCommon(this->mod, RADIOLIB_LR11X0_CMD_BOOT_WRITE_FLASH_ENCRYPTED, offset, data, len, nonvolatile));
}
int16_t LR11x0::bootReboot(bool stay) {
@ -852,42 +853,4 @@ int16_t LR11x0::bootGetJoinEui(uint8_t* eui) {
return(this->SPIcommand(RADIOLIB_LR11X0_CMD_BOOT_GET_JOIN_EUI, false, eui, RADIOLIB_LR11X0_EUI_LEN));
}
int16_t LR11x0::writeCommon(uint16_t cmd, uint32_t addrOffset, const uint32_t* data, size_t len, bool nonvolatile) {
// build buffers - later we need to ensure endians are correct,
// so there is probably no way to do this without copying buffers and iterating
size_t buffLen = sizeof(uint32_t) + len*sizeof(uint32_t);
#if RADIOLIB_STATIC_ONLY
uint8_t dataBuff[sizeof(uint32_t) + RADIOLIB_LR11X0_SPI_MAX_READ_WRITE_LEN];
#else
uint8_t* dataBuff = new uint8_t[buffLen];
#endif
// set the address or offset
dataBuff[0] = (uint8_t)((addrOffset >> 24) & 0xFF);
dataBuff[1] = (uint8_t)((addrOffset >> 16) & 0xFF);
dataBuff[2] = (uint8_t)((addrOffset >> 8) & 0xFF);
dataBuff[3] = (uint8_t)(addrOffset & 0xFF);
// convert endians
for(size_t i = 0; i < len; i++) {
uint32_t bin = 0;
if(nonvolatile) {
uint32_t* ptr = const_cast<uint32_t*>(data) + i;
bin = RADIOLIB_NONVOLATILE_READ_DWORD(ptr);
} else {
bin = data[i];
}
dataBuff[4 + i*sizeof(uint32_t)] = (uint8_t)((bin >> 24) & 0xFF);
dataBuff[5 + i*sizeof(uint32_t)] = (uint8_t)((bin >> 16) & 0xFF);
dataBuff[6 + i*sizeof(uint32_t)] = (uint8_t)((bin >> 8) & 0xFF);
dataBuff[7 + i*sizeof(uint32_t)] = (uint8_t)(bin & 0xFF);
}
int16_t state = this->mod->SPIwriteStream(cmd, dataBuff, buffLen, true, false);
#if !RADIOLIB_STATIC_ONLY
delete[] dataBuff;
#endif
return(state);
}
#endif

Wyświetl plik

@ -1,6 +1,8 @@
#include "LR11x0.h"
#include "../../utils/Cryptography.h"
#include "LR_common.h"
#include <string.h>
#if !RADIOLIB_EXCLUDE_LR11X0
@ -176,7 +178,7 @@ int16_t LR11x0::cryptoCheckEncryptedFirmwareImage(uint32_t offset, const uint32_
if(len > (RADIOLIB_LR11X0_SPI_MAX_READ_WRITE_LEN/sizeof(uint32_t))) {
return(RADIOLIB_ERR_SPI_CMD_INVALID);
}
return(this->writeCommon(RADIOLIB_LR11X0_CMD_CRYPTO_CHECK_ENCRYPTED_FIRMWARE_IMAGE, offset, data, len, nonvolatile));
return(LR_writeCommon(this->mod, RADIOLIB_LR11X0_CMD_CRYPTO_CHECK_ENCRYPTED_FIRMWARE_IMAGE, offset, data, len, nonvolatile));
}
int16_t LR11x0::cryptoCheckEncryptedFirmwareImageResult(bool* result) {

Wyświetl plik

@ -0,0 +1,39 @@
#include "LR_common.h"
int16_t LR_writeCommon(Module* mod, uint16_t cmd, uint32_t addrOffset, const uint32_t* data, size_t len, bool nonvolatile) {
// build buffers - later we need to ensure endians are correct,
// so there is probably no way to do this without copying buffers and iterating
size_t buffLen = sizeof(uint32_t) + len*sizeof(uint32_t);
#if RADIOLIB_STATIC_ONLY
uint8_t dataBuff[sizeof(uint32_t) + RADIOLIB_LR11X0_SPI_MAX_READ_WRITE_LEN];
#else
uint8_t* dataBuff = new uint8_t[buffLen];
#endif
// set the address or offset
dataBuff[0] = (uint8_t)((addrOffset >> 24) & 0xFF);
dataBuff[1] = (uint8_t)((addrOffset >> 16) & 0xFF);
dataBuff[2] = (uint8_t)((addrOffset >> 8) & 0xFF);
dataBuff[3] = (uint8_t)(addrOffset & 0xFF);
// convert endians
for(size_t i = 0; i < len; i++) {
uint32_t bin = 0;
if(nonvolatile) {
uint32_t* ptr = const_cast<uint32_t*>(data) + i;
bin = RADIOLIB_NONVOLATILE_READ_DWORD(ptr);
} else {
bin = data[i];
}
dataBuff[4 + i*sizeof(uint32_t)] = (uint8_t)((bin >> 24) & 0xFF);
dataBuff[5 + i*sizeof(uint32_t)] = (uint8_t)((bin >> 16) & 0xFF);
dataBuff[6 + i*sizeof(uint32_t)] = (uint8_t)((bin >> 8) & 0xFF);
dataBuff[7 + i*sizeof(uint32_t)] = (uint8_t)(bin & 0xFF);
}
int16_t state = mod->SPIwriteStream(cmd, dataBuff, buffLen, true, false);
#if !RADIOLIB_STATIC_ONLY
delete[] dataBuff;
#endif
return(state);
}

Wyświetl plik

@ -0,0 +1,8 @@
#if !defined(RADIOLIB_LR_COMMON_H)
#define RADIOLIB_LR_COMMON_H
#include "../../Module.h"
int16_t LR_writeCommon(Module* mod, uint16_t cmd, uint32_t addrOffset, const uint32_t* data, size_t len, bool nonvolatile);
#endif