From 68b5f182af145fdd9e62c9dde3eedcb9108f5ba4 Mon Sep 17 00:00:00 2001 From: Tobias Wiese Date: Mon, 3 May 2021 23:58:30 +0200 Subject: Initial commit Signed-off-by: Tobias Wiese --- img_mono.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 img_mono.c (limited to 'img_mono.c') diff --git a/img_mono.c b/img_mono.c new file mode 100644 index 0000000..b711a6b --- /dev/null +++ b/img_mono.c @@ -0,0 +1,58 @@ +#include +#include "libleds.h" +#include "img_mono.xbm" + +static char const PORT = 0; +static char const PINS = 1<<7; + +char const is_active(unsigned int const n) +{ + /* + * The first led is in the top left corner. + * After that it goes down the column, then up the next and so on. + * + * This means all columns with an even index count down. + * Those with an odd index count up. + * + * + * With a height of 8 the led numbers would look like this: + * + * 00 0F 10 1F 20 ... + * 01 0E 11 1E 21 ... + * 02 0D 12 1D ... + * 03 0C 13 1C ... + * 04 0B 14 1B ... + * 05 0A 15 1A ... + * 06 09 16 19 ... + * 07 08 17 18 ... + */ + + unsigned int const bytes_per_row = ceil(img_width / 8.0); + unsigned int col = n / img_height; + unsigned int row = n % img_height; + if (col % 2) + row = img_height - 1 - row; + + // calculate byte to access + unsigned int byte = row * bytes_per_row; + byte += col / 8; + + unsigned char data = img_bits[byte]; + unsigned char mask = 1<<(col % 8); + return data & mask; +} + +void led_main() +{ + const int length = img_width * img_height; + + struct led_color pixel[length]; + + for (unsigned int i = 0; i < length; i++) { + unsigned char out = is_active(i) ? 0xFF : 0x00; + pixel[i] = (struct led_color){out, out, out}; + } + + for (unsigned int i = 0; i < length; i++) + led_write_rgb(PORT, PINS, pixel[i]); +} -- cgit v1.2.3