Prechádzať zdrojové kódy

remove obsolete files

Oliver Fabel 1 rok pred
rodič
commit
636fdec342

+ 5 - 7
application.fam

@@ -1,17 +1,14 @@
-# For details & more options, see documentation/AppManifests.md in firmware repo
-
 App(
 App(
-    appid="mp_flipper_app",  # Must be unique
-    name="uPython",  # Displayed in menus
+    appid="mp_flipper_app",
+    name="uPython",
     apptype=FlipperAppType.EXTERNAL,
     apptype=FlipperAppType.EXTERNAL,
     entry_point="mp_flipper_app",
     entry_point="mp_flipper_app",
     stack_size=4 * 1024,
     stack_size=4 * 1024,
     fap_category="Examples",
     fap_category="Examples",
-    fap_icon="icon.png",  # 10x10 1-bit PNG
+    fap_icon="icon.png",
     fap_author="Oliver Fabel",
     fap_author="Oliver Fabel",
     fap_file_assets="examples",
     fap_file_assets="examples",
-    # fap_weburl="https://github.com/user/funky_flipper_app",
-    # fap_icon_assets="images",  # Image assets to compile for this application
+    fap_weburl="https://github.com/ofabel/mp-flipper",
     cdefines=[
     cdefines=[
         "MP_FLIPPER_RUNTIME",
         "MP_FLIPPER_RUNTIME",
         "MP_FLIPPER_COMPILER",
         "MP_FLIPPER_COMPILER",
@@ -20,6 +17,7 @@ App(
     sources=[
     sources=[
         "*.c*",
         "*.c*",
         "!./lib/micropython",
         "!./lib/micropython",
+        "!./lib/micropython-port",
     ],
     ],
     fap_private_libs=[
     fap_private_libs=[
         Lib(
         Lib(

+ 0 - 0
lib/micropython-port/polyfill.c → lib/micropython-port/mp_flipper_polyfill.c


+ 43 - 6
mp_flipper_app.c

@@ -5,14 +5,51 @@
 #include <storage/storage.h>
 #include <storage/storage.h>
 
 
 #include <mp_flipper_runtime.h>
 #include <mp_flipper_runtime.h>
+#include <mp_flipper_compiler.h>
 
 
-#include "mp_flipper_app.h"
-#include "py_app.h"
+#define TAG "uPython"
 
 
-const char* root_module_path;
+static void execute_file(FuriString* file) {
+    size_t stack;
 
 
-ViewPort* mp_flipper_view_port;
-FuriMessageQueue* mp_flipper_event_queue;
+    const char* path = furi_string_get_cstr(file);
+    FuriString* file_path = furi_string_alloc_printf("%s", path);
+
+    do {
+        FURI_LOG_I(TAG, "executing script %s", path);
+
+        const size_t heap_size = memmgr_get_free_heap() * 0.1;
+        const size_t stack_size = 2 * 1024;
+        uint8_t* heap = malloc(heap_size * sizeof(uint8_t));
+
+        FURI_LOG_D(TAG, "initial heap size is %zu bytes", heap_size);
+        FURI_LOG_D(TAG, "stack size is %zu bytes", stack_size);
+
+        size_t index = furi_string_search_rchar(file_path, '/');
+
+        furi_check(index != FURI_STRING_FAILURE);
+
+        bool is_py_file = furi_string_end_with_str(file_path, ".py");
+
+        furi_string_left(file_path, index);
+
+        mp_flipper_set_root_module_path(furi_string_get_cstr(file_path));
+
+        mp_flipper_init(heap, heap_size, stack_size, &stack);
+
+        if(is_py_file) {
+            mp_flipper_exec_py_file(path);
+        } else {
+            mp_flipper_exec_mpy_file(path);
+        }
+
+        mp_flipper_deinit();
+
+        free(heap);
+    } while(false);
+
+    furi_string_free(file_path);
+}
 
 
 static bool select_python_file(FuriString* file_path) {
 static bool select_python_file(FuriString* file_path) {
     DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
     DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
@@ -37,7 +74,7 @@ int32_t mp_flipper_app(void* p) {
     FuriString* file_path = furi_string_alloc();
     FuriString* file_path = furi_string_alloc();
 
 
     if(select_python_file(file_path)) {
     if(select_python_file(file_path)) {
-        py_app_file_execute(file_path);
+        execute_file(file_path);
     }
     }
 
 
     furi_string_free(file_path);
     furi_string_free(file_path);

+ 0 - 14
mp_flipper_app.h

@@ -1,14 +0,0 @@
-#pragma once
-
-#include <stdbool.h>
-
-#include <gui/gui.h>
-
-#define SCREEN_WIDTH 128
-#define SCREEN_HEIGHT 64
-#define SCREEN_PIXEL_PER_ITEM 32
-
-extern ViewPort* mp_flipper_view_port;
-extern FuriMessageQueue* mp_flipper_event_queue;
-
-extern const char* root_module_path;

+ 0 - 115
mp_flipper_app_settings.c

@@ -1,115 +0,0 @@
-#include <gui/gui.h>
-#include <gui/modules/variable_item_list.h>
-#include <gui/view_dispatcher.h>
-#include <lib/toolbox/value_index.h>
-
-#include "py_app.h"
-
-typedef struct {
-    Gui* gui;
-    PyApp* settings;
-    ViewDispatcher* view_dispatcher;
-    VariableItemList* items;
-} PyAppSettings;
-
-#define STACK_SIZE 3
-const char* const stack_size_text[STACK_SIZE] = {
-    "512",
-    "1024",
-    "2048",
-};
-const int32_t stack_size[STACK_SIZE] = {
-    512,
-    1024,
-    2048,
-};
-
-#define HEAP_SIZE 5
-const char* const heap_size_text[HEAP_SIZE] = {
-    "10%",
-    "20%",
-    "30%",
-    "40%",
-    "50%",
-};
-const float heap_size[HEAP_SIZE] = {
-    0.1,
-    0.2,
-    0.3,
-    0.4,
-    0.5,
-};
-
-static void set_stack_size(VariableItem* item) {
-    PyAppSettings* app = variable_item_get_context(item);
-    uint8_t index = variable_item_get_current_value_index(item);
-
-    variable_item_set_current_value_text(item, stack_size_text[index]);
-    app->settings->stack_size = stack_size[index];
-}
-
-static void set_heap_size(VariableItem* item) {
-    PyAppSettings* app = variable_item_get_context(item);
-    uint8_t index = variable_item_get_current_value_index(item);
-
-    variable_item_set_current_value_text(item, heap_size_text[index]);
-    app->settings->heap_size = heap_size[index];
-}
-
-static uint32_t py_app_settings_exit(void* context) {
-    UNUSED(context);
-    return VIEW_NONE;
-}
-
-static PyAppSettings* alloc_settings(void) {
-    PyAppSettings* app = malloc(sizeof(PyAppSettings));
-
-    app->gui = furi_record_open(RECORD_GUI);
-    app->settings = py_app_load_settings();
-    app->items = variable_item_list_alloc();
-
-    View* view = variable_item_list_get_view(app->items);
-
-    view_set_previous_callback(view, py_app_settings_exit);
-
-    VariableItem* item;
-    uint8_t value_index;
-
-    item = variable_item_list_add(app->items, "Stack Size", STACK_SIZE, set_stack_size, app);
-    value_index = value_index_int32(app->settings->stack_size, stack_size, STACK_SIZE);
-    variable_item_set_current_value_index(item, value_index);
-    variable_item_set_current_value_text(item, stack_size_text[value_index]);
-
-    item = variable_item_list_add(app->items, "Heap Size", HEAP_SIZE, set_heap_size, app);
-    value_index = value_index_float(app->settings->heap_size, heap_size, HEAP_SIZE);
-    variable_item_set_current_value_index(item, value_index);
-    variable_item_set_current_value_text(item, heap_size_text[value_index]);
-
-    app->view_dispatcher = view_dispatcher_alloc();
-    view_dispatcher_enable_queue(app->view_dispatcher);
-    view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
-    view_dispatcher_add_view(app->view_dispatcher, 0, view);
-    view_dispatcher_switch_to_view(app->view_dispatcher, 0);
-
-    return app;
-}
-
-static void free_settings(PyAppSettings* app) {
-    view_dispatcher_remove_view(app->view_dispatcher, 0);
-    variable_item_list_free(app->items);
-    view_dispatcher_free(app->view_dispatcher);
-
-    free(app->settings);
-
-    furi_record_close(RECORD_GUI);
-    free(app);
-}
-
-int32_t py_app_settings_app(void* p) {
-    UNUSED(p);
-    PyAppSettings* app = alloc_settings();
-    view_dispatcher_run(app->view_dispatcher);
-    py_app_save_settings(app->settings);
-    free_settings(app);
-    return 0;
-}

+ 0 - 42
mpconfigport.h

@@ -1,42 +0,0 @@
-#include <stdint.h>
-
-// Type definitions for the specific machine
-
-typedef int32_t mp_int_t; // must be pointer size
-typedef uint32_t mp_uint_t; // must be pointer size
-typedef long mp_off_t;
-
-// Need to provide a declaration/definition of alloca()
-#if defined(__FreeBSD__) || defined(__NetBSD__)
-#include <stdlib.h>
-#else
-#include <alloca.h>
-#endif
-
-#define MICROPY_MPHALPORT_H "lib/micropython-port/mphalport.h"
-
-#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_BASIC_FEATURES)
-
-#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"
-
-#define MICROPY_ENABLE_EXTERNAL_IMPORT (1)
-#define MICROPY_READER_VFS (1)
-
-#define MICROPY_PY_TIME (1)
-#define MICROPY_PY_TIME_TIME_TIME_NS (1)
-
-#define MICROPY_PY_RANDOM (1)
-#define MICROPY_PY_RANDOM_EXTRA_FUNCS (1)
-
-#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (mp_flipper_seed_init())
-
-#define MICROPY_PY_MATH (0)
-#define MICROPY_PY_BUILTINS_COMPLEX (0)
-#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)

+ 0 - 142
py_app.c

@@ -1,142 +0,0 @@
-#include <furi.h>
-#include <storage/storage.h>
-
-#include <mp_flipper_runtime.h>
-#include <mp_flipper_compiler.h>
-
-#include "py_app.h"
-
-#define PYTHON_SETTINGS_VERSION 0x01
-#define PYTHON_SETTINGS_PATH INT_PATH(".python.settings")
-
-int32_t py_app(void* arg) {
-    if(arg == NULL || strlen(arg) == 0) {
-        return 0;
-    }
-
-    FuriString* file_path = furi_string_alloc_printf("%s", (const char*)arg);
-
-    py_app_file_execute(file_path);
-
-    furi_string_free(file_path);
-
-    return 0;
-}
-
-void py_app_file_execute(FuriString* file) {
-    size_t stack;
-
-    PyApp* app = py_app_alloc();
-    const char* path = furi_string_get_cstr(file);
-    FuriString* file_path = furi_string_alloc_printf("%s", path);
-
-    do {
-        FURI_LOG_I(TAG, "executing script %s", path);
-
-        const size_t heap_size = memmgr_get_free_heap() * app->heap_size;
-        const size_t stack_size = app->stack_size;
-        uint8_t* heap = malloc(heap_size * sizeof(uint8_t));
-
-        FURI_LOG_D(TAG, "allocated memory is %zu bytes", heap_size);
-        FURI_LOG_D(TAG, "stack size is %zu bytes", stack_size);
-
-        size_t index = furi_string_search_rchar(file_path, '/');
-
-        furi_check(index != FURI_STRING_FAILURE);
-
-        bool is_py_file = furi_string_end_with_str(file_path, ".py");
-
-        furi_string_left(file_path, index);
-
-        mp_flipper_set_root_module_path(furi_string_get_cstr(file_path));
-
-        mp_flipper_init(heap, heap_size, stack_size, &stack);
-
-        if(is_py_file) {
-            mp_flipper_exec_py_file(path);
-        } else {
-            mp_flipper_exec_mpy_file(path);
-        }
-
-        mp_flipper_deinit();
-
-        free(heap);
-    } while(false);
-
-    furi_string_free(file_path);
-
-    py_app_free(app);
-}
-
-PyApp* py_app_load_settings() {
-    File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
-
-    PyApp* settings = malloc(sizeof(PyApp));
-
-    const size_t settings_size = sizeof(PyApp);
-
-    FURI_LOG_I(TAG, "loading settings from \"%s\"", PYTHON_SETTINGS_PATH);
-    bool fs_result = storage_file_open(file, PYTHON_SETTINGS_PATH, FSAM_READ, FSOM_OPEN_EXISTING);
-
-    if(fs_result) {
-        size_t bytes_count = storage_file_read(file, settings, settings_size);
-
-        fs_result = bytes_count == settings_size;
-    }
-
-    if(fs_result) {
-        FURI_LOG_I(TAG, "load success");
-    } else {
-        FURI_LOG_E(TAG, "load failed, %s", storage_file_get_error_desc(file));
-
-        settings->heap_size = 0.1;
-        settings->stack_size = 1024;
-        settings->version = PYTHON_SETTINGS_VERSION;
-    }
-
-    if(fs_result && settings->version != PYTHON_SETTINGS_VERSION) {
-        FURI_LOG_E(TAG, "version(%d != %d) mismatch", settings->version, PYTHON_SETTINGS_VERSION);
-    }
-
-    storage_file_close(file);
-    storage_file_free(file);
-
-    furi_record_close(RECORD_STORAGE);
-
-    return settings;
-};
-
-void py_app_save_settings(PyApp* settings) {
-    File* file = storage_file_alloc(furi_record_open(RECORD_STORAGE));
-
-    const size_t settings_size = sizeof(PyApp);
-
-    FURI_LOG_I(TAG, "saving settings to \"%s\"", PYTHON_SETTINGS_PATH);
-
-    bool fs_result = storage_file_open(file, PYTHON_SETTINGS_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS);
-
-    if(fs_result) {
-        size_t bytes_count = storage_file_write(file, settings, settings_size);
-
-        fs_result = bytes_count == settings_size;
-    }
-
-    if(fs_result) {
-        FURI_LOG_I(TAG, "save success");
-    } else {
-        FURI_LOG_E(TAG, "save failed, %s", storage_file_get_error_desc(file));
-    }
-
-    storage_file_close(file);
-    storage_file_free(file);
-
-    furi_record_close(RECORD_STORAGE);
-};
-
-PyApp* py_app_alloc() {
-    return py_app_load_settings();
-}
-
-void py_app_free(PyApp* app) {
-    free(app);
-}

+ 0 - 21
py_app.h

@@ -1,21 +0,0 @@
-#pragma once
-
-#include <furi.h>
-
-#define TAG "uPython"
-
-typedef struct {
-    size_t stack_size;
-    float heap_size;
-    uint8_t version;
-} PyApp;
-
-int32_t py_app(void* arg);
-
-void py_app_file_execute(FuriString* file);
-
-PyApp* py_app_load_settings();
-void py_app_save_settings(PyApp* settings);
-
-PyApp* py_app_alloc();
-void py_app_free(PyApp* app);