summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2011-02-21 15:43:17 +0900
committertmk <nobody@nowhere>2011-02-22 03:09:14 +0900
commitfb8d23c60c757d5d9c2270cb0123a53be2049a28 (patch)
tree2f5d695f9d501468dc83f4861e7367cdf905ed3f
parent47f5d8b545eec12ca74d8e7048bb5daa290d937e (diff)
integrate V-USB support into ps2_usb
-rw-r--r--Makefile.rules11
-rw-r--r--command.c4
-rw-r--r--key_process.c392
-rw-r--r--key_process.h7
-rw-r--r--keyboard.c10
-rw-r--r--keymap.h (renamed from keymap_skel.h)7
-rw-r--r--layer.c2
-rw-r--r--main_pjrc.c97
-rw-r--r--matrix.h (renamed from matrix_skel.h)4
-rw-r--r--ps2.c12
-rw-r--r--ps2_usb/Makefile56
-rw-r--r--ps2_usb/Makefile.vusb (renamed from ps2_vusb/Makefile)10
-rw-r--r--ps2_usb/README15
-rw-r--r--ps2_usb/config_pjrc.h (renamed from ps2_usb/config.h)16
-rw-r--r--ps2_usb/config_vusb.h (renamed from ps2_vusb/config.h)6
-rw-r--r--ps2_usb/keymap.c9
-rw-r--r--ps2_usb/led.c (renamed from ps2_vusb/led.c)0
-rw-r--r--ps2_usb/main_vusb.c (renamed from ps2_vusb/main.c)2
-rw-r--r--ps2_usb/matrix.c50
-rw-r--r--ps2_usb/ps2_usart.c (renamed from ps2_vusb/ps2_usart.c)0
-rw-r--r--ps2_usb/sendchar_dummy.c (renamed from ps2_vusb/sendchar_dummy.c)0
-rw-r--r--ps2_usb/sendchar_usart.c (renamed from ps2_vusb/sendchar_usart.c)0
-rw-r--r--ps2_usb/usbconfig.h (renamed from ps2_vusb/usbconfig.h)2
-rw-r--r--ps2_vusb/README12
-rw-r--r--ps2_vusb/keymap.c189
-rw-r--r--ps2_vusb/matrix.c444
-rw-r--r--tmk.c2
27 files changed, 176 insertions, 1183 deletions
diff --git a/Makefile.rules b/Makefile.rules
index 96d1d7e1e4..f1d0a301ca 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -47,7 +47,7 @@ FORMAT = ihex
# Object files directory
# To put object files in current directory, use a dot (.), do NOT make
# this an empty or blank macro!
-OBJDIR = obj
+OBJDIR = obj_$(TARGET)
# Optimization level, can be [0, 1, 2, 3, s].
@@ -121,7 +121,7 @@ CFLAGS += -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
-CFLAGS += -include config.h
+CFLAGS += -include $(CONFIG_H)
#---------------- Compiler Options C++ ----------------
@@ -149,7 +149,7 @@ CPPFLAGS += -Wundef
CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
-CPPFLAGS += -include config.h
+CPPFLAGS += -include $(CONFIG_H)
#---------------- Assembler Options ----------------
@@ -162,7 +162,7 @@ CPPFLAGS += -include config.h
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
-ASFLAGS += -include config.h
+ASFLAGS += -include $(CONFIG_H)
#---------------- Library Options ----------------
@@ -273,7 +273,6 @@ OBJDUMP = avr-objdump
SIZE = avr-size
AR = avr-ar rcs
NM = avr-nm
-AVRDUDE = avrdude
REMOVE = rm -f
REMOVEDIR = rmdir
COPY = cp
@@ -377,7 +376,7 @@ gccversion :
# Program the device.
program: $(TARGET).hex $(TARGET).eep
- $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
+ $(PROGRAM_CMD)
# Generate avr-gdb config/init file which does the following:
diff --git a/command.c b/command.c
index a31a4007b3..0152ccd87b 100644
--- a/command.c
+++ b/command.c
@@ -8,7 +8,7 @@
#include "util.h"
#include "timer.h"
#include "layer.h"
-#include "matrix_skel.h"
+#include "matrix.h"
#include "command.h"
#ifdef HOST_PJRC
@@ -107,6 +107,8 @@ uint8_t command_proc(void)
break;
#ifdef USB_NKRO_ENABLE
case KB_N:
+ host_clear_keyboard_report();
+ host_send_keyboard_report();
keyboard_nkro = !keyboard_nkro;
if (keyboard_nkro)
print("USB_NKRO: enabled\n");
diff --git a/key_process.c b/key_process.c
deleted file mode 100644
index 4367f471da..0000000000
--- a/key_process.c
+++ /dev/null
@@ -1,392 +0,0 @@
-#include <stdbool.h>
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include "print.h"
-#include "debug.h"
-#include "timer.h"
-#include "util.h"
-#include "jump_bootloader.h"
-#include "usb_keyboard.h"
-#include "usb_keycodes.h"
-#include "usb.h"
-#include "layer.h"
-#include "matrix_skel.h"
-#include "keymap_skel.h"
-#include "key_process.h"
-#ifdef MOUSEKEY_ENABLE
-# include "mousekey.h"
-#endif
-#ifdef PS2_MOUSE_ENABLE
-# include "ps2_mouse.h"
-#endif
-#ifdef USB_EXTRA_ENABLE
-# include "usb_extra.h"
-#endif
-#ifdef USB_MOUSE_ENABLE
-# include "usb_mouse.h"
-#endif
-
-
-// TODO: refactoring
-void proc_matrix(void) {
- bool modified = false;
- uint8_t fn_bits = 0;
-
- matrix_scan();
- modified = matrix_is_modified();
-
- if (modified) {
- if (debug_matrix) matrix_print();
-#ifdef DEBUG_LED
- // LED flash for debug
- DEBUG_LED_CONFIG;
- DEBUG_LED_ON;
-#endif
- }
-
- if (matrix_has_ghost()) {
- // should send error?
- debug("matrix has ghost!!\n");
- return;
- }
-
- usb_keyboard_swap_report();
- usb_keyboard_clear_report();
- for (int row = 0; row < matrix_rows(); row++) {
- for (int col = 0; col < matrix_cols(); col++) {
- if (!matrix_is_on(row, col)) continue;
-
- uint8_t code = layer_get_keycode(row, col);
- if (code == KB_NO) {
- // do nothing
- } else if (IS_MOD(code)) {
- usb_keyboard_add_mod(code);
- } else if (IS_FN(code)) {
- fn_bits |= FN_BIT(code);
- }
-#ifdef MOUSEKEY_ENABLE
- else if (IS_MOUSEKEY(code)) {
- mousekey_decode(code);
- }
-#endif
-#ifdef USB_EXTRA_ENABLE
- // audio control & system control
- else if (code == KB_MUTE) {
- usb_extra_audio_send(AUDIO_MUTE);
- usb_extra_audio_send(0);
- _delay_ms(500);
- } else if (code == KB_VOLU) {
- usb_extra_audio_send(AUDIO_VOL_UP);
- usb_extra_audio_send(0);
- _delay_ms(200);
- } else if (code == KB_VOLD) {
- usb_extra_audio_send(AUDIO_VOL_DOWN);
- usb_extra_audio_send(0);
- _delay_ms(200);
- } else if (code == KB_PWR) {
- if (suspend && remote_wakeup) {
- usb_remote_wakeup();
- } else {
- usb_extra_system_send(SYSTEM_POWER_DOWN);
- }
- _delay_ms(1000);
- }
-#endif
- // normal key
- else if (IS_KEY(code)) {
- usb_keyboard_add_key(code);
- } else {
- debug("ignore keycode: "); debug_hex(code); debug("\n");
- }
- }
- }
-
- if (modified) {
-#ifdef DEBUG_LED
- // LED flash for debug
- DEBUG_LED_CONFIG;
- DEBUG_LED_OFF;
-#endif
- }
-
- layer_switching(fn_bits);
-
- // TODO: clean code
- // special mode for control, develop and debug
- if (keymap_is_special_mode(fn_bits)) {
- switch (usb_keyboard_get_key()) {
- case KB_H: // help
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print_enable = true;
- print("b: jump to bootloader\n");
- print("d: toggle debug enable\n");
- print("x: toggle matrix debug\n");
- print("k: toggle keyboard debug\n");
- print("m: toggle mouse debug\n");
- print("p: toggle print enable\n");
- print("v: print version\n");
- print("t: print timer count\n");
- print("s: print status\n");
- print("`: toggle protcol(boot/report)\n");
-#ifdef USB_NKRO_ENABLE
- print("n: toggle USB_NKRO\n");
-#endif
- print("Backspace: clear matrix\n");
- print("ESC: power down/wake up\n");
- print("0: switch to Layer0 \n");
- print("1: switch to Layer1 \n");
- print("2: switch to Layer2 \n");
- print("3: switch to Layer3 \n");
- print("4: switch to Layer4 \n");
-#ifdef PS2_MOUSE_ENABLE
- print("[: ps2_mouse_init \n");
- print("]: ps2_mouse_read \n");
- print("\: ps2_mouse: on/off toggle \n");
-#endif
- _delay_ms(500);
- print_enable = false;
- break;
- case KB_BSPC:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- matrix_init();
- print("clear matrix\n");
- _delay_ms(500);
- break;
- case KB_0:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print("current_layer: "); phex(current_layer); print("\n");
- print("default_layer: "); phex(default_layer); print("\n");
- current_layer = 0;
- default_layer = 0;
- print("switch to Layer0 \n");
- _delay_ms(500);
- break;
- case KB_1:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print("current_layer: "); phex(current_layer); print("\n");
- print("default_layer: "); phex(default_layer); print("\n");
- current_layer = 1;
- default_layer = 1;
- print("switch to Layer1 \n");
- _delay_ms(500);
- break;
- case KB_2:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print("current_layer: "); phex(current_layer); print("\n");
- print("default_layer: "); phex(default_layer); print("\n");
- current_layer = 2;
- default_layer = 2;
- print("switch to Layer2 \n");
- _delay_ms(500);
- break;
- case KB_3:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print("current_layer: "); phex(current_layer); print("\n");
- print("default_layer: "); phex(default_layer); print("\n");
- current_layer = 3;
- default_layer = 3;
- print("switch to Layer3 \n");
- _delay_ms(500);
- break;
- case KB_4:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print("current_layer: "); phex(current_layer); print("\n");
- print("default_layer: "); phex(default_layer); print("\n");
- current_layer = 4;
- default_layer = 4;
- print("switch to Layer4 \n");
- _delay_ms(500);
- break;
-#ifdef PS2_MOUSE_ENABLE
- case KB_LBRC:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print_enable = true;
- print("ps2_mouse_init...\n");
- _delay_ms(500);
- ps2_mouse_init();
- break;
- case KB_RBRC:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print_enable = true;
- print("ps2_mouse_read[btn x y]: ");
- _delay_ms(100);
- ps2_mouse_read();
- phex(ps2_mouse_btn); print(" ");
- phex(ps2_mouse_x); print(" ");
- phex(ps2_mouse_y); print("\n");
- print("ps2_mouse_error_count: "); phex(ps2_mouse_error_count); print("\n");
- break;
- case KB_BSLS:
- ps2_mouse_enable = !ps2_mouse_enable;
- print("ps2_mouse: ");
- if (ps2_mouse_enable)
- print("on");
- else
- print("off");
- print("\n");
- _delay_ms(500);
- break;
-#endif
- case KB_B: // bootloader
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print_enable = true;
- print("jump to bootloader...\n");
- _delay_ms(1000);
- jump_bootloader(); // not return
- break;
- case KB_D: // debug all toggle
- usb_keyboard_clear_report();
- usb_keyboard_send();
- debug_enable = !debug_enable;
- if (debug_enable) {
- print_enable = true;
- print("debug enabled.\n");
- //debug_matrix = true;
- //debug_keyboard = true;
- //debug_mouse = true;
- } else {
- print("debug disabled.\n");
- print_enable = false;
- //debug_matrix = false;
- //debug_keyboard = false;
- //debug_mouse = false;
- }
- _delay_ms(1000);
- break;
- case KB_X: // debug matrix toggle
- usb_keyboard_clear_report();
- usb_keyboard_send();
- debug_matrix = !debug_matrix;
- if (debug_matrix)
- print("debug matrix enabled.\n");
- else
- print("debug matrix disabled.\n");
- _delay_ms(1000);
- break;
- case KB_K: // debug keyboard toggle
- usb_keyboard_clear_report();
- usb_keyboard_send();
- debug_keyboard = !debug_keyboard;
- if (debug_keyboard)
- print("debug keyboard enabled.\n");
- else
- print("debug keyboard disabled.\n");
- _delay_ms(1000);
- break;
- case KB_M: // debug mouse toggle
- usb_keyboard_clear_report();
- usb_keyboard_send();
- debug_mouse = !debug_mouse;
- if (debug_mouse)
- print("debug mouse enabled.\n");
- else
- print("debug mouse disabled.\n");
- _delay_ms(1000);
- break;
- case KB_V: // print version & information
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print_enable = true;
- print(STR(DESCRIPTION) "\n");
- _delay_ms(1000);
- break;
- case KB_T: // print timer
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print_enable = true;
- print("timer: "); phex16(timer_count); print("\n");
- _delay_ms(500);
- break;
- case KB_P: // print toggle
- usb_keyboard_clear_report();
- usb_keyboard_send();
- if (print_enable) {
- print("print disabled.\n");
- print_enable = false;
- } else {
- print_enable = true;
- print("print enabled.\n");
- }
- _delay_ms(1000);
- break;
- case KB_S:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- print("UDCON: "); phex(UDCON); print("\n");
- print("UDIEN: "); phex(UDIEN); print("\n");
- print("UDINT: "); phex(UDINT); print("\n");
- print("usb_keyboard_leds:"); phex(usb_keyboard_leds); print("\n");
- print("usb_keyboard_protocol:"); phex(usb_keyboard_protocol); print("\n");
- print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n");
- print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n");
-#ifdef USB_MOUSE_ENABLE
- print("usb_mouse_protocol:"); phex(usb_mouse_protocol); print("\n");
-#endif
- if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n");
- _delay_ms(500);
- break;
- case KB_GRV:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- usb_keyboard_protocol = !usb_keyboard_protocol;
- print("keyboard protcol: ");
- if (usb_keyboard_protocol) print("report"); else print("boot");
- print("\n");
-
-#ifdef USB_MOUSE_ENABLE
- usb_mouse_protocol = !usb_mouse_protocol;
- print("mouse protcol: ");
- if (usb_mouse_protocol) print("report"); else print("boot");
- print("\n");
-#endif
- _delay_ms(1000);
- break;
-#ifdef USB_NKRO_ENABLE
- case KB_N:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- usb_keyboard_nkro = !usb_keyboard_nkro;
- if (usb_keyboard_nkro) print("USB_NKRO: enabled\n"); else print("USB_NKRO: disabled\n");
- _delay_ms(1000);
- break;
-#endif
-#ifdef USB_EXTRA_ENABLE
- case KB_ESC:
- usb_keyboard_clear_report();
- usb_keyboard_send();
- if (suspend && remote_wakeup) {
- usb_remote_wakeup();
- } else {
- usb_extra_system_send(SYSTEM_POWER_DOWN);
- }
- _delay_ms(1000);
- break;
-#endif
- }
- }
-
-
- if (modified) {
- usb_keyboard_send();
- }
-
-#ifdef MOUSEKEY_ENABLE
- mousekey_usb_send();
-#endif
-
-#ifdef PS2_MOUSE_ENABLE
- if (ps2_mouse_read() == 0)
- ps2_mouse_usb_send();
-#endif
-}
diff --git a/key_process.h b/key_process.h
deleted file mode 100644
index bfc0218f3e..0000000000
--- a/key_process.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef KEY_PROCESS_H
-#define KEY_PROCESS_H 1
-
-
-void proc_matrix(void);
-
-#endif
diff --git a/keyboard.c b/keyboard.c
index 25948ddf71..03db3257a2 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -1,7 +1,7 @@
#include "keyboard.h"
#include "host.h"
#include "layer.h"
-#include "matrix_skel.h"
+#include "matrix.h"
#include "led.h"
#include "usb_keycodes.h"
#include "timer.h"
@@ -11,6 +11,11 @@
#ifdef MOUSEKEY_ENABLE
#include "mousekey.h"
#endif
+/* TODO: shoud make new API */
+#ifdef USB_EXTRA_ENABLE
+#include "usb_extra.h"
+#include <util/delay.h>
+#endif
static uint8_t last_leds = 0;
@@ -61,7 +66,6 @@ void keyboard_proc(void)
fn_bits |= FN_BIT(code);
}
#ifdef USB_EXTRA_ENABLE
-/* TODO: use new API
// audio control & system control
else if (code == KB_MUTE) {
usb_extra_audio_send(AUDIO_MUTE);
@@ -83,7 +87,6 @@ void keyboard_proc(void)
}
_delay_ms(1000);
}
-*/
#endif
else if (IS_KEY(code)) {
host_add_key(code);
@@ -102,7 +105,6 @@ void keyboard_proc(void)
layer_switching(fn_bits);
if (command_proc()) {
- // not send report
return;
}
diff --git a/keymap_skel.h b/keymap.h
index 300801ff62..79ef0359d9 100644
--- a/keymap_skel.h
+++ b/keymap.h
@@ -1,5 +1,5 @@
-#ifndef KEYMAP_SKEL_H
-#define KEYMAP_SKEL_H 1
+#ifndef KEYMAP_H
+#define KEYMAP_H
#include <stdint.h>
#include <stdbool.h>
@@ -15,7 +15,4 @@ uint8_t keymap_fn_layer(uint8_t fn_bits);
/* keycode to send when release Fn key without using */
uint8_t keymap_fn_keycode(uint8_t fn_bits);
-/* whether special key combination */
-bool keymap_is_special_mode(uint8_t fn_bits);
-
#endif
diff --git a/layer.c b/layer.c
index 90314e4429..0c59c91fb7 100644
--- a/layer.c
+++ b/layer.c
@@ -1,4 +1,4 @@
-#include "keymap_skel.h"
+#include "keymap.h"
#include "host.h"
#include "debug.h"
#include "timer.h"
diff --git a/main_pjrc.c b/main_pjrc.c
new file mode 100644
index 0000000000..18a05ffdff
--- /dev/null
+++ b/main_pjrc.c
@@ -0,0 +1,97 @@
+/* 2010/08/23 noname
+ * keyboard firmware based on PJRC USB keyboard example
+ */
+/* Keyboard example with debug channel, for Teensy USB Development Board
+ * http://www.pjrc.com/teensy/usb_keyboard.html
+ * Copyright (c) 2008 PJRC.COM, LLC
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdbool.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include "keyboard.h"
+#include "usb.h"
+#include "matrix.h"
+#include "print.h"
+#include "debug.h"
+#include "util.h"
+#include "jump_bootloader.h"
+#ifdef PS2_MOUSE_ENABLE
+# include "ps2_mouse.h"
+#endif
+
+
+#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
+
+
+bool debug_enable = false;
+bool debug_matrix = false;
+bool debug_keyboard = false;
+bool debug_mouse = false;
+
+
+int main(void)
+{
+ DEBUG_LED_CONFIG;
+ DEBUG_LED_OFF;
+
+ // set for 16 MHz clock
+ CPU_PRESCALE(0);
+
+ // Initialize the USB, and then wait for the host to set configuration.
+ // If the Teensy is powered without a PC connected to the USB port,
+ // this will wait forever.
+ usb_init();
+ while (!usb_configured()) /* wait */ ;
+
+ keyboard_init();
+ matrix_scan();
+ if (matrix_key_count() >= 3) {
+#ifdef DEBUG_LED
+ for (int i = 0; i < 6; i++) {
+ DEBUG_LED_CONFIG;
+ DEBUG_LED_ON;
+ _delay_ms(500);
+ DEBUG_LED_OFF;
+ _delay_ms(500);
+ }
+#else
+ _delay_ms(5000);
+#endif
+ print_enable = true;
+ debug_enable = true;
+ debug_matrix = true;
+ debug_keyboard = true;
+ debug_mouse = true;
+ print("debug enabled.\n");
+ }
+ if (matrix_key_count() >= 4) {
+ print("jump to bootloader...\n");
+ _delay_ms(1000);
+ jump_bootloader(); // not return
+ }
+
+
+ while (1) {
+ keyboard_proc();
+ }
+}
diff --git a/matrix_skel.h b/matrix.h
index 2379ce44ab..1bcd0915fe 100644
--- a/matrix_skel.h
+++ b/matrix.h
@@ -1,5 +1,5 @@
-#ifndef MATRIX_SKEL_H
-#define MATRIX_SKEL_H 1
+#ifndef MATRIX_H
+#define MATRIX_H
#include <stdbool.h>
diff --git a/ps2.c b/ps2.c
index 52ee1691fb..99749cf6ba 100644
--- a/ps2.c
+++ b/ps2.c
@@ -187,6 +187,9 @@ static inline void pbuf_enqueue(uint8_t data)
{
if (!data)
return;
+
+ uint8_t sreg = SREG;
+ cli();
uint8_t next = (pbuf_head + 1) % PBUF_SIZE;
if (next != pbuf_tail) {
pbuf[pbuf_head] = data;
@@ -194,10 +197,12 @@ static inline void pbuf_enqueue(uint8_t data)
} else {
debug("pbuf: full\n");
}
+ SREG = sreg;
}
static inline uint8_t pbuf_dequeue(void)
{
uint8_t val = 0;
+
uint8_t sreg = SREG;
cli();
if (pbuf_head != pbuf_tail) {
@@ -205,17 +210,20 @@ static inline uint8_t pbuf_dequeue(void)
pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;
}
SREG = sreg;
+
return val;
}
/* get data received by interrupt */
uint8_t ps2_host_recv(void)
{
- // TODO: release clock line after 100us when inhibited by error
if (ps2_error) {
+ print("x");
+ phex(ps2_error);
ps2_host_send(0xFE); // request to resend
ps2_error = PS2_ERR_NONE;
}
+ idle();
return pbuf_dequeue();
}
@@ -281,7 +289,7 @@ ISR(PS2_INT_VECT)
}
goto RETURN;
ERROR:
- DEBUGP(0xFF);
+ DEBUGP(0x0F);
inhibit();
ps2_error = state;
DONE:
diff --git a/ps2_usb/Makefile b/ps2_usb/Makefile
index bd9a76eb85..af73be2c92 100644
--- a/ps2_usb/Makefile
+++ b/ps2_usb/Makefile
@@ -1,46 +1,5 @@
-# Hey Emacs, this is a -*- makefile -*-
-#----------------------------------------------------------------------------
-# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
-#
-# Released to the Public Domain
-#
-# Additional material for this makefile was written by:
-# Peter Fleury
-# Tim Henigan
-# Colin O'Flynn
-# Reiner Patommel
-# Markus Pfaff
-# Sander Pool
-# Frederik Rouleau
-# Carlos Lamas
-#
-#----------------------------------------------------------------------------
-# On command line:
-#
-# make all = Make software.
-#
-# make clean = Clean out built project files.
-#
-# make coff = Convert ELF to AVR COFF.
-#
-# make extcoff = Convert ELF to AVR Extended COFF.
-#
-# make program = Download the hex file to the device, using avrdude.
-# Please customize the avrdude settings below first!
-#
-# make debug = Start either simulavr or avarice as specified for debugging,
-# with avr-gdb or avr-insight as the front end for debugging.
-#
-# make filename.s = Just compile filename.c into the assembler code only.
-#
-# make filename.i = Create a preprocessed source file for use in submitting
-# bug reports to the GCC project.
-#
-# To rebuild project do "make clean" then "make all".
-#----------------------------------------------------------------------------
-
# Target file name (without extension).
-TARGET = tmk_ps2_usb
+TARGET = ps2_usb
# Directory common source filess exist
COMMON_DIR = ..
@@ -49,10 +8,14 @@ COMMON_DIR = ..
TARGET_DIR = .
# keyboard dependent files
-TARGET_SRC = keymap.c \
+TARGET_SRC = main_pjrc.c \
+ keymap.c \
matrix.c \
+ led.c \
ps2.c
+CONFIG_H = config_pjrc.h
+
# MCU name, you MUST set this to match the board you are using
# type "make clean" after changing this, so all files will be rebuilt
@@ -78,4 +41,11 @@ USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System c
USB_NKRO_ENABLE = yes # USB Nkey Rollover
+
+#---------------- Programming Options --------------------------
+PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex
+
+
+
+include $(COMMON_DIR)/Makefile.pjrc
include $(COMMON_DIR)/Makefile.common
diff --git a/ps2_vusb/Makefile b/ps2_usb/Makefile.vusb
index 6901d1f5cc..7b69dc27b5 100644
--- a/ps2_vusb/Makefile
+++ b/ps2_usb/Makefile.vusb
@@ -8,7 +8,7 @@ COMMON_DIR = ..
TARGET_DIR = .
# keyboard dependent files
-TARGET_SRC = main.c \
+TARGET_SRC = main_vusb.c \
keymap.c \
matrix.c \
led.c \
@@ -16,6 +16,9 @@ TARGET_SRC = main.c \
sendchar_dummy.c
# sendchar_usart.c
+CONFIG_H = config_vusb.h
+
+
OPT_DEFS = -DDEBUG_LEVEL=0
@@ -45,7 +48,8 @@ MOUSEKEY_ENABLE = yes # Mouse keys
-#---------------- Programming Options (avrdude) ----------------
+#---------------- Programming Options --------------------------
+AVRDUDE = avrdude
# Type: avrdude -c ? to get a full listing.
AVRDUDE_PROGRAMMER = usbasp
AVRDUDE_PORT =
@@ -72,6 +76,8 @@ AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
+PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
+
include $(COMMON_DIR)/Makefile.vusb
diff --git a/ps2_usb/README b/ps2_usb/README
index 3c9eb14282..ad5c6c4311 100644
--- a/ps2_usb/README
+++ b/ps2_usb/README
@@ -47,10 +47,10 @@ Keymap customization
You can customize keymaps easily by editing source code.
-Build
------
+Build for Teensy
+----------------
0. Connect PS/2 keyboard to Teensy by 4 lines(Vcc, GND, Data, Clock).
-1. Define following macros for PS/2 connection in config.h:
+1. Define following macros for PS/2 connection in config_pjrc.h:
PS2_DATA_PORT
PS2_DATA_PIN
PS2_DATA_DDR
@@ -65,6 +65,15 @@ Build
http://www.pjrc.com/teensy/loader.html
+Build for V-USB
+---------------
+0. Build V-USB controller board and connect PS/2 keyboard.
+1. Define macros in config_vusb.h if needed.
+2. Edit Makefile.vusb for build options and MCU setting.
+3. make -f Makefile.vusb
+4. program