From 87535e87e7a814bdda3d550c4f2c243a6c2d3270 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Tue, 29 Nov 2011 19:35:07 +0100 Subject: [PATCH 01/12] Just code formated. --- client/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/test.c b/client/test.c index e94047c..493a6ef 100644 --- a/client/test.c +++ b/client/test.c @@ -92,7 +92,7 @@ int cnt, vid, pid; cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, v, 0, buffer, 0, 5000); if (cnt < 0) { - if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ + if (usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid); exit(1); } From 8a2a2d99edaae394ad16eaabab275b7b98dcd315 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Tue, 29 Nov 2011 19:39:57 +0100 Subject: [PATCH 02/12] First implementation of the new ISR. --- firmware/main.c | 24 ++++++++++-------------- firmware/main.h | 2 +- firmware/usb.c | 13 +++++++------ firmware/usb.h | 7 ++++--- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 083c55d..aec19ac 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -59,23 +59,19 @@ void init() } // Interruptvektor von TIMER1 -//SIGNAL(SIG_OUTPUT_COMPARE1A) // alte schreibweise ISR (TIMER1_COMPA_vect) { - // Vorgang für reihenweise Ausgabe. - // Alle Pins von PORTD auf LOW setzen - // Höchstes Bit in PORTA auf 0 setzen (Leitung 9 für letzte Reihe) - - // bei cube_row_offset % 3 eine Ebene weiter schalten (ABC-Leitungen durch rotieren) - // bei Systemstart muss A aktiviert sein. - - // bits der anzuzeigenden reihe auslesen (cube & (0b00000111 << cube_row_offset)) - // und in PORTD und Pin 8 von PORTA setzen - - // cube_row_offset += 3 // immer um 3 Bits weiter springen in 32Bit Variable - - // cube_row_offset auf 0 setzen wenn maximum überschritten (27-3 = 24) + PORTD &= 0xC7; // 0b11000111 + PORTD |= (1 << (cube_layer + 3)); // shift "1" to bit 3,4,5 in PortD + PORTB = ~(cube & (0xFF << (cube_layer * 9))); // set the lines 1 to 8 negated to the port b + PORTD = (~(cube & (1 << cube_layer * 9 + 8)) << 6) + | (PORTD & 0x7F); // 0b01111111 keep the ower 7 bits and set the 9. bit from the LEDCube data. + cube_layer++; + + if (cube_layer > 2) + cube_layer = 0; + } diff --git a/firmware/main.h b/firmware/main.h index 243866a..9479473 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -22,7 +22,7 @@ // Cube-Data volatile uint32_t cube = 0x00000000; // Bit Offset in Cube-Data -volatile uint8_t cube_row_offset = 0x00; +volatile uint8_t cube_layer = 0x00; // Prototypen void init(void); diff --git a/firmware/usb.c b/firmware/usb.c index 3915e30..6c5fddf 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -12,21 +12,22 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) { - usbRequest_t *rq = (void *)data; + usbRequest_t *rq = (void *)data; if ( (rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR ) { if ( rq->bRequest == CUSTOM_RQ_SET_STATUS ) { - /*if (rq->wIndex.bytes[0] == 0) +/* + if (rq->wIndex.bytes[0] == 0) cube[0][0][0] = 1; if (rq->wIndex.bytes[0] == 1) cube[0][0][1] = 1; if (rq->wIndex.bytes[0] == 2) cube[0][0][2] = 1; if (rq->wIndex.bytes[0] == 3) - cube[0][1][0] = 1;*/ + cube[0][1][0] = 1; if (rq->wIndex.bytes[0] == 0) x = rq->wValue.bytes[0]; @@ -38,7 +39,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) z = rq->wValue.bytes[0]; else if (rq->wIndex.bytes[0] == 3) - cube[x][y][z] = rq->wValue.bytes[0]; + //cube[x][y][z] = rq->wValue.bytes[0]; } else if ( rq->bRequest == CUSTOM_RQ_GET_STATUS ) { // Send one byte to the USB host. @@ -48,7 +49,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) //return 1; // tell the driver to send 1 byte //return 0; // tell the driver to send 0 byte - +*/ } }else{ /* class requests USBRQ_HID_GET_REPORT and USBRQ_HID_SET_REPORT are @@ -69,7 +70,7 @@ void init_usb(void) usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ i = 0; - while(--i){ /* fake USB disconnect for > 250 ms */ + while(--i) { /* fake USB disconnect for > 250 ms */ //wdt_reset(); _delay_ms(1); //sleep_nop(255); diff --git a/firmware/usb.h b/firmware/usb.h index f1e4c03..5db1cec 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -55,13 +55,14 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ void init_usb(void); -volatile uint8_t x; +/*volatile uint8_t x; volatile uint8_t y; -volatile uint8_t z; +volatile uint8_t z;*/ // usb buffer //extern uint8_t buffer[3][3][3]; // Framebuffer -extern uint8_t cube[3][3][3]; // Framebuffer +//extern uint8_t cube[3][3][3]; // Framebuffer +extern uint32_t cube; // Framebuffer #endif // __usb_h__ From a0ae46b6c3d140ac5731d93679d8df528863b5c1 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Wed, 30 Nov 2011 00:16:21 +0100 Subject: [PATCH 03/12] Copied changes from USB branch. --- firmware/main.c | 36 +++++++++++++++++++++--------------- firmware/main.h | 4 ++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index aec19ac..5855a1d 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -42,36 +42,42 @@ void init() // Timer-Interrupt "TIMER1" vorbereiten //cli(); // - set_bit(TIMSK, OCIE1A); - set_bit(TCCR1B, WGM12); + set_bit(TIMSK, OCIE1A); // Interrupt für ISR COMPA + set_bit(TCCR1B, WGM12); // Überlauf // Animations-Geschwindigkeit // (vergleichswert bei dem der Interrupt ausgelöst wird) - OCR1AH = 0x01; - OCR1AL = 0x00; + // 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); - sei(); + + + sei(); // Set enable interrupt bit (Muss gesetzt werden damit es überhaupt aufgerufen wird) } // Interruptvektor von TIMER1 +//SIGNAL(SIG_OUTPUT_COMPARE1A) // alte schreibweise ISR (TIMER1_COMPA_vect) { + // PORTD = __, 9, C, B, A,D+,D-,__ + PORTD &= 0b11000111; // Reset durch Bitmaske + PORTD |= ((1 << (cube_level))<< 3); // Level setzen (A=0, B=1, C=2) - PORTD &= 0xC7; // 0b11000111 - PORTD |= (1 << (cube_layer + 3)); // shift "1" to bit 3,4,5 in PortD - PORTB = ~(cube & (0xFF << (cube_layer * 9))); // set the lines 1 to 8 negated to the port b - PORTD = (~(cube & (1 << cube_layer * 9 + 8)) << 6) - | (PORTD & 0x7F); // 0b01111111 keep the ower 7 bits and set the 9. bit from the LEDCube data. + // PORTB = 1..8 + // 0 = leuchtet, 1 = leuchtet nicht (invertiert!) + PORTB = ~(cube & (0b11111111 << (cube_level*9))); - cube_layer++; - - if (cube_layer > 2) - cube_layer = 0; - + PORTD &= 0b10111111; // 7tes Bit löschen (9) + PORTD |= ~((cube & (1 << (cube_level*9+8))) << 6); + + //cube_level++; + //if (cube_level > 2) cube_level = 0; } diff --git a/firmware/main.h b/firmware/main.h index 9479473..0cc7dc8 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -20,9 +20,9 @@ //#include // Cube-Data -volatile uint32_t cube = 0x00000000; +volatile uint32_t cube = 0x0000000F; // Aktuelle Frame // Bit Offset in Cube-Data -volatile uint8_t cube_layer = 0x00; +volatile uint8_t cube_level = 0; // Ebene // Prototypen void init(void); From 15c681c7e38f762fb416e98f01d3f3aca5b39911 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Wed, 30 Nov 2011 19:21:11 +0100 Subject: [PATCH 04/12] A simple test program to simulate the bitshifting in the ISR. --- firmware/isr_test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 firmware/isr_test.c diff --git a/firmware/isr_test.c b/firmware/isr_test.c new file mode 100644 index 0000000..c77a6ab --- /dev/null +++ b/firmware/isr_test.c @@ -0,0 +1,52 @@ + +#include +#include +#include + +int main (void) +{ + int PORTD = 0xff; + int PORTB = 0xff; + int cube = 0x000001ff; + int cube_level = 0; + + char test[100]; + + int i = 0; + for (i = 0; i < 3; i++) + { + + printf("-----------------\ncube_level = %d\n",cube_level); + + printf("PORTD = 0x%2x\n", PORTD); + printf("PORTB = 0x%2x\n", PORTB); + + PORTD &= 0x87; // 0x87 = 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren + + printf("& 0b10000111: PORTD = 0x%2x\n", PORTD); + + PORTD |= ((1 << cube_level)<< 3); // cube_level setzen (Ebene A=0, B=1, C=2) + + printf("Level festlegen: PORTD = 0x%2x\n", PORTD); + + int tmp = cube_level * 9; + + printf("8 Bits aus cube: PORTD = 0x%2x\n", ((~cube & (0xff << tmp)) >> tmp)); + // PORTB = 1..8 + // 0 = leuchtet, 1 = leuchtet nicht (invertiert!) + PORTB = ((~cube & (0xff << tmp)) >> tmp); + + printf("Pins1-8: PORTB = 0x%2x\n", PORTB); + + // PORTD &= 0b10111111; // bereits oben erledigt + PORTD |= (((~cube & (1 << (tmp+8))) >> (tmp+8)) << 6); + + printf("Pin9: PORTD = 0x%2x\n", PORTD); + + cube_level++; + if (cube_level > 2) cube_level = 0; + + } + +} + From 0a316aaed93caae9fcf01dd5be73c690a0f5d4bb Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Wed, 30 Nov 2011 20:45:22 +0100 Subject: [PATCH 05/12] First working version of the ISR to control the LEDs. --- firmware/globals.h | 4 ---- firmware/main.c | 44 +++++++++++++++++++++++++++++++++++--------- firmware/main.h | 4 +++- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/firmware/globals.h b/firmware/globals.h index b3827b0..1bb565a 100644 --- a/firmware/globals.h +++ b/firmware/globals.h @@ -8,10 +8,6 @@ #define FALSE 0 #define TRUE 1 -// Definitionen -#define PIXEL_TON 30 -#define PIXEL_TOFF 10 - #define sleep_nop(cnt) for (uint8_t i = 0; i < cnt; i++) { asm volatile("nop"::); } // Pixelmakros diff --git a/firmware/main.c b/firmware/main.c index 5855a1d..e8588e4 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -16,6 +16,8 @@ int main(void) init(); init_usb(); + uint8_t anim = 0; + // Hauptschleife //while (1) for (;;) @@ -26,6 +28,19 @@ int main(void) // hier pause einfügen _delay_ms(50); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation + anim++; + + if (anim == 40) + { + if (cube == 0xffffffff) + cube = 0x07007007; + else if (cube == 0x07007007) + cube = 0x00000000; + else if (cube == 0x00000000) + cube = 0xffffffff; + anim = 0; + } + } } @@ -36,8 +51,8 @@ void init() DDRB = 0b11111111; // PB0-PB7: LED 1-8 (Kathoden) PORTB = 0b11111111; // HIGH - DDRD = 0b1111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden) - PORTD = 0b1000000; + DDRD = 0b01111000; // PD6: LED 9 (Kathode); PD5-PD3: A-C (Anoden) + PORTD = 0b01000000; // Timer-Interrupt "TIMER1" vorbereiten //cli(); // @@ -67,17 +82,28 @@ void init() ISR (TIMER1_COMPA_vect) { // PORTD = __, 9, C, B, A,D+,D-,__ - PORTD &= 0b11000111; // Reset durch Bitmaske - PORTD |= ((1 << (cube_level))<< 3); // Level setzen (A=0, B=1, C=2) + PORTD &= 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren + PORTD |= ((1 << cube_level) << 3); // cube_level setzen (Ebene A=0, B=1, C=2) + + uint32_t tmp = cube_level * 9; + uint32_t tmp1 = tmp + 8; // PORTB = 1..8 // 0 = leuchtet, 1 = leuchtet nicht (invertiert!) - PORTB = ~(cube & (0b11111111 << (cube_level*9))); + //PORTB = ~((uint32_t)(cube & (0b11111111 << tmp)) >> tmp); + //PORTB = ((uint32_t)(~cube & (uint32_t)(0xff << tmp)) >> tmp); + PORTB = ~((cube >> tmp) & 0xff); - PORTD &= 0b10111111; // 7tes Bit löschen (9) - PORTD |= ~((cube & (1 << (cube_level*9+8))) << 6); + // PORTD &= 0b10111111; // bereits oben erledigt + //PORTD |= ~(((uint32_t)(cube & (1 << (tmp+8))) >> (tmp+8)) << 6); + //PORTD |= (((~cube & (1 << tmp)) >> tmp) << 6); + if ( (((cube >> tmp) >> 8) & 0x01) == 1 ) + PORTD &= ~(1 << 6); + else + PORTD |= (1 << 6); + //PORTD |= (1 << 6); // test to always off - //cube_level++; - //if (cube_level > 2) cube_level = 0; + cube_level++; + if (cube_level > 2) cube_level = 0; } diff --git a/firmware/main.h b/firmware/main.h index 0cc7dc8..b11f28e 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -20,7 +20,9 @@ //#include // Cube-Data -volatile uint32_t cube = 0x0000000F; // Aktuelle Frame +//volatile uint32_t cube = 0x07007007; // Aktuelles Frame +volatile uint32_t cube = 0xffffffff; // Aktuelles Frame +//volatile uint32_t cube = 0x00000000; // Aktuelles Frame // Bit Offset in Cube-Data volatile uint8_t cube_level = 0; // Ebene From c175dc0ad82040aa569ba32e52549285cd804530 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Wed, 30 Nov 2011 20:47:37 +0100 Subject: [PATCH 06/12] Some other files to ignore. --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 2920d97..c84e492 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ firmware/.dep *.lss *.s#* *.b#* +*.eep +*.map +*.sym + From 4697706a2c50f121a061434c89d4d9ea78858f0a Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Fri, 2 Dec 2011 10:08:28 +0100 Subject: [PATCH 07/12] First stable usb connection lsusb report. --- doc/lsusb.txt | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 doc/lsusb.txt diff --git a/doc/lsusb.txt b/doc/lsusb.txt new file mode 100644 index 0000000..3516739 --- /dev/null +++ b/doc/lsusb.txt @@ -0,0 +1,59 @@ + +Bus 002 Device 013: ID 16c0:05df VOTI +Device Descriptor: + bLength 18 + bDescriptorType 1 + bcdUSB 1.10 + bDeviceClass 0 (Defined at Interface level) + bDeviceSubClass 0 + bDeviceProtocol 0 + bMaxPacketSize0 8 + idVendor 0x16c0 VOTI + idProduct 0x05df + bcdDevice 1.00 + iManufacturer 1 CTHN.de + iProduct 2 MiniLEDCube + iSerial 0 + bNumConfigurations 1 + Configuration Descriptor: + bLength 9 + bDescriptorType 2 + wTotalLength 34 + bNumInterfaces 1 + bConfigurationValue 1 + iConfiguration 0 + bmAttributes 0x80 + (Bus Powered) + MaxPower 250mA + Interface Descriptor: + bLength 9 + bDescriptorType 4 + bInterfaceNumber 0 + bAlternateSetting 0 + bNumEndpoints 1 + bInterfaceClass 3 Human Interface Device + bInterfaceSubClass 0 No Subclass + bInterfaceProtocol 0 None + iInterface 0 + HID Device Descriptor: + bLength 9 + bDescriptorType 33 + bcdHID 1.01 + bCountryCode 0 Not supported + bNumDescriptors 1 + bDescriptorType 34 Report + wDescriptorLength 22 + Report Descriptors: + ** UNAVAILABLE ** + Endpoint Descriptor: + bLength 7 + bDescriptorType 5 + bEndpointAddress 0x81 EP 1 IN + bmAttributes 3 + Transfer Type Interrupt + Synch Type None + Usage Type Data + wMaxPacketSize 0x0008 1x 8 bytes + bInterval 10 +Device Status: 0x0000 + (Bus Powered) From 9a8082065a6c7cead2b734c908ef31b147848a99 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Fri, 2 Dec 2011 14:45:07 +0100 Subject: [PATCH 08/12] Simple test. --- client/test.c | 51 +++++++++++++++------------------------------------ 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/client/test.c b/client/test.c index 493a6ef..15932c6 100644 --- a/client/test.c +++ b/client/test.c @@ -33,7 +33,7 @@ usb_dev_handle *handle = NULL; const unsigned char rawVid[2] = {USB_CFG_VENDOR_ID}, rawPid[2] = {USB_CFG_DEVICE_ID}; char vendor[] = {USB_CFG_VENDOR_NAME, 0}, product[] = {USB_CFG_DEVICE_NAME, 0}; char buffer[4]; -int cnt, vid, pid; +int vid, pid; usb_init(); @@ -67,43 +67,22 @@ int cnt, vid, pid; } #endif - int i,x,y,z,onoff = 0; - while (1) - { - onoff = (onoff == 0) ? 1 : 0; - for (x = 0; x <3; x++) - for (y = 0; y <3; y++) - for (z = 0; z <3; z++) - { - for (i = 0; i < 4; i++) - { - int v = 0; - if (i == 0) - v = x; - if (i == 1) - v = y; - if (i == 2) - v = z; - if (i == 3) - v = onoff; - cnt = -1; - do { - sleep(1); - cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, v, 0, buffer, 0, 5000); - if (cnt < 0) - { - if (usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ - fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid); - exit(1); - } - } - } while (cnt < 0); + // int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout); + // 32 bit in 2 transmission + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x7007, 0x1B, buffer, 0, 5000); + sleep(2); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x0700, 0x1C, buffer, 0, 5000); - } + // bitwise set/get + //usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, 25, buffer, 0, 5000); + sleep(2); - fprintf(stdout, "%d %d %d %d\n",x,y,z,onoff); - } - } + int i = 0; + for (i = 0; i < 27; i++) + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 1, i, buffer, 0, 5000); + + for (i = 26; i >= 0; i--) + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, i, buffer, 0, 5000); usb_close(handle); return 0; From 09f600f9e1de4c6f000473843ca42a16684ed646 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Fri, 2 Dec 2011 14:47:59 +0100 Subject: [PATCH 09/12] First implementation of the USB communication. --- firmware/main.c | 37 ++++++++++++++++++++++++------------- firmware/main.h | 3 --- firmware/usb.c | 43 +++++++++++++++++++------------------------ firmware/usb.h | 6 +----- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index e8588e4..d6c05c7 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -16,7 +16,7 @@ int main(void) init(); init_usb(); - uint8_t anim = 0; + //uint8_t anim = 0; // Hauptschleife //while (1) @@ -28,9 +28,9 @@ int main(void) // hier pause einfügen _delay_ms(50); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation - anim++; + /*anim++; - if (anim == 40) + if (anim >= 0) { if (cube == 0xffffffff) cube = 0x07007007; @@ -38,8 +38,18 @@ int main(void) cube = 0x00000000; else if (cube == 0x00000000) cube = 0xffffffff; - anim = 0; - } + + anim = 0; + }*/ + /*if (anim >= 40) + { + cube += 1; + + if (cube > 0x07ffffff) + cube = 0; + + anim = 0; + }*/ } } @@ -58,7 +68,7 @@ void init() //cli(); // set_bit(TIMSK, OCIE1A); // Interrupt für ISR COMPA - set_bit(TCCR1B, WGM12); // Überlauf + //set_bit(TCCR1B, WGM12); // Überlauf // Animations-Geschwindigkeit // (vergleichswert bei dem der Interrupt ausgelöst wird) @@ -68,11 +78,10 @@ void init() // 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); - - + //clear_bit(TCCR1B, CS12); // Prescaler 64 + //set_bit(TCCR1B, CS11); + //set_bit(TCCR1B, CS10); + TCCR1B |= (1 << CS11) | (1 << CS10) | (1 << WGM12); sei(); // Set enable interrupt bit (Muss gesetzt werden damit es überhaupt aufgerufen wird) } @@ -81,12 +90,12 @@ void init() //SIGNAL(SIG_OUTPUT_COMPARE1A) // alte schreibweise ISR (TIMER1_COMPA_vect) { - // PORTD = __, 9, C, B, A,D+,D-,__ + + // PORTD = __, 9, C, B, A,D+,D-,__ PORTD &= 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren PORTD |= ((1 << cube_level) << 3); // cube_level setzen (Ebene A=0, B=1, C=2) uint32_t tmp = cube_level * 9; - uint32_t tmp1 = tmp + 8; // PORTB = 1..8 // 0 = leuchtet, 1 = leuchtet nicht (invertiert!) @@ -101,9 +110,11 @@ ISR (TIMER1_COMPA_vect) PORTD &= ~(1 << 6); else PORTD |= (1 << 6); + //PORTD |= (1 << 6); // test to always off cube_level++; if (cube_level > 2) cube_level = 0; + } diff --git a/firmware/main.h b/firmware/main.h index b11f28e..4453228 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -16,8 +16,6 @@ #include #include #include -//#include -//#include // Cube-Data //volatile uint32_t cube = 0x07007007; // Aktuelles Frame @@ -28,7 +26,6 @@ volatile uint8_t cube_level = 0; // Ebene // Prototypen void init(void); -void loop(uint8_t); extern void init_usb(void); extern void usbPoll(void); diff --git a/firmware/usb.c b/firmware/usb.c index 6c5fddf..045faef 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -19,29 +19,25 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) if ( rq->bRequest == CUSTOM_RQ_SET_STATUS ) { -/* - if (rq->wIndex.bytes[0] == 0) - cube[0][0][0] = 1; - if (rq->wIndex.bytes[0] == 1) - cube[0][0][1] = 1; - if (rq->wIndex.bytes[0] == 2) - cube[0][0][2] = 1; - if (rq->wIndex.bytes[0] == 3) - cube[0][1][0] = 1; + if ( rq->wIndex.bytes[0] == 27 ) + { + cube = (cube & (uint32_t)0xffff0000) | + rq->wValue.bytes[0] + + (rq->wValue.bytes[1] << 8); + } else if ( rq->wIndex.bytes[0] == 28 ) + { + cube = (cube & (uint32_t)0x0000ffff) | + ((uint32_t)(rq->wValue.bytes[0] + + (rq->wValue.bytes[1] << 8)) << 16); + } else if ( rq->wIndex.bytes[0] < 27 ) + { + if ( rq->wValue.bytes[0] == 1 ) + cube |= ((uint32_t)1 << rq->wIndex.bytes[0]); + else + cube &= ~((uint32_t)1 << rq->wIndex.bytes[0]); + } - if (rq->wIndex.bytes[0] == 0) - x = rq->wValue.bytes[0]; - - else if (rq->wIndex.bytes[0] == 1) - y = rq->wValue.bytes[0]; - - else if (rq->wIndex.bytes[0] == 2) - z = rq->wValue.bytes[0]; - - else if (rq->wIndex.bytes[0] == 3) - //cube[x][y][z] = rq->wValue.bytes[0]; - - } else if ( rq->bRequest == CUSTOM_RQ_GET_STATUS ) { + //} else if ( rq->bRequest == CUSTOM_RQ_GET_STATUS ) { // Send one byte to the USB host. //static uchar dataBuffer[1]; // buffer must stay valid when usbFunctionSetup returns @@ -49,9 +45,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) //return 1; // tell the driver to send 1 byte //return 0; // tell the driver to send 0 byte -*/ } - }else{ + //} else { /* class requests USBRQ_HID_GET_REPORT and USBRQ_HID_SET_REPORT are * not implemented since we never call them. The operating system * won't call them either because our descriptor defines no meaning. diff --git a/firmware/usb.h b/firmware/usb.h index 5db1cec..8e7fb82 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -55,14 +55,10 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ void init_usb(void); -/*volatile uint8_t x; -volatile uint8_t y; -volatile uint8_t z;*/ - // usb buffer //extern uint8_t buffer[3][3][3]; // Framebuffer //extern uint8_t cube[3][3][3]; // Framebuffer -extern uint32_t cube; // Framebuffer +extern volatile uint32_t cube; // Framebuffer #endif // __usb_h__ From 28bd57a8fbca088b44cfbb9dc88d988ffc142490 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Mon, 5 Dec 2011 19:14:06 +0100 Subject: [PATCH 10/12] Timeout reduced. --- client/test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/test.c b/client/test.c index 15932c6..6e03b0b 100644 --- a/client/test.c +++ b/client/test.c @@ -69,20 +69,20 @@ int vid, pid; // int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout); // 32 bit in 2 transmission - usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x7007, 0x1B, buffer, 0, 5000); - sleep(2); - usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x0700, 0x1C, buffer, 0, 5000); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x7007, 0x1B, buffer, 0, 300); + //sleep(2); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0x0700, 0x1C, buffer, 0, 300); // bitwise set/get //usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, 25, buffer, 0, 5000); - sleep(2); + sleep(5); int i = 0; for (i = 0; i < 27; i++) - usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 1, i, buffer, 0, 5000); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 1, i, buffer, 0, 300); for (i = 26; i >= 0; i--) - usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, i, buffer, 0, 5000); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, i, buffer, 0, 300); usb_close(handle); return 0; From 66c84c6415b2f0527ece8d4e3bfe632810f2e182 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Mon, 5 Dec 2011 20:37:10 +0100 Subject: [PATCH 11/12] Some sleep call's added. --- client/test.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/test.c b/client/test.c index 6e03b0b..2d76f9e 100644 --- a/client/test.c +++ b/client/test.c @@ -79,10 +79,16 @@ int vid, pid; int i = 0; for (i = 0; i < 27; i++) + { usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 1, i, buffer, 0, 300); + sleep(1); + } for (i = 26; i >= 0; i--) + { usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, i, buffer, 0, 300); + sleep(1); + } usb_close(handle); return 0; From f8242b9ae37f97e6c95392d1b449933e9390bcac Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Mon, 5 Dec 2011 22:17:00 +0100 Subject: [PATCH 12/12] Delay call from mainloop removed because of faster usb communication. --- firmware/globals.h | 27 +-------------------------- firmware/main.c | 2 +- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/firmware/globals.h b/firmware/globals.h index 1bb565a..cddcba7 100644 --- a/firmware/globals.h +++ b/firmware/globals.h @@ -1,33 +1,8 @@ #define F_CPU 12000000UL -// Bitpopelei +// Bitshifting #define set_bit(var, bit) ((var) |= (1 << (bit))) #define clear_bit(var, bit) ((var) &= (unsigned)~(1 << (bit))) -// Bool -#define FALSE 0 -#define TRUE 1 - #define sleep_nop(cnt) for (uint8_t i = 0; i < cnt; i++) { asm volatile("nop"::); } -// Pixelmakros -#define PSET(x,y,z) (0b01000000 | ((z * 3 + x) + y * 9)) -#define PCLEAR(x,y,z) (0b00000000 | ((z * 3 + x) + y * 9)) - -// Instructions -#define CLEAR 0b10000000 -#define SET 0b10010000 -#define FPS 0b10110000 -#define NEXT 0b11110000 - -// Variablen -#define VAR_FPS 0 - -// Für CLEAR und SET -#define CLEAR_ALL 0 -#define SET_ALL 0 - -// Für NEXT -#define JUMP_FORWARD 1 -#define JUMP_BACKWARD 2 - diff --git a/firmware/main.c b/firmware/main.c index d6c05c7..62ec55c 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -26,7 +26,7 @@ int main(void) usbPoll(); // keep connected // hier pause einfügen - _delay_ms(50); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation + //_delay_ms(1); // beispielsweise 50 ms => muss angepasst werden an usb kommunikation /*anim++;