USB-C Sink 4 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
- Author : Nenad Filipovic
- Date : Mar 2023.
- Type : I2C type
This example demonstrates the use of a USB-C Sink 4 Click board by setting DC power requests and control for Type-C connector-equipped devices (TCD).
- MikroSDK.Board
- MikroSDK.Log
- Click.USBCSink4
usbcsink4_cfg_setupConfig Object Initialization function.
void usbcsink4_cfg_setup ( usbcsink4_cfg_t *cfg );usbcsink4_initInitialization function.
err_t usbcsink4_init ( usbcsink4_t *ctx, usbcsink4_cfg_t *cfg );usbcsink4_default_cfgClick Default Configuration function.
err_t usbcsink4_default_cfg ( usbcsink4_t *ctx );usbcsink4_get_type_c_statusThis function reads the reports of the status of the Type-C port by using the I2C serial interface.
err_t usbcsink4_get_type_c_status ( usbcsink4_t *ctx, usbcsink4_type_c_status_t *type_c_status );usbcsink4_get_bus_voltageThis function reads the live voltage on the VBUS supply for the specified port using the I2C serial interface.
err_t usbcsink4_get_bus_voltage ( usbcsink4_t *ctx, float *vbus_v );usbcsink4_get_event_statusThis function reads the reports of the event status to know what has happened on the Type-C/PD port using the I2C serial interface.
err_t usbcsink4_get_event_status ( usbcsink4_t *ctx, usbcsink4_event_status_t *event_status );The initialization of the I2C module and log UART. After driver initialization, the app sets the default configuration.
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
usbcsink4_cfg_t usbcsink4_cfg; /**< Click config object. */
/**
* Logger initialization.
* Default baud rate: 115200
* Default log level: LOG_LEVEL_DEBUG
* @note If USB_UART_RX and USB_UART_TX
* are defined as HAL_PIN_NC, you will
* need to define them manually for log to work.
* See @b LOG_MAP_USB_UART macro definition for detailed explanation.
*/
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
usbcsink4_cfg_setup( &usbcsink4_cfg );
USBCSINK4_MAP_MIKROBUS( usbcsink4_cfg, MIKROBUS_POSITION_USBCSINK4 );
if ( I2C_MASTER_ERROR == usbcsink4_init( &usbcsink4, &usbcsink4_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
if ( USBCSINK4_ERROR == usbcsink4_default_cfg ( &usbcsink4 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
log_printf( &logger, " ------------------------\r\n" );
Delay_ms ( 100 );
}The demo app displays the reports of the Type-C port, active legacy charging mode status, and live voltage measurements on the VBUS supply for the specified port.
void application_task ( void )
{
usbcsink4_display_type_c_status( );
Delay_ms ( 100 );
usbcsink4_display_chrg_mode( );
Delay_ms ( 100 );
usbcsink4_display_bus_voltage( );
Delay_ms ( 1000 );
}This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.