summaryrefslogtreecommitdiff
path: root/common/usbx_host_classes/src/ux_host_class_hid_remote_control_callback.c
blob: 88292c3cda8c33a4d5becd7ec94139e59758d81e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   HID Remote Control Class                                            */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/* Include necessary system files.  */

#define UX_SOURCE_CODE

#include "ux_api.h"
#include "ux_host_class_hid.h"
#include "ux_host_class_hid_remote_control.h"
#include "ux_host_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_host_class_hid_remote_control_callback          PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function is the callback mechanism for a report registration.  */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    callback                              Pointer to callback           */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    HID Remote Control Class                                            */
/*                                                                        */
/**************************************************************************/
VOID  _ux_host_class_hid_remote_control_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK *callback)
{

UX_HOST_CLASS_HID_CLIENT            *hid_client;
UX_HOST_CLASS_HID_REMOTE_CONTROL    *remote_control_instance;
ULONG                               *array_head;
ULONG                               *array_tail;
ULONG                               *array_end;
ULONG                               *array_start;
ULONG                               *array_head_next;


    /* Get the HID client instance that issued the callback.  */
    hid_client = callback -> ux_host_class_hid_report_callback_client;

    /* Get the remote control local instance.  */
    remote_control_instance =  (UX_HOST_CLASS_HID_REMOTE_CONTROL *) hid_client -> ux_host_class_hid_client_local_instance;

    /* Load the remote control usage/value array info.  */
    array_start =  remote_control_instance -> ux_host_class_hid_remote_control_usage_array;
    array_end =    array_start + UX_HOST_CLASS_HID_REMOTE_CONTROL_USAGE_ARRAY_LENGTH;
    array_head =   remote_control_instance -> ux_host_class_hid_remote_control_usage_array_head;
    array_tail =   remote_control_instance -> ux_host_class_hid_remote_control_usage_array_tail;

    /* We have a single usage/value. We have to store it into the array. If the array overflows,
       there is no mechanism for flow control here so we ignore the usage/value until the
       applications makes more room in the array.  */

    /* Get position where next head will be.  */
    array_head_next =  array_head + 2;

    /* The head always points to where we will insert the next element. This
       is the reason for the wrap.  */
    if (array_head_next == array_end)
        array_head_next =  array_start;

    /* Do we have enough space to store the new usage?  */
    if (array_head_next != array_tail)
    {

        /* Yes, we have some space.  */
        *array_head =        callback -> ux_host_class_hid_report_callback_usage;
        *(array_head + 1) =  callback -> ux_host_class_hid_report_callback_value;

        /* Now update the array head.  */
        remote_control_instance -> ux_host_class_hid_remote_control_usage_array_head =  array_head_next;
    }
    else
    {

        /* If trace is enabled, insert this event into the trace buffer.  */
        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)

        /* Notify application.  */
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_BUFFER_OVERFLOW);
    }

    /* Return to caller.  */
    return;
}