Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/usb.h

    r3e6a98c5 rfa9d3af  
    8484} usb_speed_t;
    8585
     86static inline bool usb_speed_is_11(const usb_speed_t s)
     87{
     88        return (s == USB_SPEED_FULL) || (s == USB_SPEED_LOW);
     89}
     90
    8691const char *usb_str_speed(usb_speed_t);
    8792
     
    110115#define USB_ADDRESS_DEFAULT 0
    111116/** Maximum address number in USB 1.1. */
    112 #define USB11_ADDRESS_MAX 128
     117#define USB11_ADDRESS_MAX 127
     118#define USB_ADDRESS_COUNT (USB11_ADDRESS_MAX + 1)
     119
     120/** Check USB address for allowed values.
     121 *
     122 * @param ep USB address.
     123 * @return True, if value is wihtin limits, false otherwise.
     124 */
     125static inline bool usb_address_is_valid(usb_address_t a)
     126{
     127        return (a >= USB_ADDRESS_DEFAULT) && (a <= USB11_ADDRESS_MAX);
     128}
    113129
    114130/** USB endpoint number type.
     
    117133typedef int16_t usb_endpoint_t;
    118134
    119 /** Maximum endpoint number in USB 1.1.
    120  */
     135/** Default control endpoint */
     136#define USB_ENDPOINT_DEFAULT_CONTROL 0
     137/** Maximum endpoint number in USB 1.1. */
    121138#define USB11_ENDPOINT_MAX 16
     139
     140/** Check USB endpoint for allowed values.
     141 *
     142 * @param ep USB endpoint number.
     143 * @return True, if value is wihtin limits, false otherwise.
     144 */
     145static inline bool usb_endpoint_is_valid(usb_endpoint_t ep)
     146{
     147        return (ep >= USB_ENDPOINT_DEFAULT_CONTROL) &&
     148            (ep < USB11_ENDPOINT_MAX);
     149}
    122150
    123151
     
    133161} usb_target_t;
    134162
     163
    135164/** Check USB target for allowed values (address and endpoint).
    136165 *
     
    140169static inline bool usb_target_is_valid(usb_target_t target)
    141170{
    142         return !(target.endpoint > 15 || target.endpoint < 0
    143             || target.address >= USB11_ADDRESS_MAX || target.address < 0);
     171        return usb_address_is_valid(target.address) &&
     172            usb_endpoint_is_valid(target.endpoint);
    144173}
    145174
Note: See TracChangeset for help on using the changeset viewer.