Changeset c6cb76d in mainline for uspace/lib/usb/src


Ignore:
Timestamp:
2011-04-08T20:19:48Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
297341b
Parents:
7dfc06fa (diff), 61727bf (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/lib/usb/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/devpoll.c

    r7dfc06fa rc6cb76d  
    6666        usb_pipe_t *pipe
    6767            = polling_data->dev->pipes[polling_data->pipe_index].pipe;
     68       
     69        usb_log_debug("Pipe interface number: %d, protocol: %d, subclass: %d, max packet size: %d\n",
     70            polling_data->dev->pipes[polling_data->pipe_index].interface_no,
     71            polling_data->dev->pipes[polling_data->pipe_index].description->interface_protocol,
     72            polling_data->dev->pipes[polling_data->pipe_index].description->interface_subclass,
     73            pipe->max_packet_size);
    6874
    6975        size_t failed_attempts = 0;
     
    8389                /* Quit the session regardless of errors. */
    8490                usb_pipe_end_session(pipe);
     91               
     92//              if (rc == ESTALL) {
     93//                      usb_log_debug("Seding clear feature...\n");
     94//                      usb_request_clear_feature(pipe, USB_REQUEST_TYPE_STANDARD,
     95//                        USB_REQUEST_RECIPIENT_ENDPOINT, 0, pipe->endpoint_no);
     96//                      continue;
     97//              }
    8598
    8699                if (rc != EOK) {
  • uspace/lib/usb/src/hidparser.c

    r7dfc06fa rc6cb76d  
    6464int usb_hid_report_reset_local_items();
    6565void usb_hid_free_report_list(link_t *head);
    66 
     66usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item);
    6767/*
    6868 * Data translation private functions
     
    106106    list_initialize(&(parser->feature));
    107107
     108        list_initialize(&(parser->stack));
     109
     110        parser->use_report_id = 0;
    108111    return EOK;   
    109112}
     
    186189                                        tmp_usage_path = NULL;
    187190
     191                                        usb_hid_report_path_set_report_id(report_item->usage_path, report_item->id);   
     192                                        if(report_item->id != 0){
     193                                                parser->use_report_id = 1;
     194                                        }
    188195                                       
    189196                                        switch(tag) {
     
    215222                                        if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
    216223                                                return ENOMEM;
    217                                         }
     224                                        }                                       
    218225                                        memcpy(new_report_item,report_item, sizeof(usb_hid_report_item_t));
     226                                        link_initialize(&(new_report_item->link));
     227                                       
    219228                                        /* reset local items */
    220229                                        new_report_item->usage_minimum = 0;
    221230                                        new_report_item->usage_maximum = 0;
     231                                        new_report_item->designator_index = 0;
     232                                        new_report_item->designator_minimum = 0;
     233                                        new_report_item->designator_maximum = 0;
     234                                        new_report_item->string_index = 0;
     235                                        new_report_item->string_minimum = 0;
     236                                        new_report_item->string_maximum = 0;
     237
     238                                        /* reset usage from current usage path */
     239                                        usb_hid_report_usage_path_t *path = list_get_instance(&usage_path->link, usb_hid_report_usage_path_t, link);
     240                                        path->usage = 0;
    222241                                       
    223                                         link_initialize(&(new_report_item->link));
    224242                                        report_item = new_report_item;
    225243                                                                               
     
    227245                                case USB_HID_REPORT_TAG_PUSH:
    228246                                        // push current state to stack
    229                                         // not yet implemented
     247                                        new_report_item = usb_hid_report_item_clone(report_item);
     248                                        list_prepend (&parser->stack, &new_report_item->link);
     249                                       
    230250                                        break;
    231251                                case USB_HID_REPORT_TAG_POP:
    232252                                        // restore current state from stack
    233                                         // not yet implemented                                             
     253                                        if(list_empty (&parser->stack)) {
     254                                                return EINVAL;
     255                                        }
     256                                       
     257                                        report_item = list_get_instance(&parser->stack, usb_hid_report_item_t, link);
     258                                        list_remove (parser->stack.next);
     259                                       
    234260                                        break;
    235261                                       
     
    647673        }
    648674
     675        parser->use_report_id = 0;
     676
    649677        usb_hid_free_report_list(&parser->input);
    650678        usb_hid_free_report_list(&parser->output);
     
    676704        size_t i=0;
    677705        size_t j=0;
     706        uint8_t report_id = 0;
    678707
    679708        if(parser == NULL) {
     
    686715        if(!(keys = malloc(sizeof(uint8_t) * key_count))){
    687716                return ENOMEM;
     717        }
     718
     719        if(parser->use_report_id != 0) {
     720                report_id = data[0];
     721                usb_hid_report_path_set_report_id(path, report_id);
    688722        }
    689723
     
    693727
    694728                item = list_get_instance(list_item, usb_hid_report_item_t, link);
     729
    695730                if(!USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) &&
    696731                   (usb_hid_report_compare_usage_path(item->usage_path, path, flags) == EOK)) {
     
    715750        }
    716751
    717         callbacks->keyboard(keys, key_count, 0, arg);
     752        callbacks->keyboard(keys, key_count, report_id, arg);
    718753           
    719754        free(keys);     
     
    739774        int32_t mask;
    740775        const uint8_t *foo;
    741        
     776
    742777        // now only common numbers llowed
    743778        if(item->size > 32) {
     
    758793                (usb_pow(10,(item->unit_exponent))));
    759794        }
     795
    760796        offset = item->offset + (j * item->size);
     797        if(item->id != 0) {
     798                offset += 8;
     799                usb_log_debug("MOVED OFFSET BY 1Byte, REPORT_ID(%d)\n", item->id);
     800        }
    761801       
    762802        // FIXME
     
    942982
    943983        int only_page;
     984
     985        if(report_path->report_id != path->report_id) {
     986                return 1;
     987        }
    944988
    945989        if(path->depth == 0){
     
    10381082        else {
    10391083                path->depth = 0;
     1084                path->report_id = 0;
    10401085                list_initialize(&path->link);
    10411086                return path;
     
    11551200                return 0;
    11561201        }
    1157        
     1202
    11581203        item = parser->output.next;
    11591204        while(&parser->output != item) {
     
    11951240        int length;
    11961241        int32_t tmp_value;
     1242        size_t offset_prefix = 0;
    11971243       
    11981244        if(parser == NULL) {
    11991245                return EINVAL;
     1246        }
     1247
     1248        if(parser->use_report_id != 0) {
     1249                buffer[0] = path->report_id;
     1250                offset_prefix = 8;
    12001251        }
    12011252
     
    12181269//                              // variable item
    12191270                                value = usb_hid_translate_data_reverse(report_item, data[idx++]);
    1220                                 offset = report_item->offset + (i * report_item->size);
     1271                                offset = report_item->offset + (i * report_item->size) + offset_prefix;
    12211272                                length = report_item->size;
    12221273                        }
     
    12241275                                //bitmap
    12251276                                value += usb_hid_translate_data_reverse(report_item, data[idx++]);
    1226                                 offset = report_item->offset;
     1277                                offset = report_item->offset + offset_prefix;
    12271278                                length = report_item->size * report_item->count;
    12281279                        }
     
    13231374
    13241375
     1376int usb_hid_report_path_set_report_id(usb_hid_report_path_t *path, uint8_t report_id)
     1377{
     1378        if(path == NULL){
     1379                return EINVAL;
     1380        }
     1381
     1382        path->report_id = report_id;
     1383        return EOK;
     1384}
     1385
     1386
     1387usb_hid_report_item_t *usb_hid_report_item_clone(const usb_hid_report_item_t *item)
     1388{
     1389        usb_hid_report_item_t *new_report_item;
     1390       
     1391        if(!(new_report_item = malloc(sizeof(usb_hid_report_item_t)))) {
     1392                return NULL;
     1393        }                                       
     1394        memcpy(new_report_item,item, sizeof(usb_hid_report_item_t));
     1395        link_initialize(&(new_report_item->link));
     1396
     1397        return new_report_item;
     1398}
     1399
    13251400/**
    13261401 * @}
  • uspace/lib/usb/src/hidreport.c

    r7dfc06fa rc6cb76d  
    8080                d = usb_dp_get_sibling_descriptor(&parser, &parser_data,
    8181                    dev->descriptors.configuration, d);
     82                ++i;
    8283        }
    8384       
  • uspace/lib/usb/src/host/batch.c

    r7dfc06fa rc6cb76d  
    7979        instance->error = EOK;
    8080        instance->ep = ep;
     81        endpoint_use(instance->ep);
    8182}
    8283/*----------------------------------------------------------------------------*/
     
    8687 *
    8788 */
    88 void usb_transfer_batch_finish(usb_transfer_batch_t *instance, int error)
     89void usb_transfer_batch_finish(usb_transfer_batch_t *instance)
    8990{
    9091        assert(instance);
    91         instance->error = error;
     92        assert(instance->ep);
     93        endpoint_release(instance->ep);
    9294        instance->next_step(instance);
    9395}
  • uspace/lib/usb/src/host/device_keeper.c

    r7dfc06fa rc6cb76d  
    264264        return instance->devices[address].speed;
    265265}
    266 /*----------------------------------------------------------------------------*/
    267 void usb_device_keeper_use_control(
    268     usb_device_keeper_t *instance, usb_target_t target)
    269 {
    270         assert(instance);
    271         const uint16_t ep = 1 << target.endpoint;
    272         fibril_mutex_lock(&instance->guard);
    273         while (instance->devices[target.address].control_used & ep) {
    274                 fibril_condvar_wait(&instance->change, &instance->guard);
    275         }
    276         instance->devices[target.address].control_used |= ep;
    277         fibril_mutex_unlock(&instance->guard);
    278 }
    279 /*----------------------------------------------------------------------------*/
    280 void usb_device_keeper_release_control(
    281     usb_device_keeper_t *instance, usb_target_t target)
    282 {
    283         assert(instance);
    284         const uint16_t ep = 1 << target.endpoint;
    285         fibril_mutex_lock(&instance->guard);
    286         assert((instance->devices[target.address].control_used & ep) != 0);
    287         instance->devices[target.address].control_used &= ~ep;
    288         fibril_mutex_unlock(&instance->guard);
    289         fibril_condvar_signal(&instance->change);
    290 }
    291266/**
    292267 * @}
  • uspace/lib/usb/src/host/endpoint.c

    r7dfc06fa rc6cb76d  
    3434 */
    3535
     36#include <assert.h>
    3637#include <errno.h>
    3738#include <usb/host/endpoint.h>
     
    4950        instance->max_packet_size = max_packet_size;
    5051        instance->toggle = 0;
     52        instance->active = false;
     53        fibril_mutex_initialize(&instance->guard);
     54        fibril_condvar_initialize(&instance->avail);
    5155        link_initialize(&instance->same_device_eps);
    5256        return EOK;
     
    5660{
    5761        assert(instance);
     62        assert(!instance->active);
    5863        list_remove(&instance->same_device_eps);
    5964        free(instance);
     65}
     66/*----------------------------------------------------------------------------*/
     67void endpoint_use(endpoint_t *instance)
     68{
     69        assert(instance);
     70        fibril_mutex_lock(&instance->guard);
     71        while (instance->active)
     72                fibril_condvar_wait(&instance->avail, &instance->guard);
     73        instance->active = true;
     74        fibril_mutex_unlock(&instance->guard);
     75}
     76/*----------------------------------------------------------------------------*/
     77void endpoint_release(endpoint_t *instance)
     78{
     79        assert(instance);
     80        fibril_mutex_lock(&instance->guard);
     81        instance->active = false;
     82        fibril_mutex_unlock(&instance->guard);
     83        fibril_condvar_signal(&instance->avail);
    6084}
    6185/*----------------------------------------------------------------------------*/
  • uspace/lib/usb/src/hub.c

    r7dfc06fa rc6cb76d  
    178178 * error codes than those listed as return codes by this function itself).
    179179 *
     180 * The @p connection representing connection with host controller does not
     181 * need to be started.
     182 * This function duplicates the connection to allow simultaneous calls of
     183 * this function (i.e. from different fibrils).
     184 *
    180185 * @param[in] parent Parent device (i.e. the hub device).
    181  * @param[in] connection Opened connection to host controller.
     186 * @param[in] connection Connection to host controller.
    182187 * @param[in] dev_speed New device speed.
    183188 * @param[in] enable_port Function for enabling signaling through the port the
     
    206211    ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
    207212{
    208         CHECK_CONNECTION(connection);
     213        assert(connection != NULL);
     214        // FIXME: this is awful, we are accessing directly the structure.
     215        usb_hc_connection_t hc_conn = {
     216                .hc_handle = connection->hc_handle,
     217                .hc_phone = -1
     218        };
     219
     220        int rc;
     221
     222        rc = usb_hc_connection_open(&hc_conn);
     223        if (rc != EOK) {
     224                return rc;
     225        }
     226
    209227
    210228        /*
    211229         * Request new address.
    212230         */
    213         usb_address_t dev_addr = usb_hc_request_address(connection, dev_speed);
     231        usb_address_t dev_addr = usb_hc_request_address(&hc_conn, dev_speed);
    214232        if (dev_addr < 0) {
     233                usb_hc_connection_close(&hc_conn);
    215234                return EADDRNOTAVAIL;
    216235        }
    217236
    218         int rc;
    219237
    220238        /*
    221239         * Reserve the default address.
    222240         */
    223         rc = usb_hc_reserve_default_address(connection, dev_speed);
     241        rc = usb_hc_reserve_default_address(&hc_conn, dev_speed);
    224242        if (rc != EOK) {
    225243                rc = EBUSY;
     
    241259        usb_device_connection_t dev_conn;
    242260        rc = usb_device_connection_initialize_on_default_address(&dev_conn,
    243             connection);
     261            &hc_conn);
    244262        if (rc != EOK) {
    245263                rc = ENOTCONN;
     
    258276         * endpoint.
    259277         */
    260         rc = usb_pipe_register(&ctrl_pipe, 0, connection);
     278        rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn);
    261279        if (rc != EOK) {
    262280                rc = EREFUSED;
     
    286304         * Register the control endpoint for the new device.
    287305         */
    288         rc = usb_pipe_register(&ctrl_pipe, 0, connection);
     306        rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn);
    289307        if (rc != EOK) {
    290308                rc = EREFUSED;
     
    295313         * Release the original endpoint.
    296314         */
    297         unregister_control_endpoint_on_default_address(connection);
     315        unregister_control_endpoint_on_default_address(&hc_conn);
    298316
    299317        /*
    300318         * Once the address is changed, we can return the default address.
    301319         */
    302         usb_hc_release_default_address(connection);
     320        usb_hc_release_default_address(&hc_conn);
    303321
    304322
     
    325343                .handle = child_handle
    326344        };
    327         rc = usb_hc_register_device(connection, &new_device);
     345        rc = usb_hc_register_device(&hc_conn, &new_device);
    328346        if (rc != EOK) {
    329347                rc = EDESTADDRREQ;
     
    354372
    355373leave_unregister_endpoint:
    356         usb_pipe_unregister(&ctrl_pipe, connection);
     374        usb_pipe_unregister(&ctrl_pipe, &hc_conn);
    357375
    358376leave_release_default_address:
    359         usb_hc_release_default_address(connection);
     377        usb_hc_release_default_address(&hc_conn);
    360378
    361379leave_release_free_address:
    362         usb_hc_unregister_device(connection, dev_addr);
     380        usb_hc_unregister_device(&hc_conn, dev_addr);
     381
     382        usb_hc_connection_close(&hc_conn);
    363383
    364384        return rc;
Note: See TracChangeset for help on using the changeset viewer.