Changeset 8f62b0f in mainline


Ignore:
Timestamp:
2010-11-21T22:52:34Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f0da4eb2
Parents:
c4ba29c7
Message:

Add example of usb_hc_async usage

The example simply sets address of the root hub.

File:
1 edited

Legend:

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

    rc4ba29c7 r8f62b0f  
    3434 */
    3535#include <usb/hcdhubd.h>
     36#include <usb/devreq.h>
    3637#include <usbhc_iface.h>
    3738#include <driver.h>
     
    5556        .interfaces[USBHC_DEV_IFACE] = &usb_interface
    5657};
     58
     59static void set_hub_address(usb_hc_device_t *hc, usb_address_t address);
    5760
    5861/** Callback when new device is detected and must be handled by this driver.
     
    98101                return EOK;
    99102        } else {
     103                usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link);
     104                set_hub_address(hc, 5);
     105
    100106                /*
    101107                 * We are some (probably deeply nested) hub.
     
    103109                 * connected devices.
    104110                 */
     111
    105112                return ENOTSUP;
    106113        }
     114}
     115
     116/** Sample usage of usb_hc_async functions.
     117 * This function sets hub address using standard SET_ADDRESS request.
     118 *
     119 * @warning This function shall be removed once you are familiar with
     120 * the usb_hc_ API.
     121 *
     122 * @param hc Host controller the hub belongs to.
     123 * @param address New hub address.
     124 */
     125static void set_hub_address(usb_hc_device_t *hc, usb_address_t address)
     126{
     127        printf("%s: setting hub address to %d\n", hc->generic->name, address);
     128        usb_target_t target = {0, 0};
     129        usb_handle_t handle;
     130        int rc;
     131
     132        usb_device_request_setup_packet_t setup_packet = {
     133                .request_type = 0,
     134                .request = USB_DEVREQ_SET_ADDRESS,
     135                .index = 0,
     136                .length = 0,
     137        };
     138        setup_packet.value = address;
     139
     140        rc = usb_hc_async_control_write_setup(hc, target,
     141            &setup_packet, sizeof(setup_packet), &handle);
     142        if (rc != EOK) {
     143                return;
     144        }
     145
     146        rc = usb_hc_async_wait_for(handle);
     147        if (rc != EOK) {
     148                return;
     149        }
     150
     151        rc = usb_hc_async_control_write_status(hc, target, &handle);
     152        if (rc != EOK) {
     153                return;
     154        }
     155
     156        rc = usb_hc_async_wait_for(handle);
     157        if (rc != EOK) {
     158                return;
     159        }
     160
     161        printf("%s: hub address changed\n", hc->generic->name);
    107162}
    108163
     
    211266
    212267        /*
    213          * For testing/debugging purposes only.
    214          * Try to send some data to default USB address.
    215          */
    216         usb_target_t target = {0, 0};
    217         usb_handle_t handle = 0;
    218         char *data = (char *) "Hello, World!";
    219 
    220 
    221         (void)usb_hc_async_interrupt_out(dev, target, data, str_length(data), &handle);
    222         (void)usb_hc_async_wait_for(handle);
    223 
    224         /*
    225268         * Announce presence of child device.
    226269         */
Note: See TracChangeset for help on using the changeset viewer.