forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/imagimob: Adding support for imagimob integration.
Signed-off-by: NikhitaR-IFX <[email protected]>
- Loading branch information
1 parent
484febb
commit a2b7c72
Showing
9 changed files
with
4,091 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# MicroPython ImagiMob Integration for Infineon's PSoC6 port | ||
|
||
This directory contains the imagimob generated model files and the interface for it's enablement in micropython. To access your edge ai models developed for PSoC6 based kit from a micropython application, please follow the description below. | ||
|
||
## Folder structure | ||
|
||
model.c : Imagimob generated source code in C for your developed model in the studio. | ||
model.h : Imagimob generated source code in C for your developed model in the studio. | ||
|
||
imai_mp_iface.c : MicroPython interface for ImagiMob models. | ||
|
||
micropython.mk : Makefile configurations for firmware generation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Include MicroPython API. | ||
#include "py/runtime.h" | ||
|
||
#include "py/mphal.h" | ||
#include "model.h" | ||
|
||
static mp_obj_t init(void){ | ||
IMAI_init(); | ||
return mp_const_none; | ||
} | ||
MP_DEFINE_CONST_FUN_OBJ_0(init_obj, init); | ||
|
||
static mp_obj_t enqueue(const mp_obj_t data_in_obj){ | ||
float data_in[IMAI_DATA_IN_COUNT]; | ||
mp_obj_t *data_in_items; | ||
size_t len; | ||
mp_obj_get_array(data_in_obj, &len, &data_in_items); | ||
if (len != IMAI_DATA_IN_COUNT) { | ||
mp_raise_ValueError("data_in must be a list of IMAI_DATA_IN_COUNT floats"); | ||
} | ||
for (int i = 0; i < IMAI_DATA_IN_COUNT; i++) { | ||
data_in[i] = mp_obj_float_get(data_in_items[i]); | ||
} | ||
int result = IMAI_enqueue(data_in); | ||
return MP_OBJ_NEW_SMALL_INT(result); | ||
} | ||
MP_DEFINE_CONST_FUN_OBJ_1(enqueue_obj, enqueue); | ||
|
||
static mp_obj_t dequeue(mp_obj_t data_out_obj) { | ||
mp_buffer_info_t buf_info; | ||
mp_get_buffer(data_out_obj, &buf_info, MP_BUFFER_WRITE); | ||
float *data_out = (float *)buf_info.buf; | ||
int result = IMAI_dequeue(data_out); | ||
if (result == 0) { | ||
return MP_OBJ_NEW_SMALL_INT(result); | ||
} else if (result == -1) { | ||
mp_printf(&mp_plat_print, "No data is currently available\n"); | ||
return MP_OBJ_NEW_SMALL_INT(result); | ||
} else if (result == -2) { | ||
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("Internal memory allocation error"), result); | ||
} | ||
return MP_OBJ_NEW_SMALL_INT(result); | ||
} | ||
MP_DEFINE_CONST_FUN_OBJ_1(dequeue_obj, dequeue); | ||
|
||
static const mp_rom_map_elem_t example_module_globals_table[] = { | ||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_imai) }, | ||
|
||
// imagimob fns | ||
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&init_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_enqueue), MP_ROM_PTR(&enqueue_obj) }, | ||
{ MP_ROM_QSTR(MP_QSTR_dequeue), MP_ROM_PTR(&dequeue_obj) }, | ||
|
||
// constants | ||
{ MP_ROM_QSTR(MP_QSTR_DATA_IN), MP_ROM_INT(IMAI_DATA_IN_COUNT) }, | ||
{ MP_ROM_QSTR(MP_QSTR_DATA_OUT), MP_ROM_INT(IMAI_DATA_OUT_COUNT) }, | ||
}; | ||
static MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); | ||
|
||
// Define module object. | ||
const mp_obj_module_t imai_module = { | ||
.base = { &mp_type_module }, | ||
.globals = (mp_obj_dict_t *)&example_module_globals, | ||
}; | ||
|
||
// Register the module to make it available in Python. | ||
#if MICROPY_PY_IMAI | ||
MP_REGISTER_MODULE(MP_QSTR_imai, imai_module); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
IMAI_MOD_DIR := $(USERMOD_DIR) | ||
|
||
# Add all C files to SRC_USERMOD. | ||
SRC_USERMOD += $(IMAI_MOD_DIR)/imai_mp_iface.c $(IMAI_MOD_DIR)/model.c | ||
|
||
# We can add our module folder to include paths if needed | ||
# This is not actually needed in this example. | ||
CFLAGS_USERMOD += -I$(IMAI_MOD_DIR) |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
MICROPY_VFS_LFS2=1 | ||
MICROPY_PY_IMAI=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
Q(/) | ||
Q(/flash) | ||
Q(/lib) | ||
Q(imai_model) | ||
Q(add_ints) |