Просмотр исходного кода

add new ofw apps for new module

MX 1 год назад
Родитель
Сommit
2fca679514
85 измененных файлов с 6887 добавлено и 1 удалено
  1. 3 1
      ReadMe.md
  2. 16 0
      non_catalog_apps/air_arkanoid/application.fam
  3. BIN
      non_catalog_apps/air_arkanoid/assets/sprites/logo_air.fxbm
  4. BIN
      non_catalog_apps/air_arkanoid/assets/sprites/logo_arkanoid.fxbm
  5. 674 0
      non_catalog_apps/air_arkanoid/engine/LICENSE
  6. 13 0
      non_catalog_apps/air_arkanoid/engine/README.md
  7. 28 0
      non_catalog_apps/air_arkanoid/engine/canvas.c
  8. 32 0
      non_catalog_apps/air_arkanoid/engine/canvas.h
  9. 53 0
      non_catalog_apps/air_arkanoid/engine/clock_timer.c
  10. 15 0
      non_catalog_apps/air_arkanoid/engine/clock_timer.h
  11. 25 0
      non_catalog_apps/air_arkanoid/engine/engine.h
  12. 217 0
      non_catalog_apps/air_arkanoid/engine/entity.c
  13. 65 0
      non_catalog_apps/air_arkanoid/engine/entity.h
  14. 58 0
      non_catalog_apps/air_arkanoid/engine/entity_i.h
  15. 199 0
      non_catalog_apps/air_arkanoid/engine/game_engine.c
  16. 88 0
      non_catalog_apps/air_arkanoid/engine/game_engine.h
  17. 162 0
      non_catalog_apps/air_arkanoid/engine/game_manager.c
  18. 40 0
      non_catalog_apps/air_arkanoid/engine/game_manager.h
  19. 24 0
      non_catalog_apps/air_arkanoid/engine/game_manager_i.h
  20. 249 0
      non_catalog_apps/air_arkanoid/engine/level.c
  21. 78 0
      non_catalog_apps/air_arkanoid/engine/level.h
  22. 26 0
      non_catalog_apps/air_arkanoid/engine/level_i.h
  23. 54 0
      non_catalog_apps/air_arkanoid/engine/main.c
  24. 84 0
      non_catalog_apps/air_arkanoid/engine/scripts/sprite_builder.py
  25. 297 0
      non_catalog_apps/air_arkanoid/engine/sensors/ICM42688P/ICM42688P.c
  26. 127 0
      non_catalog_apps/air_arkanoid/engine/sensors/ICM42688P/ICM42688P.h
  27. 176 0
      non_catalog_apps/air_arkanoid/engine/sensors/ICM42688P/ICM42688P_regs.h
  28. 326 0
      non_catalog_apps/air_arkanoid/engine/sensors/imu.c
  29. 15 0
      non_catalog_apps/air_arkanoid/engine/sensors/imu.h
  30. 69 0
      non_catalog_apps/air_arkanoid/engine/sprite.c
  31. 44 0
      non_catalog_apps/air_arkanoid/engine/sprite.h
  32. 33 0
      non_catalog_apps/air_arkanoid/engine/vector.c
  33. 32 0
      non_catalog_apps/air_arkanoid/engine/vector.h
  34. 25 0
      non_catalog_apps/air_arkanoid/fonts/fonts.c
  35. 4 0
      non_catalog_apps/air_arkanoid/fonts/fonts.h
  36. 73 0
      non_catalog_apps/air_arkanoid/game.c
  37. 35 0
      non_catalog_apps/air_arkanoid/game.h
  38. 21 0
      non_catalog_apps/air_arkanoid/game_settings.c
  39. 6 0
      non_catalog_apps/air_arkanoid/game_settings.h
  40. BIN
      non_catalog_apps/air_arkanoid/icon.png
  41. 357 0
      non_catalog_apps/air_arkanoid/levels/level_game.c
  42. 4 0
      non_catalog_apps/air_arkanoid/levels/level_game.h
  43. 201 0
      non_catalog_apps/air_arkanoid/levels/level_menu.c
  44. 4 0
      non_catalog_apps/air_arkanoid/levels/level_menu.h
  45. 57 0
      non_catalog_apps/air_arkanoid/levels/level_message.c
  46. 8 0
      non_catalog_apps/air_arkanoid/levels/level_message.h
  47. 223 0
      non_catalog_apps/air_arkanoid/levels/level_settings.c
  48. 4 0
      non_catalog_apps/air_arkanoid/levels/level_settings.h
  49. BIN
      non_catalog_apps/air_arkanoid/sprites/logo_air.png
  50. BIN
      non_catalog_apps/air_arkanoid/sprites/logo_arkanoid.png
  51. 115 0
      non_catalog_apps/video_game_module_tool/app.c
  52. 58 0
      non_catalog_apps/video_game_module_tool/app_i.h
  53. 17 0
      non_catalog_apps/video_game_module_tool/application.fam
  54. 11 0
      non_catalog_apps/video_game_module_tool/custom_event.h
  55. BIN
      non_catalog_apps/video_game_module_tool/files/vgm-fw-0.1.0.uf2
  56. 23 0
      non_catalog_apps/video_game_module_tool/flasher/board.c
  57. 23 0
      non_catalog_apps/video_game_module_tool/flasher/board.h
  58. 292 0
      non_catalog_apps/video_game_module_tool/flasher/flasher.c
  59. 84 0
      non_catalog_apps/video_game_module_tool/flasher/flasher.h
  60. 433 0
      non_catalog_apps/video_game_module_tool/flasher/rp2040.c
  61. 53 0
      non_catalog_apps/video_game_module_tool/flasher/rp2040.h
  62. 281 0
      non_catalog_apps/video_game_module_tool/flasher/swd.c
  63. 122 0
      non_catalog_apps/video_game_module_tool/flasher/swd.h
  64. 231 0
      non_catalog_apps/video_game_module_tool/flasher/target.c
  65. 45 0
      non_catalog_apps/video_game_module_tool/flasher/target.h
  66. 167 0
      non_catalog_apps/video_game_module_tool/flasher/uf2.c
  67. 60 0
      non_catalog_apps/video_game_module_tool/flasher/uf2.h
  68. BIN
      non_catalog_apps/video_game_module_tool/icons/Checkmark_44x40.png
  69. BIN
      non_catalog_apps/video_game_module_tool/icons/Flashing_module_70x30.png
  70. BIN
      non_catalog_apps/video_game_module_tool/icons/Module_60x26.png
  71. BIN
      non_catalog_apps/video_game_module_tool/icons/Update_module_56x52.png
  72. BIN
      non_catalog_apps/video_game_module_tool/icons/WarningDolphinFlip_45x42.png
  73. 30 0
      non_catalog_apps/video_game_module_tool/scenes/scene.c
  74. 28 0
      non_catalog_apps/video_game_module_tool/scenes/scene.h
  75. 7 0
      non_catalog_apps/video_game_module_tool/scenes/scene_config.h
  76. 66 0
      non_catalog_apps/video_game_module_tool/scenes/scene_confirm.c
  77. 68 0
      non_catalog_apps/video_game_module_tool/scenes/scene_error.c
  78. 36 0
      non_catalog_apps/video_game_module_tool/scenes/scene_file_select.c
  79. 39 0
      non_catalog_apps/video_game_module_tool/scenes/scene_install.c
  80. 43 0
      non_catalog_apps/video_game_module_tool/scenes/scene_probe.c
  81. 60 0
      non_catalog_apps/video_game_module_tool/scenes/scene_start.c
  82. 54 0
      non_catalog_apps/video_game_module_tool/scenes/scene_success.c
  83. BIN
      non_catalog_apps/video_game_module_tool/vgm_tool.png
  84. 76 0
      non_catalog_apps/video_game_module_tool/views/progress.c
  85. 21 0
      non_catalog_apps/video_game_module_tool/views/progress.h

+ 3 - 1
ReadMe.md

@@ -13,7 +13,7 @@ Apps contains changes needed to compile them on latest firmware, fixes has been
 
 The Flipper and its community wouldn't be as rich as it is without your contributions and support. Thank you for all you have done.
 
-### Apps checked & updated at `12 Feb 22:20 GMT +3`
+### Apps checked & updated at `13 Feb 16:22 GMT +3`
 
 
 # Default pack
@@ -155,6 +155,7 @@ The Flipper and its community wouldn't be as rich as it is without your contribu
 | Tarot spread | ![Games Badge] | [by pionaiki](https://github.com/pionaiki/fz-tarot) |  | ![None Badge] |
 | Vexed | ![Games Badge] | [by dlvoy](https://github.com/dlvoy/flipper-zero-vexed) |  | ![None Badge] |
 | Paper Plane | ![Games Badge] | [by Larry-the-Pig](https://github.com/Larry-the-Pig/flipper-plane) |  | ![None Badge] |
+| Air Arkanoid | ![Games Badge] | [by DrZlo13](https://github.com/flipperdevices/flipperzero-good-faps/pull/141/files) |  | [![Official Badge]](https://lab.flipper.net/apps/air_arkanoid) |
 | Air Mouse | ![GPIO Badge] | [by ginkage](https://github.com/ginkage/FlippAirMouse/) |  | [![Author Badge]](https://lab.flipper.net/apps/air_mouse) |
 | Plantower PMSx003 sensor reader | ![GPIO Badge] | [by 3cky](https://github.com/3cky/flipperzero-airmon) |  | [![UFW Badge]](https://lab.flipper.net/apps/airmon) |
 | Bar code scanner emulator via COM port | ![GPIO Badge] | [by polarikus](https://github.com/polarikus/flipper-zero_bc_scanner_emulator) |  | ![None Badge] |
@@ -252,6 +253,7 @@ The Flipper and its community wouldn't be as rich as it is without your contribu
 | Simple calendar app | ![Tools Badge] | [by Adiras](https://github.com/Adiras/flipperzero-calendar) |  | ![None Badge] |
 | Programmer Calculator | ![Tools Badge] | [by armixz](https://github.com/armixz/Flipper-Zero-Programmer-Calculator) |  | ![None Badge] |
 | Tone Generator | ![Tools Badge] | [by GEMISIS](https://github.com/GEMISIS/tone_gen/) |  | ![None Badge] |
+| Video Game Module Tool | ![Tools Badge] | [by gsurkov](https://github.com/flipperdevices/flipperzero-good-faps/pull/127/files) |  | [![Official Badge]](https://lab.flipper.net/apps/video_game_module_tool) |
 | USB HID Autofire | ![USB Badge] | [by pbek](https://github.com/pbek/usb_hid_autofire) |  | ![None Badge] |
 | USB Consumer Control | ![USB Badge] | [by WithSecureLabs](https://github.com/WithSecureLabs/usb-consumer-control/tree/main) |  | ![None Badge] |
 | HID File Transfer | ![USB Badge] | [by Kavakuo](https://github.com/Kavakuo/HID-File-Transfer) | Get client app in [original repo](https://github.com/Kavakuo/HID-File-Transfer) | ![None Badge] |

+ 16 - 0
non_catalog_apps/air_arkanoid/application.fam

@@ -0,0 +1,16 @@
+App(
+    appid="air_arkanoid",
+    name="Air Arkanoid",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="game_app",
+    stack_size=4 * 1024,
+    fap_icon="icon.png",
+    fap_category="Games",
+    fap_file_assets="assets",
+    fap_extbuild=(
+        ExtFile(
+            path="${FAP_SRC_DIR}/assets",
+            command="python3 ${FAP_SRC_DIR}/engine/scripts/sprite_builder.py ${FAP_SRC_DIR.abspath}/sprites ${TARGET.abspath}/sprites",
+        ),
+    ),
+)

BIN
non_catalog_apps/air_arkanoid/assets/sprites/logo_air.fxbm


BIN
non_catalog_apps/air_arkanoid/assets/sprites/logo_arkanoid.fxbm


+ 674 - 0
non_catalog_apps/air_arkanoid/engine/LICENSE

@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

+ 13 - 0
non_catalog_apps/air_arkanoid/engine/README.md

@@ -0,0 +1,13 @@
+# Flipper Zero Game Engine
+
+Welcome to the Flipper Zero game engine! This engine is designed to help you create games for the Flipper Zero device.
+
+## Example App
+
+To see the game engine in action, check out our [example app](https://github.com/flipperdevices/flipperzero-game-engine-example). This app demonstrates how to use the game engine to create a simple game.
+
+## Contributing
+
+We welcome contributions to the Flipper Zero game engine! If you have any bug reports, feature requests, or pull requests, please submit them to the [official repository](https://github.com/flipperdevices/flipperzero-game-engine).
+
+Happy game development with Flipper Zero!

+ 28 - 0
non_catalog_apps/air_arkanoid/engine/canvas.c

@@ -0,0 +1,28 @@
+#include <furi.h>
+#include "canvas.h"
+
+void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...) {
+    FuriString* string = furi_string_alloc();
+    va_list args;
+    va_start(args, format);
+    furi_string_vprintf(string, format, args);
+    va_end(args);
+
+    canvas_draw_str(canvas, x, y, furi_string_get_cstr(string));
+
+    furi_string_free(string);
+}
+
+size_t canvas_printf_width(Canvas* canvas, const char* format, ...) {
+    FuriString* string = furi_string_alloc();
+    va_list args;
+    va_start(args, format);
+    furi_string_vprintf(string, format, args);
+    va_end(args);
+
+    size_t size = canvas_string_width(canvas, furi_string_get_cstr(string));
+
+    furi_string_free(string);
+
+    return size;
+}

+ 32 - 0
non_catalog_apps/air_arkanoid/engine/canvas.h

@@ -0,0 +1,32 @@
+#pragma once
+#include <stddef.h>
+#include <gui/canvas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Print formatted string to canvas
+ * 
+ * @param canvas canvas instance
+ * @param x x position
+ * @param y y position
+ * @param format format string
+ * @param ...  arguments
+ */
+void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...);
+
+/**
+ * @brief Get width of formatted string
+ * 
+ * @param canvas canvas instance
+ * @param format format string
+ * @param ... arguments
+ * @return size_t width of formatted string
+ */
+size_t canvas_printf_width(Canvas* canvas, const char* format, ...);
+
+#ifdef __cplusplus
+}
+#endif

+ 53 - 0
non_catalog_apps/air_arkanoid/engine/clock_timer.c

@@ -0,0 +1,53 @@
+#include "clock_timer.h"
+#include <stdlib.h>
+
+#include <furi_hal_interrupt.h>
+#include <furi_hal_bus.h>
+#include <stm32wbxx_ll_tim.h>
+
+#define FURI_HAL_CLOCK_TIMER TIM2
+#define FURI_HAL_CLOCK_TIMER_BUS FuriHalBusTIM2
+#define FURI_HAL_CLOCK_TIMER_IRQ FuriHalInterruptIdTIM2
+
+typedef struct {
+    ClockTimerCallback callback;
+    void* context;
+} ClockTimer;
+
+static ClockTimer clock_timer = {
+    .callback = NULL,
+    .context = NULL,
+};
+
+static void clock_timer_isr(void* context) {
+    if(clock_timer.callback) {
+        clock_timer.callback(context);
+    }
+
+    LL_TIM_ClearFlag_UPDATE(FURI_HAL_CLOCK_TIMER);
+}
+
+void clock_timer_start(ClockTimerCallback callback, void* context, float period) {
+    clock_timer.callback = callback;
+    clock_timer.context = context;
+
+    furi_hal_bus_enable(FURI_HAL_CLOCK_TIMER_BUS);
+
+    // init timer to produce interrupts
+    LL_TIM_InitTypeDef TIM_InitStruct = {0};
+    TIM_InitStruct.Autoreload = (SystemCoreClock / period) - 1;
+    LL_TIM_Init(FURI_HAL_CLOCK_TIMER, &TIM_InitStruct);
+
+    furi_hal_interrupt_set_isr(FURI_HAL_CLOCK_TIMER_IRQ, clock_timer_isr, clock_timer.context);
+
+    LL_TIM_EnableIT_UPDATE(FURI_HAL_CLOCK_TIMER);
+    LL_TIM_EnableCounter(FURI_HAL_CLOCK_TIMER);
+}
+
+void clock_timer_stop(void) {
+    LL_TIM_DisableIT_UPDATE(FURI_HAL_CLOCK_TIMER);
+    LL_TIM_DisableCounter(FURI_HAL_CLOCK_TIMER);
+
+    furi_hal_bus_disable(FURI_HAL_CLOCK_TIMER_BUS);
+    furi_hal_interrupt_set_isr(FURI_HAL_CLOCK_TIMER_IRQ, NULL, NULL);
+}

+ 15 - 0
non_catalog_apps/air_arkanoid/engine/clock_timer.h

@@ -0,0 +1,15 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*ClockTimerCallback)(void* context);
+
+void clock_timer_start(ClockTimerCallback callback, void* context, float period);
+
+void clock_timer_stop(void);
+
+#ifdef __cplusplus
+}
+#endif

+ 25 - 0
non_catalog_apps/air_arkanoid/engine/engine.h

@@ -0,0 +1,25 @@
+#pragma once
+#include <furi.h>
+#include "game_engine.h"
+#include "level.h"
+#include "entity.h"
+#include "game_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+    float target_fps;
+    bool show_fps;
+    bool always_backlight;
+    void (*start)(GameManager* game_manager, void* context);
+    void (*stop)(void* context);
+    size_t context_size;
+} Game;
+
+extern const Game game;
+
+#ifdef __cplusplus
+}
+#endif

+ 217 - 0
non_catalog_apps/air_arkanoid/engine/entity.c

@@ -0,0 +1,217 @@
+#include "entity.h"
+#include "entity_i.h"
+#include <stdlib.h>
+#include <furi.h>
+
+#ifdef ENTITY_DEBUG
+#define ENTITY_D(...) FURI_LOG_D("Entity", __VA_ARGS__)
+#else
+#define ENTITY_D(...)
+#endif
+
+static int32_t entities_count = 0;
+
+int32_t entities_get_count(void) {
+    return entities_count;
+}
+
+Entity* entity_alloc(const EntityDescription* description) {
+    entities_count++;
+    Entity* entity = malloc(sizeof(Entity));
+    entity->position = VECTOR_ZERO;
+    entity->description = description;
+    entity->context = NULL;
+    if(description && description->context_size > 0) {
+        entity->context = malloc(description->context_size);
+    }
+    entity->collider = NULL;
+    entity->collider_offset = VECTOR_ZERO;
+    ENTITY_D("Allocated at %p", entity);
+    entity->collider_dirty = false;
+    return entity;
+}
+
+void entity_collider_add_circle(Entity* entity, float radius) {
+    furi_check(entity->collider == NULL, "Collider already added");
+    entity->collider = malloc(sizeof(Collider));
+    entity->collider->type = ColliderTypeCircle;
+    entity->collider->circle.radius = radius;
+    entity->collider_dirty = true;
+}
+
+void entity_collider_add_rect(Entity* entity, float width, float height) {
+    furi_check(entity->collider == NULL, "Collider already added");
+    entity->collider = malloc(sizeof(Collider));
+    entity->collider->type = ColliderTypeRect;
+    entity->collider->rect.half_width = width / 2;
+    entity->collider->rect.half_height = height / 2;
+    entity->collider_dirty = true;
+}
+
+void entity_collider_remove(Entity* entity) {
+    furi_check(entity->collider != NULL, "Collider not added");
+    free(entity->collider);
+    entity->collider = NULL;
+    entity->collider_dirty = false;
+}
+
+void entity_collider_offset_set(Entity* entity, Vector offset) {
+    entity->collider_offset = offset;
+    entity->collider_dirty = true;
+}
+
+Vector entity_collider_offset_get(Entity* entity) {
+    return entity->collider_offset;
+}
+
+static Vector entity_collider_position_get(Entity* entity) {
+    return (Vector){
+        .x = entity->position.x + entity->collider_offset.x,
+        .y = entity->position.y + entity->collider_offset.y,
+    };
+}
+
+void entity_free(Entity* entity) {
+    entities_count--;
+    ENTITY_D("Freeing at %p", entity);
+    if(entity->context) {
+        free(entity->context);
+    }
+    if(entity->collider) {
+        free(entity->collider);
+    }
+    free(entity);
+}
+
+const EntityDescription* entity_description_get(Entity* entity) {
+    return entity->description;
+}
+
+Vector entity_pos_get(Entity* entity) {
+    return entity->position;
+}
+
+void entity_pos_set(Entity* entity, Vector position) {
+    entity->position = position;
+    entity->collider_dirty = true;
+}
+
+void* entity_context_get(Entity* entity) {
+    return entity->context;
+}
+
+void entity_call_start(Entity* entity, GameManager* manager) {
+    if(entity->description && entity->description->start) {
+        entity->description->start(entity, manager, entity->context);
+    }
+}
+
+void entity_call_stop(Entity* entity, GameManager* manager) {
+    if(entity->description && entity->description->stop) {
+        entity->description->stop(entity, manager, entity->context);
+    }
+}
+
+void entity_call_update(Entity* entity, GameManager* manager) {
+    if(entity->description && entity->description->update) {
+        entity->description->update(entity, manager, entity->context);
+    }
+}
+
+void entity_call_render(Entity* entity, GameManager* manager, Canvas* canvas) {
+    if(entity->description && entity->description->render) {
+        entity->description->render(entity, manager, canvas, entity->context);
+    }
+}
+
+void entity_call_collision(Entity* entity, Entity* other, GameManager* manager) {
+    if(entity->description && entity->description->collision) {
+        entity->description->collision(entity, other, manager, entity->context);
+    }
+}
+
+bool entity_collider_circle_circle(Entity* entity, Entity* other) {
+    Vector pos1 = entity_collider_position_get(entity);
+    Vector pos2 = entity_collider_position_get(other);
+
+    float dx = pos1.x - pos2.x;
+    float dy = pos1.y - pos2.y;
+    float distance = sqrtf(dx * dx + dy * dy);
+    return distance < entity->collider->circle.radius + other->collider->circle.radius;
+}
+
+bool entity_collider_rect_rect(Entity* entity, Entity* other) {
+    Vector pos1 = entity_collider_position_get(entity);
+    Vector pos2 = entity_collider_position_get(other);
+
+    float left1 = pos1.x - entity->collider->rect.half_width;
+    float right1 = pos1.x + entity->collider->rect.half_width;
+    float top1 = pos1.y - entity->collider->rect.half_height;
+    float bottom1 = pos1.y + entity->collider->rect.half_height;
+
+    float left2 = pos2.x - other->collider->rect.half_width;
+    float right2 = pos2.x + other->collider->rect.half_width;
+    float top2 = pos2.y - other->collider->rect.half_height;
+    float bottom2 = pos2.y + other->collider->rect.half_height;
+
+    return left1 < right2 && right1 > left2 && top1 < bottom2 && bottom1 > top2;
+}
+
+bool entity_collider_circle_rect(Entity* circle, Entity* rect) {
+    Vector pos1 = entity_collider_position_get(circle);
+    Vector pos2 = entity_collider_position_get(rect);
+
+    float left = pos2.x - rect->collider->rect.half_width;
+    float right = pos2.x + rect->collider->rect.half_width;
+    float top = pos2.y - rect->collider->rect.half_height;
+    float bottom = pos2.y + rect->collider->rect.half_height;
+
+    float closestX = fmaxf(left, fminf(pos1.x, right));
+    float closestY = fmaxf(top, fminf(pos1.y, bottom));
+
+    float dx = pos1.x - closestX;
+    float dy = pos1.y - closestY;
+    float distance = sqrtf(dx * dx + dy * dy);
+    return distance < circle->collider->circle.radius;
+}
+
+bool entity_collider_check_collision(Entity* entity, Entity* other) {
+    furi_check(entity->collider);
+    furi_check(other->collider);
+
+    if(entity->collider->type == ColliderTypeCircle) {
+        Entity* circle = entity;
+        if(other->collider->type == ColliderTypeCircle) {
+            return entity_collider_circle_circle(circle, other);
+        } else {
+            return entity_collider_circle_rect(circle, other);
+        }
+    } else {
+        Entity* rect = entity;
+        if(other->collider->type == ColliderTypeCircle) {
+            return entity_collider_circle_rect(other, rect);
+        } else {
+            return entity_collider_rect_rect(rect, other);
+        }
+    }
+}
+
+bool entity_collider_exists(Entity* entity) {
+    return entity->collider != NULL;
+}
+
+void entity_send_event(
+    Entity* sender,
+    Entity* receiver,
+    GameManager* manager,
+    uint32_t type,
+    EntityEventValue value) {
+    if(receiver->description && receiver->description->event) {
+        EntityEvent event = {
+            .type = type,
+            .sender = sender,
+            .value = value,
+        };
+        receiver->description->event(receiver, manager, event, receiver->context);
+    }
+}

+ 65 - 0
non_catalog_apps/air_arkanoid/engine/entity.h

@@ -0,0 +1,65 @@
+#pragma once
+#include "vector.h"
+#include "game_engine.h"
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Entity Entity;
+
+typedef struct Level Level;
+
+typedef union {
+    uint32_t value;
+    void* pointer;
+} EntityEventValue;
+
+typedef struct {
+    uint32_t type;
+    Entity* sender;
+    EntityEventValue value;
+} EntityEvent;
+
+typedef struct Level Level;
+typedef struct GameManager GameManager;
+
+typedef struct {
+    void (*start)(Entity* self, GameManager* manager, void* context);
+    void (*stop)(Entity* self, GameManager* manager, void* context);
+    void (*update)(Entity* self, GameManager* manager, void* context);
+    void (*render)(Entity* self, GameManager* manager, Canvas* canvas, void* context);
+    void (*collision)(Entity* self, Entity* other, GameManager* manager, void* context);
+    void (*event)(Entity* self, GameManager* manager, EntityEvent event, void* context);
+    size_t context_size;
+} EntityDescription;
+
+const EntityDescription* entity_description_get(Entity* entity);
+
+Vector entity_pos_get(Entity* entity);
+
+void entity_pos_set(Entity* entity, Vector position);
+
+void* entity_context_get(Entity* entity);
+
+void entity_collider_add_circle(Entity* entity, float radius);
+
+void entity_collider_add_rect(Entity* entity, float width, float height);
+
+void entity_collider_remove(Entity* entity);
+
+void entity_collider_offset_set(Entity* entity, Vector offset);
+
+Vector entity_collider_offset_get(Entity* entity);
+
+void entity_send_event(
+    Entity* sender,
+    Entity* receiver,
+    GameManager* manager,
+    uint32_t type,
+    EntityEventValue value);
+
+#ifdef __cplusplus
+}
+#endif

+ 58 - 0
non_catalog_apps/air_arkanoid/engine/entity_i.h

@@ -0,0 +1,58 @@
+#pragma once
+#include "entity.h"
+#include "game_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+    ColliderTypeCircle,
+    ColliderTypeRect,
+} ColliderType;
+
+typedef struct {
+    ColliderType type;
+    union {
+        struct {
+            float radius;
+        } circle;
+        struct {
+            float half_width;
+            float half_height;
+        } rect;
+    };
+} Collider;
+
+struct Entity {
+    Vector position;
+    const EntityDescription* description;
+    void* context;
+    Collider* collider;
+    Vector collider_offset;
+    bool collider_dirty;
+};
+
+Entity* entity_alloc(const EntityDescription* behaviour);
+
+void entity_free(Entity* entity);
+
+void entity_call_start(Entity* entity, GameManager* manager);
+
+void entity_call_stop(Entity* entity, GameManager* manager);
+
+void entity_call_update(Entity* entity, GameManager* manager);
+
+void entity_call_render(Entity* entity, GameManager* manager, Canvas* canvas);
+
+void entity_call_collision(Entity* entity, Entity* other, GameManager* manager);
+
+bool entity_collider_check_collision(Entity* entity, Entity* other);
+
+bool entity_collider_exists(Entity* entity);
+
+int32_t entities_get_count(void);
+
+#ifdef __cplusplus
+}
+#endif

+ 199 - 0
non_catalog_apps/air_arkanoid/engine/game_engine.c

@@ -0,0 +1,199 @@
+#include "game_engine.h"
+#include <furi.h>
+#include <gui/gui.h>
+#include <input/input.h>
+#include <notification/notification_messages.h>
+#include "clock_timer.h"
+
+typedef _Atomic uint32_t AtomicUint32;
+
+GameEngineSettings game_engine_settings_init() {
+    GameEngineSettings settings;
+    settings.target_fps = 30.0f;
+    settings.show_fps = false;
+    settings.always_backlight = true;
+    settings.start_callback = NULL;
+    settings.frame_callback = NULL;
+    settings.stop_callback = NULL;
+    settings.context = NULL;
+    return settings;
+}
+
+struct GameEngine {
+    Gui* gui;
+    NotificationApp* notifications;
+    FuriPubSub* input_pubsub;
+    FuriThreadId thread_id;
+    GameEngineSettings settings;
+    float fps;
+};
+
+typedef enum {
+    GameThreadFlagUpdate = 1 << 0,
+    GameThreadFlagStop = 1 << 1,
+} GameThreadFlag;
+
+#define GameThreadFlagMask (GameThreadFlagUpdate | GameThreadFlagStop)
+
+GameEngine* game_engine_alloc(GameEngineSettings settings) {
+    furi_check(settings.frame_callback != NULL);
+
+    GameEngine* engine = malloc(sizeof(GameEngine));
+    engine->gui = furi_record_open(RECORD_GUI);
+    engine->notifications = furi_record_open(RECORD_NOTIFICATION);
+    engine->input_pubsub = furi_record_open(RECORD_INPUT_EVENTS);
+    engine->thread_id = furi_thread_get_current_id();
+    engine->settings = settings;
+    engine->fps = 1.0f;
+
+    return engine;
+}
+
+void game_engine_free(GameEngine* engine) {
+    furi_record_close(RECORD_GUI);
+    furi_record_close(RECORD_NOTIFICATION);
+    furi_record_close(RECORD_INPUT_EVENTS);
+    free(engine);
+}
+
+static void clock_timer_callback(void* context) {
+    GameEngine* engine = context;
+    furi_thread_flags_set(engine->thread_id, GameThreadFlagUpdate);
+}
+
+static const GameKey keys[] = {
+    [InputKeyUp] = GameKeyUp,
+    [InputKeyDown] = GameKeyDown,
+    [InputKeyRight] = GameKeyRight,
+    [InputKeyLeft] = GameKeyLeft,
+    [InputKeyOk] = GameKeyOk,
+    [InputKeyBack] = GameKeyBack,
+};
+
+static const size_t keys_count = sizeof(keys) / sizeof(keys[0]);
+
+static void input_events_callback(const void* value, void* context) {
+    AtomicUint32* input_state = context;
+    const InputEvent* event = value;
+
+    if(event->key < keys_count) {
+        switch(event->type) {
+        case InputTypePress:
+            *input_state |= (keys[event->key]);
+            break;
+        case InputTypeRelease:
+            *input_state &= ~(keys[event->key]);
+            break;
+        default:
+            break;
+        }
+    }
+}
+
+void game_engine_run(GameEngine* engine) {
+    // input state
+    AtomicUint32 input_state = 0;
+    uint32_t input_prev_state = 0;
+
+    // set backlight if needed
+    if(engine->settings.always_backlight) {
+        notification_message(engine->notifications, &sequence_display_backlight_enforce_on);
+    }
+
+    // acquire gui canvas
+    Canvas* canvas = gui_direct_draw_acquire(engine->gui);
+
+    // subscribe to input events
+    FuriPubSubSubscription* input_subscription =
+        furi_pubsub_subscribe(engine->input_pubsub, input_events_callback, &input_state);
+
+    // call start callback, if any
+    if(engine->settings.start_callback) {
+        engine->settings.start_callback(engine, engine->settings.context);
+    }
+
+    // start "game update" timer
+    clock_timer_start(clock_timer_callback, engine, engine->settings.target_fps);
+
+    // init fps counter
+    uint32_t time_start = DWT->CYCCNT;
+
+    while(true) {
+        uint32_t flags =
+            furi_thread_flags_wait(GameThreadFlagMask, FuriFlagWaitAny, FuriWaitForever);
+        furi_check((flags & FuriFlagError) == 0);
+
+        if(flags & GameThreadFlagUpdate) {
+            // update fps counter
+            uint32_t time_end = DWT->CYCCNT;
+            uint32_t time_delta = time_end - time_start;
+            time_start = time_end;
+
+            // update input state
+            uint32_t input_current_state = input_state;
+            InputState input = {
+                .held = input_current_state,
+                .pressed = input_current_state & ~input_prev_state,
+                .released = ~input_current_state & input_prev_state,
+            };
+            input_prev_state = input_current_state;
+
+            // clear screen
+            canvas_reset(canvas);
+
+            // calculate actual fps
+            engine->fps = (float)SystemCoreClock / time_delta;
+
+            // do the work
+            engine->settings.frame_callback(engine, canvas, input, engine->settings.context);
+
+            // show fps if needed
+            if(engine->settings.show_fps) {
+                canvas_set_color(canvas, ColorXOR);
+                canvas_printf(canvas, 0, 7, "%u", (uint32_t)roundf(engine->fps));
+            }
+
+            // and output screen buffer
+            canvas_commit(canvas);
+
+            // throttle a bit
+            furi_delay_tick(2);
+        }
+
+        if(flags & GameThreadFlagStop) {
+            break;
+        }
+    }
+
+    // stop timer
+    clock_timer_stop();
+
+    // call stop callback, if any
+    if(engine->settings.stop_callback) {
+        engine->settings.stop_callback(engine, engine->settings.context);
+    }
+
+    // release gui canvas and unsubscribe from input events
+    gui_direct_draw_release(engine->gui);
+    furi_pubsub_unsubscribe(engine->input_pubsub, input_subscription);
+
+    if(engine->settings.always_backlight) {
+        notification_message(engine->notifications, &sequence_display_backlight_enforce_auto);
+    }
+}
+
+void game_engine_stop(GameEngine* engine) {
+    furi_thread_flags_set(engine->thread_id, GameThreadFlagStop);
+}
+
+float game_engine_get_delta_time(GameEngine* engine) {
+    return 1.0f / engine->fps;
+}
+
+float game_engine_get_delta_frames(GameEngine* engine) {
+    return engine->fps / engine->settings.target_fps;
+}
+
+void game_engine_show_fps_set(GameEngine* engine, bool show_fps) {
+    engine->settings.show_fps = show_fps;
+}

+ 88 - 0
non_catalog_apps/air_arkanoid/engine/game_engine.h

@@ -0,0 +1,88 @@
+#pragma once
+#include <stdbool.h>
+#include "canvas.h"
+#include <gui/canvas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+    GameKeyUp = 1 << 0,
+    GameKeyDown = 1 << 1,
+    GameKeyRight = 1 << 2,
+    GameKeyLeft = 1 << 3,
+    GameKeyOk = 1 << 4,
+    GameKeyBack = 1 << 5,
+} GameKey;
+
+typedef struct {
+    uint32_t held; // mask of GameKey held in current frame
+    uint32_t pressed; // mask of GameKey pressed in current frame
+    uint32_t released; // mask of GameKey released in current frame
+} InputState;
+
+typedef struct GameEngine GameEngine;
+
+typedef void (*GameEngineStartCallback)(GameEngine* engine, void* context);
+
+typedef void (*GameEngineStopCallback)(GameEngine* engine, void* context);
+
+typedef void (
+    *GameEngineFrameCallback)(GameEngine* engine, Canvas* canvas, InputState input, void* context);
+
+typedef struct {
+    float target_fps; // target fps
+    bool show_fps; // show fps counter
+    bool always_backlight; // keep backlight on
+    GameEngineStartCallback start_callback; // called when engine starts
+    GameEngineFrameCallback frame_callback; // frame callback, called at target fps
+    GameEngineStopCallback stop_callback; // called when engine stops
+    void* context; // user context passed to callback
+} GameEngineSettings;
+
+/** Default settings initializer */
+GameEngineSettings game_engine_settings_init(void);
+
+/** Game Engine allocator
+ * @param settings engine settings
+ * @return GameEngine*  GameEngine instance
+ */
+GameEngine* game_engine_alloc(GameEngineSettings settings);
+
+/** Run the Game Engine. Blocks until game_engine_stop() is called.
+ * @param engine GameEngine instance
+ */
+void game_engine_run(GameEngine* engine);
+
+/** Free the Game Engine
+ * @param engine GameEngine instance
+ */
+void game_engine_free(GameEngine* engine);
+
+/** Stop the Game Engine, will not block execution
+ * @param engine GameEngine instance
+ */
+void game_engine_stop(GameEngine* engine);
+
+/** Get delta time between current and previous frame
+ * @param engine GameEngine instance
+ * @return float  delta time in seconds
+ */
+float game_engine_get_delta_time(GameEngine* engine);
+
+/** Get delta frames between current and previous frame
+ * @param engine GameEngine instance
+ * @return float  delta frames
+ */
+float game_engine_get_delta_frames(GameEngine* engine);
+
+/** Enable/disable show fps counter
+ * @param engine GameEngine instance
+ * @param show_fps show fps counter
+ */
+void game_engine_show_fps_set(GameEngine* engine, bool show_fps);
+
+#ifdef __cplusplus
+}
+#endif

+ 162 - 0
non_catalog_apps/air_arkanoid/engine/game_manager.c

@@ -0,0 +1,162 @@
+#include "game_manager.h"
+#include "level_i.h"
+#include <furi.h>
+#include <m-list.h>
+#include <storage/storage.h>
+
+typedef struct {
+    Sprite* sprite;
+    FuriString* path;
+} SpriteCache;
+
+LIST_DEF(LevelList, Level*, M_POD_OPLIST);
+LIST_DEF(SpriteCacheList, SpriteCache, M_POD_OPLIST);
+
+struct GameManager {
+    LevelList_t levels;
+    Level* current_level;
+    Level* next_level;
+
+    GameEngine* engine;
+    InputState input;
+    void* game_context;
+
+    SpriteCacheList_t sprites;
+};
+
+GameManager* game_manager_alloc() {
+    GameManager* manager = malloc(sizeof(GameManager));
+    LevelList_init(manager->levels);
+    manager->current_level = NULL;
+    manager->next_level = NULL;
+    manager->engine = NULL;
+    manager->game_context = NULL;
+    memset(&manager->input, 0, sizeof(InputState));
+    SpriteCacheList_init(manager->sprites);
+    return manager;
+}
+
+void game_manager_free(GameManager* manager) {
+    level_call_stop(manager->current_level);
+
+    // Free all levels
+    {
+        LevelList_it_t it;
+        LevelList_it(it, manager->levels);
+        while(!LevelList_end_p(it)) {
+            level_call_free(*LevelList_cref(it));
+            level_free(*LevelList_cref(it));
+            LevelList_next(it);
+        }
+    }
+
+    LevelList_clear(manager->levels);
+
+    // Free all sprites
+    {
+        SpriteCacheList_it_t it;
+        SpriteCacheList_it(it, manager->sprites);
+        while(!SpriteCacheList_end_p(it)) {
+            furi_string_free(SpriteCacheList_cref(it)->path);
+            sprite_free(SpriteCacheList_cref(it)->sprite);
+            SpriteCacheList_next(it);
+        }
+    }
+    SpriteCacheList_clear(manager->sprites);
+    free(manager);
+}
+
+Level* game_manager_add_level(GameManager* manager, const LevelBehaviour* behaviour) {
+    UNUSED(manager);
+    Level* level = level_alloc(behaviour, manager);
+    LevelList_push_back(manager->levels, level);
+    level_call_alloc(level);
+    if(!manager->current_level) {
+        manager->current_level = level;
+        level_call_start(level);
+    }
+    return level;
+}
+
+void game_manager_next_level_set(GameManager* manager, Level* next_level) {
+    manager->next_level = next_level;
+}
+
+void game_manager_game_stop(GameManager* manager) {
+    GameEngine* engine = game_manager_engine_get(manager);
+    game_engine_stop(engine);
+}
+
+Level* game_manager_current_level_get(GameManager* manager) {
+    return manager->current_level;
+}
+
+void game_manager_update(GameManager* manager) {
+    if(manager->next_level) {
+        level_call_stop(manager->current_level);
+        manager->current_level = manager->next_level;
+        level_call_start(manager->current_level);
+        manager->next_level = NULL;
+    }
+
+    level_update(manager->current_level, manager);
+}
+
+void game_manager_render(GameManager* manager, Canvas* canvas) {
+    level_render(manager->current_level, manager, canvas);
+}
+
+void game_manager_engine_set(GameManager* manager, GameEngine* engine) {
+    manager->engine = engine;
+}
+
+void game_manager_input_set(GameManager* manager, InputState input) {
+    manager->input = input;
+}
+
+void game_manager_game_context_set(GameManager* manager, void* context) {
+    manager->game_context = context;
+}
+
+GameEngine* game_manager_engine_get(GameManager* manager) {
+    return manager->engine;
+}
+
+InputState game_manager_input_get(GameManager* manager) {
+    return manager->input;
+}
+
+void* game_manager_game_context_get(GameManager* manager) {
+    return manager->game_context;
+}
+
+void game_manager_show_fps_set(GameManager* manager, bool show_fps) {
+    GameEngine* engine = game_manager_engine_get(manager);
+    game_engine_show_fps_set(engine, show_fps);
+}
+
+Sprite* game_manager_sprite_load(GameManager* manager, const char* path) {
+    SpriteCacheList_it_t it;
+    SpriteCacheList_it(it, manager->sprites);
+    while(!SpriteCacheList_end_p(it)) {
+        if(furi_string_cmp(SpriteCacheList_cref(it)->path, path) == 0) {
+            return SpriteCacheList_cref(it)->sprite;
+        }
+        SpriteCacheList_next(it);
+    }
+
+    FuriString* path_full = furi_string_alloc_set(APP_ASSETS_PATH("sprites/"));
+    furi_string_cat(path_full, path);
+
+    Sprite* sprite = sprite_alloc(furi_string_get_cstr(path_full));
+    if(sprite) {
+        SpriteCache cache = {
+            .sprite = sprite,
+            .path = furi_string_alloc_set(path),
+        };
+        SpriteCacheList_push_back(manager->sprites, cache);
+    }
+    furi_string_free(path_full);
+
+    return sprite;
+}

+ 40 - 0
non_catalog_apps/air_arkanoid/engine/game_manager.h

@@ -0,0 +1,40 @@
+#pragma once
+#include "level.h"
+#include "game_engine.h"
+#include "sprite.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct GameManager GameManager;
+
+Level* game_manager_add_level(GameManager* manager, const LevelBehaviour* behaviour);
+
+void game_manager_next_level_set(GameManager* manager, Level* level);
+
+Level* game_manager_current_level_get(GameManager* manager);
+
+GameEngine* game_manager_engine_get(GameManager* manager);
+
+InputState game_manager_input_get(GameManager* manager);
+
+void* game_manager_game_context_get(GameManager* manager);
+
+void game_manager_game_stop(GameManager* manager);
+
+void game_manager_show_fps_set(GameManager* manager, bool show_fps);
+
+/**
+ * @brief Load a sprite from a file
+ * Sprite will be cached and reused if the same file is loaded again
+ * 
+ * @param manager game manager instance
+ * @param path sprite file path, relative to the game's assets folder
+ * @return Sprite* or NULL if the sprite could not be loaded
+ */
+Sprite* game_manager_sprite_load(GameManager* manager, const char* path);
+
+#ifdef __cplusplus
+}
+#endif

+ 24 - 0
non_catalog_apps/air_arkanoid/engine/game_manager_i.h

@@ -0,0 +1,24 @@
+#pragma once
+#include "game_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+GameManager* game_manager_alloc(void);
+
+void game_manager_free(GameManager* manager);
+
+void game_manager_update(GameManager* manager);
+
+void game_manager_render(GameManager* manager, Canvas* canvas);
+
+void game_manager_engine_set(GameManager* manager, GameEngine* engine);
+
+void game_manager_input_set(GameManager* manager, InputState input);
+
+void game_manager_game_context_set(GameManager* manager, void* context);
+
+#ifdef __cplusplus
+}
+#endif

+ 249 - 0
non_catalog_apps/air_arkanoid/engine/level.c

@@ -0,0 +1,249 @@
+#include "level.h"
+#include "level_i.h"
+#include "entity_i.h"
+#include <m-list.h>
+#include <furi.h>
+
+LIST_DEF(EntityList, Entity*, M_POD_OPLIST);
+#define M_OPL_EntityList_t() LIST_OPLIST(EntityList)
+#define FOREACH(name, list) for \
+    M_EACH(name, list, EntityList_t)
+
+#define LEVEL_DEBUG(...) FURI_LOG_D("Level", __VA_ARGS__)
+#define LEVEL_ERROR(...) FURI_LOG_E("Level", __VA_ARGS__)
+
+struct Level {
+    EntityList_t entities;
+    EntityList_t to_add;
+    EntityList_t to_remove;
+    const LevelBehaviour* behaviour;
+    void* context;
+    GameManager* manager;
+};
+
+Level* level_alloc(const LevelBehaviour* behaviour, GameManager* manager) {
+    Level* level = malloc(sizeof(Level));
+    level->manager = manager;
+    EntityList_init(level->entities);
+    EntityList_init(level->to_add);
+    EntityList_init(level->to_remove);
+    level->behaviour = behaviour;
+    if(behaviour->context_size > 0) {
+        level->context = malloc(behaviour->context_size);
+    } else {
+        level->context = NULL;
+    }
+    LEVEL_DEBUG("Allocated level at %p", level);
+    return level;
+}
+
+static void level_process_add(Level* level) {
+    // move entities from to_add to entities
+    FOREACH(item, level->to_add) {
+        EntityList_push_back(level->entities, *item);
+    }
+    EntityList_clear(level->to_add);
+}
+
+static void level_process_remove(Level* level) {
+    // remove entities in to_remove from entities and free them
+    FOREACH(item, level->to_remove) {
+        entity_free(*item);
+        EntityList_it_t it;
+
+        // find and remove the entity from the entities list
+        for(EntityList_it(it, level->entities); !EntityList_end_p(it); EntityList_next(it)) {
+            if(*EntityList_ref(it) == *item) {
+                EntityList_remove(level->entities, it);
+                break;
+            }
+        }
+    }
+    EntityList_clear(level->to_remove);
+}
+
+static bool level_entity_in_list_p(EntityList_t list, Entity* entity) {
+    FOREACH(item, list) {
+        if(*item == entity) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void level_free(Level* level) {
+    level_clear(level);
+
+    EntityList_clear(level->entities);
+    EntityList_clear(level->to_add);
+    EntityList_clear(level->to_remove);
+
+    if(level->behaviour->context_size > 0) {
+        free(level->context);
+    }
+
+    LEVEL_DEBUG("Freeing level at %p", level);
+    free(level);
+}
+
+void level_clear(Level* level) {
+    size_t iterations = 0;
+
+    do {
+        // process to_add and to_remove
+        level_process_add(level);
+        level_process_remove(level);
+
+        // remove entities from entities list
+        FOREACH(item, level->entities) {
+            if(!level_entity_in_list_p(level->to_remove, *item)) {
+                level_remove_entity(level, *item);
+            }
+        }
+
+        // check if we are looping too many times
+        iterations++;
+        if(iterations >= 100) {
+            LEVEL_ERROR("Level free looped too many times");
+        }
+
+        // entity_call_stop can call level_remove_entity or level_add_entity
+        // so we need to process to_add and to_remove again
+    } while(!EntityList_empty_p(level->to_add) || !EntityList_empty_p(level->to_remove));
+}
+
+Entity* level_add_entity(Level* level, const EntityDescription* description) {
+    Entity* entity = entity_alloc(description);
+    EntityList_push_back(level->to_add, entity);
+    entity_call_start(entity, level->manager);
+    return entity;
+}
+
+void level_remove_entity(Level* level, Entity* entity) {
+    EntityList_push_back(level->to_remove, entity);
+    entity_call_stop(entity, level->manager);
+}
+
+void level_send_event(
+    Level* level,
+    Entity* sender,
+    const EntityDescription* receiver_desc,
+    uint32_t type,
+    EntityEventValue value) {
+    FOREACH(item, level->entities) {
+        if(receiver_desc == entity_description_get(*item) || receiver_desc == NULL) {
+            entity_send_event(sender, *item, level->manager, type, value);
+        }
+    }
+
+    FOREACH(item, level->to_add) {
+        if(receiver_desc == entity_description_get(*item) || receiver_desc == NULL) {
+            entity_send_event(sender, *item, level->manager, type, value);
+        }
+    }
+}
+
+static void level_process_update(Level* level, GameManager* manager) {
+    FOREACH(item, level->entities) {
+        entity_call_update(*item, manager);
+    }
+}
+
+static void level_process_collision(Level* level, GameManager* manager) {
+    EntityList_it_t it_first;
+    EntityList_it_t it_second;
+
+    EntityList_it(it_first, level->entities);
+    while(!EntityList_end_p(it_first)) {
+        Entity* first = *EntityList_ref(it_first);
+        if(entity_collider_exists(first)) {
+            // start second iterator at the next entity,
+            // so we don't check the same pair twice
+            EntityList_it_set(it_second, it_first);
+            EntityList_next(it_second);
+            while(!EntityList_end_p(it_second)) {
+                Entity* second = *EntityList_ref(it_second);
+                if(first->collider_dirty || second->collider_dirty) {
+                    if(entity_collider_exists(second)) {
+                        if(entity_collider_check_collision(first, second)) {
+                            entity_call_collision(first, second, manager);
+                            entity_call_collision(second, first, manager);
+                        }
+                    }
+                }
+                EntityList_next(it_second);
+            }
+        }
+        EntityList_next(it_first);
+    }
+
+    FOREACH(item, level->entities) {
+        (*item)->collider_dirty = false;
+    }
+}
+
+void level_update(Level* level, GameManager* manager) {
+    level_process_add(level);
+    level_process_remove(level);
+    level_process_update(level, manager);
+    level_process_collision(level, manager);
+}
+
+void level_render(Level* level, GameManager* manager, Canvas* canvas) {
+    FOREACH(item, level->entities) {
+        entity_call_render(*item, manager, canvas);
+    }
+}
+
+void level_call_start(Level* level) {
+    if(level->behaviour->start) {
+        level->behaviour->start(level, level->manager, level->context);
+    }
+}
+
+void level_call_stop(Level* level) {
+    if(level->behaviour->stop) {
+        level->behaviour->stop(level, level->manager, level->context);
+    }
+}
+
+void level_call_alloc(Level* level) {
+    if(level->behaviour->alloc) {
+        level->behaviour->alloc(level, level->manager, level->context);
+    }
+}
+
+void level_call_free(Level* level) {
+    if(level->behaviour->free) {
+        level->behaviour->free(level, level->manager, level->context);
+    }
+}
+
+size_t level_entity_count(const Level* level, const EntityDescription* description) {
+    size_t count = 0;
+    FOREACH(item, level->entities) {
+        if(description == NULL || description == entity_description_get(*item)) {
+            count++;
+        }
+    }
+
+    // subtract entities that are in to_remove
+    FOREACH(item, level->to_remove) {
+        if(description == NULL || description == entity_description_get(*item)) {
+            count--;
+        }
+    }
+
+    // add entities that are in to_add
+    FOREACH(item, level->to_add) {
+        if(description == NULL || description == entity_description_get(*item)) {
+            count++;
+        }
+    }
+
+    return count;
+}
+
+void* level_context_get(Level* level) {
+    return level->context;
+}

+ 78 - 0
non_catalog_apps/air_arkanoid/engine/level.h

@@ -0,0 +1,78 @@
+#pragma once
+#include <stddef.h>
+#include "entity.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct GameManager GameManager;
+
+typedef struct {
+    void (*alloc)(Level* level, GameManager* manager, void* context);
+    void (*free)(Level* level, GameManager* manager, void* context);
+    void (*start)(Level* level, GameManager* manager, void* context);
+    void (*stop)(Level* level, GameManager* manager, void* context);
+    size_t context_size;
+} LevelBehaviour;
+
+/**
+ * @brief Remove all entities from the level
+ * 
+ * @param level level instance
+ */
+void level_clear(Level* level);
+
+/**
+ * @brief Add an entity to the level
+ * 
+ * @param level level instance
+ * @param behaviour entity behaviour
+ * @return Entity* 
+ */
+Entity* level_add_entity(Level* level, const EntityDescription* behaviour);
+
+/**
+ * @brief Remove an entity from the level
+ * 
+ * @param level level instance
+ * @param entity entity to remove
+ */
+void level_remove_entity(Level* level, Entity* entity);
+
+/**
+ * @brief Send an event to all entities of a certain type in the level
+ * 
+ * @param level level instance
+ * @param sender entity that sends the event
+ * @param receiver_desc entity description that will receive the event, NULL for all entities
+ * @param type event type
+ * @param value event value
+ */
+void level_send_event(
+    Level* level,
+    Entity* sender,
+    const EntityDescription* receiver_desc,
+    uint32_t type,
+    EntityEventValue value);
+
+/**
+ * @brief Get the count of entities of a certain type in the level, or all entities if description is NULL
+ * 
+ * @param level level instance
+ * @param description entity description, NULL for all entities
+ * @return size_t entity count 
+ */
+size_t level_entity_count(const Level* level, const EntityDescription* description);
+
+/**
+ * @brief Get the context of the level
+ * 
+ * @param level level instance
+ * @return void* context
+ */
+void* level_context_get(Level* level);
+
+#ifdef __cplusplus
+}
+#endif

+ 26 - 0
non_catalog_apps/air_arkanoid/engine/level_i.h

@@ -0,0 +1,26 @@
+#pragma once
+#include "level.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+Level* level_alloc(const LevelBehaviour* behaviour, GameManager* manager);
+
+void level_free(Level* level);
+
+void level_update(Level* level, GameManager* manager);
+
+void level_render(Level* level, GameManager* manager, Canvas* canvas);
+
+void level_call_alloc(Level* level);
+
+void level_call_free(Level* level);
+
+void level_call_start(Level* level);
+
+void level_call_stop(Level* level);
+
+#ifdef __cplusplus
+}
+#endif

+ 54 - 0
non_catalog_apps/air_arkanoid/engine/main.c

@@ -0,0 +1,54 @@
+#include <furi.h>
+#include "engine.h"
+#include "game_engine.h"
+#include "game_manager_i.h"
+#include "level_i.h"
+#include "entity_i.h"
+
+static void frame_cb(GameEngine* engine, Canvas* canvas, InputState input, void* context) {
+    UNUSED(engine);
+    GameManager* game_manager = context;
+    game_manager_input_set(game_manager, input);
+    game_manager_update(game_manager);
+    game_manager_render(game_manager, canvas);
+}
+
+int32_t game_app(void* p) {
+    UNUSED(p);
+    GameManager* game_manager = game_manager_alloc();
+
+    GameEngineSettings settings = game_engine_settings_init();
+    settings.target_fps = game.target_fps;
+    settings.show_fps = game.show_fps;
+    settings.always_backlight = game.always_backlight;
+    settings.frame_callback = frame_cb;
+    settings.context = game_manager;
+
+    GameEngine* engine = game_engine_alloc(settings);
+    game_manager_engine_set(game_manager, engine);
+
+    void* game_context = NULL;
+    if(game.context_size > 0) {
+        game_context = malloc(game.context_size);
+        game_manager_game_context_set(game_manager, game_context);
+    }
+    game.start(game_manager, game_context);
+
+    game_engine_run(engine);
+    game_engine_free(engine);
+
+    game_manager_free(game_manager);
+
+    game.stop(game_context);
+    if(game_context) {
+        free(game_context);
+    }
+
+    int32_t entities = entities_get_count();
+    if(entities != 0) {
+        FURI_LOG_E("Game", "Memory leak detected: %ld entities still allocated", entities);
+        return -1;
+    }
+
+    return 0;
+}

+ 84 - 0
non_catalog_apps/air_arkanoid/engine/scripts/sprite_builder.py

@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+import argparse
+import io
+import logging
+import os
+import struct
+
+from PIL import Image, ImageOps
+
+# XBM flipper sprite (.fxbm) is 1-bit depth, width-padded to 8 bits
+# file format:
+#   uint32 size of the rest of the file in bytes
+#   uint32 width in px
+#   uint32 height in px
+#   uint8[] pixel data, every row is padded to 8 bits (like XBM)
+
+def image2xbm(input_file_path):
+    with Image.open(input_file_path) as im:
+        with io.BytesIO() as output:
+            bw = im.convert("1")
+            bw = ImageOps.invert(bw)
+            bw.save(output, format="XBM")
+            return output.getvalue()
+
+def xbm2fxbm(data):
+    # hell as it is, but it works
+    f = io.StringIO(data.decode().strip())
+    width = int(f.readline().strip().split(" ")[2])
+    height = int(f.readline().strip().split(" ")[2])
+    data = f.read().strip().replace("\n", "").replace(" ", "").split("=")[1][:-1]
+    data_str = data[1:-1].replace(",", " ").replace("0x", "")
+    image_bin = bytearray.fromhex(data_str)
+
+    output = struct.pack("<I", len(image_bin) + 8)
+    output += struct.pack("<II", width, height)
+    output += image_bin
+    return output
+
+def process_sprites(input_dir, output_dir):
+    for root, dirs, files in os.walk(input_dir):
+        for file in files:
+            if file.startswith('.'):
+                continue
+            
+            try:
+                input_file_path = os.path.join(root, file)
+                rel_path = os.path.relpath(input_file_path, input_dir)
+                new_rel_path = os.path.splitext(rel_path)[0] + ".fxbm"
+                output_file_path = os.path.join(output_dir, new_rel_path)
+
+                os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
+
+                print(f"Converting '{rel_path}' to '{new_rel_path}'")
+                xbm = image2xbm(input_file_path)
+                img_data = xbm2fxbm(xbm)
+                with open(output_file_path, "wb") as f:
+                    f.write(img_data)
+            except Exception as e:
+                print(f"Cannot convert '{rel_path}': {e}")
+
+def clear_directory(directory):
+    for root, dirs, files in os.walk(directory, topdown=False):
+        for name in files:
+            os.remove(os.path.join(root, name))
+        for name in dirs:
+            os.rmdir(os.path.join(root, name))
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("source", help="Source directory")
+    parser.add_argument("target", help="Target directory")
+    args = parser.parse_args()
+
+    logging.basicConfig(level=logging.ERROR)
+    logger = logging.getLogger(__name__)
+    logger.debug(f"Building sprites from {args.source} to {args.target}")
+
+    clear_directory(args.target)
+    process_sprites(args.source, args.target)
+
+    return 0
+
+if __name__ == "__main__":
+    main()

+ 297 - 0
non_catalog_apps/air_arkanoid/engine/sensors/ICM42688P/ICM42688P.c

@@ -0,0 +1,297 @@
+#include "ICM42688P_regs.h"
+#include "ICM42688P.h"
+
+#define TAG "ICM42688P"
+
+#define ICM42688P_TIMEOUT 100
+
+struct ICM42688P {
+    FuriHalSpiBusHandle* spi_bus;
+    const GpioPin* irq_pin;
+    float accel_scale;
+    float gyro_scale;
+};
+
+static const struct AccelFullScale {
+    float value;
+    uint8_t reg_mask;
+} accel_fs_modes[] = {
+    [AccelFullScale16G] = {16.f, ICM42688_AFS_16G},
+    [AccelFullScale8G] = {8.f, ICM42688_AFS_8G},
+    [AccelFullScale4G] = {4.f, ICM42688_AFS_4G},
+    [AccelFullScale2G] = {2.f, ICM42688_AFS_2G},
+};
+
+static const struct GyroFullScale {
+    float value;
+    uint8_t reg_mask;
+} gyro_fs_modes[] = {
+    [GyroFullScale2000DPS] = {2000.f, ICM42688_GFS_2000DPS},
+    [GyroFullScale1000DPS] = {1000.f, ICM42688_GFS_1000DPS},
+    [GyroFullScale500DPS] = {500.f, ICM42688_GFS_500DPS},
+    [GyroFullScale250DPS] = {250.f, ICM42688_GFS_250DPS},
+    [GyroFullScale125DPS] = {125.f, ICM42688_GFS_125DPS},
+    [GyroFullScale62_5DPS] = {62.5f, ICM42688_GFS_62_5DPS},
+    [GyroFullScale31_25DPS] = {31.25f, ICM42688_GFS_31_25DPS},
+    [GyroFullScale15_625DPS] = {15.625f, ICM42688_GFS_15_625DPS},
+};
+
+static bool icm42688p_write_reg(FuriHalSpiBusHandle* spi_bus, uint8_t addr, uint8_t value) {
+    bool res = false;
+    furi_hal_spi_acquire(spi_bus);
+    do {
+        uint8_t cmd_data[2] = {addr & 0x7F, value};
+        if(!furi_hal_spi_bus_tx(spi_bus, cmd_data, 2, ICM42688P_TIMEOUT)) break;
+        res = true;
+    } while(0);
+    furi_hal_spi_release(spi_bus);
+    return res;
+}
+
+static bool icm42688p_read_reg(FuriHalSpiBusHandle* spi_bus, uint8_t addr, uint8_t* value) {
+    bool res = false;
+    furi_hal_spi_acquire(spi_bus);
+    do {
+        uint8_t cmd_byte = addr | (1 << 7);
+        if(!furi_hal_spi_bus_tx(spi_bus, &cmd_byte, 1, ICM42688P_TIMEOUT)) break;
+        if(!furi_hal_spi_bus_rx(spi_bus, value, 1, ICM42688P_TIMEOUT)) break;
+        res = true;
+    } while(0);
+    furi_hal_spi_release(spi_bus);
+    return res;
+}
+
+static bool
+    icm42688p_read_mem(FuriHalSpiBusHandle* spi_bus, uint8_t addr, uint8_t* data, uint8_t len) {
+    bool res = false;
+    furi_hal_spi_acquire(spi_bus);
+    do {
+        uint8_t cmd_byte = addr | (1 << 7);
+        if(!furi_hal_spi_bus_tx(spi_bus, &cmd_byte, 1, ICM42688P_TIMEOUT)) break;
+        if(!furi_hal_spi_bus_rx(spi_bus, data, len, ICM42688P_TIMEOUT)) break;
+        res = true;
+    } while(0);
+    furi_hal_spi_release(spi_bus);
+    return res;
+}
+
+bool icm42688p_accel_config(
+    ICM42688P* icm42688p,
+    ICM42688PAccelFullScale full_scale,
+    ICM42688PDataRate rate) {
+    icm42688p->accel_scale = accel_fs_modes[full_scale].value;
+    uint8_t reg_value = accel_fs_modes[full_scale].reg_mask | rate;
+    return icm42688p_write_reg(icm42688p->spi_bus, ICM42688_ACCEL_CONFIG0, reg_value);
+}
+
+float icm42688p_accel_get_full_scale(ICM42688P* icm42688p) {
+    return icm42688p->accel_scale;
+}
+
+bool icm42688p_gyro_config(
+    ICM42688P* icm42688p,
+    ICM42688PGyroFullScale full_scale,
+    ICM42688PDataRate rate) {
+    icm42688p->gyro_scale = gyro_fs_modes[full_scale].value;
+    uint8_t reg_value = gyro_fs_modes[full_scale].reg_mask | rate;
+    return icm42688p_write_reg(icm42688p->spi_bus, ICM42688_GYRO_CONFIG0, reg_value);
+}
+
+float icm42688p_gyro_get_full_scale(ICM42688P* icm42688p) {
+    return icm42688p->gyro_scale;
+}
+
+bool icm42688p_read_accel_raw(ICM42688P* icm42688p, ICM42688PRawData* data) {
+    bool ret = icm42688p_read_mem(
+        icm42688p->spi_bus, ICM42688_ACCEL_DATA_X1, (uint8_t*)data, sizeof(ICM42688PRawData));
+    return ret;
+}
+
+bool icm42688p_read_gyro_raw(ICM42688P* icm42688p, ICM42688PRawData* data) {
+    bool ret = icm42688p_read_mem(
+        icm42688p->spi_bus, ICM42688_GYRO_DATA_X1, (uint8_t*)data, sizeof(ICM42688PRawData));
+    return ret;
+}
+
+bool icm42688p_write_gyro_offset(ICM42688P* icm42688p, ICM42688PScaledData* scaled_data) {
+    if((fabsf(scaled_data->x) > 64.f) || (fabsf(scaled_data->y) > 64.f) ||
+       (fabsf(scaled_data->z) > 64.f)) {
+        return false;
+    }
+
+    uint16_t offset_x = (uint16_t)(-(int16_t)(scaled_data->x * 32.f) * 16) >> 4;
+    uint16_t offset_y = (uint16_t)(-(int16_t)(scaled_data->y * 32.f) * 16) >> 4;
+    uint16_t offset_z = (uint16_t)(-(int16_t)(scaled_data->z * 32.f) * 16) >> 4;
+
+    uint8_t offset_regs[9];
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 4);
+    icm42688p_read_mem(icm42688p->spi_bus, ICM42688_OFFSET_USER0, offset_regs, 5);
+
+    offset_regs[0] = offset_x & 0xFF;
+    offset_regs[1] = (offset_x & 0xF00) >> 8;
+    offset_regs[1] |= (offset_y & 0xF00) >> 4;
+    offset_regs[2] = offset_y & 0xFF;
+    offset_regs[3] = offset_z & 0xFF;
+    offset_regs[4] &= 0xF0;
+    offset_regs[4] |= (offset_z & 0x0F00) >> 8;
+
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER0, offset_regs[0]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER1, offset_regs[1]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER2, offset_regs[2]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER3, offset_regs[3]);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_OFFSET_USER4, offset_regs[4]);
+
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0);
+    return true;
+}
+
+void icm42688p_apply_scale(ICM42688PRawData* raw_data, float full_scale, ICM42688PScaledData* data) {
+    data->x = ((float)(raw_data->x)) / 32768.f * full_scale;
+    data->y = ((float)(raw_data->y)) / 32768.f * full_scale;
+    data->z = ((float)(raw_data->z)) / 32768.f * full_scale;
+}
+
+void icm42688p_apply_scale_fifo(
+    ICM42688P* icm42688p,
+    ICM42688PFifoPacket* fifo_data,
+    ICM42688PScaledData* accel_data,
+    ICM42688PScaledData* gyro_data) {
+    float full_scale = icm42688p->accel_scale;
+    accel_data->x = ((float)(fifo_data->a_x)) / 32768.f * full_scale;
+    accel_data->y = ((float)(fifo_data->a_y)) / 32768.f * full_scale;
+    accel_data->z = ((float)(fifo_data->a_z)) / 32768.f * full_scale;
+
+    full_scale = icm42688p->gyro_scale;
+    gyro_data->x = ((float)(fifo_data->g_x)) / 32768.f * full_scale;
+    gyro_data->y = ((float)(fifo_data->g_y)) / 32768.f * full_scale;
+    gyro_data->z = ((float)(fifo_data->g_z)) / 32768.f * full_scale;
+}
+
+float icm42688p_read_temp(ICM42688P* icm42688p) {
+    uint8_t reg_val[2];
+
+    icm42688p_read_mem(icm42688p->spi_bus, ICM42688_TEMP_DATA1, reg_val, 2);
+    int16_t temp_int = (reg_val[0] << 8) | reg_val[1];
+    return ((float)temp_int / 132.48f) + 25.f;
+}
+
+void icm42688_fifo_enable(
+    ICM42688P* icm42688p,
+    ICM42688PIrqCallback irq_callback,
+    void* irq_context) {
+    // FIFO mode: stream
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG, (1 << 6));
+    // Little-endian data, FIFO count in records
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INTF_CONFIG0, (1 << 7) | (1 << 6));
+    // FIFO partial read, FIFO packet: gyro + accel TODO: 20bit
+    icm42688p_write_reg(
+        icm42688p->spi_bus, ICM42688_FIFO_CONFIG1, (1 << 6) | (1 << 5) | (1 << 1) | (1 << 0));
+    // FIFO irq watermark
+    uint16_t fifo_watermark = 1;
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG2, fifo_watermark & 0xFF);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG3, fifo_watermark >> 8);
+
+    // IRQ1: push-pull, active high
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_CONFIG, (1 << 1) | (1 << 0));
+    // Clear IRQ on status read
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_CONFIG0, 0);
+    // IRQ pulse duration
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_CONFIG1, (1 << 6) | (1 << 5));
+
+    uint8_t reg_data = 0;
+    icm42688p_read_reg(icm42688p->spi_bus, ICM42688_INT_STATUS, &reg_data);
+
+    furi_hal_gpio_init(icm42688p->irq_pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedVeryHigh);
+    furi_hal_gpio_remove_int_callback(icm42688p->irq_pin);
+    furi_hal_gpio_add_int_callback(icm42688p->irq_pin, irq_callback, irq_context);
+
+    // IRQ1 source: FIFO threshold
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE0, (1 << 2));
+}
+
+void icm42688_fifo_disable(ICM42688P* icm42688p) {
+    furi_hal_gpio_remove_int_callback(icm42688p->irq_pin);
+    furi_hal_gpio_init(icm42688p->irq_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
+
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE0, 0);
+
+    // FIFO mode: bypass
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_FIFO_CONFIG, 0);
+}
+
+uint16_t icm42688_fifo_get_count(ICM42688P* icm42688p) {
+    uint16_t reg_val = 0;
+    icm42688p_read_mem(icm42688p->spi_bus, ICM42688_FIFO_COUNTH, (uint8_t*)&reg_val, 2);
+    return reg_val;
+}
+
+bool icm42688_fifo_read(ICM42688P* icm42688p, ICM42688PFifoPacket* data) {
+    icm42688p_read_mem(
+        icm42688p->spi_bus, ICM42688_FIFO_DATA, (uint8_t*)data, sizeof(ICM42688PFifoPacket));
+    return (data->header) & (1 << 7);
+}
+
+ICM42688P* icm42688p_alloc(FuriHalSpiBusHandle* spi_bus, const GpioPin* irq_pin) {
+    ICM42688P* icm42688p = malloc(sizeof(ICM42688P));
+    icm42688p->spi_bus = spi_bus;
+    icm42688p->irq_pin = irq_pin;
+    return icm42688p;
+}
+
+void icm42688p_free(ICM42688P* icm42688p) {
+    free(icm42688p);
+}
+
+bool icm42688p_init(ICM42688P* icm42688p) {
+    furi_hal_spi_bus_handle_init(icm42688p->spi_bus);
+
+    // Software reset
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0); // Set reg bank to 0
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_DEVICE_CONFIG, 0x01); // SPI Mode 0, SW reset
+    furi_delay_ms(1);
+
+    uint8_t reg_value = 0;
+    bool read_ok = icm42688p_read_reg(icm42688p->spi_bus, ICM42688_WHO_AM_I, &reg_value);
+    if(!read_ok) {
+        FURI_LOG_E(TAG, "Chip ID read failed");
+        return false;
+    } else if(reg_value != ICM42688_WHOAMI) {
+        FURI_LOG_E(
+            TAG, "Sensor returned wrong ID 0x%02X, expected 0x%02X", reg_value, ICM42688_WHOAMI);
+        return false;
+    }
+
+    // Disable all interrupts
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE0, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE1, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE3, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE4, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 4);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE6, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INT_SOURCE7, 0);
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0);
+
+    // Data format: little endian
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_INTF_CONFIG0, 0);
+
+    // Enable all sensors
+    icm42688p_write_reg(
+        icm42688p->spi_bus,
+        ICM42688_PWR_MGMT0,
+        ICM42688_PWR_TEMP_ON | ICM42688_PWR_GYRO_MODE_LN | ICM42688_PWR_ACCEL_MODE_LN);
+    furi_delay_ms(45);
+
+    icm42688p_accel_config(icm42688p, AccelFullScale16G, DataRate1kHz);
+    icm42688p_gyro_config(icm42688p, GyroFullScale2000DPS, DataRate1kHz);
+
+    return true;
+}
+
+bool icm42688p_deinit(ICM42688P* icm42688p) {
+    // Software reset
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_REG_BANK_SEL, 0); // Set reg bank to 0
+    icm42688p_write_reg(icm42688p->spi_bus, ICM42688_DEVICE_CONFIG, 0x01); // SPI Mode 0, SW reset
+
+    furi_hal_spi_bus_handle_deinit(icm42688p->spi_bus);
+    return true;
+}

+ 127 - 0
non_catalog_apps/air_arkanoid/engine/sensors/ICM42688P/ICM42688P.h

@@ -0,0 +1,127 @@
+#pragma once
+
+#include <furi.h>
+#include <furi_hal.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+    DataRate32kHz = 0x01,
+    DataRate16kHz = 0x02,
+    DataRate8kHz = 0x03,
+    DataRate4kHz = 0x04,
+    DataRate2kHz = 0x05,
+    DataRate1kHz = 0x06,
+    DataRate200Hz = 0x07,
+    DataRate100Hz = 0x08,
+    DataRate50Hz = 0x09,
+    DataRate25Hz = 0x0A,
+    DataRate12_5Hz = 0x0B,
+    DataRate6_25Hz = 0x0C, // Accelerometer only
+    DataRate3_125Hz = 0x0D, // Accelerometer only
+    DataRate1_5625Hz = 0x0E, // Accelerometer only
+    DataRate500Hz = 0x0F,
+} ICM42688PDataRate;
+
+typedef enum {
+    AccelFullScale16G = 0,
+    AccelFullScale8G,
+    AccelFullScale4G,
+    AccelFullScale2G,
+    AccelFullScaleTotal,
+} ICM42688PAccelFullScale;
+
+typedef enum {
+    GyroFullScale2000DPS = 0,
+    GyroFullScale1000DPS,
+    GyroFullScale500DPS,
+    GyroFullScale250DPS,
+    GyroFullScale125DPS,
+    GyroFullScale62_5DPS,
+    GyroFullScale31_25DPS,
+    GyroFullScale15_625DPS,
+    GyroFullScaleTotal,
+} ICM42688PGyroFullScale;
+
+typedef struct {
+    int16_t x;
+    int16_t y;
+    int16_t z;
+} __attribute__((packed)) ICM42688PRawData;
+
+typedef struct {
+    uint8_t header;
+    int16_t a_x;
+    int16_t a_y;
+    int16_t a_z;
+    int16_t g_x;
+    int16_t g_y;
+    int16_t g_z;
+    uint8_t temp;
+    uint16_t ts;
+} __attribute__((packed)) ICM42688PFifoPacket;
+
+typedef struct {
+    float x;
+    float y;
+    float z;
+} ICM42688PScaledData;
+
+typedef struct ICM42688P ICM42688P;
+
+typedef void (*ICM42688PIrqCallback)(void* ctx);
+
+ICM42688P* icm42688p_alloc(FuriHalSpiBusHandle* spi_bus, const GpioPin* irq_pin);
+
+bool icm42688p_init(ICM42688P* icm42688p);
+
+bool icm42688p_deinit(ICM42688P* icm42688p);
+
+void icm42688p_free(ICM42688P* icm42688p);
+
+bool icm42688p_accel_config(
+    ICM42688P* icm42688p,
+    ICM42688PAccelFullScale full_scale,
+    ICM42688PDataRate rate);
+
+float icm42688p_accel_get_full_scale(ICM42688P* icm42688p);
+
+bool icm42688p_gyro_config(
+    ICM42688P* icm42688p,
+    ICM42688PGyroFullScale full_scale,
+    ICM42688PDataRate rate);
+
+float icm42688p_gyro_get_full_scale(ICM42688P* icm42688p);
+
+bool icm42688p_read_accel_raw(ICM42688P* icm42688p, ICM42688PRawData* data);
+
+bool icm42688p_read_gyro_raw(ICM42688P* icm42688p, ICM42688PRawData* data);
+
+bool icm42688p_write_gyro_offset(ICM42688P* icm42688p, ICM42688PScaledData* scaled_data);
+
+void icm42688p_apply_scale(ICM42688PRawData* raw_data, float full_scale, ICM42688PScaledData* data);
+
+void icm42688p_apply_scale_fifo(
+    ICM42688P* icm42688p,
+    ICM42688PFifoPacket* fifo_data,
+    ICM42688PScaledData* accel_data,
+    ICM42688PScaledData* gyro_data);
+
+float icm42688p_read_temp(ICM42688P* icm42688p);
+
+void icm42688_fifo_enable(
+    ICM42688P* icm42688p,
+    ICM42688PIrqCallback irq_callback,
+    void* irq_context);
+
+void icm42688_fifo_disable(ICM42688P* icm42688p);
+
+uint16_t icm42688_fifo_get_count(ICM42688P* icm42688p);
+
+bool icm42688_fifo_read(ICM42688P* icm42688p, ICM42688PFifoPacket* data);
+
+#ifdef __cplusplus
+}
+#endif

+ 176 - 0
non_catalog_apps/air_arkanoid/engine/sensors/ICM42688P/ICM42688P_regs.h

@@ -0,0 +1,176 @@
+#pragma once
+
+#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_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
+
+// 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_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
+
+// 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
+
+// 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_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
+
+// 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_ACCEL_MODE_OFF (0 << 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_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_12_5Hz 0x0B
+#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_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

+ 326 - 0
non_catalog_apps/air_arkanoid/engine/sensors/imu.c

@@ -0,0 +1,326 @@
+#include <furi.h>
+#include "imu.h"
+#include "ICM42688P/ICM42688P.h"
+
+#define TAG "IMU"
+
+#define ACCEL_GYRO_RATE DataRate100Hz
+
+#define FILTER_SAMPLE_FREQ 100.f
+#define FILTER_BETA 0.08f
+
+#define SAMPLE_RATE_DIV 5
+
+#define SENSITIVITY_K 30.f
+#define EXP_RATE 1.1f
+
+#define IMU_CALI_AVG 64
+
+typedef enum {
+    ImuStop = (1 << 0),
+    ImuNewData = (1 << 1),
+} ImuThreadFlags;
+
+#define FLAGS_ALL (ImuStop | ImuNewData)
+
+typedef struct {
+    float q0;
+    float q1;
+    float q2;
+    float q3;
+    float roll;
+    float pitch;
+    float yaw;
+} ImuProcessedData;
+
+typedef struct {
+    FuriThread* thread;
+    ICM42688P* icm42688p;
+    ImuProcessedData processed_data;
+} ImuThread;
+
+static void imu_madgwick_filter(
+    ImuProcessedData* out,
+    ICM42688PScaledData* accel,
+    ICM42688PScaledData* gyro);
+
+static void imu_irq_callback(void* context) {
+    furi_assert(context);
+    ImuThread* imu = context;
+    furi_thread_flags_set(furi_thread_get_id(imu->thread), ImuNewData);
+}
+
+static void imu_process_data(ImuThread* imu, ICM42688PFifoPacket* in_data) {
+    ICM42688PScaledData accel_data;
+    ICM42688PScaledData gyro_data;
+
+    // Get accel and gyro data in g and degrees/s
+    icm42688p_apply_scale_fifo(imu->icm42688p, in_data, &accel_data, &gyro_data);
+
+    // Gyro: degrees/s to rads/s
+    gyro_data.x = gyro_data.x / 180.f * M_PI;
+    gyro_data.y = gyro_data.y / 180.f * M_PI;
+    gyro_data.z = gyro_data.z / 180.f * M_PI;
+
+    // Sensor Fusion algorithm
+    ImuProcessedData* out = &imu->processed_data;
+    imu_madgwick_filter(out, &accel_data, &gyro_data);
+
+    // Quaternion to euler angles
+    float roll = atan2f(
+        out->q0 * out->q1 + out->q2 * out->q3, 0.5f - out->q1 * out->q1 - out->q2 * out->q2);
+    float pitch = asinf(-2.0f * (out->q1 * out->q3 - out->q0 * out->q2));
+    float yaw = atan2f(
+        out->q1 * out->q2 + out->q0 * out->q3, 0.5f - out->q2 * out->q2 - out->q3 * out->q3);
+
+    // Euler angles: rads to degrees
+    out->roll = roll / M_PI * 180.f;
+    out->pitch = pitch / M_PI * 180.f;
+    out->yaw = yaw / M_PI * 180.f;
+}
+
+static void calibrate_gyro(ImuThread* imu) {
+    ICM42688PRawData data;
+    ICM42688PScaledData offset_scaled = {.x = 0.f, .y = 0.f, .z = 0.f};
+
+    icm42688p_write_gyro_offset(imu->icm42688p, &offset_scaled);
+    furi_delay_ms(10);
+
+    int32_t avg_x = 0;
+    int32_t avg_y = 0;
+    int32_t avg_z = 0;
+
+    for(uint8_t i = 0; i < IMU_CALI_AVG; i++) {
+        icm42688p_read_gyro_raw(imu->icm42688p, &data);
+        avg_x += data.x;
+        avg_y += data.y;
+        avg_z += data.z;
+        furi_delay_ms(2);
+    }
+
+    data.x = avg_x / IMU_CALI_AVG;
+    data.y = avg_y / IMU_CALI_AVG;
+    data.z = avg_z / IMU_CALI_AVG;
+
+    icm42688p_apply_scale(&data, icm42688p_gyro_get_full_scale(imu->icm42688p), &offset_scaled);
+    FURI_LOG_I(
+        TAG,
+        "Offsets: x %f, y %f, z %f",
+        (double)offset_scaled.x,
+        (double)offset_scaled.y,
+        (double)offset_scaled.z);
+    icm42688p_write_gyro_offset(imu->icm42688p, &offset_scaled);
+}
+
+// static float imu_angle_diff(float a, float b) {
+//     float diff = a - b;
+//     if(diff > 180.f)
+//         diff -= 360.f;
+//     else if(diff < -180.f)
+//         diff += 360.f;
+
+//     return diff;
+// }
+
+static int32_t imu_thread(void* context) {
+    furi_assert(context);
+    ImuThread* imu = context;
+
+    // float yaw_last = 0.f;
+    // float pitch_last = 0.f;
+    // float diff_x = 0.f;
+    // float diff_y = 0.f;
+
+    calibrate_gyro(imu);
+
+    icm42688p_accel_config(imu->icm42688p, AccelFullScale16G, ACCEL_GYRO_RATE);
+    icm42688p_gyro_config(imu->icm42688p, GyroFullScale2000DPS, ACCEL_GYRO_RATE);
+
+    imu->processed_data.q0 = 1.f;
+    imu->processed_data.q1 = 0.f;
+    imu->processed_data.q2 = 0.f;
+    imu->processed_data.q3 = 0.f;
+    icm42688_fifo_enable(imu->icm42688p, imu_irq_callback, imu);
+
+    while(1) {
+        uint32_t events = furi_thread_flags_wait(FLAGS_ALL, FuriFlagWaitAny, FuriWaitForever);
+
+        if(events & ImuStop) {
+            break;
+        }
+
+        if(events & ImuNewData) {
+            uint16_t data_pending = icm42688_fifo_get_count(imu->icm42688p);
+            ICM42688PFifoPacket data;
+            while(data_pending--) {
+                icm42688_fifo_read(imu->icm42688p, &data);
+                imu_process_data(imu, &data);
+            }
+        }
+    }
+
+    icm42688_fifo_disable(imu->icm42688p);
+
+    return 0;
+}
+
+ImuThread* imu_start(ICM42688P* icm42688p) {
+    ImuThread* imu = malloc(sizeof(ImuThread));
+    imu->icm42688p = icm42688p;
+    imu->thread = furi_thread_alloc_ex("ImuThread", 4096, imu_thread, imu);
+
+    furi_thread_start(imu->thread);
+
+    return imu;
+}
+
+void imu_stop(ImuThread* imu) {
+    furi_assert(imu);
+
+    furi_thread_flags_set(furi_thread_get_id(imu->thread), ImuStop);
+
+    furi_thread_join(imu->thread);
+    furi_thread_free(imu->thread);
+
+    free(imu);
+}
+
+static float imu_inv_sqrt(float number) {
+    union {
+        float f;
+        uint32_t i;
+    } conv = {.f = number};
+    conv.i = 0x5F3759Df - (conv.i >> 1);
+    conv.f *= 1.5f - (number * 0.5f * conv.f * conv.f);
+    return conv.f;
+}
+
+/* Simple madgwik filter, based on: https://github.com/arduino-libraries/MadgwickAHRS/ */
+
+static void imu_madgwick_filter(
+    ImuProcessedData* out,
+    ICM42688PScaledData* accel,
+    ICM42688PScaledData* gyro) {
+    float recipNorm;
+    float s0, s1, s2, s3;
+    float qDot1, qDot2, qDot3, qDot4;
+    float _2q0, _2q1, _2q2, _2q3, _4q0, _4q1, _4q2, _8q1, _8q2, q0q0, q1q1, q2q2, q3q3;
+
+    // Rate of change of quaternion from gyroscope
+    qDot1 = 0.5f * (-out->q1 * gyro->x - out->q2 * gyro->y - out->q3 * gyro->z);
+    qDot2 = 0.5f * (out->q0 * gyro->x + out->q2 * gyro->z - out->q3 * gyro->y);
+    qDot3 = 0.5f * (out->q0 * gyro->y - out->q1 * gyro->z + out->q3 * gyro->x);
+    qDot4 = 0.5f * (out->q0 * gyro->z + out->q1 * gyro->y - out->q2 * gyro->x);
+
+    // Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation)
+    if(!((accel->x == 0.0f) && (accel->y == 0.0f) && (accel->z == 0.0f))) {
+        // Normalise accelerometer measurement
+        recipNorm = imu_inv_sqrt(accel->x * accel->x + accel->y * accel->y + accel->z * accel->z);
+        accel->x *= recipNorm;
+        accel->y *= recipNorm;
+        accel->z *= recipNorm;
+
+        // Auxiliary variables to avoid repeated arithmetic
+        _2q0 = 2.0f * out->q0;
+        _2q1 = 2.0f * out->q1;
+        _2q2 = 2.0f * out->q2;
+        _2q3 = 2.0f * out->q3;
+        _4q0 = 4.0f * out->q0;
+        _4q1 = 4.0f * out->q1;
+        _4q2 = 4.0f * out->q2;
+        _8q1 = 8.0f * out->q1;
+        _8q2 = 8.0f * out->q2;
+        q0q0 = out->q0 * out->q0;
+        q1q1 = out->q1 * out->q1;
+        q2q2 = out->q2 * out->q2;
+        q3q3 = out->q3 * out->q3;
+
+        // Gradient decent algorithm corrective step
+        s0 = _4q0 * q2q2 + _2q2 * accel->x + _4q0 * q1q1 - _2q1 * accel->y;
+        s1 = _4q1 * q3q3 - _2q3 * accel->x + 4.0f * q0q0 * out->q1 - _2q0 * accel->y - _4q1 +
+             _8q1 * q1q1 + _8q1 * q2q2 + _4q1 * accel->z;
+        s2 = 4.0f * q0q0 * out->q2 + _2q0 * accel->x + _4q2 * q3q3 - _2q3 * accel->y - _4q2 +
+             _8q2 * q1q1 + _8q2 * q2q2 + _4q2 * accel->z;
+        s3 = 4.0f * q1q1 * out->q3 - _2q1 * accel->x + 4.0f * q2q2 * out->q3 - _2q2 * accel->y;
+        recipNorm =
+            imu_inv_sqrt(s0 * s0 + s1 * s1 + s2 * s2 + s3 * s3); // normalise step magnitude
+        s0 *= recipNorm;
+        s1 *= recipNorm;
+        s2 *= recipNorm;
+        s3 *= recipNorm;
+
+        // Apply feedback step
+        qDot1 -= FILTER_BETA * s0;
+        qDot2 -= FILTER_BETA * s1;
+        qDot3 -= FILTER_BETA * s2;
+        qDot4 -= FILTER_BETA * s3;
+    }
+
+    // Integrate rate of change of quaternion to yield quaternion
+    out->q0 += qDot1 * (1.0f / FILTER_SAMPLE_FREQ);
+    out->q1 += qDot2 * (1.0f / FILTER_SAMPLE_FREQ);
+    out->q2 += qDot3 * (1.0f / FILTER_SAMPLE_FREQ);
+    out->q3 += qDot4 * (1.0f / FILTER_SAMPLE_FREQ);
+
+    // Normalise quaternion
+    recipNorm = imu_inv_sqrt(
+        out->q0 * out->q0 + out->q1 * out->q1 + out->q2 * out->q2 + out->q3 * out->q3);
+    out->q0 *= recipNorm;
+    out->q1 *= recipNorm;
+    out->q2 *= recipNorm;
+    out->q3 *= recipNorm;
+}
+
+/* IMU API */
+
+struct Imu {
+    FuriHalSpiBusHandle* icm42688p_device;
+    ICM42688P* icm42688p;
+    ImuThread* thread;
+    bool present;
+};
+
+Imu* imu_alloc(void) {
+    Imu* imu = malloc(sizeof(Imu));
+    imu->icm42688p_device = malloc(sizeof(FuriHalSpiBusHandle));
+    memcpy(imu->icm42688p_device, &furi_hal_spi_bus_handle_external, sizeof(FuriHalSpiBusHandle));
+    imu->icm42688p_device->cs = &gpio_ext_pc3;
+
+    imu->icm42688p = icm42688p_alloc(imu->icm42688p_device, &gpio_ext_pb2);
+    imu->present = icm42688p_init(imu->icm42688p);
+
+    if(imu->present) {
+        imu->thread = imu_start(imu->icm42688p);
+    }
+
+    return imu;
+}
+
+void imu_free(Imu* imu) {
+    if(imu->present) {
+        imu_stop(imu->thread);
+    }
+    icm42688p_deinit(imu->icm42688p);
+    icm42688p_free(imu->icm42688p);
+    free(imu->icm42688p_device);
+    free(imu);
+}
+
+bool imu_present(Imu* imu) {
+    return imu->present;
+}
+
+float imu_pitch_get(Imu* imu) {
+    // we pretend that reading a float is an atomic operation
+    return imu->thread->processed_data.pitch;
+}
+
+float imu_roll_get(Imu* imu) {
+    // we pretend that reading a float is an atomic operation
+    return imu->thread->processed_data.roll;
+}
+
+float imu_yaw_get(Imu* imu) {
+    // we pretend that reading a float is an atomic operation
+    return imu->thread->processed_data.yaw;
+}

+ 15 - 0
non_catalog_apps/air_arkanoid/engine/sensors/imu.h

@@ -0,0 +1,15 @@
+#pragma once
+
+typedef struct Imu Imu;
+
+Imu* imu_alloc(void);
+
+void imu_free(Imu* imu);
+
+bool imu_present(Imu* imu);
+
+float imu_pitch_get(Imu* imu);
+
+float imu_roll_get(Imu* imu);
+
+float imu_yaw_get(Imu* imu);

+ 69 - 0
non_catalog_apps/air_arkanoid/engine/sprite.c

@@ -0,0 +1,69 @@
+#include "sprite.h"
+#include <storage/storage.h>
+
+#ifdef SPRITE_DEBUG
+#define SPRITE_D(...) FURI_LOG_D("Sprite", __VA_ARGS__)
+#define SPRITE_E(...) FURI_LOG_E("Sprite", __VA_ARGS__)
+#else
+#define SPRITE_D(...)
+#define SPRITE_E(...)
+#endif
+
+struct Sprite {
+    uint32_t width;
+    uint32_t height;
+    uint8_t data[];
+};
+
+Sprite* sprite_alloc(const char* path) {
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
+    Sprite* sprite = NULL;
+
+    do {
+        if(!storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) {
+            SPRITE_E("Failed to open file: %s", path);
+            break;
+        }
+
+        uint32_t size = 0;
+        if(storage_file_read(file, &size, sizeof(size)) != sizeof(size)) {
+            SPRITE_E("Failed to read file size: %s", path);
+            break;
+        }
+
+        sprite = malloc(size);
+        if(storage_file_read(file, sprite, size) != size) {
+            SPRITE_E("Failed to read file: %s", path);
+            free(sprite);
+            sprite = NULL;
+            break;
+        }
+
+        SPRITE_D(
+            "Loaded sprite: %s, width: %lu, height: %lu", path, sprite->width, sprite->height);
+    } while(false);
+
+    storage_file_free(file);
+
+    return sprite;
+}
+
+void sprite_free(Sprite* sprite) {
+    free(sprite);
+}
+
+size_t sprite_get_width(Sprite* sprite) {
+    return sprite->width;
+}
+
+size_t sprite_get_height(Sprite* sprite) {
+    return sprite->height;
+}
+
+void canvas_draw_sprite(Canvas* canvas, Sprite* sprite, int32_t x, int32_t y) {
+    furi_check(sprite->width);
+    furi_check(sprite->height);
+    furi_check(sprite->data);
+    canvas_draw_xbm(canvas, x, y, sprite->width, sprite->height, sprite->data);
+}

+ 44 - 0
non_catalog_apps/air_arkanoid/engine/sprite.h

@@ -0,0 +1,44 @@
+#pragma once
+#include <stdbool.h>
+#include <stddef.h>
+#include <gui/canvas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct Sprite Sprite;
+
+/** Sprite allocator
+ * @return Sprite*  Sprite instance or NULL, if failed
+ */
+Sprite* sprite_alloc(const char* path);
+
+/** Sprite deallocator
+ * @param sprite Sprite instance
+ */
+void sprite_free(Sprite* sprite);
+
+/** Get sprite width
+ * @param sprite Sprite instance
+ * @return size_t sprite width
+ */
+size_t sprite_get_width(Sprite* sprite);
+
+/** Get sprite height
+ * @param sprite Sprite instance
+ * @return size_t sprite height
+ */
+size_t sprite_get_height(Sprite* sprite);
+
+/** Draw sprite on canvas
+ * @param canvas Canvas instance
+ * @param sprite Sprite instance
+ * @param x x coordinate
+ * @param y y coordinate
+ */
+void canvas_draw_sprite(Canvas* canvas, Sprite* sprite, int32_t x, int32_t y);
+
+#ifdef __cplusplus
+}
+#endif

+ 33 - 0
non_catalog_apps/air_arkanoid/engine/vector.c

@@ -0,0 +1,33 @@
+#include "vector.h"
+
+Vector vector_add(Vector a, Vector b) {
+    return (Vector){.x = a.x + b.x, .y = a.y + b.y};
+}
+
+Vector vector_sub(Vector a, Vector b) {
+    return (Vector){.x = a.x - b.x, .y = a.y - b.y};
+}
+
+Vector vector_mul(Vector a, Vector b) {
+    return (Vector){.x = a.x * b.x, .y = a.y * b.y};
+}
+
+Vector vector_div(Vector a, Vector b) {
+    return (Vector){.x = a.x / b.x, .y = a.y / b.y};
+}
+
+Vector vector_addf(Vector a, float b) {
+    return (Vector){.x = a.x + b, .y = a.y + b};
+}
+
+Vector vector_subf(Vector a, float b) {
+    return (Vector){.x = a.x - b, .y = a.y - b};
+}
+
+Vector vector_mulf(Vector a, float b) {
+    return (Vector){.x = a.x * b, .y = a.y * b};
+}
+
+Vector vector_divf(Vector a, float b) {
+    return (Vector){.x = a.x / b, .y = a.y / b};
+}

+ 32 - 0
non_catalog_apps/air_arkanoid/engine/vector.h

@@ -0,0 +1,32 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+    float x;
+    float y;
+} Vector;
+
+#define VECTOR_ZERO ((Vector){0, 0})
+
+Vector vector_add(Vector a, Vector b);
+
+Vector vector_sub(Vector a, Vector b);
+
+Vector vector_mul(Vector a, Vector b);
+
+Vector vector_div(Vector a, Vector b);
+
+Vector vector_addf(Vector a, float b);
+
+Vector vector_subf(Vector a, float b);
+
+Vector vector_mulf(Vector a, float b);
+
+Vector vector_divf(Vector a, float b);
+
+#ifdef __cplusplus
+}
+#endif

+ 25 - 0
non_catalog_apps/air_arkanoid/fonts/fonts.c

@@ -0,0 +1,25 @@
+#include "fonts.h"
+
+const uint8_t u8g2_font_u8glib_4_tr[681] =
+    "`\0\2\2\3\3\1\3\4\5\6\0\377\4\377\5\377\0\325\1\272\2\214 \4@*!\5a**"
+    "\42\6\323\63I\5#\12\355y\325P\325P\25\0$\13\365\271\31\34\31\215\221A\4%\6d\66\261"
+    "\7&\11lv\61\305*\215\0'\5\321+\2(\6\362m\252\31)\7\362-\61U\12*\5\322."
+    "#+\7[ri%\0,\5\321)\2-\5\313\62\3.\5I*\1/\7d\366 \266\1\60\7"
+    "c\62#\251\21\61\6bn\253\0\62\7c\62\63\245\1\63\7c\62+\203\21\64\7c\62\61\215\30"
+    "\65\7c\62C\203\21\66\7c\62#\216\1\67\7c\62\63\225\0\70\7c\62G\32\1\71\6c\62"
+    "\347\10:\5Y*);\5\341)I<\5Zn\62=\6[\62\33\14>\6Z.Q\1\77\7b"
+    ".*\203\0@\10d\66Cm\60\2A\7dv*\216\31B\7d\66k\310!C\7cr\63\3"
+    "\1D\10d\66+\312\221\0E\10d\66G\312`\4F\10d\66C\203\225\1G\10d\66C\203\64"
+    "\6H\7d\66qL\31I\5a*#J\7c\62\63.\0K\10d\66q\244(\3L\6c\62"
+    "\261\34M\11e:\31\254\225\64\10N\7d\66q\251\31O\10dv*\312\244\0P\10d\66+\216"
+    "\224\1Q\11e:#\305\24\323\12R\6d\66\257\62S\10dvC\243\241\0T\7c\62+V\0"
+    "U\7d\66\321\34\2V\7d\66\321L\12W\11e:\31\250\244\272\0X\7c\62\251L\5Y\10"
+    "d\66qh\60\4Z\7d\66#\226#[\6\362-\253%\134\11d\66\31e\224Q\0]\6\362-"
+    "\252\65^\5\323s\15_\5\314\65#`\5\322/\61a\6[rG\0b\7c\62Q\245\5c\5"
+    "Z.Kd\7c\262i%\1e\7[\62#-\0f\7c\262)\255\4g\6\343\61g\22h\7"
+    "c\62Q%\25i\5a*Ij\7\352m\31$\5k\7c\62\61\255\2l\5a*#m\7]"
+    ":\252\245\12n\7[\62*\251\0o\7[\62#\215\0p\7\343\61*\255\10q\7\343q+\311\0"
+    "r\6Z.+\1s\7[r*)\0t\7criE\1u\7[\62I\215\0v\7[\62I"
+    "U\0w\10]:\31\250.\0x\6[\62\251\3y\7\343\61i\304\21z\6[\62\62\12{\10\363"
+    "q\252\314 \12|\5\361)\7}\11\363\61\62\203\230\222\2~\7\324wI%\0\177\7l\66C\232"
+    "C\0\0\0\4\377\377\0";

+ 4 - 0
non_catalog_apps/air_arkanoid/fonts/fonts.h

@@ -0,0 +1,4 @@
+#pragma once
+#include <stdint.h>
+
+extern const uint8_t u8g2_font_u8glib_4_tr[];

+ 73 - 0
non_catalog_apps/air_arkanoid/game.c

@@ -0,0 +1,73 @@
+#include "game.h"
+#include "game_settings.h"
+#include "levels/level_menu.h"
+#include "levels/level_game.h"
+#include "levels/level_settings.h"
+#include "levels/level_message.h"
+
+const NotificationSequence sequence_sound_blip = {
+    &message_note_c7,
+    &message_delay_50,
+    &message_sound_off,
+    NULL,
+};
+
+const NotificationSequence sequence_sound_menu = {
+    &message_note_c6,
+    &message_delay_10,
+    &message_sound_off,
+    NULL,
+};
+
+void game_start(GameManager* game_manager, void* ctx) {
+    GameContext* context = ctx;
+    context->imu = imu_alloc();
+    context->imu_present = imu_present(context->imu);
+    context->levels.menu = game_manager_add_level(game_manager, &level_menu);
+    context->levels.settings = game_manager_add_level(game_manager, &level_settings);
+    context->levels.game = game_manager_add_level(game_manager, &level_game);
+    context->levels.message = game_manager_add_level(game_manager, &level_message);
+
+    if(!game_settings_load(&context->settings)) {
+        context->settings.sound = true;
+        context->settings.show_fps = false;
+    }
+
+    context->app = furi_record_open(RECORD_NOTIFICATION);
+    context->game_manager = game_manager;
+
+    game_manager_show_fps_set(context->game_manager, context->settings.show_fps);
+}
+
+void game_stop(void* ctx) {
+    GameContext* context = ctx;
+    imu_free(context->imu);
+
+    furi_record_close(RECORD_NOTIFICATION);
+}
+
+const Game game = {
+    .target_fps = 30,
+    .show_fps = false,
+    .always_backlight = true,
+    .start = game_start,
+    .stop = game_stop,
+    .context_size = sizeof(GameContext),
+};
+
+void game_switch_sound(GameContext* context) {
+    context->settings.sound = !context->settings.sound;
+    game_settings_save(&context->settings);
+}
+
+void game_switch_show_fps(GameContext* context) {
+    context->settings.show_fps = !context->settings.show_fps;
+    game_manager_show_fps_set(context->game_manager, context->settings.show_fps);
+    game_settings_save(&context->settings);
+}
+
+void game_sound_play(GameContext* context, const NotificationSequence* sequence) {
+    if(context->settings.sound) {
+        notification_message(context->app, sequence);
+    }
+}

+ 35 - 0
non_catalog_apps/air_arkanoid/game.h

@@ -0,0 +1,35 @@
+#pragma once
+#include "engine/engine.h"
+#include "engine/sensors/imu.h"
+#include <notification/notification_messages.h>
+
+typedef struct {
+    Level* menu;
+    Level* settings;
+    Level* game;
+    Level* message;
+} Levels;
+
+typedef struct {
+    bool sound;
+    bool show_fps;
+} Settings;
+
+typedef struct {
+    Imu* imu;
+    bool imu_present;
+
+    Levels levels;
+    Settings settings;
+
+    NotificationApp* app;
+    GameManager* game_manager;
+} GameContext;
+
+void game_switch_sound(GameContext* context);
+
+void game_switch_show_fps(GameContext* context);
+
+void game_sound_play(GameContext* context, const NotificationSequence* sequence);
+
+extern const NotificationSequence sequence_sound_menu;

+ 21 - 0
non_catalog_apps/air_arkanoid/game_settings.c

@@ -0,0 +1,21 @@
+#include <storage/storage.h>
+#include "game_settings.h"
+#include <lib/toolbox/saved_struct.h>
+
+#define SETTINGS_PATH APP_DATA_PATH("settings.bin")
+#define SETTINGS_VERSION (0)
+#define SETTINGS_MAGIC (0x69)
+
+bool game_settings_load(Settings* settings) {
+    furi_assert(settings);
+
+    return saved_struct_load(
+        SETTINGS_PATH, settings, sizeof(Settings), SETTINGS_MAGIC, SETTINGS_VERSION);
+}
+
+bool game_settings_save(Settings* settings) {
+    furi_assert(settings);
+
+    return saved_struct_save(
+        SETTINGS_PATH, settings, sizeof(Settings), SETTINGS_MAGIC, SETTINGS_VERSION);
+}

+ 6 - 0
non_catalog_apps/air_arkanoid/game_settings.h

@@ -0,0 +1,6 @@
+#pragma once
+#include "game.h"
+
+bool game_settings_save(Settings* settings);
+
+bool game_settings_load(Settings* settings);

BIN
non_catalog_apps/air_arkanoid/icon.png


+ 357 - 0
non_catalog_apps/air_arkanoid/levels/level_game.c

@@ -0,0 +1,357 @@
+#include "level_game.h"
+#include "level_message.h"
+
+const NotificationSequence sequence_sound_ball_collide = {
+    &message_note_c7,
+    &message_delay_50,
+    &message_sound_off,
+    NULL,
+};
+
+const NotificationSequence sequence_sound_ball_paddle_collide = {
+    &message_note_d6,
+    &message_delay_10,
+    &message_sound_off,
+    NULL,
+};
+
+const NotificationSequence sequence_sound_ball_lost = {
+    &message_vibro_on,
+
+    &message_note_ds4,
+    &message_delay_10,
+    &message_sound_off,
+    &message_delay_10,
+
+    &message_note_ds4,
+    &message_delay_10,
+    &message_sound_off,
+    &message_delay_10,
+
+    &message_note_ds4,
+    &message_delay_10,
+    &message_sound_off,
+    &message_delay_10,
+
+    &message_vibro_off,
+    NULL,
+};
+
+typedef enum {
+    GameEventBallLost,
+} GameEvent;
+
+/****** Ball ******/
+
+static const EntityDescription paddle_desc;
+
+typedef struct {
+    Vector speed;
+    float radius;
+    float max_speed;
+} Ball;
+
+static void ball_reset(Ball* ball) {
+    ball->max_speed = 2;
+    ball->speed = (Vector){0, 0};
+    ball->radius = 2;
+}
+
+static void ball_start(Entity* self, GameManager* manager, void* context) {
+    UNUSED(manager);
+    Ball* ball = context;
+    ball_reset(ball);
+    entity_collider_add_circle(self, ball->radius);
+}
+
+static void ball_set_angle(Ball* ball, float angle) {
+    ball->speed.x = cosf(angle * (M_PI / 180.0f)) * ball->max_speed;
+    ball->speed.y = sinf(angle * (M_PI / 180.0f)) * ball->max_speed;
+}
+
+static void ball_update(Entity* entity, GameManager* manager, void* context) {
+    UNUSED(manager);
+    Ball* ball = context;
+    Vector pos = entity_pos_get(entity);
+    pos = vector_add(pos, ball->speed);
+
+    const Vector screen = {128, 64};
+
+    // prevent to go out of screen
+    if(pos.x - ball->radius < 0) {
+        pos.x = ball->radius;
+        ball->speed.x = -ball->speed.x;
+    } else if(pos.x + ball->radius > screen.x) {
+        pos.x = screen.x - ball->radius;
+        ball->speed.x = -ball->speed.x;
+    } else if(pos.y - ball->radius < 0) {
+        pos.y = ball->radius;
+        ball->speed.y = -ball->speed.y;
+    } else if(pos.y - ball->radius > screen.y) {
+        Level* level = game_manager_current_level_get(manager);
+        level_send_event(level, entity, &paddle_desc, GameEventBallLost, (EntityEventValue){0});
+    }
+
+    entity_pos_set(entity, pos);
+}
+
+static void ball_render(Entity* entity, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(manager);
+    Ball* ball = context;
+    Vector pos = entity_pos_get(entity);
+    canvas_draw_disc(canvas, pos.x, pos.y, ball->radius);
+}
+
+static const EntityDescription ball_desc = {
+    .start = ball_start,
+    .stop = NULL,
+    .update = ball_update,
+    .render = ball_render,
+    .collision = NULL,
+    .event = NULL,
+    .context_size = sizeof(Ball),
+};
+
+/****** Block ******/
+
+static const EntityDescription block_desc;
+
+typedef struct {
+    Vector size;
+} Block;
+
+static void block_spawn(Level* level, Vector pos, Vector size) {
+    Entity* block = level_add_entity(level, &block_desc);
+    entity_collider_add_rect(block, size.x, size.y);
+    entity_pos_set(block, pos);
+    Block* block_context = entity_context_get(block);
+    block_context->size = size;
+}
+
+static void block_render(Entity* entity, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(manager);
+    Block* block = context;
+    Vector pos = entity_pos_get(entity);
+    canvas_draw_box(
+        canvas, pos.x - block->size.x / 2, pos.y - block->size.y / 2, block->size.x, block->size.y);
+}
+
+static void block_collision(Entity* self, Entity* other, GameManager* manager, void* context) {
+    UNUSED(manager);
+
+    if(entity_description_get(other) == &ball_desc) {
+        Ball* ball = entity_context_get(other);
+        Block* block = context;
+        Vector ball_pos = entity_pos_get(other);
+        Vector block_pos = entity_pos_get(self);
+
+        Vector closest = {
+            CLAMP(ball_pos.x, block_pos.x + block->size.x / 2, block_pos.x - block->size.x / 2),
+            CLAMP(ball_pos.y, block_pos.y + block->size.y / 2, block_pos.y - block->size.y / 2),
+        };
+
+        // change the ball speed based on the collision
+        Vector distance = vector_sub(ball_pos, closest);
+        if(fabsf(distance.x) < fabsf(distance.y)) {
+            ball->speed.y = -ball->speed.y;
+        } else {
+            ball->speed.x = -ball->speed.x;
+        }
+
+        Level* level = game_manager_current_level_get(manager);
+        level_remove_entity(level, self);
+
+        GameContext* game = game_manager_game_context_get(manager);
+        game_sound_play(game, &sequence_sound_ball_collide);
+
+        if(level_entity_count(level, &block_desc) == 0) {
+            LevelMessageContext* message_context = level_context_get(game->levels.message);
+            furi_string_set(message_context->message, "You win!");
+            game_manager_next_level_set(manager, game->levels.message);
+        }
+    }
+}
+
+static const EntityDescription block_desc = {
+    .start = NULL,
+    .stop = NULL,
+    .update = NULL,
+    .render = block_render,
+    .collision = block_collision,
+    .event = NULL,
+    .context_size = sizeof(Block),
+};
+
+/****** Paddle ******/
+
+static const Vector paddle_start_size = {30, 3};
+
+typedef struct {
+    Vector size;
+    bool ball_launched;
+    Entity* ball;
+} Paddle;
+
+static void paddle_start(Entity* self, GameManager* manager, void* context) {
+    UNUSED(manager);
+    Paddle* paddle = context;
+    paddle->size = paddle_start_size;
+    paddle->ball_launched = false;
+    entity_pos_set(self, (Vector){64, 61});
+    entity_collider_add_rect(self, paddle->size.x, paddle->size.y);
+
+    Level* level = game_manager_current_level_get(manager);
+    paddle->ball = level_add_entity(level, &ball_desc);
+}
+
+static void paddle_stop(Entity* entity, GameManager* manager, void* context) {
+    UNUSED(entity);
+    Paddle* paddle = context;
+
+    Level* level = game_manager_current_level_get(manager);
+    level_remove_entity(level, paddle->ball);
+    paddle->ball = NULL;
+}
+
+static float paddle_x_from_angle(float angle) {
+    const float min_angle = -45.0f;
+    const float max_angle = 45.0f;
+
+    return 128.0f * (angle - min_angle) / (max_angle - min_angle);
+}
+
+static void paddle_update(Entity* entity, GameManager* manager, void* context) {
+    Paddle* paddle = context;
+    InputState input = game_manager_input_get(manager);
+    GameContext* game_context = game_manager_game_context_get(manager);
+
+    Vector pos = entity_pos_get(entity);
+    float paddle_half = paddle->size.x / 2;
+    if(game_context->imu_present) {
+        pos.x = paddle_x_from_angle(-imu_pitch_get(game_context->imu));
+    } else {
+        if(input.held & GameKeyLeft) {
+            pos.x -= 2;
+        }
+        if(input.held & GameKeyRight) {
+            pos.x += 2;
+        }
+    }
+    pos.x = CLAMP(pos.x, 128 - paddle_half, paddle_half);
+    entity_pos_set(entity, pos);
+
+    if(input.pressed & GameKeyBack) {
+        game_manager_next_level_set(manager, game_context->levels.menu);
+    }
+
+    if(input.pressed & GameKeyOk) {
+        if(!paddle->ball_launched) {
+            paddle->ball_launched = true;
+
+            Ball* ball = entity_context_get(paddle->ball);
+            ball_set_angle(ball, 270.0f);
+        }
+    }
+
+    if(!paddle->ball_launched) {
+        Vector ball_pos = entity_pos_get(paddle->ball);
+        Ball* ball = entity_context_get(paddle->ball);
+        ball_pos.x = pos.x;
+        ball_pos.y = pos.y - paddle->size.y / 2 - ball->radius;
+        entity_pos_set(paddle->ball, ball_pos);
+    }
+}
+
+static void paddle_render(Entity* entity, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(manager);
+    Paddle* paddle = context;
+    Vector pos = entity_pos_get(entity);
+    float paddle_half = paddle->size.x / 2;
+    canvas_draw_box(canvas, pos.x - paddle_half, pos.y, paddle->size.x, paddle->size.y);
+}
+
+static void paddle_collision(Entity* self, Entity* other, GameManager* manager, void* context) {
+    UNUSED(manager);
+
+    if(entity_description_get(other) == &ball_desc) {
+        Ball* ball = entity_context_get(other);
+        Paddle* paddle = context;
+        Vector ball_pos = entity_pos_get(other);
+        Vector paddle_pos = entity_pos_get(self);
+
+        float paddle_half = paddle->size.x / 2;
+        float paddle_center = paddle_pos.x;
+        float paddle_edge = paddle_center - paddle_half;
+        float paddle_edge_distance = ball_pos.x - paddle_edge;
+        float paddle_edge_distance_normalized = paddle_edge_distance / paddle->size.x;
+
+        // lerp the angle based on the distance from the paddle center
+        float angle = 270.0f - 45.0f + 90.0f * paddle_edge_distance_normalized;
+        ball_set_angle(ball, angle);
+
+        GameContext* game = game_manager_game_context_get(manager);
+        game_sound_play(game, &sequence_sound_ball_paddle_collide);
+    }
+}
+
+static void paddle_event(Entity* self, GameManager* manager, EntityEvent event, void* context) {
+    UNUSED(manager);
+    UNUSED(self);
+    if(event.type == GameEventBallLost) {
+        Paddle* paddle = context;
+        paddle->ball_launched = false;
+        Ball* ball = entity_context_get(paddle->ball);
+        ball_reset(ball);
+        GameContext* game = game_manager_game_context_get(manager);
+        game_sound_play(game, &sequence_sound_ball_lost);
+    }
+}
+
+static const EntityDescription paddle_desc = {
+    .start = paddle_start,
+    .stop = paddle_stop,
+    .update = paddle_update,
+    .render = paddle_render,
+    .collision = paddle_collision,
+    .event = paddle_event,
+    .context_size = sizeof(Paddle),
+};
+
+static void level_1_spawn(Level* level) {
+    level_add_entity(level, &paddle_desc);
+    const Vector block_size = {13, 5};
+    const Vector screen = {128, 64};
+    const int block_count_x = screen.x / block_size.x;
+    const int block_count_y = 6;
+    size_t block_spacing = 1;
+
+    for(int y = 0; y < block_count_y; y++) {
+        for(int x = 0; x < block_count_x; x++) {
+            Vector pos = {
+                (x) * (block_size.x + block_spacing) + block_size.x / 2,
+                (y) * (block_size.y + block_spacing) + block_size.y / 2,
+            };
+            block_spawn(level, pos, block_size);
+        }
+    }
+}
+
+static void level_game_start(Level* level, GameManager* manager, void* context) {
+    UNUSED(manager);
+    UNUSED(context);
+    level_1_spawn(level);
+}
+
+static void level_game_stop(Level* level, GameManager* manager, void* context) {
+    UNUSED(manager);
+    UNUSED(context);
+    level_clear(level);
+}
+
+const LevelBehaviour level_game = {
+    .alloc = NULL,
+    .free = NULL,
+    .start = level_game_start,
+    .stop = level_game_stop,
+    .context_size = 0,
+};

+ 4 - 0
non_catalog_apps/air_arkanoid/levels/level_game.h

@@ -0,0 +1,4 @@
+#pragma once
+#include "../game.h"
+
+extern const LevelBehaviour level_game;

+ 201 - 0
non_catalog_apps/air_arkanoid/levels/level_menu.c

@@ -0,0 +1,201 @@
+#include "level_menu.h"
+#include "../game.h"
+
+typedef struct {
+    Sprite* sprite;
+    Vector pos_start;
+    Vector pos_end;
+    float duration;
+    float time;
+} MovingSpriteContext;
+
+/***** Moving Sprite *****/
+
+static void moving_sprite_update(Entity* entity, GameManager* manager, void* context) {
+    UNUSED(manager);
+    MovingSpriteContext* sprite_context = context;
+
+    // lerp position between start and end for duration
+    if(sprite_context->time < sprite_context->duration) {
+        Vector dir = vector_sub(sprite_context->pos_end, sprite_context->pos_start);
+        Vector len = vector_mulf(dir, sprite_context->time / sprite_context->duration);
+        Vector pos = vector_add(sprite_context->pos_start, len);
+
+        entity_pos_set(entity, pos);
+        sprite_context->time += 1.0f;
+    } else {
+        entity_pos_set(entity, sprite_context->pos_end);
+    }
+}
+
+static void
+    moving_sprite_render(Entity* entity, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(manager);
+    MovingSpriteContext* sprite_context = context;
+
+    if(sprite_context->sprite) {
+        Vector pos = entity_pos_get(entity);
+        canvas_draw_sprite(canvas, sprite_context->sprite, pos.x, pos.y);
+    }
+}
+
+static void moving_sprite_init(
+    Entity* entity,
+    GameManager* manager,
+    Vector start,
+    Vector end,
+    const char* sprite_name) {
+    MovingSpriteContext* sprite_context = entity_context_get(entity);
+    sprite_context->pos_start = start;
+    sprite_context->pos_end = end;
+    sprite_context->duration = 30.0f;
+    sprite_context->time = 0;
+    sprite_context->sprite = game_manager_sprite_load(manager, sprite_name);
+}
+
+static void moving_sprite_reset(Entity* entity) {
+    MovingSpriteContext* sprite_context = entity_context_get(entity);
+    sprite_context->time = 0;
+}
+
+static const EntityDescription moving_sprite_desc = {
+    .start = NULL,
+    .stop = NULL,
+    .update = moving_sprite_update,
+    .render = moving_sprite_render,
+    .collision = NULL,
+    .event = NULL,
+    .context_size = sizeof(MovingSpriteContext),
+};
+
+/***** Menu *****/
+
+typedef struct {
+    int selected;
+} MenuContext;
+
+static void menu_update(Entity* entity, GameManager* manager, void* context) {
+    UNUSED(entity);
+    MenuContext* menu_context = context;
+    GameContext* game_context = game_manager_game_context_get(manager);
+
+    InputState input = game_manager_input_get(manager);
+    if(input.pressed & GameKeyBack) {
+        game_manager_game_stop(manager);
+    }
+
+    if(input.pressed & GameKeyUp) {
+        menu_context->selected--;
+        if(menu_context->selected < 0) {
+            menu_context->selected = 2;
+        }
+    }
+
+    if(input.pressed & GameKeyDown) {
+        menu_context->selected++;
+        if(menu_context->selected > 2) {
+            menu_context->selected = 0;
+        }
+    }
+
+    if(input.pressed & GameKeyUp || input.pressed & GameKeyDown || input.pressed & GameKeyOk) {
+        game_sound_play(game_context, &sequence_sound_menu);
+    }
+
+    if(input.pressed & GameKeyOk) {
+        switch(menu_context->selected) {
+        case 0:
+            game_manager_next_level_set(manager, game_context->levels.game);
+            break;
+        case 1:
+            game_manager_next_level_set(manager, game_context->levels.settings);
+            break;
+        case 2:
+            game_manager_game_stop(manager);
+            break;
+
+        default:
+            break;
+        }
+    }
+}
+
+#include "../fonts/fonts.h"
+
+static void menu_render(Entity* entity, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(entity);
+    UNUSED(manager);
+    MenuContext* menu_context = context;
+    const char* line_1 = "Play";
+    const char* line_2 = "Settings";
+    const char* line_3 = "Exit";
+
+    if(menu_context->selected == 0) {
+        line_1 = ">Play";
+    } else if(menu_context->selected == 1) {
+        line_2 = ">Settings";
+    } else if(menu_context->selected == 2) {
+        line_3 = ">Exit";
+    }
+
+    canvas_draw_str_aligned(canvas, 64, 39, AlignCenter, AlignCenter, line_1);
+    canvas_draw_str_aligned(canvas, 64, 49, AlignCenter, AlignCenter, line_2);
+    canvas_draw_str_aligned(canvas, 64, 59, AlignCenter, AlignCenter, line_3);
+}
+
+static const EntityDescription menu_desc = {
+    .start = NULL,
+    .stop = NULL,
+    .update = menu_update,
+    .render = menu_render,
+    .collision = NULL,
+    .event = NULL,
+    .context_size = sizeof(MenuContext),
+};
+
+/***** Level *****/
+
+typedef struct {
+    Entity* arkanoid;
+    Entity* air;
+} LevelMenuContext;
+
+static void level_menu_alloc(Level* level, GameManager* manager, void* context) {
+    LevelMenuContext* menu_context = context;
+
+    const float start = 256; // 0, due to the canvas draw limitations
+
+    menu_context->arkanoid = level_add_entity(level, &moving_sprite_desc);
+    moving_sprite_init(
+        menu_context->arkanoid,
+        manager,
+        (Vector){.x = start - 50, .y = start + 11},
+        (Vector){.x = start + 7, .y = start + 11},
+        "logo_arkanoid.fxbm");
+
+    menu_context->air = level_add_entity(level, &moving_sprite_desc);
+    moving_sprite_init(
+        menu_context->air,
+        manager,
+        (Vector){.x = start + 20, .y = start - 27},
+        (Vector){.x = start + 20, .y = start + 0},
+        "logo_air.fxbm");
+
+    level_add_entity(level, &menu_desc);
+}
+
+static void level_menu_start(Level* level, GameManager* manager, void* context) {
+    UNUSED(level);
+    UNUSED(manager);
+    LevelMenuContext* menu_context = context;
+    moving_sprite_reset(menu_context->arkanoid);
+    moving_sprite_reset(menu_context->air);
+}
+
+const LevelBehaviour level_menu = {
+    .alloc = level_menu_alloc,
+    .free = NULL,
+    .start = level_menu_start,
+    .stop = NULL,
+    .context_size = sizeof(LevelMenuContext),
+};

+ 4 - 0
non_catalog_apps/air_arkanoid/levels/level_menu.h

@@ -0,0 +1,4 @@
+#pragma once
+#include "../game.h"
+
+extern const LevelBehaviour level_menu;

+ 57 - 0
non_catalog_apps/air_arkanoid/levels/level_message.c

@@ -0,0 +1,57 @@
+#include <gui/elements.h>
+#include "level_message.h"
+
+static void message_update(Entity* self, GameManager* manager, void* context) {
+    UNUSED(self);
+    UNUSED(context);
+    InputState input = game_manager_input_get(manager);
+    if(input.pressed & GameKeyOk || input.pressed & GameKeyBack) {
+        GameContext* ctx = game_manager_game_context_get(manager);
+        game_manager_next_level_set(manager, ctx->levels.menu);
+    }
+}
+
+static void message_render(Entity* self, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(self);
+    UNUSED(manager);
+    UNUSED(context);
+    GameContext* game_ctx = game_manager_game_context_get(manager);
+    LevelMessageContext* ctx = level_context_get(game_ctx->levels.message);
+    canvas_set_font(canvas, FontPrimary);
+    canvas_draw_str_aligned(
+        canvas, 64, 30, AlignCenter, AlignTop, furi_string_get_cstr(ctx->message));
+    canvas_set_font(canvas, FontSecondary);
+}
+
+static const EntityDescription message_desc = {
+    .start = NULL,
+    .stop = NULL,
+    .update = message_update,
+    .render = message_render,
+    .collision = NULL,
+    .event = NULL,
+    .context_size = 0,
+};
+
+static void level_alloc(Level* level, GameManager* manager, void* ctx) {
+    UNUSED(level);
+    UNUSED(manager);
+    LevelMessageContext* context = ctx;
+    context->message = furi_string_alloc();
+    level_add_entity(level, &message_desc);
+}
+
+static void level_free(Level* level, GameManager* manager, void* context) {
+    UNUSED(level);
+    UNUSED(manager);
+    LevelMessageContext* ctx = context;
+    furi_string_free(ctx->message);
+}
+
+const LevelBehaviour level_message = {
+    .alloc = level_alloc,
+    .free = level_free,
+    .start = NULL,
+    .stop = NULL,
+    .context_size = sizeof(LevelMessageContext),
+};

+ 8 - 0
non_catalog_apps/air_arkanoid/levels/level_message.h

@@ -0,0 +1,8 @@
+#pragma once
+#include "../game.h"
+
+extern const LevelBehaviour level_message;
+
+typedef struct {
+    FuriString* message;
+} LevelMessageContext;

+ 223 - 0
non_catalog_apps/air_arkanoid/levels/level_settings.c

@@ -0,0 +1,223 @@
+#include "level_settings.h"
+
+/**** Menu ****/
+
+typedef enum {
+    Sound = 0,
+    ShowFPS,
+    Back,
+} MenuOption;
+
+typedef struct {
+    int selected;
+} MenuContext;
+
+static void menu_update(Entity* entity, GameManager* manager, void* context) {
+    UNUSED(entity);
+    MenuContext* menu_context = context;
+    GameContext* game_context = game_manager_game_context_get(manager);
+
+    InputState input = game_manager_input_get(manager);
+
+    if(input.pressed & GameKeyUp || input.pressed & GameKeyDown || input.pressed & GameKeyOk) {
+        game_sound_play(game_context, &sequence_sound_menu);
+    }
+
+    if(input.pressed & GameKeyBack) {
+        game_manager_next_level_set(manager, game_context->levels.menu);
+    }
+
+    if(input.pressed & GameKeyUp) {
+        menu_context->selected--;
+        if(menu_context->selected < Sound) {
+            menu_context->selected = Back;
+        }
+    }
+
+    if(input.pressed & GameKeyDown) {
+        menu_context->selected++;
+        if(menu_context->selected > Back) {
+            menu_context->selected = Sound;
+        }
+    }
+
+    if(input.pressed & GameKeyOk) {
+        switch(menu_context->selected) {
+        case Sound:
+            game_switch_sound(game_context);
+            break;
+        case ShowFPS:
+            game_switch_show_fps(game_context);
+            break;
+        case Back:
+            game_manager_next_level_set(manager, game_context->levels.menu);
+            break;
+
+        default:
+            break;
+        }
+    }
+
+    if(input.pressed & GameKeyRight || input.pressed & GameKeyLeft) {
+        switch(menu_context->selected) {
+        case Sound:
+            game_switch_sound(game_context);
+            break;
+        case ShowFPS:
+            game_switch_show_fps(game_context);
+            break;
+
+        default:
+            break;
+        }
+    }
+}
+
+static void menu_render(Entity* entity, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(entity);
+    MenuContext* menu_context = context;
+    GameContext* game_context = game_manager_game_context_get(manager);
+    FuriString* line = furi_string_alloc_set("Sound: ");
+
+    if(menu_context->selected == Sound) {
+        furi_string_set(line, ">Sound: ");
+    }
+
+    if(game_context->settings.sound) {
+        furi_string_cat(line, "On");
+    } else {
+        furi_string_cat(line, "Off");
+    }
+
+    canvas_draw_str_aligned(
+        canvas, 64 + 3, 18, AlignLeft, AlignCenter, furi_string_get_cstr(line));
+
+    furi_string_set(line, "FPS: ");
+    if(menu_context->selected == ShowFPS) {
+        furi_string_set(line, ">FPS: ");
+    }
+
+    if(game_context->settings.show_fps) {
+        furi_string_cat(line, "On");
+    } else {
+        furi_string_cat(line, "Off");
+    }
+
+    canvas_draw_str_aligned(
+        canvas, 64 + 3, 33, AlignLeft, AlignCenter, furi_string_get_cstr(line));
+
+    furi_string_set(line, "Back");
+
+    if(menu_context->selected == Back) {
+        furi_string_set(line, ">Back");
+    }
+
+    canvas_draw_str_aligned(
+        canvas, 64 + 3, 48, AlignLeft, AlignCenter, furi_string_get_cstr(line));
+
+    furi_string_free(line);
+}
+
+static const EntityDescription menu_desc = {
+    .start = NULL,
+    .stop = NULL,
+    .update = menu_update,
+    .render = menu_render,
+    .collision = NULL,
+    .event = NULL,
+    .context_size = sizeof(MenuContext),
+};
+
+/**** IMU Debug ****/
+
+typedef struct {
+    float pitch;
+    float roll;
+    float yaw;
+    bool imu_present;
+} IMUDebugContext;
+
+static void imu_debug_start(Entity* self, GameManager* manager, void* ctx) {
+    UNUSED(self);
+    IMUDebugContext* context = ctx;
+    context->pitch = 0;
+    context->roll = 0;
+    context->yaw = 0;
+    GameContext* game_context = game_manager_game_context_get(manager);
+    context->imu_present = game_context->imu_present;
+}
+
+static void imu_debug_update(Entity* self, GameManager* manager, void* ctx) {
+    UNUSED(self);
+    IMUDebugContext* context = (IMUDebugContext*)ctx;
+    GameContext* game_context = game_manager_game_context_get(manager);
+
+    if(game_context->imu_present) {
+        context->pitch = imu_pitch_get(game_context->imu);
+        context->roll = imu_roll_get(game_context->imu);
+        context->yaw = imu_yaw_get(game_context->imu);
+    }
+}
+
+static void imu_debug_render(Entity* self, GameManager* manager, Canvas* canvas, void* context) {
+    UNUSED(self);
+    UNUSED(manager);
+
+    Vector pos = {32, 32};
+    const float radius = 30;
+    const float max_angle = 45;
+    const float bubble_radius = 3;
+
+    canvas_draw_circle(canvas, pos.x, pos.y, radius);
+
+    IMUDebugContext* imu_debug_context = context;
+    if(imu_debug_context->imu_present) {
+        const float pitch = -CLAMP(imu_debug_context->pitch, max_angle, -max_angle);
+        const float roll = -CLAMP(imu_debug_context->roll, max_angle, -max_angle);
+        const float max_bubble_len = radius - bubble_radius - 2;
+
+        Vector ball = {
+            max_bubble_len * (pitch / max_angle),
+            max_bubble_len * (roll / max_angle),
+        };
+
+        float bubble_len = sqrtf(ball.x * ball.x + ball.y * ball.y);
+        if(bubble_len > max_bubble_len) {
+            ball.x = ball.x * max_bubble_len / bubble_len;
+            ball.y = ball.y * max_bubble_len / bubble_len;
+        }
+
+        ball = vector_add(pos, ball);
+
+        canvas_draw_disc(canvas, ball.x, ball.y, bubble_radius);
+    } else {
+        canvas_draw_str_aligned(canvas, pos.x, pos.y + 1, AlignCenter, AlignCenter, "No IMU");
+    }
+}
+
+static const EntityDescription imu_debug_desc = {
+    .start = imu_debug_start,
+    .stop = NULL,
+    .update = imu_debug_update,
+    .render = imu_debug_render,
+    .collision = NULL,
+    .event = NULL,
+    .context_size = sizeof(IMUDebugContext),
+};
+
+/**** Level  ****/
+
+static void level_settings_alloc(Level* level, GameManager* manager, void* ctx) {
+    UNUSED(ctx);
+    UNUSED(manager);
+    level_add_entity(level, &imu_debug_desc);
+    level_add_entity(level, &menu_desc);
+}
+
+const LevelBehaviour level_settings = {
+    .alloc = level_settings_alloc,
+    .free = NULL,
+    .start = NULL,
+    .stop = NULL,
+    .context_size = 0,
+};

+ 4 - 0
non_catalog_apps/air_arkanoid/levels/level_settings.h

@@ -0,0 +1,4 @@
+#pragma once
+#include "../game.h"
+
+extern const LevelBehaviour level_settings;

BIN
non_catalog_apps/air_arkanoid/sprites/logo_air.png


BIN
non_catalog_apps/air_arkanoid/sprites/logo_arkanoid.png


+ 115 - 0
non_catalog_apps/video_game_module_tool/app.c

@@ -0,0 +1,115 @@
+#include <furi.h>
+
+#include <furi_hal_rtc.h>
+#include <furi_hal_debug.h>
+
+#include <gui/gui.h>
+#include <expansion/expansion.h>
+
+#include "app_i.h"
+
+static bool custom_event_callback(void* context, uint32_t event) {
+    furi_assert(context);
+    App* app = context;
+    return scene_manager_handle_custom_event(app->scene_manager, event);
+}
+
+static bool back_event_callback(void* context) {
+    furi_assert(context);
+    App* app = context;
+    return scene_manager_handle_back_event(app->scene_manager);
+}
+
+static void tick_event_callback(void* context) {
+    furi_assert(context);
+    App* app = context;
+    scene_manager_handle_tick_event(app->scene_manager);
+}
+
+static App* app_alloc() {
+    App* app = malloc(sizeof(App));
+
+    app->file_path = furi_string_alloc();
+
+    app->view_dispatcher = view_dispatcher_alloc();
+    app->scene_manager = scene_manager_alloc(&scene_handlers, app);
+
+    app->widget = widget_alloc();
+    app->submenu = submenu_alloc();
+    app->progress = progress_alloc();
+
+    view_dispatcher_add_view(app->view_dispatcher, ViewIdWidget, widget_get_view(app->widget));
+    view_dispatcher_add_view(app->view_dispatcher, ViewIdSubmenu, submenu_get_view(app->submenu));
+    view_dispatcher_add_view(
+        app->view_dispatcher, ViewIdProgress, progress_get_view(app->progress));
+
+    view_dispatcher_enable_queue(app->view_dispatcher);
+    view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
+    view_dispatcher_set_custom_event_callback(app->view_dispatcher, custom_event_callback);
+    view_dispatcher_set_navigation_event_callback(app->view_dispatcher, back_event_callback);
+    view_dispatcher_set_tick_event_callback(app->view_dispatcher, tick_event_callback, 500);
+
+    app->notification = furi_record_open(RECORD_NOTIFICATION);
+
+    return app;
+}
+
+static void app_free(App* app) {
+    furi_record_close(RECORD_NOTIFICATION);
+
+    for(uint32_t i = 0; i < ViewIdMax; ++i) {
+        view_dispatcher_remove_view(app->view_dispatcher, i);
+    }
+
+    progress_free(app->progress);
+    submenu_free(app->submenu);
+    widget_free(app->widget);
+
+    scene_manager_free(app->scene_manager);
+    view_dispatcher_free(app->view_dispatcher);
+
+    furi_string_free(app->file_path);
+
+    free(app);
+}
+
+void submenu_item_common_callback(void* context, uint32_t index) {
+    furi_assert(context);
+
+    App* app = context;
+    view_dispatcher_send_custom_event(app->view_dispatcher, index);
+}
+
+int32_t vgm_tool_app(void* arg) {
+    UNUSED(arg);
+
+    Expansion* expansion = furi_record_open(RECORD_EXPANSION);
+    expansion_disable(expansion);
+
+    const bool is_debug_enabled = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
+    if(is_debug_enabled) {
+        furi_hal_debug_disable();
+    }
+
+    App* app = app_alloc();
+    Gui* gui = furi_record_open(RECORD_GUI);
+
+    view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
+    scene_manager_next_scene(app->scene_manager, SceneProbe);
+
+    view_dispatcher_run(app->view_dispatcher);
+
+    flasher_deinit();
+    app_free(app);
+
+    furi_record_close(RECORD_GUI);
+
+    if(is_debug_enabled) {
+        furi_hal_debug_enable();
+    }
+
+    expansion_enable(expansion);
+    furi_record_close(RECORD_EXPANSION);
+
+    return 0;
+}

+ 58 - 0
non_catalog_apps/video_game_module_tool/app_i.h

@@ -0,0 +1,58 @@
+/**
+ * @file app_i.h
+ * @brief Main application header file.
+ *
+ * Contains defines, structure definitions and function prototypes
+ * used throughout the whole application.
+ */
+#pragma once
+
+#include <gui/scene_manager.h>
+#include <gui/view_dispatcher.h>
+
+#include <gui/modules/widget.h>
+#include <gui/modules/submenu.h>
+
+#include <storage/storage.h>
+
+#include <notification/notification.h>
+
+#include "scenes/scene.h"
+#include "views/progress.h"
+#include "flasher/flasher.h"
+
+#define VGM_TOOL_TAG "VgmTool"
+
+// This can be set by the build system to avoid manual code editing
+#ifndef VGM_FW_VERSION
+#define VGM_FW_VERSION "0.1.0"
+#endif
+#define VGM_FW_FILE_EXTENSION ".uf2"
+#define VGM_FW_FILE_NAME "vgm-fw-" VGM_FW_VERSION VGM_FW_FILE_EXTENSION
+
+#define VGM_DEFAULT_FW_FILE APP_ASSETS_PATH(VGM_FW_FILE_NAME)
+#define VGM_FW_DEFAULT_PATH EXT_PATH("")
+
+typedef struct {
+    SceneManager* scene_manager;
+    ViewDispatcher* view_dispatcher;
+
+    Widget* widget;
+    Submenu* submenu;
+    Progress* progress;
+
+    NotificationApp* notification;
+
+    FuriString* file_path;
+    FlasherError flasher_error;
+} App;
+
+typedef enum {
+    ViewIdWidget,
+    ViewIdSubmenu,
+    ViewIdProgress,
+
+    ViewIdMax,
+} ViewId;
+
+void submenu_item_common_callback(void* context, uint32_t index);

+ 17 - 0
non_catalog_apps/video_game_module_tool/application.fam

@@ -0,0 +1,17 @@
+App(
+    appid="video_game_module_tool",
+    name="Video Game Module Tool",
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="vgm_tool_app",
+    requires=[
+        "gui",
+        "dialogs",
+    ],
+    stack_size=2048,
+    fap_description="Update Video Game Module's firmware directly from Flipper",
+    fap_version="1.0",
+    fap_icon="vgm_tool.png",
+    fap_category="Tools",
+    fap_icon_assets="icons",
+    fap_file_assets="files",
+)

+ 11 - 0
non_catalog_apps/video_game_module_tool/custom_event.h

@@ -0,0 +1,11 @@
+#pragma once
+
+typedef enum {
+    // Reserve first 100 events for submenu indexes, starting from 0
+    CustomEventReserved = 100,
+
+    CustomEventFileConfirmed,
+    CustomEventFileRejected,
+    CustomEventSuccessDismissed,
+    CustomEventRetryRequested,
+} CustomEvent;

BIN
non_catalog_apps/video_game_module_tool/files/vgm-fw-0.1.0.uf2


+ 23 - 0
non_catalog_apps/video_game_module_tool/flasher/board.c

@@ -0,0 +1,23 @@
+#include "board.h"
+
+#include <furi.h>
+#include <furi_hal_resources.h>
+
+#define BOARD_RESET_PIN (gpio_ext_pc1)
+
+void board_init(void) {
+    furi_hal_gpio_write(&BOARD_RESET_PIN, false);
+    furi_hal_gpio_init(&BOARD_RESET_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
+}
+
+void board_deinit(void) {
+    furi_hal_gpio_write(&BOARD_RESET_PIN, false);
+    furi_hal_gpio_init_simple(&BOARD_RESET_PIN, GpioModeAnalog);
+}
+
+void board_reset(void) {
+    furi_hal_gpio_write(&BOARD_RESET_PIN, true);
+    furi_delay_ms(5);
+    furi_hal_gpio_write(&BOARD_RESET_PIN, false);
+    furi_delay_ms(5);
+}

+ 23 - 0
non_catalog_apps/video_game_module_tool/flasher/board.h

@@ -0,0 +1,23 @@
+/**
+ * @file board.h
+ * @brief Video Game Module-specific functions.
+ */
+#pragma once
+
+/**
+ * @brief Initialise the module-specific hardware.
+ */
+void board_init(void);
+
+/**
+ * @brief Disable the module-specific hardware.
+ */
+void board_deinit(void);
+
+/**
+ * @brief Reset the module.
+ *
+ * Resets the Video Game Module through the dedicated
+ * reset pin (Pin 15)
+ */
+void board_reset(void);

+ 292 - 0
non_catalog_apps/video_game_module_tool/flasher/flasher.c

@@ -0,0 +1,292 @@
+#include "flasher.h"
+
+#include <furi.h>
+#include <storage/storage.h>
+
+#include "uf2.h"
+#include "swd.h"
+#include "board.h"
+#include "target.h"
+#include "rp2040.h"
+
+#define TAG "VgmFlasher"
+
+#define W25Q128_CAPACITY (0x1000000UL)
+#define W25Q128_PAGE_SIZE (0x100UL)
+#define W25Q128_SECTOR_SIZE (0x1000UL)
+
+#define PROGRESS_VERIFY_WEIGHT (4U)
+#define PROGRESS_ERASE_WEIGHT (6U)
+#define PROGRESS_PROGRAM_WEIGHT (90U)
+
+#define FLASHER_ATTEMPT_COUNT (10UL)
+
+typedef struct {
+    FlasherCallback callback;
+    void* context;
+} Flasher;
+
+static Flasher flasher;
+
+bool flasher_init(void) {
+    FURI_LOG_D(TAG, "Attaching the target");
+
+    board_init();
+
+    bool success = false;
+    FURI_CRITICAL_ENTER();
+    do {
+        swd_init();
+        if(!target_attach(RP2040_CORE0_ADDR)) {
+            FURI_LOG_E(TAG, "Failed to attach target");
+            break;
+        }
+        success = true;
+    } while(false);
+    FURI_CRITICAL_EXIT();
+
+    if(!success) {
+        flasher_deinit();
+    }
+
+    return success;
+}
+
+void flasher_deinit(void) {
+    FURI_LOG_D(TAG, "Detaching target and restoring pins");
+
+    FURI_CRITICAL_ENTER();
+    target_detach();
+    swd_deinit();
+    FURI_CRITICAL_EXIT();
+
+    board_reset();
+    board_deinit();
+}
+
+void flasher_set_callback(FlasherCallback callback, void* context) {
+    flasher.callback = callback;
+    flasher.context = context;
+}
+
+static inline bool flasher_init_chip(void) {
+    FURI_CRITICAL_ENTER();
+    const bool success = rp2040_init();
+    FURI_CRITICAL_EXIT();
+    return success;
+}
+
+static inline bool flasher_erase_sector(uint32_t address) {
+    FURI_CRITICAL_ENTER();
+    const bool success = rp2040_flash_erase_sector(address);
+    FURI_CRITICAL_EXIT();
+    return success;
+}
+
+static inline bool flasher_program_page(uint32_t address, const void* data, size_t data_size) {
+    FURI_CRITICAL_ENTER();
+    const bool success = rp2040_flash_program_page(address, data, data_size);
+    FURI_CRITICAL_EXIT();
+    return success;
+}
+
+static void flasher_emit_progress(uint8_t start, uint8_t weight, uint8_t progress) {
+    furi_assert(flasher.callback);
+
+    FlasherEvent event = {
+        .type = FlasherEventTypeProgress,
+        .progress = start + ((uint32_t)weight * progress) / 100U,
+    };
+
+    flasher.callback(event, flasher.context);
+}
+
+static void flasher_emit_error(FlasherError error) {
+    furi_assert(flasher.callback);
+
+    FlasherEvent event = {
+        .type = FlasherEventTypeError,
+        .error = error,
+    };
+
+    flasher.callback(event, flasher.context);
+}
+
+static void flasher_emit_success(void) {
+    furi_assert(flasher.callback);
+
+    FlasherEvent event = {
+        .type = FlasherEventTypeSuccess,
+    };
+
+    flasher.callback(event, flasher.context);
+}
+
+static bool flasher_prepare_target(void) {
+    bool success = false;
+
+    for(uint32_t i = 0; i < FLASHER_ATTEMPT_COUNT; ++i) {
+        if(flasher_init()) {
+            success = true;
+            break;
+        }
+        furi_delay_ms(10);
+    }
+
+    if(!success) {
+        flasher_emit_error(FlasherErrorDisconnect);
+    }
+
+    return success;
+}
+
+static bool flasher_prepare_file(File* file, const char* file_path) {
+    bool success = false;
+
+    do {
+        if(!flasher_init_chip()) {
+            FURI_LOG_E(TAG, "Failed to initialise chip");
+            flasher_emit_error(FlasherErrorDisconnect);
+            break;
+        }
+        if(!storage_file_open(file, file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
+            FURI_LOG_E(TAG, "Failed to open firmware file: %s", file_path);
+            flasher_emit_error(FlasherErrorBadFile);
+            break;
+        }
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool flasher_verify_file(File* file, size_t* data_size) {
+    bool success = false;
+
+    do {
+        uint32_t block_count;
+        if(!uf2_get_block_count(file, &block_count)) {
+            FURI_LOG_E(TAG, "Failed to get block count");
+            flasher_emit_error(FlasherErrorBadFile);
+            break;
+        }
+
+        uint32_t blocks_verified;
+        uint8_t prev_progress = UINT8_MAX;
+
+        for(blocks_verified = 0; blocks_verified < block_count; ++blocks_verified) {
+            if(!uf2_verify_block(file, RP2040_FAMILY_ID, W25Q128_PAGE_SIZE)) break;
+
+            const uint8_t verify_progress = (blocks_verified * 100UL) / block_count;
+            if(verify_progress != prev_progress) {
+                prev_progress = verify_progress;
+                flasher_emit_progress(0, PROGRESS_VERIFY_WEIGHT, verify_progress);
+                FURI_LOG_D(TAG, "Verifying file: %u%%", verify_progress);
+            }
+        }
+
+        if(blocks_verified < block_count) {
+            FURI_LOG_E(TAG, "Failed to verify all blocks");
+            flasher_emit_error(FlasherErrorBadFile);
+            break;
+        }
+
+        const size_t size_total = block_count * W25Q128_PAGE_SIZE;
+
+        if(size_total > W25Q128_CAPACITY) {
+            FURI_LOG_E(TAG, "File is too large to fit on the flash");
+            flasher_emit_error(FlasherErrorBadFile);
+            break;
+        }
+
+        if(!storage_file_seek(file, 0, true)) {
+            FURI_LOG_E(TAG, "Failed to rewind the file");
+            flasher_emit_error(FlasherErrorBadFile);
+            break;
+        }
+
+        *data_size = size_total;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool flasher_erase_flash(size_t erase_size) {
+    uint8_t prev_progress = UINT8_MAX;
+
+    size_t size_erased;
+    for(size_erased = 0; size_erased < erase_size;) {
+        if(!flasher_erase_sector(size_erased)) {
+            FURI_LOG_E(TAG, "Failed to erase flash sector at address 0x%zX", size_erased);
+            flasher_emit_error(FlasherErrorDisconnect);
+            break;
+        }
+
+        size_erased += MIN(erase_size - size_erased, W25Q128_SECTOR_SIZE);
+
+        const uint8_t erase_progress = (size_erased * 100UL) / erase_size;
+        if(erase_progress != prev_progress) {
+            prev_progress = erase_progress;
+            flasher_emit_progress(PROGRESS_VERIFY_WEIGHT, PROGRESS_ERASE_WEIGHT, erase_progress);
+            FURI_LOG_D(TAG, "Erasing flash: %u%%", erase_progress);
+        }
+    }
+
+    return size_erased == erase_size;
+}
+
+static bool flasher_program_flash(File* file, size_t data_size) {
+    uint8_t prev_progress = UINT8_MAX;
+
+    size_t size_programmed;
+    for(size_programmed = 0; size_programmed < data_size;) {
+        uint8_t buf[W25Q128_PAGE_SIZE];
+
+        if(!uf2_read_block(file, buf, W25Q128_PAGE_SIZE)) {
+            FURI_LOG_E(TAG, "Failed to read UF2 block");
+            flasher_emit_error(FlasherErrorBadFile);
+            break;
+        }
+
+        if(!flasher_program_page(size_programmed, buf, W25Q128_PAGE_SIZE)) {
+            FURI_LOG_E(TAG, "Failed to program flash page at address 0x%zX", size_programmed);
+            flasher_emit_error(FlasherErrorDisconnect);
+            break;
+        }
+
+        size_programmed += W25Q128_PAGE_SIZE;
+
+        const uint8_t program_progress = (size_programmed * 100UL) / data_size;
+        if(program_progress != prev_progress) {
+            prev_progress = program_progress;
+            flasher_emit_progress(
+                PROGRESS_VERIFY_WEIGHT + PROGRESS_ERASE_WEIGHT,
+                PROGRESS_PROGRAM_WEIGHT,
+                program_progress);
+            FURI_LOG_D(TAG, "Programming flash: %u%%", program_progress);
+        }
+    }
+
+    return size_programmed == data_size;
+}
+
+void flasher_start(const char* file_path) {
+    FURI_LOG_D(TAG, "Flashing firmware from file: %s", file_path);
+
+    Storage* storage = furi_record_open(RECORD_STORAGE);
+    File* file = storage_file_alloc(storage);
+    size_t data_size;
+
+    do {
+        if(!flasher_prepare_target()) break;
+        if(!flasher_prepare_file(file, file_path)) break;
+        if(!flasher_verify_file(file, &data_size)) break;
+        if(!flasher_erase_flash(data_size)) break;
+        if(!flasher_program_flash(file, data_size)) break;
+        flasher_emit_success();
+    } while(false);
+
+    storage_file_free(file);
+    furi_record_close(RECORD_STORAGE);
+}

+ 84 - 0
non_catalog_apps/video_game_module_tool/flasher/flasher.h

@@ -0,0 +1,84 @@
+/**
+ * @file flasher.h
+ * @brief High-level functions for flashing the VGM firmware.
+ */
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/**
+ * @brief Enumeration of possible flasher event types.
+ */
+typedef enum {
+    FlasherEventTypeProgress, /**< Operation progress has been reported. */
+    FlasherEventTypeSuccess, /**< Operation has finished successfully. */
+    FlasherEventTypeError, /**< Operation has finished with an error. */
+} FlasherEventType;
+
+/**
+ * @brief Enumeration of possible flasher errors.
+ */
+typedef enum {
+    FlasherErrorBadFile, /**< File error: wrong format, I/O problem, etc.*/
+    FlasherErrorDisconnect, /**< Connection error: Module disconnected, frozen, etc. */
+    FlasherErrorUnknown, /**< An error that does not fit to any of the above categories. */
+} FlasherError;
+
+/**
+ * @brief Flasher event structure.
+ *
+ * Events of FlasherEventTypeSuccess type do not carry additional data.
+ */
+typedef struct {
+    FlasherEventType type; /**< Type of the event that has occurred. */
+    union {
+        uint8_t progress; /**< Progress value (0-100). */
+        FlasherError error; /**< Error value. */
+    };
+} FlasherEvent;
+
+/**
+ * @brief Flasher event callback type.
+ *
+ * @param[in] event Description of the event that has occurred.
+ * @param[in,out] context Pointer to a user-specified object.
+ */
+typedef void (*FlasherCallback)(FlasherEvent event, void* context);
+
+/**
+ * @brief Initialise the flasher.
+ *
+ * Calling this function will initialise the GPIO, set up the debug
+ * connection, halt the module's CPU, etc.
+ *
+ * @returns true on success, false on failure.
+ */
+bool flasher_init(void);
+
+/**
+ * @brief Disable the flasher.
+ *
+ * Calling this function will disable all activated hardware and
+ * reset the module.
+ */
+void flasher_deinit(void);
+
+/**
+ * @brief Set callback for flasher events.
+ *
+ * The callback MUST be set before calling flasher_start().
+ *
+ * @param[in] callback pointer to the function used to receive events.
+ * @param[in] context pointer to a user-specified object (will be passed to the callback function).
+ */
+void flasher_set_callback(FlasherCallback callback, void* context);
+
+/**
+ * @brief Start the flashing process.
+ *
+ * The only way to get the return value is via the event callback.
+ *
+ * @param[in] file_path pointer to a zero-terminated string containing the full firmware file path.
+ */
+void flasher_start(const char* file_path);

+ 433 - 0
non_catalog_apps/video_game_module_tool/flasher/rp2040.c

@@ -0,0 +1,433 @@
+#include "rp2040.h"
+
+#include <furi.h>
+
+#include "target.h"
+
+// Most of the below code is heavily inspired by or taken directly from:
+// Blackmagic: https://github.com/blackmagic-debug/blackmagic
+// Pico-bootrom: https://github.com/raspberrypi/pico-bootrom
+
+#define RP_REG_ACCESS_NORMAL 0x0000U
+#define RP_REG_ACCESS_WRITE_XOR 0x1000U
+#define RP_REG_ACCESS_WRITE_ATOMIC_BITSET 0x2000U
+#define RP_REG_ACCESS_WRITE_ATOMIC_BITCLR 0x3000U
+
+#define RP_CLOCKS_BASE_ADDR 0x40008000U
+#define RP_CLOCKS_WAKE_EN0 (RP_CLOCKS_BASE_ADDR + 0xa0U)
+#define RP_CLOCKS_WAKE_EN1 (RP_CLOCKS_BASE_ADDR + 0xa4U)
+#define RP_CLOCKS_WAKE_EN0_MASK 0xff0c0f19U
+#define RP_CLOCKS_WAKE_EN1_MASK 0x00002007U
+
+#define RP_GPIO_QSPI_BASE_ADDR 0x40018000U
+#define RP_GPIO_QSPI_SCLK_CTRL (RP_GPIO_QSPI_BASE_ADDR + 0x04U)
+#define RP_GPIO_QSPI_CS_CTRL (RP_GPIO_QSPI_BASE_ADDR + 0x0cU)
+#define RP_GPIO_QSPI_SD0_CTRL (RP_GPIO_QSPI_BASE_ADDR + 0x14U)
+#define RP_GPIO_QSPI_SD1_CTRL (RP_GPIO_QSPI_BASE_ADDR + 0x1cU)
+#define RP_GPIO_QSPI_SD2_CTRL (RP_GPIO_QSPI_BASE_ADDR + 0x24U)
+#define RP_GPIO_QSPI_SD3_CTRL (RP_GPIO_QSPI_BASE_ADDR + 0x2cU)
+#define RP_GPIO_QSPI_CS_DRIVE_NORMAL (0U << 8U)
+#define RP_GPIO_QSPI_CS_DRIVE_INVERT (1U << 8U)
+#define RP_GPIO_QSPI_CS_DRIVE_LOW (2U << 8U)
+#define RP_GPIO_QSPI_CS_DRIVE_HIGH (3U << 8U)
+#define RP_GPIO_QSPI_CS_DRIVE_MASK 0x00000300U
+#define RP_GPIO_QSPI_SD1_CTRL_INOVER_BITS 0x00030000U
+#define RP_GPIO_QSPI_SCLK_POR 0x0000001fU
+
+#define RP_SSI_BASE_ADDR 0x18000000U
+#define RP_SSI_CTRL0 (RP_SSI_BASE_ADDR + 0x00U)
+#define RP_SSI_CTRL1 (RP_SSI_BASE_ADDR + 0x04U)
+#define RP_SSI_ENABLE (RP_SSI_BASE_ADDR + 0x08U)
+#define RP_SSI_SER (RP_SSI_BASE_ADDR + 0x10U)
+#define RP_SSI_BAUD (RP_SSI_BASE_ADDR + 0x14U)
+#define RP_SSI_TXFLR (RP_SSI_BASE_ADDR + 0x20U)
+#define RP_SSI_RXFLR (RP_SSI_BASE_ADDR + 0x24U)
+#define RP_SSI_SR (RP_SSI_BASE_ADDR + 0x28U)
+#define RP_SSI_ICR (RP_SSI_BASE_ADDR + 0x48U)
+#define RP_SSI_DR0 (RP_SSI_BASE_ADDR + 0x60U)
+#define RP_SSI_XIP_SPI_CTRL0 (RP_SSI_BASE_ADDR + 0xf4U)
+#define RP_SSI_CTRL0_FRF_MASK 0x00600000U
+#define RP_SSI_CTRL0_FRF_SERIAL (0U << 21U)
+#define RP_SSI_CTRL0_FRF_DUAL (1U << 21U)
+#define RP_SSI_CTRL0_FRF_QUAD (2U << 21U)
+#define RP_SSI_CTRL0_TMOD_MASK 0x00000300U
+#define RP_SSI_CTRL0_TMOD_BIDI (0U << 8U)
+#define RP_SSI_CTRL0_TMOD_TX_ONLY (1U << 8U)
+#define RP_SSI_CTRL0_TMOD_RX_ONLY (2U << 8U)
+#define RP_SSI_CTRL0_TMOD_EEPROM (3U << 8U)
+#define RP_SSI_CTRL0_DATA_BIT_MASK 0x001f0000U
+#define RP_SSI_CTRL0_DATA_BIT_SHIFT 16U
+#define RP_SSI_CTRL0_DATA_BITS(x) (((x)-1U) << RP_SSI_CTRL0_DATA_BIT_SHIFT)
+#define RP_SSI_CTRL0_MASK \
+    (RP_SSI_CTRL0_FRF_MASK | RP_SSI_CTRL0_TMOD_MASK | RP_SSI_CTRL0_DATA_BIT_MASK)
+#define RP_SSI_ENABLE_SSI (1U << 0U)
+#define RP_SSI_XIP_SPI_CTRL0_FORMAT_STD_SPI (0U << 0U)
+#define RP_SSI_XIP_SPI_CTRL0_FORMAT_SPLIT (1U << 0U)
+#define RP_SSI_XIP_SPI_CTRL0_FORMAT_FRF (2U << 0U)
+#define RP_SSI_XIP_SPI_CTRL0_ADDRESS_LENGTH(x) (((x)*2U) << 2U)
+#define RP_SSI_XIP_SPI_CTRL0_INSTR_LENGTH_8b (2U << 8U)
+#define RP_SSI_XIP_SPI_CTRL0_WAIT_CYCLES(x) (((x)*8U) << 11U)
+#define RP_SSI_XIP_SPI_CTRL0_XIP_CMD_SHIFT 24U
+#define RP_SSI_XIP_SPI_CTRL0_XIP_CMD(x) ((x) << RP_SSI_XIP_SPI_CTRL0_XIP_CMD_SHIFT)
+#define RP_SSI_XIP_SPI_CTRL0_TRANS_1C1A (0U << 0U)
+#define RP_SSI_XIP_SPI_CTRL0_TRANS_1C2A (1U << 0U)
+#define RP_SSI_XIP_SPI_CTRL0_TRANS_2C2A (2U << 0U)
+
+#define RP_PADS_QSPI_BASE_ADDR 0x40020000U
+#define RP_PADS_QSPI_GPIO_SCLK (RP_PADS_QSPI_BASE_ADDR + 0x04U)
+#define RP_PADS_QSPI_GPIO_SD0 (RP_PADS_QSPI_BASE_ADDR + 0x08U)
+#define RP_PADS_QSPI_GPIO_SD1 (RP_PADS_QSPI_BASE_ADDR + 0x0cU)
+#define RP_PADS_QSPI_GPIO_SD2 (RP_PADS_QSPI_BASE_ADDR + 0x10U)
+#define RP_PADS_QSPI_GPIO_SD3 (RP_PADS_QSPI_BASE_ADDR + 0x14U)
+#define RP_PADS_QSPI_GPIO_SCLK_FAST_SLEW 0x00000001U
+#define RP_PADS_QSPI_GPIO_SCLK_8mA_DRIVE 0x00000020U
+#define RP_PADS_QSPI_GPIO_SCLK_IE 0x00000040U
+#define RP_PADS_QSPI_GPIO_SD0_OD_BITS 0x00000080U
+#define RP_PADS_QSPI_GPIO_SD0_PUE_BITS 0x00000008U
+#define RP_PADS_QSPI_GPIO_SD0_PDE_BITS 0x00000004U
+
+#define RP_RESETS_BASE_ADDR 0x4000c000U
+#define RP_RESETS_RESET (RP_RESETS_BASE_ADDR + 0x00U)
+#define RP_RESETS_RESET_DONE (RP_RESETS_BASE_ADDR + 0x08U)
+#define RP_RESETS_RESET_IO_QSPI_BITS 0x00000040U
+#define RP_RESETS_RESET_PADS_QSPI_BITS 0x00000200U
+
+// SPI Flash defines
+#define SPI_FLASH_OPCODE_MASK 0x00ffU
+#define SPI_FLASH_OPCODE(x) ((x)&SPI_FLASH_OPCODE_MASK)
+#define SPI_FLASH_DUMMY_MASK 0x0700U
+#define SPI_FLASH_DUMMY_SHIFT 8U
+#define SPI_FLASH_DUMMY_LEN(x) (((x) << SPI_FLASH_DUMMY_SHIFT) & SPI_FLASH_DUMMY_MASK)
+#define SPI_FLASH_OPCODE_MODE_MASK 0x0800U
+#define SPI_FLASH_OPCODE_ONLY (0U << 11U)
+#define SPI_FLASH_OPCODE_3B_ADDR (1U << 11U)
+#define SPI_FLASH_DATA_MASK 0x1000U
+#define SPI_FLASH_DATA_SHIFT 12U
+#define SPI_FLASH_DATA_IN (0U << SPI_FLASH_DATA_SHIFT)
+#define SPI_FLASH_DATA_OUT (1U << SPI_FLASH_DATA_SHIFT)
+
+#define SPI_FLASH_CMD_WRITE_ENABLE \
+    (SPI_FLASH_OPCODE_ONLY | SPI_FLASH_DUMMY_LEN(0) | SPI_FLASH_OPCODE(0x06U))
+#define SPI_FLASH_CMD_PAGE_PROGRAM                                            \
+    (SPI_FLASH_OPCODE_3B_ADDR | SPI_FLASH_DATA_OUT | SPI_FLASH_DUMMY_LEN(0) | \
+     SPI_FLASH_OPCODE(0x02))
+#define SPI_FLASH_CMD_SECTOR_ERASE \
+    (SPI_FLASH_OPCODE_3B_ADDR | SPI_FLASH_DUMMY_LEN(0) | SPI_FLASH_OPCODE(0x20U))
+#define SPI_FLASH_CMD_CHIP_ERASE \
+    (SPI_FLASH_OPCODE_ONLY | SPI_FLASH_DUMMY_LEN(0) | SPI_FLASH_OPCODE(0x60U))
+#define SPI_FLASH_CMD_READ_STATUS \
+    (SPI_FLASH_OPCODE_ONLY | SPI_FLASH_DATA_IN | SPI_FLASH_DUMMY_LEN(0) | SPI_FLASH_OPCODE(0x05U))
+#define SPI_FLASH_CMD_READ_JEDEC_ID \
+    (SPI_FLASH_OPCODE_ONLY | SPI_FLASH_DATA_IN | SPI_FLASH_DUMMY_LEN(0) | SPI_FLASH_OPCODE(0x9FU))
+#define SPI_FLASH_CMD_READ_SFDP                                              \
+    (SPI_FLASH_OPCODE_3B_ADDR | SPI_FLASH_DATA_IN | SPI_FLASH_DUMMY_LEN(1) | \
+     SPI_FLASH_OPCODE(0x5AU))
+#define SPI_FLASH_CMD_WAKE_UP \
+    (SPI_FLASH_OPCODE_ONLY | SPI_FLASH_DUMMY_LEN(0) | SPI_FLASH_OPCODE(0xABU))
+#define SPI_FLASH_CMD_READ_DATA                                              \
+    (SPI_FLASH_OPCODE_3B_ADDR | SPI_FLASH_DATA_IN | SPI_FLASH_DUMMY_LEN(0) | \
+     SPI_FLASH_OPCODE(0x03U))
+
+#define SPI_FLASH_STATUS_BUSY 0x01U
+#define SPI_FLASH_STATUS_WRITE_ENABLED 0x02U
+
+#define RP2040_IO_PADS_BITS (RP_RESETS_RESET_IO_QSPI_BITS | RP_RESETS_RESET_PADS_QSPI_BITS)
+
+#define W25X_CMD_RESET_ENABLE (0x66U)
+#define W25X_CMD_RESET (0x99U)
+
+#define TAG "VgmRp2040"
+
+static bool rp2040_spi_gpio_init(void) {
+    bool success = false;
+
+    do {
+        if(!target_write_memory_32(
+               RP_RESETS_RESET | RP_REG_ACCESS_WRITE_ATOMIC_BITSET, RP2040_IO_PADS_BITS))
+            break;
+        if(!target_write_memory_32(
+               RP_RESETS_RESET | RP_REG_ACCESS_WRITE_ATOMIC_BITCLR, RP2040_IO_PADS_BITS))
+            break;
+
+        uint32_t reset_done = 0;
+        while((reset_done & RP2040_IO_PADS_BITS) != RP2040_IO_PADS_BITS) {
+            if(!target_read_memory_32(RP_RESETS_RESET_DONE, &reset_done)) break;
+        }
+
+        if(reset_done == 0) break;
+
+        if(!target_write_memory_32(RP_GPIO_QSPI_SCLK_CTRL, 0)) break;
+        if(!target_write_memory_32(RP_GPIO_QSPI_CS_CTRL, 0)) break;
+        if(!target_write_memory_32(RP_GPIO_QSPI_SD0_CTRL, 0)) break;
+        if(!target_write_memory_32(RP_GPIO_QSPI_SD1_CTRL, 0)) break;
+        if(!target_write_memory_32(RP_GPIO_QSPI_SD2_CTRL, 0)) break;
+        if(!target_write_memory_32(RP_GPIO_QSPI_SD3_CTRL, 0)) break;
+
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+// Configure SSI in regular SPI mode
+static bool rp2040_spi_init(void) {
+    bool success = false;
+
+    do {
+        // Disable SSI
+        if(!target_write_memory_32(RP_SSI_ENABLE, 0)) break;
+        // Clear error all flags
+        if(!target_read_memory_32(RP_SSI_SR, NULL)) break;
+        // Clear all pending interrupts
+        if(!target_read_memory_32(RP_SSI_ICR, NULL)) break;
+        // Set SPI clock divisor (Fclk_out = Fssi_clk / RP_SSI_BAUD)
+        if(!target_write_memory_32(RP_SSI_BAUD, 6UL)) break;
+        // Set SPI configuration:
+        // - Regular 1-bit SPI frame format,
+        // - Frame size = 8 bit,
+        // - Both transmit and receive
+        if(!target_write_memory_32(
+               RP_SSI_CTRL0,
+               RP_SSI_CTRL0_FRF_SERIAL | RP_SSI_CTRL0_DATA_BITS(8) | RP_SSI_CTRL0_TMOD_BIDI))
+            break;
+        if(!target_write_memory_32(RP_SSI_SER, 1)) break;
+        // Enable SSI
+        if(!target_write_memory_32(RP_SSI_ENABLE, 1)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+// Force CS pin to a chosen state
+static bool rp2040_spi_chip_select(uint32_t state) {
+    bool success = false;
+
+    do {
+        uint32_t cs_value;
+        // Read GPIO control register
+        if(!target_read_memory_32(RP_GPIO_QSPI_CS_CTRL, &cs_value)) break;
+        // Modify GPIO control register
+        if(!target_write_memory_32(
+               RP_GPIO_QSPI_CS_CTRL, (cs_value & (~RP_GPIO_QSPI_CS_DRIVE_MASK)) | state))
+            break;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+// Perform an SPI transaction (transmit one byte, receive one byte at the same time)
+static bool rp2040_spi_txrx(uint8_t tx_data, uint8_t* rx_data) {
+    bool success = false;
+
+    do {
+        // Write to SSI data register 0
+        if(!target_write_memory_32(RP_SSI_DR0, tx_data)) break;
+        uint32_t value;
+        // Read from SSI data register 0
+        if(!target_read_memory_32(RP_SSI_DR0, &value)) break;
+        if(rx_data) {
+            *rx_data = value;
+        }
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+// Prepare SPI flash operation
+static bool rp2040_spi_setup_txrx(uint16_t command, uint32_t address, size_t data_size) {
+    bool success = false;
+
+    do {
+        // Number of data frames = data_size
+        if(!target_write_memory_32(RP_SSI_CTRL1, data_size)) break;
+        // Select flash chip
+        if(!rp2040_spi_chip_select(RP_GPIO_QSPI_CS_DRIVE_LOW)) break;
+        // Transmit command
+        const uint8_t opcode = command & SPI_FLASH_OPCODE_MASK;
+        if(!rp2040_spi_txrx(opcode, NULL)) break;
+
+        // Transmit 24-bit address for commands that require it
+        if((command & SPI_FLASH_OPCODE_MODE_MASK) == SPI_FLASH_OPCODE_3B_ADDR) {
+            if(!rp2040_spi_txrx((address >> 16U) & 0xFFUL, NULL)) break;
+            if(!rp2040_spi_txrx((address >> 8U) & 0xFFUL, NULL)) break;
+            if(!rp2040_spi_txrx(address & 0xFFUL, NULL)) break;
+        }
+
+        const size_t inter_length = (command & SPI_FLASH_DUMMY_MASK) >> SPI_FLASH_DUMMY_SHIFT;
+
+        size_t i;
+        for(i = 0; i < inter_length; ++i) {
+            if(!rp2040_spi_txrx(0, NULL)) break;
+        }
+        if(i < inter_length) break;
+
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool rp2040_spi_read(uint16_t command, uint32_t address, void* data, size_t data_size) {
+    bool success = false;
+
+    do {
+        if(!rp2040_spi_setup_txrx(command, address, data_size)) break;
+        uint8_t* rx_data = data;
+        size_t rx_data_size;
+        for(rx_data_size = 0; rx_data_size < data_size; ++rx_data_size) {
+            if(!rp2040_spi_txrx(0, &rx_data[rx_data_size])) break;
+        }
+        if(rx_data_size < data_size) break;
+        rp2040_spi_chip_select(RP_GPIO_QSPI_CS_DRIVE_HIGH);
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool
+    rp2040_spi_write(uint16_t command, uint32_t address, const void* data, const size_t data_size) {
+    bool success = false;
+
+    do {
+        if(!rp2040_spi_setup_txrx(command, address, data_size)) break;
+        const uint8_t* tx_data = data;
+        size_t tx_data_size;
+        for(tx_data_size = 0; tx_data_size < data_size; ++tx_data_size) {
+            if(!rp2040_spi_txrx(tx_data[tx_data_size], NULL)) break;
+        }
+        if(tx_data_size < data_size) break;
+        if(!rp2040_spi_chip_select(RP_GPIO_QSPI_CS_DRIVE_HIGH)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool rp2040_spi_run_command(uint16_t command, uint32_t address) {
+    return rp2040_spi_write(command, address, NULL, 0);
+}
+
+// Custom procedure to reset the W25X SPI flash
+static bool rp2040_w25xx_flash_reset(void) {
+    bool success = false;
+    do {
+        if(!rp2040_spi_txrx(W25X_CMD_RESET_ENABLE, NULL)) break;
+        if(!rp2040_spi_txrx(W25X_CMD_RESET, NULL)) break;
+        furi_delay_us(50);
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool rp2040_init(void) {
+    bool success = false;
+
+    do {
+        if(!rp2040_spi_gpio_init()) {
+            FURI_LOG_E(TAG, "Failed to initialize SPI pins");
+            break;
+        }
+        if(!rp2040_spi_init()) {
+            FURI_LOG_E(TAG, "Failed to configure SPI hardware");
+            break;
+        }
+        if(!rp2040_w25xx_flash_reset()) {
+            FURI_LOG_E(TAG, "Failed to reset SPI flash");
+            break;
+        }
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool rp2040_flash_read_data(uint32_t address, void* data, size_t data_size) {
+    bool success = false;
+
+    do {
+        if(!rp2040_spi_read(SPI_FLASH_CMD_READ_DATA, address, data, data_size)) {
+            FURI_LOG_E(TAG, "Failed to read data");
+            break;
+        }
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool rp2040_flash_erase_sector(uint32_t address) {
+    bool success = false;
+
+    do {
+        if(!rp2040_spi_run_command(SPI_FLASH_CMD_WRITE_ENABLE, 0)) {
+            FURI_LOG_E(TAG, "Failed to issue WRITE_ENABLE command");
+            break;
+        }
+        uint8_t status;
+        if(!rp2040_spi_read(SPI_FLASH_CMD_READ_STATUS, 0U, &status, sizeof(status))) {
+            FURI_LOG_E(TAG, "Failed to issue READ_STATUS command");
+            break;
+        }
+        if((status & SPI_FLASH_STATUS_WRITE_ENABLED) == 0) {
+            FURI_LOG_E(TAG, "Failed to enable write mode, status byte: 0x%02X", status);
+            break;
+        }
+        if(!rp2040_spi_run_command(SPI_FLASH_CMD_SECTOR_ERASE, address)) {
+            FURI_LOG_E(TAG, "Failed to issue SECTOR_ERASE command");
+            break;
+        }
+        do {
+            if(!rp2040_spi_read(SPI_FLASH_CMD_READ_STATUS, 0U, &status, sizeof(status))) {
+                FURI_LOG_E(TAG, "Failed to issue READ_STATUS command");
+                break;
+            }
+        } while(status & SPI_FLASH_STATUS_BUSY);
+
+        if(status & SPI_FLASH_STATUS_BUSY) break;
+
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool rp2040_flash_program_page(uint32_t address, const void* data, size_t data_size) {
+    bool success = false;
+
+    do {
+        if(!rp2040_spi_run_command(SPI_FLASH_CMD_WRITE_ENABLE, 0)) {
+            FURI_LOG_E(TAG, "Failed to issue WRITE_ENABLE command");
+            break;
+        }
+        uint8_t status;
+        if(!rp2040_spi_read(SPI_FLASH_CMD_READ_STATUS, 0U, &status, sizeof(status))) {
+            FURI_LOG_E(TAG, "Failed to issue READ_STATUS command");
+            break;
+        }
+        if((status & SPI_FLASH_STATUS_WRITE_ENABLED) == 0) {
+            FURI_LOG_E(TAG, "Failed to enable write mode, status byte: 0x%02X", status);
+            break;
+        }
+        if(!rp2040_spi_write(SPI_FLASH_CMD_PAGE_PROGRAM, address, data, data_size)) {
+            FURI_LOG_E(TAG, "Failed to issue PAGE_PROGRAM command");
+            break;
+        }
+        do {
+            if(!rp2040_spi_read(SPI_FLASH_CMD_READ_STATUS, 0U, &status, sizeof(status))) {
+                FURI_LOG_E(TAG, "Failed to issue READ_STATUS command");
+                break;
+            }
+        } while(status & SPI_FLASH_STATUS_BUSY);
+
+        if(status & SPI_FLASH_STATUS_BUSY) break;
+
+        success = true;
+    } while(false);
+
+    return success;
+}

+ 53 - 0
non_catalog_apps/video_game_module_tool/flasher/rp2040.h

@@ -0,0 +1,53 @@
+/**
+ * @file rp2040.h
+ * @brief RP2040-specific functions.
+ *
+ * This file is responsible for initialising and accessing
+ * the SPI flash chip via RP2040 hardware.
+ */
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#define RP2040_CORE0_ADDR (0x01002927UL)
+#define RP2040_CORE1_ADDR (0x11002927UL)
+#define RP2040_RESCUE_ADDR (0xF1002927UL)
+
+#define RP2040_FAMILY_ID (0xE48BFF56UL)
+
+/**
+ * @brief Initialise RP2040-specific hardware.
+ *
+ * @returns true on success, false otherwise.
+ */
+bool rp2040_init(void);
+
+/**
+ * @brief Read data from the SPI flash chip.
+ *
+ * @param[in] address target address within the flash address space.
+ * @param[out] data pointer to the buffer to contain the data to be read.
+ * @param[in] data_size size of the data to be read.
+ * @returns true on success, false otherwise.
+ */
+bool rp2040_flash_read_data(uint32_t address, void* data, size_t data_size);
+
+/**
+ * @brief Erase one sector (4K) of the SPI flash chip.
+ *
+ * @param[in] address target address within the flash address space (must be sector-aligned).
+ * @returns true on success, false otherwise.
+ */
+bool rp2040_flash_erase_sector(uint32_t address);
+
+/**
+ * @brief Program one page (256B) of the SPI flash chip.
+ *
+ * @param[in] address target address within the flash address space.
+ * @param[in] data pointer to the buffer containing the data to be written.
+ * @param[in] data_size size of the data to be written.
+ * @returns true on success, false otherwise.
+ */
+bool rp2040_flash_program_page(uint32_t address, const void* data, size_t data_size);

+ 281 - 0
non_catalog_apps/video_game_module_tool/flasher/swd.c

@@ -0,0 +1,281 @@
+#include "swd.h"
+
+#include <furi.h>
+#include <furi_hal_resources.h>
+
+#define TAG "VgmSwd"
+
+#define SWD_REQUEST_LEN (8U)
+#define SWD_RESPONSE_LEN (3U)
+#define SWD_DATA_LEN (32U)
+
+#define SWD_ALERT_SEQUENCE_0 (0x6209F392UL)
+#define SWD_ALERT_SEQUENCE_1 (0x86852D95UL)
+#define SWD_ALERT_SEQUENCE_2 (0xE3DDAFE9UL)
+#define SWD_ALERT_SEQUENCE_3 (0x19BC0EA2UL)
+
+#define SWD_ACTIVATION_CODE (0x1AU)
+
+#define SWD_SLEEP_SEQUENCE (0xE3BCU)
+
+#define SWD_READ_REQUEST_INIT (0x85U)
+#define SWD_WRITE_REQUEST_INIT (0x81U)
+#define SWD_REQUEST_INIT (0x81U)
+
+typedef enum {
+    SwdioDirectionIn,
+    SwdioDirectionOut,
+} SwdioDirection;
+
+typedef enum {
+    SwdResponseOk = 1U,
+    SwdResponseWait = 2U,
+    SwdResponseFault = 4U,
+    SwdResponseNone = 7U,
+} SwdResponse;
+
+typedef enum {
+    SwdAccessTypeDp = 0U << 1,
+    SwdAccessTypeAp = 1U << 1,
+} SwdAccessType;
+
+typedef enum {
+    SwdAccessDirectionWrite = 0U << 2,
+    SwdAccessDirectionRead = 1U << 2,
+} SwdAccessDirection;
+
+#ifdef SWD_ENABLE_CYCLE_DELAY
+// Slows SWCLK down, useful for debugging via logic analyzer
+__attribute__((always_inline)) static inline void swd_delay_half_cycle(void) {
+    asm volatile("nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n"
+                 "nop \n");
+}
+#else
+#define swd_delay_half_cycle()
+#endif
+
+static void __attribute__((optimize("-O3"))) swd_turnaround(SwdioDirection mode) {
+    static SwdioDirection prev_dir = SwdioDirectionIn;
+
+    if(prev_dir == mode) {
+        return;
+    } else {
+        prev_dir = mode;
+    }
+
+    if(mode == SwdioDirectionIn) {
+        // Using LL functions for performance reasons
+        LL_GPIO_SetPinMode(gpio_swdio.port, gpio_swdio.pin, LL_GPIO_MODE_INPUT);
+    } else {
+        furi_hal_gpio_write(&gpio_swclk, false);
+    }
+    swd_delay_half_cycle();
+
+    furi_hal_gpio_write(&gpio_swclk, true);
+    swd_delay_half_cycle();
+
+    if(mode == SwdioDirectionOut) {
+        furi_hal_gpio_write(&gpio_swclk, false);
+        // Using LL functions for performance reasons
+        LL_GPIO_SetPinMode(gpio_swdio.port, gpio_swdio.pin, LL_GPIO_MODE_OUTPUT);
+    }
+}
+
+static void __attribute__((optimize("-O3"))) swd_tx(uint32_t data, uint32_t n_cycles) {
+    swd_turnaround(SwdioDirectionOut);
+
+    for(uint32_t i = 0; i < n_cycles; ++i) {
+        furi_hal_gpio_write(&gpio_swclk, false);
+        furi_hal_gpio_write(&gpio_swdio, data & (1UL << i));
+        swd_delay_half_cycle();
+
+        furi_hal_gpio_write(&gpio_swclk, true);
+        swd_delay_half_cycle();
+    }
+
+    furi_hal_gpio_write(&gpio_swclk, false);
+}
+
+static void __attribute__((optimize("-O3"))) swd_tx_parity(uint32_t data, uint32_t n_cycles) {
+    const int parity = __builtin_parity(data);
+    swd_tx(data, n_cycles);
+    furi_hal_gpio_write(&gpio_swdio, parity);
+    swd_delay_half_cycle();
+    furi_hal_gpio_write(&gpio_swclk, true);
+    swd_delay_half_cycle();
+    furi_hal_gpio_write(&gpio_swclk, false);
+}
+
+static uint32_t __attribute__((optimize("-O3"))) swd_rx(uint32_t n_cycles) {
+    uint32_t ret = 0;
+    swd_turnaround(SwdioDirectionIn);
+
+    for(uint32_t i = 0; i < n_cycles; ++i) {
+        furi_hal_gpio_write(&gpio_swclk, false);
+        ret |= furi_hal_gpio_read(&gpio_swdio) ? (1UL << i) : 0;
+        swd_delay_half_cycle();
+
+        furi_hal_gpio_write(&gpio_swclk, true);
+        swd_delay_half_cycle();
+    }
+
+    furi_hal_gpio_write(&gpio_swclk, false);
+    return ret;
+}
+
+static bool __attribute__((optimize("-O3"))) swd_rx_parity(uint32_t* data, uint32_t n_cycles) {
+    furi_assert(data);
+
+    const uint32_t rx_value = swd_rx(n_cycles);
+    swd_delay_half_cycle();
+
+    const bool parity_calc = __builtin_parity(rx_value);
+    const bool parity_rx = furi_hal_gpio_read(&gpio_swdio);
+
+    furi_hal_gpio_write(&gpio_swclk, true);
+    swd_delay_half_cycle();
+    furi_hal_gpio_write(&gpio_swclk, false);
+
+    if(data) {
+        *data = rx_value;
+    }
+
+    return parity_calc == parity_rx;
+}
+
+static void swd_line_reset(bool idle_cycles) {
+    swd_tx(0xFFFFFFFFUL, 32U);
+    swd_tx(0x0FFFFFFFUL, idle_cycles ? 32U : 24U);
+}
+
+static void swd_leave_dormant_state(void) {
+    swd_line_reset(false);
+    swd_tx(SWD_ALERT_SEQUENCE_0, 32U);
+    swd_tx(SWD_ALERT_SEQUENCE_1, 32U);
+    swd_tx(SWD_ALERT_SEQUENCE_2, 32U);
+    swd_tx(SWD_ALERT_SEQUENCE_3, 32U);
+    swd_tx(SWD_ACTIVATION_CODE << 4U, 12U);
+}
+
+static void swd_enter_dormant_state(void) {
+    swd_line_reset(false);
+    swd_tx(SWD_SLEEP_SEQUENCE, 16U);
+}
+
+void swd_init(void) {
+    furi_hal_gpio_init_ex(
+        &gpio_swclk, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh, GpioAltFnUnused);
+    furi_hal_gpio_init_ex(
+        &gpio_swdio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh, GpioAltFnUnused);
+
+    swd_leave_dormant_state();
+    swd_line_reset(true);
+}
+
+void swd_deinit(void) {
+    swd_enter_dormant_state();
+
+    furi_hal_gpio_init_simple(&gpio_swclk, GpioModeAnalog);
+    furi_hal_gpio_init_simple(&gpio_swdio, GpioModeAnalog);
+}
+
+static inline uint8_t swd_prepare_request(
+    SwdAccessDirection access_direction,
+    SwdAccessType access_type,
+    uint8_t address) {
+    uint8_t ret = SWD_REQUEST_INIT | access_type | access_direction | (address << 3);
+    ret |= __builtin_parity(ret) << 5;
+    return ret;
+}
+
+static bool swd_read_request(SwdAccessType access_type, uint8_t address, uint32_t* data) {
+    const uint8_t request = swd_prepare_request(SwdAccessDirectionRead, access_type, address);
+    swd_tx(request, SWD_REQUEST_LEN);
+
+    const uint32_t response = swd_rx(SWD_RESPONSE_LEN);
+    if(response == SwdResponseOk) {
+        return swd_rx_parity(data, SWD_DATA_LEN);
+    } else {
+        return false;
+    }
+}
+
+static bool swd_write_request(SwdAccessType access_type, uint8_t address, uint32_t data) {
+    const uint8_t request = swd_prepare_request(SwdAccessDirectionWrite, access_type, address);
+    swd_tx(request, SWD_REQUEST_LEN);
+
+    const uint32_t response = swd_rx(SWD_RESPONSE_LEN);
+    if(response == SwdResponseOk) {
+        swd_tx_parity(data, SWD_DATA_LEN);
+        swd_tx(0UL, 8);
+        return true;
+    } else {
+        return false;
+    }
+}
+
+void swd_select_target(uint32_t target_id) {
+    swd_tx(SWD_WRITE_REQUEST_INIT | (SWD_DP_REG_WO_TASRGETSEL << 3), SWD_REQUEST_LEN);
+    swd_rx(SWD_RESPONSE_LEN);
+    swd_tx_parity(target_id, SWD_DATA_LEN);
+    swd_tx(0UL, 8);
+}
+
+bool swd_dp_read(uint8_t address, uint32_t* data) {
+    return swd_read_request(SwdAccessTypeDp, address, data);
+}
+
+bool swd_dp_write(uint8_t address, uint32_t data) {
+    return swd_write_request(SwdAccessTypeDp, address, data);
+}
+
+bool swd_ap_read(uint8_t address, uint32_t* data) {
+    bool success = false;
+
+    do {
+        // Using hardcoded AP 0
+        const uint32_t select_val = address & 0xF0U;
+        if(!swd_write_request(SwdAccessTypeDp, SWD_DP_REG_WO_SELECT, select_val)) break;
+        if(!swd_read_request(SwdAccessTypeAp, (address & 0x0FU) >> 2, NULL)) break;
+        if(!swd_read_request(SwdAccessTypeDp, SWD_DP_REG_RO_RDBUFF, data)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool swd_ap_write(uint8_t address, uint32_t data) {
+    bool success = false;
+
+    do {
+        // Using hardcoded AP 0
+        const uint32_t select_val = address & 0xF0U;
+        if(!swd_write_request(SwdAccessTypeDp, SWD_DP_REG_WO_SELECT, select_val)) break;
+        if(!swd_write_request(SwdAccessTypeAp, (address & 0x0FU) >> 2, data)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}

+ 122 - 0
non_catalog_apps/video_game_module_tool/flasher/swd.h

@@ -0,0 +1,122 @@
+/**
+ * @file swd.h
+ * @brief Serial Wire Debug (SWD) bus functions.
+ *
+ * This file is responsible for:
+ *
+ * - Debug hardware initialisation
+ * - Target selection in a multidrop bus
+ * - Debug and Access port access
+ *
+ * For more information, see ARM IHI0031G
+ * https://documentation-service.arm.com/static/622222b2e6f58973271ebc21
+ */
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+// Only bits [3:2] are used to access DP registers
+#define SWD_DP_REG_ADDR_SHIFT (2U)
+
+// Debug port registers - write
+#define SWD_DP_REG_WO_ABORT (0x0U >> SWD_DP_REG_ADDR_SHIFT)
+#define SWD_DP_REG_WO_SELECT (0x8U >> SWD_DP_REG_ADDR_SHIFT)
+#define SWD_DP_REG_WO_TASRGETSEL (0xCU >> SWD_DP_REG_ADDR_SHIFT)
+
+// Debug port registers - read
+#define SWD_DP_REG_RO_DPIDR (0x0U >> SWD_DP_REG_ADDR_SHIFT)
+#define SWD_DP_REG_RO_RESEND (0x8U >> SWD_DP_REG_ADDR_SHIFT)
+#define SWD_DP_REG_RO_RDBUFF (0xCU >> SWD_DP_REG_ADDR_SHIFT)
+
+// Debug port registers - read/write
+#define SWD_DP_REG_RW_BANK (0x4U >> SWD_DP_REG_ADDR_SHIFT)
+#define SWD_DP_REG_RW_CTRL_STAT (SWD_DP_REG_RW_BANK)
+
+// Access port registers
+#define SWD_AP_REG_RW_CSW (0x00U)
+#define SWD_AP_REG_RW_TAR (0x04U)
+#define SWD_AP_REG_RW_DRW (0x0CU)
+#define SWD_AP_REG_RO_IDR (0xFCU)
+
+// CTRL/STAT bits
+#define SWD_DP_REG_CTRL_STAT_CDBGPWRUPREQ (1UL << 28U)
+#define SWD_DP_REG_CTRL_STAT_CDBGPWRUPACK (1UL << 29U)
+#define SWD_DP_REG_CTRL_STAT_CSYSPWRUPREQ (1UL << 30U)
+#define SWD_DP_REG_CTRL_STAT_CSYSPWRUPACK (1UL << 31U)
+
+// CSW bits (PROT bits are for AHB3)
+#define SWD_AP_REG_CSW_SIZE_WORD (2UL << 0U)
+#define SWD_AP_REG_CSW_HPROT_DATA (1UL << 24U)
+#define SWD_AP_REG_CSW_HPROT_PRIVILIGED (1UL << 25U)
+#define SWD_AP_REG_CSW_HPROT_BUFFERABLE (1UL << 26U)
+#define SWD_AP_REG_CSW_HPROT_CACHEABLE (1UL << 27U)
+#define SWD_AP_REG_CSW_HNONSEC (1UL << 30U)
+
+/**
+ * @brief Initialise SWD bus.
+ *
+ * Configures SWCLK and SWDIO pins, wakes up the target from
+ * dormant state and resets the SWD bus.
+ */
+void swd_init(void);
+
+/**
+ * @brief Disable SWD bus.
+ *
+ * Sets the target to dormant state and returns
+ * SWCLK and SWDIO pins to analog mode.
+ */
+void swd_deinit(void);
+
+/**
+ * @brief Select one target on a multidrop (SWD v2) bus.
+ *
+ * @param[in] target_id target address or id (specified in device datasheet)
+ */
+void swd_select_target(uint32_t target_id);
+
+/**
+ * @brief Perform a Debug Port (DP) read.
+ *
+ * Reads a 32-bit word from the designated DP register.
+ *
+ * @param[in] address DP register address.
+ * @param[out] data pointer to the value to contain the read data.
+ * @returns true on success, false otherwise.
+ */
+bool swd_dp_read(uint8_t address, uint32_t* data);
+
+/**
+ * @brief Perform a Debug Port (DP) write.
+ *
+ * Writes a 32-bit word to the designated DP register.
+ *
+ * @param[in] address DP register address.
+ * @param[in] data value to be written as data.
+ * @returns true on success, false otherwise.
+ */
+bool swd_dp_write(uint8_t address, uint32_t data);
+
+/**
+ * @brief Perform an Access Port (AP) read.
+ *
+ * Reads a 32-bit word from the designated AP register.
+ *
+ * @param[in] address AP register address.
+ * @param[out] data pointer to the value to contain the read data.
+ * @returns true on success, false otherwise.
+ */
+bool swd_ap_read(uint8_t address, uint32_t* data);
+
+/**
+ * @brief Perform an Access Port (AP) write.
+ *
+ * Writes a 32-bit word to the designated AP register.
+ *
+ * @param[in] address AP register address.
+ * @param[in] data value to be written as data.
+ * @returns true on success, false otherwise.
+ */
+bool swd_ap_write(uint8_t address, uint32_t data);

+ 231 - 0
non_catalog_apps/video_game_module_tool/flasher/target.c

@@ -0,0 +1,231 @@
+#include "target.h"
+
+#include <furi.h>
+
+#include "swd.h"
+
+/* Cortex-M registers (taken from Blackmagic) */
+#define CORTEXM_PPB_BASE 0xe0000000U
+
+#define CORTEXM_SCS_BASE (CORTEXM_PPB_BASE + 0xe000U)
+
+#define CORTEXM_CPUID (CORTEXM_SCS_BASE + 0xd00U)
+#define CORTEXM_AIRCR (CORTEXM_SCS_BASE + 0xd0cU)
+#define CORTEXM_CFSR (CORTEXM_SCS_BASE + 0xd28U)
+#define CORTEXM_HFSR (CORTEXM_SCS_BASE + 0xd2cU)
+#define CORTEXM_DFSR (CORTEXM_SCS_BASE + 0xd30U)
+#define CORTEXM_CPACR (CORTEXM_SCS_BASE + 0xd88U)
+#define CORTEXM_DHCSR (CORTEXM_SCS_BASE + 0xdf0U)
+#define CORTEXM_DCRSR (CORTEXM_SCS_BASE + 0xdf4U)
+#define CORTEXM_DCRDR (CORTEXM_SCS_BASE + 0xdf8U)
+#define CORTEXM_DEMCR (CORTEXM_SCS_BASE + 0xdfcU)
+
+/* Debug Halting Control and Status Register (DHCSR) */
+/* This key must be written to bits 31:16 for write to take effect */
+#define CORTEXM_DHCSR_DBGKEY 0xa05f0000U
+/* Bits 31:26 - Reserved */
+#define CORTEXM_DHCSR_S_RESET_ST (1U << 25U)
+#define CORTEXM_DHCSR_S_RETIRE_ST (1U << 24U)
+/* Bits 23:20 - Reserved */
+#define CORTEXM_DHCSR_S_LOCKUP (1U << 19U)
+#define CORTEXM_DHCSR_S_SLEEP (1U << 18U)
+#define CORTEXM_DHCSR_S_HALT (1U << 17U)
+#define CORTEXM_DHCSR_S_REGRDY (1U << 16U)
+/* Bits 15:6 - Reserved */
+#define CORTEXM_DHCSR_C_SNAPSTALL (1U << 5U) /* v7m only */
+/* Bit 4 - Reserved */
+#define CORTEXM_DHCSR_C_MASKINTS (1U << 3U)
+#define CORTEXM_DHCSR_C_STEP (1U << 2U)
+#define CORTEXM_DHCSR_C_HALT (1U << 1U)
+#define CORTEXM_DHCSR_C_DEBUGEN (1U << 0U)
+
+/* Debug Exception and Monitor Control Register (DEMCR) */
+/* Bits 31:25 - Reserved */
+#define CORTEXM_DEMCR_TRCENA (1U << 24U)
+/* Bits 23:20 - Reserved */
+#define CORTEXM_DEMCR_MON_REQ (1U << 19U) /* v7m only */
+#define CORTEXM_DEMCR_MON_STEP (1U << 18U) /* v7m only */
+#define CORTEXM_DEMCR_VC_MON_PEND (1U << 17U) /* v7m only */
+#define CORTEXM_DEMCR_VC_MON_EN (1U << 16U) /* v7m only */
+/* Bits 15:11 - Reserved */
+#define CORTEXM_DEMCR_VC_HARDERR (1U << 10U)
+#define CORTEXM_DEMCR_VC_INTERR (1U << 9U) /* v7m only */
+#define CORTEXM_DEMCR_VC_BUSERR (1U << 8U) /* v7m only */
+#define CORTEXM_DEMCR_VC_STATERR (1U << 7U) /* v7m only */
+#define CORTEXM_DEMCR_VC_CHKERR (1U << 6U) /* v7m only */
+#define CORTEXM_DEMCR_VC_NOCPERR (1U << 5U) /* v7m only */
+#define CORTEXM_DEMCR_VC_MMERR (1U << 4U) /* v7m only */
+/* Bits 3:1 - Reserved */
+#define CORTEXM_DEMCR_VC_CORERESET (1U << 0U)
+
+#define CORTEXM_DHCSR_DEBUG_HALT (CORTEXM_DHCSR_C_DEBUGEN | CORTEXM_DHCSR_C_HALT)
+
+#define TAG "VgmTarget"
+
+static uint32_t prev_address;
+
+static bool target_memory_access_setup(uint32_t address) {
+    bool success = false;
+    do {
+        // If the address was previously set up, do not waste time on it
+        if(address != prev_address) {
+            // Word access, no auto increment
+            if(!swd_ap_write(
+                   SWD_AP_REG_RW_CSW,
+                   SWD_AP_REG_CSW_HPROT_DATA | SWD_AP_REG_CSW_HPROT_PRIVILIGED |
+                       SWD_AP_REG_CSW_HNONSEC | SWD_AP_REG_CSW_SIZE_WORD))
+                break;
+            if(!swd_ap_write(SWD_AP_REG_RW_TAR, address)) break;
+            prev_address = address;
+        }
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool target_dbg_power_up(void) {
+    if(!swd_dp_write(SWD_DP_REG_RW_CTRL_STAT, 0)) return false;
+
+    uint32_t status;
+
+    do {
+        if(!swd_dp_read(SWD_DP_REG_RW_CTRL_STAT, &status)) return false;
+    } while(status & (SWD_DP_REG_CTRL_STAT_CDBGPWRUPACK | SWD_DP_REG_CTRL_STAT_CSYSPWRUPACK));
+
+    if(!swd_dp_write(
+           SWD_DP_REG_RW_CTRL_STAT,
+           (SWD_DP_REG_CTRL_STAT_CDBGPWRUPREQ | SWD_DP_REG_CTRL_STAT_CSYSPWRUPREQ)))
+        return false;
+
+    do {
+        furi_delay_us(10000);
+        if(!swd_dp_read(SWD_DP_REG_RW_CTRL_STAT, &status)) return false;
+    } while((status & (SWD_DP_REG_CTRL_STAT_CDBGPWRUPACK | SWD_DP_REG_CTRL_STAT_CSYSPWRUPACK)) !=
+            (SWD_DP_REG_CTRL_STAT_CDBGPWRUPACK | SWD_DP_REG_CTRL_STAT_CSYSPWRUPACK));
+
+    return true;
+}
+
+static bool target_halt(void) {
+    bool success = false;
+
+    do {
+        if(!target_write_memory_32(CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_DEBUG_HALT))
+            break;
+
+        bool target_halted = false;
+        for(bool target_reset = false; !target_halted;) {
+            uint32_t dhcsr;
+            if(!target_read_memory_32(CORTEXM_DHCSR, &dhcsr)) break;
+            if((dhcsr & CORTEXM_DHCSR_S_RESET_ST) && !target_reset) {
+                target_reset = true;
+                continue;
+            }
+            if((dhcsr & CORTEXM_DHCSR_DEBUG_HALT) == CORTEXM_DHCSR_DEBUG_HALT) {
+                target_halted = true;
+            }
+        }
+
+        if(!target_halted) break;
+
+        if(!target_write_memory_32(
+               CORTEXM_DEMCR,
+               CORTEXM_DEMCR_TRCENA | CORTEXM_DEMCR_VC_HARDERR | CORTEXM_DEMCR_VC_CORERESET))
+            break;
+
+        bool target_local_reset = false;
+        for(; !target_local_reset;) {
+            uint32_t dhcsr;
+            if(!target_read_memory_32(CORTEXM_DHCSR, &dhcsr)) break;
+            if((dhcsr & CORTEXM_DHCSR_S_RESET_ST) == 0) {
+                target_local_reset = true;
+            }
+        }
+
+        if(!target_local_reset) break;
+
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool target_attach(uint32_t id) {
+    bool success = false;
+
+    do {
+        // Reset previous memory address
+        prev_address = UINT32_MAX;
+
+        swd_select_target(id);
+
+        uint32_t dpidr;
+        if(!swd_dp_read(SWD_DP_REG_RO_DPIDR, &dpidr)) {
+            FURI_LOG_E(TAG, "Failed to read DPIDR");
+            break;
+        }
+
+        if(dpidr == 0) {
+            FURI_LOG_E(TAG, "Zero DPIDR value");
+            break;
+        }
+
+        if(!target_dbg_power_up()) {
+            FURI_LOG_E(TAG, "Failed to enable debug power");
+            break;
+        }
+
+        if(!target_halt()) {
+            FURI_LOG_E(TAG, "Failed to halt target");
+            break;
+        }
+
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool target_detach(void) {
+    bool success = false;
+
+    do {
+        if(!target_write_memory_32(CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_DEBUG_HALT))
+            break;
+        if(!target_write_memory_32(CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_C_DEBUGEN))
+            break;
+        if(!target_write_memory_32(CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool target_read_memory_32(uint32_t address, uint32_t* data) {
+    furi_assert((address & 3U) == 0);
+
+    bool success = false;
+
+    do {
+        if(!target_memory_access_setup(address)) break;
+        if(!swd_ap_read(SWD_AP_REG_RW_DRW, data)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+bool target_write_memory_32(uint32_t address, uint32_t data) {
+    furi_assert((address & 3U) == 0);
+
+    bool success = false;
+
+    do {
+        if(!target_memory_access_setup(address)) break;
+        if(!swd_ap_write(SWD_AP_REG_RW_DRW, data)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}

+ 45 - 0
non_catalog_apps/video_game_module_tool/flasher/target.h

@@ -0,0 +1,45 @@
+/**
+ * @file target.h
+ * @brief Debug target functions.
+ *
+ * This file is responsible for configuring the debug target
+ * and accessing its memory-mapped devices.
+ */
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+/**
+ * @brief Attach and halt the debug target.
+ *
+ * @param[in] target_id target address or id (specified in device datasheet)
+ * @returns true on success, false otherwise.
+ */
+bool target_attach(uint32_t id);
+
+/**
+ * @brief Detach and resume the debug target.
+ *
+ * @returns true on success, false otherwise.
+ */
+bool target_detach(void);
+
+/**
+ * @brief Read a 32-bit word within target address space.
+ *
+ * @param[in] address target memory address.
+ * @param[out] data pointer to the value to hold the read data.
+ * @returns true on success, false otherwise.
+ */
+bool target_read_memory_32(uint32_t address, uint32_t* data);
+
+/**
+ * @brief Write a 32-bit word within target address space.
+ *
+ * @param[in] address target memory address.
+ * @param[in] data value to be written as data.
+ * @returns true on success, false otherwise.
+ */
+bool target_write_memory_32(uint32_t address, uint32_t data);

+ 167 - 0
non_catalog_apps/video_game_module_tool/flasher/uf2.c

@@ -0,0 +1,167 @@
+#include "uf2.h"
+
+#include <furi.h>
+
+#define UF2_BLOCK_SIZE (512UL)
+#define UF2_DATA_SIZE (476UL)
+#define UF2_CHECKSUM_SIZE (16UL)
+
+#define UF2_MAGIC_START_0 (0x0A324655UL)
+#define UF2_MAGIC_START_1 (0x9E5D5157UL)
+#define UF2_MAGIC_END (0x0AB16F30UL)
+
+#define TAG "VgmUf2"
+
+typedef enum {
+    Uf2FlagNotMainFlash = 1UL << 0,
+    Uf2FlagFileContainer = 1UL << 12,
+    Uf2FlagFamilyIdPresent = 1UL << 13,
+    Uf2FlagChecksumPresent = 1UL << 14,
+    Uf2FlagExtensionPresent = 1UL << 15,
+} Uf2Flag;
+
+typedef struct {
+    uint32_t magic_start[2];
+    uint32_t flags;
+    uint32_t target_addr;
+    uint32_t payload_size;
+    uint32_t block_no;
+    uint32_t num_blocks;
+    union {
+        uint32_t file_size;
+        uint32_t family_id;
+    };
+} Uf2BlockHeader;
+
+typedef union {
+    uint8_t payload[UF2_DATA_SIZE];
+    struct {
+        uint8_t reserved[UF2_DATA_SIZE - 24];
+        uint32_t start_addr;
+        uint32_t region_len;
+        uint8_t checksum[UF2_CHECKSUM_SIZE];
+    };
+} Uf2BlockData;
+
+typedef struct {
+    uint32_t magic_end;
+} Uf2BlockTrailer;
+
+static bool uf2_block_header_read(Uf2BlockHeader* header, File* file) {
+    const size_t size_read = storage_file_read(file, header, sizeof(Uf2BlockHeader));
+    return size_read == sizeof(Uf2BlockHeader);
+}
+
+static bool
+    uf2_block_header_verify(const Uf2BlockHeader* header, uint32_t family_id, size_t payload_size) {
+    bool success = false;
+
+    do {
+        if(header->magic_start[0] != UF2_MAGIC_START_0) break;
+        if(header->magic_start[1] != UF2_MAGIC_START_1) break;
+        if(header->flags & Uf2FlagNotMainFlash) {
+            FURI_LOG_E(TAG, "Non-flash blocks are not supported (block #%lu)", header->block_no);
+            break;
+        }
+        if(header->flags & Uf2FlagFamilyIdPresent) {
+            if(header->family_id != family_id) {
+                FURI_LOG_E(
+                    TAG,
+                    "Family ID expected: %lX, got: %lX (block #%lu)",
+                    family_id,
+                    header->family_id,
+                    header->block_no);
+                break;
+            }
+        }
+        if(header->payload_size != payload_size) {
+            FURI_LOG_E(
+                TAG,
+                "Only %zu-byte block payloads are supported (block #%lu)",
+                payload_size,
+                header->block_no);
+            break;
+        }
+        if(header->target_addr % payload_size != 0) {
+            FURI_LOG_E(
+                TAG,
+                "Only %zu-byte aligned  are allowed (block #%lu)",
+                payload_size,
+                header->block_no);
+            break;
+        }
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool uf2_block_header_skip(File* file) {
+    return storage_file_seek(file, sizeof(Uf2BlockHeader), false);
+}
+
+static bool uf2_block_payload_skip(File* file) {
+    return storage_file_seek(file, sizeof(Uf2BlockData), false);
+}
+
+static bool uf2_block_trailer_skip(File* file) {
+    return storage_file_seek(file, sizeof(Uf2BlockTrailer), false);
+}
+
+static bool uf2_block_payload_read(File* file, void* payload_data, size_t payload_size) {
+    bool success = false;
+
+    do {
+        const size_t size_read = storage_file_read(file, payload_data, payload_size);
+        if(size_read != payload_size) break;
+        if(!storage_file_seek(file, UF2_DATA_SIZE - payload_size, false)) break;
+        success = true;
+    } while(false);
+
+    return success;
+}
+
+static bool uf2_block_trailer_read(Uf2BlockTrailer* trailer, File* file) {
+    const size_t size_read = storage_file_read(file, trailer, sizeof(Uf2BlockTrailer));
+    return size_read == sizeof(Uf2BlockTrailer);
+}
+
+static bool uf2_block_trailer_verify(const Uf2BlockTrailer* trailer) {
+    return trailer->magic_end == UF2_MAGIC_END;
+}
+
+bool uf2_get_block_count(File* file, uint32_t* block_count) {
+    const size_t file_size = storage_file_size(file);
+
+    if(file_size == 0) {
+        FURI_LOG_E(TAG, "File size is zero");
+        return false;
+    } else if(file_size % UF2_BLOCK_SIZE != 0) {
+        FURI_LOG_E(TAG, "File size is not a multiple of %lu bytes", UF2_BLOCK_SIZE);
+        return false;
+    }
+
+    *block_count = file_size / UF2_BLOCK_SIZE;
+    return true;
+}
+
+bool uf2_verify_block(File* file, uint32_t family_id, size_t payload_size) {
+    Uf2BlockHeader header;
+    Uf2BlockTrailer trailer;
+
+    if(!uf2_block_header_read(&header, file)) return false;
+    if(!uf2_block_header_verify(&header, family_id, payload_size)) return false;
+    if(!uf2_block_payload_skip(file)) return false;
+    if(!uf2_block_trailer_read(&trailer, file)) return false;
+    if(!uf2_block_trailer_verify(&trailer)) return false;
+
+    return true;
+}
+
+bool uf2_read_block(File* file, void* payload_data, size_t payload_size) {
+    if(!uf2_block_header_skip(file)) return false;
+    if(!uf2_block_payload_read(file, payload_data, payload_size)) return false;
+    if(!uf2_block_trailer_skip(file)) return false;
+
+    return true;
+}

+ 60 - 0
non_catalog_apps/video_game_module_tool/flasher/uf2.h

@@ -0,0 +1,60 @@
+/**
+ * @file uf2.h
+ * @brief UF2 file support functions.
+ *
+ * This is a minimal UF2 file implementation.
+ *
+ * UNsupported features:
+ * - Non-flash blocks
+ * - File containers
+ * - Extended tags
+ * - Md5 checksum
+ *
+ * Suported features:
+ * - Family id (respective flag must be set)
+ *
+ * See https://github.com/Microsoft/uf2 for more information.
+ */
+#pragma once
+
+#include <storage/storage.h>
+
+/**
+ * @brief Get the block count in a UF2 file.
+ *
+ * The file MUST be already open.
+ *
+ * Will fail if the file size is not evenly divisible
+ * by 512 bytes (UF2 block size).
+ *
+ * @param[in] file pointer to the storage file instance.
+ * @param[out] block_count pointer to the value to contain the block count.
+ * @returns true on success, false otherwise.
+ */
+bool uf2_get_block_count(File* file, uint32_t* block_count);
+
+/**
+ * @brief Verify a single UF2 block.
+ *
+ * The file MUST be already open.
+ *
+ * Will fail if:
+ * - the family id flag is set, but does not match the provided value,
+ * - payload size does not match the provided value.
+ *
+ * @param[in] file pointer to the storage file instance.
+ * @param[in] family_id family identifier to check against the respective header field.
+ * @param[in] payload_size payload size to check agains the respective header field, in bytes.
+ * @returns true on success, false otherwise.
+ */
+bool uf2_verify_block(File* file, uint32_t family_id, size_t payload_size);
+
+/**
+ * @brief Read the payload from a single UF2 block.
+ *
+ * @param[in] file pointer to the storage file instance.
+ * @param[out] payload pointer to the buffer to contain the payload data.
+ * @param[in] payload_size size of the payload buffer, in bytes.
+ * @returns true on success, false otherwise.
+ */
+bool uf2_read_block(File* file, void* payload, size_t payload_size);

BIN
non_catalog_apps/video_game_module_tool/icons/Checkmark_44x40.png


BIN
non_catalog_apps/video_game_module_tool/icons/Flashing_module_70x30.png


BIN
non_catalog_apps/video_game_module_tool/icons/Module_60x26.png


BIN
non_catalog_apps/video_game_module_tool/icons/Update_module_56x52.png


BIN
non_catalog_apps/video_game_module_tool/icons/WarningDolphinFlip_45x42.png


+ 30 - 0
non_catalog_apps/video_game_module_tool/scenes/scene.c

@@ -0,0 +1,30 @@
+#include "scene.h"
+
+// Generate scene on_enter handlers array
+#define ADD_SCENE(name, id) scene_##name##_on_enter,
+static void (*const on_enter_handlers[])(void*) = {
+#include "scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_event handlers array
+#define ADD_SCENE(name, id) scene_##name##_on_event,
+static bool (*const on_event_handlers[])(void* context, SceneManagerEvent event) = {
+#include "scene_config.h"
+};
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers array
+#define ADD_SCENE(name, id) scene_##name##_on_exit,
+static void (*const on_exit_handlers[])(void* context) = {
+#include "scene_config.h"
+};
+#undef ADD_SCENE
+
+// Initialize scene handlers configuration structure
+const SceneManagerHandlers scene_handlers = {
+    .on_enter_handlers = on_enter_handlers,
+    .on_event_handlers = on_event_handlers,
+    .on_exit_handlers = on_exit_handlers,
+    .scene_num = SceneNum,
+};

+ 28 - 0
non_catalog_apps/video_game_module_tool/scenes/scene.h

@@ -0,0 +1,28 @@
+#pragma once
+
+#include <gui/scene_manager.h>
+
+// Generate scene id and total number
+#define ADD_SCENE(name, id) Scene##id,
+typedef enum {
+#include "scene_config.h"
+    SceneNum,
+} Scene;
+#undef ADD_SCENE
+
+extern const SceneManagerHandlers scene_handlers;
+
+// Generate scene on_enter handlers declaration
+#define ADD_SCENE(name, id) void scene_##name##_on_enter(void*);
+#include "scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_event handlers declaration
+#define ADD_SCENE(name, id) bool scene_##name##_on_event(void* context, SceneManagerEvent event);
+#include "scene_config.h"
+#undef ADD_SCENE
+
+// Generate scene on_exit handlers declaration
+#define ADD_SCENE(name, id) void scene_##name##_on_exit(void* context);
+#include "scene_config.h"
+#undef ADD_SCENE

+ 7 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_config.h

@@ -0,0 +1,7 @@
+ADD_SCENE(probe, Probe)
+ADD_SCENE(start, Start)
+ADD_SCENE(confirm, Confirm)
+ADD_SCENE(install, Install)
+ADD_SCENE(file_select, FileSelect)
+ADD_SCENE(success, Success)
+ADD_SCENE(error, Error)

+ 66 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_confirm.c

@@ -0,0 +1,66 @@
+#include "app_i.h"
+
+#include <furi.h>
+#include <toolbox/path.h>
+
+#include "custom_event.h"
+
+static void
+    scene_confirm_button_callback(GuiButtonType button_type, InputType input_type, void* context) {
+    furi_assert(context);
+    App* app = context;
+
+    if(input_type == InputTypeShort) {
+        if(button_type == GuiButtonTypeLeft) {
+            view_dispatcher_send_custom_event(app->view_dispatcher, CustomEventFileRejected);
+        } else if(button_type == GuiButtonTypeRight) {
+            view_dispatcher_send_custom_event(app->view_dispatcher, CustomEventFileConfirmed);
+        }
+    }
+}
+
+void scene_confirm_on_enter(void* context) {
+    App* app = context;
+
+    FuriString* file_name = furi_string_alloc();
+    path_extract_filename(app->file_path, file_name, false);
+
+    FuriString* label = furi_string_alloc_printf("Install %s?", furi_string_get_cstr(file_name));
+    widget_add_string_element(
+        app->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(label));
+
+    furi_string_free(label);
+    furi_string_free(file_name);
+
+    widget_add_button_element(
+        app->widget, GuiButtonTypeLeft, "Cancel", scene_confirm_button_callback, app);
+    widget_add_button_element(
+        app->widget, GuiButtonTypeRight, "Install", scene_confirm_button_callback, app);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdWidget);
+}
+
+bool scene_confirm_on_event(void* context, SceneManagerEvent event) {
+    App* app = context;
+
+    bool consumed = false;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == CustomEventFileConfirmed) {
+            scene_manager_next_scene(app->scene_manager, SceneInstall);
+        } else if(event.event == CustomEventFileRejected) {
+            furi_string_reset(app->file_path);
+            scene_manager_previous_scene(app->scene_manager);
+        }
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeBack) {
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void scene_confirm_on_exit(void* context) {
+    App* app = context;
+    widget_reset(app->widget);
+}

+ 68 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_error.c

@@ -0,0 +1,68 @@
+#include "app_i.h"
+
+#include <furi.h>
+#include <notification/notification_messages.h>
+
+#include "custom_event.h"
+#include "video_game_module_tool_icons.h"
+
+static void
+    scene_error_button_callback(GuiButtonType button_type, InputType input_type, void* context) {
+    App* app = context;
+    if(input_type == InputTypeShort && button_type == GuiButtonTypeLeft) {
+        view_dispatcher_send_custom_event(app->view_dispatcher, CustomEventRetryRequested);
+    }
+}
+
+void scene_error_on_enter(void* context) {
+    App* app = context;
+
+    widget_add_icon_element(app->widget, 83, 22, &I_WarningDolphinFlip_45x42);
+    widget_add_button_element(
+        app->widget, GuiButtonTypeLeft, "Retry", scene_error_button_callback, app);
+    widget_add_string_element(
+        app->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Installation Failed!");
+
+    const char* error_msg;
+    if(app->flasher_error == FlasherErrorBadFile) {
+        error_msg = "This file is\ncorrupted or\nunsupported";
+    } else if(app->flasher_error == FlasherErrorDisconnect) {
+        error_msg = "The module was\ndisconnected\nduring the update";
+    } else if(app->flasher_error == FlasherErrorUnknown) {
+        error_msg = "An unknown error\nhas occurred";
+    } else {
+        furi_crash();
+    }
+
+    widget_add_string_multiline_element(
+        app->widget, 0, 28, AlignLeft, AlignCenter, FontSecondary, error_msg);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdWidget);
+
+    notification_message(app->notification, &sequence_error);
+    notification_message(app->notification, &sequence_set_red_255);
+}
+
+bool scene_error_on_event(void* context, SceneManagerEvent event) {
+    App* app = context;
+
+    bool consumed = false;
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == CustomEventRetryRequested) {
+            scene_manager_search_and_switch_to_previous_scene(app->scene_manager, SceneProbe);
+        }
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeBack) {
+        furi_string_reset(app->file_path);
+        scene_manager_search_and_switch_to_previous_scene(app->scene_manager, SceneProbe);
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void scene_error_on_exit(void* context) {
+    App* app = context;
+    widget_reset(app->widget);
+    notification_message(app->notification, &sequence_reset_red);
+}

+ 36 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_file_select.c

@@ -0,0 +1,36 @@
+#include "app_i.h"
+
+#include <furi.h>
+
+#include <dialogs/dialogs.h>
+#include <storage/storage.h>
+
+void scene_file_select_on_enter(void* context) {
+    App* app = context;
+    DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
+
+    DialogsFileBrowserOptions options;
+    dialog_file_browser_set_basic_options(&options, VGM_FW_FILE_EXTENSION, NULL);
+
+    options.hide_dot_files = true;
+    options.base_path = VGM_FW_DEFAULT_PATH;
+
+    if(dialog_file_browser_show(dialogs, app->file_path, app->file_path, &options)) {
+        scene_manager_next_scene(app->scene_manager, SceneConfirm);
+    } else {
+        furi_string_reset(app->file_path);
+        scene_manager_previous_scene(app->scene_manager);
+    }
+
+    furi_record_close(RECORD_DIALOGS);
+}
+
+bool scene_file_select_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return false;
+}
+
+void scene_file_select_on_exit(void* context) {
+    UNUSED(context);
+}

+ 39 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_install.c

@@ -0,0 +1,39 @@
+#include "app_i.h"
+
+#include <furi.h>
+
+#include "flasher/flasher.h"
+
+static void scene_install_flasher_callback(FlasherEvent event, void* context) {
+    furi_assert(context);
+    App* app = context;
+
+    if(event.type == FlasherEventTypeProgress) {
+        progress_set_value(app->progress, event.progress);
+    } else if(event.type == FlasherEventTypeSuccess) {
+        scene_manager_next_scene(app->scene_manager, SceneSuccess);
+    } else if(event.type == FlasherEventTypeError) {
+        app->flasher_error = event.error;
+        scene_manager_next_scene(app->scene_manager, SceneError);
+    }
+}
+
+void scene_install_on_enter(void* context) {
+    App* app = context;
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdProgress);
+
+    flasher_set_callback(scene_install_flasher_callback, app);
+    flasher_start(furi_string_get_cstr(app->file_path));
+}
+
+bool scene_install_on_event(void* context, SceneManagerEvent event) {
+    UNUSED(context);
+    UNUSED(event);
+    return true;
+}
+
+void scene_install_on_exit(void* context) {
+    App* app = context;
+    progress_reset(app->progress);
+}

+ 43 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_probe.c

@@ -0,0 +1,43 @@
+#include "app_i.h"
+
+#include <furi.h>
+
+#include "video_game_module_tool_icons.h"
+
+void scene_probe_on_enter(void* context) {
+    App* app = context;
+
+    if(flasher_init()) {
+        scene_manager_next_scene(app->scene_manager, SceneStart);
+    } else {
+        widget_add_icon_element(app->widget, 1, 1, &I_Update_module_56x52);
+        widget_add_string_multiline_element(
+            app->widget,
+            92,
+            32,
+            AlignCenter,
+            AlignCenter,
+            FontSecondary,
+            "Install Video\nGame Module");
+        view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdWidget);
+    }
+}
+
+bool scene_probe_on_event(void* context, SceneManagerEvent event) {
+    App* app = context;
+
+    bool consumed = false;
+    if(event.type == SceneManagerEventTypeTick) {
+        if(flasher_init()) {
+            scene_manager_next_scene(app->scene_manager, SceneStart);
+        }
+        consumed = true;
+    }
+    return consumed;
+}
+
+void scene_probe_on_exit(void* context) {
+    App* app = context;
+    widget_reset(app->widget);
+    flasher_deinit();
+}

+ 60 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_start.c

@@ -0,0 +1,60 @@
+#include "app_i.h"
+
+#include <furi.h>
+
+typedef enum {
+    SceneStartIndexInstallDefault,
+    SceneStartIndexInstallCustom,
+} SceneStartIndex;
+
+void scene_start_on_enter(void* context) {
+    App* app = context;
+
+    if(!furi_string_empty(app->file_path)) {
+        // File path is set, go directly to firmware install
+        scene_manager_next_scene(app->scene_manager, SceneInstall);
+        return;
+    }
+
+    submenu_add_item(
+        app->submenu,
+        "Install Official Firmware",
+        SceneStartIndexInstallDefault,
+        submenu_item_common_callback,
+        app);
+    submenu_add_item(
+        app->submenu,
+        "Install Firmware from File",
+        SceneStartIndexInstallCustom,
+        submenu_item_common_callback,
+        app);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdSubmenu);
+}
+
+bool scene_start_on_event(void* context, SceneManagerEvent event) {
+    furi_assert(context);
+
+    App* app = context;
+
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == SceneStartIndexInstallDefault) {
+            furi_string_set(app->file_path, VGM_DEFAULT_FW_FILE);
+            scene_manager_next_scene(app->scene_manager, SceneConfirm);
+        } else if(event.event == SceneStartIndexInstallCustom) {
+            scene_manager_next_scene(app->scene_manager, SceneFileSelect);
+        }
+
+        return true;
+    } else if(event.type == SceneManagerEventTypeBack) {
+        view_dispatcher_stop(app->view_dispatcher);
+        return true;
+    }
+
+    return false;
+}
+
+void scene_start_on_exit(void* context) {
+    App* app = context;
+    submenu_reset(app->submenu);
+}

+ 54 - 0
non_catalog_apps/video_game_module_tool/scenes/scene_success.c

@@ -0,0 +1,54 @@
+#include "app_i.h"
+
+#include <furi.h>
+#include <notification/notification_messages.h>
+
+#include "custom_event.h"
+#include "video_game_module_tool_icons.h"
+
+static void
+    scene_success_button_callback(GuiButtonType button_type, InputType input_type, void* context) {
+    App* app = context;
+    if(input_type == InputTypeShort && button_type == GuiButtonTypeCenter) {
+        view_dispatcher_send_custom_event(app->view_dispatcher, CustomEventSuccessDismissed);
+    }
+}
+
+void scene_success_on_enter(void* context) {
+    App* app = context;
+
+    widget_add_icon_element(app->widget, 11, 24, &I_Module_60x26);
+    widget_add_icon_element(app->widget, 77, 10, &I_Checkmark_44x40);
+    widget_add_button_element(
+        app->widget, GuiButtonTypeCenter, "OK", scene_success_button_callback, app);
+    widget_add_string_multiline_element(
+        app->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Video Game Module\nUpdated");
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdWidget);
+
+    notification_message(app->notification, &sequence_success);
+    notification_message(app->notification, &sequence_set_green_255);
+}
+
+bool scene_success_on_event(void* context, SceneManagerEvent event) {
+    App* app = context;
+
+    bool consumed = false;
+    if(event.type == SceneManagerEventTypeCustom) {
+        if(event.event == CustomEventSuccessDismissed) {
+            scene_manager_search_and_switch_to_previous_scene(app->scene_manager, SceneProbe);
+        }
+        consumed = true;
+    } else if(event.type == SceneManagerEventTypeBack) {
+        consumed = true;
+    }
+
+    return consumed;
+}
+
+void scene_success_on_exit(void* context) {
+    App* app = context;
+    widget_reset(app->widget);
+    furi_string_reset(app->file_path);
+    notification_message(app->notification, &sequence_reset_green);
+}

BIN
non_catalog_apps/video_game_module_tool/vgm_tool.png


+ 76 - 0
non_catalog_apps/video_game_module_tool/views/progress.c

@@ -0,0 +1,76 @@
+#include "progress.h"
+
+#include <gui/canvas.h>
+#include <gui/elements.h>
+
+#include "video_game_module_tool_icons.h"
+
+struct Progress {
+    View* view;
+};
+
+typedef struct {
+    FuriString* text;
+    uint8_t progress;
+} ProgressModel;
+
+static void progress_draw_callback(Canvas* canvas, void* _model) {
+    ProgressModel* model = _model;
+
+    canvas_set_font(canvas, FontPrimary);
+    canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "INSTALLING");
+    canvas_draw_icon(canvas, 34, 11, &I_Flashing_module_70x30);
+
+    elements_progress_bar_with_text(
+        canvas, 22, 45, 84, model->progress / 100.f, furi_string_get_cstr(model->text));
+}
+
+Progress* progress_alloc() {
+    Progress* instance = malloc(sizeof(Progress));
+    instance->view = view_alloc();
+
+    view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(ProgressModel));
+    view_set_draw_callback(instance->view, progress_draw_callback);
+
+    with_view_model(
+        instance->view,
+        ProgressModel * model,
+        {
+            model->progress = 0;
+            model->text = furi_string_alloc_printf("0%%");
+        },
+        true);
+
+    return instance;
+}
+
+void progress_free(Progress* instance) {
+    with_view_model(
+        instance->view, ProgressModel * model, { furi_string_free(model->text); }, false);
+
+    view_free(instance->view);
+    free(instance);
+}
+
+View* progress_get_view(Progress* instance) {
+    return instance->view;
+}
+
+void progress_set_value(Progress* instance, uint8_t value) {
+    bool update = false;
+    with_view_model(
+        instance->view,
+        ProgressModel * model,
+        {
+            update = model->progress != value;
+            if(update) {
+                furi_string_printf(model->text, "%u%%", value);
+                model->progress = value;
+            }
+        },
+        update);
+}
+
+void progress_reset(Progress* instance) {
+    progress_set_value(instance, 0);
+}

+ 21 - 0
non_catalog_apps/video_game_module_tool/views/progress.h

@@ -0,0 +1,21 @@
+/**
+ * @file progress.h
+ * @brief Gui view used to display the flashing progress.
+ *
+ * Includes a progress bar and some static graphics.
+ */
+#pragma once
+
+#include <gui/view.h>
+
+typedef struct Progress Progress;
+
+Progress* progress_alloc();
+
+void progress_free(Progress* instance);
+
+View* progress_get_view(Progress* instance);
+
+void progress_set_value(Progress* instance, uint8_t value);
+
+void progress_reset(Progress* instance);