Simplified USB endpoints configuration.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2734 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
95d128420a
commit
eb3355b558
|
@ -81,6 +81,14 @@
|
||||||
*/
|
*/
|
||||||
#define USB_ENDPOINT_BUSY ((size_t)0xFFFFFFFF)
|
#define USB_ENDPOINT_BUSY ((size_t)0xFFFFFFFF)
|
||||||
|
|
||||||
|
#define USB_EP_MODE_TYPE 0x0003 /**< Endpoint type mask. */
|
||||||
|
#define USB_EP_MODE_TYPE_CTRL 0x0000 /**< Control endpoint. */
|
||||||
|
#define USB_EP_MODE_TYPE_ISOC 0x0001 /**< Isochronous endpoint. */
|
||||||
|
#define USB_EP_MODE_TYPE_BULK 0x0002 /**< Bulk endpoint. */
|
||||||
|
#define USB_EP_MODE_TYPE_INTR 0x0003 /**< Interrupt endpoint. */
|
||||||
|
#define USB_EP_MODE_TRANSACTION 0x0000 /**< Transaction mode. */
|
||||||
|
#define USB_EP_MODE_PACKET 0x0010 /**< Packet mode enabled. */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver pre-compile time settings. */
|
/* Driver pre-compile time settings. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -114,21 +122,11 @@ typedef enum {
|
||||||
USB_ACTIVE = 4, /**< Active, configuration selected.*/
|
USB_ACTIVE = 4, /**< Active, configuration selected.*/
|
||||||
} usbstate_t;
|
} usbstate_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of an endpoint type.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
EP_TYPE_CTRL = 0, /**< Control endpoint. */
|
|
||||||
EP_TYPE_ISOC = 1, /**< Isochronous endpoint. */
|
|
||||||
EP_TYPE_BULK = 2, /**< Bulk endpoint. */
|
|
||||||
EP_TYPE_INTR = 3 /**< Interrupt endpoint. */
|
|
||||||
} usbeptype_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of an endpoint status.
|
* @brief Type of an endpoint status.
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
EP_STATUS_DISABLED = 0, /**< Endpoint not opened. */
|
EP_STATUS_DISABLED = 0, /**< Endpoint not active. */
|
||||||
EP_STATUS_STALLED = 1, /**< Endpoint opened but stalled. */
|
EP_STATUS_STALLED = 1, /**< Endpoint opened but stalled. */
|
||||||
EP_STATUS_ACTIVE = 2 /**< Active endpoint. */
|
EP_STATUS_ACTIVE = 2 /**< Active endpoint. */
|
||||||
} usbepstatus_t;
|
} usbepstatus_t;
|
||||||
|
|
|
@ -58,12 +58,11 @@ static USBEndpointState ep0state;
|
||||||
* @brief EP0 initialization structure.
|
* @brief EP0 initialization structure.
|
||||||
*/
|
*/
|
||||||
static const USBEndpointConfig ep0config = {
|
static const USBEndpointConfig ep0config = {
|
||||||
EP_TYPE_CTRL,
|
USB_EP_MODE_TYPE_CTRL | USB_EP_MODE_TRANSACTION,
|
||||||
_usb_ep0in,
|
_usb_ep0in,
|
||||||
_usb_ep0out,
|
_usb_ep0out,
|
||||||
0x40,
|
0x40,
|
||||||
0x40,
|
0x40,
|
||||||
0,
|
|
||||||
0x40,
|
0x40,
|
||||||
0x80
|
0x80
|
||||||
};
|
};
|
||||||
|
@ -179,7 +178,7 @@ CH_IRQ_HANDLER(USB_LP_IRQHandler) {
|
||||||
if (epr & EPR_CTR_TX) {
|
if (epr & EPR_CTR_TX) {
|
||||||
/* IN endpoint, transmission.*/
|
/* IN endpoint, transmission.*/
|
||||||
EPR_CLEAR_CTR_TX(ep);
|
EPR_CLEAR_CTR_TX(ep);
|
||||||
if (epcp->flags & USB_EP_FLAGS_IN_PACKET_MODE) {
|
if (epcp->ep_mode & USB_EP_MODE_PACKET) {
|
||||||
/* Packet mode, just invokes the callback.*/
|
/* Packet mode, just invokes the callback.*/
|
||||||
(usbp)->transmitting &= ~((uint16_t)(1 << ep));
|
(usbp)->transmitting &= ~((uint16_t)(1 << ep));
|
||||||
epcp->in_cb(usbp, ep);
|
epcp->in_cb(usbp, ep);
|
||||||
|
@ -208,7 +207,7 @@ CH_IRQ_HANDLER(USB_LP_IRQHandler) {
|
||||||
if (epr & EPR_CTR_RX) {
|
if (epr & EPR_CTR_RX) {
|
||||||
EPR_CLEAR_CTR_RX(ep);
|
EPR_CLEAR_CTR_RX(ep);
|
||||||
/* OUT endpoint, receive.*/
|
/* OUT endpoint, receive.*/
|
||||||
if (epcp->flags & USB_EP_FLAGS_OUT_PACKET_MODE) {
|
if (epcp->ep_mode & USB_EP_MODE_PACKET) {
|
||||||
/* Packet mode, just invokes the callback.*/
|
/* Packet mode, just invokes the callback.*/
|
||||||
(usbp)->receiving &= ~((uint16_t)(1 << ep));
|
(usbp)->receiving &= ~((uint16_t)(1 << ep));
|
||||||
epcp->out_cb(usbp, ep);
|
epcp->out_cb(usbp, ep);
|
||||||
|
@ -376,14 +375,14 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
|
||||||
const USBEndpointConfig *epcp = usbp->ep[ep]->config;
|
const USBEndpointConfig *epcp = usbp->ep[ep]->config;
|
||||||
|
|
||||||
/* Setting the endpoint type.*/
|
/* Setting the endpoint type.*/
|
||||||
switch (epcp->ep_type) {
|
switch (epcp->ep_mode & USB_EP_MODE_TYPE) {
|
||||||
case EP_TYPE_ISOC:
|
case USB_EP_MODE_TYPE_ISOC:
|
||||||
epr = EPR_EP_TYPE_ISO;
|
epr = EPR_EP_TYPE_ISO;
|
||||||
break;
|
break;
|
||||||
case EP_TYPE_BULK:
|
case USB_EP_MODE_TYPE_BULK:
|
||||||
epr = EPR_EP_TYPE_BULK;
|
epr = EPR_EP_TYPE_BULK;
|
||||||
break;
|
break;
|
||||||
case EP_TYPE_INTR:
|
case USB_EP_MODE_TYPE_INTR:
|
||||||
epr = EPR_EP_TYPE_INTERRUPT;
|
epr = EPR_EP_TYPE_INTERRUPT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -397,7 +396,7 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
|
||||||
/* OUT endpoint settings. If the endpoint is in packet mode then it must
|
/* OUT endpoint settings. If the endpoint is in packet mode then it must
|
||||||
start ready to accept data else it must start in NAK mode.*/
|
start ready to accept data else it must start in NAK mode.*/
|
||||||
if (epcp->out_cb) {
|
if (epcp->out_cb) {
|
||||||
if (epcp->flags & USB_EP_FLAGS_OUT_PACKET_MODE) {
|
if (epcp->ep_mode & USB_EP_MODE_PACKET) {
|
||||||
usbp->receiving |= ((uint16_t)(1 << ep));
|
usbp->receiving |= ((uint16_t)(1 << ep));
|
||||||
epr |= EPR_STAT_RX_VALID;
|
epr |= EPR_STAT_RX_VALID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,16 +46,6 @@
|
||||||
*/
|
*/
|
||||||
#define USB_SET_ADDRESS_MODE USB_LATE_SET_ADDRESS
|
#define USB_SET_ADDRESS_MODE USB_LATE_SET_ADDRESS
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Enables the packet mode for an IN endpoint.
|
|
||||||
*/
|
|
||||||
#define USB_EP_FLAGS_IN_PACKET_MODE 1
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Enables the packet mode for an OUT endpoint.
|
|
||||||
*/
|
|
||||||
#define USB_EP_FLAGS_OUT_PACKET_MODE 2
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver pre-compile time settings. */
|
/* Driver pre-compile time settings. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -109,9 +99,9 @@
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/**
|
/**
|
||||||
* @brief Type of the endpoint.
|
* @brief Type and mode of the endpoint.
|
||||||
*/
|
*/
|
||||||
usbeptype_t ep_type;
|
uint32_t ep_mode;
|
||||||
/**
|
/**
|
||||||
* @brief IN endpoint notification callback.
|
* @brief IN endpoint notification callback.
|
||||||
* @details This field must be set to @p NULL if the IN endpoint is not
|
* @details This field must be set to @p NULL if the IN endpoint is not
|
||||||
|
@ -137,10 +127,6 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
uint16_t out_maxsize;
|
uint16_t out_maxsize;
|
||||||
/* End of the mandatory fields.*/
|
/* End of the mandatory fields.*/
|
||||||
/**
|
|
||||||
* @bief Endpoint mode flags.
|
|
||||||
*/
|
|
||||||
uint16_t flags;
|
|
||||||
/**
|
/**
|
||||||
* @brief Endpoint IN buffer address as offset in the PMA.
|
* @brief Endpoint IN buffer address as offset in the PMA.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -251,12 +251,11 @@ USBEndpointState ep3state;
|
||||||
* @brief EP1 initialization structure (IN only).
|
* @brief EP1 initialization structure (IN only).
|
||||||
*/
|
*/
|
||||||
static const USBEndpointConfig ep1config = {
|
static const USBEndpointConfig ep1config = {
|
||||||
EP_TYPE_BULK,
|
USB_EP_MODE_TYPE_BULK | USB_EP_MODE_PACKET,
|
||||||
sduDataTransmitted,
|
sduDataTransmitted,
|
||||||
NULL,
|
NULL,
|
||||||
0x0040,
|
0x0040,
|
||||||
0x0000,
|
0x0000,
|
||||||
USB_EP_FLAGS_IN_PACKET_MODE,
|
|
||||||
0x00C0,
|
0x00C0,
|
||||||
0x0000
|
0x0000
|
||||||
};
|
};
|
||||||
|
@ -265,12 +264,11 @@ static const USBEndpointConfig ep1config = {
|
||||||
* @brief EP2 initialization structure (IN only).
|
* @brief EP2 initialization structure (IN only).
|
||||||
*/
|
*/
|
||||||
static const USBEndpointConfig ep2config = {
|
static const USBEndpointConfig ep2config = {
|
||||||
EP_TYPE_INTR,
|
USB_EP_MODE_TYPE_INTR | USB_EP_MODE_PACKET,
|
||||||
sduInterruptTransmitted,
|
sduInterruptTransmitted,
|
||||||
NULL,
|
NULL,
|
||||||
0x0010,
|
0x0010,
|
||||||
0x0000,
|
0x0000,
|
||||||
0,
|
|
||||||
0x0100,
|
0x0100,
|
||||||
0x0000
|
0x0000
|
||||||
};
|
};
|
||||||
|
@ -279,12 +277,11 @@ static const USBEndpointConfig ep2config = {
|
||||||
* @brief EP3 initialization structure (OUT only).
|
* @brief EP3 initialization structure (OUT only).
|
||||||
*/
|
*/
|
||||||
static const USBEndpointConfig ep3config = {
|
static const USBEndpointConfig ep3config = {
|
||||||
EP_TYPE_BULK,
|
USB_EP_MODE_TYPE_BULK | USB_EP_MODE_PACKET,
|
||||||
NULL,
|
NULL,
|
||||||
sduDataReceived,
|
sduDataReceived,
|
||||||
0x0000,
|
0x0000,
|
||||||
0x0040,
|
0x0040,
|
||||||
USB_EP_FLAGS_OUT_PACKET_MODE,
|
|
||||||
0x0000,
|
0x0000,
|
||||||
0x0110
|
0x0110
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue