Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to define TCXO and XTAL radio modules within one variant #4492

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ AccelerometerThread *accelerometerThread = nullptr;
AudioThread *audioThread = nullptr;
#endif

#if defined(TCXO_OPTIONAL)
float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // if TCXO is optional, put this here so it can be changed further down.
#endif

using namespace concurrency;

// We always create a screen object, but we only init it if we find the hardware
Expand Down Expand Up @@ -890,7 +894,7 @@ void setup()
}
#endif

#if defined(USE_SX1262) && !defined(ARCH_PORTDUINO)
#if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) && !defined(TCXO_OPTIONAL)
if (!rIf) {
rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY);
if (!rIf->init()) {
Expand All @@ -904,6 +908,40 @@ void setup()
}
#endif

#if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) && defined(TCXO_OPTIONAL)
if (!rIf) {
// Try using the specified TCXO voltage
rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY);
if (!rIf->init()) {
LOG_WARN("Failed to find SX1262 radio with TCXO using DIO3 reference voltage at %f V\n", tcxoVoltage);
delete rIf;
rIf = NULL;
tcxoVoltage = 0; // if it fails, set the TCXO voltage to zero for the next attempt
} else {
LOG_INFO("SX1262 Radio init succeeded, using ");
LOG_WARN("SX1262 Radio with TCXO");
LOG_INFO(", reference voltage at %f V\n", tcxoVoltage);
radioType = SX1262_RADIO;
}
}

if (!rIf) {
// If specified TCXO voltage fails, attempt to use DIO3 as a reference instea
rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY);
if (!rIf->init()) {
LOG_WARN("Failed to find SX1262 radio with XTAL using DIO3 reference voltage at %f V\n", tcxoVoltage);
delete rIf;
rIf = NULL;
tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // if it fails, set the TCXO voltage back for the next radio search
} else {
LOG_INFO("SX1262 Radio init succeeded, using ");
LOG_WARN("SX1262 Radio with XTAL");
LOG_INFO(", reference voltage at %f V\n", tcxoVoltage);
radioType = SX1262_RADIO;
}
}
#endif

#if defined(USE_SX1268)
if (!rIf) {
rIf = new SX1268Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY);
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/SX126xInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ template <typename T> bool SX126xInterface<T>::init()
0; // "TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip." per
// https://github.com/jgromes/RadioLib/blob/690a050ebb46e6097c5d00c371e961c1caa3b52e/src/modules/SX126x/SX126x.h#L471C26-L471C104
// (DIO3 is free to be used as an IRQ)
#else
#elif !defined(TCXO_OPTIONAL)
float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE;
// (DIO3 is not free to be used as an IRQ)
#endif
Expand Down Expand Up @@ -345,4 +345,4 @@ template <typename T> bool SX126xInterface<T>::sleep()
#endif

return true;
}
}
33 changes: 20 additions & 13 deletions variants/diy/nrf52_promicro_diy_tcxo/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,29 @@ NRF52 PRO MICRO PIN ASSIGNMENT
#define SX126X_RXEN (0 + 17) // P0.17
#define SX126X_TXEN RADIOLIB_NC // Assuming that DIO2 is connected to TXEN pin. If not, TXEN must be connected.

/*
On the SX1262, DIO3 sets the voltage for an external TCXO, if one is present. If one is not present, then this should not be used.

Ebyte
e22-900mm22s has no TCXO
e22-900m22s has TCXO
e220-900mm22s has no TCXO, works with/without this definition, looks like DIO3 not connected at all

AI-thinker
RA-01SH does not have TCXO
// #define SX126X_MAX_POWER 8 set this if using a high-power board!

Waveshare
Core1262 has TCXO
/*
On the SX1262, DIO3 sets the voltage for an external TCXO, if one is present. If one is not present, use TCXO_OPTIONAL to try both settings.

| Mfr | Module | TCXO | RF Switch | Notes |
| ---------- | ---------------- | ---- | --------- | -------------------------------------------- |
| Ebyte | E22-900M22S | Yes | Ext | |
| Ebyte | E22-900MM22S | No | Ext | |
| Ebyte | E22-900M30S | Yes | Ext | |
| Ebyte | E22-900M33S | Yes | Ext | MAX_POWER must be set to 8 for this |
| Ebyte | E220-900M22S | No | Ext | LLCC68, looks like DIO3 not connected at all |
| AI-Thinker | RA-01SH | No | Int | |
| Heltec | HT-RA62 | Yes | Int | |
| NiceRF | Lora1262 | yes | Int | |
| Waveshare | Core1262-HF | yes | Ext | |
| Waveshare | LoRa Node Module | yes | Int | |

*/

#define SX126X_DIO3_TCXO_VOLTAGE 1.8
#define TCXO_OPTIONAL // make it so that the firmware can try both TCXO and XTAL
extern float tcxoVoltage; // make this available everywhere

#ifdef __cplusplus
}
Expand All @@ -153,4 +160,4 @@ Core1262 has TCXO
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/

#endif
#endif
Loading