Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
teachop committed Mar 10, 2014
0 parents commit 66c35b6
Show file tree
Hide file tree
Showing 6 changed files with 1,088 additions and 0 deletions.
842 changes: 842 additions & 0 deletions .cproject

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.build*
.settings
bin

79 changes: 79 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>xcore_neopixel_buffered</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>?children?</key>
<value>?name?=outputEntries\|?children?=?name?=entry\\\\\\\|\\\|\||</value>
</dictionary>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value>CONFIG=Release</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>xmake</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
<value>clean</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.environment</key>
<value>XTA_ENABLED=false|</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>false</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>com.xmos.cdt.core.XdeProjectNature</nature>
</natures>
</projectDescription>
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# The TARGET variable determines what target system the application is
# compiled for. It either refers to an XN file in the source directories
# or a valid argument for the --target option when compiling
TARGET = STARTKIT

# The APP_NAME variable determines the name of the final .xe file. It should
# not include the .xe postfix. If left blank the name will default to
# the project name
APP_NAME = xcore_neopixel_buffered

# The USED_MODULES variable lists other module used by the application.
USED_MODULES =

# The flags passed to xcc when building the application
# You can also set the following to override flags for a particular language:
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
XCC_FLAGS_Debug = -O0 -g
XCC_FLAGS_Release = -O2 -g

# The VERBOSE variable, if set to 1, enables verbose output from the make system.
VERBOSE = 0

XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Buffered Driver for NeoPixels

This repo is a driver to output arrays of color pixel data to multiple NeoPixel strips. In this test, the data is fully generated into a buffer before writing to the strip. Eight copies of the generator / writer task output to 8 strips.



129 changes: 129 additions & 0 deletions neopixel_buffered.xc
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//---------------------------------------------------------
// Buffered NeoPixel driver
// by teachop
//

#include <xs1.h>
#include <timer.h>


// length of the strip(s)
#define LEDS 60


// ------------------------------------------------------------
// grbColor - convert separate R,G,B into a neopixel color word
//
unsigned int grbColor(unsigned char r, unsigned char g, unsigned char b) {
return ((unsigned int)g << 16) | ((unsigned int)r << 8) | b;
}


// ---------------------------------------------------------
// wheel - input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r
//
unsigned int wheel(unsigned char wheelPos) {
if ( wheelPos < 85 ) {
return grbColor(wheelPos * 3, 255 - wheelPos * 3, 0);
} else if ( wheelPos < 170 ) {
wheelPos -= 85;
return grbColor(255 - wheelPos * 3, 0, wheelPos * 3);
} else {
wheelPos -= 170;
return grbColor(0, wheelPos * 3, 255 - wheelPos * 3);
}
}


// ---------------------------------------------------------
// neopixel_led_driver - output driver for one neopixel strip
//
void neopixel_led_driver(port neo, unsigned int (&colors)[]) {
const unsigned int delay_third = 42;
unsigned int delay_count;
unsigned int color_shift;
unsigned int bit;

// beginning of strip, resync counter
neo <: 0 @ delay_count;
delay_count += delay_third;

for ( unsigned int pixel=0; pixel<LEDS; ++pixel ) {
color_shift = colors[pixel];
unsigned int bit_count = 24;
while (bit_count--) {
// output low->high transition
delay_count += delay_third;
neo @ delay_count <: 1;

// output high->data transition
bit = (color_shift & 0x800000)? 1 : 0;
color_shift <<=1;
delay_count += delay_third;
neo @ delay_count <: bit;

// output data->low transition
delay_count += delay_third;
neo @ delay_count <: 0;
}
}

}


// ---------------------------------------------------------------
// blinky_task - rainbow cycle pattern from pjrc and / or adafruit
//
void blinky_task(port neo, unsigned int strip) {
unsigned int colors[LEDS];
timer tick;
unsigned int next_pass;
unsigned int loop, outer;

while (1) {
for ( outer=0; outer<256; ++outer) {
// cycle of all colors on wheel
for ( loop=0; loop<LEDS; ++loop) {
// emit data to the driver
colors[loop] = wheel(( (loop*256/LEDS) + outer) & 255);
}

// write to the strip
neopixel_led_driver(neo, colors);

// wait a bit, must allow strip to latch at least
tick :> next_pass;
next_pass += (50+strip*500)*100;
tick when timerafter(next_pass) :> void;
}
}
}


// ---------------------------------------------------------
// main - xCore startKIT NeoPixel blinky test
//
port out_pin[8] = {
// j7.1, j7.2, j7.3, j7.4
XS1_PORT_1F, XS1_PORT_1H, XS1_PORT_1G, XS1_PORT_1E,
// j7.23, j7.21, j7.20, j7.19
XS1_PORT_1P, XS1_PORT_1O, XS1_PORT_1I, XS1_PORT_1L
};
int main() {

par {
// 8 led strips
blinky_task(out_pin[0], 0);
blinky_task(out_pin[1], 1);
blinky_task(out_pin[2], 2);
blinky_task(out_pin[3], 3);
blinky_task(out_pin[4], 4);
blinky_task(out_pin[5], 5);
blinky_task(out_pin[6], 6);
blinky_task(out_pin[7], 7);
}

return 0;
}

0 comments on commit 66c35b6

Please sign in to comment.