RA Flexible Software Package Documentation  Release v5.9.0

 
USB-TYPEC (r_usb_typec)

Functions

fsp_err_t R_USB_TYPEC_Open (usb_typec_ctrl_t *const p_ctrl, usb_typec_cfg_t const *const p_cfg)
 Initialize USB Type-C module and USB Type-C driver. Implements usb_typec_api_t::open. More...
 
fsp_err_t R_USB_TYPEC_Close (usb_typec_ctrl_t *const p_ctrl)
 Uninitialize USB Type-C module and disable interrupts. Implements usb_typec_api_t::close. More...
 
fsp_err_t R_USB_TYPEC_InfoGet (usb_typec_ctrl_t *const p_ctrl, usb_typec_info_t *p_info)
 Get USB Type-C connect Information. Implements usb_typec_api_t::infoGet. More...
 
fsp_err_t R_USB_TYPEC_LowPowerModeSet (usb_typec_ctrl_t *const p_ctrl, usb_typec_ccs_status_t status)
 Set IRQ Mode for USB Type-C module by Low Power Mode. Implements usb_typec_api_t::lowPowerModeSet. More...
 

Detailed Description

Driver for the USB_TYPEC peripheral on RA MCUs. This module implements the USB TYPEC Interface.

Overview

The r_usb_typec module is used in combination with r_usb_basic and other device class for USB communication and with the Type C module alone for Type-C charging.

Features

The r_usb_typec module has the following key features:

Usage Notes

Basic Functions

The main functions of thie module are the following:

Note

If the user is using an MCU that supports the USB Type-C module and all of the following conditions are satisfied, please add code to control the port connected to External Rd immediately after calling the R_USB_TYPEC_Open function. (Because it is necessary to control External Rd after Internal Rd is turned ON.)

  1. The USB operating mode is Device mode.
  2. The power mode is BusPower. (External Rd is mounted on board)
R_USB_TYPEC_Open(&g_usbcc0_ctrl, &g_usbcc0_cfg);

Depending on the user board, the user may need code to debaunce the USB_VBUS pin.

Examples

USB Type-C Example

The following is example code for USB Type-C.

/******************************************************************************
* Function Name : usb_typec_apl_callback
* Description : Callback function for Application program
* Arguments : usb_typec_callback_args_t * p_typec_args : Callback function parameter data.
* Return value : none
******************************************************************************/
void usb_typec_apl_callback (usb_typec_callback_args_t * p_typec_args)
{
g_typec_args = *p_typec_args;
/* USB Type-C Callback Flag Set */
g_typec_callback_flg = 1;
} /* End of function usb_apl_callback */
/******************************************************************************
* Function Name : usb_typec_example
* Description : USB Type-C application main process
* Arguments : none
* Return value : none
******************************************************************************/
void usb_typec_example (void)
{
usb_typec_info_t typec_info;
#if TYPEC_APL_SUPPORT_SOFTWARE_STANDBY
g_lpm_on_lpm.open(&g_lpm_ctrl, &g_lpm_cfg);
#endif /* TYPEC_APL_SUPPORT_SOFTWARE_STANDBY */
g_typec_on_typec.open(&g_usbcc0_ctrl, &g_usbcc0_cfg);
/* EK-RA2L2 ExRd1_En(P109) = L */
R_IOPORT_PinCfg(&g_ioport_ctrl,
/* EK-RA2L2 ExRd2_En(P110) = L */
R_IOPORT_PinCfg(&g_ioport_ctrl,
/* Waiting for USB Type-C event */
while (1)
{
/* USB Type-C Callback Flag Check */
if (1 == g_typec_callback_flg)
{
switch (g_typec_args.status)
{
/* Connection Status Change */
g_typec_on_typec.infoGet(&g_usbcc0_ctrl, &typec_info);
switch (typec_info.connection_status)
{
/* None */
break;
/* In the case of Power1.5.SNK or Power3.0.SNK, the PowerDefault event is notified first. */
/* None */
break;
/* None */
break;
/* None */
break;
default:
/* None */
break;
}
break;
#if TYPEC_APL_SUPPORT_SOFTWARE_STANDBY
/* VBUS Status Change */
/* Note: Depending on the board, it may be necessary to use software to prevent VBUS chattering.
* */
if (USB_TYPEC_VBUS_STATUS_OFF == g_typec_args.vbus_status)
{
/* USBCC CCS enable */
g_typec_on_typec.lowPowerModeSet (&g_usbcc0_ctrl, USB_TYPEC_CCS_STATUS_ON);
/* Software Standby */
g_lpm_on_lpm.lowPowerModeEnter(&g_lpm_ctrl);
/* USBCC CCI enable */
g_typec_on_typec.lowPowerModeSet (&g_usbcc0_ctrl, USB_TYPEC_CCS_STATUS_OFF);
}
break;
#endif /* TYPEC_APL_SUPPORT_SOFTWARE_STANDBY */
default:
/* None */
break;
}
/* USB Type-C Callback Flag Clear */
g_typec_callback_flg = 0;
}
}
} /* End of function usb_typec_example() */

Data Structures

struct  usb_typec_instance_ctrl_t
 

Data Structure Documentation

◆ usb_typec_instance_ctrl_t

struct usb_typec_instance_ctrl_t

USB TYPE-C control block. DO NOT INITIALIZE. Initialization occurs when usb_typec_api_t::open is called.

Data Fields

uint32_t open
 Used to determine if the channel is configured.
 
usb_typec_cfg_tp_cfg
 Pointer to initial configurations.
 
uint32_t module_number
 USB module number (USB_IP0/USB_IP1)
 
IRQn_Type irq_typec_cci
 USBCC_CCI interrupt number storage variable.
 
IRQn_Type irq_typec_ccs
 USBCC_CCS interrupt number storage variable.
 
uint32_t ipl_typec_cci
 Variable to store the interrupt priority of USBCC_CCI.
 
uint32_t ipl_typec_ccs
 Variable to store the interrupt priority of USBCC_CCS.
 

Function Documentation

◆ R_USB_TYPEC_Open()

fsp_err_t R_USB_TYPEC_Open ( usb_typec_ctrl_t *const  p_ctrl,
usb_typec_cfg_t const *const  p_cfg 
)

Initialize USB Type-C module and USB Type-C driver. Implements usb_typec_api_t::open.

Return values
FSP_SUCCESSChannel opened successfully.
FSP_ERR_NOT_OPENUSB TYPEC module is not open.
FSP_ERR_ALREADY_OPENControl block has already been opened or channel is being used by another instance. Call close() then open() to reconfigure.

◆ R_USB_TYPEC_Close()

fsp_err_t R_USB_TYPEC_Close ( usb_typec_ctrl_t *const  p_ctrl)

Uninitialize USB Type-C module and disable interrupts. Implements usb_typec_api_t::close.

Return values
FSP_SUCCESSChannel successfully closed.
FSP_ERR_NOT_OPENUSB TYPEC module is not open.

◆ R_USB_TYPEC_InfoGet()

fsp_err_t R_USB_TYPEC_InfoGet ( usb_typec_ctrl_t *const  p_ctrl,
usb_typec_info_t *  p_info 
)

Get USB Type-C connect Information. Implements usb_typec_api_t::infoGet.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_NOT_OPENUSB TYPEC module is not open.

◆ R_USB_TYPEC_LowPowerModeSet()

fsp_err_t R_USB_TYPEC_LowPowerModeSet ( usb_typec_ctrl_t *const  p_ctrl,
usb_typec_ccs_status_t  status 
)

Set IRQ Mode for USB Type-C module by Low Power Mode. Implements usb_typec_api_t::lowPowerModeSet.

Return values
FSP_SUCCESSSuccessful completion.
FSP_ERR_NOT_OPENUSB TYPEC module is not open.
FSP_ERR_USB_PARAMETERParameter error.