From 73ad4d9fd9f784259b3702987397e36fc9411e15 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Sun, 18 Dec 2011 22:16:32 +0100 Subject: [PATCH] Code optimized, delay changing via USB added and animation viewing routine fixed. --- firmware/main.c | 28 ++++++++++++++++------------ firmware/main.h | 3 ++- firmware/usb.c | 6 ++---- firmware/usb.h | 7 ++++--- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index a380280..9beac36 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -18,7 +18,8 @@ main() init(); init_usb(); - frame = 0x07ffffff; + //frame = 0x07ffffff; + mode = 2; // Hauptschleife for (;;) @@ -31,11 +32,11 @@ main() void init() { // Ports vorbereiten - DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathoden) - PORTB = 0b11111111; // HIGH + DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathoden) + PORTB = 0b11111111; // HIGH - DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden) - PORTD = 0b01000000; + DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden) + PORTD = 0b01000000; // Timer-Interrupt "TIMER1" vorbereiten @@ -67,14 +68,17 @@ ISR (TIMER1_COMPA_vect) { if (frmnum == 32) { - if (mode > 0) - frmnum = 0; if (mode == 1) mode = 0; - } else - setFrame(frmnum); - if (mode) - frmnum++; + frmnum = 0; + } else { + if (mode) + { + loadEEPROMFrame(frmnum); + frmnum++; + } + } + delay = delay_max; } // PORTD = __, 9, C, B, A,D+,D-,__ @@ -95,7 +99,7 @@ ISR (TIMER1_COMPA_vect) } -void setFrame(uint8_t f) +void loadEEPROMFrame(uint8_t f) { frame = eeprom_read_dword( &eep_anim[f] ); } diff --git a/firmware/main.h b/firmware/main.h index 00f81bf..cff2aa6 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -27,6 +27,7 @@ uint8_t level; // Aktive Ebene uint8_t mode; uint8_t frmnum; uint8_t delay; +uint8_t delay_max; //cube_t *cube; uint32_t eep_anim[32] EEMEM; @@ -37,7 +38,7 @@ void init(void); extern void init_usb(void); extern void usbPoll(void); -void setFrame(uint8_t); +void loadEEPROMFrame(uint8_t); #endif // __main_h__ diff --git a/firmware/usb.c b/firmware/usb.c index a9cad36..8c1a2d5 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -33,11 +33,9 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) } else if ( rq->bRequest == CUSTOM_RQ_EEPROM_STORE_FRAME ) { eeprom_write_dword( &eep_anim[ rq->wIndex.bytes[0] ], frame ); - - /*} else if ( rq->bRequest == CUSTOM_RQ_EEPROM_SET_FRAME ) + } else if ( rq->bRequest == CUSTOM_RQ_SET_DELAY ) { - //frame = eeprom_read_dword( &eep_anim[rq->wIndex.bytes[0]] ); - setFrame( &eep_anim[rq->wIndex.bytes[0]] );*/ + 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 diff --git a/firmware/usb.h b/firmware/usb.h index 835cb6e..eabc2a2 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -60,11 +60,12 @@ void init_usb(void); extern uint32_t eep_anim[32] EEMEM; // usb buffer -extern uint32_t frame; // Framebuffer -extern uint8_t mode; // FW mode +extern uint32_t frame; // Framebuffer +extern uint8_t delay_max; // delay in ISR aufrufen +extern uint8_t mode; // FW mode //extern cube_t *cube; -extern void setFrame(uint8_t f); +extern void loadEEPROMFrame(uint8_t f); #endif // __usb_h__