USB Device driver Compliance with common driver UDD.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include "conf_usb.h"
#include "sysclk.h"
#include "udd.h"
#include "usb_device.h"
#include <string.h>
#include "sleepmgr.h"
Data Structures | |
struct | udd_ep_job_t |
Structure definition about job registered on an endpoint. More... | |
struct | udd_sram_data |
USB SRAM data about fifo, endpoint descriptor table and frame number. More... | |
Macros | |
#define | UDD_EP_t USB_EP_t volatile |
#define | UDD_USB_INT_LEVEL USB_INTLVL_LO_gc |
Functions | |
ISR (USB_BUSEVENT_vect) | |
Function called by USB bus event interrupt. More... | |
ISR (USB_TRNCOMPL_vect) | |
Function called by USB transfer complete interrupt. More... | |
void | udd_attach (void) |
Attach device to the bus when possible. More... | |
void | udd_detach (void) |
Detaches the device from the bus. More... | |
void | udd_disable (void) |
Disables the USB Device mode. More... | |
void | udd_enable (void) |
Enables the USB Device mode. More... | |
void | udd_ep_abort (udd_ep_id_t ep) |
Aborts transfer on going on endpoint. More... | |
bool | udd_ep_alloc (udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize) |
Configures and enables an endpoint. More... | |
bool | udd_ep_clear_halt (udd_ep_id_t ep) |
Clear the halted state of the endpoint ep. More... | |
void | udd_ep_free (udd_ep_id_t ep) |
Disables an endpoint. More... | |
static UDD_EP_t * | udd_ep_get_ctrl (udd_ep_id_t ep) |
static void | udd_ep_init (udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize) |
bool | udd_ep_is_halted (udd_ep_id_t ep) |
Check if the endpoint ep is halted. More... | |
bool | udd_ep_run (udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback) |
Allows to receive or send data on an endpoint. More... | |
bool | udd_ep_set_halt (udd_ep_id_t ep) |
Set the halted state of the endpoint ep. More... | |
bool | udd_ep_wait_stall_clear (udd_ep_id_t ep, udd_callback_halt_cleared_t callback) |
Registers a callback to call when endpoint halt is cleared. More... | |
uint16_t | udd_get_frame_number (void) |
Returns the current start of frame number. More... | |
uint16_t | udd_get_micro_frame_number (void) |
Returns the current micro start of frame number. More... | |
uint8_t | udd_getaddress (void) |
Returns the USB address of device. More... | |
bool | udd_include_vbus_monitoring (void) |
Authorizes the VBUS event. More... | |
bool | udd_is_high_speed (void) |
Test whether the USB Device Controller is running at high speed or not. More... | |
void | udd_send_remotewakeup (void) |
The USB driver sends a resume signal called Upstream Resume. More... | |
void | udd_set_address (uint8_t address) |
Changes the USB address of device. More... | |
void | udd_set_setup_payload (uint8_t *payload, uint16_t payload_size) |
Load setup payload. More... | |
Power management routine. | |
#define | USBC_SLEEP_MODE_USB_SUSPEND SLEEPMGR_PDOWN |
Definition of sleep levels. More... | |
#define | USBC_SLEEP_MODE_USB_IDLE SLEEPMGR_IDLE |
static bool | udd_b_idle |
State of USB line. More... | |
static void | udd_sleep_mode (bool b_idle) |
Authorize or not the CPU powerdown mode. More... | |
Control endpoint low level management routine. | |
This function performs control endpoint management. It handle the SETUP/DATA/HANDSHAKE phases of a control transaction. | |
udd_ctrl_ep_state_t | |
static udd_ctrl_ep_state_t | udd_ep_control_state |
State of the endpoint control management. More... | |
static uint16_t | udd_ctrl_prev_payload_nb_trans |
Total number of data received/sent during data packet phase with previous payload buffers. More... | |
static uint16_t | udd_ctrl_payload_nb_trans |
Number of data received/sent to/from udd_g_ctrlreq.payload buffer. More... | |
static uint8_t | udd_ctrl_buffer [USB_DEVICE_EP_CTRL_SIZE] |
Buffer to store the data received on control endpoint (SETUP/OUT endpoint 0) More... | |
static void | udd_ctrl_init (void) |
Reset control endpoint management. More... | |
static void | udd_ctrl_setup_received (void) |
Managed reception of SETUP packet on control endpoint. More... | |
static void | udd_ctrl_in_sent (void) |
Managed reception of IN packet on control endpoint. More... | |
static void | udd_ctrl_out_received (void) |
Managed reception of OUT packet on control endpoint. More... | |
static void | udd_ctrl_underflow (void) |
Managed underflow event of IN packet on control endpoint It is used to detect a DATA phase stopped by the host via a ZLP request. More... | |
static void | udd_ctrl_overflow (void) |
Managed overflow event of OUT packet on control endpoint It is used to detect a DATA phase stopped by the host via a ZLP request. More... | |
static void | udd_ctrl_stall_data (void) |
Managed stall event of IN/OUT packet on control endpoint. More... | |
static void | udd_ctrl_send_zlp_in (void) |
Send a ZLP IN on control endpoint. More... | |
static void | udd_ctrl_send_zlp_out (void) |
Send a ZLP OUT on control endpoint. More... | |
static void | udd_ctrl_endofrequest (void) |
Call callback associated to setup request. More... | |
static bool | udd_ctrl_interrupt_error (void) |
Sub interrupt routine to manage error on control endpoint. More... | |
static bool | udd_ctrl_interrupt_tc_setup (void) |
Sub interrupt routine to manage a SETUP transfer complete on control endpoint. More... | |
Management of bulk/interrupt/isochronous endpoints | |
The UDD manages the data transfer on endpoints:
| |
static udd_ep_job_t | udd_ep_job [USB_DEVICE_MAX_EP *2] |
Array to register a job on bulk/interrupt/isochronous endpoint. More... | |
static uint8_t | udd_ep_out_cache_buffer [USB_DEVICE_MAX_EP][64] |
Buffer to store the data received on bulk/interrupt endpoints. More... | |
bool | udd_ep_is_valid (udd_ep_id_t ep) |
Checks endpoint number. More... | |
static void | udd_ep_trans_complet (udd_ep_id_t ep) |
Manages transfer complete on bulk/interrupt/isochronous endpoints. More... | |
static uint16_t | udd_ep_get_size (UDD_EP_t *ep_ctrl) |
Returns the size of endpoint. More... | |
static udd_ep_job_t * | udd_ep_get_job (udd_ep_id_t ep) |
Returns a pointer on endpoint job corresponding at endpoint number. More... | |
#define UDD_EP_t USB_EP_t volatile |
#define UDD_USB_INT_LEVEL USB_INTLVL_LO_gc |
Referenced by udd_enable().