From 7c76f3303ec40ca2eec08ef6d86e32e1cdd635cc Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Sat, 10 Dec 2011 11:46:58 +0100 Subject: [PATCH] EEPROM write/read access via USB implemented. --- client/test.c | 8 ++++++-- firmware/Makefile | 16 +++++++++------- firmware/main.h | 3 +-- firmware/requests.h | 3 +++ firmware/usb.c | 23 ++++++++++++++++------- firmware/usb.h | 10 +++++++++- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/client/test.c b/client/test.c index 852824c..14e733a 100644 --- a/client/test.c +++ b/client/test.c @@ -67,11 +67,15 @@ int main(int argc, char **argv) } #endif + //usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_EEPROM, 0, 0, buffer, 0, 300); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_LOAD_EEPROM, 0, 1, buffer, 0, 300); + sleep(2); + // 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_FRAME, 0x7007, 0, buffer, 0, 300); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x7217, 0, buffer, 0, 300); //sleep(2); - usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0700, 1, buffer, 0, 300); + usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0743, 1, 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); diff --git a/firmware/Makefile b/firmware/Makefile index 44c7e72..a10c611 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -108,28 +108,30 @@ CINCS = -Iusbdrv # -Wall...: warning level # -Wa,...: tell GCC to pass this to the assembler. # -adhlns...: create assembler listing -CFLAGS = #-g$(DEBUG) -CFLAGS += $(CDEFS) $(CINCS) -CFLAGS += -O$(OPT) #CFLAGS += -funsigned-char #CFLAGS += -funsigned-bitfields #CFLAGS += -fpack-struct #CFLAGS += -fshort-enums #CFLAGS += -fno-split-wide-types -CFLAGS += -fno-move-loop-invariants -CFLAGS += -fno-tree-scev-cprop #CFLAGS += -fno-inline-small-functions #CFLAGS += -fno-tree-loop-optimize #CFLAGS += -mcall-prologues #CFLAGS += -mtiny-stack #CFLAGS += -mint8 +#CFLAGS += -fdata-sections +#CFLAGS = -g$(DEBUG) + +CFLAGS += -fno-move-loop-invariants +CFLAGS += -fno-tree-scev-cprop +CFLAGS += -ffunction-sections + +CFLAGS += $(CDEFS) $(CINCS) +CFLAGS += -O$(OPT) CFLAGS += -Wall -Wstrict-prototypes CFLAGS += -Wa,-adhlns=$(<:.c=.lst) CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) CFLAGS += $(CSTANDARD) CFLAGS += -DF_CPU=$(F_CPU) -CFLAGS += -ffunction-sections -#CFLAGS += -fdata-sections CFLAGS += -Wl,--gc-sections diff --git a/firmware/main.h b/firmware/main.h index c2556b2..609e9b6 100644 --- a/firmware/main.h +++ b/firmware/main.h @@ -16,11 +16,10 @@ #include #include - // Cube-Data uint32_t cube = 0xffffffff; // Bit Offset in Cube-Data -uint8_t cube_level; // = 0; // Ebene +uint8_t cube_level; // Aktive Ebene // Prototypen void init(void); diff --git a/firmware/requests.h b/firmware/requests.h index 5d1706c..ae94e0f 100644 --- a/firmware/requests.h +++ b/firmware/requests.h @@ -18,5 +18,8 @@ #define CUSTOM_RQ_SET_LED 1 #define CUSTOM_RQ_SET_FRAME 2 +#define CUSTOM_RQ_SET_EEPROM 3 +#define CUSTOM_RQ_GET_EEPROM 4 +#define CUSTOM_RQ_LOAD_EEPROM 5 #endif /* __REQUESTS_H_INCLUDED__ */ diff --git a/firmware/usb.c b/firmware/usb.c index 298adac..e1ed80a 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -25,6 +25,10 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) } else 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 ) { cube = (cube & (uint32_t)0xffff0000) | @@ -36,7 +40,14 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) (rq->wValue.bytes[1] << 8)) << 16); } + /*} else if ( rq->bRequest == CUSTOM_RQ_SET_EEPROM ) + { + eeprom_write_dword(&eep_anim[0], 0x07007007);*/ + } else if ( rq->bRequest == CUSTOM_RQ_LOAD_EEPROM ) + { + cube = eeprom_read_dword( &eep_anim[rq->wIndex.bytes[0]] ); } + } return 0; /* default for not implemented requests: return no data back to host */ } @@ -46,17 +57,15 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) void init_usb(void) { - uint8_t i, j, k; + uint8_t i; 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 */ - while(--k) - while(--j) { asm volatile("nop"::); } + // fake USB disconnect for > 250 ms + while(--i) + { + asm volatile("nop"::); } usbDeviceConnect(); diff --git a/firmware/usb.h b/firmware/usb.h index ca31d99..c15c8a3 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -10,6 +10,12 @@ #ifndef __usb_h__ #define __usb_h__ +#include + +#ifndef EEMEM +#define EEMEM __attribute__ ((section (".eeprom"))) +#endif + #include "globals.h" /* @@ -49,8 +55,10 @@ PROGMEM char usbHidReportDescriptor[22] = { /* USB report descriptor */ void init_usb(void); +uint32_t eep_anim[32] EEMEM; + // usb buffer -extern volatile uint32_t cube; // Framebuffer +extern uint32_t cube; // Framebuffer #endif // __usb_h__