Ignore:
File:
1 edited

Legend:

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

    r66d5062 r0484d92  
    4343#include <io/console.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <fibril.h>
    4647#include <usb/classes/hid.h>
    4748#include <usb/classes/hidparser.h>
    48 #include <usb/devreq.h>
     49#include <usb/request.h>
    4950#include <usb/descriptor.h>
    5051#include <io/console.h>
     52#include "hid.h"
    5153#include "descparser.h"
    5254#include "descdump.h"
     
    278280               
    279281                // get the descriptor from the device
    280                 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
    281                     kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
    282                     0, i, kbd_dev->conf->interfaces[i].report_desc, length,
     282                int rc = usb_request_get_descriptor(&kbd_dev->ctrl_pipe,
     283                    USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
     284                    i, 0,
     285                    kbd_dev->conf->interfaces[i].report_desc, length,
    283286                    &actual_size);
    284287
     
    301304        usb_standard_configuration_descriptor_t config_desc;
    302305       
    303         int rc = usb_drv_req_get_bare_configuration_descriptor(
    304             kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
     306        int rc;
     307        rc = usb_request_get_bare_configuration_descriptor(&kbd_dev->ctrl_pipe,
     308            0, &config_desc);
    305309       
    306310        if (rc != EOK) {
     
    316320        size_t transferred = 0;
    317321        // get full configuration descriptor
    318         rc = usb_drv_req_get_full_configuration_descriptor(
    319             kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
     322        rc = usb_request_get_full_configuration_descriptor(&kbd_dev->ctrl_pipe,
     323            0, descriptors,
    320324            config_desc.total_length, &transferred);
    321325       
     
    364368static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    365369{
     370        int rc;
     371
    366372        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    367373            sizeof(usb_hid_dev_kbd_t));
     
    374380        kbd_dev->device = dev;
    375381
    376         // get phone to my HC and save it as my parent's phone
    377         // TODO: maybe not a good idea if DDF will use parent_phone
    378         int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    379         if (rc < 0) {
    380                 printf("Problem setting phone to HC.\n");
    381                 free(kbd_dev);
    382                 return NULL;
    383         }
    384 
    385         rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
    386         if (rc < 0) {
    387                 printf("Problem getting address of the device.\n");
    388                 free(kbd_dev);
    389                 return NULL;
    390         }
    391 
    392         // doesn't matter now that we have no address
    393 //      if (kbd_dev->address < 0) {
    394 //              fprintf(stderr, NAME ": No device address!\n");
    395 //              free(kbd_dev);
    396 //              return NULL;
    397 //      }
    398 
    399         // default endpoint
    400         kbd_dev->poll_endpoint = GUESSED_POLL_ENDPOINT;
    401        
     382        /*
     383         * Initialize the backing connection to the host controller.
     384         */
     385        rc = usb_device_connection_initialize_from_device(&kbd_dev->wire, dev);
     386        if (rc != EOK) {
     387                printf("Problem initializing connection to device: %s.\n",
     388                    str_error(rc));
     389                goto error_leave;
     390        }
     391
     392        /*
     393         * Initialize device pipes.
     394         */
     395        rc = usb_endpoint_pipe_initialize_default_control(&kbd_dev->ctrl_pipe,
     396            &kbd_dev->wire);
     397        if (rc != EOK) {
     398                printf("Failed to initialize default control pipe: %s.\n",
     399                    str_error(rc));
     400                goto error_leave;
     401        }
     402
     403        rc = usb_endpoint_pipe_initialize(&kbd_dev->poll_pipe, &kbd_dev->wire,
     404            GUESSED_POLL_ENDPOINT, USB_TRANSFER_INTERRUPT, USB_DIRECTION_IN);
     405        if (rc != EOK) {
     406                printf("Failed to initialize interrupt in pipe: %s.\n",
     407                    str_error(rc));
     408                goto error_leave;
     409        }
     410
    402411        /*
    403412         * will need all descriptors:
    404          * 1) choose one configuration from configuration descriptors 
     413         * 1) choose one configuration from configuration descriptors
    405414         *    (set it to the device)
    406415         * 2) set endpoints from endpoint descriptors
     
    408417
    409418        // TODO: get descriptors, parse descriptors and save endpoints
     419        usb_endpoint_pipe_start_session(&kbd_dev->ctrl_pipe);
    410420        usbkbd_process_descriptors(kbd_dev);
     421        usb_endpoint_pipe_end_session(&kbd_dev->ctrl_pipe);
    411422
    412423        return kbd_dev;
     424
     425error_leave:
     426        free(kbd_dev);
     427        return NULL;
    413428}
    414429
     
    435450static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    436451{
    437         int rc;
    438         usb_handle_t handle;
     452        int rc, sess_rc;
    439453        uint8_t buffer[BUFFER_SIZE];
    440454        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         };
    453455
    454456        printf("Polling keyboard...\n");
     
    456458        while (true) {
    457459                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);
     460
     461                sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe);
     462                if (sess_rc != EOK) {
     463                        printf("Failed to start a session: %s.\n",
     464                            str_error(sess_rc));
     465                        continue;
     466                }
     467
     468                rc = usb_endpoint_pipe_read(&kbd_dev->poll_pipe, buffer,
     469                    BUFFER_SIZE, &actual_size);
     470                sess_rc = usb_endpoint_pipe_end_session(&kbd_dev->poll_pipe);
    460471
    461472                if (rc != EOK) {
    462                         printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);
     473                        printf("Error polling the keyboard: %s.\n",
     474                            str_error(rc));
    463475                        continue;
    464476                }
    465477
    466                 rc = usb_drv_async_wait_for(handle);
    467                 if (rc != EOK) {
    468                         printf("Error in usb_drv_async_wait_for(): %d\n", rc);
     478                if (sess_rc != EOK) {
     479                        printf("Error closing session: %s.\n",
     480                            str_error(sess_rc));
    469481                        continue;
    470482                }
Note: See TracChangeset for help on using the changeset viewer.