From 620a1747853afd8d2892ad37c911a3d868aed307 Mon Sep 17 00:00:00 2001 From: Thomas Kopp <20.kopp@gmail.com> Date: Mon, 29 Sep 2014 22:43:38 +0200 Subject: [PATCH] Changes for GCC 4.9 --- firmware/main.c | 24 ++++---- firmware/main.h | 10 ++-- firmware/main.hex | 141 +++++++++++++++++++++++----------------------- firmware/usb.c | 90 ++++++++++++----------------- firmware/usb.h | 10 +++- 5 files changed, 129 insertions(+), 146 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 0502847..c444c18 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -11,8 +11,6 @@ #include "main.h" -volatile uint8_t timer_tick = false; - /*! \brief Initialize the AVR. */ static inline void init(void) @@ -38,9 +36,9 @@ static inline void init(void) */ int __attribute__((OS_main)) main() { - uint8_t level; - uint8_t frmnum; - uint8_t delay; + uint8_t level = 0x00; + uint8_t frmnum = 0x00; + uint8_t delay = 0x00; // Initialize the AVR and the USB connection. init(); init_usb(); @@ -64,7 +62,7 @@ int __attribute__((OS_main)) main() if (mode) { // if we are in an animation mode we have to load a frame out of the eeprom // and increase the counter - frame = eeprom_read_dword(&eep_anim[frmnum]); + frame.all = eeprom_read_dword(&eep_anim[frmnum]); frmnum++; } } @@ -73,20 +71,20 @@ int __attribute__((OS_main)) main() // Possible delays are 8 16 24 32 and so on. A zero delay isn't possible. // Zero means that a delay of 255 happens because the delay variable was decreased first before testing // it's zero value. - delay = (frame >> 24) & 0xf8; + delay = frame.bytes[3] & 0xf8; } // PORTD = __, 9, C, B, A, D+, D-, __ - PORTD &= ~((1 << 5) | (1 << 4) | (1 << 3) | (1 << 2));; // delete bit 3 to 6 (bit 3 to 5 = layer 0 to 2 - uint8_t tmp = level * 9; // calculate the position in the frame + PORTD &= ~((1 << PORTD5) | (1 << PORTD4) | (1 << PORTD3) | (1 << PORTD2)); // delete bit 3 to 6 (bit 3 to 5 = layer 0 to 2 // PORTB = 1..8 + uint32_t tmp_frame = (frame.all >> (uint8_t)(level * 9)); // 0 = led is on, 1 = led is off - PORTB = ~((frame >> tmp) & 0xff); + PORTB = ~((uint8_t)tmp_frame); - if ((((frame >> tmp) >> 8) & 0x01)) { - PORTD &= ~(1 << 6); // turn the 9th LED on + if (!(tmp_frame & 0x100)) { + PORTD |= (1 << PORTD6); // turn the 9th LED off } else { - PORTD |= (1 << 6); // turn the 9th LED off + PORTD &= ~(1 << PORTD6); // turn the 9th LED on } // set the current level to high diff --git a/firmware/main.h b/firmware/main.h index ada975e..7d4d751 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -28,13 +28,13 @@ * bit 27 - 31 = The delay in ISR calls multiplied with 8 until * the next frame will be shown (load from the EEPROM) */ -uint32_t frame; +union { + uint32_t all; + uint8_t bytes[4]; +} frame; +// uint32_t frame; uint8_t mode = MODE_ANIMATION_LOOP; // firmware mode -// uint8_t level; // current layer -// uint8_t frmnum; // frame nummber in the animation loop -// uint8_t delay; // delay in ISR calls between changing to the next animation frame - // eeprom array of the animation uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM; diff --git a/firmware/main.hex b/firmware/main.hex index 7270622..39b3243 100644 --- a/firmware/main.hex +++ b/firmware/main.hex @@ -8,9 +8,9 @@ :1000700048004E002E0064006500040309040600D9 :10008000FF0901A101150026FF007508950109006F :10009000B20201C011241FBECFEDCDBF10E0A0E61B -:1000A000B0E0E2ECF7E002C005900D92A436B10793 +:1000A000B0E0EEE9F7E002C005900D92A436B1078A :1000B000D9F710E0A4E6B0E001C01D92AF39B10756 -:1000C000E1F755D17CC39CCFA82FB92F80E090E0F9 +:1000C000E1F755D16AC39CCFA82FB92F80E090E00B :1000D00041E050EA609530E009C02D918227979564 :1000E000879510F084279527305EC8F36F5FA8F3DB :1000F0000895EADF8D939D930895CF93CFB7CF9363 @@ -54,74 +54,71 @@ :10035000800010E41ABF026011B3197F402F497F5B :100360005F9100C000C002BB11BB42BB71CF8FEFD9 :1003700087BB88BB88E781BB80E482BB81E792E0D2 -:100380009BBD8ABD8BE08EBD7894DED166D008B669 -:1003900006FEFCCF80E488BFF894115011F58091DF -:1003A0006000D03229F48130C1F41092600015C091 -:1003B0008823A1F08D2F90E0880F991F880F991F37 -:1003C00080509040D4D16093650070936600809314 -:1003D000670090936800DF5F01C0D0E01091680073 -:1003E000187F82B3837C82BB8C2F69E0B7D1282F22 -:1003F00040916500509166006091670070916800BF -:1004000004C076956795579547958A95D2F740959C -:1004100048BB8091650090916600A0916700B09103 -:10042000680004C0B695A795979587952A95D2F749 -:1004300090FF02C0969801C0969A22B388E090E09F -:100440000C2E01C0880F0A94EAF7822B82BBCF5F83 -:10045000C33009F4C0E0789499CFCF93DF938091B3 -:100460008500835087FDA3C0909182002091810078 -:100470002D3209F09AC0883009F097C0CCE0D0E066 -:10048000C91BD109C757DF4F83EC809369008AE508 -:1004900080936200109264008881807619F0CE010A -:1004A000E7D07AC09A81109272008981811106C0CA -:1004B0001092730022E730E082E06AC0853019F4C0 -:1004C0009093860062C0863009F049C08B818130EC -:1004D00041F488E490E0909384008093830082E16B -:1004E0003AC0823041F486E290E090938400809399 -:1004F000830082E230C08330C9F4911108C08AE7DA -:1005000090E0909384008093830084E024C0913035 -:1005100019F48AE690E004C09230E1F48AE590E0B4 -:10052000909384008093830080E115C0813241F470 -:1005300088E390E0909384008093830089E00BC06F -:10054000823241F48EE790E09093840080938300A0 -:1005500086E101C080E090E4909364001DC0883083 -:1005600069F0893019F4909388000FC08A3049F0FF -:100570008B3059F48BE48093750007C028E830E095 -:1005800002C022E730E081E003C022E730E080E0F3 -:1005900030938400209383009F81911104C09E8139 -:1005A000981708F4892F809361001092850080913C -:1005B000620084FF43C0809161008F3F09F43EC018 -:1005C000C82F893008F0C8E08C1B8093610090919F -:1005D000690088E8892780936900CC2319F180910C -:1005E000830040918400209164009C2F980F26FF87 -:1005F0000AC0AAE6B0E0E82FF42F84918D933196DB -:100600009E13FBCF0BC02AE630E0A82FB42F8D91AC -:10061000F90181939F01FD019A13F9CFF0938400B2 -:10062000E09383006C2F8AE690E063DDCC5FCC30F2 -:1006300019F08FEF80936100C093620084E190B362 -:10064000967031F48150D9F7109286001092800094 -:10065000DF91CF91089585B7826085BF8BB78064A5 -:100660008BBFE4E7F0E08BE481838AE58083089523 -:100670000F931F93FC0180818076803409F060C065 -:100680008181813009F043C084814091650050919F -:100690006600609167007091680081111AC08281C4 -:1006A000038110E0102F0027080F111D222717FDCE -:1006B0002095322F44275527042B152B262B372B1B -:1006C00000936500109366002093670030936800E4 -:1006D00037C022819381892F90E0982F8827820F3D -:1006E000911DAA2797FDA095BA2FDC01992788278D -:1006F00066277727842B952BA62BB72B8093650035 -:1007000090936600A0936700B093680019C0823090 -:1007100091F440916500509166006091670070917E -:100720006800848190E0880F991F880F991F80507E -:10073000904020D005C0833019F4828180936000FE -:1007400080E01F910F910895CF9385DF899AC15062 -:1007500011F00000FCCF8998CF910895002480FD0E -:10076000060E660F11F08695D1F7802D0895A6E14B -:1007700044E00AC0242F16D0252F14D000C011D079 -:10078000272F10C0A82F862FE82FE199FECF1FBA80 -:1007900005C0EEBBE09AE3950DB20D924150C8F74B -:1007A0000895262FE199FECF1CBA1FBA8EBB2DBB30 -:1007B0000FB6F894E29AE19A0FBE01960895F89464 -:0207C000FFCF69 -:0407C20002FF5A00D8 +:100380009BBD8ABD8BE08EBD7894D2D110E0D0E0C9 +:10039000C0E062D008B606FEFCCF80E488BFF894C7 +:1003A000115011F580916000D03229F48130C1F4F0 +:1003B0001092600015C08823A1F08D2F90E0880F67 +:1003C000991F880F991F80509040BFD1609365009E +:1003D000709366008093670090936800DF5F01C0B0 +:1003E000D0E010916800187F82B3837C82BB8C2F91 +:1003F00069E029D0409165005091660060916700E6 +:10040000709168006A017B0104C0F694E794D79468 +:10041000C7948A95D2F72C2D209528BBD0FC02C01A +:10042000969A01C0969822B388E090E00C2E01C005 +:10043000880F0A94EAF7822B82BBCF5FC33008F0A3 +:10044000C0E07894A6CF002480FD060E660F11F060 +:100450008695D1F7802D0895CF93DF938091850005 +:10046000835087FDA3C090918200209181002D329E +:1004700009F09AC0883009F097C0CCE0D0E0C91BE1 +:10048000D109C757DF4F83EC809369008AE58093D9 +:100490006200109264008881807619F0CE01E7D066 +:1004A0007AC09A81109272008981811106C01092DF +:1004B000730022E730E082E06AC0853019F490933F +:1004C000860062C0863009F049C08B81813041F4DA +:1004D00088E490E0909384008093830082E13AC0A6 +:1004E000823041F486E290E0909384008093830010 +:1004F00082E230C08330C9F4911108C08AE790E0ED +:10050000909384008093830084E024C0913019F498 +:100510008AE690E004C09230E1F48AE590E090939E +:1005200084008093830080E115C0813241F488E328 +:1005300090E0909384008093830089E00BC0823226 +:1005400041F48EE790E0909384008093830086E1ED +:1005500001C080E090E4909364001DC0883069F091 +:10056000893019F4909388000FC08A3049F08B309D +:1005700059F48BE48093750007C028E830E002C08E +:1005800022E730E081E003C022E730E080E03093F2 +:100590008400209383009F81911104C09E8198174D +:1005A00008F4892F80936100109285008091620089 +:1005B00084FF43C0809161008F3F09F43EC0C82F83 +:1005C000893008F0C8E08C1B80936100909169002D +:1005D00088E8892780936900CC2319F180918300F2 +:1005E00040918400209164009C2F980F26FF0AC040 +:1005F000AAE6B0E0E82FF42F84918D9331969E13F4 +:10060000FBCF0BC02AE630E0A82FB42F8D91F90163 +:1006100081939F01FD019A13F9CFF0938400E09339 +:1006200083006C2F8AE690E064DDCC5FCC3019F05B +:100630008FEF80936100C093620084E190B3967065 +:1006400031F48150D9F71092860010928000DF912A +:10065000CF91089585B7826085BF8BB780648BBFCB +:10066000E4E7F0E08BE481838AE580830895FC0170 +:1006700080818076803409F059C081818130E9F52C +:1006800084812281811115C0838190E0982F882771 +:10069000820F911DAA2797FDA095BA2F4091650062 +:1006A000509166006091670070916800442755275B +:1006B00017C0838190E0982F8827820F911DAA2769 +:1006C00097FDA095BA2FDC019927882740916500F6 +:1006D00050916600609167007091680066277727E7 +:1006E000842B952BA62BB72B8093650090936600E7 +:1006F000A0936700B093680019C0823091F44091D4 +:100700006500509166006091670070916800848177 +:1007100090E0880F991F880F991F8050904018D043 +:1007200005C0833019F482818093600080E00895D1 +:1007300091DF899A2FEB87E299E021508040904029 +:10074000E1F700C0000089980895A6E144E00AC0DE +:10075000242F16D0252F14D000C011D0272F10C061 +:10076000A82F862FE82FE199FECF1FBA05C0EEBB58 +:10077000E09AE3950DB20D924150C8F70895262FE7 +:10078000E199FECF1CBA1FBA8EBB2DBB0FB6F894F1 +:0E079000E29AE19A0FBE01960895F894FFCF09 +:04079E0002FF5A00FC :00000001FF diff --git a/firmware/usb.c b/firmware/usb.c index 96be7f4..3374abc 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -1,4 +1,4 @@ -/* +/* * CTHN.de MiniLEDCube * * usb.h by Kai Lauterbach 11/2011 @@ -20,65 +20,49 @@ */ usbMsgLen_t usbFunctionSetup(uchar data[8]) { - usbRequest_t *rq = (void *)data; - - if ( (rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR ) - { - 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] ) - { - // 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); - } - - } 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_MODE ) - { - // set the firmware mode - // 0 = stop; 1 = single; 2 = loop - mode = rq->wValue.bytes[0]; - } + usbRequest_t *rq = (void *)data; + if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR) { + 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]) { + // the lower word + frame.all = (frame.all & (uint32_t)0xffff0000) | + (rq->wValue.bytes[0] + + (rq->wValue.bytes[1] << 8)); + } else { + // the high word + frame.all = (frame.all & (uint32_t)0x0000ffff) | + ((uint32_t)(rq->wValue.bytes[0] + + (rq->wValue.bytes[1] << 8)) << 16); + } + } 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.all); + } else if (rq->bRequest == CUSTOM_RQ_SET_MODE) { + // set the firmware mode + // 0 = stop; 1 = single; 2 = loop + mode = rq->wValue.bytes[0]; } - return 0; /* default for not implemented requests: return no data back to host */ + } + + return 0; /* default for not implemented requests: return no data back to host */ } -/* ------------------------------------------------------------------------- */ - -/*! \brief Initializes the USB conneciton. +/*! \brief Initializes the USB connection. */ void init_usb(void) { + usbInit(); + usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ - uint8_t i; - - usbInit(); - usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ - - // fake USB disconnect for > 250 ms - while(--i) - { - asm volatile("nop"::); - } - - usbDeviceConnect(); + // fake USB disconnect for > 250 ms + // for (uint8_t i = 0; i <= 25; i++) { + // _delay_ms(10); + // } + _delay_ms(250); + usbDeviceConnect(); } - -/* ------------------------------------------------------------------------- */ diff --git a/firmware/usb.h b/firmware/usb.h index e6b6fa2..cd61d37 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -17,6 +17,7 @@ #include "globals.h" +#include "util/delay.h" #include "usbconfig.h" #include "usbdrv.h" #include "requests.h" /* The custom request numbers we use */ @@ -38,12 +39,15 @@ PROGMEM const char usbHidReportDescriptor[22] = { /* USB report descriptor */ 0xc0 // END_COLLECTION }; -void init_usb(void); - extern uint32_t eep_anim[MAX_EEPROM_FRAMES] EEMEM; // usb buffer -extern uint32_t frame; // Framebuffer +extern union { + uint32_t all; + uint8_t bytes[4]; +} frame; // Framebuffer +// extern uint32_t frame; + extern uint8_t mode; // FW mode #endif // __usb_h__