From 04f351b80279c55dfc6c8028f95eab7e01d50c84 Mon Sep 17 00:00:00 2001 From: tmk Date: Mon, 7 Feb 2011 14:59:07 +0900 Subject: PS/2 library receives data partially by interrupt --- ps2_vusb/config.h | 28 ++++++++++++++++++-- ps2_vusb/host.h | 1 + ps2_vusb/host_vusb.c | 73 +++++++++++++++++++++++++++++++++++++++++++++------- ps2_vusb/host_vusb.h | 1 - ps2_vusb/keyboard.c | 18 +++++++++++++ ps2_vusb/keyboard.h | 1 + ps2_vusb/main.c | 12 +++++++++ ps2_vusb/matrix.c | 54 +------------------------------------- ps2_vusb/usbconfig.h | 2 +- 9 files changed, 123 insertions(+), 67 deletions(-) (limited to 'ps2_vusb') diff --git a/ps2_vusb/config.h b/ps2_vusb/config.h index 1d2a283071..639a1ac719 100644 --- a/ps2_vusb/config.h +++ b/ps2_vusb/config.h @@ -23,14 +23,38 @@ # define MOUSEKEY_DELAY_TIME 255 #endif -/* PS/2 mouse */ +/* PS/2 lines */ #define PS2_CLOCK_PORT PORTD #define PS2_CLOCK_PIN PIND #define PS2_CLOCK_DDR DDRD -#define PS2_CLOCK_BIT 6 +#define PS2_CLOCK_BIT 3 #define PS2_DATA_PORT PORTD #define PS2_DATA_PIN PIND #define PS2_DATA_DDR DDRD #define PS2_DATA_BIT 7 +/* External interrupt for PS/2 clock line (optional) */ +#define PS2_INT_ENABLE() do { \ + EIMSK |= (1<bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */ + /* print("CLASS: "); - phex(rq->bRequest); + phex(rq->bRequest); print(" "); + phex16(rq->wValue.word); print(" "); + phex16(rq->wIndex.word); print(" "); + phex16(rq->wLength.word); print(" "); + */ if(rq->bRequest == USBRQ_HID_GET_REPORT){ - print("GET_REPORT"); + print(" GET_REPORT"); /* we only have one report type, so don't look at wValue */ usbMsgPtr = (void *)keyboard_report; return sizeof(*keyboard_report); }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ - print("GET_IDLE: "); + print(" GET_IDLE: "); phex(idleRate); usbMsgPtr = &idleRate; return 1; }else if(rq->bRequest == USBRQ_HID_SET_IDLE){ idleRate = rq->wValue.bytes[1]; - print("SET_IDLE: "); + print(" SET_IDLE: "); phex(idleRate); + }else if(rq->bRequest == USBRQ_HID_SET_REPORT){ + //print(" SET_REPORT: "); + if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) { + last_req.kind = SET_LED; + last_req.len = rq->wLength.word; + } + return USB_NO_MSG; // to get data in usbFunctionWrite } print("\n"); }else{ @@ -79,6 +112,26 @@ usbRequest_t *rq = (void *)data; return 0; /* default for not implemented requests: return no data back to host */ } +uchar usbFunctionWrite(uchar *data, uchar len) +{ + if (last_req.len == 0) { + return -1; + } + switch (last_req.kind) { + case SET_LED: + //print("SET_LED\n"); + host_keyboard_led = data[0]; + last_req.len = 0; + return 1; + break; + case NONE: + default: + return -1; + break; + } + return 1; +} + PROGMEM uchar keyboard_hid_report[] = { 0x05, 0x01, // Usage Page (Generic Desktop), diff --git a/ps2_vusb/host_vusb.h b/ps2_vusb/host_vusb.h index c9b1d77671..f09ad58228 100644 --- a/ps2_vusb/host_vusb.h +++ b/ps2_vusb/host_vusb.h @@ -4,4 +4,3 @@ void host_vusb_keyboard_send(void); #endif - diff --git a/ps2_vusb/keyboard.c b/ps2_vusb/keyboard.c index 95f65887f8..c480908f84 100644 --- a/ps2_vusb/keyboard.c +++ b/ps2_vusb/keyboard.c @@ -1,12 +1,30 @@ #include "usb_keycodes.h" #include "host.h" +#include "ps2.h" +#include "usb.h" #include "keyboard.h" +#include "print.h" static report_keyboard_t report0; static report_keyboard_t report1; static report_keyboard_t *report = &report0; static report_keyboard_t *report_prev = &report1; + +void keyboard_set_led(uint8_t usb_led) +{ + uint8_t ps2_led = 0; + if (usb_led & (1<