USB OTG Driver for UOTGHS.
Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
#include "compiler.h"
Macros | |
UOTGHS OTG ID pin management | |
The ID pin come from the USB OTG connector (A and B receptable) and allows to select the USB mode host or device. The UOTGHS hardware can manage it automatically. This feature is optional. When USB_ID_GPIO is defined (in board.h), this feature is enabled. | |
#define | otg_enable_id_pin() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_UIDE)) |
Enable external OTG_ID pin (listened to by USB) More... | |
#define | otg_disable_id_pin() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_UIDE)) |
Disable external OTG_ID pin (ignored by USB) More... | |
#define | Is_otg_id_pin_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_UIDE)) |
Test if external OTG_ID pin enabled (listened to by USB) More... | |
#define | otg_force_device_mode() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_UIMOD), otg_disable_id_pin()) |
Disable external OTG_ID pin and force device mode. More... | |
#define | Is_otg_device_mode_forced() (!Is_otg_id_pin_enabled() && Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_UIMOD)) |
Test if device mode is forced. More... | |
#define | otg_force_host_mode() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_UIMOD), otg_disable_id_pin()) |
Disable external OTG_ID pin and force host mode. More... | |
#define | Is_otg_host_mode_forced() (!Is_otg_id_pin_enabled() && !Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_UIMOD)) |
Test if host mode is forced. More... | |
UOTGHS OTG ID pin interrupt management | |
These macros manage the ID pin interrupt | |
#define | otg_enable_id_interrupt() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_IDTE)) |
#define | otg_disable_id_interrupt() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_IDTE)) |
#define | Is_otg_id_interrupt_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_IDTE)) |
#define | Is_otg_id_device() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_ID)) |
#define | Is_otg_id_host() (!Is_otg_id_device()) |
#define | otg_ack_id_transition() (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_IDTIC) |
#define | otg_raise_id_transition() (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_IDTIS) |
#define | Is_otg_id_transition() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_IDTI)) |
OTG Vbus management | |
#define | otg_enable_vbus_interrupt() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_VBUSTE)) |
#define | otg_disable_vbus_interrupt() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_VBUSTE)) |
#define | Is_otg_vbus_interrupt_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_VBUSTE)) |
#define | Is_otg_vbus_high() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_VBUS)) |
#define | Is_otg_vbus_low() (!Is_otg_vbus_high()) |
#define | otg_ack_vbus_transition() (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_VBUSTIC) |
#define | otg_raise_vbus_transition() (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_VBUSTIS) |
#define | Is_otg_vbus_transition() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_VBUSTI)) |
UOTGHS OTG main management | |
These macros allows to enable/disable pad and UOTGHS hardware | |
#define | otg_reset() |
Reset USB macro. More... | |
#define | otg_enable() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_USBE)) |
Enable USB macro. More... | |
#define | otg_disable() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_USBE)) |
Disable USB macro. More... | |
#define | Is_otg_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_USBE)) |
#define | otg_enable_pad() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_OTGPADE)) |
Enable OTG pad. More... | |
#define | otg_disable_pad() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_OTGPADE)) |
Disable OTG pad. More... | |
#define | Is_otg_pad_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_OTGPADE)) |
#define | Is_otg_clock_usable() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_CLKUSABLE)) |
Check Clock Usable For parts with HS feature, this one corresponding at UTMI clock. More... | |
#define | otg_freeze_clock() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK)) |
Stop (freeze) internal USB clock. More... | |
#define | otg_unfreeze_clock() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK)) |
#define | Is_otg_clock_frozen() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK)) |
#define | otg_configure_timeout(timer, timeout) |
Configure time-out of specified OTG timer. More... | |
#define | otg_get_timeout(timer) |
Get configured time-out of specified OTG timer. More... | |
#define | otg_get_fsm_drd_state() (Rd_bitfield(UOTGHS->UOTGHS_FSM, UOTGHS_FSM_DRDSTATE_Msk)) |
Get the dual-role device state of the internal USB finite state machine of the UOTGHS controller. More... | |
#define | Is_otg_a_suspend() (4==otg_get_fsm_drd_state()) |
#define | Is_otg_a_wait_vrise() (1==otg_get_fsm_drd_state()) |
UOTGHS OTG hardware protocol | |
These macros manages the hardware OTG protocol | |
#define | otg_device_initiate_hnp() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Initiates a Host negotiation Protocol. More... | |
#define | otg_host_accept_hnp() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Accepts a Host negotiation Protocol. More... | |
#define | otg_host_reject_hnp() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Rejects a Host negotiation Protocol. More... | |
#define | otg_device_initiate_srp() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPREQ)) |
initiates a Session Request Protocol More... | |
#define | otg_select_vbus_srp_method() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPSEL)) |
Selects VBus as SRP method. More... | |
#define | Is_otg_vbus_srp_method_selected() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPSEL)) |
#define | otg_select_data_srp_method() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPSEL)) |
Selects data line as SRP method. More... | |
#define | Is_otg_data_srp_method_selected() (!Is_otg_vbus_srp_method_selected()) |
#define | Is_otg_hnp() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Tests if a HNP occurs. More... | |
#define | Is_otg_device_srp() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPREQ)) |
Tests if a SRP from device occurs. More... | |
#define | otg_enable_hnp_error_interrupt() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPERRE)) |
Enables HNP error interrupt. More... | |
#define | otg_disable_hnp_error_interrupt() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPERRE)) |
Disables HNP error interrupt. More... | |
#define | Is_otg_hnp_error_interrupt_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPERRE)) |
#define | otg_ack_hnp_error_interrupt() (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_HNPERRIC) |
ACKs HNP error interrupt. More... | |
#define | otg_raise_hnp_error_interrupt() (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_HNPERRIS) |
Raises HNP error interrupt. More... | |
#define | Is_otg_hnp_error_interrupt() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_HNPERRI)) |
Tests if a HNP error occurs. More... | |
#define | otg_enable_role_exchange_interrupt() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_ROLEEXE)) |
Enables role exchange interrupt. More... | |
#define | otg_disable_role_exchange_interrupt() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_ROLEEXE)) |
Disables role exchange interrupt. More... | |
#define | Is_otg_role_exchange_interrupt_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_ROLEEXE)) |
#define | otg_ack_role_exchange_interrupt() (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_ROLEEXIC) |
ACKs role exchange interrupt. More... | |
#define | otg_raise_role_exchange_interrupt() (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_ROLEEXIS) |
Raises role exchange interrupt. More... | |
#define | Is_otg_role_exchange_interrupt() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_ROLEEXI)) |
Tests if a role exchange occurs. More... | |
#define | otg_enable_srp_interrupt() (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPE)) |
Enables SRP interrupt. More... | |
#define | otg_disable_srp_interrupt() (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPE)) |
Disables SRP interrupt. More... | |
#define | Is_otg_srp_interrupt_enabled() (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPE)) |
#define | otg_ack_srp_interrupt() (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_SRPIC) |
ACKs SRP interrupt. More... | |
#define | otg_raise_srp_interrupt() (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_SRPIS) |
Raises SRP interrupt. More... | |
#define | Is_otg_srp_interrupt() (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_SRPI)) |
Tests if a SRP occurs. More... | |
Functions | |
void | otg_dual_disable (void) |
Uninitialize the dual role This function is implemented in uotghs_host.c file. More... | |
bool | otg_dual_enable (void) |
Initialize the dual role This function is implemented in uotghs_host.c file. More... | |
#define Is_otg_a_suspend | ( | ) | (4==otg_get_fsm_drd_state()) |
#define Is_otg_a_wait_vrise | ( | ) | (1==otg_get_fsm_drd_state()) |
#define Is_otg_clock_frozen | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK)) |
#define Is_otg_clock_usable | ( | ) | (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_CLKUSABLE)) |
Check Clock Usable For parts with HS feature, this one corresponding at UTMI clock.
Referenced by if(), udd_attach(), and udd_enable().
#define Is_otg_data_srp_method_selected | ( | ) | (!Is_otg_vbus_srp_method_selected()) |
#define Is_otg_device_srp | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPREQ)) |
Tests if a SRP from device occurs.
#define Is_otg_enabled | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_USBE)) |
#define Is_otg_hnp | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Tests if a HNP occurs.
#define Is_otg_hnp_error_interrupt | ( | ) | (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_HNPERRI)) |
Tests if a HNP error occurs.
#define Is_otg_hnp_error_interrupt_enabled | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPERRE)) |
#define Is_otg_pad_enabled | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_OTGPADE)) |
#define Is_otg_role_exchange_interrupt | ( | ) | (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_ROLEEXI)) |
Tests if a role exchange occurs.
#define Is_otg_role_exchange_interrupt_enabled | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_ROLEEXE)) |
#define Is_otg_srp_interrupt | ( | ) | (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_SRPI)) |
Tests if a SRP occurs.
#define Is_otg_srp_interrupt_enabled | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPE)) |
#define Is_otg_vbus_high | ( | ) | (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_VBUS)) |
Referenced by if(), and udd_enable().
#define Is_otg_vbus_interrupt_enabled | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_VBUSTE)) |
#define Is_otg_vbus_low | ( | ) | (!Is_otg_vbus_high()) |
#define Is_otg_vbus_srp_method_selected | ( | ) | (Tst_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPSEL)) |
#define Is_otg_vbus_transition | ( | ) | (Tst_bits(UOTGHS->UOTGHS_SR, UOTGHS_SR_VBUSTI)) |
#define otg_ack_hnp_error_interrupt | ( | ) | (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_HNPERRIC) |
ACKs HNP error interrupt.
#define otg_ack_role_exchange_interrupt | ( | ) | (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_ROLEEXIC) |
ACKs role exchange interrupt.
#define otg_ack_srp_interrupt | ( | ) | (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_SRPIC) |
ACKs SRP interrupt.
#define otg_ack_vbus_transition | ( | ) | (UOTGHS->UOTGHS_SCR = UOTGHS_SCR_VBUSTIC) |
Referenced by if(), and udd_enable().
#define otg_configure_timeout | ( | timer, | |
timeout | |||
) |
Configure time-out of specified OTG timer.
#define otg_device_initiate_hnp | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Initiates a Host negotiation Protocol.
#define otg_device_initiate_srp | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPREQ)) |
initiates a Session Request Protocol
#define otg_disable | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_USBE)) |
Disable USB macro.
Referenced by udd_disable().
#define otg_disable_hnp_error_interrupt | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPERRE)) |
Disables HNP error interrupt.
#define otg_disable_pad | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_OTGPADE)) |
Disable OTG pad.
Referenced by udd_disable().
#define otg_disable_role_exchange_interrupt | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_ROLEEXE)) |
Disables role exchange interrupt.
#define otg_disable_srp_interrupt | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPE)) |
Disables SRP interrupt.
#define otg_disable_vbus_interrupt | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_VBUSTE)) |
#define otg_enable | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_USBE)) |
Enable USB macro.
Referenced by udd_enable().
#define otg_enable_hnp_error_interrupt | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPERRE)) |
Enables HNP error interrupt.
#define otg_enable_pad | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_OTGPADE)) |
Enable OTG pad.
Referenced by udd_enable().
#define otg_enable_role_exchange_interrupt | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_ROLEEXE)) |
Enables role exchange interrupt.
#define otg_enable_srp_interrupt | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPE)) |
Enables SRP interrupt.
#define otg_enable_vbus_interrupt | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_VBUSTE)) |
Referenced by udd_enable().
#define otg_freeze_clock | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK)) |
Stop (freeze) internal USB clock.
Referenced by if(), udd_attach(), udd_detach(), udd_disable(), and udd_enable().
#define otg_get_fsm_drd_state | ( | ) | (Rd_bitfield(UOTGHS->UOTGHS_FSM, UOTGHS_FSM_DRDSTATE_Msk)) |
Get the dual-role device state of the internal USB finite state machine of the UOTGHS controller.
#define otg_get_timeout | ( | timer | ) |
Get configured time-out of specified OTG timer.
#define otg_host_accept_hnp | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Accepts a Host negotiation Protocol.
#define otg_host_reject_hnp | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_HNPREQ)) |
Rejects a Host negotiation Protocol.
#define otg_raise_hnp_error_interrupt | ( | ) | (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_HNPERRIS) |
Raises HNP error interrupt.
#define otg_raise_role_exchange_interrupt | ( | ) | (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_ROLEEXIS) |
Raises role exchange interrupt.
#define otg_raise_srp_interrupt | ( | ) | (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_SRPIS) |
Raises SRP interrupt.
#define otg_raise_vbus_transition | ( | ) | (UOTGHS->UOTGHS_SFR = UOTGHS_SFR_VBUSTIS) |
Referenced by udd_enable().
#define otg_reset | ( | ) |
Reset USB macro.
#define otg_select_data_srp_method | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPSEL)) |
Selects data line as SRP method.
#define otg_select_vbus_srp_method | ( | ) | (Set_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_SRPSEL)) |
Selects VBus as SRP method.
#define otg_unfreeze_clock | ( | ) | (Clr_bits(UOTGHS->UOTGHS_CTRL, UOTGHS_CTRL_FRZCLK)) |
Referenced by if(), udd_attach(), udd_detach(), udd_disable(), udd_enable(), and udd_send_remotewakeup().