mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-15 02:52:58 +00:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb524f7110 | |||
| 3413d71bb3 | |||
| c64dddf5cc | |||
| 3d56bccd49 | |||
| 705e4f125f | |||
| 363b27efe8 | |||
| f8ed7489c9 | |||
| 0685fb7a9f | |||
| 6498f5a1b2 | |||
| 77f747aab2 | |||
| 819b4d0fed | |||
| 15df51f976 | |||
| e9e78609b7 | |||
| 785bd06938 | |||
| 300a4b03c6 | |||
| eaa07f8369 | |||
| c31a978e6f | |||
| 266db4b158 | |||
| 290bf543a1 | |||
| e17f4c4ab4 | |||
| 83a4580353 | |||
| 00f40bf171 | |||
| 794daf5257 | |||
| 95eafeb812 | |||
| 94d46036f8 | |||
| 68000f0b94 | |||
| eff68693ad | |||
| 2f468fd37c | |||
| 39424632bb | |||
| cd30022b61 | |||
| be872003ec | |||
| 9e7758718c | |||
| 89b878d3bb | |||
| 56d965f3ae | |||
| fe9f0c228f | |||
| 6562e596e8 | |||
| c27192bdbb | |||
| 927e3b11e7 | |||
| a44a00acf0 | |||
| 6739b43914 | |||
| b306a0d490 | |||
| c6130c6e8d | |||
| 97f2ca42f1 |
@@ -3,7 +3,7 @@ name: Check formatting
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
check_date:
|
||||
check_format:
|
||||
runs-on: ubuntu-latest
|
||||
name: Check formatting
|
||||
strategy:
|
||||
@@ -13,12 +13,20 @@ jobs:
|
||||
- "firmware/application"
|
||||
- "firmware/baseband"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: print latest_commit
|
||||
run: echo ${{ github.sha }}
|
||||
- name: clang-format Check
|
||||
uses: jidicula/clang-format-action@v4.11.0
|
||||
with:
|
||||
clang-format-version: '18'
|
||||
check-path: ${{ matrix.path }}
|
||||
fallback-style: Chromium
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: clang-format check (repo pinned)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
CF="./tools/clang-format.sh"
|
||||
chmod +x "$CF" || true
|
||||
|
||||
"$CF" --version
|
||||
|
||||
ROOT="${{ matrix.path }}"
|
||||
find "$ROOT" -type f \( \
|
||||
-name '*.c' -o -name '*.cpp' -o \
|
||||
-name '*.h' -o -name '*.hpp' \
|
||||
\) -print0 \
|
||||
| xargs -0 -r "$CF" --dry-run --Werror --style=file
|
||||
|
||||
@@ -3,7 +3,7 @@ name: Nightly Release
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@@ -21,27 +21,36 @@ jobs:
|
||||
id: should_run
|
||||
continue-on-error: true
|
||||
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "should_run=false" >> $GITHUB_OUTPUT
|
||||
|
||||
build:
|
||||
needs: check_date
|
||||
if: ${{ needs.check_date.outputs.should_run != 'false' }}
|
||||
runs-on: ubuntu-latest
|
||||
name: build (${{ matrix.device_name }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- device: default
|
||||
device_name: HackRF
|
||||
cmake_args: ""
|
||||
artifact_suffix: "_hackrf"
|
||||
- device: portarf
|
||||
device_name: PortaRF
|
||||
cmake_args: "-DFLASH_MB_SIZE=2 -DFLASH_MB_LIMIT_SIZE=2"
|
||||
artifact_suffix: "_portarf"
|
||||
- device: hpro
|
||||
device_name: HackRF Pro
|
||||
cmake_args: "-DBOARD=PRALINE"
|
||||
artifact_suffix: "_hpro"
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Get version date
|
||||
id: version_date
|
||||
run: echo "date=n_$(date +'%y%m%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
#ref: next
|
||||
# The branch, tag or SHA to checkout. When checking out the repository that
|
||||
# triggered a workflow, this defaults to the reference or SHA for that event.
|
||||
# Otherwise, uses the default branch.
|
||||
# https://github.com/actions/checkout
|
||||
# So scheduled runs will use the default branch (next) but its now possible to trigger a workflow from another branch
|
||||
submodules: true
|
||||
- name: Git Sumbodule Update
|
||||
run: |
|
||||
@@ -51,10 +60,10 @@ jobs:
|
||||
- name: Make build folder
|
||||
run: mkdir ${{ github.workspace }}/build
|
||||
- name: Run the Docker image
|
||||
run: docker run -e VERSION_STRING=${{ steps.version_date.outputs.date }} -i -v ${{ github.workspace }}:/havoc portapack-dev
|
||||
run: docker run -e VERSION_STRING=${{ steps.version_date.outputs.date }} -i -v ${{ github.workspace }}:/havoc portapack-dev ${{ matrix.cmake_args }}
|
||||
- name: Create Small SD Card ZIP - No World Map
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
- name: Download world map
|
||||
run: |
|
||||
wget https://github.com/portapack-mayhem/mayhem-firmware/releases/download/world_map/world_map.zip
|
||||
@@ -69,7 +78,47 @@ jobs:
|
||||
zip -j firmware.zip build/firmware/portapack-mayhem-firmware.bin && cd flashing && zip -r ../firmware.zip *
|
||||
- name: Create SD Card ZIP
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
- name: Upload firmware zip artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: firmware-${{ matrix.device }}
|
||||
path: ./firmware.zip
|
||||
- name: Upload SD card artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-${{ matrix.device }}
|
||||
path: ./sdcard.zip
|
||||
- name: Upload SD card no-map artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-no-map-${{ matrix.device }}
|
||||
path: ./sdcard-no-map.zip
|
||||
- name: Upload OCI tar artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: oci-tar-${{ matrix.device }}
|
||||
path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Get version date
|
||||
id: version_date
|
||||
run: echo "date=n_$(date +'%y%m%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
- name: Create changelog
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -96,43 +145,114 @@ jobs:
|
||||
${{ steps.changelog.outputs.content }}
|
||||
draft: false
|
||||
prerelease: true
|
||||
- name: Upload Firmware TAR Asset
|
||||
id: upload-firmware-tar-asset
|
||||
# Default device assets
|
||||
- name: Upload Default Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_OCI.ppfw.tar
|
||||
asset_path: artifacts/oci-tar-default/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload Firmware Asset
|
||||
id: upload-firmware-asset
|
||||
- name: Upload Default Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./firmware.zip
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_FIRMWARE.zip
|
||||
asset_path: artifacts/firmware-default/firmware.zip
|
||||
asset_name: FIRMWARE_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets
|
||||
id: upload-sd-card-asset
|
||||
- name: Upload Default SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard.zip
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_COPY_TO_SDCARD.zip
|
||||
asset_path: artifacts/sdcard-default/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets - No Map
|
||||
id: upload-sd-card-asset-no-map
|
||||
- name: Upload Default SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard-no-map.zip
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_COPY_TO_SDCARD-no-world-map.zip
|
||||
asset_path: artifacts/sdcard-no-map-default/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# PortaRF device assets
|
||||
- name: Upload PortaRF Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-portarf/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload PortaRF Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-portarf/firmware.zip
|
||||
asset_name: FIRMWARE_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-portarf/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-portarf/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# HPro device assets
|
||||
- name: Upload HPro Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-hpro/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload HPro Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-hpro/firmware.zip
|
||||
asset_name: FIRMWARE_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-hpro/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-hpro/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
@@ -1,25 +1,36 @@
|
||||
name: Stable Release
|
||||
|
||||
on:
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
name: build (${{ matrix.device_name }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- device: default
|
||||
device_name: HackRF
|
||||
cmake_args: ""
|
||||
artifact_suffix: "_hackrf"
|
||||
- device: portarf
|
||||
device_name: PortaRF
|
||||
cmake_args: "-DFLASH_MB_SIZE=2 -DFLASH_MB_LIMIT_SIZE=2"
|
||||
artifact_suffix: "_portarf"
|
||||
- device: hpro
|
||||
device_name: HackRF Pro
|
||||
cmake_args: "-DBOARD=PRALINE"
|
||||
artifact_suffix: "_hpro"
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
#ref: next
|
||||
# The branch, tag or SHA to checkout. When checking out the repository that
|
||||
# triggered a workflow, this defaults to the reference or SHA for that event.
|
||||
# Otherwise, uses the default branch.
|
||||
# https://github.com/actions/checkout
|
||||
# So scheduled runs will use the default branch (next) but its now possible to trigger a workflow from another branch
|
||||
submodules: true
|
||||
- name: Git Sumbodule Update
|
||||
run: |
|
||||
@@ -27,18 +38,15 @@ jobs:
|
||||
- name: Get version
|
||||
id: version
|
||||
run: echo "version=$(cat .github/workflows/version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Get past version
|
||||
id: past_version
|
||||
run: echo "past_version=$(cat .github/workflows/past_version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Build the Docker image
|
||||
run: docker build -t portapack-dev -f dockerfile-nogit . --tag my-image-name:$(date +%s)
|
||||
- name: Make build folder
|
||||
run: mkdir ${{ github.workspace }}/build
|
||||
- name: Run the Docker image
|
||||
run: docker run -e VERSION_STRING=${{ steps.version.outputs.version }} -i -v ${{ github.workspace }}:/havoc portapack-dev
|
||||
run: docker run -e VERSION_STRING=${{ steps.version.outputs.version }} -i -v ${{ github.workspace }}:/havoc portapack-dev ${{ matrix.cmake_args }}
|
||||
- name: Create Small SD Card ZIP - No World Map
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
- name: Download world map
|
||||
run: |
|
||||
wget https://github.com/portapack-mayhem/mayhem-firmware/releases/download/world_map/world_map.zip
|
||||
@@ -53,7 +61,50 @@ jobs:
|
||||
zip -j firmware.zip build/firmware/portapack-mayhem-firmware.bin && cd flashing && zip -r ../firmware.zip *
|
||||
- name: Create SD Card ZIP
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
- name: Upload firmware zip artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: firmware-${{ matrix.device }}
|
||||
path: ./firmware.zip
|
||||
- name: Upload SD card artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-${{ matrix.device }}
|
||||
path: ./sdcard.zip
|
||||
- name: Upload SD card no-map artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-no-map-${{ matrix.device }}
|
||||
path: ./sdcard-no-map.zip
|
||||
- name: Upload OCI tar artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: oci-tar-${{ matrix.device }}
|
||||
path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
- name: Get version
|
||||
id: version
|
||||
run: echo "version=$(cat .github/workflows/version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Get past version
|
||||
id: past_version
|
||||
run: echo "past_version=$(cat .github/workflows/past_version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
- name: Create changelog
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -78,7 +129,7 @@ jobs:
|
||||
## Release notes
|
||||
### Revision (${{ steps.version.outputs.version }}):
|
||||
${{ steps.changelog.outputs.content }}
|
||||
|
||||
|
||||
**Full Changelog**: https://github.com/portapack-mayhem/mayhem-firmware/compare/${{ steps.past_version.outputs.past_version }}...${{ steps.version.outputs.version }}
|
||||
|
||||
## Installation
|
||||
@@ -90,44 +141,114 @@ jobs:
|
||||
For certain functionality, like external apps, the world map, GPS simulator, and others you need to uncompress (using [7-zip](https://www.7-zip.org/download.html)) the files from `mayhem_vX.Y.Z_COPY_TO_SDCARD.zip` to a FAT32 formatted MicroSD card.
|
||||
draft: true
|
||||
prerelease: false
|
||||
- name: Upload Firmware TAR Asset
|
||||
id: upload-firmware-tar-asset
|
||||
# Default device assets
|
||||
- name: Upload Default Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_OCI.ppfw.tar
|
||||
asset_path: artifacts/oci-tar-default/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hackrf_mayhem_${{ steps.version.outputs.version }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload Firmware Asset
|
||||
id: upload-firmware-asset
|
||||
- name: Upload Default Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./firmware.zip
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_FIRMWARE.zip
|
||||
asset_path: artifacts/firmware-default/firmware.zip
|
||||
asset_name: FIRMWARE_hackrf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets
|
||||
id: upload-sd-card-asset
|
||||
- name: Upload Default SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard.zip
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_COPY_TO_SDCARD.zip
|
||||
asset_path: artifacts/sdcard-default/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets - No Map
|
||||
id: upload-sd-card-asset-no-map
|
||||
- name: Upload Default SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard-no-map.zip
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_COPY_TO_SDCARD-no-world-map.zip
|
||||
asset_path: artifacts/sdcard-no-map-default/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_${{ steps.version.outputs.version }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# PortaRF device assets
|
||||
- name: Upload PortaRF Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-portarf/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_portarf_mayhem_${{ steps.version.outputs.version }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload PortaRF Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-portarf/firmware.zip
|
||||
asset_name: FIRMWARE_portarf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-portarf/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-portarf/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_${{ steps.version.outputs.version }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# HPro device assets
|
||||
- name: Upload HPro Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-hpro/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hpro_mayhem_${{ steps.version.outputs.version }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload HPro Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-hpro/firmware.zip
|
||||
asset_name: FIRMWARE_hpro_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-hpro/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-hpro/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_${{ steps.version.outputs.version }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
|
||||
+2
-1
@@ -83,4 +83,5 @@ venv/
|
||||
# generated bitmap arr file
|
||||
# TODO: generate bitmap during build, since we use python during build anyway, lemme know if this is a bad idea @zxkmm
|
||||
/firmware/tools/bitmap.hpp
|
||||
firmware/flashsize.h
|
||||
# flashsize is generated by cmake
|
||||
/firmware/flashsize.h
|
||||
|
||||
+16
-3
@@ -30,12 +30,20 @@ add_compile_options(-fdiagnostics-color=always)
|
||||
#Flash size related options
|
||||
#This is the size of the flash memory we SUPPORT. Don't worry, the internl flash app has harder limits based on device type.
|
||||
if(NOT DEFINED FLASH_MB_SIZE)
|
||||
set(FLASH_MB_SIZE 2) # Default to 2MB if not provided. For PortaRf this should be 2MB passed to cmake with -DFLASH_MB_SIZE=2
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
set(FLASH_MB_SIZE 4) # PRALINE has 4MB flash
|
||||
else()
|
||||
set(FLASH_MB_SIZE 2) # Default to 2MB if not provided. For PortaRf this should be 2MB passed to cmake with -DFLASH_MB_SIZE=2
|
||||
endif()
|
||||
endif()
|
||||
message("Configuring for FLASH_MB_SIZE=${FLASH_MB_SIZE}MB")
|
||||
#This is the flash memory size we build. This can be less, so the FW size will be less, so can be flashed with older utils.
|
||||
if(NOT DEFINED FLASH_MB_LIMIT_SIZE)
|
||||
set(FLASH_MB_LIMIT_SIZE 1) #TODO: should be ${FLASH_MB_SIZE} remove once we got a stable build for all devices we support with bigger than 1 mb flash
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
set(FLASH_MB_LIMIT_SIZE 3.5) #PRALINE 4 MB = 3.5 firmware + 0.5 MB fpga bitstream.
|
||||
else()
|
||||
set(FLASH_MB_LIMIT_SIZE 1) #TODO: should be ${FLASH_MB_SIZE} remove once we got a stable build for all devices we support with bigger than 1 mb flash
|
||||
endif()
|
||||
endif()
|
||||
message("Configuring for FLASH_MB_LIMIT_SIZE=${FLASH_MB_LIMIT_SIZE}MB")
|
||||
|
||||
@@ -44,7 +52,12 @@ if(FLASH_MB_SIZE LESS FLASH_MB_LIMIT_SIZE)
|
||||
endif()
|
||||
|
||||
math(EXPR FLASH_BYTES_SIZE "${FLASH_MB_SIZE} * 1024 * 1024")
|
||||
math(EXPR FLASH_BYTES_LIMIT_SIZE "${FLASH_MB_LIMIT_SIZE} * 1024 * 1024")
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
math(EXPR FLASH_BYTES_LIMIT_SIZE "3584 * 1024") #4 MB = 3.5 firmware + 0.5 MB fpga bitstream.
|
||||
else()
|
||||
math(EXPR FLASH_BYTES_LIMIT_SIZE "${FLASH_MB_LIMIT_SIZE} * 1024 * 1024")
|
||||
endif()
|
||||
|
||||
#generate h files
|
||||
configure_file(flashsize.h.in ${CMAKE_CURRENT_SOURCE_DIR}/firmware/flashsize.h)
|
||||
|
||||
|
||||
+5
-2
@@ -15,8 +15,11 @@
|
||||
# - Get a shell inside the build image to
|
||||
# inspect problems: ./dockerize.sh shell
|
||||
# - Give additional parameters to the container:
|
||||
# ./dockerize.sh -j10
|
||||
# ./dockerize.sh ninja -j10
|
||||
# Additional parameters to make: ./dockerize.sh -j10
|
||||
# Use ninja instead of make: ./dockerize.sh ninja -j10
|
||||
# Addotopnal CMake parameters: ./dockerize.sh -DBOARD=PRALINE
|
||||
# Change the default build directory: ./dockerize.sh -B build-alt
|
||||
# (Alternatively --workdir works as well)
|
||||
# - Use a different dockerfile:
|
||||
# ./dockerize.sh build dockerfile-other
|
||||
# - Use a different cpu architecture:
|
||||
|
||||
@@ -67,6 +67,24 @@ add_custom_target(
|
||||
DEPENDS ${FIRMWARE_FILENAME} ${HACKRF_FIRMWARE_DFU_FILENAME} ${HACKRF_FIRMWARE_FILENAME}
|
||||
)
|
||||
|
||||
# PRALINE: Append FPGA bitstream to firmware at offset 0x180000
|
||||
# The base firmware is 1MB, FPGA goes at 1MB offset, final size is 2MB
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
math(EXPR PRALINE_FINAL_SIZE "4 * 1024 * 1024")
|
||||
set(PRALINE_FPGA_BIN ${CMAKE_CURRENT_SOURCE_DIR}/../hackrf/firmware/fpga/build/praline_fpga.bin)
|
||||
set(APPEND_FPGA_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/tools/append_fpga_bitstream.py)
|
||||
add_custom_command(
|
||||
TARGET firmware POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Appending PRALINE FPGA bitstream to firmware..."
|
||||
COMMAND python3 ${APPEND_FPGA_SCRIPT} ${FIRMWARE_FILENAME} ${PRALINE_FPGA_BIN} ${FIRMWARE_FILENAME}.tmp ${PRALINE_FINAL_SIZE}
|
||||
COMMAND ${CMAKE_COMMAND} -E rename ${FIRMWARE_FILENAME}.tmp ${FIRMWARE_FILENAME}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "PRALINE firmware with FPGA bitstream created:"
|
||||
COMMAND ls -la ${FIRMWARE_FILENAME}
|
||||
COMMENT "Appending PRALINE FPGA bitstream"
|
||||
VERBATIM
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${GCC_VERSION_MISMATCH})
|
||||
set(COMPILER_MISMATCH_MESSAGE "WARNING: Compiler version mismatch, please use the official compiler version ${EXPECTED_GCC_VERSION} when sharing builds! Current compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
message(${COMPILER_MISMATCH_MESSAGE})
|
||||
|
||||
@@ -86,6 +86,9 @@ set(CPLD_20150901_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/portapack_cpld_20150901_d
|
||||
set(CPLD_20170522_SVF_PATH ${HARDWARE_PATH}/portapack_h1/cpld/20170522/output_files/portapack_h1_cpld.svf)
|
||||
set(CPLD_20170522_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/portapack_cpld_20170522_data.cpp)
|
||||
|
||||
set(CPLD_H4M_SVF_PATH ${HARDWARE_PATH}/portapack_h4m/CPLD/AG256SL100/output_files/portapack_h4m_cpld.svf)
|
||||
set(CPLD_H4M_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/portapack_cpld_h4m_data.cpp)
|
||||
|
||||
set(HACKRF_CPLD_DATA_HPP ${CMAKE_CURRENT_BINARY_DIR}/hackrf_cpld_data.hpp)
|
||||
set(HACKRF_CPLD_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/hackrf_cpld_data.cpp)
|
||||
|
||||
@@ -118,11 +121,16 @@ set(CSRC
|
||||
usb_serial_endpoints.c
|
||||
usb_serial_device_to_host.c
|
||||
i2c_device_to_host.c
|
||||
hackrf_core_mini.c
|
||||
${HACKRF_PATH}/firmware/common/adc.c
|
||||
${HACKRF_PATH}/firmware/common/usb.c
|
||||
${HACKRF_PATH}/firmware/common/usb_queue.c
|
||||
${HACKRF_PATH}/firmware/hackrf_usb/usb_device.c
|
||||
${HACKRF_PATH}/firmware/common/usb_request.c
|
||||
${HACKRF_PATH}/firmware/common/usb_standard_request.c
|
||||
${HACKRF_PATH}/firmware/libopencm3/lib/lpc43xx/scu.c
|
||||
${HACKRF_PATH}/firmware/common/gpio_lpc.c
|
||||
${HACKRF_PATH}/firmware/common/platform_detect.c
|
||||
${CHIBIOS}/os/various/chprintf.c
|
||||
)
|
||||
|
||||
@@ -205,6 +213,9 @@ set(CPPSRC
|
||||
irq_controls.cpp
|
||||
irq_lcd_frame.cpp
|
||||
irq_rtc.cpp
|
||||
keeloq_common.cpp
|
||||
keeloq_file.cpp
|
||||
keeloq_keystore.cpp
|
||||
log_file.cpp
|
||||
metadata_file.cpp
|
||||
flipper_subfile.cpp
|
||||
@@ -237,6 +248,7 @@ set(CPPSRC
|
||||
hw/encoder.cpp
|
||||
hw/max2837.cpp
|
||||
hw/max2839.cpp
|
||||
hw/max2831.cpp
|
||||
hw/max5864.cpp
|
||||
hw/rffc507x.cpp
|
||||
hw/rffc507x_spi.cpp
|
||||
@@ -246,6 +258,7 @@ set(CPPSRC
|
||||
ook_file.cpp
|
||||
ui_baseband_stats_view.cpp
|
||||
ui_navigation.cpp
|
||||
ui_notifications.cpp
|
||||
ui_record_view.cpp
|
||||
ui_sd_card_status_view.cpp
|
||||
ui/ui_alphanum.cpp
|
||||
@@ -317,6 +330,7 @@ set(CPPSRC
|
||||
config_mode.cpp
|
||||
${CPLD_20150901_DATA_CPP}
|
||||
${CPLD_20170522_DATA_CPP}
|
||||
${CPLD_H4M_DATA_CPP}
|
||||
${HACKRF_CPLD_DATA_CPP}
|
||||
ui_external_items_menu_loader.cpp
|
||||
view_factory_base.cpp
|
||||
@@ -402,7 +416,11 @@ set(CPPWARN "-Wall -Wextra -Wno-psabi")
|
||||
# List all default C defines here, like -D_DEBUG=1
|
||||
# TODO: Switch -DCRT0_INIT_DATA depending on load from RAM or SPIFI?
|
||||
# NOTE: _RANDOM_TCC to kill a GCC 4.9.3 error with std::max argument types
|
||||
set(DDEFS "-DLPC43XX -DLPC43XX_M0 -D__NEWLIB__ -DHACKRF_ONE -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -D_RANDOM_TCC=0 -D'VERSION_STRING=\"${VERSION}\"' -DVERSION_MD5=${VERSION_MD5} -D'GCC_VERSION_MISMATCH=${GCC_VERSION_MISMATCH}'")
|
||||
# Use BOARD variable if set, otherwise default to HACKRF_ONE
|
||||
if(NOT DEFINED BOARD)
|
||||
set(BOARD "HACKRF_ONE")
|
||||
endif()
|
||||
set(DDEFS "-DLPC43XX -DLPC43XX_M0 -D__NEWLIB__ -D${BOARD} -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -D_RANDOM_TCC=0 -D'VERSION_STRING=\"${VERSION}\"' -DVERSION_MD5=${VERSION_MD5} -D'GCC_VERSION_MISMATCH=${GCC_VERSION_MISMATCH}'")
|
||||
|
||||
# List all default ASM defines here, like -D_DEBUG=1
|
||||
set(DADEFS)
|
||||
@@ -460,6 +478,12 @@ add_custom_command(
|
||||
DEPENDS ${EXTRACT_CPLD_DATA} ${CPLD_20170522_SVF_PATH}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CPLD_H4M_DATA_CPP}
|
||||
COMMAND ${EXTRACT_CPLD_DATA} ${CPLD_H4M_SVF_PATH} rev_h4m >${CPLD_H4M_DATA_CPP}
|
||||
DEPENDS ${EXTRACT_CPLD_DATA} ${CPLD_H4M_SVF_PATH}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${HACKRF_CPLD_DATA_CPP}
|
||||
COMMAND ${HACKRF_CPLD_TOOL} --xsvf ${HACKRF_CPLD_XSVF_PATH} --portapack-data ${HACKRF_CPLD_DATA_CPP}
|
||||
|
||||
@@ -225,7 +225,7 @@ void BLETxView::send_packet() {
|
||||
uint8_t min = 0x00;
|
||||
uint8_t max = 0x0F;
|
||||
|
||||
hexDigit = min + std::rand() % (max - min + 1);
|
||||
hexDigit = min + rand() % (max - min + 1);
|
||||
} break;
|
||||
default:
|
||||
hexDigit = 0;
|
||||
|
||||
@@ -320,6 +320,47 @@ void ADSBRxDetailsView::update(const AircraftRecentEntry& entry) {
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::get_altitude_color(int32_t alt_ft, uint8_t* r, uint8_t* g, uint8_t* b) {
|
||||
static const struct {
|
||||
int32_t alt;
|
||||
uint8_t r, g, b;
|
||||
} stops[] = {
|
||||
{0, 220, 220, 220}, // 0 ft: White/Grey (Ground)
|
||||
{2000, 255, 255, 0}, // 2k ft: Yellow
|
||||
{10000, 0, 255, 0}, // 10k ft: Green
|
||||
{20000, 0, 255, 255}, // 20k ft: Cyan
|
||||
{30000, 60, 60, 255}, // 30k ft: Blue (Lightened for visibility on Black)
|
||||
{40000, 255, 0, 255} // 40k+ ft: Magenta
|
||||
};
|
||||
if (alt_ft <= stops[0].alt) {
|
||||
*r = stops[0].r;
|
||||
*g = stops[0].g;
|
||||
*b = stops[0].b;
|
||||
return;
|
||||
}
|
||||
const int count = sizeof(stops) / sizeof(stops[0]);
|
||||
if (alt_ft >= stops[count - 1].alt) {
|
||||
*r = stops[count - 1].r;
|
||||
*g = stops[count - 1].g;
|
||||
*b = stops[count - 1].b;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < count - 1; i++) {
|
||||
if (alt_ft < stops[i + 1].alt) {
|
||||
float t = (float)(alt_ft - stops[i].alt) / (stops[i + 1].alt - stops[i].alt);
|
||||
|
||||
*r = (uint8_t)(stops[i].r + (stops[i + 1].r - stops[i].r) * t);
|
||||
*g = (uint8_t)(stops[i].g + (stops[i + 1].g - stops[i].g) * t);
|
||||
*b = (uint8_t)(stops[i].b + (stops[i + 1].b - stops[i].b) * t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Fallback: in case no interval matched, default to ground color.
|
||||
*r = stops[0].r;
|
||||
*g = stops[0].g;
|
||||
*b = stops[0].b;
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::clear_map_markers() {
|
||||
if (geomap_view_)
|
||||
geomap_view_->clear_markers();
|
||||
@@ -335,6 +376,9 @@ bool ADSBRxDetailsView::add_map_marker(const AircraftRecentEntry& entry) {
|
||||
marker.lat = entry.pos.latitude;
|
||||
marker.angle = entry.velo.heading;
|
||||
marker.tag = get_map_tag(entry);
|
||||
uint8_t r, g, b;
|
||||
get_altitude_color(entry.pos.altitude, &r, &g, &b);
|
||||
marker.color = Color(r, g, b);
|
||||
|
||||
auto markerStored = geomap_view_->store_marker(marker);
|
||||
return markerStored == MARKER_STORED;
|
||||
@@ -651,14 +695,15 @@ void ADSBRxView::refresh_ui() {
|
||||
// Process the entries list.
|
||||
for (const auto& entry : recent) {
|
||||
// Found the entry being shown in details view. Update it.
|
||||
if (entry.key() == detail_key) {
|
||||
if (entry.key() == detail_key) { // we don't add it to the markers, since this is the currently selected and shown in the middle one. This eliminates the "shadow" marker, and saves ram
|
||||
details_view->update(entry);
|
||||
current_updated = true;
|
||||
}
|
||||
|
||||
// NB: current entry also gets a marker so it shows up if map is panned.
|
||||
if (map_needs_update && entry.pos.pos_valid && entry.state <= ADSBAgeState::Recent) {
|
||||
map_needs_update = details_view->add_map_marker(entry);
|
||||
} else {
|
||||
// Add others only
|
||||
// NB: current entry also gets a marker so it shows up if map is panned.
|
||||
if (map_needs_update && entry.pos.pos_valid && entry.state <= ADSBAgeState::Recent) {
|
||||
map_needs_update = details_view->add_map_marker(entry);
|
||||
}
|
||||
}
|
||||
|
||||
// Any work left to do?
|
||||
|
||||
@@ -270,6 +270,7 @@ class ADSBRxDetailsView : public View {
|
||||
void focus() override;
|
||||
void update(const AircraftRecentEntry& entry);
|
||||
|
||||
void get_altitude_color(int32_t alt_ft, uint8_t* r, uint8_t* g, uint8_t* b);
|
||||
/* Calls forwarded to map view if shown. */
|
||||
bool map_active() const { return geomap_view_; }
|
||||
void clear_map_markers();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -93,6 +93,10 @@ typedef enum {
|
||||
CT_SI5351,
|
||||
CT_AUDIO,
|
||||
CT_MAX17055,
|
||||
#ifdef PRALINE
|
||||
CT_FPGA,
|
||||
#endif
|
||||
CT_SGPIO,
|
||||
} chip_type_t;
|
||||
|
||||
struct RegistersWidgetConfig {
|
||||
@@ -373,6 +377,651 @@ private:
|
||||
};
|
||||
};*/
|
||||
|
||||
/* Radio Signal Path Diagnostics View
|
||||
* Shows status of each component in the RX/TX signal chain:
|
||||
* Antenna -> RF Path -> RFFC5072 -> MAX283x -> MAX5864 -> FPGA -> SGPIO -> MCU
|
||||
*/
|
||||
class RadioDiagnosticsView : public View {
|
||||
public:
|
||||
RadioDiagnosticsView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "Radio Diag"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
void update_status();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Signal Path Status ==="};
|
||||
|
||||
Text text_lbl_rffc{{0, 20, 140, 16}, "RFFC5072 (1st IF):"};
|
||||
Text text_rffc_status{{144, 20, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_max{{0, 36, 140, 16}, "MAX283x (2nd IF):"};
|
||||
Text text_max_status{{144, 36, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_adc{{0, 52, 140, 16}, "MAX5864 (ADC):"};
|
||||
Text text_adc_status{{144, 52, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga{{0, 68, 140, 16}, "FPGA/CPLD:"};
|
||||
Text text_fpga_status{{144, 68, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_sgpio{{0, 84, 140, 16}, "SGPIO:"};
|
||||
Text text_sgpio_status{{144, 84, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_clock{{0, 100, 140, 16}, "Si5351 Clocks:"};
|
||||
Text text_clock_status{{144, 100, 96, 16}, "---"};
|
||||
|
||||
Text text_regs_title{{0, 124, 240, 16}, "=== Key Registers ==="};
|
||||
|
||||
Text text_lbl_rffc_reg{{0, 144, 80, 16}, "RFFC R0:"};
|
||||
Text text_rffc_reg{{80, 144, 160, 16}, "---"};
|
||||
|
||||
Text text_lbl_max_reg{{0, 160, 80, 16}, "MAX R0:"};
|
||||
Text text_max_reg{{80, 160, 160, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_reg{{0, 176, 80, 16}, "FPGA:"};
|
||||
Text text_fpga_reg{{80, 176, 160, 16}, "---"};
|
||||
|
||||
Text text_lbl_sgpio_reg{{0, 192, 80, 16}, "SGPIO:"};
|
||||
Text text_sgpio_reg{{80, 192, 160, 16}, "---"};
|
||||
|
||||
Text text_test_result{{0, 220, 240, 32}, ""};
|
||||
|
||||
Button button_refresh{
|
||||
{8, 280, 72, 24},
|
||||
"Refresh"};
|
||||
|
||||
Button button_done{
|
||||
{168, 280, 64, 24},
|
||||
"Done"};
|
||||
};
|
||||
|
||||
/* BasebandStatusView ***************************************************/
|
||||
|
||||
class BasebandStatusView : public View {
|
||||
public:
|
||||
BasebandStatusView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "Baseband Status"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
void update();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Baseband Counters ==="};
|
||||
|
||||
Text text_lbl_marker{{0, 20, 140, 16}, "Streaming Marker:"};
|
||||
Text text_marker{{144, 20, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_loops{{0, 36, 140, 16}, "Baseband Loops:"};
|
||||
Text text_loops{{144, 36, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_wait{{0, 52, 140, 16}, "DMA Wait Count:"};
|
||||
Text text_wait{{144, 52, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_xfr{{0, 68, 140, 16}, "DMA Xfr Count:"};
|
||||
Text text_xfr{{144, 68, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_missed{{0, 84, 140, 16}, "Buffer Missed:"};
|
||||
Text text_missed{{144, 84, 96, 16}, "---"};
|
||||
|
||||
Text text_status_line1{{0, 110, 240, 16}, ""};
|
||||
Text text_status_line2{{0, 126, 240, 16}, ""};
|
||||
Text text_status_line3{{0, 142, 240, 16}, ""};
|
||||
|
||||
Button button_refresh{
|
||||
{8, 280, 72, 24},
|
||||
"Refresh"};
|
||||
|
||||
Button button_done{
|
||||
{168, 280, 64, 24},
|
||||
"Done"};
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) { this->update(); }};
|
||||
};
|
||||
|
||||
/* SGPIOLiveMonitorView ***************************************************/
|
||||
|
||||
class SGPIOLiveMonitorView : public View {
|
||||
public:
|
||||
SGPIOLiveMonitorView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "SGPIO Live"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
void update();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== SGPIO Registers ==="};
|
||||
|
||||
Text text_lbl_ctrl{{0, 20, 140, 16}, "CTRL_ENABLE:"};
|
||||
Text text_ctrl{{144, 20, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_in{{0, 36, 140, 16}, "GPIO_INREG:"};
|
||||
Text text_in{{144, 36, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_ss{{0, 52, 140, 16}, "REG_SS[0]:"};
|
||||
Text text_ss{{144, 52, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_status{{0, 68, 140, 16}, "STATUS_1:"};
|
||||
Text text_status{{144, 68, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_out{{0, 84, 140, 16}, "GPIO_OUTREG:"};
|
||||
Text text_out{{144, 84, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_oen{{0, 100, 140, 16}, "GPIO_OENREG:"};
|
||||
Text text_oen{{144, 100, 96, 16}, "---"};
|
||||
|
||||
Text text_diag_line1{{0, 126, 240, 16}, ""};
|
||||
Text text_diag_line2{{0, 142, 240, 16}, ""};
|
||||
Text text_diag_line3{{0, 158, 240, 16}, ""};
|
||||
Text text_diag_line4{{0, 174, 240, 16}, ""};
|
||||
|
||||
Button button_refresh{
|
||||
{8, 280, 72, 24},
|
||||
"Refresh"};
|
||||
|
||||
Button button_done{
|
||||
{168, 280, 64, 24},
|
||||
"Done"};
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) { this->update(); }};
|
||||
};
|
||||
|
||||
/* Radio RX Step-by-Step Test View
|
||||
* Tests radio hardware directly without M0 baseband involvement.
|
||||
* Logs each step to help isolate where the signal chain breaks.
|
||||
*/
|
||||
class RadioRxTestView : public View {
|
||||
public:
|
||||
RadioRxTestView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "RX Test"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
bool radio_initialized_{false};
|
||||
uint32_t test_frequency_{433000000}; // 433 MHz default
|
||||
|
||||
void log(const std::string& msg);
|
||||
void log_registers(const std::string& label);
|
||||
void run_init_test();
|
||||
void run_rx_mode_test();
|
||||
void run_freq_test();
|
||||
void run_sgpio_test();
|
||||
void run_full_test();
|
||||
void run_step_test();
|
||||
bool check_gpio_changing();
|
||||
|
||||
Labels labels{
|
||||
{{0, 0}, "=== Radio RX Test ===", Theme::getInstance()->fg_yellow->foreground}};
|
||||
|
||||
Console console{
|
||||
{0, 20, 240, 200}};
|
||||
|
||||
Button button_init{
|
||||
{0, 224, 56, 24},
|
||||
"Init"};
|
||||
|
||||
Button button_rx{
|
||||
{60, 224, 56, 24},
|
||||
"RX"};
|
||||
|
||||
Button button_freq{
|
||||
{120, 224, 56, 24},
|
||||
"Freq"};
|
||||
|
||||
Button button_sgpio{
|
||||
{180, 224, 56, 24},
|
||||
"SGPIO"};
|
||||
|
||||
Button button_full{
|
||||
{0, 252, 56, 24},
|
||||
"Full"};
|
||||
|
||||
Button button_step{
|
||||
{60, 252, 56, 24},
|
||||
"Step"};
|
||||
|
||||
Button button_done{
|
||||
{120, 252, 112, 24},
|
||||
"Done"};
|
||||
};
|
||||
|
||||
/* SGPIO8 Clock Detector View
|
||||
* Samples SGPIO8 pin to verify external clock is present.
|
||||
* Shows toggle count and estimated frequency.
|
||||
*/
|
||||
class SGPIO8ClockDetectorView : public View {
|
||||
public:
|
||||
SGPIO8ClockDetectorView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "SGPIO8 Clock"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
Text text_title{{8, 16, 224, 16}, "SGPIO8 Clock Detector"};
|
||||
Text text_lbl_samples{{8, 48, 160, 16}, "Samples (first 20):"};
|
||||
Text text_samples{{8, 64, 224, 16}, " "};
|
||||
Text text_lbl_toggles{{8, 96, 160, 16}, "Toggle count:"};
|
||||
Text text_toggles{{8, 112, 224, 16}, " "};
|
||||
Text text_status{{8, 144, 224, 32}, " "};
|
||||
|
||||
Button button_sample{{8, 200, 96, 24}, "Sample"};
|
||||
Button button_done{{128, 200, 96, 24}, "Done"};
|
||||
|
||||
void sample_sgpio8();
|
||||
};
|
||||
|
||||
/* Slice Status View
|
||||
* Shows SGPIO slice status: which slices are enabled vs active,
|
||||
* counter values, and data capture status.
|
||||
*/
|
||||
|
||||
/* Si5351 Debug View
|
||||
* Dedicated diagnostic tool for Si5351 clock generator.
|
||||
* Shows PLL lock status, clock configurations, and allows testing.
|
||||
*/
|
||||
class Si5351DebugView : public View {
|
||||
public:
|
||||
Si5351DebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Si5351 Clocks"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
Text text_title{{8, 16, 200, 16}, "Si5351 Clock Generator"};
|
||||
|
||||
Text text_status_label{{8, 40, 80, 16}, "Status Reg:"};
|
||||
Text text_status_value{{96, 40, 144, 16}, ""};
|
||||
|
||||
Text text_pll_a_label{{8, 60, 80, 16}, "PLL A:"};
|
||||
Text text_pll_a_status{{96, 60, 144, 16}, ""};
|
||||
|
||||
Text text_pll_b_label{{8, 80, 80, 16}, "PLL B:"};
|
||||
Text text_pll_b_status{{96, 80, 144, 16}, ""};
|
||||
|
||||
Text text_sys_init_label{{8, 100, 80, 16}, "SYS_INIT:"};
|
||||
Text text_sys_init_status{{96, 100, 144, 16}, ""};
|
||||
|
||||
Text text_xtal_cap_label{{8, 120, 80, 16}, "XTAL Cap:"};
|
||||
Text text_xtal_cap_value{{96, 120, 144, 16}, ""};
|
||||
|
||||
Text text_clkin_label{{8, 140, 72, 16}, "CLKIN:"};
|
||||
Text text_clkin_status{{88, 140, 160, 16}, ""};
|
||||
|
||||
Text text_clk0_label{{8, 160, 72, 16}, "CLK0:"};
|
||||
Text text_clk0_status{{88, 160, 152, 16}, ""};
|
||||
|
||||
Text text_clk0_freq_label{{8, 180, 72, 16}, " Freq:"};
|
||||
Text text_clk0_freq_value{{88, 180, 152, 16}, ""};
|
||||
|
||||
Text text_clk0_div_label{{8, 200, 72, 16}, " Div:"};
|
||||
Text text_clk0_div_value{{88, 200, 152, 16}, ""};
|
||||
|
||||
Text text_clk1_label{{8, 220, 96, 16}, "CLK1 (SCT):"};
|
||||
Text text_clk1_status{{112, 220, 128, 16}, ""};
|
||||
|
||||
Button button_refresh{{8, 240, 72, 24}, "Refresh"};
|
||||
Button button_reset_pll{{88, 240, 72, 24}, "Reset PLL"};
|
||||
Button button_done{{168, 240, 64, 24}, "Done"};
|
||||
|
||||
void refresh_status();
|
||||
void reset_pll();
|
||||
};
|
||||
|
||||
#ifdef PRALINE
|
||||
/* SignalPathStatusView *************************************************/
|
||||
class SignalPathStatusView : public View {
|
||||
public:
|
||||
SignalPathStatusView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Signal Path"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
void refresh_status();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Signal Path Status ==="};
|
||||
|
||||
Text text_lbl_max_enable{{0, 20, 1114, 16}, "MAX2831:"};
|
||||
Text text_max_enable{{116, 20, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_max_mode{{0, 36, 114, 16}, "RX Mode:"};
|
||||
Text text_max_mode{{116, 36, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_rf_path{{0, 52, 114, 16}, "RF Path:"};
|
||||
Text text_rf_path{{116, 52, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_filter{{0, 68, 114, 16}, "Filter Band:"};
|
||||
Text text_filter{{116, 68, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_mixer{{0, 84, 114, 16}, "Mixer Enable:"};
|
||||
Text text_mixer{{116, 84, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_rf_amp{{0, 100, 114, 16}, "RF Amp:"};
|
||||
Text text_rf_amp{{116, 100, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_lna{{0, 116, 114, 16}, "LNA Gain:"};
|
||||
Text text_lna{{116, 116, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_vga{{0, 132, 114, 16}, "VGA Gain:"};
|
||||
Text text_vga{{116, 132, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_decim{{0, 148, 114, 16}, "FPGA Decim:"};
|
||||
Text text_fpga_decim{{116, 148, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_ctrl_dc_q{{0, 164, 114, 16}, "FPGA Ctrl:"};
|
||||
Text text_fpga_ctrl_dc_q{{116, 164, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_ctrl_qs{{0, 180, 114, 16}, ""};
|
||||
Text text_fpga_ctrl_qs{{116, 180, 124, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 200, 240, 32}, ""};
|
||||
|
||||
Button button_refresh{{0, 280, 72, 24}, "Refresh"};
|
||||
Button button_toggle_q{{88, 280, 72, 24}, "Q Inv"};
|
||||
Button button_done{{176, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
class GPIODebugView : public View {
|
||||
public:
|
||||
GPIODebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "GPIO Debug"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
// GPIO4 (LPF and RF Amp)
|
||||
Text text_lbl_gpio4{{0, 0, 240, 16}, "Pin Diag: GPIO4 (LPF|Amp|Mix)"};
|
||||
|
||||
Text text_lbl_dir4{{0, 18, 114, 16}, "DIR[4]:"};
|
||||
Text text_dir4{{116, 18, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_pin4{{0, 36, 114, 16}, "PIN[4] (read):"};
|
||||
Text text_pin4{{116, 36, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_set4{{0, 54, 114, 16}, "SET[4] (write):"};
|
||||
Text text_set4{{116, 54, 124, 16}, "---"};
|
||||
|
||||
// Bit 8 (LPF)
|
||||
Text text_lbl_lpf_bit{{0, 78, 240, 16}, "Bit 8 (LPF - GPIO4[8]):"};
|
||||
Text text_lpf_dir{{0, 96, 80, 16}, "DIR: ?"};
|
||||
Text text_lpf_pin{{82, 96, 78, 16}, "PIN: ?"};
|
||||
Text text_lpf_set{{162, 96, 78, 16}, "SET: ?"};
|
||||
|
||||
Button button_lpf_toggle{{8, 114, 110, 24}, "Toggle LPF"};
|
||||
Button button_lpf_on{{122, 114, 50, 24}, "ON"};
|
||||
Button button_lpf_off{{176, 114, 50, 24}, "OFF"};
|
||||
|
||||
// Bit 9 (RF Amp)
|
||||
Text text_lbl_amp_bit{{0, 146, 240, 16}, "Bit 9 (Amp - GPIO4[9]):"};
|
||||
Text text_amp_dir{{0, 164, 80, 16}, "DIR: ?"};
|
||||
Text text_amp_pin{{82, 164, 78, 16}, "PIN: ?"};
|
||||
Text text_amp_set{{162, 164, 78, 16}, "SET: ?"};
|
||||
|
||||
Button button_amp_toggle{{8, 182, 110, 24}, "Toggle Amp"};
|
||||
Button button_amp_on{{122, 182, 50, 24}, "ON"};
|
||||
Button button_amp_off{{176, 182, 50, 24}, "OFF"};
|
||||
|
||||
// GPIO3 (Mixer)
|
||||
Text text_lbl_gpio3{{0, 214, 240, 16}, "--- GPIO3 (Mixer) ---"};
|
||||
Text text_lbl_mix_bit{{0, 232, 240, 16}, "Bit 2 (MIX - GPIO3[2]):"};
|
||||
Text text_mix_dir{{0, 250, 80, 16}, "DIR: ?"};
|
||||
Text text_mix_pin{{82, 250, 78, 16}, "PIN: ?"};
|
||||
Text text_mix_set{{162, 250, 78, 16}, "SET: ?"};
|
||||
|
||||
// Controls
|
||||
Button button_refresh{{8, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* RFFC5072StatusView *************************************************/
|
||||
class RFFC5072StatusView : public View {
|
||||
public:
|
||||
RFFC5072StatusView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "RFFC5072 Status"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
void refresh_status();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== RFFC5072 (1st IF) ==="};
|
||||
|
||||
Text text_lbl_lock{{0, 16, 114, 16}, "Lock Detect:"};
|
||||
Text text_lock{{116, 16, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_ctrl{{0, 32, 114, 16}, "Control:"};
|
||||
Text text_ctrl{{116, 32, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_enabled{{0, 48, 114, 16}, "Status:"};
|
||||
Text text_enabled{{116, 48, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_freq{{0, 64, 114, 16}, "LO Freq:"};
|
||||
Text text_freq{{116, 64, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_path{{0, 80, 114, 16}, "Path:"};
|
||||
Text text_path{{116, 80, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_mixer{{0, 96, 114, 16}, "Mixer:"};
|
||||
Text text_mixer{{116, 96, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_r0{{0, 112, 114, 16}, "Reg 0:"};
|
||||
Text text_r0{{116, 112, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_r1{{0, 128, 114, 16}, "Reg 1 (N):"};
|
||||
Text text_r1{{116, 128, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_r2{{0, 144, 114, 16}, "Reg 2:"};
|
||||
Text text_r2{{116, 144, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_n{{0, 160, 114, 16}, "N divider:"};
|
||||
Text text_n{{116, 160, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_lodiv{{0, 176, 114, 16}, "LO divider:"};
|
||||
Text text_lodiv{{116, 176, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc{{0, 192, 114, 16}, "Calc freq:"};
|
||||
Text text_calc{{116, 192, 124, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 208, 240, 16}, ""};
|
||||
|
||||
Text text_lbl_regs_status{{0, 224, 48, 16}, "Regs:"};
|
||||
Text text_regs_status{{50, 224, 190, 16}, "---"};
|
||||
|
||||
Button button_refresh{{2, 280, 56, 24}, "Rfrsh"};
|
||||
Button button_done{{182, 280, 56, 24}, "Done"};
|
||||
};
|
||||
|
||||
#ifdef PRALINE
|
||||
/* RFFCTuningDebugView *************************************************/
|
||||
class RFFCTuningDebugView : public View {
|
||||
public:
|
||||
RFFCTuningDebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "RFFC Tuning Debug"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "RFFC5072 Tuning Debug"};
|
||||
|
||||
Text text_lbl_called{{0, 18, 120, 16}, "Freq Set:"};
|
||||
Text text_called{{122, 18, 118, 16}, "NO"};
|
||||
|
||||
Text text_lbl_req{{0, 38, 120, 16}, "Requested:"};
|
||||
Text text_req{{122, 38, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_exp_n{{0, 56, 120, 16}, "Expected N:"};
|
||||
Text text_exp_n{{122, 56, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_n{{0, 74, 120, 16}, "Actual N:"};
|
||||
Text text_act_n{{122, 74, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_exp_div{{0, 92, 120, 16}, "Exp LO/Pres:"};
|
||||
Text text_exp_div{{122, 92, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_div{{0, 110, 120, 16}, "Act LO/Pres:"};
|
||||
Text text_act_div{{122, 110, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc{{0, 128, 120, 16}, "Calc LO freq:"};
|
||||
Text text_calc{{122, 128, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_lo{{0, 146, 120, 16}, "Calc input:"};
|
||||
Text text_calc_lo{{122, 146, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_vco{{0, 164, 120, 16}, "In Calc VCO:"};
|
||||
Text text_calc_vco{{122, 164, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_vco{{0, 182, 120, 16}, "Calc VCO:"};
|
||||
Text text_vco{{122, 182, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_n_q24{{0, 200, 120, 16}, "N (Q24):"};
|
||||
Text text_n_q24{{122, 200, 118, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 224, 240, 48}, ""};
|
||||
|
||||
Button button_refresh{{8, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* MAX2831DebugView *************************************************/
|
||||
|
||||
class MAX2831DebugView : public View {
|
||||
public:
|
||||
MAX2831DebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "MAX2831 Debug"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "MAX2831 (2nd IF) Debug"};
|
||||
|
||||
Text text_lbl_called{{0, 24, 120, 16}, "Freq Set:"};
|
||||
Text text_called{{122, 24, 118, 16}, "NO"};
|
||||
|
||||
Text text_lbl_valid{{0, 42, 120, 16}, "In Range:"};
|
||||
Text text_valid{{122, 42, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_req{{0, 60, 120, 16}, "Requested:"};
|
||||
Text text_req{{122, 60, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_n{{0, 78, 120, 16}, "Calc N:"};
|
||||
Text text_calc_n{{122, 78, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_frac{{0, 96, 120, 16}, "Calc Frac:"};
|
||||
Text text_calc_frac{{122, 96, 118, 16}, "---"};
|
||||
|
||||
Text text_spacer{{0, 114, 240, 16}, "--- Hardware Regs ---"};
|
||||
|
||||
Text text_lbl_r3{{0, 132, 120, 16}, "Reg 3:"};
|
||||
Text text_r3{{122, 132, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_r4{{0, 150, 120, 16}, "Reg 4:"};
|
||||
Text text_r4{{122, 150, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_n{{0, 168, 120, 16}, "Actual N:"};
|
||||
Text text_act_n{{122, 168, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_frac{{0, 186, 120, 16}, "Actual Frac:"};
|
||||
Text text_act_frac{{122, 186, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_freq{{0, 204, 120, 16}, "Calc Freq:"};
|
||||
Text text_calc_freq{{122, 204, 118, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 228, 240, 44}, ""};
|
||||
|
||||
Button button_refresh{{8, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
class SystemDiagnosticsView : public View {
|
||||
public:
|
||||
SystemDiagnosticsView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "System Diagnostics"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
void read_gpio_states();
|
||||
void set_sample_rate(uint32_t rate);
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "System Diagnostics"};
|
||||
|
||||
// Sample Rate Section
|
||||
Text text_lbl_sample{{0, 24, 42, 16}, "Rate:"};
|
||||
Text text_sample_rate{{44, 24, 50, 16}, "---"};
|
||||
Text text_lbl_fpga_decode{{96, 24, 144, 16}, "DC:? Q:? QS:?"};
|
||||
|
||||
Button button_sample_2m{{2, 44, 56, 24}, "2 MSPS"};
|
||||
Button button_sample_4m{{62, 44, 56, 24}, "4 MSPS"};
|
||||
Button button_sample_8m{{122, 44, 56, 24}, "8 MSPS"};
|
||||
Button button_sample_20m{{182, 44, 56, 24}, "20 MSPS"};
|
||||
|
||||
// Baseband Filter Section
|
||||
Text text_lbl_bb_filter{{0, 76, 114, 16}, "BB Filter BW:"};
|
||||
Text text_bb_filter{{116, 76, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_reg8{{0, 94, 114, 16}, "MAX2831 R8:"};
|
||||
Text text_reg8{{116, 94, 124, 16}, "---"};
|
||||
|
||||
// GPIO States Section
|
||||
Text text_lbl_gpio{{0, 118, 240, 16}, "--- GPIO Pin States ---"};
|
||||
|
||||
Text text_lbl_lpf{{0, 136, 56, 16}, "LPF:"};
|
||||
Text text_gpio_lpf{{58, 136, 181, 16}, "---"};
|
||||
|
||||
Text text_lbl_mix{{0, 154, 56, 16}, "Mixer:"};
|
||||
Text text_gpio_mix{{58, 154, 181, 16}, "---"};
|
||||
|
||||
Text text_lbl_amp{{0, 172, 56, 16}, "RF Amp:"};
|
||||
Text text_gpio_amp{{58, 172, 181, 16}, "---"};
|
||||
|
||||
// FPGA Control Section
|
||||
Text text_lbl_fpga{{0, 196, 240, 16}, "--- FPGA Control ---"};
|
||||
|
||||
Text text_lbl_fpga_ctrl{{0, 214, 114, 16}, "FPGA Reg 1:"};
|
||||
Text text_fpga_ctrl{{116, 214, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_band{{0, 232, 48, 16}, "Band:"};
|
||||
Text text_band{{50, 232, 190, 16}, "---"};
|
||||
|
||||
Button button_toggle_q{{2, 252, 110, 24}, "Toggle Q Inv"};
|
||||
Button button_toggle_dc{{122, 252, 110, 24}, "Toggle DC Blk"};
|
||||
|
||||
// Control Buttons
|
||||
Button button_refresh{{2, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
class DebugPeripheralsMenuView : public BtnGridView {
|
||||
public:
|
||||
DebugPeripheralsMenuView(NavigationView& nav);
|
||||
|
||||
@@ -46,11 +46,10 @@ bool valid_firmware_file(std::filesystem::path::string_type path) {
|
||||
auto result = firmware_file.open(path.c_str());
|
||||
if (!result.is_valid()) {
|
||||
uint64_t file_size = firmware_file.size();
|
||||
if (portapack::device_type == portapack::DeviceType::DEV_PORTAPACK && file_size > 1 * 1024 * 1024) {
|
||||
// Portapack firmware files must not be larger than 1MB
|
||||
if (file_size > FLASH_ROM_SIZE) {
|
||||
// Firmware file is larger than the flash size for this device
|
||||
return false;
|
||||
}
|
||||
// May need to add a check to portarf and portarf pro too.
|
||||
checksum = 0;
|
||||
for (uint64_t offset = 0; offset < FLASH_ROM_SIZE && offset < file_size; offset += sizeof(read_buffer)) {
|
||||
auto readResult = firmware_file.read(&read_buffer, sizeof(read_buffer));
|
||||
|
||||
@@ -350,6 +350,12 @@ MicTXView::MicTXView(
|
||||
&tx_button,
|
||||
&tx_icon});
|
||||
|
||||
// disable key repeat on select
|
||||
initial_switch_config_ = get_switches_repeat_config();
|
||||
SwitchesState config = initial_switch_config_;
|
||||
config[toUType(Switch::Sel)] = false;
|
||||
set_switches_repeat_config(config);
|
||||
|
||||
set_rxbw_options();
|
||||
set_rxbw_defaults(settings_.loaded());
|
||||
|
||||
@@ -640,6 +646,9 @@ MicTXView::MicTXView(
|
||||
}
|
||||
|
||||
MicTXView::~MicTXView() {
|
||||
// restore select key repeat mode
|
||||
set_switches_repeat_config(initial_switch_config_);
|
||||
|
||||
audio::input::stop();
|
||||
if (rx_enabled) { // Also turn off both (audio rx if enabled, and disable mic_loop to HP)
|
||||
rxaudio(false);
|
||||
|
||||
@@ -90,6 +90,9 @@ class MicTXView : public View {
|
||||
sampling_rate /* sampling rate */
|
||||
};
|
||||
|
||||
// structure used to control key repeat
|
||||
SwitchesState initial_switch_config_{};
|
||||
|
||||
enum Mic_Modulation : uint32_t {
|
||||
MIC_MOD_NFM = 0,
|
||||
MIC_MOD_WFM = 1,
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "ui_touch_calibration.hpp"
|
||||
#include "ui_text_editor.hpp"
|
||||
#include "ui_external_items_menu_loader.hpp"
|
||||
#include "ui_ss_viewer.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
@@ -348,7 +350,6 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
add_children({&checkbox_disable_touchscreen,
|
||||
&checkbox_bloff,
|
||||
&options_bloff,
|
||||
&checkbox_showsplash,
|
||||
&checkbox_showclock,
|
||||
&options_clockformat,
|
||||
&checkbox_guireturnflag,
|
||||
@@ -375,7 +376,6 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
}
|
||||
|
||||
checkbox_disable_touchscreen.set_value(pmem::disable_touchscreen());
|
||||
checkbox_showsplash.set_value(pmem::config_splash());
|
||||
checkbox_showclock.set_value(!pmem::hide_clock());
|
||||
checkbox_guireturnflag.set_value(pmem::show_gui_return_icon());
|
||||
|
||||
@@ -414,7 +414,6 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
pmem::set_clock_with_date(false);
|
||||
}
|
||||
|
||||
pmem::set_config_splash(checkbox_showsplash.value());
|
||||
pmem::set_clock_hidden(!checkbox_showclock.value());
|
||||
pmem::set_gui_return_icon(checkbox_guireturnflag.value());
|
||||
pmem::set_disable_touchscreen(checkbox_disable_touchscreen.value());
|
||||
@@ -1113,6 +1112,46 @@ void SetBatteryView::focus() {
|
||||
button_cancel.focus();
|
||||
}
|
||||
|
||||
/* SetSlpash *********************************************/
|
||||
|
||||
SetSplash::SetSplash(NavigationView& nav) {
|
||||
add_children({&checkbox_showsplash,
|
||||
&checkbox_randomsplash,
|
||||
&message,
|
||||
&button_picture_select,
|
||||
&button_save,
|
||||
&button_cancel});
|
||||
|
||||
checkbox_showsplash.set_value(pmem::config_splash());
|
||||
splash_bmp_exists = file_exists(splash_dot_bmp);
|
||||
checkbox_randomsplash.set_value(!splash_bmp_exists);
|
||||
message.hidden(splash_bmp_exists);
|
||||
|
||||
checkbox_randomsplash.on_select = [this](Checkbox&, bool v) {
|
||||
random_enabled = v;
|
||||
};
|
||||
|
||||
button_picture_select.on_select = [this, &nav](Button&) {
|
||||
auto ret = nav.push<FileManagerView>();
|
||||
ret->push_dir(splash_dir);
|
||||
};
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
if (random_enabled == true) delete_file(splash_dot_bmp);
|
||||
pmem::set_config_splash(checkbox_showsplash.value());
|
||||
send_system_refresh();
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
button_cancel.on_select = [&nav, this](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void SetSplash::focus() {
|
||||
button_save.focus();
|
||||
}
|
||||
|
||||
/* SettingsMenuView **************************************/
|
||||
|
||||
SettingsMenuView::SettingsMenuView(NavigationView& nav)
|
||||
@@ -1146,6 +1185,7 @@ void SettingsMenuView::on_populate() {
|
||||
{"Display", ui::Color::dark_cyan(), &bitmap_icon_brightness, [this]() { nav_.push<SetDisplayView>(); }},
|
||||
{"Menu Color", ui::Color::dark_cyan(), &bitmap_icon_brightness, [this]() { nav_.push<SetMenuColorView>(); }},
|
||||
{"Theme", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetThemeView>(); }},
|
||||
{"Splash settings", ui::Color::dark_cyan(), &bitmap_icon_file_image, [this]() { nav_.push<SetSplash>(); }},
|
||||
});
|
||||
|
||||
if (battery::BatteryManagement::isDetected()) add_item({"Battery", ui::Color::dark_cyan(), &bitmap_icon_batt_icon, [this]() { nav_.push<SetBatteryView>(); }});
|
||||
|
||||
@@ -343,77 +343,72 @@ class SetUIView : public View {
|
||||
{"1 hour", backlight_timeout_t::Timeout3600Sec},
|
||||
}};
|
||||
|
||||
Checkbox checkbox_showsplash{
|
||||
{3 * 8, 6 * 16},
|
||||
20,
|
||||
"Show splash"};
|
||||
|
||||
Checkbox checkbox_showclock{
|
||||
{3 * 8, 8 * 16},
|
||||
{3 * 8, 6 * 16},
|
||||
20,
|
||||
"Show clock with:"};
|
||||
|
||||
OptionsField options_clockformat{
|
||||
{60, 9 * 16 + 8},
|
||||
{60, 7 * 16 + 8},
|
||||
20,
|
||||
{{"time only", 0},
|
||||
{"time and date", 1}}};
|
||||
|
||||
Checkbox checkbox_guireturnflag{
|
||||
{3 * 8, 11 * 16},
|
||||
{3 * 8, 9 * 16},
|
||||
20,
|
||||
"Back button in menu"};
|
||||
|
||||
Labels labels{
|
||||
{{3 * 8, 13 * 16}, "Show/Hide Status Icons", Theme::getInstance()->fg_light->foreground},
|
||||
{{3 * 8, 11 * 16}, "Show/Hide Status Icons", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
ImageToggle toggle_camera{
|
||||
{2 * 8, 14 * 16 + 2, 16, 16},
|
||||
{2 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_camera};
|
||||
|
||||
ImageToggle toggle_sleep{
|
||||
{4 * 8, 14 * 16 + 2, 16, 16},
|
||||
{4 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_sleep};
|
||||
|
||||
ImageToggle toggle_stealth{
|
||||
{6 * 8, 14 * 16 + 2, 16, 16},
|
||||
{6 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_stealth};
|
||||
|
||||
ImageToggle toggle_converter{
|
||||
{8 * 8, 14 * 16 + 2, 16, 16},
|
||||
{8 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_upconvert};
|
||||
|
||||
ImageToggle toggle_bias_tee{
|
||||
{10 * 8, 14 * 16 + 2, 16, 16},
|
||||
{10 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_biast_off};
|
||||
|
||||
ImageToggle toggle_clock{
|
||||
{12 * 8, 14 * 16 + 2, 8, 16},
|
||||
{12 * 8, 12 * 16 + 2, 8, 16},
|
||||
&bitmap_icon_clk_ext};
|
||||
|
||||
ImageToggle toggle_mute{
|
||||
{13 * 8, 14 * 16 + 2, 16, 16},
|
||||
{13 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_speaker_and_headphones_mute};
|
||||
|
||||
ImageToggle toggle_speaker{
|
||||
{15 * 8, 14 * 16 + 2, 16, 16},
|
||||
{15 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_speaker_mute};
|
||||
|
||||
ImageToggle toggle_battery_icon{
|
||||
{17 * 8, 14 * 16 + 2, 16, 16},
|
||||
{17 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_batt_icon};
|
||||
|
||||
ImageToggle toggle_battery_text{
|
||||
{19 * 8, 14 * 16 + 2, 16, 16},
|
||||
{19 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_batt_text};
|
||||
|
||||
ImageToggle toggle_fake_brightness{
|
||||
{21 * 8, 14 * 16 + 2, 16, 16},
|
||||
{21 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_brightness};
|
||||
|
||||
ImageToggle toggle_sd_card{
|
||||
{23 * 8, 14 * 16 + 2, 16, 16},
|
||||
{23 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_sd_card_ok};
|
||||
|
||||
Button button_save{
|
||||
@@ -1069,6 +1064,43 @@ class SettingsMenuView : public BtnGridView {
|
||||
void on_populate() override;
|
||||
};
|
||||
|
||||
class SetSplash : public View {
|
||||
public:
|
||||
SetSplash(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Splash"; };
|
||||
|
||||
private:
|
||||
bool splash_bmp_exists = false;
|
||||
bool random_enabled = false;
|
||||
|
||||
Checkbox checkbox_showsplash{
|
||||
{3 * 8, 1 * 16},
|
||||
20,
|
||||
"Show splash"};
|
||||
|
||||
Checkbox checkbox_randomsplash{
|
||||
{3 * 8, 3 * 16},
|
||||
20,
|
||||
"Random splash on boot"};
|
||||
|
||||
Text message{{UI_POS_X(1), UI_POS_Y(6), UI_POS_WIDTH(26), UI_POS_HEIGHT(1)}, "Pick image to stop random."};
|
||||
|
||||
Button button_picture_select{
|
||||
{UI_POS_X_CENTER(8) - UI_POS_WIDTH(4), UI_POS_Y_BOTTOM(7), UI_POS_WIDTH(13), UI_POS_HEIGHT(2)},
|
||||
"Select pict."};
|
||||
|
||||
Button button_save{
|
||||
{UI_POS_X_CENTER(12) - UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
"Save"};
|
||||
|
||||
Button button_cancel{
|
||||
{UI_POS_X_CENTER(16) + UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
"Cancel"};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif /*__UI_SETTINGS_H__*/
|
||||
|
||||
@@ -27,8 +27,6 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace ui {
|
||||
|
||||
const std::filesystem::path splash_dot_bmp{u"/splash.bmp"};
|
||||
|
||||
ScreenshotViewer::ScreenshotViewer(
|
||||
NavigationView& nav,
|
||||
const std::filesystem::path& path)
|
||||
@@ -44,7 +42,6 @@ bool ScreenshotViewer::on_key(KeyEvent) {
|
||||
|
||||
void ScreenshotViewer::paint(Painter& painter) {
|
||||
File file{};
|
||||
|
||||
painter.fill_rectangle({0, 0, screen_width, screen_height}, Color::black());
|
||||
|
||||
auto show_invalid = [&]() {
|
||||
|
||||
@@ -28,11 +28,10 @@
|
||||
#include "ui_painter.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "file.hpp"
|
||||
#include "file_path.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
extern const std::filesystem::path splash_dot_bmp;
|
||||
|
||||
class ScreenshotViewer : public View {
|
||||
public:
|
||||
ScreenshotViewer(NavigationView& nav, const std::filesystem::path& path);
|
||||
@@ -49,7 +48,6 @@ class SplashViewer : public View {
|
||||
SplashViewer(NavigationView& nav, const std::filesystem::path& path);
|
||||
bool on_key(KeyEvent key) override;
|
||||
void paint(Painter& painter) override;
|
||||
void update_ss(void);
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "ui_textentry.hpp"
|
||||
#include "../keeloq_keystore.hpp"
|
||||
#include "../keeloq_file.hpp"
|
||||
#include "../keeloq_common.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
@@ -56,6 +60,51 @@ void SubGhzDRecentEntryDetailView::update_data() {
|
||||
if (cnt != SD_NO_CNT) console.writeln("Cnt: " + to_string_dec_uint(cnt));
|
||||
|
||||
if (entry_.data != 0) console.writeln("Data: " + to_string_hex(entry_.data));
|
||||
|
||||
if (entry_.sensorType == FPS_RESTAURANT_PAGER) {
|
||||
uint8_t pager_addr = (entry_.data >> 5) & 0x0F;
|
||||
uint8_t func_code = (entry_.data >> 1) & 0x0F;
|
||||
console.writeln("Station: 0x" + to_string_hex(serial) + " (" + to_string_dec_uint(serial) + ")");
|
||||
console.writeln("Pager: " + to_string_dec_uint(pager_addr));
|
||||
if (func_code == 0x0D)
|
||||
console.writeln("Action: Buzz");
|
||||
else if (func_code == 0x0F)
|
||||
console.writeln("Action: Sync");
|
||||
else
|
||||
console.writeln("Action: 0x" + to_string_hex(func_code));
|
||||
}
|
||||
|
||||
if (entry_.sensorType == FPS_KEELOQ) {
|
||||
console.writeln("Fix: " + to_string_hex(fix));
|
||||
console.writeln("Encrypted: " + to_string_hex(encrypted));
|
||||
console.writeln("Manufacturer: " + mf_name);
|
||||
|
||||
if (hop != SD_NO_HOP) {
|
||||
console.writeln("Hop: " + to_string_hex(hop));
|
||||
|
||||
add_children({&button_save});
|
||||
|
||||
button_save.on_select = [this](const Button&) {
|
||||
keeloq_file_buffer.clear();
|
||||
|
||||
text_prompt(
|
||||
nav_,
|
||||
keeloq_file_buffer,
|
||||
64,
|
||||
ENTER_KEYBOARD_MODE_ALPHA,
|
||||
[this](std::string& buffer) {
|
||||
KeeloqData params{
|
||||
mf_name,
|
||||
serial,
|
||||
(uint16_t)cnt,
|
||||
btn};
|
||||
|
||||
ensure_directory(keeloq_remotes_dir);
|
||||
write_keeloq_file(keeloq_remotes_dir / buffer + ".KEELOQ", params);
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SubGhzDRecentEntryDetailView::SubGhzDRecentEntryDetailView(NavigationView& nav, const SubGhzDRecentEntry& entry)
|
||||
@@ -244,6 +293,8 @@ const char* SubGhzDView::getSensorTypeName(FPROTO_SUBGHZD_SENSOR type) {
|
||||
return "Marantec24";
|
||||
case FPS_HOLTEKHT6P20B:
|
||||
return "Holtek HT6P20B";
|
||||
case FPS_RESTAURANT_PAGER:
|
||||
return "Rest. Pager";
|
||||
case FPS_Invalid:
|
||||
default:
|
||||
return "Unknown";
|
||||
@@ -270,7 +321,14 @@ void RecentEntriesTable<ui::SubGhzDRecentEntries>::draw(
|
||||
line.reserve(30);
|
||||
|
||||
line = SubGhzDView::getSensorTypeName((FPROTO_SUBGHZD_SENSOR)entry.sensorType);
|
||||
line = line + " " + to_string_hex(entry.data << 32);
|
||||
if (entry.sensorType == FPS_RESTAURANT_PAGER) {
|
||||
uint8_t pgr = (entry.data >> 5) & 0x0F;
|
||||
uint8_t func = (entry.data >> 1) & 0x0F;
|
||||
line += " P:" + to_string_dec_uint(pgr) + (func == 0x0D ? " Buzz" : func == 0x0F ? " Sync"
|
||||
: "");
|
||||
} else {
|
||||
line = line + " " + to_string_hex(entry.data << 32);
|
||||
}
|
||||
line.resize(columns.at(0).second, ' ');
|
||||
std::string ageStr = to_string_dec_uint(entry.age);
|
||||
std::string bitsStr = to_string_dec_uint(entry.bits);
|
||||
@@ -303,6 +361,29 @@ void atomo_decrypt(uint8_t* buff) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SubGhzDRecentEntryDetailView::keeloq_check_decrypt(uint32_t decrypt) {
|
||||
uint16_t end_serial = serial & 0xFF;
|
||||
|
||||
if ((decrypt >> 28 == btn) && (((((uint16_t)(decrypt >> 16)) & 0xFF) == end_serial) ||
|
||||
((((uint16_t)(decrypt >> 16)) & 0xFF) == 0))) {
|
||||
cnt = decrypt & 0xFFFF;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SubGhzDRecentEntryDetailView::keeloq_check_decrypt_centurion(uint32_t decrypt) {
|
||||
if ((decrypt >> 28 == btn) && ((((uint16_t)(decrypt >> 16)) & 0x3FF) == 0x1CE)) {
|
||||
cnt = decrypt & 0xFFFF;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint32_t came_twee_magic_numbers_xor[15] = {
|
||||
0x0E0E0E00,
|
||||
0x1D1D1D11,
|
||||
@@ -591,7 +672,57 @@ void SubGhzDRecentEntryDetailView::parseProtocol() {
|
||||
}
|
||||
|
||||
if (entry_.sensorType == FPS_KEELOQ) {
|
||||
// too many sub protocol versions, skipping. maybe in future when we'll have much more fw space
|
||||
uint64_t data_rev = FProtoGeneral::subghz_protocol_blocks_reverse_key(entry_.data, 64);
|
||||
|
||||
btn = data_rev >> 60;
|
||||
serial = (data_rev >> 32) & 0xFFFFFFF;
|
||||
fix = data_rev >> 32;
|
||||
encrypted = data_rev & 0xFFFFFFFF;
|
||||
|
||||
KeeloqKeystore keystore{};
|
||||
|
||||
const auto& keys = keystore.get_keys();
|
||||
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& key : keys) {
|
||||
switch (key.type) {
|
||||
case KEELOQ_SIMPLE_LEARNING: {
|
||||
uint32_t decrypted = keeloq_decrypt(encrypted, key.key);
|
||||
|
||||
if (keeloq_check_decrypt(decrypted)) {
|
||||
mf_name = key.mf_name;
|
||||
hop = decrypted;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case KEELOQ_NORMAL_LEARNING: {
|
||||
uint64_t man = keeloq_normal_learning(fix, key.key);
|
||||
uint32_t decrypted = keeloq_decrypt(encrypted, man);
|
||||
|
||||
if (key.mf_name == "Centurion" && keeloq_check_decrypt_centurion(decrypted)) {
|
||||
mf_name = "Centurion";
|
||||
hop = decrypted;
|
||||
|
||||
return;
|
||||
} else if (keeloq_check_decrypt(decrypted)) {
|
||||
mf_name = key.mf_name;
|
||||
hop = decrypted;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -764,5 +895,12 @@ void SubGhzDRecentEntryDetailView::parseProtocol() {
|
||||
btn = (entry_.data >> 4) & 0xF;
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry_.sensorType == FPS_RESTAURANT_PAGER) {
|
||||
// 25-bit EV1527-variant: [sysid:16][pager:4][func:4][stop:1]
|
||||
serial = (entry_.data >> 9) & 0xFFFF; // System ID
|
||||
// btn/cnt left as SD_NO values; friendly output in update_data()
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace ui
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
|
||||
#define SD_NO_SERIAL 0xFFFFFFFF
|
||||
#define SD_NO_BTN 0xFF
|
||||
#define SD_NO_CNT 0xFF
|
||||
#define SD_NO_CNT 0xFFFFFFFF
|
||||
|
||||
#define SD_NO_HOP 0xFFFFFFFF
|
||||
#define SD_NO_FIX 0xFFFFFFFF
|
||||
#define SD_NO_ENCRYPTED 0xFFFFFFFF
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
@@ -191,6 +195,19 @@ class SubGhzDRecentEntryDetailView : public View {
|
||||
uint32_t cnt = SD_NO_CNT;
|
||||
uint32_t seed = 0;
|
||||
|
||||
// keeloq specific
|
||||
std::string keeloq_file_buffer{};
|
||||
|
||||
uint32_t hop = SD_NO_HOP;
|
||||
uint32_t fix = SD_NO_FIX;
|
||||
uint32_t encrypted = SD_NO_ENCRYPTED;
|
||||
|
||||
std::string mf_name = "Unknown";
|
||||
|
||||
bool keeloq_check_decrypt(uint32_t decrypt);
|
||||
bool keeloq_check_decrypt_centurion(uint32_t decrypt);
|
||||
// end keeloq specific
|
||||
|
||||
Text text_type{{UI_POS_X(0), 1 * 16, 15 * 8, 16}, "?"};
|
||||
Text text_id{{6 * 8, 2 * 16, 10 * 8, 16}, "?"};
|
||||
|
||||
@@ -207,6 +224,10 @@ class SubGhzDRecentEntryDetailView : public View {
|
||||
{screen_width - 96 - 4, screen_height - 32 - 12, 96, 32},
|
||||
"Done"};
|
||||
|
||||
Button button_save{
|
||||
{4, screen_height - 32 - 12, 96, 32},
|
||||
"Save"};
|
||||
|
||||
void parseProtocol();
|
||||
};
|
||||
|
||||
|
||||
@@ -52,12 +52,21 @@ static void send_message(const Message* const message) {
|
||||
creg::m0apptxevent::assert_event();
|
||||
|
||||
if constexpr (check_for_message_hang) {
|
||||
#ifdef PRALINE
|
||||
/* Timeout: ~3 seconds at typical clock speeds */
|
||||
auto count = 200'000'000u;
|
||||
#else
|
||||
auto count = UINT32_MAX;
|
||||
#endif
|
||||
while (shared_memory.baseband_message && --count)
|
||||
/* spin */;
|
||||
|
||||
if (count == 0)
|
||||
#ifdef PRALINE
|
||||
chDbgPanic("BB Msg Timeout");
|
||||
#else
|
||||
chDbgPanic("Baseband Send Fail");
|
||||
#endif
|
||||
} else {
|
||||
while (shared_memory.baseband_message)
|
||||
/* spin */;
|
||||
@@ -383,6 +392,26 @@ void set_morsetx_key(bool key_down) {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_bitstream_config(uint32_t deviation, uint8_t mode) {
|
||||
const StreamTXConfigurationMessage message{deviation, mode};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_rtty_config(uint16_t baud, uint16_t shift, uint8_t* payload, uint16_t payload_length) {
|
||||
RTTYDataMessage message{baud, shift};
|
||||
if (payload && payload_length > 0) {
|
||||
message.data_len = payload_length > message.max_len ? message.max_len : payload_length;
|
||||
for (size_t i = 0; i < message.data_len; ++i) {
|
||||
message.data[i] = payload[i];
|
||||
}
|
||||
}
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_rtty_config(RTTYDataMessage& message) {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
static bool baseband_image_running = false;
|
||||
|
||||
void run_image(const spi_flash::image_tag_t image_tag) {
|
||||
@@ -444,7 +473,12 @@ void shutdown() {
|
||||
send_message(&message);
|
||||
|
||||
shared_memory.application_queue.reset();
|
||||
|
||||
// Allow time for the shutdown message to be processed and for the baseband
|
||||
// core to stop before starting another image. Otherwise, the M4 may still be
|
||||
// running and cause a crash when the next image is started.
|
||||
#ifdef PRALINE
|
||||
chThdSleepMilliseconds(20);
|
||||
#endif
|
||||
baseband_image_running = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,9 @@ void set_morsetx_key(bool key_down);
|
||||
void set_wefax_config(uint8_t lpm, uint8_t ioc);
|
||||
void set_noaaapt_config();
|
||||
void set_flex_config();
|
||||
void set_bitstream_config(uint32_t deviation, uint8_t mode); // mode 0 for am, 1 for 2fsk
|
||||
void set_rtty_config(uint16_t baud, uint16_t shift, uint8_t* payload = nullptr, uint16_t payload_length = 0); // baud*100
|
||||
void set_rtty_config(RTTYDataMessage& message);
|
||||
|
||||
void request_roger_beep();
|
||||
void request_rssi_beep();
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "portapack_io.hpp"
|
||||
#include "portapack.hpp"
|
||||
|
||||
#include "hackrf_hal.hpp"
|
||||
using namespace hackrf::one;
|
||||
@@ -30,6 +31,14 @@ using namespace hackrf::one;
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
#ifdef PRALINE
|
||||
extern "C" {
|
||||
#include "fpga_bridge.h"
|
||||
}
|
||||
// Need access to ssp1_arbiter from radio namespace
|
||||
#include "radio.hpp"
|
||||
#endif
|
||||
|
||||
constexpr uint32_t si5351_vco_f = 800000000;
|
||||
|
||||
constexpr si5351::Inputs si5351_inputs{
|
||||
@@ -54,6 +63,12 @@ constexpr si5351::PLL si5351_pll_xtal_25m{
|
||||
.c = 1,
|
||||
};
|
||||
constexpr auto si5351_pll_a_xtal_reg = si5351_pll_xtal_25m.reg(0);
|
||||
#ifdef PRALINE
|
||||
static_assert(si5351_pll_xtal_25m.f_vco() == si5351_vco_f, "PLL XTAL frequency wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p1() == 3584, "PLL XTAL P1 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p2() == 0, "PLL XTAL P2 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p3() == 1, "PLL XTAL P3 wrong");
|
||||
#endif
|
||||
|
||||
constexpr si5351::PLL si5351_pll_clkin_10m{
|
||||
.f_in = si5351_inputs.f_clkin_out(),
|
||||
@@ -64,10 +79,12 @@ constexpr si5351::PLL si5351_pll_clkin_10m{
|
||||
constexpr auto si5351c_pll_b_clkin_reg = si5351_pll_clkin_10m.reg(1);
|
||||
constexpr auto si5351a_pll_a_clkin_reg = si5351_pll_clkin_10m.reg(0);
|
||||
|
||||
#ifndef PRALINE
|
||||
static_assert(si5351_pll_xtal_25m.f_vco() == si5351_vco_f, "PLL XTAL frequency wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p1() == 3584, "PLL XTAL P1 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p2() == 0, "PLL XTAL P2 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p3() == 1, "PLL XTAL P3 wrong");
|
||||
#endif
|
||||
|
||||
static_assert(si5351_pll_clkin_10m.f_vco() == si5351_vco_f, "PLL CLKIN frequency wrong");
|
||||
static_assert(si5351_pll_clkin_10m.p1() == 9728, "PLL CLKIN P1 wrong");
|
||||
@@ -101,6 +118,22 @@ constexpr si5351::MultisynthFractional si5351_ms_0_8m{
|
||||
};
|
||||
constexpr auto si5351c_ms_0_8m_reg = si5351_ms_0_8m.reg(clock_generator_output_og_codec);
|
||||
|
||||
#ifdef PRALINE
|
||||
// Verify compile-time values for 8 MHz config
|
||||
static_assert(si5351_ms_0_8m.p1() == 5888, "MS0 8MHz P1 should be 5888 (0x1700)");
|
||||
static_assert(si5351_ms_0_8m.p2() == 0, "MS0 8MHz P2 should be 0");
|
||||
static_assert(si5351_ms_0_8m.p3() == 1, "MS0 8MHz P3 should be 1");
|
||||
static_assert(si5351_ms_0_8m.f_out() == 8000000, "MS0 should output 8 MHz");
|
||||
|
||||
// Verify register array encoding
|
||||
static_assert(si5351c_ms_0_8m_reg[0] == 42, "MS0 base register should be 42");
|
||||
static_assert(si5351c_ms_0_8m_reg[1] == 0x00, "MS0 reg43 P3[15:8] should be 0x00");
|
||||
static_assert(si5351c_ms_0_8m_reg[2] == 0x01, "MS0 reg44 P3[7:0] should be 0x01");
|
||||
static_assert(si5351c_ms_0_8m_reg[3] == 0x10, "MS0 reg45 R_DIV should be 0x10");
|
||||
static_assert(si5351c_ms_0_8m_reg[4] == 0x17, "MS0 reg46 P1[15:8] should be 0x17");
|
||||
static_assert(si5351c_ms_0_8m_reg[5] == 0x00, "MS0 reg47 P1[7:0] should be 0x00");
|
||||
#endif
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_group{
|
||||
.f_src = si5351_vco_f,
|
||||
.a = 80, /* Don't care */
|
||||
@@ -204,7 +237,11 @@ constexpr ClockControls si5351c_clock_control_common{{
|
||||
}};
|
||||
|
||||
constexpr ClockControls si5351a_clock_control_common{{
|
||||
#ifndef PRALINE
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
#else
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off}, // CLK0: MUST be Fractional for 8 MHz!
|
||||
#endif
|
||||
{ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off},
|
||||
{ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
{ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
@@ -255,9 +292,48 @@ static void portapack_tcxo_disable() {
|
||||
using namespace hackrf::one;
|
||||
|
||||
void ClockManager::init_clock_generator() {
|
||||
#ifdef PRALINE
|
||||
// PRALINE: Configure clock input mux GPIO
|
||||
// GPIO0_15 (clkin_ctrl) selects GP_CLKIN source:
|
||||
// 0 = P1 connector (external)
|
||||
// 1 = P22 (internal Si5351 CLK2)
|
||||
constexpr GPIO gpio_clkin_ctrl = gpio[GPIO0_15];
|
||||
gpio_clkin_ctrl.output();
|
||||
gpio_clkin_ctrl.write(1); // CLKIN_SIGNAL_P22 = 1 = internal Si5351 CLK2
|
||||
|
||||
// Also enable MCU clock gate (GPIO0_8)
|
||||
gpio_r9_mcu_clk_en.output();
|
||||
gpio_r9_mcu_clk_en.write(1);
|
||||
#else
|
||||
// HackRF One r9: GPIO0_8 (mcu_clk_en) gates Si5351 CLK2/CLK7 to GP_CLKIN
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_mcu_clk_en.output();
|
||||
gpio_r9_mcu_clk_en.write(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
clock_generator.reset();
|
||||
clock_generator.set_crystal_internal_load_capacitance(CrystalInternalLoadCapacitance::XTAL_CL_8pF);
|
||||
clock_generator.enable_fanout();
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE has Si5351A (NOT Si5351C like HackRF One OG).
|
||||
* Must use Si5351A configuration: PLLA only, no CLKIN support.
|
||||
*
|
||||
* IMPORTANT: Follow HackRF reference sequence:
|
||||
* 1. Set PLL input sources
|
||||
* 2. Configure PLL and multisynths
|
||||
* 3. Set clock control registers (AFTER multisynths!)
|
||||
* 4. Reset PLLs
|
||||
* 5. Enable outputs
|
||||
*/
|
||||
clock_generator.set_pll_input_sources(si5351a_pll_input_sources);
|
||||
|
||||
/* Skip MCU CLKIN setup and reference detection for PRALINE - not applicable */
|
||||
reference = Reference{ReferenceSource::Xtal, 0};
|
||||
|
||||
/* Clock control will be set AFTER multisynth configuration - see below */
|
||||
#else
|
||||
clock_generator.set_pll_input_sources(hackrf_r9
|
||||
? si5351a_pll_input_sources
|
||||
: si5351c_pll_input_sources);
|
||||
@@ -298,7 +374,62 @@ void ClockManager::init_clock_generator() {
|
||||
si5351_clock_control_common[7].ms_src(ref_pll),
|
||||
}};
|
||||
clock_generator.set_clock_control(si5351_clock_control);
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses Si5351A with:
|
||||
* CLK0 = AFE_CLK (codec/FPGA sample clock)
|
||||
* CLK1 = SCT_CLK (FPGA timing clock at 2x sample rate)
|
||||
* CLK4 = first IF (RFFC5072)
|
||||
* CLK5 = second IF (MAX2831)
|
||||
* Uses PLLA on XTAL only (no CLKIN support).
|
||||
*/
|
||||
|
||||
/* Step 1: Write PLL A configuration (800 MHz VCO from 25 MHz XTAL) */
|
||||
/* Use single-byte writes to debug I2C issues */
|
||||
{
|
||||
const auto& pll_regs = si5351_pll_a_xtal_reg;
|
||||
const uint8_t base_reg = pll_regs[0];
|
||||
for (size_t i = 1; i < pll_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, pll_regs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 2: Write multisynth configurations using single-byte writes */
|
||||
clock_generator.write_ms_single_byte(0, si5351_ms_0_8m); // MS0 = divider 50, r_div=1 for 8 MHz
|
||||
clock_generator.write_ms_single_byte(1, si5351_ms_16m); // MS1 = divider 50, r_div=0 for 16 MHz
|
||||
|
||||
/* CLK4 and CLK5 - use single-byte writes too */
|
||||
{
|
||||
const auto& ms4_regs = si5351c_ms_4_reg;
|
||||
const uint8_t base_reg = ms4_regs[0];
|
||||
for (size_t i = 1; i < ms4_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, ms4_regs[i]);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto& ms5_regs = si5351c_ms_5_reg;
|
||||
const uint8_t base_reg = ms5_regs[0];
|
||||
for (size_t i = 1; i < ms5_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, ms5_regs[i]);
|
||||
}
|
||||
}
|
||||
clock_generator.write(si5351a_ms6_7_off_reg); // MS6/7 off - short write is OK
|
||||
|
||||
/* Step 3: NOW set clock control registers (AFTER multisynths per HackRF reference) */
|
||||
const auto ref_pll = ClockControl::MultiSynthSource::PLLA;
|
||||
const ClockControls si5351_clock_control = ClockControls{{
|
||||
si5351a_clock_control_common[0].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[1].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[2].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[3].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[4].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[5].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[6].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[7].ms_src(ref_pll),
|
||||
}};
|
||||
clock_generator.set_clock_control(si5351_clock_control);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
const PLLReg pll_reg = (reference.source == ReferenceSource::Xtal)
|
||||
? si5351_pll_a_xtal_reg
|
||||
@@ -319,21 +450,45 @@ void ClockManager::init_clock_generator() {
|
||||
clock_generator.write(si5351c_ms_5_reg);
|
||||
clock_generator.write(si5351c_ms6_7_off_mcu_clkin_reg);
|
||||
}
|
||||
#endif
|
||||
|
||||
clock_generator.reset_plls();
|
||||
|
||||
// Wait for PLL(s) to lock.
|
||||
#ifdef PRALINE
|
||||
// PRALINE: Wait for PLLA to lock (0x20 = LOL_A bit)
|
||||
uint8_t device_status_mask = 0x20;
|
||||
uint32_t pll_timeout = 100000;
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0 && pll_timeout > 0) {
|
||||
pll_timeout--;
|
||||
}
|
||||
// Store PLL lock status for debugging
|
||||
static volatile uint32_t pll_lock_timeout = pll_timeout;
|
||||
(void)pll_lock_timeout;
|
||||
|
||||
// CRITICAL: Add delay to ensure Si5351 writes complete before I2C bus stops
|
||||
chThdSleepMilliseconds(100);
|
||||
#else
|
||||
// Wait for PLL(s) to lock - with timeout to prevent hang
|
||||
uint8_t device_status_mask = hackrf_r9
|
||||
? 0x20
|
||||
: (ref_pll == ClockControl::MultiSynthSource::PLLB)
|
||||
? 0x40
|
||||
: 0x20;
|
||||
#ifndef PRALINE
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0);
|
||||
#else
|
||||
uint32_t pll_timeout = 100000;
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0 && pll_timeout > 0) {
|
||||
pll_timeout--;
|
||||
}
|
||||
#endif
|
||||
|
||||
clock_generator.set_clock_control(
|
||||
clock_generator_output_mcu_clkin,
|
||||
si5351_clock_control_common[clock_generator_output_mcu_clkin].ms_src(ref_pll).clk_pdn(ClockControl::ClockPowerDown::Power_On));
|
||||
clock_generator.enable_output(clock_generator_output_mcu_clkin);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t ClockManager::measure_gp_clkin_frequency() {
|
||||
@@ -400,6 +555,15 @@ void ClockManager::shutdown() {
|
||||
}
|
||||
|
||||
void ClockManager::enable_codec_clocks() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0 (AFE_CLK) for codec/FPGA, CLK1 (SCT_CLK) for FPGA timing.
|
||||
* Reference hackrf_core.c shows PRALINE needs both CLK0 and CLK1. */
|
||||
clock_generator.enable_clock(clock_generator_output_og_codec); /* CLK0 */
|
||||
clock_generator.enable_clock(clock_generator_output_og_cpld); /* CLK1 */
|
||||
clock_generator.enable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) |
|
||||
(1U << clock_generator_output_og_cpld));
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_clock(clock_generator_output_r9_sgpio);
|
||||
} else {
|
||||
@@ -417,6 +581,7 @@ void ClockManager::enable_codec_clocks() {
|
||||
clock_generator.enable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) | (1U << clock_generator_output_og_cpld) | (1U << clock_generator_output_og_sgpio));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::disable_codec_clocks() {
|
||||
@@ -424,6 +589,14 @@ void ClockManager::disable_codec_clocks() {
|
||||
* be enabled for the output to come to rest at the state specified by
|
||||
* CLKx_DISABLE_STATE.
|
||||
*/
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0 (AFE_CLK) and CLK1 (SCT_CLK) used for codec/FPGA */
|
||||
clock_generator.disable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) |
|
||||
(1U << clock_generator_output_og_cpld));
|
||||
clock_generator.disable_clock(clock_generator_output_og_codec);
|
||||
clock_generator.disable_clock(clock_generator_output_og_cpld);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_r9_sgpio);
|
||||
clock_generator.disable_clock(clock_generator_output_r9_sgpio);
|
||||
@@ -434,9 +607,17 @@ void ClockManager::disable_codec_clocks() {
|
||||
clock_generator.disable_clock(clock_generator_output_og_cpld);
|
||||
clock_generator.disable_clock(clock_generator_output_og_sgpio);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::enable_if_clocks() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses CLK4 (first IF) and CLK5 (second IF) like original HackRF One */
|
||||
clock_generator.enable_clock(clock_generator_output_og_first_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_first_if);
|
||||
clock_generator.enable_clock(clock_generator_output_og_second_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_clock(clock_generator_output_r9_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_r9_if);
|
||||
@@ -446,9 +627,16 @@ void ClockManager::enable_if_clocks() {
|
||||
clock_generator.enable_clock(clock_generator_output_og_second_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::disable_if_clocks() {
|
||||
#ifdef PRALINE
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_first_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_first_if);
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_second_if);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_r9_if);
|
||||
clock_generator.disable_clock(clock_generator_output_r9_if);
|
||||
@@ -458,19 +646,41 @@ void ClockManager::disable_if_clocks() {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_second_if);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::set_sampling_frequency(const uint32_t frequency) {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0=AFE_CLK runs at sample rate (VCO/divider/2)
|
||||
* CLK1=SCT_CLK runs at 2x sample rate (VCO/divider/1)
|
||||
* Reference: hackrf_core.c sample_rate_frac_set() lines 580-582
|
||||
*/
|
||||
|
||||
/* PRALINE: Match HackRF USB sample_rate_frac_set()
|
||||
* Reference: hackrf_usb radio.c lines 29-91, hackrf_core.c lines 501-685 */
|
||||
|
||||
_base_band_frequency = frequency;
|
||||
|
||||
// Set FPGA decimation to 0 (no decimation) for direct passthrough
|
||||
fpga_debug_register_write(2, 0);
|
||||
radio::invalidate_spi_config();
|
||||
|
||||
// The following was originally from @kitty. Adopting for testing radio.
|
||||
clock_generator.set_ms_frequency(0, frequency * 2, si5351_vco_f, 1); // CLK0: r_div=1 (÷2)
|
||||
clock_generator.set_ms_frequency(1, frequency * 2, si5351_vco_f, 0); // CLK1: r_div=0 (÷1)
|
||||
#else
|
||||
/* Codec clock is at sampling frequency, CPLD and SGPIO clocks are at
|
||||
* twice the frequency, and derived from the MS0 synth. So it's only
|
||||
* necessary to change the MS0 synth frequency, and ensure the output
|
||||
* is divided by two.
|
||||
*/
|
||||
|
||||
if (hackrf_r9) {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_r9_sgpio, frequency * 2, si5351_vco_f, 0);
|
||||
} else {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_og_codec, frequency * 2, si5351_vco_f, 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::set_reference_ppb(const int32_t ppb) {
|
||||
@@ -510,7 +720,15 @@ void ClockManager::start_frequency_monitor_measurement(const cgu::CLK_SEL clk_se
|
||||
|
||||
void ClockManager::wait_For_frequency_monitor_measurement_done() {
|
||||
// FREQ_MON mechanism fails to finish if there's no clock present on selected input?!
|
||||
#ifndef PRALINE
|
||||
while (LPC_CGU->FREQ_MON.MEAS == 1);
|
||||
#else
|
||||
// PRALINE FIX: Add timeout to prevent infinite hang
|
||||
uint32_t timeout = 100000;
|
||||
while (LPC_CGU->FREQ_MON.MEAS == 1 && timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t ClockManager::get_frequency_monitor_measurement_in_hertz() {
|
||||
@@ -521,6 +739,35 @@ uint32_t ClockManager::get_frequency_monitor_measurement_in_hertz() {
|
||||
}
|
||||
|
||||
void ClockManager::start_audio_pll() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: Use 12MHz XTAL for audio PLL
|
||||
* For 12MHz XTAL input, 48kHz audio rate, 256Fs MCLK:
|
||||
* Fout=12.288MHz, Fcco=491.52MHz
|
||||
* 12MHz * 1024 / 25 = 491.52MHz
|
||||
* MSEL=1024, NSEL=25, PSEL=20
|
||||
*/
|
||||
cgu::pll0audio::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
.directi = 0,
|
||||
.directo = 0,
|
||||
.clken = 0,
|
||||
.frm = 0,
|
||||
.autoblock = 1,
|
||||
.pllfract_req = 0,
|
||||
.sel_ext = 1,
|
||||
.mod_pd = 1,
|
||||
.clk_sel = cgu::CLK_SEL::XTAL,
|
||||
});
|
||||
|
||||
cgu::pll0audio::mdiv({
|
||||
.mdec = 22625UL, // MDEC for MSEL=1024
|
||||
});
|
||||
cgu::pll0audio::np_div({
|
||||
.pdec = 31, // PSEL=20
|
||||
.ndec = 69, // NDEC for NSEL=25
|
||||
});
|
||||
#else
|
||||
cgu::pll0audio::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
@@ -549,13 +796,24 @@ void ClockManager::start_audio_pll() {
|
||||
.pdec = 31,
|
||||
.ndec = 45,
|
||||
});
|
||||
#endif
|
||||
|
||||
cgu::pll0audio::frac({
|
||||
.pllfract_ctrl = 0,
|
||||
});
|
||||
|
||||
cgu::pll0audio::power_up();
|
||||
#ifndef PRALINE
|
||||
while (!cgu::pll0audio::is_locked());
|
||||
#else
|
||||
// PRALINE FIX: Add timeout to prevent infinite hang if GP_CLKIN not present
|
||||
{
|
||||
uint32_t timeout = 100000;
|
||||
while (!cgu::pll0audio::is_locked() && timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
cgu::pll0audio::clock_enable();
|
||||
|
||||
set_base_audio_clock_divider(1);
|
||||
|
||||
@@ -70,8 +70,19 @@ class ClockManager {
|
||||
|
||||
void set_sampling_frequency(const uint32_t frequency);
|
||||
|
||||
uint32_t get_sampling_frequency() const {
|
||||
return _base_band_frequency;
|
||||
};
|
||||
|
||||
void set_reference_ppb(const int32_t ppb);
|
||||
|
||||
#ifdef PRALINE
|
||||
// Si5351 diagnostic methods
|
||||
uint8_t si5351_read_status() { return clock_generator.device_status(); }
|
||||
uint8_t si5351_read_register(uint8_t reg) { return clock_generator.read_register(reg); }
|
||||
void si5351_write_register(uint8_t reg, uint8_t value) { clock_generator.write_register(reg, value); }
|
||||
#endif
|
||||
|
||||
uint32_t get_frequency_monitor_measurement_in_hertz();
|
||||
|
||||
Reference get_reference() const;
|
||||
@@ -85,6 +96,8 @@ class ClockManager {
|
||||
si5351::Si5351& clock_generator;
|
||||
Reference reference;
|
||||
|
||||
uint32_t _base_band_frequency{20000000};
|
||||
|
||||
void set_gp_clkin_to_clkin_direct();
|
||||
|
||||
void start_frequency_monitor_measurement(const cgu::CLK_SEL clk_sel);
|
||||
|
||||
@@ -256,7 +256,9 @@ ui::Widget* EventDispatcher::touch_widget(ui::Widget* const w, ui::TouchEvent ev
|
||||
if (!w->hidden()) {
|
||||
// To achieve reverse depth ordering (last object drawn is
|
||||
// considered "top"), descend first.
|
||||
for (const auto child : w->children()) {
|
||||
auto& children = w->children();
|
||||
for (auto it = children.rbegin(); it != children.rend(); ++it) { // reverse, bc the lastly added will be "top" if overlaps
|
||||
const auto& child = *it;
|
||||
const auto touched_widget = touch_widget(child, event);
|
||||
if (touched_widget) {
|
||||
return touched_widget;
|
||||
|
||||
+1
-1
@@ -339,7 +339,7 @@ void AdultToysView::randomizeMac() {
|
||||
}
|
||||
|
||||
void AdultToysView::randomChn() {
|
||||
channel_number = 37 + std::rand() % (39 - 37 + 1);
|
||||
channel_number = 37 + rand() % (39 - 37 + 1);
|
||||
field_frequency.set_value(get_freq_by_channel_number(channel_number));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ void BlackjackView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_deck();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ void BLESpamView::reset() {
|
||||
}
|
||||
|
||||
void BLESpamView::randomChn() {
|
||||
channel_number = 37 + std::rand() % (39 - 37 + 1);
|
||||
channel_number = 37 + rand() % (39 - 37 + 1);
|
||||
field_frequency.set_value(get_freq_by_channel_number(channel_number));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -655,7 +655,7 @@ void BreakoutView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -125,7 +125,7 @@ void DinoGameView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
@@ -789,8 +789,8 @@ void DinoGameView::draw_current_score() {
|
||||
|
||||
void DinoGameView::draw_high_score() {
|
||||
auto style = *ui::Theme::getInstance()->fg_light;
|
||||
painter.fill_rectangle({UI_POS_X_RIGHT(90), 28, 90, 18}, Color::black());
|
||||
painter.draw_string({UI_POS_X_RIGHT(90), 30}, style, "HI " + score_to_string(highScore));
|
||||
painter.fill_rectangle({UI_POS_X_RIGHT(10), 28, 90, 18}, Color::black());
|
||||
painter.draw_string({UI_POS_X_RIGHT(10), 30}, style, "HI " + score_to_string(highScore));
|
||||
}
|
||||
|
||||
void DinoGameView::jump() {
|
||||
|
||||
+15
-15
@@ -204,11 +204,11 @@ void spawn_entity(uint8_t type, uint8_t x, uint8_t y) {
|
||||
|
||||
void spawn_random_entity(uint8_t type) {
|
||||
if (num_entities >= MAX_ENTITIES) return;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
uint8_t spawn_x, spawn_y;
|
||||
do {
|
||||
spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
spawn_x = rand() % LEVEL_WIDTH;
|
||||
spawn_y = rand() % LEVEL_HEIGHT;
|
||||
} while (get_block_at(spawn_x, spawn_y) == 0xF ||
|
||||
(spawn_x == (uint8_t)player.pos.x && spawn_y == (uint8_t)player.pos.y));
|
||||
|
||||
@@ -227,9 +227,9 @@ void remove_entity(uint8_t index) {
|
||||
bool spawned = false;
|
||||
|
||||
while (!spawned && attempts < 50) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts);
|
||||
uint8_t spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
srand(LPC_RTC->CTIME0 + attempts);
|
||||
uint8_t spawn_x = rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = rand() % LEVEL_HEIGHT;
|
||||
|
||||
int16_t dx = (int16_t)spawn_x - (int16_t)player.pos.x;
|
||||
int16_t dy = (int16_t)spawn_y - (int16_t)player.pos.y;
|
||||
@@ -270,9 +270,9 @@ void initialize_level() {
|
||||
uint8_t attempts = 0;
|
||||
|
||||
while (initial_enemies < 2 && num_entities < MAX_ENTITIES && attempts < 50) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts);
|
||||
int8_t offset_x = (std::rand() % 11) - 5;
|
||||
int8_t offset_y = (std::rand() % 11) - 5;
|
||||
srand(LPC_RTC->CTIME0 + attempts);
|
||||
int8_t offset_x = (rand() % 11) - 5;
|
||||
int8_t offset_y = (rand() % 11) - 5;
|
||||
|
||||
if (abs(offset_x) < 3 && abs(offset_y) < 3) {
|
||||
attempts++;
|
||||
@@ -307,10 +307,10 @@ void initialize_level() {
|
||||
|
||||
attempts = 0;
|
||||
while (num_entities < MIN_ENTITIES && attempts < 100) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts + 100);
|
||||
srand(LPC_RTC->CTIME0 + attempts + 100);
|
||||
|
||||
uint8_t spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
uint8_t spawn_x = rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = rand() % LEVEL_HEIGHT;
|
||||
|
||||
int16_t dx = (int16_t)spawn_x - (int16_t)player.pos.x;
|
||||
int16_t dy = (int16_t)spawn_y - (int16_t)player.pos.y;
|
||||
@@ -1045,7 +1045,7 @@ void DoomView::on_show() {
|
||||
void DoomView::paint(Painter& painter) {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
scene = 0;
|
||||
up = down = left = right = fired = false;
|
||||
jogging = view_height = 0;
|
||||
@@ -1081,7 +1081,7 @@ void DoomView::paint(Painter& painter) {
|
||||
int hud_y = RENDER_HEIGHT + 5;
|
||||
painter.draw_string({5, hud_y}, style_yellow, "Health: " + std::to_string(player.health));
|
||||
painter.draw_string({UI_POS_X_CENTER(15), hud_y}, style_red, "Kills: " + std::to_string(kills));
|
||||
painter.draw_string({UI_POS_X_RIGHT(80), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
painter.draw_string({UI_POS_X_RIGHT(10), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
|
||||
prev_velocity_moving = (player.velocity != 0);
|
||||
needs_redraw = false;
|
||||
@@ -1113,7 +1113,7 @@ void DoomView::paint(Painter& painter) {
|
||||
int hud_y = RENDER_HEIGHT + 5;
|
||||
painter.draw_string({5, hud_y}, style_yellow, "Health: " + std::to_string(player.health));
|
||||
painter.draw_string({UI_POS_X_CENTER(15), hud_y}, style_red, "Kills: " + std::to_string(kills));
|
||||
painter.draw_string({UI_POS_X_RIGHT(80), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
painter.draw_string({UI_POS_X_RIGHT(10), hud_y}, style_blue, "Ammo: " + std::to_string(player.ammo));
|
||||
|
||||
needs_gun_redraw = false;
|
||||
}
|
||||
|
||||
+30
-6
@@ -83,6 +83,10 @@ set(EXTCPPSRC
|
||||
external/tpmsrx/main.cpp
|
||||
external/tpmsrx/tpms_app.cpp
|
||||
|
||||
#tpmstx 800 bytes - TPMS transmit with editable fields
|
||||
external/tpmstx/main.cpp
|
||||
external/tpmstx/tpms_tx_app.cpp
|
||||
|
||||
#protoview 8 byte
|
||||
external/protoview/main.cpp
|
||||
external/protoview/ui_protoview.cpp
|
||||
@@ -285,11 +289,6 @@ set(EXTCPPSRC
|
||||
external/siggen/main.cpp
|
||||
external/siggen/ui_siggen.cpp
|
||||
|
||||
#sdusb
|
||||
external/sdusb/main.cpp
|
||||
external/sdusb/ui_sd_over_usb.cpp
|
||||
|
||||
|
||||
#morse_radio
|
||||
external/morse_radio/main.cpp
|
||||
external/morse_radio/ui_morse_radio.cpp
|
||||
@@ -297,6 +296,18 @@ set(EXTCPPSRC
|
||||
#morseradiotx
|
||||
external/morseradiotx/main.cpp
|
||||
external/morseradiotx/ui_morse_radiotx.cpp
|
||||
|
||||
external/keeloqtx/main.cpp
|
||||
external/keeloqtx/ui_keeloqtx.cpp
|
||||
#rtty_rx
|
||||
external/rtty_rx/main.cpp
|
||||
external/rtty_rx/ui_rtty_rx.cpp
|
||||
external/rtty_rx/baudot.cpp
|
||||
|
||||
#rtty_tx
|
||||
external/rtty_tx/main.cpp
|
||||
external/rtty_tx/ui_rtty_tx.cpp
|
||||
external/rtty_tx/baudot.cpp
|
||||
)
|
||||
|
||||
set(EXTAPPLIST
|
||||
@@ -319,6 +330,7 @@ set(EXTAPPLIST
|
||||
audio_test
|
||||
wardrivemap
|
||||
tpmsrx
|
||||
tpmstx
|
||||
protoview
|
||||
adsbtx
|
||||
#morse_tx
|
||||
@@ -368,7 +380,19 @@ set(EXTAPPLIST
|
||||
flex_rx
|
||||
subcarrx
|
||||
siggen
|
||||
sdusb
|
||||
morse_radio
|
||||
morseradiotx
|
||||
keeloqtx
|
||||
rtty_rx
|
||||
rtty_tx
|
||||
)
|
||||
|
||||
# sdusb has type conflicts with PRALINE (HackRF Pro) - add only for non-PRALINE builds
|
||||
if(NOT BOARD STREQUAL "PRALINE")
|
||||
list(APPEND EXTCPPSRC
|
||||
external/sdusb/main.cpp
|
||||
external/sdusb/ui_sd_over_usb.cpp
|
||||
)
|
||||
list(APPEND EXTAPPLIST sdusb)
|
||||
endif()
|
||||
|
||||
|
||||
+26
@@ -94,6 +94,10 @@ MEMORY
|
||||
ram_external_app_morse_radio (rwx) : org = 0xADF50000, len = 32k
|
||||
ram_external_app_waterfall_designer (rwx) : org = 0xADF60000, len = 32k
|
||||
ram_external_app_morseradiotx (rwx) : org = 0xADF70000, len = 32k
|
||||
ram_external_app_keeloqtx (rwx) : org = 0xADF80000, len = 32k
|
||||
ram_external_app_rtty_rx (rwx) : org = 0xADF90000, len = 32k
|
||||
ram_external_app_rtty_tx (rwx) : org = 0xADFA0000, len = 32k
|
||||
ram_external_app_tpmstx (rwx) : org = 0xADFB0000, len = 32k
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
@@ -212,6 +216,12 @@ SECTIONS
|
||||
*(*ui*external_app*tpmsrx*);
|
||||
} > ram_external_app_tpmsrx
|
||||
|
||||
.external_app_tpmstx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_tpmstx.application_information));
|
||||
*(*ui*external_app*tpmstx*);
|
||||
} > ram_external_app_tpmstx
|
||||
|
||||
.external_app_protoview : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_protoview.application_information));
|
||||
@@ -526,5 +536,21 @@ SECTIONS
|
||||
*(*ui*external_app*morseradiotx*);
|
||||
} > ram_external_app_morseradiotx
|
||||
|
||||
.external_app_keeloqtx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_keeloqtx.application_information));
|
||||
*(*ui*external_app*keeloqtx*);
|
||||
} > ram_external_app_keeloqtx
|
||||
.external_app_rtty_rx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_rtty_rx.application_information));
|
||||
*(*ui*external_app*rtty_rx*);
|
||||
} > ram_external_app_rtty_rx
|
||||
|
||||
.external_app_rtty_tx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_rtty_tx.application_information));
|
||||
*(*ui*external_app*rtty_tx*);
|
||||
} > ram_external_app_rtty_tx
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ bool FlipperTxView::on_file_changed(std::filesystem::path new_file_path) {
|
||||
return false;
|
||||
}
|
||||
preset = submeta.value().preset;
|
||||
if (preset != FLIPPER_PRESET_OOK) {
|
||||
if (preset != FLIPPER_PRESET_OOK && preset != FLIPPER_PRESET_2FSK) {
|
||||
field_filename.set_text("File: err, not supp. preset");
|
||||
return false;
|
||||
}
|
||||
@@ -108,8 +108,13 @@ void FlipperTxView::stop() {
|
||||
bool FlipperTxView::start() {
|
||||
if (filename.empty()) return false;
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
transmitter_model.set_sampling_rate(OOK_SAMPLERATE);
|
||||
transmitter_model.enable();
|
||||
button_startstop.set_text(LanguageHelper::currentMessages[LANG_STOP]);
|
||||
uint8_t mode = 0;
|
||||
if (preset == FLIPPER_PRESET_2FSK)
|
||||
mode = 1;
|
||||
baseband::set_bitstream_config(FM_DEVIATION, mode);
|
||||
// start thread
|
||||
replay_thread = std::make_unique<FlipperPlayThread>(
|
||||
filename,
|
||||
|
||||
@@ -28,6 +28,8 @@ using namespace ui;
|
||||
namespace ui::external_app::flippertx {
|
||||
|
||||
#define OOK_SAMPLERATE 2280000U
|
||||
#define FM_DEVIATION 60000U
|
||||
|
||||
class FlipperPlayThread;
|
||||
class FlipperTxView : public View {
|
||||
public:
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ Game2048View::Game2048View(NavigationView& nav)
|
||||
|
||||
void Game2048View::on_show() {
|
||||
if (!initialized) {
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
reset_game();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2026 lifegame1lu111
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_keeloqtx.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::ui_keeloqtx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<KeeloqTXView>();
|
||||
}
|
||||
} // namespace ui::external_app::ui_keeloqtx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_keeloqtx.application_information"), used)) application_information_t _application_information_keeloqtx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::ui_keeloqtx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
/*.app_name = */ "KeeLoq TX",
|
||||
/*.bitmap_data = */ {
|
||||
0x20,
|
||||
0x00,
|
||||
0x20,
|
||||
0x00,
|
||||
0x20,
|
||||
0x00,
|
||||
0x20,
|
||||
0x00,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0x30,
|
||||
0x0C,
|
||||
0x30,
|
||||
0x0C,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0x70,
|
||||
0x0D,
|
||||
0xB0,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0D,
|
||||
0xB0,
|
||||
0x0E,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xE0,
|
||||
0x07,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::yellow().v,
|
||||
/*.menu_location = */ app_location_t::TX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_ook */ {'P', 'O', 'O', 'K'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
#include "ui_keeloqtx.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "../../keeloq_common.hpp"
|
||||
#include "../../baseband/fprotos/fprotogeneral.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace ui;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace ui::external_app::ui_keeloqtx {
|
||||
|
||||
void KeeloqTXView::focus() {
|
||||
button_open.focus();
|
||||
}
|
||||
|
||||
void KeeloqTXView::update_hop() {
|
||||
hop = data.btn << 28 | (data.serial & 0x3FF) << 16 | data.counter;
|
||||
|
||||
if (data.mf_name == "Aprimatic") {
|
||||
uint32_t apri_serial = data.serial;
|
||||
uint8_t apr1 = 0;
|
||||
|
||||
for (uint16_t i = 1; i != 0b10000000000; i <<= 1) {
|
||||
if (apri_serial & i) apr1++;
|
||||
}
|
||||
|
||||
apri_serial &= 0b00001111111111;
|
||||
|
||||
if (apr1 % 2 == 0) {
|
||||
apri_serial |= 0b110000000000;
|
||||
}
|
||||
|
||||
hop = data.btn << 28 | (apri_serial & 0xFFF) << 16 | data.counter;
|
||||
} else if (
|
||||
data.mf_name == "DTM_Neo" || data.mf_name == "FAAC_RC,XT" || data.mf_name == "Mutanco_Mutancode" || data.mf_name == "Came_Space" || data.mf_name == "Genius_Bravo" || data.mf_name == "GSN" || data.mf_name == "Rosh" || data.mf_name == "Rossi" || data.mf_name == "Peccinin" || data.mf_name == "Steelmate" || data.mf_name == "Cardin_S449") {
|
||||
hop = data.btn << 28 | (data.serial & 0xFFF) << 16 | data.counter;
|
||||
} else if (
|
||||
data.mf_name == "NICE_Smilo" || data.mf_name == "NICE_MHOUSE" || data.mf_name == "JCM_Tech") {
|
||||
hop = data.btn << 28 | (data.serial & 0xFF) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Merlin") {
|
||||
hop = data.btn << 28 | (0x000) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Centurion") {
|
||||
hop = data.btn << 28 | (0x1CE) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Monarch") {
|
||||
hop = data.btn << 28 | (0x100) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Dea_Mio") {
|
||||
uint8_t first_disc_num = (data.serial >> 8) & 0xF;
|
||||
uint8_t result_disc = (0xC + (first_disc_num % 4));
|
||||
|
||||
uint32_t dea_serial = (data.serial & 0xFF) | (((uint32_t)result_disc) << 8);
|
||||
|
||||
hop = data.btn << 28 | (dea_serial & 0xFFF) << 16 | data.counter;
|
||||
}
|
||||
|
||||
text_hop.set(to_string_hex(hop));
|
||||
}
|
||||
|
||||
void KeeloqTXView::update_payload() {
|
||||
uint64_t encrypt = 0;
|
||||
|
||||
switch (current_key.type) {
|
||||
case KEELOQ_SIMPLE_LEARNING: {
|
||||
encrypt = keeloq_encrypt(hop, current_key.key);
|
||||
|
||||
break;
|
||||
}
|
||||
case KEELOQ_NORMAL_LEARNING: {
|
||||
uint64_t man = keeloq_normal_learning(fix, current_key.key);
|
||||
|
||||
encrypt = keeloq_encrypt(hop, man);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
payload = (uint64_t)fix << 32 | encrypt;
|
||||
|
||||
uint64_t preview_payload = FProtoGeneral::subghz_protocol_blocks_reverse_key(payload, 64);
|
||||
|
||||
text_payload.set(to_string_hex(preview_payload));
|
||||
encode_data();
|
||||
}
|
||||
|
||||
void KeeloqTXView::encode_data() {
|
||||
std::string fragments{};
|
||||
|
||||
for (uint32_t i = 0; i < 64; ++i) {
|
||||
fragments += keeloq_fragments[bit(payload, i)];
|
||||
}
|
||||
|
||||
encoded_data = KEELOQ_HEADER + fragments + "1001";
|
||||
|
||||
if (data.mf_name == "Sommer") {
|
||||
pause_duration = 28;
|
||||
} else {
|
||||
pause_duration = 39;
|
||||
}
|
||||
}
|
||||
|
||||
KeeloqTXView::KeeloqTXView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_ook);
|
||||
|
||||
add_children({&labels,
|
||||
&text_mf_name,
|
||||
&text_serial,
|
||||
&text_fix,
|
||||
&text_hop,
|
||||
&field_counter,
|
||||
&field_button,
|
||||
&field_repeat,
|
||||
&text_payload,
|
||||
&button_open,
|
||||
&text_status,
|
||||
&progressbar,
|
||||
&tx_view});
|
||||
|
||||
field_counter.on_change = [this](uint32_t value) {
|
||||
data.counter = (uint16_t)value;
|
||||
|
||||
update_hop();
|
||||
update_payload();
|
||||
};
|
||||
|
||||
field_button.on_change = [this](uint32_t value) {
|
||||
data.btn = (uint8_t)value;
|
||||
|
||||
fix &= 0xFFFFFFF;
|
||||
fix |= data.btn << 28;
|
||||
|
||||
text_fix.set(to_string_hex(fix));
|
||||
|
||||
update_hop();
|
||||
update_payload();
|
||||
};
|
||||
|
||||
field_repeat.on_change = [this](uint32_t value) {
|
||||
repeat = value;
|
||||
};
|
||||
|
||||
field_repeat.set_value(4, true);
|
||||
|
||||
tx_view.on_edit_frequency = [this, &nav]() {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(transmitter_model.target_frequency());
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
transmitter_model.set_target_frequency(f);
|
||||
};
|
||||
};
|
||||
|
||||
tx_view.on_start = [this]() {
|
||||
start_tx();
|
||||
};
|
||||
|
||||
tx_view.on_stop = [this]() {
|
||||
baseband::kill_ook();
|
||||
stop_tx();
|
||||
};
|
||||
|
||||
button_open.on_select = [this](const Button&) {
|
||||
auto open_view = nav_.push<FileLoadView>(".KEELOQ");
|
||||
|
||||
ensure_directory(keeloq_remotes_dir);
|
||||
open_view->push_dir(keeloq_remotes_dir);
|
||||
open_view->on_changed = [this](fs::path path) {
|
||||
nav_.set_on_pop([this, path]() {
|
||||
if (!read_keeloq_file(path, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
file_path = path;
|
||||
|
||||
for (const auto& key : keystore.get_keys()) {
|
||||
if (key.mf_name == data.mf_name) {
|
||||
current_key = key;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fix = data.btn << 28 | data.serial;
|
||||
|
||||
update_hop();
|
||||
|
||||
text_mf_name.set(data.mf_name);
|
||||
text_serial.set(to_string_hex(data.serial));
|
||||
text_fix.set(to_string_hex(fix));
|
||||
|
||||
field_counter.set_value(data.counter, false);
|
||||
field_button.set_value(data.btn, false);
|
||||
|
||||
update_payload();
|
||||
|
||||
field_counter.focus();
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
void KeeloqTXView::start_tx() {
|
||||
size_t bitstream_length = encoders::make_bitstream(encoded_data);
|
||||
|
||||
progressbar.set_max(repeat);
|
||||
tx_view.set_transmitting(true);
|
||||
|
||||
transmitter_model.enable();
|
||||
|
||||
baseband::set_ook_data(
|
||||
bitstream_length,
|
||||
OOK_SAMPLERATE * (400.0 / 1000000.0),
|
||||
repeat,
|
||||
pause_duration);
|
||||
}
|
||||
|
||||
void KeeloqTXView::stop_tx() {
|
||||
transmitter_model.disable();
|
||||
text_status.set("Ready");
|
||||
progressbar.set_value(0);
|
||||
tx_view.set_transmitting(false);
|
||||
|
||||
data.counter += 1;
|
||||
|
||||
field_counter.set_value(data.counter, false);
|
||||
|
||||
update_hop();
|
||||
update_payload();
|
||||
|
||||
write_keeloq_file(file_path, data);
|
||||
}
|
||||
|
||||
void KeeloqTXView::on_tx_progress(uint32_t progress, bool done) {
|
||||
if (!done) {
|
||||
text_status.set(to_string_dec_uint(progress + 1) + "/" + to_string_dec_uint(repeat));
|
||||
progressbar.set_value(progress + 1);
|
||||
} else {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
stop_tx();
|
||||
}
|
||||
}
|
||||
|
||||
KeeloqTXView::~KeeloqTXView() {
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::ui_keeloqtx
|
||||
@@ -0,0 +1,129 @@
|
||||
#ifndef __KEELOQTX__
|
||||
#define __KEELOQTX__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "transmitter_model.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "encoders.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "../../keeloq_file.hpp"
|
||||
#include "../../keeloq_keystore.hpp"
|
||||
|
||||
#define KEELOQ_HEADER "101010101010101010101010000000000"
|
||||
|
||||
namespace ui::external_app::ui_keeloqtx {
|
||||
|
||||
class KeeloqTXView : public View {
|
||||
public:
|
||||
KeeloqTXView(NavigationView& nav);
|
||||
~KeeloqTXView();
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override {
|
||||
return "KeeLoqTX";
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string keeloq_fragments[2] = {"110", "100"};
|
||||
|
||||
NavigationView& nav_;
|
||||
|
||||
TxRadioState radio_state_{
|
||||
433920000,
|
||||
1750000,
|
||||
OOK_SAMPLERATE};
|
||||
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_keeloq", app_settings::Mode::TX};
|
||||
|
||||
std::filesystem::path file_path{};
|
||||
|
||||
KeeloqKeystore keystore{};
|
||||
KeeloqKey current_key{};
|
||||
KeeloqData data{};
|
||||
|
||||
uint32_t fix = 0;
|
||||
uint32_t hop = 0;
|
||||
uint64_t payload = 0;
|
||||
|
||||
void update_hop();
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(1), UI_POS_Y(0)}, "Manufacturer:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(1)}, "Serial:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(2)}, "Fix:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(3)}, "Hop:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(4)}, "Counter:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(5)}, "Button:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(6)}, "Repeat:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(2), UI_POS_Y(8)}, "Payload:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
Text text_mf_name{{UI_POS_X(15), UI_POS_Y(0), 128, 16}, ""};
|
||||
Text text_serial{{UI_POS_X(9), UI_POS_Y(1), 64, 16}, "00000000"};
|
||||
Text text_fix{{UI_POS_X(6), UI_POS_Y(2), 64, 16}, "00000000"};
|
||||
Text text_hop{{UI_POS_X(6), UI_POS_Y(3), 64, 16}, "00000000"};
|
||||
|
||||
NumberField field_counter{
|
||||
{UI_POS_X(10), UI_POS_Y(4)},
|
||||
5,
|
||||
{0, 65535},
|
||||
1,
|
||||
' '};
|
||||
NumberField field_button{
|
||||
{UI_POS_X(9), UI_POS_Y(5)},
|
||||
2,
|
||||
{0, 15},
|
||||
1,
|
||||
' '};
|
||||
NumberField field_repeat{
|
||||
{UI_POS_X(10), UI_POS_Y(6)},
|
||||
3,
|
||||
{0, 100},
|
||||
1,
|
||||
' '};
|
||||
|
||||
Text text_payload{{UI_POS_X(2), UI_POS_Y(9), 128, 16}, "0000000000000000"};
|
||||
|
||||
void update_payload();
|
||||
|
||||
Button button_open{{UI_POS_X(0), UI_POS_Y(11), screen_width, 32}, "Open file"};
|
||||
|
||||
Text text_status{{UI_POS_X(2), UI_POS_Y_BOTTOM(7), 128, 16}, "Ready"};
|
||||
|
||||
ProgressBar progressbar{
|
||||
{UI_POS_X(2), UI_POS_Y_BOTTOM(7) + 20, UI_POS_WIDTH_REMAINING(4), 16}};
|
||||
|
||||
TransmitterView tx_view{
|
||||
(int16_t)UI_POS_Y_BOTTOM(4),
|
||||
50000,
|
||||
9};
|
||||
|
||||
std::string encoded_data{};
|
||||
|
||||
void encode_data();
|
||||
|
||||
uint32_t repeat = 4;
|
||||
uint32_t pause_duration = 0;
|
||||
|
||||
void start_tx();
|
||||
void stop_tx();
|
||||
|
||||
void update_progress();
|
||||
void on_tx_progress(uint32_t progress, bool done);
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
this->on_tx_progress(message.progress, message.done);
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::ui_keeloqtx
|
||||
|
||||
#endif
|
||||
+35
-27
@@ -17,6 +17,7 @@ MorseRadioView::MorseRadioView(ui::NavigationView& nav)
|
||||
&txt_last,
|
||||
&txt_speed,
|
||||
&txt_freq,
|
||||
&txt_clip,
|
||||
&options_mode,
|
||||
&btn_clear,
|
||||
&console_text,
|
||||
@@ -33,41 +34,44 @@ MorseRadioView::MorseRadioView(ui::NavigationView& nav)
|
||||
logger->init_daily_log(logs_dir);
|
||||
};
|
||||
|
||||
audio::output::start();
|
||||
receiver_model.set_sampling_rate(3072000);
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
receiver_model.enable();
|
||||
field_squelch.on_change = [this](int32_t v) {
|
||||
receiver_model.set_squelch_level(v);
|
||||
};
|
||||
|
||||
options_mode.on_change = [this](size_t, int32_t value) {
|
||||
current_mode = (uint8_t)value;
|
||||
options_mode.on_change = [this](size_t, int32_t mode) {
|
||||
audio::output::stop();
|
||||
receiver_model.disable();
|
||||
morse_decoder_.resetLearning();
|
||||
if (current_mode == 0) {
|
||||
if (mode == MORSE_NFM) {
|
||||
receiver_model.set_am_configuration(4);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio);
|
||||
field_squelch.set_style(Theme::getInstance()->option_active);
|
||||
field_squelch.set_focusable(true);
|
||||
receiver_model.set_squelch_level(field_squelch.value());
|
||||
field_squelch.set_value(receiver_model.squelch_level());
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
} else {
|
||||
audio::set_rate(audio::Rate::Hz_12000);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::AMAudio);
|
||||
receiver_model.set_am_configuration(current_mode + 7);
|
||||
receiver_model.set_squelch_level(0);
|
||||
if (mode == MORSE_AM_CW || mode == MORSE_AM_DSB)
|
||||
receiver_model.set_am_configuration(7);
|
||||
else if (mode == MORSE_AM_USB)
|
||||
receiver_model.set_am_configuration(9);
|
||||
else // LSB
|
||||
receiver_model.set_am_configuration(10);
|
||||
field_squelch.set_style(Theme::getInstance()->fg_dark);
|
||||
field_squelch.set_focusable(false);
|
||||
audio::set_rate(audio::Rate::Hz_12000);
|
||||
}
|
||||
baseband::set_moreserx_config(current_mode);
|
||||
};
|
||||
field_squelch.set_value(receiver_model.squelch_level(), false); // will be sent later, no need to send 2x
|
||||
field_squelch.on_change = [this](int32_t v) {
|
||||
if (current_mode == 0)
|
||||
receiver_model.set_squelch_level(v);
|
||||
};
|
||||
options_mode.set_selected_index(current_mode, true);
|
||||
baseband::set_moreserx_config(mode);
|
||||
saved_mode = mode;
|
||||
|
||||
auto vol = field_volume.value(); // audio volume fix
|
||||
field_volume.set_value(0);
|
||||
field_volume.set_value(vol);
|
||||
audio::output::start();
|
||||
receiver_model.set_headphone_volume(receiver_model.headphone_volume()); // WM8731 hack.
|
||||
|
||||
receiver_model.set_sampling_rate(3072000);
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
receiver_model.enable();
|
||||
};
|
||||
options_mode.set_selected_index(saved_mode);
|
||||
|
||||
logger = std::make_unique<MorseLogger>();
|
||||
chk_log.on_select = [this](Checkbox&, bool save) {
|
||||
@@ -103,21 +107,21 @@ void MorseLogger::init_daily_log(const std::filesystem::path& log_dir) {
|
||||
}
|
||||
}
|
||||
|
||||
void MorseLogger::radio_set_log(uint8_t current_mode) {
|
||||
void MorseLogger::radio_set_log(const std::string& morse_mode) {
|
||||
int64_t freq = receiver_model.target_frequency();
|
||||
std::string header = "Freq:" + to_string_rounded_freq(freq, 4);
|
||||
header += "MHz, ";
|
||||
header += "RX MODE:" + std::string(current_mode == 0 ? "CW/FM" : (current_mode == 1 ? "USB" : "LSB"));
|
||||
header += "RX MODE:" + morse_mode;
|
||||
header += "\r\nMessage:";
|
||||
log_file.write_raw(header);
|
||||
}
|
||||
|
||||
bool MorseLogger::on_packet(const std::string& content, bool time, uint8_t current_mode) {
|
||||
bool MorseLogger::on_packet(const std::string& content, bool time, const std::string& morse_mode) {
|
||||
if (!time) {
|
||||
log_file.write_raw_no_newline("\r\n\r\n");
|
||||
auto timestamp = to_string_datetime(rtc_time::now(), YMDHMS);
|
||||
log_file.write_raw("[" + timestamp + "] ");
|
||||
radio_set_log(current_mode);
|
||||
radio_set_log(morse_mode);
|
||||
char_count = 0;
|
||||
time = true;
|
||||
}
|
||||
@@ -152,6 +156,8 @@ MorseRadioView::~MorseRadioView() {
|
||||
|
||||
void MorseRadioView::focus() {
|
||||
field_frequency.focus();
|
||||
txt_clip.set_style(Theme::getInstance()->fg_red);
|
||||
txt_clip.hidden(true);
|
||||
}
|
||||
|
||||
void MorseRadioView::check_for_timeout() {
|
||||
@@ -205,6 +211,8 @@ int32_t MorseRadioView::ProcessSignal(int32_t sig_time_us) {
|
||||
void MorseRadioView::on_data(const MorseRXDataMessage* message) {
|
||||
int32_t r;
|
||||
|
||||
txt_clip.hidden(!message->clipped);
|
||||
|
||||
for (uint8_t i = 0; i <= message->state_cnt; ++i) {
|
||||
r = ProcessSignal(message->state_durations[i]);
|
||||
auto result = morse_decoder_.handleInput((r != 0) ? r : 0);
|
||||
@@ -212,7 +220,7 @@ void MorseRadioView::on_data(const MorseRXDataMessage* message) {
|
||||
last_activity_time = chTimeNow(); // start reset timer on valid input
|
||||
writeCharToConsole(result.text, result.confidence);
|
||||
if (logger && save_log) {
|
||||
time_stamp = logger->on_packet(result.text, time_stamp, current_mode);
|
||||
time_stamp = logger->on_packet(result.text, time_stamp, options_mode.selected_index_name());
|
||||
}
|
||||
float dah_time = morse_decoder_.getCurrentTimeUnit() * 3.0f;
|
||||
if (dah_time > 0) {
|
||||
|
||||
@@ -54,8 +54,8 @@ class MorseLogger {
|
||||
}
|
||||
|
||||
void init_daily_log(const std::filesystem::path& log_dir);
|
||||
bool on_packet(const std::string& content, bool time, uint8_t current_mode);
|
||||
void radio_set_log(uint8_t current_mode);
|
||||
bool on_packet(const std::string& content, bool time, const std::string& morse_mode);
|
||||
void radio_set_log(const std::string& morse_mode);
|
||||
|
||||
private:
|
||||
LogFile log_file{};
|
||||
@@ -83,12 +83,21 @@ class MorseRadioView : public ui::View {
|
||||
RxRadioState radio_state_{};
|
||||
std::unique_ptr<MorseLogger> logger{};
|
||||
|
||||
uint8_t current_mode{0}; // 0=CW/FM, 1=USB, 2=LSB
|
||||
enum morse_modes : uint8_t {
|
||||
MORSE_AM_CW = 0,
|
||||
MORSE_NFM,
|
||||
MORSE_AM_DSB,
|
||||
MORSE_AM_USB,
|
||||
MORSE_AM_LSB,
|
||||
};
|
||||
uint8_t saved_mode = MORSE_AM_CW;
|
||||
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_morese_radio",
|
||||
"rx_morse_radio",
|
||||
app_settings::Mode::RX,
|
||||
{{"cwmode"sv, ¤t_mode}}};
|
||||
{
|
||||
{"cwmode"sv, &saved_mode},
|
||||
}};
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{UI_POS_X(0), UI_POS_Y(0)},
|
||||
@@ -115,6 +124,7 @@ class MorseRadioView : public ui::View {
|
||||
ui::Text txt_speed{{UI_POS_X(23), UI_POS_Y(1), UI_POS_WIDTH(3), UI_POS_HEIGHT(1)}, "??"};
|
||||
ui::Text txt_last{{UI_POS_X(12), UI_POS_Y(4), UI_POS_WIDTH_REMAINING(12), UI_POS_HEIGHT(1)}, ""};
|
||||
ui::Text txt_freq{{UI_POS_X(21), UI_POS_Y(2), UI_POS_WIDTH(5), UI_POS_HEIGHT(1)}, "??"};
|
||||
ui::Text txt_clip{{UI_POS_X(15), UI_POS_Y(3), UI_POS_WIDTH(5), UI_POS_HEIGHT(1)}, "clipping"};
|
||||
ui::Console console_text{{UI_POS_X(0), UI_POS_Y(5), UI_POS_MAXWIDTH, UI_POS_HEIGHT_REMAINING(7)}};
|
||||
ui::Labels labels{
|
||||
{{UI_POS_X(0), UI_POS_Y(1)}, "Squelch:", Theme::getInstance()->fg_light->foreground},
|
||||
@@ -125,9 +135,15 @@ class MorseRadioView : public ui::View {
|
||||
{{UI_POS_X(27), UI_POS_Y(2)}, "Hz", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
ui::OptionsField options_mode{
|
||||
{UI_POS_X(9), UI_POS_Y(2)},
|
||||
5,
|
||||
{{"CW/FM", 0}, {"USB", 1}, {"LSB", 2}}};
|
||||
{UI_POS_X(8), UI_POS_Y(2) + 4}, // +4 to align with 'Log' checkbox text
|
||||
6,
|
||||
{
|
||||
{"AM/CW", MORSE_AM_CW},
|
||||
{"NFM", MORSE_NFM},
|
||||
{"AM/DSB", MORSE_AM_DSB},
|
||||
{"AM/USB", MORSE_AM_USB},
|
||||
{"AM/LSB", MORSE_AM_LSB},
|
||||
}};
|
||||
|
||||
Checkbox chk_log{{UI_POS_X(0), UI_POS_Y(2)}, 12, "Log", false};
|
||||
ui::Button btn_clear{{UI_POS_X(0), UI_POS_Y_BOTTOM(2), UI_POS_WIDTH(6), UI_POS_HEIGHT(1)}, "CLR"};
|
||||
|
||||
@@ -239,10 +239,10 @@ void RandomPasswordView::on_freqchg(int64_t freq) {
|
||||
}
|
||||
|
||||
void RandomPasswordView::set_random_freq() {
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
// this is only for seed to visit random freq, the radio is still real random
|
||||
|
||||
auto random_freq = 100000000 + (std::rand() % 900000000); // 100mhz to 1ghz
|
||||
auto random_freq = 100000000 + (rand() % 900000000); // 100mhz to 1ghz
|
||||
receiver_model.set_target_frequency(random_freq);
|
||||
field_frequency.set_value(random_freq);
|
||||
}
|
||||
@@ -297,12 +297,12 @@ void RandomPasswordView::new_password() {
|
||||
/// roll worker
|
||||
for (int i = 0; i < password_length * 2; i += 2) {
|
||||
unsigned int seed = seeds_deque[i];
|
||||
std::srand(seed);
|
||||
srand(seed);
|
||||
uint8_t rollnum = (uint8_t)(seeds_deque[i + 1] % 128);
|
||||
uint8_t nu = 0;
|
||||
for (uint8_t o = 0; o < rollnum; ++o) nu = std::rand();
|
||||
for (uint8_t o = 0; o < rollnum; ++o) nu = rand();
|
||||
nu++;
|
||||
char c = charset[std::rand() % charset.length()];
|
||||
char c = charset[rand() % charset.length()];
|
||||
initial_password += c;
|
||||
}
|
||||
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
#include "baudot.hpp"
|
||||
#include <cctype>
|
||||
|
||||
namespace ui::external_app::rtty_rx {
|
||||
|
||||
constexpr uint8_t CODE_FIGS = 0x1B;
|
||||
constexpr uint8_t CODE_LTRS = 0x1F;
|
||||
constexpr uint8_t CODE_SPACE = 0x04;
|
||||
|
||||
char BaudotCoder::get_char_mapping(bool is_figures, uint8_t index) const {
|
||||
if (index >= 32) return 0; // Safety check
|
||||
|
||||
if (is_figures) {
|
||||
// ITA2 FIGURES Table
|
||||
const char figures[32] = {
|
||||
0, '3', '\n', '-', ' ', '\'', '8', '7',
|
||||
'\r', '$', '4', '\a', ',', '!', ':', '(',
|
||||
'5', '+', ')', '2', '#', '6', '0', '1',
|
||||
'9', '?', '&', 0, '.', '/', '=', 0};
|
||||
return figures[index];
|
||||
} else {
|
||||
// ITA2 LETTERS Table
|
||||
const char letters[32] = {
|
||||
0, 'E', '\n', 'A', ' ', 'S', 'I', 'U',
|
||||
'\r', 'D', 'R', 'J', 'N', 'F', 'C', 'K',
|
||||
'T', 'Z', 'L', 'W', 'H', 'Y', 'P', 'Q',
|
||||
'O', 'B', 'G', 0, 'M', 'X', 'V', 0};
|
||||
return letters[index];
|
||||
}
|
||||
}
|
||||
|
||||
// --- DECODE ---
|
||||
char BaudotCoder::decode(uint8_t baudotCode) {
|
||||
uint8_t code = baudotCode & 0x1F;
|
||||
if (code == CODE_FIGS) {
|
||||
shiftState = FIGURES;
|
||||
return 0;
|
||||
}
|
||||
if (code == CODE_LTRS) {
|
||||
shiftState = LETTERS;
|
||||
return 0;
|
||||
}
|
||||
if (usos_enabled && shiftState == FIGURES && code == CODE_SPACE) {
|
||||
shiftState = LETTERS;
|
||||
return ' ';
|
||||
}
|
||||
return get_char_mapping((shiftState == FIGURES), code);
|
||||
}
|
||||
|
||||
void BaudotCoder::encode(const std::string& src, uint8_t* dest, uint16_t* dest_length, uint16_t dest_max_size) {
|
||||
uint16_t idx = 0;
|
||||
|
||||
for (char c : src) {
|
||||
if (idx >= dest_max_size) break;
|
||||
|
||||
char upper_c = std::toupper(c);
|
||||
uint8_t code = 0;
|
||||
bool found = false;
|
||||
bool target_is_figures = false;
|
||||
if (upper_c == ' ') {
|
||||
code = CODE_SPACE;
|
||||
found = true;
|
||||
} else {
|
||||
for (int i = 1; i < 32; i++) {
|
||||
if (get_char_mapping(false, i) == upper_c) {
|
||||
code = i;
|
||||
found = true;
|
||||
target_is_figures = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
for (int i = 1; i < 32; i++) {
|
||||
if (get_char_mapping(true, i) == upper_c) {
|
||||
code = i;
|
||||
found = true;
|
||||
target_is_figures = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (target_is_figures && shiftState != FIGURES) {
|
||||
if (idx + 1 >= dest_max_size) break;
|
||||
dest[idx++] = CODE_FIGS;
|
||||
shiftState = FIGURES;
|
||||
} else if (!target_is_figures && shiftState != LETTERS && code != CODE_SPACE) {
|
||||
if (idx + 1 >= dest_max_size) break;
|
||||
dest[idx++] = CODE_LTRS;
|
||||
shiftState = LETTERS;
|
||||
}
|
||||
|
||||
dest[idx++] = code;
|
||||
}
|
||||
}
|
||||
|
||||
if (dest_length) {
|
||||
*dest_length = idx;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::rtty_rx
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef BAUDOT_HPP
|
||||
#define BAUDOT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace ui::external_app::rtty_rx {
|
||||
|
||||
class BaudotCoder {
|
||||
public:
|
||||
enum ShiftState { LETTERS,
|
||||
FIGURES };
|
||||
|
||||
BaudotCoder()
|
||||
: shiftState(LETTERS) {}
|
||||
char decode(uint8_t baudotCode);
|
||||
void encode(const std::string& src, uint8_t* dest, uint16_t* dest_length, uint16_t dest_max_size);
|
||||
void set_usos(bool enable) { usos_enabled = enable; } // shift == set to letters too
|
||||
|
||||
private:
|
||||
ShiftState shiftState;
|
||||
bool usos_enabled = true;
|
||||
char get_char_mapping(bool is_figures, uint8_t index) const;
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::rtty_rx
|
||||
|
||||
#endif // BAUDOT_HPP
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2026 HTotoo
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_rtty_rx.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::rtty_rx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<RttyRxView>();
|
||||
}
|
||||
} // namespace ui::external_app::rtty_rx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_rtty_rx.application_information"), used)) application_information_t _application_information_rtty_rx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::rtty_rx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "RTTY",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0xFE,
|
||||
0x1F,
|
||||
0xFE,
|
||||
0x3F,
|
||||
0x0E,
|
||||
0x78,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0E,
|
||||
0x78,
|
||||
0xFE,
|
||||
0x3F,
|
||||
0xFE,
|
||||
0x1F,
|
||||
0x8E,
|
||||
0x07,
|
||||
0x0E,
|
||||
0x0F,
|
||||
0x0E,
|
||||
0x1E,
|
||||
0x0E,
|
||||
0x3C,
|
||||
0x0E,
|
||||
0x78,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::orange().v,
|
||||
/*.menu_location = */ app_location_t::RX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_rttyrx */ {'P', 'R', 'T', 'R'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2026 HTotoo
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui_rtty_rx.hpp"
|
||||
|
||||
#include "audio.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace ui;
|
||||
|
||||
// todo add timeout, so add newline and time when new data arrives after a time.
|
||||
|
||||
namespace ui::external_app::rtty_rx {
|
||||
|
||||
void RttyRxView::focus() {
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
RttyRxView::RttyRxView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
add_children({
|
||||
&rssi,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_volume,
|
||||
&field_frequency,
|
||||
&labels,
|
||||
&options_baud,
|
||||
&console,
|
||||
});
|
||||
field_frequency.set_step(100);
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
audio::output::start();
|
||||
|
||||
receiver_model.set_hidden_offset(0);
|
||||
receiver_model.set_sampling_rate(3072000); // set the needed baseband SR.
|
||||
receiver_model.set_baseband_bandwidth(1750000); // set the front-end RF BW filter.
|
||||
receiver_model.enable();
|
||||
console.enable_scrolling(false);
|
||||
|
||||
options_baud.on_change = [this](size_t, int32_t value) {
|
||||
baseband::set_rtty_config(value, 170);
|
||||
baud_conf = value;
|
||||
};
|
||||
options_baud.set_by_value(baud_conf);
|
||||
if (baud_conf == 0) { // to trigger it when not changed
|
||||
baseband::set_rtty_config(0, 170);
|
||||
}
|
||||
}
|
||||
|
||||
void RttyRxView::got_message(std::string msg) {
|
||||
console.write(msg);
|
||||
}
|
||||
|
||||
RttyRxView::~RttyRxView() {
|
||||
receiver_model.set_hidden_offset(0);
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
audio::output::stop();
|
||||
}
|
||||
|
||||
void RttyRxView::on_data(const RTTYDataMessage* message) {
|
||||
std::string msg = "";
|
||||
for (size_t i = 0; i < message->data_len; i++) {
|
||||
const auto c = baudot_decoder.decode(message->data[i]);
|
||||
if (c != 0)
|
||||
msg += c;
|
||||
}
|
||||
got_message(msg);
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::rtty_rx
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2026 HTotoo
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __UI_RTTY_RX_H__
|
||||
#define __UI_RTTY_RX_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_language.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "baudot.hpp"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::rtty_rx {
|
||||
|
||||
class RttyRxView : public View {
|
||||
public:
|
||||
RttyRxView(NavigationView& nav);
|
||||
~RttyRxView();
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "RTTY"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{};
|
||||
uint32_t baud_conf = 0;
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_rtty",
|
||||
app_settings::Mode::RX,
|
||||
{
|
||||
{"baud_conf"sv, &baud_conf},
|
||||
}};
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{UI_POS_X(0), UI_POS_Y(0)},
|
||||
nav_};
|
||||
RFAmpField field_rf_amp{
|
||||
{UI_POS_X(13), UI_POS_Y(0)}};
|
||||
LNAGainField field_lna{
|
||||
{UI_POS_X(15), UI_POS_Y(0)}};
|
||||
VGAGainField field_vga{
|
||||
{UI_POS_X(18), UI_POS_Y(0)}};
|
||||
RSSI rssi{
|
||||
{UI_POS_X(21), UI_POS_Y(0), UI_POS_WIDTH_REMAINING(24), 4}};
|
||||
AudioVolumeField field_volume{{UI_POS_X_RIGHT(2), UI_POS_Y(0)}};
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), UI_POS_Y(1)}, "Baud:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
OptionsField options_baud{
|
||||
{UI_POS_X(7), UI_POS_Y(1)},
|
||||
5,
|
||||
{{"Auto", 0},
|
||||
{"45", 4500},
|
||||
{"45.45", 4545},
|
||||
{"50", 5000},
|
||||
{"75", 7500},
|
||||
{"100", 10000},
|
||||
{"110", 11000},
|
||||
{"150", 15000},
|
||||
{"200", 20000}}};
|
||||
|
||||
Console console{
|
||||
{UI_POS_X(0), UI_POS_Y(2), UI_POS_MAXWIDTH, UI_POS_HEIGHT_REMAINING(3)}};
|
||||
|
||||
BaudotCoder baudot_decoder{};
|
||||
|
||||
void on_data(const RTTYDataMessage* message);
|
||||
void got_message(std::string msg);
|
||||
|
||||
MessageHandlerRegistration message_handler_data{
|
||||
Message::ID::RTTYData,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const RTTYDataMessage*>(p);
|
||||
this->on_data(message);
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::rtty_rx
|
||||
|
||||
#endif /*__UI_RTTY_RX_H__*/
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
#include "baudot.hpp"
|
||||
#include <cctype>
|
||||
|
||||
namespace ui::external_app::rtty_tx {
|
||||
|
||||
constexpr uint8_t CODE_FIGS = 0x1B;
|
||||
constexpr uint8_t CODE_LTRS = 0x1F;
|
||||
constexpr uint8_t CODE_SPACE = 0x04;
|
||||
|
||||
char BaudotCoder::get_char_mapping(bool is_figures, uint8_t index) const {
|
||||
if (index >= 32) return 0; // Safety check
|
||||
|
||||
if (is_figures) {
|
||||
// ITA2 FIGURES Table
|
||||
const char figures[32] = {
|
||||
0, '3', '\n', '-', ' ', '\'', '8', '7',
|
||||
'\r', '$', '4', '\a', ',', '!', ':', '(',
|
||||
'5', '+', ')', '2', '#', '6', '0', '1',
|
||||
'9', '?', '&', 0, '.', '/', '=', 0};
|
||||
return figures[index];
|
||||
} else {
|
||||
// ITA2 LETTERS Table
|
||||
const char letters[32] = {
|
||||
0, 'E', '\n', 'A', ' ', 'S', 'I', 'U',
|
||||
'\r', 'D', 'R', 'J', 'N', 'F', 'C', 'K',
|
||||
'T', 'Z', 'L', 'W', 'H', 'Y', 'P', 'Q',
|
||||
'O', 'B', 'G', 0, 'M', 'X', 'V', 0};
|
||||
return letters[index];
|
||||
}
|
||||
}
|
||||
|
||||
// --- DECODE ---
|
||||
char BaudotCoder::decode(uint8_t baudotCode) {
|
||||
uint8_t code = baudotCode & 0x1F;
|
||||
if (code == CODE_FIGS) {
|
||||
shiftState = FIGURES;
|
||||
return 0;
|
||||
}
|
||||
if (code == CODE_LTRS) {
|
||||
shiftState = LETTERS;
|
||||
return 0;
|
||||
}
|
||||
if (usos_enabled && shiftState == FIGURES && code == CODE_SPACE) {
|
||||
shiftState = LETTERS;
|
||||
return ' ';
|
||||
}
|
||||
return get_char_mapping((shiftState == FIGURES), code);
|
||||
}
|
||||
|
||||
void BaudotCoder::encode(const std::string& src, uint8_t* dest, uint16_t* dest_length, uint16_t dest_max_size) {
|
||||
uint16_t idx = 0;
|
||||
|
||||
for (char c : src) {
|
||||
if (idx >= dest_max_size) break;
|
||||
|
||||
char upper_c = std::toupper(c);
|
||||
uint8_t code = 0;
|
||||
bool found = false;
|
||||
bool target_is_figures = false;
|
||||
if (upper_c == ' ') {
|
||||
code = CODE_SPACE;
|
||||
found = true;
|
||||
} else {
|
||||
for (int i = 1; i < 32; i++) {
|
||||
if (get_char_mapping(false, i) == upper_c) {
|
||||
code = i;
|
||||
found = true;
|
||||
target_is_figures = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
for (int i = 1; i < 32; i++) {
|
||||
if (get_char_mapping(true, i) == upper_c) {
|
||||
code = i;
|
||||
found = true;
|
||||
target_is_figures = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (target_is_figures && shiftState != FIGURES) {
|
||||
if (idx + 1 >= dest_max_size) break;
|
||||
dest[idx++] = CODE_FIGS;
|
||||
shiftState = FIGURES;
|
||||
} else if (!target_is_figures && shiftState != LETTERS && code != CODE_SPACE) {
|
||||
if (idx + 1 >= dest_max_size) break;
|
||||
dest[idx++] = CODE_LTRS;
|
||||
shiftState = LETTERS;
|
||||
}
|
||||
|
||||
dest[idx++] = code;
|
||||
}
|
||||
}
|
||||
|
||||
if (dest_length) {
|
||||
*dest_length = idx;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::rtty_tx
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef BAUDOT_HPP
|
||||
#define BAUDOT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace ui::external_app::rtty_tx {
|
||||
|
||||
class BaudotCoder {
|
||||
public:
|
||||
enum ShiftState { LETTERS,
|
||||
FIGURES };
|
||||
|
||||
BaudotCoder()
|
||||
: shiftState(LETTERS) {}
|
||||
char decode(uint8_t baudotCode);
|
||||
void encode(const std::string& src, uint8_t* dest, uint16_t* dest_length, uint16_t dest_max_size);
|
||||
void set_usos(bool enable) { usos_enabled = enable; } // shift == set to letters too
|
||||
|
||||
private:
|
||||
ShiftState shiftState;
|
||||
bool usos_enabled = true;
|
||||
char get_char_mapping(bool is_figures, uint8_t index) const;
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::rtty_tx
|
||||
|
||||
#endif // BAUDOT_HPP
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2026 HTotoo
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_rtty_tx.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::rtty_tx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<RttyTxView>();
|
||||
}
|
||||
} // namespace ui::external_app::rtty_tx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_rtty_tx.application_information"), used)) application_information_t _application_information_rtty_tx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::rtty_tx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "RTTY",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0xFE,
|
||||
0x1F,
|
||||
0xFE,
|
||||
0x3F,
|
||||
0x0E,
|
||||
0x78,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0E,
|
||||
0x78,
|
||||
0xFE,
|
||||
0x3F,
|
||||
0xFE,
|
||||
0x1F,
|
||||
0x8E,
|
||||
0x07,
|
||||
0x0E,
|
||||
0x0F,
|
||||
0x0E,
|
||||
0x1E,
|
||||
0x0E,
|
||||
0x3C,
|
||||
0x0E,
|
||||
0x78,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::orange().v,
|
||||
/*.menu_location = */ app_location_t::TX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_rttytx */ {'P', 'R', 'T', 'T'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2026 HTotoo
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui_rtty_tx.hpp"
|
||||
|
||||
#include "audio.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::rtty_tx {
|
||||
|
||||
void RttyTxView::focus() {
|
||||
options_baud.focus();
|
||||
}
|
||||
|
||||
RttyTxView::RttyTxView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
add_children({&tx_view,
|
||||
&labels,
|
||||
&options_baud,
|
||||
&options_shift,
|
||||
&btn_message,
|
||||
&text_message,
|
||||
&check_inverted,
|
||||
&options_tone,
|
||||
&text_tones});
|
||||
|
||||
options_baud.on_change = [this](size_t, int32_t value) {
|
||||
baud_conf = value;
|
||||
};
|
||||
options_baud.set_by_value(baud_conf);
|
||||
|
||||
options_shift.on_change = [this](size_t, int32_t value) {
|
||||
shift = value;
|
||||
refresh_tones();
|
||||
};
|
||||
options_shift.set_by_value(shift);
|
||||
|
||||
btn_message.on_select = [this](Button&) {
|
||||
text_prompt(nav_, message, 64, ENTER_KEYBOARD_MODE_ALPHA, [this](std::string& new_message) {
|
||||
message = new_message;
|
||||
text_message.set(message); // maybe replace to console
|
||||
});
|
||||
};
|
||||
text_message.set(message);
|
||||
options_tone.set_by_value(mark_tone);
|
||||
options_tone.on_change = [this](size_t, int32_t value) {
|
||||
mark_tone = value;
|
||||
refresh_tones();
|
||||
};
|
||||
check_inverted.on_select = [this](Checkbox&, bool) {
|
||||
refresh_tones();
|
||||
};
|
||||
|
||||
tx_view.on_edit_frequency = [this, &nav]() {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(transmitter_model.target_frequency());
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
transmitter_model.set_target_frequency(f);
|
||||
};
|
||||
};
|
||||
|
||||
tx_view.on_start = [this]() {
|
||||
if (message.empty()) {
|
||||
nav_.display_modal("Error", "Message is empty. Please set a message to transmit.");
|
||||
return;
|
||||
}
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
transmitter_model.set_baseband_bandwidth(2048000);
|
||||
baseband::set_sample_rate(2048000, OversampleRate::None);
|
||||
transmitter_model.set_sampling_rate(2048000);
|
||||
transmitter_model.set_baseband_bandwidth(2048000);
|
||||
transmitter_model.enable();
|
||||
rtty_message.baud = baud_conf;
|
||||
rtty_message.shift = shift;
|
||||
rtty_message.inverted = false; // check_inverted.value(); //i already invert it with the mark and space calculation
|
||||
rtty_message.mark_tone = mark;
|
||||
rtty_message.space_tone = space;
|
||||
rtty_message.stopbits = stop_bits;
|
||||
baudot_encoder.set_usos(false); // to be compatible with all
|
||||
baudot_encoder.encode(message, rtty_message.data, &rtty_message.data_len, rtty_message.max_len);
|
||||
baseband::set_rtty_config(rtty_message);
|
||||
tx_view.set_transmitting(true);
|
||||
};
|
||||
|
||||
tx_view.on_stop = [this]() {
|
||||
stop();
|
||||
};
|
||||
|
||||
refresh_tones();
|
||||
}
|
||||
|
||||
void RttyTxView::refresh_tones() {
|
||||
std::string tones_str = "";
|
||||
|
||||
int16_t shift = options_shift.selected_index_value();
|
||||
if (mark_tone == -32000) {
|
||||
mark = -shift / 2;
|
||||
space = shift / 2;
|
||||
} else {
|
||||
if (mark_tone < 0) {
|
||||
space = -(shift + abs(mark_tone));
|
||||
} else {
|
||||
space = shift + mark_tone;
|
||||
}
|
||||
mark = mark_tone;
|
||||
}
|
||||
|
||||
if (check_inverted.value()) {
|
||||
int16_t tmp = mark;
|
||||
mark = space;
|
||||
space = tmp;
|
||||
}
|
||||
tones_str = "Mark:" + to_string_dec_int(mark) + " Hz, Space:" + to_string_dec_int(space) + " Hz";
|
||||
text_tones.set(tones_str);
|
||||
}
|
||||
|
||||
void RttyTxView::on_tx_progress(bool done) {
|
||||
if (done) stop();
|
||||
}
|
||||
|
||||
void RttyTxView::stop() {
|
||||
tx_view.set_transmitting(false);
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
RttyTxView::~RttyTxView() {
|
||||
stop();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::rtty_tx
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2026 HTotoo
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __UI_RTTY_TX_H__
|
||||
#define __UI_RTTY_TX_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_language.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "baudot.hpp"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::rtty_tx {
|
||||
|
||||
class RttyTxView : public View {
|
||||
public:
|
||||
RttyTxView(NavigationView& nav);
|
||||
~RttyTxView();
|
||||
void focus() override;
|
||||
std::string title() const override { return "RTTY"; };
|
||||
|
||||
private:
|
||||
void on_tx_progress(bool done);
|
||||
void stop();
|
||||
void refresh_tones();
|
||||
|
||||
NavigationView& nav_;
|
||||
RxRadioState radio_state_{};
|
||||
uint32_t baud_conf = 4545; // default to 45.45 baud, which is common for RTTY.
|
||||
uint32_t shift = 170; // 170 hz
|
||||
std::string message = "PORTAPACK";
|
||||
int32_t mark_tone = 0; // for option
|
||||
int16_t mark = 0, space = 170;
|
||||
uint8_t stop_bits = 3; // 2=1.0, 3=1.5, 4=2.0
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_rtty",
|
||||
app_settings::Mode::TX,
|
||||
{
|
||||
{"baud_conf"sv, &baud_conf},
|
||||
{"shift"sv, &shift},
|
||||
{"message"sv, &message},
|
||||
{"mark_tone"sv, &mark_tone},
|
||||
}};
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), UI_POS_Y(0)}, "Baud:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(14), UI_POS_Y(0)}, "Shift:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(15), UI_POS_Y(1)}, "Mark t:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(3)}, "Message:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
OptionsField options_baud{
|
||||
{UI_POS_X(7), UI_POS_Y(0)},
|
||||
5,
|
||||
{{"45", 4500},
|
||||
{"45.45", 4545},
|
||||
{"50", 5000},
|
||||
{"75", 7500},
|
||||
{"100", 10000},
|
||||
{"110", 11000},
|
||||
{"150", 15000},
|
||||
{"200", 20000}}};
|
||||
|
||||
OptionsField options_shift{
|
||||
{UI_POS_X(21), UI_POS_Y(0)},
|
||||
5,
|
||||
{{"170", 170},
|
||||
{"85", 85},
|
||||
{"200", 200},
|
||||
{"450", 450},
|
||||
{"850", 850}}};
|
||||
|
||||
Checkbox check_inverted{
|
||||
{UI_POS_X(0), UI_POS_Y(1)},
|
||||
10,
|
||||
"Inverted",
|
||||
true};
|
||||
|
||||
OptionsField options_tone{
|
||||
{UI_POS_X(25), UI_POS_Y(1)},
|
||||
5,
|
||||
{{"CNT", -32000},
|
||||
{"0", 0},
|
||||
{"2125", 2125},
|
||||
{"-2125", -2125},
|
||||
{"1275", 1275},
|
||||
{"-1275", -1275}}};
|
||||
|
||||
Text text_tones{
|
||||
{UI_POS_X(0), UI_POS_Y(2), UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Button btn_message{
|
||||
{UI_POS_X(0), UI_POS_Y(3), UI_POS_WIDTH(15), UI_POS_HEIGHT(2)},
|
||||
"Set message"};
|
||||
|
||||
Text text_message{
|
||||
{UI_POS_X(0), UI_POS_Y(5), UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)},
|
||||
""};
|
||||
|
||||
TransmitterView tx_view{
|
||||
(int16_t)UI_POS_Y_BOTTOM(4),
|
||||
1000,
|
||||
0};
|
||||
|
||||
RTTYDataMessage rtty_message{};
|
||||
BaudotCoder baudot_encoder{};
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
this->on_tx_progress(message.done);
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::rtty_tx
|
||||
|
||||
#endif /*__UI_RTTY_TX_H__*/
|
||||
+1
-1
@@ -221,7 +221,7 @@ void SnakeView::paint(Painter& painter) {
|
||||
(void)painter;
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -91,6 +91,7 @@ SubCarView::SubCarView(NavigationView& nav)
|
||||
&button_clear_list,
|
||||
&check_log,
|
||||
&labels,
|
||||
&options_mode,
|
||||
&recent_entries_view});
|
||||
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
@@ -114,11 +115,17 @@ SubCarView::SubCarView(NavigationView& nav)
|
||||
recent_entries_view.on_select = [this](const SubCarRecentEntry& entry) {
|
||||
nav_.push<SubCarRecentEntryDetailView>(entry);
|
||||
};
|
||||
baseband::set_subghzd_config(0, receiver_model.sampling_rate()); // 0=am
|
||||
receiver_model.enable();
|
||||
|
||||
options_mode.on_change = [this](size_t, int32_t v) {
|
||||
modulation = v;
|
||||
chThdSleepMilliseconds(100); // wait for the baseband thread to process the previous config, to avoid glitchy output when switching modes
|
||||
baseband::set_subghzd_config(modulation, receiver_model.sampling_rate());
|
||||
};
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
on_tick_second();
|
||||
};
|
||||
options_mode.set_selected_index(modulation, true);
|
||||
receiver_model.enable();
|
||||
}
|
||||
|
||||
void SubCarView::on_tick_second() {
|
||||
@@ -176,6 +183,8 @@ const char* SubCarView::getSensorTypeName(FPROTO_SUBCAR_SENSOR type) {
|
||||
return "Fiat V0";
|
||||
case FPC_BMWV0:
|
||||
return "BMW V0";
|
||||
/* case FPC_KIAV6:
|
||||
return "Kia V6";*/
|
||||
|
||||
case FPC_Invalid:
|
||||
default:
|
||||
@@ -491,6 +500,13 @@ void SubCarRecentEntryDetailView::parseProtocol() {
|
||||
btn = to_string_dec_uint(button);
|
||||
}
|
||||
|
||||
/*if (entry_.sensorType == FPC_KIAV6) {
|
||||
// not decrypted!
|
||||
serial = 0;
|
||||
btn = "?";
|
||||
cnt = 0;
|
||||
}*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+19
-13
@@ -116,25 +116,27 @@ class SubCarView : public View {
|
||||
4'000'000 /* sampling rate */,
|
||||
ReceiverModel::Mode::AMAudio};
|
||||
bool logging = false;
|
||||
uint8_t modulation = 0;
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_subcar",
|
||||
app_settings::Mode::RX,
|
||||
{
|
||||
{"log"sv, &logging},
|
||||
{"modulationmode"sv, &modulation},
|
||||
}};
|
||||
|
||||
SubCarRecentEntries recent{};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{13 * 8, UI_POS_Y(0)}};
|
||||
{UI_POS_X(13), UI_POS_Y(0)}};
|
||||
LNAGainField field_lna{
|
||||
{15 * 8, UI_POS_Y(0)}};
|
||||
{UI_POS_X(15), UI_POS_Y(0)}};
|
||||
VGAGainField field_vga{
|
||||
{18 * 8, UI_POS_Y(0)}};
|
||||
{UI_POS_X(18), UI_POS_Y(0)}};
|
||||
RSSI rssi{
|
||||
{21 * 8, 0, UI_POS_WIDTH_REMAINING(24), 4}};
|
||||
{UI_POS_X(21), 0, UI_POS_WIDTH_REMAINING(24), 4}};
|
||||
Channel channel{
|
||||
{21 * 8, 5, UI_POS_WIDTH_REMAINING(24), 4},
|
||||
{UI_POS_X(21), 5, UI_POS_WIDTH_REMAINING(24), 4},
|
||||
};
|
||||
RxFrequencyField field_frequency{
|
||||
{UI_POS_X(0), UI_POS_Y(0)},
|
||||
@@ -143,18 +145,22 @@ class SubCarView : public View {
|
||||
SignalToken signal_token_tick_second{};
|
||||
|
||||
Button button_clear_list{
|
||||
{0, 16, 7 * 8, 32},
|
||||
{UI_POS_X(0), UI_POS_Y(1), UI_POS_WIDTH(7), UI_POS_HEIGHT(2)},
|
||||
"Clear"};
|
||||
|
||||
Checkbox check_log{
|
||||
{10 * 8, 18},
|
||||
{UI_POS_X(8), UI_POS_Y(1)},
|
||||
3,
|
||||
"Log",
|
||||
true};
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X_RIGHT(14), UI_POS_Y(1)}, "no fm yet :(", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(15), UI_POS_Y(1)}, "Mode:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
ui::OptionsField options_mode{
|
||||
{UI_POS_X(22), UI_POS_Y(1)},
|
||||
3,
|
||||
{{"AM", 0}, {"FM", 1}}};
|
||||
|
||||
static constexpr auto header_height = 3 * 16;
|
||||
|
||||
@@ -198,16 +204,16 @@ class SubCarRecentEntryDetailView : public View {
|
||||
std::string btn = "";
|
||||
uint32_t cnt = SD_NO_CNT;
|
||||
|
||||
Text text_type{{UI_POS_X(0), 1 * 16, 15 * 8, 16}, "?"};
|
||||
Text text_id{{6 * 8, 2 * 16, 10 * 8, 16}, "?"};
|
||||
Text text_type{{UI_POS_X(0), UI_POS_Y(1), UI_POS_WIDTH(15), UI_POS_HEIGHT(1)}, "?"};
|
||||
Text text_id{{UI_POS_X(6), UI_POS_Y(2), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)}, "?"};
|
||||
|
||||
Console console{
|
||||
{0, 4 * 16, screen_width, screen_height - (4 * 16) - 36}};
|
||||
{UI_POS_X(0), UI_POS_Y(4), UI_POS_MAXWIDTH, screen_height - (4 * 16) - 36}};
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), UI_POS_Y(0)}, "Type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 2 * 16}, "Serial: ", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 3 * 16}, "Data:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(2)}, "Serial: ", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(3)}, "Data:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
Button button_done{
|
||||
|
||||
+1
-1
@@ -605,7 +605,7 @@ void pause_game() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::srand(GenerateRandomSeed());
|
||||
srand(GenerateRandomSeed());
|
||||
Init();
|
||||
ShowLevelMenu();
|
||||
joystick.attach(&ReadJoystickForLevel, 0.3);
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ __attribute__((section(".external_app.app_tpmsrx.application_information"), used
|
||||
},
|
||||
/*.icon_color = */ ui::Color::green().v,
|
||||
/*.menu_location = */ app_location_t::RX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
/*.desired_menu_position = */ 7,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_tpms */ {'P', 'T', 'P', 'M'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
|
||||
+146
-8
@@ -42,16 +42,37 @@ std::string type(tpms::Reading::Type type) {
|
||||
return to_string_dec_uint(toUType(type), 2);
|
||||
}
|
||||
|
||||
std::string type_name(tpms::Reading::Type type) {
|
||||
switch (type) {
|
||||
case tpms::Reading::Type::None:
|
||||
return "None";
|
||||
case tpms::Reading::Type::FLM_64:
|
||||
return "FLM_64";
|
||||
case tpms::Reading::Type::FLM_72:
|
||||
return "FLM_72";
|
||||
case tpms::Reading::Type::FLM_80:
|
||||
return "FLM_80";
|
||||
case tpms::Reading::Type::Schrader:
|
||||
return "Schrader";
|
||||
case tpms::Reading::Type::GMC_96:
|
||||
return "GMC_96";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
std::string id(tpms::TransponderID id) {
|
||||
return to_string_hex(id.value(), 8);
|
||||
}
|
||||
|
||||
std::string pressure(Pressure pressure) {
|
||||
return to_string_dec_int(units_psi ? pressure.psi() : pressure.kilopascal(), 3);
|
||||
return to_string_dec_int(pressure_unit == PRESSURE_UNIT_PSI ? pressure.psi() : pressure_unit == PRESSURE_UNIT_BAR ? pressure.bar()
|
||||
: pressure.kilopascal(),
|
||||
3);
|
||||
}
|
||||
|
||||
std::string temperature(Temperature temperature) {
|
||||
return to_string_dec_int(units_fahr ? temperature.fahrenheit() : temperature.celsius(), 3);
|
||||
return to_string_dec_int(temp_unit == TEMP_UNIT_CELSIUS ? temperature.celsius() : temperature.fahrenheit(), 3);
|
||||
}
|
||||
|
||||
std::string flags(tpms::Flags flags) {
|
||||
@@ -99,7 +120,8 @@ void TPMSRecentEntry::update(const tpms::Reading& reading) {
|
||||
}
|
||||
}
|
||||
|
||||
TPMSAppView::TPMSAppView(NavigationView&) {
|
||||
TPMSAppView::TPMSAppView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
// baseband::run_image(portapack::spi_flash::image_tag_tpms);
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
|
||||
@@ -122,16 +144,21 @@ TPMSAppView::TPMSAppView(NavigationView&) {
|
||||
options_band.set_by_value(receiver_model.target_frequency());
|
||||
|
||||
options_pressure.on_change = [this](size_t, int32_t i) {
|
||||
format::units_psi = (bool)i;
|
||||
format::pressure_unit = (uint8_t)i;
|
||||
update_view();
|
||||
};
|
||||
options_pressure.set_selected_index(format::units_psi, true);
|
||||
options_pressure.set_by_value(format::pressure_unit);
|
||||
|
||||
options_temperature.on_change = [this](size_t, int32_t i) {
|
||||
format::units_fahr = (bool)i;
|
||||
format::temp_unit = (uint8_t)i;
|
||||
update_view();
|
||||
};
|
||||
options_temperature.set_selected_index(format::units_fahr, true);
|
||||
options_temperature.set_by_value(format::temp_unit);
|
||||
|
||||
// Add on_select handler for entries
|
||||
recent_entries_view.on_select = [this](const TPMSRecentEntry& entry) {
|
||||
on_show_detail(entry);
|
||||
};
|
||||
|
||||
logger = std::make_unique<TPMSLogger>();
|
||||
if (logger) {
|
||||
@@ -176,6 +203,7 @@ void TPMSAppView::on_packet(const tpms::Packet& packet) {
|
||||
const auto reading = reading_opt.value();
|
||||
auto& entry = ::on_packet(recent, TPMSRecentEntry::Key{reading.type(), reading.id()});
|
||||
entry.update(reading);
|
||||
entry.signal_type = packet.signal_type();
|
||||
recent_entries_view.set_dirty();
|
||||
}
|
||||
|
||||
@@ -189,6 +217,116 @@ void TPMSAppView::on_show_list() {
|
||||
recent_entries_view.focus();
|
||||
}
|
||||
|
||||
void TPMSAppView::on_show_detail(const TPMSRecentEntry& entry) {
|
||||
nav_.push<TPMSRecentEntryDetailView>(entry);
|
||||
}
|
||||
|
||||
// Detail view implementation
|
||||
TPMSRecentEntryDetailView::TPMSRecentEntryDetailView(NavigationView& nav, const TPMSRecentEntry& entry)
|
||||
: nav_{nav},
|
||||
entry_{entry} {
|
||||
add_children({&labels,
|
||||
&text_type,
|
||||
&text_id,
|
||||
&text_pressure,
|
||||
&text_temperature,
|
||||
&text_flags,
|
||||
&text_count,
|
||||
&button_done,
|
||||
&button_save});
|
||||
|
||||
// Display entry data
|
||||
text_type.set(format::type_name(entry.type));
|
||||
text_id.set(to_string_hex(entry.id.value(), 8));
|
||||
|
||||
if (entry.last_pressure.is_valid()) {
|
||||
std::string pressure_str = format::pressure(entry.last_pressure.value());
|
||||
std::string unit_str = format::pressure_unit == PRESSURE_UNIT_PSI ? " PSI" : format::pressure_unit == PRESSURE_UNIT_BAR ? " BAR"
|
||||
: " kPa";
|
||||
text_pressure.set(pressure_str + unit_str);
|
||||
} else {
|
||||
text_pressure.set("---");
|
||||
}
|
||||
|
||||
if (entry.last_temperature.is_valid()) {
|
||||
text_temperature.set(to_string_dec_int(entry.last_temperature.value().celsius(), 3) + " C");
|
||||
} else {
|
||||
text_temperature.set("---");
|
||||
}
|
||||
|
||||
if (entry.last_flags.is_valid()) {
|
||||
text_flags.set(to_string_hex(entry.last_flags.value(), 2));
|
||||
} else {
|
||||
text_flags.set("--");
|
||||
}
|
||||
|
||||
text_count.set(to_string_dec_uint(entry.received_count, 4));
|
||||
|
||||
button_done.on_select = [&nav](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
button_save.on_select = [this](Button&) {
|
||||
on_save();
|
||||
};
|
||||
}
|
||||
|
||||
void TPMSRecentEntryDetailView::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
void TPMSRecentEntryDetailView::set_entry(const TPMSRecentEntry& entry) {
|
||||
entry_ = entry;
|
||||
}
|
||||
|
||||
void TPMSRecentEntryDetailView::on_save() {
|
||||
auto timestamp = to_string_timestamp(rtc_time::now());
|
||||
std::string file_name = "TPMS_" + timestamp + ".TXT";
|
||||
ensure_directory(tpms_dir);
|
||||
auto file_path = tpms_dir / file_name;
|
||||
|
||||
if (save_file(file_path)) {
|
||||
nav_.display_modal("Saved", "Packet saved to:\n" + file_name);
|
||||
} else {
|
||||
nav_.display_modal("Error", "Failed to save\npacket");
|
||||
}
|
||||
}
|
||||
|
||||
bool TPMSRecentEntryDetailView::save_file(const std::filesystem::path& path) {
|
||||
File f;
|
||||
auto error = f.create(path);
|
||||
if (error.is_valid())
|
||||
return false;
|
||||
|
||||
// Save in format compatible with TX app
|
||||
std::string content = "Type=" + to_string_dec_uint(toUType(entry_.type), 1) + "\n";
|
||||
content += "ID=" + to_string_hex(entry_.id.value(), 8) + "\n";
|
||||
|
||||
if (entry_.last_pressure.is_valid()) {
|
||||
content += "Pressure=" + to_string_dec_int(entry_.last_pressure.value().kilopascal(), 1) + "\n";
|
||||
} else {
|
||||
content += "Pressure=240\n"; // Default value
|
||||
}
|
||||
|
||||
if (entry_.last_temperature.is_valid()) {
|
||||
content += "Temperature=" + to_string_dec_int(entry_.last_temperature.value().celsius(), 1) + "\n";
|
||||
} else {
|
||||
content += "Temperature=25\n"; // Default value
|
||||
}
|
||||
|
||||
if (entry_.last_flags.is_valid()) {
|
||||
content += "Flags=" + to_string_hex(entry_.last_flags.value(), 2) + "\n";
|
||||
} else {
|
||||
content += "Flags=00\n";
|
||||
}
|
||||
|
||||
// Save signal type for proper retransmission
|
||||
content += "SignalType=" + to_string_dec_uint(toUType(entry_.signal_type), 1) + "\n";
|
||||
|
||||
f.write(content.c_str(), content.length());
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::tpmsrx
|
||||
|
||||
namespace ui {
|
||||
@@ -239,4 +377,4 @@ void RecentEntriesTable<ui::external_app::tpmsrx::TPMSRecentEntries>::draw(
|
||||
painter.draw_string(target_rect.location(), style, line);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace ui
|
||||
|
||||
+73
-11
@@ -42,10 +42,9 @@ namespace ui::external_app::tpmsrx {
|
||||
|
||||
namespace format {
|
||||
|
||||
static bool units_psi{false};
|
||||
static bool units_fahr{false};
|
||||
|
||||
} /* namespace format */
|
||||
static uint8_t pressure_unit{PRESSURE_UNIT_KPA};
|
||||
static uint8_t temp_unit{TEMP_UNIT_CELSIUS};
|
||||
} // namespace format
|
||||
|
||||
struct TPMSRecentEntry {
|
||||
using Key = std::pair<tpms::Reading::Type, tpms::TransponderID>;
|
||||
@@ -54,6 +53,7 @@ struct TPMSRecentEntry {
|
||||
|
||||
tpms::Reading::Type type{invalid_key.first};
|
||||
tpms::TransponderID id{invalid_key.second};
|
||||
tpms::SignalType signal_type{tpms::SignalType::OOK_8k192_Schrader};
|
||||
|
||||
size_t received_count{0};
|
||||
|
||||
@@ -90,6 +90,64 @@ class TPMSLogger {
|
||||
|
||||
using TPMSRecentEntriesView = RecentEntriesView<TPMSRecentEntries>;
|
||||
|
||||
class TPMSRecentEntryDetailView : public View {
|
||||
public:
|
||||
TPMSRecentEntryDetailView(NavigationView& nav, const TPMSRecentEntry& entry);
|
||||
|
||||
void set_entry(const TPMSRecentEntry& entry);
|
||||
const TPMSRecentEntry& entry() const { return entry_; }
|
||||
|
||||
void focus() override;
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
TPMSRecentEntry entry_;
|
||||
|
||||
void on_save();
|
||||
bool save_file(const std::filesystem::path& path);
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 1 * 16}, "Type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 3 * 16}, "ID:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 5 * 16}, "Pressure:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 7 * 16}, "Temperature:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 9 * 16}, "Flags:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 11 * 16}, "Count:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
Text text_type{
|
||||
{8 * 8, 1 * 16, 20 * 8, 16},
|
||||
""};
|
||||
|
||||
Text text_id{
|
||||
{8 * 8, 3 * 16, 20 * 8, 16},
|
||||
""};
|
||||
|
||||
Text text_pressure{
|
||||
{12 * 8, 5 * 16, 16 * 8, 16},
|
||||
""};
|
||||
|
||||
Text text_temperature{
|
||||
{14 * 8, 7 * 16, 14 * 8, 16},
|
||||
""};
|
||||
|
||||
Text text_flags{
|
||||
{8 * 8, 9 * 16, 20 * 8, 16},
|
||||
""};
|
||||
|
||||
Text text_count{
|
||||
{8 * 8, 11 * 16, 20 * 8, 16},
|
||||
""};
|
||||
|
||||
Button button_save{
|
||||
{0 * 8, 13 * 16, 14 * 8, 32},
|
||||
"Save"};
|
||||
|
||||
Button button_done{
|
||||
{16 * 8, 13 * 16, 14 * 8, 32},
|
||||
"Done"};
|
||||
};
|
||||
|
||||
class TPMSAppView : public View {
|
||||
public:
|
||||
TPMSAppView(NavigationView& nav);
|
||||
@@ -106,6 +164,8 @@ class TPMSAppView : public View {
|
||||
std::string title() const override { return "TPMS RX"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
RxRadioState radio_state_{
|
||||
314900000 /* frequency*/
|
||||
,
|
||||
@@ -117,8 +177,8 @@ class TPMSAppView : public View {
|
||||
"rx_tpms",
|
||||
app_settings::Mode::RX,
|
||||
{
|
||||
{"units_psi"sv, &format::units_psi},
|
||||
{"units_fahr"sv, &format::units_fahr},
|
||||
{"pressure_unit"sv, &format::pressure_unit},
|
||||
{"temp_unit"sv, &format::temp_unit},
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
@@ -154,15 +214,16 @@ class TPMSAppView : public View {
|
||||
|
||||
OptionsField options_pressure{
|
||||
{6 * 8, UI_POS_Y(0)},
|
||||
3,
|
||||
{{"kPa", 0},
|
||||
{"PSI", 1}}};
|
||||
4,
|
||||
{{"kPa", PRESSURE_UNIT_KPA},
|
||||
{"PSI", PRESSURE_UNIT_PSI},
|
||||
{"BAR", PRESSURE_UNIT_BAR}}};
|
||||
|
||||
OptionsField options_temperature{
|
||||
{10 * 8, UI_POS_Y(0)},
|
||||
2,
|
||||
{{STR_DEGREES_C, 0},
|
||||
{STR_DEGREES_F, 1}}};
|
||||
{{STR_DEGREES_C, TEMP_UNIT_CELSIUS},
|
||||
{STR_DEGREES_F, TEMP_UNIT_FAHRENHEIT}}};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{13 * 8, UI_POS_Y(0)}};
|
||||
@@ -188,6 +249,7 @@ class TPMSAppView : public View {
|
||||
|
||||
void on_packet(const tpms::Packet& packet);
|
||||
void on_show_list();
|
||||
void on_show_detail(const TPMSRecentEntry& entry);
|
||||
void update_view();
|
||||
};
|
||||
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2026
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "tpms_tx_app.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::tpmstx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<TPMSTXView>();
|
||||
}
|
||||
} // namespace ui::external_app::tpmstx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_tpmstx.application_information"), used)) application_information_t _application_information_tpmstx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000, // will be filled at compile time
|
||||
/*.externalAppEntry = */ ui::external_app::tpmstx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "TPMS TX",
|
||||
/*.bitmap_data = */ {
|
||||
0xC0,
|
||||
0x03,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0x18,
|
||||
0x18,
|
||||
0xEC,
|
||||
0x37,
|
||||
0x36,
|
||||
0x6D,
|
||||
0x3A,
|
||||
0x59,
|
||||
0x4B,
|
||||
0xD5,
|
||||
0x8B,
|
||||
0xD3,
|
||||
0xCB,
|
||||
0xD1,
|
||||
0xAB,
|
||||
0xD2,
|
||||
0x9A,
|
||||
0x5C,
|
||||
0xB6,
|
||||
0x6C,
|
||||
0xEC,
|
||||
0x37,
|
||||
0x18,
|
||||
0x18,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xC0,
|
||||
0x03,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::green().v,
|
||||
/*.menu_location = */ app_location_t::TX,
|
||||
/*.desired_menu_position = */ 6,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_ook */ {'P', 'O', 'O', 'K'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,812 @@
|
||||
/*
|
||||
* Copyright (C) 2026
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "tpms_tx_app.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "spi_image.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
#include "ui_freqman.hpp"
|
||||
#include "manchester.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "encoders.hpp"
|
||||
#include "crc.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace tpms;
|
||||
|
||||
namespace ui::external_app::tpmstx {
|
||||
|
||||
void TPMSTXView::focus() {
|
||||
options_packet_type.focus();
|
||||
}
|
||||
|
||||
void TPMSTXView::update_signal_type_from_packet() {
|
||||
// Auto-select signal type based on packet type
|
||||
switch (packet_type_) {
|
||||
case tpms::Reading::Type::Schrader:
|
||||
signal_type_ = tpms::SignalType::OOK_8k192_Schrader;
|
||||
break;
|
||||
case tpms::Reading::Type::FLM_64:
|
||||
case tpms::Reading::Type::FLM_72:
|
||||
case tpms::Reading::Type::FLM_80:
|
||||
signal_type_ = tpms::SignalType::FSK_19k2_Schrader;
|
||||
break;
|
||||
case tpms::Reading::Type::GMC_96:
|
||||
signal_type_ = tpms::SignalType::OOK_8k4_Schrader;
|
||||
break;
|
||||
default:
|
||||
signal_type_ = tpms::SignalType::OOK_8k192_Schrader;
|
||||
break;
|
||||
}
|
||||
// Note: Don't call switch_baseband() here - it's called when needed
|
||||
}
|
||||
|
||||
void TPMSTXView::switch_baseband() {
|
||||
// Switch baseband image based on signal type
|
||||
// Must shutdown first to avoid BBRunning error
|
||||
baseband::shutdown();
|
||||
chThdSleepMilliseconds(100);
|
||||
|
||||
if (signal_type_ == tpms::SignalType::FSK_19k2_Schrader) {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_fsktx);
|
||||
} else {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_ook);
|
||||
}
|
||||
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
|
||||
void TPMSTXView::update_packet_display() {
|
||||
// Only update status text - field values are already set by user interaction
|
||||
// or by explicit set_value calls when loading from file
|
||||
std::string status = "ID:" + to_string_hex(transponder_id_, 8);
|
||||
|
||||
// Note protocol-specific limitations
|
||||
if (packet_type_ == tpms::Reading::Type::Schrader) {
|
||||
status = "ID:" + to_string_hex(transponder_id_ & 0x00FFFFFF, 6) + " (24bit)";
|
||||
}
|
||||
|
||||
status += " " + to_string_dec_uint(pressure_kpa_) + "kPa";
|
||||
|
||||
// Check for pressure overflow and warn user
|
||||
if (packet_type_ == tpms::Reading::Type::GMC_96) {
|
||||
if (pressure_kpa_ > 701) {
|
||||
status += " !MAX"; // GMC_96 max is 701 kPa (101.7 PSI)
|
||||
}
|
||||
} else {
|
||||
if (pressure_kpa_ > 340) {
|
||||
status += " !MAX"; // Schrader/FLM max is 340 kPa (49.3 PSI)
|
||||
}
|
||||
}
|
||||
|
||||
// Temperature note for protocols that support it
|
||||
if (packet_type_ == tpms::Reading::Type::GMC_96 ||
|
||||
packet_type_ == tpms::Reading::Type::FLM_64 ||
|
||||
packet_type_ == tpms::Reading::Type::FLM_72 ||
|
||||
packet_type_ == tpms::Reading::Type::FLM_80) {
|
||||
status += " " + to_string_dec_int(temperature_c_) + "C";
|
||||
} else {
|
||||
status += " (no temp)";
|
||||
}
|
||||
|
||||
text_status.set(status);
|
||||
}
|
||||
|
||||
void TPMSTXView::update_field_visibility() {
|
||||
// Schrader: Show Func, Hide Temp (no temperature support)
|
||||
// GMC_96, FLM_xx: Hide Func, Show Temp (temperature supported, no func field)
|
||||
if (packet_type_ == tpms::Reading::Type::Schrader) {
|
||||
// Show Func field and label
|
||||
label_flags.hidden(false);
|
||||
field_flags.hidden(false);
|
||||
// Hide Temp field, label, and unit selector
|
||||
label_temperature.hidden(true);
|
||||
field_temperature.hidden(true);
|
||||
options_temperature.hidden(true);
|
||||
// Show 24-bit ID field, hide 32-bit ID field
|
||||
field_transponder_id_24.hidden(false);
|
||||
field_transponder_id_32.hidden(true);
|
||||
} else {
|
||||
// Hide Func field and label
|
||||
label_flags.hidden(true);
|
||||
field_flags.hidden(true);
|
||||
// Show Temp field, label, and unit selector
|
||||
label_temperature.hidden(false);
|
||||
field_temperature.hidden(false);
|
||||
options_temperature.hidden(false);
|
||||
// Show 32-bit ID field, hide 24-bit ID field
|
||||
field_transponder_id_24.hidden(true);
|
||||
field_transponder_id_32.hidden(false);
|
||||
}
|
||||
// Force screen refresh to clear hidden widgets
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void TPMSTXView::on_pressure_unit_change() {
|
||||
// Convert displayed pressure to new unit and update field
|
||||
units::Pressure pressure(pressure_kpa_);
|
||||
int display_value = 0;
|
||||
|
||||
if (format::pressure_unit == PRESSURE_UNIT_PSI) {
|
||||
display_value = pressure.psi();
|
||||
} else if (format::pressure_unit == PRESSURE_UNIT_BAR) {
|
||||
display_value = pressure.bar();
|
||||
} else {
|
||||
display_value = pressure.kilopascal();
|
||||
}
|
||||
|
||||
field_pressure.set_value(display_value);
|
||||
}
|
||||
|
||||
void TPMSTXView::on_temperature_unit_change() {
|
||||
// Convert displayed temperature to new unit and update field
|
||||
units::Temperature temperature(temperature_c_);
|
||||
int display_value = 0;
|
||||
|
||||
if (format::temp_unit == TEMP_UNIT_FAHRENHEIT) {
|
||||
display_value = temperature.fahrenheit();
|
||||
} else {
|
||||
display_value = temperature.celsius();
|
||||
}
|
||||
|
||||
field_temperature.set_value(display_value);
|
||||
}
|
||||
|
||||
void TPMSTXView::encode_and_transmit() {
|
||||
if (!is_transmitting_) return;
|
||||
|
||||
// Build TPMS packet based on signal type
|
||||
std::string binary_string;
|
||||
uint32_t symbol_rate;
|
||||
uint32_t sample_rate;
|
||||
|
||||
// Set sample rate based on signal type to match transmitter config
|
||||
if (signal_type_ == tpms::SignalType::FSK_19k2_Schrader) {
|
||||
sample_rate = 2280000; // 2.28 MHz for FSK (matches transmitter_model config)
|
||||
} else {
|
||||
sample_rate = 2000000; // 2 MHz for OOK
|
||||
}
|
||||
|
||||
if (signal_type_ == tpms::SignalType::OOK_8k192_Schrader) {
|
||||
// Schrader OOK 8k192 format (Type = Schrader)
|
||||
// Preamble: 11*2, 01*14, 11, 10
|
||||
// Data: 3 bits function code, 24 bits ID, 8 bits pressure, 2 bits checksum
|
||||
// Total: 37 Manchester symbols (74 bits after encoding)
|
||||
// NOTE: This protocol does NOT support temperature transmission
|
||||
// NOTE: Only lower 24 bits of ID are transmitted
|
||||
// NOTE: Function code (flags_) is stored as 3-bit value (0-7)
|
||||
// RX will display it combined with checksum in upper nibble
|
||||
|
||||
symbol_rate = 8192;
|
||||
|
||||
// Preamble as expected by RX decoder
|
||||
binary_string = "1111"; // 11*2
|
||||
for (int i = 0; i < 14; i++) {
|
||||
binary_string += "01";
|
||||
}
|
||||
binary_string += "1110"; // 11, 10
|
||||
|
||||
// Build data bits (pre-Manchester)
|
||||
uint64_t data = 0;
|
||||
|
||||
// 3-bit flags (0-7, stored directly)
|
||||
uint8_t flags_3bit = flags_ & 0x07;
|
||||
data |= ((uint64_t)flags_3bit << 34);
|
||||
|
||||
// 24-bit ID (only use lower 24 bits - protocol limitation)
|
||||
uint32_t id_24bit = transponder_id_ & 0x00FFFFFF;
|
||||
data |= ((uint64_t)id_24bit << 10);
|
||||
|
||||
// 8-bit pressure (convert kPa to raw: kPa * 3/4)
|
||||
// Clamp to prevent overflow: max raw = 255, max kPa = 255 * 4/3 = 340 (49.3 PSI)
|
||||
uint16_t pressure_clamped = (pressure_kpa_ > 340) ? 340 : pressure_kpa_;
|
||||
uint8_t pressure_raw = (pressure_clamped * 3 / 4);
|
||||
data |= ((uint64_t)pressure_raw << 2);
|
||||
|
||||
// Calculate 2-bit checksum: sum all 2-bit pairs, result & 3 must equal 3
|
||||
uint32_t checksum_calc = (data >> 36) & 1; // First bit
|
||||
for (size_t i = 1; i < 37; i += 2) {
|
||||
checksum_calc += (data >> (37 - i - 2)) & 3;
|
||||
}
|
||||
uint8_t checksum_2bit = (3 - (checksum_calc & 3)) & 3;
|
||||
data |= checksum_2bit;
|
||||
|
||||
// Manchester encode the 37 data bits
|
||||
for (int i = 36; i >= 0; i--) {
|
||||
if ((data >> i) & 1) {
|
||||
binary_string += "10"; // '1' = 10 in Manchester
|
||||
} else {
|
||||
binary_string += "01"; // '0' = 01 in Manchester
|
||||
}
|
||||
}
|
||||
|
||||
} else if (signal_type_ == tpms::SignalType::OOK_8k4_Schrader) {
|
||||
// GMC_96 OOK 8k4 format
|
||||
symbol_rate = 8400;
|
||||
|
||||
// Preamble: 01*40
|
||||
for (int i = 0; i < 40; i++) {
|
||||
binary_string += "01";
|
||||
}
|
||||
|
||||
// First nibble of System ID (0x4) - part of preamble pattern match
|
||||
// RX looks for pattern ending with: 01010101...01100101
|
||||
// The "01100101" = Manchester for 0x4, and is consumed by pattern matcher
|
||||
binary_string += "01"; // 0
|
||||
binary_string += "10"; // 1
|
||||
binary_string += "01"; // 0
|
||||
binary_string += "01"; // 0 (0100 = 0x4)
|
||||
|
||||
// Remaining 20 bits of system ID (padding with zeros)
|
||||
// These are the first 20 bits of the 76-bit payload
|
||||
for (int i = 0; i < 20; i++) {
|
||||
binary_string += "01"; // All zeros for padding
|
||||
}
|
||||
|
||||
// 32-bit ID (Manchester encoded)
|
||||
for (int i = 31; i >= 0; i--) {
|
||||
if ((transponder_id_ >> i) & 1) {
|
||||
binary_string += "10";
|
||||
} else {
|
||||
binary_string += "01";
|
||||
}
|
||||
}
|
||||
|
||||
// Pressure: kPa * 4/11
|
||||
// Clamp to prevent overflow: max raw = 255, max kPa = 255 * 11/4 = 701.25 (101.7 PSI)
|
||||
uint16_t pressure_clamped = (pressure_kpa_ > 701) ? 701 : pressure_kpa_;
|
||||
uint8_t pressure_gmc = (pressure_clamped * 4 / 11);
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
if ((pressure_gmc >> i) & 1) {
|
||||
binary_string += "10";
|
||||
} else {
|
||||
binary_string += "01";
|
||||
}
|
||||
}
|
||||
|
||||
// Temperature: temp + 61
|
||||
uint8_t temp_gmc = (temperature_c_ + 61) & 0xFF;
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
if ((temp_gmc >> i) & 1) {
|
||||
binary_string += "10";
|
||||
} else {
|
||||
binary_string += "01";
|
||||
}
|
||||
}
|
||||
|
||||
// Checksum: sum of all data bytes (system ID + ID + pressure + temp)
|
||||
// System ID byte 0: (0x4 << 4) | 0x0 = 0x40
|
||||
// System ID byte 1: 0x00
|
||||
// System ID byte 2: 0x00
|
||||
uint8_t checksum = 0x40; // First byte of system ID
|
||||
checksum += 0x00; // Second byte of system ID
|
||||
checksum += 0x00; // Third byte of system ID
|
||||
|
||||
// Add all 4 bytes of the ID
|
||||
checksum += (transponder_id_ >> 24) & 0xFF;
|
||||
checksum += (transponder_id_ >> 16) & 0xFF;
|
||||
checksum += (transponder_id_ >> 8) & 0xFF;
|
||||
checksum += transponder_id_ & 0xFF;
|
||||
|
||||
// Add pressure and temperature
|
||||
checksum += pressure_gmc;
|
||||
checksum += temp_gmc;
|
||||
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
if ((checksum >> i) & 1) {
|
||||
binary_string += "10";
|
||||
} else {
|
||||
binary_string += "01";
|
||||
}
|
||||
}
|
||||
|
||||
} else if (signal_type_ == tpms::SignalType::FSK_19k2_Schrader) {
|
||||
// FSK 19.2k for FLM variants
|
||||
// Data is Manchester encoded: each data bit becomes two FSK symbols
|
||||
// Preamble: 14 x '01' + '10' = 30 bits (matches RX pattern exactly)
|
||||
// Payload: 160 Manchester-encoded bits (80 data bits max)
|
||||
|
||||
symbol_rate = 19200;
|
||||
|
||||
// Build preamble: 14 pairs of "01" followed by "10"
|
||||
for (int i = 0; i < 14; i++) {
|
||||
binary_string += "01";
|
||||
}
|
||||
binary_string += "10";
|
||||
|
||||
std::array<uint8_t, 20> data_bytes = {0}; // 160 bits = 20 bytes max
|
||||
size_t num_data_bits = 0;
|
||||
|
||||
if (packet_type_ == tpms::Reading::Type::FLM_64) {
|
||||
// FLM_64: 64 bits (8 bytes)
|
||||
// Bytes 0-3: ID (32 bits)
|
||||
// Byte 4: Pressure (8 bits)
|
||||
// Byte 5: Temperature (8 bits, LSB 7 bits used)
|
||||
// Byte 6: Padding
|
||||
// Byte 7: Sum checksum of bytes 0-6 (low 8 bits)
|
||||
|
||||
num_data_bits = 64;
|
||||
|
||||
data_bytes[0] = (transponder_id_ >> 24) & 0xFF;
|
||||
data_bytes[1] = (transponder_id_ >> 16) & 0xFF;
|
||||
data_bytes[2] = (transponder_id_ >> 8) & 0xFF;
|
||||
data_bytes[3] = transponder_id_ & 0xFF;
|
||||
// Clamp pressure to prevent overflow: max 340 kPa (49.3 PSI)
|
||||
uint16_t pressure_clamped_flm64 = (pressure_kpa_ > 340) ? 340 : pressure_kpa_;
|
||||
data_bytes[4] = (pressure_clamped_flm64 * 3 / 4);
|
||||
data_bytes[5] = ((temperature_c_ + 56) & 0x7F); // LSB 7 bits only
|
||||
data_bytes[6] = 0x00; // Padding
|
||||
|
||||
// Addition checksum over bytes 0-6
|
||||
uint32_t checksum = 0;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
checksum += data_bytes[i];
|
||||
}
|
||||
data_bytes[7] = checksum & 0xFF;
|
||||
|
||||
} else if (packet_type_ == tpms::Reading::Type::FLM_72) {
|
||||
// FLM_72: 72 bits (9 bytes)
|
||||
// Bytes 0-3: ID (32 bits)
|
||||
// Byte 4: Padding
|
||||
// Byte 5: Pressure (8 bits)
|
||||
// Byte 6: Temperature (8 bits)
|
||||
// Bytes 7-8: CRC field - RX processes ALL 9 bytes and expects CRC result = 0
|
||||
|
||||
num_data_bits = 72;
|
||||
|
||||
data_bytes[0] = (transponder_id_ >> 24) & 0xFF;
|
||||
data_bytes[1] = (transponder_id_ >> 16) & 0xFF;
|
||||
data_bytes[2] = (transponder_id_ >> 8) & 0xFF;
|
||||
data_bytes[3] = transponder_id_ & 0xFF;
|
||||
data_bytes[4] = 0x00; // Padding
|
||||
// Clamp pressure to prevent overflow: max 340 kPa (49.3 PSI)
|
||||
uint16_t pressure_clamped_flm = (pressure_kpa_ > 340) ? 340 : pressure_kpa_;
|
||||
data_bytes[5] = (pressure_clamped_flm * 3 / 4);
|
||||
data_bytes[6] = (temperature_c_ + 56) & 0xFF;
|
||||
data_bytes[7] = 0x00; // Set to 0 initially
|
||||
|
||||
// Calculate CRC over bytes 0-7, place result in byte 8
|
||||
// When RX calculates CRC over bytes 0-8, it should get residual 0
|
||||
CRC<8> crc{0x01, 0x00};
|
||||
for (int i = 0; i < 8; i++) {
|
||||
crc.process_byte(data_bytes[i]);
|
||||
}
|
||||
data_bytes[8] = crc.checksum() & 0xFF;
|
||||
|
||||
} else if (packet_type_ == tpms::Reading::Type::FLM_80) {
|
||||
// FLM_80: 80 bits (10 bytes)
|
||||
// Byte 0: Padding
|
||||
// Bytes 1-4: ID (32 bits)
|
||||
// Byte 5: Padding
|
||||
// Byte 6: Pressure (8 bits)
|
||||
// Byte 7: Temperature (8 bits)
|
||||
// Bytes 8-9: CRC field - RX processes bytes 1-9 and expects CRC result = 0
|
||||
|
||||
num_data_bits = 80;
|
||||
|
||||
data_bytes[0] = 0x00; // Padding (not included in CRC)
|
||||
data_bytes[1] = (transponder_id_ >> 24) & 0xFF;
|
||||
data_bytes[2] = (transponder_id_ >> 16) & 0xFF;
|
||||
data_bytes[3] = (transponder_id_ >> 8) & 0xFF;
|
||||
data_bytes[4] = transponder_id_ & 0xFF;
|
||||
data_bytes[5] = 0x00; // Padding
|
||||
// Clamp pressure to prevent overflow: max 340 kPa (49.3 PSI)
|
||||
uint16_t pressure_clamped_flm80 = (pressure_kpa_ > 340) ? 340 : pressure_kpa_;
|
||||
data_bytes[6] = (pressure_clamped_flm80 * 3 / 4);
|
||||
data_bytes[7] = (temperature_c_ + 56) & 0xFF;
|
||||
data_bytes[8] = 0x00; // Padding/Reserved
|
||||
data_bytes[9] = 0x00; // CRC byte
|
||||
|
||||
// Calculate CRC over bytes 1-8 (all bytes except 0 and 9)
|
||||
// When RX calculates CRC over bytes 1-9, it should get residual 0
|
||||
CRC<8> crc{0x01, 0x00};
|
||||
for (int i = 1; i <= 8; i++) {
|
||||
crc.process_byte(data_bytes[i]);
|
||||
}
|
||||
data_bytes[9] = crc.checksum() & 0xFF;
|
||||
}
|
||||
|
||||
// Manchester-encode data bits for FSK
|
||||
// RX ManchesterDecoder with sense=0: '1' = "10", '0' = "01"
|
||||
size_t num_bytes = num_data_bits / 8;
|
||||
for (size_t byte_idx = 0; byte_idx < num_bytes; byte_idx++) {
|
||||
uint8_t byte_val = data_bytes[byte_idx];
|
||||
for (int bit_idx = 7; bit_idx >= 0; bit_idx--) {
|
||||
if ((byte_val >> bit_idx) & 1) {
|
||||
binary_string += "10"; // Manchester '1'
|
||||
} else {
|
||||
binary_string += "01"; // Manchester '0'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pad payload to 160 bits with valid Manchester pairs ("01" = 0)
|
||||
// Using proper Manchester encoding maintains clock recovery sync
|
||||
while (binary_string.length() < 190) { // 30 preamble + 160 payload
|
||||
binary_string += "01"; // Manchester-encoded zero
|
||||
}
|
||||
|
||||
} else {
|
||||
text_status.set("Unknown signal type");
|
||||
stop_tx();
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert binary string to bitstream
|
||||
size_t bitstream_length = encoders::make_bitstream(binary_string);
|
||||
|
||||
// Calculate samples per bit (round to nearest for best timing accuracy)
|
||||
uint32_t samples_per_bit = (sample_rate + symbol_rate / 2) / symbol_rate;
|
||||
|
||||
// Update status to show we're sending
|
||||
text_status.set("TX: " + to_string_dec_uint(binary_string.length()) + " bits");
|
||||
|
||||
// Send via appropriate baseband (OOK or FSK)
|
||||
if (signal_type_ == tpms::SignalType::FSK_19k2_Schrader) {
|
||||
// FSK mode: 19.2 kbaud, 38.4 kHz shift
|
||||
baseband::set_fsk_data(
|
||||
bitstream_length,
|
||||
samples_per_bit,
|
||||
38400, // 38.4 kHz shift
|
||||
256); // Progress notice interval
|
||||
} else {
|
||||
// OOK mode
|
||||
baseband::set_ook_data(
|
||||
bitstream_length,
|
||||
samples_per_bit,
|
||||
repeat_count_,
|
||||
pause_duration_);
|
||||
}
|
||||
}
|
||||
|
||||
void TPMSTXView::handle_tx_complete() {
|
||||
// For FSK (FLM packets), handle repeats at application level
|
||||
// OOK repeats are handled by the baseband processor
|
||||
if (signal_type_ == tpms::SignalType::FSK_19k2_Schrader) {
|
||||
fsk_repeat_counter_++;
|
||||
|
||||
if (fsk_repeat_counter_ < repeat_count_) {
|
||||
// More repeats needed - send the next one
|
||||
// Update progress bar
|
||||
progressbar.set_value(fsk_repeat_counter_);
|
||||
|
||||
// Wait for FSK processor to fully complete and reset
|
||||
// This allows the shared memory bitstream to be safely rewritten
|
||||
chThdSleepMilliseconds(50);
|
||||
|
||||
encode_and_transmit();
|
||||
} else {
|
||||
// All FSK repeats complete
|
||||
stop_tx();
|
||||
}
|
||||
} else {
|
||||
// OOK repeats are handled by baseband, just stop here
|
||||
stop_tx();
|
||||
}
|
||||
}
|
||||
|
||||
void TPMSTXView::start_tx() {
|
||||
if (is_transmitting_)
|
||||
return;
|
||||
|
||||
is_transmitting_ = true;
|
||||
|
||||
progressbar.set_max(repeat_count_);
|
||||
progressbar.set_value(0);
|
||||
|
||||
button_transmit.set_text("STOP TX");
|
||||
text_status.set("Transmitting...");
|
||||
|
||||
// Initialize FSK repeat counter for application-level repeat handling
|
||||
fsk_repeat_counter_ = 0;
|
||||
|
||||
// Switch to appropriate baseband before transmission
|
||||
switch_baseband();
|
||||
|
||||
// Configure transmitter based on modulation type
|
||||
if (signal_type_ == tpms::SignalType::FSK_19k2_Schrader) {
|
||||
// FSK configuration
|
||||
transmitter_model.set_sampling_rate(2280000); // 2.28 MHz for FSK
|
||||
transmitter_model.set_baseband_bandwidth(1750000);
|
||||
} else {
|
||||
// OOK configuration
|
||||
transmitter_model.set_sampling_rate(2000000); // 2 MHz for OOK
|
||||
transmitter_model.set_baseband_bandwidth(1750000);
|
||||
}
|
||||
|
||||
transmitter_model.enable();
|
||||
|
||||
// Start transmission
|
||||
encode_and_transmit();
|
||||
}
|
||||
|
||||
void TPMSTXView::stop_tx() {
|
||||
if (!is_transmitting_)
|
||||
return;
|
||||
|
||||
is_transmitting_ = false;
|
||||
transmitter_model.disable();
|
||||
|
||||
button_transmit.set_text("START TX");
|
||||
text_status.set("Transmission complete");
|
||||
progressbar.set_value(0);
|
||||
}
|
||||
|
||||
TPMSTXView::TPMSTXView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
// Start with OOK baseband (will switch if needed)
|
||||
baseband::run_image(portapack::spi_flash::image_tag_ook);
|
||||
|
||||
add_children({&labels,
|
||||
&label_temperature,
|
||||
&label_flags,
|
||||
&options_frequency,
|
||||
&options_packet_type,
|
||||
&field_transponder_id_24,
|
||||
&field_transponder_id_32,
|
||||
&field_pressure,
|
||||
&options_pressure,
|
||||
&field_temperature,
|
||||
&options_temperature,
|
||||
&field_flags,
|
||||
&field_repeat,
|
||||
&button_load,
|
||||
&button_save,
|
||||
&tx_view,
|
||||
&button_transmit,
|
||||
&text_status,
|
||||
&progressbar});
|
||||
|
||||
// Set label styles to match other labels (light grey)
|
||||
label_temperature.set_style(Theme::getInstance()->fg_light);
|
||||
label_flags.set_style(Theme::getInstance()->fg_light);
|
||||
|
||||
// Initialize values
|
||||
options_frequency.set_by_value(transmitter_model.target_frequency());
|
||||
options_packet_type.set_selected_index(0);
|
||||
field_repeat.set_value(repeat_count_);
|
||||
|
||||
// Set initial signal type based on packet type
|
||||
update_signal_type_from_packet();
|
||||
|
||||
// Initialize unit selection
|
||||
options_pressure.set_by_value(format::pressure_unit);
|
||||
options_temperature.set_by_value(format::temp_unit);
|
||||
|
||||
// Initialize field values from default member variables
|
||||
// For pressure and temperature, use unit conversion to display in selected units
|
||||
field_transponder_id_24.set_value(transponder_id_ & 0x00FFFFFF);
|
||||
field_transponder_id_32.set_value(transponder_id_);
|
||||
on_pressure_unit_change();
|
||||
on_temperature_unit_change();
|
||||
field_flags.set_value(flags_);
|
||||
|
||||
update_field_visibility();
|
||||
update_packet_display();
|
||||
|
||||
// Event handlers
|
||||
options_frequency.on_change = [this](size_t, OptionsField::value_t v) {
|
||||
transmitter_model.set_target_frequency(v);
|
||||
};
|
||||
|
||||
options_packet_type.on_change = [this](size_t, int32_t value) {
|
||||
packet_type_ = static_cast<tpms::Reading::Type>(value);
|
||||
update_signal_type_from_packet();
|
||||
|
||||
// Sync field values when switching packet types
|
||||
if (packet_type_ == tpms::Reading::Type::Schrader) {
|
||||
// Switching to Schrader: copy from 32-bit field to 24-bit field (masked)
|
||||
transponder_id_ = field_transponder_id_32.to_integer() & 0x00FFFFFF;
|
||||
field_transponder_id_24.set_value(transponder_id_);
|
||||
} else {
|
||||
// Switching from Schrader: copy from 24-bit field to 32-bit field
|
||||
transponder_id_ = field_transponder_id_24.to_integer();
|
||||
field_transponder_id_32.set_value(transponder_id_);
|
||||
}
|
||||
|
||||
update_field_visibility();
|
||||
update_packet_display();
|
||||
};
|
||||
|
||||
options_pressure.on_change = [this](size_t, int32_t i) {
|
||||
format::pressure_unit = (uint8_t)i;
|
||||
on_pressure_unit_change();
|
||||
};
|
||||
|
||||
options_temperature.on_change = [this](size_t, int32_t i) {
|
||||
format::temp_unit = (uint8_t)i;
|
||||
on_temperature_unit_change();
|
||||
};
|
||||
|
||||
field_transponder_id_24.on_change = [this](SymField&) {
|
||||
transponder_id_ = field_transponder_id_24.to_integer() & 0x00FFFFFF;
|
||||
update_packet_display();
|
||||
};
|
||||
|
||||
field_transponder_id_32.on_change = [this](SymField&) {
|
||||
transponder_id_ = field_transponder_id_32.to_integer();
|
||||
update_packet_display();
|
||||
};
|
||||
|
||||
field_pressure.on_change = [this](int32_t value) {
|
||||
// Convert from displayed unit to kPa for internal storage
|
||||
if (format::pressure_unit == PRESSURE_UNIT_PSI) {
|
||||
pressure_kpa_ = value * 6895 / 1000;
|
||||
} else if (format::pressure_unit == PRESSURE_UNIT_BAR) {
|
||||
pressure_kpa_ = value * 100;
|
||||
} else {
|
||||
pressure_kpa_ = value;
|
||||
}
|
||||
update_packet_display();
|
||||
};
|
||||
|
||||
field_temperature.on_change = [this](int32_t value) {
|
||||
// Convert from displayed unit to Celsius for internal storage
|
||||
if (format::temp_unit == TEMP_UNIT_FAHRENHEIT) {
|
||||
temperature_c_ = (value - 32) * 5 / 9;
|
||||
} else {
|
||||
temperature_c_ = value;
|
||||
}
|
||||
update_packet_display();
|
||||
};
|
||||
|
||||
field_flags.on_change = [this](int32_t value) {
|
||||
flags_ = value & 0x07;
|
||||
update_packet_display();
|
||||
};
|
||||
|
||||
field_repeat.on_change = [this](int32_t value) {
|
||||
repeat_count_ = value;
|
||||
};
|
||||
|
||||
button_transmit.on_select = [this](Button&) {
|
||||
if (is_transmitting_) {
|
||||
stop_tx();
|
||||
} else {
|
||||
start_tx();
|
||||
}
|
||||
};
|
||||
|
||||
button_load.on_select = [this, &nav](Button&) {
|
||||
auto open_view = nav.push<FileLoadView>(".TXT");
|
||||
open_view->on_changed = [this](std::filesystem::path file_path) {
|
||||
// Load TPMS packet from file
|
||||
File f;
|
||||
auto error = f.open(file_path);
|
||||
if (!error.is_valid()) {
|
||||
char buffer[512];
|
||||
auto result = f.read(buffer, sizeof(buffer) - 1);
|
||||
if (result.is_ok()) {
|
||||
buffer[result.value()] = 0;
|
||||
|
||||
// Parse the file format (key=value format, one per line)
|
||||
std::string content(buffer);
|
||||
size_t pos = 0;
|
||||
|
||||
auto parse_line = [&content, &pos](const std::string& key) -> std::string {
|
||||
size_t key_pos = content.find(key + "=", pos);
|
||||
if (key_pos != std::string::npos) {
|
||||
size_t value_start = key_pos + key.length() + 1;
|
||||
size_t value_end = content.find('\n', value_start);
|
||||
if (value_end == std::string::npos) value_end = content.length();
|
||||
return content.substr(value_start, value_end - value_start);
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
std::string type_str = parse_line("Type");
|
||||
std::string id_str = parse_line("ID");
|
||||
std::string pressure_str = parse_line("Pressure");
|
||||
std::string temp_str = parse_line("Temperature");
|
||||
std::string flags_str = parse_line("Flags");
|
||||
std::string signal_type_str = parse_line("SignalType");
|
||||
|
||||
if (!type_str.empty()) {
|
||||
int type = std::stoi(type_str);
|
||||
if (type >= static_cast<int>(tpms::Reading::Type::FLM_64) &&
|
||||
type <= static_cast<int>(tpms::Reading::Type::GMC_96)) {
|
||||
packet_type_ = static_cast<tpms::Reading::Type>(type);
|
||||
options_packet_type.set_by_value(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (!id_str.empty()) {
|
||||
transponder_id_ = std::stoul(id_str, nullptr, 16);
|
||||
field_transponder_id_24.set_value(transponder_id_ & 0x00FFFFFF);
|
||||
field_transponder_id_32.set_value(transponder_id_);
|
||||
}
|
||||
|
||||
if (!pressure_str.empty()) {
|
||||
pressure_kpa_ = std::stoi(pressure_str);
|
||||
on_pressure_unit_change();
|
||||
}
|
||||
|
||||
if (!temp_str.empty()) {
|
||||
temperature_c_ = std::stoi(temp_str);
|
||||
field_temperature.set_value(temperature_c_);
|
||||
}
|
||||
|
||||
if (!flags_str.empty()) {
|
||||
uint8_t loaded_flags = std::stoul(flags_str, nullptr, 16);
|
||||
// Handle old format files: extract bits 6-4 if value > 7
|
||||
flags_ = (loaded_flags > 7) ? ((loaded_flags >> 4) & 0x07) : (loaded_flags & 0x07);
|
||||
field_flags.set_value(flags_);
|
||||
}
|
||||
|
||||
// Load signal type if available, otherwise auto-select based on packet type
|
||||
if (!signal_type_str.empty()) {
|
||||
int signal_type = std::stoi(signal_type_str);
|
||||
if (signal_type >= 1 && signal_type <= 3) {
|
||||
signal_type_ = static_cast<tpms::SignalType>(signal_type);
|
||||
} else {
|
||||
// Fall back to auto-detect
|
||||
update_signal_type_from_packet();
|
||||
}
|
||||
} else {
|
||||
// Fall back to auto-detect for backwards compatibility
|
||||
update_signal_type_from_packet();
|
||||
}
|
||||
|
||||
update_packet_display();
|
||||
update_field_visibility();
|
||||
text_status.set("Loaded: " + file_path.filename().string());
|
||||
} else {
|
||||
text_status.set("Error reading file");
|
||||
}
|
||||
} else {
|
||||
text_status.set("Error opening file");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
button_save.on_select = [this](Button&) {
|
||||
// Save current TPMS packet to file
|
||||
auto timestamp = to_string_timestamp(rtc_time::now());
|
||||
std::string file_name = "TPMS_" + timestamp + ".TXT";
|
||||
ensure_directory(tpms_dir);
|
||||
auto file_path = tpms_dir / file_name;
|
||||
|
||||
File f;
|
||||
auto error = f.create(file_path);
|
||||
if (!error.is_valid()) {
|
||||
std::string content = "Type=" + to_string_dec_uint(toUType(packet_type_), 1) + "\n";
|
||||
content += "ID=" + to_string_hex(transponder_id_, 8) + "\n";
|
||||
content += "Pressure=" + to_string_dec_uint(pressure_kpa_) + "\n";
|
||||
content += "Temperature=" + to_string_dec_int(temperature_c_) + "\n";
|
||||
content += "Flags=" + to_string_hex(flags_ & 0x07, 1) + "\n";
|
||||
|
||||
f.write(content.c_str(), content.length());
|
||||
text_status.set("Saved: " + file_name);
|
||||
} else {
|
||||
text_status.set("Error saving file");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TPMSTXView::~TPMSTXView() {
|
||||
stop_tx();
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::tpmstx
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (C) 2026
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __TPMS_TX_APP_H__
|
||||
#define __TPMS_TX_APP_H__
|
||||
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "transmitter_model.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "message.hpp"
|
||||
#include "tpms_packet.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "units.hpp"
|
||||
|
||||
namespace ui::external_app::tpmstx {
|
||||
|
||||
namespace format {
|
||||
static uint8_t pressure_unit{PRESSURE_UNIT_PSI};
|
||||
static uint8_t temp_unit{TEMP_UNIT_CELSIUS};
|
||||
} // namespace format
|
||||
|
||||
class TPMSTXView : public View {
|
||||
public:
|
||||
TPMSTXView(NavigationView& nav);
|
||||
~TPMSTXView();
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "TPMS TX"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
TxRadioState radio_state_{
|
||||
314900000, /* frequency */
|
||||
1750000, /* bandwidth */
|
||||
2457600 /* sampling rate */
|
||||
};
|
||||
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_tpms",
|
||||
app_settings::Mode::TX,
|
||||
{
|
||||
{"pressure_unit"sv, &format::pressure_unit},
|
||||
{"temp_unit"sv, &format::temp_unit},
|
||||
}};
|
||||
|
||||
// TPMS packet data
|
||||
tpms::Reading::Type packet_type_{tpms::Reading::Type::Schrader};
|
||||
uint32_t transponder_id_{0x12345678};
|
||||
uint16_t pressure_kpa_{240}; // Default ~35 PSI
|
||||
int16_t temperature_c_{25}; // Default 25°C
|
||||
uint8_t flags_{0x00}; // 3-bit function code (0-7), checksum is auto-calculated
|
||||
tpms::SignalType signal_type_{tpms::SignalType::FSK_19k2_Schrader};
|
||||
|
||||
uint8_t repeat_count_{5};
|
||||
uint32_t pause_duration_{50}; // ms between repeats
|
||||
|
||||
bool is_transmitting_{false};
|
||||
|
||||
// FSK-specific repeat tracking (OOK repeats are handled by baseband)
|
||||
uint8_t fsk_repeat_counter_{0};
|
||||
uint32_t fsk_repeat_timer_id_{0};
|
||||
|
||||
void update_signal_type_from_packet();
|
||||
void switch_baseband();
|
||||
|
||||
void start_tx();
|
||||
void stop_tx();
|
||||
void send_packet();
|
||||
void encode_and_transmit();
|
||||
void update_packet_display();
|
||||
void on_pressure_unit_change();
|
||||
void on_temperature_unit_change();
|
||||
void update_field_visibility();
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
progressbar.set_value(message.progress);
|
||||
if (message.done) {
|
||||
handle_tx_complete();
|
||||
}
|
||||
}};
|
||||
|
||||
void handle_tx_complete();
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 0 * 16}, "Freq:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 1 * 16}, "Type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 2 * 16}, "ID:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 3 * 16}, "Pres:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 5 * 16}, "Rpt:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
Text label_temperature{
|
||||
{0 * 8, 4 * 16, 5 * 8, 16},
|
||||
"Temp:"};
|
||||
|
||||
Text label_flags{
|
||||
{0 * 8, 4 * 16, 5 * 8, 16},
|
||||
"Func:"};
|
||||
|
||||
OptionsField options_frequency{
|
||||
{6 * 8, 0 * 16},
|
||||
5,
|
||||
{
|
||||
{"314.9", 314900000},
|
||||
{"315.0", 315000000},
|
||||
{"433.9", 433920000},
|
||||
}};
|
||||
|
||||
OptionsField options_packet_type{
|
||||
{6 * 8, 1 * 16},
|
||||
10,
|
||||
{
|
||||
{"Schrader", (int32_t)tpms::Reading::Type::Schrader},
|
||||
{"FLM_64", (int32_t)tpms::Reading::Type::FLM_64},
|
||||
{"FLM_72", (int32_t)tpms::Reading::Type::FLM_72},
|
||||
{"FLM_80", (int32_t)tpms::Reading::Type::FLM_80},
|
||||
{"GMC_96", (int32_t)tpms::Reading::Type::GMC_96},
|
||||
}};
|
||||
|
||||
OptionsField options_pressure{
|
||||
{11 * 8, 3 * 16},
|
||||
4,
|
||||
{{"kPa", PRESSURE_UNIT_KPA},
|
||||
{"PSI", PRESSURE_UNIT_PSI},
|
||||
{"BAR", PRESSURE_UNIT_BAR}}};
|
||||
|
||||
OptionsField options_temperature{
|
||||
{11 * 8, 4 * 16},
|
||||
2,
|
||||
{{STR_DEGREES_C, TEMP_UNIT_CELSIUS},
|
||||
{STR_DEGREES_F, TEMP_UNIT_FAHRENHEIT}}};
|
||||
|
||||
SymField field_transponder_id_24{
|
||||
{6 * 8, 2 * 16},
|
||||
6,
|
||||
SymField::Type::Hex};
|
||||
|
||||
SymField field_transponder_id_32{
|
||||
{6 * 8, 2 * 16},
|
||||
8,
|
||||
SymField::Type::Hex};
|
||||
|
||||
NumberField field_pressure{
|
||||
{6 * 8, 3 * 16},
|
||||
4,
|
||||
{0, 9999},
|
||||
1,
|
||||
' '};
|
||||
|
||||
NumberField field_temperature{
|
||||
{6 * 8, 4 * 16},
|
||||
4,
|
||||
{-99, 999},
|
||||
1,
|
||||
' '};
|
||||
|
||||
NumberField field_flags{
|
||||
{6 * 8, 4 * 16},
|
||||
1,
|
||||
{0, 7},
|
||||
1,
|
||||
' '};
|
||||
|
||||
NumberField field_repeat{
|
||||
{6 * 8, 5 * 16},
|
||||
3,
|
||||
{1, 100},
|
||||
1,
|
||||
' '};
|
||||
|
||||
Button button_load{
|
||||
{0 * 8, 8 * 16 + 4, 7 * 8, 24},
|
||||
"Load"};
|
||||
|
||||
Button button_save{
|
||||
{8 * 8, 8 * 16 + 4, 7 * 8, 24},
|
||||
"Save"};
|
||||
|
||||
TransmitterView2 tx_view{
|
||||
{16 * 8, 0 * 16},
|
||||
true // Short UI format
|
||||
};
|
||||
|
||||
Button button_transmit{
|
||||
{0 * 8, 11 * 16, 15 * 8, 32},
|
||||
"START TX"};
|
||||
|
||||
Text text_status{
|
||||
{0 * 8, 13 * 16 + 4, 30 * 8, 16},
|
||||
"Ready"};
|
||||
|
||||
ProgressBar progressbar{
|
||||
{0 * 8, 14 * 16 + 8, 30 * 8, 16}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::tpmstx
|
||||
|
||||
#endif /*__TPMS_TX_APP_H__*/
|
||||
@@ -51,5 +51,9 @@ const std::filesystem::path whipcalc_dir = u"WHIPCALC";
|
||||
const std::filesystem::path ook_editor_dir = u"OOKFILES";
|
||||
const std::filesystem::path hopper_dir = u"HOPPER";
|
||||
const std::filesystem::path subghz_dir = u"SUBGHZ";
|
||||
const std::filesystem::path tpms_dir = u"TPMS";
|
||||
const std::filesystem::path waterfalls_dir = u"WATERFALLS";
|
||||
const std::filesystem::path macaddress_dir = u"MACADDRESS";
|
||||
const std::filesystem::path splash_dot_bmp = u"/splash.bmp";
|
||||
const std::filesystem::path keeloq_keys_dir = u"KEELOQKEYS";
|
||||
const std::filesystem::path keeloq_remotes_dir = u"KEELOQREMOTES";
|
||||
|
||||
@@ -53,7 +53,12 @@ extern const std::filesystem::path whipcalc_dir;
|
||||
extern const std::filesystem::path ook_editor_dir;
|
||||
extern const std::filesystem::path hopper_dir;
|
||||
extern const std::filesystem::path subghz_dir;
|
||||
extern const std::filesystem::path tpms_dir;
|
||||
extern const std::filesystem::path waterfalls_dir;
|
||||
extern const std::filesystem::path macaddress_dir;
|
||||
extern const std::filesystem::path keeloq_keys_dir;
|
||||
extern const std::filesystem::path keeloq_remotes_dir;
|
||||
|
||||
extern const std::filesystem::path splash_dot_bmp;
|
||||
|
||||
#endif /* __FILE_PATH_H__ */
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
#include "../../hackrf/firmware/common/firmware_info.h"
|
||||
#include "../../hackrf/firmware/common/platform_detect.h"
|
||||
|
||||
// Use the same logic as official HackRF firmware
|
||||
#ifdef JAWBREAKER
|
||||
#define SUPPORTED_PLATFORM PLATFORM_JAWBREAKER
|
||||
#elif HACKRF_ONE
|
||||
#define SUPPORTED_PLATFORM (PLATFORM_HACKRF1_OG | PLATFORM_HACKRF1_R9)
|
||||
#elif RAD1O
|
||||
#define SUPPORTED_PLATFORM PLATFORM_RAD1O
|
||||
#elif PRALINE
|
||||
#define SUPPORTED_PLATFORM PLATFORM_PRALINE
|
||||
#else
|
||||
#define SUPPORTED_PLATFORM 0
|
||||
#endif
|
||||
|
||||
#define DFU_MODE_VALUE 0
|
||||
|
||||
__attribute__((section(".firmware_info"))) const struct firmware_info_t firmware_info = {
|
||||
|
||||
@@ -122,7 +122,7 @@ options_t freqman_steps = {
|
||||
{"1kHz ", 1000},
|
||||
{"5kHz (SA AM)", 5000},
|
||||
{"6.25kHz(NFM)", 6250},
|
||||
{"8.33kHz(AIR)", 8330},
|
||||
{"8.33kHz(AIR)", 8333},
|
||||
{"9kHz (EU AM)", 9000},
|
||||
{"10kHz(US AM)", 10000},
|
||||
{"12.5kHz(NFM)", 12500},
|
||||
@@ -144,7 +144,7 @@ options_t freqman_steps_short = {
|
||||
{"1kHz", 1000},
|
||||
{"5kHz", 5000},
|
||||
{"6.25kHz", 6250},
|
||||
{"8.33kHz", 8330},
|
||||
{"8.33kHz", 8333},
|
||||
{"9kHz", 9000},
|
||||
{"10kHz", 10000},
|
||||
{"12.5kHz", 12500},
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "gpio_lpc.h"
|
||||
|
||||
typedef enum {
|
||||
LED1 = 0,
|
||||
LED2 = 1,
|
||||
LED3 = 2,
|
||||
LED4 = 3,
|
||||
} led_t;
|
||||
|
||||
/* GPIO Output PinMux */
|
||||
static struct gpio_t gpio_led[] = {
|
||||
GPIO(2, 1),
|
||||
GPIO(2, 2),
|
||||
GPIO(2, 8),
|
||||
#ifdef RAD1O
|
||||
GPIO(5, 26),
|
||||
#endif
|
||||
};
|
||||
|
||||
void delay(uint32_t duration) {
|
||||
while (duration--) {
|
||||
/* cannot be optimized out */
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
}
|
||||
|
||||
void delay_us_at_mhz(uint32_t us, uint32_t mhz) {
|
||||
/* overflow-safe multiply */
|
||||
uint64_t cycles64 = (uint64_t)us * (uint64_t)mhz;
|
||||
if (cycles64 > UINT32_MAX) {
|
||||
cycles64 = UINT32_MAX;
|
||||
}
|
||||
delay((uint32_t)cycles64);
|
||||
}
|
||||
|
||||
void led_on(const led_t led) {
|
||||
gpio_set(&gpio_led[led]);
|
||||
}
|
||||
|
||||
void led_off(const led_t led) {
|
||||
gpio_clear(&gpio_led[led]);
|
||||
}
|
||||
|
||||
void halt_and_flash(const uint32_t duration) {
|
||||
/* blink LED1, LED2, and LED3 */
|
||||
while (1) {
|
||||
led_on(LED1);
|
||||
led_on(LED2);
|
||||
led_on(LED3);
|
||||
delay(duration);
|
||||
led_off(LED1);
|
||||
led_off(LED2);
|
||||
led_off(LED3);
|
||||
delay(duration);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,482 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Great Scott Gadgets
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MAX2831 driver ported from GSG HackRF reference implementation (max2831.c).
|
||||
* Adapted to work with Mayhem's MAX283x abstraction layer.
|
||||
*/
|
||||
|
||||
#ifdef PRALINE
|
||||
|
||||
#include "max2831.hpp"
|
||||
|
||||
#include "hackrf_hal.hpp"
|
||||
#include "hackrf_gpio.hpp"
|
||||
using namespace hackrf::one;
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace max2831 {
|
||||
|
||||
using namespace max283x;
|
||||
|
||||
static MAX2831Info max2831_info = {0, 0, 0, false, false};
|
||||
|
||||
MAX2831Info get_max2831_info() {
|
||||
return {
|
||||
max2831_info.requested_freq_mhz,
|
||||
max2831_info.calculated_n,
|
||||
max2831_info.calculated_frac,
|
||||
max2831_info.set_frequency_called,
|
||||
max2831_info.frequency_valid};
|
||||
}
|
||||
|
||||
/*
|
||||
* MAX2831 uses 9-bit SPI transfers.
|
||||
* An 18-bit word is sent as two 9-bit transfers:
|
||||
* Word format: [VALUE:14][REG:4]
|
||||
* First transfer: bits 17:9 (high 9 bits)
|
||||
* Second transfer: bits 8:0 (low 9 bits)
|
||||
*
|
||||
* This matches the GSG reference implementation exactly.
|
||||
*/
|
||||
void MAX2831::write_reg(const uint8_t reg, const uint16_t value) {
|
||||
uint32_t word = (((uint32_t)value & 0x3fff) << 4) | (reg & 0xf);
|
||||
uint16_t values[2] = {
|
||||
static_cast<uint16_t>(word >> 9),
|
||||
static_cast<uint16_t>(word & 0x1ff)};
|
||||
_target.transfer(values, 2);
|
||||
}
|
||||
|
||||
void MAX2831::set_reg_field(const uint8_t reg, const uint16_t mask, const uint16_t value) {
|
||||
_regs[reg] = (_regs[reg] & ~mask) | (value & mask);
|
||||
mark_dirty(reg);
|
||||
}
|
||||
|
||||
uint16_t MAX2831::get_reg_field(const uint8_t reg, const uint16_t mask, const uint8_t shift) {
|
||||
return (_regs[reg] & mask) >> shift;
|
||||
}
|
||||
|
||||
void MAX2831::mark_dirty(const uint8_t reg) {
|
||||
_regs_dirty |= (1 << reg);
|
||||
}
|
||||
|
||||
void MAX2831::mark_clean(const uint8_t reg) {
|
||||
_regs_dirty &= ~(1 << reg);
|
||||
}
|
||||
|
||||
void MAX2831::flush_reg(const uint8_t reg) {
|
||||
write_reg(reg, _regs[reg]);
|
||||
mark_clean(reg);
|
||||
}
|
||||
|
||||
void MAX2831::flush_dirty() {
|
||||
for (size_t r = 0; r < reg_count; r++) {
|
||||
if ((_regs_dirty >> r) & 0x1) {
|
||||
flush_reg(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MAX2831::init() {
|
||||
set_mode(Mode::Shutdown);
|
||||
|
||||
/* Configure GPIO pins for MAX2831 control */
|
||||
gpio_max283x_enable.output();
|
||||
gpio_max2831_rx_enable.output();
|
||||
gpio_max2831_rxhp.output();
|
||||
gpio_max2831_rxhp.write(0); /* RXHP low = 100 Hz HPF (default) */
|
||||
|
||||
/* Reset to default register values */
|
||||
std::memcpy(_regs.data(), default_regs.data(), sizeof(_regs));
|
||||
_regs_dirty = 0xFFFF;
|
||||
|
||||
/* Write default register values to chip */
|
||||
flush_dirty();
|
||||
|
||||
/* Use SPI control instead of B1-B7 pins for gain settings.
|
||||
* This matches the GSG reference: max2831_setup() */
|
||||
set_reg_field(8, REG8_RXVGA_GAIN_SPI_EN, REG8_RXVGA_GAIN_SPI_EN);
|
||||
set_reg_field(9, REG9_TXVGA_GAIN_SPI_EN, REG9_TXVGA_GAIN_SPI_EN);
|
||||
|
||||
/* Set initial gains - matches GSG reference */
|
||||
set_reg_field(12, REG12_TXVGA_GAIN_MASK, 0x00); /* Minimum TX gain */
|
||||
set_reg_field(7, REG7_RX_HPF_SEL_MASK, REG7_RX_HPF_30KHZ);
|
||||
set_reg_field(11, REG11_LNA_GAIN_MASK, REG11_LNA_GAIN_MAX);
|
||||
set_reg_field(11, REG11_RXVGA_GAIN_MASK, 0x18); // Moderate RX VGA gain
|
||||
|
||||
/* FORCE MAXIMUM GAIN FOR TESTING */
|
||||
// set_reg_field(11, REG11_RXVGA_GAIN_MASK, 0x1F); // 62 dB VGA = MAX
|
||||
|
||||
/* Configure baseband filter for 8 MHz TX - matches GSG reference */
|
||||
// set_reg_field(8, REG8_LPF_COARSE_MASK, REG8_RX_LPF_7_5M);
|
||||
set_reg_field(8, REG8_LPF_COARSE_MASK, REG8_RX_LPF_15M);
|
||||
set_reg_field(7, REG7_RX_LPF_FINE_MASK, REG7_RX_LPF_FINE_100);
|
||||
set_reg_field(7, REG7_TX_LPF_FINE_MASK, REG7_TX_LPF_FINE_100);
|
||||
|
||||
/* Disable clock output */
|
||||
set_reg_field(14, REG14_CLKOUT_PIN_EN, 0);
|
||||
|
||||
/* Write all modified registers */
|
||||
flush_dirty();
|
||||
|
||||
set_mode(Mode::Standby);
|
||||
}
|
||||
|
||||
void MAX2831::set_mode(const Mode mode) {
|
||||
_mode = mode;
|
||||
|
||||
/*
|
||||
* MAX2831 mode control via ENABLE and RXTX pins.
|
||||
* From GSG hackrf max2831_target.c:
|
||||
*
|
||||
* Shutdown: ENABLE=0, RXTX=0
|
||||
* Standby: ENABLE=0, RXTX=1 (PLL/VCO/LO on, ready for quick TX/RX)
|
||||
* RX: ENABLE=1, RXTX=0
|
||||
* TX: ENABLE=1, RXTX=1
|
||||
*
|
||||
* Note: gpio_max2831_rx_enable is the RXTX mode select pin.
|
||||
* RXTX=0 selects RX, RXTX=1 selects TX.
|
||||
*/
|
||||
|
||||
/* Handle calibration mode bits if needed */
|
||||
bool tx_cal = (mode == Mode::Tx_Calibration);
|
||||
bool rx_cal = (mode == Mode::Rx_Calibration);
|
||||
|
||||
uint16_t current_tx_cal = get_reg_field(6, REG6_TX_CAL_MODE_EN, REG6_TX_CAL_MODE_EN_SHIFT);
|
||||
uint16_t current_rx_cal = get_reg_field(6, REG6_RX_CAL_MODE_EN, REG6_RX_CAL_MODE_EN_SHIFT);
|
||||
|
||||
if (current_tx_cal != (tx_cal ? 1 : 0)) {
|
||||
set_reg_field(6, REG6_TX_CAL_MODE_EN, tx_cal ? REG6_TX_CAL_MODE_EN : 0);
|
||||
flush_dirty();
|
||||
}
|
||||
if (current_rx_cal != (rx_cal ? 1 : 0)) {
|
||||
set_reg_field(6, REG6_RX_CAL_MODE_EN, rx_cal ? REG6_RX_CAL_MODE_EN : 0);
|
||||
flush_dirty();
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
default:
|
||||
case Mode::Shutdown:
|
||||
gpio_max2831_rx_enable.write(0); /* RXTX=0 */
|
||||
gpio_max283x_enable.write(0); /* ENABLE=0 */
|
||||
break;
|
||||
case Mode::Standby:
|
||||
gpio_max2831_rx_enable.write(1); /* RXTX=1 */
|
||||
gpio_max283x_enable.write(0); /* ENABLE=0 */
|
||||
break;
|
||||
case Mode::Transmit:
|
||||
case Mode::Tx_Calibration:
|
||||
gpio_max2831_rx_enable.write(1); /* RXTX=1 for TX */
|
||||
gpio_max283x_enable.write(1); /* ENABLE=1 */
|
||||
break;
|
||||
case Mode::Receive:
|
||||
case Mode::Rx_Calibration:
|
||||
gpio_max2831_rx_enable.write(0); /* RXTX=0 for RX */
|
||||
gpio_max283x_enable.write(1); /* ENABLE=1 */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Update LPF bandwidth for current mode */
|
||||
if (_desired_lpf_bw > 0) {
|
||||
set_lpf_bandwidth_internal(_desired_lpf_bw);
|
||||
}
|
||||
}
|
||||
|
||||
void MAX2831::set_tx_vga_gain(const int_fast8_t db) {
|
||||
/* TX VGA gain: 0-31 dB in ~1 dB steps
|
||||
* Register value: gain * 2 | 1, max 0x3F
|
||||
* This matches GSG reference: max2831_set_txvga_gain() */
|
||||
int_fast8_t db_clipped = std::max(0, std::min(31, (int)db));
|
||||
uint16_t value = std::min((db_clipped << 1) | 1, 0x3f);
|
||||
set_reg_field(12, REG12_TXVGA_GAIN_MASK, value);
|
||||
flush_reg(12);
|
||||
}
|
||||
|
||||
void MAX2831::set_lna_gain(const int_fast8_t db) {
|
||||
/*
|
||||
* LNA gain has 3 settings (from GSG reference):
|
||||
* MAX (33 dB), -16 dB from max (17 dB), -33 dB from max (0 dB)
|
||||
* Map from MAX2837 8 dB steps for compatibility
|
||||
*/
|
||||
uint16_t gain_val;
|
||||
if (db >= 32) {
|
||||
gain_val = REG11_LNA_GAIN_MAX;
|
||||
} else if (db >= 16) {
|
||||
gain_val = REG11_LNA_GAIN_M16;
|
||||
} else {
|
||||
gain_val = REG11_LNA_GAIN_M33;
|
||||
}
|
||||
set_reg_field(11, REG11_LNA_GAIN_MASK, gain_val);
|
||||
flush_reg(11);
|
||||
}
|
||||
|
||||
void MAX2831::set_vga_gain(const int_fast8_t db) {
|
||||
/* VGA gain: 0-62 dB in 2 dB steps
|
||||
* This matches GSG reference: max2831_set_vga_gain() */
|
||||
if ((db & 0x1) || db > 62) {
|
||||
return; /* Invalid: must be even and <= 62 */
|
||||
}
|
||||
int_fast8_t db_clipped = std::max(0, std::min(62, (int)db));
|
||||
uint16_t value = (db_clipped >> 1) & 0x1f;
|
||||
set_reg_field(11, REG11_RXVGA_GAIN_MASK, value);
|
||||
flush_reg(11);
|
||||
}
|
||||
|
||||
/*
|
||||
* LPF bandwidth tables from GSG reference max2831.c
|
||||
*/
|
||||
struct lpf_ft_t {
|
||||
uint32_t bandwidth_hz;
|
||||
uint8_t ft;
|
||||
};
|
||||
|
||||
struct lpf_ft_fine_t {
|
||||
uint8_t percent;
|
||||
uint8_t ft_fine;
|
||||
};
|
||||
|
||||
/* Measured -0.5 dB complex baseband bandwidth for each register setting */
|
||||
static constexpr lpf_ft_t rx_lpf_ft[] = {
|
||||
{11600000, REG8_RX_LPF_7_5M},
|
||||
{15100000, REG8_RX_LPF_8_5M},
|
||||
{22600000, REG8_RX_LPF_15M},
|
||||
{28300000, REG8_RX_LPF_18M},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static constexpr lpf_ft_fine_t rx_lpf_ft_fine[] = {
|
||||
{90, REG7_RX_LPF_FINE_90},
|
||||
{95, REG7_RX_LPF_FINE_95},
|
||||
{100, REG7_RX_LPF_FINE_100},
|
||||
{105, REG7_RX_LPF_FINE_105},
|
||||
{110, REG7_RX_LPF_FINE_110},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static constexpr lpf_ft_t tx_lpf_ft[] = {
|
||||
{11900000, REG8_TX_LPF_8M},
|
||||
{15800000, REG8_TX_LPF_11M},
|
||||
{23600000, REG8_TX_LPF_16_5M},
|
||||
{31300000, REG8_TX_LPF_22_5M},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static constexpr lpf_ft_fine_t tx_lpf_ft_fine[] = {
|
||||
{90, REG7_TX_LPF_FINE_90},
|
||||
{95, REG7_TX_LPF_FINE_95},
|
||||
{100, REG7_TX_LPF_FINE_100},
|
||||
{105, REG7_TX_LPF_FINE_105},
|
||||
{110, REG7_TX_LPF_FINE_110},
|
||||
{115, REG7_TX_LPF_FINE_115},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
uint32_t MAX2831::set_lpf_bandwidth_internal(const uint32_t bandwidth_hz) {
|
||||
const lpf_ft_t* coarse;
|
||||
const lpf_ft_fine_t* fine;
|
||||
|
||||
if (_mode == Mode::Receive || _mode == Mode::Rx_Calibration) {
|
||||
coarse = rx_lpf_ft;
|
||||
fine = rx_lpf_ft_fine;
|
||||
} else {
|
||||
coarse = tx_lpf_ft;
|
||||
fine = tx_lpf_ft_fine;
|
||||
}
|
||||
|
||||
/* Find coarse and fine settings for LPF - matches GSG reference */
|
||||
bool found = false;
|
||||
const lpf_ft_fine_t* f = fine;
|
||||
for (; coarse->bandwidth_hz != 0; coarse++) {
|
||||
uint32_t coarse_aux = coarse->bandwidth_hz / 100;
|
||||
for (f = fine; f->percent != 0; f++) {
|
||||
if ((coarse_aux * f->percent) >= bandwidth_hz) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) break;
|
||||
}
|
||||
|
||||
/* Use the widest setting if a wider bandwidth than our maximum is requested */
|
||||
if (!found) {
|
||||
coarse--;
|
||||
f--;
|
||||
}
|
||||
|
||||
/* Program found settings */
|
||||
set_reg_field(8, REG8_LPF_COARSE_MASK, coarse->ft);
|
||||
if (_mode == Mode::Receive || _mode == Mode::Rx_Calibration) {
|
||||
set_reg_field(7, REG7_RX_LPF_FINE_MASK, f->ft_fine);
|
||||
} else {
|
||||
/* TX fine values are already shifted in the constants (REG7_TX_LPF_FINE_*) */
|
||||
set_reg_field(7, REG7_TX_LPF_FINE_MASK, f->ft_fine);
|
||||
}
|
||||
flush_dirty();
|
||||
|
||||
return coarse->bandwidth_hz * f->percent / 100;
|
||||
}
|
||||
|
||||
void MAX2831::set_lpf_rf_bandwidth_rx(const uint32_t bandwidth_minimum) {
|
||||
_desired_lpf_bw = bandwidth_minimum;
|
||||
#ifdef PRALINE
|
||||
uint32_t actual_bw = bandwidth_minimum;
|
||||
if (actual_bw < 22000000) {
|
||||
actual_bw = 22000000; // Never go below 15 MHz, set by choosing 22.6 MHz bandwidth
|
||||
}
|
||||
|
||||
_desired_lpf_bw = actual_bw;
|
||||
if (_mode == Mode::Receive || _mode == Mode::Rx_Calibration) {
|
||||
set_lpf_bandwidth_internal(actual_bw);
|
||||
}
|
||||
#else
|
||||
if (_mode == Mode::Receive || _mode == Mode::Rx_Calibration) {
|
||||
set_lpf_bandwidth_internal(bandwidth_minimum);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MAX2831::set_lpf_rf_bandwidth_tx(const uint32_t bandwidth_minimum) {
|
||||
_desired_lpf_bw = bandwidth_minimum;
|
||||
if (_mode == Mode::Transmit || _mode == Mode::Tx_Calibration) {
|
||||
set_lpf_bandwidth_internal(bandwidth_minimum);
|
||||
}
|
||||
}
|
||||
|
||||
bool MAX2831::set_frequency(const rf::Frequency lo_frequency) {
|
||||
/*
|
||||
* MAX2831 frequency synthesis from GSG reference max2831_set_frequency():
|
||||
* F_LO = F_REF * (N + F/2^20) / R
|
||||
* Where:
|
||||
* F_REF = 40 MHz reference
|
||||
* R = reference divider (1 or 2), we use R=2
|
||||
* N = integer divider (8 bits)
|
||||
* F = fractional divider (20 bits)
|
||||
*
|
||||
* Using R=2: F_LO = 40M * (N + F/2^20) / 2 = 20M * (N + F/2^20)
|
||||
*/
|
||||
|
||||
/* MAX2831 supports 2.3-2.6 GHz */
|
||||
// if (lo_frequency < MAX2831_MIN_LO_FREQUENCY_HZ || lo_frequency > MAX2831_MAX_LO_FREQUENCY_HZ) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
bool valid = (lo_frequency >= MAX2831_MIN_LO_FREQUENCY_HZ && lo_frequency <= MAX2831_MAX_LO_FREQUENCY_HZ);
|
||||
|
||||
// TRACK REQUEST IMMEDIATELY
|
||||
max2831_info.requested_freq_mhz = lo_frequency / 1000000;
|
||||
max2831_info.set_frequency_called = true;
|
||||
max2831_info.frequency_valid = valid;
|
||||
|
||||
if (!valid) {
|
||||
max2831_info.calculated_n = 0;
|
||||
max2831_info.calculated_frac = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* From GSG reference: ASSUME 40MHz PLL. Ratio = F*R/40,000,000.
|
||||
* TODO: fixed to R=2. Check if it's worth exploring R=1. */
|
||||
uint32_t freq = lo_frequency;
|
||||
freq += (20000000 >> 21); /* Round to nearest frequency */
|
||||
uint32_t div_int = freq / 20000000;
|
||||
uint32_t div_rem = freq % 20000000;
|
||||
uint32_t div_frac = 0;
|
||||
uint32_t div_cmp = 20000000;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
div_frac <<= 1;
|
||||
div_rem <<= 1;
|
||||
if (div_rem >= div_cmp) {
|
||||
div_frac |= 0x1;
|
||||
div_rem -= div_cmp;
|
||||
}
|
||||
}
|
||||
|
||||
// TRACK CALCULATED VALUES
|
||||
max2831_info.calculated_n = div_int;
|
||||
max2831_info.calculated_frac = div_frac;
|
||||
|
||||
/* Write order matters - matches GSG reference */
|
||||
/* REG 3: SYN_INT (bits 7:0) and SYN_FRAC_LO (bits 13:8) */
|
||||
uint16_t reg3_val = (div_int & 0xFF) | ((div_frac & 0x3F) << 8);
|
||||
_regs[3] = reg3_val;
|
||||
mark_dirty(3);
|
||||
|
||||
/* REG 4: SYN_FRAC_HI (bits 13:0) - upper 14 bits of 20-bit fractional */
|
||||
uint16_t reg4_val = (div_frac >> 6) & 0x3FFF;
|
||||
_regs[4] = reg4_val;
|
||||
mark_dirty(4);
|
||||
|
||||
flush_dirty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MAX2831::set_rx_LO_iq_phase_calibration(const size_t v) {
|
||||
/* MAX2831 doesn't have the same IQ calibration as MAX2837 */
|
||||
(void)v;
|
||||
}
|
||||
|
||||
void MAX2831::set_tx_LO_iq_phase_calibration(const size_t v) {
|
||||
/* MAX2831 doesn't have the same IQ calibration as MAX2837 */
|
||||
(void)v;
|
||||
}
|
||||
|
||||
void MAX2831::set_rx_buff_vcm(const size_t v) {
|
||||
/* MAX2831 RX IQ common mode voltage is in register 15
|
||||
* Values: 0=1.1V, 1=1.2V, 2=1.3V, 3=1.45V */
|
||||
uint16_t vcm = std::min(v, (size_t)3) << REG15_RXIQ_VCM_SHIFT;
|
||||
set_reg_field(15, REG15_RXIQ_VCM_MASK, vcm);
|
||||
flush_reg(15);
|
||||
}
|
||||
|
||||
int8_t MAX2831::temp_sense() {
|
||||
/* MAX2831 temperature sensor can be read via RSSI MUX.
|
||||
* This would require:
|
||||
* 1. Switch RSSI_MUX to temperature mode
|
||||
* 2. Read the ADC
|
||||
* 3. Switch back to RSSI mode
|
||||
* For now, return a placeholder value. */
|
||||
return 25; /* Room temperature placeholder */
|
||||
}
|
||||
|
||||
reg_t MAX2831::read(const address_t reg_num) {
|
||||
/* MAX2831 doesn't support SPI read, return cached value */
|
||||
if (reg_num < reg_count) {
|
||||
return _regs[reg_num];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MAX2831::write(const address_t reg_num, const reg_t value) {
|
||||
if (reg_num < reg_count) {
|
||||
_regs[reg_num] = value & 0x3FFF; /* 14-bit registers */
|
||||
write_reg(reg_num, _regs[reg_num]);
|
||||
mark_clean(reg_num);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace max2831
|
||||
#endif
|
||||
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Great Scott Gadgets
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MAX2831 driver ported from GSG HackRF reference implementation.
|
||||
* Register definitions match max2831_regs.def from hackrf firmware.
|
||||
*/
|
||||
|
||||
#ifndef __MAX2831_H__
|
||||
#define __MAX2831_H__
|
||||
|
||||
#include "max283x.hpp"
|
||||
#include "gpio.hpp"
|
||||
#include "spi_arbiter.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
||||
namespace max2831 {
|
||||
|
||||
using namespace max283x;
|
||||
|
||||
// Global debug tracking for MAX2831
|
||||
struct MAX2831Info {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_n;
|
||||
uint32_t calculated_frac;
|
||||
bool set_frequency_called;
|
||||
bool frequency_valid;
|
||||
};
|
||||
|
||||
MAX2831Info get_max2831_info();
|
||||
|
||||
/* minumum and maximum lo_frequencies supported by max2831 */
|
||||
constexpr rf::Frequency MAX2831_MIN_LO_FREQUENCY_HZ = 2300000000LL;
|
||||
constexpr rf::Frequency MAX2831_MAX_LO_FREQUENCY_HZ = 2600000000LL;
|
||||
|
||||
/* MAX2831 has 16 registers, each containing 14 bits of data */
|
||||
constexpr size_t reg_count = 16;
|
||||
|
||||
/* Default register values from GSG HackRF reference (max2831.c) */
|
||||
constexpr std::array<uint16_t, reg_count> default_regs = {
|
||||
0x1740, /* 0: enable fractional mode (Table 16 recommends 0x0740, clearing unknown bit) */
|
||||
0x119a, /* 1 */
|
||||
0x1003, /* 2 */
|
||||
0x0079, /* 3: PLL divider settings for 2437 MHz */
|
||||
0x3666, /* 4: PLL divider settings for 2437 MHz */
|
||||
0x00a4, /* 5: divide reference frequency by 2 */
|
||||
0x0060, /* 6: enable TX power detector */
|
||||
0x1022, /* 7: 110% TX LPF bandwidth */
|
||||
0x2021, /* 8: pin control of RX gain, 11 MHz LPF bandwidth */
|
||||
0x03b5, /* 9: pin control of TX gain */
|
||||
0x1d80, /* 10: 3.5 us PA enable delay, zero PA bias */
|
||||
0x0074, /* 11: LNA high gain, RX VGA moderate gain (Table 27 recommends 0x007f, maximum gain) */
|
||||
0x0140, /* 12: TX VGA minimum */
|
||||
0x0e92, /* 13 */
|
||||
0x0100, /* 14: reference clock output disabled */
|
||||
0x0145, /* 15: RX IQ common mode 1.1 V */
|
||||
};
|
||||
|
||||
/*
|
||||
* Register bit field definitions from max2831_regs.def
|
||||
* Format: REG<num>_<field>_<info>
|
||||
*/
|
||||
|
||||
/* REG 0: PLL Mode */
|
||||
constexpr uint16_t REG0_PLL_MODE_SHIFT = 10;
|
||||
constexpr uint16_t REG0_PLL_MODE_MASK = (1 << REG0_PLL_MODE_SHIFT);
|
||||
constexpr uint16_t REG0_PLL_MODE_INTEGER = 0;
|
||||
constexpr uint16_t REG0_PLL_MODE_FRACTIONAL = 1;
|
||||
|
||||
/* REG 3: Synthesizer Integer and Fractional Low */
|
||||
constexpr uint16_t REG3_SYN_INT_SHIFT = 0;
|
||||
constexpr uint16_t REG3_SYN_INT_MASK = 0x00FF; /* D7:D0 - Integer divider (8 bits) */
|
||||
constexpr uint16_t REG3_SYN_FRAC_LO_SHIFT = 8;
|
||||
constexpr uint16_t REG3_SYN_FRAC_LO_MASK = 0x3F00; /* D13:D8 - Low 6 bits of fractional divider */
|
||||
|
||||
/* REG 4: Synthesizer Fractional High */
|
||||
constexpr uint16_t REG4_SYN_FRAC_HI_MASK = 0x3FFF; /* D13:D0 - High 14 bits of fractional divider */
|
||||
|
||||
/* REG 5: Reference Divider and Lock Detect */
|
||||
constexpr uint16_t REG5_SYN_REF_DIV_SHIFT = 2;
|
||||
constexpr uint16_t REG5_SYN_REF_DIV_1 = (0 << REG5_SYN_REF_DIV_SHIFT);
|
||||
constexpr uint16_t REG5_SYN_REF_DIV_2 = (1 << REG5_SYN_REF_DIV_SHIFT);
|
||||
|
||||
/* REG 6: Calibration Mode */
|
||||
constexpr uint16_t REG6_RX_CAL_MODE_EN_SHIFT = 0;
|
||||
constexpr uint16_t REG6_RX_CAL_MODE_EN = (1 << REG6_RX_CAL_MODE_EN_SHIFT);
|
||||
constexpr uint16_t REG6_TX_CAL_MODE_EN_SHIFT = 1;
|
||||
constexpr uint16_t REG6_TX_CAL_MODE_EN = (1 << REG6_TX_CAL_MODE_EN_SHIFT);
|
||||
constexpr uint16_t REG6_TX_POWER_DETECT_EN_SHIFT = 6;
|
||||
constexpr uint16_t REG6_TX_POWER_DETECT_EN = (1 << REG6_TX_POWER_DETECT_EN_SHIFT);
|
||||
|
||||
/* REG 7: LPF Fine Adjustment and RX HPF */
|
||||
constexpr uint16_t REG7_RX_LPF_FINE_SHIFT = 0;
|
||||
constexpr uint16_t REG7_RX_LPF_FINE_MASK = 0x0007; /* D2:D0 */
|
||||
constexpr uint16_t REG7_RX_LPF_FINE_90 = 0;
|
||||
constexpr uint16_t REG7_RX_LPF_FINE_95 = 1;
|
||||
constexpr uint16_t REG7_RX_LPF_FINE_100 = 2;
|
||||
constexpr uint16_t REG7_RX_LPF_FINE_105 = 3;
|
||||
constexpr uint16_t REG7_RX_LPF_FINE_110 = 4;
|
||||
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_SHIFT = 3;
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_MASK = 0x0038; /* D5:D3 */
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_90 = (0 << REG7_TX_LPF_FINE_SHIFT);
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_95 = (1 << REG7_TX_LPF_FINE_SHIFT);
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_100 = (2 << REG7_TX_LPF_FINE_SHIFT);
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_105 = (3 << REG7_TX_LPF_FINE_SHIFT);
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_110 = (4 << REG7_TX_LPF_FINE_SHIFT);
|
||||
constexpr uint16_t REG7_TX_LPF_FINE_115 = (5 << REG7_TX_LPF_FINE_SHIFT);
|
||||
|
||||
constexpr uint16_t REG7_RX_HPF_SEL_SHIFT = 12;
|
||||
constexpr uint16_t REG7_RX_HPF_SEL_MASK = 0x3000; /* D13:D12 */
|
||||
constexpr uint16_t REG7_RX_HPF_100HZ = (0 << REG7_RX_HPF_SEL_SHIFT);
|
||||
constexpr uint16_t REG7_RX_HPF_4KHZ = (1 << REG7_RX_HPF_SEL_SHIFT);
|
||||
constexpr uint16_t REG7_RX_HPF_30KHZ = (2 << REG7_RX_HPF_SEL_SHIFT);
|
||||
|
||||
/* REG 8: LPF Coarse, RSSI MUX, and RX VGA SPI Enable */
|
||||
constexpr uint16_t REG8_LPF_COARSE_SHIFT = 0;
|
||||
constexpr uint16_t REG8_LPF_COARSE_MASK = 0x0003; /* D1:D0 */
|
||||
/* RX and TX share the same coarse LPF setting bits */
|
||||
constexpr uint16_t REG8_RX_LPF_7_5M = 0;
|
||||
constexpr uint16_t REG8_RX_LPF_8_5M = 1;
|
||||
constexpr uint16_t REG8_RX_LPF_15M = 2;
|
||||
constexpr uint16_t REG8_RX_LPF_18M = 3;
|
||||
constexpr uint16_t REG8_TX_LPF_8M = 0;
|
||||
constexpr uint16_t REG8_TX_LPF_11M = 1;
|
||||
constexpr uint16_t REG8_TX_LPF_16_5M = 2;
|
||||
constexpr uint16_t REG8_TX_LPF_22_5M = 3;
|
||||
|
||||
constexpr uint16_t REG8_RSSI_MUX_SHIFT = 8;
|
||||
constexpr uint16_t REG8_RSSI_MUX_MASK = 0x0300; /* D9:D8 */
|
||||
constexpr uint16_t REG8_RSSI_MUX_RSSI = (0 << REG8_RSSI_MUX_SHIFT);
|
||||
constexpr uint16_t REG8_RSSI_MUX_TEMP = (1 << REG8_RSSI_MUX_SHIFT);
|
||||
constexpr uint16_t REG8_RSSI_MUX_TX_POWER = (2 << REG8_RSSI_MUX_SHIFT);
|
||||
|
||||
constexpr uint16_t REG8_RXVGA_GAIN_SPI_EN_SHIFT = 12;
|
||||
constexpr uint16_t REG8_RXVGA_GAIN_SPI_EN = (1 << REG8_RXVGA_GAIN_SPI_EN_SHIFT);
|
||||
|
||||
/* REG 9: TX VGA SPI Enable */
|
||||
constexpr uint16_t REG9_TXVGA_GAIN_SPI_EN_SHIFT = 10;
|
||||
constexpr uint16_t REG9_TXVGA_GAIN_SPI_EN = (1 << REG9_TXVGA_GAIN_SPI_EN_SHIFT);
|
||||
|
||||
/* REG 11: RX Gain */
|
||||
constexpr uint16_t REG11_RXVGA_GAIN_SHIFT = 0;
|
||||
constexpr uint16_t REG11_RXVGA_GAIN_MASK = 0x001F; /* D4:D0 - 5 bits */
|
||||
|
||||
constexpr uint16_t REG11_LNA_GAIN_SHIFT = 5;
|
||||
constexpr uint16_t REG11_LNA_GAIN_MASK = 0x0060; /* D6:D5 - 2 bits */
|
||||
constexpr uint16_t REG11_LNA_GAIN_M33 = (0 << REG11_LNA_GAIN_SHIFT); /* -33 dB from max (min) */
|
||||
constexpr uint16_t REG11_LNA_GAIN_M16 = (2 << REG11_LNA_GAIN_SHIFT); /* -16 dB from max */
|
||||
constexpr uint16_t REG11_LNA_GAIN_MAX = (3 << REG11_LNA_GAIN_SHIFT); /* Maximum LNA gain */
|
||||
|
||||
/* REG 12: TX VGA Gain */
|
||||
constexpr uint16_t REG12_TXVGA_GAIN_SHIFT = 0;
|
||||
constexpr uint16_t REG12_TXVGA_GAIN_MASK = 0x003F; /* D5:D0 - 6 bits */
|
||||
|
||||
/* REG 14: Clock Output */
|
||||
constexpr uint16_t REG14_CLKOUT_PIN_EN_SHIFT = 9;
|
||||
constexpr uint16_t REG14_CLKOUT_PIN_EN = (1 << REG14_CLKOUT_PIN_EN_SHIFT);
|
||||
|
||||
/* REG 15: RX IQ Common Mode */
|
||||
constexpr uint16_t REG15_RXIQ_VCM_SHIFT = 10;
|
||||
constexpr uint16_t REG15_RXIQ_VCM_MASK = 0x0C00; /* D11:D10 - 2 bits */
|
||||
constexpr uint16_t REG15_RXIQ_VCM_1_1 = (0 << REG15_RXIQ_VCM_SHIFT); /* 1.1V */
|
||||
constexpr uint16_t REG15_RXIQ_VCM_1_2 = (1 << REG15_RXIQ_VCM_SHIFT); /* 1.2V */
|
||||
constexpr uint16_t REG15_RXIQ_VCM_1_3 = (2 << REG15_RXIQ_VCM_SHIFT); /* 1.3V */
|
||||
constexpr uint16_t REG15_RXIQ_VCM_1_45 = (3 << REG15_RXIQ_VCM_SHIFT); /* 1.45V */
|
||||
|
||||
class MAX2831 : public MAX283x {
|
||||
public:
|
||||
constexpr MAX2831(
|
||||
spi::arbiter::Target& target)
|
||||
: _target(target) {
|
||||
}
|
||||
|
||||
void init() override;
|
||||
void set_mode(const Mode mode) override;
|
||||
|
||||
void set_tx_vga_gain(const int_fast8_t db) override;
|
||||
void set_lna_gain(const int_fast8_t db) override;
|
||||
void set_vga_gain(const int_fast8_t db) override;
|
||||
void set_lpf_rf_bandwidth_rx(const uint32_t bandwidth_minimum) override;
|
||||
void set_lpf_rf_bandwidth_tx(const uint32_t bandwidth_minimum) override;
|
||||
|
||||
bool set_frequency(const rf::Frequency lo_frequency) override;
|
||||
|
||||
void set_rx_LO_iq_phase_calibration(const size_t v) override;
|
||||
void set_tx_LO_iq_phase_calibration(const size_t v) override;
|
||||
|
||||
void set_rx_buff_vcm(const size_t v) override;
|
||||
|
||||
int8_t temp_sense() override;
|
||||
|
||||
reg_t read(const address_t reg_num) override;
|
||||
void write(const address_t reg_num, const reg_t value) override;
|
||||
|
||||
private:
|
||||
spi::arbiter::Target& _target;
|
||||
Mode _mode{Mode::Standby};
|
||||
std::array<uint16_t, reg_count> _regs{default_regs};
|
||||
uint16_t _regs_dirty{0xFFFF}; /* Track which registers need to be written */
|
||||
uint32_t _desired_lpf_bw{0}; /* Desired LPF bandwidth in Hz */
|
||||
|
||||
void write_reg(const uint8_t reg, const uint16_t value);
|
||||
void set_reg_field(const uint8_t reg, const uint16_t mask, const uint16_t value);
|
||||
uint16_t get_reg_field(const uint8_t reg, const uint16_t mask, const uint8_t shift);
|
||||
void mark_dirty(const uint8_t reg);
|
||||
void mark_clean(const uint8_t reg);
|
||||
void flush_reg(const uint8_t reg);
|
||||
void flush_dirty();
|
||||
uint32_t set_lpf_bandwidth_internal(const uint32_t bandwidth_hz);
|
||||
};
|
||||
|
||||
} // namespace max2831
|
||||
|
||||
#endif /*__MAX2831_H__*/
|
||||
@@ -31,6 +31,24 @@ using namespace hackrf::one;
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#ifdef PRALINE
|
||||
// Global debug tracking - visible to other files
|
||||
struct rffc507x_debug_t {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_vco_mhz;
|
||||
uint32_t expected_n;
|
||||
uint8_t expected_lodiv;
|
||||
uint8_t expected_presc;
|
||||
bool was_called;
|
||||
uint32_t calc_lo_freq_mhz; // Input to calculate()
|
||||
uint32_t calc_vco_inside_mhz; // VCO calculated inside calculate()
|
||||
uint8_t calc_lodiv_log2; // LO divider log2
|
||||
uint8_t calc_presc_log2; // Prescaler log2
|
||||
uint64_t calc_n_q24; // N in Q24 format before shift
|
||||
};
|
||||
rffc507x_debug_t rffc507x_debug_info = {0, 0, 0, 0, 0, false, 0, 0, 0, 0, 0};
|
||||
#endif
|
||||
|
||||
namespace rffc507x {
|
||||
|
||||
/* Empirical tests indicate no minimum reset pulse width, but the speed
|
||||
@@ -96,9 +114,31 @@ constexpr size_t divider_min = 1U << divider_log2_min;
|
||||
constexpr size_t divider_max = 1U << divider_log2_max;
|
||||
|
||||
constexpr size_t divider_log2(const rf::Frequency vco_frequency) {
|
||||
#ifdef PRALINE
|
||||
// PRALINE FIX: Avoid N register overflow (9-bit max = 511)
|
||||
// With 40 MHz reference:
|
||||
// - For VCO=5400 MHz, presc=÷2: N = (5400×2)/40 = 270 ✓
|
||||
// - For VCO=5400 MHz, presc=÷4: N = (5400×4)/40 = 540 ✗ OVERFLOW!
|
||||
//
|
||||
// Maximum safe VCO for ÷4 prescaler:
|
||||
// N_max = 511, so VCO_max = (511 × 40) / 4 = 5110 MHz
|
||||
//
|
||||
// Use ÷4 only if VCO < 5110 MHz AND VCO > 3200 MHz
|
||||
// Use ÷2 for VCO >= 5110 MHz to avoid overflow
|
||||
|
||||
constexpr rf::Frequency overflow_threshold = 5110000000ULL; // Max VCO for ÷4
|
||||
constexpr rf::Frequency min_presc4_freq = 3200000000ULL; // Min VCO for ÷4
|
||||
|
||||
if ((vco_frequency > min_presc4_freq) && (vco_frequency < overflow_threshold)) {
|
||||
return divider_log2_max; // ÷4 prescaler
|
||||
} else {
|
||||
return divider_log2_min; // ÷2 prescaler
|
||||
}
|
||||
#else
|
||||
return (vco_frequency > (prescaler::divider_min * prescaler::max_frequency))
|
||||
? prescaler::divider_log2_max
|
||||
: prescaler::divider_log2_min;
|
||||
#endif
|
||||
}
|
||||
|
||||
} /* namespace prescaler */
|
||||
@@ -121,9 +161,22 @@ struct SynthConfig {
|
||||
|
||||
const size_t prescaler_divider_log2 = prescaler::divider_log2(vco_frequency);
|
||||
|
||||
#ifndef PRALINE
|
||||
const uint64_t prescaled_lo_q24 = vco_frequency << (24 - prescaler_divider_log2);
|
||||
#else
|
||||
const uint64_t prescaled_lo_q24 = vco_frequency << (24 + prescaler_divider_log2);
|
||||
#endif
|
||||
const uint64_t n_divider_q24 = prescaled_lo_q24 / reference_frequency;
|
||||
|
||||
#ifdef PRALINE
|
||||
// DEBUG: Track everything
|
||||
rffc507x_debug_info.calc_lo_freq_mhz = lo_frequency / 1000000;
|
||||
rffc507x_debug_info.calc_vco_inside_mhz = vco_frequency / 1000000;
|
||||
rffc507x_debug_info.calc_lodiv_log2 = lo_divider_log2;
|
||||
rffc507x_debug_info.calc_presc_log2 = prescaler_divider_log2;
|
||||
rffc507x_debug_info.calc_n_q24 = n_divider_q24;
|
||||
#endif
|
||||
|
||||
return {
|
||||
lo_divider_log2,
|
||||
prescaler_divider_log2,
|
||||
@@ -144,9 +197,11 @@ struct SynthConfig {
|
||||
*/
|
||||
|
||||
void RFFC507x::init() {
|
||||
#ifndef PRALINE
|
||||
gpio_rffc5072_resetx.set();
|
||||
gpio_rffc5072_resetx.output();
|
||||
reset();
|
||||
#endif
|
||||
|
||||
_bus.init();
|
||||
|
||||
@@ -158,10 +213,12 @@ void RFFC507x::reset() {
|
||||
/* TODO: Is RESETB pin ignored if sdi_ctrl.sipin=1? Programming guide
|
||||
* description of sdi_ctrl.sipin suggests the pin is not ignored.
|
||||
*/
|
||||
#ifndef PRALINE
|
||||
gpio_rffc5072_resetx.clear();
|
||||
halPolledDelay(ticks_during_reset);
|
||||
gpio_rffc5072_resetx.set();
|
||||
halPolledDelay(ticks_after_reset);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RFFC507x::flush() {
|
||||
@@ -233,6 +290,20 @@ void RFFC507x::set_mixer_current(const uint8_t value) {
|
||||
void RFFC507x::set_frequency(const rf::Frequency lo_frequency) {
|
||||
const SynthConfig synth_config = SynthConfig::calculate(lo_frequency);
|
||||
|
||||
#ifdef PRALINE
|
||||
// Calculate VCO frequency from LO frequency and divider
|
||||
const size_t lo_divider = 1U << synth_config.lo_divider_log2; // 2^lodiv_log2
|
||||
const rf::Frequency vco_freq = lo_frequency * lo_divider;
|
||||
|
||||
// Track what we calculated
|
||||
rffc507x_debug_info.requested_freq_mhz = lo_frequency / 1000000;
|
||||
rffc507x_debug_info.calculated_vco_mhz = vco_freq / 1000000;
|
||||
rffc507x_debug_info.expected_n = synth_config.n_divider_q24 >> 24;
|
||||
rffc507x_debug_info.expected_lodiv = synth_config.lo_divider_log2;
|
||||
rffc507x_debug_info.expected_presc = synth_config.prescaler_divider_log2;
|
||||
rffc507x_debug_info.was_called = true;
|
||||
#endif
|
||||
|
||||
/* Boost charge pump leakage if VCO frequency > 3.2GHz, indicated by
|
||||
* prescaler divider set to 4 (log2=2) instead of 2 (log2=1).
|
||||
*/
|
||||
|
||||
@@ -57,7 +57,15 @@ void Si5351::reset() {
|
||||
write_register(Register::CrystalInternalLoadCapacitance, 0b11010010);
|
||||
write_register(Register::FanoutEnable, 0x00);
|
||||
|
||||
#ifndef PRALINE
|
||||
reset_plls();
|
||||
#endif
|
||||
// NOTE: Do NOT call reset_plls() here!
|
||||
// Multisynth registers are not yet configured at this point.
|
||||
// Resetting PLLs with power-on default multisynth values (divider=6)
|
||||
// causes Si5351 to output wrong frequencies (66.666 MHz instead of 8 MHz).
|
||||
// The PLL reset should happen in init_clock_generator() AFTER multisynths
|
||||
// are properly configured. This matches HackRF reference firmware.
|
||||
}
|
||||
|
||||
Si5351::regvalue_t Si5351::read_register(const uint8_t reg) {
|
||||
@@ -93,7 +101,16 @@ void Si5351::set_ms_frequency(
|
||||
.r_div = r_div,
|
||||
};
|
||||
const auto regs = ms.reg(ms_number);
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: Use single-byte writes - multi-byte I2C writes seem to fail */
|
||||
const uint8_t base_reg = regs[0];
|
||||
for (size_t i = 1; i < regs.size(); i++) {
|
||||
write_register(base_reg + i - 1, regs[i]);
|
||||
}
|
||||
#else
|
||||
write(regs);
|
||||
#endif
|
||||
}
|
||||
|
||||
} /* namespace si5351 */
|
||||
|
||||
@@ -361,7 +361,16 @@ class Si5351 {
|
||||
}
|
||||
|
||||
void wait_for_device_ready() {
|
||||
#ifndef PRALINE
|
||||
while (device_status() & 0x80);
|
||||
#else
|
||||
// Add timeout to prevent infinite loop if I2C communication fails
|
||||
// (e.g., on PRALINE hardware with different configuration)
|
||||
uint32_t timeout = 100000;
|
||||
while ((device_status() & 0x80) && (timeout > 0)) {
|
||||
timeout--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool plla_loss_of_signal() {
|
||||
@@ -377,10 +386,15 @@ class Si5351 {
|
||||
}
|
||||
|
||||
void reset_plls() {
|
||||
#ifndef PRALINE
|
||||
// Datasheet recommends value 0xac, though the low nibble bits are not defined in AN619.
|
||||
write_register(Register::PLLReset, 0xac);
|
||||
#else
|
||||
// Reset both PLLA and PLLB. Use 0xA0 to match HackRF reference firmware.
|
||||
// The low nibble bits are reserved/undefined in AN619.
|
||||
write_register(Register::PLLReset, 0xa0);
|
||||
#endif
|
||||
}
|
||||
|
||||
regvalue_t read_register(const uint8_t reg);
|
||||
|
||||
template <size_t N>
|
||||
@@ -397,6 +411,18 @@ class Si5351 {
|
||||
write(config.reg(ms_number));
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
/* Write multisynth config using single-byte writes for debugging */
|
||||
void write_ms_single_byte(const size_t ms_number, const MultisynthFractional& config) {
|
||||
const auto regs = config.reg(ms_number);
|
||||
// regs[0] is the base register address, regs[1-8] are the data bytes
|
||||
const uint8_t base_reg = regs[0];
|
||||
for (size_t i = 1; i < regs.size(); i++) {
|
||||
write_register(base_reg + i - 1, regs[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_ms_frequency(
|
||||
const size_t ms_number,
|
||||
const uint32_t frequency,
|
||||
@@ -480,7 +506,6 @@ class Si5351 {
|
||||
}});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace si5351
|
||||
|
||||
#endif /*__SI5351_H__*/
|
||||
|
||||
@@ -46,6 +46,14 @@ class Arbiter {
|
||||
_bus.transfer(data, count);
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
/* Invalidate cached config - forces reconfiguration on next transfer.
|
||||
* Call this after directly manipulating SSP registers (e.g., FPGA access). */
|
||||
void invalidate() {
|
||||
_config = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
SPI& _bus;
|
||||
const SPIConfig* _config;
|
||||
|
||||
@@ -194,8 +194,12 @@ void timer0_callback(GPTDriver* const) {
|
||||
if (encoder_update(switches_raw) || encoder_read())
|
||||
event_mask |= EVT_MASK_ENCODER;
|
||||
|
||||
/* Signal event loop */
|
||||
/* Signal event loop */
|
||||
#ifdef PRALINE
|
||||
if (event_mask && thread_controls_event) {
|
||||
#else
|
||||
if (event_mask) {
|
||||
#endif
|
||||
chSysLockFromIsr();
|
||||
chEvtSignalI(thread_controls_event, event_mask);
|
||||
chSysUnlockFromIsr();
|
||||
@@ -227,8 +231,13 @@ void controls_init() {
|
||||
gptStart(&GPTD1, &timer0_config);
|
||||
gptStartContinuous(&GPTD1, timer0_match_count);
|
||||
|
||||
#ifdef PRALINE
|
||||
// Enable repeat for directional switches only
|
||||
for (auto i = Switch::Right; i <= Switch::Up; incr(i))
|
||||
#else
|
||||
// Enable repeat for directional and Select switches only
|
||||
for (auto i = Switch::Right; i <= Switch::Sel; incr(i))
|
||||
#endif
|
||||
switch_debounce[toUType(i)].enable_repeat();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,10 +52,17 @@ extern "C" {
|
||||
|
||||
CH_IRQ_HANDLER(PIN_INT4_IRQHandler) {
|
||||
CH_IRQ_PROLOGUE();
|
||||
|
||||
#ifdef PRALINE
|
||||
if (thread_lcd_frame_event) {
|
||||
chSysLockFromIsr();
|
||||
chEvtSignalI(thread_lcd_frame_event, EVT_MASK_LCD_FRAME_SYNC);
|
||||
chSysUnlockFromIsr();
|
||||
}
|
||||
#else
|
||||
chSysLockFromIsr();
|
||||
chEvtSignalI(thread_lcd_frame_event, EVT_MASK_LCD_FRAME_SYNC);
|
||||
chSysUnlockFromIsr();
|
||||
#endif
|
||||
|
||||
LPC_GPIO_INT->IST = (1U << 4);
|
||||
|
||||
|
||||
@@ -40,10 +40,17 @@ extern "C" {
|
||||
|
||||
CH_IRQ_HANDLER(RTC_IRQHandler) {
|
||||
CH_IRQ_PROLOGUE();
|
||||
|
||||
#ifdef PRALINE
|
||||
if (thread_rtc_event) {
|
||||
chSysLockFromIsr();
|
||||
chEvtSignalI(thread_rtc_event, EVT_MASK_RTC_TICK);
|
||||
chSysUnlockFromIsr();
|
||||
}
|
||||
#else
|
||||
chSysLockFromIsr();
|
||||
chEvtSignalI(thread_rtc_event, EVT_MASK_RTC_TICK);
|
||||
chSysUnlockFromIsr();
|
||||
#endif
|
||||
|
||||
rtc::interrupt::clear_all();
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "keeloq_common.hpp"
|
||||
|
||||
uint32_t keeloq_encrypt(const uint32_t data, const uint64_t key) {
|
||||
uint32_t x = data, r;
|
||||
|
||||
for (r = 0; r < 528; r++)
|
||||
x = (x >> 1) ^ ((bit(x, 0) ^ bit(x, 16) ^ (uint32_t)bit(key, r & 63) ^
|
||||
bit(KEELOQ_NLF, g5(x, 1, 9, 20, 26, 31)))
|
||||
<< 31);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
uint32_t keeloq_decrypt(const uint32_t data, const uint64_t key) {
|
||||
uint32_t x = data, r;
|
||||
|
||||
for (r = 0; r < 528; r++)
|
||||
x = (x << 1) ^ bit(x, 31) ^ bit(x, 15) ^ (uint32_t)bit(key, (15 - r) & 63) ^
|
||||
bit(KEELOQ_NLF, g5(x, 0, 8, 19, 25, 30));
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
uint64_t keeloq_normal_learning(uint32_t data, const uint64_t key) {
|
||||
uint32_t k1, k2;
|
||||
|
||||
data &= 0x0FFFFFFF;
|
||||
data |= 0x20000000;
|
||||
k1 = keeloq_decrypt(data, key);
|
||||
|
||||
data &= 0x0FFFFFFF;
|
||||
data |= 0x60000000;
|
||||
k2 = keeloq_decrypt(data, key);
|
||||
|
||||
return ((uint64_t)k2 << 32) | k1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef __KEELOQ_COMMON__
|
||||
#define __KEELOQ_COMMON__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define bit(x, n) (((x) >> (n)) & 1)
|
||||
#define g5(x, a, b, c, d, e) \
|
||||
(bit(x, a) + bit(x, b) * 2 + bit(x, c) * 4 + bit(x, d) * 8 + bit(x, e) * 16)
|
||||
|
||||
#define KEELOQ_NLF 0x3A5C742E
|
||||
|
||||
uint32_t keeloq_encrypt(const uint32_t data, const uint64_t key);
|
||||
uint32_t keeloq_decrypt(const uint32_t data, const uint64_t key);
|
||||
uint64_t keeloq_normal_learning(uint32_t data, const uint64_t key);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2026 lifegame1lu111
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "keeloq_file.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
bool read_keeloq_file(const fs::path& path, KeeloqData& data) {
|
||||
File file{};
|
||||
|
||||
auto result = file.open(path);
|
||||
|
||||
if (result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FileLineReader reader{file};
|
||||
|
||||
std::string raw = *reader.begin();
|
||||
auto chunks = split_string(raw, ';');
|
||||
|
||||
if (chunks.size() != 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data.mf_name = std::string{chunks[0]};
|
||||
data.serial = std::strtoul(chunks[1].data(), NULL, 16);
|
||||
data.counter = (uint16_t)std::atoi(chunks[2].data());
|
||||
data.btn = (uint8_t)std::atoi(chunks[3].data());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_keeloq_file(const fs::path& path, const KeeloqData& data) {
|
||||
delete_file(path);
|
||||
|
||||
File file{};
|
||||
|
||||
auto result = file.open(path, false, true);
|
||||
|
||||
if (result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string formatted = data.mf_name + ";" +
|
||||
to_string_hex(data.serial) + ";" +
|
||||
to_string_dec_uint(data.counter) + ";" +
|
||||
to_string_dec_uint(data.btn);
|
||||
|
||||
file.write_line(formatted);
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2026 lifegame1lu111
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __KEELOQ_FILE__
|
||||
#define __KEELOQ_FILE__
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "file_reader.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include <string_view>
|
||||
|
||||
struct KeeloqData {
|
||||
std::string mf_name{};
|
||||
uint32_t serial = 0;
|
||||
uint16_t counter = 0;
|
||||
uint8_t btn = 0;
|
||||
};
|
||||
|
||||
bool read_keeloq_file(const std::filesystem::path&, KeeloqData&);
|
||||
bool write_keeloq_file(const std::filesystem::path&, const KeeloqData&);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2026 lifegame1lu111
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "keeloq_keystore.hpp"
|
||||
|
||||
KeeloqKeystore::KeeloqKeystore() {
|
||||
ensure_directory(keeloq_keys_dir);
|
||||
|
||||
File keeloq_keys_file{};
|
||||
|
||||
if (keeloq_keys_file.open(keeloq_keys_dir / "MFCODES")) {
|
||||
return;
|
||||
}
|
||||
|
||||
FileLineReader reader{keeloq_keys_file};
|
||||
|
||||
for (const std::string& line : reader) {
|
||||
auto cols = split_string(line, ';');
|
||||
|
||||
if (cols.size() != 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
KeeloqKey key{
|
||||
std::string{cols[0]},
|
||||
std::strtoull(cols[1].data(), NULL, 16),
|
||||
(uint8_t)std::atoi(cols[2].data())};
|
||||
|
||||
keys.push_back(key);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<KeeloqKey>& KeeloqKeystore::get_keys() {
|
||||
return keys;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2026 lifegame1lu111
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __KEELOQ_KEYSTORE__
|
||||
#define __KEELOQ_KEYSTORE__
|
||||
|
||||
#include "file_reader.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include <string_view>
|
||||
|
||||
#define KEELOQ_SIMPLE_LEARNING 1
|
||||
#define KEELOQ_NORMAL_LEARNING 2
|
||||
|
||||
struct KeeloqKey {
|
||||
std::string mf_name{};
|
||||
uint64_t key = 0;
|
||||
uint8_t type = 0;
|
||||
};
|
||||
|
||||
class KeeloqKeystore {
|
||||
public:
|
||||
KeeloqKeystore();
|
||||
|
||||
const std::vector<KeeloqKey>& get_keys();
|
||||
|
||||
private:
|
||||
std::vector<KeeloqKey> keys{};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -145,6 +145,21 @@ Continuous (Fox-oring)
|
||||
rffc507x::RFFC507x first_if;
|
||||
ui::SystemView* system_view_ptr;
|
||||
|
||||
static uint32_t random_seed_state = 123456789;
|
||||
extern "C" int rand(void) {
|
||||
random_seed_state ^= random_seed_state << 13;
|
||||
random_seed_state ^= random_seed_state >> 17;
|
||||
random_seed_state ^= random_seed_state << 5;
|
||||
return (int)(random_seed_state & 0x7FFFFFFF);
|
||||
}
|
||||
extern "C" void srand(unsigned int seed) {
|
||||
if (seed == 0) {
|
||||
random_seed_state = 123456789;
|
||||
} else {
|
||||
random_seed_state = seed;
|
||||
}
|
||||
}
|
||||
|
||||
static void event_loop() {
|
||||
static ui::Context context;
|
||||
static ui::SystemView system_view{
|
||||
@@ -187,7 +202,7 @@ int main(void) {
|
||||
lcd_frame_sync_configure();
|
||||
rtc_interrupt_enable();
|
||||
|
||||
Theme::SetTheme((Theme::ThemeId)portapack::persistent_memory::ui_theme_id()); // load theme
|
||||
Theme::SetTheme((Theme::ThemeId)portapack::persistent_memory::ui_theme_id());
|
||||
|
||||
event_loop();
|
||||
|
||||
|
||||
@@ -56,6 +56,10 @@ using asahi_kasei::ak4951::AK4951;
|
||||
#include "i2cdevmanager.hpp"
|
||||
#include "battery.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include "platform_detect.h"
|
||||
}
|
||||
|
||||
namespace portapack {
|
||||
|
||||
const char* init_error = nullptr;
|
||||
@@ -337,14 +341,37 @@ static void set_cpu_clock_speed() {
|
||||
*/
|
||||
|
||||
/* Step into the 90-110MHz M4 clock range */
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: Enable and use 12MHz XTAL directly (no GP_CLKIN from Si5351) */
|
||||
|
||||
/* Step 1: Enable the crystal oscillator */
|
||||
LPC_CGU->XTAL_OSC_CTRL.ENABLE = 0; // 0 = enable (active low)
|
||||
LPC_CGU->XTAL_OSC_CTRL.HF = 0; // 0 = low frequency mode (1-20MHz)
|
||||
|
||||
/* Step 2: Wait for oscillator to stabilize (~250us at IRC speed) */
|
||||
volatile uint32_t delay = 3000; // ~250us at 12MHz IRC
|
||||
while (delay--);
|
||||
|
||||
/* Step 3: Configure PLL1 from XTAL
|
||||
* Fclkin = 12M, /N=1 = 12M, Fcco = 12M * 17 = 204M
|
||||
* Fclk = Fcco / (2*(P=1)) = 102M
|
||||
*/
|
||||
cgu::pll1::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
.fbsel = 0,
|
||||
.direct = 0,
|
||||
.psel = 0,
|
||||
.autoblock = 1,
|
||||
.nsel = 0, // N = 1
|
||||
.msel = 16, // M = 17, so 12MHz * 17 = 204MHz
|
||||
.clk_sel = cgu::CLK_SEL::XTAL,
|
||||
});
|
||||
#else
|
||||
/* OG:
|
||||
* Fclkin = 40M
|
||||
* /N=2 = 20M = PFDin
|
||||
* Fcco = PFDin * (M=10) = 200M
|
||||
* Fclkin = 40M, /N=2 = 20M, Fcco = 20M * 10 = 200M
|
||||
* r9:
|
||||
* Fclkin = 10M
|
||||
* /N=1 = 10M = PFDin
|
||||
* Fcco = PFDin * (M=20) = 200M
|
||||
* Fclkin = 10M, /N=1 = 10M, Fcco = 10M * 20 = 200M
|
||||
* Fclk = Fcco / (2*(P=1)) = 100M
|
||||
*/
|
||||
cgu::pll1::ctrl({
|
||||
@@ -358,20 +385,41 @@ static void set_cpu_clock_speed() {
|
||||
.msel = hackrf_r9 ? 19UL : 9UL,
|
||||
.clk_sel = cgu::CLK_SEL::GP_CLKIN,
|
||||
});
|
||||
#endif
|
||||
|
||||
cgu::pll1::enable();
|
||||
#ifndef PRALINE
|
||||
while (!cgu::pll1::is_locked());
|
||||
|
||||
set_clock_config(clock_config_pll1_step);
|
||||
|
||||
/* Delay >50us at 90-110MHz clock speed */
|
||||
volatile uint32_t delay = 1400;
|
||||
while (delay--);
|
||||
|
||||
set_clock_config(clock_config_pll1);
|
||||
|
||||
/* Remove /2P divider from PLL1 output to achieve full speed */
|
||||
cgu::pll1::direct();
|
||||
#else
|
||||
// Wait for PLL1 to lock with timeout
|
||||
{
|
||||
uint32_t timeout = 100000;
|
||||
while (!cgu::pll1::is_locked() && timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
}
|
||||
|
||||
if (cgu::pll1::is_locked()) {
|
||||
set_clock_config(clock_config_pll1_step);
|
||||
|
||||
/* Delay >50us at 90-110MHz clock speed */
|
||||
volatile uint32_t delay = 1400;
|
||||
while (delay--);
|
||||
set_clock_config(clock_config_pll1);
|
||||
|
||||
/* Remove /2P divider from PLL1 output to achieve full speed */
|
||||
cgu::pll1::direct();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void draw_splash_screen_icon(int16_t n, const ui::Bitmap& bitmap) {
|
||||
@@ -505,6 +553,11 @@ init_status_t init() {
|
||||
|
||||
chThdSleepMilliseconds(100);
|
||||
|
||||
detect_hardware_platform();
|
||||
finalize_detect_hardware_platform();
|
||||
|
||||
chThdSleepMilliseconds(100);
|
||||
|
||||
configure_pins_portapack();
|
||||
|
||||
portapack::io.init();
|
||||
@@ -534,11 +587,11 @@ init_status_t init() {
|
||||
cgu::pll1::disable();
|
||||
|
||||
set_cpu_clock_speed();
|
||||
|
||||
/* sample max: 1023 sample_t AKA uint16_t
|
||||
* touch_sensitivity: range: 1 to 128
|
||||
* threshold range: 1023/1 to 1023/128 = 1023 to 8
|
||||
*/
|
||||
|
||||
touch_threshold = portapack::persistent_memory::touchscreen_threshold();
|
||||
|
||||
if (lcd_fast_setup)
|
||||
@@ -561,8 +614,10 @@ init_status_t init() {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
clock_manager.set_reference_ppb(persistent_memory::correction_ppb());
|
||||
|
||||
clock_manager.enable_if_clocks();
|
||||
clock_manager.enable_codec_clocks();
|
||||
|
||||
radio::init();
|
||||
|
||||
sdcStart(&SDCD1, nullptr);
|
||||
@@ -574,12 +629,18 @@ init_status_t init() {
|
||||
draw_splash_screen_icon(2, ui::bitmap_icon_sd);
|
||||
|
||||
init_status_t return_code = init_status_t::INIT_SUCCESS;
|
||||
#ifndef PRALINE
|
||||
// HackRF One uses CPLD - load it via JTAG
|
||||
if (!hackrf::cpld::load_sram()) {
|
||||
if (lcd_fast_setup)
|
||||
chDbgPanic("HACKRF CPLD FAILED");
|
||||
|
||||
return_code = init_status_t::INIT_HACKRF_CPLD_FAILED;
|
||||
}
|
||||
#else
|
||||
// HackRF Pro (PRALINE) uses FPGA - already loaded in board.cpp __early_init()
|
||||
// via fpga_bridge_init(), so nothing to do here
|
||||
#endif
|
||||
|
||||
if (lcd_fast_setup)
|
||||
draw_splash_screen_icon(3, ui::bitmap_icon_hackrf);
|
||||
@@ -592,6 +653,7 @@ init_status_t init() {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
audio::init(portapack_audio_codec());
|
||||
|
||||
battery::BatteryManagement::set_calc_override(persistent_memory::ui_override_batt_calc());
|
||||
i2cdev::I2CDevManager::init();
|
||||
|
||||
|
||||
@@ -26,8 +26,17 @@
|
||||
#include "rffc507x.hpp"
|
||||
#include "max2837.hpp"
|
||||
#include "max2839.hpp"
|
||||
#include "max5864.hpp"
|
||||
|
||||
#ifdef PRALINE
|
||||
#include "max2831.hpp"
|
||||
extern "C" {
|
||||
#include "fpga_bridge.h"
|
||||
}
|
||||
#else
|
||||
#include "baseband_cpld.hpp"
|
||||
#endif
|
||||
|
||||
#include "max5864.hpp"
|
||||
|
||||
#include "tuning.hpp"
|
||||
|
||||
@@ -42,6 +51,10 @@ using namespace hackrf::one;
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
#include "hal.h" // For LPC_SGPIO
|
||||
|
||||
#include <array>
|
||||
|
||||
/* Direct access to the radio. Setting values incorrectly can damage
|
||||
* the device. Applications should use ReceiverModel or TransmitterModel
|
||||
* instead of calling these functions directly. */
|
||||
@@ -56,6 +69,18 @@ static constexpr uint32_t ssp_scr(
|
||||
return static_cast<uint8_t>(pclk_f / cpsr / spi_f - 1);
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
/* MAX2831 uses 9-bit SPI transfers */
|
||||
static constexpr SPIConfig ssp_config_max283x = {
|
||||
.end_cb = NULL,
|
||||
.ssport = gpio_max283x_select.port(),
|
||||
.sspad = gpio_max283x_select.pad(),
|
||||
.cr0 =
|
||||
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max283x_spi_f) + 3) | CR0_FRFSPI | CR0_DSS9BIT,
|
||||
.cpsr = ssp1_cpsr,
|
||||
};
|
||||
#else
|
||||
/* MAX2837/MAX2839 use 16-bit SPI transfers */
|
||||
static constexpr SPIConfig ssp_config_max283x = {
|
||||
.end_cb = NULL,
|
||||
.ssport = gpio_max283x_select.port(),
|
||||
@@ -64,6 +89,7 @@ static constexpr SPIConfig ssp_config_max283x = {
|
||||
CR0_CLOCKRATE(ssp_scr(ssp1_pclk_f, ssp1_cpsr, max283x_spi_f) + 3) | CR0_FRFSPI | CR0_DSS16BIT,
|
||||
.cpsr = ssp1_cpsr,
|
||||
};
|
||||
#endif
|
||||
|
||||
static constexpr SPIConfig ssp_config_max5864 = {
|
||||
.end_cb = NULL,
|
||||
@@ -89,27 +115,58 @@ rffc507x::RFFC507x first_if;
|
||||
max283x::MAX283x* second_if;
|
||||
max2837::MAX2837 second_if_max2837{ssp1_target_max283x};
|
||||
max2839::MAX2839 second_if_max2839{ssp1_target_max283x};
|
||||
static max5864::MAX5864 baseband_codec{ssp1_target_max5864};
|
||||
#ifdef PRALINE
|
||||
max2831::MAX2831 second_if_max2831{ssp1_target_max283x};
|
||||
#else
|
||||
static baseband::CPLD baseband_cpld;
|
||||
#endif
|
||||
static max5864::MAX5864 baseband_codec{ssp1_target_max5864};
|
||||
|
||||
// load_sram() is called at boot in portapack.cpp, including verify CPLD part, so default direction is Receive
|
||||
static rf::Direction direction{rf::Direction::Receive};
|
||||
static bool baseband_invert = false;
|
||||
static bool mixer_invert = false;
|
||||
|
||||
#ifdef PRALINE
|
||||
static rf::Direction cached_direction = rf::Direction::Receive;
|
||||
static bool cached_rf_amp = false;
|
||||
static int_fast8_t cached_lna_gain = 0;
|
||||
static int_fast8_t cached_vga_gain = 0;
|
||||
#endif
|
||||
|
||||
void init() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses MAX2831 transceiver */
|
||||
second_if = (max283x::MAX283x*)&second_if_max2831;
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_not_ant_pwr.write(1);
|
||||
gpio_r9_not_ant_pwr.output();
|
||||
}
|
||||
rf_path.init();
|
||||
first_if.init();
|
||||
second_if = hackrf_r9
|
||||
? (max283x::MAX283x*)&second_if_max2839
|
||||
: (max283x::MAX283x*)&second_if_max2837;
|
||||
#endif
|
||||
rf_path.init();
|
||||
first_if.init();
|
||||
second_if->init();
|
||||
baseband_codec.init();
|
||||
#ifndef PRALINE
|
||||
/* HackRF One uses CPLD for Q inversion control.
|
||||
* PRALINE uses FPGA and the pin (P2_3) is used for LCD_TE on H4M. */
|
||||
baseband_cpld.init();
|
||||
#else
|
||||
/* Initialize FPGA registers - DC_BLOCK must be enabled for RX */
|
||||
// debug::fpga::init();
|
||||
fpga_debug_register_write(1, 0x01); // DC_BLOCK=1, QUARTER_SHIFT=0, Q_INVERT=0
|
||||
fpga_debug_register_write(2, 0x00); // RX_DECIM=0 (no decimation for testing)
|
||||
fpga_debug_register_write(3, 0x00); // TX_CTRL=0
|
||||
fpga_debug_register_write(4, 0x00); // TX_INTRP=0
|
||||
fpga_debug_register_write(5, 0x00); // TX_PSTEP=0
|
||||
|
||||
ssp1_arbiter.invalidate();
|
||||
chThdSleepMilliseconds(10); // Let FPGA registers settle
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_direction(const rf::Direction new_direction) {
|
||||
@@ -120,6 +177,10 @@ void set_direction(const rf::Direction new_direction) {
|
||||
// Deleting that load_sram_no_verify() (or the original , load_sram() ), solves random TX swap I/Q problem in H1R1 , others OK- (and no side effects to all).
|
||||
// hackrf::cpld::load_sram_no_verify(); // After commit "removed the use of the hackrf cpld eeprom #1732", in a H1R1, Mic App wrong SSB TX with random USB/LSB change.
|
||||
|
||||
#ifdef PRALINE
|
||||
cached_direction = new_direction; // Track state for debug and potentially other purposes.
|
||||
#endif
|
||||
|
||||
direction = new_direction;
|
||||
|
||||
if (hackrf_r9) {
|
||||
@@ -143,7 +204,20 @@ void set_direction(const rf::Direction new_direction) {
|
||||
*/
|
||||
baseband_invert = false;
|
||||
}
|
||||
#ifndef PRALINE
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
#else
|
||||
// TEST: Force baseband invert for Praline (like r9)
|
||||
// baseband_invert = (direction == rf::Direction::Receive);
|
||||
|
||||
// Praline: Control Q inversion via FPGA register
|
||||
uint8_t ctrl_reg = 0x01; // DC_BLOCK enabled
|
||||
if (mixer_invert ^ baseband_invert) {
|
||||
ctrl_reg |= 0x02; // Set Q_INVERT bit
|
||||
}
|
||||
fpga_debug_register_write(1, ctrl_reg);
|
||||
ssp1_arbiter.invalidate();
|
||||
#endif
|
||||
|
||||
second_if->set_mode((direction == rf::Direction::Transmit) ? max283x::Mode::Transmit : max283x::Mode::Receive);
|
||||
rf_path.set_direction(direction);
|
||||
@@ -196,7 +270,20 @@ bool set_tuning_frequency(const rf::Frequency frequency) {
|
||||
|
||||
rf_path.set_band(tuning_config.rf_path_band);
|
||||
mixer_invert = tuning_config.mixer_invert;
|
||||
#ifndef PRALINE
|
||||
baseband_cpld.set_invert(mixer_invert ^ baseband_invert);
|
||||
#else
|
||||
// TEST: Force baseband invert for Praline (like r9)
|
||||
// baseband_invert = (direction == rf::Direction::Receive);
|
||||
|
||||
// PRALINE: Update FPGA Q inversion when tuning changes
|
||||
uint8_t ctrl_reg = 0x01; // DC_BLOCK enabled
|
||||
if (mixer_invert ^ baseband_invert) {
|
||||
ctrl_reg |= 0x02; // Set Q_INVERT bit
|
||||
}
|
||||
fpga_debug_register_write(1, ctrl_reg);
|
||||
ssp1_arbiter.invalidate();
|
||||
#endif
|
||||
|
||||
return result_second_if;
|
||||
} else {
|
||||
@@ -205,14 +292,23 @@ bool set_tuning_frequency(const rf::Frequency frequency) {
|
||||
}
|
||||
|
||||
void set_rf_amp(const bool rf_amp) {
|
||||
#ifdef PRALINE
|
||||
cached_rf_amp = rf_amp; // Track state for debug and potentialy other purposes.
|
||||
#endif
|
||||
rf_path.set_rf_amp(rf_amp);
|
||||
}
|
||||
|
||||
void set_lna_gain(const int_fast8_t db) {
|
||||
#ifdef PRALINE
|
||||
cached_lna_gain = db; // Track state for debug and potentially other purposes.
|
||||
#endif
|
||||
second_if->set_lna_gain(db);
|
||||
}
|
||||
|
||||
void set_vga_gain(const int_fast8_t db) {
|
||||
#ifdef PRALINE
|
||||
cached_vga_gain = db; // Track state for debug and potentially other purposes.
|
||||
#endif
|
||||
second_if->set_vga_gain(db);
|
||||
}
|
||||
|
||||
@@ -235,11 +331,17 @@ void set_baseband_rate(const uint32_t rate) {
|
||||
|
||||
void set_antenna_bias(const bool on) {
|
||||
/* Pull MOSFET gate low to turn on antenna bias. */
|
||||
#ifdef PRALINE
|
||||
// Praline: P2_12 = GPIO1[12], ANT_BIAS_EN_N (active LOW)
|
||||
LPC_GPIO->CLR[1] = on ? (1 << 12) : 0;
|
||||
LPC_GPIO->SET[1] = on ? 0 : (1 << 12);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_not_ant_pwr.write(on ? 0 : 1);
|
||||
} else {
|
||||
first_if.set_gpo1(on ? 0 : 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_tx_max283x_iq_phase_calibration(const size_t v) {
|
||||
@@ -275,8 +377,32 @@ void disable() {
|
||||
led_tx.off();
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
void invalidate_spi_config() {
|
||||
ssp1_arbiter.invalidate();
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace debug {
|
||||
|
||||
#ifdef PRALINE
|
||||
rf::Direction get_cached_direction() {
|
||||
return cached_direction;
|
||||
}
|
||||
|
||||
bool get_cached_rf_amp() {
|
||||
return cached_rf_amp;
|
||||
}
|
||||
|
||||
int_fast8_t get_cached_lna_gain() {
|
||||
return cached_lna_gain;
|
||||
}
|
||||
|
||||
int_fast8_t get_cached_vga_gain() {
|
||||
return cached_vga_gain;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace first_if {
|
||||
|
||||
uint32_t register_read(const size_t register_number) {
|
||||
@@ -287,6 +413,48 @@ void register_write(const size_t register_number, uint32_t value) {
|
||||
radio::first_if.write(register_number, value);
|
||||
}
|
||||
|
||||
#ifdef PRALINE
|
||||
extern "C" {
|
||||
extern struct rffc507x_debug_t {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_vco_mhz;
|
||||
uint32_t expected_n;
|
||||
uint8_t expected_lodiv;
|
||||
uint8_t expected_presc;
|
||||
bool was_called;
|
||||
uint32_t calc_lo_freq_mhz;
|
||||
uint32_t calc_vco_inside_mhz;
|
||||
uint8_t calc_lodiv_log2;
|
||||
uint8_t calc_presc_log2;
|
||||
uint64_t calc_n_q24;
|
||||
} rffc507x_debug_info;
|
||||
}
|
||||
|
||||
/*struct TuningInfo {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t expected_n;
|
||||
uint8_t expected_lodiv;
|
||||
uint8_t expected_presc;
|
||||
bool was_called;
|
||||
};*/
|
||||
|
||||
TuningInfo get_tuning_info() {
|
||||
return {
|
||||
rffc507x_debug_info.requested_freq_mhz,
|
||||
rffc507x_debug_info.calculated_vco_mhz,
|
||||
rffc507x_debug_info.expected_n,
|
||||
rffc507x_debug_info.expected_lodiv,
|
||||
rffc507x_debug_info.expected_presc,
|
||||
rffc507x_debug_info.was_called,
|
||||
rffc507x_debug_info.calc_lo_freq_mhz,
|
||||
rffc507x_debug_info.calc_vco_inside_mhz,
|
||||
rffc507x_debug_info.calc_lodiv_log2,
|
||||
rffc507x_debug_info.calc_presc_log2,
|
||||
rffc507x_debug_info.calc_n_q24,
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
} /* namespace first_if */
|
||||
|
||||
namespace second_if {
|
||||
@@ -305,6 +473,79 @@ int8_t temp_sense() {
|
||||
|
||||
} /* namespace second_if */
|
||||
|
||||
namespace rf_path_info {
|
||||
rf::path::Band get_current_band() {
|
||||
return radio::rf_path.get_band();
|
||||
}
|
||||
} /* namespace rf_path_info */
|
||||
|
||||
#ifdef PRALINE
|
||||
namespace fpga {
|
||||
|
||||
/* Use fpga_bridge.c functions for FPGA register access.
|
||||
* These properly switch SPI mode between iCE40 (Mode 3, 8-bit)
|
||||
* and MAX2831 (Mode 0, 9-bit). After each access, we must
|
||||
* invalidate the SPI arbiter's cached config since fpga_bridge.c
|
||||
* modifies SSP1 registers directly. */
|
||||
|
||||
uint32_t register_read(const size_t register_number) {
|
||||
uint32_t result = fpga_debug_register_read(static_cast<uint8_t>(register_number));
|
||||
ssp1_arbiter.invalidate(); // Force arbiter to reconfigure on next transfer
|
||||
return result;
|
||||
}
|
||||
|
||||
void register_write(const size_t register_number, uint32_t value) {
|
||||
fpga_debug_register_write(static_cast<uint8_t>(register_number), static_cast<uint8_t>(value));
|
||||
ssp1_arbiter.invalidate(); // Force arbiter to reconfigure on next transfer
|
||||
}
|
||||
|
||||
void init() {
|
||||
// Initialize FPGA registers after bitstream load
|
||||
// DC_BLOCK (bit 0) must be enabled for RX to work
|
||||
fpga_debug_register_write(1, 0x01); // CTRL: DC_BLOCK=1
|
||||
fpga_debug_register_write(2, 0x00); // RX_DECIM: no decimation
|
||||
fpga_debug_register_write(3, 0x00); // TX_CTRL: NCO disabled
|
||||
fpga_debug_register_write(4, 0x00); // TX_INTRP: no interpolation
|
||||
fpga_debug_register_write(5, 0x00); // TX_PSTEP: zero phase step
|
||||
ssp1_arbiter.invalidate(); // Force arbiter to reconfigure on next transfer
|
||||
}
|
||||
|
||||
} /* namespace fpga */
|
||||
#endif
|
||||
|
||||
namespace sgpio {
|
||||
|
||||
/* SGPIO register map for debug viewing
|
||||
* We expose key registers for diagnosing data flow issues.
|
||||
* Register numbers map to:
|
||||
* 0: CTRL_ENABLE - Which slices are enabled
|
||||
* 1: GPIO_INREG - GPIO input register (data pins state)
|
||||
* 2: GPIO_OUTREG - GPIO output register (direction, disable, etc)
|
||||
* 3: GPIO_OENREG - GPIO output enable register
|
||||
* 4: STATUS_1 - Exchange interrupt status (slice A = bit 0)
|
||||
* 5: REG_SS[0] - Shadow register slice A (current sample data)
|
||||
*/
|
||||
uint32_t register_read(const size_t register_number) {
|
||||
switch (register_number) {
|
||||
case 0:
|
||||
return LPC_SGPIO->CTRL_ENABLE;
|
||||
case 1:
|
||||
return LPC_SGPIO->GPIO_INREG;
|
||||
case 2:
|
||||
return LPC_SGPIO->GPIO_OUTREG;
|
||||
case 3:
|
||||
return LPC_SGPIO->GPIO_OENREG;
|
||||
case 4:
|
||||
return LPC_SGPIO->STATUS_1;
|
||||
case 5:
|
||||
return LPC_SGPIO->REG_SS[0];
|
||||
default:
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace sgpio */
|
||||
|
||||
} /* namespace debug */
|
||||
|
||||
} /* namespace radio */
|
||||
|
||||
@@ -62,6 +62,10 @@ void set_rx_max283x_iq_phase_calibration(const size_t v);
|
||||
// void configure(Configuration configuration);
|
||||
void disable();
|
||||
|
||||
#ifdef PRALINE
|
||||
void invalidate_spi_config();
|
||||
#endif
|
||||
|
||||
namespace debug {
|
||||
|
||||
namespace first_if {
|
||||
@@ -69,6 +73,24 @@ namespace first_if {
|
||||
uint32_t register_read(const size_t register_number);
|
||||
void register_write(const size_t register_number, uint32_t value);
|
||||
|
||||
#ifdef PRALINE
|
||||
struct TuningInfo {
|
||||
uint32_t requested_freq_mhz;
|
||||
uint32_t calculated_vco_mhz;
|
||||
uint32_t expected_n;
|
||||
uint8_t expected_lodiv;
|
||||
uint8_t expected_presc;
|
||||
bool was_called;
|
||||
uint32_t calc_lo_freq_mhz;
|
||||
uint32_t calc_vco_inside_mhz;
|
||||
uint8_t calc_lodiv_log2;
|
||||
uint8_t calc_presc_log2;
|
||||
uint64_t calc_n_q24;
|
||||
};
|
||||
|
||||
TuningInfo get_tuning_info();
|
||||
#endif
|
||||
|
||||
} /* namespace first_if */
|
||||
|
||||
namespace second_if {
|
||||
@@ -81,6 +103,34 @@ int8_t temp_sense();
|
||||
|
||||
} /* namespace second_if */
|
||||
|
||||
namespace rf_path_info {
|
||||
|
||||
rf::path::Band get_current_band();
|
||||
|
||||
} /* namespace rf_path_info */
|
||||
|
||||
#ifdef PRALINE
|
||||
namespace fpga {
|
||||
|
||||
uint32_t register_read(const size_t register_number);
|
||||
void register_write(const size_t register_number, uint32_t value);
|
||||
void init();
|
||||
|
||||
} /* namespace fpga */
|
||||
|
||||
/* State tracking - GPIO pins are write-only so we cache last known state */
|
||||
rf::Direction get_cached_direction();
|
||||
bool get_cached_rf_amp();
|
||||
int_fast8_t get_cached_lna_gain();
|
||||
int_fast8_t get_cached_vga_gain();
|
||||
#endif
|
||||
|
||||
namespace sgpio {
|
||||
|
||||
uint32_t register_read(const size_t register_number);
|
||||
|
||||
} /* namespace sgpio */
|
||||
|
||||
} /* namespace debug */
|
||||
|
||||
} /* namespace radio */
|
||||
|
||||
@@ -34,6 +34,12 @@
|
||||
#include "dsp_iir_config.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#ifdef PRALINE
|
||||
extern "C" {
|
||||
#include "fpga_bridge.h"
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace hackrf::one;
|
||||
using namespace portapack;
|
||||
|
||||
@@ -303,8 +309,20 @@ int32_t ReceiverModel::tuning_offset() {
|
||||
|
||||
void ReceiverModel::update_tuning_frequency() {
|
||||
// TODO: use positive offset if freq < offset.
|
||||
if (enabled_)
|
||||
if (enabled_) {
|
||||
radio::set_tuning_frequency(target_frequency() + hidden_offset + tuning_offset());
|
||||
|
||||
#ifdef PRALINE
|
||||
/* Praline: Must re-apply baseband filter after frequency change
|
||||
* Reference: hackrf_usb radio.c radio_set_frequency()
|
||||
*
|
||||
* Different frequency ranges may use different quarter-shift modes,
|
||||
* which affects the required LPF bandwidth. For now we just
|
||||
* recalculate the filter to be safe.
|
||||
*/
|
||||
update_baseband_bandwidth();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverModel::set_hidden_offset(rf::Frequency offset) {
|
||||
@@ -313,8 +331,28 @@ void ReceiverModel::set_hidden_offset(rf::Frequency offset) {
|
||||
}
|
||||
|
||||
void ReceiverModel::update_baseband_bandwidth() {
|
||||
if (enabled_)
|
||||
if (enabled_) {
|
||||
#ifdef PRALINE
|
||||
/* Praline: LPF bandwidth calculation
|
||||
* Reference: hackrf_usb radio.c radio_set_filter()
|
||||
*
|
||||
* LPF = (sample_rate * 3) / 8
|
||||
* Plus additional offset if quarter-shift is enabled (not implemented yet)
|
||||
*/
|
||||
uint32_t lpf_bandwidth = (sampling_rate() * 3) / 8;
|
||||
|
||||
// For now, quarter-shift is disabled, so no offset added
|
||||
// When quarter-shift is implemented:
|
||||
// if (quarter_shift_enabled) {
|
||||
// uint32_t offset = (sampling_rate() << decimation_n) / 8;
|
||||
// lpf_bandwidth += offset * 2;
|
||||
// }
|
||||
|
||||
radio::set_baseband_filter_bandwidth_rx(lpf_bandwidth);
|
||||
#else
|
||||
radio::set_baseband_filter_bandwidth_rx(baseband_bandwidth());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverModel::update_sampling_rate() {
|
||||
@@ -323,9 +361,9 @@ void ReceiverModel::update_sampling_rate() {
|
||||
// protocols that need quick RX/TX turn-around.
|
||||
|
||||
// Disabling baseband while changing sampling rates seems like a good idea...
|
||||
if (enabled_)
|
||||
if (enabled_) {
|
||||
radio::set_baseband_rate(sampling_rate());
|
||||
|
||||
}
|
||||
update_tuning_frequency();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,36 @@ namespace path {
|
||||
|
||||
namespace {
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses a simplified RF path with only 5 control signals.
|
||||
* The RF path architecture is completely different from HackRF One.
|
||||
*/
|
||||
struct PralineConfig {
|
||||
bool tx_en;
|
||||
bool mix_en_n; // Inverted: 0 = mixer enabled
|
||||
bool lpf_en;
|
||||
bool rf_amp_en;
|
||||
bool ant_bias_en_n; // Inverted: 0 = bias enabled
|
||||
|
||||
static void gpio_init() {
|
||||
gpio_tx_enable.output();
|
||||
gpio_mix_enable_n.output();
|
||||
gpio_lpf_enable.output();
|
||||
gpio_rf_amp_enable.output();
|
||||
gpio_ant_bias_disable.output();
|
||||
}
|
||||
|
||||
void apply() const {
|
||||
gpio_tx_enable.write(tx_en);
|
||||
gpio_mix_enable_n.write(mix_en_n);
|
||||
gpio_lpf_enable.write(lpf_en);
|
||||
gpio_rf_amp_enable.write(rf_amp_en);
|
||||
gpio_ant_bias_disable.write(ant_bias_en_n);
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
/* HackRF One uses 11 GPIOs for RF path control */
|
||||
using GPIOs = std::array<GPIO, 11>;
|
||||
|
||||
/* TODO: ARM GCC 4.8 2014q3 doesn't like this array inside struct Config.
|
||||
@@ -53,7 +83,10 @@ constexpr GPIOs gpios{
|
||||
gpio_rx_amp,
|
||||
gpio_not_rx_amp_pwr,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef PRALINE
|
||||
/* HackRF One Config struct - not used on PRALINE */
|
||||
struct Config {
|
||||
using base_type = uint16_t;
|
||||
|
||||
@@ -153,7 +186,10 @@ struct Config {
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif /* !PRALINE */
|
||||
|
||||
#ifndef PRALINE
|
||||
/* HackRF One config table - not used on PRALINE */
|
||||
using ConfigAmp = std::array<Config, 2>;
|
||||
using ConfigDirection = std::array<ConfigAmp, 2>;
|
||||
using ConfigBand = std::array<ConfigDirection, 3>;
|
||||
@@ -193,12 +229,26 @@ constexpr Config get_config(
|
||||
const bool amplify) {
|
||||
return config_table[toUType(band)][toUType(direction)][amplify ? 1 : 0];
|
||||
}
|
||||
#endif /* !PRALINE */
|
||||
|
||||
} /* namespace */
|
||||
|
||||
void Path::init() {
|
||||
#ifdef PRALINE
|
||||
PralineConfig::gpio_init();
|
||||
/* Set safe initial state: RX mode, mixer enabled, LPF on, amp off, no bias */
|
||||
PralineConfig config = {
|
||||
.tx_en = false,
|
||||
.mix_en_n = false, // Mixer enabled (inverted)
|
||||
.lpf_en = true, // LPF on for low band
|
||||
.rf_amp_en = false, // Amp off
|
||||
.ant_bias_en_n = true // Bias off (inverted)
|
||||
};
|
||||
config.apply();
|
||||
#else
|
||||
update();
|
||||
Config::gpio_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Path::set_direction(const Direction new_direction) {
|
||||
@@ -208,6 +258,7 @@ void Path::set_direction(const Direction new_direction) {
|
||||
|
||||
void Path::set_band(const Band new_band) {
|
||||
band = new_band;
|
||||
_band = new_band;
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -220,20 +271,50 @@ void Path::update() {
|
||||
/* 0 ^ 0 => 0 & 0 = 0 ^ 0 = 0 (no change)
|
||||
* 0 ^ 1 => 1 & 0 = 0 ^ 0 = 0 (ignore change to 1)
|
||||
* 1 ^ 0 => 1 & 1 = 1 ^ 1 = 0 (allow change to 0)
|
||||
* 1 ^ 1 => 0 & 1 = 0 ^ 1 = 1 (no change)
|
||||
* 1 ^ 1 => 0 & 1 = 0 ^ 1 = 1 (no change) */
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE RF path control:
|
||||
* - tx_en: 1 for TX, 0 for RX
|
||||
* - mix_en_n: 0 to enable mixer (inverted), 1 to bypass
|
||||
* - lpf_en: 1 for low band (< 2.4 GHz), 0 for high band
|
||||
* - rf_amp_en: 1 to enable RF amplifier
|
||||
* - ant_bias_en_n: 0 to enable antenna bias (inverted)
|
||||
*/
|
||||
// const Config changed = _config ^ config_next;
|
||||
// const Config turned_off = _config & changed;
|
||||
|
||||
PralineConfig config;
|
||||
|
||||
/* In transition, ignore the bits that are turning on. So this transition phase
|
||||
* only turns off signals. It doesn't turn on signals.
|
||||
*/
|
||||
// const Config transition_config = _config ^ turned_off;
|
||||
// update_signals(transition_config);
|
||||
|
||||
config.tx_en = (direction == Direction::Transmit);
|
||||
|
||||
/* Mixer bypass for mid band (2.3-2.7 GHz direct to MAX2831) */
|
||||
config.mix_en_n = (band == Band::Mid); // 1 = bypass (disabled)
|
||||
|
||||
/* Move to the final state by turning on required signals. */
|
||||
/* LPF for low band */
|
||||
|
||||
config.lpf_en = (band == Band::Low);
|
||||
|
||||
/* RF amp when amplification requested */
|
||||
config.rf_amp_en = rf_amp;
|
||||
|
||||
/* Antenna bias off by default */
|
||||
config.ant_bias_en_n = true;
|
||||
|
||||
config.apply();
|
||||
|
||||
#else
|
||||
/* HackRF One RF path control */
|
||||
const auto config = get_config(direction, band, rf_amp);
|
||||
config.apply();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace path
|
||||
|
||||
@@ -58,12 +58,16 @@ class Path {
|
||||
void set_band(const Band band);
|
||||
void set_rf_amp(const bool rf_amp);
|
||||
|
||||
Band get_band() const { return _band; } //_band is used solely for debugging purposes.
|
||||
|
||||
private:
|
||||
Direction direction{Direction::Receive};
|
||||
Band band{Band::Mid};
|
||||
bool rf_amp{false};
|
||||
|
||||
void update();
|
||||
|
||||
Band _band{Band::Mid}; //_band is solely used of debugging purposes
|
||||
};
|
||||
|
||||
} // namespace path
|
||||
|
||||
@@ -31,6 +31,11 @@
|
||||
#include "shell.hpp"
|
||||
#include "chprintf.h"
|
||||
#include "portapack.hpp"
|
||||
#include "../flashsize.h"
|
||||
|
||||
extern "C" {
|
||||
#include "platform_detect.h"
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shell termination event source.
|
||||
@@ -65,8 +70,58 @@ static void list_commands(BaseSequentialStream* chp, const ShellCommand* scp) {
|
||||
}
|
||||
}
|
||||
|
||||
static const char* get_board_revision_string(board_rev_t rev) {
|
||||
switch (rev) {
|
||||
case BOARD_REV_HACKRF1_OLD:
|
||||
return "HackRF R1-R5";
|
||||
case BOARD_REV_HACKRF1_R6:
|
||||
return "HackRF R6";
|
||||
case BOARD_REV_HACKRF1_R7:
|
||||
return "HackRF R7";
|
||||
case BOARD_REV_HACKRF1_R8:
|
||||
return "HackRF R8";
|
||||
case BOARD_REV_HACKRF1_R9:
|
||||
return "HackRF R9";
|
||||
case BOARD_REV_HACKRF1_R10:
|
||||
return "HackRF R10";
|
||||
case BOARD_REV_GSG_HACKRF1_R6:
|
||||
return "GSG HackRF R6";
|
||||
case BOARD_REV_GSG_HACKRF1_R7:
|
||||
return "GSG HackRF R7";
|
||||
case BOARD_REV_GSG_HACKRF1_R8:
|
||||
return "GSG HackRF R8";
|
||||
case BOARD_REV_GSG_HACKRF1_R9:
|
||||
return "GSG HackRF R9";
|
||||
case BOARD_REV_GSG_HACKRF1_R10:
|
||||
return "GSG HackRF R10";
|
||||
case BOARD_REV_PRALINE_R0_1:
|
||||
case BOARD_REV_PRALINE_R0_2:
|
||||
case BOARD_REV_PRALINE_R0_3:
|
||||
return "HackRF Pro R0";
|
||||
case BOARD_REV_PRALINE_R1_0:
|
||||
case BOARD_REV_PRALINE_R1_1:
|
||||
case BOARD_REV_PRALINE_R1_2:
|
||||
return "HackRF Pro R1";
|
||||
case BOARD_REV_GSG_PRALINE_R0_1:
|
||||
case BOARD_REV_GSG_PRALINE_R0_2:
|
||||
case BOARD_REV_GSG_PRALINE_R0_3:
|
||||
return "GSG HackRF Pro R0";
|
||||
case BOARD_REV_GSG_PRALINE_R1_0:
|
||||
case BOARD_REV_GSG_PRALINE_R1_1:
|
||||
case BOARD_REV_GSG_PRALINE_R1_2:
|
||||
return "GSG HackRF Pro R1";
|
||||
case BOARD_REV_UNRECOGNIZED:
|
||||
return "Unrecognized";
|
||||
case BOARD_REV_UNDETECTED:
|
||||
return "Undetected";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_info(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
(void)argv;
|
||||
|
||||
if (argc > 0) {
|
||||
usage(chp, const_cast<char*>("info"));
|
||||
return;
|
||||
@@ -92,7 +147,40 @@ static void cmd_info(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
#ifdef VERSION_STRING
|
||||
chprintf(chp, "Mayhem Version: %s\r\n", VERSION_STRING);
|
||||
#endif
|
||||
chprintf(chp, "HackRF Board Rev: %s\r\n", hackrf_r9 ? "R9" : "R1-R8");
|
||||
|
||||
board_rev_t revision = detected_revision();
|
||||
const char* revision_string = get_board_revision_string(revision);
|
||||
chprintf(chp, "HackRF Board Rev: %s\r\n", revision_string);
|
||||
|
||||
// Determine device type string
|
||||
const char* device_str;
|
||||
#ifdef PRALINE
|
||||
device_str = "HackRF Pro";
|
||||
#else
|
||||
if (portapack::device_type == portapack::DEV_PORTARF) {
|
||||
device_str = "PortaRF";
|
||||
} else {
|
||||
device_str = "HackRF One";
|
||||
}
|
||||
#endif
|
||||
chprintf(chp, "Device: %s\r\n", device_str);
|
||||
|
||||
// Flash info: build-time allowed MB, runtime-detected limit, current firmware size
|
||||
// Use explicit uint32_t cast: FLASH_SIZE_LIMIT_MB may be a float (e.g. 3.5 for HPro)
|
||||
uint8_t flash_allowrun;
|
||||
#ifdef PRALINE
|
||||
flash_allowrun = 4; // HackRF Pro
|
||||
#else
|
||||
if (portapack::device_type == portapack::DeviceType::DEV_PORTAPACK) {
|
||||
flash_allowrun = 1; // PortaPack classic
|
||||
} else {
|
||||
flash_allowrun = FLASH_SIZE_MB; // PortaRF
|
||||
}
|
||||
#endif
|
||||
chprintf(chp, "Flash Allowed: %dMB\r\n", (uint32_t)FLASH_SIZE_MB);
|
||||
chprintf(chp, "Flash Runtime: %dMB\r\n", (uint32_t)flash_allowrun);
|
||||
chprintf(chp, "Flash Current: %dMB\r\n", (uint32_t)FLASH_SIZE_LIMIT_MB);
|
||||
|
||||
chprintf(chp, "Reference Source: %s\r\n", portapack::clock_manager.get_source().c_str());
|
||||
chprintf(chp, "Reference Freq: %s\r\n", portapack::clock_manager.get_freq().c_str());
|
||||
#ifdef __DATE__
|
||||
|
||||
@@ -26,9 +26,26 @@
|
||||
namespace tuning {
|
||||
namespace config {
|
||||
|
||||
// Forward declarations
|
||||
Config low_band(const rf::Frequency target_frequency);
|
||||
Config mid_band(const rf::Frequency target_frequency);
|
||||
Config high_band(const rf::Frequency target_frequency);
|
||||
|
||||
// Low band <2170 Mhz:
|
||||
constexpr rf::Frequency low_band_second_lo_frequency(const rf::Frequency target_frequency) {
|
||||
#ifdef PRALINE
|
||||
// Praline-specific formula for MAX2831 (2.3-2.6 GHz range)
|
||||
// Use a fixed second_lo that:
|
||||
// 1. Falls in MAX2831's sweet spot (2.3-2.6 GHz)
|
||||
// 2. Gives RFFC5072 a VCO frequency in its range (2700-5400 MHz)
|
||||
|
||||
// For most low-band frequencies, use 2500 MHz as second_lo
|
||||
// This gives RFFC5072 plenty of headroom
|
||||
(void)target_frequency; // Unused in fixed formula
|
||||
return 2500'000'000;
|
||||
#else
|
||||
return 2650'000'000 - (target_frequency / 7);
|
||||
#endif
|
||||
}
|
||||
|
||||
Config low_band(const rf::Frequency target_frequency) {
|
||||
@@ -40,20 +57,52 @@ Config low_band(const rf::Frequency target_frequency) {
|
||||
|
||||
// Mid band 2170-2740 Mhz:
|
||||
Config mid_band(const rf::Frequency target_frequency) {
|
||||
#ifdef PRALINE
|
||||
// For Praline with MAX2831 (2.3-2.6 GHz range)
|
||||
// Frequencies 2170-2300 MHz need upconversion since they're below MAX2831 minimum
|
||||
if (target_frequency < 2300'000'000) {
|
||||
// Treat as low band
|
||||
return low_band(target_frequency);
|
||||
}
|
||||
// Frequencies 2300-2600 MHz can go direct (no RFFC5072)
|
||||
else if (target_frequency <= 2600'000'000) {
|
||||
const rf::Frequency second_lo_frequency = target_frequency;
|
||||
const rf::Frequency first_lo_frequency = 0;
|
||||
const bool mixer_invert = false;
|
||||
return {first_lo_frequency, second_lo_frequency, rf::path::Band::Mid, mixer_invert};
|
||||
}
|
||||
// Frequencies 2600-2740 MHz need downconversion since they're above MAX2831 maximum
|
||||
else {
|
||||
// Treat as high band
|
||||
return high_band(target_frequency);
|
||||
}
|
||||
#else
|
||||
const rf::Frequency second_lo_frequency = target_frequency;
|
||||
const rf::Frequency first_lo_frequency = 0;
|
||||
const bool mixer_invert = false;
|
||||
return {first_lo_frequency, second_lo_frequency, rf::path::Band::Mid, mixer_invert};
|
||||
#endif
|
||||
}
|
||||
|
||||
// High band >2740 Mhz:
|
||||
constexpr rf::Frequency high_band_second_lo_frequency(const rf::Frequency target_frequency) {
|
||||
#ifdef PRALINE
|
||||
// Praline formula tuned for MAX2831 (2.3-2.6 GHz range)
|
||||
// Keep second_lo in MAX2831's range while allowing RFFC5072 to work
|
||||
if (target_frequency < 3600'000'000)
|
||||
return 2400'000'000 + ((target_frequency - 2740'000'000) / 4);
|
||||
else if (target_frequency < 5100'000'000)
|
||||
return 2500'000'000 + ((target_frequency - 3600'000'000) / 6);
|
||||
else
|
||||
return 2550'000'000 + ((target_frequency - 5100'000'000) / 10);
|
||||
#else
|
||||
if (target_frequency < 3600'000'000)
|
||||
return (2170'000'000 + (((target_frequency - 2740'000'000) * 57) / 86));
|
||||
else if (target_frequency < 5100'000'000)
|
||||
return (2350'000'000 + ((target_frequency - 3600'000'000) / 5));
|
||||
else
|
||||
return (2500'000'000 + ((target_frequency - 5100'000'000) / 9));
|
||||
#endif
|
||||
}
|
||||
|
||||
Config high_band(const rf::Frequency target_frequency) {
|
||||
|
||||
@@ -265,7 +265,7 @@ void GeoMap::map_read_line_bin(ui::Color* buffer, uint16_t pixels) {
|
||||
|
||||
void GeoMap::draw_markers(Painter& painter) {
|
||||
for (int i = 0; i < markerListLen; ++i) {
|
||||
draw_marker_item(painter, markerList[i], Color::blue(), Color::blue(), Color::magenta());
|
||||
draw_marker_item(painter, markerList[i], markerList[i].color, markerList[i].color, Color::black());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,7 +657,13 @@ void GeoMap::move(const float lon, const float lat) {
|
||||
} else {
|
||||
if (is_changed) {
|
||||
set_osm_max_zoom();
|
||||
redraw_map = true;
|
||||
double global_center_px = lon_to_pixel_x_tile(lon_, map_osm_real_zoom);
|
||||
double global_center_py = lat_to_pixel_y_tile(lat_, map_osm_real_zoom);
|
||||
// Redraw if viewport moved by at least 1 pixel (includes zoom level changes)
|
||||
if (abs(global_center_px - (r.width() / 2.0) - viewport_top_left_px) >= 1.0 ||
|
||||
abs(global_center_py - (r.height() / 2.0) - viewport_top_left_py) >= 1.0) {
|
||||
redraw_map = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -820,7 +826,7 @@ void GeoMap::update_my_position(float lat, float lon, int32_t altitude) {
|
||||
my_pos.lat = lat;
|
||||
my_pos.lon = lon;
|
||||
my_altitude = altitude;
|
||||
redraw_map = is_changed;
|
||||
redraw_map |= is_changed;
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
||||
@@ -62,13 +62,14 @@ struct GeoMarker {
|
||||
float lon{0};
|
||||
uint16_t angle{0};
|
||||
std::string tag{""};
|
||||
Color color{Color::blue()};
|
||||
|
||||
GeoMarker& operator=(GeoMarker& rhs) {
|
||||
GeoMarker& operator=(const GeoMarker& rhs) {
|
||||
lat = rhs.lat;
|
||||
lon = rhs.lon;
|
||||
angle = rhs.angle;
|
||||
tag = rhs.tag;
|
||||
|
||||
color = rhs.color;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -26,7 +26,10 @@
|
||||
#include "string_format.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_freqman.hpp"
|
||||
|
||||
#ifndef PRALINE
|
||||
#include "audio.hpp"
|
||||
#endif
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
@@ -592,6 +595,10 @@ AudioVolumeField::AudioVolumeField(
|
||||
/* fill char */ ' '} {
|
||||
set_value(receiver_model.normalized_headphone_volume());
|
||||
|
||||
#ifdef PRALINE
|
||||
on_change = [](int32_t v) {
|
||||
receiver_model.set_normalized_headphone_volume(v);
|
||||
#else
|
||||
on_change = [](int32_t vol) {
|
||||
// don't call receiver model, because this widget shuld be able to handle volume settinsg from any app, regardless of the receiver model's enables state. like the tx apps should be able to set volume too.
|
||||
// this is identical to the receiver model's method
|
||||
@@ -599,6 +606,7 @@ AudioVolumeField::AudioVolumeField(
|
||||
auto new_volume = volume_t::decibel(v - 99) + audio::headphone::volume_range().max;
|
||||
persistent_memory::set_headphone_volume(new_volume);
|
||||
audio::headphone::set_volume(new_volume);
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -607,7 +607,14 @@ bool InformationView::firmware_checksum_error() {
|
||||
|
||||
// only checking firmware checksum once per boot
|
||||
if (!fw_checksum_checked) {
|
||||
#ifdef PRALINE
|
||||
fw_checksum_error = (simple_checksum(FLASH_STARTING_ADDRESS, 4 * 1024 * 1024) != FLASH_EXPECTED_CHECKSUM);
|
||||
// TODO: This is a minimal workaround to fix the FLASH ERR checksum, bc GSG's cmake doesn't define the PortaRF board,
|
||||
// so if we do, we need to patch many codes. so we can't define the PortaRF board currently in our cmake.
|
||||
// discuss needed to find a better way but currently we need CI works and make hackrf pro works as much as possible.
|
||||
#else
|
||||
fw_checksum_error = (simple_checksum(FLASH_STARTING_ADDRESS, FLASH_SIZE_LIMIT_MB * 1024 * 1024) != FLASH_EXPECTED_CHECKSUM);
|
||||
#endif
|
||||
}
|
||||
return fw_checksum_error;
|
||||
}
|
||||
@@ -969,6 +976,8 @@ SystemView::SystemView(
|
||||
|
||||
navigation_view.push<SystemMenuView>();
|
||||
|
||||
add_child(¬ification_view);
|
||||
|
||||
if (pmem::config_splash()) {
|
||||
navigation_view.push<SplashScreenView>();
|
||||
}
|
||||
@@ -1054,17 +1063,56 @@ SplashScreenView::SplashScreenView(NavigationView& nav)
|
||||
};
|
||||
}
|
||||
|
||||
void SplashScreenView::get_random_splash_file(std::filesystem::path& path) {
|
||||
path = u"";
|
||||
|
||||
srand(LPC_RTC->CTIME0);
|
||||
|
||||
DIR dir;
|
||||
FILINFO fno;
|
||||
int32_t valid_count = 0;
|
||||
|
||||
// Open directory
|
||||
if (f_opendir(&dir, (const TCHAR*)splash_dir.c_str()) == FR_OK) {
|
||||
while (f_readdir(&dir, &fno) == FR_OK && fno.fname[0] != 0) {
|
||||
// Skip directories
|
||||
if (fno.fattrib & AM_DIR) continue;
|
||||
int len = 0;
|
||||
while (fno.fname[len]) len++; // Get length
|
||||
if (len >= 4) {
|
||||
const TCHAR* ext = &fno.fname[len - 4];
|
||||
// Check extension case-insensitively
|
||||
if (ext[0] == '.' &&
|
||||
(ext[1] == 'B' || ext[1] == 'b') &&
|
||||
(ext[2] == 'M' || ext[2] == 'm') &&
|
||||
(ext[3] == 'P' || ext[3] == 'p')) {
|
||||
valid_count++;
|
||||
// Reservoir Sampling:
|
||||
if ((rand() % valid_count) == 0) {
|
||||
path = splash_dir / fno.fname;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
f_closedir(&dir);
|
||||
}
|
||||
}
|
||||
|
||||
void SplashScreenView::paint(Painter&) {
|
||||
constexpr const uint8_t zoom = 3;
|
||||
set_clean();
|
||||
// if (!bmp_view.load_bmp(splash_dot_bmp)) { //--too slow drawing, bc of the more bmp format support, and up-> down drawing
|
||||
if (!portapack::display.draw_bmp_from_sdcard_file({0, 0}, splash_dot_bmp))
|
||||
// ^ try draw bmp file from sdcard at (0,0), and the (0,0) already bypassed the status bar, so actual pos is (0, STATUS_BAR_HEIGHT)
|
||||
portapack::display.draw_bitmap({screen_width / 2 - ((bitmap_titlebar_image.size.width() * zoom) / 2),
|
||||
screen_height / 2},
|
||||
bitmap_titlebar_image.size,
|
||||
bitmap_titlebar_image.data,
|
||||
Theme::getInstance()->bg_darkest->foreground,
|
||||
Theme::getInstance()->bg_darkest->background, zoom);
|
||||
if (portapack::display.draw_bmp_from_sdcard_file({0, 0}, splash_dot_bmp)) return;
|
||||
// ^ try draw bmp file from sdcard at (0,0), and the (0,0) already bypassed the status bar, so actual pos is (0, STATUS_BAR_HEIGHT)
|
||||
|
||||
std::filesystem::path path{};
|
||||
get_random_splash_file(path);
|
||||
if (portapack::display.draw_bmp_from_sdcard_file({0, 0}, path)) return;
|
||||
portapack::display.draw_bitmap({screen_width / 2 - ((bitmap_titlebar_image.size.width() * 3) / 2),
|
||||
screen_height / 2},
|
||||
bitmap_titlebar_image.size,
|
||||
bitmap_titlebar_image.data,
|
||||
Theme::getInstance()->bg_darkest->foreground,
|
||||
Theme::getInstance()->bg_darkest->background, 3);
|
||||
// ^ draw BMP HEX arr in firmware, note that the BMP HEX arr only cover the image part (instead of fill the screen with background, this position is located it in the center)
|
||||
}
|
||||
|
||||
@@ -1082,7 +1130,6 @@ bool SplashScreenView::on_touch(const TouchEvent event) {
|
||||
case TouchEvent::Type::Start:
|
||||
handle_pop();
|
||||
return false;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "ui_audio.hpp"
|
||||
#include "ui_sd_card_status_view.hpp"
|
||||
#include "ui_dfu_menu.hpp"
|
||||
|
||||
#include "ui_notifications.hpp"
|
||||
#include "bitmap.hpp"
|
||||
#include "ui_bmpview.hpp"
|
||||
#include "ff.h"
|
||||
@@ -366,7 +366,7 @@ class SplashScreenView : public View {
|
||||
Button button_done{
|
||||
{screen_width, 0, 1, 1},
|
||||
""};
|
||||
// BMPViewer bmp_view{ {0, 0, screen_width, screen_height - 16}};
|
||||
void get_random_splash_file(std::filesystem::path& path);
|
||||
};
|
||||
|
||||
class ReceiversMenuView : public BtnGridView {
|
||||
@@ -446,11 +446,12 @@ class SystemView : public View {
|
||||
private:
|
||||
uint8_t overlay_active{0};
|
||||
|
||||
NavigationView navigation_view{};
|
||||
SystemStatusView status_view{navigation_view};
|
||||
InformationView info_view{navigation_view};
|
||||
NotificationView notification_view{navigation_view};
|
||||
DfuMenu overlay{navigation_view};
|
||||
DfuMenu2 overlay2{navigation_view};
|
||||
NavigationView navigation_view{};
|
||||
Context& context_;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "ui_notifications.hpp"
|
||||
|
||||
#include "ui_navigation.hpp"
|
||||
|
||||
extern ui::SystemView* system_view_ptr;
|
||||
|
||||
namespace ui {
|
||||
|
||||
NotificationEntryView::NotificationEntryView(const NotificationEntry& entry, NotificationView* notifhandler)
|
||||
: entry_(entry), notifhandler_(notifhandler) {
|
||||
add_children({&background, &border, &title_text, &message_text, &close_button});
|
||||
border.set_outline(true);
|
||||
if (entry_.icon != NOTIF_ICON_NONE) {
|
||||
add_child(&icon_image);
|
||||
icon_image.set_parent_rect({UI_POS_X(0) + 2, UI_POS_Y(1), UI_POS_WIDTH(2), UI_POS_HEIGHT(1)});
|
||||
message_text.set_parent_rect({UI_POS_X(2) + 2, UI_POS_Y(1), UI_POS_WIDTH_REMAINING(6) - 2, UI_POS_HEIGHT(2)});
|
||||
if (entry_.icon == NOTIF_ICON_MESSAGE) {
|
||||
icon_image.set_bitmap(&bitmap_icon_pocsag);
|
||||
}
|
||||
|
||||
} else {
|
||||
message_text.set_parent_rect({UI_POS_X(1), UI_POS_Y(1), UI_POS_WIDTH_REMAINING(5) - 1, UI_POS_HEIGHT(2)});
|
||||
}
|
||||
title_text.set_style(Theme::getInstance()->bg_dark);
|
||||
title_text.set(entry_.title);
|
||||
message_text.set_style(Theme::getInstance()->bg_darkest);
|
||||
message_text.set(entry_.message);
|
||||
|
||||
close_button.on_select = [this](Button&) {
|
||||
if (notifhandler_) {
|
||||
notifhandler_->remove_notification(entry_.id);
|
||||
}
|
||||
};
|
||||
|
||||
message_text.on_select = [this](Text&) {
|
||||
if (!entry_.source_app.empty() && notifhandler_) {
|
||||
notifhandler_->open_notification(entry_.source_app);
|
||||
// notifhandler_->remove_notification(entry_.id);
|
||||
}
|
||||
};
|
||||
title_text.on_select = message_text.on_select;
|
||||
}
|
||||
|
||||
NotificationView::NotificationView(NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
this->on_tick_second();
|
||||
};
|
||||
}
|
||||
|
||||
NotificationView::~NotificationView() {
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
}
|
||||
|
||||
void NotificationView::on_tick_second() {
|
||||
bool changed = false;
|
||||
for (size_t i = 0; i < notification_views_.size();) {
|
||||
if (notification_views_[i]->entry()->increase_time(1000)) {
|
||||
notification_views_.erase(notification_views_.begin() + i);
|
||||
changed = true;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
rearrange_notifications();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationView::rearrange_notifications() {
|
||||
size_t count = children().size();
|
||||
while (children().size() > 0) {
|
||||
remove_child(children().back());
|
||||
}
|
||||
|
||||
const int entry_height = UI_POS_HEIGHT(3) + 1;
|
||||
int index = 0;
|
||||
|
||||
for (auto& view_ptr : notification_views_) {
|
||||
view_ptr->set_parent_rect({UI_POS_X(0),
|
||||
(Coord)(UI_POS_Y(0) + (index * entry_height)),
|
||||
UI_POS_MAXWIDTH,
|
||||
entry_height});
|
||||
add_child(view_ptr.get());
|
||||
index++;
|
||||
}
|
||||
|
||||
set_parent_rect({UI_POS_X(0), UI_POS_Y(0), UI_POS_MAXWIDTH, (Coord)(notification_views_.size() * entry_height)});
|
||||
set_dirty();
|
||||
if (count != children().size()) {
|
||||
// refresh screen!!!
|
||||
system_view_ptr->set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationView::add_notification(NotificationEntry& entry) {
|
||||
if (notification_views_.size() >= max_notifications) {
|
||||
notification_views_.erase(notification_views_.begin());
|
||||
}
|
||||
|
||||
entry.id = ++curr_not_id;
|
||||
notification_views_.push_back(std::make_unique<NotificationEntryView>(entry, this));
|
||||
|
||||
rearrange_notifications();
|
||||
}
|
||||
|
||||
void NotificationView::remove_notification(uint16_t id) {
|
||||
bool found = false;
|
||||
size_t found_index = 0;
|
||||
|
||||
for (size_t i = 0; i < notification_views_.size(); i++) {
|
||||
if (notification_views_[i]->id() == id) {
|
||||
found = true;
|
||||
found_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
notification_views_.erase(notification_views_.begin() + found_index);
|
||||
rearrange_notifications();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationView::open_notification(std::string app_name) {
|
||||
if (app_name.empty()) return;
|
||||
nav_.StartAppByName(app_name.c_str());
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "ui.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "signal.hpp"
|
||||
#include "rtc_time.hpp"
|
||||
#include "event_m0.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class NotificationView;
|
||||
class NavigationView;
|
||||
|
||||
enum notification_icon_t : uint8_t {
|
||||
NOTIF_ICON_NONE = 0,
|
||||
NOTIF_ICON_MESSAGE
|
||||
};
|
||||
|
||||
class NotificationEntry {
|
||||
public:
|
||||
std::string source_app{};
|
||||
std::string title{};
|
||||
std::string message{};
|
||||
notification_icon_t icon = NOTIF_ICON_NONE;
|
||||
uint16_t timeout = 10000;
|
||||
uint16_t id = 0;
|
||||
|
||||
NotificationEntry() = default;
|
||||
NotificationEntry(const std::string& source_app, const std::string& title, const std::string& message, notification_icon_t icon = NOTIF_ICON_NONE, uint16_t timeout = 10000, uint16_t id = 0)
|
||||
: source_app(source_app), title(title), message(message), icon(icon), timeout(timeout), id(id) {}
|
||||
|
||||
static NotificationEntry build(const std::string& source_app, const std::string& title, const std::string& message, notification_icon_t icon = NOTIF_ICON_NONE, uint16_t timeout = 10000) {
|
||||
return NotificationEntry{source_app, title, message, icon, timeout, 0};
|
||||
}
|
||||
|
||||
bool increase_time(uint16_t delta) {
|
||||
current_time += delta;
|
||||
return (current_time >= timeout);
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t current_time = 0;
|
||||
};
|
||||
|
||||
class NotificationEntryView : public View {
|
||||
public:
|
||||
NotificationEntryView(const NotificationEntry& entry, NotificationView* notifhandler);
|
||||
|
||||
NotificationEntryView(const NotificationEntryView&) = delete;
|
||||
NotificationEntryView& operator=(const NotificationEntryView&) = delete;
|
||||
|
||||
ui::Rectangle background{{1, 1, UI_POS_MAXWIDTH - 2, UI_POS_HEIGHT(3) - 2}, Theme::getInstance()->bg_darkest->background};
|
||||
ui::Rectangle border{{0, 0, UI_POS_MAXWIDTH, UI_POS_HEIGHT(3) + 1}, Theme::getInstance()->bg_light->background};
|
||||
ui::Text title_text{{UI_POS_X(0) + 1, UI_POS_Y(0) + 1, UI_POS_WIDTH_REMAINING(4) - 3, UI_POS_HEIGHT(1)}, ""};
|
||||
ui::Text message_text{{UI_POS_X(1), UI_POS_Y(1), UI_POS_WIDTH_REMAINING(5) - 1, UI_POS_HEIGHT(2)}, ""};
|
||||
ui::Image icon_image{}; // 16*16 bitmap
|
||||
ui::Button close_button{{UI_POS_X_RIGHT(4) - 2, UI_POS_Y(0) + 1, UI_POS_WIDTH(4), UI_POS_HEIGHT(2)}, "X"};
|
||||
|
||||
uint16_t id() const { return entry_.id; }
|
||||
NotificationEntry* entry() { return &entry_; }
|
||||
|
||||
private:
|
||||
NotificationEntry entry_;
|
||||
NotificationView* notifhandler_;
|
||||
};
|
||||
|
||||
class NotificationView : public View {
|
||||
public:
|
||||
NotificationView(NavigationView& nav);
|
||||
~NotificationView();
|
||||
|
||||
void add_notification(NotificationEntry& entry);
|
||||
void remove_notification(uint16_t id);
|
||||
void open_notification(std::string app_name);
|
||||
|
||||
private:
|
||||
void on_tick_second();
|
||||
void rearrange_notifications();
|
||||
|
||||
NavigationView& nav_;
|
||||
|
||||
// Changed to unique_ptr to handle non-copyable Views safely
|
||||
std::vector<std::unique_ptr<NotificationEntryView>> notification_views_{};
|
||||
|
||||
SignalToken signal_token_tick_second{};
|
||||
|
||||
uint16_t curr_not_id = 0;
|
||||
constexpr static uint8_t max_notifications = 4;
|
||||
|
||||
MessageHandlerRegistration message_handler_notifs{
|
||||
Message::ID::NotificationData, [this](Message* const p) {
|
||||
const auto message = static_cast<const NotificationDataMessage*>(p);
|
||||
NotificationEntry entry = NotificationEntry::build(message->source_app, message->title, message->message, static_cast<notification_icon_t>(message->icon), message->timeout);
|
||||
this->add_notification(entry);
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user