Get an Instance of a Timer
Get an Instance of a Timer
Hello,
I am currently trying to implement a MicroPython module that init a timer and starts it. But with the following code:
[code]
mp_obj_t TimerInit (uint8_t uint8TimerNum) {
mp_obj_t args[1] = {
MP_OBJ_NEW_SMALL_INT(uint8TimerNum)
};
return pyb_timer_type.make_new((mp_obj_t)&pyb_timer_type, 1, 0, args);
}
[/code]
I only get the error message:
[code]
...:82:2: error: unknown type name 'pyb_timer_obj_t'; did you mean 'pin_obj_t'?
[/code]
Can someone tell me how to initalize a new timer in C and then access his arguments?
I am currently trying to implement a MicroPython module that init a timer and starts it. But with the following code:
[code]
mp_obj_t TimerInit (uint8_t uint8TimerNum) {
mp_obj_t args[1] = {
MP_OBJ_NEW_SMALL_INT(uint8TimerNum)
};
return pyb_timer_type.make_new((mp_obj_t)&pyb_timer_type, 1, 0, args);
}
[/code]
I only get the error message:
[code]
...:82:2: error: unknown type name 'pyb_timer_obj_t'; did you mean 'pin_obj_t'?
[/code]
Can someone tell me how to initalize a new timer in C and then access his arguments?
Re: Get an Instance of a Timer
There's plenty of examples of initializing timers.Scalli wrote: ↑Wed Jul 18, 2018 12:18 pmHello,
I am currently trying to implement a MicroPython module that init a timer and starts it. But with the following code:I only get the error message:Code: Select all
mp_obj_t TimerInit (uint8_t uint8TimerNum) { mp_obj_t args[1] = { MP_OBJ_NEW_SMALL_INT(uint8TimerNum) }; return pyb_timer_type.make_new((mp_obj_t)&pyb_timer_type, 1, 0, args); }
Can someone tell me how to initalize a new timer in C and then access his arguments?Code: Select all
...:82:2: error: unknown type name 'pyb_timer_obj_t'; did you mean 'pin_obj_t'?
https://github.com/micropython/micropyt ... r_make_new
What specifically do you need to do?
Re: Get an Instance of a Timer
[quote=jickster post_id=28696 time=1531935285 user_id=3167]
There's plenty of examples of initializing timers.
https://github.com/micropython/micropyt ... r_make_new
What specifically do you need to do?
[/quote]
Hi jickster,
thanks for your repl.
I know there is the make_new method in each objekt. But I can't access the pyb_timer_obj_t type of the timer.
I want to do the following in c:
[code]
timer = pyb.Timer(x, freq=y)
[/code]
after init I want to access the number of the timer. I thought the tim_id variable stores it but I can't get the init done.
If i modyfy the timer.h and the timer.c I can declare the timer but can't access the variables in it after initialisation. So I thought there must be another way to declare and init a Timer.
There's plenty of examples of initializing timers.
https://github.com/micropython/micropyt ... r_make_new
What specifically do you need to do?
[/quote]
Hi jickster,
thanks for your repl.
I know there is the make_new method in each objekt. But I can't access the pyb_timer_obj_t type of the timer.
I want to do the following in c:
[code]
timer = pyb.Timer(x, freq=y)
[/code]
after init I want to access the number of the timer. I thought the tim_id variable stores it but I can't get the init done.
If i modyfy the timer.h and the timer.c I can declare the timer but can't access the variables in it after initialisation. So I thought there must be another way to declare and init a Timer.
Re: Get an Instance of a Timer
Scalli wrote: ↑Thu Jul 19, 2018 5:42 amHi jickster,jickster wrote: ↑Wed Jul 18, 2018 5:34 pmThere's plenty of examples of initializing timers.
https://github.com/micropython/micropyt ... r_make_new
What specifically do you need to do?
thanks for your repl.
I know there is the make_new method in each objekt. But I can't access the pyb_timer_obj_t type of the timer.
I want to do the following in c:after init I want to access the number of the timer. I thought the tim_id variable stores it but I can't get the init done.Code: Select all
timer = pyb.Timer(x, freq=y)
If i modyfy the timer.h and the timer.c I can declare the timer but can't access the variables in it after initialisation. So I thought there must be another way to declare and init a Timer.
Code: Select all
mp_obj_t TimerInit(uint8_t uint8TimerNum)
{
mp_obj_t args[1];
args[0] = MP_OBJ_NEW_SMALL_INT(uint8TimerNum);
return pyb_timer_type.make_new(NULL, 1, 0, args);
}
pyb_timer_obj_t *tim = MP_OBJ_TO_PTR(TimerInit(0));
Re: Get an Instance of a Timer
Hey jickster,
thanks a lot for your time.
I tryed to copy your code into my moule,
but I get a "unknown type name 'pyb_timer_obj_t'" Compiler Error.
I've included the following files:
could you help me?
thanks a lot for your time.
I tryed to copy your code into my moule,
but I get a "unknown type name 'pyb_timer_obj_t'" Compiler Error.
I've included the following files:
Code: Select all
#include "py/mpconfig.h"
#include "py/nlr.h"
#include "py/misc.h"
#include "py/qstr.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "py/objmodule.h"
#include <stdio.h>
(#include "uart.h")
#include "timer.h"
Re: Get an Instance of a Timer
In the example code, "pyb_timer_obj_t" is only defined in .c filesScalli wrote: ↑Fri Jul 20, 2018 8:48 amHey jickster,
thanks a lot for your time.
I tryed to copy your code into my moule,
but I get a "unknown type name 'pyb_timer_obj_t'" Compiler Error.
I've included the following files:could you help me?Code: Select all
#include "py/mpconfig.h" #include "py/nlr.h" #include "py/misc.h" #include "py/qstr.h" #include "py/obj.h" #include "py/runtime.h" #include "py/mphal.h" #include "py/objmodule.h" #include <stdio.h> (#include "uart.h") #include "timer.h"
https://github.com/micropython/micropyt ... imer_obj_t
so including the .h files does nothing.
Re: Get an Instance of a Timer
Oh, I forgot that.
How can I access the pyb_timer_obj then?
edit:
I tryed to modify the timer code so the obj is now public:
timer.h:
and the needed change in the timer.c.
I have access to the timer obj. now, but now i get the following error:
With the following code:
How can I access the pyb_timer_obj then?
edit:
I tryed to modify the timer code so the obj is now public:
timer.h:
Code: Select all
typedef struct _pyb_timer_obj_t pyb_timer_obj_t
I have access to the timer obj. now, but now i get the following error:
Code: Select all
"dereferencing pointer to incomplete type 'pyb_timer_obj_t {aka struct _pyb_timer_obj_t}"
Code: Select all
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
printf("timer ID: %d", self->tim_id);
Re: Get an Instance of a Timer
What is the task you're trying to do?Scalli wrote: ↑Mon Jul 23, 2018 5:50 amOh, I forgot that.
How can I access the pyb_timer_obj then?
edit:
I tryed to modify the timer code so the obj is now public:
timer.h:and the needed change in the timer.c.Code: Select all
typedef struct _pyb_timer_obj_t pyb_timer_obj_t
I have access to the timer obj. now, but now i get the following error:With the following code:Code: Select all
"dereferencing pointer to incomplete type 'pyb_timer_obj_t {aka struct _pyb_timer_obj_t}"
Code: Select all
pyb_timer_obj_t *self = MP_OBJ_TO_PTR(self_in); printf("timer ID: %d", self->tim_id);
Re: Get an Instance of a Timer
At the moment Im playing around and try to understand how the MircoPython Objekts work.
Re: Get an Instance of a Timer
OK I fond it out by myself,
I cut and past the definition of _pyb_timer_obj_t into the Timer.
If Somebody have a better Solution please tell me.
I don't want to change the HAL of the firmware because of my module.
I cut and past the definition of _pyb_timer_obj_t into the Timer.
If Somebody have a better Solution please tell me.
I don't want to change the HAL of the firmware because of my module.