1
radio_ff_arduino_sx127x.cpp@0:9c052ff8dd6a, 2018-07-05 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Thu Jul 05 17:31:54 2018 -0700
- Revision:
- 0:9c052ff8dd6a
- Child:
- 5:ab124d3842a8
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:9c052ff8dd6a | 1 | /* Only for NUCLEO boards: prevent compiling for MOTE_L152RC and typeABZ discovery */ |
Wayne Roberts |
0:9c052ff8dd6a | 2 | #if defined(TARGET_FF_ARDUINO) && defined(TARGET_FF_MORPHO) && !defined(TARGET_DISCO_L072CZ_LRWAN1) |
Wayne Roberts |
0:9c052ff8dd6a | 3 | #include "radio.h" |
Wayne Roberts |
0:9c052ff8dd6a | 4 | #ifdef SX127x_H |
Wayne Roberts |
0:9c052ff8dd6a | 5 | #include "SPIu.h" |
Wayne Roberts |
0:9c052ff8dd6a | 6 | |
Wayne Roberts |
0:9c052ff8dd6a | 7 | SPIu spi(D11, D12, D13); // mosi, miso, sclk |
Wayne Roberts |
0:9c052ff8dd6a | 8 | // dio0, dio1, nss, spi, rst |
Wayne Roberts |
0:9c052ff8dd6a | 9 | SX127x Radio::radio( D2, D3, D10, spi, A0); // sx127[62] arduino shield |
Wayne Roberts |
0:9c052ff8dd6a | 10 | SX127x_lora Radio::lora(radio); |
Wayne Roberts |
0:9c052ff8dd6a | 11 | SX127x_fsk Radio::fsk(radio); |
Wayne Roberts |
0:9c052ff8dd6a | 12 | |
Wayne Roberts |
0:9c052ff8dd6a | 13 | InterruptIn Radio::dio0(D2); |
Wayne Roberts |
0:9c052ff8dd6a | 14 | InterruptIn Radio::dio1(D3); |
Wayne Roberts |
0:9c052ff8dd6a | 15 | |
Wayne Roberts |
0:9c052ff8dd6a | 16 | typedef enum { |
Wayne Roberts |
0:9c052ff8dd6a | 17 | SHIELD_TYPE_NONE = 0, |
Wayne Roberts |
0:9c052ff8dd6a | 18 | SHIELD_TYPE_LAS, |
Wayne Roberts |
0:9c052ff8dd6a | 19 | SHIELD_TYPE_MAS, |
Wayne Roberts |
0:9c052ff8dd6a | 20 | } shield_type_e; |
Wayne Roberts |
0:9c052ff8dd6a | 21 | shield_type_e shield_type; |
Wayne Roberts |
0:9c052ff8dd6a | 22 | |
Wayne Roberts |
0:9c052ff8dd6a | 23 | #ifdef TARGET_FF_MORPHO |
Wayne Roberts |
0:9c052ff8dd6a | 24 | DigitalOut pc3(PC_3); // debug RX indication, for nucleo boards |
Wayne Roberts |
0:9c052ff8dd6a | 25 | #endif /* TARGET_FF_MORPHO */ |
Wayne Roberts |
0:9c052ff8dd6a | 26 | DigitalInOut rfsw(A4); |
Wayne Roberts |
0:9c052ff8dd6a | 27 | void Radio::rfsw_callback() |
Wayne Roberts |
0:9c052ff8dd6a | 28 | { |
Wayne Roberts |
0:9c052ff8dd6a | 29 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) |
Wayne Roberts |
0:9c052ff8dd6a | 30 | rfsw = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 31 | else |
Wayne Roberts |
0:9c052ff8dd6a | 32 | rfsw = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 33 | |
Wayne Roberts |
0:9c052ff8dd6a | 34 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE) |
Wayne Roberts |
0:9c052ff8dd6a | 35 | pc3 = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 36 | else |
Wayne Roberts |
0:9c052ff8dd6a | 37 | pc3 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 38 | } |
Wayne Roberts |
0:9c052ff8dd6a | 39 | |
Wayne Roberts |
0:9c052ff8dd6a | 40 | void |
Wayne Roberts |
0:9c052ff8dd6a | 41 | Radio::set_tx_dbm(int8_t dbm) |
Wayne Roberts |
0:9c052ff8dd6a | 42 | { |
Wayne Roberts |
0:9c052ff8dd6a | 43 | RegPdsTrim1_t pds_trim; |
Wayne Roberts |
0:9c052ff8dd6a | 44 | uint8_t adr; |
Wayne Roberts |
0:9c052ff8dd6a | 45 | |
Wayne Roberts |
0:9c052ff8dd6a | 46 | if (radio.type == SX1276) |
Wayne Roberts |
0:9c052ff8dd6a | 47 | adr = REG_PDSTRIM1_SX1276; |
Wayne Roberts |
0:9c052ff8dd6a | 48 | else |
Wayne Roberts |
0:9c052ff8dd6a | 49 | adr = REG_PDSTRIM1_SX1272; |
Wayne Roberts |
0:9c052ff8dd6a | 50 | |
Wayne Roberts |
0:9c052ff8dd6a | 51 | pds_trim.octet = radio.read_reg(adr); |
Wayne Roberts |
0:9c052ff8dd6a | 52 | |
Wayne Roberts |
0:9c052ff8dd6a | 53 | if (shield_type == SHIELD_TYPE_LAS) |
Wayne Roberts |
0:9c052ff8dd6a | 54 | radio.RegPaConfig.bits.PaSelect = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 55 | else |
Wayne Roberts |
0:9c052ff8dd6a | 56 | radio.RegPaConfig.bits.PaSelect = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 57 | |
Wayne Roberts |
0:9c052ff8dd6a | 58 | if (radio.RegPaConfig.bits.PaSelect) { |
Wayne Roberts |
0:9c052ff8dd6a | 59 | /* PABOOST used: +2dbm to +17, or +20 */ |
Wayne Roberts |
0:9c052ff8dd6a | 60 | if (dbm > 17) { |
Wayne Roberts |
0:9c052ff8dd6a | 61 | if (dbm > 20) |
Wayne Roberts |
0:9c052ff8dd6a | 62 | dbm = 20; |
Wayne Roberts |
0:9c052ff8dd6a | 63 | dbm -= 3; |
Wayne Roberts |
0:9c052ff8dd6a | 64 | pds_trim.bits.prog_txdac = 7; |
Wayne Roberts |
0:9c052ff8dd6a | 65 | radio.write_reg(adr, pds_trim.octet); |
Wayne Roberts |
0:9c052ff8dd6a | 66 | ocp(150); |
Wayne Roberts |
0:9c052ff8dd6a | 67 | } else |
Wayne Roberts |
0:9c052ff8dd6a | 68 | ocp(120); |
Wayne Roberts |
0:9c052ff8dd6a | 69 | |
Wayne Roberts |
0:9c052ff8dd6a | 70 | if (dbm > 1) |
Wayne Roberts |
0:9c052ff8dd6a | 71 | radio.RegPaConfig.bits.OutputPower = dbm - 2; |
Wayne Roberts |
0:9c052ff8dd6a | 72 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 73 | /* RFO used: -1 to +14dbm */ |
Wayne Roberts |
0:9c052ff8dd6a | 74 | ocp(80); |
Wayne Roberts |
0:9c052ff8dd6a | 75 | if (dbm < 15) |
Wayne Roberts |
0:9c052ff8dd6a | 76 | radio.RegPaConfig.bits.OutputPower = dbm + 1; |
Wayne Roberts |
0:9c052ff8dd6a | 77 | } |
Wayne Roberts |
0:9c052ff8dd6a | 78 | radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet); |
Wayne Roberts |
0:9c052ff8dd6a | 79 | |
Wayne Roberts |
0:9c052ff8dd6a | 80 | radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG); |
Wayne Roberts |
0:9c052ff8dd6a | 81 | if (radio.RegPaConfig.bits.PaSelect) { |
Wayne Roberts |
0:9c052ff8dd6a | 82 | dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2; |
Wayne Roberts |
0:9c052ff8dd6a | 83 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 84 | dbm = radio.RegPaConfig.bits.OutputPower - 1; |
Wayne Roberts |
0:9c052ff8dd6a | 85 | } |
Wayne Roberts |
0:9c052ff8dd6a | 86 | } |
Wayne Roberts |
0:9c052ff8dd6a | 87 | |
Wayne Roberts |
0:9c052ff8dd6a | 88 | void Radio::boardInit() |
Wayne Roberts |
0:9c052ff8dd6a | 89 | { |
Wayne Roberts |
0:9c052ff8dd6a | 90 | printf("boardInit sx127x-ff-arduino "); |
Wayne Roberts |
0:9c052ff8dd6a | 91 | rfsw.input(); |
Wayne Roberts |
0:9c052ff8dd6a | 92 | if (rfsw.read()) { |
Wayne Roberts |
0:9c052ff8dd6a | 93 | shield_type = SHIELD_TYPE_LAS; |
Wayne Roberts |
0:9c052ff8dd6a | 94 | printf("LAS\r\n"); |
Wayne Roberts |
0:9c052ff8dd6a | 95 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 96 | shield_type = SHIELD_TYPE_MAS; |
Wayne Roberts |
0:9c052ff8dd6a | 97 | printf("MAS\r\n"); |
Wayne Roberts |
0:9c052ff8dd6a | 98 | } |
Wayne Roberts |
0:9c052ff8dd6a | 99 | |
Wayne Roberts |
0:9c052ff8dd6a | 100 | rfsw.output(); |
Wayne Roberts |
0:9c052ff8dd6a | 101 | } |
Wayne Roberts |
0:9c052ff8dd6a | 102 | |
Wayne Roberts |
0:9c052ff8dd6a | 103 | #endif /* ..SX127x_H */ |
Wayne Roberts |
0:9c052ff8dd6a | 104 | #endif /* ...sx127x shield */ |
Wayne Roberts |
0:9c052ff8dd6a | 105 |