Added demos for LED cube 8x8x8.
This commit is contained in:
@@ -31,3 +31,21 @@ float ldexpf(float x, int exp);
|
|||||||
double ldexp(double x, int exp);
|
double ldexp(double x, int exp);
|
||||||
|
|
||||||
double fmod(double x, double y);
|
double fmod(double x, double y);
|
||||||
|
|
||||||
|
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
|
||||||
|
|
||||||
|
#define M_E 2.7182818284590452354 /* e */
|
||||||
|
#define M_LOG2E 1.4426950408889634074 /* log 2e */
|
||||||
|
#define M_LOG10E 0.43429448190325182765 /* log 10e */
|
||||||
|
#define M_LN2 0.69314718055994530942 /* log e2 */
|
||||||
|
#define M_LN10 2.30258509299404568402 /* log e10 */
|
||||||
|
#define M_PI 3.14159265358979323846 /* pi */
|
||||||
|
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
||||||
|
#define M_PI_4 0.78539816339744830962 /* pi/4 */
|
||||||
|
#define M_1_PI 0.31830988618379067154 /* 1/pi */
|
||||||
|
#define M_2_PI 0.63661977236758134308 /* 2/pi */
|
||||||
|
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
|
||||||
|
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||||
|
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||||
|
|
||||||
|
#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
|
||||||
|
|||||||
@@ -787,6 +787,19 @@ file /share/examples/sensors/pbuzz.c
|
|||||||
file /share/examples/sensors/relay.c
|
file /share/examples/sensors/relay.c
|
||||||
file /share/examples/sensors/relay.sh
|
file /share/examples/sensors/relay.sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Files: /share/examples/cube
|
||||||
|
#
|
||||||
|
dir /share/examples/cube
|
||||||
|
file /share/examples/cube/Makefile
|
||||||
|
file /share/examples/cube/README.txt
|
||||||
|
file /share/examples/cube/all.c
|
||||||
|
file /share/examples/cube/backlight.c
|
||||||
|
file /share/examples/cube/cube.c
|
||||||
|
file /share/examples/cube/cube.h
|
||||||
|
file /share/examples/cube/demo.c
|
||||||
|
file /share/examples/cube/gpio.c
|
||||||
|
|
||||||
#
|
#
|
||||||
# Files: /var
|
# Files: /var
|
||||||
#
|
#
|
||||||
|
|||||||
19
share/examples/cube/Makefile
Normal file
19
share/examples/cube/Makefile
Normal 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)
|
||||||
16
share/examples/cube/Makefile-host
Normal file
16
share/examples/cube/Makefile-host
Normal 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 *~
|
||||||
1
share/examples/cube/README.txt
Normal file
1
share/examples/cube/README.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Examples for LED cube 8x8x8.
|
||||||
25
share/examples/cube/all.c
Normal file
25
share/examples/cube/all.c
Normal 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;
|
||||||
|
}
|
||||||
20
share/examples/cube/backlight.c
Normal file
20
share/examples/cube/backlight.c
Normal 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;
|
||||||
|
}
|
||||||
BIN
share/examples/cube/board.jpg
Normal file
BIN
share/examples/cube/board.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
73
share/examples/cube/cube.c
Normal file
73
share/examples/cube/cube.c
Normal 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;
|
||||||
|
}
|
||||||
13
share/examples/cube/cube.h
Normal file
13
share/examples/cube/cube.h
Normal 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
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
131
share/examples/cube/gpio.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
share/examples/cube/schematic.jpg
Normal file
BIN
share/examples/cube/schematic.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 264 KiB |
Reference in New Issue
Block a user