Changeset 74d6e90 in mainline for uspace/lib/usb


Ignore:
Timestamp:
2011-02-04T13:07:32Z (15 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
97e87de
Parents:
621afdb (diff), ff244e6 (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 devel branch

Location:
uspace/lib/usb
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/Makefile

    r621afdb r74d6e90  
    4343        src/hidparser.c \
    4444        src/localdrv.c \
     45        src/pipes.c \
    4546        src/recognise.c \
    4647        src/remotedrv.c \
     48        src/request.c \
    4749        src/usb.c \
    4850        src/usbdrvreq.c \
  • uspace/lib/usb/include/usb/classes/hid.h

    r621afdb r74d6e90  
    3737
    3838#include <usb/usb.h>
    39 #include <driver.h>
    4039#include <usb/classes/hidparser.h>
    4140#include <usb/descriptor.h>
     
    101100} __attribute__ ((packed)) usb_standard_hid_descriptor_t;
    102101
    103 /**
    104  *
    105  */
    106 typedef struct {
    107         usb_standard_interface_descriptor_t iface_desc;
    108         usb_standard_endpoint_descriptor_t *endpoints;
    109         usb_standard_hid_descriptor_t hid_desc;
    110         uint8_t *report_desc;
    111         //usb_standard_hid_class_descriptor_info_t *class_desc_info;
    112         //uint8_t **class_descs;
    113 } usb_hid_iface_t;
    114 
    115 /**
    116  *
    117  */
    118 typedef struct {
    119         usb_standard_configuration_descriptor_t config_descriptor;
    120         usb_hid_iface_t *interfaces;
    121 } usb_hid_configuration_t;
    122 
    123 /**
    124  * @brief USB/HID keyboard device type.
    125  *
    126  * Quite dummy right now.
    127  */
    128 typedef struct {
    129         device_t *device;
    130         usb_hid_configuration_t *conf;
    131         usb_address_t address;
    132         usb_endpoint_t poll_endpoint;
    133         usb_hid_report_parser_t *parser;
    134 } usb_hid_dev_kbd_t;
    135 
    136 // TODO: more configurations!
    137102
    138103#endif
  • uspace/lib/usb/include/usb/debug.h

    r621afdb r74d6e90  
    4747/** Logging level. */
    4848typedef 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
     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
    5556} usb_log_level_t;
    5657
  • uspace/lib/usb/include/usb/usb.h

    r621afdb r74d6e90  
    3737
    3838#include <sys/types.h>
     39#include <byteorder.h>
    3940#include <ipc/ipc.h>
     41
     42/** Convert 16bit value from native (host) endianness to USB endianness. */
     43#define uint16_host2usb(n) host2uint16_t_le((n))
     44
     45/** Convert 32bit value from native (host) endianness to USB endianness. */
     46#define uint32_host2usb(n) host2uint32_t_le((n))
     47
     48/** Convert 16bit value from USB endianness into native (host) one. */
     49#define uint16_usb2host(n) uint16_t_le2host((n))
     50
     51/** Convert 32bit value from USB endianness into native (host) one. */
     52#define uint32_usb2host(n) uint32_t_le2host((n))
     53
    4054
    4155/** USB transfer type. */
     
    5266typedef enum {
    5367        USB_DIRECTION_IN,
    54         USB_DIRECTION_OUT
     68        USB_DIRECTION_OUT,
     69        USB_DIRECTION_BOTH
    5570} usb_direction_t;
    5671
  • uspace/lib/usb/include/usb/usbdrv.h

    r621afdb r74d6e90  
    7070    usb_handle_t *);
    7171
     72int usb_drv_async_control_write(int, usb_target_t,
     73    void *, size_t, void *, size_t, usb_handle_t *);
     74
    7275int usb_drv_psync_control_write_setup(int, usb_target_t, void *, size_t);
    7376int usb_drv_psync_control_write_data(int, usb_target_t, void *, size_t);
     
    7780    void *, size_t, void *, size_t);
    7881
    79 
    8082int usb_drv_async_control_read_setup(int, usb_target_t,
    8183    void *, size_t, usb_handle_t *);
     
    8486int usb_drv_async_control_read_status(int, usb_target_t,
    8587    usb_handle_t *);
     88
     89int usb_drv_async_control_read(int, usb_target_t,
     90    void *, size_t, void *, size_t, size_t *, usb_handle_t *);
    8691
    8792int usb_drv_psync_control_read_setup(int, usb_target_t, void *, size_t);
  • uspace/lib/usb/src/debug.c

    r621afdb r74d6e90  
    6767/** Serialization mutex for logging functions. */
    6868static FIBRIL_MUTEX_INITIALIZE(log_serializer);
     69static FILE *log_stream = NULL;
    6970
    7071/** Find or create new tag with given name.
     
    171172        log_prefix = message_prefix;
    172173        log_level = level;
     174        if (log_stream == NULL) {
     175                char *fname;
     176                int rc = asprintf(&fname, "/log/%s", message_prefix);
     177                if (rc > 0) {
     178                        log_stream = fopen(fname, "w");
     179                        free(fname);
     180                }
     181        }
    173182}
    174183
     
    197206void usb_log_printf(usb_log_level_t level, const char *format, ...)
    198207{
    199         if (level > log_level) {
    200                 return;
    201         }
    202 
    203208        FILE *stream = NULL;
    204209        switch (level) {
     
    216221        va_start(args, format);
    217222
     223        /*
     224         * Serialize access to log files.
     225         * Always print to log file, to screen print only when the enabled
     226         * log level is high enough.
     227         */
    218228        fibril_mutex_lock(&log_serializer);
    219         fprintf(stream, "[%s]%s: ", log_prefix, log_level_name(level));
    220         vfprintf(stream, format, args);
     229
     230        const char *level_name = log_level_name(level);
     231
     232        if (log_stream != NULL) {
     233                fprintf(log_stream, "[%s]%s: ", log_prefix, level_name);
     234                vfprintf(log_stream, format, args);
     235        }
     236
     237        if (level <= log_level) {
     238                fprintf(stream, "[%s]%s: ", log_prefix, level_name);
     239                vfprintf(stream, format, args);
     240        }
     241
    221242        fibril_mutex_unlock(&log_serializer);
    222243
  • uspace/lib/usb/src/usbdrv.c

    r621afdb r74d6e90  
    495495}
    496496
     497/** Issue whole control write transfer. */
     498int usb_drv_async_control_write(int phone, usb_target_t target,
     499    void *setup_packet, size_t setup_packet_size,
     500    void *buffer, size_t buffer_size,
     501    usb_handle_t *handle)
     502{
     503        // FIXME - check input parameters instead of asserting them
     504        assert(phone > 0);
     505        assert(setup_packet != NULL);
     506        assert(setup_packet_size > 0);
     507        assert(buffer != NULL);
     508        assert(buffer_size > 0);
     509        assert(handle != NULL);
     510
     511        transfer_info_t *transfer
     512            = (transfer_info_t *) malloc(sizeof(transfer_info_t));
     513        if (transfer == NULL) {
     514                return ENOMEM;
     515        }
     516
     517        transfer->size_transferred = NULL;
     518        transfer->buffer = NULL;
     519        transfer->size = 0;
     520        transfer->phone = phone;
     521
     522        int rc;
     523
     524        transfer->request = async_send_3(phone,
     525            DEV_IFACE_ID(USBHC_DEV_IFACE),
     526            IPC_M_USBHC_CONTROL_WRITE,
     527            target.address, target.endpoint,
     528            &transfer->reply);
     529
     530        rc = async_data_write_start(phone, setup_packet, setup_packet_size);
     531        if (rc != EOK) {
     532                async_wait_for(transfer->request, NULL);
     533                return rc;
     534        }
     535
     536        rc = async_data_write_start(phone, buffer, buffer_size);
     537        if (rc != EOK) {
     538                async_wait_for(transfer->request, NULL);
     539                return rc;
     540        }
     541
     542        *handle = (usb_handle_t) transfer;
     543
     544        return EOK;
     545}
     546
    497547/** Start control read transfer. */
    498548int usb_drv_async_control_read_setup(int phone, usb_target_t target,
     
    530580}
    531581
     582/** Issue whole control read transfer. */
     583int usb_drv_async_control_read(int phone, usb_target_t target,
     584    void *setup_packet, size_t setup_packet_size,
     585    void *buffer, size_t buffer_size, size_t *actual_size,
     586    usb_handle_t *handle)
     587{
     588        // FIXME - check input parameters instead of asserting them
     589        assert(phone > 0);
     590        assert(setup_packet != NULL);
     591        assert(setup_packet_size > 0);
     592        assert(buffer != NULL);
     593        assert(buffer_size > 0);
     594        assert(handle != NULL);
     595
     596        transfer_info_t *transfer
     597            = (transfer_info_t *) malloc(sizeof(transfer_info_t));
     598        if (transfer == NULL) {
     599                return ENOMEM;
     600        }
     601
     602        transfer->size_transferred = actual_size;
     603        transfer->buffer = buffer;
     604        transfer->size = buffer_size;
     605        transfer->phone = phone;
     606
     607        int rc;
     608
     609        transfer->request = async_send_4(phone,
     610            DEV_IFACE_ID(USBHC_DEV_IFACE),
     611            IPC_M_USBHC_CONTROL_READ,
     612            target.address, target.endpoint,
     613            buffer_size,
     614            &transfer->reply);
     615
     616        rc = async_data_write_start(phone, setup_packet, setup_packet_size);
     617        if (rc != EOK) {
     618                async_wait_for(transfer->request, NULL);
     619                return rc;
     620        }
     621
     622        *handle = (usb_handle_t) transfer;
     623
     624        return EOK;
     625}
     626
    532627/**
    533628 * @}
Note: See TracChangeset for help on using the changeset viewer.