diff --git a/.clang-format b/.clang-format index 4b76f7fa43b..c42068920c0 100644 --- a/.clang-format +++ b/.clang-format @@ -3,22 +3,55 @@ Language: Cpp AccessModifierOffset: -4 AlignAfterOpenBracket: AlwaysBreak AlignArrayOfStructures: None -AlignConsecutiveMacros: None -AlignConsecutiveAssignments: None -AlignConsecutiveBitFields: None -AlignConsecutiveDeclarations: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: true + AcrossEmptyLines: true + AcrossComments: true + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true + AlignCompound: true + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false AlignEscapedNewlines: Left AlignOperands: Align -AlignTrailingComments: false +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false -AllowShortEnumsOnASingleLine: true +AllowBreakBeforeNoexceptSpecifier: Never AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: All AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLoopsOnASingleLine: true +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false @@ -27,17 +60,18 @@ AttributeMacros: - __capability BinPackArguments: false BinPackParameters: false +BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false AfterClass: false AfterControlStatement: Never AfterEnum: false + AfterExternBlock: false AfterFunction: false AfterNamespace: false AfterObjCDeclaration: false AfterStruct: false AfterUnion: false - AfterExternBlock: false BeforeCatch: false BeforeElse: false BeforeLambdaBody: false @@ -46,38 +80,35 @@ BraceWrapping: SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: true +BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon +BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: false -BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeComma -BreakAfterJavaFieldAnnotations: false +BreakInheritanceList: BeforeColon BreakStringLiterals: false ColumnLimit: 99 CommentPragmas: '^ IWYU pragma:' -QualifierAlignment: Leave CompactNamespaces: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DeriveLineEnding: true DerivePointerAlignment: false DisableFormat: false EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false -PackConstructorInitializers: BinPack -BasedOnStyle: '' -ConstructorInitializerAllOnOneLineOrOnePerLine: false -AllowAllConstructorInitializersOnNextLine: true FixNamespaceComments: false ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH + - M_EACH IfMacros: - KJ_IF_MAYBE IncludeBlocks: Preserve @@ -97,19 +128,30 @@ IncludeCategories: IncludeIsMainRegex: '(Test)?$' IncludeIsMainSourceRegex: '' IndentAccessModifiers: false -IndentCaseLabels: false IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock IndentGotoLabels: true IndentPPDirectives: None -IndentExternBlock: AfterExternBlock -IndentRequires: false +IndentRequiresClause: false IndentWidth: 4 IndentWrappedFunctionNames: true +InsertBraces: false +InsertNewlineAtEOF: true InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: false LambdaBodyIndentation: Signature +LineEnding: DeriveLF MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 @@ -119,34 +161,44 @@ ObjCBlockIndentWidth: 4 ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack PenaltyBreakAssignment: 10 PenaltyBreakBeforeFirstCallParameter: 30 PenaltyBreakComment: 10 PenaltyBreakFirstLessLess: 0 PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 PenaltyBreakString: 10 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 60 PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Left PPIndentWidth: -1 +QualifierAlignment: Leave ReferenceAlignment: Pointer ReflowComments: false RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: true +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope SeparateDefinitionBlocks: Leave ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false SortIncludes: Never SortJavaStaticImport: Before -SortUsingDeclarations: false +SortUsingDeclarations: Never SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false SpaceBeforeParens: Never SpaceBeforeParensOptions: AfterControlStatements: false @@ -155,32 +207,35 @@ SpaceBeforeParensOptions: AfterFunctionDeclarationName: false AfterIfMacros: false AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false BeforeNonEmptyParentheses: false -SpaceAroundPointerQualifiers: Default SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: Never -SpacesInConditionalStatement: false SpacesInContainerLiterals: false -SpacesInCStyleCastParentheses: false SpacesInLineCommentPrefix: Minimum: 1 Maximum: -1 -SpacesInParentheses: false +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false -BitFieldColonSpacing: Both -Standard: c++03 +Standard: c++20 StatementAttributeLikeMacros: - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 4 -UseCRLF: false UseTab: Never +VerilogBreakBetweenInstancePorts: true WhitespaceSensitiveMacros: - STRINGIZE - PP_STRINGIZE diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index d35ca0c17e5..d37337452a9 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -1,5 +1,4 @@ name: 'Unit tests' - on: pull_request: @@ -25,7 +24,7 @@ jobs: - name: 'Get flipper from device manager (mock)' id: device run: | - echo "flipper=/dev/ttyACM0" >> $GITHUB_OUTPUT + echo "flipper=auto" >> $GITHUB_OUTPUT - name: 'Flash unit tests firmware' id: flashing @@ -40,7 +39,7 @@ jobs: timeout-minutes: 5 run: | source scripts/toolchain/fbtenv.sh - python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}} + python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=120 await_flipper python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} format_ext - name: 'Copy assets and unit data, reboot and wait for flipper' @@ -49,11 +48,11 @@ jobs: timeout-minutes: 7 run: | source scripts/toolchain/fbtenv.sh - python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}} + python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=15 await_flipper rm -rf build/latest/resources/dolphin python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} -f send build/latest/resources /ext python3 scripts/power.py -p ${{steps.device.outputs.flipper}} reboot - python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}} + python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=15 await_flipper - name: 'Run units and validate results' id: run_units @@ -61,7 +60,7 @@ jobs: timeout-minutes: 7 run: | source scripts/toolchain/fbtenv.sh - python3 scripts/testing/units.py ${{steps.device.outputs.flipper}} + python3 scripts/testops.py run_units -p ${{steps.device.outputs.flipper}} - name: 'Check GDB output' if: failure() && steps.flashing.outcome == 'success' diff --git a/.github/workflows/updater_test.yml b/.github/workflows/updater_test.yml index b14b618a6eb..dbe5df883d6 100644 --- a/.github/workflows/updater_test.yml +++ b/.github/workflows/updater_test.yml @@ -1,8 +1,6 @@ name: 'Updater test' - on: pull_request: - env: TARGETS: f7 DEFAULT_TARGET: f7 @@ -26,7 +24,7 @@ jobs: - name: 'Get flipper from device manager (mock)' id: device run: | - echo "flipper=Rekigyn" >> $GITHUB_OUTPUT + echo "flipper=auto" >> $GITHUB_OUTPUT echo "stlink=0F020D026415303030303032" >> $GITHUB_OUTPUT - name: 'Flashing target firmware' @@ -35,7 +33,7 @@ jobs: run: | source scripts/toolchain/fbtenv.sh ./fbt flash_usb_full PORT=${{steps.device.outputs.flipper}} FORCE=1 - python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}} + python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=180 await_flipper - name: 'Validating updater' id: second_full_flash @@ -44,7 +42,7 @@ jobs: run: | source scripts/toolchain/fbtenv.sh ./fbt flash_usb PORT=${{steps.device.outputs.flipper}} FORCE=1 - python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}} + python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=180 await_flipper - name: 'Get last release tag' id: release_tag @@ -71,5 +69,5 @@ jobs: if: failure() run: | source scripts/toolchain/fbtenv.sh - python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}} + python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=180 await_flipper python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} format_ext diff --git a/.gitignore b/.gitignore index 56c8363383f..c97ba8da9f1 100644 --- a/.gitignore +++ b/.gitignore @@ -44,9 +44,6 @@ Brewfile.lock.json .sconsign.dblite -# Visual Studio Code -/.vscode - # bundle output /dist diff --git a/.gitmodules b/.gitmodules index c4c68a6a77d..038bb57e6f2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -23,9 +23,6 @@ [submodule "lib/mbedtls"] path = lib/mbedtls url = https://github.com/Mbed-TLS/mbedtls.git -[submodule "lib/cxxheaderparser"] - path = lib/cxxheaderparser - url = https://github.com/robotpy/cxxheaderparser.git [submodule "lib/heatshrink"] path = lib/heatshrink url = https://github.com/flipperdevices/heatshrink.git diff --git a/.pvsconfig b/.pvsconfig index b6001ca5c02..674231d2203 100644 --- a/.pvsconfig +++ b/.pvsconfig @@ -3,10 +3,12 @@ //-V:M_EACH:1048,1044 //-V:ARRAY_DEF:760,747,568,776,729,712,654,1103 //-V:LIST_DEF:760,747,568,712,729,654,776,1103 +//-V:LIST_DUAL_PUSH_DEF:524,760,774 //-V:BPTREE_DEF2:779,1086,557,773,512 //-V:DICT_DEF2:779,524,776,760,1044,1001,729,590,568,747,685,1103 //-V:ALGO_DEF:1048,747,1044 //-V:TUPLE_DEF2:524,590,1001,760 +//-V:DEQUE_DEF:658,747,760 # Non-severe malloc/null pointer deref warnings //-V::522:2,3 @@ -43,4 +45,4 @@ //-V:with_view_model:1044,1048 # Examples -//V_EXCLUDE_PATH applications/examples/ \ No newline at end of file +//V_EXCLUDE_PATH applications/examples/ diff --git a/.sublime-project b/.sublime-project index 5d751aaf630..da2ef41a12e 100644 --- a/.sublime-project +++ b/.sublime-project @@ -6,16 +6,20 @@ } ], "settings": { - "LSP": { - "clangd": { - "initializationOptions": { - "clangd.compile-commands-dir": "build/latest", - "clangd.header-insertion": "never", - "clangd.query-driver": "**", - "clangd.clang-tidy": true, - }, + "LSP": { + "clangd": { "enabled": true, + "initializationOptions": { + // Use with toolchain version 39+ + // Set `"binary": "custom",` option in LSP-clangd config to use toolchain clangd + // "custom_command": ["toolchain/current/bin/clangd"], + + "clangd.compile-commands-dir": "build/latest", + "clangd.header-insertion": "never", + "clangd.query-driver": "**/arm-none-eabi-*", + "clangd.clang-tidy": true, + }, }, - }, + }, }, } diff --git a/.vscode/.gitignore b/.vscode/.gitignore index 481efcdef35..bd4df47d60d 100644 --- a/.vscode/.gitignore +++ b/.vscode/.gitignore @@ -1,5 +1,3 @@ -/c_cpp_properties.json -/extensions.json -/launch.json -/settings.json -/tasks.json +* +!example/ +!ReadMe.md diff --git a/.vscode/example/settings.json b/.vscode/example/settings.json.tmpl similarity index 72% rename from .vscode/example/settings.json rename to .vscode/example/settings.json.tmpl index 9afabf92688..5e0da689770 100644 --- a/.vscode/example/settings.json +++ b/.vscode/example/settings.json.tmpl @@ -1,11 +1,7 @@ { - "C_Cpp.default.cStandard": "gnu23", - "C_Cpp.default.cppStandard": "c++20", - "python.formatting.provider": "black", "workbench.tree.indent": 12, "cortex-debug.enableTelemetry": false, "cortex-debug.variableUseNaturalFormat": true, - "cortex-debug.showRTOS": true, "cortex-debug.armToolchainPath": "${workspaceFolder}/toolchain/current/bin", "cortex-debug.openocdPath": "${workspaceFolder}/toolchain/current/bin/openocd", "cortex-debug.gdbPath": "${workspaceFolder}/toolchain/current/bin/arm-none-eabi-gdb-py3", @@ -16,9 +12,9 @@ "SConstruct": "python", "*.fam": "python" }, + // "clangd.path": "${workspaceFolder}/toolchain/current/bin/clangd@FBT_PLATFORM_EXECUTABLE_EXT@", "clangd.arguments": [ - // We might be able to tighten this a bit more to only include the correct toolchain. - "--query-driver=**", + "--query-driver=**/arm-none-eabi-*", "--compile-commands-dir=${workspaceFolder}/build/latest", "--clang-tidy", "--header-insertion=never" diff --git a/ReadMe.md b/ReadMe.md index 34776ebd157..f4c0dffedc3 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -52,7 +52,8 @@ Supported development platforms: Supported in-circuit debuggers (optional but highly recommended): - [Flipper Zero Wi-Fi Development Board](https://shop.flipperzero.one/products/wifi-devboard) -- ST-Link +- CMSIS-DAP compatible: Raspberry Pi Debug Probe and etc... +- ST-Link (v2, v3, v3mods) - J-Link Flipper Build System will take care of all the other dependencies. @@ -96,18 +97,20 @@ Make sure your Flipper is on, and your firmware is functioning. Connect your Fli - [Hardware combos and Un-bricking](/documentation/KeyCombo.md) - recovering your Flipper from the most nasty situations - [Flipper File Formats](/documentation/file_formats) - everything about how Flipper stores your data and how you can work with it - [Universal Remotes](/documentation/UniversalRemotes.md) - contributing your infrared remote to the universal remote database -- [Firmware Roadmap](/documentation/RoadMap.md) +- [Firmware Roadmap](https://miro.com/app/board/uXjVO_3D6xU=/) - And much more in the [Developer Documentation](https://developer.flipper.net/flipperzero/doxygen) # Project structure -- `applications` - applications and services used in firmware -- `assets` - assets used by applications and services -- `furi` - Furi Core: OS-level primitives and helpers -- `documentation` - documentation generation system configs and input files -- `firmware` - firmware source code -- `lib` - our and 3rd party libraries, drivers, etc. -- `scripts` - supplementary scripts and python libraries home +- `applications` - Applications and services used in firmware +- `applications_users` - Place for your additional applications and services +- `assets` - Assets used by applications and services +- `documentation` - Documentation generation system configs and input files +- `furi` - Furi Core: OS-level primitives and helpers +- `lib` - Our and 3rd party libraries, drivers, tools and etc... +- `site_scons` - Build system configuration and modules +- `scripts` - Supplementary scripts and various python libraries +- `targets` - Firmware targets: platform specific code Also, see `ReadMe.md` files inside those directories for further details. diff --git a/SConstruct b/SConstruct index 532c37b7f59..89a337cd508 100644 --- a/SConstruct +++ b/SConstruct @@ -43,10 +43,10 @@ distenv = coreenv.Clone( "blackmagic", "jflash", "doxygen", + "textfile", ], ENV=os.environ, UPDATE_BUNDLE_DIR="dist/${DIST_DIR}/f${TARGET_HW}-update-${DIST_SUFFIX}", - VSCODE_LANG_SERVER=ARGUMENTS.get("LANG_SERVER", "cpptools"), ) firmware_env = distenv.AddFwProject( @@ -403,14 +403,23 @@ distenv.PhonyTarget( ) # Prepare vscode environment -VSCODE_LANG_SERVER = cmd_environment["LANG_SERVER"] vscode_dist = distenv.Install( "#.vscode", [ - distenv.Glob("#.vscode/example/*.json"), - distenv.Glob(f"#.vscode/example/{VSCODE_LANG_SERVER}/*.json"), + distenv.Glob("#.vscode/example/*.json", exclude="*.tmpl"), + distenv.Glob("#.vscode/example/${LANG_SERVER}/*.json"), ], ) +for template_file in distenv.Glob("#.vscode/example/*.tmpl"): + vscode_dist.append( + distenv.Substfile( + distenv.Dir("#.vscode").File(template_file.name.replace(".tmpl", "")), + template_file, + SUBST_DICT={ + "@FBT_PLATFORM_EXECUTABLE_EXT@": ".exe" if os.name == "nt" else "" + }, + ) + ) distenv.Precious(vscode_dist) distenv.NoClean(vscode_dist) distenv.Alias("vscode_dist", (vscode_dist, firmware_env["FW_CDB"])) diff --git a/applications/debug/battery_test_app/views/battery_info.c b/applications/debug/battery_test_app/views/battery_info.c index 5c5a3bd4532..8e53cc6fb83 100644 --- a/applications/debug/battery_test_app/views/battery_info.c +++ b/applications/debug/battery_test_app/views/battery_info.c @@ -3,7 +3,7 @@ #include #include -#define LOW_CHARGE_THRESHOLD 10 +#define LOW_CHARGE_THRESHOLD 10 #define HIGH_DRAIN_CURRENT_THRESHOLD 100 struct BatteryInfo { @@ -17,7 +17,7 @@ static void draw_stat(Canvas* canvas, int x, int y, const Icon* icon, char* val) canvas_draw_box(canvas, x - 4, y + 16, 24, 6); canvas_set_color(canvas, ColorBlack); canvas_draw_str_aligned(canvas, x + 8, y + 22, AlignCenter, AlignBottom, val); -}; +} static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { char emote[20] = {}; @@ -85,7 +85,7 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { canvas_draw_str_aligned(canvas, 92, y + 3, AlignCenter, AlignCenter, emote); canvas_draw_str_aligned(canvas, 92, y + 15, AlignCenter, AlignCenter, header); canvas_draw_str_aligned(canvas, 92, y + 27, AlignCenter, AlignCenter, value); -}; +} static void battery_info_draw_callback(Canvas* canvas, void* context) { furi_assert(context); diff --git a/applications/debug/bt_debug_app/views/bt_test.c b/applications/debug/bt_debug_app/views/bt_test.c index 792ebfd8f88..58b65e1947b 100644 --- a/applications/debug/bt_debug_app/views/bt_test.c +++ b/applications/debug/bt_debug_app/views/bt_test.c @@ -39,7 +39,7 @@ typedef struct { } BtTestModel; #define BT_TEST_START_MESSAGE "Ok - Start" -#define BT_TEST_STOP_MESSAGE "Ok - Stop" +#define BT_TEST_STOP_MESSAGE "Ok - Stop" static void bt_test_process_up(BtTest* bt_test); static void bt_test_process_down(BtTest* bt_test); @@ -384,8 +384,7 @@ BtTestParam* bt_test_param_add( void bt_test_set_rssi(BtTest* bt_test, float rssi) { furi_assert(bt_test); - with_view_model( - bt_test->view, BtTestModel * model, { model->rssi = rssi; }, true); + with_view_model(bt_test->view, BtTestModel * model, { model->rssi = rssi; }, true); } void bt_test_set_packets_tx(BtTest* bt_test, uint32_t packets_num) { diff --git a/applications/debug/ccid_test/ccid_test_app.c b/applications/debug/ccid_test/ccid_test_app.c index 6993901d243..46a1237f93d 100644 --- a/applications/debug/ccid_test/ccid_test_app.c +++ b/applications/debug/ccid_test/ccid_test_app.c @@ -9,6 +9,7 @@ #include "iso7816_callbacks.h" #include "iso7816_t0_apdu.h" #include "iso7816_atr.h" +#include "iso7816_response.h" typedef enum { EventTypeInput, @@ -118,6 +119,80 @@ static const CcidCallbacks ccid_cb = { ccid_xfr_datablock_callback, }; +//Instruction 1: returns an OK response unconditionally +//APDU example: 0x01:0x01:0x00:0x00 +//response: SW1=0x90, SW2=0x00 +void handle_instruction_01(ISO7816_Response_APDU* responseAPDU) { + responseAPDU->DataLen = 0; + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_OK); +} + +//Instruction 2: expect command with no body, replies wit with a body with two bytes +//APDU example: 0x01:0x02:0x00:0x00:0x02 +//response: 'bc' (0x62, 0x63) SW1=0x90, SW2=0x00 +void handle_instruction_02( + uint8_t p1, + uint8_t p2, + uint16_t lc, + uint16_t le, + ISO7816_Response_APDU* responseAPDU) { + if(p1 == 0 && p2 == 0 && lc == 0 && le >= 2) { + responseAPDU->Data[0] = 0x62; + responseAPDU->Data[1] = 0x63; + + responseAPDU->DataLen = 2; + + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_OK); + } else if(p1 != 0 || p2 != 0) { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_PARAMETERS_P1_P2); + } else { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_LENGTH); + } +} + +//Instruction 3: sends a command with a body with two bytes, receives a response with no bytes +//APDU example: 0x01:0x03:0x00:0x00:0x02:CA:FE +//response SW1=0x90, SW2=0x00 +void handle_instruction_03( + uint8_t p1, + uint8_t p2, + uint16_t lc, + ISO7816_Response_APDU* responseAPDU) { + if(p1 == 0 && p2 == 0 && lc == 2) { + responseAPDU->DataLen = 0; + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_OK); + } else if(p1 != 0 || p2 != 0) { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_PARAMETERS_P1_P2); + } else { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_LENGTH); + } +} + +//instruction 4: sends a command with a body with 'n' bytes, receives a response with 'n' bytes +//APDU example: 0x01:0x04:0x00:0x00:0x04:0x01:0x02:0x03:0x04:0x04 +//receives (0x01, 0x02, 0x03, 0x04) SW1=0x90, SW2=0x00 +void handle_instruction_04( + uint8_t p1, + uint8_t p2, + uint16_t lc, + uint16_t le, + const uint8_t* commandApduDataBuffer, + ISO7816_Response_APDU* responseAPDU) { + if(p1 == 0 && p2 == 0 && lc > 0 && le > 0 && le >= lc) { + for(uint16_t i = 0; i < lc; i++) { + responseAPDU->Data[i] = commandApduDataBuffer[i]; + } + + responseAPDU->DataLen = lc; + + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_OK); + } else if(p1 != 0 || p2 != 0) { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_PARAMETERS_P1_P2); + } else { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_LENGTH); + } +} + void iso7816_answer_to_reset(Iso7816Atr* atr) { //minimum valid ATR: https://smartcard-atr.apdu.fr/parse?ATR=3B+00 atr->TS = 0x3B; @@ -125,48 +200,38 @@ void iso7816_answer_to_reset(Iso7816Atr* atr) { } void iso7816_process_command( - const struct ISO7816_Command_APDU* commandAPDU, - struct ISO7816_Response_APDU* responseAPDU, - const uint8_t* commandApduDataBuffer, - uint8_t commandApduDataBufferLen, - uint8_t* responseApduDataBuffer, - uint8_t* responseApduDataBufferLen) { + const ISO7816_Command_APDU* commandAPDU, + ISO7816_Response_APDU* responseAPDU) { //example 1: sends a command with no body, receives a response with no body - //sends APDU 0x01:0x02:0x00:0x00 + //sends APDU 0x01:0x01:0x00:0x00 //receives SW1=0x90, SW2=0x00 - if(commandAPDU->CLA == 0x01 && commandAPDU->INS == 0x01) { - responseAPDU->SW1 = 0x90; - responseAPDU->SW2 = 0x00; - } - //example 2: sends a command with no body, receives a response with a body with two bytes - //sends APDU 0x01:0x02:0x00:0x00 - //receives 'bc' (0x62, 0x63) SW1=0x80, SW2=0x10 - else if(commandAPDU->CLA == 0x01 && commandAPDU->INS == 0x02) { - responseApduDataBuffer[0] = 0x62; - responseApduDataBuffer[1] = 0x63; - - *responseApduDataBufferLen = 2; - responseAPDU->SW1 = 0x90; - responseAPDU->SW2 = 0x00; - } - //example 3: ends a command with a body with two bytes, receives a response with a body with two bytes - //sends APDU 0x01:0x03:0x00:0x00:0x02:CA:FE - //receives (0xCA, 0xFE) SW1=0x90, SW2=0x02 - else if( - commandAPDU->CLA == 0x01 && commandAPDU->INS == 0x03 && commandApduDataBufferLen == 2 && - commandAPDU->Lc == 2) { - //echo command body to response body - responseApduDataBuffer[0] = commandApduDataBuffer[0]; - responseApduDataBuffer[1] = commandApduDataBuffer[1]; - - *responseApduDataBufferLen = 2; - - responseAPDU->SW1 = 0x90; - responseAPDU->SW2 = 0x00; + if(commandAPDU->CLA == 0x01) { + switch(commandAPDU->INS) { + case 0x01: + handle_instruction_01(responseAPDU); + break; + case 0x02: + handle_instruction_02( + commandAPDU->P1, commandAPDU->P2, commandAPDU->Lc, commandAPDU->Le, responseAPDU); + break; + case 0x03: + handle_instruction_03(commandAPDU->P1, commandAPDU->P2, commandAPDU->Lc, responseAPDU); + break; + case 0x04: + handle_instruction_04( + commandAPDU->P1, + commandAPDU->P2, + commandAPDU->Lc, + commandAPDU->Le, + commandAPDU->Data, + responseAPDU); + break; + default: + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_INSTRUCTION_NOT_SUPPORTED); + } } else { - responseAPDU->SW1 = 0x6A; - responseAPDU->SW2 = 0x00; + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_CLASS_NOT_SUPPORTED); } } @@ -188,8 +253,10 @@ int32_t ccid_test_app(void* p) { FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); furi_hal_usb_unlock(); - furi_hal_ccid_set_callbacks((CcidCallbacks*)&ccid_cb, NULL); + furi_check(furi_hal_usb_set_config(&usb_ccid, &app->ccid_cfg) == true); + furi_hal_usb_ccid_set_callbacks((CcidCallbacks*)&ccid_cb, NULL); + furi_hal_usb_ccid_insert_smartcard(); iso7816_set_callbacks((Iso7816Callbacks*)&iso87816_cb); @@ -210,8 +277,8 @@ int32_t ccid_test_app(void* p) { } //tear down USB + furi_hal_usb_ccid_set_callbacks(NULL, NULL); furi_hal_usb_set_config(usb_mode_prev, NULL); - furi_hal_ccid_set_callbacks(NULL, NULL); iso7816_set_callbacks(NULL); diff --git a/applications/debug/ccid_test/client/ccid_client.py b/applications/debug/ccid_test/client/ccid_client.py new file mode 100755 index 00000000000..77d2711ef94 --- /dev/null +++ b/applications/debug/ccid_test/client/ccid_client.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# pylint: disable=missing-module-docstring, too-many-arguments, consider-using-f-string, missing-function-docstring +from smartcard.System import readers + + +def test_apdu(connection, test_name, apdu, expected_sw1, expected_sw2, expected_data): + print("Running test: [%s]" % test_name) + data, sw1, sw2 = connection.transmit(apdu) + + failed = [] + + if sw1 != expected_sw1: + failed.append("SW1: Expected %x, actual %x" % (expected_sw1, sw1)) + + if sw2 != expected_sw2: + failed.append("SW2: Expected %x, actual %x" % (expected_sw2, sw2)) + + if len(data) != len(expected_data): + failed.append( + "Data: Sizes differ: Expected %x, actual %x" + % (len(expected_data), len(data)) + ) + print(data) + elif len(data) > 0: + data_matches = True + for i, _ in enumerate(data): + if data[i] != expected_data[i]: + data_matches = False + + if not data_matches: + failed.append("Data: Expected %s, actual %s" % (expected_data, data)) + + if len(failed) > 0: + print("Test failed: ") + for failure in failed: + print("- %s" % failure) + else: + print("Test passed!") + + +def main(): + r = readers() + print("Found following smartcard readers: ") + + for i, sc in enumerate(r): + print("[%d] %s" % (i, sc)) + + print("Select the smartcard reader you want to run tests against:") + + reader_index = int(input()) + + if reader_index < len(r): + connection = r[reader_index].createConnection() + + connection.connect() + + test_apdu( + connection, + "INS 0x01: No Lc, no Data, No Le. Expect no data in return", + [0x01, 0x01, 0x00, 0x00], + 0x90, + 0x00, + [], + ) + + test_apdu( + connection, + "INS 0x02: No Lc, no Data, Le=2. Expect 2 byte data in return", + [0x01, 0x02, 0x00, 0x00, 0x02], + 0x90, + 0x00, + [0x62, 0x63], + ) + + test_apdu( + connection, + "INS 0x03: Lc=2, data=[0xCA, 0xFE], No Le. Expect no data in return", + [0x01, 0x03, 0x00, 0x00, 0x02, 0xCA, 0xFE], + 0x90, + 0x00, + [], + ) + + test_apdu( + connection, + "INS 0x04: Lc=2, data=[0xCA, 0xFE], Le=2. Expect 1 byte data in return", + [0x01, 0x04, 0x00, 0x00, 0x02, 0xCA, 0xFE, 0x02], + 0x90, + 0x00, + [0xCA, 0xFE], + ) + + small_apdu = list(range(0, 0x0F)) + + test_apdu( + connection, + "INS 0x04: Lc=0x0F, data=small_apdu, Le=0x0F. Expect 14 bytes data in return", + [0x01, 0x04, 0x00, 0x00, 0x0F] + small_apdu + [0x0F], + 0x90, + 0x00, + small_apdu, + ) + + upper_bound = 0xF0 + max_apdu = list(range(0, upper_bound)) + + test_apdu( + connection, + "INS 0x04: Lc=0x%x, data=max_apdu, Le=0x%x. Expect 0x%x bytes data in return" + % (upper_bound, upper_bound, upper_bound), + [0x01, 0x04, 0x00, 0x00, upper_bound] + max_apdu + [upper_bound], + 0x90, + 0x00, + max_apdu, + ) + + +if __name__ == "__main__": + main() diff --git a/applications/debug/ccid_test/client/requirements.txt b/applications/debug/ccid_test/client/requirements.txt new file mode 100644 index 00000000000..fe0a8e539f2 --- /dev/null +++ b/applications/debug/ccid_test/client/requirements.txt @@ -0,0 +1,2 @@ +pyscard +# or sudo apt install python3-pyscard \ No newline at end of file diff --git a/applications/debug/ccid_test/iso7816_atr.h b/applications/debug/ccid_test/iso7816_atr.h index 050457f8c19..215ec60ee63 100644 --- a/applications/debug/ccid_test/iso7816_atr.h +++ b/applications/debug/ccid_test/iso7816_atr.h @@ -1,9 +1,6 @@ -#ifndef _ISO7816_ATR_H_ -#define _ISO7816_ATR_H_ +#pragma once typedef struct { uint8_t TS; uint8_t T0; } Iso7816Atr; - -#endif //_ISO7816_ATR_H_ diff --git a/applications/debug/ccid_test/iso7816_callbacks.c b/applications/debug/ccid_test/iso7816_callbacks.c index 1a66fa7755d..6c1bb106a90 100644 --- a/applications/debug/ccid_test/iso7816_callbacks.c +++ b/applications/debug/ccid_test/iso7816_callbacks.c @@ -1,17 +1,21 @@ // transforms low level calls such as XFRCallback or ICC Power on to a structured one // an application can register these calls and listen for the callbacks defined in Iso7816Callbacks -#include "iso7816_t0_apdu.h" -#include "iso7816_atr.h" -#include "iso7816_callbacks.h" #include #include #include +#include -#define ISO7816_RESPONSE_BUFFER_SIZE 255 +#include "iso7816_t0_apdu.h" +#include "iso7816_atr.h" +#include "iso7816_callbacks.h" +#include "iso7816_response.h" static Iso7816Callbacks* callbacks = NULL; +static uint8_t commandApduBuffer[sizeof(ISO7816_Command_APDU) + CCID_SHORT_APDU_SIZE]; +static uint8_t responseApduBuffer[sizeof(ISO7816_Response_APDU) + CCID_SHORT_APDU_SIZE]; + void iso7816_set_callbacks(Iso7816Callbacks* cb) { callbacks = cb; } @@ -36,41 +40,26 @@ void iso7816_xfr_datablock_callback( uint32_t pcToReaderDataBlockLen, uint8_t* readerToPcDataBlock, uint32_t* readerToPcDataBlockLen) { - struct ISO7816_Response_APDU responseAPDU; - uint8_t responseApduDataBuffer[ISO7816_RESPONSE_BUFFER_SIZE]; - uint8_t responseApduDataBufferLen = 0; + ISO7816_Response_APDU* responseAPDU = (ISO7816_Response_APDU*)&responseApduBuffer; if(callbacks != NULL) { - struct ISO7816_Command_APDU commandAPDU; + ISO7816_Command_APDU* commandAPDU = (ISO7816_Command_APDU*)&commandApduBuffer; - const uint8_t* commandApduDataBuffer = NULL; - uint8_t commandApduDataBufferLen = 0; + uint8_t result = + iso7816_read_command_apdu(commandAPDU, pcToReaderDataBlock, pcToReaderDataBlockLen); - iso7816_read_command_apdu(&commandAPDU, pcToReaderDataBlock, pcToReaderDataBlockLen); + if(result == ISO7816_READ_COMMAND_APDU_OK) { + callbacks->iso7816_process_command(commandAPDU, responseAPDU); - if(commandAPDU.Lc > 0) { - commandApduDataBufferLen = commandAPDU.Lc; - commandApduDataBuffer = &pcToReaderDataBlock[5]; + furi_assert(responseAPDU->DataLen < CCID_SHORT_APDU_SIZE); + } else if(result == ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LE) { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_LE); + } else if(result == ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LENGTH) { + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_WRONG_LENGTH); } - - callbacks->iso7816_process_command( - &commandAPDU, - &responseAPDU, - commandApduDataBuffer, - commandApduDataBufferLen, - responseApduDataBuffer, - &responseApduDataBufferLen); - } else { - //class not supported - responseAPDU.SW1 = 0x6E; - responseAPDU.SW2 = 0x00; + iso7816_set_response(responseAPDU, ISO7816_RESPONSE_INTERNAL_EXCEPTION); } - iso7816_write_response_apdu( - &responseAPDU, - readerToPcDataBlock, - readerToPcDataBlockLen, - responseApduDataBuffer, - responseApduDataBufferLen); + iso7816_write_response_apdu(responseAPDU, readerToPcDataBlock, readerToPcDataBlockLen); } diff --git a/applications/debug/ccid_test/iso7816_callbacks.h b/applications/debug/ccid_test/iso7816_callbacks.h index 3d337d23a0b..6b408c7f502 100644 --- a/applications/debug/ccid_test/iso7816_callbacks.h +++ b/applications/debug/ccid_test/iso7816_callbacks.h @@ -1,5 +1,4 @@ -#ifndef _ISO7816_CALLBACKS_H_ -#define _ISO7816_CALLBACKS_H_ +#pragma once #include #include "iso7816_atr.h" @@ -8,12 +7,8 @@ typedef struct { void (*iso7816_answer_to_reset)(Iso7816Atr* atr); void (*iso7816_process_command)( - const struct ISO7816_Command_APDU* command, - struct ISO7816_Response_APDU* response, - const uint8_t* commandApduDataBuffer, - uint8_t commandApduDataBufferLen, - uint8_t* responseApduDataBuffer, - uint8_t* responseApduDataBufferLen); + const ISO7816_Command_APDU* command, + ISO7816_Response_APDU* response); } Iso7816Callbacks; void iso7816_set_callbacks(Iso7816Callbacks* cb); @@ -24,5 +19,3 @@ void iso7816_xfr_datablock_callback( uint32_t dataBlockLen, uint8_t* responseDataBlock, uint32_t* responseDataBlockLen); - -#endif //_ISO7816_CALLBACKS_H_ \ No newline at end of file diff --git a/applications/debug/ccid_test/iso7816_response.c b/applications/debug/ccid_test/iso7816_response.c new file mode 100644 index 00000000000..e222756189c --- /dev/null +++ b/applications/debug/ccid_test/iso7816_response.c @@ -0,0 +1,8 @@ +#include +#include "iso7816_t0_apdu.h" +#include "iso7816_response.h" + +void iso7816_set_response(ISO7816_Response_APDU* responseAPDU, uint16_t responseCode) { + responseAPDU->SW1 = (responseCode >> (8 * 1)) & 0xff; + responseAPDU->SW2 = (responseCode >> (8 * 0)) & 0xff; +} diff --git a/applications/debug/ccid_test/iso7816_response.h b/applications/debug/ccid_test/iso7816_response.h new file mode 100644 index 00000000000..cb328d09535 --- /dev/null +++ b/applications/debug/ccid_test/iso7816_response.h @@ -0,0 +1,12 @@ +#pragma once + +#define ISO7816_RESPONSE_OK 0x9000 + +#define ISO7816_RESPONSE_WRONG_LENGTH 0x6700 +#define ISO7816_RESPONSE_WRONG_PARAMETERS_P1_P2 0x6A00 +#define ISO7816_RESPONSE_WRONG_LE 0x6C00 +#define ISO7816_RESPONSE_INSTRUCTION_NOT_SUPPORTED 0x6D00 +#define ISO7816_RESPONSE_CLASS_NOT_SUPPORTED 0x6E00 +#define ISO7816_RESPONSE_INTERNAL_EXCEPTION 0x6F00 + +void iso7816_set_response(ISO7816_Response_APDU* responseAPDU, uint16_t responseCode); diff --git a/applications/debug/ccid_test/iso7816_t0_apdu.c b/applications/debug/ccid_test/iso7816_t0_apdu.c index 5fb695af193..3de5555f493 100644 --- a/applications/debug/ccid_test/iso7816_t0_apdu.c +++ b/applications/debug/ccid_test/iso7816_t0_apdu.c @@ -2,37 +2,73 @@ #include #include #include +#include #include "iso7816_t0_apdu.h" //reads dataBuffer with dataLen size, translate it into a ISO7816_Command_APDU type //extra data will be pointed to commandDataBuffer -void iso7816_read_command_apdu( - struct ISO7816_Command_APDU* command, +uint8_t iso7816_read_command_apdu( + ISO7816_Command_APDU* command, const uint8_t* dataBuffer, uint32_t dataLen) { - UNUSED(dataLen); - command->CLA = dataBuffer[0]; command->INS = dataBuffer[1]; command->P1 = dataBuffer[2]; command->P2 = dataBuffer[3]; - command->Lc = dataBuffer[4]; + + if(dataLen == 4) { + command->Lc = 0; + command->Le = 0; + command->LePresent = false; + + return ISO7816_READ_COMMAND_APDU_OK; + } else if(dataLen == 5) { + //short le + + command->Lc = 0; + command->Le = dataBuffer[4]; + command->LePresent = true; + + return ISO7816_READ_COMMAND_APDU_OK; + } else if(dataLen > 5 && dataBuffer[4] != 0x00) { + //short lc + + command->Lc = dataBuffer[4]; + if(command->Lc > 0 && command->Lc < CCID_SHORT_APDU_SIZE) { //-V560 + memcpy(command->Data, &dataBuffer[5], command->Lc); + + //does it have a short le too? + if(dataLen == (uint32_t)(command->Lc + 5)) { + command->Le = 0; + command->LePresent = false; + return ISO7816_READ_COMMAND_APDU_OK; + } else if(dataLen == (uint32_t)(command->Lc + 6)) { + command->Le = dataBuffer[dataLen - 1]; + command->LePresent = true; + + return ISO7816_READ_COMMAND_APDU_OK; + } else { + return ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LENGTH; + } + } else { + return ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LENGTH; + } + } else { + return ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LENGTH; + } } -//data buffer countains the whole APU response (response + trailer (SW1+SW2)) +//data buffer contains the whole APU response (response + trailer (SW1+SW2)) void iso7816_write_response_apdu( - const struct ISO7816_Response_APDU* response, + const ISO7816_Response_APDU* response, uint8_t* readerToPcDataBlock, - uint32_t* readerToPcDataBlockLen, - uint8_t* responseDataBuffer, - uint32_t responseDataLen) { + uint32_t* readerToPcDataBlockLen) { uint32_t responseDataBufferIndex = 0; //response body - if(responseDataLen > 0) { - while(responseDataBufferIndex < responseDataLen) { - readerToPcDataBlock[responseDataBufferIndex] = - responseDataBuffer[responseDataBufferIndex]; + if(response->DataLen > 0) { + while(responseDataBufferIndex < response->DataLen) { + readerToPcDataBlock[responseDataBufferIndex] = response->Data[responseDataBufferIndex]; responseDataBufferIndex++; } } @@ -45,4 +81,4 @@ void iso7816_write_response_apdu( responseDataBufferIndex++; *readerToPcDataBlockLen = responseDataBufferIndex; -} \ No newline at end of file +} diff --git a/applications/debug/ccid_test/iso7816_t0_apdu.h b/applications/debug/ccid_test/iso7816_t0_apdu.h index 48a18944067..50eb476a9cd 100644 --- a/applications/debug/ccid_test/iso7816_t0_apdu.h +++ b/applications/debug/ccid_test/iso7816_t0_apdu.h @@ -1,11 +1,14 @@ -#ifndef _ISO7816_T0_APDU_H_ -#define _ISO7816_T0_APDU_H_ +#pragma once #include #include "iso7816_atr.h" #include "core/common_defines.h" -struct ISO7816_Command_APDU { +#define ISO7816_READ_COMMAND_APDU_OK 0 +#define ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LE 1 +#define ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LENGTH 2 + +typedef struct { //header uint8_t CLA; uint8_t INS; @@ -13,24 +16,27 @@ struct ISO7816_Command_APDU { uint8_t P2; //body - uint8_t Lc; - uint8_t Le; -} FURI_PACKED; + uint16_t Lc; //data length + uint16_t Le; //maximum response data length expected by client + + //Le can have value of 0x00, which actually meand 0x100 = 256 + bool LePresent; + uint8_t Data[0]; +} FURI_PACKED ISO7816_Command_APDU; -struct ISO7816_Response_APDU { +typedef struct { uint8_t SW1; uint8_t SW2; -} FURI_PACKED; + uint16_t DataLen; + uint8_t Data[0]; +} FURI_PACKED ISO7816_Response_APDU; void iso7816_answer_to_reset(Iso7816Atr* atr); -void iso7816_read_command_apdu( - struct ISO7816_Command_APDU* command, - const uint8_t* dataBuffer, - uint32_t dataLen); +uint8_t iso7816_read_command_apdu( + ISO7816_Command_APDU* command, + const uint8_t* pcToReaderDataBlock, + uint32_t pcToReaderDataBlockLen); void iso7816_write_response_apdu( - const struct ISO7816_Response_APDU* response, + const ISO7816_Response_APDU* response, uint8_t* readerToPcDataBlock, - uint32_t* readerToPcDataBlockLen, - uint8_t* responseDataBuffer, - uint32_t responseDataLen); -#endif //_ISO7816_T0_APDU_H_ + uint32_t* readerToPcDataBlockLen); diff --git a/applications/debug/display_test/view_display_test.c b/applications/debug/display_test/view_display_test.c index d4fe433efe0..31003ae0b33 100644 --- a/applications/debug/display_test/view_display_test.c +++ b/applications/debug/display_test/view_display_test.c @@ -150,8 +150,7 @@ static void view_display_test_exit(void* context) { static void view_display_test_timer_callback(void* context) { ViewDisplayTest* instance = context; - with_view_model( - instance->view, ViewDisplayTestModel * model, { model->counter++; }, true); + with_view_model(instance->view, ViewDisplayTestModel * model, { model->counter++; }, true); } ViewDisplayTest* view_display_test_alloc(void) { diff --git a/applications/debug/event_loop_blink_test/application.fam b/applications/debug/event_loop_blink_test/application.fam new file mode 100644 index 00000000000..7d42ad33902 --- /dev/null +++ b/applications/debug/event_loop_blink_test/application.fam @@ -0,0 +1,10 @@ +App( + appid="event_loop_blink_test", + name="Event Loop Blink Test", + apptype=FlipperAppType.DEBUG, + entry_point="event_loop_blink_test_app", + requires=["input"], + stack_size=1 * 1024, + order=20, + fap_category="Debug", +) diff --git a/applications/debug/event_loop_blink_test/event_loop_blink_test.c b/applications/debug/event_loop_blink_test/event_loop_blink_test.c new file mode 100644 index 00000000000..5c7e0ce558c --- /dev/null +++ b/applications/debug/event_loop_blink_test/event_loop_blink_test.c @@ -0,0 +1,169 @@ +#include +#include + +#include +#include +#include + +#include + +#define TAG "EventLoopBlinkTest" + +#define TIMER_COUNT (6U) + +typedef struct { + FuriEventLoop* event_loop; + FuriMessageQueue* input_queue; + FuriEventLoopTimer* timers[TIMER_COUNT]; +} EventLoopBlinkTestApp; + +static const GpioPin* blink_gpio_pins[] = { + &gpio_ext_pa7, + &gpio_ext_pa6, + &gpio_ext_pa4, + &gpio_ext_pb3, + &gpio_ext_pb2, + &gpio_ext_pc3, +}; + +static_assert(COUNT_OF(blink_gpio_pins) == TIMER_COUNT); + +static const uint32_t timer_intervals[] = { + 25, + 50, + 100, + 200, + 400, + 800, +}; + +static_assert(COUNT_OF(timer_intervals) == TIMER_COUNT); + +static void blink_gpio_init(void) { + for(size_t i = 0; i < TIMER_COUNT; ++i) { + furi_hal_gpio_init_simple(blink_gpio_pins[i], GpioModeOutputPushPull); + furi_hal_gpio_write(blink_gpio_pins[i], false); + } + + furi_hal_gpio_init_simple(&gpio_ext_pc0, GpioModeOutputPushPull); + furi_hal_gpio_write(&gpio_ext_pc0, false); +} + +static void blink_gpio_deinit(void) { + for(size_t i = 0; i < TIMER_COUNT; ++i) { + furi_hal_gpio_write(blink_gpio_pins[i], false); + furi_hal_gpio_init_simple(blink_gpio_pins[i], GpioModeAnalog); + } + + furi_hal_gpio_write(&gpio_ext_pc0, false); + furi_hal_gpio_init_simple(&gpio_ext_pc0, GpioModeAnalog); +} + +static void view_port_draw_callback(Canvas* canvas, void* context) { + UNUSED(context); + canvas_clear(canvas); + elements_text_box( + canvas, + 0, + 0, + canvas_width(canvas), + canvas_height(canvas), + AlignCenter, + AlignCenter, + "\e#Event Loop Timers Test\e#\n" + "Press buttons\n" + "to enable or disable timers\n" + "\e#Exit\e# = long press \e#Back\e#", + false); +} + +static void view_port_input_callback(InputEvent* input_event, void* context) { + EventLoopBlinkTestApp* app = context; + furi_message_queue_put(app->input_queue, input_event, 0); +} + +static bool input_queue_callback(FuriMessageQueue* queue, void* context) { + EventLoopBlinkTestApp* app = context; + + InputEvent event; + FuriStatus status = furi_message_queue_get(queue, &event, 0); + furi_assert(status == FuriStatusOk); + + if(event.type == InputTypeShort) { + const size_t timer_idx = event.key; + furi_assert(timer_idx < TIMER_COUNT); + + FuriEventLoopTimer* timer = app->timers[timer_idx]; + + if(furi_event_loop_timer_is_running(timer)) { + furi_event_loop_timer_stop(timer); + } else { + furi_event_loop_timer_restart(timer); + } + + } else if(event.type == InputTypeLong) { + if(event.key == InputKeyBack) { + furi_event_loop_stop(app->event_loop); + } + } + + return true; +} + +static void blink_timer_callback(void* context) { + const GpioPin* gpio = blink_gpio_pins[(size_t)context]; + furi_hal_gpio_write(gpio, !furi_hal_gpio_read(gpio)); +} + +static void event_loop_tick_callback(void* context) { + UNUSED(context); + furi_hal_gpio_write(&gpio_ext_pc0, !furi_hal_gpio_read(&gpio_ext_pc0)); +} + +int32_t event_loop_blink_test_app(void* arg) { + UNUSED(arg); + + blink_gpio_init(); + + EventLoopBlinkTestApp app; + + app.event_loop = furi_event_loop_alloc(); + app.input_queue = furi_message_queue_alloc(3, sizeof(InputEvent)); + + for(size_t i = 0; i < TIMER_COUNT; ++i) { + app.timers[i] = furi_event_loop_timer_alloc( + app.event_loop, blink_timer_callback, FuriEventLoopTimerTypePeriodic, (void*)i); + furi_event_loop_timer_start(app.timers[i], timer_intervals[i]); + } + + ViewPort* view_port = view_port_alloc(); + view_port_draw_callback_set(view_port, view_port_draw_callback, &app); + view_port_input_callback_set(view_port, view_port_input_callback, &app); + + Gui* gui = furi_record_open(RECORD_GUI); + gui_add_view_port(gui, view_port, GuiLayerFullscreen); + + furi_event_loop_tick_set(app.event_loop, 500, event_loop_tick_callback, &app); + furi_event_loop_message_queue_subscribe( + app.event_loop, app.input_queue, FuriEventLoopEventIn, input_queue_callback, &app); + + furi_event_loop_run(app.event_loop); + + gui_remove_view_port(gui, view_port); + view_port_free(view_port); + + furi_record_close(RECORD_GUI); + + furi_event_loop_message_queue_unsubscribe(app.event_loop, app.input_queue); + furi_message_queue_free(app.input_queue); + + for(size_t i = 0; i < TIMER_COUNT; ++i) { + furi_event_loop_timer_free(app.timers[i]); + } + + furi_event_loop_free(app.event_loop); + + blink_gpio_deinit(); + + return 0; +} diff --git a/applications/debug/expansion_test/expansion_test.c b/applications/debug/expansion_test/expansion_test.c index fc7fb189452..e3bcf4e9c92 100644 --- a/applications/debug/expansion_test/expansion_test.c +++ b/applications/debug/expansion_test/expansion_test.c @@ -40,11 +40,11 @@ #define TAG "ExpansionTest" -#define TEST_DIR_PATH EXT_PATH(TAG) +#define TEST_DIR_PATH EXT_PATH(TAG) #define TEST_FILE_NAME "test.txt" #define TEST_FILE_PATH EXT_PATH(TAG "/" TEST_FILE_NAME) -#define HOST_SERIAL_ID (FuriHalSerialIdLpuart) +#define HOST_SERIAL_ID (FuriHalSerialIdLpuart) #define MODULE_SERIAL_ID (FuriHalSerialIdUsart) #define RECEIVE_BUFFER_SIZE (sizeof(ExpansionFrame) + sizeof(ExpansionFrameChecksum)) diff --git a/applications/debug/file_browser_test/scenes/file_browser_scene_browser.c b/applications/debug/file_browser_test/scenes/file_browser_scene_browser.c index 0bf70e9c63f..6bce58078d3 100644 --- a/applications/debug/file_browser_test/scenes/file_browser_scene_browser.c +++ b/applications/debug/file_browser_test/scenes/file_browser_scene_browser.c @@ -2,7 +2,7 @@ #include #define DEFAULT_PATH "/" -#define EXTENSION "*" +#define EXTENSION "*" bool file_browser_scene_browser_on_event(void* context, SceneManagerEvent event) { UNUSED(context); diff --git a/applications/debug/lfrfid_debug/lfrfid_debug.c b/applications/debug/lfrfid_debug/lfrfid_debug.c index 8776f8b7ad9..13c0b299fa3 100644 --- a/applications/debug/lfrfid_debug/lfrfid_debug.c +++ b/applications/debug/lfrfid_debug/lfrfid_debug.c @@ -78,4 +78,4 @@ int32_t lfrfid_debug_app(void* p) { lfrfid_debug_free(app); return 0; -} \ No newline at end of file +} diff --git a/applications/debug/lfrfid_debug/views/lfrfid_debug_view_tune.c b/applications/debug/lfrfid_debug/views/lfrfid_debug_view_tune.c index ddca372e38f..7b28b66bfe7 100644 --- a/applications/debug/lfrfid_debug/views/lfrfid_debug_view_tune.c +++ b/applications/debug/lfrfid_debug/views/lfrfid_debug_view_tune.c @@ -223,16 +223,14 @@ bool lfrfid_debug_view_tune_is_dirty(LfRfidTuneView* tune_view) { uint32_t lfrfid_debug_view_tune_get_arr(LfRfidTuneView* tune_view) { uint32_t result = false; - with_view_model( - tune_view->view, LfRfidTuneViewModel * model, { result = model->ARR; }, false); + with_view_model(tune_view->view, LfRfidTuneViewModel * model, { result = model->ARR; }, false); return result; } uint32_t lfrfid_debug_view_tune_get_ccr(LfRfidTuneView* tune_view) { uint32_t result = false; - with_view_model( - tune_view->view, LfRfidTuneViewModel * model, { result = model->CCR; }, false); + with_view_model(tune_view->view, LfRfidTuneViewModel * model, { result = model->CCR; }, false); return result; } diff --git a/applications/debug/speaker_debug/speaker_debug.c b/applications/debug/speaker_debug/speaker_debug.c index 82a6fbc7746..3f685ab30d4 100644 --- a/applications/debug/speaker_debug/speaker_debug.c +++ b/applications/debug/speaker_debug/speaker_debug.c @@ -5,6 +5,7 @@ #include #define TAG "SpeakerDebug" + #define CLI_COMMAND "speaker_debug" typedef enum { diff --git a/applications/debug/subghz_test/helpers/subghz_test_types.h b/applications/debug/subghz_test/helpers/subghz_test_types.h index 03be6459ec1..91411bd8d46 100644 --- a/applications/debug/subghz_test/helpers/subghz_test_types.h +++ b/applications/debug/subghz_test/helpers/subghz_test_types.h @@ -4,8 +4,8 @@ #include #define SUBGHZ_TEST_VERSION_APP "0.1" -#define SUBGHZ_TEST_DEVELOPED "SkorP" -#define SUBGHZ_TEST_GITHUB "https://github.com/flipperdevices/flipperzero-firmware" +#define SUBGHZ_TEST_DEVELOPED "SkorP" +#define SUBGHZ_TEST_GITHUB "https://github.com/flipperdevices/flipperzero-firmware" typedef enum { SubGhzTestViewVariableItemList, diff --git a/applications/debug/subghz_test/protocol/math.c b/applications/debug/subghz_test/protocol/math.c index 24202ad1c62..226bb3e7460 100644 --- a/applications/debug/subghz_test/protocol/math.c +++ b/applications/debug/subghz_test/protocol/math.c @@ -241,4 +241,4 @@ uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size) { result ^= message[i]; } return result; -} \ No newline at end of file +} diff --git a/applications/debug/subghz_test/protocol/math.h b/applications/debug/subghz_test/protocol/math.h index dcea3da5faf..bee1bf73307 100644 --- a/applications/debug/subghz_test/protocol/math.h +++ b/applications/debug/subghz_test/protocol/math.h @@ -16,7 +16,7 @@ (value) &= ~(_one << (bit)); \ }) #define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit)) -#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) +#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) #ifdef __cplusplus extern "C" { diff --git a/applications/debug/subghz_test/protocol/princeton_for_testing.c b/applications/debug/subghz_test/protocol/princeton_for_testing.c index 70f323937da..acd4bf56a65 100644 --- a/applications/debug/subghz_test/protocol/princeton_for_testing.c +++ b/applications/debug/subghz_test/protocol/princeton_for_testing.c @@ -9,13 +9,13 @@ * */ -#define SUBGHZ_PT_SHORT 300 -#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3) -#define SUBGHZ_PT_GUARD (SUBGHZ_PT_SHORT * 30) +#define SUBGHZ_PT_SHORT 300 +#define SUBGHZ_PT_LONG (SUBGHZ_PT_SHORT * 3) +#define SUBGHZ_PT_GUARD (SUBGHZ_PT_SHORT * 30) #define SUBGHZ_PT_COUNT_KEY_433 9 -#define SUBGHZ_PT_TIMEOUT_433 900 +#define SUBGHZ_PT_TIMEOUT_433 900 #define SUBGHZ_PT_COUNT_KEY_868 9 -#define SUBGHZ_PT_TIMEOUT_868 14000 +#define SUBGHZ_PT_TIMEOUT_868 14000 #define TAG "SubGhzProtocolPrinceton" diff --git a/applications/debug/uart_echo/uart_echo.c b/applications/debug/uart_echo/uart_echo.c index 0291c9e79d4..595a13ac5ed 100644 --- a/applications/debug/uart_echo/uart_echo.c +++ b/applications/debug/uart_echo/uart_echo.c @@ -9,9 +9,10 @@ #include #include -#define LINES_ON_SCREEN 6 -#define COLUMNS_ON_SCREEN 21 #define TAG "UartEcho" + +#define LINES_ON_SCREEN 6 +#define COLUMNS_ON_SCREEN 21 #define DEFAULT_BAUD_RATE 230400 typedef struct UartDumpModel UartDumpModel; @@ -147,7 +148,7 @@ static void uart_echo_push_to_list(UartDumpModel* model, const char data) { bool new_string_needed = false; if(furi_string_size(model->list[model->line]->text) >= COLUMNS_ON_SCREEN) { new_string_needed = true; - } else if((data == '\n' || data == '\r')) { + } else if(data == '\n' || data == '\r') { // pack line breaks if(model->last_char != '\n' && model->last_char != '\r') { new_string_needed = true; @@ -206,8 +207,7 @@ static int32_t uart_echo_worker(void* context) { } while(length > 0); notification_message(app->notification, &sequence_notification); - with_view_model( - app->view, UartDumpModel * model, { UNUSED(model); }, true); + with_view_model(app->view, UartDumpModel * model, { UNUSED(model); }, true); } if(events & WorkerEventRxIdle) { diff --git a/applications/debug/unit_tests/resources/unit_tests/compress/hsstream.in.bin b/applications/debug/unit_tests/resources/unit_tests/compress/hsstream.in.bin new file mode 100644 index 00000000000..c3bcf5fdaf1 Binary files /dev/null and b/applications/debug/unit_tests/resources/unit_tests/compress/hsstream.in.bin differ diff --git a/applications/debug/unit_tests/resources/unit_tests/compress/test.ths b/applications/debug/unit_tests/resources/unit_tests/compress/test.ths new file mode 100644 index 00000000000..ab7d34af8c2 Binary files /dev/null and b/applications/debug/unit_tests/resources/unit_tests/compress/test.ths differ diff --git a/applications/debug/unit_tests/resources/unit_tests/nfc/Ultralight_C.nfc b/applications/debug/unit_tests/resources/unit_tests/nfc/Ultralight_C.nfc new file mode 100644 index 00000000000..8c125865c35 --- /dev/null +++ b/applications/debug/unit_tests/resources/unit_tests/nfc/Ultralight_C.nfc @@ -0,0 +1,71 @@ +Filetype: Flipper NFC device +Version: 4 +# Device type can be ISO14443-3A, ISO14443-3B, ISO14443-4A, ISO14443-4B, ISO15693-3, FeliCa, NTAG/Ultralight, Mifare Classic, Mifare DESFire, SLIX, ST25TB +Device type: NTAG/Ultralight +# UID is common for all formats +UID: 04 BA FF CA 4D 5D 80 +# ISO14443-3A specific data +ATQA: 00 44 +SAK: 00 +# NTAG/Ultralight specific data +Data format version: 2 +NTAG/Ultralight type: Mifare Ultralight C +Signature: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +Mifare version: 00 00 00 00 00 00 00 00 +Counter 0: 0 +Tearing 0: 00 +Counter 1: 0 +Tearing 1: 00 +Counter 2: 0 +Tearing 2: 00 +Pages total: 48 +Pages read: 48 +Page 0: 04 BA FF C9 +Page 1: CA 4D 5D 80 +Page 2: 5A 48 00 00 +Page 3: E1 10 12 00 +Page 4: 01 03 A0 0C +Page 5: 34 03 00 FE +Page 6: 00 00 00 00 +Page 7: 00 00 00 00 +Page 8: 00 00 00 00 +Page 9: 00 00 00 00 +Page 10: 00 00 BE AF +Page 11: 00 00 00 00 +Page 12: 00 00 00 00 +Page 13: 00 00 00 00 +Page 14: 00 00 00 00 +Page 15: 00 00 00 00 +Page 16: 00 00 00 00 +Page 17: 00 00 00 00 +Page 18: 00 00 00 00 +Page 19: 00 00 00 00 +Page 20: 00 00 00 00 +Page 21: 00 00 00 00 +Page 22: 00 00 00 00 +Page 23: 00 00 00 00 +Page 24: 00 00 00 00 +Page 25: 00 00 00 00 +Page 26: 00 00 00 00 +Page 27: 00 00 00 00 +Page 28: 00 00 00 00 +Page 29: 00 00 00 00 +Page 30: 00 00 00 00 +Page 31: 00 00 00 00 +Page 32: 00 00 00 00 +Page 33: 00 00 00 00 +Page 34: 00 00 00 00 +Page 35: 00 00 00 00 +Page 36: 00 00 00 00 +Page 37: 00 00 00 00 +Page 38: 00 00 00 00 +Page 39: 00 00 00 00 +Page 40: 00 00 00 00 +Page 41: 00 00 00 00 +Page 42: 05 00 00 00 +Page 43: 00 00 00 00 +Page 44: 00 00 00 00 +Page 45: 00 00 00 00 +Page 46: 00 00 00 00 +Page 47: 00 00 00 00 +Failed authentication attempts: 0 diff --git a/applications/debug/unit_tests/test_runner.c b/applications/debug/unit_tests/test_runner.c index 517a4fd24a1..de29e91b39a 100644 --- a/applications/debug/unit_tests/test_runner.c +++ b/applications/debug/unit_tests/test_runner.c @@ -72,7 +72,7 @@ void test_runner_free(TestRunner* instance) { free(instance); } -#define TEST_RUNNER_TMP_DIR EXT_PATH(".tmp") +#define TEST_RUNNER_TMP_DIR EXT_PATH(".tmp") #define TEST_RUNNER_TMP_UNIT_TESTS_DIR TEST_RUNNER_TMP_DIR "/unit_tests" static bool test_runner_run_plugin(TestRunner* instance, const char* path) { diff --git a/applications/debug/unit_tests/test_runner.h b/applications/debug/unit_tests/test_runner.h index 024799ebe5f..43aba8bb15b 100644 --- a/applications/debug/unit_tests/test_runner.h +++ b/applications/debug/unit_tests/test_runner.h @@ -9,4 +9,4 @@ TestRunner* test_runner_alloc(Cli* cli, FuriString* args); void test_runner_free(TestRunner* isntance); -void test_runner_run(TestRunner* isntance); \ No newline at end of file +void test_runner_run(TestRunner* isntance); diff --git a/applications/debug/unit_tests/tests/bt/bt_test.c b/applications/debug/unit_tests/tests/bt/bt_test.c index b65a35bf5a8..a0f189fdbb1 100644 --- a/applications/debug/unit_tests/tests/bt/bt_test.c +++ b/applications/debug/unit_tests/tests/bt/bt_test.c @@ -6,7 +6,7 @@ #include #define BT_TEST_KEY_STORAGE_FILE_PATH EXT_PATH("unit_tests/bt_test.keys") -#define BT_TEST_NVM_RAM_BUFF_SIZE (507 * 4) // The same as in ble NVM storage +#define BT_TEST_NVM_RAM_BUFF_SIZE (507 * 4) // The same as in ble NVM storage typedef struct { Storage* storage; diff --git a/applications/debug/unit_tests/tests/compress/compress_test.c b/applications/debug/unit_tests/tests/compress/compress_test.c index 15984083d1c..8ff774bdf98 100644 --- a/applications/debug/unit_tests/tests/compress/compress_test.c +++ b/applications/debug/unit_tests/tests/compress/compress_test.c @@ -1,6 +1,9 @@ #include "../test.h" // IWYU pragma: keep #include +#include +#include +#include #include #include @@ -56,7 +59,7 @@ static void compress_test_reference_comp_decomp() { furi_record_close(RECORD_STORAGE); uint8_t* temp_buffer = malloc(1024); - Compress* comp = compress_alloc(1024); + Compress* comp = compress_alloc(CompressTypeHeatshrink, &compress_config_heatshrink_default); size_t encoded_size = 0; mu_assert( @@ -98,7 +101,7 @@ static void compress_test_random_comp_decomp() { // We only fill half of the buffer with random data, so if anything goes wrong, there's no overflow static const size_t src_data_size = src_buffer_size / 2; - Compress* comp = compress_alloc(src_buffer_size); + Compress* comp = compress_alloc(CompressTypeHeatshrink, &compress_config_heatshrink_default); uint8_t* src_buff = malloc(src_buffer_size); uint8_t* encoded_buff = malloc(encoded_buffer_size); uint8_t* decoded_buff = malloc(src_buffer_size); @@ -146,9 +149,200 @@ static void compress_test_random_comp_decomp() { compress_free(comp); } +static int32_t hs_unpacker_file_read(void* context, uint8_t* buffer, size_t size) { + File* file = (File*)context; + return storage_file_read(file, buffer, size); +} + +static int32_t hs_unpacker_file_write(void* context, uint8_t* buffer, size_t size) { + File* file = (File*)context; + return storage_file_write(file, buffer, size); +} +/* +Source file was generated with: +```python3 +import random, string +random.seed(1337) +with open("hsstream.out.bin", "wb") as f: + for c in random.choices(string.printable, k=1024): + for _ in range(random.randint(1, 10)): + f.write(c.encode()) +``` + +It was compressed with heatshrink using the following command: +`python3 -m heatshrink2 compress -w 9 -l 4 hsstream.out.bin hsstream.in.bin` +*/ + +#define HSSTREAM_IN COMPRESS_UNIT_TESTS_PATH("hsstream.in.bin") +#define HSSTREAM_OUT COMPRESS_UNIT_TESTS_PATH("hsstream.out.bin") + +static void compress_test_heatshrink_stream() { + Storage* api = furi_record_open(RECORD_STORAGE); + File* comp_file = storage_file_alloc(api); + File* dest_file = storage_file_alloc(api); + + CompressConfigHeatshrink config = { + .window_sz2 = 9, + .lookahead_sz2 = 4, + .input_buffer_sz = 128, + }; + Compress* compress = compress_alloc(CompressTypeHeatshrink, &config); + + do { + storage_simply_remove(api, HSSTREAM_OUT); + + mu_assert( + storage_file_open(comp_file, HSSTREAM_IN, FSAM_READ, FSOM_OPEN_EXISTING), + "Failed to open compressed file"); + + mu_assert( + storage_file_open(dest_file, HSSTREAM_OUT, FSAM_WRITE, FSOM_OPEN_ALWAYS), + "Failed to open decompressed file"); + + mu_assert( + compress_decode_streamed( + compress, hs_unpacker_file_read, comp_file, hs_unpacker_file_write, dest_file), + "Decompression failed"); + + storage_file_close(dest_file); + + unsigned char md5[16]; + FS_Error file_error; + mu_assert( + md5_calc_file(dest_file, HSSTREAM_OUT, md5, &file_error), "Failed to calculate md5"); + + const unsigned char expected_md5[16] = { + 0xa3, + 0x70, + 0xe8, + 0x8b, + 0xa9, + 0x42, + 0x74, + 0xf4, + 0xaa, + 0x12, + 0x8d, + 0x41, + 0xd2, + 0xb6, + 0x71, + 0xc9}; + mu_assert(memcmp(md5, expected_md5, sizeof(md5)) == 0, "MD5 mismatch after decompression"); + + storage_simply_remove(api, HSSTREAM_OUT); + } while(false); + + compress_free(compress); + storage_file_free(comp_file); + storage_file_free(dest_file); + furi_record_close(RECORD_STORAGE); +} + +#define HS_TAR_PATH COMPRESS_UNIT_TESTS_PATH("test.ths") +#define HS_TAR_EXTRACT_PATH COMPRESS_UNIT_TESTS_PATH("tar_out") + +static bool file_counter(const char* name, bool is_dir, void* context) { + UNUSED(name); + UNUSED(is_dir); + int32_t* n_entries = (int32_t*)context; + (*n_entries)++; + return true; +} + +/* +Heatshrink tar file contents and MD5 sums: +file1.txt: 64295676ceed5cce2d0dcac402e4bda4 +file2.txt: 188f67f297eedd7bf3d6a4d3c2fc31c4 +dir/file3.txt: 34d98ad8135ffe502dba374690136d16 +dir/big_file.txt: ee169c1e1791a4d319dbfaefaa850e98 +dir/nested_dir/file4.txt: e099fcb2aaa0672375eaedc549247ee6 +dir/nested_dir/empty_file.txt: d41d8cd98f00b204e9800998ecf8427e + +XOR of all MD5 sums: 92ed5729786d0e1176d047e35f52d376 +*/ + +static void compress_test_heatshrink_tar() { + Storage* api = furi_record_open(RECORD_STORAGE); + + TarArchive* archive = tar_archive_alloc(api); + FuriString* path = furi_string_alloc(); + FileInfo fileinfo; + File* file = storage_file_alloc(api); + + do { + storage_simply_remove_recursive(api, HS_TAR_EXTRACT_PATH); + + mu_assert(storage_simply_mkdir(api, HS_TAR_EXTRACT_PATH), "Failed to create extract dir"); + + mu_assert( + tar_archive_get_mode_for_path(HS_TAR_PATH) == TarOpenModeReadHeatshrink, + "Invalid mode for heatshrink tar"); + + mu_assert( + tar_archive_open(archive, HS_TAR_PATH, TarOpenModeReadHeatshrink), + "Failed to open heatshrink tar"); + + int32_t n_entries = 0; + tar_archive_set_file_callback(archive, file_counter, &n_entries); + + mu_assert( + tar_archive_unpack_to(archive, HS_TAR_EXTRACT_PATH, NULL), + "Failed to unpack heatshrink tar"); + + mu_assert(n_entries == 9, "Invalid number of entries in heatshrink tar"); + + uint8_t md5_total[16] = {0}, md5_file[16]; + + DirWalk* dir_walk = dir_walk_alloc(api); + mu_assert(dir_walk_open(dir_walk, HS_TAR_EXTRACT_PATH), "Failed to open dirwalk"); + while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) { + if(file_info_is_dir(&fileinfo)) { + continue; + } + mu_assert( + md5_calc_file(file, furi_string_get_cstr(path), md5_file, NULL), + "Failed to calc md5"); + + for(size_t i = 0; i < 16; i++) { + md5_total[i] ^= md5_file[i]; + } + } + dir_walk_free(dir_walk); + + static const unsigned char expected_md5[16] = { + 0x92, + 0xed, + 0x57, + 0x29, + 0x78, + 0x6d, + 0x0e, + 0x11, + 0x76, + 0xd0, + 0x47, + 0xe3, + 0x5f, + 0x52, + 0xd3, + 0x76}; + mu_assert(memcmp(md5_total, expected_md5, sizeof(md5_total)) == 0, "MD5 mismatch"); + + storage_simply_remove_recursive(api, HS_TAR_EXTRACT_PATH); + } while(false); + + storage_file_free(file); + furi_string_free(path); + tar_archive_free(archive); + furi_record_close(RECORD_STORAGE); +} + MU_TEST_SUITE(test_compress) { MU_RUN_TEST(compress_test_random_comp_decomp); MU_RUN_TEST(compress_test_reference_comp_decomp); + MU_RUN_TEST(compress_test_heatshrink_stream); + MU_RUN_TEST(compress_test_heatshrink_tar); } int run_minunit_test_compress(void) { diff --git a/applications/debug/unit_tests/tests/expansion/expansion_test.c b/applications/debug/unit_tests/tests/expansion/expansion_test.c index ea4fea28ce9..73d3ff07948 100644 --- a/applications/debug/unit_tests/tests/expansion/expansion_test.c +++ b/applications/debug/unit_tests/tests/expansion/expansion_test.c @@ -5,8 +5,8 @@ #include -#define EXPANSION_TEST_GARBAGE_MAGIC (0xB19AF) -#define EXPANSION_TEST_GARBAGE_BUF_SIZE (0x100U) +#define EXPANSION_TEST_GARBAGE_MAGIC (0xB19AF) +#define EXPANSION_TEST_GARBAGE_BUF_SIZE (0x100U) #define EXPANSION_TEST_GARBAGE_ITERATIONS (100U) MU_TEST(test_expansion_encoded_size) { diff --git a/applications/debug/unit_tests/tests/flipper_format/flipper_format_test.c b/applications/debug/unit_tests/tests/flipper_format/flipper_format_test.c index d26acf57702..888a6644426 100644 --- a/applications/debug/unit_tests/tests/flipper_format/flipper_format_test.c +++ b/applications/debug/unit_tests/tests/flipper_format/flipper_format_test.c @@ -5,7 +5,7 @@ #include "../test.h" // IWYU pragma: keep #define TEST_DIR_NAME EXT_PATH(".tmp/unit_tests/ff") -#define TEST_DIR TEST_DIR_NAME "/" +#define TEST_DIR TEST_DIR_NAME "/" static const char* test_filetype = "Flipper File test"; static const uint32_t test_version = 666; diff --git a/applications/debug/unit_tests/tests/furi_hal/furi_hal_tests.c b/applications/debug/unit_tests/tests/furi_hal/furi_hal_tests.c index 4b515206c9c..aaaa031e45e 100644 --- a/applications/debug/unit_tests/tests/furi_hal/furi_hal_tests.c +++ b/applications/debug/unit_tests/tests/furi_hal/furi_hal_tests.c @@ -5,11 +5,11 @@ #include #include "../test.h" // IWYU pragma: keep -#define DATA_SIZE 4 -#define EEPROM_ADDRESS 0b10101000 -#define EEPROM_ADDRESS_HIGH (EEPROM_ADDRESS | 0b10) -#define EEPROM_SIZE 512 -#define EEPROM_PAGE_SIZE 16 +#define DATA_SIZE 4 +#define EEPROM_ADDRESS 0b10101000 +#define EEPROM_ADDRESS_HIGH (EEPROM_ADDRESS | 0b10) +#define EEPROM_SIZE 512 +#define EEPROM_PAGE_SIZE 16 #define EEPROM_WRITE_DELAY_MS 6 static void furi_hal_i2c_int_setup(void) { @@ -74,7 +74,8 @@ MU_TEST(furi_hal_i2c_int_3b) { DATA_SIZE - 1, LP5562_I2C_TIMEOUT); mu_assert(ret, "4 rx failed"); - for(size_t i = 0; i < DATA_SIZE; i++) mu_assert(data_many[i] != 0, "4 invalid data_many"); + for(size_t i = 0; i < DATA_SIZE; i++) + mu_assert(data_many[i] != 0, "4 invalid data_many"); ret = furi_hal_i2c_tx( &furi_hal_i2c_handle_power, LP5562_ADDRESS, data_many, DATA_SIZE, LP5562_I2C_TIMEOUT); @@ -90,7 +91,8 @@ MU_TEST(furi_hal_i2c_int_3b) { DATA_SIZE - 1, LP5562_I2C_TIMEOUT); mu_assert(ret, "7 rx failed"); - for(size_t i = 0; i < DATA_SIZE; i++) mu_assert(data_many[i] != 0, "7 invalid data_many"); + for(size_t i = 0; i < DATA_SIZE; i++) + mu_assert(data_many[i] != 0, "7 invalid data_many"); } MU_TEST(furi_hal_i2c_int_1b_fail) { diff --git a/applications/debug/unit_tests/tests/infrared/infrared_test.c b/applications/debug/unit_tests/tests/infrared/infrared_test.c index cf6a1322002..e64b630b2e9 100644 --- a/applications/debug/unit_tests/tests/infrared/infrared_test.c +++ b/applications/debug/unit_tests/tests/infrared/infrared_test.c @@ -4,7 +4,7 @@ #include #include "../test.h" // IWYU pragma: keep -#define IR_TEST_FILES_DIR EXT_PATH("unit_tests/infrared/") +#define IR_TEST_FILES_DIR EXT_PATH("unit_tests/infrared/") #define IR_TEST_FILE_PREFIX "test_" #define IR_TEST_FILE_SUFFIX ".irtest" diff --git a/applications/debug/unit_tests/tests/lfrfid/lfrfid_protocols.c b/applications/debug/unit_tests/tests/lfrfid/lfrfid_protocols.c index 8bf7753c0e8..032fe115e33 100644 --- a/applications/debug/unit_tests/tests/lfrfid/lfrfid_protocols.c +++ b/applications/debug/unit_tests/tests/lfrfid/lfrfid_protocols.c @@ -6,9 +6,8 @@ #define LF_RFID_READ_TIMING_MULTIPLIER 8 -#define EM_TEST_DATA \ - { 0x58, 0x00, 0x85, 0x64, 0x02 } -#define EM_TEST_DATA_SIZE 5 +#define EM_TEST_DATA {0x58, 0x00, 0x85, 0x64, 0x02} +#define EM_TEST_DATA_SIZE 5 #define EM_TEST_EMULATION_TIMINGS_COUNT (64 * 2) const int8_t em_test_timings[EM_TEST_EMULATION_TIMINGS_COUNT] = { @@ -21,9 +20,8 @@ const int8_t em_test_timings[EM_TEST_EMULATION_TIMINGS_COUNT] = { -32, 32, 32, -32, -32, 32, -32, 32, -32, 32, -32, 32, -32, 32, }; -#define HID10301_TEST_DATA \ - { 0x8D, 0x48, 0xA8 } -#define HID10301_TEST_DATA_SIZE 3 +#define HID10301_TEST_DATA {0x8D, 0x48, 0xA8} +#define HID10301_TEST_DATA_SIZE 3 #define HID10301_TEST_EMULATION_TIMINGS_COUNT (541 * 2) const int8_t hid10301_test_timings[HID10301_TEST_EMULATION_TIMINGS_COUNT] = { @@ -71,9 +69,8 @@ const int8_t hid10301_test_timings[HID10301_TEST_EMULATION_TIMINGS_COUNT] = { 5, -5, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, 4, -4, }; -#define IOPROX_XSF_TEST_DATA \ - { 0x65, 0x01, 0x05, 0x39 } -#define IOPROX_XSF_TEST_DATA_SIZE 4 +#define IOPROX_XSF_TEST_DATA {0x65, 0x01, 0x05, 0x39} +#define IOPROX_XSF_TEST_DATA_SIZE 4 #define IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT (468 * 2) const int8_t ioprox_xsf_test_timings[IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT] = { @@ -116,9 +113,8 @@ const int8_t ioprox_xsf_test_timings[IOPROX_XSF_TEST_EMULATION_TIMINGS_COUNT] = }; #define INDALA26_EMULATION_TIMINGS_COUNT (1024 * 2) -#define INDALA26_TEST_DATA \ - { 0x3B, 0x73, 0x64, 0xA8 } -#define INDALA26_TEST_DATA_SIZE 4 +#define INDALA26_TEST_DATA {0x3B, 0x73, 0x64, 0xA8} +#define INDALA26_TEST_DATA_SIZE 4 const int8_t indala26_test_timings[INDALA26_EMULATION_TIMINGS_COUNT] = { 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, @@ -209,9 +205,8 @@ const int8_t indala26_test_timings[INDALA26_EMULATION_TIMINGS_COUNT] = { -1, 1, -1, 1, -1, 1, -1, 1, }; -#define FDXB_TEST_DATA \ - { 0x44, 0x88, 0x23, 0xF2, 0x5A, 0x6F, 0x00, 0x01, 0x00, 0x00, 0x00 } -#define FDXB_TEST_DATA_SIZE 11 +#define FDXB_TEST_DATA {0x44, 0x88, 0x23, 0xF2, 0x5A, 0x6F, 0x00, 0x01, 0x00, 0x00, 0x00} +#define FDXB_TEST_DATA_SIZE 11 #define FDXB_TEST_EMULATION_TIMINGS_COUNT (206) const int8_t fdxb_test_timings[FDXB_TEST_EMULATION_TIMINGS_COUNT] = { diff --git a/applications/debug/unit_tests/tests/minunit.h b/applications/debug/unit_tests/tests/minunit.h index 083db5a9a9a..9310cfc9c9c 100644 --- a/applications/debug/unit_tests/tests/minunit.h +++ b/applications/debug/unit_tests/tests/minunit.h @@ -71,7 +71,7 @@ extern "C" { /* Maximum length of last message */ #define MINUNIT_MESSAGE_LEN 1024 /* Accuracy with which floats are compared */ -#define MINUNIT_EPSILON 1E-12 +#define MINUNIT_EPSILON 1E-12 #include "minunit_vars_ex.h" @@ -84,9 +84,9 @@ void minunit_print_fail(const char* error); void minunit_printf_warning(const char* format, ...); /* Definitions */ -#define MU_TEST(method_name) static void method_name(void) +#define MU_TEST(method_name) static void method_name(void) #define MU_TEST_1(method_name, arg_1) static void method_name(arg_1) -#define MU_TEST_SUITE(suite_name) static void suite_name(void) +#define MU_TEST_SUITE(suite_name) static void suite_name(void) #define MU__SAFE_BLOCK(block) \ do { \ diff --git a/applications/debug/unit_tests/tests/nfc/nfc_test.c b/applications/debug/unit_tests/tests/nfc/nfc_test.c index 1e440707643..0898ac8edac 100644 --- a/applications/debug/unit_tests/tests/nfc/nfc_test.c +++ b/applications/debug/unit_tests/tests/nfc/nfc_test.c @@ -30,7 +30,7 @@ #define TAG "NfcTest" -#define NFC_TEST_NFC_DEV_PATH EXT_PATH("unit_tests/nfc/nfc_device_test.nfc") +#define NFC_TEST_NFC_DEV_PATH EXT_PATH("unit_tests/nfc/nfc_device_test.nfc") #define NFC_APP_MF_CLASSIC_DICT_UNIT_TEST_PATH EXT_PATH("unit_tests/mf_dict.nfc") #define NFC_TEST_FLAG_WORKER_DONE (1) @@ -286,6 +286,10 @@ MU_TEST(mf_ultralight_21_reader) { mf_ultralight_reader_test(EXT_PATH("unit_tests/nfc/Ultralight_21.nfc")); } +MU_TEST(mf_ultralight_c_reader) { + mf_ultralight_reader_test(EXT_PATH("unit_tests/nfc/Ultralight_C.nfc")); +} + MU_TEST(ntag_215_reader) { mf_ultralight_reader_test(EXT_PATH("unit_tests/nfc/Ntag215.nfc")); } @@ -828,6 +832,7 @@ MU_TEST_SUITE(nfc) { MU_RUN_TEST(ntag_215_reader); MU_RUN_TEST(ntag_216_reader); MU_RUN_TEST(ntag_213_locked_reader); + MU_RUN_TEST(mf_ultralight_c_reader); MU_RUN_TEST(mf_ultralight_write); diff --git a/applications/debug/unit_tests/tests/rpc/rpc_test.c b/applications/debug/unit_tests/tests/rpc/rpc_test.c index f5b9e762d7b..63ea706ed66 100644 --- a/applications/debug/unit_tests/tests/rpc/rpc_test.c +++ b/applications/debug/unit_tests/tests/rpc/rpc_test.c @@ -43,14 +43,15 @@ typedef struct { static RpcSessionContext rpc_session[TEST_RPC_SESSIONS]; #define TAG "UnitTestsRpc" + #define MAX_RECEIVE_OUTPUT_TIMEOUT 3000 -#define MAX_NAME_LENGTH 255 -#define MAX_DATA_SIZE 512u // have to be exact as in rpc_storage.c -#define TEST_DIR_NAME EXT_PATH(".tmp/unit_tests/rpc") -#define TEST_DIR TEST_DIR_NAME "/" -#define MD5SUM_SIZE 16 +#define MAX_NAME_LENGTH 255 +#define MAX_DATA_SIZE 512u // have to be exact as in rpc_storage.c +#define TEST_DIR_NAME EXT_PATH(".tmp/unit_tests/rpc") +#define TEST_DIR TEST_DIR_NAME "/" +#define MD5SUM_SIZE 16 -#define PING_REQUEST 0 +#define PING_REQUEST 0 #define PING_RESPONSE 1 #define WRITE_REQUEST 0 #define READ_RESPONSE 1 @@ -554,7 +555,7 @@ static bool test_rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_ time_left = MAX(time_left, 0); bytes_received = furi_stream_buffer_receive(session_context->output_stream, buf, count, time_left); - return (count == bytes_received); + return count == bytes_received; } static void @@ -971,7 +972,7 @@ MU_TEST(test_storage_info) { } #define TEST_DIR_STAT_NAME TEST_DIR "stat_dir" -#define TEST_DIR_STAT TEST_DIR_STAT_NAME "/" +#define TEST_DIR_STAT TEST_DIR_STAT_NAME "/" MU_TEST(test_storage_stat) { test_create_dir(TEST_DIR_STAT_NAME); test_create_file(TEST_DIR_STAT "empty.txt", 0); @@ -1212,7 +1213,7 @@ static void test_storage_delete_run( } #define TEST_DIR_RMRF_NAME TEST_DIR "rmrf_test" -#define TEST_DIR_RMRF TEST_DIR_RMRF_NAME "/" +#define TEST_DIR_RMRF TEST_DIR_RMRF_NAME "/" MU_TEST(test_storage_delete_recursive) { test_create_dir(TEST_DIR_RMRF_NAME); diff --git a/applications/debug/unit_tests/tests/storage/storage_test.c b/applications/debug/unit_tests/tests/storage/storage_test.c index 65a25cf4943..f317fbf6803 100644 --- a/applications/debug/unit_tests/tests/storage/storage_test.c +++ b/applications/debug/unit_tests/tests/storage/storage_test.c @@ -9,7 +9,7 @@ #define UNIT_TESTS_PATH(path) EXT_PATH("unit_tests/" path) #define STORAGE_LOCKED_FILE EXT_PATH("locked_file.test") -#define STORAGE_LOCKED_DIR STORAGE_INT_PATH_PREFIX +#define STORAGE_LOCKED_DIR STORAGE_INT_PATH_PREFIX #define STORAGE_TEST_DIR UNIT_TESTS_PATH("test_dir") diff --git a/applications/debug/unit_tests/tests/subghz/subghz_test.c b/applications/debug/unit_tests/tests/subghz/subghz_test.c index 6a41293592a..90e6d429b2e 100644 --- a/applications/debug/unit_tests/tests/subghz/subghz_test.c +++ b/applications/debug/unit_tests/tests/subghz/subghz_test.c @@ -11,13 +11,14 @@ #include #define TAG "SubGhzTest" -#define KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes") -#define CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo") -#define NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s") -#define ALUTECH_AT_4N_DIR_NAME EXT_PATH("subghz/assets/alutech_at_4n") -#define TEST_RANDOM_DIR_NAME EXT_PATH("unit_tests/subghz/test_random_raw.sub") + +#define KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes") +#define CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo") +#define NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s") +#define ALUTECH_AT_4N_DIR_NAME EXT_PATH("subghz/assets/alutech_at_4n") +#define TEST_RANDOM_DIR_NAME EXT_PATH("unit_tests/subghz/test_random_raw.sub") #define TEST_RANDOM_COUNT_PARSE 329 -#define TEST_TIMEOUT 10000 +#define TEST_TIMEOUT 10000 static SubGhzEnvironment* environment_handler; static SubGhzReceiver* receiver_handler; diff --git a/applications/debug/unit_tests/tests/test_api.h b/applications/debug/unit_tests/tests/test_api.h index 55b9f7885b9..fc2c7479c16 100644 --- a/applications/debug/unit_tests/tests/test_api.h +++ b/applications/debug/unit_tests/tests/test_api.h @@ -2,7 +2,7 @@ #include -#define APPID "UnitTest" +#define APPID "UnitTest" #define API_VERSION (0u) typedef struct { diff --git a/applications/debug/usb_mouse/usb_mouse.c b/applications/debug/usb_mouse/usb_mouse.c index 2b7710451f4..e322a58ae2e 100644 --- a/applications/debug/usb_mouse/usb_mouse.c +++ b/applications/debug/usb_mouse/usb_mouse.c @@ -4,7 +4,7 @@ #include #define MOUSE_MOVE_SHORT 5 -#define MOUSE_MOVE_LONG 20 +#define MOUSE_MOVE_LONG 20 typedef enum { EventTypeInput, diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index 429a4b3a41a..ae355639650 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -21,11 +21,11 @@ #define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO (&gpio_ext_pb2) /* DMA Channels definition */ -#define SUBGHZ_DEVICE_CC1101_EXT_DMA (DMA2) +#define SUBGHZ_DEVICE_CC1101_EXT_DMA (DMA2) #define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL (LL_DMA_CHANNEL_3) #define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_CHANNEL (LL_DMA_CHANNEL_4) #define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_CHANNEL (LL_DMA_CHANNEL_5) -#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ (FuriHalInterruptIdDma2Ch3) +#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ (FuriHalInterruptIdDma2Ch3) #define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF \ SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL #define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF \ @@ -365,7 +365,7 @@ bool subghz_device_cc1101_ext_is_rx_data_crc_valid(void) { cc1101_read_reg( subghz_device_cc1101_ext->spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data); furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle); - if(((data[0] >> 7) & 0x01)) { + if((data[0] >> 7) & 0x01) { return true; } else { return false; @@ -826,9 +826,8 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb } bool subghz_device_cc1101_ext_is_async_tx_complete(void) { - return ( - (subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx) && - (LL_TIM_GetAutoReload(TIM17) == 0)); + return (subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx) && + (LL_TIM_GetAutoReload(TIM17) == 0); } void subghz_device_cc1101_ext_stop_async_tx(void) { diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c index 68f2b8aff9c..eef92dbe84e 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.c @@ -107,4 +107,4 @@ static const FlipperAppPluginDescriptor subghz_device_cc1101_ext_descriptor = { const FlipperAppPluginDescriptor* subghz_device_cc1101_ext_ep(void) { return &subghz_device_cc1101_ext_descriptor; -} \ No newline at end of file +} diff --git a/applications/examples/example_ble_beacon/ble_beacon_app.c b/applications/examples/example_ble_beacon/ble_beacon_app.c index af213360278..faa3feb9154 100644 --- a/applications/examples/example_ble_beacon/ble_beacon_app.c +++ b/applications/examples/example_ble_beacon/ble_beacon_app.c @@ -5,7 +5,7 @@ #include -#define TAG "ble_beacon_app" +#define TAG "BleBeaconApp" static bool ble_beacon_app_custom_event_callback(void* context, uint32_t event) { furi_assert(context); diff --git a/applications/examples/example_plugins/plugin_interface.h b/applications/examples/example_plugins/plugin_interface.h index fadb9089fef..50c26ba7a6d 100644 --- a/applications/examples/example_plugins/plugin_interface.h +++ b/applications/examples/example_plugins/plugin_interface.h @@ -6,7 +6,7 @@ */ #pragma once -#define PLUGIN_APP_ID "example_plugins" +#define PLUGIN_APP_ID "example_plugins" #define PLUGIN_API_VERSION 1 typedef struct { diff --git a/applications/examples/example_plugins_advanced/app_api_interface.h b/applications/examples/example_plugins_advanced/app_api_interface.h index d0db44c4aa0..be4f78930d9 100644 --- a/applications/examples/example_plugins_advanced/app_api_interface.h +++ b/applications/examples/example_plugins_advanced/app_api_interface.h @@ -6,4 +6,4 @@ * Resolver interface with private application's symbols. * Implementation is contained in app_api_table.c */ -extern const ElfApiInterface* const application_api_interface; \ No newline at end of file +extern const ElfApiInterface* const application_api_interface; diff --git a/applications/examples/example_plugins_advanced/app_api_table_i.h b/applications/examples/example_plugins_advanced/app_api_table_i.h index 17cc8be5f93..1abd85cd45a 100644 --- a/applications/examples/example_plugins_advanced/app_api_table_i.h +++ b/applications/examples/example_plugins_advanced/app_api_table_i.h @@ -10,4 +10,4 @@ static constexpr auto app_api_table = sort(create_array_t( API_METHOD(app_api_accumulator_get, uint32_t, ()), API_METHOD(app_api_accumulator_add, void, (uint32_t)), API_METHOD(app_api_accumulator_sub, void, (uint32_t)), - API_METHOD(app_api_accumulator_mul, void, (uint32_t)))); \ No newline at end of file + API_METHOD(app_api_accumulator_mul, void, (uint32_t)))); diff --git a/applications/examples/example_plugins_advanced/plugin_interface.h b/applications/examples/example_plugins_advanced/plugin_interface.h index 4cef7567bc1..721e7c64617 100644 --- a/applications/examples/example_plugins_advanced/plugin_interface.h +++ b/applications/examples/example_plugins_advanced/plugin_interface.h @@ -6,7 +6,7 @@ */ #pragma once -#define PLUGIN_APP_ID "example_plugins_advanced" +#define PLUGIN_APP_ID "example_plugins_advanced" #define PLUGIN_API_VERSION 1 typedef struct { diff --git a/applications/examples/example_thermo/example_thermo.c b/applications/examples/example_thermo/example_thermo.c index dafe5688631..895f05ce76f 100644 --- a/applications/examples/example_thermo/example_thermo.c +++ b/applications/examples/example_thermo/example_thermo.c @@ -25,15 +25,15 @@ #include #define UPDATE_PERIOD_MS 1000UL -#define TEXT_STORE_SIZE 64U +#define TEXT_STORE_SIZE 64U -#define DS18B20_CMD_SKIP_ROM 0xccU -#define DS18B20_CMD_CONVERT 0x44U +#define DS18B20_CMD_SKIP_ROM 0xccU +#define DS18B20_CMD_CONVERT 0x44U #define DS18B20_CMD_READ_SCRATCHPAD 0xbeU -#define DS18B20_CFG_RESOLUTION_POS 5U +#define DS18B20_CFG_RESOLUTION_POS 5U #define DS18B20_CFG_RESOLUTION_MASK 0x03U -#define DS18B20_DECIMAL_PART_MASK 0x0fU +#define DS18B20_DECIMAL_PART_MASK 0x0fU #define DS18B20_SIGN_MASK 0xf0U diff --git a/applications/main/archive/helpers/archive_browser.c b/applications/main/archive/helpers/archive_browser.c index ea9cdbdc353..c34c505a23e 100644 --- a/applications/main/archive/helpers/archive_browser.c +++ b/applications/main/archive/helpers/archive_browser.c @@ -360,7 +360,7 @@ bool archive_is_home(ArchiveBrowserView* browser) { } const char* default_path = archive_get_default_path(archive_get_tab(browser)); - return (furi_string_cmp_str(browser->path, default_path) == 0); + return furi_string_cmp_str(browser->path, default_path) == 0; } const char* archive_get_name(ArchiveBrowserView* browser) { diff --git a/applications/main/archive/helpers/archive_browser.h b/applications/main/archive/helpers/archive_browser.h index 0a977b647cb..02cf8d708c9 100644 --- a/applications/main/archive/helpers/archive_browser.h +++ b/applications/main/archive/helpers/archive_browser.h @@ -3,8 +3,8 @@ #include "../archive_i.h" #include -#define TAB_RIGHT InputKeyRight // Default tab switch direction -#define TAB_DEFAULT ArchiveTabFavorites // Start tab +#define TAB_RIGHT InputKeyRight // Default tab switch direction +#define TAB_DEFAULT ArchiveTabFavorites // Start tab #define FILE_LIST_BUF_LEN 50 static const char* tab_default_paths[] = { @@ -62,7 +62,7 @@ static inline const char* archive_get_default_path(ArchiveTabEnum tab) { } inline bool archive_is_known_app(ArchiveFileTypeEnum type) { - return (type != ArchiveFileTypeFolder && type != ArchiveFileTypeUnknown); + return type != ArchiveFileTypeFolder && type != ArchiveFileTypeUnknown; } bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx); diff --git a/applications/main/archive/helpers/archive_favorites.h b/applications/main/archive/helpers/archive_favorites.h index db89433782a..64ffcdd7bd3 100644 --- a/applications/main/archive/helpers/archive_favorites.h +++ b/applications/main/archive/helpers/archive_favorites.h @@ -2,7 +2,7 @@ #include -#define ARCHIVE_FAV_PATH ANY_PATH("favorites.txt") +#define ARCHIVE_FAV_PATH ANY_PATH("favorites.txt") #define ARCHIVE_FAV_TEMP_PATH ANY_PATH("favorites.tmp") uint16_t archive_favorites_count(void* context); diff --git a/applications/main/archive/scenes/archive_scene_browser.c b/applications/main/archive/scenes/archive_scene_browser.c index c08deb60a26..d0959503738 100644 --- a/applications/main/archive/scenes/archive_scene_browser.c +++ b/applications/main/archive/scenes/archive_scene_browser.c @@ -8,7 +8,7 @@ #define TAG "ArchiveSceneBrowser" -#define SCENE_STATE_DEFAULT (0) +#define SCENE_STATE_DEFAULT (0) #define SCENE_STATE_NEED_REFRESH (1) static const char* archive_get_flipper_app_name(ArchiveFileTypeEnum file_type) { diff --git a/applications/main/archive/scenes/archive_scene_delete.c b/applications/main/archive/scenes/archive_scene_delete.c index cbeb4824d72..e12941970a5 100644 --- a/applications/main/archive/scenes/archive_scene_delete.c +++ b/applications/main/archive/scenes/archive_scene_delete.c @@ -5,7 +5,7 @@ #include "toolbox/path.h" #define SCENE_DELETE_CUSTOM_EVENT (0UL) -#define MAX_TEXT_INPUT_LEN 22 +#define MAX_TEXT_INPUT_LEN 22 void archive_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) { furi_assert(context); diff --git a/applications/main/archive/scenes/archive_scene_rename.c b/applications/main/archive/scenes/archive_scene_rename.c index 7b6552dfba2..dd6ba0a6e69 100644 --- a/applications/main/archive/scenes/archive_scene_rename.c +++ b/applications/main/archive/scenes/archive_scene_rename.c @@ -6,7 +6,7 @@ #include "toolbox/path.h" #define SCENE_RENAME_CUSTOM_EVENT (0UL) -#define MAX_TEXT_INPUT_LEN 22 +#define MAX_TEXT_INPUT_LEN 22 void archive_scene_rename_text_input_callback(void* context) { ArchiveApp* archive = (ArchiveApp*)context; diff --git a/applications/main/archive/views/archive_browser_view.c b/applications/main/archive/views/archive_browser_view.c index de06b968409..9e0918373ec 100644 --- a/applications/main/archive/views/archive_browser_view.c +++ b/applications/main/archive/views/archive_browser_view.c @@ -5,7 +5,7 @@ #include "../helpers/archive_browser.h" #define SCROLL_INTERVAL (333) -#define SCROLL_DELAY (2) +#define SCROLL_DELAY (2) static const char* ArchiveTabNames[] = { [ArchiveTabFavorites] = "Favorites", diff --git a/applications/main/archive/views/archive_browser_view.h b/applications/main/archive/views/archive_browser_view.h index 5fbdaf973c8..e7b8ee40f63 100644 --- a/applications/main/archive/views/archive_browser_view.h +++ b/applications/main/archive/views/archive_browser_view.h @@ -11,12 +11,12 @@ #include #include -#define MAX_LEN_PX 110 +#define MAX_LEN_PX 110 #define MAX_NAME_LEN 255 -#define MAX_EXT_LEN 6 +#define MAX_EXT_LEN 6 #define FRAME_HEIGHT 12 -#define MENU_ITEMS 4u -#define MOVE_OFFSET 5u +#define MENU_ITEMS 4u +#define MOVE_OFFSET 5u typedef enum { ArchiveTabFavorites, diff --git a/applications/main/bad_usb/bad_usb_app.c b/applications/main/bad_usb/bad_usb_app.c index 0cf7f192488..0f10d60d8fb 100644 --- a/applications/main/bad_usb/bad_usb_app.c +++ b/applications/main/bad_usb/bad_usb_app.c @@ -5,9 +5,9 @@ #include #include -#define BAD_USB_SETTINGS_PATH BAD_USB_APP_BASE_FOLDER "/.badusb.settings" -#define BAD_USB_SETTINGS_FILE_TYPE "Flipper BadUSB Settings File" -#define BAD_USB_SETTINGS_VERSION 1 +#define BAD_USB_SETTINGS_PATH BAD_USB_APP_BASE_FOLDER "/.badusb.settings" +#define BAD_USB_SETTINGS_FILE_TYPE "Flipper BadUSB Settings File" +#define BAD_USB_SETTINGS_VERSION 1 #define BAD_USB_SETTINGS_DEFAULT_LAYOUT BAD_USB_APP_PATH_LAYOUT_FOLDER "/en-US.kl" static bool bad_usb_app_custom_event_callback(void* context, uint32_t event) { diff --git a/applications/main/bad_usb/bad_usb_app_i.h b/applications/main/bad_usb/bad_usb_app_i.h index c12f9ac751c..34b3db15cd6 100644 --- a/applications/main/bad_usb/bad_usb_app_i.h +++ b/applications/main/bad_usb/bad_usb_app_i.h @@ -16,10 +16,10 @@ #include "views/bad_usb_view.h" #include -#define BAD_USB_APP_BASE_FOLDER ANY_PATH("badusb") +#define BAD_USB_APP_BASE_FOLDER ANY_PATH("badusb") #define BAD_USB_APP_PATH_LAYOUT_FOLDER BAD_USB_APP_BASE_FOLDER "/assets/layouts" -#define BAD_USB_APP_SCRIPT_EXTENSION ".txt" -#define BAD_USB_APP_LAYOUT_EXTENSION ".kl" +#define BAD_USB_APP_SCRIPT_EXTENSION ".txt" +#define BAD_USB_APP_LAYOUT_EXTENSION ".kl" typedef enum { BadUsbAppErrorNoFiles, @@ -49,4 +49,4 @@ typedef enum { BadUsbAppViewError, BadUsbAppViewWork, BadUsbAppViewConfig, -} BadUsbAppView; \ No newline at end of file +} BadUsbAppView; diff --git a/applications/main/bad_usb/helpers/bad_usb_hid.c b/applications/main/bad_usb/helpers/bad_usb_hid.c index 289e3ae8c1a..5d7076314af 100644 --- a/applications/main/bad_usb/helpers/bad_usb_hid.c +++ b/applications/main/bad_usb/helpers/bad_usb_hid.c @@ -223,4 +223,4 @@ void bad_usb_hid_ble_remove_pairing(void) { furi_check(bt_profile_restore_default(bt)); furi_record_close(RECORD_BT); -} \ No newline at end of file +} diff --git a/applications/main/bad_usb/helpers/ducky_script.c b/applications/main/bad_usb/helpers/ducky_script.c index 077b1c37b8e..2ee66955c58 100644 --- a/applications/main/bad_usb/helpers/ducky_script.c +++ b/applications/main/bad_usb/helpers/ducky_script.c @@ -9,6 +9,7 @@ #include #define TAG "BadUsb" + #define WORKER_TAG TAG "Worker" #define BADUSB_ASCII_TO_KEY(script, x) \ @@ -46,7 +47,7 @@ uint32_t ducky_get_command_len(const char* line) { } bool ducky_is_line_end(const char chr) { - return ((chr == ' ') || (chr == '\0') || (chr == '\r') || (chr == '\n')); + return (chr == ' ') || (chr == '\0') || (chr == '\r') || (chr == '\n'); } uint16_t ducky_get_keycode(BadUsbScript* bad_usb, const char* param, bool accept_chars) { @@ -56,7 +57,7 @@ uint16_t ducky_get_keycode(BadUsbScript* bad_usb, const char* param, bool accept } if((accept_chars) && (strlen(param) > 0)) { - return (BADUSB_ASCII_TO_KEY(bad_usb, param[0]) & 0xFF); + return BADUSB_ASCII_TO_KEY(bad_usb, param[0]) & 0xFF; } return 0; } @@ -305,7 +306,7 @@ static int32_t ducky_script_execute_next(BadUsbScript* bad_usb, File* script_fil FURI_LOG_E(WORKER_TAG, "Unknown command at line %zu", bad_usb->st.line_cur - 1U); return SCRIPT_STATE_ERROR; } else { - return (delay_val + bad_usb->defdelay); + return delay_val + bad_usb->defdelay; } } @@ -344,7 +345,7 @@ static int32_t ducky_script_execute_next(BadUsbScript* bad_usb, File* script_fil FURI_LOG_E(WORKER_TAG, "Unknown command at line %zu", bad_usb->st.line_cur); return SCRIPT_STATE_ERROR; } else { - return (delay_val + bad_usb->defdelay); + return delay_val + bad_usb->defdelay; } } else { furi_string_push_back(bad_usb->line, bad_usb->file_buf[i]); diff --git a/applications/main/bad_usb/helpers/ducky_script_commands.c b/applications/main/bad_usb/helpers/ducky_script_commands.c index 7f9a48fb20b..79dcdd531de 100644 --- a/applications/main/bad_usb/helpers/ducky_script_commands.c +++ b/applications/main/bad_usb/helpers/ducky_script_commands.c @@ -216,6 +216,7 @@ static const DuckyCmd ducky_commands[] = { }; #define TAG "BadUsb" + #define WORKER_TAG TAG "Worker" int32_t ducky_execute_cmd(BadUsbScript* bad_usb, const char* line) { @@ -231,7 +232,7 @@ int32_t ducky_execute_cmd(BadUsbScript* bad_usb, const char* line) { if(ducky_commands[i].callback == NULL) { return 0; } else { - return ((ducky_commands[i].callback)(bad_usb, line, ducky_commands[i].param)); + return (ducky_commands[i].callback)(bad_usb, line, ducky_commands[i].param); } } } diff --git a/applications/main/bad_usb/helpers/ducky_script_i.h b/applications/main/bad_usb/helpers/ducky_script_i.h index bbafdccb6a0..464c8a72bf0 100644 --- a/applications/main/bad_usb/helpers/ducky_script_i.h +++ b/applications/main/bad_usb/helpers/ducky_script_i.h @@ -9,10 +9,10 @@ extern "C" { #include "ducky_script.h" #include "bad_usb_hid.h" -#define SCRIPT_STATE_ERROR (-1) -#define SCRIPT_STATE_END (-2) -#define SCRIPT_STATE_NEXT_LINE (-3) -#define SCRIPT_STATE_CMD_UNKNOWN (-4) +#define SCRIPT_STATE_ERROR (-1) +#define SCRIPT_STATE_END (-2) +#define SCRIPT_STATE_NEXT_LINE (-3) +#define SCRIPT_STATE_CMD_UNKNOWN (-4) #define SCRIPT_STATE_STRING_START (-5) #define SCRIPT_STATE_WAIT_FOR_BTN (-6) diff --git a/applications/main/gpio/usb_uart_bridge.c b/applications/main/gpio/usb_uart_bridge.c index 8dff09cb808..f6e68b10966 100644 --- a/applications/main/gpio/usb_uart_bridge.c +++ b/applications/main/gpio/usb_uart_bridge.c @@ -10,11 +10,11 @@ #include #include -#define USB_CDC_PKT_LEN CDC_DATA_SZ +#define USB_CDC_PKT_LEN CDC_DATA_SZ #define USB_UART_RX_BUF_SIZE (USB_CDC_PKT_LEN * 5) -#define USB_CDC_BIT_DTR (1 << 0) -#define USB_CDC_BIT_RTS (1 << 1) +#define USB_CDC_BIT_DTR (1 << 0) +#define USB_CDC_BIT_RTS (1 << 1) #define USB_USART_DE_RE_PIN &gpio_ext_pa4 static const GpioPin* flow_pins[][2] = { diff --git a/applications/main/ibutton/ibutton_cli.c b/applications/main/ibutton/ibutton_cli.c index 98ef308016b..cf6442c0614 100644 --- a/applications/main/ibutton/ibutton_cli.c +++ b/applications/main/ibutton/ibutton_cli.c @@ -31,7 +31,7 @@ static void ibutton_cli_print_usage(void) { printf("\tCyfral (2 bytes key_data)\r\n"); printf("\tMetakom (4 bytes key_data), must contain correct parity\r\n"); printf("\t are hex-formatted\r\n"); -}; +} static bool ibutton_cli_parse_key(iButtonProtocols* protocols, iButtonKey* key, FuriString* args) { bool result = false; @@ -124,7 +124,7 @@ static void ibutton_cli_read(Cli* cli) { ibutton_protocols_free(protocols); furi_event_flag_free(event); -}; +} typedef struct { FuriEventFlag* event; @@ -226,7 +226,7 @@ void ibutton_cli_emulate(Cli* cli, FuriString* args) { ibutton_key_free(key); ibutton_worker_free(worker); ibutton_protocols_free(protocols); -}; +} void ibutton_cli(Cli* cli, FuriString* args, void* context) { UNUSED(cli); diff --git a/applications/main/ibutton/ibutton_i.h b/applications/main/ibutton/ibutton_i.h index c6a35f888b4..d355a4ea5f2 100644 --- a/applications/main/ibutton/ibutton_i.h +++ b/applications/main/ibutton/ibutton_i.h @@ -28,8 +28,8 @@ #include "ibutton_custom_event.h" #include "scenes/ibutton_scene.h" -#define IBUTTON_APP_FOLDER ANY_PATH("ibutton") -#define IBUTTON_APP_FILENAME_PREFIX "iBtn" +#define IBUTTON_APP_FOLDER ANY_PATH("ibutton") +#define IBUTTON_APP_FILENAME_PREFIX "iBtn" #define IBUTTON_APP_FILENAME_EXTENSION ".ibtn" #define IBUTTON_KEY_NAME_SIZE 22 diff --git a/applications/main/ibutton/scenes/ibutton_scene_add_value.c b/applications/main/ibutton/scenes/ibutton_scene_add_value.c index 71b852115e6..9815e52814a 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_add_value.c +++ b/applications/main/ibutton/scenes/ibutton_scene_add_value.c @@ -36,7 +36,27 @@ bool ibutton_scene_add_value_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == iButtonCustomEventByteEditResult) { - scene_manager_next_scene(scene_manager, iButtonSceneSaveName); + if(scene_manager_has_previous_scene(scene_manager, iButtonSceneAddType)) { + ibutton_protocols_apply_edits(ibutton->protocols, ibutton->key); + scene_manager_next_scene(scene_manager, iButtonSceneSaveName); + } else { + furi_string_printf( + ibutton->file_path, + "%s/%s%s", + IBUTTON_APP_FOLDER, + ibutton->key_name, + IBUTTON_APP_FILENAME_EXTENSION); + + if(ibutton_save_key(ibutton)) { + scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSaveSuccess); + + } else { + const uint32_t possible_scenes[] = { + iButtonSceneReadKeyMenu, iButtonSceneSavedKeyMenu, iButtonSceneAddType}; + scene_manager_search_and_switch_to_previous_scene_one_of( + ibutton->scene_manager, possible_scenes, COUNT_OF(possible_scenes)); + } + } } else if(event.event == iButtonCustomEventByteEditChanged) { ibutton_protocols_apply_edits(ibutton->protocols, ibutton->key); } diff --git a/applications/main/ibutton/scenes/ibutton_scene_save_name.c b/applications/main/ibutton/scenes/ibutton_scene_save_name.c index e6236dc3592..522d2be786e 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_save_name.c +++ b/applications/main/ibutton/scenes/ibutton_scene_save_name.c @@ -41,9 +41,17 @@ bool ibutton_scene_save_name_on_event(void* context, SceneManagerEvent event) { iButton* ibutton = context; bool consumed = false; + const bool is_new_file = furi_string_empty(ibutton->file_path); + if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == iButtonCustomEventTextEditResult) { + if(!is_new_file) { + Storage* storage = furi_record_open(RECORD_STORAGE); + storage_simply_remove(storage, furi_string_get_cstr(ibutton->file_path)); + furi_record_close(RECORD_STORAGE); + } + furi_string_printf( ibutton->file_path, "%s/%s%s", diff --git a/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c b/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c index 1547a647bf1..668b79ae3c5 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c +++ b/applications/main/ibutton/scenes/ibutton_scene_saved_key_menu.c @@ -6,6 +6,7 @@ enum SubmenuIndex { SubmenuIndexWriteBlank, SubmenuIndexWriteCopy, SubmenuIndexEdit, + SubmenuIndexRename, SubmenuIndexDelete, SubmenuIndexInfo, }; @@ -34,6 +35,7 @@ void ibutton_scene_saved_key_menu_on_enter(void* context) { } submenu_add_item(submenu, "Edit", SubmenuIndexEdit, ibutton_submenu_callback, ibutton); + submenu_add_item(submenu, "Rename", SubmenuIndexRename, ibutton_submenu_callback, ibutton); submenu_add_item(submenu, "Delete", SubmenuIndexDelete, ibutton_submenu_callback, ibutton); submenu_add_item(submenu, "Info", SubmenuIndexInfo, ibutton_submenu_callback, ibutton); @@ -61,6 +63,8 @@ bool ibutton_scene_saved_key_menu_on_event(void* context, SceneManagerEvent even scene_manager_next_scene(scene_manager, iButtonSceneWrite); } else if(event.event == SubmenuIndexEdit) { scene_manager_next_scene(scene_manager, iButtonSceneAddValue); + } else if(event.event == SubmenuIndexRename) { + scene_manager_next_scene(scene_manager, iButtonSceneSaveName); } else if(event.event == SubmenuIndexDelete) { scene_manager_next_scene(scene_manager, iButtonSceneDeleteConfirm); } else if(event.event == SubmenuIndexInfo) { diff --git a/applications/main/infrared/infrared_app.c b/applications/main/infrared/infrared_app.c index 93311716a17..c6e4bca0266 100644 --- a/applications/main/infrared/infrared_app.c +++ b/applications/main/infrared/infrared_app.c @@ -10,11 +10,11 @@ #define TAG "InfraredApp" #define INFRARED_TX_MIN_INTERVAL_MS (50U) -#define INFRARED_TASK_STACK_SIZE (2048UL) +#define INFRARED_TASK_STACK_SIZE (2048UL) -#define INFRARED_SETTINGS_PATH INT_PATH(".infrared.settings") +#define INFRARED_SETTINGS_PATH INT_PATH(".infrared.settings") #define INFRARED_SETTINGS_VERSION (1) -#define INFRARED_SETTINGS_MAGIC (0x1F) +#define INFRARED_SETTINGS_MAGIC (0x1F) typedef struct { FuriHalInfraredTxPin tx_pin; diff --git a/applications/main/infrared/infrared_app_i.h b/applications/main/infrared/infrared_app_i.h index 1635fa0dc42..d353b2503b1 100644 --- a/applications/main/infrared/infrared_app_i.h +++ b/applications/main/infrared/infrared_app_i.h @@ -39,18 +39,18 @@ #include "views/infrared_debug_view.h" #include "views/infrared_move_view.h" -#define INFRARED_FILE_NAME_SIZE 100 -#define INFRARED_TEXT_STORE_NUM 2 +#define INFRARED_FILE_NAME_SIZE 100 +#define INFRARED_TEXT_STORE_NUM 2 #define INFRARED_TEXT_STORE_SIZE 128 #define INFRARED_MAX_BUTTON_NAME_LENGTH 22 #define INFRARED_MAX_REMOTE_NAME_LENGTH 22 -#define INFRARED_APP_FOLDER ANY_PATH("infrared") +#define INFRARED_APP_FOLDER ANY_PATH("infrared") #define INFRARED_APP_EXTENSION ".ir" #define INFRARED_DEFAULT_REMOTE_NAME "Remote" -#define INFRARED_LOG_TAG "InfraredApp" +#define INFRARED_LOG_TAG "InfraredApp" /** * @brief Enumeration of invalid remote button indices. @@ -86,7 +86,7 @@ typedef struct { bool is_transmitting; /**< Whether a signal is currently being transmitted. */ bool is_otg_enabled; /**< Whether OTG power (external 5V) is enabled. */ InfraredEditTarget edit_target : 8; /**< Selected editing target (a remote or a button). */ - InfraredEditMode edit_mode : 8; /**< Selected editing operation (rename or delete). */ + InfraredEditMode edit_mode : 8; /**< Selected editing operation (rename or delete). */ int32_t current_button_index; /**< Selected button index (move destination). */ int32_t prev_button_index; /**< Previous button index (move source). */ uint32_t last_transmit_time; /**< Lat time a signal was transmitted. */ diff --git a/applications/main/infrared/infrared_cli.c b/applications/main/infrared/infrared_cli.c index 123fe78d54c..169f0c63d94 100644 --- a/applications/main/infrared/infrared_cli.c +++ b/applications/main/infrared/infrared_cli.c @@ -10,10 +10,10 @@ #include "infrared_signal.h" #include "infrared_brute_force.h" -#define INFRARED_CLI_BUF_SIZE (10U) -#define INFRARED_CLI_FILE_NAME_SIZE (256U) -#define INFRARED_FILE_EXTENSION ".ir" -#define INFRARED_ASSETS_FOLDER EXT_PATH("infrared/assets") +#define INFRARED_CLI_BUF_SIZE (10U) +#define INFRARED_CLI_FILE_NAME_SIZE (256U) +#define INFRARED_FILE_EXTENSION ".ir" +#define INFRARED_ASSETS_FOLDER EXT_PATH("infrared/assets") #define INFRARED_BRUTE_FORCE_DUMMY_INDEX 0 DICT_DEF2(dict_signals, FuriString*, FURI_STRING_OPLIST, int, M_DEFAULT_OPLIST) diff --git a/applications/main/infrared/infrared_remote.c b/applications/main/infrared/infrared_remote.c index c574d75c76c..11bbf197bc8 100644 --- a/applications/main/infrared/infrared_remote.c +++ b/applications/main/infrared/infrared_remote.c @@ -8,7 +8,7 @@ #define TAG "InfraredRemote" -#define INFRARED_FILE_HEADER "IR signals file" +#define INFRARED_FILE_HEADER "IR signals file" #define INFRARED_FILE_VERSION (1) ARRAY_DEF(StringArray, const char*, M_CSTR_DUP_OPLIST); //-V575 diff --git a/applications/main/infrared/infrared_signal.c b/applications/main/infrared/infrared_signal.c index 8902fc04c36..a4cb28bf0ed 100644 --- a/applications/main/infrared/infrared_signal.c +++ b/applications/main/infrared/infrared_signal.c @@ -13,18 +13,18 @@ #define INFRARED_SIGNAL_TYPE_KEY "type" // Type key values -#define INFRARED_SIGNAL_TYPE_RAW "raw" +#define INFRARED_SIGNAL_TYPE_RAW "raw" #define INFRARED_SIGNAL_TYPE_PARSED "parsed" // Raw signal keys -#define INFRARED_SIGNAL_DATA_KEY "data" -#define INFRARED_SIGNAL_FREQUENCY_KEY "frequency" +#define INFRARED_SIGNAL_DATA_KEY "data" +#define INFRARED_SIGNAL_FREQUENCY_KEY "frequency" #define INFRARED_SIGNAL_DUTY_CYCLE_KEY "duty_cycle" // Parsed signal keys #define INFRARED_SIGNAL_PROTOCOL_KEY "protocol" -#define INFRARED_SIGNAL_ADDRESS_KEY "address" -#define INFRARED_SIGNAL_COMMAND_KEY "command" +#define INFRARED_SIGNAL_ADDRESS_KEY "address" +#define INFRARED_SIGNAL_COMMAND_KEY "command" struct InfraredSignal { bool is_raw; diff --git a/applications/main/infrared/resources/infrared/assets/audio.ir b/applications/main/infrared/resources/infrared/assets/audio.ir index 2d3d2198598..6303278acf9 100644 --- a/applications/main/infrared/resources/infrared/assets/audio.ir +++ b/applications/main/infrared/resources/infrared/assets/audio.ir @@ -475,3 +475,34 @@ type: parsed protocol: NEC address: 00 00 00 00 command: 85 00 00 00 +# +#Sony audio remote RM-SC3 +name: Power +type: parsed +protocol: SIRC +address: 10 00 00 00 +command: 15 00 00 00 +# +name: Vol_up +type: parsed +protocol: SIRC +address: 10 00 00 00 +command: 12 00 00 00 +# +name: Vol_dn +type: parsed +protocol: SIRC +address: 10 00 00 00 +command: 13 00 00 00 +# +name: Play +type: parsed +protocol: SIRC20 +address: 3A 07 00 00 +command: 32 00 00 00 +# +name: Pause +type: parsed +protocol: SIRC20 +address: 3A 07 00 00 +command: 39 00 00 00 diff --git a/applications/main/infrared/resources/infrared/assets/tv.ir b/applications/main/infrared/resources/infrared/assets/tv.ir index 5eab4c65c6c..4d5868ccea1 100644 --- a/applications/main/infrared/resources/infrared/assets/tv.ir +++ b/applications/main/infrared/resources/infrared/assets/tv.ir @@ -1867,3 +1867,41 @@ protocol: NEC address: 04 00 00 00 command: 09 00 00 00 # +# Emerson TV +# +name: Power +type: parsed +protocol: NECext +address: 84 E0 00 00 +command: 20 DF 00 00 +# +name: Ch_next +type: parsed +protocol: NECext +address: 84 E0 00 00 +command: 50 AF 00 00 +# +name: Ch_prev +type: parsed +protocol: NECext +address: 84 E0 00 00 +command: 51 AE 00 00 +# +name: Vol_up +type: parsed +protocol: NECext +address: 84 E0 00 00 +command: 60 9F 00 00 +# +name: Vol_dn +type: parsed +protocol: NECext +address: 84 E0 00 00 +command: 61 9E 00 00 +# +name: Mute +type: parsed +protocol: NECext +address: 84 E0 00 00 +command: 64 9B 00 00 + diff --git a/applications/main/infrared/views/infrared_move_view.c b/applications/main/infrared/views/infrared_move_view.c index 5635d8a74dc..f3fc6dde12f 100644 --- a/applications/main/infrared/views/infrared_move_view.c +++ b/applications/main/infrared/views/infrared_move_view.c @@ -7,9 +7,9 @@ #include -#define LIST_ITEMS 4U -#define LIST_LINE_H 13U -#define HEADER_H 12U +#define LIST_ITEMS 4U +#define LIST_LINE_H 13U +#define HEADER_H 12U #define MOVE_X_OFFSET 5U struct InfraredMoveView { @@ -98,7 +98,7 @@ static bool infrared_move_view_input_callback(InputEvent* event, void* context) bool consumed = false; - if(((event->type == InputTypeShort || event->type == InputTypeRepeat)) && + if((event->type == InputTypeShort || event->type == InputTypeRepeat) && ((event->key == InputKeyUp) || (event->key == InputKeyDown))) { with_view_model( move_view->view, diff --git a/applications/main/lfrfid/lfrfid_cli.c b/applications/main/lfrfid/lfrfid_cli.c index 2101670fa73..a25032d6af9 100644 --- a/applications/main/lfrfid/lfrfid_cli.c +++ b/applications/main/lfrfid/lfrfid_cli.c @@ -32,7 +32,7 @@ static void lfrfid_cli_print_usage(void) { "rfid raw_emulate - emulate raw data (not very useful, but helps debug protocols)\r\n"); printf( "rfid raw_analyze - outputs raw data to the cli and tries to decode it (useful for protocol development)\r\n"); -}; +} typedef struct { ProtocolId protocol; diff --git a/applications/main/lfrfid/lfrfid_i.h b/applications/main/lfrfid/lfrfid_i.h index 70623154505..b1f82d026fd 100644 --- a/applications/main/lfrfid/lfrfid_i.h +++ b/applications/main/lfrfid/lfrfid_i.h @@ -35,13 +35,13 @@ #include -#define LFRFID_KEY_NAME_SIZE 22 +#define LFRFID_KEY_NAME_SIZE 22 #define LFRFID_TEXT_STORE_SIZE 40 -#define LFRFID_APP_FOLDER ANY_PATH("lfrfid") -#define LFRFID_SD_FOLDER EXT_PATH("lfrfid") -#define LFRFID_APP_FILENAME_PREFIX "RFID" -#define LFRFID_APP_FILENAME_EXTENSION ".rfid" +#define LFRFID_APP_FOLDER ANY_PATH("lfrfid") +#define LFRFID_SD_FOLDER EXT_PATH("lfrfid") +#define LFRFID_APP_FILENAME_PREFIX "RFID" +#define LFRFID_APP_FILENAME_EXTENSION ".rfid" #define LFRFID_APP_SHADOW_FILENAME_EXTENSION ".shd" #define LFRFID_APP_RAW_ASK_EXTENSION ".ask.raw" diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c b/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c index 11a687bdd4d..20c8a10df7b 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c @@ -31,8 +31,21 @@ bool lfrfid_scene_save_data_on_event(void* context, SceneManagerEvent event) { consumed = true; size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id); protocol_dict_set_data(app->dict, app->protocol_id, app->new_key_data, size); - scene_manager_next_scene(scene_manager, LfRfidSceneSaveName); - scene_manager_set_scene_state(scene_manager, LfRfidSceneSaveData, 1); + + if(scene_manager_has_previous_scene(scene_manager, LfRfidSceneSaveType)) { + scene_manager_next_scene(scene_manager, LfRfidSceneSaveName); + } else { + if(!furi_string_empty(app->file_name)) { + lfrfid_delete_key(app); + } + + if(lfrfid_save_key(app)) { + scene_manager_next_scene(scene_manager, LfRfidSceneSaveSuccess); + } else { + scene_manager_search_and_switch_to_previous_scene( + scene_manager, LfRfidSceneSavedKeyMenu); + } + } } } else if(event.type == SceneManagerEventTypeBack) { scene_manager_set_scene_state(scene_manager, LfRfidSceneSaveData, 0); diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c b/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c index f687cd0a294..9ae789a170c 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c @@ -5,6 +5,7 @@ typedef enum { SubmenuIndexEmulate, SubmenuIndexWrite, SubmenuIndexEdit, + SubmenuIndexRename, SubmenuIndexDelete, SubmenuIndexInfo, } SubmenuIndex; @@ -25,6 +26,8 @@ void lfrfid_scene_saved_key_menu_on_enter(void* context) { submenu, "Write", SubmenuIndexWrite, lfrfid_scene_saved_key_menu_submenu_callback, app); submenu_add_item( submenu, "Edit", SubmenuIndexEdit, lfrfid_scene_saved_key_menu_submenu_callback, app); + submenu_add_item( + submenu, "Rename", SubmenuIndexRename, lfrfid_scene_saved_key_menu_submenu_callback, app); submenu_add_item( submenu, "Delete", SubmenuIndexDelete, lfrfid_scene_saved_key_menu_submenu_callback, app); submenu_add_item( @@ -51,6 +54,9 @@ bool lfrfid_scene_saved_key_menu_on_event(void* context, SceneManagerEvent event } else if(event.event == SubmenuIndexEdit) { scene_manager_next_scene(app->scene_manager, LfRfidSceneSaveData); consumed = true; + } else if(event.event == SubmenuIndexRename) { + scene_manager_next_scene(app->scene_manager, LfRfidSceneSaveName); + consumed = true; } else if(event.event == SubmenuIndexDelete) { scene_manager_next_scene(app->scene_manager, LfRfidSceneDeleteConfirm); consumed = true; diff --git a/applications/main/nfc/api/gallagher/gallagher_util.c b/applications/main/nfc/api/gallagher/gallagher_util.c index caa3650e740..8217d0383a2 100644 --- a/applications/main/nfc/api/gallagher/gallagher_util.c +++ b/applications/main/nfc/api/gallagher/gallagher_util.c @@ -56,4 +56,4 @@ void gallagher_deobfuscate_and_parse_credential( ((uint32_t)cardholder_data_deobfuscated[2] << 3) + (((uint32_t)cardholder_data_deobfuscated[3] >> 5) & 0x07); credential->issue = cardholder_data_deobfuscated[7] & 0x0F; -} \ No newline at end of file +} diff --git a/applications/main/nfc/api/gallagher/gallagher_util.h b/applications/main/nfc/api/gallagher/gallagher_util.h index 79e09838948..eeff5ae086c 100644 --- a/applications/main/nfc/api/gallagher/gallagher_util.h +++ b/applications/main/nfc/api/gallagher/gallagher_util.h @@ -30,4 +30,4 @@ void gallagher_deobfuscate_and_parse_credential( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/main/nfc/api/mosgortrans/mosgortrans_util.h b/applications/main/nfc/api/mosgortrans/mosgortrans_util.h index e5da8ddeb44..2dc469c45cc 100644 --- a/applications/main/nfc/api/mosgortrans/mosgortrans_util.h +++ b/applications/main/nfc/api/mosgortrans/mosgortrans_util.h @@ -14,4 +14,4 @@ bool mosgortrans_parse_transport_block(const MfClassicBlock* block, FuriString* #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/main/nfc/helpers/felica_auth.c b/applications/main/nfc/helpers/felica_auth.c index a8cd0929bae..6e2cf786a31 100644 --- a/applications/main/nfc/helpers/felica_auth.c +++ b/applications/main/nfc/helpers/felica_auth.c @@ -18,4 +18,4 @@ void felica_auth_reset(FelicaAuthenticationContext* instance) { instance->skip_auth = true; instance->auth_status.external = 0; instance->auth_status.internal = 0; -} \ No newline at end of file +} diff --git a/applications/main/nfc/helpers/mf_classic_key_cache.c b/applications/main/nfc/helpers/mf_classic_key_cache.c index 2c1141e9c69..1b945660c0a 100644 --- a/applications/main/nfc/helpers/mf_classic_key_cache.c +++ b/applications/main/nfc/helpers/mf_classic_key_cache.c @@ -3,7 +3,7 @@ #include #include -#define NFC_APP_KEYS_EXTENSION ".keys" +#define NFC_APP_KEYS_EXTENSION ".keys" #define NFC_APP_KEY_CACHE_FOLDER "/ext/nfc/.cache" static const char* mf_classic_key_cache_file_header = "Flipper NFC keys"; diff --git a/applications/main/nfc/helpers/mf_ultralight_auth.c b/applications/main/nfc/helpers/mf_ultralight_auth.c index d954c1f7e91..e97649cb3ed 100644 --- a/applications/main/nfc/helpers/mf_ultralight_auth.c +++ b/applications/main/nfc/helpers/mf_ultralight_auth.c @@ -20,6 +20,7 @@ void mf_ultralight_auth_reset(MfUltralightAuth* instance) { instance->type = MfUltralightAuthTypeNone; memset(&instance->password, 0, sizeof(MfUltralightAuthPassword)); + memset(&instance->tdes_key, 0, sizeof(MfUltralightC3DesAuthKey)); memset(&instance->pack, 0, sizeof(MfUltralightAuthPack)); } diff --git a/applications/main/nfc/helpers/mf_ultralight_auth.h b/applications/main/nfc/helpers/mf_ultralight_auth.h index 51267b3eab3..c9e80765fb5 100644 --- a/applications/main/nfc/helpers/mf_ultralight_auth.h +++ b/applications/main/nfc/helpers/mf_ultralight_auth.h @@ -17,6 +17,7 @@ typedef enum { typedef struct { MfUltralightAuthType type; MfUltralightAuthPassword password; + MfUltralightC3DesAuthKey tdes_key; MfUltralightAuthPack pack; } MfUltralightAuth; diff --git a/applications/main/nfc/helpers/mf_user_dict.c b/applications/main/nfc/helpers/mf_user_dict.c index 9410c8537d8..70b1114722d 100644 --- a/applications/main/nfc/helpers/mf_user_dict.c +++ b/applications/main/nfc/helpers/mf_user_dict.c @@ -4,7 +4,7 @@ #include #include -#define NFC_APP_FOLDER ANY_PATH("nfc") +#define NFC_APP_FOLDER ANY_PATH("nfc") #define NFC_APP_MF_CLASSIC_DICT_USER_PATH (NFC_APP_FOLDER "/assets/mf_classic_dict_user.nfc") struct MfUserDict { diff --git a/applications/main/nfc/helpers/nfc_supported_cards.c b/applications/main/nfc/helpers/nfc_supported_cards.c index 1e0e7ba6bf2..6513eef5f6e 100644 --- a/applications/main/nfc/helpers/nfc_supported_cards.c +++ b/applications/main/nfc/helpers/nfc_supported_cards.c @@ -14,7 +14,7 @@ #define TAG "NfcSupportedCards" -#define NFC_SUPPORTED_CARDS_PLUGINS_PATH APP_DATA_PATH("plugins") +#define NFC_SUPPORTED_CARDS_PLUGINS_PATH APP_DATA_PATH("plugins") #define NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX "_parser.fal" typedef enum { @@ -24,7 +24,7 @@ typedef enum { } NfcSupportedCardsPluginFeature; typedef struct { - FuriString* path; + FuriString* name; NfcProtocol protocol; NfcSupportedCardsPluginFeature feature; } NfcSupportedCardsPluginCache; @@ -41,7 +41,6 @@ typedef enum { typedef struct { Storage* storage; File* directory; - FuriString* file_path; char file_name[256]; FlipperApplication* app; } NfcSupportedCardsLoadContext; @@ -73,7 +72,7 @@ void nfc_supported_cards_free(NfcSupportedCards* instance) { !NfcSupportedCardsPluginCache_end_p(iter); NfcSupportedCardsPluginCache_next(iter)) { NfcSupportedCardsPluginCache* plugin_cache = NfcSupportedCardsPluginCache_ref(iter); - furi_string_free(plugin_cache->path); + furi_string_free(plugin_cache->name); } NfcSupportedCardsPluginCache_clear(instance->plugins_cache_arr); @@ -86,7 +85,6 @@ static NfcSupportedCardsLoadContext* nfc_supported_cards_load_context_alloc(void instance->storage = furi_record_open(RECORD_STORAGE); instance->directory = storage_file_alloc(instance->storage); - instance->file_path = furi_string_alloc(); if(!storage_dir_open(instance->directory, NFC_SUPPORTED_CARDS_PLUGINS_PATH)) { FURI_LOG_D(TAG, "Failed to open directory: %s", NFC_SUPPORTED_CARDS_PLUGINS_PATH); @@ -100,8 +98,6 @@ static void nfc_supported_cards_load_context_free(NfcSupportedCardsLoadContext* flipper_application_free(instance->app); } - furi_string_free(instance->file_path); - storage_dir_close(instance->directory); storage_file_free(instance->directory); @@ -111,16 +107,19 @@ static void nfc_supported_cards_load_context_free(NfcSupportedCardsLoadContext* static const NfcSupportedCardsPlugin* nfc_supported_cards_get_plugin( NfcSupportedCardsLoadContext* instance, - const FuriString* path, + const char* name, const ElfApiInterface* api_interface) { furi_assert(instance); - furi_assert(path); + furi_assert(name); const NfcSupportedCardsPlugin* plugin = NULL; + FuriString* plugin_path = furi_string_alloc_printf( + "%s/%s%s", NFC_SUPPORTED_CARDS_PLUGINS_PATH, name, NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX); do { if(instance->app) flipper_application_free(instance->app); instance->app = flipper_application_alloc(instance->storage, api_interface); - if(flipper_application_preload(instance->app, furi_string_get_cstr(path)) != + + if(flipper_application_preload(instance->app, furi_string_get_cstr(plugin_path)) != FlipperApplicationPreloadStatusSuccess) break; if(!flipper_application_is_plugin(instance->app)) break; @@ -136,6 +135,7 @@ static const NfcSupportedCardsPlugin* nfc_supported_cards_get_plugin( plugin = descriptor->entry_point; } while(false); + furi_string_free(plugin_path); return plugin; } @@ -151,13 +151,21 @@ static const NfcSupportedCardsPlugin* nfc_supported_cards_get_next_plugin( instance->directory, NULL, instance->file_name, sizeof(instance->file_name))) break; - furi_string_set(instance->file_path, instance->file_name); - if(!furi_string_end_with_str(instance->file_path, NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX)) - continue; + const size_t suffix_len = strlen(NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX); + const size_t file_name_len = strlen(instance->file_name); + if(file_name_len <= suffix_len) break; + + size_t suffix_start_pos = file_name_len - suffix_len; + if(memcmp( + &instance->file_name[suffix_start_pos], + NFC_SUPPORTED_CARDS_PLUGIN_SUFFIX, + suffix_len) != 0) //-V1051 + break; - path_concat(NFC_SUPPORTED_CARDS_PLUGINS_PATH, instance->file_name, instance->file_path); + // Trim suffix from file_name to save memory. The suffix will be concatenated on plugin load. + instance->file_name[suffix_start_pos] = '\0'; - plugin = nfc_supported_cards_get_plugin(instance, instance->file_path, api_interface); + plugin = nfc_supported_cards_get_plugin(instance, instance->file_name, api_interface); } while(plugin == NULL); //-V654 return plugin; @@ -181,7 +189,7 @@ void nfc_supported_cards_load_cache(NfcSupportedCards* instance) { if(plugin == NULL) break; //-V547 NfcSupportedCardsPluginCache plugin_cache = {}; //-V779 - plugin_cache.path = furi_string_alloc_set(instance->load_context->file_path); + plugin_cache.name = furi_string_alloc_set(instance->load_context->file_name); plugin_cache.protocol = plugin->protocol; if(plugin->verify) { plugin_cache.feature |= NfcSupportedCardsPluginFeatureHasVerify; @@ -233,7 +241,7 @@ bool nfc_supported_cards_read(NfcSupportedCards* instance, NfcDevice* device, Nf const ElfApiInterface* api_interface = composite_api_resolver_get(instance->api_resolver); const NfcSupportedCardsPlugin* plugin = nfc_supported_cards_get_plugin( - instance->load_context, plugin_cache->path, api_interface); + instance->load_context, furi_string_get_cstr(plugin_cache->name), api_interface); if(plugin == NULL) continue; if(plugin->verify) { @@ -281,7 +289,7 @@ bool nfc_supported_cards_parse( const ElfApiInterface* api_interface = composite_api_resolver_get(instance->api_resolver); const NfcSupportedCardsPlugin* plugin = nfc_supported_cards_get_plugin( - instance->load_context, plugin_cache->path, api_interface); + instance->load_context, furi_string_get_cstr(plugin_cache->name), api_interface); if(plugin == NULL) continue; if(plugin->parse) { diff --git a/applications/main/nfc/helpers/protocol_support/felica/felica.c b/applications/main/nfc/helpers/protocol_support/felica/felica.c index ceb18065369..561cd4d2e91 100644 --- a/applications/main/nfc/helpers/protocol_support/felica/felica.c +++ b/applications/main/nfc/helpers/protocol_support/felica/felica.c @@ -106,7 +106,7 @@ static void nfc_scene_read_success_on_enter_felica(NfcApp* instance) { FuriString* temp_str = furi_string_alloc(); - if(!scene_manager_has_previous_scene(instance->scene_manager, NfcSceneFelicaUnlockWarn)) { + if(!scene_manager_has_previous_scene(instance->scene_manager, NfcSceneDesAuthUnlockWarn)) { furi_string_cat_printf( temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull)); nfc_render_felica_info(data, NfcProtocolFormatTypeShort, temp_str); @@ -163,7 +163,7 @@ static void nfc_scene_read_menu_on_enter_felica(NfcApp* instance) { static bool nfc_scene_read_menu_on_event_felica(NfcApp* instance, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubmenuIndexUnlock) { - scene_manager_next_scene(instance->scene_manager, NfcSceneFelicaKeyInput); + scene_manager_next_scene(instance->scene_manager, NfcSceneDesAuthKeyInput); return true; } } diff --git a/applications/main/nfc/helpers/protocol_support/felica/felica_render.h b/applications/main/nfc/helpers/protocol_support/felica/felica_render.h index 3d32e8d14e2..48bea44331f 100644 --- a/applications/main/nfc/helpers/protocol_support/felica/felica_render.h +++ b/applications/main/nfc/helpers/protocol_support/felica/felica_render.h @@ -19,4 +19,4 @@ void nfc_render_felica_dump(const FelicaData* data, FuriString* str); void nfc_render_felica_idm( const FelicaData* data, NfcProtocolFormatType format_type, - FuriString* str); \ No newline at end of file + FuriString* str); diff --git a/applications/main/nfc/helpers/protocol_support/iso15693_3/iso15693_3_render.c b/applications/main/nfc/helpers/protocol_support/iso15693_3/iso15693_3_render.c index 07b96d70187..ba8f10b9356 100644 --- a/applications/main/nfc/helpers/protocol_support/iso15693_3/iso15693_3_render.c +++ b/applications/main/nfc/helpers/protocol_support/iso15693_3/iso15693_3_render.c @@ -71,7 +71,7 @@ void nfc_render_iso15693_3_system_info(const Iso15693_3Data* data, FuriString* s void nfc_render_iso15693_3_extra(const Iso15693_3Data* data, FuriString* str) { furi_string_cat(str, "\n::::::::::::::::[General info]:::::::::::::::::\n"); if(data->system_info.flags & ISO15693_3_SYSINFO_FLAG_DSFID) { - furi_string_cat_printf(str, "DSFID: %02X\n", data->system_info.ic_ref); + furi_string_cat_printf(str, "DSFID: %02X\n", data->system_info.dsfid); } if(data->system_info.flags & ISO15693_3_SYSINFO_FLAG_AFI) { diff --git a/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c b/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c index 23a1a3b69ad..783cbb871c2 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c +++ b/applications/main/nfc/helpers/protocol_support/mf_desfire/mf_desfire_render.c @@ -91,7 +91,7 @@ void nfc_render_mf_desfire_version(const MfDesfireVersion* data, FuriString* str furi_string_cat_printf( str, "batch %02x:%02x:%02x:%02x:%02x\n" - "week %d year %d\n", + "week %02x year 20%02x\n", data->batch[0], data->batch[1], data->batch[2], diff --git a/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c b/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c index eb2299cb5c7..c7b36e21ea3 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c +++ b/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c @@ -120,4 +120,4 @@ const NfcProtocolSupportBase nfc_protocol_support_mf_plus = { .on_enter = nfc_scene_emulate_on_enter_mf_plus, .on_event = nfc_protocol_support_common_on_event_empty, }, -}; \ No newline at end of file +}; diff --git a/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.h b/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.h index 7f2e63dd1d6..049e46e645a 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.h +++ b/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.h @@ -2,4 +2,4 @@ #include "../nfc_protocol_support_base.h" -extern const NfcProtocolSupportBase nfc_protocol_support_mf_plus; \ No newline at end of file +extern const NfcProtocolSupportBase nfc_protocol_support_mf_plus; diff --git a/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c b/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c index b55ba130e76..3adf2a1f5c3 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c +++ b/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight.c @@ -150,6 +150,7 @@ static NfcCommand } if(!mf_ultralight_event->data->auth_context.skip_auth) { mf_ultralight_event->data->auth_context.password = instance->mf_ul_auth->password; + mf_ultralight_event->data->auth_context.tdes_key = instance->mf_ul_auth->tdes_key; } } else if(mf_ultralight_event->type == MfUltralightPollerEventTypeAuthSuccess) { instance->mf_ul_auth->pack = mf_ultralight_event->data->auth_context.pack; @@ -243,7 +244,13 @@ static bool nfc_scene_read_and_saved_menu_on_event_mf_ultralight( if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubmenuIndexUnlock) { - scene_manager_next_scene(instance->scene_manager, NfcSceneMfUltralightUnlockMenu); + const MfUltralightData* data = + nfc_device_get_data(instance->nfc_device, NfcProtocolMfUltralight); + + uint32_t next_scene = (data->type == MfUltralightTypeMfulC) ? + NfcSceneDesAuthKeyInput : + NfcSceneMfUltralightUnlockMenu; + scene_manager_next_scene(instance->scene_manager, next_scene); consumed = true; } else if(event.event == SubmenuIndexWrite) { scene_manager_next_scene(instance->scene_manager, NfcSceneMfUltralightWrite); diff --git a/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight_render.h b/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight_render.h index 5b15bb59110..eddae0bcabd 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight_render.h +++ b/applications/main/nfc/helpers/protocol_support/mf_ultralight/mf_ultralight_render.h @@ -11,4 +11,4 @@ void nfc_render_mf_ultralight_info( void nfc_render_mf_ultralight_dump(const MfUltralightData* data, FuriString* str); -void nfc_render_mf_ultralight_pwd_pack(const MfUltralightData* data, FuriString* str); \ No newline at end of file +void nfc_render_mf_ultralight_pwd_pack(const MfUltralightData* data, FuriString* str); diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.h b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.h index 855642c621d..d3efc3a41cb 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.h +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support.h @@ -113,4 +113,4 @@ bool nfc_protocol_support_on_event( */ void nfc_protocol_support_on_exit(NfcProtocolSupportScene scene, void* context); -bool nfc_protocol_support_has_feature(NfcProtocol protocol, NfcProtocolFeature feature); \ No newline at end of file +bool nfc_protocol_support_has_feature(NfcProtocol protocol, NfcProtocolFeature feature); diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.c b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.c index f1d504d2486..8cfb26a533c 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.c +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.c @@ -22,7 +22,7 @@ void nfc_unlock_helper_setup_from_state(NfcApp* instance) { bool unlocking = scene_manager_has_previous_scene( instance->scene_manager, NfcSceneMfUltralightUnlockWarn) || - scene_manager_has_previous_scene(instance->scene_manager, NfcSceneFelicaUnlockWarn); + scene_manager_has_previous_scene(instance->scene_manager, NfcSceneDesAuthUnlockWarn); uint32_t state = unlocking ? NfcSceneReadMenuStateCardSearch : NfcSceneReadMenuStateCardFound; @@ -35,4 +35,4 @@ void nfc_unlock_helper_card_detected_handler(NfcApp* instance) { scene_manager_set_scene_state( instance->scene_manager, NfcSceneRead, NfcSceneReadMenuStateCardFound); nfc_scene_read_setup_view(instance); -} \ No newline at end of file +} diff --git a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.h b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.h index 65da3324022..34f52496bd3 100644 --- a/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.h +++ b/applications/main/nfc/helpers/protocol_support/nfc_protocol_support_unlock_helper.h @@ -6,4 +6,4 @@ typedef enum { } NfcSceneUnlockReadState; void nfc_unlock_helper_setup_from_state(NfcApp* instance); -void nfc_unlock_helper_card_detected_handler(NfcApp* instance); \ No newline at end of file +void nfc_unlock_helper_card_detected_handler(NfcApp* instance); diff --git a/applications/main/nfc/nfc_app_i.h b/applications/main/nfc/nfc_app_i.h index 64f7fc6e7b9..c91ef33df0f 100644 --- a/applications/main/nfc/nfc_app_i.h +++ b/applications/main/nfc/nfc_app_i.h @@ -61,19 +61,19 @@ #include #include -#define NFC_NAME_SIZE 22 -#define NFC_TEXT_STORE_SIZE 128 +#define NFC_NAME_SIZE 22 +#define NFC_TEXT_STORE_SIZE 128 #define NFC_BYTE_INPUT_STORE_SIZE 10 -#define NFC_LOG_SIZE_MAX (1024) -#define NFC_APP_FOLDER ANY_PATH("nfc") -#define NFC_APP_EXTENSION ".nfc" -#define NFC_APP_SHADOW_EXTENSION ".shd" -#define NFC_APP_FILENAME_PREFIX "NFC" +#define NFC_LOG_SIZE_MAX (1024) +#define NFC_APP_FOLDER ANY_PATH("nfc") +#define NFC_APP_EXTENSION ".nfc" +#define NFC_APP_SHADOW_EXTENSION ".shd" +#define NFC_APP_FILENAME_PREFIX "NFC" #define NFC_APP_MFKEY32_LOGS_FILE_NAME ".mfkey32.log" #define NFC_APP_MFKEY32_LOGS_FILE_PATH (NFC_APP_FOLDER "/" NFC_APP_MFKEY32_LOGS_FILE_NAME) -#define NFC_APP_MF_CLASSIC_DICT_USER_PATH (NFC_APP_FOLDER "/assets/mf_classic_dict_user.nfc") +#define NFC_APP_MF_CLASSIC_DICT_USER_PATH (NFC_APP_FOLDER "/assets/mf_classic_dict_user.nfc") #define NFC_APP_MF_CLASSIC_DICT_SYSTEM_PATH (NFC_APP_FOLDER "/assets/mf_classic_dict.nfc") typedef enum { diff --git a/applications/main/nfc/plugins/supported_cards/gallagher.c b/applications/main/nfc/plugins/supported_cards/gallagher.c index 84ac335a49c..e88a85f2bd5 100644 --- a/applications/main/nfc/plugins/supported_cards/gallagher.c +++ b/applications/main/nfc/plugins/supported_cards/gallagher.c @@ -85,4 +85,4 @@ static const FlipperAppPluginDescriptor gallagher_plugin_descriptor = { /* Plugin entry point */ const FlipperAppPluginDescriptor* gallagher_plugin_ep(void) { return &gallagher_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/hi.c b/applications/main/nfc/plugins/supported_cards/hi.c index f24c1c11a8f..a26d2265042 100644 --- a/applications/main/nfc/plugins/supported_cards/hi.c +++ b/applications/main/nfc/plugins/supported_cards/hi.c @@ -5,9 +5,10 @@ #include #define TAG "HI!" -#define KEY_LENGTH 6 + +#define KEY_LENGTH 6 #define HI_KEY_TO_GEN 5 -#define UID_LENGTH 7 +#define UID_LENGTH 7 typedef struct { uint64_t a; diff --git a/applications/main/nfc/plugins/supported_cards/microel.c b/applications/main/nfc/plugins/supported_cards/microel.c index fa3be7235e4..18d08f5331a 100644 --- a/applications/main/nfc/plugins/supported_cards/microel.c +++ b/applications/main/nfc/plugins/supported_cards/microel.c @@ -5,6 +5,7 @@ #include #define TAG "Microel" + #define KEY_LENGTH 6 #define UID_LENGTH 4 @@ -227,4 +228,4 @@ static const FlipperAppPluginDescriptor microel_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* microel_plugin_ep(void) { return µel_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/mizip.c b/applications/main/nfc/plugins/supported_cards/mizip.c index 0fd1a8f4a90..c29c5f90885 100644 --- a/applications/main/nfc/plugins/supported_cards/mizip.c +++ b/applications/main/nfc/plugins/supported_cards/mizip.c @@ -5,9 +5,10 @@ #include #define TAG "MiZIP" -#define KEY_LENGTH 6 + +#define KEY_LENGTH 6 #define MIZIP_KEY_TO_GEN 5 -#define UID_LENGTH 4 +#define UID_LENGTH 4 typedef struct { uint64_t a; diff --git a/applications/main/nfc/plugins/supported_cards/opal.c b/applications/main/nfc/plugins/supported_cards/opal.c index db9a1784ca6..b499e4978b8 100644 --- a/applications/main/nfc/plugins/supported_cards/opal.c +++ b/applications/main/nfc/plugins/supported_cards/opal.c @@ -62,18 +62,18 @@ static const char* opal_usages[14] = { // Opal file 0x7 structure. Assumes a little-endian CPU. typedef struct FURI_PACKED { - uint32_t serial : 32; - uint8_t check_digit : 4; - bool blocked : 1; - uint16_t txn_number : 16; - int32_t balance : 21; - uint16_t days : 15; - uint16_t minutes : 11; - uint8_t mode : 3; - uint16_t usage : 4; - bool auto_topup : 1; + uint32_t serial : 32; + uint8_t check_digit : 4; + bool blocked : 1; + uint16_t txn_number : 16; + int32_t balance : 21; + uint16_t days : 15; + uint16_t minutes : 11; + uint8_t mode : 3; + uint16_t usage : 4; + bool auto_topup : 1; uint8_t weekly_journeys : 4; - uint16_t checksum : 16; + uint16_t checksum : 16; } OpalFile; static_assert(sizeof(OpalFile) == 16, "OpalFile"); diff --git a/applications/main/nfc/plugins/supported_cards/troika.c b/applications/main/nfc/plugins/supported_cards/troika.c index de9a47facb4..0c93fa59ae0 100644 --- a/applications/main/nfc/plugins/supported_cards/troika.c +++ b/applications/main/nfc/plugins/supported_cards/troika.c @@ -260,4 +260,4 @@ static const FlipperAppPluginDescriptor troika_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* troika_plugin_ep(void) { return &troika_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/umarsh.c b/applications/main/nfc/plugins/supported_cards/umarsh.c index fd0b0968087..298e201d8ff 100644 --- a/applications/main/nfc/plugins/supported_cards/umarsh.c +++ b/applications/main/nfc/plugins/supported_cards/umarsh.c @@ -40,7 +40,7 @@ bool parse_datetime(uint16_t date, DateTime* result) { result->year = 2000 + (date >> 9); result->month = date >> 5 & 0x0F; result->day = date & 0x1F; - return (date != 0); + return date != 0; } static bool umarsh_parse(const NfcDevice* device, FuriString* parsed_data) { diff --git a/applications/main/nfc/plugins/supported_cards/washcity.c b/applications/main/nfc/plugins/supported_cards/washcity.c index 6a8c8c28ba9..737e5734117 100644 --- a/applications/main/nfc/plugins/supported_cards/washcity.c +++ b/applications/main/nfc/plugins/supported_cards/washcity.c @@ -194,4 +194,4 @@ static const FlipperAppPluginDescriptor washcity_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* washcity_plugin_ep(void) { return &washcity_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/scenes/nfc_scene_config.h b/applications/main/nfc/scenes/nfc_scene_config.h index 3017d16a406..83c8ffeed3e 100644 --- a/applications/main/nfc/scenes/nfc_scene_config.h +++ b/applications/main/nfc/scenes/nfc_scene_config.h @@ -33,8 +33,8 @@ ADD_SCENE(nfc, mf_ultralight_unlock_menu, MfUltralightUnlockMenu) ADD_SCENE(nfc, mf_ultralight_unlock_warn, MfUltralightUnlockWarn) ADD_SCENE(nfc, mf_ultralight_key_input, MfUltralightKeyInput) ADD_SCENE(nfc, mf_ultralight_capture_pass, MfUltralightCapturePass) -ADD_SCENE(nfc, felica_key_input, FelicaKeyInput) -ADD_SCENE(nfc, felica_unlock_warn, FelicaUnlockWarn) +ADD_SCENE(nfc, des_auth_key_input, DesAuthKeyInput) +ADD_SCENE(nfc, des_auth_unlock_warn, DesAuthUnlockWarn) ADD_SCENE(nfc, mf_desfire_more_info, MfDesfireMoreInfo) ADD_SCENE(nfc, mf_desfire_app, MfDesfireApp) diff --git a/applications/main/nfc/scenes/nfc_scene_felica_key_input.c b/applications/main/nfc/scenes/nfc_scene_des_auth_key_input.c similarity index 52% rename from applications/main/nfc/scenes/nfc_scene_felica_key_input.c rename to applications/main/nfc/scenes/nfc_scene_des_auth_key_input.c index b04f12dae85..f3a6ecb328e 100644 --- a/applications/main/nfc/scenes/nfc_scene_felica_key_input.c +++ b/applications/main/nfc/scenes/nfc_scene_des_auth_key_input.c @@ -1,43 +1,54 @@ #include "../nfc_app_i.h" -void nfc_scene_felica_key_input_byte_input_callback(void* context) { +void nfc_scene_des_auth_key_input_byte_input_callback(void* context) { NfcApp* nfc = context; view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventByteInputDone); } -void nfc_scene_felica_key_input_on_enter(void* context) { +void nfc_scene_des_auth_key_input_on_enter(void* context) { NfcApp* nfc = context; // Setup view + NfcProtocol protocol = nfc_device_get_protocol(nfc->nfc_device); + uint8_t* key = (protocol == NfcProtocolFelica) ? nfc->felica_auth->card_key.data : + nfc->mf_ul_auth->tdes_key.data; + ByteInput* byte_input = nfc->byte_input; byte_input_set_header_text(byte_input, "Enter key in hex"); byte_input_set_result_callback( byte_input, - nfc_scene_felica_key_input_byte_input_callback, + nfc_scene_des_auth_key_input_byte_input_callback, NULL, nfc, - nfc->felica_auth->card_key.data, + key, FELICA_DATA_BLOCK_SIZE); view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewByteInput); } -bool nfc_scene_felica_key_input_on_event(void* context, SceneManagerEvent event) { +bool nfc_scene_des_auth_key_input_on_event(void* context, SceneManagerEvent event) { NfcApp* nfc = context; UNUSED(event); bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { if(event.event == NfcCustomEventByteInputDone) { - nfc->felica_auth->skip_auth = false; - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaUnlockWarn); + NfcProtocol protocol = nfc_device_get_protocol(nfc->nfc_device); + + if(protocol == NfcProtocolFelica) { + nfc->felica_auth->skip_auth = false; + } else { + nfc->mf_ul_auth->type = MfUltralightAuthTypeManual; + } + + scene_manager_next_scene(nfc->scene_manager, NfcSceneDesAuthUnlockWarn); consumed = true; } } return consumed; } -void nfc_scene_felica_key_input_on_exit(void* context) { +void nfc_scene_des_auth_key_input_on_exit(void* context) { NfcApp* nfc = context; // Clear view diff --git a/applications/main/nfc/scenes/nfc_scene_felica_unlock_warn.c b/applications/main/nfc/scenes/nfc_scene_des_auth_unlock_warn.c similarity index 68% rename from applications/main/nfc/scenes/nfc_scene_felica_unlock_warn.c rename to applications/main/nfc/scenes/nfc_scene_des_auth_unlock_warn.c index 15b61dfa510..80c735c9ca1 100644 --- a/applications/main/nfc/scenes/nfc_scene_felica_unlock_warn.c +++ b/applications/main/nfc/scenes/nfc_scene_des_auth_unlock_warn.c @@ -1,25 +1,30 @@ #include "../nfc_app_i.h" -void nfc_scene_felica_unlock_warn_dialog_callback(DialogExResult result, void* context) { +void nfc_scene_des_auth_unlock_warn_dialog_callback(DialogExResult result, void* context) { NfcApp* nfc = context; view_dispatcher_send_custom_event(nfc->view_dispatcher, result); } -void nfc_scene_felica_unlock_warn_on_enter(void* context) { +void nfc_scene_des_auth_unlock_warn_on_enter(void* context) { NfcApp* nfc = context; const char* message = "Risky Action!"; DialogEx* dialog_ex = nfc->dialog_ex; dialog_ex_set_context(dialog_ex, nfc); - dialog_ex_set_result_callback(dialog_ex, nfc_scene_felica_unlock_warn_dialog_callback); + dialog_ex_set_result_callback(dialog_ex, nfc_scene_des_auth_unlock_warn_dialog_callback); dialog_ex_set_header(dialog_ex, message, 64, 0, AlignCenter, AlignTop); FuriString* str = furi_string_alloc(); furi_string_cat_printf(str, "Unlock with key: "); + + NfcProtocol protocol = nfc_device_get_protocol(nfc->nfc_device); + uint8_t* key = (protocol == NfcProtocolFelica) ? nfc->felica_auth->card_key.data : + nfc->mf_ul_auth->tdes_key.data; + for(uint8_t i = 0; i < FELICA_DATA_BLOCK_SIZE; i++) - furi_string_cat_printf(str, "%02X ", nfc->felica_auth->card_key.data[i]); + furi_string_cat_printf(str, "%02X ", key[i]); furi_string_cat_printf(str, "?"); nfc_text_store_set(nfc, furi_string_get_cstr(str)); @@ -33,7 +38,7 @@ void nfc_scene_felica_unlock_warn_on_enter(void* context) { view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx); } -bool nfc_scene_felica_unlock_warn_on_event(void* context, SceneManagerEvent event) { +bool nfc_scene_des_auth_unlock_warn_on_event(void* context, SceneManagerEvent event) { NfcApp* nfc = context; UNUSED(event); bool consumed = false; @@ -51,7 +56,7 @@ bool nfc_scene_felica_unlock_warn_on_event(void* context, SceneManagerEvent even return consumed; } -void nfc_scene_felica_unlock_warn_on_exit(void* context) { +void nfc_scene_des_auth_unlock_warn_on_exit(void* context) { NfcApp* nfc = context; dialog_ex_reset(nfc->dialog_ex); diff --git a/applications/main/nfc/scenes/nfc_scene_mf_classic_detect_reader.c b/applications/main/nfc/scenes/nfc_scene_mf_classic_detect_reader.c index e2d3e6d72f5..176b014e90a 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_classic_detect_reader.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_classic_detect_reader.c @@ -4,7 +4,7 @@ #define NXP_MANUFACTURER_ID (0x04) -#define NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX (10U) +#define NFC_SCENE_DETECT_READER_PAIR_NONCES_MAX (10U) #define NFC_SCENE_DETECT_READER_WAIT_NONCES_TIMEOUT_MS (1000) static const NotificationSequence sequence_detect_reader = { diff --git a/applications/main/nfc/scenes/nfc_scene_mf_classic_mfkey_complete.c b/applications/main/nfc/scenes/nfc_scene_mf_classic_mfkey_complete.c index d5033789a12..660674ceb0a 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_classic_mfkey_complete.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_classic_mfkey_complete.c @@ -22,7 +22,7 @@ void nfc_scene_mf_classic_mfkey_complete_on_enter(void* context) { AlignCenter, AlignTop, FontSecondary, - "Now use Mfkey32 to extract \nkeys: lab.flipper.net/nfc-tools"); + "Now use Mfkey32 to extract \nkeys: r.flipper.net/nfc-tools"); widget_add_icon_element(instance->widget, 50, 39, &I_MFKey_qr_25x25); widget_add_button_element( instance->widget, diff --git a/applications/main/nfc/scenes/nfc_scene_mf_classic_update_initial_wrong_card.c b/applications/main/nfc/scenes/nfc_scene_mf_classic_update_initial_wrong_card.c index c2c36c74fa1..f3aefb78150 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_classic_update_initial_wrong_card.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_classic_update_initial_wrong_card.c @@ -55,4 +55,4 @@ void nfc_scene_mf_classic_update_initial_wrong_card_on_exit(void* context) { NfcApp* instance = context; widget_reset(instance->widget); -} \ No newline at end of file +} diff --git a/applications/main/nfc/scenes/nfc_scene_mf_classic_write_initial_wrong_card.c b/applications/main/nfc/scenes/nfc_scene_mf_classic_write_initial_wrong_card.c index 3f92ebfd3b2..3d49b3cac63 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_classic_write_initial_wrong_card.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_classic_write_initial_wrong_card.c @@ -54,4 +54,4 @@ void nfc_scene_mf_classic_write_initial_wrong_card_on_exit(void* context) { NfcApp* instance = context; widget_reset(instance->widget); -} \ No newline at end of file +} diff --git a/applications/main/nfc/scenes/nfc_scene_mf_ultralight_wrong_card.c b/applications/main/nfc/scenes/nfc_scene_mf_ultralight_wrong_card.c index 0ca765db78c..bc34a45b4a5 100644 --- a/applications/main/nfc/scenes/nfc_scene_mf_ultralight_wrong_card.c +++ b/applications/main/nfc/scenes/nfc_scene_mf_ultralight_wrong_card.c @@ -55,4 +55,4 @@ void nfc_scene_mf_ultralight_wrong_card_on_exit(void* context) { NfcApp* instance = context; widget_reset(instance->widget); -} \ No newline at end of file +} diff --git a/applications/main/onewire/onewire_cli.c b/applications/main/onewire/onewire_cli.c index 19e58421750..af3d4e8035c 100644 --- a/applications/main/onewire/onewire_cli.c +++ b/applications/main/onewire/onewire_cli.c @@ -21,7 +21,7 @@ void onewire_on_system_start(void) { static void onewire_cli_print_usage(void) { printf("Usage:\r\n"); printf("onewire search\r\n"); -}; +} static void onewire_cli_search(Cli* cli) { UNUSED(cli); diff --git a/applications/main/subghz/helpers/subghz_chat.c b/applications/main/subghz/helpers/subghz_chat.c index bbe219fd2f7..9945b69c8b7 100644 --- a/applications/main/subghz/helpers/subghz_chat.c +++ b/applications/main/subghz/helpers/subghz_chat.c @@ -2,6 +2,7 @@ #include #define TAG "SubGhzChat" + #define SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES 500 struct SubGhzChatWorker { diff --git a/applications/main/subghz/helpers/subghz_threshold_rssi.c b/applications/main/subghz/helpers/subghz_threshold_rssi.c index f9906b51340..188ded35e9f 100644 --- a/applications/main/subghz/helpers/subghz_threshold_rssi.c +++ b/applications/main/subghz/helpers/subghz_threshold_rssi.c @@ -3,6 +3,7 @@ #include #define TAG "SubGhzThresholdRssi" + #define THRESHOLD_RSSI_LOW_COUNT 10 struct SubGhzThresholdRssi { diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index d14be476802..e3a0c6057a6 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -508,22 +508,19 @@ SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* instance) { bool subghz_txrx_protocol_is_serializable(SubGhzTxRx* instance) { furi_assert(instance); - return ( - (instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == - SubGhzProtocolFlag_Save); + return (instance->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == + SubGhzProtocolFlag_Save; } bool subghz_txrx_protocol_is_transmittable(SubGhzTxRx* instance, bool check_type) { furi_assert(instance); const SubGhzProtocol* protocol = instance->decoder_result->protocol; if(check_type) { - return ( - ((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && - protocol->encoder->deserialize && protocol->type == SubGhzProtocolTypeStatic); + return ((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && + protocol->encoder->deserialize && protocol->type == SubGhzProtocolTypeStatic; } - return ( - ((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && - protocol->encoder->deserialize); + return ((protocol->flag & SubGhzProtocolFlag_Send) == SubGhzProtocolFlag_Send) && + protocol->encoder->deserialize; } void subghz_txrx_receiver_set_filter(SubGhzTxRx* instance, SubGhzProtocolFlag filter) { @@ -609,4 +606,4 @@ const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance) { bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency) { furi_assert(instance); return subghz_devices_is_frequency_valid(instance->radio_device, frequency); -} \ No newline at end of file +} diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index a16625f8b71..b2ca44ee71f 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -333,4 +333,4 @@ const char* subghz_txrx_radio_device_get_name(SubGhzTxRx* instance); * @param instance Pointer to a SubGhzTxRx * @return bool True if the frequency is valid */ -bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency); \ No newline at end of file +bool subghz_txrx_radio_device_is_frequecy_valid(SubGhzTxRx* instance, uint32_t frequency); diff --git a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h index edc6e541557..89a52f235fb 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h @@ -93,4 +93,4 @@ SubGhzProtocolStatus subghz_txrx_gen_secplus_v2_protocol( SubGhzProtocolStatus subghz_txrx_gen_secplus_v1_protocol( SubGhzTxRx* instance, const char* name_preset, - uint32_t frequency); \ No newline at end of file + uint32_t frequency); diff --git a/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes b/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes index f2e45b491b3..886cf82121a 100644 --- a/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes +++ b/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes @@ -1,57 +1,58 @@ Filetype: Flipper SubGhz Keystore File Version: 0 Encryption: 1 -IV: 23 17 32 54 92 3A 28 13 12 DE 8B A7 24 71 25 74 -B8ACA082EA4B34E8B217A6FE63F3545D160AB7F4833C87E8743BAA7002ACC123 -E779135FE66629CAC4661B1C3D5C9857C9417CAF216241933FF6CE60A74D53C0 -15340C049A444C79ED489619A31E2AFDCFF6E4864CC4D9B1DA8E98D7EAB9C8D5 -8E696E85837B3BA8D6D380E1F36E445D630CF0B7B18A45930A08F832EE634A02 -C85341BE669E509E902FEFCA7D025A20DC80D4F14FE1C3542B1DC3A5C7393A36F901A63C3BC074B058897B12F0F5F0D6 -2834E5D7726670A03ED6C8B27B5863EEE2FD3668795251AB65B9E4FF76ADEC3E -8E71AF7660BCFC545E92674D74F98A35FCF1B54AB5BACCEE182B7F8EDB3FA356 -C20442D506332D1A410AF3187C29BE01729C282A69B85CF8D92D70FAE3407BA8 -00BC449D006566A6549A86F52B98410871B0C14D60C181BFC017446B192C934A -8A6A28DAF1F61867B1209AB9105986A7383ECE72A40F8D93F1D0066251800A3A -4A6AFDFA6130A50180358B111145D7914C720E04D69EE5459C049FCD64249153315F86A5A9F75AEE5CB726847BA64F2A -91F838BC515C8CDD32C5803679B81A24FD5CF0C3A4AEA2C07342ACA1020E05F3B393A410B33847A8C48141D923202CF3 -7C4DEBC03295291EC5B2EBB002670D14E7C972F32DB2B3CD4E61B2BE846345D9 -8FFEB948DA3D1A7FCF620F043B1D35354F83861F22B6D693F2A7119A2E287D01 -309C66AF38E6447CB33FB0967C9365CA36314DBF74695F63CF9E558A4FF5193B -411D32EC6ADED3360DE9E9A0962F97DF2B80A09F2A2AC8D4DB6DB09FAD6EA217 -A5E5550BD59425003F9166237CD4BB6A323885D7916F71F3B2795B8A4C7125ACC1237BBF0840F0E999BD2EC14327654F -4370A828AFED684B96E8EDAB670C46D2D525FCB7E469B63CD1228C902C3ACF4E -88E3853F58129C4D834B18E4D01785591094301148D802A3A21B63521DDDA325 -D5365BF55DFE7107909684F4ECCE052E617F91FAF08CE5254721A30BEF87F368F329C46439BD1EA2819DC416B2CEF247 -BDAB9FFD3A82ECE05E8CA00F11954CDB1C124B558A5D369DFE16D32C3AEF08B2013945CC69212F170F17F62A55D35928 -8E448AA1D39C894F306FE65B0D0DD733717EF81758FFA908AF7583BFD00108E5 -019A1B0AA3492427DF3DB817B438D0302B0B8C77807D19EE45EAC7F697B2EB85 -C678A3F9DA726FE1688F86BB063EA017EDB5389E0F185484D9F5DFD4EBEE0579 -760F77AB9BD99593AC855E4AE00FBAFBB34FA2BFF504BD5CC9557658E850C6D0 -4F3E77342E9A655D4EC167E2B0428833FEE31CF603FA1CE3D1BCD619D5C9D511 -2233EFBEDD4A3A95BA8160EFCED533D9F25B65AAB10F627681D2753871814366 -A1261BE878933B4905956BE7708F7C40E999714503B52B8021D44E131D87FF6C -8F31E76314A46EA9B0CCD3EDA4B2DF603829D8E3AF8CE41AEA6BFFBA2E2990AC -850C08E45CDA4E42BD4F09B956299C0ED58615BE3664791C88D1E2608D46D205 -6283656518C6ADFC3B7D309D2763BD91111720CD51029FAA691211DEFF84CB47 -9FCAF9F77C9D1B9B6934E53DB10DFF88D392D8E7BB4DC28D65F65DC396E2E00A -41D2406BE1887FCC094861E4DF0683B1BE534C5CBF059259E946F9D04222C2AB -1D6F37E645591F0C491312C1E0CB54F1A6B70F94B54D63100C4584AA016DB589338A704B6D8B6B89C2381F660D987A2F -DCEA08D6E5C0D6229EBDE07DBB6CBC0EA8D6E24A3B631CC3775CE23A496CF178 -907051215A741BE55603F27C3FD86561CC6231CEED83AA76665D6A0B6B3FEC88 -36CD5B5BCC63D45B89592B2938D6542B9D82AB47BEB73C0D30D2EC19BD8B35C2 -1FD9651ABAD773D6D22DE677CF7B19615D5B805594DCA117F04AC3255AE8184A -4900723A8F7736C9BEAE938EE021F3E44AD806244010F825D04C59E6C67B5EA2 -0D56A8CE77106DA2CB44F65B8CF5F4A024B9CC774D1C4CB8E862C95BD30B42E7B2E946CAC361F2830361C010DC938833 -11543FD104EA7D68B6B9C3BFE3F25A84F651FCB7FB5423AADDC472A48E12AFB2 -98CD236E8B92D706DA0F92F43AC1D2CAF1CFBCDC7B330A7C9D65CDC4F2E2A677 -753557A9A5075C033206111E3C832044227A32EBF3AB2B08F6FBFCC2109B2F2A -4AA124232EF6C25CB7321F5E5F7BE11114C763F8DDAFB6B05E8412ADF37B5C7B -01514EA408E26BAFD30290429DE1A0211F4FBDB09DE2E66CE92A6F09B998EF29 -4715716D5AFF99A2D8205A46AEEF0BC20D72F3F54991F7DF4142FF187485C178 -281A32B90F8B85F31F54BF0D83B6D03E4E65A72ADB3D5A297C91881E36B45E8F -9C05D3CB9F473D5693697A8567DBA7CF650C0A0D6C1BBE3ACE78ACDE0BD027B6C836B6CB6365D5B5D00F101FA83876B9 -DC88B0237634CB007244A4169A5D9F5F65FC782E3C4388358A7E2019F7B4CC05 -BC7ACAA91D23616A0070DCA328901DDDE3BB5B59260FB45083916B6ED0E6450C -A280434D059D652D77ACB9F44409CDC7393A876239BA894DD4BE843FAB0AC561 -334F1316A35EB8A838F6B209FA4F8148062972E27A296379731B1F728A0BB32E -DDC9883E90EBE73915CFDF8EA7193F2449B66010D45F5EC6F20949D5C49719A9298B95269531A3440577B00EADE1B379 +IV: 59 65 73 2C 20 61 6E 64 20 79 6F 75 20 74 6F 6F +25F6594BB3FA40C929F9CF43E5E6649A42047B727398F057589EAAC7430169E5 +B2D2A6E64C3A13406610C086DBF2D17F0C5643E44CD276D4F8933942B964DAA2 +76EE2549A4F62499533856346B3AAF535F248E23802111380D44B70014581E09 +482D1CD99F0F9940195777F482B6EF78B0895FDEAF721544A349B705FCFDF3DE +A83ED14173781D96C7434892D9A092A8658EDDC105FC35FFB1D1C727E0A9FD13F8C07A79F6778D858C0002265C8D49ED +3675A174F916BDCBE056B5C9C7B6461AC885969A140DAB923137F80CEBBBF64D +EE55B1DE8D6632FF91C090641032A290C15271E59C6B9E75328B7463F9029B9F +8A81B9B366DD0F00D1829B3DF62A3EF912B4F492E9D6E99BDC33519C53A9A24D +1C55C1195C5BFCC502448269211384EF13C979FABE39E4F3251E219F67C8DC4B +11F0FFEB6B9B308DFA9CFA0CD87F5D4EB2D0E48CC9D026C4FAE2C3D06EDE64E4 +11B3CC20AAD78DE62E835B922006635F6BA8D6D72088AEE51D6B0BA4DF8A87AB9A900F7B9D2AD87F0D9DC091EFFCE41A +5E57F7A3369B51636E91471C3873C4017B7694FC074E1620AD288548282201860304FA42804049A974E8D495C9DFDDC2 +62E153886C36AD29DDFBE061800863C12DB1E04E10E082A4FED50BE36ACCF2D1 +B0699C0D88A3E91683D90D0B8E2BC78829E12691A9D44B771D0FCC6A8E6E5F34 +5039B897208F5224F8147B443BF2E4AECBC4FF6BB8C5BA330094C7B1426E88EF +3F1B2AE46A6467BFE35EA4003788A2F437A7AEB45B3EB0B53D4236445165CF93 +CFB07A55170A6CC9DD578E294087FCCE356A5C11D6BDC4728BC3CE28C1AD4E0AF8CE283915464C2BC2BD47CF93B2FAE2 +EB7F7622C0A1C32B630F923CAB2A8014868212F7B3CE2DA3A81BC0BA11FE26EB +ABEBD5C5EF32E24841BDAD3A412F4CF841CB0FBC515E47F73DB55A8E3ABE8854 +099226A6C87F2E543BEF871491CBB18F4CB3AC96B0629F45D79021183EC35B34C48E03E8C8EA5E11171D6ACC233293D7 +AE78F4F9F800E1A2F96C2A1ADC2655576B723773D533DF2B6A9D98004F607990675648FEA66470FE70E32CCD071D7DEB +AC4065F0A4CD5947DE081FEC2B35F3C1A30A3C2A12908F59B7B4A1C2AA5A1C56 +15791F43991B06D729EAD37E9990D6FCF20F356D03661B4B96A5777D9FE6A7EA +78AADF788C3AE3E619078B0AF71AAB39E125A6046B4FC362D7C8D51EC8C32451 +8B9000CF70198026159D56F7B4A530BCE0E247C00CD4D81EEB59ED52C57FEA03 +A41F06335E36DDEED8E77A6773E75C8BB9E255DB48A070DDB63CCA4D8DA00336 +33DB24D54DA53E295467FAB962D863C7015DB706E4AF6248B9B046FB7B9899C2 +3C4C7C892BAA22AAEF6C92962C67CA0B0F18D8C0A88FD45A4D0A5A166FF1C766 +9B0850A575A27BA23E82E52EAECC6766B0D5FB3CDCBC60CD970AB90742B5BCFA +9329F044763196FC029639758C29F4186F77AF3DAF237CA434427A712A6BA890 +35F89F373EA9F7EBAF1DE48BC21E14D7D1B28967C8F65A5D0228CED120ABD06F +319423ACE5A80A117C7521A1A0BF22B40181B62BEBDB800AEE139E94FE323298 +3C2D4F8700825C966004993A1191F1573CBF4A407CB7728937ED0E46320D4E9B +C1A9BF45B7E5AFE2753D7C8E04C80301EF54FBD9377F1A879C224A6CD0C841C9B8DAFEF2E12B4D0418D36B3AF8AFCBB7 +062E33ADC270AF5111536CADF329D9C78E3CC3FB0538ACF38E9E2A61B5A3B49E +BC6E26CCC82DB4C4AD1970CDCED894E85F838EFF0701A36BCFCBFA463A7D0482 +CDBD96D21F2CD5457863AE80240A435E478FEE7F7130ED22253B9FA77BED9B67 +21956DAF6FE1C313DBF310EC05A6EAD9930B6571AAEAB968C26CA4348ACECFE4 +F05A6468310D49A770A4FFB960EDD2F985646C83C7A7F5160E61CE9BDC578D38 +7F7BEC5B03AFE530746A0F2E8277D17FAA743D678D0FDB69626FFA4AB07504B4 +92204CD4721F426DE2870D47FDDB54771BF8BF766AE2B88C1A2AE1A27ADAEBB6B50BB0D2A64E50725A8613DC702B4645 +A3EA461CED048BA13FEFD357C04EC1CFD8C3608D5B5C81577C36B8C7B9A80759 +960FA991AC2669E25D03AF0B52D04691172A00EECE05DC6DD59D008CEF220780 +EFE29D8222D2C319C93A0601410A1ED88563CD38E3E4E621617AFB72E3C100F3 +C55ADFA945416FFBD013F6B97914B4A902FABBFB4EFBB2583AEE11D93DC87B4D +6D462090B80489D07337E034F0F27C881066321C58C553EDCBCE593A50B96A31 +C2DB9833D0810D023E548EF4BEC218D916DB005EF2BE1122AE4BC756EBE4AFBF +D5E0EC7C772A9E39973EF35DA201C661BCD182DA2AAE3E3706781191666B7B4F +371463A5E41EEEA81D25217FDB97DACABC0B1892E0A5B36825B83330FEB900D3D89915D7B9AD5B3C3550C84384DF242E +BEE891192062A5AA254B6E3AD27D006A650D947EDF9010F6A78C78A4443F1D0C +D56C5498E65B3E2FE6B1A3C25B4D47650DD9E1BAE04AA9CD468026854D5B231B +2CFF607EE43B721D9B6F564CF70034920716392BAD686A95518CD02ACFE6D232 +2FABCA8EA65BF98CB8236AD4301B8D1C474FBB1F33B084C736C323A83B6DE336 +07AF12E594D474483BB6DB6CD2F7F722934DF2B9BECE2F0761FED2ECA2738C17FA8B03195A632D5395E9D2F4F8B84C91 diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index b12c946813d..449a799f0a4 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -4,9 +4,10 @@ #include #include -#define RAW_FILE_NAME "Raw_signal_" #define TAG "SubGhzSceneReadRaw" +#define RAW_FILE_NAME "Raw_signal_" + bool subghz_scene_read_raw_update_filename(SubGhz* subghz) { bool ret = false; //set the path to read the file diff --git a/applications/main/subghz/subghz_cli.c b/applications/main/subghz/subghz_cli.c index b96a22db62b..b6d3bf5c4b3 100644 --- a/applications/main/subghz/subghz_cli.c +++ b/applications/main/subghz/subghz_cli.c @@ -1203,7 +1203,7 @@ static bool subghz_on_system_start_istream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) { File* file = istream->state; size_t ret = storage_file_read(file, buf, count); - return (count == ret); + return count == ret; } static bool subghz_on_system_start_istream_decode_band( diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index e6c93e05cc0..85e59ae0799 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -4,8 +4,9 @@ #include -#define SUBGHZ_HISTORY_MAX 50 +#define SUBGHZ_HISTORY_MAX 50 #define SUBGHZ_HISTORY_FREE_HEAP 20480 + #define TAG "SubGhzHistory" typedef struct { diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 243ad101f8a..61544c5dfa2 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -408,7 +408,7 @@ void subghz_unlock(SubGhz* subghz) { bool subghz_is_locked(SubGhz* subghz) { furi_assert(subghz); - return (subghz->lock == SubGhzLockOn); + return subghz->lock == SubGhzLockOn; } void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state) { diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 39b5c78b905..ea74f8c6c65 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -7,9 +7,9 @@ #include #define FRAME_HEIGHT 12 -#define MAX_LEN_PX 111 -#define MENU_ITEMS 4u -#define UNLOCK_CNT 3 +#define MAX_LEN_PX 111 +#define MENU_ITEMS 4u +#define UNLOCK_CNT 3 #define SUBGHZ_RAW_THRESHOLD_MIN -90.0f @@ -145,7 +145,7 @@ void subghz_view_receiver_add_item_to_menu( SubGhzReceiverMenuItemArray_push_raw(model->history->data); item_menu->item_str = furi_string_alloc_set(name); item_menu->type = type; - if((model->idx == model->history_item - 1)) { + if(model->idx == model->history_item - 1) { model->history_item++; model->idx++; } else { diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index b59426f022c..8e66c56ed17 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -46,8 +46,7 @@ typedef struct { } SubGhzFrequencyAnalyzerModel; static inline uint8_t rssi_sanitize(float rssi) { - return ( - !float_is_equal(rssi, 0.f) ? (uint8_t)(rssi - SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) : 0); + return !float_is_equal(rssi, 0.f) ? (uint8_t)(rssi - SUBGHZ_FREQUENCY_ANALYZER_THRESHOLD) : 0; } void subghz_frequency_analyzer_set_callback( diff --git a/applications/main/subghz/views/subghz_read_raw.c b/applications/main/subghz/views/subghz_read_raw.c index 322c0d49905..5665818697e 100644 --- a/applications/main/subghz/views/subghz_read_raw.c +++ b/applications/main/subghz/views/subghz_read_raw.c @@ -6,9 +6,11 @@ #include #include -#define SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE 100 + #define TAG "SubGhzReadRaw" +#define SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE 100 + struct SubGhzReadRAW { View* view; SubGhzReadRAWCallback callback; diff --git a/applications/main/u2f/u2f.c b/applications/main/u2f/u2f.c index b61cfa15d3b..6a37769a8b7 100644 --- a/applications/main/u2f/u2f.c +++ b/applications/main/u2f/u2f.c @@ -12,13 +12,14 @@ #include #define TAG "U2f" + #define WORKER_TAG TAG "Worker" #define MCHECK(expr) furi_check((expr) == 0) -#define U2F_CMD_REGISTER 0x01 +#define U2F_CMD_REGISTER 0x01 #define U2F_CMD_AUTHENTICATE 0x02 -#define U2F_CMD_VERSION 0x03 +#define U2F_CMD_VERSION 0x03 typedef enum { U2fCheckOnly = 0x07, // "check-only" - only check key handle, don't send auth response @@ -28,14 +29,14 @@ typedef enum { 0x08, // "dont-enforce-user-presence-and-sign" - send auth response even if user is missing } U2fAuthMode; -#define U2F_HASH_SIZE 32 -#define U2F_NONCE_SIZE 32 +#define U2F_HASH_SIZE 32 +#define U2F_NONCE_SIZE 32 #define U2F_CHALLENGE_SIZE 32 -#define U2F_APP_ID_SIZE 32 +#define U2F_APP_ID_SIZE 32 -#define U2F_EC_KEY_SIZE 32 +#define U2F_EC_KEY_SIZE 32 #define U2F_EC_BIGNUM_SIZE 32 -#define U2F_EC_POINT_SIZE 65 +#define U2F_EC_POINT_SIZE 65 typedef struct { uint8_t format; @@ -315,7 +316,7 @@ static uint16_t u2f_register(U2fData* U2F, uint8_t* buf) { uint8_t signature_len = u2f_der_encode_signature(resp->cert + cert_len, signature); memcpy(resp->cert + cert_len + signature_len, state_no_error, 2); - return (sizeof(U2fRegisterResp) + cert_len + signature_len + 2); + return sizeof(U2fRegisterResp) + cert_len + signature_len + 2; } static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) { @@ -410,7 +411,7 @@ static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) { if(U2F->callback != NULL) U2F->callback(U2fNotifyAuthSuccess, U2F->context); - return (sizeof(U2fAuthResp) + signature_len + 2); + return sizeof(U2fAuthResp) + signature_len + 2; } uint16_t u2f_msg_parse(U2fData* U2F, uint8_t* buf, uint16_t len) { diff --git a/applications/main/u2f/u2f_data.c b/applications/main/u2f/u2f_data.c index c6451757b1b..52c6b37d59c 100644 --- a/applications/main/u2f/u2f_data.c +++ b/applications/main/u2f/u2f_data.c @@ -7,28 +7,28 @@ #define TAG "U2f" -#define U2F_DATA_FOLDER EXT_PATH("u2f/") -#define U2F_CERT_FILE U2F_DATA_FOLDER "assets/cert.der" +#define U2F_DATA_FOLDER EXT_PATH("u2f/") +#define U2F_CERT_FILE U2F_DATA_FOLDER "assets/cert.der" #define U2F_CERT_KEY_FILE U2F_DATA_FOLDER "assets/cert_key.u2f" -#define U2F_KEY_FILE U2F_DATA_FOLDER "key.u2f" -#define U2F_CNT_FILE U2F_DATA_FOLDER "cnt.u2f" +#define U2F_KEY_FILE U2F_DATA_FOLDER "key.u2f" +#define U2F_CNT_FILE U2F_DATA_FOLDER "cnt.u2f" #define U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_FACTORY 2 -#define U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE FURI_HAL_CRYPTO_ENCLAVE_UNIQUE_KEY_SLOT +#define U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE FURI_HAL_CRYPTO_ENCLAVE_UNIQUE_KEY_SLOT #define U2F_CERT_STOCK 0 // Stock certificate, private key is encrypted with factory key -#define U2F_CERT_USER 1 // User certificate, private key is encrypted with unique key +#define U2F_CERT_USER 1 // User certificate, private key is encrypted with unique key #define U2F_CERT_USER_UNENCRYPTED \ 2 // Unencrypted user certificate, will be encrypted after first load #define U2F_CERT_KEY_FILE_TYPE "Flipper U2F Certificate Key File" -#define U2F_CERT_KEY_VERSION 1 +#define U2F_CERT_KEY_VERSION 1 #define U2F_DEVICE_KEY_FILE_TYPE "Flipper U2F Device Key File" -#define U2F_DEVICE_KEY_VERSION 1 +#define U2F_DEVICE_KEY_VERSION 1 -#define U2F_COUNTER_FILE_TYPE "Flipper U2F Counter File" -#define U2F_COUNTER_VERSION 2 +#define U2F_COUNTER_FILE_TYPE "Flipper U2F Counter File" +#define U2F_COUNTER_VERSION 2 #define U2F_COUNTER_VERSION_OLD 1 #define U2F_COUNTER_CONTROL_VAL 0xAA5500FF diff --git a/applications/main/u2f/u2f_hid.c b/applications/main/u2f/u2f_hid.c index 83c8a575f56..76d3d7cece3 100644 --- a/applications/main/u2f/u2f_hid.c +++ b/applications/main/u2f/u2f_hid.c @@ -9,6 +9,7 @@ #include #define TAG "U2fHid" + #define WORKER_TAG TAG "Worker" #define U2F_HID_MAX_PAYLOAD_LEN ((HID_U2F_PACKET_LEN - 7) + 128 * (HID_U2F_PACKET_LEN - 5)) @@ -17,23 +18,23 @@ #define U2F_HID_TYPE_INIT 0x80 // Initial frame identifier #define U2F_HID_TYPE_CONT 0x00 // Continuation frame identifier -#define U2F_HID_PING (U2F_HID_TYPE_INIT | 0x01) // Echo data through local processor only -#define U2F_HID_MSG (U2F_HID_TYPE_INIT | 0x03) // Send U2F message frame -#define U2F_HID_LOCK (U2F_HID_TYPE_INIT | 0x04) // Send lock channel command -#define U2F_HID_INIT (U2F_HID_TYPE_INIT | 0x06) // Channel initialization -#define U2F_HID_WINK (U2F_HID_TYPE_INIT | 0x08) // Send device identification wink +#define U2F_HID_PING (U2F_HID_TYPE_INIT | 0x01) // Echo data through local processor only +#define U2F_HID_MSG (U2F_HID_TYPE_INIT | 0x03) // Send U2F message frame +#define U2F_HID_LOCK (U2F_HID_TYPE_INIT | 0x04) // Send lock channel command +#define U2F_HID_INIT (U2F_HID_TYPE_INIT | 0x06) // Channel initialization +#define U2F_HID_WINK (U2F_HID_TYPE_INIT | 0x08) // Send device identification wink #define U2F_HID_ERROR (U2F_HID_TYPE_INIT | 0x3f) // Error response -#define U2F_HID_ERR_NONE 0x00 // No error -#define U2F_HID_ERR_INVALID_CMD 0x01 // Invalid command -#define U2F_HID_ERR_INVALID_PAR 0x02 // Invalid parameter -#define U2F_HID_ERR_INVALID_LEN 0x03 // Invalid message length -#define U2F_HID_ERR_INVALID_SEQ 0x04 // Invalid message sequencing -#define U2F_HID_ERR_MSG_TIMEOUT 0x05 // Message has timed out -#define U2F_HID_ERR_CHANNEL_BUSY 0x06 // Channel busy +#define U2F_HID_ERR_NONE 0x00 // No error +#define U2F_HID_ERR_INVALID_CMD 0x01 // Invalid command +#define U2F_HID_ERR_INVALID_PAR 0x02 // Invalid parameter +#define U2F_HID_ERR_INVALID_LEN 0x03 // Invalid message length +#define U2F_HID_ERR_INVALID_SEQ 0x04 // Invalid message sequencing +#define U2F_HID_ERR_MSG_TIMEOUT 0x05 // Message has timed out +#define U2F_HID_ERR_CHANNEL_BUSY 0x06 // Channel busy #define U2F_HID_ERR_LOCK_REQUIRED 0x0a // Command requires channel lock -#define U2F_HID_ERR_SYNC_FAIL 0x0b // SYNC command failed -#define U2F_HID_ERR_OTHER 0x7f // Other unspecified error +#define U2F_HID_ERR_SYNC_FAIL 0x0b // SYNC command failed +#define U2F_HID_ERR_OTHER 0x7f // Other unspecified error #define U2F_HID_BROADCAST_CID 0xFFFFFFFF diff --git a/applications/main/u2f/views/u2f_view.c b/applications/main/u2f/views/u2f_view.c index bdbe8bcecdb..a110b3f4f74 100644 --- a/applications/main/u2f/views/u2f_view.c +++ b/applications/main/u2f/views/u2f_view.c @@ -97,6 +97,5 @@ void u2f_view_set_ok_callback(U2fView* u2f, U2fOkCallback callback, void* contex } void u2f_view_set_state(U2fView* u2f, U2fViewMsg msg) { - with_view_model( - u2f->view, U2fModel * model, { model->display_msg = msg; }, true); + with_view_model(u2f->view, U2fModel * model, { model->display_msg = msg; }, true); } diff --git a/applications/services/bt/bt_service/bt.c b/applications/services/bt/bt_service/bt.c index 59eb863889a..e3afceb70b0 100644 --- a/applications/services/bt/bt_service/bt.c +++ b/applications/services/bt/bt_service/bt.c @@ -11,9 +11,9 @@ #define TAG "BtSrv" -#define BT_RPC_EVENT_BUFF_SENT (1UL << 0) +#define BT_RPC_EVENT_BUFF_SENT (1UL << 0) #define BT_RPC_EVENT_DISCONNECTED (1UL << 1) -#define BT_RPC_EVENT_ALL (BT_RPC_EVENT_BUFF_SENT | BT_RPC_EVENT_DISCONNECTED) +#define BT_RPC_EVENT_ALL (BT_RPC_EVENT_BUFF_SENT | BT_RPC_EVENT_DISCONNECTED) #define ICON_SPACER 2 diff --git a/applications/services/bt/bt_service/bt_keys_storage.c b/applications/services/bt/bt_service/bt_keys_storage.c index cf06d663ba0..6392c2d6775 100644 --- a/applications/services/bt/bt_service/bt_keys_storage.c +++ b/applications/services/bt/bt_service/bt_keys_storage.c @@ -6,7 +6,7 @@ #include #define BT_KEYS_STORAGE_VERSION (0) -#define BT_KEYS_STORAGE_MAGIC (0x18) +#define BT_KEYS_STORAGE_MAGIC (0x18) #define TAG "BtKeyStorage" diff --git a/applications/services/bt/bt_settings.c b/applications/services/bt/bt_settings.c index 8a505f9e3f6..3602cf49774 100644 --- a/applications/services/bt/bt_settings.c +++ b/applications/services/bt/bt_settings.c @@ -4,9 +4,9 @@ #include #include -#define BT_SETTINGS_PATH INT_PATH(BT_SETTINGS_FILE_NAME) +#define BT_SETTINGS_PATH INT_PATH(BT_SETTINGS_FILE_NAME) #define BT_SETTINGS_VERSION (0) -#define BT_SETTINGS_MAGIC (0x19) +#define BT_SETTINGS_MAGIC (0x19) bool bt_settings_load(BtSettings* bt_settings) { furi_assert(bt_settings); diff --git a/applications/services/bt/bt_settings.h b/applications/services/bt/bt_settings.h index da43e149879..a4e76a12cc5 100644 --- a/applications/services/bt/bt_settings.h +++ b/applications/services/bt/bt_settings.h @@ -19,4 +19,4 @@ bool bt_settings_save(const BtSettings* bt_settings); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/cli/cli.c b/applications/services/cli/cli.c index 709d69768fd..0d8f52c04ec 100644 --- a/applications/services/cli/cli.c +++ b/applications/services/cli/cli.c @@ -75,7 +75,7 @@ size_t cli_read_timeout(Cli* cli, uint8_t* buffer, size_t size, uint32_t timeout bool cli_is_connected(Cli* cli) { furi_check(cli); if(cli->session != NULL) { - return (cli->session->is_connected()); + return cli->session->is_connected(); } return false; } diff --git a/applications/services/cli/cli_commands.c b/applications/services/cli/cli_commands.c index 7bf86c90cf5..5a1b11d8038 100644 --- a/applications/services/cli/cli_commands.c +++ b/applications/services/cli/cli_commands.c @@ -65,7 +65,8 @@ void cli_command_help(Cli* cli, FuriString* args, void* context) { CliCommandTree_it(it_left, cli->commands); CliCommandTree_it_t it_right; CliCommandTree_it(it_right, cli->commands); - for(size_t i = 0; i < commands_count_mid; i++) CliCommandTree_next(it_right); + for(size_t i = 0; i < commands_count_mid; i++) + CliCommandTree_next(it_right); // Iterate throw tree for(size_t i = 0; i < commands_count_mid; i++) { @@ -167,7 +168,7 @@ void cli_command_date(Cli* cli, FuriString* args, void* context) { } } -#define CLI_COMMAND_LOG_RING_SIZE 2048 +#define CLI_COMMAND_LOG_RING_SIZE 2048 #define CLI_COMMAND_LOG_BUFFER_SIZE 64 void cli_command_log_tx_callback(const uint8_t* buffer, size_t size, void* context) { @@ -398,8 +399,9 @@ static void cli_command_top(Cli* cli, FuriString* args, void* context) { uint32_t uptime = tick / furi_kernel_get_tick_frequency(); printf( - "Threads: %zu, Uptime: %luh%lum%lus\r\n", + "Threads: %zu, ISR Time: %0.2f%%, Uptime: %luh%lum%lus\r\n", furi_thread_list_size(thread_list), + (double)furi_thread_list_get_isr_time(thread_list), uptime / 60 / 60, uptime / 60 % 60, uptime % 60); diff --git a/applications/services/cli/cli_i.h b/applications/services/cli/cli_i.h index 8a82d961948..d4cac6e7d92 100644 --- a/applications/services/cli/cli_i.h +++ b/applications/services/cli/cli_i.h @@ -64,4 +64,4 @@ void cli_stdout_callback(void* _cookie, const char* data, size_t size); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/crypto/crypto_cli.c b/applications/services/crypto/crypto_cli.c index e1ea83613c8..744fa7151d1 100644 --- a/applications/services/crypto/crypto_cli.c +++ b/applications/services/crypto/crypto_cli.c @@ -15,7 +15,7 @@ void crypto_cli_print_usage(void) { printf("\thas_key \t - Check if secure enclave has key in slot\r\n"); printf( "\tstore_key \t - Store key in secure enclave. !!! NON-REVERSABLE OPERATION - READ MANUAL FIRST !!!\r\n"); -}; +} void crypto_cli_encrypt(Cli* cli, FuriString* args) { int key_slot = 0; diff --git a/applications/services/desktop/animations/animation_manager.c b/applications/services/desktop/animations/animation_manager.c index 44c0c228c4e..8e04e7894ef 100644 --- a/applications/services/desktop/animations/animation_manager.c +++ b/applications/services/desktop/animations/animation_manager.c @@ -14,14 +14,14 @@ #define TAG "AnimationManager" -#define HARDCODED_ANIMATION_NAME "L1_Tv_128x47" -#define NO_SD_ANIMATION_NAME "L1_NoSd_128x49" +#define HARDCODED_ANIMATION_NAME "L1_Tv_128x47" +#define NO_SD_ANIMATION_NAME "L1_NoSd_128x49" #define BAD_BATTERY_ANIMATION_NAME "L1_BadBattery_128x47" -#define NO_DB_ANIMATION_NAME "L0_NoDb_128x51" -#define BAD_SD_ANIMATION_NAME "L0_SdBad_128x51" -#define SD_OK_ANIMATION_NAME "L0_SdOk_128x51" -#define URL_ANIMATION_NAME "L0_Url_128x51" +#define NO_DB_ANIMATION_NAME "L0_NoDb_128x51" +#define BAD_SD_ANIMATION_NAME "L0_SdBad_128x51" +#define SD_OK_ANIMATION_NAME "L0_SdOk_128x51" +#define URL_ANIMATION_NAME "L0_Url_128x51" #define NEW_MAIL_ANIMATION_NAME "L0_NewMail_128x51" typedef enum { @@ -32,11 +32,6 @@ typedef enum { } AnimationManagerState; struct AnimationManager { - bool sd_show_url; - bool sd_shown_no_db; - bool sd_shown_sd_ok; - bool levelup_pending; - bool levelup_active; AnimationManagerState state; FuriPubSubSubscription* pubsub_subscription_storage; FuriPubSubSubscription* pubsub_subscription_dolphin; @@ -51,7 +46,14 @@ struct AnimationManager { FuriString* freezed_animation_name; int32_t freezed_animation_time_left; ViewStack* view_stack; - bool dummy_mode; + + bool dummy_mode : 1; + bool blocking_shown_url : 1; + bool blocking_shown_sd_bad : 1; + bool blocking_shown_no_db : 1; + bool blocking_shown_sd_ok : 1; + bool levelup_pending : 1; + bool levelup_active : 1; }; static StorageAnimation* @@ -214,27 +216,31 @@ static bool animation_manager_check_blocking(AnimationManager* animation_manager FS_Error sd_status = storage_sd_status(storage); if(sd_status == FSE_INTERNAL) { - blocking_animation = animation_storage_find_animation(BAD_SD_ANIMATION_NAME); - furi_assert(blocking_animation); + if(!animation_manager->blocking_shown_sd_bad) { + blocking_animation = animation_storage_find_animation(BAD_SD_ANIMATION_NAME); + furi_assert(blocking_animation); + animation_manager->blocking_shown_sd_bad = true; + } } else if(sd_status == FSE_NOT_READY) { - animation_manager->sd_shown_sd_ok = false; - animation_manager->sd_shown_no_db = false; + animation_manager->blocking_shown_sd_bad = false; + animation_manager->blocking_shown_sd_ok = false; + animation_manager->blocking_shown_no_db = false; } else if(sd_status == FSE_OK) { - if(!animation_manager->sd_shown_sd_ok) { + if(!animation_manager->blocking_shown_sd_ok) { blocking_animation = animation_storage_find_animation(SD_OK_ANIMATION_NAME); furi_assert(blocking_animation); - animation_manager->sd_shown_sd_ok = true; - } else if(!animation_manager->sd_shown_no_db) { + animation_manager->blocking_shown_sd_ok = true; + } else if(!animation_manager->blocking_shown_no_db) { if(!storage_file_exists(storage, EXT_PATH("Manifest"))) { blocking_animation = animation_storage_find_animation(NO_DB_ANIMATION_NAME); furi_assert(blocking_animation); - animation_manager->sd_shown_no_db = true; - animation_manager->sd_show_url = true; + animation_manager->blocking_shown_no_db = true; + animation_manager->blocking_shown_url = true; } - } else if(animation_manager->sd_show_url) { + } else if(animation_manager->blocking_shown_url) { blocking_animation = animation_storage_find_animation(URL_ANIMATION_NAME); furi_assert(blocking_animation); - animation_manager->sd_show_url = false; + animation_manager->blocking_shown_url = false; } } @@ -299,7 +305,7 @@ AnimationManager* animation_manager_alloc(void) { dolphin_get_pubsub(dolphin), animation_manager_check_blocking_callback, animation_manager); furi_record_close(RECORD_DOLPHIN); - animation_manager->sd_shown_sd_ok = true; + animation_manager->blocking_shown_sd_ok = true; if(!animation_manager_check_blocking(animation_manager)) { animation_manager_start_new_idle(animation_manager); } diff --git a/applications/services/desktop/animations/animation_storage.c b/applications/services/desktop/animations/animation_storage.c index 1db61f1abf6..9ee85727ba1 100644 --- a/applications/services/desktop/animations/animation_storage.c +++ b/applications/services/desktop/animations/animation_storage.c @@ -11,11 +11,12 @@ #include #include -#define ANIMATION_META_FILE "meta.txt" -#define ANIMATION_DIR EXT_PATH("dolphin") -#define ANIMATION_MANIFEST_FILE ANIMATION_DIR "/manifest.txt" #define TAG "AnimationStorage" +#define ANIMATION_META_FILE "meta.txt" +#define ANIMATION_DIR EXT_PATH("dolphin") +#define ANIMATION_MANIFEST_FILE ANIMATION_DIR "/manifest.txt" + static void animation_storage_free_bubbles(BubbleAnimation* animation); static void animation_storage_free_frames(BubbleAnimation* animation); static void animation_storage_free_animation(BubbleAnimation** storage_animation); diff --git a/applications/services/desktop/desktop_i.h b/applications/services/desktop/desktop_i.h index 634f0ee00dc..4bcbb6585a5 100644 --- a/applications/services/desktop/desktop_i.h +++ b/applications/services/desktop/desktop_i.h @@ -84,7 +84,7 @@ struct Desktop { DesktopClock clock; bool in_transition : 1; - bool locked : 1; + bool locked : 1; FuriSemaphore* animation_semaphore; }; diff --git a/applications/services/desktop/desktop_settings.h b/applications/services/desktop/desktop_settings.h index 5cf9cc4c648..54be6aaa917 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -10,9 +10,9 @@ #define DESKTOP_SETTINGS_VER (10) -#define DESKTOP_SETTINGS_PATH INT_PATH(DESKTOP_SETTINGS_FILE_NAME) +#define DESKTOP_SETTINGS_PATH INT_PATH(DESKTOP_SETTINGS_FILE_NAME) #define DESKTOP_SETTINGS_MAGIC (0x17) -#define PIN_MAX_LENGTH 12 +#define PIN_MAX_LENGTH 12 #define DESKTOP_SETTINGS_RUN_PIN_SETUP_ARG "run_pin_setup" @@ -32,8 +32,8 @@ DESKTOP_SETTINGS_MAGIC, \ DESKTOP_SETTINGS_VER) -#define MAX_PIN_SIZE 10 -#define MIN_PIN_SIZE 4 +#define MAX_PIN_SIZE 10 +#define MIN_PIN_SIZE 4 #define MAX_APP_LENGTH 128 typedef enum { diff --git a/applications/services/desktop/helpers/slideshow.c b/applications/services/desktop/helpers/slideshow.c index ec02f27a1d4..565449cbbd3 100644 --- a/applications/services/desktop/helpers/slideshow.c +++ b/applications/services/desktop/helpers/slideshow.c @@ -5,7 +5,7 @@ #include #include -#define SLIDESHOW_MAGIC 0x72676468 +#define SLIDESHOW_MAGIC 0x72676468 #define SLIDESHOW_MAX_SUPPORTED_VERSION 1 struct Slideshow { diff --git a/applications/services/desktop/scenes/desktop_scene_config.h b/applications/services/desktop/scenes/desktop_scene_config.h index 34d00054333..2a536603f6a 100644 --- a/applications/services/desktop/scenes/desktop_scene_config.h +++ b/applications/services/desktop/scenes/desktop_scene_config.h @@ -7,4 +7,4 @@ ADD_SCENE(desktop, locked, Locked) ADD_SCENE(desktop, pin_input, PinInput) ADD_SCENE(desktop, pin_timeout, PinTimeout) ADD_SCENE(desktop, slideshow, Slideshow) -ADD_SCENE(desktop, secure_enclave, SecureEnclave) \ No newline at end of file +ADD_SCENE(desktop, secure_enclave, SecureEnclave) diff --git a/applications/services/desktop/scenes/desktop_scene_i.h b/applications/services/desktop/scenes/desktop_scene_i.h index 953f8c83601..f481733aca8 100644 --- a/applications/services/desktop/scenes/desktop_scene_i.h +++ b/applications/services/desktop/scenes/desktop_scene_i.h @@ -1,4 +1,4 @@ #pragma once -#define SCENE_LOCKED_FIRST_ENTER 0 +#define SCENE_LOCKED_FIRST_ENTER 0 #define SCENE_LOCKED_REPEAT_ENTER 1 diff --git a/applications/services/desktop/scenes/desktop_scene_locked.c b/applications/services/desktop/scenes/desktop_scene_locked.c index 6d432858a50..846b2b5412d 100644 --- a/applications/services/desktop/scenes/desktop_scene_locked.c +++ b/applications/services/desktop/scenes/desktop_scene_locked.c @@ -14,7 +14,7 @@ #include "desktop_scene_i.h" #define WRONG_PIN_HEADER_TIMEOUT 3000 -#define INPUT_PIN_VIEW_TIMEOUT 15000 +#define INPUT_PIN_VIEW_TIMEOUT 15000 static void desktop_scene_locked_callback(DesktopEvent event, void* context) { Desktop* desktop = (Desktop*)context; diff --git a/applications/services/desktop/scenes/desktop_scene_pin_input.c b/applications/services/desktop/scenes/desktop_scene_pin_input.c index b1c0d4c8523..6f5bfe8cb32 100644 --- a/applications/services/desktop/scenes/desktop_scene_pin_input.c +++ b/applications/services/desktop/scenes/desktop_scene_pin_input.c @@ -14,7 +14,7 @@ #include "desktop_scene.h" #define WRONG_PIN_HEADER_TIMEOUT 3000 -#define INPUT_PIN_VIEW_TIMEOUT 15000 +#define INPUT_PIN_VIEW_TIMEOUT 15000 typedef struct { FuriTimer* timer; diff --git a/applications/services/desktop/views/desktop_view_locked.c b/applications/services/desktop/views/desktop_view_locked.c index 34d92b0ddb2..81d3fc65f55 100644 --- a/applications/services/desktop/views/desktop_view_locked.c +++ b/applications/services/desktop/views/desktop_view_locked.c @@ -10,17 +10,17 @@ #include "../desktop_i.h" #include "desktop_view_locked.h" -#define DOOR_MOVING_INTERVAL_MS (1000 / 16) -#define LOCKED_HINT_TIMEOUT_MS (1000) +#define DOOR_MOVING_INTERVAL_MS (1000 / 16) +#define LOCKED_HINT_TIMEOUT_MS (1000) #define UNLOCKED_HINT_TIMEOUT_MS (2000) #define DOOR_OFFSET_START (-55) -#define DOOR_OFFSET_END (0) +#define DOOR_OFFSET_END (0) #define DOOR_L_FINAL_POS (0) #define DOOR_R_FINAL_POS (60) -#define UNLOCK_CNT (3) +#define UNLOCK_CNT (3) #define UNLOCK_RST_TIMEOUT (600) struct DesktopViewLocked { diff --git a/applications/services/desktop/views/desktop_view_pin_input.c b/applications/services/desktop/views/desktop_view_pin_input.c index c859b9b023d..965b5cceb7c 100644 --- a/applications/services/desktop/views/desktop_view_pin_input.c +++ b/applications/services/desktop/views/desktop_view_pin_input.c @@ -11,8 +11,8 @@ #define NO_ACTIVITY_TIMEOUT 15000 #define PIN_CELL_WIDTH 13 -#define DEFAULT_PIN_X 64 -#define DEFAULT_PIN_Y 32 +#define DEFAULT_PIN_X 64 +#define DEFAULT_PIN_Y 32 struct DesktopViewPinInput { View* view; diff --git a/applications/services/desktop/views/desktop_view_slideshow.c b/applications/services/desktop/views/desktop_view_slideshow.c index de8c1cb8625..6aae449c889 100644 --- a/applications/services/desktop/views/desktop_view_slideshow.c +++ b/applications/services/desktop/views/desktop_view_slideshow.c @@ -6,7 +6,7 @@ #include "../helpers/slideshow.h" #define DESKTOP_SLIDESHOW_POWEROFF_SHORT 5000 -#define DESKTOP_SLIDESHOW_POWEROFF_LONG (60 * 60 * 1000) +#define DESKTOP_SLIDESHOW_POWEROFF_LONG (60 * 60 * 1000) struct DesktopSlideshowView { View* view; @@ -136,4 +136,4 @@ void desktop_view_slideshow_set_callback( furi_assert(callback); instance->callback = callback; instance->context = context; -} \ No newline at end of file +} diff --git a/applications/services/dolphin/dolphin.c b/applications/services/dolphin/dolphin.c index 4a75241e6c6..95982f1af83 100644 --- a/applications/services/dolphin/dolphin.c +++ b/applications/services/dolphin/dolphin.c @@ -1,22 +1,48 @@ -#include "dolphin.h" -#include "helpers/dolphin_state.h" #include "dolphin_i.h" + #include -#include -#include -#define DOLPHIN_LOCK_EVENT_FLAG (0x1) #define TAG "Dolphin" -#define HOURS_IN_TICKS(x) ((x) * 60 * 60 * 1000) -static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin); +#define DOLPHIN_LOCK_EVENT_FLAG (0x1) +#define EVENT_QUEUE_SIZE (8) + +#define SECONDS_IN_TICKS(x) ((x) * 1000UL) +#define MINUTES_IN_TICKS(x) (SECONDS_IN_TICKS(x) * 60UL) +#define HOURS_IN_TICKS(x) (MINUTES_IN_TICKS(x) * 60UL) +#define DATE_IN_TICKS(h, m, s) (HOURS_IN_TICKS(h) + MINUTES_IN_TICKS(m) + SECONDS_IN_TICKS(s)) + +#define FLUSH_TIMEOUT_TICKS (SECONDS_IN_TICKS(30UL)) + +#ifndef DOLPHIN_DEBUG +#define BUTTHURT_INCREASE_PERIOD_TICKS (HOURS_IN_TICKS(48UL)) +#define CLEAR_LIMITS_PERIOD_TICKS (HOURS_IN_TICKS(24UL)) +#define CLEAR_LIMITS_UPDATE_PERIOD_TICKS (HOURS_IN_TICKS(1UL)) +#else +#define BUTTHURT_INCREASE_PERIOD_TICKS (SECONDS_IN_TICKS(30UL)) +#define CLEAR_LIMITS_PERIOD_TICKS (MINUTES_IN_TICKS(1)) +#define CLEAR_LIMITS_UPDATE_PERIOD_TICKS (SECONDS_IN_TICKS(5UL)) +#endif + +#define CLEAR_LIMITS_UPDATE_THRESHOLD_TICKS (MINUTES_IN_TICKS(5UL)) + +#define CLEAR_LIMITS_TIME_HOURS (5UL) +#define CLEAR_LIMITS_TIME_TICKS (HOURS_IN_TICKS(CLEAR_LIMITS_TIME_HOURS)) + +static void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event); +static void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event); + +// Public API void dolphin_deed(DolphinDeed deed) { - Dolphin* dolphin = (Dolphin*)furi_record_open(RECORD_DOLPHIN); + Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN); + DolphinEvent event; event.type = DolphinEventTypeDeed; event.deed = deed; + dolphin_event_send_async(dolphin, &event); + furi_record_close(RECORD_DOLPHIN); } @@ -43,52 +69,75 @@ void dolphin_flush(Dolphin* dolphin) { dolphin_event_send_wait(dolphin, &event); } -void dolphin_butthurt_timer_callback(void* context) { - Dolphin* dolphin = context; - furi_assert(dolphin); +void dolphin_upgrade_level(Dolphin* dolphin) { + furi_check(dolphin); DolphinEvent event; - event.type = DolphinEventTypeIncreaseButthurt; + event.type = DolphinEventTypeLevel; + dolphin_event_send_async(dolphin, &event); } -void dolphin_flush_timer_callback(void* context) { +FuriPubSub* dolphin_get_pubsub(Dolphin* dolphin) { + furi_check(dolphin); + return dolphin->pubsub; +} + +// Private functions + +static void dolphin_butthurt_timer_callback(void* context) { Dolphin* dolphin = context; furi_assert(dolphin); - DolphinEvent event; - event.type = DolphinEventTypeFlush; - dolphin_event_send_async(dolphin, &event); + FURI_LOG_I(TAG, "Increase butthurt"); + dolphin_state_butthurted(dolphin->state); + dolphin_state_save(dolphin->state); } -void dolphin_clear_limits_timer_callback(void* context) { +static void dolphin_flush_timer_callback(void* context) { Dolphin* dolphin = context; furi_assert(dolphin); - furi_timer_start(dolphin->clear_limits_timer, HOURS_IN_TICKS(24)); + FURI_LOG_I(TAG, "Flush stats"); + dolphin_state_save(dolphin->state); +} - DolphinEvent event; - event.type = DolphinEventTypeClearLimits; - dolphin_event_send_async(dolphin, &event); +static void dolphin_clear_limits_timer_callback(void* context) { + Dolphin* dolphin = context; + furi_assert(dolphin); + + FURI_LOG_I(TAG, "Clear limits"); + dolphin_state_clear_limits(dolphin->state); + dolphin_state_save(dolphin->state); } -Dolphin* dolphin_alloc(void) { +static Dolphin* dolphin_alloc(void) { Dolphin* dolphin = malloc(sizeof(Dolphin)); dolphin->state = dolphin_state_alloc(); - dolphin->event_queue = furi_message_queue_alloc(8, sizeof(DolphinEvent)); dolphin->pubsub = furi_pubsub_alloc(); - dolphin->butthurt_timer = - furi_timer_alloc(dolphin_butthurt_timer_callback, FuriTimerTypePeriodic, dolphin); - dolphin->flush_timer = - furi_timer_alloc(dolphin_flush_timer_callback, FuriTimerTypeOnce, dolphin); - dolphin->clear_limits_timer = - furi_timer_alloc(dolphin_clear_limits_timer_callback, FuriTimerTypePeriodic, dolphin); + dolphin->event_queue = furi_message_queue_alloc(EVENT_QUEUE_SIZE, sizeof(DolphinEvent)); + dolphin->event_loop = furi_event_loop_alloc(); + + dolphin->butthurt_timer = furi_event_loop_timer_alloc( + dolphin->event_loop, + dolphin_butthurt_timer_callback, + FuriEventLoopTimerTypePeriodic, + dolphin); + + dolphin->flush_timer = furi_event_loop_timer_alloc( + dolphin->event_loop, dolphin_flush_timer_callback, FuriEventLoopTimerTypeOnce, dolphin); + + dolphin->clear_limits_timer = furi_event_loop_timer_alloc( + dolphin->event_loop, + dolphin_clear_limits_timer_callback, + FuriEventLoopTimerTypePeriodic, + dolphin); return dolphin; } -void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event) { +static void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event) { furi_assert(dolphin); furi_assert(event); event->flag = NULL; @@ -96,7 +145,7 @@ void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event) { furi_message_queue_put(dolphin->event_queue, event, FuriWaitForever) == FuriStatusOk); } -void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event) { +static void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event) { furi_assert(dolphin); furi_assert(event); @@ -110,39 +159,81 @@ void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event) { furi_event_flag_free(event->flag); } -void dolphin_event_release(Dolphin* dolphin, DolphinEvent* event) { - UNUSED(dolphin); +static void dolphin_event_release(DolphinEvent* event) { if(event->flag) { furi_event_flag_set(event->flag, DOLPHIN_LOCK_EVENT_FLAG); } } -FuriPubSub* dolphin_get_pubsub(Dolphin* dolphin) { - furi_check(dolphin); - return dolphin->pubsub; -} +static void dolphin_update_clear_limits_timer_period(void* context) { + furi_assert(context); + Dolphin* dolphin = context; -static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin) { - furi_assert(dolphin); - uint32_t now_ticks = furi_get_tick(); - uint32_t timer_expires_at = furi_timer_get_expire_time(dolphin->clear_limits_timer); + uint32_t time_to_clear_limits = + furi_event_loop_timer_get_remaining_time(dolphin->clear_limits_timer); - if((timer_expires_at - now_ticks) > HOURS_IN_TICKS(0.1)) { + if(time_to_clear_limits > CLEAR_LIMITS_UPDATE_THRESHOLD_TICKS) { DateTime date; furi_hal_rtc_get_datetime(&date); - uint32_t now_time_in_ms = ((date.hour * 60 + date.minute) * 60 + date.second) * 1000; - uint32_t time_to_clear_limits = 0; - if(date.hour < 5) { - time_to_clear_limits = HOURS_IN_TICKS(5) - now_time_in_ms; + const uint32_t now_time_ticks = DATE_IN_TICKS(date.hour, date.minute, date.second); + + if(date.hour < CLEAR_LIMITS_TIME_HOURS) { + time_to_clear_limits = CLEAR_LIMITS_TIME_TICKS - now_time_ticks; } else { - time_to_clear_limits = HOURS_IN_TICKS(24 + 5) - now_time_in_ms; + time_to_clear_limits = + CLEAR_LIMITS_PERIOD_TICKS + CLEAR_LIMITS_TIME_TICKS - now_time_ticks; } - furi_timer_start(dolphin->clear_limits_timer, time_to_clear_limits); + furi_event_loop_timer_start(dolphin->clear_limits_timer, time_to_clear_limits); } + + FURI_LOG_D(TAG, "Daily limits reset in %lu ms", time_to_clear_limits); } +static bool dolphin_process_event(FuriMessageQueue* queue, void* context) { + UNUSED(queue); + + Dolphin* dolphin = context; + DolphinEvent event; + + FuriStatus status = furi_message_queue_get(dolphin->event_queue, &event, 0); + furi_check(status == FuriStatusOk); + + if(event.type == DolphinEventTypeDeed) { + dolphin_state_on_deed(dolphin->state, event.deed); + + DolphinPubsubEvent event = DolphinPubsubEventUpdate; + furi_pubsub_publish(dolphin->pubsub, &event); + furi_event_loop_timer_start(dolphin->butthurt_timer, BUTTHURT_INCREASE_PERIOD_TICKS); + furi_event_loop_timer_start(dolphin->flush_timer, FLUSH_TIMEOUT_TICKS); + + } else if(event.type == DolphinEventTypeStats) { + event.stats->icounter = dolphin->state->data.icounter; + event.stats->butthurt = dolphin->state->data.butthurt; + event.stats->timestamp = dolphin->state->data.timestamp; + event.stats->level = dolphin_get_level(dolphin->state->data.icounter); + event.stats->level_up_is_pending = + !dolphin_state_xp_to_levelup(dolphin->state->data.icounter); + + } else if(event.type == DolphinEventTypeFlush) { + furi_event_loop_timer_start(dolphin->flush_timer, FLUSH_TIMEOUT_TICKS); + + } else if(event.type == DolphinEventTypeLevel) { + dolphin_state_increase_level(dolphin->state); + furi_event_loop_timer_start(dolphin->flush_timer, FLUSH_TIMEOUT_TICKS); + + } else { + furi_crash(); + } + + dolphin_event_release(&event); + + return true; +} + +// Application thread + int32_t dolphin_srv(void* p) { UNUSED(p); @@ -157,54 +248,27 @@ int32_t dolphin_srv(void* p) { furi_record_create(RECORD_DOLPHIN, dolphin); dolphin_state_load(dolphin->state); - furi_timer_restart(dolphin->butthurt_timer, HOURS_IN_TICKS(2 * 24)); - dolphin_update_clear_limits_timer_period(dolphin); - furi_timer_restart(dolphin->clear_limits_timer, HOURS_IN_TICKS(24)); - DolphinEvent event; - while(1) { - if(furi_message_queue_get(dolphin->event_queue, &event, HOURS_IN_TICKS(1)) == - FuriStatusOk) { - if(event.type == DolphinEventTypeDeed) { - dolphin_state_on_deed(dolphin->state, event.deed); - DolphinPubsubEvent event = DolphinPubsubEventUpdate; - furi_pubsub_publish(dolphin->pubsub, &event); - furi_timer_restart(dolphin->butthurt_timer, HOURS_IN_TICKS(2 * 24)); - furi_timer_restart(dolphin->flush_timer, 30 * 1000); - } else if(event.type == DolphinEventTypeStats) { - event.stats->icounter = dolphin->state->data.icounter; - event.stats->butthurt = dolphin->state->data.butthurt; - event.stats->timestamp = dolphin->state->data.timestamp; - event.stats->level = dolphin_get_level(dolphin->state->data.icounter); - event.stats->level_up_is_pending = - !dolphin_state_xp_to_levelup(dolphin->state->data.icounter); - } else if(event.type == DolphinEventTypeFlush) { - FURI_LOG_I(TAG, "Flush stats"); - dolphin_state_save(dolphin->state); - } else if(event.type == DolphinEventTypeClearLimits) { - FURI_LOG_I(TAG, "Clear limits"); - dolphin_state_clear_limits(dolphin->state); - dolphin_state_save(dolphin->state); - } else if(event.type == DolphinEventTypeIncreaseButthurt) { - FURI_LOG_I(TAG, "Increase butthurt"); - dolphin_state_butthurted(dolphin->state); - dolphin_state_save(dolphin->state); - } - dolphin_event_release(dolphin, &event); - } else { - /* once per hour check rtc time is not changed */ - dolphin_update_clear_limits_timer_period(dolphin); - } - } + furi_event_loop_message_queue_subscribe( + dolphin->event_loop, + dolphin->event_queue, + FuriEventLoopEventIn, + dolphin_process_event, + dolphin); - furi_crash("That was unexpected"); + furi_event_loop_timer_start(dolphin->butthurt_timer, BUTTHURT_INCREASE_PERIOD_TICKS); + furi_event_loop_timer_start(dolphin->clear_limits_timer, CLEAR_LIMITS_PERIOD_TICKS); - return 0; -} + furi_event_loop_tick_set( + dolphin->event_loop, + CLEAR_LIMITS_UPDATE_PERIOD_TICKS, + dolphin_update_clear_limits_timer_period, + dolphin); -void dolphin_upgrade_level(Dolphin* dolphin) { - furi_check(dolphin); + furi_event_loop_pend_callback( + dolphin->event_loop, dolphin_update_clear_limits_timer_period, dolphin); - dolphin_state_increase_level(dolphin->state); - dolphin_flush(dolphin); + furi_event_loop_run(dolphin->event_loop); + + return 0; } diff --git a/applications/services/dolphin/dolphin.h b/applications/services/dolphin/dolphin.h index 1035247e718..01da7f3f239 100644 --- a/applications/services/dolphin/dolphin.h +++ b/applications/services/dolphin/dolphin.h @@ -1,10 +1,9 @@ #pragma once -#include "helpers/dolphin_deed.h" - -#include -#include #include +#include + +#include "helpers/dolphin_deed.h" #ifdef __cplusplus extern "C" { diff --git a/applications/services/dolphin/dolphin_i.h b/applications/services/dolphin/dolphin_i.h index 666e039423f..d4add808ade 100644 --- a/applications/services/dolphin/dolphin_i.h +++ b/applications/services/dolphin/dolphin_i.h @@ -1,8 +1,8 @@ #pragma once -#include #include -#include + +#include #include "dolphin.h" #include "helpers/dolphin_state.h" @@ -11,8 +11,7 @@ typedef enum { DolphinEventTypeDeed, DolphinEventTypeStats, DolphinEventTypeFlush, - DolphinEventTypeIncreaseButthurt, - DolphinEventTypeClearLimits, + DolphinEventTypeLevel, } DolphinEventType; typedef struct { @@ -25,20 +24,11 @@ typedef struct { } DolphinEvent; struct Dolphin { - // State DolphinState* state; - // Queue - FuriMessageQueue* event_queue; FuriPubSub* pubsub; - FuriTimer* butthurt_timer; - FuriTimer* flush_timer; - FuriTimer* clear_limits_timer; + FuriMessageQueue* event_queue; + FuriEventLoop* event_loop; + FuriEventLoopTimer* butthurt_timer; + FuriEventLoopTimer* flush_timer; + FuriEventLoopTimer* clear_limits_timer; }; - -Dolphin* dolphin_alloc(void); - -void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event); - -void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event); - -void dolphin_event_release(Dolphin* dolphin, DolphinEvent* event); diff --git a/applications/services/dolphin/helpers/dolphin_state.c b/applications/services/dolphin/helpers/dolphin_state.c index 724060e53b8..5216b961dcf 100644 --- a/applications/services/dolphin/helpers/dolphin_state.c +++ b/applications/services/dolphin/helpers/dolphin_state.c @@ -10,13 +10,13 @@ #define TAG "DolphinState" -#define DOLPHIN_STATE_PATH INT_PATH(DOLPHIN_STATE_FILE_NAME) -#define DOLPHIN_STATE_HEADER_MAGIC 0xD0 +#define DOLPHIN_STATE_PATH INT_PATH(DOLPHIN_STATE_FILE_NAME) +#define DOLPHIN_STATE_HEADER_MAGIC 0xD0 #define DOLPHIN_STATE_HEADER_VERSION 0x01 -#define LEVEL2_THRESHOLD 300 -#define LEVEL3_THRESHOLD 1800 -#define BUTTHURT_MAX 14 -#define BUTTHURT_MIN 0 +#define LEVEL2_THRESHOLD 300 +#define LEVEL3_THRESHOLD 1800 +#define BUTTHURT_MAX 14 +#define BUTTHURT_MIN 0 DolphinState* dolphin_state_alloc(void) { return malloc(sizeof(DolphinState)); diff --git a/applications/services/expansion/expansion_settings.c b/applications/services/expansion/expansion_settings.c index 691c454a57a..ca48a290319 100644 --- a/applications/services/expansion/expansion_settings.c +++ b/applications/services/expansion/expansion_settings.c @@ -5,9 +5,9 @@ #include "expansion_settings_filename.h" -#define EXPANSION_SETTINGS_PATH INT_PATH(EXPANSION_SETTINGS_FILE_NAME) +#define EXPANSION_SETTINGS_PATH INT_PATH(EXPANSION_SETTINGS_FILE_NAME) #define EXPANSION_SETTINGS_VERSION (0) -#define EXPANSION_SETTINGS_MAGIC (0xEA) +#define EXPANSION_SETTINGS_MAGIC (0xEA) bool expansion_settings_load(ExpansionSettings* settings) { furi_assert(settings); diff --git a/applications/services/expansion/expansion_worker.c b/applications/services/expansion/expansion_worker.c index fd92063d258..449d02cffc9 100644 --- a/applications/services/expansion/expansion_worker.c +++ b/applications/services/expansion/expansion_worker.c @@ -11,7 +11,7 @@ #define TAG "ExpansionSrv" -#define EXPANSION_WORKER_STACK_SZIE (768UL) +#define EXPANSION_WORKER_STACK_SZIE (768UL) #define EXPANSION_WORKER_BUFFER_SIZE (sizeof(ExpansionFrame) + sizeof(ExpansionFrameChecksum)) typedef enum { diff --git a/applications/services/gui/elements.h b/applications/services/gui/elements.h index 54d78420ea3..88a00481514 100644 --- a/applications/services/gui/elements.h +++ b/applications/services/gui/elements.h @@ -16,9 +16,9 @@ extern "C" { #endif -#define ELEMENTS_MAX_LINES_NUM (7) -#define ELEMENTS_BOLD_MARKER '#' -#define ELEMENTS_MONO_MARKER '*' +#define ELEMENTS_MAX_LINES_NUM (7) +#define ELEMENTS_BOLD_MARKER '#' +#define ELEMENTS_MONO_MARKER '*' #define ELEMENTS_INVERSE_MARKER '!' /** Draw progress bar. diff --git a/applications/services/gui/gui_i.h b/applications/services/gui/gui_i.h index 3ca9c05c93e..8bd3215f97c 100644 --- a/applications/services/gui/gui_i.h +++ b/applications/services/gui/gui_i.h @@ -17,29 +17,29 @@ #include "view_port.h" #include "view_port_i.h" -#define GUI_DISPLAY_WIDTH 128 +#define GUI_DISPLAY_WIDTH 128 #define GUI_DISPLAY_HEIGHT 64 -#define GUI_STATUS_BAR_X 0 -#define GUI_STATUS_BAR_Y 0 -#define GUI_STATUS_BAR_WIDTH GUI_DISPLAY_WIDTH +#define GUI_STATUS_BAR_X 0 +#define GUI_STATUS_BAR_Y 0 +#define GUI_STATUS_BAR_WIDTH GUI_DISPLAY_WIDTH /* 0-1 pixels for upper thin frame * 2-9 pixels for icons (battery, sd card, etc) * 10-12 pixels for lower bold line */ -#define GUI_STATUS_BAR_HEIGHT 13 +#define GUI_STATUS_BAR_HEIGHT 13 /* icon itself area (battery, sd card, etc) excluding frame. * painted 2 pixels below GUI_STATUS_BAR_X. */ #define GUI_STATUS_BAR_WORKAREA_HEIGHT 8 -#define GUI_WINDOW_X 0 -#define GUI_WINDOW_Y GUI_STATUS_BAR_HEIGHT -#define GUI_WINDOW_WIDTH GUI_DISPLAY_WIDTH +#define GUI_WINDOW_X 0 +#define GUI_WINDOW_Y GUI_STATUS_BAR_HEIGHT +#define GUI_WINDOW_WIDTH GUI_DISPLAY_WIDTH #define GUI_WINDOW_HEIGHT (GUI_DISPLAY_HEIGHT - GUI_WINDOW_Y) -#define GUI_THREAD_FLAG_DRAW (1 << 0) +#define GUI_THREAD_FLAG_DRAW (1 << 0) #define GUI_THREAD_FLAG_INPUT (1 << 1) -#define GUI_THREAD_FLAG_ALL (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT) +#define GUI_THREAD_FLAG_ALL (GUI_THREAD_FLAG_DRAW | GUI_THREAD_FLAG_INPUT) ARRAY_DEF(ViewPortArray, ViewPort*, M_PTR_OPLIST); diff --git a/applications/services/gui/modules/button_menu.c b/applications/services/gui/modules/button_menu.c index ed76bd2b3a4..d9c178dd235 100644 --- a/applications/services/gui/modules/button_menu.c +++ b/applications/services/gui/modules/button_menu.c @@ -10,10 +10,10 @@ #include #include -#define ITEM_FIRST_OFFSET 17 -#define ITEM_NEXT_OFFSET 4 -#define ITEM_HEIGHT 14 -#define ITEM_WIDTH 64 +#define ITEM_FIRST_OFFSET 17 +#define ITEM_NEXT_OFFSET 4 +#define ITEM_HEIGHT 14 +#define ITEM_WIDTH 64 #define BUTTONS_PER_SCREEN 6 struct ButtonMenuItem { @@ -321,8 +321,7 @@ void button_menu_reset(ButtonMenu* button_menu) { void button_menu_set_header(ButtonMenu* button_menu, const char* header) { furi_check(button_menu); - with_view_model( - button_menu->view, ButtonMenuModel * model, { model->header = header; }, true); + with_view_model(button_menu->view, ButtonMenuModel * model, { model->header = header; }, true); } ButtonMenuItem* button_menu_add_item( diff --git a/applications/services/gui/modules/button_panel.c b/applications/services/gui/modules/button_panel.c index 0aa9dd005d0..9301870efd5 100644 --- a/applications/services/gui/modules/button_panel.c +++ b/applications/services/gui/modules/button_panel.c @@ -439,4 +439,4 @@ void button_panel_add_icon( icon->name_selected = icon_name; }, true); -} \ No newline at end of file +} diff --git a/applications/services/gui/modules/byte_input.c b/applications/services/gui/modules/byte_input.c index c33ad3e07f8..6e85401dabe 100644 --- a/applications/services/gui/modules/byte_input.c +++ b/applications/services/gui/modules/byte_input.c @@ -868,6 +868,5 @@ void byte_input_set_result_callback( void byte_input_set_header_text(ByteInput* byte_input, const char* text) { furi_check(byte_input); - with_view_model( - byte_input->view, ByteInputModel * model, { model->header = text; }, true); + with_view_model(byte_input->view, ByteInputModel * model, { model->header = text; }, true); } diff --git a/applications/services/gui/modules/dialog_ex.c b/applications/services/gui/modules/dialog_ex.c index 5fd42be6c6d..7171f6892b8 100644 --- a/applications/services/gui/modules/dialog_ex.c +++ b/applications/services/gui/modules/dialog_ex.c @@ -257,20 +257,17 @@ void dialog_ex_set_icon(DialogEx* dialog_ex, uint8_t x, uint8_t y, const Icon* i void dialog_ex_set_left_button_text(DialogEx* dialog_ex, const char* text) { furi_check(dialog_ex); - with_view_model( - dialog_ex->view, DialogExModel * model, { model->left_text = text; }, true); + with_view_model(dialog_ex->view, DialogExModel * model, { model->left_text = text; }, true); } void dialog_ex_set_center_button_text(DialogEx* dialog_ex, const char* text) { furi_check(dialog_ex); - with_view_model( - dialog_ex->view, DialogExModel * model, { model->center_text = text; }, true); + with_view_model(dialog_ex->view, DialogExModel * model, { model->center_text = text; }, true); } void dialog_ex_set_right_button_text(DialogEx* dialog_ex, const char* text) { furi_check(dialog_ex); - with_view_model( - dialog_ex->view, DialogExModel * model, { model->right_text = text; }, true); + with_view_model(dialog_ex->view, DialogExModel * model, { model->right_text = text; }, true); } void dialog_ex_reset(DialogEx* dialog_ex) { diff --git a/applications/services/gui/modules/file_browser.c b/applications/services/gui/modules/file_browser.c index 9e0a7560dd7..477e1fb7d53 100644 --- a/applications/services/gui/modules/file_browser.c +++ b/applications/services/gui/modules/file_browser.c @@ -13,17 +13,17 @@ #include #include -#define LIST_ITEMS 5u -#define MAX_LEN_PX 110 +#define LIST_ITEMS 5u +#define MAX_LEN_PX 110 #define FRAME_HEIGHT 12 -#define Y_OFFSET 3 +#define Y_OFFSET 3 #define ITEM_LIST_LEN_MAX 50 #define CUSTOM_ICON_MAX_SIZE 32 #define SCROLL_INTERVAL (333) -#define SCROLL_DELAY (2) +#define SCROLL_DELAY (2) typedef enum { BrowserItemTypeLoading, @@ -142,15 +142,13 @@ static void browser_long_load_cb(void* context); static void file_browser_scroll_timer_callback(void* context) { furi_check(context); FileBrowser* browser = context; - with_view_model( - browser->view, FileBrowserModel * model, { model->scroll_counter++; }, true); + with_view_model(browser->view, FileBrowserModel * model, { model->scroll_counter++; }, true); } static void file_browser_view_enter_callback(void* context) { furi_check(context); FileBrowser* browser = context; - with_view_model( - browser->view, FileBrowserModel * model, { model->scroll_counter = 0; }, true); + with_view_model(browser->view, FileBrowserModel * model, { model->scroll_counter = 0; }, true); furi_timer_start(browser->scroll_timer, SCROLL_INTERVAL); } diff --git a/applications/services/gui/modules/file_browser_worker.c b/applications/services/gui/modules/file_browser_worker.c index 1ca9ac83798..15117eae2ff 100644 --- a/applications/services/gui/modules/file_browser_worker.c +++ b/applications/services/gui/modules/file_browser_worker.c @@ -14,9 +14,9 @@ #define TAG "BrowserWorker" -#define ASSETS_DIR "assets" -#define BROWSER_ROOT STORAGE_ANY_PATH_PREFIX -#define FILE_NAME_LEN_MAX 256 +#define ASSETS_DIR "assets" +#define BROWSER_ROOT STORAGE_ANY_PATH_PREFIX +#define FILE_NAME_LEN_MAX 256 #define LONG_LOAD_THRESHOLD 100 typedef enum { @@ -117,7 +117,7 @@ static bool browser_filter_by_name(BrowserWorker* browser, FuriString* name, boo if(is_folder) { // Skip assets folders (if enabled) if(browser->skip_assets) { - return ((furi_string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true)); + return (furi_string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true); } else { return true; } @@ -295,7 +295,7 @@ static bool furi_record_close(RECORD_STORAGE); - return (items_cnt == count); + return items_cnt == count; } static int32_t browser_worker(void* context) { @@ -509,7 +509,7 @@ void file_browser_worker_folder_enter(BrowserWorker* browser, FuriString* path, bool file_browser_worker_is_in_start_folder(BrowserWorker* browser) { furi_check(browser); - return (furi_string_cmp(browser->path_start, browser->path_current) == 0); + return furi_string_cmp(browser->path_start, browser->path_current) == 0; } void file_browser_worker_folder_exit(BrowserWorker* browser) { diff --git a/applications/services/gui/modules/menu.c b/applications/services/gui/modules/menu.c index 84529519338..012fa17d6c8 100644 --- a/applications/services/gui/modules/menu.c +++ b/applications/services/gui/modules/menu.c @@ -149,8 +149,7 @@ void menu_free(Menu* menu) { furi_check(menu); menu_reset(menu); - with_view_model( - menu->view, MenuModel * model, { MenuItemArray_clear(model->items); }, false); + with_view_model(menu->view, MenuModel * model, { MenuItemArray_clear(model->items); }, false); view_free(menu->view); free(menu); @@ -158,7 +157,7 @@ void menu_free(Menu* menu) { View* menu_get_view(Menu* menu) { furi_check(menu); - return (menu->view); + return menu->view; } void menu_add_item( diff --git a/applications/services/gui/modules/text_box.c b/applications/services/gui/modules/text_box.c index c3bff00d085..8b7056a000b 100644 --- a/applications/services/gui/modules/text_box.c +++ b/applications/services/gui/modules/text_box.c @@ -4,12 +4,12 @@ #include #include -#define TEXT_BOX_TEXT_WIDTH (120) -#define TEXT_BOX_TEXT_HEIGHT (56) +#define TEXT_BOX_TEXT_WIDTH (120) +#define TEXT_BOX_TEXT_HEIGHT (56) #define TEXT_BOX_MAX_LINES_PER_SCREEN (10) -#define TEXT_BOX_LINES_SCROLL_SPEED_MEDIUM (3) -#define TEXT_BOX_LINES_SCROLL_SPEED_FAST (5) +#define TEXT_BOX_LINES_SCROLL_SPEED_MEDIUM (3) +#define TEXT_BOX_LINES_SCROLL_SPEED_FAST (5) #define TEXT_BOX_LINES_SCROLL_SPEED_SATURATION (9) struct TextBox { @@ -355,13 +355,11 @@ void text_box_set_text(TextBox* text_box, const char* text) { void text_box_set_font(TextBox* text_box, TextBoxFont font) { furi_check(text_box); - with_view_model( - text_box->view, TextBoxModel * model, { model->font = font; }, true); + with_view_model(text_box->view, TextBoxModel * model, { model->font = font; }, true); } void text_box_set_focus(TextBox* text_box, TextBoxFocus focus) { furi_check(text_box); - with_view_model( - text_box->view, TextBoxModel * model, { model->focus = focus; }, true); + with_view_model(text_box->view, TextBoxModel * model, { model->focus = focus; }, true); } diff --git a/applications/services/gui/modules/text_input.c b/applications/services/gui/modules/text_input.c index da391628d14..dc1c9c8c1c7 100644 --- a/applications/services/gui/modules/text_input.c +++ b/applications/services/gui/modules/text_input.c @@ -36,7 +36,7 @@ static const uint8_t keyboard_origin_x = 1; static const uint8_t keyboard_origin_y = 29; static const uint8_t keyboard_row_count = 3; -#define ENTER_KEY '\r' +#define ENTER_KEY '\r' #define BACKSPACE_KEY '\b' static const TextInputKey keyboard_keys_row_1[] = { @@ -132,14 +132,14 @@ static char get_selected_char(TextInputModel* model) { } static bool char_is_lowercase(char letter) { - return (letter >= 0x61 && letter <= 0x7A); + return letter >= 0x61 && letter <= 0x7A; } static char char_to_uppercase(const char letter) { if(letter == '_') { return 0x20; } else if(islower(letter)) { - return (letter - 0x20); + return letter - 0x20; } else { return letter; } @@ -570,6 +570,5 @@ void* text_input_get_validator_callback_context(TextInput* text_input) { void text_input_set_header_text(TextInput* text_input, const char* text) { furi_check(text_input); - with_view_model( - text_input->view, TextInputModel * model, { model->header = text; }, true); + with_view_model(text_input->view, TextInputModel * model, { model->header = text; }, true); } diff --git a/applications/services/gui/modules/widget_elements/widget_element.h b/applications/services/gui/modules/widget_elements/widget_element.h index 67990417387..473fabd041c 100644 --- a/applications/services/gui/modules/widget_elements/widget_element.h +++ b/applications/services/gui/modules/widget_elements/widget_element.h @@ -19,4 +19,4 @@ typedef void (*ButtonCallback)(GuiButtonType result, InputType type, void* conte #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/gui/modules/widget_elements/widget_element_i.h b/applications/services/gui/modules/widget_elements/widget_element_i.h index 456a8317290..2bced557616 100644 --- a/applications/services/gui/modules/widget_elements/widget_element_i.h +++ b/applications/services/gui/modules/widget_elements/widget_element_i.h @@ -90,4 +90,4 @@ WidgetElement* widget_element_text_scroll_create( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/gui/scene_manager.c b/applications/services/gui/scene_manager.c index 7a0a2913765..11acc079602 100644 --- a/applications/services/gui/scene_manager.c +++ b/applications/services/gui/scene_manager.c @@ -2,14 +2,13 @@ #include SceneManager* scene_manager_alloc(const SceneManagerHandlers* app_scene_handlers, void* context) { - furi_check(context); + furi_check(app_scene_handlers); - SceneManager* scene_manager = malloc(sizeof(SceneManager)); + SceneManager* scene_manager = + malloc(sizeof(SceneManager) + (sizeof(AppScene) * app_scene_handlers->scene_num)); // Set SceneManager context and scene handlers scene_manager->context = context; scene_manager->scene_handlers = app_scene_handlers; - // Allocate all scenes - scene_manager->scene = malloc(sizeof(AppScene) * app_scene_handlers->scene_num); // Initialize ScaneManager array for navigation SceneManagerIdStack_init(scene_manager->scene_id_stack); @@ -21,8 +20,6 @@ void scene_manager_free(SceneManager* scene_manager) { // Clear ScaneManager array SceneManagerIdStack_clear(scene_manager->scene_id_stack); - // Clear allocated scenes - free(scene_manager->scene); // Free SceneManager structure free(scene_manager); } diff --git a/applications/services/gui/scene_manager_i.h b/applications/services/gui/scene_manager_i.h index fca798d124d..85f7e7bee9c 100644 --- a/applications/services/gui/scene_manager_i.h +++ b/applications/services/gui/scene_manager_i.h @@ -17,6 +17,6 @@ typedef struct { struct SceneManager { SceneManagerIdStack_t scene_id_stack; const SceneManagerHandlers* scene_handlers; - AppScene* scene; void* context; + AppScene scene[]; }; diff --git a/applications/services/gui/view.c b/applications/services/gui/view.c index 51d02354355..3ac85794aab 100644 --- a/applications/services/gui/view.c +++ b/applications/services/gui/view.c @@ -76,9 +76,8 @@ void view_allocate_model(View* view, ViewModelType type, size_t size) { if(view->model_type == ViewModelTypeLockFree) { view->model = malloc(size); } else if(view->model_type == ViewModelTypeLocking) { - ViewModelLocking* model = malloc(sizeof(ViewModelLocking)); + ViewModelLocking* model = malloc(sizeof(ViewModelLocking) + size); model->mutex = furi_mutex_alloc(FuriMutexTypeRecursive); - model->data = malloc(size); view->model = model; } else { furi_crash(); @@ -89,16 +88,11 @@ void view_free_model(View* view) { furi_check(view); if(view->model_type == ViewModelTypeNone) { return; - } else if(view->model_type == ViewModelTypeLockFree) { - free(view->model); } else if(view->model_type == ViewModelTypeLocking) { ViewModelLocking* model = view->model; furi_mutex_free(model->mutex); - free(model->data); - free(model); - } else { - furi_crash(); } + free(view->model); view->model = NULL; view->model_type = ViewModelTypeNone; } diff --git a/applications/services/gui/view_dispatcher.c b/applications/services/gui/view_dispatcher.c index bf1cd2be660..b4c534932f5 100644 --- a/applications/services/gui/view_dispatcher.c +++ b/applications/services/gui/view_dispatcher.c @@ -69,11 +69,6 @@ void view_dispatcher_enable_queue(ViewDispatcher* view_dispatcher) { view_dispatcher); } -void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, void* context) { - furi_check(view_dispatcher); - view_dispatcher->event_context = context; -} - void view_dispatcher_set_navigation_event_callback( ViewDispatcher* view_dispatcher, ViewDispatcherNavigationEventCallback callback) { @@ -97,6 +92,11 @@ void view_dispatcher_set_tick_event_callback( view_dispatcher->tick_period = tick_period; } +void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, void* context) { + furi_check(view_dispatcher); + view_dispatcher->event_context = context; +} + FuriEventLoop* view_dispatcher_get_event_loop(ViewDispatcher* view_dispatcher) { furi_check(view_dispatcher); furi_check(view_dispatcher->event_loop); diff --git a/applications/services/gui/view_dispatcher.h b/applications/services/gui/view_dispatcher.h index 7627e5a0b0b..905c60975b2 100644 --- a/applications/services/gui/view_dispatcher.h +++ b/applications/services/gui/view_dispatcher.h @@ -107,7 +107,7 @@ void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, * in view_dispatcher_run. * * You can add your objects into event_loop instance, but don't run the loop on - * your side it will cause issues with input processing on dispatcher stop. + * your side as it will cause issues with input processing on dispatcher stop. * * @param view_dispatcher ViewDispatcher instance * diff --git a/applications/services/gui/view_dispatcher_i.h b/applications/services/gui/view_dispatcher_i.h index fcf426c3177..46a4ac7fa7d 100644 --- a/applications/services/gui/view_dispatcher_i.h +++ b/applications/services/gui/view_dispatcher_i.h @@ -11,7 +11,7 @@ #include "view_i.h" #include "gui_i.h" -DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST) +DICT_DEF2(ViewDict, uint32_t, M_DEFAULT_OPLIST, View*, M_PTR_OPLIST) // NOLINT struct ViewDispatcher { FuriEventLoop* event_loop; diff --git a/applications/services/gui/view_holder.c b/applications/services/gui/view_holder.c index d9b382c17b3..ca2f9b04e17 100644 --- a/applications/services/gui/view_holder.c +++ b/applications/services/gui/view_holder.c @@ -104,7 +104,8 @@ void view_holder_start(ViewHolder* view_holder) { } void view_holder_stop(ViewHolder* view_holder) { - while(view_holder->ongoing_input) furi_delay_tick(1); + while(view_holder->ongoing_input) + furi_delay_tick(1); view_port_enabled_set(view_holder->view_port, false); } diff --git a/applications/services/gui/view_i.h b/applications/services/gui/view_i.h index 3e895bd942b..1cc84c7456f 100644 --- a/applications/services/gui/view_i.h +++ b/applications/services/gui/view_i.h @@ -9,8 +9,8 @@ #include typedef struct { - void* data; FuriMutex* mutex; + uint8_t data[]; } ViewModelLocking; struct View { diff --git a/applications/services/input/input.c b/applications/services/input/input.c index 216aa39b2e6..6cbafb79583 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -1,11 +1,36 @@ -#include "input_i.h" +#include "input.h" + +#include +#include +#include +#include +#include +#include + +#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2) +#define INPUT_PRESS_TICKS 150 +#define INPUT_LONG_PRESS_COUNTS 2 +#define INPUT_THREAD_FLAG_ISR 0x00000001 + +/** Input pin state */ +typedef struct { + const InputPin* pin; + // State + volatile bool state; + volatile uint8_t debounce; + FuriTimer* press_timer; + FuriPubSub* event_pubsub; + volatile uint8_t press_counter; + volatile uint32_t counter; +} InputPinState; + +/** Input CLI command handler */ +void input_cli(Cli* cli, FuriString* args, void* context); // #define INPUT_DEBUG #define GPIO_Read(input_pin) (furi_hal_gpio_read(input_pin.pin->gpio) ^ (input_pin.pin->inverted)) -static Input* input = NULL; - void input_press_timer_callback(void* arg) { InputPinState* input_pin = arg; InputEvent event; @@ -15,17 +40,17 @@ void input_press_timer_callback(void* arg) { input_pin->press_counter++; if(input_pin->press_counter == INPUT_LONG_PRESS_COUNTS) { event.type = InputTypeLong; - furi_pubsub_publish(input->event_pubsub, &event); + furi_pubsub_publish(input_pin->event_pubsub, &event); } else if(input_pin->press_counter > INPUT_LONG_PRESS_COUNTS) { input_pin->press_counter--; event.type = InputTypeRepeat; - furi_pubsub_publish(input->event_pubsub, &event); + furi_pubsub_publish(input_pin->event_pubsub, &event); } } void input_isr(void* _ctx) { - UNUSED(_ctx); - furi_thread_flags_set(input->thread_id, INPUT_THREAD_FLAG_ISR); + FuriThreadId thread_id = (FuriThreadId)_ctx; + furi_thread_flags_set(thread_id, INPUT_THREAD_FLAG_ISR); } const char* input_get_key_name(InputKey key) { @@ -56,85 +81,84 @@ const char* input_get_type_name(InputType type) { int32_t input_srv(void* p) { UNUSED(p); - input = malloc(sizeof(Input)); - input->thread_id = furi_thread_get_current_id(); - input->event_pubsub = furi_pubsub_alloc(); - furi_record_create(RECORD_INPUT_EVENTS, input->event_pubsub); -#if INPUT_DEBUG + const FuriThreadId thread_id = furi_thread_get_current_id(); + FuriPubSub* event_pubsub = furi_pubsub_alloc(); + uint32_t counter = 1; + furi_record_create(RECORD_INPUT_EVENTS, event_pubsub); + +#ifdef INPUT_DEBUG furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull); #endif #ifdef SRV_CLI - input->cli = furi_record_open(RECORD_CLI); - cli_add_command(input->cli, "input", CliCommandFlagParallelSafe, input_cli, input); + Cli* cli = furi_record_open(RECORD_CLI); + cli_add_command(cli, "input", CliCommandFlagParallelSafe, input_cli, event_pubsub); #endif - input->pin_states = malloc(input_pins_count * sizeof(InputPinState)); + InputPinState pin_states[input_pins_count]; for(size_t i = 0; i < input_pins_count; i++) { - furi_hal_gpio_add_int_callback(input_pins[i].gpio, input_isr, NULL); - input->pin_states[i].pin = &input_pins[i]; - input->pin_states[i].state = GPIO_Read(input->pin_states[i]); - input->pin_states[i].debounce = INPUT_DEBOUNCE_TICKS_HALF; - input->pin_states[i].press_timer = furi_timer_alloc( - input_press_timer_callback, FuriTimerTypePeriodic, &input->pin_states[i]); - input->pin_states[i].press_counter = 0; + furi_hal_gpio_add_int_callback(input_pins[i].gpio, input_isr, thread_id); + pin_states[i].pin = &input_pins[i]; + pin_states[i].state = GPIO_Read(pin_states[i]); + pin_states[i].debounce = INPUT_DEBOUNCE_TICKS_HALF; + pin_states[i].press_timer = + furi_timer_alloc(input_press_timer_callback, FuriTimerTypePeriodic, &pin_states[i]); + pin_states[i].event_pubsub = event_pubsub; + pin_states[i].press_counter = 0; } while(1) { bool is_changing = false; for(size_t i = 0; i < input_pins_count; i++) { - bool state = GPIO_Read(input->pin_states[i]); + bool state = GPIO_Read(pin_states[i]); if(state) { - if(input->pin_states[i].debounce < INPUT_DEBOUNCE_TICKS) - input->pin_states[i].debounce += 1; + if(pin_states[i].debounce < INPUT_DEBOUNCE_TICKS) pin_states[i].debounce += 1; } else { - if(input->pin_states[i].debounce > 0) input->pin_states[i].debounce -= 1; + if(pin_states[i].debounce > 0) pin_states[i].debounce -= 1; } - if(input->pin_states[i].debounce > 0 && - input->pin_states[i].debounce < INPUT_DEBOUNCE_TICKS) { + if(pin_states[i].debounce > 0 && pin_states[i].debounce < INPUT_DEBOUNCE_TICKS) { is_changing = true; - } else if(input->pin_states[i].state != state) { - input->pin_states[i].state = state; + } else if(pin_states[i].state != state) { + pin_states[i].state = state; // Common state info InputEvent event; event.sequence_source = INPUT_SEQUENCE_SOURCE_HARDWARE; - event.key = input->pin_states[i].pin->key; + event.key = pin_states[i].pin->key; // Short / Long / Repeat timer routine if(state) { - input->counter++; - input->pin_states[i].counter = input->counter; - event.sequence_counter = input->pin_states[i].counter; - furi_timer_start(input->pin_states[i].press_timer, INPUT_PRESS_TICKS); + pin_states[i].counter = counter++; + event.sequence_counter = pin_states[i].counter; + furi_timer_start(pin_states[i].press_timer, INPUT_PRESS_TICKS); } else { - event.sequence_counter = input->pin_states[i].counter; - furi_timer_stop(input->pin_states[i].press_timer); - while(furi_timer_is_running(input->pin_states[i].press_timer)) + event.sequence_counter = pin_states[i].counter; + furi_timer_stop(pin_states[i].press_timer); + while(furi_timer_is_running(pin_states[i].press_timer)) furi_delay_tick(1); - if(input->pin_states[i].press_counter < INPUT_LONG_PRESS_COUNTS) { + if(pin_states[i].press_counter < INPUT_LONG_PRESS_COUNTS) { event.type = InputTypeShort; - furi_pubsub_publish(input->event_pubsub, &event); + furi_pubsub_publish(event_pubsub, &event); } - input->pin_states[i].press_counter = 0; + pin_states[i].press_counter = 0; } // Send Press/Release event - event.type = input->pin_states[i].state ? InputTypePress : InputTypeRelease; - furi_pubsub_publish(input->event_pubsub, &event); + event.type = pin_states[i].state ? InputTypePress : InputTypeRelease; + furi_pubsub_publish(event_pubsub, &event); } } if(is_changing) { -#if INPUT_DEBUG +#ifdef INPUT_DEBUG furi_hal_gpio_write(&gpio_ext_pa4, 1); #endif furi_delay_tick(1); } else { -#if INPUT_DEBUG +#ifdef INPUT_DEBUG furi_hal_gpio_write(&gpio_ext_pa4, 0); #endif furi_thread_flags_wait(INPUT_THREAD_FLAG_ISR, FuriFlagWaitAny, FuriWaitForever); diff --git a/applications/services/input/input.h b/applications/services/input/input.h index a62e84569b6..5233b4a01e9 100644 --- a/applications/services/input/input.h +++ b/applications/services/input/input.h @@ -11,7 +11,7 @@ extern "C" { #endif -#define RECORD_INPUT_EVENTS "input_events" +#define RECORD_INPUT_EVENTS "input_events" #define INPUT_SEQUENCE_SOURCE_HARDWARE (0u) #define INPUT_SEQUENCE_SOURCE_SOFTWARE (1u) @@ -32,7 +32,7 @@ typedef struct { union { uint32_t sequence; struct { - uint8_t sequence_source : 2; + uint8_t sequence_source : 2; uint32_t sequence_counter : 30; }; }; diff --git a/applications/services/input/input_cli.c b/applications/services/input/input_cli.c index 8aa04d6bdbe..8e711c8954a 100644 --- a/applications/services/input/input_cli.c +++ b/applications/services/input/input_cli.c @@ -1,4 +1,4 @@ -#include "input_i.h" +#include "input.h" #include #include @@ -19,11 +19,11 @@ static void input_cli_dump_events_callback(const void* value, void* ctx) { furi_message_queue_put(input_queue, value, FuriWaitForever); } -static void input_cli_dump(Cli* cli, FuriString* args, Input* input) { +static void input_cli_dump(Cli* cli, FuriString* args, FuriPubSub* event_pubsub) { UNUSED(args); FuriMessageQueue* input_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); FuriPubSubSubscription* input_subscription = - furi_pubsub_subscribe(input->event_pubsub, input_cli_dump_events_callback, input_queue); + furi_pubsub_subscribe(event_pubsub, input_cli_dump_events_callback, input_queue); InputEvent input_event; printf("Press CTRL+C to stop\r\n"); @@ -36,7 +36,7 @@ static void input_cli_dump(Cli* cli, FuriString* args, Input* input) { } } - furi_pubsub_unsubscribe(input->event_pubsub, input_subscription); + furi_pubsub_unsubscribe(event_pubsub, input_subscription); furi_message_queue_free(input_queue); } @@ -47,7 +47,7 @@ static void input_cli_send_print_usage(void) { printf("\t\t \t - one of 'press', 'release', 'short', 'long'\r\n"); } -static void input_cli_send(Cli* cli, FuriString* args, Input* input) { +static void input_cli_send(Cli* cli, FuriString* args, FuriPubSub* event_pubsub) { UNUSED(cli); InputEvent event; FuriString* key_str; @@ -90,7 +90,7 @@ static void input_cli_send(Cli* cli, FuriString* args, Input* input) { } while(false); if(parsed) { //-V547 - furi_pubsub_publish(input->event_pubsub, &event); + furi_pubsub_publish(event_pubsub, &event); } else { input_cli_send_print_usage(); } @@ -100,7 +100,7 @@ static void input_cli_send(Cli* cli, FuriString* args, Input* input) { void input_cli(Cli* cli, FuriString* args, void* context) { furi_assert(cli); furi_assert(context); - Input* input = context; + FuriPubSub* event_pubsub = context; FuriString* cmd; cmd = furi_string_alloc(); @@ -110,11 +110,11 @@ void input_cli(Cli* cli, FuriString* args, void* context) { break; } if(furi_string_cmp_str(cmd, "dump") == 0) { - input_cli_dump(cli, args, input); + input_cli_dump(cli, args, event_pubsub); break; } if(furi_string_cmp_str(cmd, "send") == 0) { - input_cli_send(cli, args, input); + input_cli_send(cli, args, event_pubsub); break; } diff --git a/applications/services/input/input_i.h b/applications/services/input/input_i.h deleted file mode 100644 index 14d8b0735a5..00000000000 --- a/applications/services/input/input_i.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @file input_i.h - * Input: internal API - */ - -#pragma once - -#include "input.h" -#include -#include -#include -#include -#include -#include - -#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2) -#define INPUT_PRESS_TICKS 150 -#define INPUT_LONG_PRESS_COUNTS 2 -#define INPUT_THREAD_FLAG_ISR 0x00000001 - -/** Input pin state */ -typedef struct { - const InputPin* pin; - // State - volatile bool state; - volatile uint8_t debounce; - FuriTimer* press_timer; - volatile uint8_t press_counter; - volatile uint32_t counter; -} InputPinState; - -/** Input state */ -typedef struct { - FuriThreadId thread_id; - FuriPubSub* event_pubsub; - InputPinState* pin_states; - Cli* cli; - volatile uint32_t counter; -} Input; - -/** Input press timer callback */ -void input_press_timer_callback(void* arg); - -/** Input interrupt handler */ -void input_isr(void* _ctx); - -/** Input CLI command handler */ -void input_cli(Cli* cli, FuriString* args, void* context); diff --git a/applications/services/loader/firmware_api/firmware_api.cpp b/applications/services/loader/firmware_api/firmware_api.cpp index 45953eddf46..541b67d7d0b 100644 --- a/applications/services/loader/firmware_api/firmware_api.cpp +++ b/applications/services/loader/firmware_api/firmware_api.cpp @@ -24,4 +24,4 @@ const ElfApiInterface* const firmware_api_interface = &elf_api_interface; extern "C" void furi_hal_info_get_api_version(uint16_t* major, uint16_t* minor) { *major = firmware_api_interface->api_version_major; *minor = firmware_api_interface->api_version_minor; -} \ No newline at end of file +} diff --git a/applications/services/loader/loader.c b/applications/services/loader/loader.c index de013381fdd..7e42a4488e0 100644 --- a/applications/services/loader/loader.c +++ b/applications/services/loader/loader.c @@ -11,6 +11,7 @@ #include #define TAG "Loader" + #define LOADER_MAGIC_THREAD_VALUE 0xDEADBEEF // helpers @@ -244,6 +245,43 @@ FuriPubSub* loader_get_pubsub(Loader* loader) { return loader->pubsub; } +bool loader_signal(Loader* loader, uint32_t signal, void* arg) { + furi_check(loader); + + LoaderMessageBoolResult result; + + LoaderMessage message = { + .type = LoaderMessageTypeSignal, + .api_lock = api_lock_alloc_locked(), + .signal.signal = signal, + .signal.arg = arg, + .bool_value = &result, + }; + + furi_message_queue_put(loader->queue, &message, FuriWaitForever); + api_lock_wait_unlock_and_free(message.api_lock); + + return result.value; +} + +bool loader_get_application_name(Loader* loader, FuriString* name) { + furi_check(loader); + + LoaderMessageBoolResult result; + + LoaderMessage message = { + .type = LoaderMessageTypeGetApplicationName, + .api_lock = api_lock_alloc_locked(), + .application_name = name, + .bool_value = &result, + }; + + furi_message_queue_put(loader->queue, &message, FuriWaitForever); + api_lock_wait_unlock_and_free(message.api_lock); + + return result.value; +} + // callbacks static void loader_menu_closed_callback(void* context) { @@ -654,6 +692,28 @@ static void loader_do_app_closed(Loader* loader) { furi_pubsub_publish(loader->pubsub, &event); } +static bool loader_is_application_running(Loader* loader) { + FuriThread* app_thread = loader->app.thread; + return app_thread && (app_thread != (FuriThread*)LOADER_MAGIC_THREAD_VALUE); +} + +static bool loader_do_signal(Loader* loader, uint32_t signal, void* arg) { + if(loader_is_application_running(loader)) { + return furi_thread_signal(loader->app.thread, signal, arg); + } + + return false; +} + +static bool loader_do_get_application_name(Loader* loader, FuriString* name) { + if(loader_is_application_running(loader)) { + furi_string_set(name, furi_thread_get_name(loader->app.thread)); + return true; + } + + return false; +} + // app int32_t loader_srv(void* p) { @@ -714,9 +774,19 @@ int32_t loader_srv(void* p) { case LoaderMessageTypeApplicationsClosed: loader_do_applications_closed(loader); break; + case LoaderMessageTypeSignal: + message.bool_value->value = + loader_do_signal(loader, message.signal.signal, message.signal.arg); + api_lock_unlock(message.api_lock); + break; + case LoaderMessageTypeGetApplicationName: + message.bool_value->value = + loader_do_get_application_name(loader, message.application_name); + api_lock_unlock(message.api_lock); + break; } } } return 0; -} \ No newline at end of file +} diff --git a/applications/services/loader/loader.h b/applications/services/loader/loader.h index ae914117d92..cacfbff684b 100644 --- a/applications/services/loader/loader.h +++ b/applications/services/loader/loader.h @@ -5,7 +5,7 @@ extern "C" { #endif -#define RECORD_LOADER "loader" +#define RECORD_LOADER "loader" #define LOADER_APPLICATIONS_NAME "Apps" typedef struct Loader Loader; @@ -88,6 +88,26 @@ void loader_show_menu(Loader* instance); */ FuriPubSub* loader_get_pubsub(Loader* instance); +/** + * @brief Send a signal to the currently running application + * + * @param[in] instance pointer to the loader instance + * @param[in] signal signal value to be sent + * @param[in,out] arg optional argument (can be of any value, including NULL) + * + * @return true if the signal was handled by the application, false otherwise + */ +bool loader_signal(Loader* instance, uint32_t signal, void* arg); + +/** + * @brief Get the name of the currently running application + * + * @param[in] instance pointer to the loader instance + * @param[in,out] name pointer to the string to contain the name (must be allocated) + * @return true if it was possible to get an application name, false otherwise + */ +bool loader_get_application_name(Loader* instance, FuriString* name); + #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/loader/loader_applications.c b/applications/services/loader/loader_applications.c index 0c5d93cc8e1..232e5314e9f 100644 --- a/applications/services/loader/loader_applications.c +++ b/applications/services/loader/loader_applications.c @@ -170,4 +170,4 @@ static int32_t loader_applications_thread(void* p) { } return 0; -} \ No newline at end of file +} diff --git a/applications/services/loader/loader_applications.h b/applications/services/loader/loader_applications.h index 6b132af0559..57097ba48eb 100644 --- a/applications/services/loader/loader_applications.h +++ b/applications/services/loader/loader_applications.h @@ -13,4 +13,4 @@ void loader_applications_free(LoaderApplications* loader_applications); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/loader/loader_cli.c b/applications/services/loader/loader_cli.c index 1fbd0035e79..a0254f0d0c5 100644 --- a/applications/services/loader/loader_cli.c +++ b/applications/services/loader/loader_cli.c @@ -1,8 +1,10 @@ +#include "loader.h" + #include #include #include #include -#include "loader.h" +#include static void loader_cli_print_usage(void) { printf("Usage:\r\n"); @@ -11,6 +13,8 @@ static void loader_cli_print_usage(void) { printf("\tlist\t - List available applications\r\n"); printf("\topen \t - Open application by name\r\n"); printf("\tinfo\t - Show loader state\r\n"); + printf("\tclose\t - Close the current application\r\n"); + printf("\tsignal [arg:hex]\t - Send a signal with an optional argument\r\n"); } static void loader_cli_list(void) { @@ -25,12 +29,15 @@ static void loader_cli_list(void) { } static void loader_cli_info(Loader* loader) { - if(!loader_is_locked(loader)) { + FuriString* app_name = furi_string_alloc(); + + if(!loader_get_application_name(loader, app_name)) { printf("No application is running\r\n"); } else { - // TODO FL-3513: print application name ??? - printf("Application is running\r\n"); + printf("Application \"%s\" is running\r\n", furi_string_get_cstr(app_name)); } + + furi_string_free(app_name); } static void loader_cli_open(FuriString* args, Loader* loader) { @@ -53,6 +60,12 @@ static void loader_cli_open(FuriString* args, Loader* loader) { FuriString* error_message = furi_string_alloc(); if(loader_start(loader, app_name_str, args_str, error_message) != LoaderStatusOk) { printf("%s\r\n", furi_string_get_cstr(error_message)); + } else { +#ifdef SRV_NOTIFICATION + NotificationApp* notification_srv = furi_record_open(RECORD_NOTIFICATION); + notification_message(notification_srv, &sequence_display_backlight_on); + furi_record_close(RECORD_NOTIFICATION); +#endif } furi_string_free(error_message); } while(false); @@ -60,6 +73,38 @@ static void loader_cli_open(FuriString* args, Loader* loader) { furi_string_free(app_name); } +static void loader_cli_close(Loader* loader) { + FuriString* app_name = furi_string_alloc(); + + if(!loader_get_application_name(loader, app_name)) { + printf("No application is running\r\n"); + } else if(!loader_signal(loader, FuriSignalExit, NULL)) { + printf("Application \"%s\" has to be closed manually\r\n", furi_string_get_cstr(app_name)); + } else { + printf("Application \"%s\" was closed\r\n", furi_string_get_cstr(app_name)); + } + + furi_string_free(app_name); +} + +static void loader_cli_signal(FuriString* args, Loader* loader) { + uint32_t signal; + void* arg = NULL; + + if(!sscanf(furi_string_get_cstr(args), "%lu %p", &signal, &arg)) { + printf("Signal must be a decimal number\r\n"); + } else if(!loader_is_locked(loader)) { + printf("No application is running\r\n"); + } else { + const bool is_handled = loader_signal(loader, signal, arg); + printf( + "Signal %lu with argument 0x%p was %s\r\n", + signal, + arg, + is_handled ? "handled" : "ignored"); + } +} + static void loader_cli(Cli* cli, FuriString* args, void* context) { UNUSED(cli); UNUSED(context); @@ -68,29 +113,21 @@ static void loader_cli(Cli* cli, FuriString* args, void* context) { FuriString* cmd; cmd = furi_string_alloc(); - do { - if(!args_read_string_and_trim(args, cmd)) { - loader_cli_print_usage(); - break; - } - - if(furi_string_cmp_str(cmd, "list") == 0) { - loader_cli_list(); - break; - } - - if(furi_string_cmp_str(cmd, "open") == 0) { - loader_cli_open(args, loader); - break; - } - - if(furi_string_cmp_str(cmd, "info") == 0) { - loader_cli_info(loader); - break; - } - + if(!args_read_string_and_trim(args, cmd)) { loader_cli_print_usage(); - } while(false); + } else if(furi_string_equal(cmd, "list")) { + loader_cli_list(); + } else if(furi_string_equal(cmd, "open")) { + loader_cli_open(args, loader); + } else if(furi_string_equal(cmd, "info")) { + loader_cli_info(loader); + } else if(furi_string_equal(cmd, "close")) { + loader_cli_close(loader); + } else if(furi_string_equal(cmd, "signal")) { + loader_cli_signal(args, loader); + } else { + loader_cli_print_usage(); + } furi_string_free(cmd); furi_record_close(RECORD_LOADER); @@ -104,4 +141,4 @@ void loader_on_system_start(void) { #else UNUSED(loader_cli); #endif -} \ No newline at end of file +} diff --git a/applications/services/loader/loader_i.h b/applications/services/loader/loader_i.h index 95c0c0006c1..92f1e88e009 100644 --- a/applications/services/loader/loader_i.h +++ b/applications/services/loader/loader_i.h @@ -31,6 +31,8 @@ typedef enum { LoaderMessageTypeUnlock, LoaderMessageTypeIsLocked, LoaderMessageTypeStartByNameDetachedWithGuiError, + LoaderMessageTypeSignal, + LoaderMessageTypeGetApplicationName, } LoaderMessageType; typedef struct { @@ -39,6 +41,11 @@ typedef struct { FuriString* error_message; } LoaderMessageStartByName; +typedef struct { + uint32_t signal; + void* arg; +} LoaderMessageSignal; + typedef enum { LoaderStatusErrorUnknown, LoaderStatusErrorInvalidFile, @@ -65,6 +72,8 @@ typedef struct { union { LoaderMessageStartByName start; + LoaderMessageSignal signal; + FuriString* application_name; }; union { diff --git a/applications/services/loader/loader_menu.c b/applications/services/loader/loader_menu.c index 149fea72c19..3293548810b 100644 --- a/applications/services/loader/loader_menu.c +++ b/applications/services/loader/loader_menu.c @@ -124,7 +124,7 @@ static void loader_menu_build_menu(LoaderMenuApp* app, LoaderMenu* menu) { i++, loader_menu_applications_callback, (void*)menu); -}; +} static void loader_menu_build_submenu(LoaderMenuApp* app, LoaderMenu* loader_menu) { for(size_t i = 0; i < FLIPPER_SETTINGS_APPS_COUNT; i++) { @@ -192,4 +192,4 @@ static int32_t loader_menu_thread(void* p) { loader_menu_app_free(app); return 0; -} \ No newline at end of file +} diff --git a/applications/services/loader/loader_menu.h b/applications/services/loader/loader_menu.h index 528fe7d291c..89d01a3617d 100644 --- a/applications/services/loader/loader_menu.h +++ b/applications/services/loader/loader_menu.h @@ -13,4 +13,4 @@ void loader_menu_free(LoaderMenu* loader_menu); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/locale/locale.c b/applications/services/locale/locale.c index f4ee9c63464..6acf2eea973 100644 --- a/applications/services/locale/locale.c +++ b/applications/services/locale/locale.c @@ -31,7 +31,7 @@ float locale_fahrenheit_to_celsius(float temp_f) { } float locale_celsius_to_fahrenheit(float temp_c) { - return (temp_c * 1.8f + 32.f); + return temp_c * 1.8f + 32.f; } void locale_format_time( diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 8e183f74e14..d4c5b91c8c9 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -39,7 +39,7 @@ void notification_message_save_settings(NotificationApp* app) { furi_event_flag_wait( m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever); furi_event_flag_free(m.back_event); -}; +} // internal layer static void @@ -143,17 +143,16 @@ static void notification_apply_notification_leds(NotificationApp* app, const uin // settings uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value) { - return (value * app->settings.display_brightness); + return value * app->settings.display_brightness; } static uint8_t notification_settings_get_rgb_led_brightness(NotificationApp* app, uint8_t value) { - return (value * app->settings.led_brightness); + return value * app->settings.led_brightness; } static uint32_t notification_settings_display_off_delay_ticks(NotificationApp* app) { - return ( - (float)(app->settings.display_off_delay_ms) / - (1000.0f / furi_kernel_get_tick_frequency())); + return (float)(app->settings.display_off_delay_ms) / + (1000.0f / furi_kernel_get_tick_frequency()); } // generics @@ -471,7 +470,7 @@ static bool notification_load_settings(NotificationApp* app) { furi_record_close(RECORD_STORAGE); return fs_result; -}; +} static bool notification_save_settings(NotificationApp* app) { NotificationSettings settings; @@ -506,7 +505,7 @@ static bool notification_save_settings(NotificationApp* app) { furi_record_close(RECORD_STORAGE); return fs_result; -}; +} static void input_event_callback(const void* value, void* context) { furi_assert(value); @@ -555,7 +554,7 @@ static NotificationApp* notification_app_alloc(void) { notification_message(app, &sequence_display_backlight_on); return app; -}; +} // App int32_t notification_srv(void* p) { @@ -598,4 +597,4 @@ int32_t notification_srv(void* p) { } return 0; -}; +} diff --git a/applications/services/notification/notification_app.h b/applications/services/notification/notification_app.h index cacc17ffb0c..434773f2e50 100644 --- a/applications/services/notification/notification_app.h +++ b/applications/services/notification/notification_app.h @@ -4,7 +4,7 @@ #include "notification_messages.h" #include "notification_settings_filename.h" -#define NOTIFICATION_LED_COUNT 3 +#define NOTIFICATION_LED_COUNT 3 #define NOTIFICATION_EVENT_COMPLETE 0x00000001U typedef enum { @@ -33,7 +33,7 @@ typedef struct { } NotificationLedLayer; #define NOTIFICATION_SETTINGS_VERSION 0x02 -#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME) +#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME) typedef struct { uint8_t version; diff --git a/applications/services/notification/notification_app_api.c b/applications/services/notification/notification_app_api.c index 90e3f236e56..80f7995f178 100644 --- a/applications/services/notification/notification_app_api.c +++ b/applications/services/notification/notification_app_api.c @@ -10,7 +10,7 @@ void notification_message(NotificationApp* app, const NotificationSequence* sequ NotificationAppMessage m = { .type = NotificationLayerMessage, .sequence = sequence, .back_event = NULL}; furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk); -}; +} void notification_internal_message(NotificationApp* app, const NotificationSequence* sequence) { furi_check(app); @@ -19,7 +19,7 @@ void notification_internal_message(NotificationApp* app, const NotificationSeque NotificationAppMessage m = { .type = InternalLayerMessage, .sequence = sequence, .back_event = NULL}; furi_check(furi_message_queue_put(app->queue, &m, FuriWaitForever) == FuriStatusOk); -}; +} void notification_message_block(NotificationApp* app, const NotificationSequence* sequence) { furi_check(app); @@ -33,7 +33,7 @@ void notification_message_block(NotificationApp* app, const NotificationSequence furi_event_flag_wait( m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever); furi_event_flag_free(m.back_event); -}; +} void notification_internal_message_block( NotificationApp* app, @@ -47,4 +47,4 @@ void notification_internal_message_block( furi_event_flag_wait( m.back_event, NOTIFICATION_EVENT_COMPLETE, FuriFlagWaitAny, FuriWaitForever); furi_event_flag_free(m.back_event); -}; +} diff --git a/applications/services/power/power_service/power.c b/applications/services/power/power_service/power.c index 278854e13cc..64121d8525a 100644 --- a/applications/services/power/power_service/power.c +++ b/applications/services/power/power_service/power.c @@ -3,9 +3,10 @@ #include #include -#define POWER_OFF_TIMEOUT 90 #define TAG "Power" +#define POWER_OFF_TIMEOUT 90 + void power_draw_battery_callback(Canvas* canvas, void* context) { furi_assert(context); Power* power = context; diff --git a/applications/services/rpc/rpc.c b/applications/services/rpc/rpc.c index 32371fa82ed..6ad16fbff4a 100644 --- a/applications/services/rpc/rpc.c +++ b/applications/services/rpc/rpc.c @@ -232,7 +232,7 @@ bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) { rpc_debug_print_data("INPUT", buf, bytes_received); #endif - return (count == bytes_received); + return count == bytes_received; } static bool rpc_pb_content_callback(pb_istream_t* stream, const pb_field_t* field, void** arg) { diff --git a/applications/services/rpc/rpc_desktop.c b/applications/services/rpc/rpc_desktop.c index a70e8436306..76ab6c70d38 100644 --- a/applications/services/rpc/rpc_desktop.c +++ b/applications/services/rpc/rpc_desktop.c @@ -133,4 +133,4 @@ void rpc_desktop_free(void* context) { rpc_desktop->session = NULL; free(rpc_desktop); -} \ No newline at end of file +} diff --git a/applications/services/rpc/rpc_gui.c b/applications/services/rpc/rpc_gui.c index ee352659024..292fc2ef879 100644 --- a/applications/services/rpc/rpc_gui.c +++ b/applications/services/rpc/rpc_gui.c @@ -55,6 +55,7 @@ typedef struct { RpcSession* session; Gui* gui; const Icon* icon; + FuriPubSub* input_events; // Receive part ViewPort* virtual_display_view_port; @@ -234,10 +235,7 @@ static void } // Submit event - FuriPubSub* input_events = furi_record_open(RECORD_INPUT_EVENTS); - furi_check(input_events); - furi_pubsub_publish(input_events, &event); - furi_record_close(RECORD_INPUT_EVENTS); + furi_pubsub_publish(rpc_gui->input_events, &event); rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK); } @@ -401,6 +399,7 @@ void* rpc_system_gui_alloc(RpcSession* session) { RpcGuiSystem* rpc_gui = malloc(sizeof(RpcGuiSystem)); rpc_gui->gui = furi_record_open(RECORD_GUI); + rpc_gui->input_events = furi_record_open(RECORD_INPUT_EVENTS); rpc_gui->session = session; // Active session icon @@ -447,6 +446,19 @@ void rpc_system_gui_free(void* context) { RpcGuiSystem* rpc_gui = context; furi_assert(rpc_gui->gui); + // Release ongoing inputs to avoid lockup + for(InputKey key = 0; key < InputKeyMAX; key++) { + if(rpc_gui->input_key_counter[key] != RPC_GUI_INPUT_RESET) { + InputEvent event = { + .key = key, + .type = InputTypeRelease, + .sequence_source = INPUT_SEQUENCE_SOURCE_SOFTWARE, + .sequence_counter = rpc_gui->input_key_counter[key], + }; + furi_pubsub_publish(rpc_gui->input_events, &event); + } + } + if(rpc_gui->virtual_display_view_port) { gui_remove_view_port(rpc_gui->gui, rpc_gui->virtual_display_view_port); view_port_free(rpc_gui->virtual_display_view_port); @@ -474,6 +486,7 @@ void rpc_system_gui_free(void* context) { free(rpc_gui->transmit_frame); rpc_gui->transmit_frame = NULL; } + furi_record_close(RECORD_INPUT_EVENTS); furi_record_close(RECORD_GUI); free(rpc_gui); } diff --git a/applications/services/rpc/rpc_i.h b/applications/services/rpc/rpc_i.h index 20baca7b122..0342df2b656 100644 --- a/applications/services/rpc/rpc_i.h +++ b/applications/services/rpc/rpc_i.h @@ -52,4 +52,4 @@ PB_CommandStatus rpc_system_storage_get_error(FS_Error fs_error); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/services/rpc/rpc_property.c b/applications/services/rpc/rpc_property.c index ad15051ebca..e88b11b8756 100644 --- a/applications/services/rpc/rpc_property.c +++ b/applications/services/rpc/rpc_property.c @@ -9,7 +9,7 @@ #define TAG "RpcProperty" #define PROPERTY_CATEGORY_DEVICE_INFO "devinfo" -#define PROPERTY_CATEGORY_POWER_INFO "pwrinfo" +#define PROPERTY_CATEGORY_POWER_INFO "pwrinfo" #define PROPERTY_CATEGORY_POWER_DEBUG "pwrdebug" typedef struct { diff --git a/applications/services/rpc/rpc_storage.c b/applications/services/rpc/rpc_storage.c index 306b25777b9..89991aa86c7 100644 --- a/applications/services/rpc/rpc_storage.c +++ b/applications/services/rpc/rpc_storage.c @@ -700,21 +700,21 @@ static void rpc_system_storage_tar_extract_process(const PB_Main* request, void* TarArchive* archive = tar_archive_alloc(rpc_storage->api); do { - if(!path_contains_only_ascii(request->content.storage_tar_extract_request.out_path)) { + const char *tar_path = request->content.storage_tar_extract_request.tar_path, + *out_path = request->content.storage_tar_extract_request.out_path; + if(!path_contains_only_ascii(out_path)) { status = PB_CommandStatus_ERROR_STORAGE_INVALID_NAME; break; } - if(!tar_archive_open( - archive, - request->content.storage_tar_extract_request.tar_path, - TAR_OPEN_MODE_READ)) { + TarOpenMode tar_mode = tar_archive_get_mode_for_path(tar_path); + + if(!tar_archive_open(archive, tar_path, tar_mode)) { status = PB_CommandStatus_ERROR_STORAGE_INVALID_PARAMETER; break; } - if(!tar_archive_unpack_to( - archive, request->content.storage_tar_extract_request.out_path, NULL)) { + if(!tar_archive_unpack_to(archive, out_path, NULL)) { status = PB_CommandStatus_ERROR_STORAGE_INTERNAL; break; } diff --git a/applications/services/storage/filesystem_api.c b/applications/services/storage/filesystem_api.c index e6012864d43..cf3803864a6 100644 --- a/applications/services/storage/filesystem_api.c +++ b/applications/services/storage/filesystem_api.c @@ -40,5 +40,5 @@ const char* filesystem_api_error_get_desc(FS_Error error_id) { bool file_info_is_dir(const FileInfo* file_info) { furi_check(file_info); - return (file_info->flags & FSF_DIRECTORY); -} \ No newline at end of file + return file_info->flags & FSF_DIRECTORY; +} diff --git a/applications/services/storage/storage.c b/applications/services/storage/storage.c index f43c6e81517..21f8789cecd 100644 --- a/applications/services/storage/storage.c +++ b/applications/services/storage/storage.c @@ -10,7 +10,7 @@ #define STORAGE_TICK 1000 #define ICON_SD_MOUNTED &I_SDcardMounted_11x8 -#define ICON_SD_ERROR &I_SDcardFail_11x8 +#define ICON_SD_ERROR &I_SDcardFail_11x8 #define TAG "Storage" diff --git a/applications/services/storage/storage.h b/applications/services/storage/storage.h index eaef59cd6dd..a4dffe63309 100644 --- a/applications/services/storage/storage.h +++ b/applications/services/storage/storage.h @@ -12,16 +12,16 @@ extern "C" { #endif -#define STORAGE_INT_PATH_PREFIX "/int" -#define STORAGE_EXT_PATH_PREFIX "/ext" -#define STORAGE_ANY_PATH_PREFIX "/any" -#define STORAGE_APP_DATA_PATH_PREFIX "/data" +#define STORAGE_INT_PATH_PREFIX "/int" +#define STORAGE_EXT_PATH_PREFIX "/ext" +#define STORAGE_ANY_PATH_PREFIX "/any" +#define STORAGE_APP_DATA_PATH_PREFIX "/data" #define STORAGE_APP_ASSETS_PATH_PREFIX "/assets" -#define INT_PATH(path) STORAGE_INT_PATH_PREFIX "/" path -#define EXT_PATH(path) STORAGE_EXT_PATH_PREFIX "/" path -#define ANY_PATH(path) STORAGE_ANY_PATH_PREFIX "/" path -#define APP_DATA_PATH(path) STORAGE_APP_DATA_PATH_PREFIX "/" path +#define INT_PATH(path) STORAGE_INT_PATH_PREFIX "/" path +#define EXT_PATH(path) STORAGE_EXT_PATH_PREFIX "/" path +#define ANY_PATH(path) STORAGE_ANY_PATH_PREFIX "/" path +#define APP_DATA_PATH(path) STORAGE_APP_DATA_PATH_PREFIX "/" path #define APP_ASSETS_PATH(path) STORAGE_APP_ASSETS_PATH_PREFIX "/" path #define RECORD_STORAGE "storage" diff --git a/applications/services/storage/storage_cli.c b/applications/services/storage/storage_cli.c index 67a7e288b80..918e796ce33 100644 --- a/applications/services/storage/storage_cli.c +++ b/applications/services/storage/storage_cli.c @@ -5,42 +5,22 @@ #include #include #include +#include #include #include #include #define MAX_NAME_LENGTH 255 -static void storage_cli_print_usage(void) { - printf("Usage:\r\n"); - printf("storage \r\n"); - printf("The path must start with /int or /ext\r\n"); - printf("Cmd list:\r\n"); - printf("\tinfo\t - get FS info\r\n"); - printf("\tformat\t - format filesystem\r\n"); - printf("\tlist\t - list files and dirs\r\n"); - printf("\ttree\t - list files and dirs, recursive\r\n"); - printf("\tremove\t - delete the file or directory\r\n"); - printf("\tread\t - read text from file and print file size and content to cli\r\n"); - printf( - "\tread_chunks\t - read data from file and print file size and content to cli, should contain how many bytes you want to read in block\r\n"); - printf("\twrite\t - read text from cli and append it to file, stops by ctrl+c\r\n"); - printf( - "\twrite_chunk\t - read data from cli and append it to file, should contain how many bytes you want to write\r\n"); - printf("\tcopy\t - copy file to new file, must contain new path\r\n"); - printf("\trename\t - move file to new file, must contain new path\r\n"); - printf("\tmkdir\t - creates a new directory\r\n"); - printf("\tmd5\t - md5 hash of the file\r\n"); - printf("\tstat\t - info about file or dir\r\n"); - printf("\ttimestamp\t - last modification timestamp\r\n"); -}; +static void storage_cli_print_usage(void); static void storage_cli_print_error(FS_Error error) { printf("Storage error: %s\r\n", storage_error_get_desc(error)); } -static void storage_cli_info(Cli* cli, FuriString* path) { +static void storage_cli_info(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); if(furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) { @@ -86,9 +66,10 @@ static void storage_cli_info(Cli* cli, FuriString* path) { } furi_record_close(RECORD_STORAGE); -}; +} -static void storage_cli_format(Cli* cli, FuriString* path) { +static void storage_cli_format(Cli* cli, FuriString* path, FuriString* args) { + UNUSED(args); if(furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) { storage_cli_print_error(FSE_NOT_IMPLEMENTED); } else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) { @@ -112,10 +93,11 @@ static void storage_cli_format(Cli* cli, FuriString* path) { } else { storage_cli_print_usage(); } -}; +} -static void storage_cli_list(Cli* cli, FuriString* path) { +static void storage_cli_list(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); if(furi_string_cmp_str(path, "/") == 0) { printf("\t[D] int\r\n"); printf("\t[D] ext\r\n"); @@ -151,12 +133,13 @@ static void storage_cli_list(Cli* cli, FuriString* path) { } } -static void storage_cli_tree(Cli* cli, FuriString* path) { +static void storage_cli_tree(Cli* cli, FuriString* path, FuriString* args) { + UNUSED(args); if(furi_string_cmp_str(path, "/") == 0) { furi_string_set(path, STORAGE_INT_PATH_PREFIX); - storage_cli_tree(cli, path); + storage_cli_tree(cli, path, NULL); furi_string_set(path, STORAGE_EXT_PATH_PREFIX); - storage_cli_tree(cli, path); + storage_cli_tree(cli, path, NULL); } else { Storage* api = furi_record_open(RECORD_STORAGE); DirWalk* dir_walk = dir_walk_alloc(api); @@ -192,8 +175,9 @@ static void storage_cli_tree(Cli* cli, FuriString* path) { } } -static void storage_cli_read(Cli* cli, FuriString* path) { +static void storage_cli_read(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); File* file = storage_file_alloc(api); @@ -223,7 +207,8 @@ static void storage_cli_read(Cli* cli, FuriString* path) { furi_record_close(RECORD_STORAGE); } -static void storage_cli_write(Cli* cli, FuriString* path) { +static void storage_cli_write(Cli* cli, FuriString* path, FuriString* args) { + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); File* file = storage_file_alloc(api); @@ -256,7 +241,7 @@ static void storage_cli_write(Cli* cli, FuriString* path) { fflush(stdout); read_index++; - if(((read_index % buffer_size) == 0)) { + if((read_index % buffer_size) == 0) { size_t written_size = storage_file_write(file, buffer, buffer_size); if(written_size != buffer_size) { @@ -353,8 +338,9 @@ static void storage_cli_write_chunk(Cli* cli, FuriString* path, FuriString* args furi_record_close(RECORD_STORAGE); } -static void storage_cli_stat(Cli* cli, FuriString* path) { +static void storage_cli_stat(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); if(furi_string_cmp_str(path, "/") == 0) { @@ -394,8 +380,9 @@ static void storage_cli_stat(Cli* cli, FuriString* path) { furi_record_close(RECORD_STORAGE); } -static void storage_cli_timestamp(Cli* cli, FuriString* path) { +static void storage_cli_timestamp(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); uint32_t timestamp = 0; @@ -431,8 +418,9 @@ static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) { furi_record_close(RECORD_STORAGE); } -static void storage_cli_remove(Cli* cli, FuriString* path) { +static void storage_cli_remove(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); FS_Error error = storage_common_remove(api, furi_string_get_cstr(path)); @@ -464,8 +452,9 @@ static void storage_cli_rename(Cli* cli, FuriString* old_path, FuriString* args) furi_record_close(RECORD_STORAGE); } -static void storage_cli_mkdir(Cli* cli, FuriString* path) { +static void storage_cli_mkdir(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); FS_Error error = storage_common_mkdir(api, furi_string_get_cstr(path)); @@ -476,8 +465,9 @@ static void storage_cli_mkdir(Cli* cli, FuriString* path) { furi_record_close(RECORD_STORAGE); } -static void storage_cli_md5(Cli* cli, FuriString* path) { +static void storage_cli_md5(Cli* cli, FuriString* path, FuriString* args) { UNUSED(cli); + UNUSED(args); Storage* api = furi_record_open(RECORD_STORAGE); File* file = storage_file_alloc(api); FuriString* md5 = furi_string_alloc(); @@ -496,100 +486,182 @@ static void storage_cli_md5(Cli* cli, FuriString* path) { furi_record_close(RECORD_STORAGE); } -void storage_cli(Cli* cli, FuriString* args, void* context) { +static bool tar_extract_file_callback(const char* name, bool is_directory, void* context) { UNUSED(context); - FuriString* cmd; - FuriString* path; - cmd = furi_string_alloc(); - path = furi_string_alloc(); - - do { - if(!args_read_string_and_trim(args, cmd)) { - storage_cli_print_usage(); - break; - } - - if(!args_read_probably_quoted_string_and_trim(args, path)) { - storage_cli_print_usage(); - break; - } - - if(furi_string_cmp_str(cmd, "info") == 0) { - storage_cli_info(cli, path); - break; - } - - if(furi_string_cmp_str(cmd, "format") == 0) { - storage_cli_format(cli, path); - break; - } + printf("\t%s %s\r\n", is_directory ? "D" : "F", name); + return true; +} - if(furi_string_cmp_str(cmd, "list") == 0) { - storage_cli_list(cli, path); - break; - } +static void storage_cli_extract(Cli* cli, FuriString* old_path, FuriString* args) { + UNUSED(cli); + FuriString* new_path = furi_string_alloc(); - if(furi_string_cmp_str(cmd, "tree") == 0) { - storage_cli_tree(cli, path); - break; - } + if(!args_read_probably_quoted_string_and_trim(args, new_path)) { + storage_cli_print_usage(); + furi_string_free(new_path); + return; + } - if(furi_string_cmp_str(cmd, "read") == 0) { - storage_cli_read(cli, path); - break; - } + Storage* api = furi_record_open(RECORD_STORAGE); - if(furi_string_cmp_str(cmd, "read_chunks") == 0) { - storage_cli_read_chunks(cli, path, args); + TarArchive* archive = tar_archive_alloc(api); + TarOpenMode tar_mode = tar_archive_get_mode_for_path(furi_string_get_cstr(old_path)); + do { + if(!tar_archive_open(archive, furi_string_get_cstr(old_path), tar_mode)) { + printf("Failed to open archive\r\n"); break; } + uint32_t start_tick = furi_get_tick(); + tar_archive_set_file_callback(archive, tar_extract_file_callback, NULL); + printf("Unpacking to %s\r\n", furi_string_get_cstr(new_path)); + bool success = tar_archive_unpack_to(archive, furi_string_get_cstr(new_path), NULL); + uint32_t end_tick = furi_get_tick(); + printf( + "Decompression %s in %lu ticks \r\n", + success ? "success" : "failed", + end_tick - start_tick); + } while(false); - if(furi_string_cmp_str(cmd, "write") == 0) { - storage_cli_write(cli, path); - break; - } + tar_archive_free(archive); + furi_string_free(new_path); + furi_record_close(RECORD_STORAGE); +} - if(furi_string_cmp_str(cmd, "write_chunk") == 0) { - storage_cli_write_chunk(cli, path, args); - break; - } +typedef void (*StorageCliCommandCallback)(Cli* cli, FuriString* path, FuriString* args); + +typedef struct { + const char* command; + const char* help; + const StorageCliCommandCallback impl; +} StorageCliCommand; + +static const StorageCliCommand storage_cli_commands[] = { + { + "write_chunk", + "read data from cli and append it to file, should contain how many bytes you want to write", + &storage_cli_write_chunk, + }, + { + "read_chunks", + "read data from file and print file size and content to cli, should contain how many bytes you want to read in block", + &storage_cli_read_chunks, + }, + { + "list", + "list files and dirs", + &storage_cli_list, + }, + { + "md5", + "md5 hash of the file", + &storage_cli_md5, + }, + { + "stat", + "info about file or dir", + &storage_cli_stat, + }, + { + "info", + "get FS info", + &storage_cli_info, + }, + { + "tree", + "list files and dirs, recursive", + &storage_cli_tree, + }, + { + "read", + "read text from file and print file size and content to cli", + &storage_cli_read, + }, + { + "write", + "read text from cli and append it to file, stops by ctrl+c", + &storage_cli_write, + }, + { + "copy", + "copy file to new file, must contain new path", + &storage_cli_copy, + }, + { + "remove", + "delete the file or directory", + &storage_cli_remove, + }, + { + "rename", + "move file to new file, must contain new path", + &storage_cli_rename, + }, + { + "mkdir", + "creates a new directory", + &storage_cli_mkdir, + }, + { + "timestamp", + "last modification timestamp", + &storage_cli_timestamp, + }, + { + "extract", + "extract tar archive to destination", + &storage_cli_extract, + }, + { + "format", + "format filesystem", + &storage_cli_format, + }, +}; - if(furi_string_cmp_str(cmd, "copy") == 0) { - storage_cli_copy(cli, path, args); - break; - } +static void storage_cli_print_usage(void) { + printf("Usage:\r\n"); + printf("storage \r\n"); + printf("The path must start with /int or /ext\r\n"); + printf("Cmd list:\r\n"); - if(furi_string_cmp_str(cmd, "remove") == 0) { - storage_cli_remove(cli, path); - break; - } + for(size_t i = 0; i < COUNT_OF(storage_cli_commands); ++i) { + const StorageCliCommand* command_descr = &storage_cli_commands[i]; + const char* cli_cmd = command_descr->command; + printf( + "\t%s%s - %s\r\n", cli_cmd, strlen(cli_cmd) > 8 ? "\t" : "\t\t", command_descr->help); + } +} - if(furi_string_cmp_str(cmd, "rename") == 0) { - storage_cli_rename(cli, path, args); - break; - } +void storage_cli(Cli* cli, FuriString* args, void* context) { + UNUSED(context); + FuriString* cmd; + FuriString* path; + cmd = furi_string_alloc(); + path = furi_string_alloc(); - if(furi_string_cmp_str(cmd, "mkdir") == 0) { - storage_cli_mkdir(cli, path); + do { + if(!args_read_string_and_trim(args, cmd)) { + storage_cli_print_usage(); break; } - if(furi_string_cmp_str(cmd, "md5") == 0) { - storage_cli_md5(cli, path); + if(!args_read_probably_quoted_string_and_trim(args, path)) { + storage_cli_print_usage(); break; } - if(furi_string_cmp_str(cmd, "stat") == 0) { - storage_cli_stat(cli, path); - break; + size_t i = 0; + for(; i < COUNT_OF(storage_cli_commands); ++i) { + const StorageCliCommand* command_descr = &storage_cli_commands[i]; + if(furi_string_cmp_str(cmd, command_descr->command) == 0) { + command_descr->impl(cli, path, args); + break; + } } - if(furi_string_cmp_str(cmd, "timestamp") == 0) { - storage_cli_timestamp(cli, path); - break; + if(i == COUNT_OF(storage_cli_commands)) { + storage_cli_print_usage(); } - - storage_cli_print_usage(); } while(false); furi_string_free(path); diff --git a/applications/services/storage/storage_external_api.c b/applications/services/storage/storage_external_api.c index adc0e2465ac..7803e8f6a22 100644 --- a/applications/services/storage/storage_external_api.c +++ b/applications/services/storage/storage_external_api.c @@ -7,8 +7,8 @@ #include #include "toolbox/path.h" -#define MAX_NAME_LENGTH 256 -#define MAX_EXT_LEN 16 +#define MAX_NAME_LENGTH 256 +#define MAX_EXT_LEN 16 #define FILE_BUFFER_SIZE 512 #define TAG "StorageApi" @@ -41,10 +41,10 @@ .file = file, \ }}; -#define S_RETURN_BOOL (return_data.bool_value); -#define S_RETURN_UINT16 (return_data.uint16_value); -#define S_RETURN_UINT64 (return_data.uint64_value); -#define S_RETURN_ERROR (return_data.error_value); +#define S_RETURN_BOOL (return_data.bool_value); +#define S_RETURN_UINT16 (return_data.uint16_value); +#define S_RETURN_UINT64 (return_data.uint64_value); +#define S_RETURN_ERROR (return_data.error_value); #define S_RETURN_CSTRING (return_data.cstring_value); typedef enum { @@ -929,12 +929,12 @@ File* storage_file_alloc(Storage* storage) { bool storage_file_is_open(File* file) { furi_check(file); - return (file->type != FileTypeClosed); + return file->type != FileTypeClosed; } bool storage_file_is_dir(File* file) { furi_check(file); - return (file->type == FileTypeOpenDir); + return file->type == FileTypeOpenDir; } void storage_file_free(File* file) { diff --git a/applications/services/storage/storage_glue.h b/applications/services/storage/storage_glue.h index 4323296cfb3..7aa66fce036 100644 --- a/applications/services/storage/storage_glue.h +++ b/applications/services/storage/storage_glue.h @@ -8,7 +8,12 @@ extern "C" { #endif -typedef enum { ST_EXT = 0, ST_INT = 1, ST_ANY, ST_ERROR } StorageType; +typedef enum { + ST_EXT = 0, + ST_INT = 1, + ST_ANY, + ST_ERROR +} StorageType; typedef struct StorageData StorageData; diff --git a/applications/services/storage/storage_i.h b/applications/services/storage/storage_i.h index cb7f16e4709..2ad9dcc78e7 100644 --- a/applications/services/storage/storage_i.h +++ b/applications/services/storage/storage_i.h @@ -12,7 +12,7 @@ extern "C" { #define STORAGE_COUNT (ST_INT + 1) -#define APPS_DATA_PATH EXT_PATH("apps_data") +#define APPS_DATA_PATH EXT_PATH("apps_data") #define APPS_ASSETS_PATH EXT_PATH("apps_assets") typedef struct { diff --git a/applications/services/storage/storage_internal_api.c b/applications/services/storage/storage_internal_api.c index 37ea4a2a513..4cbce7546eb 100644 --- a/applications/services/storage/storage_internal_api.c +++ b/applications/services/storage/storage_internal_api.c @@ -6,7 +6,7 @@ FS_Error storage_int_backup(Storage* storage, const char* dstname) { furi_check(storage); TarArchive* archive = tar_archive_alloc(storage); - bool success = tar_archive_open(archive, dstname, TAR_OPEN_MODE_WRITE) && + bool success = tar_archive_open(archive, dstname, TarOpenModeWrite) && tar_archive_add_dir(archive, STORAGE_INT_PATH_PREFIX, "") && tar_archive_finalize(archive); tar_archive_free(archive); @@ -18,7 +18,7 @@ FS_Error furi_check(storage); TarArchive* archive = tar_archive_alloc(storage); - bool success = tar_archive_open(archive, srcname, TAR_OPEN_MODE_READ) && + bool success = tar_archive_open(archive, srcname, TarOpenModeRead) && tar_archive_unpack_to(archive, STORAGE_INT_PATH_PREFIX, converter); tar_archive_free(archive); return success ? FSE_OK : FSE_INTERNAL; diff --git a/applications/services/storage/storages/storage_ext.c b/applications/services/storage/storages/storage_ext.c index 7e617c0ff20..93e06f6632c 100644 --- a/applications/services/storage/storages/storage_ext.c +++ b/applications/services/storage/storages/storage_ext.c @@ -337,7 +337,7 @@ static bool storage_ext_file_open( file->internal_error_id = f_open(file_data, path, _mode); file->error_id = storage_ext_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_ext_file_close(void* ctx, File* file) { @@ -347,7 +347,7 @@ static bool storage_ext_file_close(void* ctx, File* file) { file->error_id = storage_ext_parse_error(file->internal_error_id); free(file_data); storage_set_storage_file_data(file, NULL, storage); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static uint16_t @@ -392,7 +392,7 @@ static bool } file->error_id = storage_ext_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static uint64_t storage_ext_file_tell(void* ctx, File* file) { @@ -416,7 +416,7 @@ static bool storage_ext_file_truncate(void* ctx, File* file) { file->internal_error_id = f_truncate(file_data); file->error_id = storage_ext_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; #endif } @@ -431,7 +431,7 @@ static bool storage_ext_file_sync(void* ctx, File* file) { file->internal_error_id = f_sync(file_data); file->error_id = storage_ext_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; #endif } @@ -464,7 +464,7 @@ static bool storage_ext_dir_open(void* ctx, File* file, const char* path) { storage_set_storage_file_data(file, file_data, storage); file->internal_error_id = f_opendir(file_data, path); file->error_id = storage_ext_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_ext_dir_close(void* ctx, File* file) { @@ -474,7 +474,7 @@ static bool storage_ext_dir_close(void* ctx, File* file) { file->internal_error_id = f_closedir(file_data); file->error_id = storage_ext_parse_error(file->internal_error_id); free(file_data); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_ext_dir_read( @@ -505,7 +505,7 @@ static bool storage_ext_dir_read( file->error_id = FSE_NOT_EXIST; } - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_ext_dir_rewind(void* ctx, File* file) { @@ -514,7 +514,7 @@ static bool storage_ext_dir_rewind(void* ctx, File* file) { file->internal_error_id = f_readdir(file_data, NULL); file->error_id = storage_ext_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } /******************* Common FS Functions *******************/ diff --git a/applications/services/storage/storages/storage_int.c b/applications/services/storage/storages/storage_int.c index 8c3827fe5da..324ce632861 100644 --- a/applications/services/storage/storages/storage_int.c +++ b/applications/services/storage/storages/storage_int.c @@ -4,7 +4,8 @@ #include #define TAG "StorageInt" -#define STORAGE_PATH STORAGE_INT_PATH_PREFIX + +#define STORAGE_PATH STORAGE_INT_PATH_PREFIX #define LFS_CLEAN_FINGERPRINT 0 /* When less than LFS_RESERVED_PAGES_COUNT are left free, creation & @@ -160,7 +161,7 @@ static LFSData* storage_int_lfs_data_alloc(void) { lfs_data->config.lookahead_size = 16; return lfs_data; -}; +} // Returns true if fingerprint was invalid and LFS reformatting is needed static bool storage_int_check_and_set_fingerprint(LFSData* lfs_data) { @@ -287,7 +288,7 @@ static bool storage_int_check_for_free_space(StorageData* storage) { lfs_size_t free_space = (lfs_data->config.block_count - result) * lfs_data->config.block_size; - return (free_space > LFS_RESERVED_PAGES_COUNT * furi_hal_flash_get_page_size()); + return free_space > LFS_RESERVED_PAGES_COUNT * furi_hal_flash_get_page_size(); } return false; @@ -344,7 +345,7 @@ static bool storage_int_file_open( file->error_id = storage_int_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_int_file_close(void* ctx, File* file) { @@ -360,7 +361,7 @@ static bool storage_int_file_close(void* ctx, File* file) { file->error_id = storage_int_parse_error(file->internal_error_id); lfs_handle_free(handle); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static uint16_t @@ -430,7 +431,7 @@ static bool } file->error_id = storage_int_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static uint64_t storage_int_file_tell(void* ctx, File* file) { @@ -475,7 +476,7 @@ static bool storage_int_file_truncate(void* ctx, File* file) { file->error_id = storage_int_parse_error(file->internal_error_id); } - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_int_file_sync(void* ctx, File* file) { @@ -490,7 +491,7 @@ static bool storage_int_file_sync(void* ctx, File* file) { } file->error_id = storage_int_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static uint64_t storage_int_file_size(void* ctx, File* file) { @@ -557,7 +558,7 @@ static bool storage_int_dir_open(void* ctx, File* file, const char* path) { } file->error_id = storage_int_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_int_dir_close(void* ctx, File* file) { @@ -573,7 +574,7 @@ static bool storage_int_dir_close(void* ctx, File* file) { file->error_id = storage_int_parse_error(file->internal_error_id); lfs_handle_free(handle); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_int_dir_read( @@ -614,7 +615,7 @@ static bool storage_int_dir_read( file->error_id = storage_int_parse_error(file->internal_error_id); } - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } static bool storage_int_dir_rewind(void* ctx, File* file) { @@ -629,7 +630,7 @@ static bool storage_int_dir_rewind(void* ctx, File* file) { } file->error_id = storage_int_parse_error(file->internal_error_id); - return (file->error_id == FSE_OK); + return file->error_id == FSE_OK; } /******************* Common FS Functions *******************/ diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_config.h b/applications/settings/desktop_settings/scenes/desktop_settings_scene_config.h index 52b8829bee6..4a1d0370162 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_config.h +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_config.h @@ -11,4 +11,4 @@ ADD_SCENE(desktop_settings, pin_setup_howto2, PinSetupHowto2) ADD_SCENE(desktop_settings, pin_setup_done, PinSetupDone) ADD_SCENE(desktop_settings, quick_apps_menu, QuickAppsMenu) -ADD_SCENE(desktop_settings, quick_apps_direction_menu, QuickAppsDirectionMenu) \ No newline at end of file +ADD_SCENE(desktop_settings, quick_apps_direction_menu, QuickAppsDirectionMenu) diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index e46473a7195..384c0739c94 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -8,17 +8,17 @@ #define APPS_COUNT (FLIPPER_APPS_COUNT + FLIPPER_EXTERNAL_APPS_COUNT) -#define DEFAULT_INDEX (0) -#define EXTERNAL_BROWSER_NAME ("( ) Apps Menu (Default)") +#define DEFAULT_INDEX (0) +#define EXTERNAL_BROWSER_NAME ("( ) Apps Menu (Default)") #define EXTERNAL_BROWSER_NAME_SELECTED ("(*) Apps Menu (Default)") -#define PASSPORT_NAME ("( ) Passport (Default)") -#define PASSPORT_NAME_SELECTED ("(*) Passport (Default)") +#define PASSPORT_NAME ("( ) Passport (Default)") +#define PASSPORT_NAME_SELECTED ("(*) Passport (Default)") -#define SELECTED_PREFIX ("(*) ") +#define SELECTED_PREFIX ("(*) ") #define NOT_SELECTED_PREFIX ("( ) ") -#define EXTERNAL_APPLICATION_INDEX (1) -#define EXTERNAL_APPLICATION_NAME ("( ) [Select App]") +#define EXTERNAL_APPLICATION_INDEX (1) +#define EXTERNAL_APPLICATION_NAME ("( ) [Select App]") #define EXTERNAL_APPLICATION_NAME_SELECTED ("(*) [Select App]") #define PRESELECTED_SPECIAL 0xffffffff diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_i.h b/applications/settings/desktop_settings/scenes/desktop_settings_scene_i.h index 657680bc351..207824a6264 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_i.h +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_i.h @@ -1,10 +1,10 @@ #pragma once -#define SCENE_STATE_PIN_AUTH_DISABLE (0) +#define SCENE_STATE_PIN_AUTH_DISABLE (0) #define SCENE_STATE_PIN_AUTH_CHANGE_PIN (1) #define SCENE_STATE_PIN_ERROR_MISMATCH (0) -#define SCENE_STATE_PIN_ERROR_WRONG (1) +#define SCENE_STATE_PIN_ERROR_WRONG (1) #define SCENE_STATE_SET_FAVORITE_APP (0) -#define SCENE_STATE_SET_DUMMY_APP (1 << 8) +#define SCENE_STATE_SET_DUMMY_APP (1 << 8) diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_auth.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_auth.c index b73fe347b2d..5af25cd614c 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_auth.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_auth.c @@ -8,8 +8,8 @@ #include "desktop_settings_scene.h" #include "desktop_settings_scene_i.h" -#define SCENE_EVENT_EXIT (0U) -#define SCENE_EVENT_PINS_EQUAL (1U) +#define SCENE_EVENT_EXIT (0U) +#define SCENE_EVENT_PINS_EQUAL (1U) #define SCENE_EVENT_PINS_DIFFERENT (2U) static void pin_auth_done_callback(const PinCode* pin_code, void* context) { diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_menu.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_menu.c index 950be4c5a3e..7375edd3f4e 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_menu.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_menu.c @@ -5,8 +5,8 @@ #include "desktop_settings_scene.h" #include "desktop_settings_scene_i.h" -#define SCENE_EVENT_SET_PIN 0 -#define SCENE_EVENT_CHANGE_PIN 1 +#define SCENE_EVENT_SET_PIN 0 +#define SCENE_EVENT_CHANGE_PIN 1 #define SCENE_EVENT_DISABLE_PIN 2 static void desktop_settings_scene_pin_menu_submenu_callback(void* context, uint32_t index) { diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup.c index 5b8aa8638af..93012330aa8 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_pin_setup.c @@ -9,10 +9,10 @@ #include "desktop_settings_scene_i.h" #include -#define SCENE_EVENT_EXIT (0U) +#define SCENE_EVENT_EXIT (0U) #define SCENE_EVENT_1ST_PIN_ENTERED (1U) -#define SCENE_EVENT_PINS_EQUAL (2U) -#define SCENE_EVENT_PINS_DIFFERENT (3U) +#define SCENE_EVENT_PINS_EQUAL (2U) +#define SCENE_EVENT_PINS_DIFFERENT (3U) static void pin_setup_done_callback(const PinCode* pin_code, void* context) { furi_assert(pin_code); diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_quick_apps_menu.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_quick_apps_menu.c index acba4fa2558..a7000204f5b 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_quick_apps_menu.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_quick_apps_menu.c @@ -6,7 +6,7 @@ #include "desktop_settings_scene_i.h" #define SCENE_EVENT_SET_DEFAULT (0U) -#define SCENE_EVENT_SET_DUMMY (1U) +#define SCENE_EVENT_SET_DUMMY (1U) static void desktop_settings_scene_quick_apps_menu_submenu_callback(void* context, uint32_t index) { diff --git a/applications/settings/dolphin_passport/passport.c b/applications/settings/dolphin_passport/passport.c index aae53cd2a68..6419f4366ac 100644 --- a/applications/settings/dolphin_passport/passport.c +++ b/applications/settings/dolphin_passport/passport.c @@ -7,7 +7,7 @@ #include -#define MOODS_TOTAL 3 +#define MOODS_TOTAL 3 #define BUTTHURT_MAX 3 static const Icon* const portrait_happy[BUTTHURT_MAX] = { diff --git a/applications/settings/power_settings_app/power_settings_app.h b/applications/settings/power_settings_app/power_settings_app.h index 09cc5af7ae2..e19e7c983e3 100644 --- a/applications/settings/power_settings_app/power_settings_app.h +++ b/applications/settings/power_settings_app/power_settings_app.h @@ -31,4 +31,7 @@ typedef enum { PowerSettingsAppViewDialog, } PowerSettingsAppView; -typedef enum { RebootTypeDFU, RebootTypeNormal } RebootType; +typedef enum { + RebootTypeDFU, + RebootTypeNormal +} RebootType; diff --git a/applications/settings/power_settings_app/views/battery_info.c b/applications/settings/power_settings_app/views/battery_info.c index c626d18449c..e4c040b9c71 100644 --- a/applications/settings/power_settings_app/views/battery_info.c +++ b/applications/settings/power_settings_app/views/battery_info.c @@ -4,7 +4,7 @@ #include #include -#define LOW_CHARGE_THRESHOLD (10) +#define LOW_CHARGE_THRESHOLD (10) #define HIGH_DRAIN_CURRENT_THRESHOLD (-100) struct BatteryInfo { @@ -18,7 +18,7 @@ static void draw_stat(Canvas* canvas, int x, int y, const Icon* icon, char* val) canvas_draw_box(canvas, x - 4, y + 16, 24, 6); canvas_set_color(canvas, ColorBlack); canvas_draw_str_aligned(canvas, x + 8, y + 22, AlignCenter, AlignBottom, val); -}; +} static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { char emote[20] = {}; @@ -88,7 +88,7 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) { canvas_draw_str_aligned(canvas, 92, y + 3, AlignCenter, AlignCenter, emote); canvas_draw_str_aligned(canvas, 92, y + 15, AlignCenter, AlignCenter, header); canvas_draw_str_aligned(canvas, 92, y + 27, AlignCenter, AlignCenter, value); -}; +} static void battery_info_draw_callback(Canvas* canvas, void* context) { furi_assert(context); diff --git a/applications/settings/storage_settings/scenes/storage_settings_scene_benchmark.c b/applications/settings/storage_settings/scenes/storage_settings_scene_benchmark.c index bfc9ac9c935..c07ab1ae688 100644 --- a/applications/settings/storage_settings/scenes/storage_settings_scene_benchmark.c +++ b/applications/settings/storage_settings/scenes/storage_settings_scene_benchmark.c @@ -4,9 +4,9 @@ #include #define BENCH_DATA_SIZE 4096 -#define BENCH_COUNT 6 -#define BENCH_REPEATS 4 -#define BENCH_FILE EXT_PATH("rwfiletest.bin") +#define BENCH_COUNT 6 +#define BENCH_REPEATS 4 +#define BENCH_FILE EXT_PATH("rwfiletest.bin") static void storage_settings_scene_benchmark_dialog_callback(DialogExResult result, void* context) { diff --git a/applications/system/hid_app/assets/Alt_17x10.png b/applications/system/hid_app/assets/Alt_17x10.png index 93041d25039..78529ca07d7 100644 Binary files a/applications/system/hid_app/assets/Alt_17x10.png and b/applications/system/hid_app/assets/Alt_17x10.png differ diff --git a/applications/system/hid_app/assets/Alt_active_17x9.png b/applications/system/hid_app/assets/Alt_active_17x9.png new file mode 100755 index 00000000000..46a21a2e855 Binary files /dev/null and b/applications/system/hid_app/assets/Alt_active_17x9.png differ diff --git a/applications/system/hid_app/assets/Alt_pressed_17x10.png b/applications/system/hid_app/assets/Alt_pressed_17x10.png deleted file mode 100644 index e7421c8c0bf..00000000000 Binary files a/applications/system/hid_app/assets/Alt_pressed_17x10.png and /dev/null differ diff --git a/applications/system/hid_app/assets/Backspace_9x7.png b/applications/system/hid_app/assets/Backspace_9x7.png deleted file mode 100644 index e098cf67616..00000000000 Binary files a/applications/system/hid_app/assets/Backspace_9x7.png and /dev/null differ diff --git a/applications/system/hid_app/assets/Cmd_17x10.png b/applications/system/hid_app/assets/Cmd_17x10.png index 26ca3395c69..b29da07b716 100644 Binary files a/applications/system/hid_app/assets/Cmd_17x10.png and b/applications/system/hid_app/assets/Cmd_17x10.png differ diff --git a/applications/system/hid_app/assets/Cmd_active_17x9.png b/applications/system/hid_app/assets/Cmd_active_17x9.png new file mode 100755 index 00000000000..9d31b4eb3ef Binary files /dev/null and b/applications/system/hid_app/assets/Cmd_active_17x9.png differ diff --git a/applications/system/hid_app/assets/Cmd_pressed_17x10.png b/applications/system/hid_app/assets/Cmd_pressed_17x10.png deleted file mode 100644 index 274c3e070ae..00000000000 Binary files a/applications/system/hid_app/assets/Cmd_pressed_17x10.png and /dev/null differ diff --git a/applications/system/hid_app/assets/Ctrl_17x10.png b/applications/system/hid_app/assets/Ctrl_17x10.png index 0eda7216000..05be3292eba 100644 Binary files a/applications/system/hid_app/assets/Ctrl_17x10.png and b/applications/system/hid_app/assets/Ctrl_17x10.png differ diff --git a/applications/system/hid_app/assets/Ctrl_active_17x9.png b/applications/system/hid_app/assets/Ctrl_active_17x9.png new file mode 100755 index 00000000000..6fade6dd77d Binary files /dev/null and b/applications/system/hid_app/assets/Ctrl_active_17x9.png differ diff --git a/applications/system/hid_app/assets/Ctrl_pressed_17x10.png b/applications/system/hid_app/assets/Ctrl_pressed_17x10.png deleted file mode 100644 index 978a1090c2e..00000000000 Binary files a/applications/system/hid_app/assets/Ctrl_pressed_17x10.png and /dev/null differ diff --git a/applications/system/hid_app/assets/Del_17x10.png b/applications/system/hid_app/assets/Del_17x10.png index 13d73698307..95cbf7d5bd9 100644 Binary files a/applications/system/hid_app/assets/Del_17x10.png and b/applications/system/hid_app/assets/Del_17x10.png differ diff --git a/applications/system/hid_app/assets/Enter_11x7.png b/applications/system/hid_app/assets/Enter_11x7.png new file mode 100755 index 00000000000..d41b8feffbd Binary files /dev/null and b/applications/system/hid_app/assets/Enter_11x7.png differ diff --git a/applications/system/hid_app/assets/Esc_17x10.png b/applications/system/hid_app/assets/Esc_17x10.png index 6a011e97a8a..83a6f225fc6 100644 Binary files a/applications/system/hid_app/assets/Esc_17x10.png and b/applications/system/hid_app/assets/Esc_17x10.png differ diff --git a/applications/system/hid_app/assets/Shift_active_7x9.png b/applications/system/hid_app/assets/Shift_active_7x9.png new file mode 100644 index 00000000000..1ec9ce11e8a Binary files /dev/null and b/applications/system/hid_app/assets/Shift_active_7x9.png differ diff --git a/applications/system/hid_app/assets/Shift_inactive_7x9.png b/applications/system/hid_app/assets/Shift_inactive_7x9.png new file mode 100644 index 00000000000..1cd97076edc Binary files /dev/null and b/applications/system/hid_app/assets/Shift_inactive_7x9.png differ diff --git a/applications/system/hid_app/assets/Shift_pressed_7x10.png b/applications/system/hid_app/assets/Shift_pressed_7x10.png deleted file mode 100644 index 4f6b4b58eac..00000000000 Binary files a/applications/system/hid_app/assets/Shift_pressed_7x10.png and /dev/null differ diff --git a/applications/system/hid_app/assets/Tab_17x10.png b/applications/system/hid_app/assets/Tab_17x10.png index c62d75c0db5..4d8471483e5 100644 Binary files a/applications/system/hid_app/assets/Tab_17x10.png and b/applications/system/hid_app/assets/Tab_17x10.png differ diff --git a/applications/system/hid_app/assets/Tab_19x12.png b/applications/system/hid_app/assets/Tab_19x12.png new file mode 100755 index 00000000000..4dbde3babfc Binary files /dev/null and b/applications/system/hid_app/assets/Tab_19x12.png differ diff --git a/applications/system/hid_app/assets/apostrophe_button_9x11.png b/applications/system/hid_app/assets/apostrophe_button_9x11.png new file mode 100644 index 00000000000..0f54f0e2b15 Binary files /dev/null and b/applications/system/hid_app/assets/apostrophe_button_9x11.png differ diff --git a/applications/system/hid_app/assets/backslash_button_9x11.png b/applications/system/hid_app/assets/backslash_button_9x11.png new file mode 100755 index 00000000000..6cac74a57a1 Binary files /dev/null and b/applications/system/hid_app/assets/backslash_button_9x11.png differ diff --git a/applications/system/hid_app/assets/backspace_19x11.png b/applications/system/hid_app/assets/backspace_19x11.png new file mode 100755 index 00000000000..caf92807b5f Binary files /dev/null and b/applications/system/hid_app/assets/backspace_19x11.png differ diff --git a/applications/system/hid_app/assets/backspace_hovered_9x11.png b/applications/system/hid_app/assets/backspace_hovered_9x11.png new file mode 100755 index 00000000000..17cb1b7403b Binary files /dev/null and b/applications/system/hid_app/assets/backspace_hovered_9x11.png differ diff --git a/applications/system/hid_app/assets/backtick_button_9x11.png b/applications/system/hid_app/assets/backtick_button_9x11.png new file mode 100755 index 00000000000..1e5955a03ac Binary files /dev/null and b/applications/system/hid_app/assets/backtick_button_9x11.png differ diff --git a/applications/system/hid_app/assets/brace_left_button_9x11.png b/applications/system/hid_app/assets/brace_left_button_9x11.png new file mode 100755 index 00000000000..a61db48f369 Binary files /dev/null and b/applications/system/hid_app/assets/brace_left_button_9x11.png differ diff --git a/applications/system/hid_app/assets/brace_right_button_9x11.png b/applications/system/hid_app/assets/brace_right_button_9x11.png new file mode 100755 index 00000000000..bf6b927f192 Binary files /dev/null and b/applications/system/hid_app/assets/brace_right_button_9x11.png differ diff --git a/applications/system/hid_app/assets/equals_button_9x11.png b/applications/system/hid_app/assets/equals_button_9x11.png new file mode 100755 index 00000000000..8fe8afe34d3 Binary files /dev/null and b/applications/system/hid_app/assets/equals_button_9x11.png differ diff --git a/applications/system/hid_app/assets/hash_button_9x11.png b/applications/system/hid_app/assets/hash_button_9x11.png new file mode 100755 index 00000000000..bddc7aaceae Binary files /dev/null and b/applications/system/hid_app/assets/hash_button_9x11.png differ diff --git a/applications/system/hid_app/assets/percent_button_9x11.png b/applications/system/hid_app/assets/percent_button_9x11.png new file mode 100755 index 00000000000..ce12dcbf1e4 Binary files /dev/null and b/applications/system/hid_app/assets/percent_button_9x11.png differ diff --git a/applications/system/hid_app/assets/quote_button_9x11.png b/applications/system/hid_app/assets/quote_button_9x11.png new file mode 100755 index 00000000000..e96d29ddcdb Binary files /dev/null and b/applications/system/hid_app/assets/quote_button_9x11.png differ diff --git a/applications/system/hid_app/assets/slash_button_9x11.png b/applications/system/hid_app/assets/slash_button_9x11.png new file mode 100755 index 00000000000..60871320ffd Binary files /dev/null and b/applications/system/hid_app/assets/slash_button_9x11.png differ diff --git a/applications/system/hid_app/assets/sq_bracket_left_button_9x11.png b/applications/system/hid_app/assets/sq_bracket_left_button_9x11.png new file mode 100755 index 00000000000..0983db12962 Binary files /dev/null and b/applications/system/hid_app/assets/sq_bracket_left_button_9x11.png differ diff --git a/applications/system/hid_app/assets/sq_bracket_right_button_9x11.png b/applications/system/hid_app/assets/sq_bracket_right_button_9x11.png new file mode 100755 index 00000000000..48f9c77e4df Binary files /dev/null and b/applications/system/hid_app/assets/sq_bracket_right_button_9x11.png differ diff --git a/applications/system/hid_app/assets/underscore_button_9x11.png b/applications/system/hid_app/assets/underscore_button_9x11.png new file mode 100755 index 00000000000..eb000cba552 Binary files /dev/null and b/applications/system/hid_app/assets/underscore_button_9x11.png differ diff --git a/applications/system/hid_app/views.h b/applications/system/hid_app/views.h index f94a55cc65b..6f027e2509d 100644 --- a/applications/system/hid_app/views.h +++ b/applications/system/hid_app/views.h @@ -9,4 +9,4 @@ typedef enum { BtHidViewTikTok, HidViewDialog, HidViewPopup, -} HidView; \ No newline at end of file +} HidView; diff --git a/applications/system/hid_app/views/hid_keyboard.c b/applications/system/hid_app/views/hid_keyboard.c index 9dd2ad65525..0b8c4ed3195 100644 --- a/applications/system/hid_app/views/hid_keyboard.c +++ b/applications/system/hid_app/views/hid_keyboard.c @@ -30,6 +30,7 @@ typedef struct { char key; char shift_key; const Icon* icon; + const Icon* icon_shift; const Icon* icon_toggled; uint8_t value; } HidKeyboardKey; @@ -39,12 +40,12 @@ typedef struct { int8_t y; } HidKeyboardPoint; // 4 BY 12 -#define MARGIN_TOP 0 -#define MARGIN_LEFT 4 -#define KEY_WIDTH 9 -#define KEY_HEIGHT 12 -#define KEY_PADDING 1 -#define ROW_COUNT 7 +#define MARGIN_TOP 0 +#define MARGIN_LEFT 3 +#define KEY_WIDTH 11 +#define KEY_HEIGHT 13 +#define KEY_PADDING -1 +#define ROW_COUNT 7 #define COLUMN_COUNT 12 // 0 width items are not drawn, but their value is used @@ -66,15 +67,23 @@ const HidKeyboardKey hid_keyboard_keyset[ROW_COUNT][COLUMN_COUNT] = { { {.width = 1, .icon = NULL, .key = '1', .shift_key = '!', .value = HID_KEYBOARD_1}, {.width = 1, .icon = NULL, .key = '2', .shift_key = '@', .value = HID_KEYBOARD_2}, - {.width = 1, .icon = NULL, .key = '3', .shift_key = '#', .value = HID_KEYBOARD_3}, + {.width = 1, + .icon = NULL, + .icon_shift = &I_hash_button_9x11, + .key = '3', + .value = HID_KEYBOARD_3}, {.width = 1, .icon = NULL, .key = '4', .shift_key = '$', .value = HID_KEYBOARD_4}, - {.width = 1, .icon = NULL, .key = '5', .shift_key = '%', .value = HID_KEYBOARD_5}, + {.width = 1, + .icon = NULL, + .icon_shift = &I_percent_button_9x11, + .key = '5', + .value = HID_KEYBOARD_5}, {.width = 1, .icon = NULL, .key = '6', .shift_key = '^', .value = HID_KEYBOARD_6}, {.width = 1, .icon = NULL, .key = '7', .shift_key = '&', .value = HID_KEYBOARD_7}, {.width = 1, .icon = NULL, .key = '8', .shift_key = '*', .value = HID_KEYBOARD_8}, {.width = 1, .icon = NULL, .key = '9', .shift_key = '(', .value = HID_KEYBOARD_9}, {.width = 1, .icon = NULL, .key = '0', .shift_key = ')', .value = HID_KEYBOARD_0}, - {.width = 2, .icon = &I_Backspace_9x7, .value = HID_KEYBOARD_DELETE}, + {.width = 2, .icon = &I_backspace_19x11, .value = HID_KEYBOARD_DELETE}, {.width = 0, .value = HID_KEYBOARD_DELETE}, }, { @@ -88,11 +97,13 @@ const HidKeyboardKey hid_keyboard_keyset[ROW_COUNT][COLUMN_COUNT] = { {.width = 1, .icon = NULL, .key = 'i', .shift_key = 'I', .value = HID_KEYBOARD_I}, {.width = 1, .icon = NULL, .key = 'o', .shift_key = 'O', .value = HID_KEYBOARD_O}, {.width = 1, .icon = NULL, .key = 'p', .shift_key = 'P', .value = HID_KEYBOARD_P}, - {.width = 1, .icon = NULL, .key = '[', .shift_key = '{', .value = HID_KEYBOARD_OPEN_BRACKET}, {.width = 1, - .icon = NULL, - .key = ']', - .shift_key = '}', + .icon = &I_sq_bracket_left_button_9x11, + .icon_shift = &I_brace_left_button_9x11, + .value = HID_KEYBOARD_OPEN_BRACKET}, + {.width = 1, + .icon = &I_sq_bracket_right_button_9x11, + .icon_shift = &I_brace_right_button_9x11, .value = HID_KEYBOARD_CLOSE_BRACKET}, }, { @@ -117,16 +128,26 @@ const HidKeyboardKey hid_keyboard_keyset[ROW_COUNT][COLUMN_COUNT] = { {.width = 1, .icon = NULL, .key = 'b', .shift_key = 'B', .value = HID_KEYBOARD_B}, {.width = 1, .icon = NULL, .key = 'n', .shift_key = 'N', .value = HID_KEYBOARD_N}, {.width = 1, .icon = NULL, .key = 'm', .shift_key = 'M', .value = HID_KEYBOARD_M}, - {.width = 1, .icon = NULL, .key = '/', .shift_key = '?', .value = HID_KEYBOARD_SLASH}, - {.width = 1, .icon = NULL, .key = '\\', .shift_key = '|', .value = HID_KEYBOARD_BACKSLASH}, - {.width = 1, .icon = NULL, .key = '`', .shift_key = '~', .value = HID_KEYBOARD_GRAVE_ACCENT}, + {.width = 1, .icon = &I_slash_button_9x11, .shift_key = '?', .value = HID_KEYBOARD_SLASH}, + {.width = 1, + .icon = &I_backslash_button_9x11, + .shift_key = '|', + .value = HID_KEYBOARD_BACKSLASH}, + {.width = 1, + .icon = &I_backtick_button_9x11, + .shift_key = '~', + .value = HID_KEYBOARD_GRAVE_ACCENT}, {.width = 1, .icon = &I_ButtonUp_7x4, .value = HID_KEYBOARD_UP_ARROW}, - {.width = 1, .icon = NULL, .key = '-', .shift_key = '_', .value = HID_KEYBOARD_MINUS}, + {.width = 1, + .icon = NULL, + .icon_shift = &I_underscore_button_9x11, + .key = '-', + .value = HID_KEYBOARD_MINUS}, }, { {.width = 1, - .icon = &I_Pin_arrow_up_7x9, - .icon_toggled = &I_Shift_pressed_7x10, + .icon = &I_Shift_inactive_7x9, + .icon_toggled = &I_Shift_active_7x9, .value = HID_KEYBOARD_L_SHIFT}, {.width = 1, .icon = NULL, .key = ',', .shift_key = '<', .value = HID_KEYBOARD_COMMA}, {.width = 1, .icon = NULL, .key = '.', .shift_key = '>', .value = HID_KEYBOARD_DOT}, @@ -134,8 +155,14 @@ const HidKeyboardKey hid_keyboard_keyset[ROW_COUNT][COLUMN_COUNT] = { {.width = 0, .value = HID_KEYBOARD_SPACEBAR}, {.width = 0, .value = HID_KEYBOARD_SPACEBAR}, {.width = 0, .value = HID_KEYBOARD_SPACEBAR}, - {.width = 1, .icon = NULL, .key = '\'', .shift_key = '\"', .value = HID_KEYBOARD_APOSTROPHE}, - {.width = 1, .icon = NULL, .key = '=', .shift_key = '+', .value = HID_KEYBOARD_EQUAL_SIGN}, + {.width = 1, + .icon = &I_apostrophe_button_9x11, + .icon_shift = &I_quote_button_9x11, + .value = HID_KEYBOARD_APOSTROPHE}, + {.width = 1, + .icon = &I_equals_button_9x11, + .shift_key = '+', + .value = HID_KEYBOARD_EQUAL_SIGN}, {.width = 1, .icon = &I_ButtonLeft_4x7, .value = HID_KEYBOARD_LEFT_ARROW}, {.width = 1, .icon = &I_ButtonDown_7x4, .value = HID_KEYBOARD_DOWN_ARROW}, {.width = 1, .icon = &I_ButtonRight_4x7, .value = HID_KEYBOARD_RIGHT_ARROW}, @@ -143,17 +170,17 @@ const HidKeyboardKey hid_keyboard_keyset[ROW_COUNT][COLUMN_COUNT] = { { {.width = 2, .icon = &I_Ctrl_17x10, - .icon_toggled = &I_Ctrl_pressed_17x10, + .icon_toggled = &I_Ctrl_active_17x9, .value = HID_KEYBOARD_L_CTRL}, {.width = 0, .value = HID_KEYBOARD_L_CTRL}, {.width = 2, .icon = &I_Alt_17x10, - .icon_toggled = &I_Alt_pressed_17x10, + .icon_toggled = &I_Alt_active_17x9, .value = HID_KEYBOARD_L_ALT}, {.width = 0, .value = HID_KEYBOARD_L_ALT}, {.width = 2, .icon = &I_Cmd_17x10, - .icon_toggled = &I_Cmd_pressed_17x10, + .icon_toggled = &I_Cmd_active_17x9, .value = HID_KEYBOARD_L_GUI}, {.width = 0, .value = HID_KEYBOARD_L_GUI}, {.width = 2, .icon = &I_Tab_17x10, .value = HID_KEYBOARD_TAB}, @@ -194,8 +221,47 @@ static void hid_keyboard_draw_key( keyWidth, KEY_HEIGHT); } + + if(model->shift && key.icon_shift != NULL) { + // Icon and shift + const Icon* key_icon = key.icon_shift; + + if((model->ctrl && key.value == HID_KEYBOARD_L_CTRL) || + (model->alt && key.value == HID_KEYBOARD_L_ALT) || + (key.value == HID_KEYBOARD_L_SHIFT) || + (model->gui && key.value == HID_KEYBOARD_L_GUI)) { + if(key.icon_toggled) { + key_icon = key.icon_toggled; + } + } + // Draw the icon centered on the button + canvas_draw_icon( + canvas, + MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING) + keyWidth / 2 - key_icon->width / 2, + MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING) + KEY_HEIGHT / 2 - key_icon->height / 2, + key_icon); + + return; + } + if(model->shift && key.shift_key != 0) { + // Text and shift + char key_str[2] = {key.shift_key, '\0'}; + + canvas_draw_str_aligned( + canvas, + MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING) + keyWidth / 2 + 1, + MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING) + KEY_HEIGHT / 2 + 1, + AlignCenter, + AlignCenter, + key_str); + + return; + } + if(key.icon != NULL) { + // Icon with no shift const Icon* key_icon = key.icon; + if((model->ctrl && key.value == HID_KEYBOARD_L_CTRL) || (model->alt && key.value == HID_KEYBOARD_L_ALT) || (model->shift && key.value == HID_KEYBOARD_L_SHIFT) || @@ -210,17 +276,29 @@ static void hid_keyboard_draw_key( MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING) + keyWidth / 2 - key_icon->width / 2, MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING) + KEY_HEIGHT / 2 - key_icon->height / 2, key_icon); - } else { - char key_str[2] = "\0\0"; - // If shift is toggled use the shift key when available - key_str[0] = (model->shift && key.shift_key != 0) ? key.shift_key : key.key; + + return; + } + + if(key.key != 0) { + // Text with no shift + char key_str[2] = {key.key, '\0'}; + uint8_t key_offset = 0; + + // Special case for numbers, draw them one pixel lower + if(key.value >= HID_KEYBOARD_1 && key.value <= HID_KEYBOARD_0) { + key_offset = 1; + } + canvas_draw_str_aligned( canvas, MARGIN_LEFT + x * (KEY_WIDTH + KEY_PADDING) + keyWidth / 2 + 1, - MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING) + KEY_HEIGHT / 2, + MARGIN_TOP + y * (KEY_HEIGHT + KEY_PADDING) + KEY_HEIGHT / 2 + key_offset, AlignCenter, AlignCenter, key_str); + + return; } } @@ -400,8 +478,7 @@ HidKeyboard* hid_keyboard_alloc(Hid* bt_hid) { view_set_draw_callback(hid_keyboard->view, hid_keyboard_draw_callback); view_set_input_callback(hid_keyboard->view, hid_keyboard_input_callback); - with_view_model( - hid_keyboard->view, HidKeyboardModel * model, { model->y = 1; }, true); + with_view_model(hid_keyboard->view, HidKeyboardModel * model, { model->y = 1; }, true); return hid_keyboard; } diff --git a/applications/system/hid_app/views/hid_mouse.h b/applications/system/hid_app/views/hid_mouse.h index d9fb2fd88a7..9a1bcc0285c 100644 --- a/applications/system/hid_app/views/hid_mouse.h +++ b/applications/system/hid_app/views/hid_mouse.h @@ -3,7 +3,7 @@ #include #define MOUSE_MOVE_SHORT 5 -#define MOUSE_MOVE_LONG 20 +#define MOUSE_MOVE_LONG 20 typedef struct Hid Hid; typedef struct HidMouse HidMouse; diff --git a/applications/system/hid_app/views/hid_mouse_clicker.c b/applications/system/hid_app/views/hid_mouse_clicker.c index 3a2a064cbb1..0bb815249df 100644 --- a/applications/system/hid_app/views/hid_mouse_clicker.c +++ b/applications/system/hid_app/views/hid_mouse_clicker.c @@ -5,6 +5,7 @@ #include "hid_icons.h" #define TAG "HidMouseClicker" + #define DEFAULT_CLICK_RATE 1 #define MAXIMUM_CLICK_RATE 60 diff --git a/applications/system/hid_app/views/hid_mouse_jiggler.h b/applications/system/hid_app/views/hid_mouse_jiggler.h index 0813b4351e1..0ed949aaeca 100644 --- a/applications/system/hid_app/views/hid_mouse_jiggler.h +++ b/applications/system/hid_app/views/hid_mouse_jiggler.h @@ -3,7 +3,7 @@ #include #define MOUSE_MOVE_SHORT 5 -#define MOUSE_MOVE_LONG 20 +#define MOUSE_MOVE_LONG 20 typedef struct Hid Hid; typedef struct HidMouseJiggler HidMouseJiggler; diff --git a/applications/system/js_app/js_modules.c b/applications/system/js_app/js_modules.c index fa533288455..9ab6cb14074 100644 --- a/applications/system/js_app/js_modules.c +++ b/applications/system/js_app/js_modules.c @@ -126,4 +126,4 @@ mjs_val_t js_module_require(JsModules* modules, const char* name, size_t name_le furi_string_free(module_name); return module_object; -} \ No newline at end of file +} diff --git a/applications/system/js_app/js_modules.h b/applications/system/js_app/js_modules.h index aff4d7e8df1..77e50786f47 100644 --- a/applications/system/js_app/js_modules.h +++ b/applications/system/js_app/js_modules.h @@ -4,7 +4,7 @@ #include #include -#define PLUGIN_APP_ID "js" +#define PLUGIN_APP_ID "js" #define PLUGIN_API_VERSION 1 typedef void* (*JsModeConstructor)(struct mjs* mjs, mjs_val_t* object); diff --git a/applications/system/js_app/modules/js_badusb.c b/applications/system/js_app/modules/js_badusb.c index 199773c3991..99f8958f761 100644 --- a/applications/system/js_app/modules/js_badusb.c +++ b/applications/system/js_app/modules/js_badusb.c @@ -159,7 +159,7 @@ static void js_badusb_is_connected(struct mjs* mjs) { uint16_t get_keycode_by_name(const char* key_name, size_t name_len) { if(name_len == 1) { // Single char - return (HID_ASCII_TO_KEY(key_name[0])); + return HID_ASCII_TO_KEY(key_name[0]); } for(size_t i = 0; i < COUNT_OF(key_codes); i++) { diff --git a/applications/system/js_app/modules/js_math.c b/applications/system/js_app/modules/js_math.c index b4c1cdca232..d8812e61bbb 100644 --- a/applications/system/js_app/modules/js_math.c +++ b/applications/system/js_app/modules/js_math.c @@ -2,8 +2,8 @@ #include "furi_hal_random.h" #include -#define JS_MATH_PI ((double)M_PI) -#define JS_MATH_E ((double)M_E) +#define JS_MATH_PI ((double)M_PI) +#define JS_MATH_E ((double)M_E) #define JS_MATH_EPSILON ((double)DBL_EPSILON) #define TAG "JsMath" diff --git a/applications/system/js_app/modules/js_notification.c b/applications/system/js_app/modules/js_notification.c index e1084be1390..2f57c45d1b2 100644 --- a/applications/system/js_app/modules/js_notification.c +++ b/applications/system/js_app/modules/js_notification.c @@ -106,4 +106,4 @@ static const FlipperAppPluginDescriptor plugin_descriptor = { const FlipperAppPluginDescriptor* js_notification_ep(void) { return &plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/system/js_app/modules/js_serial.c b/applications/system/js_app/modules/js_serial.c index 4f1b14f98c9..234eefb4324 100644 --- a/applications/system/js_app/modules/js_serial.c +++ b/applications/system/js_app/modules/js_serial.c @@ -3,7 +3,8 @@ #include "../js_modules.h" #include -#define TAG "js_serial" +#define TAG "JsSerial" + #define RX_BUF_LEN 2048 typedef struct { @@ -444,14 +445,14 @@ static int32_t js_serial_expect_check_pattern_start( int32_t pattern_last) { size_t array_len = PatternArray_size(patterns); if((pattern_last + 1) >= (int32_t)array_len) { - return (-1); + return -1; } for(size_t i = pattern_last + 1; i < array_len; i++) { if(PatternArray_get(patterns, i)->data[0] == value) { return i; } } - return (-1); + return -1; } static void js_serial_expect(struct mjs* mjs) { diff --git a/applications/system/js_app/modules/js_textbox.c b/applications/system/js_app/modules/js_textbox.c index d15cd2779dd..33798b29656 100644 --- a/applications/system/js_app/modules/js_textbox.c +++ b/applications/system/js_app/modules/js_textbox.c @@ -217,4 +217,4 @@ static const FlipperAppPluginDescriptor textbox_plugin_descriptor = { const FlipperAppPluginDescriptor* js_textbox_ep(void) { return &textbox_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/system/js_app/plugin_api/app_api_interface.h b/applications/system/js_app/plugin_api/app_api_interface.h index d0db44c4aa0..be4f78930d9 100644 --- a/applications/system/js_app/plugin_api/app_api_interface.h +++ b/applications/system/js_app/plugin_api/app_api_interface.h @@ -6,4 +6,4 @@ * Resolver interface with private application's symbols. * Implementation is contained in app_api_table.c */ -extern const ElfApiInterface* const application_api_interface; \ No newline at end of file +extern const ElfApiInterface* const application_api_interface; diff --git a/applications/system/js_app/plugin_api/js_plugin_api.h b/applications/system/js_app/plugin_api/js_plugin_api.h index 4918605876d..a817d34a90f 100644 --- a/applications/system/js_app/plugin_api/js_plugin_api.h +++ b/applications/system/js_app/plugin_api/js_plugin_api.h @@ -15,4 +15,4 @@ uint32_t js_flags_wait(struct mjs* mjs, uint32_t flags, uint32_t timeout); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/system/js_app/views/console_view.c b/applications/system/js_app/views/console_view.c index b87e5352847..67f5d9de877 100644 --- a/applications/system/js_app/views/console_view.c +++ b/applications/system/js_app/views/console_view.c @@ -1,10 +1,10 @@ #include "../js_app_i.h" #include "console_font.h" -#define CONSOLE_LINES 8 -#define CONSOLE_CHAR_W 5 +#define CONSOLE_LINES 8 +#define CONSOLE_CHAR_W 5 #define LINE_BREAKS_MAX 3 -#define LINE_LEN_MAX (128 / CONSOLE_CHAR_W) +#define LINE_LEN_MAX (128 / CONSOLE_CHAR_W) struct JsConsoleView { View* view; @@ -161,4 +161,4 @@ void console_view_free(JsConsoleView* console_view) { View* console_view_get_view(JsConsoleView* console_view) { return console_view->view; -} \ No newline at end of file +} diff --git a/applications/system/storage_move_to_sd/storage_move_to_sd.c b/applications/system/storage_move_to_sd/storage_move_to_sd.c index 12a77eafadd..652c34c7203 100644 --- a/applications/system/storage_move_to_sd/storage_move_to_sd.c +++ b/applications/system/storage_move_to_sd/storage_move_to_sd.c @@ -17,7 +17,7 @@ static bool storage_move_to_sd_check_entry(const char* name, FileInfo* fileinfo, return true; } - return (name && (*name != '.')); + return name && (*name != '.'); } bool storage_move_to_sd_perform(void) { diff --git a/applications/system/updater/util/update_task.c b/applications/system/updater/util/update_task.c index c0ea6421c50..0eae0eaf529 100644 --- a/applications/system/updater/util/update_task.c +++ b/applications/system/updater/util/update_task.c @@ -9,6 +9,8 @@ #include #include +#define TAG "UpdWorker" + static const char* update_task_stage_descr[] = { [UpdateTaskStageProgress] = "...", [UpdateTaskStageReadManifest] = "Loading update manifest", @@ -23,7 +25,9 @@ static const char* update_task_stage_descr[] = { [UpdateTaskStageOBValidation] = "Validating opt. bytes", [UpdateTaskStageLfsBackup] = "Backing up LFS", [UpdateTaskStageLfsRestore] = "Restoring LFS", - [UpdateTaskStageResourcesUpdate] = "Updating resources", + [UpdateTaskStageResourcesFileCleanup] = "Cleaning up files", + [UpdateTaskStageResourcesDirCleanup] = "Cleaning up directories", + [UpdateTaskStageResourcesFileUnpack] = "Extracting resources", [UpdateTaskStageSplashscreenInstall] = "Installing splashscreen", [UpdateTaskStageCompleted] = "Restarting...", [UpdateTaskStageError] = "Error", @@ -196,7 +200,19 @@ static const struct { .descr = "LFS I/O error", }, { - .stage = UpdateTaskStageResourcesUpdate, + .stage = UpdateTaskStageResourcesFileCleanup, + .percent_min = 0, + .percent_max = 100, + .descr = "SD card I/O error", + }, + { + .stage = UpdateTaskStageResourcesDirCleanup, + .percent_min = 0, + .percent_max = 100, + .descr = "SD card I/O error", + }, + { + .stage = UpdateTaskStageResourcesFileUnpack, .percent_min = 0, .percent_max = 100, .descr = "SD card I/O error", @@ -221,7 +237,10 @@ typedef struct { } UpdateTaskStageGroupMap; #define STAGE_DEF(GROUP, WEIGHT) \ - { .group = (GROUP), .weight = (WEIGHT), } + { \ + .group = (GROUP), \ + .weight = (WEIGHT), \ + } static const UpdateTaskStageGroupMap update_task_stage_progress[] = { [UpdateTaskStageProgress] = STAGE_DEF(UpdateTaskStageGroupMisc, 0), @@ -230,20 +249,22 @@ static const UpdateTaskStageGroupMap update_task_stage_progress[] = { [UpdateTaskStageLfsBackup] = STAGE_DEF(UpdateTaskStageGroupPreUpdate, 5), [UpdateTaskStageRadioImageValidate] = STAGE_DEF(UpdateTaskStageGroupRadio, 15), - [UpdateTaskStageRadioErase] = STAGE_DEF(UpdateTaskStageGroupRadio, 35), - [UpdateTaskStageRadioWrite] = STAGE_DEF(UpdateTaskStageGroupRadio, 60), + [UpdateTaskStageRadioErase] = STAGE_DEF(UpdateTaskStageGroupRadio, 25), + [UpdateTaskStageRadioWrite] = STAGE_DEF(UpdateTaskStageGroupRadio, 40), [UpdateTaskStageRadioInstall] = STAGE_DEF(UpdateTaskStageGroupRadio, 30), [UpdateTaskStageRadioBusy] = STAGE_DEF(UpdateTaskStageGroupRadio, 5), [UpdateTaskStageOBValidation] = STAGE_DEF(UpdateTaskStageGroupOptionBytes, 2), - [UpdateTaskStageValidateDFUImage] = STAGE_DEF(UpdateTaskStageGroupFirmware, 30), - [UpdateTaskStageFlashWrite] = STAGE_DEF(UpdateTaskStageGroupFirmware, 150), - [UpdateTaskStageFlashValidate] = STAGE_DEF(UpdateTaskStageGroupFirmware, 15), + [UpdateTaskStageValidateDFUImage] = STAGE_DEF(UpdateTaskStageGroupFirmware, 33), + [UpdateTaskStageFlashWrite] = STAGE_DEF(UpdateTaskStageGroupFirmware, 100), + [UpdateTaskStageFlashValidate] = STAGE_DEF(UpdateTaskStageGroupFirmware, 20), [UpdateTaskStageLfsRestore] = STAGE_DEF(UpdateTaskStageGroupPostUpdate, 5), - [UpdateTaskStageResourcesUpdate] = STAGE_DEF(UpdateTaskStageGroupResources, 255), + [UpdateTaskStageResourcesFileCleanup] = STAGE_DEF(UpdateTaskStageGroupResources, 100), + [UpdateTaskStageResourcesDirCleanup] = STAGE_DEF(UpdateTaskStageGroupResources, 50), + [UpdateTaskStageResourcesFileUnpack] = STAGE_DEF(UpdateTaskStageGroupResources, 255), [UpdateTaskStageSplashscreenInstall] = STAGE_DEF(UpdateTaskStageGroupSplashscreen, 5), [UpdateTaskStageCompleted] = STAGE_DEF(UpdateTaskStageGroupMisc, 1), @@ -288,6 +309,7 @@ static void update_task_calc_completed_stages(UpdateTask* update_task) { void update_task_set_progress(UpdateTask* update_task, UpdateTaskStage stage, uint8_t progress) { if(stage != UpdateTaskStageProgress) { + FURI_LOG_I(TAG, "Stage %d, progress %d", stage, progress); /* do not override more specific error states */ if((stage >= UpdateTaskStageError) && (update_task->state.stage >= UpdateTaskStageError)) { return; diff --git a/applications/system/updater/util/update_task.h b/applications/system/updater/util/update_task.h index a3c47429ecb..52bdfdbd235 100644 --- a/applications/system/updater/util/update_task.h +++ b/applications/system/updater/util/update_task.h @@ -9,7 +9,7 @@ extern "C" { #include #include -#define UPDATE_DELAY_OPERATION_OK 10 +#define UPDATE_DELAY_OPERATION_OK 10 #define UPDATE_DELAY_OPERATION_ERROR INT_MAX typedef enum { @@ -31,7 +31,9 @@ typedef enum { UpdateTaskStageFlashValidate, UpdateTaskStageLfsRestore, - UpdateTaskStageResourcesUpdate, + UpdateTaskStageResourcesFileCleanup, + UpdateTaskStageResourcesDirCleanup, + UpdateTaskStageResourcesFileUnpack, UpdateTaskStageSplashscreenInstall, UpdateTaskStageCompleted, diff --git a/applications/system/updater/util/update_task_i.h b/applications/system/updater/util/update_task_i.h index 1b664e57e4c..e2663c97da5 100644 --- a/applications/system/updater/util/update_task_i.h +++ b/applications/system/updater/util/update_task_i.h @@ -3,7 +3,7 @@ #include #include -#define UPDATE_TASK_NOERR 0 +#define UPDATE_TASK_NOERR 0 #define UPDATE_TASK_FAILED -1 typedef struct UpdateTask { diff --git a/applications/system/updater/util/update_task_worker_backup.c b/applications/system/updater/util/update_task_worker_backup.c index ef4276fac5e..8d5039a16da 100644 --- a/applications/system/updater/util/update_task_worker_backup.c +++ b/applications/system/updater/util/update_task_worker_backup.c @@ -35,36 +35,23 @@ static bool update_task_pre_update(UpdateTask* update_task) { furi_string_free(backup_file_path); return success; } - -typedef enum { - UpdateTaskResourcesWeightsFileCleanup = 20, - UpdateTaskResourcesWeightsDirCleanup = 20, - UpdateTaskResourcesWeightsFileUnpack = 60, -} UpdateTaskResourcesWeights; - -#define UPDATE_TASK_RESOURCES_FILE_TO_TOTAL_PERCENT 90 - typedef struct { UpdateTask* update_task; - int32_t total_files, processed_files; + TarArchive* archive; } TarUnpackProgress; static bool update_task_resource_unpack_cb(const char* name, bool is_directory, void* context) { UNUSED(name); UNUSED(is_directory); TarUnpackProgress* unpack_progress = context; - unpack_progress->processed_files++; + int32_t progress = 0, total = 0; + tar_archive_get_read_progress(unpack_progress->archive, &progress, &total); update_task_set_progress( - unpack_progress->update_task, - UpdateTaskStageProgress, - /* For this stage, last progress segment = extraction */ - (UpdateTaskResourcesWeightsFileCleanup + UpdateTaskResourcesWeightsDirCleanup) + - (unpack_progress->processed_files * UpdateTaskResourcesWeightsFileUnpack) / - (unpack_progress->total_files + 1)); + unpack_progress->update_task, UpdateTaskStageProgress, (progress * 100) / (total + 1)); return true; } -static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_t n_tar_entries) { +static void update_task_cleanup_resources(UpdateTask* update_task) { ResourceManifestReader* manifest_reader = resource_manifest_reader_alloc(update_task->storage); do { FURI_LOG_D(TAG, "Cleaning up old manifest"); @@ -73,20 +60,26 @@ static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_ break; } - const uint32_t n_approx_file_entries = - n_tar_entries * UPDATE_TASK_RESOURCES_FILE_TO_TOTAL_PERCENT / 100 + 1; - uint32_t n_dir_entries = 1; - ResourceManifestEntry* entry_ptr = NULL; - uint32_t n_processed_entries = 0; + /* Iterate over manifest and calculate entries count */ + uint32_t n_file_entries = 1, n_dir_entries = 1; + while((entry_ptr = resource_manifest_reader_next(manifest_reader))) { + if(entry_ptr->type == ResourceManifestEntryTypeFile) { + n_file_entries++; + } else if(entry_ptr->type == ResourceManifestEntryTypeDirectory) { + n_dir_entries++; + } + } + resource_manifest_rewind(manifest_reader); + + update_task_set_progress(update_task, UpdateTaskStageResourcesFileCleanup, 0); + uint32_t n_processed_file_entries = 0; while((entry_ptr = resource_manifest_reader_next(manifest_reader))) { if(entry_ptr->type == ResourceManifestEntryTypeFile) { update_task_set_progress( update_task, UpdateTaskStageProgress, - /* For this stage, first pass = old manifest's file cleanup */ - (n_processed_entries++ * UpdateTaskResourcesWeightsFileCleanup) / - n_approx_file_entries); + (n_processed_file_entries++ * 100) / n_file_entries); FuriString* file_path = furi_string_alloc(); path_concat( @@ -103,21 +96,17 @@ static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_ storage_error_get_desc(result)); } furi_string_free(file_path); - } else if(entry_ptr->type == ResourceManifestEntryTypeDirectory) { - n_dir_entries++; } } - n_processed_entries = 0; + update_task_set_progress(update_task, UpdateTaskStageResourcesDirCleanup, 0); + uint32_t n_processed_dir_entries = 0; while((entry_ptr = resource_manifest_reader_previous(manifest_reader))) { if(entry_ptr->type == ResourceManifestEntryTypeDirectory) { update_task_set_progress( update_task, UpdateTaskStageProgress, - /* For this stage, second 10% of progress = cleanup directories */ - UpdateTaskResourcesWeightsFileCleanup + - (n_processed_entries++ * UpdateTaskResourcesWeightsDirCleanup) / - n_dir_entries); + (n_processed_dir_entries++ * 100) / n_dir_entries); FuriString* folder_path = furi_string_alloc(); @@ -166,26 +155,22 @@ static bool update_task_post_update(UpdateTask* update_task) { if(update_task->state.groups & UpdateTaskStageGroupResources) { TarUnpackProgress progress = { .update_task = update_task, - .total_files = 0, - .processed_files = 0, + .archive = archive, }; - update_task_set_progress(update_task, UpdateTaskStageResourcesUpdate, 0); path_concat( furi_string_get_cstr(update_task->update_path), furi_string_get_cstr(update_task->manifest->resource_bundle), file_path); - tar_archive_set_file_callback(archive, update_task_resource_unpack_cb, &progress); - CHECK_RESULT( - tar_archive_open(archive, furi_string_get_cstr(file_path), TAR_OPEN_MODE_READ)); + CHECK_RESULT(tar_archive_open( + archive, furi_string_get_cstr(file_path), TarOpenModeReadHeatshrink)); - progress.total_files = tar_archive_get_entries_count(archive); - if(progress.total_files > 0) { - update_task_cleanup_resources(update_task, progress.total_files); + update_task_cleanup_resources(update_task); - CHECK_RESULT(tar_archive_unpack_to(archive, STORAGE_EXT_PATH_PREFIX, NULL)); - } + update_task_set_progress(update_task, UpdateTaskStageResourcesFileUnpack, 0); + tar_archive_set_file_callback(archive, update_task_resource_unpack_cb, &progress); + CHECK_RESULT(tar_archive_unpack_to(archive, STORAGE_EXT_PATH_PREFIX, NULL)); } if(update_task->state.groups & UpdateTaskStageGroupSplashscreen) { diff --git a/applications/system/updater/util/update_task_worker_flasher.c b/applications/system/updater/util/update_task_worker_flasher.c index 40f58f462b7..848cc549428 100644 --- a/applications/system/updater/util/update_task_worker_flasher.c +++ b/applications/system/updater/util/update_task_worker_flasher.c @@ -13,12 +13,12 @@ #define TAG "UpdWorkerRam" -#define STM_DFU_VENDOR_ID 0x0483 -#define STM_DFU_PRODUCT_ID 0xDF11 +#define STM_DFU_VENDOR_ID 0x0483 +#define STM_DFU_PRODUCT_ID 0xDF11 /* Written into DFU file by build pipeline */ #define FLIPPER_ZERO_DFU_DEVICE_CODE 0xFFFF /* Time, in ms, to wait for system restart by C2 before crashing */ -#define C2_MODE_SWITCH_TIMEOUT 10000 +#define C2_MODE_SWITCH_TIMEOUT 10000 static const DfuValidationParams flipper_dfu_params = { .device = FLIPPER_ZERO_DFU_DEVICE_CODE, @@ -36,7 +36,7 @@ static bool page_task_compare_flash( const uint8_t* update_block, uint16_t update_block_len) { const size_t page_addr = furi_hal_flash_get_base() + furi_hal_flash_get_page_size() * i_page; - return (memcmp(update_block, (void*)page_addr, update_block_len) == 0); + return memcmp(update_block, (void*)page_addr, update_block_len) == 0; } /* Verifies a flash operation address for fitting into writable memory @@ -44,7 +44,7 @@ static bool page_task_compare_flash( static bool check_address_boundaries(const size_t address) { const size_t min_allowed_address = furi_hal_flash_get_base(); const size_t max_allowed_address = (size_t)furi_hal_flash_get_free_end_address(); - return ((address >= min_allowed_address) && (address < max_allowed_address)); + return (address >= min_allowed_address) && (address < max_allowed_address); } static bool update_task_flash_program_page( @@ -348,6 +348,8 @@ int32_t update_task_worker_flash_writer(void* context) { // Production furi_hal_rtc_set_log_level(FuriLogLevelDefault); furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug); + furi_hal_rtc_reset_flag(FuriHalRtcFlagLegacySleep); + furi_hal_rtc_set_heap_track_mode(FuriHalRtcHeapTrackModeNone); #endif update_task_set_progress(update_task, UpdateTaskStageCompleted, 100); success = true; diff --git a/assets/ReadMe.md b/assets/ReadMe.md index 50e25a8c908..7a117c0ea74 100644 --- a/assets/ReadMe.md +++ b/assets/ReadMe.md @@ -1,10 +1,5 @@ # Firmware Assets {#firmware_assets} -## Requirements - -- Python3 -- Python3 packages: Pillow & heatshrink2 - ## Compiling ```bash diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_0.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_0.png new file mode 100755 index 00000000000..b937cc08606 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_0.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_1.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_1.png new file mode 100755 index 00000000000..a3b494dda46 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_1.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_10.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_10.png new file mode 100755 index 00000000000..b8163164b23 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_10.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_11.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_11.png new file mode 100755 index 00000000000..e685ff86aa9 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_11.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_12.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_12.png new file mode 100755 index 00000000000..10a52400b0f Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_12.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_13.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_13.png new file mode 100755 index 00000000000..9cdea5002fb Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_13.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_14.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_14.png new file mode 100755 index 00000000000..590d0bf8914 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_14.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_15.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_15.png new file mode 100755 index 00000000000..97cf05dd07c Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_15.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_16.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_16.png new file mode 100755 index 00000000000..e2bae209f15 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_16.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_17.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_17.png new file mode 100755 index 00000000000..63db9fa0e24 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_17.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_18.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_18.png new file mode 100755 index 00000000000..ad66f34efc8 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_18.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_19.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_19.png new file mode 100755 index 00000000000..213fb76369b Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_19.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_2.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_2.png new file mode 100755 index 00000000000..81174f7fa82 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_2.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_20.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_20.png new file mode 100755 index 00000000000..7f4ce3bacc6 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_20.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_21.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_21.png new file mode 100755 index 00000000000..dc90311fedc Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_21.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_22.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_22.png new file mode 100755 index 00000000000..cda17cb6091 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_22.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_23.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_23.png new file mode 100755 index 00000000000..7a048dbaeed Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_23.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_24.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_24.png new file mode 100755 index 00000000000..c5a80a9255b Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_24.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_25.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_25.png new file mode 100755 index 00000000000..e80fdfb0050 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_25.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_26.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_26.png new file mode 100755 index 00000000000..b3955ac8a90 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_26.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_27.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_27.png new file mode 100755 index 00000000000..4b003d03490 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_27.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_28.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_28.png new file mode 100755 index 00000000000..df2008d932d Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_28.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_29.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_29.png new file mode 100755 index 00000000000..c0afacdfa2c Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_29.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_3.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_3.png new file mode 100755 index 00000000000..97c138235ce Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_3.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_30.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_30.png new file mode 100755 index 00000000000..6f693de4f3f Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_30.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_31.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_31.png new file mode 100755 index 00000000000..c971b217833 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_31.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_32.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_32.png new file mode 100755 index 00000000000..856c8455712 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_32.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_33.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_33.png new file mode 100755 index 00000000000..7e99a4a8206 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_33.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_34.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_34.png new file mode 100755 index 00000000000..949d845d45f Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_34.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_35.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_35.png new file mode 100755 index 00000000000..ee7be1409ae Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_35.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_36.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_36.png new file mode 100755 index 00000000000..ae6fca1cdc7 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_36.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_37.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_37.png new file mode 100755 index 00000000000..2567cf087dc Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_37.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_38.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_38.png new file mode 100755 index 00000000000..b3d0c7acfbb Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_38.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_39.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_39.png new file mode 100755 index 00000000000..dd98cfcbd87 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_39.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_4.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_4.png new file mode 100755 index 00000000000..0f81cd5dcdb Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_4.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_40.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_40.png new file mode 100755 index 00000000000..8e55dd9edf9 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_40.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_41.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_41.png new file mode 100755 index 00000000000..459f0c8e651 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_41.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_42.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_42.png new file mode 100755 index 00000000000..3c095599310 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_42.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_43.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_43.png new file mode 100755 index 00000000000..32d4eb4f1a2 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_43.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_44.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_44.png new file mode 100755 index 00000000000..11bd640ae9d Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_44.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_45.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_45.png new file mode 100755 index 00000000000..27af626e8aa Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_45.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_46.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_46.png new file mode 100755 index 00000000000..cfc81bd3f34 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_46.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_47.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_47.png new file mode 100755 index 00000000000..f9480b1e38c Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_47.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_48.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_48.png new file mode 100755 index 00000000000..6793a3df6e7 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_48.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_49.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_49.png new file mode 100755 index 00000000000..6b58a0fa782 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_49.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_5.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_5.png new file mode 100755 index 00000000000..cb62bb7b355 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_5.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_50.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_50.png new file mode 100755 index 00000000000..8b5ab6a9b6d Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_50.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_51.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_51.png new file mode 100755 index 00000000000..9a2c6b15091 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_51.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_52.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_52.png new file mode 100755 index 00000000000..f7da1b58759 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_52.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_53.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_53.png new file mode 100755 index 00000000000..d8e390bb59c Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_53.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_54.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_54.png new file mode 100755 index 00000000000..8dfe5defe07 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_54.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_55.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_55.png new file mode 100755 index 00000000000..fae299733cb Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_55.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_6.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_6.png new file mode 100755 index 00000000000..2d111a7a17b Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_6.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_7.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_7.png new file mode 100755 index 00000000000..4c8a9d2e5d6 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_7.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_8.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_8.png new file mode 100755 index 00000000000..aa0d1e6a77a Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_8.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/frame_9.png b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_9.png new file mode 100755 index 00000000000..9f2d03b7ef7 Binary files /dev/null and b/assets/dolphin/external/L3_Intruder_alert_128x64/frame_9.png differ diff --git a/assets/dolphin/external/L3_Intruder_alert_128x64/meta.txt b/assets/dolphin/external/L3_Intruder_alert_128x64/meta.txt new file mode 100755 index 00000000000..435b2da4a5f --- /dev/null +++ b/assets/dolphin/external/L3_Intruder_alert_128x64/meta.txt @@ -0,0 +1,14 @@ +Filetype: Flipper Animation +Version: 1 + +Width: 128 +Height: 64 +Passive frames: 14 +Active frames: 42 +Frames order: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 +Active cycles: 1 +Frame rate: 2 +Duration: 3600 +Active cooldown: 7 + +Bubble slots: 0 \ No newline at end of file diff --git a/assets/dolphin/external/manifest.txt b/assets/dolphin/external/manifest.txt index 42e18ad3f23..5ab996f5918 100644 --- a/assets/dolphin/external/manifest.txt +++ b/assets/dolphin/external/manifest.txt @@ -188,11 +188,18 @@ Min butthurt: 0 Max butthurt: 12 Min level: 3 Max level: 3 -Weight: 5 +Weight: 4 Name: L1_Akira_128x64 Min butthurt: 0 Max butthurt: 8 Min level: 1 Max level: 3 -Weight: 5 +Weight: 4 + +Name: L3_Intruder_alert_128x64 +Min butthurt: 0 +Max butthurt: 12 +Min level: 3 +Max level: 3 +Weight: 6 diff --git a/documentation/OTA.md b/documentation/OTA.md index 9028eff714b..0456eab1f91 100644 --- a/documentation/OTA.md +++ b/documentation/OTA.md @@ -102,7 +102,7 @@ Even if something goes wrong, updater allows you to retry failed operations and | Writing flash | **10** | **0-100** | Block read/write error | | Validating flash | **11** | **0-100** | Block read/write error | | Restoring LFS | **12** | **0-100** | FS read/write error | -| Updating resources | **13** | **0-100** | SD card read/write error | +| Updating resources | **13-15** | **0-100** | SD card read/write error | ## Building update packages diff --git a/documentation/doxygen/js.dox b/documentation/doxygen/js.dox index 1c81a083503..f4faf668fea 100644 --- a/documentation/doxygen/js.dox +++ b/documentation/doxygen/js.dox @@ -12,7 +12,10 @@ JS modules use the Flipper app plugin system. Each module is compiled into a .fa - @subpage js_badusb - BadUSB module - @subpage js_serial - Serial module +- @subpage js_math - Math module - @subpage js_dialog - Dialog module +- @subpage js_submenu - Submenu module +- @subpage js_textbox - Textbox module - @subpage js_notification - Notifications module */ diff --git a/documentation/file_formats/TarHeatshrinkFormat.md b/documentation/file_formats/TarHeatshrinkFormat.md new file mode 100644 index 00000000000..86c27a698eb --- /dev/null +++ b/documentation/file_formats/TarHeatshrinkFormat.md @@ -0,0 +1,19 @@ +# Heatshrink-compressed Tarball Format + +Flipper supports the use of Heatshrink compression library for .tar archives. This allows for smaller file sizes and faster OTA updates. + +Heatshrink specification does not define a container format for storing compression parameters. This document describes the format used by Flipper to store Heatshrink-compressed data streams. + +## Header + +Header begins with a magic value, followed by a version number and compression parameters - window size and lookahead size. + +Magic value consists of 4 bytes: `0x48 0x53 0x44 0x53` (ASCII "HSDS", HeatShrink DataStream). + +Version number is a single byte, currently set to `0x01`. + +Window size is a single byte, representing the size of the sliding window used by the compressor. It corresponds to `-w` parameter in Heatshrink CLI. + +Lookahead size is a single byte, representing the size of the lookahead buffer used by the compressor. It corresponds to `-l` parameter in Heatshrink CLI. + +Total header size is 7 bytes. Header is followed by compressed data. diff --git a/documentation/js/js_badusb.md b/documentation/js/js_badusb.md index 28372e56a44..78c49104ca5 100644 --- a/documentation/js/js_badusb.md +++ b/documentation/js/js_badusb.md @@ -111,10 +111,10 @@ badusb.println("Hello, world!"); // print "Hello, world!" and press "ENTER" | Name | | ------------- | -| CTRL | -| SHIFT | +| CTRL | +| SHIFT | | ALT | -| GUI | +| GUI | ## Special keys diff --git a/documentation/js/js_dialog.md b/documentation/js/js_dialog.md index 5804b075eb4..eb027e6a738 100644 --- a/documentation/js/js_dialog.md +++ b/documentation/js/js_dialog.md @@ -13,7 +13,7 @@ Show a simple message dialog with header, text and "OK" button. - Dialog header text - Dialog text -### Retuns +### Returns true if central button was pressed, false if the dialog was closed by back key press ### Examples: @@ -25,14 +25,14 @@ dialog.message("Dialog demo", "Press OK to start"); More complex dialog with configurable buttons ### Parameters -Configuration object with the following fileds: +Configuration object with the following fields: - header: Dialog header text - text: Dialog text - button_left: (optional) left button name - button_right: (optional) right button name - button_center: (optional) central button name -### Retuns +### Returns Name of pressed button or empty string if the dialog was closed by back key press ### Examples: diff --git a/documentation/js/js_math.md b/documentation/js/js_math.md new file mode 100644 index 00000000000..296f01c62db --- /dev/null +++ b/documentation/js/js_math.md @@ -0,0 +1,362 @@ +# js_math {#js_math} + +# Math module +```js +let math = require("math"); +``` +# Constants + +## PI +The number π = 3.14159265358979323846264338327950288. + +## E +The number e (Euler's number) = 2.71828182845904523536028747135266250. + +## EPSILON +The smallest number that satisfies the condition: 1.0 + EPSILON != 1.0. +EPSILON = 2.2204460492503131e-16. + +# Methods + +## abs +Return the absolute value of a number. + +### Parameters +- x: A number + +### Returns +The absolute value of `x`. If `x` is negative (including -0), returns `-x`. Otherwise, returns `x`. The result is therefore always a positive number or 0. + +### Example +```js +math.abs(-5); // 5 +``` + +## acos +Return the inverse cosine (in radians) of a number. + +### Parameters +- x: A number between -1 and 1, inclusive, representing the angle's cosine value + +### Returns +The inverse cosine (angle in radians between 0 and π, inclusive) of `x`. If `x` is less than -1 or greater than 1, returns `NaN`. + +### Example +```js +math.acos(-1); // 3.141592653589793 +``` + +## acosh +Return the inverse hyperbolic cosine of a number. + +### Parameters +- x: A number greater than or equal to 1 + +### Returns +The inverse hyperbolic cosine of `x`. + +### Example +```js +math.acosh(1); // 0 +``` + +## asin +Return the inverse sine (in radians) of a number. + +### Parameters +- x: A number between -1 and 1, inclusive, representing the angle's sine value + +### Returns +The inverse sine (angle in radians between -𝜋/2 and 𝜋/2, inclusive) of `x`. + +### Example +```js +math.asin(0.5); // 0.5235987755982989 +``` + +## asinh +Return the inverse hyperbolic sine of a number. + +### Parameters +- x: A number + +### Returns +The inverse hyperbolic sine of `x`. + +### Example +```js +math.asinh(1); // 0.881373587019543 +``` + +## atan +Return the inverse tangent (in radians) of a number. + +### Parameters +- x: A number + +### Returns +The inverse tangent (angle in radians between -𝜋/2 and 𝜋/2, inclusive) of `x`. + +### Example +```js +math.atan(1); // 0.7853981633974483 +``` + +## atan2 +Return the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for math.atan2(y, x). + +### Parameters +- y: The y coordinate of the point +- x: The x coordinate of the point + +### Returns +The angle in radians (between -π and π, inclusive) between the positive x-axis and the ray from (0, 0) to the point (x, y). + +### Example +```js +math.atan2(90, 15); // 1.4056476493802699 +``` + +## atanh +The method returns the inverse hyperbolic tangent of a number. + +### Parameters +- x: A number between -1 and 1, inclusive + +### Returns +The inverse hyperbolic tangent of `x`. + +### Example +```js +math.atanh(0.5); // 0.5493061443340548 +``` + +## cbrt +Return the cube root of a number. + +### Parameters +- x: A number + +### Returns +The cube root of `x`. + +### Example +```js +math.cbrt(2); // 1.2599210498948732 +``` + +## ceil +Round up and return the smallest integer greater than or equal to a given number. + +### Parameters +- x: A number + +### Returns +The smallest integer greater than or equal to `x`. It's the same value as `-math.floor(-x)`. + +### Example +```js +math.ceil(-7.004); // -7 +math.ceil(7.004); // 8 +``` + +## clz32 +Return the number of leading zero bits in the 32-bit binary representation of a number. + +### Parameters +- x: A number + +### Returns +The number of leading zero bits in the 32-bit binary representation of `x`. + +### Example +```js +math.clz32(1); // 31 +math.clz32(1000); // 22 +``` + +## cos +Return the cosine of a number in radians. + +### Parameters +- x: A number representing an angle in radians + +### Returns +The cosine of `x`, between -1 and 1, inclusive. + +### Example +```js +math.cos(math.PI); // -1 +``` + +## exp +Return e raised to the power of a number. + +### Parameters +- x: A number + +### Returns +A nonnegative number representing `e^x`, where `e` is the base of the natural logarithm. + +### Example +```js +math.exp(0); // 1 +math.exp(1); // 2.718281828459045 +``` + +## floor +Round down and return the largest integer less than or equal to a given number. + +### Parameters +- x: A number + +### Returns +The largest integer smaller than or equal to `x`. It's the same value as `-math.ceil(-x)`. + +### Example +```js +math.floor(-45.95); // -46 +math.floor(-45.05); // -46 +math.floor(-0); // -0 +math.floor(0); // 0 +math.floor(45.05); // 45 +math.floor(45.95); // 45 +``` + +## is_equal +Return true if the difference between numbers `a` and `b` is less than the specified parameter `e`. + +### Parameters +- a: A number a +- b: A number b +- e: An epsilon parameter + +### Returns +True if the difference between numbers `a` and `b` is less than the specified parameter `e`. Otherwise, false. + +### Example +```js +math.is_equal(1.4, 1.6, 0.2); // false +math.is_equal(3.556, 3.555, 0.01); // true +``` + +## max +Return the largest of two numbers given as input parameters. + +### Parameters +- a: A number a +- b: A number b + +### Returns +The largest of the given numbers. + +### Example +```js +math.max(10, 20); // 20 +math.max(-10, -20); // -10 +``` + +## min +Return the smallest of two numbers given as input parameters. + +### Parameters +- a: A number a +- b: A number b + +### Returns +The smallest of the given numbers. + +### Example +```js +math.min(10, 20); // 10 +math.min(-10, -20); // -20 +``` + +## pow +Return the value of a base raised to a power. + +### Parameters +- base: The base number +- exponent: The exponent number + +### Returns +A number representing base taken to the power of exponent. + +### Example +```js +math.pow(7, 2); // 49 +math.pow(7, 3); // 343 +math.pow(2, 10); // 1024 +``` + +## random +Return a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range - which you can then scale to your desired range. + +### Returns +A floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). + +### Example +```js +let num = math.random(); +``` + +## sign +Return 1 or -1, indicating the sign of the number passed as argument. + +### Parameters +- x: A number + +### Returns +-1 if the number is less than 0, and 1 otherwise. + +### Example +```js +math.sign(3); // 1 +math.sign(0); // 1 +math.sign(-3); // -1 +``` + +## sin +Return the sine of a number in radians. + +### Parameters +- x: A number representing an angle in radians + +### Returns +The sine of `x`, between -1 and 1, inclusive. + +### Example +```js +math.sin(math.PI / 2); // 1 +``` + +## sqrt +Return the square root of a number. + +### Parameters +- x: A number greater than or equal to 0 + +### Returns +The square root of `x`, a nonnegative number. If `x` < 0, script will fail with an error. + +### Example +```js +math.sqrt(25); // 5 +``` + +## trunc +Return the integer part of a number by removing any fractional digits. + +### Parameters +- x: A number + +### Returns +The integer part of `x`. + +### Example +```js +math.trunc(-1.123); // -1 +math.trunc(0.123); // 0 +math.trunc(13.37); // 13 +math.trunc(42.84); // 42 +``` diff --git a/documentation/js/js_serial.md b/documentation/js/js_serial.md index cd9993a1810..9d7938044d0 100644 --- a/documentation/js/js_serial.md +++ b/documentation/js/js_serial.md @@ -53,7 +53,7 @@ serial.read(10, 5000); // Read 10 bytes, with 5s timeout ``` ## readln -Read from serial port untill line break character +Read from serial port until line break character ### Parameters (optional) Timeout value in ms @@ -68,7 +68,7 @@ serial.readln(5000); // Read with 5s timeout ``` ## readBytes -Read from serial port untill line break character +Read from serial port until line break character ### Parameters - Number of bytes to read @@ -81,7 +81,7 @@ ArrayBuffer with received data or undefined if nothing was received before timeo ```js serial.readBytes(4); // Read 4 bytes, without timeout -// Read one byte from receive buffer with zero timeout, returns UNDEFINED if Rx bufer is empty +// Read one byte from receive buffer with zero timeout, returns UNDEFINED if Rx buffer is empty serial.readBytes(1, 0); ``` diff --git a/documentation/js/js_submenu.md b/documentation/js/js_submenu.md new file mode 100644 index 00000000000..580a43bd5cc --- /dev/null +++ b/documentation/js/js_submenu.md @@ -0,0 +1,48 @@ +# js_submenu {#js_submenu} + +# Submenu module +```js +let submenu = require("submenu"); +``` +# Methods + +## setHeader +Set the submenu header text. + +### Parameters +- header (string): The submenu header text + +### Example +```js +submenu.setHeader("Select an option:"); +``` + +## addItem +Add a new submenu item. + +### Parameters +- label (string): The submenu item label text +- id (number): The submenu item ID, must be a Uint32 number + +### Example +```js +submenu.addItem("Option 1", 1); +submenu.addItem("Option 2", 2); +submenu.addItem("Option 3", 3); +``` + +## show +Show a submenu that was previously configured using `setHeader()` and `addItem()` methods. + +### Returns +The ID of the submenu item that was selected, or `undefined` if the BACK button was pressed. + +### Example +```js +let selected = submenu.show(); +if (selected === undefined) { + // if BACK button was pressed +} else if (selected === 1) { + // if item with ID 1 was selected +} +``` diff --git a/documentation/js/js_textbox.md b/documentation/js/js_textbox.md new file mode 100644 index 00000000000..61652df1a6e --- /dev/null +++ b/documentation/js/js_textbox.md @@ -0,0 +1,69 @@ +# js_textbox {#js_textbox} + +# Textbox module +```js +let textbox = require("textbox"); +``` +# Methods + +## setConfig +Set focus and font for the textbox. + +### Parameters +- focus: "start" to focus on the beginning of the text, or "end" to focus on the end of the text +- font: "text" to use the default proportional font, or "hex" to use a monospaced font, which is convenient for aligned array output in HEX + +### Example +```js +textbox.setConfig("start", "text"); +textbox.addText("Hello world"); +textbox.show(); +``` + +## addText +Add text to the end of the textbox. + +### Parameters +- text (string): The text to add to the end of the textbox + +### Example +```js +textbox.addText("New text 1\nNew text 2"); +``` + +## clearText +Clear the textbox. + +### Example +```js +textbox.clearText(); +``` + +## isOpen +Return true if the textbox is open. + +### Returns +True if the textbox is open, false otherwise. + +### Example +```js +let isOpen = textbox.isOpen(); +``` + +## show +Show the textbox. You can add text to it using the `addText()` method before or after calling the `show()` method. + +### Example +```js +textbox.show(); +``` + +## close +Close the textbox. + +### Example +```js +if (textbox.isOpen()) { + textbox.close(); +} +``` diff --git a/fbt_options.py b/fbt_options.py index c4b84105816..e30f7fc2d9b 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -22,7 +22,7 @@ COPRO_OB_DATA = "scripts/ob.data" # Must match lib/stm32wb_copro version -COPRO_CUBE_VERSION = "1.19.0" +COPRO_CUBE_VERSION = "1.20.0" COPRO_CUBE_DIR = "lib/stm32wb_copro" diff --git a/furi/core/base.h b/furi/core/base.h index 92a52a7978b..e89065a7d58 100644 --- a/furi/core/base.h +++ b/furi/core/base.h @@ -40,6 +40,12 @@ typedef enum { FuriStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. } FuriStatus; +typedef enum { + FuriSignalExit, /**< Request (graceful) exit. */ + // Other standard signals may be added in the future + FuriSignalCustom = 100, /**< Custom signal values start from here. */ +} FuriSignal; + #ifdef __cplusplus } #endif diff --git a/furi/core/check.h b/furi/core/check.h index a51d7b41eae..a2b7dd18e4b 100644 --- a/furi/core/check.h +++ b/furi/core/check.h @@ -22,7 +22,7 @@ extern "C" { // Flags instead of pointers will save ~4 bytes on furi_assert and furi_check calls. #define __FURI_ASSERT_MESSAGE_FLAG (0x01) -#define __FURI_CHECK_MESSAGE_FLAG (0x02) +#define __FURI_CHECK_MESSAGE_FLAG (0x02) /** Crash system */ FURI_NORETURN void __furi_crash_implementation(void); diff --git a/furi/core/common_defines.h b/furi/core/common_defines.h index 0f6230c19f1..20883332b02 100644 --- a/furi/core/common_defines.h +++ b/furi/core/common_defines.h @@ -29,8 +29,8 @@ extern "C" { #define FURI_PACKED __attribute__((packed)) #endif -#ifndef FURI_ALWAYS_STATIC_INLINE -#define FURI_ALWAYS_STATIC_INLINE __attribute__((always_inline)) static inline +#ifndef FURI_ALWAYS_INLINE +#define FURI_ALWAYS_INLINE __attribute__((always_inline)) inline #endif #ifndef FURI_IS_IRQ_MASKED diff --git a/furi/core/core_defines.h b/furi/core/core_defines.h index 732a90cb526..fa56150ce15 100644 --- a/furi/core/core_defines.h +++ b/furi/core/core_defines.h @@ -79,7 +79,7 @@ extern "C" { #endif #ifndef CONCATENATE -#define CONCATENATE(a, b) CONCATENATE_(a, b) +#define CONCATENATE(a, b) CONCATENATE_(a, b) #define CONCATENATE_(a, b) a##b #endif diff --git a/furi/core/critical.c b/furi/core/critical.c index 3bef2be38e0..32797ee0009 100644 --- a/furi/core/critical.c +++ b/furi/core/critical.c @@ -29,4 +29,4 @@ void __furi_critical_exit(__FuriCriticalInfo info) { } else { __enable_irq(); } -} \ No newline at end of file +} diff --git a/furi/core/event_flag.c b/furi/core/event_flag.c index c2e04e2fda8..f89c4e77ff6 100644 --- a/furi/core/event_flag.c +++ b/furi/core/event_flag.c @@ -6,7 +6,7 @@ #include #define FURI_EVENT_FLAG_MAX_BITS_EVENT_GROUPS 24U -#define FURI_EVENT_FLAG_INVALID_BITS (~((1UL << FURI_EVENT_FLAG_MAX_BITS_EVENT_GROUPS) - 1U)) +#define FURI_EVENT_FLAG_INVALID_BITS (~((1UL << FURI_EVENT_FLAG_MAX_BITS_EVENT_GROUPS) - 1U)) struct FuriEventFlag { StaticEventGroup_t container; diff --git a/furi/core/event_loop.c b/furi/core/event_loop.c index b939695dde4..26401c84b2c 100644 --- a/furi/core/event_loop.c +++ b/furi/core/event_loop.c @@ -5,32 +5,14 @@ #include "check.h" #include "thread.h" -#include -#include - #include #include #define TAG "FuriEventLoop" -struct FuriEventLoopItem { - // Source - FuriEventLoop* owner; - - // Tracking item - const FuriEventLoopContract* contract; - void* object; - FuriEventLoopEvent event; - - // Callback and context - FuriEventLoopMessageQueueCallback callback; - void* callback_context; - - // Waiting list - ILIST_INTERFACE(WaitingList, struct FuriEventLoopItem); -}; - -ILIST_DEF(WaitingList, FuriEventLoopItem, M_POD_OPLIST) +/* + * Private functions + */ static FuriEventLoopItem* furi_event_loop_item_alloc( FuriEventLoop* owner, @@ -47,56 +29,17 @@ static void furi_event_loop_item_set_callback( static void furi_event_loop_item_notify(FuriEventLoopItem* instance); -/* Event Loop RB tree */ -#define FURI_EVENT_LOOP_TREE_RANK (4) - -BPTREE_DEF2( // NOLINT - FuriEventLoopTree, - FURI_EVENT_LOOP_TREE_RANK, - void*, /* pointer to object we track */ - M_PTR_OPLIST, - FuriEventLoopItem*, /* pointer to the FuriEventLoopItem */ - M_PTR_OPLIST) - -#define M_OPL_FuriEventLoopTree_t() BPTREE_OPLIST(FuriEventLoopTree, M_POD_OPLIST) - -#define FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX (2) - -typedef enum { - FuriEventLoopFlagEvent = (1 << 0), - FuriEventLoopFlagStop = (1 << 1), -} FuriEventLoopFlag; - -#define FuriEventLoopFlagAll (FuriEventLoopFlagEvent | FuriEventLoopFlagStop) - -typedef enum { - FuriEventLoopProcessStatusComplete, - FuriEventLoopProcessStatusIncomplete, - FuriEventLoopProcessStatusAgain, -} FuriEventLoopProcessStatus; - -typedef enum { - FuriEventLoopStateIdle, - FuriEventLoopStateProcessing, -} FuriEventLoopState; - -struct FuriEventLoop { - // Only works if all operations are done from the same thread - FuriThreadId thread_id; - - // Poller state - volatile FuriEventLoopState state; - - // Tree - FuriEventLoopTree_t tree; - // Tree waiting list - WaitingList_t waiting_list; +static void furi_event_loop_process_pending_callbacks(FuriEventLoop* instance) { + for(; !PendingQueue_empty_p(instance->pending_queue); + PendingQueue_pop_back(NULL, instance->pending_queue)) { + const FuriEventLoopPendingQueueItem* item = PendingQueue_back(instance->pending_queue); + item->callback(item->context); + } +} - // Tick event - uint32_t tick_interval; - FuriEventLoopTickCallback tick_callback; - void* tick_callback_context; -}; +/* + * Main public API + */ FuriEventLoop* furi_event_loop_alloc(void) { FuriEventLoop* instance = malloc(sizeof(FuriEventLoop)); @@ -105,6 +48,9 @@ FuriEventLoop* furi_event_loop_alloc(void) { FuriEventLoopTree_init(instance->tree); WaitingList_init(instance->waiting_list); + TimerList_init(instance->timer_list); + TimerQueue_init(instance->timer_queue); + PendingQueue_init(instance->pending_queue); // Clear notification state and value xTaskNotifyStateClearIndexed(instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX); @@ -117,14 +63,19 @@ FuriEventLoop* furi_event_loop_alloc(void) { void furi_event_loop_free(FuriEventLoop* instance) { furi_check(instance); furi_check(instance->thread_id == furi_thread_get_current_id()); + furi_check(instance->state == FuriEventLoopStateStopped); + + furi_event_loop_process_timer_queue(instance); + furi_check(TimerList_empty_p(instance->timer_list)); FuriEventLoopTree_clear(instance->tree); + PendingQueue_clear(instance->pending_queue); uint32_t flags = 0; BaseType_t ret = xTaskNotifyWaitIndexed( FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, 0, FuriEventLoopFlagAll, &flags, 0); if(ret == pdTRUE) { - FURI_LOG_D(TAG, "Some events was not processed: 0x%lx", flags); + FURI_LOG_D(TAG, "Some events were not processed: 0x%lx", flags); } free(instance); @@ -145,30 +96,51 @@ static FuriEventLoopProcessStatus } } +static void furi_event_loop_restore_flags(FuriEventLoop* instance, uint32_t flags) { + if(flags) { + xTaskNotifyIndexed( + instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, flags, eSetBits); + } +} + void furi_event_loop_run(FuriEventLoop* instance) { furi_check(instance); furi_check(instance->thread_id == furi_thread_get_current_id()); - uint32_t timeout = instance->tick_callback ? instance->tick_interval : FuriWaitForever; + furi_event_loop_init_tick(instance); + + furi_thread_set_signal_callback( + instance->thread_id, furi_event_loop_signal_callback, instance); while(true) { + instance->state = FuriEventLoopStateIdle; + + const TickType_t ticks_to_sleep = + MIN(furi_event_loop_get_timer_wait_time(instance), + furi_event_loop_get_tick_wait_time(instance)); + uint32_t flags = 0; BaseType_t ret = xTaskNotifyWaitIndexed( - FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, 0, FuriEventLoopFlagAll, &flags, timeout); + FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, 0, FuriEventLoopFlagAll, &flags, ticks_to_sleep); instance->state = FuriEventLoopStateProcessing; + if(ret == pdTRUE) { if(flags & FuriEventLoopFlagStop) { - instance->state = FuriEventLoopStateIdle; + instance->state = FuriEventLoopStateStopped; break; + } else if(flags & FuriEventLoopFlagEvent) { FuriEventLoopItem* item = NULL; FURI_CRITICAL_ENTER(); + if(!WaitingList_empty_p(instance->waiting_list)) { item = WaitingList_pop_front(instance->waiting_list); WaitingList_init_field(item); } + FURI_CRITICAL_EXIT(); + if(item) { while(true) { FuriEventLoopProcessStatus ret = @@ -186,38 +158,62 @@ void furi_event_loop_run(FuriEventLoop* instance) { } } } + + furi_event_loop_restore_flags(instance, flags & ~FuriEventLoopFlagEvent); + + } else if(flags & FuriEventLoopFlagTimer) { + furi_event_loop_process_timer_queue(instance); + furi_event_loop_restore_flags(instance, flags & ~FuriEventLoopFlagTimer); + + } else if(flags & FuriEventLoopFlagPending) { + furi_event_loop_process_pending_callbacks(instance); + + } else { + furi_crash(); } - } else { - if(instance->tick_callback) { - instance->tick_callback(instance->tick_callback_context); - } + + } else if(!furi_event_loop_process_expired_timers(instance)) { + furi_event_loop_process_tick(instance); } - instance->state = FuriEventLoopStateIdle; } + + furi_thread_set_signal_callback(instance->thread_id, NULL, NULL); } void furi_event_loop_stop(FuriEventLoop* instance) { furi_check(instance); - furi_check(instance->thread_id == furi_thread_get_current_id()); xTaskNotifyIndexed( instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, FuriEventLoopFlagStop, eSetBits); } -void furi_event_loop_tick_set( +/* + * Public deferred function call API + */ + +void furi_event_loop_pend_callback( FuriEventLoop* instance, - uint32_t interval, - FuriEventLoopTickCallback callback, + FuriEventLoopPendingCallback callback, void* context) { furi_check(instance); furi_check(instance->thread_id == furi_thread_get_current_id()); - furi_check(callback ? interval > 0 : true); + furi_check(callback); - instance->tick_interval = interval; - instance->tick_callback = callback; - instance->tick_callback_context = context; + const FuriEventLoopPendingQueueItem item = { + .callback = callback, + .context = context, + }; + + PendingQueue_push_front(instance->pending_queue, item); + + xTaskNotifyIndexed( + instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, FuriEventLoopFlagPending, eSetBits); } +/* + * Message queue API + */ + void furi_event_loop_message_queue_subscribe( FuriEventLoop* instance, FuriMessageQueue* message_queue, @@ -226,7 +222,7 @@ void furi_event_loop_message_queue_subscribe( void* context) { furi_check(instance); furi_check(instance->thread_id == furi_thread_get_current_id()); - furi_check(instance->state == FuriEventLoopStateIdle); + furi_check(instance->state == FuriEventLoopStateStopped); furi_check(message_queue); FURI_CRITICAL_ENTER(); @@ -263,7 +259,7 @@ void furi_event_loop_message_queue_unsubscribe( FuriEventLoop* instance, FuriMessageQueue* message_queue) { furi_check(instance); - furi_check(instance->state == FuriEventLoopStateIdle); + furi_check(instance->state == FuriEventLoopStateStopped); furi_check(instance->thread_id == furi_thread_get_current_id()); FURI_CRITICAL_ENTER(); @@ -366,4 +362,19 @@ void furi_event_loop_link_notify(FuriEventLoopLink* instance, FuriEventLoopEvent } FURI_CRITICAL_EXIT(); -} \ No newline at end of file +} + +bool furi_event_loop_signal_callback(uint32_t signal, void* arg, void* context) { + furi_assert(context); + FuriEventLoop* instance = context; + UNUSED(arg); + + switch(signal) { + case FuriSignalExit: + furi_event_loop_stop(instance); + return true; + // Room for possible other standard signal handlers + default: + return false; + } +} diff --git a/furi/core/event_loop.h b/furi/core/event_loop.h index 7221a90bca9..9ae9f6c4dda 100644 --- a/furi/core/event_loop.h +++ b/furi/core/event_loop.h @@ -34,7 +34,7 @@ typedef struct FuriEventLoop FuriEventLoop; * Couple things to keep in mind: * - You can have 1 event_loop per 1 thread * - You can not use event_loop instance in the other thread - * - Do not use blocking api to query object delegated to Event Loop + * - Do not use blocking API to query object delegated to Event Loop * * @return The Event Loop instance */ @@ -72,8 +72,10 @@ typedef void (*FuriEventLoopTickCallback)(void* context); /** Set Event Loop tick callback * - * Tick callback called after specified inactivity time. It's not periodic. If - * Event Loop is busy then ticks will be skipped. + * Tick callback is called periodically after specified inactivity time. + * It acts like a low-priority timer: it will only fire if there is time + * left after processing the synchronization primitives and the regular timers. + * Therefore, it is not monotonic: ticks will be skipped if the event loop is busy. * * @param instance The Event Loop instance * @param[in] interval The tick interval @@ -86,6 +88,32 @@ void furi_event_loop_tick_set( FuriEventLoopTickCallback callback, void* context); +/* + * Deferred function call API + */ + +/** + * @brief Timer callback type for functions to be called in a deferred manner. + * + * @param[in,out] context pointer to a user-specific object that was provided during + * furi_event_loop_pend_callback() call + */ +typedef void (*FuriEventLoopPendingCallback)(void* context); + +/** + * @brief Call a function when all preceding timer commands are processed + * + * This function may be useful to call another function when the event loop has been started. + * + * @param[in,out] instance pointer to the current FuriEventLoop instance + * @param[in] callback pointer to the callback to be executed when previous commands have been processed + * @param[in,out] context pointer to a user-specific object (will be passed to the callback) + */ +void furi_event_loop_pend_callback( + FuriEventLoop* instance, + FuriEventLoopPendingCallback callback, + void* context); + /* * Message queue related APIs */ diff --git a/furi/core/event_loop_i.h b/furi/core/event_loop_i.h index 8ddd10966f9..cd10148673d 100644 --- a/furi/core/event_loop_i.h +++ b/furi/core/event_loop_i.h @@ -1,33 +1,97 @@ #pragma once #include "event_loop.h" +#include "event_loop_link_i.h" +#include "event_loop_timer_i.h" +#include "event_loop_tick_i.h" -#ifdef __cplusplus -extern "C" { -#endif +#include +#include +#include -typedef struct FuriEventLoopItem FuriEventLoopItem; +#include "thread.h" -/* Link between Event Loop */ +struct FuriEventLoopItem { + // Source + FuriEventLoop* owner; -typedef struct { - FuriEventLoopItem* item_in; - FuriEventLoopItem* item_out; -} FuriEventLoopLink; + // Tracking item + const FuriEventLoopContract* contract; + void* object; + FuriEventLoopEvent event; + + // Callback and context + FuriEventLoopMessageQueueCallback callback; + void* callback_context; + + // Waiting list + ILIST_INTERFACE(WaitingList, struct FuriEventLoopItem); +}; + +ILIST_DEF(WaitingList, FuriEventLoopItem, M_POD_OPLIST) + +/* Event Loop RB tree */ +#define FURI_EVENT_LOOP_TREE_RANK (4) + +BPTREE_DEF2( // NOLINT + FuriEventLoopTree, + FURI_EVENT_LOOP_TREE_RANK, + void*, /* pointer to object we track */ + M_PTR_OPLIST, + FuriEventLoopItem*, /* pointer to the FuriEventLoopItem */ + M_PTR_OPLIST) -void furi_event_loop_link_notify(FuriEventLoopLink* instance, FuriEventLoopEvent event); +#define M_OPL_FuriEventLoopTree_t() BPTREE_OPLIST(FuriEventLoopTree, M_POD_OPLIST) -/* Contract between event loop and an object */ +#define FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX (2) -typedef FuriEventLoopLink* (*FuriEventLoopContractGetLink)(void* object); +typedef enum { + FuriEventLoopFlagEvent = (1 << 0), + FuriEventLoopFlagStop = (1 << 1), + FuriEventLoopFlagTimer = (1 << 2), + FuriEventLoopFlagPending = (1 << 3), +} FuriEventLoopFlag; -typedef uint32_t (*FuriEventLoopContractGetLevel)(void* object, FuriEventLoopEvent event); +#define FuriEventLoopFlagAll \ + (FuriEventLoopFlagEvent | FuriEventLoopFlagStop | FuriEventLoopFlagTimer | \ + FuriEventLoopFlagPending) + +typedef enum { + FuriEventLoopProcessStatusComplete, + FuriEventLoopProcessStatusIncomplete, + FuriEventLoopProcessStatusAgain, +} FuriEventLoopProcessStatus; + +typedef enum { + FuriEventLoopStateStopped, + FuriEventLoopStateIdle, + FuriEventLoopStateProcessing, +} FuriEventLoopState; typedef struct { - const FuriEventLoopContractGetLink get_link; - const FuriEventLoopContractGetLevel get_level; -} FuriEventLoopContract; + FuriEventLoopPendingCallback callback; + void* context; +} FuriEventLoopPendingQueueItem; + +LIST_DUAL_PUSH_DEF(PendingQueue, FuriEventLoopPendingQueueItem, M_POD_OPLIST) + +struct FuriEventLoop { + // Only works if all operations are done from the same thread + FuriThreadId thread_id; + + // Poller state + volatile FuriEventLoopState state; + + // Event handling + FuriEventLoopTree_t tree; + WaitingList_t waiting_list; -#ifdef __cplusplus -} -#endif + // Active timer list + TimerList_t timer_list; + // Timer request queue + TimerQueue_t timer_queue; + // Pending callback queue + PendingQueue_t pending_queue; + // Tick event + FuriEventLoopTick tick; +}; diff --git a/furi/core/event_loop_link_i.h b/furi/core/event_loop_link_i.h new file mode 100644 index 00000000000..5c0b144a1bc --- /dev/null +++ b/furi/core/event_loop_link_i.h @@ -0,0 +1,35 @@ +#pragma once + +#include "event_loop.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct FuriEventLoopItem FuriEventLoopItem; + +/* Link between Event Loop */ + +typedef struct { + FuriEventLoopItem* item_in; + FuriEventLoopItem* item_out; +} FuriEventLoopLink; + +void furi_event_loop_link_notify(FuriEventLoopLink* instance, FuriEventLoopEvent event); + +/* Contract between event loop and an object */ + +typedef FuriEventLoopLink* (*FuriEventLoopContractGetLink)(void* object); + +typedef uint32_t (*FuriEventLoopContractGetLevel)(void* object, FuriEventLoopEvent event); + +typedef struct { + const FuriEventLoopContractGetLink get_link; + const FuriEventLoopContractGetLevel get_level; +} FuriEventLoopContract; + +bool furi_event_loop_signal_callback(uint32_t signal, void* arg, void* context); + +#ifdef __cplusplus +} +#endif diff --git a/furi/core/event_loop_tick.c b/furi/core/event_loop_tick.c new file mode 100644 index 00000000000..b81c4893305 --- /dev/null +++ b/furi/core/event_loop_tick.c @@ -0,0 +1,69 @@ +#include "event_loop_i.h" + +#include +#include + +#include + +/** + * Private functions + */ + +static inline uint32_t furi_event_loop_tick_get_elapsed_time(const FuriEventLoop* instance) { + return xTaskGetTickCount() - instance->tick.prev_time; +} + +static inline uint32_t furi_event_loop_tick_get_remaining_time(const FuriEventLoop* instance) { + const uint32_t elapsed_time = furi_event_loop_tick_get_elapsed_time(instance); + return elapsed_time < instance->tick.interval ? instance->tick.interval - elapsed_time : 0; +} + +static inline bool furi_event_loop_tick_is_expired(const FuriEventLoop* instance) { + return furi_event_loop_tick_get_elapsed_time(instance) >= instance->tick.interval; +} + +/* + * Private tick API + */ + +void furi_event_loop_init_tick(FuriEventLoop* instance) { + if(instance->tick.callback) { + instance->tick.prev_time = xTaskGetTickCount(); + } +} + +void furi_event_loop_process_tick(FuriEventLoop* instance) { + if(instance->tick.callback && furi_event_loop_tick_is_expired(instance)) { + instance->tick.prev_time += instance->tick.interval; + instance->tick.callback(instance->tick.callback_context); + } +} + +uint32_t furi_event_loop_get_tick_wait_time(const FuriEventLoop* instance) { + uint32_t wait_time = FuriWaitForever; + + if(instance->tick.callback) { + wait_time = furi_event_loop_tick_get_remaining_time(instance); + } + + return wait_time; +} + +/* + * Public tick API + */ + +void furi_event_loop_tick_set( + FuriEventLoop* instance, + uint32_t interval, + FuriEventLoopTickCallback callback, + void* context) { + furi_check(instance); + furi_check(instance->thread_id == furi_thread_get_current_id()); + furi_check(callback ? interval > 0 : true); + + instance->tick.callback = callback; + instance->tick.callback_context = context; + instance->tick.interval = interval; + instance->tick.prev_time = xTaskGetTickCount(); +} diff --git a/furi/core/event_loop_tick_i.h b/furi/core/event_loop_tick_i.h new file mode 100644 index 00000000000..8936e38282f --- /dev/null +++ b/furi/core/event_loop_tick_i.h @@ -0,0 +1,16 @@ +#pragma once + +#include "event_loop.h" + +typedef struct { + uint32_t interval; + uint32_t prev_time; + FuriEventLoopTickCallback callback; + void* callback_context; +} FuriEventLoopTick; + +void furi_event_loop_init_tick(FuriEventLoop* instance); + +void furi_event_loop_process_tick(FuriEventLoop* instance); + +uint32_t furi_event_loop_get_tick_wait_time(const FuriEventLoop* instance); diff --git a/furi/core/event_loop_timer.c b/furi/core/event_loop_timer.c new file mode 100644 index 00000000000..03b6c513234 --- /dev/null +++ b/furi/core/event_loop_timer.c @@ -0,0 +1,215 @@ +#include "event_loop_i.h" + +#include +#include + +#include + +/* + * Private functions + */ + +static inline uint32_t furi_event_loop_timer_get_elapsed_time(const FuriEventLoopTimer* timer) { + return xTaskGetTickCount() - timer->start_time; +} + +static inline uint32_t + furi_event_loop_timer_get_remaining_time_private(const FuriEventLoopTimer* timer) { + const uint32_t elapsed_time = furi_event_loop_timer_get_elapsed_time(timer); + return elapsed_time < timer->interval ? timer->interval - elapsed_time : 0; +} + +static inline bool furi_event_loop_timer_is_expired(const FuriEventLoopTimer* timer) { + return furi_event_loop_timer_get_elapsed_time(timer) >= timer->interval; +} + +static void furi_event_loop_schedule_timer(FuriEventLoop* instance, FuriEventLoopTimer* timer) { + FuriEventLoopTimer* timer_pos = NULL; + + FURI_CRITICAL_ENTER(); + + const uint32_t remaining_time = furi_event_loop_timer_get_remaining_time_private(timer); + + TimerList_it_t it; + for(TimerList_it_last(it, instance->timer_list); !TimerList_end_p(it); + TimerList_previous(it)) { + FuriEventLoopTimer* tmp = TimerList_ref(it); + if(remaining_time >= furi_event_loop_timer_get_remaining_time_private(tmp)) { + timer_pos = tmp; + break; + } + } + + FURI_CRITICAL_EXIT(); + + if(timer_pos) { + TimerList_push_after(timer_pos, timer); + } else { + TimerList_push_front(instance->timer_list, timer); + } + // At this point, TimerList_front() points to the first timer to expire +} + +static void furi_event_loop_timer_enqueue_request( + FuriEventLoopTimer* timer, + FuriEventLoopTimerRequest request) { + if(timer->request != FuriEventLoopTimerRequestNone) { + // You cannot change your mind after calling furi_event_loop_timer_free() + furi_check(timer->request != FuriEventLoopTimerRequestFree); + TimerQueue_unlink(timer); + } + + timer->request = request; + + FuriEventLoop* instance = timer->owner; + TimerQueue_push_back(instance->timer_queue, timer); + + xTaskNotifyIndexed( + instance->thread_id, FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX, FuriEventLoopFlagTimer, eSetBits); +} + +/* + * Private API + */ + +uint32_t furi_event_loop_get_timer_wait_time(const FuriEventLoop* instance) { + uint32_t wait_time = FuriWaitForever; + + if(!TimerList_empty_p(instance->timer_list)) { + FuriEventLoopTimer* timer = TimerList_front(instance->timer_list); + wait_time = furi_event_loop_timer_get_remaining_time_private(timer); + } + + return wait_time; +} + +void furi_event_loop_process_timer_queue(FuriEventLoop* instance) { + while(!TimerQueue_empty_p(instance->timer_queue)) { + FuriEventLoopTimer* timer = TimerQueue_pop_front(instance->timer_queue); + + if(timer->active) { + TimerList_unlink(timer); + } + + if(timer->request == FuriEventLoopTimerRequestStart) { + timer->active = true; + timer->interval = timer->next_interval; + timer->start_time = xTaskGetTickCount(); + timer->request = FuriEventLoopTimerRequestNone; + + furi_event_loop_schedule_timer(instance, timer); + + } else if(timer->request == FuriEventLoopTimerRequestStop) { + timer->active = false; + timer->request = FuriEventLoopTimerRequestNone; + + } else if(timer->request == FuriEventLoopTimerRequestFree) { + free(timer); + + } else { + furi_crash(); + } + } +} + +bool furi_event_loop_process_expired_timers(FuriEventLoop* instance) { + if(TimerList_empty_p(instance->timer_list)) { + return false; + } + // The front() element contains the earliest-expiring timer + FuriEventLoopTimer* timer = TimerList_front(instance->timer_list); + + if(!furi_event_loop_timer_is_expired(timer)) { + return false; + } + + TimerList_unlink(timer); + + if(timer->periodic) { + const uint32_t num_events = + furi_event_loop_timer_get_elapsed_time(timer) / timer->interval; + + timer->start_time += timer->interval * num_events; + furi_event_loop_schedule_timer(instance, timer); + + } else { + timer->active = false; + } + + timer->callback(timer->context); + return true; +} + +/* + * Public timer API + */ + +FuriEventLoopTimer* furi_event_loop_timer_alloc( + FuriEventLoop* instance, + FuriEventLoopTimerCallback callback, + FuriEventLoopTimerType type, + void* context) { + furi_check(instance); + furi_check(instance->thread_id == furi_thread_get_current_id()); + furi_check(callback); + furi_check(type <= FuriEventLoopTimerTypePeriodic); + + FuriEventLoopTimer* timer = malloc(sizeof(FuriEventLoopTimer)); + + timer->owner = instance; + timer->callback = callback; + timer->context = context; + timer->periodic = (type == FuriEventLoopTimerTypePeriodic); + + TimerList_init_field(timer); + TimerQueue_init_field(timer); + + return timer; +} + +void furi_event_loop_timer_free(FuriEventLoopTimer* timer) { + furi_check(timer); + furi_check(timer->owner->thread_id == furi_thread_get_current_id()); + + furi_event_loop_timer_enqueue_request(timer, FuriEventLoopTimerRequestFree); +} + +void furi_event_loop_timer_start(FuriEventLoopTimer* timer, uint32_t interval) { + furi_check(timer); + furi_check(timer->owner->thread_id == furi_thread_get_current_id()); + + timer->next_interval = interval; + + furi_event_loop_timer_enqueue_request(timer, FuriEventLoopTimerRequestStart); +} + +void furi_event_loop_timer_restart(FuriEventLoopTimer* timer) { + furi_check(timer); + furi_check(timer->owner->thread_id == furi_thread_get_current_id()); + + timer->next_interval = timer->interval; + + furi_event_loop_timer_enqueue_request(timer, FuriEventLoopTimerRequestStart); +} + +void furi_event_loop_timer_stop(FuriEventLoopTimer* timer) { + furi_check(timer); + furi_check(timer->owner->thread_id == furi_thread_get_current_id()); + + furi_event_loop_timer_enqueue_request(timer, FuriEventLoopTimerRequestStop); +} + +uint32_t furi_event_loop_timer_get_remaining_time(const FuriEventLoopTimer* timer) { + furi_check(timer); + return furi_event_loop_timer_get_remaining_time_private(timer); +} + +uint32_t furi_event_loop_timer_get_interval(const FuriEventLoopTimer* timer) { + furi_check(timer); + return timer->interval; +} + +bool furi_event_loop_timer_is_running(const FuriEventLoopTimer* timer) { + furi_check(timer); + return timer->active; +} diff --git a/furi/core/event_loop_timer.h b/furi/core/event_loop_timer.h new file mode 100644 index 00000000000..9034043faf7 --- /dev/null +++ b/furi/core/event_loop_timer.h @@ -0,0 +1,118 @@ +/** + * @file event_loop_timer.h + * @brief Software timer functionality for FuriEventLoop. + */ + +#pragma once + +#include "event_loop.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumeration of possible timer types. + */ +typedef enum { + FuriEventLoopTimerTypeOnce = 0, /**< One-shot timer. */ + FuriEventLoopTimerTypePeriodic = 1, /**< Repeating timer. */ +} FuriEventLoopTimerType; + +/** + * @brief Timer callback type for functions to be called when a timer expires. + * + * In the timer callback, it is ALLOWED: + * - To start, stop, or restart an existing timer, + * - To create new timers using furi_event_loop_timer_alloc(), + * - To delete timers using furi_event_loop_timer_free(). + * + * @param[in,out] context pointer to a user-specific object that was provided during timer creation + */ +typedef void (*FuriEventLoopTimerCallback)(void* context); + +/** + * @brief Opaque event loop timer type. + */ +typedef struct FuriEventLoopTimer FuriEventLoopTimer; + +/** + * @brief Create a new event loop timer instance. + * + * @param[in,out] instance pointer to the current FuriEventLoop instance + * @param[in] callback pointer to the callback function to be executed upon timer timeout + * @param[in] type timer type value to determine its behavior (single-shot or periodic) + * @param[in,out] context pointer to a user-specific object (will be passed to the callback) + * @returns pointer to the created timer instance + */ +FuriEventLoopTimer* furi_event_loop_timer_alloc( + FuriEventLoop* instance, + FuriEventLoopTimerCallback callback, + FuriEventLoopTimerType type, + void* context); + +/** + * @brief Delete an event loop timer instance. + * + * @warning The user code MUST call furi_event_loop_timer_free() on ALL instances + * associated with the current event loop BEFORE calling furi_event_loop_free(). + * The event loop may EITHER be running OR stopped when the timers are being deleted. + * + * @param[in,out] timer pointer to the timer instance to be deleted + */ +void furi_event_loop_timer_free(FuriEventLoopTimer* timer); + +/** + * @brief Start a timer or restart it with a new interval. + * + * @param[in,out] timer pointer to the timer instance to be (re)started + * @param[in] interval timer interval in ticks + */ +void furi_event_loop_timer_start(FuriEventLoopTimer* timer, uint32_t interval); + +/** + * @brief Restart a timer with the previously set interval. + * + * @param[in,out] timer pointer to the timer instance to be restarted + */ +void furi_event_loop_timer_restart(FuriEventLoopTimer* timer); + +/** + * @brief Stop a timer without firing its callback. + * + * It is safe to call this function on an already stopped timer (it will do nothing). + * + * @param[in,out] timer pointer to the timer instance to be stopped + */ +void furi_event_loop_timer_stop(FuriEventLoopTimer* timer); + +/** + * @brief Get the time remaining before the timer becomes expires. + * + * For stopped or expired timers, this function returns 0. + * + * @param[in] timer pointer to the timer to be queried + * @returns remaining time in ticks + */ +uint32_t furi_event_loop_timer_get_remaining_time(const FuriEventLoopTimer* timer); + +/** + * @brief Get the timer interval. + * + * @param[in] timer pointer to the timer to be queried + * @returns timer interval in ticks + */ +uint32_t furi_event_loop_timer_get_interval(const FuriEventLoopTimer* timer); + +/** + * @brief Check if the timer is currently running. + * + * A timer is considered running if it has not expired yet. + * @param[in] timer pointer to the timer to be queried + * @returns true if the timer is running, false otherwise + */ +bool furi_event_loop_timer_is_running(const FuriEventLoopTimer* timer); + +#ifdef __cplusplus +} +#endif diff --git a/furi/core/event_loop_timer_i.h b/furi/core/event_loop_timer_i.h new file mode 100644 index 00000000000..9c6f90cca2c --- /dev/null +++ b/furi/core/event_loop_timer_i.h @@ -0,0 +1,43 @@ +#pragma once + +#include "event_loop_timer.h" + +#include + +typedef enum { + FuriEventLoopTimerRequestNone, + FuriEventLoopTimerRequestStart, + FuriEventLoopTimerRequestStop, + FuriEventLoopTimerRequestFree, +} FuriEventLoopTimerRequest; + +struct FuriEventLoopTimer { + FuriEventLoop* owner; + + FuriEventLoopTimerCallback callback; + void* context; + + uint32_t interval; + uint32_t start_time; + uint32_t next_interval; + + // Interface for the active timer list + ILIST_INTERFACE(TimerList, FuriEventLoopTimer); + + // Interface for the timer request queue + ILIST_INTERFACE(TimerQueue, FuriEventLoopTimer); + + FuriEventLoopTimerRequest request; + + bool active; + bool periodic; +}; + +ILIST_DEF(TimerList, FuriEventLoopTimer, M_POD_OPLIST) +ILIST_DEF(TimerQueue, FuriEventLoopTimer, M_POD_OPLIST) + +uint32_t furi_event_loop_get_timer_wait_time(const FuriEventLoop* instance); + +void furi_event_loop_process_timer_queue(FuriEventLoop* instance); + +bool furi_event_loop_process_expired_timers(FuriEventLoop* instance); diff --git a/furi/core/kernel.c b/furi/core/kernel.c index 52c0e285eed..f3f84e692e4 100644 --- a/furi/core/kernel.c +++ b/furi/core/kernel.c @@ -29,7 +29,7 @@ bool furi_kernel_is_irq_or_masked(void) { } /* Return context, 0: thread context, 1: IRQ context */ - return (irq); + return irq; } bool furi_kernel_is_running(void) { @@ -58,7 +58,7 @@ int32_t furi_kernel_lock(void) { } /* Return previous lock state */ - return (lock); + return lock; } int32_t furi_kernel_unlock(void) { @@ -88,7 +88,7 @@ int32_t furi_kernel_unlock(void) { } /* Return previous lock state */ - return (lock); + return lock; } int32_t furi_kernel_restore_lock(int32_t lock) { @@ -119,12 +119,12 @@ int32_t furi_kernel_restore_lock(int32_t lock) { } /* Return new lock state */ - return (lock); + return lock; } uint32_t furi_kernel_get_tick_frequency(void) { /* Return frequency in hertz */ - return (configTICK_RATE_HZ_RAW); + return configTICK_RATE_HZ_RAW; } void furi_delay_tick(uint32_t ticks) { @@ -160,7 +160,7 @@ FuriStatus furi_delay_until_tick(uint32_t tick) { } /* Return execution status */ - return (stat); + return stat; } uint32_t furi_get_tick(void) { diff --git a/furi/core/log.h b/furi/core/log.h index 3ce88db5b2e..817d9dda350 100644 --- a/furi/core/log.h +++ b/furi/core/log.h @@ -23,14 +23,14 @@ typedef enum { FuriLogLevelTrace = 6, } FuriLogLevel; -#define _FURI_LOG_CLR(clr) "\033[0;" clr "m" +#define _FURI_LOG_CLR(clr) "\033[0;" clr "m" #define _FURI_LOG_CLR_RESET "\033[0m" -#define _FURI_LOG_CLR_BLACK "30" -#define _FURI_LOG_CLR_RED "31" -#define _FURI_LOG_CLR_GREEN "32" -#define _FURI_LOG_CLR_BROWN "33" -#define _FURI_LOG_CLR_BLUE "34" +#define _FURI_LOG_CLR_BLACK "30" +#define _FURI_LOG_CLR_RED "31" +#define _FURI_LOG_CLR_GREEN "32" +#define _FURI_LOG_CLR_BROWN "33" +#define _FURI_LOG_CLR_BLUE "34" #define _FURI_LOG_CLR_PURPLE "35" #define _FURI_LOG_CLR_E _FURI_LOG_CLR(_FURI_LOG_CLR_RED) diff --git a/furi/core/memmgr.c b/furi/core/memmgr.c index ba9a7336a9c..d3ff873ae50 100644 --- a/furi/core/memmgr.c +++ b/furi/core/memmgr.c @@ -107,4 +107,4 @@ void* aligned_malloc(size_t size, size_t alignment) { void aligned_free(void* p) { free(((void**)p)[-1]); -} \ No newline at end of file +} diff --git a/furi/core/memmgr_heap.c b/furi/core/memmgr_heap.c index 3827ddde34c..359d0e3dba4 100644 --- a/furi/core/memmgr_heap.c +++ b/furi/core/memmgr_heap.c @@ -528,7 +528,7 @@ void vPortFree(void* pv) { xFreeBytesRemaining += pxLink->xBlockSize; traceFREE(pv, pxLink->xBlockSize); memset(pv, 0, pxLink->xBlockSize - xHeapStructSize); - prvInsertBlockIntoFreeList(((BlockLink_t*)pxLink)); + prvInsertBlockIntoFreeList((BlockLink_t*)pxLink); } (void)xTaskResumeAll(); } else { diff --git a/furi/core/message_queue.c b/furi/core/message_queue.c index cda775abe96..3521ceb30b2 100644 --- a/furi/core/message_queue.c +++ b/furi/core/message_queue.c @@ -1,9 +1,15 @@ #include "message_queue_i.h" +#include +#include + +#include "kernel.h" +#include "check.h" + // Internal FreeRTOS member names #define uxMessagesWaiting uxDummy4[0] -#define uxLength uxDummy4[1] -#define uxItemSize uxDummy4[2] +#define uxLength uxDummy4[1] +#define uxItemSize uxDummy4[2] struct FuriMessageQueue { StaticQueue_t container; diff --git a/furi/core/message_queue_i.h b/furi/core/message_queue_i.h index aa24cfe54fc..a88d04131ae 100644 --- a/furi/core/message_queue_i.h +++ b/furi/core/message_queue_i.h @@ -1,12 +1,6 @@ #pragma once #include "message_queue.h" +#include "event_loop_link_i.h" -#include "kernel.h" -#include "event_loop_i.h" -#include "check.h" - -#include -#include - -extern const FuriEventLoopContract furi_message_queue_event_loop_contract; \ No newline at end of file +extern const FuriEventLoopContract furi_message_queue_event_loop_contract; diff --git a/furi/core/stream_buffer.c b/furi/core/stream_buffer.c index 879520010a4..ef8869dea06 100644 --- a/furi/core/stream_buffer.c +++ b/furi/core/stream_buffer.c @@ -29,20 +29,20 @@ FuriStreamBuffer* furi_stream_buffer_alloc(size_t size, size_t trigger_level) { furi_check(hStreamBuffer == (StreamBufferHandle_t)stream_buffer); return stream_buffer; -}; +} void furi_stream_buffer_free(FuriStreamBuffer* stream_buffer) { furi_check(stream_buffer); vStreamBufferDelete((StreamBufferHandle_t)stream_buffer); free(stream_buffer); -}; +} bool furi_stream_set_trigger_level(FuriStreamBuffer* stream_buffer, size_t trigger_level) { furi_check(stream_buffer); return xStreamBufferSetTriggerLevel((StreamBufferHandle_t)stream_buffer, trigger_level) == pdTRUE; -}; +} size_t furi_stream_buffer_send( FuriStreamBuffer* stream_buffer, @@ -62,7 +62,7 @@ size_t furi_stream_buffer_send( } return ret; -}; +} size_t furi_stream_buffer_receive( FuriStreamBuffer* stream_buffer, @@ -89,25 +89,25 @@ size_t furi_stream_buffer_bytes_available(FuriStreamBuffer* stream_buffer) { furi_check(stream_buffer); return xStreamBufferBytesAvailable((StreamBufferHandle_t)stream_buffer); -}; +} size_t furi_stream_buffer_spaces_available(FuriStreamBuffer* stream_buffer) { furi_check(stream_buffer); return xStreamBufferSpacesAvailable((StreamBufferHandle_t)stream_buffer); -}; +} bool furi_stream_buffer_is_full(FuriStreamBuffer* stream_buffer) { furi_check(stream_buffer); return xStreamBufferIsFull((StreamBufferHandle_t)stream_buffer) == pdTRUE; -}; +} bool furi_stream_buffer_is_empty(FuriStreamBuffer* stream_buffer) { furi_check(stream_buffer); - return (xStreamBufferIsEmpty((StreamBufferHandle_t)stream_buffer) == pdTRUE); -}; + return xStreamBufferIsEmpty((StreamBufferHandle_t)stream_buffer) == pdTRUE; +} FuriStatus furi_stream_buffer_reset(FuriStreamBuffer* stream_buffer) { furi_check(stream_buffer); diff --git a/furi/core/string.h b/furi/core/string.h index 324135e96d7..bcdf9336c7d 100644 --- a/furi/core/string.h +++ b/furi/core/string.h @@ -17,7 +17,7 @@ extern "C" { /** * @brief Furi string failure constant. */ -#define FURI_STRING_FAILURE ((size_t)-1) +#define FURI_STRING_FAILURE ((size_t) - 1) /** * @brief Furi string primitive. diff --git a/furi/core/thread.c b/furi/core/thread.c index 4e9477712a0..c47df55e49d 100644 --- a/furi/core/thread.c +++ b/furi/core/thread.c @@ -42,6 +42,9 @@ struct FuriThread { FuriThreadStateCallback state_callback; void* state_context; + FuriThreadSignalCallback signal_callback; + void* signal_context; + char* name; char* appid; @@ -304,6 +307,29 @@ FuriThreadState furi_thread_get_state(FuriThread* thread) { return thread->state; } +void furi_thread_set_signal_callback( + FuriThread* thread, + FuriThreadSignalCallback callback, + void* context) { + furi_check(thread); + furi_check(thread->state == FuriThreadStateStopped || thread == furi_thread_get_current()); + + thread->signal_callback = callback; + thread->signal_context = context; +} + +bool furi_thread_signal(const FuriThread* thread, uint32_t signal, void* arg) { + furi_check(thread); + + bool is_consumed = false; + + if(thread->signal_callback) { + is_consumed = thread->signal_callback(signal, arg, thread->signal_context); + } + + return is_consumed; +} + void furi_thread_start(FuriThread* thread) { furi_check(thread); furi_check(thread->callback); @@ -400,11 +426,11 @@ void furi_thread_yield(void) { } /* Limits */ -#define MAX_BITS_TASK_NOTIFY 31U +#define MAX_BITS_TASK_NOTIFY 31U #define MAX_BITS_EVENT_GROUPS 24U #define THREAD_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_TASK_NOTIFY) - 1U)) -#define EVENT_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_EVENT_GROUPS) - 1U)) +#define EVENT_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_EVENT_GROUPS) - 1U)) uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags) { TaskHandle_t hTask = (TaskHandle_t)thread_id; diff --git a/furi/core/thread.h b/furi/core/thread.h index 9c113bd4943..be09e040ea2 100644 --- a/furi/core/thread.h +++ b/furi/core/thread.h @@ -86,6 +86,18 @@ typedef void (*FuriThreadStdoutWriteCallback)(const char* data, size_t size); */ typedef void (*FuriThreadStateCallback)(FuriThreadState state, void* context); +/** + * @brief Signal handler callback function pointer type. + * + * The function to be used as a signal handler callback MUS follow this signature. + * + * @param[in] signal value of the signal to be handled by the recipient + * @param[in,out] arg optional argument (can be of any value, including NULL) + * @param[in,out] context pointer to a user-specified object + * @returns true if the signal was handled, false otherwise + */ +typedef bool (*FuriThreadSignalCallback)(uint32_t signal, void* arg, void* context); + /** * @brief Create a FuriThread instance. * @@ -255,6 +267,29 @@ void furi_thread_set_state_context(FuriThread* thread, void* context); */ FuriThreadState furi_thread_get_state(FuriThread* thread); +/** + * @brief Set a signal handler callback for a FuriThread instance. + * + * The thread MUST be stopped when calling this function. + * + * @param[in,out] thread pointer to the FuriThread instance to be modified + * @param[in] callback pointer to a user-specified callback function + * @param[in] context pointer to a user-specified object (will be passed to the callback, can be NULL) + */ +void furi_thread_set_signal_callback( + FuriThread* thread, + FuriThreadSignalCallback callback, + void* context); + +/** + * @brief Send a signal to a FuriThread instance. + * + * @param[in] thread pointer to the FuriThread instance to be signaled + * @param[in] signal signal value to be sent + * @param[in,out] arg optional argument (can be of any value, including NULL) + */ +bool furi_thread_signal(const FuriThread* thread, uint32_t signal, void* arg); + /** * @brief Start a FuriThread instance. * diff --git a/furi/core/thread_list.c b/furi/core/thread_list.c index 65ee11ad388..5355a896caf 100644 --- a/furi/core/thread_list.c +++ b/furi/core/thread_list.c @@ -1,6 +1,8 @@ #include "thread_list.h" #include "check.h" +#include + #include #include @@ -23,6 +25,8 @@ struct FuriThreadList { FuriThreadListItemDict_t search; uint32_t runtime_previous; uint32_t runtime_current; + uint32_t isr_previous; + uint32_t isr_current; }; FuriThreadList* furi_thread_list_alloc(void) { @@ -85,7 +89,10 @@ void furi_thread_list_process(FuriThreadList* instance, uint32_t runtime, uint32 instance->runtime_previous = instance->runtime_current; instance->runtime_current = runtime; - uint32_t runtime_counter = instance->runtime_current - instance->runtime_previous; + instance->isr_previous = instance->isr_current; + instance->isr_current = furi_hal_interrupt_get_time_in_isr_total(); + + const uint32_t runtime_counter = instance->runtime_current - instance->runtime_previous; FuriThreadListItemArray_it_t it; FuriThreadListItemArray_it(it, instance->items); @@ -108,3 +115,10 @@ void furi_thread_list_process(FuriThreadList* instance, uint32_t runtime, uint32 } } } + +float furi_thread_list_get_isr_time(FuriThreadList* instance) { + const uint32_t runtime_counter = instance->runtime_current - instance->runtime_previous; + const uint32_t isr_counter = instance->isr_current - instance->isr_previous; + + return (float)isr_counter / (float)runtime_counter; +} diff --git a/furi/core/thread_list.h b/furi/core/thread_list.h index bf15e4032be..d01aa24a04e 100644 --- a/furi/core/thread_list.h +++ b/furi/core/thread_list.h @@ -76,6 +76,14 @@ FuriThreadListItem* furi_thread_list_get_or_insert(FuriThreadList* instance, Fur */ void furi_thread_list_process(FuriThreadList* instance, uint32_t runtime, uint32_t tick); +/** Get percent of time spent in ISR + * + * @param instance The instance + * + * @return percent of time spent in ISR + */ +float furi_thread_list_get_isr_time(FuriThreadList* instance); + #ifdef __cplusplus } #endif diff --git a/furi/furi.h b/furi/furi.h index 400cf1d6439..80ee30457c6 100644 --- a/furi/furi.h +++ b/furi/furi.h @@ -5,6 +5,7 @@ #include "core/check.h" #include "core/common_defines.h" #include "core/event_loop.h" +#include "core/event_loop_timer.h" #include "core/event_flag.h" #include "core/kernel.h" #include "core/log.h" diff --git a/lib/ReadMe.md b/lib/ReadMe.md index ed0e4ce887c..64da39e358c 100644 --- a/lib/ReadMe.md +++ b/lib/ReadMe.md @@ -1,17 +1,18 @@ # Structure -- `FreeRTOS-Kernel` - FreeRTOS kernel source code -- `FreeRTOS-glue` - Extra glue to hold together FreeRTOS kernel and flipper firmware - `app-scened-template` - C++ app library - `bit_lib` - library for working with bits/bytes directly -- `callback-connector` - Callback connector library +- `ble_profile` - BLE Profiles source code - `cmsis_core` - CMSIS Core package, contain cortex-m core headers - `cxxheaderparser` - C++ headers parser, used by SDK bundler +- `datetime` - DateTime library - `digital_signal` - Digital signal library: used by NFC for software implemented protocols - `drivers` - Various flipper drivers - `fatfs` - FatFS file system driver - `flipper_application` - Flipper application library, used for FAPs - `flipper_format` - Flipper File Format library +- `FreeRTOS-glue` - Extra glue to hold together FreeRTOS kernel and flipper firmware +- `FreeRTOS-Kernel` - FreeRTOS kernel source code - `heatshrink` - Heatshrink compression library - `ibutton` - ibutton library, used by iButton application - `infrared` - Infrared library, used by Infrared application @@ -20,7 +21,9 @@ - `littlefs` - LittleFS file system driver, used by internal storage - `mbedtls` - MbedTLS cryptography library - `microtar` - MicroTAR library +- `mjs` - MJs, javascript engine library - `mlib` - M-Lib C containers library +- `music_worker` - MusicWorker library for playing midi and RTTTL files - `nanopb` - NanoPB library, protobuf implementation for MCU - `nfc` - NFC library, used by NFC application - `one_wire` - OneWire library, used by iButton application @@ -33,4 +36,4 @@ - `subghz` - Subghz library, used by SubGhz application - `toolbox` - Toolbox library, contains various things that is used by Flipper firmware - `u8g2` - u8g2 graphics library, used by GUI subsystem -- `update_util` - update utilities library, used by updater \ No newline at end of file +- `update_util` - update utilities library, used by updater diff --git a/lib/SConscript b/lib/SConscript index 8125739325a..f331198a426 100644 --- a/lib/SConscript +++ b/lib/SConscript @@ -4,7 +4,7 @@ Import("env") env.Append( CPPPATH=[ "#/", - "#/lib", # TODO FL-3553: remove! + "#/lib", # Ugly hack Dir("../assets/compiled"), ], diff --git a/lib/app-scened-template/generic_scene.hpp b/lib/app-scened-template/generic_scene.hpp index bcdf0b46413..580346c8c01 100644 --- a/lib/app-scened-template/generic_scene.hpp +++ b/lib/app-scened-template/generic_scene.hpp @@ -4,7 +4,7 @@ class GenericScene { virtual void on_enter(TApp* app, bool need_restore) = 0; virtual bool on_event(TApp* app, typename TApp::Event* event) = 0; virtual void on_exit(TApp* app) = 0; - virtual ~GenericScene(){}; + virtual ~GenericScene() {}; private: }; diff --git a/lib/app-scened-template/record_controller.hpp b/lib/app-scened-template/record_controller.hpp index 171115e15bf..3453c12f3ab 100644 --- a/lib/app-scened-template/record_controller.hpp +++ b/lib/app-scened-template/record_controller.hpp @@ -17,7 +17,7 @@ class RecordController { RecordController(const char* record_name) { name = record_name; value = static_cast(furi_record_open(name)); - }; + } ~RecordController() { furi_record_close(name); diff --git a/lib/app-scened-template/scene_controller.hpp b/lib/app-scened-template/scene_controller.hpp index 052eca73166..eb431095840 100644 --- a/lib/app-scened-template/scene_controller.hpp +++ b/lib/app-scened-template/scene_controller.hpp @@ -175,7 +175,8 @@ class SceneController { bool switch_to_previous_scene(uint8_t count = 1) { auto previous_scene_index = TApp::SceneType::Start; - for(uint8_t i = 0; i < count; i++) previous_scene_index = get_previous_scene_index(); + for(uint8_t i = 0; i < count; i++) + previous_scene_index = get_previous_scene_index(); if(previous_scene_index == TApp::SceneType::Exit) return true; @@ -198,7 +199,8 @@ class SceneController { * */ ~SceneController() { - for(auto& it : scenes) delete it.second; + for(auto& it : scenes) + delete it.second; } private: diff --git a/lib/app-scened-template/typeindex_no_rtti.hpp b/lib/app-scened-template/typeindex_no_rtti.hpp index 0f399385ab5..579a0189d9a 100644 --- a/lib/app-scened-template/typeindex_no_rtti.hpp +++ b/lib/app-scened-template/typeindex_no_rtti.hpp @@ -50,7 +50,8 @@ struct type_index { * Creates a type_index object for the specified type. */ template - type_index(tag_type) noexcept : hash_code_{index} { + type_index(tag_type) noexcept + : hash_code_{index} { } /** diff --git a/lib/app-scened-template/view_controller.hpp b/lib/app-scened-template/view_controller.hpp index 8c48fcf747a..ccd3c0fd39a 100644 --- a/lib/app-scened-template/view_controller.hpp +++ b/lib/app-scened-template/view_controller.hpp @@ -27,7 +27,7 @@ class ViewController { 0)...); gui = static_cast(furi_record_open("gui")); - }; + } ~ViewController() { for(auto& it : holder) { diff --git a/lib/app-scened-template/view_modules/generic_view_module.h b/lib/app-scened-template/view_modules/generic_view_module.h index 8b74ea3add2..f6c56a9110f 100644 --- a/lib/app-scened-template/view_modules/generic_view_module.h +++ b/lib/app-scened-template/view_modules/generic_view_module.h @@ -3,8 +3,8 @@ class GenericViewModule { public: - GenericViewModule(){}; - virtual ~GenericViewModule(){}; + GenericViewModule() {}; + virtual ~GenericViewModule() {}; virtual View* get_view() = 0; virtual void clean() = 0; }; diff --git a/lib/bit_lib/bit_lib.c b/lib/bit_lib/bit_lib.c index 8122b1cc453..c00cfaca33e 100644 --- a/lib/bit_lib/bit_lib.c +++ b/lib/bit_lib/bit_lib.c @@ -482,4 +482,4 @@ uint64_t bit_lib_bytes_to_num_bcd(const uint8_t* src, uint8_t len, bool* is_bcd) } return res; -} \ No newline at end of file +} diff --git a/lib/bit_lib/bit_lib.h b/lib/bit_lib/bit_lib.h index 7d23cf06364..b8cc092c816 100644 --- a/lib/bit_lib/bit_lib.h +++ b/lib/bit_lib/bit_lib.h @@ -7,7 +7,7 @@ extern "C" { #endif -#define TOPBIT(X) (1 << ((X)-1)) +#define TOPBIT(X) (1 << ((X) - 1)) typedef enum { BitLibParityEven, diff --git a/lib/cxxheaderparser b/lib/cxxheaderparser deleted file mode 160000 index ba4222560fc..00000000000 --- a/lib/cxxheaderparser +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ba4222560fc1040670b1a917d5d357198e8ec5d6 diff --git a/lib/datetime/datetime.c b/lib/datetime/datetime.c index 9c2194d968a..4429312628d 100644 --- a/lib/datetime/datetime.c +++ b/lib/datetime/datetime.c @@ -4,10 +4,10 @@ #define TAG "DateTime" #define SECONDS_PER_MINUTE 60 -#define SECONDS_PER_HOUR (SECONDS_PER_MINUTE * 60) -#define SECONDS_PER_DAY (SECONDS_PER_HOUR * 24) -#define MONTHS_COUNT 12 -#define EPOCH_START_YEAR 1970 +#define SECONDS_PER_HOUR (SECONDS_PER_MINUTE * 60) +#define SECONDS_PER_DAY (SECONDS_PER_HOUR * 24) +#define MONTHS_COUNT 12 +#define EPOCH_START_YEAR 1970 static const uint8_t datetime_days_per_month[2][MONTHS_COUNT] = { {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, diff --git a/lib/digital_signal/digital_sequence.c b/lib/digital_signal/digital_sequence.c index 24dddb77de2..f93ce6d951a 100644 --- a/lib/digital_signal/digital_sequence.c +++ b/lib/digital_signal/digital_sequence.c @@ -22,7 +22,7 @@ #define DIGITAL_SEQUENCE_TIMER_MAX 0xFFFFFFFFUL /* Time to wait in loops before returning */ -#define DIGITAL_SEQUENCE_LOCK_WAIT_MS 10UL +#define DIGITAL_SEQUENCE_LOCK_WAIT_MS 10UL #define DIGITAL_SEQUENCE_LOCK_WAIT_TICKS (DIGITAL_SEQUENCE_LOCK_WAIT_MS * 1000 * 64) #define DIGITAL_SEQUENCE_GPIO_BUFFER_SIZE 2 @@ -55,7 +55,6 @@ struct DigitalSequence { uint32_t size; uint32_t max_size; - uint8_t* data; LL_DMA_InitTypeDef dma_config_gpio; LL_DMA_InitTypeDef dma_config_timer; @@ -64,19 +63,19 @@ struct DigitalSequence { DigitalSequenceRingBuffer timer_buf; DigitalSequenceSignalBank signals; DigitalSequenceState state; + + uint8_t data[]; }; DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio) { furi_assert(size); furi_assert(gpio); - DigitalSequence* sequence = malloc(sizeof(DigitalSequence)); + DigitalSequence* sequence = malloc(sizeof(DigitalSequence) + size); sequence->gpio = gpio; sequence->max_size = size; - sequence->data = malloc(sequence->max_size); - sequence->dma_config_gpio.PeriphOrM2MSrcAddress = (uint32_t)&gpio->port->BSRR; sequence->dma_config_gpio.MemoryOrM2MDstAddress = (uint32_t)sequence->gpio_buf; sequence->dma_config_gpio.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH; @@ -107,7 +106,6 @@ DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio) { void digital_sequence_free(DigitalSequence* sequence) { furi_assert(sequence); - free(sequence->data); free(sequence); } diff --git a/lib/digital_signal/digital_signal.c b/lib/digital_signal/digital_signal.c index 585250c2614..dd8600a4017 100644 --- a/lib/digital_signal/digital_signal.c +++ b/lib/digital_signal/digital_signal.c @@ -6,10 +6,9 @@ #define TAG "DigitalSignal" DigitalSignal* digital_signal_alloc(uint32_t max_size) { - DigitalSignal* signal = malloc(sizeof(DigitalSignal)); + DigitalSignal* signal = malloc(sizeof(DigitalSignal) + (max_size * sizeof(uint32_t))); signal->max_size = max_size; - signal->data = malloc(max_size * sizeof(uint32_t)); return signal; } @@ -17,7 +16,6 @@ DigitalSignal* digital_signal_alloc(uint32_t max_size) { void digital_signal_free(DigitalSignal* signal) { furi_check(signal); - free(signal->data); free(signal); } diff --git a/lib/digital_signal/digital_signal_i.h b/lib/digital_signal/digital_signal_i.h index e473c80c091..71a28021c8b 100644 --- a/lib/digital_signal/digital_signal_i.h +++ b/lib/digital_signal/digital_signal_i.h @@ -8,7 +8,7 @@ #include #include -#define DIGITAL_SIGNAL_T_TIM 1562 /**< 15.625 ns *100 */ +#define DIGITAL_SIGNAL_T_TIM 1562 /**< 15.625 ns *100 */ #define DIGITAL_SIGNAL_T_TIM_DIV2 (DIGITAL_SIGNAL_T_TIM / 2) /**< 15.625 ns / 2 *100 */ /** @@ -18,6 +18,6 @@ struct DigitalSignal { bool start_level; /**< The level to begin the signal with. */ uint32_t size; /**< Current period count contained in the instance. */ uint32_t max_size; /**< Maximum period count this instance can hold. */ - uint32_t* data; /**< Pointer to the array of time periods. */ int32_t remainder; /**< Remainder left after converting all periods into timer ticks. */ + uint32_t data[]; /**< The array of time periods. */ }; diff --git a/lib/digital_signal/presets/nfc/iso14443_3a_signal.c b/lib/digital_signal/presets/nfc/iso14443_3a_signal.c index 1f3824e2dcd..740d6ae9813 100644 --- a/lib/digital_signal/presets/nfc/iso14443_3a_signal.c +++ b/lib/digital_signal/presets/nfc/iso14443_3a_signal.c @@ -5,14 +5,14 @@ #define BITS_IN_BYTE (8) #define ISO14443_3A_SIGNAL_BIT_MAX_EDGES (10) -#define ISO14443_3A_SIGNAL_MAX_EDGES (1350) +#define ISO14443_3A_SIGNAL_MAX_EDGES (1350) #define ISO14443_3A_SIGNAL_SEQUENCE_SIZE \ (ISO14443_3A_SIGNAL_MAX_EDGES / (ISO14443_3A_SIGNAL_BIT_MAX_EDGES - 2)) -#define ISO14443_3A_SIGNAL_F_SIG (13560000.0) -#define ISO14443_3A_SIGNAL_T_SIG 7374 //73.746ns*100 -#define ISO14443_3A_SIGNAL_T_SIG_X8 58992 //T_SIG*8 +#define ISO14443_3A_SIGNAL_F_SIG (13560000.0) +#define ISO14443_3A_SIGNAL_T_SIG 7374 //73.746ns*100 +#define ISO14443_3A_SIGNAL_T_SIG_X8 58992 //T_SIG*8 #define ISO14443_3A_SIGNAL_T_SIG_X8_X8 471936 //T_SIG*8*8 #define ISO14443_3A_SIGNAL_T_SIG_X8_X9 530928 //T_SIG*8*9 diff --git a/lib/digital_signal/presets/nfc/iso15693_signal.c b/lib/digital_signal/presets/nfc/iso15693_signal.c index 735a88f57aa..43066b5bf0a 100644 --- a/lib/digital_signal/presets/nfc/iso15693_signal.c +++ b/lib/digital_signal/presets/nfc/iso15693_signal.c @@ -8,13 +8,13 @@ #define ISO15693_SIGNAL_COEFF_LO (4U) #define ISO15693_SIGNAL_ZERO_EDGES (16U) -#define ISO15693_SIGNAL_ONE_EDGES (ISO15693_SIGNAL_ZERO_EDGES + 1U) -#define ISO15693_SIGNAL_EOF_EDGES (64U) -#define ISO15693_SIGNAL_SOF_EDGES (ISO15693_SIGNAL_EOF_EDGES + 1U) -#define ISO15693_SIGNAL_EDGES (1350U) +#define ISO15693_SIGNAL_ONE_EDGES (ISO15693_SIGNAL_ZERO_EDGES + 1U) +#define ISO15693_SIGNAL_EOF_EDGES (64U) +#define ISO15693_SIGNAL_SOF_EDGES (ISO15693_SIGNAL_EOF_EDGES + 1U) +#define ISO15693_SIGNAL_EDGES (1350U) -#define ISO15693_SIGNAL_FC (13.56e6) -#define ISO15693_SIGNAL_FC_16 (16.0e11 / ISO15693_SIGNAL_FC) +#define ISO15693_SIGNAL_FC (13.56e6) +#define ISO15693_SIGNAL_FC_16 (16.0e11 / ISO15693_SIGNAL_FC) #define ISO15693_SIGNAL_FC_256 (256.0e11 / ISO15693_SIGNAL_FC) #define ISO15693_SIGNAL_FC_768 (768.0e11 / ISO15693_SIGNAL_FC) diff --git a/lib/drivers/bq25896_reg.h b/lib/drivers/bq25896_reg.h index a6ca3e1c77e..23d094003a9 100644 --- a/lib/drivers/bq25896_reg.h +++ b/lib/drivers/bq25896_reg.h @@ -7,27 +7,27 @@ #error Bit structures defined in this file is not portable to BE #endif -#define BQ25896_ADDRESS 0xD6 +#define BQ25896_ADDRESS 0xD6 #define BQ25896_I2C_TIMEOUT 50 #define IILIM_1600 (1 << 5) -#define IILIM_800 (1 << 4) -#define IILIM_400 (1 << 3) -#define IILIM_200 (1 << 2) -#define IILIM_100 (1 << 1) -#define IILIM_50 (1 << 0) +#define IILIM_800 (1 << 4) +#define IILIM_400 (1 << 3) +#define IILIM_200 (1 << 2) +#define IILIM_100 (1 << 1) +#define IILIM_50 (1 << 0) typedef struct { uint8_t IINLIM : 6; // Input Current Limit, mA, offset: +100mA - bool EN_ILIM : 1; // Enable ILIM Pin - bool EN_HIZ : 1; // Enable HIZ Mode + bool EN_ILIM : 1; // Enable ILIM Pin + bool EN_HIZ : 1; // Enable HIZ Mode } REG00; #define VINDPM_OS_1600 (1 << 4) -#define VINDPM_OS_800 (1 << 3) -#define VINDPM_OS_400 (1 << 2) -#define VINDPM_OS_200 (1 << 1) -#define VINDPM_OS_100 (1 << 0) +#define VINDPM_OS_800 (1 << 3) +#define VINDPM_OS_400 (1 << 2) +#define VINDPM_OS_200 (1 << 1) +#define VINDPM_OS_100 (1 << 0) typedef enum { Bhot34 = 0b00, // – VBHOT1 Threshold (34.75%) (default) @@ -38,18 +38,18 @@ typedef enum { typedef struct { uint8_t VINDPM_OS : 5; // Input Voltage Limit Offset, mV - bool BCOLD : 1; // Boost Mode Cold Temperature Monitor Threshold - Bhot BHOT : 2; // Boost Mode Hot Temperature Monitor Threshold + bool BCOLD : 1; // Boost Mode Cold Temperature Monitor Threshold + Bhot BHOT : 2; // Boost Mode Hot Temperature Monitor Threshold } REG01; typedef struct { bool AUTO_DPDM_EN : 1; // Automatic Input Detection Enable - bool FORCE_DPDM : 1; // Force Input Detection - uint8_t RES : 2; // Reserved - bool ICO_EN : 1; // Input Current Optimizer (ICO) Enable - bool BOOST_FREQ : 1; // Boost Mode Frequency Selection - bool CONV_RATE : 1; // ADC Conversion Rate Selection - bool CONV_START : 1; // ADC Conversion Start Control + bool FORCE_DPDM : 1; // Force Input Detection + uint8_t RES : 2; // Reserved + bool ICO_EN : 1; // Input Current Optimizer (ICO) Enable + bool BOOST_FREQ : 1; // Boost Mode Frequency Selection + bool CONV_RATE : 1; // ADC Conversion Rate Selection + bool CONV_START : 1; // ADC Conversion Start Control } REG02; #define SYS_MIN_400 (1 << 2) @@ -58,45 +58,45 @@ typedef struct { typedef struct { bool MIN_VBAT_SEL : 1; // Minimum Battery Voltage (falling) to exit boost mode - uint8_t SYS_MIN : 3; // Minimum System Voltage Limit, mV, offset: +3000mV - bool CHG_CONFIG : 1; // Charge Enable Configuration - bool OTG_CONFIG : 1; // Boost (OTG) Mode Configuration - bool WD_RST : 1; // I2C Watchdog Timer Reset - bool BAT_LOADEN : 1; // Battery Load (IBATLOAD) Enable + uint8_t SYS_MIN : 3; // Minimum System Voltage Limit, mV, offset: +3000mV + bool CHG_CONFIG : 1; // Charge Enable Configuration + bool OTG_CONFIG : 1; // Boost (OTG) Mode Configuration + bool WD_RST : 1; // I2C Watchdog Timer Reset + bool BAT_LOADEN : 1; // Battery Load (IBATLOAD) Enable } REG03; #define ICHG_4096 (1 << 6) #define ICHG_2048 (1 << 5) #define ICHG_1024 (1 << 4) -#define ICHG_512 (1 << 3) -#define ICHG_256 (1 << 2) -#define ICHG_128 (1 << 1) -#define ICHG_64 (1 << 0) +#define ICHG_512 (1 << 3) +#define ICHG_256 (1 << 2) +#define ICHG_128 (1 << 1) +#define ICHG_64 (1 << 0) typedef struct { - uint8_t ICHG : 7; // Fast Charge Current Limit, mA + uint8_t ICHG : 7; // Fast Charge Current Limit, mA bool EN_PUMPX : 1; // Current pulse control Enable } REG04; #define IPRETERM_512 (1 << 3) #define IPRETERM_256 (1 << 2) #define IPRETERM_128 (1 << 1) -#define IPRETERM_64 (1 << 0) +#define IPRETERM_64 (1 << 0) typedef struct { - uint8_t ITERM : 4; // Termination Current Limit, offset: +64mA + uint8_t ITERM : 4; // Termination Current Limit, offset: +64mA uint8_t IPRECHG : 4; // Precharge Current Limit, offset: +64mA } REG05; #define VREG_512 (1 << 5) #define VREG_256 (1 << 4) #define VREG_128 (1 << 3) -#define VREG_64 (1 << 2) -#define VREG_32 (1 << 1) -#define VREG_16 (1 << 0) +#define VREG_64 (1 << 2) +#define VREG_32 (1 << 1) +#define VREG_16 (1 << 0) typedef struct { - bool VRECHG : 1; // Battery Recharge Threshold Offset + bool VRECHG : 1; // Battery Recharge Threshold Offset bool BATLOWV : 1; // Battery Precharge to Fast Charge Threshold uint8_t VREG : 6; // Charge Voltage Limit, offset: +3840mV } REG06; @@ -116,12 +116,12 @@ typedef enum { } ChgTimer; typedef struct { - bool JEITA_ISET : 1; // JEITA Low Temperature Current Setting + bool JEITA_ISET : 1; // JEITA Low Temperature Current Setting ChgTimer CHG_TIMER : 2; // Fast Charge Timer Setting - bool EN_TIMER : 1; // Charging Safety Timer Enable - Watchdog WATCHDOG : 2; // I2C Watchdog Timer Setting - bool STAT_DIS : 1; // STAT Pin Disable - bool EN_TERM : 1; // Charging Termination Enable + bool EN_TIMER : 1; // Charging Safety Timer Enable + Watchdog WATCHDOG : 2; // I2C Watchdog Timer Setting + bool STAT_DIS : 1; // STAT Pin Disable + bool EN_TERM : 1; // Charging Termination Enable } REG07; #define BAT_COMP_80 (1 << 2) @@ -129,35 +129,35 @@ typedef struct { #define BAT_COMP_20 (1 << 0) #define VCLAMP_128 (1 << 2) -#define VCLAMP_64 (1 << 1) -#define VCLAMP_32 (1 << 0) +#define VCLAMP_64 (1 << 1) +#define VCLAMP_32 (1 << 0) -#define TREG_60 (0b00) -#define TREG_80 (0b01) +#define TREG_60 (0b00) +#define TREG_80 (0b01) #define TREG_100 (0b10) #define TREG_120 (0b11) typedef struct { - uint8_t TREG : 2; // Thermal Regulation Threshold - uint8_t VCLAMP : 3; // IR Compensation Voltage Clamp + uint8_t TREG : 2; // Thermal Regulation Threshold + uint8_t VCLAMP : 3; // IR Compensation Voltage Clamp uint8_t BAT_COMP : 3; // IR Compensation Resistor Setting } REG08; typedef struct { - bool PUMPX_DN : 1; // Current pulse control voltage down enable - bool PUMPX_UP : 1; // Current pulse control voltage up enable + bool PUMPX_DN : 1; // Current pulse control voltage down enable + bool PUMPX_UP : 1; // Current pulse control voltage up enable bool BATFET_RST_EN : 1; // BATFET full system reset enable - bool BATFET_DLY : 1; // BATFET turn off delay control - bool JEITA_VSET : 1; // JEITA High Temperature Voltage Setting - bool BATFET_DIS : 1; // Force BATFET off to enable ship mode - bool TMR2X_EN : 1; // Safety Timer Setting during DPM or Thermal Regulation - bool FORCE_ICO : 1; // Force Start Input Current Optimizer + bool BATFET_DLY : 1; // BATFET turn off delay control + bool JEITA_VSET : 1; // JEITA High Temperature Voltage Setting + bool BATFET_DIS : 1; // Force BATFET off to enable ship mode + bool TMR2X_EN : 1; // Safety Timer Setting during DPM or Thermal Regulation + bool FORCE_ICO : 1; // Force Start Input Current Optimizer } REG09; #define BOOSTV_512 (1 << 3) #define BOOSTV_256 (1 << 2) #define BOOSTV_128 (1 << 1) -#define BOOSTV_64 (1 << 0) +#define BOOSTV_64 (1 << 0) typedef enum { BoostLim_500 = 0b000, @@ -172,8 +172,8 @@ typedef enum { typedef struct { uint8_t BOOST_LIM : 3; // Boost Mode Current Limit - bool PFM_OTG_DIS : 1; // PFM mode allowed in boost mode - uint8_t BOOSTV : 4; // Boost Mode Voltage Regulation, offset: +4550mV + bool PFM_OTG_DIS : 1; // PFM mode allowed in boost mode + uint8_t BOOSTV : 4; // Boost Mode Voltage Regulation, offset: +4550mV } REG0A; typedef enum { @@ -191,9 +191,9 @@ typedef enum { } ChrgStat; typedef struct { - bool VSYS_STAT : 1; // VSYS Regulation Status - bool RES : 1; // Reserved: Always reads 1 - bool PG_STAT : 1; // Power Good Status + bool VSYS_STAT : 1; // VSYS Regulation Status + bool RES : 1; // Reserved: Always reads 1 + bool PG_STAT : 1; // Power Good Status ChrgStat CHRG_STAT : 2; // Charging Status VBusStat VBUS_STAT : 3; // VBUS Status register } REG0B; @@ -214,49 +214,49 @@ typedef enum { } NtcFault; typedef struct { - NtcFault NTC_FAULT : 3; // NTC Fault Status - bool BAT_FAULT : 1; // Battery Fault Status + NtcFault NTC_FAULT : 3; // NTC Fault Status + bool BAT_FAULT : 1; // Battery Fault Status ChrgFault CHRG_FAULT : 2; // Charge Fault Status - bool BOOST_FAULT : 1; // Boost Mode Fault Status - bool WATCHDOG_FAULT : 1; // Watchdog Fault Status + bool BOOST_FAULT : 1; // Boost Mode Fault Status + bool WATCHDOG_FAULT : 1; // Watchdog Fault Status } REG0C; #define VINDPM_6400 (1 << 6) #define VINDPM_3200 (1 << 5) #define VINDPM_1600 (1 << 4) -#define VINDPM_800 (1 << 3) -#define VINDPM_400 (1 << 2) -#define VINDPM_200 (1 << 1) -#define VINDPM_100 (1 << 0) +#define VINDPM_800 (1 << 3) +#define VINDPM_400 (1 << 2) +#define VINDPM_200 (1 << 1) +#define VINDPM_100 (1 << 0) typedef struct { - uint8_t VINDPM : 7; // Absolute VINDPM Threshold, offset: +2600mV + uint8_t VINDPM : 7; // Absolute VINDPM Threshold, offset: +2600mV bool FORCE_VINDPM : 1; // VINDPM Threshold Setting Method } REG0D; typedef struct { - uint8_t BATV : 7; // ADC conversion of Battery Voltage (VBAT), offset: +2304mV + uint8_t BATV : 7; // ADC conversion of Battery Voltage (VBAT), offset: +2304mV bool THERM_STAT : 1; // Thermal Regulation Status } REG0E; typedef struct { uint8_t SYSV : 7; // ADDC conversion of System Voltage (VSYS), offset: +2304mV - uint8_t RES : 1; // Reserved: Always reads 0 + uint8_t RES : 1; // Reserved: Always reads 0 } REG0F; typedef struct { uint8_t TSPCT : 7; // ADC conversion of TS Voltage (TS) as percentage of REGN, offset: +21% - uint8_t RES : 1; // Reserved: Always reads 0 + uint8_t RES : 1; // Reserved: Always reads 0 } REG10; typedef struct { uint8_t VBUSV : 7; // ADC conversion of VBUS voltage (VBUS), offset: +2600mV - bool VBUS_GD : 1; // VBUS Good Status + bool VBUS_GD : 1; // VBUS Good Status } REG11; typedef struct { uint8_t ICHGR : 7; // ADC conversion of Charge Current (IBAT) when VBAT > VBATSHORT - uint8_t RES : 1; // Reserved: Always reads 0 + uint8_t RES : 1; // Reserved: Always reads 0 } REG12; typedef struct { @@ -267,9 +267,9 @@ typedef struct { } REG13; typedef struct { - uint8_t DEV_REV : 2; // Device Revision - bool TS_PROFILE : 1; // Temperature Profile - uint8_t PN : 3; // Device Configuration + uint8_t DEV_REV : 2; // Device Revision + bool TS_PROFILE : 1; // Temperature Profile + uint8_t PN : 3; // Device Configuration bool ICO_OPTIMIZED : 1; // Input Current Optimizer (ICO) Status - bool REG_RST : 1; // Register Reset + bool REG_RST : 1; // Register Reset } REG14; diff --git a/lib/drivers/bq27220.h b/lib/drivers/bq27220.h index ca9e0312e87..fc76e318f82 100644 --- a/lib/drivers/bq27220.h +++ b/lib/drivers/bq27220.h @@ -4,45 +4,45 @@ #include #include -#define BQ27220_ERROR 0x0 +#define BQ27220_ERROR 0x0 #define BQ27220_SUCCESS 0x1 typedef struct { // Low byte, Low bit first - bool DSG : 1; // The device is in DISCHARGE - bool SYSDWN : 1; // System down bit indicating the system should shut down - bool TDA : 1; // Terminate Discharge Alarm + bool DSG : 1; // The device is in DISCHARGE + bool SYSDWN : 1; // System down bit indicating the system should shut down + bool TDA : 1; // Terminate Discharge Alarm bool BATTPRES : 1; // Battery Present detected - bool AUTH_GD : 1; // Detect inserted battery - bool OCVGD : 1; // Good OCV measurement taken - bool TCA : 1; // Terminate Charge Alarm - bool RSVD : 1; // Reserved + bool AUTH_GD : 1; // Detect inserted battery + bool OCVGD : 1; // Good OCV measurement taken + bool TCA : 1; // Terminate Charge Alarm + bool RSVD : 1; // Reserved // High byte, Low bit first - bool CHGINH : 1; // Charge inhibit - bool FC : 1; // Full-charged is detected - bool OTD : 1; // Overtemperature in discharge condition is detected - bool OTC : 1; // Overtemperature in charge condition is detected - bool SLEEP : 1; // Device is operating in SLEEP mode when set - bool OCVFAIL : 1; // Status bit indicating that the OCV reading failed due to current - bool OCVCOMP : 1; // An OCV measurement update is complete - bool FD : 1; // Full-discharge is detected + bool CHGINH : 1; // Charge inhibit + bool FC : 1; // Full-charged is detected + bool OTD : 1; // Overtemperature in discharge condition is detected + bool OTC : 1; // Overtemperature in charge condition is detected + bool SLEEP : 1; // Device is operating in SLEEP mode when set + bool OCVFAIL : 1; // Status bit indicating that the OCV reading failed due to current + bool OCVCOMP : 1; // An OCV measurement update is complete + bool FD : 1; // Full-discharge is detected } BatteryStatus; _Static_assert(sizeof(BatteryStatus) == 2, "Incorrect structure size"); typedef struct { // Low byte, Low bit first - bool CALMD : 1; /**< Calibration mode enabled */ + bool CALMD : 1; /**< Calibration mode enabled */ uint8_t SEC : 2; /**< Current security access */ - bool EDV2 : 1; /**< EDV2 threshold exceeded */ + bool EDV2 : 1; /**< EDV2 threshold exceeded */ bool VDQ : 1; /**< Indicates if Current discharge cycle is NOT qualified or qualified for an FCC updated */ - bool INITCOMP : 1; /**< gauge initialization is complete */ - bool SMTH : 1; /**< RemainingCapacity is scaled by smooth engine */ - bool BTPINT : 1; /**< BTP threshold has been crossed */ + bool INITCOMP : 1; /**< gauge initialization is complete */ + bool SMTH : 1; /**< RemainingCapacity is scaled by smooth engine */ + bool BTPINT : 1; /**< BTP threshold has been crossed */ // High byte, Low bit first - uint8_t RSVD1 : 2; + uint8_t RSVD1 : 2; bool CFGUPDATE : 1; /**< Gauge is in CONFIG UPDATE mode */ - uint8_t RSVD0 : 5; + uint8_t RSVD0 : 5; } OperationStatus; _Static_assert(sizeof(OperationStatus) == 2, "Incorrect structure size"); diff --git a/lib/drivers/bq27220_data_memory.h b/lib/drivers/bq27220_data_memory.h index ae00be88360..30f2dae1ec6 100644 --- a/lib/drivers/bq27220_data_memory.h +++ b/lib/drivers/bq27220_data_memory.h @@ -67,18 +67,18 @@ struct BQ27220DMData { typedef struct { // Low byte, Low bit first - const bool CCT : 1; - const bool CSYNC : 1; - const bool RSVD0 : 1; - const bool EDV_CMP : 1; - const bool SC : 1; + const bool CCT : 1; + const bool CSYNC : 1; + const bool RSVD0 : 1; + const bool EDV_CMP : 1; + const bool SC : 1; const bool FIXED_EDV0 : 1; - const uint8_t RSVD1 : 2; + const uint8_t RSVD1 : 2; // High byte, Low bit first - const bool FCC_LIM : 1; - const bool RSVD2 : 1; + const bool FCC_LIM : 1; + const bool RSVD2 : 1; const bool FC_FOR_VDQ : 1; - const bool IGNORE_SD : 1; - const bool SME0 : 1; - const uint8_t RSVD3 : 3; + const bool IGNORE_SD : 1; + const bool SME0 : 1; + const uint8_t RSVD3 : 3; } BQ27220DMGaugingConfig; diff --git a/lib/drivers/bq27220_reg.h b/lib/drivers/bq27220_reg.h index 2e6e54aabef..1c1ec9d8f90 100644 --- a/lib/drivers/bq27220_reg.h +++ b/lib/drivers/bq27220_reg.h @@ -1,68 +1,68 @@ #pragma once -#define BQ27220_ADDRESS 0xAA +#define BQ27220_ADDRESS 0xAA #define BQ27220_I2C_TIMEOUT 50 -#define CommandControl 0x00 -#define CommandAtRate 0x02 -#define CommandAtRateTimeToEmpty 0x04 -#define CommandTemperature 0x06 -#define CommandVoltage 0x08 -#define CommandBatteryStatus 0x0A -#define CommandCurrent 0x0C -#define CommandRemainingCapacity 0x10 -#define CommandFullChargeCapacity 0x12 -#define CommandAverageCurrent 0x14 -#define CommandTimeToEmpty 0x16 -#define CommandTimeToFull 0x18 -#define CommandStandbyCurrent 0x1A -#define CommandStandbyTimeToEmpty 0x1C -#define CommandMaxLoadCurrent 0x1E -#define CommandMaxLoadTimeToEmpty 0x20 -#define CommandRawCoulombCount 0x22 -#define CommandAveragePower 0x24 +#define CommandControl 0x00 +#define CommandAtRate 0x02 +#define CommandAtRateTimeToEmpty 0x04 +#define CommandTemperature 0x06 +#define CommandVoltage 0x08 +#define CommandBatteryStatus 0x0A +#define CommandCurrent 0x0C +#define CommandRemainingCapacity 0x10 +#define CommandFullChargeCapacity 0x12 +#define CommandAverageCurrent 0x14 +#define CommandTimeToEmpty 0x16 +#define CommandTimeToFull 0x18 +#define CommandStandbyCurrent 0x1A +#define CommandStandbyTimeToEmpty 0x1C +#define CommandMaxLoadCurrent 0x1E +#define CommandMaxLoadTimeToEmpty 0x20 +#define CommandRawCoulombCount 0x22 +#define CommandAveragePower 0x24 #define CommandInternalTemperature 0x28 -#define CommandCycleCount 0x2A -#define CommandStateOfCharge 0x2C -#define CommandStateOfHealth 0x2E -#define CommandChargeVoltage 0x30 -#define CommandChargeCurrent 0x32 -#define CommandBTPDischargeSet 0x34 -#define CommandBTPChargeSet 0x36 -#define CommandOperationStatus 0x3A -#define CommandDesignCapacity 0x3C -#define CommandSelectSubclass 0x3E -#define CommandMACData 0x40 -#define CommandMACDataSum 0x60 -#define CommandMACDataLen 0x61 -#define CommandAnalogCount 0x79 -#define CommandRawCurrent 0x7A -#define CommandRawVoltage 0x7C -#define CommandRawIntTemp 0x7E +#define CommandCycleCount 0x2A +#define CommandStateOfCharge 0x2C +#define CommandStateOfHealth 0x2E +#define CommandChargeVoltage 0x30 +#define CommandChargeCurrent 0x32 +#define CommandBTPDischargeSet 0x34 +#define CommandBTPChargeSet 0x36 +#define CommandOperationStatus 0x3A +#define CommandDesignCapacity 0x3C +#define CommandSelectSubclass 0x3E +#define CommandMACData 0x40 +#define CommandMACDataSum 0x60 +#define CommandMACDataLen 0x61 +#define CommandAnalogCount 0x79 +#define CommandRawCurrent 0x7A +#define CommandRawVoltage 0x7C +#define CommandRawIntTemp 0x7E -#define Control_CONTROL_STATUS 0x0000 -#define Control_DEVICE_NUMBER 0x0001 -#define Control_FW_VERSION 0x0002 -#define Control_BOARD_OFFSET 0x0009 -#define Control_CC_OFFSET 0x000A -#define Control_CC_OFFSET_SAVE 0x000B -#define Control_OCV_CMD 0x000C -#define Control_BAT_INSERT 0x000D -#define Control_BAT_REMOVE 0x000E -#define Control_SET_SNOOZE 0x0013 -#define Control_CLEAR_SNOOZE 0x0014 -#define Control_SET_PROFILE_1 0x0015 -#define Control_SET_PROFILE_2 0x0016 -#define Control_SET_PROFILE_3 0x0017 -#define Control_SET_PROFILE_4 0x0018 -#define Control_SET_PROFILE_5 0x0019 -#define Control_SET_PROFILE_6 0x001A -#define Control_CAL_TOGGLE 0x002D -#define Control_SEALED 0x0030 -#define Control_RESET 0x0041 -#define Control_EXIT_CAL 0x0080 -#define Control_ENTER_CAL 0x0081 -#define Control_ENTER_CFG_UPDATE 0x0090 +#define Control_CONTROL_STATUS 0x0000 +#define Control_DEVICE_NUMBER 0x0001 +#define Control_FW_VERSION 0x0002 +#define Control_BOARD_OFFSET 0x0009 +#define Control_CC_OFFSET 0x000A +#define Control_CC_OFFSET_SAVE 0x000B +#define Control_OCV_CMD 0x000C +#define Control_BAT_INSERT 0x000D +#define Control_BAT_REMOVE 0x000E +#define Control_SET_SNOOZE 0x0013 +#define Control_CLEAR_SNOOZE 0x0014 +#define Control_SET_PROFILE_1 0x0015 +#define Control_SET_PROFILE_2 0x0016 +#define Control_SET_PROFILE_3 0x0017 +#define Control_SET_PROFILE_4 0x0018 +#define Control_SET_PROFILE_5 0x0019 +#define Control_SET_PROFILE_6 0x001A +#define Control_CAL_TOGGLE 0x002D +#define Control_SEALED 0x0030 +#define Control_RESET 0x0041 +#define Control_EXIT_CAL 0x0080 +#define Control_ENTER_CAL 0x0081 +#define Control_ENTER_CFG_UPDATE 0x0090 #define Control_EXIT_CFG_UPDATE_REINIT 0x0091 -#define Control_EXIT_CFG_UPDATE 0x0092 -#define Control_RETURN_TO_ROM 0x0F00 +#define Control_EXIT_CFG_UPDATE 0x0092 +#define Control_RETURN_TO_ROM 0x0F00 diff --git a/lib/drivers/cc1101.c b/lib/drivers/cc1101.c index b71d78ff0a9..40b286a9b85 100644 --- a/lib/drivers/cc1101.c +++ b/lib/drivers/cc1101.c @@ -185,4 +185,4 @@ uint8_t cc1101_read_fifo(FuriHalSpiBusHandle* handle, uint8_t* data, uint8_t* si furi_hal_spi_bus_trx(handle, NULL, data, *size, CC1101_TIMEOUT); return *size; -} \ No newline at end of file +} diff --git a/lib/drivers/cc1101_regs.h b/lib/drivers/cc1101_regs.h index e0aed6bd93c..aaf9062a858 100644 --- a/lib/drivers/cc1101_regs.h +++ b/lib/drivers/cc1101_regs.h @@ -9,65 +9,65 @@ extern "C" { /* Frequency Synthesizer constants */ #define CC1101_QUARTZ 26000000 -#define CC1101_FMASK 0xFFFFFF -#define CC1101_FDIV 0x10000 -#define CC1101_IFDIV 0x400 +#define CC1101_FMASK 0xFFFFFF +#define CC1101_FDIV 0x10000 +#define CC1101_IFDIV 0x400 /* IO Bus constants */ #define CC1101_TIMEOUT 250 /* Bits and pieces */ -#define CC1101_READ (1 << 7) /** Read Bit */ +#define CC1101_READ (1 << 7) /** Read Bit */ #define CC1101_BURST (1 << 6) /** Burst Bit */ /* Common registers, CC1101_BURST and CC1101_WRITE behaves as expected */ -#define CC1101_IOCFG2 0x00 /** GDO2 output pin configuration */ -#define CC1101_IOCFG1 0x01 /** GDO1 output pin configuration */ -#define CC1101_IOCFG0 0x02 /** GDO0 output pin configuration */ -#define CC1101_FIFOTHR 0x03 /** RX FIFO and TX FIFO thresholds */ -#define CC1101_SYNC1 0x04 /** Sync word, high byte */ -#define CC1101_SYNC0 0x05 /** Sync word, low byte */ -#define CC1101_PKTLEN 0x06 /** Packet length */ +#define CC1101_IOCFG2 0x00 /** GDO2 output pin configuration */ +#define CC1101_IOCFG1 0x01 /** GDO1 output pin configuration */ +#define CC1101_IOCFG0 0x02 /** GDO0 output pin configuration */ +#define CC1101_FIFOTHR 0x03 /** RX FIFO and TX FIFO thresholds */ +#define CC1101_SYNC1 0x04 /** Sync word, high byte */ +#define CC1101_SYNC0 0x05 /** Sync word, low byte */ +#define CC1101_PKTLEN 0x06 /** Packet length */ #define CC1101_PKTCTRL1 0x07 /** Packet automation control */ #define CC1101_PKTCTRL0 0x08 /** Packet automation control */ -#define CC1101_ADDR 0x09 /** Device address */ -#define CC1101_CHANNR 0x0A /** Channel number */ -#define CC1101_FSCTRL1 0x0B /** Frequency synthesizer control */ -#define CC1101_FSCTRL0 0x0C /** Frequency synthesizer control */ -#define CC1101_FREQ2 0x0D /** Frequency control word, high byte */ -#define CC1101_FREQ1 0x0E /** Frequency control word, middle byte */ -#define CC1101_FREQ0 0x0F /** Frequency control word, low byte */ -#define CC1101_MDMCFG4 0x10 /** Modem configuration */ -#define CC1101_MDMCFG3 0x11 /** Modem configuration */ -#define CC1101_MDMCFG2 0x12 /** Modem configuration */ -#define CC1101_MDMCFG1 0x13 /** Modem configuration */ -#define CC1101_MDMCFG0 0x14 /** Modem configuration */ -#define CC1101_DEVIATN 0x15 /** Modem deviation setting */ -#define CC1101_MCSM2 0x16 /** Main Radio Control State Machine configuration */ -#define CC1101_MCSM1 0x17 /** Main Radio Control State Machine configuration */ -#define CC1101_MCSM0 0x18 /** Main Radio Control State Machine configuration */ -#define CC1101_FOCCFG 0x19 /** Frequency Offset Compensation configuration */ -#define CC1101_BSCFG 0x1A /** Bit Synchronization configuration */ +#define CC1101_ADDR 0x09 /** Device address */ +#define CC1101_CHANNR 0x0A /** Channel number */ +#define CC1101_FSCTRL1 0x0B /** Frequency synthesizer control */ +#define CC1101_FSCTRL0 0x0C /** Frequency synthesizer control */ +#define CC1101_FREQ2 0x0D /** Frequency control word, high byte */ +#define CC1101_FREQ1 0x0E /** Frequency control word, middle byte */ +#define CC1101_FREQ0 0x0F /** Frequency control word, low byte */ +#define CC1101_MDMCFG4 0x10 /** Modem configuration */ +#define CC1101_MDMCFG3 0x11 /** Modem configuration */ +#define CC1101_MDMCFG2 0x12 /** Modem configuration */ +#define CC1101_MDMCFG1 0x13 /** Modem configuration */ +#define CC1101_MDMCFG0 0x14 /** Modem configuration */ +#define CC1101_DEVIATN 0x15 /** Modem deviation setting */ +#define CC1101_MCSM2 0x16 /** Main Radio Control State Machine configuration */ +#define CC1101_MCSM1 0x17 /** Main Radio Control State Machine configuration */ +#define CC1101_MCSM0 0x18 /** Main Radio Control State Machine configuration */ +#define CC1101_FOCCFG 0x19 /** Frequency Offset Compensation configuration */ +#define CC1101_BSCFG 0x1A /** Bit Synchronization configuration */ #define CC1101_AGCCTRL2 0x1B /** AGC control */ #define CC1101_AGCCTRL1 0x1C /** AGC control */ #define CC1101_AGCCTRL0 0x1D /** AGC control */ -#define CC1101_WOREVT1 0x1E /** High byte Event 0 timeout */ -#define CC1101_WOREVT0 0x1F /** Low byte Event 0 timeout */ -#define CC1101_WORCTRL 0x20 /** Wake On Radio control */ -#define CC1101_FREND1 0x21 /** Front end RX configuration */ -#define CC1101_FREND0 0x22 /** Front end TX configuration */ -#define CC1101_FSCAL3 0x23 /** Frequency synthesizer calibration */ -#define CC1101_FSCAL2 0x24 /** Frequency synthesizer calibration */ -#define CC1101_FSCAL1 0x25 /** Frequency synthesizer calibration */ -#define CC1101_FSCAL0 0x26 /** Frequency synthesizer calibration */ -#define CC1101_RCCTRL1 0x27 /** RC oscillator configuration */ -#define CC1101_RCCTRL0 0x28 /** RC oscillator configuration */ -#define CC1101_FSTEST 0x29 /** Frequency synthesizer calibration control */ -#define CC1101_PTEST 0x2A /** Production test */ -#define CC1101_AGCTEST 0x2B /** AGC test */ -#define CC1101_TEST2 0x2C /** Various test settings */ -#define CC1101_TEST1 0x2D /** Various test settings */ -#define CC1101_TEST0 0x2E /** Various test settings */ +#define CC1101_WOREVT1 0x1E /** High byte Event 0 timeout */ +#define CC1101_WOREVT0 0x1F /** Low byte Event 0 timeout */ +#define CC1101_WORCTRL 0x20 /** Wake On Radio control */ +#define CC1101_FREND1 0x21 /** Front end RX configuration */ +#define CC1101_FREND0 0x22 /** Front end TX configuration */ +#define CC1101_FSCAL3 0x23 /** Frequency synthesizer calibration */ +#define CC1101_FSCAL2 0x24 /** Frequency synthesizer calibration */ +#define CC1101_FSCAL1 0x25 /** Frequency synthesizer calibration */ +#define CC1101_FSCAL0 0x26 /** Frequency synthesizer calibration */ +#define CC1101_RCCTRL1 0x27 /** RC oscillator configuration */ +#define CC1101_RCCTRL0 0x28 /** RC oscillator configuration */ +#define CC1101_FSTEST 0x29 /** Frequency synthesizer calibration control */ +#define CC1101_PTEST 0x2A /** Production test */ +#define CC1101_AGCTEST 0x2B /** AGC test */ +#define CC1101_TEST2 0x2C /** Various test settings */ +#define CC1101_TEST1 0x2D /** Various test settings */ +#define CC1101_TEST0 0x2E /** Various test settings */ /* Strobe registers, CC1101_BURST is not available, CC1101_WRITE ignored */ #define CC1101_STROBE_SRES 0x30 /** Reset chip. */ @@ -95,15 +95,15 @@ extern "C" { 0x3D /** No operation. May be used to get access to the chip status byte.*/ /* Status registers, must be accessed with CC1101_BURST, but one by one */ -#define CC1101_STATUS_PARTNUM 0x30 /** Chip ID Part Number */ -#define CC1101_STATUS_VERSION 0x31 /** Chip ID Version */ -#define CC1101_STATUS_FREQEST 0x32 /** Frequency Offset Estimate from Demodulator */ -#define CC1101_STATUS_LQI 0x33 /** Demodulator Estimate for Link Quality, 7bit-CRC, 6..0-LQI*/ -#define CC1101_STATUS_RSSI 0x34 /** Received Signal Strength Indication */ -#define CC1101_STATUS_MARCSTATE 0x35 /** Main Radio Control State Machine State */ -#define CC1101_STATUS_WORTIME1 0x36 /** High Byte of WOR Time */ -#define CC1101_STATUS_WORTIME0 0x37 /** Low Byte of WOR Time */ -#define CC1101_STATUS_PKTSTATUS 0x38 /** Current GDOx Status and Packet Status */ +#define CC1101_STATUS_PARTNUM 0x30 /** Chip ID Part Number */ +#define CC1101_STATUS_VERSION 0x31 /** Chip ID Version */ +#define CC1101_STATUS_FREQEST 0x32 /** Frequency Offset Estimate from Demodulator */ +#define CC1101_STATUS_LQI 0x33 /** Demodulator Estimate for Link Quality, 7bit-CRC, 6..0-LQI*/ +#define CC1101_STATUS_RSSI 0x34 /** Received Signal Strength Indication */ +#define CC1101_STATUS_MARCSTATE 0x35 /** Main Radio Control State Machine State */ +#define CC1101_STATUS_WORTIME1 0x36 /** High Byte of WOR Time */ +#define CC1101_STATUS_WORTIME0 0x37 /** Low Byte of WOR Time */ +#define CC1101_STATUS_PKTSTATUS 0x38 /** Current GDOx Status and Packet Status */ #define CC1101_STATUS_VCO_VC_DAC 0x39 /** Current Setting from PLL Calibration Module */ #define CC1101_STATUS_TXBYTES \ 0x3A /** Underflow and Number of Bytes, 7bit-Underflow, 6..0-Number of Bytes*/ @@ -188,8 +188,8 @@ typedef enum { typedef struct { uint8_t FIFO_BYTES_AVAILABLE : 4; - CC1101State STATE : 3; - bool CHIP_RDYn : 1; + CC1101State STATE : 3; + bool CHIP_RDYn : 1; } CC1101Status; typedef union { @@ -198,12 +198,12 @@ typedef union { } CC1101StatusRaw; typedef struct { - uint8_t NUM_TXBYTES : 7; + uint8_t NUM_TXBYTES : 7; bool TXFIFO_UNDERFLOW : 1; } CC1101TxBytes; typedef struct { - uint8_t NUM_RXBYTES : 7; + uint8_t NUM_RXBYTES : 7; bool RXFIFO_OVERFLOW : 1; } CC1101RxBytes; diff --git a/lib/drivers/lp5562_reg.h b/lib/drivers/lp5562_reg.h index e65cc2afee1..9103e5395f9 100644 --- a/lib/drivers/lp5562_reg.h +++ b/lib/drivers/lp5562_reg.h @@ -4,17 +4,17 @@ #error Bit structures defined in this file is not portable to BE #endif -#define LP5562_ADDRESS 0x60 +#define LP5562_ADDRESS 0x60 #define LP5562_I2C_TIMEOUT 50 -#define LP5562_CHANNEL_RED_CURRENT_REGISTER 0x07 +#define LP5562_CHANNEL_RED_CURRENT_REGISTER 0x07 #define LP5562_CHANNEL_GREEN_CURRENT_REGISTER 0x06 -#define LP5562_CHANNEL_BLUE_CURRENT_REGISTER 0x05 +#define LP5562_CHANNEL_BLUE_CURRENT_REGISTER 0x05 #define LP5562_CHANNEL_WHITE_CURRENT_REGISTER 0x0F -#define LP5562_CHANNEL_RED_VALUE_REGISTER 0x04 +#define LP5562_CHANNEL_RED_VALUE_REGISTER 0x04 #define LP5562_CHANNEL_GREEN_VALUE_REGISTER 0x03 -#define LP5562_CHANNEL_BLUE_VALUE_REGISTER 0x02 +#define LP5562_CHANNEL_BLUE_VALUE_REGISTER 0x02 #define LP5562_CHANNEL_WHITE_VALUE_REGISTER 0x0E typedef enum { @@ -28,8 +28,8 @@ typedef struct { EngExec ENG3_EXEC : 2; EngExec ENG2_EXEC : 2; EngExec ENG1_EXEC : 2; - bool CHIP_EN : 1; - bool LOG_EN : 1; + bool CHIP_EN : 1; + bool LOG_EN : 1; } Reg00_Enable; typedef enum { @@ -43,39 +43,39 @@ typedef struct { EngMode ENG3_MODE : 2; EngMode ENG2_MODE : 2; EngMode ENG1_MODE : 2; - uint8_t reserved : 2; + uint8_t reserved : 2; } Reg01_OpMode; typedef struct { - bool INT_CLK_EN : 1; - bool CLK_DET_EN : 1; + bool INT_CLK_EN : 1; + bool CLK_DET_EN : 1; uint8_t reserved0 : 3; - bool PS_EN : 1; - bool PWM_HF : 1; + bool PS_EN : 1; + bool PWM_HF : 1; uint8_t reserved1 : 1; } Reg08_Config; typedef struct { - uint8_t pc : 3; + uint8_t pc : 3; uint8_t reserved : 5; } Reg09_Engine1PC; typedef struct { - uint8_t pc : 3; + uint8_t pc : 3; uint8_t reserved : 5; } Reg0A_Engine2PC; typedef struct { - uint8_t pc : 3; + uint8_t pc : 3; uint8_t reserved : 5; } Reg0B_Engine3PC; typedef struct { - bool ENG3_INT : 1; - bool ENG2_INT : 1; - bool ENG1_INT : 1; + bool ENG3_INT : 1; + bool ENG2_INT : 1; + bool ENG1_INT : 1; bool EXT_CLK_USED : 1; - uint8_t reserved : 5; + uint8_t reserved : 5; } Reg0C_Status; typedef struct { @@ -90,8 +90,8 @@ typedef enum { } EngSelect; typedef struct { - EngSelect blue : 2; + EngSelect blue : 2; EngSelect green : 2; - EngSelect red : 2; + EngSelect red : 2; EngSelect white : 2; } Reg70_LedMap; diff --git a/lib/drivers/st25r3916.h b/lib/drivers/st25r3916.h index 532239f4728..0e77b63172b 100644 --- a/lib/drivers/st25r3916.h +++ b/lib/drivers/st25r3916.h @@ -6,7 +6,7 @@ extern "C" { #endif -#define ST25R3916_IRQ_MASK_ALL (uint32_t)(0xFFFFFFFFUL) /** All ST25R3916 interrupt sources */ +#define ST25R3916_IRQ_MASK_ALL (uint32_t)(0xFFFFFFFFUL) /** All ST25R3916 interrupt sources */ #define ST25R3916_IRQ_MASK_NONE (uint32_t)(0x00000000UL) /**No ST25R3916 interrupt source */ /** Main interrupt register */ diff --git a/lib/drivers/st25r3916_reg.c b/lib/drivers/st25r3916_reg.c index 76a8827557d..f7a47d46338 100644 --- a/lib/drivers/st25r3916_reg.c +++ b/lib/drivers/st25r3916_reg.c @@ -253,5 +253,5 @@ bool st25r3916_check_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t mask, uint8_t reg_val = 0; st25r3916_read_reg(handle, reg, ®_val); - return ((reg_val & mask) == val); + return (reg_val & mask) == val; } diff --git a/lib/drivers/st25r3916_reg.h b/lib/drivers/st25r3916_reg.h index 8a924fc3929..5163c4423f8 100644 --- a/lib/drivers/st25r3916_reg.h +++ b/lib/drivers/st25r3916_reg.h @@ -9,49 +9,49 @@ extern "C" { /** ST25R3916 direct commands */ #define ST25R3916_CMD_SET_DEFAULT \ 0xC1U /** Puts the chip in default state (same as after power-up */ -#define ST25R3916_CMD_STOP 0xC2U /*!< Stops all activities and clears FIFO */ -#define ST25R3916_CMD_TRANSMIT_WITH_CRC 0xC4U /** Transmit with CRC */ +#define ST25R3916_CMD_STOP 0xC2U /*!< Stops all activities and clears FIFO */ +#define ST25R3916_CMD_TRANSMIT_WITH_CRC 0xC4U /** Transmit with CRC */ #define ST25R3916_CMD_TRANSMIT_WITHOUT_CRC 0xC5U /** Transmit without CRC */ -#define ST25R3916_CMD_TRANSMIT_REQA 0xC6U /** Transmit REQA */ -#define ST25R3916_CMD_TRANSMIT_WUPA 0xC7U /** Transmit WUPA */ +#define ST25R3916_CMD_TRANSMIT_REQA 0xC6U /** Transmit REQA */ +#define ST25R3916_CMD_TRANSMIT_WUPA 0xC7U /** Transmit WUPA */ #define ST25R3916_CMD_INITIAL_RF_COLLISION \ 0xC8U /** NFC transmit with Initial RF Collision Avoidance */ #define ST25R3916_CMD_RESPONSE_RF_COLLISION_N \ 0xC9U /** NFC transmit with Response RF Collision Avoidance */ -#define ST25R3916_CMD_GOTO_SENSE 0xCDU /** Passive target logic to Sense/Idle state */ -#define ST25R3916_CMD_GOTO_SLEEP 0xCEU /** Passive target logic to Sleep/Halt state */ -#define ST25R3916_CMD_MASK_RECEIVE_DATA 0xD0U /** Mask receive data */ +#define ST25R3916_CMD_GOTO_SENSE 0xCDU /** Passive target logic to Sense/Idle state */ +#define ST25R3916_CMD_GOTO_SLEEP 0xCEU /** Passive target logic to Sleep/Halt state */ +#define ST25R3916_CMD_MASK_RECEIVE_DATA 0xD0U /** Mask receive data */ #define ST25R3916_CMD_UNMASK_RECEIVE_DATA 0xD1U /** Unmask receive data */ #define ST25R3916_CMD_AM_MOD_STATE_CHANGE 0xD2U /** AM Modulation state change */ -#define ST25R3916_CMD_MEASURE_AMPLITUDE 0xD3U /** Measure singal amplitude on RFI inputs */ -#define ST25R3916_CMD_RESET_RXGAIN 0xD5U /** Reset RX Gain */ -#define ST25R3916_CMD_ADJUST_REGULATORS 0xD6U /** Adjust regulators */ +#define ST25R3916_CMD_MEASURE_AMPLITUDE 0xD3U /** Measure singal amplitude on RFI inputs */ +#define ST25R3916_CMD_RESET_RXGAIN 0xD5U /** Reset RX Gain */ +#define ST25R3916_CMD_ADJUST_REGULATORS 0xD6U /** Adjust regulators */ #define ST25R3916_CMD_CALIBRATE_DRIVER_TIMING \ 0xD8U /** Starts the sequence to adjust the driver timing */ -#define ST25R3916_CMD_MEASURE_PHASE 0xD9U /** Measure phase between RFO and RFI signal */ -#define ST25R3916_CMD_CLEAR_RSSI 0xDAU /** Clear RSSI bits and restart the measurement */ -#define ST25R3916_CMD_CLEAR_FIFO 0xDBU /** Clears FIFO, Collision and IRQ status */ -#define ST25R3916_CMD_TRANSPARENT_MODE 0xDCU /** Transparent mode */ -#define ST25R3916_CMD_CALIBRATE_C_SENSOR 0xDDU /** Calibrate the capacitive sensor */ -#define ST25R3916_CMD_MEASURE_CAPACITANCE 0xDEU /** Measure capacitance */ -#define ST25R3916_CMD_MEASURE_VDD 0xDFU /** Measure power supply voltage */ -#define ST25R3916_CMD_START_GP_TIMER 0xE0U /** Start the general purpose timer */ -#define ST25R3916_CMD_START_WUP_TIMER 0xE1U /** Start the wake-up timer */ +#define ST25R3916_CMD_MEASURE_PHASE 0xD9U /** Measure phase between RFO and RFI signal */ +#define ST25R3916_CMD_CLEAR_RSSI 0xDAU /** Clear RSSI bits and restart the measurement */ +#define ST25R3916_CMD_CLEAR_FIFO 0xDBU /** Clears FIFO, Collision and IRQ status */ +#define ST25R3916_CMD_TRANSPARENT_MODE 0xDCU /** Transparent mode */ +#define ST25R3916_CMD_CALIBRATE_C_SENSOR 0xDDU /** Calibrate the capacitive sensor */ +#define ST25R3916_CMD_MEASURE_CAPACITANCE 0xDEU /** Measure capacitance */ +#define ST25R3916_CMD_MEASURE_VDD 0xDFU /** Measure power supply voltage */ +#define ST25R3916_CMD_START_GP_TIMER 0xE0U /** Start the general purpose timer */ +#define ST25R3916_CMD_START_WUP_TIMER 0xE1U /** Start the wake-up timer */ #define ST25R3916_CMD_START_MASK_RECEIVE_TIMER 0xE2U /** Start the mask-receive timer */ -#define ST25R3916_CMD_START_NO_RESPONSE_TIMER 0xE3U /** Start the no-response timer */ -#define ST25R3916_CMD_START_PPON2_TIMER 0xE4U /** Start PPon2 timer */ -#define ST25R3916_CMD_STOP_NRT 0xE8U /** Stop No Response Timer */ -#define ST25R3916_CMD_SPACE_B_ACCESS 0xFBU /** Enable R/W access to the test registers */ -#define ST25R3916_CMD_TEST_ACCESS 0xFCU /** Enable R/W access to the test registers */ +#define ST25R3916_CMD_START_NO_RESPONSE_TIMER 0xE3U /** Start the no-response timer */ +#define ST25R3916_CMD_START_PPON2_TIMER 0xE4U /** Start PPon2 timer */ +#define ST25R3916_CMD_STOP_NRT 0xE8U /** Stop No Response Timer */ +#define ST25R3916_CMD_SPACE_B_ACCESS 0xFBU /** Enable R/W access to the test registers */ +#define ST25R3916_CMD_TEST_ACCESS 0xFCU /** Enable R/W access to the test registers */ -#define ST25R3916_SPACE_B 0x40U /** ST25R3916 Space-B indicator */ +#define ST25R3916_SPACE_B 0x40U /** ST25R3916 Space-B indicator */ #define ST25R3916_SPACE_B_REG_LEN 16U /** Number of register in the space B */ #define ST25R3916_FIFO_STATUS_LEN 2 /** Number of FIFO Status Register */ -#define ST25R3916_PTM_A_LEN 15U /** Passive target memory A config length */ -#define ST25R3916_PTM_B_LEN 0U /** Passive target memory B config length */ -#define ST25R3916_PTM_F_LEN 21U /** Passive target memory F config length */ +#define ST25R3916_PTM_A_LEN 15U /** Passive target memory A config length */ +#define ST25R3916_PTM_B_LEN 0U /** Passive target memory B config length */ +#define ST25R3916_PTM_F_LEN 21U /** Passive target memory F config length */ #define ST25R3916_PTM_TSN_LEN 12U /** Passive target memory TSN data length */ /** Full Passive target memory length */ @@ -64,8 +64,8 @@ extern "C" { /** Operation control and mode definition */ #define ST25R3916_REG_OP_CONTROL 0x02U /** RW Operation Control Register */ -#define ST25R3916_REG_MODE 0x03U /** RW Mode Definition Register */ -#define ST25R3916_REG_BIT_RATE 0x04U /** RW Bit Rate Definition Register */ +#define ST25R3916_REG_MODE 0x03U /** RW Mode Definition Register */ +#define ST25R3916_REG_BIT_RATE 0x04U /** RW Bit Rate Definition Register */ /** Protocol Configuration registers */ #define ST25R3916_REG_ISO14443A_NFC 0x05U /** RW ISO14443A and NFC 106 kBit/s Settings Register */ @@ -74,10 +74,10 @@ extern "C" { #define ST25R3916_REG_ISO14443B_1 0x06U /** RW ISO14443B Settings Register 1 */ #define ST25R3916_REG_SUBC_START_TIME \ (ST25R3916_SPACE_B | 0x06U) /*!< RW Subcarrier Start Time Register */ -#define ST25R3916_REG_ISO14443B_2 0x07U /** RW ISO14443B Settings Register 2 */ +#define ST25R3916_REG_ISO14443B_2 0x07U /** RW ISO14443B Settings Register 2 */ #define ST25R3916_REG_PASSIVE_TARGET 0x08U /** RW Passive Target Definition Register */ -#define ST25R3916_REG_STREAM_MODE 0x09U /** RW Stream Mode Definition Register */ -#define ST25R3916_REG_AUX 0x0AU /** RW Auxiliary Definition Register */ +#define ST25R3916_REG_STREAM_MODE 0x09U /** RW Stream Mode Definition Register */ +#define ST25R3916_REG_AUX 0x0AU /** RW Auxiliary Definition Register */ /** Receiver Configuration registers */ #define ST25R3916_REG_RX_CONF1 0x0BU /** RW Receiver Configuration Register 1 */ @@ -92,28 +92,28 @@ extern "C" { (ST25R3916_SPACE_B | 0x0DU) /** RW Correlator configuration register 2 */ /** Timer definition registers */ -#define ST25R3916_REG_MASK_RX_TIMER 0x0FU /** RW Mask Receive Timer Register */ +#define ST25R3916_REG_MASK_RX_TIMER 0x0FU /** RW Mask Receive Timer Register */ #define ST25R3916_REG_NO_RESPONSE_TIMER1 0x10U /** RW No-response Timer Register 1 */ #define ST25R3916_REG_NO_RESPONSE_TIMER2 0x11U /** RW No-response Timer Register 2 */ -#define ST25R3916_REG_TIMER_EMV_CONTROL 0x12U /** RW Timer and EMV Control */ -#define ST25R3916_REG_GPT1 0x13U /** RW General Purpose Timer Register 1 */ -#define ST25R3916_REG_GPT2 0x14U /** RW General Purpose Timer Register 2 */ -#define ST25R3916_REG_PPON2 0x15U /** RW PPON2 Field waiting Timer Register */ -#define ST25R3916_REG_SQUELCH_TIMER (ST25R3916_SPACE_B | 0x0FU) /** RW Squelch timeout Register */ -#define ST25R3916_REG_FIELD_ON_GT (ST25R3916_SPACE_B | 0x15U) /** RW NFC Field on guard time */ +#define ST25R3916_REG_TIMER_EMV_CONTROL 0x12U /** RW Timer and EMV Control */ +#define ST25R3916_REG_GPT1 0x13U /** RW General Purpose Timer Register 1 */ +#define ST25R3916_REG_GPT2 0x14U /** RW General Purpose Timer Register 2 */ +#define ST25R3916_REG_PPON2 0x15U /** RW PPON2 Field waiting Timer Register */ +#define ST25R3916_REG_SQUELCH_TIMER (ST25R3916_SPACE_B | 0x0FU) /** RW Squelch timeout Register */ +#define ST25R3916_REG_FIELD_ON_GT (ST25R3916_SPACE_B | 0x15U) /** RW NFC Field on guard time */ /** Interrupt and associated reporting registers */ -#define ST25R3916_REG_IRQ_MASK_MAIN 0x16U /** RW Mask Main Interrupt Register */ -#define ST25R3916_REG_IRQ_MASK_TIMER_NFC 0x17U /** RW Mask Timer and NFC Interrupt Register */ -#define ST25R3916_REG_IRQ_MASK_ERROR_WUP 0x18U /** RW Mask Error and Wake-up Interrupt Register */ -#define ST25R3916_REG_IRQ_MASK_TARGET 0x19U /** RW Mask 3916 Target Interrupt Register */ -#define ST25R3916_REG_IRQ_MAIN 0x1AU /** R Main Interrupt Register */ -#define ST25R3916_REG_IRQ_TIMER_NFC 0x1BU /** R Timer and NFC Interrupt Register */ -#define ST25R3916_REG_IRQ_ERROR_WUP 0x1CU /** R Error and Wake-up Interrupt Register */ -#define ST25R3916_REG_IRQ_TARGET 0x1DU /*!< R ST25R3916 Target Interrupt Register */ -#define ST25R3916_REG_FIFO_STATUS1 0x1EU /** R FIFO Status Register 1 */ -#define ST25R3916_REG_FIFO_STATUS2 0x1FU /** R FIFO Status Register 2 */ -#define ST25R3916_REG_COLLISION_STATUS 0x20U /** R Collision Display Register */ +#define ST25R3916_REG_IRQ_MASK_MAIN 0x16U /** RW Mask Main Interrupt Register */ +#define ST25R3916_REG_IRQ_MASK_TIMER_NFC 0x17U /** RW Mask Timer and NFC Interrupt Register */ +#define ST25R3916_REG_IRQ_MASK_ERROR_WUP 0x18U /** RW Mask Error and Wake-up Interrupt Register */ +#define ST25R3916_REG_IRQ_MASK_TARGET 0x19U /** RW Mask 3916 Target Interrupt Register */ +#define ST25R3916_REG_IRQ_MAIN 0x1AU /** R Main Interrupt Register */ +#define ST25R3916_REG_IRQ_TIMER_NFC 0x1BU /** R Timer and NFC Interrupt Register */ +#define ST25R3916_REG_IRQ_ERROR_WUP 0x1CU /** R Error and Wake-up Interrupt Register */ +#define ST25R3916_REG_IRQ_TARGET 0x1DU /*!< R ST25R3916 Target Interrupt Register */ +#define ST25R3916_REG_FIFO_STATUS1 0x1EU /** R FIFO Status Register 1 */ +#define ST25R3916_REG_FIFO_STATUS2 0x1FU /** R FIFO Status Register 2 */ +#define ST25R3916_REG_COLLISION_STATUS 0x20U /** R Collision Display Register */ #define ST25R3916_REG_PASSIVE_TARGET_STATUS 0x21U /** R Passive target state status */ /** Definition of number of transmitted bytes */ @@ -132,8 +132,8 @@ extern "C" { /** Antenna Driver and Modulation registers */ #define ST25R3916_REG_TX_DRIVER 0x28U /** RW TX driver register */ -#define ST25R3916_REG_PT_MOD 0x29U /** RW PT modulation Register */ -#define ST25R3916_REG_AUX_MOD (ST25R3916_SPACE_B | 0x28U) /** RW Aux Modulation setting Register */ +#define ST25R3916_REG_PT_MOD 0x29U /** RW PT modulation Register */ +#define ST25R3916_REG_AUX_MOD (ST25R3916_SPACE_B | 0x28U) /** RW Aux Modulation setting Register */ #define ST25R3916_REG_TX_DRIVER_TIMING \ (ST25R3916_SPACE_B | 0x29U) /** RW TX driver timing Register */ #define ST25R3916_REG_RES_AM_MOD \ @@ -153,11 +153,11 @@ extern "C" { (ST25R3916_SPACE_B | 0x2CU) /** R Regulator Display Register */ /** Receiver State Display Register */ -#define ST25R3916_REG_RSSI_RESULT 0x2DU /** R RSSI Display Register */ -#define ST25R3916_REG_GAIN_RED_STATE 0x2EU /** R Gain Reduction State Register */ +#define ST25R3916_REG_RSSI_RESULT 0x2DU /** R RSSI Display Register */ +#define ST25R3916_REG_GAIN_RED_STATE 0x2EU /** R Gain Reduction State Register */ #define ST25R3916_REG_CAP_SENSOR_CONTROL 0x2FU /** RW Capacitive Sensor Control Register */ -#define ST25R3916_REG_CAP_SENSOR_RESULT 0x30U /** R Capacitive Sensor Display Register */ -#define ST25R3916_REG_AUX_DISPLAY 0x31U /** R Auxiliary Display Register */ +#define ST25R3916_REG_CAP_SENSOR_RESULT 0x30U /** R Capacitive Sensor Display Register */ +#define ST25R3916_REG_AUX_DISPLAY 0x31U /** R Auxiliary Display Register */ /** Over/Undershoot Protection Configuration Registers */ #define ST25R3916_REG_OVERSHOOT_CONF1 \ @@ -180,7 +180,7 @@ extern "C" { #define ST25R3916_REG_AMPLITUDE_MEASURE_RESULT \ 0x36U /** R Amplitude Measurement Display Register */ #define ST25R3916_REG_PHASE_MEASURE_CONF 0x37U /** RW Phase Measurement Configuration Register */ -#define ST25R3916_REG_PHASE_MEASURE_REF 0x38U /** RW Phase Measurement Reference Register */ +#define ST25R3916_REG_PHASE_MEASURE_REF 0x38U /** RW Phase Measurement Reference Register */ #define ST25R3916_REG_PHASE_MEASURE_AA_RESULT \ 0x39U /** R Phase Measurement Auto Averaging Display */ #define ST25R3916_REG_PHASE_MEASURE_RESULT 0x3AU /** R Phase Measurement Display Register */ @@ -198,304 +198,304 @@ extern "C" { /** Register bit definitions */ -#define ST25R3916_REG_IO_CONF1_single (1U << 7) -#define ST25R3916_REG_IO_CONF1_rfo2 (1U << 6) -#define ST25R3916_REG_IO_CONF1_i2c_thd1 (1U << 5) -#define ST25R3916_REG_IO_CONF1_i2c_thd0 (1U << 4) -#define ST25R3916_REG_IO_CONF1_i2c_thd_mask (3U << 4) -#define ST25R3916_REG_IO_CONF1_i2c_thd_shift (4U) -#define ST25R3916_REG_IO_CONF1_rfu (1U << 3) -#define ST25R3916_REG_IO_CONF1_out_cl1 (1U << 2) -#define ST25R3916_REG_IO_CONF1_out_cl0 (1U << 1) +#define ST25R3916_REG_IO_CONF1_single (1U << 7) +#define ST25R3916_REG_IO_CONF1_rfo2 (1U << 6) +#define ST25R3916_REG_IO_CONF1_i2c_thd1 (1U << 5) +#define ST25R3916_REG_IO_CONF1_i2c_thd0 (1U << 4) +#define ST25R3916_REG_IO_CONF1_i2c_thd_mask (3U << 4) +#define ST25R3916_REG_IO_CONF1_i2c_thd_shift (4U) +#define ST25R3916_REG_IO_CONF1_rfu (1U << 3) +#define ST25R3916_REG_IO_CONF1_out_cl1 (1U << 2) +#define ST25R3916_REG_IO_CONF1_out_cl0 (1U << 1) #define ST25R3916_REG_IO_CONF1_out_cl_disabled (3U << 1) #define ST25R3916_REG_IO_CONF1_out_cl_13_56MHZ (2U << 1) -#define ST25R3916_REG_IO_CONF1_out_cl_4_78MHZ (1U << 1) -#define ST25R3916_REG_IO_CONF1_out_cl_3_39MHZ (0U << 1) -#define ST25R3916_REG_IO_CONF1_out_cl_mask (3U << 1) -#define ST25R3916_REG_IO_CONF1_out_cl_shift (1U) -#define ST25R3916_REG_IO_CONF1_lf_clk_off (1U << 0) -#define ST25R3916_REG_IO_CONF1_lf_clk_off_on (1U << 0) -#define ST25R3916_REG_IO_CONF1_lf_clk_off_off (0U << 0) - -#define ST25R3916_REG_IO_CONF2_sup3V (1U << 7) -#define ST25R3916_REG_IO_CONF2_sup3V_3V (1U << 7) -#define ST25R3916_REG_IO_CONF2_sup3V_5V (0U << 7) -#define ST25R3916_REG_IO_CONF2_vspd_off (1U << 6) -#define ST25R3916_REG_IO_CONF2_aat_en (1U << 5) -#define ST25R3916_REG_IO_CONF2_miso_pd2 (1U << 4) -#define ST25R3916_REG_IO_CONF2_miso_pd1 (1U << 3) +#define ST25R3916_REG_IO_CONF1_out_cl_4_78MHZ (1U << 1) +#define ST25R3916_REG_IO_CONF1_out_cl_3_39MHZ (0U << 1) +#define ST25R3916_REG_IO_CONF1_out_cl_mask (3U << 1) +#define ST25R3916_REG_IO_CONF1_out_cl_shift (1U) +#define ST25R3916_REG_IO_CONF1_lf_clk_off (1U << 0) +#define ST25R3916_REG_IO_CONF1_lf_clk_off_on (1U << 0) +#define ST25R3916_REG_IO_CONF1_lf_clk_off_off (0U << 0) + +#define ST25R3916_REG_IO_CONF2_sup3V (1U << 7) +#define ST25R3916_REG_IO_CONF2_sup3V_3V (1U << 7) +#define ST25R3916_REG_IO_CONF2_sup3V_5V (0U << 7) +#define ST25R3916_REG_IO_CONF2_vspd_off (1U << 6) +#define ST25R3916_REG_IO_CONF2_aat_en (1U << 5) +#define ST25R3916_REG_IO_CONF2_miso_pd2 (1U << 4) +#define ST25R3916_REG_IO_CONF2_miso_pd1 (1U << 3) #define ST25R3916_REG_IO_CONF2_io_drv_lvl (1U << 2) -#define ST25R3916_REG_IO_CONF2_slow_up (1U << 0) - -#define ST25R3916_REG_OP_CONTROL_en (1U << 7) -#define ST25R3916_REG_OP_CONTROL_rx_en (1U << 6) -#define ST25R3916_REG_OP_CONTROL_rx_chn (1U << 5) -#define ST25R3916_REG_OP_CONTROL_rx_man (1U << 4) -#define ST25R3916_REG_OP_CONTROL_tx_en (1U << 3) -#define ST25R3916_REG_OP_CONTROL_wu (1U << 2) -#define ST25R3916_REG_OP_CONTROL_en_fd_c1 (1U << 1) -#define ST25R3916_REG_OP_CONTROL_en_fd_c0 (1U << 0) -#define ST25R3916_REG_OP_CONTROL_en_fd_efd_off (0U << 0) -#define ST25R3916_REG_OP_CONTROL_en_fd_manual_efd_ca (1U << 0) +#define ST25R3916_REG_IO_CONF2_slow_up (1U << 0) + +#define ST25R3916_REG_OP_CONTROL_en (1U << 7) +#define ST25R3916_REG_OP_CONTROL_rx_en (1U << 6) +#define ST25R3916_REG_OP_CONTROL_rx_chn (1U << 5) +#define ST25R3916_REG_OP_CONTROL_rx_man (1U << 4) +#define ST25R3916_REG_OP_CONTROL_tx_en (1U << 3) +#define ST25R3916_REG_OP_CONTROL_wu (1U << 2) +#define ST25R3916_REG_OP_CONTROL_en_fd_c1 (1U << 1) +#define ST25R3916_REG_OP_CONTROL_en_fd_c0 (1U << 0) +#define ST25R3916_REG_OP_CONTROL_en_fd_efd_off (0U << 0) +#define ST25R3916_REG_OP_CONTROL_en_fd_manual_efd_ca (1U << 0) #define ST25R3916_REG_OP_CONTROL_en_fd_manual_efd_pdt (2U << 0) -#define ST25R3916_REG_OP_CONTROL_en_fd_auto_efd (3U << 0) -#define ST25R3916_REG_OP_CONTROL_en_fd_shift (0U) -#define ST25R3916_REG_OP_CONTROL_en_fd_mask (3U << 0) - -#define ST25R3916_REG_MODE_targ (1U << 7) -#define ST25R3916_REG_MODE_targ_targ (1U << 7) -#define ST25R3916_REG_MODE_targ_init (0U << 7) -#define ST25R3916_REG_MODE_om3 (1U << 6) -#define ST25R3916_REG_MODE_om2 (1U << 5) -#define ST25R3916_REG_MODE_om1 (1U << 4) -#define ST25R3916_REG_MODE_om0 (1U << 3) -#define ST25R3916_REG_MODE_om_bpsk_stream (0xfU << 3) +#define ST25R3916_REG_OP_CONTROL_en_fd_auto_efd (3U << 0) +#define ST25R3916_REG_OP_CONTROL_en_fd_shift (0U) +#define ST25R3916_REG_OP_CONTROL_en_fd_mask (3U << 0) + +#define ST25R3916_REG_MODE_targ (1U << 7) +#define ST25R3916_REG_MODE_targ_targ (1U << 7) +#define ST25R3916_REG_MODE_targ_init (0U << 7) +#define ST25R3916_REG_MODE_om3 (1U << 6) +#define ST25R3916_REG_MODE_om2 (1U << 5) +#define ST25R3916_REG_MODE_om1 (1U << 4) +#define ST25R3916_REG_MODE_om0 (1U << 3) +#define ST25R3916_REG_MODE_om_bpsk_stream (0xfU << 3) #define ST25R3916_REG_MODE_om_subcarrier_stream (0xeU << 3) -#define ST25R3916_REG_MODE_om_topaz (0x4U << 3) -#define ST25R3916_REG_MODE_om_felica (0x3U << 3) -#define ST25R3916_REG_MODE_om_iso14443b (0x2U << 3) -#define ST25R3916_REG_MODE_om_iso14443a (0x1U << 3) -#define ST25R3916_REG_MODE_om_targ_nfca (0x1U << 3) -#define ST25R3916_REG_MODE_om_targ_nfcb (0x2U << 3) -#define ST25R3916_REG_MODE_om_targ_nfcf (0x4U << 3) -#define ST25R3916_REG_MODE_om_targ_nfcip (0x7U << 3) -#define ST25R3916_REG_MODE_om_nfc (0x0U << 3) -#define ST25R3916_REG_MODE_om_mask (0xfU << 3) -#define ST25R3916_REG_MODE_om_shift (3U) -#define ST25R3916_REG_MODE_tr_am (1U << 2) -#define ST25R3916_REG_MODE_tr_am_ook (0U << 2) -#define ST25R3916_REG_MODE_tr_am_am (1U << 2) -#define ST25R3916_REG_MODE_nfc_ar1 (1U << 1) -#define ST25R3916_REG_MODE_nfc_ar0 (1U << 0) -#define ST25R3916_REG_MODE_nfc_ar_off (0U << 0) -#define ST25R3916_REG_MODE_nfc_ar_auto_rx (1U << 0) -#define ST25R3916_REG_MODE_nfc_ar_eof (2U << 0) -#define ST25R3916_REG_MODE_nfc_ar_rfu (3U << 0) -#define ST25R3916_REG_MODE_nfc_ar_mask (3U << 0) -#define ST25R3916_REG_MODE_nfc_ar_shift (0U) - -#define ST25R3916_REG_BIT_RATE_txrate_106 (0x0U << 4) -#define ST25R3916_REG_BIT_RATE_txrate_212 (0x1U << 4) -#define ST25R3916_REG_BIT_RATE_txrate_424 (0x2U << 4) -#define ST25R3916_REG_BIT_RATE_txrate_848 (0x3U << 4) -#define ST25R3916_REG_BIT_RATE_txrate_mask (0x3U << 4) +#define ST25R3916_REG_MODE_om_topaz (0x4U << 3) +#define ST25R3916_REG_MODE_om_felica (0x3U << 3) +#define ST25R3916_REG_MODE_om_iso14443b (0x2U << 3) +#define ST25R3916_REG_MODE_om_iso14443a (0x1U << 3) +#define ST25R3916_REG_MODE_om_targ_nfca (0x1U << 3) +#define ST25R3916_REG_MODE_om_targ_nfcb (0x2U << 3) +#define ST25R3916_REG_MODE_om_targ_nfcf (0x4U << 3) +#define ST25R3916_REG_MODE_om_targ_nfcip (0x7U << 3) +#define ST25R3916_REG_MODE_om_nfc (0x0U << 3) +#define ST25R3916_REG_MODE_om_mask (0xfU << 3) +#define ST25R3916_REG_MODE_om_shift (3U) +#define ST25R3916_REG_MODE_tr_am (1U << 2) +#define ST25R3916_REG_MODE_tr_am_ook (0U << 2) +#define ST25R3916_REG_MODE_tr_am_am (1U << 2) +#define ST25R3916_REG_MODE_nfc_ar1 (1U << 1) +#define ST25R3916_REG_MODE_nfc_ar0 (1U << 0) +#define ST25R3916_REG_MODE_nfc_ar_off (0U << 0) +#define ST25R3916_REG_MODE_nfc_ar_auto_rx (1U << 0) +#define ST25R3916_REG_MODE_nfc_ar_eof (2U << 0) +#define ST25R3916_REG_MODE_nfc_ar_rfu (3U << 0) +#define ST25R3916_REG_MODE_nfc_ar_mask (3U << 0) +#define ST25R3916_REG_MODE_nfc_ar_shift (0U) + +#define ST25R3916_REG_BIT_RATE_txrate_106 (0x0U << 4) +#define ST25R3916_REG_BIT_RATE_txrate_212 (0x1U << 4) +#define ST25R3916_REG_BIT_RATE_txrate_424 (0x2U << 4) +#define ST25R3916_REG_BIT_RATE_txrate_848 (0x3U << 4) +#define ST25R3916_REG_BIT_RATE_txrate_mask (0x3U << 4) #define ST25R3916_REG_BIT_RATE_txrate_shift (4U) -#define ST25R3916_REG_BIT_RATE_rxrate_106 (0x0U << 0) -#define ST25R3916_REG_BIT_RATE_rxrate_212 (0x1U << 0) -#define ST25R3916_REG_BIT_RATE_rxrate_424 (0x2U << 0) -#define ST25R3916_REG_BIT_RATE_rxrate_848 (0x3U << 0) -#define ST25R3916_REG_BIT_RATE_rxrate_mask (0x3U << 0) +#define ST25R3916_REG_BIT_RATE_rxrate_106 (0x0U << 0) +#define ST25R3916_REG_BIT_RATE_rxrate_212 (0x1U << 0) +#define ST25R3916_REG_BIT_RATE_rxrate_424 (0x2U << 0) +#define ST25R3916_REG_BIT_RATE_rxrate_848 (0x3U << 0) +#define ST25R3916_REG_BIT_RATE_rxrate_mask (0x3U << 0) #define ST25R3916_REG_BIT_RATE_rxrate_shift (0U) -#define ST25R3916_REG_ISO14443A_NFC_no_tx_par (1U << 7) +#define ST25R3916_REG_ISO14443A_NFC_no_tx_par (1U << 7) #define ST25R3916_REG_ISO14443A_NFC_no_tx_par_off (0U << 7) -#define ST25R3916_REG_ISO14443A_NFC_no_rx_par (1U << 6) +#define ST25R3916_REG_ISO14443A_NFC_no_rx_par (1U << 6) #define ST25R3916_REG_ISO14443A_NFC_no_rx_par_off (0U << 6) -#define ST25R3916_REG_ISO14443A_NFC_nfc_f0 (1U << 5) -#define ST25R3916_REG_ISO14443A_NFC_nfc_f0_off (0U << 5) -#define ST25R3916_REG_ISO14443A_NFC_p_len3 (1U << 4) -#define ST25R3916_REG_ISO14443A_NFC_p_len2 (1U << 3) -#define ST25R3916_REG_ISO14443A_NFC_p_len1 (1U << 2) -#define ST25R3916_REG_ISO14443A_NFC_p_len0 (1U << 1) -#define ST25R3916_REG_ISO14443A_NFC_p_len_mask (0xfU << 1) -#define ST25R3916_REG_ISO14443A_NFC_p_len_shift (1U) -#define ST25R3916_REG_ISO14443A_NFC_antcl (1U << 0) - -#define ST25R3916_REG_EMD_SUP_CONF_emd_emv (1U << 7) -#define ST25R3916_REG_EMD_SUP_CONF_emd_emv_on (1U << 7) -#define ST25R3916_REG_EMD_SUP_CONF_emd_emv_off (0U << 7) -#define ST25R3916_REG_EMD_SUP_CONF_rx_start_emv (1U << 6) -#define ST25R3916_REG_EMD_SUP_CONF_rx_start_emv_on (1U << 6) +#define ST25R3916_REG_ISO14443A_NFC_nfc_f0 (1U << 5) +#define ST25R3916_REG_ISO14443A_NFC_nfc_f0_off (0U << 5) +#define ST25R3916_REG_ISO14443A_NFC_p_len3 (1U << 4) +#define ST25R3916_REG_ISO14443A_NFC_p_len2 (1U << 3) +#define ST25R3916_REG_ISO14443A_NFC_p_len1 (1U << 2) +#define ST25R3916_REG_ISO14443A_NFC_p_len0 (1U << 1) +#define ST25R3916_REG_ISO14443A_NFC_p_len_mask (0xfU << 1) +#define ST25R3916_REG_ISO14443A_NFC_p_len_shift (1U) +#define ST25R3916_REG_ISO14443A_NFC_antcl (1U << 0) + +#define ST25R3916_REG_EMD_SUP_CONF_emd_emv (1U << 7) +#define ST25R3916_REG_EMD_SUP_CONF_emd_emv_on (1U << 7) +#define ST25R3916_REG_EMD_SUP_CONF_emd_emv_off (0U << 7) +#define ST25R3916_REG_EMD_SUP_CONF_rx_start_emv (1U << 6) +#define ST25R3916_REG_EMD_SUP_CONF_rx_start_emv_on (1U << 6) #define ST25R3916_REG_EMD_SUP_CONF_rx_start_emv_off (0U << 6) -#define ST25R3916_REG_EMD_SUP_CONF_rfu1 (1U << 5) -#define ST25R3916_REG_EMD_SUP_CONF_rfu0 (1U << 4) -#define ST25R3916_REG_EMD_SUP_CONF_emd_thld3 (1U << 3) -#define ST25R3916_REG_EMD_SUP_CONF_emd_thld2 (1U << 2) -#define ST25R3916_REG_EMD_SUP_CONF_emd_thld1 (1U << 1) -#define ST25R3916_REG_EMD_SUP_CONF_emd_thld0 (1U << 0) -#define ST25R3916_REG_EMD_SUP_CONF_emd_thld_mask (0xfU << 0) -#define ST25R3916_REG_EMD_SUP_CONF_emd_thld_shift (0U) - -#define ST25R3916_REG_SUBC_START_TIME_rfu2 (1U << 7) -#define ST25R3916_REG_SUBC_START_TIME_rfu1 (1U << 6) -#define ST25R3916_REG_SUBC_START_TIME_rfu0 (1U << 5) -#define ST25R3916_REG_SUBC_START_TIME_sst4 (1U << 4) -#define ST25R3916_REG_SUBC_START_TIME_sst3 (1U << 3) -#define ST25R3916_REG_SUBC_START_TIME_sst2 (1U << 2) -#define ST25R3916_REG_SUBC_START_TIME_sst1 (1U << 1) -#define ST25R3916_REG_SUBC_START_TIME_sst0 (1U << 0) -#define ST25R3916_REG_SUBC_START_TIME_sst_mask (0x1fU << 0) +#define ST25R3916_REG_EMD_SUP_CONF_rfu1 (1U << 5) +#define ST25R3916_REG_EMD_SUP_CONF_rfu0 (1U << 4) +#define ST25R3916_REG_EMD_SUP_CONF_emd_thld3 (1U << 3) +#define ST25R3916_REG_EMD_SUP_CONF_emd_thld2 (1U << 2) +#define ST25R3916_REG_EMD_SUP_CONF_emd_thld1 (1U << 1) +#define ST25R3916_REG_EMD_SUP_CONF_emd_thld0 (1U << 0) +#define ST25R3916_REG_EMD_SUP_CONF_emd_thld_mask (0xfU << 0) +#define ST25R3916_REG_EMD_SUP_CONF_emd_thld_shift (0U) + +#define ST25R3916_REG_SUBC_START_TIME_rfu2 (1U << 7) +#define ST25R3916_REG_SUBC_START_TIME_rfu1 (1U << 6) +#define ST25R3916_REG_SUBC_START_TIME_rfu0 (1U << 5) +#define ST25R3916_REG_SUBC_START_TIME_sst4 (1U << 4) +#define ST25R3916_REG_SUBC_START_TIME_sst3 (1U << 3) +#define ST25R3916_REG_SUBC_START_TIME_sst2 (1U << 2) +#define ST25R3916_REG_SUBC_START_TIME_sst1 (1U << 1) +#define ST25R3916_REG_SUBC_START_TIME_sst0 (1U << 0) +#define ST25R3916_REG_SUBC_START_TIME_sst_mask (0x1fU << 0) #define ST25R3916_REG_SUBC_START_TIME_sst_shift (0U) -#define ST25R3916_REG_ISO14443B_1_egt2 (1U << 7) -#define ST25R3916_REG_ISO14443B_1_egt1 (1U << 6) -#define ST25R3916_REG_ISO14443B_1_egt0 (1U << 5) -#define ST25R3916_REG_ISO14443B_1_egt_shift (5U) -#define ST25R3916_REG_ISO14443B_1_egt_mask (7U << 5) -#define ST25R3916_REG_ISO14443B_1_sof_1 (1U << 3) -#define ST25R3916_REG_ISO14443B_1_sof_1_3etu (1U << 3) -#define ST25R3916_REG_ISO14443B_1_sof_1_2etu (0U << 3) -#define ST25R3916_REG_ISO14443B_1_sof_0 (1U << 4) +#define ST25R3916_REG_ISO14443B_1_egt2 (1U << 7) +#define ST25R3916_REG_ISO14443B_1_egt1 (1U << 6) +#define ST25R3916_REG_ISO14443B_1_egt0 (1U << 5) +#define ST25R3916_REG_ISO14443B_1_egt_shift (5U) +#define ST25R3916_REG_ISO14443B_1_egt_mask (7U << 5) +#define ST25R3916_REG_ISO14443B_1_sof_1 (1U << 3) +#define ST25R3916_REG_ISO14443B_1_sof_1_3etu (1U << 3) +#define ST25R3916_REG_ISO14443B_1_sof_1_2etu (0U << 3) +#define ST25R3916_REG_ISO14443B_1_sof_0 (1U << 4) #define ST25R3916_REG_ISO14443B_1_sof_0_11etu (1U << 4) #define ST25R3916_REG_ISO14443B_1_sof_0_10etu (0U << 4) -#define ST25R3916_REG_ISO14443B_1_sof_mask (3U << 3) -#define ST25R3916_REG_ISO14443B_1_eof (1U << 2) -#define ST25R3916_REG_ISO14443B_1_eof_11etu (1U << 2) -#define ST25R3916_REG_ISO14443B_1_eof_10etu (0U << 2) -#define ST25R3916_REG_ISO14443B_1_half (1U << 1) -#define ST25R3916_REG_ISO14443B_1_rx_st_om (1U << 0) - -#define ST25R3916_REG_ISO14443B_2_tr1_1 (1U << 7) -#define ST25R3916_REG_ISO14443B_2_tr1_0 (1U << 6) +#define ST25R3916_REG_ISO14443B_1_sof_mask (3U << 3) +#define ST25R3916_REG_ISO14443B_1_eof (1U << 2) +#define ST25R3916_REG_ISO14443B_1_eof_11etu (1U << 2) +#define ST25R3916_REG_ISO14443B_1_eof_10etu (0U << 2) +#define ST25R3916_REG_ISO14443B_1_half (1U << 1) +#define ST25R3916_REG_ISO14443B_1_rx_st_om (1U << 0) + +#define ST25R3916_REG_ISO14443B_2_tr1_1 (1U << 7) +#define ST25R3916_REG_ISO14443B_2_tr1_0 (1U << 6) #define ST25R3916_REG_ISO14443B_2_tr1_64fs32fs (1U << 6) #define ST25R3916_REG_ISO14443B_2_tr1_80fs80fs (0U << 6) -#define ST25R3916_REG_ISO14443B_2_tr1_mask (3U << 6) -#define ST25R3916_REG_ISO14443B_2_tr1_shift (6U) -#define ST25R3916_REG_ISO14443B_2_no_sof (1U << 5) -#define ST25R3916_REG_ISO14443B_2_no_eof (1U << 4) -#define ST25R3916_REG_ISO14443B_rfu1 (1U << 3) -#define ST25R3916_REG_ISO14443B_rfu0 (1U << 2) -#define ST25R3916_REG_ISO14443B_2_f_p1 (1U << 1) -#define ST25R3916_REG_ISO14443B_2_f_p0 (1U << 0) -#define ST25R3916_REG_ISO14443B_2_f_p_96 (3U << 0) -#define ST25R3916_REG_ISO14443B_2_f_p_80 (2U << 0) -#define ST25R3916_REG_ISO14443B_2_f_p_64 (1U << 0) -#define ST25R3916_REG_ISO14443B_2_f_p_48 (0U << 0) -#define ST25R3916_REG_ISO14443B_2_f_p_mask (3U << 0) -#define ST25R3916_REG_ISO14443B_2_f_p_shift (0U) - -#define ST25R3916_REG_PASSIVE_TARGET_fdel_3 (1U << 7) -#define ST25R3916_REG_PASSIVE_TARGET_fdel_2 (1U << 6) -#define ST25R3916_REG_PASSIVE_TARGET_fdel_1 (1U << 5) -#define ST25R3916_REG_PASSIVE_TARGET_fdel_0 (1U << 4) -#define ST25R3916_REG_PASSIVE_TARGET_fdel_mask (0xfU << 4) -#define ST25R3916_REG_PASSIVE_TARGET_fdel_shift (4U) -#define ST25R3916_REG_PASSIVE_TARGET_d_ac_ap2p (1U << 3) +#define ST25R3916_REG_ISO14443B_2_tr1_mask (3U << 6) +#define ST25R3916_REG_ISO14443B_2_tr1_shift (6U) +#define ST25R3916_REG_ISO14443B_2_no_sof (1U << 5) +#define ST25R3916_REG_ISO14443B_2_no_eof (1U << 4) +#define ST25R3916_REG_ISO14443B_rfu1 (1U << 3) +#define ST25R3916_REG_ISO14443B_rfu0 (1U << 2) +#define ST25R3916_REG_ISO14443B_2_f_p1 (1U << 1) +#define ST25R3916_REG_ISO14443B_2_f_p0 (1U << 0) +#define ST25R3916_REG_ISO14443B_2_f_p_96 (3U << 0) +#define ST25R3916_REG_ISO14443B_2_f_p_80 (2U << 0) +#define ST25R3916_REG_ISO14443B_2_f_p_64 (1U << 0) +#define ST25R3916_REG_ISO14443B_2_f_p_48 (0U << 0) +#define ST25R3916_REG_ISO14443B_2_f_p_mask (3U << 0) +#define ST25R3916_REG_ISO14443B_2_f_p_shift (0U) + +#define ST25R3916_REG_PASSIVE_TARGET_fdel_3 (1U << 7) +#define ST25R3916_REG_PASSIVE_TARGET_fdel_2 (1U << 6) +#define ST25R3916_REG_PASSIVE_TARGET_fdel_1 (1U << 5) +#define ST25R3916_REG_PASSIVE_TARGET_fdel_0 (1U << 4) +#define ST25R3916_REG_PASSIVE_TARGET_fdel_mask (0xfU << 4) +#define ST25R3916_REG_PASSIVE_TARGET_fdel_shift (4U) +#define ST25R3916_REG_PASSIVE_TARGET_d_ac_ap2p (1U << 3) #define ST25R3916_REG_PASSIVE_TARGET_d_212_424_1r (1U << 2) -#define ST25R3916_REG_PASSIVE_TARGET_rfu (1U << 1) -#define ST25R3916_REG_PASSIVE_TARGET_d_106_ac_a (1U << 0) - -#define ST25R3916_REG_STREAM_MODE_rfu (1U << 7) -#define ST25R3916_REG_STREAM_MODE_scf1 (1U << 6) -#define ST25R3916_REG_STREAM_MODE_scf0 (1U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_sc212 (0U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_sc424 (1U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_sc848 (2U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_sc1695 (3U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_bpsk848 (0U << 5) +#define ST25R3916_REG_PASSIVE_TARGET_rfu (1U << 1) +#define ST25R3916_REG_PASSIVE_TARGET_d_106_ac_a (1U << 0) + +#define ST25R3916_REG_STREAM_MODE_rfu (1U << 7) +#define ST25R3916_REG_STREAM_MODE_scf1 (1U << 6) +#define ST25R3916_REG_STREAM_MODE_scf0 (1U << 5) +#define ST25R3916_REG_STREAM_MODE_scf_sc212 (0U << 5) +#define ST25R3916_REG_STREAM_MODE_scf_sc424 (1U << 5) +#define ST25R3916_REG_STREAM_MODE_scf_sc848 (2U << 5) +#define ST25R3916_REG_STREAM_MODE_scf_sc1695 (3U << 5) +#define ST25R3916_REG_STREAM_MODE_scf_bpsk848 (0U << 5) #define ST25R3916_REG_STREAM_MODE_scf_bpsk1695 (1U << 5) #define ST25R3916_REG_STREAM_MODE_scf_bpsk3390 (2U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_bpsk106 (3U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_mask (3U << 5) -#define ST25R3916_REG_STREAM_MODE_scf_shift (5U) -#define ST25R3916_REG_STREAM_MODE_scp1 (1U << 4) -#define ST25R3916_REG_STREAM_MODE_scp0 (1U << 3) -#define ST25R3916_REG_STREAM_MODE_scp_1pulse (0U << 3) -#define ST25R3916_REG_STREAM_MODE_scp_2pulses (1U << 3) -#define ST25R3916_REG_STREAM_MODE_scp_4pulses (2U << 3) -#define ST25R3916_REG_STREAM_MODE_scp_8pulses (3U << 3) -#define ST25R3916_REG_STREAM_MODE_scp_mask (3U << 3) -#define ST25R3916_REG_STREAM_MODE_scp_shift (3U) -#define ST25R3916_REG_STREAM_MODE_stx2 (1U << 2) -#define ST25R3916_REG_STREAM_MODE_stx1 (1U << 1) -#define ST25R3916_REG_STREAM_MODE_stx0 (1U << 0) -#define ST25R3916_REG_STREAM_MODE_stx_106 (0U << 0) -#define ST25R3916_REG_STREAM_MODE_stx_212 (1U << 0) -#define ST25R3916_REG_STREAM_MODE_stx_424 (2U << 0) -#define ST25R3916_REG_STREAM_MODE_stx_848 (3U << 0) -#define ST25R3916_REG_STREAM_MODE_stx_mask (7U << 0) -#define ST25R3916_REG_STREAM_MODE_stx_shift (0U) - -#define ST25R3916_REG_AUX_no_crc_rx (1U << 7) -#define ST25R3916_REG_AUX_rfu (1U << 6) -#define ST25R3916_REG_AUX_nfc_id1 (1U << 5) -#define ST25R3916_REG_AUX_nfc_id0 (1U << 4) -#define ST25R3916_REG_AUX_nfc_id_7bytes (1U << 4) -#define ST25R3916_REG_AUX_nfc_id_4bytes (0U << 4) -#define ST25R3916_REG_AUX_nfc_id_mask (3U << 4) -#define ST25R3916_REG_AUX_nfc_id_shift (4U) -#define ST25R3916_REG_AUX_mfaz_cl90 (1U << 3) -#define ST25R3916_REG_AUX_dis_corr (1U << 2) -#define ST25R3916_REG_AUX_dis_corr_coherent (1U << 2) +#define ST25R3916_REG_STREAM_MODE_scf_bpsk106 (3U << 5) +#define ST25R3916_REG_STREAM_MODE_scf_mask (3U << 5) +#define ST25R3916_REG_STREAM_MODE_scf_shift (5U) +#define ST25R3916_REG_STREAM_MODE_scp1 (1U << 4) +#define ST25R3916_REG_STREAM_MODE_scp0 (1U << 3) +#define ST25R3916_REG_STREAM_MODE_scp_1pulse (0U << 3) +#define ST25R3916_REG_STREAM_MODE_scp_2pulses (1U << 3) +#define ST25R3916_REG_STREAM_MODE_scp_4pulses (2U << 3) +#define ST25R3916_REG_STREAM_MODE_scp_8pulses (3U << 3) +#define ST25R3916_REG_STREAM_MODE_scp_mask (3U << 3) +#define ST25R3916_REG_STREAM_MODE_scp_shift (3U) +#define ST25R3916_REG_STREAM_MODE_stx2 (1U << 2) +#define ST25R3916_REG_STREAM_MODE_stx1 (1U << 1) +#define ST25R3916_REG_STREAM_MODE_stx0 (1U << 0) +#define ST25R3916_REG_STREAM_MODE_stx_106 (0U << 0) +#define ST25R3916_REG_STREAM_MODE_stx_212 (1U << 0) +#define ST25R3916_REG_STREAM_MODE_stx_424 (2U << 0) +#define ST25R3916_REG_STREAM_MODE_stx_848 (3U << 0) +#define ST25R3916_REG_STREAM_MODE_stx_mask (7U << 0) +#define ST25R3916_REG_STREAM_MODE_stx_shift (0U) + +#define ST25R3916_REG_AUX_no_crc_rx (1U << 7) +#define ST25R3916_REG_AUX_rfu (1U << 6) +#define ST25R3916_REG_AUX_nfc_id1 (1U << 5) +#define ST25R3916_REG_AUX_nfc_id0 (1U << 4) +#define ST25R3916_REG_AUX_nfc_id_7bytes (1U << 4) +#define ST25R3916_REG_AUX_nfc_id_4bytes (0U << 4) +#define ST25R3916_REG_AUX_nfc_id_mask (3U << 4) +#define ST25R3916_REG_AUX_nfc_id_shift (4U) +#define ST25R3916_REG_AUX_mfaz_cl90 (1U << 3) +#define ST25R3916_REG_AUX_dis_corr (1U << 2) +#define ST25R3916_REG_AUX_dis_corr_coherent (1U << 2) #define ST25R3916_REG_AUX_dis_corr_correlator (0U << 2) -#define ST25R3916_REG_AUX_nfc_n1 (1U << 1) -#define ST25R3916_REG_AUX_nfc_n0 (1U << 0) -#define ST25R3916_REG_AUX_nfc_n_mask (3U << 0) -#define ST25R3916_REG_AUX_nfc_n_shift (0U) - -#define ST25R3916_REG_RX_CONF1_ch_sel (1U << 7) -#define ST25R3916_REG_RX_CONF1_ch_sel_PM (1U << 7) -#define ST25R3916_REG_RX_CONF1_ch_sel_AM (0U << 7) -#define ST25R3916_REG_RX_CONF1_lp2 (1U << 6) -#define ST25R3916_REG_RX_CONF1_lp1 (1U << 5) -#define ST25R3916_REG_RX_CONF1_lp0 (1U << 4) -#define ST25R3916_REG_RX_CONF1_lp_1200khz (0U << 4) -#define ST25R3916_REG_RX_CONF1_lp_600khz (1U << 4) -#define ST25R3916_REG_RX_CONF1_lp_300khz (2U << 4) -#define ST25R3916_REG_RX_CONF1_lp_2000khz (4U << 4) -#define ST25R3916_REG_RX_CONF1_lp_7000khz (5U << 4) -#define ST25R3916_REG_RX_CONF1_lp_mask (7U << 4) -#define ST25R3916_REG_RX_CONF1_lp_shift (4U) -#define ST25R3916_REG_RX_CONF1_z600k (1U << 3) -#define ST25R3916_REG_RX_CONF1_h200 (1U << 2) -#define ST25R3916_REG_RX_CONF1_h80 (1U << 1) -#define ST25R3916_REG_RX_CONF1_z12k (1U << 0) -#define ST25R3916_REG_RX_CONF1_hz_60_400khz (0U << 0) -#define ST25R3916_REG_RX_CONF1_hz_60_200khz (4U << 0) -#define ST25R3916_REG_RX_CONF1_hz_40_80khz (2U << 0) -#define ST25R3916_REG_RX_CONF1_hz_12_200khz (1U << 0) -#define ST25R3916_REG_RX_CONF1_hz_12_80khz (3U << 0) +#define ST25R3916_REG_AUX_nfc_n1 (1U << 1) +#define ST25R3916_REG_AUX_nfc_n0 (1U << 0) +#define ST25R3916_REG_AUX_nfc_n_mask (3U << 0) +#define ST25R3916_REG_AUX_nfc_n_shift (0U) + +#define ST25R3916_REG_RX_CONF1_ch_sel (1U << 7) +#define ST25R3916_REG_RX_CONF1_ch_sel_PM (1U << 7) +#define ST25R3916_REG_RX_CONF1_ch_sel_AM (0U << 7) +#define ST25R3916_REG_RX_CONF1_lp2 (1U << 6) +#define ST25R3916_REG_RX_CONF1_lp1 (1U << 5) +#define ST25R3916_REG_RX_CONF1_lp0 (1U << 4) +#define ST25R3916_REG_RX_CONF1_lp_1200khz (0U << 4) +#define ST25R3916_REG_RX_CONF1_lp_600khz (1U << 4) +#define ST25R3916_REG_RX_CONF1_lp_300khz (2U << 4) +#define ST25R3916_REG_RX_CONF1_lp_2000khz (4U << 4) +#define ST25R3916_REG_RX_CONF1_lp_7000khz (5U << 4) +#define ST25R3916_REG_RX_CONF1_lp_mask (7U << 4) +#define ST25R3916_REG_RX_CONF1_lp_shift (4U) +#define ST25R3916_REG_RX_CONF1_z600k (1U << 3) +#define ST25R3916_REG_RX_CONF1_h200 (1U << 2) +#define ST25R3916_REG_RX_CONF1_h80 (1U << 1) +#define ST25R3916_REG_RX_CONF1_z12k (1U << 0) +#define ST25R3916_REG_RX_CONF1_hz_60_400khz (0U << 0) +#define ST25R3916_REG_RX_CONF1_hz_60_200khz (4U << 0) +#define ST25R3916_REG_RX_CONF1_hz_40_80khz (2U << 0) +#define ST25R3916_REG_RX_CONF1_hz_12_200khz (1U << 0) +#define ST25R3916_REG_RX_CONF1_hz_12_80khz (3U << 0) #define ST25R3916_REG_RX_CONF1_hz_12_200khz_alt (5U << 0) -#define ST25R3916_REG_RX_CONF1_hz_600_400khz (8U << 0) -#define ST25R3916_REG_RX_CONF1_hz_600_200khz (12U << 0) -#define ST25R3916_REG_RX_CONF1_hz_mask (0xfU << 0) -#define ST25R3916_REG_RX_CONF1_hz_shift (0U) +#define ST25R3916_REG_RX_CONF1_hz_600_400khz (8U << 0) +#define ST25R3916_REG_RX_CONF1_hz_600_200khz (12U << 0) +#define ST25R3916_REG_RX_CONF1_hz_mask (0xfU << 0) +#define ST25R3916_REG_RX_CONF1_hz_shift (0U) -#define ST25R3916_REG_RX_CONF2_demod_mode (1U << 7) -#define ST25R3916_REG_RX_CONF2_amd_sel (1U << 6) +#define ST25R3916_REG_RX_CONF2_demod_mode (1U << 7) +#define ST25R3916_REG_RX_CONF2_amd_sel (1U << 6) #define ST25R3916_REG_RX_CONF2_amd_sel_mixer (1U << 6) -#define ST25R3916_REG_RX_CONF2_amd_sel_peak (0U << 6) -#define ST25R3916_REG_RX_CONF2_sqm_dyn (1U << 5) -#define ST25R3916_REG_RX_CONF2_pulz_61 (1U << 4) -#define ST25R3916_REG_RX_CONF2_agc_en (1U << 3) -#define ST25R3916_REG_RX_CONF2_agc_m (1U << 2) -#define ST25R3916_REG_RX_CONF2_agc_alg (1U << 1) -#define ST25R3916_REG_RX_CONF2_agc6_3 (1U << 0) - -#define ST25R3916_REG_RX_CONF3_rg1_am2 (1U << 7) -#define ST25R3916_REG_RX_CONF3_rg1_am1 (1U << 6) -#define ST25R3916_REG_RX_CONF3_rg1_am0 (1U << 5) -#define ST25R3916_REG_RX_CONF3_rg1_am_mask (0x7U << 5) +#define ST25R3916_REG_RX_CONF2_amd_sel_peak (0U << 6) +#define ST25R3916_REG_RX_CONF2_sqm_dyn (1U << 5) +#define ST25R3916_REG_RX_CONF2_pulz_61 (1U << 4) +#define ST25R3916_REG_RX_CONF2_agc_en (1U << 3) +#define ST25R3916_REG_RX_CONF2_agc_m (1U << 2) +#define ST25R3916_REG_RX_CONF2_agc_alg (1U << 1) +#define ST25R3916_REG_RX_CONF2_agc6_3 (1U << 0) + +#define ST25R3916_REG_RX_CONF3_rg1_am2 (1U << 7) +#define ST25R3916_REG_RX_CONF3_rg1_am1 (1U << 6) +#define ST25R3916_REG_RX_CONF3_rg1_am0 (1U << 5) +#define ST25R3916_REG_RX_CONF3_rg1_am_mask (0x7U << 5) #define ST25R3916_REG_RX_CONF3_rg1_am_shift (5U) -#define ST25R3916_REG_RX_CONF3_rg1_pm2 (1U << 4) -#define ST25R3916_REG_RX_CONF3_rg1_pm1 (1U << 3) -#define ST25R3916_REG_RX_CONF3_rg1_pm0 (1U << 2) -#define ST25R3916_REG_RX_CONF3_rg1_pm_mask (0x7U << 2) +#define ST25R3916_REG_RX_CONF3_rg1_pm2 (1U << 4) +#define ST25R3916_REG_RX_CONF3_rg1_pm1 (1U << 3) +#define ST25R3916_REG_RX_CONF3_rg1_pm0 (1U << 2) +#define ST25R3916_REG_RX_CONF3_rg1_pm_mask (0x7U << 2) #define ST25R3916_REG_RX_CONF3_rg1_pm_shift (2U) -#define ST25R3916_REG_RX_CONF3_lf_en (1U << 1) -#define ST25R3916_REG_RX_CONF3_lf_op (1U << 0) - -#define ST25R3916_REG_RX_CONF4_rg2_am3 (1U << 7) -#define ST25R3916_REG_RX_CONF4_rg2_am2 (1U << 6) -#define ST25R3916_REG_RX_CONF4_rg2_am1 (1U << 5) -#define ST25R3916_REG_RX_CONF4_rg2_am0 (1U << 4) -#define ST25R3916_REG_RX_CONF4_rg2_am_mask (0xfU << 4) +#define ST25R3916_REG_RX_CONF3_lf_en (1U << 1) +#define ST25R3916_REG_RX_CONF3_lf_op (1U << 0) + +#define ST25R3916_REG_RX_CONF4_rg2_am3 (1U << 7) +#define ST25R3916_REG_RX_CONF4_rg2_am2 (1U << 6) +#define ST25R3916_REG_RX_CONF4_rg2_am1 (1U << 5) +#define ST25R3916_REG_RX_CONF4_rg2_am0 (1U << 4) +#define ST25R3916_REG_RX_CONF4_rg2_am_mask (0xfU << 4) #define ST25R3916_REG_RX_CONF4_rg2_am_shift (4U) -#define ST25R3916_REG_RX_CONF4_rg2_pm3 (1U << 3) -#define ST25R3916_REG_RX_CONF4_rg2_pm2 (1U << 2) -#define ST25R3916_REG_RX_CONF4_rg2_pm1 (1U << 1) -#define ST25R3916_REG_RX_CONF4_rg2_pm0 (1U << 0) -#define ST25R3916_REG_RX_CONF4_rg2_pm_mask (0xfU << 0) +#define ST25R3916_REG_RX_CONF4_rg2_pm3 (1U << 3) +#define ST25R3916_REG_RX_CONF4_rg2_pm2 (1U << 2) +#define ST25R3916_REG_RX_CONF4_rg2_pm1 (1U << 1) +#define ST25R3916_REG_RX_CONF4_rg2_pm0 (1U << 0) +#define ST25R3916_REG_RX_CONF4_rg2_pm_mask (0xfU << 0) #define ST25R3916_REG_RX_CONF4_rg2_pm_shift (0U) -#define ST25R3916_REG_P2P_RX_CONF_ook_fd (1U << 7) -#define ST25R3916_REG_P2P_RX_CONF_ook_rc1 (1U << 6) -#define ST25R3916_REG_P2P_RX_CONF_ook_rc0 (1U << 5) +#define ST25R3916_REG_P2P_RX_CONF_ook_fd (1U << 7) +#define ST25R3916_REG_P2P_RX_CONF_ook_rc1 (1U << 6) +#define ST25R3916_REG_P2P_RX_CONF_ook_rc0 (1U << 5) #define ST25R3916_REG_P2P_RX_CONF_ook_thd1 (1U << 4) #define ST25R3916_REG_P2P_RX_CONF_ook_thd0 (1U << 3) -#define ST25R3916_REG_P2P_RX_CONF_ask_rc1 (1U << 2) -#define ST25R3916_REG_P2P_RX_CONF_ask_rc0 (1U << 1) -#define ST25R3916_REG_P2P_RX_CONF_ask_thd (1U << 0) +#define ST25R3916_REG_P2P_RX_CONF_ask_rc1 (1U << 2) +#define ST25R3916_REG_P2P_RX_CONF_ask_rc0 (1U << 1) +#define ST25R3916_REG_P2P_RX_CONF_ask_thd (1U << 0) #define ST25R3916_REG_CORR_CONF1_corr_s7 (1U << 7) #define ST25R3916_REG_CORR_CONF1_corr_s6 (1U << 6) @@ -506,122 +506,122 @@ extern "C" { #define ST25R3916_REG_CORR_CONF1_corr_s1 (1U << 1) #define ST25R3916_REG_CORR_CONF1_corr_s0 (1U << 0) -#define ST25R3916_REG_CORR_CONF2_rfu5 (1U << 7) -#define ST25R3916_REG_CORR_CONF2_rfu4 (1U << 6) -#define ST25R3916_REG_CORR_CONF2_rfu3 (1U << 5) -#define ST25R3916_REG_CORR_CONF2_rfu2 (1U << 4) -#define ST25R3916_REG_CORR_CONF2_rfu1 (1U << 3) -#define ST25R3916_REG_CORR_CONF2_rfu0 (1U << 2) +#define ST25R3916_REG_CORR_CONF2_rfu5 (1U << 7) +#define ST25R3916_REG_CORR_CONF2_rfu4 (1U << 6) +#define ST25R3916_REG_CORR_CONF2_rfu3 (1U << 5) +#define ST25R3916_REG_CORR_CONF2_rfu2 (1U << 4) +#define ST25R3916_REG_CORR_CONF2_rfu1 (1U << 3) +#define ST25R3916_REG_CORR_CONF2_rfu0 (1U << 2) #define ST25R3916_REG_CORR_CONF2_corr_s9 (1U << 1) #define ST25R3916_REG_CORR_CONF2_corr_s8 (1U << 0) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc2 (1U << 7) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc1 (1U << 6) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc0 (1U << 5) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_no_trigger (0U << 5) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_erx (1U << 5) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_srx (2U << 5) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_etx_nfc (3U << 5) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_mask (7U << 5) -#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_shift (5U) -#define ST25R3916_REG_TIMER_EMV_CONTROL_rfu (1U << 4) -#define ST25R3916_REG_TIMER_EMV_CONTROL_mrt_step (1U << 3) -#define ST25R3916_REG_TIMER_EMV_CONTROL_mrt_step_512 (1U << 3) -#define ST25R3916_REG_TIMER_EMV_CONTROL_mrt_step_64 (0U << 3) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_nfc (1U << 2) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_nfc_on (1U << 2) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_nfc_off (0U << 2) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv (1U << 1) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv_on (1U << 1) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv_off (0U << 1) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step (1U << 0) -#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step_64fc (0U << 0) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc2 (1U << 7) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc1 (1U << 6) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc0 (1U << 5) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_no_trigger (0U << 5) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_erx (1U << 5) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_srx (2U << 5) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_etx_nfc (3U << 5) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_mask (7U << 5) +#define ST25R3916_REG_TIMER_EMV_CONTROL_gptc_shift (5U) +#define ST25R3916_REG_TIMER_EMV_CONTROL_rfu (1U << 4) +#define ST25R3916_REG_TIMER_EMV_CONTROL_mrt_step (1U << 3) +#define ST25R3916_REG_TIMER_EMV_CONTROL_mrt_step_512 (1U << 3) +#define ST25R3916_REG_TIMER_EMV_CONTROL_mrt_step_64 (0U << 3) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_nfc (1U << 2) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_nfc_on (1U << 2) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_nfc_off (0U << 2) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv (1U << 1) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv_on (1U << 1) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv_off (0U << 1) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step (1U << 0) +#define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step_64fc (0U << 0) #define ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step_4096_fc (1U << 0) -#define ST25R3916_REG_FIFO_STATUS2_fifo_b9 (1U << 7) -#define ST25R3916_REG_FIFO_STATUS2_fifo_b8 (1U << 6) -#define ST25R3916_REG_FIFO_STATUS2_fifo_b_mask (3U << 6) -#define ST25R3916_REG_FIFO_STATUS2_fifo_b_shift (6U) -#define ST25R3916_REG_FIFO_STATUS2_fifo_unf (1U << 5) -#define ST25R3916_REG_FIFO_STATUS2_fifo_ovr (1U << 4) -#define ST25R3916_REG_FIFO_STATUS2_fifo_lb2 (1U << 3) -#define ST25R3916_REG_FIFO_STATUS2_fifo_lb1 (1U << 2) -#define ST25R3916_REG_FIFO_STATUS2_fifo_lb0 (1U << 1) -#define ST25R3916_REG_FIFO_STATUS2_fifo_lb_mask (7U << 1) +#define ST25R3916_REG_FIFO_STATUS2_fifo_b9 (1U << 7) +#define ST25R3916_REG_FIFO_STATUS2_fifo_b8 (1U << 6) +#define ST25R3916_REG_FIFO_STATUS2_fifo_b_mask (3U << 6) +#define ST25R3916_REG_FIFO_STATUS2_fifo_b_shift (6U) +#define ST25R3916_REG_FIFO_STATUS2_fifo_unf (1U << 5) +#define ST25R3916_REG_FIFO_STATUS2_fifo_ovr (1U << 4) +#define ST25R3916_REG_FIFO_STATUS2_fifo_lb2 (1U << 3) +#define ST25R3916_REG_FIFO_STATUS2_fifo_lb1 (1U << 2) +#define ST25R3916_REG_FIFO_STATUS2_fifo_lb0 (1U << 1) +#define ST25R3916_REG_FIFO_STATUS2_fifo_lb_mask (7U << 1) #define ST25R3916_REG_FIFO_STATUS2_fifo_lb_shift (1U) -#define ST25R3916_REG_FIFO_STATUS2_np_lb (1U << 0) +#define ST25R3916_REG_FIFO_STATUS2_np_lb (1U << 0) -#define ST25R3916_REG_COLLISION_STATUS_c_byte3 (1U << 7) -#define ST25R3916_REG_COLLISION_STATUS_c_byte2 (1U << 6) -#define ST25R3916_REG_COLLISION_STATUS_c_byte1 (1U << 5) -#define ST25R3916_REG_COLLISION_STATUS_c_byte0 (1U << 4) -#define ST25R3916_REG_COLLISION_STATUS_c_byte_mask (0xfU << 4) +#define ST25R3916_REG_COLLISION_STATUS_c_byte3 (1U << 7) +#define ST25R3916_REG_COLLISION_STATUS_c_byte2 (1U << 6) +#define ST25R3916_REG_COLLISION_STATUS_c_byte1 (1U << 5) +#define ST25R3916_REG_COLLISION_STATUS_c_byte0 (1U << 4) +#define ST25R3916_REG_COLLISION_STATUS_c_byte_mask (0xfU << 4) #define ST25R3916_REG_COLLISION_STATUS_c_byte_shift (4U) -#define ST25R3916_REG_COLLISION_STATUS_c_bit2 (1U << 3) -#define ST25R3916_REG_COLLISION_STATUS_c_bit1 (1U << 2) -#define ST25R3916_REG_COLLISION_STATUS_c_bit0 (1U << 1) -#define ST25R3916_REG_COLLISION_STATUS_c_pb (1U << 0) -#define ST25R3916_REG_COLLISION_STATUS_c_bit_mask (3U << 1) -#define ST25R3916_REG_COLLISION_STATUS_c_bit_shift (1U) - -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu (1U << 7) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu1 (1U << 6) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu2 (1U << 5) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu3 (1U << 4) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state3 (1U << 3) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state2 (1U << 2) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state1 (1U << 1) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state0 (1U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_power_off (0x0U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_idle (0x1U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_ready_l1 (0x2U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_ready_l2 (0x3U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu4 (0x4U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_active (0x5U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu6 (0x6U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu7 (0x7U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu8 (0x8U << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_halt (0x9U << 0) +#define ST25R3916_REG_COLLISION_STATUS_c_bit2 (1U << 3) +#define ST25R3916_REG_COLLISION_STATUS_c_bit1 (1U << 2) +#define ST25R3916_REG_COLLISION_STATUS_c_bit0 (1U << 1) +#define ST25R3916_REG_COLLISION_STATUS_c_pb (1U << 0) +#define ST25R3916_REG_COLLISION_STATUS_c_bit_mask (3U << 1) +#define ST25R3916_REG_COLLISION_STATUS_c_bit_shift (1U) + +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu (1U << 7) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu1 (1U << 6) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu2 (1U << 5) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_rfu3 (1U << 4) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state3 (1U << 3) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state2 (1U << 2) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state1 (1U << 1) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state0 (1U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_power_off (0x0U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_idle (0x1U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_ready_l1 (0x2U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_ready_l2 (0x3U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu4 (0x4U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_active (0x5U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu6 (0x6U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu7 (0x7U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu8 (0x8U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_halt (0x9U << 0) #define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_ready_l1_x (0xaU << 0) #define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_ready_l2_x (0xbU << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu12 (0xcU << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_active_x (0xdU << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state_mask (0xfU << 0) -#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state_shift (0U) - -#define ST25R3916_REG_NUM_TX_BYTES2_ntx4 (1U << 7) -#define ST25R3916_REG_NUM_TX_BYTES2_ntx3 (1U << 6) -#define ST25R3916_REG_NUM_TX_BYTES2_ntx2 (1U << 5) -#define ST25R3916_REG_NUM_TX_BYTES2_ntx1 (1U << 4) -#define ST25R3916_REG_NUM_TX_BYTES2_ntx0 (1U << 3) -#define ST25R3916_REG_NUM_TX_BYTES2_ntx_mask (0x1fU << 3) -#define ST25R3916_REG_NUM_TX_BYTES2_ntx_shift (3U) -#define ST25R3916_REG_NUM_TX_BYTES2_nbtx2 (1U << 2) -#define ST25R3916_REG_NUM_TX_BYTES2_nbtx1 (1U << 1) -#define ST25R3916_REG_NUM_TX_BYTES2_nbtx0 (1U << 0) -#define ST25R3916_REG_NUM_TX_BYTES2_nbtx_mask (7U << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_rfu12 (0xcU << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_st_active_x (0xdU << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state_mask (0xfU << 0) +#define ST25R3916_REG_PASSIVE_TARGET_STATUS_pta_state_shift (0U) + +#define ST25R3916_REG_NUM_TX_BYTES2_ntx4 (1U << 7) +#define ST25R3916_REG_NUM_TX_BYTES2_ntx3 (1U << 6) +#define ST25R3916_REG_NUM_TX_BYTES2_ntx2 (1U << 5) +#define ST25R3916_REG_NUM_TX_BYTES2_ntx1 (1U << 4) +#define ST25R3916_REG_NUM_TX_BYTES2_ntx0 (1U << 3) +#define ST25R3916_REG_NUM_TX_BYTES2_ntx_mask (0x1fU << 3) +#define ST25R3916_REG_NUM_TX_BYTES2_ntx_shift (3U) +#define ST25R3916_REG_NUM_TX_BYTES2_nbtx2 (1U << 2) +#define ST25R3916_REG_NUM_TX_BYTES2_nbtx1 (1U << 1) +#define ST25R3916_REG_NUM_TX_BYTES2_nbtx0 (1U << 0) +#define ST25R3916_REG_NUM_TX_BYTES2_nbtx_mask (7U << 0) #define ST25R3916_REG_NUM_TX_BYTES2_nbtx_shift (0U) -#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rfu1 (1U << 7) -#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rfu0 (1U << 6) -#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rate1 (1U << 5) -#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rate0 (1U << 4) -#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rate_mask (0x3U << 4) +#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rfu1 (1U << 7) +#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rfu0 (1U << 6) +#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rate1 (1U << 5) +#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rate0 (1U << 4) +#define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rate_mask (0x3U << 4) #define ST25R3916_REG_NFCIP1_BIT_RATE_nfc_rate_shift (4U) -#define ST25R3916_REG_NFCIP1_BIT_RATE_ppt2_on (1U << 3) -#define ST25R3916_REG_NFCIP1_BIT_RATE_gpt_on (1U << 2) -#define ST25R3916_REG_NFCIP1_BIT_RATE_nrt_on (1U << 1) -#define ST25R3916_REG_NFCIP1_BIT_RATE_mrt_on (1U << 0) - -#define ST25R3916_REG_TX_DRIVER_am_mod3 (1U << 7) -#define ST25R3916_REG_TX_DRIVER_am_mod2 (1U << 6) -#define ST25R3916_REG_TX_DRIVER_am_mod1 (1U << 5) -#define ST25R3916_REG_TX_DRIVER_am_mod0 (1U << 4) -#define ST25R3916_REG_TX_DRIVER_am_mod_5percent (0x0U << 4) -#define ST25R3916_REG_TX_DRIVER_am_mod_6percent (0x1U << 4) -#define ST25R3916_REG_TX_DRIVER_am_mod_7percent (0x2U << 4) -#define ST25R3916_REG_TX_DRIVER_am_mod_8percent (0x3U << 4) -#define ST25R3916_REG_TX_DRIVER_am_mod_9percent (0x4U << 4) +#define ST25R3916_REG_NFCIP1_BIT_RATE_ppt2_on (1U << 3) +#define ST25R3916_REG_NFCIP1_BIT_RATE_gpt_on (1U << 2) +#define ST25R3916_REG_NFCIP1_BIT_RATE_nrt_on (1U << 1) +#define ST25R3916_REG_NFCIP1_BIT_RATE_mrt_on (1U << 0) + +#define ST25R3916_REG_TX_DRIVER_am_mod3 (1U << 7) +#define ST25R3916_REG_TX_DRIVER_am_mod2 (1U << 6) +#define ST25R3916_REG_TX_DRIVER_am_mod1 (1U << 5) +#define ST25R3916_REG_TX_DRIVER_am_mod0 (1U << 4) +#define ST25R3916_REG_TX_DRIVER_am_mod_5percent (0x0U << 4) +#define ST25R3916_REG_TX_DRIVER_am_mod_6percent (0x1U << 4) +#define ST25R3916_REG_TX_DRIVER_am_mod_7percent (0x2U << 4) +#define ST25R3916_REG_TX_DRIVER_am_mod_8percent (0x3U << 4) +#define ST25R3916_REG_TX_DRIVER_am_mod_9percent (0x4U << 4) #define ST25R3916_REG_TX_DRIVER_am_mod_10percent (0x5U << 4) #define ST25R3916_REG_TX_DRIVER_am_mod_11percent (0x6U << 4) #define ST25R3916_REG_TX_DRIVER_am_mod_12percent (0x7U << 4) @@ -633,78 +633,78 @@ extern "C" { #define ST25R3916_REG_TX_DRIVER_am_mod_22percent (0xdU << 4) #define ST25R3916_REG_TX_DRIVER_am_mod_26percent (0xeU << 4) #define ST25R3916_REG_TX_DRIVER_am_mod_40percent (0xfU << 4) -#define ST25R3916_REG_TX_DRIVER_am_mod_mask (0xfU << 4) -#define ST25R3916_REG_TX_DRIVER_am_mod_shift (4U) -#define ST25R3916_REG_TX_DRIVER_d_res3 (1U << 3) -#define ST25R3916_REG_TX_DRIVER_d_res2 (1U << 2) -#define ST25R3916_REG_TX_DRIVER_d_res1 (1U << 1) -#define ST25R3916_REG_TX_DRIVER_d_res0 (1U << 0) -#define ST25R3916_REG_TX_DRIVER_d_res_mask (0xfU << 0) -#define ST25R3916_REG_TX_DRIVER_d_res_shift (0U) - -#define ST25R3916_REG_PT_MOD_ptm_res3 (1U << 7) -#define ST25R3916_REG_PT_MOD_ptm_res2 (1U << 6) -#define ST25R3916_REG_PT_MOD_ptm_res1 (1U << 5) -#define ST25R3916_REG_PT_MOD_ptm_res0 (1U << 4) -#define ST25R3916_REG_PT_MOD_ptm_res_mask (0xfU << 4) +#define ST25R3916_REG_TX_DRIVER_am_mod_mask (0xfU << 4) +#define ST25R3916_REG_TX_DRIVER_am_mod_shift (4U) +#define ST25R3916_REG_TX_DRIVER_d_res3 (1U << 3) +#define ST25R3916_REG_TX_DRIVER_d_res2 (1U << 2) +#define ST25R3916_REG_TX_DRIVER_d_res1 (1U << 1) +#define ST25R3916_REG_TX_DRIVER_d_res0 (1U << 0) +#define ST25R3916_REG_TX_DRIVER_d_res_mask (0xfU << 0) +#define ST25R3916_REG_TX_DRIVER_d_res_shift (0U) + +#define ST25R3916_REG_PT_MOD_ptm_res3 (1U << 7) +#define ST25R3916_REG_PT_MOD_ptm_res2 (1U << 6) +#define ST25R3916_REG_PT_MOD_ptm_res1 (1U << 5) +#define ST25R3916_REG_PT_MOD_ptm_res0 (1U << 4) +#define ST25R3916_REG_PT_MOD_ptm_res_mask (0xfU << 4) #define ST25R3916_REG_PT_MOD_ptm_res_shift (4U) -#define ST25R3916_REG_PT_MOD_pt_res3 (1U << 3) -#define ST25R3916_REG_PT_MOD_pt_res2 (1U << 2) -#define ST25R3916_REG_PT_MOD_pt_res1 (1U << 1) -#define ST25R3916_REG_PT_MOD_pt_res0 (1U << 0) -#define ST25R3916_REG_PT_MOD_pt_res_mask (0xfU << 0) -#define ST25R3916_REG_PT_MOD_pt_res_shift (0U) +#define ST25R3916_REG_PT_MOD_pt_res3 (1U << 3) +#define ST25R3916_REG_PT_MOD_pt_res2 (1U << 2) +#define ST25R3916_REG_PT_MOD_pt_res1 (1U << 1) +#define ST25R3916_REG_PT_MOD_pt_res0 (1U << 0) +#define ST25R3916_REG_PT_MOD_pt_res_mask (0xfU << 0) +#define ST25R3916_REG_PT_MOD_pt_res_shift (0U) #define ST25R3916_REG_AUX_MOD_dis_reg_am (1U << 7) #define ST25R3916_REG_AUX_MOD_lm_ext_pol (1U << 6) -#define ST25R3916_REG_AUX_MOD_lm_ext (1U << 5) -#define ST25R3916_REG_AUX_MOD_lm_dri (1U << 4) -#define ST25R3916_REG_AUX_MOD_res_am (1U << 3) -#define ST25R3916_REG_AUX_MOD_rfu2 (1U << 2) -#define ST25R3916_REG_AUX_MOD_rfu1 (1U << 1) -#define ST25R3916_REG_AUX_MOD_rfu0 (1U << 0) - -#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t3 (1U << 7) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t2 (1U << 6) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t1 (1U << 5) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t0 (1U << 4) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_mask (0xfU << 4) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_shift (4U) -#define ST25R3916_REG_TX_DRIVER_TIMING_rfu (1U << 3) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m2 (1U << 2) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m1 (1U << 1) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m0 (1U << 0) -#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m_mask (0x7U << 0) +#define ST25R3916_REG_AUX_MOD_lm_ext (1U << 5) +#define ST25R3916_REG_AUX_MOD_lm_dri (1U << 4) +#define ST25R3916_REG_AUX_MOD_res_am (1U << 3) +#define ST25R3916_REG_AUX_MOD_rfu2 (1U << 2) +#define ST25R3916_REG_AUX_MOD_rfu1 (1U << 1) +#define ST25R3916_REG_AUX_MOD_rfu0 (1U << 0) + +#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t3 (1U << 7) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t2 (1U << 6) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t1 (1U << 5) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_t0 (1U << 4) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_mask (0xfU << 4) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_rat_shift (4U) +#define ST25R3916_REG_TX_DRIVER_TIMING_rfu (1U << 3) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m2 (1U << 2) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m1 (1U << 1) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m0 (1U << 0) +#define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m_mask (0x7U << 0) #define ST25R3916_REG_TX_DRIVER_TIMING_d_tim_m_shift (0U) -#define ST25R3916_REG_RES_AM_MOD_fa3_f (1U << 7) -#define ST25R3916_REG_RES_AM_MOD_md_res6 (1U << 6) -#define ST25R3916_REG_RES_AM_MOD_md_res5 (1U << 5) -#define ST25R3916_REG_RES_AM_MOD_md_res4 (1U << 4) -#define ST25R3916_REG_RES_AM_MOD_md_res3 (1U << 3) -#define ST25R3916_REG_RES_AM_MOD_md_res2 (1U << 2) -#define ST25R3916_REG_RES_AM_MOD_md_res1 (1U << 1) -#define ST25R3916_REG_RES_AM_MOD_md_res0 (1U << 0) -#define ST25R3916_REG_RES_AM_MOD_md_res_mask (0x7FU << 0) +#define ST25R3916_REG_RES_AM_MOD_fa3_f (1U << 7) +#define ST25R3916_REG_RES_AM_MOD_md_res6 (1U << 6) +#define ST25R3916_REG_RES_AM_MOD_md_res5 (1U << 5) +#define ST25R3916_REG_RES_AM_MOD_md_res4 (1U << 4) +#define ST25R3916_REG_RES_AM_MOD_md_res3 (1U << 3) +#define ST25R3916_REG_RES_AM_MOD_md_res2 (1U << 2) +#define ST25R3916_REG_RES_AM_MOD_md_res1 (1U << 1) +#define ST25R3916_REG_RES_AM_MOD_md_res0 (1U << 0) +#define ST25R3916_REG_RES_AM_MOD_md_res_mask (0x7FU << 0) #define ST25R3916_REG_RES_AM_MOD_md_res_shift (0U) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r3 (1U << 7) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r2 (1U << 6) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r1 (1U << 5) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r0 (1U << 4) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_mask (0xfU << 4) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r3 (1U << 7) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r2 (1U << 6) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r1 (1U << 5) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_r0 (1U << 4) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_mask (0xfU << 4) #define ST25R3916_REG_TX_DRIVER_STATUS_d_rat_shift (4U) -#define ST25R3916_REG_TX_DRIVER_STATUS_rfu (1U << 3) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_r2 (1U << 2) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_r1 (1U << 1) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_r0 (1U << 0) -#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_mask (0x7U << 0) +#define ST25R3916_REG_TX_DRIVER_STATUS_rfu (1U << 3) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_r2 (1U << 2) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_r1 (1U << 1) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_r0 (1U << 0) +#define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_mask (0x7U << 0) #define ST25R3916_REG_TX_DRIVER_STATUS_d_tim_shift (0U) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_l2a (1U << 6) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_l1a (1U << 5) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_l0a (1U << 4) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_75mV (0x0U << 4) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_l2a (1U << 6) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_l1a (1U << 5) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_l0a (1U << 4) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_75mV (0x0U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_105mV (0x1U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_150mV (0x2U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_205mV (0x3U << 4) @@ -712,13 +712,13 @@ extern "C" { #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_400mV (0x5U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_560mV (0x6U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_800mV (0x7U << 4) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_mask (7U << 4) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_mask (7U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_shift (4U) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t3a (1U << 3) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t2a (1U << 2) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t1a (1U << 1) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t0a (1U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_75mV (0x0U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t3a (1U << 3) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t2a (1U << 2) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t1a (1U << 1) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_t0a (1U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_75mV (0x0U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_105mV (0x1U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_150mV (0x2U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_205mV (0x3U << 0) @@ -726,21 +726,21 @@ extern "C" { #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_400mV (0x5U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_560mV (0x6U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_800mV (0x7U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_25mV (0x8U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_33mV (0x9U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_47mV (0xAU << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_64mV (0xBU << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_90mV (0xCU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_25mV (0x8U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_33mV (0x9U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_47mV (0xAU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_64mV (0xBU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_90mV (0xCU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_125mV (0xDU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_175mV (0xEU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_250mV (0xFU << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_mask (0xfU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_mask (0xfU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_shift (0U) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_l2d (1U << 6) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_l1d (1U << 5) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_l0d (1U << 4) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_75mV (0x0U << 4) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_l2d (1U << 6) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_l1d (1U << 5) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_l0d (1U << 4) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_75mV (0x0U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_105mV (0x1U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_150mV (0x2U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_205mV (0x3U << 4) @@ -748,13 +748,13 @@ extern "C" { #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_400mV (0x5U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_560mV (0x6U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_800mV (0x7U << 4) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_mask (7U << 4) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_mask (7U << 4) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_shift (4U) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t3d (1U << 3) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t2d (1U << 2) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t1d (1U << 1) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t0d (1U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_75mV (0x0U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t3d (1U << 3) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t2d (1U << 2) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t1d (1U << 1) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_t0d (1U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_75mV (0x0U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_105mV (0x1U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_150mV (0x2U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_205mV (0x3U << 0) @@ -762,112 +762,112 @@ extern "C" { #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_400mV (0x5U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_560mV (0x6U << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_800mV (0x7U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_25mV (0x8U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_33mV (0x9U << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_47mV (0xAU << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_64mV (0xBU << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_90mV (0xCU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_25mV (0x8U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_33mV (0x9U << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_47mV (0xAU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_64mV (0xBU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_90mV (0xCU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_125mV (0xDU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_175mV (0xEU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_250mV (0xFU << 0) -#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_mask (0xfU << 0) +#define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_mask (0xfU << 0) #define ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_shift (0U) -#define ST25R3916_REG_REGULATOR_CONTROL_reg_s (1U << 7) -#define ST25R3916_REG_REGULATOR_CONTROL_rege_3 (1U << 6) -#define ST25R3916_REG_REGULATOR_CONTROL_rege_2 (1U << 5) -#define ST25R3916_REG_REGULATOR_CONTROL_rege_1 (1U << 4) -#define ST25R3916_REG_REGULATOR_CONTROL_rege_0 (1U << 3) -#define ST25R3916_REG_REGULATOR_CONTROL_rege_mask (0xfU << 3) -#define ST25R3916_REG_REGULATOR_CONTROL_rege_shift (3U) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv2 (2U << 2) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv1 (1U << 1) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv0 (1U << 0) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd (0U) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_a (1U) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_d (2U) +#define ST25R3916_REG_REGULATOR_CONTROL_reg_s (1U << 7) +#define ST25R3916_REG_REGULATOR_CONTROL_rege_3 (1U << 6) +#define ST25R3916_REG_REGULATOR_CONTROL_rege_2 (1U << 5) +#define ST25R3916_REG_REGULATOR_CONTROL_rege_1 (1U << 4) +#define ST25R3916_REG_REGULATOR_CONTROL_rege_0 (1U << 3) +#define ST25R3916_REG_REGULATOR_CONTROL_rege_mask (0xfU << 3) +#define ST25R3916_REG_REGULATOR_CONTROL_rege_shift (3U) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv2 (2U << 2) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv1 (1U << 1) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv0 (1U << 0) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd (0U) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_a (1U) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_d (2U) #define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_rf (3U) #define ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_am (4U) -#define ST25R3916_REG_REGULATOR_CONTROL_rfu (5U) -#define ST25R3916_REG_REGULATOR_CONTROL_rfu1 (6U) -#define ST25R3916_REG_REGULATOR_CONTROL_rfu2 (7U) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_mask (7U) -#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_shift (0U) - -#define ST25R3916_REG_REGULATOR_RESULT_reg_3 (1U << 7) -#define ST25R3916_REG_REGULATOR_RESULT_reg_2 (1U << 6) -#define ST25R3916_REG_REGULATOR_RESULT_reg_1 (1U << 5) -#define ST25R3916_REG_REGULATOR_RESULT_reg_0 (1U << 4) -#define ST25R3916_REG_REGULATOR_RESULT_reg_mask (0xfU << 4) +#define ST25R3916_REG_REGULATOR_CONTROL_rfu (5U) +#define ST25R3916_REG_REGULATOR_CONTROL_rfu1 (6U) +#define ST25R3916_REG_REGULATOR_CONTROL_rfu2 (7U) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_mask (7U) +#define ST25R3916_REG_REGULATOR_CONTROL_mpsv_shift (0U) + +#define ST25R3916_REG_REGULATOR_RESULT_reg_3 (1U << 7) +#define ST25R3916_REG_REGULATOR_RESULT_reg_2 (1U << 6) +#define ST25R3916_REG_REGULATOR_RESULT_reg_1 (1U << 5) +#define ST25R3916_REG_REGULATOR_RESULT_reg_0 (1U << 4) +#define ST25R3916_REG_REGULATOR_RESULT_reg_mask (0xfU << 4) #define ST25R3916_REG_REGULATOR_RESULT_reg_shift (4U) -#define ST25R3916_REG_REGULATOR_RESULT_i_lim (1U << 0) +#define ST25R3916_REG_REGULATOR_RESULT_i_lim (1U << 0) -#define ST25R3916_REG_RSSI_RESULT_rssi_am_3 (1U << 7) -#define ST25R3916_REG_RSSI_RESULT_rssi_am_2 (1U << 6) -#define ST25R3916_REG_RSSI_RESULT_rssi_am_1 (1U << 5) -#define ST25R3916_REG_RSSI_RESULT_rssi_am_0 (1U << 4) -#define ST25R3916_REG_RSSI_RESULT_rssi_am_mask (0xfU << 4) +#define ST25R3916_REG_RSSI_RESULT_rssi_am_3 (1U << 7) +#define ST25R3916_REG_RSSI_RESULT_rssi_am_2 (1U << 6) +#define ST25R3916_REG_RSSI_RESULT_rssi_am_1 (1U << 5) +#define ST25R3916_REG_RSSI_RESULT_rssi_am_0 (1U << 4) +#define ST25R3916_REG_RSSI_RESULT_rssi_am_mask (0xfU << 4) #define ST25R3916_REG_RSSI_RESULT_rssi_am_shift (4U) -#define ST25R3916_REG_RSSI_RESULT_rssi_pm3 (1U << 3) -#define ST25R3916_REG_RSSI_RESULT_rssi_pm2 (1U << 2) -#define ST25R3916_REG_RSSI_RESULT_rssi_pm1 (1U << 1) -#define ST25R3916_REG_RSSI_RESULT_rssi_pm0 (1U << 0) -#define ST25R3916_REG_RSSI_RESULT_rssi_pm_mask (0xfU << 0) +#define ST25R3916_REG_RSSI_RESULT_rssi_pm3 (1U << 3) +#define ST25R3916_REG_RSSI_RESULT_rssi_pm2 (1U << 2) +#define ST25R3916_REG_RSSI_RESULT_rssi_pm1 (1U << 1) +#define ST25R3916_REG_RSSI_RESULT_rssi_pm0 (1U << 0) +#define ST25R3916_REG_RSSI_RESULT_rssi_pm_mask (0xfU << 0) #define ST25R3916_REG_RSSI_RESULT_rssi_pm_shift (0U) -#define ST25R3916_REG_GAIN_RED_STATE_gs_am_3 (1U << 7) -#define ST25R3916_REG_GAIN_RED_STATE_gs_am_2 (1U << 6) -#define ST25R3916_REG_GAIN_RED_STATE_gs_am_1 (1U << 5) -#define ST25R3916_REG_GAIN_RED_STATE_gs_am_0 (1U << 4) -#define ST25R3916_REG_GAIN_RED_STATE_gs_am_mask (0xfU << 4) +#define ST25R3916_REG_GAIN_RED_STATE_gs_am_3 (1U << 7) +#define ST25R3916_REG_GAIN_RED_STATE_gs_am_2 (1U << 6) +#define ST25R3916_REG_GAIN_RED_STATE_gs_am_1 (1U << 5) +#define ST25R3916_REG_GAIN_RED_STATE_gs_am_0 (1U << 4) +#define ST25R3916_REG_GAIN_RED_STATE_gs_am_mask (0xfU << 4) #define ST25R3916_REG_GAIN_RED_STATE_gs_am_shift (4U) -#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_3 (1U << 3) -#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_2 (1U << 2) -#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_1 (1U << 1) -#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_0 (1U << 0) -#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_mask (0xfU << 0) +#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_3 (1U << 3) +#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_2 (1U << 2) +#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_1 (1U << 1) +#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_0 (1U << 0) +#define ST25R3916_REG_GAIN_RED_STATE_gs_pm_mask (0xfU << 0) #define ST25R3916_REG_GAIN_RED_STATE_gs_pm_shift (0U) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal4 (1U << 7) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal3 (1U << 6) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal2 (1U << 5) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal1 (1U << 4) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal0 (1U << 3) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal_mask (0x1fU << 3) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal4 (1U << 7) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal3 (1U << 6) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal2 (1U << 5) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal1 (1U << 4) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal0 (1U << 3) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal_mask (0x1fU << 3) #define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal_shift (3U) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g2 (1U << 2) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g1 (1U << 1) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g0 (1U << 0) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g_mask (7U << 0) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g_shift (0U) - -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal4 (1U << 7) -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal3 (1U << 6) -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal2 (1U << 5) -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal1 (1U << 4) -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal0 (1U << 3) -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_mask (0x1fU << 3) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g2 (1U << 2) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g1 (1U << 1) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g0 (1U << 0) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g_mask (7U << 0) +#define ST25R3916_REG_CAP_SENSOR_CONTROL_cs_g_shift (0U) + +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal4 (1U << 7) +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal3 (1U << 6) +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal2 (1U << 5) +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal1 (1U << 4) +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal0 (1U << 3) +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_mask (0x1fU << 3) #define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_shift (3U) -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_end (1U << 2) -#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_err (1U << 1) - -#define ST25R3916_REG_AUX_DISPLAY_a_cha (1U << 7) -#define ST25R3916_REG_AUX_DISPLAY_efd_o (1U << 6) -#define ST25R3916_REG_AUX_DISPLAY_tx_on (1U << 5) -#define ST25R3916_REG_AUX_DISPLAY_osc_ok (1U << 4) -#define ST25R3916_REG_AUX_DISPLAY_rx_on (1U << 3) -#define ST25R3916_REG_AUX_DISPLAY_rx_act (1U << 2) +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_end (1U << 2) +#define ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_err (1U << 1) + +#define ST25R3916_REG_AUX_DISPLAY_a_cha (1U << 7) +#define ST25R3916_REG_AUX_DISPLAY_efd_o (1U << 6) +#define ST25R3916_REG_AUX_DISPLAY_tx_on (1U << 5) +#define ST25R3916_REG_AUX_DISPLAY_osc_ok (1U << 4) +#define ST25R3916_REG_AUX_DISPLAY_rx_on (1U << 3) +#define ST25R3916_REG_AUX_DISPLAY_rx_act (1U << 2) #define ST25R3916_REG_AUX_DISPLAY_en_peer (1U << 1) -#define ST25R3916_REG_AUX_DISPLAY_en_ac (1U << 0) +#define ST25R3916_REG_AUX_DISPLAY_en_ac (1U << 0) -#define ST25R3916_REG_OVERSHOOT_CONF1_ov_tx_mode1 (1U << 7) -#define ST25R3916_REG_OVERSHOOT_CONF1_ov_tx_mode0 (1U << 6) +#define ST25R3916_REG_OVERSHOOT_CONF1_ov_tx_mode1 (1U << 7) +#define ST25R3916_REG_OVERSHOOT_CONF1_ov_tx_mode0 (1U << 6) #define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern13 (1U << 5) #define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern12 (1U << 4) #define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern11 (1U << 3) #define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern10 (1U << 2) -#define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern9 (1U << 1) -#define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern8 (1U << 0) +#define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern9 (1U << 1) +#define ST25R3916_REG_OVERSHOOT_CONF1_ov_pattern8 (1U << 0) #define ST25R3916_REG_OVERSHOOT_CONF2_ov_pattern7 (1U << 7) #define ST25R3916_REG_OVERSHOOT_CONF2_ov_pattern6 (1U << 6) @@ -878,14 +878,14 @@ extern "C" { #define ST25R3916_REG_OVERSHOOT_CONF2_ov_pattern1 (1U << 1) #define ST25R3916_REG_OVERSHOOT_CONF2_ov_pattern0 (1U << 0) -#define ST25R3916_REG_UNDERSHOOT_CONF1_un_tx_mode1 (1U << 7) -#define ST25R3916_REG_UNDERSHOOT_CONF1_un_tx_mode0 (1U << 6) +#define ST25R3916_REG_UNDERSHOOT_CONF1_un_tx_mode1 (1U << 7) +#define ST25R3916_REG_UNDERSHOOT_CONF1_un_tx_mode0 (1U << 6) #define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern13 (1U << 5) #define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern12 (1U << 4) #define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern11 (1U << 3) #define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern10 (1U << 2) -#define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern9 (1U << 1) -#define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern8 (1U << 0) +#define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern9 (1U << 1) +#define ST25R3916_REG_UNDERSHOOT_CONF1_un_pattern8 (1U << 0) #define ST25R3916_REG_UNDERSHOOT_CONF2_un_pattern7 (1U << 7) #define ST25R3916_REG_UNDERSHOOT_CONF2_un_pattern6 (1U << 6) @@ -896,70 +896,70 @@ extern "C" { #define ST25R3916_REG_UNDERSHOOT_CONF2_un_pattern1 (1U << 1) #define ST25R3916_REG_UNDERSHOOT_CONF2_un_pattern0 (1U << 0) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wur (1U << 7) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wut2 (1U << 6) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wut1 (1U << 5) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wut0 (1U << 4) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wut_mask (7U << 4) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wur (1U << 7) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wut2 (1U << 6) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wut1 (1U << 5) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wut0 (1U << 4) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wut_mask (7U << 4) #define ST25R3916_REG_WUP_TIMER_CONTROL_wut_shift (4U) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wto (1U << 3) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wam (1U << 2) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wph (1U << 1) -#define ST25R3916_REG_WUP_TIMER_CONTROL_wcap (1U << 0) - -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d3 (1U << 7) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d2 (1U << 6) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d1 (1U << 5) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d0 (1U << 4) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d_mask (0xfU << 4) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d_shift (4U) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aam (1U << 3) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aew1 (1U << 2) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aew0 (1U << 1) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aew_mask (0x3U << 1) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wto (1U << 3) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wam (1U << 2) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wph (1U << 1) +#define ST25R3916_REG_WUP_TIMER_CONTROL_wcap (1U << 0) + +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d3 (1U << 7) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d2 (1U << 6) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d1 (1U << 5) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d0 (1U << 4) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d_mask (0xfU << 4) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_d_shift (4U) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aam (1U << 3) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aew1 (1U << 2) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aew0 (1U << 1) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aew_mask (0x3U << 1) #define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_aew_shift (1U) -#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_ae (1U << 0) - -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d3 (1U << 7) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d2 (1U << 6) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d1 (1U << 5) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d0 (1U << 4) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d_mask (0xfU << 4) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d_shift (4U) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aam (1U << 3) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aew1 (1U << 2) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aew0 (1U << 1) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aew_mask (0x3U << 1) +#define ST25R3916_REG_AMPLITUDE_MEASURE_CONF_am_ae (1U << 0) + +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d3 (1U << 7) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d2 (1U << 6) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d1 (1U << 5) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d0 (1U << 4) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d_mask (0xfU << 4) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_d_shift (4U) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aam (1U << 3) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aew1 (1U << 2) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aew0 (1U << 1) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aew_mask (0x3U << 1) #define ST25R3916_REG_PHASE_MEASURE_CONF_pm_aew_shift (1U) -#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_ae (1U << 0) - -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d3 (1U << 7) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d2 (1U << 6) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d1 (1U << 5) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d0 (1U << 4) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d_mask (0xfU << 4) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d_shift (4U) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aam (1U << 3) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aew1 (1U << 2) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aew0 (1U << 1) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aew_mask (0x3U << 1) +#define ST25R3916_REG_PHASE_MEASURE_CONF_pm_ae (1U << 0) + +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d3 (1U << 7) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d2 (1U << 6) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d1 (1U << 5) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d0 (1U << 4) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d_mask (0xfU << 4) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_d_shift (4U) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aam (1U << 3) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aew1 (1U << 2) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aew0 (1U << 1) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aew_mask (0x3U << 1) #define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_aew_shift (1U) -#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_ae (1U << 0) +#define ST25R3916_REG_CAPACITANCE_MEASURE_CONF_cm_ae (1U << 0) -#define ST25R3916_REG_IC_IDENTITY_ic_type4 (1U << 7) -#define ST25R3916_REG_IC_IDENTITY_ic_type3 (1U << 6) -#define ST25R3916_REG_IC_IDENTITY_ic_type2 (1U << 5) -#define ST25R3916_REG_IC_IDENTITY_ic_type1 (1U << 4) -#define ST25R3916_REG_IC_IDENTITY_ic_type0 (1U << 3) +#define ST25R3916_REG_IC_IDENTITY_ic_type4 (1U << 7) +#define ST25R3916_REG_IC_IDENTITY_ic_type3 (1U << 6) +#define ST25R3916_REG_IC_IDENTITY_ic_type2 (1U << 5) +#define ST25R3916_REG_IC_IDENTITY_ic_type1 (1U << 4) +#define ST25R3916_REG_IC_IDENTITY_ic_type0 (1U << 3) #define ST25R3916_REG_IC_IDENTITY_ic_type_st25r3916 (5U << 3) -#define ST25R3916_REG_IC_IDENTITY_ic_type_mask (0x1fU << 3) -#define ST25R3916_REG_IC_IDENTITY_ic_type_shift (3U) -#define ST25R3916_REG_IC_IDENTITY_ic_rev2 (1U << 2) -#define ST25R3916_REG_IC_IDENTITY_ic_rev1 (1U << 1) -#define ST25R3916_REG_IC_IDENTITY_ic_rev0 (1U << 0) -#define ST25R3916_REG_IC_IDENTITY_ic_rev_v0 (0U << 0) -#define ST25R3916_REG_IC_IDENTITY_ic_rev_mask (7U << 0) -#define ST25R3916_REG_IC_IDENTITY_ic_rev_shift (0U) +#define ST25R3916_REG_IC_IDENTITY_ic_type_mask (0x1fU << 3) +#define ST25R3916_REG_IC_IDENTITY_ic_type_shift (3U) +#define ST25R3916_REG_IC_IDENTITY_ic_rev2 (1U << 2) +#define ST25R3916_REG_IC_IDENTITY_ic_rev1 (1U << 1) +#define ST25R3916_REG_IC_IDENTITY_ic_rev0 (1U << 0) +#define ST25R3916_REG_IC_IDENTITY_ic_rev_v0 (0U << 0) +#define ST25R3916_REG_IC_IDENTITY_ic_rev_mask (7U << 0) +#define ST25R3916_REG_IC_IDENTITY_ic_rev_shift (0U) /** Read register * diff --git a/lib/flipper_format/flipper_format_stream.c b/lib/flipper_format/flipper_format_stream.c index 405b819a760..b9d33169c9a 100644 --- a/lib/flipper_format/flipper_format_stream.c +++ b/lib/flipper_format/flipper_format_stream.c @@ -122,7 +122,11 @@ bool flipper_format_stream_seek_to_key(Stream* stream, const char* key, bool str } static bool flipper_format_stream_read_value(Stream* stream, FuriString* value, bool* last) { - enum { LeadingSpace, ReadValue, TrailingSpace } state = LeadingSpace; + enum { + LeadingSpace, + ReadValue, + TrailingSpace + } state = LeadingSpace; const size_t buffer_size = 32; uint8_t buffer[buffer_size]; bool result = false; @@ -396,7 +400,11 @@ bool flipper_format_stream_read_value_line( }; break; case FlipperStreamValueUint32: { uint32_t* data = _data; - scan_values = sscanf(furi_string_get_cstr(value), "%" PRIu32, &data[i]); + // Minus sign is allowed in scanf() for unsigned numbers, resulting in unintentionally huge values with no error reported + if(!furi_string_start_with(value, "-")) { + scan_values = + sscanf(furi_string_get_cstr(value), "%" PRIu32, &data[i]); + } }; break; case FlipperStreamValueHexUint64: { uint64_t* data = _data; diff --git a/lib/ibutton/ibutton_protocols.c b/lib/ibutton/ibutton_protocols.c index 84fcccd71c1..ecd5f9a0dc6 100644 --- a/lib/ibutton/ibutton_protocols.c +++ b/lib/ibutton/ibutton_protocols.c @@ -17,8 +17,8 @@ iButtonProtocolGroupInfo info; \ ibutton_protocols_get_group_by_id(protocols, (id), &info); -#define GROUP_BASE (info.base) -#define GROUP_DATA (info.group) +#define GROUP_BASE (info.base) +#define GROUP_DATA (info.group) #define PROTOCOL_ID (info.id) struct iButtonProtocols { diff --git a/lib/ibutton/protocols/blanks/rw1990.c b/lib/ibutton/protocols/blanks/rw1990.c index f86e43d99c0..d8017ca8395 100644 --- a/lib/ibutton/protocols/blanks/rw1990.c +++ b/lib/ibutton/protocols/blanks/rw1990.c @@ -3,12 +3,12 @@ #include #define RW1990_1_CMD_WRITE_RECORD_FLAG 0xD1 -#define RW1990_1_CMD_READ_RECORD_FLAG 0xB5 -#define RW1990_1_CMD_WRITE_ROM 0xD5 +#define RW1990_1_CMD_READ_RECORD_FLAG 0xB5 +#define RW1990_1_CMD_WRITE_ROM 0xD5 #define RW1990_2_CMD_WRITE_RECORD_FLAG 0x1D -#define RW1990_2_CMD_READ_RECORD_FLAG 0x1E -#define RW1990_2_CMD_WRITE_ROM 0xD5 +#define RW1990_2_CMD_READ_RECORD_FLAG 0x1E +#define RW1990_2_CMD_WRITE_ROM 0xD5 #define DS1990_CMD_READ_ROM 0x33 diff --git a/lib/ibutton/protocols/blanks/tm2004.c b/lib/ibutton/protocols/blanks/tm2004.c index b020a218d7e..a275dda0a86 100644 --- a/lib/ibutton/protocols/blanks/tm2004.c +++ b/lib/ibutton/protocols/blanks/tm2004.c @@ -2,10 +2,10 @@ #include -#define TM2004_CMD_READ_STATUS 0xAA -#define TM2004_CMD_READ_MEMORY 0xF0 -#define TM2004_CMD_WRITE_ROM 0x3C -#define TM2004_CMD_FINALIZATION 0x35 +#define TM2004_CMD_READ_STATUS 0xAA +#define TM2004_CMD_READ_MEMORY 0xF0 +#define TM2004_CMD_WRITE_ROM 0x3C +#define TM2004_CMD_FINALIZATION 0x35 #define TM2004_ANSWER_READ_MEMORY 0xF5 bool tm2004_write(OneWireHost* host, const uint8_t* data, size_t data_size) { diff --git a/lib/ibutton/protocols/dallas/dallas_common.c b/lib/ibutton/protocols/dallas/dallas_common.c index 7ce12f7a065..e9e655717a4 100644 --- a/lib/ibutton/protocols/dallas/dallas_common.c +++ b/lib/ibutton/protocols/dallas/dallas_common.c @@ -9,12 +9,12 @@ #define DALLAS_COMMON_ROM_DATA_KEY_V2 "Rom Data" #define DALLAS_COMMON_COPY_SCRATCH_MIN_TIMEOUT_US 5U -#define DALLAS_COMMON_COPY_SCRATCH_POLL_COUNT 20U +#define DALLAS_COMMON_COPY_SCRATCH_POLL_COUNT 20U #define DALLAS_COMMON_END_ADDRESS_MASK 0x01F -#define DALLAS_COMMON_STATUS_FLAG_PF (1U << 5) -#define DALLAS_COMMON_STATUS_FLAG_OF (1U << 6) -#define DALLAS_COMMON_STATUS_FLAG_AA (1U << 7) +#define DALLAS_COMMON_STATUS_FLAG_PF (1U << 5) +#define DALLAS_COMMON_STATUS_FLAG_OF (1U << 6) +#define DALLAS_COMMON_STATUS_FLAG_AA (1U << 7) #define DALLAS_COMMON_BRIEF_HEAD_COUNT 4U #define DALLAS_COMMON_BRIEF_TAIL_COUNT 3U diff --git a/lib/ibutton/protocols/dallas/dallas_common.h b/lib/ibutton/protocols/dallas/dallas_common.h index 90fec3e28a1..3df0e1c96f2 100644 --- a/lib/ibutton/protocols/dallas/dallas_common.h +++ b/lib/ibutton/protocols/dallas/dallas_common.h @@ -7,19 +7,19 @@ #define DALLAS_COMMON_MANUFACTURER_NAME "Dallas" -#define DALLAS_COMMON_CMD_READ_ROM 0x33U -#define DALLAS_COMMON_CMD_MATCH_ROM 0x55U -#define DALLAS_COMMON_CMD_SKIP_ROM 0xCCU +#define DALLAS_COMMON_CMD_READ_ROM 0x33U +#define DALLAS_COMMON_CMD_MATCH_ROM 0x55U +#define DALLAS_COMMON_CMD_SKIP_ROM 0xCCU #define DALLAS_COMMON_CMD_COND_SEARCH 0xECU -#define DALLAS_COMMON_CMD_SEARCH_ROM 0xF0U +#define DALLAS_COMMON_CMD_SEARCH_ROM 0xF0U -#define DALLAS_COMMON_CMD_READ_SCRATCH 0xAAU +#define DALLAS_COMMON_CMD_READ_SCRATCH 0xAAU #define DALLAS_COMMON_CMD_WRITE_SCRATCH 0x0FU -#define DALLAS_COMMON_CMD_COPY_SCRATCH 0x55U +#define DALLAS_COMMON_CMD_COPY_SCRATCH 0x55U #define DALLAS_COMMON_CMD_READ_MEM 0xF0U -#define DALLAS_COMMON_CMD_OVERDRIVE_SKIP_ROM 0x3CU +#define DALLAS_COMMON_CMD_OVERDRIVE_SKIP_ROM 0x3CU #define DALLAS_COMMON_CMD_OVERDRIVE_MATCH_ROM 0x69U typedef enum { diff --git a/lib/ibutton/protocols/dallas/protocol_ds1971.c b/lib/ibutton/protocols/dallas/protocol_ds1971.c index 6d147d28d3e..64920f6acea 100644 --- a/lib/ibutton/protocols/dallas/protocol_ds1971.c +++ b/lib/ibutton/protocols/dallas/protocol_ds1971.c @@ -8,14 +8,14 @@ #define DS1971_FAMILY_CODE 0x14U #define DS1971_FAMILY_NAME "DS1971" -#define DS1971_EEPROM_DATA_SIZE 32U -#define DS1971_SRAM_PAGE_SIZE 32U +#define DS1971_EEPROM_DATA_SIZE 32U +#define DS1971_SRAM_PAGE_SIZE 32U #define DS1971_COPY_SCRATCH_DELAY_US 250U #define DS1971_DATA_BYTE_COUNT 4U #define DS1971_EEPROM_DATA_KEY "Eeprom Data" -#define DS1971_MEMORY_TYPE "EEPROM" +#define DS1971_MEMORY_TYPE "EEPROM" #define DS1971_CMD_FINALIZATION 0xA5 diff --git a/lib/ibutton/protocols/dallas/protocol_ds1992.c b/lib/ibutton/protocols/dallas/protocol_ds1992.c index 483d9827f07..0b6cd4fca2f 100644 --- a/lib/ibutton/protocols/dallas/protocol_ds1992.c +++ b/lib/ibutton/protocols/dallas/protocol_ds1992.c @@ -10,14 +10,14 @@ #define DS1992_FAMILY_CODE 0x08U #define DS1992_FAMILY_NAME "DS1992" -#define DS1992_SRAM_DATA_SIZE 128U -#define DS1992_SRAM_PAGE_SIZE 4U +#define DS1992_SRAM_DATA_SIZE 128U +#define DS1992_SRAM_PAGE_SIZE 4U #define DS1992_COPY_SCRATCH_TIMEOUT_US 100U #define DS1992_DATA_BYTE_COUNT 4U #define DS1992_SRAM_DATA_KEY "Sram Data" -#define DS1992_MEMORY_TYPE "SRAM" +#define DS1992_MEMORY_TYPE "SRAM" typedef struct { OneWireSlave* bus; diff --git a/lib/ibutton/protocols/dallas/protocol_ds1996.c b/lib/ibutton/protocols/dallas/protocol_ds1996.c index 157dc601a1a..d78a303f86b 100644 --- a/lib/ibutton/protocols/dallas/protocol_ds1996.c +++ b/lib/ibutton/protocols/dallas/protocol_ds1996.c @@ -8,14 +8,14 @@ #define DS1996_FAMILY_CODE 0x0CU #define DS1996_FAMILY_NAME "DS1996" -#define DS1996_SRAM_DATA_SIZE 8192U -#define DS1996_SRAM_PAGE_SIZE 32U +#define DS1996_SRAM_DATA_SIZE 8192U +#define DS1996_SRAM_PAGE_SIZE 32U #define DS1996_COPY_SCRATCH_TIMEOUT_US 100U #define DS1996_DATA_BYTE_COUNT 4U #define DS1996_SRAM_DATA_KEY "Sram Data" -#define DS1996_MEMORY_TYPE "SRAM" +#define DS1996_MEMORY_TYPE "SRAM" typedef struct { OneWireSlave* bus; diff --git a/lib/ibutton/protocols/misc/protocol_cyfral.c b/lib/ibutton/protocols/misc/protocol_cyfral.c index e43d0c6adb2..2f9f8bc74f1 100644 --- a/lib/ibutton/protocols/misc/protocol_cyfral.c +++ b/lib/ibutton/protocols/misc/protocol_cyfral.c @@ -4,11 +4,11 @@ #include "protocol_cyfral.h" #define CYFRAL_DATA_SIZE sizeof(uint16_t) -#define CYFRAL_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond()) -#define CYFRAL_0_LOW (CYFRAL_PERIOD * 0.66f) -#define CYFRAL_0_HI (CYFRAL_PERIOD * 0.33f) -#define CYFRAL_1_LOW (CYFRAL_PERIOD * 0.33f) -#define CYFRAL_1_HI (CYFRAL_PERIOD * 0.66f) +#define CYFRAL_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond()) +#define CYFRAL_0_LOW (CYFRAL_PERIOD * 0.66f) +#define CYFRAL_0_HI (CYFRAL_PERIOD * 0.33f) +#define CYFRAL_1_LOW (CYFRAL_PERIOD * 0.33f) +#define CYFRAL_1_HI (CYFRAL_PERIOD * 0.66f) #define CYFRAL_MAX_PERIOD_US 230 diff --git a/lib/ibutton/protocols/misc/protocol_metakom.c b/lib/ibutton/protocols/misc/protocol_metakom.c index 6d5e0339d6f..26e5cd1d71a 100644 --- a/lib/ibutton/protocols/misc/protocol_metakom.c +++ b/lib/ibutton/protocols/misc/protocol_metakom.c @@ -4,11 +4,11 @@ #include "protocol_metakom.h" #define METAKOM_DATA_SIZE sizeof(uint32_t) -#define METAKOM_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond()) -#define METAKOM_0_LOW (METAKOM_PERIOD * 0.33f) -#define METAKOM_0_HI (METAKOM_PERIOD * 0.66f) -#define METAKOM_1_LOW (METAKOM_PERIOD * 0.66f) -#define METAKOM_1_HI (METAKOM_PERIOD * 0.33f) +#define METAKOM_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond()) +#define METAKOM_0_LOW (METAKOM_PERIOD * 0.33f) +#define METAKOM_0_HI (METAKOM_PERIOD * 0.66f) +#define METAKOM_1_LOW (METAKOM_PERIOD * 0.66f) +#define METAKOM_1_HI (METAKOM_PERIOD * 0.33f) #define METAKOM_PERIOD_SAMPLE_COUNT 10 diff --git a/lib/infrared/encoder_decoder/infrared.h b/lib/infrared/encoder_decoder/infrared.h index 377ce0ef27a..cc652c88c8c 100644 --- a/lib/infrared/encoder_decoder/infrared.h +++ b/lib/infrared/encoder_decoder/infrared.h @@ -9,7 +9,7 @@ extern "C" { #endif #define INFRARED_COMMON_CARRIER_FREQUENCY ((uint32_t)38000) -#define INFRARED_COMMON_DUTY_CYCLE ((float)0.33) +#define INFRARED_COMMON_DUTY_CYCLE ((float)0.33) /* if we want to see split raw signals during bruteforce, * we have to have RX raw timing delay less than TX */ diff --git a/lib/infrared/encoder_decoder/kaseikyo/infrared_protocol_kaseikyo_i.h b/lib/infrared/encoder_decoder/kaseikyo/infrared_protocol_kaseikyo_i.h index bee116c4d15..c3ad3f1f606 100644 --- a/lib/infrared/encoder_decoder/kaseikyo/infrared_protocol_kaseikyo_i.h +++ b/lib/infrared/encoder_decoder/kaseikyo/infrared_protocol_kaseikyo_i.h @@ -2,23 +2,23 @@ #include "../common/infrared_common_i.h" -#define INFRARED_KASEIKYO_UNIT 432 -#define INFRARED_KASEIKYO_PREAMBLE_MARK (8 * INFRARED_KASEIKYO_UNIT) -#define INFRARED_KASEIKYO_PREAMBLE_SPACE (4 * INFRARED_KASEIKYO_UNIT) -#define INFRARED_KASEIKYO_BIT1_MARK INFRARED_KASEIKYO_UNIT -#define INFRARED_KASEIKYO_BIT1_SPACE (3 * INFRARED_KASEIKYO_UNIT) -#define INFRARED_KASEIKYO_BIT0_MARK INFRARED_KASEIKYO_UNIT -#define INFRARED_KASEIKYO_BIT0_SPACE INFRARED_KASEIKYO_UNIT -#define INFRARED_KASEIKYO_REPEAT_PERIOD 130000 -#define INFRARED_KASEIKYO_SILENCE INFRARED_KASEIKYO_REPEAT_PERIOD -#define INFRARED_KASEIKYO_MIN_SPLIT_TIME INFRARED_KASEIKYO_REPEAT_PAUSE_MIN -#define INFRARED_KASEIKYO_REPEAT_PAUSE_MIN 4000 -#define INFRARED_KASEIKYO_REPEAT_PAUSE_MAX 150000 -#define INFRARED_KASEIKYO_REPEAT_COUNT_MIN 1 -#define INFRARED_KASEIKYO_REPEAT_MARK INFRARED_KASEIKYO_PREAMBLE_MARK -#define INFRARED_KASEIKYO_REPEAT_SPACE (INFRARED_KASEIKYO_REPEAT_PERIOD - 56000) +#define INFRARED_KASEIKYO_UNIT 432 +#define INFRARED_KASEIKYO_PREAMBLE_MARK (8 * INFRARED_KASEIKYO_UNIT) +#define INFRARED_KASEIKYO_PREAMBLE_SPACE (4 * INFRARED_KASEIKYO_UNIT) +#define INFRARED_KASEIKYO_BIT1_MARK INFRARED_KASEIKYO_UNIT +#define INFRARED_KASEIKYO_BIT1_SPACE (3 * INFRARED_KASEIKYO_UNIT) +#define INFRARED_KASEIKYO_BIT0_MARK INFRARED_KASEIKYO_UNIT +#define INFRARED_KASEIKYO_BIT0_SPACE INFRARED_KASEIKYO_UNIT +#define INFRARED_KASEIKYO_REPEAT_PERIOD 130000 +#define INFRARED_KASEIKYO_SILENCE INFRARED_KASEIKYO_REPEAT_PERIOD +#define INFRARED_KASEIKYO_MIN_SPLIT_TIME INFRARED_KASEIKYO_REPEAT_PAUSE_MIN +#define INFRARED_KASEIKYO_REPEAT_PAUSE_MIN 4000 +#define INFRARED_KASEIKYO_REPEAT_PAUSE_MAX 150000 +#define INFRARED_KASEIKYO_REPEAT_COUNT_MIN 1 +#define INFRARED_KASEIKYO_REPEAT_MARK INFRARED_KASEIKYO_PREAMBLE_MARK +#define INFRARED_KASEIKYO_REPEAT_SPACE (INFRARED_KASEIKYO_REPEAT_PERIOD - 56000) #define INFRARED_KASEIKYO_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_KASEIKYO_BIT_TOLERANCE 120 // us +#define INFRARED_KASEIKYO_BIT_TOLERANCE 120 // us extern const InfraredCommonProtocolSpec infrared_protocol_kaseikyo; diff --git a/lib/infrared/encoder_decoder/nec/infrared_protocol_nec_i.h b/lib/infrared/encoder_decoder/nec/infrared_protocol_nec_i.h index 05df1f474ea..56a6607eb25 100644 --- a/lib/infrared/encoder_decoder/nec/infrared_protocol_nec_i.h +++ b/lib/infrared/encoder_decoder/nec/infrared_protocol_nec_i.h @@ -2,22 +2,22 @@ #include "../common/infrared_common_i.h" -#define INFRARED_NEC_PREAMBLE_MARK 9000 -#define INFRARED_NEC_PREAMBLE_SPACE 4500 -#define INFRARED_NEC_BIT1_MARK 560 -#define INFRARED_NEC_BIT1_SPACE 1690 -#define INFRARED_NEC_BIT0_MARK 560 -#define INFRARED_NEC_BIT0_SPACE 560 -#define INFRARED_NEC_REPEAT_PERIOD 110000 -#define INFRARED_NEC_SILENCE INFRARED_NEC_REPEAT_PERIOD -#define INFRARED_NEC_MIN_SPLIT_TIME INFRARED_NEC_REPEAT_PAUSE_MIN -#define INFRARED_NEC_REPEAT_PAUSE_MIN 4000 -#define INFRARED_NEC_REPEAT_PAUSE_MAX 150000 -#define INFRARED_NEC_REPEAT_COUNT_MIN 1 -#define INFRARED_NEC_REPEAT_MARK 9000 -#define INFRARED_NEC_REPEAT_SPACE 2250 +#define INFRARED_NEC_PREAMBLE_MARK 9000 +#define INFRARED_NEC_PREAMBLE_SPACE 4500 +#define INFRARED_NEC_BIT1_MARK 560 +#define INFRARED_NEC_BIT1_SPACE 1690 +#define INFRARED_NEC_BIT0_MARK 560 +#define INFRARED_NEC_BIT0_SPACE 560 +#define INFRARED_NEC_REPEAT_PERIOD 110000 +#define INFRARED_NEC_SILENCE INFRARED_NEC_REPEAT_PERIOD +#define INFRARED_NEC_MIN_SPLIT_TIME INFRARED_NEC_REPEAT_PAUSE_MIN +#define INFRARED_NEC_REPEAT_PAUSE_MIN 4000 +#define INFRARED_NEC_REPEAT_PAUSE_MAX 150000 +#define INFRARED_NEC_REPEAT_COUNT_MIN 1 +#define INFRARED_NEC_REPEAT_MARK 9000 +#define INFRARED_NEC_REPEAT_SPACE 2250 #define INFRARED_NEC_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_NEC_BIT_TOLERANCE 120 // us +#define INFRARED_NEC_BIT_TOLERANCE 120 // us extern const InfraredCommonProtocolSpec infrared_protocol_nec; diff --git a/lib/infrared/encoder_decoder/pioneer/infrared_protocol_pioneer_i.h b/lib/infrared/encoder_decoder/pioneer/infrared_protocol_pioneer_i.h index 2ff7f7e3a05..791242a3aa6 100644 --- a/lib/infrared/encoder_decoder/pioneer/infrared_protocol_pioneer_i.h +++ b/lib/infrared/encoder_decoder/pioneer/infrared_protocol_pioneer_i.h @@ -2,19 +2,19 @@ #include "../common/infrared_common_i.h" -#define INFRARED_PIONEER_CARRIER_FREQUENCY 40000 -#define INFRARED_PIONEER_DUTY_CYCLE 0.33 -#define INFRARED_PIONEER_PREAMBLE_MARK 8500 -#define INFRARED_PIONEER_PREAMBLE_SPACE 4225 -#define INFRARED_PIONEER_BIT1_MARK 500 -#define INFRARED_PIONEER_BIT1_SPACE 1500 -#define INFRARED_PIONEER_BIT0_MARK 500 -#define INFRARED_PIONEER_BIT0_SPACE 500 +#define INFRARED_PIONEER_CARRIER_FREQUENCY 40000 +#define INFRARED_PIONEER_DUTY_CYCLE 0.33 +#define INFRARED_PIONEER_PREAMBLE_MARK 8500 +#define INFRARED_PIONEER_PREAMBLE_SPACE 4225 +#define INFRARED_PIONEER_BIT1_MARK 500 +#define INFRARED_PIONEER_BIT1_SPACE 1500 +#define INFRARED_PIONEER_BIT0_MARK 500 +#define INFRARED_PIONEER_BIT0_SPACE 500 #define INFRARED_PIONEER_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_PIONEER_BIT_TOLERANCE 120 // us -#define INFRARED_PIONEER_SILENCE 26000 -#define INFRARED_PIONEER_MIN_SPLIT_TIME (INFRARED_PIONEER_SILENCE) -#define INFRARED_PIONEER_REPEAT_COUNT_MIN 2 +#define INFRARED_PIONEER_BIT_TOLERANCE 120 // us +#define INFRARED_PIONEER_SILENCE 26000 +#define INFRARED_PIONEER_MIN_SPLIT_TIME (INFRARED_PIONEER_SILENCE) +#define INFRARED_PIONEER_REPEAT_COUNT_MIN 2 extern const InfraredCommonProtocolSpec infrared_protocol_pioneer; @@ -22,4 +22,4 @@ bool infrared_decoder_pioneer_interpret(InfraredCommonDecoder* decoder); InfraredStatus infrared_encoder_pioneer_encode_repeat( InfraredCommonEncoder* encoder, uint32_t* duration, - bool* level); \ No newline at end of file + bool* level); diff --git a/lib/infrared/encoder_decoder/rc5/infrared_protocol_rc5_i.h b/lib/infrared/encoder_decoder/rc5/infrared_protocol_rc5_i.h index b906c369e00..551163e0c48 100644 --- a/lib/infrared/encoder_decoder/rc5/infrared_protocol_rc5_i.h +++ b/lib/infrared/encoder_decoder/rc5/infrared_protocol_rc5_i.h @@ -3,17 +3,17 @@ #include "../common/infrared_common_i.h" #define INFRARED_RC5_CARRIER_FREQUENCY 36000 -#define INFRARED_RC5_DUTY_CYCLE 0.33 +#define INFRARED_RC5_DUTY_CYCLE 0.33 -#define INFRARED_RC5_PREAMBLE_MARK 0 -#define INFRARED_RC5_PREAMBLE_SPACE 0 -#define INFRARED_RC5_BIT 888 // half of time-quant for 1 bit +#define INFRARED_RC5_PREAMBLE_MARK 0 +#define INFRARED_RC5_PREAMBLE_SPACE 0 +#define INFRARED_RC5_BIT 888 // half of time-quant for 1 bit #define INFRARED_RC5_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_RC5_BIT_TOLERANCE 120 // us +#define INFRARED_RC5_BIT_TOLERANCE 120 // us /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */ -#define INFRARED_RC5_SILENCE (2700 * 10) -#define INFRARED_RC5_MIN_SPLIT_TIME 2700 -#define INFRARED_RC5_REPEAT_COUNT_MIN 1 +#define INFRARED_RC5_SILENCE (2700 * 10) +#define INFRARED_RC5_MIN_SPLIT_TIME 2700 +#define INFRARED_RC5_REPEAT_COUNT_MIN 1 extern const InfraredCommonProtocolSpec infrared_protocol_rc5; diff --git a/lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6_i.h b/lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6_i.h index 06aa2a6a519..efa3071f43e 100644 --- a/lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6_i.h +++ b/lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6_i.h @@ -3,17 +3,17 @@ #include "../common/infrared_common_i.h" #define INFRARED_RC6_CARRIER_FREQUENCY 36000 -#define INFRARED_RC6_DUTY_CYCLE 0.33 +#define INFRARED_RC6_DUTY_CYCLE 0.33 -#define INFRARED_RC6_PREAMBLE_MARK 2666 -#define INFRARED_RC6_PREAMBLE_SPACE 889 -#define INFRARED_RC6_BIT 444 // half of time-quant for 1 bit +#define INFRARED_RC6_PREAMBLE_MARK 2666 +#define INFRARED_RC6_PREAMBLE_SPACE 889 +#define INFRARED_RC6_BIT 444 // half of time-quant for 1 bit #define INFRARED_RC6_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_RC6_BIT_TOLERANCE 120 // us +#define INFRARED_RC6_BIT_TOLERANCE 120 // us /* protocol allows 2700 silence, but it is hard to send 1 message without repeat */ -#define INFRARED_RC6_SILENCE (2700 * 10) -#define INFRARED_RC6_MIN_SPLIT_TIME 2700 -#define INFRARED_RC6_REPEAT_COUNT_MIN 1 +#define INFRARED_RC6_SILENCE (2700 * 10) +#define INFRARED_RC6_MIN_SPLIT_TIME 2700 +#define INFRARED_RC6_REPEAT_COUNT_MIN 1 extern const InfraredCommonProtocolSpec infrared_protocol_rc6; diff --git a/lib/infrared/encoder_decoder/rca/infrared_protocol_rca_i.h b/lib/infrared/encoder_decoder/rca/infrared_protocol_rca_i.h index 9ec4fe3b179..b628735c87d 100644 --- a/lib/infrared/encoder_decoder/rca/infrared_protocol_rca_i.h +++ b/lib/infrared/encoder_decoder/rca/infrared_protocol_rca_i.h @@ -2,23 +2,23 @@ #include "../common/infrared_common_i.h" -#define INFRARED_RCA_PREAMBLE_MARK 4000 +#define INFRARED_RCA_PREAMBLE_MARK 4000 #define INFRARED_RCA_PREAMBLE_SPACE 4000 -#define INFRARED_RCA_BIT1_MARK 500 -#define INFRARED_RCA_BIT1_SPACE 2000 -#define INFRARED_RCA_BIT0_MARK 500 -#define INFRARED_RCA_BIT0_SPACE 1000 -#define INFRARED_RCA_REPEAT_PERIOD 8000 -#define INFRARED_RCA_SILENCE INFRARED_RCA_REPEAT_PERIOD +#define INFRARED_RCA_BIT1_MARK 500 +#define INFRARED_RCA_BIT1_SPACE 2000 +#define INFRARED_RCA_BIT0_MARK 500 +#define INFRARED_RCA_BIT0_SPACE 1000 +#define INFRARED_RCA_REPEAT_PERIOD 8000 +#define INFRARED_RCA_SILENCE INFRARED_RCA_REPEAT_PERIOD -#define INFRARED_RCA_MIN_SPLIT_TIME INFRARED_RCA_REPEAT_PAUSE_MIN -#define INFRARED_RCA_REPEAT_PAUSE_MIN 4000 -#define INFRARED_RCA_REPEAT_PAUSE_MAX 150000 -#define INFRARED_RCA_REPEAT_COUNT_MIN 1 -#define INFRARED_RCA_REPEAT_MARK INFRARED_RCA_PREAMBLE_MARK -#define INFRARED_RCA_REPEAT_SPACE INFRARED_RCA_PREAMBLE_SPACE +#define INFRARED_RCA_MIN_SPLIT_TIME INFRARED_RCA_REPEAT_PAUSE_MIN +#define INFRARED_RCA_REPEAT_PAUSE_MIN 4000 +#define INFRARED_RCA_REPEAT_PAUSE_MAX 150000 +#define INFRARED_RCA_REPEAT_COUNT_MIN 1 +#define INFRARED_RCA_REPEAT_MARK INFRARED_RCA_PREAMBLE_MARK +#define INFRARED_RCA_REPEAT_SPACE INFRARED_RCA_PREAMBLE_SPACE #define INFRARED_RCA_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_RCA_BIT_TOLERANCE 120 // us +#define INFRARED_RCA_BIT_TOLERANCE 120 // us extern const InfraredCommonProtocolSpec infrared_protocol_rca; diff --git a/lib/infrared/encoder_decoder/samsung/infrared_protocol_samsung_i.h b/lib/infrared/encoder_decoder/samsung/infrared_protocol_samsung_i.h index b8538494296..ceb082e2288 100644 --- a/lib/infrared/encoder_decoder/samsung/infrared_protocol_samsung_i.h +++ b/lib/infrared/encoder_decoder/samsung/infrared_protocol_samsung_i.h @@ -2,28 +2,28 @@ #include "../common/infrared_common_i.h" -#define INFRARED_SAMSUNG_PREAMBLE_MARK 4500 -#define INFRARED_SAMSUNG_PREAMBLE_SPACE 4500 -#define INFRARED_SAMSUNG_BIT1_MARK 550 -#define INFRARED_SAMSUNG_BIT1_SPACE 1650 -#define INFRARED_SAMSUNG_BIT0_MARK 550 -#define INFRARED_SAMSUNG_BIT0_SPACE 550 -#define INFRARED_SAMSUNG_REPEAT_PAUSE_MIN 30000 -#define INFRARED_SAMSUNG_REPEAT_PAUSE_MAX 140000 -#define INFRARED_SAMSUNG_REPEAT_PAUSE1 46000 -#define INFRARED_SAMSUNG_REPEAT_PAUSE2 97000 -#define INFRARED_SAMSUNG_REPEAT_COUNT_MIN 1 +#define INFRARED_SAMSUNG_PREAMBLE_MARK 4500 +#define INFRARED_SAMSUNG_PREAMBLE_SPACE 4500 +#define INFRARED_SAMSUNG_BIT1_MARK 550 +#define INFRARED_SAMSUNG_BIT1_SPACE 1650 +#define INFRARED_SAMSUNG_BIT0_MARK 550 +#define INFRARED_SAMSUNG_BIT0_SPACE 550 +#define INFRARED_SAMSUNG_REPEAT_PAUSE_MIN 30000 +#define INFRARED_SAMSUNG_REPEAT_PAUSE_MAX 140000 +#define INFRARED_SAMSUNG_REPEAT_PAUSE1 46000 +#define INFRARED_SAMSUNG_REPEAT_PAUSE2 97000 +#define INFRARED_SAMSUNG_REPEAT_COUNT_MIN 1 /* Samsung silence have to be greater than REPEAT MAX * otherwise there can be problems during unit tests parsing * of some data. Real tolerances we don't know, but in real life * silence time should be greater than max repeat time. This is * because of similar preambule timings for repeat and first messages. */ -#define INFRARED_SAMSUNG_MIN_SPLIT_TIME 5000 -#define INFRARED_SAMSUNG_SILENCE 145000 -#define INFRARED_SAMSUNG_REPEAT_MARK 4500 -#define INFRARED_SAMSUNG_REPEAT_SPACE 4500 +#define INFRARED_SAMSUNG_MIN_SPLIT_TIME 5000 +#define INFRARED_SAMSUNG_SILENCE 145000 +#define INFRARED_SAMSUNG_REPEAT_MARK 4500 +#define INFRARED_SAMSUNG_REPEAT_SPACE 4500 #define INFRARED_SAMSUNG_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_SAMSUNG_BIT_TOLERANCE 120 // us +#define INFRARED_SAMSUNG_BIT_TOLERANCE 120 // us bool infrared_decoder_samsung32_interpret(InfraredCommonDecoder* decoder); InfraredStatus infrared_decoder_samsung32_decode_repeat(InfraredCommonDecoder* decoder); diff --git a/lib/infrared/encoder_decoder/sirc/infrared_protocol_sirc_i.h b/lib/infrared/encoder_decoder/sirc/infrared_protocol_sirc_i.h index e38be9bc868..e37b9846915 100644 --- a/lib/infrared/encoder_decoder/sirc/infrared_protocol_sirc_i.h +++ b/lib/infrared/encoder_decoder/sirc/infrared_protocol_sirc_i.h @@ -2,20 +2,20 @@ #include "../common/infrared_common_i.h" -#define INFRARED_SIRC_CARRIER_FREQUENCY 40000 -#define INFRARED_SIRC_DUTY_CYCLE 0.33 -#define INFRARED_SIRC_PREAMBLE_MARK 2400 -#define INFRARED_SIRC_PREAMBLE_SPACE 600 -#define INFRARED_SIRC_BIT1_MARK 1200 -#define INFRARED_SIRC_BIT1_SPACE 600 -#define INFRARED_SIRC_BIT0_MARK 600 -#define INFRARED_SIRC_BIT0_SPACE 600 +#define INFRARED_SIRC_CARRIER_FREQUENCY 40000 +#define INFRARED_SIRC_DUTY_CYCLE 0.33 +#define INFRARED_SIRC_PREAMBLE_MARK 2400 +#define INFRARED_SIRC_PREAMBLE_SPACE 600 +#define INFRARED_SIRC_BIT1_MARK 1200 +#define INFRARED_SIRC_BIT1_SPACE 600 +#define INFRARED_SIRC_BIT0_MARK 600 +#define INFRARED_SIRC_BIT0_SPACE 600 #define INFRARED_SIRC_PREAMBLE_TOLERANCE 200 // us -#define INFRARED_SIRC_BIT_TOLERANCE 120 // us -#define INFRARED_SIRC_SILENCE 10000 -#define INFRARED_SIRC_MIN_SPLIT_TIME (INFRARED_SIRC_SILENCE - 1000) -#define INFRARED_SIRC_REPEAT_PERIOD 45000 -#define INFRARED_SIRC_REPEAT_COUNT_MIN 3 +#define INFRARED_SIRC_BIT_TOLERANCE 120 // us +#define INFRARED_SIRC_SILENCE 10000 +#define INFRARED_SIRC_MIN_SPLIT_TIME (INFRARED_SIRC_SILENCE - 1000) +#define INFRARED_SIRC_REPEAT_PERIOD 45000 +#define INFRARED_SIRC_REPEAT_COUNT_MIN 3 extern const InfraredCommonProtocolSpec infrared_protocol_sirc; diff --git a/lib/infrared/worker/infrared_worker.c b/lib/infrared/worker/infrared_worker.c index 89f351eb92d..cc9361ccf15 100644 --- a/lib/infrared/worker/infrared_worker.c +++ b/lib/infrared/worker/infrared_worker.c @@ -10,12 +10,12 @@ #define INFRARED_WORKER_RX_TIMEOUT INFRARED_RAW_RX_TIMING_DELAY_US -#define INFRARED_WORKER_RX_RECEIVED 0x01 +#define INFRARED_WORKER_RX_RECEIVED 0x01 #define INFRARED_WORKER_RX_TIMEOUT_RECEIVED 0x02 -#define INFRARED_WORKER_OVERRUN 0x04 -#define INFRARED_WORKER_EXIT 0x08 -#define INFRARED_WORKER_TX_FILL_BUFFER 0x10 -#define INFRARED_WORKER_TX_MESSAGE_SENT 0x20 +#define INFRARED_WORKER_OVERRUN 0x04 +#define INFRARED_WORKER_EXIT 0x08 +#define INFRARED_WORKER_TX_FILL_BUFFER 0x10 +#define INFRARED_WORKER_TX_MESSAGE_SENT 0x20 #define INFRARED_WORKER_ALL_RX_EVENTS \ (INFRARED_WORKER_RX_RECEIVED | INFRARED_WORKER_RX_TIMEOUT_RECEIVED | \ diff --git a/lib/lfrfid/lfrfid_dict_file.c b/lib/lfrfid/lfrfid_dict_file.c index 367150812b2..11e812fdbfc 100644 --- a/lib/lfrfid/lfrfid_dict_file.c +++ b/lib/lfrfid/lfrfid_dict_file.c @@ -185,4 +185,4 @@ ProtocolId lfrfid_dict_file_load(ProtocolDict* dict, const char* filename) { furi_record_close(RECORD_STORAGE); return result; -} \ No newline at end of file +} diff --git a/lib/lfrfid/lfrfid_dict_file.h b/lib/lfrfid/lfrfid_dict_file.h index 077bb0ba138..8be9e60b47c 100644 --- a/lib/lfrfid/lfrfid_dict_file.h +++ b/lib/lfrfid/lfrfid_dict_file.h @@ -28,4 +28,4 @@ ProtocolId lfrfid_dict_file_load(ProtocolDict* dict, const char* filename); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/lfrfid/lfrfid_raw_file.c b/lib/lfrfid/lfrfid_raw_file.c index 441cf7333b0..c0aac71bed9 100644 --- a/lib/lfrfid/lfrfid_raw_file.c +++ b/lib/lfrfid/lfrfid_raw_file.c @@ -3,7 +3,7 @@ #include #include -#define LFRFID_RAW_FILE_MAGIC 0x4C464952 +#define LFRFID_RAW_FILE_MAGIC 0x4C464952 #define LFRFID_RAW_FILE_VERSION 1 #define TAG "LfRfidRawFile" @@ -71,7 +71,7 @@ bool lfrfid_raw_file_write_header( .max_buffer_size = max_buffer_size}; size_t size = stream_write(file->stream, (uint8_t*)&header, sizeof(LFRFIDRawFileHeader)); - return (size == sizeof(LFRFIDRawFileHeader)); + return size == sizeof(LFRFIDRawFileHeader); } bool lfrfid_raw_file_write_buffer(LFRFIDRawFile* file, uint8_t* buffer_data, size_t buffer_size) { @@ -166,4 +166,4 @@ bool lfrfid_raw_file_read_pair( } return true; -} \ No newline at end of file +} diff --git a/lib/lfrfid/lfrfid_raw_worker.c b/lib/lfrfid/lfrfid_raw_worker.c index 7c04b9dfad6..bef30506b50 100644 --- a/lib/lfrfid/lfrfid_raw_worker.c +++ b/lib/lfrfid/lfrfid_raw_worker.c @@ -6,8 +6,8 @@ #include "lfrfid_raw_file.h" #include "tools/varint_pair.h" -#define EMULATE_BUFFER_SIZE 1024 -#define RFID_DATA_BUFFER_SIZE 2048 +#define EMULATE_BUFFER_SIZE 1024 +#define RFID_DATA_BUFFER_SIZE 2048 #define READ_DATA_BUFFER_COUNT 4 #define TAG_EMULATE "RawEmulate" diff --git a/lib/lfrfid/lfrfid_raw_worker.h b/lib/lfrfid/lfrfid_raw_worker.h index e145dcaa348..7bfe25cab69 100644 --- a/lib/lfrfid/lfrfid_raw_worker.h +++ b/lib/lfrfid/lfrfid_raw_worker.h @@ -65,4 +65,4 @@ void lfrfid_raw_worker_stop(LFRFIDRawWorker* worker); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/lfrfid/lfrfid_worker.c b/lib/lfrfid/lfrfid_worker.c index 3a0841cac4e..179c3c48fe3 100644 --- a/lib/lfrfid/lfrfid_worker.c +++ b/lib/lfrfid/lfrfid_worker.c @@ -141,7 +141,7 @@ void lfrfid_worker_stop_thread(LFRFIDWorker* worker) { bool lfrfid_worker_check_for_stop(LFRFIDWorker* worker) { UNUSED(worker); uint32_t flags = furi_thread_flags_get(); - return (flags & LFRFIDEventStopMode); + return flags & LFRFIDEventStopMode; } size_t lfrfid_worker_dict_get_data_size(LFRFIDWorker* worker, LFRFIDProtocol protocol) { diff --git a/lib/lfrfid/lfrfid_worker_modes.c b/lib/lfrfid/lfrfid_worker_modes.c index a017863b36c..aec19e37499 100644 --- a/lib/lfrfid/lfrfid_worker_modes.c +++ b/lib/lfrfid/lfrfid_worker_modes.c @@ -18,23 +18,23 @@ #ifdef LFRFID_WORKER_READ_DEBUG_GPIO #define LFRFID_WORKER_READ_DEBUG_GPIO_VALUE &gpio_ext_pa7 -#define LFRFID_WORKER_READ_DEBUG_GPIO_LOAD &gpio_ext_pa6 +#define LFRFID_WORKER_READ_DEBUG_GPIO_LOAD &gpio_ext_pa6 #endif #define LFRFID_WORKER_READ_AVERAGE_COUNT 64 -#define LFRFID_WORKER_READ_MIN_TIME_US 16 +#define LFRFID_WORKER_READ_MIN_TIME_US 16 -#define LFRFID_WORKER_READ_DROP_TIME_MS 50 +#define LFRFID_WORKER_READ_DROP_TIME_MS 50 #define LFRFID_WORKER_READ_STABILIZE_TIME_MS 450 -#define LFRFID_WORKER_READ_SWITCH_TIME_MS 2000 +#define LFRFID_WORKER_READ_SWITCH_TIME_MS 2000 -#define LFRFID_WORKER_WRITE_VERIFY_TIME_MS 2000 -#define LFRFID_WORKER_WRITE_DROP_TIME_MS 50 +#define LFRFID_WORKER_WRITE_VERIFY_TIME_MS 2000 +#define LFRFID_WORKER_WRITE_DROP_TIME_MS 50 #define LFRFID_WORKER_WRITE_TOO_LONG_TIME_MS 10000 #define LFRFID_WORKER_WRITE_MAX_UNSUCCESSFUL_READS 5 -#define LFRFID_WORKER_READ_BUFFER_SIZE 512 +#define LFRFID_WORKER_READ_BUFFER_SIZE 512 #define LFRFID_WORKER_READ_BUFFER_COUNT 16 #define LFRFID_WORKER_EMULATE_BUFFER_SIZE 1024 diff --git a/lib/lfrfid/protocols/protocol_awid.c b/lib/lfrfid/protocols/protocol_awid.c index b3e92245e42..299e5cab5e9 100644 --- a/lib/lfrfid/protocols/protocol_awid.c +++ b/lib/lfrfid/protocols/protocol_awid.c @@ -6,12 +6,12 @@ #include "lfrfid_protocols.h" #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) #define AWID_DECODED_DATA_SIZE (9) -#define AWID_ENCODED_BIT_SIZE (96) +#define AWID_ENCODED_BIT_SIZE (96) #define AWID_ENCODED_DATA_SIZE (((AWID_ENCODED_BIT_SIZE) / 8) + 1) #define AWID_ENCODED_DATA_LAST (AWID_ENCODED_DATA_SIZE - 1) @@ -37,21 +37,21 @@ ProtocolAwid* protocol_awid_alloc(void) { protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 50); return protocol; -}; +} void protocol_awid_free(ProtocolAwid* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_awid_get_data(ProtocolAwid* protocol) { return protocol->data; -}; +} void protocol_awid_decoder_start(ProtocolAwid* protocol) { memset(protocol->encoded_data, 0, AWID_ENCODED_DATA_SIZE); -}; +} static bool protocol_awid_can_be_decoded(uint8_t* data) { bool result = false; @@ -112,7 +112,7 @@ bool protocol_awid_decoder_feed(ProtocolAwid* protocol, bool level, uint32_t dur } return result; -}; +} static void protocol_awid_encode(const uint8_t* decoded_data, uint8_t* encoded_data) { memset(encoded_data, 0, AWID_ENCODED_DATA_SIZE); @@ -125,14 +125,14 @@ static void protocol_awid_encode(const uint8_t* decoded_data, uint8_t* encoded_d value |= bit_lib_test_parity_32(value, BitLibParityOdd); bit_lib_set_bits(encoded_data, 8 + i * 4, value, 4); } -}; +} bool protocol_awid_encoder_start(ProtocolAwid* protocol) { protocol_awid_encode(protocol->data, (uint8_t*)protocol->encoded_data); protocol->encoder.encoded_index = 0; fsk_osc_reset(protocol->encoder.fsk_osc); return true; -}; +} LevelDuration protocol_awid_encoder_yield(ProtocolAwid* protocol) { bool level; @@ -145,7 +145,7 @@ LevelDuration protocol_awid_encoder_yield(ProtocolAwid* protocol) { bit_lib_increment_index(protocol->encoder.encoded_index, AWID_ENCODED_BIT_SIZE); } return level_duration_make(level, duration); -}; +} void protocol_awid_render_data(ProtocolAwid* protocol, FuriString* result) { // Index map @@ -186,7 +186,7 @@ void protocol_awid_render_data(ProtocolAwid* protocol, FuriString* result) { furi_string_cat_printf(result, "%02hhX", decoded_data[i]); } } -}; +} void protocol_awid_render_brief_data(ProtocolAwid* protocol, FuriString* result) { uint8_t* decoded_data = protocol->data; @@ -210,7 +210,7 @@ void protocol_awid_render_brief_data(ProtocolAwid* protocol, FuriString* result) } else { furi_string_cat(result, "\nData: Unknown"); } -}; +} bool protocol_awid_write_data(ProtocolAwid* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -239,7 +239,7 @@ bool protocol_awid_write_data(ProtocolAwid* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_awid = { .name = "AWID", diff --git a/lib/lfrfid/protocols/protocol_awid.h b/lib/lfrfid/protocols/protocol_awid.h index 51a4ea52f59..4e694a37d48 100644 --- a/lib/lfrfid/protocols/protocol_awid.h +++ b/lib/lfrfid/protocols/protocol_awid.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_awid; \ No newline at end of file +extern const ProtocolBase protocol_awid; diff --git a/lib/lfrfid/protocols/protocol_electra.c b/lib/lfrfid/protocols/protocol_electra.c index f01b8f2ba3c..014c83d1f97 100644 --- a/lib/lfrfid/protocols/protocol_electra.c +++ b/lib/lfrfid/protocols/protocol_electra.c @@ -61,17 +61,17 @@ typedef uint64_t ElectraDecodedData; -#define EM_HEADER_POS (55) +#define EM_HEADER_POS (55) #define EM_HEADER_MASK (0x1FFLLU << EM_HEADER_POS) #define EM_FIRST_ROW_POS (50) -#define EM_ROW_COUNT (10) -#define EM_COLUMN_COUNT (4) +#define EM_ROW_COUNT (10) +#define EM_COLUMN_COUNT (4) #define EM_BITS_PER_ROW_COUNT (EM_COLUMN_COUNT + 1) -#define EM_COLUMN_POS (4) -#define ELECTRA_STOP_POS (0) +#define EM_COLUMN_POS (4) +#define ELECTRA_STOP_POS (0) #define ELECTRA_STOP_MASK (0x1LLU << ELECTRA_STOP_POS) #define EM_HEADER_AND_STOP_MASK (EM_HEADER_MASK | ELECTRA_STOP_MASK) @@ -90,14 +90,14 @@ typedef uint64_t ElectraDecodedData; #define ELECTRA_CLOCK_PER_BIT (64) -#define ELECTRA_READ_SHORT_TIME (256) -#define ELECTRA_READ_LONG_TIME (512) +#define ELECTRA_READ_SHORT_TIME (256) +#define ELECTRA_READ_LONG_TIME (512) #define ELECTRA_READ_JITTER_TIME (100) -#define ELECTRA_READ_SHORT_TIME_LOW (ELECTRA_READ_SHORT_TIME - ELECTRA_READ_JITTER_TIME) +#define ELECTRA_READ_SHORT_TIME_LOW (ELECTRA_READ_SHORT_TIME - ELECTRA_READ_JITTER_TIME) #define ELECTRA_READ_SHORT_TIME_HIGH (ELECTRA_READ_SHORT_TIME + ELECTRA_READ_JITTER_TIME) -#define ELECTRA_READ_LONG_TIME_LOW (ELECTRA_READ_LONG_TIME - ELECTRA_READ_JITTER_TIME) -#define ELECTRA_READ_LONG_TIME_HIGH (ELECTRA_READ_LONG_TIME + ELECTRA_READ_JITTER_TIME) +#define ELECTRA_READ_LONG_TIME_LOW (ELECTRA_READ_LONG_TIME - ELECTRA_READ_JITTER_TIME) +#define ELECTRA_READ_LONG_TIME_HIGH (ELECTRA_READ_LONG_TIME + ELECTRA_READ_JITTER_TIME) #define EM_ENCODED_DATA_HEADER (0xFF80000000000000ULL) @@ -116,15 +116,15 @@ typedef struct { ProtocolElectra* protocol_electra_alloc(void) { ProtocolElectra* proto = malloc(sizeof(ProtocolElectra)); return (void*)proto; -}; +} void protocol_electra_free(ProtocolElectra* proto) { free(proto); -}; +} uint8_t* protocol_electra_get_data(ProtocolElectra* proto) { return proto->data; -}; +} static void electra_decode( const uint8_t* encoded_base_data, @@ -198,7 +198,7 @@ static bool electra_can_be_decoded( parity_sum += (*base_data >> (EM_FIRST_ROW_POS - i * EM_BITS_PER_ROW_COUNT + j)) & 1; } - if((parity_sum % 2)) { + if(parity_sum % 2) { return false; } } @@ -211,7 +211,7 @@ static bool electra_can_be_decoded( parity_sum += (*base_data >> (EM_COLUMN_POS - i + j * EM_BITS_PER_ROW_COUNT)) & 1; } - if((parity_sum % 2)) { + if(parity_sum % 2) { FURI_LOG_D( TAG, "Unexpected column parity found. EM4100 data: %016llX", @@ -242,7 +242,7 @@ void protocol_electra_decoder_start(ProtocolElectra* proto) { ManchesterEventReset, &proto->decoder_manchester_state, NULL); -}; +} bool protocol_electra_decoder_feed(ProtocolElectra* proto, bool level, uint32_t duration) { bool result = false; @@ -299,7 +299,7 @@ bool protocol_electra_decoder_feed(ProtocolElectra* proto, bool level, uint32_t } return result; -}; +} static void em_write_nibble(bool low_nibble, uint8_t data, ElectraDecodedData* encoded_base_data) { uint8_t parity_sum = 0; @@ -354,7 +354,7 @@ bool protocol_electra_encoder_start(ProtocolElectra* proto) { } return true; -}; +} LevelDuration protocol_electra_encoder_yield(ProtocolElectra* proto) { bool level; @@ -378,7 +378,7 @@ LevelDuration protocol_electra_encoder_yield(ProtocolElectra* proto) { } return level_duration_make(level, duration); -}; +} bool protocol_electra_write_data(ProtocolElectra* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -408,12 +408,12 @@ bool protocol_electra_write_data(ProtocolElectra* protocol, void* data) { result = true; } return result; -}; +} void protocol_electra_render_data(ProtocolElectra* protocol, FuriString* result) { protocol_electra_encoder_start(protocol); furi_string_printf(result, "Epilogue: %016llX", protocol->encoded_epilogue); -}; +} const ProtocolBase protocol_electra = { .name = "Electra", @@ -437,4 +437,4 @@ const ProtocolBase protocol_electra = { .render_data = (ProtocolRenderData)protocol_electra_render_data, .render_brief_data = (ProtocolRenderData)protocol_electra_render_data, .write_data = (ProtocolWriteData)protocol_electra_write_data, -}; \ No newline at end of file +}; diff --git a/lib/lfrfid/protocols/protocol_electra.h b/lib/lfrfid/protocols/protocol_electra.h index 2c9f79285f3..b5aef5a0736 100644 --- a/lib/lfrfid/protocols/protocol_electra.h +++ b/lib/lfrfid/protocols/protocol_electra.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_electra; \ No newline at end of file +extern const ProtocolBase protocol_electra; diff --git a/lib/lfrfid/protocols/protocol_em4100.c b/lib/lfrfid/protocols/protocol_em4100.c index a4a403167a5..eca14c04663 100644 --- a/lib/lfrfid/protocols/protocol_em4100.c +++ b/lib/lfrfid/protocols/protocol_em4100.c @@ -6,18 +6,18 @@ typedef uint64_t EM4100DecodedData; typedef uint64_t EM4100Epilogue; -#define EM_HEADER_POS (55) +#define EM_HEADER_POS (55) #define EM_HEADER_MASK (0x1FFLLU << EM_HEADER_POS) #define EM_FIRST_ROW_POS (50) -#define EM_ROW_COUNT (10) -#define EM_COLUMN_COUNT (4) +#define EM_ROW_COUNT (10) +#define EM_COLUMN_COUNT (4) #define EM_BITS_PER_ROW_COUNT (EM_COLUMN_COUNT + 1) #define EM_COLUMN_POS (4) -#define EM_STOP_POS (0) -#define EM_STOP_MASK (0x1LLU << EM_STOP_POS) +#define EM_STOP_POS (0) +#define EM_STOP_MASK (0x1LLU << EM_STOP_POS) #define EM_HEADER_AND_STOP_MASK (EM_HEADER_MASK | EM_STOP_MASK) #define EM_HEADER_AND_STOP_DATA (EM_HEADER_MASK) @@ -25,8 +25,8 @@ typedef uint64_t EM4100Epilogue; #define EM4100_DECODED_DATA_SIZE (5) #define EM4100_ENCODED_DATA_SIZE (sizeof(EM4100DecodedData)) -#define EM_READ_SHORT_TIME_BASE (256) -#define EM_READ_LONG_TIME_BASE (512) +#define EM_READ_SHORT_TIME_BASE (256) +#define EM_READ_LONG_TIME_BASE (512) #define EM_READ_JITTER_TIME_BASE (100) #define EM_ENCODED_DATA_HEADER (0xFF80000000000000ULL) @@ -93,27 +93,27 @@ ProtocolEM4100* protocol_em4100_alloc(void) { ProtocolEM4100* proto = malloc(sizeof(ProtocolEM4100)); proto->clock_per_bit = 64; return (void*)proto; -}; +} ProtocolEM4100* protocol_em4100_16_alloc(void) { ProtocolEM4100* proto = malloc(sizeof(ProtocolEM4100)); proto->clock_per_bit = 16; return (void*)proto; -}; +} ProtocolEM4100* protocol_em4100_32_alloc(void) { ProtocolEM4100* proto = malloc(sizeof(ProtocolEM4100)); proto->clock_per_bit = 32; return (void*)proto; -}; +} void protocol_em4100_free(ProtocolEM4100* proto) { free(proto); -}; +} uint8_t* protocol_em4100_get_data(ProtocolEM4100* proto) { return proto->data; -}; +} static void em4100_decode( const uint8_t* encoded_data, @@ -173,7 +173,7 @@ static bool em4100_can_be_decoded( parity_sum += (*card_data >> (EM_FIRST_ROW_POS - i * EM_BITS_PER_ROW_COUNT + j)) & 1; } - if((parity_sum % 2)) { + if(parity_sum % 2) { return false; } } @@ -186,7 +186,7 @@ static bool em4100_can_be_decoded( parity_sum += (*card_data >> (EM_COLUMN_POS - i + j * EM_BITS_PER_ROW_COUNT)) & 1; } - if((parity_sum % 2)) { + if(parity_sum % 2) { return false; } } @@ -202,7 +202,7 @@ void protocol_em4100_decoder_start(ProtocolEM4100* proto) { ManchesterEventReset, &proto->decoder_manchester_state, NULL); -}; +} bool protocol_em4100_decoder_feed(ProtocolEM4100* proto, bool level, uint32_t duration) { bool result = false; @@ -252,7 +252,7 @@ bool protocol_em4100_decoder_feed(ProtocolEM4100* proto, bool level, uint32_t du } return result; -}; +} static void em4100_write_nibble(bool low_nibble, uint8_t data, EM4100DecodedData* encoded_data) { uint8_t parity_sum = 0; @@ -296,7 +296,7 @@ bool protocol_em4100_encoder_start(ProtocolEM4100* proto) { proto->encoded_polarity = true; return true; -}; +} LevelDuration protocol_em4100_encoder_yield(ProtocolEM4100* proto) { bool level = (proto->encoded_data >> (63 - proto->encoded_data_index)) & 1; @@ -315,7 +315,7 @@ LevelDuration protocol_em4100_encoder_yield(ProtocolEM4100* proto) { } return level_duration_make(level, duration); -}; +} bool protocol_em4100_write_data(ProtocolEM4100* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -341,7 +341,7 @@ bool protocol_em4100_write_data(ProtocolEM4100* protocol, void* data) { result = true; } return result; -}; +} void protocol_em4100_render_data(ProtocolEM4100* protocol, FuriString* result) { uint8_t* data = protocol->data; @@ -352,7 +352,7 @@ void protocol_em4100_render_data(ProtocolEM4100* protocol, FuriString* result) { data[2], (uint16_t)((data[3] << 8) | (data[4])), protocol->clock_per_bit); -}; +} const ProtocolBase protocol_em4100 = { .name = "EM4100", diff --git a/lib/lfrfid/protocols/protocol_fdx_a.c b/lib/lfrfid/protocols/protocol_fdx_a.c index f7852eb1013..9849a39b60f 100644 --- a/lib/lfrfid/protocols/protocol_fdx_a.c +++ b/lib/lfrfid/protocols/protocol_fdx_a.c @@ -6,16 +6,16 @@ #include #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) -#define FDXA_DATA_SIZE 10 +#define FDXA_DATA_SIZE 10 #define FDXA_PREAMBLE_SIZE 2 #define FDXA_ENCODED_DATA_SIZE (FDXA_PREAMBLE_SIZE + FDXA_DATA_SIZE + FDXA_PREAMBLE_SIZE) -#define FDXA_ENCODED_BIT_SIZE ((FDXA_PREAMBLE_SIZE + FDXA_DATA_SIZE) * 8) +#define FDXA_ENCODED_BIT_SIZE ((FDXA_PREAMBLE_SIZE + FDXA_DATA_SIZE) * 8) #define FDXA_DECODED_DATA_SIZE (5) -#define FDXA_DECODED_BIT_SIZE ((FDXA_ENCODED_BIT_SIZE - FDXA_PREAMBLE_SIZE * 8) / 2) +#define FDXA_DECODED_BIT_SIZE ((FDXA_ENCODED_BIT_SIZE - FDXA_PREAMBLE_SIZE * 8) / 2) #define FDXA_PREAMBLE_0 0x55 #define FDXA_PREAMBLE_1 0x1D @@ -44,21 +44,21 @@ ProtocolFDXA* protocol_fdx_a_alloc(void) { protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 50); return protocol; -}; +} void protocol_fdx_a_free(ProtocolFDXA* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_fdx_a_get_data(ProtocolFDXA* protocol) { return protocol->data; -}; +} void protocol_fdx_a_decoder_start(ProtocolFDXA* protocol) { memset(protocol->encoded_data, 0, FDXA_ENCODED_DATA_SIZE); -}; +} static bool protocol_fdx_a_decode(const uint8_t* from, uint8_t* to) { size_t bit_index = 0; @@ -104,7 +104,7 @@ static bool protocol_fdx_a_can_be_decoded(const uint8_t* data) { decoded_data[i] &= 0x7F; } - return (parity_sum == 0); + return parity_sum == 0; } bool protocol_fdx_a_decoder_feed(ProtocolFDXA* protocol, bool level, uint32_t duration) { @@ -124,7 +124,7 @@ bool protocol_fdx_a_decoder_feed(ProtocolFDXA* protocol, bool level, uint32_t du } return result; -}; +} static void protocol_fdx_a_encode(ProtocolFDXA* protocol) { protocol->encoded_data[0] = FDXA_PREAMBLE_0; @@ -150,7 +150,7 @@ bool protocol_fdx_a_encoder_start(ProtocolFDXA* protocol) { protocol_fdx_a_encode(protocol); return true; -}; +} LevelDuration protocol_fdx_a_encoder_yield(ProtocolFDXA* protocol) { bool level = 0; @@ -180,7 +180,7 @@ LevelDuration protocol_fdx_a_encoder_yield(ProtocolFDXA* protocol) { } return level_duration_make(level, duration); -}; +} bool protocol_fdx_a_write_data(ProtocolFDXA* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -203,7 +203,7 @@ bool protocol_fdx_a_write_data(ProtocolFDXA* protocol, void* data) { result = true; } return result; -}; +} void protocol_fdx_a_render_data(ProtocolFDXA* protocol, FuriString* result) { uint8_t data[FDXA_DECODED_DATA_SIZE]; @@ -221,7 +221,7 @@ void protocol_fdx_a_render_data(ProtocolFDXA* protocol, FuriString* result) { "Parity: %c", bit_lib_get_bits_64(data, 0, 40), parity_sum == 0 ? '+' : '-'); -}; +} const ProtocolBase protocol_fdx_a = { .name = "FDX-A", diff --git a/lib/lfrfid/protocols/protocol_fdx_a.h b/lib/lfrfid/protocols/protocol_fdx_a.h index 355544881c0..6eafb00557f 100644 --- a/lib/lfrfid/protocols/protocol_fdx_a.h +++ b/lib/lfrfid/protocols/protocol_fdx_a.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_fdx_a; \ No newline at end of file +extern const ProtocolBase protocol_fdx_a; diff --git a/lib/lfrfid/protocols/protocol_fdx_b.c b/lib/lfrfid/protocols/protocol_fdx_b.c index a5af855e484..3de2b661b3b 100644 --- a/lib/lfrfid/protocols/protocol_fdx_b.c +++ b/lib/lfrfid/protocols/protocol_fdx_b.c @@ -6,22 +6,22 @@ #include "lfrfid_protocols.h" #include -#define FDX_B_ENCODED_BIT_SIZE (128) -#define FDX_B_ENCODED_BYTE_SIZE (((FDX_B_ENCODED_BIT_SIZE) / 8)) -#define FDX_B_PREAMBLE_BIT_SIZE (11) -#define FDX_B_PREAMBLE_BYTE_SIZE (2) +#define FDX_B_ENCODED_BIT_SIZE (128) +#define FDX_B_ENCODED_BYTE_SIZE (((FDX_B_ENCODED_BIT_SIZE) / 8)) +#define FDX_B_PREAMBLE_BIT_SIZE (11) +#define FDX_B_PREAMBLE_BYTE_SIZE (2) #define FDX_B_ENCODED_BYTE_FULL_SIZE (FDX_B_ENCODED_BYTE_SIZE + FDX_B_PREAMBLE_BYTE_SIZE) #define FDXB_DECODED_DATA_SIZE (11) -#define FDX_B_SHORT_TIME (128) -#define FDX_B_LONG_TIME (256) +#define FDX_B_SHORT_TIME (128) +#define FDX_B_LONG_TIME (256) #define FDX_B_JITTER_TIME (60) -#define FDX_B_SHORT_TIME_LOW (FDX_B_SHORT_TIME - FDX_B_JITTER_TIME) +#define FDX_B_SHORT_TIME_LOW (FDX_B_SHORT_TIME - FDX_B_JITTER_TIME) #define FDX_B_SHORT_TIME_HIGH (FDX_B_SHORT_TIME + FDX_B_JITTER_TIME) -#define FDX_B_LONG_TIME_LOW (FDX_B_LONG_TIME - FDX_B_JITTER_TIME) -#define FDX_B_LONG_TIME_HIGH (FDX_B_LONG_TIME + FDX_B_JITTER_TIME) +#define FDX_B_LONG_TIME_LOW (FDX_B_LONG_TIME - FDX_B_JITTER_TIME) +#define FDX_B_LONG_TIME_HIGH (FDX_B_LONG_TIME + FDX_B_JITTER_TIME) typedef struct { bool last_short; @@ -34,20 +34,20 @@ typedef struct { ProtocolFDXB* protocol_fdx_b_alloc(void) { ProtocolFDXB* protocol = malloc(sizeof(ProtocolFDXB)); return protocol; -}; +} void protocol_fdx_b_free(ProtocolFDXB* protocol) { free(protocol); -}; +} uint8_t* protocol_fdx_b_get_data(ProtocolFDXB* proto) { return proto->data; -}; +} void protocol_fdx_b_decoder_start(ProtocolFDXB* protocol) { memset(protocol->encoded_data, 0, FDX_B_ENCODED_BYTE_FULL_SIZE); protocol->last_short = false; -}; +} static bool protocol_fdx_b_can_be_decoded(ProtocolFDXB* protocol) { bool result = false; @@ -179,7 +179,7 @@ bool protocol_fdx_b_decoder_feed(ProtocolFDXB* protocol, bool level, uint32_t du } return result; -}; +} bool protocol_fdx_b_encoder_start(ProtocolFDXB* protocol) { memset(protocol->encoded_data, 0, FDX_B_ENCODED_BYTE_FULL_SIZE); @@ -203,7 +203,7 @@ bool protocol_fdx_b_encoder_start(ProtocolFDXB* protocol) { protocol->last_short = false; protocol->last_level = false; return true; -}; +} LevelDuration protocol_fdx_b_encoder_yield(ProtocolFDXB* protocol) { uint32_t duration; @@ -228,7 +228,7 @@ LevelDuration protocol_fdx_b_encoder_yield(ProtocolFDXB* protocol) { } return level_duration_make(protocol->last_level, duration); -}; +} // 0 nnnnnnnn // 8 nnnnnnnn 38 bit (12 digit) National code. @@ -320,7 +320,7 @@ void protocol_fdx_b_render_data(ProtocolFDXB* protocol, FuriString* result) { reserved, user_info, replacement_number); -}; +} void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result) { // 38 bits of national code @@ -348,7 +348,7 @@ void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result } else { furi_string_cat(result, "---"); } -}; +} bool protocol_fdx_b_write_data(ProtocolFDXB* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -371,7 +371,7 @@ bool protocol_fdx_b_write_data(ProtocolFDXB* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_fdx_b = { .name = "FDX-B", diff --git a/lib/lfrfid/protocols/protocol_fdx_b.h b/lib/lfrfid/protocols/protocol_fdx_b.h index 549c862e380..78a171db4ea 100644 --- a/lib/lfrfid/protocols/protocol_fdx_b.h +++ b/lib/lfrfid/protocols/protocol_fdx_b.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_fdx_b; \ No newline at end of file +extern const ProtocolBase protocol_fdx_b; diff --git a/lib/lfrfid/protocols/protocol_gallagher.c b/lib/lfrfid/protocols/protocol_gallagher.c index b00c14acd16..9ae0cf80acf 100644 --- a/lib/lfrfid/protocols/protocol_gallagher.c +++ b/lib/lfrfid/protocols/protocol_gallagher.c @@ -6,22 +6,22 @@ #define GALLAGHER_CLOCK_PER_BIT (32) -#define GALLAGHER_ENCODED_BIT_SIZE (96) -#define GALLAGHER_ENCODED_BYTE_SIZE ((GALLAGHER_ENCODED_BIT_SIZE) / 8) -#define GALLAGHER_PREAMBLE_BIT_SIZE (16) +#define GALLAGHER_ENCODED_BIT_SIZE (96) +#define GALLAGHER_ENCODED_BYTE_SIZE ((GALLAGHER_ENCODED_BIT_SIZE) / 8) +#define GALLAGHER_PREAMBLE_BIT_SIZE (16) #define GALLAGHER_PREAMBLE_BYTE_SIZE ((GALLAGHER_PREAMBLE_BIT_SIZE) / 8) #define GALLAGHER_ENCODED_BYTE_FULL_SIZE \ (GALLAGHER_ENCODED_BYTE_SIZE + GALLAGHER_PREAMBLE_BYTE_SIZE) #define GALLAGHER_DECODED_DATA_SIZE 8 -#define GALLAGHER_READ_SHORT_TIME (128) -#define GALLAGHER_READ_LONG_TIME (256) +#define GALLAGHER_READ_SHORT_TIME (128) +#define GALLAGHER_READ_LONG_TIME (256) #define GALLAGHER_READ_JITTER_TIME (60) -#define GALLAGHER_READ_SHORT_TIME_LOW (GALLAGHER_READ_SHORT_TIME - GALLAGHER_READ_JITTER_TIME) +#define GALLAGHER_READ_SHORT_TIME_LOW (GALLAGHER_READ_SHORT_TIME - GALLAGHER_READ_JITTER_TIME) #define GALLAGHER_READ_SHORT_TIME_HIGH (GALLAGHER_READ_SHORT_TIME + GALLAGHER_READ_JITTER_TIME) -#define GALLAGHER_READ_LONG_TIME_LOW (GALLAGHER_READ_LONG_TIME - GALLAGHER_READ_JITTER_TIME) -#define GALLAGHER_READ_LONG_TIME_HIGH (GALLAGHER_READ_LONG_TIME + GALLAGHER_READ_JITTER_TIME) +#define GALLAGHER_READ_LONG_TIME_LOW (GALLAGHER_READ_LONG_TIME - GALLAGHER_READ_JITTER_TIME) +#define GALLAGHER_READ_LONG_TIME_HIGH (GALLAGHER_READ_LONG_TIME + GALLAGHER_READ_JITTER_TIME) typedef struct { uint8_t data[GALLAGHER_DECODED_DATA_SIZE]; @@ -36,15 +36,15 @@ typedef struct { ProtocolGallagher* protocol_gallagher_alloc(void) { ProtocolGallagher* proto = malloc(sizeof(ProtocolGallagher)); return (void*)proto; -}; +} void protocol_gallagher_free(ProtocolGallagher* protocol) { free(protocol); -}; +} uint8_t* protocol_gallagher_get_data(ProtocolGallagher* protocol) { return protocol->data; -}; +} static void protocol_gallagher_scramble(uint8_t* data, size_t length) { const uint8_t lut[] = { @@ -152,7 +152,7 @@ void protocol_gallagher_decoder_start(ProtocolGallagher* protocol) { ManchesterEventReset, &protocol->decoder_manchester_state, NULL); -}; +} bool protocol_gallagher_decoder_feed(ProtocolGallagher* protocol, bool level, uint32_t duration) { bool result = false; @@ -189,7 +189,7 @@ bool protocol_gallagher_decoder_feed(ProtocolGallagher* protocol, bool level, ui } return result; -}; +} bool protocol_gallagher_encoder_start(ProtocolGallagher* protocol) { // Preamble @@ -227,7 +227,7 @@ bool protocol_gallagher_encoder_start(ProtocolGallagher* protocol) { bit_lib_set_bits(protocol->encoded_data, 16 + (9 * 8), crc, 8); return true; -}; +} LevelDuration protocol_gallagher_encoder_yield(ProtocolGallagher* protocol) { bool level = bit_lib_get_bit(protocol->encoded_data, protocol->encoded_data_index); @@ -243,7 +243,7 @@ LevelDuration protocol_gallagher_encoder_yield(ProtocolGallagher* protocol) { } return level_duration_make(level, duration); -}; +} bool protocol_gallagher_write_data(ProtocolGallagher* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -266,7 +266,7 @@ bool protocol_gallagher_write_data(ProtocolGallagher* protocol, void* data) { result = true; } return result; -}; +} static void protocol_gallagher_render_data_internal( ProtocolGallagher* protocol, @@ -296,7 +296,7 @@ static void protocol_gallagher_render_data_internal( region, issue_level); } -}; +} void protocol_gallagher_render_data(ProtocolGallagher* protocol, FuriString* result) { protocol_gallagher_render_data_internal(protocol, result, false); diff --git a/lib/lfrfid/protocols/protocol_gallagher.h b/lib/lfrfid/protocols/protocol_gallagher.h index 2d922f605e4..f9fef9ea078 100644 --- a/lib/lfrfid/protocols/protocol_gallagher.h +++ b/lib/lfrfid/protocols/protocol_gallagher.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_gallagher; \ No newline at end of file +extern const ProtocolBase protocol_gallagher; diff --git a/lib/lfrfid/protocols/protocol_h10301.c b/lib/lfrfid/protocols/protocol_h10301.c index 6c6d5771ac8..66f1c617db3 100644 --- a/lib/lfrfid/protocols/protocol_h10301.c +++ b/lib/lfrfid/protocols/protocol_h10301.c @@ -5,14 +5,14 @@ #include "lfrfid_protocols.h" #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) -#define H10301_DECODED_DATA_SIZE (3) +#define H10301_DECODED_DATA_SIZE (3) #define H10301_ENCODED_DATA_SIZE_U32 (3) -#define H10301_ENCODED_DATA_SIZE (sizeof(uint32_t) * H10301_ENCODED_DATA_SIZE_U32) +#define H10301_ENCODED_DATA_SIZE (sizeof(uint32_t) * H10301_ENCODED_DATA_SIZE_U32) -#define H10301_BIT_SIZE (sizeof(uint32_t) * 8) +#define H10301_BIT_SIZE (sizeof(uint32_t) * 8) #define H10301_BIT_MAX_SIZE (H10301_BIT_SIZE * H10301_DECODED_DATA_SIZE) typedef struct { @@ -38,21 +38,21 @@ ProtocolH10301* protocol_h10301_alloc(void) { protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 50); return protocol; -}; +} void protocol_h10301_free(ProtocolH10301* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_h10301_get_data(ProtocolH10301* protocol) { return protocol->data; -}; +} void protocol_h10301_decoder_start(ProtocolH10301* protocol) { memset(protocol->encoded_data, 0, sizeof(uint32_t) * 3); -}; +} static void protocol_h10301_decoder_store_data(ProtocolH10301* protocol, bool data) { protocol->encoded_data[0] = (protocol->encoded_data[0] << 1) | @@ -205,7 +205,7 @@ bool protocol_h10301_decoder_feed(ProtocolH10301* protocol, bool level, uint32_t } return result; -}; +} static void protocol_h10301_write_raw_bit(bool bit, uint8_t position, uint32_t* card_data) { if(bit) { @@ -295,7 +295,7 @@ bool protocol_h10301_encoder_start(ProtocolH10301* protocol) { protocol->encoder.pulse = 0; return true; -}; +} LevelDuration protocol_h10301_encoder_yield(ProtocolH10301* protocol) { bool level = 0; @@ -331,7 +331,7 @@ LevelDuration protocol_h10301_encoder_yield(ProtocolH10301* protocol) { } return level_duration_make(level, duration); -}; +} bool protocol_h10301_write_data(ProtocolH10301* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -353,7 +353,7 @@ bool protocol_h10301_write_data(ProtocolH10301* protocol, void* data) { result = true; } return result; -}; +} void protocol_h10301_render_data(ProtocolH10301* protocol, FuriString* result) { uint8_t* data = protocol->data; @@ -363,7 +363,7 @@ void protocol_h10301_render_data(ProtocolH10301* protocol, FuriString* result) { "Card: %hu", data[0], (uint16_t)((data[1] << 8) | (data[2]))); -}; +} const ProtocolBase protocol_h10301 = { .name = "H10301", diff --git a/lib/lfrfid/protocols/protocol_h10301.h b/lib/lfrfid/protocols/protocol_h10301.h index b7ee5ad57d9..03073308eb1 100644 --- a/lib/lfrfid/protocols/protocol_h10301.h +++ b/lib/lfrfid/protocols/protocol_h10301.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_h10301; \ No newline at end of file +extern const ProtocolBase protocol_h10301; diff --git a/lib/lfrfid/protocols/protocol_hid_ex_generic.c b/lib/lfrfid/protocols/protocol_hid_ex_generic.c index efc7a5190ca..936a194b875 100644 --- a/lib/lfrfid/protocols/protocol_hid_ex_generic.c +++ b/lib/lfrfid/protocols/protocol_hid_ex_generic.c @@ -6,16 +6,16 @@ #include #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) -#define HID_DATA_SIZE 23 +#define HID_DATA_SIZE 23 #define HID_PREAMBLE_SIZE 1 #define HID_ENCODED_DATA_SIZE (HID_PREAMBLE_SIZE + HID_DATA_SIZE + HID_PREAMBLE_SIZE) -#define HID_ENCODED_BIT_SIZE ((HID_PREAMBLE_SIZE + HID_DATA_SIZE) * 8) +#define HID_ENCODED_BIT_SIZE ((HID_PREAMBLE_SIZE + HID_DATA_SIZE) * 8) #define HID_DECODED_DATA_SIZE (12) -#define HID_DECODED_BIT_SIZE ((HID_ENCODED_BIT_SIZE - HID_PREAMBLE_SIZE * 8) / 2) +#define HID_DECODED_BIT_SIZE ((HID_ENCODED_BIT_SIZE - HID_PREAMBLE_SIZE * 8) / 2) #define HID_PREAMBLE 0x1D @@ -43,21 +43,21 @@ ProtocolHIDEx* protocol_hid_ex_generic_alloc(void) { protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 50); return protocol; -}; +} void protocol_hid_ex_generic_free(ProtocolHIDEx* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_hid_ex_generic_get_data(ProtocolHIDEx* protocol) { return protocol->data; -}; +} void protocol_hid_ex_generic_decoder_start(ProtocolHIDEx* protocol) { memset(protocol->encoded_data, 0, HID_ENCODED_DATA_SIZE); -}; +} static bool protocol_hid_ex_generic_can_be_decoded(const uint8_t* data) { // check preamble @@ -110,7 +110,7 @@ bool protocol_hid_ex_generic_decoder_feed(ProtocolHIDEx* protocol, bool level, u } return result; -}; +} static void protocol_hid_ex_generic_encode(ProtocolHIDEx* protocol) { protocol->encoded_data[0] = HID_PREAMBLE; @@ -135,7 +135,7 @@ bool protocol_hid_ex_generic_encoder_start(ProtocolHIDEx* protocol) { protocol_hid_ex_generic_encode(protocol); return true; -}; +} LevelDuration protocol_hid_ex_generic_encoder_yield(ProtocolHIDEx* protocol) { bool level = 0; @@ -165,7 +165,7 @@ LevelDuration protocol_hid_ex_generic_encoder_yield(ProtocolHIDEx* protocol) { } return level_duration_make(level, duration); -}; +} bool protocol_hid_ex_generic_write_data(ProtocolHIDEx* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -190,7 +190,7 @@ bool protocol_hid_ex_generic_write_data(ProtocolHIDEx* protocol, void* data) { result = true; } return result; -}; +} void protocol_hid_ex_generic_render_data(ProtocolHIDEx* protocol, FuriString* result) { UNUSED(protocol); @@ -200,7 +200,7 @@ void protocol_hid_ex_generic_render_data(ProtocolHIDEx* protocol, FuriString* re result, "Type: Generic HID Extended\n" "Data: Unknown"); -}; +} const ProtocolBase protocol_hid_ex_generic = { .name = "HIDExt", diff --git a/lib/lfrfid/protocols/protocol_hid_ex_generic.h b/lib/lfrfid/protocols/protocol_hid_ex_generic.h index 9c4ddffff3e..34877b8a33c 100644 --- a/lib/lfrfid/protocols/protocol_hid_ex_generic.h +++ b/lib/lfrfid/protocols/protocol_hid_ex_generic.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_hid_ex_generic; \ No newline at end of file +extern const ProtocolBase protocol_hid_ex_generic; diff --git a/lib/lfrfid/protocols/protocol_hid_generic.c b/lib/lfrfid/protocols/protocol_hid_generic.c index 1a95288855a..b7d58d6fd77 100644 --- a/lib/lfrfid/protocols/protocol_hid_generic.c +++ b/lib/lfrfid/protocols/protocol_hid_generic.c @@ -6,17 +6,17 @@ #include #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) -#define HID_DATA_SIZE 11 -#define HID_PREAMBLE_SIZE 1 +#define HID_DATA_SIZE 11 +#define HID_PREAMBLE_SIZE 1 #define HID_PROTOCOL_SIZE_UNKNOWN 0 #define HID_ENCODED_DATA_SIZE (HID_PREAMBLE_SIZE + HID_DATA_SIZE + HID_PREAMBLE_SIZE) -#define HID_ENCODED_BIT_SIZE ((HID_PREAMBLE_SIZE + HID_DATA_SIZE) * 8) +#define HID_ENCODED_BIT_SIZE ((HID_PREAMBLE_SIZE + HID_DATA_SIZE) * 8) #define HID_DECODED_DATA_SIZE (6) -#define HID_DECODED_BIT_SIZE ((HID_ENCODED_BIT_SIZE - HID_PREAMBLE_SIZE * 8) / 2) +#define HID_DECODED_BIT_SIZE ((HID_ENCODED_BIT_SIZE - HID_PREAMBLE_SIZE * 8) / 2) #define HID_PREAMBLE 0x1D @@ -43,21 +43,21 @@ ProtocolHID* protocol_hid_generic_alloc(void) { protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 50); return protocol; -}; +} void protocol_hid_generic_free(ProtocolHID* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_hid_generic_get_data(ProtocolHID* protocol) { return protocol->data; -}; +} void protocol_hid_generic_decoder_start(ProtocolHID* protocol) { memset(protocol->encoded_data, 0, HID_ENCODED_DATA_SIZE); -}; +} static bool protocol_hid_generic_can_be_decoded(const uint8_t* data) { // check preamble @@ -142,7 +142,7 @@ bool protocol_hid_generic_decoder_feed(ProtocolHID* protocol, bool level, uint32 } return result; -}; +} static void protocol_hid_generic_encode(ProtocolHID* protocol) { protocol->encoded_data[0] = HID_PREAMBLE; @@ -167,7 +167,7 @@ bool protocol_hid_generic_encoder_start(ProtocolHID* protocol) { protocol_hid_generic_encode(protocol); return true; -}; +} LevelDuration protocol_hid_generic_encoder_yield(ProtocolHID* protocol) { bool level = 0; @@ -197,7 +197,7 @@ LevelDuration protocol_hid_generic_encoder_yield(ProtocolHID* protocol) { } return level_duration_make(level, duration); -}; +} bool protocol_hid_generic_write_data(ProtocolHID* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -219,7 +219,7 @@ bool protocol_hid_generic_write_data(ProtocolHID* protocol, void* data) { result = true; } return result; -}; +} static void protocol_hid_generic_string_cat_protocol_bits( ProtocolHID* protocol, @@ -261,7 +261,7 @@ void protocol_hid_generic_render_data(ProtocolHID* protocol, FuriString* result) protocol_size); protocol_hid_generic_string_cat_protocol_bits(protocol, protocol_size, result); } -}; +} const ProtocolBase protocol_hid_generic = { .name = "HIDProx", diff --git a/lib/lfrfid/protocols/protocol_hid_generic.h b/lib/lfrfid/protocols/protocol_hid_generic.h index 22e78a4d34f..4ffa5dabbb6 100644 --- a/lib/lfrfid/protocols/protocol_hid_generic.h +++ b/lib/lfrfid/protocols/protocol_hid_generic.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_hid_generic; \ No newline at end of file +extern const ProtocolBase protocol_hid_generic; diff --git a/lib/lfrfid/protocols/protocol_idteck.c b/lib/lfrfid/protocols/protocol_idteck.c index 2075576bae8..0fb654597db 100644 --- a/lib/lfrfid/protocols/protocol_idteck.c +++ b/lib/lfrfid/protocols/protocol_idteck.c @@ -8,17 +8,17 @@ // 4 9 4 4 5 4 4 B 3 5 1 F B E 4 B // 0100 1001 0100 0100 0101 0100 0100 1011 0011 0101 0001 1111 1011 1110 0100 1011 -#define IDTECK_PREAMBLE_BIT_SIZE (32) +#define IDTECK_PREAMBLE_BIT_SIZE (32) #define IDTECK_PREAMBLE_DATA_SIZE (8) -#define IDTECK_ENCODED_BIT_SIZE (64) +#define IDTECK_ENCODED_BIT_SIZE (64) #define IDTECK_ENCODED_DATA_SIZE (((IDTECK_ENCODED_BIT_SIZE) / 8) + IDTECK_PREAMBLE_DATA_SIZE) #define IDTECK_ENCODED_DATA_LAST ((IDTECK_ENCODED_BIT_SIZE) / 8) -#define IDTECK_DECODED_BIT_SIZE (64) +#define IDTECK_DECODED_BIT_SIZE (64) #define IDTECK_DECODED_DATA_SIZE (8) -#define IDTECK_US_PER_BIT (255) +#define IDTECK_US_PER_BIT (255) #define IDTECK_ENCODER_PULSES_PER_BIT (16) typedef struct { @@ -42,22 +42,22 @@ typedef struct { ProtocolIdteck* protocol_idteck_alloc(void) { ProtocolIdteck* protocol = malloc(sizeof(ProtocolIdteck)); return protocol; -}; +} void protocol_idteck_free(ProtocolIdteck* protocol) { free(protocol); -}; +} uint8_t* protocol_idteck_get_data(ProtocolIdteck* protocol) { return protocol->data; -}; +} void protocol_idteck_decoder_start(ProtocolIdteck* protocol) { memset(protocol->encoded_data, 0, IDTECK_ENCODED_DATA_SIZE); memset(protocol->negative_encoded_data, 0, IDTECK_ENCODED_DATA_SIZE); memset(protocol->corrupted_encoded_data, 0, IDTECK_ENCODED_DATA_SIZE); memset(protocol->corrupted_negative_encoded_data, 0, IDTECK_ENCODED_DATA_SIZE); -}; +} static bool protocol_idteck_check_preamble(uint8_t* data, size_t bit_index) { // Preamble 01001001 01000100 01010100 01001011 @@ -144,7 +144,7 @@ bool protocol_idteck_decoder_feed(ProtocolIdteck* protocol, bool level, uint32_t } return result; -}; +} bool protocol_idteck_encoder_start(ProtocolIdteck* protocol) { memset(protocol->encoded_data, 0, IDTECK_ENCODED_DATA_SIZE); @@ -159,7 +159,7 @@ bool protocol_idteck_encoder_start(ProtocolIdteck* protocol) { protocol->encoder.bit_clock_index = 0; return true; -}; +} LevelDuration protocol_idteck_encoder_yield(ProtocolIdteck* protocol) { LevelDuration level_duration; @@ -189,7 +189,7 @@ LevelDuration protocol_idteck_encoder_yield(ProtocolIdteck* protocol) { } return level_duration; -}; +} // factory code static uint32_t get_fc(const uint8_t* data) { @@ -232,7 +232,7 @@ bool protocol_idteck_write_data(ProtocolIdteck* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_idteck = { .name = "Idteck", diff --git a/lib/lfrfid/protocols/protocol_indala26.c b/lib/lfrfid/protocols/protocol_indala26.c index 893361abb2c..d0a711daad1 100644 --- a/lib/lfrfid/protocols/protocol_indala26.c +++ b/lib/lfrfid/protocols/protocol_indala26.c @@ -3,7 +3,7 @@ #include #include "lfrfid_protocols.h" -#define INDALA26_PREAMBLE_BIT_SIZE (33) +#define INDALA26_PREAMBLE_BIT_SIZE (33) #define INDALA26_PREAMBLE_DATA_SIZE (5) #define INDALA26_ENCODED_BIT_SIZE (64) @@ -11,10 +11,10 @@ (((INDALA26_ENCODED_BIT_SIZE) / 8) + INDALA26_PREAMBLE_DATA_SIZE) #define INDALA26_ENCODED_DATA_LAST ((INDALA26_ENCODED_BIT_SIZE) / 8) -#define INDALA26_DECODED_BIT_SIZE (28) +#define INDALA26_DECODED_BIT_SIZE (28) #define INDALA26_DECODED_DATA_SIZE (4) -#define INDALA26_US_PER_BIT (255) +#define INDALA26_US_PER_BIT (255) #define INDALA26_ENCODER_PULSES_PER_BIT (16) typedef struct { @@ -38,22 +38,22 @@ typedef struct { ProtocolIndala* protocol_indala26_alloc(void) { ProtocolIndala* protocol = malloc(sizeof(ProtocolIndala)); return protocol; -}; +} void protocol_indala26_free(ProtocolIndala* protocol) { free(protocol); -}; +} uint8_t* protocol_indala26_get_data(ProtocolIndala* protocol) { return protocol->data; -}; +} void protocol_indala26_decoder_start(ProtocolIndala* protocol) { memset(protocol->encoded_data, 0, INDALA26_ENCODED_DATA_SIZE); memset(protocol->negative_encoded_data, 0, INDALA26_ENCODED_DATA_SIZE); memset(protocol->corrupted_encoded_data, 0, INDALA26_ENCODED_DATA_SIZE); memset(protocol->corrupted_negative_encoded_data, 0, INDALA26_ENCODED_DATA_SIZE); -}; +} static bool protocol_indala26_check_preamble(uint8_t* data, size_t bit_index) { // Preamble 10100000 00000000 00000000 00000000 1 @@ -146,7 +146,7 @@ bool protocol_indala26_decoder_feed(ProtocolIndala* protocol, bool level, uint32 } return result; -}; +} bool protocol_indala26_encoder_start(ProtocolIndala* protocol) { memset(protocol->encoded_data, 0, INDALA26_ENCODED_DATA_SIZE); @@ -164,7 +164,7 @@ bool protocol_indala26_encoder_start(ProtocolIndala* protocol) { protocol->encoder.bit_clock_index = 0; return true; -}; +} LevelDuration protocol_indala26_encoder_yield(ProtocolIndala* protocol) { LevelDuration level_duration; @@ -194,7 +194,7 @@ LevelDuration protocol_indala26_encoder_yield(ProtocolIndala* protocol) { } return level_duration; -}; +} // factory code static uint8_t get_fc(const uint8_t* data) { @@ -328,7 +328,7 @@ bool protocol_indala26_write_data(ProtocolIndala* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_indala26 = { .name = "Indala26", diff --git a/lib/lfrfid/protocols/protocol_io_prox_xsf.c b/lib/lfrfid/protocols/protocol_io_prox_xsf.c index b41cb66f3da..bce4e817dcc 100644 --- a/lib/lfrfid/protocols/protocol_io_prox_xsf.c +++ b/lib/lfrfid/protocols/protocol_io_prox_xsf.c @@ -6,13 +6,13 @@ #include "lfrfid_protocols.h" #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) #define IOPROXXSF_DECODED_DATA_SIZE (4) #define IOPROXXSF_ENCODED_DATA_SIZE (8) -#define IOPROXXSF_BIT_SIZE (8) +#define IOPROXXSF_BIT_SIZE (8) #define IOPROXXSF_BIT_MAX_SIZE (IOPROXXSF_BIT_SIZE * IOPROXXSF_ENCODED_DATA_SIZE) typedef struct { @@ -36,21 +36,21 @@ ProtocolIOProxXSF* protocol_io_prox_xsf_alloc(void) { protocol->decoder.fsk_demod = fsk_demod_alloc(MIN_TIME, 8, MAX_TIME, 6); protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 64); return protocol; -}; +} void protocol_io_prox_xsf_free(ProtocolIOProxXSF* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_io_prox_xsf_get_data(ProtocolIOProxXSF* protocol) { return protocol->data; -}; +} void protocol_io_prox_xsf_decoder_start(ProtocolIOProxXSF* protocol) { memset(protocol->encoded_data, 0, IOPROXXSF_ENCODED_DATA_SIZE); -}; +} static uint8_t protocol_io_prox_xsf_compute_checksum(const uint8_t* data) { // Packet structure: @@ -172,7 +172,7 @@ bool protocol_io_prox_xsf_decoder_feed(ProtocolIOProxXSF* protocol, bool level, } return result; -}; +} static void protocol_io_prox_xsf_encode(const uint8_t* decoded_data, uint8_t* encoded_data) { // Packet to transmit: @@ -217,7 +217,7 @@ bool protocol_io_prox_xsf_encoder_start(ProtocolIOProxXSF* protocol) { protocol->encoder.encoded_index = 0; fsk_osc_reset(protocol->encoder.fsk_osc); return true; -}; +} LevelDuration protocol_io_prox_xsf_encoder_yield(ProtocolIOProxXSF* protocol) { bool level; @@ -230,7 +230,7 @@ LevelDuration protocol_io_prox_xsf_encoder_yield(ProtocolIOProxXSF* protocol) { bit_lib_increment_index(protocol->encoder.encoded_index, IOPROXXSF_BIT_MAX_SIZE); } return level_duration_make(level, duration); -}; +} void protocol_io_prox_xsf_render_data(ProtocolIOProxXSF* protocol, FuriString* result) { uint8_t* data = protocol->data; @@ -274,7 +274,7 @@ bool protocol_io_prox_xsf_write_data(ProtocolIOProxXSF* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_io_prox_xsf = { .name = "IoProxXSF", diff --git a/lib/lfrfid/protocols/protocol_jablotron.c b/lib/lfrfid/protocols/protocol_jablotron.c index c2cbb417443..643bb1be681 100644 --- a/lib/lfrfid/protocols/protocol_jablotron.c +++ b/lib/lfrfid/protocols/protocol_jablotron.c @@ -5,23 +5,23 @@ #include #include "lfrfid_protocols.h" -#define JABLOTRON_ENCODED_BIT_SIZE (64) -#define JABLOTRON_ENCODED_BYTE_SIZE (((JABLOTRON_ENCODED_BIT_SIZE) / 8)) -#define JABLOTRON_PREAMBLE_BIT_SIZE (16) +#define JABLOTRON_ENCODED_BIT_SIZE (64) +#define JABLOTRON_ENCODED_BYTE_SIZE (((JABLOTRON_ENCODED_BIT_SIZE) / 8)) +#define JABLOTRON_PREAMBLE_BIT_SIZE (16) #define JABLOTRON_PREAMBLE_BYTE_SIZE (2) #define JABLOTRON_ENCODED_BYTE_FULL_SIZE \ (JABLOTRON_ENCODED_BYTE_SIZE + JABLOTRON_PREAMBLE_BYTE_SIZE) #define JABLOTRON_DECODED_DATA_SIZE (5) -#define JABLOTRON_SHORT_TIME (256) -#define JABLOTRON_LONG_TIME (512) +#define JABLOTRON_SHORT_TIME (256) +#define JABLOTRON_LONG_TIME (512) #define JABLOTRON_JITTER_TIME (120) -#define JABLOTRON_SHORT_TIME_LOW (JABLOTRON_SHORT_TIME - JABLOTRON_JITTER_TIME) +#define JABLOTRON_SHORT_TIME_LOW (JABLOTRON_SHORT_TIME - JABLOTRON_JITTER_TIME) #define JABLOTRON_SHORT_TIME_HIGH (JABLOTRON_SHORT_TIME + JABLOTRON_JITTER_TIME) -#define JABLOTRON_LONG_TIME_LOW (JABLOTRON_LONG_TIME - JABLOTRON_JITTER_TIME) -#define JABLOTRON_LONG_TIME_HIGH (JABLOTRON_LONG_TIME + JABLOTRON_JITTER_TIME) +#define JABLOTRON_LONG_TIME_LOW (JABLOTRON_LONG_TIME - JABLOTRON_JITTER_TIME) +#define JABLOTRON_LONG_TIME_HIGH (JABLOTRON_LONG_TIME + JABLOTRON_JITTER_TIME) typedef struct { bool last_short; @@ -34,20 +34,20 @@ typedef struct { ProtocolJablotron* protocol_jablotron_alloc(void) { ProtocolJablotron* protocol = malloc(sizeof(ProtocolJablotron)); return protocol; -}; +} void protocol_jablotron_free(ProtocolJablotron* protocol) { free(protocol); -}; +} uint8_t* protocol_jablotron_get_data(ProtocolJablotron* proto) { return proto->data; -}; +} void protocol_jablotron_decoder_start(ProtocolJablotron* protocol) { memset(protocol->encoded_data, 0, JABLOTRON_ENCODED_BYTE_FULL_SIZE); protocol->last_short = false; -}; +} uint8_t protocol_jablotron_checksum(uint8_t* bits) { uint8_t chksum = 0; @@ -115,7 +115,7 @@ bool protocol_jablotron_decoder_feed(ProtocolJablotron* protocol, bool level, ui } return false; -}; +} bool protocol_jablotron_encoder_start(ProtocolJablotron* protocol) { // preamble @@ -133,7 +133,7 @@ bool protocol_jablotron_encoder_start(ProtocolJablotron* protocol) { protocol->last_short = false; protocol->last_level = false; return true; -}; +} LevelDuration protocol_jablotron_encoder_yield(ProtocolJablotron* protocol) { uint32_t duration; @@ -158,12 +158,12 @@ LevelDuration protocol_jablotron_encoder_yield(ProtocolJablotron* protocol) { } return level_duration_make(protocol->last_level, duration); -}; +} void protocol_jablotron_render_data(ProtocolJablotron* protocol, FuriString* result) { uint64_t id = protocol_jablotron_card_id(protocol->data); furi_string_printf(result, "Card: %llX", id); -}; +} bool protocol_jablotron_write_data(ProtocolJablotron* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -184,7 +184,7 @@ bool protocol_jablotron_write_data(ProtocolJablotron* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_jablotron = { .name = "Jablotron", diff --git a/lib/lfrfid/protocols/protocol_jablotron.h b/lib/lfrfid/protocols/protocol_jablotron.h index 4de57de42a5..08b96c20bd0 100644 --- a/lib/lfrfid/protocols/protocol_jablotron.h +++ b/lib/lfrfid/protocols/protocol_jablotron.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_jablotron; \ No newline at end of file +extern const ProtocolBase protocol_jablotron; diff --git a/lib/lfrfid/protocols/protocol_keri.c b/lib/lfrfid/protocols/protocol_keri.c index 2cc7e8cdfcb..666369dce94 100644 --- a/lib/lfrfid/protocols/protocol_keri.c +++ b/lib/lfrfid/protocols/protocol_keri.c @@ -3,17 +3,17 @@ #include #include "lfrfid_protocols.h" -#define KERI_PREAMBLE_BIT_SIZE (33) +#define KERI_PREAMBLE_BIT_SIZE (33) #define KERI_PREAMBLE_DATA_SIZE (5) -#define KERI_ENCODED_BIT_SIZE (64) +#define KERI_ENCODED_BIT_SIZE (64) #define KERI_ENCODED_DATA_SIZE (((KERI_ENCODED_BIT_SIZE) / 8) + KERI_PREAMBLE_DATA_SIZE) #define KERI_ENCODED_DATA_LAST ((KERI_ENCODED_BIT_SIZE) / 8) -#define KERI_DECODED_BIT_SIZE (28) +#define KERI_DECODED_BIT_SIZE (28) #define KERI_DECODED_DATA_SIZE (4) -#define KERI_US_PER_BIT (255) +#define KERI_US_PER_BIT (255) #define KERI_ENCODER_PULSES_PER_BIT (16) typedef struct { @@ -37,22 +37,22 @@ typedef struct { ProtocolKeri* protocol_keri_alloc(void) { ProtocolKeri* protocol = malloc(sizeof(ProtocolKeri)); return protocol; -}; +} void protocol_keri_free(ProtocolKeri* protocol) { free(protocol); -}; +} uint8_t* protocol_keri_get_data(ProtocolKeri* protocol) { return protocol->data; -}; +} void protocol_keri_decoder_start(ProtocolKeri* protocol) { memset(protocol->encoded_data, 0, KERI_ENCODED_DATA_SIZE); memset(protocol->negative_encoded_data, 0, KERI_ENCODED_DATA_SIZE); memset(protocol->corrupted_encoded_data, 0, KERI_ENCODED_DATA_SIZE); memset(protocol->corrupted_negative_encoded_data, 0, KERI_ENCODED_DATA_SIZE); -}; +} static bool protocol_keri_check_preamble(uint8_t* data, size_t bit_index) { // Preamble 11100000 00000000 00000000 00000000 1 @@ -164,7 +164,7 @@ bool protocol_keri_decoder_feed(ProtocolKeri* protocol, bool level, uint32_t dur } return result; -}; +} bool protocol_keri_encoder_start(ProtocolKeri* protocol) { memset(protocol->encoded_data, 0, KERI_ENCODED_DATA_SIZE); @@ -180,7 +180,7 @@ bool protocol_keri_encoder_start(ProtocolKeri* protocol) { protocol->encoder.bit_clock_index = 0; return true; -}; +} LevelDuration protocol_keri_encoder_yield(ProtocolKeri* protocol) { LevelDuration level_duration; @@ -210,7 +210,7 @@ LevelDuration protocol_keri_encoder_yield(ProtocolKeri* protocol) { } return level_duration; -}; +} static void protocol_keri_render_data_internal(ProtocolKeri* protocol, FuriString* result, bool brief) { @@ -267,7 +267,7 @@ bool protocol_keri_write_data(ProtocolKeri* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_keri = { .name = "Keri", diff --git a/lib/lfrfid/protocols/protocol_nexwatch.c b/lib/lfrfid/protocols/protocol_nexwatch.c index 3df83be7ac2..a794a4a8e4b 100644 --- a/lib/lfrfid/protocols/protocol_nexwatch.c +++ b/lib/lfrfid/protocols/protocol_nexwatch.c @@ -3,16 +3,16 @@ #include #include "lfrfid_protocols.h" -#define NEXWATCH_PREAMBLE_BIT_SIZE (8) +#define NEXWATCH_PREAMBLE_BIT_SIZE (8) #define NEXWATCH_PREAMBLE_DATA_SIZE (1) -#define NEXWATCH_ENCODED_BIT_SIZE (96) +#define NEXWATCH_ENCODED_BIT_SIZE (96) #define NEXWATCH_ENCODED_DATA_SIZE ((NEXWATCH_ENCODED_BIT_SIZE) / 8) -#define NEXWATCH_DECODED_BIT_SIZE (NEXWATCH_DECODED_DATA_SIZE * 8) +#define NEXWATCH_DECODED_BIT_SIZE (NEXWATCH_DECODED_DATA_SIZE * 8) #define NEXWATCH_DECODED_DATA_SIZE (8) -#define NEXWATCH_US_PER_BIT (255) +#define NEXWATCH_US_PER_BIT (255) #define NEXWATCH_ENCODER_PULSES_PER_BIT (16) typedef struct { @@ -47,22 +47,22 @@ typedef struct { ProtocolNexwatch* protocol_nexwatch_alloc(void) { ProtocolNexwatch* protocol = malloc(sizeof(ProtocolNexwatch)); return protocol; -}; +} void protocol_nexwatch_free(ProtocolNexwatch* protocol) { free(protocol); -}; +} uint8_t* protocol_nexwatch_get_data(ProtocolNexwatch* protocol) { return protocol->data; -}; +} void protocol_nexwatch_decoder_start(ProtocolNexwatch* protocol) { memset(protocol->encoded_data, 0, NEXWATCH_ENCODED_DATA_SIZE); memset(protocol->negative_encoded_data, 0, NEXWATCH_ENCODED_DATA_SIZE); memset(protocol->corrupted_encoded_data, 0, NEXWATCH_ENCODED_DATA_SIZE); memset(protocol->corrupted_negative_encoded_data, 0, NEXWATCH_ENCODED_DATA_SIZE); -}; +} static bool protocol_nexwatch_check_preamble(uint8_t* data, size_t bit_index) { // 01010110 @@ -71,7 +71,7 @@ static bool protocol_nexwatch_check_preamble(uint8_t* data, size_t bit_index) { } static uint8_t protocol_nexwatch_parity_swap(uint8_t parity) { - uint8_t a = (((parity >> 3) & 1)); + uint8_t a = ((parity >> 3) & 1); a |= (((parity >> 1) & 1) << 1); a |= (((parity >> 2) & 1) << 2); a |= ((parity & 1) << 3); @@ -215,7 +215,7 @@ bool protocol_nexwatch_decoder_feed(ProtocolNexwatch* protocol, bool level, uint } return result; -}; +} bool protocol_nexwatch_encoder_start(ProtocolNexwatch* protocol) { memset(protocol->encoded_data, 0, NEXWATCH_ENCODED_DATA_SIZE); @@ -231,7 +231,7 @@ bool protocol_nexwatch_encoder_start(ProtocolNexwatch* protocol) { protocol->encoder.bit_clock_index = 0; return true; -}; +} LevelDuration protocol_nexwatch_encoder_yield(ProtocolNexwatch* protocol) { LevelDuration level_duration; @@ -261,7 +261,7 @@ LevelDuration protocol_nexwatch_encoder_yield(ProtocolNexwatch* protocol) { } return level_duration; -}; +} static void protocol_nexwatch_render_data_internal( ProtocolNexwatch* protocol, @@ -328,7 +328,7 @@ bool protocol_nexwatch_write_data(ProtocolNexwatch* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_nexwatch = { .name = "Nexwatch", diff --git a/lib/lfrfid/protocols/protocol_pac_stanley.c b/lib/lfrfid/protocols/protocol_pac_stanley.c index 4eabe365920..4d4c58e99c7 100644 --- a/lib/lfrfid/protocols/protocol_pac_stanley.c +++ b/lib/lfrfid/protocols/protocol_pac_stanley.c @@ -5,13 +5,13 @@ #include #include "lfrfid_protocols.h" -#define PAC_STANLEY_ENCODED_BIT_SIZE (128) -#define PAC_STANLEY_ENCODED_BYTE_SIZE (((PAC_STANLEY_ENCODED_BIT_SIZE) / 8)) -#define PAC_STANLEY_PREAMBLE_BIT_SIZE (8) +#define PAC_STANLEY_ENCODED_BIT_SIZE (128) +#define PAC_STANLEY_ENCODED_BYTE_SIZE (((PAC_STANLEY_ENCODED_BIT_SIZE) / 8)) +#define PAC_STANLEY_PREAMBLE_BIT_SIZE (8) #define PAC_STANLEY_PREAMBLE_BYTE_SIZE (1) #define PAC_STANLEY_ENCODED_BYTE_FULL_SIZE \ (PAC_STANLEY_ENCODED_BYTE_SIZE + PAC_STANLEY_PREAMBLE_BYTE_SIZE) -#define PAC_STANLEY_BYTE_LENGTH (10) // start bit, 7 data bits, parity bit, stop bit +#define PAC_STANLEY_BYTE_LENGTH (10) // start bit, 7 data bits, parity bit, stop bit #define PAC_STANLEY_DATA_START_INDEX (8 + (3 * PAC_STANLEY_BYTE_LENGTH) + 1) #define PAC_STANLEY_DECODED_DATA_SIZE (4) @@ -19,8 +19,8 @@ #define PAC_STANLEY_CLOCKS_IN_US (32) #define PAC_STANLEY_CYCLE_LENGTH (256) -#define PAC_STANLEY_MIN_TIME (60) -#define PAC_STANLEY_MAX_TIME (4000) +#define PAC_STANLEY_MIN_TIME (60) +#define PAC_STANLEY_MAX_TIME (4000) typedef struct { bool inverted; @@ -137,7 +137,8 @@ bool protocol_pac_stanley_encoder_start(ProtocolPACStanley* protocol) { uint8_to_hex_chars(protocol->data, &idbytes[2], 8); // insert start and stop bits - for(size_t i = 0; i < 16; i++) protocol->encoded_data[i] = 0x40 >> ((i + 3) % 5 * 2); + for(size_t i = 0; i < 16; i++) + protocol->encoded_data[i] = 0x40 >> ((i + 3) % 5 * 2); protocol->encoded_data[0] = 0xFF; // mark + stop protocol->encoded_data[1] = 0x20; // start + reflect8(STX) diff --git a/lib/lfrfid/protocols/protocol_pac_stanley.h b/lib/lfrfid/protocols/protocol_pac_stanley.h index 3ca329cf797..322a6c95f99 100644 --- a/lib/lfrfid/protocols/protocol_pac_stanley.h +++ b/lib/lfrfid/protocols/protocol_pac_stanley.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_pac_stanley; \ No newline at end of file +extern const ProtocolBase protocol_pac_stanley; diff --git a/lib/lfrfid/protocols/protocol_paradox.c b/lib/lfrfid/protocols/protocol_paradox.c index bb52f0529c0..f04b5811302 100644 --- a/lib/lfrfid/protocols/protocol_paradox.c +++ b/lib/lfrfid/protocols/protocol_paradox.c @@ -6,13 +6,13 @@ #include "lfrfid_protocols.h" #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) #define PARADOX_DECODED_DATA_SIZE (6) -#define PARADOX_PREAMBLE_LENGTH (8) -#define PARADOX_ENCODED_BIT_SIZE (96) +#define PARADOX_PREAMBLE_LENGTH (8) +#define PARADOX_ENCODED_BIT_SIZE (96) #define PARADOX_ENCODED_DATA_SIZE (((PARADOX_ENCODED_BIT_SIZE) / 8) + 1) #define PARADOX_ENCODED_DATA_LAST (PARADOX_ENCODED_DATA_SIZE - 1) @@ -38,21 +38,21 @@ ProtocolParadox* protocol_paradox_alloc(void) { protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 50); return protocol; -}; +} void protocol_paradox_free(ProtocolParadox* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_paradox_get_data(ProtocolParadox* protocol) { return protocol->data; -}; +} void protocol_paradox_decoder_start(ProtocolParadox* protocol) { memset(protocol->encoded_data, 0, PARADOX_ENCODED_DATA_SIZE); -}; +} static bool protocol_paradox_can_be_decoded(ProtocolParadox* protocol) { // check preamble @@ -101,7 +101,7 @@ bool protocol_paradox_decoder_feed(ProtocolParadox* protocol, bool level, uint32 } return false; -}; +} static void protocol_paradox_encode(const uint8_t* decoded_data, uint8_t* encoded_data) { // preamble @@ -114,14 +114,14 @@ static void protocol_paradox_encode(const uint8_t* decoded_data, uint8_t* encode bit_lib_set_bits(encoded_data, PARADOX_PREAMBLE_LENGTH + i * 2, 0b01, 2); } } -}; +} bool protocol_paradox_encoder_start(ProtocolParadox* protocol) { protocol_paradox_encode(protocol->data, (uint8_t*)protocol->encoded_data); protocol->encoder.encoded_index = 0; fsk_osc_reset(protocol->encoder.fsk_osc); return true; -}; +} LevelDuration protocol_paradox_encoder_yield(ProtocolParadox* protocol) { bool level; @@ -134,7 +134,7 @@ LevelDuration protocol_paradox_encoder_yield(ProtocolParadox* protocol) { bit_lib_increment_index(protocol->encoder.encoded_index, PARADOX_ENCODED_BIT_SIZE); } return level_duration_make(level, duration); -}; +} static uint8_t protocol_paradox_calculate_checksum(uint8_t fc, uint16_t card_id) { uint8_t card_hi = (card_id >> 8) & 0xff; @@ -185,7 +185,7 @@ void protocol_paradox_render_data(ProtocolParadox* protocol, FuriString* result) if(card_crc != calc_crc) { furi_string_cat(result, "\nCRC Mismatch, Invalid Card!"); } -}; +} void protocol_paradox_render_brief_data(ProtocolParadox* protocol, FuriString* result) { uint8_t* decoded_data = protocol->data; @@ -200,7 +200,7 @@ void protocol_paradox_render_brief_data(ProtocolParadox* protocol, FuriString* r if(calc_crc != card_crc) { furi_string_cat(result, "\nCRC Mismatch, Invalid Card!"); } -}; +} bool protocol_paradox_write_data(ProtocolParadox* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -222,7 +222,7 @@ bool protocol_paradox_write_data(ProtocolParadox* protocol, void* data) { result = true; } return result; -}; +} const ProtocolBase protocol_paradox = { .name = "Paradox", diff --git a/lib/lfrfid/protocols/protocol_paradox.h b/lib/lfrfid/protocols/protocol_paradox.h index a80696c35ab..7c0bf56927a 100644 --- a/lib/lfrfid/protocols/protocol_paradox.h +++ b/lib/lfrfid/protocols/protocol_paradox.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_paradox; \ No newline at end of file +extern const ProtocolBase protocol_paradox; diff --git a/lib/lfrfid/protocols/protocol_pyramid.c b/lib/lfrfid/protocols/protocol_pyramid.c index 8711fe13a08..cab217d1463 100644 --- a/lib/lfrfid/protocols/protocol_pyramid.c +++ b/lib/lfrfid/protocols/protocol_pyramid.c @@ -6,17 +6,17 @@ #include #define JITTER_TIME (20) -#define MIN_TIME (64 - JITTER_TIME) -#define MAX_TIME (80 + JITTER_TIME) +#define MIN_TIME (64 - JITTER_TIME) +#define MAX_TIME (80 + JITTER_TIME) -#define PYRAMID_DATA_SIZE 13 +#define PYRAMID_DATA_SIZE 13 #define PYRAMID_PREAMBLE_SIZE 3 #define PYRAMID_ENCODED_DATA_SIZE \ (PYRAMID_PREAMBLE_SIZE + PYRAMID_DATA_SIZE + PYRAMID_PREAMBLE_SIZE) -#define PYRAMID_ENCODED_BIT_SIZE ((PYRAMID_PREAMBLE_SIZE + PYRAMID_DATA_SIZE) * 8) +#define PYRAMID_ENCODED_BIT_SIZE ((PYRAMID_PREAMBLE_SIZE + PYRAMID_DATA_SIZE) * 8) #define PYRAMID_DECODED_DATA_SIZE (4) -#define PYRAMID_DECODED_BIT_SIZE ((PYRAMID_ENCODED_BIT_SIZE - PYRAMID_PREAMBLE_SIZE * 8) / 2) +#define PYRAMID_DECODED_BIT_SIZE ((PYRAMID_ENCODED_BIT_SIZE - PYRAMID_PREAMBLE_SIZE * 8) / 2) typedef struct { FSKDemod* fsk_demod; @@ -41,21 +41,21 @@ ProtocolPyramid* protocol_pyramid_alloc(void) { protocol->encoder.fsk_osc = fsk_osc_alloc(8, 10, 50); return protocol; -}; +} void protocol_pyramid_free(ProtocolPyramid* protocol) { fsk_demod_free(protocol->decoder.fsk_demod); fsk_osc_free(protocol->encoder.fsk_osc); free(protocol); -}; +} uint8_t* protocol_pyramid_get_data(ProtocolPyramid* protocol) { return protocol->data; -}; +} void protocol_pyramid_decoder_start(ProtocolPyramid* protocol) { memset(protocol->encoded_data, 0, PYRAMID_ENCODED_DATA_SIZE); -}; +} static bool protocol_pyramid_can_be_decoded(uint8_t* data) { // check preamble @@ -122,11 +122,12 @@ bool protocol_pyramid_decoder_feed(ProtocolPyramid* protocol, bool level, uint32 } return result; -}; +} bool protocol_pyramid_get_parity(const uint8_t* bits, uint8_t type, int length) { int x; - for(x = 0; length > 0; --length) x += bit_lib_get_bit(bits, length - 1); + for(x = 0; length > 0; --length) + x += bit_lib_get_bit(bits, length - 1); x %= 2; return x ^ type; } @@ -183,7 +184,7 @@ bool protocol_pyramid_encoder_start(ProtocolPyramid* protocol) { protocol_pyramid_encode(protocol); return true; -}; +} LevelDuration protocol_pyramid_encoder_yield(ProtocolPyramid* protocol) { bool level = 0; @@ -213,7 +214,7 @@ LevelDuration protocol_pyramid_encoder_yield(ProtocolPyramid* protocol) { } return level_duration_make(level, duration); -}; +} bool protocol_pyramid_write_data(ProtocolPyramid* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -237,7 +238,7 @@ bool protocol_pyramid_write_data(ProtocolPyramid* protocol, void* data) { result = true; } return result; -}; +} void protocol_pyramid_render_data(ProtocolPyramid* protocol, FuriString* result) { uint8_t* decoded_data = protocol->data; @@ -255,7 +256,7 @@ void protocol_pyramid_render_data(ProtocolPyramid* protocol, FuriString* result) } else { furi_string_cat_printf(result, "Data: Unknown"); } -}; +} const ProtocolBase protocol_pyramid = { .name = "Pyramid", diff --git a/lib/lfrfid/protocols/protocol_securakey.c b/lib/lfrfid/protocols/protocol_securakey.c index 55048a592f1..a4bfeca60f8 100644 --- a/lib/lfrfid/protocols/protocol_securakey.c +++ b/lib/lfrfid/protocols/protocol_securakey.c @@ -11,30 +11,34 @@ #include #define TAG "SECURAKEY" -#define SECURAKEY_ENCODED_SIZE_BITS (84) -#define SECURAKEY_PREAMBLE_SIZE_BITS (12) -#define SECURAKEY_ENCODED_FULL_SIZE_BITS \ - (SECURAKEY_ENCODED_SIZE_BITS + SECURAKEY_PREAMBLE_SIZE_BITS) -#define SECURAKEY_ENCODED_FULL_SIZE_BYTE (SECURAKEY_ENCODED_FULL_SIZE_BITS / 8) -#define SECURAKEY_DECODED_DATA_SIZE_BITS \ - (48) // 16-bit for facility code/number, 16-bit for card number, 16-bit for two checksum + +#define SECURAKEY_RKKT_ENCODED_FULL_SIZE_BITS (96) +#define SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE (12) + +#define SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BITS (64) +#define SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BYTE (8) + +#define SECURAKEY_DECODED_DATA_SIZE_BITS (48) +// RKKT: 16-bit for facility code/number, 16-bit for card number, 16-bit for two checksum +// RKKTH: 16-bit zero padding, 32-bit card number #define SECURAKEY_DECODED_DATA_SIZE_BYTES (SECURAKEY_DECODED_DATA_SIZE_BITS / 8) -#define LFRFID_FREQUENCY (125000) -#define SECURAKEY_CLOCK_PER_BIT (40) // RF/40 +#define LFRFID_FREQUENCY (125000) +#define SECURAKEY_CLOCK_PER_BIT (40) // RF/40 #define SECURAKEY_READ_LONG_TIME \ (1000000 / (LFRFID_FREQUENCY / SECURAKEY_CLOCK_PER_BIT)) // 1000000 micro sec / sec -#define SECURAKEY_READ_SHORT_TIME (SECURAKEY_READ_LONG_TIME / 2) +#define SECURAKEY_READ_SHORT_TIME (SECURAKEY_READ_LONG_TIME / 2) #define SECURAKEY_READ_JITTER_TIME (SECURAKEY_READ_SHORT_TIME * 40 / 100) // 40% jitter tolerance #define SECURAKEY_READ_SHORT_TIME_LOW \ (SECURAKEY_READ_SHORT_TIME - \ SECURAKEY_READ_JITTER_TIME) // these are used for manchester decoding #define SECURAKEY_READ_SHORT_TIME_HIGH (SECURAKEY_READ_SHORT_TIME + SECURAKEY_READ_JITTER_TIME) -#define SECURAKEY_READ_LONG_TIME_LOW (SECURAKEY_READ_LONG_TIME - SECURAKEY_READ_JITTER_TIME) -#define SECURAKEY_READ_LONG_TIME_HIGH (SECURAKEY_READ_LONG_TIME + SECURAKEY_READ_JITTER_TIME) +#define SECURAKEY_READ_LONG_TIME_LOW (SECURAKEY_READ_LONG_TIME - SECURAKEY_READ_JITTER_TIME) +#define SECURAKEY_READ_LONG_TIME_HIGH (SECURAKEY_READ_LONG_TIME + SECURAKEY_READ_JITTER_TIME) typedef struct { uint8_t data[SECURAKEY_DECODED_DATA_SIZE_BYTES]; - uint8_t encoded_data[SECURAKEY_ENCODED_FULL_SIZE_BYTE]; + uint8_t RKKT_encoded_data[SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE]; + uint8_t RKKTH_encoded_data[SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BYTE]; uint8_t encoded_data_index; bool encoded_polarity; ManchesterState decoder_manchester_state; @@ -44,34 +48,35 @@ typedef struct { ProtocolSecurakey* protocol_securakey_alloc(void) { ProtocolSecurakey* protocol = malloc(sizeof(ProtocolSecurakey)); return (void*)protocol; -}; +} void protocol_securakey_free(ProtocolSecurakey* protocol) { free(protocol); -}; +} uint8_t* protocol_securakey_get_data(ProtocolSecurakey* protocol) { return protocol->data; -}; +} static bool protocol_securakey_can_be_decoded(ProtocolSecurakey* protocol) { - // check 11 bits preamble - if(bit_lib_get_bits_16(protocol->encoded_data, 0, SECURAKEY_PREAMBLE_SIZE_BITS) == - 0b011111111100) { - if(bit_lib_get_bits(protocol->encoded_data, 13, 6) == 26 || - bit_lib_get_bits(protocol->encoded_data, 13, 6) == 32) { - return true; - } else { - return false; - } + // check 19 bits preamble + format flag + if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111000000000) { + protocol->bit_format = 0; + return true; + } else if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111001011010) { + protocol->bit_format = 26; + return true; + } else if(bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 19) == 0b0111111111001100000) { + protocol->bit_format = 32; + return true; } else { return false; } -}; +} static void protocol_securakey_decode(ProtocolSecurakey* protocol) { memset(protocol->data, 0, SECURAKEY_DECODED_DATA_SIZE_BYTES); - // encoded_data looks like this (citation: pm3 repo): + // RKKT_encoded_data looks like this (citation: pm3 repo): // 26-bit format (1-bit even parity bit, 8-bit facility number, 16-bit card number, 1-bit odd parity bit) // preamble ??bitlen reserved EPf fffffffc cccccccc cccccccOP CS? CS2? // 0111111111 0 01011010 0 00000000 0 00000010 0 00110110 0 00111110 0 01100010 0 00001111 0 01100000 0 00000000 0 0000 @@ -80,34 +85,51 @@ static void protocol_securakey_decode(ProtocolSecurakey* protocol) { // preamble ??bitlen reserved EPfffffff fffffffc cccccccc cccccccOP CS? CS2? // 0111111111 0 01100000 0 00000000 0 10000100 0 11001010 0 01011011 0 01010110 0 00010110 0 11100000 0 00000000 0 0000 - // left two 0 paddings in the beginning for easier parsing (00011010 = 011010) - // get facility number (f) - if(bit_lib_get_bits(protocol->encoded_data, 13, 6) == 26) { - FURI_LOG_D(TAG, "26-bit Securakey detected"); - protocol->bit_format = 26; - bit_lib_copy_bits(protocol->data, 8, 1, protocol->encoded_data, 36); - // have to skip one spacer - bit_lib_copy_bits(protocol->data, 9, 7, protocol->encoded_data, 38); - } else if(bit_lib_get_bits(protocol->encoded_data, 13, 6) == 32) { - FURI_LOG_D(TAG, "32-bit Securakey detected"); - protocol->bit_format = 32; - // same two 0 paddings here, otherwise should be bit_lib_copy_bits(protocol->data, 8, 7, protocol->encoded_data, 30); - bit_lib_copy_bits(protocol->data, 2, 7, protocol->encoded_data, 30); - // have to skip one spacer - bit_lib_copy_bits(protocol->data, 9, 7, protocol->encoded_data, 38); - } + // RKKTH-02 encoded data sometimes look like this + // plaintext format (preamble and 32-bit? card number) + // preamble unknown unknown cccccccc cccccccc cccccccc cccccccc + // 0 1 2 3 4 5 6 + // 0123456789 0 12345678 9 01234567 8 90123456 7 89012345 6 78901234 5 67890123 + // 0111111111 0 00000000 0 00000000 0 00000000 0 00011101 0 00000100 0 01001010 - // get card number (c) - bit_lib_copy_bits(protocol->data, 16, 1, protocol->encoded_data, 45); - // same skips here - bit_lib_copy_bits(protocol->data, 17, 8, protocol->encoded_data, 47); - bit_lib_copy_bits(protocol->data, 25, 7, protocol->encoded_data, 56); + if(bit_lib_get_bits(protocol->RKKT_encoded_data, 13, 6) == 0) { + FURI_LOG_D(TAG, "Plaintext RKKTH detected"); + protocol->bit_format = 0; + // get card number (c) + bit_lib_copy_bits(protocol->data, 16, 8, protocol->RKKT_encoded_data, 29); + // skip spacers (0s) + bit_lib_copy_bits(protocol->data, 24, 8, protocol->RKKT_encoded_data, 38); + bit_lib_copy_bits(protocol->data, 32, 8, protocol->RKKT_encoded_data, 47); + bit_lib_copy_bits(protocol->data, 40, 8, protocol->RKKT_encoded_data, 56); + } else { + if(bit_lib_get_bits(protocol->RKKT_encoded_data, 13, 6) == 26) { + FURI_LOG_D(TAG, "26-bit RKKT detected"); + protocol->bit_format = 26; + // left two 0 paddings in the beginning for easier parsing (00011010 = 011010) + // get facility number (f) + bit_lib_copy_bits(protocol->data, 8, 1, protocol->RKKT_encoded_data, 36); + // have to skip one spacer + bit_lib_copy_bits(protocol->data, 9, 7, protocol->RKKT_encoded_data, 38); + } else if(bit_lib_get_bits(protocol->RKKT_encoded_data, 13, 6) == 32) { + FURI_LOG_D(TAG, "32-bit RKKT detected"); + protocol->bit_format = 32; + // same two 0 paddings here, otherwise should be bit_lib_copy_bits(protocol->data, 8, 7, protocol->RKKT_encoded_data, 30); + bit_lib_copy_bits(protocol->data, 2, 7, protocol->RKKT_encoded_data, 30); + // have to skip one spacer + bit_lib_copy_bits(protocol->data, 9, 7, protocol->RKKT_encoded_data, 38); + } + // get card number (c) + bit_lib_copy_bits(protocol->data, 16, 1, protocol->RKKT_encoded_data, 45); + // same skips here + bit_lib_copy_bits(protocol->data, 17, 8, protocol->RKKT_encoded_data, 47); + bit_lib_copy_bits(protocol->data, 25, 7, protocol->RKKT_encoded_data, 56); - // unsure about CS yet, might as well just save it - // CS1 - bit_lib_copy_bits(protocol->data, 32, 8, protocol->encoded_data, 65); - // CS2 - bit_lib_copy_bits(protocol->data, 40, 8, protocol->encoded_data, 74); + // unsure about CS yet, might as well just save it + // CS1 + bit_lib_copy_bits(protocol->data, 32, 8, protocol->RKKT_encoded_data, 65); + // CS2 + bit_lib_copy_bits(protocol->data, 40, 8, protocol->RKKT_encoded_data, 74); + } // (decoded) data looks like this (pp are zero paddings): // 26-bit format (1-bit EP, 8-bit facility number, 16-bit card number, 1-bit OP) @@ -117,16 +139,22 @@ static void protocol_securakey_decode(ProtocolSecurakey* protocol) { // 32-bit format (1-bit EP, 14-bit facility number, 16-bit card number, 1-bit OP) // ppffffff ffffffff cccccccc cccccccc CS1 CS2 // 00000010 01100101 00101101 10101011 00010110 11100000 -}; + + // plaintext format (preamble and 32-bit? card number) + // pppppppp pppppppp cccccccc cccccccc cccccccc cccccccc + // 00000000 00000000 00101011 00011101 00000100 01001010 +} void protocol_securakey_decoder_start(ProtocolSecurakey* protocol) { - memset(protocol->encoded_data, 0, SECURAKEY_ENCODED_FULL_SIZE_BYTE); + // always takes in encoded data as RKKT for simplicity + // this part is feeding decoder which will delineate the format anyway + memset(protocol->RKKT_encoded_data, 0, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE); manchester_advance( protocol->decoder_manchester_state, ManchesterEventReset, &protocol->decoder_manchester_state, NULL); -}; +} bool protocol_securakey_decoder_feed(ProtocolSecurakey* protocol, bool level, uint32_t duration) { bool result = false; @@ -151,7 +179,8 @@ bool protocol_securakey_decoder_feed(ProtocolSecurakey* protocol, bool level, ui bool data_ok = manchester_advance( protocol->decoder_manchester_state, event, &protocol->decoder_manchester_state, &data); if(data_ok) { - bit_lib_push_bit(protocol->encoded_data, SECURAKEY_ENCODED_FULL_SIZE_BYTE, data); + bit_lib_push_bit( + protocol->RKKT_encoded_data, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE, data); if(protocol_securakey_can_be_decoded(protocol)) { protocol_securakey_decode(protocol); result = true; @@ -159,115 +188,157 @@ bool protocol_securakey_decoder_feed(ProtocolSecurakey* protocol, bool level, ui } } return result; -}; +} void protocol_securakey_render_data(ProtocolSecurakey* protocol, FuriString* result) { - if(bit_lib_get_bits(protocol->data, 0, 8) == 0) { - protocol->bit_format = 26; + if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) { + protocol->bit_format = 0; + furi_string_printf( + result, + "RKKTH Plaintext format\nCard number: %llu", + bit_lib_get_bits_64(protocol->data, 0, 48)); } else { - protocol->bit_format = 32; + if(bit_lib_get_bits(protocol->data, 0, 8) == 0) { + protocol->bit_format = 26; + } else { + protocol->bit_format = 32; + } + furi_string_printf( + result, + "RKKT %u-bit format\nFacility code: %u\nCard number: %u", + protocol->bit_format, + bit_lib_get_bits_16(protocol->data, 0, 16), + bit_lib_get_bits_16(protocol->data, 16, 16)); } - furi_string_printf( - result, - "%u-bit format\nFacility code: %u\nCard number: %u", - protocol->bit_format, - bit_lib_get_bits_16(protocol->data, 0, 16), - bit_lib_get_bits_16(protocol->data, 16, 16)); -}; +} bool protocol_securakey_encoder_start(ProtocolSecurakey* protocol) { // set all of our encoded_data bits to zeros. - memset(protocol->encoded_data, 0, SECURAKEY_ENCODED_FULL_SIZE_BYTE); - - // write the preamble to the beginning of the encoded_data - bit_lib_set_bits(protocol->encoded_data, 0, 0b01111111, 8); - bit_lib_set_bits(protocol->encoded_data, 8, 0b11001, 5); - - if(bit_lib_get_bits(protocol->data, 0, 8) == 0) { - protocol->bit_format = 26; - // set bit length - bit_lib_set_bits(protocol->encoded_data, 13, protocol->bit_format, 6); - // set even parity & odd parity - if(!bit_lib_test_parity(protocol->data, 8, 12, BitLibParityOdd, 12)) { - bit_lib_set_bit(protocol->encoded_data, 35, 1); - } - if(bit_lib_test_parity(protocol->data, 20, 12, BitLibParityOdd, 12)) { - bit_lib_set_bit(protocol->encoded_data, 63, 1); - } - // write facility number (f) - bit_lib_copy_bits(protocol->encoded_data, 36, 1, protocol->data, 8); - // have to skip one spacer - bit_lib_copy_bits(protocol->encoded_data, 38, 7, protocol->data, 9); - + memset(protocol->RKKTH_encoded_data, 0, SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BYTE); + memset(protocol->RKKT_encoded_data, 0, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BYTE); + if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) { + // write the preamble to the beginning of the RKKT_encoded_data + bit_lib_set_bits(protocol->RKKTH_encoded_data, 0, 0b01111111, 8); + bit_lib_set_bits(protocol->RKKTH_encoded_data, 8, 0b110, 3); //preamble cont. + // write card number (c) + bit_lib_copy_bits(protocol->RKKTH_encoded_data, 29, 8, protocol->data, 16); + // skip spacers (they are zero already by memset) + bit_lib_copy_bits(protocol->RKKTH_encoded_data, 38, 8, protocol->data, 24); + bit_lib_copy_bits(protocol->RKKTH_encoded_data, 47, 8, protocol->data, 32); + bit_lib_copy_bits(protocol->RKKTH_encoded_data, 56, 8, protocol->data, 40); } else { - protocol->bit_format = 32; - // set bit length - bit_lib_set_bits(protocol->encoded_data, 13, protocol->bit_format, 6); - // set EP & OP - if(!bit_lib_test_parity(protocol->data, 2, 15, BitLibParityOdd, 15)) { - bit_lib_set_bit(protocol->encoded_data, 29, 1); - } - if(bit_lib_test_parity(protocol->data, 17, 15, BitLibParityOdd, 15)) { - bit_lib_set_bit(protocol->encoded_data, 63, 1); + // write the preamble to the beginning of the RKKT_encoded_data + bit_lib_set_bits(protocol->RKKT_encoded_data, 0, 0b01111111, 8); + bit_lib_set_bits(protocol->RKKT_encoded_data, 8, 0b11001, 5); //preamble cont. + if(bit_lib_get_bits(protocol->data, 0, 8) == 0) { + protocol->bit_format = 26; + // set bit length + bit_lib_set_bits(protocol->RKKT_encoded_data, 13, protocol->bit_format, 6); + // set even parity & odd parity + if(!bit_lib_test_parity(protocol->data, 8, 12, BitLibParityOdd, 12)) { + bit_lib_set_bit(protocol->RKKT_encoded_data, 35, 1); + } + if(bit_lib_test_parity(protocol->data, 20, 12, BitLibParityOdd, 12)) { + bit_lib_set_bit(protocol->RKKT_encoded_data, 63, 1); + } + // write facility number (f) + bit_lib_copy_bits(protocol->RKKT_encoded_data, 36, 1, protocol->data, 8); + // have to skip one spacer + bit_lib_copy_bits(protocol->RKKT_encoded_data, 38, 7, protocol->data, 9); + } else { + protocol->bit_format = 32; + // set bit length + bit_lib_set_bits(protocol->RKKT_encoded_data, 13, protocol->bit_format, 6); + // set EP & OP + if(!bit_lib_test_parity(protocol->data, 2, 15, BitLibParityOdd, 15)) { + bit_lib_set_bit(protocol->RKKT_encoded_data, 29, 1); + } + if(bit_lib_test_parity(protocol->data, 17, 15, BitLibParityOdd, 15)) { + bit_lib_set_bit(protocol->RKKT_encoded_data, 63, 1); + } + // write facility number (f) + bit_lib_copy_bits(protocol->RKKT_encoded_data, 30, 7, protocol->data, 2); + // have to skip one spacer + bit_lib_copy_bits(protocol->RKKT_encoded_data, 38, 7, protocol->data, 3); } - // write facility number (f) - bit_lib_copy_bits(protocol->encoded_data, 30, 7, protocol->data, 2); - // have to skip one spacer - bit_lib_copy_bits(protocol->encoded_data, 38, 7, protocol->data, 3); - } - - // write card number (c) - bit_lib_copy_bits(protocol->encoded_data, 45, 1, protocol->data, 16); - // same skips here - bit_lib_copy_bits(protocol->encoded_data, 47, 8, protocol->data, 17); - bit_lib_copy_bits(protocol->encoded_data, 56, 7, protocol->data, 25); - // unsure about CS yet might as well just copy it from saved - // CS1 - bit_lib_copy_bits(protocol->encoded_data, 65, 8, protocol->data, 32); - // CS2 - bit_lib_copy_bits(protocol->encoded_data, 74, 8, protocol->data, 40); + // write card number (c) + bit_lib_copy_bits(protocol->RKKT_encoded_data, 45, 1, protocol->data, 16); + // same skips here + bit_lib_copy_bits(protocol->RKKT_encoded_data, 47, 8, protocol->data, 17); + bit_lib_copy_bits(protocol->RKKT_encoded_data, 56, 7, protocol->data, 25); + // unsure about CS yet might as well just copy it from saved + // CS1 + bit_lib_copy_bits(protocol->RKKT_encoded_data, 65, 8, protocol->data, 32); + // CS2 + bit_lib_copy_bits(protocol->RKKT_encoded_data, 74, 8, protocol->data, 40); + } // for sending we start at bit 0. protocol->encoded_data_index = 0; protocol->encoded_polarity = true; return true; -}; +} LevelDuration protocol_securakey_encoder_yield(ProtocolSecurakey* protocol) { - bool level = bit_lib_get_bit(protocol->encoded_data, protocol->encoded_data_index); - uint32_t duration = SECURAKEY_CLOCK_PER_BIT / 2; - if(protocol->encoded_polarity) { - protocol->encoded_polarity = false; + if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) { + bool level = bit_lib_get_bit(protocol->RKKTH_encoded_data, protocol->encoded_data_index); + uint32_t duration = SECURAKEY_CLOCK_PER_BIT / 2; + if(protocol->encoded_polarity) { + protocol->encoded_polarity = false; + } else { + level = !level; + protocol->encoded_polarity = true; + bit_lib_increment_index( + protocol->encoded_data_index, SECURAKEY_RKKTH_ENCODED_FULL_SIZE_BITS); + } + return level_duration_make(level, duration); } else { - level = !level; - protocol->encoded_polarity = true; - bit_lib_increment_index(protocol->encoded_data_index, SECURAKEY_ENCODED_FULL_SIZE_BITS); + bool level = bit_lib_get_bit(protocol->RKKT_encoded_data, protocol->encoded_data_index); + uint32_t duration = SECURAKEY_CLOCK_PER_BIT / 2; + if(protocol->encoded_polarity) { + protocol->encoded_polarity = false; + } else { + level = !level; + protocol->encoded_polarity = true; + bit_lib_increment_index( + protocol->encoded_data_index, SECURAKEY_RKKT_ENCODED_FULL_SIZE_BITS); + } + return level_duration_make(level, duration); } - return level_duration_make(level, duration); -}; +} bool protocol_securakey_write_data(ProtocolSecurakey* protocol, void* data) { + protocol_securakey_encoder_start(protocol); LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; bool result = false; - // Correct protocol data by redecoding - protocol_securakey_encoder_start(protocol); - protocol_securakey_decode(protocol); - protocol_securakey_encoder_start(protocol); // Write T5577 - if(request->write_type == LFRFIDWriteTypeT5577) { - request->t5577.block[0] = - (LFRFID_T5577_MODULATION_MANCHESTER | LFRFID_T5577_BITRATE_RF_40 | - (3 - << LFRFID_T5577_MAXBLOCK_SHIFT)); // we only need 3 32-bit blocks for our 96-bit encoded data - request->t5577.block[1] = bit_lib_get_bits_32(protocol->encoded_data, 0, 32); - request->t5577.block[2] = bit_lib_get_bits_32(protocol->encoded_data, 32, 32); - request->t5577.block[3] = bit_lib_get_bits_32(protocol->encoded_data, 64, 32); - request->t5577.blocks_to_write = 4; - result = true; + if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) { + if(request->write_type == LFRFIDWriteTypeT5577) { + request->t5577.block[0] = + (LFRFID_T5577_MODULATION_MANCHESTER | LFRFID_T5577_BITRATE_RF_40 | + (2 + << LFRFID_T5577_MAXBLOCK_SHIFT)); // we only need 2 32-bit blocks for our 64-bit encoded data + request->t5577.block[1] = bit_lib_get_bits_32(protocol->RKKTH_encoded_data, 0, 32); + request->t5577.block[2] = bit_lib_get_bits_32(protocol->RKKTH_encoded_data, 32, 32); + request->t5577.blocks_to_write = 3; + result = true; + } + } else { + if(request->write_type == LFRFIDWriteTypeT5577) { + request->t5577.block[0] = + (LFRFID_T5577_MODULATION_MANCHESTER | LFRFID_T5577_BITRATE_RF_40 | + (3 + << LFRFID_T5577_MAXBLOCK_SHIFT)); // we only need 3 32-bit blocks for our 96-bit encoded data + request->t5577.block[1] = bit_lib_get_bits_32(protocol->RKKT_encoded_data, 0, 32); + request->t5577.block[2] = bit_lib_get_bits_32(protocol->RKKT_encoded_data, 32, 32); + request->t5577.block[3] = bit_lib_get_bits_32(protocol->RKKT_encoded_data, 64, 32); + request->t5577.blocks_to_write = 4; + result = true; + } } return result; -}; +} const ProtocolBase protocol_securakey = { .name = "Radio Key", @@ -291,4 +362,4 @@ const ProtocolBase protocol_securakey = { .render_data = (ProtocolRenderData)protocol_securakey_render_data, .render_brief_data = (ProtocolRenderData)protocol_securakey_render_data, .write_data = (ProtocolWriteData)protocol_securakey_write_data, -}; \ No newline at end of file +}; diff --git a/lib/lfrfid/protocols/protocol_securakey.h b/lib/lfrfid/protocols/protocol_securakey.h index ad990f119c1..4af153e3dda 100644 --- a/lib/lfrfid/protocols/protocol_securakey.h +++ b/lib/lfrfid/protocols/protocol_securakey.h @@ -1,4 +1,4 @@ #pragma once #include -extern const ProtocolBase protocol_securakey; \ No newline at end of file +extern const ProtocolBase protocol_securakey; diff --git a/lib/lfrfid/protocols/protocol_viking.c b/lib/lfrfid/protocols/protocol_viking.c index 4989e4e6813..78499a41587 100644 --- a/lib/lfrfid/protocols/protocol_viking.c +++ b/lib/lfrfid/protocols/protocol_viking.c @@ -6,21 +6,21 @@ #define VIKING_CLOCK_PER_BIT (32) -#define VIKING_ENCODED_BIT_SIZE (64) -#define VIKING_ENCODED_BYTE_SIZE (((VIKING_ENCODED_BIT_SIZE) / 8)) -#define VIKING_PREAMBLE_BIT_SIZE (24) -#define VIKING_PREAMBLE_BYTE_SIZE (3) +#define VIKING_ENCODED_BIT_SIZE (64) +#define VIKING_ENCODED_BYTE_SIZE (((VIKING_ENCODED_BIT_SIZE) / 8)) +#define VIKING_PREAMBLE_BIT_SIZE (24) +#define VIKING_PREAMBLE_BYTE_SIZE (3) #define VIKING_ENCODED_BYTE_FULL_SIZE (VIKING_ENCODED_BYTE_SIZE + VIKING_PREAMBLE_BYTE_SIZE) -#define VIKING_DECODED_DATA_SIZE 4 +#define VIKING_DECODED_DATA_SIZE 4 -#define VIKING_READ_SHORT_TIME (128) -#define VIKING_READ_LONG_TIME (256) +#define VIKING_READ_SHORT_TIME (128) +#define VIKING_READ_LONG_TIME (256) #define VIKING_READ_JITTER_TIME (60) -#define VIKING_READ_SHORT_TIME_LOW (VIKING_READ_SHORT_TIME - VIKING_READ_JITTER_TIME) +#define VIKING_READ_SHORT_TIME_LOW (VIKING_READ_SHORT_TIME - VIKING_READ_JITTER_TIME) #define VIKING_READ_SHORT_TIME_HIGH (VIKING_READ_SHORT_TIME + VIKING_READ_JITTER_TIME) -#define VIKING_READ_LONG_TIME_LOW (VIKING_READ_LONG_TIME - VIKING_READ_JITTER_TIME) -#define VIKING_READ_LONG_TIME_HIGH (VIKING_READ_LONG_TIME + VIKING_READ_JITTER_TIME) +#define VIKING_READ_LONG_TIME_LOW (VIKING_READ_LONG_TIME - VIKING_READ_JITTER_TIME) +#define VIKING_READ_LONG_TIME_HIGH (VIKING_READ_LONG_TIME + VIKING_READ_JITTER_TIME) typedef struct { uint8_t data[VIKING_DECODED_DATA_SIZE]; @@ -35,15 +35,15 @@ typedef struct { ProtocolViking* protocol_viking_alloc(void) { ProtocolViking* proto = malloc(sizeof(ProtocolViking)); return (void*)proto; -}; +} void protocol_viking_free(ProtocolViking* protocol) { free(protocol); -}; +} uint8_t* protocol_viking_get_data(ProtocolViking* protocol) { return protocol->data; -}; +} static void protocol_viking_decode(ProtocolViking* protocol) { // Copy Card ID @@ -80,7 +80,7 @@ void protocol_viking_decoder_start(ProtocolViking* protocol) { ManchesterEventReset, &protocol->decoder_manchester_state, NULL); -}; +} bool protocol_viking_decoder_feed(ProtocolViking* protocol, bool level, uint32_t duration) { bool result = false; @@ -117,7 +117,7 @@ bool protocol_viking_decoder_feed(ProtocolViking* protocol, bool level, uint32_t } return result; -}; +} bool protocol_viking_encoder_start(ProtocolViking* protocol) { // Preamble @@ -135,7 +135,7 @@ bool protocol_viking_encoder_start(ProtocolViking* protocol) { bit_lib_set_bits(protocol->encoded_data, 56, checksum, 8); return true; -}; +} LevelDuration protocol_viking_encoder_yield(ProtocolViking* protocol) { bool level = bit_lib_get_bit(protocol->encoded_data, protocol->encoded_data_index); @@ -151,7 +151,7 @@ LevelDuration protocol_viking_encoder_yield(ProtocolViking* protocol) { } return level_duration_make(level, duration); -}; +} bool protocol_viking_write_data(ProtocolViking* protocol, void* data) { LFRFIDWriteRequest* request = (LFRFIDWriteRequest*)data; @@ -173,11 +173,11 @@ bool protocol_viking_write_data(ProtocolViking* protocol, void* data) { result = true; } return result; -}; +} void protocol_viking_render_data(ProtocolViking* protocol, FuriString* result) { furi_string_printf(result, "ID: %08lX", bit_lib_get_bits_32(protocol->data, 0, 32)); -}; +} const ProtocolBase protocol_viking = { .name = "Viking", diff --git a/lib/lfrfid/tools/fsk_ocs.c b/lib/lfrfid/tools/fsk_ocs.c index 1fd46cf1793..a71e24aac71 100644 --- a/lib/lfrfid/tools/fsk_ocs.c +++ b/lib/lfrfid/tools/fsk_ocs.c @@ -59,4 +59,4 @@ bool fsk_osc_next_half(FSKOsc* osc, bool bit, bool* level, uint32_t* duration) { } return advance; -} \ No newline at end of file +} diff --git a/lib/lfrfid/tools/fsk_osc.h b/lib/lfrfid/tools/fsk_osc.h index ed7d436c855..048f090ab82 100644 --- a/lib/lfrfid/tools/fsk_osc.h +++ b/lib/lfrfid/tools/fsk_osc.h @@ -57,4 +57,4 @@ bool fsk_osc_next_half(FSKOsc* osc, bool bit, bool* level, uint32_t* duration); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/lfrfid/tools/t5577.c b/lib/lfrfid/tools/t5577.c index 9d0d28fc51b..59ec7d27226 100644 --- a/lib/lfrfid/tools/t5577.c +++ b/lib/lfrfid/tools/t5577.c @@ -5,13 +5,13 @@ #define T5577_TIMING_WAIT_TIME 400 #define T5577_TIMING_START_GAP 30 #define T5577_TIMING_WRITE_GAP 18 -#define T5577_TIMING_DATA_0 24 -#define T5577_TIMING_DATA_1 56 -#define T5577_TIMING_PROGRAM 700 +#define T5577_TIMING_DATA_0 24 +#define T5577_TIMING_DATA_1 56 +#define T5577_TIMING_PROGRAM 700 #define T5577_OPCODE_PAGE_0 0b10 #define T5577_OPCODE_PAGE_1 0b11 -#define T5577_OPCODE_RESET 0b00 +#define T5577_OPCODE_RESET 0b00 #define T5577_BLOCKS_IN_PAGE_0 8 #define T5577_BLOCKS_IN_PAGE_1 4 diff --git a/lib/lfrfid/tools/t5577.h b/lib/lfrfid/tools/t5577.h index f7b5cc4f5a5..026e7290bb0 100644 --- a/lib/lfrfid/tools/t5577.h +++ b/lib/lfrfid/tools/t5577.h @@ -9,35 +9,35 @@ extern "C" { #define LFRFID_T5577_BLOCK_COUNT 8 // T5577 block 0 definitions, thanks proxmark3! -#define LFRFID_T5577_POR_DELAY 0x00000001 -#define LFRFID_T5577_ST_TERMINATOR 0x00000008 -#define LFRFID_T5577_PWD 0x00000010 -#define LFRFID_T5577_MAXBLOCK_SHIFT 5 -#define LFRFID_T5577_AOR 0x00000200 -#define LFRFID_T5577_PSKCF_RF_2 0 -#define LFRFID_T5577_PSKCF_RF_4 0x00000400 -#define LFRFID_T5577_PSKCF_RF_8 0x00000800 -#define LFRFID_T5577_MODULATION_DIRECT 0 -#define LFRFID_T5577_MODULATION_PSK1 0x00001000 -#define LFRFID_T5577_MODULATION_PSK2 0x00002000 -#define LFRFID_T5577_MODULATION_PSK3 0x00003000 -#define LFRFID_T5577_MODULATION_FSK1 0x00004000 -#define LFRFID_T5577_MODULATION_FSK2 0x00005000 -#define LFRFID_T5577_MODULATION_FSK1a 0x00006000 -#define LFRFID_T5577_MODULATION_FSK2a 0x00007000 +#define LFRFID_T5577_POR_DELAY 0x00000001 +#define LFRFID_T5577_ST_TERMINATOR 0x00000008 +#define LFRFID_T5577_PWD 0x00000010 +#define LFRFID_T5577_MAXBLOCK_SHIFT 5 +#define LFRFID_T5577_AOR 0x00000200 +#define LFRFID_T5577_PSKCF_RF_2 0 +#define LFRFID_T5577_PSKCF_RF_4 0x00000400 +#define LFRFID_T5577_PSKCF_RF_8 0x00000800 +#define LFRFID_T5577_MODULATION_DIRECT 0 +#define LFRFID_T5577_MODULATION_PSK1 0x00001000 +#define LFRFID_T5577_MODULATION_PSK2 0x00002000 +#define LFRFID_T5577_MODULATION_PSK3 0x00003000 +#define LFRFID_T5577_MODULATION_FSK1 0x00004000 +#define LFRFID_T5577_MODULATION_FSK2 0x00005000 +#define LFRFID_T5577_MODULATION_FSK1a 0x00006000 +#define LFRFID_T5577_MODULATION_FSK2a 0x00007000 #define LFRFID_T5577_MODULATION_MANCHESTER 0x00008000 -#define LFRFID_T5577_MODULATION_BIPHASE 0x00010000 -#define LFRFID_T5577_MODULATION_DIPHASE 0x00018000 -#define LFRFID_T5577_X_MODE 0x00020000 -#define LFRFID_T5577_BITRATE_RF_8 0 -#define LFRFID_T5577_BITRATE_RF_16 0x00040000 -#define LFRFID_T5577_BITRATE_RF_32 0x00080000 -#define LFRFID_T5577_BITRATE_RF_40 0x000C0000 -#define LFRFID_T5577_BITRATE_RF_50 0x00100000 -#define LFRFID_T5577_BITRATE_RF_64 0x00140000 -#define LFRFID_T5577_BITRATE_RF_100 0x00180000 -#define LFRFID_T5577_BITRATE_RF_128 0x001C0000 -#define LFRFID_T5577_TESTMODE_DISABLED 0x60000000 +#define LFRFID_T5577_MODULATION_BIPHASE 0x00010000 +#define LFRFID_T5577_MODULATION_DIPHASE 0x00018000 +#define LFRFID_T5577_X_MODE 0x00020000 +#define LFRFID_T5577_BITRATE_RF_8 0 +#define LFRFID_T5577_BITRATE_RF_16 0x00040000 +#define LFRFID_T5577_BITRATE_RF_32 0x00080000 +#define LFRFID_T5577_BITRATE_RF_40 0x000C0000 +#define LFRFID_T5577_BITRATE_RF_50 0x00100000 +#define LFRFID_T5577_BITRATE_RF_64 0x00140000 +#define LFRFID_T5577_BITRATE_RF_100 0x00180000 +#define LFRFID_T5577_BITRATE_RF_128 0x001C0000 +#define LFRFID_T5577_TESTMODE_DISABLED 0x60000000 typedef struct { uint32_t block[LFRFID_T5577_BLOCK_COUNT]; @@ -58,4 +58,4 @@ void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, bool with_pass, uint #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/lfrfid/tools/varint_pair.h b/lib/lfrfid/tools/varint_pair.h index 12697a7a6ad..4567e2d04af 100644 --- a/lib/lfrfid/tools/varint_pair.h +++ b/lib/lfrfid/tools/varint_pair.h @@ -76,4 +76,4 @@ bool varint_pair_unpack( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/music_worker/music_worker.c b/lib/music_worker/music_worker.c index 3225134b702..ce91f602956 100644 --- a/lib/music_worker/music_worker.c +++ b/lib/music_worker/music_worker.c @@ -12,12 +12,12 @@ #define TAG "MusicWorker" #define MUSIC_PLAYER_FILETYPE "Flipper Music Format" -#define MUSIC_PLAYER_VERSION 0 +#define MUSIC_PLAYER_VERSION 0 #define SEMITONE_PAUSE 0xFF -#define NOTE_C4 261.63f -#define NOTE_C4_SEMITONE (4.0f * 12.0f) +#define NOTE_C4 261.63f +#define NOTE_C4_SEMITONE (4.0f * 12.0f) #define TWO_POW_TWELTH_ROOT 1.059463094359f typedef struct { diff --git a/lib/nanopb b/lib/nanopb index afc499f9a41..6cfe48d6f15 160000 --- a/lib/nanopb +++ b/lib/nanopb @@ -1 +1 @@ -Subproject commit afc499f9a410fc9bbf6c9c48cdd8d8b199d49eb4 +Subproject commit 6cfe48d6f1593f8fa5c0f90437f5e6522587745e diff --git a/lib/nfc/helpers/crypto1.c b/lib/nfc/helpers/crypto1.c index 938d2765a31..bd4fc8d6195 100644 --- a/lib/nfc/helpers/crypto1.c +++ b/lib/nfc/helpers/crypto1.c @@ -8,7 +8,7 @@ #define SWAPENDIAN(x) \ ((x) = ((x) >> 8 & 0xff00ff) | ((x) & 0xff00ff) << 8, (x) = (x) >> 16 | (x) << 16) -#define LF_POLY_ODD (0x29CE5C) +#define LF_POLY_ODD (0x29CE5C) #define LF_POLY_EVEN (0x870804) #define BEBIT(x, n) FURI_BIT(x, (n) ^ 24) @@ -84,7 +84,8 @@ uint32_t crypto1_word(Crypto1* crypto1, uint32_t in, int is_encrypted) { uint32_t prng_successor(uint32_t x, uint32_t n) { SWAPENDIAN(x); - while(n--) x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31; + while(n--) + x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31; return SWAPENDIAN(x); } diff --git a/lib/nfc/helpers/felica_crc.c b/lib/nfc/helpers/felica_crc.c index bba7cee346e..e1b4fc28737 100644 --- a/lib/nfc/helpers/felica_crc.c +++ b/lib/nfc/helpers/felica_crc.c @@ -45,7 +45,7 @@ bool felica_crc_check(const BitBuffer* buf) { const uint8_t* data = bit_buffer_get_data(buf); const uint16_t crc_calc = felica_crc_calculate(data, data_size - FELICA_CRC_SIZE); - return (crc_calc == crc_received); + return crc_calc == crc_received; } void felica_crc_trim(BitBuffer* buf) { diff --git a/lib/nfc/helpers/iso13239_crc.c b/lib/nfc/helpers/iso13239_crc.c index c1affba4686..3837382e399 100644 --- a/lib/nfc/helpers/iso13239_crc.c +++ b/lib/nfc/helpers/iso13239_crc.c @@ -2,9 +2,9 @@ #include -#define ISO13239_CRC_INIT_DEFAULT (0xFFFFU) +#define ISO13239_CRC_INIT_DEFAULT (0xFFFFU) #define ISO13239_CRC_INIT_PICOPASS (0xE012U) -#define ISO13239_CRC_POLY (0x8408U) +#define ISO13239_CRC_POLY (0x8408U) static uint16_t iso13239_crc_calculate(Iso13239CrcType type, const uint8_t* data, size_t data_size) { @@ -55,7 +55,7 @@ bool iso13239_crc_check(Iso13239CrcType type, const BitBuffer* buf) { const uint8_t* data = bit_buffer_get_data(buf); const uint16_t crc_calc = iso13239_crc_calculate(type, data, data_size - ISO13239_CRC_SIZE); - return (crc_calc == crc_received); + return crc_calc == crc_received; } void iso13239_crc_trim(BitBuffer* buf) { diff --git a/lib/nfc/helpers/iso14443_4_layer.c b/lib/nfc/helpers/iso14443_4_layer.c index d5b0d32defc..3e8c6e83a34 100644 --- a/lib/nfc/helpers/iso14443_4_layer.c +++ b/lib/nfc/helpers/iso14443_4_layer.c @@ -2,7 +2,7 @@ #include -#define ISO14443_4_BLOCK_PCB (1U << 1) +#define ISO14443_4_BLOCK_PCB (1U << 1) #define ISO14443_4_BLOCK_PCB_I (0U) #define ISO14443_4_BLOCK_PCB_R (5U << 5) #define ISO14443_4_BLOCK_PCB_S (3U << 6) diff --git a/lib/nfc/helpers/iso14443_crc.c b/lib/nfc/helpers/iso14443_crc.c index 33789bd71f8..88d5f41d24a 100644 --- a/lib/nfc/helpers/iso14443_crc.c +++ b/lib/nfc/helpers/iso14443_crc.c @@ -50,7 +50,7 @@ bool iso14443_crc_check(Iso14443CrcType type, const BitBuffer* buf) { const uint8_t* data = bit_buffer_get_data(buf); const uint16_t crc_calc = iso14443_crc_calculate(type, data, data_size - ISO14443_CRC_SIZE); - return (crc_calc == crc_received); + return crc_calc == crc_received; } void iso14443_crc_trim(BitBuffer* buf) { diff --git a/lib/nfc/helpers/nfc_util.c b/lib/nfc/helpers/nfc_util.c index 31ade8fc7a0..f502b4bfb4e 100644 --- a/lib/nfc/helpers/nfc_util.c +++ b/lib/nfc/helpers/nfc_util.c @@ -17,7 +17,7 @@ uint8_t nfc_util_even_parity32(uint32_t data) { // data ^= data >> 16; // data ^= data >> 8; // return !nfc_util_odd_byte_parity[data]; - return (__builtin_parity(data) & 0xFF); + return __builtin_parity(data) & 0xFF; } uint8_t nfc_util_odd_parity8(uint8_t data) { @@ -45,4 +45,4 @@ void nfc_util_odd_parity(const uint8_t* src, uint8_t* dst, uint8_t len) { if(bit) { *dst = parity; } -} \ No newline at end of file +} diff --git a/lib/nfc/nfc_common.h b/lib/nfc/nfc_common.h index c3cccf697d3..1da6e307aa6 100644 --- a/lib/nfc/nfc_common.h +++ b/lib/nfc/nfc_common.h @@ -9,13 +9,13 @@ extern "C" { #endif /* NFC file format version which changed ATQA format. Deprecated. */ -#define NFC_LSB_ATQA_FORMAT_VERSION (2) +#define NFC_LSB_ATQA_FORMAT_VERSION (2) /* NFC file format version which is still supported as backwards compatible. */ #define NFC_MINIMUM_SUPPORTED_FORMAT_VERSION NFC_LSB_ATQA_FORMAT_VERSION /* NFC file format version which implemented the unified loading process. */ -#define NFC_UNIFIED_FORMAT_VERSION (4) +#define NFC_UNIFIED_FORMAT_VERSION (4) /* Current NFC file format version. */ -#define NFC_CURRENT_FORMAT_VERSION NFC_UNIFIED_FORMAT_VERSION +#define NFC_CURRENT_FORMAT_VERSION NFC_UNIFIED_FORMAT_VERSION #ifdef __cplusplus } diff --git a/lib/nfc/nfc_device.c b/lib/nfc/nfc_device.c index 9f95dfc151d..463b2df1aa2 100644 --- a/lib/nfc/nfc_device.c +++ b/lib/nfc/nfc_device.c @@ -6,10 +6,10 @@ #include "nfc_common.h" #include "protocols/nfc_device_defs.h" -#define NFC_FILE_HEADER "Flipper NFC device" +#define NFC_FILE_HEADER "Flipper NFC device" #define NFC_DEV_TYPE_ERROR "Protocol type mismatch" -#define NFC_DEVICE_UID_KEY "UID" +#define NFC_DEVICE_UID_KEY "UID" #define NFC_DEVICE_TYPE_KEY "Device type" #define NFC_DEVICE_UID_MAX_LEN (10U) diff --git a/lib/nfc/nfc_poller.c b/lib/nfc/nfc_poller.c index 114ff369519..2fe50b3fc5b 100644 --- a/lib/nfc/nfc_poller.c +++ b/lib/nfc/nfc_poller.c @@ -190,7 +190,8 @@ void nfc_poller_start_ex(NfcPoller* instance, NfcGenericCallbackEx callback, voi NfcProtocol parent_protocol = nfc_protocol_get_parent(instance->protocol); if(parent_protocol != NfcProtocolInvalid) { NfcPollerListElement* iter = instance->list.head; - while(iter->protocol != parent_protocol) iter = iter->child; + while(iter->protocol != parent_protocol) + iter = iter->child; iter->poller_api->set_callback(iter->poller, nfc_poller_start_ex_tail_callback, instance); } @@ -254,7 +255,8 @@ bool nfc_poller_detect(NfcPoller* instance) { NfcPollerListElement* iter = instance->list.head; if(tail_poller != instance->list.head) { - while(iter->child != tail_poller) iter = iter->child; + while(iter->child != tail_poller) + iter = iter->child; iter->poller_api->set_callback(iter->poller, nfc_poller_detect_tail_callback, instance); } diff --git a/lib/nfc/protocols/felica/felica.c b/lib/nfc/protocols/felica/felica.c index 89e610f86a3..e9ffb771acb 100644 --- a/lib/nfc/protocols/felica/felica.c +++ b/lib/nfc/protocols/felica/felica.c @@ -5,10 +5,10 @@ #include #define FELICA_PROTOCOL_NAME "FeliCa" -#define FELICA_DEVICE_NAME "FeliCa" +#define FELICA_DEVICE_NAME "FeliCa" -#define FELICA_DATA_FORMAT_VERSION "Data format version" -#define FELICA_MANUFACTURE_ID "Manufacture id" +#define FELICA_DATA_FORMAT_VERSION "Data format version" +#define FELICA_MANUFACTURE_ID "Manufacture id" #define FELICA_MANUFACTURE_PARAMETER "Manufacture parameter" static const uint32_t felica_data_format_version = 1; @@ -353,4 +353,4 @@ void felica_calculate_mac_write( memcpy(session_swapped, session_key + 8, 8); memcpy(session_swapped + 8, session_key, 8); felica_calculate_mac(ctx, session_swapped, rc, first_block, data, FELICA_DATA_BLOCK_SIZE, mac); -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/felica/felica.h b/lib/nfc/protocols/felica/felica.h index 17229c150ac..7b9c78e079f 100644 --- a/lib/nfc/protocols/felica/felica.h +++ b/lib/nfc/protocols/felica/felica.h @@ -8,44 +8,44 @@ extern "C" { #endif -#define FELICA_IDM_SIZE (8U) -#define FELICA_PMM_SIZE (8U) +#define FELICA_IDM_SIZE (8U) +#define FELICA_PMM_SIZE (8U) #define FELICA_DATA_BLOCK_SIZE (16U) -#define FELICA_CMD_READ_WITHOUT_ENCRYPTION (0x06U) +#define FELICA_CMD_READ_WITHOUT_ENCRYPTION (0x06U) #define FELICA_CMD_WRITE_WITHOUT_ENCRYPTION (0x08U) #define FELICA_SERVICE_RW_ACCESS (0x0009U) #define FELICA_SERVICE_RO_ACCESS (0x000BU) -#define FELICA_BLOCKS_TOTAL_COUNT (28U) -#define FELICA_BLOCK_INDEX_REG (0x0EU) -#define FELICA_BLOCK_INDEX_RC (0x80U) -#define FELICA_BLOCK_INDEX_MAC (0x81U) -#define FELICA_BLOCK_INDEX_ID (0x82U) -#define FELICA_BLOCK_INDEX_D_ID (0x83U) -#define FELICA_BLOCK_INDEX_SER_C (0x84U) -#define FELICA_BLOCK_INDEX_SYS_C (0x85U) -#define FELICA_BLOCK_INDEX_CKV (0x86U) -#define FELICA_BLOCK_INDEX_CK (0x87U) -#define FELICA_BLOCK_INDEX_MC (0x88U) -#define FELICA_BLOCK_INDEX_WCNT (0x90U) -#define FELICA_BLOCK_INDEX_MAC_A (0x91U) -#define FELICA_BLOCK_INDEX_STATE (0x92U) +#define FELICA_BLOCKS_TOTAL_COUNT (28U) +#define FELICA_BLOCK_INDEX_REG (0x0EU) +#define FELICA_BLOCK_INDEX_RC (0x80U) +#define FELICA_BLOCK_INDEX_MAC (0x81U) +#define FELICA_BLOCK_INDEX_ID (0x82U) +#define FELICA_BLOCK_INDEX_D_ID (0x83U) +#define FELICA_BLOCK_INDEX_SER_C (0x84U) +#define FELICA_BLOCK_INDEX_SYS_C (0x85U) +#define FELICA_BLOCK_INDEX_CKV (0x86U) +#define FELICA_BLOCK_INDEX_CK (0x87U) +#define FELICA_BLOCK_INDEX_MC (0x88U) +#define FELICA_BLOCK_INDEX_WCNT (0x90U) +#define FELICA_BLOCK_INDEX_MAC_A (0x91U) +#define FELICA_BLOCK_INDEX_STATE (0x92U) #define FELICA_BLOCK_INDEX_CRC_CHECK (0xA0U) -#define FELICA_GUARD_TIME_US (20000U) -#define FELICA_FDT_POLL_FC (10000U) +#define FELICA_GUARD_TIME_US (20000U) +#define FELICA_FDT_POLL_FC (10000U) #define FELICA_POLL_POLL_MIN_US (1280U) #define FELICA_FDT_LISTEN_FC (1172) #define FELICA_SYSTEM_CODE_CODE (0xFFFFU) -#define FELICA_TIME_SLOT_1 (0x00U) -#define FELICA_TIME_SLOT_2 (0x01U) -#define FELICA_TIME_SLOT_4 (0x03U) -#define FELICA_TIME_SLOT_8 (0x07U) -#define FELICA_TIME_SLOT_16 (0x0FU) +#define FELICA_TIME_SLOT_1 (0x00U) +#define FELICA_TIME_SLOT_2 (0x01U) +#define FELICA_TIME_SLOT_4 (0x03U) +#define FELICA_TIME_SLOT_8 (0x07U) +#define FELICA_TIME_SLOT_16 (0x0FU) /** @brief Type of possible Felica errors */ typedef enum { @@ -174,8 +174,8 @@ typedef struct { typedef struct { uint8_t service_code : 4; - uint8_t access_mode : 3; - uint8_t length : 1; + uint8_t access_mode : 3; + uint8_t length : 1; uint8_t block_number; } FelicaBlockListElement; diff --git a/lib/nfc/protocols/felica/felica_listener.c b/lib/nfc/protocols/felica/felica_listener.c index 90215eced29..d019eb21db8 100644 --- a/lib/nfc/protocols/felica/felica_listener.c +++ b/lib/nfc/protocols/felica/felica_listener.c @@ -4,8 +4,8 @@ #include #include -#define FELICA_LISTENER_MAX_BUFFER_SIZE (128) -#define FELICA_LISTENER_RESPONSE_CODE_READ (0x07) +#define FELICA_LISTENER_MAX_BUFFER_SIZE (128) +#define FELICA_LISTENER_RESPONSE_CODE_READ (0x07) #define FELICA_LISTENER_RESPONSE_CODE_WRITE (0x09) #define TAG "FelicaListener" @@ -207,4 +207,4 @@ const NfcListenerBase nfc_listener_felica = { .set_callback = (NfcListenerSetCallback)felica_listener_set_callback, .get_data = (NfcListenerGetData)felica_listener_get_data, .run = (NfcListenerRun)felica_listener_run, -}; \ No newline at end of file +}; diff --git a/lib/nfc/protocols/felica/felica_listener.h b/lib/nfc/protocols/felica/felica_listener.h index d210befa574..a7cbbe38c45 100644 --- a/lib/nfc/protocols/felica/felica_listener.h +++ b/lib/nfc/protocols/felica/felica_listener.h @@ -11,4 +11,4 @@ typedef struct FelicaListener FelicaListener; #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/nfc/protocols/felica/felica_listener_i.c b/lib/nfc/protocols/felica/felica_listener_i.c index caab11778f6..b3ae24635db 100644 --- a/lib/nfc/protocols/felica/felica_listener_i.c +++ b/lib/nfc/protocols/felica/felica_listener_i.c @@ -2,25 +2,25 @@ #include -#define FELICA_WCNT_MC2_FF_MAX_VALUE (0x00FFFFFFU) -#define FELICA_WCNT_MC2_00_MAX_VALUE (0x00FFFE00U) +#define FELICA_WCNT_MC2_FF_MAX_VALUE (0x00FFFFFFU) +#define FELICA_WCNT_MC2_00_MAX_VALUE (0x00FFFE00U) #define FELICA_WCNT_MC2_00_WARNING_BEGIN_VALUE (0x00001027U) -#define FELICA_WCNT_MC2_00_WARNING_END_VALUE (0x00FFFDFFU) - -#define FELICA_MC_SP_REG_ALL_RW_BYTES_0_1 (0U) -#define FELICA_MC_ALL_BYTE (2U) -#define FELICA_MC_SYS_OP (3U) -#define FELICA_MC_RF_PRM (4U) -#define FELICA_MC_CKCKV_W_MAC_A (5U) -#define FELICA_MC_SP_REG_R_RESTR_BYTES_6_7 (6U) -#define FELICA_MC_SP_REG_W_RESTR_BYTES_8_9 (8U) +#define FELICA_WCNT_MC2_00_WARNING_END_VALUE (0x00FFFDFFU) + +#define FELICA_MC_SP_REG_ALL_RW_BYTES_0_1 (0U) +#define FELICA_MC_ALL_BYTE (2U) +#define FELICA_MC_SYS_OP (3U) +#define FELICA_MC_RF_PRM (4U) +#define FELICA_MC_CKCKV_W_MAC_A (5U) +#define FELICA_MC_SP_REG_R_RESTR_BYTES_6_7 (6U) +#define FELICA_MC_SP_REG_W_RESTR_BYTES_8_9 (8U) #define FELICA_MC_SP_REG_W_MAC_A_BYTES_10_11 (10U) -#define FELICA_MC_STATE_W_MAC_A (12U) -#define FELICA_MC_RESERVED_13 (13U) -#define FELICA_MC_RESERVED_14 (14U) -#define FELICA_MC_RESERVED_15 (15U) +#define FELICA_MC_STATE_W_MAC_A (12U) +#define FELICA_MC_RESERVED_13 (13U) +#define FELICA_MC_RESERVED_14 (14U) +#define FELICA_MC_RESERVED_15 (15U) -#define FELICA_MC_BYTE_GET(data, byte) (data->data.fs.mc.data[byte]) +#define FELICA_MC_BYTE_GET(data, byte) (data->data.fs.mc.data[byte]) #define FELICA_SYSTEM_BLOCK_RO_ACCESS(data) (FELICA_MC_BYTE_GET(data, FELICA_MC_ALL_BYTE) == 0x00) #define FELICA_SYSTEM_BLOCK_RW_ACCESS(data) (FELICA_MC_BYTE_GET(data, FELICA_MC_ALL_BYTE) == 0xFF) @@ -39,10 +39,9 @@ static uint32_t felica_wcnt_get_max_value(const FelicaData* data) { static bool felica_wcnt_check_warning_boundary(const FelicaData* data) { const uint32_t* wcnt_ptr = (uint32_t*)data->data.fs.wcnt.data; - return ( - FELICA_SYSTEM_BLOCK_RO_ACCESS(data) && - ((*wcnt_ptr > FELICA_WCNT_MC2_00_WARNING_BEGIN_VALUE) && - (*wcnt_ptr < FELICA_WCNT_MC2_00_WARNING_END_VALUE))); + return FELICA_SYSTEM_BLOCK_RO_ACCESS(data) && + ((*wcnt_ptr > FELICA_WCNT_MC2_00_WARNING_BEGIN_VALUE) && + (*wcnt_ptr < FELICA_WCNT_MC2_00_WARNING_END_VALUE)); } static bool felica_wcnt_check_error_boundary(const FelicaData* data) { @@ -138,7 +137,7 @@ static bool felica_listener_check_write_request_data_size( uint8_t possible_data_size = fact_item_cnt * FELICA_DATA_BLOCK_SIZE; uint8_t fact_data_size = request->base.length - sizeof(FelicaListenerGenericRequest) - instance->block_list_size; - return (possible_data_size <= fact_data_size); + return possible_data_size <= fact_data_size; } static bool felica_listener_test_block_list_size_bounds(const FelicaListenerGenericRequest* req) { @@ -735,4 +734,4 @@ FelicaError } while(false); return ret; -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/felica/felica_listener_i.h b/lib/nfc/protocols/felica/felica_listener_i.h index 43c03a608e4..0ea144249b4 100644 --- a/lib/nfc/protocols/felica/felica_listener_i.h +++ b/lib/nfc/protocols/felica/felica_listener_i.h @@ -2,8 +2,8 @@ #include -#define FELICA_LISTENER_READ_BLOCK_COUNT_MAX (4U) -#define FELICA_LISTENER_READ_BLOCK_COUNT_MIN (1U) +#define FELICA_LISTENER_READ_BLOCK_COUNT_MAX (4U) +#define FELICA_LISTENER_READ_BLOCK_COUNT_MIN (1U) #define FELICA_LISTENER_WRITE_BLOCK_COUNT_MAX (2U) #define FELICA_LISTENER_WRITE_BLOCK_COUNT_MIN (1U) diff --git a/lib/nfc/protocols/felica/felica_poller_i.h b/lib/nfc/protocols/felica/felica_poller_i.h index 9857d96d602..df205ba67e7 100644 --- a/lib/nfc/protocols/felica/felica_poller_i.h +++ b/lib/nfc/protocols/felica/felica_poller_i.h @@ -11,7 +11,7 @@ extern "C" { #define FELICA_POLLER_POLLING_FWT (200000U) -#define FELICA_POLLER_CMD_POLLING_REQ_CODE (0x00U) +#define FELICA_POLLER_CMD_POLLING_REQ_CODE (0x00U) #define FELICA_POLLER_CMD_POLLING_RESP_CODE (0x01U) typedef enum { diff --git a/lib/nfc/protocols/felica/felica_poller_sync.c b/lib/nfc/protocols/felica/felica_poller_sync.c index f20ff08e19d..ec73227f5ef 100644 --- a/lib/nfc/protocols/felica/felica_poller_sync.c +++ b/lib/nfc/protocols/felica/felica_poller_sync.c @@ -67,4 +67,4 @@ FelicaError felica_poller_sync_read(Nfc* nfc, FelicaData* data, const FelicaCard } return poller_context.error; -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/iso14443_3a/iso14443_3a.c b/lib/nfc/protocols/iso14443_3a/iso14443_3a.c index 96e30e5c8d1..fc527a59c3a 100644 --- a/lib/nfc/protocols/iso14443_3a/iso14443_3a.c +++ b/lib/nfc/protocols/iso14443_3a/iso14443_3a.c @@ -6,11 +6,11 @@ #define ISO14443A_ATS_BIT (1U << 5) #define ISO14443_3A_PROTOCOL_NAME_LEGACY "UID" -#define ISO14443_3A_PROTOCOL_NAME "ISO14443-3A" -#define ISO14443_3A_DEVICE_NAME "ISO14443-3A (Unknown)" +#define ISO14443_3A_PROTOCOL_NAME "ISO14443-3A" +#define ISO14443_3A_DEVICE_NAME "ISO14443-3A (Unknown)" #define ISO14443_3A_ATQA_KEY "ATQA" -#define ISO14443_3A_SAK_KEY "SAK" +#define ISO14443_3A_SAK_KEY "SAK" const NfcDeviceBase nfc_device_iso14443_3a = { .protocol_name = ISO14443_3A_PROTOCOL_NAME, diff --git a/lib/nfc/protocols/iso14443_3a/iso14443_3a.h b/lib/nfc/protocols/iso14443_3a/iso14443_3a.h index 714c1dadafb..0a8bd2413bc 100644 --- a/lib/nfc/protocols/iso14443_3a/iso14443_3a.h +++ b/lib/nfc/protocols/iso14443_3a/iso14443_3a.h @@ -7,16 +7,16 @@ extern "C" { #endif -#define ISO14443_3A_UID_4_BYTES (4U) -#define ISO14443_3A_UID_7_BYTES (7U) +#define ISO14443_3A_UID_4_BYTES (4U) +#define ISO14443_3A_UID_7_BYTES (7U) #define ISO14443_3A_UID_10_BYTES (10U) #define ISO14443_3A_MAX_UID_SIZE ISO14443_3A_UID_10_BYTES -#define ISO14443_3A_GUARD_TIME_US (5000) -#define ISO14443_3A_FDT_POLL_FC (1620) -#define ISO14443_3A_FDT_LISTEN_FC (1172) +#define ISO14443_3A_GUARD_TIME_US (5000) +#define ISO14443_3A_FDT_POLL_FC (1620) +#define ISO14443_3A_FDT_LISTEN_FC (1172) #define ISO14443_3A_POLLER_MASK_RX_FS ((ISO14443_3A_FDT_LISTEN_FC) / 2) -#define ISO14443_3A_POLL_POLL_MIN_US (1100) +#define ISO14443_3A_POLL_POLL_MIN_US (1100) typedef enum { Iso14443_3aErrorNone, diff --git a/lib/nfc/protocols/iso14443_3a/iso14443_3a_listener_i.c b/lib/nfc/protocols/iso14443_3a/iso14443_3a_listener_i.c index 46501503cee..33320f492f6 100644 --- a/lib/nfc/protocols/iso14443_3a/iso14443_3a_listener_i.c +++ b/lib/nfc/protocols/iso14443_3a/iso14443_3a_listener_i.c @@ -47,7 +47,7 @@ Iso14443_3aError iso14443_3a_listener_tx_with_custom_parity( } return ret; -}; +} Iso14443_3aError iso14443_3a_listener_send_standard_frame( Iso14443_3aListener* instance, diff --git a/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h b/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h index 664d54598e5..29a8c29b509 100644 --- a/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h +++ b/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_i.h @@ -12,7 +12,7 @@ extern "C" { #define ISO14443_3A_POLLER_SEL_CMD(cascade_lvl) (0x93 + 2 * (cascade_lvl)) #define ISO14443_3A_POLLER_SEL_PAR(bytes, bits) (((bytes) << 4 & 0xf0U) | ((bits) & 0x0fU)) -#define ISO14443_3A_POLLER_SDD_CL (0x88U) +#define ISO14443_3A_POLLER_SDD_CL (0x88U) typedef enum { Iso14443_3aPollerColResStateStateIdle, diff --git a/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_sync.c b/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_sync.c index 52ba7e8456d..2bbc6556468 100644 --- a/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_sync.c +++ b/lib/nfc/protocols/iso14443_3a/iso14443_3a_poller_sync.c @@ -55,4 +55,4 @@ Iso14443_3aError iso14443_3a_poller_sync_read(Nfc* nfc, Iso14443_3aData* iso1444 } return poller_context.error; -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/iso14443_3b/iso14443_3b.c b/lib/nfc/protocols/iso14443_3b/iso14443_3b.c index c2dc7e5a061..caae5f0c925 100644 --- a/lib/nfc/protocols/iso14443_3b/iso14443_3b.c +++ b/lib/nfc/protocols/iso14443_3b/iso14443_3b.c @@ -7,9 +7,9 @@ #include #define ISO14443_3B_PROTOCOL_NAME "ISO14443-3B" -#define ISO14443_3B_DEVICE_NAME "ISO14443-3B (Unknown)" +#define ISO14443_3B_DEVICE_NAME "ISO14443-3B (Unknown)" -#define ISO14443_3B_APP_DATA_KEY "Application data" +#define ISO14443_3B_APP_DATA_KEY "Application data" #define ISO14443_3B_PROTOCOL_INFO_KEY "Protocol info" #define ISO14443_3B_FDT_POLL_DEFAULT_FC (ISO14443_3B_FDT_POLL_FC) diff --git a/lib/nfc/protocols/iso14443_3b/iso14443_3b_i.h b/lib/nfc/protocols/iso14443_3b/iso14443_3b_i.h index f4ff36bd7e3..01e9a914bfb 100644 --- a/lib/nfc/protocols/iso14443_3b/iso14443_3b_i.h +++ b/lib/nfc/protocols/iso14443_3b/iso14443_3b_i.h @@ -2,20 +2,20 @@ #include "iso14443_3b.h" -#define ISO14443_3B_UID_SIZE (4U) +#define ISO14443_3B_UID_SIZE (4U) #define ISO14443_3B_APP_DATA_SIZE (4U) -#define ISO14443_3B_GUARD_TIME_US (5000U) -#define ISO14443_3B_FDT_POLL_FC (9000U) +#define ISO14443_3B_GUARD_TIME_US (5000U) +#define ISO14443_3B_FDT_POLL_FC (9000U) #define ISO14443_3B_POLL_POLL_MIN_US (1280U) -#define ISO14443_3B_BIT_RATE_BOTH_106KBIT (0U << 0) -#define ISO14443_3B_BIT_RATE_PCD_TO_PICC_212KBIT (1U << 0) -#define ISO14443_3B_BIT_RATE_PCD_TO_PICC_424KBIT (1U << 1) -#define ISO14443_3B_BIT_RATE_PCD_TO_PICC_848KBIT (1U << 2) -#define ISO14443_3B_BIT_RATE_PICC_TO_PCD_212KBIT (1U << 4) -#define ISO14443_3B_BIT_RATE_PICC_TO_PCD_424KBIT (1U << 5) -#define ISO14443_3B_BIT_RATE_PICC_TO_PCD_848KBIT (1U << 6) +#define ISO14443_3B_BIT_RATE_BOTH_106KBIT (0U << 0) +#define ISO14443_3B_BIT_RATE_PCD_TO_PICC_212KBIT (1U << 0) +#define ISO14443_3B_BIT_RATE_PCD_TO_PICC_424KBIT (1U << 1) +#define ISO14443_3B_BIT_RATE_PCD_TO_PICC_848KBIT (1U << 2) +#define ISO14443_3B_BIT_RATE_PICC_TO_PCD_212KBIT (1U << 4) +#define ISO14443_3B_BIT_RATE_PICC_TO_PCD_424KBIT (1U << 5) +#define ISO14443_3B_BIT_RATE_PICC_TO_PCD_848KBIT (1U << 6) #define ISO14443_3B_BIT_RATE_BOTH_SAME_COMPULSORY (1U << 7) #define ISO14443_3B_FRAME_OPTION_NAD (1U << 1) @@ -23,11 +23,11 @@ typedef struct { uint8_t bit_rate_capability; - uint8_t protocol_type : 4; + uint8_t protocol_type : 4; uint8_t max_frame_size : 4; - uint8_t fo : 2; - uint8_t adc : 2; - uint8_t fwi : 4; + uint8_t fo : 2; + uint8_t adc : 2; + uint8_t fwi : 4; } Iso14443_3bProtocolInfo; struct Iso14443_3bData { diff --git a/lib/nfc/protocols/iso14443_4a/iso14443_4a.c b/lib/nfc/protocols/iso14443_4a/iso14443_4a.c index 756c3508489..cdef65a2549 100644 --- a/lib/nfc/protocols/iso14443_4a/iso14443_4a.c +++ b/lib/nfc/protocols/iso14443_4a/iso14443_4a.c @@ -3,12 +3,12 @@ #include #define ISO14443_4A_PROTOCOL_NAME "ISO14443-4A" -#define ISO14443_4A_DEVICE_NAME "ISO14443-4A (Unknown)" +#define ISO14443_4A_DEVICE_NAME "ISO14443-4A (Unknown)" -#define ISO14443_4A_T0_KEY "T0" -#define ISO14443_4A_TA1_KEY "TA(1)" -#define ISO14443_4A_TB1_KEY "TB(1)" -#define ISO14443_4A_TC1_KEY "TC(1)" +#define ISO14443_4A_T0_KEY "T0" +#define ISO14443_4A_TA1_KEY "TA(1)" +#define ISO14443_4A_TB1_KEY "TB(1)" +#define ISO14443_4A_TC1_KEY "TC(1)" #define ISO14443_4A_T1_TK_KEY "T1...Tk" #define ISO14443_4A_FDT_DEFAULT_FC ISO14443_3A_FDT_POLL_FC diff --git a/lib/nfc/protocols/iso14443_4a/iso14443_4a_i.h b/lib/nfc/protocols/iso14443_4a/iso14443_4a_i.h index e5483a6ba1f..9b0230975da 100644 --- a/lib/nfc/protocols/iso14443_4a/iso14443_4a_i.h +++ b/lib/nfc/protocols/iso14443_4a/iso14443_4a_i.h @@ -9,13 +9,13 @@ #define ISO14443_4A_ATS_T0_TB1 (1U << 5) #define ISO14443_4A_ATS_T0_TC1 (1U << 6) -#define ISO14443_4A_ATS_TA1_BOTH_106KBIT (0U << 0) -#define ISO14443_4A_ATS_TA1_PCD_TO_PICC_212KBIT (1U << 0) -#define ISO14443_4A_ATS_TA1_PCD_TO_PICC_424KBIT (1U << 1) -#define ISO14443_4A_ATS_TA1_PCD_TO_PICC_848KBIT (1U << 2) -#define ISO14443_4A_ATS_TA1_PICC_TO_PCD_212KBIT (1U << 4) -#define ISO14443_4A_ATS_TA1_PICC_TO_PCD_424KBIT (1U << 5) -#define ISO14443_4A_ATS_TA1_PICC_TO_PCD_848KBIT (1U << 6) +#define ISO14443_4A_ATS_TA1_BOTH_106KBIT (0U << 0) +#define ISO14443_4A_ATS_TA1_PCD_TO_PICC_212KBIT (1U << 0) +#define ISO14443_4A_ATS_TA1_PCD_TO_PICC_424KBIT (1U << 1) +#define ISO14443_4A_ATS_TA1_PCD_TO_PICC_848KBIT (1U << 2) +#define ISO14443_4A_ATS_TA1_PICC_TO_PCD_212KBIT (1U << 4) +#define ISO14443_4A_ATS_TA1_PICC_TO_PCD_424KBIT (1U << 5) +#define ISO14443_4A_ATS_TA1_PICC_TO_PCD_848KBIT (1U << 6) #define ISO14443_4A_ATS_TA1_BOTH_SAME_COMPULSORY (1U << 7) #define ISO14443_4A_ATS_TC1_NAD (1U << 0) diff --git a/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c b/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c index 961a61d7179..a9453b03907 100644 --- a/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c +++ b/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c @@ -6,11 +6,11 @@ #define TAG "Iso14443_4aPoller" -#define ISO14443_4A_FSDI_256 (0x8U) -#define ISO14443_4A_FWT_MAX (4096UL << 14) +#define ISO14443_4A_FSDI_256 (0x8U) +#define ISO14443_4A_FWT_MAX (4096UL << 14) #define ISO14443_4A_WTXM_MASK (0x3FU) -#define ISO14443_4A_WTXM_MAX (0x3BU) -#define ISO14443_4A_SWTX (0xF2U) +#define ISO14443_4A_WTXM_MAX (0x3BU) +#define ISO14443_4A_SWTX (0xF2U) Iso14443_4aError iso14443_4a_poller_halt(Iso14443_4aPoller* instance) { furi_check(instance); diff --git a/lib/nfc/protocols/iso14443_4b/iso14443_4b.c b/lib/nfc/protocols/iso14443_4b/iso14443_4b.c index 6f849b1d463..2e72eced8dc 100644 --- a/lib/nfc/protocols/iso14443_4b/iso14443_4b.c +++ b/lib/nfc/protocols/iso14443_4b/iso14443_4b.c @@ -4,7 +4,7 @@ #include #define ISO14443_4B_PROTOCOL_NAME "ISO14443-4B" -#define ISO14443_4B_DEVICE_NAME "ISO14443-4B (Unknown)" +#define ISO14443_4B_DEVICE_NAME "ISO14443-4B (Unknown)" const NfcDeviceBase nfc_device_iso14443_4b = { .protocol_name = ISO14443_4B_PROTOCOL_NAME, diff --git a/lib/nfc/protocols/iso15693_3/iso15693_3.c b/lib/nfc/protocols/iso15693_3/iso15693_3.c index 1c94ac81142..e2628b258ab 100644 --- a/lib/nfc/protocols/iso15693_3/iso15693_3.c +++ b/lib/nfc/protocols/iso15693_3/iso15693_3.c @@ -3,21 +3,21 @@ #include -#define ISO15693_3_PROTOCOL_NAME "ISO15693-3" +#define ISO15693_3_PROTOCOL_NAME "ISO15693-3" #define ISO15693_3_PROTOCOL_NAME_LEGACY "ISO15693" -#define ISO15693_3_DEVICE_NAME "ISO15693-3 (Unknown)" +#define ISO15693_3_DEVICE_NAME "ISO15693-3 (Unknown)" #define ISO15693_3_LOCK_DSFID_LEGACY (1U << 0) -#define ISO15693_3_LOCK_AFI_LEGACY (1U << 1) - -#define ISO15693_3_DSFID_KEY "DSFID" -#define ISO15693_3_AFI_KEY "AFI" -#define ISO15693_3_IC_REF_KEY "IC Reference" -#define ISO15693_3_BLOCK_COUNT_KEY "Block Count" -#define ISO15693_3_BLOCK_SIZE_KEY "Block Size" -#define ISO15693_3_DATA_CONTENT_KEY "Data Content" -#define ISO15693_3_LOCK_DSFID_KEY "Lock DSFID" -#define ISO15693_3_LOCK_AFI_KEY "Lock AFI" +#define ISO15693_3_LOCK_AFI_LEGACY (1U << 1) + +#define ISO15693_3_DSFID_KEY "DSFID" +#define ISO15693_3_AFI_KEY "AFI" +#define ISO15693_3_IC_REF_KEY "IC Reference" +#define ISO15693_3_BLOCK_COUNT_KEY "Block Count" +#define ISO15693_3_BLOCK_SIZE_KEY "Block Size" +#define ISO15693_3_DATA_CONTENT_KEY "Data Content" +#define ISO15693_3_LOCK_DSFID_KEY "Lock DSFID" +#define ISO15693_3_LOCK_AFI_KEY "Lock AFI" #define ISO15693_3_SECURITY_STATUS_KEY "Security Status" const NfcDeviceBase nfc_device_iso15693_3 = { diff --git a/lib/nfc/protocols/iso15693_3/iso15693_3.h b/lib/nfc/protocols/iso15693_3/iso15693_3.h index 1120ac56e86..fdff7112b36 100644 --- a/lib/nfc/protocols/iso15693_3/iso15693_3.h +++ b/lib/nfc/protocols/iso15693_3/iso15693_3.h @@ -10,9 +10,9 @@ extern "C" { #define ISO15693_3_UID_SIZE (8U) -#define ISO15693_3_GUARD_TIME_US (5000U) -#define ISO15693_3_FDT_POLL_FC (4202U) -#define ISO15693_3_FDT_LISTEN_FC (4320U) +#define ISO15693_3_GUARD_TIME_US (5000U) +#define ISO15693_3_FDT_POLL_FC (4202U) +#define ISO15693_3_FDT_LISTEN_FC (4320U) #define ISO15693_3_POLL_POLL_MIN_US (1500U) #define ISO15693_3_REQ_FLAG_SUBCARRIER_1 (0U << 0) @@ -21,59 +21,59 @@ extern "C" { #define ISO15693_3_REQ_FLAG_DATA_RATE_HI (1U << 1) #define ISO15693_3_REQ_FLAG_INVENTORY_T4 (0U << 2) #define ISO15693_3_REQ_FLAG_INVENTORY_T5 (1U << 2) -#define ISO15693_3_REQ_FLAG_EXTENSION (1U << 3) +#define ISO15693_3_REQ_FLAG_EXTENSION (1U << 3) -#define ISO15693_3_REQ_FLAG_T4_SELECTED (1U << 4) +#define ISO15693_3_REQ_FLAG_T4_SELECTED (1U << 4) #define ISO15693_3_REQ_FLAG_T4_ADDRESSED (1U << 5) -#define ISO15693_3_REQ_FLAG_T4_OPTION (1U << 6) +#define ISO15693_3_REQ_FLAG_T4_OPTION (1U << 6) #define ISO15693_3_REQ_FLAG_T5_AFI_PRESENT (1U << 4) -#define ISO15693_3_REQ_FLAG_T5_N_SLOTS_16 (0U << 5) -#define ISO15693_3_REQ_FLAG_T5_N_SLOTS_1 (1U << 5) -#define ISO15693_3_REQ_FLAG_T5_OPTION (1U << 6) +#define ISO15693_3_REQ_FLAG_T5_N_SLOTS_16 (0U << 5) +#define ISO15693_3_REQ_FLAG_T5_N_SLOTS_1 (1U << 5) +#define ISO15693_3_REQ_FLAG_T5_OPTION (1U << 6) -#define ISO15693_3_RESP_FLAG_NONE (0U) -#define ISO15693_3_RESP_FLAG_ERROR (1U << 0) +#define ISO15693_3_RESP_FLAG_NONE (0U) +#define ISO15693_3_RESP_FLAG_ERROR (1U << 0) #define ISO15693_3_RESP_FLAG_EXTENSION (1U << 3) -#define ISO15693_3_RESP_ERROR_NOT_SUPPORTED (0x01U) -#define ISO15693_3_RESP_ERROR_FORMAT (0x02U) -#define ISO15693_3_RESP_ERROR_OPTION (0x03U) -#define ISO15693_3_RESP_ERROR_UNKNOWN (0x0FU) -#define ISO15693_3_RESP_ERROR_BLOCK_UNAVAILABLE (0x10U) +#define ISO15693_3_RESP_ERROR_NOT_SUPPORTED (0x01U) +#define ISO15693_3_RESP_ERROR_FORMAT (0x02U) +#define ISO15693_3_RESP_ERROR_OPTION (0x03U) +#define ISO15693_3_RESP_ERROR_UNKNOWN (0x0FU) +#define ISO15693_3_RESP_ERROR_BLOCK_UNAVAILABLE (0x10U) #define ISO15693_3_RESP_ERROR_BLOCK_ALREADY_LOCKED (0x11U) -#define ISO15693_3_RESP_ERROR_BLOCK_LOCKED (0x12U) -#define ISO15693_3_RESP_ERROR_BLOCK_WRITE (0x13U) -#define ISO15693_3_RESP_ERROR_BLOCK_LOCK (0x14U) -#define ISO15693_3_RESP_ERROR_CUSTOM_START (0xA0U) -#define ISO15693_3_RESP_ERROR_CUSTOM_END (0xDFU) - -#define ISO15693_3_CMD_MANDATORY_START (0x01U) -#define ISO15693_3_CMD_INVENTORY (0x01U) -#define ISO15693_3_CMD_STAY_QUIET (0x02U) -#define ISO15693_3_CMD_MANDATORY_RFU (0x03U) -#define ISO15693_3_CMD_OPTIONAL_START (0x20U) -#define ISO15693_3_CMD_READ_BLOCK (0x20U) -#define ISO15693_3_CMD_WRITE_BLOCK (0x21U) -#define ISO15693_3_CMD_LOCK_BLOCK (0x22U) -#define ISO15693_3_CMD_READ_MULTI_BLOCKS (0x23U) -#define ISO15693_3_CMD_WRITE_MULTI_BLOCKS (0x24U) -#define ISO15693_3_CMD_SELECT (0x25U) -#define ISO15693_3_CMD_RESET_TO_READY (0x26U) -#define ISO15693_3_CMD_WRITE_AFI (0x27U) -#define ISO15693_3_CMD_LOCK_AFI (0x28U) -#define ISO15693_3_CMD_WRITE_DSFID (0x29U) -#define ISO15693_3_CMD_LOCK_DSFID (0x2AU) -#define ISO15693_3_CMD_GET_SYS_INFO (0x2BU) +#define ISO15693_3_RESP_ERROR_BLOCK_LOCKED (0x12U) +#define ISO15693_3_RESP_ERROR_BLOCK_WRITE (0x13U) +#define ISO15693_3_RESP_ERROR_BLOCK_LOCK (0x14U) +#define ISO15693_3_RESP_ERROR_CUSTOM_START (0xA0U) +#define ISO15693_3_RESP_ERROR_CUSTOM_END (0xDFU) + +#define ISO15693_3_CMD_MANDATORY_START (0x01U) +#define ISO15693_3_CMD_INVENTORY (0x01U) +#define ISO15693_3_CMD_STAY_QUIET (0x02U) +#define ISO15693_3_CMD_MANDATORY_RFU (0x03U) +#define ISO15693_3_CMD_OPTIONAL_START (0x20U) +#define ISO15693_3_CMD_READ_BLOCK (0x20U) +#define ISO15693_3_CMD_WRITE_BLOCK (0x21U) +#define ISO15693_3_CMD_LOCK_BLOCK (0x22U) +#define ISO15693_3_CMD_READ_MULTI_BLOCKS (0x23U) +#define ISO15693_3_CMD_WRITE_MULTI_BLOCKS (0x24U) +#define ISO15693_3_CMD_SELECT (0x25U) +#define ISO15693_3_CMD_RESET_TO_READY (0x26U) +#define ISO15693_3_CMD_WRITE_AFI (0x27U) +#define ISO15693_3_CMD_LOCK_AFI (0x28U) +#define ISO15693_3_CMD_WRITE_DSFID (0x29U) +#define ISO15693_3_CMD_LOCK_DSFID (0x2AU) +#define ISO15693_3_CMD_GET_SYS_INFO (0x2BU) #define ISO15693_3_CMD_GET_BLOCKS_SECURITY (0x2CU) -#define ISO15693_3_CMD_OPTIONAL_RFU (0x2DU) -#define ISO15693_3_CMD_CUSTOM_START (0xA0U) +#define ISO15693_3_CMD_OPTIONAL_RFU (0x2DU) +#define ISO15693_3_CMD_CUSTOM_START (0xA0U) #define ISO15693_3_MANDATORY_COUNT (ISO15693_3_CMD_MANDATORY_RFU - ISO15693_3_CMD_MANDATORY_START) -#define ISO15693_3_OPTIONAL_COUNT (ISO15693_3_CMD_OPTIONAL_RFU - ISO15693_3_CMD_OPTIONAL_START) +#define ISO15693_3_OPTIONAL_COUNT (ISO15693_3_CMD_OPTIONAL_RFU - ISO15693_3_CMD_OPTIONAL_START) -#define ISO15693_3_SYSINFO_FLAG_DSFID (1U << 0) -#define ISO15693_3_SYSINFO_FLAG_AFI (1U << 1) +#define ISO15693_3_SYSINFO_FLAG_DSFID (1U << 0) +#define ISO15693_3_SYSINFO_FLAG_AFI (1U << 1) #define ISO15693_3_SYSINFO_FLAG_MEMORY (1U << 2) #define ISO15693_3_SYSINFO_FLAG_IC_REF (1U << 3) diff --git a/lib/nfc/protocols/mf_classic/mf_classic.c b/lib/nfc/protocols/mf_classic/mf_classic.c index 5fee3eb7b41..4f92201e342 100644 --- a/lib/nfc/protocols/mf_classic/mf_classic.c +++ b/lib/nfc/protocols/mf_classic/mf_classic.c @@ -432,6 +432,23 @@ bool mf_classic_is_sector_trailer(uint8_t block) { return block == mf_classic_get_sector_trailer_num_by_block(block); } +void mf_classic_set_sector_trailer_read( + MfClassicData* data, + uint8_t block_num, + MfClassicSectorTrailer* sec_tr) { + furi_check(data); + furi_check(sec_tr); + furi_check(mf_classic_is_sector_trailer(block_num)); + + uint8_t sector_num = mf_classic_get_sector_by_block(block_num); + MfClassicSectorTrailer* sec_trailer = + mf_classic_get_sector_trailer_by_sector(data, sector_num); + memcpy(sec_trailer, sec_tr, sizeof(MfClassicSectorTrailer)); + FURI_BIT_SET(data->block_read_mask[block_num / 32], block_num % 32); + FURI_BIT_SET(data->key_a_mask, sector_num); + FURI_BIT_SET(data->key_b_mask, sector_num); +} + uint8_t mf_classic_get_sector_by_block(uint8_t block) { uint8_t sector = 0; @@ -529,7 +546,7 @@ void mf_classic_set_key_not_found( bool mf_classic_is_block_read(const MfClassicData* data, uint8_t block_num) { furi_check(data); - return (FURI_BIT(data->block_read_mask[block_num / 32], block_num % 32) == 1); + return FURI_BIT(data->block_read_mask[block_num / 32], block_num % 32) == 1; } void mf_classic_set_block_read(MfClassicData* data, uint8_t block_num, MfClassicBlock* block_data) { @@ -644,22 +661,20 @@ static bool mf_classic_is_allowed_access_sector_trailer( } case MfClassicActionKeyAWrite: case MfClassicActionKeyBWrite: { - return ( - (key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x01)) || - (key_type == MfClassicKeyTypeB && - (AC == 0x00 || AC == 0x04 || AC == 0x03 || AC == 0x01))); + return (key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x01)) || + (key_type == MfClassicKeyTypeB && + (AC == 0x00 || AC == 0x04 || AC == 0x03 || AC == 0x01)); } case MfClassicActionKeyBRead: { return (key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x02 || AC == 0x01)) || (key_type == MfClassicKeyTypeB && (AC == 0x00 || AC == 0x02 || AC == 0x01)); } case MfClassicActionACRead: { - return ((key_type == MfClassicKeyTypeA) || (key_type == MfClassicKeyTypeB)); + return (key_type == MfClassicKeyTypeA) || (key_type == MfClassicKeyTypeB); } case MfClassicActionACWrite: { - return ( - (key_type == MfClassicKeyTypeA && (AC == 0x01)) || - (key_type == MfClassicKeyTypeB && (AC == 0x01 || AC == 0x03 || AC == 0x05))); + return (key_type == MfClassicKeyTypeA && (AC == 0x01)) || + (key_type == MfClassicKeyTypeB && (AC == 0x01 || AC == 0x03 || AC == 0x05)); } default: return false; @@ -710,25 +725,21 @@ bool mf_classic_is_allowed_access_data_block( switch(action) { case MfClassicActionDataRead: { - return ( - (key_type == MfClassicKeyTypeA && !(AC == 0x03 || AC == 0x05 || AC == 0x07)) || - (key_type == MfClassicKeyTypeB && !(AC == 0x07))); + return (key_type == MfClassicKeyTypeA && !(AC == 0x03 || AC == 0x05 || AC == 0x07)) || + (key_type == MfClassicKeyTypeB && !(AC == 0x07)); } case MfClassicActionDataWrite: { - return ( - (key_type == MfClassicKeyTypeA && (AC == 0x00)) || - (key_type == MfClassicKeyTypeB && - (AC == 0x00 || AC == 0x04 || AC == 0x06 || AC == 0x03))); + return (key_type == MfClassicKeyTypeA && (AC == 0x00)) || + (key_type == MfClassicKeyTypeB && + (AC == 0x00 || AC == 0x04 || AC == 0x06 || AC == 0x03)); } case MfClassicActionDataInc: { - return ( - (key_type == MfClassicKeyTypeA && (AC == 0x00)) || - (key_type == MfClassicKeyTypeB && (AC == 0x00 || AC == 0x06))); + return (key_type == MfClassicKeyTypeA && (AC == 0x00)) || + (key_type == MfClassicKeyTypeB && (AC == 0x00 || AC == 0x06)); } case MfClassicActionDataDec: { - return ( - (key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x06 || AC == 0x01)) || - (key_type == MfClassicKeyTypeB && (AC == 0x00 || AC == 0x06 || AC == 0x01))); + return (key_type == MfClassicKeyTypeA && (AC == 0x00 || AC == 0x06 || AC == 0x01)) || + (key_type == MfClassicKeyTypeB && (AC == 0x00 || AC == 0x06 || AC == 0x01)); } default: return false; diff --git a/lib/nfc/protocols/mf_classic/mf_classic.h b/lib/nfc/protocols/mf_classic/mf_classic.h index b42e09ab1d3..801ec1764d8 100644 --- a/lib/nfc/protocols/mf_classic/mf_classic.h +++ b/lib/nfc/protocols/mf_classic/mf_classic.h @@ -6,27 +6,27 @@ extern "C" { #endif -#define MF_CLASSIC_CMD_AUTH_KEY_A (0x60U) -#define MF_CLASSIC_CMD_AUTH_KEY_B (0x61U) -#define MF_CLASSIC_CMD_READ_BLOCK (0x30U) -#define MF_CLASSIC_CMD_WRITE_BLOCK (0xA0U) -#define MF_CLASSIC_CMD_VALUE_DEC (0xC0U) -#define MF_CLASSIC_CMD_VALUE_INC (0xC1U) -#define MF_CLASSIC_CMD_VALUE_RESTORE (0xC2U) +#define MF_CLASSIC_CMD_AUTH_KEY_A (0x60U) +#define MF_CLASSIC_CMD_AUTH_KEY_B (0x61U) +#define MF_CLASSIC_CMD_READ_BLOCK (0x30U) +#define MF_CLASSIC_CMD_WRITE_BLOCK (0xA0U) +#define MF_CLASSIC_CMD_VALUE_DEC (0xC0U) +#define MF_CLASSIC_CMD_VALUE_INC (0xC1U) +#define MF_CLASSIC_CMD_VALUE_RESTORE (0xC2U) #define MF_CLASSIC_CMD_VALUE_TRANSFER (0xB0U) -#define MF_CLASSIC_CMD_HALT_MSB (0x50) -#define MF_CLASSIC_CMD_HALT_LSB (0x00) -#define MF_CLASSIC_CMD_ACK (0x0A) -#define MF_CLASSIC_CMD_NACK (0x00) -#define MF_CLASSIC_CMD_NACK_TRANSFER_INVALID (0x04) +#define MF_CLASSIC_CMD_HALT_MSB (0x50) +#define MF_CLASSIC_CMD_HALT_LSB (0x00) +#define MF_CLASSIC_CMD_ACK (0x0A) +#define MF_CLASSIC_CMD_NACK (0x00) +#define MF_CLASSIC_CMD_NACK_TRANSFER_INVALID (0x04) #define MF_CLASSIC_CMD_NACK_TRANSFER_CRC_ERROR (0x01) #define MF_CLASSIC_TOTAL_SECTORS_MAX (40) -#define MF_CLASSIC_TOTAL_BLOCKS_MAX (256) -#define MF_CLASSIC_READ_MASK_SIZE (MF_CLASSIC_TOTAL_BLOCKS_MAX / 32) -#define MF_CLASSIC_BLOCK_SIZE (16) -#define MF_CLASSIC_KEY_SIZE (6) +#define MF_CLASSIC_TOTAL_BLOCKS_MAX (256) +#define MF_CLASSIC_READ_MASK_SIZE (MF_CLASSIC_TOTAL_BLOCKS_MAX / 32) +#define MF_CLASSIC_BLOCK_SIZE (16) +#define MF_CLASSIC_KEY_SIZE (6) #define MF_CLASSIC_ACCESS_BYTES_SIZE (4) #define MF_CLASSIC_NT_SIZE (4) @@ -184,6 +184,11 @@ MfClassicSectorTrailer* bool mf_classic_is_sector_trailer(uint8_t block); +void mf_classic_set_sector_trailer_read( + MfClassicData* data, + uint8_t block_num, + MfClassicSectorTrailer* sec_tr); + uint8_t mf_classic_get_sector_by_block(uint8_t block); bool mf_classic_block_to_value(const MfClassicBlock* block, int32_t* value, uint8_t* addr); diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire.h b/lib/nfc/protocols/mf_desfire/mf_desfire.h index 2818e9a24eb..dd2009276b6 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire.h +++ b/lib/nfc/protocols/mf_desfire/mf_desfire.h @@ -8,26 +8,26 @@ extern "C" { #endif -#define MF_DESFIRE_CMD_GET_VERSION (0x60) -#define MF_DESFIRE_CMD_GET_FREE_MEMORY (0x6E) -#define MF_DESFIRE_CMD_GET_KEY_SETTINGS (0x45) -#define MF_DESFIRE_CMD_GET_KEY_VERSION (0x64) +#define MF_DESFIRE_CMD_GET_VERSION (0x60) +#define MF_DESFIRE_CMD_GET_FREE_MEMORY (0x6E) +#define MF_DESFIRE_CMD_GET_KEY_SETTINGS (0x45) +#define MF_DESFIRE_CMD_GET_KEY_VERSION (0x64) #define MF_DESFIRE_CMD_GET_APPLICATION_IDS (0x6A) -#define MF_DESFIRE_CMD_SELECT_APPLICATION (0x5A) -#define MF_DESFIRE_CMD_GET_FILE_IDS (0x6F) -#define MF_DESFIRE_CMD_GET_FILE_SETTINGS (0xF5) +#define MF_DESFIRE_CMD_SELECT_APPLICATION (0x5A) +#define MF_DESFIRE_CMD_GET_FILE_IDS (0x6F) +#define MF_DESFIRE_CMD_GET_FILE_SETTINGS (0xF5) -#define MF_DESFIRE_CMD_READ_DATA (0xBD) -#define MF_DESFIRE_CMD_GET_VALUE (0x6C) +#define MF_DESFIRE_CMD_READ_DATA (0xBD) +#define MF_DESFIRE_CMD_GET_VALUE (0x6C) #define MF_DESFIRE_CMD_READ_RECORDS (0xBB) -#define MF_DESFIRE_MAX_KEYS (14) +#define MF_DESFIRE_MAX_KEYS (14) #define MF_DESFIRE_MAX_FILES (32) -#define MF_DESFIRE_UID_SIZE (7) -#define MF_DESFIRE_BATCH_SIZE (5) +#define MF_DESFIRE_UID_SIZE (7) +#define MF_DESFIRE_BATCH_SIZE (5) #define MF_DESFIRE_APP_ID_SIZE (3) -#define MF_DESFIRE_VALUE_SIZE (4) +#define MF_DESFIRE_VALUE_SIZE (4) typedef struct { uint8_t hw_vendor; diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire_i.c b/lib/nfc/protocols/mf_desfire/mf_desfire_i.c index bfbbadadff1..d83a91ad1ae 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire_i.c +++ b/lib/nfc/protocols/mf_desfire/mf_desfire_i.c @@ -11,15 +11,15 @@ MF_DESFIRE_FFF_PICC_PREFIX " " \ "Free Memory" -#define MF_DESFIRE_FFF_CHANGE_KEY_ID_KEY "Change Key ID" -#define MF_DESFIRE_FFF_CONFIG_CHANGEABLE_KEY "Config Changeable" +#define MF_DESFIRE_FFF_CHANGE_KEY_ID_KEY "Change Key ID" +#define MF_DESFIRE_FFF_CONFIG_CHANGEABLE_KEY "Config Changeable" #define MF_DESFIRE_FFF_FREE_CREATE_DELETE_KEY "Free Create Delete" -#define MF_DESFIRE_FFF_FREE_DIR_LIST_KEY "Free Directory List" -#define MF_DESFIRE_FFF_KEY_CHANGEABLE_KEY "Key Changeable" -#define MF_DESFIRE_FFF_FLAGS_KEY "Flags" -#define MF_DESFIRE_FFF_MAX_KEYS_KEY "Max Keys" +#define MF_DESFIRE_FFF_FREE_DIR_LIST_KEY "Free Directory List" +#define MF_DESFIRE_FFF_KEY_CHANGEABLE_KEY "Key Changeable" +#define MF_DESFIRE_FFF_FLAGS_KEY "Flags" +#define MF_DESFIRE_FFF_MAX_KEYS_KEY "Max Keys" -#define MF_DESFIRE_FFF_KEY_SUB_PREFIX "Key" +#define MF_DESFIRE_FFF_KEY_SUB_PREFIX "Key" #define MF_DESFIRE_FFF_KEY_VERSION_KEY "Version" #define MF_DESFIRE_FFF_APPLICATION_COUNT_KEY \ @@ -33,15 +33,15 @@ #define MF_DESFIRE_FFF_FILE_IDS_KEY \ MF_DESFIRE_FFF_FILE_SUB_PREFIX " " \ "IDs" -#define MF_DESFIRE_FFF_FILE_TYPE_KEY "Type" +#define MF_DESFIRE_FFF_FILE_TYPE_KEY "Type" #define MF_DESFIRE_FFF_FILE_COMM_SETTINGS_KEY "Communication Settings" #define MF_DESFIRE_FFF_FILE_ACCESS_RIGHTS_KEY "Access Rights" #define MF_DESFIRE_FFF_FILE_SIZE_KEY "Size" -#define MF_DESFIRE_FFF_FILE_HI_LIMIT_KEY "Hi Limit" -#define MF_DESFIRE_FFF_FILE_LO_LIMIT_KEY "Lo Limit" -#define MF_DESFIRE_FFF_FILE_LIMIT_CREDIT_VALUE_KEY "Limited Credit Value" +#define MF_DESFIRE_FFF_FILE_HI_LIMIT_KEY "Hi Limit" +#define MF_DESFIRE_FFF_FILE_LO_LIMIT_KEY "Lo Limit" +#define MF_DESFIRE_FFF_FILE_LIMIT_CREDIT_VALUE_KEY "Limited Credit Value" #define MF_DESFIRE_FFF_FILE_LIMIT_CREDIT_ENABLED_KEY "Limited Credit Enabled" #define MF_DESFIRE_FFF_FILE_MAX_KEY "Max" @@ -78,12 +78,12 @@ bool mf_desfire_free_memory_parse(MfDesfireFreeMemory* data, const BitBuffer* bu bool mf_desfire_key_settings_parse(MfDesfireKeySettings* data, const BitBuffer* buf) { typedef struct FURI_PACKED { bool is_master_key_changeable : 1; - bool is_free_directory_list : 1; - bool is_free_create_delete : 1; - bool is_config_changeable : 1; - uint8_t change_key_id : 4; - uint8_t max_keys : 4; - uint8_t flags : 4; + bool is_free_directory_list : 1; + bool is_free_create_delete : 1; + bool is_config_changeable : 1; + uint8_t change_key_id : 4; + uint8_t max_keys : 4; + uint8_t flags : 4; } MfDesfireKeySettingsLayout; const bool can_parse = bit_buffer_get_size_bytes(buf) == sizeof(MfDesfireKeySettingsLayout); @@ -164,8 +164,8 @@ bool mf_desfire_file_settings_parse(MfDesfireFileSettings* data, const BitBuffer typedef struct FURI_PACKED { uint32_t size : 3 * BITS_IN_BYTE; - uint32_t max : 3 * BITS_IN_BYTE; - uint32_t cur : 3 * BITS_IN_BYTE; + uint32_t max : 3 * BITS_IN_BYTE; + uint32_t cur : 3 * BITS_IN_BYTE; } MfDesfireFileSettingsRecord; typedef struct FURI_PACKED { diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire_i.h b/lib/nfc/protocols/mf_desfire/mf_desfire_i.h index 21250baace3..921bbb9ded5 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire_i.h +++ b/lib/nfc/protocols/mf_desfire/mf_desfire_i.h @@ -3,53 +3,53 @@ #include "mf_desfire.h" #define MF_DESFIRE_FFF_PICC_PREFIX "PICC" -#define MF_DESFIRE_FFF_APP_PREFIX "Application" +#define MF_DESFIRE_FFF_APP_PREFIX "Application" // Successful operation -#define MF_DESFIRE_STATUS_OPERATION_OK (0x00) +#define MF_DESFIRE_STATUS_OPERATION_OK (0x00) // No changes done to backup files, CommitTransaction / AbortTransaction not necessary -#define MF_DESFIRE_STATUS_NO_CHANGES (0x0C) +#define MF_DESFIRE_STATUS_NO_CHANGES (0x0C) // Insufficient NV-Memory to complete command -#define MF_DESFIRE_STATUS_OUT_OF_EEPROM_ERROR (0x0E) +#define MF_DESFIRE_STATUS_OUT_OF_EEPROM_ERROR (0x0E) // Command code not supported -#define MF_DESFIRE_STATUS_ILLEGAL_COMMAND_CODE (0x1C) +#define MF_DESFIRE_STATUS_ILLEGAL_COMMAND_CODE (0x1C) // CRC or MAC does not match data Padding bytes not valid -#define MF_DESFIRE_STATUS_INTEGRITY_ERROR (0x1E) +#define MF_DESFIRE_STATUS_INTEGRITY_ERROR (0x1E) // Invalid key number specified -#define MF_DESFIRE_STATUS_NO_SUCH_KEY (0x40) +#define MF_DESFIRE_STATUS_NO_SUCH_KEY (0x40) // Length of command string invalid -#define MF_DESFIRE_STATUS_LENGTH_ERROR (0x7E) +#define MF_DESFIRE_STATUS_LENGTH_ERROR (0x7E) // Current configuration / status does not allow the requested command -#define MF_DESFIRE_STATUS_PERMISSION_DENIED (0x9D) +#define MF_DESFIRE_STATUS_PERMISSION_DENIED (0x9D) // Value of the parameter(s) invalid -#define MF_DESFIRE_STATUS_PARAMETER_ERROR (0x9E) +#define MF_DESFIRE_STATUS_PARAMETER_ERROR (0x9E) // Requested AID not present on PICC #define MF_DESFIRE_STATUS_APPLICATION_NOT_FOUND (0xA0) // Unrecoverable error within application, application will be disabled -#define MF_DESFIRE_STATUS_APPL_INTEGRITY_ERROR (0xA1) +#define MF_DESFIRE_STATUS_APPL_INTEGRITY_ERROR (0xA1) // Current authentication status does not allow the requested command -#define MF_DESFIRE_STATUS_AUTHENTICATION_ERROR (0xAE) +#define MF_DESFIRE_STATUS_AUTHENTICATION_ERROR (0xAE) // Additional data frame is expected to be sent -#define MF_DESFIRE_STATUS_ADDITIONAL_FRAME (0xAF) +#define MF_DESFIRE_STATUS_ADDITIONAL_FRAME (0xAF) // Attempt to read/write data from/to beyond the file's/record's limits // Attempt to exceed the limits of a value file. -#define MF_DESFIRE_STATUS_BOUNDARY_ERROR (0xBE) +#define MF_DESFIRE_STATUS_BOUNDARY_ERROR (0xBE) // Unrecoverable error within PICC, PICC will be disabled -#define MF_DESFIRE_STATUS_PICC_INTEGRITY_ERROR (0xC1) +#define MF_DESFIRE_STATUS_PICC_INTEGRITY_ERROR (0xC1) // Previous Command was not fully completed. Not all Frames were requested or provided by the PCD -#define MF_DESFIRE_STATUS_COMMAND_ABORTED (0xCA) +#define MF_DESFIRE_STATUS_COMMAND_ABORTED (0xCA) // PICC was disabled by an unrecoverable error -#define MF_DESFIRE_STATUS_PICC_DISABLED_ERROR (0xCD) +#define MF_DESFIRE_STATUS_PICC_DISABLED_ERROR (0xCD) // Number of Applications limited to 28, no additional CreateApplication possible -#define MF_DESFIRE_STATUS_COUNT_ERROR (0xCE) +#define MF_DESFIRE_STATUS_COUNT_ERROR (0xCE) // Creation of file/application failed because file/application with same number already exists -#define MF_DESFIRE_STATUS_DUBLICATE_ERROR (0xDE) +#define MF_DESFIRE_STATUS_DUBLICATE_ERROR (0xDE) // Could not complete NV-write operation due to loss of power, internal backup/rollback mechanism activated -#define MF_DESFIRE_STATUS_EEPROM_ERROR (0xEE) +#define MF_DESFIRE_STATUS_EEPROM_ERROR (0xEE) // Specified file number does not exist -#define MF_DESFIRE_STATUS_FILE_NOT_FOUND (0xF0) +#define MF_DESFIRE_STATUS_FILE_NOT_FOUND (0xF0) // Unrecoverable error within file, file will be disabled -#define MF_DESFIRE_STATUS_FILE_INTEGRITY_ERROR (0xF1) +#define MF_DESFIRE_STATUS_FILE_INTEGRITY_ERROR (0xF1) // SimpleArray configurations diff --git a/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c b/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c index fa8a7ae9b90..bd8ecfaeed1 100644 --- a/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c +++ b/lib/nfc/protocols/mf_desfire/mf_desfire_poller.c @@ -6,7 +6,7 @@ #define TAG "MfDesfirePoller" -#define MF_DESFIRE_BUF_SIZE (64U) +#define MF_DESFIRE_BUF_SIZE (64U) #define MF_DESFIRE_RESULT_BUF_SIZE (512U) typedef NfcCommand (*MfDesfirePollerReadHandler)(MfDesfirePoller* instance); diff --git a/lib/nfc/protocols/mf_plus/mf_plus.c b/lib/nfc/protocols/mf_plus/mf_plus.c index 32d8d6c5996..1d00594c641 100644 --- a/lib/nfc/protocols/mf_plus/mf_plus.c +++ b/lib/nfc/protocols/mf_plus/mf_plus.c @@ -177,4 +177,4 @@ Iso14443_4aData* mf_plus_get_base_data(const MfPlusData* data) { furi_check(data); return data->iso14443_4a_data; -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/mf_plus/mf_plus.h b/lib/nfc/protocols/mf_plus/mf_plus.h index 31559ffdc8b..b68c3279e0b 100644 --- a/lib/nfc/protocols/mf_plus/mf_plus.h +++ b/lib/nfc/protocols/mf_plus/mf_plus.h @@ -7,7 +7,7 @@ extern "C" { #endif #define MF_PLUS_UID_SIZE_MAX (7) -#define MF_PLUS_BATCH_SIZE (5) +#define MF_PLUS_BATCH_SIZE (5) #define MF_PLUS_CMD_GET_VERSION (0x60) @@ -112,4 +112,4 @@ Iso14443_4aData* mf_plus_get_base_data(const MfPlusData* data); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/nfc/protocols/mf_plus/mf_plus_i.c b/lib/nfc/protocols/mf_plus/mf_plus_i.c index 13bf8c5d8d5..4ad2ff87841 100644 --- a/lib/nfc/protocols/mf_plus/mf_plus_i.c +++ b/lib/nfc/protocols/mf_plus/mf_plus_i.c @@ -7,8 +7,8 @@ #define MF_PLUS_T1_TK_VALUE_LEN 7 #define MF_PLUS_FFF_SECURITY_LEVEL_KEY "Security Level" -#define MF_PLUS_FFF_CARD_TYPE_KEY "Card Type" -#define MF_PLUS_FFF_MEMORY_SIZE_KEY "Memory Size" +#define MF_PLUS_FFF_CARD_TYPE_KEY "Card Type" +#define MF_PLUS_FFF_MEMORY_SIZE_KEY "Memory Size" #define TAG "MfPlus" diff --git a/lib/nfc/protocols/mf_plus/mf_plus_poller.c b/lib/nfc/protocols/mf_plus/mf_plus_poller.c index c93ec9e67c1..8d1cc1c99a2 100644 --- a/lib/nfc/protocols/mf_plus/mf_plus_poller.c +++ b/lib/nfc/protocols/mf_plus/mf_plus_poller.c @@ -7,7 +7,7 @@ #define TAG "MfPlusPoller" -#define MF_PLUS_BUF_SIZE (64U) +#define MF_PLUS_BUF_SIZE (64U) #define MF_PLUS_RESULT_BUF_SIZE (512U) typedef NfcCommand (*MfPlusPollerReadHandler)(MfPlusPoller* instance); @@ -197,7 +197,7 @@ static bool mf_plus_poller_detect(NfcGenericEvent event, void* context) { } } - return (error == MfPlusErrorNone); + return error == MfPlusErrorNone; } const NfcPollerBase mf_plus_poller = { diff --git a/lib/nfc/protocols/mf_plus/mf_plus_poller.h b/lib/nfc/protocols/mf_plus/mf_plus_poller.h index 7e892366fa0..1e4e97eaf17 100644 --- a/lib/nfc/protocols/mf_plus/mf_plus_poller.h +++ b/lib/nfc/protocols/mf_plus/mf_plus_poller.h @@ -52,4 +52,4 @@ MfPlusError mf_plus_poller_read_version(MfPlusPoller* instance, MfPlusVersion* d #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight.c index 1f3481c1786..d1f08294fee 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight.c @@ -5,15 +5,15 @@ #define MF_ULTRALIGHT_PROTOCOL_NAME "NTAG/Ultralight" -#define MF_ULTRALIGHT_FORMAT_VERSION_KEY "Data format version" -#define MF_ULTRALIGHT_TYPE_KEY MF_ULTRALIGHT_PROTOCOL_NAME " type" -#define MF_ULTRALIGHT_SIGNATURE_KEY "Signature" -#define MF_ULTRALIGHT_MIFARE_VERSION_KEY "Mifare version" -#define MF_ULTRALIGHT_COUNTER_KEY "Counter" -#define MF_ULTRALIGHT_TEARING_KEY "Tearing" -#define MF_ULTRALIGHT_PAGES_TOTAL_KEY "Pages total" -#define MF_ULTRALIGHT_PAGES_READ_KEY "Pages read" -#define MF_ULTRALIGHT_PAGE_KEY "Page" +#define MF_ULTRALIGHT_FORMAT_VERSION_KEY "Data format version" +#define MF_ULTRALIGHT_TYPE_KEY MF_ULTRALIGHT_PROTOCOL_NAME " type" +#define MF_ULTRALIGHT_SIGNATURE_KEY "Signature" +#define MF_ULTRALIGHT_MIFARE_VERSION_KEY "Mifare version" +#define MF_ULTRALIGHT_COUNTER_KEY "Counter" +#define MF_ULTRALIGHT_TEARING_KEY "Tearing" +#define MF_ULTRALIGHT_PAGES_TOTAL_KEY "Pages total" +#define MF_ULTRALIGHT_PAGES_READ_KEY "Pages read" +#define MF_ULTRALIGHT_PAGE_KEY "Page" #define MF_ULTRALIGHT_FAILED_ATTEMPTS_KEY "Failed authentication attempts" typedef struct { @@ -598,7 +598,7 @@ uint8_t mf_ultralight_get_pwd_page_num(MfUltralightType type) { bool mf_ultralight_is_page_pwd_or_pack(MfUltralightType type, uint16_t page) { uint8_t pwd_page = mf_ultralight_get_pwd_page_num(type); uint8_t pack_page = pwd_page + 1; - return ((pwd_page != 0) && (page == pwd_page || page == pack_page)); + return (pwd_page != 0) && (page == pwd_page || page == pack_page); } bool mf_ultralight_support_feature(const uint32_t feature_set, const uint32_t features_to_check) { @@ -624,15 +624,19 @@ bool mf_ultralight_is_all_data_read(const MfUltralightData* data) { furi_check(data); bool all_read = false; - if(data->pages_read == data->pages_total || - (data->type == MfUltralightTypeMfulC && data->pages_read == data->pages_total - 4)) { - // Having read all the pages doesn't mean that we've got everything. - // By default PWD is 0xFFFFFFFF, but if read back it is always 0x00000000, - // so a default read on an auth-supported NTAG is never complete. + + if(data->pages_read == data->pages_total) { uint32_t feature_set = mf_ultralight_get_feature_support_set(data->type); - if(!mf_ultralight_support_feature(feature_set, MfUltralightFeatureSupportPasswordAuth)) { + if((data->type == MfUltralightTypeMfulC) && + mf_ultralight_support_feature(feature_set, MfUltralightFeatureSupportAuthenticate)) { + all_read = true; + } else if(!mf_ultralight_support_feature( + feature_set, MfUltralightFeatureSupportPasswordAuth)) { all_read = true; } else { + // Having read all the pages doesn't mean that we've got everything. + // By default PWD is 0xFFFFFFFF, but if read back it is always 0x00000000, + // so a default read on an auth-supported NTAG is never complete. MfUltralightConfigPages* config = NULL; if(mf_ultralight_get_config_page(data, &config)) { uint32_t pass = bit_lib_bytes_to_num_be( @@ -669,3 +673,61 @@ bool mf_ultralight_is_counter_configured(const MfUltralightData* data) { return configured; } + +void mf_ultralight_3des_shift_data(uint8_t* const data) { + furi_check(data); + + uint8_t buf = data[0]; + for(uint8_t i = 1; i < MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE; i++) { + data[i - 1] = data[i]; + } + data[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE - 1] = buf; +} + +bool mf_ultralight_3des_key_valid(const MfUltralightData* data) { + furi_check(data); + furi_check(data->type == MfUltralightTypeMfulC); + + return !(data->pages_read == data->pages_total - 4); +} + +const uint8_t* mf_ultralight_3des_get_key(const MfUltralightData* data) { + furi_check(data); + furi_check(data->type == MfUltralightTypeMfulC); + + return data->page[44].data; +} + +void mf_ultralight_3des_encrypt( + mbedtls_des3_context* ctx, + const uint8_t* ck, + const uint8_t* iv, + const uint8_t* input, + const uint8_t length, + uint8_t* out) { + furi_check(ctx); + furi_check(ck); + furi_check(iv); + furi_check(input); + furi_check(out); + + mbedtls_des3_set2key_enc(ctx, ck); + mbedtls_des3_crypt_cbc(ctx, MBEDTLS_DES_ENCRYPT, length, (uint8_t*)iv, input, out); +} + +void mf_ultralight_3des_decrypt( + mbedtls_des3_context* ctx, + const uint8_t* ck, + const uint8_t* iv, + const uint8_t* input, + const uint8_t length, + uint8_t* out) { + furi_check(ctx); + furi_check(ck); + furi_check(iv); + furi_check(input); + furi_check(out); + + mbedtls_des3_set2key_dec(ctx, ck); + mbedtls_des3_crypt_cbc(ctx, MBEDTLS_DES_DECRYPT, length, (uint8_t*)iv, input, out); +} diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight.h b/lib/nfc/protocols/mf_ultralight/mf_ultralight.h index 582e9e0e260..caf25ceeeb5 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight.h +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight.h @@ -1,6 +1,7 @@ #pragma once #include +#include #ifdef __cplusplus extern "C" { @@ -8,36 +9,44 @@ extern "C" { #define MF_ULTRALIGHT_TEARING_FLAG_DEFAULT (0xBD) -#define MF_ULTRALIGHT_CMD_GET_VERSION (0x60) -#define MF_ULTRALIGHT_CMD_READ_PAGE (0x30) -#define MF_ULTRALIGHT_CMD_FAST_READ (0x3A) +#define MF_ULTRALIGHT_CMD_GET_VERSION (0x60) +#define MF_ULTRALIGHT_CMD_READ_PAGE (0x30) +#define MF_ULTRALIGHT_CMD_FAST_READ (0x3A) #define MF_ULTRALIGHT_CMD_SECTOR_SELECT (0xC2) -#define MF_ULTRALIGHT_CMD_COMP_WRITE (0xA0) -#define MF_ULTRALIGHT_CMD_WRITE_PAGE (0xA2) -#define MF_ULTRALIGHT_CMD_FAST_WRITE (0xA6) -#define MF_ULTRALIGHT_CMD_READ_SIG (0x3C) -#define MF_ULTRALIGHT_CMD_READ_CNT (0x39) -#define MF_ULTRALIGHT_CMD_INCR_CNT (0xA5) +#define MF_ULTRALIGHT_CMD_COMP_WRITE (0xA0) +#define MF_ULTRALIGHT_CMD_WRITE_PAGE (0xA2) +#define MF_ULTRALIGHT_CMD_FAST_WRITE (0xA6) +#define MF_ULTRALIGHT_CMD_READ_SIG (0x3C) +#define MF_ULTRALIGHT_CMD_READ_CNT (0x39) +#define MF_ULTRALIGHT_CMD_INCR_CNT (0xA5) #define MF_ULTRALIGHT_CMD_CHECK_TEARING (0x3E) -#define MF_ULTRALIGHT_CMD_PWD_AUTH (0x1B) -#define MF_ULTRALIGHT_CMD_AUTH (0x1A) -#define MF_ULTRALIGHT_CMD_VCSL (0x4B) +#define MF_ULTRALIGHT_CMD_PWD_AUTH (0x1B) +#define MF_ULTRALIGHT_CMD_AUTH (0x1A) +#define MF_ULTRALIGHT_CMD_VCSL (0x4B) -#define MF_ULTRALIGHT_CMD_ACK (0x0A) -#define MF_ULTRALIGHT_CMD_NACK (0x00) +#define MF_ULTRALIGHT_CMD_ACK (0x0A) +#define MF_ULTRALIGHT_CMD_NACK (0x00) #define MF_ULTRALIGHT_CMD_AUTH_NAK (0x04) -#define MF_ULTRALIGHT_MAX_CNTR_VAL (0x00FFFFFF) -#define MF_ULTRALIGHT_MAX_PAGE_NUM (510) -#define MF_ULTRALIGHT_PAGE_SIZE (4U) -#define MF_ULTRALIGHT_SIGNATURE_SIZE (32) -#define MF_ULTRALIGHT_COUNTER_SIZE (3) -#define MF_ULTRALIGHT_COUNTER_NUM (3) -#define MF_ULTRALIGHT_TEARING_FLAG_SIZE (1) -#define MF_ULTRALIGHT_TEARING_FLAG_NUM (3) +#define MF_ULTRALIGHT_MAX_CNTR_VAL (0x00FFFFFF) +#define MF_ULTRALIGHT_MAX_PAGE_NUM (510) +#define MF_ULTRALIGHT_PAGE_SIZE (4U) +#define MF_ULTRALIGHT_SIGNATURE_SIZE (32) +#define MF_ULTRALIGHT_COUNTER_SIZE (3) +#define MF_ULTRALIGHT_COUNTER_NUM (3) +#define MF_ULTRALIGHT_TEARING_FLAG_SIZE (1) +#define MF_ULTRALIGHT_TEARING_FLAG_NUM (3) #define MF_ULTRALIGHT_AUTH_PASSWORD_SIZE (4) -#define MF_ULTRALIGHT_AUTH_PACK_SIZE (2) -#define MF_ULTRALIGHT_AUTH_RESPONSE_SIZE (9) +#define MF_ULTRALIGHT_AUTH_PACK_SIZE (2) + +#define MF_ULTRALIGHT_C_AUTH_RESPONSE_SIZE (9) +#define MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE (16) +#define MF_ULTRALIGHT_C_AUTH_DATA_SIZE (MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE) +#define MF_ULTRALIGHT_C_AUTH_IV_BLOCK_SIZE (8) +#define MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE (8) +#define MF_ULTRALIGHT_C_AUTH_RND_A_BLOCK_OFFSET (0) +#define MF_ULTRALIGHT_C_AUTH_RND_B_BLOCK_OFFSET (8) +#define MF_ULTRALIGHT_C_ENCRYPTED_PACK_SIZE (MF_ULTRALIGHT_C_AUTH_DATA_SIZE + 1) typedef enum { MfUltralightErrorNone, @@ -119,6 +128,10 @@ typedef struct { uint8_t data[MF_ULTRALIGHT_AUTH_PASSWORD_SIZE]; } MfUltralightAuthPassword; +typedef struct { + uint8_t data[MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE]; +} MfUltralightC3DesAuthKey; + typedef struct { uint8_t data[MF_ULTRALIGHT_AUTH_PACK_SIZE]; } MfUltralightAuthPack; @@ -134,10 +147,10 @@ typedef struct FURI_PACKED { union { uint8_t value; struct { - uint8_t rfui1 : 2; - bool strg_mod_en : 1; - bool rfui2 : 1; - uint8_t mirror_byte : 2; + uint8_t rfui1 : 2; + bool strg_mod_en : 1; + bool rfui2 : 1; + uint8_t mirror_byte : 2; MfUltralightMirrorConf mirror_conf : 2; }; } mirror; @@ -147,12 +160,12 @@ typedef struct FURI_PACKED { union { uint8_t value; struct { - uint8_t authlim : 3; + uint8_t authlim : 3; bool nfc_cnt_pwd_prot : 1; - bool nfc_cnt_en : 1; - bool nfc_dis_sec1 : 1; // NTAG I2C Plus only - bool cfglck : 1; - bool prot : 1; + bool nfc_cnt_en : 1; + bool nfc_dis_sec1 : 1; // NTAG I2C Plus only + bool cfglck : 1; + bool prot : 1; }; } access; uint8_t vctid; @@ -226,6 +239,28 @@ bool mf_ultralight_detect_protocol(const Iso14443_3aData* iso14443_3a_data); bool mf_ultralight_is_counter_configured(const MfUltralightData* data); +void mf_ultralight_3des_shift_data(uint8_t* const arr); + +bool mf_ultralight_3des_key_valid(const MfUltralightData* data); + +const uint8_t* mf_ultralight_3des_get_key(const MfUltralightData* data); + +void mf_ultralight_3des_encrypt( + mbedtls_des3_context* ctx, + const uint8_t* ck, + const uint8_t* iv, + const uint8_t* input, + const uint8_t length, + uint8_t* out); + +void mf_ultralight_3des_decrypt( + mbedtls_des3_context* ctx, + const uint8_t* ck, + const uint8_t* iv, + const uint8_t* input, + const uint8_t length, + uint8_t* out); + #ifdef __cplusplus } #endif diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener.c index 5bef2a354c9..050f9abc1a6 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener.c @@ -4,16 +4,12 @@ #include #include +#include #define TAG "MfUltralightListener" #define MF_ULTRALIGHT_LISTENER_MAX_TX_BUFF_SIZE (256) -typedef enum { - MfUltralightListenerAccessTypeRead, - MfUltralightListenerAccessTypeWrite, -} MfUltralightListenerAccessType; - typedef struct { uint8_t cmd; size_t cmd_len_bits; @@ -24,31 +20,15 @@ static bool mf_ultralight_listener_check_access( MfUltralightListener* instance, uint16_t start_page, MfUltralightListenerAccessType access_type) { - bool access_success = false; - bool is_write_op = (access_type == MfUltralightListenerAccessTypeWrite); - - do { - if(!mf_ultralight_support_feature( - instance->features, MfUltralightFeatureSupportPasswordAuth)) { - access_success = true; - break; - } - if(instance->auth_state != MfUltralightListenerAuthStateSuccess) { - if((instance->config->auth0 <= start_page) && - (instance->config->access.prot || is_write_op)) { - break; - } - } - if(instance->config->access.cfglck && is_write_op) { - uint16_t config_page_start = instance->data->pages_total - 4; - if((start_page == config_page_start) || (start_page == config_page_start + 1)) { - break; - } - } - - access_success = true; - } while(false); - + bool access_success = true; + + if(mf_ultralight_support_feature(instance->features, MfUltralightFeatureSupportAuthenticate)) { + access_success = mf_ultralight_c_check_access( + instance->data, start_page, access_type, instance->auth_state); + } else if(mf_ultralight_support_feature( + instance->features, MfUltralightFeatureSupportPasswordAuth)) { + access_success = mf_ultralight_common_check_access(instance, start_page, access_type); + } return access_success; } @@ -58,7 +38,7 @@ static void mf_ultralight_listener_send_short_resp(MfUltralightListener* instanc bit_buffer_set_size(instance->tx_buffer, 4); bit_buffer_set_byte(instance->tx_buffer, 0, data); iso14443_3a_listener_tx(instance->iso14443_3a_listener, instance->tx_buffer); -}; +} static void mf_ultralight_listener_perform_read( MfUltralightPage* pages, @@ -565,6 +545,82 @@ static MfUltralightCommand return command; } +static MfUltralightCommand + mf_ultralight_c_authenticate_handler_p2(MfUltralightListener* instance, BitBuffer* buffer) { + MfUltralightCommand command = MfUltralightCommandNotProcessedNAK; + FURI_LOG_T(TAG, "CMD_ULC_AUTH_2"); + UNUSED(instance); + do { + if(bit_buffer_get_byte(buffer, 0) != 0xAF || + bit_buffer_get_size_bytes(buffer) != MF_ULTRALIGHT_C_ENCRYPTED_PACK_SIZE || + !mf_ultralight_3des_key_valid(instance->data)) + break; + + const uint8_t* data = bit_buffer_get_data(buffer) + 1; + const uint8_t* iv = data + MF_ULTRALIGHT_C_AUTH_RND_B_BLOCK_OFFSET; + + uint8_t out[MF_ULTRALIGHT_C_AUTH_DATA_SIZE] = {0}; + + const uint8_t* ck = mf_ultralight_3des_get_key(instance->data); + mf_ultralight_3des_decrypt( + &instance->des_context, ck, instance->encB, data, sizeof(out), out); + + uint8_t* rndA = out; + const uint8_t* decoded_shifted_rndB = out + MF_ULTRALIGHT_C_AUTH_RND_B_BLOCK_OFFSET; + + mf_ultralight_3des_shift_data(rndA); + mf_ultralight_3des_shift_data(instance->rndB); + if(memcmp(decoded_shifted_rndB, instance->rndB, sizeof(instance->rndB)) == 0) { + instance->auth_state = MfUltralightListenerAuthStateSuccess; + } + + mf_ultralight_3des_encrypt( + &instance->des_context, ck, iv, rndA, MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE, rndA); + + bit_buffer_reset(instance->tx_buffer); + bit_buffer_append_byte(instance->tx_buffer, 0x00); + bit_buffer_append_bytes(instance->tx_buffer, rndA, MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE); + + iso14443_3a_listener_send_standard_frame( + instance->iso14443_3a_listener, instance->tx_buffer); + + command = MfUltralightCommandProcessed; + } while(false); + return command; +} + +static MfUltralightCommand + mf_ultralight_c_authenticate_handler_p1(MfUltralightListener* instance, BitBuffer* buffer) { + MfUltralightCommand command = MfUltralightCommandNotProcessedNAK; + FURI_LOG_T(TAG, "CMD_ULC_AUTH_1"); + do { + if(!mf_ultralight_support_feature( + instance->features, MfUltralightFeatureSupportAuthenticate) && + bit_buffer_get_byte(buffer, 1) == 0x00) + break; + + bit_buffer_reset(instance->tx_buffer); + bit_buffer_append_byte(instance->tx_buffer, 0xAF); + + furi_hal_random_fill_buf(instance->rndB, sizeof(instance->rndB)); + + const uint8_t iv[MF_ULTRALIGHT_C_AUTH_IV_BLOCK_SIZE] = {0}; + const uint8_t* ck = mf_ultralight_3des_get_key(instance->data); + + mf_ultralight_3des_encrypt( + &instance->des_context, ck, iv, instance->rndB, sizeof(instance->rndB), instance->encB); + + bit_buffer_append_bytes(instance->tx_buffer, instance->encB, sizeof(instance->encB)); + + iso14443_3a_listener_send_standard_frame( + instance->iso14443_3a_listener, instance->tx_buffer); + command = MfUltralightCommandProcessed; + mf_ultralight_composite_command_set_next( + instance, mf_ultralight_c_authenticate_handler_p2); + } while(false); + return command; +} + static const MfUltralightListenerCmdHandler mf_ultralight_command[] = { { .cmd = MF_ULTRALIGHT_CMD_READ_PAGE, @@ -631,7 +687,11 @@ static const MfUltralightListenerCmdHandler mf_ultralight_command[] = { .cmd_len_bits = 21 * 8, .callback = mf_ultralight_listener_vcsl_handler, }, -}; + { + .cmd = MF_ULTRALIGHT_CMD_AUTH, + .cmd_len_bits = 2 * 8, + .callback = mf_ultralight_c_authenticate_handler_p1, + }}; static void mf_ultralight_listener_prepare_emulation(MfUltralightListener* instance) { MfUltralightData* data = instance->data; @@ -695,6 +755,7 @@ MfUltralightListener* mf_ultralight_listener_alloc( instance->generic_event.protocol = NfcProtocolMfUltralight; instance->generic_event.instance = instance; instance->generic_event.event_data = &instance->mfu_event; + mbedtls_des3_init(&instance->des_context); return instance; } @@ -706,6 +767,7 @@ void mf_ultralight_listener_free(MfUltralightListener* instance) { bit_buffer_free(instance->tx_buffer); furi_string_free(instance->mirror.ascii_mirror_data); + mbedtls_des3_free(&instance->des_context); free(instance); } diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c index 64647492de1..f38badae64f 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.c @@ -2,13 +2,13 @@ #include -#define MF_ULTRALIGHT_STATIC_BIT_LOCK_OTP_CC 0 -#define MF_ULTRALIGHT_STATIC_BIT_LOCK_BL_9_4 1 +#define MF_ULTRALIGHT_STATIC_BIT_LOCK_OTP_CC 0 +#define MF_ULTRALIGHT_STATIC_BIT_LOCK_BL_9_4 1 #define MF_ULTRALIGHT_STATIC_BIT_LOCK_BL_15_10 2 #define MF_ULTRALIGHT_BIT_ACTIVE(lock_bits, bit) (((lock_bits) & (1U << (bit))) != 0) -#define MF_ULTRALIGHT_BITS_SET(lock_bits, mask) ((lock_bits) |= (mask)) -#define MF_ULTRALIGHT_BITS_CLR(lock_bits, mask) ((lock_bits) &= ~(mask)) +#define MF_ULTRALIGHT_BITS_SET(lock_bits, mask) ((lock_bits) |= (mask)) +#define MF_ULTRALIGHT_BITS_CLR(lock_bits, mask) ((lock_bits) &= ~(mask)) #define MF_ULTRALIGHT_PAGE_LOCKED(lock_bits, page) MF_ULTRALIGHT_BIT_ACTIVE(lock_bits, page) @@ -35,7 +35,7 @@ #define MF_ULTRALIGHT_I2C_PAGE_ON_MIRRORED_SESSION_REG(page) \ MF_ULTRALIGHT_PAGE_IN_BOUNDS(page, 0x00F8, 0x00F9) -#define MF_ULTRALIGHT_AUTH_RESET_ATTEMPTS(instance) (instance->data->auth_attempts = 0) +#define MF_ULTRALIGHT_AUTH_RESET_ATTEMPTS(instance) (instance->data->auth_attempts = 0) #define MF_ULTRALIGHT_AUTH_INCREASE_ATTEMPTS(instance) (instance->data->auth_attempts++) static MfUltralightMirrorConf mf_ultralight_mirror_check_mode( @@ -125,7 +125,7 @@ static uint8_t mf_ultralight_get_mirror_data_size(MfUltralightMirrorConf mode) { static uint8_t mf_ultralight_get_mirror_last_page(MfUltralightListener* instance) { uint8_t strSize = mf_ultralight_get_mirror_data_size(instance->mirror.actual_mode); - return (instance->config->mirror_page + 1U + strSize / 4); + return instance->config->mirror_page + 1U + strSize / 4; } static uint8_t mf_ultralight_get_ascii_offset(uint8_t start_page, MfUltralightListener* instance) { @@ -155,7 +155,8 @@ static void mf_ultralight_format_mirror_data( FuriString* str, const uint8_t* const data, const uint8_t data_len) { - for(uint8_t i = 0; i < data_len; i++) furi_string_cat_printf(str, "%02X", data[i]); + for(uint8_t i = 0; i < data_len; i++) + furi_string_cat_printf(str, "%02X", data[i]); } void mf_ultralight_mirror_read_prepare(uint8_t start_page, MfUltralightListener* instance) { @@ -206,7 +207,7 @@ void mf_ultraligt_mirror_format_counter(MfUltralightListener* instance) { } bool mf_ultralight_composite_command_in_progress(MfUltralightListener* instance) { - return (instance->composite_cmd.callback != NULL); + return instance->composite_cmd.callback != NULL; } MfUltralightCommand @@ -549,7 +550,7 @@ static bool mf_ultralight_auth_check_attempts(const MfUltralightListener* instan (1U << instance->config->access.authlim) : instance->config->access.authlim; - return (instance->data->auth_attempts >= authlim); + return instance->data->auth_attempts >= authlim; } bool mf_ultralight_auth_limit_check_and_update(MfUltralightListener* instance, bool auth_success) { @@ -576,4 +577,61 @@ bool mf_ultralight_auth_check_password( const MfUltralightAuthPassword* config_pass, const MfUltralightAuthPassword* auth_pass) { return memcmp(config_pass->data, auth_pass->data, sizeof(MfUltralightAuthPassword)) == 0; -} \ No newline at end of file +} + +bool mf_ultralight_common_check_access( + const MfUltralightListener* instance, + const uint16_t start_page, + const MfUltralightListenerAccessType access_type) { + bool access_success = false; + bool is_write_op = (access_type == MfUltralightListenerAccessTypeWrite); + + do { + if(instance->auth_state != MfUltralightListenerAuthStateSuccess) { + if((instance->config->auth0 <= start_page) && + (instance->config->access.prot || is_write_op)) { + break; + } + } + + if(instance->config->access.cfglck && is_write_op) { + uint16_t config_page_start = instance->data->pages_total - 4; + if((start_page == config_page_start) || (start_page == config_page_start + 1)) { + break; + } + } + + access_success = true; + } while(false); + + return access_success; +} + +bool mf_ultralight_c_check_access( + const MfUltralightData* data, + const uint16_t start_page, + const MfUltralightListenerAccessType access_type, + const MfUltralightListenerAuthState auth_state) { + bool access_success = false; + bool is_write_op = (access_type == MfUltralightListenerAccessTypeWrite); + + do { + if(start_page >= 44) break; + + const uint8_t auth0 = data->page[42].data[0]; + const uint8_t auth1 = data->page[43].data[0] & 0x01; + + if(auth0 < 0x03 || auth0 >= 0x30 || auth_state == MfUltralightListenerAuthStateSuccess) { + access_success = true; + break; + } + + if((auth0 <= start_page) && ((auth1 == 0) || (auth1 == 1 || is_write_op))) { //-V560 + break; + } + + access_success = true; + } while(false); + + return access_success; +} diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.h b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.h index ba448d0879c..c43658eddbb 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.h +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_listener_i.h @@ -13,6 +13,11 @@ typedef enum { MfUltralightListenerAuthStateSuccess, } MfUltralightListenerAuthState; +typedef enum { + MfUltralightListenerAccessTypeRead, + MfUltralightListenerAccessTypeWrite, +} MfUltralightListenerAccessType; + typedef enum { MfUltralightCommandNotFound, MfUltralightCommandProcessed, @@ -63,6 +68,9 @@ struct MfUltralightListener { bool single_counter_increased; MfUltralightMirrorMode mirror; MfUltralightListenerCompositeCommandContext composite_cmd; + mbedtls_des3_context des_context; + uint8_t rndB[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE]; + uint8_t encB[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE]; void* context; }; @@ -118,6 +126,17 @@ bool mf_ultralight_auth_limit_check_and_update(MfUltralightListener* instance, b bool mf_ultralight_auth_check_password( const MfUltralightAuthPassword* config_pass, const MfUltralightAuthPassword* auth_pass); + +bool mf_ultralight_common_check_access( + const MfUltralightListener* instance, + const uint16_t start_page, + const MfUltralightListenerAccessType access_type); + +bool mf_ultralight_c_check_access( + const MfUltralightData* data, + const uint16_t start_page, + const MfUltralightListenerAccessType access_type, + const MfUltralightListenerAuthState auth_state); #ifdef __cplusplus } #endif diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c index 52b445859e7..0e5ff001162 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c @@ -3,6 +3,7 @@ #include #include +#include #define TAG "MfUltralightPoller" @@ -180,7 +181,7 @@ MfUltralightPoller* mf_ultralight_poller_alloc(Iso14443_3aPoller* iso14443_3a_po instance->general_event.protocol = NfcProtocolMfUltralight; instance->general_event.event_data = &instance->mfu_event; instance->general_event.instance = instance; - + mbedtls_des3_init(&instance->des_context); return instance; } @@ -193,6 +194,7 @@ void mf_ultralight_poller_free(MfUltralightPoller* instance) { bit_buffer_free(instance->tx_buffer); bit_buffer_free(instance->rx_buffer); mf_ultralight_free(instance->data); + mbedtls_des3_free(&instance->des_context); free(instance); } @@ -258,7 +260,7 @@ static NfcCommand mf_ultralight_poller_handler_read_version(MfUltralightPoller* } static NfcCommand mf_ultralight_poller_handler_check_ultralight_c(MfUltralightPoller* instance) { - instance->error = mf_ultralight_poller_authenticate(instance); + instance->error = mf_ultralight_poller_authentication_test(instance); if(instance->error == MfUltralightErrorNone) { FURI_LOG_D(TAG, "Ultralight C detected"); instance->data->type = MfUltralightTypeMfulC; @@ -315,6 +317,10 @@ static NfcCommand mf_ultralight_poller_handler_read_signature(MfUltralightPoller } } else { FURI_LOG_D(TAG, "Skip reading signature"); + if(mf_ultralight_support_feature( + instance->feature_set, MfUltralightFeatureSupportAuthenticate)) { + next_state = MfUltralightPollerStateAuthMfulC; + } } instance->state = next_state; @@ -436,6 +442,50 @@ static NfcCommand mf_ultralight_poller_handler_auth(MfUltralightPoller* instance return command; } +static NfcCommand mf_ultralight_poller_handler_auth_ultralight_c(MfUltralightPoller* instance) { + NfcCommand command = NfcCommandContinue; + FURI_LOG_D(TAG, "MfulC auth"); + if(mf_ultralight_support_feature( + instance->feature_set, MfUltralightFeatureSupportAuthenticate)) { + instance->mfu_event.type = MfUltralightPollerEventTypeAuthRequest; + + command = instance->callback(instance->general_event, instance->context); + if(!instance->mfu_event.data->auth_context.skip_auth) { + FURI_LOG_D(TAG, "Trying to authenticate with 3des key"); + instance->auth_context.tdes_key = instance->mfu_event.data->auth_context.tdes_key; + do { + uint8_t output[MF_ULTRALIGHT_C_AUTH_DATA_SIZE]; + uint8_t RndA[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE] = {0}; + furi_hal_random_fill_buf(RndA, sizeof(RndA)); + instance->error = mf_ultralight_poller_authenticate_start(instance, RndA, output); + if(instance->error != MfUltralightErrorNone) break; + + uint8_t decoded_shifted_RndA[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE] = {0}; + const uint8_t* RndB = output + MF_ULTRALIGHT_C_AUTH_RND_B_BLOCK_OFFSET; + instance->error = mf_ultralight_poller_authenticate_end( + instance, RndB, output, decoded_shifted_RndA); + if(instance->error != MfUltralightErrorNone) break; + + mf_ultralight_3des_shift_data(RndA); + instance->auth_context.auth_success = + (memcmp(RndA, decoded_shifted_RndA, sizeof(decoded_shifted_RndA)) == 0); + + if(instance->auth_context.auth_success) { + FURI_LOG_D(TAG, "Auth success"); + } + } while(false); + + if(instance->error != MfUltralightErrorNone || !instance->auth_context.auth_success) { + FURI_LOG_D(TAG, "Auth failed"); + iso14443_3a_poller_halt(instance->iso14443_3a_poller); + } + } + } + instance->state = MfUltralightPollerStateReadPages; + + return command; +} + static NfcCommand mf_ultralight_poller_handler_read_pages(MfUltralightPoller* instance) { MfUltralightPageReadCommandData data = {}; uint16_t start_page = instance->pages_read; @@ -455,8 +505,9 @@ static NfcCommand mf_ultralight_poller_handler_read_pages(MfUltralightPoller* in instance->error = mf_ultralight_poller_read_page(instance, start_page, &data); } + const uint8_t read_cnt = instance->data->type == MfUltralightTypeMfulC ? 1 : 4; if(instance->error == MfUltralightErrorNone) { - for(size_t i = 0; i < 4; i++) { + for(size_t i = 0; i < read_cnt; i++) { if(start_page + i < instance->pages_total) { FURI_LOG_D(TAG, "Read page %d success", start_page + i); instance->data->page[start_page + i] = data.page[i]; @@ -468,11 +519,16 @@ static NfcCommand mf_ultralight_poller_handler_read_pages(MfUltralightPoller* in instance->state = MfUltralightPollerStateReadCounters; } } else { - FURI_LOG_D(TAG, "Read page %d failed", instance->pages_read); - if(instance->pages_read) { - instance->state = MfUltralightPollerStateReadCounters; + if(instance->data->type == MfUltralightTypeMfulC && + !mf_ultralight_3des_key_valid(instance->data)) { + instance->state = MfUltralightPollerStateCheckMfulCAuthStatus; } else { - instance->state = MfUltralightPollerStateReadFailed; + FURI_LOG_D(TAG, "Read page %d failed", instance->pages_read); + if(instance->pages_read) { + instance->state = MfUltralightPollerStateReadCounters; + } else { + instance->state = MfUltralightPollerStateReadFailed; + } } } @@ -524,6 +580,31 @@ static NfcCommand mf_ultralight_poller_handler_try_default_pass(MfUltralightPoll return NfcCommandContinue; } +static NfcCommand + mf_ultralight_poller_handler_check_mfuc_auth_status(MfUltralightPoller* instance) { + instance->state = MfUltralightPollerStateReadSuccess; + + do { + if(!mf_ultralight_support_feature( + instance->feature_set, MfUltralightFeatureSupportAuthenticate)) + break; + + if(!instance->auth_context.auth_success) { + FURI_LOG_D(TAG, "Skip 3des key populating"); + break; + } + + memcpy( + &instance->data->page[44], + instance->auth_context.tdes_key.data, + MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE); + instance->data->pages_read = instance->pages_total; + instance->pages_read = instance->pages_total; + } while(false); + + return NfcCommandContinue; +} + static NfcCommand mf_ultralight_poller_handler_read_fail(MfUltralightPoller* instance) { FURI_LOG_D(TAG, "Read Failed"); iso14443_3a_poller_halt(instance->iso14443_3a_poller); @@ -663,6 +744,9 @@ static const MfUltralightPollerReadHandler mf_ultralight_poller_handler_read_tearing_flags, [MfUltralightPollerStateAuth] = mf_ultralight_poller_handler_auth, [MfUltralightPollerStateTryDefaultPass] = mf_ultralight_poller_handler_try_default_pass, + [MfUltralightPollerStateCheckMfulCAuthStatus] = + mf_ultralight_poller_handler_check_mfuc_auth_status, + [MfUltralightPollerStateAuthMfulC] = mf_ultralight_poller_handler_auth_ultralight_c, [MfUltralightPollerStateReadPages] = mf_ultralight_poller_handler_read_pages, [MfUltralightPollerStateReadFailed] = mf_ultralight_poller_handler_read_fail, [MfUltralightPollerStateReadSuccess] = mf_ultralight_poller_handler_read_success, diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.h b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.h index 2343be089bf..e5001732446 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.h +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.h @@ -42,6 +42,7 @@ typedef enum { */ typedef struct { MfUltralightAuthPassword password; /**< Password to be used for authentication. */ + MfUltralightC3DesAuthKey tdes_key; MfUltralightAuthPack pack; /**< Pack received on successfull authentication. */ bool auth_success; /**< Set to true if authentication succeeded, false otherwise. */ bool skip_auth; /**< Set to true if authentication should be skipped, false otherwise. */ @@ -85,12 +86,33 @@ MfUltralightError mf_ultralight_poller_auth_pwd( * * Must ONLY be used inside the callback function. * - * This function now is used only to identify Mf Ultralight C cards. + * This function is used to start authentication process for Ultralight C cards. * * @param[in, out] instance pointer to the instance to be used in the transaction. + * @param[in] RndA Randomly generated block which is required for authentication process. + * @param[out] output Authentication encryption result. * @return MfUltralightErrorNone if card supports authentication command, an error code on otherwise. */ -MfUltralightError mf_ultralight_poller_authenticate(MfUltralightPoller* instance); +MfUltralightError mf_ultralight_poller_authenticate_start( + MfUltralightPoller* instance, + const uint8_t* RndA, + uint8_t* output); + +/** + * @brief End authentication procedure + * + * This function is used to end authentication process for Ultralight C cards. + * + * @param[in, out] instance pointer to the instance to be used in the transaction. + * @param[in] RndB Block received from the card (card generates it randomly) which is required for authentication process. + * @param[in] request Contains data of RndA + RndB', where RndB' is decoded and shifted RndB received from the card on previous step. + * @param[out] response Must return RndA' which an encrypted shifted RndA value received from the card and decrypted by this function. +*/ +MfUltralightError mf_ultralight_poller_authenticate_end( + MfUltralightPoller* instance, + const uint8_t* RndB, + const uint8_t* request, + uint8_t* response); /** * @brief Read page from card. diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.c index cc3433f7318..141ab6c46d0 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.c @@ -62,11 +62,17 @@ MfUltralightError mf_ultralight_poller_auth_pwd( return ret; } -MfUltralightError mf_ultralight_poller_authenticate(MfUltralightPoller* instance) { +static MfUltralightError mf_ultralight_poller_send_authenticate_cmd( + MfUltralightPoller* instance, + const uint8_t* cmd, + const uint8_t length, + const bool initial_cmd, + uint8_t* response) { furi_check(instance); + furi_check(cmd); + furi_check(response); - uint8_t auth_cmd[2] = {MF_ULTRALIGHT_CMD_AUTH, 0x00}; - bit_buffer_copy_bytes(instance->tx_buffer, auth_cmd, sizeof(auth_cmd)); + bit_buffer_copy_bytes(instance->tx_buffer, cmd, length); MfUltralightError ret = MfUltralightErrorNone; Iso14443_3aError error = Iso14443_3aErrorNone; @@ -80,12 +86,104 @@ MfUltralightError mf_ultralight_poller_authenticate(MfUltralightPoller* instance ret = mf_ultralight_process_error(error); break; } - if((bit_buffer_get_size_bytes(instance->rx_buffer) != MF_ULTRALIGHT_AUTH_RESPONSE_SIZE) && - (bit_buffer_get_byte(instance->rx_buffer, 0) != 0xAF)) { + + const uint8_t expected_response_code = initial_cmd ? 0xAF : 0x00; + if((bit_buffer_get_byte(instance->rx_buffer, 0) != expected_response_code) || + (bit_buffer_get_size_bytes(instance->rx_buffer) != + MF_ULTRALIGHT_C_AUTH_RESPONSE_SIZE)) { ret = MfUltralightErrorAuth; break; } - //Save encrypted PICC random number RndB here if needed + + memcpy( + response, + bit_buffer_get_data(instance->rx_buffer) + 1, + MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE); + } while(false); + + return ret; +} + +MfUltralightError mf_ultralight_poller_authentication_test(MfUltralightPoller* instance) { + furi_check(instance); + + uint8_t auth_cmd[2] = {MF_ULTRALIGHT_CMD_AUTH, 0x00}; + uint8_t dummy[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE]; + return mf_ultralight_poller_send_authenticate_cmd( + instance, auth_cmd, sizeof(auth_cmd), true, dummy); +} + +MfUltralightError mf_ultralight_poller_authenticate_start( + MfUltralightPoller* instance, + const uint8_t* RndA, + uint8_t* output) { + furi_check(instance); + furi_check(RndA); + furi_check(output); + + MfUltralightError ret = MfUltralightErrorNone; + do { + uint8_t encRndB[MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE] = {0}; + uint8_t auth_cmd[2] = {MF_ULTRALIGHT_CMD_AUTH, 0x00}; + ret = mf_ultralight_poller_send_authenticate_cmd( + instance, auth_cmd, sizeof(auth_cmd), true, encRndB /* instance->encRndB */); + + if(ret != MfUltralightErrorNone) break; + + uint8_t iv[MF_ULTRALIGHT_C_AUTH_IV_BLOCK_SIZE] = {0}; + uint8_t* RndB = output + MF_ULTRALIGHT_C_AUTH_RND_B_BLOCK_OFFSET; + mf_ultralight_3des_decrypt( + &instance->des_context, + instance->mfu_event.data->auth_context.tdes_key.data, + iv, + encRndB, + sizeof(encRndB), + RndB); + mf_ultralight_3des_shift_data(RndB); + + memcpy(output, RndA, MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE); + + mf_ultralight_3des_encrypt( + &instance->des_context, + instance->mfu_event.data->auth_context.tdes_key.data, + encRndB, + output, + MF_ULTRALIGHT_C_AUTH_DATA_SIZE, + output); + + } while(false); + + return ret; +} + +MfUltralightError mf_ultralight_poller_authenticate_end( + MfUltralightPoller* instance, + const uint8_t* RndB, + const uint8_t* request, + uint8_t* response) { + furi_check(instance); + furi_check(RndB); + furi_check(request); + furi_check(response); + + uint8_t auth_cmd[MF_ULTRALIGHT_C_ENCRYPTED_PACK_SIZE] = {0xAF}; //-V1009 + memcpy(&auth_cmd[1], request, MF_ULTRALIGHT_C_AUTH_DATA_SIZE); + bit_buffer_copy_bytes(instance->tx_buffer, auth_cmd, sizeof(auth_cmd)); + + MfUltralightError ret = MfUltralightErrorNone; + do { + ret = mf_ultralight_poller_send_authenticate_cmd( + instance, auth_cmd, sizeof(auth_cmd), false, response); + + if(ret != MfUltralightErrorNone) break; + + mf_ultralight_3des_decrypt( + &instance->des_context, + instance->mfu_event.data->auth_context.tdes_key.data, + RndB, + bit_buffer_get_data(instance->rx_buffer) + 1, + MF_ULTRALIGHT_C_AUTH_RND_BLOCK_SIZE, + response); } while(false); return ret; diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.h b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.h index 3f8645fe73a..b35c49aeafb 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.h +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_i.h @@ -9,7 +9,7 @@ extern "C" { #endif #define MF_ULTRALIGHT_POLLER_STANDARD_FWT_FC (60000) -#define MF_ULTRALIGHT_MAX_BUFF_SIZE (64) +#define MF_ULTRALIGHT_MAX_BUFF_SIZE (64) #define MF_ULTRALIGHT_DEFAULT_PASSWORD (0xffffffffUL) @@ -58,8 +58,10 @@ typedef enum { MfUltralightPollerStateReadCounters, MfUltralightPollerStateReadTearingFlags, MfUltralightPollerStateAuth, + MfUltralightPollerStateAuthMfulC, MfUltralightPollerStateReadPages, MfUltralightPollerStateTryDefaultPass, + MfUltralightPollerStateCheckMfulCAuthStatus, MfUltralightPollerStateReadFailed, MfUltralightPollerStateReadSuccess, MfUltralightPollerStateRequestWriteData, @@ -87,6 +89,7 @@ struct MfUltralightPoller { uint8_t tearing_flag_total; uint16_t current_page; MfUltralightError error; + mbedtls_des3_context des_context; NfcGenericEvent general_event; MfUltralightPollerEvent mfu_event; @@ -110,6 +113,8 @@ bool mf_ultralight_poller_ntag_i2c_addr_lin_to_tag( uint8_t* tag, uint8_t* pages_left); +MfUltralightError mf_ultralight_poller_authentication_test(MfUltralightPoller* instance); + #ifdef __cplusplus } #endif diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_sync.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_sync.c index 157e2bdef7b..9958dc50de5 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_sync.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller_sync.c @@ -251,6 +251,12 @@ static NfcCommand mf_ultralight_poller_read_callback(NfcGenericEvent event, void command = NfcCommandStop; } else if(mfu_event->type == MfUltralightPollerEventTypeAuthRequest) { mfu_event->data->auth_context.skip_auth = true; + if(mf_ultralight_support_feature( + mfu_poller->feature_set, MfUltralightFeatureSupportAuthenticate)) { + mfu_event->data->auth_context.skip_auth = false; + memset( + mfu_poller->auth_context.tdes_key.data, 0x00, MF_ULTRALIGHT_C_AUTH_DES_KEY_SIZE); + } } if(command == NfcCommandStop) { diff --git a/lib/nfc/protocols/slix/slix.c b/lib/nfc/protocols/slix/slix.c index f6ce885d4bc..7a60682304e 100644 --- a/lib/nfc/protocols/slix/slix.c +++ b/lib/nfc/protocols/slix/slix.c @@ -5,36 +5,36 @@ #include #define SLIX_PROTOCOL_NAME "SLIX" -#define SLIX_DEVICE_NAME "SLIX" +#define SLIX_DEVICE_NAME "SLIX" #define SLIX_TYPE_SLIX_SLIX2 (0x01U) -#define SLIX_TYPE_SLIX_S (0x02U) -#define SLIX_TYPE_SLIX_L (0x03U) +#define SLIX_TYPE_SLIX_S (0x02U) +#define SLIX_TYPE_SLIX_L (0x03U) -#define SLIX_TYPE_INDICATOR_SLIX (0x02U) +#define SLIX_TYPE_INDICATOR_SLIX (0x02U) #define SLIX_TYPE_INDICATOR_SLIX2 (0x01U) -#define SLIX_CAPABILITIES_KEY "Capabilities" -#define SLIX_PASSWORD_READ_KEY "Password Read" -#define SLIX_PASSWORD_WRITE_KEY "Password Write" -#define SLIX_PASSWORD_PRIVACY_KEY "Password Privacy" -#define SLIX_PASSWORD_DESTROY_KEY "Password Destroy" -#define SLIX_PASSWORD_EAS_KEY "Password EAS" -#define SLIX_SIGNATURE_KEY "Signature" -#define SLIX_PRIVACY_MODE_KEY "Privacy Mode" -#define SLIX_PROTECTION_POINTER_KEY "Protection Pointer" +#define SLIX_CAPABILITIES_KEY "Capabilities" +#define SLIX_PASSWORD_READ_KEY "Password Read" +#define SLIX_PASSWORD_WRITE_KEY "Password Write" +#define SLIX_PASSWORD_PRIVACY_KEY "Password Privacy" +#define SLIX_PASSWORD_DESTROY_KEY "Password Destroy" +#define SLIX_PASSWORD_EAS_KEY "Password EAS" +#define SLIX_SIGNATURE_KEY "Signature" +#define SLIX_PRIVACY_MODE_KEY "Privacy Mode" +#define SLIX_PROTECTION_POINTER_KEY "Protection Pointer" #define SLIX_PROTECTION_CONDITION_KEY "Protection Condition" -#define SLIX_LOCK_EAS_KEY "Lock EAS" -#define SLIX_LOCK_PPL_KEY "Lock PPL" +#define SLIX_LOCK_EAS_KEY "Lock EAS" +#define SLIX_LOCK_PPL_KEY "Lock PPL" typedef struct { uint8_t iso15693_3[2]; uint8_t icode_type; union { struct { - uint8_t unused_1 : 3; + uint8_t unused_1 : 3; uint8_t type_indicator : 2; - uint8_t unused_2 : 3; + uint8_t unused_2 : 3; }; uint8_t serial_num[5]; }; diff --git a/lib/nfc/protocols/slix/slix.h b/lib/nfc/protocols/slix/slix.h index cc2390c6eee..2a32224457d 100644 --- a/lib/nfc/protocols/slix/slix.h +++ b/lib/nfc/protocols/slix/slix.h @@ -6,7 +6,7 @@ extern "C" { #endif -#define SLIX_BLOCK_SIZE (4U) +#define SLIX_BLOCK_SIZE (4U) #define SLIX_SIGNATURE_SIZE (32U) #define SLIX_COUNTER_BLOCK_NUM (79U) @@ -16,27 +16,27 @@ extern "C" { #define SLIX_PP_CONDITION_RH (1U << 4) #define SLIX_PP_CONDITION_WH (1U << 5) -#define SLIX_FEATURE_FLAG_UM_PP (1UL << 0) -#define SLIX_FEATURE_FLAG_COUNTER (1UL << 1) -#define SLIX_FEATURE_FLAG_EAS_ID (1UL << 2) -#define SLIX_FEATURE_FLAG_EAS_PP (1UL << 3) -#define SLIX_FEATURE_FLAG_AFI_PP (1UL << 4) +#define SLIX_FEATURE_FLAG_UM_PP (1UL << 0) +#define SLIX_FEATURE_FLAG_COUNTER (1UL << 1) +#define SLIX_FEATURE_FLAG_EAS_ID (1UL << 2) +#define SLIX_FEATURE_FLAG_EAS_PP (1UL << 3) +#define SLIX_FEATURE_FLAG_AFI_PP (1UL << 4) #define SLIX_FEATURE_FLAG_INVENTORY_READ_EXT (1UL << 5) -#define SLIX_FEATURE_FLAG_EAS_IR (1UL << 6) -#define SLIX_FEATURE_FLAG_ORIGINALITY_SIG (1UL << 8) +#define SLIX_FEATURE_FLAG_EAS_IR (1UL << 6) +#define SLIX_FEATURE_FLAG_ORIGINALITY_SIG (1UL << 8) #define SLIX_FEATURE_FLAG_ORIGINALITY_SIG_PP (1UL << 9) -#define SLIX_FEATURE_FLAG_PERSISTENT_QUIET (1UL << 10) -#define SLIX_FEATURE_FLAG_PRIVACY (1UL << 12) -#define SLIX_FEATURE_FLAG_DESTROY (1UL << 13) -#define SLIX_FEATURE_EXT (1UL << 31) - -#define SLIX_TYPE_FEATURE_READ (1U << 0) -#define SLIX_TYPE_FEATURE_WRITE (1U << 1) -#define SLIX_TYPE_FEATURE_PRIVACY (1U << 2) -#define SLIX_TYPE_FEATURE_DESTROY (1U << 3) -#define SLIX_TYPE_FEATURE_EAS (1U << 4) -#define SLIX_TYPE_FEATURE_SIGNATURE (1U << 5) -#define SLIX_TYPE_FEATURE_PROTECTION (1U << 6) +#define SLIX_FEATURE_FLAG_PERSISTENT_QUIET (1UL << 10) +#define SLIX_FEATURE_FLAG_PRIVACY (1UL << 12) +#define SLIX_FEATURE_FLAG_DESTROY (1UL << 13) +#define SLIX_FEATURE_EXT (1UL << 31) + +#define SLIX_TYPE_FEATURE_READ (1U << 0) +#define SLIX_TYPE_FEATURE_WRITE (1U << 1) +#define SLIX_TYPE_FEATURE_PRIVACY (1U << 2) +#define SLIX_TYPE_FEATURE_DESTROY (1U << 3) +#define SLIX_TYPE_FEATURE_EAS (1U << 4) +#define SLIX_TYPE_FEATURE_SIGNATURE (1U << 5) +#define SLIX_TYPE_FEATURE_PROTECTION (1U << 6) #define SLIX_TYPE_FEATURE_NFC_SYSTEM_INFO (1U << 7) typedef uint32_t SlixTypeFeatures; diff --git a/lib/nfc/protocols/slix/slix_i.h b/lib/nfc/protocols/slix/slix_i.h index 4a15b50ff4e..c8830f31b37 100644 --- a/lib/nfc/protocols/slix/slix_i.h +++ b/lib/nfc/protocols/slix/slix_i.h @@ -11,33 +11,33 @@ extern "C" { #define SLIX_NXP_MANUFACTURER_CODE (0x04U) -#define SLIX_LOCK_BITS_AFI (1U << 0) -#define SLIX_LOCK_BITS_EAS (1U << 1) +#define SLIX_LOCK_BITS_AFI (1U << 0) +#define SLIX_LOCK_BITS_EAS (1U << 1) #define SLIX_LOCK_BITS_DSFID (1U << 2) -#define SLIX_LOCK_BITS_PPL (1U << 3) - -#define SLIX_CMD_CUSTOM_START (0xA2U) -#define SLIX_CMD_SET_EAS (0xA2U) -#define SLIX_CMD_RESET_EAS (0xA3U) -#define SLIX_CMD_LOCK_EAS (0xA4U) -#define SLIX_CMD_EAS_ALARM (0xA5U) -#define SLIX_CMD_PASSWORD_PROTECT_EAS_AFI (0xA6U) -#define SLIX_CMD_WRITE_EAS_ID (0xA7U) -#define SLIX_CMD_GET_NXP_SYSTEM_INFORMATION (0xABU) -#define SLIX_CMD_INVENTORY_PAGE_READ (0xB0U) -#define SLIX_CMD_INVENTORY_PAGE_READ_FAST (0xB1U) -#define SLIX_CMD_GET_RANDOM_NUMBER (0xB2U) -#define SLIX_CMD_SET_PASSWORD (0xB3U) -#define SLIX_CMD_WRITE_PASSWORD (0xB4U) -#define SLIX_CMD_64_BIT_PASSWORD_PROTECTION (0xB5U) -#define SLIX_CMD_PROTECT_PAGE (0xB6U) +#define SLIX_LOCK_BITS_PPL (1U << 3) + +#define SLIX_CMD_CUSTOM_START (0xA2U) +#define SLIX_CMD_SET_EAS (0xA2U) +#define SLIX_CMD_RESET_EAS (0xA3U) +#define SLIX_CMD_LOCK_EAS (0xA4U) +#define SLIX_CMD_EAS_ALARM (0xA5U) +#define SLIX_CMD_PASSWORD_PROTECT_EAS_AFI (0xA6U) +#define SLIX_CMD_WRITE_EAS_ID (0xA7U) +#define SLIX_CMD_GET_NXP_SYSTEM_INFORMATION (0xABU) +#define SLIX_CMD_INVENTORY_PAGE_READ (0xB0U) +#define SLIX_CMD_INVENTORY_PAGE_READ_FAST (0xB1U) +#define SLIX_CMD_GET_RANDOM_NUMBER (0xB2U) +#define SLIX_CMD_SET_PASSWORD (0xB3U) +#define SLIX_CMD_WRITE_PASSWORD (0xB4U) +#define SLIX_CMD_64_BIT_PASSWORD_PROTECTION (0xB5U) +#define SLIX_CMD_PROTECT_PAGE (0xB6U) #define SLIX_CMD_LOCK_PAGE_PROTECTION_CONDITION (0xB7U) -#define SLIX_CMD_DESTROY (0xB9U) -#define SLIX_CMD_ENABLE_PRIVACY (0xBAU) -#define SLIX_CMD_STAY_QUIET_PERSISTENT (0xBCU) -#define SLIX_CMD_READ_SIGNATURE (0xBDU) -#define SLIX_CMD_CUSTOM_END (0xBEU) -#define SLIX_CMD_CUSTOM_COUNT (SLIX_CMD_CUSTOM_END - SLIX_CMD_CUSTOM_START) +#define SLIX_CMD_DESTROY (0xB9U) +#define SLIX_CMD_ENABLE_PRIVACY (0xBAU) +#define SLIX_CMD_STAY_QUIET_PERSISTENT (0xBCU) +#define SLIX_CMD_READ_SIGNATURE (0xBDU) +#define SLIX_CMD_CUSTOM_END (0xBEU) +#define SLIX_CMD_CUSTOM_COUNT (SLIX_CMD_CUSTOM_END - SLIX_CMD_CUSTOM_START) #define SLIX_TYPE_FEATURES_SLIX (SLIX_TYPE_FEATURE_EAS) #define SLIX_TYPE_FEATURES_SLIX_S \ diff --git a/lib/nfc/protocols/st25tb/st25tb.c b/lib/nfc/protocols/st25tb/st25tb.c index 8b1e9be2e9e..e5a8c1cc0ef 100644 --- a/lib/nfc/protocols/st25tb/st25tb.c +++ b/lib/nfc/protocols/st25tb/st25tb.c @@ -6,9 +6,9 @@ #include #include -#define ST25TB_PROTOCOL_NAME "ST25TB" -#define ST25TB_TYPE_KEY "ST25TB Type" -#define ST25TB_BLOCK_KEY "Block %d" +#define ST25TB_PROTOCOL_NAME "ST25TB" +#define ST25TB_TYPE_KEY "ST25TB Type" +#define ST25TB_BLOCK_KEY "Block %d" #define ST25TB_SYSTEM_BLOCK_KEY "System OTP Block" typedef struct { diff --git a/lib/nfc/protocols/st25tb/st25tb.h b/lib/nfc/protocols/st25tb/st25tb.h index 67d733315fc..cda6c570f35 100644 --- a/lib/nfc/protocols/st25tb/st25tb.h +++ b/lib/nfc/protocols/st25tb/st25tb.h @@ -9,13 +9,13 @@ extern "C" { #define ST25TB_UID_SIZE (8U) //#define ST25TB_FDT_FC (4205U) -#define ST25TB_FDT_FC (8494U) -#define ST25TB_GUARD_TIME_US (5000U) +#define ST25TB_FDT_FC (8494U) +#define ST25TB_GUARD_TIME_US (5000U) #define ST25TB_POLL_POLL_MIN_US (1280U) -#define ST25TB_MAX_BLOCKS (128U) +#define ST25TB_MAX_BLOCKS (128U) #define ST25TB_SYSTEM_OTP_BLOCK (0xFFU) -#define ST25TB_BLOCK_SIZE (4U) +#define ST25TB_BLOCK_SIZE (4U) typedef enum { St25tbErrorNone, diff --git a/lib/nfc/protocols/st25tb/st25tb_poller_sync.c b/lib/nfc/protocols/st25tb/st25tb_poller_sync.c index 359435034ef..c8f82c8ff80 100644 --- a/lib/nfc/protocols/st25tb/st25tb_poller_sync.c +++ b/lib/nfc/protocols/st25tb/st25tb_poller_sync.c @@ -211,4 +211,4 @@ St25tbError st25tb_poller_sync_read(Nfc* nfc, St25tbData* data) { nfc_poller_free(poller); return poller_context.error; -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/st25tb/st25tb_poller_sync.h b/lib/nfc/protocols/st25tb/st25tb_poller_sync.h index ecd994b3981..78c5ab91ef0 100644 --- a/lib/nfc/protocols/st25tb/st25tb_poller_sync.h +++ b/lib/nfc/protocols/st25tb/st25tb_poller_sync.h @@ -17,4 +17,4 @@ St25tbError st25tb_poller_sync_read(Nfc* nfc, St25tbData* data); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/one_wire/one_wire_host.c b/lib/one_wire/one_wire_host.c index 9383e0f15da..f3f3d953ed9 100644 --- a/lib/one_wire/one_wire_host.c +++ b/lib/one_wire/one_wire_host.c @@ -224,7 +224,8 @@ void onewire_host_target_search(OneWireHost* host, uint8_t family_code) { furi_check(host); host->saved_rom[0] = family_code; - for(uint8_t i = 1; i < 8; i++) host->saved_rom[i] = 0; + for(uint8_t i = 1; i < 8; i++) + host->saved_rom[i] = 0; host->last_discrepancy = 64; host->last_family_discrepancy = 0; host->last_device_flag = false; @@ -341,7 +342,8 @@ bool onewire_host_search(OneWireHost* host, uint8_t* new_addr, OneWireHostSearch host->last_family_discrepancy = 0; search_result = false; } else { - for(int i = 0; i < 8; i++) new_addr[i] = host->saved_rom[i]; + for(int i = 0; i < 8; i++) + new_addr[i] = host->saved_rom[i]; } return search_result; diff --git a/lib/one_wire/one_wire_slave.c b/lib/one_wire/one_wire_slave.c index 8dfbe4aa582..36edc620f89 100644 --- a/lib/one_wire/one_wire_slave.c +++ b/lib/one_wire/one_wire_slave.c @@ -150,7 +150,7 @@ static inline bool onewire_slave_receive_and_process_command(OneWireSlave* bus) } } - return (bus->error == OneWireSlaveErrorResetInProgress); + return bus->error == OneWireSlaveErrorResetInProgress; } return false; @@ -204,7 +204,7 @@ static void onewire_slave_exti_callback(void* context) { } else { pulse_start = DWT->CYCCNT; } -}; +} /*********************** PUBLIC ***********************/ diff --git a/lib/print/SConscript b/lib/print/SConscript index 819e60bf07f..07be8d890e1 100644 --- a/lib/print/SConscript +++ b/lib/print/SConscript @@ -107,6 +107,9 @@ env.Append( libenv = env.Clone(FW_LIB_NAME="print") libenv.ApplyLibFlags() +if env["RAM_EXEC"]: + libenv.AppendUnique(CPPDEFINES=["PRINTF_DISABLE_SUPPORT_FLOAT"]) + libenv.Append(CCFLAGS=["-Wno-double-promotion"]) sources = libenv.GlobRecursive("*.c*", ".") diff --git a/lib/print/printf_tiny.c b/lib/print/printf_tiny.c index 54f192a609b..387a6451e2d 100644 --- a/lib/print/printf_tiny.c +++ b/lib/print/printf_tiny.c @@ -96,15 +96,15 @@ /////////////////////////////////////////////////////////////////////////////// // internal flag definitions -#define FLAGS_ZEROPAD (1U << 0U) -#define FLAGS_LEFT (1U << 1U) -#define FLAGS_PLUS (1U << 2U) -#define FLAGS_SPACE (1U << 3U) -#define FLAGS_HASH (1U << 4U) +#define FLAGS_ZEROPAD (1U << 0U) +#define FLAGS_LEFT (1U << 1U) +#define FLAGS_PLUS (1U << 2U) +#define FLAGS_SPACE (1U << 3U) +#define FLAGS_HASH (1U << 4U) #define FLAGS_UPPERCASE (1U << 5U) -#define FLAGS_CHAR (1U << 6U) -#define FLAGS_SHORT (1U << 7U) -#define FLAGS_LONG (1U << 8U) +#define FLAGS_CHAR (1U << 6U) +#define FLAGS_SHORT (1U << 7U) +#define FLAGS_LONG (1U << 8U) #define FLAGS_LONG_LONG (1U << 9U) #define FLAGS_PRECISION (1U << 10U) #define FLAGS_ADAPT_EXP (1U << 11U) @@ -616,7 +616,8 @@ static size_t _etoa( FLAGS_ZEROPAD | FLAGS_PLUS); // might need to right-pad spaces if(flags & FLAGS_LEFT) { - while(idx - start_idx < width) out(' ', buffer, idx++, maxlen); + while(idx - start_idx < width) + out(' ', buffer, idx++, maxlen); } } return idx; diff --git a/lib/print/wrappers.c b/lib/print/wrappers.c index b248aeb3dfe..c8d72d19285 100644 --- a/lib/print/wrappers.c +++ b/lib/print/wrappers.c @@ -68,4 +68,4 @@ __attribute__((__noreturn__)) void UNUSED(line); UNUSED(func); furi_crash(e); -} \ No newline at end of file +} diff --git a/lib/print/wrappers.h b/lib/print/wrappers.h index 7c0d1f92ebe..3cec88249a2 100644 --- a/lib/print/wrappers.h +++ b/lib/print/wrappers.h @@ -23,4 +23,4 @@ __attribute__((__noreturn__)) void #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/pulse_reader/pulse_reader.h b/lib/pulse_reader/pulse_reader.h index 62c5f2fa46d..a4383b4c619 100644 --- a/lib/pulse_reader/pulse_reader.h +++ b/lib/pulse_reader/pulse_reader.h @@ -10,9 +10,9 @@ extern "C" { #endif -#define PULSE_READER_NO_EDGE (0xFFFFFFFFUL) +#define PULSE_READER_NO_EDGE (0xFFFFFFFFUL) #define PULSE_READER_LOST_EDGE (0xFFFFFFFEUL) -#define F_TIM2 (64000000UL) +#define F_TIM2 (64000000UL) /** * unit of the edge durations to return diff --git a/lib/signal_reader/parsers/iso15693/iso15693_parser.c b/lib/signal_reader/parsers/iso15693/iso15693_parser.c index c5326a354d7..a2c6912e637 100644 --- a/lib/signal_reader/parsers/iso15693/iso15693_parser.c +++ b/lib/signal_reader/parsers/iso15693/iso15693_parser.c @@ -5,8 +5,8 @@ #include #define ISO15693_PARSER_SIGNAL_READER_BUFF_SIZE (2) -#define ISO15693_PARSER_BITSTREAM_BUFF_SIZE (32) -#define ISO15693_PARSER_BITRATE_F64MHZ (603U) +#define ISO15693_PARSER_BITSTREAM_BUFF_SIZE (32) +#define ISO15693_PARSER_BITRATE_F64MHZ (603U) #define TAG "Iso15693Parser" diff --git a/lib/signal_reader/signal_reader.c b/lib/signal_reader/signal_reader.c index 8df2d5c72af..97d56435c1e 100644 --- a/lib/signal_reader/signal_reader.c +++ b/lib/signal_reader/signal_reader.c @@ -13,18 +13,18 @@ #define SIGNAL_READER_DMA DMA2 -#define SIGNAL_READER_CAPTURE_TIM (TIM16) +#define SIGNAL_READER_CAPTURE_TIM (TIM16) #define SIGNAL_READER_CAPTURE_TIM_CHANNEL LL_TIM_CHANNEL_CH1 -#define SIGNAL_READER_DMA_GPIO LL_DMA_CHANNEL_2 +#define SIGNAL_READER_DMA_GPIO LL_DMA_CHANNEL_2 #define SIGNAL_READER_DMA_GPIO_IRQ FuriHalInterruptIdDma2Ch2 #define SIGNAL_READER_DMA_GPIO_DEF SIGNAL_READER_DMA, SIGNAL_READER_DMA_GPIO -#define SIGNAL_READER_DMA_TRIGGER LL_DMA_CHANNEL_3 +#define SIGNAL_READER_DMA_TRIGGER LL_DMA_CHANNEL_3 #define SIGNAL_READER_DMA_TRIGGER_IRQ FuriHalInterruptIdDma2Ch3 #define SIGNAL_READER_DMA_TRIGGER_DEF SIGNAL_READER_DMA, SIGNAL_READER_DMA_TRIGGER -#define SIGNAL_READER_DMA_CNT_SYNC LL_DMA_CHANNEL_5 +#define SIGNAL_READER_DMA_CNT_SYNC LL_DMA_CHANNEL_5 #define SIGNAL_READER_DMA_CNT_SYNC_IRQ FuriHalInterruptIdDma2Ch5 #define SIGNAL_READER_DMA_CNT_SYNC_DEF SIGNAL_READER_DMA, SIGNAL_READER_DMA_CNT_SYNC diff --git a/lib/stm32wb_copro b/lib/stm32wb_copro index 64a060d91f5..133182d5583 160000 --- a/lib/stm32wb_copro +++ b/lib/stm32wb_copro @@ -1 +1 @@ -Subproject commit 64a060d91f5cbf25d765cf23231876add006bcf4 +Subproject commit 133182d5583e998bb263cd947105be4df9c29cb3 diff --git a/lib/subghz/blocks/const.h b/lib/subghz/blocks/const.h index f32334e2f44..e73b1a55940 100644 --- a/lib/subghz/blocks/const.h +++ b/lib/subghz/blocks/const.h @@ -17,4 +17,4 @@ typedef struct { #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/subghz/blocks/decoder.h b/lib/subghz/blocks/decoder.h index a5e561e3517..4323dae09a5 100644 --- a/lib/subghz/blocks/decoder.h +++ b/lib/subghz/blocks/decoder.h @@ -44,4 +44,4 @@ uint8_t subghz_protocol_blocks_get_hash_data(SubGhzBlockDecoder* decoder, size_t #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/subghz/blocks/encoder.h b/lib/subghz/blocks/encoder.h index aeaa2add023..71710fa14d9 100644 --- a/lib/subghz/blocks/encoder.h +++ b/lib/subghz/blocks/encoder.h @@ -64,4 +64,4 @@ size_t subghz_protocol_blocks_get_upload_from_bit_array( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/subghz/blocks/generic.c b/lib/subghz/blocks/generic.c index 06be6b3d5d0..164ed65aeeb 100644 --- a/lib/subghz/blocks/generic.c +++ b/lib/subghz/blocks/generic.c @@ -150,4 +150,4 @@ SubGhzProtocolStatus subghz_block_generic_deserialize_check_count_bit( } } while(false); return ret; -} \ No newline at end of file +} diff --git a/lib/subghz/blocks/generic.h b/lib/subghz/blocks/generic.h index bc26a54d9f0..54342601d4b 100644 --- a/lib/subghz/blocks/generic.h +++ b/lib/subghz/blocks/generic.h @@ -66,4 +66,4 @@ SubGhzProtocolStatus subghz_block_generic_deserialize_check_count_bit( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/subghz/blocks/math.c b/lib/subghz/blocks/math.c index 24202ad1c62..226bb3e7460 100644 --- a/lib/subghz/blocks/math.c +++ b/lib/subghz/blocks/math.c @@ -241,4 +241,4 @@ uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size) { result ^= message[i]; } return result; -} \ No newline at end of file +} diff --git a/lib/subghz/blocks/math.h b/lib/subghz/blocks/math.h index dcea3da5faf..bee1bf73307 100644 --- a/lib/subghz/blocks/math.h +++ b/lib/subghz/blocks/math.h @@ -16,7 +16,7 @@ (value) &= ~(_one << (bit)); \ }) #define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit)) -#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) +#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) #ifdef __cplusplus extern "C" { diff --git a/lib/subghz/devices/cc1101_configs.h b/lib/subghz/devices/cc1101_configs.h index eecab01d999..a821ade6b4d 100644 --- a/lib/subghz/devices/cc1101_configs.h +++ b/lib/subghz/devices/cc1101_configs.h @@ -15,4 +15,4 @@ extern const uint8_t subghz_device_cc1101_preset_gfsk_9_99kb_async_regs[]; #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/subghz/devices/types.h b/lib/subghz/devices/types.h index 8a41984263f..9060ab9303d 100644 --- a/lib/subghz/devices/types.h +++ b/lib/subghz/devices/types.h @@ -11,7 +11,7 @@ #include -#define SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID "subghz_radio_device" +#define SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID "subghz_radio_device" #define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 1 typedef struct SubGhzDeviceRegistry SubGhzDeviceRegistry; diff --git a/lib/subghz/environment.c b/lib/subghz/environment.c index 1df598dc3d4..134b4d2784e 100644 --- a/lib/subghz/environment.c +++ b/lib/subghz/environment.c @@ -116,4 +116,4 @@ const char* } else { return NULL; } -} \ No newline at end of file +} diff --git a/lib/subghz/protocols/bin_raw.c b/lib/subghz/protocols/bin_raw.c index 8f62ccb1f64..8298bce6b06 100644 --- a/lib/subghz/protocols/bin_raw.c +++ b/lib/subghz/protocols/bin_raw.c @@ -14,15 +14,15 @@ #define TAG "SubGhzProtocolBinRaw" //change very carefully, RAM ends at the most inopportune moment -#define BIN_RAW_BUF_RAW_SIZE 2048 +#define BIN_RAW_BUF_RAW_SIZE 2048 #define BIN_RAW_BUF_DATA_SIZE 512 -#define BIN_RAW_THRESHOLD_RSSI -85.0f -#define BIN_RAW_DELTA_RSSI 7.0f -#define BIN_RAW_SEARCH_CLASSES 20 -#define BIN_RAW_TE_MIN_COUNT 40 +#define BIN_RAW_THRESHOLD_RSSI -85.0f +#define BIN_RAW_DELTA_RSSI 7.0f +#define BIN_RAW_SEARCH_CLASSES 20 +#define BIN_RAW_TE_MIN_COUNT 40 #define BIN_RAW_BUF_MIN_DATA_COUNT 128 -#define BIN_RAW_MAX_MARKUP_COUNT 20 +#define BIN_RAW_MAX_MARKUP_COUNT 20 //#define BIN_RAW_DEBUG @@ -131,7 +131,7 @@ static uint16_t subghz_protocol_bin_raw_get_full_byte(uint16_t bit_count) { if(bit_count & 0x7) { return (bit_count >> 3) + 1; } else { - return (bit_count >> 3); + return bit_count >> 3; } } diff --git a/lib/subghz/protocols/came.c b/lib/subghz/protocols/came.c index 40ae05bade3..645f5eee137 100644 --- a/lib/subghz/protocols/came.c +++ b/lib/subghz/protocols/came.c @@ -13,12 +13,13 @@ */ #define TAG "SubGhzProtocolCame" -#define CAME_12_COUNT_BIT 12 -#define CAME_24_COUNT_BIT 24 -#define PRASTEL_COUNT_BIT 25 -#define PRASTEL_NAME "Prastel" + +#define CAME_12_COUNT_BIT 12 +#define CAME_24_COUNT_BIT 24 +#define PRASTEL_COUNT_BIT 25 +#define PRASTEL_NAME "Prastel" #define AIRFORCE_COUNT_BIT 18 -#define AIRFORCE_NAME "Airforce" +#define AIRFORCE_NAME "Airforce" static const SubGhzBlockConst subghz_protocol_came_const = { .te_short = 320, @@ -173,7 +174,7 @@ SubGhzProtocolStatus if(ret != SubGhzProtocolStatusOk) { break; } - if((instance->generic.data_count_bit > PRASTEL_COUNT_BIT)) { + if(instance->generic.data_count_bit > PRASTEL_COUNT_BIT) { FURI_LOG_E(TAG, "Wrong number of bits in key"); ret = SubGhzProtocolStatusErrorValueBitCount; break; @@ -336,7 +337,7 @@ SubGhzProtocolStatus if(ret != SubGhzProtocolStatusOk) { break; } - if((instance->generic.data_count_bit > PRASTEL_COUNT_BIT)) { + if(instance->generic.data_count_bit > PRASTEL_COUNT_BIT) { FURI_LOG_E(TAG, "Wrong number of bits in key"); ret = SubGhzProtocolStatusErrorValueBitCount; break; diff --git a/lib/subghz/protocols/chamberlain_code.c b/lib/subghz/protocols/chamberlain_code.c index 0dd0d2b0b79..ea85fc0d96a 100644 --- a/lib/subghz/protocols/chamberlain_code.c +++ b/lib/subghz/protocols/chamberlain_code.c @@ -9,8 +9,8 @@ #define TAG "SubGhzProtocolChambCode" #define CHAMBERLAIN_CODE_BIT_STOP 0b0001 -#define CHAMBERLAIN_CODE_BIT_1 0b0011 -#define CHAMBERLAIN_CODE_BIT_0 0b0111 +#define CHAMBERLAIN_CODE_BIT_1 0b0011 +#define CHAMBERLAIN_CODE_BIT_0 0b0111 #define CHAMBERLAIN_7_CODE_MASK 0xF000000FF0F #define CHAMBERLAIN_8_CODE_MASK 0xF00000F00F diff --git a/lib/subghz/protocols/clemsa.c b/lib/subghz/protocols/clemsa.c index a0547a11372..5cbffefed0d 100644 --- a/lib/subghz/protocols/clemsa.c +++ b/lib/subghz/protocols/clemsa.c @@ -267,13 +267,12 @@ void subghz_protocol_decoder_clemsa_feed(void* context, bool level, uint32_t dur } else if( DURATION_DIFF(duration, subghz_protocol_clemsa_const.te_short * 51) < subghz_protocol_clemsa_const.te_delta * 25) { - if((DURATION_DIFF( - instance->decoder.te_last, subghz_protocol_clemsa_const.te_short) < - subghz_protocol_clemsa_const.te_delta)) { + if(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_clemsa_const.te_short) < + subghz_protocol_clemsa_const.te_delta) { subghz_protocol_blocks_add_bit(&instance->decoder, 0); - } else if((DURATION_DIFF( - instance->decoder.te_last, subghz_protocol_clemsa_const.te_long) < - subghz_protocol_clemsa_const.te_delta * 3)) { + } else if( + DURATION_DIFF(instance->decoder.te_last, subghz_protocol_clemsa_const.te_long) < + subghz_protocol_clemsa_const.te_delta * 3) { subghz_protocol_blocks_add_bit(&instance->decoder, 1); } else { instance->decoder.parser_step = ClemsaDecoderStepReset; diff --git a/lib/subghz/protocols/doitrand.c b/lib/subghz/protocols/doitrand.c index 69b8bba4ae1..cf9618fcbb3 100644 --- a/lib/subghz/protocols/doitrand.c +++ b/lib/subghz/protocols/doitrand.c @@ -219,8 +219,8 @@ void subghz_protocol_decoder_doitrand_feed(void* context, bool level, uint32_t d } break; case DoitrandDecoderStepFoundStartBit: - if(level && ((DURATION_DIFF(duration, (subghz_protocol_doitrand_const.te_short * 2)) < - subghz_protocol_doitrand_const.te_delta * 3))) { + if(level && (DURATION_DIFF(duration, (subghz_protocol_doitrand_const.te_short * 2)) < + subghz_protocol_doitrand_const.te_delta * 3)) { //Found start bit instance->decoder.parser_step = DoitrandDecoderStepSaveDuration; instance->decoder.decode_data = 0; diff --git a/lib/subghz/protocols/gate_tx.c b/lib/subghz/protocols/gate_tx.c index 2ebd6bb03b9..d6a6bc7c9e1 100644 --- a/lib/subghz/protocols/gate_tx.c +++ b/lib/subghz/protocols/gate_tx.c @@ -212,8 +212,8 @@ void subghz_protocol_decoder_gate_tx_feed(void* context, bool level, uint32_t du } break; case GateTXDecoderStepFoundStartBit: - if(level && ((DURATION_DIFF(duration, subghz_protocol_gate_tx_const.te_long) < - subghz_protocol_gate_tx_const.te_delta * 3))) { + if(level && (DURATION_DIFF(duration, subghz_protocol_gate_tx_const.te_long) < + subghz_protocol_gate_tx_const.te_delta * 3)) { //Found start bit instance->decoder.parser_step = GateTXDecoderStepSaveDuration; instance->decoder.decode_data = 0; diff --git a/lib/subghz/protocols/holtek.c b/lib/subghz/protocols/holtek.c index 294bd124d3c..b4717f5c678 100644 --- a/lib/subghz/protocols/holtek.c +++ b/lib/subghz/protocols/holtek.c @@ -16,7 +16,7 @@ #define TAG "SubGhzProtocolHoltek" #define HOLTEK_HEADER_MASK 0xF000000000 -#define HOLTEK_HEADER 0x5000000000 +#define HOLTEK_HEADER 0x5000000000 static const SubGhzBlockConst subghz_protocol_holtek_const = { .te_short = 430, @@ -358,7 +358,7 @@ void subghz_protocol_decoder_holtek_get_string(void* context, FuriString* output if((instance->generic.btn & 0xF) == 0xE) { furi_string_cat_printf(output, "ON\r\n"); - } else if(((instance->generic.btn & 0xF) == 0xB)) { + } else if((instance->generic.btn & 0xF) == 0xB) { furi_string_cat_printf(output, "OFF\r\n"); } } diff --git a/lib/subghz/protocols/hormann.c b/lib/subghz/protocols/hormann.c index fc490e9d1c7..70954bb39d4 100644 --- a/lib/subghz/protocols/hormann.c +++ b/lib/subghz/protocols/hormann.c @@ -285,7 +285,7 @@ void subghz_protocol_decoder_hormann_feed(void* context, bool level, uint32_t du * @param instance Pointer to a SubGhzBlockGeneric* instance */ static void subghz_protocol_hormann_check_remote_controller(SubGhzBlockGeneric* instance) { - instance->btn = (instance->data >> 4) & 0xF; + instance->btn = (instance->data >> 8) & 0xF; } uint8_t subghz_protocol_decoder_hormann_get_hash_data(void* context) { diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 51f7d35906f..b38abb75b50 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -473,7 +473,7 @@ static inline bool subghz_protocol_keeloq_check_decrypt_centurion( uint8_t btn) { furi_assert(instance); - if((decrypt >> 28 == btn) && (((((uint16_t)(decrypt >> 16)) & 0x3FF) == 0x1CE))) { + if((decrypt >> 28 == btn) && ((((uint16_t)(decrypt >> 16)) & 0x3FF) == 0x1CE)) { instance->cnt = decrypt & 0x0000FFFF; return true; } @@ -521,7 +521,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 man = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if((strcmp(furi_string_get_cstr(manufacture_code->name), "Centurion") == 0)) { + if(strcmp(furi_string_get_cstr(manufacture_code->name), "Centurion") == 0) { if(subghz_protocol_keeloq_check_decrypt_centurion(instance, decrypt, btn)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); return 1; diff --git a/lib/subghz/protocols/keeloq_common.h b/lib/subghz/protocols/keeloq_common.h index df3d0dbf367..6e40b66ce4f 100644 --- a/lib/subghz/protocols/keeloq_common.h +++ b/lib/subghz/protocols/keeloq_common.h @@ -16,11 +16,11 @@ * KeeLoq learning types * https://phreakerclub.com/forum/showthread.php?t=67 */ -#define KEELOQ_LEARNING_UNKNOWN 0u -#define KEELOQ_LEARNING_SIMPLE 1u -#define KEELOQ_LEARNING_NORMAL 2u -#define KEELOQ_LEARNING_SECURE 3u -#define KEELOQ_LEARNING_MAGIC_XOR_TYPE_1 4u +#define KEELOQ_LEARNING_UNKNOWN 0u +#define KEELOQ_LEARNING_SIMPLE 1u +#define KEELOQ_LEARNING_NORMAL 2u +#define KEELOQ_LEARNING_SECURE 3u +#define KEELOQ_LEARNING_MAGIC_XOR_TYPE_1 4u #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1 5u #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_2 6u #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_3 7u diff --git a/lib/subghz/protocols/linear.c b/lib/subghz/protocols/linear.c index 8d37357966b..f9d7aaca871 100644 --- a/lib/subghz/protocols/linear.c +++ b/lib/subghz/protocols/linear.c @@ -243,8 +243,8 @@ void subghz_protocol_decoder_linear_feed(void* context, bool level, uint32_t dur if(duration >= (subghz_protocol_linear_const.te_short * 5)) { instance->decoder.parser_step = LinearDecoderStepReset; //checking that the duration matches the guardtime - if((DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) > - subghz_protocol_linear_const.te_delta * 20)) { + if(DURATION_DIFF(duration, subghz_protocol_linear_const.te_short * 42) > + subghz_protocol_linear_const.te_delta * 20) { break; } if(DURATION_DIFF(instance->decoder.te_last, subghz_protocol_linear_const.te_short) < diff --git a/lib/subghz/protocols/mastercode.c b/lib/subghz/protocols/mastercode.c index 54ad5bfaa44..d4c549a4229 100644 --- a/lib/subghz/protocols/mastercode.c +++ b/lib/subghz/protocols/mastercode.c @@ -269,14 +269,14 @@ void subghz_protocol_decoder_mastercode_feed(void* context, bool level, uint32_t } else if( DURATION_DIFF(duration, subghz_protocol_mastercode_const.te_short * 15) < subghz_protocol_mastercode_const.te_delta * 15) { - if((DURATION_DIFF( - instance->decoder.te_last, subghz_protocol_mastercode_const.te_short) < - subghz_protocol_mastercode_const.te_delta)) { + if(DURATION_DIFF( + instance->decoder.te_last, subghz_protocol_mastercode_const.te_short) < + subghz_protocol_mastercode_const.te_delta) { subghz_protocol_blocks_add_bit(&instance->decoder, 0); - } else if((DURATION_DIFF( - instance->decoder.te_last, - subghz_protocol_mastercode_const.te_long) < - subghz_protocol_mastercode_const.te_delta * 8)) { + } else if( + DURATION_DIFF( + instance->decoder.te_last, subghz_protocol_mastercode_const.te_long) < + subghz_protocol_mastercode_const.te_delta * 8) { subghz_protocol_blocks_add_bit(&instance->decoder, 1); } else { instance->decoder.parser_step = MastercodeDecoderStepReset; diff --git a/lib/subghz/protocols/nice_flor_s.c b/lib/subghz/protocols/nice_flor_s.c index d8f5a070a08..413204f20d6 100644 --- a/lib/subghz/protocols/nice_flor_s.c +++ b/lib/subghz/protocols/nice_flor_s.c @@ -15,7 +15,7 @@ #define TAG "SubGhzProtocoNiceFlorS" #define NICE_ONE_COUNT_BIT 72 -#define NICE_ONE_NAME "Nice One" +#define NICE_ONE_NAME "Nice One" static const SubGhzBlockConst subghz_protocol_nice_flor_s_const = { .te_short = 500, diff --git a/lib/subghz/protocols/phoenix_v2.c b/lib/subghz/protocols/phoenix_v2.c index 2416a9d0109..2fabed73d5e 100644 --- a/lib/subghz/protocols/phoenix_v2.c +++ b/lib/subghz/protocols/phoenix_v2.c @@ -215,8 +215,8 @@ void subghz_protocol_decoder_phoenix_v2_feed(void* context, bool level, uint32_t } break; case Phoenix_V2DecoderStepFoundStartBit: - if(level && ((DURATION_DIFF(duration, (subghz_protocol_phoenix_v2_const.te_short * 6)) < - subghz_protocol_phoenix_v2_const.te_delta * 4))) { + if(level && (DURATION_DIFF(duration, (subghz_protocol_phoenix_v2_const.te_short * 6)) < + subghz_protocol_phoenix_v2_const.te_delta * 4)) { //Found start bit instance->decoder.parser_step = Phoenix_V2DecoderStepSaveDuration; instance->decoder.decode_data = 0; diff --git a/lib/subghz/protocols/power_smart.c b/lib/subghz/protocols/power_smart.c index d03282f73a1..828c4a76eaa 100644 --- a/lib/subghz/protocols/power_smart.c +++ b/lib/subghz/protocols/power_smart.c @@ -8,7 +8,8 @@ #include "../blocks/math.h" #define TAG "SubGhzProtocolPowerSmart" -#define POWER_SMART_PACKET_HEADER 0xFD000000AA000000 + +#define POWER_SMART_PACKET_HEADER 0xFD000000AA000000 #define POWER_SMART_PACKET_HEADER_MASK 0xFF000000FF000000 #define CHANNEL_PATTERN "%c%c%c%c%c%c" diff --git a/lib/subghz/protocols/princeton.c b/lib/subghz/protocols/princeton.c index 888ea964573..35034935136 100644 --- a/lib/subghz/protocols/princeton.c +++ b/lib/subghz/protocols/princeton.c @@ -13,6 +13,7 @@ */ #define TAG "SubGhzProtocolPrinceton" + #define PRINCETON_GUARD_TIME_DEFALUT 30 //GUARD_TIME = PRINCETON_GUARD_TIME_DEFALUT * TE // Guard Time value should be between 15 -> 72 otherwise default value will be used diff --git a/lib/subghz/protocols/raw.c b/lib/subghz/protocols/raw.c index b5677f9c29b..d7b31be3791 100644 --- a/lib/subghz/protocols/raw.c +++ b/lib/subghz/protocols/raw.c @@ -9,6 +9,7 @@ #include #define TAG "SubGhzProtocolRaw" + #define SUBGHZ_DOWNLOAD_MAX_SIZE 512 static const SubGhzBlockConst subghz_protocol_raw_const = { diff --git a/lib/subghz/protocols/secplus_v1.c b/lib/subghz/protocols/secplus_v1.c index 644b2fba9cf..f878ecb01b5 100644 --- a/lib/subghz/protocols/secplus_v1.c +++ b/lib/subghz/protocols/secplus_v1.c @@ -14,16 +14,16 @@ #define TAG "SubGhzProtocoSecPlusV1" #define SECPLUS_V1_BIT_ERR -1 //0b0000 -#define SECPLUS_V1_BIT_0 0 //0b0001 -#define SECPLUS_V1_BIT_1 1 //0b0011 -#define SECPLUS_V1_BIT_2 2 //0b0111 +#define SECPLUS_V1_BIT_0 0 //0b0001 +#define SECPLUS_V1_BIT_1 1 //0b0011 +#define SECPLUS_V1_BIT_2 2 //0b0111 -#define SECPLUS_V1_PACKET_1_HEADER 0x00 -#define SECPLUS_V1_PACKET_2_HEADER 0x02 +#define SECPLUS_V1_PACKET_1_HEADER 0x00 +#define SECPLUS_V1_PACKET_2_HEADER 0x02 #define SECPLUS_V1_PACKET_1_INDEX_BASE 0 #define SECPLUS_V1_PACKET_2_INDEX_BASE 21 -#define SECPLUS_V1_PACKET_1_ACCEPTED (1 << 0) -#define SECPLUS_V1_PACKET_2_ACCEPTED (1 << 1) +#define SECPLUS_V1_PACKET_1_ACCEPTED (1 << 0) +#define SECPLUS_V1_PACKET_2_ACCEPTED (1 << 1) static const SubGhzBlockConst subghz_protocol_secplus_v1_const = { .te_short = 500, diff --git a/lib/subghz/protocols/secplus_v2.c b/lib/subghz/protocols/secplus_v2.c index 08d5c84f6ab..4f11e22b6bd 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -15,10 +15,10 @@ #define TAG "SubGhzProtocoSecPlusV2" -#define SECPLUS_V2_HEADER 0x3C0000000000 +#define SECPLUS_V2_HEADER 0x3C0000000000 #define SECPLUS_V2_HEADER_MASK 0xFFFF3C0000000000 -#define SECPLUS_V2_PACKET_1 0x000000000000 -#define SECPLUS_V2_PACKET_2 0x010000000000 +#define SECPLUS_V2_PACKET_1 0x000000000000 +#define SECPLUS_V2_PACKET_2 0x010000000000 #define SECPLUS_V2_PACKET_MASK 0x30000000000 static const SubGhzBlockConst subghz_protocol_secplus_v2_const = { diff --git a/lib/subghz/subghz_keystore.c b/lib/subghz/subghz_keystore.c index c5c676a607f..4191d768f23 100644 --- a/lib/subghz/subghz_keystore.c +++ b/lib/subghz/subghz_keystore.c @@ -13,9 +13,9 @@ #define FILE_BUFFER_SIZE 64 -#define SUBGHZ_KEYSTORE_FILE_TYPE "Flipper SubGhz Keystore File" +#define SUBGHZ_KEYSTORE_FILE_TYPE "Flipper SubGhz Keystore File" #define SUBGHZ_KEYSTORE_FILE_RAW_TYPE "Flipper SubGhz Keystore RAW File" -#define SUBGHZ_KEYSTORE_FILE_VERSION 0 +#define SUBGHZ_KEYSTORE_FILE_VERSION 0 #define SUBGHZ_KEYSTORE_FILE_ENCRYPTION_KEY_SLOT 1 #define SUBGHZ_KEYSTORE_FILE_DECRYPTED_LINE_SIZE 512 diff --git a/lib/subghz/subghz_setting.c b/lib/subghz/subghz_setting.c index ed1120a2002..12b7bd16a0b 100644 --- a/lib/subghz/subghz_setting.c +++ b/lib/subghz/subghz_setting.c @@ -7,11 +7,11 @@ #define TAG "SubGhzSetting" -#define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File" +#define SUBGHZ_SETTING_FILE_TYPE "Flipper SubGhz Setting File" #define SUBGHZ_SETTING_FILE_VERSION 1 #define FREQUENCY_FLAG_DEFAULT (1 << 31) -#define FREQUENCY_MASK (0xFFFFFFFF ^ FREQUENCY_FLAG_DEFAULT) +#define FREQUENCY_MASK (0xFFFFFFFF ^ FREQUENCY_FLAG_DEFAULT) /* Default */ static const uint32_t subghz_frequency_list[] = { diff --git a/lib/subghz/subghz_tx_rx_worker.c b/lib/subghz/subghz_tx_rx_worker.c index edef84caf10..9a98ed57a08 100644 --- a/lib/subghz/subghz_tx_rx_worker.c +++ b/lib/subghz/subghz_tx_rx_worker.c @@ -4,7 +4,7 @@ #define TAG "SubGhzTxRxWorker" -#define SUBGHZ_TXRX_WORKER_BUF_SIZE 2048 +#define SUBGHZ_TXRX_WORKER_BUF_SIZE 2048 //you can not set more than 62 because it will not fit into the FIFO CC1101 #define SUBGHZ_TXRX_WORKER_MAX_TXRX_SIZE 60 diff --git a/lib/subghz/subghz_worker.c b/lib/subghz/subghz_worker.c index fe68d5e2d15..a771d1d192a 100644 --- a/lib/subghz/subghz_worker.c +++ b/lib/subghz/subghz_worker.c @@ -146,4 +146,4 @@ bool subghz_worker_is_running(SubGhzWorker* instance) { void subghz_worker_set_filter(SubGhzWorker* instance, uint16_t timeout) { furi_check(instance); instance->filter_duration = timeout; -} \ No newline at end of file +} diff --git a/lib/subghz/types.h b/lib/subghz/types.h index 8c7f50d5dca..e674ef7302e 100644 --- a/lib/subghz/types.h +++ b/lib/subghz/types.h @@ -11,21 +11,21 @@ #include #include -#define SUBGHZ_APP_FOLDER EXT_PATH("subghz") -#define SUBGHZ_RAW_FOLDER EXT_PATH("subghz") -#define SUBGHZ_APP_FILENAME_PREFIX "SubGHz" +#define SUBGHZ_APP_FOLDER EXT_PATH("subghz") +#define SUBGHZ_RAW_FOLDER EXT_PATH("subghz") +#define SUBGHZ_APP_FILENAME_PREFIX "SubGHz" #define SUBGHZ_APP_FILENAME_EXTENSION ".sub" #define SUBGHZ_KEY_FILE_VERSION 1 -#define SUBGHZ_KEY_FILE_TYPE "Flipper SubGhz Key File" +#define SUBGHZ_KEY_FILE_TYPE "Flipper SubGhz Key File" #define SUBGHZ_RAW_FILE_VERSION 1 -#define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File" +#define SUBGHZ_RAW_FILE_TYPE "Flipper SubGhz RAW File" -#define SUBGHZ_KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes") +#define SUBGHZ_KEYSTORE_DIR_NAME EXT_PATH("subghz/assets/keeloq_mfcodes") #define SUBGHZ_KEYSTORE_DIR_USER_NAME EXT_PATH("subghz/assets/keeloq_mfcodes_user") -#define SUBGHZ_CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo") -#define SUBGHZ_NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s") +#define SUBGHZ_CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo") +#define SUBGHZ_NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s") #define SUBGHZ_ALUTECH_AT_4N_DIR_NAME EXT_PATH("subghz/assets/alutech_at_4n") typedef struct SubGhzProtocolRegistry SubGhzProtocolRegistry; diff --git a/lib/toolbox/buffer_stream.c b/lib/toolbox/buffer_stream.c index e8cb334d51c..4ab4a0c5b1d 100644 --- a/lib/toolbox/buffer_stream.c +++ b/lib/toolbox/buffer_stream.c @@ -12,8 +12,8 @@ struct BufferStream { FuriStreamBuffer* stream; size_t index; - Buffer* buffers; size_t max_buffers_count; + Buffer buffers[]; }; bool buffer_write(Buffer* buffer, const uint8_t* data, size_t size) { @@ -44,9 +44,8 @@ void buffer_reset(Buffer* buffer) { BufferStream* buffer_stream_alloc(size_t buffer_size, size_t buffers_count) { furi_assert(buffer_size > 0); furi_assert(buffers_count > 0); - BufferStream* buffer_stream = malloc(sizeof(BufferStream)); + BufferStream* buffer_stream = malloc(sizeof(BufferStream) + (sizeof(Buffer) * buffers_count)); buffer_stream->max_buffers_count = buffers_count; - buffer_stream->buffers = malloc(sizeof(Buffer) * buffer_stream->max_buffers_count); for(size_t i = 0; i < buffer_stream->max_buffers_count; i++) { buffer_stream->buffers[i].occupied = false; buffer_stream->buffers[i].size = 0; @@ -66,7 +65,6 @@ void buffer_stream_free(BufferStream* buffer_stream) { free(buffer_stream->buffers[i].data); } furi_stream_buffer_free(buffer_stream->stream); - free(buffer_stream->buffers); free(buffer_stream); } @@ -137,4 +135,4 @@ void buffer_stream_reset(BufferStream* buffer_stream) { buffer_reset(&buffer_stream->buffers[i]); } FURI_CRITICAL_EXIT(); -} \ No newline at end of file +} diff --git a/lib/toolbox/compress.c b/lib/toolbox/compress.c index 780bea27ab7..5e794891f37 100644 --- a/lib/toolbox/compress.c +++ b/lib/toolbox/compress.c @@ -13,9 +13,15 @@ /** Defines encoder and decoder lookahead buffer size */ #define COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG (4u) -/** Buffer size for input data */ #define COMPRESS_ICON_ENCODED_BUFF_SIZE (256u) +const CompressConfigHeatshrink compress_config_heatshrink_default = { + .window_sz2 = COMPRESS_EXP_BUFF_SIZE_LOG, + .lookahead_sz2 = COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG, + .input_buffer_sz = COMPRESS_ICON_ENCODED_BUFF_SIZE, +}; + +/** Buffer size for input data */ static bool compress_decode_internal( heatshrink_decoder* decoder, const uint8_t* data_in, @@ -83,16 +89,19 @@ void compress_icon_decode(CompressIcon* instance, const uint8_t* icon_data, uint } struct Compress { + const void* config; heatshrink_encoder* encoder; heatshrink_decoder* decoder; }; -Compress* compress_alloc(uint16_t compress_buff_size) { +Compress* compress_alloc(CompressType type, const void* config) { + furi_check(type == CompressTypeHeatshrink); + furi_check(config); + Compress* compress = malloc(sizeof(Compress)); - compress->encoder = - heatshrink_encoder_alloc(COMPRESS_EXP_BUFF_SIZE_LOG, COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG); - compress->decoder = heatshrink_decoder_alloc( - compress_buff_size, COMPRESS_EXP_BUFF_SIZE_LOG, COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG); + compress->config = config; + compress->encoder = NULL; + compress->decoder = NULL; return compress; } @@ -100,8 +109,12 @@ Compress* compress_alloc(uint16_t compress_buff_size) { void compress_free(Compress* compress) { furi_check(compress); - heatshrink_encoder_free(compress->encoder); - heatshrink_decoder_free(compress->decoder); + if(compress->encoder) { + heatshrink_encoder_free(compress->encoder); + } + if(compress->decoder) { + heatshrink_decoder_free(compress->decoder); + } free(compress); } @@ -125,6 +138,7 @@ static bool compress_encode_internal( size_t sunk = 0; size_t res_buff_size = sizeof(CompressHeader); + heatshrink_encoder_reset(encoder); /* Sink data to encoding buffer */ while((sunk < data_in_size) && !encode_failed) { sink_res = @@ -179,76 +193,152 @@ static bool compress_encode_internal( *data_res_size = 0; result = false; } - heatshrink_encoder_reset(encoder); return result; } -static bool compress_decode_internal( +static inline bool compress_decoder_poll( heatshrink_decoder* decoder, - const uint8_t* data_in, - size_t data_in_size, - uint8_t* data_out, - size_t data_out_size, - size_t* data_res_size) { - furi_check(decoder); - furi_check(data_in); - furi_check(data_out); - furi_check(data_res_size); + uint8_t* decompressed_chunk, + size_t decomp_buffer_size, + CompressIoCallback write_cb, + void* write_context) { + HSD_poll_res poll_res; + size_t poll_size; - bool result = false; + do { + poll_res = + heatshrink_decoder_poll(decoder, decompressed_chunk, decomp_buffer_size, &poll_size); + if(poll_res < 0) { + return false; + } + + size_t write_size = write_cb(write_context, decompressed_chunk, poll_size); + if(write_size != poll_size) { + return false; + } + } while(poll_res == HSDR_POLL_MORE); + + return true; +} + +static bool compress_decode_stream_internal( + heatshrink_decoder* decoder, + const size_t work_buffer_size, + CompressIoCallback read_cb, + void* read_context, + CompressIoCallback write_cb, + void* write_context) { bool decode_failed = false; HSD_sink_res sink_res; - HSD_poll_res poll_res; HSD_finish_res finish_res; + size_t read_size = 0; size_t sink_size = 0; - size_t res_buff_size = 0; - size_t poll_size = 0; - CompressHeader* header = (CompressHeader*)data_in; - if(header->is_compressed) { - /* Sink data to decoding buffer */ - size_t compressed_size = header->compressed_buff_size; + uint8_t* compressed_chunk = malloc(work_buffer_size); + uint8_t* decompressed_chunk = malloc(work_buffer_size); + + /* Sink data to decoding buffer */ + do { + read_size = read_cb(read_context, compressed_chunk, work_buffer_size); + size_t sunk = 0; - while(sunk < compressed_size && !decode_failed) { + while(sunk < read_size && !decode_failed) { sink_res = heatshrink_decoder_sink( - decoder, - (uint8_t*)&data_in[sizeof(CompressHeader) + sunk], - compressed_size - sunk, - &sink_size); + decoder, &compressed_chunk[sunk], read_size - sunk, &sink_size); if(sink_res < 0) { decode_failed = true; break; } sunk += sink_size; - do { - poll_res = heatshrink_decoder_poll( - decoder, &data_out[res_buff_size], data_out_size - res_buff_size, &poll_size); - if((poll_res < 0) || ((data_out_size - res_buff_size) == 0)) { - decode_failed = true; - break; - } - res_buff_size += poll_size; - } while(poll_res == HSDR_POLL_MORE); + + if(!compress_decoder_poll( + decoder, decompressed_chunk, work_buffer_size, write_cb, write_context)) { + decode_failed = true; + break; + } } - /* Notify sinking complete and poll decoded data */ - if(!decode_failed) { - finish_res = heatshrink_decoder_finish(decoder); + } while(!decode_failed && read_size); + + /* Notify sinking complete and poll decoded data */ + if(!decode_failed) { + while((finish_res = heatshrink_decoder_finish(decoder)) != HSDR_FINISH_DONE) { if(finish_res < 0) { decode_failed = true; - } else { - do { - poll_res = heatshrink_decoder_poll( - decoder, - &data_out[res_buff_size], - data_out_size - res_buff_size, - &poll_size); - res_buff_size += poll_size; - finish_res = heatshrink_decoder_finish(decoder); - } while(finish_res != HSDR_FINISH_DONE); + break; + } + + if(!compress_decoder_poll( + decoder, decompressed_chunk, work_buffer_size, write_cb, write_context)) { + decode_failed = true; + break; } } - *data_res_size = res_buff_size; - result = !decode_failed; + } + + free(compressed_chunk); + free(decompressed_chunk); + + return !decode_failed; +} + +typedef struct { + uint8_t* data_ptr; + size_t data_size; + bool is_source; +} MemoryStreamState; + +static int32_t memory_stream_io_callback(void* context, uint8_t* ptr, size_t size) { + MemoryStreamState* state = (MemoryStreamState*)context; + + if(size > state->data_size) { + size = state->data_size; + } + if(state->is_source) { + memcpy(ptr, state->data_ptr, size); + } else { + memcpy(state->data_ptr, ptr, size); + } + state->data_ptr += size; + state->data_size -= size; + return size; +} + +static bool compress_decode_internal( + heatshrink_decoder* decoder, + const uint8_t* data_in, + size_t data_in_size, + uint8_t* data_out, + size_t data_out_size, + size_t* data_res_size) { + furi_check(decoder); + furi_check(data_in); + furi_check(data_out); + furi_check(data_res_size); + + bool result = false; + + CompressHeader* header = (CompressHeader*)data_in; + if(header->is_compressed) { + MemoryStreamState compressed_context = { + .data_ptr = (uint8_t*)&data_in[sizeof(CompressHeader)], + .data_size = header->compressed_buff_size, + .is_source = true, + }; + MemoryStreamState decompressed_context = { + .data_ptr = data_out, + .data_size = data_out_size, + .is_source = false, + }; + heatshrink_decoder_reset(decoder); + if((result = compress_decode_stream_internal( + decoder, + COMPRESS_ICON_ENCODED_BUFF_SIZE, + memory_stream_io_callback, + &compressed_context, + memory_stream_io_callback, + &decompressed_context))) { + *data_res_size = data_out_size - decompressed_context.data_size; + } } else if(data_out_size >= data_in_size - 1) { memcpy(data_out, &data_in[1], data_in_size); *data_res_size = data_in_size - 1; @@ -257,7 +347,6 @@ static bool compress_decode_internal( /* Not enough space in output buffer */ result = false; } - heatshrink_decoder_reset(decoder); return result; } @@ -268,6 +357,11 @@ bool compress_encode( uint8_t* data_out, size_t data_out_size, size_t* data_res_size) { + if(!compress->encoder) { + CompressConfigHeatshrink* hs_config = (CompressConfigHeatshrink*)compress->config; + compress->encoder = + heatshrink_encoder_alloc(hs_config->window_sz2, hs_config->lookahead_sz2); + } return compress_encode_internal( compress->encoder, data_in, data_in_size, data_out, data_out_size, data_res_size); } @@ -279,6 +373,201 @@ bool compress_decode( uint8_t* data_out, size_t data_out_size, size_t* data_res_size) { + if(!compress->decoder) { + CompressConfigHeatshrink* hs_config = (CompressConfigHeatshrink*)compress->config; + compress->decoder = heatshrink_decoder_alloc( + hs_config->input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); + } return compress_decode_internal( compress->decoder, data_in, data_in_size, data_out, data_out_size, data_res_size); } + +bool compress_decode_streamed( + Compress* compress, + CompressIoCallback read_cb, + void* read_context, + CompressIoCallback write_cb, + void* write_context) { + CompressConfigHeatshrink* hs_config = (CompressConfigHeatshrink*)compress->config; + if(!compress->decoder) { + compress->decoder = heatshrink_decoder_alloc( + hs_config->input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); + } + + heatshrink_decoder_reset(compress->decoder); + return compress_decode_stream_internal( + compress->decoder, + hs_config->input_buffer_sz, + read_cb, + read_context, + write_cb, + write_context); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +struct CompressStreamDecoder { + heatshrink_decoder* decoder; + size_t stream_position; + size_t decode_buffer_size; + size_t decode_buffer_position; + uint8_t* decode_buffer; + CompressIoCallback read_cb; + void* read_context; +}; + +CompressStreamDecoder* compress_stream_decoder_alloc( + CompressType type, + const void* config, + CompressIoCallback read_cb, + void* read_context) { + furi_check(type == CompressTypeHeatshrink); + furi_check(config); + + const CompressConfigHeatshrink* hs_config = (const CompressConfigHeatshrink*)config; + CompressStreamDecoder* instance = malloc(sizeof(CompressStreamDecoder)); + instance->decoder = heatshrink_decoder_alloc( + hs_config->input_buffer_sz, hs_config->window_sz2, hs_config->lookahead_sz2); + instance->stream_position = 0; + instance->decode_buffer_size = hs_config->input_buffer_sz; + instance->decode_buffer_position = 0; + instance->decode_buffer = malloc(hs_config->input_buffer_sz); + instance->read_cb = read_cb; + instance->read_context = read_context; + + return instance; +} + +void compress_stream_decoder_free(CompressStreamDecoder* instance) { + furi_check(instance); + heatshrink_decoder_free(instance->decoder); + free(instance->decode_buffer); + free(instance); +} + +static bool compress_decode_stream_chunk( + CompressStreamDecoder* sd, + CompressIoCallback read_cb, + void* read_context, + uint8_t* decompressed_chunk, + size_t decomp_chunk_size) { + HSD_sink_res sink_res; + HSD_poll_res poll_res; + + /* + First, try to output data from decoder to the output buffer. + If the we could fill the output buffer, return + If the output buffer is not full, keep polling the decoder + until it has no more data to output. + Then, read more data from the input and sink it to the decoder. + Repeat until the input is exhausted or output buffer is full. + */ + + bool failed = false; + bool can_sink_more = true; + bool can_read_more = true; + + do { + do { + size_t poll_size = 0; + poll_res = heatshrink_decoder_poll( + sd->decoder, decompressed_chunk, decomp_chunk_size, &poll_size); + if(poll_res < 0) { + return false; + } + + decomp_chunk_size -= poll_size; + decompressed_chunk += poll_size; + } while((poll_res == HSDR_POLL_MORE) && decomp_chunk_size); + + if(!decomp_chunk_size) { + break; + } + + if(can_read_more && (sd->decode_buffer_position < sd->decode_buffer_size)) { + size_t read_size = read_cb( + read_context, + &sd->decode_buffer[sd->decode_buffer_position], + sd->decode_buffer_size - sd->decode_buffer_position); + sd->decode_buffer_position += read_size; + can_read_more = read_size > 0; + } + + while(sd->decode_buffer_position && can_sink_more) { + size_t sink_size = 0; + sink_res = heatshrink_decoder_sink( + sd->decoder, sd->decode_buffer, sd->decode_buffer_position, &sink_size); + can_sink_more = sink_res == HSDR_SINK_OK; + if(sink_res < 0) { + failed = true; + break; + } + sd->decode_buffer_position -= sink_size; + + /* If some data was left in the buffer, move it to the beginning */ + if(sink_size && sd->decode_buffer_position) { + memmove( + sd->decode_buffer, &sd->decode_buffer[sink_size], sd->decode_buffer_position); + } + } + } while(!failed); + + return decomp_chunk_size == 0; +} + +bool compress_stream_decoder_read( + CompressStreamDecoder* instance, + uint8_t* data_out, + size_t data_out_size) { + furi_check(instance); + furi_check(data_out); + + if(compress_decode_stream_chunk( + instance, instance->read_cb, instance->read_context, data_out, data_out_size)) { + instance->stream_position += data_out_size; + return true; + } + return false; +} + +bool compress_stream_decoder_seek(CompressStreamDecoder* instance, size_t position) { + furi_check(instance); + + /* Check if requested position is ahead of current position + we can't rewind the input stream */ + furi_check(position >= instance->stream_position); + + /* Read and discard data up to requested position */ + uint8_t* dummy_buffer = malloc(instance->decode_buffer_size); + bool success = true; + + while(instance->stream_position < position) { + size_t bytes_to_read = position - instance->stream_position; + if(bytes_to_read > instance->decode_buffer_size) { + bytes_to_read = instance->decode_buffer_size; + } + if(!compress_stream_decoder_read(instance, dummy_buffer, bytes_to_read)) { + success = false; + break; + } + } + + free(dummy_buffer); + return success; +} + +size_t compress_stream_decoder_tell(CompressStreamDecoder* instance) { + furi_check(instance); + return instance->stream_position; +} + +bool compress_stream_decoder_rewind(CompressStreamDecoder* instance) { + furi_check(instance); + + /* Reset decoder and read buffer */ + heatshrink_decoder_reset(instance->decoder); + instance->stream_position = 0; + instance->decode_buffer_position = 0; + + return true; +} diff --git a/lib/toolbox/compress.h b/lib/toolbox/compress.h index f08e1758408..f5862222d0e 100644 --- a/lib/toolbox/compress.h +++ b/lib/toolbox/compress.h @@ -44,17 +44,34 @@ void compress_icon_free(CompressIcon* instance); */ void compress_icon_decode(CompressIcon* instance, const uint8_t* icon_data, uint8_t** output); +////////////////////////////////////////////////////////////////////////// + /** Compress control structure */ typedef struct Compress Compress; +/** Supported compression types */ +typedef enum { + CompressTypeHeatshrink = 0, +} CompressType; + +/** Configuration for heatshrink compression */ +typedef struct { + uint16_t window_sz2; + uint16_t lookahead_sz2; + uint16_t input_buffer_sz; +} CompressConfigHeatshrink; + +/** Default configuration for heatshrink compression. Used for image assets. */ +extern const CompressConfigHeatshrink compress_config_heatshrink_default; + /** Allocate encoder and decoder * - * @param compress_buff_size size of decoder and encoder buffer to - * allocate + * @param type Compression type + * @param[in] config Configuration for compression, specific to type * * @return Compress instance */ -Compress* compress_alloc(uint16_t compress_buff_size); +Compress* compress_alloc(CompressType type, const void* config); /** Free encoder and decoder * @@ -71,6 +88,8 @@ void compress_free(Compress* compress); * @param[in] data_out_size The data out size * @param data_res_size pointer to result output data size * + * @note Prepends compressed stream with a header. If data is not compressible, + * it will be stored as is after the header. * @return true on success */ bool compress_encode( @@ -90,6 +109,7 @@ bool compress_encode( * @param[in] data_out_size The data out size * @param data_res_size pointer to result output data size * + * @note Expects compressed stream with a header, as produced by `compress_encode`. * @return true on success */ bool compress_decode( @@ -100,6 +120,100 @@ bool compress_decode( size_t data_out_size, size_t* data_res_size); +/** I/O callback for streamed compression/decompression + * + * @param context user context + * @param buffer buffer to read/write + * @param size size of buffer + * + * @return number of bytes read/written, 0 on end of stream, negative on error + */ +typedef int32_t (*CompressIoCallback)(void* context, uint8_t* buffer, size_t size); + +/** Decompress streamed data + * + * @param compress Compress instance + * @param read_cb read callback + * @param read_context read callback context + * @param write_cb write callback + * @param write_context write callback context + * + * @note Does not expect a header, just compressed data stream. + * @return true on success + */ +bool compress_decode_streamed( + Compress* compress, + CompressIoCallback read_cb, + void* read_context, + CompressIoCallback write_cb, + void* write_context); + +////////////////////////////////////////////////////////////////////////// + +/** CompressStreamDecoder control structure */ +typedef struct CompressStreamDecoder CompressStreamDecoder; + +/** Allocate stream decoder + * + * @param type Compression type + * @param[in] config Configuration for compression, specific to type + * @param read_cb The read callback for input (compressed) data + * @param read_context The read context + * + * @return CompressStreamDecoder instance + */ +CompressStreamDecoder* compress_stream_decoder_alloc( + CompressType type, + const void* config, + CompressIoCallback read_cb, + void* read_context); + +/** Free stream decoder + * + * @param instance The CompressStreamDecoder instance + */ +void compress_stream_decoder_free(CompressStreamDecoder* instance); + +/** Read uncompressed data chunk from stream decoder + * + * @param instance The CompressStreamDecoder instance + * @param data_out The data out + * @param[in] data_out_size The data out size + * + * @return true on success + */ +bool compress_stream_decoder_read( + CompressStreamDecoder* instance, + uint8_t* data_out, + size_t data_out_size); + +/** Seek to position in uncompressed data stream + * + * @param instance The CompressStreamDecoder instance + * @param[in] position The position + * + * @return true on success + * @warning Backward seeking is not supported + */ +bool compress_stream_decoder_seek(CompressStreamDecoder* instance, size_t position); + +/** Get current position in uncompressed data stream + * + * @param instance The CompressStreamDecoder instance + * + * @return current position + */ +size_t compress_stream_decoder_tell(CompressStreamDecoder* instance); + +/** Reset stream decoder to the beginning + * @warning Read callback must be repositioned by caller separately + * + * @param instance The CompressStreamDecoder instance + * + * @return true on success + */ +bool compress_stream_decoder_rewind(CompressStreamDecoder* instance); + #ifdef __cplusplus } #endif diff --git a/lib/toolbox/dir_walk.h b/lib/toolbox/dir_walk.h index 535237fc6e2..f2d32921f2d 100644 --- a/lib/toolbox/dir_walk.h +++ b/lib/toolbox/dir_walk.h @@ -76,4 +76,4 @@ void dir_walk_close(DirWalk* dir_walk); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/toolbox/hex.c b/lib/toolbox/hex.c index e5cdfff17c1..4b5bd30d389 100644 --- a/lib/toolbox/hex.c +++ b/lib/toolbox/hex.c @@ -4,10 +4,10 @@ bool hex_char_to_hex_nibble(char c, uint8_t* nibble) { furi_check(nibble); - if((c >= '0' && c <= '9')) { + if(c >= '0' && c <= '9') { *nibble = c - '0'; return true; - } else if((c >= 'A' && c <= 'F')) { + } else if(c >= 'A' && c <= 'F') { *nibble = c - 'A' + 10; return true; } else if(c >= 'a' && c <= 'f') { diff --git a/lib/toolbox/keys_dict.c b/lib/toolbox/keys_dict.c index 09fc241eebb..602653e8ffb 100644 --- a/lib/toolbox/keys_dict.c +++ b/lib/toolbox/keys_dict.c @@ -176,7 +176,8 @@ static bool keys_dict_get_next_key_str(KeysDict* instance, FuriString* key) { furi_string_reset(key); - while(!key_read && !is_endfile) key_read = keys_dict_read_key_line(instance, key, &is_endfile); + while(!key_read && !is_endfile) + key_read = keys_dict_read_key_line(instance, key, &is_endfile); return key_read; } diff --git a/lib/toolbox/level_duration.h b/lib/toolbox/level_duration.h index 7618344ac3c..cb50fa3b489 100644 --- a/lib/toolbox/level_duration.h +++ b/lib/toolbox/level_duration.h @@ -6,15 +6,15 @@ #ifdef LEVEL_DURATION_BIG -#define LEVEL_DURATION_RESET 0U -#define LEVEL_DURATION_LEVEL_LOW 1U +#define LEVEL_DURATION_RESET 0U +#define LEVEL_DURATION_LEVEL_LOW 1U #define LEVEL_DURATION_LEVEL_HIGH 2U -#define LEVEL_DURATION_WAIT 3U -#define LEVEL_DURATION_RESERVED 0x800000U +#define LEVEL_DURATION_WAIT 3U +#define LEVEL_DURATION_RESERVED 0x800000U typedef struct { uint32_t duration : 30; - uint8_t level : 2; + uint8_t level : 2; } LevelDuration; static inline LevelDuration level_duration_make(bool level, uint32_t duration) { @@ -54,7 +54,7 @@ static inline uint32_t level_duration_get_duration(LevelDuration level_duration) #else -#define LEVEL_DURATION_RESET 0U +#define LEVEL_DURATION_RESET 0U #define LEVEL_DURATION_RESERVED 0x800000U typedef int32_t LevelDuration; @@ -68,11 +68,11 @@ static inline LevelDuration level_duration_reset() { } static inline bool level_duration_is_reset(LevelDuration level_duration) { - return (level_duration == LEVEL_DURATION_RESET); + return level_duration == LEVEL_DURATION_RESET; } static inline bool level_duration_get_level(LevelDuration level_duration) { - return (level_duration > 0); + return level_duration > 0; } static inline uint32_t level_duration_get_duration(LevelDuration level_duration) { diff --git a/lib/toolbox/m_cstr_dup.h b/lib/toolbox/m_cstr_dup.h index 11b7fe35ada..8cc45dd8566 100644 --- a/lib/toolbox/m_cstr_dup.h +++ b/lib/toolbox/m_cstr_dup.h @@ -1,10 +1,10 @@ #pragma once #include -#define M_INIT_DUP(a) ((a) = strdup("")) +#define M_INIT_DUP(a) ((a) = strdup("")) #define M_INIT_SET_DUP(a, b) ((a) = strdup(b)) -#define M_SET_DUP(a, b) (free((void*)a), (a) = strdup(b)) -#define M_CLEAR_DUP(a) (free((void*)a)) +#define M_SET_DUP(a, b) (free((void*)a), (a) = strdup(b)) +#define M_CLEAR_DUP(a) (free((void*)a)) #define M_CSTR_DUP_OPLIST \ (INIT(M_INIT_DUP), \ diff --git a/lib/toolbox/md5_calc.c b/lib/toolbox/md5_calc.c index 59c9403e812..f70f2361e1e 100644 --- a/lib/toolbox/md5_calc.c +++ b/lib/toolbox/md5_calc.c @@ -55,4 +55,4 @@ bool md5_string_calc_file(File* file, const char* path, FuriString* output, FS_E } return result; -} \ No newline at end of file +} diff --git a/lib/toolbox/name_generator.h b/lib/toolbox/name_generator.h index bc17d54cd57..624533afb4d 100644 --- a/lib/toolbox/name_generator.h +++ b/lib/toolbox/name_generator.h @@ -32,4 +32,4 @@ void name_generator_make_detailed(char* name, size_t max_name_size, const char* #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/toolbox/path.c b/lib/toolbox/path.c index 37bacd65a89..a3fe6847306 100644 --- a/lib/toolbox/path.c +++ b/lib/toolbox/path.c @@ -43,6 +43,7 @@ void path_extract_filename(FuriString* path, FuriString* name, bool trim_ext) { void path_extract_extension(FuriString* path, char* ext, size_t ext_len_max) { furi_check(path); furi_check(ext); + furi_check(ext_len_max > 0); size_t dot = furi_string_search_rchar(path, '.'); size_t filename_start = furi_string_search_rchar(path, '/'); diff --git a/lib/toolbox/pretty_format.h b/lib/toolbox/pretty_format.h index 860528e4cd3..fcd500fc6f4 100644 --- a/lib/toolbox/pretty_format.h +++ b/lib/toolbox/pretty_format.h @@ -6,7 +6,7 @@ extern "C" { #endif -#define PRETTY_FORMAT_FONT_BOLD "\e#" +#define PRETTY_FORMAT_FONT_BOLD "\e#" #define PRETTY_FORMAT_FONT_MONOSPACE "\e*" /** diff --git a/lib/toolbox/profiler.h b/lib/toolbox/profiler.h index 037711a8ff8..4c5d906ba7b 100644 --- a/lib/toolbox/profiler.h +++ b/lib/toolbox/profiler.h @@ -20,4 +20,4 @@ void profiler_dump(Profiler* profiler); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/toolbox/protocols/protocol.h b/lib/toolbox/protocols/protocol.h index 0ee165d13e6..855839dc7f4 100644 --- a/lib/toolbox/protocols/protocol.h +++ b/lib/toolbox/protocols/protocol.h @@ -44,4 +44,4 @@ typedef struct { ProtocolRenderData render_data; ProtocolRenderData render_brief_data; ProtocolWriteData write_data; -} ProtocolBase; \ No newline at end of file +} ProtocolBase; diff --git a/lib/toolbox/protocols/protocol_dict.c b/lib/toolbox/protocols/protocol_dict.c index 71fa4fe2896..5680be18de0 100644 --- a/lib/toolbox/protocols/protocol_dict.c +++ b/lib/toolbox/protocols/protocol_dict.c @@ -4,16 +4,15 @@ struct ProtocolDict { const ProtocolBase** base; size_t count; - void** data; + void* data[]; }; ProtocolDict* protocol_dict_alloc(const ProtocolBase** protocols, size_t count) { furi_check(protocols); - ProtocolDict* dict = malloc(sizeof(ProtocolDict)); + ProtocolDict* dict = malloc(sizeof(ProtocolDict) + (sizeof(void*) * count)); dict->base = protocols; dict->count = count; - dict->data = malloc(sizeof(void*) * dict->count); for(size_t i = 0; i < dict->count; i++) { dict->data[i] = dict->base[i]->alloc(); @@ -29,7 +28,6 @@ void protocol_dict_free(ProtocolDict* dict) { dict->base[i]->free(dict->data[i]); } - free(dict->data); free(dict); } @@ -247,4 +245,4 @@ bool protocol_dict_get_write_data(ProtocolDict* dict, size_t protocol_index, voi furi_check(fn); return fn(dict->data[protocol_index], data); -} \ No newline at end of file +} diff --git a/lib/toolbox/protocols/protocol_dict.h b/lib/toolbox/protocols/protocol_dict.h index dd0711732df..543b3ead2ae 100644 --- a/lib/toolbox/protocols/protocol_dict.h +++ b/lib/toolbox/protocols/protocol_dict.h @@ -9,7 +9,7 @@ typedef struct ProtocolDict ProtocolDict; typedef int32_t ProtocolId; -#define PROTOCOL_NO (-1) +#define PROTOCOL_NO (-1) #define PROTOCOL_ALL_FEATURES (0xFFFFFFFF) ProtocolDict* protocol_dict_alloc(const ProtocolBase** protocols, size_t protocol_count); diff --git a/lib/toolbox/pulse_joiner.c b/lib/toolbox/pulse_joiner.c index dce63b82338..dcacb1f9814 100644 --- a/lib/toolbox/pulse_joiner.c +++ b/lib/toolbox/pulse_joiner.c @@ -114,4 +114,4 @@ void pulse_joiner_pop_pulse(PulseJoiner* pulse_joiner, size_t* period, size_t* p break; } } -} \ No newline at end of file +} diff --git a/lib/toolbox/pulse_joiner.h b/lib/toolbox/pulse_joiner.h index f9597280f15..b4b7d2d9f19 100644 --- a/lib/toolbox/pulse_joiner.h +++ b/lib/toolbox/pulse_joiner.h @@ -43,4 +43,4 @@ void pulse_joiner_pop_pulse(PulseJoiner* pulse_joiner, size_t* period, size_t* p #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/toolbox/stream/stream.c b/lib/toolbox/stream/stream.c index 9aff8bd4fb6..0e4c5fc7a6e 100644 --- a/lib/toolbox/stream/stream.c +++ b/lib/toolbox/stream/stream.c @@ -144,7 +144,7 @@ static bool stream_write_struct(Stream* stream, const void* context) { furi_check(stream); furi_check(context); const StreamWriteData* write_data = context; - return (stream_write(stream, write_data->data, write_data->size) == write_data->size); + return stream_write(stream, write_data->data, write_data->size) == write_data->size; } bool stream_read_line(Stream* stream, FuriString* str_result) { diff --git a/lib/toolbox/stream/string_stream.c b/lib/toolbox/stream/string_stream.c index 742547fb780..7b014391e4f 100644 --- a/lib/toolbox/stream/string_stream.c +++ b/lib/toolbox/stream/string_stream.c @@ -51,7 +51,7 @@ static void string_stream_free(StringStream* stream) { } static bool string_stream_eof(StringStream* stream) { - return (string_stream_tell(stream) >= string_stream_size(stream)); + return string_stream_tell(stream) >= string_stream_size(stream); } static void string_stream_clean(StringStream* stream) { diff --git a/lib/toolbox/tar/tar_archive.c b/lib/toolbox/tar/tar_archive.c index 25084aaa045..80144a0f4f5 100644 --- a/lib/toolbox/tar/tar_archive.c +++ b/lib/toolbox/tar/tar_archive.c @@ -4,22 +4,39 @@ #include #include #include +#include #define TAG "TarArch" -#define MAX_NAME_LEN 255 + +#define MAX_NAME_LEN 255 #define FILE_BLOCK_SIZE 512 -#define FILE_OPEN_NTRIES 10 +#define FILE_OPEN_NTRIES 10 #define FILE_OPEN_RETRY_DELAY 25 +TarOpenMode tar_archive_get_mode_for_path(const char* path) { + char ext[8]; + + FuriString* path_str = furi_string_alloc_set_str(path); + path_extract_extension(path_str, ext, sizeof(ext)); + furi_string_free(path_str); + + if(strcmp(ext, ".ths") == 0) { + return TarOpenModeReadHeatshrink; + } else { + return TarOpenModeRead; + } +} + typedef struct TarArchive { Storage* storage; + File* stream; mtar_t tar; tar_unpack_file_cb unpack_cb; void* unpack_cb_context; } TarArchive; -/* API WRAPPER */ +/* Plain file backend - uncompressed, supports read and write */ static int mtar_storage_file_write(void* stream, const void* data, unsigned size) { uint16_t bytes_written = storage_file_write(stream, data, size); return (bytes_written == size) ? bytes_written : MTAR_EWRITEFAIL; @@ -38,7 +55,6 @@ static int mtar_storage_file_seek(void* stream, unsigned offset) { static int mtar_storage_file_close(void* stream) { if(stream) { storage_file_close(stream); - storage_file_free(stream); } return MTAR_ESUCCESS; } @@ -50,41 +66,132 @@ const struct mtar_ops filesystem_ops = { .close = mtar_storage_file_close, }; +/* Heatshrink stream backend - compressed, read-only */ + +typedef struct { + CompressConfigHeatshrink heatshrink_config; + File* stream; + CompressStreamDecoder* decoder; +} HeatshrinkStream; + +/* HSDS 'heatshrink data stream' header magic */ +static const uint32_t HEATSHRINK_MAGIC = 0x53445348; + +typedef struct { + uint32_t magic; + uint8_t version; + uint8_t window_sz2; + uint8_t lookahead_sz2; +} FURI_PACKED HeatshrinkStreamHeader; +_Static_assert(sizeof(HeatshrinkStreamHeader) == 7, "Invalid HeatshrinkStreamHeader size"); + +static int mtar_heatshrink_file_close(void* stream) { + HeatshrinkStream* hs_stream = stream; + if(hs_stream) { + if(hs_stream->decoder) { + compress_stream_decoder_free(hs_stream->decoder); + } + storage_file_close(hs_stream->stream); + free(hs_stream); + } + return MTAR_ESUCCESS; +} + +static int mtar_heatshrink_file_read(void* stream, void* data, unsigned size) { + HeatshrinkStream* hs_stream = stream; + bool read_success = compress_stream_decoder_read(hs_stream->decoder, data, size); + return read_success ? (int)size : MTAR_EREADFAIL; +} + +static int mtar_heatshrink_file_seek(void* stream, unsigned offset) { + HeatshrinkStream* hs_stream = stream; + bool success = false; + if(offset == 0) { + success = storage_file_seek(hs_stream->stream, sizeof(HeatshrinkStreamHeader), true) && + compress_stream_decoder_rewind(hs_stream->decoder); + } else { + success = compress_stream_decoder_seek(hs_stream->decoder, offset); + } + return success ? MTAR_ESUCCESS : MTAR_ESEEKFAIL; +} + +const struct mtar_ops heatshrink_ops = { + .read = mtar_heatshrink_file_read, + .write = NULL, // not supported + .seek = mtar_heatshrink_file_seek, + .close = mtar_heatshrink_file_close, +}; + +////////////////////////////////////////////////////////////////////////// + TarArchive* tar_archive_alloc(Storage* storage) { furi_check(storage); TarArchive* archive = malloc(sizeof(TarArchive)); archive->storage = storage; + archive->stream = storage_file_alloc(archive->storage); archive->unpack_cb = NULL; return archive; } +static int32_t file_read_cb(void* context, uint8_t* buffer, size_t buffer_size) { + File* file = context; + return storage_file_read(file, buffer, buffer_size); +} + bool tar_archive_open(TarArchive* archive, const char* path, TarOpenMode mode) { furi_check(archive); FS_AccessMode access_mode; FS_OpenMode open_mode; + bool compressed = false; int mtar_access = 0; switch(mode) { - case TAR_OPEN_MODE_READ: + case TarOpenModeRead: mtar_access = MTAR_READ; access_mode = FSAM_READ; open_mode = FSOM_OPEN_EXISTING; break; - case TAR_OPEN_MODE_WRITE: + case TarOpenModeWrite: mtar_access = MTAR_WRITE; access_mode = FSAM_WRITE; open_mode = FSOM_CREATE_ALWAYS; break; + case TarOpenModeReadHeatshrink: + mtar_access = MTAR_READ; + access_mode = FSAM_READ; + open_mode = FSOM_OPEN_EXISTING; + compressed = true; + break; default: return false; } - File* stream = storage_file_alloc(archive->storage); + File* stream = archive->stream; if(!storage_file_open(stream, path, access_mode, open_mode)) { - storage_file_free(stream); return false; } - mtar_init(&archive->tar, mtar_access, &filesystem_ops, stream); + + if(compressed) { + /* Read and validate stream header */ + HeatshrinkStreamHeader header; + if(storage_file_read(stream, &header, sizeof(HeatshrinkStreamHeader)) != + sizeof(HeatshrinkStreamHeader) || + header.magic != HEATSHRINK_MAGIC) { + storage_file_close(stream); + return false; + } + + HeatshrinkStream* hs_stream = malloc(sizeof(HeatshrinkStream)); + hs_stream->stream = stream; + hs_stream->heatshrink_config.window_sz2 = header.window_sz2; + hs_stream->heatshrink_config.lookahead_sz2 = header.lookahead_sz2; + hs_stream->heatshrink_config.input_buffer_sz = FILE_BLOCK_SIZE; + hs_stream->decoder = compress_stream_decoder_alloc( + CompressTypeHeatshrink, &hs_stream->heatshrink_config, file_read_cb, stream); + mtar_init(&archive->tar, mtar_access, &heatshrink_ops, hs_stream); + } else { + mtar_init(&archive->tar, mtar_access, &filesystem_ops, stream); + } return true; } @@ -94,6 +201,7 @@ void tar_archive_free(TarArchive* archive) { if(mtar_is_open(&archive->tar)) { mtar_close(&archive->tar); } + storage_file_free(archive->stream); free(archive); } @@ -121,14 +229,29 @@ int32_t tar_archive_get_entries_count(TarArchive* archive) { return counter; } +bool tar_archive_get_read_progress(TarArchive* archive, int32_t* processed, int32_t* total) { + furi_check(archive); + if(mtar_access_mode(&archive->tar) != MTAR_READ) { + return false; + } + + if(processed) { + *processed = storage_file_tell(archive->stream); + } + if(total) { + *total = storage_file_size(archive->stream); + } + return true; +} + bool tar_archive_dir_add_element(TarArchive* archive, const char* dirpath) { furi_check(archive); - return (mtar_write_dir_header(&archive->tar, dirpath) == MTAR_ESUCCESS); + return mtar_write_dir_header(&archive->tar, dirpath) == MTAR_ESUCCESS; } bool tar_archive_finalize(TarArchive* archive) { furi_check(archive); - return (mtar_finalize(&archive->tar) == MTAR_ESUCCESS); + return mtar_finalize(&archive->tar) == MTAR_ESUCCESS; } bool tar_archive_store_data( @@ -138,16 +261,15 @@ bool tar_archive_store_data( const int32_t data_len) { furi_check(archive); - return ( - tar_archive_file_add_header(archive, path, data_len) && - tar_archive_file_add_data_block(archive, data, data_len) && - tar_archive_file_finalize(archive)); + return tar_archive_file_add_header(archive, path, data_len) && + tar_archive_file_add_data_block(archive, data, data_len) && + tar_archive_file_finalize(archive); } bool tar_archive_file_add_header(TarArchive* archive, const char* path, const int32_t data_len) { furi_check(archive); - return (mtar_write_file_header(&archive->tar, path, data_len) == MTAR_ESUCCESS); + return mtar_write_file_header(&archive->tar, path, data_len) == MTAR_ESUCCESS; } bool tar_archive_file_add_data_block( @@ -156,12 +278,12 @@ bool tar_archive_file_add_data_block( const int32_t block_len) { furi_check(archive); - return (mtar_write_data(&archive->tar, data_block, block_len) == block_len); + return mtar_write_data(&archive->tar, data_block, block_len) == block_len; } bool tar_archive_file_finalize(TarArchive* archive) { furi_check(archive); - return (mtar_end_data(&archive->tar) == MTAR_ESUCCESS); + return mtar_end_data(&archive->tar) == MTAR_ESUCCESS; } typedef struct { @@ -258,7 +380,7 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header, furi_string_free(converted_fname); furi_string_free(full_extracted_fname); - return success ? 0 : -1; + return success ? 0 : MTAR_EFAILURE; } bool tar_archive_unpack_to( @@ -274,8 +396,8 @@ bool tar_archive_unpack_to( FURI_LOG_I(TAG, "Restoring '%s'", destination); - return (mtar_foreach(&archive->tar, archive_extract_foreach_cb, ¶m) == MTAR_ESUCCESS); -}; + return mtar_foreach(&archive->tar, archive_extract_foreach_cb, ¶m) == MTAR_ESUCCESS; +} bool tar_archive_add_file( TarArchive* archive, diff --git a/lib/toolbox/tar/tar_archive.h b/lib/toolbox/tar/tar_archive.h index ba2f7749f09..3eb97391e8d 100644 --- a/lib/toolbox/tar/tar_archive.h +++ b/lib/toolbox/tar/tar_archive.h @@ -12,62 +12,197 @@ typedef struct TarArchive TarArchive; typedef struct Storage Storage; +/** Tar archive open mode + */ typedef enum { - TAR_OPEN_MODE_READ = 'r', - TAR_OPEN_MODE_WRITE = 'w', - TAR_OPEN_MODE_STDOUT = 's' /* to be implemented */ + TarOpenModeRead = 'r', + TarOpenModeWrite = 'w', + /* read-only heatshrink compressed tar */ + TarOpenModeReadHeatshrink = 'h', } TarOpenMode; +/** Get expected open mode for archive at the path. + * Used for automatic mode detection based on the file extension. + * + * @param[in] path Path to the archive + * + * @return open mode from TarOpenMode enum + */ +TarOpenMode tar_archive_get_mode_for_path(const char* path); + +/** Tar archive constructor + * + * @param storage Storage API pointer + * + * @return allocated object + */ TarArchive* tar_archive_alloc(Storage* storage); +/** Open tar archive + * + * @param archive Tar archive object + * @param[in] path Path to the tar archive + * @param mode Open mode + * + * @return true if successful + */ bool tar_archive_open(TarArchive* archive, const char* path, TarOpenMode mode); +/** Tar archive destructor + * + * @param archive Tar archive object + */ void tar_archive_free(TarArchive* archive); /* High-level API - assumes archive is open */ + +/** Unpack tar archive to destination + * + * @param archive Tar archive object. Must be opened in read mode + * @param[in] destination Destination path + * @param converter Storage name converter + * + * @return true if successful + */ bool tar_archive_unpack_to( TarArchive* archive, const char* destination, Storage_name_converter converter); +/** Add file to tar archive + * + * @param archive Tar archive object. Must be opened in write mode + * @param[in] fs_file_path Path to the file on the filesystem + * @param[in] archive_fname Name of the file in the archive + * @param file_size Size of the file + * + * @return true if successful + */ bool tar_archive_add_file( TarArchive* archive, const char* fs_file_path, const char* archive_fname, const int32_t file_size); +/** Add directory to tar archive + * + * @param archive Tar archive object. Must be opened in write mode + * @param fs_full_path Path to the directory on the filesystem + * @param path_prefix Prefix to add to the directory name in the archive + * + * @return true if successful + */ bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const char* path_prefix); +/** Get number of entries in the archive + * + * @param archive Tar archive object + * + * @return number of entries. -1 on error + */ int32_t tar_archive_get_entries_count(TarArchive* archive); +/** Get read progress + * + * @param archive Tar archive object. Must be opened in read mode + * @param[in] processed Number of processed entries + * @param[in] total Total number of entries + * + * @return true if successful + */ +bool tar_archive_get_read_progress(TarArchive* archive, int32_t* processed, int32_t* total); + +/** Unpack single file from tar archive + * + * @param archive Tar archive object. Must be opened in read mode + * @param[in] archive_fname Name of the file in the archive + * @param[in] destination Destination path + * + * @return true if successful + */ bool tar_archive_unpack_file( TarArchive* archive, const char* archive_fname, const char* destination); -/* Optional per-entry callback on unpacking - return false to skip entry */ +/** Optional per-entry callback on unpacking + * @param name Name of the file or directory + * @param is_directory True if the entry is a directory + * @param[in] context User context + * @return true to process the entry, false to skip + */ typedef bool (*tar_unpack_file_cb)(const char* name, bool is_directory, void* context); +/** Set per-entry callback on unpacking + * @param archive Tar archive object + * @param callback Callback function + * @param[in] context User context + */ void tar_archive_set_file_callback(TarArchive* archive, tar_unpack_file_cb callback, void* context); /* Low-level API */ + +/** Add tar archive directory header + * + * @param archive Tar archive object. Must be opened in write mode + * @param[in] dirpath Path to the directory + * + * @return true if successful + */ bool tar_archive_dir_add_element(TarArchive* archive, const char* dirpath); +/** Add tar archive file header + * + * @param archive Tar archive object. Must be opened in write mode + * @param[in] path Path to the file + * @param data_len Size of the file + * + * @return true if successful + */ bool tar_archive_file_add_header(TarArchive* archive, const char* path, const int32_t data_len); +/** Add tar archive file data block + * + * @param archive Tar archive object. Must be opened in write mode + * @param[in] data_block Data block + * @param block_len Size of the data block + * + * @return true if successful + */ bool tar_archive_file_add_data_block( TarArchive* archive, const uint8_t* data_block, const int32_t block_len); +/** Finalize tar archive file + * + * @param archive Tar archive object. Must be opened in write mode + * + * @return true if successful + */ bool tar_archive_file_finalize(TarArchive* archive); +/** Store data in tar archive + * + * @param archive Tar archive object. Must be opened in write mode + * @param[in] path Path to the file + * @param[in] data Data to store + * @param data_len Size of the data + * + * @return true if successful + */ bool tar_archive_store_data( TarArchive* archive, const char* path, const uint8_t* data, const int32_t data_len); +/** Finalize tar archive + * + * @param archive Tar archive object. Must be opened in write mode + * + * @return true if successful + */ bool tar_archive_finalize(TarArchive* archive); #ifdef __cplusplus diff --git a/lib/toolbox/varint.h b/lib/toolbox/varint.h index bf4681d4dcb..997c4d9d8bc 100644 --- a/lib/toolbox/varint.h +++ b/lib/toolbox/varint.h @@ -32,4 +32,4 @@ size_t varint_int32_length(int32_t value); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/u8g2/u8g2.h b/lib/u8g2/u8g2.h index 540b7a87381..c37f3b93127 100644 --- a/lib/u8g2/u8g2.h +++ b/lib/u8g2/u8g2.h @@ -348,7 +348,7 @@ struct u8g2_struct { //#define u8g2_GetU8x8(u8g2) (&((u8g2)->u8x8)) #ifdef U8X8_WITH_USER_PTR -#define u8g2_GetUserPtr(u8g2) ((u8g2_GetU8x8(u8g2))->user_ptr) +#define u8g2_GetUserPtr(u8g2) ((u8g2_GetU8x8(u8g2))->user_ptr) #define u8g2_SetUserPtr(u8g2, p) ((u8g2_GetU8x8(u8g2))->user_ptr = (p)) #endif @@ -361,27 +361,27 @@ struct u8g2_struct { #define u8g2_SetupDisplay(u8g2, display_cb, cad_cb, byte_cb, gpio_and_delay_cb) \ u8x8_Setup(u8g2_GetU8x8(u8g2), (display_cb), (cad_cb), (byte_cb), (gpio_and_delay_cb)) -#define u8g2_InitDisplay(u8g2) u8x8_InitDisplay(u8g2_GetU8x8(u8g2)) +#define u8g2_InitDisplay(u8g2) u8x8_InitDisplay(u8g2_GetU8x8(u8g2)) #define u8g2_SetPowerSave(u8g2, is_enable) u8x8_SetPowerSave(u8g2_GetU8x8(u8g2), (is_enable)) -#define u8g2_SetFlipMode(u8g2, mode) u8x8_SetFlipMode(u8g2_GetU8x8(u8g2), (mode)) -#define u8g2_SetContrast(u8g2, value) u8x8_SetContrast(u8g2_GetU8x8(u8g2), (value)) +#define u8g2_SetFlipMode(u8g2, mode) u8x8_SetFlipMode(u8g2_GetU8x8(u8g2), (mode)) +#define u8g2_SetContrast(u8g2, value) u8x8_SetContrast(u8g2_GetU8x8(u8g2), (value)) //#define u8g2_ClearDisplay(u8g2) u8x8_ClearDisplay(u8g2_GetU8x8(u8g2)) obsolete, can not be used in all cases void u8g2_ClearDisplay(u8g2_t* u8g2); #define u8g2_GetDisplayHeight(u8g2) ((u8g2)->height) -#define u8g2_GetDisplayWidth(u8g2) ((u8g2)->width) -#define u8g2_GetDrawColor(u8g2) ((u8g2)->draw_color) +#define u8g2_GetDisplayWidth(u8g2) ((u8g2)->width) +#define u8g2_GetDrawColor(u8g2) ((u8g2)->draw_color) #define u8g2_SetI2CAddress(u8g2, address) ((u8g2_GetU8x8(u8g2))->i2c_address = (address)) -#define u8g2_GetI2CAddress(u8g2) u8x8_GetI2CAddress(u8g2_GetU8x8(u8g2)) +#define u8g2_GetI2CAddress(u8g2) u8x8_GetI2CAddress(u8g2_GetU8x8(u8g2)) #ifdef U8X8_USE_PINS #define u8g2_SetMenuSelectPin(u8g2, val) u8x8_SetMenuSelectPin(u8g2_GetU8x8(u8g2), (val)) -#define u8g2_SetMenuNextPin(u8g2, val) u8x8_SetMenuNextPin(u8g2_GetU8x8(u8g2), (val)) -#define u8g2_SetMenuPrevPin(u8g2, val) u8x8_SetMenuPrevPin(u8g2_GetU8x8(u8g2), (val)) -#define u8g2_SetMenuHomePin(u8g2, val) u8x8_SetMenuHomePin(u8g2_GetU8x8(u8g2), (val)) -#define u8g2_SetMenuUpPin(u8g2, val) u8x8_SetMenuUpPin(u8g2_GetU8x8(u8g2), (val)) -#define u8g2_SetMenuDownPin(u8g2, val) u8x8_SetMenuDownPin(u8g2_GetU8x8(u8g2), (val)) +#define u8g2_SetMenuNextPin(u8g2, val) u8x8_SetMenuNextPin(u8g2_GetU8x8(u8g2), (val)) +#define u8g2_SetMenuPrevPin(u8g2, val) u8x8_SetMenuPrevPin(u8g2_GetU8x8(u8g2), (val)) +#define u8g2_SetMenuHomePin(u8g2, val) u8x8_SetMenuHomePin(u8g2_GetU8x8(u8g2), (val)) +#define u8g2_SetMenuUpPin(u8g2, val) u8x8_SetMenuUpPin(u8g2_GetU8x8(u8g2), (val)) +#define u8g2_SetMenuDownPin(u8g2, val) u8x8_SetMenuDownPin(u8g2_GetU8x8(u8g2), (val)) #endif /*==========================================*/ @@ -395,10 +395,10 @@ extern const u8g2_cb_t u8g2_cb_r2; extern const u8g2_cb_t u8g2_cb_r3; extern const u8g2_cb_t u8g2_cb_mirror; -#define U8G2_R0 (&u8g2_cb_r0) -#define U8G2_R1 (&u8g2_cb_r1) -#define U8G2_R2 (&u8g2_cb_r2) -#define U8G2_R3 (&u8g2_cb_r3) +#define U8G2_R0 (&u8g2_cb_r0) +#define U8G2_R1 (&u8g2_cb_r1) +#define U8G2_R2 (&u8g2_cb_r2) +#define U8G2_R3 (&u8g2_cb_r3) #define U8G2_MIRROR (&u8g2_cb_mirror) /* u8g2: A new, not yet initialized u8g2 memory areay @@ -3559,12 +3559,12 @@ uint8_t u8g2_NextPage(u8g2_t* u8g2); #define u8g2_GetBufferSize(u8g2) \ ((u8g2)->u8x8.display_info->tile_width * 8 * (u8g2)->tile_buf_height) #endif -#define u8g2_GetBufferPtr(u8g2) ((u8g2)->tile_buf_ptr) -#define u8g2_GetBufferTileHeight(u8g2) ((u8g2)->tile_buf_height) -#define u8g2_GetBufferTileWidth(u8g2) (u8g2_GetU8x8(u8g2)->display_info->tile_width) +#define u8g2_GetBufferPtr(u8g2) ((u8g2)->tile_buf_ptr) +#define u8g2_GetBufferTileHeight(u8g2) ((u8g2)->tile_buf_height) +#define u8g2_GetBufferTileWidth(u8g2) (u8g2_GetU8x8(u8g2)->display_info->tile_width) /* the following variable is only valid after calling u8g2_FirstPage */ /* renamed from Page to Buffer: the CurrTileRow is the current row of the buffer, issue #370 */ -#define u8g2_GetPageCurrTileRow(u8g2) ((u8g2)->tile_curr_row) +#define u8g2_GetPageCurrTileRow(u8g2) ((u8g2)->tile_curr_row) #define u8g2_GetBufferCurrTileRow(u8g2) ((u8g2)->tile_curr_row) void u8g2_UpdateDisplayArea(u8g2_t* u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th); @@ -3660,8 +3660,8 @@ uint8_t u8g2_IsIntersection( /*==========================================*/ /* u8g2_circle.c */ #define U8G2_DRAW_UPPER_RIGHT 0x01 -#define U8G2_DRAW_UPPER_LEFT 0x02 -#define U8G2_DRAW_LOWER_LEFT 0x04 +#define U8G2_DRAW_UPPER_LEFT 0x02 +#define U8G2_DRAW_LOWER_LEFT 0x04 #define U8G2_DRAW_LOWER_RIGHT 0x08 #define U8G2_DRAW_ALL \ (U8G2_DRAW_UPPER_RIGHT | U8G2_DRAW_UPPER_LEFT | U8G2_DRAW_LOWER_RIGHT | U8G2_DRAW_LOWER_LEFT) @@ -3733,9 +3733,9 @@ u8g2_uint_t u8g2_add_vector_x(u8g2_uint_t dx, int8_t x, int8_t y, uint8_t dir) U size_t u8g2_GetFontSize(const uint8_t* font_arg); -#define U8G2_FONT_HEIGHT_MODE_TEXT 0 +#define U8G2_FONT_HEIGHT_MODE_TEXT 0 #define U8G2_FONT_HEIGHT_MODE_XTEXT 1 -#define U8G2_FONT_HEIGHT_MODE_ALL 2 +#define U8G2_FONT_HEIGHT_MODE_ALL 2 void u8g2_SetFont(u8g2_t* u8g2, const uint8_t* font); void u8g2_SetFontMode(u8g2_t* u8g2, uint8_t is_transparent); @@ -3764,11 +3764,11 @@ u8g2_uint_t u8g2_DrawExtUTF8( const char* str); #define u8g2_GetMaxCharHeight(u8g2) ((u8g2)->font_info.max_char_height) -#define u8g2_GetMaxCharWidth(u8g2) ((u8g2)->font_info.max_char_width) -#define u8g2_GetAscent(u8g2) ((u8g2)->font_ref_ascent) -#define u8g2_GetDescent(u8g2) ((u8g2)->font_ref_descent) -#define u8g2_GetFontAscent(u8g2) ((u8g2)->font_ref_ascent) -#define u8g2_GetFontDescent(u8g2) ((u8g2)->font_ref_descent) +#define u8g2_GetMaxCharWidth(u8g2) ((u8g2)->font_info.max_char_width) +#define u8g2_GetAscent(u8g2) ((u8g2)->font_ref_ascent) +#define u8g2_GetDescent(u8g2) ((u8g2)->font_ref_descent) +#define u8g2_GetFontAscent(u8g2) ((u8g2)->font_ref_ascent) +#define u8g2_GetFontDescent(u8g2) ((u8g2)->font_ref_descent) uint8_t u8g2_IsAllValidUTF8(u8g2_t* u8g2, const char* str); // checks whether all codes are valid @@ -3859,7 +3859,7 @@ void u8g2_SetupBuffer_Utf8(u8g2_t* u8g2, const u8g2_cb_t* u8g2_cb); /*==========================================*/ /* itoa procedures */ -#define u8g2_u8toa u8x8_u8toa +#define u8g2_u8toa u8x8_u8toa #define u8g2_u16toa u8x8_u16toa /*==========================================*/ @@ -5818,197 +5818,197 @@ extern const uint8_t u8g2_font_px437wyse700b_mn[] U8G2_FONT_SECTION("u8g2_font_p /*==========================================*/ /* u8g font mapping, might be incomplete.... */ -#define u8g_font_10x20 u8g2_font_10x20_tf -#define u8g_font_10x20r u8g2_font_10x20_tr -#define u8g_font_4x6 u8g2_font_4x6_tf -#define u8g_font_4x6r u8g2_font_4x6_tr -#define u8g_font_5x7 u8g2_font_5x7_tf -#define u8g_font_5x7r u8g2_font_5x7_tr -#define u8g_font_5x8 u8g2_font_5x8_tf -#define u8g_font_5x8r u8g2_font_5x8_tr -#define u8g_font_6x10 u8g2_font_6x10_tf -#define u8g_font_6x10r u8g2_font_6x10_tr -#define u8g_font_6x12 u8g2_font_6x12_tf -#define u8g_font_6x12r u8g2_font_6x12_tr -#define u8g_font_6x13B u8g2_font_6x13B_tf -#define u8g_font_6x13Br u8g2_font_6x13B_tr -#define u8g_font_6x13 u8g2_font_6x13_tf -#define u8g_font_6x13r u8g2_font_6x13_tr -#define u8g_font_6x13O u8g2_font_6x13O_tf -#define u8g_font_6x13Or u8g2_font_6x13O_tr -#define u8g_font_7x13B u8g2_font_7x13B_tf -#define u8g_font_7x13Br u8g2_font_7x13B_tr -#define u8g_font_7x13 u8g2_font_7x13_tf -#define u8g_font_7x13r u8g2_font_7x13_tr -#define u8g_font_7x13O u8g2_font_7x13O_tf -#define u8g_font_7x13Or u8g2_font_7x13O_tr -#define u8g_font_7x14B u8g2_font_7x14B_tf -#define u8g_font_7x14Br u8g2_font_7x14B_tr -#define u8g_font_7x14 u8g2_font_7x14_tf -#define u8g_font_7x14r u8g2_font_7x14_tr -#define u8g_font_8x13B u8g2_font_8x13B_tf -#define u8g_font_8x13Br u8g2_font_8x13B_tr -#define u8g_font_8x13 u8g2_font_8x13_tf -#define u8g_font_8x13r u8g2_font_8x13_tr -#define u8g_font_8x13O u8g2_font_8x13O_tf -#define u8g_font_8x13Or u8g2_font_8x13O_tr -#define u8g_font_9x15B u8g2_font_9x15B_tf -#define u8g_font_9x15Br u8g2_font_9x15B_tr -#define u8g_font_9x15 u8g2_font_9x15_tf -#define u8g_font_9x15r u8g2_font_9x15_tr -#define u8g_font_9x18B u8g2_font_9x18B_tf -#define u8g_font_9x18 u8g2_font_9x18_tf -#define u8g_font_9x18Br u8g2_font_9x18B_tr -#define u8g_font_9x18r u8g2_font_9x18_tr -#define u8g_font_cu12 u8g2_font_cu12_tf -#define u8g_font_micro u8g2_font_micro_tf -#define u8g_font_unifont u8g2_font_unifont_t_latin -#define u8g_font_unifontr u8g2_font_unifont_t_latin -#define u8g_font_courB08 u8g2_font_courB08_tf -#define u8g_font_courB08r u8g2_font_courB08_tr -#define u8g_font_courB10 u8g2_font_courB10_tf -#define u8g_font_courB10r u8g2_font_courB10_tr -#define u8g_font_courB12 u8g2_font_courB12_tf -#define u8g_font_courB12r u8g2_font_courB12_tr -#define u8g_font_courB14 u8g2_font_courB14_tf -#define u8g_font_courB14r u8g2_font_courB14_tr -#define u8g_font_courB18 u8g2_font_courB18_tf -#define u8g_font_courB18r u8g2_font_courB18_tr -#define u8g_font_courB24 u8g2_font_courB24_tf -#define u8g_font_courB24r u8g2_font_courB24_tr -#define u8g_font_courB24n u8g2_font_courB24_tn -#define u8g_font_courR08 u8g2_font_courR08_tf -#define u8g_font_courR08r u8g2_font_courR08_tr -#define u8g_font_courR10 u8g2_font_courR10_tf -#define u8g_font_courR10r u8g2_font_courR10_tr -#define u8g_font_courR12 u8g2_font_courR12_tf -#define u8g_font_courR12r u8g2_font_courR12_tr -#define u8g_font_courR14 u8g2_font_courR14_tf -#define u8g_font_courR14r u8g2_font_courR14_tr -#define u8g_font_courR18 u8g2_font_courR18_tf -#define u8g_font_courR18r u8g2_font_courR18_tr -#define u8g_font_courR24 u8g2_font_courR24_tf -#define u8g_font_courR24r u8g2_font_courR24_tr -#define u8g_font_courR24n u8g2_font_courR24_tn -#define u8g_font_helvB08 u8g2_font_helvB08_tf -#define u8g_font_helvB08r u8g2_font_helvB08_tr -#define u8g_font_helvB08n u8g2_font_helvB08_tn -#define u8g_font_helvB10 u8g2_font_helvB10_tf -#define u8g_font_helvB10r u8g2_font_helvB10_tr -#define u8g_font_helvB10n u8g2_font_helvB10_tn -#define u8g_font_helvB12 u8g2_font_helvB12_tf -#define u8g_font_helvB12r u8g2_font_helvB12_tr -#define u8g_font_helvB12n u8g2_font_helvB12_tn -#define u8g_font_helvB14 u8g2_font_helvB14_tf -#define u8g_font_helvB14r u8g2_font_helvB14_tr -#define u8g_font_helvB14n u8g2_font_helvB14_tn -#define u8g_font_helvB18 u8g2_font_helvB18_tf -#define u8g_font_helvB18r u8g2_font_helvB18_tr -#define u8g_font_helvB18n u8g2_font_helvB18_tn -#define u8g_font_helvB24 u8g2_font_helvB24_tf -#define u8g_font_helvB24r u8g2_font_helvB24_tr -#define u8g_font_helvB24n u8g2_font_helvB24_tn -#define u8g_font_helvR08 u8g2_font_helvR08_tf -#define u8g_font_helvR08r u8g2_font_helvR08_tr -#define u8g_font_helvR08n u8g2_font_helvR08_tn -#define u8g_font_helvR10 u8g2_font_helvR10_tf -#define u8g_font_helvR10r u8g2_font_helvR10_tr -#define u8g_font_helvR10n u8g2_font_helvR10_tn -#define u8g_font_helvR12 u8g2_font_helvR12_tf -#define u8g_font_helvR12r u8g2_font_helvR12_tr -#define u8g_font_helvR12n u8g2_font_helvR12_tn -#define u8g_font_helvR14 u8g2_font_helvR14_tf -#define u8g_font_helvR14r u8g2_font_helvR14_tr -#define u8g_font_helvR14n u8g2_font_helvR14_tn -#define u8g_font_helvR18 u8g2_font_helvR18_tf -#define u8g_font_helvR18r u8g2_font_helvR18_tr -#define u8g_font_helvR18n u8g2_font_helvR18_tn -#define u8g_font_helvR24 u8g2_font_helvR24_tf -#define u8g_font_helvR24r u8g2_font_helvR24_tr -#define u8g_font_helvR24n u8g2_font_helvR24_tn -#define u8g_font_ncenB08 u8g2_font_ncenB08_tf -#define u8g_font_ncenB08r u8g2_font_ncenB08_tr -#define u8g_font_ncenB10 u8g2_font_ncenB10_tf -#define u8g_font_ncenB10r u8g2_font_ncenB10_tr -#define u8g_font_ncenB12 u8g2_font_ncenB12_tf -#define u8g_font_ncenB12r u8g2_font_ncenB12_tr -#define u8g_font_ncenB14 u8g2_font_ncenB14_tf -#define u8g_font_ncenB14r u8g2_font_ncenB14_tr -#define u8g_font_ncenB18 u8g2_font_ncenB18_tf -#define u8g_font_ncenB18r u8g2_font_ncenB18_tr -#define u8g_font_ncenB24 u8g2_font_ncenB24_tf -#define u8g_font_ncenB24r u8g2_font_ncenB24_tr -#define u8g_font_ncenB24n u8g2_font_ncenB24_tn -#define u8g_font_ncenR08 u8g2_font_ncenR08_tf -#define u8g_font_ncenR08r u8g2_font_ncenR08_tr -#define u8g_font_ncenR10 u8g2_font_ncenR10_tf -#define u8g_font_ncenR10r u8g2_font_ncenR10_tr -#define u8g_font_ncenR12 u8g2_font_ncenR12_tf -#define u8g_font_ncenR12r u8g2_font_ncenR12_tr -#define u8g_font_ncenR14 u8g2_font_ncenR14_tf -#define u8g_font_ncenR14r u8g2_font_ncenR14_tr -#define u8g_font_ncenR18 u8g2_font_ncenR18_tf -#define u8g_font_ncenR18r u8g2_font_ncenR18_tr -#define u8g_font_ncenR24 u8g2_font_ncenR24_tf -#define u8g_font_ncenR24r u8g2_font_ncenR24_tr -#define u8g_font_ncenR24n u8g2_font_ncenR24_tn -#define u8g_font_timB08 u8g2_font_timB08_tf -#define u8g_font_timB08r u8g2_font_timB08_tr -#define u8g_font_timB10 u8g2_font_timB10_tf -#define u8g_font_timB10r u8g2_font_timB10_tr -#define u8g_font_timB12 u8g2_font_timB12_tf -#define u8g_font_timB12r u8g2_font_timB12_tr -#define u8g_font_timB14 u8g2_font_timB14_tf -#define u8g_font_timB14r u8g2_font_timB14_tr -#define u8g_font_timB18 u8g2_font_timB18_tf -#define u8g_font_timB18r u8g2_font_timB18_tr -#define u8g_font_timB24 u8g2_font_timB24_tf -#define u8g_font_timB24r u8g2_font_timB24_tr -#define u8g_font_timB24n u8g2_font_timB24_tn -#define u8g_font_timR08 u8g2_font_timR08_tf -#define u8g_font_timR08r u8g2_font_timR08_tr -#define u8g_font_timR10 u8g2_font_timR10_tf -#define u8g_font_timR10r u8g2_font_timR10_tr -#define u8g_font_timR12 u8g2_font_timR12_tf -#define u8g_font_timR12r u8g2_font_timR12_tr -#define u8g_font_timR14 u8g2_font_timR14_tf -#define u8g_font_timR14r u8g2_font_timR14_tr -#define u8g_font_timR18 u8g2_font_timR18_tf -#define u8g_font_timR18r u8g2_font_timR18_tr -#define u8g_font_timR24 u8g2_font_timR24_tf -#define u8g_font_timR24r u8g2_font_timR24_tr -#define u8g_font_timR24n u8g2_font_timR24_tn -#define u8g_font_p01type u8g2_font_p01type_tf -#define u8g_font_p01typer u8g2_font_p01type_tr -#define u8g_font_lucasfont_alternate u8g2_font_lucasfont_alternate_tf +#define u8g_font_10x20 u8g2_font_10x20_tf +#define u8g_font_10x20r u8g2_font_10x20_tr +#define u8g_font_4x6 u8g2_font_4x6_tf +#define u8g_font_4x6r u8g2_font_4x6_tr +#define u8g_font_5x7 u8g2_font_5x7_tf +#define u8g_font_5x7r u8g2_font_5x7_tr +#define u8g_font_5x8 u8g2_font_5x8_tf +#define u8g_font_5x8r u8g2_font_5x8_tr +#define u8g_font_6x10 u8g2_font_6x10_tf +#define u8g_font_6x10r u8g2_font_6x10_tr +#define u8g_font_6x12 u8g2_font_6x12_tf +#define u8g_font_6x12r u8g2_font_6x12_tr +#define u8g_font_6x13B u8g2_font_6x13B_tf +#define u8g_font_6x13Br u8g2_font_6x13B_tr +#define u8g_font_6x13 u8g2_font_6x13_tf +#define u8g_font_6x13r u8g2_font_6x13_tr +#define u8g_font_6x13O u8g2_font_6x13O_tf +#define u8g_font_6x13Or u8g2_font_6x13O_tr +#define u8g_font_7x13B u8g2_font_7x13B_tf +#define u8g_font_7x13Br u8g2_font_7x13B_tr +#define u8g_font_7x13 u8g2_font_7x13_tf +#define u8g_font_7x13r u8g2_font_7x13_tr +#define u8g_font_7x13O u8g2_font_7x13O_tf +#define u8g_font_7x13Or u8g2_font_7x13O_tr +#define u8g_font_7x14B u8g2_font_7x14B_tf +#define u8g_font_7x14Br u8g2_font_7x14B_tr +#define u8g_font_7x14 u8g2_font_7x14_tf +#define u8g_font_7x14r u8g2_font_7x14_tr +#define u8g_font_8x13B u8g2_font_8x13B_tf +#define u8g_font_8x13Br u8g2_font_8x13B_tr +#define u8g_font_8x13 u8g2_font_8x13_tf +#define u8g_font_8x13r u8g2_font_8x13_tr +#define u8g_font_8x13O u8g2_font_8x13O_tf +#define u8g_font_8x13Or u8g2_font_8x13O_tr +#define u8g_font_9x15B u8g2_font_9x15B_tf +#define u8g_font_9x15Br u8g2_font_9x15B_tr +#define u8g_font_9x15 u8g2_font_9x15_tf +#define u8g_font_9x15r u8g2_font_9x15_tr +#define u8g_font_9x18B u8g2_font_9x18B_tf +#define u8g_font_9x18 u8g2_font_9x18_tf +#define u8g_font_9x18Br u8g2_font_9x18B_tr +#define u8g_font_9x18r u8g2_font_9x18_tr +#define u8g_font_cu12 u8g2_font_cu12_tf +#define u8g_font_micro u8g2_font_micro_tf +#define u8g_font_unifont u8g2_font_unifont_t_latin +#define u8g_font_unifontr u8g2_font_unifont_t_latin +#define u8g_font_courB08 u8g2_font_courB08_tf +#define u8g_font_courB08r u8g2_font_courB08_tr +#define u8g_font_courB10 u8g2_font_courB10_tf +#define u8g_font_courB10r u8g2_font_courB10_tr +#define u8g_font_courB12 u8g2_font_courB12_tf +#define u8g_font_courB12r u8g2_font_courB12_tr +#define u8g_font_courB14 u8g2_font_courB14_tf +#define u8g_font_courB14r u8g2_font_courB14_tr +#define u8g_font_courB18 u8g2_font_courB18_tf +#define u8g_font_courB18r u8g2_font_courB18_tr +#define u8g_font_courB24 u8g2_font_courB24_tf +#define u8g_font_courB24r u8g2_font_courB24_tr +#define u8g_font_courB24n u8g2_font_courB24_tn +#define u8g_font_courR08 u8g2_font_courR08_tf +#define u8g_font_courR08r u8g2_font_courR08_tr +#define u8g_font_courR10 u8g2_font_courR10_tf +#define u8g_font_courR10r u8g2_font_courR10_tr +#define u8g_font_courR12 u8g2_font_courR12_tf +#define u8g_font_courR12r u8g2_font_courR12_tr +#define u8g_font_courR14 u8g2_font_courR14_tf +#define u8g_font_courR14r u8g2_font_courR14_tr +#define u8g_font_courR18 u8g2_font_courR18_tf +#define u8g_font_courR18r u8g2_font_courR18_tr +#define u8g_font_courR24 u8g2_font_courR24_tf +#define u8g_font_courR24r u8g2_font_courR24_tr +#define u8g_font_courR24n u8g2_font_courR24_tn +#define u8g_font_helvB08 u8g2_font_helvB08_tf +#define u8g_font_helvB08r u8g2_font_helvB08_tr +#define u8g_font_helvB08n u8g2_font_helvB08_tn +#define u8g_font_helvB10 u8g2_font_helvB10_tf +#define u8g_font_helvB10r u8g2_font_helvB10_tr +#define u8g_font_helvB10n u8g2_font_helvB10_tn +#define u8g_font_helvB12 u8g2_font_helvB12_tf +#define u8g_font_helvB12r u8g2_font_helvB12_tr +#define u8g_font_helvB12n u8g2_font_helvB12_tn +#define u8g_font_helvB14 u8g2_font_helvB14_tf +#define u8g_font_helvB14r u8g2_font_helvB14_tr +#define u8g_font_helvB14n u8g2_font_helvB14_tn +#define u8g_font_helvB18 u8g2_font_helvB18_tf +#define u8g_font_helvB18r u8g2_font_helvB18_tr +#define u8g_font_helvB18n u8g2_font_helvB18_tn +#define u8g_font_helvB24 u8g2_font_helvB24_tf +#define u8g_font_helvB24r u8g2_font_helvB24_tr +#define u8g_font_helvB24n u8g2_font_helvB24_tn +#define u8g_font_helvR08 u8g2_font_helvR08_tf +#define u8g_font_helvR08r u8g2_font_helvR08_tr +#define u8g_font_helvR08n u8g2_font_helvR08_tn +#define u8g_font_helvR10 u8g2_font_helvR10_tf +#define u8g_font_helvR10r u8g2_font_helvR10_tr +#define u8g_font_helvR10n u8g2_font_helvR10_tn +#define u8g_font_helvR12 u8g2_font_helvR12_tf +#define u8g_font_helvR12r u8g2_font_helvR12_tr +#define u8g_font_helvR12n u8g2_font_helvR12_tn +#define u8g_font_helvR14 u8g2_font_helvR14_tf +#define u8g_font_helvR14r u8g2_font_helvR14_tr +#define u8g_font_helvR14n u8g2_font_helvR14_tn +#define u8g_font_helvR18 u8g2_font_helvR18_tf +#define u8g_font_helvR18r u8g2_font_helvR18_tr +#define u8g_font_helvR18n u8g2_font_helvR18_tn +#define u8g_font_helvR24 u8g2_font_helvR24_tf +#define u8g_font_helvR24r u8g2_font_helvR24_tr +#define u8g_font_helvR24n u8g2_font_helvR24_tn +#define u8g_font_ncenB08 u8g2_font_ncenB08_tf +#define u8g_font_ncenB08r u8g2_font_ncenB08_tr +#define u8g_font_ncenB10 u8g2_font_ncenB10_tf +#define u8g_font_ncenB10r u8g2_font_ncenB10_tr +#define u8g_font_ncenB12 u8g2_font_ncenB12_tf +#define u8g_font_ncenB12r u8g2_font_ncenB12_tr +#define u8g_font_ncenB14 u8g2_font_ncenB14_tf +#define u8g_font_ncenB14r u8g2_font_ncenB14_tr +#define u8g_font_ncenB18 u8g2_font_ncenB18_tf +#define u8g_font_ncenB18r u8g2_font_ncenB18_tr +#define u8g_font_ncenB24 u8g2_font_ncenB24_tf +#define u8g_font_ncenB24r u8g2_font_ncenB24_tr +#define u8g_font_ncenB24n u8g2_font_ncenB24_tn +#define u8g_font_ncenR08 u8g2_font_ncenR08_tf +#define u8g_font_ncenR08r u8g2_font_ncenR08_tr +#define u8g_font_ncenR10 u8g2_font_ncenR10_tf +#define u8g_font_ncenR10r u8g2_font_ncenR10_tr +#define u8g_font_ncenR12 u8g2_font_ncenR12_tf +#define u8g_font_ncenR12r u8g2_font_ncenR12_tr +#define u8g_font_ncenR14 u8g2_font_ncenR14_tf +#define u8g_font_ncenR14r u8g2_font_ncenR14_tr +#define u8g_font_ncenR18 u8g2_font_ncenR18_tf +#define u8g_font_ncenR18r u8g2_font_ncenR18_tr +#define u8g_font_ncenR24 u8g2_font_ncenR24_tf +#define u8g_font_ncenR24r u8g2_font_ncenR24_tr +#define u8g_font_ncenR24n u8g2_font_ncenR24_tn +#define u8g_font_timB08 u8g2_font_timB08_tf +#define u8g_font_timB08r u8g2_font_timB08_tr +#define u8g_font_timB10 u8g2_font_timB10_tf +#define u8g_font_timB10r u8g2_font_timB10_tr +#define u8g_font_timB12 u8g2_font_timB12_tf +#define u8g_font_timB12r u8g2_font_timB12_tr +#define u8g_font_timB14 u8g2_font_timB14_tf +#define u8g_font_timB14r u8g2_font_timB14_tr +#define u8g_font_timB18 u8g2_font_timB18_tf +#define u8g_font_timB18r u8g2_font_timB18_tr +#define u8g_font_timB24 u8g2_font_timB24_tf +#define u8g_font_timB24r u8g2_font_timB24_tr +#define u8g_font_timB24n u8g2_font_timB24_tn +#define u8g_font_timR08 u8g2_font_timR08_tf +#define u8g_font_timR08r u8g2_font_timR08_tr +#define u8g_font_timR10 u8g2_font_timR10_tf +#define u8g_font_timR10r u8g2_font_timR10_tr +#define u8g_font_timR12 u8g2_font_timR12_tf +#define u8g_font_timR12r u8g2_font_timR12_tr +#define u8g_font_timR14 u8g2_font_timR14_tf +#define u8g_font_timR14r u8g2_font_timR14_tr +#define u8g_font_timR18 u8g2_font_timR18_tf +#define u8g_font_timR18r u8g2_font_timR18_tr +#define u8g_font_timR24 u8g2_font_timR24_tf +#define u8g_font_timR24r u8g2_font_timR24_tr +#define u8g_font_timR24n u8g2_font_timR24_tn +#define u8g_font_p01type u8g2_font_p01type_tf +#define u8g_font_p01typer u8g2_font_p01type_tr +#define u8g_font_lucasfont_alternate u8g2_font_lucasfont_alternate_tf #define u8g_font_lucasfont_alternater u8g2_font_lucasfont_alternate_tr -#define u8g_font_chikita u8g2_font_chikita_tf -#define u8g_font_chikitar u8g2_font_chikita_tr -#define u8g_font_pixelle_micro u8g2_font_pixelle_micro_tf -#define u8g_font_pixelle_micror u8g2_font_pixelle_micro_tr -#define u8g_font_trixel_square u8g2_font_trixel_square_tf -#define u8g_font_trixel_squarer u8g2_font_trixel_square_tr -#define u8g_font_robot_de_niro u8g2_font_robot_de_niro_tf -#define u8g_font_robot_de_niror u8g2_font_robot_de_niro_tr -#define u8g_font_baby u8g2_font_baby_tf -#define u8g_font_babyr u8g2_font_baby_tr -#define u8g_font_blipfest_07 u8g2_font_blipfest_07_tr -#define u8g_font_blipfest_07r u8g2_font_blipfest_07_tr -#define u8g_font_blipfest_07n u8g2_font_blipfest_07_tn -#define u8g_font_profont10 u8g2_font_profont10_tf -#define u8g_font_profont10r u8g2_font_profont10_tr -#define u8g_font_profont11 u8g2_font_profont11_tf -#define u8g_font_profont11r u8g2_font_profont11_tr -#define u8g_font_profont12 u8g2_font_profont12_tf -#define u8g_font_profont12r u8g2_font_profont12_tr -#define u8g_font_profont15 u8g2_font_profont15_tf -#define u8g_font_profont15r u8g2_font_profont15_tr -#define u8g_font_profont17 u8g2_font_profont17_tf -#define u8g_font_profont17r u8g2_font_profont17_tr -#define u8g_font_profont22 u8g2_font_profont22_tf -#define u8g_font_profont22r u8g2_font_profont22_tr -#define u8g_font_profont29 u8g2_font_profont29_tf -#define u8g_font_profont29r u8g2_font_profont29_tr +#define u8g_font_chikita u8g2_font_chikita_tf +#define u8g_font_chikitar u8g2_font_chikita_tr +#define u8g_font_pixelle_micro u8g2_font_pixelle_micro_tf +#define u8g_font_pixelle_micror u8g2_font_pixelle_micro_tr +#define u8g_font_trixel_square u8g2_font_trixel_square_tf +#define u8g_font_trixel_squarer u8g2_font_trixel_square_tr +#define u8g_font_robot_de_niro u8g2_font_robot_de_niro_tf +#define u8g_font_robot_de_niror u8g2_font_robot_de_niro_tr +#define u8g_font_baby u8g2_font_baby_tf +#define u8g_font_babyr u8g2_font_baby_tr +#define u8g_font_blipfest_07 u8g2_font_blipfest_07_tr +#define u8g_font_blipfest_07r u8g2_font_blipfest_07_tr +#define u8g_font_blipfest_07n u8g2_font_blipfest_07_tn +#define u8g_font_profont10 u8g2_font_profont10_tf +#define u8g_font_profont10r u8g2_font_profont10_tr +#define u8g_font_profont11 u8g2_font_profont11_tf +#define u8g_font_profont11r u8g2_font_profont11_tr +#define u8g_font_profont12 u8g2_font_profont12_tf +#define u8g_font_profont12r u8g2_font_profont12_tr +#define u8g_font_profont15 u8g2_font_profont15_tf +#define u8g_font_profont15r u8g2_font_profont15_tr +#define u8g_font_profont17 u8g2_font_profont17_tf +#define u8g_font_profont17r u8g2_font_profont17_tr +#define u8g_font_profont22 u8g2_font_profont22_tf +#define u8g_font_profont22r u8g2_font_profont22_tr +#define u8g_font_profont29 u8g2_font_profont29_tf +#define u8g_font_profont29r u8g2_font_profont29_tr /*==========================================*/ /* C++ compatible */ diff --git a/lib/u8g2/u8g2_glue.c b/lib/u8g2/u8g2_glue.c index 230bd2a1bcf..b3e74c229b3 100644 --- a/lib/u8g2/u8g2_glue.c +++ b/lib/u8g2/u8g2_glue.c @@ -55,22 +55,22 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ return 1; } -#define ST756X_CMD_ON_OFF 0b10101110 /**< 0:0 Switch Display ON/OFF: last bit */ -#define ST756X_CMD_SET_LINE 0b01000000 /**< 0:0 Set Start Line: last 6 bits */ -#define ST756X_CMD_SET_PAGE 0b10110000 /**< 0:0 Set Page address: last 4 bits */ -#define ST756X_CMD_SET_COLUMN_MSB 0b00010000 /**< 0:0 Set Column MSB: last 4 bits */ -#define ST756X_CMD_SET_COLUMN_LSB 0b00000000 /**< 0:0 Set Column LSB: last 4 bits */ -#define ST756X_CMD_SEG_DIRECTION 0b10100000 /**< 0:0 Reverse scan direction of SEG: last bit */ -#define ST756X_CMD_INVERSE_DISPLAY 0b10100110 /**< 0:0 Invert display: last bit */ -#define ST756X_CMD_ALL_PIXEL_ON 0b10100100 /**< 0:0 Set all pixel on: last bit */ -#define ST756X_CMD_BIAS_SELECT 0b10100010 /**< 0:0 Select 1/9(0) or 1/7(1) bias: last bit */ -#define ST756X_CMD_R_M_W 0b11100000 /**< 0:0 Enter Read Modify Write mode: read+0, write+1 */ -#define ST756X_CMD_END 0b11101110 /**< 0:0 Exit Read Modify Write mode */ -#define ST756X_CMD_RESET 0b11100010 /**< 0:0 Software Reset */ -#define ST756X_CMD_COM_DIRECTION 0b11000000 /**< 0:0 Com direction reverse: +0b1000 */ -#define ST756X_CMD_POWER_CONTROL 0b00101000 /**< 0:0 Power control: last 3 bits VB:VR:VF */ +#define ST756X_CMD_ON_OFF 0b10101110 /**< 0:0 Switch Display ON/OFF: last bit */ +#define ST756X_CMD_SET_LINE 0b01000000 /**< 0:0 Set Start Line: last 6 bits */ +#define ST756X_CMD_SET_PAGE 0b10110000 /**< 0:0 Set Page address: last 4 bits */ +#define ST756X_CMD_SET_COLUMN_MSB 0b00010000 /**< 0:0 Set Column MSB: last 4 bits */ +#define ST756X_CMD_SET_COLUMN_LSB 0b00000000 /**< 0:0 Set Column LSB: last 4 bits */ +#define ST756X_CMD_SEG_DIRECTION 0b10100000 /**< 0:0 Reverse scan direction of SEG: last bit */ +#define ST756X_CMD_INVERSE_DISPLAY 0b10100110 /**< 0:0 Invert display: last bit */ +#define ST756X_CMD_ALL_PIXEL_ON 0b10100100 /**< 0:0 Set all pixel on: last bit */ +#define ST756X_CMD_BIAS_SELECT 0b10100010 /**< 0:0 Select 1/9(0) or 1/7(1) bias: last bit */ +#define ST756X_CMD_R_M_W 0b11100000 /**< 0:0 Enter Read Modify Write mode: read+0, write+1 */ +#define ST756X_CMD_END 0b11101110 /**< 0:0 Exit Read Modify Write mode */ +#define ST756X_CMD_RESET 0b11100010 /**< 0:0 Software Reset */ +#define ST756X_CMD_COM_DIRECTION 0b11000000 /**< 0:0 Com direction reverse: +0b1000 */ +#define ST756X_CMD_POWER_CONTROL 0b00101000 /**< 0:0 Power control: last 3 bits VB:VR:VF */ #define ST756X_CMD_REGULATION_RATIO 0b00100000 /**< 0:0 Regulation resistor ration: last 3bits */ -#define ST756X_CMD_SET_EV 0b10000001 /**< 0:0 Set electronic volume: 5 bits in next byte */ +#define ST756X_CMD_SET_EV 0b10000001 /**< 0:0 Set electronic volume: 5 bits in next byte */ #define ST756X_CMD_SET_BOOSTER \ 0b11111000 /**< 0:0 Set Booster level, 4X(0) or 5X(1): last bit in next byte */ #define ST756X_CMD_NOP 0b11100011 /**< 0:0 No operation */ @@ -142,7 +142,7 @@ uint8_t u8x8_d_st756x_common(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* a x *= 8; x += u8x8->x_offset; u8x8_cad_SendCmd(u8x8, 0x010 | (x >> 4)); - u8x8_cad_SendCmd(u8x8, 0x000 | ((x & 15))); + u8x8_cad_SendCmd(u8x8, 0x000 | (x & 15)); u8x8_cad_SendCmd(u8x8, 0x0b0 | (((u8x8_tile_t*)arg_ptr)->y_pos)); c = ((u8x8_tile_t*)arg_ptr)->cnt; diff --git a/lib/u8g2/u8x8.h b/lib/u8g2/u8x8.h index 834284f5d85..821fba92ee5 100644 --- a/lib/u8g2/u8x8.h +++ b/lib/u8g2/u8x8.h @@ -137,9 +137,9 @@ extern "C" { */ #ifdef __GNUC__ -#define U8X8_NOINLINE __attribute__((noinline)) +#define U8X8_NOINLINE __attribute__((noinline)) #define U8X8_SECTION(name) __attribute__((section(name))) -#define U8X8_UNUSED __attribute__((unused)) +#define U8X8_UNUSED __attribute__((unused)) #else #define U8X8_SECTION(name) #define U8X8_NOINLINE @@ -148,14 +148,14 @@ extern "C" { #if defined(__GNUC__) && defined(__AVR__) #define U8X8_FONT_SECTION(name) U8X8_SECTION(".progmem." name) -#define u8x8_pgm_read(adr) pgm_read_byte_near(adr) -#define U8X8_PROGMEM PROGMEM +#define u8x8_pgm_read(adr) pgm_read_byte_near(adr) +#define U8X8_PROGMEM PROGMEM #endif #if defined(ESP8266) uint8_t u8x8_pgm_read_esp(const uint8_t* addr); /* u8x8_8x8.c */ #define U8X8_FONT_SECTION(name) __attribute__((section(".text." name))) -#define u8x8_pgm_read(adr) u8x8_pgm_read_esp(adr) +#define u8x8_pgm_read(adr) u8x8_pgm_read_esp(adr) #define U8X8_PROGMEM #endif @@ -269,24 +269,24 @@ struct u8x8_display_info_struct { }; /* list of U8x8 pins */ -#define U8X8_PIN_D0 0 +#define U8X8_PIN_D0 0 #define U8X8_PIN_SPI_CLOCK 0 -#define U8X8_PIN_D1 1 -#define U8X8_PIN_SPI_DATA 1 -#define U8X8_PIN_D2 2 -#define U8X8_PIN_D3 3 -#define U8X8_PIN_D4 4 -#define U8X8_PIN_D5 5 -#define U8X8_PIN_D6 6 -#define U8X8_PIN_D7 7 - -#define U8X8_PIN_E 8 -#define U8X8_PIN_CS 9 /* parallel, SPI */ -#define U8X8_PIN_DC 10 /* parallel, SPI */ +#define U8X8_PIN_D1 1 +#define U8X8_PIN_SPI_DATA 1 +#define U8X8_PIN_D2 2 +#define U8X8_PIN_D3 3 +#define U8X8_PIN_D4 4 +#define U8X8_PIN_D5 5 +#define U8X8_PIN_D6 6 +#define U8X8_PIN_D7 7 + +#define U8X8_PIN_E 8 +#define U8X8_PIN_CS 9 /* parallel, SPI */ +#define U8X8_PIN_DC 10 /* parallel, SPI */ #define U8X8_PIN_RESET 11 /* parallel, SPI, I2C */ #define U8X8_PIN_I2C_CLOCK 12 /* 1 = Input/high impedance, 0 = drive low */ -#define U8X8_PIN_I2C_DATA 13 /* 1 = Input/high impedance, 0 = drive low */ +#define U8X8_PIN_I2C_DATA 13 /* 1 = Input/high impedance, 0 = drive low */ #define U8X8_PIN_CS1 14 /* KS0108 extra chip select */ #define U8X8_PIN_CS2 15 /* KS0108 extra chip select */ @@ -294,16 +294,16 @@ struct u8x8_display_info_struct { #define U8X8_PIN_OUTPUT_CNT 16 #define U8X8_PIN_MENU_SELECT 16 -#define U8X8_PIN_MENU_NEXT 17 -#define U8X8_PIN_MENU_PREV 18 -#define U8X8_PIN_MENU_HOME 19 -#define U8X8_PIN_MENU_UP 20 -#define U8X8_PIN_MENU_DOWN 21 +#define U8X8_PIN_MENU_NEXT 17 +#define U8X8_PIN_MENU_PREV 18 +#define U8X8_PIN_MENU_HOME 19 +#define U8X8_PIN_MENU_UP 20 +#define U8X8_PIN_MENU_DOWN 21 #define U8X8_PIN_INPUT_CNT 6 #ifdef U8X8_USE_PINS -#define U8X8_PIN_CNT (U8X8_PIN_OUTPUT_CNT + U8X8_PIN_INPUT_CNT) +#define U8X8_PIN_CNT (U8X8_PIN_OUTPUT_CNT + U8X8_PIN_INPUT_CNT) #define U8X8_PIN_NONE 255 #endif @@ -341,32 +341,32 @@ struct u8x8_struct { }; #ifdef U8X8_WITH_USER_PTR -#define u8x8_GetUserPtr(u8x8) ((u8x8)->user_ptr) +#define u8x8_GetUserPtr(u8x8) ((u8x8)->user_ptr) #define u8x8_SetUserPtr(u8x8, p) ((u8x8)->user_ptr = (p)) #endif -#define u8x8_GetCols(u8x8) ((u8x8)->display_info->tile_width) -#define u8x8_GetRows(u8x8) ((u8x8)->display_info->tile_height) -#define u8x8_GetI2CAddress(u8x8) ((u8x8)->i2c_address) +#define u8x8_GetCols(u8x8) ((u8x8)->display_info->tile_width) +#define u8x8_GetRows(u8x8) ((u8x8)->display_info->tile_height) +#define u8x8_GetI2CAddress(u8x8) ((u8x8)->i2c_address) #define u8x8_SetI2CAddress(u8x8, address) ((u8x8)->i2c_address = (address)) #define u8x8_SetGPIOResult(u8x8, val) ((u8x8)->gpio_result = (val)) #define u8x8_GetSPIClockPhase(u8x8) \ ((u8x8)->display_info->spi_mode & 0x01) /* 0 means rising edge */ -#define u8x8_GetSPIClockPolarity(u8x8) (((u8x8)->display_info->spi_mode & 0x02) >> 1) +#define u8x8_GetSPIClockPolarity(u8x8) (((u8x8)->display_info->spi_mode & 0x02) >> 1) #define u8x8_GetSPIClockDefaultLevel(u8x8) (((u8x8)->display_info->spi_mode & 0x02) >> 1) -#define u8x8_GetFontCharWidth(u8x8) u8x8_pgm_read((u8x8)->font + 2) +#define u8x8_GetFontCharWidth(u8x8) u8x8_pgm_read((u8x8)->font + 2) #define u8x8_GetFontCharHeight(u8x8) u8x8_pgm_read((u8x8)->font + 3) #ifdef U8X8_USE_PINS -#define u8x8_SetPin(u8x8, pin, val) (u8x8)->pins[pin] = (val) +#define u8x8_SetPin(u8x8, pin, val) (u8x8)->pins[pin] = (val) #define u8x8_SetMenuSelectPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_SELECT, (val)) -#define u8x8_SetMenuNextPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_NEXT, (val)) -#define u8x8_SetMenuPrevPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_PREV, (val)) -#define u8x8_SetMenuHomePin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_HOME, (val)) -#define u8x8_SetMenuUpPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_UP, (val)) -#define u8x8_SetMenuDownPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_DOWN, (val)) +#define u8x8_SetMenuNextPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_NEXT, (val)) +#define u8x8_SetMenuPrevPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_PREV, (val)) +#define u8x8_SetMenuHomePin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_HOME, (val)) +#define u8x8_SetMenuUpPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_UP, (val)) +#define u8x8_SetMenuDownPin(u8x8, val) u8x8_SetPin((u8x8), U8X8_PIN_MENU_DOWN, (val)) #endif /*==========================================*/ @@ -558,15 +558,15 @@ void u8x8_ClearLine(u8x8_t* u8x8, uint8_t line); */ #define U8X8_MSG_CAD_INIT 20 -#define U8X8_MSG_CAD_SEND_CMD 21 +#define U8X8_MSG_CAD_SEND_CMD 21 /* arg_int: cmd byte */ -#define U8X8_MSG_CAD_SEND_ARG 22 +#define U8X8_MSG_CAD_SEND_ARG 22 /* arg_int: arg byte */ -#define U8X8_MSG_CAD_SEND_DATA 23 +#define U8X8_MSG_CAD_SEND_DATA 23 /* arg_int: expected cs level after processing this msg */ #define U8X8_MSG_CAD_START_TRANSFER 24 /* arg_int: expected cs level after processing this msg */ -#define U8X8_MSG_CAD_END_TRANSFER 25 +#define U8X8_MSG_CAD_END_TRANSFER 25 /* arg_int = 0: disable chip, arg_int = 1: enable chip */ //#define U8X8_MSG_CAD_SET_I2C_ADR 26 //#define U8X8_MSG_CAD_SET_DEVICE 27 @@ -592,8 +592,8 @@ void u8x8_SendF(u8x8_t* u8x8, const char* fmt, ...); #define U8X8_D1(d0) (0x11), (d0) */ -#define U8X8_C(c0) (U8X8_MSG_CAD_SEND_CMD), (c0) -#define U8X8_A(a0) (U8X8_MSG_CAD_SEND_ARG), (a0) +#define U8X8_C(c0) (U8X8_MSG_CAD_SEND_CMD), (c0) +#define U8X8_A(a0) (U8X8_MSG_CAD_SEND_ARG), (a0) #define U8X8_CA(c0, a0) (U8X8_MSG_CAD_SEND_CMD), (c0), (U8X8_MSG_CAD_SEND_ARG), (a0) #define U8X8_CAA(c0, a0, a1) \ (U8X8_MSG_CAD_SEND_CMD), (c0), (U8X8_MSG_CAD_SEND_ARG), (a0), (U8X8_MSG_CAD_SEND_ARG), (a1) @@ -612,9 +612,9 @@ void u8x8_SendF(u8x8_t* u8x8, const char* fmt, ...); U8X8_A4((a0), (a1), (a2), (a3)), U8X8_A4((a4), (a5), (a6), (a7)) #define U8X8_START_TRANSFER() (U8X8_MSG_CAD_START_TRANSFER) -#define U8X8_END_TRANSFER() (U8X8_MSG_CAD_END_TRANSFER) -#define U8X8_DLY(m) (0xfe), (m) /* delay in milli seconds */ -#define U8X8_END() (0xff) +#define U8X8_END_TRANSFER() (U8X8_MSG_CAD_END_TRANSFER) +#define U8X8_DLY(m) (0xfe), (m) /* delay in milli seconds */ +#define U8X8_END() (0xff) void u8x8_cad_SendSequence(u8x8_t* u8x8, uint8_t const* data); uint8_t u8x8_cad_empty(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr); @@ -632,13 +632,13 @@ uint8_t u8x8_cad_uc16xx_i2c(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* ar /*==========================================*/ /* Byte Interface */ -#define U8X8_MSG_BYTE_INIT U8X8_MSG_CAD_INIT +#define U8X8_MSG_BYTE_INIT U8X8_MSG_CAD_INIT #define U8X8_MSG_BYTE_SET_DC 32 #define U8X8_MSG_BYTE_SEND U8X8_MSG_CAD_SEND_DATA #define U8X8_MSG_BYTE_START_TRANSFER U8X8_MSG_CAD_START_TRANSFER -#define U8X8_MSG_BYTE_END_TRANSFER U8X8_MSG_CAD_END_TRANSFER +#define U8X8_MSG_BYTE_END_TRANSFER U8X8_MSG_CAD_END_TRANSFER //#define U8X8_MSG_BYTE_SET_I2C_ADR U8X8_MSG_CAD_SET_I2C_ADR //#define U8X8_MSG_BYTE_SET_DEVICE U8X8_MSG_CAD_SET_DEVICE @@ -684,7 +684,7 @@ uint8_t u8x8_byte_sed1520(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ #define U8X8_MSG_DELAY_NANO 44 /* delay of one i2c unit, should be 5us for 100K, and 1.25us for 400K */ -#define U8X8_MSG_DELAY_I2C 45 +#define U8X8_MSG_DELAY_I2C 45 #define U8X8_MSG_GPIO(x) (64 + (x)) #ifdef U8X8_USE_PINS @@ -692,33 +692,33 @@ uint8_t u8x8_byte_sed1520(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ #define u8x8_GetPinValue(u8x8, msg) ((u8x8)->pins[(msg) & 0x3f]) #endif -#define U8X8_MSG_GPIO_D0 U8X8_MSG_GPIO(U8X8_PIN_D0) +#define U8X8_MSG_GPIO_D0 U8X8_MSG_GPIO(U8X8_PIN_D0) #define U8X8_MSG_GPIO_SPI_CLOCK U8X8_MSG_GPIO(U8X8_PIN_SPI_CLOCK) -#define U8X8_MSG_GPIO_D1 U8X8_MSG_GPIO(U8X8_PIN_D1) -#define U8X8_MSG_GPIO_SPI_DATA U8X8_MSG_GPIO(U8X8_PIN_SPI_DATA) -#define U8X8_MSG_GPIO_D2 U8X8_MSG_GPIO(U8X8_PIN_D2) -#define U8X8_MSG_GPIO_D3 U8X8_MSG_GPIO(U8X8_PIN_D3) -#define U8X8_MSG_GPIO_D4 U8X8_MSG_GPIO(U8X8_PIN_D4) -#define U8X8_MSG_GPIO_D5 U8X8_MSG_GPIO(U8X8_PIN_D5) -#define U8X8_MSG_GPIO_D6 U8X8_MSG_GPIO(U8X8_PIN_D6) -#define U8X8_MSG_GPIO_D7 U8X8_MSG_GPIO(U8X8_PIN_D7) -#define U8X8_MSG_GPIO_E U8X8_MSG_GPIO(U8X8_PIN_E) // used as E1 for the SED1520 -#define U8X8_MSG_GPIO_CS U8X8_MSG_GPIO(U8X8_PIN_CS) // used as E2 for the SED1520 -#define U8X8_MSG_GPIO_DC U8X8_MSG_GPIO(U8X8_PIN_DC) -#define U8X8_MSG_GPIO_RESET U8X8_MSG_GPIO(U8X8_PIN_RESET) +#define U8X8_MSG_GPIO_D1 U8X8_MSG_GPIO(U8X8_PIN_D1) +#define U8X8_MSG_GPIO_SPI_DATA U8X8_MSG_GPIO(U8X8_PIN_SPI_DATA) +#define U8X8_MSG_GPIO_D2 U8X8_MSG_GPIO(U8X8_PIN_D2) +#define U8X8_MSG_GPIO_D3 U8X8_MSG_GPIO(U8X8_PIN_D3) +#define U8X8_MSG_GPIO_D4 U8X8_MSG_GPIO(U8X8_PIN_D4) +#define U8X8_MSG_GPIO_D5 U8X8_MSG_GPIO(U8X8_PIN_D5) +#define U8X8_MSG_GPIO_D6 U8X8_MSG_GPIO(U8X8_PIN_D6) +#define U8X8_MSG_GPIO_D7 U8X8_MSG_GPIO(U8X8_PIN_D7) +#define U8X8_MSG_GPIO_E U8X8_MSG_GPIO(U8X8_PIN_E) // used as E1 for the SED1520 +#define U8X8_MSG_GPIO_CS U8X8_MSG_GPIO(U8X8_PIN_CS) // used as E2 for the SED1520 +#define U8X8_MSG_GPIO_DC U8X8_MSG_GPIO(U8X8_PIN_DC) +#define U8X8_MSG_GPIO_RESET U8X8_MSG_GPIO(U8X8_PIN_RESET) #define U8X8_MSG_GPIO_I2C_CLOCK U8X8_MSG_GPIO(U8X8_PIN_I2C_CLOCK) -#define U8X8_MSG_GPIO_I2C_DATA U8X8_MSG_GPIO(U8X8_PIN_I2C_DATA) +#define U8X8_MSG_GPIO_I2C_DATA U8X8_MSG_GPIO(U8X8_PIN_I2C_DATA) #define U8X8_MSG_GPIO_CS1 U8X8_MSG_GPIO(U8X8_PIN_CS1) /* KS0108 extra chip select */ #define U8X8_MSG_GPIO_CS2 U8X8_MSG_GPIO(U8X8_PIN_CS2) /* KS0108 extra chip select */ /* these message expect the return value in u8x8->gpio_result */ #define U8X8_MSG_GPIO_MENU_SELECT U8X8_MSG_GPIO(U8X8_PIN_MENU_SELECT) -#define U8X8_MSG_GPIO_MENU_NEXT U8X8_MSG_GPIO(U8X8_PIN_MENU_NEXT) -#define U8X8_MSG_GPIO_MENU_PREV U8X8_MSG_GPIO(U8X8_PIN_MENU_PREV) -#define U8X8_MSG_GPIO_MENU_HOME U8X8_MSG_GPIO(U8X8_PIN_MENU_HOME) -#define U8X8_MSG_GPIO_MENU_UP U8X8_MSG_GPIO(U8X8_PIN_MENU_UP) -#define U8X8_MSG_GPIO_MENU_DOWN U8X8_MSG_GPIO(U8X8_PIN_MENU_DOWN) +#define U8X8_MSG_GPIO_MENU_NEXT U8X8_MSG_GPIO(U8X8_PIN_MENU_NEXT) +#define U8X8_MSG_GPIO_MENU_PREV U8X8_MSG_GPIO(U8X8_PIN_MENU_PREV) +#define U8X8_MSG_GPIO_MENU_HOME U8X8_MSG_GPIO(U8X8_PIN_MENU_HOME) +#define U8X8_MSG_GPIO_MENU_UP U8X8_MSG_GPIO(U8X8_PIN_MENU_UP) +#define U8X8_MSG_GPIO_MENU_DOWN U8X8_MSG_GPIO(U8X8_PIN_MENU_DOWN) #define u8x8_gpio_Init(u8x8) \ ((u8x8)->gpio_and_delay_cb((u8x8), U8X8_MSG_GPIO_AND_DELAY_INIT, 0, NULL)) @@ -729,13 +729,13 @@ uint8_t u8x8_byte_sed1520(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ #define u8x8_gpio_SetReset(u8x8, v) ((u8x8)->gpio_and_delay_cb((u8x8), U8X8_MSG_GPIO_RESET, (v), NULL )) */ -#define u8x8_gpio_SetDC(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_DC, (v)) -#define u8x8_gpio_SetCS(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS, (v)) -#define u8x8_gpio_SetReset(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_RESET, (v)) +#define u8x8_gpio_SetDC(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_DC, (v)) +#define u8x8_gpio_SetCS(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS, (v)) +#define u8x8_gpio_SetReset(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_RESET, (v)) #define u8x8_gpio_SetSPIClock(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_SPI_CLOCK, (v)) -#define u8x8_gpio_SetSPIData(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_SPI_DATA, (v)) +#define u8x8_gpio_SetSPIData(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_SPI_DATA, (v)) #define u8x8_gpio_SetI2CClock(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_I2C_CLOCK, (v)) -#define u8x8_gpio_SetI2CData(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_I2C_DATA, (v)) +#define u8x8_gpio_SetI2CData(u8x8, v) u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_I2C_DATA, (v)) void u8x8_gpio_call(u8x8_t* u8x8, uint8_t msg, uint8_t arg) U8X8_NOINLINE; diff --git a/lib/u8g2/u8x8_byte.c b/lib/u8g2/u8x8_byte.c index a5af75e11e5..2d729711d80 100644 --- a/lib/u8g2/u8x8_byte.c +++ b/lib/u8g2/u8x8_byte.c @@ -584,7 +584,8 @@ void i2c_transfer(u8x8_t* u8x8, uint8_t adr, uint8_t cnt, uint8_t* data) { uint8_t i; i2c_start(u8x8); i2c_write_byte(u8x8, adr); - for(i = 0; i < cnt; i++) i2c_write_byte(u8x8, data[i]); + for(i = 0; i < cnt; i++) + i2c_write_byte(u8x8, data[i]); i2c_stop(u8x8); } diff --git a/lib/u8g2/u8x8_setup.c b/lib/u8g2/u8x8_setup.c index c59c68d05eb..b8873fb7d66 100644 --- a/lib/u8g2/u8x8_setup.c +++ b/lib/u8g2/u8x8_setup.c @@ -109,7 +109,8 @@ void u8x8_SetupDefaults(u8x8_t* u8x8) { #ifdef U8X8_USE_PINS { uint8_t i; - for(i = 0; i < U8X8_PIN_CNT; i++) u8x8->pins[i] = U8X8_PIN_NONE; + for(i = 0; i < U8X8_PIN_CNT; i++) + u8x8->pins[i] = U8X8_PIN_NONE; } #endif } diff --git a/lib/update_util/dfu_file.c b/lib/update_util/dfu_file.c index 85b661e8e00..c336a19d0b8 100644 --- a/lib/update_util/dfu_file.c +++ b/lib/update_util/dfu_file.c @@ -4,8 +4,8 @@ #include #define VALID_WHOLE_FILE_CRC 0xFFFFFFFF -#define DFU_SUFFIX_VERSION 0x011A -#define DFU_SIGNATURE "DfuSe" +#define DFU_SUFFIX_VERSION 0x011A +#define DFU_SIGNATURE "DfuSe" bool dfu_file_validate_crc(File* dfuf, const DfuPageTaskProgressCb progress_cb, void* context) { uint32_t file_crc = crc32_calc_file(dfuf, progress_cb, context); diff --git a/lib/update_util/resources/manifest.c b/lib/update_util/resources/manifest.c index 5a818a0a4a4..580a76d457c 100644 --- a/lib/update_util/resources/manifest.c +++ b/lib/update_util/resources/manifest.c @@ -161,3 +161,9 @@ ResourceManifestEntry* return NULL; } } + +bool resource_manifest_rewind(ResourceManifestReader* resource_manifest) { + furi_assert(resource_manifest); + + return stream_seek(resource_manifest->stream, 0, StreamOffsetFromStart); +} diff --git a/lib/update_util/resources/manifest.h b/lib/update_util/resources/manifest.h index ddceb5ffaa0..90b41fa5499 100644 --- a/lib/update_util/resources/manifest.h +++ b/lib/update_util/resources/manifest.h @@ -47,6 +47,13 @@ void resource_manifest_reader_free(ResourceManifestReader* resource_manifest); */ bool resource_manifest_reader_open(ResourceManifestReader* resource_manifest, const char* filename); +/** + * @brief Rewind manifest to the beginning + * @param resource_manifest allocated object + * @return true if successful + */ +bool resource_manifest_rewind(ResourceManifestReader* resource_manifest); + /** * @brief Read next file/dir entry from manifest * @param resource_manifest allocated object @@ -68,4 +75,4 @@ ResourceManifestEntry* #ifdef __cplusplus } // extern "C" -#endif \ No newline at end of file +#endif diff --git a/lib/update_util/update_manifest.c b/lib/update_util/update_manifest.c index eef27cb4291..920db3f0353 100644 --- a/lib/update_util/update_manifest.c +++ b/lib/update_util/update_manifest.c @@ -4,20 +4,20 @@ #include #include -#define MANIFEST_KEY_INFO "Info" -#define MANIFEST_KEY_TARGET "Target" -#define MANIFEST_KEY_LOADER_FILE "Loader" -#define MANIFEST_KEY_LOADER_CRC "Loader CRC" -#define MANIFEST_KEY_DFU_FILE "Firmware" -#define MANIFEST_KEY_RADIO_FILE "Radio" +#define MANIFEST_KEY_INFO "Info" +#define MANIFEST_KEY_TARGET "Target" +#define MANIFEST_KEY_LOADER_FILE "Loader" +#define MANIFEST_KEY_LOADER_CRC "Loader CRC" +#define MANIFEST_KEY_DFU_FILE "Firmware" +#define MANIFEST_KEY_RADIO_FILE "Radio" #define MANIFEST_KEY_RADIO_ADDRESS "Radio address" #define MANIFEST_KEY_RADIO_VERSION "Radio version" -#define MANIFEST_KEY_RADIO_CRC "Radio CRC" -#define MANIFEST_KEY_ASSETS_FILE "Resources" -#define MANIFEST_KEY_OB_REFERENCE "OB reference" -#define MANIFEST_KEY_OB_MASK "OB mask" +#define MANIFEST_KEY_RADIO_CRC "Radio CRC" +#define MANIFEST_KEY_ASSETS_FILE "Resources" +#define MANIFEST_KEY_OB_REFERENCE "OB reference" +#define MANIFEST_KEY_OB_MASK "OB mask" #define MANIFEST_KEY_OB_WRITE_MASK "OB write mask" -#define MANIFEST_KEY_SPLASH_FILE "Splashscreen" +#define MANIFEST_KEY_SPLASH_FILE "Splashscreen" UpdateManifest* update_manifest_alloc(void) { UpdateManifest* update_manifest = malloc(sizeof(UpdateManifest)); diff --git a/lib/update_util/update_manifest.h b/lib/update_util/update_manifest.h index 0c6284516cf..4d064b3f787 100644 --- a/lib/update_util/update_manifest.h +++ b/lib/update_util/update_manifest.h @@ -10,7 +10,7 @@ extern "C" { #include /* Paths don't include /ext -- because at startup SD card is mounted as FS root */ -#define UPDATE_MANIFEST_DEFAULT_NAME "update.fuf" +#define UPDATE_MANIFEST_DEFAULT_NAME "update.fuf" #define UPDATE_MANIFEST_POINTER_FILE_NAME ".fupdate" typedef union { diff --git a/lib/update_util/update_operation.c b/lib/update_util/update_operation.c index cb603abe042..3ab8c02b083 100644 --- a/lib/update_util/update_operation.c +++ b/lib/update_util/update_operation.c @@ -71,7 +71,7 @@ static bool update_operation_get_current_package_path_rtc(Storage* storage, Furi return found; } -#define UPDATE_FILE_POINTER_FN EXT_PATH(UPDATE_MANIFEST_POINTER_FILE_NAME) +#define UPDATE_FILE_POINTER_FN EXT_PATH(UPDATE_MANIFEST_POINTER_FILE_NAME) #define UPDATE_MANIFEST_MAX_PATH_LEN 256u bool update_operation_get_current_package_manifest_path(Storage* storage, FuriString* out_path) { diff --git a/lib/update_util/update_operation.h b/lib/update_util/update_operation.h index 063f577e247..1f246337e63 100644 --- a/lib/update_util/update_operation.h +++ b/lib/update_util/update_operation.h @@ -8,8 +8,8 @@ extern "C" { #endif #define UPDATE_OPERATION_ROOT_DIR_PACKAGE_MAGIC 0 -#define UPDATE_OPERATION_MAX_MANIFEST_PATH_LEN 255u -#define UPDATE_OPERATION_MIN_MANIFEST_VERSION 2 +#define UPDATE_OPERATION_MAX_MANIFEST_PATH_LEN 255u +#define UPDATE_OPERATION_MIN_MANIFEST_VERSION 2 /* * Checks if supplied full manifest path is valid diff --git a/scripts/debug/stm32wbx.cfg b/scripts/debug/stm32wbx.cfg index ba383831bd4..4fc9c8d2ce2 100644 --- a/scripts/debug/stm32wbx.cfg +++ b/scripts/debug/stm32wbx.cfg @@ -44,7 +44,7 @@ if {[using_jtag]} { set _TARGETNAME $_CHIPNAME.cpu target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap -$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 +$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 1 set _FLASHNAME $_CHIPNAME.flash flash bank $_FLASHNAME stm32l4x 0 0 0 0 $_TARGETNAME diff --git a/scripts/distfap.py b/scripts/distfap.py deleted file mode 100755 index b1c5587906b..00000000000 --- a/scripts/distfap.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python3 - -import os -import posixpath - -from flipper.app import App -from flipper.storage import FlipperStorage, FlipperStorageOperations -from flipper.utils.cdc import resolve_port - - -class Main(App): - def init(self): - self.parser.add_argument("-p", "--port", help="CDC Port", default="auto") - self.parser.add_argument( - "-n", - "--no-launch", - dest="launch_app", - action="store_false", - help="Don't launch app", - ) - - self.parser.add_argument("fap_src_path", help="App file to upload") - self.parser.add_argument( - "--fap_dst_dir", help="Upload path", default="/ext/apps", required=False - ) - self.parser.set_defaults(func=self.install) - - def install(self): - if not (port := resolve_port(self.logger, self.args.port)): - return 1 - - try: - with FlipperStorage(port) as storage: - storage_ops = FlipperStorageOperations(storage) - fap_local_path = self.args.fap_src_path - self.args.fap_dst_dir = self.args.fap_dst_dir.rstrip("/\\") - - if not os.path.isfile(fap_local_path): - self.logger.error( - f"Error: source .fap ({fap_local_path}) not found" - ) - return 2 - - fap_dst_path = posixpath.join( - self.args.fap_dst_dir, os.path.basename(fap_local_path) - ) - - self.logger.info(f'Installing "{fap_local_path}" to {fap_dst_path}') - - storage_ops.recursive_send(fap_dst_path, fap_local_path, False) - - if not self.args.launch_app: - return 0 - - storage.send_and_wait_eol(f"loader open {fap_dst_path}\r") - - if len(result := storage.read.until(storage.CLI_EOL)): - self.logger.error(f"Unexpected response: {result.decode('ascii')}") - return 3 - return 0 - - except Exception as e: - self.logger.error(f"Error: {e}") - # raise - return 4 - - -if __name__ == "__main__": - Main()() diff --git a/scripts/fbt/sdk/collector.py b/scripts/fbt/sdk/collector.py index 1dd3bc4ebb9..5615f105ed4 100644 --- a/scripts/fbt/sdk/collector.py +++ b/scripts/fbt/sdk/collector.py @@ -38,7 +38,6 @@ from cxxheaderparser.parserstate import ( State, - EmptyBlockState, ClassBlockState, ExternBlockState, NamespaceBlockState, @@ -180,12 +179,6 @@ def on_pragma(self, state: State, content: str) -> None: def on_include(self, state: State, filename: str) -> None: pass - def on_empty_block_start(self, state: EmptyBlockState) -> None: - pass - - def on_empty_block_end(self, state: EmptyBlockState) -> None: - pass - def on_extern_block_start(self, state: ExternBlockState) -> None: pass @@ -230,3 +223,6 @@ def on_class_friend(self, state: ClassBlockState, friend: FriendDecl) -> None: def on_class_end(self, state: ClassBlockState) -> None: pass + + def on_parse_start(self, state: NamespaceBlockState) -> None: + pass diff --git a/scripts/fbt_tools/compilation_db.py b/scripts/fbt_tools/compilation_db.py index 6bad96b2dc1..2988fd67b27 100644 --- a/scripts/fbt_tools/compilation_db.py +++ b/scripts/fbt_tools/compilation_db.py @@ -32,7 +32,7 @@ import fnmatch import itertools import json -from shlex import join, split +from oslex import join, split import SCons from SCons.Tool.asm import ASPPSuffixes, ASSuffixes diff --git a/scripts/flipper/assets/heatshrink_stream.py b/scripts/flipper/assets/heatshrink_stream.py new file mode 100644 index 00000000000..bae84d3feda --- /dev/null +++ b/scripts/flipper/assets/heatshrink_stream.py @@ -0,0 +1,26 @@ +import struct + + +class HeatshrinkDataStreamHeader: + MAGIC = 0x53445348 + VERSION = 1 + + def __init__(self, window_size, lookahead_size): + self.window_size = window_size + self.lookahead_size = lookahead_size + + def pack(self): + return struct.pack( + " 1: logger.error("More than one Flipper is attached") - logger.error("Failed to guess which port to use") diff --git a/scripts/hs.py b/scripts/hs.py new file mode 100755 index 00000000000..4ceb6e36f56 --- /dev/null +++ b/scripts/hs.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python3 + +import heatshrink2 as hs +from flipper.app import App +from flipper.assets.heatshrink_stream import HeatshrinkDataStreamHeader +from flipper.assets.tarball import compress_tree_tarball + + +class HSWrapper(App): + DEFAULT_WINDOW = 13 + DEFAULT_LOOKAHEAD = 6 + + def init(self): + self.subparsers = self.parser.add_subparsers( + title="subcommands", dest="subcommand" + ) + + self.parser_compress = self.subparsers.add_parser( + "compress", help="compress file using heatshrink" + ) + self.parser_compress.add_argument( + "-w", "--window", help="window size", type=int, default=self.DEFAULT_WINDOW + ) + self.parser_compress.add_argument( + "-l", + "--lookahead", + help="lookahead size", + type=int, + default=self.DEFAULT_LOOKAHEAD, + ) + self.parser_compress.add_argument("file", help="file to compress") + self.parser_compress.add_argument( + "-o", "--output", help="output file", required=True + ) + self.parser_compress.set_defaults(func=self.compress) + + self.parser_decompress = self.subparsers.add_parser( + "decompress", help="decompress file using heatshrink" + ) + self.parser_decompress.add_argument("file", help="file to decompress") + self.parser_decompress.add_argument( + "-o", "--output", help="output file", required=True + ) + self.parser_decompress.set_defaults(func=self.decompress) + + self.parser_info = self.subparsers.add_parser("info", help="show file info") + self.parser_info.add_argument("file", help="file to show info for") + self.parser_info.set_defaults(func=self.info) + + self.parser_tar = self.subparsers.add_parser( + "tar", help="create a tarball and compress it" + ) + self.parser_tar.add_argument("dir", help="directory to tar") + self.parser_tar.add_argument( + "-o", "--output", help="output file", required=True + ) + self.parser_tar.add_argument( + "-w", "--window", help="window size", type=int, default=self.DEFAULT_WINDOW + ) + self.parser_tar.add_argument( + "-l", + "--lookahead", + help="lookahead size", + type=int, + default=self.DEFAULT_LOOKAHEAD, + ) + self.parser_tar.set_defaults(func=self.tar) + + def compress(self): + args = self.args + + with open(args.file, "rb") as f: + data = f.read() + + compressed = hs.compress( + data, window_sz2=args.window, lookahead_sz2=args.lookahead + ) + + with open(args.output, "wb") as f: + header = HeatshrinkDataStreamHeader(args.window, args.lookahead) + f.write(header.pack()) + f.write(compressed) + + self.logger.info( + f"Compressed {len(data)} bytes to {len(compressed)} bytes, " + f"compression ratio: {len(compressed) * 100 / len(data):.2f}%" + ) + return 0 + + def decompress(self): + args = self.args + + with open(args.file, "rb") as f: + header = HeatshrinkDataStreamHeader.unpack(f.read(7)) + compressed = f.read() + + self.logger.info( + f"Decompressing with window size {header.window_size} and lookahead size {header.lookahead_size}" + ) + + data = hs.decompress( + compressed, + window_sz2=header.window_size, + lookahead_sz2=header.lookahead_size, + ) + + with open(args.output, "wb") as f: + f.write(data) + + self.logger.info(f"Decompressed {len(compressed)} bytes to {len(data)} bytes") + return 0 + + def info(self): + args = self.args + + try: + with open(args.file, "rb") as f: + header = HeatshrinkDataStreamHeader.unpack(f.read(7)) + except Exception as e: + self.logger.error(f"Error: {e}") + return 1 + + self.logger.info( + f"Window size: {header.window_size}, lookahead size: {header.lookahead_size}" + ) + + return 0 + + def tar(self): + args = self.args + + orig_size, compressed_size = compress_tree_tarball( + args.dir, args.output, hs_window=args.window, hs_lookahead=args.lookahead + ) + + self.logger.info( + f"Tarred and compressed {orig_size} bytes to {compressed_size} bytes, " + f"compression ratio: {compressed_size * 100 / orig_size:.2f}%" + ) + + return 0 + + +if __name__ == "__main__": + HSWrapper()() diff --git a/scripts/runfap.py b/scripts/runfap.py index 42141acff65..a85d1e91aec 100755 --- a/scripts/runfap.py +++ b/scripts/runfap.py @@ -2,6 +2,7 @@ import operator from functools import reduce +import time from flipper.app import App from flipper.storage import FlipperStorage, FlipperStorageOperations @@ -9,6 +10,8 @@ class Main(App): + APP_POST_CLOSE_DELAY_SEC = 0.2 + def init(self): self.parser.add_argument("-p", "--port", help="CDC Port", default="auto") self.parser.add_argument( @@ -67,8 +70,25 @@ def install(self): if self.args.host_app: startup_command = self.args.host_app + self.logger.info("Closing current app, if any") + for _ in range(10): + storage.send_and_wait_eol("loader close\r") + result = storage.read.until(storage.CLI_EOL) + if b"was closed" in result: + self.logger.info("App closed") + storage.read.until(storage.CLI_EOL) + time.sleep(self.APP_POST_CLOSE_DELAY_SEC) + elif result.startswith(b"No application"): + storage.read.until(storage.CLI_EOL) + break + else: + self.logger.error( + f"Unexpected response: {result.decode('ascii')}" + ) + return 4 + self.logger.info(f"Launching app: {startup_command}") - storage.send_and_wait_eol(f"loader open {startup_command}\r") + storage.send_and_wait_eol(f'loader open "{startup_command}"\r') if len(result := storage.read.until(storage.CLI_EOL)): self.logger.error(f"Unexpected response: {result.decode('ascii')}") diff --git a/scripts/sconsdist.py b/scripts/sconsdist.py index 7ce0e884214..314eabecd5b 100755 --- a/scripts/sconsdist.py +++ b/scripts/sconsdist.py @@ -9,6 +9,7 @@ from ansi.color import fg from flipper.app import App +from flipper.assets.tarball import FLIPPER_TAR_FORMAT, tar_sanitizer_filter from update import Main as UpdateMain @@ -266,20 +267,15 @@ def bundle_update_package(self): ), "w:gz", compresslevel=9, - format=tarfile.USTAR_FORMAT, + format=FLIPPER_TAR_FORMAT, ) as tar: self.note_dist_component( "update", "tgz", self.get_dist_path(bundle_tgz) ) - # Strip uid and gid in case of overflow - def tar_filter(tarinfo): - tarinfo.uid = tarinfo.gid = 0 - tarinfo.mtime = 0 - tarinfo.uname = tarinfo.gname = "furippa" - return tarinfo - - tar.add(bundle_dir, arcname=bundle_dir_name, filter=tar_filter) + tar.add( + bundle_dir, arcname=bundle_dir_name, filter=tar_sanitizer_filter + ) return bundle_result diff --git a/scripts/testing/await_flipper.py b/scripts/testing/await_flipper.py deleted file mode 100755 index f8dffeb66bf..00000000000 --- a/scripts/testing/await_flipper.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python3 -import logging -import os -import sys -import time - - -def flp_serial_by_name(flp_name): - if sys.platform == "darwin": # MacOS - flp_serial = "/dev/cu.usbmodemflip_" + flp_name + "1" - logging.info(f"Darwin, looking for {flp_serial}") - elif sys.platform == "linux": # Linux - flp_serial = ( - "/dev/serial/by-id/usb-Flipper_Devices_Inc._Flipper_" - + flp_name - + "_flip_" - + flp_name - + "-if00" - ) - logging.info(f"linux, looking for {flp_serial}") - - if os.path.exists(flp_serial): - return flp_serial - else: - logging.info(f"Couldn't find {flp_name} on this attempt.") - if os.path.exists(flp_name): - return flp_name - else: - return "" - - -UPDATE_TIMEOUT = 30 * 4 # 4 minutes - - -def main(): - flipper_name = sys.argv[1] - elapsed = 0 - flipper = flp_serial_by_name(flipper_name) - logging.basicConfig( - format="%(asctime)s %(levelname)-8s %(message)s", - level=logging.INFO, - datefmt="%Y-%m-%d %H:%M:%S", - ) - logging.info(f"Waiting for Flipper {flipper_name} to be ready...") - - while flipper == "" and elapsed < UPDATE_TIMEOUT: - elapsed += 1 - time.sleep(1) - flipper = flp_serial_by_name(flipper_name) - - if flipper == "": - logging.error("Flipper not found!") - exit(1) - - logging.info(f"Found Flipper at {flipper}") - - sys.exit(0) - - -if __name__ == "__main__": - main() diff --git a/scripts/testing/units.py b/scripts/testing/units.py deleted file mode 100755 index db302e9daeb..00000000000 --- a/scripts/testing/units.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python3 -import logging -import re -import sys - -import serial -from await_flipper import flp_serial_by_name - - -def main(): - logging.basicConfig( - format="%(asctime)s %(levelname)-8s %(message)s", - level=logging.INFO, - datefmt="%Y-%m-%d %H:%M:%S", - ) - logging.info("Trying to run units on flipper") - flp_serial = flp_serial_by_name(sys.argv[1]) - - if flp_serial == "": - logging.error("Flipper not found!") - sys.exit(1) - - with serial.Serial(flp_serial, timeout=150) as flipper: - logging.info(f"Found Flipper at {flp_serial}") - flipper.baudrate = 230400 - flipper.flushOutput() - flipper.flushInput() - - flipper.read_until(b">: ").decode("utf-8") - flipper.write(b"unit_tests\r") - data = flipper.read_until(b">: ").decode("utf-8") - - lines = data.split("\r\n") - - tests_re = r"Failed tests: \d{0,}" - time_re = r"Consumed: \d{0,}" - leak_re = r"Leaked: \d{0,}" - status_re = r"Status: \w{3,}" - - tests_pattern = re.compile(tests_re) - time_pattern = re.compile(time_re) - leak_pattern = re.compile(leak_re) - status_pattern = re.compile(status_re) - - tests, time, leak, status = None, None, None, None - total = 0 - - for line in lines: - logging.info(line) - if "()" in line: - total += 1 - - if not tests: - tests = re.match(tests_pattern, line) - if not time: - time = re.match(time_pattern, line) - if not leak: - leak = re.match(leak_pattern, line) - if not status: - status = re.match(status_pattern, line) - - if None in (tests, time, leak, status): - logging.error(f"Failed to parse output: {leak} {time} {leak} {status}") - sys.exit(1) - - leak = int(re.findall(r"[- ]\d+", leak.group(0))[0]) - status = re.findall(r"\w+", status.group(0))[1] - tests = int(re.findall(r"\d+", tests.group(0))[0]) - time = int(re.findall(r"\d+", time.group(0))[0]) - - if tests > 0 or status != "PASSED": - logging.error(f"Got {tests} failed tests.") - logging.error(f"Leaked (not failing on this stat): {leak}") - logging.error(f"Status: {status}") - logging.error(f"Time: {time/1000} seconds") - sys.exit(1) - - logging.info(f"Leaked (not failing on this stat): {leak}") - logging.info( - f"Tests ran successfully! Time elapsed {time/1000} seconds. Passed {total} tests." - ) - - sys.exit(0) - - -if __name__ == "__main__": - main() diff --git a/scripts/testops.py b/scripts/testops.py new file mode 100644 index 00000000000..bf02feaad37 --- /dev/null +++ b/scripts/testops.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 + +import re +import sys +import time +from typing import Optional + +from flipper.app import App +from flipper.storage import FlipperStorage +from flipper.utils.cdc import resolve_port + + +class Main(App): + # this is basic use without sub-commands, simply to reboot flipper / power it off, not meant as a full CLI wrapper + def init(self): + self.parser.add_argument("-p", "--port", help="CDC Port", default="auto") + self.parser.add_argument( + "-t", "--timeout", help="Timeout in seconds", type=int, default=10 + ) + + self.subparsers = self.parser.add_subparsers(help="sub-command help") + + self.parser_await_flipper = self.subparsers.add_parser( + "await_flipper", help="Wait for Flipper to connect or reconnect" + ) + self.parser_await_flipper.set_defaults(func=self.await_flipper) + + self.parser_run_units = self.subparsers.add_parser( + "run_units", help="Run unit tests and post result" + ) + self.parser_run_units.set_defaults(func=self.run_units) + + def _get_flipper(self, retry_count: Optional[int] = 1): + port = None + self.logger.info(f"Attempting to find flipper with {retry_count} attempts.") + + for i in range(retry_count): + self.logger.info(f"Attempt to find flipper #{i}.") + + if port := resolve_port(self.logger, self.args.port): + self.logger.info(f"Found flipper at {port}") + break + time.sleep(1) + + if not port: + self.logger.info(f"Failed to find flipper {port}") + return None + + flipper = FlipperStorage(port) + flipper.start() + return flipper + + def await_flipper(self): + if not (flipper := self._get_flipper(retry_count=self.args.timeout)): + return 1 + + self.logger.info("Flipper started") + flipper.stop() + return 0 + + def run_units(self): + if not (flipper := self._get_flipper(retry_count=10)): + return 1 + + self.logger.info("Running unit tests") + flipper.send("unit_tests" + "\r") + self.logger.info("Waiting for unit tests to complete") + data = flipper.read.until(">: ") + self.logger.info("Parsing result") + + lines = data.decode().split("\r\n") + + tests_re = r"Failed tests: \d{0,}" + time_re = r"Consumed: \d{0,}" + leak_re = r"Leaked: \d{0,}" + status_re = r"Status: \w{3,}" + + tests_pattern = re.compile(tests_re) + time_pattern = re.compile(time_re) + leak_pattern = re.compile(leak_re) + status_pattern = re.compile(status_re) + + tests, elapsed_time, leak, status = None, None, None, None + total = 0 + + for line in lines: + self.logger.info(line) + if "()" in line: + total += 1 + + if not tests: + tests = re.match(tests_pattern, line) + if not elapsed_time: + elapsed_time = re.match(time_pattern, line) + if not leak: + leak = re.match(leak_pattern, line) + if not status: + status = re.match(status_pattern, line) + + if None in (tests, elapsed_time, leak, status): + self.logger.error( + f"Failed to parse output: {tests} {elapsed_time} {leak} {status}" + ) + sys.exit(1) + + leak = int(re.findall(r"[- ]\d+", leak.group(0))[0]) + status = re.findall(r"\w+", status.group(0))[1] + tests = int(re.findall(r"\d+", tests.group(0))[0]) + elapsed_time = int(re.findall(r"\d+", elapsed_time.group(0))[0]) + + if tests > 0 or status != "PASSED": + self.logger.error(f"Got {tests} failed tests.") + self.logger.error(f"Leaked (not failing on this stat): {leak}") + self.logger.error(f"Status: {status}") + self.logger.error(f"Time: {elapsed_time/1000} seconds") + flipper.stop() + return 1 + + self.logger.info(f"Leaked (not failing on this stat): {leak}") + self.logger.info( + f"Tests ran successfully! Time elapsed {elapsed_time/1000} seconds. Passed {total} tests." + ) + + flipper.stop() + return 0 + + +if __name__ == "__main__": + Main()() diff --git a/scripts/toolchain/fbtenv.cmd b/scripts/toolchain/fbtenv.cmd index 29b48369a1a..c0a3cd87008 100644 --- a/scripts/toolchain/fbtenv.cmd +++ b/scripts/toolchain/fbtenv.cmd @@ -13,7 +13,7 @@ if not ["%FBT_NOENV%"] == [""] ( exit /b 0 ) -set "FLIPPER_TOOLCHAIN_VERSION=33" +set "FLIPPER_TOOLCHAIN_VERSION=38" if ["%FBT_TOOLCHAIN_PATH%"] == [""] ( set "FBT_TOOLCHAIN_PATH=%FBT_ROOT%" diff --git a/scripts/toolchain/fbtenv.sh b/scripts/toolchain/fbtenv.sh index 495cdba6f91..156fabcca80 100755 --- a/scripts/toolchain/fbtenv.sh +++ b/scripts/toolchain/fbtenv.sh @@ -4,7 +4,7 @@ # public variables DEFAULT_SCRIPT_PATH="$(pwd -P)"; -FBT_TOOLCHAIN_VERSION="${FBT_TOOLCHAIN_VERSION:-"33"}"; +FBT_TOOLCHAIN_VERSION="${FBT_TOOLCHAIN_VERSION:-"38"}"; if [ -z ${FBT_TOOLCHAIN_PATH+x} ] ; then FBT_TOOLCHAIN_PATH_WAS_SET=0; diff --git a/scripts/ufbt/SConstruct b/scripts/ufbt/SConstruct index 26b1046ee34..18c4d1cac80 100644 --- a/scripts/ufbt/SConstruct +++ b/scripts/ufbt/SConstruct @@ -403,6 +403,9 @@ for template_file in project_template_dir.Dir(".vscode").glob("*"): "@UFBT_FIRMWARE_ELF@": PosixPathWrapper.fix_path( dist_env["FW_ELF"].abspath ), + "@UFBT_TOOLCHAIN_CLANGD@": PosixPathWrapper.fix_path( + dist_env.WhereIs("clangd") + ), }, ) ) diff --git a/scripts/ufbt/commandline.scons b/scripts/ufbt/commandline.scons index a3ba7e08dae..67a274bb556 100644 --- a/scripts/ufbt/commandline.scons +++ b/scripts/ufbt/commandline.scons @@ -93,6 +93,11 @@ vars.AddVariables( help="Enable strict import check for .faps", default=True, ), + ( + "ARGS", + "Extra arguments to pass to certain scripts supporting it", + "", + ), ) Return("vars") diff --git a/scripts/ufbt/project_template/.clang-format b/scripts/ufbt/project_template/.clang-format index 4b76f7fa43b..c42068920c0 100644 --- a/scripts/ufbt/project_template/.clang-format +++ b/scripts/ufbt/project_template/.clang-format @@ -3,22 +3,55 @@ Language: Cpp AccessModifierOffset: -4 AlignAfterOpenBracket: AlwaysBreak AlignArrayOfStructures: None -AlignConsecutiveMacros: None -AlignConsecutiveAssignments: None -AlignConsecutiveBitFields: None -AlignConsecutiveDeclarations: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: true + AcrossEmptyLines: true + AcrossComments: true + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: false + AcrossComments: true + AlignCompound: true + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false AlignEscapedNewlines: Left AlignOperands: Align -AlignTrailingComments: false +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: false -AllowShortEnumsOnASingleLine: true +AllowBreakBeforeNoexceptSpecifier: Never AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: false AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: All AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLoopsOnASingleLine: true +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false @@ -27,17 +60,18 @@ AttributeMacros: - __capability BinPackArguments: false BinPackParameters: false +BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false AfterClass: false AfterControlStatement: Never AfterEnum: false + AfterExternBlock: false AfterFunction: false AfterNamespace: false AfterObjCDeclaration: false AfterStruct: false AfterUnion: false - AfterExternBlock: false BeforeCatch: false BeforeElse: false BeforeLambdaBody: false @@ -46,38 +80,35 @@ BraceWrapping: SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: true +BreakBeforeConceptDeclarations: Always BreakBeforeBraces: Attach -BreakBeforeInheritanceComma: false -BreakInheritanceList: BeforeColon +BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: false -BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeComma -BreakAfterJavaFieldAnnotations: false +BreakInheritanceList: BeforeColon BreakStringLiterals: false ColumnLimit: 99 CommentPragmas: '^ IWYU pragma:' -QualifierAlignment: Leave CompactNamespaces: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DeriveLineEnding: true DerivePointerAlignment: false DisableFormat: false EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false -PackConstructorInitializers: BinPack -BasedOnStyle: '' -ConstructorInitializerAllOnOneLineOrOnePerLine: false -AllowAllConstructorInitializersOnNextLine: true FixNamespaceComments: false ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH + - M_EACH IfMacros: - KJ_IF_MAYBE IncludeBlocks: Preserve @@ -97,19 +128,30 @@ IncludeCategories: IncludeIsMainRegex: '(Test)?$' IncludeIsMainSourceRegex: '' IndentAccessModifiers: false -IndentCaseLabels: false IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock IndentGotoLabels: true IndentPPDirectives: None -IndentExternBlock: AfterExternBlock -IndentRequires: false +IndentRequiresClause: false IndentWidth: 4 IndentWrappedFunctionNames: true +InsertBraces: false +InsertNewlineAtEOF: true InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: false LambdaBodyIndentation: Signature +LineEnding: DeriveLF MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 @@ -119,34 +161,44 @@ ObjCBlockIndentWidth: 4 ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack PenaltyBreakAssignment: 10 PenaltyBreakBeforeFirstCallParameter: 30 PenaltyBreakComment: 10 PenaltyBreakFirstLessLess: 0 PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 PenaltyBreakString: 10 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 100 -PenaltyReturnTypeOnItsOwnLine: 60 PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Left PPIndentWidth: -1 +QualifierAlignment: Leave ReferenceAlignment: Pointer ReflowComments: false RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: true +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope SeparateDefinitionBlocks: Leave ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false SortIncludes: Never SortJavaStaticImport: Before -SortUsingDeclarations: false +SortUsingDeclarations: Never SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false SpaceBeforeParens: Never SpaceBeforeParensOptions: AfterControlStatements: false @@ -155,32 +207,35 @@ SpaceBeforeParensOptions: AfterFunctionDeclarationName: false AfterIfMacros: false AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false BeforeNonEmptyParentheses: false -SpaceAroundPointerQualifiers: Default SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: Never -SpacesInConditionalStatement: false SpacesInContainerLiterals: false -SpacesInCStyleCastParentheses: false SpacesInLineCommentPrefix: Minimum: 1 Maximum: -1 -SpacesInParentheses: false +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false SpacesInSquareBrackets: false -SpaceBeforeSquareBrackets: false -BitFieldColonSpacing: Both -Standard: c++03 +Standard: c++20 StatementAttributeLikeMacros: - Q_EMIT StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 4 -UseCRLF: false UseTab: Never +VerilogBreakBetweenInstancePorts: true WhitespaceSensitiveMacros: - STRINGIZE - PP_STRINGIZE diff --git a/scripts/ufbt/project_template/.clangd b/scripts/ufbt/project_template/.clangd new file mode 100644 index 00000000000..12e13751d2c --- /dev/null +++ b/scripts/ufbt/project_template/.clangd @@ -0,0 +1,17 @@ +CompileFlags: + Add: + - -Wno-unknown-warning-option + - -Wno-format + Remove: + - -mword-relocations + +Diagnostics: + ClangTidy: + FastCheckFilter: None + +--- + +If: + PathMatch: .*\.h +Diagnostics: + UnusedIncludes: None diff --git a/scripts/ufbt/project_template/.gitignore b/scripts/ufbt/project_template/.gitignore index 81a8981f739..dd6a4750db6 100644 --- a/scripts/ufbt/project_template/.gitignore +++ b/scripts/ufbt/project_template/.gitignore @@ -1,6 +1,7 @@ dist/* .vscode .clang-format +.clangd .editorconfig .env .ufbt diff --git a/scripts/ufbt/project_template/.vscode/extensions.json b/scripts/ufbt/project_template/.vscode/extensions.json index 9daefb43088..dc92d3bbdb9 100644 --- a/scripts/ufbt/project_template/.vscode/extensions.json +++ b/scripts/ufbt/project_template/.vscode/extensions.json @@ -8,7 +8,7 @@ // List of extensions which should be recommended for users of this workspace. "recommendations": [ "ms-python.black-formatter", - "ms-vscode.cpptools", + "llvm-vs-code-extensions.vscode-clangd", "amiralizadeh9480.cpp-helper", "marus25.cortex-debug", "zxh404.vscode-proto3", @@ -18,6 +18,7 @@ // List of extensions recommended by VS Code that should not be recommended for users of this workspace. "unwantedRecommendations": [ "twxs.cmake", + "ms-vscode.cpptools", "ms-vscode.cmake-tools" ] } \ No newline at end of file diff --git a/scripts/ufbt/project_template/.vscode/settings.json b/scripts/ufbt/project_template/.vscode/settings.json index ce5210f5fe4..b93ad82f1aa 100644 --- a/scripts/ufbt/project_template/.vscode/settings.json +++ b/scripts/ufbt/project_template/.vscode/settings.json @@ -5,7 +5,6 @@ { "cortex-debug.enableTelemetry": false, "cortex-debug.variableUseNaturalFormat": false, - "cortex-debug.showRTOS": true, "cortex-debug.armToolchainPath": "@UFBT_TOOLCHAIN_ARM_TOOLCHAIN_DIR@", "cortex-debug.openocdPath": "@UFBT_TOOLCHAIN_OPENOCD@", "cortex-debug.gdbPath": "@UFBT_TOOLCHAIN_GDB_PY@", @@ -16,9 +15,15 @@ "SConstruct": "python", "*.fam": "python" }, - "cortex-debug.registerUseNaturalFormat": false, "python.analysis.typeCheckingMode": "off", "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" - } + }, + // "clangd.path": "@UFBT_TOOLCHAIN_CLANGD@", + "clangd.arguments": [ + "--query-driver=**/arm-none-eabi-*", + "--compile-commands-dir=${workspaceFolder}/.vscode", + "--clang-tidy", + "--header-insertion=never" + ] } \ No newline at end of file diff --git a/scripts/update.py b/scripts/update.py index c315ef8adef..e880bced844 100755 --- a/scripts/update.py +++ b/scripts/update.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import io import math import os import shutil @@ -7,9 +8,12 @@ import zlib from os.path import exists, join +import heatshrink2 from flipper.app import App from flipper.assets.coprobin import CoproBinary, get_stack_type +from flipper.assets.heatshrink_stream import HeatshrinkDataStreamHeader from flipper.assets.obdata import ObReferenceValues, OptionBytesData +from flipper.assets.tarball import compress_tree_tarball, tar_sanitizer_filter from flipper.utils.fff import FlipperFormatFile from slideshow import Main as SlideshowMain @@ -20,8 +24,7 @@ class Main(App): # No compression, plain tar RESOURCE_TAR_MODE = "w:" - RESOURCE_TAR_FORMAT = tarfile.USTAR_FORMAT - RESOURCE_FILE_NAME = "resources.tar" + RESOURCE_FILE_NAME = "resources.ths" # .Tar.HeatShrink RESOURCE_ENTRY_NAME_MAX_LENGTH = 100 WHITELISTED_STACK_TYPES = set( @@ -34,6 +37,9 @@ class Main(App): FLASH_BASE = 0x8000000 MIN_LFS_PAGES = 6 + HEATSHRINK_WINDOW_SIZE = 13 + HEATSHRINK_LOOKAHEAD_SIZE = 6 + # Post-update slideshow SPLASH_BIN_NAME = "splash.bin" @@ -221,23 +227,19 @@ def _tar_filter(self, tarinfo: tarfile.TarInfo): f"Cannot package resource: name '{tarinfo.name}' too long" ) raise ValueError("Resource name too long") - tarinfo.gid = tarinfo.uid = 0 - tarinfo.mtime = 0 - tarinfo.uname = tarinfo.gname = "furippa" - return tarinfo + return tar_sanitizer_filter(tarinfo) def package_resources(self, srcdir: str, dst_name: str): try: - with tarfile.open( - dst_name, self.RESOURCE_TAR_MODE, format=self.RESOURCE_TAR_FORMAT - ) as tarball: - tarball.add( - srcdir, - arcname="", - filter=self._tar_filter, - ) + src_size, compressed_size = compress_tree_tarball( + srcdir, dst_name, filter=self._tar_filter + ) + + self.logger.info( + f"Resources compression ratio: {compressed_size * 100 / src_size:.2f}%" + ) return True - except ValueError as e: + except Exception as e: self.logger.error(f"Cannot package resources: {e}") return False diff --git a/site_scons/commandline.scons b/site_scons/commandline.scons index 3ea5dcd6b70..3eb9c9ff7b7 100644 --- a/site_scons/commandline.scons +++ b/site_scons/commandline.scons @@ -263,7 +263,7 @@ vars.AddVariables( EnumVariable( "LANG_SERVER", help="Language server type for vscode_dist.", - default="cpptools", + default="clangd", allowed_values=[ "cpptools", "clangd", diff --git a/site_scons/site_init.py b/site_scons/site_init.py index b763a3a7c05..5b297e80e51 100644 --- a/site_scons/site_init.py +++ b/site_scons/site_init.py @@ -6,7 +6,6 @@ from ansi.color import fg, fx sys.path.insert(0, os.path.join(os.getcwd(), "scripts")) -sys.path.insert(0, os.path.join(os.getcwd(), "lib/cxxheaderparser")) def bf_to_str(bf): diff --git a/targets/ReadMe.md b/targets/ReadMe.md index c39f8c4ab31..e4b2f17f749 100644 --- a/targets/ReadMe.md +++ b/targets/ReadMe.md @@ -1,22 +1,5 @@ -# Flipper firmware - -What does it do? - -- [x] RTOS -- [x] FuriHAL -- [x] FuriCore -- [x] Services -- [x] Applications - # Targets -| Name | Firmware Address | Reset Combo | DFU Combo | -|-----------|-------------------|-----------------------|-----------------------| -| f7 | 0x08000000 | L+Back, release both | L+Back, release Back | - -Also, there is a "hardware" ST bootloader combo available even on a bricked or empty device: L+Ok+Back, release Back, Left. -Target independent code and headers in `target/include` folders. More details in `documentation/KeyCombo.md` - -# Building - -Check out `documentation/fbt.md` on how to build and flash firmware. +- f18 - Not Flipper Zero +- f7 - Flipper Zero +- furi_hal_include - Global Furi HAL includes, common for all targets diff --git a/targets/f18/api_symbols.csv b/targets/f18/api_symbols.csv index 99c153c049d..7e254ce4010 100644 --- a/targets/f18/api_symbols.csv +++ b/targets/f18/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,66.0,, +Version,+,69.0,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, Header,+,applications/services/cli/cli.h,, @@ -780,13 +780,20 @@ Function,+,composite_api_resolver_add,void,"CompositeApiResolver*, const ElfApiI Function,+,composite_api_resolver_alloc,CompositeApiResolver*, Function,+,composite_api_resolver_free,void,CompositeApiResolver* Function,+,composite_api_resolver_get,const ElfApiInterface*,CompositeApiResolver* -Function,+,compress_alloc,Compress*,uint16_t +Function,+,compress_alloc,Compress*,"CompressType, const void*" Function,+,compress_decode,_Bool,"Compress*, uint8_t*, size_t, uint8_t*, size_t, size_t*" +Function,+,compress_decode_streamed,_Bool,"Compress*, CompressIoCallback, void*, CompressIoCallback, void*" Function,+,compress_encode,_Bool,"Compress*, uint8_t*, size_t, uint8_t*, size_t, size_t*" Function,+,compress_free,void,Compress* Function,+,compress_icon_alloc,CompressIcon*,size_t Function,+,compress_icon_decode,void,"CompressIcon*, const uint8_t*, uint8_t**" Function,+,compress_icon_free,void,CompressIcon* +Function,+,compress_stream_decoder_alloc,CompressStreamDecoder*,"CompressType, const void*, CompressIoCallback, void*" +Function,+,compress_stream_decoder_free,void,CompressStreamDecoder* +Function,+,compress_stream_decoder_read,_Bool,"CompressStreamDecoder*, uint8_t*, size_t" +Function,+,compress_stream_decoder_rewind,_Bool,CompressStreamDecoder* +Function,+,compress_stream_decoder_seek,_Bool,"CompressStreamDecoder*, size_t" +Function,+,compress_stream_decoder_tell,size_t,CompressStreamDecoder* Function,-,copysign,double,"double, double" Function,-,copysignf,float,"float, float" Function,-,copysignl,long double,"long double, long double" @@ -1098,13 +1105,22 @@ Function,+,furi_event_flag_free,void,FuriEventFlag* Function,+,furi_event_flag_get,uint32_t,FuriEventFlag* Function,+,furi_event_flag_set,uint32_t,"FuriEventFlag*, uint32_t" Function,+,furi_event_flag_wait,uint32_t,"FuriEventFlag*, uint32_t, uint32_t, uint32_t" -Function,-,furi_event_loop_alloc,FuriEventLoop*, -Function,-,furi_event_loop_free,void,FuriEventLoop* -Function,-,furi_event_loop_message_queue_subscribe,void,"FuriEventLoop*, FuriMessageQueue*, FuriEventLoopEvent, FuriEventLoopMessageQueueCallback, void*" -Function,-,furi_event_loop_message_queue_unsubscribe,void,"FuriEventLoop*, FuriMessageQueue*" -Function,-,furi_event_loop_run,void,FuriEventLoop* -Function,-,furi_event_loop_stop,void,FuriEventLoop* -Function,-,furi_event_loop_tick_set,void,"FuriEventLoop*, uint32_t, FuriEventLoopTickCallback, void*" +Function,+,furi_event_loop_alloc,FuriEventLoop*, +Function,+,furi_event_loop_free,void,FuriEventLoop* +Function,+,furi_event_loop_message_queue_subscribe,void,"FuriEventLoop*, FuriMessageQueue*, FuriEventLoopEvent, FuriEventLoopMessageQueueCallback, void*" +Function,+,furi_event_loop_message_queue_unsubscribe,void,"FuriEventLoop*, FuriMessageQueue*" +Function,+,furi_event_loop_pend_callback,void,"FuriEventLoop*, FuriEventLoopPendingCallback, void*" +Function,+,furi_event_loop_run,void,FuriEventLoop* +Function,+,furi_event_loop_stop,void,FuriEventLoop* +Function,+,furi_event_loop_tick_set,void,"FuriEventLoop*, uint32_t, FuriEventLoopTickCallback, void*" +Function,+,furi_event_loop_timer_alloc,FuriEventLoopTimer*,"FuriEventLoop*, FuriEventLoopTimerCallback, FuriEventLoopTimerType, void*" +Function,+,furi_event_loop_timer_free,void,FuriEventLoopTimer* +Function,+,furi_event_loop_timer_get_interval,uint32_t,const FuriEventLoopTimer* +Function,+,furi_event_loop_timer_get_remaining_time,uint32_t,const FuriEventLoopTimer* +Function,+,furi_event_loop_timer_is_running,_Bool,const FuriEventLoopTimer* +Function,+,furi_event_loop_timer_restart,void,FuriEventLoopTimer* +Function,+,furi_event_loop_timer_start,void,"FuriEventLoopTimer*, uint32_t" +Function,+,furi_event_loop_timer_stop,void,FuriEventLoopTimer* Function,+,furi_get_tick,uint32_t, Function,+,furi_hal_adc_acquire,FuriHalAdcHandle*, Function,+,furi_hal_adc_configure,void,FuriHalAdcHandle* @@ -1162,9 +1178,6 @@ Function,+,furi_hal_bus_enable,void,FuriHalBus Function,+,furi_hal_bus_init_early,void, Function,+,furi_hal_bus_is_enabled,_Bool,FuriHalBus Function,+,furi_hal_bus_reset,void,FuriHalBus -Function,+,furi_hal_ccid_ccid_insert_smartcard,void, -Function,+,furi_hal_ccid_ccid_remove_smartcard,void, -Function,+,furi_hal_ccid_set_callbacks,void,"CcidCallbacks*, void*" Function,+,furi_hal_cdc_get_ctrl_line_state,uint8_t,uint8_t Function,+,furi_hal_cdc_get_port_settings,usb_cdc_line_coding*,uint8_t Function,+,furi_hal_cdc_receive,int32_t,"uint8_t, uint8_t*, uint16_t" @@ -1272,6 +1285,7 @@ Function,+,furi_hal_info_get_api_version,void,"uint16_t*, uint16_t*" Function,-,furi_hal_init,void, Function,-,furi_hal_init_early,void, Function,+,furi_hal_interrupt_get_name,const char*,uint8_t +Function,+,furi_hal_interrupt_get_time_in_isr_total,uint32_t, Function,-,furi_hal_interrupt_init,void, Function,+,furi_hal_interrupt_set_isr,void,"FuriHalInterruptId, FuriHalInterruptISR, void*" Function,+,furi_hal_interrupt_set_isr_ex,void,"FuriHalInterruptId, FuriHalInterruptPriority, FuriHalInterruptISR, void*" @@ -1437,6 +1451,9 @@ Function,-,furi_hal_spi_config_init_early,void, Function,-,furi_hal_spi_dma_init,void, Function,+,furi_hal_spi_release,void,FuriHalSpiBusHandle* Function,+,furi_hal_switch,void,void* +Function,+,furi_hal_usb_ccid_insert_smartcard,void, +Function,+,furi_hal_usb_ccid_remove_smartcard,void, +Function,+,furi_hal_usb_ccid_set_callbacks,void,"CcidCallbacks*, void*" Function,+,furi_hal_usb_disable,void, Function,+,furi_hal_usb_enable,void, Function,+,furi_hal_usb_get_config,FuriHalUsbInterface*, @@ -1617,6 +1634,7 @@ Function,+,furi_thread_join,_Bool,FuriThread* Function,+,furi_thread_list_alloc,FuriThreadList*, Function,+,furi_thread_list_free,void,FuriThreadList* Function,+,furi_thread_list_get_at,FuriThreadListItem*,"FuriThreadList*, size_t" +Function,+,furi_thread_list_get_isr_time,float,FuriThreadList* Function,+,furi_thread_list_get_or_insert,FuriThreadListItem*,"FuriThreadList*, FuriThread*" Function,+,furi_thread_list_process,void,"FuriThreadList*, uint32_t, uint32_t" Function,+,furi_thread_list_size,size_t,FuriThreadList* @@ -1627,10 +1645,12 @@ Function,+,furi_thread_set_context,void,"FuriThread*, void*" Function,+,furi_thread_set_current_priority,void,FuriThreadPriority Function,+,furi_thread_set_name,void,"FuriThread*, const char*" Function,+,furi_thread_set_priority,void,"FuriThread*, FuriThreadPriority" +Function,+,furi_thread_set_signal_callback,void,"FuriThread*, FuriThreadSignalCallback, void*" Function,+,furi_thread_set_stack_size,void,"FuriThread*, size_t" Function,+,furi_thread_set_state_callback,void,"FuriThread*, FuriThreadStateCallback" Function,+,furi_thread_set_state_context,void,"FuriThread*, void*" Function,+,furi_thread_set_stdout_callback,void,FuriThreadStdoutWriteCallback +Function,+,furi_thread_signal,_Bool,"const FuriThread*, uint32_t, void*" Function,+,furi_thread_start,void,FuriThread* Function,+,furi_thread_stdout_flush,int32_t, Function,+,furi_thread_stdout_write,size_t,"const char*, size_t" @@ -1782,10 +1802,12 @@ Function,-,llrintl,long long int,long double Function,-,llround,long long int,double Function,-,llroundf,long long int,float Function,-,llroundl,long long int,long double +Function,+,loader_get_application_name,_Bool,"Loader*, FuriString*" Function,+,loader_get_pubsub,FuriPubSub*,Loader* Function,+,loader_is_locked,_Bool,Loader* Function,+,loader_lock,_Bool,Loader* Function,+,loader_show_menu,void,Loader* +Function,+,loader_signal,_Bool,"Loader*, uint32_t, void*" Function,+,loader_start,LoaderStatus,"Loader*, const char*, const char*, FuriString*" Function,+,loader_start_detached_with_gui_error,void,"Loader*, const char*, const char*" Function,+,loader_start_with_gui_error,LoaderStatus,"Loader*, const char*, const char*" @@ -2613,6 +2635,8 @@ Function,+,tar_archive_file_finalize,_Bool,TarArchive* Function,+,tar_archive_finalize,_Bool,TarArchive* Function,+,tar_archive_free,void,TarArchive* Function,+,tar_archive_get_entries_count,int32_t,TarArchive* +Function,+,tar_archive_get_mode_for_path,TarOpenMode,const char* +Function,+,tar_archive_get_read_progress,_Bool,"TarArchive*, int32_t*, int32_t*" Function,+,tar_archive_open,_Bool,"TarArchive*, const char*, TarOpenMode" Function,+,tar_archive_set_file_callback,void,"TarArchive*, tar_unpack_file_cb, void*" Function,+,tar_archive_store_data,_Bool,"TarArchive*, const char*, const uint8_t*, const int32_t" @@ -2812,6 +2836,7 @@ Variable,-,_sys_nerr,int, Variable,-,ble_profile_hid,const FuriHalBleProfileTemplate*, Variable,-,ble_profile_serial,const FuriHalBleProfileTemplate*, Variable,+,cli_vcp,CliSession, +Variable,+,compress_config_heatshrink_default,const CompressConfigHeatshrink, Variable,+,firmware_api_interface,const ElfApiInterface*, Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus, Variable,+,furi_hal_i2c_bus_power,FuriHalI2cBus, diff --git a/targets/f18/furi_hal/furi_hal_version_device.c b/targets/f18/furi_hal/furi_hal_version_device.c index 8b85260314e..f9be05e24b2 100644 --- a/targets/f18/furi_hal/furi_hal_version_device.c +++ b/targets/f18/furi_hal/furi_hal_version_device.c @@ -30,4 +30,4 @@ const char* furi_hal_version_get_srrc_id(void) { const char* furi_hal_version_get_ncc_id(void) { return "Pending"; -} \ No newline at end of file +} diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index b59453823a1..cce5a320ab5 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,66.0,, +Version,+,69.0,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, @@ -857,13 +857,20 @@ Function,+,composite_api_resolver_add,void,"CompositeApiResolver*, const ElfApiI Function,+,composite_api_resolver_alloc,CompositeApiResolver*, Function,+,composite_api_resolver_free,void,CompositeApiResolver* Function,+,composite_api_resolver_get,const ElfApiInterface*,CompositeApiResolver* -Function,+,compress_alloc,Compress*,uint16_t +Function,+,compress_alloc,Compress*,"CompressType, const void*" Function,+,compress_decode,_Bool,"Compress*, uint8_t*, size_t, uint8_t*, size_t, size_t*" +Function,+,compress_decode_streamed,_Bool,"Compress*, CompressIoCallback, void*, CompressIoCallback, void*" Function,+,compress_encode,_Bool,"Compress*, uint8_t*, size_t, uint8_t*, size_t, size_t*" Function,+,compress_free,void,Compress* Function,+,compress_icon_alloc,CompressIcon*,size_t Function,+,compress_icon_decode,void,"CompressIcon*, const uint8_t*, uint8_t**" Function,+,compress_icon_free,void,CompressIcon* +Function,+,compress_stream_decoder_alloc,CompressStreamDecoder*,"CompressType, const void*, CompressIoCallback, void*" +Function,+,compress_stream_decoder_free,void,CompressStreamDecoder* +Function,+,compress_stream_decoder_read,_Bool,"CompressStreamDecoder*, uint8_t*, size_t" +Function,+,compress_stream_decoder_rewind,_Bool,CompressStreamDecoder* +Function,+,compress_stream_decoder_seek,_Bool,"CompressStreamDecoder*, size_t" +Function,+,compress_stream_decoder_tell,size_t,CompressStreamDecoder* Function,-,copysign,double,"double, double" Function,-,copysignf,float,"float, float" Function,-,copysignl,long double,"long double, long double" @@ -1203,13 +1210,22 @@ Function,+,furi_event_flag_free,void,FuriEventFlag* Function,+,furi_event_flag_get,uint32_t,FuriEventFlag* Function,+,furi_event_flag_set,uint32_t,"FuriEventFlag*, uint32_t" Function,+,furi_event_flag_wait,uint32_t,"FuriEventFlag*, uint32_t, uint32_t, uint32_t" -Function,-,furi_event_loop_alloc,FuriEventLoop*, -Function,-,furi_event_loop_free,void,FuriEventLoop* -Function,-,furi_event_loop_message_queue_subscribe,void,"FuriEventLoop*, FuriMessageQueue*, FuriEventLoopEvent, FuriEventLoopMessageQueueCallback, void*" -Function,-,furi_event_loop_message_queue_unsubscribe,void,"FuriEventLoop*, FuriMessageQueue*" -Function,-,furi_event_loop_run,void,FuriEventLoop* -Function,-,furi_event_loop_stop,void,FuriEventLoop* -Function,-,furi_event_loop_tick_set,void,"FuriEventLoop*, uint32_t, FuriEventLoopTickCallback, void*" +Function,+,furi_event_loop_alloc,FuriEventLoop*, +Function,+,furi_event_loop_free,void,FuriEventLoop* +Function,+,furi_event_loop_message_queue_subscribe,void,"FuriEventLoop*, FuriMessageQueue*, FuriEventLoopEvent, FuriEventLoopMessageQueueCallback, void*" +Function,+,furi_event_loop_message_queue_unsubscribe,void,"FuriEventLoop*, FuriMessageQueue*" +Function,+,furi_event_loop_pend_callback,void,"FuriEventLoop*, FuriEventLoopPendingCallback, void*" +Function,+,furi_event_loop_run,void,FuriEventLoop* +Function,+,furi_event_loop_stop,void,FuriEventLoop* +Function,+,furi_event_loop_tick_set,void,"FuriEventLoop*, uint32_t, FuriEventLoopTickCallback, void*" +Function,+,furi_event_loop_timer_alloc,FuriEventLoopTimer*,"FuriEventLoop*, FuriEventLoopTimerCallback, FuriEventLoopTimerType, void*" +Function,+,furi_event_loop_timer_free,void,FuriEventLoopTimer* +Function,+,furi_event_loop_timer_get_interval,uint32_t,const FuriEventLoopTimer* +Function,+,furi_event_loop_timer_get_remaining_time,uint32_t,const FuriEventLoopTimer* +Function,+,furi_event_loop_timer_is_running,_Bool,const FuriEventLoopTimer* +Function,+,furi_event_loop_timer_restart,void,FuriEventLoopTimer* +Function,+,furi_event_loop_timer_start,void,"FuriEventLoopTimer*, uint32_t" +Function,+,furi_event_loop_timer_stop,void,FuriEventLoopTimer* Function,+,furi_get_tick,uint32_t, Function,+,furi_hal_adc_acquire,FuriHalAdcHandle*, Function,+,furi_hal_adc_configure,void,FuriHalAdcHandle* @@ -1267,9 +1283,6 @@ Function,+,furi_hal_bus_enable,void,FuriHalBus Function,+,furi_hal_bus_init_early,void, Function,+,furi_hal_bus_is_enabled,_Bool,FuriHalBus Function,+,furi_hal_bus_reset,void,FuriHalBus -Function,+,furi_hal_ccid_ccid_insert_smartcard,void, -Function,+,furi_hal_ccid_ccid_remove_smartcard,void, -Function,+,furi_hal_ccid_set_callbacks,void,"CcidCallbacks*, void*" Function,+,furi_hal_cdc_get_ctrl_line_state,uint8_t,uint8_t Function,+,furi_hal_cdc_get_port_settings,usb_cdc_line_coding*,uint8_t Function,+,furi_hal_cdc_receive,int32_t,"uint8_t, uint8_t*, uint16_t" @@ -1397,6 +1410,7 @@ Function,+,furi_hal_infrared_set_tx_output,void,FuriHalInfraredTxPin Function,-,furi_hal_init,void, Function,-,furi_hal_init_early,void, Function,+,furi_hal_interrupt_get_name,const char*,uint8_t +Function,+,furi_hal_interrupt_get_time_in_isr_total,uint32_t, Function,-,furi_hal_interrupt_init,void, Function,+,furi_hal_interrupt_set_isr,void,"FuriHalInterruptId, FuriHalInterruptISR, void*" Function,+,furi_hal_interrupt_set_isr_ex,void,"FuriHalInterruptId, FuriHalInterruptPriority, FuriHalInterruptISR, void*" @@ -1651,6 +1665,9 @@ Function,+,furi_hal_subghz_stop_async_tx,void, Function,+,furi_hal_subghz_tx,_Bool, Function,+,furi_hal_subghz_write_packet,void,"const uint8_t*, uint8_t" Function,+,furi_hal_switch,void,void* +Function,+,furi_hal_usb_ccid_insert_smartcard,void, +Function,+,furi_hal_usb_ccid_remove_smartcard,void, +Function,+,furi_hal_usb_ccid_set_callbacks,void,"CcidCallbacks*, void*" Function,+,furi_hal_usb_disable,void, Function,+,furi_hal_usb_enable,void, Function,+,furi_hal_usb_get_config,FuriHalUsbInterface*, @@ -1831,6 +1848,7 @@ Function,+,furi_thread_join,_Bool,FuriThread* Function,+,furi_thread_list_alloc,FuriThreadList*, Function,+,furi_thread_list_free,void,FuriThreadList* Function,+,furi_thread_list_get_at,FuriThreadListItem*,"FuriThreadList*, size_t" +Function,+,furi_thread_list_get_isr_time,float,FuriThreadList* Function,+,furi_thread_list_get_or_insert,FuriThreadListItem*,"FuriThreadList*, FuriThread*" Function,+,furi_thread_list_process,void,"FuriThreadList*, uint32_t, uint32_t" Function,+,furi_thread_list_size,size_t,FuriThreadList* @@ -1841,10 +1859,12 @@ Function,+,furi_thread_set_context,void,"FuriThread*, void*" Function,+,furi_thread_set_current_priority,void,FuriThreadPriority Function,+,furi_thread_set_name,void,"FuriThread*, const char*" Function,+,furi_thread_set_priority,void,"FuriThread*, FuriThreadPriority" +Function,+,furi_thread_set_signal_callback,void,"FuriThread*, FuriThreadSignalCallback, void*" Function,+,furi_thread_set_stack_size,void,"FuriThread*, size_t" Function,+,furi_thread_set_state_callback,void,"FuriThread*, FuriThreadStateCallback" Function,+,furi_thread_set_state_context,void,"FuriThread*, void*" Function,+,furi_thread_set_stdout_callback,void,FuriThreadStdoutWriteCallback +Function,+,furi_thread_signal,_Bool,"const FuriThread*, uint32_t, void*" Function,+,furi_thread_start,void,FuriThread* Function,+,furi_thread_stdout_flush,int32_t, Function,+,furi_thread_stdout_write,size_t,"const char*, size_t" @@ -2200,10 +2220,12 @@ Function,-,llrintl,long long int,long double Function,-,llround,long long int,double Function,-,llroundf,long long int,float Function,-,llroundl,long long int,long double +Function,+,loader_get_application_name,_Bool,"Loader*, FuriString*" Function,+,loader_get_pubsub,FuriPubSub*,Loader* Function,+,loader_is_locked,_Bool,Loader* Function,+,loader_lock,_Bool,Loader* Function,+,loader_show_menu,void,Loader* +Function,+,loader_signal,_Bool,"Loader*, uint32_t, void*" Function,+,loader_start,LoaderStatus,"Loader*, const char*, const char*, FuriString*" Function,+,loader_start_detached_with_gui_error,void,"Loader*, const char*, const char*" Function,+,loader_start_with_gui_error,LoaderStatus,"Loader*, const char*, const char*" @@ -2505,6 +2527,7 @@ Function,+,mf_classic_save,_Bool,"const MfClassicData*, FlipperFormat*" Function,+,mf_classic_set_block_read,void,"MfClassicData*, uint8_t, MfClassicBlock*" Function,+,mf_classic_set_key_found,void,"MfClassicData*, uint8_t, MfClassicKeyType, uint64_t" Function,+,mf_classic_set_key_not_found,void,"MfClassicData*, uint8_t, MfClassicKeyType" +Function,+,mf_classic_set_sector_trailer_read,void,"MfClassicData*, uint8_t, MfClassicSectorTrailer*" Function,+,mf_classic_set_uid,_Bool,"MfClassicData*, const uint8_t*, size_t" Function,+,mf_classic_value_to_block,void,"int32_t, uint8_t, MfClassicBlock*" Function,+,mf_classic_verify,_Bool,"MfClassicData*, const FuriString*" @@ -2553,6 +2576,11 @@ Function,+,mf_plus_reset,void,MfPlusData* Function,+,mf_plus_save,_Bool,"const MfPlusData*, FlipperFormat*" Function,+,mf_plus_set_uid,_Bool,"MfPlusData*, const uint8_t*, size_t" Function,+,mf_plus_verify,_Bool,"MfPlusData*, const FuriString*" +Function,+,mf_ultralight_3des_decrypt,void,"mbedtls_des3_context*, const uint8_t*, const uint8_t*, const uint8_t*, const uint8_t, uint8_t*" +Function,+,mf_ultralight_3des_encrypt,void,"mbedtls_des3_context*, const uint8_t*, const uint8_t*, const uint8_t*, const uint8_t, uint8_t*" +Function,+,mf_ultralight_3des_get_key,const uint8_t*,const MfUltralightData* +Function,+,mf_ultralight_3des_key_valid,_Bool,const MfUltralightData* +Function,+,mf_ultralight_3des_shift_data,void,uint8_t* Function,+,mf_ultralight_alloc,MfUltralightData*, Function,+,mf_ultralight_copy,void,"MfUltralightData*, const MfUltralightData*" Function,+,mf_ultralight_detect_protocol,_Bool,const Iso14443_3aData* @@ -2573,7 +2601,8 @@ Function,+,mf_ultralight_is_equal,_Bool,"const MfUltralightData*, const MfUltral Function,+,mf_ultralight_is_page_pwd_or_pack,_Bool,"MfUltralightType, uint16_t" Function,+,mf_ultralight_load,_Bool,"MfUltralightData*, FlipperFormat*, uint32_t" Function,+,mf_ultralight_poller_auth_pwd,MfUltralightError,"MfUltralightPoller*, MfUltralightPollerAuthContext*" -Function,+,mf_ultralight_poller_authenticate,MfUltralightError,MfUltralightPoller* +Function,+,mf_ultralight_poller_authenticate_end,MfUltralightError,"MfUltralightPoller*, const uint8_t*, const uint8_t*, uint8_t*" +Function,+,mf_ultralight_poller_authenticate_start,MfUltralightError,"MfUltralightPoller*, const uint8_t*, uint8_t*" Function,+,mf_ultralight_poller_read_counter,MfUltralightError,"MfUltralightPoller*, uint8_t, MfUltralightCounter*" Function,+,mf_ultralight_poller_read_page,MfUltralightError,"MfUltralightPoller*, uint8_t, MfUltralightPageReadCommandData*" Function,+,mf_ultralight_poller_read_page_from_sector,MfUltralightError,"MfUltralightPoller*, uint8_t, uint8_t, MfUltralightPageReadCommandData*" @@ -3447,6 +3476,8 @@ Function,+,tar_archive_file_finalize,_Bool,TarArchive* Function,+,tar_archive_finalize,_Bool,TarArchive* Function,+,tar_archive_free,void,TarArchive* Function,+,tar_archive_get_entries_count,int32_t,TarArchive* +Function,+,tar_archive_get_mode_for_path,TarOpenMode,const char* +Function,+,tar_archive_get_read_progress,_Bool,"TarArchive*, int32_t*, int32_t*" Function,+,tar_archive_open,_Bool,"TarArchive*, const char*, TarOpenMode" Function,+,tar_archive_set_file_callback,void,"TarArchive*, tar_unpack_file_cb, void*" Function,+,tar_archive_store_data,_Bool,"TarArchive*, const char*, const uint8_t*, const int32_t" @@ -3646,6 +3677,7 @@ Variable,-,_sys_nerr,int, Variable,-,ble_profile_hid,const FuriHalBleProfileTemplate*, Variable,-,ble_profile_serial,const FuriHalBleProfileTemplate*, Variable,+,cli_vcp,CliSession, +Variable,+,compress_config_heatshrink_default,const CompressConfigHeatshrink, Variable,+,firmware_api_interface,const ElfApiInterface*, Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus, Variable,+,furi_hal_i2c_bus_power,FuriHalI2cBus, diff --git a/targets/f7/ble_glue/app_conf.h b/targets/f7/ble_glue/app_conf.h index d0e089eb1ea..43be8129dcc 100644 --- a/targets/f7/ble_glue/app_conf.h +++ b/targets/f7/ble_glue/app_conf.h @@ -26,12 +26,12 @@ * Define PHY */ #define ALL_PHYS_PREFERENCE 0x00 -#define RX_2M_PREFERRED 0x02 -#define TX_2M_PREFERRED 0x02 -#define TX_1M 0x01 -#define TX_2M 0x02 -#define RX_1M 0x01 -#define RX_2M 0x02 +#define RX_2M_PREFERRED 0x02 +#define TX_2M_PREFERRED 0x02 +#define TX_1M 0x01 +#define TX_2M 0x02 +#define RX_1M 0x01 +#define RX_2M 0x02 /****************************************************************************** * BLE Stack diff --git a/targets/f7/ble_glue/app_debug.c b/targets/f7/ble_glue/app_debug.c index eab17e5b79c..37263849a16 100644 --- a/targets/f7/ble_glue/app_debug.c +++ b/targets/f7/ble_glue/app_debug.c @@ -19,15 +19,15 @@ typedef PACKED_STRUCT { } APPD_GpioConfig_t; -#define GPIO_NBR_OF_RF_SIGNALS 9 -#define GPIO_CFG_NBR_OF_FEATURES 34 -#define NBR_OF_TRACES_CONFIG_PARAMETERS 4 +#define GPIO_NBR_OF_RF_SIGNALS 9 +#define GPIO_CFG_NBR_OF_FEATURES 34 +#define NBR_OF_TRACES_CONFIG_PARAMETERS 4 #define NBR_OF_GENERAL_CONFIG_PARAMETERS 4 /** * THIS SHALL BE SET TO A VALUE DIFFERENT FROM 0 ONLY ON REQUEST FROM ST SUPPORT */ -#define BLE_DTB_CFG 0 +#define BLE_DTB_CFG 0 // #define BLE_DTB_CFG 7 #define SYS_DBG_CFG1 (SHCI_C2_DEBUG_OPTIONS_IPCORE_LP | SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_EN) diff --git a/targets/f7/ble_glue/ble_event_thread.c b/targets/f7/ble_glue/ble_event_thread.c index deafbb9a484..c6bc5684613 100644 --- a/targets/f7/ble_glue/ble_event_thread.c +++ b/targets/f7/ble_glue/ble_event_thread.c @@ -9,8 +9,8 @@ #define TAG "BleEvt" -#define BLE_EVENT_THREAD_FLAG_SHCI_EVENT (1UL << 0) -#define BLE_EVENT_THREAD_FLAG_HCI_EVENT (1UL << 1) +#define BLE_EVENT_THREAD_FLAG_SHCI_EVENT (1UL << 0) +#define BLE_EVENT_THREAD_FLAG_HCI_EVENT (1UL << 1) #define BLE_EVENT_THREAD_FLAG_KILL_THREAD (1UL << 2) #define BLE_EVENT_THREAD_FLAG_ALL \ diff --git a/targets/f7/ble_glue/ble_glue.c b/targets/f7/ble_glue/ble_glue.c index c50360361f3..73bb41badc8 100644 --- a/targets/f7/ble_glue/ble_glue.c +++ b/targets/f7/ble_glue/ble_glue.c @@ -370,7 +370,7 @@ static void ble_glue_clear_shared_memory(void) { } bool ble_glue_reinit_c2(void) { - return (SHCI_C2_Reinit() == SHCI_Success); + return SHCI_C2_Reinit() == SHCI_Success; } BleGlueCommandResult ble_glue_fus_stack_delete(void) { diff --git a/targets/f7/ble_glue/compiler.h b/targets/f7/ble_glue/compiler.h index 1d32c2a2edc..7446b7941b7 100644 --- a/targets/f7/ble_glue/compiler.h +++ b/targets/f7/ble_glue/compiler.h @@ -65,7 +65,7 @@ * Usage: PACKED(struct) myStruct_s * PACKED(union) myStruct_s */ -#define PACKED(decl) decl __attribute__((packed)) +#define PACKED(decl) decl __attribute__((packed)) /** * @brief SECTION @@ -79,7 +79,7 @@ * Use the ALIGN_DEF macro to specify the alignment of a variable. * Usage: ALIGN_DEF(4) */ -#define ALIGN_DEF(N) __attribute__((aligned(N))) +#define ALIGN_DEF(N) __attribute__((aligned(N))) /** * @brief NO_INIT @@ -87,7 +87,7 @@ * Usage: NO_INIT(int my_no_init_var) * Usage: NO_INIT(uint16_t my_no_init_array[10]) */ -#define NO_INIT(var) var __attribute__((section(".noinit"))) +#define NO_INIT(var) var __attribute__((section(".noinit"))) /** * @brief This is the section dedicated to Keil toolchain @@ -105,7 +105,7 @@ * Usage: PACKED(struct) myStruct_s * PACKED(union) myStruct_s */ -#define PACKED(decl) decl __attribute__((packed)) +#define PACKED(decl) decl __attribute__((packed)) /** * @brief SECTION @@ -119,7 +119,7 @@ * Use the ALIGN_DEF macro to specify the alignment of a variable. * Usage: ALIGN_DEF(4) */ -#define ALIGN_DEF(N) __attribute__((aligned(N))) +#define ALIGN_DEF(N) __attribute__((aligned(N))) /** * @brief NO_INIT @@ -127,7 +127,7 @@ * Usage: NO_INIT(int my_no_init_var) * Usage: NO_INIT(uint16_t my_no_init_array[10]) */ -#define NO_INIT(var) var __attribute__((section("NoInit"))) +#define NO_INIT(var) var __attribute__((section("NoInit"))) #else diff --git a/targets/f7/ble_glue/extra_beacon.c b/targets/f7/ble_glue/extra_beacon.c index 60338cb76bd..0fd452a5a6d 100644 --- a/targets/f7/ble_glue/extra_beacon.c +++ b/targets/f7/ble_glue/extra_beacon.c @@ -159,4 +159,4 @@ const GapExtraBeaconConfig* gap_extra_beacon_get_config(void) { } return &extra_beacon.last_config; -} \ No newline at end of file +} diff --git a/targets/f7/ble_glue/furi_ble/gatt.h b/targets/f7/ble_glue/furi_ble/gatt.h index 5a33e9e542e..d4d85181a74 100644 --- a/targets/f7/ble_glue/furi_ble/gatt.h +++ b/targets/f7/ble_glue/furi_ble/gatt.h @@ -55,8 +55,8 @@ typedef struct { Char_UUID_t uuid; // Some packed bitfields to save space BleGattCharacteristicDataType data_prop_type : 2; - uint8_t is_variable : 2; - uint8_t uuid_type : 2; + uint8_t is_variable : 2; + uint8_t uuid_type : 2; uint8_t char_properties; uint8_t security_permissions; uint8_t gatt_evt_mask; diff --git a/targets/f7/ble_glue/gap.c b/targets/f7/ble_glue/gap.c index 2235a8da334..9cd33456b41 100644 --- a/targets/f7/ble_glue/gap.c +++ b/targets/f7/ble_glue/gap.c @@ -11,7 +11,7 @@ #define TAG "BleGap" -#define FAST_ADV_TIMEOUT 30000 +#define FAST_ADV_TIMEOUT 30000 #define INITIAL_ADV_TIMEOUT 60000 #define GAP_INTERVAL_TO_MS(x) (uint16_t)((x) * 1.25) diff --git a/targets/f7/ble_glue/hsem_map.h b/targets/f7/ble_glue/hsem_map.h index 9a5f51d204c..2166d069689 100644 --- a/targets/f7/ble_glue/hsem_map.h +++ b/targets/f7/ble_glue/hsem_map.h @@ -8,7 +8,7 @@ * Index of the semaphore used the prevent conflicts after standby sleep. * Each CPUs takes this semaphore at standby wakeup until conflicting elements are restored. */ -#define CFG_HW_PWR_STANDBY_SEMID 10 +#define CFG_HW_PWR_STANDBY_SEMID 10 /** * The CPU2 may be configured to store the Thread persistent data either in internal NVM storage on CPU2 or in * SRAM2 buffer provided by the user application. This can be configured with the system command SHCI_C2_Config() diff --git a/targets/f7/ble_glue/services/battery_service.c b/targets/f7/ble_glue/services/battery_service.c index 4250b356c9c..66aafc49592 100644 --- a/targets/f7/ble_glue/services/battery_service.c +++ b/targets/f7/ble_glue/services/battery_service.c @@ -30,10 +30,10 @@ enum { }; typedef struct { - uint8_t present : 2; + uint8_t present : 2; uint8_t discharging : 2; - uint8_t charging : 2; - uint8_t level : 2; + uint8_t charging : 2; + uint8_t level : 2; } BattrySvcPowerState; _Static_assert(sizeof(BattrySvcPowerState) == 1, "Incorrect structure size"); diff --git a/targets/f7/ble_glue/services/serial_service.h b/targets/f7/ble_glue/services/serial_service.h index 91ad886e061..4d2b069d145 100644 --- a/targets/f7/ble_glue/services/serial_service.h +++ b/targets/f7/ble_glue/services/serial_service.h @@ -11,7 +11,7 @@ extern "C" { * Serial service. Implements RPC over BLE, with flow control. */ -#define BLE_SVC_SERIAL_DATA_LEN_MAX (486) +#define BLE_SVC_SERIAL_DATA_LEN_MAX (486) #define BLE_SVC_SERIAL_CHAR_VALUE_LEN_MAX (243) typedef enum { diff --git a/targets/f7/ble_glue/tl_dbg_conf.h b/targets/f7/ble_glue/tl_dbg_conf.h index 240cd5f2faf..53d312b2e73 100644 --- a/targets/f7/ble_glue/tl_dbg_conf.h +++ b/targets/f7/ble_glue/tl_dbg_conf.h @@ -21,7 +21,7 @@ extern "C" { #define TL_HCI_CMD_DBG_EN 1 /* Reports BLE command sent to CPU2 and the command response */ #define TL_HCI_CMD_DBG_RAW_EN \ 0 /* Reports raw data BLE command sent to CPU2 and the command response */ -#define TL_HCI_EVT_DBG_EN 1 /* Reports BLE Asynchronous Events received from CPU2 */ +#define TL_HCI_EVT_DBG_EN 1 /* Reports BLE Asynchronous Events received from CPU2 */ #define TL_HCI_EVT_DBG_RAW_EN 0 /* Reports raw data BLE Asynchronous Events received from CPU2 */ #define TL_MM_DBG_EN 1 /* Reports the informations of the buffer released to CPU2 */ diff --git a/targets/f7/fatfs/fatfs.h b/targets/f7/fatfs/fatfs.h index 8376bf6cc34..2bde80bde4c 100644 --- a/targets/f7/fatfs/fatfs.h +++ b/targets/f7/fatfs/fatfs.h @@ -16,4 +16,4 @@ void fatfs_init(void); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/targets/f7/fatfs/ffconf.h b/targets/f7/fatfs/ffconf.h index 8408a1ec175..08dd5b994b7 100644 --- a/targets/f7/fatfs/ffconf.h +++ b/targets/f7/fatfs/ffconf.h @@ -164,7 +164,7 @@ /* USER CODE BEGIN Volumes */ #define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */ -#define _VOLUME_STRS "SD" +#define _VOLUME_STRS "SD" /* _STR_VOLUME_ID switches string support of volume ID. / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive / number in the path name. _VOLUME_STRS defines the drive ID strings for each @@ -179,8 +179,8 @@ / When multi-partition is enabled (1), each logical drive number can be bound to / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() / funciton will be available. */ -#define _MIN_SS 512 /* 512, 1024, 2048 or 4096 */ -#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */ +#define _MIN_SS 512 /* 512, 1024, 2048 or 4096 */ +#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */ /* These options configure the range of sector size to be supported. (512, 1024, / 2048 or 4096) Always set both 512 for most systems, all type of memory cards and / harddisk. But a larger value may be required for on-board flash memory and some @@ -241,8 +241,8 @@ / lock control is independent of re-entrancy. */ #define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */ -#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ -#define _SYNC_t FuriMutex* +#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ +#define _SYNC_t FuriMutex* /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs / module itself. Note that regardless of this option, file access to different / volume is always re-entrant and volume control functions, f_mount(), f_mkfs() @@ -264,7 +264,7 @@ #if !defined(ff_malloc) && !defined(ff_free) #include #define ff_malloc malloc -#define ff_free free +#define ff_free free #endif #endif /* _FFCONF */ diff --git a/targets/f7/fatfs/sector_cache.c b/targets/f7/fatfs/sector_cache.c index 319dd21732d..a76035a0940 100644 --- a/targets/f7/fatfs/sector_cache.c +++ b/targets/f7/fatfs/sector_cache.c @@ -7,7 +7,7 @@ #include #define SECTOR_SIZE 512 -#define N_SECTORS 8 +#define N_SECTORS 8 typedef struct { uint32_t itr; @@ -53,4 +53,4 @@ void sector_cache_invalidate_range(uint32_t start_sector, uint32_t end_sector) { cache->sectors[sector_i] = 0; } } -} \ No newline at end of file +} diff --git a/targets/f7/fatfs/user_diskio.h b/targets/f7/fatfs/user_diskio.h index db636fbb950..009a17d4bfa 100644 --- a/targets/f7/fatfs/user_diskio.h +++ b/targets/f7/fatfs/user_diskio.h @@ -10,4 +10,4 @@ extern Diskio_drvTypeDef sd_fatfs_driver; #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/targets/f7/furi_hal/furi_hal_bt.c b/targets/f7/furi_hal/furi_hal_bt.c index 3d4e417315d..2d76188da40 100644 --- a/targets/f7/furi_hal/furi_hal_bt.c +++ b/targets/f7/furi_hal/furi_hal_bt.c @@ -21,8 +21,7 @@ #define TAG "FuriHalBt" -#define furi_hal_bt_DEFAULT_MAC_ADDR \ - { 0x6c, 0x7a, 0xd8, 0xac, 0x57, 0x72 } +#define furi_hal_bt_DEFAULT_MAC_ADDR {0x6c, 0x7a, 0xd8, 0xac, 0x57, 0x72} /* Time, in ms, to wait for mode transition before crashing */ #define C2_MODE_SWITCH_TIMEOUT 10000 diff --git a/targets/f7/furi_hal/furi_hal_bus.c b/targets/f7/furi_hal/furi_hal_bus.c index 85b121dc44a..30b3879f612 100644 --- a/targets/f7/furi_hal/furi_hal_bus.c +++ b/targets/f7/furi_hal/furi_hal_bus.c @@ -46,7 +46,7 @@ /* Test macro definitions */ #define FURI_HAL_BUS_IS_ALL_CLEAR(reg, value) (READ_BIT((reg), (value)) == 0UL) -#define FURI_HAL_BUS_IS_ALL_SET(reg, value) (READ_BIT((reg), (value)) == (value)) +#define FURI_HAL_BUS_IS_ALL_SET(reg, value) (READ_BIT((reg), (value)) == (value)) #define FURI_HAL_BUS_IS_CLOCK_ENABLED(bus, value, ...) \ (FURI_HAL_BUS_IS_ALL_SET(RCC->bus##ENR##__VA_ARGS__, (value))) @@ -67,10 +67,10 @@ FURI_HAL_BUS_IS_RESET_ASSERTED(bus, (value), __VA_ARGS__)) /* Control macro definitions */ -#define FURI_HAL_BUS_RESET_ASSERT(bus, value, grp) LL_##bus##_GRP##grp##_ForceReset(value) +#define FURI_HAL_BUS_RESET_ASSERT(bus, value, grp) LL_##bus##_GRP##grp##_ForceReset(value) #define FURI_HAL_BUS_RESET_DEASSERT(bus, value, grp) LL_##bus##_GRP##grp##_ReleaseReset(value) -#define FURI_HAL_BUS_CLOCK_ENABLE(bus, value, grp) LL_##bus##_GRP##grp##_EnableClock(value) +#define FURI_HAL_BUS_CLOCK_ENABLE(bus, value, grp) LL_##bus##_GRP##grp##_EnableClock(value) #define FURI_HAL_BUS_CLOCK_DISABLE(bus, value, grp) LL_##bus##_GRP##grp##_DisableClock(value) #define FURI_HAL_BUS_PERIPH_ENABLE(bus, value, grp) \ diff --git a/targets/f7/furi_hal/furi_hal_clock.c b/targets/f7/furi_hal/furi_hal_clock.c index ca4c7ad4d7a..fd55bf6f2b0 100644 --- a/targets/f7/furi_hal/furi_hal_clock.c +++ b/targets/f7/furi_hal/furi_hal_clock.c @@ -15,10 +15,10 @@ #define CPU_CLOCK_EARLY_HZ 4000000 #define CPU_CLOCK_HSI16_HZ 16000000 -#define CPU_CLOCK_HSE_HZ 32000000 -#define CPU_CLOCK_PLL_HZ 64000000 +#define CPU_CLOCK_HSE_HZ 32000000 +#define CPU_CLOCK_PLL_HZ 64000000 -#define TICK_INT_PRIORITY 15U +#define TICK_INT_PRIORITY 15U #define HS_CLOCK_IS_READY() (LL_RCC_HSE_IsReady() && LL_RCC_HSI_IsReady()) #define LS_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) diff --git a/targets/f7/furi_hal/furi_hal_crypto.c b/targets/f7/furi_hal/furi_hal_crypto.c index 236573bca8d..1879eb2caee 100644 --- a/targets/f7/furi_hal/furi_hal_crypto.c +++ b/targets/f7/furi_hal/furi_hal_crypto.c @@ -11,32 +11,32 @@ #define TAG "FuriHalCrypto" #define ENCLAVE_FACTORY_KEY_SLOTS 10 -#define ENCLAVE_SIGNATURE_SIZE 16 +#define ENCLAVE_SIGNATURE_SIZE 16 -#define CRYPTO_BLK_LEN (4 * sizeof(uint32_t)) +#define CRYPTO_BLK_LEN (4 * sizeof(uint32_t)) #define CRYPTO_TIMEOUT_US (1000000) -#define CRYPTO_MODE_ENCRYPT 0U -#define CRYPTO_MODE_INIT (AES_CR_MODE_0) -#define CRYPTO_MODE_DECRYPT (AES_CR_MODE_1) +#define CRYPTO_MODE_ENCRYPT 0U +#define CRYPTO_MODE_INIT (AES_CR_MODE_0) +#define CRYPTO_MODE_DECRYPT (AES_CR_MODE_1) #define CRYPTO_MODE_DECRYPT_INIT (AES_CR_MODE_0 | AES_CR_MODE_1) #define CRYPTO_DATATYPE_32B 0U #define CRYPTO_KEYSIZE_256B (AES_CR_KEYSIZE) -#define CRYPTO_AES_CBC (AES_CR_CHMOD_0) +#define CRYPTO_AES_CBC (AES_CR_CHMOD_0) -#define CRYPTO_AES_CTR (AES_CR_CHMOD_1) -#define CRYPTO_CTR_IV_LEN (12U) +#define CRYPTO_AES_CTR (AES_CR_CHMOD_1) +#define CRYPTO_CTR_IV_LEN (12U) #define CRYPTO_CTR_CTR_LEN (4U) -#define CRYPTO_AES_GCM (AES_CR_CHMOD_1 | AES_CR_CHMOD_0) -#define CRYPTO_GCM_IV_LEN (12U) -#define CRYPTO_GCM_CTR_LEN (4U) -#define CRYPTO_GCM_TAG_LEN (16U) -#define CRYPTO_GCM_PH_INIT (0x0U << AES_CR_GCMPH_Pos) -#define CRYPTO_GCM_PH_HEADER (AES_CR_GCMPH_0) +#define CRYPTO_AES_GCM (AES_CR_CHMOD_1 | AES_CR_CHMOD_0) +#define CRYPTO_GCM_IV_LEN (12U) +#define CRYPTO_GCM_CTR_LEN (4U) +#define CRYPTO_GCM_TAG_LEN (16U) +#define CRYPTO_GCM_PH_INIT (0x0U << AES_CR_GCMPH_Pos) +#define CRYPTO_GCM_PH_HEADER (AES_CR_GCMPH_0) #define CRYPTO_GCM_PH_PAYLOAD (AES_CR_GCMPH_1) -#define CRYPTO_GCM_PH_FINAL (AES_CR_GCMPH_1 | AES_CR_GCMPH_0) +#define CRYPTO_GCM_PH_FINAL (AES_CR_GCMPH_1 | AES_CR_GCMPH_0) static FuriMutex* furi_hal_crypto_mutex = NULL; static bool furi_hal_crypto_mode_init_done = false; @@ -192,7 +192,7 @@ bool furi_hal_crypto_enclave_store_key(FuriHalCryptoKey* key, uint8_t* slot) { SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_StoreUsrKey(&pParam, slot); furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk); - return (shci_state == SHCI_Success); + return shci_state == SHCI_Success; } static void crypto_key_init(uint32_t* key, uint32_t* iv) { @@ -291,7 +291,7 @@ bool furi_hal_crypto_enclave_unload_key(uint8_t slot) { furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk); - return (shci_state == SHCI_Success); + return shci_state == SHCI_Success; } bool furi_hal_crypto_load_key(const uint8_t* key, const uint8_t* iv) { @@ -631,7 +631,7 @@ static bool furi_hal_crypto_gcm_compare_tag(const uint8_t* tag1, const uint8_t* diff |= tag1[i] ^ tag2[i]; } - return (diff == 0); + return diff == 0; } bool furi_hal_crypto_gcm( diff --git a/targets/f7/furi_hal/furi_hal_debug.c b/targets/f7/furi_hal/furi_hal_debug.c index 7d1488fa521..f97673ea159 100644 --- a/targets/f7/furi_hal/furi_hal_debug.c +++ b/targets/f7/furi_hal/furi_hal_debug.c @@ -38,4 +38,4 @@ void furi_hal_debug_disable(void) { bool furi_hal_debug_is_gdb_session_active(void) { return furi_hal_debug_gdb_session_active; -} \ No newline at end of file +} diff --git a/targets/f7/furi_hal/furi_hal_flash.c b/targets/f7/furi_hal/furi_hal_flash.c index 8999edaedb2..8bf1ac70271 100644 --- a/targets/f7/furi_hal/furi_hal_flash.c +++ b/targets/f7/furi_hal/furi_hal_flash.c @@ -22,21 +22,21 @@ #define FURI_LOG_T(...) #endif -#define FURI_HAL_CRITICAL_MSG "Critical flash operation fail" -#define FURI_HAL_FLASH_READ_BLOCK (8U) -#define FURI_HAL_FLASH_WRITE_BLOCK (8U) -#define FURI_HAL_FLASH_PAGE_SIZE (4096U) +#define FURI_HAL_CRITICAL_MSG "Critical flash operation fail" +#define FURI_HAL_FLASH_READ_BLOCK (8U) +#define FURI_HAL_FLASH_WRITE_BLOCK (8U) +#define FURI_HAL_FLASH_PAGE_SIZE (4096U) #define FURI_HAL_FLASH_CYCLES_COUNT (10000U) -#define FURI_HAL_FLASH_TIMEOUT (1000U) -#define FURI_HAL_FLASH_KEY1 (0x45670123U) -#define FURI_HAL_FLASH_KEY2 (0xCDEF89ABU) -#define FURI_HAL_FLASH_TOTAL_PAGES (256U) +#define FURI_HAL_FLASH_TIMEOUT (1000U) +#define FURI_HAL_FLASH_KEY1 (0x45670123U) +#define FURI_HAL_FLASH_KEY2 (0xCDEF89ABU) +#define FURI_HAL_FLASH_TOTAL_PAGES (256U) #define FURI_HAL_FLASH_SR_ERRORS \ (FLASH_SR_OPERR | FLASH_SR_PROGERR | FLASH_SR_WRPERR | FLASH_SR_PGAERR | FLASH_SR_SIZERR | \ FLASH_SR_PGSERR | FLASH_SR_MISERR | FLASH_SR_FASTERR | FLASH_SR_RDERR | FLASH_SR_OPTVERR) -#define FURI_HAL_FLASH_OPT_KEY1 (0x08192A3BU) -#define FURI_HAL_FLASH_OPT_KEY2 (0x4C5D6E7FU) +#define FURI_HAL_FLASH_OPT_KEY1 (0x08192A3BU) +#define FURI_HAL_FLASH_OPT_KEY2 (0x4C5D6E7FU) #define FURI_HAL_FLASH_OB_TOTAL_WORDS (0x80 / (sizeof(uint32_t) * 2)) /* STM32CubeWB/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_RfWithFlash/Core/Src/flash_driver.c @@ -319,9 +319,9 @@ void furi_hal_flash_erase(uint8_t page) { op_stat = DWT->CYCCNT - op_stat; FURI_LOG_T( TAG, - "erase took %lu clocks or %fus", + "erase took %lu clocks or %luus", op_stat, - (double)((float)op_stat / (float)furi_hal_cortex_instructions_per_microsecond())); + op_stat / furi_hal_cortex_instructions_per_microsecond()); } static inline void furi_hal_flash_write_dword_internal_nowait(size_t address, uint64_t* data) { @@ -448,9 +448,9 @@ void furi_hal_flash_program_page(const uint8_t page, const uint8_t* data, uint16 op_stat = DWT->CYCCNT - op_stat; FURI_LOG_T( TAG, - "program_page took %lu clocks or %fus", + "program_page took %lu clocks or %luus", op_stat, - (double)((float)op_stat / (float)furi_hal_cortex_instructions_per_microsecond())); + op_stat / furi_hal_cortex_instructions_per_microsecond()); } int16_t furi_hal_flash_get_page_number(size_t address) { @@ -509,8 +509,7 @@ typedef struct { uint32_t* ob_register_address; } FuriHalFlashObMapping; -#define OB_REG_DEF(INDEX, REG) \ - { .ob_reg = INDEX, .ob_register_address = (uint32_t*)(REG) } +#define OB_REG_DEF(INDEX, REG) {.ob_reg = INDEX, .ob_register_address = (uint32_t*)(REG)} static const FuriHalFlashObMapping furi_hal_flash_ob_reg_map[FURI_HAL_FLASH_OB_TOTAL_WORDS] = { OB_REG_DEF(FuriHalFlashObRegisterUserRead, (&FLASH->OPTR)), diff --git a/targets/f7/furi_hal/furi_hal_flash.h b/targets/f7/furi_hal/furi_hal_flash.h index 6a5d4222268..c20f9074959 100644 --- a/targets/f7/furi_hal/furi_hal_flash.h +++ b/targets/f7/furi_hal/furi_hal_flash.h @@ -9,8 +9,8 @@ extern "C" { #endif #define FURI_HAL_FLASH_OB_RAW_SIZE_BYTES 0x80 -#define FURI_HAL_FLASH_OB_SIZE_WORDS (FURI_HAL_FLASH_OB_RAW_SIZE_BYTES / sizeof(uint32_t)) -#define FURI_HAL_FLASH_OB_TOTAL_VALUES (FURI_HAL_FLASH_OB_SIZE_WORDS / 2) +#define FURI_HAL_FLASH_OB_SIZE_WORDS (FURI_HAL_FLASH_OB_RAW_SIZE_BYTES / sizeof(uint32_t)) +#define FURI_HAL_FLASH_OB_TOTAL_VALUES (FURI_HAL_FLASH_OB_SIZE_WORDS / 2) typedef union { uint8_t bytes[FURI_HAL_FLASH_OB_RAW_SIZE_BYTES]; diff --git a/targets/f7/furi_hal/furi_hal_gpio.c b/targets/f7/furi_hal/furi_hal_gpio.c index ec3e725c595..a020e9d7c11 100644 --- a/targets/f7/furi_hal/furi_hal_gpio.c +++ b/targets/f7/furi_hal/furi_hal_gpio.c @@ -39,11 +39,11 @@ static uint32_t furi_hal_gpio_invalid_argument_crash(void) { furi_hal_gpio_invalid_argument_crash()) #define GET_SYSCFG_EXTI_PORT(port) GPIO_PORT_MAP(port, LL_SYSCFG_EXTI_PORT) -#define GET_SYSCFG_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_SYSCFG_EXTI_LINE) -#define GET_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_EXTI_LINE_) +#define GET_SYSCFG_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_SYSCFG_EXTI_LINE) +#define GET_EXTI_LINE(pin) GPIO_PIN_MAP(pin, LL_EXTI_LINE_) #define GET_PWR_PORT(port) GPIO_PORT_MAP(port, LL_PWR_GPIO_) -#define GET_PWR_PIN(pin) GPIO_PIN_MAP(pin, LL_PWR_GPIO_BIT_) +#define GET_PWR_PIN(pin) GPIO_PIN_MAP(pin, LL_PWR_GPIO_BIT_) static volatile GpioInterrupt gpio_interrupt[GPIO_NUMBER]; @@ -249,7 +249,7 @@ void furi_hal_gpio_remove_int_callback(const GpioPin* gpio) { FURI_CRITICAL_EXIT(); } -FURI_ALWAYS_STATIC_INLINE void furi_hal_gpio_int_call(uint16_t pin_num) { +FURI_ALWAYS_INLINE static void furi_hal_gpio_int_call(uint16_t pin_num) { if(gpio_interrupt[pin_num].callback) { gpio_interrupt[pin_num].callback(gpio_interrupt[pin_num].context); } diff --git a/targets/f7/furi_hal/furi_hal_ibutton.c b/targets/f7/furi_hal/furi_hal_ibutton.c index 07cf8de6e21..4f7c5e4732c 100644 --- a/targets/f7/furi_hal/furi_hal_ibutton.c +++ b/targets/f7/furi_hal/furi_hal_ibutton.c @@ -8,7 +8,8 @@ #include #define TAG "FuriHalIbutton" -#define FURI_HAL_IBUTTON_TIMER TIM1 + +#define FURI_HAL_IBUTTON_TIMER TIM1 #define FURI_HAL_IBUTTON_TIMER_BUS FuriHalBusTIM1 #define FURI_HAL_IBUTTON_TIMER_IRQ FuriHalInterruptIdTim1UpTim16 diff --git a/targets/f7/furi_hal/furi_hal_idle_timer.h b/targets/f7/furi_hal/furi_hal_idle_timer.h index e1ffb1b25f4..76d2238f94a 100644 --- a/targets/f7/furi_hal/furi_hal_idle_timer.h +++ b/targets/f7/furi_hal/furi_hal_idle_timer.h @@ -8,7 +8,7 @@ // Timer used for tickless idle #define FURI_HAL_IDLE_TIMER_MAX 0xFFFF -#define FURI_HAL_IDLE_TIMER LPTIM1 +#define FURI_HAL_IDLE_TIMER LPTIM1 #define FURI_HAL_IDLE_TIMER_IRQ LPTIM1_IRQn static inline void furi_hal_idle_timer_init() { diff --git a/targets/f7/furi_hal/furi_hal_infrared.c b/targets/f7/furi_hal/furi_hal_infrared.c index a0b166fad4a..029d103cb59 100644 --- a/targets/f7/furi_hal/furi_hal_infrared.c +++ b/targets/f7/furi_hal/furi_hal_infrared.c @@ -11,7 +11,7 @@ #include #define INFRARED_TIM_TX_DMA_BUFFER_SIZE 200 -#define INFRARED_POLARITY_SHIFT 1 +#define INFRARED_POLARITY_SHIFT 1 #define INFRARED_TX_CCMR_HIGH \ (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_PWM2) /* Mark time - enable PWM2 mode */ @@ -19,23 +19,23 @@ (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_FORCED_INACTIVE) /* Space time - force low */ /* DMA Channels definition */ -#define INFRARED_DMA DMA2 +#define INFRARED_DMA DMA2 #define INFRARED_DMA_CH1_CHANNEL LL_DMA_CHANNEL_1 #define INFRARED_DMA_CH2_CHANNEL LL_DMA_CHANNEL_2 -#define INFRARED_DMA_CH1_IRQ FuriHalInterruptIdDma2Ch1 -#define INFRARED_DMA_CH2_IRQ FuriHalInterruptIdDma2Ch2 -#define INFRARED_DMA_CH1_DEF INFRARED_DMA, INFRARED_DMA_CH1_CHANNEL -#define INFRARED_DMA_CH2_DEF INFRARED_DMA, INFRARED_DMA_CH2_CHANNEL +#define INFRARED_DMA_CH1_IRQ FuriHalInterruptIdDma2Ch1 +#define INFRARED_DMA_CH2_IRQ FuriHalInterruptIdDma2Ch2 +#define INFRARED_DMA_CH1_DEF INFRARED_DMA, INFRARED_DMA_CH1_CHANNEL +#define INFRARED_DMA_CH2_DEF INFRARED_DMA, INFRARED_DMA_CH2_CHANNEL /* Timers definition */ -#define INFRARED_RX_TIMER TIM2 -#define INFRARED_DMA_TIMER TIM1 -#define INFRARED_RX_TIMER_BUS FuriHalBusTIM2 +#define INFRARED_RX_TIMER TIM2 +#define INFRARED_DMA_TIMER TIM1 +#define INFRARED_RX_TIMER_BUS FuriHalBusTIM2 #define INFRARED_DMA_TIMER_BUS FuriHalBusTIM1 /* Misc */ #define INFRARED_RX_GPIO_ALT GpioAltFn1TIM2 -#define INFRARED_RX_IRQ FuriHalInterruptIdTIM2 +#define INFRARED_RX_IRQ FuriHalInterruptIdTIM2 typedef struct { FuriHalInfraredRxCaptureCallback capture_callback; diff --git a/targets/f7/furi_hal/furi_hal_interrupt.c b/targets/f7/furi_hal/furi_hal_interrupt.c index 15a9a819fa3..35c40c25955 100644 --- a/targets/f7/furi_hal/furi_hal_interrupt.c +++ b/targets/f7/furi_hal/furi_hal_interrupt.c @@ -13,12 +13,27 @@ #define FURI_HAL_INTERRUPT_DEFAULT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 5) +#ifdef FURI_RAM_EXEC +#define FURI_HAL_INTERRUPT_ACCOUNT_START() +#define FURI_HAL_INTERRUPT_ACCOUNT_END() +#else +#define FURI_HAL_INTERRUPT_ACCOUNT_START() const uint32_t _isr_start = DWT->CYCCNT; +#define FURI_HAL_INTERRUPT_ACCOUNT_END() \ + const uint32_t _time_in_isr = DWT->CYCCNT - _isr_start; \ + furi_hal_interrupt.counter_time_in_isr_total += _time_in_isr; +#endif + typedef struct { FuriHalInterruptISR isr; void* context; } FuriHalInterruptISRPair; -FuriHalInterruptISRPair furi_hal_interrupt_isr[FuriHalInterruptIdMax] = {0}; +typedef struct { + FuriHalInterruptISRPair isr[FuriHalInterruptIdMax]; + uint32_t counter_time_in_isr_total; +} FuriHalIterrupt; + +static FuriHalIterrupt furi_hal_interrupt = {}; const IRQn_Type furi_hal_interrupt_irqn[FuriHalInterruptIdMax] = { // TIM1, TIM16, TIM17 @@ -67,12 +82,16 @@ const IRQn_Type furi_hal_interrupt_irqn[FuriHalInterruptIdMax] = { [FuriHalInterruptIdLpUart1] = LPUART1_IRQn, }; -FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_call(FuriHalInterruptId index) { - furi_check(furi_hal_interrupt_isr[index].isr); - furi_hal_interrupt_isr[index].isr(furi_hal_interrupt_isr[index].context); +FURI_ALWAYS_INLINE static void furi_hal_interrupt_call(FuriHalInterruptId index) { + const FuriHalInterruptISRPair* isr_descr = &furi_hal_interrupt.isr[index]; + furi_check(isr_descr->isr); + + FURI_HAL_INTERRUPT_ACCOUNT_START(); + isr_descr->isr(isr_descr->context); + FURI_HAL_INTERRUPT_ACCOUNT_END(); } -FURI_ALWAYS_STATIC_INLINE void +FURI_ALWAYS_INLINE static void furi_hal_interrupt_enable(FuriHalInterruptId index, uint16_t priority) { NVIC_SetPriority( furi_hal_interrupt_irqn[index], @@ -80,19 +99,19 @@ FURI_ALWAYS_STATIC_INLINE void NVIC_EnableIRQ(furi_hal_interrupt_irqn[index]); } -FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_clear_pending(FuriHalInterruptId index) { +FURI_ALWAYS_INLINE static void furi_hal_interrupt_clear_pending(FuriHalInterruptId index) { NVIC_ClearPendingIRQ(furi_hal_interrupt_irqn[index]); } -FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_get_pending(FuriHalInterruptId index) { +FURI_ALWAYS_INLINE static void furi_hal_interrupt_get_pending(FuriHalInterruptId index) { NVIC_GetPendingIRQ(furi_hal_interrupt_irqn[index]); } -FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_set_pending(FuriHalInterruptId index) { +FURI_ALWAYS_INLINE static void furi_hal_interrupt_set_pending(FuriHalInterruptId index) { NVIC_SetPendingIRQ(furi_hal_interrupt_irqn[index]); } -FURI_ALWAYS_STATIC_INLINE void furi_hal_interrupt_disable(FuriHalInterruptId index) { +FURI_ALWAYS_INLINE static void furi_hal_interrupt_disable(FuriHalInterruptId index) { NVIC_DisableIRQ(furi_hal_interrupt_irqn[index]); } @@ -137,17 +156,18 @@ void furi_hal_interrupt_set_isr_ex( uint16_t real_priority = FURI_HAL_INTERRUPT_DEFAULT_PRIORITY - priority; + FuriHalInterruptISRPair* isr_descr = &furi_hal_interrupt.isr[index]; if(isr) { // Pre ISR set - furi_check(furi_hal_interrupt_isr[index].isr == NULL); + furi_check(isr_descr->isr == NULL); } else { // Pre ISR clear furi_hal_interrupt_disable(index); furi_hal_interrupt_clear_pending(index); } - furi_hal_interrupt_isr[index].isr = isr; - furi_hal_interrupt_isr[index].context = context; + isr_descr->isr = isr; + isr_descr->context = context; __DMB(); if(isr) { @@ -304,27 +324,37 @@ extern void HW_IPCC_Tx_Handler(void); extern void HW_IPCC_Rx_Handler(void); void SysTick_Handler(void) { + FURI_HAL_INTERRUPT_ACCOUNT_START(); furi_hal_os_tick(); + FURI_HAL_INTERRUPT_ACCOUNT_END(); } void USB_LP_IRQHandler(void) { #ifndef FURI_RAM_EXEC + FURI_HAL_INTERRUPT_ACCOUNT_START(); usbd_poll(&udev); + FURI_HAL_INTERRUPT_ACCOUNT_END(); #endif } void USB_HP_IRQHandler(void) { //-V524 #ifndef FURI_RAM_EXEC + FURI_HAL_INTERRUPT_ACCOUNT_START(); usbd_poll(&udev); + FURI_HAL_INTERRUPT_ACCOUNT_END(); #endif } void IPCC_C1_TX_IRQHandler(void) { + FURI_HAL_INTERRUPT_ACCOUNT_START(); HW_IPCC_Tx_Handler(); + FURI_HAL_INTERRUPT_ACCOUNT_END(); } void IPCC_C1_RX_IRQHandler(void) { + FURI_HAL_INTERRUPT_ACCOUNT_START(); HW_IPCC_Rx_Handler(); + FURI_HAL_INTERRUPT_ACCOUNT_END(); } void FPU_IRQHandler(void) { @@ -347,6 +377,7 @@ void LPUART1_IRQHandler(void) { furi_hal_interrupt_call(FuriHalInterruptIdLpUart1); } +// Potential space-saver for updater build const char* furi_hal_interrupt_get_name(uint8_t exception_number) { int32_t id = (int32_t)exception_number - 16; @@ -499,3 +530,7 @@ const char* furi_hal_interrupt_get_name(uint8_t exception_number) { return NULL; } } + +uint32_t furi_hal_interrupt_get_time_in_isr_total(void) { + return furi_hal_interrupt.counter_time_in_isr_total; +} diff --git a/targets/f7/furi_hal/furi_hal_interrupt.h b/targets/f7/furi_hal/furi_hal_interrupt.h index c06ec23d20f..2326d3c0acd 100644 --- a/targets/f7/furi_hal/furi_hal_interrupt.h +++ b/targets/f7/furi_hal/furi_hal_interrupt.h @@ -118,6 +118,12 @@ void furi_hal_interrupt_set_isr_ex( */ const char* furi_hal_interrupt_get_name(uint8_t exception_number); +/** Get total time(in CPU clocks) spent in ISR + * + * @return total time in CPU clocks + */ +uint32_t furi_hal_interrupt_get_time_in_isr_total(void); + #ifdef __cplusplus } #endif diff --git a/targets/f7/furi_hal/furi_hal_light.c b/targets/f7/furi_hal/furi_hal_light.c index b44342b5229..621478d14dd 100644 --- a/targets/f7/furi_hal/furi_hal_light.c +++ b/targets/f7/furi_hal/furi_hal_light.c @@ -4,9 +4,9 @@ #include #include -#define LED_CURRENT_RED (50u) +#define LED_CURRENT_RED (50u) #define LED_CURRENT_GREEN (50u) -#define LED_CURRENT_BLUE (50u) +#define LED_CURRENT_BLUE (50u) #define LED_CURRENT_WHITE (150u) void furi_hal_light_init(void) { diff --git a/targets/f7/furi_hal/furi_hal_memory.c b/targets/f7/furi_hal/furi_hal_memory.c index 780a9d743d8..cae87342a37 100644 --- a/targets/f7/furi_hal/furi_hal_memory.c +++ b/targets/f7/furi_hal/furi_hal_memory.c @@ -65,11 +65,11 @@ void furi_hal_memory_init(void) { TAG, "SRAM2B: 0x%p, %lu", memory->region[SRAM_B].start, memory->region[SRAM_B].size); if((memory->region[SRAM_A].size > 0) || (memory->region[SRAM_B].size > 0)) { - if((memory->region[SRAM_A].size > 0)) { + if(memory->region[SRAM_A].size > 0) { FURI_LOG_I(TAG, "SRAM2A clear"); memset(memory->region[SRAM_A].start, 0, memory->region[SRAM_A].size); } - if((memory->region[SRAM_B].size > 0)) { + if(memory->region[SRAM_B].size > 0) { FURI_LOG_I(TAG, "SRAM2B clear"); memset(memory->region[SRAM_B].start, 0, memory->region[SRAM_B].size); } diff --git a/targets/f7/furi_hal/furi_hal_mpu.c b/targets/f7/furi_hal/furi_hal_mpu.c index 5fe3ab66bbc..5af638ab137 100644 --- a/targets/f7/furi_hal/furi_hal_mpu.c +++ b/targets/f7/furi_hal/furi_hal_mpu.c @@ -69,4 +69,4 @@ void furi_hal_mpu_set_stack_protection(uint32_t* stack) { furi_hal_mpu_protect_read_only( FuriHalMpuRegionThreadStack, stack_ptr, FURI_HAL_MPU_STACK_PROTECT_REGION); -} \ No newline at end of file +} diff --git a/targets/f7/furi_hal/furi_hal_nfc.c b/targets/f7/furi_hal/furi_hal_nfc.c index 550f1b16efd..ee7a04e45f6 100644 --- a/targets/f7/furi_hal/furi_hal_nfc.c +++ b/targets/f7/furi_hal/furi_hal_nfc.c @@ -253,7 +253,7 @@ FuriHalNfcError furi_hal_nfc_init(void) { } static bool furi_hal_nfc_is_mine(void) { - return (furi_mutex_get_owner(furi_hal_nfc.mutex) == furi_thread_get_current_id()); + return furi_mutex_get_owner(furi_hal_nfc.mutex) == furi_thread_get_current_id(); } FuriHalNfcError furi_hal_nfc_acquire(void) { diff --git a/targets/f7/furi_hal/furi_hal_nfc_iso15693.c b/targets/f7/furi_hal/furi_hal_nfc_iso15693.c index 9ab3532f95c..3245b67cc8c 100644 --- a/targets/f7/furi_hal/furi_hal_nfc_iso15693.c +++ b/targets/f7/furi_hal/furi_hal_nfc_iso15693.c @@ -6,21 +6,21 @@ #include -#define FURI_HAL_NFC_ISO15693_MAX_FRAME_SIZE (1024U) +#define FURI_HAL_NFC_ISO15693_MAX_FRAME_SIZE (1024U) #define FURI_HAL_NFC_ISO15693_POLLER_MAX_BUFFER_SIZE (64) -#define FURI_HAL_NFC_ISO15693_RESP_SOF_SIZE (5) -#define FURI_HAL_NFC_ISO15693_RESP_EOF_SIZE (5) -#define FURI_HAL_NFC_ISO15693_RESP_SOF_MASK (0x1FU) +#define FURI_HAL_NFC_ISO15693_RESP_SOF_SIZE (5) +#define FURI_HAL_NFC_ISO15693_RESP_EOF_SIZE (5) +#define FURI_HAL_NFC_ISO15693_RESP_SOF_MASK (0x1FU) #define FURI_HAL_NFC_ISO15693_RESP_SOF_PATTERN (0x17U) #define FURI_HAL_NFC_ISO15693_RESP_EOF_PATTERN (0x1DU) #define FURI_HAL_NFC_ISO15693_RESP_PATTERN_MASK (0x03U) -#define FURI_HAL_NFC_ISO15693_RESP_PATTERN_0 (0x01U) -#define FURI_HAL_NFC_ISO15693_RESP_PATTERN_1 (0x02U) +#define FURI_HAL_NFC_ISO15693_RESP_PATTERN_0 (0x01U) +#define FURI_HAL_NFC_ISO15693_RESP_PATTERN_1 (0x02U) // Derived experimentally -#define FURI_HAL_NFC_ISO15693_POLLER_FWT_COMP_FC (-1300) +#define FURI_HAL_NFC_ISO15693_POLLER_FWT_COMP_FC (-1300) #define FURI_HAL_NFC_ISO15693_LISTENER_FDT_COMP_FC (2850) #define BITS_IN_BYTE (8U) diff --git a/targets/f7/furi_hal/furi_hal_os.c b/targets/f7/furi_hal/furi_hal_os.c index ba28a141f38..35e381a55a2 100644 --- a/targets/f7/furi_hal/furi_hal_os.c +++ b/targets/f7/furi_hal/furi_hal_os.c @@ -15,17 +15,17 @@ #define TAG "FuriHalOs" #define FURI_HAL_IDLE_TIMER_CLK_HZ 32768 -#define FURI_HAL_OS_TICK_HZ configTICK_RATE_HZ +#define FURI_HAL_OS_TICK_HZ configTICK_RATE_HZ #define FURI_HAL_OS_IDLE_CNT_TO_TICKS(x) (((x) * FURI_HAL_OS_TICK_HZ) / FURI_HAL_IDLE_TIMER_CLK_HZ) #define FURI_HAL_OS_TICKS_TO_IDLE_CNT(x) (((x) * FURI_HAL_IDLE_TIMER_CLK_HZ) / FURI_HAL_OS_TICK_HZ) #define FURI_HAL_IDLE_TIMER_TICK_PER_EPOCH (FURI_HAL_OS_IDLE_CNT_TO_TICKS(FURI_HAL_IDLE_TIMER_MAX)) -#define FURI_HAL_OS_MAX_SLEEP (FURI_HAL_IDLE_TIMER_TICK_PER_EPOCH - 1) +#define FURI_HAL_OS_MAX_SLEEP (FURI_HAL_IDLE_TIMER_TICK_PER_EPOCH - 1) #define FURI_HAL_OS_NVIC_IS_PENDING() (NVIC->ISPR[0] || NVIC->ISPR[1]) -#define FURI_HAL_OS_EXTI_LINE_0_31 0 -#define FURI_HAL_OS_EXTI_LINE_32_63 1 +#define FURI_HAL_OS_EXTI_LINE_0_31 0 +#define FURI_HAL_OS_EXTI_LINE_32_63 1 // Arbitrary (but small) number for better tick consistency #define FURI_HAL_OS_EXTRA_CNT 3 diff --git a/targets/f7/furi_hal/furi_hal_random.c b/targets/f7/furi_hal/furi_hal_random.c index fd557fa98fd..8b75a05c5b4 100644 --- a/targets/f7/furi_hal/furi_hal_random.c +++ b/targets/f7/furi_hal/furi_hal_random.c @@ -75,9 +75,9 @@ void srand(unsigned seed) { } int rand(void) { - return (furi_hal_random_get() & RAND_MAX); + return furi_hal_random_get() & RAND_MAX; } long random(void) { - return (furi_hal_random_get() & RAND_MAX); + return furi_hal_random_get() & RAND_MAX; } diff --git a/targets/f7/furi_hal/furi_hal_resources.h b/targets/f7/furi_hal/furi_hal_resources.h index 99768654d95..c01b2207fff 100644 --- a/targets/f7/furi_hal/furi_hal_resources.h +++ b/targets/f7/furi_hal/furi_hal_resources.h @@ -110,107 +110,107 @@ extern const GpioPin gpio_periph_power; extern const GpioPin gpio_usb_dm; extern const GpioPin gpio_usb_dp; -#define BUTTON_BACK_GPIO_Port GPIOC -#define BUTTON_BACK_Pin LL_GPIO_PIN_13 -#define BUTTON_DOWN_GPIO_Port GPIOC -#define BUTTON_DOWN_Pin LL_GPIO_PIN_6 -#define BUTTON_LEFT_GPIO_Port GPIOB -#define BUTTON_LEFT_Pin LL_GPIO_PIN_11 -#define BUTTON_OK_GPIO_Port GPIOH -#define BUTTON_OK_Pin LL_GPIO_PIN_3 +#define BUTTON_BACK_GPIO_Port GPIOC +#define BUTTON_BACK_Pin LL_GPIO_PIN_13 +#define BUTTON_DOWN_GPIO_Port GPIOC +#define BUTTON_DOWN_Pin LL_GPIO_PIN_6 +#define BUTTON_LEFT_GPIO_Port GPIOB +#define BUTTON_LEFT_Pin LL_GPIO_PIN_11 +#define BUTTON_OK_GPIO_Port GPIOH +#define BUTTON_OK_Pin LL_GPIO_PIN_3 #define BUTTON_RIGHT_GPIO_Port GPIOB -#define BUTTON_RIGHT_Pin LL_GPIO_PIN_12 -#define BUTTON_UP_GPIO_Port GPIOB -#define BUTTON_UP_Pin LL_GPIO_PIN_10 +#define BUTTON_RIGHT_Pin LL_GPIO_PIN_12 +#define BUTTON_UP_GPIO_Port GPIOB +#define BUTTON_UP_Pin LL_GPIO_PIN_10 #define CC1101_CS_GPIO_Port GPIOD -#define CC1101_CS_Pin LL_GPIO_PIN_0 +#define CC1101_CS_Pin LL_GPIO_PIN_0 #define CC1101_G0_GPIO_Port GPIOA -#define CC1101_G0_Pin LL_GPIO_PIN_1 +#define CC1101_G0_Pin LL_GPIO_PIN_1 -#define DISPLAY_CS_GPIO_Port GPIOC -#define DISPLAY_CS_Pin LL_GPIO_PIN_11 -#define DISPLAY_DI_GPIO_Port GPIOB -#define DISPLAY_DI_Pin LL_GPIO_PIN_1 +#define DISPLAY_CS_GPIO_Port GPIOC +#define DISPLAY_CS_Pin LL_GPIO_PIN_11 +#define DISPLAY_DI_GPIO_Port GPIOB +#define DISPLAY_DI_Pin LL_GPIO_PIN_1 #define DISPLAY_RST_GPIO_Port GPIOB -#define DISPLAY_RST_Pin LL_GPIO_PIN_0 +#define DISPLAY_RST_Pin LL_GPIO_PIN_0 #define IR_RX_GPIO_Port GPIOA -#define IR_RX_Pin LL_GPIO_PIN_0 +#define IR_RX_Pin LL_GPIO_PIN_0 #define IR_TX_GPIO_Port GPIOB -#define IR_TX_Pin LL_GPIO_PIN_9 +#define IR_TX_Pin LL_GPIO_PIN_9 #define NFC_CS_GPIO_Port GPIOE -#define NFC_CS_Pin LL_GPIO_PIN_4 +#define NFC_CS_Pin LL_GPIO_PIN_4 #define PA4_GPIO_Port GPIOA -#define PA4_Pin LL_GPIO_PIN_4 +#define PA4_Pin LL_GPIO_PIN_4 #define PA6_GPIO_Port GPIOA -#define PA6_Pin LL_GPIO_PIN_6 +#define PA6_Pin LL_GPIO_PIN_6 #define PA7_GPIO_Port GPIOA -#define PA7_Pin LL_GPIO_PIN_7 +#define PA7_Pin LL_GPIO_PIN_7 #define PB2_GPIO_Port GPIOB -#define PB2_Pin LL_GPIO_PIN_2 +#define PB2_Pin LL_GPIO_PIN_2 #define PB3_GPIO_Port GPIOB -#define PB3_Pin LL_GPIO_PIN_3 +#define PB3_Pin LL_GPIO_PIN_3 #define PC0_GPIO_Port GPIOC -#define PC0_Pin LL_GPIO_PIN_0 +#define PC0_Pin LL_GPIO_PIN_0 #define PC1_GPIO_Port GPIOC -#define PC1_Pin LL_GPIO_PIN_1 +#define PC1_Pin LL_GPIO_PIN_1 #define PC3_GPIO_Port GPIOC -#define PC3_Pin LL_GPIO_PIN_3 +#define PC3_Pin LL_GPIO_PIN_3 -#define QUARTZ_32MHZ_IN_GPIO_Port GPIOC -#define QUARTZ_32MHZ_IN_Pin LL_GPIO_PIN_14 +#define QUARTZ_32MHZ_IN_GPIO_Port GPIOC +#define QUARTZ_32MHZ_IN_Pin LL_GPIO_PIN_14 #define QUARTZ_32MHZ_OUT_GPIO_Port GPIOC -#define QUARTZ_32MHZ_OUT_Pin LL_GPIO_PIN_15 - -#define RFID_OUT_GPIO_Port GPIOB -#define RFID_OUT_Pin LL_GPIO_PIN_13 -#define RFID_PULL_GPIO_Port GPIOA -#define RFID_PULL_Pin LL_GPIO_PIN_2 -#define RFID_RF_IN_GPIO_Port GPIOC -#define RFID_RF_IN_Pin LL_GPIO_PIN_5 +#define QUARTZ_32MHZ_OUT_Pin LL_GPIO_PIN_15 + +#define RFID_OUT_GPIO_Port GPIOB +#define RFID_OUT_Pin LL_GPIO_PIN_13 +#define RFID_PULL_GPIO_Port GPIOA +#define RFID_PULL_Pin LL_GPIO_PIN_2 +#define RFID_RF_IN_GPIO_Port GPIOC +#define RFID_RF_IN_Pin LL_GPIO_PIN_5 #define RFID_CARRIER_GPIO_Port GPIOA -#define RFID_CARRIER_Pin LL_GPIO_PIN_15 +#define RFID_CARRIER_Pin LL_GPIO_PIN_15 #define RF_SW_0_GPIO_Port GPIOC -#define RF_SW_0_Pin LL_GPIO_PIN_4 +#define RF_SW_0_Pin LL_GPIO_PIN_4 #define SD_CD_GPIO_Port GPIOC -#define SD_CD_Pin LL_GPIO_PIN_10 +#define SD_CD_Pin LL_GPIO_PIN_10 #define SD_CS_GPIO_Port GPIOC -#define SD_CS_Pin LL_GPIO_PIN_12 +#define SD_CS_Pin LL_GPIO_PIN_12 #define SPEAKER_GPIO_Port GPIOB -#define SPEAKER_Pin LL_GPIO_PIN_8 +#define SPEAKER_Pin LL_GPIO_PIN_8 #define VIBRO_GPIO_Port GPIOA -#define VIBRO_Pin LL_GPIO_PIN_8 +#define VIBRO_Pin LL_GPIO_PIN_8 #define iBTN_GPIO_Port GPIOB -#define iBTN_Pin LL_GPIO_PIN_14 +#define iBTN_Pin LL_GPIO_PIN_14 -#define USART1_TX_Pin LL_GPIO_PIN_6 +#define USART1_TX_Pin LL_GPIO_PIN_6 #define USART1_TX_Port GPIOB -#define USART1_RX_Pin LL_GPIO_PIN_7 +#define USART1_RX_Pin LL_GPIO_PIN_7 #define USART1_RX_Port GPIOB #define SPI_D_MISO_GPIO_Port GPIOC -#define SPI_D_MISO_Pin LL_GPIO_PIN_2 +#define SPI_D_MISO_Pin LL_GPIO_PIN_2 #define SPI_D_MOSI_GPIO_Port GPIOB -#define SPI_D_MOSI_Pin LL_GPIO_PIN_15 -#define SPI_D_SCK_GPIO_Port GPIOD -#define SPI_D_SCK_Pin LL_GPIO_PIN_1 +#define SPI_D_MOSI_Pin LL_GPIO_PIN_15 +#define SPI_D_SCK_GPIO_Port GPIOD +#define SPI_D_SCK_Pin LL_GPIO_PIN_1 #define SPI_R_MISO_GPIO_Port GPIOB -#define SPI_R_MISO_Pin LL_GPIO_PIN_4 +#define SPI_R_MISO_Pin LL_GPIO_PIN_4 #define SPI_R_MOSI_GPIO_Port GPIOB -#define SPI_R_MOSI_Pin LL_GPIO_PIN_5 -#define SPI_R_SCK_GPIO_Port GPIOA -#define SPI_R_SCK_Pin LL_GPIO_PIN_5 +#define SPI_R_MOSI_Pin LL_GPIO_PIN_5 +#define SPI_R_SCK_GPIO_Port GPIOA +#define SPI_R_SCK_Pin LL_GPIO_PIN_5 -#define NFC_IRQ_Pin RFID_PULL_Pin +#define NFC_IRQ_Pin RFID_PULL_Pin #define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port void furi_hal_resources_init_early(void); diff --git a/targets/f7/furi_hal/furi_hal_rfid.c b/targets/f7/furi_hal/furi_hal_rfid.c index 07ea5ab0a7c..34bb3a51600 100644 --- a/targets/f7/furi_hal/furi_hal_rfid.c +++ b/targets/f7/furi_hal/furi_hal_rfid.c @@ -9,42 +9,42 @@ #include #include -#define FURI_HAL_RFID_READ_TIMER TIM1 -#define FURI_HAL_RFID_READ_TIMER_BUS FuriHalBusTIM1 -#define FURI_HAL_RFID_READ_TIMER_CHANNEL LL_TIM_CHANNEL_CH1N +#define FURI_HAL_RFID_READ_TIMER TIM1 +#define FURI_HAL_RFID_READ_TIMER_BUS FuriHalBusTIM1 +#define FURI_HAL_RFID_READ_TIMER_CHANNEL LL_TIM_CHANNEL_CH1N // We can't use N channel for LL_TIM_OC_Init, so... #define FURI_HAL_RFID_READ_TIMER_CHANNEL_CONFIG LL_TIM_CHANNEL_CH1 -#define FURI_HAL_RFID_EMULATE_TIMER TIM2 -#define FURI_HAL_RFID_EMULATE_TIMER_BUS FuriHalBusTIM2 -#define FURI_HAL_RFID_EMULATE_TIMER_IRQ FuriHalInterruptIdTIM2 +#define FURI_HAL_RFID_EMULATE_TIMER TIM2 +#define FURI_HAL_RFID_EMULATE_TIMER_BUS FuriHalBusTIM2 +#define FURI_HAL_RFID_EMULATE_TIMER_IRQ FuriHalInterruptIdTIM2 #define FURI_HAL_RFID_EMULATE_TIMER_CHANNEL LL_TIM_CHANNEL_CH3 -#define RFID_CAPTURE_TIM TIM2 +#define RFID_CAPTURE_TIM TIM2 #define RFID_CAPTURE_TIM_BUS FuriHalBusTIM2 -#define RFID_CAPTURE_IND_CH LL_TIM_CHANNEL_CH3 -#define RFID_CAPTURE_DIR_CH LL_TIM_CHANNEL_CH4 +#define RFID_CAPTURE_IND_CH LL_TIM_CHANNEL_CH3 +#define RFID_CAPTURE_DIR_CH LL_TIM_CHANNEL_CH4 // Field presence detection #define FURI_HAL_RFID_FIELD_FREQUENCY_MIN 80000 #define FURI_HAL_RFID_FIELD_FREQUENCY_MAX 200000 -#define FURI_HAL_RFID_FIELD_COUNTER_TIMER TIM2 -#define FURI_HAL_RFID_FIELD_COUNTER_TIMER_BUS FuriHalBusTIM2 +#define FURI_HAL_RFID_FIELD_COUNTER_TIMER TIM2 +#define FURI_HAL_RFID_FIELD_COUNTER_TIMER_BUS FuriHalBusTIM2 #define FURI_HAL_RFID_FIELD_COUNTER_TIMER_CHANNEL LL_TIM_CHANNEL_CH3 -#define FURI_HAL_RFID_FIELD_TIMEOUT_TIMER TIM1 +#define FURI_HAL_RFID_FIELD_TIMEOUT_TIMER TIM1 #define FURI_HAL_RFID_FIELD_TIMEOUT_TIMER_BUS FuriHalBusTIM1 #define FURI_HAL_RFID_FIELD_DMAMUX_DMA LL_DMAMUX_REQ_TIM1_UP /* DMA Channels definition */ -#define RFID_DMA DMA2 +#define RFID_DMA DMA2 #define RFID_DMA_CH1_CHANNEL LL_DMA_CHANNEL_1 #define RFID_DMA_CH2_CHANNEL LL_DMA_CHANNEL_2 -#define RFID_DMA_CH1_IRQ FuriHalInterruptIdDma2Ch1 -#define RFID_DMA_CH1_DEF RFID_DMA, RFID_DMA_CH1_CHANNEL -#define RFID_DMA_CH2_DEF RFID_DMA, RFID_DMA_CH2_CHANNEL +#define RFID_DMA_CH1_IRQ FuriHalInterruptIdDma2Ch1 +#define RFID_DMA_CH1_DEF RFID_DMA, RFID_DMA_CH1_CHANNEL +#define RFID_DMA_CH2_DEF RFID_DMA, RFID_DMA_CH2_CHANNEL typedef struct { uint32_t counter; @@ -60,11 +60,11 @@ typedef struct { FuriHalRfid* furi_hal_rfid = NULL; -#define LFRFID_LL_READ_TIM TIM1 +#define LFRFID_LL_READ_TIM TIM1 #define LFRFID_LL_READ_CONFIG_CHANNEL LL_TIM_CHANNEL_CH1 -#define LFRFID_LL_READ_CHANNEL LL_TIM_CHANNEL_CH1N +#define LFRFID_LL_READ_CHANNEL LL_TIM_CHANNEL_CH1N -#define LFRFID_LL_EMULATE_TIM TIM2 +#define LFRFID_LL_EMULATE_TIM TIM2 #define LFRFID_LL_EMULATE_CHANNEL LL_TIM_CHANNEL_CH3 void furi_hal_rfid_init(void) { @@ -585,7 +585,6 @@ bool furi_hal_rfid_field_is_present(uint32_t* frequency) { furi_check(frequency); *frequency = furi_hal_rfid->field.counter * 10; - return ( - (*frequency >= FURI_HAL_RFID_FIELD_FREQUENCY_MIN) && - (*frequency <= FURI_HAL_RFID_FIELD_FREQUENCY_MAX)); -} \ No newline at end of file + return (*frequency >= FURI_HAL_RFID_FIELD_FREQUENCY_MIN) && + (*frequency <= FURI_HAL_RFID_FIELD_FREQUENCY_MAX); +} diff --git a/targets/f7/furi_hal/furi_hal_rtc.c b/targets/f7/furi_hal/furi_hal_rtc.c index a1c8b46c348..f5f7bdf2d26 100644 --- a/targets/f7/furi_hal/furi_hal_rtc.c +++ b/targets/f7/furi_hal/furi_hal_rtc.c @@ -17,7 +17,7 @@ #define FURI_HAL_RTC_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady()) -#define FURI_HAL_RTC_HEADER_MAGIC 0x10F1 +#define FURI_HAL_RTC_HEADER_MAGIC 0x10F1 #define FURI_HAL_RTC_HEADER_VERSION 0 typedef struct { @@ -27,17 +27,17 @@ typedef struct { } FuriHalRtcHeader; typedef struct { - uint8_t log_level : 4; + uint8_t log_level : 4; uint8_t log_reserved : 4; uint8_t flags; - FuriHalRtcBootMode boot_mode : 4; - FuriHalRtcHeapTrackMode heap_track_mode : 2; - FuriHalRtcLocaleUnits locale_units : 1; + FuriHalRtcBootMode boot_mode : 4; + FuriHalRtcHeapTrackMode heap_track_mode : 2; + FuriHalRtcLocaleUnits locale_units : 1; FuriHalRtcLocaleTimeFormat locale_timeformat : 1; FuriHalRtcLocaleDateFormat locale_dateformat : 2; - FuriHalRtcLogDevice log_device : 2; - FuriHalRtcLogBaudRate log_baud_rate : 3; - uint8_t reserved : 1; + FuriHalRtcLogDevice log_device : 2; + FuriHalRtcLogBaudRate log_baud_rate : 3; + uint8_t reserved : 1; } SystemReg; _Static_assert(sizeof(SystemReg) == 4, "SystemReg size mismatch"); diff --git a/targets/f7/furi_hal/furi_hal_sd.c b/targets/f7/furi_hal/furi_hal_sd.c index fb7f43ec8d4..eca5b6da9c0 100644 --- a/targets/f7/furi_hal/furi_hal_sd.c +++ b/targets/f7/furi_hal/furi_hal_sd.c @@ -11,12 +11,12 @@ #define sd_spi_debug(...) #endif -#define SD_CMD_LENGTH (6) -#define SD_DUMMY_BYTE (0xFF) +#define SD_CMD_LENGTH (6) +#define SD_DUMMY_BYTE (0xFF) #define SD_ANSWER_RETRY_COUNT (8) -#define SD_IDLE_RETRY_COUNT (100) -#define SD_TIMEOUT_MS (1000) -#define SD_BLOCK_SIZE (512) +#define SD_IDLE_RETRY_COUNT (100) +#define SD_TIMEOUT_MS (1000) +#define SD_BLOCK_SIZE (512) #define FLAG_SET(x, y) (((x) & (y)) == (y)) @@ -125,53 +125,53 @@ typedef enum { */ typedef struct { /* Header part */ - uint8_t CSDStruct : 2; /* CSD structure */ - uint8_t Reserved1 : 6; /* Reserved */ - uint8_t TAAC : 8; /* Data read access-time 1 */ - uint8_t NSAC : 8; /* Data read access-time 2 in CLK cycles */ - uint8_t MaxBusClkFreq : 8; /* Max. bus clock frequency */ + uint8_t CSDStruct : 2; /* CSD structure */ + uint8_t Reserved1 : 6; /* Reserved */ + uint8_t TAAC : 8; /* Data read access-time 1 */ + uint8_t NSAC : 8; /* Data read access-time 2 in CLK cycles */ + uint8_t MaxBusClkFreq : 8; /* Max. bus clock frequency */ uint16_t CardComdClasses : 12; /* Card command classes */ - uint8_t RdBlockLen : 4; /* Max. read data block length */ - uint8_t PartBlockRead : 1; /* Partial blocks for read allowed */ - uint8_t WrBlockMisalign : 1; /* Write block misalignment */ - uint8_t RdBlockMisalign : 1; /* Read block misalignment */ - uint8_t DSRImpl : 1; /* DSR implemented */ + uint8_t RdBlockLen : 4; /* Max. read data block length */ + uint8_t PartBlockRead : 1; /* Partial blocks for read allowed */ + uint8_t WrBlockMisalign : 1; /* Write block misalignment */ + uint8_t RdBlockMisalign : 1; /* Read block misalignment */ + uint8_t DSRImpl : 1; /* DSR implemented */ /* v1 or v2 struct */ union csd_version { struct { - uint8_t Reserved1 : 2; /* Reserved */ - uint16_t DeviceSize : 12; /* Device Size */ + uint8_t Reserved1 : 2; /* Reserved */ + uint16_t DeviceSize : 12; /* Device Size */ uint8_t MaxRdCurrentVDDMin : 3; /* Max. read current @ VDD min */ uint8_t MaxRdCurrentVDDMax : 3; /* Max. read current @ VDD max */ uint8_t MaxWrCurrentVDDMin : 3; /* Max. write current @ VDD min */ uint8_t MaxWrCurrentVDDMax : 3; /* Max. write current @ VDD max */ - uint8_t DeviceSizeMul : 3; /* Device size multiplier */ + uint8_t DeviceSizeMul : 3; /* Device size multiplier */ } v1; struct { - uint8_t Reserved1 : 6; /* Reserved */ + uint8_t Reserved1 : 6; /* Reserved */ uint32_t DeviceSize : 22; /* Device Size */ - uint8_t Reserved2 : 1; /* Reserved */ + uint8_t Reserved2 : 1; /* Reserved */ } v2; } version; uint8_t EraseSingleBlockEnable : 1; /* Erase single block enable */ - uint8_t EraseSectorSize : 7; /* Erase group size multiplier */ - uint8_t WrProtectGrSize : 7; /* Write protect group size */ - uint8_t WrProtectGrEnable : 1; /* Write protect group enable */ - uint8_t Reserved2 : 2; /* Reserved */ - uint8_t WrSpeedFact : 3; /* Write speed factor */ - uint8_t MaxWrBlockLen : 4; /* Max. write data block length */ - uint8_t WriteBlockPartial : 1; /* Partial blocks for write allowed */ - uint8_t Reserved3 : 5; /* Reserved */ - uint8_t FileFormatGrouop : 1; /* File format group */ - uint8_t CopyFlag : 1; /* Copy flag (OTP) */ - uint8_t PermWrProtect : 1; /* Permanent write protection */ - uint8_t TempWrProtect : 1; /* Temporary write protection */ - uint8_t FileFormat : 2; /* File Format */ - uint8_t Reserved4 : 2; /* Reserved */ - uint8_t crc : 7; /* Reserved */ - uint8_t Reserved5 : 1; /* always 1*/ + uint8_t EraseSectorSize : 7; /* Erase group size multiplier */ + uint8_t WrProtectGrSize : 7; /* Write protect group size */ + uint8_t WrProtectGrEnable : 1; /* Write protect group enable */ + uint8_t Reserved2 : 2; /* Reserved */ + uint8_t WrSpeedFact : 3; /* Write speed factor */ + uint8_t MaxWrBlockLen : 4; /* Max. write data block length */ + uint8_t WriteBlockPartial : 1; /* Partial blocks for write allowed */ + uint8_t Reserved3 : 5; /* Reserved */ + uint8_t FileFormatGrouop : 1; /* File format group */ + uint8_t CopyFlag : 1; /* Copy flag (OTP) */ + uint8_t PermWrProtect : 1; /* Permanent write protection */ + uint8_t TempWrProtect : 1; /* Temporary write protection */ + uint8_t FileFormat : 2; /* File Format */ + uint8_t Reserved4 : 2; /* Reserved */ + uint8_t crc : 7; /* Reserved */ + uint8_t Reserved5 : 1; /* always 1*/ } SD_CSD; @@ -324,7 +324,7 @@ static FuriStatus sd_spi_wait_for_data(uint8_t data, uint32_t timeout_ms) { if(furi_hal_cortex_timer_is_expired(timer)) { return FuriStatusErrorTimeout; } - } while((byte != data)); + } while(byte != data); return FuriStatusOk; } @@ -1098,4 +1098,4 @@ FuriStatus furi_hal_sd_info(FuriHalSdInfo* info) { furi_hal_spi_release(&furi_hal_spi_bus_handle_sd_fast); return status; -} \ No newline at end of file +} diff --git a/targets/f7/furi_hal/furi_hal_serial.c b/targets/f7/furi_hal/furi_hal_serial.c index f26b412d2d5..5ddb0785f7d 100644 --- a/targets/f7/furi_hal/furi_hal_serial.c +++ b/targets/f7/furi_hal/furi_hal_serial.c @@ -15,10 +15,10 @@ #define FURI_HAL_SERIAL_USART_OVERSAMPLING LL_USART_OVERSAMPLING_16 #define FURI_HAL_SERIAL_USART_DMA_INSTANCE (DMA1) -#define FURI_HAL_SERIAL_USART_DMA_CHANNEL (LL_DMA_CHANNEL_6) +#define FURI_HAL_SERIAL_USART_DMA_CHANNEL (LL_DMA_CHANNEL_6) #define FURI_HAL_SERIAL_LPUART_DMA_INSTANCE (DMA1) -#define FURI_HAL_SERIAL_LPUART_DMA_CHANNEL (LL_DMA_CHANNEL_7) +#define FURI_HAL_SERIAL_LPUART_DMA_CHANNEL (LL_DMA_CHANNEL_7) typedef struct { uint8_t* buffer_rx_ptr; diff --git a/targets/f7/furi_hal/furi_hal_speaker.c b/targets/f7/furi_hal/furi_hal_speaker.c index 0aa8ce951a2..65b517b9eeb 100644 --- a/targets/f7/furi_hal/furi_hal_speaker.c +++ b/targets/f7/furi_hal/furi_hal_speaker.c @@ -9,9 +9,9 @@ #define TAG "FuriHalSpeaker" -#define FURI_HAL_SPEAKER_TIMER TIM16 -#define FURI_HAL_SPEAKER_CHANNEL LL_TIM_CHANNEL_CH1 -#define FURI_HAL_SPEAKER_PRESCALER 500 +#define FURI_HAL_SPEAKER_TIMER TIM16 +#define FURI_HAL_SPEAKER_CHANNEL LL_TIM_CHANNEL_CH1 +#define FURI_HAL_SPEAKER_PRESCALER 500 #define FURI_HAL_SPEAKER_MAX_VOLUME 60 static FuriMutex* furi_hal_speaker_mutex = NULL; diff --git a/targets/f7/furi_hal/furi_hal_spi.c b/targets/f7/furi_hal/furi_hal_spi.c index e2892572fa1..49bcd48a1ef 100644 --- a/targets/f7/furi_hal/furi_hal_spi.c +++ b/targets/f7/furi_hal/furi_hal_spi.c @@ -11,13 +11,13 @@ #define TAG "FuriHalSpi" -#define SPI_DMA DMA2 +#define SPI_DMA DMA2 #define SPI_DMA_RX_CHANNEL LL_DMA_CHANNEL_6 #define SPI_DMA_TX_CHANNEL LL_DMA_CHANNEL_7 -#define SPI_DMA_RX_IRQ FuriHalInterruptIdDma2Ch6 -#define SPI_DMA_TX_IRQ FuriHalInterruptIdDma2Ch7 -#define SPI_DMA_RX_DEF SPI_DMA, SPI_DMA_RX_CHANNEL -#define SPI_DMA_TX_DEF SPI_DMA, SPI_DMA_TX_CHANNEL +#define SPI_DMA_RX_IRQ FuriHalInterruptIdDma2Ch6 +#define SPI_DMA_TX_IRQ FuriHalInterruptIdDma2Ch7 +#define SPI_DMA_RX_DEF SPI_DMA, SPI_DMA_RX_CHANNEL +#define SPI_DMA_TX_DEF SPI_DMA, SPI_DMA_TX_CHANNEL // For simplicity, I assume that only one SPI DMA transaction can occur at a time. static FuriSemaphore* spi_dma_lock = NULL; diff --git a/targets/f7/furi_hal/furi_hal_subghz.c b/targets/f7/furi_hal/furi_hal_subghz.c index c5670f73e21..220e9219b17 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.c +++ b/targets/f7/furi_hal/furi_hal_subghz.c @@ -20,12 +20,12 @@ static uint32_t furi_hal_subghz_debug_gpio_buff[2] = {0}; /* DMA Channels definition */ -#define SUBGHZ_DMA (DMA2) +#define SUBGHZ_DMA (DMA2) #define SUBGHZ_DMA_CH1_CHANNEL (LL_DMA_CHANNEL_1) #define SUBGHZ_DMA_CH2_CHANNEL (LL_DMA_CHANNEL_2) -#define SUBGHZ_DMA_CH1_IRQ (FuriHalInterruptIdDma2Ch1) -#define SUBGHZ_DMA_CH1_DEF SUBGHZ_DMA, SUBGHZ_DMA_CH1_CHANNEL -#define SUBGHZ_DMA_CH2_DEF SUBGHZ_DMA, SUBGHZ_DMA_CH2_CHANNEL +#define SUBGHZ_DMA_CH1_IRQ (FuriHalInterruptIdDma2Ch1) +#define SUBGHZ_DMA_CH1_DEF SUBGHZ_DMA, SUBGHZ_DMA_CH1_CHANNEL +#define SUBGHZ_DMA_CH2_DEF SUBGHZ_DMA, SUBGHZ_DMA_CH2_CHANNEL /** SubGhz state */ typedef enum { @@ -253,7 +253,7 @@ bool furi_hal_subghz_is_rx_data_crc_valid(void) { uint8_t data[1]; cc1101_read_reg(&furi_hal_spi_bus_handle_subghz, CC1101_STATUS_LQI | CC1101_BURST, data); furi_hal_spi_release(&furi_hal_spi_bus_handle_subghz); - if(((data[0] >> 7) & 0x01)) { + if((data[0] >> 7) & 0x01) { return true; } else { return false; diff --git a/targets/f7/furi_hal/furi_hal_subghz.h b/targets/f7/furi_hal/furi_hal_subghz.h index 0a0ee7667a8..49c7360bc3a 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.h +++ b/targets/f7/furi_hal/furi_hal_subghz.h @@ -20,7 +20,7 @@ extern "C" { /** Various subghz defines */ #define FURI_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256u) #define FURI_HAL_SUBGHZ_ASYNC_TX_BUFFER_HALF (FURI_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL / 2) -#define FURI_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME (999u) +#define FURI_HAL_SUBGHZ_ASYNC_TX_GUARD_TIME (999u) /** Switchable Radio Paths */ typedef enum { diff --git a/targets/f7/furi_hal/furi_hal_usb_ccid.c b/targets/f7/furi_hal/furi_hal_usb_ccid.c index 5e2fe77b776..a2c1a0583e5 100644 --- a/targets/f7/furi_hal/furi_hal_usb_ccid.c +++ b/targets/f7/furi_hal/furi_hal_usb_ccid.c @@ -4,27 +4,27 @@ #include #include -#include "usb.h" -#include "usb_ccid.h" +#include -static const uint8_t USB_DEVICE_NO_CLASS = 0x0; -static const uint8_t USB_DEVICE_NO_SUBCLASS = 0x0; -static const uint8_t USB_DEVICE_NO_PROTOCOL = 0x0; +#define USB_DEVICE_NO_CLASS (0x0) +#define USB_DEVICE_NO_SUBCLASS (0x0) +#define USB_DEVICE_NO_PROTOCOL (0x0) -#define FIXED_CONTROL_ENDPOINT_SIZE 8 -#define IF_NUM_MAX 1 +#define FIXED_CONTROL_ENDPOINT_SIZE (8) +#define IF_NUM_MAX (1) -#define CCID_VID_DEFAULT 0x1234 -#define CCID_PID_DEFAULT 0xABCD -#define CCID_TOTAL_SLOTS 1 -#define CCID_SLOT_INDEX 0 +#define CCID_VID_DEFAULT (0x1234) +#define CCID_PID_DEFAULT (0xABCD) +#define CCID_TOTAL_SLOTS (1) +#define CCID_SLOT_INDEX (0) -#define CCID_DATABLOCK_SIZE 256 +#define CCID_DATABLOCK_SIZE \ + (4 + 1 + CCID_SHORT_APDU_SIZE + 1) //APDU Header + Lc + Short APDU size + Le -#define ENDPOINT_DIR_IN 0x80 -#define ENDPOINT_DIR_OUT 0x00 +#define ENDPOINT_DIR_IN (0x80) +#define ENDPOINT_DIR_OUT (0x00) -#define INTERFACE_ID_CCID 0 +#define INTERFACE_ID_CCID (0) #define CCID_IN_EPADDR (ENDPOINT_DIR_IN | 2) @@ -64,6 +64,18 @@ enum CCID_Features_ExchangeLevel_t { CCID_Features_ExchangeLevel_ShortExtendedAPDU = 0x00040000 }; +typedef enum { + WorkerEvtStop = (1 << 0), + WorkerEvtRequest = (1 << 1), +} WorkerEvtFlags; + +typedef struct ccid_bulk_message_header { + uint8_t bMessageType; + uint32_t dwLength; + uint8_t bSlot; + uint8_t bSeq; +} FURI_PACKED ccid_bulk_message_header_t; + /* Device descriptor */ static struct usb_device_descriptor ccid_device_desc = { .bLength = sizeof(struct usb_device_descriptor), @@ -162,6 +174,7 @@ static void ccid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx); static void ccid_deinit(usbd_device* dev); static void ccid_on_wakeup(usbd_device* dev); static void ccid_on_suspend(usbd_device* dev); +static int32_t ccid_worker(void* context); FuriHalUsbInterface usb_ccid = { .init = ccid_init, @@ -180,11 +193,22 @@ FuriHalUsbInterface usb_ccid = { static usbd_respond ccid_ep_config(usbd_device* dev, uint8_t cfg); static usbd_respond ccid_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_callback* callback); -static usbd_device* usb_dev; -static bool connected = false; -static bool smartcard_inserted = true; -static CcidCallbacks* callbacks[CCID_TOTAL_SLOTS] = {NULL}; -static void* cb_ctx[CCID_TOTAL_SLOTS]; + +typedef struct { + bool connected; + bool smartcard_inserted; + CcidCallbacks* callbacks[CCID_TOTAL_SLOTS]; + void* cb_ctx[CCID_TOTAL_SLOTS]; + FuriThread* ccid_thread; + FuriSemaphore* ccid_semaphore; + usbd_device* usb_dev; + + uint16_t receive_buffer_data_index; + uint8_t send_buffer[sizeof(ccid_bulk_message_header_t) + CCID_DATABLOCK_SIZE]; + uint8_t receive_buffer[sizeof(ccid_bulk_message_header_t) + CCID_DATABLOCK_SIZE]; +} FuriHalUsbCcid; + +static FuriHalUsbCcid* furi_hal_usb_ccid = NULL; static void* ccid_set_string_descr(char* str) { furi_check(str); @@ -193,7 +217,8 @@ static void* ccid_set_string_descr(char* str) { struct usb_string_descriptor* dev_str_desc = malloc(len * 2 + 2); dev_str_desc->bLength = len * 2 + 2; dev_str_desc->bDescriptorType = USB_DTYPE_STRING; - for(size_t i = 0; i < len; i++) dev_str_desc->wString[i] = str[i]; + for(size_t i = 0; i < len; i++) + dev_str_desc->wString[i] = str[i]; return dev_str_desc; } @@ -203,7 +228,11 @@ static void ccid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) { FuriHalUsbCcidConfig* cfg = (FuriHalUsbCcidConfig*)ctx; - usb_dev = dev; + furi_check(furi_hal_usb_ccid == NULL); + furi_hal_usb_ccid = malloc(sizeof(FuriHalUsbCcid)); + + furi_hal_usb_ccid->usb_dev = dev; + furi_hal_usb_ccid->ccid_semaphore = furi_semaphore_alloc(1, 1); usb_ccid.dev_descr->iManufacturer = 0; usb_ccid.dev_descr->iProduct = 0; @@ -231,42 +260,50 @@ static void ccid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) { usbd_reg_control(dev, ccid_control); usbd_connect(dev, true); + + furi_hal_usb_ccid->receive_buffer_data_index = 0; + furi_hal_usb_ccid->ccid_thread = furi_thread_alloc_ex("CcidWorker", 2048, ccid_worker, ctx); + furi_thread_start(furi_hal_usb_ccid->ccid_thread); } static void ccid_deinit(usbd_device* dev) { + furi_thread_flags_set(furi_thread_get_id(furi_hal_usb_ccid->ccid_thread), WorkerEvtStop); + furi_thread_join(furi_hal_usb_ccid->ccid_thread); + furi_thread_free(furi_hal_usb_ccid->ccid_thread); + usbd_reg_config(dev, NULL); usbd_reg_control(dev, NULL); free(usb_ccid.str_prod_descr); free(usb_ccid.str_serial_descr); + + free(furi_hal_usb_ccid); + + furi_hal_usb_ccid = NULL; } static void ccid_on_wakeup(usbd_device* dev) { UNUSED(dev); - connected = true; + furi_check(furi_hal_usb_ccid); + + furi_hal_usb_ccid->connected = true; } static void ccid_on_suspend(usbd_device* dev) { UNUSED(dev); - connected = false; -} - -typedef struct ccid_bulk_message_header { - uint8_t bMessageType; - uint32_t dwLength; - uint8_t bSlot; - uint8_t bSeq; -} FURI_PACKED ccid_bulk_message_header_t; - -uint8_t SendBuffer[sizeof(ccid_bulk_message_header_t) + CCID_DATABLOCK_SIZE]; + furi_check(furi_hal_usb_ccid); -//stores the data p -uint8_t ReceiveBuffer[sizeof(ccid_bulk_message_header_t) + CCID_DATABLOCK_SIZE]; + furi_hal_usb_ccid->connected = false; +} void CALLBACK_CCID_GetSlotStatus( uint8_t slot, uint8_t seq, struct rdr_to_pc_slot_status* responseSlotStatus) { + furi_check(responseSlotStatus); + + furi_check(furi_hal_usb_ccid); + responseSlotStatus->bMessageType = RDR_TO_PC_SLOTSTATUS; responseSlotStatus->bSlot = slot; @@ -277,7 +314,7 @@ void CALLBACK_CCID_GetSlotStatus( if(responseSlotStatus->bSlot == CCID_SLOT_INDEX) { responseSlotStatus->bError = CCID_ERROR_NOERROR; - if(smartcard_inserted) { + if(furi_hal_usb_ccid->smartcard_inserted) { responseSlotStatus->bStatus = CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } else { @@ -291,9 +328,16 @@ void CALLBACK_CCID_GetSlotStatus( } void CALLBACK_CCID_SetParametersT0( + struct pc_to_rdr_set_parameters_t0* requestSetParametersT0, struct rdr_to_pc_parameters_t0* responseSetParametersT0) { + furi_check(requestSetParametersT0); + furi_check(responseSetParametersT0); + + furi_check(furi_hal_usb_ccid); + furi_check(requestSetParametersT0->bProtocolNum == 0x00); //T0 + responseSetParametersT0->bMessageType = RDR_TO_PC_PARAMETERS; responseSetParametersT0->bSlot = requestSetParametersT0->bSlot; responseSetParametersT0->bSeq = requestSetParametersT0->bSeq; @@ -303,7 +347,7 @@ void CALLBACK_CCID_SetParametersT0( if(responseSetParametersT0->bSlot == CCID_SLOT_INDEX) { responseSetParametersT0->bError = CCID_ERROR_NOERROR; - if(smartcard_inserted) { + if(furi_hal_usb_ccid->smartcard_inserted) { responseSetParametersT0->bProtocolNum = requestSetParametersT0->bProtocolNum; responseSetParametersT0->bStatus = CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; @@ -321,6 +365,10 @@ void CALLBACK_CCID_IccPowerOn( uint8_t slot, uint8_t seq, struct rdr_to_pc_data_block* responseDataBlock) { + furi_check(responseDataBlock); + + furi_check(furi_hal_usb_ccid); + responseDataBlock->bMessageType = RDR_TO_PC_DATABLOCK; responseDataBlock->dwLength = 0; responseDataBlock->bSlot = slot; @@ -328,12 +376,12 @@ void CALLBACK_CCID_IccPowerOn( if(responseDataBlock->bSlot == CCID_SLOT_INDEX) { responseDataBlock->bError = CCID_ERROR_NOERROR; - if(smartcard_inserted) { - if(callbacks[CCID_SLOT_INDEX] != NULL) { - callbacks[CCID_SLOT_INDEX]->icc_power_on_callback( + if(furi_hal_usb_ccid->smartcard_inserted) { + if(furi_hal_usb_ccid->callbacks[CCID_SLOT_INDEX] != NULL) { + furi_hal_usb_ccid->callbacks[CCID_SLOT_INDEX]->icc_power_on_callback( responseDataBlock->abData, &responseDataBlock->dwLength, - cb_ctx[CCID_SLOT_INDEX]); + furi_hal_usb_ccid->cb_ctx[CCID_SLOT_INDEX]); responseDataBlock->bStatus = CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } else { @@ -353,6 +401,11 @@ void CALLBACK_CCID_IccPowerOn( void CALLBACK_CCID_XfrBlock( struct pc_to_rdr_xfr_block* receivedXfrBlock, struct rdr_to_pc_data_block* responseDataBlock) { + furi_check(receivedXfrBlock); + furi_check(responseDataBlock); + + furi_check(furi_hal_usb_ccid); + responseDataBlock->bMessageType = RDR_TO_PC_DATABLOCK; responseDataBlock->bSlot = receivedXfrBlock->bSlot; responseDataBlock->bSeq = receivedXfrBlock->bSeq; @@ -360,14 +413,14 @@ void CALLBACK_CCID_XfrBlock( if(responseDataBlock->bSlot == CCID_SLOT_INDEX) { responseDataBlock->bError = CCID_ERROR_NOERROR; - if(smartcard_inserted) { - if(callbacks[CCID_SLOT_INDEX] != NULL) { - callbacks[CCID_SLOT_INDEX]->xfr_datablock_callback( + if(furi_hal_usb_ccid->smartcard_inserted) { + if(furi_hal_usb_ccid->callbacks[CCID_SLOT_INDEX] != NULL) { + furi_hal_usb_ccid->callbacks[CCID_SLOT_INDEX]->xfr_datablock_callback( (const uint8_t*)receivedXfrBlock->abData, receivedXfrBlock->dwLength, responseDataBlock->abData, &responseDataBlock->dwLength, - cb_ctx[CCID_SLOT_INDEX]); + furi_hal_usb_ccid->cb_ctx[CCID_SLOT_INDEX]); responseDataBlock->bStatus = CCID_COMMANDSTATUS_PROCESSEDWITHOUTERROR | CCID_ICCSTATUS_PRESENTANDACTIVE; } else { @@ -384,118 +437,177 @@ void CALLBACK_CCID_XfrBlock( } } -void furi_hal_ccid_ccid_insert_smartcard(void) { - smartcard_inserted = true; +void furi_hal_usb_ccid_insert_smartcard(void) { + furi_check(furi_hal_usb_ccid); + + furi_hal_usb_ccid->smartcard_inserted = true; } -void furi_hal_ccid_ccid_remove_smartcard(void) { - smartcard_inserted = false; +void furi_hal_usb_ccid_remove_smartcard(void) { + furi_check(furi_hal_usb_ccid); + + furi_hal_usb_ccid->smartcard_inserted = false; } -void furi_hal_ccid_set_callbacks(CcidCallbacks* cb, void* context) { - callbacks[CCID_SLOT_INDEX] = cb; - cb_ctx[CCID_SLOT_INDEX] = context; +void furi_hal_usb_ccid_set_callbacks(CcidCallbacks* cb, void* context) { + furi_check(furi_hal_usb_ccid); + + furi_hal_usb_ccid->callbacks[CCID_SLOT_INDEX] = cb; + furi_hal_usb_ccid->cb_ctx[CCID_SLOT_INDEX] = context; +} + +void ccid_send_packet(uint8_t* data, uint8_t len) { + furi_check(furi_hal_usb_ccid); + + if(furi_hal_usb_ccid->ccid_semaphore == NULL || furi_hal_usb_ccid->connected == false) return; + furi_check( + furi_semaphore_acquire(furi_hal_usb_ccid->ccid_semaphore, FuriWaitForever) == + FuriStatusOk); + if(furi_hal_usb_ccid->connected == true) { + usbd_ep_write(furi_hal_usb_ccid->usb_dev, CCID_IN_EPADDR, data, len); + } +} + +void ccid_send_response(uint8_t* data, uint32_t len) { + uint32_t data_to_send = len; + uint32_t data_index = 0; + while(data_to_send >= CCID_EPSIZE) { + ccid_send_packet(&data[data_index], CCID_EPSIZE); + data_to_send = data_to_send - CCID_EPSIZE; + data_index = data_index + CCID_EPSIZE; + } + + ccid_send_packet(&data[data_index], data_to_send); } static void ccid_rx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) { UNUSED(dev); UNUSED(event); UNUSED(ep); + furi_check(furi_hal_usb_ccid); + + furi_semaphore_release(furi_hal_usb_ccid->ccid_semaphore); } static void ccid_tx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) { UNUSED(dev); - + UNUSED(ep); if(event == usbd_evt_eprx) { - if(connected == false) return; + furi_check(furi_hal_usb_ccid); + int32_t bytes_read = usbd_ep_read( + furi_hal_usb_ccid->usb_dev, + CCID_OUT_EPADDR, + &furi_hal_usb_ccid->receive_buffer[furi_hal_usb_ccid->receive_buffer_data_index], + CCID_EPSIZE); - //read initial CCID message header + if(bytes_read > 0) { + furi_hal_usb_ccid->receive_buffer_data_index = + furi_hal_usb_ccid->receive_buffer_data_index + bytes_read; - int32_t bytes_read = usbd_ep_read( - usb_dev, ep, &ReceiveBuffer, sizeof(ccid_bulk_message_header_t) + CCID_DATABLOCK_SIZE); - //minimum request size is header size - furi_check((uint16_t)bytes_read >= sizeof(ccid_bulk_message_header_t)); - ccid_bulk_message_header_t* message = (ccid_bulk_message_header_t*)&ReceiveBuffer; //-V641 - - if(message->bMessageType == PC_TO_RDR_ICCPOWERON) { - struct pc_to_rdr_icc_power_on* requestDataBlock = - (struct pc_to_rdr_icc_power_on*)message; //-V641 - struct rdr_to_pc_data_block* responseDataBlock = - (struct rdr_to_pc_data_block*)&SendBuffer; - - CALLBACK_CCID_IccPowerOn( - requestDataBlock->bSlot, requestDataBlock->bSeq, responseDataBlock); - - usbd_ep_write( - usb_dev, - CCID_IN_EPADDR, - responseDataBlock, - sizeof(struct rdr_to_pc_data_block) + - (sizeof(uint8_t) * responseDataBlock->dwLength)); - } else if(message->bMessageType == PC_TO_RDR_ICCPOWEROFF) { - struct pc_to_rdr_icc_power_off* requestIccPowerOff = - (struct pc_to_rdr_icc_power_off*)message; //-V641 - struct rdr_to_pc_slot_status* responseSlotStatus = - (struct rdr_to_pc_slot_status*)&SendBuffer; //-V641 - - CALLBACK_CCID_GetSlotStatus( - requestIccPowerOff->bSlot, requestIccPowerOff->bSeq, responseSlotStatus); - - usbd_ep_write( - usb_dev, CCID_IN_EPADDR, responseSlotStatus, sizeof(struct rdr_to_pc_slot_status)); - } else if(message->bMessageType == PC_TO_RDR_GETSLOTSTATUS) { - struct pc_to_rdr_get_slot_status* requestSlotStatus = - (struct pc_to_rdr_get_slot_status*)message; //-V641 - struct rdr_to_pc_slot_status* responseSlotStatus = - (struct rdr_to_pc_slot_status*)&SendBuffer; //-V641 - - CALLBACK_CCID_GetSlotStatus( - requestSlotStatus->bSlot, requestSlotStatus->bSeq, responseSlotStatus); - - usbd_ep_write( - usb_dev, CCID_IN_EPADDR, responseSlotStatus, sizeof(struct rdr_to_pc_slot_status)); - } else if(message->bMessageType == PC_TO_RDR_XFRBLOCK) { - struct pc_to_rdr_xfr_block* receivedXfrBlock = (struct pc_to_rdr_xfr_block*)message; - struct rdr_to_pc_data_block* responseDataBlock = - (struct rdr_to_pc_data_block*)&SendBuffer; - - furi_check(receivedXfrBlock->dwLength <= CCID_DATABLOCK_SIZE); - furi_check( - (uint16_t)bytes_read >= - sizeof(ccid_bulk_message_header_t) + receivedXfrBlock->dwLength); - - CALLBACK_CCID_XfrBlock(receivedXfrBlock, responseDataBlock); - - furi_check(responseDataBlock->dwLength <= CCID_DATABLOCK_SIZE); - - usbd_ep_write( - usb_dev, - CCID_IN_EPADDR, - responseDataBlock, - sizeof(struct rdr_to_pc_data_block) + - (sizeof(uint8_t) * responseDataBlock->dwLength)); - } else if(message->bMessageType == PC_TO_RDR_SETPARAMETERS) { - struct pc_to_rdr_set_parameters_t0* requestSetParametersT0 = - (struct pc_to_rdr_set_parameters_t0*)message; //-V641 - struct rdr_to_pc_parameters_t0* responseSetParametersT0 = - (struct rdr_to_pc_parameters_t0*)&SendBuffer; //-V641 - - furi_check(requestSetParametersT0->dwLength <= CCID_DATABLOCK_SIZE); - furi_check( - (uint16_t)bytes_read >= - sizeof(ccid_bulk_message_header_t) + requestSetParametersT0->dwLength); - - CALLBACK_CCID_SetParametersT0(requestSetParametersT0, responseSetParametersT0); - - usbd_ep_write( - usb_dev, - CCID_IN_EPADDR, - responseSetParametersT0, - sizeof(struct rdr_to_pc_parameters_t0)); + furi_thread_flags_set( + furi_thread_get_id(furi_hal_usb_ccid->ccid_thread), WorkerEvtRequest); } } } +static int32_t ccid_worker(void* context) { + UNUSED(context); + + while(1) { + furi_check(furi_hal_usb_ccid); + uint32_t flags = furi_thread_flags_wait( + WorkerEvtStop | WorkerEvtRequest, FuriFlagWaitAny, FuriWaitForever); + + if(flags & WorkerEvtRequest) { + //read initial CCID message header + + ccid_bulk_message_header_t* message = + (ccid_bulk_message_header_t*)&furi_hal_usb_ccid->receive_buffer; //-V641 + + furi_check(message); + + if(message->bMessageType == PC_TO_RDR_ICCPOWERON) { + struct pc_to_rdr_icc_power_on* requestDataBlock = + (struct pc_to_rdr_icc_power_on*)message; //-V641 + struct rdr_to_pc_data_block* responseDataBlock = + (struct rdr_to_pc_data_block*)&furi_hal_usb_ccid->send_buffer; + + CALLBACK_CCID_IccPowerOn( + requestDataBlock->bSlot, requestDataBlock->bSeq, responseDataBlock); + + ccid_send_response( + furi_hal_usb_ccid->send_buffer, + sizeof(struct rdr_to_pc_data_block) + + (sizeof(uint8_t) * responseDataBlock->dwLength)); + + furi_hal_usb_ccid->receive_buffer_data_index = 0; + + } else if(message->bMessageType == PC_TO_RDR_ICCPOWEROFF) { + struct pc_to_rdr_icc_power_off* requestIccPowerOff = + (struct pc_to_rdr_icc_power_off*)message; //-V641 + struct rdr_to_pc_slot_status* responseSlotStatus = + (struct rdr_to_pc_slot_status*)&furi_hal_usb_ccid->send_buffer; //-V641 + + CALLBACK_CCID_GetSlotStatus( + requestIccPowerOff->bSlot, requestIccPowerOff->bSeq, responseSlotStatus); + + ccid_send_response( + furi_hal_usb_ccid->send_buffer, sizeof(struct rdr_to_pc_slot_status)); + + furi_hal_usb_ccid->receive_buffer_data_index = 0; + + } else if(message->bMessageType == PC_TO_RDR_GETSLOTSTATUS) { + struct pc_to_rdr_get_slot_status* requestSlotStatus = + (struct pc_to_rdr_get_slot_status*)message; //-V641 + struct rdr_to_pc_slot_status* responseSlotStatus = + (struct rdr_to_pc_slot_status*)&furi_hal_usb_ccid->send_buffer; //-V641 + + CALLBACK_CCID_GetSlotStatus( + requestSlotStatus->bSlot, requestSlotStatus->bSeq, responseSlotStatus); + + ccid_send_response( + furi_hal_usb_ccid->send_buffer, sizeof(struct rdr_to_pc_slot_status)); + + furi_hal_usb_ccid->receive_buffer_data_index = 0; + + } else if(message->bMessageType == PC_TO_RDR_XFRBLOCK) { + struct pc_to_rdr_xfr_block* receivedXfrBlock = + (struct pc_to_rdr_xfr_block*)message; + struct rdr_to_pc_data_block* responseDataBlock = + (struct rdr_to_pc_data_block*)&furi_hal_usb_ccid->send_buffer; + + if(furi_hal_usb_ccid->receive_buffer_data_index >= + sizeof(struct pc_to_rdr_xfr_block) + receivedXfrBlock->dwLength) { + CALLBACK_CCID_XfrBlock(receivedXfrBlock, responseDataBlock); + + ccid_send_response( + furi_hal_usb_ccid->send_buffer, + sizeof(struct rdr_to_pc_data_block) + + (sizeof(uint8_t) * responseDataBlock->dwLength)); + + furi_hal_usb_ccid->receive_buffer_data_index = 0; + } + + } else if(message->bMessageType == PC_TO_RDR_SETPARAMETERS) { + struct pc_to_rdr_set_parameters_t0* requestSetParametersT0 = + (struct pc_to_rdr_set_parameters_t0*)message; //-V641 + struct rdr_to_pc_parameters_t0* responseSetParametersT0 = + (struct rdr_to_pc_parameters_t0*)&furi_hal_usb_ccid->send_buffer; //-V641 + + CALLBACK_CCID_SetParametersT0(requestSetParametersT0, responseSetParametersT0); + + ccid_send_response( + furi_hal_usb_ccid->send_buffer, sizeof(struct rdr_to_pc_parameters_t0)); + + furi_hal_usb_ccid->receive_buffer_data_index = 0; + } + } else if(flags & WorkerEvtStop) { + break; + } + } + return 0; +} + /* Configure endpoints */ static usbd_respond ccid_ep_config(usbd_device* dev, uint8_t cfg) { switch(cfg) { @@ -537,4 +649,4 @@ static usbd_respond ccid_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_ca } } return usbd_fail; -} \ No newline at end of file +} diff --git a/targets/f7/furi_hal/furi_hal_usb_cdc.c b/targets/f7/furi_hal/furi_hal_usb_cdc.c index 8525022c09f..cfedb5e76bf 100644 --- a/targets/f7/furi_hal/furi_hal_usb_cdc.c +++ b/targets/f7/furi_hal/furi_hal_usb_cdc.c @@ -518,7 +518,7 @@ int32_t furi_hal_cdc_receive(uint8_t if_num, uint8_t* buf, uint16_t max_len) { } else { len = usbd_ep_read(usb_dev, CDC1_RXD_EP, buf, max_len); } - return ((len < 0) ? 0 : len); + return (len < 0) ? 0 : len; } static void cdc_on_wakeup(usbd_device* dev) { diff --git a/targets/f7/furi_hal/furi_hal_usb_hid.c b/targets/f7/furi_hal/furi_hal_usb_hid.c index 9599aa1c12b..c83261226ec 100644 --- a/targets/f7/furi_hal/furi_hal_usb_hid.c +++ b/targets/f7/furi_hal/furi_hal_usb_hid.c @@ -368,7 +368,8 @@ static void* hid_set_string_descr(char* str) { struct usb_string_descriptor* dev_str_desc = malloc(len * 2 + 2); dev_str_desc->bLength = len * 2 + 2; dev_str_desc->bDescriptorType = USB_DTYPE_STRING; - for(size_t i = 0; i < len; i++) dev_str_desc->wString[i] = str[i]; + for(size_t i = 0; i < len; i++) + dev_str_desc->wString[i] = str[i]; return dev_str_desc; } diff --git a/targets/f7/furi_hal/furi_hal_usb_u2f.c b/targets/f7/furi_hal/furi_hal_usb_u2f.c index 390070c8f63..05f498376d5 100644 --- a/targets/f7/furi_hal/furi_hal_usb_u2f.c +++ b/targets/f7/furi_hal/furi_hal_usb_u2f.c @@ -6,12 +6,12 @@ #include "usb.h" #include "usb_hid.h" -#define HID_PAGE_FIDO 0xF1D0 -#define HID_FIDO_U2F 0x01 -#define HID_FIDO_INPUT 0x20 +#define HID_PAGE_FIDO 0xF1D0 +#define HID_FIDO_U2F 0x01 +#define HID_FIDO_INPUT 0x20 #define HID_FIDO_OUTPUT 0x21 -#define HID_EP_IN 0x81 +#define HID_EP_IN 0x81 #define HID_EP_OUT 0x01 struct HidIadDescriptor { @@ -237,7 +237,7 @@ void furi_hal_hid_u2f_send_response(uint8_t* data, uint8_t len) { uint32_t furi_hal_hid_u2f_get_request(uint8_t* data) { int32_t len = usbd_ep_read(usb_dev, HID_EP_IN, data, HID_U2F_PACKET_LEN); - return ((len < 0) ? 0 : len); + return (len < 0) ? 0 : len; } static void hid_u2f_rx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) { diff --git a/targets/f7/furi_hal/furi_hal_version.c b/targets/f7/furi_hal/furi_hal_version.c index c7656a8df5c..bd449e59936 100644 --- a/targets/f7/furi_hal/furi_hal_version.c +++ b/targets/f7/furi_hal/furi_hal_version.c @@ -11,7 +11,7 @@ #define TAG "FuriHalVersion" #define FURI_HAL_VERSION_OTP_HEADER_MAGIC 0xBABE -#define FURI_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE +#define FURI_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE /** OTP V0 Structure: prototypes and early EVT */ typedef struct { diff --git a/targets/f7/furi_hal/furi_hal_version_device.c b/targets/f7/furi_hal/furi_hal_version_device.c index af88c067190..6ddb99e866e 100644 --- a/targets/f7/furi_hal/furi_hal_version_device.c +++ b/targets/f7/furi_hal/furi_hal_version_device.c @@ -30,4 +30,4 @@ const char* furi_hal_version_get_srrc_id(void) { const char* furi_hal_version_get_ncc_id(void) { return "CCAJ23LP34D0T3"; -} \ No newline at end of file +} diff --git a/targets/f7/inc/FreeRTOSConfig.h b/targets/f7/inc/FreeRTOSConfig.h index 37aac1eb092..62310511d2d 100644 --- a/targets/f7/inc/FreeRTOSConfig.h +++ b/targets/f7/inc/FreeRTOSConfig.h @@ -14,73 +14,73 @@ #define configENABLE_FPU 1 #define configENABLE_MPU 0 -#define configUSE_PREEMPTION 1 -#define configSUPPORT_STATIC_ALLOCATION 1 +#define configUSE_PREEMPTION 1 +#define configSUPPORT_STATIC_ALLOCATION 1 #define configSUPPORT_DYNAMIC_ALLOCATION 0 -#define configUSE_IDLE_HOOK 0 -#define configUSE_TICK_HOOK 0 -#define configCPU_CLOCK_HZ (SystemCoreClock) -#define configTICK_RATE_HZ_RAW 1000 -#define configTICK_RATE_HZ ((TickType_t)configTICK_RATE_HZ_RAW) -#define configMAX_PRIORITIES (32) -#define configMINIMAL_STACK_SIZE ((uint16_t)128) +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ (SystemCoreClock) +#define configTICK_RATE_HZ_RAW 1000 +#define configTICK_RATE_HZ ((TickType_t)configTICK_RATE_HZ_RAW) +#define configMAX_PRIORITIES (32) +#define configMINIMAL_STACK_SIZE ((uint16_t)128) /* Heap size determined automatically by linker */ // #define configTOTAL_HEAP_SIZE ((size_t)0) #define configMAX_TASK_NAME_LEN (32) -#define configGENERATE_RUN_TIME_STATS 1 +#define configGENERATE_RUN_TIME_STATS 1 #define portGET_RUN_TIME_COUNTER_VALUE() (DWT->CYCCNT) #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() -#define configUSE_TRACE_FACILITY 1 -#define configUSE_16_BIT_TICKS 0 -#define configUSE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 0 -#define configCHECK_FOR_STACK_OVERFLOW 0 -#define configUSE_RECURSIVE_MUTEXES 1 -#define configUSE_COUNTING_SEMAPHORES 1 -#define configENABLE_BACKWARD_COMPATIBILITY 0 +#define configUSE_TRACE_FACILITY 1 +#define configUSE_16_BIT_TICKS 0 +#define configUSE_MUTEXES 1 +#define configQUEUE_REGISTRY_SIZE 0 +#define configCHECK_FOR_STACK_OVERFLOW 0 +#define configUSE_RECURSIVE_MUTEXES 1 +#define configUSE_COUNTING_SEMAPHORES 1 +#define configENABLE_BACKWARD_COMPATIBILITY 0 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 -#define configUSE_TICKLESS_IDLE 2 -#define configRECORD_STACK_HIGH_ADDRESS 1 -#define configUSE_NEWLIB_REENTRANT 0 +#define configUSE_TICKLESS_IDLE 2 +#define configRECORD_STACK_HIGH_ADDRESS 1 +#define configUSE_NEWLIB_REENTRANT 0 /* Defaults to size_t for backward compatibility, but can be changed if lengths will always be less than the number of bytes in a size_t. */ -#define configMESSAGE_BUFFER_LENGTH_TYPE size_t +#define configMESSAGE_BUFFER_LENGTH_TYPE size_t #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 1 -#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 4 +#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 4 /* Co-routine definitions. */ #define configUSE_CO_ROUTINES 0 /* Software timer definitions. */ -#define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY (2) -#define configTIMER_QUEUE_LENGTH 32 -#define configTIMER_TASK_STACK_DEPTH 256 +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY (2) +#define configTIMER_QUEUE_LENGTH 32 +#define configTIMER_TASK_STACK_DEPTH 256 #define configTIMER_SERVICE_TASK_NAME "TimersSrv" -#define configIDLE_TASK_NAME "(-_-)" +#define configIDLE_TASK_NAME "(-_-)" #define configIDLE_TASK_STACK_DEPTH 128 /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ -#define INCLUDE_xTaskGetHandle 1 -#define INCLUDE_eTaskGetState 1 +#define INCLUDE_xTaskGetHandle 1 +#define INCLUDE_eTaskGetState 1 #define INCLUDE_uxTaskGetStackHighWaterMark 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_xQueueGetMutexHolder 1 -#define INCLUDE_xTaskGetCurrentTaskHandle 1 -#define INCLUDE_xTaskGetSchedulerState 1 -#define INCLUDE_xTimerPendFunctionCall 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_xQueueGetMutexHolder 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 +#define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerPendFunctionCall 1 /* Workaround for various notification issues: * - First one used by system primitives @@ -138,7 +138,7 @@ header file. */ /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */ -#define vPortSVCHandler SVC_Handler +#define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler #define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1 diff --git a/targets/f7/inc/furi_config.h b/targets/f7/inc/furi_config.h index c935611ab7b..d03549c7908 100644 --- a/targets/f7/inc/furi_config.h +++ b/targets/f7/inc/furi_config.h @@ -1,3 +1,3 @@ #pragma once -#define FURI_CONFIG_THREAD_MAX_PRIORITIES (32) \ No newline at end of file +#define FURI_CONFIG_THREAD_MAX_PRIORITIES (32) diff --git a/targets/f7/inc/stm32.h b/targets/f7/inc/stm32.h index 8e5cc379b5d..8209fd6a25d 100644 --- a/targets/f7/inc/stm32.h +++ b/targets/f7/inc/stm32.h @@ -4,17 +4,17 @@ /* modify bitfield */ #define _BMD(reg, msk, val) (reg) = (((reg) & ~(msk)) | (val)) /* set bitfield */ -#define _BST(reg, bits) (reg) = ((reg) | (bits)) +#define _BST(reg, bits) (reg) = ((reg) | (bits)) /* clear bitfield */ -#define _BCL(reg, bits) (reg) = ((reg) & ~(bits)) +#define _BCL(reg, bits) (reg) = ((reg) & ~(bits)) /* wait until bitfield set */ -#define _WBS(reg, bits) while(((reg) & (bits)) == 0) +#define _WBS(reg, bits) while(((reg) & (bits)) == 0) /* wait until bitfield clear */ -#define _WBC(reg, bits) while(((reg) & (bits)) != 0) +#define _WBC(reg, bits) while(((reg) & (bits)) != 0) /* wait for bitfield value */ #define _WVL(reg, msk, val) while(((reg) & (msk)) != (val)) /* bit value */ -#define _BV(bit) (0x01 << (bit)) +#define _BV(bit) (0x01 << (bit)) #include "stm32wbxx.h" diff --git a/targets/f7/platform_specific/math_wrapper.h b/targets/f7/platform_specific/math_wrapper.h index 83f5a8b75d3..e2dfd4541c0 100644 --- a/targets/f7/platform_specific/math_wrapper.h +++ b/targets/f7/platform_specific/math_wrapper.h @@ -1,2 +1,2 @@ #pragma once -#include \ No newline at end of file +#include diff --git a/targets/furi_hal_include/furi_hal_bt.h b/targets/furi_hal_include/furi_hal_bt.h index ef6b31bb43d..6da72331115 100644 --- a/targets/furi_hal_include/furi_hal_bt.h +++ b/targets/furi_hal_include/furi_hal_bt.h @@ -16,7 +16,7 @@ #define FURI_HAL_BT_STACK_VERSION_MAJOR (1) #define FURI_HAL_BT_STACK_VERSION_MINOR (12) -#define FURI_HAL_BT_C2_START_TIMEOUT (1000) +#define FURI_HAL_BT_C2_START_TIMEOUT (1000) #ifdef __cplusplus extern "C" { diff --git a/targets/furi_hal_include/furi_hal_crypto.h b/targets/furi_hal_include/furi_hal_crypto.h index 04a2c67cf18..9a3b488fb29 100644 --- a/targets/furi_hal_include/furi_hal_crypto.h +++ b/targets/furi_hal_include/furi_hal_crypto.h @@ -51,14 +51,14 @@ extern "C" { /** Factory provisioned keys slot range. All of them are exactly same on all flippers. */ #define FURI_HAL_CRYPTO_ENCLAVE_FACTORY_KEY_SLOT_START (1u) -#define FURI_HAL_CRYPTO_ENCLAVE_FACTORY_KEY_SLOT_END (10u) +#define FURI_HAL_CRYPTO_ENCLAVE_FACTORY_KEY_SLOT_END (10u) /** Device unique key slot. This key generated on first use or provisioned by user. Use furi_hal_crypto_enclave_ensure_key before using this slot. */ #define FURI_HAL_CRYPTO_ENCLAVE_UNIQUE_KEY_SLOT (11u) /** User key slot range. This slots can be used for your needs, but never use them in public apps. */ #define FURI_HAL_CRYPTO_ENCLAVE_USER_KEY_SLOT_START (12u) -#define FURI_HAL_CRYPTO_ENCLAVE_USER_KEY_SLOT_END (100u) +#define FURI_HAL_CRYPTO_ENCLAVE_USER_KEY_SLOT_END (100u) /** [Deprecated] Indicates availability of advanced crypto functions, will be dropped before v1.0 */ #define FURI_HAL_CRYPTO_ADVANCED_AVAIL 1 diff --git a/targets/furi_hal_include/furi_hal_memory.h b/targets/furi_hal_include/furi_hal_memory.h index 6451d93bca3..c57c434fa80 100644 --- a/targets/furi_hal_include/furi_hal_memory.h +++ b/targets/furi_hal_include/furi_hal_memory.h @@ -41,4 +41,4 @@ size_t furi_hal_memory_max_pool_block(void); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/targets/furi_hal_include/furi_hal_usb_ccid.h b/targets/furi_hal_include/furi_hal_usb_ccid.h index cbd0bf092b9..fbe69ce3cbd 100644 --- a/targets/furi_hal_include/furi_hal_usb_ccid.h +++ b/targets/furi_hal_include/furi_hal_usb_ccid.h @@ -1,9 +1,13 @@ #pragma once + #include "hid_usage_desktop.h" #include "hid_usage_button.h" #include "hid_usage_keyboard.h" #include "hid_usage_consumer.h" #include "hid_usage_led.h" +#include + +#define CCID_SHORT_APDU_SIZE (0xFF) #ifdef __cplusplus extern "C" { @@ -26,10 +30,18 @@ typedef struct { void* context); } CcidCallbacks; -void furi_hal_ccid_set_callbacks(CcidCallbacks* cb, void* context); +/** Set CCID callbacks + * + * @param cb CcidCallbacks instance + * @param context The context for callbacks + */ +void furi_hal_usb_ccid_set_callbacks(CcidCallbacks* cb, void* context); + +/** Insert Smart Card */ +void furi_hal_usb_ccid_insert_smartcard(void); -void furi_hal_ccid_ccid_insert_smartcard(void); -void furi_hal_ccid_ccid_remove_smartcard(void); +/** Remove Smart Card */ +void furi_hal_usb_ccid_remove_smartcard(void); #ifdef __cplusplus } diff --git a/targets/furi_hal_include/furi_hal_usb_hid.h b/targets/furi_hal_include/furi_hal_usb_hid.h index 29994196fcd..af4a542de9d 100644 --- a/targets/furi_hal_include/furi_hal_usb_hid.h +++ b/targets/furi_hal_include/furi_hal_usb_hid.h @@ -10,14 +10,14 @@ extern "C" { #endif /** Max number of simultaneously pressed keys (keyboard) */ -#define HID_KB_MAX_KEYS 6 +#define HID_KB_MAX_KEYS 6 /** Max number of simultaneously pressed keys (consumer control) */ #define HID_CONSUMER_MAX_KEYS 2 /** OS-specific consumer keys, defined as "Reserved" in HID Usage Tables document */ #define HID_CONSUMER_BRIGHTNESS_INCREMENT 0x006F #define HID_CONSUMER_BRIGHTNESS_DECREMENT 0x0070 -#define HID_CONSUMER_FN_GLOBE 0x029D +#define HID_CONSUMER_FN_GLOBE 0x029D #define HID_KEYBOARD_NONE 0x00 diff --git a/targets/furi_hal_include/furi_hal_version.h b/targets/furi_hal_include/furi_hal_version.h index 79ebf4275d8..8e00a754166 100644 --- a/targets/furi_hal_include/furi_hal_version.h +++ b/targets/furi_hal_include/furi_hal_version.h @@ -14,8 +14,8 @@ extern "C" { #endif -#define FURI_HAL_VERSION_NAME_LENGTH 8 -#define FURI_HAL_VERSION_ARRAY_NAME_LENGTH (FURI_HAL_VERSION_NAME_LENGTH + 1) +#define FURI_HAL_VERSION_NAME_LENGTH 8 +#define FURI_HAL_VERSION_ARRAY_NAME_LENGTH (FURI_HAL_VERSION_NAME_LENGTH + 1) /** BLE symbol + "Flipper " + name */ #define FURI_HAL_VERSION_DEVICE_NAME_LENGTH (1 + 8 + FURI_HAL_VERSION_ARRAY_NAME_LENGTH)