CEC Introduction

Quoting from the Wikipedia page of the CEC:

Consumer Electronics Control (CEC) is a feature of HDMI designed to allow users to command and control devices connected through HDMI by using only one remote control. For example by using the remote control of a television set to control a set-top box and or DVD player. Up to 15 devices can be controlled. CEC also allows for individual CEC-enabled devices to command and control each other without user intervention.

UDOO X86’s HDMI 1.4b supports CEC so we decided to develop the driver for the CEC of our board by adopting the new Linux standard CEC Framework.

CEC Framework

The Linux Kernel includes, since the 4.8 version, a standard HDMI-CEC framework to provide a unified kernel interface for use with HDMI-CEC hardware.

Quoting from the official CEC framework documentation:

The framework also gives the option to decide what to do in the kernel driver and what should be handled by userspace applications. In addition it integrates the remote control passthrough feature into the kernel’s remote control framework. This new HDMI-CEC framework just acts like an API that allows manufacturers to easily write 'device drivers' that can talk to all different type of CEC hardware. The framework exposes CEC as a remote control input device allowing to any generic hardware to have standard syscalls to user-space application.

With the new Linux kernels, most of the future hardware as well as the current ones, will be supported directly. This CEC Framework sets itself as a standard that will be adopted by all manufacturers to support CEC in their hardware and should be adopted by media applications soon.

Here you can find details on the framework by the developer Hans Verkuil from Cisco.

State of Art - libCEC

libCEC is a well established user-space library. Many graphical media applications, like Kodi, use the libCEC platform in its own code to interact with CEC protocol.

Now that a standard HDMI-CEC Framework is integrated into the Linux Kernel, future hardware will probably adopt it. LibCEC still has a pending Pull Request at the time of writing (2019/07/12) in order to add support for the Linux Framework.

LibreELEC, a Linux distro for Kodi, has an option to add the patch and enabling the support, but it's not available in the official images. In the section LibreELEC with CEC support is possible to download a custom version with the CEC Support enabled.

libCEC issue on github about adding the CEC Framework support - GitHub link.

Kodi thread about using the CEC Framework alternatively to libCEC - KODI Forum thread.

Compile and mount the seco-cec driver for UDOO X86

Use

Heads up! Make sure you have installed an updated FW version (>= 1.04) on your UDOO X86 (check this in BIOS Main Page).

In order to use the driver, there are several methods:

  • Install Linux Kernel version > 5.0 with CONFIG_VIDEO_SECO_CEC and, optionally, CONFIG_VIDEO_SECO_RC (for IR) enabled
  • Use DKMS (Dynamic Kernel Module System)
  • Compile and mount the module manually

Heads up! If you are compiling, make sure you have Linux kernel headers >= 4.19 and CEC_NOTIFIER enabled (if you want to compile with headers >= 4.14 you need to use version 0.1 ).

DKMS

DKMS is an automatic system for mounting and managing Linux external modules. It is really useful in case of a kernel update or for automounting the module at boot.

# install dependencies (make, git, ecc..)
sudo apt install git build-essential linux-headers-`uname -r` dkms

# clone repo
git clone https://github.com/ektor5/secocec

# go to dir
cd secocec

# create dkms directory
sudo mkdir '/usr/src/secocec-1.0'

# copy files
sudo cp seco-cec.? dkms.conf Makefile '/usr/src/secocec-1.0'

# install module
sudo dkms install secocec/1.0 -k `uname -r`

Now at reboot the module will be mounted automatically.

Compile

Install dependencies (make, git, ecc..)

sudo apt install git build-essential linux-headers-`uname -r`

Download the source code from git

git clone https://github.com/ektor5/secocec.git

Enter into the dir just downloaded:

cd secocec

compile the driver:

make

The module should appear as file called seco-cec.ko.

Mount

This module depends on the Linux CEC Framework Module, and it needs to be loaded first.

modprobe cec

Note: this module conflicts with the official SMBus driver i2c-i801 and therefore it needs to be blacklisted. On Ubuntu should be already blacklisted, if you're using

echo "blacklist i2c-i801" > /etc/modprobe.d/i2c-i801.conf

Load the module:

insmod seco-cec.ko

Done, the module is now loaded and working!

How to use the driver with file system applications

The CEC Framework expose all the CEC functionalities of the CEC protocol through a file system device /dev/cec0 so the applications can access directly this file. Since the CEC Framework is quite new there are still few applications that exploits all functions provided by the Framework.

To test the device from userspace (/dev/cec0), there are some programs ready to use in v4l-utils tools package (available to install via apt):

  • cec-ctl: An application to control cec devices
  • cec-compliance: An application to verify remote CEC devices
  • cec-follower: An application to emulate CEC followers

You can check the official man pages for info.

Install v4l-utils

apt install v4l-utils

Following you can find some examples.

Register the CEC device (UDOO X86) in the CEC network using the physical and logical address:

cec-ctl --phys-addr=2.0.0.0 \
        --playback

Power on tv

cec-ctl --active-source=phys-addr=2.0.0.0 --image-view-on -t0

Power off tv

cec-ctl --standby -t0

Enable TV remote (it depends on manufacturers protocol) E.g. SimpLink by LG.

cec-ctl --phys-addr=2.0.0.0 \
        --playback \
        --custom-command=cmd=0x89,payload=0x02:0x05 \
        --deck-status=deck-info=0x01 \
        --menu-status=menu-state=0x00 \
        --custom-command=cmd=0x89,payload=0x05:0x01 \
        --report-power-status=pwr-state=0 -t0

With this command the TV remote keys are interpreted by the OS as a standard keyboard and you can use it to interact with the OS applications like Kodi for examples.

Edit keymaps

Sometimes, not all the remote keys are set like we want it to be.
E.g: the OK button is not understood as Enter by the X server input module (Xinput), so it is necessary to remap it.

To edit the keymap do the following:

Install ir-keytable package:

apt install ir-keytable

Get the current keytable:

ir-keytable -r > seco-cec-keytable.conf

Edit the file with a text editor (e.g. vim):

vim seco-cec-keytable.conf

Rewrite it to the driver

ir-keytable -w seco-cec-keytable.conf

Done!

This page was last updated on Monday, March 21, 2022 at 5:22 AM.