I have a MAX7359 keypad which is already supported by linux as a keyboard. See: [https://github.com/torvalds/linux/blob/master/drivers/input/keyboard/max7359_keypad.c](max7359 driver source)
I have attached it to my AML-S905X-CC and enabled pin 3 and 5 of the header and followed instructions on this page: How to Enable I2C on AML-S905X-CC Le Potato
sudo ldto enable i2c-ao
I can confirm that the i2c communication is working via i2cget
command. For that test I used prebuilt raspbian flashed to a micro sdcard.
I believe the next steps to get the MAX7359 working as a keyboard are:
- Rebuild the kernel with CONFIG_KEYBOARD_MAX7359 enabled and flash it
- Write a device tree overlay in the libretech-wiring-tool project for the MAX7359, rebuild LWT, copy it to the device and run a command to enable the overlay
Hopefully this is an approach that will work, if there’s any easier way let me know.
I followed this post SPI and u-boot tweaks on Le Potato Buildroot and using buildroot I can produce an sdcard.img which I can flash to an sdcard and reach login via UART console. I added CONFIG_KEYBOARD_MAX7359=y
to board/librecomputer/amlogic/linux.config and rebuilt and flashed and looking at /proc/cofig.gz
it appears to have worked.
I’m only vaguely familar with the linux device tree, I assume I need to make an entry which is a child of the i2c bus it is attached to, specifiy keypads i2c address, and the interrupt line it will use (I have chosen pin 11 which is apparently GPIOAO_8), along with the rows/cols of the keypad matrix. I’m not 100% what to cput in the “compatible” field, in other driver source code I see a line like compatible = "abc,xyz",
but I don’t see any such line in max7359_keypad.c I only see the string "max7359"
in a couple places.
Here’s the dtsi file I created which compiles (after adding input.h and linux-event-codes.h)
/dts-v1/;
/plugin/;
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/interrupt-controller/meson-gic.h>
/{
compatible = "libretech,cc", "amlogic,s905x", "amlogic,meson-gxl";
fragment@1 {
target = <&i2c_AO>;
__overlay__ {
max7359@20 {
compatible = "max7359";
reg = <0x20>;
interrupt-parent = <&gpio_intc>;
interrupts = <MESON_GIC_GXL_GPIOAO_8 0x2008>;
linux,keymap = <
MATRIX_KEY(0, 0, KEY_NUMERIC_0)
MATRIX_KEY(0, 1, KEY_NUMERIC_1)
MATRIX_KEY(0, 2, KEY_NUMERIC_2)
MATRIX_KEY(1, 0, KEY_NUMERIC_3)
MATRIX_KEY(1, 1, KEY_NUMERIC_4)
MATRIX_KEY(1, 2, KEY_NUMERIC_5)
MATRIX_KEY(2, 0, KEY_NUMERIC_6)
MATRIX_KEY(2, 1, KEY_NUMERIC_7)
MATRIX_KEY(2, 2, KEY_NUMERIC_8)
MATRIX_KEY(3, 0, KEY_NUMERIC_9)
MATRIX_KEY(3, 1, KEY_ENTER)
MATRIX_KEY(3, 2, KEY_ESC)
>;
status = "okay";
};
};
};
};
Let me know if anything in the device tree file looks obviously wrong.
This appears to produce a file named libretech-dtoverlay_2023.08.17_all.deb but my Buildroot produces barebones embedded system which doesn’t have dpkg. I tried unpacking the deb file and copying the contents to the filesystem of the device but I cannot run the ldto program for some reason:
# pwd
/opt/librecomputer/libretech-wiring-tool
# ls -l
total 8
-rwxr-xr-x 1 root root 5586 Jan 1 00:24 ldto
drwxr-xr-x 8 root root 160 Jan 1 00:24 libre-computer
# ./ldto
-sh: ./ldto: not found
Can I use the kernel produced by buildroot with a prebuilt distro such as Raspbian which will have dpkg and allow me to easily install my custom version of the libretech wiring tool?
Alternatively maybe I can just modify the device tree that is used by buildroot so support for the keypad is there at boot and skip modifying and loading the libretech wiring tool, but looking at libretech-buildroot it looks like the device tree files are downloaded from somewhere, I only see them in the output directory, for example ./output/build/linux-6.1.30/arch/arm64/boot/dts/amlogic/meson-gxl-s905x-libretech-cc.dts
and modifying that doesn’t seem to work.