summaryrefslogtreecommitdiff
path: root/common/usbx_host_classes/src/ux_host_class_hid_tasks_run.c
blob: 7edbcc7e519de7279ae28e58c4c4110de077fdef (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
/***************************************************************************
 * 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 Class                                                           */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/* Include necessary system files.  */

#define UX_SOURCE_CODE

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


#if defined(UX_HOST_STANDALONE)


static inline VOID _ux_host_class_hid_inst_tasks_run(UX_HOST_CLASS_HID *hid);

/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_host_class_hid_tasks_run                        PORTABLE C      */
/*                                                           6.1.10       */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function runs HID background tasks.                            */
/*                                                                        */
/*    This function is for standalone mode.                               */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    hid                                       Pointer to hid instance   */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    (ux_host_class_hid_client_function)   Client task function          */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    USBX Host Stack                                                     */
/*                                                                        */
/**************************************************************************/
UINT  _ux_host_class_hid_tasks_run(UX_HOST_CLASS *hid_class)
{
UX_HOST_CLASS_HID           *hid;

    /* Validate class entry.  */
    if (hid_class -> ux_host_class_status != UX_USED ||
        hid_class -> ux_host_class_entry_function != _ux_host_class_hid_entry)
        return(UX_STATE_IDLE);

    /* Run for class instances.  */
    hid = (UX_HOST_CLASS_HID *)hid_class -> ux_host_class_first_instance;
    while(hid)
    {

        /* Run tasks for each hid instance.  */
        if ((hid -> ux_host_class_hid_flags & UX_HOST_CLASS_HID_FLAG_PROTECT) == 0)
        {
            hid -> ux_host_class_hid_flags |= UX_HOST_CLASS_HID_FLAG_PROTECT;
            _ux_host_class_hid_inst_tasks_run(hid);
            hid -> ux_host_class_hid_flags &= ~UX_HOST_CLASS_HID_FLAG_PROTECT;
        }
        hid = hid -> ux_host_class_hid_next_instance;
    }
    return(UX_STATE_WAIT);
}

static inline VOID _ux_host_class_hid_inst_tasks_run(UX_HOST_CLASS_HID *hid)
{
UX_HOST_CLASS_HID_CLIENT        *client = hid -> ux_host_class_hid_client;
    if (client && client -> ux_host_class_hid_client_function)
    {
        client -> ux_host_class_hid_client_function(client);
    }
}
#endif