From 46e9b3d1c8a23c3884c8edf4ace96ff650333648 Mon Sep 17 00:00:00 2001 From: bg Date: Sun, 20 Oct 2013 13:11:51 +0200 Subject: [PATCH] some minor fixes --- firmware/main.c | 27 ++++++++++++--------------- hostware/commandline/main.c | 14 +++++++++----- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/firmware/main.c b/firmware/main.c index b1afcdc..247fced 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -50,6 +50,8 @@ at least be connected to INT0 as well. #define STATE_RELEASE_KEY 2 #define STATE_NEXT 3 +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ 0x09, 0x06, /* USAGE (Keyboard) */ @@ -340,23 +342,23 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) return 0; case CUSTOM_RQ_SET_DBG: return USB_NO_MSG; - case CUSTOM_RQ_GET_DBG:{ - usbMsgLen_t len = 8; - if(len > rq->wLength.word){ - len = rq->wLength.word; - } + case CUSTOM_RQ_GET_DBG: usbMsgPtr = dbg_buffer; - return len; - } + return MIN(8, rq->wLength.word); case CUSTOM_RQ_RESET: soft_reset((uint8_t)(rq->wValue.word)); break; case CUSTOM_RQ_READ_BUTTON: uni_buffer.w8[0] = button_get_debounced(DEBOUNCE_DELAY); return 1; +#if ALLOW_SECRET_READ case CUSTOM_RQ_GET_SECRET: - uni_buffer.w8[0] = 0; + uni_buffer.w8[0] = 0; return USB_NO_MSG; +#else +#endif + default: + return 0; } } @@ -389,17 +391,12 @@ uchar usbFunctionWrite(uchar *data, uchar len) len = sizeof(dbg_buffer); } memcpy(dbg_buffer, data, len); - return 1; - default: - return 1; } - return 0; + return 1; } -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - uchar usbFunctionRead(uchar *data, uchar len){ -#if ALLOW_SECRET_READ +#if ALLOW_SECRET_READ || 1 uchar r; uint8_t s_length_B; switch(current_command){ diff --git a/hostware/commandline/main.c b/hostware/commandline/main.c index 202dbee..18e9547 100644 --- a/hostware/commandline/main.c +++ b/hostware/commandline/main.c @@ -78,7 +78,7 @@ void set_dbg(char *hex_string){ } void get_dbg(char *param){ - uint16_t buffer[256]; + uint8_t buffer[256]; int cnt; cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_DBG, 0, 0, (char*)buffer, 256, 5000); printf("DBG-Buffer:\n"); @@ -191,11 +191,15 @@ void read_button(char* param){ } void get_secret(char *param){ - uint16_t buffer[256]; + uint8_t buffer[64]; int cnt; - cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_SECRET, 0, 0, (char*)buffer, 256, 5000); - printf("Secret:\n"); - hexdump_block(stdout, buffer, 0, cnt, 16); + cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_SECRET, 0, 0, (char*)buffer, 32, 5000); + if (cnt > 0) { + printf("Secret (%d):\n", cnt); + hexdump_block(stdout, buffer, NULL, cnt, 16); + } else { + fprintf(stderr, "Error: usb_control_msg(...) returned %d\n", cnt); + } } -- 2.39.5