libopencm3/include/libopencm3/usb/usbd.h

133 lines
4.1 KiB
C
Raw Normal View History

/** @defgroup usb_driver_defines USB Drivers
@brief <b>Defined Constants and Types for the USB Drivers</b>
@ingroup USB_defines
@version 1.0.0
@author @htmlonly &copy; @endhtmlonly 2010
Gareth McMullin <gareth@blacksphere.co.nz>
@date 10 March 2013
LGPL License Terms @ref lgpl_license
*/
/*
* This file is part of the libopencm3 project.
*
2010-12-29 15:43:26 +00:00
* Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
2010-12-29 15:43:26 +00:00
/**@{*/
#ifndef __USBD_H
#define __USBD_H
#include <libopencm3/usb/usbstd.h>
BEGIN_DECLS
enum usbd_request_return_codes {
USBD_REQ_NOTSUPP = 0,
USBD_REQ_HANDLED = 1,
USBD_REQ_NEXT_CALLBACK = 2,
};
typedef struct _usbd_driver usbd_driver;
typedef struct _usbd_device usbd_device;
extern const usbd_driver st_usbfs_v1_usb_driver;
extern const usbd_driver stm32f107_usb_driver;
extern const usbd_driver stm32f207_usb_driver;
extern const usbd_driver st_usbfs_v2_usb_driver;
#define otgfs_usb_driver stm32f107_usb_driver
#define otghs_usb_driver stm32f207_usb_driver
/* <usb.c> */
extern usbd_device * usbd_init(const usbd_driver *driver,
const struct usb_device_descriptor *dev,
const struct usb_config_descriptor *conf,
const char **strings, int num_strings,
2013-06-13 04:00:50 +00:00
uint8_t *control_buffer,
uint16_t control_buffer_size);
extern void usbd_register_reset_callback(usbd_device *usbd_dev,
void (*callback)(void));
extern void usbd_register_suspend_callback(usbd_device *usbd_dev,
void (*callback)(void));
extern void usbd_register_resume_callback(usbd_device *usbd_dev,
void (*callback)(void));
extern void usbd_register_sof_callback(usbd_device *usbd_dev,
void (*callback)(void));
typedef int (*usbd_control_complete_callback)(usbd_device *usbd_dev,
struct usb_setup_data *req);
typedef int (*usbd_control_callback)(usbd_device *usbd_dev,
2013-06-13 02:11:22 +00:00
struct usb_setup_data *req, uint8_t **buf, uint16_t *len,
usbd_control_complete_callback *complete);
typedef void (*usbd_set_config_callback)(usbd_device *usbd_dev, uint16_t wValue);
typedef void (*usbd_set_altsetting_callback)(usbd_device *usbd_dev,
uint16_t wIndex, uint16_t wValue);
typedef void (*usbd_endpoint_callback)(usbd_device *usbd_dev, uint8_t ep);
/* <usb_control.c> */
2013-06-13 02:11:22 +00:00
extern int usbd_register_control_callback(usbd_device *usbd_dev, uint8_t type,
uint8_t type_mask,
usbd_control_callback callback);
/* <usb_standard.c> */
extern int usbd_register_set_config_callback(usbd_device *usbd_dev,
usbd_set_config_callback callback);
extern void usbd_register_set_altsetting_callback(usbd_device *usbd_dev,
usbd_set_altsetting_callback callback);
/* Functions to be provided by the hardware abstraction layer */
extern void usbd_poll(usbd_device *usbd_dev);
extern void usbd_disconnect(usbd_device *usbd_dev, bool disconnected);
2013-06-13 04:00:50 +00:00
extern void usbd_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type,
uint16_t max_size, usbd_endpoint_callback callback);
2013-06-13 02:11:22 +00:00
extern uint16_t usbd_ep_write_packet(usbd_device *usbd_dev, uint8_t addr,
const void *buf, uint16_t len);
2013-06-13 02:11:22 +00:00
extern uint16_t usbd_ep_read_packet(usbd_device *usbd_dev, uint8_t addr,
void *buf, uint16_t len);
2013-06-13 04:00:50 +00:00
extern void usbd_ep_stall_set(usbd_device *usbd_dev, uint8_t addr,
uint8_t stall);
2013-06-13 02:11:22 +00:00
extern uint8_t usbd_ep_stall_get(usbd_device *usbd_dev, uint8_t addr);
2013-06-13 02:11:22 +00:00
extern void usbd_ep_nak_set(usbd_device *usbd_dev, uint8_t addr, uint8_t nak);
/* Optional */
2013-06-13 02:11:22 +00:00
extern void usbd_cable_connect(usbd_device *usbd_dev, uint8_t on);
END_DECLS
#endif
/**@}*/