Mistake on this page?
Report an issue in GitHub or email us
USBTester.h
1 /*
2  * Copyright (c) 2018-2018, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef USB_TESTER_H
19 #define USB_TESTER_H
20 
21 /* These headers are included for child class. */
22 #include "USBDescriptor.h"
23 #include "USBDevice_Types.h"
24 #include "EventQueue.h"
25 #include "EventFlags.h"
26 
27 #include "USBDevice.h"
28 
29 class USBTester: public USBDevice {
30 public:
31 
32  /*
33  * Constructor
34  *
35  * @param vendor_id Your vendor_id
36  * @param product_id Your product_id
37  * @param product_release Your product_release
38  */
39  USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
40 
41  virtual ~USBTester();
42 
43  /*
44  *
45  * @returns descriptor string in ASCII
46  */
47  const char *get_serial_desc_string();
48  const char *get_iproduct_desc_string();
49  const char *get_iinterface_desc_string();
50  uint32_t get_reset_count() const
51  {
52  return reset_count;
53  }
54  uint32_t get_suspend_count() const
55  {
56  return suspend_count;
57  }
58  uint32_t get_resume_count() const
59  {
60  return resume_count;
61  }
62  void clear_reset_count()
63  {
64  reset_count = 0;
65  }
66  void clear_suspend_count()
67  {
68  suspend_count = 0;
69  }
70  void clear_resume_count()
71  {
72  resume_count = 0;
73  }
74 
75 private:
76 
77  enum { NONE = -1 };
78  const char *get_desc_string(const uint8_t *desc);
79  virtual void suspend(bool suspended);
80  bool set_configuration(uint16_t configuration);
81  bool set_interface(uint16_t interface, uint16_t alternate);
82  bool setup_iterface(uint8_t ep_in, uint8_t ep_out, uint32_t ep_size, usb_ep_type_t ep_type,
83  uint8_t *buf, uint32_t buf_size, void (USBTester::*callback)());
84  void remove_iterface(uint16_t interface);
85  int16_t interface_0_alt_set;
86  int16_t interface_1_alt_set;
87  int16_t configuration_set;
88 
89 protected:
90 
91  /*
92  * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
93  *
94  * @returns pointer to the device descriptor
95  */
96  virtual const uint8_t *device_desc();
97 
98  /*
99  * Get string product descriptor
100  *
101  * @returns pointer to the string product descriptor
102  */
103  virtual const uint8_t *string_iproduct_desc();
104 
105  /*
106  * Get string interface descriptor
107  *
108  * @returns pointer to the string interface descriptor
109  */
110  virtual const uint8_t *string_iinterface_desc();
111 
112  /*
113  * Get configuration descriptor
114  *
115  * @param index descriptor index
116  * @returns pointer to the configuration descriptor
117  */
118  virtual const uint8_t *configuration_desc(uint8_t index);
119 
120 protected:
121  uint8_t bulk_in;
122  uint8_t bulk_out;
123  uint8_t bulk_buf[64];
124  uint8_t int_in;
125  uint8_t int_out;
126  uint8_t int_buf[64];
127  events::EventQueue *queue;
128  rtos::EventFlags flags;
129  volatile uint32_t reset_count;
130  volatile uint32_t suspend_count;
131  volatile uint32_t resume_count;
132 
133  virtual void callback_state_change(DeviceState new_state);
134  virtual void callback_request(const setup_packet_t *setup);
135  virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted);
136  virtual void callback_set_configuration(uint8_t configuration);
137  virtual void callback_set_interface(uint16_t interface, uint8_t alternate);
138  virtual void epbulk_out_callback();
139  virtual void epint_out_callback();
140  virtual void callback_reset();
141  uint8_t ctrl_buf[2048];
142 
143 };
144 
145 #endif
The EventFlags class is used to control event flags or wait for event flags other threads control...
Definition: EventFlags.h:49
EventQueue.
Definition: EventQueue.h:52
virtual void callback_reset()
Called by USBDevice layer on bus reset.
Abstract interface to physical USB hardware.
Definition: USBPhy.h:82
virtual void callback_request(const setup_packet_t *setup)
Called by USBDevice on Endpoint0 request.
Callback< R()> callback(R(*func)()=0)
Create a callback class with type inferred from the arguments.
Definition: Callback.h:3848
Core USB Device driver.
Definition: USBDevice.h:44
virtual void callback_state_change(DeviceState new_state)
Called when USB changes state.
virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted)
Called by USBDevice on data stage completion.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.