Help interfacing with C function and input parameters format

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
sigur_ros21
Posts: 1
Joined: Mon Dec 03, 2018 3:10 pm

Help interfacing with C function and input parameters format

Post by sigur_ros21 » Mon Dec 03, 2018 3:27 pm

Hi All,

I am relatively new to micropython and am struggling a bit trying to do the following. I have a series of functions implemented in C, which look like:

[code]
void foo(double [] arg1, double [] arg2, double [] arg3)
[/code]

I would like to create a micropython module that allows me to call such c function from the main .py that is running on an ESP32-based platform. So far, I have created such module, including methods that allow calling such c functions. For example:

[code]
STATIC mp_obj_t mymod_foo(size_t n_args, const mp_obj_t *args) {

mp_obj_t *arg1, *arg2, *arg3;
mp_uint_t len_arg1, len_arg1, len_arg3;
/* ToDo*/
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mymod_obj, 4, 4, mymod_foo);
[/code]

What I don't know is how to get double-type objects such that I can call the C-function foo(arg1, arg2, arg3). So far, I have tried things like:

[code]
mp_obj_list_get(args[1], &len_arg1, &arg1);
[/code]

which as expected copies whichever input list I have in args[1] in arg1 as well as extracts the length of such list. Nonetheless, what could I do next? How could I convert arg1 into an double-type array? Or is any other approach to do this?

Thank you

jickster
Posts: 546
Joined: Thu Sep 07, 2017 8:57 pm

Re: Help interfacing with C function and input parameters format

Post by jickster » Tue Dec 04, 2018 6:18 pm

Yes I’ll help.

Putting this here as a reminder to myself.


Sent from my iPhone using Tapatalk Pro

Post Reply