Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
USBC OTG Driver

USBC low-level driver for OTG features.

Macros

#define Is_otg_clock_frozen()   USBC_TST_BITS(USBCON,FRZCLK)
 
#define Is_otg_clock_usable()   USBC_TST_BITS(USBSTA,CLKUSABLE)
 Check USB interface clock usable. More...
 
#define Is_otg_suspend()   USBC_TST_BITS(USBSTA,SUSPEND)
 Check transceiver state. More...
 
#define Is_otg_transceiver_off()   (Is_otg_suspend())
 
#define Is_otg_transceiver_on()   (!Is_otg_suspend())
 
#define otg_freeze_clock()   USBC_SET_BITS(USBCON,FRZCLK)
 
#define otg_get_fsm_drd_state()   USBC_RD_BITFIELD(USBFSM,DRDSTATE)
 Get the dual-role device state of the internal USB finite state machine. More...
 
#define otg_register_desc_tab(addr)   (Wr_bitfield(USBC->USBC_UDESC, USBC_UDESC_UDESCA_Msk, addr))
 
#define otg_unfreeze_clock()   USBC_CLR_BITS(USBCON,FRZCLK)
 

Functions

void otg_dual_disable (void)
 Uninitialize the dual role This function is implemented in usbc_host.c file. More...
 
bool otg_dual_enable (void)
 Initialize the dual role This function is implemented in usbc_host.c file. More...
 

USBC IP properties

These macros give access to IP properties

#define otg_get_ip_name()   (((uint64_t)USBC->USBC_UNAME1<<32)|(uint64_t)USBC->USBC_UNAME2)
 Get IP name part 1 or 2. More...
 
#define otg_data_memory_barrier()   do { barrier(); } while (0)
 
#define otg_get_ip_version()   USBC_RD_BITFIELD(UVERS,VERSION)
 Get IP version. More...
 
#define otg_get_max_nbr_endpoints()   USBC_RD_BITFIELD(UFEATURES, EPTNBRMAX)
 Get maximal number of pipes/endpoints. More...
 
#define otg_get_max_nbr_pipes()   USBC_RD_BITFIELD(UFEATURES, EPTNBRMAX)
 

USBC 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 ID pin can be managed through GPIO or EIC pin. This feature is optional, and it is enabled if USB_ID_PIN or USB_ID_EIC is defined in board.h and CONF_BOARD_USB_ID_DETECT defined in conf_board.h.

#define OTG_ID_DETECT   (defined(CONF_BOARD_USB_ID_DETECT))
 
#define OTG_ID_IO   (defined(USB_ID_PIN) && OTG_ID_DETECT)
 
#define OTG_ID_EIC   (defined(USB_ID_EIC) && OTG_ID_DETECT)
 
#define pad_id_init()   eic_pad_init(USB_ID_EIC_LINE, otg_id_handler, USB_ID_EIC_IRQn, USB_ID_EIC, UHD_USB_INT_LEVEL);
 
#define pad_id_interrupt_disable()   eic_line_disable_interrupt(EIC, USB_ID_EIC_LINE)
 
#define pad_ack_id_interrupt()
 
#define Is_pad_id_device()   ioport_get_pin_level(USB_ID_EIC)
 

USBC Vbus management

The VBus line can be monitored through a GPIO pin and a basic resitor voltage divider.

This feature is optional, and it is enabled if USB_VBUS_PIN or USB_VBUS_EIC is defined in board.h and CONF_BOARD_USB_VBUS_DETECT defined in conf_board.h.

#define OTG_VBUS_DETECT   (defined(CONF_BOARD_USB_VBUS_DETECT))
 
#define OTG_VBUS_IO   (defined(USB_VBUS_PIN) && OTG_VBUS_DETECT)
 
#define OTG_VBUS_EIC   (defined(USB_VBUS_EIC) && OTG_VBUS_DETECT)
 
#define pad_vbus_init(level)   eic_pad_init(USB_VBUS_EIC_LINE, uhd_vbus_handler, USB_VBUS_EIC_IRQn, USB_VBUS_EIC, level);
 
#define pad_vbus_interrupt_disable()   eic_line_disable_interrupt(EIC, USB_VBUS_EIC_LINE)
 
#define pad_ack_vbus_interrupt()
 
#define Is_pad_vbus_high()   ioport_get_pin_level(USB_VBUS_EIC)
 
#define uhd_vbus_is_on()   USBC_REG_SET(USBSTA,VBUSRQ)
 Notify USBC that the VBUS on the usb line is powered. More...
 
#define uhd_vbus_is_off()   USBC_REG_CLR(USBSTA,VBUSRQ)
 Notify USBC that the VBUS on the usb line is not powered. More...
 

USBC OTG main management

These macros allows to enable/disable pad and USBC hardware

#define otg_enable()   USBC_SET_BITS(USBCON,USBE)
 
#define otg_disable()   USBC_CLR_BITS(USBCON,USBE)
 

USBC mode management

The USBC mode device or host must be selected manualy by user

#define otg_enable_device_mode()   USBC_SET_BITS(USBCON,UIMOD)
 
#define Is_otg_device_mode_enabled()   USBC_TST_BITS(USBCON,UIMOD)
 
#define otg_enable_host_mode()   USBC_CLR_BITS(USBCON,UIMOD)
 
#define Is_otg_host_mode_enabled()   (!Is_otg_device_mode_enabled())
 

#define Is_otg_clock_frozen ( )    USBC_TST_BITS(USBCON,FRZCLK)

Referenced by udd_enable().

#define Is_otg_clock_usable ( )    USBC_TST_BITS(USBSTA,CLKUSABLE)

Check USB interface clock usable.

Referenced by udd_attach(), uhd_disable(), uhd_interrupt(), uhd_resume(), and uhd_vbus_handler().

#define Is_otg_device_mode_enabled ( )    USBC_TST_BITS(USBCON,UIMOD)

Referenced by ISR().

#define Is_otg_host_mode_enabled ( )    (!Is_otg_device_mode_enabled())

Referenced by udd_disable().

#define Is_otg_suspend ( )    USBC_TST_BITS(USBSTA,SUSPEND)

Check transceiver state.

#define Is_otg_transceiver_off ( )    (Is_otg_suspend())
#define Is_otg_transceiver_on ( )    (!Is_otg_suspend())
#define Is_pad_id_device ( )    ioport_get_pin_level(USB_ID_EIC)
#define Is_pad_vbus_high ( )    ioport_get_pin_level(USB_VBUS_EIC)
#define otg_data_memory_barrier ( )    do { barrier(); } while (0)

Referenced by ISR().

#define otg_disable ( )    USBC_CLR_BITS(USBCON,USBE)

Referenced by otg_dual_disable(), and udd_disable().

#define otg_enable ( )    USBC_SET_BITS(USBCON,USBE)

Referenced by udd_enable(), and uhd_enable().

#define otg_enable_device_mode ( )    USBC_SET_BITS(USBCON,UIMOD)
#define otg_enable_host_mode ( )    USBC_CLR_BITS(USBCON,UIMOD)
#define otg_freeze_clock ( )    USBC_SET_BITS(USBCON,FRZCLK)
#define otg_get_fsm_drd_state ( )    USBC_RD_BITFIELD(USBFSM,DRDSTATE)

Get the dual-role device state of the internal USB finite state machine.

Referenced by uhd_sof_interrupt().

#define otg_get_ip_name ( )    (((uint64_t)USBC->USBC_UNAME1<<32)|(uint64_t)USBC->USBC_UNAME2)

Get IP name part 1 or 2.

#define otg_get_ip_version ( )    USBC_RD_BITFIELD(UVERS,VERSION)

Get IP version.

#define otg_get_max_nbr_endpoints ( )    USBC_RD_BITFIELD(UFEATURES, EPTNBRMAX)

Get maximal number of pipes/endpoints.

#define otg_get_max_nbr_pipes ( )    USBC_RD_BITFIELD(UFEATURES, EPTNBRMAX)
#define OTG_ID_DETECT   (defined(CONF_BOARD_USB_ID_DETECT))
#define OTG_ID_EIC   (defined(USB_ID_EIC) && OTG_ID_DETECT)
#define OTG_ID_IO   (defined(USB_ID_PIN) && OTG_ID_DETECT)
#define otg_register_desc_tab (   addr)    (Wr_bitfield(USBC->USBC_UDESC, USBC_UDESC_UDESCA_Msk, addr))

Referenced by udd_enable(), and uhd_enable().

#define OTG_VBUS_DETECT   (defined(CONF_BOARD_USB_VBUS_DETECT))
#define OTG_VBUS_EIC   (defined(USB_VBUS_EIC) && OTG_VBUS_DETECT)
#define OTG_VBUS_IO   (defined(USB_VBUS_PIN) && OTG_VBUS_DETECT)
#define pad_ack_id_interrupt ( )
Value:
(eic_line_change_config(USB_ID_EIC_LINE, !ioport_get_pin_level(USB_ID_EIC)), \
eic_line_clear_interrupt(EIC, USB_ID_EIC_LINE))
static bool ioport_get_pin_level(ioport_pin_t pin)
Get current value of an IOPORT pin, which has been configured as an input.
Definition: ioport.h:301
static __always_inline void eic_line_change_config(uint8_t line, bool b_high)
Definition: usbc_otg.h:74
static void eic_line_clear_interrupt(Eic *eic, uint8_t line_number)
Clear the interrupt flag of specified pin.
Definition: eic.h:315

Referenced by otg_id_handler().

#define pad_ack_vbus_interrupt ( )
Value:
(eic_line_change_config(USB_VBUS_EIC_LINE, !ioport_get_pin_level(USB_VBUS_EIC)), \
eic_line_clear_interrupt(EIC, USB_VBUS_EIC_LINE))
static bool ioport_get_pin_level(ioport_pin_t pin)
Get current value of an IOPORT pin, which has been configured as an input.
Definition: ioport.h:301
static __always_inline void eic_line_change_config(uint8_t line, bool b_high)
Definition: usbc_otg.h:74
static void eic_line_clear_interrupt(Eic *eic, uint8_t line_number)
Clear the interrupt flag of specified pin.
Definition: eic.h:315

Referenced by uhd_vbus_handler().

#define pad_id_init ( )    eic_pad_init(USB_ID_EIC_LINE, otg_id_handler, USB_ID_EIC_IRQn, USB_ID_EIC, UHD_USB_INT_LEVEL);

Referenced by otg_dual_enable().

#define pad_id_interrupt_disable ( )    eic_line_disable_interrupt(EIC, USB_ID_EIC_LINE)

Referenced by otg_dual_disable().

#define pad_vbus_init (   level)    eic_pad_init(USB_VBUS_EIC_LINE, uhd_vbus_handler, USB_VBUS_EIC_IRQn, USB_VBUS_EIC, level);

Referenced by udd_enable(), and uhd_enable().

#define pad_vbus_interrupt_disable ( )    eic_line_disable_interrupt(EIC, USB_VBUS_EIC_LINE)

Referenced by uhd_disable().

#define uhd_vbus_is_off ( )    USBC_REG_CLR(USBSTA,VBUSRQ)

Notify USBC that the VBUS on the usb line is not powered.

Referenced by uhd_vbus_handler().

#define uhd_vbus_is_on ( )    USBC_REG_SET(USBSTA,VBUSRQ)

Notify USBC that the VBUS on the usb line is powered.

Referenced by uhd_enable(), and uhd_vbus_handler().

void otg_dual_disable ( void  )
bool otg_dual_enable ( void  )

Initialize the dual role This function is implemented in usbc_host.c file.

Returns
true if the ID pin management has been started, otherwise false.

References eic_enable(), Is_pad_id_device, otg_enable_device_mode, otg_enable_host_mode, otg_initialized, pad_id_init, sysclk_enable_usb(), udc_start(), UHC_MODE_CHANGE, uhc_start(), uhd_sleep_mode(), UHD_STATE_OFF, UHD_STATE_WAIT_ID_HOST, UHD_USB_INT_LEVEL, and usbc_async_wake_up_enable().

Referenced by udd_enable(), and uhd_enable().