|
| 1 | +/** @defgroup usb_private_defines USB Private Structures |
| 2 | +
|
| 3 | +@brief <b>Defined Constants and Types for the USB Private Structures</b> |
| 4 | +
|
| 5 | +@ingroup USB_defines |
| 6 | +
|
| 7 | +@version 1.0.0 |
| 8 | +
|
| 9 | +@author @htmlonly © @endhtmlonly 2010 |
| 10 | +Gareth McMullin <gareth@blacksphere.co.nz> |
| 11 | +
|
| 12 | +@date 10 March 2013 |
| 13 | +
|
| 14 | +LGPL License Terms @ref lgpl_license |
| 15 | +*/ |
| 16 | + |
| 17 | +/* |
| 18 | + * This file is part of the libopencm3 project. |
| 19 | + * |
| 20 | + * Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz> |
| 21 | + * |
| 22 | + * This library is free software: you can redistribute it and/or modify |
| 23 | + * it under the terms of the GNU Lesser General Public License as published by |
| 24 | + * the Free Software Foundation, either version 3 of the License, or |
| 25 | + * (at your option) any later version. |
| 26 | + * |
| 27 | + * This library is distributed in the hope that it will be useful, |
| 28 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | + * GNU Lesser General Public License for more details. |
| 31 | + * |
| 32 | + * You should have received a copy of the GNU Lesser General Public License |
| 33 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 34 | + */ |
| 35 | + |
| 36 | +/**@{*/ |
| 37 | + |
| 38 | +#ifndef __USB_PRIVATE_H |
| 39 | +#define __USB_PRIVATE_H |
| 40 | + |
| 41 | +#define MAX_USER_CONTROL_CALLBACK 4 |
| 42 | +#define MAX_USER_SET_CONFIG_CALLBACK 4 |
| 43 | + |
| 44 | +/** Internal collection of device information. */ |
| 45 | +struct _usbd_device { |
| 46 | + const struct usb_device_descriptor *desc; |
| 47 | + const struct usb_config_descriptor *config; |
| 48 | + const char **strings; |
| 49 | + int num_strings; |
| 50 | + |
| 51 | + uint8_t *ctrl_buf; /**< Internal buffer used for control transfers */ |
| 52 | + uint16_t ctrl_buf_len; |
| 53 | + |
| 54 | + uint8_t current_address; |
| 55 | + uint8_t current_config; |
| 56 | + |
| 57 | + uint16_t pm_top; /**< Top of allocated endpoint buffer memory */ |
| 58 | + |
| 59 | + /* User callback functions for various USB events */ |
| 60 | + void (*user_callback_reset)(void); |
| 61 | + void (*user_callback_suspend)(void); |
| 62 | + void (*user_callback_resume)(void); |
| 63 | + void (*user_callback_sof)(void); |
| 64 | + |
| 65 | + struct usb_control_state { |
| 66 | + enum { |
| 67 | + IDLE, STALLED, |
| 68 | + DATA_IN, LAST_DATA_IN, STATUS_IN, |
| 69 | + DATA_OUT, LAST_DATA_OUT, STATUS_OUT, |
| 70 | + } state; |
| 71 | + struct usb_setup_data req __attribute__((aligned(4))); |
| 72 | + uint8_t *ctrl_buf; |
| 73 | + uint16_t ctrl_len; |
| 74 | + usbd_control_complete_callback complete; |
| 75 | + bool needs_zlp; |
| 76 | + } control_state; |
| 77 | + |
| 78 | + struct user_control_callback { |
| 79 | + usbd_control_callback cb; |
| 80 | + uint8_t type; |
| 81 | + uint8_t type_mask; |
| 82 | + } user_control_callback[MAX_USER_CONTROL_CALLBACK]; |
| 83 | + |
| 84 | + usbd_endpoint_callback user_callback_ctr[8][3]; |
| 85 | + |
| 86 | + /* User callback function for some standard USB function hooks */ |
| 87 | + usbd_set_config_callback user_callback_set_config[MAX_USER_SET_CONFIG_CALLBACK]; |
| 88 | + |
| 89 | + usbd_set_altsetting_callback user_callback_set_altsetting; |
| 90 | + |
| 91 | + const struct _usbd_driver *driver; |
| 92 | + |
| 93 | + /* private driver data */ |
| 94 | + |
| 95 | + uint16_t fifo_mem_top; |
| 96 | + uint16_t fifo_mem_top_ep0; |
| 97 | + uint8_t force_nak[4]; |
| 98 | + /* |
| 99 | + * We keep a backup copy of the out endpoint size registers to restore |
| 100 | + * them after a transaction. |
| 101 | + */ |
| 102 | + uint32_t doeptsiz[4]; |
| 103 | + /* |
| 104 | + * Received packet size for each endpoint. This is assigned in |
| 105 | + * stm32f107_poll() which reads the packet status push register GRXSTSP |
| 106 | + * for use in stm32f107_ep_read_packet(). |
| 107 | + */ |
| 108 | + uint16_t rxbcnt; |
| 109 | +}; |
| 110 | + |
| 111 | +enum _usbd_transaction { |
| 112 | + USB_TRANSACTION_IN, |
| 113 | + USB_TRANSACTION_OUT, |
| 114 | + USB_TRANSACTION_SETUP, |
| 115 | +}; |
| 116 | + |
| 117 | +/* Do not appear to belong to the API, so are omitted from docs */ |
| 118 | +/**@}*/ |
| 119 | + |
| 120 | +void _usbd_control_in(usbd_device *usbd_dev, uint8_t ea); |
| 121 | +void _usbd_control_out(usbd_device *usbd_dev, uint8_t ea); |
| 122 | +void _usbd_control_setup(usbd_device *usbd_dev, uint8_t ea); |
| 123 | + |
| 124 | +int _usbd_standard_request_device(usbd_device *usbd_dev, |
| 125 | + struct usb_setup_data *req, uint8_t **buf, |
| 126 | + uint16_t *len); |
| 127 | +int _usbd_standard_request_interface(usbd_device *usbd_dev, |
| 128 | + struct usb_setup_data *req, uint8_t **buf, |
| 129 | + uint16_t *len); |
| 130 | +int _usbd_standard_request_endpoint(usbd_device *usbd_dev, |
| 131 | + struct usb_setup_data *req, uint8_t **buf, |
| 132 | + uint16_t *len); |
| 133 | +int _usbd_standard_request(usbd_device *usbd_dev, struct usb_setup_data *req, |
| 134 | + uint8_t **buf, uint16_t *len); |
| 135 | + |
| 136 | +void _usbd_reset(usbd_device *usbd_dev); |
| 137 | + |
| 138 | +/* Functions provided by the hardware abstraction. */ |
| 139 | +struct _usbd_driver { |
| 140 | + usbd_device *(*init)(void); |
| 141 | + void (*set_address)(usbd_device *usbd_dev, uint8_t addr); |
| 142 | + void (*ep_setup)(usbd_device *usbd_dev, uint8_t addr, uint8_t type, |
| 143 | + uint16_t max_size, usbd_endpoint_callback cb); |
| 144 | + void (*ep_reset)(usbd_device *usbd_dev); |
| 145 | + void (*ep_stall_set)(usbd_device *usbd_dev, uint8_t addr, |
| 146 | + uint8_t stall); |
| 147 | + void (*ep_nak_set)(usbd_device *usbd_dev, uint8_t addr, uint8_t nak); |
| 148 | + uint8_t (*ep_stall_get)(usbd_device *usbd_dev, uint8_t addr); |
| 149 | + uint16_t (*ep_write_packet)(usbd_device *usbd_dev, uint8_t addr, |
| 150 | + const void *buf, uint16_t len); |
| 151 | + uint16_t (*ep_read_packet)(usbd_device *usbd_dev, uint8_t addr, |
| 152 | + void *buf, uint16_t len); |
| 153 | + void (*poll)(usbd_device *usbd_dev); |
| 154 | + void (*disconnect)(usbd_device *usbd_dev, bool disconnected); |
| 155 | + uint32_t base_address; |
| 156 | + bool set_address_before_status; |
| 157 | + uint16_t rx_fifo_size; |
| 158 | +}; |
| 159 | + |
| 160 | +#endif |
| 161 | + |
0 commit comments