Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 54 additions & 34 deletions common/usbx_host_classes/src/ux_host_class_hid_client_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** USBX Component */
/** */
/** HID Class */
/** */
Expand All @@ -30,36 +30,36 @@
#include "ux_host_stack.h"


/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_hid_client_search PORTABLE C */
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_hid_client_search PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* */
/* This function searches for a HID client that wants to own this HID */
/* device. */
/* */
/* INPUT */
/* */
/* hid Pointer to HID class */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (ux_host_class_hid_client_handler) HID client handler */
/* */
/* CALLED BY */
/* */
/* HID Class */
/* device. */
/* */
/* INPUT */
/* */
/* hid Pointer to HID class */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (ux_host_class_hid_client_handler) HID client handler */
/* */
/* CALLED BY */
/* */
/* HID Class */
/* */
/**************************************************************************/
UINT _ux_host_class_hid_client_search(UX_HOST_CLASS_HID *hid)
Expand All @@ -77,10 +77,10 @@ UX_HOST_CLASS_HID_CLIENT_COMMAND hid_client_command;
hid_client_command.ux_host_class_hid_client_command_instance = hid;
hid_client_command.ux_host_class_hid_client_command_container = (VOID *) hid -> ux_host_class_hid_class;
hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_QUERY;

/* Dereference the client pointer into a HID client pointer. */
hid_client = (UX_HOST_CLASS_HID_CLIENT *) hid -> ux_host_class_hid_class -> ux_host_class_client;

/* If the hid_client pointer is NULL, the array of clients was not initialized. */
if (hid_client == UX_NULL)
{
Expand All @@ -93,7 +93,7 @@ UX_HOST_CLASS_HID_CLIENT_COMMAND hid_client_command;

return(UX_HOST_CLASS_HID_UNKNOWN);
}

/* We need to parse the hid client driver table to find a registered client. */
for (hid_client_index = 0; hid_client_index < UX_HOST_CLASS_HID_MAX_CLIENTS; hid_client_index++)
{
Expand All @@ -104,32 +104,52 @@ UX_HOST_CLASS_HID_CLIENT_COMMAND hid_client_command;

/* Call the HID client with a query command. */
status = hid_client -> ux_host_class_hid_client_handler(&hid_client_command);

/* Have we found a HID client? */
if (status == UX_SUCCESS)
{

/* Allocate a per-instance copy of the client struct so that
each HID device gets its own local_instance pointer.
This prevents multiple devices of the same type from
using a single local_instance. */
UX_HOST_CLASS_HID_CLIENT *hid_client_instance;
hid_client_instance = (UX_HOST_CLASS_HID_CLIENT *)
_ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY,
sizeof(UX_HOST_CLASS_HID_CLIENT));
if (hid_client_instance == UX_NULL)
return(UX_MEMORY_INSUFFICIENT);

/* Copy the registered client entry into the per-instance copy
and NULL the local instance. */
_ux_utility_memory_copy(hid_client_instance, hid_client,
sizeof(UX_HOST_CLASS_HID_CLIENT));
hid_client_instance -> ux_host_class_hid_client_local_instance = UX_NULL;

/* Update the command to activate the client. */
hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_ACTIVATE;

/* Memorize the client for this HID device. */
hid -> ux_host_class_hid_client = hid_client;
/* Store the per-instance client on this HID device. */
hid -> ux_host_class_hid_client = hid_client_instance;

/* Call the HID client with an activate command. */
status = hid_client -> ux_host_class_hid_client_handler(&hid_client_command);
status = hid_client_instance -> ux_host_class_hid_client_handler(&hid_client_command);

/* Unmount the client if activation fail. */
if (status != UX_SUCCESS)
{
hid -> ux_host_class_hid_client = UX_NULL;

_ux_utility_memory_free(hid_client_instance);
}

/* Return completion status. */
return(status);
}
}

/* Try the next HID client. */
hid_client++;
}
}

/* Error trap. */
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_HID_UNKNOWN);
Expand Down
79 changes: 43 additions & 36 deletions common/usbx_host_classes/src/ux_host_class_hid_deactivate.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** USBX Component */
/** */
/** HID Class */
/** */
Expand All @@ -30,44 +30,44 @@
#include "ux_host_stack.h"


/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_hid_deactivate PORTABLE C */
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_hid_deactivate PORTABLE C */
/* 6.1.10 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* */
/* This function is called when this instance of the HID has been */
/* removed from the bus either directly or indirectly. The interrupt */
/* pipe will be destroyed and the instanced removed. */
/* */
/* INPUT */
/* */
/* command Pointer to command */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (ux_host_class_hid_client_handler) HID client handler */
/* _ux_host_class_hid_instance_clean HID instance clean */
/* _ux_host_stack_class_instance_destroy Destroy the class instance */
/* removed from the bus either directly or indirectly. The interrupt */
/* pipe will be destroyed and the instanced removed. */
/* */
/* INPUT */
/* */
/* command Pointer to command */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* (ux_host_class_hid_client_handler) HID client handler */
/* _ux_host_class_hid_instance_clean HID instance clean */
/* _ux_host_stack_class_instance_destroy Destroy the class instance */
/* _ux_host_stack_endpoint_transfer_abort */
/* Abort transfer */
/* _ux_utility_memory_free Release memory block */
/* _ux_host_semaphore_delete Delete semaphore */
/* _ux_host_semaphore_get Get semaphore */
/* */
/* CALLED BY */
/* */
/* HID Class */
/* Abort transfer */
/* _ux_utility_memory_free Release memory block */
/* _ux_host_semaphore_delete Delete semaphore */
/* _ux_host_semaphore_get Get semaphore */
/* */
/* CALLED BY */
/* */
/* HID Class */
/* */
/**************************************************************************/
UINT _ux_host_class_hid_deactivate(UX_HOST_CLASS_COMMAND *command)
Expand Down Expand Up @@ -138,17 +138,23 @@ UINT status;
hid_client_command.ux_host_class_hid_client_command_instance = (VOID *) hid;
hid_client_command.ux_host_class_hid_client_command_container = (VOID *) hid -> ux_host_class_hid_class;
hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_DEACTIVATE;

/* Call the HID client with a deactivate command if there was a client registered. */
if (hid -> ux_host_class_hid_client != UX_NULL)
{
hid -> ux_host_class_hid_client -> ux_host_class_hid_client_handler(&hid_client_command);

/* Free the per-instance client copy allocated in _ux_host_class_hid_client_search. */
_ux_utility_memory_free(hid -> ux_host_class_hid_client);
hid -> ux_host_class_hid_client = UX_NULL;
}

/* Clean all the HID memory fields. */
_ux_host_class_hid_instance_clean(hid);

/* The enumeration thread needs to sleep a while to allow the application or the class that may be using
endpoints to exit properly. */
_ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);
_ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM);

/* Destroy the instance. */
_ux_host_stack_class_instance_destroy(hid -> ux_host_class_hid_class, (VOID *) hid);
Expand All @@ -160,7 +166,7 @@ UINT status;
that the device is removed. */
if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
{

/* Inform the application the device is removed. */
_ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, hid -> ux_host_class_hid_class, (VOID *) hid);
}
Expand All @@ -175,5 +181,6 @@ UINT status;
_ux_utility_memory_free(hid);

/* Return successful completion. */
return(UX_SUCCESS);
return(UX_SUCCESS);
}