Mbed OS Reference
Loading...
Searching...
No Matches
EndpointResolver.h
1/*
2 * Copyright (c) 2018-2019, Arm Limited and affiliates.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may 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,
13 * WITHOUT 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 ENDPOINT_RESOLVER_H
19#define ENDPOINT_RESOLVER_H
20
21#include "USBPhy.h"
22
23/**
24 * \defgroup drivers_EndpointResolver EndpointResolver class
25 * \ingroup drivers-internal-api-usb
26 * @{
27 */
28
29/**
30 * Utility class for resolving endpoints
31 *
32 * This class is intended to make the process of
33 * selecting the correct endpoint from a device endpoint
34 * table easier. It also provides a verification function
35 * to check if the device has enough resources for the
36 * given configuration.
37 *
38 */
40public:
41 EndpointResolver(const usb_ep_table_t *table);
43
44 /**
45 * Add control endpoint size
46 *
47 * @param size Space reserved for control in and control out
48 */
49 void endpoint_ctrl(uint32_t size);
50
51 /**
52 * Return a free IN endpoint of the given size
53 *
54 * @param type Desired endpoint type
55 * @param size Space to reserve for this endpoint
56 * @return Endpoint index or 0 if there are not enough resources
57 */
58 usb_ep_t endpoint_in(usb_ep_type_t type, uint32_t size);
59
60 /**
61 * Return a free OUT endpoint of the given size
62 *
63 * @param type Desired endpoint type
64 * @param size Space to reserve for this endpoint
65 * @return Endpoint index or 0 if there are not enough resources
66 */
67 usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size);
68
69 /**
70 * Get next free endpoint
71 */
72 usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size);
73
74 /**
75 * Check if the endpoint configuration created so far is valid
76 *
77 * @return true if all endpoint sizes are available and fit, false otherwise
78 */
79 bool valid();
80
81 /**
82 * Reset this class's state to when it was constructed
83 */
84 void reset();
85
86private:
87
88 usb_ep_t index_to_endpoint(int index);
89 int next_index(usb_ep_type_t type, bool in_not_out);
90
91 const usb_ep_table_t *_table;
92 uint32_t _cost;
93 uint32_t _used;
94 bool _valid;
95};
96
97/** @}*/
98
99#endif
Utility class for resolving endpoints.
usb_ep_t endpoint_in(usb_ep_type_t type, uint32_t size)
Return a free IN endpoint of the given size.
bool valid()
Check if the endpoint configuration created so far is valid.
void endpoint_ctrl(uint32_t size)
Add control endpoint size.
usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size)
Return a free OUT endpoint of the given size.
usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size)
Get next free endpoint.
void reset()
Reset this class's state to when it was constructed.