From 1ceeaf0d1e2e62f9e0b643c753efdd17a7c1704b Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Sat, 10 Dec 2011 00:49:39 +0100 Subject: [PATCH] Some more changes. --- firmware/main.c | 5 ++--- firmware/main.h | 7 ++---- firmware/requests.h | 6 ++---- firmware/usb.c | 52 +++++++-------------------------------------- firmware/usb.h | 8 ------- 5 files changed, 14 insertions(+), 64 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index 9e7e30f..2b77d81 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -11,7 +11,8 @@ #include "main.h" // Main -int main(void) +int __attribute__((OS_main)) +main() { // Initialisierung init(); @@ -20,9 +21,7 @@ int main(void) // Hauptschleife for (;;) { - //wdt_reset(); // we are alive, so don't reset the µC usbPoll(); // keep connected - } } diff --git a/firmware/main.h b/firmware/main.h index 09f21a9..c2556b2 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -16,14 +16,11 @@ #include #include -#include // Cube-Data -//volatile uint32_t cube = 0x07007007; // Aktuelles Frame -volatile uint32_t cube = 0xffffffff; // Aktuelles Frame -//volatile uint32_t cube = 0x00000000; // Aktuelles Frame +uint32_t cube = 0xffffffff; // Bit Offset in Cube-Data -volatile uint8_t cube_level = 0; // Ebene +uint8_t cube_level; // = 0; // Ebene // Prototypen void init(void); diff --git a/firmware/requests.h b/firmware/requests.h index 0627a1f..5d1706c 100644 --- a/firmware/requests.h +++ b/firmware/requests.h @@ -16,9 +16,7 @@ #ifndef __REQUESTS_H_INCLUDED__ #define __REQUESTS_H_INCLUDED__ -#define CUSTOM_RQ_SET_LED 1 -#define CUSTOM_RQ_SET_FRAME 2 - -//#define CUSTOM_RQ_GET_STATUS 255 +#define CUSTOM_RQ_SET_LED 1 +#define CUSTOM_RQ_SET_FRAME 2 #endif /* __REQUESTS_H_INCLUDED__ */ diff --git a/firmware/usb.c b/firmware/usb.c index 03d11f9..298adac 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -28,29 +28,15 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) if ( rq->wIndex.bytes[0] == 0 ) { cube = (cube & (uint32_t)0xffff0000) | - rq->wValue.bytes[0] + - (rq->wValue.bytes[1] << 8); - //} else if ( rq->wIndex.bytes[0] == 1 ) + ( rq->wValue.bytes[0] + + (rq->wValue.bytes[1] << 8)); } else { cube = (cube & (uint32_t)0x0000ffff) | ((uint32_t)(rq->wValue.bytes[0] + (rq->wValue.bytes[1] << 8)) << 16); } - //} 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 - //usbMsgPtr = 0; // tell the driver which data to return - //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 - * not implemented since we never call them. The operating system - * won't call them either because our descriptor defines no meaning. - */ } return 0; /* default for not implemented requests: return no data back to host */ } @@ -59,44 +45,22 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) void init_usb(void) { - uchar i; + + uint8_t i, j, k; usbInit(); usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */ i = 0; + j = 0; + k = 50; while(--i) { /* fake USB disconnect for > 250 ms */ - //wdt_reset(); - _delay_ms(1); - //sleep_nop(255); + while(--k) + while(--j) { asm volatile("nop"::); } } usbDeviceConnect(); - sei(); // enable global interrupts - } -/* TODO add to the projects main - - init_usb(); - - // Even if you don't use the watchdog, turn it off here. On newer devices, - // the status of the watchdog (on/off, period) is PRESERVED OVER RESET! - // - // RESET status: all port bits are inputs without pull-up. - // That's the way we need D+ and D-. Therefore we don't need any - // additional hardware initialization. - wdt_enable(WDTO_1S); - - ...mainloop start... - - wdt_reset(); // we are alive, please dont reset the µC (optional) - usbPoll(); // keep the usb connection up - - ...end mainloop... - - -*/ - /* ------------------------------------------------------------------------- */ diff --git a/firmware/usb.h b/firmware/usb.h index 8e7fb82..ca31d99 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -21,12 +21,6 @@ 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 /* for sei() */ -//#include -//#include -#include /* for _delay_ms() */ -//#include /* required by usbdrv.h */ - #include "usbconfig.h" #include "usbdrv.h" #include "requests.h" /* The custom request numbers we use */ @@ -56,8 +50,6 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ void init_usb(void); // usb buffer -//extern uint8_t buffer[3][3][3]; // Framebuffer -//extern uint8_t cube[3][3][3]; // Framebuffer extern volatile uint32_t cube; // Framebuffer #endif // __usb_h__