Changeset 9097c16a in mainline for uspace/drv/usbhid/main.c


Ignore:
Timestamp:
2011-02-04T13:14:14Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9e7cdf8
Parents:
11797d5 (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:

Merged development

File:
1 moved

Legend:

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

    r11797d5 r9097c16a  
    11/*
    22 * Copyright (c) 2010 Vojtech Horky
     3 * Copyright (c) 2011 Lubos Slovak
    34 * All rights reserved.
    45 *
     
    2627 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2728 */
     29
     30/** @addtogroup drvusbhid
     31 * @{
     32 */
     33/**
     34 * @file
     35 * Main routines of USB HID driver.
     36 */
     37
    2838#include <usb/usbdrv.h>
    2939#include <driver.h>
     
    3343#include <io/console.h>
    3444#include <errno.h>
     45#include <str_error.h>
    3546#include <fibril.h>
    3647#include <usb/classes/hid.h>
     
    3950#include <usb/descriptor.h>
    4051#include <io/console.h>
     52#include "hid.h"
    4153#include "descparser.h"
    4254#include "descdump.h"
     
    4557
    4658#define BUFFER_SIZE 32
    47 #define NAME "usbkbd"
     59#define NAME "usbhid"
    4860
    4961#define GUESSED_POLL_ENDPOINT 1
     
    369381        if (rc < 0) {
    370382                printf("Problem setting phone to HC.\n");
    371                 free(kbd_dev);
    372                 return NULL;
     383                goto error_leave;
    373384        }
    374385
     
    376387        if (rc < 0) {
    377388                printf("Problem getting address of the device.\n");
    378                 free(kbd_dev);
    379                 return NULL;
     389                goto error_leave;
    380390        }
    381391
     
    387397//      }
    388398
    389         // default endpoint
    390         kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
    391        
    392399        /*
    393400         * will need all descriptors:
     
    400407        usbkbd_process_descriptors(kbd_dev);
    401408
     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
    402433        return kbd_dev;
     434
     435error_leave:
     436        free(kbd_dev);
     437        return NULL;
    403438}
    404439
     
    413448        //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    414449        //    NULL);
    415         printf("Calling usb_hid_boot_keyboard_input_report() with size %d\n",
     450        printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",
    416451            actual_size);
    417452        //dump_buffer("bufffer: ", buffer, actual_size);
     
    425460static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    426461{
    427         int rc;
    428         usb_handle_t handle;
     462        int rc, sess_rc;
    429463        uint8_t buffer[BUFFER_SIZE];
    430464        size_t actual_size;
    431         //usb_endpoint_t poll_endpoint = 1;
    432 
    433 //      usb_address_t my_address = usb_drv_get_my_address(dev->parent_phone,
    434 //          dev);
    435 //      if (my_address < 0) {
    436 //              return;
    437 //      }
    438 
    439         usb_target_t poll_target = {
    440                 .address = kbd_dev->address,
    441                 .endpoint = kbd_dev->poll_endpoint
    442         };
    443465
    444466        printf("Polling keyboard...\n");
     
    446468        while (true) {
    447469                async_usleep(1000 * 1000 * 2);
    448                 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone,
    449                     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);
    450481
    451482                if (rc != EOK) {
    452                         printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
     483                        printf("Error polling the keyboard: %s.\n",
     484                            str_error(rc));
    453485                        continue;
    454486                }
    455487
    456                 rc = usb_drv_async_wait_for(handle);
    457                 if (rc != EOK) {
    458                         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));
    459491                        continue;
    460492                }
     
    557589        return driver_main(&kbd_driver);
    558590}
     591
     592/**
     593 * @}
     594 */
Note: See TracChangeset for help on using the changeset viewer.