summaryrefslogtreecommitdiff
path: root/usb-fastled
diff options
context:
space:
mode:
Diffstat (limited to 'usb-fastled')
-rw-r--r--usb-fastled/Makefile50
-rw-r--r--usb-fastled/usb-fastled.cpp131
2 files changed, 181 insertions, 0 deletions
diff --git a/usb-fastled/Makefile b/usb-fastled/Makefile
new file mode 100644
index 0000000..03d2c7e
--- /dev/null
+++ b/usb-fastled/Makefile
@@ -0,0 +1,50 @@
+##
+## spreadspace avr utils
+##
+##
+## Copyright (C) 2013-2015 Christian Pointner <equinox@spreadspace.org>
+##
+## This file is part of spreadspace avr utils.
+##
+## spreadspace avr utils 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 3 of the License, or
+## any later version.
+##
+## spreadspace avr utils is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+##
+
+NAME := usb-fastled
+BOARD_TYPE := teensy2
+CXX_OBJ := $(NAME).o
+LIBS := util led lufa-descriptor-usbserial usbio
+CXX_LIBS := arduino-stub
+EXTERNAL_LIBS := fastled lufa
+SPREADAVR_PATH := ..
+RESET_FUNC := $(SPREADAVR_PATH)/tools/reset_lufa_cdc
+RESET_PARAM := '!'
+
+FASTLED_PATH := $(SPREADAVR_PATH)/contrib/FastLED
+
+LUFA_PATH := $(SPREADAVR_PATH)/contrib/lufa-LUFA-140928
+LUFA_OPTS = -D USB_DEVICE_ONLY
+LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
+LUFA_OPTS += -D ORDERED_EP_CONFIG
+LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
+LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
+LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
+LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
+LUFA_OPTS += -D INTERRUPT_CONTROL_ENDPOINT
+
+LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\""
+LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-fastled example\""
+
+LUFA_COMPONENTS := USB USBCLASS
+
+include $(SPREADAVR_PATH)/include.mk
diff --git a/usb-fastled/usb-fastled.cpp b/usb-fastled/usb-fastled.cpp
new file mode 100644
index 0000000..429e8f5
--- /dev/null
+++ b/usb-fastled/usb-fastled.cpp
@@ -0,0 +1,131 @@
+/*
+ * spreadspace avr utils
+ *
+ *
+ * Copyright (C) 2013-2015 Christian Pointner <equinox@spreadspace.org>
+ *
+ * This file is part of spreadspace avr utils.
+ *
+ * spreadspace avr utils 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 3 of the License, or
+ * any later version.
+ *
+ * spreadspace avr utils is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with spreadspace avr utils. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <avr/io.h>
+#include <avr/wdt.h>
+#include <avr/interrupt.h>
+#include <avr/power.h>
+#include <stdio.h>
+
+#include "util.h"
+#include "led.h"
+#include "usbio.h"
+
+#include "Arduino.h"
+#include "FastLED.h"
+
+
+
+
+// How many leds in your strip?
+#define NUM_LEDS 30
+
+// For led chips like Neopixels, which have a data line, ground, and power, you just
+// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
+// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
+#define DATA_PIN 3 // PD0 @ Atmega32U4
+#define CLOCK_PIN 2 // PD1 @ Atmega32U4
+
+// Define the array of leds
+CRGB leds[NUM_LEDS];
+
+void fastled_init()
+{
+ arduino_init();
+
+// Uncomment/edit one of the following lines for your leds arrangement.
+// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
+ FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
+// FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
+// FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
+
+// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);
+
+// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
+// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
+}
+
+
+void leds_set(CRGB color)
+{
+ uint8_t i;
+ for(i = 0; i < NUM_LEDS; ++i) {
+ leds[i] = color;
+ }
+ FastLED.show();
+}
+
+void handle_cmd(uint8_t cmd)
+{
+ switch(cmd) {
+ case '0': leds_set(CRGB::Black); led_off(); break;
+ case '1': leds_set(CRGB::White); led_on(); break;
+ case 'r': leds_set(CRGB::Red); led_on(); break;
+ case 'g': leds_set(CRGB::Green); led_on(); break;
+ case 'b': leds_set(CRGB::Blue); led_on(); break;
+ case '!': reset2bootloader(); break;
+ default: printf("error\r\n"); return;
+ }
+ printf("ok\r\n");
+}
+
+int main(void)
+{
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ cpu_init();
+ led_init();
+ usbio_init();
+ fastled_init();
+ sei();
+
+ for(;;) {
+ int16_t BytesReceived = usbio_bytes_received();
+ while(BytesReceived > 0) {
+ int ReceivedByte = fgetc(stdin);
+ if(ReceivedByte != EOF) {
+ handle_cmd(ReceivedByte);
+ }
+ BytesReceived--;
+ }
+
+ usbio_task();
+ }
+}