# HG changeset patch # User Paul Boddie # Date 1385319668 0 # Node ID 6aa0d0be8062dd231318d80298c23d7187e8200d # Parent 3644970cf1b6e03bffd2507f611289296a3cfd9c Added a bitmap example program and some images to use with it. diff -r 3644970cf1b6 -r 6aa0d0be8062 Makefile --- a/Makefile Fri Nov 22 22:13:07 2013 +0000 +++ b/Makefile Sun Nov 24 19:01:08 2013 +0000 @@ -17,25 +17,44 @@ CFLAGS = -g -Wall -fPIC -march=mips32 -I$(LIBUBB)/include # -DDEBUG=1 LDFLAGS = -lm -lubb -L$(LIBUBB) -TARGETS = spin +SPIN = spin +BITMAP = bitmap +TARGETS = $(SPIN) $(BITMAP) BASICSRC = pcf8833.c -SOURCES = $(BASICSRC) spin.c -OBJECTS = $(SOURCES:.c=.o) +SPINSOURCES = $(BASICSRC) spin.c +SPINOBJECTS = $(SPINSOURCES:.c=.o) + +BITMAPSOURCES = $(BASICSRC) bitmap.c bitmaps.c +BITMAPOBJECTS = $(BITMAPSOURCES:.c=.o) + +ALLSOURCES = $(BASICSRC) spin.c bitmap.c bitmaps.c +ALLOBJECTS = $(ALLSOURCES:.c=.o) + +IMAGES = examples/*.JPG +IMAGESOURCES = bitmaps.c bitmaps.h .PHONY: all clean distclean all: $(TARGETS) clean: - rm -f $(OBJECTS) $(TARGETS) + rm -f $(ALLOBJECTS) $(IMAGESOURCES) $(TARGETS) distclean: clean echo "Nothing else to clean." -$(TARGETS): $(OBJECTS) - $(CC) $(LDFLAGS) $(OBJECTS) -o $@ +$(SPIN): $(SPINOBJECTS) + $(CC) $(LDFLAGS) $(SPINOBJECTS) -o $@ + +$(BITMAP): $(BITMAPOBJECTS) + $(CC) $(LDFLAGS) $(BITMAPOBJECTS) -o $@ + +bitmap.c: $(IMAGESOURCES) + +$(IMAGESOURCES): $(IMAGES) + tools/bitmap.py bitmaps $(IMAGES) .c.o: $(CC) -c $(CFLAGS) $< -o $@ diff -r 3644970cf1b6 -r 6aa0d0be8062 bitmap.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bitmap.c Sun Nov 24 19:01:08 2013 +0000 @@ -0,0 +1,77 @@ +/* + * A demonstration of bitmap plotting. + * + * Copyright (C) 2013 Paul Boddie + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include "pcf8833.h" +#include +#include +#include +#include +#include "bitmaps.h" + +/** + * Handle termination of the process. + */ +void shutdown(int signum) +{ + printf("Closing...\n"); + ubb_close(0); + exit(1); +} + +void bitmap(uint8_t image) +{ + LCD_image(0, 0, image_data[image], IMAGE_WIDTH, IMAGE_HEIGHT); +} + +uint8_t states[] = {LCD_MADCTL_MY_MX, LCD_MADCTL_MY_V, 0, LCD_MADCTL_MX_V}; + +int main(int argc, char *argv[]) +{ + uint8_t state = 1; + uint8_t times; + uint8_t current_image = 0; + + signal(SIGINT, shutdown); + + /* Access the 8:10 port. */ + + if (ubb_open(0) < 0) { + perror("ubb_open"); + return 1; + } + + ubb_power(1); + printf("Power on.\n"); + + spi_init(); + LCD_init(); + bitmap(current_image); + + while (times--) + { + sleep(1); + printf("Updating...\n"); + + LCD_send(LCD_COMMAND, LCD_MADCTL); + LCD_send(LCD_DATA, states[state]); + bitmap(current_image); + + state = (state + 1) % 4; + current_image = (current_image + 1) % NUMBER_OF_IMAGES; + } + + printf("Closing...\n"); + ubb_close(0); + return 0; +} + +/* vim: tabstop=4 expandtab shiftwidth=4 + */ diff -r 3644970cf1b6 -r 6aa0d0be8062 examples/DSCF0320-132x132.JPG Binary file examples/DSCF0320-132x132.JPG has changed diff -r 3644970cf1b6 -r 6aa0d0be8062 examples/DSCF0321-132x132.JPG Binary file examples/DSCF0321-132x132.JPG has changed diff -r 3644970cf1b6 -r 6aa0d0be8062 pcf8833.c --- a/pcf8833.c Fri Nov 22 22:13:07 2013 +0000 +++ b/pcf8833.c Sun Nov 24 19:01:08 2013 +0000 @@ -172,12 +172,12 @@ LCD_send(LCD_COMMAND, LCD_NOP); } -void LCD_image(int x, int y, uint16_t image[], uint8_t width, uint8_t height) +void LCD_image(int x, int y, const uint16_t image[], uint8_t width, uint8_t height) { LCD_image_region(x, y, image, width, height, 0, width, 0, height); } -void LCD_image_region(int x, int y, uint16_t image[], uint8_t width, uint8_t height, uint8_t from_x, uint8_t span_x, uint8_t from_y, uint8_t span_y) +void LCD_image_region(int x, int y, const uint16_t image[], uint8_t width, uint8_t height, uint8_t from_x, uint8_t span_x, uint8_t from_y, uint8_t span_y) { uint8_t xmin, ymin, xcmax, ycmax, xcmin, xc, yc; uint16_t xmax, ymax, colour; diff -r 3644970cf1b6 -r 6aa0d0be8062 pcf8833.h --- a/pcf8833.h Fri Nov 22 22:13:07 2013 +0000 +++ b/pcf8833.h Sun Nov 24 19:01:08 2013 +0000 @@ -88,8 +88,8 @@ void LCD_window(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax); void LCD_blit_int(uint16_t colour); void LCD_area(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax, uint16_t colour); -void LCD_image(int x, int y, uint16_t image[], uint8_t width, uint8_t height); -void LCD_image_region(int x, int y, uint16_t image[], uint8_t width, uint8_t height, uint8_t from_x, uint8_t span_x, uint8_t from_y, uint8_t span_y); +void LCD_image(int x, int y, const uint16_t image[], uint8_t width, uint8_t height); +void LCD_image_region(int x, int y, const uint16_t image[], uint8_t width, uint8_t height, uint8_t from_x, uint8_t span_x, uint8_t from_y, uint8_t span_y); void LCD_normal(void); void LCD_scroll_area(uint8_t top_fixed, uint8_t scrolling, uint8_t bottom_fixed); void LCD_scroll_start(uint8_t address); diff -r 3644970cf1b6 -r 6aa0d0be8062 tools/bitmap.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/bitmap.py Sun Nov 24 19:01:08 2013 +0000 @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +""" +Produce program files for image data converted to 16bpp values suitable for +writing directly to the display. + +Copyright (C) 2013 Paul Boddie + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. +""" + +import PIL.Image +import math +import sys + +def get_image(input_filename, width, height): + + i = PIL.Image.open(input_filename) + i.thumbnail((width, height), PIL.Image.ANTIALIAS) + + all_values = [] + values = [] + last = None + x = 0 + for (r, g, b) in i.getdata(): + rgb = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3) + values.append(rgb) + x += 1 + + if x == width: + x = 0 + all_values.append(values) + values = [] + + return all_values + +def get_image_size(width, height): + return width * height + +if __name__ == "__main__": + import sys, os + + if len(sys.argv) < 3: + print sys.argv[0], " ..." + sys.exit(1) + + output_basename = sys.argv[1] + input_filenames = sys.argv[2:] + width = 132 + height = 132 + size = get_image_size(width, height) + number_of_images = len(input_filenames) + + f = open("%s.c" % output_basename, "wb") + + try: + # Write the image data. + + f.write("#include \n") + f.write("const uint16_t image_data[%d][%d] = {\n" % (number_of_images, size)) + for input_filename in input_filenames: + f.write("{\n") + for values in get_image(input_filename, width, height): + f.write(", ".join([("0x%04x" % v) for v in values])) + f.write(",\n") + f.write("},\n") + f.write("};\n") + + finally: + f.close() + + f = open("%s.h" % output_basename, "wb") + + try: + f.write("#include \n") + f.write("extern const uint16_t image_data[%d][%d];\n" % (number_of_images, size)) + f.write("#define MAX_IMAGE %d\n" % (number_of_images - 1)) + f.write("#define NUMBER_OF_IMAGES %d\n" % number_of_images) + f.write("#define IMAGE_SIZE %d\n" % size) + f.write("#define IMAGE_WIDTH %d\n" % width) + f.write("#define IMAGE_HEIGHT %d\n" % height) + + finally: + f.close() + +# vim: tabstop=4 expandtab shiftwidth=4