1

Committer:
advxolltm
Date:
Mon Jun 06 16:37:12 2022 +0000
Revision:
22:fc88e265f425
Parent:
5:ab124d3842a8
123

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 0:9c052ff8dd6a 1 #include "radio.h"
Wayne Roberts 0:9c052ff8dd6a 2
Wayne Roberts 0:9c052ff8dd6a 3 #define RADIO_RESET PC_2 //NorAm_Mote Reset_sx
Wayne Roberts 0:9c052ff8dd6a 4 #define RADIO_MOSI PB_15 //NorAm_Mote SPI2 Mosi
Wayne Roberts 0:9c052ff8dd6a 5 #define RADIO_MISO PB_14 //NorAm_Mote SPI2 Miso
Wayne Roberts 0:9c052ff8dd6a 6 #define RADIO_SCLK PB_13 //NorAm_Mote SPI2 Clk
Wayne Roberts 0:9c052ff8dd6a 7 #define RADIO_NSS PB_12 //NorAm_Mote SPI2 Nss
Wayne Roberts 0:9c052ff8dd6a 8
Wayne Roberts 0:9c052ff8dd6a 9 #define RADIO_DIO_0 PC_6 //NorAm_Mote DIO0
Wayne Roberts 0:9c052ff8dd6a 10 #define RADIO_DIO_1 PC_10 //NorAm_Mote DIO1
Wayne Roberts 0:9c052ff8dd6a 11 #define RADIO_DIO_2 PC_8 //NorAm_Mote DIO2
Wayne Roberts 0:9c052ff8dd6a 12 #define RADIO_DIO_3 PB_4 //NorAm_Mote DIO3
Wayne Roberts 0:9c052ff8dd6a 13 #define RADIO_DIO_4 PB_5 //NorAm_Mote DIO4
Wayne Roberts 0:9c052ff8dd6a 14 #define RADIO_DIO_5 PB_6 //NorAm_Mote DIO5
Wayne Roberts 0:9c052ff8dd6a 15
Wayne Roberts 0:9c052ff8dd6a 16 #define RFSW1 PC_4 //NorAm_Mote RFSwitch_CNTR_1
Wayne Roberts 0:9c052ff8dd6a 17 #define RFSW2 PC_13 //NorAm_Mote RFSwitch_CNTR_2
Wayne Roberts 0:9c052ff8dd6a 18
Wayne Roberts 0:9c052ff8dd6a 19 // txpow: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Wayne Roberts 0:9c052ff8dd6a 20 const uint8_t PaBTable[20] = { 0, 0, 0, 0, 0, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15 };
Wayne Roberts 0:9c052ff8dd6a 21
Wayne Roberts 0:9c052ff8dd6a 22 // txpow: 20 21 22 23 24 25 26 27 28 29 30
Wayne Roberts 0:9c052ff8dd6a 23 const uint8_t RfoTable[11] = { 1, 1, 1, 2, 2, 3, 4, 5, 6, 8, 9 };
Wayne Roberts 0:9c052ff8dd6a 24
Wayne Roberts 5:ab124d3842a8 25 #include "SPIu.h"
Wayne Roberts 5:ab124d3842a8 26 SPIu spi(RADIO_MOSI, RADIO_MISO, RADIO_SCLK); // mosi, miso, sclk
Wayne Roberts 0:9c052ff8dd6a 27 // dio0, dio1, nss, spi, rst
Wayne Roberts 0:9c052ff8dd6a 28 SX127x Radio::radio(RADIO_DIO_0, RADIO_DIO_1, RADIO_NSS, spi, RADIO_RESET); // sx1276 arduino shield
Wayne Roberts 0:9c052ff8dd6a 29 SX127x_lora Radio::lora(radio);
Wayne Roberts 0:9c052ff8dd6a 30 SX127x_fsk Radio::fsk(radio);
Wayne Roberts 0:9c052ff8dd6a 31
Wayne Roberts 0:9c052ff8dd6a 32 DigitalOut rfsw1(RFSW1);
Wayne Roberts 0:9c052ff8dd6a 33 DigitalOut rfsw2(RFSW2);
Wayne Roberts 0:9c052ff8dd6a 34
Wayne Roberts 0:9c052ff8dd6a 35 InterruptIn Radio::dio0(RADIO_DIO_0);
Wayne Roberts 0:9c052ff8dd6a 36 InterruptIn Radio::dio1(RADIO_DIO_1);
Wayne Roberts 0:9c052ff8dd6a 37
Wayne Roberts 0:9c052ff8dd6a 38 DigitalOut red(LED1);
Wayne Roberts 0:9c052ff8dd6a 39 DigitalOut yellow(LED3);
Wayne Roberts 0:9c052ff8dd6a 40 #define LED_OFF 1
Wayne Roberts 0:9c052ff8dd6a 41 #define LED_ON 0
Wayne Roberts 0:9c052ff8dd6a 42
Wayne Roberts 0:9c052ff8dd6a 43 void Radio::rfsw_callback()
Wayne Roberts 0:9c052ff8dd6a 44 {
Wayne Roberts 0:9c052ff8dd6a 45 if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) { // start of transmission
Wayne Roberts 0:9c052ff8dd6a 46 red = LED_ON;
Wayne Roberts 0:9c052ff8dd6a 47 yellow = LED_OFF;
Wayne Roberts 0:9c052ff8dd6a 48 if (radio.HF) {
Wayne Roberts 0:9c052ff8dd6a 49 if (radio.RegPaConfig.bits.PaSelect) { // if PA_BOOST
Wayne Roberts 0:9c052ff8dd6a 50 rfsw2 = 0;
Wayne Roberts 0:9c052ff8dd6a 51 rfsw1 = 1;
Wayne Roberts 0:9c052ff8dd6a 52 } else { // RFO to power amp
Wayne Roberts 0:9c052ff8dd6a 53 rfsw2 = 1;
Wayne Roberts 0:9c052ff8dd6a 54 rfsw1 = 0;
Wayne Roberts 0:9c052ff8dd6a 55 }
Wayne Roberts 0:9c052ff8dd6a 56 } else {
Wayne Roberts 0:9c052ff8dd6a 57 // todo: sx1276
Wayne Roberts 0:9c052ff8dd6a 58 }
Wayne Roberts 0:9c052ff8dd6a 59 } else if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE || radio.RegOpMode.bits.Mode == RF_OPMODE_CAD) { // start of reception
Wayne Roberts 0:9c052ff8dd6a 60 red = LED_OFF;
Wayne Roberts 0:9c052ff8dd6a 61 yellow = LED_ON;
Wayne Roberts 0:9c052ff8dd6a 62 if (radio.HF) {
Wayne Roberts 0:9c052ff8dd6a 63 rfsw2 = 1;
Wayne Roberts 0:9c052ff8dd6a 64 rfsw1 = 1;
Wayne Roberts 0:9c052ff8dd6a 65 } else {
Wayne Roberts 0:9c052ff8dd6a 66 // todo: sx1276
Wayne Roberts 0:9c052ff8dd6a 67 }
Wayne Roberts 0:9c052ff8dd6a 68 } else { // RF switch shutdown
Wayne Roberts 0:9c052ff8dd6a 69 yellow = LED_OFF;
Wayne Roberts 0:9c052ff8dd6a 70 red = LED_OFF;
Wayne Roberts 0:9c052ff8dd6a 71 rfsw2 = 0;
Wayne Roberts 0:9c052ff8dd6a 72 rfsw1 = 0;
Wayne Roberts 0:9c052ff8dd6a 73 }
Wayne Roberts 0:9c052ff8dd6a 74 }
Wayne Roberts 0:9c052ff8dd6a 75
Wayne Roberts 0:9c052ff8dd6a 76 void
Wayne Roberts 0:9c052ff8dd6a 77 Radio::set_tx_dbm(int8_t dbm)
Wayne Roberts 0:9c052ff8dd6a 78 {
Wayne Roberts 0:9c052ff8dd6a 79 //int i = dbm;
Wayne Roberts 0:9c052ff8dd6a 80 RegPdsTrim1_t pds_trim;
Wayne Roberts 0:9c052ff8dd6a 81 uint8_t adr;
Wayne Roberts 0:9c052ff8dd6a 82
Wayne Roberts 0:9c052ff8dd6a 83 radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
Wayne Roberts 0:9c052ff8dd6a 84
Wayne Roberts 0:9c052ff8dd6a 85 if (dbm < 20) {
Wayne Roberts 0:9c052ff8dd6a 86 radio.RegPaConfig.bits.PaSelect = 1;
Wayne Roberts 0:9c052ff8dd6a 87 if (dbm < 0)
Wayne Roberts 0:9c052ff8dd6a 88 dbm = 0;
Wayne Roberts 0:9c052ff8dd6a 89 radio.RegPaConfig.bits.OutputPower = PaBTable[dbm];
Wayne Roberts 0:9c052ff8dd6a 90 } else {
Wayne Roberts 0:9c052ff8dd6a 91 radio.RegPaConfig.bits.PaSelect = 0;
Wayne Roberts 0:9c052ff8dd6a 92 if (dbm > 30)
Wayne Roberts 0:9c052ff8dd6a 93 dbm = 30;
Wayne Roberts 0:9c052ff8dd6a 94 radio.RegPaConfig.bits.OutputPower = RfoTable[dbm-20];
Wayne Roberts 0:9c052ff8dd6a 95 }
Wayne Roberts 0:9c052ff8dd6a 96
Wayne Roberts 0:9c052ff8dd6a 97 if (radio.type == SX1276)
Wayne Roberts 0:9c052ff8dd6a 98 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 0:9c052ff8dd6a 99 else
Wayne Roberts 0:9c052ff8dd6a 100 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 0:9c052ff8dd6a 101
Wayne Roberts 0:9c052ff8dd6a 102 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 0:9c052ff8dd6a 103
Wayne Roberts 0:9c052ff8dd6a 104 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 0:9c052ff8dd6a 105 /* PABOOST used: +2dbm to +17, or +20 */
Wayne Roberts 0:9c052ff8dd6a 106 if (dbm == 20) {
Wayne Roberts 0:9c052ff8dd6a 107 dbm -= 3;
Wayne Roberts 0:9c052ff8dd6a 108 pds_trim.bits.prog_txdac = 7;
Wayne Roberts 0:9c052ff8dd6a 109 radio.write_reg(adr, pds_trim.octet);
Wayne Roberts 0:9c052ff8dd6a 110 ocp(150);
Wayne Roberts 0:9c052ff8dd6a 111 } else if (dbm < 18) {
Wayne Roberts 0:9c052ff8dd6a 112 pds_trim.bits.prog_txdac = 5;
Wayne Roberts 0:9c052ff8dd6a 113 radio.write_reg(adr, pds_trim.octet);
Wayne Roberts 0:9c052ff8dd6a 114 ocp(120);
Wayne Roberts 0:9c052ff8dd6a 115 }
Wayne Roberts 0:9c052ff8dd6a 116 } else
Wayne Roberts 0:9c052ff8dd6a 117 ocp(80);
Wayne Roberts 0:9c052ff8dd6a 118
Wayne Roberts 0:9c052ff8dd6a 119 radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
Wayne Roberts 0:9c052ff8dd6a 120 } // ..set_tx_dbm()
Wayne Roberts 0:9c052ff8dd6a 121
Wayne Roberts 0:9c052ff8dd6a 122 void Radio::boardInit()
Wayne Roberts 0:9c052ff8dd6a 123 {
Wayne Roberts 0:9c052ff8dd6a 124 red = LED_OFF;
Wayne Roberts 0:9c052ff8dd6a 125 yellow = LED_OFF;
Wayne Roberts 0:9c052ff8dd6a 126 }
Wayne Roberts 0:9c052ff8dd6a 127