mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-24 00:20:38 +02:00
ubb-vga2: move image generation out of the main program
- ubb-vga2.c (session, grab): made the frame buffer "void *" and pass frame buffer resolution - ubb-vga.h: color encoding and items shared between compilation units - ubb-vga2.c (thres, pattern, grab), grabfb.c: move to grabfb.c - ubb-vga2.c (map): make global, for use by grabfb.c - ubb-vga2.c (pick, pattern, tricolor, grid): removed obsolete test image generators - Makefile (OBJS, ubb-vga2): added grabfb.o - Makefile (clean): remove only .o files - Makefile (spotless): remove only executables
This commit is contained in:
parent
625d9877ab
commit
8643e457fa
@ -2,11 +2,14 @@
|
||||
CC=mipsel-linux-gcc
|
||||
|
||||
CFLAGS=-Wall -g -O9 -march=mips32
|
||||
OBJS=ubb-vga2.o grabfb.o
|
||||
|
||||
.PHONY: all asm sch clean spotless
|
||||
|
||||
all: ubb-vga ubb-vga2
|
||||
|
||||
ubb-vga2: $(OBJS)
|
||||
|
||||
asm: ubb-vga.c
|
||||
$(CC) $(CFLAGS) -S $<
|
||||
|
||||
@ -14,6 +17,7 @@ sch:
|
||||
eeschema `pwd`/ubb-vga.sch
|
||||
|
||||
clean:
|
||||
rm -f ubb-vga ubb-vga2
|
||||
rm -f $(OBJS)
|
||||
|
||||
spotless: clean
|
||||
rm -f ubb-vga ubb-vga2
|
||||
|
51
ubb-vga/grabfb.c
Normal file
51
ubb-vga/grabfb.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* grabfb.c - Grab the Ben's main frame buffer
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "ubb-vga.h"
|
||||
|
||||
|
||||
uint8_t thres = 63;
|
||||
|
||||
|
||||
static uint8_t pattern(int r, int g, int b)
|
||||
{
|
||||
return ((r ? R_VAL : 0) | (g ? G_VAL : 0) | (b ? B_VAL : 0))*0x11;
|
||||
}
|
||||
|
||||
|
||||
void grabfb(void *f, int xres, int yres)
|
||||
{
|
||||
uint32_t *fb = map(0x01d00000, 4*320*240);
|
||||
uint8_t *p = f;
|
||||
int x, y;
|
||||
uint32_t pix;
|
||||
uint8_t r, g, b;
|
||||
|
||||
assert(xres == 640);
|
||||
assert(yres == 480);
|
||||
for (y = 0; y != 240; y++) {
|
||||
for (x = 0; x != 320; x++) {
|
||||
pix = *fb++;
|
||||
r = pix >> 16;
|
||||
g = pix >> 8;
|
||||
b = pix;
|
||||
p[0] = p[320] =
|
||||
pattern(r >= thres, g >= thres, b >= thres);
|
||||
p++;
|
||||
}
|
||||
p += 320;
|
||||
}
|
||||
}
|
33
ubb-vga/ubb-vga.h
Normal file
33
ubb-vga/ubb-vga.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* ubb-vga.h - Output video on UBB with more or less VGA timing
|
||||
*
|
||||
* Written 2011 by Werner Almesberger
|
||||
* Copyright 2011 Werner Almesberger
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef UBB_VGA_H
|
||||
#define UBB_VGA_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
#define R_VAL (1 << 3)
|
||||
#define G_VAL (1 << 0)
|
||||
#define B_VAL (1 << 1)
|
||||
#define Y_VAL (1 << 2)
|
||||
|
||||
|
||||
void *map(off_t addr, size_t size);
|
||||
|
||||
|
||||
extern uint8_t thres;
|
||||
|
||||
void grabfb(void *f, int xres, int yres);
|
||||
|
||||
#endif /* !UBB_VGA_H */
|
@ -34,8 +34,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "ubb-vga.h"
|
||||
|
||||
|
||||
static uint8_t thres = 63;
|
||||
static int bad;
|
||||
|
||||
/* ----- I/O pin assignment ------------------------------------------------ */
|
||||
@ -139,7 +140,7 @@ static void release_timer(void)
|
||||
}
|
||||
|
||||
|
||||
static void *map(off_t addr, size_t size)
|
||||
void *map(off_t addr, size_t size)
|
||||
{
|
||||
int fd;
|
||||
void *mem;
|
||||
@ -386,95 +387,6 @@ static void frame(const uint32_t *f)
|
||||
}
|
||||
|
||||
|
||||
/* ----- Frame buffer image generation ------------------------------------- */
|
||||
|
||||
|
||||
#if 0
|
||||
static uint32_t pick(int set, int bit, uint32_t val)
|
||||
{
|
||||
return set == bit ? val >> 8 : 0;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t pattern(int set, int r, int g, int b)
|
||||
{
|
||||
return pick(set, r, R) | pick(set, g, G) | pick(set, b, B);
|
||||
}
|
||||
|
||||
static void tricolor(uint32_t *f)
|
||||
{
|
||||
int pairs = 2*line_pairs*240;
|
||||
int i;
|
||||
|
||||
for (i = 0; i != pairs/3; i++) {
|
||||
f[i & ~1] = R;
|
||||
f[i | 1] = G | B;
|
||||
}
|
||||
for (; i != pairs*2/3; i++) {
|
||||
f[i & ~1] = G;
|
||||
f[i | 1] = R | B;
|
||||
}
|
||||
|
||||
for (; i != pairs; i++) {
|
||||
f[i & ~1] = B;
|
||||
f[i | 1] = R | G;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void grid(uint8_t *f)
|
||||
{
|
||||
static uint32_t col[8] = {
|
||||
R | G | B,
|
||||
R,
|
||||
R | G,
|
||||
G,
|
||||
G | B,
|
||||
B,
|
||||
R | B,
|
||||
R | G | B,
|
||||
};
|
||||
int i, x, y;
|
||||
|
||||
for (i = 0; i != 8; i++) {
|
||||
x = i*line_pairs/4+line_pairs/8;
|
||||
for (y = 0; y != 240; y++) {
|
||||
uint8_t *p = f+y*2*line_pairs+x;
|
||||
p[0] = p[1] = col[i] >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static uint8_t pattern(int r, int g, int b)
|
||||
{
|
||||
return (r ? 0x88 : 0) | (g ? 0x11 : 0) | (b ? 0x22 : 0);
|
||||
}
|
||||
|
||||
|
||||
static void grab(uint8_t *f)
|
||||
{
|
||||
uint32_t *fb = map(0x01d00000, 4*320*240);
|
||||
int x, y;
|
||||
uint32_t pix;
|
||||
uint8_t r, g, b;
|
||||
|
||||
for (y = 0; y != 240; y++) {
|
||||
for (x = 0; x != 320; x++) {
|
||||
pix = *fb++;
|
||||
r = pix >> 16;
|
||||
g = pix >> 8;
|
||||
b = pix;
|
||||
f[0] = f[320] =
|
||||
pattern(r >= thres, g >= thres, b >= thres);
|
||||
f++;
|
||||
}
|
||||
f += 320;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ----- Command-line parsing and main loop -------------------------------- */
|
||||
|
||||
|
||||
@ -484,7 +396,7 @@ static void session(int frames)
|
||||
int i;
|
||||
|
||||
memset(f, 0, sizeof(f));
|
||||
grab((uint8_t *) f);
|
||||
grabfb(f, 640, 480);
|
||||
// grid(f);
|
||||
|
||||
disable_interrupts();
|
||||
|
Loading…
Reference in New Issue
Block a user