- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# include/usb/udc.h

Go to the documentation of this file.

    00001
    00044 #ifndef USB_UDC_H_INCLUDED
    00045 #define USB_UDC_H_INCLUDED
    00046
    00047 #include <bitops.h>
    00048 #include <usb/usb_protocol.h>
    00049 #include <app/config_usb.h>
    00050
    00051 struct usb_request;
    00052
    00056 typedef int     usb_ep_id_t;
    00057
    00061 enum usb_device_flag {
    00062         USB_DEV_IS_ENABLED,
    00063         USB_DEV_AUTOATTACH,
    00064         USB_DEV_HAS_POWER,
    00065         USB_DEV_IS_SUSPENDED,
    00066 };
    00067
    00072 struct udc {
    00077         const struct usb_configuration_descriptor *config;
    00079         enum usb_device_speed   speed;
    00081         unsigned long           flags;
    00086         uint8_t                 address;
    00087 };
    00088
    00100 static inline bool udc_is_high_speed(struct udc *udc)
    00101 {
    00102 #ifdef CONFIG_UDC_HIGH_SPEED
    00103         return udc->speed == USB_SPEED_HIGH;
    00104 #else
    00105         return false;
    00106 #endif
    00107 }
    00108
    00121 static inline bool udc_is_full_speed(struct udc *udc)
    00122 {
    00123 #ifdef CONFIG_UDC_FULL_SPEED
    00124         return udc->speed == USB_SPEED_FULL;
    00125 #else
    00126         return false;
    00127 #endif
    00128 }
    00129
    00143 static inline bool udc_is_low_speed(struct udc *udc)
    00144 {
    00145 #ifdef CONFIG_UDC_LOW_SPEED
    00146         return udc->speed == USB_SPEED_LOW;
    00147 #else
    00148         return false;
    00149 #endif
    00150 }
    00151
    00157 static inline enum usb_device_state udc_state(struct udc *udc)
    00158 {
    00159         int state;
    00160
    00161         if (!test_bit(USB_DEV_HAS_POWER, &udc->flags))
    00162                 state = USB_STATE_ATTACHED;
    00163         else if (udc->speed == USB_SPEED_UNKNOWN)
    00164                 state = USB_STATE_POWERED;
    00165         else if (!udc->address)
    00166                 state = USB_STATE_DEFAULT;
    00167         else if (!udc->config)
    00168                 state = USB_STATE_ADDRESS;
    00169         else
    00170                 state = USB_STATE_CONFIGURED;
    00171
    00172         if (test_bit(USB_DEV_IS_SUSPENDED, &udc->flags))
    00173                 state |= USB_STATE_SUSPENDED;
    00174
    00175         return state;
    00176 }
    00177
    00178 extern struct udc *udc_init(void);
    00179
    00180 extern void udc_attach(struct udc *udc);
    00181 extern void udc_detach(struct udc *udc);
    00182
    00183 extern usb_ep_id_t udc_ep_create(struct udc *udc,
    00184                 const struct usb_endpoint_descriptor *desc,
    00185                 unsigned int nr_banks);
    00186 extern void udc_ep_destroy(struct udc *udc, usb_ep_id_t ep);
    00187
    00188 extern int udc_ep_clear_halt(struct udc *udc, usb_ep_id_t ep);
    00189 extern int udc_ep_set_halt(struct udc *udc, usb_ep_id_t ep);
    00190 extern int udc_ep_is_halted(struct udc *udc, usb_ep_id_t ep);
    00191
    00192 extern void udc_ep_clear_wedge(struct udc *udc, usb_ep_id_t ep);
    00193 extern void udc_ep_set_wedge(struct udc *udc, usb_ep_id_t ep);
    00194 extern bool udc_ep_is_wedged(struct udc *udc, usb_ep_id_t);
    00195
    00196 extern void udc_ep0_submit_out_req(struct udc *udc, struct usb_request *req);
    00197 extern void udc_ep0_submit_in_req(struct udc *udc, struct usb_request *req);
    00198
    00199 extern int udc_ep0_write_sync(struct udc *udc, const void *data, size_t len);
    00200 extern void udc_ep0_send_status(struct udc *udc);
    00201 extern void udc_ep0_expect_status(struct udc *udc);
    00202 extern void udc_set_address(struct udc *udc, unsigned int addr);
    00203
    00204 extern void udc_ep_submit_out_req(struct udc *udc, usb_ep_id_t ep,
    00205                 struct usb_request *req);
    00206 extern void udc_ep_submit_in_req(struct udc *udc, usb_ep_id_t ep,
    00207                 struct usb_request *req);
    00208
    00209 extern void udc_ep_flush(struct udc *udc, usb_ep_id_t ep);
    00210
    00211 extern int udc_enter_test_mode(struct udc *udc, unsigned int mode);
    00212
    00213 extern int udc_lib_process_setup_request(struct udc *udc,
    00214                 struct usb_setup_req *req);
    00215
    00216 #endif /* USB_UDC_H_INCLUDED */