Skip to content

Commit

Permalink
Fix mapping for new LEDscape board, fix bug in matrix-udp-rx
Browse files Browse the repository at this point in the history
  • Loading branch information
cibomahto committed Aug 22, 2014
1 parent 8bf74ee commit bd89120
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 128 deletions.
26 changes: 17 additions & 9 deletions src/demos/matrix-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ rainbow(
)
{
const unsigned color = cycle % 180;
const unsigned dim = 127;
const unsigned dim = 128;

static unsigned count = 0;

count += 1;

for (unsigned x=0; x < width; x++) {
for (unsigned y=0; y < height; y++) {
Expand All @@ -110,12 +114,16 @@ rainbow(
out[1] = ((in >> 8) & 0xFF) * dim / 128; // * y / 16;
out[2] = ((in >> 16) & 0xFF) * dim / 128; // * y / 16;
#else
//out[0] = ((in >> 0) & 0xFF);
//out[1] = ((in >> 8) & 0xFF);
//out[2] = ((in >> 16) & 0xFF);
out[0] = y + 3*x + cycle;
out[1] = y + 3*x + cycle;
out[2] = y + 3*x + cycle;
if(y==((count >> 3) & 0x1F) && x<20) {
out[0] = 0xff;
out[1] = 0xff;
out[2] = 0x00;
}
else {
out[0] = 0x00;
out[1] = 0x00;
out[2] = 0xff;
}
#endif
}
}
Expand Down Expand Up @@ -194,8 +202,8 @@ main(
{
// int width = 240; // 256;
// int height = 64; //128;
int width = 256;
int height = 128;
int width = 135;
int height = 32;

ledscape_config_t * config = &ledscape_matrix_default;
if (argc > 1)
Expand Down
7 changes: 2 additions & 5 deletions src/ledscape/ledscape.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,9 @@ ledscape_strip_draw(
uint8_t * const row_out
= ledscape_remap(leds, out, x, y);
uint32_t p = row_in[x];
row_out[0*pru_stride] = 0xFF; // green
row_out[1*pru_stride] = 0x00; // red
row_out[2*pru_stride] = 0x00; // blue
row_out[0*pru_stride] = (p >> 8) & 0xFF; // green
row_out[1*pru_stride] = (p >> 0) & 0xFF; // red
row_out[2*pru_stride] = (p >> 16) & 0xFF; // blue
row_out[1*pru_stride] = (p >> 16) & 0xFF; // red
row_out[2*pru_stride] = (p >> 0) & 0xFF; // blue
}
}

Expand Down
160 changes: 86 additions & 74 deletions src/ledscape/ws281x.p
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
*
*/

// while len > 0:
// for bit# = 24 down to 0:
// delay 600 ns
// read 16 registers of data, build zero map for gpio0
// read 10 registers of data, build zero map for gpio1
// read 5 registers of data, build zero map for gpio3
//
// Send start pulse on all pins on gpio0, gpio1 and gpio3
// delay 250 ns
// bring zero pins low
// delay 300 ns
// bring all pins low
// increment address by 32
// while len > 0:
// for bit# = 24 down to 0:
// delay 600 ns
// read 16 registers of data, build zero map for gpio0
// read 10 registers of data, build zero map for gpio1
// read 5 registers of data, build zero map for gpio3
//
// Send start pulse on all pins on gpio0, gpio1 and gpio3
// delay 250 ns
// bring zero pins low
// delay 300 ns
// bring all pins low
// increment address by 32

//*
//* So to clock this out:
Expand All @@ -46,80 +46,80 @@
//*
//*/

#define r11_gpio 2
#define r11_pin 1
#define g11_gpio 0
#define g11_pin 27
#define b11_gpio 2
#define b11_pin 2
#define r11_gpio 0
#define r11_pin 27
#define g11_gpio 2
#define g11_pin 1
#define b11_gpio 1
#define b11_pin 14

#define r12_gpio 2
#define r12_pin 3
#define r12_gpio 1
#define r12_pin 15
#define g12_gpio 0
#define g12_pin 20
#define b12_gpio 3
#define b12_pin 16

#define r21_gpio 3
#define r21_pin 19
#define g21_gpio 0
#define g21_pin 14
#define b21_gpio 3
#define b21_pin 21

#define r22_gpio 0
#define r22_pin 15
#define g22_gpio 1
#define g22_pin 17
#define b22_gpio 0
#define g12_pin 23
#define b12_gpio 0
#define b12_pin 26

#define r21_gpio 1
#define r21_pin 12
#define g21_gpio 1
#define g21_pin 13
#define b21_gpio 2
#define b21_pin 5

#define r22_gpio 2
#define r22_pin 4
#define g22_gpio 2
#define g22_pin 3
#define b22_gpio 2
#define b22_pin 2

#define r31_gpio 1
#define r31_pin 15
#define r31_gpio 3
#define r31_pin 16
#define g31_gpio 0
#define g31_pin 3
#define b31_gpio 2
#define b31_pin 22
#define g31_pin 20
#define b31_gpio 0
#define b31_pin 14

#define r32_gpio 2
#define r32_pin 24
#define r32_gpio 3
#define r32_pin 19
#define g32_gpio 0
#define g32_pin 4
#define b32_gpio 0
#define b32_pin 5
#define g32_pin 15
#define b32_gpio 3
#define b32_pin 21

#define r41_gpio 1
#define r41_pin 19
#define r41_gpio 0
#define r41_pin 2
#define g41_gpio 1
#define g41_pin 16
#define b41_gpio 1
#define b41_pin 18
#define g41_pin 17
#define b41_gpio 2
#define b41_pin 22

#define r42_gpio 0
#define r42_pin 31
#define g42_gpio 1
#define g42_pin 28
#define b42_gpio 1
#define b42_pin 14

#define r51_gpio 0
#define r51_pin 30
#define g51_gpio 1
#define g51_pin 29
#define b51_gpio 0
#define b51_pin 26

#define r52_gpio 0
#define r52_pin 23
#define r42_pin 3
#define g42_gpio 0
#define g42_pin 4
#define b42_gpio 2
#define b42_pin 24

#define r51_gpio 1
#define r51_pin 19
#define g51_gpio 0
#define g51_pin 5
#define b51_gpio 1
#define b51_pin 18

#define r52_gpio 1
#define r52_pin 16
#define g52_gpio 1
#define g52_pin 13
#define b52_gpio 1
#define b52_pin 12
#define g52_pin 28
#define b52_gpio 0
#define b52_pin 31

#define r61_gpio 2
#define r61_pin 4
#define g61_gpio 2
#define g61_pin 5
#define r61_gpio 1
#define r61_pin 29
#define g61_gpio 0
#define g61_pin 30

// Note: From here down, these are garbage, we only have 32 outputs.
#define b61_gpio 0
Expand Down Expand Up @@ -240,6 +240,17 @@ lab:

#define GPIO(R) CAT3(gpio,R,_zeros)

// Output the current bit for three LED strip outputs
// Note that this nomenclature was ported from the matrix code, and is
// mostly nonsense when applied to the strip code.
// Parameters:
// N: Output group to consider (11, 12, 21, ... 82)
// reg_r: register byte to read first strip data from (ex: r10.b0)
// reg_g: register byte to read second strip data from (ex: r10.b1)
// reg_b: register byte to read third strip data from (ex: r10.b2)
//
// Parameters from the environment:
// bit_num: current bit we're reading from
#define OUTPUT_ROW(N,reg_r,reg_g,reg_b) \
QBBS skip_r##N, reg_r, bit_num; \
SET GPIO(r##N##_gpio), r##N##_pin; \
Expand Down Expand Up @@ -278,6 +289,7 @@ START:
MOV r2, #0x1
SBCO r2, CONST_PRUDRAM, 12, 4

SET GPIO_MASK(r11_gpio), r11_pin
SET GPIO_MASK(g11_gpio), g11_pin
SET GPIO_MASK(b11_gpio), b11_pin
SET GPIO_MASK(r12_gpio), r12_pin
Expand Down
57 changes: 18 additions & 39 deletions src/net/matrix-udp-rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ main(
break;
case 'H':
height = atoi(optarg);
if(height%2) {
die("Height must be even!\n");
}
break;
case 'm':
startup_message = optarg;
Expand All @@ -146,13 +149,11 @@ main(
die("socket port %d failed: %s\n", port, strerror(errno));

const size_t image_size = width * height * 3;
const size_t frame_size = 1 + image_size/2;

// largest possible UDP packet
uint8_t *buf = calloc(width*height,4);
#if 0
if (sizeof(buf) < image_size + 1)
die("%u x %u too large for UDP\n", width, height);
#endif
// 1 header byte + width*height/2 for a half frame
uint8_t *buf = calloc(frame_size,1);

fprintf(stderr, "%u x %u, UDP port %u\n", width, height, port);

Expand Down Expand Up @@ -185,6 +186,7 @@ main(
ledscape_printf(fb, width, 0xFF0000, "%s", startup_message);
ledscape_printf(fb+16*width, width, 0x00FF00, "%dx%d UDP port %d", width, height, port);
ledscape_draw(leds, fb);
ledscape_draw(leds, fb); // TODO: Why do we have to do this twice?

while (1)
{
Expand All @@ -207,63 +209,40 @@ main(
continue;
}

const ssize_t rlen = recv(sock, buf, sizeof(buf), 0);
const ssize_t rlen = recv(sock, buf, frame_size, 0);
if (rlen < 0)
die("recv failed: %s\n", strerror(errno));
warn_once("received %zu bytes\n", rlen);

/*
if (buf[0] == 2)
{
// image type
printf("image type: %.*s\n",
(int) rlen - 1,
&buf[1]
);
continue;
}
if (buf[0] != 1)
{
// What is it?
warn_once("Unknown image type '%c' (%02x)\n",
buf[0],
buf[0]
);
continue;
}
*/
const unsigned frame_part = buf[0];
if (frame_part != 0 && frame_part != 1)
{
printf("bad type %d\n", frame_part);
continue;
}

if ((size_t) rlen != image_size + 1)
if ((size_t) rlen != frame_size)
{
warn_once("WARNING: Received packet %zu bytes, expected %zu\n",
printf("WARNING: Received packet %zu bytes, expected %zu\n",
rlen,
image_size + 1
frame_size
);
}

struct timeval start_tv, stop_tv, delta_tv;
gettimeofday(&start_tv, NULL);

const unsigned frame_num = 0;

// copy the 3-byte values into the 4-byte framebuffer
// and turn onto the side
for (unsigned x = 0 ; x < width ; x++) // 256
{
for (unsigned y = 0 ; y < 32 ; y++) // 64
for (unsigned y = 0 ; y < height ; y++) // 64
{
uint32_t * out = (void*) &fb[(y+32*frame_part)*width + x];
const uint8_t * const in = &buf[1 + 3*(y*width + x)];
uint32_t r = in[0];
uint32_t g = in[1];
uint32_t b = in[2];
uint32_t * out = &fb[(height*frame_part + y)*width + x];
const uint8_t * in = &buf[1 + 3*(y*width + x)];

uint8_t r = in[0];
uint8_t g = in[1];
uint8_t b = in[2];
*out = (r << 16) | (g << 8) | (b << 0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion strips.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ws2812
240,48
240,32

0 comments on commit bd89120

Please sign in to comment.