Extending MP classes #10811
-
Hi, I would like to extend the PWM object with the In python itself, lets say when I create the
I tried to define the methods in the source, by creating a So, any hints, how it can be done? Simple, Fast, and proper.. Even if these are three different ways :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I have a similar question, regarding the Timer class in my case. |
Beta Was this translation helpful? Give feedback.
-
The PWM class is pretty limited in methods. The class dictionary is in extmod/machine_pwm.c, and the per-port machine_pwm implementation is just included into that file. The only freedom you have is in the keyword arguments of the constructor or the init() method. The rp2 port does not support keyword arguments for the constructor, |
Beta Was this translation helpful? Give feedback.
The PWM class is pretty limited in methods. The class dictionary is in extmod/machine_pwm.c, and the per-port machine_pwm implementation is just included into that file. The only freedom you have is in the keyword arguments of the constructor or the init() method. The rp2 port does not support keyword arguments for the constructor,
but you can use pwm.init(), and there is no init() method. So for any extension you have to change extmod/machine_pwm.c, or extend the existing rp2 port e.g. with pwm.init().