Repository: radiolib-org/RadioBoards
Pull request #8: Add RAKWireless RAK11300 Module
Author: login: ScholliYT
Created: 2025-03-07T18:18:05Z | Merged: 2025-03-23T20:14:19Z

This PR adds support for the [RAK11300](https://store.rakwireless.com/products/wisduo-lpwan-module-rak11300) Module to RadioBoards to make it easier to use with RadioLib.

The code is mostly based on https://www.nico-maas.de/?p=2607 from @nmaas87

Features:
* Add support for RAK11300 with SX1262
* Use SPI1 as defined in Arduino-Pico
* Use custom RF Switch

TODO:
- [x] Auto detect board based on compiler flags (any flag that can we use?)


Diff:
diff --git a/src/RadioBoards.h b/src/RadioBoards.h
index 9767153..39fc9c6 100644
--- a/src/RadioBoards.h
+++ b/src/RadioBoards.h
@@ -43,6 +43,9 @@
 
   #elif defined(ARDUINO_LILYGO_T3S3_SX1262) || defined(ARDUINO_LILYGO_T3S3_SX1276) || defined(ARDUINO_LILYGO_T3S3_LR1121)
     #define RADIO_BOARD_LILYGO_T3S3
+
+  #elif defined(ARDUINO_RAKWIRELESS_RAK11300)
+    #define RADIO_BOARD_RAKWIRELESS_RAK11300
   
   #else
     #error "Unable to resolve board type automatically, please select one from the supported list"
@@ -110,6 +113,9 @@
 #elif defined(RADIO_BOARD_LILYGO_T3S3)
   #include "contributed/LilyGo/LilyGo_T3S3.h"
 
+#elif defined(RADIO_BOARD_RAKWIRELESS_RAK11300)
+  #include "contributed/RAKWireless/RAK11300.h"
+
 #else
   #error "Unsupported or unknown radio board!"
 
diff --git a/src/contributed/RAKWireless/RAK11300.h b/src/contributed/RAKWireless/RAK11300.h
new file mode 100644
index 0000000..6a272eb
--- /dev/null
+++ b/src/contributed/RAKWireless/RAK11300.h
@@ -0,0 +1,50 @@
+#if !defined(_RADIOBOARDS_CONTRIBUTED_RAK11300_H)
+#define _RADIOBOARDS_CONTRIBUTED_RAK11300_H
+
+// Pin definitions taken from:
+//    RAK definition: https://github.com/RAKWireless/RAK-RP-Arduino/
+//    RAK datasheet: https://docs.rakwireless.com/Product-Categories/WisDuo/RAK11300-Module/Datasheet/#overview
+//    Internal wiring of SX1262 module: https://forum.rakwireless.com/t/rak11300-pinout-rp2040-to-sx1262/8414/
+//    Arduino-Pico: https://github.com/earlephilhower/arduino-pico/blob/5bd1a3a0f6f4df55053daf2c13c853f233501c81/variants/rakwireless_rak11300/pins_arduino.h#L6
+// Based on: https://www.nico-maas.de/?p=2607
+
+#define RADIO_BOARDS_NAME "RAKWireless RAK11300"
+
+#define RADIO_NSS     (PIN_SPI1_SS)
+#define RADIO_IRQ     (PIN_SX1262_DIO1)
+#define RADIO_RST     (PIN_SX1262_NRESET)
+#define RADIO_GPIO    (PIN_SX1262_BUSY)
+
+// this board uses custom SPI to interface with the module
+// SPI pins are configured in Arduino-Pico
+#define RADIO_SPI     SPI1
+
+#define RADIO_PIN_SX1262_ANT_PWR PIN_SX1262_ANT_PWR
+
+#define RADIO_SPI_INIT                                      \
+  RADIO_SPI.begin(RADIO_NSS);
+
+#endif
+
+
+#if RADIOLIB_SUPPORT_ENABLED
+  #define Radio       SX1262
+
+  // it also has custom RF switching
+  #define RADIO_RF_SWITCH
+
+  #define RADIO_RF_SWITCH_PINS                              \
+  static const uint32_t RadioBoards_rfswitch_pins[] = {     \
+      RADIO_PIN_SX1262_ANT_PWR,                             \
+      RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC    \
+    };
+
+  #define RADIO_RF_SWITCH_TABLE \
+  static const Module::RfSwitchMode_t RadioBoards_rfswitch_table[] = {  \
+    /* mode              ANT_PWR */                         \
+    {Module::MODE_IDLE,  {LOW}},                            \
+    {Module::MODE_RX,    {HIGH}},                           \
+    {Module::MODE_TX,    {HIGH}},                           \
+    END_OF_MODE_TABLE,                                      \
+  };
+#endif
\ No newline at end of file


Reviews:
user: login: jgromes
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-08T10:04:33Z
user: login: ScholliYT
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-08T11:07:42Z

Review comments:
diff_hunk: @@ -0,0 +1,50 @@
+#if !defined(_RADIOBOARDS_CONTRIBUTED_RAK11300_H)
+#define _RADIOBOARDS_CONTRIBUTED_RAK11300_H
+
+// Pin definitions taken from:
+//    RAK definition: https://github.com/RAKWireless/RAK-RP-Arduino/
+//    RAK datasheet: https://docs.rakwireless.com/Product-Categories/WisDuo/RAK11300-Module/Datasheet/#overview
+//    Internal wiring of SX1262 module: https://forum.rakwireless.com/t/rak11300-pinout-rp2040-to-sx1262/8414/
+//    Arduino-Pico: https://github.com/earlephilhower/arduino-pico/blob/5bd1a3a0f6f4df55053daf2c13c853f233501c81/variants/rakwireless_rak11300/pins_arduino.h#L6
+// Based on: https://www.nico-maas.de/?p=2607
+
+#define RADIO_BOARDS_NAME "RAKWireless RAK11300"
+
+#define RADIO_NSS     (PIN_SPI1_SS)
+#define RADIO_IRQ     (PIN_SX1262_DIO1)
+#define RADIO_RST     (PIN_SX1262_NRESET)
+#define RADIO_GPIO    (PIN_SX1262_BUSY)
+
+// this board uses custom SPI to interface with the module
+// SPI pins are configured in Arduino-Pico
+#define RADIO_SPI     SPI1
+
+#define RADIO_PIN_SX1262_ANT_PWR PIN_SX1262_ANT_PWR
+
+#define RADIO_SPI_INIT                                      \
+  RADIO_SPI.begin(RADIO_NSS);
+
+#endif
+
+
+#if RADIOLIB_SUPPORT_ENABLED
+  #define Radio       SX1262
+
+  // it also has custom RF switching
+  #define RADIO_RF_SWITCH
+
+  #define RADIO_RF_SWITCH_PINS                              \
+  static const uint32_t RadioBoards_rfswitch_pins[] = {     \
+      RADIO_PIN_SX1262_ANT_PWR,                             \
+      RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC    \
+    };
+
+  #define RADIO_RF_SWITCH_TABLE \
+  static const Module::RfSwitchMode_t RadioBoards_rfswitch_table[] = {  \
+    /* mode              ANT_PWR */                         \
+    {Module::MODE_IDLE,  {LOW}},                            \
+    {Module::MODE_RX,    {HIGH}},                           \
+    {Module::MODE_TX,    {HIGH}},                           \
+    {Module::MODE_IDLE,  {LOW}},                            \
path: src/contributed/RAKWireless/RAK11300.h
user: login: jgromes
body: Why is idle mode twice here? It should be enough to have it just once.
created_at: 2025-03-08T10:04:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,50 @@
+#if !defined(_RADIOBOARDS_CONTRIBUTED_RAK11300_H)
+#define _RADIOBOARDS_CONTRIBUTED_RAK11300_H
+
+// Pin definitions taken from:
+//    RAK definition: https://github.com/RAKWireless/RAK-RP-Arduino/
+//    RAK datasheet: https://docs.rakwireless.com/Product-Categories/WisDuo/RAK11300-Module/Datasheet/#overview
+//    Internal wiring of SX1262 module: https://forum.rakwireless.com/t/rak11300-pinout-rp2040-to-sx1262/8414/
+//    Arduino-Pico: https://github.com/earlephilhower/arduino-pico/blob/5bd1a3a0f6f4df55053daf2c13c853f233501c81/variants/rakwireless_rak11300/pins_arduino.h#L6
+// Based on: https://www.nico-maas.de/?p=2607
+
+#define RADIO_BOARDS_NAME "RAKWireless RAK11300"
+
+#define RADIO_NSS     (PIN_SPI1_SS)
+#define RADIO_IRQ     (PIN_SX1262_DIO1)
+#define RADIO_RST     (PIN_SX1262_NRESET)
+#define RADIO_GPIO    (PIN_SX1262_BUSY)
+
+// this board uses custom SPI to interface with the module
+// SPI pins are configured in Arduino-Pico
+#define RADIO_SPI     SPI1
+
+#define RADIO_PIN_SX1262_ANT_PWR PIN_SX1262_ANT_PWR
+
+#define RADIO_SPI_INIT                                      \
+  RADIO_SPI.begin(RADIO_NSS);
+
+#endif
+
+
+#if RADIOLIB_SUPPORT_ENABLED
+  #define Radio       SX1262
+
+  // it also has custom RF switching
+  #define RADIO_RF_SWITCH
+
+  #define RADIO_RF_SWITCH_PINS                              \
+  static const uint32_t RadioBoards_rfswitch_pins[] = {     \
+      RADIO_PIN_SX1262_ANT_PWR,                             \
+      RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC    \
+    };
+
+  #define RADIO_RF_SWITCH_TABLE \
+  static const Module::RfSwitchMode_t RadioBoards_rfswitch_table[] = {  \
+    /* mode              ANT_PWR */                         \
+    {Module::MODE_IDLE,  {LOW}},                            \
+    {Module::MODE_RX,    {HIGH}},                           \
+    {Module::MODE_TX,    {HIGH}},                           \
+    {Module::MODE_IDLE,  {LOW}},                            \
path: src/contributed/RAKWireless/RAK11300.h
user: login: ScholliYT
body: You're absolutely right. Stupid copy paste error... 
created_at: 2025-03-08T11:07:42Z
author_association: CONTRIBUTOR

PR comments:
user: login: jgromes
created_at: 2025-03-08T10:08:36Z
body: Thank you for the contribution! I left one comment. 

Do you want to keep this open until you figure out the automated detection? If so, then please mark it as draft so that it doesn't get merged prematurely.
author_association: CONTRIBUTOR
user: login: serialrf433
created_at: 2025-03-13T17:11:29Z
body: I also had some struggle to understand how the automatic detection is working.
Here is the solution for esp32: https://github.com/radiolib-org/RadioBoards/issues/5#issuecomment-2721992913

But the RAK1130 is not esp32. That is why you have to take a look at the arduino library you are using to add support for this board when using the library you have chosen. If you for example use this: https://github.com/RAKWireless/RAK-RP-Arduino
Then inside here https://raw.githubusercontent.com/RAKWireless/RAK-RP-Arduino/refs/heads/main/boards.txt its the line WisCoreRAK11300Board.build.board=RASPBERRY_PI_PICO

So the name for autodetection when using this library would be: **RASPBERRY_PI_PICO**

I hope you are using some other library, because RAK's choice is not that great to be added to RadioBoards because its far too general.
author_association: NONE
user: login: StevenCellist
created_at: 2025-03-19T12:52:06Z
body: Compiling a random sketch for the RAK11300 on the Arduino IDE with verbose compilation uncovers the following definition:

```cpp
ARDUINO_RAKWIRELESS_RAK11300
```

This RAK11300 is present in the unofficial RP2040 core - it is not the BSP from RAKWireless linked above by @serialrf433. So the question would be which core @ScholliYT wishes to use. Personally, I'd say using the RP2040 core makes sense.
author_association: COLLABORATOR
user: login: ScholliYT
created_at: 2025-03-19T20:51:48Z
body: I was wondering about the same thing. Which BSP should be chosen if any. 

Personally, I am using PlatformIO with the following setup based on a [fork](https://github.com/maxgerhardt/platform-raspberrypi.) of the unofficial [RP2040 core](https://github.com/earlephilhower/arduino-pico).
```ini
[env:rakwireless_rak11300]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rakwireless_rak11300
framework = arduino
board_build.core = earlephilhower
monitor_speed = 115200
lib_deps = 
	jgromes/RadioLib@^7.1.2
	; jgromes/RadioBoards@^1.0.0
        git+git@github.com:ScholliYT/RadioBoards.git#rakwireless-rak11300
```

We have `ARDUINO_RAKWIRELESS_RAK11300` in [there](https://github.com/maxgerhardt/platform-raspberrypi/blob/daa66b4a9853aae38bdcc482f0a702215013425b/boards/rakwireless_rak11300.json#L12) as @StevenCellist commented. 

author_association: CONTRIBUTOR
user: login: StevenCellist
created_at: 2025-03-19T20:54:08Z
body: Definitely use the RP2040, I'd say - it's actually maintained. So let's stick to `ARDUINO_RAKWIRELESS_RAK11300`. Could you kindly add it to cross off your TODO?
author_association: COLLABORATOR
user: login: ScholliYT
created_at: 2025-03-19T21:32:43Z
body: Done. This should be good to go now @jgromes 
author_association: CONTRIBUTOR
user: login: jgromes
created_at: 2025-03-23T20:14:42Z
body: @ScholliYT merged - thank you for the contribution!
author_association: CONTRIBUTOR