This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why doesn't the nRF-SDK SPIM callback have a context parameter like the IIC callback does?

I'm wondering whether I'm missing something.

This is the callback called from finish_transfer in both nrf_drv_spi.c and nrf_drv_twi.c.

This parameter is useful because it can be used to let me know which SPIM instance completed the transaction.

Since SPIM does not have that parameter, I will have to assume that any of the active SPIM peripherals completed the transaction.

Parents
  • True - not hard to work around though. Just write a generic function in your code which does take an instance, eg

    void my_cb_handler( nrf_drv_spi_evt_t const * evt, int instance );
    

    then write an actual callback handler for each actual instance you want to use

    void cb_handler_0( nrf_drv_spi_evt_t const * evt )
    {
        my_cb_handler( evt, 0 );
    }
    
    void cb_handler_1( nrf_drv_spi_evt_t const * evt )
    {
        my_cb_handler( evt, 1 );
    }
    

    and then register each corresponding handler when you register that peripheral. It calls your specific handler, your handler calls the generic handler with the instance number. Now you can have one single instance-aware handler.

Reply
  • True - not hard to work around though. Just write a generic function in your code which does take an instance, eg

    void my_cb_handler( nrf_drv_spi_evt_t const * evt, int instance );
    

    then write an actual callback handler for each actual instance you want to use

    void cb_handler_0( nrf_drv_spi_evt_t const * evt )
    {
        my_cb_handler( evt, 0 );
    }
    
    void cb_handler_1( nrf_drv_spi_evt_t const * evt )
    {
        my_cb_handler( evt, 1 );
    }
    

    and then register each corresponding handler when you register that peripheral. It calls your specific handler, your handler calls the generic handler with the instance number. Now you can have one single instance-aware handler.

Children
No Data
Related