diff --git a/client/test.c b/client/test.c index 5b3d1e3..d014092 100644 --- a/client/test.c +++ b/client/test.c @@ -26,6 +26,7 @@ respectively. #include "opendevice.h" /* common code moved to separate module */ +#include "../firmware/globals.h" /* custom request numbers */ #include "../firmware/requests.h" /* custom request numbers */ #include "../firmware/usbconfig.h" /* device's VID/PID and names */ @@ -65,7 +66,7 @@ void eeprom1() usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, high, 1, buffer, 0, 300); // save to position tmp - usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_EEPROM_STORE_FRAME, 0, tmp, buffer, 0, 300); + //usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_EEPROM_STORE_FRAME, 0, tmp, buffer, 0, 300); //usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_MODE, 1, 0, buffer, 0, 300); usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_MODE, 2, 0, buffer, 0, 300); @@ -73,17 +74,18 @@ void eeprom1() } -void sinus1() +void sinus1(int max) { usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_MODE, 0, 0, buffer, 0, 300); int low_last = 0; int high_last = 0; - int j = 0xf; + int j = max; while (--j) { + //int j = 0; int i = 0; for (i = 0; i < 360; i++) // for (i = 79; i < 90; i++) @@ -111,10 +113,14 @@ void sinus1() usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0, 0, buffer, 0, 300); } + // save the frame to eeprom + //usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_EEPROM_STORE_FRAME, 0, j, buffer, 0, 300); + high_last = high; low_last = low; usleep(2500); + //j++; } } @@ -165,7 +171,7 @@ void demo() sleep(30); // animate with a sinus wave - sinus1(); + sinus1(1); // start animation one time usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_MODE, 1, 0, buffer, 0, 300); @@ -207,6 +213,9 @@ int main(int argc, char **argv) #endif //usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_MODE, 2, 0, buffer, 0, 300); demo(); + //sinus1(255); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_MODE, 2, 0, buffer, 0, 300); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_DELAY, 10, 0, buffer, 0, 300); usb_close(handle); return 0; diff --git a/firmware/Makefile b/firmware/Makefile index a10c611..03e151e 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -200,8 +200,8 @@ AVRDUDE_PROGRAMMER = dragon_isp # com1 = serial port. Use lpt1 to connect to parallel port. AVRDUDE_PORT = -P usb #-P com1 # programmer connected to serial device -AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex -#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex:i +AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep:i # Uncomment the following if you want avrdude's erase cycle counter. @@ -297,7 +297,7 @@ build: elf hex eep lss sym elf: $(TARGET).elf hex: $(TARGET).hex -eep: $(TARGET).eep +#eep: $(TARGET).eep lss: $(TARGET).lss sym: $(TARGET).sym @@ -371,11 +371,11 @@ extcoff: $(TARGET).elf @echo $(MSG_FLASH) $@ $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ -%.eep: %.elf - @echo - @echo $(MSG_EEPROM) $@ - -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ - --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ +#%.eep: %.elf +# @echo +# @echo $(MSG_EEPROM) $@ +# -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ +# --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ # Create extended listing file from ELF output file. %.lss: %.elf @@ -427,7 +427,7 @@ clean_list : @echo @echo $(MSG_CLEANING) $(REMOVE) $(TARGET).hex - $(REMOVE) $(TARGET).eep + #$(REMOVE) $(TARGET).eep $(REMOVE) $(TARGET).obj $(REMOVE) $(TARGET).cof $(REMOVE) $(TARGET).elf diff --git a/firmware/globals.h b/firmware/globals.h index 80d9227..d24fafe 100644 --- a/firmware/globals.h +++ b/firmware/globals.h @@ -1,6 +1,6 @@ /* CTHN.de MiniLEDCube * - * Kai Lauterbach (klaute at web dot de) + * By Kai Lauterbach (klaute at web dot de) 11/2011 * * License: General Public License (GPL v3) * @@ -8,7 +8,10 @@ #define F_CPU 12000000UL -// Bitshifting -#define set_bit(var, bit) ((var) |= (1 << (bit))) -#define clear_bit(var, bit) ((var) &= (unsigned)~(1 << (bit))) +#define MODE_ANIMATION_STOP 0 +#define MODE_ANIMATION_SINGLE 1 +#define MODE_ANIMATION_LOOP 2 + +#define MAX_EEPROM_FRAMES 32 +#define STARTUP_DELAY_MAX 10 diff --git a/firmware/main.c b/firmware/main.c index 9beac36..67c1799 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -1,6 +1,7 @@ -/* CTHN.de MiniLEDCube +/* + * CTHN.de MiniLEDCube * - * Kai Lauterbach (klaute at web dot de) + * By Kai Lauterbach (klaute at web dot de) 11/2011 * * Based on http://mosfetkiller.de/?s=miniledcube * @@ -10,16 +11,14 @@ #include "main.h" -// Main +// Main loop int __attribute__((OS_main)) main() { - // Initialisierung + // Initialize the AVR and the USB connection. init(); init_usb(); - //frame = 0x07ffffff; - mode = 2; // Hauptschleife for (;;) @@ -31,74 +30,75 @@ main() // Initialisierung void init() { - // Ports vorbereiten - DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathoden) + // Init ports + DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathode) PORTB = 0b11111111; // HIGH DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden) PORTD = 0b01000000; - // Timer-Interrupt "TIMER1" vorbereiten + // Setup Timer-Interrupt "TIMER1" + TIMSK |= (1 << OCIE1A); - set_bit(TIMSK, OCIE1A); // Interrupt für ISR COMPA - //set_bit(TCCR1B, WGM12); // Überlauf wird unten gesetzt - - // Animations-Geschwindigkeit - // (vergleichswert bei dem der Interrupt ausgelöst wird) + // Refreshrate is 100Hz + // Set the compare value // 625d = 0x271 = 0b00000010, 0b01110001 OCR1AH = 0b00000010; OCR1AL = 0b01110001; // anpassen auf reihenweise ausgabe - // Vorteiler durch 64 (0x011) ----> CS12=0, CS11=1, CS10=1 - //clear_bit(TCCR1B, CS12); // Prescaler 64 - //set_bit(TCCR1B, CS11); - //set_bit(TCCR1B, CS10); + // prescale is 64 (0x011) ----> CS12=0, CS11=1, CS10=1 TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM12); - sei(); // Set enable interrupt bit (Muss gesetzt werden damit es überhaupt aufgerufen wird) + sei(); // Enable interrupts global } -// Interruptvektor von TIMER1 +// TIMER1 Interruptvector ISR (TIMER1_COMPA_vect) { - delay--; - if ( !delay ) + delay--; // decrease the delay counter + if ( !delay ) // check if we are done with waiting { - if (frmnum == 32) + if (frmnum == MAX_EEPROM_FRAMES) { - if (mode == 1) - mode = 0; - frmnum = 0; + if (mode == MODE_ANIMATION_SINGLE) + mode = MODE_ANIMATION_STOP; // stop the animation after we have reached the 31th frame + frmnum = 0; // always start at the first frame } else { if (mode) { + // if we are in an animation mode we have to load a frame out of the eeprom + // and increase the counter loadEEPROMFrame(frmnum); frmnum++; } } - delay = delay_max; + delay = delay_max; // start counting from the top of the maximum delay } // PORTD = __, 9, C, B, A,D+,D-,__ - PORTD &= 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren - PORTD |= (1 << 6) | ((1 << level) << 3); // level setzen (Ebene A=0, B=1, C=2) + PORTD &= 0b10000111; // delete bit 3 to 6 (bit 3 to 5 = layer 0 to 2; bit 6 = wire 9 to the LEDs) + PORTD |= (1 << 6) | ((1 << level) << 3); // set the current level and pin 6 to high (9th LEDs off) - uint8_t tmp = level * 9; + uint8_t tmp = level * 9; // calculate the position in the frame // PORTB = 1..8 - // 0 = leuchtet, 1 = leuchtet nicht (invertiert!) + // 0 = led is on, 1 = led is off PORTB = ~((frame >> tmp) & 0xff); if ( (((frame >> tmp) >> 8) & 0x01) ) - PORTD &= ~(1 << 6); // 9. led setzen falls notwendig + PORTD &= ~(1 << 6); // turn the 9th LED on if required + // rotate through the 3 level level++; if (level > 2) level = 0; } +/** + * Simple function to load a single frame out of the EEPROM. + */ void loadEEPROMFrame(uint8_t f) { frame = eeprom_read_dword( &eep_anim[f] ); diff --git a/firmware/main.eep b/firmware/main.eep new file mode 100644 index 0000000..34db133 --- /dev/null +++ b/firmware/main.eep @@ -0,0 +1,5 @@ +:2000000000000004000000040000000400000001000080000000200000000400000001002E +:20002000002000000008000000010000400000001000000004000000020000000100000040 +:20004000010000000100000001000000020000000800000010000000800000000002000001 +:20006000001000000040000000000200000008000000200000008000000000020000000480 +:00000001FF diff --git a/firmware/main.h b/firmware/main.h index cff2aa6..731871e 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -1,6 +1,7 @@ -/* CTHN.de MiniLEDCube +/* + * CTHN.de MiniLEDCube * - * Kai Lauterbach (klaute at web dot de) + * By Kai Lauterbach (klaute at web dot de) 11/2011 * * Based on http://mosfetkiller.de/?s=miniledcube * @@ -14,31 +15,28 @@ // Includes #include "globals.h" -//#include "type.h" - #include #include #include // Cube-Data -uint32_t frame = 0xffffffff; -// Bit Offset in Cube-Data -uint8_t level; // Aktive Ebene -uint8_t mode; -uint8_t frmnum; -uint8_t delay; -uint8_t delay_max; +uint32_t frame; -//cube_t *cube; -uint32_t eep_anim[32] EEMEM; +uint8_t level; // current layer +uint8_t mode = MODE_ANIMATION_LOOP; // firmware mode +uint8_t frmnum; // frame nummber in the animation loop +uint8_t delay; // delay in ISR calls between changing to the next animation frame +uint8_t delay_max = STARTUP_DELAY_MAX; // maximum delay between the animation frames -// Prototypen +// eeprom array of the animation +uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM; + +// function prototypes void init(void); +void loadEEPROMFrame(uint8_t); extern void init_usb(void); extern void usbPoll(void); -void loadEEPROMFrame(uint8_t); - #endif // __main_h__ diff --git a/firmware/main.hex b/firmware/main.hex new file mode 100644 index 0000000..fecb3d1 --- /dev/null +++ b/firmware/main.hex @@ -0,0 +1,129 @@ +:1000000083C111C09AC199C1DAC197C196C195C186 +:1000100094C193C192C191C190C18FC18EC18DC154 +:100020008CC18BC18AC1CF93CFB7CF93C395819B2E +:10003000E9F7819B09C0819B07C0819B05C0819B1B +:1000400003C0819B01C0A3C0DF93C0918400DD2762 +:10005000C557DF4F819B02C0DF91EBCF2F930F93EA +:100060001F9300B32FEF01FB20F94F933F9310B381 +:100070004FEF012701FB21F93BE031C04E7F012FFB +:1000800010B3216028C0102F4D7F2260000000B304 +:1000900029C04B7F2460012F000010B32BC010B388 +:1000A000477F28602AC04F7E00B320612CC04F7D5F +:1000B00010B320622FC04F7B00B3206432C04227B0 +:1000C00000B349934FEF0000102711FB20F910B344 +:1000D0001670C9F1297F91F2012701FB21F900B3C4 +:1000E000237F89F2315058F1102711FB22F910B308 +:1000F000277E79F2012701FB23F92F7C81F200B3DF +:10010000102711FB24F92F7971F200C010B30127D9 +:1001100001FB25F92F7359F200C000B3102711FB22 +:1001200026F9223040F200C010B3012701FB27F965 +:10013000243028F64F77206810B30000F9CF10E480 +:100140001ABF002719C03B503195C31BD04010E4A3 +:100150001ABF0881033CF9F00B34E9F020918200CA +:100160001981110F1213EDCF4A81441F093641F155 +:100170000D3211F0013E29F7009389003F914F9114 +:100180001F910F912F91DF91CAB7C6FD4FCFCF912D +:10019000CFBFCF91189520918900222379F3109138 +:1001A0008700112369F534306AF13093870020937A +:1001B0008300109184003BE0311B3093840022C007 +:1001C000009187000130E4F40AE54F7049F4309162 +:1001D000620034FD19C000936200CBE6D0E018C085 +:1001E0003091760034FD10C000937600C7E7D0E070 +:1001F0000FC02795A8F45150A9F4220F0000F9CFA1 +:100200004AE503C042ED01C0432FC4E1D0E032E033 +:1002100011B31660919A11BB02B320E416E05F930C +:10022000012756E002BB279520F4515021F4220FFC +:10023000F9CF012756E000003B5A02BBD0F22795C8 +:1002400028F4515029F4220F0000F9CF012756E07D +:10025000279502BB20F4515021F4220FF9CF01273A +:1002600056E02991332302BB21F6097F10918800C3 +:10027000110FC651D04002BB11F01093820010E460 +:100280001ABF026011B3197F402F497F5F9100C0F0 +:1002900000C002BB11BB42BB71CF040309041003B1 +:1002A0004300540048004E002E0064006500100317 +:1002B0004C004500440043007500620065001201D7 +:1002C000100100000008C016DF0500010102000156 +:1002D00009022200010100807D09040000010300E1 +:1002E0000000092101010001221600070581030811 +:1002F000000A0600FF0901A101150026FF0075088C +:1003000095010900B20201C011241FBECFEDCDBF7F +:1003100010E0A0E6B0E0E4EEF7E002C005900D9238 +:10032000A436B107D9F710E0A4E6B0E001C01D92F1 +:10033000A13AB107E1F72ED053C262CEA82FB92F50 +:1003400080E090E041E050EA609530E009C02D91F6 +:1003500082279795879510F084279527305EC8F3FC +:100360006F5FA8F30895EADF8D939D9308958FEF53 +:1003700087BB88BB88E781BB80E482BB89B7806488 +:1003800089BF82E08BBD81E78ABD8EB58B608EBD53 +:1003900078940895ECDFE0D184D0FECF90E0880F10 +:1003A000991F880F991F80509040F2D1609366008A +:1003B00070936700809368009093690008951F927E +:1003C0000F920FB60F9211242F933F934F935F9389 +:1003D0006F937F938F939F93AF93BF93EF93FF930D +:1003E000809165008150809365008823C9F48091D5 +:1003F0006A0090916000803239F4913011F41092CB +:10040000600010926A0008C0992331F0C7DF809124 +:100410006A008F5F80936A0080916100809365001D +:1004200082B3877882BB92B390648091640028E0A5 +:1004300030E0082E02C0220F331F0A94E2F7922BFD +:1004400092BB69E09CD12091660030916700409199 +:1004500068005091690004C05695479537952795D7 +:100460008A95D2F7822F809588BB30FD969880912F +:1004700064008F5F80936400833010F010926400FA +:10048000FF91EF91BF91AF919F918F917F916F916C +:100490005F914F913F912F910F900FBE0F901F9042 +:1004A00018951F93CF93DF9380918700835087FD2A +:1004B000A1C090918400209183002D3209F098C052 +:1004C000883009F095C0CCE0D0E0C91BD109C557F0 +:1004D000DF4F83EC80936B008AE58093620013BA50 +:1004E0008881807619F0CE01DBD079C09A81109294 +:1004F00074008981882331F41092750024E730E07C +:1005000082E069C0853019F49093880061C086301C +:1005100009F048C08B81813041F48EEB92E09093DA +:1005200086008093850082E13AC0823041F480EDFC +:1005300092E0909386008093850082E230C0833001 +:10054000C9F4992341F48AE992E09093860080935C +:10055000850084E024C0913019F48EE992E004C053 +:100560009230E1F48EEA92E09093860080938500C9 +:1005700080E115C0813241F482EE92E090938600D2 +:100580008093850089E00BC0823241F482EF92E0D3 +:10059000909386008093850086E101C080E090E41E +:1005A00093BB1DC0883069F0893019F490938A009C +:1005B0000FC08A3049F08B3059F48BE48093770078 +:1005C00007C02AE830E002C024E730E081E003C041 +:1005D00024E730E080E030938600209385009F81FF +:1005E000992321F49E81981708F4892F8093630042 +:1005F000109287008091620084FF44C08091630064 +:100600008F3F09F43FC0182F893008F018E0811B94 +:100610008093630080916B0098E8892780936B003A +:10062000112321F1E0918500F0918600812F815006 +:100630009E9B0CC090E083599F4FACE6B0E02491A4 +:100640002D933196A817B907D1F70CC0EF0190E0B0 +:1006500083599F4FACE6B0E029912D93FE01A81776 +:10066000B907D1F7F0938600E09385008CE690E01F +:10067000612F79DE1C5F1C3019F08FEF80936300CF +:100680001093620084E190B3967031F48150D9F7F1 +:100690001092880010928200DF91CF911F910895EF +:1006A000FC0180818076803409F054C081818130E2 +:1006B00091F5848173816281209166003091670099 +:1006C0004091680050916900882359F4972F80E089 +:1006D000860F911DAA2797FDA095BA2F2070307024 +:1006E0000DC0972F80E0860F911DAA2797FDA0953A +:1006F000BA2FDC019927882740705070822B932BEA +:10070000A42BB52B8093660090936700A09368009C +:10071000B09369001FC0823091F4848190E0880F0B +:10072000991F880F991F4091660050916700609152 +:10073000680070916900805090402DD00BC08430CB +:1007400021F482818093610005C0833019F4828195 +:100750008093600080E0089585B7826085BF8BB785 +:1007600080648BBF8BE4809377008AE5809376006A +:10077000899A01C000009150E9F7899808950024F2 +:1007800080FD060E660F11F08695D1F7802D089535 +:10079000A6E144E00AC0242F16D0252F14D000C0B3 +:1007A00011D0272F10C0A82F862FE82FE199FECF58 +:1007B0001FBA05C0EEBBE09AE3950DB20D92415011 +:1007C000C8F70895262FE199FECF1CBA1FBA8EBB39 +:1007D0002DBB0FB6F894E29AE19A0FBE01960895E8 +:0407E000F894FFCFBB +:0407E400020A5AFFAC +:00000001FF diff --git a/firmware/requests.h b/firmware/requests.h index 3548621..fd9aa9f 100644 --- a/firmware/requests.h +++ b/firmware/requests.h @@ -1,11 +1,13 @@ -/* Name: requests.h - * Project: custom-class, a basic USB example - * Author: Christian Starkjohann - * Creation Date: 2008-04-09 - * Tabsize: 4 - * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH - * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) - * This Revision: $Id: requests.h 692 2008-11-07 15:07:40Z cs $ +/* + * CTHN.de MiniLEDCube + * + * requests.h by Kai Lauterbach + * + * Based on project: hid-custom-rq example by Christian Starkjohann + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * */ /* This header is shared between the firmware and the host software. It @@ -18,8 +20,7 @@ #define CUSTOM_RQ_SET_FRAME 1 #define CUSTOM_RQ_EEPROM_STORE_FRAME 2 -#define CUSTOM_RQ_EEPROM_SET_FRAME 3 -#define CUSTOM_RQ_SET_MODE 4 -#define CUSTOM_RQ_SET_DELAY 5 +#define CUSTOM_RQ_SET_MODE 3 +#define CUSTOM_RQ_SET_DELAY 4 #endif /* __REQUESTS_H_INCLUDED__ */ diff --git a/firmware/usb.c b/firmware/usb.c index 8c1a2d5..3b00389 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -1,9 +1,13 @@ -/* Name: usb.h by Kai Lauterbach - * Based on Project: hid-custom-rq example - * Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ - * Author: Christian Starkjohann - * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH - * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) +/* + * CTHN.de MiniLEDCube + * + * usb.h by Kai Lauterbach 11/2011 + * + * Based on project: hid-custom-rq example by Christian Starkjohann + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * */ #include "usb.h" @@ -19,12 +23,16 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) if ( rq->bRequest == CUSTOM_RQ_SET_FRAME ) { + // because of the code size we have to transfer one frame in + // two steps (control messages) if ( rq->wIndex.bytes[0] == 0 ) { + // the lower word frame = (frame & (uint32_t)0xffff0000) | ( rq->wValue.bytes[0] + (rq->wValue.bytes[1] << 8) ); } else { + // the high word frame = (frame & (uint32_t)0x0000ffff) | ((uint32_t)( rq->wValue.bytes[0] + (rq->wValue.bytes[1] << 8) ) << 16); @@ -32,13 +40,19 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) } else if ( rq->bRequest == CUSTOM_RQ_EEPROM_STORE_FRAME ) { + // save the actual frame to the eeprom + // don't forget to send a frame first eeprom_write_dword( &eep_anim[ rq->wIndex.bytes[0] ], frame ); } else if ( rq->bRequest == CUSTOM_RQ_SET_DELAY ) { + // set the maximum delay between two frames + // as a multiply of ISR calls delay_max = rq->wValue.bytes[0]; } else if ( rq->bRequest == CUSTOM_RQ_SET_MODE ) { - mode = rq->wValue.bytes[0]; // 0 = stop; 1 = single; 2 = loop + // set the firmware mode + // 0 = stop; 1 = single; 2 = loop + mode = rq->wValue.bytes[0]; } } diff --git a/firmware/usb.h b/firmware/usb.h index eabc2a2..d8d2445 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -1,10 +1,13 @@ -/* Name: usb.h by Kai Lauterbach - * Based on Project: hid-custom-rq example - * Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ - * Author: Christian Starkjohann - * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH - * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) - * This +/* + * CTHN.de MiniLEDCube + * + * usb.c by Kai Lauterbach 11/2011 + * + * Based on project: hid-custom-rq example by Christian Starkjohann + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH + * + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * */ #ifndef __usb_h__ @@ -18,17 +21,6 @@ #include "globals.h" -//#include "type.h" - -/* -This example should run on most AVRs with only little changes. No special -hardware resources except INT0 are used. You may have to change usbconfig.h for -different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or -at least be connected to INT0 as well. -We assume that an LED is connected to port B bit 0. If you connect it to a -different port or bit, change the macros below: -*/ - #include "usbconfig.h" #include "usbdrv.h" #include "requests.h" /* The custom request numbers we use */ @@ -57,7 +49,7 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ void init_usb(void); -extern uint32_t eep_anim[32] EEMEM; +extern uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM; // usb buffer extern uint32_t frame; // Framebuffer @@ -65,7 +57,7 @@ extern uint8_t delay_max; // delay in ISR aufrufen extern uint8_t mode; // FW mode //extern cube_t *cube; -extern void loadEEPROMFrame(uint8_t f); +extern void loadEEPROMFrame(uint8_t); #endif // __usb_h__