2011-02-28 18:44:46 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2013-02-02 10:58:09 +00:00
|
|
|
2011,2012,2013 Giovanni Di Sirio.
|
2011-02-28 18:44:46 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file templates/usb_lld.c
|
|
|
|
* @brief USB Driver subsystem low level driver source template.
|
|
|
|
*
|
|
|
|
* @addtogroup USB
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
#if HAL_USE_USB || defined(__DOXYGEN__)
|
|
|
|
|
2011-08-26 13:47:22 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
/**
|
|
|
|
* @brief USB1 driver identifier.
|
|
|
|
*/
|
2013-02-24 15:35:53 +00:00
|
|
|
#if PLATFORM_USB_USE_USB1 || defined(__DOXYGEN__)
|
|
|
|
USBDriver USBD1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
/**
|
|
|
|
* @brief EP0 state.
|
|
|
|
* @note It is an union because IN and OUT endpoints are never used at the
|
|
|
|
* same time for EP0.
|
|
|
|
*/
|
|
|
|
static union {
|
|
|
|
/**
|
|
|
|
* @brief IN EP0 state.
|
|
|
|
*/
|
|
|
|
USBInEndpointState in;
|
|
|
|
/**
|
|
|
|
* @brief OUT EP0 state.
|
|
|
|
*/
|
|
|
|
USBOutEndpointState out;
|
|
|
|
} ep0_state;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief EP0 initialization structure.
|
|
|
|
*/
|
|
|
|
static const USBEndpointConfig ep0config = {
|
2013-02-24 15:35:53 +00:00
|
|
|
USB_EP_MODE_TYPE_CTRL,
|
|
|
|
_usb_ep0setup,
|
2011-02-28 18:44:46 +00:00
|
|
|
_usb_ep0in,
|
|
|
|
_usb_ep0out,
|
|
|
|
0x40,
|
|
|
|
0x40,
|
|
|
|
&ep0_state.in,
|
2013-02-25 13:10:39 +00:00
|
|
|
&ep0_state.out
|
2011-02-28 18:44:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2013-02-24 15:35:53 +00:00
|
|
|
/* Driver interrupt handlers and threads. */
|
2011-02-28 18:44:46 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Low level USB driver initialization.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_init(void) {
|
|
|
|
|
2013-02-24 15:35:53 +00:00
|
|
|
#if PLATFORM_USB_USE_USB1
|
2013-02-25 13:10:39 +00:00
|
|
|
/* Driver initialization.*/
|
2013-02-24 15:35:53 +00:00
|
|
|
usbObjectInit(&USBD1);
|
2013-02-25 13:10:39 +00:00
|
|
|
#endif /* PLATFORM_USB_USE_USB1 */
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configures and activates the USB peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_start(USBDriver *usbp) {
|
|
|
|
|
|
|
|
if (usbp->state == USB_STOP) {
|
2013-02-27 10:42:09 +00:00
|
|
|
/* Enables the peripheral.*/
|
2013-02-25 13:10:39 +00:00
|
|
|
#if PLATFORM_USB_USE_USB1
|
2013-02-24 15:35:53 +00:00
|
|
|
if (&USBD1 == usbp) {
|
2011-02-28 18:44:46 +00:00
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
}
|
|
|
|
#endif /* PLATFORM_USB_USE_USB1 */
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
2013-02-25 13:10:39 +00:00
|
|
|
/* Configures the peripheral.*/
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deactivates the USB peripheral.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_stop(USBDriver *usbp) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
if (usbp->state == USB_READY) {
|
|
|
|
/* Resets the peripheral.*/
|
|
|
|
|
|
|
|
/* Disables the peripheral.*/
|
|
|
|
#if PLATFORM_USB_USE_USB1
|
|
|
|
if (&USBD1 == usbp) {
|
2011-02-28 18:44:46 +00:00
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
}
|
|
|
|
#endif /* PLATFORM_USB_USE_USB1 */
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief USB low level reset routine.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_reset(USBDriver *usbp) {
|
|
|
|
|
|
|
|
/* Post reset initialization.*/
|
|
|
|
|
|
|
|
/* EP0 initialization.*/
|
|
|
|
usbp->epc[0] = &ep0config;
|
|
|
|
usb_lld_init_endpoint(usbp, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the USB address.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_set_address(USBDriver *usbp) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enables an endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disables all the active endpoints except the endpoint zero.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_disable_endpoints(USBDriver *usbp) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the status of an OUT endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
* @return The endpoint status.
|
|
|
|
* @retval EP_STATUS_DISABLED The endpoint is not active.
|
|
|
|
* @retval EP_STATUS_STALLED The endpoint is stalled.
|
|
|
|
* @retval EP_STATUS_ACTIVE The endpoint is active.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
usbepstatus_t usb_lld_get_status_out(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
|
|
|
return EP_STATUS_DISABLED;
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the status of an IN endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
* @return The endpoint status.
|
|
|
|
* @retval EP_STATUS_DISABLED The endpoint is not active.
|
|
|
|
* @retval EP_STATUS_STALLED The endpoint is stalled.
|
|
|
|
* @retval EP_STATUS_ACTIVE The endpoint is active.
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
usbepstatus_t usb_lld_get_status_in(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
|
|
|
return EP_STATUS_DISABLED;
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
2011-03-10 18:54:58 +00:00
|
|
|
/**
|
|
|
|
* @brief Reads a setup packet from the dedicated packet buffer.
|
|
|
|
* @details This function must be invoked in the context of the @p setup_cb
|
|
|
|
* callback in order to read the received setup packet.
|
|
|
|
* @pre In order to use this function the endpoint must have been
|
|
|
|
* initialized as a control endpoint.
|
|
|
|
* @post The endpoint is ready to accept another packet.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
* @param[out] buf buffer where to copy the packet data
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_read_setup(USBDriver *usbp, usbep_t ep, uint8_t *buf) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
(void)buf;
|
|
|
|
|
2011-03-10 18:54:58 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Prepares for a receive operation.
|
2011-02-28 18:44:46 +00:00
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2013-02-24 15:35:53 +00:00
|
|
|
void usb_lld_prepare_receive(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
2011-02-28 18:44:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Prepares for a transmit operation.
|
2011-02-28 18:44:46 +00:00
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2013-02-24 15:35:53 +00:00
|
|
|
void usb_lld_prepare_transmit(USBDriver *usbp, usbep_t ep) {
|
2013-02-25 13:10:39 +00:00
|
|
|
|
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
2011-02-28 18:44:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Starts a receive operation on an OUT endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2013-02-24 15:35:53 +00:00
|
|
|
void usb_lld_start_out(USBDriver *usbp, usbep_t ep) {
|
2011-02-28 18:44:46 +00:00
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Starts a transmit operation on an IN endpoint.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
2013-02-24 15:35:53 +00:00
|
|
|
void usb_lld_start_in(USBDriver *usbp, usbep_t ep) {
|
2011-02-28 18:44:46 +00:00
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Brings an OUT endpoint in the stalled state.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_stall_out(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Brings an IN endpoint in the stalled state.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_stall_in(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Brings an OUT endpoint in the active state.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_clear_out(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Brings an IN endpoint in the active state.
|
|
|
|
*
|
|
|
|
* @param[in] usbp pointer to the @p USBDriver object
|
|
|
|
* @param[in] ep endpoint number
|
|
|
|
*
|
|
|
|
* @notapi
|
|
|
|
*/
|
|
|
|
void usb_lld_clear_in(USBDriver *usbp, usbep_t ep) {
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
(void)usbp;
|
|
|
|
(void)ep;
|
|
|
|
|
2011-02-28 18:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAL_USE_USB */
|
|
|
|
|
|
|
|
/** @} */
|