#Pointer to instance function callback

7 messages · Page 1 of 1 (latest)

shy bobcat
#

I have recently started learning c++ to control a raspberry pi pico and i am at a roadblock, hear me out:
i need to pass a pointer to gpio_irq_callback_t (AKA "void (*gpio_irq_callback_t)(uint gpio, uint32_t event_mask)" in the Pico SDK) as a parameter
example
forgive this pseudo code :

class B(...)
(static) void B::SetButtonCallBack(unknown parameters)
{
    gpio_irq_callback_t test = unknown process;
}
class A (...)
void A::ButtonCallBack(uint gpio, uint32_t events);
A::A()
{
//here if it was as i had before separating classes it would be simply
  B::SetButtonCallBack(&ButtonCallback);
//I understand i need to pass a reference to the instance as well so i am assuming i need at least:
  B::SetButtonCallBack(this, &ButtonCallback);
}

I have been "fighting" with copilot AI for a while but it circles back to the same answers and it looks way to complex and doesnt even compile. does this have a simple answer?

weak krakenBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

gleaming lintel
#

Though there such a thing as pointer to an instance function, those cannot be converted to C-like function pointers

#

gpio_irq_callback_t is a pointer to a free standing function.

#

I don't have enough details about what you want and/or expect to happen to say anything more

shy bobcat
#

thanks i eventually figured that out and solved by using static functions and using the gpio pin to get the instance i needed to modify

#

!solved