nRF5 SDK v13.0.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions

nRF52840 only: Module with generic HID event data processing. More...

Modules

 USB HID class configuration
 
 USB HID class types
 nRF52840 only: Module with types and definitions used by HID modules.
 
 USB HID generic
 nRF52840 only: Module with types, definitions, and API used by the HID generic class.
 
 USB HID keyboard
 nRF52840 only: Module with types, definitions, and API used by the HID keyboard class.
 
 USB HID mouse
 nRF52840 only: Module with types, definitions, and API used by the HID mouse class.
 

Data Structures

struct  app_usbd_hid_methods_t
 HID unified interface. More...
 
struct  app_usbd_hid_report_buffer_t
 HID report buffers. More...
 
struct  app_usbd_hid_inst_t
 USB HID instance. More...
 
struct  app_usbd_hid_ctx_t
 HID internal context. More...
 

Macros

#define APP_USBD_HID_IFACE_IDX   0
 
#define APP_USBD_HID_EPIN_IDX   0
 
#define APP_USBD_HID_EPOUT_IDX   1
 
#define APP_USBD_HID_GENERIC_GLOBAL_OUT_REP_DEF(name, rep_size)
 Define OUT report buffer structure app_usbd_hid_report_buffer_t. More...
 
#define APP_USBD_HID_INST_CONFIG(descriptors,report_dsc,report_buff_in,report_buff_out,user_ev_handler,hid_methods)
 USB HID instance initializer app_usbd_hid_inst_t. More...
 

Typedefs

typedef void(* app_usbd_hid_user_ev_handler_t )(app_usbd_class_inst_t const *p_inst, app_usbd_hid_user_event_t event)
 User event handler. More...
 

Enumerations

enum  app_usbd_hid_state_flag_t {
  APP_USBD_HID_STATE_FLAG_APPENDED = 0,
  APP_USBD_HID_STATE_FLAG_STARTED = 1,
  APP_USBD_HID_STATE_FLAG_SUSPENDED = 2,
  APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS = 3
}
 HID context state flags. More...
 
enum  app_usbd_hid_user_event_t {
  APP_USBD_HID_USER_EVT_SET_BOOT_PROTO,
  APP_USBD_HID_USER_EVT_SET_REPORT_PROTO,
  APP_USBD_HID_USER_EVT_OUT_REPORT_READY,
  APP_USBD_HID_USER_EVT_IN_REPORT_DONE
}
 Events passed to user event handler. More...
 

Functions

static void app_usbd_hid_access_lock (app_usbd_hid_ctx_t *p_hid_ctx)
 Locks internal hid context. More...
 
static void app_usbd_hid_access_unlock (app_usbd_hid_ctx_t *p_hid_ctx)
 Unlocks internal hid context. More...
 
static bool app_usbd_hid_access_lock_test (app_usbd_hid_ctx_t *p_hid_ctx)
 Tests whether internal lock is acquired. More...
 
static void app_usbd_hid_state_flag_set (app_usbd_hid_ctx_t *p_hid_ctx, app_usbd_hid_state_flag_t flag)
 Set one of the HID internal state flags. More...
 
static void app_usbd_hid_state_flag_clr (app_usbd_hid_ctx_t *p_hid_ctx, app_usbd_hid_state_flag_t flag)
 Clear one of the HID internal state flags. More...
 
static bool app_usbd_hid_state_flag_test (app_usbd_hid_ctx_t *p_hid_ctx, app_usbd_hid_state_flag_t flag)
 Test one of the HID internal state flags. More...
 
static bool app_usbd_hid_trans_required (app_usbd_hid_ctx_t *p_hid_ctx)
 Checks whether HID endpoint transfer required. More...
 
static bool app_usbd_hid_state_valid (app_usbd_hid_ctx_t *p_hid_ctx)
 Validates internal hid state. More...
 
ret_code_t app_usbd_hid_event_handler (app_usbd_class_inst_t const *p_inst, app_usbd_hid_inst_t const *p_hinst, app_usbd_hid_ctx_t *p_hid_ctx, app_usbd_complex_evt_t const *p_event)
 HID generic event handler. More...
 
app_usbd_hid_report_buffer_tapp_usbd_hid_rep_buff_in_get (app_usbd_hid_inst_t const *p_hinst)
 Returns IN report buffer. More...
 
static
app_usbd_hid_report_buffer_t
const * 
app_usbd_hid_rep_buff_out_get (app_usbd_hid_inst_t const *p_hinst)
 Returns OUT report buffer. More...
 
static nrf_drv_usbd_ep_t app_usbd_hid_epin_addr_get (app_usbd_class_inst_t const *p_inst)
 Auxiliary function to access to HID IN endpoint address. More...
 
static nrf_drv_usbd_ep_t app_usbd_hid_epout_addr_get (app_usbd_class_inst_t const *p_inst)
 Auxiliary function to access to HID generic OUT endpoint address. More...
 

Detailed Description

nRF52840 only: Module with generic HID event data processing.

Macro Definition Documentation

#define APP_USBD_HID_EPIN_IDX   0

HID instance endpoint IN index.

#define APP_USBD_HID_EPOUT_IDX   1

HID instance endpoint OUT index.

#define APP_USBD_HID_GENERIC_GLOBAL_OUT_REP_DEF (   name,
  rep_size 
)
Value:
static uint8_t CONCAT_2(name, _buf)[(rep_size)]; \
.p_buff = CONCAT_2(name, _buf), \
.size = sizeof(CONCAT_2(name, _buf)), \
}

Define OUT report buffer structure app_usbd_hid_report_buffer_t.

Parameters
nameInstance name.
rep_sizeOutput report size.
#define APP_USBD_HID_IFACE_IDX   0

HID instance interface index.

#define APP_USBD_HID_INST_CONFIG (   descriptors,
  report_dsc,
  report_buff_in,
  report_buff_out,
  user_ev_handler,
  hid_methods 
)
Value:
{ \
.p_raw_desc = descriptors, \
.raw_desc_size = ARRAY_SIZE(descriptors), \
.p_report_dsc = report_dsc, \
.report_dsc_size = ARRAY_SIZE(report_dsc), \
.p_rep_buffer_in = report_buff_in, \
.p_rep_buffer_out = report_buff_out, \
.user_event_handler = user_ev_handler, \
.p_hid_methods = hid_methods, \
}

USB HID instance initializer app_usbd_hid_inst_t.

Parameters
descriptorsInterface, hid, endpoint packed descriptor structure.
report_dscReport descriptor (raw uint8_t array).
report_buff_inInput report buffer list.
report_buff_outOutput report buffer.
user_ev_handlerapp_usbd_hid_user_ev_handler_t.
hid_methodsapp_usbd_hid_methods_t.

Typedef Documentation

typedef void(* app_usbd_hid_user_ev_handler_t)(app_usbd_class_inst_t const *p_inst, app_usbd_hid_user_event_t event)

User event handler.

Parameters
[in]p_instClass instance.
[in]eventUser event.

Enumeration Type Documentation

HID context state flags.

Bit numbers in app_usbd_hid_ctx_t::state_flags.

Enumerator
APP_USBD_HID_STATE_FLAG_APPENDED 

State flag APPENDED.

APP_USBD_HID_STATE_FLAG_STARTED 

State flag STARTED.

APP_USBD_HID_STATE_FLAG_SUSPENDED 

State flag SUSPENDED.

APP_USBD_HID_STATE_FLAG_TRANS_IN_PROGRESS 

State flag TRANS_IN_PROGRESS.

Events passed to user event handler.

Note
Example prototype of user event handler:
void hid_user_ev_handler(app_usbd_class_inst_t const * p_inst,
app_usbd_hid_mouse_user_event_t event);
Enumerator
APP_USBD_HID_USER_EVT_SET_BOOT_PROTO 

Event SET_BOOT_PROTOCOL.

APP_USBD_HID_USER_EVT_SET_REPORT_PROTO 

Event SET_REPORT_PROTOCOL.

APP_USBD_HID_USER_EVT_OUT_REPORT_READY 

Event OUT_REPORT_READY.

APP_USBD_HID_USER_EVT_IN_REPORT_DONE 

Event IN_REPORT_DONE.

Function Documentation

static void app_usbd_hid_access_lock ( app_usbd_hid_ctx_t p_hid_ctx)
inlinestatic

Locks internal hid context.

Simple semaphore functionality to prevent concurrent access from application and interrupt to internal mouse data.

Parameters
[in]p_hid_ctxInternal hid context
static bool app_usbd_hid_access_lock_test ( app_usbd_hid_ctx_t p_hid_ctx)
inlinestatic

Tests whether internal lock is acquired.

Parameters
[in]p_hid_ctxInternal HID context.
Return values
trueLocked.
falseUnlocked.
static void app_usbd_hid_access_unlock ( app_usbd_hid_ctx_t p_hid_ctx)
inlinestatic

Unlocks internal hid context.

Simple semaphore functionality to prevent concurrent access from application and interrupt to internal mouse data.

Parameters
[in]p_hid_ctxInternal hid context.
static nrf_drv_usbd_ep_t app_usbd_hid_epin_addr_get ( app_usbd_class_inst_t const *  p_inst)
inlinestatic

Auxiliary function to access to HID IN endpoint address.

Parameters
[in]p_instClass instance data.
Returns
IN endpoint address.

< HID instance interface index.

< HID instance endpoint IN index.

static nrf_drv_usbd_ep_t app_usbd_hid_epout_addr_get ( app_usbd_class_inst_t const *  p_inst)
inlinestatic

Auxiliary function to access to HID generic OUT endpoint address.

Parameters
[in]p_instClass instance data.
Returns
OUT endpoint address.

< HID instance interface index.

< HID instance endpoint OUT index.

ret_code_t app_usbd_hid_event_handler ( app_usbd_class_inst_t const *  p_inst,
app_usbd_hid_inst_t const *  p_hinst,
app_usbd_hid_ctx_t p_hid_ctx,
app_usbd_complex_evt_t const *  p_event 
)

HID generic event handler.

This handler should process every class event after specific class handler. This approach allow to handle some events in the same way in all HID sub-classes.

Parameters
[in]p_instGeneric class instance.
[in]p_hinstHID class instance.
[in]p_hid_ctxHID context.
[in]p_eventComplex event structure.
Returns
Standard error code.
app_usbd_hid_report_buffer_t* app_usbd_hid_rep_buff_in_get ( app_usbd_hid_inst_t const *  p_hinst)

Returns IN report buffer.

Parameters
[in]p_hinstHID class instance.
Returns
Report buffer handle or NULL if report doesn't exist.
static app_usbd_hid_report_buffer_t const* app_usbd_hid_rep_buff_out_get ( app_usbd_hid_inst_t const *  p_hinst)
inlinestatic

Returns OUT report buffer.

Output reports are handled in interrupt handler so only one buffer is required. Buffer returned by this function has predefined size, which should be equal (maximum OUTPUT report size + 1). To receive OUT report this function should be called on APP_USBD_HID_USER_EVT_OUT_REPORT_READY event.

Parameters
[in]p_hinstHID class instance.
Returns
Report buffer handle or NULL if report doesn't exist.
static void app_usbd_hid_state_flag_clr ( app_usbd_hid_ctx_t p_hid_ctx,
app_usbd_hid_state_flag_t  flag 
)
inlinestatic

Clear one of the HID internal state flags.

Parameters
[in]p_hid_ctxInternal HID context.
[in]flagFlag to clear.
static void app_usbd_hid_state_flag_set ( app_usbd_hid_ctx_t p_hid_ctx,
app_usbd_hid_state_flag_t  flag 
)
inlinestatic

Set one of the HID internal state flags.

Parameters
[in]p_hid_ctxInternal HID context.
[in]flagFlag to set.
static bool app_usbd_hid_state_flag_test ( app_usbd_hid_ctx_t p_hid_ctx,
app_usbd_hid_state_flag_t  flag 
)
inlinestatic

Test one of the HID internal state flags.

Parameters
[in]p_hid_ctxInternal HID context.
[in]flagFlag to test.
Return values
trueFlag is set.
falseFlag is not set.
static bool app_usbd_hid_state_valid ( app_usbd_hid_ctx_t p_hid_ctx)
inlinestatic

Validates internal hid state.

HID Mouse has to receive some USBD events before functions from this module could be used.

Parameters
[in]p_hid_ctxInternal hid context.
Return values
trueState is valid.
falseState is invalid.
static bool app_usbd_hid_trans_required ( app_usbd_hid_ctx_t p_hid_ctx)
inlinestatic

Checks whether HID endpoint transfer required.

Parameters
[in]p_hid_ctxInternal HID context.
Return values
trueInput endpoint transfer required.
falseTransfer in progress or not allowed.

Documentation feedback | Developer Zone | Subscribe | Updated