Replies: 2 comments 2 replies
-
To pass a pwm object from Python to C, you basically do this: machine_pwm_obj_t *self = MP_OBJ_TO_PTR(args[0]); The file ports/esp32/machine_pwm.c is where the The file micropython/extmod/machine_pwm.c defines the methods to be used in MicroPython. for example, // PWM.freq([value])
static mp_obj_t machine_pwm_freq(size_t n_args, const mp_obj_t *args) {
machine_pwm_obj_t *self = MP_OBJ_TO_PTR(args[0]);
if (n_args == 1) {
// Get frequency.
return mp_machine_pwm_freq_get(self);
} else {
// Set the frequency.
mp_int_t freq = mp_obj_get_int(args[1]);
mp_machine_pwm_freq_set(self, freq);
return mp_const_none;
}
}
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_pwm_freq_obj, 1, 2, machine_p
wm_freq); This is what get called when you do: freq = pwm.freq() |
Beta Was this translation helpful? Give feedback.
1 reply
-
I wrote a short tutorial that might be helpful. You can find it at https://github.com/shariltumin/c-module-tutorial-micropython |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, we are trying to develop an external C module on esp32, starting from the cppexample user module example. We successfully built the the custom firmware, things are all good until we started to use the hardware PWM peripheral. What we expected to implement is to initialize a PWM from python and pass the pwm object to a C function to use in the C module. I searched a lot, but found few information about this topic. Any suggestion or guidance is appreciated. Thanks
Beta Was this translation helpful? Give feedback.
All reactions