Fix bug in hxtft driver: drawing rectangles.

Add a few gpanel examples.
This commit is contained in:
Serge Vakulenko
2015-10-08 22:15:01 -07:00
parent b99fcc6c8c
commit 08edaaba8c
20 changed files with 366 additions and 38 deletions

View File

@@ -1024,9 +1024,25 @@ file /share/examples/c/tetris.c
# Files: /share/examples/gpanel
#
dir /share/examples/gpanel
dir /share/examples/gpanel/fonts
file /share/examples/gpanel/Makefile
file /share/examples/gpanel/circle.c
file /share/examples/gpanel/fill.c
file /share/examples/gpanel/font.c
file /share/examples/gpanel/line.c
file /share/examples/gpanel/pixel.c
file /share/examples/gpanel/rect.c
file /share/examples/gpanel/tft.c
file /share/examples/gpanel/tftetris.c
file /share/examples/gpanel/fonts/5x7.c
file /share/examples/gpanel/fonts/6x9.c
file /share/examples/gpanel/fonts/digits20.c
file /share/examples/gpanel/fonts/digits32.c
file /share/examples/gpanel/fonts/lucidasans11.c
file /share/examples/gpanel/fonts/lucidasans15.c
file /share/examples/gpanel/fonts/lucidasans7.c
file /share/examples/gpanel/fonts/lucidasans9.c
file /share/examples/gpanel/fonts/verdana7.c
#
# Files: /share/examples/smallc

View File

@@ -1,5 +1,9 @@
CC = cc
PROG = tft tftetris
LIBS = -lgpanel
PROG = tft tftetris pixel line rect fill circle font
FONTS = 5x7.o 6x9.o digits20.o digits32.o lucidasans11.o lucidasans15.o \
lucidasans7.o lucidasans9.o verdana7.o
all: $(PROG)
@@ -11,3 +15,48 @@ tft: tft.c
tftetris: tftetris.c
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $?
pixel: pixel.c
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS)
line: line.c
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS)
rect: rect.c
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS)
fill: fill.c
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS)
circle: circle.c
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS)
font: font.c $(FONTS)
$(CC) $(CFLAGS) -o $@ $(LDFLAGS) font.c $(FONTS) $(LIBS)
5x7.o: fonts/5x7.c
$(CC) $(CFLAGS) -o $@ -c $?
6x9.o: fonts/6x9.c
$(CC) $(CFLAGS) -o $@ -c $?
digits20.o: fonts/digits20.c
$(CC) $(CFLAGS) -o $@ -c $?
digits32.o: fonts/digits32.c
$(CC) $(CFLAGS) -o $@ -c $?
lucidasans11.o: fonts/lucidasans11.c
$(CC) $(CFLAGS) -o $@ -c $?
lucidasans15.o: fonts/lucidasans15.c
$(CC) $(CFLAGS) -o $@ -c $?
lucidasans7.o: fonts/lucidasans7.c
$(CC) $(CFLAGS) -o $@ -c $?
lucidasans9.o: fonts/lucidasans9.c
$(CC) $(CFLAGS) -o $@ -c $?
verdana7.o: fonts/verdana7.c
$(CC) $(CFLAGS) -o $@ -c $?

View File

@@ -0,0 +1,33 @@
/*
* Draw random circles.
*/
#include <stdio.h>
#include <sys/gpanel.h>
int xsize, ysize;
int main()
{
char *devname = "/dev/tft0";
int x, y, r, color;
if (gpanel_open(devname) < 0) {
printf("Cannot open %s\n", devname);
exit(-1);
}
gpanel_clear(0, &xsize, &ysize);
printf("Screen size %u x %u.\n", xsize, ysize);
srandom(time(0));
printf("Draw random circles.\n");
printf("Press ^C to stop.\n");
for (;;) {
x = random() % xsize;
y = random() % ysize;
r = random() % ysize;
color = random();
gpanel_circle(color, x, y, r);
}
return 0;
}

View File

@@ -0,0 +1,34 @@
/*
* Draw random filled rectangles.
*/
#include <stdio.h>
#include <sys/gpanel.h>
int xsize, ysize;
int main()
{
char *devname = "/dev/tft0";
int x0, y0, x1, y1, color;
if (gpanel_open(devname) < 0) {
printf("Cannot open %s\n", devname);
exit(-1);
}
gpanel_clear(0, &xsize, &ysize);
printf("Screen size %u x %u.\n", xsize, ysize);
srandom(time(0));
printf("Draw random filled rectangles.\n");
printf("Press ^C to stop.\n");
for (;;) {
x0 = random() % xsize;
y0 = random() % ysize;
x1 = random() % xsize;
y1 = random() % ysize;
color = random();
gpanel_fill(color, x0, y0, x1, y1);
}
return 0;
}

View File

@@ -0,0 +1,90 @@
/*
* Draw samples of various fonts.
*/
#include <stdio.h>
#include <sys/gpanel.h>
/*
* Data from external font files.
*/
extern const struct gpanel_font_t font_lucidasans15;
extern const struct gpanel_font_t font_lucidasans11;
extern const struct gpanel_font_t font_lucidasans9;
extern const struct gpanel_font_t font_lucidasans7;
extern const struct gpanel_font_t font_verdana7;
extern const struct gpanel_font_t font_6x9;
extern const struct gpanel_font_t font_5x7;
extern const struct gpanel_font_t font_digits32;
extern const struct gpanel_font_t font_digits20;
/*
* Color constants.
*/
#define COLOR_RGB(r,g,b) ((r)<<11 | (g)<<5 | (b))
#define COLOR_BLACK 0
#define COLOR_WHITE COLOR_RGB(31, 63, 31)
#define COLOR_YELLOW COLOR_RGB(31, 63, 0)
#define COLOR_MAGENTA COLOR_RGB(31, 0, 31)
#define COLOR_CYAN COLOR_RGB(0, 63, 31)
/*
* Screen size.
*/
int xsize, ysize;
void show(const struct gpanel_font_t *font, const char *title, int digits_only)
{
char line[100];
int x = 10;
int y = 10;
gpanel_clear(COLOR_BLACK, 0, 0);
gpanel_text(&font_lucidasans15, COLOR_WHITE, COLOR_BLACK, x, y, title);
y += font_lucidasans15.height;
gpanel_text(font, COLOR_YELLOW, COLOR_BLACK, x, y,
digits_only ? "0123456789"
: "The quick brown fox");
y += font->height;
gpanel_text(font, COLOR_CYAN, COLOR_BLACK, x, y,
digits_only ? "3456789012"
: "jumps over");
y += font->height;
gpanel_text(font, COLOR_MAGENTA, COLOR_BLACK, x, y,
digits_only ? "6789012345"
: "the lazy dog.");
printf("Font %s: press Enter...", title);
fflush(stdout);
fgets(line, sizeof(line), stdin);
}
int main()
{
char *devname = "/dev/tft0";
int x, y, color;
if (gpanel_open(devname) < 0) {
printf("Cannot open %s\n", devname);
exit(-1);
}
gpanel_clear(0, &xsize, &ysize);
printf("Screen size %u x %u.\n", xsize, ysize);
printf("Draw fonts.\n");
printf("Press ^C to stop.\n");
for (;;) {
show(&font_lucidasans15, "Lucida Sans 15", 0);
show(&font_lucidasans11, "Lucida Sans 11", 0);
show(&font_lucidasans9, "Lucida Sans 9", 0);
show(&font_lucidasans7, "Lucida Sans 7", 0);
show(&font_verdana7, "Verdana 7", 0);
show(&font_6x9, "Fixed 6x9", 0);
show(&font_5x7, "Fixed 5x7", 0);
show(&font_digits32, "Digits 32", 1);
show(&font_digits20, "Digits 20", 1);
}
return 0;
}

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */
#include <sys/gpanel.h>
/* Font information:
name: 5x7
@@ -4168,7 +4168,7 @@ static const unsigned short _5x7_offset[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_5x7 = {
const struct gpanel_font_t font_5x7 = {
"5x7",
5,
7,

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */
#include <sys/gpanel.h>
/* Font information:
name: 6x9
@@ -4808,7 +4808,7 @@ static const unsigned short _6x9_offset[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_6x9 = {
const struct gpanel_font_t font_6x9 = {
"6x9",
6,
9,

View File

@@ -733,7 +733,7 @@ gen_c_source(font_t *pf, char *path)
char obuf[256];
char hdr1[] = {
"/* Generated by convbdf on %s. */\n"
"#include \"gpanel.h\"\n"
"#include <sys/gpanel.h>\n"
"\n"
"/* Font information:\n"
" name: %s\n"
@@ -894,7 +894,7 @@ gen_c_source(font_t *pf, char *path)
sprintf(buf, "_%s_width,", pf->name);
else sprintf(buf, "0, /* fixed width*/");
fprintf(ofp, "/* Exported structure definition. */\n"
"const gpanel_font_t font_%s = {\n"
"const struct gpanel_font_t font_%s = {\n"
" \"%s\",\n"
" %d,\n"
" %d,\n"

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:54 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */
#include <sys/gpanel.h>
/* Font information:
name: digits20
@@ -670,7 +670,7 @@ static const unsigned char _digits20_width[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_digits20 = {
const struct gpanel_font_t font_digits20 = {
"digits20",
18,
22,

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:54 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */
#include <sys/gpanel.h>
/* Font information:
name: digits32
@@ -1102,7 +1102,7 @@ static const unsigned char _digits32_width[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_digits32 = {
const struct gpanel_font_t font_digits32 = {
"digits32",
28,
40,

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */
#include <sys/gpanel.h>
/* Font information:
name: lucidasans11
@@ -4038,7 +4038,7 @@ static const unsigned char _lucidasans11_width[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_lucidasans11 = {
const struct gpanel_font_t font_lucidasans11 = {
"lucidasans11",
14,
17,

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */
#include <sys/gpanel.h>
/* Font information:
name: lucidasans15
@@ -4998,7 +4998,7 @@ static const unsigned char _lucidasans15_width[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_lucidasans15 = {
const struct gpanel_font_t font_lucidasans15 = {
"lucidasans15",
20,
22,

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */
#include <sys/gpanel.h>
/* Font information:
name: lucidasans7
@@ -2502,7 +2502,7 @@ static const unsigned char _lucidasans7_width[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_lucidasans7 = {
const struct gpanel_font_t font_lucidasans7 = {
"lucidasans7",
9,
9,

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */
#include <sys/gpanel.h>
/* Font information:
name: lucidasans9
@@ -3462,7 +3462,7 @@ static const unsigned char _lucidasans9_width[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_lucidasans9 = {
const struct gpanel_font_t font_lucidasans9 = {
"lucidasans9",
12,
14,

View File

@@ -1,5 +1,5 @@
/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */
#include "gpanel.h"
/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */
#include <sys/gpanel.h>
/* Font information:
name: verdana7
@@ -2694,7 +2694,7 @@ static const unsigned char _verdana7_width[] = {
};
/* Exported structure definition. */
const gpanel_font_t font_verdana7 = {
const struct gpanel_font_t font_verdana7 = {
"verdana7",
11,
10,

View File

@@ -0,0 +1,34 @@
/*
* Draw random lines.
*/
#include <stdio.h>
#include <sys/gpanel.h>
int xsize, ysize;
int main()
{
char *devname = "/dev/tft0";
int x0, y0, x1, y1, color;
if (gpanel_open(devname) < 0) {
printf("Cannot open %s\n", devname);
exit(-1);
}
gpanel_clear(0, &xsize, &ysize);
printf("Screen size %u x %u.\n", xsize, ysize);
srandom(time(0));
printf("Draw random lines.\n");
printf("Press ^C to stop.\n");
for (;;) {
x0 = random() % xsize;
y0 = random() % ysize;
x1 = random() % xsize;
y1 = random() % ysize;
color = random();
gpanel_line(color, x0, y0, x1, y1);
}
return 0;
}

View File

@@ -0,0 +1,32 @@
/*
* Draw random pixels.
*/
#include <stdio.h>
#include <sys/gpanel.h>
int xsize, ysize;
int main()
{
char *devname = "/dev/tft0";
int x, y, color;
if (gpanel_open(devname) < 0) {
printf("Cannot open %s\n", devname);
exit(-1);
}
gpanel_clear(0, &xsize, &ysize);
printf("Screen size %u x %u.\n", xsize, ysize);
srandom(time(0));
printf("Draw random pixels.\n");
printf("Press ^C to stop.\n");
for (;;) {
x = random() % xsize;
y = random() % ysize;
color = random();
gpanel_pixel(color, x, y);
}
return 0;
}

View File

@@ -0,0 +1,34 @@
/*
* Draw random rectangles.
*/
#include <stdio.h>
#include <sys/gpanel.h>
int xsize, ysize;
int main()
{
char *devname = "/dev/tft0";
int x0, y0, x1, y1, color;
if (gpanel_open(devname) < 0) {
printf("Cannot open %s\n", devname);
exit(-1);
}
gpanel_clear(0, &xsize, &ysize);
printf("Screen size %u x %u.\n", xsize, ysize);
srandom(time(0));
printf("Draw random rectangles.\n");
printf("Press ^C to stop.\n");
for (;;) {
x0 = random() % xsize;
y0 = random() % ysize;
x1 = random() % xsize;
y1 = random() % ysize;
color = random();
gpanel_rect(color, x0, y0, x1, y1);
}
return 0;
}

View File

@@ -15,9 +15,6 @@ srand(x)
int
rand()
{
#ifdef pdp11
return(((randx = randx * 1103515245 + 12345)>>16) & 0x7fff);
#else
return((randx = randx * 1103515245 + 12345) & 0x7fffffff);
#endif
randx = randx * 1103515245 + 12345;
return (randx >> 16) & 0x7fff;
}

View File

@@ -254,6 +254,15 @@ static void fillRectangle(int x0, int y0, int x1, int y1, int color)
{
int x, y;
if (x0 < 0) x0 = 0;
if (y0 < 0) x0 = 0;
if (x1 < 0) x1 = 0;
if (y1 < 0) x1 = 0;
if (x0 >= _width) x0 = _width-1;
if (x1 >= _width) x1 = _width-1;
if (y0 >= _height) y0 = _height-1;
if (y1 >= _height) y1 = _height-1;
if (x1 < x0) {
int t = x0;
x0 = x1;
@@ -264,12 +273,12 @@ static void fillRectangle(int x0, int y0, int x1, int y1, int color)
y0 = y1;
y1 = t;
}
setAddrWindow(x0, y0, x1-1, y1-1);
setAddrWindow(x0, y0, x1, y1);
while (PMMODE & PIC32_PMMODE_BUSY);
PMADDR = 0x0001;
for (y=y0; y<y1; y++) {
for (x=x0; x<x1; x++) {
for (y=y0; y<=y1; y++) {
for (x=x0; x<=x1; x++) {
while (PMMODE & PIC32_PMMODE_BUSY);
PMDIN = color;
}