diff --git a/.ci_files/rgb.patch b/.ci_files/rgb.patch index b5895d9c1f..7108901093 100644 --- a/.ci_files/rgb.patch +++ b/.ci_files/rgb.patch @@ -1,5 +1,5 @@ diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c -index 9baa738..91ad7c1 100644 +index d4c5b91..8b43599 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -9,6 +9,7 @@ @@ -10,7 +10,7 @@ index 9baa738..91ad7c1 100644 #define TAG "NotificationSrv" -@@ -589,6 +590,7 @@ int32_t notification_srv(void* p) { +@@ -588,6 +589,7 @@ int32_t notification_srv(void* p) { break; case SaveSettingsMessage: notification_save_settings(app); @@ -19,7 +19,7 @@ index 9baa738..91ad7c1 100644 } diff --git a/applications/settings/notification_settings/notification_settings_app.c b/applications/settings/notification_settings/notification_settings_app.c -index 2a1d988..dda86f3 100644 +index 7576dcf..ae022e2 100644 --- a/applications/settings/notification_settings/notification_settings_app.c +++ b/applications/settings/notification_settings/notification_settings_app.c @@ -3,6 +3,7 @@ @@ -99,7 +99,7 @@ index 2a1d988..dda86f3 100644 static uint32_t notification_app_settings_exit(void* context) { UNUSED(context); return VIEW_NONE; -@@ -192,8 +248,40 @@ static NotificationAppSettings* alloc_settings() { +@@ -192,8 +248,40 @@ static NotificationAppSettings* alloc_settings(void) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, contrast_text[value_index]); @@ -143,7 +143,7 @@ index 2a1d988..dda86f3 100644 variable_item_set_current_value_index(item, value_index); diff --git a/applications/settings/notification_settings/rgb_backlight.c b/applications/settings/notification_settings/rgb_backlight.c new file mode 100644 -index 0000000..98f0d3a +index 0000000..4edd775 --- /dev/null +++ b/applications/settings/notification_settings/rgb_backlight.c @@ -0,0 +1,217 @@ @@ -169,9 +169,9 @@ index 0000000..98f0d3a +#include +#include + -+#define RGB_BACKLIGHT_SETTINGS_VERSION 6 ++#define RGB_BACKLIGHT_SETTINGS_VERSION 6 +#define RGB_BACKLIGHT_SETTINGS_FILE_NAME ".rgb_backlight.settings" -+#define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) ++#define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME) + +#define COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightColor)) + @@ -263,7 +263,7 @@ index 0000000..98f0d3a + storage_file_free(file); + furi_record_close(RECORD_STORAGE); + rgb_settings.settings_is_loaded = true; -+}; ++} + +void rgb_backlight_save_settings(void) { + RGBBacklightSettings settings; @@ -294,7 +294,7 @@ index 0000000..98f0d3a + storage_file_close(file); + storage_file_free(file); + furi_record_close(RECORD_STORAGE); -+}; ++} + +RGBBacklightSettings* rgb_backlight_get_settings(void) { + if(!rgb_settings.settings_is_loaded) { @@ -366,7 +366,7 @@ index 0000000..98f0d3a +} diff --git a/applications/settings/notification_settings/rgb_backlight.h b/applications/settings/notification_settings/rgb_backlight.h new file mode 100644 -index 0000000..68dacda +index 0000000..f215ed3 --- /dev/null +++ b/applications/settings/notification_settings/rgb_backlight.h @@ -0,0 +1,91 @@ @@ -461,10 +461,9 @@ index 0000000..68dacda + * @return Указатель на строку с названием цвета + */ +const char* rgb_backlight_get_color_text(uint8_t index); -\ No newline at end of file diff --git a/lib/drivers/SK6805.c b/lib/drivers/SK6805.c new file mode 100644 -index 0000000..572e1df +index 0000000..b89f82a --- /dev/null +++ b/lib/drivers/SK6805.c @@ -0,0 +1,101 @@ @@ -491,14 +490,14 @@ index 0000000..572e1df + +/* Настройки */ +#define SK6805_LED_COUNT 3 //Количество светодиодов на плате подсветки -+#define SK6805_LED_PIN &led_pin //Порт подключения светодиодов ++#define SK6805_LED_PIN &led_pin //Порт подключения светодиодов + +#ifdef FURI_DEBUG +#define DEBUG_PIN &gpio_ext_pa7 +#define DEBUG_INIT() \ + furi_hal_gpio_init(DEBUG_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh) +#define DEBUG_SET_HIGH() furi_hal_gpio_write(DEBUG_PIN, true) -+#define DEBUG_SET_LOW() furi_hal_gpio_write(DEBUG_PIN, false) ++#define DEBUG_SET_LOW() furi_hal_gpio_write(DEBUG_PIN, false) +#else +#define DEBUG_INIT() +#define DEBUG_SET_HIGH() @@ -571,7 +570,7 @@ index 0000000..572e1df +} diff --git a/lib/drivers/SK6805.h b/lib/drivers/SK6805.h new file mode 100644 -index 0000000..7c58956 +index 0000000..c97054f --- /dev/null +++ b/lib/drivers/SK6805.h @@ -0,0 +1,51 @@ @@ -626,9 +625,8 @@ index 0000000..7c58956 +void SK6805_update(void); + +#endif /* SK6805_H_ */ -\ No newline at end of file diff --git a/targets/f7/furi_hal/furi_hal_light.c b/targets/f7/furi_hal/furi_hal_light.c -index 83e1603..45798ca 100644 +index 621478d..ef15153 100644 --- a/targets/f7/furi_hal/furi_hal_light.c +++ b/targets/f7/furi_hal/furi_hal_light.c @@ -3,6 +3,7 @@ @@ -637,7 +635,7 @@ index 83e1603..45798ca 100644 #include +#include - #define LED_CURRENT_RED (50u) + #define LED_CURRENT_RED (50u) #define LED_CURRENT_GREEN (50u) @@ -31,22 +32,21 @@ void furi_hal_light_init(void) { } diff --git a/.clang-format b/.clang-format index 4b76f7fa43..c42068920c 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/.gitignore b/.gitignore index 59c526d2d5..888c6a6b24 100644 --- a/.gitignore +++ b/.gitignore @@ -45,9 +45,6 @@ null.d .sconsign.dblite -# Visual Studio Code -/.vscode - # bundle output /dist /artifacts-default diff --git a/.gitmodules b/.gitmodules index 6f73e125ac..df5bf648fa 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 b6001ca5c0..674231d220 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 5d751aaf63..da2ef41a12 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 481efcdef3..bd4df47d60 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 9afabf9268..5e0da68977 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/CHANGELOG.md b/CHANGELOG.md index aa73753099..0bd2bf2516 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,57 +1,64 @@ ## Main changes - SubGHz: - - Add new protocol - legrand 18bit (by @user890104) - - OFW: Princeton protocol add custom guard time support - - Princeton fix guard time bounds and show guard time multiplier in UI -- NFC: - - Fix Mifare DESFire reading (revert of buffer check workaround for rare emv cases) (some emv cards can be read only via Extra Actions -> Read specific card type -> EMV) - - Better plugins(parsers) loading - much faster emulation launch from favourites, no more lags in Saved menu - - OFW: MF Ultralight Original write support - - OFW: Mifare Plus detection support - - OFW: Felica emulation - - OFW: Write to ultralight cards is now possible (no UID writing) - - OFW: Fixed infinite loop in dictionary attack scene -* LF RFID: OFW: Added Support for Securakey Protocol -* JS: `adc` support in `gpio` module (by @jamisonderek) -* JS: `storage` module (without virtual mount API at the moment) (by @Willy-JL) -* BadUSB: Add Finnish keyboard layout (by @nicou | PR #761) -* Archive: Fix SubGHz Remote files in favourites falling into non working and non removable state + - **Novoferm** remotes full support + - Fix Decode scene in RAW files + - Add manually -> Add Sommer FM238 option for cases when default option doesn't work (named as Sommer fm2) + - Remove broken preset modulation + - Normstahl, Sommer, MHouse, Aprimatic -> Fixes for button codes and more in Add manually + - Custom button improvements for MHouse, Novoferm, Nice Smilo + - Hormann EcoStar -> Add manually support, and custom button support + - Hormann HSM 44bit static -> Button code decoding fix + - Choose RSSI threshold for Hopping mode (by @Willy-JL) +- NFC: + - OFW: Ultralight C authentication with des key + - EMV Transactions less nested, hide if unavailable (by @Willy-JL | PR #771) + - Update Mifare Classic default keys dict with new keys from proxmark3 repo and UberGuidoZ repo +- LF RFID: + - Update T5577 password list (by @korden32 | PR #774) + - Add DEZ 8 display form for EM4100 (by @korden32 | PR #776 & (#777 by @mishamyte)) +- JS: + - Refactor widget and keyboard modules, fix crash (by @Willy-JL | PR #770) + - SubGHz module fixes and improvements (by @Willy-JL) +* OFW: Infrared: check for negative timings +* OFW: Fix iButton/LFRFID Add Manually results being discarded +* OFW: Event Loop Timers +* OFW: Updater: resource compression * Apps: **Check out more Apps updates and fixes by following** [this link](https://github.com/xMasterX/all-the-plugins/commits/dev) ## Other changes -* SubGHz: Fix add manually princeton -* SubGHz: Sync signal delete scene with OFW -* SubGHz: Fix incorrect rx key state when opening Read menu -* SubGHz: Fix incorrect state in decode raw exit - causing keys to be not removed from history and showing up in Read menu after exit from decode raw -* Misc: Remove outdated brew sdk install files -* Misc: Revert USB CDC changes to fix usb serial -* Misc: Fix usage of deprecated `icon_get_data` -* Loader: Better API Mismatch message (by @Willy-JL) -* CLI: Move part of the CLI to microsd to free up space for COMPACT 0 builds (by @Willy-JL) -* NFC: Fix typo in parsers -* Apps: Fix `input_callback` and `timer_callback` usage of non `void` argument as input -* LF RFID: OFW PR 3728: Securakey - Add Support for RKKTH Plain Text Format (by @zinongli) -* OFW: ReadMe: update outdated bits and pieces -* OFW: Debug: backup openocd work area, fix crash after fresh debugger connect and continue -* OFW: ELF, Flipper application: do not crash on "out of memory" -* OFW: MF Plus - Don't crash on reading weird cards -* OFW: SubGhz: fix Missed the "Deleted" screen when deleting RAW Subghz (by @Skorpionm) -* OFW: JS: Disable logging in mjs +2k free flash (by @hedger) -* OFW: Archive: fix memory leak in favorites add/remove -* OFW: Furi: Fix EventLoop state persisting on same thread after free -* OFW: Cli: top -* OFW: Desktop lockup fix, GUI improvements -* OFW: Loader: fix crash on "locked via cli loader" -* OFW: SubGhz: fix navigation GUI -* OFW: Furi: event loop -* OFW: Code Cleanup: unused includes, useless checks, unused variables, etc... -* OFW: SubGhz: fix gui "No transition to the "Saved" menu when deleting a SubGHz RAW file" -* OFW: RPC: Add TarExtract command, some small fixes -* OFW: Use static synchronisation primitives -* OFW: cleanup of various warnings from clangd -* OFW: Add initial ISO7816 support -* OFW: fbt, vscode: tweaks for cdb generation for clangd -* OFW: Updater: fix inability to update with bigger updater.bin -* OFW: Furi: wrap message queue in container, prepare it for epoll. Accessor: disable expansion service on start. +* OFW: HID/BLE Keyboard UI refactoring +* OFW: CCID: Add CCIDWorker +* OFW: Disabled ISR runtime stats collection for updater builds +* OFW: VSCode fixes: .gitignore & clangd +* OFW: ufbt: synced .clang-format rules with main +* OFW: Code formatting update +* OFW: scripts: runfap: fixed starting apps with spaces in path +* OFW: toolchain: v38. clangd as default language server +* OFW: NFC: ISO15693 Render Typo Fix +* OFW: tar archive: fix double free +* OFW: ufbt: added ARGS to commandline parser +* OFW: lib: sconscript todo cleanup +* OFW: Intruder animation +* OFW: Desktop: allow to close blocking bad sd animation +* OFW: Updater: reset various debug flags on production build flash (was done in same way in UL before) +* OFW: Fix PVS Warnings +* OFW: CCID: Improve request and response data handling +* OFW: Furi: count ISR time. Cli: show ISR time in top. +* OFW: toolchain: v37 +* OFW: NFC: Cache plugin name not full path, saves some RAM (by @Willy-JL) +* OFW: copro: bumped to 1.20.0 +* OFW: input_srv: Put input state data on the stack of the service +* OFW: Coalesce some allocations +* OFW: updater: slightly smaller image +* OFW: Updater: Fix double dir cleanup +* OFW: cli: storage: minor subcommand lookup refactor +* OFW: LFRFID Securakey: Add Support for RKKTH Plain Text Format +* OFW: NFC: Add mf_classic_set_sector_trailer_read function +* OFW: Separate editing and renaming in iButton and LFRFID +* OFW: New js modules documentation added +* OFW: Update link to mfkey32 +* OFW: NFC: Desfire Renderer Minor Debug +* OFW: RPC: Fix input lockup on disconnect +* OFW: Thread Signals

#### Known NFC post-refactor regressions list: - Mifare Mini clones reading is broken (original mini working fine) (OFW) diff --git a/ReadMe.md b/ReadMe.md index 56f098d809..7eb98aeed3 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -79,6 +79,7 @@ - Infrared -> External IR modules support (with autodetect by OFW) - **NFC/RFID/iButton** * LFRFID and iButton Fuzzer plugins + * Add DEZ 8 display form for EM4100 (by @korden32) * Extra Mifare Classic keys in system dict * EMV Protocol + Public data parser (by @Leptopt1los and @wosk) * NFC `Add manually` -> Mifare Classic with custom UID @@ -104,18 +105,18 @@ Thanks to Official team (to their SubGHz Developer, Skorp) for implementing supp Keeloq [Not ALL systems supported for decode or emulation!] - [Supported manufacturers list](https://pastes.io/raw/unuj9bhe4m) -Encoders or emulation support made by @xMasterX: +Encoders or emulation (+ programming mode) support made by @xMasterX: - Nero Radio 57bit (+ 56bit support) - CAME 12bit/24bit encoder fixes (Fixes are now merged in OFW) -- Keeloq: Dea Mio, Genius Bravo, GSN, HCS101, AN-Motors, JCM Tech, MHouse, Nice Smilo, DTM Neo, FAAC RC,XT, Mutancode, Normstahl, Beninca + Allmatic, Stilmatic, CAME Space, Aprimatic (model TR and similar), Centurion Nova (thanks Carlos !) +- Keeloq: Dea Mio, Genius Bravo, GSN, HCS101, AN-Motors, JCM Tech, MHouse, Nice Smilo, DTM Neo, FAAC RC,XT, Mutancode, Normstahl, Beninca + Allmatic, Stilmatic, CAME Space, Aprimatic (model TR and similar), Centurion Nova (thanks Carlos !), Hormann EcoStar, Novoferm -Encoders or emulation made by @Eng1n33r(first implementation in Q2 2022) and @xMasterX (current version): +Protocols support made by Skorp (original implementation) and @xMasterX (current version): - CAME Atomo -> Update! check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) - Nice Flor S -> How to create new remote - [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) -- FAAC SLH (Spa) -> Update!!! Check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) +- FAAC SLH (Spa) -> Update!!! (Programming mode!) Check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) - Keeloq: BFT Mitto -> Update! Check out new [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) - Star Line -- Security+ v1 & v2 (encoders was made in OFW) +- Security+ v1 & v2 Encoders made by @assasinfil and @xMasterX: - Somfy Telis -> How to create new remote - [instructions](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/documentation/SubGHzRemoteProg.md) diff --git a/SConstruct b/SConstruct index 268472a7c7..48baaa95ef 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 5c5a3bd453..8e53cc6fb8 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 792ebfd8f8..58b65e1947 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 6993901d24..46a1237f93 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 0000000000..77d2711ef9 --- /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 0000000000..fe0a8e539f --- /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 050457f8c1..215ec60ee6 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 1a66fa7755..6c1bb106a9 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 3d337d23a0..6b408c7f50 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 0000000000..e222756189 --- /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 0000000000..cb328d0953 --- /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 5fb695af19..3de5555f49 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 48a1894406..50eb476a9c 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 d4fe433efe..31003ae0b3 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 0000000000..7d42ad3390 --- /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 0000000000..5c7e0ce558 --- /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 fc7fb18945..e3bcf4e9c9 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 0bf70e9c63..6bce58078d 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 8776f8b7ad..13c0b299fa 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 ddca372e38..7b28b66bfe 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 82a6fbc774..3f685ab30d 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 03be6459ec..91411bd8d4 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 24202ad1c6..226bb3e746 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 dcea3da5fa..bee1bf7330 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 70f323937d..acd4bf56a6 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 9c65910a04..8e1884e9a2 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 0000000000..c3bcf5fdaf 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 0000000000..ab7d34af8c 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 0000000000..8c125865c3 --- /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 517a4fd24a..de29e91b39 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 024799ebe5..43aba8bb15 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 b65a35bf5a..a0f189fdbb 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 15984083d1..8ff774bdf9 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 ea4fea28ce..73d3ff0794 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 d26acf5770..888a664442 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 4b515206c9..aaaa031e45 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 cf6a132200..e64b630b2e 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 8bf7753c0e..032fe115e3 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 083db5a9a9..9310cfc9c9 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 1e44070764..0898ac8eda 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 f5b9e762d7..63ea706ed6 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 65a25cf494..f317fbf680 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 3a8c08d718..3e93ac4c3b 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 55b9f7885b..fc2c7479c1 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 2b7710451f..e322a58ae2 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 f77842a3a0..ac72ab5c1a 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -17,18 +17,18 @@ #define TAG "SubGhzDeviceCc1101Ext" -#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO (&gpio_ext_pb2) -#define SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO &gpio_ext_pc3 +#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO (&gpio_ext_pb2) +#define SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO &gpio_ext_pc3 #define SUBGHZ_DEVICE_CC1101_EXT_FORCE_DANGEROUS_RANGE false #define SUBGHZ_DEVICE_CC1101_CONFIG_VER 1 /* 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 \ @@ -390,7 +390,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; @@ -879,9 +879,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 68f2b8aff9..eef92dbe84 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 af21336027..faa3feb915 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 fadb9089fe..50c26ba7a6 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 d0db44c4aa..be4f78930d 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 17cc8be5f9..1abd85cd45 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 4cef7567bc..721e7c6461 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 dafe568863..895f05ce76 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/archive_i.h b/applications/main/archive/archive_i.h index 3ae549ca69..6982cc0a6e 100644 --- a/applications/main/archive/archive_i.h +++ b/applications/main/archive/archive_i.h @@ -43,4 +43,4 @@ struct ArchiveApp { char file_extension[MAX_EXT_LEN + 1]; }; -void archive_show_loading_popup(ArchiveApp* context, bool show); \ No newline at end of file +void archive_show_loading_popup(ArchiveApp* context, bool show); diff --git a/applications/main/archive/helpers/archive_browser.c b/applications/main/archive/helpers/archive_browser.c index cd55d7e529..bd9b007456 100644 --- a/applications/main/archive/helpers/archive_browser.c +++ b/applications/main/archive/helpers/archive_browser.c @@ -344,7 +344,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 37c05da302..1e1cdc8818 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_LEFT InputKeyLeft // Default tab switch direction -#define TAB_DEFAULT ArchiveTabFavorites // Start tab +#define TAB_LEFT InputKeyLeft // Default tab switch direction +#define TAB_DEFAULT ArchiveTabFavorites // Start tab #define FILE_LIST_BUF_LEN 50 static const char* tab_default_paths[] = { @@ -67,7 +67,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 db89433782..64ffcdd7bd 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/helpers/archive_menu.h b/applications/main/archive/helpers/archive_menu.h index bd5200b21f..683c6e6fcf 100644 --- a/applications/main/archive/helpers/archive_menu.h +++ b/applications/main/archive/helpers/archive_menu.h @@ -47,4 +47,4 @@ static void obj->text = furi_string_alloc_set(text); obj->event = event; } -#pragma GCC diagnostic pop \ No newline at end of file +#pragma GCC diagnostic pop diff --git a/applications/main/archive/scenes/archive_scene_browser.c b/applications/main/archive/scenes/archive_scene_browser.c index e078471300..b7f7e0303c 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_config.h b/applications/main/archive/scenes/archive_scene_config.h index 2f3ebe7714..9f63724430 100644 --- a/applications/main/archive/scenes/archive_scene_config.h +++ b/applications/main/archive/scenes/archive_scene_config.h @@ -3,4 +3,4 @@ ADD_SCENE(archive, rename, Rename) ADD_SCENE(archive, delete, Delete) ADD_SCENE(archive, info, Info) ADD_SCENE(archive, show, Show) -ADD_SCENE(archive, new_dir, NewDir) \ No newline at end of file +ADD_SCENE(archive, new_dir, NewDir) diff --git a/applications/main/archive/scenes/archive_scene_delete.c b/applications/main/archive/scenes/archive_scene_delete.c index b23fae574c..a0610ceeb8 100644 --- a/applications/main/archive/scenes/archive_scene_delete.c +++ b/applications/main/archive/scenes/archive_scene_delete.c @@ -3,7 +3,7 @@ #include "../helpers/archive_browser.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 21b4e05d87..2753f193ef 100644 --- a/applications/main/archive/scenes/archive_scene_rename.c +++ b/applications/main/archive/scenes/archive_scene_rename.c @@ -9,7 +9,7 @@ #define TAG "Archive" #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 0fe1ff62a8..e1739ca5b1 100644 --- a/applications/main/archive/views/archive_browser_view.c +++ b/applications/main/archive/views/archive_browser_view.c @@ -4,9 +4,9 @@ #include "archive_browser_view.h" #include "../helpers/archive_browser.h" -#define TAG "Archive" +#define TAG "Archive" #define SCROLL_INTERVAL (333) -#define SCROLL_DELAY (2) +#define SCROLL_DELAY (2) static const char* ArchiveTabNames[] = { [ArchiveTabFavorites] = "Favorites", @@ -753,4 +753,4 @@ void archive_browser_clipboard_reset(ArchiveBrowserView* browser) { ArchiveBrowserViewModel * model, { model->clipboard_mode = CLIPBOARD_MODE_OFF; }, true); -} \ No newline at end of file +} diff --git a/applications/main/archive/views/archive_browser_view.h b/applications/main/archive/views/archive_browser_view.h index 87d029664a..ade01fb827 100644 --- a/applications/main/archive/views/archive_browser_view.h +++ b/applications/main/archive/views/archive_browser_view.h @@ -14,15 +14,15 @@ #include "../helpers/archive_favorites.h" #include "gui/modules/file_browser_worker.h" -#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 5u -#define MOVE_OFFSET 5u +#define MENU_ITEMS 5u +#define MOVE_OFFSET 5u -#define CLIPBOARD_MODE_OFF (0U) -#define CLIPBOARD_MODE_CUT (1U) +#define CLIPBOARD_MODE_OFF (0U) +#define CLIPBOARD_MODE_CUT (1U) #define CLIPBOARD_MODE_COPY (2U) typedef enum { diff --git a/applications/main/bad_usb/bad_usb_app.c b/applications/main/bad_usb/bad_usb_app.c index 0cf7f19248..0f10d60d8f 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 cb54d94e92..a4dd57d8b9 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 EXT_PATH("badusb") +#define BAD_USB_APP_BASE_FOLDER EXT_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 289e3ae8c1..5d7076314a 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 e1bd44169e..f098d9da31 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; } @@ -309,7 +310,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; } } @@ -348,7 +349,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 7f9a48fb20..79dcdd531d 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 bbafdccb6a..464c8a72bf 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/clock_app/clock_app.h b/applications/main/clock_app/clock_app.h index 74648ba330..8118e6982b 100644 --- a/applications/main/clock_app/clock_app.h +++ b/applications/main/clock_app/clock_app.h @@ -7,14 +7,14 @@ #define CLOCK_ISO_DATE_FORMAT "%.4d-%.2d-%.2d" #define CLOCK_RFC_DATE_FORMAT "%.2d-%.2d-%.4d" -#define CLOCK_TIME_FORMAT "%.2d:%.2d:%.2d" +#define CLOCK_TIME_FORMAT "%.2d:%.2d:%.2d" -#define MERIDIAN_FORMAT "%s" +#define MERIDIAN_FORMAT "%s" #define MERIDIAN_STRING_AM "AM" #define MERIDIAN_STRING_PM "PM" -#define TIME_LEN 12 -#define DATE_LEN 14 +#define TIME_LEN 12 +#define DATE_LEN 14 #define MERIDIAN_LEN 3 typedef enum { diff --git a/applications/main/gpio/usb_uart_bridge.c b/applications/main/gpio/usb_uart_bridge.c index 8dff09cb80..f6e68b1096 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_i.h b/applications/main/ibutton/ibutton_i.h index c6a35f888b..d355a4ea5f 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 71b852115e..9815e52814 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 f48ae60d39..cf621d62aa 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 1547a647bf..668b79ae3c 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 346e5e640a..d860aa3b23 100644 --- a/applications/main/infrared/infrared_app.c +++ b/applications/main/infrared/infrared_app.c @@ -10,7 +10,7 @@ #define TAG "InfraredApp" #define INFRARED_TX_MIN_INTERVAL_MS (50U) -#define INFRARED_TASK_STACK_SIZE (2048UL) +#define INFRARED_TASK_STACK_SIZE (2048UL) static const NotificationSequence* infrared_notification_sequences[InfraredNotificationMessageCount] = { diff --git a/applications/main/infrared/infrared_app.h b/applications/main/infrared/infrared_app.h index 6b7b8821a9..545fada9f0 100644 --- a/applications/main/infrared/infrared_app.h +++ b/applications/main/infrared/infrared_app.h @@ -17,9 +17,9 @@ typedef struct InfraredApp InfraredApp; #include #include -#define INFRARED_SETTINGS_PATH EXT_PATH("infrared/.infrared.settings") +#define INFRARED_SETTINGS_PATH EXT_PATH("infrared/.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 1635fa0dc4..d353b2503b 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 b09c7f0b17..2763d2345d 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 c574d75c76..11bbf197bc 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 c27afb0271..dd40754d7f 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/views/infrared_move_view.c b/applications/main/infrared/views/infrared_move_view.c index 5635d8a74d..f3fc6dde12 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.c b/applications/main/lfrfid/lfrfid.c index 7fc6cf6b0d..a405c0f853 100644 --- a/applications/main/lfrfid/lfrfid.c +++ b/applications/main/lfrfid/lfrfid.c @@ -3,22 +3,22 @@ //TODO: use .txt file in resources for passwords. const uint32_t default_passwords[] = { - 0x51243648, 0x000D8787, 0x19920427, 0x50524F58, 0xF9DCEBA0, 0x65857569, 0x05D73B9F, 0x89A69E60, - 0x314159E0, 0xAA55BBBB, 0xA5B4C3D2, 0x1C0B5848, 0x00434343, 0x444E4752, 0x4E457854, 0x44B44CAE, - 0x88661858, 0xE9920427, 0x575F4F4B, 0x50520901, 0x20206666, 0x65857569, 0x5469616E, 0x7686962A, - 0xC0F5009A, 0x07CEE75D, 0xfeedbeef, 0xdeadc0de, 0x00000000, 0x11111111, 0x22222222, 0x33333333, - 0x44444444, 0x55555555, 0x66666666, 0x77777777, 0x88888888, 0x99999999, 0xAAAAAAAA, 0xBBBBBBBB, - 0xCCCCCCCC, 0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF, 0xa0a1a2a3, 0xb0b1b2b3, 0x50415353, 0x00000001, - 0x00000002, 0x0000000a, 0x0000000b, 0x01020304, 0x02030405, 0x03040506, 0x04050607, 0x05060708, - 0x06070809, 0x0708090A, 0x08090A0B, 0x090A0B0C, 0x0A0B0C0D, 0x0B0C0D0E, 0x0C0D0E0F, 0x01234567, - 0x12345678, 0x10000000, 0x20000000, 0x30000000, 0x40000000, 0x50000000, 0x60000000, 0x70000000, - 0x80000000, 0x90000000, 0xA0000000, 0xB0000000, 0xC0000000, 0xD0000000, 0xE0000000, 0xF0000000, - 0x10101010, 0x01010101, 0x11223344, 0x22334455, 0x33445566, 0x44556677, 0x55667788, 0x66778899, - 0x778899AA, 0x8899AABB, 0x99AABBCC, 0xAABBCCDD, 0xBBCCDDEE, 0xCCDDEEFF, 0x0CB7E7FC, 0xFABADA11, - 0x87654321, 0x12341234, 0x69696969, 0x12121212, 0x12344321, 0x1234ABCD, 0x11112222, 0x13131313, - 0x10041004, 0x31415926, 0xabcd1234, 0x20002000, 0x19721972, 0xaa55aa55, 0x55aa55aa, 0x4f271149, - 0x07d7bb0b, 0x9636ef8f, 0xb5f44686, 0x9E3779B9, 0xC6EF3720, 0x7854794A, 0xF1EA5EED, 0x69314718, - 0x57721566, 0x93C467E3, 0x27182818, 0x50415353}; + 0x00000000, 0x00000001, 0x00000002, 0x0000000A, 0x0000000B, 0x00012323, 0x000D8787, 0x00434343, + 0x01010101, 0x01020304, 0x01234567, 0x02030405, 0x03040506, 0x04050607, 0x05060708, 0x05D73B9F, + 0x06070809, 0x0708090A, 0x07CEE75D, 0x07D7BB0B, 0x08090A0B, 0x090A0B0C, 0x0A0B0C0D, 0x0B0C0D0E, + 0x0C0D0E0F, 0x0CB7E7FC, 0x10000000, 0x10041004, 0x10101010, 0x11111111, 0x11112222, 0x11223344, + 0x12121212, 0x121AD038, 0x12341234, 0x12344321, 0x12345678, 0x1234ABCD, 0x126C248A, 0x13131313, + 0x19721972, 0x19920427, 0x1C0B5848, 0x20000000, 0x20002000, 0x20206666, 0x22222222, 0x22334455, + 0x27182818, 0x30000000, 0x31415926, 0x314159E0, 0x33333333, 0x33445566, 0x40000000, 0x44444444, + 0x444E4752, 0x44556677, 0x44B44CAE, 0x4E457854, 0x4F271149, 0x50000000, 0x50415353, 0x50520901, + 0x50524F58, 0x51243648, 0x5469616E, 0x55555555, 0x55667788, 0x55AA55AA, 0x575F4F4B, 0x57721566, + 0x60000000, 0x65857569, 0x66666666, 0x66778899, 0x69314718, 0x69696969, 0x70000000, 0x7686962A, + 0x77777777, 0x778899AA, 0x7854794A, 0x80000000, 0x87654321, 0x88661858, 0x88888888, 0x8899AABB, + 0x89A69E60, 0x90000000, 0x932D9963, 0x93C467E3, 0x9636EF8F, 0x99999999, 0x99AABBCC, 0x9E3779B9, + 0xA0000000, 0xA0A1A2A3, 0xA5B4C3D2, 0xAA55AA55, 0xAA55BBBB, 0xAAAAAAAA, 0xAABBCCDD, 0xABCD1234, + 0xB0000000, 0xB0B1B2B3, 0xB5F44686, 0xBBBBBBBB, 0xBBCCDDEE, 0xC0000000, 0xC0F5009A, 0xC6EF3720, + 0xCCCCCCCC, 0xCCDDEEFF, 0xD0000000, 0xDDDDDDDD, 0xDEADC0DE, 0xE0000000, 0xE4204998, 0xE9920427, + 0xEEEEEEEE, 0xF0000000, 0xF1EA5EED, 0xF9DCEBA0, 0xFABADA11, 0xFEEDBEEF, 0xFFFFFFFF}; const uint32_t* lfrfid_get_t5577_default_passwords(uint8_t* len) { *len = sizeof(default_passwords) / sizeof(uint32_t); diff --git a/applications/main/lfrfid/lfrfid_cli.c b/applications/main/lfrfid/lfrfid_cli.c index de8609aeda..eaafcda922 100644 --- a/applications/main/lfrfid/lfrfid_cli.c +++ b/applications/main/lfrfid/lfrfid_cli.c @@ -23,7 +23,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 7a05e9e918..f949e73e66 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" @@ -155,4 +155,4 @@ void lfrfid_widget_callback(GuiButtonType result, InputType type, void* context) void lfrfid_text_input_callback(void* context); -const uint32_t* lfrfid_get_t5577_default_passwords(uint8_t* len); \ No newline at end of file +const uint32_t* lfrfid_get_t5577_default_passwords(uint8_t* len); diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c b/applications/main/lfrfid/scenes/lfrfid_scene_save_data.c index 11a687bdd4..20c8a10df7 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 6e3ab4c533..06c835bfbf 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_saved_key_menu.c @@ -6,6 +6,7 @@ typedef enum { SubmenuIndexWrite, SubmenuIndexWriteAndSetPass, SubmenuIndexEdit, + SubmenuIndexRename, SubmenuIndexDelete, SubmenuIndexInfo, } SubmenuIndex; @@ -32,6 +33,8 @@ void lfrfid_scene_saved_key_menu_on_enter(void* context) { 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( @@ -63,6 +66,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 caa3650e74..8217d0383a 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 79e0983894..eeff5ae086 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 e5da8ddeb4..2dc469c45c 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 a8cd0929ba..6e2cf786a3 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 2c1141e9c6..1b945660c0 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 d954c1f7e9..e97649cb3e 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 51267b3eab..c9e80765fb 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 9410c8537d..70b1114722 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 1e0e7ba6bf..6513eef5f6 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/emv/emv.c b/applications/main/nfc/helpers/protocol_support/emv/emv.c index 728aabefee..06e2ca624d 100644 --- a/applications/main/nfc/helpers/protocol_support/emv/emv.c +++ b/applications/main/nfc/helpers/protocol_support/emv/emv.c @@ -9,6 +9,10 @@ #include "../nfc_protocol_support_gui_common.h" #include "../iso14443_4a/iso14443_4a_i.h" +enum { + SubmenuIndexTransactions = SubmenuIndexCommonMax, +}; + static void nfc_scene_info_on_enter_emv(NfcApp* instance) { const NfcDevice* device = instance->nfc_device; const EmvData* data = nfc_device_get_data(device, NfcProtocolEmv); @@ -24,11 +28,6 @@ static void nfc_scene_info_on_enter_emv(NfcApp* instance) { furi_string_free(temp_str); } -static void nfc_scene_more_info_on_enter_emv(NfcApp* instance) { - // Jump to advanced scene right away - scene_manager_next_scene(instance->scene_manager, NfcSceneEmvMoreInfo); -} - static NfcCommand nfc_scene_read_poller_callback_emv(NfcGenericEvent event, void* context) { furi_assert(event.protocol == NfcProtocolEmv); @@ -49,6 +48,20 @@ static void nfc_scene_read_on_enter_emv(NfcApp* instance) { nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_emv, instance); } +static void nfc_scene_read_menu_on_enter_emv(NfcApp* instance) { + Submenu* submenu = instance->submenu; + const EmvData* data = nfc_device_get_data(instance->nfc_device, NfcProtocolEmv); + + if(data->emv_application.active_tr > 0) { + submenu_add_item( + submenu, + "Transactions", + SubmenuIndexTransactions, + nfc_protocol_support_common_submenu_callback, + instance); + } +} + static void nfc_scene_read_success_on_enter_emv(NfcApp* instance) { const NfcDevice* device = instance->nfc_device; const EmvData* data = nfc_device_get_data(device, NfcProtocolEmv); @@ -64,8 +77,21 @@ static void nfc_scene_read_success_on_enter_emv(NfcApp* instance) { furi_string_free(temp_str); } +static bool nfc_scene_read_menu_on_event_emv(NfcApp* instance, SceneManagerEvent event) { + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == SubmenuIndexTransactions) { + scene_manager_next_scene(instance->scene_manager, NfcSceneEmvTransactions); + consumed = true; + } + } + + return consumed; +} + const NfcProtocolSupportBase nfc_protocol_support_emv = { - .features = NfcProtocolFeatureMoreInfo, + .features = NfcProtocolFeatureNone, .scene_info = { @@ -74,7 +100,7 @@ const NfcProtocolSupportBase nfc_protocol_support_emv = { }, .scene_more_info = { - .on_enter = nfc_scene_more_info_on_enter_emv, + .on_enter = nfc_protocol_support_common_on_enter_empty, .on_event = nfc_protocol_support_common_on_event_empty, }, .scene_read = @@ -84,8 +110,8 @@ const NfcProtocolSupportBase nfc_protocol_support_emv = { }, .scene_read_menu = { - .on_enter = nfc_protocol_support_common_on_enter_empty, - .on_event = nfc_protocol_support_common_on_event_empty, + .on_enter = nfc_scene_read_menu_on_enter_emv, + .on_event = nfc_scene_read_menu_on_event_emv, }, .scene_read_success = { diff --git a/applications/main/nfc/helpers/protocol_support/emv/emv_render.c b/applications/main/nfc/helpers/protocol_support/emv/emv_render.c index ba6866a50f..9a586fe4b2 100644 --- a/applications/main/nfc/helpers/protocol_support/emv/emv_render.c +++ b/applications/main/nfc/helpers/protocol_support/emv/emv_render.c @@ -68,7 +68,8 @@ void nfc_render_emv_application(const EmvApplication* apl, FuriString* str) { const uint8_t len = apl->aid_len; furi_string_cat_printf(str, "AID: "); - for(uint8_t i = 0; i < len; i++) furi_string_cat_printf(str, "%02X", apl->aid[i]); + for(uint8_t i = 0; i < len; i++) + furi_string_cat_printf(str, "%02X", apl->aid[i]); furi_string_cat_printf(str, "\n"); } diff --git a/applications/main/nfc/helpers/protocol_support/emv/emv_render.h b/applications/main/nfc/helpers/protocol_support/emv/emv_render.h index 4f1e9bb096..de2e20ebb9 100644 --- a/applications/main/nfc/helpers/protocol_support/emv/emv_render.h +++ b/applications/main/nfc/helpers/protocol_support/emv/emv_render.h @@ -27,4 +27,4 @@ void nfc_render_emv_transactions(const EmvApplication* data, FuriString* str); void nfc_render_emv_uid(const uint8_t* uid, const uint8_t uid_len, FuriString* str); -void nfc_render_emv_header(FuriString* str); \ No newline at end of file +void nfc_render_emv_header(FuriString* str); diff --git a/applications/main/nfc/helpers/protocol_support/felica/felica.c b/applications/main/nfc/helpers/protocol_support/felica/felica.c index ceb1806536..561cd4d2e9 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 3d32e8d14e..48bea44331 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 07b96d7018..ba8f10b935 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 23a1a3b69a..783cbb871c 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 eb2299cb5c..c7b36e21ea 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 7f2e63dd1d..049e46e645 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 b55ba130e7..3adf2a1f5c 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 5b15bb5911..eddae0bcab 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 855642c621..d3efc3a41c 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 f1d504d248..8cfb26a533 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 65da332402..34f52496bd 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 4c8fba2f87..9a9c81004d 100644 --- a/applications/main/nfc/nfc_app_i.h +++ b/applications/main/nfc/nfc_app_i.h @@ -62,19 +62,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/bip.c b/applications/main/nfc/plugins/supported_cards/bip.c index 43acd09472..6bc586bc6b 100644 --- a/applications/main/nfc/plugins/supported_cards/bip.c +++ b/applications/main/nfc/plugins/supported_cards/bip.c @@ -9,11 +9,11 @@ #define TAG "Bip" -#define BIP_CARD_ID_SECTOR_NUMBER (0) -#define BIP_BALANCE_SECTOR_NUMBER (8) +#define BIP_CARD_ID_SECTOR_NUMBER (0) +#define BIP_BALANCE_SECTOR_NUMBER (8) #define BIP_TRIP_TIME_WINDOW_SECTOR_NUMBER (5) -#define BIP_LAST_TOP_UPS_SECTOR_NUMBER (10) -#define BIP_TRIPS_INFO_SECTOR_NUMBER (11) +#define BIP_LAST_TOP_UPS_SECTOR_NUMBER (10) +#define BIP_TRIPS_INFO_SECTOR_NUMBER (11) typedef struct { DateTime datetime; diff --git a/applications/main/nfc/plugins/supported_cards/charliecard.c b/applications/main/nfc/plugins/supported_cards/charliecard.c index 9880ca3ad7..da29dbfe69 100644 --- a/applications/main/nfc/plugins/supported_cards/charliecard.c +++ b/applications/main/nfc/plugins/supported_cards/charliecard.c @@ -92,10 +92,10 @@ 0, 0, 0, 1, 1, 2003, 4 \ } // timestep is one minute -#define CHARLIE_TIME_DELTA_SECS 60 -#define CHARLIE_END_VALID_DELTA_SECS 60 * 8 +#define CHARLIE_TIME_DELTA_SECS 60 +#define CHARLIE_END_VALID_DELTA_SECS 60 * 8 #define CHARLIE_N_TRANSACTION_HISTORY 10 -#define CHARLIE_N_PASSES 4 +#define CHARLIE_N_PASSES 4 typedef struct { uint64_t a; diff --git a/applications/main/nfc/plugins/supported_cards/emv.c b/applications/main/nfc/plugins/supported_cards/emv.c index c79e76a005..97b16acf80 100644 --- a/applications/main/nfc/plugins/supported_cards/emv.c +++ b/applications/main/nfc/plugins/supported_cards/emv.c @@ -201,4 +201,4 @@ static const FlipperAppPluginDescriptor emv_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* emv_plugin_ep() { return &emv_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/gallagher.c b/applications/main/nfc/plugins/supported_cards/gallagher.c index 4a634296ac..e10806ccfd 100644 --- a/applications/main/nfc/plugins/supported_cards/gallagher.c +++ b/applications/main/nfc/plugins/supported_cards/gallagher.c @@ -84,4 +84,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 da616c1e1e..1206b807e4 100644 --- a/applications/main/nfc/plugins/supported_cards/hi.c +++ b/applications/main/nfc/plugins/supported_cards/hi.c @@ -6,9 +6,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/kazan.c b/applications/main/nfc/plugins/supported_cards/kazan.c index 3c71a3c744..403685468e 100644 --- a/applications/main/nfc/plugins/supported_cards/kazan.c +++ b/applications/main/nfc/plugins/supported_cards/kazan.c @@ -411,4 +411,4 @@ static const FlipperAppPluginDescriptor kazan_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* kazan_plugin_ep() { return &kazan_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/metromoney.c b/applications/main/nfc/plugins/supported_cards/metromoney.c index 338515f901..3a3d1fe6e3 100644 --- a/applications/main/nfc/plugins/supported_cards/metromoney.c +++ b/applications/main/nfc/plugins/supported_cards/metromoney.c @@ -187,4 +187,4 @@ static const FlipperAppPluginDescriptor metromoney_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* metromoney_plugin_ep() { return &metromoney_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/microel.c b/applications/main/nfc/plugins/supported_cards/microel.c index 93f564f357..469cc847ba 100644 --- a/applications/main/nfc/plugins/supported_cards/microel.c +++ b/applications/main/nfc/plugins/supported_cards/microel.c @@ -6,6 +6,7 @@ #include #define TAG "Microel" + #define KEY_LENGTH 6 #define UID_LENGTH 4 @@ -228,4 +229,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 8b8d7ee4b5..c00fef6b58 100644 --- a/applications/main/nfc/plugins/supported_cards/mizip.c +++ b/applications/main/nfc/plugins/supported_cards/mizip.c @@ -6,9 +6,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/mykey.c b/applications/main/nfc/plugins/supported_cards/mykey.c index 40a647b320..cb7092fce5 100644 --- a/applications/main/nfc/plugins/supported_cards/mykey.c +++ b/applications/main/nfc/plugins/supported_cards/mykey.c @@ -154,4 +154,4 @@ static const FlipperAppPluginDescriptor mykey_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* mykey_plugin_ep(void) { return &mykey_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/ndef.c b/applications/main/nfc/plugins/supported_cards/ndef.c index 1ed3a6365f..d22a0e48a8 100644 --- a/applications/main/nfc/plugins/supported_cards/ndef.c +++ b/applications/main/nfc/plugins/supported_cards/ndef.c @@ -148,16 +148,16 @@ static void parse_ndef_vcard(FuriString* str, const uint8_t* payload, uint32_t p static void parse_ndef_wifi(FuriString* str, const uint8_t* payload, uint32_t payload_len) { // https://android.googlesource.com/platform/packages/apps/Nfc/+/refs/heads/main/src/com/android/nfc/NfcWifiProtectedSetup.java -#define CREDENTIAL_FIELD_ID (0x100E) -#define SSID_FIELD_ID (0x1045) -#define NETWORK_KEY_FIELD_ID (0x1027) -#define AUTH_TYPE_FIELD_ID (0x1003) -#define AUTH_TYPE_EXPECTED_SIZE (2) -#define AUTH_TYPE_OPEN (0x0001) -#define AUTH_TYPE_WPA_PSK (0x0002) -#define AUTH_TYPE_WPA_EAP (0x0008) -#define AUTH_TYPE_WPA2_EAP (0x0010) -#define AUTH_TYPE_WPA2_PSK (0x0020) +#define CREDENTIAL_FIELD_ID (0x100E) +#define SSID_FIELD_ID (0x1045) +#define NETWORK_KEY_FIELD_ID (0x1027) +#define AUTH_TYPE_FIELD_ID (0x1003) +#define AUTH_TYPE_EXPECTED_SIZE (2) +#define AUTH_TYPE_OPEN (0x0001) +#define AUTH_TYPE_WPA_PSK (0x0002) +#define AUTH_TYPE_WPA_EAP (0x0008) +#define AUTH_TYPE_WPA2_EAP (0x0010) +#define AUTH_TYPE_WPA2_PSK (0x0020) #define AUTH_TYPE_WPA_AND_WPA2_PSK (0x0022) #define MAX_NETWORK_KEY_SIZE_BYTES (64) diff --git a/applications/main/nfc/plugins/supported_cards/opal.c b/applications/main/nfc/plugins/supported_cards/opal.c index dc451e72c8..a1318eecba 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/saflok.c b/applications/main/nfc/plugins/supported_cards/saflok.c index ba2383f8ca..a9ca2bc5c1 100644 --- a/applications/main/nfc/plugins/supported_cards/saflok.c +++ b/applications/main/nfc/plugins/supported_cards/saflok.c @@ -10,10 +10,11 @@ #include #define TAG "Saflok" + #define MAGIC_TABLE_SIZE 192 -#define KEY_LENGTH 6 -#define UID_LENGTH 4 -#define CHECK_SECTOR 1 +#define KEY_LENGTH 6 +#define UID_LENGTH 4 +#define CHECK_SECTOR 1 typedef struct { uint64_t a; diff --git a/applications/main/nfc/plugins/supported_cards/social_moscow.c b/applications/main/nfc/plugins/supported_cards/social_moscow.c index 55ca6a1ec2..cce74946d9 100644 --- a/applications/main/nfc/plugins/supported_cards/social_moscow.c +++ b/applications/main/nfc/plugins/supported_cards/social_moscow.c @@ -59,7 +59,7 @@ static const MfClassicKeyPair social_moscow_4k_keys[] = { {.a = 0xa229e68ad9e5, .b = 0x49c2b5296ef4}, {.a = 0xa229e68ad9e5, .b = 0x49c2b5296ef4}, }; -#define TOPBIT(X) (1 << ((X)-1)) +#define TOPBIT(X) (1 << ((X) - 1)) void from_days_to_datetime(uint16_t days, DateTime* datetime, uint16_t start_year) { uint32_t timestamp = days * 24 * 60 * 60; diff --git a/applications/main/nfc/plugins/supported_cards/troika.c b/applications/main/nfc/plugins/supported_cards/troika.c index de9a47facb..0c93fa59ae 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 a6dc5450c5..927263615f 100644 --- a/applications/main/nfc/plugins/supported_cards/umarsh.c +++ b/applications/main/nfc/plugins/supported_cards/umarsh.c @@ -38,7 +38,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 fe7abd32df..22f207a1e5 100644 --- a/applications/main/nfc/plugins/supported_cards/washcity.c +++ b/applications/main/nfc/plugins/supported_cards/washcity.c @@ -192,4 +192,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/plugins/supported_cards/zolotaya_korona.c b/applications/main/nfc/plugins/supported_cards/zolotaya_korona.c index 3a07b95db8..cb0254b146 100644 --- a/applications/main/nfc/plugins/supported_cards/zolotaya_korona.c +++ b/applications/main/nfc/plugins/supported_cards/zolotaya_korona.c @@ -29,9 +29,9 @@ #define TAG "Zolotaya Korona" -#define TRIP_SECTOR_NUM (4) +#define TRIP_SECTOR_NUM (4) #define PURSE_SECTOR_NUM (6) -#define INFO_SECTOR_NUM (15) +#define INFO_SECTOR_NUM (15) // Sector 15 data. Byte [11] contains the mistake. If byte [11] was 0xEF, bytes [1-18] means "ЗАО Золотая Корона" static const uint8_t info_sector_signature[] = {0xE2, 0x87, 0x80, 0x8E, 0x20, 0x87, 0xAE, @@ -211,4 +211,4 @@ static const FlipperAppPluginDescriptor zolotaya_korona_plugin_descriptor = { /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* zolotaya_korona_plugin_ep() { return &zolotaya_korona_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/plugins/supported_cards/zolotaya_korona_online.c b/applications/main/nfc/plugins/supported_cards/zolotaya_korona_online.c index 1c43f57766..f2eccd7c0b 100644 --- a/applications/main/nfc/plugins/supported_cards/zolotaya_korona_online.c +++ b/applications/main/nfc/plugins/supported_cards/zolotaya_korona_online.c @@ -141,4 +141,4 @@ static const FlipperAppPluginDescriptor zolotaya_korona_online_plugin_descriptor /* Plugin entry point - must return a pointer to const descriptor */ const FlipperAppPluginDescriptor* zolotaya_korona_online_plugin_ep() { return &zolotaya_korona_online_plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc b/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc index 609b48c093..120c1a49d4 100644 --- a/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc +++ b/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc @@ -1,7 +1,7 @@ ########################### # Do not edit, this file will be overwritten after firmware update # Use the user_dict file for user keys -# Last updated 17 December 2023 +# Last updated 11 July 2024 ########################### # +-----------------------------------------------------------------------------------------------------+ # | https://github.com/RfidResearchGroup/proxmark3/blob/master/client/dictionaries/mfc_default_keys.dic | @@ -244,15 +244,15 @@ E3429281EFC1 # 3dprinter # EPI Envisionte AAFB06045877 -# gym +# Gyms / Fitness Clubs / Health Clubs / Wellness Centres # Fysiken A 3E65E4FB65B3 # Fysiken B 25094DF6F148 # https://mattionline.de/fitnessstudio-armband-reverse-engineering/ # https://mattionline.de/milazycracker/ -# gym wistband A, same as Fysiken A -# gym wistband B +# Gym Wristband A - Same as Fysiken A +# Gym Wristband B 81CC25EBBB6A 195DC63DB3A3 # CleverFit @@ -260,9 +260,12 @@ A05DBD98E0FC # GoFit AA4DDA458EBB EAB8066C7479 -# Nordic Wellness A, same as Fysiken A +# Nordic Wellness A - Same as Fysiken A # Nordic Wellness B E5519E1CC92B +# Jett's 24 Hour Fitness S0 KA/B +# 049979614077 +# 829338771705 # Hotel KeyCard D3B595E9DD63 AFBECD121004 @@ -290,6 +293,8 @@ F101622750B7 B39AE17435DC # key A 454841585443 +# Lift system +190819842023 # Data from http://pastebin.com/gQ6nk38G D39BB83F5297 85675B200017 @@ -958,6 +963,14 @@ EA0FD73CB149 FC0001877BF7 FD8705E721B0 00ADA2CD516D +518108E061E2 +558AAD64EB5B +001122334455 +6CA761AB6CA7 +B1C4A8F7F6E3 +FF75AFDA5A3C +FCDDF7767C10 +A6B3F6C8F1D4 237A4D0D9119 0ED7846C2BC9 FFFFD06F83E3 @@ -1935,6 +1948,13 @@ E69DD9015A43 C8382A233993 7B304F2A12A6 FC9418BF788B +# Guest Cashless Prepaid Arcade Payment Cards +168168168168 +198407157610 +4E4F584D2101 +4E4F584D2105 +686B35333376 +861861861861 # Data from "the more the marriott" mifare project (colonelborkmundus) # aka The Horde # These keys seem to be from Vingcard / Saflok system which means they are diversified @@ -2111,6 +2131,122 @@ B12000000000 B13000000000 B14000000000 B15000000000 +# Pittsburgh, PA, USA - Pittsburgh Regional Transit ConnectCard +A7AE4A5A33DC +6B857B568C10 +E2CE9A674CBE +A4896B2EBA4E +0724DF9AEDE8 +0E368FB140C1 +874EB25C8721 +5C313F4539CD +C5498606E0A8 +79C69F7EC7C0 +DA7DD0044DA2 +1B8189BD966B +765584147990 +4B7C7C315E6E +46CAAD12C524 +53BD03DEA5C9 +D2D72CB60F59 +14D258786538 +E2E89A375B36 +B3FA87DB0C45 +44D3B1561B34 +2817C6E02F97 +A513FF1232E9 +BD454BD52792 +391771654DC8 +5162797F8E1C +F700BD8E042D +3973ABFD8B66 +CE8BFF3728EE +09938D05DA78 +EACDA4DBE420 +EC2B9FD483CA +# Hotel Intelier Orange - Benicasim, Spain +# block 1 - key A +04256CFE0425 +# InsideWash Membership Card - Portugal +C18063858BB9 +# An apartment building in Sydney Olympic Park +13254608D0AB +24A2971BC0B2 +14264709D1AC +25A3981CC1B3 +1527480AD2AD +26A4991DC2B4 +1628490BD3AE +27A59A1EC3B5 +17294A0CD4AF +28A69B1FC4B6 +182A4B0DD5B0 +29A79C20C5B7 +192B4C0ED6B1 +2AA89D21C6B8 +1A2C4D0FD7B2 +2BA99E22C7B9 +1B2D4E10D8B3 +2CAA9F23C8BA +1C2E4F11D9B4 +2DABA024C9BB +1D2F5012DAB5 +2EACA125CABC +1E305113DBB6 +2FADA226CBBD +1F315214DCB7 +30AEA327CCBE +20325315DDB8 +31AFA428CDBF +21335416DEB9 +32B0A529CEC0 +22345517DFBA +33B1A62ACFC1 +# Universidade de Sao Paulo (USP) student card +17B50E38F1B0 +24E311F594CE +3794FBFB1A54 +43B229069F6A +4531952F765F +4943F2F35E0A +4985E681EF88 +4F56C88E0337 +710070E92C79 +8A036C5C35D4 +A027BD830A06 +D33673C19243 +D89A506542F2 +E5813CD228F1 +FAB943906E9C +# R.A.T.T transport card key A/B +AA034F342A55 +456776908C48 +# BusFacil - Brazilian public transport card for some cities +FAE9B14365A9 +C567DD4A6004 +C567DD4A6005 +C567DD4A6006 +C567DD4A6007 +C567DD4A6008 +C567DD4A6009 +C567DD4A600A +C567DD4A600D +C567DD4A600E +C567DD4A600F +5EF014EC5D7F +5086052022AC +BD6AF9754C18 +5D67D4732A7D +17FE45604A04 +17FE45604A05 +17FE45604A06 +17FE45604A07 +17FE45604A08 +17FE45604A09 +17FE45604A0A +17FE45604A0D +17FE45604A0E +17FE45604A0F # +--------------------------------------------------------------------------------------------------------+ # | https://github.com/RfidResearchGroup/proxmark3/blob/master/client/dictionaries/mfc_keys_bmp_sorted.dic | # +--------------------------------------------------------------------------------------------------------+ @@ -4120,17 +4256,7 @@ EED69A391464 # +-----------------------------------------------------------------------------------------------------------------------------------+ # | https://github.com/ikarus23/MifareClassicTool/blob/master/Mifare%20Classic%20Tool/app/src/main/assets/key-files/extended-std.keys | # +-----------------------------------------------------------------------------------------------------------------------------------+ -# Wojo coworking space, Fance -FF75AFDA5A3C -558AAD64EB5B -518108E061E2 -FCDDF7767C10 -A6B3F6C8F1D4 -B1C4A8F7F6E3 -# Key from some random card -001122334455 -# Key from hotel in Spain -6CA761AB6CA7 +# Nothing currently, all included in blocks above # +----------------------------------------------------------------------------------------------+ # | https://github.com/UberGuidoZ/Flipper/blob/main/NFC/mf_classic_dict/mf_classic_dict_user.nfc | # +----------------------------------------------------------------------------------------------+ @@ -4147,7 +4273,6 @@ A2CA48CA4C05 193DFE0FA18E 3D6F823FFFFF 48C8852D15F9 -4E4F584D2105 7213B13D02E0 7ADD3D735725 7F796F60FFFF @@ -4158,6 +4283,32 @@ AEF617B3D040 C1F6C7B55F5E # Metro card Sec 001 Blk 007 key B EDA4BF3E7B04 +# Lime Fitness +113355779933 +# Some employee badges and other interesting things +4D4946415245 +2B29232D3624 +2D2F182C4024 +BE3C1BF60B37 +D156F66D38EC +4A1094F378D8 +CB5ED0E57B08 +AE381EA0811B +40454EE64229 +66A4932816D3 +B54D99618ADC +08D6A7765640 +3E0557273982 +68C867397AD5 +4427385D72AB +9B2C3E00B561 +120A7837BB5D +B19A0664ECA6 +B456E1951216 +E87E3554727E +8D96A0BA7234 +124F004321D3 +D881B675D881 # +--------------------------------------------------------------------------------------------------------------------------------+ # | https://github.com/flipperdevices/flipperzero-firmware/blob/dev/applications/main/nfc/resources/nfc/assets/mf_classic_dict.nfc | # +--------------------------------------------------------------------------------------------------------------------------------+ @@ -4338,9 +4489,3 @@ EA19E58DD046 3F41891454EE 7EDAE7923287 11DDA4862A1C -############################################## -# Bubbleland Play Card - keys from Bubble Land Arcade -# Found with FlipperNestedRecovery by CaitSith2 -168168168168 -861861861861 -686B35333376 diff --git a/applications/main/nfc/scenes/nfc_scene_config.h b/applications/main/nfc/scenes/nfc_scene_config.h index 2457fb1561..55f8aa3be2 100644 --- a/applications/main/nfc/scenes/nfc_scene_config.h +++ b/applications/main/nfc/scenes/nfc_scene_config.h @@ -33,13 +33,13 @@ 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) -ADD_SCENE(nfc, emv_more_info, EmvMoreInfo) +ADD_SCENE(nfc, emv_transactions, EmvTransactions) ADD_SCENE(nfc, mf_classic_dict_attack, MfClassicDictAttack) ADD_SCENE(nfc, mf_classic_detect_reader, MfClassicDetectReader) 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 b04f12dae8..f3a6ecb328 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 15b61dfa51..80c735c9ca 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_emv_more_info.c b/applications/main/nfc/scenes/nfc_scene_emv_more_info.c deleted file mode 100644 index 08f373496b..0000000000 --- a/applications/main/nfc/scenes/nfc_scene_emv_more_info.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "../nfc_app_i.h" - -#include "../helpers/protocol_support/nfc_protocol_support_gui_common.h" -#include "../helpers/protocol_support/emv/emv_render.h" - -enum { - EmvMoreInfoStateMenu, - EmvMoreInfoStateItem, // MUST be last, states >= this correspond with submenu index -}; - -enum SubmenuIndex { - SubmenuIndexTransactions, - SubmenuIndexDynamic, // dynamic indices start here -}; - -void nfc_scene_emv_more_info_on_enter(void* context) { - NfcApp* nfc = context; - Submenu* submenu = nfc->submenu; - - text_box_set_font(nfc->text_box, TextBoxFontHex); - - submenu_add_item( - submenu, - "Transactions", - SubmenuIndexTransactions, - nfc_protocol_support_common_submenu_callback, - nfc); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); -} - -bool nfc_scene_emv_more_info_on_event(void* context, SceneManagerEvent event) { - NfcApp* nfc = context; - bool consumed = false; - - const uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneEmvMoreInfo); - const EmvData* data = nfc_device_get_data(nfc->nfc_device, NfcProtocolEmv); - - if(event.type == SceneManagerEventTypeCustom) { - widget_reset(nfc->widget); - - if(event.event == SubmenuIndexTransactions) { - FuriString* temp_str = furi_string_alloc(); - nfc_render_emv_transactions(&data->emv_application, temp_str); - widget_add_text_scroll_element( - nfc->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str)); - furi_string_free(temp_str); - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); - scene_manager_set_scene_state( - nfc->scene_manager, - NfcSceneEmvMoreInfo, - EmvMoreInfoStateItem + SubmenuIndexTransactions); - consumed = true; - } - } else if(event.type == SceneManagerEventTypeBack) { - if(state >= EmvMoreInfoStateItem) { - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); - scene_manager_set_scene_state( - nfc->scene_manager, NfcSceneEmvMoreInfo, EmvMoreInfoStateMenu); - } else { - // Return directly to the Info scene - scene_manager_search_and_switch_to_previous_scene(nfc->scene_manager, NfcSceneInfo); - } - consumed = true; - } - - return consumed; -} - -void nfc_scene_emv_more_info_on_exit(void* context) { - NfcApp* nfc = context; - - // Clear views - widget_reset(nfc->widget); - submenu_reset(nfc->submenu); -} diff --git a/applications/main/nfc/scenes/nfc_scene_emv_transactions.c b/applications/main/nfc/scenes/nfc_scene_emv_transactions.c new file mode 100644 index 0000000000..e044348318 --- /dev/null +++ b/applications/main/nfc/scenes/nfc_scene_emv_transactions.c @@ -0,0 +1,31 @@ +#include "../nfc_app_i.h" + +#include "../helpers/protocol_support/nfc_protocol_support_gui_common.h" +#include "../helpers/protocol_support/emv/emv_render.h" + +void nfc_scene_emv_transactions_on_enter(void* context) { + NfcApp* nfc = context; + Widget* widget = nfc->widget; + const EmvData* data = nfc_device_get_data(nfc->nfc_device, NfcProtocolEmv); + + FuriString* temp_str = furi_string_alloc(); + nfc_render_emv_transactions(&data->emv_application, temp_str); + + widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str)); + + furi_string_free(temp_str); + + view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); +} + +bool nfc_scene_emv_transactions_on_event(void* context, SceneManagerEvent event) { + UNUSED(context); + UNUSED(event); + return false; +} + +void nfc_scene_emv_transactions_on_exit(void* context) { + NfcApp* nfc = context; + + widget_reset(nfc->widget); +} 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 e2d3e6d72f..176b014e90 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 d5033789a1..660674ceb0 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 c2c36c74fa..f3aefb7815 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 3f92ebfd3b..3d49b3cac6 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 0ca765db78..bc34a45b4a 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/subghz/helpers/subghz_chat.c b/applications/main/subghz/helpers/subghz_chat.c index 6e2ac73888..b8124026f2 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_custom_event.h b/applications/main/subghz/helpers/subghz_custom_event.h index 2bf308e28d..c84bed3fc3 100644 --- a/applications/main/subghz/helpers/subghz_custom_event.h +++ b/applications/main/subghz/helpers/subghz_custom_event.h @@ -83,6 +83,8 @@ typedef enum { SetTypeCenturion433, SetTypeSommer_FM_434, SetTypeSommer_FM_868, + SetTypeSommer_FM238_434, + SetTypeSommer_FM238_868, SetTypeStilmatic, SetTypeIronLogic, SetTypeDeaMio433, @@ -93,6 +95,8 @@ typedef enum { SetTypeElmesElectronic, SetTypeNormstahl_433_92, SetTypeJCM_433_92, + SetTypeNovoferm_433_92, + SetTypeHormannEcoStar_433_92, SetTypeFAACRCXT_433_92, SetTypeFAACRCXT_868, SetTypeGeniusBravo433, diff --git a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.h b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.h index eeb1804d9d..1b21c39e9b 100644 --- a/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.h +++ b/applications/main/subghz/helpers/subghz_frequency_analyzer_worker.h @@ -77,4 +77,4 @@ void subghz_frequency_analyzer_worker_set_trigger_level( * @param instance SubGhzFrequencyAnalyzerWorker instance * @return RSSI trigger level */ -float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance); \ No newline at end of file +float subghz_frequency_analyzer_worker_get_trigger_level(SubGhzFrequencyAnalyzerWorker* instance); diff --git a/applications/main/subghz/helpers/subghz_threshold_rssi.c b/applications/main/subghz/helpers/subghz_threshold_rssi.c index 07d7bccf93..f413babae8 100644 --- a/applications/main/subghz/helpers/subghz_threshold_rssi.c +++ b/applications/main/subghz/helpers/subghz_threshold_rssi.c @@ -3,6 +3,7 @@ #include "../subghz_i.h" #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 e273d0670b..8e00bd6af3 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -363,7 +363,7 @@ void subghz_txrx_stop(SubGhzTxRx* instance) { } } -void subghz_txrx_hopper_update(SubGhzTxRx* instance) { +void subghz_txrx_hopper_update(SubGhzTxRx* instance, float stay_threshold) { furi_assert(instance); switch(instance->hopper_state) { @@ -386,7 +386,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance) { float rssi = subghz_devices_get_rssi(instance->radio_device); // Stay if RSSI is high enough - if(rssi > -90.0f) { + if(rssi > stay_threshold) { instance->hopper_timeout = 10; instance->hopper_state = SubGhzHopperStateRSSITimeOut; return; @@ -528,22 +528,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) { diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index a380e48756..0f3b643043 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -121,8 +121,9 @@ void subghz_txrx_sleep(SubGhzTxRx* instance); * Update frequency CC1101 in automatic mode (hopper) * * @param instance Pointer to a SubGhzTxRx + * @param stay_threshold RSSI theshold over which to stay before hopping */ -void subghz_txrx_hopper_update(SubGhzTxRx* instance); +void subghz_txrx_hopper_update(SubGhzTxRx* instance, float stay_threshold); /** * Get state hopper diff --git a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c index 5148ca20d1..a294849027 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c @@ -381,4 +381,4 @@ bool subghz_txrx_gen_secplus_v1_protocol( ret = true; } return ret; -} \ No newline at end of file +} 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 e0ebec685d..0b9cfefab9 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.h @@ -145,4 +145,4 @@ bool subghz_txrx_gen_secplus_v2_protocol( bool 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/helpers/subghz_types.h b/applications/main/subghz/helpers/subghz_types.h index 48bfc2cbe0..6fbdc9e336 100644 --- a/applications/main/subghz/helpers/subghz_types.h +++ b/applications/main/subghz/helpers/subghz_types.h @@ -102,4 +102,4 @@ typedef enum { SubGhzDecodeRawStateStart, SubGhzDecodeRawStateLoading, SubGhzDecodeRawStateLoaded, -} SubGhzDecodeRawState; \ No newline at end of file +} SubGhzDecodeRawState; diff --git a/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes b/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes index 27ab5aaafd..0db72444e1 100644 --- a/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes +++ b/applications/main/subghz/resources/subghz/assets/keeloq_mfcodes @@ -1,59 +1,60 @@ Filetype: Flipper SubGhz Keystore File Version: 0 Encryption: 1 -IV: AD 0B A4 A1 51 C0 C0 41 36 78 26 82 17 24 9D 62 -0D18FF475E57A67CC5C0B430664E8EF6E07CB6AF72454995F17DE84E2E876D87 -C9BC55E1E3A9B312E341D7E2663C66C2479D5C51AE2EB83BAE47D8C6C79DB8A0 -776E01A7B4FCB929FA59CFE1F16D2D600F6FD9FD8BE1E9E41667144E61E023E4 -C354F854F14AAC08C6A51606582CD73EECEED54779927DC1E04A0D72C4E6A58E -09BA4DC551CDB0141F4A053133DBF9B7B99CBAA402C7B6B2AC8ADB516CA2FCB29FF9744DD95FB009BED6A09AE3303317 -675777F65042358100A9A2BE142C42E10CC5CF98CA6BFF82284FFD9BF7E7FB11 -4739972DCC08EFF0E8547694A67E116F3EC8638F286E333E7D89F2D61218F65D -FE8D5A0A9ED36545004CEE70D3C1FE477F34212364CF7C9EBA0FDD4F6B8F1D3E -453D5C6FE0EA7FD779B54696E66DE6BD6AEF3B1EE347142A3DB7505609077219 -A52339EE40D046E7DF6C130CEC7F9F686753A73A5F72EF344E01B00C3A3CF5F2 -94029CE386CC0403984F7C9D80B40FF12BE6E50412891FD45B347742340D1E6E679102DEC6F7D36C36863701A2BBDA7B -793633A3D97D704779E2E841A5F616ED0BB0BD50740C0B196D72C6C6453124183CA93ADCAC1A5042EBD579AC238B9DBC -B1C6EBB7320CAE97E28A244228B288BEEA44C9FD262E2C448219DAC6E194CB14 -A6C374B3FB7E8BB6F3052ED9DB67E5BCFA6CCC42F5A0D7F20BEDB7C0B58592A5 -DF4FCBDCA3414B7551797A856048625186B2EC7B836EB35B4B080CEE4A72C39F -4127F58BDEB18D79EA8317B1858F7575CF4B648E3C53338975B4A093FA9730C0 -294659EBD39D7CC01DC4E0E3B0B90A3555704E736D3BE4485BAAACBC58A84652CF3A7DA3C271E3198C72561332F2A141 -9E2CC77756BE7AB3D500C0B4A91271C0A4DED5BCB78484217EA922B7878AA8F5 -BF13D9949C783CF6B2F0E489A6912E56DDD9183D651D7F36FD0342981596A85C -8441C62006E1334FC31F53DAFF5281260C463AF3E92B1E797CB67882C49566846825606804C14C49FFD440F4E05CE692 -BE7E62E9CFA1C703CCB971F2B0C6C0F339C78A951CA8DB287B40C3BA76EA7179E8B62C29EAC8293FD218CF981BB84BEF -DA53C52101FAC8FD8F9545768CF1DB59F3B31C9249A2FC64B66DB259C721ABE1 -C9842AD0A8A8E94FCE94F46BDE89DAA8D11C41F9C83A7F6394D595028829AB92 -904A94542BCD85F72D470640A220FD28EBC337C0673C189C96BFB8CE373B4F84 -EEEE187B03FE77B955F22214707017DB8A60B2E3979D5C2F6BED61D0623D4D50 -CEF91BE6EBD8F331E2422B6B948053E8DA143F3DD907C922E0328D49B0ADA8A6 -A6F0F8A4F03B45062CEA86B291E80EE15906C0B226ABDB77E222EB95B026952D -62280870E48A2E8B8A18AD5DFF0089E927BEACE1F81A8BB1A8A2BE8EB0E92BFD -C9A3DE8165D47D1D41715F00192313755226C1B0A3D04BCD7A121B1CB4999FBD -3CAEEB62FCF601F34D3320E3EACE9EFC5D627BF69FEE965F8B84A258A765B6FE -8D83CC36514CE5CC46B181AE28089BE5BC99CE3096C569751B4E07A7D956AFA3 -0F81DDB18F60E238C7FF751E70431AA5328EFDBBDFF03D5F360A524AA968CEE9 -1F1E498A279E9BA15CB6BB836E90FEE522F2BE16572A4D057DF9C2B104487458 -68C60FF95056BE4D814CE9B8A4175625DB3E365712C2D3E42CEEBA2E0977CDB9 -D95FB21943FCAD5A21F157E629314986D92F568FD3067B65911135E6335FB7E8 -17908EF142C4B6740CBE7DCA43DA3C23C7912739299786473A994E5752E7E9459B23653EE0D7775FCECB7B7608CB0495 -6D17B6BA17DBFFAA4E90953CE6A73AB967076B8FBC14A9361D93A01C0850CC38 -8723740BCC0A5CCEE52B6EF73DD441672FB6728965CC588044C78D495AB0675F -CA548FA44A444C8F45490A11DBC8FB24E6DB38F910EC60520A3890C8B45664FE -591356440344AAFEC21FAA0C85B6A8F354D45074932E37E0972F851E08937469 -DE3A54CAAC8014625EE502F547A93754AFAD0A7EB6028599D03CCB0473BC8D5C -B2C2F6F971034E1591AD374793D6D17A595D6544DF5A9585780C6B2E3505BCFF -54447BE6C626D1CA37FD799B76B35ED266D12757B5DA1AB9277F671BBF7F07B461D0CE26593F1372354979E836972F85 -45FBD88AA7C26B967BC3638F6083A6B83AA82D5B974B37DF1C3F52839DDA020C -33B9890FBE46FDB7AEE404B71C893DC20059F96224CF48F284A66D3A8D91918E -CCEA5BC148BC84DB4825320A2B8D39A30BAB4641FFEE33BD4B8700339F15892D -4BC4E0D1263E9B02DA401C884923778D1A6FACACFFE7F660381ECD64CCA5CCD2 -0284EA911FB1B37F623F92B1662E10D79AEBD0009C107A9C554D417F7553B28E -FE48F26C44FA4C3EB3B2F3497FE99AC30A0A7BF9FF261740E177D7A2A5BD7880 -1EA96FEBB62543A8731D19BBDD1C7FE323CADBAB7242E5A8F4B1D706964B4C32 -4AB7EEF02FD59EA5D16837A50282A6254B93A34F31FE9335DA9FABEF76EA714591029C64967506B99860358E5CBF4EDA -A0F25C5387FE9B871E246F33FE64396A5DC0A9BC9AD9DF9E219F3482ADD6497E -0130F99FA395F4364491E6718B53E9D6983B68E29A70035B158CA7629C31C33E -3CDAEDA88534C2E31D1235C99DEC466221C89F63E1F8F59C9CE224573E39E2D4 -F5ED2863D8B51DA620484CDE23D590F4A208DA6D155E645FCD6BCF5FEB39EE551EAE9C0366F7FFD4CBF1DCA063D154E1 +IV: 41 72 65 20 79 6F 75 20 61 20 46 75 72 72 79 3F +8B441920A9F30EA40001F37E0F3C0D72161467678511928D219A7DBC42F8D9B7 +1ADE5B8541491C46674EECC05A1C4297CB28259954FD7C6DA0EAADE8D57773FC +0497A50135FA4468B49694974DAADEF2A9CC2B7BAFC8465E0AA58E940C085850 +4BC77520AE09B4F6A5A5365B6B9C16CA53566E096159A98EF0AB6E7FE5C2DD1C +B674AC1674312E74471E44917F6FC049DAB48BBB65B84F14A4CD64223A49E93DC0C507B8E17BFFDCBB67B55F1B4091C6 +FBBE4E4F703A9C1F17268F73EC00A3F76517A4470783363102D2B7647F0F2E7F +21BE8A51F32CE62DA6B5E207E627D224639877860C71933C4F54AC7BD742B265 +74E3EA89CC7AA99855C1BC87734506413B882CF36D68C3329022415EB29D1360 +567937E84052F230610B3A2FC26CA1BE32B9617F7554EF5E6E7CB35A76718ADA +4C34F7FE5D6EAE40B0EB6BAB7DE4F0D059C32E4F312F9C62F2C50C54C5486276 +74C8656F8EA033C60F3183FA0923C9AF1EB6689FAACC39E6548ECE16E3312D39DCF45AC6EC70A70421FBFFA43D91E19E +275903678A81B6E62CD2BB4C50E93CB3E4B092E2894EBAA04AC4E0244E4D5BA9FCDFC6BCF845EA41DF0691BF2AEDF300 +BFE52324D666ADEB3D33D94331376B33A3D31566331DE0F372548FE7255F8085 +8E1B2E82B4C78360B3174741FB8031EE0DFEB479859BE8708F8AF40C5228BFDF +6014A4A9D9703DAC11DA6B93FB7A0E0E0856E9379148F3CC125D77BA4C3D4931 +B8C22EA72B35E60A7A3DD02956D2375EE7C07E243F17F413CA4AC3A1445AA250 +B545037B8798370A8638B7ADCBE9EEF748F73C89EB5E04B460057BAFA52B1D7DF29B009FBB3FA07CE87247D185BE4926 +09AEA3223E4FFB06333425BA977403E7C2F9B5F121FDA8313E73FE98D0041425 +E7A97F65883E4D3CDA02483738219E219EED0681C2BB140EF3E5D02230433D42 +4AE67B9EA288183047A9498F58978E7C41BB8905533F42FF5B94E41AFEFF0EB4907A8C472B9E32F6D659CFA6C391179B +1F9752FBA7A7A00D518D91BA8A8C1ADEF2EDF6282A5AFB2E4332B4351CF67F18317D2BCFF2DA6B5216EA138A4CCBDB81 +EDC508FE0D0E894B529C5E4AB82A7188072592BE9D4D9A3D2485822A9F4C5A67 +780582645A71D3A9841B0E8F5E84A2285F783872102AA1A98A956B98AEA19421 +37E2858B90868BCAA6B3198C3B205DC1413A9D378AF1671BEA3B8F47FCE1C5CE +229719C5AFE1E567B8BD5F07EFF89C30B11CB79C9C841FFE7B53404CA5422EDB +CDA16E59B8C24DBE95ABF978CAD4D04A4F124DED1965124F92AACA4C5AEB8721 +5C61D5C655DD9EB78C4F8E965101F98D7899155D2379EF6553FA9DEA0302A232 +7D3DCFDE942398244624C7ABFE08363404BA688EDA39D45A05BB6FB982BB9042 +ECCB10BCB2A8CF2093C61634E9AFEE9B69EB4A7C8B7139061730B5FA869F65BF +7AE6C19ED3C97F45D1167FC9EF52CCE321EA002D31D8AEA94106A2F711626551 +793A984F6EBD35253C319FAB671348A4C6843AEA7CCCD5A52ACA9BBE96484B5E +BB3ADBB5FD60F0FB01E5A8B1610D30A24975DC67ED1B70472E509218E213393E +BB971C6304723B9928F50FA2E5C30A48ED5527556EE1BA5A7EA75AB7A4ED4137 +489579673025F7A351072EB8D5C7FC1DBF651AA6233FB01D99DAC4BDC0A60F2F +ACA000B78B091A9B2621A9FA1A50FA6A3B63DDDF7D966224837028F93D570C08 +C1EB4EA179EC0437D5B0E72C47AAD06803F7619C53D3D2FEF38DD3C068118766B73202B75C534C6249312245218C9285 +639C6F53600C0F01410361164FEF715DB8E08C68D68B8AE76CF2D09A0C6C4CA1 +F5F2D77DD3AF60489312055EBA3B511F7D9E312F02465639FFF3E71A862BB9EB +3EC1F7B2C43646249C4D14B4B1B85B3416B8D3B0B8DA9E87BD6199DC27BD45C2 +AA24DB7345317FE980C917909F364EAA13591A664E0893271E9DBCC250782EA5 +32C18DBA479AD57BFF9FE7B7BD1022D4969D8E2EC99BC0799148809796E227D5 +494B44697DACDFDBBFEB0FDBEF6E9B5D7291B6CB43B4C93088F3ED8632AF23B5 +B79CC1A90C7AC36DA2F318BF69E6BB1FAC32C178453663069C0CF2C4AE77B211 +A059D006EF98446BDF9E1F5E09641A641CA88348E79499D79BCFDE6646C716A0BE2253421858D327E796EB5237B6E2C4 +9E90AE6138A3676E3E5058FF277331032CD6BBF114768104A33D684B0825C5A5 +7477B55332666FC6B1279F5FDF84DCA01176498984809B74E17AB726F888000F +6A0300B90BC11127A031E62537468A1CA7A0775BE85ED12069074E26181FBA50 +4DAF986F9A850EB18F0FE3B88B9796D80EEC3984C92F4F8B32D513A176CCAA9A +EB84517DCAA7D10A6E7C4D0A7995AE278AAF3FDE52DAE30C7FD3FB853C799369 +0941FB8965604ABC852B94F29396783783632E4C80AEE665E42C233B6E7AA7D0 +71FEF69734589BE3C0893A1584FC1C0A75A5D4BF88CFF323C8C68E0EEC06993C +790A26B77912EE07BABCDF478D8E492422B73465DC209E5DBC8E31F43AA2DA7448EAB6312AC1DC4FE3F20D7A2EC93968 +CE0AA966F33B7AC9E9982D2241524F2FC7613DAAC6C5C768AAAE29A630B414CE +93FA632D945E18DE6358D4F443CB6F023C640407B7FAD6E8AF6EF15139B044E3 +059ABA7A866A865159D4E0B3E30FA1900BAB2BAB82A1D1F9D74CAEC11FA95393 +9C5A4CF1D49E0F741577BAB868575739AEBBDC15D7178C87A46EA3B3E7E856EFD815AD5F998778E8FBAA2832F387B967 diff --git a/applications/main/subghz/scenes/subghz_scene_config.h b/applications/main/subghz/scenes/subghz_scene_config.h index 0915e0f127..b9480b349b 100644 --- a/applications/main/subghz/scenes/subghz_scene_config.h +++ b/applications/main/subghz/scenes/subghz_scene_config.h @@ -22,4 +22,4 @@ ADD_SCENE(subghz, more_raw, MoreRAW) ADD_SCENE(subghz, decode_raw, DecodeRAW) ADD_SCENE(subghz, delete_raw, DeleteRAW) ADD_SCENE(subghz, need_saving, NeedSaving) -ADD_SCENE(subghz, rpc, Rpc) \ No newline at end of file +ADD_SCENE(subghz, rpc, Rpc) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 331c7c7042..b6c57414fe 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -1,6 +1,7 @@ #include "../subghz_i.h" #define TAG "SubGhzDecodeRaw" + #define SAMPLES_TO_READ_PER_TICK 400 static void subghz_scene_receiver_update_statusbar(void* context) { @@ -207,8 +208,6 @@ bool subghz_scene_decode_raw_on_event(void* context, SceneManagerEvent event) { subghz_txrx_set_rx_callback(subghz->txrx, NULL, subghz); - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); - if(subghz_file_encoder_worker_is_running(subghz->decode_raw_file_worker_encoder)) { subghz_file_encoder_worker_stop(subghz->decode_raw_file_worker_encoder); } diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 4c1320f029..355c339ffa 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -5,7 +5,7 @@ #include #define RAW_FILE_NAME "RAW_" -#define TAG "SubGhzSceneReadRAW" +#define TAG "SubGhzSceneReadRAW" bool subghz_scene_read_raw_update_filename(SubGhz* subghz) { bool ret = false; diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 23ac442222..01b46d2486 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -294,7 +294,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { } } else if(event.type == SceneManagerEventTypeTick) { if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { - subghz_txrx_hopper_update(subghz->txrx); + subghz_txrx_hopper_update(subghz->txrx, subghz->last_settings->hopping_threshold); subghz_scene_receiver_update_statusbar(subghz); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index f937e80b97..f82a459761 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -49,6 +49,37 @@ const float raw_threshold_rssi_value[RAW_THRESHOLD_RSSI_COUNT] = { -40.0f, }; +#define HOPPING_MODE_COUNT 12 +const char* const hopping_mode_text[HOPPING_MODE_COUNT] = { + "OFF", + "-90dBm", + "-85dBm", + "-80dBm", + "-75dBm", + "-70dBm", + "-65dBm", + "-60dBm", + "-55dBm", + "-50dBm", + "-45dBm", + "-40dBm", + +}; +const float hopping_mode_value[HOPPING_MODE_COUNT] = { + NAN, + -90.0f, + -85.0f, + -80.0f, + -75.0f, + -70.0f, + -65.0f, + -60.0f, + -55.0f, + -50.0f, + -45.0f, + -40.0f, +}; + #define COMBO_BOX_COUNT 2 const uint32_t hopping_value[COMBO_BOX_COUNT] = { @@ -121,18 +152,19 @@ uint8_t subghz_scene_receiver_config_next_preset(const char* preset_name, void* return index; } -SubGhzHopperState subghz_scene_receiver_config_hopper_value_index(void* context) { +uint8_t subghz_scene_receiver_config_hopper_value_index(void* context) { furi_assert(context); SubGhz* subghz = context; if(subghz_txrx_hopper_get_state(subghz->txrx) == SubGhzHopperStateOFF) { - return SubGhzHopperStateOFF; + return 0; } else { variable_item_set_current_value_text( - (VariableItem*)scene_manager_get_scene_state( - subghz->scene_manager, SubGhzSceneReceiverConfig), + variable_item_list_get(subghz->variable_item_list, SubGhzSettingIndexFrequency), " -----"); - return SubGhzHopperStateRunning; + return value_index_float( + subghz->last_settings->hopping_threshold, hopping_mode_value, HOPPING_MODE_COUNT); + ; } } @@ -188,16 +220,16 @@ static void subghz_scene_receiver_config_set_preset(VariableItem* item) { subghz->last_settings->preset_index = index; } -static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { +static void subghz_scene_receiver_config_set_hopping(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); - SubGhzHopperState index = variable_item_get_current_value_index(item); + uint8_t index = variable_item_get_current_value_index(item); SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx); - VariableItem* frequency_item = (VariableItem*)scene_manager_get_scene_state( - subghz->scene_manager, SubGhzSceneReceiverConfig); + VariableItem* frequency_item = + variable_item_list_get(subghz->variable_item_list, SubGhzSettingIndexFrequency); - variable_item_set_current_value_text(item, combobox_text[(uint8_t)index]); + variable_item_set_current_value_text(item, hopping_mode_text[index]); - if(index == SubGhzHopperStateOFF) { + if(index == 0) { char text_buf[10] = {0}; uint32_t frequency = subghz_setting_get_default_frequency(setting); SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); @@ -219,13 +251,18 @@ static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) preset.data_size); variable_item_set_current_value_index( frequency_item, subghz_setting_get_frequency_default_index(setting)); + variable_item_set_item_label(item, "Hopping"); } else { variable_item_set_current_value_text(frequency_item, " -----"); variable_item_set_current_value_index( frequency_item, subghz_setting_get_frequency_default_index(setting)); + + variable_item_set_item_label(item, "Hopping RSSI"); } - subghz->last_settings->enable_hopping = index != SubGhzHopperStateOFF; - subghz_txrx_hopper_set_state(subghz->txrx, index); + subghz->last_settings->enable_hopping = index != 0; + subghz->last_settings->hopping_threshold = hopping_mode_value[index]; + subghz_txrx_hopper_set_state( + subghz->txrx, index != 0 ? SubGhzHopperStateRunning : SubGhzHopperStateOFF); } static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { @@ -380,16 +417,16 @@ void subghz_scene_receiver_config_on_enter(void* context) { if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerSet) { // Hopping + value_index = subghz_scene_receiver_config_hopper_value_index(subghz); item = variable_item_list_add( subghz->variable_item_list, - "Hopping", - COMBO_BOX_COUNT, - subghz_scene_receiver_config_set_hopping_running, + value_index ? "Hopping RSSI" : "Hopping", + HOPPING_MODE_COUNT, + subghz_scene_receiver_config_set_hopping, subghz); - value_index = subghz_scene_receiver_config_hopper_value_index(subghz); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, combobox_text[value_index]); + variable_item_set_current_value_text(item, hopping_mode_text[value_index]); } if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 0b0c5d3762..e68b0203d7 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -175,7 +175,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) } } else if(event.type == SceneManagerEventTypeTick) { if(subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF) { - subghz_txrx_hopper_update(subghz->txrx); + subghz_txrx_hopper_update(subghz->txrx, subghz->last_settings->hopping_threshold); } switch(subghz->state_notifications) { case SubGhzNotificationStateTx: diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index b94f4430b2..1b89d1d4d6 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -186,4 +186,4 @@ void subghz_scene_save_name_on_exit(void* context) { // Clear view text_input_reset(subghz->text_input); -} \ No newline at end of file +} diff --git a/applications/main/subghz/scenes/subghz_scene_save_success.c b/applications/main/subghz/scenes/subghz_scene_save_success.c index 70b6a2fc32..9a71c74a71 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_success.c +++ b/applications/main/subghz/scenes/subghz_scene_save_success.c @@ -50,6 +50,8 @@ bool subghz_scene_save_success_on_event(void* context, SceneManagerEvent event) subghz_file_encoder_worker_free(subghz->decode_raw_file_worker_encoder); subghz->state_notifications = SubGhzNotificationStateIDLE; + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); + scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet); if(!scene_manager_search_and_switch_to_previous_scene( diff --git a/applications/main/subghz/scenes/subghz_scene_set_fix.c b/applications/main/subghz/scenes/subghz_scene_set_fix.c index 7564fb24d7..93df4e54d2 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_fix.c +++ b/applications/main/subghz/scenes/subghz_scene_set_fix.c @@ -43,4 +43,4 @@ void subghz_scene_set_fix_on_exit(void* context) { // Clear view byte_input_set_result_callback(subghz->byte_input, NULL, NULL, NULL, NULL, 0); byte_input_set_header_text(subghz->byte_input, ""); -} \ No newline at end of file +} diff --git a/applications/main/subghz/scenes/subghz_scene_set_type.c b/applications/main/subghz/scenes/subghz_scene_set_type.c index b88e449b15..324cc48f06 100644 --- a/applications/main/subghz/scenes/subghz_scene_set_type.c +++ b/applications/main/subghz/scenes/subghz_scene_set_type.c @@ -30,6 +30,8 @@ static const char* submenu_names[SetTypeMAX] = { [SetTypeCenturion433] = "KL: Centurion 433MHz", [SetTypeSommer_FM_434] = "KL: Sommer 434MHz", [SetTypeSommer_FM_868] = "KL: Sommer 868MHz", + [SetTypeSommer_FM238_434] = "KL: Sommer fm2 434Mhz", + [SetTypeSommer_FM238_868] = "KL: Sommer fm2 868Mhz", [SetTypeStilmatic] = "KL: Stilmatic 433MHz", [SetTypeIronLogic] = "KL: IronLogic 433MHz", [SetTypeDeaMio433] = "KL: DEA Mio 433MHz", @@ -40,10 +42,12 @@ static const char* submenu_names[SetTypeMAX] = { [SetTypeElmesElectronic] = "KL: Elmes (PL) 433MHz", [SetTypeNormstahl_433_92] = "KL: Normstahl 433MHz", [SetTypeJCM_433_92] = "KL: JCM Tech 433MHz", + [SetTypeNovoferm_433_92] = "KL: Novoferm 433MHz", + [SetTypeHormannEcoStar_433_92] = "KL: Hor. EcoStar 433MHz", [SetTypeFAACRCXT_433_92] = "KL: FAAC RC,XT 433MHz", [SetTypeFAACRCXT_868] = "KL: FAAC RC,XT 868MHz", [SetTypeGeniusBravo433] = "KL: Genius Bravo 433MHz", - [SetTypeNiceMHouse_433_92] = "KL: Nice Mhouse 433MHz", + [SetTypeNiceMHouse_433_92] = "KL: Mhouse 433MHz", [SetTypeNiceSmilo_433_92] = "KL: Nice Smilo 433MHz", [SetTypeNiceFlorS_433_92] = "Nice FloR-S 433MHz", [SetTypeNiceOne_433_92] = "Nice One 433MHz", @@ -396,7 +400,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { .mod = "AM650", .freq = 433920000, .keeloq.serial = (key & 0x000FFFFF) | 0x00600000, - .keeloq.btn = 0x04, + .keeloq.btn = 0x08, .keeloq.cnt = 0x03, .keeloq.manuf = "Aprimatic"}; break; @@ -445,7 +449,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { .type = GenKeeloq, .mod = "FM476", .freq = 434420000, - .keeloq.serial = (key & 0x0000FFFF) | 0x07150000, + .keeloq.serial = (key & 0x0000FFFF) | 0x01700000, .keeloq.btn = 0x02, .keeloq.cnt = 0x03, .keeloq.manuf = "Sommer(fsk476)"}; @@ -455,7 +459,27 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { .type = GenKeeloq, .mod = "FM476", .freq = 868800000, - .keeloq.serial = (key & 0x0000FFFF) | 0x07150000, + .keeloq.serial = (key & 0x0000FFFF) | 0x01700000, + .keeloq.btn = 0x02, + .keeloq.cnt = 0x03, + .keeloq.manuf = "Sommer(fsk476)"}; + break; + case SetTypeSommer_FM238_434: + gen_info = (GenInfo){ + .type = GenKeeloq, + .mod = "FM238", + .freq = 434420000, + .keeloq.serial = key & 0x0000FFFF, + .keeloq.btn = 0x02, + .keeloq.cnt = 0x03, + .keeloq.manuf = "Sommer(fsk476)"}; + break; + case SetTypeSommer_FM238_868: + gen_info = (GenInfo){ + .type = GenKeeloq, + .mod = "FM238", + .freq = 868800000, + .keeloq.serial = key & 0x0000FFFF, .keeloq.btn = 0x02, .keeloq.cnt = 0x03, .keeloq.manuf = "Sommer(fsk476)"}; @@ -476,7 +500,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { .mod = "AM650", .freq = 433920000, .keeloq.serial = key & 0x00FFFFFF, - .keeloq.btn = 0x02, + .keeloq.btn = 0x04, .keeloq.cnt = 0x03, .keeloq.manuf = "Came_Space"}; break; @@ -581,7 +605,7 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { .mod = "AM650", .freq = 433920000, .keeloq.serial = key & 0x00FFFFFF, - .keeloq.btn = 0x02, + .keeloq.btn = 0x09, .keeloq.cnt = 0x03, .keeloq.manuf = "NICE_MHOUSE"}; break; @@ -615,6 +639,26 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { .keeloq.cnt = 0x03, .keeloq.manuf = "JCM_Tech"}; break; + case SetTypeNovoferm_433_92: + gen_info = (GenInfo){ + .type = GenKeeloq, + .mod = "AM650", + .freq = 433920000, + .keeloq.serial = (key & 0x0000FFFF) | 0x018F0000, + .keeloq.btn = 0x01, + .keeloq.cnt = 0x03, + .keeloq.manuf = "Novoferm"}; + break; + case SetTypeHormannEcoStar_433_92: + gen_info = (GenInfo){ + .type = GenKeeloq, + .mod = "AM650", + .freq = 433920000, + .keeloq.serial = (key & 0x000FFFFF) | 0x02200000, + .keeloq.btn = 0x04, + .keeloq.cnt = 0x03, + .keeloq.manuf = "EcoStar"}; + break; case SetTypeFAACRCXT_433_92: gen_info = (GenInfo){ .type = GenKeeloq, @@ -640,8 +684,8 @@ bool subghz_scene_set_type_on_event(void* context, SceneManagerEvent event) { .type = GenKeeloq, .mod = "AM650", .freq = 433920000, - .keeloq.serial = key & 0x00FFFFFF, - .keeloq.btn = 0x02, + .keeloq.serial = key & 0x0000FFFF, + .keeloq.btn = 0x04, .keeloq.cnt = 0x03, .keeloq.manuf = "Normstahl"}; break; diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index c4169530de..7a5fad74c9 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -68,10 +68,6 @@ static void subghz_load_custom_presets(SubGhzSetting* setting) { // Pagers {"Pagers", "02 0D 07 04 08 32 0B 06 10 64 11 93 12 0C 13 02 14 00 15 15 18 18 19 16 1B 07 1C 00 1D 91 20 FB 21 56 22 10 00 00 C0 00 00 00 00 00 00 00"}, - - // # HND - FM preset - {"HND_1", - "02 0D 0B 06 08 32 07 04 14 00 13 02 12 04 11 36 10 69 15 32 18 18 19 16 1D 91 1C 00 1B 07 20 FB 22 10 21 56 00 00 C0 00 00 00 00 00 00 00"}, }; FlipperFormat* fff_temp = flipper_format_string_alloc(); diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 0bc0d633de..3b10e90d90 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -3,9 +3,9 @@ #include -#define SUBGHZ_HISTORY_MAX 55 +#define SUBGHZ_HISTORY_MAX 55 #define SUBGHZ_HISTORY_FREE_HEAP 20480 -#define TAG "SubGhzHistory" +#define TAG "SubGhzHistory" typedef struct { FuriString* item_str; diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 84f0a43e32..1bdaf07d90 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -414,7 +414,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/subghz_i.h b/applications/main/subghz/subghz_i.h index d89dcceaea..4ad71baa2c 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -40,10 +40,10 @@ #include "helpers/subghz_txrx.h" -#define SUBGHZ_MAX_LEN_NAME 64 -#define SUBGHZ_EXT_PRESET_NAME true +#define SUBGHZ_MAX_LEN_NAME 64 +#define SUBGHZ_EXT_PRESET_NAME true #define SUBGHZ_RAW_THRESHOLD_MIN (-90.0f) -#define SUBGHZ_MEASURE_LOADING false +#define SUBGHZ_MEASURE_LOADING false typedef struct { uint8_t fix[4]; diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 09d5821a50..12e871a2f9 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -3,20 +3,21 @@ #define TAG "SubGhzLastSettings" -#define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File" +#define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File" #define SUBGHZ_LAST_SETTING_FILE_VERSION 3 -#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/last_subghz.settings") +#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/last_subghz.settings") -#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" -#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" // AKA Modulation +#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" +#define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" // AKA Modulation #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_FEEDBACK_LEVEL "FeedbackLevel" -#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" -#define SUBGHZ_LAST_SETTING_FIELD_PROTOCOL_FILE_NAMES "ProtocolNames" -#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE "Hopping" -#define SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER "IgnoreFilter" -#define SUBGHZ_LAST_SETTING_FIELD_FILTER "Filter" -#define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI" -#define SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD "DelOldSignals" +#define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" +#define SUBGHZ_LAST_SETTING_FIELD_PROTOCOL_FILE_NAMES "ProtocolNames" +#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE "Hopping" +#define SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER "IgnoreFilter" +#define SUBGHZ_LAST_SETTING_FIELD_FILTER "Filter" +#define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI" +#define SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD "DelOldSignals" +#define SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD "HoppingThreshold" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -40,6 +41,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count // See bin_raw_value in scenes/subghz_scene_receiver_config.c instance->filter = SubGhzProtocolFlag_Decodable; instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN; + instance->hopping_threshold = -90.0f; Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); @@ -114,6 +116,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count 1)) { flipper_format_rewind(fff_data_file); } + if(!flipper_format_read_float( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD, + &instance->hopping_threshold, + 1)) { + flipper_format_rewind(fff_data_file); + } } while(0); } else { @@ -203,6 +212,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_DELETE_OLD, &instance->delete_old_signals, 1)) { break; } + if(!flipper_format_write_float( + file, + SUBGHZ_LAST_SETTING_FIELD_HOPPING_THRESHOLD, + &instance->hopping_threshold, + 1)) { + break; + } saved = true; } while(0); diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 2b18861ff3..30c5884e55 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -6,11 +6,11 @@ #include #include -#define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER (-93.0f) +#define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER (-93.0f) // 1 = "AM650" // "AM270", "AM650", "FM238", "FM476", -#define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 -#define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 +#define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 +#define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 #define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL 2 typedef struct { @@ -24,6 +24,7 @@ typedef struct { uint32_t filter; float rssi; bool delete_old_signals; + float hopping_threshold; } SubGhzLastSettings; SubGhzLastSettings* subghz_last_settings_alloc(void); diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 4e5d851190..a97d442c59 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -8,9 +8,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) @@ -186,7 +186,7 @@ void subghz_view_receiver_add_item_to_menu( item_menu->time = furi_string_alloc_set(time); 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++; subghz_view_receiver_show_time_moment(subghz_receiver); diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index d2c19576ca..1bb2f044fe 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -12,11 +12,11 @@ #define TAG "frequency_analyzer" -#define RSSI_MIN -97 -#define RSSI_MAX -60 -#define RSSI_SCALE 2.3 +#define RSSI_MIN -97 +#define RSSI_MAX -60 +#define RSSI_SCALE 2.3 #define TRIGGER_STEP 1 -#define MAX_HISTORY 4 +#define MAX_HISTORY 4 static const uint32_t subghz_frequency_list[] = { 300000000, 302757000, 303875000, 303900000, 304250000, 307000000, 307500000, 307800000, @@ -402,7 +402,8 @@ uint32_t round_int(uint32_t value, uint8_t n) { value /= 10; if(i >= 5) value++; } - while(on--) value *= 10; + while(on--) + value *= 10; return value; } diff --git a/applications/main/subghz/views/subghz_read_raw.c b/applications/main/subghz/views/subghz_read_raw.c index 9c96a931f7..52b7fc28ba 100644 --- a/applications/main/subghz/views/subghz_read_raw.c +++ b/applications/main/subghz/views/subghz_read_raw.c @@ -8,7 +8,7 @@ #include #define SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE 100 -#define TAG "SubGhzReadRaw" +#define TAG "SubGhzReadRaw" struct SubGhzReadRAW { View* view; diff --git a/applications/main/subghz_remote b/applications/main/subghz_remote index 73ca3f2ac0..6ba386c09e 160000 --- a/applications/main/subghz_remote +++ b/applications/main/subghz_remote @@ -1 +1 @@ -Subproject commit 73ca3f2ac02e313004aa3a724f2f8a0e4646ad10 +Subproject commit 6ba386c09e5650f3ea814faee021829f3332ee35 diff --git a/applications/main/u2f/u2f.c b/applications/main/u2f/u2f.c index b61cfa15d3..6a37769a8b 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 c6451757b1..52c6b37d59 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 83c8a575f5..76d3d7cece 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 bdbe8bcecd..a110b3f4f7 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 abeb903099..36e7446fb7 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 cf06d663ba..6392c2d677 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 8a505f9e3f..3602cf4977 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 da43e14987..a4e76a12cc 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 a300009f5d..34a882c68e 100644 --- a/applications/services/cli/cli.c +++ b/applications/services/cli/cli.c @@ -79,7 +79,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 1e72647cff..1604f4389d 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++) { @@ -177,7 +178,7 @@ void cli_command_src(Cli* cli, FuriString* args, void* context) { printf("https://github.com/DarkFlippers/unleashed-firmware"); } -#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) { @@ -408,8 +409,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 4828bf7235..ed207b9f9a 100644 --- a/applications/services/cli/cli_i.h +++ b/applications/services/cli/cli_i.h @@ -65,10 +65,10 @@ void cli_stdout_callback(void* _cookie, const char* data, size_t size); // Wraps CLI commands to load from plugin file // Must call from CLI context, like dummy CLI command callback // You need to setup the plugin to compile correctly separately -#define CLI_PLUGIN_APP_ID "cli" +#define CLI_PLUGIN_APP_ID "cli" #define CLI_PLUGIN_API_VERSION 1 void cli_plugin_wrapper(const char* name, Cli* cli, FuriString* args, void* context); #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 1fc19e48ba..21fd2ebcf8 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-REVERSIBLE 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 44c0c228c4..8e04e7894e 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 1db61f1abf..a59907ce8e 100644 --- a/applications/services/desktop/animations/animation_storage.c +++ b/applications/services/desktop/animations/animation_storage.c @@ -11,10 +11,10 @@ #include #include -#define ANIMATION_META_FILE "meta.txt" -#define ANIMATION_DIR EXT_PATH("dolphin") +#define ANIMATION_META_FILE "meta.txt" +#define ANIMATION_DIR EXT_PATH("dolphin") #define ANIMATION_MANIFEST_FILE ANIMATION_DIR "/manifest.txt" -#define TAG "AnimationStorage" +#define TAG "AnimationStorage" static void animation_storage_free_bubbles(BubbleAnimation* animation); static void animation_storage_free_frames(BubbleAnimation* animation); diff --git a/applications/services/desktop/desktop_i.h b/applications/services/desktop/desktop_i.h index 634f0ee00d..4bcbb6585a 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 9e1db835c1..4c848117a2 100644 --- a/applications/services/desktop/desktop_settings.h +++ b/applications/services/desktop/desktop_settings.h @@ -10,9 +10,9 @@ #define DESKTOP_SETTINGS_VER (13) -#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,16 +32,16 @@ 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 -#define DISPLAY_BATTERY_BAR 0 -#define DISPLAY_BATTERY_PERCENT 1 +#define DISPLAY_BATTERY_BAR 0 +#define DISPLAY_BATTERY_PERCENT 1 #define DISPLAY_BATTERY_INVERTED_PERCENT 2 -#define DISPLAY_BATTERY_RETRO_3 3 -#define DISPLAY_BATTERY_RETRO_5 4 -#define DISPLAY_BATTERY_BAR_PERCENT 5 +#define DISPLAY_BATTERY_RETRO_3 3 +#define DISPLAY_BATTERY_RETRO_5 4 +#define DISPLAY_BATTERY_BAR_PERCENT 5 typedef enum { FavoriteAppLeftShort = 0, diff --git a/applications/services/desktop/helpers/slideshow.c b/applications/services/desktop/helpers/slideshow.c index ec02f27a1d..565449cbbd 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 34d0005433..2a536603f6 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 953f8c8360..f481733aca 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 6d432858a5..846b2b5412 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 b1c0d4c852..6f5bfe8cb3 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 53c86d8109..74b020f45f 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 c859b9b023..965b5cceb7 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 5f62f997ef..4c4d4e3767 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 4a75241e6c..95982f1af8 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 1035247e71..01da7f3f23 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 666e039423..d4add808ad 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 724060e53b..5216b961dc 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 c953e9decd..c00b8fe247 100644 --- a/applications/services/expansion/expansion_settings.c +++ b/applications/services/expansion/expansion_settings.c @@ -6,9 +6,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 4047212eb8..edc1d09cce 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 8270a93191..30d7e35ac1 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 3ca9c05c93..8bd3215f97 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 ed76bd2b3a..d9c178dd23 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 94e18e6c37..341cef5258 100644 --- a/applications/services/gui/modules/button_panel.c +++ b/applications/services/gui/modules/button_panel.c @@ -450,4 +450,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 4c3da820b4..1da36b2dcb 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 5fd42be6c6..7171f6892b 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 c4a0a1b523..a17e5d5cd4 100644 --- a/applications/services/gui/modules/file_browser.c +++ b/applications/services/gui/modules/file_browser.c @@ -14,17 +14,17 @@ #include "m-algo.h" #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, @@ -174,15 +174,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 08e1943257..7092e15da8 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; } @@ -303,7 +303,7 @@ static bool browser_folder_load_chunked( furi_record_close(RECORD_STORAGE); - return (items_cnt == count); + return items_cnt == count; } // Load all files at once, may cause memory overflow so need to limit that to about 400 files @@ -571,7 +571,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 8452951933..012fa17d6c 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 c3bff00d08..8b7056a000 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 c96510bccf..52b00c0f9b 100644 --- a/applications/services/gui/modules/text_input.c +++ b/applications/services/gui/modules/text_input.c @@ -40,7 +40,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[] = { @@ -136,7 +136,7 @@ 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) { @@ -649,6 +649,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/variable_item_list.c b/applications/services/gui/modules/variable_item_list.c index 3fe26b5693..d8fcc8652f 100644 --- a/applications/services/gui/modules/variable_item_list.c +++ b/applications/services/gui/modules/variable_item_list.c @@ -544,6 +544,12 @@ void variable_item_set_values_count(VariableItem* item, uint8_t values_count) { item->values_count = values_count; } +void variable_item_set_item_label(VariableItem* item, const char* label) { + furi_check(item); + furi_check(label); + item->label = label; +} + void variable_item_set_current_value_text(VariableItem* item, const char* current_value_text) { furi_check(item); furi_string_set(item->current_value_text, current_value_text); diff --git a/applications/services/gui/modules/variable_item_list.h b/applications/services/gui/modules/variable_item_list.h index aec2239f7e..a00b84f222 100644 --- a/applications/services/gui/modules/variable_item_list.h +++ b/applications/services/gui/modules/variable_item_list.h @@ -97,6 +97,13 @@ void variable_item_set_current_value_index(VariableItem* item, uint8_t current_v */ void variable_item_set_values_count(VariableItem* item, uint8_t values_count); +/** Set new label for item + * + * @param item VariableItem* instance + * @param label The new label text + */ +void variable_item_set_item_label(VariableItem* item, const char* label); + /** Set item current selected text * * @param item VariableItem* instance diff --git a/applications/services/gui/modules/widget_elements/widget_element.h b/applications/services/gui/modules/widget_elements/widget_element.h index 6799041738..473fabd041 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 456a831729..2bced55761 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 3cdcbf0716..35556e3229 100644 --- a/applications/services/gui/scene_manager.c +++ b/applications/services/gui/scene_manager.c @@ -2,15 +2,14 @@ #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 SceneManager array for navigation + // Initialize ScaneManager array for navigation SceneManagerIdStack_init(scene_manager->scene_id_stack); return scene_manager; @@ -21,8 +20,6 @@ void scene_manager_free(SceneManager* scene_manager) { // Clear SceneManager 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 fca798d124..85f7e7bee9 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 51d0235435..3ac85794aa 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 bf1cd2be66..b4c534932f 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 7627e5a0b0..905c60975b 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 fcf426c317..46a4ac7fa7 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 d9b382c17b..ca2f9b04e1 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 3e895bd942..1cc84c7456 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 216aa39b2e..6cbafb7958 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 a62e84569b..5233b4a01e 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 8aa04d6bdb..8e711c8954 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 14d8b0735a..0000000000 --- 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 45953eddf4..541b67d7d0 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 7601ad1793..606fdec4b2 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 @@ -245,6 +246,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) { @@ -704,6 +742,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) { @@ -764,9 +824,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 42ce84a985..567a2483d6 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; @@ -90,6 +90,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 0c5d93cc8e..232e5314e9 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 6b132af055..57097ba48e 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 1fbd0035e7..a0254f0d0c 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 95c0c0006c..92f1e88e00 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 8277b6db0f..0ee3cada2d 100644 --- a/applications/services/loader/loader_menu.c +++ b/applications/services/loader/loader_menu.c @@ -126,7 +126,7 @@ static void loader_menu_build_menu(LoaderMenuApp* app, LoaderMenu* menu) { menu_add_item( app->primary_menu, "Settings", &A_Settings_14, i++, loader_menu_switch_to_settings, app); -}; +} static void loader_menu_build_submenu(LoaderMenuApp* app, LoaderMenu* loader_menu) { for(size_t i = 0; i < FLIPPER_SETTINGS_APPS_COUNT; i++) { @@ -194,4 +194,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 528fe7d291..89d01a3617 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 f4ee9c6346..6acf2eea97 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/namechanger/namechanger.c b/applications/services/namechanger/namechanger.c index 5bdaa2a1b2..904a4d4058 100644 --- a/applications/services/namechanger/namechanger.c +++ b/applications/services/namechanger/namechanger.c @@ -108,4 +108,4 @@ int32_t namechanger_on_system_start(void* p) { } return 0; -} \ No newline at end of file +} diff --git a/applications/services/namechanger/namechanger.h b/applications/services/namechanger/namechanger.h index dac1b7952e..5bd5bd8d9f 100644 --- a/applications/services/namechanger/namechanger.h +++ b/applications/services/namechanger/namechanger.h @@ -1,5 +1,5 @@ #pragma once -#define NAMECHANGER_HEADER "Flipper Name File" +#define NAMECHANGER_HEADER "Flipper Name File" #define NAMECHANGER_VERSION 1 -#define NAMECHANGER_PATH EXT_PATH("dolphin/name.settings") +#define NAMECHANGER_PATH EXT_PATH("dolphin/name.settings") diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 8e183f74e1..d4c5b91c8c 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 cacc17ffb0..434773f2e5 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 90e3f236e5..80f7995f17 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 c6a9fefd40..636a2bc983 100644 --- a/applications/services/power/power_service/power.c +++ b/applications/services/power/power_service/power.c @@ -5,7 +5,7 @@ #include #define POWER_OFF_TIMEOUT 90 -#define TAG "Power" +#define TAG "Power" void power_draw_battery_callback(Canvas* canvas, void* context) { furi_assert(context); diff --git a/applications/services/rpc/rpc.c b/applications/services/rpc/rpc.c index b6dd30b240..c2aa3e27c3 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 a70e843630..76ab6c70d3 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 ee35265902..292fc2ef87 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 20baca7b12..0342df2b65 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 ad15051ebc..e88b11b875 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 306b25777b..89991aa86c 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 e6012864d4..cf3803864a 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 f43c6e8151..21f8789cec 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 eaef59cd6d..a4dffe6330 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 67a7e288b8..918e796ce3 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 adc0e2465a..7803e8f6a2 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 4323296cfb..7aa66fce03 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 cb7f16e470..2ad9dcc78e 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 37ea4a2a51..4cbce7546e 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 7e617c0ff2..93e06f6632 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 8c3827fe5d..324ce63286 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/about/about.c b/applications/settings/about/about.c index 1669e335a6..a4c2e5b9ef 100644 --- a/applications/settings/about/about.c +++ b/applications/settings/about/about.c @@ -74,11 +74,12 @@ static DialogMessageButton unleashed_info_screen(DialogsApp* dialogs, DialogMess const char* screen_header = "Unleashed Firmware\n"; - const char* screen_text = "Play with caution.\n" - "Not for illegal use!"; + const char* screen_text = "Is for experimental purposes\nonly " + "and is not meant for any\nillegal use! " + "We do not condone\nany illegal activity."; dialog_message_set_header(message, screen_header, 0, 0, AlignLeft, AlignTop); - dialog_message_set_text(message, screen_text, 0, 26, AlignLeft, AlignTop); + dialog_message_set_text(message, screen_text, 0, 11, AlignLeft, AlignTop); result = dialog_message_show(dialogs, message); dialog_message_set_header(message, NULL, 0, 0, AlignLeft, AlignTop); dialog_message_set_text(message, NULL, 0, 0, AlignLeft, AlignTop); @@ -89,9 +90,9 @@ static DialogMessageButton unleashed_info_screen(DialogsApp* dialogs, DialogMess static DialogMessageButton unleashed_info_screen2(DialogsApp* dialogs, DialogMessage* message) { DialogMessageButton result; - const char* screen_text = "Custom plugins included\n" - "For updates & info visit\n" - "github.com/DarkFlippers"; + const char* screen_text = + "This firmware is free and\ndistributed under\nthe OpenSource license.\n" + "If you paid any money for it\n- you got scammed."; dialog_message_set_text(message, screen_text, 0, 0, AlignLeft, AlignTop); result = dialog_message_show(dialogs, message); @@ -100,24 +101,15 @@ static DialogMessageButton unleashed_info_screen2(DialogsApp* dialogs, DialogMes return result; } -static DialogMessageButton icon1_screen(DialogsApp* dialogs, DialogMessage* message) { +static DialogMessageButton unleashed_info_screen3(DialogsApp* dialogs, DialogMessage* message) { DialogMessageButton result; - dialog_message_set_icon(message, &I_Certification1_103x56, 13, 0); - result = dialog_message_show(dialogs, message); - dialog_message_set_icon(message, NULL, 0, 0); - - return result; -} - -static DialogMessageButton icon2_screen(DialogsApp* dialogs, DialogMessage* message) { - DialogMessageButton result; + const char* screen_text = "Community apps included in\nall builds except `c` build\n" + "For updates and more visit:\n" + "github.com/DarkFlippers"; - dialog_message_set_icon(message, &I_Certification2_46x33, 15, 10); - dialog_message_set_text( - message, furi_hal_version_get_mic_id(), 63, 27, AlignLeft, AlignCenter); + dialog_message_set_text(message, screen_text, 0, 0, AlignLeft, AlignTop); result = dialog_message_show(dialogs, message); - dialog_message_set_icon(message, NULL, 0, 0); dialog_message_set_text(message, NULL, 0, 0, AlignLeft, AlignTop); return result; @@ -197,11 +189,10 @@ static DialogMessageButton fw_version_screen(DialogsApp* dialogs, DialogMessage* const AboutDialogScreen about_screens[] = { unleashed_info_screen, unleashed_info_screen2, + unleashed_info_screen3, product_screen, compliance_screen, address_screen, - icon1_screen, - icon2_screen, hw_version_screen, fw_version_screen}; diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_change_name.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_change_name.c index 11080b2ecb..57d2aedf0d 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_change_name.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_change_name.c @@ -72,4 +72,4 @@ bool desktop_settings_scene_change_name_on_event(void* context, SceneManagerEven void desktop_settings_scene_change_name_on_exit(void* context) { DesktopSettingsApp* app = context; text_input_reset(app->text_input); -} \ No newline at end of file +} 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 117aeeccd1..ee6af0bd9c 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -8,16 +8,16 @@ #define APPS_COUNT (FLIPPER_APPS_COUNT + FLIPPER_EXTERNAL_APPS_COUNT) -#define DEFAULT_INDEX (0) +#define DEFAULT_INDEX (0) #define EXTERNAL_BROWSER_NAME ("Apps Menu (Default)") -#define PASSPORT_NAME ("Passport (Default)") +#define PASSPORT_NAME ("Passport (Default)") #define NONE_APPLICATION_INDEX (1) -#define NONE_APPLICATION_NAME "None (disable)" -#define LOCK_APPLICATION_NAME "Lock Flipper" +#define NONE_APPLICATION_NAME "None (disable)" +#define LOCK_APPLICATION_NAME "Lock Flipper" #define EXTERNAL_APPLICATION_INDEX (2) -#define EXTERNAL_APPLICATION_NAME ("[Select App]") +#define EXTERNAL_APPLICATION_NAME ("[Select App]") #define MAIN_LIST_APPLICATION_OFFSET (3) 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 657680bc35..207824a626 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 b73fe347b2..5af25cd614 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 950be4c5a3..7375edd3f4 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 5b8aa8638a..93012330aa 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/dolphin_passport/passport.c b/applications/settings/dolphin_passport/passport.c index aae53cd2a6..6419f4366a 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 6ee1a0a086..bbbbacd612 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 c626d18449..e4c040b9c7 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 bfc9ac9c93..c07ab1ae68 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 93041d2503..78529ca07d 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 0000000000..46a21a2e85 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 e7421c8c0b..0000000000 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 e098cf6761..0000000000 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 26ca3395c6..b29da07b71 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 0000000000..9d31b4eb3e 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 274c3e070a..0000000000 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 0eda721600..05be3292eb 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 0000000000..6fade6dd77 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 978a1090c2..0000000000 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 13d7369830..95cbf7d5bd 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 0000000000..d41b8feffb 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 6a011e97a8..83a6f225fc 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 0000000000..1ec9ce11e8 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 0000000000..1cd97076ed 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 4f6b4b58ea..0000000000 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 c62d75c0db..4d8471483e 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 0000000000..4dbde3babf 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 0000000000..0f54f0e2b1 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 0000000000..6cac74a57a 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 0000000000..caf92807b5 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 0000000000..17cb1b7403 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 0000000000..1e5955a03a 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 0000000000..a61db48f36 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 0000000000..bf6b927f19 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 0000000000..8fe8afe34d 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 0000000000..bddc7aacea 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 0000000000..ce12dcbf1e 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 0000000000..e96d29ddcd 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 0000000000..60871320ff 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 0000000000..0983db1296 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 0000000000..48f9c77e4d 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 0000000000..eb000cba55 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 71cd30e5dd..606a48daf6 100644 --- a/applications/system/hid_app/views.h +++ b/applications/system/hid_app/views.h @@ -16,4 +16,4 @@ typedef enum { HidViewPushToTalkHelp, 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 9dd2ad6552..0b8c4ed319 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 d9fb2fd88a..9a1bcc0285 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 3a2a064cbb..0bb815249d 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_numpad.c b/applications/system/hid_app/views/hid_numpad.c index 7e528e3fbd..b480e96786 100644 --- a/applications/system/hid_app/views/hid_numpad.c +++ b/applications/system/hid_app/views/hid_numpad.c @@ -38,12 +38,12 @@ typedef struct { int8_t y; } HidNumpadPoint; -#define MARGIN_TOP 32 -#define MARGIN_LEFT 1 -#define KEY_WIDTH 20 -#define KEY_HEIGHT 15 -#define KEY_PADDING 1 -#define ROW_COUNT 6 +#define MARGIN_TOP 32 +#define MARGIN_LEFT 1 +#define KEY_WIDTH 20 +#define KEY_HEIGHT 15 +#define KEY_PADDING 1 +#define ROW_COUNT 6 #define COLUMN_COUNT 3 const HidNumpadKey hid_numpad_keyset[ROW_COUNT][COLUMN_COUNT] = { @@ -289,8 +289,7 @@ HidNumpad* hid_numpad_alloc(Hid* bt_hid) { view_set_draw_callback(hid_numpad->view, hid_numpad_draw_callback); view_set_input_callback(hid_numpad->view, hid_numpad_input_callback); - with_view_model( - hid_numpad->view, HidNumpadModel * model, { model->y = 0; }, true); + with_view_model(hid_numpad->view, HidNumpadModel * model, { model->y = 0; }, true); return hid_numpad; } diff --git a/applications/system/hid_app/views/hid_ptt_menu.h b/applications/system/hid_app/views/hid_ptt_menu.h index c6dc53d550..2defd05699 100644 --- a/applications/system/hid_app/views/hid_ptt_menu.h +++ b/applications/system/hid_app/views/hid_ptt_menu.h @@ -26,4 +26,4 @@ void ptt_menu_add_item_to_list( PushToTalkMenuItemCallback callback, void* callback_context); -void ptt_menu_add_list(HidPushToTalkMenu* hid_ptt_menu, const char* label, uint32_t index); \ No newline at end of file +void ptt_menu_add_list(HidPushToTalkMenu* hid_ptt_menu, const char* label, uint32_t index); diff --git a/applications/system/js_app/examples/apps/Scripts/js_examples/subghz.js b/applications/system/js_app/examples/apps/Scripts/js_examples/subghz.js index 39dadf0709..b5e54bac67 100644 --- a/applications/system/js_app/examples/apps/Scripts/js_examples/subghz.js +++ b/applications/system/js_app/examples/apps/Scripts/js_examples/subghz.js @@ -29,9 +29,17 @@ changeFrequency(433920000); printRXline(); delay(1000); -let result = subghz.transmitFile("/ext/subghz/0.sub"); -print(result ? "Send success" : "Send failed"); +print("Sending 0.sub") +subghz.transmitFile("/ext/subghz/0.sub"); +// Can also specify repeat count: subghz.transmitFile(path, repeat) +// If not provided, defaults to 1 repeat for RAW and 10 repeats for parsed +// These 10 repeats by default are to simulate holding the button on remote +print("Send success"); delay(1000); changeFrequency(315000000); -printRXline(); \ No newline at end of file +printRXline(); + +// Optional, done automatically at script end +subghz.end() +// But can be used to setup again, which will retry to detect external modules \ No newline at end of file diff --git a/applications/system/js_app/js_modules.c b/applications/system/js_app/js_modules.c index fa53328845..9ab6cb1407 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 aff4d7e8df..77e50786f4 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_blebeacon.c b/applications/system/js_app/modules/js_blebeacon.c index 7dc212b6a4..1d79457c87 100644 --- a/applications/system/js_app/modules/js_blebeacon.c +++ b/applications/system/js_app/modules/js_blebeacon.c @@ -241,4 +241,4 @@ static const FlipperAppPluginDescriptor plugin_descriptor = { const FlipperAppPluginDescriptor* js_blebeacon_ep(void) { return &plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/system/js_app/modules/js_gpio.c b/applications/system/js_app/modules/js_gpio.c index ce65837b17..fb42bea2be 100644 --- a/applications/system/js_app/modules/js_gpio.c +++ b/applications/system/js_app/modules/js_gpio.c @@ -392,4 +392,4 @@ static const FlipperAppPluginDescriptor plugin_descriptor = { const FlipperAppPluginDescriptor* js_gpio_ep(void) { return &plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/system/js_app/modules/js_keyboard.c b/applications/system/js_app/modules/js_keyboard.c index 2bfb296e00..65373db785 100644 --- a/applications/system/js_app/modules/js_keyboard.c +++ b/applications/system/js_app/modules/js_keyboard.c @@ -1,14 +1,16 @@ #include "../js_modules.h" #include #include -#include +#include +#include #define membersof(x) (sizeof(x) / sizeof(x[0])) typedef struct { TextInput* text_input; ByteInput* byte_input; - ViewDispatcher* view_dispatcher; + ViewHolder* view_holder; + FuriApiLock lock; char* header; bool accepted; } JsKeyboardInst; @@ -28,14 +30,13 @@ static JsKeyboardInst* get_this_ctx(struct mjs* mjs) { static void keyboard_callback(void* context) { JsKeyboardInst* keyboard = (JsKeyboardInst*)context; keyboard->accepted = true; - view_dispatcher_stop(keyboard->view_dispatcher); + api_lock_unlock(keyboard->lock); } -static bool keyboard_exit(void* context) { +static void keyboard_exit(void* context) { JsKeyboardInst* keyboard = (JsKeyboardInst*)context; keyboard->accepted = false; - view_dispatcher_stop(keyboard->view_dispatcher); - return true; + api_lock_unlock(keyboard->lock); } static void js_keyboard_set_header(struct mjs* mjs) { @@ -84,22 +85,21 @@ static void js_keyboard_text(struct mjs* mjs) { text_input_set_minimum_length(keyboard->text_input, 0); + keyboard->lock = api_lock_alloc_locked(); Gui* gui = furi_record_open(RECORD_GUI); - keyboard->view_dispatcher = view_dispatcher_alloc(); - view_dispatcher_enable_queue(keyboard->view_dispatcher); - view_dispatcher_add_view( - keyboard->view_dispatcher, 0, text_input_get_view(keyboard->text_input)); - view_dispatcher_set_event_callback_context(keyboard->view_dispatcher, keyboard); - view_dispatcher_set_navigation_event_callback(keyboard->view_dispatcher, keyboard_exit); - view_dispatcher_attach_to_gui(keyboard->view_dispatcher, gui, ViewDispatcherTypeFullscreen); - view_dispatcher_switch_to_view(keyboard->view_dispatcher, 0); - - view_dispatcher_run(keyboard->view_dispatcher); - - view_dispatcher_remove_view(keyboard->view_dispatcher, 0); - view_dispatcher_free(keyboard->view_dispatcher); - keyboard->view_dispatcher = NULL; + keyboard->view_holder = view_holder_alloc(); + view_holder_attach_to_gui(keyboard->view_holder, gui); + view_holder_set_back_callback(keyboard->view_holder, keyboard_exit, keyboard); + + view_holder_set_view(keyboard->view_holder, text_input_get_view(keyboard->text_input)); + view_holder_start(keyboard->view_holder); + api_lock_wait_unlock(keyboard->lock); + + view_holder_stop(keyboard->view_holder); + view_holder_free(keyboard->view_holder); + furi_record_close(RECORD_GUI); + api_lock_free(keyboard->lock); text_input_reset(keyboard->text_input); if(keyboard->header) { @@ -141,22 +141,21 @@ static void js_keyboard_byte(struct mjs* mjs) { byte_input_set_result_callback( keyboard->byte_input, keyboard_callback, NULL, keyboard, buffer, input_length); + keyboard->lock = api_lock_alloc_locked(); Gui* gui = furi_record_open(RECORD_GUI); - keyboard->view_dispatcher = view_dispatcher_alloc(); - view_dispatcher_enable_queue(keyboard->view_dispatcher); - view_dispatcher_add_view( - keyboard->view_dispatcher, 0, byte_input_get_view(keyboard->byte_input)); - view_dispatcher_set_event_callback_context(keyboard->view_dispatcher, keyboard); - view_dispatcher_set_navigation_event_callback(keyboard->view_dispatcher, keyboard_exit); - view_dispatcher_attach_to_gui(keyboard->view_dispatcher, gui, ViewDispatcherTypeFullscreen); - view_dispatcher_switch_to_view(keyboard->view_dispatcher, 0); - - view_dispatcher_run(keyboard->view_dispatcher); - - view_dispatcher_remove_view(keyboard->view_dispatcher, 0); - view_dispatcher_free(keyboard->view_dispatcher); - keyboard->view_dispatcher = NULL; + keyboard->view_holder = view_holder_alloc(); + view_holder_attach_to_gui(keyboard->view_holder, gui); + view_holder_set_back_callback(keyboard->view_holder, keyboard_exit, keyboard); + + view_holder_set_view(keyboard->view_holder, byte_input_get_view(keyboard->byte_input)); + view_holder_start(keyboard->view_holder); + api_lock_wait_unlock(keyboard->lock); + + view_holder_stop(keyboard->view_holder); + view_holder_free(keyboard->view_holder); + furi_record_close(RECORD_GUI); + api_lock_free(keyboard->lock); if(keyboard->header) { free(keyboard->header); @@ -206,4 +205,4 @@ static const FlipperAppPluginDescriptor plugin_descriptor = { const FlipperAppPluginDescriptor* js_keyboard_ep(void) { return &plugin_descriptor; -} \ No newline at end of file +} diff --git a/applications/system/js_app/modules/js_math.c b/applications/system/js_app/modules/js_math.c index b4c1cdca23..d8812e61bb 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 e1084be139..2f57c45d1b 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 a7d1398956..293798a12b 100644 --- a/applications/system/js_app/modules/js_serial.c +++ b/applications/system/js_app/modules/js_serial.c @@ -4,7 +4,8 @@ #include "../js_modules.h" #include -#define TAG "js_serial" +#define TAG "JsSerial" + #define RX_BUF_LEN 2048 typedef struct { @@ -529,14 +530,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_subghz/js_subghz.c b/applications/system/js_app/modules/js_subghz/js_subghz.c index f170aa04bc..f0e21c1ff9 100644 --- a/applications/system/js_app/modules/js_subghz/js_subghz.c +++ b/applications/system/js_app/modules/js_subghz/js_subghz.c @@ -7,7 +7,7 @@ #include -#define tag "js_subghz" +#define TAG "js_subghz" typedef enum { JsSubghzRadioStateRX, @@ -22,7 +22,6 @@ typedef struct { JsSubghzRadioState state; } JsSubghzInst; -// from subghz cli static FuriHalSubGhzPreset js_subghz_get_preset_name(const char* preset_name) { FuriHalSubGhzPreset preset = FuriHalSubGhzPresetIDLE; if(!strcmp(preset_name, "FuriHalSubGhzPresetOok270Async")) { @@ -36,7 +35,7 @@ static FuriHalSubGhzPreset js_subghz_get_preset_name(const char* preset_name) { } else if(!strcmp(preset_name, "FuriHalSubGhzPresetCustom")) { preset = FuriHalSubGhzPresetCustom; } else { - FURI_LOG_I(tag, "unknown preset"); + FURI_LOG_I(TAG, "unknown preset"); } return preset; } @@ -46,27 +45,37 @@ static void js_subghz_set_rx(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); - if(js_subghz->state == JsSubghzRadioStateRX) { + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); mjs_return(mjs, MJS_UNDEFINED); return; } - subghz_devices_set_rx(js_subghz->radio_device); - js_subghz->state = JsSubghzRadioStateRX; + if(js_subghz->state != JsSubghzRadioStateRX) { + subghz_devices_set_rx(js_subghz->radio_device); + js_subghz->state = JsSubghzRadioStateRX; + } + + mjs_return(mjs, MJS_UNDEFINED); } -static void js_subgjz_set_idle(struct mjs* mjs) { +static void js_subghz_set_idle(struct mjs* mjs) { mjs_val_t obj_inst = mjs_get(mjs, mjs_get_this(mjs), INST_PROP_NAME, ~0); JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); - if(js_subghz->state == JsSubghzRadioStateIDLE) { + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); mjs_return(mjs, MJS_UNDEFINED); return; } - subghz_devices_idle(js_subghz->radio_device); - js_subghz->state = JsSubghzRadioStateIDLE; + if(js_subghz->state != JsSubghzRadioStateIDLE) { + subghz_devices_idle(js_subghz->radio_device); + js_subghz->state = JsSubghzRadioStateIDLE; + } + + mjs_return(mjs, MJS_UNDEFINED); } static void js_subghz_get_rssi(struct mjs* mjs) { @@ -74,6 +83,12 @@ static void js_subghz_get_rssi(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + if(js_subghz->state != JsSubghzRadioStateRX) { mjs_return(mjs, MJS_UNDEFINED); return; @@ -88,6 +103,12 @@ static void js_subghz_get_state(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + const char* state; switch(js_subghz->state) { case JsSubghzRadioStateRX: @@ -112,6 +133,12 @@ static void js_subghz_is_external(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + mjs_return(mjs, mjs_mk_boolean(mjs, js_subghz->is_external)); } @@ -120,6 +147,12 @@ static void js_subghz_set_frequency(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + if(js_subghz->state != JsSubghzRadioStateIDLE) { mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not in IDLE state"); mjs_return(mjs, MJS_UNDEFINED); @@ -150,6 +183,12 @@ static void js_subghz_get_frequency(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + mjs_return(mjs, mjs_mk_number(mjs, (double)js_subghz->frequency)); } @@ -158,8 +197,13 @@ static void js_subghz_transmit_file(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); - mjs_val_t file = mjs_arg(mjs, 0); + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + mjs_val_t file = mjs_arg(mjs, 0); if(!mjs_is_string(file)) { mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "File must be a string"); mjs_return(mjs, MJS_UNDEFINED); @@ -173,9 +217,25 @@ static void js_subghz_transmit_file(struct mjs* mjs) { return; } + // Repeat works weirdly: + // - "Repeat" in parsed protocol is like holding Send in Sub-GHz app + // This is necessary as most receivers require hearing signals multiple times + // - "repeat" as variable and loop in this code applies to RAW files only + // parsed files handle repeat in protocol layer instead + // We keep 0 as default, or literal value if specified by user + // If user did not specify, -1 is detected below, and we use: + // - 1 repeat for RAW + // - 10 repeats for parsed, which is passed to protocol, and we loop once here + uint32_t repeat = 0; + mjs_val_t repeat_arg = mjs_arg(mjs, 1); + if(mjs_is_number(repeat_arg)) { + int32_t repeat_val = mjs_get_int32(mjs, repeat_arg); + repeat = MAX(repeat_val, 0); + } + Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_file = flipper_format_file_alloc(storage); - FlipperFormat* fff_data_raw = flipper_format_string_alloc(); + FlipperFormat* fff_raw = NULL; if(!flipper_format_file_open_existing(fff_file, file_path)) { flipper_format_free(fff_file); @@ -187,10 +247,10 @@ static void js_subghz_transmit_file(struct mjs* mjs) { SubGhzEnvironment* environment = subghz_environment_alloc(); if(!subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_NAME)) { - FURI_LOG_I(tag, "Load_keystore keeloq_mfcodes \033[0;31mERROR\033[0m\r\n"); + FURI_LOG_W(TAG, "Load_keystore keeloq_mfcodes - failed to load"); } if(!subghz_environment_load_keystore(environment, SUBGHZ_KEYSTORE_DIR_USER_NAME)) { - FURI_LOG_I(tag, "Load_keystore keeloq_mfcodes_user \033[0;33mAbsent\033[0m\r\n"); + FURI_LOG_W(TAG, "Load_keystore keeloq_mfcodes_user - failed to load"); } subghz_environment_set_alutech_at_4n_rainbow_table_file_name( environment, SUBGHZ_ALUTECH_AT_4N_DIR_NAME); @@ -200,119 +260,172 @@ static void js_subghz_transmit_file(struct mjs* mjs) { FuriString* temp_str = furi_string_alloc(); SubGhzTransmitter* transmitter = NULL; - bool is_init_protocol = true; - bool is_sent = false; + uint32_t temp_data32 = 0; uint32_t frequency = 0; - uint32_t repeat = 10; + bool is_sent = false; do { - //Load frequency - if(!flipper_format_read_uint32(fff_file, "Frequency", &frequency, 1)) { - mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Failed to read frequency from file"); - mjs_return(mjs, MJS_UNDEFINED); + if(!flipper_format_read_header(fff_file, temp_str, &temp_data32)) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing or incorrect header"); break; } - if(!subghz_devices_is_frequency_valid(js_subghz->radio_device, frequency)) { - mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Invalid frequency"); - mjs_return(mjs, MJS_UNDEFINED); + if(((!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_KEY_FILE_TYPE)) || + (!strcmp(furi_string_get_cstr(temp_str), SUBGHZ_RAW_FILE_TYPE))) && + temp_data32 == SUBGHZ_KEY_FILE_VERSION) { + } else { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Type or version mismatch"); + break; + } + if(!flipper_format_read_uint32(fff_file, "Frequency", &frequency, 1)) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing Frequency"); break; } if(!flipper_format_read_string(fff_file, "Preset", temp_str)) { - mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Failed to read preset from file"); - mjs_return(mjs, MJS_UNDEFINED); + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing Preset"); + break; + } + + FuriHalSubGhzPreset preset = js_subghz_get_preset_name(furi_string_get_cstr(temp_str)); + if(preset == FuriHalSubGhzPresetIDLE) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Unknown preset"); break; } subghz_devices_reset(js_subghz->radio_device); + subghz_devices_idle(js_subghz->radio_device); - if(!strcmp(furi_string_get_cstr(temp_str), "FuriHalSubGhzPresetCustom")) { - mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Custom presets are not supported (yet)"); - mjs_return(mjs, MJS_UNDEFINED); - break; + if(preset == FuriHalSubGhzPresetCustom) { + uint8_t* custom_preset_data; + if(!flipper_format_get_value_count(fff_file, "Custom_preset_data", &temp_data32) || + !temp_data32 || (temp_data32 % 2)) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Custom_preset_data size error"); + break; + } + custom_preset_data = malloc(temp_data32); + if(!flipper_format_read_hex( + fff_file, "Custom_preset_data", custom_preset_data, temp_data32)) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Custom_preset_data read error"); + break; + } + subghz_devices_load_preset(js_subghz->radio_device, preset, custom_preset_data); + free(custom_preset_data); } else { - subghz_devices_load_preset( - js_subghz->radio_device, - js_subghz_get_preset_name(furi_string_get_cstr(temp_str)), - NULL); + subghz_devices_load_preset(js_subghz->radio_device, preset, NULL); } js_subghz->frequency = subghz_devices_set_frequency(js_subghz->radio_device, frequency); if(!flipper_format_read_string(fff_file, "Protocol", temp_str)) { - mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Failed to read protocol from file"); - mjs_return(mjs, MJS_UNDEFINED); + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Missing protocol"); break; } - SubGhzProtocolStatus status; - bool is_raw = false; - - if(!strcmp(furi_string_get_cstr(temp_str), "RAW")) { + bool is_raw = furi_string_equal(temp_str, "RAW"); + if(is_raw) { + fff_raw = flipper_format_string_alloc(); subghz_protocol_raw_gen_fff_data( - fff_data_raw, file_path, subghz_devices_get_name(js_subghz->radio_device)); - is_raw = true; + fff_raw, file_path, subghz_devices_get_name(js_subghz->radio_device)); + // One repeat by default + if(!repeat) { + repeat = 1; + } + } else { + // Simulate holding button by default + if(!repeat) { + if(furi_string_equal(temp_str, "CAME Atomo") || + furi_string_equal(temp_str, "CAME TWEE") || + furi_string_equal(temp_str, "Hormann HSM") || + furi_string_equal(temp_str, "Nice FloR-S") || + furi_string_equal(temp_str, "Power Smart")) { + // These protocols send multiple frames/packets for each "repeat" + // Just 1 full repeat should be sufficient + repeat = 1; + } else { + repeat = 10; + } + } + // Pass repeat value to protocol layer + flipper_format_insert_or_update_uint32(fff_file, "Repeat", &repeat, 1); + // Repeat variable applies to high-level code here, should only loop once + repeat = 1; } transmitter = subghz_transmitter_alloc_init(environment, furi_string_get_cstr(temp_str)); - if(transmitter == NULL) { - is_init_protocol = false; + if(!transmitter) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Failed to init transmitter"); + break; } - if(is_init_protocol) { - status = subghz_transmitter_deserialize(transmitter, is_raw ? fff_data_raw : fff_file); - if(status != SubGhzProtocolStatusOk) { - FURI_LOG_I(tag, "failed to deserialize transmitter"); - is_init_protocol = false; - } - } else { - FURI_LOG_I(tag, "failed to allocate transmitter"); - subghz_devices_idle(js_subghz->radio_device); - js_subghz->state = JsSubghzRadioStateIDLE; + SubGhzProtocolStatus status = + subghz_transmitter_deserialize(transmitter, is_raw ? fff_raw : fff_file); + if(status != SubGhzProtocolStatusOk) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Failed to deserialize protocol"); + break; } - } while(false); + // Must close file here, otherwise RAW protocol cannot open + flipper_format_file_close(fff_file); - if(is_init_protocol) { if(!js_subghz->is_external) { furi_hal_power_suppress_charge_enter(); } + subghz_devices_set_tx(js_subghz->radio_device); + FURI_LOG_I(TAG, "Transmitting file %s", file_path); - FURI_LOG_I(tag, "transmitting file %s", file_path); - - do { - furi_delay_ms(200); - if(subghz_devices_start_async_tx( + while(repeat) { + if(!subghz_devices_start_async_tx( js_subghz->radio_device, subghz_transmitter_yield, transmitter)) { - while(!subghz_devices_is_async_complete_tx(js_subghz->radio_device)) { - furi_delay_ms(333); - } - subghz_devices_stop_async_tx(js_subghz->radio_device); - is_sent = true; - } else { - FURI_LOG_E(tag, "failed to start async tx"); + is_sent = false; + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Failed to start async tx"); + break; } - - } while(repeat && !strcmp(furi_string_get_cstr(temp_str), "RAW")); - - subghz_devices_idle(js_subghz->radio_device); - js_subghz->state = JsSubghzRadioStateIDLE; + while(!subghz_devices_is_async_complete_tx(js_subghz->radio_device)) { + furi_delay_ms(100); + } + subghz_devices_stop_async_tx(js_subghz->radio_device); + subghz_transmitter_stop(transmitter); + is_sent = true; + repeat--; + + // Only RAW is repeated with this loop, check comments above + if(!is_raw) { + break; + } + if(repeat) { + subghz_transmitter_deserialize(transmitter, fff_raw); + furi_delay_ms(200); + } + } if(!js_subghz->is_external) { furi_hal_power_suppress_charge_exit(); } - } + } while(false); + + subghz_devices_idle(js_subghz->radio_device); + js_subghz->state = JsSubghzRadioStateIDLE; + if(transmitter) { + subghz_transmitter_free(transmitter); + } furi_string_free(temp_str); + subghz_environment_free(environment); + + if(fff_raw) { + flipper_format_free(fff_raw); + } flipper_format_free(fff_file); - flipper_format_free(fff_data_raw); furi_record_close(RECORD_STORAGE); - subghz_environment_reset_keeloq(environment); - subghz_environment_free(environment); - subghz_transmitter_free(transmitter); - - mjs_return(mjs, mjs_mk_boolean(mjs, is_sent)); + if(is_sent) { + // Return true for backwards compatibility + // Now it will just error if something goes wrong, not return false + mjs_return(mjs, mjs_mk_boolean(mjs, true)); + } else { + // Broke out of do...while with an mJS error + mjs_return(mjs, MJS_UNDEFINED); + } } static void js_subghz_setup(struct mjs* mjs) { @@ -320,6 +433,12 @@ static void js_subghz_setup(struct mjs* mjs) { JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); furi_assert(js_subghz); + if(js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is already setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + js_subghz->radio_device = radio_device_loader_set(js_subghz->radio_device, SubGhzRadioDeviceTypeExternalCC1101); @@ -338,6 +457,28 @@ static void js_subghz_setup(struct mjs* mjs) { mjs_return(mjs, MJS_UNDEFINED); } +static void js_subghz_end(struct mjs* mjs) { + mjs_val_t obj_inst = mjs_get(mjs, mjs_get_this(mjs), INST_PROP_NAME, ~0); + JsSubghzInst* js_subghz = mjs_get_ptr(mjs, obj_inst); + furi_assert(js_subghz); + + if(!js_subghz->radio_device) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Radio is not setup"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } + + subghz_devices_sleep(js_subghz->radio_device); + radio_device_loader_end(js_subghz->radio_device); + js_subghz->radio_device = NULL; + + js_subghz->is_external = false; + js_subghz->state = -1; + js_subghz->frequency = 0; + + mjs_return(mjs, MJS_UNDEFINED); +} + static void* js_subghz_create(struct mjs* mjs, mjs_val_t* object) { JsSubghzInst* js_subghz = malloc(sizeof(JsSubghzInst)); mjs_val_t subghz_obj = mjs_mk_object(mjs); @@ -346,8 +487,9 @@ static void* js_subghz_create(struct mjs* mjs, mjs_val_t* object) { mjs_set(mjs, subghz_obj, INST_PROP_NAME, ~0, mjs_mk_foreign(mjs, js_subghz)); mjs_set(mjs, subghz_obj, "setup", ~0, MJS_MK_FN(js_subghz_setup)); + mjs_set(mjs, subghz_obj, "end", ~0, MJS_MK_FN(js_subghz_end)); mjs_set(mjs, subghz_obj, "setRx", ~0, MJS_MK_FN(js_subghz_set_rx)); - mjs_set(mjs, subghz_obj, "setIdle", ~0, MJS_MK_FN(js_subgjz_set_idle)); + mjs_set(mjs, subghz_obj, "setIdle", ~0, MJS_MK_FN(js_subghz_set_idle)); mjs_set(mjs, subghz_obj, "getRssi", ~0, MJS_MK_FN(js_subghz_get_rssi)); mjs_set(mjs, subghz_obj, "getState", ~0, MJS_MK_FN(js_subghz_get_state)); mjs_set(mjs, subghz_obj, "getFrequency", ~0, MJS_MK_FN(js_subghz_get_frequency)); @@ -363,6 +505,11 @@ static void* js_subghz_create(struct mjs* mjs, mjs_val_t* object) { static void js_subghz_destroy(void* inst) { JsSubghzInst* js_subghz = inst; + if(js_subghz->radio_device) { + subghz_devices_sleep(js_subghz->radio_device); + radio_device_loader_end(js_subghz->radio_device); + } + subghz_devices_deinit(); free(js_subghz); diff --git a/applications/system/js_app/modules/js_subghz/radio_device_loader.c b/applications/system/js_app/modules/js_subghz/radio_device_loader.c index d2cffde583..0a45c24181 100644 --- a/applications/system/js_app/modules/js_subghz/radio_device_loader.c +++ b/applications/system/js_app/modules/js_subghz/radio_device_loader.c @@ -61,4 +61,4 @@ void radio_device_loader_end(const SubGhzDevice* radio_device) { if(radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)) { subghz_devices_end(radio_device); } -} \ No newline at end of file +} diff --git a/applications/system/js_app/modules/js_subghz/radio_device_loader.h b/applications/system/js_app/modules/js_subghz/radio_device_loader.h index bee4e2c362..4f200ebc31 100644 --- a/applications/system/js_app/modules/js_subghz/radio_device_loader.h +++ b/applications/system/js_app/modules/js_subghz/radio_device_loader.h @@ -12,4 +12,4 @@ const SubGhzDevice* radio_device_loader_set( const SubGhzDevice* current_radio_device, SubGhzRadioDeviceType radio_device_type); -void radio_device_loader_end(const SubGhzDevice* radio_device); \ No newline at end of file +void radio_device_loader_end(const SubGhzDevice* radio_device); diff --git a/applications/system/js_app/modules/js_textbox.c b/applications/system/js_app/modules/js_textbox.c index d15cd2779d..33798b2965 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/modules/js_usbdisk/mass_storage_scsi.c b/applications/system/js_app/modules/js_usbdisk/mass_storage_scsi.c index c1efacf8e2..83f8caaef1 100644 --- a/applications/system/js_app/modules/js_usbdisk/mass_storage_scsi.c +++ b/applications/system/js_app/modules/js_usbdisk/mass_storage_scsi.c @@ -4,16 +4,16 @@ #define TAG "MassStorageSCSI" -#define SCSI_TEST_UNIT_READY (0x00) -#define SCSI_REQUEST_SENSE (0x03) -#define SCSI_INQUIRY (0x12) +#define SCSI_TEST_UNIT_READY (0x00) +#define SCSI_REQUEST_SENSE (0x03) +#define SCSI_INQUIRY (0x12) #define SCSI_READ_FORMAT_CAPACITIES (0x23) -#define SCSI_READ_CAPACITY_10 (0x25) -#define SCSI_MODE_SENSE_6 (0x1A) -#define SCSI_READ_10 (0x28) +#define SCSI_READ_CAPACITY_10 (0x25) +#define SCSI_MODE_SENSE_6 (0x1A) +#define SCSI_READ_10 (0x28) #define SCSI_PREVENT_MEDIUM_REMOVAL (0x1E) -#define SCSI_START_STOP_UNIT (0x1B) -#define SCSI_WRITE_10 (0x2A) +#define SCSI_START_STOP_UNIT (0x1B) +#define SCSI_WRITE_10 (0x2A) bool scsi_cmd_start(SCSISession* scsi, uint8_t* cmd, uint8_t len) { if(!len) { diff --git a/applications/system/js_app/modules/js_usbdisk/mass_storage_scsi.h b/applications/system/js_app/modules/js_usbdisk/mass_storage_scsi.h index a35d6aff32..56f4847a1f 100644 --- a/applications/system/js_app/modules/js_usbdisk/mass_storage_scsi.h +++ b/applications/system/js_app/modules/js_usbdisk/mass_storage_scsi.h @@ -7,8 +7,8 @@ #define SCSI_SK_ILLEGAL_REQUEST (5) #define SCSI_ASC_INVALID_COMMAND_OPERATION_CODE (0x20) -#define SCSI_ASC_LBA_OOB (0x21) -#define SCSI_ASC_INVALID_FIELD_IN_CDB (0x24) +#define SCSI_ASC_LBA_OOB (0x21) +#define SCSI_ASC_INVALID_FIELD_IN_CDB (0x24) typedef struct { void* ctx; @@ -53,4 +53,4 @@ typedef struct { bool scsi_cmd_start(SCSISession* scsi, uint8_t* cmd, uint8_t len); bool scsi_cmd_rx_data(SCSISession* scsi, uint8_t* data, uint32_t len); bool scsi_cmd_tx_data(SCSISession* scsi, uint8_t* data, uint32_t* len, uint32_t cap); -bool scsi_cmd_end(SCSISession* scsi); \ No newline at end of file +bool scsi_cmd_end(SCSISession* scsi); diff --git a/applications/system/js_app/modules/js_usbdisk/mass_storage_usb.c b/applications/system/js_app/modules/js_usbdisk/mass_storage_usb.c index b96b4fecc4..1f1a461311 100644 --- a/applications/system/js_app/modules/js_usbdisk/mass_storage_usb.c +++ b/applications/system/js_app/modules/js_usbdisk/mass_storage_usb.c @@ -10,14 +10,14 @@ #define USB_MSC_TX_EP_SIZE (64UL) #define USB_MSC_BOT_GET_MAX_LUN (0xFE) -#define USB_MSC_BOT_RESET (0xFF) +#define USB_MSC_BOT_RESET (0xFF) -#define CBW_SIG (0x43425355) +#define CBW_SIG (0x43425355) #define CBW_FLAGS_DEVICE_TO_HOST (0x80) -#define CSW_SIG (0x53425355) -#define CSW_STATUS_OK (0) -#define CSW_STATUS_NOK (1) +#define CSW_SIG (0x53425355) +#define CSW_STATUS_OK (0) +#define CSW_STATUS_NOK (1) #define CSW_STATUS_PHASE_ERROR (2) // must be SCSI_BLOCK_SIZE aligned @@ -456,14 +456,16 @@ MassStorageUsb* mass_storage_usb_start(const char* filename, SCSIDeviceFunc fn) struct usb_string_descriptor* str_prod_descr = malloc(len * 2 + 2); str_prod_descr->bLength = len * 2 + 2; str_prod_descr->bDescriptorType = USB_DTYPE_STRING; - for(uint8_t i = 0; i < len; i++) str_prod_descr->wString[i] = name[i]; + for(uint8_t i = 0; i < len; i++) + str_prod_descr->wString[i] = name[i]; mass->usb.str_prod_descr = str_prod_descr; len = strlen(filename); struct usb_string_descriptor* str_serial_descr = malloc(len * 2 + 2); str_serial_descr->bLength = len * 2 + 2; str_serial_descr->bDescriptorType = USB_DTYPE_STRING; - for(uint8_t i = 0; i < len; i++) str_serial_descr->wString[i] = filename[i]; + for(uint8_t i = 0; i < len; i++) + str_serial_descr->wString[i] = filename[i]; mass->usb.str_serial_descr = str_serial_descr; mass->fn = fn; diff --git a/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P.h b/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P.h index b04fb9809e..c060e84b26 100644 --- a/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P.h +++ b/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P.h @@ -124,4 +124,4 @@ bool icm42688_fifo_read(ICM42688P* icm42688p, ICM42688PFifoPacket* data); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P_regs.h b/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P_regs.h index 1967534df1..cad14542b2 100644 --- a/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P_regs.h +++ b/applications/system/js_app/modules/js_vgm/ICM42688P/ICM42688P_regs.h @@ -3,174 +3,174 @@ #define ICM42688_WHOAMI 0x47 // Bank 0 -#define ICM42688_DEVICE_CONFIG 0x11 -#define ICM42688_DRIVE_CONFIG 0x13 -#define ICM42688_INT_CONFIG 0x14 -#define ICM42688_FIFO_CONFIG 0x16 -#define ICM42688_TEMP_DATA1 0x1D -#define ICM42688_TEMP_DATA0 0x1E -#define ICM42688_ACCEL_DATA_X1 0x1F -#define ICM42688_ACCEL_DATA_X0 0x20 -#define ICM42688_ACCEL_DATA_Y1 0x21 -#define ICM42688_ACCEL_DATA_Y0 0x22 -#define ICM42688_ACCEL_DATA_Z1 0x23 -#define ICM42688_ACCEL_DATA_Z0 0x24 -#define ICM42688_GYRO_DATA_X1 0x25 -#define ICM42688_GYRO_DATA_X0 0x26 -#define ICM42688_GYRO_DATA_Y1 0x27 -#define ICM42688_GYRO_DATA_Y0 0x28 -#define ICM42688_GYRO_DATA_Z1 0x29 -#define ICM42688_GYRO_DATA_Z0 0x2A -#define ICM42688_TMST_FSYNCH 0x2B -#define ICM42688_TMST_FSYNCL 0x2C -#define ICM42688_INT_STATUS 0x2D -#define ICM42688_FIFO_COUNTH 0x2E -#define ICM42688_FIFO_COUNTL 0x2F -#define ICM42688_FIFO_DATA 0x30 -#define ICM42688_APEX_DATA0 0x31 -#define ICM42688_APEX_DATA1 0x32 -#define ICM42688_APEX_DATA2 0x33 -#define ICM42688_APEX_DATA3 0x34 -#define ICM42688_APEX_DATA4 0x35 -#define ICM42688_APEX_DATA5 0x36 -#define ICM42688_INT_STATUS2 0x37 -#define ICM42688_INT_STATUS3 0x38 -#define ICM42688_SIGNAL_PATH_RESET 0x4B -#define ICM42688_INTF_CONFIG0 0x4C -#define ICM42688_INTF_CONFIG1 0x4D -#define ICM42688_PWR_MGMT0 0x4E -#define ICM42688_GYRO_CONFIG0 0x4F -#define ICM42688_ACCEL_CONFIG0 0x50 -#define ICM42688_GYRO_CONFIG1 0x51 +#define ICM42688_DEVICE_CONFIG 0x11 +#define ICM42688_DRIVE_CONFIG 0x13 +#define ICM42688_INT_CONFIG 0x14 +#define ICM42688_FIFO_CONFIG 0x16 +#define ICM42688_TEMP_DATA1 0x1D +#define ICM42688_TEMP_DATA0 0x1E +#define ICM42688_ACCEL_DATA_X1 0x1F +#define ICM42688_ACCEL_DATA_X0 0x20 +#define ICM42688_ACCEL_DATA_Y1 0x21 +#define ICM42688_ACCEL_DATA_Y0 0x22 +#define ICM42688_ACCEL_DATA_Z1 0x23 +#define ICM42688_ACCEL_DATA_Z0 0x24 +#define ICM42688_GYRO_DATA_X1 0x25 +#define ICM42688_GYRO_DATA_X0 0x26 +#define ICM42688_GYRO_DATA_Y1 0x27 +#define ICM42688_GYRO_DATA_Y0 0x28 +#define ICM42688_GYRO_DATA_Z1 0x29 +#define ICM42688_GYRO_DATA_Z0 0x2A +#define ICM42688_TMST_FSYNCH 0x2B +#define ICM42688_TMST_FSYNCL 0x2C +#define ICM42688_INT_STATUS 0x2D +#define ICM42688_FIFO_COUNTH 0x2E +#define ICM42688_FIFO_COUNTL 0x2F +#define ICM42688_FIFO_DATA 0x30 +#define ICM42688_APEX_DATA0 0x31 +#define ICM42688_APEX_DATA1 0x32 +#define ICM42688_APEX_DATA2 0x33 +#define ICM42688_APEX_DATA3 0x34 +#define ICM42688_APEX_DATA4 0x35 +#define ICM42688_APEX_DATA5 0x36 +#define ICM42688_INT_STATUS2 0x37 +#define ICM42688_INT_STATUS3 0x38 +#define ICM42688_SIGNAL_PATH_RESET 0x4B +#define ICM42688_INTF_CONFIG0 0x4C +#define ICM42688_INTF_CONFIG1 0x4D +#define ICM42688_PWR_MGMT0 0x4E +#define ICM42688_GYRO_CONFIG0 0x4F +#define ICM42688_ACCEL_CONFIG0 0x50 +#define ICM42688_GYRO_CONFIG1 0x51 #define ICM42688_GYRO_ACCEL_CONFIG0 0x52 -#define ICM42688_ACCEL_CONFIG1 0x53 -#define ICM42688_TMST_CONFIG 0x54 -#define ICM42688_APEX_CONFIG0 0x56 -#define ICM42688_SMD_CONFIG 0x57 -#define ICM42688_FIFO_CONFIG1 0x5F -#define ICM42688_FIFO_CONFIG2 0x60 -#define ICM42688_FIFO_CONFIG3 0x61 -#define ICM42688_FSYNC_CONFIG 0x62 -#define ICM42688_INT_CONFIG0 0x63 -#define ICM42688_INT_CONFIG1 0x64 -#define ICM42688_INT_SOURCE0 0x65 -#define ICM42688_INT_SOURCE1 0x66 -#define ICM42688_INT_SOURCE3 0x68 -#define ICM42688_INT_SOURCE4 0x69 -#define ICM42688_FIFO_LOST_PKT0 0x6C -#define ICM42688_FIFO_LOST_PKT1 0x6D -#define ICM42688_SELF_TEST_CONFIG 0x70 -#define ICM42688_WHO_AM_I 0x75 -#define ICM42688_REG_BANK_SEL 0x76 +#define ICM42688_ACCEL_CONFIG1 0x53 +#define ICM42688_TMST_CONFIG 0x54 +#define ICM42688_APEX_CONFIG0 0x56 +#define ICM42688_SMD_CONFIG 0x57 +#define ICM42688_FIFO_CONFIG1 0x5F +#define ICM42688_FIFO_CONFIG2 0x60 +#define ICM42688_FIFO_CONFIG3 0x61 +#define ICM42688_FSYNC_CONFIG 0x62 +#define ICM42688_INT_CONFIG0 0x63 +#define ICM42688_INT_CONFIG1 0x64 +#define ICM42688_INT_SOURCE0 0x65 +#define ICM42688_INT_SOURCE1 0x66 +#define ICM42688_INT_SOURCE3 0x68 +#define ICM42688_INT_SOURCE4 0x69 +#define ICM42688_FIFO_LOST_PKT0 0x6C +#define ICM42688_FIFO_LOST_PKT1 0x6D +#define ICM42688_SELF_TEST_CONFIG 0x70 +#define ICM42688_WHO_AM_I 0x75 +#define ICM42688_REG_BANK_SEL 0x76 // Bank 1 -#define ICM42688_SENSOR_CONFIG0 0x03 -#define ICM42688_GYRO_CONFIG_STATIC2 0x0B -#define ICM42688_GYRO_CONFIG_STATIC3 0x0C -#define ICM42688_GYRO_CONFIG_STATIC4 0x0D -#define ICM42688_GYRO_CONFIG_STATIC5 0x0E -#define ICM42688_GYRO_CONFIG_STATIC6 0x0F -#define ICM42688_GYRO_CONFIG_STATIC7 0x10 -#define ICM42688_GYRO_CONFIG_STATIC8 0x11 -#define ICM42688_GYRO_CONFIG_STATIC9 0x12 +#define ICM42688_SENSOR_CONFIG0 0x03 +#define ICM42688_GYRO_CONFIG_STATIC2 0x0B +#define ICM42688_GYRO_CONFIG_STATIC3 0x0C +#define ICM42688_GYRO_CONFIG_STATIC4 0x0D +#define ICM42688_GYRO_CONFIG_STATIC5 0x0E +#define ICM42688_GYRO_CONFIG_STATIC6 0x0F +#define ICM42688_GYRO_CONFIG_STATIC7 0x10 +#define ICM42688_GYRO_CONFIG_STATIC8 0x11 +#define ICM42688_GYRO_CONFIG_STATIC9 0x12 #define ICM42688_GYRO_CONFIG_STATIC10 0x13 -#define ICM42688_XG_ST_DATA 0x5F -#define ICM42688_YG_ST_DATA 0x60 -#define ICM42688_ZG_ST_DATA 0x61 -#define ICM42688_TMSTVAL0 0x62 -#define ICM42688_TMSTVAL1 0x63 -#define ICM42688_TMSTVAL2 0x64 -#define ICM42688_INTF_CONFIG4 0x7A -#define ICM42688_INTF_CONFIG5 0x7B -#define ICM42688_INTF_CONFIG6 0x7C +#define ICM42688_XG_ST_DATA 0x5F +#define ICM42688_YG_ST_DATA 0x60 +#define ICM42688_ZG_ST_DATA 0x61 +#define ICM42688_TMSTVAL0 0x62 +#define ICM42688_TMSTVAL1 0x63 +#define ICM42688_TMSTVAL2 0x64 +#define ICM42688_INTF_CONFIG4 0x7A +#define ICM42688_INTF_CONFIG5 0x7B +#define ICM42688_INTF_CONFIG6 0x7C // Bank 2 #define ICM42688_ACCEL_CONFIG_STATIC2 0x03 #define ICM42688_ACCEL_CONFIG_STATIC3 0x04 #define ICM42688_ACCEL_CONFIG_STATIC4 0x05 -#define ICM42688_XA_ST_DATA 0x3B -#define ICM42688_YA_ST_DATA 0x3C -#define ICM42688_ZA_ST_DATA 0x3D +#define ICM42688_XA_ST_DATA 0x3B +#define ICM42688_YA_ST_DATA 0x3C +#define ICM42688_ZA_ST_DATA 0x3D // Bank 4 -#define ICM42688_APEX_CONFIG1 0x40 -#define ICM42688_APEX_CONFIG2 0x41 -#define ICM42688_APEX_CONFIG3 0x42 -#define ICM42688_APEX_CONFIG4 0x43 -#define ICM42688_APEX_CONFIG5 0x44 -#define ICM42688_APEX_CONFIG6 0x45 -#define ICM42688_APEX_CONFIG7 0x46 -#define ICM42688_APEX_CONFIG8 0x47 -#define ICM42688_APEX_CONFIG9 0x48 +#define ICM42688_APEX_CONFIG1 0x40 +#define ICM42688_APEX_CONFIG2 0x41 +#define ICM42688_APEX_CONFIG3 0x42 +#define ICM42688_APEX_CONFIG4 0x43 +#define ICM42688_APEX_CONFIG5 0x44 +#define ICM42688_APEX_CONFIG6 0x45 +#define ICM42688_APEX_CONFIG7 0x46 +#define ICM42688_APEX_CONFIG8 0x47 +#define ICM42688_APEX_CONFIG9 0x48 #define ICM42688_ACCEL_WOM_X_THR 0x4A #define ICM42688_ACCEL_WOM_Y_THR 0x4B #define ICM42688_ACCEL_WOM_Z_THR 0x4C -#define ICM42688_INT_SOURCE6 0x4D -#define ICM42688_INT_SOURCE7 0x4E -#define ICM42688_INT_SOURCE8 0x4F -#define ICM42688_INT_SOURCE9 0x50 -#define ICM42688_INT_SOURCE10 0x51 -#define ICM42688_OFFSET_USER0 0x77 -#define ICM42688_OFFSET_USER1 0x78 -#define ICM42688_OFFSET_USER2 0x79 -#define ICM42688_OFFSET_USER3 0x7A -#define ICM42688_OFFSET_USER4 0x7B -#define ICM42688_OFFSET_USER5 0x7C -#define ICM42688_OFFSET_USER6 0x7D -#define ICM42688_OFFSET_USER7 0x7E -#define ICM42688_OFFSET_USER8 0x7F +#define ICM42688_INT_SOURCE6 0x4D +#define ICM42688_INT_SOURCE7 0x4E +#define ICM42688_INT_SOURCE8 0x4F +#define ICM42688_INT_SOURCE9 0x50 +#define ICM42688_INT_SOURCE10 0x51 +#define ICM42688_OFFSET_USER0 0x77 +#define ICM42688_OFFSET_USER1 0x78 +#define ICM42688_OFFSET_USER2 0x79 +#define ICM42688_OFFSET_USER3 0x7A +#define ICM42688_OFFSET_USER4 0x7B +#define ICM42688_OFFSET_USER5 0x7C +#define ICM42688_OFFSET_USER6 0x7D +#define ICM42688_OFFSET_USER7 0x7E +#define ICM42688_OFFSET_USER8 0x7F // PWR_MGMT0 -#define ICM42688_PWR_TEMP_ON (0 << 5) -#define ICM42688_PWR_TEMP_OFF (1 << 5) -#define ICM42688_PWR_IDLE (1 << 4) -#define ICM42688_PWR_GYRO_MODE_OFF (0 << 2) -#define ICM42688_PWR_GYRO_MODE_LN (3 << 2) +#define ICM42688_PWR_TEMP_ON (0 << 5) +#define ICM42688_PWR_TEMP_OFF (1 << 5) +#define ICM42688_PWR_IDLE (1 << 4) +#define ICM42688_PWR_GYRO_MODE_OFF (0 << 2) +#define ICM42688_PWR_GYRO_MODE_LN (3 << 2) #define ICM42688_PWR_ACCEL_MODE_OFF (0 << 0) -#define ICM42688_PWR_ACCEL_MODE_LP (2 << 0) -#define ICM42688_PWR_ACCEL_MODE_LN (3 << 0) +#define ICM42688_PWR_ACCEL_MODE_LP (2 << 0) +#define ICM42688_PWR_ACCEL_MODE_LN (3 << 0) // GYRO_CONFIG0 -#define ICM42688_GFS_2000DPS (0x00 << 5) -#define ICM42688_GFS_1000DPS (0x01 << 5) -#define ICM42688_GFS_500DPS (0x02 << 5) -#define ICM42688_GFS_250DPS (0x03 << 5) -#define ICM42688_GFS_125DPS (0x04 << 5) -#define ICM42688_GFS_62_5DPS (0x05 << 5) -#define ICM42688_GFS_31_25DPS (0x06 << 5) +#define ICM42688_GFS_2000DPS (0x00 << 5) +#define ICM42688_GFS_1000DPS (0x01 << 5) +#define ICM42688_GFS_500DPS (0x02 << 5) +#define ICM42688_GFS_250DPS (0x03 << 5) +#define ICM42688_GFS_125DPS (0x04 << 5) +#define ICM42688_GFS_62_5DPS (0x05 << 5) +#define ICM42688_GFS_31_25DPS (0x06 << 5) #define ICM42688_GFS_15_625DPS (0x07 << 5) -#define ICM42688_GODR_32kHz 0x01 -#define ICM42688_GODR_16kHz 0x02 -#define ICM42688_GODR_8kHz 0x03 -#define ICM42688_GODR_4kHz 0x04 -#define ICM42688_GODR_2kHz 0x05 -#define ICM42688_GODR_1kHz 0x06 -#define ICM42688_GODR_200Hz 0x07 -#define ICM42688_GODR_100Hz 0x08 -#define ICM42688_GODR_50Hz 0x09 -#define ICM42688_GODR_25Hz 0x0A +#define ICM42688_GODR_32kHz 0x01 +#define ICM42688_GODR_16kHz 0x02 +#define ICM42688_GODR_8kHz 0x03 +#define ICM42688_GODR_4kHz 0x04 +#define ICM42688_GODR_2kHz 0x05 +#define ICM42688_GODR_1kHz 0x06 +#define ICM42688_GODR_200Hz 0x07 +#define ICM42688_GODR_100Hz 0x08 +#define ICM42688_GODR_50Hz 0x09 +#define ICM42688_GODR_25Hz 0x0A #define ICM42688_GODR_12_5Hz 0x0B -#define ICM42688_GODR_500Hz 0x0F +#define ICM42688_GODR_500Hz 0x0F // ACCEL_CONFIG0 #define ICM42688_AFS_16G (0x00 << 5) -#define ICM42688_AFS_8G (0x01 << 5) -#define ICM42688_AFS_4G (0x02 << 5) -#define ICM42688_AFS_2G (0x03 << 5) +#define ICM42688_AFS_8G (0x01 << 5) +#define ICM42688_AFS_4G (0x02 << 5) +#define ICM42688_AFS_2G (0x03 << 5) -#define ICM42688_AODR_32kHz 0x01 -#define ICM42688_AODR_16kHz 0x02 -#define ICM42688_AODR_8kHz 0x03 -#define ICM42688_AODR_4kHz 0x04 -#define ICM42688_AODR_2kHz 0x05 -#define ICM42688_AODR_1kHz 0x06 -#define ICM42688_AODR_200Hz 0x07 -#define ICM42688_AODR_100Hz 0x08 -#define ICM42688_AODR_50Hz 0x09 -#define ICM42688_AODR_25Hz 0x0A -#define ICM42688_AODR_12_5Hz 0x0B -#define ICM42688_AODR_6_25Hz 0x0C -#define ICM42688_AODR_3_125Hz 0x0D +#define ICM42688_AODR_32kHz 0x01 +#define ICM42688_AODR_16kHz 0x02 +#define ICM42688_AODR_8kHz 0x03 +#define ICM42688_AODR_4kHz 0x04 +#define ICM42688_AODR_2kHz 0x05 +#define ICM42688_AODR_1kHz 0x06 +#define ICM42688_AODR_200Hz 0x07 +#define ICM42688_AODR_100Hz 0x08 +#define ICM42688_AODR_50Hz 0x09 +#define ICM42688_AODR_25Hz 0x0A +#define ICM42688_AODR_12_5Hz 0x0B +#define ICM42688_AODR_6_25Hz 0x0C +#define ICM42688_AODR_3_125Hz 0x0D #define ICM42688_AODR_1_5625Hz 0x0E -#define ICM42688_AODR_500Hz 0x0F +#define ICM42688_AODR_500Hz 0x0F diff --git a/applications/system/js_app/modules/js_vgm/imu.c b/applications/system/js_app/modules/js_vgm/imu.c index 2b4cd98b8d..eecab3f676 100644 --- a/applications/system/js_app/modules/js_vgm/imu.c +++ b/applications/system/js_app/modules/js_vgm/imu.c @@ -7,12 +7,12 @@ #define ACCEL_GYRO_RATE DataRate100Hz #define FILTER_SAMPLE_FREQ 100.f -#define FILTER_BETA 0.08f +#define FILTER_BETA 0.08f #define SAMPLE_RATE_DIV 5 #define SENSITIVITY_K 30.f -#define EXP_RATE 1.1f +#define EXP_RATE 1.1f #define IMU_CALI_AVG 64 @@ -325,4 +325,4 @@ float imu_roll_get(Imu* imu) { float imu_yaw_get(Imu* imu) { // we pretend that reading a float is an atomic operation return imu->thread->lefty ? -imu->thread->processed_data.yaw : imu->thread->processed_data.yaw; -} \ No newline at end of file +} diff --git a/applications/system/js_app/modules/js_vgm/imu.h b/applications/system/js_app/modules/js_vgm/imu.h index 42a08fe0cd..5dba452419 100644 --- a/applications/system/js_app/modules/js_vgm/imu.h +++ b/applications/system/js_app/modules/js_vgm/imu.h @@ -12,4 +12,4 @@ float imu_pitch_get(Imu* imu); float imu_roll_get(Imu* imu); -float imu_yaw_get(Imu* imu); \ No newline at end of file +float imu_yaw_get(Imu* imu); diff --git a/applications/system/js_app/modules/js_widget.c b/applications/system/js_app/modules/js_widget.c index 69279bb7c7..0d6aeb1dba 100644 --- a/applications/system/js_app/modules/js_widget.c +++ b/applications/system/js_app/modules/js_widget.c @@ -1,6 +1,5 @@ #include -#include -#include +#include #include #include #include @@ -113,8 +112,8 @@ typedef struct { typedef struct { View* view; - ViewDispatcher* view_dispatcher; - FuriThread* thread; + ViewHolder* view_holder; + bool is_shown; } JsWidgetInst; static JsWidgetInst* get_this_ctx(struct mjs* mjs) { @@ -754,60 +753,34 @@ static void js_widget_is_open(struct mjs* mjs) { JsWidgetInst* widget = get_this_ctx(mjs); if(!check_arg_count(mjs, 0)) return; - mjs_return(mjs, mjs_mk_boolean(mjs, !!widget->thread)); -} - -static void widget_deinit(void* context) { - JsWidgetInst* widget = context; - if(widget->thread) { - furi_thread_join(widget->thread); - furi_thread_free(widget->thread); - widget->thread = NULL; - - furi_assert(widget->view_dispatcher); - view_dispatcher_remove_view(widget->view_dispatcher, 0); - view_dispatcher_free(widget->view_dispatcher); - widget->view_dispatcher = NULL; - - furi_record_close(RECORD_GUI); - } + mjs_return(mjs, mjs_mk_boolean(mjs, widget->is_shown)); } static void widget_callback(void* context, uint32_t arg) { UNUSED(arg); - widget_deinit(context); + JsWidgetInst* widget = context; + view_holder_stop(widget->view_holder); + widget->is_shown = false; } -static bool widget_exit(void* context) { +static void widget_exit(void* context) { JsWidgetInst* widget = context; - view_dispatcher_stop(widget->view_dispatcher); + // Using timer to schedule view_holder stop, will not work under high CPU load furi_timer_pending_callback(widget_callback, widget, 0); - return true; -} - -static int32_t widget_thread(void* context) { - ViewDispatcher* view_dispatcher = context; - view_dispatcher_run(view_dispatcher); - return 0; } static void js_widget_show(struct mjs* mjs) { JsWidgetInst* widget = get_this_ctx(mjs); if(!check_arg_count(mjs, 0)) return; - Gui* gui = furi_record_open(RECORD_GUI); - - widget->view_dispatcher = view_dispatcher_alloc(); - view_dispatcher_enable_queue(widget->view_dispatcher); - view_dispatcher_add_view(widget->view_dispatcher, 0, widget->view); - view_dispatcher_set_event_callback_context(widget->view_dispatcher, widget); - view_dispatcher_set_navigation_event_callback(widget->view_dispatcher, widget_exit); - view_dispatcher_attach_to_gui(widget->view_dispatcher, gui, ViewDispatcherTypeFullscreen); - view_dispatcher_switch_to_view(widget->view_dispatcher, 0); + if(widget->is_shown) { + mjs_prepend_errorf(mjs, MJS_INTERNAL_ERROR, "Widget is already shown"); + mjs_return(mjs, MJS_UNDEFINED); + return; + } - widget->thread = - furi_thread_alloc_ex("JsWidget", 1024, widget_thread, widget->view_dispatcher); - furi_thread_start(widget->thread); + view_holder_start(widget->view_holder); + widget->is_shown = true; mjs_return(mjs, MJS_UNDEFINED); } @@ -816,10 +789,8 @@ static void js_widget_close(struct mjs* mjs) { JsWidgetInst* widget = get_this_ctx(mjs); if(!check_arg_count(mjs, 0)) return; - if(widget->thread) { - view_dispatcher_stop(widget->view_dispatcher); - widget_deinit(widget); - } + view_holder_stop(widget->view_holder); + widget->is_shown = false; mjs_return(mjs, MJS_UNDEFINED); } @@ -839,57 +810,9 @@ static void widget_draw_callback(Canvas* canvas, void* model) { } } -static void widget_remove_view(void* context) { - JsWidgetInst* widget = context; - - if(widget->view) { - with_view_model( - widget->view, - WidgetModel * model, - { - ComponentArray_it_t it; - ComponentArray_it(it, model->component); - while(!ComponentArray_end_p(it)) { - WidgetComponent* component = *ComponentArray_ref(it); - if(component && component->free) { - component->free(component); - } - ComponentArray_next(it); - } - ComponentArray_reset(model->component); - ComponentArray_clear(model->component); - }, - false); - with_view_model( - widget->view, WidgetModel * model, { XbmImageList_clear(model->image); }, false); - view_free(widget->view); - widget->view = NULL; - } -} - -static JsWidgetInst* widget_alloc(void) { +static void* js_widget_create(struct mjs* mjs, mjs_val_t* object) { JsWidgetInst* widget = malloc(sizeof(JsWidgetInst)); - widget->thread = NULL; - widget->view_dispatcher = NULL; - - widget->view = view_alloc(); - view_allocate_model(widget->view, ViewModelTypeLockFree, sizeof(WidgetModel)); - view_set_draw_callback(widget->view, widget_draw_callback); - with_view_model( - widget->view, - WidgetModel * model, - { - ComponentArray_init(model->component); - XbmImageList_init(model->image); - model->max_assigned_id = 0; - }, - true); - return widget; -} - -static void* js_widget_create(struct mjs* mjs, mjs_val_t* object) { - JsWidgetInst* widget = widget_alloc(); mjs_val_t widget_obj = mjs_mk_object(mjs); mjs_set(mjs, widget_obj, INST_PROP_NAME, ~0, mjs_mk_foreign(mjs, widget)); // addBox(x: number, y: number, w: number, h: number): number (returns id of the added component) @@ -924,17 +847,60 @@ static void* js_widget_create(struct mjs* mjs, mjs_val_t* object) { mjs_set(mjs, widget_obj, "show", ~0, MJS_MK_FN(js_widget_show)); // close(): void (closes the widget) mjs_set(mjs, widget_obj, "close", ~0, MJS_MK_FN(js_widget_close)); + + widget->view = view_alloc(); + view_allocate_model(widget->view, ViewModelTypeLockFree, sizeof(WidgetModel)); + view_set_draw_callback(widget->view, widget_draw_callback); + with_view_model( + widget->view, + WidgetModel * model, + { + ComponentArray_init(model->component); + XbmImageList_init(model->image); + model->max_assigned_id = 0; + }, + true); + + Gui* gui = furi_record_open(RECORD_GUI); + widget->view_holder = view_holder_alloc(); + view_holder_attach_to_gui(widget->view_holder, gui); + view_holder_set_back_callback(widget->view_holder, widget_exit, widget); + view_holder_set_view(widget->view_holder, widget->view); + *object = widget_obj; return widget; } static void js_widget_destroy(void* inst) { JsWidgetInst* widget = inst; - if(widget->thread) { - view_dispatcher_stop(widget->view_dispatcher); - widget_deinit(widget); - } - widget_remove_view(widget); + + view_holder_stop(widget->view_holder); + view_holder_free(widget->view_holder); + widget->view_holder = NULL; + + furi_record_close(RECORD_GUI); + + with_view_model( + widget->view, + WidgetModel * model, + { + ComponentArray_it_t it; + ComponentArray_it(it, model->component); + while(!ComponentArray_end_p(it)) { + WidgetComponent* component = *ComponentArray_ref(it); + if(component && component->free) { + component->free(component); + } + ComponentArray_next(it); + } + ComponentArray_reset(model->component); + ComponentArray_clear(model->component); + XbmImageList_clear(model->image); + }, + false); + view_free(widget->view); + widget->view = NULL; + free(widget); } 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 d0db44c4aa..be4f78930d 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 4918605876..a817d34a90 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 b87e535284..67f5d9de87 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 bc587f3eb6..44e73c6895 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 @@ -18,7 +18,7 @@ static bool storage_move_to_sd_check_entry(const char* name, FileInfo* fileinfo, return true; } - return (name && (*name != '.')); + return name && (*name != '.'); } static void storage_move_to_sd_remove_region() { diff --git a/applications/system/updater/util/update_task.c b/applications/system/updater/util/update_task.c index c0ea6421c5..0eae0eaf52 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 a3c47429ec..52bdfdbd23 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 1b664e57e4..e2663c97da 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 ef4276fac5..8d5039a16d 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 0c7881e63d..848cc54942 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( 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 0000000000..b937cc0860 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 0000000000..a3b494dda4 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 0000000000..b8163164b2 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 0000000000..e685ff86aa 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 0000000000..10a52400b0 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 0000000000..9cdea5002f 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 0000000000..590d0bf891 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 0000000000..97cf05dd07 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 0000000000..e2bae209f1 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 0000000000..63db9fa0e2 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 0000000000..ad66f34efc 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 0000000000..213fb76369 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 0000000000..81174f7fa8 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 0000000000..7f4ce3bacc 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 0000000000..dc90311fed 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 0000000000..cda17cb609 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 0000000000..7a048dbaee 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 0000000000..c5a80a9255 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 0000000000..e80fdfb005 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 0000000000..b3955ac8a9 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 0000000000..4b003d0349 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 0000000000..df2008d932 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 0000000000..c0afacdfa2 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 0000000000..97c138235c 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 0000000000..6f693de4f3 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 0000000000..c971b21783 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 0000000000..856c845571 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 0000000000..7e99a4a820 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 0000000000..949d845d45 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 0000000000..ee7be1409a 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 0000000000..ae6fca1cdc 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 0000000000..2567cf087d 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 0000000000..b3d0c7acfb 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 0000000000..dd98cfcbd8 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 0000000000..0f81cd5dcd 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 0000000000..8e55dd9edf 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 0000000000..459f0c8e65 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 0000000000..3c09559931 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 0000000000..32d4eb4f1a 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 0000000000..11bd640ae9 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 0000000000..27af626e8a 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 0000000000..cfc81bd3f3 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 0000000000..f9480b1e38 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 0000000000..6793a3df6e 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 0000000000..6b58a0fa78 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 0000000000..cb62bb7b35 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 0000000000..8b5ab6a9b6 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 0000000000..9a2c6b1509 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 0000000000..f7da1b5875 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 0000000000..d8e390bb59 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 0000000000..8dfe5defe0 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 0000000000..fae299733c 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 0000000000..2d111a7a17 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 0000000000..4c8a9d2e5d 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 0000000000..aa0d1e6a77 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 0000000000..9f2d03b7ef 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 0000000000..435b2da4a5 --- /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 70b2b7159e..d6399f8fc4 100644 --- a/assets/dolphin/external/manifest.txt +++ b/assets/dolphin/external/manifest.txt @@ -188,14 +188,21 @@ 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 Name: L3_Fireplace_128x64 Min butthurt: 0 diff --git a/assets/icons/About/Certification1_103x56.png b/assets/icons/About/Certification1_103x56.png deleted file mode 100644 index 6e11bbbb22..0000000000 Binary files a/assets/icons/About/Certification1_103x56.png and /dev/null differ diff --git a/assets/icons/About/Certification2_46x33.png b/assets/icons/About/Certification2_46x33.png deleted file mode 100644 index d421b82914..0000000000 Binary files a/assets/icons/About/Certification2_46x33.png and /dev/null differ diff --git a/assets/slideshow/update_default/frame_01.png b/assets/slideshow/update_default/frame_01.png index ea37077ccd..0be99436a3 100644 Binary files a/assets/slideshow/update_default/frame_01.png and b/assets/slideshow/update_default/frame_01.png differ diff --git a/assets/slideshow/update_default/frame_02.png b/assets/slideshow/update_default/frame_02.png index db97109225..ea37077ccd 100644 Binary files a/assets/slideshow/update_default/frame_02.png and b/assets/slideshow/update_default/frame_02.png differ diff --git a/assets/slideshow/update_default/frame_03.png b/assets/slideshow/update_default/frame_03.png new file mode 100644 index 0000000000..db97109225 Binary files /dev/null and b/assets/slideshow/update_default/frame_03.png differ diff --git a/documentation/OTA.md b/documentation/OTA.md index 9028eff714..0456eab1f9 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/file_formats/TarHeatshrinkFormat.md b/documentation/file_formats/TarHeatshrinkFormat.md new file mode 100644 index 0000000000..86c27a698e --- /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 28372e56a4..78c49104ca 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 5804b075eb..eb027e6a73 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 0000000000..296f01c62d --- /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 cd9993a181..9d7938044d 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 0000000000..580a43bd5c --- /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 0000000000..61652df1a6 --- /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 e1cece7f5f..8fbd78faa8 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 92a52a7978..e89065a7d5 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 a51d7b41ea..a2b7dd18e4 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 0f6230c19f..20883332b0 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 732a90cb52..fa56150ce1 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 3bef2be38e..32797ee000 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 c2e04e2fda..f89c4e77ff 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 b939695dde..26401c84b2 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 7221a90bca..9ae9f6c4dd 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 8ddd10966f..cd10148673 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 0000000000..5c0b144a1b --- /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 0000000000..b81c489330 --- /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 0000000000..8936e38282 --- /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 0000000000..03b6c51323 --- /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 0000000000..9034043faf --- /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 0000000000..9c6f90cca2 --- /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 52c0e285ee..f3f84e692e 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 3ce88db5b2..817d9dda35 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 ba9a7336a9..d3ff873ae5 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 3827ddde34..359d0e3dba 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 cda775abe9..3521ceb30b 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 aa24cfe54f..a88d04131a 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 879520010a..ef8869dea0 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 324135e96d..bcdf9336c7 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 4e9477712a..c47df55e49 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 9c113bd494..be09e040ea 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 65ee11ad38..5355a896ca 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 bf15e4032b..d01aa24a04 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 400cf1d643..80ee30457c 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/SConscript b/lib/SConscript index 8125739325..f331198a42 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 bcdf0b4641..580346c8c0 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 171115e15b..3453c12f3a 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 052eca7316..eb43109584 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 0f399385ab..579a0189d9 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 8c48fcf747..ccd3c0fd39 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 8b74ea3add..f6c56a9110 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 8122b1cc45..c00cfaca33 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 7d23cf0636..b8cc092c81 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 ba4222560f..0000000000 --- a/lib/cxxheaderparser +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ba4222560fc1040670b1a917d5d357198e8ec5d6 diff --git a/lib/datetime/datetime.c b/lib/datetime/datetime.c index 9c2194d968..4429312628 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 24dddb77de..f93ce6d951 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 585250c261..dd8600a401 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 e473c80c09..71a28021c8 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 1f3824e2dc..740d6ae981 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 735a88f57a..43066b5bf0 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 a6ca3e1c77..23d094003a 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 ca9e0312e8..fc76e318f8 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 ae00be8836..30f2dae1ec 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 2e6e54aabe..1c1ec9d8f9 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 b71d78ff0a..40b286a9b8 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 e0aed6bd93..aaf9062a85 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 e65cc2afee..9103e5395f 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 532239f472..0e77b63172 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 76a8827557..f7a47d4633 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 8a924fc392..5163c4423f 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 405b819a76..b9d33169c9 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 84fcccd71c..ecd5f9a0dc 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 f86e43d99c..d8017ca839 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 b020a218d7..a275dda0a8 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 7ce12f7a06..e9e655717a 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 90fec3e28a..3df0e1c96f 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 6d147d28d3..64920f6ace 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 483d9827f0..0b6cd4fca2 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 157dc601a1..d78a303f86 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 e43d0c6adb..2f9f8bc74f 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 6d5e0339d6..26e5cd1d71 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 377ce0ef27..cc652c88c8 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 bee116c4d1..c3ad3f1f60 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 05df1f474e..56a6607eb2 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 2ff7f7e3a0..791242a3aa 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 b906c369e0..551163e0c4 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 06aa2a6a51..efa3071f43 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 9ec4fe3b17..b628735c87 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 b853849429..ceb082e228 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 e38be9bc86..e37b984691 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 89f351eb92..cc9361ccf1 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 367150812b..11e812fdbf 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 077bb0ba13..8be9e60b47 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 441cf7333b..c0aac71bed 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 7c04b9dfad..bef30506b5 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 e145dcaa34..7bfe25cab6 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 9554957f1e..96f0c1f23b 100644 --- a/lib/lfrfid/lfrfid_worker.c +++ b/lib/lfrfid/lfrfid_worker.c @@ -155,7 +155,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 b0ed990962..d0569b3006 100644 --- a/lib/lfrfid/lfrfid_worker_modes.c +++ b/lib/lfrfid/lfrfid_worker_modes.c @@ -19,23 +19,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 @@ -52,7 +52,8 @@ void lfrfid_worker_delay(LFRFIDWorker* worker, uint32_t milliseconds) { void t5577_trace(LFRFIDT5577 t5577, const char* message) { if(furi_log_get_level() == FuriLogLevelTrace) { FURI_LOG_T(TAG, "%s", message); - for(uint8_t i = 0; i < 8; i++) FURI_LOG_T(TAG, "\nBlock %u %08lX", i, t5577.block[i]); + for(uint8_t i = 0; i < 8; i++) + FURI_LOG_T(TAG, "\nBlock %u %08lX", i, t5577.block[i]); FURI_LOG_T(TAG, "Mask: %u", t5577.mask); FURI_LOG_T(TAG, "Blocks to write: %lu", t5577.blocks_to_write); } diff --git a/lib/lfrfid/protocols/protocol_awid.c b/lib/lfrfid/protocols/protocol_awid.c index b3e92245e4..299e5cab5e 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 51a4ea52f5..4e694a37d4 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 29223a43d6..25fcdc5141 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 2c9f79285f..b5aef5a073 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 08b4ec9e04..e68bc0e2e4 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,18 +341,19 @@ 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; furi_string_printf( result, - "FC: %03u\n" - "Card: %05hu (RF/%hhu)", + "FC: %03u Card: %05hu CL:%hhu\n" + "DEZ 8: %08lu", data[2], (uint16_t)((data[3] << 8) | (data[4])), - protocol->clock_per_bit); -}; + protocol->clock_per_bit, + (uint32_t)((data[2] << 16) | (data[3] << 8) | (data[4]))); +} 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 f7852eb101..9849a39b60 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 355544881c..6eafb00557 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 a5af855e48..3de2b661b3 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 549c862e38..78a171db4e 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 b00c14acd1..9ae0cf80ac 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 2d922f605e..f9fef9ea07 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 6c6d5771ac..66f1c617db 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 b7ee5ad57d..03073308eb 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 efc7a5190c..936a194b87 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 9c4ddffff3..34877b8a33 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 1a95288855..b7d58d6fd7 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 22e78a4d34..4ffa5dabbb 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 2075576bae..0fb654597d 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 893361abb2..d0a711daad 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 b41cb66f3d..bce4e817dc 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 c2cbb41744..643bb1be68 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 4de57de42a..08b96c20bd 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 2cc7e8cdfc..666369dce9 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 3df83be7ac..a794a4a8e4 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 4eabe36592..4d4c58e99c 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 3ca329cf79..322a6c95f9 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 bb52f0529c..f04b581130 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 a80696c35a..7c0bf56927 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 8711fe13a0..cab217d146 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 81536b7711..a4bfeca60f 100644 --- a/lib/lfrfid/protocols/protocol_securakey.c +++ b/lib/lfrfid/protocols/protocol_securakey.c @@ -11,28 +11,29 @@ #include #define TAG "SECURAKEY" + #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) +#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]; @@ -47,15 +48,15 @@ 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 19 bits preamble + format flag @@ -71,7 +72,7 @@ static bool protocol_securakey_can_be_decoded(ProtocolSecurakey* protocol) { } else { return false; } -}; +} static void protocol_securakey_decode(ProtocolSecurakey* protocol) { memset(protocol->data, 0, SECURAKEY_DECODED_DATA_SIZE_BYTES); @@ -142,7 +143,7 @@ static void protocol_securakey_decode(ProtocolSecurakey* protocol) { // 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) { // always takes in encoded data as RKKT for simplicity @@ -153,7 +154,7 @@ void protocol_securakey_decoder_start(ProtocolSecurakey* protocol) { ManchesterEventReset, &protocol->decoder_manchester_state, NULL); -}; +} bool protocol_securakey_decoder_feed(ProtocolSecurakey* protocol, bool level, uint32_t duration) { bool result = false; @@ -187,7 +188,7 @@ 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_16(protocol->data, 0, 16) == 0) { @@ -209,7 +210,7 @@ void protocol_securakey_render_data(ProtocolSecurakey* protocol, FuriString* res 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. @@ -277,7 +278,7 @@ bool protocol_securakey_encoder_start(ProtocolSecurakey* protocol) { protocol->encoded_data_index = 0; protocol->encoded_polarity = true; return true; -}; +} LevelDuration protocol_securakey_encoder_yield(ProtocolSecurakey* protocol) { if(bit_lib_get_bits_16(protocol->data, 0, 16) == 0) { @@ -305,7 +306,7 @@ LevelDuration protocol_securakey_encoder_yield(ProtocolSecurakey* protocol) { } return level_duration_make(level, duration); } -}; +} bool protocol_securakey_write_data(ProtocolSecurakey* protocol, void* data) { protocol_securakey_encoder_start(protocol); @@ -337,7 +338,7 @@ bool protocol_securakey_write_data(ProtocolSecurakey* protocol, void* data) { } } return result; -}; +} const ProtocolBase protocol_securakey = { .name = "Radio Key", @@ -361,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 ad990f119c..4af153e3dd 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 4989e4e681..78499a4158 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 1fd46cf179..a71e24aac7 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 ed7d436c85..048f090ab8 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 483762ff61..7f2d286269 100644 --- a/lib/lfrfid/tools/t5577.c +++ b/lib/lfrfid/tools/t5577.c @@ -6,13 +6,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 f7b5cc4f5a..026e7290bb 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 12697a7a6a..4567e2d04a 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 3225134b70..ce91f60295 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 afc499f9a4..6cfe48d6f1 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 938d2765a3..bd4fc8d619 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 bba7cee346..e1b4fc2873 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 c1affba468..3837382e39 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 d53aef64f4..d524c267c7 100644 --- a/lib/nfc/helpers/iso14443_4_layer.c +++ b/lib/nfc/helpers/iso14443_4_layer.c @@ -2,21 +2,21 @@ #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) -#define ISO14443_4_BLOCK_PCB_I_ (0U << 6) -#define ISO14443_4_BLOCK_PCB_R_ (2U << 6) +#define ISO14443_4_BLOCK_PCB_I_ (0U << 6) +#define ISO14443_4_BLOCK_PCB_R_ (2U << 6) #define ISO14443_4_BLOCK_PCB_TYPE_MASK (3U << 6) -#define ISO14443_4_BLOCK_PCB_S_DESELECT (0U << 4) -#define ISO14443_4_BLOCK_PCB_S_WTX (3U << 4) +#define ISO14443_4_BLOCK_PCB_S_DESELECT (0U << 4) +#define ISO14443_4_BLOCK_PCB_S_WTX (3U << 4) #define ISO14443_4_BLOCK_PCB_BLOCK_NUMBER (1U << 0) -#define ISO14443_4_BLOCK_PCB_NAD (1U << 2) -#define ISO14443_4_BLOCK_PCB_CID (1U << 3) +#define ISO14443_4_BLOCK_PCB_NAD (1U << 2) +#define ISO14443_4_BLOCK_PCB_CID (1U << 3) #define ISO14443_4_BLOCK_PCB_CHAINING (1U << 4) struct Iso14443_4Layer { diff --git a/lib/nfc/helpers/iso14443_crc.c b/lib/nfc/helpers/iso14443_crc.c index 33789bd71f..88d5f41d24 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 31ade8fc7a..f502b4bfb4 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 c3cccf697d..1da6e307aa 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 9f95dfc151..463b2df1aa 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 114ff36951..2fe50b3fc5 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/emv/emv.c b/lib/nfc/protocols/emv/emv.c index cfdad3c6e3..1b572e66dc 100644 --- a/lib/nfc/protocols/emv/emv.c +++ b/lib/nfc/protocols/emv/emv.c @@ -213,4 +213,4 @@ Iso14443_4aData* emv_get_base_data(const EmvData* data) { furi_assert(data); return data->iso14443_4a_data; -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/emv/emv.h b/lib/nfc/protocols/emv/emv.h index 638e93ddc2..79a22ade14 100644 --- a/lib/nfc/protocols/emv/emv.h +++ b/lib/nfc/protocols/emv/emv.h @@ -12,44 +12,44 @@ extern "C" { #define UNKNOWN_TAG 0x0B -#define EMV_TAG_AID 0x4F -#define EMV_TAG_PRIORITY 0x87 +#define EMV_TAG_AID 0x4F +#define EMV_TAG_PRIORITY 0x87 #define EMV_TAG_APPL_INTERCHANGE_PROFILE 0x82 -#define EMV_TAG_PDOL 0x9F38 -#define EMV_TAG_APPL_LABEL 0x50 -#define EMV_TAG_APPL_NAME 0x9F12 -#define EMV_TAG_APPL_EFFECTIVE 0x5F25 -#define EMV_TAG_PIN_TRY_COUNTER 0x9F17 -#define EMV_TAG_LOG_ENTRY 0x9F4D -#define EMV_TAG_LOG_FMT 0x9F4F +#define EMV_TAG_PDOL 0x9F38 +#define EMV_TAG_APPL_LABEL 0x50 +#define EMV_TAG_APPL_NAME 0x9F12 +#define EMV_TAG_APPL_EFFECTIVE 0x5F25 +#define EMV_TAG_PIN_TRY_COUNTER 0x9F17 +#define EMV_TAG_LOG_ENTRY 0x9F4D +#define EMV_TAG_LOG_FMT 0x9F4F #define EMV_TAG_LAST_ONLINE_ATC 0x9F13 -#define EMV_TAG_ATC 0x9F36 -#define EMV_TAG_LOG_AMOUNT 0x9F02 -#define EMV_TAG_LOG_COUNTRY 0x9F1A -#define EMV_TAG_LOG_CURRENCY 0x5F2A -#define EMV_TAG_LOG_DATE 0x9A -#define EMV_TAG_LOG_TIME 0x9F21 - -#define EMV_TAG_TRACK_1_EQUIV 0x56 -#define EMV_TAG_TRACK_2_EQUIV 0x57 -#define EMV_TAG_PAN 0x5A -#define EMV_TAG_AFL 0x94 -#define EMV_TAG_EXP_DATE 0x5F24 -#define EMV_TAG_COUNTRY_CODE 0x5F28 -#define EMV_TAG_CURRENCY_CODE 0x9F42 -#define EMV_TAG_CARDHOLDER_NAME 0x5F20 +#define EMV_TAG_ATC 0x9F36 +#define EMV_TAG_LOG_AMOUNT 0x9F02 +#define EMV_TAG_LOG_COUNTRY 0x9F1A +#define EMV_TAG_LOG_CURRENCY 0x5F2A +#define EMV_TAG_LOG_DATE 0x9A +#define EMV_TAG_LOG_TIME 0x9F21 + +#define EMV_TAG_TRACK_1_EQUIV 0x56 +#define EMV_TAG_TRACK_2_EQUIV 0x57 +#define EMV_TAG_PAN 0x5A +#define EMV_TAG_AFL 0x94 +#define EMV_TAG_EXP_DATE 0x5F24 +#define EMV_TAG_COUNTRY_CODE 0x5F28 +#define EMV_TAG_CURRENCY_CODE 0x9F42 +#define EMV_TAG_CARDHOLDER_NAME 0x5F20 #define EMV_TAG_CARDHOLDER_NAME_EXTENDED 0x9F0B -#define EMV_TAG_TRACK_2_DATA 0x9F6B -#define EMV_TAG_GPO_FMT1 0x80 +#define EMV_TAG_TRACK_2_DATA 0x9F6B +#define EMV_TAG_GPO_FMT1 0x80 -#define EMV_TAG_RESP_BUF_SIZE 0x6C +#define EMV_TAG_RESP_BUF_SIZE 0x6C #define EMV_TAG_RESP_BYTES_AVAILABLE 0x61 // Not used tags -#define EMV_TAG_FORM_FACTOR 0x9F6E -#define EMV_TAG_APP_TEMPLATE 0x61 -#define EMV_TAG_FCI 0xBF0C +#define EMV_TAG_FORM_FACTOR 0x9F6E +#define EMV_TAG_APP_TEMPLATE 0x61 +#define EMV_TAG_FCI 0xBF0C #define EMV_TAG_DEPOSIT_LOG_ENTRY 0xDF4D typedef struct { diff --git a/lib/nfc/protocols/emv/emv_poller.c b/lib/nfc/protocols/emv/emv_poller.c index 3042352fed..42c9c513c3 100644 --- a/lib/nfc/protocols/emv/emv_poller.c +++ b/lib/nfc/protocols/emv/emv_poller.c @@ -203,4 +203,4 @@ const NfcPollerBase emv_poller = { .run = (NfcPollerRun)emv_poller_run, .detect = (NfcPollerDetect)emv_poller_detect, .get_data = (NfcPollerGetData)emv_poller_get_data, -}; \ No newline at end of file +}; diff --git a/lib/nfc/protocols/emv/emv_poller.h b/lib/nfc/protocols/emv/emv_poller.h index 9cae801955..9cc632a0fa 100644 --- a/lib/nfc/protocols/emv/emv_poller.h +++ b/lib/nfc/protocols/emv/emv_poller.h @@ -56,4 +56,4 @@ EmvError emv_poller_get_last_online_atc(EmvPoller* instance); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/nfc/protocols/emv/emv_poller_defs.h b/lib/nfc/protocols/emv/emv_poller_defs.h index 001910112f..4c9bf692d5 100644 --- a/lib/nfc/protocols/emv/emv_poller_defs.h +++ b/lib/nfc/protocols/emv/emv_poller_defs.h @@ -2,4 +2,4 @@ #include -extern const NfcPollerBase emv_poller; \ No newline at end of file +extern const NfcPollerBase emv_poller; diff --git a/lib/nfc/protocols/felica/felica.c b/lib/nfc/protocols/felica/felica.c index 89e610f86a..e9ffb771ac 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 17229c150a..7b9c78e079 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 90215eced2..d019eb21db 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 d210befa57..a7cbbe38c4 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 caab11778f..b3ae24635d 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 43c03a608e..0ea144249b 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 9857d96d60..df205ba67e 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 f20ff08e19..ec73227f5e 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 96e30e5c8d..fc527a59c3 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 714c1dadaf..0a8bd2413b 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 46501503ce..33320f492f 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 664d54598e..29a8c29b50 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 52ba7e8456..2bbc655646 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 c2dc7e5a06..caae5f0c92 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 f4ff36bd7e..01e9a914bf 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 756c350848..cdef65a254 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 e5483a6ba1..9b0230975d 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 beda704c26..02d78fba5e 100644 --- a/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c +++ b/lib/nfc/protocols/iso14443_4a/iso14443_4a_poller_i.c @@ -6,12 +6,12 @@ #define TAG "Iso14443_4aPoller" -#define ISO14443_4A_FSDI_256 (0x8U) +#define ISO14443_4A_FSDI_256 (0x8U) #define ISO14443_4A_SEND_BLOCK_MAX_ATTEMPTS (20) -#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_FWT_MAX (4096UL << 14) +#define ISO14443_4A_WTXM_MASK (0x3FU) +#define ISO14443_4A_WTXM_MAX (0x3BU) +#define ISO14443_4A_SWTX (0xF2U) Iso14443_4aError iso14443_4a_poller_halt(Iso14443_4aPoller* instance) { furi_check(instance); @@ -163,4 +163,4 @@ Iso14443_4aError iso14443_4a_poller_send_block_pwt_ext( } while(true); return error; -} \ No newline at end of file +} diff --git a/lib/nfc/protocols/iso14443_4b/iso14443_4b.c b/lib/nfc/protocols/iso14443_4b/iso14443_4b.c index 6f849b1d46..2e72eced8d 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 d322cd5d94..04a9b34120 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 1120ac56e8..fdff7112b3 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 5fee3eb7b4..4f92201e34 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 b42e09ab1d..801ec1764d 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 2818e9a24e..dd2009276b 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 bfbbadadff..d83a91ad1a 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 21250baace..921bbb9ded 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 fa8a7ae9b9..bd8ecfaeed 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 32d8d6c599..1d00594c64 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 31559ffdc8..b68c3279e0 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 13bf8c5d8d..4ad2ff8784 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 c93ec9e67c..8d1cc1c99a 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 7e892366fa..1e4e97eaf1 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 1f3481c178..d1f08294fe 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 582e9e0e26..caf25ceeeb 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 5bef2a354c..050f9abc1a 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 64647492de..f38badae64 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 ba448d0879..c43658eddb 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 52b445859e..0e5ff00116 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 2343be089b..e500173244 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 cc3433f731..141ab6c46d 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 3f8645fe73..b35c49aeaf 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 157e2bdef7..9958dc50de 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 f6ce885d4b..7a60682304 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 cc2390c6ee..2a32224457 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 4a15b50ff4..c8830f31b3 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 8b1e9be2e9..e5a8c1cc0e 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 67d733315f..cda6c570f3 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 359435034e..c8f82c8ff8 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 ecd994b398..78c5ab91ef 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 9383e0f15d..f3f3d953ed 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 8dfbe4aa58..36edc620f8 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 819e60bf07..07be8d890e 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 54f192a609..387a6451e2 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 b248aeb3df..c8d72d1928 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 7c0d1f92eb..3cec88249a 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 62c5f2fa46..a4383b4c61 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 c5326a354d..a2c6912e63 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 8df2d5c72a..97d56435c1 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 64a060d91f..133182d558 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 f32334e2f4..e73b1a5594 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/custom_btn.h b/lib/subghz/blocks/custom_btn.h index 8473fa8c27..67f10a08dc 100644 --- a/lib/subghz/blocks/custom_btn.h +++ b/lib/subghz/blocks/custom_btn.h @@ -9,10 +9,10 @@ extern "C" { #endif // Default btn ID -#define SUBGHZ_CUSTOM_BTN_OK (0U) -#define SUBGHZ_CUSTOM_BTN_UP (1U) -#define SUBGHZ_CUSTOM_BTN_DOWN (2U) -#define SUBGHZ_CUSTOM_BTN_LEFT (3U) +#define SUBGHZ_CUSTOM_BTN_OK (0U) +#define SUBGHZ_CUSTOM_BTN_UP (1U) +#define SUBGHZ_CUSTOM_BTN_DOWN (2U) +#define SUBGHZ_CUSTOM_BTN_LEFT (3U) #define SUBGHZ_CUSTOM_BTN_RIGHT (4U) bool subghz_custom_btn_set(uint8_t btn_id); @@ -27,4 +27,4 @@ bool subghz_custom_btn_is_allowed(void); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/subghz/blocks/custom_btn_i.h b/lib/subghz/blocks/custom_btn_i.h index b800d7079b..3c3b590f65 100644 --- a/lib/subghz/blocks/custom_btn_i.h +++ b/lib/subghz/blocks/custom_btn_i.h @@ -2,10 +2,10 @@ #include "custom_btn.h" -#define PROG_MODE_OFF (0U) -#define PROG_MODE_KEELOQ_BFT (1U) +#define PROG_MODE_OFF (0U) +#define PROG_MODE_KEELOQ_BFT (1U) #define PROG_MODE_KEELOQ_APRIMATIC (2U) -#define PROG_MODE_KEELOQ_DEA_MIO (3U) +#define PROG_MODE_KEELOQ_DEA_MIO (3U) typedef uint8_t ProgMode; diff --git a/lib/subghz/blocks/decoder.h b/lib/subghz/blocks/decoder.h index a5e561e351..4323dae09a 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 aeaa2add02..71710fa14d 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 f11178c633..b659e79478 100644 --- a/lib/subghz/blocks/generic.c +++ b/lib/subghz/blocks/generic.c @@ -160,4 +160,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 10e7b63fab..77aaf3a034 100644 --- a/lib/subghz/blocks/generic.h +++ b/lib/subghz/blocks/generic.h @@ -69,4 +69,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 24202ad1c6..226bb3e746 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 dcea3da5fa..bee1bf7330 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.c b/lib/subghz/devices/cc1101_configs.c index 6b5b9f1f76..a758425899 100644 --- a/lib/subghz/devices/cc1101_configs.c +++ b/lib/subghz/devices/cc1101_configs.c @@ -479,4 +479,4 @@ const uint8_t subghz_device_cc1101_preset_gfsk_9_99kb_async_regs[] = { // 0x00, // 0x00, // 0x00, -// 0x00}; \ No newline at end of file +// 0x00}; diff --git a/lib/subghz/devices/cc1101_configs.h b/lib/subghz/devices/cc1101_configs.h index 0e1ffb0c74..5b96b4a1a1 100644 --- a/lib/subghz/devices/cc1101_configs.h +++ b/lib/subghz/devices/cc1101_configs.h @@ -20,4 +20,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 f5f140c6a7..6de2d9bd35 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 2 typedef struct SubGhzDeviceRegistry SubGhzDeviceRegistry; @@ -95,4 +95,4 @@ struct SubGhzDeviceConf { uint8_t ver; bool extended_range; bool power_amp; -}; \ No newline at end of file +}; diff --git a/lib/subghz/protocols/bin_raw.c b/lib/subghz/protocols/bin_raw.c index 8470c7d590..96f40f9fc7 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 40ae05bade..645f5eee13 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 0dd0d2b0b7..ea85fc0d96 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 a0547a1137..5cbffefed0 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 69b8bba4ae..cf9618fcbb 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/faac_slh.h b/lib/subghz/protocols/faac_slh.h index 66cbb70fa5..60f10a34f6 100644 --- a/lib/subghz/protocols/faac_slh.h +++ b/lib/subghz/protocols/faac_slh.h @@ -110,4 +110,4 @@ void subghz_protocol_decoder_faac_slh_get_string(void* context, FuriString* outp // Reset prog mode vars // TODO: Remake in proper way -void faac_slh_reset_prog_mode(void); \ No newline at end of file +void faac_slh_reset_prog_mode(void); diff --git a/lib/subghz/protocols/gate_tx.c b/lib/subghz/protocols/gate_tx.c index 2ebd6bb03b..d6a6bc7c9e 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 294bd124d3..b4717f5c67 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 fc490e9d1c..70954bb39d 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 0da58a78c4..cee45cfd61 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -425,11 +425,17 @@ static bool uint8_t klq_last_custom_btn = 0xA; if((strcmp(instance->manufacture_name, "BFT") == 0) || (strcmp(instance->manufacture_name, "Aprimatic") == 0) || - (strcmp(instance->manufacture_name, "Dea_Mio") == 0)) { + (strcmp(instance->manufacture_name, "Dea_Mio") == 0) || + (strcmp(instance->manufacture_name, "NICE_MHOUSE") == 0)) { klq_last_custom_btn = 0xF; - } - if((strcmp(instance->manufacture_name, "FAAC_RC,XT") == 0)) { + } else if((strcmp(instance->manufacture_name, "FAAC_RC,XT") == 0)) { + klq_last_custom_btn = 0xB; + } else if((strcmp(instance->manufacture_name, "Novoferm") == 0)) { + klq_last_custom_btn = 0x9; + } else if((strcmp(instance->manufacture_name, "NICE_Smilo") == 0)) { klq_last_custom_btn = 0xB; + } else if((strcmp(instance->manufacture_name, "EcoStar") == 0)) { + klq_last_custom_btn = 0x6; } btn = subghz_protocol_keeloq_get_btn_code(klq_last_custom_btn); @@ -752,7 +758,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; /*FURI_LOG_I( "KL", diff --git a/lib/subghz/protocols/keeloq_common.h b/lib/subghz/protocols/keeloq_common.h index a6c0d346e8..c4af17f268 100644 --- a/lib/subghz/protocols/keeloq_common.h +++ b/lib/subghz/protocols/keeloq_common.h @@ -16,12 +16,12 @@ * 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_FAAC 5u +#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_FAAC 5u #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1 6u #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_2 7u #define KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_3 8u diff --git a/lib/subghz/protocols/kinggates_stylo_4k.c b/lib/subghz/protocols/kinggates_stylo_4k.c index 9eebe62599..0f7ae06d59 100644 --- a/lib/subghz/protocols/kinggates_stylo_4k.c +++ b/lib/subghz/protocols/kinggates_stylo_4k.c @@ -581,4 +581,4 @@ void subghz_protocol_decoder_kinggates_stylo_4k_get_string(void* context, FuriSt instance->generic.serial, instance->generic.btn, instance->generic.cnt); -} \ No newline at end of file +} diff --git a/lib/subghz/protocols/linear.c b/lib/subghz/protocols/linear.c index 8d37357966..f9d7aaca87 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 54ad5bfaa4..d4c549a422 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 2e0435bdbb..8953e0d9e1 100644 --- a/lib/subghz/protocols/nice_flor_s.c +++ b/lib/subghz/protocols/nice_flor_s.c @@ -17,7 +17,7 @@ #define TAG "SubGhzProtocolNiceFlorS" #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 2416a9d010..2fabed73d5 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 d03282f73a..828c4a76ea 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 247ac3fc63..728187c0f4 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 07a121ac7e..96908130e9 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 8d41582bf4..0ed2af0737 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 b58fe3df46..4e277e52ed 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -17,10 +17,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 c12e23b423..17b958e0e2 100644 --- a/lib/subghz/subghz_keystore.c +++ b/lib/subghz/subghz_keystore.c @@ -14,9 +14,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 adb9a1714f..a7c3ee1dfc 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 f5994d4949..81f1238566 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 fe68d5e2d1..a771d1d192 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 bbe6eff9e0..b133a62bba 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 e8cb334d51..4ab4a0c5b1 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 780bea27ab..5e794891f3 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 f08e175840..f5862222d0 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 535237fc6e..f2d32921f2 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 e5cdfff17c..4b5bd30d38 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 09fc241eeb..602653e8ff 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 7618344ac3..cb50fa3b48 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 11b7fe35ad..8cc45dd856 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 59c9403e81..f70f2361e1 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 b990381c3b..8239ea9e54 100644 --- a/lib/toolbox/name_generator.h +++ b/lib/toolbox/name_generator.h @@ -48,4 +48,4 @@ void name_generator_make_detailed_datetime( #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/lib/toolbox/path.c b/lib/toolbox/path.c index 37bacd65a8..a3fe684730 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 860528e4cd..fcd500fc6f 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 037711a8ff..4c5d906ba7 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 0ee165d13e..855839dc7f 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 71fa4fe289..5680be18de 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 dd0711732d..543b3ead2a 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 dce63b8233..dcacb1f981 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 f9597280f1..b4b7d2d9f1 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 9aff8bd4fb..0e4c5fc7a6 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 742547fb78..7b014391e4 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 25084aaa04..80144a0f4f 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 ba2f7749f0..3eb97391e8 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 bf4681d4dc..997c4d9d8b 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 540b7a8738..c37f3b9312 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 230bd2a1bc..b3e74c229b 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 834284f5d8..821fba92ee 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 a5af75e11e..2d729711d8 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 c59c68d05e..b8873fb7d6 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 85b661e8e0..c336a19d0b 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 5a818a0a4a..580a76d457 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 ddceb5ffaa..90b41fa549 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 eef27cb429..920db3f035 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 0c6284516c..4d064b3f78 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 cb603abe04..3ab8c02b08 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 063f577e24..1f246337e6 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/distfap.py b/scripts/distfap.py deleted file mode 100755 index b1c5587906..0000000000 --- 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 1dd3bc4ebb..5615f105ed 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 6bad96b2dc..2988fd67b2 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 0000000000..bae84d3fed --- /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 0000000000..4ceb6e36f5 --- /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 42141acff6..a85d1e91ae 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 f0e24e7fd7..7f0ec4e873 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 f8dffeb66b..0000000000 --- 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 db302e9dae..0000000000 --- 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 0000000000..bf02feaad3 --- /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 29b48369a1..c0a3cd8700 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 edd5691f25..ed3d653d58 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 26b1046ee3..18c4d1cac8 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 a3ba7e08da..67a274bb55 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 4b76f7fa43..c42068920c 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 0000000000..12e13751d2 --- /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 81a8981f73..dd6a4750db 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 9daefb4308..dc92d3bbdb 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 ce5210f5fe..b93ad82f1a 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 c315ef8ade..e880bced84 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 c36a9a6b60..c4c2fb5abd 100644 --- a/site_scons/commandline.scons +++ b/site_scons/commandline.scons @@ -268,7 +268,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 b763a3a7c0..5b297e80e5 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/f18/api_symbols.csv b/targets/f18/api_symbols.csv index 99c153c049..7e254ce401 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 8b85260314..f9be05e24b 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 7571267f06..6002ccbee6 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,, @@ -773,8 +773,8 @@ Function,+,bt_keys_storage_set_default_path,void,Bt* Function,+,bt_keys_storage_set_file_path,void,"BtKeysStorage*, const char*" Function,+,bt_keys_storage_set_ram_params,void,"BtKeysStorage*, uint8_t*, uint16_t" Function,+,bt_keys_storage_set_storage_path,void,"Bt*, const char*" -Function,-,bt_open_rpc_connection,void,Bt* Function,+,bt_keys_storage_update,_Bool,"BtKeysStorage*, uint8_t*, uint32_t" +Function,-,bt_open_rpc_connection,void,Bt* Function,+,bt_profile_restore_default,_Bool,Bt* Function,+,bt_profile_start,FuriHalBleProfileBase*,"Bt*, const FuriHalBleProfileTemplate*, FuriHalBleProfileParams" Function,+,bt_remote_rssi,_Bool,"Bt*, uint8_t*" @@ -866,13 +866,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" @@ -1234,13 +1241,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* @@ -1301,9 +1317,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" @@ -1431,6 +1444,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*" @@ -1687,6 +1701,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*, @@ -1871,6 +1888,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* @@ -1881,10 +1899,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" @@ -2243,10 +2263,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*" @@ -2548,6 +2570,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*" @@ -2596,6 +2619,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* @@ -2616,7 +2644,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*" @@ -3515,6 +3544,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" @@ -3579,6 +3610,7 @@ Function,+,variable_item_list_set_enter_callback,void,"VariableItemList*, Variab Function,+,variable_item_list_set_selected_item,void,"VariableItemList*, uint8_t" Function,+,variable_item_set_current_value_index,void,"VariableItem*, uint8_t" Function,+,variable_item_set_current_value_text,void,"VariableItem*, const char*" +Function,+,variable_item_set_item_label,void,"VariableItem*, const char*" Function,+,variable_item_set_locked,void,"VariableItem*, _Bool, const char*" Function,+,variable_item_set_values_count,void,"VariableItem*, uint8_t" Function,+,varint_int32_length,size_t,int32_t @@ -3719,6 +3751,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 d0e089eb1e..43be8129dc 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 eab17e5b79..37263849a1 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 deafbb9a48..c6bc568461 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 c50360361f..73bb41badc 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 1d32c2a2ed..7446b7941b 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 60338cb76b..0fd452a5a6 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 5a33e9e542..d4d85181a7 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 bdef259e33..5b213fec9e 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 9a5f51d204..2166d06968 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 4250b356c9..66aafc4959 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 91ad886e06..4d2b069d14 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 240cd5f2fa..53d312b2e7 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 8376bf6cc3..2bde80bde4 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 8408a1ec17..08dd5b994b 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 319dd21732..a76035a094 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 db636fbb95..009a17d4bf 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 036d50ace2..30a4ee7ede 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 85b121dc44..30b3879f61 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 ca4c7ad4d7..fd55bf6f2b 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 236573bca8..1879eb2cae 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 7d1488fa52..f97673ea15 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 d6b840255b..28aa451736 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 @@ -323,9 +323,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) { @@ -452,9 +452,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) { @@ -513,8 +513,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 6a5d422226..c20f907495 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 8e6192ca05..e504b969cc 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 07cf8de6e2..4f7c5e4732 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 e1ffb1b25f..76d2238f94 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 a0b166fad4..029d103cb5 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 15a9a819fa..35c40c2595 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 c06ec23d20..2326d3c0ac 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 b44342b522..621478d14d 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 780a9d743d..cae87342a3 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 5fe3ab66bb..5af638ab13 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 550f1b16ef..ee7a04e45f 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 9ab3532f95..3245b67cc8 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 ba28a141f3..35e381a55a 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 fd557fa98f..8b75a05c5b 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 99768654d9..c01b2207ff 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 07ea5ab0a7..34bb3a5160 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 a1c8b46c34..f5f7bdf2d2 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 fb7f43ec8d..eca5b6da9c 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 f26b412d2d..5ddb0785f7 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 0aa8ce951a..65b517b9ee 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 e2892572fa..49bcd48a1e 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 843f637f59..c2efe1fd38 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 { @@ -271,7 +271,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 10d89947a9..e8e95d9f3b 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.h +++ b/targets/f7/furi_hal/furi_hal_subghz.h @@ -21,7 +21,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_subghz_i.h b/targets/f7/furi_hal/furi_hal_subghz_i.h index e7fe2602f7..22aa051afb 100644 --- a/targets/f7/furi_hal/furi_hal_subghz_i.h +++ b/targets/f7/furi_hal/furi_hal_subghz_i.h @@ -1,3 +1,3 @@ #pragma once -void furi_hal_subghz_set_dangerous_frequency(bool state_i); \ No newline at end of file +void furi_hal_subghz_set_dangerous_frequency(bool state_i); diff --git a/targets/f7/furi_hal/furi_hal_usb_ccid.c b/targets/f7/furi_hal/furi_hal_usb_ccid.c index 5e2fe77b77..a2c1a0583e 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 8525022c09..cfedb5e76b 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 9599aa1c12..c83261226e 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 390070c8f6..05f498376d 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 5238516514..a2f8348670 100644 --- a/targets/f7/furi_hal/furi_hal_version.c +++ b/targets/f7/furi_hal/furi_hal_version.c @@ -11,8 +11,8 @@ #define TAG "FuriHalVersion" #define FURI_HAL_VERSION_OTP_HEADER_MAGIC (0xBABE) -#define FURI_HAL_VERSION_OTP_ADDRESS (OTP_AREA_BASE) -#define FURI_HAL_VERSION_PLATFORM_ID (0x0080e126) +#define FURI_HAL_VERSION_OTP_ADDRESS (OTP_AREA_BASE) +#define FURI_HAL_VERSION_PLATFORM_ID (0x0080e126) /** 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 af88c06719..6ddb99e866 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 37aac1eb09..62310511d2 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 c935611ab7..d03549c790 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 8e5cc379b5..8209fd6a25 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 83f5a8b75d..e2dfd4541c 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 25ba33c28c..14c2975ac6 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 04a2c67cf1..9a3b488fb2 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 6451d93bca..c57c434fa8 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_region.h b/targets/furi_hal_include/furi_hal_region.h index a1605c93ab..b6a6d425e6 100644 --- a/targets/furi_hal_include/furi_hal_region.h +++ b/targets/furi_hal_include/furi_hal_region.h @@ -75,4 +75,4 @@ const FuriHalRegionBand* furi_hal_region_get_band(uint32_t frequency); #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 cbd0bf092b..fbe69ce3cb 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 29994196fc..af4a542de9 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 ca870ad664..2c098d482e 100644 --- a/targets/furi_hal_include/furi_hal_version.h +++ b/targets/furi_hal_include/furi_hal_version.h @@ -14,9 +14,9 @@ extern "C" { #endif -#define FURI_HAL_VERSION_NAME_LENGTH 8 +#define FURI_HAL_VERSION_NAME_LENGTH 8 #define FURI_HAL_VERSION_ARRAY_NAME_LENGTH (FURI_HAL_VERSION_NAME_LENGTH + 1) -#define FURI_HAL_BT_ADV_NAME_LENGTH (18 + 1) // 18 characters + null terminator +#define FURI_HAL_BT_ADV_NAME_LENGTH (18 + 1) // 18 characters + null terminator #define FURI_HAL_VERSION_DEVICE_NAME_LENGTH \ (1 + FURI_HAL_BT_ADV_NAME_LENGTH) // Used for custom BT name, BLE symbol + name