Skip to content

App port changes #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/natmod/deepcraft/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ ARCH = armv7emsp
# Link with libm.a and libgcc.a from the toolchain
LINK_RUNTIME = 1

# Include to get the rules for compiling and linking the module
include $(MPY_DIR)/py/dynruntime.mk
override LIBGCC_PATH := gcc/lib/gcc/arm-none-eabi/11.3.1/thumb/v7e-m+fp/hard/libgcc.a
override LIBM_PATH := gcc/arm-none-eabi/lib/thumb/v7e-m+fp/hard/libm.a

include $(MPY_DIR)/py/dynruntime.mk

# Custom clean target
clean:
rm -rf .mpy_ld_cache/ build/ $(MOD).mpy
50 changes: 32 additions & 18 deletions examples/natmod/deepcraft/dc_mp_iface.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define MICROPY_PY_DEEPCRAFT_MPY (1)

#include "py/dynruntime.h"

#if !defined(__linux__)
Expand All @@ -21,26 +19,42 @@ int *__errno (void)
return &native_errno;
}

mp_obj_full_type_t dcmodel_type;

#include "examples/natmod/deepcraft/mp_src.c"

mp_map_elem_t dcmodel_locals_dict_table[3];
static MP_DEFINE_CONST_DICT(dcmodel_locals_dict, dcmodel_locals_dict_table);

mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
MP_DYNRUNTIME_INIT_ENTRY
// Forward declaration of type
mp_obj_full_type_t dc_type;

dcmodel_type.base.type = mp_fun_table.type_type;
dcmodel_type.name = MP_QSTR_DEEPCRAFT;
//MP_OBJ_TYPE_SET_SLOT(&dcmodel_type, make_new, &deflateio_make_new, 0);
dcmodel_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_init), MP_OBJ_FROM_PTR(&init_obj) };
dcmodel_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_enqueue), MP_OBJ_FROM_PTR(&enqueue_obj) };
dcmodel_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_dequeue), MP_OBJ_FROM_PTR(&dequeue_obj) };
MP_OBJ_TYPE_SET_SLOT(&dcmodel_type, locals_dict, (void*)&dcmodel_locals_dict, 2);
mp_map_elem_t dc_locals_dict_table[5];
static MP_DEFINE_CONST_DICT(dc_locals_dict, dc_locals_dict_table);

mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_deepcraft));
mp_store_global(MP_QSTR_DEEPCRAFT, MP_OBJ_FROM_PTR(&dcmodel_type));
// Constructor
static mp_obj_t dc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) {
dc_obj_t *self = mp_obj_malloc(dc_obj_t, type);
return MP_OBJ_FROM_PTR(self);
}

// Create type and methods at runtime
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
// This must be first, it sets up the globals dict and other things
MP_DYNRUNTIME_INIT_ENTRY

// Populate type
dc_type.base.type = (void*)&mp_type_type;
dc_type.flags = MP_TYPE_FLAG_NONE;
dc_type.name = MP_QSTR_DEEPCRAFT;
MP_OBJ_TYPE_SET_SLOT(&dc_type, make_new, dc_make_new, 0);

dc_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_init), MP_OBJ_FROM_PTR(&init_obj) };
dc_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_enqueue), MP_OBJ_FROM_PTR(&enqueue_obj) };
dc_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_dequeue), MP_OBJ_FROM_PTR(&dequeue_obj) };
dc_locals_dict_table[3] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_get_model_input_dim), MP_OBJ_FROM_PTR(&get_model_input_dim_obj) };
dc_locals_dict_table[4] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_get_model_output_dim), MP_OBJ_FROM_PTR(&get_model_output_dim_obj) };

MP_OBJ_TYPE_SET_SLOT(&dc_type, locals_dict, (void*)&dc_locals_dict, 5);

// Expose constructor as DEEPCRAFT
mp_store_global(MP_QSTR_DEEPCRAFT, MP_OBJ_FROM_PTR(&dc_type));
// This must be last, it restores the globals dict
MP_DYNRUNTIME_INIT_EXIT

}
Loading
Loading