| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2011 Vojtech Horky
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | /** @addtogroup libusbdev
|
|---|
| 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /** @file
|
|---|
| 11 | * USB device driver framework.
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | #ifndef LIBUSBDEV_DEVICE_H_
|
|---|
| 15 | #define LIBUSBDEV_DEVICE_H_
|
|---|
| 16 |
|
|---|
| 17 | #include <ddf/driver.h>
|
|---|
| 18 | #include <usb/usb.h>
|
|---|
| 19 | #include <usb/descriptor.h>
|
|---|
| 20 | #include <usb/dev/alternate_ifaces.h>
|
|---|
| 21 | #include <usb/dev/pipes.h>
|
|---|
| 22 | #include <usbhc_iface.h>
|
|---|
| 23 |
|
|---|
| 24 | #include <assert.h>
|
|---|
| 25 | #include <async.h>
|
|---|
| 26 |
|
|---|
| 27 | /** Some useful descriptors for USB device. */
|
|---|
| 28 | typedef struct {
|
|---|
| 29 | /** Standard device descriptor. */
|
|---|
| 30 | usb_standard_device_descriptor_t device;
|
|---|
| 31 | /** Full configuration descriptor of current configuration. */
|
|---|
| 32 | void *full_config;
|
|---|
| 33 | size_t full_config_size;
|
|---|
| 34 | } usb_device_descriptors_t;
|
|---|
| 35 |
|
|---|
| 36 | typedef struct usb_device usb_device_t;
|
|---|
| 37 |
|
|---|
| 38 | /* DDF parts */
|
|---|
| 39 | errno_t usb_device_create_ddf(ddf_dev_t *,
|
|---|
| 40 | const usb_endpoint_description_t **, const char **);
|
|---|
| 41 | void usb_device_destroy_ddf(ddf_dev_t *);
|
|---|
| 42 |
|
|---|
| 43 | static inline usb_device_t *usb_device_get(ddf_dev_t *dev)
|
|---|
| 44 | {
|
|---|
| 45 | assert(dev);
|
|---|
| 46 | return ddf_dev_data_get(dev);
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | usb_device_t *usb_device_create(devman_handle_t);
|
|---|
| 50 | void usb_device_destroy(usb_device_t *);
|
|---|
| 51 |
|
|---|
| 52 | const char *usb_device_get_name(usb_device_t *);
|
|---|
| 53 | ddf_fun_t *usb_device_ddf_fun_create(usb_device_t *, fun_type_t, const char *);
|
|---|
| 54 |
|
|---|
| 55 | async_exch_t *usb_device_bus_exchange_begin(usb_device_t *);
|
|---|
| 56 | void usb_device_bus_exchange_end(async_exch_t *);
|
|---|
| 57 |
|
|---|
| 58 | errno_t usb_device_select_interface(usb_device_t *, uint8_t,
|
|---|
| 59 | const usb_endpoint_description_t **);
|
|---|
| 60 |
|
|---|
| 61 | errno_t usb_device_create_pipes(usb_device_t *usb_dev,
|
|---|
| 62 | const usb_endpoint_description_t **endpoints);
|
|---|
| 63 | void usb_device_destroy_pipes(usb_device_t *);
|
|---|
| 64 |
|
|---|
| 65 | usb_pipe_t *usb_device_get_default_pipe(usb_device_t *);
|
|---|
| 66 | usb_endpoint_mapping_t *usb_device_get_mapped_ep_desc(usb_device_t *,
|
|---|
| 67 | const usb_endpoint_description_t *);
|
|---|
| 68 | int usb_device_unmap_ep(usb_endpoint_mapping_t *);
|
|---|
| 69 |
|
|---|
| 70 | usb_address_t usb_device_get_address(const usb_device_t *);
|
|---|
| 71 | usb_speed_t usb_device_get_depth(const usb_device_t *);
|
|---|
| 72 | usb_speed_t usb_device_get_speed(const usb_device_t *);
|
|---|
| 73 | int usb_device_get_iface_number(const usb_device_t *);
|
|---|
| 74 | devman_handle_t usb_device_get_devman_handle(const usb_device_t *);
|
|---|
| 75 |
|
|---|
| 76 | const usb_device_descriptors_t *usb_device_descriptors(usb_device_t *);
|
|---|
| 77 |
|
|---|
| 78 | const usb_alternate_interfaces_t *usb_device_get_alternative_ifaces(
|
|---|
| 79 | usb_device_t *);
|
|---|
| 80 |
|
|---|
| 81 | void *usb_device_data_alloc(usb_device_t *, size_t);
|
|---|
| 82 | void *usb_device_data_get(usb_device_t *);
|
|---|
| 83 |
|
|---|
| 84 | #endif
|
|---|
| 85 | /**
|
|---|
| 86 | * @}
|
|---|
| 87 | */
|
|---|