summaryrefslogtreecommitdiffstats
path: root/src/custom_char.rs
diff options
context:
space:
mode:
authorAgathe Porte <microjoe@microjoe.org>2020-02-23 10:30:59 +0100
committerAgathe Porte <microjoe@microjoe.org>2020-02-23 11:37:50 +0100
commitc07aa9f0c068200d80f6635c221dd7480e53766a (patch)
tree8b454142169036e1b4be38289e46e9b76bdfd9dd /src/custom_char.rs
parentbc0e5a406a0179fdbc7a5e298d108e966bcb3ed0 (diff)
downloadcharlcd-c07aa9f0c068200d80f6635c221dd7480e53766a.tar.gz
charlcd-c07aa9f0c068200d80f6635c221dd7480e53766a.zip
custom chars support
Diffstat (limited to 'src/custom_char.rs')
-rw-r--r--src/custom_char.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/custom_char.rs b/src/custom_char.rs
new file mode 100644
index 0000000..47f99f5
--- /dev/null
+++ b/src/custom_char.rs
@@ -0,0 +1,50 @@
+/// X axis mirror of a custom LCD character
+pub const fn mirror_x(src: [u8; 8]) -> [u8; 8] {
+ // const fn do not support for loops currently, hence manual unroll
+ [
+ src[0].reverse_bits() >> 3,
+ src[1].reverse_bits() >> 3,
+ src[2].reverse_bits() >> 3,
+ src[3].reverse_bits() >> 3,
+ src[4].reverse_bits() >> 3,
+ src[5].reverse_bits() >> 3,
+ src[6].reverse_bits() >> 3,
+ src[7].reverse_bits() >> 3,
+ ]
+}
+
+/// Y axis mirror of a custom LCD character
+pub const fn mirror_y(src: [u8; 8]) -> [u8; 8] {
+ // const fn do not support for loops currently, hence manual unroll
+ [
+ src[7], src[6], src[5], src[4], src[3], src[2], src[1], src[0],
+ ]
+}
+
+#[cfg_attr(rustfmt, rustfmt_skip)]
+pub const RIGHT_ARROW: [u8; 8] = [
+ 0b00000,
+ 0b01000,
+ 0b01100,
+ 0b01110,
+ 0b01100,
+ 0b01000,
+ 0b00000,
+ 0b00000,
+];
+
+pub const LEFT_ARROW: [u8; 8] = mirror_x(RIGHT_ARROW);
+
+#[cfg_attr(rustfmt, rustfmt_skip)]
+pub const UP_ARROW: [u8; 8] = [
+ 0b00000,
+ 0b00000,
+ 0b00100,
+ 0b01110,
+ 0b11111,
+ 0b00000,
+ 0b00000,
+ 0b00000,
+];
+
+pub const DOWN_ARROW: [u8; 8] = mirror_y(UP_ARROW);