USB HID bridge between SX127x device and PC GUI

Dependencies:   SX127x USBDevice mbed

/media/uploads/dudmuck/lora.png

This application is a USB bridge between SX1272 or SX1276 transceiver chip and PC GUI. You can use Freescale Freedom instead of an expensive Open4, or another board supported by USBHID. Later, you might then use the freedom board for your own firmware development.

The pre-existing PC GUI checks for product device name of USB device to match a specific string of text.

After you import this program, you will have your own private copy of USB HID driver.

Edit the file USBDevice -> USBHID -> USBHID.cpp:

modification to USB HID driver

/*uint8_t * USBHID::stringIproductDesc() {
    static uint8_t stringIproductDescriptor[] = {
        0x16,                                                       //bLength
        STRING_DESCRIPTOR,                                          //bDescriptorType 0x03
        'H',0,'I',0,'D',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0 //bString iProduct - HID device
    };
    return stringIproductDescriptor;
}*/

uint8_t * USBHID::stringIproductDesc() {
    static uint8_t stringIproductDescriptor[] = {
        0x18,                                                       //bLength
        STRING_DESCRIPTOR,                                          //bDescriptorType 0x03
        'S',0,'X',0,'1',0,'2',0,'x',0,'x',0,'E',0,'i',0,'g',0,'e',0,'r',0 //bString iProduct - HID device
    };
    return stringIproductDescriptor;
}

Revision:
2:d17ce14e02d7
Parent:
1:d25ba61cd2f3
--- a/main.cpp	Wed Apr 30 23:06:39 2014 +0000
+++ b/main.cpp	Tue Jul 26 23:34:20 2016 +0000
@@ -4,14 +4,14 @@
 
 //#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);
+//           mosi, miso, sclk,   cs,  rst,  dio0, dio1
+SX127x radio(D11,   D12, D13,    D10,  A0,   D2,   D3); // sx1276 arduino shield
 #ifdef _DEBUG_
     #include "sx127x_lora.h"
     SX127x_lora lora(radio);
 #endif /* _DEBUG_ */
 
+DigitalInOut rfsw(A4);
 //We declare a USBHID device. By default input and output reports are 64 bytes long.
 USBHID hid(64, 64, 0x47a, 0x0b);
 //USBHID (uint8_t output_report_length=64, uint8_t input_report_length=64, uint16_t vendor_id=0x1234, uint16_t product_id=0x0006, uint16_t product_release=0x0001, bool connect=true) 
@@ -66,6 +66,14 @@
 char verbose = 0;
 #endif /* _DEBUG_ */
 
+void rfsw_callback()
+{
+    if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER)
+        rfsw = 1;
+    else
+        rfsw = 0;
+}
+
 void HidDecodeCommand( uint8_t *hidReport, tHidCommand *cmd )
 {
     cmd->Cmd = hidReport[0];
@@ -161,14 +169,14 @@
             // cmd.CmdData[0] = Pin id
             switch( cmd.CmdData[0] ) {
                 case 11:    // FEM_CPS_PIN
-                    dataBuffer[0] = radio.femcps;
+                    // not existing on shield board -- dataBuffer[0] = radio.femcps;
                     #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;
+                    // not existing on shield board --  dataBuffer[0] = radio.femctx;
                     #ifdef _DEBUG_
                     if (verbose)
                         printf("HID_SK_GET_PIN femctx:%02x\r\n", dataBuffer[0]);
@@ -192,14 +200,14 @@
                     // ignore LEDs
                     break;
                 case 11:    // FEM_CPS_PIN
-                    radio.femcps = cmd.CmdData[1];
+                    // not existing on shield board -- 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];
+                    // not existing on shield board -- radio.femctx = cmd.CmdData[1];
                     #ifdef _DEBUG_
                     if (verbose)
                         printf("HID_SK_SET_PIN femctx:%d\r\n", (int)radio.femctx); 
@@ -610,6 +618,8 @@
     pc.printf("\r\nstart\r\n");
     #endif /* _DEBUG_ */
     
+    radio.rf_switch.attach(rfsw_callback);
+    
     while (1) { 
         //try to read a msg
         if (hid.readNB(&recv_report)) {