Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LoRaWAN-SanJose_Bootcamp LoRaWAN-grove-cayenne LoRaWAN-classC-demo LoRaWAN-grove-cayenne ... more
radio/radio_ff_arduino.cpp
- Committer:
- Wayne Roberts
- Date:
- 2018-03-19
- Revision:
- 4:e4bfe9183f94
- Parent:
- 0:6b3ac9c5a042
File content as of revision 4:e4bfe9183f94:
/* Only for NUCLEO boards: prevent compiling for MOTE_L152RC and typeABZ discovery */ #if defined(TARGET_FF_ARDUINO) && defined(TARGET_FF_MORPHO) && !defined(TARGET_DISCO_L072CZ_LRWAN1) #include "board.h" #include "radio.h" #include "SPIu.h" SPIu spi(D11, D12, D13); // mosi, miso, sclk // dio0, dio1, nss, spi, rst SX127x Radio::radio( D2, D3, D10, spi, A0); // sx127[62] arduino shield SX127x_lora Radio::lora(radio); SX127x_fsk Radio::fsk(radio); InterruptIn Radio::dio0(D2); InterruptIn Radio::dio1(D3); typedef enum { SHIELD_TYPE_NONE = 0, SHIELD_TYPE_LAS, SHIELD_TYPE_MAS, } shield_type_e; shield_type_e shield_type; DigitalOut pc3(PC_3); DigitalInOut rfsw(A4); void Radio::rfsw_callback() { if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) rfsw = 1; else rfsw = 0; if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE) pc3 = 1; else pc3 = 0; } void Radio::set_tx_dbm(int8_t 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 (shield_type == SHIELD_TYPE_LAS) radio.RegPaConfig.bits.PaSelect = 1; else radio.RegPaConfig.bits.PaSelect = 0; if (radio.RegPaConfig.bits.PaSelect) { /* PABOOST used: +2dbm to +17, or +20 */ if (dbm > 17) { MAC_PRINTF("+20dBm PADAC bias\r\n"); if (dbm > 20) dbm = 20; dbm -= 3; pds_trim.bits.prog_txdac = 7; radio.write_reg(adr, pds_trim.octet); ocp(150); } else ocp(120); if (dbm > 1) radio.RegPaConfig.bits.OutputPower = dbm - 2; } else { /* RFO used: -1 to +14dbm */ ocp(80); if (dbm < 15) radio.RegPaConfig.bits.OutputPower = dbm + 1; } radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet); radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG); if (radio.RegPaConfig.bits.PaSelect) { MAC_PRINTF("PA_BOOST "); dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2; } else { MAC_PRINTF("RFO "); dbm = radio.RegPaConfig.bits.OutputPower - 1; } MAC_PRINTF("OutputPower:%ddBm{%02x}\r\n", dbm, radio.RegPaConfig.octet); } void Radio::boardInit() { rfsw.input(); if (rfsw.read()) { shield_type = SHIELD_TYPE_LAS; MAC_PRINTF("LAS\r\n"); } else { shield_type = SHIELD_TYPE_MAS; MAC_PRINTF("MAS\r\n"); } rfsw.output(); } #endif /* ...sx127x shield */