Hello everybody, i make good progress with chibios and i like it.
Now i am programming a universal button and rotary encoder driver without the use of interrupts.
I create a thread which reads the button input pins. There is my problem. I have a pointer to a struct which i want to pass to the THD_FUNCTION as argument. Now i do:
whre rotp is the struct of type ROTARYDriver .
struct ROTARYDriver {
rot_state_t state;
const ROTARYConfig *config;
};
void rotaryStart(ROTARYDriver *rotp, const ROTARYConfig *config) //Start the Rotary Driver
{
...configuration of inputs....
chThdCreateStatic(waButtonReadThread, sizeof(waButtonReadThread), NORMALPRIO + 5, ButtonReadThread, &rotp); //Start the Thread which reads the inputs
}
and in:
static THD_FUNCTION(ButtonReadThread, arg)
{
BUTTON = palReadLine(rotp->config->pinmap->BTN); // Here is the Problem. I need a connection from "arg" to "rotp" and i don't know how
}
This is basic C-Programming knowledge and not necessarily STM32 or Chibios but maybe somebody can help.
Need little help with pointer
Moderators: RoccoMarco, barthess
Need little help with pointer
- Attachments
-
- NUCLEO-STM32F411RE-USB-Rotary.zip
- (21.88 KiB) Downloaded 145 times
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Need little help with pointer
Hi,
In the thread:
struct ROTARYDriver rotp = (struct ROTARYDriver *)arg;
and you have your pointer back.
Giovanni
In the thread:
struct ROTARYDriver rotp = (struct ROTARYDriver *)arg;
and you have your pointer back.
Giovanni
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Need little help with pointer
I missed a *
struct ROTARYDriver *rotp = (struct ROTARYDriver *)arg;
Giovanni
struct ROTARYDriver *rotp = (struct ROTARYDriver *)arg;
Giovanni
Re: Need little help with pointer
I found the solution:
I was wrong giving the address to the thread.
chThdCreateStatic(waButtonReadThread, sizeof(waButtonReadThread), NORMALPRIO + 5, ButtonReadThread, rotp);
is correct.
In the Thread:
struct ROTARYDriver *rotp = (struct ROTARYDriver *)arg;
and:
BUTTON = palReadLine(rotp->config->pinmap->BTN);
That works.
Thanks for pointing me in the right direction.
I was wrong giving the address to the thread.
chThdCreateStatic(waButtonReadThread, sizeof(waButtonReadThread), NORMALPRIO + 5, ButtonReadThread, rotp);
is correct.
In the Thread:
struct ROTARYDriver *rotp = (struct ROTARYDriver *)arg;
and:
BUTTON = palReadLine(rotp->config->pinmap->BTN);
That works.
Thanks for pointing me in the right direction.
Who is online
Users browsing this forum: No registered users and 28 guests