1
TARGET_DISCO_L072CZ_LRWAN1/radio_typeABZ.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 | #include "radio.h" |
Wayne Roberts |
0:9c052ff8dd6a | 2 | |
Wayne Roberts |
0:9c052ff8dd6a | 3 | #define SSA_BOARD 1 |
Wayne Roberts |
0:9c052ff8dd6a | 4 | |
Wayne Roberts |
0:9c052ff8dd6a | 5 | SPI spi(PA_7, PA_6, PB_3); // mosi, miso, sclk |
Wayne Roberts |
0:9c052ff8dd6a | 6 | // dio0, dio1, nss, spi, rst |
Wayne Roberts |
0:9c052ff8dd6a | 7 | SX127x Radio::radio(PB_4, PB_1, PA_15, spi, PC_0); // sx1276 arduino shield |
Wayne Roberts |
0:9c052ff8dd6a | 8 | SX127x_lora Radio::lora(radio); |
Wayne Roberts |
0:9c052ff8dd6a | 9 | SX127x_fsk Radio::fsk(radio); |
Wayne Roberts |
0:9c052ff8dd6a | 10 | |
Wayne Roberts |
0:9c052ff8dd6a | 11 | InterruptIn Radio::dio0(PB_4); |
Wayne Roberts |
0:9c052ff8dd6a | 12 | InterruptIn Radio::dio1(PB_1); |
Wayne Roberts |
0:9c052ff8dd6a | 13 | |
Wayne Roberts |
0:9c052ff8dd6a | 14 | #define CRF1 PA_1 |
Wayne Roberts |
0:9c052ff8dd6a | 15 | #define CRF2 PC_2 |
Wayne Roberts |
0:9c052ff8dd6a | 16 | #define CRF3 PC_1 |
Wayne Roberts |
0:9c052ff8dd6a | 17 | DigitalOut Vctl1(CRF1); |
Wayne Roberts |
0:9c052ff8dd6a | 18 | DigitalOut Vctl2(CRF2); |
Wayne Roberts |
0:9c052ff8dd6a | 19 | DigitalOut Vctl3(CRF3); |
Wayne Roberts |
0:9c052ff8dd6a | 20 | |
Wayne Roberts |
0:9c052ff8dd6a | 21 | void Radio::rfsw_callback() |
Wayne Roberts |
0:9c052ff8dd6a | 22 | { |
Wayne Roberts |
0:9c052ff8dd6a | 23 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) { |
Wayne Roberts |
0:9c052ff8dd6a | 24 | Vctl1 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 25 | if (radio.RegPaConfig.bits.PaSelect) { |
Wayne Roberts |
0:9c052ff8dd6a | 26 | Vctl2 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 27 | Vctl3 = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 28 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 29 | Vctl2 = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 30 | Vctl3 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 31 | } |
Wayne Roberts |
0:9c052ff8dd6a | 32 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 33 | if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE) |
Wayne Roberts |
0:9c052ff8dd6a | 34 | Vctl1 = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 35 | else |
Wayne Roberts |
0:9c052ff8dd6a | 36 | Vctl1 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 37 | |
Wayne Roberts |
0:9c052ff8dd6a | 38 | Vctl2 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 39 | Vctl3 = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 40 | } |
Wayne Roberts |
0:9c052ff8dd6a | 41 | } |
Wayne Roberts |
0:9c052ff8dd6a | 42 | |
Wayne Roberts |
0:9c052ff8dd6a | 43 | void |
Wayne Roberts |
0:9c052ff8dd6a | 44 | Radio::set_tx_dbm(int8_t dbm) |
Wayne Roberts |
0:9c052ff8dd6a | 45 | { |
Wayne Roberts |
0:9c052ff8dd6a | 46 | RegPdsTrim1_t pds_trim; |
Wayne Roberts |
0:9c052ff8dd6a | 47 | pds_trim.octet = radio.read_reg(REG_PDSTRIM1_SX1276); |
Wayne Roberts |
0:9c052ff8dd6a | 48 | |
Wayne Roberts |
0:9c052ff8dd6a | 49 | if (dbm > 13) { |
Wayne Roberts |
0:9c052ff8dd6a | 50 | radio.RegPaConfig.bits.PaSelect = 1; |
Wayne Roberts |
0:9c052ff8dd6a | 51 | if (dbm > 17) { |
Wayne Roberts |
0:9c052ff8dd6a | 52 | pds_trim.bits.prog_txdac = 7; |
Wayne Roberts |
0:9c052ff8dd6a | 53 | dbm -= 3; |
Wayne Roberts |
0:9c052ff8dd6a | 54 | ocp(150); |
Wayne Roberts |
0:9c052ff8dd6a | 55 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 56 | pds_trim.bits.prog_txdac = 4; |
Wayne Roberts |
0:9c052ff8dd6a | 57 | ocp(120); |
Wayne Roberts |
0:9c052ff8dd6a | 58 | } |
Wayne Roberts |
0:9c052ff8dd6a | 59 | |
Wayne Roberts |
0:9c052ff8dd6a | 60 | radio.RegPaConfig.bits.OutputPower = dbm - 2; |
Wayne Roberts |
0:9c052ff8dd6a | 61 | } else { |
Wayne Roberts |
0:9c052ff8dd6a | 62 | pds_trim.bits.prog_txdac = 4; |
Wayne Roberts |
0:9c052ff8dd6a | 63 | radio.RegPaConfig.bits.PaSelect = 0; |
Wayne Roberts |
0:9c052ff8dd6a | 64 | radio.RegPaConfig.bits.OutputPower = dbm + 1; |
Wayne Roberts |
0:9c052ff8dd6a | 65 | ocp(80); |
Wayne Roberts |
0:9c052ff8dd6a | 66 | } |
Wayne Roberts |
0:9c052ff8dd6a | 67 | |
Wayne Roberts |
0:9c052ff8dd6a | 68 | radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet); |
Wayne Roberts |
0:9c052ff8dd6a | 69 | radio.write_reg(REG_PDSTRIM1_SX1276, pds_trim.octet); |
Wayne Roberts |
0:9c052ff8dd6a | 70 | } |
Wayne Roberts |
0:9c052ff8dd6a | 71 | |
Wayne Roberts |
0:9c052ff8dd6a | 72 | #ifdef SSA_BOARD |
Wayne Roberts |
0:9c052ff8dd6a | 73 | DigitalOut pa12(PA_12); // tcxo enable |
Wayne Roberts |
0:9c052ff8dd6a | 74 | DigitalOut pa11(PA_11); // sw9v enable -> sw3v3 |
Wayne Roberts |
0:9c052ff8dd6a | 75 | #endif |
Wayne Roberts |
0:9c052ff8dd6a | 76 | void Radio::boardInit() |
Wayne Roberts |
0:9c052ff8dd6a | 77 | { |
Wayne Roberts |
0:9c052ff8dd6a | 78 | #ifdef SSA_BOARD |
Wayne Roberts |
0:9c052ff8dd6a | 79 | pa12 = 1; // tcxo |
Wayne Roberts |
0:9c052ff8dd6a | 80 | pa11 = 1; // sw9v -> sw3v3 |
Wayne Roberts |
0:9c052ff8dd6a | 81 | #endif |
Wayne Roberts |
0:9c052ff8dd6a | 82 | } |
Wayne Roberts |
0:9c052ff8dd6a | 83 |