From 8deeac91ee798c24dd9a04c9339bfd0fffba76d0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 4 Oct 2024 13:09:05 +0800 Subject: [PATCH] update existing api to match hw api however, the actual driver is kind of bogus --- .../graphics-server/src/backend/cramium.rs | 2 +- .../graphics-server/src/betrusted-128x128.bmp | Bin 0 -> 2112 bytes .../graphics-server/src/convert_bmp_sh1107.py | 98 ++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 services/graphics-server/src/betrusted-128x128.bmp create mode 100644 services/graphics-server/src/convert_bmp_sh1107.py diff --git a/services/graphics-server/src/backend/cramium.rs b/services/graphics-server/src/backend/cramium.rs index 5660db3e9..ed1359cc4 100644 --- a/services/graphics-server/src/backend/cramium.rs +++ b/services/graphics-server/src/backend/cramium.rs @@ -105,7 +105,7 @@ impl XousDisplay { // setup the I/O pins let iox = IoxHal::new(); - let channel = setup_display_pins(&iox); + let (channel, _, _, _) = setup_display_pins(&iox); udma_global.udma_clock_config(PeriphId::from(channel), true); log::info!("gfx using spi channel {:?}", channel); diff --git a/services/graphics-server/src/betrusted-128x128.bmp b/services/graphics-server/src/betrusted-128x128.bmp new file mode 100644 index 0000000000000000000000000000000000000000..0750ddc327eef491ba3e0ee3a26e374d13d3f01d GIT binary patch literal 2112 zcmeH|F>b{m42De^sMH}+FTmPUG*$PW2{Lu;mC~u#pf`9ULlpNX1cKA*Ey+^pS%UCk zu)`lGd3}4ir^TMpKcV@xDN+~_-NFC(klQkWj+x8wc0Hzmg_euO9LKK6XR*(5Rf%^t z56r>vSmP(Qd=cDp6zq5w%#y#MLG^ph1Any~^-Mg}^XRB2a@W{I>OY(HC$Qbc+w-A( zdUwCS&bL25t4)sqTDSWB!FYdL{UbS^RM7|PNj|Sg9f#^q^`qDePE%$7;rh}6;hK2n zBA7p-OYca@cbMNrJff6eFF8}*Y)3flZTJ5N&YG`hhtekGaq82PHUWdx5_h2x{F7vw ziR`%f3IC2>uqWpmzZ+3s4fnAVzZ;A4ZQQ6%M#{}hEsi{=@kQFa7_kVCyA|8T(i>b? F;0GfeY@PrB literal 0 HcmV?d00001 diff --git a/services/graphics-server/src/convert_bmp_sh1107.py b/services/graphics-server/src/convert_bmp_sh1107.py new file mode 100644 index 000000000..79dfac027 --- /dev/null +++ b/services/graphics-server/src/convert_bmp_sh1107.py @@ -0,0 +1,98 @@ +#!/usr/bin/python3 + +import argparse +import numpy as np + +def bitflip(data_block, bitwidth=32): + if bitwidth == 0: + return data_block + + bytewidth = bitwidth // 8 + bitswapped = bytearray() + + i = 0 + while i < len(data_block): + data = int.from_bytes(data_block[i:i+bytewidth], byteorder='big', signed=False) + b = '{:0{width}b}'.format(data, width=bitwidth) + bitswapped.extend(int(b[::-1], 2).to_bytes(bytewidth, byteorder='big')) + i = i + bytewidth + + return bytes(bitswapped) + + +def convert(ifile, ofile): + with open(ifile, "rb") as f: + image = f.read() + + offset = image[0xa] # skip header + length = len(image) - offset + if length != 2050: + print("Image is not a full frame: {}", length) + exit(1) + + bitmap = [] + for index in range(2048): + b = image[offset + index] + bits = [] + for bit in range(8): + if (b >> (7 - bit)) & 1 == 0: + bits += [0] + else: + bits += [1] + bitmap += bits + + if False: + # Reshape the flat bitmap into a 2D array (row-normal) + bitmap_2d = np.array(bitmap).reshape((128, 128)) + + # Transpose the 2D array to convert it to column-normal + transposed_bitmap_2d = bitmap_2d.T + + # Flatten the transposed 2D array back to a 1D list (column-normal) + column_normal_bitmap = transposed_bitmap_2d.flatten() + + rotated = [] + for index in range(2048): + bits = column_normal_bitmap[index * 8 : (index + 1) * 8] + b = 0 + for (i, bit) in enumerate(bits): + if bit != 0: + b |= 1 << (7-i) + rotated += [b] + else: + rotated = [] + for index in range(2048): + rotated += [image[offset + index]] + + with open(ofile, "w") as output: + output.write("#![cfg_attr(rustfmt, rustfmt_skip)]\n") + output.write("pub const LOGO_MAP: [u8; 2048] = [") + for index in range(2048): + if index % 16 == 0: + output.write("\n") + b = rotated[index] + if index % 16 < 15: + output.write("0x{:02x}, ".format(b)) + else: + output.write("0x{:02x},".format(b)) + output.write("\n];\n") + + +def main(): + parser = argparse.ArgumentParser(description="Convert BMP to rust header file") + parser.add_argument( + "-f", "--file", required=True, help="filename to process", type=str + ) + parser.add_argument( + "-o", "--output-file", required=False, help="name of output Rust file", type=str, default="logo.rs" + ) + args = parser.parse_args() + + ifile = args.file + + convert(ifile, args.output_file) + + +if __name__ == "__main__": + main() +