mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
drivers/internal/EndpointResolver.h@1:9db0e321a9f4, 2019-12-31 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 31 06:02:27 2019 +0000
- Revision:
- 1:9db0e321a9f4
updated based on mbed-os5.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 1:9db0e321a9f4 | 1 | /* |
kenjiArai | 1:9db0e321a9f4 | 2 | * Copyright (c) 2018-2019, Arm Limited and affiliates. |
kenjiArai | 1:9db0e321a9f4 | 3 | * SPDX-License-Identifier: Apache-2.0 |
kenjiArai | 1:9db0e321a9f4 | 4 | * |
kenjiArai | 1:9db0e321a9f4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 1:9db0e321a9f4 | 6 | * you may not use this file except in compliance with the License. |
kenjiArai | 1:9db0e321a9f4 | 7 | * You may obtain a copy of the License at |
kenjiArai | 1:9db0e321a9f4 | 8 | * |
kenjiArai | 1:9db0e321a9f4 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 1:9db0e321a9f4 | 10 | * |
kenjiArai | 1:9db0e321a9f4 | 11 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 1:9db0e321a9f4 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 1:9db0e321a9f4 | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 1:9db0e321a9f4 | 14 | * See the License for the specific language governing permissions and |
kenjiArai | 1:9db0e321a9f4 | 15 | * limitations under the License. |
kenjiArai | 1:9db0e321a9f4 | 16 | */ |
kenjiArai | 1:9db0e321a9f4 | 17 | |
kenjiArai | 1:9db0e321a9f4 | 18 | #ifndef ENDPOINT_RESOLVER_H |
kenjiArai | 1:9db0e321a9f4 | 19 | #define ENDPOINT_RESOLVER_H |
kenjiArai | 1:9db0e321a9f4 | 20 | |
kenjiArai | 1:9db0e321a9f4 | 21 | #include "USBPhy.h" |
kenjiArai | 1:9db0e321a9f4 | 22 | |
kenjiArai | 1:9db0e321a9f4 | 23 | /** |
kenjiArai | 1:9db0e321a9f4 | 24 | * \defgroup drivers_EndpointResolver EndpointResolver class |
kenjiArai | 1:9db0e321a9f4 | 25 | * \ingroup drivers-internal-api-usb |
kenjiArai | 1:9db0e321a9f4 | 26 | * @{ |
kenjiArai | 1:9db0e321a9f4 | 27 | */ |
kenjiArai | 1:9db0e321a9f4 | 28 | |
kenjiArai | 1:9db0e321a9f4 | 29 | /** |
kenjiArai | 1:9db0e321a9f4 | 30 | * Utility class for resolving endpoints |
kenjiArai | 1:9db0e321a9f4 | 31 | * |
kenjiArai | 1:9db0e321a9f4 | 32 | * This class is intended to make the process of |
kenjiArai | 1:9db0e321a9f4 | 33 | * selecting the correct endpoint from a device endpoint |
kenjiArai | 1:9db0e321a9f4 | 34 | * table easier. It also provides a verification function |
kenjiArai | 1:9db0e321a9f4 | 35 | * to check if the device has enough resources for the |
kenjiArai | 1:9db0e321a9f4 | 36 | * given configuration. |
kenjiArai | 1:9db0e321a9f4 | 37 | * |
kenjiArai | 1:9db0e321a9f4 | 38 | */ |
kenjiArai | 1:9db0e321a9f4 | 39 | class EndpointResolver { |
kenjiArai | 1:9db0e321a9f4 | 40 | public: |
kenjiArai | 1:9db0e321a9f4 | 41 | EndpointResolver(const usb_ep_table_t *table); |
kenjiArai | 1:9db0e321a9f4 | 42 | ~EndpointResolver(); |
kenjiArai | 1:9db0e321a9f4 | 43 | |
kenjiArai | 1:9db0e321a9f4 | 44 | /** |
kenjiArai | 1:9db0e321a9f4 | 45 | * Add control endpoint size |
kenjiArai | 1:9db0e321a9f4 | 46 | * |
kenjiArai | 1:9db0e321a9f4 | 47 | * @param size Space reserved for control in and control out |
kenjiArai | 1:9db0e321a9f4 | 48 | */ |
kenjiArai | 1:9db0e321a9f4 | 49 | void endpoint_ctrl(uint32_t size); |
kenjiArai | 1:9db0e321a9f4 | 50 | |
kenjiArai | 1:9db0e321a9f4 | 51 | /** |
kenjiArai | 1:9db0e321a9f4 | 52 | * Return a free IN endpoint of the given size |
kenjiArai | 1:9db0e321a9f4 | 53 | * |
kenjiArai | 1:9db0e321a9f4 | 54 | * @param type Desired endpoint type |
kenjiArai | 1:9db0e321a9f4 | 55 | * @param size Space to reserve for this endpoint |
kenjiArai | 1:9db0e321a9f4 | 56 | * @return Endpoint index or 0 if there are not enough resources |
kenjiArai | 1:9db0e321a9f4 | 57 | */ |
kenjiArai | 1:9db0e321a9f4 | 58 | usb_ep_t endpoint_in(usb_ep_type_t type, uint32_t size); |
kenjiArai | 1:9db0e321a9f4 | 59 | |
kenjiArai | 1:9db0e321a9f4 | 60 | /** |
kenjiArai | 1:9db0e321a9f4 | 61 | * Return a free OUT endpoint of the given size |
kenjiArai | 1:9db0e321a9f4 | 62 | * |
kenjiArai | 1:9db0e321a9f4 | 63 | * @param type Desired endpoint type |
kenjiArai | 1:9db0e321a9f4 | 64 | * @param size Space to reserve for this endpoint |
kenjiArai | 1:9db0e321a9f4 | 65 | * @return Endpoint index or 0 if there are not enough resources |
kenjiArai | 1:9db0e321a9f4 | 66 | */ |
kenjiArai | 1:9db0e321a9f4 | 67 | usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size); |
kenjiArai | 1:9db0e321a9f4 | 68 | |
kenjiArai | 1:9db0e321a9f4 | 69 | /** |
kenjiArai | 1:9db0e321a9f4 | 70 | * Get next free endpoint |
kenjiArai | 1:9db0e321a9f4 | 71 | */ |
kenjiArai | 1:9db0e321a9f4 | 72 | usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size); |
kenjiArai | 1:9db0e321a9f4 | 73 | |
kenjiArai | 1:9db0e321a9f4 | 74 | /** |
kenjiArai | 1:9db0e321a9f4 | 75 | * Check if the endpoint configuration created so far is valid |
kenjiArai | 1:9db0e321a9f4 | 76 | * |
kenjiArai | 1:9db0e321a9f4 | 77 | * @return true if all endpoint sizes are available and fit, false otherwise |
kenjiArai | 1:9db0e321a9f4 | 78 | */ |
kenjiArai | 1:9db0e321a9f4 | 79 | bool valid(); |
kenjiArai | 1:9db0e321a9f4 | 80 | |
kenjiArai | 1:9db0e321a9f4 | 81 | /** |
kenjiArai | 1:9db0e321a9f4 | 82 | * Reset this class's state to when it was constructed |
kenjiArai | 1:9db0e321a9f4 | 83 | */ |
kenjiArai | 1:9db0e321a9f4 | 84 | void reset(); |
kenjiArai | 1:9db0e321a9f4 | 85 | |
kenjiArai | 1:9db0e321a9f4 | 86 | private: |
kenjiArai | 1:9db0e321a9f4 | 87 | |
kenjiArai | 1:9db0e321a9f4 | 88 | usb_ep_t index_to_endpoint(int index); |
kenjiArai | 1:9db0e321a9f4 | 89 | int next_index(usb_ep_type_t type, bool in_not_out); |
kenjiArai | 1:9db0e321a9f4 | 90 | |
kenjiArai | 1:9db0e321a9f4 | 91 | const usb_ep_table_t *_table; |
kenjiArai | 1:9db0e321a9f4 | 92 | uint32_t _cost; |
kenjiArai | 1:9db0e321a9f4 | 93 | uint32_t _used; |
kenjiArai | 1:9db0e321a9f4 | 94 | bool _valid; |
kenjiArai | 1:9db0e321a9f4 | 95 | }; |
kenjiArai | 1:9db0e321a9f4 | 96 | |
kenjiArai | 1:9db0e321a9f4 | 97 | /** @}*/ |
kenjiArai | 1:9db0e321a9f4 | 98 | |
kenjiArai | 1:9db0e321a9f4 | 99 | #endif |