1.1 --- a/Makefile Fri Nov 22 22:13:07 2013 +0000
1.2 +++ b/Makefile Sun Nov 24 19:01:08 2013 +0000
1.3 @@ -17,25 +17,44 @@
1.4 CFLAGS = -g -Wall -fPIC -march=mips32 -I$(LIBUBB)/include # -DDEBUG=1
1.5 LDFLAGS = -lm -lubb -L$(LIBUBB)
1.6
1.7 -TARGETS = spin
1.8 +SPIN = spin
1.9 +BITMAP = bitmap
1.10 +TARGETS = $(SPIN) $(BITMAP)
1.11
1.12 BASICSRC = pcf8833.c
1.13
1.14 -SOURCES = $(BASICSRC) spin.c
1.15 -OBJECTS = $(SOURCES:.c=.o)
1.16 +SPINSOURCES = $(BASICSRC) spin.c
1.17 +SPINOBJECTS = $(SPINSOURCES:.c=.o)
1.18 +
1.19 +BITMAPSOURCES = $(BASICSRC) bitmap.c bitmaps.c
1.20 +BITMAPOBJECTS = $(BITMAPSOURCES:.c=.o)
1.21 +
1.22 +ALLSOURCES = $(BASICSRC) spin.c bitmap.c bitmaps.c
1.23 +ALLOBJECTS = $(ALLSOURCES:.c=.o)
1.24 +
1.25 +IMAGES = examples/*.JPG
1.26 +IMAGESOURCES = bitmaps.c bitmaps.h
1.27
1.28 .PHONY: all clean distclean
1.29
1.30 all: $(TARGETS)
1.31
1.32 clean:
1.33 - rm -f $(OBJECTS) $(TARGETS)
1.34 + rm -f $(ALLOBJECTS) $(IMAGESOURCES) $(TARGETS)
1.35
1.36 distclean: clean
1.37 echo "Nothing else to clean."
1.38
1.39 -$(TARGETS): $(OBJECTS)
1.40 - $(CC) $(LDFLAGS) $(OBJECTS) -o $@
1.41 +$(SPIN): $(SPINOBJECTS)
1.42 + $(CC) $(LDFLAGS) $(SPINOBJECTS) -o $@
1.43 +
1.44 +$(BITMAP): $(BITMAPOBJECTS)
1.45 + $(CC) $(LDFLAGS) $(BITMAPOBJECTS) -o $@
1.46 +
1.47 +bitmap.c: $(IMAGESOURCES)
1.48 +
1.49 +$(IMAGESOURCES): $(IMAGES)
1.50 + tools/bitmap.py bitmaps $(IMAGES)
1.51
1.52 .c.o:
1.53 $(CC) -c $(CFLAGS) $< -o $@
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/bitmap.c Sun Nov 24 19:01:08 2013 +0000
2.3 @@ -0,0 +1,77 @@
2.4 +/*
2.5 + * A demonstration of bitmap plotting.
2.6 + *
2.7 + * Copyright (C) 2013 Paul Boddie
2.8 + *
2.9 + * This program is free software; you can redistribute it and/or modify
2.10 + * it under the terms of the GNU General Public License as published by
2.11 + * the Free Software Foundation; either version 2 of the License, or
2.12 + * (at your option) any later version.
2.13 + */
2.14 +
2.15 +#include "pcf8833.h"
2.16 +#include <stdio.h>
2.17 +#include <unistd.h>
2.18 +#include <signal.h>
2.19 +#include <stdlib.h>
2.20 +#include "bitmaps.h"
2.21 +
2.22 +/**
2.23 + * Handle termination of the process.
2.24 + */
2.25 +void shutdown(int signum)
2.26 +{
2.27 + printf("Closing...\n");
2.28 + ubb_close(0);
2.29 + exit(1);
2.30 +}
2.31 +
2.32 +void bitmap(uint8_t image)
2.33 +{
2.34 + LCD_image(0, 0, image_data[image], IMAGE_WIDTH, IMAGE_HEIGHT);
2.35 +}
2.36 +
2.37 +uint8_t states[] = {LCD_MADCTL_MY_MX, LCD_MADCTL_MY_V, 0, LCD_MADCTL_MX_V};
2.38 +
2.39 +int main(int argc, char *argv[])
2.40 +{
2.41 + uint8_t state = 1;
2.42 + uint8_t times;
2.43 + uint8_t current_image = 0;
2.44 +
2.45 + signal(SIGINT, shutdown);
2.46 +
2.47 + /* Access the 8:10 port. */
2.48 +
2.49 + if (ubb_open(0) < 0) {
2.50 + perror("ubb_open");
2.51 + return 1;
2.52 + }
2.53 +
2.54 + ubb_power(1);
2.55 + printf("Power on.\n");
2.56 +
2.57 + spi_init();
2.58 + LCD_init();
2.59 + bitmap(current_image);
2.60 +
2.61 + while (times--)
2.62 + {
2.63 + sleep(1);
2.64 + printf("Updating...\n");
2.65 +
2.66 + LCD_send(LCD_COMMAND, LCD_MADCTL);
2.67 + LCD_send(LCD_DATA, states[state]);
2.68 + bitmap(current_image);
2.69 +
2.70 + state = (state + 1) % 4;
2.71 + current_image = (current_image + 1) % NUMBER_OF_IMAGES;
2.72 + }
2.73 +
2.74 + printf("Closing...\n");
2.75 + ubb_close(0);
2.76 + return 0;
2.77 +}
2.78 +
2.79 +/* vim: tabstop=4 expandtab shiftwidth=4
2.80 + */
3.1 Binary file examples/DSCF0320-132x132.JPG has changed
4.1 Binary file examples/DSCF0321-132x132.JPG has changed
5.1 --- a/pcf8833.c Fri Nov 22 22:13:07 2013 +0000
5.2 +++ b/pcf8833.c Sun Nov 24 19:01:08 2013 +0000
5.3 @@ -172,12 +172,12 @@
5.4 LCD_send(LCD_COMMAND, LCD_NOP);
5.5 }
5.6
5.7 -void LCD_image(int x, int y, uint16_t image[], uint8_t width, uint8_t height)
5.8 +void LCD_image(int x, int y, const uint16_t image[], uint8_t width, uint8_t height)
5.9 {
5.10 LCD_image_region(x, y, image, width, height, 0, width, 0, height);
5.11 }
5.12
5.13 -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)
5.14 +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)
5.15 {
5.16 uint8_t xmin, ymin, xcmax, ycmax, xcmin, xc, yc;
5.17 uint16_t xmax, ymax, colour;
6.1 --- a/pcf8833.h Fri Nov 22 22:13:07 2013 +0000
6.2 +++ b/pcf8833.h Sun Nov 24 19:01:08 2013 +0000
6.3 @@ -88,8 +88,8 @@
6.4 void LCD_window(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax);
6.5 void LCD_blit_int(uint16_t colour);
6.6 void LCD_area(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax, uint16_t colour);
6.7 -void LCD_image(int x, int y, uint16_t image[], uint8_t width, uint8_t height);
6.8 -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);
6.9 +void LCD_image(int x, int y, const uint16_t image[], uint8_t width, uint8_t height);
6.10 +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);
6.11 void LCD_normal(void);
6.12 void LCD_scroll_area(uint8_t top_fixed, uint8_t scrolling, uint8_t bottom_fixed);
6.13 void LCD_scroll_start(uint8_t address);
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/tools/bitmap.py Sun Nov 24 19:01:08 2013 +0000
7.3 @@ -0,0 +1,89 @@
7.4 +#!/usr/bin/env python
7.5 +
7.6 +"""
7.7 +Produce program files for image data converted to 16bpp values suitable for
7.8 +writing directly to the display.
7.9 +
7.10 +Copyright (C) 2013 Paul Boddie
7.11 +
7.12 +This program is free software; you can redistribute it and/or modify
7.13 +it under the terms of the GNU General Public License as published by
7.14 +the Free Software Foundation; either version 2 of the License, or
7.15 +(at your option) any later version.
7.16 +"""
7.17 +
7.18 +import PIL.Image
7.19 +import math
7.20 +import sys
7.21 +
7.22 +def get_image(input_filename, width, height):
7.23 +
7.24 + i = PIL.Image.open(input_filename)
7.25 + i.thumbnail((width, height), PIL.Image.ANTIALIAS)
7.26 +
7.27 + all_values = []
7.28 + values = []
7.29 + last = None
7.30 + x = 0
7.31 + for (r, g, b) in i.getdata():
7.32 + rgb = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
7.33 + values.append(rgb)
7.34 + x += 1
7.35 +
7.36 + if x == width:
7.37 + x = 0
7.38 + all_values.append(values)
7.39 + values = []
7.40 +
7.41 + return all_values
7.42 +
7.43 +def get_image_size(width, height):
7.44 + return width * height
7.45 +
7.46 +if __name__ == "__main__":
7.47 + import sys, os
7.48 +
7.49 + if len(sys.argv) < 3:
7.50 + print sys.argv[0], "<output basename> <image filename>..."
7.51 + sys.exit(1)
7.52 +
7.53 + output_basename = sys.argv[1]
7.54 + input_filenames = sys.argv[2:]
7.55 + width = 132
7.56 + height = 132
7.57 + size = get_image_size(width, height)
7.58 + number_of_images = len(input_filenames)
7.59 +
7.60 + f = open("%s.c" % output_basename, "wb")
7.61 +
7.62 + try:
7.63 + # Write the image data.
7.64 +
7.65 + f.write("#include <stdint.h>\n")
7.66 + f.write("const uint16_t image_data[%d][%d] = {\n" % (number_of_images, size))
7.67 + for input_filename in input_filenames:
7.68 + f.write("{\n")
7.69 + for values in get_image(input_filename, width, height):
7.70 + f.write(", ".join([("0x%04x" % v) for v in values]))
7.71 + f.write(",\n")
7.72 + f.write("},\n")
7.73 + f.write("};\n")
7.74 +
7.75 + finally:
7.76 + f.close()
7.77 +
7.78 + f = open("%s.h" % output_basename, "wb")
7.79 +
7.80 + try:
7.81 + f.write("#include <stdint.h>\n")
7.82 + f.write("extern const uint16_t image_data[%d][%d];\n" % (number_of_images, size))
7.83 + f.write("#define MAX_IMAGE %d\n" % (number_of_images - 1))
7.84 + f.write("#define NUMBER_OF_IMAGES %d\n" % number_of_images)
7.85 + f.write("#define IMAGE_SIZE %d\n" % size)
7.86 + f.write("#define IMAGE_WIDTH %d\n" % width)
7.87 + f.write("#define IMAGE_HEIGHT %d\n" % height)
7.88 +
7.89 + finally:
7.90 + f.close()
7.91 +
7.92 +# vim: tabstop=4 expandtab shiftwidth=4