-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Add NiceRF LoRa2021 (LR2021 Gen 4) variant support #2739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
c03rad0r
wants to merge
8
commits into
meshcore-dev:dev
Choose a base branch
from
c03rad0r:feature/nicerf-lr2021-variant
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
49d3cd5
feat: add NiceRF LoRa2021 (LR2021 Gen 4) variant support
0696114
fix: adapt to upstream dev API changes (setParams, getSpreadingFactor)
627909a
fix: remove getPacketLength override (#2), use LR2021 IRQ constants (…
c03rad0r e5a0e5b
fix: try standard SPIClass(0) per reviewer suggestion (#1), keep EspI…
c03rad0r 684e9d9
fix: add configurable LR2021_IRQ_DIO=9 build flag per review feedback…
c03rad0r 05ad173
refactor: move EspIdfHal.h to src/helpers/radiolib/ per reviewer sugg…
c03rad0r 886b23d
fix: enable ESP-IDF HAL by default for LR2021 variant
c03rad0r c23a323
security: add secret-detection hooks (pre-commit + pre-push)
c03rad0r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env bash | ||
| # pre-commit: block commits containing secrets | ||
| # Scans staged files for known secret patterns | ||
| set -e | ||
|
|
||
| PATTERNS_FILE="$(git rev-parse --show-toplevel)/.secret-patterns.txt" | ||
| STAGED=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null) | ||
|
|
||
| if [ ! -f "$PATTERNS_FILE" ]; then | ||
| exit 0 # no patterns file = no scanning | ||
| fi | ||
|
|
||
| FOUND=0 | ||
| for file in $STAGED; do | ||
| [ -f "$file" ] || continue | ||
| while IFS= read -r pattern; do | ||
| [ -z "$pattern" ] && continue | ||
| [[ "$pattern" == \#* ]] && continue | ||
| MATCH=$(git diff --cached -- "$file" | grep -nP "$pattern" 2>/dev/null | head -3) | ||
| if [ -n "$MATCH" ]; then | ||
| echo "SECRET DETECTED in $file (pattern: $pattern):" | ||
| echo "$MATCH" | ||
| FOUND=1 | ||
| fi | ||
| done < "$PATTERNS_FILE" | ||
| done | ||
|
|
||
| if [ $FOUND -eq 1 ]; then | ||
| echo "" | ||
| echo "COMMIT BLOCKED — secret pattern detected." | ||
| echo "Override (NOT RECOMMENDED): git commit --no-verify" | ||
| exit 1 | ||
| fi | ||
|
|
||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/usr/bin/env bash | ||
| # pre-push: block pushes containing secrets + run quality gates | ||
| # Scans all commits being pushed for secret patterns | ||
| set -e | ||
|
|
||
| PATTERNS_FILE="$(git rev-parse --show-toplevel)/.secret-patterns.txt" | ||
|
|
||
| if [ ! -f "$PATTERNS_FILE" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Get commits being pushed | ||
| RANGE="@{u}..HEAD" | ||
| COMMITS=$(git rev-list "$RANGE" 2>/dev/null || echo "") | ||
|
|
||
| if [ -z "$COMMITS" ]; then | ||
| # No upstream — scan last 5 commits | ||
| COMMITS=$(git rev-list HEAD~5..HEAD 2>/dev/null || echo "") | ||
| fi | ||
|
|
||
| FOUND=0 | ||
| while IFS= read -r pattern; do | ||
| [ -z "$pattern" ] && continue | ||
| [[ "$pattern" == \#* ]] && continue | ||
| MATCH=$(git log -p $RANGE 2>/dev/null | grep -nP "$pattern" 2>/dev/null | head -5) | ||
| if [ -n "$MATCH" ]; then | ||
| echo "SECRET in push history (pattern: $pattern):" | ||
| echo "$MATCH" | ||
| FOUND=1 | ||
| fi | ||
| done < "$PATTERNS_FILE" | ||
|
|
||
| if [ $FOUND -eq 1 ]; then | ||
| echo "" | ||
| echo "PUSH BLOCKED — secrets detected in commit history." | ||
| echo "Scrub with: git filter-repo --replace-text .secret-patterns.txt" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "No secrets detected." | ||
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Secret patterns — one regex per line, # for comments | ||
| # Block commits/pushes containing these patterns | ||
|
|
||
| # Nostr private keys | ||
| nsec1[a-z0-9]{20,} | ||
|
|
||
| # API keys (PPQ, OpenAI, etc.) | ||
| sk-[A-Za-z0-9]{10,} | ||
|
|
||
| # z.ai key format (32-char hex hash + dot + alphanumeric) | ||
| [0-9a-f]{32}\.[A-Za-z0-9]{8,} | ||
|
|
||
| # Private keys (PEM format) | ||
| -----BEGIN [A-Z ]*PRIVATE KEY | ||
|
|
||
| # Bearer tokens | ||
| Bearer [A-Za-z0-9\-._~+/]{20,} | ||
|
|
||
| # Hardcoded password/secret assignments (not env vars) | ||
| password.*=.*['\"][^'\"]{4,}['\"] | ||
| api_key.*=.*['\"][^'\"]{8,}['\"] | ||
| secret_key.*=.*['\"][^'\"]{8,}['\"] | ||
|
|
||
| # Signal phone numbers | ||
| \+1\d{10} | ||
|
|
||
| # Matrix access tokens | ||
| syt\.[A-Za-z0-9_-]{10,} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "build": { | ||
| "arduino": { | ||
| "ldscript": "esp32c3_out.ld" | ||
| }, | ||
| "core": "esp32", | ||
| "extra_flags": [ | ||
| "-DARDUINO_ESP32C3_SUPERMINI", | ||
| "-DARDUINO_USB_MODE=1", | ||
| "-DARDUINO_USB_CDC_ON_BOOT=1" | ||
| ], | ||
| "f_cpu": "160000000L", | ||
| "f_flash": "80000000L", | ||
| "flash_mode": "dio", | ||
| "hwids": [ | ||
| [ | ||
| "0x303a", | ||
| "0x1001" | ||
| ] | ||
| ], | ||
| "mcu": "esp32c3", | ||
| "variant": "esp32c3_supermini" | ||
| }, | ||
| "connectivity": [ | ||
| "wifi" | ||
| ], | ||
| "debug": { | ||
| "openocd_target": "esp32c3.cfg" | ||
| }, | ||
| "frameworks": [ | ||
| "arduino", | ||
| "espidf" | ||
| ], | ||
| "name": "ESP32-C3 SuperMini V1 (Maker go)", | ||
| "upload": { | ||
| "flash_size": "4MB", | ||
| "maximum_ram_size": 327680, | ||
| "maximum_size": 4194304, | ||
| "require_upload_port": true, | ||
| "speed": 460800 | ||
| }, | ||
| "url": "https://www.aliexpress.com/item/1005006155740481.html", | ||
| "vendor": "Maker go" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #pragma once | ||
|
|
||
| #include <RadioLib.h> | ||
| #include "MeshCore.h" | ||
|
|
||
| class CustomLR2021 : public LR2021 { | ||
| bool _rx_boosted = false; | ||
|
|
||
| public: | ||
| CustomLR2021(Module *mod) : LR2021(mod) { | ||
| irqDioNum = LR2021_IRQ_DIO; | ||
| } | ||
|
|
||
| float getFreqMHz() const { return freqMHz; } | ||
|
|
||
| uint8_t getSpreadingFactor() const { return spreadingFactor; } | ||
|
|
||
| int16_t setRxBoostedGainMode(uint8_t level) { | ||
| _rx_boosted = (level > 0); | ||
| return LR2021::setRxBoostedGainMode(level); | ||
| } | ||
|
|
||
| bool getRxBoostedGainMode() const { return _rx_boosted; } | ||
|
|
||
| bool isReceiving() { | ||
| uint32_t irq = getIrqStatus(); | ||
| // Use LR2021-specific IRQ flags if available, fall back to LR11x0 | ||
| #ifdef RADIOLIB_LR2021_IRQ_PREAMBLE_DETECTED | ||
| bool detected = (irq & RADIOLIB_LR2021_IRQ_LORA_HEADER_VALID) || | ||
| (irq & RADIOLIB_LR2021_IRQ_PREAMBLE_DETECTED); | ||
| #else | ||
| bool detected = (irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || | ||
| (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED); | ||
| #endif | ||
| return detected; | ||
| } | ||
|
|
||
| bool std_init(SPIClass *spi = NULL) { | ||
| (void)spi; | ||
|
|
||
| int status = begin(LORA_FREQ, LORA_BW, LORA_SF, 5, | ||
| RADIOLIB_LR2021_LORA_SYNC_WORD_PRIVATE, | ||
| LORA_TX_POWER, 16, 0.0); | ||
| if (status != RADIOLIB_ERR_NONE) { | ||
| MESH_DEBUG_PRINTLN("LR2021: radio init failed: %d", status); | ||
| return false; | ||
| } | ||
|
|
||
| setCRC(1); | ||
| return true; | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #pragma once | ||
|
|
||
| #include "CustomLR2021.h" | ||
| #include "RadioLibWrappers.h" | ||
|
|
||
| class CustomLR2021Wrapper : public RadioLibWrapper { | ||
| public: | ||
| CustomLR2021Wrapper(CustomLR2021 &radio, mesh::MainBoard &board) | ||
| : RadioLibWrapper(radio, board) {} | ||
|
|
||
| void setParams(float freq, float bw, uint8_t sf, uint8_t cr) override { | ||
| ((CustomLR2021 *)_radio)->setFrequency(freq); | ||
| ((CustomLR2021 *)_radio)->setSpreadingFactor(sf); | ||
| ((CustomLR2021 *)_radio)->setBandwidth(bw); | ||
| ((CustomLR2021 *)_radio)->setCodingRate(cr); | ||
| updatePreamble(sf); | ||
| } | ||
|
|
||
| bool isReceivingPacket() override { | ||
| return ((CustomLR2021 *)_radio)->isReceiving(); | ||
| } | ||
|
|
||
| float getCurrentRSSI() override { | ||
| float rssi = -110; | ||
| ((CustomLR2021 *)_radio)->getRssiInst(&rssi); | ||
| return rssi; | ||
| } | ||
|
|
||
| void onSendFinished() override { | ||
| RadioLibWrapper::onSendFinished(); | ||
| _radio->setPreambleLength( | ||
| preambleLengthForSF(getSpreadingFactor())); | ||
| } | ||
|
|
||
| float getLastRSSI() const override { | ||
| return ((CustomLR2021 *)_radio)->getRSSI(); | ||
| } | ||
|
|
||
| float getLastSNR() const override { | ||
| return ((CustomLR2021 *)_radio)->getSNR(); | ||
| } | ||
|
|
||
| uint8_t getSpreadingFactor() const override { | ||
| return ((CustomLR2021 *)_radio)->getSpreadingFactor(); | ||
| } | ||
|
|
||
| float packetScore(float snr, int packet_len) override { | ||
| int sf = ((CustomLR2021 *)_radio)->getSpreadingFactor(); | ||
| return packetScoreInt(snr, sf, packet_len); | ||
| } | ||
|
|
||
| void powerOff() override { | ||
| ((CustomLR2021 *)_radio)->sleep(false, 0); | ||
| } | ||
|
|
||
| void doResetAGC() override { | ||
| CustomLR2021 *r = (CustomLR2021 *)_radio; | ||
| float freq = r->getFreqMHz(); | ||
| r->sleep(true, 0); | ||
| r->standby(RADIOLIB_LR2021_STANDBY_RC, true); | ||
| r->calibrate(RADIOLIB_LR2021_CALIBRATE_ALL); | ||
| r->setFrequency(freq); | ||
| r->setRxBoostedGainMode(RADIOLIB_LR2021_RX_BOOST_LF); | ||
| } | ||
|
|
||
| void setRxBoostedGainMode(bool en) override { | ||
| ((CustomLR2021 *)_radio)->setRxBoostedGainMode( | ||
| en ? RADIOLIB_LR2021_RX_BOOST_LF : 0); | ||
| } | ||
|
|
||
| bool getRxBoostedGainMode() const override { | ||
| return ((CustomLR2021 *)_radio)->getRxBoostedGainMode(); | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.