From b5f34edfe75543109080c5557b20a5dea8446f27 Mon Sep 17 00:00:00 2001 From: bg Date: Wed, 16 Oct 2013 14:01:55 +0200 Subject: [PATCH] removing color stuff; introducing debug stuff --- firmware/main.c | 69 +++++++++++---------------------------------- firmware/requests.h | 13 +++++---- 2 files changed, 24 insertions(+), 58 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index cdbc69d..a266a59 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -145,17 +145,11 @@ PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] #define CAPS_LOCK 2 #define SCROLL_LOCK 4 -union { - struct { - uint16_t red; - uint16_t green; - uint16_t blue; - } name; - uint16_t idx[3]; -} color; #define UNI_BUFFER_SIZE 16 +static uint8_t dbg_buffer[8]; + static union { uint8_t w8[UNI_BUFFER_SIZE]; uint16_t w16[UNI_BUFFER_SIZE/2]; @@ -219,35 +213,10 @@ uint16_t read_temperture_sensor(void){ return ADC; } -#if 0 -uchar usbFunctionSetup(uchar data[8]) -{ -usbRequest_t *rq = (void *)data; - - usbMsgPtr = reportBuffer; - if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */ - if(rq->bRequest == USBRQ_HID_GET_REPORT){ /* wValue: ReportType (highbyte), ReportID (lowbyte) */ - /* we only have one report type, so don't look at wValue */ - buildReport(keyPressed()); - return sizeof(reportBuffer); - }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ - usbMsgPtr = &idleRate; - return 1; - }else if(rq->bRequest == USBRQ_HID_SET_IDLE){ - idleRate = rq->wValue.bytes[1]; - } - }else{ - /* no vendor specific requests implemented */ - } - return 0; -} -#endif - usbMsgLen_t usbFunctionSetup(uchar data[8]) { usbRequest_t *rq = (usbRequest_t *)data; if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ - color.name.red = 13; switch(rq->bRequest) { case USBRQ_HID_GET_REPORT: // send "no keys pressed" if asked here // wValue: ReportType (highbyte), ReportID (lowbyte) @@ -273,14 +242,20 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) current_command = rq->bRequest; switch(rq->bRequest) { - case CUSTOM_RQ_SET_RGB: + case CUSTOM_RQ_PRESS_BUTTON: + key_state = STATE_SEND_KEY; + return 0; + case CUSTOM_RQ_CLR_DBG: + memset(dbg_buffer, 0, sizeof(dbg_buffer)); + return 0; + case CUSTOM_RQ_SET_DBG: return USB_NO_MSG; - case CUSTOM_RQ_GET_RGB:{ - usbMsgLen_t len = 6; - if(len>rq->wLength.word){ + case CUSTOM_RQ_GET_DBG:{ + usbMsgLen_t len = 8; + if(len > rq->wLength.word){ len = rq->wLength.word; } - usbMsgPtr = (uchar*)color.idx; + usbMsgPtr = dbg_buffer; return len; } case CUSTOM_RQ_READ_MEM: @@ -322,12 +297,11 @@ uchar usbFunctionWrite(uchar *data, uchar len) if (data[0] != LED_state) LED_state = data[0]; return 1; // Data read, not expecting more - case CUSTOM_RQ_SET_RGB: - if(len != 6){ - return 1; + case CUSTOM_RQ_SET_DBG: + if(len > sizeof(dbg_buffer)){ + len = sizeof(dbg_buffer); } - memcpy(color.idx, data, 6); - key_state = STATE_SEND_KEY; + memcpy(dbg_buffer, data, len); return 1; case CUSTOM_RQ_WRITE_MEM: memcpy(uni_buffer.ptr[0], data, len); @@ -449,28 +423,19 @@ int main(void) wdt_reset(); usbPoll(); - if(usbInterruptIsReady()) - color.name.green = 0x10 | key_state; - else - color.name.green = 0; - if(usbInterruptIsReady() && key_state != STATE_WAIT){ - color.name.red = 16; switch(key_state) { case STATE_SEND_KEY: - color.name.red = 17; buildReport('x'); key_state = STATE_RELEASE_KEY; // release next break; case STATE_RELEASE_KEY: - color.name.red = 18; buildReport(0); default: key_state = STATE_WAIT; // should not happen } // start sending usbSetInterrupt((void *)&keyboard_report, sizeof(keyboard_report)); - color.name.red |= 0x40; } diff --git a/firmware/requests.h b/firmware/requests.h index b5160ea..358982c 100644 --- a/firmware/requests.h +++ b/firmware/requests.h @@ -16,12 +16,13 @@ #ifndef __REQUESTS_H_INCLUDED__ #define __REQUESTS_H_INCLUDED__ -#define CUSTOM_RQ_SET_RED 3 -#define CUSTOM_RQ_SET_GREEN 4 -#define CUSTOM_RQ_SET_BLUE 5 -#define CUSTOM_RQ_SET_RGB 6 -#define CUSTOM_RQ_GET_RGB 7 -#define CUSTOM_RQ_GET_ADC 8 +#define CUSTOM_RQ_PRESS_BUTTON 0x04 + +#define CUSTOM_RQ_CLR_DBG 0x05 +#define CUSTOM_RQ_SET_DBG 0x06 +#define CUSTOM_RQ_GET_DBG 0x07 + +#define CUSTOM_RQ_GET_ADC 0x08 #define CUSTOM_RQ_READ_MEM 0x10 #define CUSTOM_RQ_WRITE_MEM 0x11 #define CUSTOM_RQ_READ_FLASH 0x12 -- 2.39.5