This program enables the use of the Semtech "SX1276 Starter Kit A" application to be used with the FRDM-KL25Z board. At the time of writing this, this app was available on Semtech's SX1276 page, in the "Docs & Resources"* tab, via the link "PC GUI (1.0.0Beta5)". This program was tested with the FRDM-KL25Z board, with a Modtronix inAir9 SX1276 board mounted in a Modtronix SHD3I shield. The inAir9 module is mounted in iMod port 3 of the SHD3I module. The SHD3I shield is mounted on the FRDM-KL25Z board.

Dependencies:   SX127x_modtronix USBDevice_Semtech_GUI mbed

Fork of hid_test by wayne roberts

Revision:
2:1972097c22d1
Parent:
1:d25ba61cd2f3
--- a/main.cpp	Wed Apr 30 23:06:39 2014 +0000
+++ b/main.cpp	Mon Feb 16 02:14:45 2015 +0000
@@ -4,9 +4,49 @@
 
 //#define _DEBUG_ 
 
-//  pin:      3     8     1      7    10    12     5   20    18
-//           mosi, miso, sclk,   cs,  rst,  dio0, dio1, fctx, fcps 
-SX127x radio(PTD2, PTD3, PTD1, PTD0, PTD5, PTA13, PTD4, PTC9, PTC8);
+/*
+ * This program is a modified version of the "hid_test" application by Wayne Roberts. All credits go
+ * to Wayne for writing it, I just did some minor modiciations!
+ *
+ * The program was tested with the FRDM-KL25Z board, with a Modtronix inAir9 SX1276 board mounted in
+ * a Modtronix SHD3I shield. The inAir9 module is mounted in iMod port 3 of the SHD3I module. The
+ * SHD3I shield is mounted on the FRDM-KL25Z board.
+ * It enables the use of the Semtech "SX1276 Starter Kit A" application to be used with this board. 
+ * At the time of writing this, this app was available on Semtech's SX1276 page, in the "Docs & Resources"
+ * tab, via the link "PC GUI (1.0.0Beta5)".
+ * This app can be used for sending and receiving data via the SX1276. To use it:
+ * - Plug the FRDM-KL25Z into the PC via the USB marked "USB KL25Z"
+ * - Start Semtech "SX1276 Starter Kit A" app on PC
+ * - App should connect to board, enabling it to control board.
+ *
+ * ========== Firmware for KL25Z ==========
+ * The default firmware listed on mbed.org puts a clock pulse on pin A5. To fix this, use alternative
+ * firmware (or unsolder resistor R24).
+ * - Download "OpenSDA Firmware" from http://www.pemicro.com/opensda/
+ * - Put KL25Z into bootloader mode (hold down button while plugging in SDA USB).
+ * - Drag "MSD-DEBUG-FRDM-KL25Z_Pemicro_v114.SDA" file onto it.
+ * - Reset KL25Z.
+ * - If the USB drivers do not automatically install, download and run "Windows USB Drivers" from
+ *   www.pemicro.com/opensda. After this, when you plug in the KL25Z next time, all drivers should
+ *   install correctly.
+ */
+
+#define TARGET_KL25Z_SHD3I_INAIR8           /* FRDM-KL25Z + Modtronix inAir9 SX1276 board + SHD3I daughter board */
+
+//Defines for the FRDM-KL25Z board, with Modtronix SHD3I with an inAir9 SX1276 module mounted in it. 
+#ifdef TARGET_KL25Z_SHD3I_INAIR8
+//SCLK=D13, MISO=D12, MOSI=D11
+//CS=D7, Reset=A5
+//DIO0=D2, DIO1=D8, DIO2=D4, DIO3=A4, DIO4=N.C., DIO5=D3
+//           mosi, miso, sclk, cs,  rst, dio0, dio1
+SX127x radio(D11,  D12,  D13,  D7,  A5,  D2,   D8);
+#else
+//  pin:      3     8     1    7     10    12      5 
+//           mosi, miso, sclk, cs,   rst,  dio0,  dio1
+//           D11   D12   D13   D10   D9    D8     D2
+SX127x radio(PTD2, PTD3, PTD1, PTD0, PTD5, PTA13, PTD4);
+#endif
+
 #ifdef _DEBUG_
     #include "sx127x_lora.h"
     SX127x_lora lora(radio);
@@ -66,6 +106,40 @@
 char verbose = 0;
 #endif /* _DEBUG_ */
 
+//Following code is from V7
+//DigitalOut rfsw1(PTC8);
+//DigitalOut rfsw2(PTC9);
+
+void rfsw_callback()
+{
+    /*
+    if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {  // start of transmission
+        if (radio.HF) {
+            if (radio.RegPaConfig.bits.PaSelect) { // if PA_BOOST
+                rfsw2 = 0;
+                rfsw1 = 1;
+            } else { // RFO to power amp
+                rfsw2 = 1;
+                rfsw1 = 0;            
+            }
+        } else {
+            // todo: sx1276
+        }
+    } else if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_CAD) { // start of reception
+        if (radio.HF) {
+            rfsw2 = 1;
+            rfsw1 = 1;              
+        } else {
+            // todo: sx1276
+        }
+    } else { // RF switch shutdown
+        rfsw2 = 0;
+        rfsw1 = 0;              
+    }
+    */
+}
+
+
 void HidDecodeCommand( uint8_t *hidReport, tHidCommand *cmd )
 {
     cmd->Cmd = hidReport[0];
@@ -161,14 +235,18 @@
             // cmd.CmdData[0] = Pin id
             switch( cmd.CmdData[0] ) {
                 case 11:    // FEM_CPS_PIN
-                    dataBuffer[0] = radio.femcps;
+                    //MODTRONIX modified, we do not have a femcps pin
+                    //dataBuffer[0] = radio.femcps;
+                    dataBuffer[0] = 0;
                     #ifdef _DEBUG_
                     if (verbose)
                         printf("HID_SK_GET_PIN femcps:%02x\r\n", dataBuffer[0]);
                     #endif /* _DEBUG_ */
                     break;
                 case 12:    // FEM_CTX_PIN
-                    dataBuffer[0] = radio.femctx;
+                    //MODTRONIX modified, we do not have a femctx pin
+                    //dataBuffer[0] = radio.femctx;
+                    dataBuffer[0] = 0;
                     #ifdef _DEBUG_
                     if (verbose)
                         printf("HID_SK_GET_PIN femctx:%02x\r\n", dataBuffer[0]);
@@ -192,14 +270,16 @@
                     // ignore LEDs
                     break;
                 case 11:    // FEM_CPS_PIN
-                    radio.femcps = cmd.CmdData[1];
+                    //MODTRONIX modified, we do not have a femcps pin
+                    //radio.femcps = cmd.CmdData[1];
                     #ifdef _DEBUG_
                     if (verbose)
                         printf("HID_SK_SET_PIN femcps:%d\r\n", (int)radio.femcps);
                     #endif /* _DEBUG_ */
                     break;                    
                 case 12:    // FEM_CTX_PIN
-                    radio.femctx = cmd.CmdData[1];
+                    //MODTRONIX modified, we do not have a femctx pin
+                    //radio.femctx = cmd.CmdData[1];
                     #ifdef _DEBUG_
                     if (verbose)
                         printf("HID_SK_SET_PIN femctx:%d\r\n", (int)radio.femctx); 
@@ -609,6 +689,9 @@
     pc.baud(57600);
     pc.printf("\r\nstart\r\n");
     #endif /* _DEBUG_ */
+
+    //Required for V7 of SX127x library, but V7 doesn't work for this program!
+    radio.rf_switch.attach(rfsw_callback);
     
     while (1) { 
         //try to read a msg