Oliver Fabel 1 год назад
Сommit
8cfa40e26b
13 измененных файлов с 291 добавлено и 0 удалено
  1. 191 0
      .clang-format
  2. 2 0
      .clangd
  3. 4 0
      .gitignore
  4. 3 0
      .gitmodules
  5. 17 0
      Makefile
  6. 0 0
      Makefile.upylib
  7. 29 0
      application.fam
  8. BIN
      icon.png
  9. 1 0
      lib/micropython
  10. 19 0
      mp_flipper_app.c
  11. 10 0
      mpconfigport.h
  12. 13 0
      port/mphalport.c
  13. 2 0
      port/mphalport.h

+ 191 - 0
.clang-format

@@ -0,0 +1,191 @@
+---
+Language:        Cpp
+AccessModifierOffset: -4
+AlignAfterOpenBracket: AlwaysBreak
+AlignArrayOfStructures: None
+AlignConsecutiveMacros: None
+AlignConsecutiveAssignments: None
+AlignConsecutiveBitFields: None
+AlignConsecutiveDeclarations: None
+AlignEscapedNewlines: Left
+AlignOperands:   Align
+AlignTrailingComments: false
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortEnumsOnASingleLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: WithoutElse
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+AttributeMacros:
+  - __capability
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+  AfterCaseLabel:  false
+  AfterClass:      false
+  AfterControlStatement: Never
+  AfterEnum:       false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  AfterExternBlock: false
+  BeforeCatch:     false
+  BeforeElse:      false
+  BeforeLambdaBody: false
+  BeforeWhile:     false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeConceptDeclarations: true
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: false
+ColumnLimit:     120
+CommentPragmas:  '^ IWYU pragma:'
+QualifierAlignment: Leave
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+PackConstructorInitializers: BinPack
+BasedOnStyle:    ''
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+AllowAllConstructorInitializersOnNextLine: true
+FixNamespaceComments: false
+ForEachMacros:
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IfMacros:
+  - KJ_IF_MAYBE
+IncludeBlocks:   Preserve
+IncludeCategories:
+  - Regex:           '.*'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
+    Priority:        3
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '.*'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseLabels: false
+IndentCaseBlocks: false
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentExternBlock: AfterExternBlock
+IndentRequires:  false
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+InsertTrailingCommas: None
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LambdaBodyIndentation: Signature
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 4
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakString: 10
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 100
+PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+PointerAlignment: Left
+PPIndentWidth:   -1
+ReferenceAlignment: Pointer
+ReflowComments:  false
+RemoveBracesLLVM: false
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes:    Never
+SortJavaStaticImport: Before
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: Never
+SpaceBeforeParensOptions:
+  AfterControlStatements: false
+  AfterForeachMacros: false
+  AfterFunctionDefinitionName: false
+  AfterFunctionDeclarationName: false
+  AfterIfMacros:   false
+  AfterOverloadedOperator: false
+  BeforeNonEmptyParentheses: false
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  Never
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+  Minimum:         1
+  Maximum:         -1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+BitFieldColonSpacing: Both
+Standard:        c++03
+StatementAttributeLikeMacros:
+  - Q_EMIT
+StatementMacros:
+  - Q_UNUSED
+  - QT_REQUIRE_VERSION
+TabWidth:        4
+UseCRLF:         false
+UseTab:          Never
+WhitespaceSensitiveMacros:
+  - STRINGIZE
+  - PP_STRINGIZE
+  - BOOST_PP_STRINGIZE
+  - NS_SWIFT_NAME
+  - CF_SWIFT_NAME
+...
+

+ 2 - 0
.clangd

@@ -0,0 +1,2 @@
+Diagnostics:
+  Suppress: 'expected_fn_body'

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+/build-embed/
+/lib/micropython-build/
+/compile_flags.txt
+*.kate-swp

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "lib/micropython"]
+	path = lib/micropython
+	url = https://github.com/micropython/micropython.git

+ 17 - 0
Makefile

@@ -0,0 +1,17 @@
+# Set the location of the top of the MicroPython repository.
+MICROPYTHON_TOP = ./lib/micropython
+
+PACKAGE_DIR = ./lib/micropython-build
+
+# Include the main makefile fragment to build the MicroPython component.
+include $(MICROPYTHON_TOP)/ports/embed/embed.mk
+
+$(PACKAGE_DIR): all
+
+.PHONY: build
+build: $(PACKAGE_DIR)
+	ufbt build
+
+.PHONY: launch
+launch: build
+	ufbt launch

+ 0 - 0
Makefile.upylib


+ 29 - 0
application.fam

@@ -0,0 +1,29 @@
+# For details & more options, see documentation/AppManifests.md in firmware repo
+
+App(
+    appid="mp_flipper_app",  # Must be unique
+    name="uPython",  # Displayed in menus
+    apptype=FlipperAppType.EXTERNAL,
+    entry_point="mp_flipper_app",
+    stack_size=2 * 1024,
+    fap_category="Examples",
+    fap_icon="icon.png",  # 10x10 1-bit PNG
+    fap_author="Oliver Fabel",
+    # fap_weburl="https://github.com/user/funky_flipper_app",
+    # fap_icon_assets="images",  # Image assets to compile for this application
+    sources=[
+        "*.c*",
+        "!./build-embed",
+        "!./lib/micropython"
+    ],
+    fap_private_libs=[
+        Lib(
+            name="micropython-build",
+            cflags=[
+                "-Wno-error",
+                "-w"
+            ],
+            cincludes=["."]
+        )
+    ]
+)


+ 1 - 0
lib/micropython

@@ -0,0 +1 @@
+Subproject commit 5114f2c1ea7c05fc7ab920299967595cfc5307de

+ 19 - 0
mp_flipper_app.c

@@ -0,0 +1,19 @@
+#include <furi.h>
+
+#include <port/micropython_embed.h>
+
+int32_t mp_flipper_app(void* p) {
+    UNUSED(p);
+
+    const size_t memory_size = memmgr_get_free_heap() * 0.5;
+    const size_t stack_size = 2 * 1024;
+    uint8_t* memory = malloc(memory_size * sizeof(uint8_t));
+
+    mp_embed_init(memory + stack_size, memory_size - stack_size, memory);
+    mp_embed_exec_str("print('hello world!');");
+    mp_embed_deinit();
+
+    free(memory);
+
+    return 0;
+}

+ 10 - 0
mpconfigport.h

@@ -0,0 +1,10 @@
+#include <port/mpconfigport_common.h>
+
+#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_MINIMUM)
+
+#define MICROPY_ENABLE_COMPILER (1)
+#define MICROPY_ENABLE_GC (1)
+#define MICROPY_MIN_USE_CORTEX_CPU (1)
+#define MICROPY_MIN_USE_STM32_MCU (1)
+#define MICROPY_HW_BOARD_NAME "Flipper Zero"
+#define MICROPY_HW_MCU_NAME "STM32WB55RG"

+ 13 - 0
port/mphalport.c

@@ -0,0 +1,13 @@
+#include <furi.h>
+#include <stdio.h>
+
+#include "py/mphal.h"
+
+// Send string of given length to stdout, converting \n to \r\n.
+void mp_hal_stdout_tx_strn_cooked(const char* str, size_t len) {
+    printf("%.*s", (int)len, str);
+}
+
+void mp_hal_stdout_tx_str(const char* str) {
+    printf("%s", str);
+}

+ 2 - 0
port/mphalport.h

@@ -0,0 +1,2 @@
+// Define so there's no dependency on extmod/virtpin.h
+#define mp_hal_pin_obj_t