point-2-point demo

Dependencies:   sx12xx_hal

radio chip selection

Radio chip driver is not included, because these options are available.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.

TX trigger selection

Edit main.h to define DIGITAL_TRIGGER or ANALOG_TRIGGER to chose whether transmit is initiated by digital pin (button/jumper) or analog pin(s) level change.

This project is intended to be used on two LoRa shields.

Each board sits in continuous RX mode, waiting for request packet.
If the received packet has good CRC, the packet is acknowledged along with read of ADC sample from the replying device.
The original request packet also contains instruction to set level of output pin.

Both sides of the link are running the same code, and each can initiate a transmission at any time.
No addressing is used, so only two nodes can operate on the radio channel.

Revision:
5:e35b1b281466
Parent:
4:b5dd459ac390
--- a/main.cpp	Tue Jul 17 14:32:29 2018 -0700
+++ b/main.cpp	Wed Aug 01 15:04:11 2018 -0700
@@ -1,7 +1,5 @@
+#include "main.h"
 #include "radio.h"
-#include "uart_cmds.h"
-
-//#define ANALOG_TX_TRIGGER
 
 #if defined(SX127x_H) || defined(SX126x_H)
     #define BW_KHZ              500
@@ -23,24 +21,13 @@
 
 DigitalOut myled(LED1);
 
-
 Timer t;
-Ticker ticker;
 volatile bool tx_done;
-InterruptIn user_button(USER_BUTTON);
 DigitalOut pc6_out(PC_6);
 
-#ifndef ANALOG_TX_TRIGGER
-    #define AIN_REST_THRESHOLD      96  // 12bit left justified
-    DigitalOut jumper_out(PC_10);
-    InterruptIn jumper_in(PC_12);
-    volatile bool start_tx;
-#endif /* !ANALOG_TX_TRIGGER */
-
 #define RX_TIMEOUT_US       200000
 /**********************************************************************/
 
-uint8_t out_pin_state;
 
 void txDoneCB()
 {
@@ -173,23 +160,6 @@
     } // ..for()
 }
 
-#ifndef ANALOG_TX_TRIGGER
-void button_isr()
-{
-    if (!jumper_in.read())
-        start_tx = true;
-}
-
-void auto_tx()
-{
-    if (jumper_in.read())
-        start_tx = true;
-    else
-        ticker.detach();
-}
-#endif /* !ANALOG_TX_TRIGGER */
-
-
 const RadioEvents_t rev = {
     /* Dio0_top_half */     NULL,
     /* TxDone_topHalf */    NULL,
@@ -204,23 +174,10 @@
 
 int main()
 {
-#ifdef ANALOG_TX_TRIGGER
-    uint16_t prev_ain;
-    int8_t ain_movement;
-    bool ain_sent;
-#else
-    bool jin = false;
+    printf("\r\nreset\r\n");
 
-    jumper_out = 1;
-    jumper_in.mode(PullDown);
+    trigger_init();
 
-    while (!user_button) {
-        printf("button-lo\r\n");
-        wait(0.01);
-    }
-    user_button.fall(&button_isr);
-#endif /* !ANALOG_TX_TRIGGER */
-    printf("\r\n2reset\r\n");
     t.start();
 
     Radio::Init(&rev);
@@ -232,67 +189,9 @@
     
     Radio::Rx(0);
 
-#ifdef ANALOG_TX_TRIGGER
-    prev_ain = a1.read_u16();
-    ain_movement = 0;
-    ain_sent = false;
-#endif /* ANALOG_TX_TRIGGER */
     for (;;) {
-#ifdef ANALOG_TX_TRIGGER
-        uint16_t ain = a1.read_u16();
-        uint16_t diff = abs(ain-prev_ain);
-        if (diff > AIN_REST_THRESHOLD) {
-            ain_sent = false;
-            if (ain_movement < 1)
-                ain_movement = 1;
-            else {
-                if (++ain_movement > 16)
-                    ain_movement = 16;
-            }
-        } else {
-            /* steady state */
-            if (ain_movement > 0)
-                ain_movement = 0;
-            else {
-                if (--ain_movement < -16) {
-                    ain_movement = -16;
-                    if (!ain_sent) {
-                        uint8_t buf[4];
-                        printf("## %02x ##\r\n", ain >> 8);
-                        buf[0] = CMD_PWM;
-                        buf[1] = 120;   // Hz
-                        buf[2] = ain >> 8;  // duty
-                        radio_tx(buf, 3);
-                        ain_sent = true;
-                    }
-                }
-            }
-        }
-        //printf("%05u  diff:%04u  move:%d\r\n", ain, diff, ain_movement);
-        prev_ain = ain;
-        wait_us(5000);
+        trigger_mainloop();
 
-#else
-
-        if (jumper_in.read()) {
-            if (!jin) {
-                ticker.attach(auto_tx, 0.5);
-                jin = true;
-            }
-        } else {
-            jin = false;
-        }
-
-        if (start_tx) {
-            start_tx = false;
-
-            uint8_t buf[2];
-            out_pin_state ^= 1;
-            buf[0] = CMD_OUT_PIN;
-            buf[1] = out_pin_state;
-            radio_tx(buf, 2);
-        }
-#endif /* !ANALOG_TX_TRIGGER */
         if (rx.length > 0) {
             uint16_t crc, rx_crc;
             int i;