Changeset a6567ed in mainline


Ignore:
Timestamp:
2011-03-02T18:54:49Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
820aba32
Parents:
d70e0a3c
Message:

Correct endpoint initialization in mouse driver

Location:
uspace/drv/usbmouse
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmouse/init.c

    rd70e0a3c ra6567ed  
    3636#include "mouse.h"
    3737#include <usb/debug.h>
     38#include <usb/classes/classes.h>
    3839#include <usb/classes/hid.h>
    3940#include <usb/request.h>
    4041#include <errno.h>
    4142
    42 #if 0
    4343/** Mouse polling endpoint description for boot protocol subclass. */
    4444static usb_endpoint_description_t poll_endpoint_description = {
     
    5050        .flags = 0
    5151};
    52 #endif
     52
     53/** Initialize poll pipe.
     54 *
     55 * Expects that session is already started on control pipe zero.
     56 *
     57 * @param mouse Mouse device.
     58 * @param my_interface Interface number.
     59 * @return Error code.
     60 */
     61static int intialize_poll_pipe(usb_mouse_t *mouse, int my_interface)
     62{
     63        assert(usb_endpoint_pipe_is_session_started(&mouse->ctrl_pipe));
     64
     65        int rc;
     66
     67        void *config_descriptor;
     68        size_t config_descriptor_size;
     69
     70        rc = usb_request_get_full_configuration_descriptor_alloc(
     71            &mouse->ctrl_pipe, 0, &config_descriptor, &config_descriptor_size);
     72        if (rc != EOK) {
     73                return rc;
     74        }
     75
     76        usb_endpoint_mapping_t endpoint_mapping[1] = {
     77                {
     78                        .pipe = &mouse->poll_pipe,
     79                        .description = &poll_endpoint_description,
     80                        .interface_no = my_interface
     81                }
     82        };
     83
     84        rc = usb_endpoint_pipe_initialize_from_configuration(endpoint_mapping,
     85            1, config_descriptor, config_descriptor_size, &mouse->wire);
     86        if (rc != EOK) {
     87                return rc;
     88        }
     89
     90        if (!endpoint_mapping[0].present) {
     91                return ENOENT;
     92        }
     93
     94        return EOK;
     95}
    5396
    5497
     
    76119        }
    77120
    78         /* FIXME: initialize to the proper endpoint. */
    79         rc = usb_endpoint_pipe_initialize(&mouse->poll_pipe, &mouse->wire,
    80             1, USB_TRANSFER_INTERRUPT, 8, USB_DIRECTION_IN);
     121        rc = usb_endpoint_pipe_start_session(&mouse->ctrl_pipe);
     122        if (rc != EOK) {
     123                goto leave;
     124        }
     125
     126        rc = intialize_poll_pipe(mouse, usb_device_get_assigned_interface(dev));
     127
     128        /* We can ignore error here. */
     129        usb_endpoint_pipe_end_session(&mouse->ctrl_pipe);
     130
    81131        if (rc != EOK) {
    82132                goto leave;
  • uspace/drv/usbmouse/mouse.c

    rd70e0a3c ra6567ed  
    4646        assert(mouse);
    4747
     48        size_t buffer_size = mouse->poll_pipe.max_packet_size;
     49
     50        if (buffer_size < 4) {
     51                usb_log_error("Weird mouse, results will be skewed.\n");
     52                buffer_size = 4;
     53        }
     54
     55        uint8_t *buffer = malloc(buffer_size);
     56        if (buffer == NULL) {
     57                usb_log_error("Out of memory, poll fibril aborted.\n");
     58                return ENOMEM;
     59        }
     60
    4861        while (true) {
    4962                async_usleep(10 * 1000);
    5063
    51                 uint8_t buffer[8];
    5264                size_t actual_size;
    5365
     
    5567                usb_endpoint_pipe_start_session(&mouse->poll_pipe);
    5668
    57                 usb_endpoint_pipe_read(&mouse->poll_pipe, buffer, 8, &actual_size);
     69                usb_endpoint_pipe_read(&mouse->poll_pipe,
     70                    buffer, buffer_size, &actual_size);
    5871
    5972                usb_endpoint_pipe_end_session(&mouse->poll_pipe);
Note: See TracChangeset for help on using the changeset viewer.