Added demos for LED cube 8x8x8.

This commit is contained in:
Sergey
2015-05-17 22:39:30 -07:00
parent 352d23a073
commit 7590783d92
13 changed files with 3447 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
PROG = all backlight cube demo
OBJS = gpio.o
all: $(PROG)
all: all.c $(OBJS)
cc $@.c $(OBJS) -o $@
backlight: backlight.c $(OBJS)
cc $@.c $(OBJS) -o $@
cube: cube.c $(OBJS)
cc $@.c $(OBJS) -o $@
demo: demo.c $(OBJS)
cc $@.c $(OBJS) -o $@
clean:
rm -f *.o *~ $(PROG)

View File

@@ -0,0 +1,16 @@
TOPSRC = $(shell cd ../../..; pwd)
include $(TOPSRC)/target.mk
CFLAGS += -Werror
LIBS += -lm
#all: demo
demo: demo.o gpio.o
${CC} ${LDFLAGS} -o demo.elf demo.o gpio.o ${LIBS}
${OBJDUMP} -S demo.elf > demo.dis
${SIZE} demo.elf
${ELF2AOUT} demo.elf $@
clean:
rm -f *.o *.elf ${MAN} demo *.elf *.dis tags *~

View File

@@ -0,0 +1 @@
Examples for LED cube 8x8x8.

25
share/examples/cube/all.c Normal file
View File

@@ -0,0 +1,25 @@
/*
* Demo for LED cube 8x8x8.
* Turn on all LEDs.
*/
#include <stdio.h>
#include "cube.h"
int main()
{
static unsigned char data[8] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
int i;
gpio_init();
gpio_le(0);
gpio_plane(data);
gpio_ext(1);
for (;;) {
for (i=0; i<8; i++) {
gpio_layer(i);
}
}
return 0;
}

View File

@@ -0,0 +1,20 @@
/*
* Demo for LED cube 8x8x8.
* Test backlight LEDs.
*/
#include <stdio.h>
#include "cube.h"
int main()
{
gpio_init();
for (;;) {
gpio_backlight_upper(1);
usleep(500000);
gpio_backlight_upper(0);
gpio_backlight_lower(1);
usleep(500000);
gpio_backlight_lower(0);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -0,0 +1,73 @@
/*
* Demo for LED cube 8x8x8.
* Switch between two static images.
*/
#include <stdio.h>
#include <sys/time.h>
#include "cube.h"
void display(int duration, unsigned char *data)
{
struct timeval t0, now;
int z, msec;
gettimeofday(&t0, 0);
z = 0;
for (;;) {
/* Send layer data. Latch is active,
* so previous layer is still displayed. */
gpio_plane(data + z*CUBE_SIZE);
/* Disable output, activate latch,
* switch to next layer. */
gpio_oe(0);
gpio_le(0);
gpio_le(1);
gpio_layer(z);
gpio_oe(1);
/* Next layer. */
z++;
if (z >= CUBE_SIZE) {
z = 0;
/* Check time. */
gettimeofday(&now, 0);
msec = (now.tv_sec - t0.tv_sec) * 1000;
msec += (now.tv_usec - t0.tv_usec) / 1000;
if (msec >= duration)
break;
}
}
}
int main()
{
static unsigned char foo[64] = {
0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff,
0x81, 0, 0, 0, 0, 0, 0, 0x81,
0x81, 0, 0, 0, 0, 0, 0, 0x81,
0x81, 0, 0, 0, 0, 0, 0, 0x81,
0x81, 0, 0, 0, 0, 0, 0, 0x81,
0x81, 0, 0, 0, 0, 0, 0, 0x81,
0x81, 0, 0, 0, 0, 0, 0, 0x81,
0xff, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xff,
};
static unsigned char bar[64] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e, 0,
0, 0x42, 0, 0, 0, 0, 0x42, 0,
0, 0x42, 0, 0, 0, 0, 0x42, 0,
0, 0x42, 0, 0, 0, 0, 0x42, 0,
0, 0x42, 0, 0, 0, 0, 0x42, 0,
0, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
gpio_init();
gpio_ext(1);
for (;;) {
display(500, foo);
display(500, bar);
}
return 0;
}

View File

@@ -0,0 +1,13 @@
/*
* Interface to LED cube 8x8x8.
*/
#define CUBE_SIZE 8
void gpio_init(void);
void gpio_ext(int on);
void gpio_oe(int active);
void gpio_le(int active);
void gpio_backlight_upper(int on);
void gpio_backlight_lower(int on);
void gpio_layer(int z);
void gpio_plane(unsigned char *data);

3118
share/examples/cube/demo.c Normal file

File diff suppressed because it is too large Load Diff

131
share/examples/cube/gpio.c Normal file
View File

@@ -0,0 +1,131 @@
/*
* Interface to LED cube 8x8x8.
* The cube is connected to D0-D9 pin of Duinomite board.
*
* Pin PIC32 Function
* ---------------
* D0 RE0 Y0 \
* D1 RE1 Y1 | Layer select
* D2 RE2 Y2 /
* D3 RE3 Y3 - Upper backlignt
* D4 RE4 Y4 - Lower backlight
* D5 RE5 SDI - Serial data \
* D6 RE6 CLK - Clock | to shift registers
* D7 RE7 /LE - Latch enable |
* D8 RB11 /OE - Output enable /
* D10 RD11 EXT - Unknown
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/gpio.h>
#include "cube.h"
static int gpio;
void gpio_init()
{
char *devname = "/dev/porta";
/* Open GPIO driver. */
gpio = open(devname, 1);
if (gpio < 0) {
perror(devname);
exit(-1);
}
/* Configure pins RE0-RE7, RB11 and RD11 as output. */
ioctl(gpio, GPIO_PORTE | GPIO_CONFOUT, 0xff);
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 0xff);
ioctl(gpio, GPIO_PORTB | GPIO_CONFOUT, 1 << 11);
ioctl(gpio, GPIO_PORTB | GPIO_CLEAR, 1 << 11);
ioctl(gpio, GPIO_PORTD | GPIO_CONFOUT, 1 << 11);
ioctl(gpio, GPIO_PORTD | GPIO_CLEAR, 1 << 11);
}
void gpio_ext(int on)
{
/* EXT signal at RD11. */
if (on)
ioctl(gpio, GPIO_PORTD | GPIO_SET, 1 << 11);
else
ioctl(gpio, GPIO_PORTD | GPIO_CLEAR, 1 << 11);
}
void gpio_oe(int active)
{
/* /OE signal at RB11, active low. */
if (active)
ioctl(gpio, GPIO_PORTB | GPIO_CLEAR, 1 << 11);
else
ioctl(gpio, GPIO_PORTB | GPIO_SET, 1 << 11);
}
void gpio_le(int active)
{
/* /LE signal at RE7, active low. */
if (active)
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 7);
else
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 7);
}
void gpio_backlight_upper(int on)
{
/* Y4 signal at RE4. */
if (on)
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 4);
else
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 4);
}
void gpio_backlight_lower(int on)
{
/* Y3 signal at RE3. */
if (on)
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 3);
else
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 3);
}
void gpio_layer(int z)
{
/* Y0-Y2 signals at RE0-RE23. */
if (z & 1)
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 0);
else
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 0);
if (z & 2)
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 1);
else
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 1);
if (z & 4)
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 2);
else
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 2);
}
void gpio_plane(unsigned char *data)
{
int i, n, val;
/* Send 8 bytes of tada to shift registers. */
for (i=0; i<8; i++) {
val = *data++;
for (n=0; n<8; n++) {
/* SDI signal at RE5. */
if (val & 0x80)
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 5);
else
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 5);
/* CLK signal at RE6. */
ioctl(gpio, GPIO_PORTE | GPIO_SET, 1 << 6);
ioctl(gpio, GPIO_PORTE | GPIO_CLEAR, 1 << 6);
val <<= 1;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB