Без опису

k4be 3047f8ab07 Radio front panel keys: TCA9539 overlay and board DT example, moved out of s1d13700-tca 2 тижнів тому
dts 3047f8ab07 Radio front panel keys: TCA9539 overlay and board DT example, moved out of s1d13700-tca 2 тижнів тому
.gitignore 3047f8ab07 Radio front panel keys: TCA9539 overlay and board DT example, moved out of s1d13700-tca 2 тижнів тому
LICENSE 3047f8ab07 Radio front panel keys: TCA9539 overlay and board DT example, moved out of s1d13700-tca 2 тижнів тому
Makefile 3047f8ab07 Radio front panel keys: TCA9539 overlay and board DT example, moved out of s1d13700-tca 2 тижнів тому
README.md 3047f8ab07 Radio front panel keys: TCA9539 overlay and board DT example, moved out of s1d13700-tca 2 тижнів тому

README.md

radio-keyboard-tca: radio front panel keys behind a TCA9539

The 13 keys of the internet radio's front panel, read through a TI TCA9539 16-bit I²C GPIO expander (U2). No driver of its own: on Linux the stock gpio-pca953x and gpio-keys drivers turn it into an evdev input device named radio-keys, described here in device tree.

The LCD on the same bus (U1, 0x74) is in the sibling repository s1d13700-tca; the application that reads the keys is radio-ui, which can also poll U2 itself over i2c-dev (radio/keypad.py) when the kernel does not handle it.

Path What
dts/radio-keys.dts Overlay: U2 and the radio-keys gpio-keys device
dts/examples/orangepi-zero-i2c1-keys.dtsi The same for a board DT, as used on the Orange Pi Zero

Building

make dtbo                       # build/*.dtbo from dts/*.dts

The kernel needs CONFIG_GPIO_PCA953X (with CONFIG_GPIO_PCA953X_IRQ for gpio-keys), CONFIG_KEYBOARD_GPIO or CONFIG_KEYBOARD_GPIO_POLLED, and CONFIG_INPUT_EVDEV.

Wiring

U2, TCA9539 at 0x76 (A1=H, A0=L). Keys are active high: each pin has an external pull-down (the TCA9539 has no internal ones) and its key connects it to the supply. INT (open drain, active low) goes to a host GPIO; on the Orange Pi Zero that is PA6/PWM1 (pin 7 of the 26-pin header). It is not connected on the USB test board, so there the keys have to be polled (gpio-keys-polled, or radio-ui i2c).

Pin Key Pin Key
P0.0-2 unused (pull-down) P1.0 Esc
P0.3 Next P1.1 OK
P0.4 Left P1.2 Menu
P0.5 Down P1.3 List
P0.6 Up P1.4 Stop
P0.7 Right P1.5 Pause
P1.6 Play
P1.7 Prev

Key codes: KEY_NEXTSONG, KEY_LEFT, KEY_DOWN, KEY_UP, KEY_RIGHT, KEY_ESC, KEY_OK, KEY_MENU, KEY_LIST, KEY_STOPCD, KEY_PAUSECD, KEY_PLAYCD, KEY_PREVIOUSSONG. Each key is debounced for 20 ms and autorepeats.

Device tree

dts/radio-keys.dts is an overlay written with plain numbers instead of #include, so it also works with armbian-add-overlay. It targets i2c0 and puts U2's INT on PA6; check both against the board. Without INT, change the compatible to gpio-keys-polled with poll-interval = <20> and drop the interrupt properties. When radio-ui polls U2 over i2c-dev, do not load this overlay: only one user of 0x76 at a time.

dts/examples/orangepi-zero-i2c1-keys.dtsi is the version in use on the Orange Pi Zero, for inclusion in a board DTS after the bus setup (e.g. s1d13700-tca's dts/examples/orangepi-zero-i2c1.dtsi): U2 with INT on PA6 and its SoC pull-up, and the radio-keys input device.

The key table exists in several places and must stay the same:

  • dts/radio-keys.dts and dts/examples/orangepi-zero-i2c1-keys.dtsi here,
  • the OPi0 board DTS, which build-kernel.sh (OPi0) compares with the compiled overlay, stopping if label, pin, flags or key code differ,
  • radio-ui's radio/keypad.py (pins) and radio/platform.py (key codes), which its tests check against dts/radio-keys.dts.

Permissions

The evdev node is root:input 0660; the user running radio-ui needs to be in the input group.

Not settled

  • Autorepeat timing on held keys (gpio-keys default: 250 ms, then 33 ms).

License

The device tree files are GPL-2.0+ OR MIT (see the SPDX headers); LICENSE has the GPL-2.0 text.