Changeset 74d6e90 in mainline for uspace/drv/usbhid/main.c


Ignore:
Timestamp:
2011-02-04T13:07:32Z (13 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/main.c

    r621afdb r74d6e90  
    4343#include <io/console.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <fibril.h>
    4647#include <usb/classes/hid.h>
     
    4950#include <usb/descriptor.h>
    5051#include <io/console.h>
     52#include "hid.h"
    5153#include "descparser.h"
    5254#include "descdump.h"
     
    379381        if (rc < 0) {
    380382                printf("Problem setting phone to HC.\n");
    381                 free(kbd_dev);
    382                 return NULL;
     383                goto error_leave;
    383384        }
    384385
     
    386387        if (rc < 0) {
    387388                printf("Problem getting address of the device.\n");
    388                 free(kbd_dev);
    389                 return NULL;
     389                goto error_leave;
    390390        }
    391391
     
    397397//      }
    398398
    399         // default endpoint
    400         kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
    401        
    402399        /*
    403400         * will need all descriptors:
     
    410407        usbkbd_process_descriptors(kbd_dev);
    411408
     409
     410
     411        /*
     412         * Initialize the backing connection to the host controller.
     413         */
     414        rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);
     415        if (rc != EOK) {
     416                printf("Problem initializing connection to device: %s.\n",
     417                    str_error(rc));
     418                goto error_leave;
     419        }
     420
     421        /*
     422         * Initialize device pipes.
     423         */
     424        rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,
     425            GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
     426        if (rc != EOK) {
     427                printf("Failed to initialize interrupt in pipe: %s.\n",
     428                    str_error(rc));
     429                goto error_leave;
     430        }
     431
     432
    412433        return kbd_dev;
     434
     435error_leave:
     436        free(kbd_dev);
     437        return NULL;
    413438}
    414439
     
    435460static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    436461{
    437         int rc;
    438         usb_handle_t handle;
     462        int rc, sess_rc;
    439463        uint8_t buffer[BUFFER_SIZE];
    440464        size_t actual_size;
    441         //usb_endpoint_t poll_endpoint = 1;
    442 
    443 //      usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
    444 //          dev);
    445 //      if (my_address < 0) {
    446 //              return;
    447 //      }
    448 
    449         usb_target_t poll_target = {
    450                 .address = kbd_dev->address,
    451                 .endpoint = kbd_dev->poll_endpoint
    452         };
    453465
    454466        printf("Polling keyboard...\n");
     
    456468        while (true) {
    457469                async_usleep(1000 * 1000 * 2);
    458                 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    459                     poll_target, buffer, BUFFER_SIZE, &actual_size, &handle);
     470
     471                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
     472                if (sess_rc != EOK) {
     473                        printf("Failed to start a session: %s.\n",
     474                            str_error(sess_rc));
     475                        continue;
     476                }
     477
     478                rc = usb_endpoint_pipe_read(&kbd_dev->poll_pipe, buffer,
     479                    BUFFER_SIZE, &actual_size);
     480                sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->poll_pipe);
    460481
    461482                if (rc != EOK) {
    462                         printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
     483                        printf("Error polling the keyboard: %s.\n",
     484                            str_error(rc));
    463485                        continue;
    464486                }
    465487
    466                 rc = usb_drv_async_wait_for(handle);
    467                 if (rc != EOK) {
    468                         printf("Error in usb_drv_async_wait_for(): %d\n", rc);
     488                if (sess_rc != EOK) {
     489                        printf("Error closing session: %s.\n",
     490                            str_error(sess_rc));
    469491                        continue;
    470492                }
Note: See TracChangeset for help on using the changeset viewer.