From b99d063bd89cd0bb479553817f9016ae15cb8012 Mon Sep 17 00:00:00 2001 From: crosstyan Date: Thu, 15 May 2025 11:20:50 +0800 Subject: [PATCH] Add .gitignore file and refactor llcc68 component - Added a comprehensive .gitignore file to exclude unnecessary files and directories for various platforms and tools. - Removed the llcc68.cpp source file as part of the refactoring process. - Updated llcc68.hpp to replace the `init_exti` function declaration with inline interrupt configuration logic. - Changed `EXTI_PIN` to `EXTI_PINS` for clarity and consistency. - Refactored the handling of CAD parameters and improved type safety by using `enum class` for `CAD_EXIT_MODE` and `CAD_SYMB`. --- .gitignore | 1054 ++++++++++++++++++++ CMakeLists.txt | 1 - inc/llcc68.hpp | 124 +-- inc/radiolib_definitions.hpp | 88 +- inc/template/app_const_llcc68_template.hpp | 2 +- src/llcc68.cpp | 42 - 6 files changed, 1163 insertions(+), 148 deletions(-) create mode 100644 .gitignore delete mode 100644 src/llcc68.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbae5f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,1054 @@ +##### Windows +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +##### Linux +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +##### MacOS +# General +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +##### Android +# Built application files +*.apk +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ +# Uncomment the following line in case you need and you don't have the release build type files in your app +# release/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +##### Backup +*.bak +*.gho +*.ori +*.orig +*.tmp + +##### GPG +secring.* + +##### Dropbox +# Dropbox settings and caches +.dropbox +.dropbox.attr +.dropbox.cache + +##### SynopsysVCS +# Waveform formats +*.vcd +*.vpd +*.evcd +*.fsdb + +# Default name of the simulation executable. A different name can be +# specified with this switch (the associated daidir database name is +# also taken from here): -o / +simv + +# Generated for Verilog and VHDL top configs +simv.daidir/ +simv.db.dir/ + +# Infrastructure necessary to co-simulate SystemC models with +# Verilog/VHDL models. An alternate directory may be specified with this +# switch: -Mdir= +csrc/ + +# Log file - the following switch allows to specify the file that will be +# used to write all messages from simulation: -l +*.log + +# Coverage results (generated with urg) and database location. The +# following switch can also be used: urg -dir .vdb +simv.vdb/ +urgReport/ + +# DVE and UCLI related files. +DVEfiles/ +ucli.key + +# When the design is elaborated for DirectC, the following file is created +# with declarations for C/C++ functions. +vc_hdrs.h + +##### SVN +.svn/ + +##### Mercurial +.hg/ +.hgignore +.hgsigs +.hgsub +.hgsubstate +.hgtags + +##### Bazaar +.bzr/ +.bzrignore + +##### CVS +/CVS/* +**/CVS/* +.cvsignore +*/.cvsignore + +##### TortoiseGit +# Project-level settings +/.tgitconfig + +##### PuTTY +# Private key +*.ppk + +##### Vim +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +##### Emacs +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + +##### SublimeText +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json +sftp-config-alt*.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +##### Notepad++ +# Notepad++ backups # +*.bak + +##### TextMate +*.tmproj +*.tmproject +tmtags + +##### VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +##### NetBeans +**/nbproject/private/ +**/nbproject/Makefile-*.mk +**/nbproject/Package-*.bash +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ + +##### JetBrains +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +##### Eclipse +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +##### Qt +# C++ objects and libs +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.so.* +*.dll +*.dylib + +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.cpp +moc_*.h +qrc_*.cpp +ui_*.h +*.qmlc +*.jsc +Makefile* +*build-* +*.qm +*.prl + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* + +# QtCreator 4.8< compilation database +compile_commands.json + +# QtCreator local machine specific files for imported projects +*creator.user* + +##### VisualStudio +##### VisualStudio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +##### Gradle +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +##### CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +##### C++ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# C/C++ binary extension file +*.bin + +##### C +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# Raspberry Pi Pico Object file +*.uf2 +# Raspberry Pi Pico disassembler file +*.dis + +# CMake +cmake-* +build +.cache +.DS_Store +managed_components + +nvs.csv diff --git a/CMakeLists.txt b/CMakeLists.txt index 88c537a..9b1b6b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ idf_component_register( SRCS - src/llcc68.cpp src/hal_spi.cpp INCLUDE_DIRS inc/ diff --git a/inc/llcc68.hpp b/inc/llcc68.hpp index 163d2c9..6d986cf 100644 --- a/inc/llcc68.hpp +++ b/inc/llcc68.hpp @@ -121,8 +121,6 @@ namespace details { extern uint32_t __tcxo_delay__; } -void init_exti(); - constexpr auto delay_ms = app::utils::delay_ms; /*! @@ -174,7 +172,7 @@ write_register(const uint16_t addr, std::span data) { return spi::write_register(addr, data); } -Result inline write_buffer(std::span data, const uint8_t offset = 0x00) { +Result inline write_buffer(std::span data, const uint8_t offset = DEFAULT_TX_BUFFER_ADDRESS) { return spi::write_buffer(offset, data); } @@ -447,8 +445,7 @@ set_dio2_as_rf_switch(const bool en) { * \brief set packet type and do the calibration */ inline Result config_packet_type(const parameters_t ¶ms) { - auto res = set_buffer_base_address(); - APP_RADIO_RETURN_ERR(res); + Result res; constexpr auto mod = RADIOLIB_SX126X_PACKET_TYPE_LORA; uint8_t data[7]; data[0] = mod; @@ -584,13 +581,21 @@ inline Result rx(const uint32_t timeout = RADIOLIB_SX126X_RX_TIME return spi::write_stream(RADIOLIB_SX126X_CMD_SET_RX, data); } -enum CAD_EXIT_MODE : uint8_t { +enum class CAD_EXIT_MODE : uint8_t { CAD_ONLY = 0x00, CAD_RX = 0x01, }; +enum class CAD_SYMB : uint8_t { + CAD_ON_1_SYMB = 0x00, + CAD_ON_2_SYMB = 0x01, + CAD_ON_4_SYMB = 0x02, + CAD_ON_8_SYMB = 0x03, + CAD_ON_16_SYMB = 0x04, +}; + struct cad_params_t { - uint8_t symbol_num; + CAD_SYMB symbol_num; uint8_t det_peak; uint8_t det_min; CAD_EXIT_MODE exit_mode; @@ -603,42 +608,30 @@ struct cad_params_t { uint32_t timeout; }; -/** - * \brief Calculate default CAD parameters for a given spreading factor - * \param sf Spreading factor - * \param params CAD parameters - * \note will mutate `params.symbol_num`, `params.det_peak`, and `params.det_min` - * \return true if the sf is valid and the parameters are set, false otherwise - */ -inline bool calculate_default_cad_params(const uint8_t sf, cad_params_t ¶ms) { - // Parameters `cadDetPeak` and `cadDetMin` define the sensitivity of the LoRa - // modem when trying to correlate to actual LoRa preamble symbols. These - // two settings depend on the LoRa spreading factor and Bandwidth, but - // also depend on the number of symbols used to validate or not the detection. - // - // Choosing the right value is not easy and the values selected must be - // carefully tested to ensure a good detection at sensitivity level, and - // also to limit the number of false detections. Application note AN1200.48 - // provides guidance for the selection of these parameters. +constexpr std::tuple sf_det_peak_map[6] = { + {7, 22}, + {8, 22}, + {9, 24}, + {10, 25}, + {11, 26}, + {12, 30}}; - // default CAD parameters are shown in Semtech AN1200.48, page 41. - const std::tuple det_peak_map[6] = {{7, 22}, {8, 22}, {9, 24}, {10, 25}, {11, 26}, {12, 30}}; - std::optional det_peak; - for (const auto &[r_sf, r_det_peak] : det_peak_map) { +// Parameters `cadDetPeak` and `cadDetMin` define the sensitivity of the LoRa +// modem when trying to correlate to actual LoRa preamble symbols. These +// two settings depend on the LoRa spreading factor and Bandwidth, but +// also depend on the number of symbols used to validate or not the detection. +// +// Choosing the right value is not easy and the values selected must be +// carefully tested to ensure a good detection at sensitivity level, and +// also to limit the number of false detections. Application note AN1200.48 +// provides guidance for the selection of these parameters. +constexpr inline std::optional get_det_peak(const uint8_t sf) { + for (const auto &[r_sf, r_det_peak] : sf_det_peak_map) { if (r_sf == sf) { - det_peak = r_det_peak; - break; + return r_det_peak; } } - if (not det_peak) { - return false; - } - - // CAD parameters aren't available for SF-6. Just to be safe. - params.symbol_num = RADIOLIB_SX126X_CAD_ON_2_SYMB; - params.det_peak = det_peak.value(); - params.det_min = RADIOLIB_SX126X_CAD_PARAM_DET_MIN; - return true; + return std::nullopt; } /** @@ -647,10 +640,10 @@ inline bool calculate_default_cad_params(const uint8_t sf, cad_params_t ¶ms) inline Result set_cad_params(const cad_params_t ¶ms) { uint8_t data[7]; - data[0] = params.symbol_num; + data[0] = static_cast(params.symbol_num); data[1] = params.det_peak; data[2] = params.det_min; - data[3] = params.exit_mode; + data[3] = static_cast(params.exit_mode); data[4] = static_cast((params.timeout >> 16) & 0xFF); data[5] = static_cast((params.timeout >> 8) & 0xFF); data[6] = static_cast(params.timeout & 0xFF); @@ -950,7 +943,8 @@ struct read_result_t { * \brief user should call this function after reading data (since it will override the internal buffer) */ static Result post_procedure() { - auto res = set_buffer_base_address(); + Result res; + res = set_buffer_base_address(); APP_RADIO_RETURN_ERR(res); res = clear_irq_status(); APP_RADIO_RETURN_ERR(res); @@ -991,8 +985,10 @@ read_data_internal() { * is incremented starting from the previous position. */ const auto [sz, ptr] = std::move(*tuple_); - ESP_LOGD(TAG, "sz=%d, ptr=0x%02x", sz, ptr); - auto res = hal::spi::read_buffer(ptr - sz, sz); + // the rx pointer would become 0x80 at first, so we need to adapt that behavior + const auto r_ptr = ptr - sz < DEFAULT_RX_BUFFER_ADDRESS ? ptr : ptr - sz; + + auto res = hal::spi::read_buffer(r_ptr, sz); APP_RADIO_RETURN_ERR(res); return read_result_t{irq, *res}; } @@ -1024,22 +1020,10 @@ inline Result kick_inf_rx() { Result res; res = standby(); - - // res = set_packet_type(PacketType::LORA); - // APP_RADIO_RETURN_ERR_CTX(res, "failed to set packet type"); - - res = set_frequency(DEFAULT_FREQUENCY, false); - APP_RADIO_RETURN_ERR_CTX(res, "failed to set frequency"); - + APP_RADIO_RETURN_ERR_CTX(res, "failed to standby"); res = set_buffer_base_address(); APP_RADIO_RETURN_ERR_CTX(res, "failed to set buffer base address"); - res = set_modulation_params(DEFAULT_SF, DEFAULT_BW, DEFAULT_CR, DEFAULT_LDR_OPTIMIZE); - APP_RADIO_RETURN_ERR_CTX(res, "failed to set modulation params"); - - res = set_packet_params(DEFAULT_PREAMBLE_LEN, 0xff, DEFAULT_CRC_TYPE, DEFAULT_HEADER_TYPE); - APP_RADIO_RETURN_ERR_CTX(res, "failed to set packet params"); - constexpr auto irq_mask = RADIOLIB_SX126X_IRQ_RX_DEFAULT; constexpr auto irq_params = irq_params_t{ irq_mask, @@ -1047,6 +1031,7 @@ kick_inf_rx() { DIO2_PIN == NC_PIN ? RADIOLIB_SX126X_IRQ_NONE : irq_mask, DIO3_PIN == NC_PIN ? RADIOLIB_SX126X_IRQ_NONE : irq_mask, }; + res = set_dio_irq_params(irq_params); APP_RADIO_RETURN_ERR_CTX(res, "failed to set dio irq params"); res = clear_irq_status(); @@ -1148,7 +1133,7 @@ async_transmit(const uint8_t *data, const size_t len, }; res = set_dio_irq_params(irq_params); APP_RADIO_RETURN_ERR_CTX(res, "failed to set dio irq params"); - clear_irq_status(); + clear_irq_status(irq_mask); APP_RADIO_RETURN_ERR_CTX(res, "failed to clear irq status"); res = tx(); @@ -1172,11 +1157,30 @@ async_transmit(const std::span data, } -static constexpr auto init_pins = [] { +static constexpr auto init_pins = [](void (*isr)(void *), void *arg) { if (RST_PIN != GPIO_NUM_NC) { gpio::set_mode(RST_PIN, gpio::Mode::OUTPUT); } - init_exti(); + uint64_t pin_bit_mask = 0; + for (const auto pin : EXTI_PINS) { + pin_bit_mask |= (1ULL << pin); + } + gpio_config_t io_conf = { + .pin_bit_mask = pin_bit_mask, + .mode = GPIO_MODE_INPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, + .intr_type = GPIO_INTR_POSEDGE, + }; + // https://github.com/espressif/esp-idf/blob/v5.3.2/examples/peripherals/gpio/generic_gpio/main/gpio_example_main.c + ESP_ERROR_CHECK(gpio_config(&io_conf)); + gpio_install_isr_service(ESP_INTR_FLAG_IRAM); + for (const auto pin : EXTI_PINS) { + if (pin == NC_PIN) { + continue; + } + gpio_isr_handler_add(pin, isr, arg); + } }; static constexpr auto begin = [](const parameters_t ¶ms) -> Result { diff --git a/inc/radiolib_definitions.hpp b/inc/radiolib_definitions.hpp index dc2e63a..6ee5db8 100644 --- a/inc/radiolib_definitions.hpp +++ b/inc/radiolib_definitions.hpp @@ -145,68 +145,68 @@ constexpr uint16_t RADIOLIB_SX126X_REG_PATCH_MEMORY_BASE = 0x8000; // SX126X SPI command variables // RADIOLIB_SX126X_CMD_SET_SLEEP MSB LSB DESCRIPTION -#define RADIOLIB_SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default) -#define RADIOLIB_SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained -#define RADIOLIB_SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled -#define RADIOLIB_SX126X_SLEEP_RTC_ON 0b00000001 // 0 0 enabled +constexpr uint8_t RADIOLIB_SX126X_SLEEP_START_COLD = 0b00000000; // 2 2 sleep mode: cold start, configuration is lost (default) +constexpr uint8_t RADIOLIB_SX126X_SLEEP_START_WARM = 0b00000100; // 2 2 warm start, configuration is retained +constexpr uint8_t RADIOLIB_SX126X_SLEEP_RTC_OFF = 0b00000000; // 0 0 wake on RTC timeout: disabled +constexpr uint8_t RADIOLIB_SX126X_SLEEP_RTC_ON = 0b00000001; // 0 0 enabled // RADIOLIB_SX126X_CMD_SET_STANDBY -#define RADIOLIB_SX126X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator -#define RADIOLIB_SX126X_STANDBY_XOSC 0x01 // 7 0 32 MHz crystal oscillator +constexpr uint8_t RADIOLIB_SX126X_STANDBY_RC = 0x00; // 7 0 standby mode: 13 MHz RC oscillator +constexpr uint8_t RADIOLIB_SX126X_STANDBY_XOSC = 0x01; // 7 0 32 MHz crystal oscillator // RADIOLIB_SX126X_CMD_SET_RX -#define RADIOLIB_SX126X_RX_TIMEOUT_NONE 0x000000 // 23 0 Rx timeout duration: no timeout (Rx single mode) -#define RADIOLIB_SX126X_RX_TIMEOUT_INF 0xFFFFFF // 23 0 infinite (Rx continuous mode) +constexpr uint32_t RADIOLIB_SX126X_RX_TIMEOUT_NONE = 0x000000; // 23 0 Rx timeout duration: no timeout (Rx single mode) +constexpr uint32_t RADIOLIB_SX126X_RX_TIMEOUT_INF = 0xFFFFFF; // 23 0 infinite (Rx continuous mode) // RADIOLIB_SX126X_CMD_SET_TX -#define RADIOLIB_SX126X_TX_TIMEOUT_NONE 0x000000 // 23 0 Tx timeout duration: no timeout (Tx single mode) +constexpr uint32_t RADIOLIB_SX126X_TX_TIMEOUT_NONE = 0x000000; // 23 0 Tx timeout duration: no timeout (Tx single mode) // RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE -#define RADIOLIB_SX126X_STOP_ON_PREAMBLE_OFF 0x00 // 7 0 stop timer on: sync word or header (default) -#define RADIOLIB_SX126X_STOP_ON_PREAMBLE_ON 0x01 // 7 0 preamble detection +constexpr uint8_t RADIOLIB_SX126X_STOP_ON_PREAMBLE_OFF = 0x00; // 7 0 stop timer on: sync word or header (default) +constexpr uint8_t RADIOLIB_SX126X_STOP_ON_PREAMBLE_ON = 0x01; // 7 0 preamble detection // RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE -#define RADIOLIB_SX126X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default) -#define RADIOLIB_SX126X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC +constexpr uint8_t RADIOLIB_SX126X_REGULATOR_LDO = 0x00; // 7 0 set regulator mode: LDO (default) +constexpr uint8_t RADIOLIB_SX126X_REGULATOR_DC_DC = 0x01; // 7 0 DC-DC // RADIOLIB_SX126X_CMD_CALIBRATE -#define RADIOLIB_SX126X_CALIBRATE_IMAGE_OFF 0b00000000 // 6 6 image calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_IMAGE_ON 0b01000000 // 6 6 enabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_OFF 0b00000000 // 5 5 ADC bulk P calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_ON 0b00100000 // 5 5 enabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_OFF 0b00000000 // 4 4 ADC bulk N calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_ON 0b00010000 // 4 4 enabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_OFF 0b00000000 // 3 3 ADC pulse calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_ON 0b00001000 // 3 3 enabled -#define RADIOLIB_SX126X_CALIBRATE_PLL_OFF 0b00000000 // 2 2 PLL calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_PLL_ON 0b00000100 // 2 2 enabled -#define RADIOLIB_SX126X_CALIBRATE_RC13M_OFF 0b00000000 // 1 1 13 MHz RC osc. calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_RC13M_ON 0b00000010 // 1 1 enabled -#define RADIOLIB_SX126X_CALIBRATE_RC64K_OFF 0b00000000 // 0 0 64 kHz RC osc. calibration: disabled -#define RADIOLIB_SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled -#define RADIOLIB_SX126X_CALIBRATE_ALL 0b01111111 // 6 0 calibrate all blocks +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_IMAGE_OFF = 0b00000000; // 6 6 image calibration: disabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_IMAGE_ON = 0b01000000; // 6 6 enabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_OFF = 0b00000000; // 5 5 ADC bulk P calibration: disabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_ON = 0b00100000; // 5 5 enabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_OFF = 0b00000000; // 4 4 ADC bulk N calibration: disabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_ON = 0b00010000; // 4 4 enabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_OFF = 0b00000000; // 3 3 ADC pulse calibration: disabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_ON = 0b00001000; // 3 3 enabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_PLL_OFF = 0b00000000; // 2 2 PLL calibration: disabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_PLL_ON = 0b00000100; // 2 2 enabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_RC13M_OFF = 0b00000000; // 1 1 13 MHz RC osc. calibration: disabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_RC13M_ON = 0b00000010; // 1 1 enabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_RC64K_OFF = 0b00000000; // 0 0 64 kHz RC osc. calibration: disabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_RC64K_ON = 0b00000001; // 0 0 enabled +constexpr uint8_t RADIOLIB_SX126X_CALIBRATE_ALL = 0b01111111; // 6 0 calibrate all blocks // RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE -#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 0x6B -#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 0x6F -#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 0x75 -#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 0x81 -#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 0xC1 -#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 0xC5 -#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 0xD7 -#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 0xDB -#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 0xE1 -#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 0xE9 +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 = 0x6B; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 = 0x6F; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 = 0x75; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 = 0x81; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 = 0xC1; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 = 0xC5; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 = 0xD7; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 = 0xDB; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 = 0xE1; +constexpr uint8_t RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 = 0xE9; // RADIOLIB_SX126X_CMD_SET_PA_CONFIG -#define RADIOLIB_SX126X_PA_CONFIG_HP_MAX 0x07 -#define RADIOLIB_SX126X_PA_CONFIG_PA_LUT 0x01 -#define RADIOLIB_SX126X_PA_CONFIG_SX1262_8 0x00 +constexpr uint8_t RADIOLIB_SX126X_PA_CONFIG_HP_MAX = 0x07; +constexpr uint8_t RADIOLIB_SX126X_PA_CONFIG_PA_LUT = 0x01; +constexpr uint8_t RADIOLIB_SX126X_PA_CONFIG_SX1262_8 = 0x00; // RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE -#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_FS 0x40 // 7 0 after Rx/Tx go to: FS mode -#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30 // 7 0 standby with crystal oscillator -#define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC 0x20 // 7 0 standby with RC oscillator (default) +constexpr uint8_t RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_FS = 0x40; // 7 0 after Rx/Tx go to: FS mode +constexpr uint8_t RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC = 0x30; // 7 0 standby with crystal oscillator +constexpr uint8_t RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC = 0x20; // 7 0 standby with RC oscillator (default) // RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS #define RADIOLIB_SX126X_IRQ_LR_FHSS_HOP 0b0100000000000000 // 14 14 PA ramped up during LR-FHSS hop diff --git a/inc/template/app_const_llcc68_template.hpp b/inc/template/app_const_llcc68_template.hpp index 9e9f92e..055bb96 100644 --- a/inc/template/app_const_llcc68_template.hpp +++ b/inc/template/app_const_llcc68_template.hpp @@ -28,7 +28,7 @@ constexpr auto DIO2_PIN = NC_PIN; constexpr auto DIO3_PIN = NC_PIN; /// @brief the pin numbers that needs to be configured as interrupt -constexpr gpio_num_t EXTI_PIN[] = {DIO1_PIN}; +constexpr gpio_num_t EXTI_PINS[] = {DIO1_PIN}; } #endif /* B0CD865F_D860_44B7_B289_4F512C770D2B */ diff --git a/src/llcc68.cpp b/src/llcc68.cpp deleted file mode 100644 index 021b650..0000000 --- a/src/llcc68.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// Created by Kurosu Chan on 2024/1/17. -// -#include "llcc68.hpp" -#include "driver/gpio.h" -#include "app_const_llcc68.hpp" - -constexpr auto ESP_INTR_FLAG_DEFAULT = 0; - -namespace app::driver::llcc68 { -namespace details { - uint32_t __tcxo_delay__; - transmit_state_t __tx_state__; - // TODO: use freeRTOS queue to handle received data - bool __dio_flag__ = false; -} - -void init_exti() { - constexpr auto isr = [](void *param) { - details::__dio_flag__ = true; - }; - - uint64_t pin_bit_mask = 0; - for (const auto pin : EXTI_PIN) { - pin_bit_mask |= (1ULL << pin); - } - - gpio_config_t io_conf = { - .pin_bit_mask = pin_bit_mask, - .mode = GPIO_MODE_INPUT, - .pull_up_en = GPIO_PULLUP_DISABLE, - .pull_down_en = GPIO_PULLDOWN_DISABLE, - .intr_type = GPIO_INTR_POSEDGE, - }; - // https://github.com/espressif/esp-idf/blob/v5.3.2/examples/peripherals/gpio/generic_gpio/main/gpio_example_main.c - ESP_ERROR_CHECK(gpio_config(&io_conf)); - gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT); - for (const auto pin : EXTI_PIN) { - gpio_isr_handler_add(pin, isr, nullptr); - } -} -}