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

Header file app_usbd_cdc_acm.h

Hi everyone,

In the file header "app_usbd_cdc_acm.h" I notice this function:

/**
* @brief Helper function to get class instance from CDC ACM class.
*
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
*
* @return Base class instance.
*/
static inline app_usbd_class_inst_t const *
app_usbd_cdc_acm_class_inst_get(app_usbd_cdc_acm_t const * p_cdc_acm)
{
return &p_cdc_acm->base;
}

What does it means " Base class instance"? What's a base class instance? I don't understand what the function is defined for.

Can anyone help me?

BR

Parents
  • Hi Alex

    Similar to other SDK libraries the USB libraries are based on an object oriented programming principle, but since C is not really an object oriented language instance structs are used instead of classes/objects. 

    The instance struct will contain information related to that particular object. In the case of the USBD classes this is mainly the different data buffers and function pointers used by that particular USB class. 

    This allows you to more easily create USB applications that combine multiple USB classes, and as an example it is possible to instantiate two CDC classes if you need two virtual comports, or combine different USB classes like CDC and MSC in the same example. 

    More concretely you typically need to pass a pointer to the class instance every time you interact with the USBD library, to tell the library which particular instance you are performing an action on. 

    Whenever you get a callback from the USB library you will also be provided a pointer to the class instance, so you know which one that particular event was related to. 

    Best regards
    Torbjørn

Reply
  • Hi Alex

    Similar to other SDK libraries the USB libraries are based on an object oriented programming principle, but since C is not really an object oriented language instance structs are used instead of classes/objects. 

    The instance struct will contain information related to that particular object. In the case of the USBD classes this is mainly the different data buffers and function pointers used by that particular USB class. 

    This allows you to more easily create USB applications that combine multiple USB classes, and as an example it is possible to instantiate two CDC classes if you need two virtual comports, or combine different USB classes like CDC and MSC in the same example. 

    More concretely you typically need to pass a pointer to the class instance every time you interact with the USBD library, to tell the library which particular instance you are performing an action on. 

    Whenever you get a callback from the USB library you will also be provided a pointer to the class instance, so you know which one that particular event was related to. 

    Best regards
    Torbjørn

Children
No Data
Related