diff --git a/examples/raw-feather/raw-feather.ino b/examples/raw-feather/raw-feather.ino index e5064742..87d62633 100644 --- a/examples/raw-feather/raw-feather.ino +++ b/examples/raw-feather/raw-feather.ino @@ -56,56 +56,6 @@ Author: #define TX_INTERVAL 2000 // milliseconds #define RX_RSSI_INTERVAL 100 // milliseconds -// Pin mapping for Adafruit Feather M0 LoRa, etc. -// -// Adafruit BSPs are not consistent -- m0 express defs ARDUINO_SAMD_FEATHER_M0, -// m0 defs ADAFRUIT_FEATHER_M0 -// -#if defined(ARDUINO_SAMD_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0) -// /!\ By default Adafruit Feather M0's pin 6 and DIO1 are not connected. -// Please ensure they are connected. -const lmic_pinmap lmic_pins = { - .nss = 8, - .rxtx = LMIC_UNUSED_PIN, - .rst = 4, - .dio = {3, 6, LMIC_UNUSED_PIN}, - .rxtx_rx_active = 0, - .rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB - .spi_freq = 8000000, -}; -#elif defined(ARDUINO_AVR_FEATHER32U4) -// Pin mapping for Adafruit Feather 32u4 LoRa, etc. -// Just like Feather M0 LoRa, but uses SPI at 1MHz; and that's only -// because MCCI doesn't have a test board; probably higher frequencies -// will work. -// /!\ By default Feather 32u4's pin 6 and DIO1 are not connected. Please -// ensure they are connected. -const lmic_pinmap lmic_pins = { - .nss = 8, - .rxtx = LMIC_UNUSED_PIN, - .rst = 4, - .dio = {7, 6, LMIC_UNUSED_PIN}, - .rxtx_rx_active = 0, - .rssi_cal = 8, // LBT cal for the Adafruit Feather 32U4 LoRa, in dB - .spi_freq = 1000000, -}; -#elif defined(ARDUINO_CATENA_4551) -const lmic_pinmap lmic_pins = { - .nss = 7, - .rxtx = 29, - .rst = 8, - .dio = { 25, // DIO0 (IRQ) is D25 - 26, // DIO1 is D26 - 27, // DIO2 is D27 - }, - .rxtx_rx_active = 1, - .rssi_cal = 10, - .spi_freq = 8000000 // 8MHz -}; -#else -# error "Unknown target" -#endif - // These callbacks are only used in over-the-air activation, so they are // left empty here (we cannot leave them out completely unless // DISABLE_JOIN is set in arduino-lmoc/project_config/lmic_project_config.h, @@ -272,7 +222,23 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); // initialize runtime env - os_init(); + // don't die mysteriously; die noisily. + const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); + + if (pPinMap == nullptr) { + pinMode(LED_BUILTIN, OUTPUT); + for (;;) { + // flash lights, sleep. + for (int i = 0; i < 5; ++i) { + digitalWrite(LED_BUILTIN, 1); + delay(100); + digitalWrite(LED_BUILTIN, 0); + delay(900); + } + Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp")); + } + } + os_init_ex(pPinMap); // Set up these settings once, and use them for both TX and RX #ifdef ARDUINO_ARCH_STM32 diff --git a/examples/raw/raw.ino b/examples/raw/raw.ino index 6fe81890..98178267 100644 --- a/examples/raw/raw.ino +++ b/examples/raw/raw.ino @@ -36,15 +36,6 @@ // https://docs.google.com/spreadsheets/d/1voGAtQAjC1qBmaVuP1ApNKs1ekgUjavHuVQIXyYSvNc #define TX_INTERVAL 2000 -// Pin mapping -const lmic_pinmap lmic_pins = { - .nss = 6, - .rxtx = LMIC_UNUSED_PIN, - .rst = 5, - .dio = {2, 3, 4}, -}; - - // These callbacks are only used in over-the-air activation, so they are // left empty here (we cannot leave them out completely unless // DISABLE_JOIN is set in arduino-lmoc/project_config/lmic_project_config.h, @@ -137,7 +128,23 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); // initialize runtime env - os_init(); + // don't die mysteriously; die noisily. + const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); + + if (pPinMap == nullptr) { + pinMode(LED_BUILTIN, OUTPUT); + for (;;) { + // flash lights, sleep. + for (int i = 0; i < 5; ++i) { + digitalWrite(LED_BUILTIN, 1); + delay(100); + digitalWrite(LED_BUILTIN, 0); + delay(900); + } + Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp")); + } + } + os_init_ex(pPinMap); #if defined(CFG_eu868) // Use a frequency in the g3 which allows 10% duty cycling. diff --git a/examples/ttn-abp-feather-us915-dht22/extra/ci/lmic-filter.sh b/examples/ttn-abp-feather-dht22/extra/ci/lmic-filter.sh similarity index 100% rename from examples/ttn-abp-feather-us915-dht22/extra/ci/lmic-filter.sh rename to examples/ttn-abp-feather-dht22/extra/ci/lmic-filter.sh diff --git a/examples/ttn-abp-feather-us915-dht22/ttn-abp-feather-us915-dht22.ino b/examples/ttn-abp-feather-dht22/ttn-abp-feather-dht22.ino similarity index 100% rename from examples/ttn-abp-feather-us915-dht22/ttn-abp-feather-us915-dht22.ino rename to examples/ttn-abp-feather-dht22/ttn-abp-feather-dht22.ino diff --git a/examples/ttn-abp/ttn-abp.ino b/examples/ttn-abp/ttn-abp.ino index 2f2ee667..d7a80294 100644 --- a/examples/ttn-abp/ttn-abp.ino +++ b/examples/ttn-abp/ttn-abp.ino @@ -37,6 +37,7 @@ #include #include #include +#include "ttn-secrets.h" // // For normal use, we require that you edit the sketch to replace FILLMEIN @@ -208,8 +209,25 @@ void setup() { delay(1000); #endif - // LMIC init - os_init(); + // initialize runtime env + // don't die mysteriously; die noisily. + const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); + + if (pPinMap == nullptr) { + pinMode(LED_BUILTIN, OUTPUT); + for (;;) { + // flash lights, sleep. + for (int i = 0; i < 5; ++i) { + digitalWrite(LED_BUILTIN, 1); + delay(100); + digitalWrite(LED_BUILTIN, 0); + delay(900); + } + Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp")); + } + } + + os_init_ex(pPinMap); // Reset the MAC state. Session and pending data transfers will be discarded. LMIC_reset(); diff --git a/examples/ttn-abp/ttn-secrets.h b/examples/ttn-abp/ttn-secrets.h new file mode 100644 index 00000000..e69de29b diff --git a/examples/ttn-otaa-feather-us915-dht22/extra/ci/lmic-filter.sh b/examples/ttn-otaa-feather-dht22/extra/ci/lmic-filter.sh similarity index 100% rename from examples/ttn-otaa-feather-us915-dht22/extra/ci/lmic-filter.sh rename to examples/ttn-otaa-feather-dht22/extra/ci/lmic-filter.sh diff --git a/examples/ttn-otaa-feather-us915-dht22/ttn-otaa-feather-us915-dht22.ino b/examples/ttn-otaa-feather-dht22/ttn-otaa-feather-dht22.ino similarity index 76% rename from examples/ttn-otaa-feather-us915-dht22/ttn-otaa-feather-us915-dht22.ino rename to examples/ttn-otaa-feather-dht22/ttn-otaa-feather-dht22.ino index 9372b214..56d221e7 100644 --- a/examples/ttn-otaa-feather-us915-dht22/ttn-otaa-feather-us915-dht22.ino +++ b/examples/ttn-otaa-feather-dht22/ttn-otaa-feather-dht22.ino @@ -18,7 +18,10 @@ *******************************************************************************/ #include #include +#include + #include +#include "ttn-secrets.h" // include the DHT22 Sensor Library #include "DHT.h" @@ -27,57 +30,13 @@ #define DHTPIN 10 #define DHTTYPE DHT22 -// -// For normal use, we require that you edit the sketch to replace FILLMEIN -// with values assigned by the TTN console. However, for regression tests, -// we want to be able to compile these scripts. The regression tests define -// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- -// working but innocuous value. -// -#ifdef COMPILE_REGRESSION_TEST -#define FILLMEIN 0 -#else -#warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!" -#define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN) -#endif - -// This EUI must be in little-endian format, so least-significant-byte -// first. When copying an EUI from ttnctl output, this means to reverse -// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, -// 0x70. -static const u1_t PROGMEM APPEUI[8] = { FILLMEIN }; -void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} - -// This should also be in little endian format, see above. -static const u1_t PROGMEM DEVEUI[8] = { FILLMEIN }; -void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} - -// This key should be in big endian format (or, since it is not really a -// number but a block of memory, endianness does not really apply). In -// practice, a key taken from the TTN console can be copied as-is. -static const u1_t PROGMEM APPKEY[16] = { FILLMEIN }; -void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} - // payload to send to TTN gateway static uint8_t payload[5]; static osjob_t sendjob; // Schedule TX every this many seconds (might become longer due to duty // cycle limitations). -const unsigned TX_INTERVAL = 30; - -// Pin mapping for Adafruit Feather M0 LoRa -// /!\ By default Adafruit Feather M0's pin 6 and DIO1 are not connected. -// Please ensure they are connected. -const lmic_pinmap lmic_pins = { - .nss = 8, - .rxtx = LMIC_UNUSED_PIN, - .rst = 4, - .dio = {3, 6, LMIC_UNUSED_PIN}, - .rxtx_rx_active = 0, - .rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB - .spi_freq = 8000000, -}; +const unsigned TX_INTERVAL = (60 * 15); // init. DHT DHT dht(DHTPIN, DHTTYPE); @@ -258,26 +217,34 @@ void do_send(osjob_t* j){ } void setup() { - delay(5000); - while (! Serial); - Serial.begin(9600); + while (!Serial) + delay(100); + + Serial.begin(115200); Serial.println(F("Starting")); dht.begin(); - // LMIC init - os_init(); + // initialize runtime env + // don't die mysteriously; die noisily. + const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); + + if (pPinMap == nullptr) { + pinMode(LED_BUILTIN, OUTPUT); + for (;;) { + // flash lights, sleep. + for (int i = 0; i < 5; ++i) { + digitalWrite(LED_BUILTIN, 1); + delay(100); + digitalWrite(LED_BUILTIN, 0); + delay(900); + } + Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp")); + } + } + os_init_ex(pPinMap); // Reset the MAC state. Session and pending data transfers will be discarded. LMIC_reset(); - // Disable link-check mode and ADR, because ADR tends to complicate testing. - LMIC_setLinkCheckMode(0); - // Set the data rate to Spreading Factor 7. This is the fastest supported rate for 125 kHz channels, and it - // minimizes air time and battery power. Set the transmission power to 14 dBi (25 mW). - LMIC_setDrTxpow(DR_SF7,14); - // in the US, with TTN, it saves join time if we start on subband 1 (channels 8-15). This will - // get overridden after the join by parameters from the network. If working with other - // networks or in other regions, this will need to be changed. - LMIC_selectSubBand(1); // Start job (sending automatically starts OTAA too) do_send(&sendjob); diff --git a/examples/ttn-otaa-feather-dht22/ttn-secrets.h b/examples/ttn-otaa-feather-dht22/ttn-secrets.h new file mode 100644 index 00000000..d685d749 --- /dev/null +++ b/examples/ttn-otaa-feather-dht22/ttn-secrets.h @@ -0,0 +1,57 @@ +/* + LoRa secrets file + + Copyright (c) 2021,2022 P. Oldberg + + Permission is hereby granted, free of charge, to anyone + obtaining a copy of this document and accompanying files, + to do whatever they want with them without any restriction, + including, but not limited to, copying, modification and redistribution. + NO WARRANTY OF ANY KIND IS PROVIDED. +*/ + +/* Here you fill in the OTAA credentials of your TTN device */ +#define APPEUI_DATA // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +#define DEVEUI_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xD5, 0xB3, 0x70 +#define APPKEY_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX + +#define REGRESSION_TEST_DATA 0 + +// +// For normal use, we require that you edit the sketch to replace FILLMEIN +// with values assigned by the TTN console. However, for regression tests, +// we want to be able to compile these scripts. The regression tests define +// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- +// working but innocuous value. +// +#if defined(COMPILE_REGRESSION_TEST) +# if defined(APPEUI_DATA) +# undef APPEUI_DATA +# define APPEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(DEVEUI_DATA) +# undef DEVEUI_DATA +# define DEVEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(APPKEY_DATA) +# undef APPKEY_DATA +# define APPKEY_DATA REGRESSION_TEST_DATA +# endif +#endif + +// EUI's must be in little-endian format, so least-significant-byte +// first. When copying an EUI from ttn console, this means to reverse +// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, +// 0x70. +static const u1_t PROGMEM APPEUI[8] = { APPEUI_DATA }; +void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} + +// This should also be in little endian format, see above. +static const u1_t PROGMEM DEVEUI[8] = { DEVEUI_DATA }; +void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} + +// This key should be in big endian format (or, since it is not really a +// number but a block of memory, endianness does not really apply). In +// practice, a key taken from ttnctl can be copied as-is. +static const u1_t PROGMEM APPKEY[16] = { APPKEY_DATA }; +void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} diff --git a/examples/ttn-otaa-feather-us915/extra/ci/lmic-filter.sh b/examples/ttn-otaa-feather/extra/ci/lmic-filter.sh similarity index 100% rename from examples/ttn-otaa-feather-us915/extra/ci/lmic-filter.sh rename to examples/ttn-otaa-feather/extra/ci/lmic-filter.sh diff --git a/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino b/examples/ttn-otaa-feather/ttn-otaa-feather.ino similarity index 68% rename from examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino rename to examples/ttn-otaa-feather/ttn-otaa-feather.ino index 4153c556..482635a2 100644 --- a/examples/ttn-otaa-feather-us915/ttn-otaa-feather-us915.ino +++ b/examples/ttn-otaa-feather/ttn-otaa-feather.ino @@ -34,38 +34,10 @@ #include #include -#include - -// -// For normal use, we require that you edit the sketch to replace FILLMEIN -// with values assigned by the TTN console. However, for regression tests, -// we want to be able to compile these scripts. The regression tests define -// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- -// working but innocuous value. -// -#ifdef COMPILE_REGRESSION_TEST -# define FILLMEIN 0 -#else -# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!" -# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN) -#endif - -// This EUI must be in little-endian format, so least-significant-byte -// first. When copying an EUI from ttnctl output, this means to reverse -// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, -// 0x70. -static const u1_t PROGMEM APPEUI[8]= { FILLMEIN }; -void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} - -// This should also be in little endian format, see above. -static const u1_t PROGMEM DEVEUI[8]= { FILLMEIN }; -void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} +#include -// This key should be in big endian format (or, since it is not really a -// number but a block of memory, endianness does not really apply). In -// practice, a key taken from the TTN console can be copied as-is. -static const u1_t PROGMEM APPKEY[16] = { FILLMEIN }; -void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} +#include +#include "ttn-secrets.h" static uint8_t mydata[] = "Hello, world!"; static osjob_t sendjob; @@ -74,58 +46,6 @@ static osjob_t sendjob; // cycle limitations). const unsigned TX_INTERVAL = 60; -// Pin mapping -// -// Adafruit BSPs are not consistent -- m0 express defs ARDUINO_SAMD_FEATHER_M0, -// m0 defs ADAFRUIT_FEATHER_M0 -// -#if defined(ARDUINO_SAMD_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0) -// Pin mapping for Adafruit Feather M0 LoRa, etc. -// /!\ By default Adafruit Feather M0's pin 6 and DIO1 are not connected. -// Please ensure they are connected. -const lmic_pinmap lmic_pins = { - .nss = 8, - .rxtx = LMIC_UNUSED_PIN, - .rst = 4, - .dio = {3, 6, LMIC_UNUSED_PIN}, - .rxtx_rx_active = 0, - .rssi_cal = 8, // LBT cal for the Adafruit Feather M0 LoRa, in dB - .spi_freq = 8000000, -}; -#elif defined(ARDUINO_AVR_FEATHER32U4) -// Pin mapping for Adafruit Feather 32u4 LoRa, etc. -// Just like Feather M0 LoRa, but uses SPI at 1MHz; and that's only -// because MCCI doesn't have a test board; probably higher frequencies -// will work. -// /!\ By default Feather 32u4's pin 6 and DIO1 are not connected. Please -// ensure they are connected. -const lmic_pinmap lmic_pins = { - .nss = 8, - .rxtx = LMIC_UNUSED_PIN, - .rst = 4, - .dio = {7, 6, LMIC_UNUSED_PIN}, - .rxtx_rx_active = 0, - .rssi_cal = 8, // LBT cal for the Adafruit Feather 32U4 LoRa, in dB - .spi_freq = 1000000, -}; -#elif defined(ARDUINO_CATENA_4551) -// Pin mapping for Murata module / Catena 4551 -const lmic_pinmap lmic_pins = { - .nss = 7, - .rxtx = 29, - .rst = 8, - .dio = { 25, // DIO0 (IRQ) is D25 - 26, // DIO1 is D26 - 27, // DIO2 is D27 - }, - .rxtx_rx_active = 1, - .rssi_cal = 10, - .spi_freq = 8000000 // 8MHz -}; -#else -# error "Unknown target" -#endif - void printHex2(unsigned v) { v &= 0xff; if (v < 16) @@ -268,10 +188,10 @@ void do_send(osjob_t* j){ } void setup() { - delay(5000); while (! Serial) - ; - Serial.begin(9600); + delay(100); + + Serial.begin(115200); Serial.println(F("Starting")); #ifdef VCC_ENABLE @@ -281,14 +201,29 @@ void setup() { delay(1000); #endif - // LMIC init - os_init(); + // initialize runtime env + // don't die mysteriously; die noisily. + const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); + + if (pPinMap == nullptr) { + pinMode(LED_BUILTIN, OUTPUT); + for (;;) { + // flash lights, sleep. + for (int i = 0; i < 5; ++i) { + digitalWrite(LED_BUILTIN, 1); + delay(100); + digitalWrite(LED_BUILTIN, 0); + delay(900); + } + Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp")); + } + } + os_init_ex(pPinMap); // Reset the MAC state. Session and pending data transfers will be discarded. LMIC_reset(); LMIC_setLinkCheckMode(0); LMIC_setDrTxpow(DR_SF7,14); - LMIC_selectSubBand(1); // Start job (sending automatically starts OTAA too) do_send(&sendjob); diff --git a/examples/ttn-otaa-feather/ttn-secrets.h b/examples/ttn-otaa-feather/ttn-secrets.h new file mode 100644 index 00000000..d685d749 --- /dev/null +++ b/examples/ttn-otaa-feather/ttn-secrets.h @@ -0,0 +1,57 @@ +/* + LoRa secrets file + + Copyright (c) 2021,2022 P. Oldberg + + Permission is hereby granted, free of charge, to anyone + obtaining a copy of this document and accompanying files, + to do whatever they want with them without any restriction, + including, but not limited to, copying, modification and redistribution. + NO WARRANTY OF ANY KIND IS PROVIDED. +*/ + +/* Here you fill in the OTAA credentials of your TTN device */ +#define APPEUI_DATA // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +#define DEVEUI_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xD5, 0xB3, 0x70 +#define APPKEY_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX + +#define REGRESSION_TEST_DATA 0 + +// +// For normal use, we require that you edit the sketch to replace FILLMEIN +// with values assigned by the TTN console. However, for regression tests, +// we want to be able to compile these scripts. The regression tests define +// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- +// working but innocuous value. +// +#if defined(COMPILE_REGRESSION_TEST) +# if defined(APPEUI_DATA) +# undef APPEUI_DATA +# define APPEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(DEVEUI_DATA) +# undef DEVEUI_DATA +# define DEVEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(APPKEY_DATA) +# undef APPKEY_DATA +# define APPKEY_DATA REGRESSION_TEST_DATA +# endif +#endif + +// EUI's must be in little-endian format, so least-significant-byte +// first. When copying an EUI from ttn console, this means to reverse +// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, +// 0x70. +static const u1_t PROGMEM APPEUI[8] = { APPEUI_DATA }; +void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} + +// This should also be in little endian format, see above. +static const u1_t PROGMEM DEVEUI[8] = { DEVEUI_DATA }; +void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} + +// This key should be in big endian format (or, since it is not really a +// number but a block of memory, endianness does not really apply). In +// practice, a key taken from ttnctl can be copied as-is. +static const u1_t PROGMEM APPKEY[16] = { APPKEY_DATA }; +void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} diff --git a/examples/ttn-otaa-halconfig-us915/ttn-otaa-halconfig-us915.ino b/examples/ttn-otaa-halconfig/ttn-otaa-halconfig.ino similarity index 84% rename from examples/ttn-otaa-halconfig-us915/ttn-otaa-halconfig-us915.ino rename to examples/ttn-otaa-halconfig/ttn-otaa-halconfig.ino index c10dad2f..599ef31f 100644 --- a/examples/ttn-otaa-halconfig-us915/ttn-otaa-halconfig-us915.ino +++ b/examples/ttn-otaa-halconfig/ttn-otaa-halconfig.ino @@ -36,39 +36,11 @@ #include #include -#include #include -// -// For normal use, we require that you edit the sketch to replace FILLMEIN -// with values assigned by the TTN console. However, for regression tests, -// we want to be able to compile these scripts. The regression tests define -// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- -// working but innocuous value. -// -#ifdef COMPILE_REGRESSION_TEST -# define FILLMEIN 0 -#else -# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!" -# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN) -#endif - -// This EUI must be in little-endian format, so least-significant-byte -// first. When copying an EUI from ttnctl output, this means to reverse -// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, -// 0x70. -static const u1_t PROGMEM APPEUI[8]= { FILLMEIN }; -void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} - -// This should also be in little endian format, see above. -static const u1_t PROGMEM DEVEUI[8]= { FILLMEIN }; -void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} +#include -// This key should be in big endian format (or, since it is not really a -// number but a block of memory, endianness does not really apply). In -// practice, a key taken from the TTN console can be copied as-is. -static const u1_t PROGMEM APPKEY[16] = { FILLMEIN }; -void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} +#include "ttn-secrets.h" static uint8_t mydata[] = "Hello, world!"; static osjob_t sendjob; diff --git a/examples/ttn-otaa-halconfig/ttn-secrets.h b/examples/ttn-otaa-halconfig/ttn-secrets.h new file mode 100644 index 00000000..d685d749 --- /dev/null +++ b/examples/ttn-otaa-halconfig/ttn-secrets.h @@ -0,0 +1,57 @@ +/* + LoRa secrets file + + Copyright (c) 2021,2022 P. Oldberg + + Permission is hereby granted, free of charge, to anyone + obtaining a copy of this document and accompanying files, + to do whatever they want with them without any restriction, + including, but not limited to, copying, modification and redistribution. + NO WARRANTY OF ANY KIND IS PROVIDED. +*/ + +/* Here you fill in the OTAA credentials of your TTN device */ +#define APPEUI_DATA // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +#define DEVEUI_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xD5, 0xB3, 0x70 +#define APPKEY_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX + +#define REGRESSION_TEST_DATA 0 + +// +// For normal use, we require that you edit the sketch to replace FILLMEIN +// with values assigned by the TTN console. However, for regression tests, +// we want to be able to compile these scripts. The regression tests define +// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- +// working but innocuous value. +// +#if defined(COMPILE_REGRESSION_TEST) +# if defined(APPEUI_DATA) +# undef APPEUI_DATA +# define APPEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(DEVEUI_DATA) +# undef DEVEUI_DATA +# define DEVEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(APPKEY_DATA) +# undef APPKEY_DATA +# define APPKEY_DATA REGRESSION_TEST_DATA +# endif +#endif + +// EUI's must be in little-endian format, so least-significant-byte +// first. When copying an EUI from ttn console, this means to reverse +// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, +// 0x70. +static const u1_t PROGMEM APPEUI[8] = { APPEUI_DATA }; +void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} + +// This should also be in little endian format, see above. +static const u1_t PROGMEM DEVEUI[8] = { DEVEUI_DATA }; +void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} + +// This key should be in big endian format (or, since it is not really a +// number but a block of memory, endianness does not really apply). In +// practice, a key taken from ttnctl can be copied as-is. +static const u1_t PROGMEM APPKEY[16] = { APPKEY_DATA }; +void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} diff --git a/examples/ttn-otaa-network-time/ttn-otaa-network-time.ino b/examples/ttn-otaa-network-time/ttn-otaa-network-time.ino index cbe702b3..834bb6e6 100644 --- a/examples/ttn-otaa-network-time/ttn-otaa-network-time.ino +++ b/examples/ttn-otaa-network-time/ttn-otaa-network-time.ino @@ -27,7 +27,7 @@ * DevEUI and AppKey. * * Do not forget to define the radio type correctly in config.h. - * + * * You will need to also install the library github.com/PaulStoffregen/Time; * you need a version that has TimeLib.h. * @@ -38,39 +38,10 @@ #include #include -#include - -// -// For normal use, we require that you edit the sketch to replace FILLMEIN -// with values assigned by the TTN console. However, for regression tests, -// we want to be able to compile these scripts. The regression tests define -// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- -// working but innocuous value. -// -#ifdef COMPILE_REGRESSION_TEST -# define FILLMEIN 0 -#else -# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!" -# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN) -#endif - - -// This EUI must be in little-endian format, so least-significant-byte -// first. When copying an EUI from ttnctl output, this means to reverse -// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, -// 0x70. -static const u1_t PROGMEM APPEUI[8]={ FILLMEIN }; -void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} - -// This should also be in little endian format, see above. -static const u1_t PROGMEM DEVEUI[8]={ FILLMEIN }; -void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} +#include -// This key should be in big endian format (or, since it is not really a -// number but a block of memory, endianness does not really apply). In -// practice, a key taken from ttnctl can be copied as-is. -static const u1_t PROGMEM APPKEY[16] = { FILLMEIN }; -void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} +#include +#include "ttn-secrets.h" static uint8_t mydata[] = "Hello, world!"; static osjob_t sendjob; @@ -79,14 +50,6 @@ static osjob_t sendjob; // cycle limitations). const unsigned TX_INTERVAL = 60; -// Pin mapping -const lmic_pinmap lmic_pins = { - .nss = 6, - .rxtx = LMIC_UNUSED_PIN, - .rst = 5, - .dio = {2, 3, 4}, -}; - void printHex2(unsigned v) { v &= 0xff; if (v < 16) @@ -297,15 +260,32 @@ void setup() { Serial.begin(9600); Serial.println(F("Starting")); - #ifdef VCC_ENABLE +#ifdef VCC_ENABLE // For Pinoccio Scout boards pinMode(VCC_ENABLE, OUTPUT); digitalWrite(VCC_ENABLE, HIGH); delay(1000); - #endif +#endif + + // initialize runtime env + // don't die mysteriously; die noisily. + const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); + + if (pPinMap == nullptr) { + pinMode(LED_BUILTIN, OUTPUT); + for (;;) { + // flash lights, sleep. + for (int i = 0; i < 5; ++i) { + digitalWrite(LED_BUILTIN, 1); + delay(100); + digitalWrite(LED_BUILTIN, 0); + delay(900); + } + Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp")); + } + } + os_init_ex(pPinMap); - // LMIC init - os_init(); // Reset the MAC state. Session and pending data transfers will be discarded. LMIC_reset(); diff --git a/examples/ttn-otaa-network-time/ttn-secrets.h b/examples/ttn-otaa-network-time/ttn-secrets.h new file mode 100644 index 00000000..d685d749 --- /dev/null +++ b/examples/ttn-otaa-network-time/ttn-secrets.h @@ -0,0 +1,57 @@ +/* + LoRa secrets file + + Copyright (c) 2021,2022 P. Oldberg + + Permission is hereby granted, free of charge, to anyone + obtaining a copy of this document and accompanying files, + to do whatever they want with them without any restriction, + including, but not limited to, copying, modification and redistribution. + NO WARRANTY OF ANY KIND IS PROVIDED. +*/ + +/* Here you fill in the OTAA credentials of your TTN device */ +#define APPEUI_DATA // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +#define DEVEUI_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xD5, 0xB3, 0x70 +#define APPKEY_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX + +#define REGRESSION_TEST_DATA 0 + +// +// For normal use, we require that you edit the sketch to replace FILLMEIN +// with values assigned by the TTN console. However, for regression tests, +// we want to be able to compile these scripts. The regression tests define +// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- +// working but innocuous value. +// +#if defined(COMPILE_REGRESSION_TEST) +# if defined(APPEUI_DATA) +# undef APPEUI_DATA +# define APPEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(DEVEUI_DATA) +# undef DEVEUI_DATA +# define DEVEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(APPKEY_DATA) +# undef APPKEY_DATA +# define APPKEY_DATA REGRESSION_TEST_DATA +# endif +#endif + +// EUI's must be in little-endian format, so least-significant-byte +// first. When copying an EUI from ttn console, this means to reverse +// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, +// 0x70. +static const u1_t PROGMEM APPEUI[8] = { APPEUI_DATA }; +void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} + +// This should also be in little endian format, see above. +static const u1_t PROGMEM DEVEUI[8] = { DEVEUI_DATA }; +void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} + +// This key should be in big endian format (or, since it is not really a +// number but a block of memory, endianness does not really apply). In +// practice, a key taken from ttnctl can be copied as-is. +static const u1_t PROGMEM APPKEY[16] = { APPKEY_DATA }; +void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} diff --git a/examples/ttn-otaa/ttn-otaa.ino b/examples/ttn-otaa/ttn-otaa.ino index fbbf0879..b2058afe 100644 --- a/examples/ttn-otaa/ttn-otaa.ino +++ b/examples/ttn-otaa/ttn-otaa.ino @@ -33,38 +33,10 @@ #include #include -#include - -// -// For normal use, we require that you edit the sketch to replace FILLMEIN -// with values assigned by the TTN console. However, for regression tests, -// we want to be able to compile these scripts. The regression tests define -// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- -// working but innocuous value. -// -#ifdef COMPILE_REGRESSION_TEST -# define FILLMEIN 0 -#else -# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!" -# define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN) -#endif - -// This EUI must be in little-endian format, so least-significant-byte -// first. When copying an EUI from ttnctl output, this means to reverse -// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, -// 0x70. -static const u1_t PROGMEM APPEUI[8]={ FILLMEIN }; -void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} - -// This should also be in little endian format, see above. -static const u1_t PROGMEM DEVEUI[8]={ FILLMEIN }; -void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} +#include -// This key should be in big endian format (or, since it is not really a -// number but a block of memory, endianness does not really apply). In -// practice, a key taken from ttnctl can be copied as-is. -static const u1_t PROGMEM APPKEY[16] = { FILLMEIN }; -void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} +#include +#include "ttn-secrets.h" static uint8_t mydata[] = "Hello, world!"; static osjob_t sendjob; @@ -73,14 +45,6 @@ static osjob_t sendjob; // cycle limitations). const unsigned TX_INTERVAL = 60; -// Pin mapping -const lmic_pinmap lmic_pins = { - .nss = 6, - .rxtx = LMIC_UNUSED_PIN, - .rst = 5, - .dio = {2, 3, 4}, -}; - void printHex2(unsigned v) { v &= 0xff; if (v < 16) @@ -222,18 +186,37 @@ void do_send(osjob_t* j){ } void setup() { - Serial.begin(9600); + while (!Serial) + delay(100); + + Serial.begin(115200); Serial.println(F("Starting")); - #ifdef VCC_ENABLE +#ifdef VCC_ENABLE // For Pinoccio Scout boards pinMode(VCC_ENABLE, OUTPUT); digitalWrite(VCC_ENABLE, HIGH); delay(1000); - #endif +#endif - // LMIC init - os_init(); + // initialize runtime env + // don't die mysteriously; die noisily. + const lmic_pinmap *pPinMap = Arduino_LMIC::GetPinmap_ThisBoard(); + + if (pPinMap == nullptr) { + pinMode(LED_BUILTIN, OUTPUT); + for (;;) { + // flash lights, sleep. + for (int i = 0; i < 5; ++i) { + digitalWrite(LED_BUILTIN, 1); + delay(100); + digitalWrite(LED_BUILTIN, 0); + delay(900); + } + Serial.println(F("board not known to library; add pinmap or update getconfig_thisboard.cpp")); + } + } + os_init_ex(pPinMap); // Reset the MAC state. Session and pending data transfers will be discarded. LMIC_reset(); diff --git a/examples/ttn-otaa/ttn-secrets.h b/examples/ttn-otaa/ttn-secrets.h new file mode 100644 index 00000000..d685d749 --- /dev/null +++ b/examples/ttn-otaa/ttn-secrets.h @@ -0,0 +1,57 @@ +/* + LoRa secrets file + + Copyright (c) 2021,2022 P. Oldberg + + Permission is hereby granted, free of charge, to anyone + obtaining a copy of this document and accompanying files, + to do whatever they want with them without any restriction, + including, but not limited to, copying, modification and redistribution. + NO WARRANTY OF ANY KIND IS PROVIDED. +*/ + +/* Here you fill in the OTAA credentials of your TTN device */ +#define APPEUI_DATA // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +#define DEVEUI_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xD5, 0xB3, 0x70 +#define APPKEY_DATA // 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX + +#define REGRESSION_TEST_DATA 0 + +// +// For normal use, we require that you edit the sketch to replace FILLMEIN +// with values assigned by the TTN console. However, for regression tests, +// we want to be able to compile these scripts. The regression tests define +// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non- +// working but innocuous value. +// +#if defined(COMPILE_REGRESSION_TEST) +# if defined(APPEUI_DATA) +# undef APPEUI_DATA +# define APPEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(DEVEUI_DATA) +# undef DEVEUI_DATA +# define DEVEUI_DATA REGRESSION_TEST_DATA +# endif +# if defined(APPKEY_DATA) +# undef APPKEY_DATA +# define APPKEY_DATA REGRESSION_TEST_DATA +# endif +#endif + +// EUI's must be in little-endian format, so least-significant-byte +// first. When copying an EUI from ttn console, this means to reverse +// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, +// 0x70. +static const u1_t PROGMEM APPEUI[8] = { APPEUI_DATA }; +void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} + +// This should also be in little endian format, see above. +static const u1_t PROGMEM DEVEUI[8] = { DEVEUI_DATA }; +void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} + +// This key should be in big endian format (or, since it is not really a +// number but a block of memory, endianness does not really apply). In +// practice, a key taken from ttnctl can be copied as-is. +static const u1_t PROGMEM APPKEY[16] = { APPKEY_DATA }; +void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} diff --git a/project_config/lmic_project_config.h b/project_config/lmic_project_config.h index 620afbf5..3e4d9ed7 100644 --- a/project_config/lmic_project_config.h +++ b/project_config/lmic_project_config.h @@ -1,9 +1,9 @@ // project-specific definitions -//#define CFG_eu868 1 -#define CFG_us915 1 +#define CFG_eu868 1 +//#define CFG_us915 1 //#define CFG_au915 1 //#define CFG_as923 1 -// #define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP /* for as923-JP; also define CFG_as923 */ +//#define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP /* for as923-JP; also define CFG_as923 */ //#define CFG_kr920 1 //#define CFG_in866 1 #define CFG_sx1276_radio 1 diff --git a/src/arduino_lmic_hal_boards.h b/src/arduino_lmic_hal_boards.h index 0cb98384..87724c06 100644 --- a/src/arduino_lmic_hal_boards.h +++ b/src/arduino_lmic_hal_boards.h @@ -21,6 +21,8 @@ Copyright & License: #include "arduino_lmic_hal_configuration.h" namespace Arduino_LMIC { +const HalPinmap_t *GetPinmap_Challenger_RP2040_LoRa(); +const HalPinmap_t *GetPinmap_Connectivity_840(); const HalPinmap_t *GetPinmap_FeatherM0LoRa(); const HalPinmap_t *GetPinmap_Feather32U4LoRa(); diff --git a/src/arduino_lmic_hal_configuration.h b/src/arduino_lmic_hal_configuration.h index 4e0aa277..ce3e007b 100644 --- a/src/arduino_lmic_hal_configuration.h +++ b/src/arduino_lmic_hal_configuration.h @@ -18,6 +18,7 @@ Copyright & License: #ifndef _arduino_lmic_hal_configuration_h_ # define _arduino_lmic_hal_configuration_h_ +#include #include #include "lmic/lmic_env.h" @@ -60,8 +61,8 @@ struct HalPinmap_t { int8_t rssi_cal; // byte 7: cal in dB -- added to RSSI // measured prior to decision. // Must include noise guardband! + SPIClass *spi; // SPI interface used uint32_t spi_freq; // bytes 8..11: SPI freq in Hz. - // optional pointer to configuration object (bytes 12..15) HalConfiguration_t *pConfig; }; diff --git a/src/hal/getpinmap_catena4420.cpp b/src/hal/getpinmap_catena4420.cpp index 21431405..eb2cf76f 100644 --- a/src/hal/getpinmap_catena4420.cpp +++ b/src/hal/getpinmap_catena4420.cpp @@ -66,6 +66,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 0, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4551.cpp b/src/hal/getpinmap_catena4551.cpp index 817dc77b..ddd9f1da 100644 --- a/src/hal/getpinmap_catena4551.cpp +++ b/src/hal/getpinmap_catena4551.cpp @@ -70,6 +70,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig, }; diff --git a/src/hal/getpinmap_catena4610.cpp b/src/hal/getpinmap_catena4610.cpp index 54e2a562..002b1d79 100644 --- a/src/hal/getpinmap_catena4610.cpp +++ b/src/hal/getpinmap_catena4610.cpp @@ -87,6 +87,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4611.cpp b/src/hal/getpinmap_catena4611.cpp index fbab2812..64fb8793 100644 --- a/src/hal/getpinmap_catena4611.cpp +++ b/src/hal/getpinmap_catena4611.cpp @@ -87,6 +87,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4612.cpp b/src/hal/getpinmap_catena4612.cpp index 9fdb3bd5..da60e37b 100644 --- a/src/hal/getpinmap_catena4612.cpp +++ b/src/hal/getpinmap_catena4612.cpp @@ -89,6 +89,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4617.cpp b/src/hal/getpinmap_catena4617.cpp index e3857a2d..961acef4 100644 --- a/src/hal/getpinmap_catena4617.cpp +++ b/src/hal/getpinmap_catena4617.cpp @@ -87,6 +87,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4618.cpp b/src/hal/getpinmap_catena4618.cpp index 9e0c4495..779b2062 100644 --- a/src/hal/getpinmap_catena4618.cpp +++ b/src/hal/getpinmap_catena4618.cpp @@ -87,6 +87,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4630.cpp b/src/hal/getpinmap_catena4630.cpp index 0ee0b273..395ccf45 100644 --- a/src/hal/getpinmap_catena4630.cpp +++ b/src/hal/getpinmap_catena4630.cpp @@ -87,6 +87,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4801.cpp b/src/hal/getpinmap_catena4801.cpp index eeeb59b3..9af675bf 100644 --- a/src/hal/getpinmap_catena4801.cpp +++ b/src/hal/getpinmap_catena4801.cpp @@ -87,6 +87,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_catena4802.cpp b/src/hal/getpinmap_catena4802.cpp index ef9d8d61..369bb853 100644 --- a/src/hal/getpinmap_catena4802.cpp +++ b/src/hal/getpinmap_catena4802.cpp @@ -87,6 +87,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_challenger_rp2040_lora.cpp b/src/hal/getpinmap_challenger_rp2040_lora.cpp new file mode 100644 index 00000000..87bd6aef --- /dev/null +++ b/src/hal/getpinmap_challenger_rp2040_lora.cpp @@ -0,0 +1,59 @@ +/* + +Module: getpinmap_challenger_rp2040_lora.cpp + +Function: + Arduino-LMIC C++ HAL pinmap for iLabs Challenger RP2040 LoRa boards. + https://ilabs.se/product/challenger-rp2040-lora + +Copyright & License: + See accompanying LICENSE file. + +Author: + Pontus Oldberg, iLabs - August 2022 + +*/ + +// Make sure only to compiler when the appropriate board is enabled +#if defined(ARDUINO_CHALLENGER_2040_LORA_RP2040) + +#include +#include + +#include "../lmic/oslmic.h" +#include "../hal/hal.h" + +namespace Arduino_LMIC { + class HalConfiguration_Challenger_RP2040_LoRa_t : public HalConfiguration_t { + public: + virtual void begin(void) override { + pinMode(RFM95W_SS, OUTPUT); + digitalWrite(RFM95W_SS, 1); + } + + // virtual void end(void) override + + // virtual ostime_t setModuleActive(bool state) override + }; + + static HalConfiguration_Challenger_RP2040_LoRa_t myConfig; + + // Pins are defined in the Arduino variant files + static const HalPinmap_t myPinmap = { + .nss = RFM95W_SS, + .rxtx = LMIC_UNUSED_PIN, + .rst = RFM95W_RST, + .dio = {RFM95W_DIO0, RFM95W_DIO1, RFM95W_DIO2}, + .rxtx_rx_active = 0, + .rssi_cal = 8, // LBT cal for the Challenger RP2040 LoRa + .spi = &SPI1, + .spi_freq = 10000000, + .pConfig = &myConfig + }; + + const HalPinmap_t *GetPinmap_Challenger_RP2040_LoRa(void) { + return &myPinmap; + } +}; // namespace Arduino_LMIC + +#endif // defined(ARDUINO_CHALLENGER_2040_LORA_RP2040) diff --git a/src/hal/getpinmap_connectivity_840.cpp b/src/hal/getpinmap_connectivity_840.cpp new file mode 100644 index 00000000..705d32f1 --- /dev/null +++ b/src/hal/getpinmap_connectivity_840.cpp @@ -0,0 +1,59 @@ +/* + +Module: getpinmap_connectivity_840.cpp + +Function: + Arduino-LMIC C++ HAL pinmap for iLabs Connectivity 840 board. + + +Copyright & License: + See accompanying LICENSE file. + +Author: + Pontus Oldberg, iLabs - September 2025 + +*/ + +// Make sure only to compile when the appropriate board is enabled +#if defined(ARDUINO_CONNECTIVITY_840) + +#include +#include + +#include "../lmic/oslmic.h" +#include "../hal/hal.h" + +namespace Arduino_LMIC { + class HalConfiguration_Connectivity_840_t : public HalConfiguration_t { + public: + virtual void begin(void) override { + pinMode(PIN_SPI1_CS, OUTPUT); + digitalWrite(PIN_SPI1_CS, 1); + } + + // virtual void end(void) override + + // virtual ostime_t setModuleActive(bool state) override + }; + + static HalConfiguration_Connectivity_840_t myConfig; + + // Pins are defined in the Arduino variant files + static const HalPinmap_t myPinmap = { + .nss = PIN_SPI1_CS, + .rxtx = LMIC_UNUSED_PIN, + .rst = PIN_LORA_RST, + .dio = {PIN_LORA_DIO0, PIN_LORA_DIO1, PIN_LORA_DIO2}, + .rxtx_rx_active = 0, + .rssi_cal = 8, + .spi = &LORA_SPI, + .spi_freq = 8000000, + .pConfig = &myConfig + }; + + const HalPinmap_t *GetPinmap_Connectivity_840(void) { + return &myPinmap; + } +}; // namespace Arduino_LMIC + +#endif // defined(ARDUINO_CONNECTIVITY_840) diff --git a/src/hal/getpinmap_disco_l072cs_lrwan1.cpp b/src/hal/getpinmap_disco_l072cs_lrwan1.cpp index 576b9158..8ec215e6 100644 --- a/src/hal/getpinmap_disco_l072cs_lrwan1.cpp +++ b/src/hal/getpinmap_disco_l072cs_lrwan1.cpp @@ -20,7 +20,7 @@ Copyright & License: #include "../lmic/oslmic.h" -namespace Arduino_LMIC { +namespace Arduino_LMIC { class HalConfiguration_Disco_L072cz_Lrwan1_t : public HalConfiguration_t { @@ -43,15 +43,16 @@ namespace Arduino_LMIC { static const HalPinmap_t myPinmap = { .nss = HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_NSS, - .rxtx = HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_RXTX, + .rxtx = HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_RXTX, .rst = HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_NRESET, - .dio = {HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO0, - HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO1, - HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO2, + .dio = {HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO0, + HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO1, + HalConfiguration_Disco_L072cz_Lrwan1_t::PIN_SX1276_DIO2, }, .rxtx_rx_active = 1, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_feather32u4lora.cpp b/src/hal/getpinmap_feather32u4lora.cpp index 715dfa5c..3c468775 100644 --- a/src/hal/getpinmap_feather32u4lora.cpp +++ b/src/hal/getpinmap_feather32u4lora.cpp @@ -69,6 +69,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 0, .rssi_cal = 8, + .spi = &SPI, .spi_freq = 1000000, /* 1MHz */ .pConfig = &myConfig, }; diff --git a/src/hal/getpinmap_featherm0lora.cpp b/src/hal/getpinmap_featherm0lora.cpp index 19751d39..6fe200e6 100644 --- a/src/hal/getpinmap_featherm0lora.cpp +++ b/src/hal/getpinmap_featherm0lora.cpp @@ -67,6 +67,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 0, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_heltec_lora32.cpp b/src/hal/getpinmap_heltec_lora32.cpp index 43e0b37d..4ef46313 100644 --- a/src/hal/getpinmap_heltec_lora32.cpp +++ b/src/hal/getpinmap_heltec_lora32.cpp @@ -71,6 +71,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 0, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig}; diff --git a/src/hal/getpinmap_heltec_lora32_v3.cpp b/src/hal/getpinmap_heltec_lora32_v3.cpp index 4bcab976..faa25b14 100644 --- a/src/hal/getpinmap_heltec_lora32_v3.cpp +++ b/src/hal/getpinmap_heltec_lora32_v3.cpp @@ -63,6 +63,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 0, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig}; diff --git a/src/hal/getpinmap_thisboard.cpp b/src/hal/getpinmap_thisboard.cpp index 19b9a553..741607be 100644 --- a/src/hal/getpinmap_thisboard.cpp +++ b/src/hal/getpinmap_thisboard.cpp @@ -17,13 +17,16 @@ Copyright & License: namespace Arduino_LMIC { -const HalPinmap_t *GetPinmap_ThisBoard(void) - { +const HalPinmap_t *GetPinmap_ThisBoard(void) { +#if defined(ARDUINO_CHALLENGER_2040_LORA_RP2040) + return GetPinmap_Challenger_RP2040_LoRa(); +#elif defined(ARDUINO_CONNECTIVITY_840) + return GetPinmap_Connectivity_840(); /* || Adafruit BSPs are not consistent -- m0 express defs ARDUINO_SAMD_FEATHER_M0, || m0 defs ADAFRUIT_FEATHER_M0 */ -#if defined(ARDUINO_SAMD_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0) +# elif defined(ARDUINO_SAMD_FEATHER_M0) || defined(ADAFRUIT_FEATHER_M0) # if defined(ARDUINO_MCCI_CATENA_4420) // this uses a radiowing and an odd configuration return GetPinmap_Catena4420(); @@ -78,4 +81,3 @@ const HalPinmap_t *GetPinmap_ThisBoard(void) } }; // namespace Arduino_LMIC - diff --git a/src/hal/getpinmap_ttgo_lora32_v1.cpp b/src/hal/getpinmap_ttgo_lora32_v1.cpp index 9beb370c..62121b6d 100644 --- a/src/hal/getpinmap_ttgo_lora32_v1.cpp +++ b/src/hal/getpinmap_ttgo_lora32_v1.cpp @@ -68,6 +68,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 0, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_ttgo_lora32_v2.1.cpp b/src/hal/getpinmap_ttgo_lora32_v2.1.cpp index 77f95891..8982c0f3 100644 --- a/src/hal/getpinmap_ttgo_lora32_v2.1.cpp +++ b/src/hal/getpinmap_ttgo_lora32_v2.1.cpp @@ -68,6 +68,7 @@ static const HalPinmap_t myPinmap = }, .rxtx_rx_active = 0, .rssi_cal = 10, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/getpinmap_ttgo_tbeam_s3.cpp b/src/hal/getpinmap_ttgo_tbeam_s3.cpp index 0f276838..0e1326df 100644 --- a/src/hal/getpinmap_ttgo_tbeam_s3.cpp +++ b/src/hal/getpinmap_ttgo_tbeam_s3.cpp @@ -57,6 +57,7 @@ namespace Arduino_LMIC { }, .rxtx_rx_active = 0, .rssi_cal = 8, + .spi = &SPI, .spi_freq = 8000000, /* 8MHz */ .pConfig = &myConfig }; diff --git a/src/hal/hal.cpp b/src/hal/hal.cpp index 7f0395e9..e4a54c4b 100644 --- a/src/hal/hal.cpp +++ b/src/hal/hal.cpp @@ -188,7 +188,7 @@ void lmic_hal_processPendingIRQs() { // SPI static void lmic_hal_spi_init () { - SPI.begin(); + plmic_pins->spi->begin(); } #if (defined(CFG_sx1261_radio) || defined(CFG_sx1262_radio)) @@ -211,7 +211,7 @@ static void lmic_hal_spi_trx(u1_t cmd, u1_t* buf, size_t len, bit_t is_read) { spi_freq = LMIC_SPI_FREQ; SPISettings settings(spi_freq, MSBFIRST, SPI_MODE0); - SPI.beginTransaction(settings); + plmic_pins->spi->beginTransaction(settings); digitalWrite(nss, 0); // SX126x modems use BUSY pin. Only interact with SPI when BUSY goes LOW @@ -219,17 +219,17 @@ static void lmic_hal_spi_trx(u1_t cmd, u1_t* buf, size_t len, bit_t is_read) { while (lmic_hal_radio_spi_is_busy()); #endif - SPI.transfer(cmd); + plmic_pins->spi->transfer(cmd); for (; len > 0; --len, ++buf) { u1_t data = is_read ? 0x00 : *buf; - data = SPI.transfer(data); + data = plmic_pins->spi->transfer(data); if (is_read) *buf = data; } digitalWrite(nss, 1); - SPI.endTransaction(); + plmic_pins->spi->endTransaction(); } void lmic_hal_spi_write(u1_t cmd, const u1_t* buf, size_t len) { @@ -250,28 +250,28 @@ void lmic_hal_spi_read_sx126x(u1_t cmd, u1_t* addr, size_t addr_len, u1_t* buf, spi_freq = LMIC_SPI_FREQ; SPISettings settings(spi_freq, MSBFIRST, SPI_MODE0); - SPI.beginTransaction(settings); + plmic_pins->spi->beginTransaction(settings); digitalWrite(nss, 0); while (lmic_hal_radio_spi_is_busy()); - SPI.transfer(cmd); + plmic_pins->spi->transfer(cmd); // Transfer address and NOP bits for (; addr_len > 0; --addr_len, ++addr) { u1_t addr_byte = *addr; - SPI.transfer(addr_byte); + plmic_pins->spi->transfer(addr_byte); } // Read buf_len bytes to buf for (; buf_len > 0; --buf_len, ++buf) { u1_t data = 0x00; - data = SPI.transfer(data); + plmic_pins->spi->transfer(data); *buf = data; } digitalWrite(nss, 1); - SPI.endTransaction(); + plmic_pins->spi->endTransaction(); } #endif @@ -364,7 +364,7 @@ u4_t lmic_hal_waitUntil (u4_t time) { // The radio driver runs with interrupt disabled, and this can // mess up timing APIs on some platforms. If we know the BSP feature - // set, we can decide whether to use delta_time() [more exact, + // set, we can decide whether to use delta_time() [more exact, // but not always possible with interrupts off], or fall back to // delay_microseconds() [less exact, but more universal] diff --git a/src/hal/hal.h b/src/hal/hal.h index 4cf7ae09..3e6a9527 100644 --- a/src/hal/hal.h +++ b/src/hal/hal.h @@ -13,6 +13,7 @@ #define _hal_hal_h_ #include "arduino_lmic_hal_configuration.h" +#include "SPI.h" #include "lmic/oslmic_types.h" // for compatbility reasons, we need to disclose the configuration diff --git a/src/lmic/oslmic.c b/src/lmic/oslmic.c index e397719e..d6f0dbc2 100644 --- a/src/lmic/oslmic.c +++ b/src/lmic/oslmic.c @@ -30,7 +30,7 @@ #include "lmic.h" -extern const struct lmic_pinmap lmic_pins; +const struct lmic_pinmap __attribute__((weak)) *lmic_pins = NULL; // RUNTIME STATE static struct { @@ -48,8 +48,9 @@ int os_init_ex (const void *pintable) { } void os_init() { - if (os_init_ex((const void *)&lmic_pins)) - return; + if (lmic_pins) + if (os_init_ex((const void *)lmic_pins)) + return; ASSERT(0); }