diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 241ba04d..01713d0a 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -9,44 +9,23 @@ static const char TAG[] = "lora"; osjob_t sendjob; QueueHandle_t LoraSendQueue; -namespace Arduino_LMIC { - -class HalConfiguration_ThisBoard_t : public HalConfiguration_t { +class cMyHalConfig_t : public Arduino_LMIC::HalConfiguration_t { public: - enum DIGITAL_PINS : uint8_t { - PIN_SX1276_NSS = LORA_CS, - PIN_SX1276_NRESET = LORA_RST, - PIN_SX1276_DIO0 = LORA_IRQ, - PIN_SX1276_DIO1 = LORA_IO1, - PIN_SX1276_DIO2 = LORA_IO2, - PIN_SX1276_ANT_SWITCH_RX = HalPinmap_t::UNUSED_PIN, - PIN_SX1276_ANT_SWITCH_TX_BOOST = HalPinmap_t::UNUSED_PIN, - PIN_SX1276_ANT_SWITCH_TX_RFO = HalPinmap_t::UNUSED_PIN, - PIN_VDD_BOOST_ENABLE = HalPinmap_t::UNUSED_PIN, - PIN_SX1276_MOSI = LORA_MOSI, - PIN_SX1276_MISO = LORA_MISO, - PIN_SX1276_SCK = LORA_SCK, - }; - + cMyHalConfig_t(){}; virtual void begin(void) override { SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); } - - // virtual void end(void) override - - // virtual ostime_t setModuleActive(bool state) override }; -static HalConfiguration_ThisBoard_t myConfig; +cMyHalConfig_t myHalConfig{}; -static const HalPinmap_t myPinmap = { - .nss = HalConfiguration_ThisBoard_t::PIN_SX1276_NSS, - .rxtx = HalConfiguration_ThisBoard_t::PIN_SX1276_ANT_SWITCH_RX, - .rst = HalConfiguration_ThisBoard_t::PIN_SX1276_NRESET, - .dio = {HalConfiguration_ThisBoard_t::PIN_SX1276_DIO0, - HalConfiguration_ThisBoard_t::PIN_SX1276_DIO1, - HalConfiguration_ThisBoard_t::PIN_SX1276_DIO2}, +// LMIC enhanced Pin mapping +const lmic_pinmap lmic_pins = { + .nss = LORA_CS, + .rxtx = LMIC_UNUSED_PIN, + .rst = LORA_RST, + .dio = {LORA_IRQ, LORA_IO1, LORA_IO2}, // optional: set polarity of rxtx pin. .rxtx_rx_active = 0, // optional: set RSSI cal for listen-before-talk @@ -57,11 +36,7 @@ static const HalPinmap_t myPinmap = { .rssi_cal = 0, // optional: override LMIC_SPI_FREQ if non-zero .spi_freq = 0, - .pConfig = &myConfig}; - -const HalPinmap_t *GetPinmap_ThisBoard(void) { return &myPinmap; } - -} // namespace Arduino_LMIC + .pConfig = &myHalConfig}; // DevEUI generator using devices's MAC address void gen_lora_deveui(uint8_t *pdeveui) { @@ -400,14 +375,8 @@ esp_err_t lora_stack_init() { ESP_LOGI(TAG, "Starting LMIC..."); - const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); - if (pPinMap == nullptr) { - ESP_LOGE(TAG, "No device pinmap found. Aborting."); - return ESP_FAIL; - } - - os_init_ex(pPinMap); // initialize lmic run-time environment on core 1 - LMIC_reset(); // initialize lmic MAC + os_init(); // initialize lmic run-time environment on core 1 + LMIC_reset(); // initialize lmic MAC LMIC_setLinkCheckMode(0); // This tells LMIC to make the receive windows bigger, in case your clock is // faster or slower. This causes the transceiver to be earlier switched on,