#include "../../../../Common/Common.h"
#include "../USBTask.h"
#include "../USBInterrupt.h"
+ #include "../USBController.h"
/* Enable C linkage for C++ Compilers: */
#if defined(__cplusplus)
#define ENDPOINT_DETAILS_MAXEP 16
+ /* External Variables: */
+ extern volatile uint8_t Endpoint_SelectedEndpoint;
+ extern volatile USB_EP_t* Endpoint_SelectedEndpointHandle;
+
/* Inline Functions: */
static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST
ATTR_ALWAYS_INLINE;
/* Function Prototypes: */
void Endpoint_ClearEndpoints(void);
- bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
- const uint8_t UECFG0XData,
- const uint8_t UECFG1XData);
-
#endif
/* Public Interface - May be used in end-application: */
/** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
* should be initialized in the OUT direction - i.e. data flows from host to device.
*/
- #define ENDPOINT_DIR_OUT false
+ #define ENDPOINT_DIR_OUT ENDPOINT_DESCRIPTOR_DIR_OUT
/** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
* should be initialized in the IN direction - i.e. data flows from device to host.
*/
- #define ENDPOINT_DIR_IN true
+ #define ENDPOINT_DIR_IN ENDPOINT_DESCRIPTOR_DIR_IN
//@}
/** \name Endpoint Bank Mode Masks */
* in faster transfers as one USB device (the AVR or the host) can access one bank while the other
* accesses the second bank.
*/
- #define ENDPOINT_BANK_DOUBLE USB_EP_BANK_bm
+ #define ENDPOINT_BANK_DOUBLE USB_EP_PINGPONG_bm
//@}
#if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
};
/* Inline Functions: */
+ /** Selects the given endpoint number. If the address from the device descriptors is used, the
+ * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
+ * number (and discarding the endpoint direction bit).
+ *
+ * Any endpoint operations which do not require the endpoint number to be indicated will operate on
+ * the currently selected endpoint.
+ *
+ * \param[in] EndpointNumber Endpoint number to select.
+ */
+ static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
+ static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber)
+ {
+ uint8_t EPTableIndex = ((EndpointNumber & ENDPOINT_EPNUM_MASK) << 1) | ((EndpointNumber & ENDPOINT_DESCRIPTOR_DIR_IN) ? 0x01 : 0);
+
+ Endpoint_SelectedEndpoint = EndpointNumber;
+ Endpoint_SelectedEndpointHandle = &((USB_EP_t*)&USB_EndpointTable)[EPTableIndex];
+ }
+
/** Configures the specified endpoint number with the given endpoint type, direction, bank size
* and banking mode. Once configured, the endpoint may be read from or written to, depending
* on its direction.
const uint16_t Size,
const uint8_t Banks)
{
- return 0; // TODO
+ Endpoint_SelectEndpoint(Number | Direction);
+ Endpoint_SelectedEndpointHandle->CTRL = (Type | Banks | Endpoint_BytesToEPSizeMask(Size));
+ return true;
}
/** Indicates the number of bytes currently stored in the current endpoint's selected bank.
static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Endpoint_BytesInEndpoint(void)
{
- return 0; // TODO
+ return (((uint16_t)(Endpoint_SelectedEndpointHandle->CNTH & ~USB_EP_ZLP_bm) << 8) | Endpoint_SelectedEndpointHandle->CNTL);
}
/** Get the endpoint address of the currently selected endpoint. This is typically used to save
static inline uint8_t Endpoint_GetCurrentEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_GetCurrentEndpoint(void)
{
- return 0; // TODO
- }
-
- /** Selects the given endpoint number. If the address from the device descriptors is used, the
- * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
- * number (and discarding the endpoint direction bit).
- *
- * Any endpoint operations which do not require the endpoint number to be indicated will operate on
- * the currently selected endpoint.
- *
- * \param[in] EndpointNumber Endpoint number to select.
- */
- static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
- static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber)
- {
- // TODO
+ return Endpoint_SelectedEndpoint;
}
/** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's
{
// TODO
}
-
+#if 0
/** Enables the currently selected endpoint so that data can be sent and received through it to
* and from a host.
*
{
// TODO
}
-
+#endif
/** Determines if the currently selected endpoint is enabled, but not necessarily configured.
*
* \return Boolean \c true if the currently selected endpoint is enabled, \c false otherwise.
static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsEnabled(void)
{
- return 0; // TODO
+ return true;
}
/** Retrieves the number of busy banks in the currently selected endpoint, which have been queued for
static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsConfigured(void)
{
- return 0; // TODO
+ return ((Endpoint_SelectedEndpointHandle->CTRL & USB_EP_TYPE_gm) ? true : false);
}
/** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsINReady(void)
{
- return 0; // TODO
+ return (Endpoint_SelectedEndpointHandle->STATUS & USB_EP_TRNCOMPL0_bm);
}
/** Determines if the selected OUT endpoint has received new packet from the host.
static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsOUTReceived(void)
{
- return 0; // TODO
+ return (Endpoint_SelectedEndpointHandle->STATUS & USB_EP_TRNCOMPL0_bm);
}
/** Determines if the current CONTROL type endpoint has received a SETUP packet.
static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsSETUPReceived(void)
{
- return 0; // TODO
+ return (Endpoint_SelectedEndpointHandle->STATUS & USB_EP_SETUP_bm);
}
/** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_StallTransaction(void)
{
- // TODO
+ Endpoint_SelectedEndpointHandle->CTRL |= USB_EP_STALL_bm;
}
/** Clears the STALL condition on the currently selected endpoint.
static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearStall(void)
{
- // TODO
+ Endpoint_SelectedEndpointHandle->CTRL &= ~USB_EP_STALL_bm;
}
/** Determines if the currently selected endpoint is stalled, false otherwise.
static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsStalled(void)
{
- return 0; // TODO
+ return (Endpoint_SelectedEndpointHandle->CTRL & USB_EP_STALL_bm);
}
/** Resets the data toggle of the currently selected endpoint. */
static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ResetDataToggle(void)
{
- // TODO
+ Endpoint_SelectedEndpointHandle->STATUS &= ~USB_EP_TOGGLE_bm;
}
/** Determines the currently selected endpoint's direction.