1 /******************************************************************************
2  *
3  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4  * Analog Devices, Inc.),
5  * Copyright (C) 2023-2024 Analog Devices, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************************/
20 
21 /*
22  * Low-layer API calls
23  *
24  * These do not change, and provide the basis by which usb.c acceses the
25  *  hardware. All usbio.c drivers will provide these calls, or return an
26  *  error if the function is not supported.
27  *
28  */
29 
30 #ifndef LIBRARIES_MAXUSB_INCLUDE_CORE_USB_EVENT_H_
31 #define LIBRARIES_MAXUSB_INCLUDE_CORE_USB_EVENT_H_
32 
33 #include "usb.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /**
40  * @file MXC_USB_event.h
41  * @brief Defines the API used for USB event handling
42  *
43  */
44 
45 /***** Definitions *****/
46 typedef struct {
47   int (*func)(maxusb_event_t, void *);
48   void *cbdata;
49 } MXC_USB_event_callback_t;
50 
51 /**
52  * @brief Register a callback for and enable the specified event
53  * @param event   event number
54  * @param func    function to be called
55  * @param cbdata  parameter to call callback function with
56  * @return This function returns zero (0) for success, non-zero for failure
57  */
58 int MXC_USB_EventEnable(maxusb_event_t event, int (*callback)(maxusb_event_t, void *), void *cbdata);
59 
60 /**
61  * @brief Enable the specified event
62  * @param event   event number
63  * @return This function returns zero (0) for success, non-zero for failure
64  */
65 int MXC_USB_EventDisable(maxusb_event_t event);
66 
67 /**
68  * @brief Clear the specified event
69  * @param event   event number
70  * @return This function returns zero (0) for success, non-zero for failure
71  */
72 int MXC_USB_EventClear(maxusb_event_t event);
73 
74 /**
75  * @brief Processes USB events
76  * This function should be called from the USB interrupt vector or periodically
77  * from the application.
78  */
79 void MXC_USB_EventHandler(void);
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 #endif //LIBRARIES_MAXUSB_INCLUDE_CORE_USB_EVENT_H_
86