Crates.io | charlcd |
lib.rs | charlcd |
version | 1.0.0 |
source | src |
created_at | 2020-03-22 21:45:48.670957 |
updated_at | 2024-03-11 12:01:53.399505 |
description | Rust library for charlcd.c Linux driver (HD44780 et al.) |
homepage | |
repository | https://github.com/gagath/charlcd |
max_upload_size | |
id | 221562 |
size | 54,355 |
A rust crate to interact with the mainline Linux charlcd.c driver.
Or, said boldly: a crate to correctly interact with HD44780 LCD screens on embedded Linux devices.
The use of these kinds of photographies is used all over the documentation to explain the before and after of every available function. Be sure to check them all!
A lot of developers are relying on userspace libraries to interact with the very popular HD44780 LCD screens, but these implementations are lacking proper abstractions and usually all reimplement the same communication protocol to interact with the screen over and over.
This approach seems just wrong if you consider what the Linux kernel can provide in comparison. Indeed, it is the role of device drivers to properly abstract the access to the hardware from userspace perspective. For this, the Linux kernel uses an abstraction mechanism to declare the hardware: the device-tree.
The device-tree nodes for a screen behind an I2C GPIO expander would look like the following:
&i2c0 {
status = "okay";
pcf8574a: i2c0@3f {
compatible = "nxp,pcf8574a";
reg = <0x3f>;
gpio-controller;
#gpio-cells = <2>;
};
};
auxdisplay: auxdisplay {
compatible = "hit,hd44780";
data-gpios = <&pcf8574a 4 GPIO_ACTIVE_HIGH>,
<&pcf8574a 5 GPIO_ACTIVE_HIGH>,
<&pcf8574a 6 GPIO_ACTIVE_HIGH>,
<&pcf8574a 7 GPIO_ACTIVE_HIGH>;
rs-gpios = <&pcf8574a 0 GPIO_ACTIVE_HIGH>;
rw-gpios = <&pcf8574a 1 GPIO_ACTIVE_HIGH>;
enable-gpios = <&pcf8574a 2 GPIO_ACTIVE_HIGH>;
backlight-gpios = <&pcf8574a 3 GPIO_ACTIVE_LOW>;
display-height-chars = <2>;
display-width-chars = <16>;
};
Once the device-tree is correctly configured, the charlcd
driver will
create a /dev/lcd
character device.
The role of this library is to provide an abstraction over this character
device entry, while letting the kernel driver implement the communication
with the screen — instead of going from scratch and using ioctl over
/dev/i2c-*
like many other libraries do.
The charlcd driver is currently not able to report screen size to userspace. This is mitigated in the library by having a look at the device-tree entries directly.
For more information about this and a demo on real hardware, see this blog article.
Apache v2.