Changeset 1537ba6 in mainline for uspace/drv


Ignore:
Timestamp:
2011-02-02T10:19:13Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
93f8da1
Parents:
0b31409 (diff), b00849e (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 development/ changes

Location:
uspace/drv
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/descdump.h

    r0b31409 r1537ba6  
    3737#define USBHID_DESCDUMP_H_
    3838
    39 #include <usb/classes/hid.h>
     39#include "hid.h"
    4040
    4141void dump_standard_configuration_descriptor(
  • uspace/drv/usbhid/descparser.h

    r0b31409 r1537ba6  
    3737#define USBHID_DESCPARSER_H_
    3838
    39 #include <usb/classes/hid.h>
     39#include "hid.h"
    4040
    4141int usbkbd_parse_descriptors(const uint8_t *data, size_t size,
  • uspace/drv/usbhid/main.c

    r0b31409 r1537ba6  
    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                }
  • uspace/drv/vhc/connhost.c

    r0b31409 r1537ba6  
    4242#include "hc.h"
    4343
     44
    4445typedef struct {
    4546        usb_direction_t direction;
     
    4748        usbhc_iface_transfer_in_callback_t in_callback;
    4849        device_t *dev;
     50        size_t reported_size;
    4951        void *arg;
    5052} transfer_info_t;
    5153
     54typedef struct {
     55        usb_direction_t direction;
     56        usb_target_t target;
     57        usbhc_iface_transfer_out_callback_t out_callback;
     58        usbhc_iface_transfer_in_callback_t in_callback;
     59        device_t *dev;
     60        void *arg;
     61        void *data_buffer;
     62        size_t data_buffer_size;
     63} control_transfer_info_t;
     64
    5265static void universal_callback(void *buffer, size_t size,
    5366    usb_transaction_outcome_t outcome, void *arg)
    5467{
    5568        transfer_info_t *transfer = (transfer_info_t *) arg;
     69
     70        if (transfer->reported_size != (size_t) -1) {
     71                size = transfer->reported_size;
     72        }
    5673
    5774        switch (transfer->direction) {
     
    84101        transfer->arg = arg;
    85102        transfer->dev = dev;
     103        transfer->reported_size = (size_t) -1;
     104
     105        return transfer;
     106}
     107
     108static void control_abort_prematurely(control_transfer_info_t *transfer,
     109    size_t size, usb_transaction_outcome_t outcome)
     110{
     111        switch (transfer->direction) {
     112                case USB_DIRECTION_IN:
     113                        transfer->in_callback(transfer->dev,
     114                            outcome, size,
     115                            transfer->arg);
     116                        break;
     117                case USB_DIRECTION_OUT:
     118                        transfer->out_callback(transfer->dev,
     119                            outcome,
     120                            transfer->arg);
     121                        break;
     122                default:
     123                        assert(false && "unreachable");
     124                        break;
     125        }
     126}
     127
     128static void control_callback_two(void *buffer, size_t size,
     129    usb_transaction_outcome_t outcome, void *arg)
     130{
     131        control_transfer_info_t *ctrl_transfer = (control_transfer_info_t *) arg;
     132
     133        if (outcome != USB_OUTCOME_OK) {
     134                control_abort_prematurely(ctrl_transfer, outcome, size);
     135                free(ctrl_transfer);
     136                return;
     137        }
     138
     139        transfer_info_t *transfer  = create_transfer_info(ctrl_transfer->dev,
     140            ctrl_transfer->direction, ctrl_transfer->arg);
     141        transfer->out_callback = ctrl_transfer->out_callback;
     142        transfer->in_callback = ctrl_transfer->in_callback;
     143        transfer->reported_size = size;
     144
     145        switch (ctrl_transfer->direction) {
     146                case USB_DIRECTION_IN:
     147                        hc_add_transaction_to_device(false, ctrl_transfer->target,
     148                            USB_TRANSFER_CONTROL,
     149                            NULL, 0,
     150                            universal_callback, transfer);
     151                        break;
     152                case USB_DIRECTION_OUT:
     153                        hc_add_transaction_from_device(ctrl_transfer->target,
     154                            USB_TRANSFER_CONTROL,
     155                            NULL, 0,
     156                            universal_callback, transfer);
     157                        break;
     158                default:
     159                        assert(false && "unreachable");
     160                        break;
     161        }
     162
     163        free(ctrl_transfer);
     164}
     165
     166static void control_callback_one(void *buffer, size_t size,
     167    usb_transaction_outcome_t outcome, void *arg)
     168{
     169        control_transfer_info_t *transfer = (control_transfer_info_t *) arg;
     170
     171        if (outcome != USB_OUTCOME_OK) {
     172                control_abort_prematurely(transfer, outcome, size);
     173                free(transfer);
     174                return;
     175        }
     176
     177        switch (transfer->direction) {
     178                case USB_DIRECTION_IN:
     179                        hc_add_transaction_from_device(transfer->target,
     180                            USB_TRANSFER_CONTROL,
     181                            transfer->data_buffer, transfer->data_buffer_size,
     182                            control_callback_two, transfer);
     183                        break;
     184                case USB_DIRECTION_OUT:
     185                        hc_add_transaction_to_device(false, transfer->target,
     186                            USB_TRANSFER_CONTROL,
     187                            transfer->data_buffer, transfer->data_buffer_size,
     188                            control_callback_two, transfer);
     189                        break;
     190                default:
     191                        assert(false && "unreachable");
     192                        break;
     193        }
     194}
     195
     196static control_transfer_info_t *create_control_transfer_info(device_t *dev,
     197    usb_direction_t direction, usb_target_t target,
     198    void *data_buffer, size_t data_buffer_size,
     199    void *arg)
     200{
     201        control_transfer_info_t *transfer
     202            = malloc(sizeof(control_transfer_info_t));
     203
     204        transfer->direction = direction;
     205        transfer->target = target;
     206        transfer->in_callback = NULL;
     207        transfer->out_callback = NULL;
     208        transfer->arg = arg;
     209        transfer->dev = dev;
     210        transfer->data_buffer = data_buffer;
     211        transfer->data_buffer_size = data_buffer_size;
    86212
    87213        return transfer;
     
    193319}
    194320
     321static int control_write(device_t *dev, usb_target_t target,
     322    void *setup_packet, size_t setup_packet_size,
     323    void *data, size_t data_size,
     324    usbhc_iface_transfer_out_callback_t callback, void *arg)
     325{
     326        control_transfer_info_t *transfer
     327            = create_control_transfer_info(dev, USB_DIRECTION_OUT, target,
     328            data, data_size, arg);
     329        transfer->out_callback = callback;
     330
     331        hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL,
     332            setup_packet, setup_packet_size,
     333            control_callback_one, transfer);
     334
     335        return EOK;
     336}
     337
    195338static int control_read_setup(device_t *dev, usb_target_t target,
    196339    void *data, size_t size,
     
    217360            NULL, 0,
    218361            callback, arg);
     362}
     363
     364static int control_read(device_t *dev, usb_target_t target,
     365    void *setup_packet, size_t setup_packet_size,
     366    void *data, size_t data_size,
     367    usbhc_iface_transfer_in_callback_t callback, void *arg)
     368{
     369        control_transfer_info_t *transfer
     370            = create_control_transfer_info(dev, USB_DIRECTION_IN, target,
     371            data, data_size, arg);
     372        transfer->in_callback = callback;
     373
     374        hc_add_transaction_to_device(true, target, USB_TRANSFER_CONTROL,
     375            setup_packet, setup_packet_size,
     376            control_callback_one, transfer);
     377
     378        return EOK;
    219379}
    220380
     
    290450        .control_write_status = control_write_status,
    291451
     452        .control_write = control_write,
     453
    292454        .control_read_setup = control_read_setup,
    293455        .control_read_data = control_read_data,
    294         .control_read_status = control_read_status
     456        .control_read_status = control_read_status,
     457
     458        .control_read = control_read
    295459};
    296460
Note: See TracChangeset for help on using the changeset viewer.