kopia lustrzana https://github.com/jgromes/RadioLib
Porównaj commity
14 Commity
58f44a9aa2
...
48553b5a9d
Autor | SHA1 | Data |
---|---|---|
Velocet | 48553b5a9d | |
Velocet | 7e4d40b486 | |
jgromes | d77823375a | |
jgromes | c9d8c601df | |
jgromes | f982314858 | |
Jan Gromeš | 4fa0656ddd | |
Velocet | 648c96503d | |
Velocet | 4bdb455a52 | |
Velocet | b80f49945a | |
Velocet | 76bda0714c | |
Velocet | d6a152402b | |
Velocet | b184a87aa0 | |
Velocet | 83271fe24e | |
Velocet | bbd419b309 |
|
@ -32,6 +32,12 @@ target_include_directories(RadioLib
|
|||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
# use c++20 standard
|
||||
set_property(TARGET RadioLib PROPERTY CXX_STANDARD 20)
|
||||
|
||||
# enable most warnings
|
||||
target_compile_options(RadioLib PRIVATE -Wall -Wextra)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(TARGETS RadioLib
|
||||
|
|
|
@ -37,30 +37,30 @@ void setup() {
|
|||
delay(5000); // Give time to switch to the serial monitor
|
||||
Serial.println(F("\nSetup ... "));
|
||||
|
||||
Serial.println(F("Initalise the radio"));
|
||||
Serial.println(F("Initialise the radio"));
|
||||
int state = radio.begin();
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initalise radio failed"), state, true);
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initialise radio failed"), state, true);
|
||||
|
||||
Serial.println(F("Initalise LoRaWAN Network credentials"));
|
||||
Serial.println(F("Initialise LoRaWAN Network credentials"));
|
||||
state = node.beginABP(devAddr, NwkSEncKey, AppSKey, NwkSKey, SNwkSIntKey, true);
|
||||
debug(state < RADIOLIB_ERR_NONE, F("Session setup failed"), state, true);
|
||||
|
||||
Serial.println(F("Ready!\n"));
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
Serial.println(F("Sending uplink"));
|
||||
|
||||
// Read some inputs
|
||||
uint8_t Digital1 = digitalRead(2);
|
||||
uint16_t Analog1 = analogRead(3);
|
||||
// This is the place to gather the sensor inputs
|
||||
// Instead of reading any real sensor, we just generate some random numbers as example
|
||||
uint8_t value1 = radio.random(100);
|
||||
uint16_t value2 = radio.random(2000);
|
||||
|
||||
// Build payload byte array
|
||||
uint8_t uplinkPayload[3];
|
||||
uplinkPayload[0] = Digital1;
|
||||
uplinkPayload[1] = highByte(Analog1); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(Analog1);
|
||||
uplinkPayload[0] = value1;
|
||||
uplinkPayload[1] = highByte(value2); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(value2);
|
||||
|
||||
// Perform an uplink
|
||||
int state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload));
|
||||
|
|
|
@ -49,11 +49,11 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
|||
|
||||
// LilyGo
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V1)
|
||||
#pragma message ("TTGO LoRa32 v1 - no Display")
|
||||
#pragma message ("Using TTGO LoRa32 v1 - no Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V2)
|
||||
#pragma message ("ARDUINO_TTGO_LORA32_V2 + Display")
|
||||
#pragma message ("Using TTGO LoRa32 v2 + Display")
|
||||
SX1276 radio = new Module(18, 26, 12, RADIOLIB_NC);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
|
||||
|
@ -64,32 +64,41 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
|||
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
#pragma message ("Using TTGO T-Beam")
|
||||
SX1276 radio = new Module(18, 26, 23, 33);
|
||||
|
||||
|
||||
// Heltec
|
||||
// HelTec: https://github.com/espressif/arduino-esp32/blob/master/variants/heltec_*/pins_arduino.h
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
|
||||
#pragma error ("ARDUINO_HELTEC_WIFI_LORA_32 awaiting pin map")
|
||||
#pragma message ("Using Heltec WiFi LoRa32")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined (ARDUINO_heltec_wireless_stick)
|
||||
#pragma message ("Using Heltec Wireless Stick")
|
||||
SX1278 radio = new Module(14, 4, 12, 16);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_lora_32_V2)
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v2")
|
||||
SX1278 radio = new Module(14, 4, 12, 16);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V2)
|
||||
#pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK)
|
||||
#pragma message ("Using Heltec Wireless Stick")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_V3)
|
||||
#pragma message ("Using Heltec Wireless Stick v3")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE)
|
||||
#pragma message ("Using Heltec Wireless Stick Lite")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE_V3)
|
||||
#pragma message ("Using Heltec Wireless Stick Lite v3")
|
||||
SX1262 radio = new Module(34, 14, 12, 13);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
#pragma message ("Using CubeCell")
|
||||
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD_V2)
|
||||
|
|
|
@ -33,18 +33,17 @@
|
|||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial); // Wait for serial to be initalised
|
||||
while(!Serial); // Wait for serial to be initialised
|
||||
delay(5000); // Give time to switch to the serial monitor
|
||||
Serial.println(F("\nSetup"));
|
||||
|
||||
int16_t state = 0; // return value for calls to RadioLib
|
||||
|
||||
Serial.println(F("Initalise the radio"));
|
||||
Serial.println(F("Initialise the radio"));
|
||||
state = radio.begin();
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initalise radio failed"), state, true);
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initialise radio failed"), state, true);
|
||||
|
||||
// Override the default join rate
|
||||
// uint8_t joinDR = 3;
|
||||
|
@ -70,8 +69,7 @@ void setup() {
|
|||
node.setDwellTime(true, 400);
|
||||
|
||||
Serial.println(F("Ready!\n"));
|
||||
} // setup
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int state = RADIOLIB_ERR_NONE;
|
||||
|
@ -85,19 +83,19 @@ void loop() {
|
|||
uint8_t battLevel = 146;
|
||||
node.setDeviceStatus(battLevel);
|
||||
|
||||
|
||||
// Read some inputs
|
||||
uint8_t Digital1 = digitalRead(2);
|
||||
uint16_t Analog1 = analogRead(3);
|
||||
// This is the place to gather the sensor inputs
|
||||
// Instead of reading any real sensor, we just generate some random numbers as example
|
||||
uint8_t value1 = radio.random(100);
|
||||
uint16_t value2 = radio.random(2000);
|
||||
|
||||
// Build payload byte array
|
||||
uint8_t uplinkPayload[3];
|
||||
uplinkPayload[0] = Digital1;
|
||||
uplinkPayload[1] = highByte(Analog1); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(Analog1);
|
||||
uplinkPayload[0] = value1;
|
||||
uplinkPayload[1] = highByte(value2); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(value2);
|
||||
|
||||
uint8_t downlinkPayload[10]; // Make sure this fits your plans!
|
||||
size_t downlinkSize; // To hold the actual payload size rec'd
|
||||
size_t downlinkSize; // To hold the actual payload size received
|
||||
|
||||
// you can also retrieve additional information about an uplink or
|
||||
// downlink by passing a reference to LoRaWANEvent_t structure
|
||||
|
@ -108,6 +106,7 @@ void loop() {
|
|||
|
||||
// Retrieve the last uplink frame counter
|
||||
uint32_t fcntUp = node.getFcntUp();
|
||||
|
||||
// Send a confirmed uplink every 64th frame
|
||||
// and also request the LinkCheck and DeviceTime MAC commands
|
||||
if(fcntUp % 64 == 0) {
|
||||
|
@ -194,5 +193,4 @@ void loop() {
|
|||
Serial.println(F("s"));
|
||||
|
||||
delay(delayMs);
|
||||
|
||||
} // loop
|
||||
}
|
||||
|
|
|
@ -44,11 +44,11 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
|||
|
||||
// LilyGo
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V1)
|
||||
#pragma message ("TTGO LoRa32 v1 - no Display")
|
||||
#pragma message ("Using TTGO LoRa32 v1 - no Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V2)
|
||||
#pragma message ("ARDUINO_TTGO_LORA32_V2 + Display")
|
||||
#pragma message ("Using TTGO LoRa32 v2 + Display")
|
||||
SX1276 radio = new Module(18, 26, 12, RADIOLIB_NC);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
|
||||
|
@ -59,32 +59,41 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
|||
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
#pragma message ("Using TTGO T-Beam")
|
||||
SX1276 radio = new Module(18, 26, 23, 33);
|
||||
|
||||
|
||||
// Heltec
|
||||
// HelTec: https://github.com/espressif/arduino-esp32/blob/master/variants/heltec_*/pins_arduino.h
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
|
||||
#pragma error ("ARDUINO_HELTEC_WIFI_LORA_32 awaiting pin map")
|
||||
#pragma message ("Using Heltec WiFi LoRa32")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined (ARDUINO_heltec_wireless_stick)
|
||||
#pragma message ("Using Heltec Wireless Stick")
|
||||
SX1278 radio = new Module(14, 4, 12, 16);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_lora_32_V2)
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v2")
|
||||
SX1278 radio = new Module(14, 4, 12, 16);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V2)
|
||||
#pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK)
|
||||
#pragma message ("Using Heltec Wireless Stick")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_V3)
|
||||
#pragma message ("Using Heltec Wireless Stick v3")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE)
|
||||
#pragma message ("Using Heltec Wireless Stick Lite")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE_V3)
|
||||
#pragma message ("Using Heltec Wireless Stick Lite v3")
|
||||
SX1262 radio = new Module(34, 14, 12, 13);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
#pragma message ("Using CubeCell")
|
||||
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD_V2)
|
||||
|
|
|
@ -30,9 +30,9 @@ void setup() {
|
|||
delay(5000); // Give time to switch to the serial monitor
|
||||
Serial.println(F("\nSetup ... "));
|
||||
|
||||
Serial.println(F("Initalise the radio"));
|
||||
Serial.println(F("Initialise the radio"));
|
||||
int state = radio.begin();
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initalise radio failed"), state, true);
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initialise radio failed"), state, true);
|
||||
|
||||
Serial.println(F("Join ('login') to the LoRaWAN Network"));
|
||||
state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, true);
|
||||
|
@ -41,19 +41,19 @@ void setup() {
|
|||
Serial.println(F("Ready!\n"));
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
Serial.println(F("Sending uplink"));
|
||||
|
||||
// Read some inputs
|
||||
uint8_t Digital1 = digitalRead(2);
|
||||
uint16_t Analog1 = analogRead(3);
|
||||
// This is the place to gather the sensor inputs
|
||||
// Instead of reading any real sensor, we just generate some random numbers as example
|
||||
uint8_t value1 = radio.random(100);
|
||||
uint16_t value2 = radio.random(2000);
|
||||
|
||||
// Build payload byte array
|
||||
uint8_t uplinkPayload[3];
|
||||
uplinkPayload[0] = Digital1;
|
||||
uplinkPayload[1] = highByte(Analog1); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(Analog1);
|
||||
uplinkPayload[0] = value1;
|
||||
uplinkPayload[1] = highByte(value2); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(value2);
|
||||
|
||||
// Perform an uplink
|
||||
int state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload));
|
||||
|
|
|
@ -44,11 +44,11 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
|||
|
||||
// LilyGo
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V1)
|
||||
#pragma message ("TTGO LoRa32 v1 - no Display")
|
||||
#pragma message ("Using TTGO LoRa32 v1 - no Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V2)
|
||||
#pragma message ("ARDUINO_TTGO_LORA32_V2 + Display")
|
||||
#pragma message ("Using TTGO LoRa32 v2 + Display")
|
||||
SX1276 radio = new Module(18, 26, 12, RADIOLIB_NC);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
|
||||
|
@ -59,32 +59,41 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
|||
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
#pragma message ("Using TTGO T-Beam")
|
||||
SX1276 radio = new Module(18, 26, 23, 33);
|
||||
|
||||
|
||||
// Heltec
|
||||
// HelTec: https://github.com/espressif/arduino-esp32/blob/master/variants/heltec_*/pins_arduino.h
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
|
||||
#pragma error ("ARDUINO_HELTEC_WIFI_LORA_32 awaiting pin map")
|
||||
#pragma message ("Using Heltec WiFi LoRa32")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined (ARDUINO_heltec_wireless_stick)
|
||||
#pragma message ("Using Heltec Wireless Stick")
|
||||
SX1278 radio = new Module(14, 4, 12, 16);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_lora_32_V2)
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v2")
|
||||
SX1278 radio = new Module(14, 4, 12, 16);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V2)
|
||||
#pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK)
|
||||
#pragma message ("Using Heltec Wireless Stick")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_V3)
|
||||
#pragma message ("Using Heltec Wireless Stick v3")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE)
|
||||
#pragma message ("Using Heltec Wireless Stick Lite")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined (ARDUINO_HELTEC_WIRELESS_STICK_LITE_V3)
|
||||
#pragma message ("Using Heltec Wireless Stick Lite v3")
|
||||
SX1262 radio = new Module(34, 14, 12, 13);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
#pragma message ("Using CubeCell")
|
||||
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD_V2)
|
||||
|
|
|
@ -152,6 +152,10 @@ Prebuilt modules are easy - we can detect the board and setup the pinmap for you
|
|||
* HELTEC_WIFI_LORA_32
|
||||
* HELTEC_WIFI_LORA_32_V2
|
||||
* HELTEC_WIFI_LORA_32_V3
|
||||
* HELTEC_WIRELESS_STICK
|
||||
* HELTEC_WIRELESS_STICK_V3
|
||||
* HELTEC_WIRELESS_STICK_LITE
|
||||
* HELTEC_WIRELESS_STICK_LITE_V3
|
||||
|
||||
If you have a TTGO T-Beam, you must choose the correct radio from the Board Revision sub-menu found under the main Tools menu.
|
||||
|
||||
|
|
|
@ -529,6 +529,17 @@
|
|||
#define RADIOLIB_DEBUG_SPI_HEXDUMP(...) {}
|
||||
#endif
|
||||
|
||||
// debug info strings
|
||||
#define RADIOLIB_VALUE_TO_STRING(x) #x
|
||||
#define RADIOLIB_VALUE(x) RADIOLIB_VALUE_TO_STRING(x)
|
||||
|
||||
#define RADIOLIB_INFO "\nRadioLib Info\nVersion: \"" \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_MAJOR) "." \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_MINOR) "." \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_PATCH) "." \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_EXTRA) "\"\n" \
|
||||
"Platform: " RADIOLIB_VALUE(RADIOLIB_PLATFORM) "\n" \
|
||||
"Compiled: " RADIOLIB_VALUE(__DATE__) " " RADIOLIB_VALUE(__TIME__)
|
||||
|
||||
/*!
|
||||
\brief A simple assert macro, will return on error.
|
||||
|
|
168
src/Module.cpp
168
src/Module.cpp
|
@ -31,8 +31,7 @@ Module::Module(const Module& mod) {
|
|||
}
|
||||
|
||||
Module& Module::operator=(const Module& mod) {
|
||||
this->SPIreadCommand = mod.SPIreadCommand;
|
||||
this->SPIwriteCommand = mod.SPIwriteCommand;
|
||||
memcpy((void*)&mod.spiConfig, &this->spiConfig, sizeof(SPIConfig_t));
|
||||
this->csPin = mod.csPin;
|
||||
this->irqPin = mod.irqPin;
|
||||
this->rstPin = mod.rstPin;
|
||||
|
@ -40,14 +39,12 @@ Module& Module::operator=(const Module& mod) {
|
|||
return(*this);
|
||||
}
|
||||
|
||||
static volatile const char info[] = RADIOLIB_INFO;
|
||||
void Module::init() {
|
||||
this->hal->init();
|
||||
this->hal->pinMode(csPin, this->hal->GpioModeOutput);
|
||||
this->hal->digitalWrite(csPin, this->hal->GpioLevelHigh);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("RadioLib Debug Info");
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Version: %d.%d.%d.%d", RADIOLIB_VERSION_MAJOR, RADIOLIB_VERSION_MINOR, RADIOLIB_VERSION_PATCH, RADIOLIB_VERSION_EXTRA);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Platform: " RADIOLIB_PLATFORM);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Compiled: " __DATE__ " " __TIME__ "\n");
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN(RADIOLIB_INFO);
|
||||
}
|
||||
|
||||
void Module::term() {
|
||||
|
@ -55,7 +52,7 @@ void Module::term() {
|
|||
this->hal->term();
|
||||
}
|
||||
|
||||
int16_t Module::SPIgetRegValue(uint16_t reg, uint8_t msb, uint8_t lsb) {
|
||||
int16_t Module::SPIgetRegValue(uint32_t reg, uint8_t msb, uint8_t lsb) {
|
||||
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
||||
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
|
||||
}
|
||||
|
@ -65,7 +62,7 @@ int16_t Module::SPIgetRegValue(uint16_t reg, uint8_t msb, uint8_t lsb) {
|
|||
return(maskedValue);
|
||||
}
|
||||
|
||||
int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t lsb, uint8_t checkInterval, uint8_t checkMask) {
|
||||
int16_t Module::SPIsetRegValue(uint32_t reg, uint8_t value, uint8_t msb, uint8_t lsb, uint8_t checkInterval, uint8_t checkMask) {
|
||||
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
||||
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
|
||||
}
|
||||
|
@ -104,47 +101,75 @@ int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t
|
|||
#endif
|
||||
}
|
||||
|
||||
void Module::SPIreadRegisterBurst(uint16_t reg, size_t numBytes, uint8_t* inBytes) {
|
||||
if(!SPIstreamType) {
|
||||
SPItransfer(SPIreadCommand, reg, NULL, inBytes, numBytes);
|
||||
void Module::SPIreadRegisterBurst(uint32_t reg, size_t numBytes, uint8_t* inBytes) {
|
||||
if(!this->spiConfig.stream) {
|
||||
SPItransfer(this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ], reg, NULL, inBytes, numBytes);
|
||||
} else {
|
||||
uint8_t cmd[] = { SPIreadCommand, (uint8_t)((reg >> 8) & 0xFF), (uint8_t)(reg & 0xFF) };
|
||||
SPItransferStream(cmd, 3, false, NULL, inBytes, numBytes, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
uint8_t cmd[6];
|
||||
uint8_t* cmdPtr = cmd;
|
||||
for(uint8_t i = 0; i < (uint8_t)this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8; i++) {
|
||||
*(cmdPtr++) = (this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] >> 8*i) & 0xFF;
|
||||
}
|
||||
for(int8_t i = (int8_t)((this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8) - 1); i >= 0; i--) {
|
||||
*(cmdPtr++) = (reg >> 8*i) & 0xFF;
|
||||
}
|
||||
SPItransferStream(cmd, this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8 + this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8, false, NULL, inBytes, numBytes, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Module::SPIreadRegister(uint16_t reg) {
|
||||
uint8_t Module::SPIreadRegister(uint32_t reg) {
|
||||
uint8_t resp = 0;
|
||||
if(!SPIstreamType) {
|
||||
SPItransfer(SPIreadCommand, reg, NULL, &resp, 1);
|
||||
if(!spiConfig.stream) {
|
||||
SPItransfer(this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ], reg, NULL, &resp, 1);
|
||||
} else {
|
||||
uint8_t cmd[] = { SPIreadCommand, (uint8_t)((reg >> 8) & 0xFF), (uint8_t)(reg & 0xFF) };
|
||||
SPItransferStream(cmd, 3, false, NULL, &resp, 1, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
uint8_t cmd[6];
|
||||
uint8_t* cmdPtr = cmd;
|
||||
for(uint8_t i = 0; i < (uint8_t)this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8; i++) {
|
||||
*(cmdPtr++) = (this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] >> 8*i) & 0xFF;
|
||||
}
|
||||
for(int8_t i = (int8_t)((this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8) - 1); i >= 0; i--) {
|
||||
*(cmdPtr++) = (reg >> 8*i) & 0xFF;
|
||||
}
|
||||
SPItransferStream(cmd, this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8 + this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8, false, NULL, &resp, 1, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
}
|
||||
return(resp);
|
||||
}
|
||||
|
||||
void Module::SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, size_t numBytes) {
|
||||
if(!SPIstreamType) {
|
||||
SPItransfer(SPIwriteCommand, reg, data, NULL, numBytes);
|
||||
void Module::SPIwriteRegisterBurst(uint32_t reg, uint8_t* data, size_t numBytes) {
|
||||
if(!spiConfig.stream) {
|
||||
SPItransfer(spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE], reg, data, NULL, numBytes);
|
||||
} else {
|
||||
uint8_t cmd[] = { SPIwriteCommand, (uint8_t)((reg >> 8) & 0xFF), (uint8_t)(reg & 0xFF) };
|
||||
SPItransferStream(cmd, 3, true, data, NULL, numBytes, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
uint8_t cmd[6];
|
||||
uint8_t* cmdPtr = cmd;
|
||||
for(uint8_t i = 0; i < (uint8_t)this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8; i++) {
|
||||
*(cmdPtr++) = (this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] >> 8*i) & 0xFF;
|
||||
}
|
||||
for(int8_t i = (int8_t)((this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8) - 1); i >= 0; i--) {
|
||||
*(cmdPtr++) = (reg >> 8*i) & 0xFF;
|
||||
}
|
||||
SPItransferStream(cmd, this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8 + this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8, true, data, NULL, numBytes, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
void Module::SPIwriteRegister(uint16_t reg, uint8_t data) {
|
||||
if(!SPIstreamType) {
|
||||
SPItransfer(SPIwriteCommand, reg, &data, NULL, 1);
|
||||
void Module::SPIwriteRegister(uint32_t reg, uint8_t data) {
|
||||
if(!spiConfig.stream) {
|
||||
SPItransfer(spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE], reg, &data, NULL, 1);
|
||||
} else {
|
||||
uint8_t cmd[] = { SPIwriteCommand, (uint8_t)((reg >> 8) & 0xFF), (uint8_t)(reg & 0xFF) };
|
||||
SPItransferStream(cmd, 3, true, &data, NULL, 1, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
uint8_t cmd[6];
|
||||
uint8_t* cmdPtr = cmd;
|
||||
for(uint8_t i = 0; i < (uint8_t)this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8; i++) {
|
||||
*(cmdPtr++) = (this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] >> 8*i) & 0xFF;
|
||||
}
|
||||
for(int8_t i = (int8_t)((this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8) - 1); i >= 0; i--) {
|
||||
*(cmdPtr++) = (reg >> 8*i) & 0xFF;
|
||||
}
|
||||
SPItransferStream(cmd, this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8 + this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8, true, &data, NULL, 1, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes) {
|
||||
void Module::SPItransfer(uint16_t cmd, uint32_t reg, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes) {
|
||||
// prepare the buffers
|
||||
size_t buffLen = this->SPIaddrWidth/8 + numBytes;
|
||||
size_t buffLen = this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8 + this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8 + numBytes;
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
uint8_t buffOut[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
uint8_t buffIn[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
|
@ -155,7 +180,8 @@ void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* d
|
|||
uint8_t* buffOutPtr = buffOut;
|
||||
|
||||
// copy the command
|
||||
if(this->SPIaddrWidth <= 8) {
|
||||
// TODO properly handle variable commands and addresses
|
||||
if(this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] <= 8) {
|
||||
*(buffOutPtr++) = reg | cmd;
|
||||
} else {
|
||||
*(buffOutPtr++) = (reg >> 8) | cmd;
|
||||
|
@ -163,10 +189,10 @@ void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* d
|
|||
}
|
||||
|
||||
// copy the data
|
||||
if(cmd == SPIwriteCommand) {
|
||||
if(cmd == spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE]) {
|
||||
memcpy(buffOutPtr, dataOut, numBytes);
|
||||
} else {
|
||||
memset(buffOutPtr, this->SPInopCommand, numBytes);
|
||||
memset(buffOutPtr, this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP], numBytes);
|
||||
}
|
||||
|
||||
// do the transfer
|
||||
|
@ -177,19 +203,19 @@ void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* d
|
|||
this->hal->spiEndTransaction();
|
||||
|
||||
// copy the data
|
||||
if(cmd == SPIreadCommand) {
|
||||
memcpy(dataIn, &buffIn[this->SPIaddrWidth/8], numBytes);
|
||||
if(cmd == spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ]) {
|
||||
memcpy(dataIn, &buffIn[this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8], numBytes);
|
||||
}
|
||||
|
||||
// print debug information
|
||||
#if RADIOLIB_DEBUG_SPI
|
||||
uint8_t* debugBuffPtr = NULL;
|
||||
if(cmd == SPIwriteCommand) {
|
||||
if(cmd == spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE]) {
|
||||
RADIOLIB_DEBUG_SPI_PRINT("W\t%X\t", reg);
|
||||
debugBuffPtr = &buffOut[this->SPIaddrWidth/8];
|
||||
} else if(cmd == SPIreadCommand) {
|
||||
debugBuffPtr = &buffOut[this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8];
|
||||
} else if(cmd == spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ]) {
|
||||
RADIOLIB_DEBUG_SPI_PRINT("R\t%X\t", reg);
|
||||
debugBuffPtr = &buffIn[this->SPIaddrWidth/8];
|
||||
debugBuffPtr = &buffIn[this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR]/8];
|
||||
}
|
||||
for(size_t n = 0; n < numBytes; n++) {
|
||||
RADIOLIB_DEBUG_SPI_PRINT_NOTAG("%X\t", debugBuffPtr[n]);
|
||||
|
@ -203,8 +229,13 @@ void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* d
|
|||
#endif
|
||||
}
|
||||
|
||||
int16_t Module::SPIreadStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||
return(this->SPIreadStream(&cmd, 1, data, numBytes, waitForGpio, verify));
|
||||
int16_t Module::SPIreadStream(uint16_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||
uint8_t cmdBuf[2];
|
||||
uint8_t* cmdPtr = cmdBuf;
|
||||
for(uint8_t i = 0; i < (uint8_t)this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8; i++) {
|
||||
*(cmdPtr++) = (cmd >> 8*i) & 0xFF;
|
||||
}
|
||||
return(this->SPIreadStream(cmdBuf, this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8, data, numBytes, waitForGpio, verify));
|
||||
}
|
||||
|
||||
int16_t Module::SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||
|
@ -212,16 +243,27 @@ int16_t Module::SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_
|
|||
int16_t state = this->SPItransferStream(cmd, cmdLen, false, NULL, data, numBytes, waitForGpio, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
#if !RADIOLIB_SPI_PARANOID
|
||||
(void)verify;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
#else
|
||||
|
||||
// check the status
|
||||
if(verify) {
|
||||
state = this->SPIcheckStream();
|
||||
if(verify && (this->spiConfig.checkStatusCb != nullptr)) {
|
||||
state = this->spiConfig.checkStatusCb(this);
|
||||
}
|
||||
|
||||
return(state);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t Module::SPIwriteStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||
return(this->SPIwriteStream(&cmd, 1, data, numBytes, waitForGpio, verify));
|
||||
int16_t Module::SPIwriteStream(uint16_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||
uint8_t cmdBuf[2];
|
||||
uint8_t* cmdPtr = cmdBuf;
|
||||
for(uint8_t i = 0; i < (uint8_t)this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8; i++) {
|
||||
*(cmdPtr++) = (cmd >> 8*i) & 0xFF;
|
||||
}
|
||||
return(this->SPIwriteStream(cmdBuf, this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8, data, numBytes, waitForGpio, verify));
|
||||
}
|
||||
|
||||
int16_t Module::SPIwriteStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio, bool verify) {
|
||||
|
@ -229,12 +271,18 @@ int16_t Module::SPIwriteStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size
|
|||
int16_t state = this->SPItransferStream(cmd, cmdLen, true, data, NULL, numBytes, waitForGpio, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
#if !RADIOLIB_SPI_PARANOID
|
||||
(void)verify;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
#else
|
||||
|
||||
// check the status
|
||||
if(verify) {
|
||||
state = this->SPIcheckStream();
|
||||
if(verify && (this->spiConfig.checkStatusCb != nullptr)) {
|
||||
state = this->spiConfig.checkStatusCb(this);
|
||||
}
|
||||
|
||||
return(state);
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t Module::SPIcheckStream() {
|
||||
|
@ -243,13 +291,17 @@ int16_t Module::SPIcheckStream() {
|
|||
#if RADIOLIB_SPI_PARANOID
|
||||
// get the status
|
||||
uint8_t spiStatus = 0;
|
||||
uint8_t cmd = this->SPIstatusCommand;
|
||||
state = this->SPItransferStream(&cmd, 1, false, NULL, &spiStatus, 0, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
uint8_t cmdBuf[2];
|
||||
uint8_t* cmdPtr = cmdBuf;
|
||||
for(uint8_t i = 0; i < (uint8_t)this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8; i++) {
|
||||
*(cmdPtr++) = ( this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_STATUS] >> 8*i) & 0xFF;
|
||||
}
|
||||
state = this->SPItransferStream(cmdBuf, this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD]/8, false, NULL, &spiStatus, 1, true, RADIOLIB_MODULE_SPI_TIMEOUT);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// translate to RadioLib status code
|
||||
if(this->SPIparseStatusCb != nullptr) {
|
||||
this->SPIstreamError = this->SPIparseStatusCb(spiStatus);
|
||||
if(this->spiConfig.parseStatusCb != nullptr) {
|
||||
this->spiConfig.err = this->spiConfig.parseStatusCb(spiStatus);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -260,7 +312,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
|||
// prepare the buffers
|
||||
size_t buffLen = cmdLen + numBytes;
|
||||
if(!write) {
|
||||
buffLen++;
|
||||
buffLen += (this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS] / 8);
|
||||
}
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
uint8_t buffOut[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
|
@ -280,12 +332,12 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
|||
if(write) {
|
||||
memcpy(buffOutPtr, dataOut, numBytes);
|
||||
} else {
|
||||
memset(buffOutPtr, this->SPInopCommand, numBytes + 1);
|
||||
memset(buffOutPtr, this->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP], numBytes + (this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS] / 8));
|
||||
}
|
||||
|
||||
// ensure GPIO is low
|
||||
if(this->gpioPin == RADIOLIB_NC) {
|
||||
this->hal->delay(1);
|
||||
this->hal->delay(50);
|
||||
} else {
|
||||
uint32_t start = this->hal->millis();
|
||||
while(this->hal->digitalRead(this->gpioPin)) {
|
||||
|
@ -331,14 +383,14 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint
|
|||
|
||||
// parse status
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
if((this->SPIparseStatusCb != nullptr) && (numBytes > 0)) {
|
||||
state = this->SPIparseStatusCb(buffIn[cmdLen]);
|
||||
if((this->spiConfig.parseStatusCb != nullptr) && (numBytes > 0)) {
|
||||
state = this->spiConfig.parseStatusCb(buffIn[this->spiConfig.statusPos]);
|
||||
}
|
||||
|
||||
// copy the data
|
||||
if(!write) {
|
||||
// skip the first byte for read-type commands (status-only)
|
||||
memcpy(dataIn, &buffIn[cmdLen + 1], numBytes);
|
||||
// skip the status bytes if present
|
||||
memcpy(dataIn, &buffIn[cmdLen + (this->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_STATUS] / 8)], numBytes);
|
||||
}
|
||||
|
||||
// print debug information
|
||||
|
|
154
src/Module.h
154
src/Module.h
|
@ -13,15 +13,53 @@
|
|||
#endif
|
||||
|
||||
/*!
|
||||
\def Value to use as the last element in a mode table to indicate the
|
||||
end of the table.
|
||||
See \ref setRfSwitchTable for details.
|
||||
\def END_OF_MODE_TABLE Value to use as the last element in a mode table to indicate the
|
||||
end of the table. See \ref setRfSwitchTable for details.
|
||||
*/
|
||||
#define END_OF_MODE_TABLE { Module::MODE_END_OF_TABLE, {} }
|
||||
|
||||
// default timeout for SPI transfers
|
||||
#define RADIOLIB_MODULE_SPI_TIMEOUT (1000)
|
||||
|
||||
/*!
|
||||
\defgroup module_spi_command_pos Position of commands in Module::spiConfig command array.
|
||||
\{
|
||||
*/
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_READ Position of the read command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_READ (0)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_WRITE Position of the write command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_WRITE (1)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_NOP Position of the no-operation command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_NOP (2)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_STATUS Position of the status command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_STATUS (3)
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\defgroup module_spi_width_pos Position of bit field widths in Module::spiConfig width array.
|
||||
\{
|
||||
*/
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_WIDTH_ADDR Position of the address width. */
|
||||
#define RADIOLIB_MODULE_SPI_WIDTH_ADDR (0)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_WIDTH_CMD Position of the command width. */
|
||||
#define RADIOLIB_MODULE_SPI_WIDTH_CMD (1)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_WIDTH_STATUS Position of the status width. */
|
||||
#define RADIOLIB_MODULE_SPI_WIDTH_STATUS (2)
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class Module
|
||||
\brief Implements all common low-level methods to control the wireless module.
|
||||
|
@ -121,57 +159,59 @@ class Module {
|
|||
Module& operator=(const Module& mod);
|
||||
|
||||
// public member variables
|
||||
/*!
|
||||
\brief Hardware abstraction layer to be used.
|
||||
*/
|
||||
/*! \brief Hardware abstraction layer to be used. */
|
||||
RadioLibHal* hal = NULL;
|
||||
|
||||
/*!
|
||||
\brief Basic SPI read command. Defaults to 0x00.
|
||||
*/
|
||||
uint8_t SPIreadCommand = 0b00000000;
|
||||
|
||||
/*!
|
||||
\brief Basic SPI write command. Defaults to 0x80.
|
||||
*/
|
||||
uint8_t SPIwriteCommand = 0b10000000;
|
||||
|
||||
/*!
|
||||
\brief Basic SPI no-operation command. Defaults to 0x00.
|
||||
*/
|
||||
uint8_t SPInopCommand = 0x00;
|
||||
|
||||
/*!
|
||||
\brief Basic SPI status read command. Defaults to 0x00.
|
||||
*/
|
||||
uint8_t SPIstatusCommand = 0x00;
|
||||
|
||||
/*!
|
||||
\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).
|
||||
Defaults to register-type SPI interfaces.
|
||||
*/
|
||||
bool SPIstreamType = false;
|
||||
|
||||
/*!
|
||||
\brief The last recorded SPI stream error.
|
||||
*/
|
||||
int16_t SPIstreamError = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
/*!
|
||||
\brief SPI status parsing callback typedef.
|
||||
*/
|
||||
/*! \brief Callback for parsing SPI status. */
|
||||
typedef int16_t (*SPIparseStatusCb_t)(uint8_t in);
|
||||
|
||||
/*! \brief Callback for validation SPI status. */
|
||||
typedef int16_t (*SPIcheckStatusCb_t)(Module* mod);
|
||||
|
||||
enum BitWidth_t {
|
||||
BITS_0 = 0,
|
||||
BITS_8 = 8,
|
||||
BITS_16 = 16,
|
||||
BITS_32 = 32,
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief Callback to function that will parse the module-specific status codes to RadioLib status codes.
|
||||
Typically used for modules with SPI stream-type interface (e.g. SX126x/SX128x).
|
||||
\struct SPIConfig_t
|
||||
\brief SPI configuration structure.
|
||||
*/
|
||||
SPIparseStatusCb_t SPIparseStatusCb = nullptr;
|
||||
struct SPIConfig_t {
|
||||
/*! \brief Whether the SPI module is stream-type (SX126x/8x) or registrer access type (SX127x, CC1101 etc). */
|
||||
bool stream;
|
||||
|
||||
/*! \brief Last recorded SPI error - only updated for modules that return status during SPI transfers. */
|
||||
int16_t err;
|
||||
|
||||
/*! \brief SPI commands */
|
||||
uint16_t cmds[4];
|
||||
|
||||
/*! \brief Bit widths of SPI addresses, commands and status bytes */
|
||||
BitWidth_t widths[3];
|
||||
|
||||
/*! \brief Byte position of status command in SPI stream */
|
||||
uint8_t statusPos;
|
||||
|
||||
/*! \brief Callback for parsing SPI status. */
|
||||
SPIparseStatusCb_t parseStatusCb;
|
||||
|
||||
/*! \brief Callback for validation SPI status. */
|
||||
SPIcheckStatusCb_t checkStatusCb;
|
||||
};
|
||||
|
||||
/*! \brief SPI configuration structure. The default configuration corresponds to register-access modules, such as SX127x. */
|
||||
SPIConfig_t spiConfig = {
|
||||
.stream = false,
|
||||
.err = RADIOLIB_ERR_UNKNOWN,
|
||||
.cmds = { 0x00, 0x80, 0x00, 0x00 },
|
||||
.widths = { Module::BITS_8, Module::BITS_0, Module::BITS_8 },
|
||||
.statusPos = 0,
|
||||
.parseStatusCb = nullptr,
|
||||
.checkStatusCb = nullptr,
|
||||
};
|
||||
|
||||
#if RADIOLIB_INTERRUPT_TIMING
|
||||
|
||||
|
@ -213,7 +253,7 @@ class Module {
|
|||
\param lsb Least significant bit of the register variable. Bits below this one will be masked out.
|
||||
\returns Masked register value or status code.
|
||||
*/
|
||||
int16_t SPIgetRegValue(uint16_t reg, uint8_t msb = 7, uint8_t lsb = 0);
|
||||
int16_t SPIgetRegValue(uint32_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.
|
||||
|
@ -225,7 +265,7 @@ class Module {
|
|||
\param checkMask Mask of bits to check, only bits set to 1 will be verified.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
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);
|
||||
int16_t SPIsetRegValue(uint32_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.
|
||||
|
@ -233,14 +273,14 @@ class Module {
|
|||
\param numBytes Number of bytes that will be read.
|
||||
\param inBytes Pointer to array that will hold the read data.
|
||||
*/
|
||||
void SPIreadRegisterBurst(uint16_t reg, size_t numBytes, uint8_t* inBytes);
|
||||
void SPIreadRegisterBurst(uint32_t reg, size_t numBytes, uint8_t* inBytes);
|
||||
|
||||
/*!
|
||||
\brief SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
|
||||
\param reg Address of SPI register to read.
|
||||
\returns Value that was read from register.
|
||||
*/
|
||||
uint8_t SPIreadRegister(uint16_t reg);
|
||||
uint8_t SPIreadRegister(uint32_t reg);
|
||||
|
||||
/*!
|
||||
\brief SPI burst write method.
|
||||
|
@ -248,14 +288,14 @@ class Module {
|
|||
\param data Pointer to array that holds the data that will be written.
|
||||
\param numBytes Number of bytes that will be written.
|
||||
*/
|
||||
void SPIwriteRegisterBurst(uint16_t reg, uint8_t* data, size_t numBytes);
|
||||
void SPIwriteRegisterBurst(uint32_t reg, uint8_t* data, size_t numBytes);
|
||||
|
||||
/*!
|
||||
\brief SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
|
||||
\param reg Address of SPI register to write.
|
||||
\param data Value that will be written to the register.
|
||||
*/
|
||||
void SPIwriteRegister(uint16_t reg, uint8_t data);
|
||||
void SPIwriteRegister(uint32_t reg, uint8_t data);
|
||||
|
||||
/*!
|
||||
\brief SPI single transfer method.
|
||||
|
@ -265,7 +305,7 @@ class Module {
|
|||
\param dataIn Data that was transferred from slave to master.
|
||||
\param numBytes Number of bytes to transfer.
|
||||
*/
|
||||
void SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes);
|
||||
void SPItransfer(uint16_t cmd, uint32_t reg, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes);
|
||||
|
||||
/*!
|
||||
\brief Method to check the result of last SPI stream transfer.
|
||||
|
@ -282,7 +322,7 @@ class Module {
|
|||
\param verify Whether to verify the result of the transaction after it is finished.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIreadStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
int16_t SPIreadStream(uint16_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
|
||||
/*!
|
||||
\brief Method to perform a read transaction with SPI stream.
|
||||
|
@ -305,7 +345,7 @@ class Module {
|
|||
\param verify Whether to verify the result of the transaction after it is finished.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIwriteStream(uint8_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
int16_t SPIwriteStream(uint16_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
|
||||
/*!
|
||||
\brief Method to perform a write transaction with SPI stream.
|
||||
|
|
|
@ -53,16 +53,7 @@
|
|||
|
||||
// print debug info
|
||||
#if RADIOLIB_DEBUG
|
||||
#define RADIOLIB_VALUE_TO_STRING(x) #x
|
||||
#define RADIOLIB_VALUE(x) RADIOLIB_VALUE_TO_STRING(x)
|
||||
#pragma message("\nRadioLib Debug Info\nVersion: \"" \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_MAJOR) "." \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_MINOR) "." \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_PATCH) "." \
|
||||
RADIOLIB_VALUE(RADIOLIB_VERSION_EXTRA) "\"\n" \
|
||||
"Platform: " RADIOLIB_VALUE(RADIOLIB_PLATFORM) "\n" \
|
||||
"Compiled: " RADIOLIB_VALUE(__DATE__) " " RADIOLIB_VALUE(__TIME__) \
|
||||
)
|
||||
#pragma message(RADIOLIB_INFO)
|
||||
#endif
|
||||
|
||||
// check unknown/unsupported platform
|
||||
|
|
|
@ -8,8 +8,8 @@ CC1101::CC1101(Module* module) : PhysicalLayer(RADIOLIB_CC1101_FREQUENCY_STEP_SI
|
|||
|
||||
int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t pwr, uint8_t preambleLength) {
|
||||
// set module properties
|
||||
this->mod->SPIreadCommand = RADIOLIB_CC1101_CMD_READ;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_CC1101_CMD_WRITE;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_CC1101_CMD_READ;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_CC1101_CMD_WRITE;
|
||||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
|
||||
|
|
|
@ -14,12 +14,15 @@ int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, flo
|
|||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
|
||||
this->mod->SPIreadCommand = RADIOLIB_SX126X_CMD_READ_REGISTER;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_SX126X_CMD_WRITE_REGISTER;
|
||||
this->mod->SPInopCommand = RADIOLIB_SX126X_CMD_NOP;
|
||||
this->mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS;
|
||||
this->mod->SPIstreamType = true;
|
||||
this->mod->SPIparseStatusCb = SPIparseStatus;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_16;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_8;
|
||||
this->mod->spiConfig.statusPos = 1;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_SX126X_CMD_READ_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_SX126X_CMD_WRITE_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP] = RADIOLIB_SX126X_CMD_NOP;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_STATUS] = RADIOLIB_SX126X_CMD_GET_STATUS;
|
||||
this->mod->spiConfig.stream = true;
|
||||
this->mod->spiConfig.parseStatusCb = SPIparseStatus;
|
||||
|
||||
// try to find the SX126x chip
|
||||
if(!SX126x::findChip(this->chipType)) {
|
||||
|
@ -99,12 +102,15 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleL
|
|||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
|
||||
this->mod->SPIreadCommand = RADIOLIB_SX126X_CMD_READ_REGISTER;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_SX126X_CMD_WRITE_REGISTER;
|
||||
this->mod->SPInopCommand = RADIOLIB_SX126X_CMD_NOP;
|
||||
this->mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS;
|
||||
this->mod->SPIstreamType = true;
|
||||
this->mod->SPIparseStatusCb = SPIparseStatus;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_16;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_8;
|
||||
this->mod->spiConfig.statusPos = 1;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_SX126X_CMD_READ_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_SX126X_CMD_WRITE_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP] = RADIOLIB_SX126X_CMD_NOP;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_STATUS] = RADIOLIB_SX126X_CMD_GET_STATUS;
|
||||
this->mod->spiConfig.stream = true;
|
||||
this->mod->spiConfig.parseStatusCb = SPIparseStatus;
|
||||
|
||||
// try to find the SX126x chip
|
||||
if(!SX126x::findChip(this->chipType)) {
|
||||
|
|
|
@ -11,12 +11,15 @@ int16_t SX128x::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
|||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
|
||||
this->mod->SPIreadCommand = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->SPInopCommand = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->SPIstreamType = true;
|
||||
this->mod->SPIparseStatusCb = SPIparseStatus;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_16;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_8;
|
||||
this->mod->spiConfig.statusPos = 1;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP] = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_STATUS] = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->spiConfig.stream = true;
|
||||
this->mod->spiConfig.parseStatusCb = SPIparseStatus;
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX128x");
|
||||
|
||||
// initialize LoRa modulation variables
|
||||
|
@ -72,12 +75,15 @@ int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t pwr, ui
|
|||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
|
||||
this->mod->SPIreadCommand = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->SPInopCommand = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->SPIstreamType = true;
|
||||
this->mod->SPIparseStatusCb = SPIparseStatus;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_16;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_8;
|
||||
this->mod->spiConfig.statusPos = 1;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP] = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_STATUS] = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->spiConfig.stream = true;
|
||||
this->mod->spiConfig.parseStatusCb = SPIparseStatus;
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX128x");
|
||||
|
||||
// initialize GFSK modulation variables
|
||||
|
@ -141,12 +147,15 @@ int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t pwr, uin
|
|||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
|
||||
this->mod->SPIreadCommand = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->SPInopCommand = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->SPIstreamType = true;
|
||||
this->mod->SPIparseStatusCb = SPIparseStatus;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_16;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_8;
|
||||
this->mod->spiConfig.statusPos = 1;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP] = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_STATUS] = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->spiConfig.stream = true;
|
||||
this->mod->spiConfig.parseStatusCb = SPIparseStatus;
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX128x");
|
||||
|
||||
// initialize BLE modulation variables
|
||||
|
@ -196,12 +205,15 @@ int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t pwr, uint1
|
|||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
|
||||
this->mod->SPIreadCommand = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->SPInopCommand = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->SPIstreamType = true;
|
||||
this->mod->SPIparseStatusCb = SPIparseStatus;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_ADDR] = Module::BITS_16;
|
||||
this->mod->spiConfig.widths[RADIOLIB_MODULE_SPI_WIDTH_CMD] = Module::BITS_8;
|
||||
this->mod->spiConfig.statusPos = 1;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_SX128X_CMD_READ_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_SX128X_CMD_WRITE_REGISTER;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_NOP] = RADIOLIB_SX128X_CMD_NOP;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_STATUS] = RADIOLIB_SX128X_CMD_GET_STATUS;
|
||||
this->mod->spiConfig.stream = true;
|
||||
this->mod->spiConfig.parseStatusCb = SPIparseStatus;
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX128x");
|
||||
|
||||
// initialize FLRC modulation variables
|
||||
|
|
|
@ -8,8 +8,8 @@ nRF24::nRF24(Module* mod) : PhysicalLayer(RADIOLIB_NRF24_FREQUENCY_STEP_SIZE, RA
|
|||
|
||||
int16_t nRF24::begin(int16_t freq, int16_t dr, int8_t pwr, uint8_t addrWidth) {
|
||||
// set module properties
|
||||
this->mod->SPIreadCommand = RADIOLIB_NRF24_CMD_READ;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_NRF24_CMD_WRITE;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_NRF24_CMD_READ;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_NRF24_CMD_WRITE;
|
||||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue