diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-06-03 23:12:38 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-06-03 23:12:38 +0200 |
commit | 5361f2ec6415d35615c2be1fca4bae94235b1b8c (patch) | |
tree | 5c2af8f91ed1ff859f933d08961db9f076e1c816 | |
parent | first prototype is working (diff) |
added simple blink commands to firmware
-rw-r--r-- | firmware/Makefile | 5 | ||||
-rw-r--r-- | firmware/blinkyfications.cpp | 46 |
2 files changed, 42 insertions, 9 deletions
diff --git a/firmware/Makefile b/firmware/Makefile index 877a90b..a5a6d44 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -22,7 +22,7 @@ NAME := blinkyfications BOARD_TYPE := minimus32 CXX_OBJ := $(NAME).o -LIBS := util led lufa-descriptor-usbserial usbio +LIBS := util lufa-descriptor-usbserial usbio CXX_LIBS := arduino-stub EXTERNAL_LIBS := fastled lufa SPREADAVR_PATH := ../contrib/avr-utils @@ -46,3 +46,6 @@ LUFA_OPTS += -D USB_PRODUCT="L\"blinkyfications\"" LUFA_COMPONENTS := USB USBCLASS include $(SPREADAVR_PATH)/include.mk + +RESET_FUNC := $(SPREADAVR_PATH)/tools/reset_lufa_cdc +RESET_PARAM := '!' diff --git a/firmware/blinkyfications.cpp b/firmware/blinkyfications.cpp index 1fc1e84..ffb4654 100644 --- a/firmware/blinkyfications.cpp +++ b/firmware/blinkyfications.cpp @@ -26,7 +26,6 @@ #include <stdio.h> #include "util.h" -#include "led.h" #include "usbio.h" #include "Arduino.h" @@ -36,6 +35,8 @@ #define NUM_LEDS 8 #define DATA_PIN 1 // PB1 @ Atmega32U2 +#define _10MS_ ((uint16_t)625) // 10ms @ 16MHz / Prescaler 1:256 + CRGB leds[NUM_LEDS]; void fastled_init() @@ -44,16 +45,45 @@ void fastled_init() FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); } +void timer_init() +{ + TCCR1A = 0; + TCCR1B = 0; + TCCR1C = 0; + + OCR1A = 0xFFFF; + TCNT1 = 0; + TIMSK1 = (1 << OCIE1A); +} + +void timer_start(uint16_t timeout) +{ + OCR1A = timeout; + TCNT1 = 0; + TCCR1B = (1 << CS12); +} + +ISR(TIMER1_COMPA_vect) +{ + TCCR1B = 0; + fill_solid(leds, NUM_LEDS, CRGB::Black); + FastLED.show(); +} void handle_cmd(uint8_t cmd) { switch(cmd) { - case '0': fill_solid(leds, NUM_LEDS, CRGB::Black); FastLED.show(); led_off(); break; - case '1': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); led_on(); break; - case 'r': fill_solid(leds, NUM_LEDS, CRGB::Red); FastLED.show(); led_on(); break; - case 'g': fill_solid(leds, NUM_LEDS, CRGB::Green); FastLED.show(); led_on(); break; - case 'b': fill_solid(leds, NUM_LEDS, CRGB::Blue); FastLED.show(); led_on(); break; - case 'w': fill_rainbow(leds, NUM_LEDS, 0, 256/NUM_LEDS); FastLED.show(); led_on(); break; + case '0': fill_solid(leds, NUM_LEDS, CRGB::Black); FastLED.show(); break; + case '1': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); break; + case 'r': fill_solid(leds, NUM_LEDS, CRGB::Red); FastLED.show(); break; + case 'g': fill_solid(leds, NUM_LEDS, CRGB::Green); FastLED.show(); break; + case 'b': fill_solid(leds, NUM_LEDS, CRGB::Blue); FastLED.show(); break; + case 'w': fill_rainbow(leds, NUM_LEDS, 0, 256/NUM_LEDS); FastLED.show(); break; + + case '.': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); timer_start(10 * _10MS_); break; + case 'o': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); timer_start(30 * _10MS_); break; + case 'O': fill_solid(leds, NUM_LEDS, CRGB::White); FastLED.show(); timer_start(100 * _10MS_); break; + case '!': reset2bootloader(); break; default: printf("error\r\n"); return; } @@ -66,11 +96,11 @@ int main(void) wdt_disable(); cpu_init(); - led_init(); usbio_init(); fastled_init(); sei(); + timer_init(); fill_solid(leds, NUM_LEDS, CRGB::Black); FastLED.show(); for(;;) { |