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.
Diff: board_shield.cpp
- Revision:
- 5:1652e04809fb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/board_shield.cpp Mon Feb 05 15:03:27 2018 -0800
@@ -0,0 +1,91 @@
+#if !defined(TARGET_MOTE_L152RC) && !defined(TARGET_DISCO_L072CZ_LRWAN1)
+#include "platform.h"
+
+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);
+
+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);
+}
+
+void board_init()
+{
+ radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
+
+ /* 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();
+
+ radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
+}
+#endif /* !defined(TARGET_MOTE_L152RC) && !defined(TARGET_DISCO_L072CZ_LRWAN1) */