diff --git a/Makefile b/Makefile index 4843328..ff68814 100755 --- a/Makefile +++ b/Makefile @@ -8,10 +8,13 @@ all: AppMain.bin m4_loader.bin .PHONY: clean: - @rm -f *.bin *.elf + @rm -f *.bin *.elf pixels.c -AppMain.bin: - @$(AS) main.S -o main.elf +pixels.c: + @python3 img2c.py image.jpg pixels.c + +AppMain.bin: pixels.c + @$(CC) -nostdlib -static -fPIC -mcpu=cortex-a7 main.S pixels.c -o main.elf @./extract.py -p main.elf AppMain.bin m4_loader.bin: diff --git a/img2c.py b/img2c.py new file mode 100644 index 0000000..cea2446 --- /dev/null +++ b/img2c.py @@ -0,0 +1,34 @@ +import sys +from PIL import Image + + +template = '''void load_pixels() {{ +{lines} +}}; +''' + +im = Image.open(sys.argv[-2]).convert('RGB') + +with open(sys.argv[-1], 'w') as f: + pixels = [] + lines = [] + count = 0 + + for y in range(im.size[1]): + for x in range(0, im.size[0], 2): + r, g, b = im.getpixel((x, y)) + rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3) + pixels.append(rgb565 >> 8) + pixels.append(rgb565 & 0xff) + + r, g, b = im.getpixel((x+1, y)) + rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3) + pixels.append(rgb565 >> 8) + pixels.append(rgb565 & 0xff) + + u32 = (pixels[0] << 24) + (pixels[1] << 16) + (pixels[2] << 8) + pixels[3] + lines.append(f'\t*(unsigned int *)(0x62000000 + {count:7d}) = {u32:#08x};') + pixels = [] + count += 4; + f.write(template.format(lines='\n'.join(lines))) + diff --git a/main.S b/main.S index d5a947b..df74e1b 100755 --- a/main.S +++ b/main.S @@ -3,6 +3,7 @@ .global _start _start: + bl load_pixels //M4 RTOS loader snipet prep ldr r4, =0x60006400 //fopen addr adr r0, [.LC2] //file name diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3868fb1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pillow