Search by Tags

Activate S/PDIF Output on Colibri T20

 
Applicable for

Tags

Article updated at 28 Oct 2017

The Colibri T20 has a built-in S/PDIF engine that can be used to output digital audio data instead of the analog audio out.

The following steps are required to activate the S/PDIF output:

Activate the Tegra's S/PDIF Unit

The S/PDIF unit is automatically activated if you pull the HOTPLUG_DET pin high. This signal is used to indicate that you connected a HDMI screen.

If you don't have a HDMI screen connected, you can activate the S/PDIF unit by the following code.

This can be done using the following code

// MixerSetOutputDevice.cpp : Defines the entry point for the console application.
 
#include <windows.h>
#include <winioctl.h>
 
//=============================================================================
// definitions for the MIX_MESSAGE IoControl
#define IOCTL_MIX_MESSAGE \
    CTL_CODE((ULONG)0x8000, 0x0040, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
 
// Definitions for the Nvidia SET_OUTPUT_DEVICE feature
#define MXDM_SET_OUTPUT_DEVICE (112)
#define WaveOutDevice_HDMI (4)
 
typedef struct {
    UINT uDeviceId;
    UINT uMsg;          // set to MXDM_SET_OUTPUT_DEVICE
    DWORD dwUser;
    DWORD dwParam1;     // set to WaveOutDevice_HDMI
    DWORD dwParam2;
} MMDRV_MESSAGE_PARAMS;
 
//=============================================================================
 
int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE                  hWAV        = INVALID_HANDLE_VALUE; 
    DWORD                   ret; 
    MMDRV_MESSAGE_PARAMS    mixerParams = {0, MXDM_SET_OUTPUT_DEVICE, 0, WaveOutDevice_HDMI, 0};
    DWORD                   outBuf;
    DWORD                   outSize;
 
    hWAV = CreateFile(L"WAV1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
    ret = DeviceIoControl(hWAV, IOCTL_MIX_MESSAGE, &mixerParams, sizeof(mixerParams), &outBuf , sizeof(outBuf), &outSize, NULL );
    if (!ret)
        printf("error in DeviceIoControl: %d, LastError=%d\r\n", ret, GetLastError());
 
    CloseHandle(hWAV);
	return 0;
}

Configure the SPDIF_OUT Pin

The SPDIF_OUT function is available on the following pins of the Colibri T20:

GPIO AltFn# SODIMM Pin
C3 1 19
D4 0 92
K5 0 137

Choose any of these pins as the SPDIF_OUT pin.

Be aware that the SPDIF_OUT feature is not compatible to the other Colibri modules. The pins mentioned in the table above are all used for other features in the compatible Colibri default configuration.

To change the alternate function to SPDIF_OUT temporarily, the simplest method is to use our GpioConfig Tool.

To change it each time your system starts, we recommend to put the respective code into your application, e.g. use the SetPinAltFn() API of our GpioLib.