Skip to content

Instantly share code, notes, and snippets.

@sm-Fifteen
Last active April 30, 2023 20:37
Show Gist options
  • Save sm-Fifteen/77db924460cb9798be9d367d9ccdfbaa to your computer and use it in GitHub Desktop.
Save sm-Fifteen/77db924460cb9798be9d367d9ccdfbaa to your computer and use it in GitHub Desktop.
Pulse Eight CEC adapter auto-configure inputattach and cec-ctl
# The CEC adapter only monitors pin 13, and physical address allocation occurs over DDC/EDID (pin 16)
# Besides, the CEC adapter can't tell if its HDMI source even is the same device as its USB host.
# So physical address needs to be decoded from the EDID, and which output that corresponds to has to be specificed manually.
SUBSYSTEM=="cec" ACTION=="add" ENV{__DEFAULT_CEC_OUTPUT}!="" TAG+="systemd" ENV{SYSTEMD_WANTS}="cec-configure@%E{__DEFAULT_CEC_OUTPUT}.service"
[Unit]
Description=Configure CEC adapter assuming it runs on output %i
AssertPathExists=/sys/class/drm/%i/edid
[Service]
Type=exec
# edid-poll checks every 100 ms for hotplug detection, which looks a bit excessive, so I won't enable it just yet...
# https://git.linuxtv.org/v4l-utils.git/tree/utils/cec-ctl/cec-ctl.cpp?id=0a195181d771090f3c99d4a6ddb8151352509061#n1977
# A PC is considered to be a "Generic Source device" which should register as a single "Playback device", per the HDMI 2.0 spec.
ExecStart=/usr/bin/cec-ctl --osd-name %H --playback --phys-addr-from-edid=/sys/class/drm/%i/edid -S -M --ignore all,poll
[Install]
WantedBy=multi-user.target
# Try enabling with a name like `pulse8-cec-attach@card1-HDMI-A-1`
[Unit]
Description=Configure USB Pulse-Eight serial device assuming it controls %i
After=sleep.target
ConditionPathExists=/dev/serial/by-id/usb-Pulse-Eight_CEC_Adapter_v12-if00
[Service]
Type=forking
# inputattach on fedora is built without Systemd daemon support, so SysD will have to guess the PID.
# https://src.fedoraproject.org/rpms/linuxconsoletools/blob/f37/f/linuxconsoletools.spec
# https://sourceforge.net/p/linuxconsole/code/ci/master/tree/utils/inputattach.c#l1233
ExecStart=/usr/bin/inputattach --daemon --pulse8-cec /dev/serial/by-id/usb-Pulse-Eight_CEC_Adapter_v12-if00
# inputattach stops on its own when the system goes in suspend mode
Restart=on-success
# Set a udev global property so we can use it in our udev rule
ExecStartPre=/usr/bin/udevadm control --property=__DEFAULT_CEC_OUTPUT="%i"
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment