Changeset 19a1800 in mainline for uspace/lib/usb/include


Ignore:
Timestamp:
2011-03-01T22:20:56Z (14 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e24e7b1
Parents:
976f546 (diff), ac8285d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with the current development

Location:
uspace/lib/usb/include/usb
Files:
6 added
2 deleted
10 edited
2 moved

Legend:

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

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief HC driver.
     33 * USB address keeping for host controller drivers.
    3434 */
    35 #ifndef LIBUSB_HCD_H_
    36 #define LIBUSB_HCD_H_
     35#ifndef LIBUSB_ADDRKEEP_H_
     36#define LIBUSB_ADDRKEEP_H_
    3737
    3838#include <usb/usb.h>
     
    8181    devman_handle_t);
    8282
    83 
    8483#endif
     84/**
     85 * @}
     86 */
  • uspace/lib/usb/include/usb/classes/classes.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/include/usb/classes/hid.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3737
    3838#include <usb/usb.h>
    39 #include <driver.h>
    4039#include <usb/classes/hidparser.h>
     40#include <usb/descriptor.h>
    4141
    4242/** USB/HID device requests. */
     
    5151} usb_hid_request_t;
    5252
     53typedef enum {
     54        USB_HID_REPORT_TYPE_INPUT = 1,
     55        USB_HID_REPORT_TYPE_OUTPUT = 2,
     56        USB_HID_REPORT_TYPE_FEATURE = 3
     57} usb_hid_report_type_t;
     58
     59typedef enum {
     60        USB_HID_PROTOCOL_BOOT = 0,
     61        USB_HID_PROTOCOL_REPORT = 1
     62} usb_hid_protocol_t;
     63
     64/** USB/HID subclass constants. */
     65typedef enum {
     66        USB_HID_SUBCLASS_NONE = 0,
     67        USB_HID_SUBCLASS_BOOT = 1
     68} usb_hid_subclass_t;
     69
    5370/** USB/HID interface protocols. */
    5471typedef enum {
     
    5673        USB_HID_PROTOCOL_KEYBOARD = 1,
    5774        USB_HID_PROTOCOL_MOUSE = 2
    58 } usb_hid_protocol_t;
     75} usb_hid_iface_protocol_t;
    5976
    6077/** Part of standard USB HID descriptor specifying one class descriptor.
     
    6380 */
    6481typedef struct {
    65         /** Type of class descriptor (Report or Physical). */
    66         uint8_t class_descriptor_type;
    67         /** Length of class descriptor. */
    68         uint16_t class_descriptor_length;
    69 } __attribute__ ((packed)) usb_standard_hid_descriptor_class_item_t;
     82        /** Type of class-specific descriptor (Report or Physical). */
     83        uint8_t type;
     84        /** Length of class-specific descriptor in bytes. */
     85        uint16_t length;
     86} __attribute__ ((packed)) usb_standard_hid_class_descriptor_info_t;
    7087
    7188/** Standard USB HID descriptor.
     
    7390 * (See HID Specification, p.22)
    7491 *
    75  * It is actually only the "header" of the descriptor, as it may have arbitrary
    76  * length if more than one class descritor is provided.
     92 * It is actually only the "header" of the descriptor, it does not contain
     93 * the last two mandatory fields (type and length of the first class-specific
     94 * descriptor).
    7795 */
    7896typedef struct {
    79         /** Size of this descriptor in bytes. */
     97        /** Total size of this descriptor in bytes.
     98         *
     99         * This includes all class-specific descriptor info - type + length
     100         * for each descriptor.
     101         */
    80102        uint8_t length;
    81103        /** Descriptor type (USB_DESCTYPE_HID). */
     
    85107        /** Country code of localized hardware. */
    86108        uint8_t country_code;
    87         /** Total number of class (i.e. Report and Physical) descriptors. */
    88         uint8_t class_count;
    89         /** First mandatory class descriptor info. */
    90         usb_standard_hid_descriptor_class_item_t class_descriptor;
     109        /** Total number of class-specific (i.e. Report and Physical)
     110         * descriptors.
     111         *
     112         * @note There is always only one Report descriptor.
     113         */
     114        uint8_t class_desc_count;
     115        /** First mandatory class descriptor (Report) info. */
     116        usb_standard_hid_class_descriptor_info_t report_desc_info;
    91117} __attribute__ ((packed)) usb_standard_hid_descriptor_t;
    92118
    93 
    94 /**
    95  * @brief USB/HID keyboard device type.
    96  *
    97  * Quite dummy right now.
    98  */
    99 typedef struct {
    100         device_t *device;
    101         usb_address_t address;
    102         usb_endpoint_t poll_endpoint;
    103         usb_hid_report_parser_t *parser;
    104 } usb_hid_dev_kbd_t;
    105119
    106120#endif
  • uspace/lib/usb/include/usb/classes/hidparser.h

    r976f546 r19a1800  
    3737
    3838#include <stdint.h>
    39 #include <adt/list.h>
    40 
    41 #include <hid_report_items.h>
    4239
    4340/**
    44  * Items prefix
     41 * Item prefix
    4542 */
    4643#define USB_HID_ITEM_SIZE(data)         ((uint8_t)(data & 0x3))
     
    6259#define USB_HID_ITEM_FLAG_VOLATILE(flags)       (flags & 0x80)
    6360#define USB_HID_ITEM_FLAG_BUFFERED(flags)       (flags & 0x100)
    64 
    65 
    66 /**
    67  * Collection Item Types
    68  */
    69 #define USB_HID_COLLECTION_TYPE_PHYSICAL                0x00
    70 #define USB_HID_COLLECTION_TYPE_APPLICATION             0x01
    71 #define USB_HID_COLLECTION_TYPE_LOGICAL                 0x02
    72 #define USB_HID_COLLECTION_TYPE_REPORT                  0x03
    73 #define USB_HID_COLLECTION_TYPE_NAMED_ARRAY             0x04
    74 #define USB_HID_COLLECTION_TYPE_USAGE_SWITCH    0x05
    75 
    76 /*
    77  * modifiers definitions
    78  */
    79 #define USB_HID_BOOT_KEYBOARD_NUM_LOCK          0x01
    80 #define USB_HID_BOOT_KEYBOARD_CAPS_LOCK         0x02
    81 #define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK       0x04
    82 #define USB_HID_BOOT_KEYBOARD_COMPOSE           0x08
    83 #define USB_HID_BOOT_KEYBOARD_KANA                      0x10
    8461
    8562
     
    128105
    129106
     107
    130108/** HID parser callbacks for IN items. */
    131109typedef struct {
     
    139117} usb_hid_report_in_callbacks_t;
    140118
     119
     120typedef enum {
     121        USB_HID_MOD_LCTRL = 0x01,
     122        USB_HID_MOD_LSHIFT = 0x02,
     123        USB_HID_MOD_LALT = 0x04,
     124        USB_HID_MOD_LGUI = 0x08,
     125        USB_HID_MOD_RCTRL = 0x10,
     126        USB_HID_MOD_RSHIFT = 0x20,
     127        USB_HID_MOD_RALT = 0x40,
     128        USB_HID_MOD_RGUI = 0x80,
     129        USB_HID_MOD_COUNT = 8
     130} usb_hid_modifiers_t;
     131
     132typedef enum {
     133        USB_HID_LED_NUM_LOCK = 0x1,
     134        USB_HID_LED_CAPS_LOCK = 0x2,
     135        USB_HID_LED_SCROLL_LOCK = 0x4,
     136        USB_HID_LED_COMPOSE = 0x8,
     137        USB_HID_LED_KANA = 0x10,
     138        USB_HID_LED_COUNT = 5
     139} usb_hid_led_t;
     140
     141static const usb_hid_modifiers_t
     142    usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
     143        USB_HID_MOD_LCTRL,
     144        USB_HID_MOD_LSHIFT,
     145        USB_HID_MOD_LALT,
     146        USB_HID_MOD_LGUI,
     147        USB_HID_MOD_RCTRL,
     148        USB_HID_MOD_RSHIFT,
     149        USB_HID_MOD_RALT,
     150        USB_HID_MOD_RGUI
     151};
     152
     153//static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = {
     154//      USB_HID_LED_NUM_LOCK,
     155//      USB_HID_LED_CAPS_LOCK,
     156//      USB_HID_LED_SCROLL_LOCK,
     157//      USB_HID_LED_COMPOSE,
     158//      USB_HID_LED_KANA
     159//};
     160
     161//#define USB_HID_BOOT_KEYBOARD_NUM_LOCK                0x01
     162//#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK               0x02
     163//#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK     0x04
     164//#define USB_HID_BOOT_KEYBOARD_COMPOSE         0x08
     165//#define USB_HID_BOOT_KEYBOARD_KANA                    0x10
     166
     167/*
     168 * modifiers definitions
     169 */
     170
    141171int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
    142172        const usb_hid_report_in_callbacks_t *callbacks, void *arg);
    143173
    144174int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
    145 
    146175
    147176int usb_hid_parser_init(usb_hid_report_parser_t *parser);
     
    157186
    158187void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
     188
    159189#endif
    160190/**
  • uspace/lib/usb/include/usb/classes/hidut.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/include/usb/classes/hidutkbd.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
  • uspace/lib/usb/include/usb/classes/hub.h

    r976f546 r19a1800  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2010 Matus Dekanek
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3333 * @brief USB hub related structures.
    3434 */
    35 #ifndef LIBUSB_HUB_H_
    36 #define LIBUSB_HUB_H_
     35#ifndef LIBUSB_CLASS_HUB_H_
     36#define LIBUSB_CLASS_HUB_H_
    3737
    3838#include <sys/types.h>
    39 #include <usb/hcdhubd.h>
    40 
    4139
    4240/** Hub class feature selector.
     
    6866 *      For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2
    6967 */
    70 typedef struct hub_descriptor_type{
     68typedef struct usb_hub_descriptor_type {
    7169    /** Number of bytes in this descriptor, including this byte */
    7270    //uint8_t bDescLength;
     
    8078    /**
    8179            D1...D0: Logical Power Switching Mode
    82             00: Ganged power switching (all ports power at
     80            00: Ganged power switching (all ports power at
    8381            once)
    8482            01: Individual port power switching
     
    9189            00: Global Over-current Protection. The hub
    9290            reports over-current as a summation of all
    93             ports current draw, without a breakdown of
     91            ports current draw, without a breakdown of
    9492            individual port over-current status.
    9593            01: Individual Port Over-current Protection. The
     
    198196extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE;
    199197
    200 /**
    201  * @brief create uint8_t array with serialized descriptor
    202  *
    203  * @param descriptor
    204  */
    205 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor);
    206 
    207 /**
    208  * @brief create deserialized desriptor structure out of serialized descriptor
    209  *
    210  * The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur.
    211  *
    212  * @param sdescriptor serialized descriptor
    213  */
    214 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor);
    215198
    216199
  • uspace/lib/usb/include/usb/debug.h

    r976f546 r19a1800  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2010-2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3535#ifndef LIBUSB_DEBUG_H_
    3636#define LIBUSB_DEBUG_H_
     37#include <stdio.h>
     38#include <usb/usb.h>
     39#include <assert.h>
    3740
    3841void usb_dprintf(const char *tag, int level, const char *format, ...);
    3942void usb_dprintf_enable(const char *tag, int level);
    4043
     44void usb_dump_standard_descriptor(FILE *, const char *, const char *,
     45    const uint8_t *, size_t);
     46
     47/** Logging level. */
     48typedef enum {
     49        USB_LOG_LEVEL_FATAL,
     50        USB_LOG_LEVEL_ERROR,
     51        USB_LOG_LEVEL_WARNING,
     52        USB_LOG_LEVEL_INFO,
     53        USB_LOG_LEVEL_DEBUG,
     54        USB_LOG_LEVEL_DEBUG2,
     55        USB_LOG_LEVEL_MAX
     56} usb_log_level_t;
     57
     58
     59void usb_log_enable(usb_log_level_t, const char *);
     60
     61void usb_log_printf(usb_log_level_t, const char *, ...);
     62
     63#define usb_log_fatal(format, ...) \
     64        usb_log_printf(USB_LOG_LEVEL_FATAL, format, ##__VA_ARGS__)
     65
     66#define usb_log_error(format, ...) \
     67        usb_log_printf(USB_LOG_LEVEL_ERROR, format, ##__VA_ARGS__)
     68
     69#define usb_log_warning(format, ...) \
     70        usb_log_printf(USB_LOG_LEVEL_WARNING, format, ##__VA_ARGS__)
     71
     72#define usb_log_info(format, ...) \
     73        usb_log_printf(USB_LOG_LEVEL_INFO, format, ##__VA_ARGS__)
     74
     75#define usb_log_debug(format, ...) \
     76        usb_log_printf(USB_LOG_LEVEL_DEBUG, format, ##__VA_ARGS__)
     77
     78#define usb_log_debug2(format, ...) \
     79        usb_log_printf(USB_LOG_LEVEL_DEBUG2, format, ##__VA_ARGS__)
     80
     81
    4182
    4283#endif
     84/**
     85 * @}
     86 */
     87
  • uspace/lib/usb/include/usb/descriptor.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3636#define LIBUSB_DESCRIPTOR_H_
    3737
    38 #include <ipc/ipc.h>
    3938#include <async.h>
    4039
  • uspace/lib/usb/include/usb/dp.h

    r976f546 r19a1800  
    4545} usb_dp_descriptor_nesting_t;
    4646
     47extern usb_dp_descriptor_nesting_t usb_dp_standard_descriptor_nesting[];
     48
    4749typedef struct {
    4850        usb_dp_descriptor_nesting_t *nesting;
  • uspace/lib/usb/include/usb/request.h

    r976f546 r19a1800  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
    3232/** @file
    33  * @brief Standard USB device requests.
     33 * Standard USB requests.
    3434 */
    35 #ifndef LIBUSB_DEVREQ_H_
    36 #define LIBUSB_DEVREQ_H_
     35#ifndef LIBUSB_REQUEST_H_
     36#define LIBUSB_REQUEST_H_
    3737
    38 #include <ipc/ipc.h>
    39 #include <async.h>
     38#include <sys/types.h>
     39#include <l18n/langs.h>
    4040#include <usb/usb.h>
     41#include <usb/pipes.h>
    4142#include <usb/descriptor.h>
    4243
     
    7071        /** Main parameter to the request. */
    7172        union {
     73                uint16_t value;
    7274                /* FIXME: add #ifdefs according to host endianess */
    7375                struct {
     
    7577                        uint8_t value_high;
    7678                };
    77                 uint16_t value;
    7879        };
    7980        /** Auxiliary parameter to the request.
     
    8586} __attribute__ ((packed)) usb_device_request_setup_packet_t;
    8687
     88int usb_control_request_set(usb_endpoint_pipe_t *,
     89    usb_request_type_t, usb_request_recipient_t, uint8_t,
     90    uint16_t, uint16_t, void *, size_t);
    8791
    88 int usb_drv_req_get_status(int, usb_address_t, usb_request_recipient_t,
    89     uint16_t, uint16_t *);
    90 int usb_drv_req_clear_feature(int, usb_address_t, usb_request_recipient_t,
    91     uint16_t, uint16_t);
    92 int usb_drv_req_set_feature(int, usb_address_t, usb_request_recipient_t,
    93     uint16_t, uint16_t);
    94 int usb_drv_req_set_address(int, usb_address_t, usb_address_t);
    95 int usb_drv_req_get_descriptor(int, usb_address_t, usb_request_type_t,
    96     uint8_t, uint8_t, uint16_t, void *, size_t, size_t *);
    97 int usb_drv_req_get_device_descriptor(int, usb_address_t,
     92int usb_control_request_get(usb_endpoint_pipe_t *,
     93    usb_request_type_t, usb_request_recipient_t, uint8_t,
     94    uint16_t, uint16_t, void *, size_t, size_t *);
     95
     96int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t);
     97int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t,
     98    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t,
     99    size_t *);
     100int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t *, usb_request_type_t,
     101    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void **, size_t *);
     102int usb_request_get_device_descriptor(usb_endpoint_pipe_t *,
    98103    usb_standard_device_descriptor_t *);
    99 int usb_drv_req_get_bare_configuration_descriptor(int, usb_address_t, int,
     104int usb_request_get_bare_configuration_descriptor(usb_endpoint_pipe_t *, int,
    100105    usb_standard_configuration_descriptor_t *);
    101 int usb_drv_req_get_full_configuration_descriptor(int, usb_address_t, int,
     106int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *, int,
    102107    void *, size_t, size_t *);
    103 int usb_drv_req_set_descriptor(int, usb_address_t, uint8_t, uint8_t, uint16_t,
    104     void *, size_t);
    105 int usb_drv_req_get_configuration(int, usb_address_t, uint8_t *);
    106 int usb_drv_req_set_configuration(int, usb_address_t, uint8_t);
    107 int usb_drv_req_get_interface(int, usb_address_t, uint16_t, uint8_t *);
    108 int usb_drv_req_set_interface(int, usb_address_t, uint16_t, uint8_t);
     108int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t);
     109
     110int usb_request_get_supported_languages(usb_endpoint_pipe_t *,
     111    l18_win_locales_t **, size_t *);
     112int usb_request_get_string(usb_endpoint_pipe_t *, size_t, l18_win_locales_t,
     113    char **);
    109114
    110115#endif
  • uspace/lib/usb/include/usb/usb.h

    r976f546 r19a1800  
    2727 */
    2828
    29 /** @addtogroup libusb usb
     29/** @addtogroup libusb
    3030 * @{
    3131 */
     
    3737
    3838#include <sys/types.h>
    39 #include <ipc/ipc.h>
     39#include <byteorder.h>
     40
     41/** Convert 16bit value from native (host) endianness to USB endianness. */
     42#define uint16_host2usb(n) host2uint16_t_le((n))
     43
     44/** Convert 32bit value from native (host) endianness to USB endianness. */
     45#define uint32_host2usb(n) host2uint32_t_le((n))
     46
     47/** Convert 16bit value from USB endianness into native (host) one. */
     48#define uint16_usb2host(n) uint16_t_le2host((n))
     49
     50/** Convert 32bit value from USB endianness into native (host) one. */
     51#define uint32_usb2host(n) uint32_t_le2host((n))
     52
    4053
    4154/** USB transfer type. */
     
    5265typedef enum {
    5366        USB_DIRECTION_IN,
    54         USB_DIRECTION_OUT
     67        USB_DIRECTION_OUT,
     68        USB_DIRECTION_BOTH
    5569} usb_direction_t;
     70
     71/** USB speeds. */
     72typedef enum {
     73        /** USB 1.1 low speed (1.5Mbits/s). */
     74        USB_SPEED_LOW,
     75        /** USB 1.1 full speed (12Mbits/s). */
     76        USB_SPEED_FULL,
     77        /** USB 2.0 high speed (480Mbits/s). */
     78        USB_SPEED_HIGH
     79} usb_speed_t;
    5680
    5781/** USB request type target. */
     
    6892        USB_REQUEST_RECIPIENT_ENDPOINT = 2
    6993} usb_request_recipient_t;
    70 
    71 /** USB transaction outcome. */
    72 typedef enum {
    73         USB_OUTCOME_OK,
    74         USB_OUTCOME_CRCERROR,
    75         USB_OUTCOME_BABBLE
    76 } usb_transaction_outcome_t;
    77 
    78 const char * usb_str_transaction_outcome(usb_transaction_outcome_t o);
    7994
    8095/** USB address type.
Note: See TracChangeset for help on using the changeset viewer.