Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EndpointResolver.h Source File

EndpointResolver.h

00001 /*
00002  * Copyright (c) 2018-2019, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef ENDPOINT_RESOLVER_H
00019 #define ENDPOINT_RESOLVER_H
00020 
00021 #include "USBPhy.h"
00022 
00023 /**
00024  * \defgroup drivers_EndpointResolver EndpointResolver class
00025  * \ingroup drivers-internal-api-usb
00026  * @{
00027  */
00028 
00029 /**
00030  * Utility class for resolving endpoints
00031  *
00032  * This class is intended to make the process of
00033  * selecting the correct endpoint from a device endpoint
00034  * table easier. It also provides a verification function
00035  * to check if the device has enough resources for the
00036  * given configuration.
00037  *
00038  */
00039 class EndpointResolver {
00040 public:
00041     EndpointResolver(const usb_ep_table_t *table);
00042     ~EndpointResolver();
00043 
00044     /**
00045      * Add control endpoint size
00046      *
00047      * @param size Space reserved for control in and control out
00048      */
00049     void endpoint_ctrl(uint32_t size);
00050 
00051     /**
00052      * Return a free IN endpoint of the given size
00053      *
00054      * @param type Desired endpoint type
00055      * @param size Space to reserve for this endpoint
00056      * @return Endpoint index or 0 if there are not enough resources
00057      */
00058     usb_ep_t endpoint_in(usb_ep_type_t type, uint32_t size);
00059 
00060     /**
00061      * Return a free OUT endpoint of the given size
00062      *
00063      * @param type Desired endpoint type
00064      * @param size Space to reserve for this endpoint
00065      * @return Endpoint index or 0 if there are not enough resources
00066      */
00067     usb_ep_t endpoint_out(usb_ep_type_t type, uint32_t size);
00068 
00069     /**
00070      * Get next free endpoint
00071      */
00072     usb_ep_t next_free_endpoint(bool in_not_out, usb_ep_type_t type, uint32_t size);
00073 
00074     /**
00075      * Check if the endpoint configuration created so far is valid
00076      *
00077      * @return true if all endpoint sizes are available and fit, false otherwise
00078      */
00079     bool valid();
00080 
00081     /**
00082      * Reset this class's state to when it was constructed
00083      */
00084     void reset();
00085 
00086 private:
00087 
00088     usb_ep_t index_to_endpoint(int index);
00089     int next_index(usb_ep_type_t type, bool in_not_out);
00090 
00091     const usb_ep_table_t *_table;
00092     uint32_t _cost;
00093     uint32_t _used;
00094     bool _valid;
00095 };
00096 
00097 /** @}*/
00098 
00099 #endif