| [6105fc0] | 1 | /*
|
|---|
| [d7f7a4a] | 2 | * SPDX-FileCopyrightText: 2011 Vojtech Horky
|
|---|
| [6105fc0] | 3 | *
|
|---|
| [d7f7a4a] | 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| [6105fc0] | 5 | */
|
|---|
| 6 |
|
|---|
| [160b75e] | 7 | /** @addtogroup libusbdev
|
|---|
| [6105fc0] | 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /** @file
|
|---|
| 11 | * USB device driver framework.
|
|---|
| 12 | */
|
|---|
| [77ad86c] | 13 |
|
|---|
| [7d521e24] | 14 | #ifndef LIBUSBDEV_DRIVER_H_
|
|---|
| 15 | #define LIBUSBDEV_DRIVER_H_
|
|---|
| [6105fc0] | 16 |
|
|---|
| [87619045] | 17 | #include <usb/dev/device.h>
|
|---|
| [7d521e24] | 18 | #include <usb/dev/pipes.h>
|
|---|
| [6105fc0] | 19 |
|
|---|
| [69334af] | 20 | /** USB driver ops. */
|
|---|
| [6105fc0] | 21 | typedef struct {
|
|---|
| [1a4ea01d] | 22 | /** Callback when a new device was added to the system. */
|
|---|
| [5a6cc679] | 23 | errno_t (*device_add)(usb_device_t *);
|
|---|
| [96646a6] | 24 | /** Callback when a device is about to be removed from the system. */
|
|---|
| [5a6cc679] | 25 | errno_t (*device_remove)(usb_device_t *);
|
|---|
| [96646a6] | 26 | /** Callback when a device was removed from the system. */
|
|---|
| [5a6cc679] | 27 | errno_t (*device_gone)(usb_device_t *);
|
|---|
| [d46ceb2b] | 28 | /** Callback asking the driver to online a specific function. */
|
|---|
| [5a6cc679] | 29 | errno_t (*function_online)(ddf_fun_t *);
|
|---|
| [d46ceb2b] | 30 | /** Callback asking the driver to offline a specific function. */
|
|---|
| [5a6cc679] | 31 | errno_t (*function_offline)(ddf_fun_t *);
|
|---|
| [6105fc0] | 32 | } usb_driver_ops_t;
|
|---|
| 33 |
|
|---|
| [69334af] | 34 | /** USB driver structure. */
|
|---|
| [6105fc0] | 35 | typedef struct {
|
|---|
| [69334af] | 36 | /** Driver name.
|
|---|
| 37 | * This name is copied to the generic driver name and must be exactly
|
|---|
| 38 | * the same as the directory name where the driver executable resides.
|
|---|
| 39 | */
|
|---|
| [6105fc0] | 40 | const char *name;
|
|---|
| [9bc276b] | 41 | /** Expected endpoints description.
|
|---|
| 42 | * This description shall exclude default control endpoint (pipe zero)
|
|---|
| 43 | * and must be NULL terminated.
|
|---|
| 44 | * When only control endpoint is expected, you may set NULL directly
|
|---|
| 45 | * without creating one item array containing NULL.
|
|---|
| [09daa8b] | 46 | *
|
|---|
| [9bc276b] | 47 | * When the driver expect single interrupt in endpoint,
|
|---|
| 48 | * the initialization may look like this:
|
|---|
| [47e00b83] | 49 | *
|
|---|
| 50 | * @code
|
|---|
| 51 | * static usb_endpoint_description_t poll_endpoint_description = {
|
|---|
| 52 | * .transfer_type = USB_TRANSFER_INTERRUPT,
|
|---|
| 53 | * .direction = USB_DIRECTION_IN,
|
|---|
| 54 | * .interface_class = USB_CLASS_HUB,
|
|---|
| 55 | * .interface_subclass = 0,
|
|---|
| 56 | * .interface_protocol = 0,
|
|---|
| 57 | * .flags = 0
|
|---|
| 58 | * };
|
|---|
| [7c3fb9b] | 59 | *
|
|---|
| [47e00b83] | 60 | * static usb_endpoint_description_t *hub_endpoints[] = {
|
|---|
| 61 | * &poll_endpoint_description,
|
|---|
| 62 | * NULL
|
|---|
| 63 | * };
|
|---|
| [7c3fb9b] | 64 | *
|
|---|
| [47e00b83] | 65 | * static usb_driver_t hub_driver = {
|
|---|
| 66 | * .endpoints = hub_endpoints,
|
|---|
| 67 | * ...
|
|---|
| 68 | * };
|
|---|
| 69 | * @endcode
|
|---|
| [09daa8b] | 70 | */
|
|---|
| [b803845] | 71 | const usb_endpoint_description_t **endpoints;
|
|---|
| [69334af] | 72 | /** Driver ops. */
|
|---|
| [49bd7ae2] | 73 | const usb_driver_ops_t *ops;
|
|---|
| [6105fc0] | 74 | } usb_driver_t;
|
|---|
| 75 |
|
|---|
| [882580a] | 76 | int usb_driver_main(const usb_driver_t *);
|
|---|
| [6105fc0] | 77 |
|
|---|
| 78 | #endif
|
|---|
| 79 | /**
|
|---|
| 80 | * @}
|
|---|
| 81 | */
|
|---|