summaryrefslogtreecommitdiff
path: root/ps2_vusb
diff options
context:
space:
mode:
Diffstat (limited to 'ps2_vusb')
-rw-r--r--ps2_vusb/config.h28
-rw-r--r--ps2_vusb/host.h1
-rw-r--r--ps2_vusb/host_vusb.c73
-rw-r--r--ps2_vusb/host_vusb.h1
-rw-r--r--ps2_vusb/keyboard.c18
-rw-r--r--ps2_vusb/keyboard.h1
-rw-r--r--ps2_vusb/main.c12
-rw-r--r--ps2_vusb/matrix.c54
-rw-r--r--ps2_vusb/usbconfig.h2
9 files changed, 123 insertions, 67 deletions
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<<INT1); \
+ EICRA |= ((1<<ISC11) | (0<<ISC10)); \
+ EIFR |= (1<<INTF1); \
+} while (0)
+#define PS2_INT_DISABLE() do { \
+ EIMSK &= ~(1<<INT1); \
+} while (0)
+#define PS2_INT_VECT INT1_vect
+
+/* Pin Change interrupt for PS/2 clock line (optional)
+#define PS2_INT_ENABLE() do { \
+ PCMSK2 |= (1<<PCINT22); \
+ PCICR |= (1<<PCIE2); \
+ PCIFR |= (1<<PCIF2); \
+} while (0)
+#define PS2_INT_DISABLE() do { \
+ PCMSK2 &= ~(1<<PCINT22); \
+ PCICR &= ~(1<<PCIE); \
+} while (0)
+#define PS2_INT_VECT PCINT2_vect
+*/
+
#endif
diff --git a/ps2_vusb/host.h b/ps2_vusb/host.h
index b4b9eefbe1..fa7e79910b 100644
--- a/ps2_vusb/host.h
+++ b/ps2_vusb/host.h
@@ -29,6 +29,7 @@ typedef struct {
} report_mouse_t;
+extern uint8_t host_keyboard_led;
void host_keyboard_send(report_keyboard_t *report);
void host_mouse_send(report_mouse_t *report);
diff --git a/ps2_vusb/host_vusb.c b/ps2_vusb/host_vusb.c
index cda9048789..060d23c186 100644
--- a/ps2_vusb/host_vusb.c
+++ b/ps2_vusb/host_vusb.c
@@ -6,7 +6,7 @@
#include "host_vusb.h"
-#define KBUF_SIZE 8
+#define KBUF_SIZE 16
static report_keyboard_t kbuf[KBUF_SIZE];
static uint8_t kbuf_head = 0;
static uint8_t kbuf_tail = 0;
@@ -14,12 +14,18 @@ static uint8_t kbuf_tail = 0;
void host_vusb_keyboard_send()
{
+ while (usbInterruptIsReady() && kbuf_head != kbuf_tail) {
+ usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
+ kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
+ }
+/*
if (kbuf_head != kbuf_tail) {
if (usbInterruptIsReady()) {
usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
}
}
+*/
}
void host_keyboard_send(report_keyboard_t *report)
@@ -28,14 +34,20 @@ void host_keyboard_send(report_keyboard_t *report)
if (next != kbuf_tail) {
kbuf[kbuf_head] = *report;
kbuf_head = next;
+ print("kbuf: "); phex(kbuf_head); phex(kbuf_tail); print("\n");
+ } else {
+ print("kbuf: full\n");
+ // hmm...
+ /*
+ matrix_init();
+ kbuf_head = 0;
+ kbuf_tail = 0;
+ */
}
}
void host_mouse_send(report_mouse_t *report)
{
- // dirty hack to send twice a loop :(
- //while (!usbInterruptIsReady3()) usbPoll();
-
if (usbInterruptIsReady3()) {
usbSetInterrupt3((void *)report, sizeof(*report));
} else {
@@ -46,30 +58,51 @@ void host_mouse_send(report_mouse_t *report)
+static struct {
+ uint16_t len;
+ enum {
+ NONE,
+ SET_LED
+ } kind;
+} last_req;
+
+uint8_t host_keyboard_led = 0;
+static uchar idleRate;
-static uchar idleRate; /* repeat rate for keyboards, never used for mice */
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
usbRequest_t *rq = (void *)data;
- print("Setup: ");
+ //print("Setup: ");
if((rq->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<<USB_LED_SCROLL_LOCK))
+ ps2_led |= (1<<PS2_LED_SCROLL_LOCK);
+ if (usb_led & (1<<USB_LED_NUM_LOCK))
+ ps2_led |= (1<<PS2_LED_NUM_LOCK);
+ if (usb_led & (1<<USB_LED_CAPS_LOCK))
+ ps2_led |= (1<<PS2_LED_CAPS_LOCK);
+ print("ps2_led: "); phex(ps2_led); print("\n");
+
+ ps2_host_set_led(ps2_led);
+}
+
void keyboard_send(void)
{
host_keyboard_send(report);
diff --git a/ps2_vusb/keyboard.h b/ps2_vusb/keyboard.h
index bc6b214937..d8604bb956 100644
--- a/ps2_vusb/keyboard.h
+++ b/ps2_vusb/keyboard.h
@@ -6,6 +6,7 @@
#include "host.h"
+void keyboard_set_led(uint8_t led);
void keyboard_send(void);
bool keyboard_has_key(void);
void keyboard_add_mod(uint8_t mod);
diff --git a/ps2_vusb/main.c b/ps2_vusb/main.c
index e692924e79..16dea9aaaf 100644
--- a/ps2_vusb/main.c
+++ b/ps2_vusb/main.c
@@ -28,9 +28,13 @@
#include "host_vusb.h"
#include "timer.h"
+#define DEBUGP_INIT() do { DDRC = 0xFF; } while (0)
+#define DEBUGP(x) do { PORTC = x; } while (0)
+static uint8_t last_led = 0;
int main(void)
{
+ DEBUGP_INIT();
wdt_enable(WDTO_1S);
/* 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!
@@ -60,10 +64,12 @@ int main(void)
uint8_t fn_bits = 0;
while (1) { /* main event loop */
+ DEBUGP(0x01);
wdt_reset();
usbPoll();
host_vusb_keyboard_send();
+ DEBUGP(0x02);
matrix_scan();
fn_bits = 0;
keyboard_swap_report();
@@ -94,10 +100,16 @@ int main(void)
}
}
}
+ DEBUGP(0x03);
layer_switching(fn_bits);
if (matrix_is_modified()) {
keyboard_send();
}
mousekey_send();
+
+ if (last_led != host_keyboard_led) {
+ keyboard_set_led(host_keyboard_led);
+ last_led = host_keyboard_led;
+ }
}
}
diff --git a/ps2_vusb/matrix.c b/ps2_vusb/matrix.c
index bd9b92446c..f04f6b7674 100644
--- a/ps2_vusb/matrix.c
+++ b/ps2_vusb/matrix.c
@@ -60,8 +60,6 @@ static bool matrix_has_ghost_in_row(uint8_t row);
#endif
static void matrix_make(uint8_t code);
static void matrix_break(uint8_t code);
-static void ps2_reset(void);
-static void ps2_set_leds(uint8_t leds);
inline
@@ -79,19 +77,7 @@ uint8_t matrix_cols(void)
void matrix_init(void)
{
ps2_host_init();
- _delay_ms(1000);
- // flush LEDs
-/*
- ps2_set_leds(1<<PS2_LED_NUM_LOCK);
- _delay_ms(100);
- ps2_set_leds(1<<PS2_LED_NUM_LOCK|1<<PS2_LED_CAPS_LOCK);
- _delay_ms(100);
- ps2_set_leds(1<<PS2_LED_NUM_LOCK|1<<PS2_LED_CAPS_LOCK|1<<PS2_LED_SCROLL_LOCK);
- _delay_ms(300);
- ps2_set_leds(0x00);
-*/
-
// initialize matrix state: all keys off
for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
@@ -190,10 +176,7 @@ uint8_t matrix_scan(void)
}
uint8_t code;
- code = ps2_host_recv();
- if (code == 0x00) return 0;
- //while ((code = ps2_host_recv())) {
-//phex(code); print(" ");
+ while ((code = ps2_host_recv())) {
switch (state) {
case INIT:
switch (code) {
@@ -350,26 +333,7 @@ uint8_t matrix_scan(void)
default:
state = INIT;
}
- //}
-//print("|");
-
- // handle LED indicators
-/*
- static uint8_t prev_leds = 0;
- if (prev_leds != usb_keyboard_leds) {
- uint8_t leds = 0;
- if (usb_keyboard_leds&(1<<USB_LED_SCROLL_LOCK))
- leds |= (1<<PS2_LED_SCROLL_LOCK);
- if (usb_keyboard_leds&(1<<USB_LED_NUM_LOCK))
- leds |= (1<<PS2_LED_NUM_LOCK);
- if (usb_keyboard_leds&(1<<USB_LED_CAPS_LOCK))
- leds |= (1<<PS2_LED_CAPS_LOCK);
-
- ps2_set_leds(leds);
- prev_leds = usb_keyboard_leds;
}
-*/
-
return 1;
}
@@ -479,19 +443,3 @@ static void matrix_break(uint8_t code)
//print("matrix_break: "); phex(code); print("\n");
}
}
-
-static void ps2_reset(void)
-{
- ps2_host_send(0xFF);
- if (ps2_host_recv() != 0xFA) return;
- _delay_ms(1000);
- if (ps2_host_recv() != 0xAA) return;
-}
-
-static void ps2_set_leds(uint8_t leds)
-{
- ps2_host_send(0xED);
- if (ps2_host_recv() != 0xFA) return; // 0xFA
- ps2_host_send(leds);
- if (ps2_host_recv() != 0xFA) return; // 0xFA
-}
diff --git a/ps2_vusb/usbconfig.h b/ps2_vusb/usbconfig.h
index 84fc6fd3fb..abc31ced54 100644
--- a/ps2_vusb/usbconfig.h
+++ b/ps2_vusb/usbconfig.h
@@ -121,7 +121,7 @@ section at the end of this file).
* The value is in milliamperes. [It will be divided by two since USB
* communicates power requirements in units of 2 mA.]
*/
-#define USB_CFG_IMPLEMENT_FN_WRITE 0
+#define USB_CFG_IMPLEMENT_FN_WRITE 1
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
* transfers. Set it to 0 if you don't need it and want to save a couple of
* bytes.