diff --git a/firmware/main.c b/firmware/main.c index 049ce06..a380280 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -18,10 +18,7 @@ main() init(); init_usb(); - //cube_t c; - //cube = &c; frame = 0x07ffffff; - //cube->level = 0x00; // Hauptschleife for (;;) @@ -65,6 +62,21 @@ void init() ISR (TIMER1_COMPA_vect) { + delay--; + if ( !delay ) + { + if (frmnum == 32) + { + if (mode > 0) + frmnum = 0; + if (mode == 1) + mode = 0; + } else + setFrame(frmnum); + if (mode) + frmnum++; + } + // 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) @@ -83,3 +95,8 @@ ISR (TIMER1_COMPA_vect) } +void setFrame(uint8_t f) +{ + frame = eeprom_read_dword( &eep_anim[f] ); +} + diff --git a/firmware/main.h b/firmware/main.h index ca54a6c..00f81bf 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -18,13 +18,18 @@ #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; //cube_t *cube; +uint32_t eep_anim[32] EEMEM; // Prototypen void init(void); @@ -32,5 +37,7 @@ void init(void); extern void init_usb(void); extern void usbPoll(void); +void setFrame(uint8_t); + #endif // __main_h__ diff --git a/firmware/requests.h b/firmware/requests.h index 6c86b13..5634a89 100644 --- a/firmware/requests.h +++ b/firmware/requests.h @@ -19,8 +19,6 @@ #define CUSTOM_RQ_SET_FRAME 1 #define CUSTOM_RQ_EEPROM_STORE_FRAME 2 #define CUSTOM_RQ_EEPROM_SET_FRAME 3 -#define CUSTOM_RQ_LOOP_ANIMATION 4 -#define CUSTOM_RQ_START_ANIMATION 5 -#define CUSTOM_RQ_STOP_ANIMATION 6 +#define CUSTOM_RQ_SET_MODE 4 #endif /* __REQUESTS_H_INCLUDED__ */ diff --git a/firmware/usb.c b/firmware/usb.c index 9b57186..a9cad36 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -16,19 +16,9 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) if ( (rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR ) { - /*if ( rq->bRequest == CUSTOM_RQ_SET_LED ) - { - if ( rq->wValue.bytes[0] == 1 ) - cube |= ((uint32_t)1 << rq->wIndex.bytes[0]); - else - cube &= ~((uint32_t)1 << rq->wIndex.bytes[0]); - } else*/ if ( rq->bRequest == CUSTOM_RQ_SET_FRAME ) + if ( rq->bRequest == CUSTOM_RQ_SET_FRAME ) { - /* requires more flash space - cube = (cube & (uint32_t)0xffff0000) | - ( rq->wValue.bytes[0] + (rq->wValue.bytes[1] << 8) ) | - ( (uint32_t)(rq->wIndex.bytes[0] + (rq->wIndex.bytes[1] << 8)) << 16 );*/ if ( rq->wIndex.bytes[0] == 0 ) { frame = (frame & (uint32_t)0xffff0000) | @@ -42,10 +32,15 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) } else if ( rq->bRequest == CUSTOM_RQ_EEPROM_STORE_FRAME ) { - eeprom_write_dword(&eep_anim[0], 0x07007007); - } else if ( rq->bRequest == CUSTOM_RQ_EEPROM_SET_FRAME ) + eeprom_write_dword( &eep_anim[ rq->wIndex.bytes[0] ], frame ); + + /*} else if ( rq->bRequest == CUSTOM_RQ_EEPROM_SET_FRAME ) { - frame = eeprom_read_dword( &eep_anim[rq->wIndex.bytes[0]] ); + //frame = eeprom_read_dword( &eep_anim[rq->wIndex.bytes[0]] ); + setFrame( &eep_anim[rq->wIndex.bytes[0]] );*/ + } else if ( rq->bRequest == CUSTOM_RQ_SET_MODE ) + { + mode = rq->wValue.bytes[0]; // 0 = stop; 1 = single; 2 = loop } } diff --git a/firmware/usb.h b/firmware/usb.h index e86b57e..835cb6e 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -57,12 +57,14 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ void init_usb(void); -uint32_t eep_anim[32] EEMEM; +extern uint32_t eep_anim[32] EEMEM; // usb buffer extern uint32_t frame; // Framebuffer +extern uint8_t mode; // FW mode //extern cube_t *cube; +extern void setFrame(uint8_t f); #endif // __usb_h__