About adi_gpio_RegisterCallback()

ADI_GPIO_RESULT adi_gpio_RegisterCallback(
         ADI_GPIO_PORT const ePort,
         uint32_t const Pins,
         ADI_GPIO_CALLBACK const pfCallback,
         void * const pCBParam
     );

I understand the third parameter in this function, which is the callback function.

But I don't understand the fourth parameter in this function, what is it used to implement, and how to use it in interrupt

  • 0
    •  Analog Employees 
    on Apr 8, 2021 2:17 PM 2 days ago

    Hi,

    pCBParam is the application provided callback parameter which will be passed back to the application in the callback.
    Since pCBParam is void parameter, you can provide any data type.
    For example:
    typedef enum GPIO_Interrupts
    {
    MyGPIO_1=1,
    MyGPIO_2,
    MyGPIO_3
    }Interrupts;


    adi_gpio_RegisterCallback(PUSH_BUTTON1_PINT,PUSH_BUTTON1_PINT_PIN,gpioCallback,(void*)MyGPIO_1);
    adi_gpio_RegisterCallback(PUSH_BUTTON2_PINT,PUSH_BUTTON2_PINT_PIN,gpioCallback,(void*)MyGPIO_2);

    void gpioCallback(ADI_GPIO_PIN_INTERRUPT ePinInt, uint32_t Data, void *pCBParam)
    {
    Interrupts name=(Interrupts)pCBParam;
    if(name==MyGPIO_1)
    {
    if (ePinInt == PUSH_BUTTON1_PINT)
    {
    if (Data & PUSH_BUTTON1_PINT_PIN)
    {
    /* push button 1 - toggle LED */
    adi_gpio_Toggle(LED1_PORT, LED1_PIN);
    }
    }
    }
    if(name==MyGPIO_2)
    {
    if (ePinInt == PUSH_BUTTON2_PINT)
    {
    if (Data & PUSH_BUTTON2_PINT_PIN)
    {
    /* push button 2 - toggle LED */
    adi_gpio_Toggle(LED2_PORT, LED2_PIN);
    }
    }
    }

    /* reset the exit counter */
    count = 0u;
    }

    Above provided one is based on Button_LED_GPIO BSP example.

    Hope this will help you.

    Best Regards,

    Santhakumari.K