1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** HID Remote Control Class */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /* Include necessary system files. */
24
25 #define UX_SOURCE_CODE
26
27 #include "ux_api.h"
28 #include "ux_host_class_hid.h"
29 #include "ux_host_class_hid_remote_control.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_hid_remote_control_callback PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function is the callback mechanism for a report registration. */
46 /* */
47 /* INPUT */
48 /* */
49 /* callback Pointer to callback */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* None */
54 /* */
55 /* CALLS */
56 /* */
57 /* None */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* HID Remote Control Class */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
69 /* resulting in version 6.1 */
70 /* */
71 /**************************************************************************/
_ux_host_class_hid_remote_control_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK * callback)72 VOID _ux_host_class_hid_remote_control_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK *callback)
73 {
74
75 UX_HOST_CLASS_HID_CLIENT *hid_client;
76 UX_HOST_CLASS_HID_REMOTE_CONTROL *remote_control_instance;
77 ULONG *array_head;
78 ULONG *array_tail;
79 ULONG *array_end;
80 ULONG *array_start;
81 ULONG *array_head_next;
82
83
84 /* Get the HID client instance that issued the callback. */
85 hid_client = callback -> ux_host_class_hid_report_callback_client;
86
87 /* Get the remote control local instance. */
88 remote_control_instance = (UX_HOST_CLASS_HID_REMOTE_CONTROL *) hid_client -> ux_host_class_hid_client_local_instance;
89
90 /* Load the remote control usage/value array info. */
91 array_start = remote_control_instance -> ux_host_class_hid_remote_control_usage_array;
92 array_end = array_start + UX_HOST_CLASS_HID_REMOTE_CONTROL_USAGE_ARRAY_LENGTH;
93 array_head = remote_control_instance -> ux_host_class_hid_remote_control_usage_array_head;
94 array_tail = remote_control_instance -> ux_host_class_hid_remote_control_usage_array_tail;
95
96 /* We have a single usage/value. We have to store it into the array. If the array overflows,
97 there is no mechanism for flow control here so we ignore the usage/value until the
98 applications makes more room in the array. */
99
100 /* Get position where next head will be. */
101 array_head_next = array_head + 2;
102
103 /* The head always points to where we will insert the next element. This
104 is the reason for the wrap. */
105 if (array_head_next == array_end)
106 array_head_next = array_start;
107
108 /* Do we have enough space to store the new usage? */
109 if (array_head_next != array_tail)
110 {
111
112 /* Yes, we have some space. */
113 *array_head = callback -> ux_host_class_hid_report_callback_usage;
114 *(array_head + 1) = callback -> ux_host_class_hid_report_callback_value;
115
116 /* Now update the array head. */
117 remote_control_instance -> ux_host_class_hid_remote_control_usage_array_head = array_head_next;
118 }
119 else
120 {
121
122 /* If trace is enabled, insert this event into the trace buffer. */
123 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_REMOTE_CONTROL_CALLBACK, hid_client, remote_control_instance, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
124
125 /* Notify application. */
126 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_BUFFER_OVERFLOW);
127 }
128
129 /* Return to caller. */
130 return;
131 }
132
133