nRF5 SDK v17.1.0
Data Structures | Macros | Functions
USBD Class Base module

nRF52840 only: The base for any class instance is defined in this module. More...

Data Structures

struct  app_usbd_class_ep_conf_t
 Endpoint configuration. More...
 
struct  app_usbd_class_iface_conf_t
 Interface configuration. More...
 
struct  app_usbd_class_data_t
 Instance variable data. More...
 
struct  app_usbd_class_descriptor_ctx_t
 Class descriptor context. More...
 
struct  app_usbd_class_descriptor_state_t
 Class descriptor state. More...
 
struct  app_usbd_class_methods_t
 Class interface function set. More...
 
struct  app_usbd_class_inst_s
 The instance structure itself. More...
 

Macros

#define APP_USBD_CLASS_INSTANCE_TYPE(type_name)   CONCAT_2(type_name, _t)
 USBD instance of class mnemonic. More...
 
#define APP_USBD_CLASS_DATA_TYPE(type_name)   CONCAT_2(type_name, _data_t)
 USBD data for instance class mnemonic. More...
 
#define APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC(type)   type class_part;
 Declare class specific member of class instance. More...
 
#define APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
 Used if there is no class specific configuration. More...
 
#define APP_USBD_CLASS_DATA_SPECIFIC_DEC(type)   APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC(type)
 Declare class specific member of class data. More...
 
#define APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE   APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
 Used if there is no class specific data. More...
 
#define APP_USBD_CLASS_INSTANCE_TYPEDEF(type_name, interfaces_configs, class_config_dec)
 Instance structure declaration. More...
 
#define APP_USBD_CLASS_INSTANCE_NO_EP_TYPEDEF(type_name, interfaces_configs, class_config_dec)
 Same as APP_USBD_CLASS_INSTANCE_TYPEDEF but for class with EP0 only. More...
 
#define APP_USBD_CLASS_DATA_TYPEDEF(type_name, class_data_dec)
 Writable data structure declaration. More...
 
#define APP_USBD_CLASS_TYPEDEF(type_name, interface_configs, class_config_dec, class_data_dec)
 Declare all data types required by the class instance. More...
 
#define APP_USBD_CLASS_NO_EP_TYPEDEF(type_name,interface_configs,class_config_dec,class_data_dec)
 Same as APP_USBD_CLASS_TYPEDEF but for class with EP0 only. More...
 
#define APP_USBD_CLASS_FORWARD(type_name)   union CONCAT_2(type_name, _u)
 Forward declaration of type defined by APP_USBD_CLASS_TYPEDEF. More...
 
#define APP_USBD_CLASS_INSTANCE_INITVAL(p_ram_data,class_methods,interfaces_configs,class_config_part)
 Generate the initialization data for. More...
 
#define APP_USBD_CLASS_INSTANCE_NO_EP_INITVAL(p_ram_data,class_methods,interfaces_configs,class_config_part)
 Same as APP_USBD_CLASS_INSTANCE_INITVAL but for class with EP0 only. More...
 
#define APP_USBD_CLASS_INST_DEF(instance_name,type_name,class_methods,interfaces_configs,class_config_part)
 Define the base class instance. More...
 
#define APP_USBD_CLASS_INST_GLOBAL_DEF(instance_name,type_name,class_methods,interfaces_configs,class_config_part)
 Define the base class instance in global scope. More...
 
#define APP_USBD_CLASS_INST_NO_EP_GLOBAL_DEF(instance_name,type_name,class_methods,interfaces_configs,class_config_part)
 Same as APP_USBD_CLASS_INST_GLOBAL_DEF but for class with EP0 only. More...
 
#define APP_USBD_CLASS_GET_SPECIFIC_CONFIG(p_inst)   (&((p_inst)->specific.class_part))
 Access class specific configuration. More...
 
#define APP_USBD_CLASS_GET_SPECIFIC_DATA(p_inst)   (&(((p_inst)->specific.p_data)->class_part))
 Access class specific data. More...
 
#define APP_USBD_CLASS_BASE_INSTANCE(p_inst)   (&((p_inst)->base))
 Macro to get base instance from class specific instance. More...
 
#define APP_USBD_CLASS_DESCRIPTOR_INIT(p_ctx)   (p_ctx)->line = 0;
 Initialize class descriptor. More...
 
#define APP_USBD_CLASS_DESCRIPTOR_BEGIN(p_ctx, p_buff, max_size)
 Begin class descriptor. More...
 
#define APP_USBD_CLASS_DESCRIPTOR_YIELD()
 Yield class descriptor. More...
 
#define APP_USBD_CLASS_DESCRIPTOR_END()
 End class descriptor. More...
 
#define APP_USBD_CLASS_DESCRIPTOR_WRITE(data)
 Write descriptor using protothreads. More...
 

Functions

static uint8_t app_usbd_class_iface_count_get (app_usbd_class_inst_t const *const p_inst)
 Get total number of interfaces.
 
static
app_usbd_class_iface_conf_t
const * 
app_usbd_class_iface_get (app_usbd_class_inst_t const *const p_inst, uint8_t iface_idx)
 Interface accessing function. More...
 
static uint8_t app_usbd_class_iface_number_get (app_usbd_class_iface_conf_t const *const p_iface)
 Get interface number. More...
 
static uint8_t app_usbd_class_iface_ep_count_get (app_usbd_class_iface_conf_t const *const p_iface)
 Get number of endpoints in interface. More...
 
static
app_usbd_class_ep_conf_t const * 
app_usbd_class_iface_ep_get (app_usbd_class_iface_conf_t const *const p_iface, uint8_t ep_idx)
 Interface Endpoint accessing function. More...
 
static uint8_t app_usbd_class_iface_ep_idx_get (app_usbd_class_iface_conf_t const *const p_iface, nrf_drv_usbd_ep_t ep_address)
 Translate endpoint address to class index. More...
 
static nrf_drv_usbd_ep_t app_usbd_class_ep_address_get (app_usbd_class_ep_conf_t const *p_ep)
 Get the selected endpoint address. More...
 
static app_usbd_class_data_tapp_usbd_class_data_access (app_usbd_class_inst_t const *const p_inst)
 Get the pointer to the writable instance data. More...
 

Internal macros for argument mapping

Functions to be used as a mapping macro for MACRO_MAP, MACRO_MAP_FOR or MACRO_MAP_FOR_PARAM

#define APP_USBD_CLASS_CONF_IFACE_EP_COUNT_(iface_config)   (NUM_VA_ARGS(BRACKET_EXTRACT(iface_config)) - 1)
 Count the number of endpoints in given configuration. More...
 
#define APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_(iface_config)   + APP_USBD_CLASS_CONF_IFACE_EP_COUNT_(iface_config)
 Adds the number of endpoints in given config to the current value. More...
 
#define APP_USBD_CLASS_IFACE_EP_EXTRACT_(iface_config)
 Create variable for endpoint. More...
 
#define APP_USBD_CLASS_IFACE_EP_EXTRACT_0(iface_nr)
 Auxiliary macro for APP_USBD_CLASS_IFACE_EP_EXTRACT_. More...
 
#define APP_USBD_CLASS_IFACE_EP_EXTRACT_1(...)   APP_USBD_CLASS_IFACE_EP_EXTRACT_1_(__VA_ARGS__)
 Auxiliary macro for APP_USBD_CLASS_IFACE_EP_EXTRACT_. More...
 
#define APP_USBD_CLASS_IFACE_EP_EXTRACT_1_(iface_nr,...)   MACRO_MAP_REC(APP_USBD_CLASS_IFACE_EP_EXTRACT_1__, __VA_ARGS__)
 
#define APP_USBD_CLASS_IFACE_EP_EXTRACT_1__(ep)   {(nrf_drv_usbd_ep_t) (ep)},
 
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_(iface_config, N, iface_configs)
 Generate configuration for single interface. More...
 
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_x(iface_config, N, iface_configs)   [N] = !!!iface_config!!!
 Macro used when there was an error extracting number of configs. More...
 
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0(N, iface_configs, iface_nr)   APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0_(N, iface_configs, iface_nr)
 Auxiliary macro for APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_. More...
 
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0_(N, iface_configs, iface_nr)   { .number = iface_nr, .ep_cnt = 0, .ep_offset = 0 },
 
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1(N, iface_configs,...)   APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1_(N, iface_configs, __VA_ARGS__)
 Auxiliary macro for APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_. More...
 
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1_(N, iface_configs, iface_nr,...)
 

Macros that uses mapping macros internally

Auxiliary macros that uses mapping macros to make some calculations or realize other functionality. Mapped here for easier unit testing and to hide complex mapping functions calling.

#define APP_USBD_CLASS_CONF_TOTAL_EP_COUNT(iface_configs)   (0 MACRO_MAP(APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_, BRACKET_EXTRACT(iface_configs)))
 Count total number of endpoints. More...
 
#define APP_USBD_CLASS_CONF_TOTAL_EP_COUNT_N(N, iface_configs)   (0 MACRO_MAP_N(N, APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_, BRACKET_EXTRACT(iface_configs)))
 Count total number of endpoint up-to interface index. More...
 
#define APP_USBD_CLASS_IFACES_CONFIG_EXTRACT(iface_configs)
 Extract configurations for interfaces. More...
 
#define APP_USBD_CLASS_IFACES_EP_EXTRACT(iface_configs)   MACRO_MAP(APP_USBD_CLASS_IFACE_EP_EXTRACT_, BRACKET_EXTRACT(iface_configs))
 Extract all endpoints. More...
 

Detailed Description

nRF52840 only: The base for any class instance is defined in this module.

Any class instance must start from base class instance structure. This makes them compatible with USBD library independently of the implementation details.

Macro Definition Documentation

#define APP_USBD_CLASS_BASE_INSTANCE (   p_inst)    (&((p_inst)->base))

Macro to get base instance from class specific instance.

This macro may be used on class specific instance to get base instance that can be processed by base instance access functions. Class specific instance can be just casted to class base instance, but then we would totally lost type safety.

A little more safe is to use pointer to base member of class instance. This would generate an error when used on any variable that has no base member and would generate also error if this base member is wrong type.

#define APP_USBD_CLASS_CONF_IFACE_EP_COUNT_ (   iface_config)    (NUM_VA_ARGS(BRACKET_EXTRACT(iface_config)) - 1)

Count the number of endpoints in given configuration.

Config should be given as a interface configuration in a brackets:

(interface_nr, ep1, ep2, ep3)

Number of endpoints may vary from 0 to a few (technically up to 16, but it seems not to make sense to use more than 4). Interface number is always present.

Parameters
iface_configSingle interface configuration (in brackets).
Returns
Number of endpoints in interface. This is computed value - can be used by compiler but not by preprocessor.
#define APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_ (   iface_config)    + APP_USBD_CLASS_CONF_IFACE_EP_COUNT_(iface_config)

Adds the number of endpoints in given config to the current value.

This is basically APP_USBD_CLASS_CONF_IFACE_EP_COUNT_ with plus sign added.

Parameters
iface_configSee parameters documentation in APP_USBD_CLASS_CONF_IFACE_EP_COUNT_
Returns
Plus sign followed by number of endpoints in interface.
See Also
APP_USBD_CLASS_CONF_IFACE_EP_COUNT_
#define APP_USBD_CLASS_CONF_TOTAL_EP_COUNT (   iface_configs)    (0 MACRO_MAP(APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_, BRACKET_EXTRACT(iface_configs)))

Count total number of endpoints.

Parameters
iface_configsList of interface configurations like explained in documentation for APP_USBD_CLASS_INSTANCE_TYPEDEF
Returns
The equation to calculate the number of endpoints by compiler.
#define APP_USBD_CLASS_CONF_TOTAL_EP_COUNT_N (   N,
  iface_configs 
)    (0 MACRO_MAP_N(N, APP_USBD_CLASS_CONF_IFACE_EP_PLUS_COUNT_, BRACKET_EXTRACT(iface_configs)))

Count total number of endpoint up-to interface index.

The version of APP_USBD_CLASS_CONF_TOTAL_EP_COUNT macro which takes the number of interfaces to analyze.

Parameters
NNumber of interfaces to analyze.
iface_configsList of interface configurations like explained in documentation for APP_USBD_CLASS_INSTANCE_TYPEDEF
Returns
The equation to calculate the number of endpoints by compiler.
#define APP_USBD_CLASS_DATA_SPECIFIC_DEC (   type)    APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC(type)

Declare class specific member of class data.

Parameters
typeType of the attached class data.
See Also
APP_USBD_CLASS_DATA_TYPEDEF
#define APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE   APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE

Used if there is no class specific data.

This constant can be used if there is no specific writable data inside created instance.

See Also
APP_USBD_CLASS_DATA_TYPEDEF
#define APP_USBD_CLASS_DATA_TYPE (   type_name)    CONCAT_2(type_name, _data_t)

USBD data for instance class mnemonic.

The mnemonic of the variable type that holds writable part of the class instance.

Parameters
type_nameThe name of the instance without _t postfix.
Returns
The name with the right postfix to create the name for the data type for the class.
#define APP_USBD_CLASS_DATA_TYPEDEF (   type_name,
  class_data_dec 
)
Value:
typedef struct \
{ \
class_data_dec \

Writable data structure declaration.

The macro that declares a variable type that would be used to store given class writable data. Writable data contains base part of the type app_usbd_class_data_t followed by class specific data.

Parameters
type_nameThe name of the type without _t postfix.
class_data_decResult of the macro APP_USBD_CLASS_DATA_SPECIFIC_DEC or APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE
Returns
The definition of the structure type that holds all the required writable data.
Note
It should not be used directly in the final application. See APP_USBD_CLASS_DATA_TYPEDEF instead.
See Also
APP_USBD_CLASS_TYPEDEF
#define APP_USBD_CLASS_DESCRIPTOR_BEGIN (   p_ctx,
  p_buff,
  max_size 
)
Value:
ASSERT((p_ctx) != NULL); \
app_usbd_class_descriptor_state_t this_descriptor_feed; \
this_descriptor_feed.p_buffer = (p_buff); \
this_descriptor_feed.current_size = 0; \
this_descriptor_feed.maximum_size = (max_size); \
this_descriptor_feed.p_context = (p_ctx); \
switch ((this_descriptor_feed.p_context)->line) \
{ \
case 0: \
;

Begin class descriptor.

Parameters
[in]p_ctxClass descriptor context.
[in]p_buffBuffer to write into.
[in]max_sizeSize of the buffer.
#define APP_USBD_CLASS_DESCRIPTOR_END ( )
Value:
} \
(this_descriptor_feed.p_context)->line = 0; \
return false;

End class descriptor.

This function has to be called at the end of class descriptor feeder function. No other operations in feeder function can be done after calling it.

#define APP_USBD_CLASS_DESCRIPTOR_INIT (   p_ctx)    (p_ctx)->line = 0;

Initialize class descriptor.

Parameters
[in]p_ctxClass descriptor context.
#define APP_USBD_CLASS_DESCRIPTOR_WRITE (   data)
Value:
do \
{ \
(this_descriptor_feed.p_context)->data_buffer = (data); \
if (this_descriptor_feed.current_size >= this_descriptor_feed.maximum_size) \
{ \
APP_USBD_CLASS_DESCRIPTOR_YIELD(); \
} \
if(this_descriptor_feed.p_buffer != NULL) \
{ \
*(this_descriptor_feed.p_buffer + this_descriptor_feed.current_size) = \
(this_descriptor_feed.p_context)->data_buffer; \
} \
this_descriptor_feed.current_size++; \
} while(0);

Write descriptor using protothreads.

This function writes one byte to the buffer with offset. If buffer is full it yields.

It is used by the class descriptor feeders internally.

APP_USBD_CLASS_DESCRIPTOR_BEGIN has to be called before using this function. APP_USBD_CLASS_DESCRIPTOR_END has to be called after last use of this function.

Parameters
dataByte to be written to buffer.
#define APP_USBD_CLASS_DESCRIPTOR_YIELD ( )
Value:
do \
{ \
(this_descriptor_feed.p_context)->line = __LINE__; \
return true; \
case __LINE__: \
; \
} while (0)

Yield class descriptor.

#define APP_USBD_CLASS_FORWARD (   type_name)    union CONCAT_2(type_name, _u)

Forward declaration of type defined by APP_USBD_CLASS_TYPEDEF.

Parameters
type_nameThe name of the type without _t postfix.
#define APP_USBD_CLASS_GET_SPECIFIC_CONFIG (   p_inst)    (&((p_inst)->specific.class_part))

Access class specific configuration.

Macro that returns class specific configuration.

Parameters
[in]p_instInstance pointer.
Returns
A pointer for class specific part of the instance.
Note
If macro is used on the instance that has no class specific configuration an error would be generated during compilation.
#define APP_USBD_CLASS_GET_SPECIFIC_DATA (   p_inst)    (&(((p_inst)->specific.p_data)->class_part))

Access class specific data.

Parameters
[in]p_instInstance pointer.
Returns
A pointer for class specific part of writable data.
Note
If macro is used on the instance that has no class specific data an error would be generated during compilation.
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_ (   iface_config,
  N,
  iface_configs 
)
Value:

Generate configuration for single interface.

This macro extract configuration for single interface. The configuration is inside curly brackets and comma is added on the end. This mean it can be directly used to init array of interface configurations.

Parameters
iface_configSingle interface configuration.
NCurrently processed configuration.
iface_configsAll interfaces configuration in brackets.
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0 (   N,
  iface_configs,
  iface_nr 
)    APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_0_(N, iface_configs, iface_nr)

Auxiliary macro for APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_.

This macro is called when interface has no endpoints.

#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1 (   N,
  iface_configs,
  ... 
)    APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1_(N, iface_configs, __VA_ARGS__)

Auxiliary macro for APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_.

This macro is called when interface has at last one endpoint.

#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_1_ (   N,
  iface_configs,
  iface_nr,
  ... 
)
Value:
{ .number = iface_nr, .ep_cnt = NUM_VA_ARGS(__VA_ARGS__), \
.ep_offset = APP_USBD_CLASS_CONF_TOTAL_EP_COUNT_N(N, iface_configs) * \
+ ((NUM_VA_ARGS(BRACKET_EXTRACT(iface_configs)) - N) * \
},
#define APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_x (   iface_config,
  N,
  iface_configs 
)    [N] = !!!iface_config!!!

Macro used when there was an error extracting number of configs.

Throws a syntax error.

#define APP_USBD_CLASS_IFACE_EP_EXTRACT_ (   iface_config)
Value:

Create variable for endpoint.

Extract endpoints given interface configuration.

This macro gets single endpoint configuration and extracts all the endpoints. It also adds comma on the end of extracted endpoints. This way when this macro is called few times it generates nice list of all endpoints that may be used to array initialization.

Parameters
iface_configSingle interface configuration in brackets. The format should be similar like described in APP_USBD_CLASS_CONF_IFACE_EP_COUNT_.
#define APP_USBD_CLASS_IFACE_EP_EXTRACT_0 (   iface_nr)

Auxiliary macro for APP_USBD_CLASS_IFACE_EP_EXTRACT_.

This macro is called when interface has no endpoints.

#define APP_USBD_CLASS_IFACE_EP_EXTRACT_1 (   ...)    APP_USBD_CLASS_IFACE_EP_EXTRACT_1_(__VA_ARGS__)

Auxiliary macro for APP_USBD_CLASS_IFACE_EP_EXTRACT_.

This macro is called when interface has at least one endpoint.

#define APP_USBD_CLASS_IFACES_CONFIG_EXTRACT (   iface_configs)
Value:

Extract configurations for interfaces.

This macro extracts the configurations for every interface. Basically uses the APP_USBD_CLASS_IFACE_CONFIG_EXTRACT_ macro on every configuration found.

This should generate interface configuration initialization data in comma separated initializers in curly braces.

Parameters
iface_configsList of interface configurations like explained in documentation for APP_USBD_CLASS_INSTANCE_TYPEDEF
Returns
Comma separated initialization data for all interfaces.
#define APP_USBD_CLASS_IFACES_EP_EXTRACT (   iface_configs)    MACRO_MAP(APP_USBD_CLASS_IFACE_EP_EXTRACT_, BRACKET_EXTRACT(iface_configs))

Extract all endpoints.

Macro that extracts all endpoints from every interface.

Parameters
iface_configsList of interface configurations like explained in documentation for APP_USBD_CLASS_INSTANCE_TYPEDEF
Returns
Comma separated list of endpoints.
#define APP_USBD_CLASS_INST_DEF (   instance_name,
  type_name,
  class_methods,
  interfaces_configs,
  class_config_part 
)
Value:
static APP_USBD_CLASS_DATA_TYPE(type_name) CONCAT_2(instance_name, _data); \
static const APP_USBD_CLASS_INSTANCE_TYPE(type_name) instance_name = \
&CONCAT_2(instance_name, _data), \
class_methods, \
interfaces_configs, \
class_config_part)

Define the base class instance.

Macro that defines whole instance variable and fill it with initialization data.

The tricky part is class_config_part. The configuration data here has to be placed inside brackets. Then any type of values can be used depending on the type used in APP_USBD_CLASS_TYPEDEF. If instance does not has any specyfic data, use just empty bracket here.

some_base_class,
CLASS_BASE_CONFIGURATION,
);
some_base_class_inst,
some_base_class,
base_class_event_handler,
CLASS_BASE_CONFIGURATION,
() // Empty configuration
);

If the type of instance configuration is simple type, just provide initialization value:

some_base_class,
CLASS_BASE_CONFIGURATION,
);
some_base_class_inst,
some_base_class,
base_class_event_handler,
CLASS_BASE_CONFIGURATION,
(12) // Example values
);

If the type of instance configuration is structure, provide initialization value for the whole structure:

typedef structure
{
uint32_t p1;
uint8_t p2;
}my_config_t;
some_base_class,
CLASS_BASE_CONFIGURATION,
);
some_base_class_inst,
some_base_class,
base_class_event_handler,
CLASS_BASE_CONFIGURATION,
({12, 3}) // Example values
);
Parameters
instance_nameThe name of created instance variable. It would be constant variable and its type would be app_usbd_class_inst_t.
type_nameThe name of the variable type. It has to be the same type that was passed to APP_USBD_CLASS_TYPEDEF
class_methodsClass unified interface.
interfaces_configsThe same configuration data that the one passed to APP_USBD_CLASS_TYPEDEF
class_config_partConfiguration data to the type that was declared by class_data_dec when calling APP_USBD_CLASS_TYPEDEF. Configuration data has to be provided in brackets. It would be extracted from brackets and placed in initialization part of configuration structure. See detailed description of this macro for more informations.
#define APP_USBD_CLASS_INST_GLOBAL_DEF (   instance_name,
  type_name,
  class_methods,
  interfaces_configs,
  class_config_part 
)
Value:
static APP_USBD_CLASS_DATA_TYPE(type_name) CONCAT_2(instance_name, _data); \
const APP_USBD_CLASS_INSTANCE_TYPE(type_name) instance_name = \
&CONCAT_2(instance_name, _data), \
class_methods, \
interfaces_configs, \
class_config_part)

Define the base class instance in global scope.

This is the same macro like APP_USBD_CLASS_INST_DEF but it creates the instance without static keyword.

Parameters
instance_nameSee documentation for APP_USBD_CLASS_INST_DEF
type_nameSee documentation for APP_USBD_CLASS_INST_DEF
class_methodsSee documentation for APP_USBD_CLASS_INST_DEF
interfaces_configsSee documentation for APP_USBD_CLASS_INST_DEF
class_config_partSee documentation for APP_USBD_CLASS_INST_DEF
#define APP_USBD_CLASS_INST_NO_EP_GLOBAL_DEF (   instance_name,
  type_name,
  class_methods,
  interfaces_configs,
  class_config_part 
)
Value:
static APP_USBD_CLASS_DATA_TYPE(type_name) CONCAT_2(instance_name, _data); \
const APP_USBD_CLASS_INSTANCE_TYPE(type_name) instance_name = \
&CONCAT_2(instance_name, _data), \
class_methods, \
interfaces_configs, \
class_config_part)

Same as APP_USBD_CLASS_INST_GLOBAL_DEF but for class with EP0 only.

#define APP_USBD_CLASS_INSTANCE_INITVAL (   p_ram_data,
  class_methods,
  interfaces_configs,
  class_config_part 
)
Value:
{ \
.specific = { \
.p_data = p_ram_data, \
.p_class_methods = class_methods, \
.iface = { \
.cnt = NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs)), \
.config = { APP_USBD_CLASS_IFACES_CONFIG_EXTRACT(interfaces_configs) }, \
.ep = { APP_USBD_CLASS_IFACES_EP_EXTRACT(interfaces_configs) } \
}, \
BRACKET_EXTRACT(class_config_part) \
} \
}

Generate the initialization data for.

Macro that generates the initialization data for instance.

Parameters
p_ram_dataPointer to writable instance data structure.
class_methodsClass methods.
interfaces_configsExactly the same interface config data that in APP_USBD_CLASS_INSTANCE_TYPEDEF
class_config_partConfiguration part. The data should be inside brackets. Any data here would be removed from brackets and then put as an initialization data for class_part member of instance structure.
Note
It should not be used directly in the final application. See APP_USBD_CLASS_INST_DEF instead.
#define APP_USBD_CLASS_INSTANCE_NO_EP_INITVAL (   p_ram_data,
  class_methods,
  interfaces_configs,
  class_config_part 
)
Value:
{ \
.specific = { \
.p_data = p_ram_data, \
.p_class_methods = class_methods, \
.iface = { \
.cnt = NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs)), \
.config = { APP_USBD_CLASS_IFACES_CONFIG_EXTRACT(interfaces_configs) } \
}, \
BRACKET_EXTRACT(class_config_part) \
} \
}

Same as APP_USBD_CLASS_INSTANCE_INITVAL but for class with EP0 only.

#define APP_USBD_CLASS_INSTANCE_NO_EP_TYPEDEF (   type_name,
  interfaces_configs,
  class_config_dec 
)
Value:
typedef union CONCAT_2(type_name, _u) \
{ \
struct \
{ \
APP_USBD_CLASS_DATA_TYPE(type_name) * p_data; \
app_usbd_class_methods_t const * p_class_methods; \
struct \
{ \
uint8_t cnt; \
app_usbd_class_iface_conf_t \
config[NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs))]; \
} iface; \
class_config_dec \
} specific; \

Same as APP_USBD_CLASS_INSTANCE_TYPEDEF but for class with EP0 only.

#define APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC (   type)    type class_part;

Declare class specific member of class instance.

Parameters
typeType of the attached class configuration.
See Also
APP_USBD_CLASS_INSTANCE_TYPEDEF
#define APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE

Used if there is no class specific configuration.

This constant can be used if there is no specific configuration inside created instance.

See Also
APP_USBD_CLASS_INSTANCE_TYPEDEF
#define APP_USBD_CLASS_INSTANCE_TYPE (   type_name)    CONCAT_2(type_name, _t)

USBD instance of class mnemonic.

Macro that generates mnemonic for the name of the structure that describes instance for selected class.

Parameters
type_nameThe name of the instance without _t postfix.
Returns
The name with the right postfix to create the name for the type for the class.
#define APP_USBD_CLASS_INSTANCE_TYPEDEF (   type_name,
  interfaces_configs,
  class_config_dec 
)
Value:
typedef union CONCAT_2(type_name, _u) \
{ \
struct \
{ \
APP_USBD_CLASS_DATA_TYPE(type_name) * p_data; \
app_usbd_class_methods_t const * p_class_methods; \
struct \
{ \
uint8_t cnt; \
app_usbd_class_iface_conf_t \
config[NUM_VA_ARGS(BRACKET_EXTRACT(interfaces_configs))]; \
app_usbd_class_ep_conf_t \
ep[APP_USBD_CLASS_CONF_TOTAL_EP_COUNT(interfaces_configs)]; \
} iface; \
class_config_dec \
} specific; \

Instance structure declaration.

The macro that declares a variable type that would be used to store given class instance. Class instance stores all the data from app_usbd_class_inst_t and overlaid data for specified class.

The structure of interface configuration data:

(
(iface1_nr, (ep1, ep2, ep3)),
(iface2_nr),
(iface3_nr, (ep4))
)
Parameters
type_nameThe name of the instance without _t postfix.
interfaces_configsList of interface configurations like explained above.
class_config_decResult of the macro APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC or APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
Returns
The definition of the structure type that holds all the required data.
Note
It should not be used directly in the final application. See APP_USBD_CLASS_DATA_TYPEDEF instead.
APP_USBD_CLASS_DATA_TYPEDEF has to be called first for the compilation to success.
See Also
APP_USBD_CLASS_TYPEDEF
#define APP_USBD_CLASS_NO_EP_TYPEDEF (   type_name,
  interface_configs,
  class_config_dec,
  class_data_dec 
)
Value:
APP_USBD_CLASS_DATA_TYPEDEF(type_name, class_data_dec); \
APP_USBD_CLASS_INSTANCE_NO_EP_TYPEDEF(type_name, interface_configs, class_config_dec)

Same as APP_USBD_CLASS_TYPEDEF but for class with EP0 only.

#define APP_USBD_CLASS_TYPEDEF (   type_name,
  interface_configs,
  class_config_dec,
  class_data_dec 
)
Value:
APP_USBD_CLASS_DATA_TYPEDEF(type_name, class_data_dec); \
APP_USBD_CLASS_INSTANCE_TYPEDEF(type_name, interface_configs, class_config_dec)

Declare all data types required by the class instance.

Macro that declares data type first and then instance type.

Parameters
type_nameThe name of the type without _t postfix.
interface_configsList of interface configurations like in APP_USBD_CLASS_INSTANCE_TYPEDEF.
class_config_decResult of the macro APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC or APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE
class_data_decResult of the macro APP_USBD_CLASS_DATA_SPECIFIC_DEC or APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE
Returns
Declaration of the data type for the instance and instance itself.
See Also
APP_USBD_CLASS_DATA_TYPEDEF
APP_USBD_CLASS_INSTANCE_TYPEDEF

Function Documentation

static app_usbd_class_data_t* app_usbd_class_data_access ( app_usbd_class_inst_t const *const  p_inst)
inlinestatic

Get the pointer to the writable instance data.

Parameters
p_instInstance pointer.
Returns
Pointer to writable instance data.
static nrf_drv_usbd_ep_t app_usbd_class_ep_address_get ( app_usbd_class_ep_conf_t const *  p_ep)
inlinestatic

Get the selected endpoint address.

Parameters
p_epEndpoint configuration structure.
Returns
Endpoint address
static uint8_t app_usbd_class_iface_ep_count_get ( app_usbd_class_iface_conf_t const *const  p_iface)
inlinestatic

Get number of endpoints in interface.

Parameters
p_ifacePointer to interface structure.
Returns
Number of endpoints used by given interface.
static app_usbd_class_ep_conf_t const* app_usbd_class_iface_ep_get ( app_usbd_class_iface_conf_t const *const  p_iface,
uint8_t  ep_idx 
)
inlinestatic

Interface Endpoint accessing function.

Parameters
p_ifaceInterface configuration pointer.
ep_idxEndpoint index.
Returns
Endpoint information structure pointer or NULL if given index is outside of endpoints for selected interface.
See Also
app_usbd_class_iface_get
static uint8_t app_usbd_class_iface_ep_idx_get ( app_usbd_class_iface_conf_t const *const  p_iface,
nrf_drv_usbd_ep_t  ep_address 
)
inlinestatic

Translate endpoint address to class index.

Parameters
p_ifaceInterface configuration pointer.
ep_addressEndpoint address.
Returns
Endpoint index or number of endpoints if not found.
static app_usbd_class_iface_conf_t const* app_usbd_class_iface_get ( app_usbd_class_inst_t const *const  p_inst,
uint8_t  iface_idx 
)
inlinestatic

Interface accessing function.

Get interface pointer. Interfaces create continuous array in the memory so it is possible to get interface with index 0 and then just iterate to the next one.

Parameters
p_instPointer to the class instance
iface_idxIndex of the instance to get. This is not the interface identifier. Technically it is the index of the interface in the class description array.
Returns
Pointer to the interface configuration parameters or NULL if given index is out of interface scope for given class.
static uint8_t app_usbd_class_iface_number_get ( app_usbd_class_iface_conf_t const *const  p_iface)
inlinestatic

Get interface number.

Parameters
p_ifacePointer to interface structure.
Returns
Interface number from interface configuration structure.

Documentation feedback | Developer Zone | Subscribe | Updated