From 1564f881f466bbb9944e5fac843c3d718b75ca65 Mon Sep 17 00:00:00 2001 From: cybernesto Date: Wed, 12 Jan 2022 17:45:22 +0100 Subject: [PATCH] Add capability of writing logos in binary format Extended python script to support writing .bin files directly. This avoids the additional step of using objcopy. Updated the 001_PINECIL.bin file to match the PNG. --- Bootup Logo/Logos/001_PINECIL.bin | Bin 1024 -> 1024 bytes .../python_logo_converter/img2ts100.py | 35 +++++++++++++----- Documentation/Logo.md | 6 +-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Bootup Logo/Logos/001_PINECIL.bin b/Bootup Logo/Logos/001_PINECIL.bin index df0a6d92f0fb5b29011fbda42bc949c8a0c688c5..5d3834a67c816d01cebf09191f6d2bb289653c0a 100644 GIT binary patch literal 1024 zcmWGt#rxqro3uRxBSQl^U}#`~g98l*4kR4du;By41|;xd!v=;G8#b&+sMv912OMnJ zv0}xI4L=_I`0xV=KKx)}Vr61wX5i-J=VXRLCQcw^XJTbwWrjdOu0(lNKUHpf232kZ dwC7d@^VPZ4xNt#vF1RB{8KWUE8UiGR006n`J?Q`d literal 1024 zcmWGt#rvUwK`Vqww4t#92{1G;fPq7U!vTc@1_l!X1U?8L0c6gF2>}-ZkiZ2n5SRc_ z&hUVVft87sl>-H^a0Mj fK0YEMKEmDK-N6Z{gTWr+(ou3W1V%%E)DQpwid-@% diff --git a/Bootup Logo/python_logo_converter/img2ts100.py b/Bootup Logo/python_logo_converter/img2ts100.py index 8691a7e2..3759c153 100644 --- a/Bootup Logo/python_logo_converter/img2ts100.py +++ b/Bootup Logo/python_logo_converter/img2ts100.py @@ -13,7 +13,7 @@ except ImportError as error: "management tool." .format(error, sys.argv[0])) -VERSION_STRING = '0.01' +VERSION_STRING = '0.02' LCD_WIDTH = 96 LCD_HEIGHT = 16 @@ -87,7 +87,8 @@ def img2hex(input_filename, preview_filename=None, threshold=128, dither=False, - negative=False): + negative=False, + binary=False): """ Convert 'input_filename' image file into Intel hex format with data formatted for display on TS100 LCD and file object. @@ -158,7 +159,11 @@ def img2hex(input_filename, # store in endian-reversed byte order data[4 + ndx + (1 if ndx % 2 == 0 else -1)] = byte - intel_hex(output_file, data, 0x0800F800) + if binary: + for byte in data: + output_file.write(byte.to_bytes(1, byteorder="big")) + else: + intel_hex(output_file, data, 0x0800F800) def parse_commandline(): @@ -229,13 +234,23 @@ if __name__ == "__main__": sys.exit(1) try: - with open(args.output_filename, 'w', newline='\r\n') as output: - img2hex(args.input_filename, - output, - args.preview, - args.threshold, - args.dither, - args.negative) + if args.output_filename[-4:] == ".bin": + with open(args.output_filename, 'wb') as output: + img2hex(args.input_filename, + output, + args.preview, + args.threshold, + args.dither, + args.negative, + True) + else: + with open(args.output_filename, 'w', newline='\r\n') as output: + img2hex(args.input_filename, + output, + args.preview, + args.threshold, + args.dither, + args.negative) except BaseException as error: sys.stderr.write("Error converting file: {}\n".format(error)) sys.exit(1) diff --git a/Documentation/Logo.md b/Documentation/Logo.md index b8b0add0..164c28c9 100644 --- a/Documentation/Logo.md +++ b/Documentation/Logo.md @@ -32,9 +32,7 @@ For the Pinecil, we require to flash the logo using dfu-util instead, which will To flash the logo, use the following steps: - - `python3 img2ts100.py input.png logo.hex` - - `riscv-nuclei-elf-objcopy -I ihex -O binary logo.hex logo.bin` + - `python3 img2ts100.py input.png logo.bin` - `dfu-util -d 28e9:0189 -a 0 -D logo.bin -s 0x0801F800` - This will use the objcopy tool to convert the hex to a binary file, and then use dfu-util to flash it in the right location. - If you do not have `riscv-nuclei-elf-objcopy` installed, you can generally use any objcopy tool from any toolchain you do have. + The converter will create a binary file if the .bin extension is used. Use dfu-util to flash it in the right location.