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 #include "platform/NonCopyable.h"
27 
28 #include "USBDevice.h"
29 
30 class USBTester: public USBDevice, private mbed::NonCopyable<USBTester> {
31 public:
32 
33  /*
34  * Constructor
35  *
36  * @param vendor_id Your vendor_id
37  * @param product_id Your product_id
38  * @param product_release Your product_release
39  */
40  USBTester(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
41 
42  virtual ~USBTester();
43 
44  /*
45  *
46  * @returns descriptor string in ASCII
47  */
48  const char *get_serial_desc_string();
49  const char *get_iproduct_desc_string();
50  const char *get_iinterface_desc_string();
51  uint32_t get_reset_count() const
52  {
53  return reset_count;
54  }
55  uint32_t get_suspend_count() const
56  {
57  return suspend_count;
58  }
59  uint32_t get_resume_count() const
60  {
61  return resume_count;
62  }
63  void clear_reset_count()
64  {
65  reset_count = 0;
66  }
67  void clear_suspend_count()
68  {
69  suspend_count = 0;
70  }
71  void clear_resume_count()
72  {
73  resume_count = 0;
74  }
75 
76 private:
77 
78  enum { NONE = -1 };
79  const char *get_desc_string(const uint8_t *desc);
80  virtual void suspend(bool suspended);
81  bool set_configuration(uint16_t configuration);
82  bool set_interface(uint16_t interface, uint16_t alternate);
83  bool setup_iterface(uint8_t ep_in, uint8_t ep_out, uint32_t ep_size, usb_ep_type_t ep_type,
84  uint8_t *buf, uint32_t buf_size, void (USBTester::*callback)());
85  void remove_iterface(uint16_t interface);
86  int16_t interface_0_alt_set;
87  int16_t interface_1_alt_set;
88  int16_t configuration_set;
89 
90 protected:
91 
92  /*
93  * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
94  *
95  * @returns pointer to the device descriptor
96  */
97  virtual const uint8_t *device_desc();
98 
99  /*
100  * Get string product descriptor
101  *
102  * @returns pointer to the string product descriptor
103  */
104  virtual const uint8_t *string_iproduct_desc();
105 
106  /*
107  * Get string interface descriptor
108  *
109  * @returns pointer to the string interface descriptor
110  */
111  virtual const uint8_t *string_iinterface_desc();
112 
113  /*
114  * Get configuration descriptor
115  *
116  * @param index descriptor index
117  * @returns pointer to the configuration descriptor
118  */
119  virtual const uint8_t *configuration_desc(uint8_t index);
120 
121 protected:
122  uint8_t bulk_in;
123  uint8_t bulk_out;
124  uint8_t bulk_buf[64];
125  uint8_t int_in;
126  uint8_t int_out;
127  uint8_t int_buf[64];
128  events::EventQueue *queue;
129  rtos::EventFlags flags;
130  volatile uint32_t reset_count;
131  volatile uint32_t suspend_count;
132  volatile uint32_t resume_count;
133 
134  virtual void callback_state_change(DeviceState new_state);
135  virtual void callback_request(const setup_packet_t *setup);
136  virtual void callback_request_xfer_done(const setup_packet_t *setup, bool aborted);
137  virtual void callback_set_configuration(uint8_t configuration);
138  virtual void callback_set_interface(uint16_t interface, uint8_t alternate);
139  virtual void epbulk_out_callback();
140  virtual void epint_out_callback();
141  virtual void callback_reset();
142  uint8_t *ctrl_buf;
143 
144 };
145 
146 #endif
The EventFlags class is used to control event flags or wait for event flags other threads control...
Definition: EventFlags.h:51
EventQueue.
Definition: EventQueue.h:60
virtual void callback_reset()
Called by USBDevice layer on bus reset.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:169
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.
Core USB Device driver.
Definition: USBDevice.h:38
virtual void callback_state_change(DeviceState new_state)
Called when USB changes state.
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=0)
Create a callback class with type inferred from the arguments.
Definition: Callback.h:709
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.