USBC low-level driver for USB Device mode.
The following USBB driver configuration must be included in the conf_usb.h file of the application.
UDD_USB_INT_LEVEL
Option to change the interrupt priority (USB_INTLVL_x_gc) by default USB_INTLVL_LO_gc (recommended).
The USB driver is fully managed by interrupt and does not request periodic task. Thereby, the USB events use callbacks to transfer the information. The callbacks are declared in static during compilation or in variable during code execution.
Static declarations defined in conf_usb.h:
Dynamic callbacks, called "endpoint job" , are registered in udd_ep_job_t structure via the following functions:
The Sleep modes authorized :
The USB_SLEEP_MODE_USB_IDLE equals SLEEPMGR_IDLE.
The USB_SLEEP_MODE_USB_SUSPEND depends on USB clock startup timing: | Clock Startup | Sleep mode authorized | | >10ms | SLEEPMGR_STDBY | | <=10ms | SLEEPMGR_PDOWN |
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... | |
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. | |
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... | |
#define | USBC_SLEEP_MODE_USB_SUSPEND SLEEPMGR_PDOWN |
Definition of sleep levels. More... | |
#define | USBC_SLEEP_MODE_USB_IDLE SLEEPMGR_IDLE |
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... | |
USB Device main management | |
static void | usb_pad_init (void) |
Initializes the USB DP/DM buffers. More... | |
#define | udd_enable_interface() (USB_CTRLA |= USB_ENABLE_bm) |
#define | udd_disable_interface() (USB_CTRLA &= ~USB_ENABLE_bm) |
#define | udd_attach_device() (USB_CTRLB |= USB_ATTACH_bm) |
#define | udd_detach_device() (USB_CTRLB &= ~USB_ATTACH_bm) |
#define | udd_gnak_disable() (USB_CTRLB &= ~USB_GNACK_bm) |
#define | udd_gnak_enable() (USB_CTRLB |= USB_GNACK_bm) |
#define | udd_gnak_is_enable() (USB_CTRLB & USB_GNACK_bm) |
#define | udd_set_nb_max_ep(n) (USB_CTRLA |= n) |
#define | udd_enable_store_frame_number() (USB_CTRLA |= USB_STFRNUM_bm) |
#define | udd_disable_store_frame_number() (USB_CTRLA &= ~USB_STFRNUM_bm) |
#define | udd_set_full_speed() (USB_CTRLA |= USB_SPEED_bm) |
#define | udd_set_low_speed() (USB_CTRLA &= ~USB_SPEED_bm) |
#define | udd_set_ep_table_addr(n) (USB.EPPTR = (uint16_t)n) |
#define | udd_get_ep_table_addr() (USB.EPPTR) |
#define | udd_get_fifo_rp() (USB_FIFORP) |
#define | udd_reset_fifo() (USB_FIFORP=0xFF) |
#define | udd_enable_interrupt(level) (USB_INTCTRLA |= level&(USB_INTLVL1_bm|USB_INTLVL0_bm)) |
#define | udd_set_device_address(n) (USB_ADDR=n) |
#define | udd_get_device_address() (USB_ADDR) |
#define | udd_enable_fifo() (USB_CTRLA |= USB_FIFOEN_bm) |
#define | udd_disable_fifo() (USB_CTRLA &= ~USB_FIFOEN_bm) |
#define | udd_send_remote_wake_up() (USB_CTRLB &= ~USB_RWAKEUP_bm, USB_CTRLB |= USB_RWAKEUP_bm) |
#define | udd_set_global_nack() (USB_CTRLB |= USB_GNACK_bm) |
#define | udd_is_crc_event() (USB_INTFLAGSASET & USB_CRCIF_bm ? true : false) |
#define | udd_ack_crc_event() (USB_INTFLAGSACLR = USB_CRCIF_bm) |
#define | udd_set_crc_event() (USB_INTFLAGSASET = USB_CRCIF_bm) |
#define | udd_enable_crc_interrupt() (USB_INTCTRLA |= USB_CRCIE_bm) |
#define | udd_disable_crc_interrupt() (USB_INTCTRLA &= ~USB_CRCIE_bm) |
#define | udd_is_start_of_frame_event() (USB_INTFLAGSASET & USB_SOFIF_bm ? true : false) |
#define | udd_ack_start_of_frame_event() (USB_INTFLAGSACLR = USB_SOFIF_bm) |
#define | udd_set_start_of_frame_event() (USB_INTFLAGSASET = USB_SOFIF_bm) |
#define | udd_enable_start_of_frame_interrupt() (USB_INTCTRLA |= USB_SOFIE_bm) |
#define | udd_disable_start_of_frame_interrupt() (USB_INTCTRLA &= ~USB_SOFIE_bm) |
#define | udd_is_enable_start_of_frame_interrupt() (0!=(USB_INTCTRLA|USB_SOFIE_bm)) |
#define | udd_is_reset_event() (USB_INTFLAGSASET & USB_RSTIF_bm ? true : false) |
#define | udd_ack_reset_event() (USB_INTFLAGSACLR = USB_RSTIF_bm) |
#define | udd_set_reset_event() (USB_INTFLAGSASET = USB_RSTIF_bm) |
#define | udd_is_suspend_event() (USB_INTFLAGSASET & USB_SUSPENDIF_bm ? true : false) |
#define | udd_ack_suspend_event() (USB_INTFLAGSACLR = USB_SUSPENDIF_bm) |
#define | udd_set_suspend_event() (USB_INTFLAGSASET = USB_SUSPENDIF_bm) |
#define | udd_is_resume_event() (USB_INTFLAGSASET & USB_RESUMEIF_bm ? true : false) |
#define | udd_ack_resume_event() (USB_INTFLAGSACLR = USB_RESUMEIF_bm) |
#define | udd_set_resume_event() (USB_INTFLAGSASET = USB_RESUMEIF_bm) |
#define | udd_enable_busevt_interrupt() (USB_INTCTRLA |= USB_BUSEVIE_bm) |
#define | udd_disable_busevt_interrupt() (USB_INTCTRLA &= ~USB_BUSEVIE_bm) |
#define | udd_is_setup_event() (USB_INTFLAGSBCLR & USB_SETUPIF_bm ? true : false) |
#define | udd_ack_setup_event() (USB_INTFLAGSBCLR = USB_SETUPIF_bm) |
#define | udd_set_setup_event() (USB_INTFLAGSBSET = USB_SETUPIF_bm) |
#define | udd_enable_setup_interrupt() (USB_INTCTRLB |= USB_SETUPIE_bm) |
#define | udd_disable_setup_interrupt() (USB_INTCTRLB &= ~USB_SETUPIE_bm) |
#define | udd_is_tc_event() (USB_INTFLAGSBCLR & USB_TRNIF_bm ? true : false) |
#define | udd_ack_tc_event() (USB_INTFLAGSBCLR = USB_TRNIF_bm) |
#define | udd_set_tc_event() (USB_INTFLAGSBSET = USB_TRNIF_bm) |
#define | udd_enable_tc_interrupt() (USB_INTCTRLB |= USB_TRNIE_bm) |
#define | udd_disable_tc_interrupt() (USB_INTCTRLB &= ~USB_TRNIE_bm) |
#define | udd_is_overflow_event() (USB_INTFLAGSASET & USB_OVFIF_bm ? true : false) |
#define | udd_ack_overflow_event() (USB_INTFLAGSACLR = USB_OVFIF_bm) |
#define | udd_set_overflow_event() (USB_INTFLAGSASET = USB_OVFIF_bm) |
#define | udd_enable_overflow_interrupt() (USB_INTCTRLA |= USB_BUSERRIE_bm) |
#define | udd_disable_overflow_interrupt() (USB_INTCTRLA &= ~USB_BUSERRIE_bm) |
#define | udd_is_enable_overflow_interrupt() (USB_INTCTRLA&USB_BUSERRIE_bm ? true : false) |
#define | udd_is_underflow_event() (USB_INTFLAGSASET & USB_UNFIF_bm ? true : false) |
#define | udd_ack_underflow_event() (USB_INTFLAGSACLR = USB_UNFIF_bm) |
#define | udd_set_underflow_event() (USB_INTFLAGSASET = USB_UNFIF_bm) |
#define | udd_enable_underflow_interrupt() (USB_INTCTRLA |= USB_BUSERRIE_bm) |
#define | udd_disable_underflow_interrupt() (USB_INTCTRLA &= ~USB_BUSERRIE_bm) |
#define | udd_is_enable_underflow_interrupt() (USB_INTCTRLA&USB_BUSERRIE_bm ? true : false) |
#define | udd_is_stall_event() (USB_INTFLAGSASET & USB_STALLIF_bm ? true : false) |
#define | udd_ack_stall_event() (USB_INTFLAGSACLR = USB_STALLIF_bm) |
#define | udd_set_stall_event() (USB_INTFLAGSASET = USB_STALLIF_bm) |
#define | udd_enable_stall_interrupt() (USB_INTCTRLA |= USB_STALLIE_bm) |
#define | udd_disable_stall_interrupt() (USB_INTCTRLA &= ~USB_STALLIE_bm) |
#define | udd_is_enable_stall_interrupt() (USB_INTCTRLA&USB_STALLIE_bm ? true : false) |
USB Device read/modify/write management | |
#define | LACR16(addr, msk) |
#define | LASR16(addr, msk) |
#define | XCHR16(addr, msk) |
#define | LATR16(addr, msk) |
USB Device endpoints table management | |
#define | udd_endpoint_set_control(ep_ctrl, val) (ep_ctrl->CTRL=val) |
#define | udd_endpoint_get_control(ep_ctrl) (ep_ctrl->CTRL) |
#define | udd_endpoint_disable(ep_ctrl) udd_endpoint_set_control(ep_ctrl,0) |
#define | udd_endpoint_is_enable(ep_ctrl) (USB_EP_TYPE_DISABLE_gc!=udd_endpoint_get_type(ep_ctrl)) |
#define | udd_endpoint_enable_stall(ep_ctrl) (ep_ctrl->CTRL |= USB_EP_STALL_bm) |
#define | udd_endpoint_disable_stall(ep_ctrl) (ep_ctrl->CTRL &= ~USB_EP_STALL_bm) |
#define | udd_endpoint_is_stall(ep_ctrl) (ep_ctrl->CTRL &USB_EP_STALL_bm ? true : false) |
#define | udd_endpoint_set_multipacket(ep_ctrl) (ep_ctrl->CTRL |= USB_EP_MULTIPKT_bm) |
#define | udd_endpoint_TC_int_disable(ep_ctrl) (ep_ctrl->CTRL |= USB_EP_INTDSBL_bm) |
#define | udd_endpoint_set_pingpong(ep_ctrl) (ep_ctrl->CTRL |= USB_EP_PINGPONG_bm) |
#define | udd_endpoint_get_size_field(ep_ctrl) (ep_ctrl->CTRL & USB_EP_BUFSIZE_gm) |
#define | udd_endpoint_get_type(ep_ctrl) (ep_ctrl->CTRL & USB_EP_TYPE_gm) |
#define | udd_endpoint_get_status(ep_ctrl) (ep_ctrl->STATUS) |
#define | udd_endpoint_clear_status(ep_ctrl) (ep_ctrl->STATUS=USB_EP_BUSNACK0_bm|USB_EP_BUSNACK1_bm) |
#define | udd_endpoint_setup_received(ep_ctrl) (ep_ctrl->STATUS&USB_EP_SETUP_bm ? true : false) |
#define | udd_endpoint_ack_setup_received(ep_ctrl) LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm) |
#define | udd_endpoint_transfer_complete(ep_ctrl) (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false) |
#define | udd_endpoint_ack_transfer_complete(ep_ctrl) LACR16(&(ep_ctrl->STATUS), USB_EP_TRNCOMPL0_bm) |
#define | udd_endpoint_transfer_complete_bank0(ep_ctrl) (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false) |
#define | udd_endpoint_ack_transfer_complete_bankO(ep_ctrl) LACR16(&ep_ctrl->STATUS, USB_EP_TRNCOMPL0_bm) |
#define | udd_endpoint_transfer_complete_bank1(ep_ctrl) (ep_ctrl->STATUS&USB_EP_SETUP_bm ? true : false) |
#define | udd_endpoint_ack_transfer_complete_bank1(ep_ctrl) LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm) |
#define | udd_endpoint_get_bank(ep_ctrl) (ep_ctrl->STATUS & USB_EP_BANK_bm ? true : false) |
#define | udd_endpoint_set_bank(ep_ctrl) LASR16(&ep_ctrl->STATUS, USB_EP_BANK_bm) |
#define | udd_endpoint_clear_bank(ep_ctrl) LACR16(&ep_ctrl->STATUS, USB_EP_BANK_bm) |
#define | udd_endpoint_set_dtgl(ep_ctrl) LASR16(&ep_ctrl->STATUS,USB_EP_TOGGLE_bm) |
#define | udd_endpoint_clear_dtgl(ep_ctrl) LACR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm ) |
#define | udd_endpoint_get_dtgl(ep_ctrl) ((ep_ctrl->STATUS)&USB_EP_TOGGLE_bm ? true : false) |
#define | udd_endpoint_toggle_dtgl(ep_ctrl) LATR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm) |
#define | udd_endpoint_set_NACK0(ep_ctrl) LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK0_bm) |
#define | udd_endpoint_set_NACK1(ep_ctrl) LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK1_bm) |
#define | udd_endpoint_clear_NACK0(ep_ctrl) LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK0_bm) |
#define | udd_endpoint_clear_NACK1(ep_ctrl) LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK1_bm) |
#define | udd_endpoint_get_NACK1(ep_ctrl) ((ep_ctrl->STATUS&USB_EP_BUSNACK1_bm) ? true : false) |
#define | udd_endpoint_get_NACK0(ep_ctrl) ((ep_ctrl->STATUS&USB_EP_BUSNACK0_bm) ? true : false) |
#define | udd_endpoint_overflow(ep_ctrl) (ep_ctrl->STATUS&USB_EP_OVF_bm ? true : false) |
#define | udd_endpoint_underflow(ep_ctrl) (ep_ctrl->STATUS&USB_EP_UNF_bm ? true : false) |
#define | UDD_ENDPOINT_MAX_TRANS (0x3FF) |
#define | udd_endpoint_out_nb_receiv(ep_ctrl) (ep_ctrl->CNT) |
#define | udd_endpoint_out_reset_nb_received(ep_ctrl) (ep_ctrl->CNT = 0) |
#define | udd_endpoint_in_set_bytecnt(ep_ctrl, n) (ep_ctrl->CNT = n) |
#define | udd_endpoint_set_azlp(ep_ctrl) (ep_ctrl->CNT |= 0x8000) |
#define | udd_endpoint_clear_azlp(ep_ctrl) (ep_ctrl->CNT &= ~0x8000) |
#define | udd_endpoint_set_buf(ep_ctrl, buf) (ep_ctrl->DATAPTR = (uint16_t) buf) |
#define | udd_endpoint_in_nb_sent(ep_ctrl) (ep_ctrl->AUXDATA) |
#define | udd_endpoint_in_reset_nb_sent(ep_ctrl) (ep_ctrl->AUXDATA = 0) |
#define | udd_endpoint_out_set_nbbyte(ep_ctrl, nb) (ep_ctrl->AUXDATA = nb) |
#define | udd_endpoint_out_get_nbbyte_requested(ep_ctrl) (ep_ctrl->AUXDATA) |
#define | udd_endpoint_set_aux(ep_ctrl, buf) (ep_ctrl->AUXDATA = (uint16_t) buf) |
USB Device endpoint control setup field management | |
#define | udd_control_setup() (udd_sram.ep_ctrl[0].STATUS&USB_EP_SETUP_bm ? true : false) |
#define | udd_control_ack_setup() LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_SETUP_bm) |
USB Device endpoint control OUT field management | |
#define | udd_control_out_is_enable_stall() (udd_sram.ep_ctrl[0].CTRL&USB_EP_STALL_bm ? true : false) |
#define | udd_control_out_enable_stall() LASR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm) |
#define | udd_control_out_disable_stall() LACR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm) |
#define | udd_control_out_is_stalled() (udd_sram.ep_ctrl[0].STATUS&USB_EP_STALLF_bm ? true : false) |
#define | udd_control_out_ack_stall() LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_STALLF_bm) |
#define | udd_control_out_set_NACK0() LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm) |
#define | udd_control_out_clear_NACK0() LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm) |
#define | udd_control_out_overflow() (udd_sram.ep_ctrl[0].STATUS&USB_EP_OVF_bm ? true : false) |
#define | udd_control_ack_out_overflow() LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_OVF_bm) |
#define | udd_control_out_tc() (udd_sram.ep_ctrl[0].STATUS&USB_EP_TRNCOMPL0_bm ? true : false) |
#define | udd_control_out_ack_tc() LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm) |
#define | udd_control_out_set_tc() LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm) |
#define | udd_control_out_dt_get() (udd_sram.ep_ctrl[0].STATUS&USB_EP_TOGGLE_bm ? true : false) |
#define | udd_control_out_dt_set() LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm ) |
#define | udd_control_out_dt_clear() LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm ) |
#define | udd_control_out_dt_toggle() LATR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm) |
#define | udd_control_out_set_buf(buf) (udd_sram.ep_ctrl[0].DATAPTR = (uint16_t) buf) |
#define | udd_control_out_get_bytecnt() (udd_sram.ep_ctrl[0].CNT) |
USB Device endpoint control IN field management | |
#define | udd_control_in_is_enable_stall() (udd_sram.ep_ctrl[1].CTRL&USB_EP_STALL_bm ? true : false) |
#define | udd_control_in_enable_stall() LASR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm) |
#define | udd_control_in_disable_stall() LACR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm) |
#define | udd_control_in_is_stalled() (udd_sram.ep_ctrl[1].STATUS&USB_EP_STALLF_bm ? true : false) |
#define | udd_control_in_ack_stall() LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_STALLF_bm) |
#define | udd_control_in_set_NACK0() LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm) |
#define | udd_control_in_clear_NACK0() LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm) |
#define | udd_control_in_underflow() (udd_sram.ep_ctrl[1].STATUS&USB_EP_UNF_bm ? true : false) |
#define | udd_control_ack_in_underflow() LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_UNF_bm) |
#define | udd_control_in_tc() (udd_sram.ep_ctrl[1].STATUS&USB_EP_TRNCOMPL0_bm ? true : false) |
#define | udd_control_in_ack_tc() LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm) |
#define | udd_control_in_set_tc() LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm) |
#define | udd_control_in_dt_get() (udd_sram.ep_ctrl[1].STATUS&USB_EP_TOGGLE_bm ? true : false) |
#define | udd_control_in_dt_set() LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm ) |
#define | udd_control_in_dt_clear() LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm ) |
#define | udd_control_in_dt_toggle() LATR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm) |
#define | udd_control_in_set_buf(buf) (udd_sram.ep_ctrl[1].DATAPTR = (uint16_t) buf) |
#define | udd_control_in_set_bytecnt(n) (udd_sram.ep_ctrl[1].CNT = n) |
#define LACR16 | ( | addr, | |
msk | |||
) |
#define LASR16 | ( | addr, | |
msk | |||
) |
#define LATR16 | ( | addr, | |
msk | |||
) |
#define udd_ack_crc_event | ( | ) | (USB_INTFLAGSACLR = USB_CRCIF_bm) |
#define udd_ack_overflow_event | ( | ) | (USB_INTFLAGSACLR = USB_OVFIF_bm) |
Referenced by udd_ctrl_interrupt_error().
#define udd_ack_reset_event | ( | ) | (USB_INTFLAGSACLR = USB_RSTIF_bm) |
Referenced by ISR().
#define udd_ack_resume_event | ( | ) | (USB_INTFLAGSACLR = USB_RESUMEIF_bm) |
Referenced by ISR(), and udd_attach().
#define udd_ack_setup_event | ( | ) | (USB_INTFLAGSBCLR = USB_SETUPIF_bm) |
Referenced by udd_ctrl_interrupt_tc_setup().
#define udd_ack_stall_event | ( | ) | (USB_INTFLAGSACLR = USB_STALLIF_bm) |
Referenced by udd_ctrl_interrupt_tc_setup().
#define udd_ack_start_of_frame_event | ( | ) | (USB_INTFLAGSACLR = USB_SOFIF_bm) |
Referenced by ISR().
#define udd_ack_suspend_event | ( | ) | (USB_INTFLAGSACLR = USB_SUSPENDIF_bm) |
Referenced by ISR(), and udd_attach().
#define udd_ack_tc_event | ( | ) | (USB_INTFLAGSBCLR = USB_TRNIF_bm) |
Referenced by ISR().
#define udd_ack_underflow_event | ( | ) | (USB_INTFLAGSACLR = USB_UNFIF_bm) |
Referenced by udd_ctrl_interrupt_error().
#define udd_attach_device | ( | ) | (USB_CTRLB |= USB_ATTACH_bm) |
Referenced by udd_attach().
#define udd_control_ack_in_underflow | ( | ) | LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_UNF_bm) |
Referenced by udd_ctrl_init().
#define udd_control_ack_out_overflow | ( | ) | LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_OVF_bm) |
Referenced by udd_ctrl_init().
#define udd_control_ack_setup | ( | ) | LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_SETUP_bm) |
Referenced by udd_ctrl_interrupt_tc_setup().
#define udd_control_in_ack_stall | ( | ) | LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_STALLF_bm) |
Referenced by udd_ctrl_interrupt_tc_setup().
#define udd_control_in_ack_tc | ( | ) | LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm) |
Referenced by udd_ctrl_init().
#define udd_control_in_clear_NACK0 | ( | ) | LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm) |
Referenced by udd_ctrl_in_sent(), and udd_ctrl_send_zlp_in().
#define udd_control_in_disable_stall | ( | ) | LACR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm) |
#define udd_control_in_dt_clear | ( | ) | LACR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm ) |
#define udd_control_in_dt_set | ( | ) | LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm ) |
#define udd_control_in_dt_toggle | ( | ) | LATR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TOGGLE_bm) |
#define udd_control_in_enable_stall | ( | ) | LASR16(&udd_sram.ep_ctrl[1].CTRL,USB_EP_STALL_bm) |
Referenced by udd_ctrl_overflow(), udd_ctrl_stall_data(), and udd_ctrl_underflow().
#define udd_control_in_is_enable_stall | ( | ) | (udd_sram.ep_ctrl[1].CTRL&USB_EP_STALL_bm ? true : false) |
#define udd_control_in_set_buf | ( | buf | ) | (udd_sram.ep_ctrl[1].DATAPTR = (uint16_t) buf) |
Referenced by udd_ctrl_in_sent().
#define udd_control_in_set_bytecnt | ( | n | ) | (udd_sram.ep_ctrl[1].CNT = n) |
Referenced by udd_ctrl_in_sent(), udd_ctrl_init(), and udd_ctrl_send_zlp_in().
#define udd_control_in_set_NACK0 | ( | ) | LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_BUSNACK0_bm) |
Referenced by udd_ctrl_init().
#define udd_control_in_set_tc | ( | ) | LASR16(&udd_sram.ep_ctrl[1].STATUS,USB_EP_TRNCOMPL0_bm) |
Referenced by udd_ctrl_interrupt_error().
#define udd_control_out_ack_stall | ( | ) | LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_STALLF_bm) |
Referenced by udd_ctrl_interrupt_tc_setup().
#define udd_control_out_ack_tc | ( | ) | LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm) |
Referenced by udd_ctrl_out_received(), and udd_ctrl_setup_received().
#define udd_control_out_clear_NACK0 | ( | ) | LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm) |
Referenced by udd_ctrl_out_received(), udd_ctrl_send_zlp_out(), and udd_ctrl_setup_received().
#define udd_control_out_disable_stall | ( | ) | LACR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm) |
#define udd_control_out_dt_clear | ( | ) | LACR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm ) |
#define udd_control_out_dt_set | ( | ) | LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm ) |
#define udd_control_out_dt_toggle | ( | ) | LATR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TOGGLE_bm) |
#define udd_control_out_enable_stall | ( | ) | LASR16(&udd_sram.ep_ctrl[0].CTRL,USB_EP_STALL_bm) |
Referenced by udd_ctrl_overflow(), udd_ctrl_stall_data(), and udd_ctrl_underflow().
#define udd_control_out_get_bytecnt | ( | ) | (udd_sram.ep_ctrl[0].CNT) |
Referenced by udd_ctrl_out_received(), and udd_ctrl_setup_received().
#define udd_control_out_is_enable_stall | ( | ) | (udd_sram.ep_ctrl[0].CTRL&USB_EP_STALL_bm ? true : false) |
Referenced by udd_ctrl_interrupt_error().
#define udd_control_out_set_buf | ( | buf | ) | (udd_sram.ep_ctrl[0].DATAPTR = (uint16_t) buf) |
Referenced by ISR().
#define udd_control_out_set_NACK0 | ( | ) | LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_BUSNACK0_bm) |
#define udd_control_out_set_tc | ( | ) | LASR16(&udd_sram.ep_ctrl[0].STATUS,USB_EP_TRNCOMPL0_bm) |
Referenced by udd_ctrl_interrupt_tc_setup().
#define udd_detach_device | ( | ) | (USB_CTRLB &= ~USB_ATTACH_bm) |
Referenced by udd_detach(), and udd_disable().
#define udd_disable_busevt_interrupt | ( | ) | (USB_INTCTRLA &= ~USB_BUSEVIE_bm) |
#define udd_disable_crc_interrupt | ( | ) | (USB_INTCTRLA &= ~USB_CRCIE_bm) |
#define udd_disable_fifo | ( | ) | (USB_CTRLA &= ~USB_FIFOEN_bm) |
#define udd_disable_interface | ( | ) | (USB_CTRLA &= ~USB_ENABLE_bm) |
#define udd_disable_overflow_interrupt | ( | ) | (USB_INTCTRLA &= ~USB_BUSERRIE_bm) |
Referenced by udd_ctrl_init().
#define udd_disable_setup_interrupt | ( | ) | (USB_INTCTRLB &= ~USB_SETUPIE_bm) |
#define udd_disable_stall_interrupt | ( | ) | (USB_INTCTRLA &= ~USB_STALLIE_bm) |
#define udd_disable_start_of_frame_interrupt | ( | ) | (USB_INTCTRLA &= ~USB_SOFIE_bm) |
#define udd_disable_store_frame_number | ( | ) | (USB_CTRLA &= ~USB_STFRNUM_bm) |
#define udd_disable_tc_interrupt | ( | ) | (USB_INTCTRLB &= ~USB_TRNIE_bm) |
#define udd_disable_underflow_interrupt | ( | ) | (USB_INTCTRLA &= ~USB_BUSERRIE_bm) |
Referenced by udd_ctrl_init().
#define udd_enable_busevt_interrupt | ( | ) | (USB_INTCTRLA |= USB_BUSEVIE_bm) |
Referenced by udd_attach().
#define udd_enable_crc_interrupt | ( | ) | (USB_INTCTRLA |= USB_CRCIE_bm) |
#define udd_enable_fifo | ( | ) | (USB_CTRLA |= USB_FIFOEN_bm) |
Referenced by udd_enable().
#define udd_enable_interface | ( | ) | (USB_CTRLA |= USB_ENABLE_bm) |
Referenced by udd_enable().
#define udd_enable_interrupt | ( | level | ) | (USB_INTCTRLA |= level&(USB_INTLVL1_bm|USB_INTLVL0_bm)) |
Referenced by udd_enable().
#define udd_enable_overflow_interrupt | ( | ) | (USB_INTCTRLA |= USB_BUSERRIE_bm) |
Referenced by udd_ctrl_setup_received().
#define udd_enable_setup_interrupt | ( | ) | (USB_INTCTRLB |= USB_SETUPIE_bm) |
Referenced by udd_attach().
#define udd_enable_stall_interrupt | ( | ) | (USB_INTCTRLA |= USB_STALLIE_bm) |
#define udd_enable_start_of_frame_interrupt | ( | ) | (USB_INTCTRLA |= USB_SOFIE_bm) |
Referenced by udd_attach().
#define udd_enable_store_frame_number | ( | ) | (USB_CTRLA |= USB_STFRNUM_bm) |
Referenced by udd_enable().
#define udd_enable_tc_interrupt | ( | ) | (USB_INTCTRLB |= USB_TRNIE_bm) |
Referenced by udd_attach().
#define udd_enable_underflow_interrupt | ( | ) | (USB_INTCTRLA |= USB_BUSERRIE_bm) |
Referenced by udd_ctrl_setup_received().
#define udd_endpoint_ack_setup_received | ( | ep_ctrl | ) | LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm) |
#define udd_endpoint_ack_transfer_complete | ( | ep_ctrl | ) | LACR16(&(ep_ctrl->STATUS), USB_EP_TRNCOMPL0_bm) |
Referenced by ISR().
#define udd_endpoint_ack_transfer_complete_bank1 | ( | ep_ctrl | ) | LACR16(&ep_ctrl->STATUS, USB_EP_SETUP_bm) |
#define udd_endpoint_ack_transfer_complete_bankO | ( | ep_ctrl | ) | LACR16(&ep_ctrl->STATUS, USB_EP_TRNCOMPL0_bm) |
#define udd_endpoint_clear_azlp | ( | ep_ctrl | ) | (ep_ctrl->CNT &= ~0x8000) |
#define udd_endpoint_clear_bank | ( | ep_ctrl | ) | LACR16(&ep_ctrl->STATUS, USB_EP_BANK_bm) |
#define udd_endpoint_clear_dtgl | ( | ep_ctrl | ) | LACR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm ) |
Referenced by udd_ep_clear_halt().
#define udd_endpoint_clear_NACK0 | ( | ep_ctrl | ) | LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK0_bm) |
Referenced by udd_ep_trans_complet().
#define udd_endpoint_clear_NACK1 | ( | ep_ctrl | ) | LACR16(&ep_ctrl->STATUS, USB_EP_BUSNACK1_bm) |
#define udd_endpoint_clear_status | ( | ep_ctrl | ) | (ep_ctrl->STATUS=USB_EP_BUSNACK0_bm|USB_EP_BUSNACK1_bm) |
Referenced by udd_ep_init().
#define udd_endpoint_disable | ( | ep_ctrl | ) | udd_endpoint_set_control(ep_ctrl,0) |
Referenced by udd_ep_free(), and udd_ep_init().
#define udd_endpoint_disable_stall | ( | ep_ctrl | ) | (ep_ctrl->CTRL &= ~USB_EP_STALL_bm) |
Referenced by udd_ep_clear_halt().
#define udd_endpoint_enable_stall | ( | ep_ctrl | ) | (ep_ctrl->CTRL |= USB_EP_STALL_bm) |
Referenced by udd_ep_set_halt().
#define udd_endpoint_get_control | ( | ep_ctrl | ) | (ep_ctrl->CTRL) |
#define udd_endpoint_get_size_field | ( | ep_ctrl | ) | (ep_ctrl->CTRL & USB_EP_BUFSIZE_gm) |
Referenced by udd_ep_alloc(), and udd_ep_get_size().
#define udd_endpoint_get_status | ( | ep_ctrl | ) | (ep_ctrl->STATUS) |
#define udd_endpoint_get_type | ( | ep_ctrl | ) | (ep_ctrl->CTRL & USB_EP_TYPE_gm) |
Referenced by udd_ep_alloc(), and udd_ep_run().
#define udd_endpoint_in_nb_sent | ( | ep_ctrl | ) | (ep_ctrl->AUXDATA) |
Referenced by udd_ep_abort(), and udd_ep_trans_complet().
#define udd_endpoint_in_reset_nb_sent | ( | ep_ctrl | ) | (ep_ctrl->AUXDATA = 0) |
Referenced by udd_ep_run(), and udd_ep_trans_complet().
#define udd_endpoint_in_set_bytecnt | ( | ep_ctrl, | |
n | |||
) | (ep_ctrl->CNT = n) |
Referenced by udd_ep_trans_complet().
#define udd_endpoint_is_enable | ( | ep_ctrl | ) | (USB_EP_TYPE_DISABLE_gc!=udd_endpoint_get_type(ep_ctrl)) |
Referenced by udd_ep_alloc(), and udd_ep_run().
Referenced by udd_ep_clear_halt(), udd_ep_is_halted(), udd_ep_run(), and udd_ep_wait_stall_clear().
#define UDD_ENDPOINT_MAX_TRANS (0x3FF) |
Referenced by udd_ep_trans_complet().
#define udd_endpoint_out_get_nbbyte_requested | ( | ep_ctrl | ) | (ep_ctrl->AUXDATA) |
Referenced by udd_ep_trans_complet().
#define udd_endpoint_out_nb_receiv | ( | ep_ctrl | ) | (ep_ctrl->CNT) |
Referenced by udd_ep_abort(), and udd_ep_trans_complet().
#define udd_endpoint_out_reset_nb_received | ( | ep_ctrl | ) | (ep_ctrl->CNT = 0) |
Referenced by udd_ep_run(), and udd_ep_trans_complet().
#define udd_endpoint_out_set_nbbyte | ( | ep_ctrl, | |
nb | |||
) | (ep_ctrl->AUXDATA = nb) |
Referenced by udd_ep_run(), and udd_ep_trans_complet().
#define udd_endpoint_set_aux | ( | ep_ctrl, | |
buf | |||
) | (ep_ctrl->AUXDATA = (uint16_t) buf) |
#define udd_endpoint_set_azlp | ( | ep_ctrl | ) | (ep_ctrl->CNT |= 0x8000) |
#define udd_endpoint_set_bank | ( | ep_ctrl | ) | LASR16(&ep_ctrl->STATUS, USB_EP_BANK_bm) |
#define udd_endpoint_set_buf | ( | ep_ctrl, | |
buf | |||
) | (ep_ctrl->DATAPTR = (uint16_t) buf) |
Referenced by udd_ep_trans_complet().
#define udd_endpoint_set_control | ( | ep_ctrl, | |
val | |||
) | (ep_ctrl->CTRL=val) |
Referenced by udd_ep_init().
#define udd_endpoint_set_dtgl | ( | ep_ctrl | ) | LASR16(&ep_ctrl->STATUS,USB_EP_TOGGLE_bm) |
#define udd_endpoint_set_multipacket | ( | ep_ctrl | ) | (ep_ctrl->CTRL |= USB_EP_MULTIPKT_bm) |
Referenced by udd_ep_alloc().
#define udd_endpoint_set_NACK0 | ( | ep_ctrl | ) | LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK0_bm) |
Referenced by udd_ep_abort().
#define udd_endpoint_set_NACK1 | ( | ep_ctrl | ) | LASR16(&ep_ctrl->STATUS,USB_EP_BUSNACK1_bm) |
#define udd_endpoint_set_pingpong | ( | ep_ctrl | ) | (ep_ctrl->CTRL |= USB_EP_PINGPONG_bm) |
#define udd_endpoint_TC_int_disable | ( | ep_ctrl | ) | (ep_ctrl->CTRL |= USB_EP_INTDSBL_bm) |
#define udd_endpoint_toggle_dtgl | ( | ep_ctrl | ) | LATR16(&ep_ctrl->STATUS, USB_EP_TOGGLE_bm) |
#define udd_endpoint_transfer_complete | ( | ep_ctrl | ) | (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false) |
Referenced by ISR().
#define udd_endpoint_transfer_complete_bank0 | ( | ep_ctrl | ) | (ep_ctrl->STATUS&USB_EP_TRNCOMPL0_bm ? true : false) |
#define udd_endpoint_transfer_complete_bank1 | ( | ep_ctrl | ) | (ep_ctrl->STATUS&USB_EP_SETUP_bm ? true : false) |
#define udd_get_device_address | ( | ) | (USB_ADDR) |
Referenced by udd_getaddress().
#define udd_get_ep_table_addr | ( | ) | (USB.EPPTR) |
#define udd_get_fifo_rp | ( | ) | (USB_FIFORP) |
Referenced by ISR().
#define udd_gnak_disable | ( | ) | (USB_CTRLB &= ~USB_GNACK_bm) |
#define udd_gnak_enable | ( | ) | (USB_CTRLB |= USB_GNACK_bm) |
#define udd_gnak_is_enable | ( | ) | (USB_CTRLB & USB_GNACK_bm) |
#define udd_is_enable_start_of_frame_interrupt | ( | ) | (0!=(USB_INTCTRLA|USB_SOFIE_bm)) |
Referenced by udd_ctrl_interrupt_error().
Referenced by ISR().
Referenced by ISR().
Referenced by udd_ctrl_interrupt_tc_setup().
Referenced by ISR().
Referenced by ISR().
Referenced by ISR(), udd_ctrl_overflow(), and udd_ctrl_underflow().
Referenced by udd_ctrl_interrupt_error().
#define udd_reset_fifo | ( | ) | (USB_FIFORP=0xFF) |
Referenced by udd_enable().
#define udd_send_remote_wake_up | ( | ) | (USB_CTRLB &= ~USB_RWAKEUP_bm, USB_CTRLB |= USB_RWAKEUP_bm) |
Referenced by udd_send_remotewakeup().
#define udd_set_crc_event | ( | ) | (USB_INTFLAGSASET = USB_CRCIF_bm) |
#define udd_set_device_address | ( | n | ) | (USB_ADDR=n) |
Referenced by ISR(), and udd_set_address().
#define udd_set_ep_table_addr | ( | n | ) | (USB.EPPTR = (uint16_t)n) |
Referenced by udd_enable().
#define udd_set_full_speed | ( | ) | (USB_CTRLA |= USB_SPEED_bm) |
Referenced by udd_enable().
#define udd_set_global_nack | ( | ) | (USB_CTRLB |= USB_GNACK_bm) |
#define udd_set_low_speed | ( | ) | (USB_CTRLA &= ~USB_SPEED_bm) |
Referenced by udd_enable().
#define udd_set_nb_max_ep | ( | n | ) | (USB_CTRLA |= n) |
Referenced by udd_enable().
#define udd_set_overflow_event | ( | ) | (USB_INTFLAGSASET = USB_OVFIF_bm) |
#define udd_set_reset_event | ( | ) | (USB_INTFLAGSASET = USB_RSTIF_bm) |
#define udd_set_resume_event | ( | ) | (USB_INTFLAGSASET = USB_RESUMEIF_bm) |
#define udd_set_setup_event | ( | ) | (USB_INTFLAGSBSET = USB_SETUPIF_bm) |
#define udd_set_stall_event | ( | ) | (USB_INTFLAGSASET = USB_STALLIF_bm) |
#define udd_set_start_of_frame_event | ( | ) | (USB_INTFLAGSASET = USB_SOFIF_bm) |
#define udd_set_suspend_event | ( | ) | (USB_INTFLAGSASET = USB_SUSPENDIF_bm) |
#define udd_set_tc_event | ( | ) | (USB_INTFLAGSBSET = USB_TRNIF_bm) |
#define udd_set_underflow_event | ( | ) | (USB_INTFLAGSASET = USB_UNFIF_bm) |
#define USBC_SLEEP_MODE_USB_IDLE SLEEPMGR_IDLE |
Referenced by udd_sleep_mode().
#define USBC_SLEEP_MODE_USB_SUSPEND SLEEPMGR_PDOWN |
Definition of sleep levels.
Referenced by udd_disable(), and udd_enable().
#define XCHR16 | ( | addr, | |
msk | |||
) |
ISR | ( | USB_BUSEVENT_vect | ) |
Function called by USB bus event interrupt.
USB bus event interrupt includes :
References udc_reset(), UDC_RESUME_EVENT, UDC_SOF_EVENT, udc_sof_notify(), UDC_SUSPEND_EVENT, udd_ack_reset_event, udd_ack_resume_event, udd_ack_start_of_frame_event, udd_ack_suspend_event, udd_control_out_set_buf, udd_ctrl_init(), udd_ctrl_interrupt_error(), udd_ep_abort(), udd_ep_init(), udd_is_reset_event, udd_is_resume_event, udd_is_start_of_frame_event, udd_is_suspend_event, udd_set_device_address, udd_sleep_mode(), USB_DEVICE_EP_CTRL_SIZE, USB_DEVICE_MAX_EP, USB_EP_DIR_IN, and USB_EP_TYPE_CONTROL.
ISR | ( | USB_TRNCOMPL_vect | ) |
Function called by USB transfer complete interrupt.
USB transfer complete interrupt includes events about endpoint transfer on all endpoints.
References Assert, udd_ack_tc_event, udd_ctrl_in_sent(), udd_ctrl_interrupt_tc_setup(), udd_ctrl_out_received(), udd_endpoint_ack_transfer_complete, udd_endpoint_transfer_complete, udd_ep_get_ctrl(), udd_ep_is_valid(), UDD_EP_t, udd_ep_trans_complet(), udd_get_fifo_rp, udd_is_tc_event, USB_DEVICE_MAX_EP, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
void udd_attach | ( | void | ) |
Attach device to the bus when possible.
References cpu_irq_restore(), cpu_irq_save(), udd_ack_resume_event, udd_ack_suspend_event, udd_attach_device, udd_enable_busevt_interrupt, udd_enable_setup_interrupt, udd_enable_start_of_frame_interrupt, udd_enable_tc_interrupt, and udd_sleep_mode().
Referenced by udc_attach(), and udd_enable().
|
static |
Call callback associated to setup request.
References udd_ctrl_request_t::callback.
Referenced by udd_ctrl_in_sent(), udd_ctrl_out_received(), and udd_ctrl_setup_received().
|
static |
Managed reception of IN packet on control endpoint.
References Assert, udd_ctrl_request_t::over_under_run, udd_ctrl_request_t::payload, udd_ctrl_request_t::payload_size, udd_ctrl_request_t::req, udd_control_in_clear_NACK0, udd_control_in_set_buf, udd_control_in_set_bytecnt, udd_ctrl_endofrequest(), udd_ctrl_init(), udd_ctrl_payload_nb_trans, udd_ctrl_send_zlp_out(), USB_DEVICE_EP_CTRL_SIZE, and usb_setup_req_t::wLength.
Referenced by ISR(), and udd_ctrl_setup_received().
|
static |
Reset control endpoint management.
Called after a USB line reset or at the end of SETUP request (after ZLP)
References udd_ctrl_request_t::callback, udd_ctrl_request_t::over_under_run, udd_ctrl_request_t::payload_size, udd_control_ack_in_underflow, udd_control_ack_out_overflow, udd_control_in_ack_tc, udd_control_in_set_bytecnt, udd_control_in_set_NACK0, udd_disable_overflow_interrupt, and udd_disable_underflow_interrupt.
Referenced by ISR(), udd_ctrl_in_sent(), udd_ctrl_out_received(), and udd_ctrl_setup_received().
|
static |
Sub interrupt routine to manage error on control endpoint.
1
if an error about control endpoint is occurred, otherwise 0
. References udd_ack_overflow_event, udd_ack_underflow_event, udd_control_in_underflow, udd_control_out_overflow, udd_ctrl_overflow(), udd_ctrl_underflow(), udd_is_overflow_event, and udd_is_underflow_event.
Referenced by ISR().
|
static |
Sub interrupt routine to manage a SETUP transfer complete on control endpoint.
1
if an SETUP transfer complete about control endpoint is occurred, otherwise 0
. References Assert, udd_ack_setup_event, udd_ack_stall_event, udd_control_ack_setup, udd_control_in_ack_stall, udd_control_out_ack_stall, udd_control_setup, udd_ctrl_setup_received(), and udd_is_setup_event.
Referenced by ISR(), udd_ctrl_overflow(), and udd_ctrl_underflow().
|
static |
Managed reception of OUT packet on control endpoint.
References Assert, udd_ctrl_request_t::over_under_run, udd_ctrl_request_t::payload, udd_ctrl_request_t::payload_size, udd_ctrl_request_t::req, udd_control_out_ack_tc, udd_control_out_clear_NACK0, udd_control_out_get_bytecnt, udd_ctrl_endofrequest(), udd_ctrl_init(), udd_ctrl_payload_nb_trans, udd_ctrl_send_zlp_in(), udd_ctrl_stall_data(), USB_DEVICE_EP_CTRL_SIZE, and usb_setup_req_t::wLength.
Referenced by ISR().
|
static |
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.
This is mandatory for chapter 8 compliance
References udd_control_in_enable_stall, udd_control_out_enable_stall, udd_ctrl_interrupt_tc_setup(), udd_ctrl_send_zlp_out(), and udd_is_tc_event.
Referenced by udd_ctrl_interrupt_error().
|
static |
Send a ZLP IN on control endpoint.
References udd_control_in_clear_NACK0, and udd_control_in_set_bytecnt.
Referenced by udd_ctrl_out_received(), udd_ctrl_setup_received(), and udd_ctrl_underflow().
|
static |
Send a ZLP OUT on control endpoint.
References udd_control_out_clear_NACK0.
Referenced by udd_ctrl_in_sent(), and udd_ctrl_overflow().
|
static |
Managed reception of SETUP packet on control endpoint.
References udd_ctrl_request_t::req, udc_process_setup(), udd_control_out_ack_tc, udd_control_out_clear_NACK0, udd_control_out_get_bytecnt, udd_ctrl_endofrequest(), udd_ctrl_in_sent(), udd_ctrl_init(), udd_ctrl_send_zlp_in(), udd_ctrl_stall_data(), udd_enable_overflow_interrupt, udd_enable_underflow_interrupt, Udd_setup_is_in, and usb_setup_req_t::wLength.
Referenced by udd_ctrl_interrupt_tc_setup().
|
static |
Managed stall event of IN/OUT packet on control endpoint.
References udd_control_in_enable_stall, and udd_control_out_enable_stall.
Referenced by udd_ctrl_out_received(), and udd_ctrl_setup_received().
|
static |
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.
This is mandatory for chapter 8 compliance
References udd_control_in_enable_stall, udd_control_out_enable_stall, udd_ctrl_interrupt_tc_setup(), udd_ctrl_send_zlp_in(), and udd_is_tc_event.
Referenced by udd_ctrl_interrupt_error().
void udd_detach | ( | void | ) |
Detaches the device from the bus.
The driver must remove pull-up on USB line D- or D+.
References udd_detach_device.
Referenced by udc_detach().
void udd_disable | ( | void | ) |
Disables the USB Device mode.
References cpu_irq_restore(), cpu_irq_save(), sleepmgr_unlock_mode(), udd_detach_device, udd_sleep_mode(), and USBC_SLEEP_MODE_USB_SUSPEND.
Referenced by udc_stop().
void udd_enable | ( | void | ) |
Enables the USB Device mode.
References Assert, udd_ep_job_t::busy, cpu_irq_restore(), cpu_irq_save(), sleepmgr_lock_mode(), udd_attach(), udd_b_idle, udd_enable_fifo, udd_enable_interface, udd_enable_interrupt, udd_enable_store_frame_number, udd_reset_fifo, udd_set_ep_table_addr, udd_set_full_speed, udd_set_low_speed, udd_set_nb_max_ep, UDD_USB_INT_LEVEL, USB_DEVICE_MAX_EP, usb_pad_init(), and USBC_SLEEP_MODE_USB_SUSPEND.
Referenced by udc_start().
void udd_ep_abort | ( | udd_ep_id_t | ep | ) |
Aborts transfer on going on endpoint.
If a transfer is on going, then it is stopped and the callback registered is called to signal the end of transfer. Note: The control endpoint is not authorized.
ep | Endpoint to abort |
References Assert, udd_ep_job_t::busy, udd_ep_job_t::call_trans, udd_endpoint_in_nb_sent, udd_endpoint_out_nb_receiv, udd_endpoint_set_NACK0, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_is_valid(), UDD_EP_t, UDD_EP_TRANSFER_ABORT, and USB_EP_DIR_IN.
Referenced by ISR(), udc_req_std_ep_set_feature(), udd_ep_free(), and udd_ep_set_halt().
bool udd_ep_alloc | ( | udd_ep_id_t | ep, |
uint8_t | bmAttributes, | ||
uint16_t | MaxEndpointSize | ||
) |
Configures and enables an endpoint.
ep | Endpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT). |
bmAttributes | Attributes of endpoint declared in the descriptor. |
MaxEndpointSize | Endpoint maximum size |
1
if the endpoint is enabled, otherwise 0
. References Assert, udd_endpoint_get_size_field, udd_endpoint_get_type, udd_endpoint_is_enable, udd_endpoint_set_multipacket, udd_ep_get_ctrl(), udd_ep_init(), udd_ep_is_valid(), and UDD_EP_t.
Referenced by udc_iface_enable().
bool udd_ep_clear_halt | ( | udd_ep_id_t | ep | ) |
Clear the halted state of the endpoint ep.
After calling this function, any transaction on ep will be handled normally, i.e. a STALL handshake will not be sent, and the data toggle sequence will start at DATA0.
ep | The ID of the endpoint to be un-halted |
1
if function was successfully done, otherwise 0
. References Assert, udd_ep_job_t::busy, udd_ep_job_t::call_nohalt, udd_endpoint_clear_dtgl, udd_endpoint_disable_stall, udd_endpoint_is_stall, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_is_valid(), and UDD_EP_t.
Referenced by udc_req_std_ep_clear_feature().
void udd_ep_free | ( | udd_ep_id_t | ep | ) |
Disables an endpoint.
ep | Endpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT). |
References Assert, udd_endpoint_disable, udd_ep_abort(), udd_ep_get_ctrl(), udd_ep_is_valid(), and UDD_EP_t.
Referenced by udc_iface_disable().
|
static |
References USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
Referenced by ISR(), udd_ep_abort(), udd_ep_alloc(), udd_ep_clear_halt(), udd_ep_free(), udd_ep_init(), udd_ep_is_halted(), udd_ep_run(), udd_ep_set_halt(), udd_ep_trans_complet(), and udd_ep_wait_stall_clear().
|
static |
Returns a pointer on endpoint job corresponding at endpoint number.
ep | Endpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT). |
References USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
Referenced by udd_ep_abort(), udd_ep_clear_halt(), udd_ep_run(), udd_ep_trans_complet(), and udd_ep_wait_stall_clear().
|
static |
Returns the size of endpoint.
References udd_endpoint_get_size_field.
Referenced by udd_ep_run(), and udd_ep_trans_complet().
|
static |
References Assert, udd_endpoint_clear_status, udd_endpoint_disable, udd_endpoint_set_control, udd_ep_get_ctrl(), UDD_EP_t, USB_EP_TYPE_BULK, USB_EP_TYPE_CONTROL, USB_EP_TYPE_INTERRUPT, USB_EP_TYPE_ISOCHRONOUS, and USB_EP_TYPE_MASK.
Referenced by ISR(), and udd_ep_alloc().
bool udd_ep_is_halted | ( | udd_ep_id_t | ep | ) |
Check if the endpoint ep is halted.
ep | The ID of the endpoint to check. |
1
if ep is halted, otherwise 0
. References Assert, udd_endpoint_is_stall, udd_ep_get_ctrl(), udd_ep_is_valid(), and UDD_EP_t.
Referenced by udc_req_std_ep_get_status().
bool udd_ep_is_valid | ( | udd_ep_id_t | ep | ) |
Checks endpoint number.
ep | endpoint number |
References USB_DEVICE_MAX_EP, and USB_EP_ADDR_MASK.
Referenced by ISR(), udd_ep_abort(), udd_ep_alloc(), udd_ep_clear_halt(), udd_ep_free(), udd_ep_is_halted(), udd_ep_run(), udd_ep_set_halt(), and udd_ep_wait_stall_clear().
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.
The driver uses a specific DMA USB to transfer data from internal RAM to endpoint, if this one is available. When the transfer is finished or aborted (stall, reset, ...), the callback is called. The callback returns the transfer status and eventually the number of byte transfered. Note: The control endpoint is not authorized.
ep | The ID of the endpoint to use |
b_shortpacket | Enabled automatic short packet |
buf | Buffer on Internal RAM to send or fill. It must be align, then use COMPILER_WORD_ALIGNED. |
buf_size | Buffer size to send or fill |
callback | NULL or function to call at the end of transfer |
1
if function was successfully done, otherwise 0
. References Assert, udd_ep_job_t::b_shortpacket, udd_ep_job_t::b_use_out_cache_buffer, udd_ep_job_t::buf, udd_ep_job_t::buf_size, udd_ep_job_t::busy, udd_ep_job_t::call_trans, cpu_irq_restore(), cpu_irq_save(), udd_ep_job_t::nb_trans, udd_endpoint_get_type, udd_endpoint_in_reset_nb_sent, udd_endpoint_is_enable, udd_endpoint_is_stall, udd_endpoint_out_reset_nb_received, udd_endpoint_out_set_nbbyte, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_get_size(), udd_ep_is_valid(), UDD_EP_t, udd_ep_trans_complet(), and USB_EP_DIR_IN.
Referenced by udi_cdc_ctrl_state_notify(), udi_cdc_data_received(), udi_cdc_rx_start(), and udi_cdc_tx_send().
bool udd_ep_set_halt | ( | udd_ep_id_t | ep | ) |
Set the halted state of the endpoint ep.
After calling this function, any transaction on ep will result in a STALL handshake being sent. Any pending transactions will be performed first, however.
ep | The ID of the endpoint to be halted |
1
if ep is halted, otherwise 0
. References Assert, udd_endpoint_enable_stall, udd_ep_abort(), udd_ep_get_ctrl(), udd_ep_is_valid(), and UDD_EP_t.
Referenced by udc_req_std_ep_set_feature().
|
static |
Manages transfer complete on bulk/interrupt/isochronous endpoints.
ep | endpoint number to manage |
References udd_ep_job_t::b_shortpacket, udd_ep_job_t::b_use_out_cache_buffer, udd_ep_job_t::buf, udd_ep_job_t::buf_size, udd_ep_job_t::busy, udd_ep_job_t::call_trans, udd_ep_job_t::nb_trans, udd_endpoint_clear_NACK0, udd_endpoint_in_nb_sent, udd_endpoint_in_reset_nb_sent, udd_endpoint_in_set_bytecnt, UDD_ENDPOINT_MAX_TRANS, udd_endpoint_out_get_nbbyte_requested, udd_endpoint_out_nb_receiv, udd_endpoint_out_reset_nb_received, udd_endpoint_out_set_nbbyte, udd_endpoint_set_buf, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_get_size(), UDD_EP_t, UDD_EP_TRANSFER_OK, and USB_EP_DIR_IN.
Referenced by ISR(), and udd_ep_run().
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.
ep | The ID of the endpoint to use |
callback | NULL or function to call when endpoint halt is cleared |
1
if the register is accepted, otherwise 0
. References Assert, udd_ep_job_t::busy, udd_ep_job_t::call_nohalt, udd_endpoint_is_stall, udd_ep_get_ctrl(), udd_ep_get_job(), udd_ep_is_valid(), and UDD_EP_t.
uint16_t udd_get_frame_number | ( | void | ) |
Returns the current start of frame number.
Referenced by main_sof_action(), and udi_cdc_tx_send().
uint16_t udd_get_micro_frame_number | ( | void | ) |
Returns the current micro start of frame number.
Referenced by udi_cdc_tx_send().
uint8_t udd_getaddress | ( | void | ) |
Returns the USB address of device.
References udd_get_device_address.
Referenced by udc_req_std_dev_set_configuration().
bool udd_include_vbus_monitoring | ( | void | ) |
Authorizes the VBUS event.
Referenced by udc_include_vbus_monitoring().
bool udd_is_high_speed | ( | void | ) |
Test whether the USB Device Controller is running at high speed or not.
true
if the Device is running at high speed mode, otherwise false
. Referenced by udc_req_std_dev_get_descriptor(), udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), and udi_cdc_tx_send().
void udd_send_remotewakeup | ( | void | ) |
The USB driver sends a resume signal called Upstream Resume.
References udd_b_idle, udd_send_remote_wake_up, and udd_sleep_mode().
Referenced by udc_remotewakeup().
void udd_set_address | ( | uint8_t | address | ) |
Changes the USB address of device.
address | New USB address |
References udd_set_device_address.
Referenced by udc_valid_address().
void udd_set_setup_payload | ( | uint8_t * | payload, |
uint16_t | payload_size | ||
) |
Load setup payload.
payload | Pointer on payload |
payload_size | Size of payload |
References udd_ctrl_request_t::payload, and udd_ctrl_request_t::payload_size.
Referenced by udc_req_std_dev_get_configuration(), udc_req_std_dev_get_descriptor(), udc_req_std_dev_get_status(), udc_req_std_dev_get_str_desc(), udc_req_std_ep_get_status(), and udc_req_std_iface_get_setting().
|
static |
Authorize or not the CPU powerdown mode.
b_enable | true to authorize powerdown mode |
References sleepmgr_lock_mode(), sleepmgr_unlock_mode(), udd_b_idle, and USBC_SLEEP_MODE_USB_IDLE.
Referenced by ISR(), udd_attach(), udd_disable(), and udd_send_remotewakeup().
|
inlinestatic |
Initializes the USB DP/DM buffers.
This functions initializes the USB buffer using the calibration value stored in production raw. If the calibration value is not found (0xFF) value, a default typical value is applied. Alternatively user can force calibration values using USB_PAD_USER_CAL0 and USB_PAD_USER_CAL1
References nvm_get_production_signature_row_offset, and nvm_read_production_signature_row().
Referenced by udd_enable().
|
static |
State of USB line.
Referenced by udd_enable(), udd_send_remotewakeup(), and udd_sleep_mode().
|
static |
Buffer to store the data received on control endpoint (SETUP/OUT endpoint 0)
Used to avoid a RAM buffer overflow in case of the payload buffer is smaller than control endpoint size
udd_ctrl_ep_state_t |
|
static |
Number of data received/sent to/from udd_g_ctrlreq.payload buffer.
Referenced by udd_ctrl_in_sent(), and udd_ctrl_out_received().
|
static |
Total number of data received/sent during data packet phase with previous payload buffers.
|
static |
State of the endpoint control management.
|
static |
Array to register a job on bulk/interrupt/isochronous endpoint.
|
static |
Buffer to store the data received on bulk/interrupt endpoints.
Used to avoid a RAM buffer overflow in case of the user buffer is smaller than endpoint size