Alarm generator, transmitter side

Dependencies:   sx12xx_hal

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
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.

This is transmitter project; Receiver side is Alarm Slave project.
This project generates alarm (transmits) from grounding certain pins.
To find the actual pins used, refer to the code where pin[A-D] is declared as DigitalIn.

Alarm message is sent N times with future timestamp indicating when alarm is to occur. This accommodates dropped packets, resulting in alarm occurring when as few as 1 packet is received.

Revision:
5:1652e04809fb
Parent:
4:19056d9707ef
Child:
6:59ba1113b3c6
--- a/main.cpp	Mon Jan 29 18:20:10 2018 +0000
+++ b/main.cpp	Mon Feb 05 15:03:27 2018 -0800
@@ -1,68 +1,5 @@
-#include "sx127x_lora.h"
+#include "platform.h"
  
-#ifdef TARGET_DISCO_L072CZ_LRWAN1
-
-    SPI spi(PA_7, PA_6, PB_3); // mosi, miso, sclk
-    //           dio0, dio1,  nss,  spi,  rst
-    SX127x radio(PB_4, PB_1, PA_15, spi, PC_0);
-    
-    #define CRF1    PA_1
-    #define CRF2    PC_2
-    #define CRF3    PC_1
-    DigitalOut Vctl1(CRF1);
-    DigitalOut Vctl2(CRF2);
-    DigitalOut Vctl3(CRF3);    
-    
-    void rfsw_callback()
-    {
-        if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {
-            Vctl1 = 0;        
-            if (radio.RegPaConfig.bits.PaSelect) {
-                Vctl2 = 0;
-                Vctl3 = 1;                        
-            } else {
-                Vctl2 = 1;
-                Vctl3 = 0;            
-            }
-        } else {
-            if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
-                Vctl1 = 1;
-            else
-                Vctl1 = 0;
-            
-            Vctl2 = 0;
-            Vctl3 = 0;        
-        }
-    }    
-    
-    DigitalIn pinA(PB_12);
-    DigitalIn pinB(PB_13);
-    DigitalIn pinC(PB_14);
-    DigitalIn pinD(PB_15);    
-#else
-    SPI spi(D11, D12, D13); // mosi, miso, sclk
-    //           dio0, dio1, nss, spi, rst
-    SX127x radio(  D2,   D3, D10, spi, A0); // sx1276 arduino shield
-     
-    DigitalInOut rfsw(A4);    // for SX1276 arduino shield
-     
-    void rfsw_callback()
-    {
-        if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) {
-            rfsw = 1;
-        } else {
-            rfsw = 0;
-        }
-    }
-    
-    DigitalIn pinA(PC_3);
-    DigitalIn pinB(PC_2);
-    DigitalIn pinC(PC_6);
-    DigitalIn pinD(PC_8);
-#endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
-
-/**********************************************************************/
-
 SX127x_lora lora(radio);
 Timer t;
 #define CMD_PINA       0x02
@@ -168,47 +105,6 @@
     printf("Ocp: %dmA\r\n", ma); 
 }
 
-void cmd_op(int dbm)
-{
-    int i = dbm;
-    RegPdsTrim1_t pds_trim;
-    uint8_t adr;
-    if (radio.type == SX1276)
-        adr = REG_PDSTRIM1_SX1276;
-    else
-        adr = REG_PDSTRIM1_SX1272;
-       
-    pds_trim.octet = radio.read_reg(adr);   
-
-    if (radio.RegPaConfig.bits.PaSelect) {
-        /* PABOOST used: +2dbm to +17, or +20 */
-        if (i == 20) {
-            printf("+20dBm PADAC bias\r\n");
-            i -= 3;
-            pds_trim.bits.prog_txdac = 7;
-            radio.write_reg(adr, pds_trim.octet);
-            cmd_ocp(150);
-        }
-        if (i > 1)
-                radio.RegPaConfig.bits.OutputPower = i - 2;
-    } else {
-        /* RFO used: -1 to +14dbm */
-        if (i < 15)
-            radio.RegPaConfig.bits.OutputPower = i + 1;
-    }
-    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
-
-    radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
-    if (radio.RegPaConfig.bits.PaSelect) {
-        printf("PA_BOOST ");
-        dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
-    } else {
-        printf("RFO ");
-        dbm = radio.RegPaConfig.bits.OutputPower - 1;
-    }
-    printf("OutputPower:%ddBm\r\n", dbm);
-}
-
 int main()
 {
     printf("\r\nreset-tx\r\n");
@@ -226,32 +122,7 @@
     lora.setBw_KHz(500);
     lora.setSf(11);
     
-    radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
-#ifdef TARGET_DISCO_L072CZ_LRWAN1
-    radio.RegPaConfig.bits.PaSelect = 1;
-    cmd_op(20);
-#else    
-    /* RFO or PABOOST choice:
-     * SX1276 shield: RFO if using 900MHz, or PA_BOOST if using 433MHz
-     */
-    rfsw.input();
-    if (rfsw.read()) {
-        printf("LAS\r\n");
-        /* LAS HF=PA_BOOST  LF=RFO */
-        if (radio.HF)
-            radio.RegPaConfig.bits.PaSelect = 1;
-        else
-            radio.RegPaConfig.bits.PaSelect = 0;
-        cmd_op(20);
-    } else {
-        /* MAS shield board, only RFO TX */
-        radio.RegPaConfig.bits.PaSelect = 0;
-        printf("MAS\r\n");
-        cmd_op(14);
-    }
-    rfsw.output();
-#endif /* !TARGET_DISCO_L072CZ_LRWAN1 */
-    radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
+    board_init();
                 
     /* constant payload length */
     lora.RegPayloadLength = 7;