aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.vusb11
-rw-r--r--POWER.txt62
-rw-r--r--README4
-rw-r--r--adb_usb/Makefile20
-rw-r--r--adb_usb/README8
-rw-r--r--adb_usb/config.h4
-rw-r--r--command.c56
-rw-r--r--command.h2
-rw-r--r--common.mk (renamed from Makefile.common)15
-rw-r--r--hhkb/FUSE.txt40
-rw-r--r--hhkb/Makefile.iwrap91
-rw-r--r--hhkb/Makefile.pjrc (renamed from hhkb/Makefile)19
-rw-r--r--hhkb/Makefile.vusb29
-rw-r--r--hhkb/README113
-rw-r--r--hhkb/config_iwrap.h55
-rw-r--r--hhkb/config_pjrc.h6
-rw-r--r--hhkb/config_vusb.h12
-rw-r--r--hhkb/doc/Bluetooth.txt4
-rwxr-xr-xhhkb/doc/Bluetooth_img/.picasa.ini2
-rwxr-xr-xhhkb/doc/Bluetooth_img/BT_circuit.jpgbin0 -> 502118 bytes
-rw-r--r--hhkb/doc/HHKB_img/HHKB_TP1684.jpg (renamed from hhkb/doc/HHKB_TP1684.jpg)bin149082 -> 149082 bytes
-rw-r--r--hhkb/doc/HHKB_img/HHKB_chart1.jpg (renamed from hhkb/doc/HHKB_chart1.jpg)bin155342 -> 155342 bytes
-rw-r--r--hhkb/doc/HHKB_img/HHKB_chart2.jpg (renamed from hhkb/doc/HHKB_chart2.jpg)bin148225 -> 148225 bytes
-rw-r--r--hhkb/doc/HHKB_img/HHKB_connector.jpg (renamed from hhkb/doc/HHKB_connector.jpg)bin193900 -> 193900 bytes
-rw-r--r--hhkb/doc/HHKB_img/HHKB_controller.jpg (renamed from hhkb/doc/HHKB_controller.jpg)bin135100 -> 135100 bytes
-rw-r--r--hhkb/doc/HHKB_img/HHKB_keyswitch.jpg (renamed from hhkb/doc/HHKB_keyswitch.jpg)bin171469 -> 171469 bytes
-rw-r--r--hhkb/doc/HHKB_img/connector_contact.jpg (renamed from hhkb/doc/connector_contact.jpg)bin192830 -> 192830 bytes
-rw-r--r--hhkb/doc/HHKB_img/logic_analyzer.jpg (renamed from hhkb/doc/logic_analyzer.jpg)bin169564 -> 169564 bytes
-rw-r--r--hhkb/doc/HHKB_img/probe_contact.jpg (renamed from hhkb/doc/probe_contact.jpg)bin208477 -> 208477 bytes
-rw-r--r--hhkb/doc/HHKB_img/teensy_install.jpg (renamed from hhkb/doc/teensy_install.jpg)bin135851 -> 135851 bytes
-rw-r--r--hhkb/doc/HHKB_img/teensy_wiring.jpg (renamed from hhkb/doc/teensy_wiring.jpg)bin154695 -> 154695 bytes
-rw-r--r--hhkb/keymap.c115
-rw-r--r--hhkb/matrix.c66
-rw-r--r--hhkb/usbconfig.h16
-rw-r--r--host.c190
-rw-r--r--host.h89
-rw-r--r--host_driver.h33
-rw-r--r--iwrap.mk10
-rw-r--r--iwrap/iWRAP.txt376
-rw-r--r--iwrap/iwrap.c467
-rw-r--r--iwrap/iwrap.h49
-rw-r--r--iwrap/main.c378
-rw-r--r--iwrap/suart.S156
-rw-r--r--iwrap/suart.h8
-rw-r--r--iwrap/wd.h159
-rw-r--r--keyboard.c9
-rwxr-xr-xlayer.c4
-rw-r--r--macway/Makefile16
-rw-r--r--macway/config.h4
-rw-r--r--[-rwxr-xr-x]macway/doc/back.jpgbin122135 -> 122135 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/case.jpgbin146003 -> 146003 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/keys.jpgbin116365 -> 116365 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/side.jpgbin109755 -> 109755 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/switch.jpgbin115526 -> 115526 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/teensy.jpgbin165814 -> 165814 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/wiring.jpgbin165569 -> 165569 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/withHHKB.jpgbin152832 -> 152832 bytes
-rw-r--r--[-rwxr-xr-x]macway/doc/withThinkPad.jpgbin118993 -> 118993 bytes
-rw-r--r--main_vusb.c58
-rwxr-xr-x[-rw-r--r--]mousekey.c10
-rw-r--r--pjrc.mk (renamed from Makefile.pjrc)10
-rw-r--r--pjrc/host.c10
-rw-r--r--pjrc/main.c (renamed from main_pjrc.c)3
-rw-r--r--pjrc/pjrc.c76
-rw-r--r--pjrc/pjrc.h26
-rw-r--r--pjrc/usb.c34
-rw-r--r--pjrc/usb.h2
-rw-r--r--pjrc/usb_keyboard.c4
-rw-r--r--print.c13
-rw-r--r--print.h2
-rw-r--r--ps2_usb/Makefile18
-rw-r--r--ps2_usb/Makefile.vusb19
-rw-r--r--ps2_usb/config_pjrc.h4
-rw-r--r--ps2_usb/config_vusb.h4
-rw-r--r--ps2_usb/keymap.c6
-rw-r--r--ps2_usb/matrix.c1
-rw-r--r--report.h96
-rw-r--r--rules.mk (renamed from Makefile.rules)0
-rw-r--r--sendchar.h4
-rw-r--r--sendchar_null.c (renamed from vusb/host_vusb.h)10
-rw-r--r--sendchar_uart.c25
-rw-r--r--timer.c35
-rw-r--r--timer.h21
-rw-r--r--uart.c129
-rw-r--r--uart.h11
-rw-r--r--usb_keycodes.h8
-rw-r--r--vusb.mk17
-rw-r--r--vusb/main.c99
-rw-r--r--vusb/vusb.c (renamed from vusb/host.c)207
-rw-r--r--vusb/vusb.h27
90 files changed, 3150 insertions, 537 deletions
diff --git a/Makefile.vusb b/Makefile.vusb
deleted file mode 100644
index b8e71a8e3..000000000
--- a/Makefile.vusb
+++ /dev/null
@@ -1,11 +0,0 @@
1OPT_DEFS += -DHOST_VUSB
2
3SRC = usbdrv.c \
4 usbdrvasm.S \
5 oddebug.c \
6 sendchar_usart.c
7SRC += $(TARGET_SRC)
8
9
10# C source file search path
11VPATH = $(TARGET_DIR):$(COMMON_DIR):$(COMMON_DIR)/vusb:$(COMMON_DIR)/vusb/usbdrv
diff --git a/POWER.txt b/POWER.txt
new file mode 100644
index 000000000..0abbbe48e
--- /dev/null
+++ b/POWER.txt
@@ -0,0 +1,62 @@
1Time to Sleep
2=============
3USB suspend no activity on USB line for 3ms
4No Interaction no user interaction
5 matrix has no change
6 matrix has no switch on
7
8
9AVR Power Management
10====================
11
12V-USB suspend
13 USB suspend
14 http://vusb.wikidot.com/examples
15
16MCUSR MCU Status Register
17 WDRF Watchdog Reset Flag
18 BORF
19 EXTRF
20 PORF Power-on Reset Flag
21
22SMCR Sleep Mode Control Register
23 SE Sleep Enable
24 SM2:0
25 #define set_sleep_mode(mode) \
26 #define SLEEP_MODE_IDLE (0)
27 #define SLEEP_MODE_ADC _BV(SM0)
28 #define SLEEP_MODE_PWR_DOWN _BV(SM1)
29 #define SLEEP_MODE_PWR_SAVE (_BV(SM0) | _BV(SM1))
30 #define SLEEP_MODE_STANDBY (_BV(SM1) | _BV(SM2))
31 #define SLEEP_MODE_EXT_STANDBY (_BV(SM0) | _BV(SM1) | _BV(SM2))
32
33
34ACSR Analog Comparator Control and Status Register
35 To disable Analog Comparator
36 ACSR = 0x80;
37 or
38 ACSR &= ~_BV(ACIE);
39 ACSR |= _BV(ACD);
40
41 ACD: Analog Comparator Disable
42 When this bit is written logic one, the power to the Analog Comparator is
43 switched off. This bit can be set at any time to turn off the Analog
44 Comparator. This will reduce power consumption in Active and Idle mode.
45 When changing the ACD bit, the Analog Comparator Interrupt must be disabled
46 by clearing the ACIE bit in ACSR. Otherwise an interrupt can occur when
47 the bit is changed.
48
49DIDR1 Digital Input Disable Register 1
50 AIN1D
51 AIN0D
52 When this bit is written logic one, the digital input buffer on the AIN1/0 pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set. When an analog signal is applied to the AIN1/0 pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer.
53
54
55PRR Power Reduction Register
56 PRTWI
57 PRTIM2
58 PRTIM0
59 PRTIM1
60 PRSPI
61 PRUSART0
62 PRADC
diff --git a/README b/README
index 2aa0106b0..d85f512c7 100644
--- a/README
+++ b/README
@@ -96,8 +96,8 @@ Build Options
963. Choose optional modules as needed. Comment out to disable optional modules. 963. Choose optional modules as needed. Comment out to disable optional modules.
97 MOUSEKEY_ENABLE = yes # Mouse keys 97 MOUSEKEY_ENABLE = yes # Mouse keys
98 PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support 98 PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
99 USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control) 99 EXTRAKEY_ENABLE = yes # Enhanced feature for Windows(Audio control and System control)
100 USB_NKRO_ENABLE = yes # USB Nkey Rollover 100 NKRO_ENABLE = yes # USB Nkey Rollover
101 101
102<target>/config.h: 102<target>/config.h:
1031. USB vendor/product ID and device description 1031. USB vendor/product ID and device description
diff --git a/adb_usb/Makefile b/adb_usb/Makefile
index 802b4248c..56b342df9 100644
--- a/adb_usb/Makefile
+++ b/adb_usb/Makefile
@@ -8,11 +8,11 @@ COMMON_DIR = ..
8TARGET_DIR = . 8TARGET_DIR = .
9 9
10# keyboard dependent files 10# keyboard dependent files
11TARGET_SRC = main_pjrc.c \ 11SRC = main.c \
12 keymap.c \ 12 keymap.c \
13 matrix.c \ 13 matrix.c \
14 led.c \ 14 led.c \
15 adb.c 15 adb.c
16 16
17CONFIG_H = config.h 17CONFIG_H = config.h
18 18
@@ -36,10 +36,10 @@ F_CPU = 16000000
36# Build Options 36# Build Options
37# comment out to disable the options. 37# comment out to disable the options.
38# 38#
39MOUSEKEY_ENABLE = yes # Mouse keys 39#MOUSEKEY_ENABLE = yes # Mouse keys
40#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support 40#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
41USB_EXTRA_ENABLE = yes # Audio control and System control 41#EXTRAKEY_ENABLE = yes # Audio control and System control
42#USB_NKRO_ENABLE = yes # USB Nkey Rollover 42#NKRO_ENABLE = yes # USB Nkey Rollover
43 43
44 44
45 45
@@ -48,5 +48,5 @@ PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
48 48
49 49
50 50
51include $(COMMON_DIR)/Makefile.pjrc 51include $(COMMON_DIR)/pjrc.mk
52include $(COMMON_DIR)/Makefile.common 52include $(COMMON_DIR)/common.mk
diff --git a/adb_usb/README b/adb_usb/README
index b4bd35bb3..5d0e1bc86 100644
--- a/adb_usb/README
+++ b/adb_usb/README
@@ -59,4 +59,12 @@ effort at this time.
59 ), 59 ),
60 60
61 61
62Notes
63-----
64Many ADB keyboards has no discrimination between right modifier and left one,
65you will always see left control even if you press right control key.
66Apple Extended Keyboard and Apple Extended Keyboard II are the examples.
67Though ADB protocol itsef has the ability of distinction between right and left.
68And most ADB keyboard has no NKRO functionality, though ADB protocol itsef has that.
69
62EOF 70EOF
diff --git a/adb_usb/config.h b/adb_usb/config.h
index 27f31ca9e..6431ede4c 100644
--- a/adb_usb/config.h
+++ b/adb_usb/config.h
@@ -37,8 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
37 37
38/* key combination for command */ 38/* key combination for command */
39#define IS_COMMAND() ( \ 39#define IS_COMMAND() ( \
40 keyboard_report->mods == (BIT_LSHIFT | BIT_LCTRL | BIT_LALT | BIT_LGUI) || \ 40 keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_LCTRL) | MOD_BIT(KB_LALT) | MOD_BIT(KB_LGUI)) || \
41 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) \ 41 keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)) \
42) 42)
43 43
44 44
diff --git a/command.c b/command.c
index 0a07aebfc..22f25e99c 100644
--- a/command.c
+++ b/command.c
@@ -30,24 +30,49 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30#ifdef HOST_PJRC 30#ifdef HOST_PJRC
31# include "jump_bootloader.h" 31# include "jump_bootloader.h"
32# include "usb_keyboard.h" 32# include "usb_keyboard.h"
33# ifdef USB_EXTRA_ENABLE 33# ifdef EXTRAKEY_ENABLE
34# include "usb_extra.h" 34# include "usb_extra.h"
35# endif 35# endif
36#endif 36#endif
37 37
38#ifdef HOST_VUSB
39# include "usbdrv.h"
40#endif
41
38 42
43static uint8_t command_common(void);
39static void help(void); 44static void help(void);
40static void switch_layer(uint8_t layer); 45static void switch_layer(uint8_t layer);
41 46
47static bool last_print_enable;
42 48
43uint8_t command_proc(void) 49uint8_t command_proc(void)
44{ 50{
51 uint8_t processed = 0;
52 last_print_enable = print_enable;
53
45 if (!IS_COMMAND()) 54 if (!IS_COMMAND())
46 return 0; 55 return 0;
47 56
48 uint8_t processed = 1;
49 bool last_print_enable = print_enable;
50 print_enable = true; 57 print_enable = true;
58 if (command_extra() || command_common()) {
59 processed = 1;
60 _delay_ms(500);
61 }
62 print_enable = last_print_enable;
63 return processed;
64}
65
66/* This allows to define extra commands. return 0 when not processed. */
67uint8_t command_extra(void) __attribute__ ((weak));
68uint8_t command_extra(void)
69{
70 return 0;
71}
72
73
74static uint8_t command_common(void)
75{
51 switch (host_get_first_key()) { 76 switch (host_get_first_key()) {
52 case KB_H: 77 case KB_H:
53 help(); 78 help();
@@ -123,20 +148,26 @@ uint8_t command_proc(void)
123 print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n"); 148 print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n");
124 print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n"); 149 print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n");
125#endif 150#endif
151
152#ifdef HOST_VUSB
153# if USB_COUNT_SOF
154 print("usbSofCount: "); phex(usbSofCount); print("\n");
155# endif
156#endif
126 break; 157 break;
127#ifdef USB_NKRO_ENABLE 158#ifdef NKRO_ENABLE
128 case KB_N: 159 case KB_N:
129 // send empty report before change 160 // send empty report before change
130 host_clear_keyboard_report(); 161 host_clear_keyboard_report();
131 host_send_keyboard_report(); 162 host_send_keyboard_report();
132 keyboard_nkro = !keyboard_nkro; 163 keyboard_nkro = !keyboard_nkro;
133 if (keyboard_nkro) 164 if (keyboard_nkro)
134 print("USB_NKRO: enabled\n"); 165 print("NKRO: enabled\n");
135 else 166 else
136 print("USB_NKRO: disabled\n"); 167 print("NKRO: disabled\n");
137 break; 168 break;
138#endif 169#endif
139#ifdef USB_EXTRA_ENABLE 170#ifdef EXTRAKEY_ENABLE
140 case KB_ESC: 171 case KB_ESC:
141 host_clear_keyboard_report(); 172 host_clear_keyboard_report();
142 host_send_keyboard_report(); 173 host_send_keyboard_report();
@@ -175,12 +206,9 @@ uint8_t command_proc(void)
175 switch_layer(4); 206 switch_layer(4);
176 break; 207 break;
177 default: 208 default:
178 processed = 0; 209 return 0;
179 } 210 }
180 if (processed) 211 return 1;
181 _delay_ms(500);
182 print_enable = last_print_enable;
183 return processed;
184} 212}
185 213
186static void help(void) 214static void help(void)
@@ -194,8 +222,8 @@ static void help(void)
194 print("v: print version\n"); 222 print("v: print version\n");
195 print("t: print timer count\n"); 223 print("t: print timer count\n");
196 print("s: print status\n"); 224 print("s: print status\n");
197#ifdef USB_NKRO_ENABLE 225#ifdef NKRO_ENABLE
198 print("n: toggle USB_NKRO\n"); 226 print("n: toggle NKRO\n");
199#endif 227#endif
200 print("Backspace: clear matrix\n"); 228 print("Backspace: clear matrix\n");
201 print("ESC: power down/wake up\n"); 229 print("ESC: power down/wake up\n");
diff --git a/command.h b/command.h
index dca6da456..4888f5ee0 100644
--- a/command.h
+++ b/command.h
@@ -19,5 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#define COMMAND 19#define COMMAND
20 20
21uint8_t command_proc(void); 21uint8_t command_proc(void);
22/* This allows to extend commands. Return 0 when command is not processed. */
23uint8_t command_extra(void);
22 24
23#endif 25#endif
diff --git a/Makefile.common b/common.mk
index 1922def00..17c6816f6 100644
--- a/Makefile.common
+++ b/common.mk
@@ -19,17 +19,20 @@ ifdef PS2_MOUSE_ENABLE
19 OPT_DEFS += -DPS2_MOUSE_ENABLE 19 OPT_DEFS += -DPS2_MOUSE_ENABLE
20endif 20endif
21 21
22ifdef USB_EXTRA_ENABLE 22ifdef EXTRAKEY_ENABLE
23 OPT_DEFS += -DUSB_EXTRA_ENABLE 23 OPT_DEFS += -DEXTRAKEY_ENABLE
24endif 24endif
25 25
26ifdef USB_NKRO_ENABLE 26ifdef NKRO_ENABLE
27 OPT_DEFS += -DUSB_NKRO_ENABLE 27 OPT_DEFS += -DNKRO_ENABLE
28endif 28endif
29 29
30ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) 30ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
31 OPT_DEFS += -DUSB_MOUSE_ENABLE 31 OPT_DEFS += -DMOUSE_ENABLE
32endif 32endif
33 33
34# Search Path
35VPATH += $(COMMON_DIR)
34 36
35include $(COMMON_DIR)/Makefile.rules 37
38include $(COMMON_DIR)/rules.mk
diff --git a/hhkb/FUSE.txt b/hhkb/FUSE.txt
new file mode 100644
index 000000000..40055e5ab
--- /dev/null
+++ b/hhkb/FUSE.txt
@@ -0,0 +1,40 @@
1ATMega168P Fuse/Lock Bits
2=========================
3This configuration is from usbasploader's Makefile.
4
5 HFUSE 0xD6
6 LFUSE 0xDF
7 EFUSE 0x00
8 LOCK 0x3F(intact)
9
10#---------------------------------------------------------------------
11# ATMega168P
12#---------------------------------------------------------------------
13# Fuse extended byte:
14# 0x00 = 0 0 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
15# \+/
16# +------- BOOTSZ (00 = 2k bytes)
17# Fuse high byte:
18# 0xd6 = 1 1 0 1 0 1 1 0
19# ^ ^ ^ ^ ^ \-+-/
20# | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
21# | | | | + --------- EESAVE (preserve EEPROM over chip erase)
22# | | | +-------------- WDTON (if 0: watchdog always on)
23# | | +---------------- SPIEN (allow serial programming)
24# | +------------------ DWEN (debug wire enable)
25# +-------------------- RSTDISBL (reset pin is enabled)
26# Fuse low byte:
27# 0xdf = 1 1 0 1 1 1 1 1
28# ^ ^ \ / \--+--/
29# | | | +------- CKSEL 3..0 (external >8M crystal)
30# | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
31# | +------------------ CKOUT (if 0: Clock output enabled)
32# +-------------------- CKDIV8 (if 0: divide by 8)
33
34
35# Lock Bits
36# 0x3f = - - 1 1 1 1 1 1
37# \ / \-/ \-/
38# | | +----- LB 2..1 (No memory lock features enabled)
39# | +--------- BLB0 2..1 (No restrictions for SPM or LPM accessing the Application section)
40# +--------------- BLB1 2..1 (No restrictions for SPM or LPM accessing the Boot Loader section)
diff --git a/hhkb/Makefile.iwrap b/hhkb/Makefile.iwrap
new file mode 100644
index 000000000..cf020b94a
--- /dev/null
+++ b/hhkb/Makefile.iwrap
@@ -0,0 +1,91 @@
1#
2# Makefile for iWRAP
3#
4
5
6# Target file name (without extension).
7TARGET = hhkb_iwrap
8
9# Directory common source filess exist
10COMMON_DIR = ..
11
12# Directory keyboard dependent files exist
13TARGET_DIR = .
14
15# keyboard dependent files
16SRC = main.c \
17 keymap.c \
18 matrix.c \
19 led.c
20
21CONFIG_H = config_iwrap.h
22
23
24# V-USB debug level: To use ps2_usart.c level must be 0
25# ps2_usart.c requires USART to receive PS/2 signal.
26OPT_DEFS = -DDEBUG_LEVEL=0
27
28
29# MCU name, you MUST set this to match the board you are using
30# type "make clean" after changing this, so all files will be rebuilt
31MCU = atmega168p
32# avrdude doesn't know atmega168p
33AVRDUDE_MCU = atmega168
34
35
36# Processor frequency.
37# Normally the first thing your program should do is set the clock prescaler,
38# so your program will run at the correct speed. You should also set this
39# variable to same clock speed. The _delay_ms() macro uses this, and many
40# examples use this variable to calculate timings. Do not add a "UL" here.
41F_CPU = 12000000
42
43
44# Build Options
45# comment out to disable the options.
46#
47MOUSEKEY_ENABLE = yes # Mouse keys
48EXTRAKEY_ENABLE = yes # Audio control and System control
49#NKRO_ENABLE = yes # USB Nkey Rollover
50
51
52
53#---------------- Programming Options --------------------------
54AVRDUDE = avrdude
55# Type: avrdude -c ? to get a full listing.
56AVRDUDE_PROGRAMMER = usbasp
57AVRDUDE_PORT =
58AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
59#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
60
61# Uncomment the following if you want avrdude's erase cycle counter.
62# Note that this counter needs to be initialized first using -Yn,
63# see avrdude manual.
64#AVRDUDE_ERASE_COUNTER = -y
65
66# Uncomment the following if you do /not/ wish a verification to be
67# performed after programming the device.
68#AVRDUDE_NO_VERIFY = -V
69
70# Increase verbosity level. Please use this when submitting bug
71# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
72# to submit bug reports.
73#AVRDUDE_VERBOSE = -v -v
74
75#AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
76AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -c $(AVRDUDE_PROGRAMMER)
77AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
78AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
79AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
80
81PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
82
83
84
85# Search Path
86VPATH = $(TARGET_DIR)
87
88include $(COMMON_DIR)/iwrap.mk
89# To be swatchable btween Bluetooth and USB. Comment out if you don't need USB.
90include $(COMMON_DIR)/vusb.mk
91include $(COMMON_DIR)/common.mk
diff --git a/hhkb/Makefile b/hhkb/Makefile.pjrc
index e1cc2f210..17aa865dd 100644
--- a/hhkb/Makefile
+++ b/hhkb/Makefile.pjrc
@@ -13,10 +13,10 @@ COMMON_DIR = ..
13TARGET_DIR = . 13TARGET_DIR = .
14 14
15# keyboard dependent files 15# keyboard dependent files
16TARGET_SRC = main_pjrc.c \ 16SRC = main.c \
17 keymap.c \ 17 keymap.c \
18 matrix.c \ 18 matrix.c \
19 led.c 19 led.c
20 20
21CONFIG_H = config_pjrc.h 21CONFIG_H = config_pjrc.h
22 22
@@ -41,8 +41,8 @@ F_CPU = 16000000
41# comment out to disable the options. 41# comment out to disable the options.
42MOUSEKEY_ENABLE = yes # Mouse keys 42MOUSEKEY_ENABLE = yes # Mouse keys
43#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support 43#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
44USB_EXTRA_ENABLE = yes # Audio control and System control 44EXTRAKEY_ENABLE = yes # Audio control and System control
45USB_NKRO_ENABLE = yes # USB Nkey Rollover 45NKRO_ENABLE = yes # USB Nkey Rollover
46 46
47 47
48 48
@@ -51,5 +51,8 @@ PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
51 51
52 52
53 53
54include $(COMMON_DIR)/Makefile.pjrc 54# Search Path
55include $(COMMON_DIR)/Makefile.common 55VPATH = $(TARGET_DIR)
56
57include $(COMMON_DIR)/pjrc.mk
58include $(COMMON_DIR)/common.mk
diff --git a/hhkb/Makefile.vusb b/hhkb/Makefile.vusb
index 77841b824..5bfc233df 100644
--- a/hhkb/Makefile.vusb
+++ b/hhkb/Makefile.vusb
@@ -13,10 +13,10 @@ COMMON_DIR = ..
13TARGET_DIR = . 13TARGET_DIR = .
14 14
15# keyboard dependent files 15# keyboard dependent files
16TARGET_SRC = main_vusb.c \ 16SRC = main.c \
17 keymap.c \ 17 keymap.c \
18 matrix.c \ 18 matrix.c \
19 led.c 19 led.c
20 20
21CONFIG_H = config_vusb.h 21CONFIG_H = config_vusb.h
22 22
@@ -28,7 +28,9 @@ OPT_DEFS = -DDEBUG_LEVEL=0
28 28
29# MCU name, you MUST set this to match the board you are using 29# MCU name, you MUST set this to match the board you are using
30# type "make clean" after changing this, so all files will be rebuilt 30# type "make clean" after changing this, so all files will be rebuilt
31MCU = atmega168 31MCU = atmega168p
32# avrdude doesn't know atmega168p
33AVRDUDE_MCU = atmega168
32 34
33 35
34# Processor frequency. 36# Processor frequency.
@@ -36,15 +38,15 @@ MCU = atmega168
36# so your program will run at the correct speed. You should also set this 38# so your program will run at the correct speed. You should also set this
37# variable to same clock speed. The _delay_ms() macro uses this, and many 39# variable to same clock speed. The _delay_ms() macro uses this, and many
38# examples use this variable to calculate timings. Do not add a "UL" here. 40# examples use this variable to calculate timings. Do not add a "UL" here.
39F_CPU = 20000000 41F_CPU = 12000000
40 42
41 43
42# Build Options 44# Build Options
43# comment out to disable the options. 45# comment out to disable the options.
44# 46#
45MOUSEKEY_ENABLE = yes # Mouse keys 47MOUSEKEY_ENABLE = yes # Mouse keys
46USB_EXTRA_ENABLE = yes # Audio control and System control 48EXTRAKEY_ENABLE = yes # Audio control and System control
47#USB_NKRO_ENABLE = yes # USB Nkey Rollover 49#NKRO_ENABLE = yes # USB Nkey Rollover
48 50
49 51
50 52
@@ -70,8 +72,8 @@ AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
70# to submit bug reports. 72# to submit bug reports.
71#AVRDUDE_VERBOSE = -v -v 73#AVRDUDE_VERBOSE = -v -v
72 74
73#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) 75#AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
74AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) 76AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -c $(AVRDUDE_PROGRAMMER)
75AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) 77AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
76AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) 78AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
77AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) 79AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
@@ -80,5 +82,8 @@ PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE
80 82
81 83
82 84
83include $(COMMON_DIR)/Makefile.vusb 85# Search Path
84include $(COMMON_DIR)/Makefile.common 86VPATH = $(TARGET_DIR)
87
88include $(COMMON_DIR)/vusb.mk
89include $(COMMON_DIR)/common.mk
diff --git a/hhkb/README b/hhkb/README
index 2a4418101..65f7dcab5 100644
--- a/hhkb/README
+++ b/hhkb/README
@@ -4,7 +4,7 @@ Alternative Controller for HHKB
4Feature 4Feature
5------- 5-------
6- Mouse Keys 6- Mouse Keys
7- NKRO on USB 7- NKRO on USB(PJRC Tennsy only)
8- Keymap Layers 8- Keymap Layers
9 9
10 10
@@ -13,8 +13,11 @@ Customize Keymap
13see keymap.c. 13see keymap.c.
14 14
15 15
16Build for Teensy 16
17---------------- 17Build
18=====
19PJRC Teensy
20-----------
180. Edit matrix.c. 210. Edit matrix.c.
19 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts) 22 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts)
201. Define macros in config_pjrc.h.(Optional) 231. Define macros in config_pjrc.h.(Optional)
@@ -22,15 +25,15 @@ Build for Teensy
22 IS_COMMAND 25 IS_COMMAND
232. Edit Makefile for MCU setting and build options. 262. Edit Makefile for MCU setting and build options.
24 MCU, F_CPU 27 MCU, F_CPU
25 MOUSEKEY_ENABLE, USB_EXTRA_ENABLE, USB_NKRO_ENABLE 28 MOUSEKEY_ENABLE, EXTRAKEY_ENABLE, NKRO_ENABLE
263. Build hex file. 293. Build hex file.
27 $ make 30 $ make -f Makefile.pjrc
284. Program MCU. 314. Program MCU.
29 $ make program 32 $ make -f Makefile.pjrc program
30 33
31 34
32Build for V-USB 35V-USB
33--------------- 36-----
340. Edit matrix.c and usbconfig.h. 370. Edit matrix.c and usbconfig.h.
35 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts) 38 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts)
36 define macros for V-USB in usbconfig.h. 39 define macros for V-USB in usbconfig.h.
@@ -38,7 +41,7 @@ Build for V-USB
38 IS_COMMAND 41 IS_COMMAND
392. Edit Makefile.vusb for MCU setting and build options. 422. Edit Makefile.vusb for MCU setting and build options.
40 MCU, F_CPU 43 MCU, F_CPU
41 MOUSEKEY_ENABLE, USB_EXTRA_ENABLE, USB_NKRO_ENABLE 44 MOUSEKEY_ENABLE, EXTRAKEY_ENABLE
423. Build hex file. 453. Build hex file.
43 $ make -f Makefile.vusb 46 $ make -f Makefile.vusb
444. Program MCU. 474. Program MCU.
@@ -52,21 +55,59 @@ Build for V-USB
52 http://www.obdev.at/products/vusb/usbasploader.html 55 http://www.obdev.at/products/vusb/usbasploader.html
53 56
54 57
55V-USB Circuit 58iWRAP
56------------- 59-----
600. Edit matrix.c and usbconfig.h.
61 adjust scan code to your pin configuration.(see doc/HHKB.txt for pinouts)
62 define macros for V-USB in usbconfig.h.
631. Define macros in config_iwrap.h.(Optional)
64 IS_COMMAND
652. Edit Makefile.iwrap for MCU setting and build options.
66 MCU, F_CPU
67 MOUSEKEY_ENABLE, EXTRAKEY_ENABLE
683. Build hex file.
69 $ make -f Makefile.iwrap
704. Program MCU.
71 $ make -f Makefile.iwrap program
72
73
74
75Hardware
76========
77PJRC Teensy
78-----------
79 +---------------+
80 | Teensy++ |
81 | |
82 | | HHKB
83 | | ~~~~
84 | PB0-2|------->ROW(6-8)
85 | PB3-5|------->COL(9-11)
86 | PB6|------->ENABLE(12)
87 | PE6|<-------KEY(4)
88 | PE7|------->PREV(5)
89 | |
90 | |
91 | |
92 +---------------+
93
94
95V-USB
96-----
57 +---+ +---------------+ 97 +---+ +---------------+
58USB GND | | ATmega168 | 98USB GND | | ATmega168 |
59=== C3 | | 99~~~ C3 | |
605V <-------+--------+---|Vcc,AVCC | HHKB 1005V <-------+--------+---|Vcc,AVCC | HHKB
61 R1 | | ==== 101 R1 | | ~~~~
62D- <----+--+-----R2-----|INT1 PB0-2|------->ROW 102D- <----+--+-----R2-----|INT1 PB2-4|------->ROW(6-8)
63D+ <----|---+----R3-----|INT0 PB3-5|------->COL 103D+ <----|---+----R3-----|INT0 PC0-2|------->COL(9-11)
64 Z1 Z2 | PB6|------->ENABLE 104 Z1 Z2 | PC3|------->ENABLE(12)
65GND<----+---+--+--+-----|GND PE6|------->KEY 105GND<----+---+-----------|GND PB0|<-------KEY(4)
66 | | | PE7|------->PREV 106 | PB1|------->PREV(5)
67 | C2-+--|XTAL1 | (see doc/HHKB.txt for pinouts) 107 | |
68 | X1 | | 108 GND+-C2--+--|XTAL1 RXD|------->Debug Console
69 +--C3-+--|XTAL2 RST|---SW--+GND 109 X1 | TXD|<-------Debug Console
110 GND+-C3--+--|XTAL2 RST|---SW--+GND
70 +---------------+ 111 +---------------+
71R1: 1.5K Ohm 112R1: 1.5K Ohm
72R2,R3: 68 Ohm 113R2,R3: 68 Ohm
@@ -77,4 +118,34 @@ X1: Crystal 20MHz(16MHz/12MHz)
77SW: Push Switch(Optional for bootloader) 118SW: Push Switch(Optional for bootloader)
78 119
79 120
121iWRAP
122-----
123 +---------------+ WT12
124 5V | ATmega168 | 5V/3.3V~~~~
125 +-----+---|Vcc,AVCC PC4|---/--->iWRAP(RxD)
126USB | C3 | PC5|<--/----iWRAP(TxD)
127~~~ | + | |
1285V <--BATT + GND | | HHKB
129 R1 | | ~~~~
130D- <----+-----+--R2-----|INT1 PB2-4|------->ROW(6-8)
131D+ <----|---+----R3-----|INT0 PC0-2|------->COL(9-11)
132 Z1 Z2 | PC3|------->ENABLE(12)
133GND<----+---+-----------|GND PB0|<-------KEY(4)
134 | PB1|------->PREV(5)
135 | |
136 GND+-C2--+--|XTAL1 RXD|------->Debug Console
137 X1 | TXD|<-------Debug Console
138 GND+-C3--+--|XTAL2 RST|---SW--+GND
139 +---------------+
140
141R1: 1.5K Ohm
142R2,R3: 68 Ohm
143Z1,Z2: Zener 3.6V
144C1,C2: 22pF
145C3: 0.1uF
146X1: Crystal 12MHz
147SW: Push Switch(Optional)
148BATT: Li-Po Battery, Battery Charger and Voltage Regulator(5V and 3.3V).
149
150
80EOF 151EOF
diff --git a/hhkb/config_iwrap.h b/hhkb/config_iwrap.h
new file mode 100644
index 000000000..80ab64398
--- /dev/null
+++ b/hhkb/config_iwrap.h
@@ -0,0 +1,55 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21#define VENDOR_ID 0xFEED
22#define PRODUCT_ID 0xBEEA
23// TODO: share these strings with usbconfig.h
24// Edit usbconfig.h to change these.
25#define MANUFACTURER t.m.k.
26#define PRODUCT HHKB mod
27#define DESCRIPTION t.m.k. keyboard firmware for HHKB mod
28
29
30/* matrix size */
31#define MATRIX_ROWS 8
32#define MATRIX_COLS 8
33
34
35/* key combination for command */
36#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
37
38/* mouse keys */
39#ifdef MOUSEKEY_ENABLE
40# define MOUSEKEY_DELAY_TIME 255
41#endif
42
43/* pins for Software UART */
44#define SUART_IN_PIN PINC
45#define SUART_IN_BIT 5
46#define SUART_OUT_PORT PORTC
47#define SUART_OUT_BIT 4
48
49
50#define DEBUG_LED 1
51#define DEBUG_LED_CONFIG (DDRD |= (1<<4))
52#define DEBUG_LED_OFF (PORTD |= (1<<4))
53#define DEBUG_LED_ON (PORTD &= ~(1<<4))
54
55#endif
diff --git a/hhkb/config_pjrc.h b/hhkb/config_pjrc.h
index ef2efe2d9..8379202ca 100644
--- a/hhkb/config_pjrc.h
+++ b/hhkb/config_pjrc.h
@@ -36,11 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
36 36
37 37
38/* key combination for command */ 38/* key combination for command */
39#define IS_COMMAND() ( \ 39#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
40 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \
41 keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \
42)
43
44 40
45/* mouse keys */ 41/* mouse keys */
46#ifdef MOUSEKEY_ENABLE 42#ifdef MOUSEKEY_ENABLE
diff --git a/hhkb/config_vusb.h b/hhkb/config_vusb.h
index 115b73de3..268644849 100644
--- a/hhkb/config_vusb.h
+++ b/hhkb/config_vusb.h
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#ifndef CONFIG_H 18#ifndef CONFIG_H
19#define CONFIG_H 19#define CONFIG_H
20 20
21
22#define VENDOR_ID 0xFEED 21#define VENDOR_ID 0xFEED
23#define PRODUCT_ID 0xC0FE 22#define PRODUCT_ID 0xC0FE
24// TODO: share these strings with usbconfig.h 23// TODO: share these strings with usbconfig.h
@@ -34,11 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
34 33
35 34
36/* key combination for command */ 35/* key combination for command */
37#define IS_COMMAND() ( \ 36#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)))
38 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \
39 keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \
40)
41
42 37
43/* mouse keys */ 38/* mouse keys */
44#ifdef MOUSEKEY_ENABLE 39#ifdef MOUSEKEY_ENABLE
@@ -46,4 +41,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
46#endif 41#endif
47 42
48 43
44#define DEBUG_LED 1
45#define DEBUG_LED_CONFIG (DDRD |= (1<<4))
46#define DEBUG_LED_OFF (PORTD |= (1<<4))
47#define DEBUG_LED_ON (PORTD &= ~(1<<4))
48
49#endif 49#endif
diff --git a/hhkb/doc/Bluetooth.txt b/hhkb/doc/Bluetooth.txt
new file mode 100644
index 000000000..b27f19700
--- /dev/null
+++ b/hhkb/doc/Bluetooth.txt
@@ -0,0 +1,4 @@
1HHKB Bluetooth mod
2==================
3See this article:
4http://geekhack.org/showwiki.php?title=Island:20851
diff --git a/hhkb/doc/Bluetooth_img/.picasa.ini b/hhkb/doc/Bluetooth_img/.picasa.ini
new file mode 100755
index 000000000..f6a4f6067
--- /dev/null
+++ b/hhkb/doc/Bluetooth_img/.picasa.ini
@@ -0,0 +1,2 @@
1[Picasa]
2name=Bluetooth_img
diff --git a/hhkb/doc/Bluetooth_img/BT_circuit.jpg b/hhkb/doc/Bluetooth_img/BT_circuit.jpg
new file mode 100755
index 000000000..2e5a25e81
--- /dev/null
+++ b/hhkb/doc/Bluetooth_img/BT_circuit.jpg
Binary files differ
diff --git a/hhkb/doc/HHKB_TP1684.jpg b/hhkb/doc/HHKB_img/HHKB_TP1684.jpg
index 0a0316409..0a0316409 100644
--- a/hhkb/doc/HHKB_TP1684.jpg
+++ b/hhkb/doc/HHKB_img/HHKB_TP1684.jpg
Binary files differ
diff --git a/hhkb/doc/HHKB_chart1.jpg b/hhkb/doc/HHKB_img/HHKB_chart1.jpg
index 1f09bd185..1f09bd185 100644
--- a/hhkb/doc/HHKB_chart1.jpg
+++ b/hhkb/doc/HHKB_img/HHKB_chart1.jpg
Binary files differ
diff --git a/hhkb/doc/HHKB_chart2.jpg b/hhkb/doc/HHKB_img/HHKB_chart2.jpg
index 45f5ada90..45f5ada90 100644
--- a/hhkb/doc/HHKB_chart2.jpg
+++ b/hhkb/doc/HHKB_img/HHKB_chart2.jpg
Binary files differ
diff --git a/hhkb/doc/HHKB_connector.jpg b/hhkb/doc/HHKB_img/HHKB_connector.jpg
index e8a09e9b2..e8a09e9b2 100644
--- a/hhkb/doc/HHKB_connector.jpg
+++ b/hhkb/doc/HHKB_img/HHKB_connector.jpg
Binary files differ
diff --git a/hhkb/doc/HHKB_controller.jpg b/hhkb/doc/HHKB_img/HHKB_controller.jpg
index e3dae8e86..e3dae8e86 100644
--- a/hhkb/doc/HHKB_controller.jpg
+++ b/hhkb/doc/HHKB_img/HHKB_controller.jpg
Binary files differ
diff --git a/hhkb/doc/HHKB_keyswitch.jpg b/hhkb/doc/HHKB_img/HHKB_keyswitch.jpg
index 3afc269e7..3afc269e7 100644
--- a/hhkb/doc/HHKB_keyswitch.jpg
+++ b/hhkb/doc/HHKB_img/HHKB_keyswitch.jpg
Binary files differ
diff --git a/hhkb/doc/connector_contact.jpg b/hhkb/doc/HHKB_img/connector_contact.jpg
index 5304bc8d7..5304bc8d7 100644
--- a/hhkb/doc/connector_contact.jpg
+++ b/hhkb/doc/HHKB_img/connector_contact.jpg
Binary files differ
diff --git a/hhkb/doc/logic_analyzer.jpg b/hhkb/doc/HHKB_img/logic_analyzer.jpg
index f1b438ae7..f1b438ae7 100644
--- a/hhkb/doc/logic_analyzer.jpg
+++ b/hhkb/doc/HHKB_img/logic_analyzer.jpg
Binary files differ
diff --git a/hhkb/doc/probe_contact.jpg b/hhkb/doc/HHKB_img/probe_contact.jpg
index dc79afa0c..dc79afa0c 100644
--- a/hhkb/doc/probe_contact.jpg
+++ b/hhkb/doc/HHKB_img/probe_contact.jpg
Binary files differ
diff --git a/hhkb/doc/teensy_install.jpg b/hhkb/doc/HHKB_img/teensy_install.jpg
index 873d988ed..873d988ed 100644
--- a/hhkb/doc/teensy_install.jpg
+++ b/hhkb/doc/HHKB_img/teensy_install.jpg
Binary files differ
diff --git a/hhkb/doc/teensy_wiring.jpg b/hhkb/doc/HHKB_img/teensy_wiring.jpg
index 1c4eb6743..1c4eb6743 100644
--- a/hhkb/doc/teensy_wiring.jpg
+++ b/hhkb/doc/HHKB_img/teensy_wiring.jpg
Binary files differ
diff --git a/hhkb/keymap.c b/hhkb/keymap.c
index f539a06cc..85a7c31b7 100644
--- a/hhkb/keymap.c
+++ b/hhkb/keymap.c
@@ -32,21 +32,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
32// Convert physical keyboard layout to matrix array. 32// Convert physical keyboard layout to matrix array.
33// This is a macro to define keymap easily in keyboard layout form. 33// This is a macro to define keymap easily in keyboard layout form.
34#define KEYMAP( \ 34#define KEYMAP( \
35 R3C1, R3C0, R0C0, R1C0, R1C1, R2C0, R2C1, R4C0, R4C1, R6C0, R6C1, R7C0, R7C1, R5C0, R5C1, \ 35 K31, K30, K00, K10, K11, K20, K21, K40, K41, K60, K61, K70, K71, K50, K51, \
36 R3C2, R0C1, R0C2, R1C3, R1C2, R2C3, R2C2, R4C2, R4C3, R6C2, R6C3, R7C3, R7C2, R5C2, \ 36 K32, K01, K02, K13, K12, K23, K22, K42, K43, K62, K63, K73, K72, K52, \
37 R3C3, R0C4, R0C3, R1C4, R1C5, R2C4, R2C5, R4C5, R4C4, R6C5, R6C4, R7C4, R5C3, \ 37 K33, K04, K03, K14, K15, K24, K25, K45, K44, K65, K64, K74, K53, \
38 R3C4, R0C5, R0C6, R0C7, R1C6, R1C7, R2C6, R4C6, R6C6, R7C6, R7C5, R5C5, R5C4, \ 38 K34, K05, K06, K07, K16, K17, K26, K46, K66, K76, K75, K55, K54, \
39 R3C5, R3C6, R3C7, R5C7, R5C6 \ 39 K35, K36, K37, K57, K56 \
40) \ 40) \
41{ \ 41{ \
42 { R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7 }, \ 42 { KB_##K00, KB_##K01, KB_##K02, KB_##K03, KB_##K04, KB_##K05, KB_##K06, KB_##K07 }, \
43 { R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7 }, \ 43 { KB_##K10, KB_##K11, KB_##K12, KB_##K13, KB_##K14, KB_##K15, KB_##K16, KB_##K17 }, \
44 { R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, KB_NO }, \ 44 { KB_##K20, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_##K25, KB_##K26, KB_NO }, \
45 { R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7 }, \ 45 { KB_##K30, KB_##K31, KB_##K32, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_##K37 }, \
46 { R4C0, R4C1, R4C2, R4C3, R4C4, R4C5, R4C6, KB_NO }, \ 46 { KB_##K40, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_NO }, \
47 { R5C0, R5C1, R5C2, R5C3, R5C4, R5C5, R5C6, R5C7 }, \ 47 { KB_##K50, KB_##K51, KB_##K52, KB_##K53, KB_##K54, KB_##K55, KB_##K56, KB_##K57 }, \
48 { R6C0, R6C1, R6C2, R6C3, R6C4, R6C5, R6C6, KB_NO }, \ 48 { KB_##K60, KB_##K61, KB_##K62, KB_##K63, KB_##K64, KB_##K65, KB_##K66, KB_NO }, \
49 { R7C0, R7C1, R7C2, R7C3, R7C4, R7C5, R7C6, KB_NO } \ 49 { KB_##K70, KB_##K71, KB_##K72, KB_##K73, KB_##K74, KB_##K75, KB_##K76, KB_NO } \
50} 50}
51 51
52#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) 52#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)]))
@@ -58,8 +58,8 @@ static const uint8_t PROGMEM fn_layer[] = {
58 1, // Fn1 58 1, // Fn1
59 2, // Fn2 59 2, // Fn2
60 3, // Fn3 60 3, // Fn3
61 4, // Fn4 61 3, // Fn4
62 0, // Fn5 62 4, // Fn5
63 0, // Fn6 63 0, // Fn6
64 0 // Fn7 64 0 // Fn7
65}; 65};
@@ -71,8 +71,8 @@ static const uint8_t PROGMEM fn_keycode[] = {
71 KB_NO, // Fn1 71 KB_NO, // Fn1
72 KB_SLSH, // Fn2 72 KB_SLSH, // Fn2
73 KB_SCLN, // Fn3 73 KB_SCLN, // Fn3
74 KB_SPC, // Fn4 74 KB_NO, // Fn4
75 KB_NO, // Fn5 75 KB_SPC, // Fn5
76 KB_NO, // Fn6 76 KB_NO, // Fn6
77 KB_NO // Fn7 77 KB_NO // Fn7
78}; 78};
@@ -91,11 +91,11 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
91 * |Gui|Alt |Fn5 |Alt |Fn4| 91 * |Gui|Alt |Fn5 |Alt |Fn4|
92 * `-------------------------------------------' 92 * `-------------------------------------------'
93 */ 93 */
94 KEYMAP(KB_ESC, KB_1, KB_2, KB_3, KB_4, KB_5, KB_6, KB_7, KB_8, KB_9, KB_0, KB_MINS,KB_EQL, KB_BSLS,KB_GRV, \ 94 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
95 KB_TAB, KB_Q, KB_W, KB_E, KB_R, KB_T, KB_Y, KB_U, KB_I, KB_O, KB_P, KB_LBRC,KB_RBRC,KB_BSPC, \ 95 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
96 KB_LCTL,KB_A, KB_S, KB_D, KB_F, KB_G, KB_H, KB_J, KB_K, KB_L, KB_FN3, KB_QUOT,KB_ENT, \ 96 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,ENT, \
97 KB_LSFT,KB_Z, KB_X, KB_C, KB_V, KB_B, KB_N, KB_M, KB_COMM,KB_DOT, KB_FN2, KB_RSFT,KB_FN1, \ 97 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
98 KB_LGUI,KB_LALT,KB_FN4, KB_RALT,KB_RGUI), 98 LGUI,LALT, FN5, RALT,FN4),
99 99
100 /* Layer 1: HHKB mode (HHKB Fn) 100 /* Layer 1: HHKB mode (HHKB Fn)
101 * ,-----------------------------------------------------------. 101 * ,-----------------------------------------------------------.
@@ -110,11 +110,11 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
110 * |Gui |Alt |Space |Alt |xxx| 110 * |Gui |Alt |Space |Alt |xxx|
111 * `--------------------------------------------' 111 * `--------------------------------------------'
112 */ 112 */
113 KEYMAP(KB_ESC, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_INS, KB_DEL, \ 113 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
114 KB_CAPS,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_PSCR,KB_SLCK,KB_BRK, KB_UP, KB_NO, KB_BSPC, \ 114 CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, BSPC, \
115 KB_LCTL,KB_VOLD,KB_VOLU,KB_MUTE,KB_NO, KB_NO, KB_PAST,KB_PSLS,KB_HOME,KB_PGUP,KB_LEFT,KB_RGHT,KB_ENT, \ 115 LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
116 KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_PPLS,KB_PMNS,KB_END, KB_PGDN,KB_DOWN,KB_RSFT,KB_FN1, \ 116 LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \
117 KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_FN7), 117 LGUI,LALT, SPC, RALT,FN7),
118 118
119 /* Layer 2: Vi mode (Slash) 119 /* Layer 2: Vi mode (Slash)
120 * ,-----------------------------------------------------------. 120 * ,-----------------------------------------------------------.
@@ -129,11 +129,11 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
129 * |Gui|Alt |Space |Alt |Gui| 129 * |Gui|Alt |Space |Alt |Gui|
130 * `-------------------------------------------' 130 * `-------------------------------------------'
131 */ 131 */
132 KEYMAP(KB_ESC, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_INS, KB_DEL, \ 132 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
133 KB_TAB, KB_HOME,KB_PGDN,KB_UP, KB_PGUP,KB_END, KB_HOME,KB_PGDN,KB_PGUP,KB_END, KB_NO, KB_NO, KB_NO, KB_BSPC, \ 133 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC, \
134 KB_LCTL,KB_NO, KB_LEFT,KB_DOWN,KB_RGHT,KB_NO, KB_LEFT,KB_DOWN,KB_UP, KB_RGHT,KB_NO, KB_NO, KB_ENT, \ 134 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \
135 KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_HOME,KB_PGDN,KB_PGUP,KB_END, KB_FN2, KB_RSFT,KB_NO, \ 135 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN2, RSFT,NO, \
136 KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI), 136 LGUI,LALT, SPC, RALT,RGUI),
137 137
138 /* Layer 3: Mouse mode (Semicolon) 138 /* Layer 3: Mouse mode (Semicolon)
139 * ,-----------------------------------------------------------. 139 * ,-----------------------------------------------------------.
@@ -149,11 +149,24 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
149 * `--------------------------------------------' 149 * `--------------------------------------------'
150 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel 150 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
151 */ 151 */
152 KEYMAP(KB_ESC, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_INS, KB_DEL, \ 152#ifdef HOST_IWRAP
153 KB_TAB, KB_WH_L,KB_WH_U,KB_MS_U,KB_WH_D,KB_WH_R,KB_WH_L,KB_WH_D,KB_WH_U,KB_WH_R,KB_NO, KB_NO, KB_NO, KB_BSPC, \ 153// iWRAP does not support mouse wheel, use these keycodes to remap as wheel
154 KB_LCTL,KB_NO, KB_MS_L,KB_MS_D,KB_MS_R,KB_NO, KB_MS_L,KB_MS_D,KB_MS_U,KB_MS_R,KB_FN3, KB_NO, KB_ENT, \ 154#define KB_KPPL KB_KP_PLUS
155 KB_LSFT,KB_BTN4,KB_BTN5,KB_BTN1,KB_BTN2,KB_BTN3,KB_BTN2,KB_BTN1,KB_BTN4,KB_BTN5,KB_NO, KB_RSFT,KB_NO, \ 155#define KB_KPMI KB_KP_MINUS
156 KB_LGUI,KB_LALT,KB_BTN1,KB_RALT,KB_RGUI), 156#define KB_KPAS KB_KP_ASTERISK
157#define KB_KPSL KB_KP_SLASH
158 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
159 TAB, KPAS,KPPL,MS_U,KPMI,KPSL,KPAS,KPPL,KPMI,KPSL,NO, NO, NO, BSPC, \
160 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
161 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,NO, NO, NO, RSFT,NO, \
162 LGUI,LALT, BTN1, RALT,FN4),
163#else
164 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
165 TAB, WH_L,WH_U,MS_U,WH_D,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
166 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
167 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
168 LGUI,LALT, BTN1, RALT,FN4),
169#endif
157 170
158 /* Layer 4: Matias half keyboard style (Space) 171 /* Layer 4: Matias half keyboard style (Space)
159 * ,-----------------------------------------------------------. 172 * ,-----------------------------------------------------------.
@@ -169,18 +182,26 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
169 * `--------------------------------------------' 182 * `--------------------------------------------'
170 */ 183 */
171/* 184/*
172 KEYMAP(KB_MINS,KB_0, KB_9, KB_8, KB_7, KB_6, KB_5, KB_4, KB_3, KB_2, KB_1, KB_NO, KB_NO, KB_NO, KB_ESC, \ 185 KEYMAP(MINS,0, 9, 8, 7, 6, 5, 4, 3, 2, 1, NO, NO, NO, ESC, \
173 KB_BSPC,KB_P, KB_O, KB_I, KB_U, KB_Y, KB_T, KB_R, KB_E, KB_W, KB_Q, KB_NO, KB_NO, KB_TAB, \ 186 BSPC,P, O, I, U, Y, T, R, E, W, Q, NO, NO, TAB, \
174 KB_LCTL,KB_SCLN,KB_L, KB_K, KB_J, KB_H, KB_G, KB_F, KB_D, KB_S, KB_A, KB_RCTL,KB_RCTL, \ 187 LCTL,SCLN,L, K, J, H, G, F, D, S, A, RCTL,RCTL, \
175 KB_LSFT,KB_SLSH,KB_DOT, KB_COMM,KB_M, KB_N, KB_B, KB_V, KB_C, KB_X, KB_Z, KB_RSFT,KB_NO, \ 188 LSFT,SLSH,DOT, COMM,M, N, B, V, C, X, Z, RSFT,NO, \
176 KB_LGUI,KB_LALT,KB_FN4, KB_RALT,KB_RGUI) 189 LGUI,LALT, FN5, RALT,RGUI)
177*/ 190*/
178 /* Mouse mode (Space) */ 191 /* Mouse mode (Space) */
179 KEYMAP(KB_ESC, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_INS, KB_DEL, \ 192#ifdef HOST_IWRAP
180 KB_TAB, KB_WH_L,KB_WH_U,KB_MS_U,KB_WH_D,KB_WH_R,KB_WH_L,KB_WH_D,KB_WH_U,KB_WH_R,KB_NO, KB_NO, KB_NO, KB_BSPC, \ 193 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
181 KB_LCTL,KB_NO, KB_MS_L,KB_MS_D,KB_MS_R,KB_NO, KB_MS_L,KB_MS_D,KB_MS_U,KB_MS_R,KB_FN3, KB_NO, KB_ENT, \ 194 TAB, KPAS,KPPL,MS_U,KPMI,KPSL,KPAS,KPPL,KPMI,KPSL,NO, NO, NO, BSPC, \
182 KB_LSFT,KB_BTN4,KB_BTN5,KB_BTN1,KB_BTN2,KB_BTN3,KB_BTN2,KB_BTN1,KB_BTN4,KB_BTN5,KB_NO, KB_RSFT,KB_NO, \ 195 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
183 KB_LGUI,KB_LALT,KB_FN4, KB_RALT,KB_RGUI), 196 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
197 LGUI,LALT, FN5, RALT,RGUI),
198#else
199 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
200 TAB, WH_L,WH_U,MS_U,WH_D,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
201 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
202 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
203 LGUI,LALT, FN5, RALT,RGUI),
204#endif
184}; 205};
185 206
186 207
diff --git a/hhkb/matrix.c b/hhkb/matrix.c
index a77febb29..350066b90 100644
--- a/hhkb/matrix.c
+++ b/hhkb/matrix.c
@@ -25,9 +25,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
25#include <util/delay.h> 25#include <util/delay.h>
26#include "print.h" 26#include "print.h"
27#include "util.h" 27#include "util.h"
28#include "timer.h"
28#include "matrix.h" 29#include "matrix.h"
29 30
30 31
32// Timer resolution check
33#if (1000000/TIMER_RAW_FREQ > 20)
34# error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB."
35#endif
36
31#if (MATRIX_COLS > 16) 37#if (MATRIX_COLS > 16)
32# error "MATRIX_COLS must not exceed 16" 38# error "MATRIX_COLS must not exceed 16"
33#endif 39#endif
@@ -82,18 +88,22 @@ static bool matrix_has_ghost_in_row(uint8_t row);
82#define KEY_STATE() (PINE & (1<<6)) 88#define KEY_STATE() (PINE & (1<<6))
83#define KEY_PREV_ON() (PORTE |= (1<<7)) 89#define KEY_PREV_ON() (PORTE |= (1<<7))
84#define KEY_PREV_OFF() (PORTE &= ~(1<<7)) 90#define KEY_PREV_OFF() (PORTE &= ~(1<<7))
85 91#define KEY_POWER_ON()
92#define KEY_POWER_OFF()
86#else 93#else
87// Ports for V-USB 94// Ports for V-USB
88// key: PB0(pull-uped) 95// key: PB0(pull-uped)
89// prev: PB1 96// prev: PB1
90// row: PB2-4 97// row: PB2-4
91// col: PC0-2,3 98// col: PC0-2,3
99// power: PB5(Low:on/Hi-z:off)
92#define KEY_INIT() do { \ 100#define KEY_INIT() do { \
93 DDRB |= 0x1E; \ 101 DDRB |= 0x3E; \
94 DDRB &= ~(1<<0); \ 102 DDRB &= ~(1<<0); \
95 PORTB |= (1<<0); \ 103 PORTB |= 1<<0; \
96 DDRC |= 0x0F; \ 104 DDRC |= 0x0F; \
105 KEY_UNABLE(); \
106 KEY_PREV_OFF(); \
97} while (0) 107} while (0)
98#define KEY_SELECT(ROW, COL) do { \ 108#define KEY_SELECT(ROW, COL) do { \
99 PORTB = (PORTB & 0xE3) | ((ROW) & 0x07)<<2; \ 109 PORTB = (PORTB & 0xE3) | ((ROW) & 0x07)<<2; \
@@ -104,6 +114,18 @@ static bool matrix_has_ghost_in_row(uint8_t row);
104#define KEY_STATE() (PINB & (1<<0)) 114#define KEY_STATE() (PINB & (1<<0))
105#define KEY_PREV_ON() (PORTB |= (1<<1)) 115#define KEY_PREV_ON() (PORTB |= (1<<1))
106#define KEY_PREV_OFF() (PORTB &= ~(1<<1)) 116#define KEY_PREV_OFF() (PORTB &= ~(1<<1))
117// Power supply switching
118#define KEY_POWER_ON() do { \
119 KEY_INIT(); \
120 PORTB &= ~(1<<5); \
121 _delay_us(200); \
122} while (0)
123#define KEY_POWER_OFF() do { \
124 DDRB &= ~0x3F; \
125 PORTB &= ~0x3F; \
126 DDRC &= ~0x0F; \
127 PORTC &= ~0x0F; \
128} while (0)
107#endif 129#endif
108 130
109 131
@@ -138,36 +160,46 @@ uint8_t matrix_scan(void)
138 matrix_prev = matrix; 160 matrix_prev = matrix;
139 matrix = tmp; 161 matrix = tmp;
140 162
163 KEY_POWER_ON();
141 for (uint8_t row = 0; row < MATRIX_ROWS; row++) { 164 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
142 for (uint8_t col = 0; col < MATRIX_COLS; col++) { 165 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
143 KEY_SELECT(row, col); 166 KEY_SELECT(row, col);
144 _delay_us(40); // from logic analyzer chart 167 _delay_us(40);
168
169 // Not sure this is needed. This just emulates HHKB controller's behaviour.
145 if (matrix_prev[row] & (1<<col)) { 170 if (matrix_prev[row] & (1<<col)) {
146 KEY_PREV_ON(); 171 KEY_PREV_ON();
147 } 172 }
148 _delay_us(7); // from logic analyzer chart 173 _delay_us(7);
174
175 // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE.
176 // If V-USB interrupts in this section we could lose 40us or so
177 // and would read invalid value from KEY_STATE.
178 uint8_t last = TIMER_RAW;
149 179
150#if HOST_VUSB
151 // to avoid V-USB interrupt during read key state
152 uint8_t sreg = SREG;
153 cli();
154#endif
155 KEY_ENABLE(); 180 KEY_ENABLE();
156 _delay_us(10); // from logic analyzer chart 181 // Wait for KEY_STATE outputs its value.
182 // 1us was ok on one HHKB, but not worked on another.
183 _delay_us(10);
157 if (KEY_STATE()) { 184 if (KEY_STATE()) {
158 matrix[row] &= ~(1<<col); 185 matrix[row] &= ~(1<<col);
159 } else { 186 } else {
160 matrix[row] |= (1<<col); 187 matrix[row] |= (1<<col);
161 } 188 }
162#if HOST_VUSB 189
163 SREG = sreg; 190 // Ignore if this code region execution time elapses more than 20us.
164#endif 191 if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
192 matrix[row] = matrix_prev[row];
193 }
165 194
166 KEY_PREV_OFF(); 195 KEY_PREV_OFF();
167 KEY_UNABLE(); 196 KEY_UNABLE();
168 _delay_us(150); // from logic analyzer chart 197 // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
198 // This takes 25us or more to make sure KEY_STATE returns to idle state.
199 _delay_us(150);
169 } 200 }
170 } 201 }
202 KEY_POWER_OFF();
171 return 1; 203 return 1;
172} 204}
173 205
diff --git a/hhkb/usbconfig.h b/hhkb/usbconfig.h
index e8283505e..c3aad34be 100644
--- a/hhkb/usbconfig.h
+++ b/hhkb/usbconfig.h
@@ -171,7 +171,7 @@ section at the end of this file).
171/* This macro (if defined) is executed when a USB SET_ADDRESS request was 171/* This macro (if defined) is executed when a USB SET_ADDRESS request was
172 * received. 172 * received.
173 */ 173 */
174#define USB_COUNT_SOF 0 174#define USB_COUNT_SOF 1
175/* define this macro to 1 if you need the global variable "usbSofCount" which 175/* define this macro to 1 if you need the global variable "usbSofCount" which
176 * counts SOF packets. This feature requires that the hardware interrupt is 176 * counts SOF packets. This feature requires that the hardware interrupt is
177 * connected to D- instead of D+. 177 * connected to D- instead of D+.
@@ -352,8 +352,8 @@ section at the end of this file).
352#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 352#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
353#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 353#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
354#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 354#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
355//#define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC 355#define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC
356#define USB_CFG_DESCR_PROPS_HID 0 356//#define USB_CFG_DESCR_PROPS_HID 0
357#define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC 357#define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC
358//#define USB_CFG_DESCR_PROPS_HID_REPORT 0 358//#define USB_CFG_DESCR_PROPS_HID_REPORT 0
359#define USB_CFG_DESCR_PROPS_UNKNOWN 0 359#define USB_CFG_DESCR_PROPS_UNKNOWN 0
@@ -375,4 +375,14 @@ section at the end of this file).
375/* #define USB_INTR_PENDING_BIT INTF0 */ 375/* #define USB_INTR_PENDING_BIT INTF0 */
376/* #define USB_INTR_VECTOR INT0_vect */ 376/* #define USB_INTR_VECTOR INT0_vect */
377 377
378/* Set INT1 for D- falling edge to count SOF */
379/* #define USB_INTR_CFG EICRA */
380#define USB_INTR_CFG_SET ((1 << ISC11) | (0 << ISC10))
381/* #define USB_INTR_CFG_CLR 0 */
382/* #define USB_INTR_ENABLE EIMSK */
383#define USB_INTR_ENABLE_BIT INT1
384/* #define USB_INTR_PENDING EIFR */
385#define USB_INTR_PENDING_BIT INTF1
386#define USB_INTR_VECTOR INT1_vect
387
378#endif /* __usbconfig_h_included__ */ 388#endif /* __usbconfig_h_included__ */
diff --git a/host.c b/host.c
new file mode 100644
index 000000000..65b5ddcbb
--- /dev/null
+++ b/host.c
@@ -0,0 +1,190 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include <avr/interrupt.h>
20#include "usb_keycodes.h"
21#include "host.h"
22#include "util.h"
23#include "debug.h"
24
25
26#ifdef NKRO_ENABLE
27bool keyboard_nkro = false;
28#endif
29
30static host_driver_t *driver;
31static report_keyboard_t report0;
32static report_keyboard_t report1;
33report_keyboard_t *keyboard_report = &report0;
34report_keyboard_t *keyboard_report_prev = &report1;
35
36
37static inline void add_key_byte(uint8_t code);
38static inline void add_key_bit(uint8_t code);
39
40
41void host_set_driver(host_driver_t *d)
42{
43 driver = d;
44}
45
46host_driver_t *host_get_driver(void)
47{
48 return driver;
49}
50
51uint8_t host_keyboard_leds(void)
52{
53 if (!driver) return 0;
54 return (*driver->keyboard_leds)();
55}
56
57/* keyboard report operations */
58void host_add_key(uint8_t key)
59{
60#ifdef NKRO_ENABLE
61 if (keyboard_nkro) {
62 add_key_bit(key);
63 return;
64 }
65#endif
66 add_key_byte(key);
67}
68
69void host_add_mod_bit(uint8_t mod)
70{
71 keyboard_report->mods |= mod;
72}
73
74void host_set_mods(uint8_t mods)
75{
76 keyboard_report->mods = mods;
77}
78
79void host_add_code(uint8_t code)
80{
81 if (IS_MOD(code)) {
82 host_add_mod_bit(MOD_BIT(code));
83 } else {
84 host_add_key(code);
85 }
86}
87
88void host_swap_keyboard_report(void)
89{
90 uint8_t sreg = SREG;
91 cli();
92 report_keyboard_t *tmp = keyboard_report_prev;
93 keyboard_report_prev = keyboard_report;
94 keyboard_report = tmp;
95 SREG = sreg;
96}
97
98void host_clear_keyboard_report(void)
99{
100 keyboard_report->mods = 0;
101 for (int8_t i = 0; i < REPORT_KEYS; i++) {
102 keyboard_report->keys[i] = 0;
103 }
104}
105
106uint8_t host_has_anykey(void)
107{
108 uint8_t cnt = 0;
109 for (int i = 0; i < REPORT_KEYS; i++) {
110 if (keyboard_report->keys[i])
111 cnt++;
112 }
113 return cnt;
114}
115
116uint8_t host_get_first_key(void)
117{
118#ifdef NKRO_ENABLE
119 if (keyboard_nkro) {
120 uint8_t i = 0;
121 for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++)
122 ;
123 return i<<3 | biton(keyboard_report->keys[i]);
124 }
125#endif
126 return keyboard_report->keys[0];
127}
128
129
130void host_send_keyboard_report(void)
131{
132 if (!driver) return;
133 (*driver->send_keyboard)(keyboard_report);
134}
135
136void host_mouse_send(report_mouse_t *report)
137{
138 if (!driver) return;
139 (*driver->send_mouse)(report);
140}
141
142void host_system_send(uint16_t data)
143{
144 if (!driver) return;
145 (*driver->send_consumer)(data);
146}
147
148void host_consumer_send(uint16_t data)
149{
150 // TODO: this is needed?
151 static uint16_t last_data = 0;
152 if (data == last_data) return;
153 last_data = data;
154
155 if (!driver) return;
156 (*driver->send_consumer)(data);
157}
158
159
160static inline void add_key_byte(uint8_t code)
161{
162 // TODO: fix ugly code
163 int8_t i = 0;
164 int8_t empty = -1;
165 for (; i < REPORT_KEYS; i++) {
166 if (keyboard_report_prev->keys[i] == code) {
167 keyboard_report->keys[i] = code;
168 break;
169 }
170 if (empty == -1 &&
171 keyboard_report_prev->keys[i] == 0 &&
172 keyboard_report->keys[i] == 0) {
173 empty = i;
174 }
175 }
176 if (i == REPORT_KEYS) {
177 if (empty != -1) {
178 keyboard_report->keys[empty] = code;
179 }
180 }
181}
182
183static inline void add_key_bit(uint8_t code)
184{
185 if ((code>>3) < REPORT_KEYS) {
186 keyboard_report->keys[code>>3] |= 1<<(code&7);
187 } else {
188 debug("add_key_bit: can't add: "); phex(code); debug("\n");
189 }
190}
diff --git a/host.h b/host.h
index bdbd7db05..06f1311ab 100644
--- a/host.h
+++ b/host.h
@@ -19,88 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#define HOST_H 19#define HOST_H
20 20
21#include <stdint.h> 21#include <stdint.h>
22#include "report.h"
23#include "host_driver.h"
22 24
23 25
24/* report id */ 26#ifdef NKRO_ENABLE
25#define REPORT_ID_MOUSE 1
26#define REPORT_ID_SYSTEM 2
27#define REPORT_ID_CONSUMER 3
28
29/* keyboard Modifiers in boot protocol report */
30#define BIT_LCTRL (1<<0)
31#define BIT_LSHIFT (1<<1)
32#define BIT_LALT (1<<2)
33#define BIT_LGUI (1<<3)
34#define BIT_RCTRL (1<<4)
35#define BIT_RSHIFT (1<<5)
36#define BIT_RALT (1<<6)
37#define BIT_RGUI (1<<7)
38#define BIT_LCTL BIT_LCTRL
39#define BIT_RCTL BIT_RCTRL
40#define BIT_LSFT BIT_LSHIFT
41#define BIT_RSFT BIT_RSHIFT
42
43/* mouse buttons */
44#define MOUSE_BTN1 (1<<0)
45#define MOUSE_BTN2 (1<<1)
46#define MOUSE_BTN3 (1<<2)
47#define MOUSE_BTN4 (1<<3)
48#define MOUSE_BTN5 (1<<4)
49
50// Consumer Page(0x0C)
51#define AUDIO_MUTE 0x00E2
52#define AUDIO_VOL_UP 0x00E9
53#define AUDIO_VOL_DOWN 0x00EA
54#define TRANSPORT_NEXT_TRACK 0x00B5
55#define TRANSPORT_PREV_TRACK 0x00B6
56#define TRANSPORT_STOP 0x00B7
57#define TRANSPORT_PLAY_PAUSE 0x00CD
58#define AL_CC_CONFIG 0x0183
59#define AL_EMAIL 0x018A
60#define AL_CALCULATOR 0x0192
61#define AL_LOCAL_BROWSER 0x0194
62#define AC_SEARCH 0x0221
63#define AC_HOME 0x0223
64#define AC_BACK 0x0224
65#define AC_FORWARD 0x0225
66#define AC_STOP 0x0226
67#define AC_REFRESH 0x0227
68#define AC_BOOKMARKS 0x022A
69
70// Generic Desktop Page(0x01)
71#define SYSTEM_POWER_DOWN 0x0081
72#define SYSTEM_SLEEP 0x0082
73#define SYSTEM_WAKE_UP 0x0083
74
75
76#if defined(HOST_PJRC)
77# include "usb.h"
78# if defined(KBD2_REPORT_KEYS) && KBD2_REPORT_KEYS > KBD_REPORT_KEYS
79# define REPORT_KEYS KBD2_REPORT_KEYS
80# else
81# define REPORT_KEYS KBD_REPORT_KEYS
82# endif
83#elif defined(HOST_VUSB)
84# define REPORT_KEYS 6
85#endif
86
87typedef struct {
88 uint8_t mods;
89 uint8_t rserved;
90 uint8_t keys[REPORT_KEYS];
91} report_keyboard_t;
92
93typedef struct {
94 uint8_t report_id;
95 uint8_t buttons;
96 int8_t x;
97 int8_t y;
98 int8_t v;
99 int8_t h;
100} report_mouse_t;
101
102
103#ifdef USB_NKRO_ENABLE
104extern bool keyboard_nkro; 27extern bool keyboard_nkro;
105#endif 28#endif
106 29
@@ -108,6 +31,8 @@ extern report_keyboard_t *keyboard_report;
108extern report_keyboard_t *keyboard_report_prev; 31extern report_keyboard_t *keyboard_report_prev;
109 32
110 33
34void host_set_driver(host_driver_t *driver);
35host_driver_t *host_get_driver(void);
111uint8_t host_keyboard_leds(void); 36uint8_t host_keyboard_leds(void);
112 37
113/* keyboard report operations */ 38/* keyboard report operations */
@@ -122,12 +47,8 @@ uint8_t host_get_first_key(void);
122 47
123 48
124void host_send_keyboard_report(void); 49void host_send_keyboard_report(void);
125#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
126void host_mouse_send(report_mouse_t *report); 50void host_mouse_send(report_mouse_t *report);
127#endif
128#ifdef USB_EXTRA_ENABLE
129void host_system_send(uint16_t data); 51void host_system_send(uint16_t data);
130void host_consumer_send(uint16_t data); 52void host_consumer_send(uint16_t data);
131#endif
132 53
133#endif 54#endif
diff --git a/host_driver.h b/host_driver.h
new file mode 100644
index 000000000..edb9e5dd9
--- /dev/null
+++ b/host_driver.h
@@ -0,0 +1,33 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef HOST_DRIVER_H
19#define HOST_DRIVER_H
20
21#include <stdint.h>
22#include "report.h"
23
24
25typedef struct {
26 uint8_t (*keyboard_leds)(void);
27 void (*send_keyboard)(report_keyboard_t *);
28 void (*send_mouse)(report_mouse_t *);
29 void (*send_system)(uint16_t);
30 void (*send_consumer)(uint16_t);
31} host_driver_t;
32
33#endif
diff --git a/iwrap.mk b/iwrap.mk
new file mode 100644
index 000000000..ea4a6e972
--- /dev/null
+++ b/iwrap.mk
@@ -0,0 +1,10 @@
1OPT_DEFS += -DHOST_IWRAP
2
3SRC += iwrap.c \
4 suart.S \
5 sendchar_uart.c \
6 uart.c
7
8
9# Search Path
10VPATH += $(COMMON_DIR)/iwrap
diff --git a/iwrap/iWRAP.txt b/iwrap/iWRAP.txt
new file mode 100644
index 000000000..2a062d9d9
--- /dev/null
+++ b/iwrap/iWRAP.txt
@@ -0,0 +1,376 @@
1Bulegiga WT12
2=============
3WT12 is a bluetooth module from Bluegiga. http://www.bluegiga.com/
4
5iWRAP
6 higher layer interface for bluetooth firmware
7 communicate with UART
8
9iWRAP HID
10default setting
11 115200 8bit/n/1/n
12
13
14TODO
15----
16KiCAD circuit/PCB design
17power saving
18 AVR sleep(15ms by watch dog timer)
19 WT12 sleep
20 measuring current consumption
21 measuring battery life of normal usage/idle/intensive usage
22software reset/bootloarder
23LED indicator(chaging/paring/connecting)
24license confirmation of suart.c
25consumer page is not working
26authenticate method/SSP
27SPP keyboard support
28SPP debug console support
29mouse wheel feature request to Bluegiga
30
31
32Problems
33--------
34power consumption
35no consumer page support(bug?)
36no mouse wheel support
37no paring management
38no interactive auth method
39
40
41UART hardware flow control
42--------------------------
43(iWRAP4 User Guide 9.5)
44Hardware flow control is enabled by default and it should not be disabled unless mandatory, because without the hardware flow control the data transmission may not be reliable.
45If the hardware flow control is enabled from PS-keys, but no flow control is used, the following steps should be implemented in the hardware design:
46- CTS pin must be grounded
47- RTS pin must be left floating
48
49
50Power Saving
51------------
52power consume
53 without opimization: 4hr to shutdown(310mAh)
54 2011/08/25: 9hr(310mAh) SNIFF MASTER sleep/WDTO_120MS
55
56measure current consumption
57 HHKB keyswitch matrix board
58 idle
59 scanning
60 Bluegiga WT12 module
61 SLEEP command
62 deep sleep on/off in config bits
63
64HHKB keyswich
65 how to power off
66 I/O pin configuration when sleeping
67 FET switch for 5V regulator
68
69Bluetooth module
70 power off when in USB mode
71 power off by FET switch
72
73AVR configuration
74 unused pins
75 ADC
76
77
78
79SET CONTROL CONFIG
80------------------
81 SET CONTROL CONFIG 4810
82 SET CONTROL CONFIG LIST
83 SET CONTROL CONFIG 0000 0000 4910 DEEP_SLEEP KLUDGE INTERACTIVE_PIN UART_LATENCY
84
85 Bit14 UART low latency
86 Bit11 Interactive pairing mode
87 Bit04 Deep sleep
88
89
90Reconnection
91------------
92SET CONTROL AUTOCALL 1124 5000 HID
93 1124 HID service class
94 5000 interval ms
95
96HID profile
97-----------
98This is needed to configure only once.
99 SET PROFILE HID ON
100 RESET
101
102HID class
103---------
104 SET BT CLASS 005C0 // keyboard/mouse combined devie
105
106Pairing Security
107----------------
108Secure Simple Pairing(SSP)
109 SET BT SSP 2 0 // Enables SSP for keyboard and Man-in-the-middle protection
110 SET BT SSP 3 0 // Enables SSP just works mode
111
112for keyboard with SSP
113 SET BT AUTH * 0000
114 SET BT SSP 2 0
115 SET CONTROL CONFIG 800
116 RESET
117
118for keyboard without SSP
119 SET BT AUTH * 0000
120 SET CONTROL CONFIG 800
121 RESET
122
123AUTH
124 AUTH xx:xx:xx:xx:xx:xx? // Pairing request event
125 AUTH xx:xx:xx:xx:xx:xx 0000
126
127 SSP PASSKEY 78:dd:08:b7:e4:a2 ?
128 SSP PASSKEY 78:dd:08:b7:e4:a2 xxxxx
129 (SSP COMPLETE 78:dd:08:b7:e4:a2 HCI_ERROR_AUTH_FAIL // failed)
130 RING 0 78:dd:08:b7:e4:a2 11 HID
131
132Connecton
133 RING xx:xx:xx:xx:xx:xx xx HID // connection event
134
135 KILL xx:xx:xx:xx:xx:xx
136
137Mode
138----
139Command mode
140Data mode
141 Raw mode
142 (Simple mode not for a real keyboard)
143
144Raw mode
145 Keyboard:
146 0x9f, length(10), 0xa1, 0x01, mods, 0x00, key1, key2, key3, key4, key5, key6
147
148 Mouse:
149 0x9f, length(5), 0xa1, 0x02, buttons, X, Y
150
151 Consumer page:
152 0x9f, length(5), 0xa1, 0x03, bitfield1, bitfield2, bitfield3
153
154 consumer page suage
155 Bitfield 1:
156 0x01 Volume Increment
157 0x02 Volume Decrement
158 0x04 Mute
159 0x08 Play/Pause
160 0x10 Scan Next Track
161 0x20 Scan Previous Track
162 0x40 Stop
163 0x80 Eject
164 Bitfield 2:
165 0x01 Email Reader
166 0x02 Application Control Search
167 0x04 AC Bookmarks
168 0x08 AC Home
169 0x10 AC Back
170 0x20 AC Forward
171 0x40 AC Stop
172 0x80 AC Refresh
173 Bitfield 3:
174 0x01 Application Launch Generic Consumer Control
175 0x02 AL Internet Browser
176 0x04 AL Calculator
177 0x08 AL Terminal Lock / Screensaver
178 0x10 AL Local Machine Browser
179 0x20 AC Minimize
180 0x40 Record
181 0x80 Rewind
182
183
184
185
186
1872011/07/13
188set
189SET BT BDADDR 00:07:80:47:22:14
190SET BT NAME HHKB pro BT
191SET BT CLASS 0005c0
192SET BT AUTH * 0000
193SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
194SET BT LAP 9e8b33
195SET BT PAGEMODE 4 2000 1
196SET BT PAIR 78:dd:08:b7:e4:a2 a191189cd7e51030ad6a07848ce879bb
197SET BT POWER 3 3 3
198SET BT ROLE 0 f 7d00
199SET BT SNIFF 0 20 1 8
200SET BT SSP 2 1
201SET BT MTU 667
202SET CONTROL AUTOCALL 1124 3000 HID
203SET CONTROL BAUD 38400,8n1
204SET CONTROL CD 00 0
205SET CONTROL ECHO 7
206SET CONTROL ESCAPE 43 00 1
207SET CONTROL GAIN 0 5
208SET CONTROL INIT SET CONTROL MUX 0
209SET CONTROL MSC DTE 00 00 00 00 00 00
210SET CONTROL MUX 1
211SET CONTROL PIO 00 00
212SET CONTROL READY 00
213SET PROFILE HID f HID
214SET
215
216info config
217
218!!! THIS IS BETA RELEASE AND MAY BE USED FOR EVALUATION PURPOSES ONLY !!!
219
220WRAP THOR AI (4.1.0 build 435)
221Copyright (c) 2003-2011 Bluegiga Technologies Inc.
222Compiled on Jun 28 2011 17:19:51, running on WT12-A module, psr v31
223 AVRCP BGIO FTP HFP HFP_AG HID HID_CONSUMER_PAGE HSP LEDS MAP OTA PBAP PIO=0x00fc SSP SUBRATE TEST VOLUME
224 - BOCK3 version 435 (Jun 28 2011 17:19:37) (max acl/sco 7/1)
225 - Bluetooth version 2.1, Power class 2
226 - Loader 4279, firmware 6297 (56-bit encryption), native execution mode
227 - up 0 days, 06:23, 2 connections (pool 2)
228 - User configuration:
229&028a = 0001 0000 0000 0011 0024 0000 0000 0010 0000 0080 0000 0000 0080 005f 009b 0034 00fb 0006
230&028b = 0000 0bb8
231&028d = 0001
232&0295 = 0000 0005 000b 0000 0003 0000 0000 0000 0000 0000 0000
233&0298 = a006
234&0299 = 0000 0000
235&02a3 = 0030 0030 0030 0030
236&02a4 = 009d 0000
237&02a5 = 0053 0045 0054 0020 0043 004f 004e 0054 0052 004f 004c 0020 004d 0055 0058 0020 0030
238&02a7 = 0000 05c0
239&02a8 = 4910 0000 0000
240&02aa = 0004 2000 0001 0033 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
241&02ac = 0000 0000 002b 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
242&02ad = 4848 424b 7020 6f72 4220 0054
243&02b3 = 0005 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003
244&02b7 = 000f 4948 0044
245&02bb = 8000
246READY.
247
248
249
250
2512011/07/07 settings:
252set
253SET BT BDADDR 00:07:80:47:22:14
254SET BT NAME HHKB Pro BT
255SET BT CLASS 0005c0
256SET BT AUTH * 000
257SET BT IDENT BT:47 f000 4.0.0 Bluegiga iWRAP
258SET BT LAP 9e8b33
259SET BT PAGEMODE 4 2000 1
260SET BT PAIR 78:dd:08:b7:e4:a2 9e54d0aabb1b4d73cfccddb1ea4ef2d6
261SET BT POWER 3 3 3
262SET BT ROLE 0 f 7d00
263SET BT SNIFF 0 20 1 8
264SET BT SSP 3 0
265SET BT MTU 667
266SET CONTROL BAUD 38400,8n1
267SET CONTROL CD 00 0
268SET CONTROL ECHO 7
269SET CONTROL ESCAPE 255 00 1
270SET CONTROL GAIN 0 5
271SET CONTROL INIT set control mux 0
272SET CONTROL MSC DTE 00 00 00 00 00 00
273SET CONTROL PREAMP 1 1
274SET CONTROL READY 00
275SET PROFILE HID HID
276SET PROFILE SPP Bluetooth Serial Port
277SET
278
279info config
280WRAP THOR AI (4.0.0 build 317)
281Copyright (c) 2003-2010 Bluegiga Technologies Inc.
282Compiled on Apr 20 2010 16:44:28, running on WT12-A module, psr v31
283 AVRCP FTP PBAP PIO=0x00fc SSP SUBRATE VOLUME
284 - BOCK3 version 317 (Apr 20 2010 16:44:21) (max acl/sco 7/1)
285 - Bluetooth version 2.1, Power class 2
286 - Loader 4279, firmware 6297 (56-bit encryption), native execution mode
287 - up 0 days, 00:00, 0 connections (pool 1)
288 - User configuration:
289&028c = 0001 0020 0000 0001 0008 0000
290&028d = 0000
291&0296 = 0047 0001 f000 0400 6c42 6575 6967 6167 6920 5257 5041
292&0298 = c006
293&02a3 = 0030 0030 0030
294&02a4 = 009d 0000
295&02a5 = 0073 0065 0074 0020 0063 006f 006e 0074 0072 006f 006c 0020 006d 0075 0078 0020 0030
296&02a7 = 0000 05c0
297&02a8 = 0800 0000 0000
298&02ac = 0000 0000 00ff 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
299&02ad = 4848 424b 5020 6f72 4220 0054
300&02b3 = 0004 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003
301&02b7 = 0000
302&02bb = 6c42 6575 6f74 746f 2068 6553 6972 6c61 5020 726f 0074
303READY.
304
305
306
3072011/08/23:
308SET BT BDADDR 00:07:80:47:22:14
309SET BT NAME HHKB pro BT
310SET BT CLASS 0005c0
311SET BT AUTH * 0000
312SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
313SET BT LAP 9e8b33
314SET BT PAGEMODE 4 2000 1
315SET BT PAIRCOUNT 4
316SET BT POWER 3 3 3
317SET BT ROLE 1 f 12c0
318SET BT SNIFF 10 2 1 8
319SET BT SSP 3 0
320SET BT MTU 667
321SET CONTROL BAUD 38400,8n1
322SET CONTROL CD 00 0
323SET CONTROL ECHO 7
324SET CONTROL ESCAPE 43 00 1
325SET CONTROL GAIN 0 5
326SET CONTROL INIT SET CONTROL MUX 0
327SET CONTROL MSC DTE 00 00 00 00 00 00
328SET CONTROL MUX 1
329SET CONTROL PIO 00 00
330SET CONTROL READY 00
331SET PROFILE HID 7 HIDKeyboardMouse
332SET
333
334SET CONTROL CONFIG 0000 0004 481e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE DEEP_SLEEP INTERACTIVE_PIN UART_LATENCY 23D_NOKLUDGE
335
336
337
3382011/08/25:
339SET BT BDADDR 00:07:80:47:22:14
340SET BT NAME HHKB pro BT
341SET BT CLASS 0005c0
342
343SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
344SET BT LAP 9e8b33
345SET BT PAGEMODE 4 2000 1
346SET BT PAIRCOUNT 4
347SET BT PAIR 78:dd:08:b7:e4:a2 0be83335a03fed8ededae42e99554e28
348SET BT POWER 3 3 3
349SET BT ROLE 1 f 12c0
350SET BT SNIFF 100 20 1 8
351SET BT SSP 3 0
352SET BT MTU 667
353SET CONTROL BAUD 38400,8n1
354SET CONTROL CD 00 0
355SET CONTROL ECHO 7
356SET CONTROL ESCAPE - 20 1
357SET CONTROL GAIN 0 5
358SET CONTROL INIT SET CONTROL MUX 0
359SET CONTROL MSC DTE 00 00 00 00 00 00
360SET CONTROL MUX 1
361SET CONTROL PIO 00 00
362SET CONTROL READY 00
363SET PROFILE HID f HIDKeyboardMouse
364SET
365
366
367SET CONTROL CONFIG 0000 0000 490e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE KLUDGE INTERACTIVE_PIN UART_LATENCY
368
369
3702011/09/08:
371SET CONTROL CONFIG 0000 0000 410e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE KLUDGE UART_LATENCY
372
373 Removed INTERACTIVE_PIN to avoid interactive auth and use SET BT AUTH pin(0000).
374
375
376EOF
diff --git a/iwrap/iwrap.c b/iwrap/iwrap.c
new file mode 100644
index 000000000..9c68761bf
--- /dev/null
+++ b/iwrap/iwrap.c
@@ -0,0 +1,467 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/* host driver for Bulegiga iWRAP */
19/* Bluegiga BT12
20 * Connections
21 * Hardware UART Software UART BlueTooth
22 * PC=====UART=======AVR=====SUART====iWRAP(BT12)-----------PC
23 *
24 * - Hardware UART for Debug Console to communicate iWRAP
25 * - Software UART for iWRAP control to send keyboard/mouse data
26 */
27
28#include <stdint.h>
29#include <string.h>
30#include <avr/interrupt.h>
31#include <util/delay.h>
32#include "usb_keycodes.h"
33#include "suart.h"
34#include "uart.h"
35#include "report.h"
36#include "host_driver.h"
37#include "iwrap.h"
38#include "print.h"
39
40
41/* iWRAP MUX mode utils. 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf) */
42#define MUX_HEADER(LINK, LENGTH) do { \
43 xmit(0xbf); /* SOF */ \
44 xmit(LINK); /* Link */ \
45 xmit(0x00); /* Flags */ \
46 xmit(LENGTH); /* Length */ \
47} while (0)
48#define MUX_FOOTER(LINK) xmit(LINK^0xff)
49
50
51static uint8_t connected = 0;
52//static uint8_t channel = 1;
53
54/* iWRAP buffer */
55#define MUX_BUF_SIZE 64
56static char buf[MUX_BUF_SIZE];
57static uint8_t snd_pos = 0;
58
59#define MUX_RCV_BUF_SIZE 256
60static char rcv_buf[MUX_RCV_BUF_SIZE];
61static uint8_t rcv_head = 0;
62static uint8_t rcv_tail = 0;
63
64
65/* receive buffer */
66static void rcv_enq(char c)
67{
68 uint8_t next = (rcv_head + 1) % MUX_RCV_BUF_SIZE;
69 if (next != rcv_tail) {
70 rcv_buf[rcv_head] = c;
71 rcv_head = next;
72 }
73}
74
75static char rcv_deq(void)
76{
77 char c = 0;
78 if (rcv_head != rcv_tail) {
79 c = rcv_buf[rcv_tail++];
80 rcv_tail %= MUX_RCV_BUF_SIZE;
81 }
82 return c;
83}
84
85/*
86static char rcv_peek(void)
87{
88 if (rcv_head == rcv_tail)
89 return 0;
90 return rcv_buf[rcv_tail];
91}
92*/
93
94static void rcv_clear(void)
95{
96 rcv_tail = rcv_head = 0;
97}
98
99/* iWRAP response */
100ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
101{
102 if ((SUART_IN_PIN & (1<<SUART_IN_BIT)))
103 return;
104
105 static volatile uint8_t mux_state = 0xff;
106 static volatile uint8_t mux_link = 0xff;
107 uint8_t c = recv();
108 switch (mux_state) {
109 case 0xff: // SOF
110 if (c == 0xbf)
111 mux_state--;
112 break;
113 case 0xfe: // Link
114 mux_state--;
115 mux_link = c;
116 break;
117 case 0xfd: // Flags
118 mux_state--;
119 break;
120 case 0xfc: // Length
121 mux_state = c;
122 break;
123 case 0x00:
124 mux_state = 0xff;
125 mux_link = 0xff;
126 break;
127 default:
128 if (mux_state--) {
129 uart_putchar(c);
130 rcv_enq(c);
131 }
132 }
133}
134
135
136/*------------------------------------------------------------------*
137 * iWRAP communication
138 *------------------------------------------------------------------*/
139void iwrap_init(void)
140{
141 // reset iWRAP if in already MUX mode after AVR software-reset
142 iwrap_send("RESET");
143 iwrap_mux_send("RESET");
144 _delay_ms(3000);
145 iwrap_send("\r\nSET CONTROL MUX 1\r\n");
146 _delay_ms(500);
147 iwrap_check_connection();
148}
149
150void iwrap_mux_send(const char *s)
151{
152 rcv_clear();
153 MUX_HEADER(0xff, strlen((char *)s));
154 iwrap_send(s);
155 MUX_FOOTER(0xff);
156}
157
158void iwrap_send(const char *s)
159{
160 while (*s)
161 xmit(*s++);
162}
163
164/* send buffer */
165void iwrap_buf_add(uint8_t c)
166{
167 // need space for '\0'
168 if (snd_pos < MUX_BUF_SIZE-1)
169 buf[snd_pos++] = c;
170}
171
172void iwrap_buf_del(void)
173{
174 if (snd_pos)
175 snd_pos--;
176}
177
178void iwrap_buf_send(void)
179{
180 buf[snd_pos] = '\0';
181 snd_pos = 0;
182 iwrap_mux_send(buf);
183}
184
185void iwrap_call(void)
186{
187 char *p;
188
189 iwrap_mux_send("SET BT PAIR");
190 _delay_ms(500);
191
192 p = rcv_buf + rcv_tail;
193 while (!strncmp(p, "SET BT PAIR", 11)) {
194 p += 7;
195 strncpy(p, "CALL", 4);
196 strncpy(p+22, " 11 HID\n\0", 9);
197 print_S(p);
198 iwrap_mux_send(p);
199 // TODO: skip to next line
200 p += 57;
201
202 DEBUG_LED_CONFIG;
203 DEBUG_LED_ON;
204 _delay_ms(500);
205 DEBUG_LED_OFF;
206 _delay_ms(500);
207 DEBUG_LED_ON;
208 _delay_ms(500);
209 DEBUG_LED_OFF;
210 _delay_ms(500);
211 DEBUG_LED_ON;
212 _delay_ms(500);
213 DEBUG_LED_OFF;
214 _delay_ms(500);
215 DEBUG_LED_ON;
216 _delay_ms(500);
217 DEBUG_LED_OFF;
218 _delay_ms(500);
219 DEBUG_LED_ON;
220 _delay_ms(500);
221 DEBUG_LED_OFF;
222 _delay_ms(500);
223 }
224 iwrap_check_connection();
225}
226
227void iwrap_kill(void)
228{
229 char c;
230 iwrap_mux_send("LIST");
231 _delay_ms(500);
232
233 while ((c = rcv_deq()) && c != '\n') ;
234 if (strncmp(rcv_buf + rcv_tail, "LIST ", 5)) {
235 print("no connection to kill.\n");
236 return;
237 }
238 // skip 10 'space' chars
239 for (uint8_t i = 10; i; i--)
240 while ((c = rcv_deq()) && c != ' ') ;
241
242 char *p = rcv_buf + rcv_tail - 5;
243 strncpy(p, "KILL ", 5);
244 strncpy(p + 22, "\n\0", 2);
245 print_S(p);
246 iwrap_mux_send(p);
247 _delay_ms(500);
248
249 iwrap_check_connection();
250}
251
252void iwrap_unpair(void)
253{
254 iwrap_mux_send("SET BT PAIR");
255 _delay_ms(500);
256
257 char *p = rcv_buf + rcv_tail;
258 if (!strncmp(p, "SET BT PAIR", 11)) {
259 strncpy(p+29, "\n\0", 2);
260 print_S(p);
261 iwrap_mux_send(p);
262 }
263}
264
265void iwrap_sleep(void)
266{
267 iwrap_mux_send("SLEEP");
268}
269
270void iwrap_sniff(void)
271{
272}
273
274void iwrap_subrate(void)
275{
276}
277
278bool iwrap_failed(void)
279{
280 if (strncmp(rcv_buf, "SYNTAX ERROR", 12))
281 return true;
282 else
283 return false;
284}
285
286uint8_t iwrap_connected(void)
287{
288 return connected;
289}
290
291uint8_t iwrap_check_connection(void)
292{
293 iwrap_mux_send("LIST");
294 _delay_ms(100);
295
296 if (strncmp(rcv_buf, "LIST ", 5) || !strncmp(rcv_buf, "LIST 0", 6))
297 connected = 0;
298 else
299 connected = 1;
300 return connected;
301}
302
303
304/*------------------------------------------------------------------*
305 * Host driver
306 *------------------------------------------------------------------*/
307static uint8_t keyboard_leds(void);
308static void send_keyboard(report_keyboard_t *report);
309static void send_mouse(report_mouse_t *report);
310static void send_system(uint16_t data);
311static void send_consumer(uint16_t data);
312
313static host_driver_t driver = {
314 keyboard_leds,
315 send_keyboard,
316 send_mouse,
317 send_system,
318 send_consumer
319};
320
321host_driver_t *iwrap_driver(void)
322{
323 return &driver;
324}
325
326static uint8_t keyboard_leds(void) {
327 return 0;
328}
329
330static void send_keyboard(report_keyboard_t *report)
331{
332 if (!iwrap_connected() && !iwrap_check_connection()) return;
333 MUX_HEADER(0x01, 0x0c);
334 // HID raw mode header
335 xmit(0x9f);
336 xmit(0x0a); // Length
337 xmit(0xa1); // keyboard report
338 xmit(0x01);
339 xmit(report->mods);
340 xmit(0x00); // reserved byte(always 0)
341 xmit(report->keys[0]);
342 xmit(report->keys[1]);
343 xmit(report->keys[2]);
344 xmit(report->keys[3]);
345 xmit(report->keys[4]);
346 xmit(report->keys[5]);
347 MUX_FOOTER(0x01);
348}
349
350static void send_mouse(report_mouse_t *report)
351{
352#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
353 if (!iwrap_connected() && !iwrap_check_connection()) return;
354 MUX_HEADER(0x01, 0x07);
355 // HID raw mode header
356 xmit(0x9f);
357 xmit(0x05); // Length
358 xmit(0xa1); // mouse report
359 xmit(0x02);
360 xmit(report->buttons);
361 xmit(report->x);
362 xmit(report->y);
363 MUX_FOOTER(0x01);
364#endif
365}
366
367static void send_system(uint16_t data)
368{
369 /* not supported */
370}
371
372static void send_consumer(uint16_t data)
373{
374#ifdef EXTRAKEY_ENABLE
375 static uint16_t last_data = 0;
376 uint8_t bits1 = 0;
377 uint8_t bits2 = 0;
378 uint8_t bits3 = 0;
379
380 if (!iwrap_connected() && !iwrap_check_connection()) return;
381 if (data == last_data) return;
382 last_data = data;
383
384 // 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf)
385 switch (data) {
386 case AUDIO_VOL_UP:
387 bits1 = 0x01;
388 break;
389 case AUDIO_VOL_DOWN:
390 bits1 = 0x02;
391 break;
392 case AUDIO_MUTE:
393 bits1 = 0x04;
394 break;
395 case TRANSPORT_PLAY_PAUSE:
396 bits1 = 0x08;
397 break;
398 case TRANSPORT_NEXT_TRACK:
399 bits1 = 0x10;
400 break;
401 case TRANSPORT_PREV_TRACK:
402 bits1 = 0x20;
403 break;
404 case TRANSPORT_STOP:
405 bits1 = 0x40;
406 break;
407 case TRANSPORT_EJECT:
408 bits1 = 0x80;
409 break;
410 case AL_EMAIL:
411 bits2 = 0x01;
412 break;
413 case AC_SEARCH:
414 bits2 = 0x02;
415 break;
416 case AC_BOOKMARKS:
417 bits2 = 0x04;
418 break;
419 case AC_HOME:
420 bits2 = 0x08;
421 break;
422 case AC_BACK:
423 bits2 = 0x10;
424 break;
425 case AC_FORWARD:
426 bits2 = 0x20;
427 break;
428 case AC_STOP:
429 bits2 = 0x40;
430 break;
431 case AC_REFRESH:
432 bits2 = 0x80;
433 break;
434 case AL_CC_CONFIG:
435 bits3 = 0x01;
436 break;
437 case AL_CALCULATOR:
438 bits3 = 0x04;
439 break;
440 case AL_LOCK:
441 bits3 = 0x08;
442 break;
443 case AL_LOCAL_BROWSER:
444 bits3 = 0x10;
445 break;
446 case AC_MINIMIZE:
447 bits3 = 0x20;
448 break;
449 case TRANSPORT_RECORD:
450 bits3 = 0x40;
451 break;
452 case TRANSPORT_REWIND:
453 bits3 = 0x80;
454 break;
455 }
456
457 MUX_HEADER(0x01, 0x07);
458 xmit(0x9f);
459 xmit(0x05); // Length
460 xmit(0xa1); // consumer report
461 xmit(0x03);
462 xmit(bits1);
463 xmit(bits2);
464 xmit(bits3);
465 MUX_FOOTER(0x01);
466#endif
467}
diff --git a/iwrap/iwrap.h b/iwrap/iwrap.h
new file mode 100644
index 000000000..ffaad9395
--- /dev/null
+++ b/iwrap/iwrap.h
@@ -0,0 +1,49 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef IWRAP_H
19#define IWRAP_H
20
21#include <stdint.h>
22#include <stdbool.h>
23#include "host_driver.h"
24
25
26/* enable iWRAP MUX mode */
27#define MUX_MODE
28
29
30host_driver_t *iwrap_driver(void);
31
32void iwrap_init(void);
33void iwrap_send(const char *s);
34void iwrap_mux_send(const char *s);
35void iwrap_buf_send(void);
36void iwrap_buf_add(uint8_t c);
37void iwrap_buf_del(void);
38
39void iwrap_call(void);
40void iwrap_kill(void);
41void iwrap_unpair(void);
42void iwrap_sleep(void);
43void iwrap_sniff(void);
44void iwrap_subrate(void);
45bool iwrap_failed(void);
46uint8_t iwrap_connected(void);
47uint8_t iwrap_check_connection(void);
48
49#endif
diff --git a/iwrap/main.c b/iwrap/main.c
new file mode 100644
index 000000000..a552afb67
--- /dev/null
+++ b/iwrap/main.c
@@ -0,0 +1,378 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include <stdint.h>
18#include <avr/interrupt.h>
19#include <avr/io.h>
20//#include <avr/wdt.h>
21#include "wd.h" // in order to use watchdog in interrupt mode
22#include <avr/sleep.h>
23#include <util/delay.h>
24#include <avr/power.h>
25#include "keyboard.h"
26#include "matrix.h"
27#include "host.h"
28#include "iwrap.h"
29#ifdef HOST_VUSB
30# include "vusb.h"
31# include "usbdrv.h"
32#endif
33#include "uart.h"
34#include "suart.h"
35#include "timer.h"
36#include "debug.h"
37#include "usb_keycodes.h"
38#include "command.h"
39
40
41static void sleep(uint8_t term);
42static bool console(void);
43static uint8_t console_command(uint8_t c);
44static uint8_t key2asc(uint8_t key);
45
46
47/*
48static void set_prr(void)
49{
50 power_adc_disable();
51 power_spi_disable();
52 power_twi_disable();
53#ifndef TIMER_H
54 //power_timer0_disable(); // used in timer.c
55#endif
56 power_timer1_disable();
57 power_timer2_disable();
58}
59*/
60
61/*
62static void pullup_pins(void)
63{
64 // DDRs are set to 0(input) by default.
65#ifdef PORTA
66 PORTA = 0xFF;
67#endif
68 PORTB = 0xFF;
69 PORTC = 0xFF;
70 PORTD = 0xFF;
71#ifdef PORTE
72 PORTE = 0xFF;
73#endif
74#ifdef PORTE
75 PORTF = 0xFF;
76#endif
77}
78*/
79
80
81#ifdef HOST_VUSB
82static void disable_vusb(void)
83{
84 // disable interrupt & disconnect to prevent host from enumerating
85 USB_INTR_ENABLE &= ~(1 << USB_INTR_ENABLE_BIT);
86 usbDeviceDisconnect();
87}
88
89static void enable_vusb(void)
90{
91 USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
92 usbDeviceConnect();
93}
94
95static void init_vusb(void)
96{
97 uint8_t i = 0;
98
99 usbInit();
100 disable_vusb();
101 /* fake USB disconnect for > 250 ms */
102 while(--i){
103 _delay_ms(1);
104 }
105 enable_vusb();
106}
107#endif
108
109void change_driver(host_driver_t *driver)
110{
111 host_clear_keyboard_report();
112 host_swap_keyboard_report();
113 host_clear_keyboard_report();
114 host_send_keyboard_report();
115 _delay_ms(1000);
116 host_set_driver(driver);
117}
118
119
120static bool sleeping = false;
121static bool insomniac = false; // TODO: should be false for power saving
122static uint16_t last_timer = 0;
123
124int main(void)
125{
126 MCUSR = 0;
127 clock_prescale_set(clock_div_1);
128 WD_SET(WD_OFF);
129
130 // power saving: the result is worse than nothing... why?
131 //pullup_pins();
132 //set_prr();
133
134 print_enable = true;
135 debug_enable = false;
136
137#ifdef HOST_VUSB
138 disable_vusb();
139#endif
140 uart_init(115200);
141 keyboard_init();
142 print("\nSend BREAK for UART Console Commands.\n");
143
144 // TODO: move to iWRAP/suart file
145 print("suart init\n");
146 // suart init
147 // PC4: Tx Output IDLE(Hi)
148 PORTC |= (1<<4);
149 DDRC |= (1<<4);
150 // PC5: Rx Input(pull-up)
151 PORTC |= (1<<5);
152 DDRC &= ~(1<<5);
153 // suart receive interrut(PC5/PCINT13)
154 PCMSK1 = 0b00100000;
155 PCICR = 0b00000010;
156
157 host_set_driver(iwrap_driver());
158
159 print("iwrap_init()\n");
160 iwrap_init();
161 iwrap_call();
162
163 last_timer = timer_read();
164 while (true) {
165#ifdef HOST_VUSB
166 if (host_get_driver() == vusb_driver())
167 usbPoll();
168#endif
169 keyboard_proc();
170#ifdef HOST_VUSB
171 if (host_get_driver() == vusb_driver())
172 vusb_transfer_keyboard();
173#endif
174 if (matrix_is_modified() || console()) {
175 last_timer = timer_read();
176 sleeping = false;
177 } else if (!sleeping && timer_elapsed(last_timer) > 4000) {
178 sleeping = true;
179 iwrap_check_connection();
180 }
181
182 if (host_get_driver() == iwrap_driver()) {
183 if (sleeping && !insomniac) {
184 _delay_ms(1); // wait for UART to send
185 iwrap_sleep();
186 sleep(WDTO_60MS);
187 }
188 }
189 }
190}
191
192static void sleep(uint8_t term)
193{
194 WD_SET(WD_IRQ, term);
195
196 cli();
197 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
198 sleep_enable();
199 sleep_bod_disable();
200 sei();
201 sleep_cpu();
202 sleep_disable();
203
204 WD_SET(WD_OFF);
205}
206
207ISR(WDT_vect)
208{
209 // wake up
210}
211
212static bool console(void)
213{
214 // Send to Bluetoot module WT12
215 static bool breaked = false;
216 if (!uart_available())
217 return false;
218 else {
219 uint8_t c;
220 c = uart_getchar();
221 uart_putchar(c);
222 switch (c) {
223 case 0x00: // BREAK signal
224 if (!breaked) {
225 print("break(? for help): ");
226 breaked = true;
227 }
228 break;
229 case '\r':
230 uart_putchar('\n');
231 iwrap_buf_send();
232 break;
233 case '\b':
234 iwrap_buf_del();
235 break;
236 default:
237 if (breaked) {
238 print("\n");
239 console_command(c);
240 breaked = false;
241 } else {
242 iwrap_buf_add(c);
243 }
244 break;
245 }
246 return true;
247 }
248}
249
250uint8_t command_extra()
251{
252 return console_command(key2asc(host_get_first_key()));
253}
254
255static uint8_t console_command(uint8_t c)
256{
257 switch (c) {
258 case 'h':
259 case '?':
260 print("\nCommands for Bluetooth(WT12/iWRAP):\n");
261 print("r: reset. software reset by watchdog\n");
262 print("i: insomniac. prevent KB from sleeping\n");
263 print("c: iwrap_call. CALL for BT connection.\n");
264#ifdef HOST_VUSB
265 print("u: USB mode. switch to USB.\n");
266 print("w: BT mode. switch to Bluetooth.\n");
267#endif
268 print("k: kill first connection.\n");
269 print("Del: unpair first pairing.\n");
270 print("\n");
271 return 0;
272 case 'r':
273 print("reset\n");
274 WD_AVR_RESET();
275 return 1;
276 case 'i':
277 insomniac = !insomniac;
278 if (insomniac)
279 print("insomniac\n");
280 else
281 print("not insomniac\n");
282 return 1;
283 case 'c':
284 print("iwrap_call()\n");
285 iwrap_call();
286 return 1;
287#ifdef HOST_VUSB
288 case 'u':
289 print("USB mode\n");
290 init_vusb();
291 change_driver(vusb_driver());
292 //iwrap_kill();
293 //iwrap_sleep();
294 // disable suart receive interrut(PC5/PCINT13)
295 PCMSK1 &= ~(0b00100000);
296 PCICR &= ~(0b00000010);
297 return 1;
298 case 'w':
299 print("iWRAP mode\n");
300 change_driver(iwrap_driver());
301 disable_vusb();
302 // enable suart receive interrut(PC5/PCINT13)
303 PCMSK1 |= 0b00100000;
304 PCICR |= 0b00000010;
305 return 1;
306#endif
307 case 'k':
308 print("kill\n");
309 iwrap_kill();
310 return 1;
311 case 0x7F: // DELETE
312 print("unpair\n");
313 iwrap_unpair();
314 return 1;
315 }
316 return 0;
317}
318
319// convert keycode into ascii charactor
320static uint8_t key2asc(uint8_t key)
321{
322 switch (key) {
323 case KB_A: return 'a';
324 case KB_B: return 'b';
325 case KB_C: return 'c';
326 case KB_D: return 'd';
327 case KB_E: return 'e';
328 case KB_F: return 'f';
329 case KB_G: return 'g';
330 case KB_H: return 'h';
331 case KB_I: return 'i';
332 case KB_J: return 'j';
333 case KB_K: return 'k';
334 case KB_L: return 'l';
335 case KB_M: return 'm';
336 case KB_N: return 'n';
337 case KB_O: return 'o';
338 case KB_P: return 'p';
339 case KB_Q: return 'q';
340 case KB_R: return 'r';
341 case KB_S: return 's';
342 case KB_T: return 't';
343 case KB_U: return 'u';
344 case KB_V: return 'v';
345 case KB_W: return 'w';
346 case KB_X: return 'x';
347 case KB_Y: return 'y';
348 case KB_Z: return 'z';
349 case KB_1: return '1';
350 case KB_2: return '2';
351 case KB_3: return '3';
352 case KB_4: return '4';
353 case KB_5: return '5';
354 case KB_6: return '6';
355 case KB_7: return '7';
356 case KB_8: return '8';
357 case KB_9: return '9';
358 case KB_0: return '0';
359 case KB_ENTER: return '\n';
360 case KB_ESCAPE: return 0x1B;
361 case KB_BSPACE: return '\b';
362 case KB_TAB: return '\t';
363 case KB_SPACE: return ' ';
364 case KB_MINUS: return '-';
365 case KB_EQUAL: return '=';
366 case KB_LBRACKET: return '[';
367 case KB_RBRACKET: return ']';
368 case KB_BSLASH: return '\\';
369 case KB_NONUS_HASH: return '\\';
370 case KB_SCOLON: return ';';
371 case KB_QUOTE: return '\'';
372 case KB_GRAVE: return '`';
373 case KB_COMMA: return ',';
374 case KB_DOT: return '.';
375 case KB_SLASH: return '/';
376 default: return 0x00;
377 }
378}
diff --git a/iwrap/suart.S b/iwrap/suart.S
new file mode 100644
index 000000000..1b0290963
--- /dev/null
+++ b/iwrap/suart.S
@@ -0,0 +1,156 @@
1;---------------------------------------------------------------------------;
2; Software implemented UART module ;
3; (C)ChaN, 2005 (http://elm-chan.org/) ;
4;---------------------------------------------------------------------------;
5; Bit rate settings:
6;
7; 1MHz 2MHz 4MHz 6MHz 8MHz 10MHz 12MHz 16MHz 20MHz
8; 2.4kbps 138 - - - - - - - -
9; 4.8kbps 68 138 - - - - - - -
10; 9.6kbps 33 68 138 208 - - - - -
11; 19.2kbps - 33 68 102 138 173 208 - -
12; 38.4kbps - - 33 50 68 85 102 138 172
13; 57.6kbps - - 21 33 44 56 68 91 114
14; 115.2kbps - - - - 21 27 33 44 56
15
16.nolist
17#include <avr/io.h>
18.list
19
20#define BPS 102 /* Bit delay. (see above table) */
21#define BIDIR 0 /* 0:Separated Tx/Rx, 1:Shared Tx/Rx */
22
23#define OUT_1 sbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 1 */
24#define OUT_0 cbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 0 */
25#define SKIP_IN_1 sbis _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 1 */
26#define SKIP_IN_0 sbic _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 0 */
27
28
29
30#ifdef SPM_PAGESIZE
31.macro _LPMI reg
32 lpm \reg, Z+
33.endm
34.macro _MOVW dh,dl, sh,sl
35 movw \dl, \sl
36.endm
37#else
38.macro _LPMI reg
39 lpm
40 mov \reg, r0
41 adiw ZL, 1
42.endm
43.macro _MOVW dh,dl, sh,sl
44 mov \dl, \sl
45 mov \dh, \sh
46.endm
47#endif
48
49
50
51;---------------------------------------------------------------------------;
52; Transmit a byte in serial format of N81
53;
54;Prototype: void xmit (uint8_t data);
55;Size: 16 words
56
57.global xmit
58.func xmit
59xmit:
60#if BIDIR
61 ldi r23, BPS-1 ;Pre-idle time for bidirectional data line
625: dec r23 ;
63 brne 5b ;/
64#endif
65 in r0, _SFR_IO_ADDR(SREG) ;Save flags
66
67 com r24 ;C = start bit
68 ldi r25, 10 ;Bit counter
69 cli ;Start critical section
70
711: ldi r23, BPS-1 ;----- Bit transferring loop
722: dec r23 ;Wait for a bit time
73 brne 2b ;/
74 brcs 3f ;MISO = bit to be sent
75 OUT_1 ;
763: brcc 4f ;
77 OUT_0 ;/
784: lsr r24 ;Get next bit into C
79 dec r25 ;All bits sent?
80 brne 1b ; no, coutinue
81
82 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
83 ret
84.endfunc
85
86
87
88;---------------------------------------------------------------------------;
89; Receive a byte
90;
91;Prototype: uint8_t rcvr (void);
92;Size: 19 words
93
94.global rcvr
95.func rcvr
96rcvr:
97 in r0, _SFR_IO_ADDR(SREG) ;Save flags
98
99 ldi r24, 0x80 ;Receiving shift reg
100 cli ;Start critical section
101
1021: SKIP_IN_1 ;Wait for idle
103 rjmp 1b
1042: SKIP_IN_0 ;Wait for start bit
105 rjmp 2b
106 ldi r25, BPS/2 ;Wait for half bit time
1073: dec r25
108 brne 3b
109
1104: ldi r25, BPS ;----- Bit receiving loop
1115: dec r25 ;Wait for a bit time
112 brne 5b ;/
113 lsr r24 ;Next bit
114 SKIP_IN_0 ;Get a data bit into r24.7
115 ori r24, 0x80
116 brcc 4b ;All bits received? no, continue
117
118 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
119 ret
120.endfunc
121
122
123; Not wait for start bit. This should be called after detecting start bit.
124.global recv
125.func recv
126recv:
127 in r0, _SFR_IO_ADDR(SREG) ;Save flags
128
129 ldi r24, 0x80 ;Receiving shift reg
130 cli ;Start critical section
131
132;1: SKIP_IN_1 ;Wait for idle
133; rjmp 1b
134;2: SKIP_IN_0 ;Wait for start bit
135; rjmp 2b
136 ldi r25, BPS/2 ;Wait for half bit time
1373: dec r25
138 brne 3b
139
1404: ldi r25, BPS ;----- Bit receiving loop
1415: dec r25 ;Wait for a bit time
142 brne 5b ;/
143 lsr r24 ;Next bit
144 SKIP_IN_0 ;Get a data bit into r24.7
145 ori r24, 0x80
146 brcc 4b ;All bits received? no, continue
147
148 ldi r25, BPS/2 ;Wait for half bit time
1496: dec r25
150 brne 6b
1517: SKIP_IN_1 ;Wait for stop bit
152 rjmp 7b
153
154 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
155 ret
156.endfunc
diff --git a/iwrap/suart.h b/iwrap/suart.h
new file mode 100644
index 000000000..72725b998
--- /dev/null
+++ b/iwrap/suart.h
@@ -0,0 +1,8 @@
1#ifndef SUART
2#define SUART
3
4void xmit(uint8_t);
5uint8_t rcvr(void);
6uint8_t recv(void);
7
8#endif /* SUART */
diff --git a/iwrap/wd.h b/iwrap/wd.h
new file mode 100644
index 000000000..99058f033
--- /dev/null
+++ b/iwrap/wd.h
@@ -0,0 +1,159 @@
1/* This is from http://www.mtcnet.net/~henryvm/wdt/ */
2#ifndef _AVR_WD_H_
3#define _AVR_WD_H_
4
5#include <avr/io.h>
6
7/*
8Copyright (c) 2009, Curt Van Maanen
9
10Permission to use, copy, modify, and/or distribute this software for any
11purpose with or without fee is hereby granted, provided that the above
12copyright notice and this permission notice appear in all copies.
13
14THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
22
23include usage-
24 #include "wd.h" //if in same directory as project
25 #include <avr/wd.h> //if wd.h is in avr directory
26
27set watchdog modes and prescale
28
29usage-
30 WD_SET(mode,[timeout]); //prescale always set
31
32modes-
33 WD_OFF disabled
34 WD_RST normal reset mode
35 WD_IRQ interrupt only mode (if supported)
36 WD_RST_IRQ interrupt+reset mode (if supported)
37
38timeout-
39 WDTO_15MS default if no timeout provided
40 WDTO_30MS
41 WDTO_60MS
42 WDTO_120MS
43 WDTO_250MS
44 WDTO_500MS
45 WDTO_1S
46 WDTO_2S
47 WDTO_4S (if supported)
48 WDTO_8S (if supported)
49
50examples-
51 WD_SET(WD_RST,WDTO_1S); //reset mode, 1s timeout
52 WD_SET(WD_OFF); //watchdog disabled (if not fused on)
53 WD_SET(WD_RST); //reset mode, 15ms (default timeout)
54 WD_SET(WD_IRQ,WDTO_120MS); //interrupt only mode, 120ms timeout
55 WD_SET(WD_RST_IRQ,WDTO_2S); //interrupt+reset mode, 2S timeout
56
57
58for enhanced watchdogs, if the watchdog is not being used WDRF should be
59cleared on every power up or reset, along with disabling the watchdog-
60 WD_DISABLE(); //clear WDRF, then turn off watchdog
61
62*/
63
64//reset registers to the same name (MCUCSR)
65#if !defined(MCUCSR)
66#define MCUCSR MCUSR
67#endif
68
69//watchdog registers to the same name (WDTCSR)
70#if !defined(WDTCSR)
71#define WDTCSR WDTCR
72#endif
73
74//if enhanced watchdog, define irq values, create disable macro
75#if defined(WDIF)
76#define WD_IRQ 0xC0
77#define WD_RST_IRQ 0xC8
78#define WD_DISABLE() do{ \
79 MCUCSR &= ~(1<<WDRF); \
80 WD_SET(WD_OFF); \
81 }while(0)
82#endif
83
84//all watchdogs
85#define WD_RST 8
86#define WD_OFF 0
87
88//prescale values
89#define WDTO_15MS 0
90#define WDTO_30MS 1
91#define WDTO_60MS 2
92#define WDTO_120MS 3
93#define WDTO_250MS 4
94#define WDTO_500MS 5
95#define WDTO_1S 6
96#define WDTO_2S 7
97
98//prescale values for avrs with WDP3
99#if defined(WDP3)
100#define WDTO_4S 0x20
101#define WDTO_8S 0x21
102#endif
103
104//watchdog reset
105#define WDR() __asm__ __volatile__("wdr")
106
107//avr reset using watchdog
108#define WD_AVR_RESET() do{ \
109 __asm__ __volatile__("cli"); \
110 WD_SET_UNSAFE(WD_RST); \
111 while(1); \
112 }while(0)
113
114/*set the watchdog-
1151. save SREG
1162. turn off irq's
1173. reset watchdog timer
1184. enable watchdog change
1195. write watchdog value
1206. restore SREG (restoring irq status)
121*/
122#define WD_SET(val,...) \
123 __asm__ __volatile__( \
124 "in __tmp_reg__,__SREG__" "\n\t" \
125 "cli" "\n\t" \
126 "wdr" "\n\t" \
127 "sts %[wdreg],%[wden]" "\n\t" \
128 "sts %[wdreg],%[wdval]" "\n\t" \
129 "out __SREG__,__tmp_reg__" "\n\t" \
130 : \
131 : [wdreg] "M" (&WDTCSR), \
132 [wden] "r" ((uint8_t)(0x18)), \
133 [wdval] "r" ((uint8_t)(val|(__VA_ARGS__+0))) \
134 : "r0" \
135)
136
137/*set the watchdog when I bit in SREG known to be clear-
1381. reset watchdog timer
1392. enable watchdog change
1405. write watchdog value
141*/
142#define WD_SET_UNSAFE(val,...) \
143 __asm__ __volatile__( \
144 "wdr" "\n\t" \
145 "sts %[wdreg],%[wden]" "\n\t" \
146 "sts %[wdreg],%[wdval]" "\n\t" \
147 : \
148 : [wdreg] "M" (&WDTCSR), \
149 [wden] "r" ((uint8_t)(0x18)), \
150 [wdval] "r" ((uint8_t)(val|(__VA_ARGS__+0))) \
151)
152
153
154//for compatibility with avr/wdt.h
155#define wdt_enable(val) WD_SET(WD_RST,val)
156#define wdt_disable() WD_SET(WD_OFF)
157
158
159#endif /* _AVR_WD_H_ */
diff --git a/keyboard.c b/keyboard.c
index 9bba409f1..5c2643c95 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#ifdef MOUSEKEY_ENABLE 27#ifdef MOUSEKEY_ENABLE
28#include "mousekey.h" 28#include "mousekey.h"
29#endif 29#endif
30#ifdef USB_EXTRA_ENABLE 30#ifdef EXTRAKEY_ENABLE
31#include <util/delay.h> 31#include <util/delay.h>
32#endif 32#endif
33 33
@@ -47,7 +47,7 @@ void keyboard_init(void)
47void keyboard_proc(void) 47void keyboard_proc(void)
48{ 48{
49 uint8_t fn_bits = 0; 49 uint8_t fn_bits = 0;
50#ifdef USB_EXTRA_ENABLE 50#ifdef EXTRAKEY_ENABLE
51 uint16_t consumer_code = 0; 51 uint16_t consumer_code = 0;
52#endif 52#endif
53 53
@@ -82,7 +82,8 @@ void keyboard_proc(void)
82 } else if (IS_FN(code)) { 82 } else if (IS_FN(code)) {
83 fn_bits |= FN_BIT(code); 83 fn_bits |= FN_BIT(code);
84 } 84 }
85#ifdef USB_EXTRA_ENABLE 85// TODO: use table or something
86#ifdef EXTRAKEY_ENABLE
86 // System Control 87 // System Control
87 else if (code == KB_SYSTEM_POWER) { 88 else if (code == KB_SYSTEM_POWER) {
88#ifdef HOST_PJRC 89#ifdef HOST_PJRC
@@ -170,7 +171,7 @@ void keyboard_proc(void)
170 // TODO: should send only when changed from last report 171 // TODO: should send only when changed from last report
171 if (matrix_is_modified()) { 172 if (matrix_is_modified()) {
172 host_send_keyboard_report(); 173 host_send_keyboard_report();
173#ifdef USB_EXTRA_ENABLE 174#ifdef EXTRAKEY_ENABLE
174 host_consumer_send(consumer_code); 175 host_consumer_send(consumer_code);
175#endif 176#endif
176#ifdef DEBUG_LED 177#ifdef DEBUG_LED
diff --git a/layer.c b/layer.c
index 8c1648572..3f9e55a15 100755
--- a/layer.c
+++ b/layer.c
@@ -69,10 +69,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
69 */ 69 */
70 70
71// LAYER_ENTER_DELAY: prevent from moving new layer 71// LAYER_ENTER_DELAY: prevent from moving new layer
72#define LAYER_ENTER_DELAY 10 72#define LAYER_ENTER_DELAY 150
73 73
74// LAYER_SEND_FN_TERM: send keycode if release key in this term 74// LAYER_SEND_FN_TERM: send keycode if release key in this term
75#define LAYER_SEND_FN_TERM 40 75#define LAYER_SEND_FN_TERM 500
76 76
77 77
78uint8_t default_layer = 0; 78uint8_t default_layer = 0;
diff --git a/macway/Makefile b/macway/Makefile
index 6e7fa7fd9..b8b0a85e1 100644
--- a/macway/Makefile
+++ b/macway/Makefile
@@ -8,10 +8,10 @@ COMMON_DIR = ..
8TARGET_DIR = . 8TARGET_DIR = .
9 9
10# keyboard dependent files 10# keyboard dependent files
11TARGET_SRC = main_pjrc.c \ 11SRC = main.c \
12 keymap.c \ 12 keymap.c \
13 matrix.c \ 13 matrix.c \
14 led.c 14 led.c
15 15
16CONFIG_H = config.h 16CONFIG_H = config.h
17 17
@@ -37,8 +37,8 @@ F_CPU = 16000000
37# 37#
38MOUSEKEY_ENABLE = yes # Mouse keys 38MOUSEKEY_ENABLE = yes # Mouse keys
39#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support 39#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
40USB_EXTRA_ENABLE = yes # Audio control and System control 40EXTRAKEY_ENABLE = yes # Audio control and System control
41#USB_NKRO_ENABLE = yes # USB Nkey Rollover 41#NKRO_ENABLE = yes # USB Nkey Rollover
42 42
43 43
44 44
@@ -47,5 +47,5 @@ PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
47 47
48 48
49 49
50include $(COMMON_DIR)/Makefile.pjrc 50include $(COMMON_DIR)/pjrc.mk
51include $(COMMON_DIR)/Makefile.common 51include $(COMMON_DIR)/common.mk
diff --git a/macway/config.h b/macway/config.h
index ff62bfdb0..546067beb 100644
--- a/macway/config.h
+++ b/macway/config.h
@@ -37,8 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
37 37
38/* key combination for command */ 38/* key combination for command */
39#define IS_COMMAND() ( \ 39#define IS_COMMAND() ( \
40 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ 40 keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_LCTRL) | MOD_BIT(KB_LALT) | MOD_BIT(KB_LGUI)) || \
41 keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ 41 keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)) \
42) 42)
43 43
44 44
diff --git a/macway/doc/back.jpg b/macway/doc/back.jpg
index 0774401f6..0774401f6 100755..100644
--- a/macway/doc/back.jpg
+++ b/macway/doc/back.jpg
Binary files differ
diff --git a/macway/doc/case.jpg b/macway/doc/case.jpg
index c776d5e05..c776d5e05 100755..100644
--- a/macway/doc/case.jpg
+++ b/macway/doc/case.jpg
Binary files differ
diff --git a/macway/doc/keys.jpg b/macway/doc/keys.jpg
index f340ebe8e..f340ebe8e 100755..100644
--- a/macway/doc/keys.jpg
+++ b/macway/doc/keys.jpg
Binary files differ
diff --git a/macway/doc/side.jpg b/macway/doc/side.jpg
index bdf8268f2..bdf8268f2 100755..100644
--- a/macway/doc/side.jpg
+++ b/macway/doc/side.jpg
Binary files differ
diff --git a/macway/doc/switch.jpg b/macway/doc/switch.jpg
index a1500d707..a1500d707 100755..100644
--- a/macway/doc/switch.jpg
+++ b/macway/doc/switch.jpg
Binary files differ
diff --git a/macway/doc/teensy.jpg b/macway/doc/teensy.jpg
index 07207475d..07207475d 100755..100644
--- a/macway/doc/teensy.jpg
+++ b/macway/doc/teensy.jpg
Binary files differ
diff --git a/macway/doc/wiring.jpg b/macway/doc/wiring.jpg
index 0f3490f10..0f3490f10 100755..100644
--- a/macway/doc/wiring.jpg
+++ b/macway/doc/wiring.jpg
Binary files differ
diff --git a/macway/doc/withHHKB.jpg b/macway/doc/withHHKB.jpg
index 9921856e7..9921856e7 100755..100644
--- a/macway/doc/withHHKB.jpg
+++ b/macway/doc/withHHKB.jpg
Binary files differ
diff --git a/macway/doc/withThinkPad.jpg b/macway/doc/withThinkPad.jpg
index 231c61d03..231c61d03 100755..100644
--- a/macway/doc/withThinkPad.jpg
+++ b/macway/doc/withThinkPad.jpg
Binary files differ
diff --git a/main_vusb.c b/main_vusb.c
deleted file mode 100644
index 017888e97..000000000
--- a/main_vusb.c
+++ /dev/null
@@ -1,58 +0,0 @@
1/* Name: main.c
2 * Project: hid-mouse, a very simple HID example
3 * Author: Christian Starkjohann
4 * Creation Date: 2008-04-07
5 * Tabsize: 4
6 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
9 */
10#include <stdint.h>
11#include <avr/wdt.h>
12#include <avr/interrupt.h>
13#include <util/delay.h>
14#include "usbdrv.h"
15#include "oddebug.h"
16#include "host_vusb.h"
17#include "keyboard.h"
18
19
20#if 0
21#define DEBUGP_INIT() do { DDRC = 0xFF; } while (0)
22#define DEBUGP(x) do { PORTC = x; } while (0)
23#else
24#define DEBUGP_INIT()
25#define DEBUGP(x)
26#endif
27
28
29int main(void)
30{
31 DEBUGP_INIT();
32 wdt_enable(WDTO_1S);
33 odDebugInit();
34 usbInit();
35
36 /* enforce re-enumeration, do this while interrupts are disabled! */
37 usbDeviceDisconnect();
38 uint8_t i = 0;
39 /* fake USB disconnect for > 250 ms */
40 while(--i){
41 wdt_reset();
42 _delay_ms(1);
43 }
44 usbDeviceConnect();
45
46 keyboard_init();
47
48 sei();
49 while (1) {
50 DEBUGP(0x1);
51 wdt_reset();
52 usbPoll();
53 DEBUGP(0x2);
54 keyboard_proc();
55 DEBUGP(0x3);
56 host_vusb_keyboard_send();
57 }
58}
diff --git a/mousekey.c b/mousekey.c
index 69b75240f..76bd0fd36 100644..100755
--- a/mousekey.c
+++ b/mousekey.c
@@ -63,10 +63,10 @@ void mousekey_decode(uint8_t code)
63 else if (code == KB_MS_BTN3) report.buttons |= MOUSE_BTN3; 63 else if (code == KB_MS_BTN3) report.buttons |= MOUSE_BTN3;
64 else if (code == KB_MS_BTN4) report.buttons |= MOUSE_BTN4; 64 else if (code == KB_MS_BTN4) report.buttons |= MOUSE_BTN4;
65 else if (code == KB_MS_BTN5) report.buttons |= MOUSE_BTN5; 65 else if (code == KB_MS_BTN5) report.buttons |= MOUSE_BTN5;
66 else if (code == KB_MS_WH_UP) report.v += 1; 66 else if (code == KB_MS_WH_UP) report.v += move_unit()/4;
67 else if (code == KB_MS_WH_DOWN) report.v -= 1; 67 else if (code == KB_MS_WH_DOWN) report.v -= move_unit()/4;
68 else if (code == KB_MS_WH_LEFT) report.h -= 1; 68 else if (code == KB_MS_WH_LEFT) report.h -= move_unit()/4;
69 else if (code == KB_MS_WH_RIGHT)report.h += 1; 69 else if (code == KB_MS_WH_RIGHT)report.h += move_unit()/4;
70} 70}
71 71
72bool mousekey_changed(void) 72bool mousekey_changed(void)
@@ -87,7 +87,7 @@ void mousekey_send(void)
87 87
88 // send immediately when buttun state is changed 88 // send immediately when buttun state is changed
89 if (report.buttons == report_prev.buttons) { 89 if (report.buttons == report_prev.buttons) {
90 if (timer_elapsed(last_timer) < 5) { 90 if (timer_elapsed(last_timer) < 100) {
91 mousekey_clear_report(); 91 mousekey_clear_report();
92 return; 92 return;
93 } 93 }
diff --git a/Makefile.pjrc b/pjrc.mk
index 894d4dcee..0bc47ac93 100644
--- a/Makefile.pjrc
+++ b/pjrc.mk
@@ -1,14 +1,14 @@
1OPT_DEFS += -DHOST_PJRC 1OPT_DEFS += -DHOST_PJRC
2 2
3SRC = usb_keyboard.c \ 3SRC += pjrc.c \
4 usb_keyboard.c \
4 usb_debug.c \ 5 usb_debug.c \
5 usb.c \ 6 usb.c \
6 jump_bootloader.c 7 jump_bootloader.c
7SRC += $(TARGET_SRC)
8 8
9 9
10# C source file search path 10# Search Path
11VPATH = $(TARGET_DIR):$(COMMON_DIR):$(COMMON_DIR)/pjrc 11VPATH += $(COMMON_DIR):$(COMMON_DIR)/pjrc
12 12
13 13
14# Option modules 14# Option modules
@@ -16,6 +16,6 @@ ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
16 SRC += usb_mouse.c 16 SRC += usb_mouse.c
17endif 17endif
18 18
19ifdef USB_EXTRA_ENABLE 19ifdef EXTRAKEY_ENABLE
20 SRC += usb_extra.c 20 SRC += usb_extra.c
21endif 21endif
diff --git a/pjrc/host.c b/pjrc/host.c
index 35d59de80..fcf71d579 100644
--- a/pjrc/host.c
+++ b/pjrc/host.c
@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) 22#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
23#include "usb_mouse.h" 23#include "usb_mouse.h"
24#endif 24#endif
25#ifdef USB_EXTRA_ENABLE 25#ifdef EXTRAKEY_ENABLE
26#include "usb_extra.h" 26#include "usb_extra.h"
27#endif 27#endif
28#include "debug.h" 28#include "debug.h"
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30#include "util.h" 30#include "util.h"
31 31
32 32
33#ifdef USB_NKRO_ENABLE 33#ifdef NKRO_ENABLE
34bool keyboard_nkro = false; 34bool keyboard_nkro = false;
35#endif 35#endif
36 36
@@ -51,7 +51,7 @@ uint8_t host_keyboard_leds(void)
51/* keyboard report operations */ 51/* keyboard report operations */
52void host_add_key(uint8_t key) 52void host_add_key(uint8_t key)
53{ 53{
54#ifdef USB_NKRO_ENABLE 54#ifdef NKRO_ENABLE
55 if (keyboard_nkro) { 55 if (keyboard_nkro) {
56 add_key_bit(key); 56 add_key_bit(key);
57 return; 57 return;
@@ -109,7 +109,7 @@ uint8_t host_has_anykey(void)
109 109
110uint8_t host_get_first_key(void) 110uint8_t host_get_first_key(void)
111{ 111{
112#ifdef USB_NKRO_ENABLE 112#ifdef NKRO_ENABLE
113 if (keyboard_nkro) { 113 if (keyboard_nkro) {
114 uint8_t i = 0; 114 uint8_t i = 0;
115 for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++) 115 for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++)
@@ -133,7 +133,7 @@ void host_mouse_send(report_mouse_t *report)
133} 133}
134#endif 134#endif
135 135
136#ifdef USB_EXTRA_ENABLE 136#ifdef EXTRAKEY_ENABLE
137void host_system_send(uint16_t data) 137void host_system_send(uint16_t data)
138{ 138{
139 usb_extra_system_send(data); 139 usb_extra_system_send(data);
diff --git a/main_pjrc.c b/pjrc/main.c
index 6ba62040d..f84925d7f 100644
--- a/main_pjrc.c
+++ b/pjrc/main.c
@@ -35,6 +35,8 @@
35#ifdef PS2_MOUSE_ENABLE 35#ifdef PS2_MOUSE_ENABLE
36# include "ps2_mouse.h" 36# include "ps2_mouse.h"
37#endif 37#endif
38#include "host.h"
39#include "pjrc.h"
38 40
39 41
40#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) 42#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
@@ -88,6 +90,7 @@ int main(void)
88 } 90 }
89 91
90 92
93 host_set_driver(pjrc_driver());
91 while (1) { 94 while (1) {
92 keyboard_proc(); 95 keyboard_proc();
93 } 96 }
diff --git a/pjrc/pjrc.c b/pjrc/pjrc.c
new file mode 100644
index 000000000..0562a12ff
--- /dev/null
+++ b/pjrc/pjrc.c
@@ -0,0 +1,76 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include "usb_keyboard.h"
20#include "usb_mouse.h"
21#include "usb_extra.h"
22#include "host_driver.h"
23#include "pjrc.h"
24
25
26/*------------------------------------------------------------------*
27 * Host driver
28 *------------------------------------------------------------------*/
29static uint8_t keyboard_leds(void);
30static void send_keyboard(report_keyboard_t *report);
31static void send_mouse(report_mouse_t *report);
32static void send_system(uint16_t data);
33static void send_consumer(uint16_t data);
34
35static host_driver_t driver = {
36 keyboard_leds,
37 send_keyboard,
38 send_mouse,
39 send_system,
40 send_consumer
41};
42
43host_driver_t *pjrc_driver(void)
44{
45 return &driver;
46}
47
48static uint8_t keyboard_leds(void) {
49 return usb_keyboard_leds;
50}
51
52static void send_keyboard(report_keyboard_t *report)
53{
54 usb_keyboard_send_report(report);
55}
56
57static void send_mouse(report_mouse_t *report)
58{
59#ifdef MOUSE_ENABLE
60 usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons);
61#endif
62}
63
64static void send_system(uint16_t data)
65{
66#ifdef EXTRAKEY_ENABLE
67 usb_extra_system_send(data);
68#endif
69}
70
71static void send_consumer(uint16_t data)
72{
73#ifdef EXTRAKEY_ENABLE
74 usb_extra_consumer_send(data);
75#endif
76}
diff --git a/pjrc/pjrc.h b/pjrc/pjrc.h
new file mode 100644
index 000000000..06e79626f
--- /dev/null
+++ b/pjrc/pjrc.h
@@ -0,0 +1,26 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef PJRC_H
19#define PJRC_H
20
21#include "host_driver.h"
22
23
24host_driver_t *pjrc_driver(void);
25
26#endif
diff --git a/pjrc/usb.c b/pjrc/usb.c
index ea2e71b3d..9989a4b2d 100644
--- a/pjrc/usb.c
+++ b/pjrc/usb.c
@@ -91,18 +91,18 @@ bool suspend = false;
91static const uint8_t PROGMEM endpoint_config_table[] = { 91static const uint8_t PROGMEM endpoint_config_table[] = {
92 // enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation) 92 // enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation)
93 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD_SIZE) | KBD_BUFFER, // 1 93 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD_SIZE) | KBD_BUFFER, // 1
94#ifdef USB_MOUSE_ENABLE 94#ifdef MOUSE_ENABLE
95 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2 95 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2
96#else 96#else
97 0, // 2 97 0, // 2
98#endif 98#endif
99 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3 99 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3
100#ifdef USB_EXTRA_ENABLE 100#ifdef EXTRAKEY_ENABLE
101 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 4 101 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 4
102#else 102#else
103 0, // 4 103 0, // 4
104#endif 104#endif
105#ifdef USB_NKRO_ENABLE 105#ifdef NKRO_ENABLE
106 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD2_SIZE) | KBD2_BUFFER, // 5 106 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD2_SIZE) | KBD2_BUFFER, // 5
107#else 107#else
108 0, // 5 108 0, // 5
@@ -176,7 +176,7 @@ static uint8_t PROGMEM keyboard_hid_report_desc[] = {
176 0x81, 0x00, // Input (Data, Array), 176 0x81, 0x00, // Input (Data, Array),
177 0xc0 // End Collection 177 0xc0 // End Collection
178}; 178};
179#ifdef USB_NKRO_ENABLE 179#ifdef NKRO_ENABLE
180static uint8_t PROGMEM keyboard2_hid_report_desc[] = { 180static uint8_t PROGMEM keyboard2_hid_report_desc[] = {
181 0x05, 0x01, // Usage Page (Generic Desktop), 181 0x05, 0x01, // Usage Page (Generic Desktop),
182 0x09, 0x06, // Usage (Keyboard), 182 0x09, 0x06, // Usage (Keyboard),
@@ -213,7 +213,7 @@ static uint8_t PROGMEM keyboard2_hid_report_desc[] = {
213}; 213};
214#endif 214#endif
215 215
216#ifdef USB_MOUSE_ENABLE 216#ifdef MOUSE_ENABLE
217// Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension 217// Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
218// http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521 218// http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521
219// http://www.keil.com/forum/15671/ 219// http://www.keil.com/forum/15671/
@@ -282,7 +282,7 @@ static uint8_t PROGMEM debug_hid_report_desc[] = {
282 0xC0 // end collection 282 0xC0 // end collection
283}; 283};
284 284
285#ifdef USB_EXTRA_ENABLE 285#ifdef EXTRAKEY_ENABLE
286// audio controls & system controls 286// audio controls & system controls
287// http://www.microsoft.com/whdc/archive/w2kbd.mspx 287// http://www.microsoft.com/whdc/archive/w2kbd.mspx
288static uint8_t PROGMEM extra_hid_report_desc[] = { 288static uint8_t PROGMEM extra_hid_report_desc[] = {
@@ -318,7 +318,7 @@ static uint8_t PROGMEM extra_hid_report_desc[] = {
318#define KBD_HID_DESC_NUM 0 318#define KBD_HID_DESC_NUM 0
319#define KBD_HID_DESC_OFFSET (9+(9+9+7)*KBD_HID_DESC_NUM+9) 319#define KBD_HID_DESC_OFFSET (9+(9+9+7)*KBD_HID_DESC_NUM+9)
320 320
321#ifdef USB_MOUSE_ENABLE 321#ifdef MOUSE_ENABLE
322# define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 1) 322# define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 1)
323# define MOUSE_HID_DESC_OFFSET (9+(9+9+7)*MOUSE_HID_DESC_NUM+9) 323# define MOUSE_HID_DESC_OFFSET (9+(9+9+7)*MOUSE_HID_DESC_NUM+9)
324#else 324#else
@@ -328,14 +328,14 @@ static uint8_t PROGMEM extra_hid_report_desc[] = {
328#define DEBUG_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 1) 328#define DEBUG_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 1)
329#define DEBUG_HID_DESC_OFFSET (9+(9+9+7)*DEBUG_HID_DESC_NUM+9) 329#define DEBUG_HID_DESC_OFFSET (9+(9+9+7)*DEBUG_HID_DESC_NUM+9)
330 330
331#ifdef USB_EXTRA_ENABLE 331#ifdef EXTRAKEY_ENABLE
332# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 1) 332# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 1)
333# define EXTRA_HID_DESC_OFFSET (9+(9+9+7)*EXTRA_HID_DESC_NUM+9) 333# define EXTRA_HID_DESC_OFFSET (9+(9+9+7)*EXTRA_HID_DESC_NUM+9)
334#else 334#else
335# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 0) 335# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 0)
336#endif 336#endif
337 337
338#ifdef USB_NKRO_ENABLE 338#ifdef NKRO_ENABLE
339# define KBD2_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 1) 339# define KBD2_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 1)
340# define KBD2_HID_DESC_OFFSET (9+(9+9+7)*EXTRA_HID_DESC_NUM+9) 340# define KBD2_HID_DESC_OFFSET (9+(9+9+7)*EXTRA_HID_DESC_NUM+9)
341#else 341#else
@@ -383,7 +383,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
383 KBD_SIZE, 0, // wMaxPacketSize 383 KBD_SIZE, 0, // wMaxPacketSize
384 10, // bInterval 384 10, // bInterval
385 385
386#ifdef USB_MOUSE_ENABLE 386#ifdef MOUSE_ENABLE
387 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 387 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
388 9, // bLength 388 9, // bLength
389 4, // bDescriptorType 389 4, // bDescriptorType
@@ -444,7 +444,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
444 DEBUG_TX_SIZE, 0, // wMaxPacketSize 444 DEBUG_TX_SIZE, 0, // wMaxPacketSize
445 1, // bInterval 445 1, // bInterval
446 446
447#ifdef USB_EXTRA_ENABLE 447#ifdef EXTRAKEY_ENABLE
448 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 448 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
449 9, // bLength 449 9, // bLength
450 4, // bDescriptorType 450 4, // bDescriptorType
@@ -473,7 +473,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
473 10, // bInterval 473 10, // bInterval
474#endif 474#endif
475 475
476#ifdef USB_NKRO_ENABLE 476#ifdef NKRO_ENABLE
477 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 477 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
478 9, // bLength 478 9, // bLength
479 4, // bDescriptorType 479 4, // bDescriptorType
@@ -542,17 +542,17 @@ static struct descriptor_list_struct {
542 // HID/REPORT descriptors 542 // HID/REPORT descriptors
543 {0x2100, KBD_INTERFACE, config1_descriptor+KBD_HID_DESC_OFFSET, 9}, 543 {0x2100, KBD_INTERFACE, config1_descriptor+KBD_HID_DESC_OFFSET, 9},
544 {0x2200, KBD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)}, 544 {0x2200, KBD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
545#ifdef USB_MOUSE_ENABLE 545#ifdef MOUSE_ENABLE
546 {0x2100, MOUSE_INTERFACE, config1_descriptor+MOUSE_HID_DESC_OFFSET, 9}, 546 {0x2100, MOUSE_INTERFACE, config1_descriptor+MOUSE_HID_DESC_OFFSET, 9},
547 {0x2200, MOUSE_INTERFACE, mouse_hid_report_desc, sizeof(mouse_hid_report_desc)}, 547 {0x2200, MOUSE_INTERFACE, mouse_hid_report_desc, sizeof(mouse_hid_report_desc)},
548#endif 548#endif
549 {0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9}, 549 {0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9},
550 {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)}, 550 {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
551#ifdef USB_EXTRA_ENABLE 551#ifdef EXTRAKEY_ENABLE
552 {0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9}, 552 {0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9},
553 {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)}, 553 {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
554#endif 554#endif
555#ifdef USB_NKRO_ENABLE 555#ifdef NKRO_ENABLE
556 {0x2100, KBD2_INTERFACE, config1_descriptor+KBD2_HID_DESC_OFFSET, 9}, 556 {0x2100, KBD2_INTERFACE, config1_descriptor+KBD2_HID_DESC_OFFSET, 9},
557 {0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)}, 557 {0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)},
558#endif 558#endif
@@ -653,7 +653,7 @@ ISR(USB_GEN_vect)
653 } 653 }
654 } 654 }
655 /* TODO: should keep IDLE rate on each keyboard interface */ 655 /* TODO: should keep IDLE rate on each keyboard interface */
656#ifdef USB_NKRO_ENABLE 656#ifdef NKRO_ENABLE
657 if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) { 657 if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) {
658#else 658#else
659 if (usb_keyboard_idle_config && (++div4 & 3) == 0) { 659 if (usb_keyboard_idle_config && (++div4 & 3) == 0) {
@@ -894,7 +894,7 @@ ISR(USB_COM_vect)
894 } 894 }
895 } 895 }
896 } 896 }
897#ifdef USB_MOUSE_ENABLE 897#ifdef MOUSE_ENABLE
898 if (wIndex == MOUSE_INTERFACE) { 898 if (wIndex == MOUSE_INTERFACE) {
899 if (bmRequestType == 0xA1) { 899 if (bmRequestType == 0xA1) {
900 if (bRequest == HID_GET_REPORT) { 900 if (bRequest == HID_GET_REPORT) {
diff --git a/pjrc/usb.h b/pjrc/usb.h
index a4e40bdd1..82e18f176 100644
--- a/pjrc/usb.h
+++ b/pjrc/usb.h
@@ -120,7 +120,7 @@ void usb_remote_wakeup(void);
120#define KBD_REPORT_KEYS (KBD_SIZE - 2) 120#define KBD_REPORT_KEYS (KBD_SIZE - 2)
121 121
122// secondary keyboard 122// secondary keyboard
123#ifdef USB_NKRO_ENABLE 123#ifdef NKRO_ENABLE
124#define KBD2_INTERFACE 4 124#define KBD2_INTERFACE 4
125#define KBD2_ENDPOINT 5 125#define KBD2_ENDPOINT 5
126#define KBD2_SIZE 16 126#define KBD2_SIZE 16
diff --git a/pjrc/usb_keyboard.c b/pjrc/usb_keyboard.c
index 34e9d495b..e057c77fa 100644
--- a/pjrc/usb_keyboard.c
+++ b/pjrc/usb_keyboard.c
@@ -55,7 +55,7 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report)
55{ 55{
56 int8_t result = 0; 56 int8_t result = 0;
57 57
58#ifdef USB_NKRO_ENABLE 58#ifdef NKRO_ENABLE
59 if (keyboard_nkro) 59 if (keyboard_nkro)
60 result = send_report(report, KBD2_ENDPOINT, 0, KBD2_REPORT_KEYS); 60 result = send_report(report, KBD2_ENDPOINT, 0, KBD2_REPORT_KEYS);
61 else 61 else
@@ -105,7 +105,7 @@ static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, ui
105 UENUM = endpoint; 105 UENUM = endpoint;
106 } 106 }
107 UEDATX = report->mods; 107 UEDATX = report->mods;
108#ifdef USB_NKRO_ENABLE 108#ifdef NKRO_ENABLE
109 if (!keyboard_nkro) 109 if (!keyboard_nkro)
110 UEDATX = 0; 110 UEDATX = 0;
111#else 111#else
diff --git a/print.c b/print.c
index d9152971b..558181ea7 100644
--- a/print.c
+++ b/print.c
@@ -29,6 +29,19 @@
29 29
30bool print_enable = false; 30bool print_enable = false;
31 31
32void print_S(const char *s)
33{
34 if (!print_enable) return;
35 char c;
36
37 while (1) {
38 c = *s++;
39 if (!c) break;
40 if (c == '\n') sendchar('\r');
41 sendchar(c);
42 }
43}
44
32void print_P(const char *s) 45void print_P(const char *s)
33{ 46{
34 if (!print_enable) return; 47 if (!print_enable) return;
diff --git a/print.h b/print.h
index edc540fab..686fa89ac 100644
--- a/print.h
+++ b/print.h
@@ -24,6 +24,7 @@
24#ifndef PRINT_H__ 24#ifndef PRINT_H__
25#define PRINT_H__ 1 25#define PRINT_H__ 1
26 26
27#include <stdint.h>
27#include <stdbool.h> 28#include <stdbool.h>
28#include <avr/pgmspace.h> 29#include <avr/pgmspace.h>
29 30
@@ -34,6 +35,7 @@ extern bool print_enable;
34// the string is automatically placed into flash memory :) 35// the string is automatically placed into flash memory :)
35#define print(s) print_P(PSTR(s)) 36#define print(s) print_P(PSTR(s))
36 37
38void print_S(const char *s);
37void print_P(const char *s); 39void print_P(const char *s);
38void phex(unsigned char c); 40void phex(unsigned char c);
39void phex16(unsigned int i); 41void phex16(unsigned int i);
diff --git a/ps2_usb/Makefile b/ps2_usb/Makefile
index a548b56d4..7352f6b13 100644
--- a/ps2_usb/Makefile
+++ b/ps2_usb/Makefile
@@ -13,11 +13,11 @@ COMMON_DIR = ..
13TARGET_DIR = . 13TARGET_DIR = .
14 14
15# keyboard dependent files 15# keyboard dependent files
16TARGET_SRC = main_pjrc.c \ 16SRC = main.c \
17 keymap.c \ 17 keymap.c \
18 matrix.c \ 18 matrix.c \
19 led.c \ 19 led.c \
20 ps2.c 20 ps2.c
21 21
22CONFIG_H = config_pjrc.h 22CONFIG_H = config_pjrc.h
23 23
@@ -42,8 +42,8 @@ F_CPU = 16000000
42# comment out to disable the options. 42# comment out to disable the options.
43# 43#
44MOUSEKEY_ENABLE = yes # Mouse keys 44MOUSEKEY_ENABLE = yes # Mouse keys
45USB_EXTRA_ENABLE = yes # Audio control and System control 45EXTRAKEY_ENABLE = yes # Audio control and System control
46USB_NKRO_ENABLE = yes # USB Nkey Rollover 46NKRO_ENABLE = yes # USB Nkey Rollover
47 47
48 48
49 49
@@ -52,5 +52,5 @@ PROGRAM_CMD = teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
52 52
53 53
54 54
55include $(COMMON_DIR)/Makefile.pjrc 55include $(COMMON_DIR)/pjrc.mk
56include $(COMMON_DIR)/Makefile.common 56include $(COMMON_DIR)/common.mk
diff --git a/ps2_usb/Makefile.vusb b/ps2_usb/Makefile.vusb
index ff86d7998..5b6978f01 100644
--- a/ps2_usb/Makefile.vusb
+++ b/ps2_usb/Makefile.vusb
@@ -13,11 +13,11 @@ COMMON_DIR = ..
13TARGET_DIR = . 13TARGET_DIR = .
14 14
15# keyboard dependent files 15# keyboard dependent files
16TARGET_SRC = main_vusb.c \ 16SRC = main.c \
17 keymap.c \ 17 keymap.c \
18 matrix.c \ 18 matrix.c \
19 led.c \ 19 led.c \
20 ps2_usart.c 20 ps2_usart.c
21 21
22CONFIG_H = config_vusb.h 22CONFIG_H = config_vusb.h
23 23
@@ -48,8 +48,9 @@ F_CPU = 20000000
48# comment out to disable the options. 48# comment out to disable the options.
49# 49#
50MOUSEKEY_ENABLE = yes # Mouse keys 50MOUSEKEY_ENABLE = yes # Mouse keys
51USB_EXTRA_ENABLE = yes # Audio control and System control 51EXTRAKEY_ENABLE = yes # Audio control and System control
52#USB_NKRO_ENABLE = yes # USB Nkey Rollover 52#NKRO_ENABLE = yes # USB Nkey Rollover
53NO_UART = yes # UART is unavailable
53 54
54 55
55 56
@@ -85,5 +86,5 @@ PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE
85 86
86 87
87 88
88include $(COMMON_DIR)/Makefile.vusb 89include $(COMMON_DIR)/vusb.mk
89include $(COMMON_DIR)/Makefile.common 90include $(COMMON_DIR)/common.mk
diff --git a/ps2_usb/config_pjrc.h b/ps2_usb/config_pjrc.h
index 56917beec..883ffab27 100644
--- a/ps2_usb/config_pjrc.h
+++ b/ps2_usb/config_pjrc.h
@@ -35,8 +35,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
35 35
36/* key combination for command */ 36/* key combination for command */
37#define IS_COMMAND() ( \ 37#define IS_COMMAND() ( \
38 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ 38 keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)) || \
39 keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ 39 keyboard_report->mods == (MOD_BIT(KB_LCTRL) | MOD_BIT(KB_RSHIFT)) \
40) 40)
41 41
42 42
diff --git a/ps2_usb/config_vusb.h b/ps2_usb/config_vusb.h
index 426bb61e2..afd2f7911 100644
--- a/ps2_usb/config_vusb.h
+++ b/ps2_usb/config_vusb.h
@@ -35,8 +35,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
35 35
36/* key combination for command */ 36/* key combination for command */
37#define IS_COMMAND() ( \ 37#define IS_COMMAND() ( \
38 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \ 38 keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT)) || \
39 keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \ 39 keyboard_report->mods == (MOD_BIT(KB_LCTRL) | MOD_BIT(KB_RSHIFT)) \
40) 40)
41 41
42 42
diff --git a/ps2_usb/keymap.c b/ps2_usb/keymap.c
index ef11daa28..e84e8c29b 100644
--- a/ps2_usb/keymap.c
+++ b/ps2_usb/keymap.c
@@ -124,7 +124,7 @@ static const uint8_t PROGMEM fn_layer[] = {
124static const uint8_t PROGMEM fn_keycode[] = { 124static const uint8_t PROGMEM fn_keycode[] = {
125 KB_SCLN, // Fn0 125 KB_SCLN, // Fn0
126 KB_SLSH, // Fn1 126 KB_SLSH, // Fn1
127 KB_A, // Fn2 127 KB_NO, // Fn2
128 KB_NO, // Fn3 128 KB_NO, // Fn3
129 KB_NO, // Fn4 129 KB_NO, // Fn4
130 KB_NO, // Fn5 130 KB_NO, // Fn5
@@ -154,7 +154,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
154 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, 154 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK,
155 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, 155 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
156 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, 156 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9,
157 CAPS,FN2, S, D, F, G, H, J, K, L, FN0, QUOT, ENT, P4, P5, P6, PPLS, 157 CAPS,A, S, D, F, G, H, J, K, L, FN0, QUOT, ENT, P4, P5, P6, PPLS,
158 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, UP, P1, P2, P3, 158 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, UP, P1, P2, P3,
159 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT 159 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
160 ), 160 ),
@@ -204,7 +204,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
204 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, 204 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK,
205 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, 205 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS,
206 TAB, WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, 206 TAB, WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9,
207 CAPS,FN2, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, ENT, P4, P5, P6, PPLS, 207 CAPS,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, ENT, P4, P5, P6, PPLS,
208 LSFT,VOLD,VOLU,MUTE,BTN2,BTN3,BTN2,BTN1,VOLD,VOLU,MUTE, RSFT, UP, P1, P2, P3, 208 LSFT,VOLD,VOLU,MUTE,BTN2,BTN3,BTN2,BTN1,VOLD,VOLU,MUTE, RSFT, UP, P1, P2, P3,
209 LCTL,LGUI,LALT, BTN1, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT 209 LCTL,LGUI,LALT, BTN1, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT
210 ), 210 ),
diff --git a/ps2_usb/matrix.c b/ps2_usb/matrix.c
index 5d73cc2a3..1aac3f866 100644
--- a/ps2_usb/matrix.c
+++ b/ps2_usb/matrix.c
@@ -349,6 +349,7 @@ uint8_t matrix_scan(void)
349 default: 349 default:
350 state = INIT; 350 state = INIT;
351 } 351 }
352 phex(code);
352 } 353 }
353 return 1; 354 return 1;
354} 355}
diff --git a/report.h b/report.h
new file mode 100644
index 000000000..b85b86c5f
--- /dev/null
+++ b/report.h
@@ -0,0 +1,96 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef REPORT_H
19#define REPORT_H
20
21#include <stdint.h>
22
23
24/* report id */
25#define REPORT_ID_MOUSE 1
26#define REPORT_ID_SYSTEM 2
27#define REPORT_ID_CONSUMER 3
28
29/* mouse buttons */
30#define MOUSE_BTN1 (1<<0)
31#define MOUSE_BTN2 (1<<1)
32#define MOUSE_BTN3 (1<<2)
33#define MOUSE_BTN4 (1<<3)
34#define MOUSE_BTN5 (1<<4)
35
36// Consumer Page(0x0C)
37// following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx
38#define AUDIO_MUTE 0x00E2
39#define AUDIO_VOL_UP 0x00E9
40#define AUDIO_VOL_DOWN 0x00EA
41#define TRANSPORT_NEXT_TRACK 0x00B5
42#define TRANSPORT_PREV_TRACK 0x00B6
43#define TRANSPORT_STOP 0x00B7
44#define TRANSPORT_PLAY_PAUSE 0x00CD
45#define AL_CC_CONFIG 0x0183
46#define AL_EMAIL 0x018A
47#define AL_CALCULATOR 0x0192
48#define AL_LOCAL_BROWSER 0x0194
49#define AC_SEARCH 0x0221
50#define AC_HOME 0x0223
51#define AC_BACK 0x0224
52#define AC_FORWARD 0x0225
53#define AC_STOP 0x0226
54#define AC_REFRESH 0x0227
55#define AC_BOOKMARKS 0x022A
56// supplement for Bluegiga iWRAP HID(not supported by Windows?)
57#define AL_LOCK 0x019E
58#define TRANSPORT_RECORD 0x00B2
59#define TRANSPORT_REWIND 0x00B4
60#define TRANSPORT_EJECT 0x00B8
61#define AC_MINIMIZE 0x0206
62
63// Generic Desktop Page(0x01)
64#define SYSTEM_POWER_DOWN 0x0081
65#define SYSTEM_SLEEP 0x0082
66#define SYSTEM_WAKE_UP 0x0083
67
68
69// key report size(NKRO or boot mode)
70#if defined(HOST_PJRC)
71# include "usb.h"
72# if defined(KBD2_REPORT_KEYS) && KBD2_REPORT_KEYS > KBD_REPORT_KEYS
73# define REPORT_KEYS KBD2_REPORT_KEYS
74# else
75# define REPORT_KEYS KBD_REPORT_KEYS
76# endif
77#else
78# define REPORT_KEYS 6
79#endif
80
81typedef struct {
82 uint8_t mods;
83 uint8_t rserved;
84 uint8_t keys[REPORT_KEYS];
85} report_keyboard_t;
86
87typedef struct {
88 uint8_t report_id;
89 uint8_t buttons;
90 int8_t x;
91 int8_t y;
92 int8_t v;
93 int8_t h;
94} report_mouse_t;
95
96#endif
diff --git a/Makefile.rules b/rules.mk
index f1d0a301c..f1d0a301c 100644
--- a/Makefile.rules
+++ b/rules.mk
diff --git a/sendchar.h b/sendchar.h
index b31665441..7c81303c7 100644
--- a/sendchar.h
+++ b/sendchar.h
@@ -18,8 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#ifndef SENDCHAR_H 18#ifndef SENDCHAR_H
19#define SENDCHAR_H 19#define SENDCHAR_H
20 20
21#include <stdint.h>
22
23
21/* transmit a character. return 0 on success, -1 on error. */ 24/* transmit a character. return 0 on success, -1 on error. */
22int8_t sendchar(uint8_t c); 25int8_t sendchar(uint8_t c);
23 26
24#endif 27#endif
25
diff --git a/vusb/host_vusb.h b/sendchar_null.c
index be9886e88..293330622 100644
--- a/vusb/host_vusb.h
+++ b/sendchar_null.c
@@ -14,10 +14,10 @@ GNU General Public License for more details.
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include "sendchar.h"
17 18
18#ifndef HOST_VUSB_H
19#define HOST_VUSB_H
20 19
21void host_vusb_keyboard_send(void); 20int8_t sendchar(uint8_t c)
22 21{
23#endif 22 return 0;
23}
diff --git a/sendchar_uart.c b/sendchar_uart.c
new file mode 100644
index 000000000..0241859eb
--- /dev/null
+++ b/sendchar_uart.c
@@ -0,0 +1,25 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "uart.h"
18#include "sendchar.h"
19
20
21int8_t sendchar(uint8_t c)
22{
23 uart_putchar(c);
24 return 0;
25}
diff --git a/timer.c b/timer.c
index edbb4409d..48a38c9b6 100644
--- a/timer.c
+++ b/timer.c
@@ -20,17 +20,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include <stdint.h> 20#include <stdint.h>
21#include "timer.h" 21#include "timer.h"
22 22
23
24// counter resolution 1ms
23volatile uint16_t timer_count = 0; 25volatile uint16_t timer_count = 0;
24 26
25// Configure timer 0 to generate a timer overflow interrupt every
26// 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock
27// This demonstrates how to use interrupts to implement a simple
28// inactivity timeout.
29void timer_init(void) 27void timer_init(void)
30{ 28{
31 TCCR0A = 0x00; 29 // Timer0 CTC mode
30 TCCR0A = 0x02;
31
32#if TIMER_PRESCALER == 1
33 TCCR0B = 0x01;
34#elif TIMER_PRESCALER == 8
35 TCCR0B = 0x02;
36#elif TIMER_PRESCALER == 64
37 TCCR0B = 0x03;
38#elif TIMER_PRESCALER == 256
39 TCCR0B = 0x04;
40#elif TIMER_PRESCALER == 1024
32 TCCR0B = 0x05; 41 TCCR0B = 0x05;
33 TIMSK0 = (1<<TOIE0); 42#else
43# error "Timer prescaler value is NOT vaild."
44#endif
45
46 OCR0A = TIMER_RAW_TOP;
47 TIMSK0 = (1<<OCIE0A);
34} 48}
35 49
36inline 50inline
@@ -65,14 +79,11 @@ uint16_t timer_elapsed(uint16_t last)
65 t = timer_count; 79 t = timer_count;
66 SREG = sreg; 80 SREG = sreg;
67 81
68 return TIMER_DIFF(t, last); 82 return TIMER_DIFF_MS(t, last);
69} 83}
70 84
71// This interrupt routine is run approx 61 times per second. 85// excecuted once per 1ms.(excess for just timer count?)
72// A very simple inactivity timeout is implemented, where we 86ISR(TIMER0_COMPA_vect)
73// will send a space character and print a message to the
74// hid_listen debug message window.
75ISR(TIMER0_OVF_vect)
76{ 87{
77 timer_count++; 88 timer_count++;
78} 89}
diff --git a/timer.h b/timer.h
index 402d4acc1..f9e8181e6 100644
--- a/timer.h
+++ b/timer.h
@@ -20,7 +20,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21#include <stdint.h> 21#include <stdint.h>
22 22
23#define TIMER_DIFF(a, b) ((a) >= (b) ? (a) - (b) : UINT16_MAX - (b) + (a)) 23#ifndef TIMER_PRESCALER
24# if F_CPU > 16000000
25# define TIMER_PRESCALER 256
26# elif F_CPU >= 4000000
27# define TIMER_PRESCALER 64
28# else
29# define TIMER_PRESCALER 8
30# endif
31#endif
32#define TIMER_RAW_FREQ (F_CPU/TIMER_PRESCALER)
33#define TIMER_RAW TCNT0
34#define TIMER_RAW_TOP (TIMER_RAW_FREQ/1000)
35
36#if (TIMER_RAW_TOP > 255)
37# error "Timer0 can't count 1ms at this clock freq. Use larger prescaler."
38#endif
39
40#define TIMER_DIFF(a, b, max) ((a) >= (b) ? (a) - (b) : (max) - (b) + (a))
41#define TIMER_DIFF_RAW(a, b) TIMER_DIFF(a, b, UINT8_MAX)
42#define TIMER_DIFF_MS(a, b) TIMER_DIFF(a, b, UINT16_MAX)
24 43
25 44
26extern volatile uint16_t timer_count; 45extern volatile uint16_t timer_count;
diff --git a/uart.c b/uart.c
new file mode 100644
index 000000000..c17649b08
--- /dev/null
+++ b/uart.c
@@ -0,0 +1,129 @@
1// TODO: Teensy support(ATMega32u4/AT90USB128)
2// Fixed for Arduino Duemilanove ATmega168p by Jun Wako
3/* UART Example for Teensy USB Development Board
4 * http://www.pjrc.com/teensy/
5 * Copyright (c) 2009 PJRC.COM, LLC
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26// Version 1.0: Initial Release
27// Version 1.1: Add support for Teensy 2.0, minor optimizations
28
29
30#include <avr/io.h>
31#include <avr/interrupt.h>
32
33#include "uart.h"
34
35// These buffers may be any size from 2 to 256 bytes.
36#define RX_BUFFER_SIZE 64
37#define TX_BUFFER_SIZE 40
38
39static volatile uint8_t tx_buffer[TX_BUFFER_SIZE];
40static volatile uint8_t tx_buffer_head;
41static volatile uint8_t tx_buffer_tail;
42static volatile uint8_t rx_buffer[RX_BUFFER_SIZE];
43static volatile uint8_t rx_buffer_head;
44static volatile uint8_t rx_buffer_tail;
45
46// Initialize the UART
47void uart_init(uint32_t baud)
48{
49 cli();
50 UBRR0 = (F_CPU / 4 / baud - 1) / 2;
51 UCSR0A = (1<<U2X0);
52 UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
53 UCSR0C = (1<<UCSZ01) | (1<<UCSZ00);
54 tx_buffer_head = tx_buffer_tail = 0;
55 rx_buffer_head = rx_buffer_tail = 0;
56 sei();
57}
58
59// Transmit a byte
60void uart_putchar(uint8_t c)
61{
62 uint8_t i;
63
64 i = tx_buffer_head + 1;
65 if (i >= TX_BUFFER_SIZE) i = 0;
66 while (tx_buffer_tail == i) ; // wait until space in buffer
67 //cli();
68 tx_buffer[i] = c;
69 tx_buffer_head = i;
70 UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0) | (1<<UDRIE0);
71 //sei();
72}
73
74// Receive a byte
75uint8_t uart_getchar(void)
76{
77 uint8_t c, i;
78
79 while (rx_buffer_head == rx_buffer_tail) ; // wait for character
80 i = rx_buffer_tail + 1;
81 if (i >= RX_BUFFER_SIZE) i = 0;
82 c = rx_buffer[i];
83 rx_buffer_tail = i;
84 return c;
85}
86
87// Return the number of bytes waiting in the receive buffer.
88// Call this before uart_getchar() to check if it will need
89// to wait for a byte to arrive.
90uint8_t uart_available(void)
91{
92 uint8_t head, tail;
93
94 head = rx_buffer_head;
95 tail = rx_buffer_tail;
96 if (head >= tail) return head - tail;
97 return RX_BUFFER_SIZE + head - tail;
98}
99
100// Transmit Interrupt
101ISR(USART_UDRE_vect)
102{
103 uint8_t i;
104
105 if (tx_buffer_head == tx_buffer_tail) {
106 // buffer is empty, disable transmit interrupt
107 UCSR0B = (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
108 } else {
109 i = tx_buffer_tail + 1;
110 if (i >= TX_BUFFER_SIZE) i = 0;
111 UDR0 = tx_buffer[i];
112 tx_buffer_tail = i;
113 }
114}
115
116// Receive Interrupt
117ISR(USART_RX_vect)
118{
119 uint8_t c, i;
120
121 c = UDR0;
122 i = rx_buffer_head + 1;
123 if (i >= RX_BUFFER_SIZE) i = 0;
124 if (i != rx_buffer_tail) {
125 rx_buffer[i] = c;
126 rx_buffer_head = i;
127 }
128}
129
diff --git a/uart.h b/uart.h
new file mode 100644
index 000000000..41136a396
--- /dev/null
+++ b/uart.h
@@ -0,0 +1,11 @@
1#ifndef _uart_included_h_
2#define _uart_included_h_
3
4#include <stdint.h>
5
6void uart_init(uint32_t baud);
7void uart_putchar(uint8_t c);
8uint8_t uart_getchar(void);
9uint8_t uart_available(void);
10
11#endif
diff --git a/usb_keycodes.h b/usb_keycodes.h
index 8b8d4d350..391d21f20 100644
--- a/usb_keycodes.h
+++ b/usb_keycodes.h
@@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18/* 18/*
19 * Key codes from HID Keyboard/Keypad Page 19 * Key codes: HID Keyboard/Keypad Page(0x07)
20 * http://www.usb.org/developers/devclass_docs/Hut1_12.pdf 20 * http://www.usb.org/developers/devclass_docs/Hut1_12.pdf
21 */ 21 */
22#ifndef USB_KEYCODES_H 22#ifndef USB_KEYCODES_H
@@ -353,7 +353,8 @@ enum keycodes {
353 KB_CRSEL, 353 KB_CRSEL,
354 KB_EXSEL, 354 KB_EXSEL,
355 355
356 /* NOTE: uses 0xB0-DF for special keycodes */ 356 /* NOTE: 0xB0-DF are used as special_keycodes */
357#if 0
357 KB_KP_00 = 0xB0, 358 KB_KP_00 = 0xB0,
358 KB_KP_000, 359 KB_KP_000,
359 KB_THOUSANDS_SEPARATOR, 360 KB_THOUSANDS_SEPARATOR,
@@ -400,6 +401,7 @@ enum keycodes {
400 KB_KP_OCTAL, 401 KB_KP_OCTAL,
401 KB_KP_DECIMAL, 402 KB_KP_DECIMAL,
402 KB_KP_HEXADECIMAL, 403 KB_KP_HEXADECIMAL,
404#endif
403 405
404 /* Modifiers */ 406 /* Modifiers */
405 KB_LCTRL = 0xE0, 407 KB_LCTRL = 0xE0,
@@ -411,7 +413,7 @@ enum keycodes {
411 KB_RALT, 413 KB_RALT,
412 KB_RGUI, 414 KB_RGUI,
413 415
414 /* NOTE: uses 0xE8-FF for special keycodes */ 416 /* NOTE: 0xE8-FF are used as special_keycodes */
415}; 417};
416 418
417#endif /* USB_KEYCODES_H */ 419#endif /* USB_KEYCODES_H */
diff --git a/vusb.mk b/vusb.mk
new file mode 100644
index 000000000..7fd5dc054
--- /dev/null
+++ b/vusb.mk
@@ -0,0 +1,17 @@
1OPT_DEFS += -DHOST_VUSB
2
3SRC += vusb.c \
4 usbdrv.c \
5 usbdrvasm.S \
6 oddebug.c
7
8ifdef NO_UART
9SRC += sendchar_null.c
10else
11SRC += sendchar_uart.c \
12 uart.c
13endif
14
15
16# Search Path
17VPATH += $(COMMON_DIR)/vusb:$(COMMON_DIR)/vusb/usbdrv
diff --git a/vusb/main.c b/vusb/main.c
new file mode 100644
index 000000000..1bf9035b3
--- /dev/null
+++ b/vusb/main.c
@@ -0,0 +1,99 @@
1/* Name: main.c
2 * Project: hid-mouse, a very simple HID example
3 * Author: Christian Starkjohann
4 * Creation Date: 2008-04-07
5 * Tabsize: 4
6 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
9 */
10#include <stdint.h>
11#include <avr/interrupt.h>
12#include <avr/wdt.h>
13#include <avr/sleep.h>
14#include <util/delay.h>
15#include "usbdrv.h"
16#include "oddebug.h"
17#include "vusb.h"
18#include "keyboard.h"
19#include "host.h"
20#include "timer.h"
21#include "uart.h"
22#include "debug.h"
23
24
25#define UART_BAUD_RATE 115200
26
27
28/* This is from main.c of USBaspLoader */
29static void initForUsbConnectivity(void)
30{
31 uint8_t i = 0;
32
33 usbInit();
34 /* enforce USB re-enumerate: */
35 usbDeviceDisconnect(); /* do this while interrupts are disabled */
36 while(--i){ /* fake USB disconnect for > 250 ms */
37 wdt_reset();
38 _delay_ms(1);
39 }
40 usbDeviceConnect();
41 sei();
42}
43
44int main(void)
45{
46 bool suspended = false;
47#if USB_COUNT_SOF
48 uint16_t last_timer = timer_read();
49#endif
50
51 CLKPR = 0x80, CLKPR = 0;
52#ifndef PS2_USE_USART
53 uart_init(UART_BAUD_RATE);
54#endif
55
56 debug_enable = true;
57 print_enable = true;
58
59 debug("keyboard_init()\n");
60 keyboard_init();
61 host_set_driver(vusb_driver());
62
63 debug("initForUsbConnectivity()\n");
64 initForUsbConnectivity();
65
66 debug("main loop\n");
67 while (1) {
68#if USB_COUNT_SOF
69 if (usbSofCount != 0) {
70 suspended = false;
71 usbSofCount = 0;
72 last_timer = timer_read();
73 } else {
74 // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
75 if (timer_elapsed(last_timer) > 5) {
76 suspended = true;
77/*
78 uart_putchar('S');
79 _delay_ms(1);
80 cli();
81 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
82 sleep_enable();
83 sleep_bod_disable();
84 sei();
85 sleep_cpu();
86 sleep_disable();
87 _delay_ms(10);
88 uart_putchar('W');
89*/
90 }
91 }
92#endif
93 if (!suspended)
94 usbPoll();
95 keyboard_proc();
96 if (!suspended)
97 vusb_transfer_keyboard();
98 }
99}
diff --git a/vusb/host.c b/vusb/vusb.c
index 8cd38d0b3..638611f32 100644
--- a/vusb/host.c
+++ b/vusb/vusb.c
@@ -16,133 +16,69 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include <stdint.h> 18#include <stdint.h>
19#include <avr/interrupt.h>
20#include "usbdrv.h" 19#include "usbdrv.h"
21#include "usbconfig.h" 20#include "usbconfig.h"
22#include "print.h"
23#include "usb_keycodes.h"
24#include "host.h" 21#include "host.h"
25#include "host_vusb.h" 22#include "report.h"
23#include "print.h"
26#include "debug.h" 24#include "debug.h"
25#include "host_driver.h"
26#include "vusb.h"
27 27
28 28
29static report_keyboard_t report0; 29static uint8_t vusb_keyboard_leds = 0;
30static report_keyboard_t report1; 30static uint8_t vusb_idle_rate = 0;
31report_keyboard_t *keyboard_report = &report0;
32report_keyboard_t *keyboard_report_prev = &report1;
33
34static uint8_t keyboard_leds = 0;
35static uchar idleRate = 0;
36
37uint8_t host_keyboard_leds(void)
38{
39 return keyboard_leds;
40}
41
42
43/*------------------------------------------------------------------*
44 * Keyboard report operations
45 *------------------------------------------------------------------*/
46void host_add_key(uint8_t code)
47{
48 int8_t i = 0;
49 int8_t empty = -1;
50 for (; i < REPORT_KEYS; i++) {
51 if (keyboard_report_prev->keys[i] == code) {
52 keyboard_report->keys[i] = code;
53 break;
54 }
55 if (empty == -1 && keyboard_report_prev->keys[i] == KB_NO && keyboard_report->keys[i] == KB_NO) {
56 empty = i;
57 }
58 }
59 if (i == REPORT_KEYS && empty != -1) {
60 keyboard_report->keys[empty] = code;
61 }
62}
63
64void host_add_mod_bit(uint8_t mod)
65{
66 keyboard_report->mods |= mod;
67}
68
69void host_set_mods(uint8_t mods)
70{
71 keyboard_report->mods = mods;
72}
73
74void host_add_code(uint8_t code)
75{
76 if (IS_MOD(code)) {
77 host_add_mod_bit(MOD_BIT(code));
78 } else {
79 host_add_key(code);
80 }
81}
82
83void host_swap_keyboard_report(void)
84{
85 uint8_t sreg = SREG;
86 cli();
87 report_keyboard_t *tmp = keyboard_report_prev;
88 keyboard_report_prev = keyboard_report;
89 keyboard_report = tmp;
90 SREG = sreg;
91}
92 31
93void host_clear_keyboard_report(void) 32/* Keyboard report send buffer */
94{ 33#define KBUF_SIZE 16
95 keyboard_report->mods = 0; 34static report_keyboard_t kbuf[KBUF_SIZE];
96 for (int8_t i = 0; i < REPORT_KEYS; i++) { 35static uint8_t kbuf_head = 0;
97 keyboard_report->keys[i] = 0; 36static uint8_t kbuf_tail = 0;
98 }
99}
100 37
101uint8_t host_has_anykey(void)
102{
103 uint8_t cnt = 0;
104 for (int i = 0; i < REPORT_KEYS; i++) {
105 if (keyboard_report->keys[i])
106 cnt++;
107 }
108 return cnt;
109}
110 38
111uint8_t host_get_first_key(void) 39/* transfer keyboard report from buffer */
40void vusb_transfer_keyboard(void)
112{ 41{
113#ifdef USB_NKRO_ENABLE 42 if (usbInterruptIsReady()) {
114 if (keyboard_nkro) { 43 if (kbuf_head != kbuf_tail) {
115 uint8_t i = 0; 44 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
116 for (; i < REPORT_KEYS && !keyboard_report->keys[i]; i++) 45 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
117 ; 46 }
118 return i<<3 | biton(keyboard_report->keys[i]);
119 } 47 }
120#endif
121 return keyboard_report->keys[0];
122} 48}
123 49
124 50
125/*------------------------------------------------------------------* 51/*------------------------------------------------------------------*
126 * Keyboard report send buffer 52 * Host driver
127 *------------------------------------------------------------------*/ 53 *------------------------------------------------------------------*/
128#define KBUF_SIZE 16 54static uint8_t keyboard_leds(void);
129static report_keyboard_t kbuf[KBUF_SIZE]; 55static void send_keyboard(report_keyboard_t *report);
130static uint8_t kbuf_head = 0; 56static void send_mouse(report_mouse_t *report);
131static uint8_t kbuf_tail = 0; 57static void send_system(uint16_t data);
58static void send_consumer(uint16_t data);
59
60static host_driver_t driver = {
61 keyboard_leds,
62 send_keyboard,
63 send_mouse,
64 send_system,
65 send_consumer
66};
132 67
133void host_vusb_keyboard_send(void) 68host_driver_t *vusb_driver(void)
134{ 69{
135 if (usbInterruptIsReady() && kbuf_head != kbuf_tail) { 70 return &driver;
136 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
137 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
138 }
139} 71}
140 72
141void host_send_keyboard_report(void) 73static uint8_t keyboard_leds(void) {
74 return vusb_keyboard_leds;
75}
76
77static void send_keyboard(report_keyboard_t *report)
142{ 78{
143 uint8_t next = (kbuf_head + 1) % KBUF_SIZE; 79 uint8_t next = (kbuf_head + 1) % KBUF_SIZE;
144 if (next != kbuf_tail) { 80 if (next != kbuf_tail) {
145 kbuf[kbuf_head] = *keyboard_report; 81 kbuf[kbuf_head] = *report;
146 kbuf_head = next; 82 kbuf_head = next;
147 } else { 83 } else {
148 debug("kbuf: full\n"); 84 debug("kbuf: full\n");
@@ -150,20 +86,15 @@ void host_send_keyboard_report(void)
150} 86}
151 87
152 88
153#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) 89static void send_mouse(report_mouse_t *report)
154void host_mouse_send(report_mouse_t *report)
155{ 90{
156 report->report_id = REPORT_ID_MOUSE; 91 report->report_id = REPORT_ID_MOUSE;
157 if (usbInterruptIsReady3()) { 92 if (usbInterruptIsReady3()) {
158 usbSetInterrupt3((void *)report, sizeof(*report)); 93 usbSetInterrupt3((void *)report, sizeof(*report));
159 } else {
160 debug("Int3 not ready\n");
161 } 94 }
162} 95}
163#endif
164 96
165#ifdef USB_EXTRA_ENABLE 97static void send_system(uint16_t data)
166void host_system_send(uint16_t data)
167{ 98{
168 // Not need static? 99 // Not need static?
169 static uint8_t report[] = { REPORT_ID_SYSTEM, 0, 0 }; 100 static uint8_t report[] = { REPORT_ID_SYSTEM, 0, 0 };
@@ -171,12 +102,10 @@ void host_system_send(uint16_t data)
171 report[2] = (data>>8)&0xFF; 102 report[2] = (data>>8)&0xFF;
172 if (usbInterruptIsReady3()) { 103 if (usbInterruptIsReady3()) {
173 usbSetInterrupt3((void *)&report, sizeof(report)); 104 usbSetInterrupt3((void *)&report, sizeof(report));
174 } else {
175 debug("Int3 not ready\n");
176 } 105 }
177} 106}
178 107
179void host_consumer_send(uint16_t data) 108static void send_consumer(uint16_t data)
180{ 109{
181 static uint16_t last_data = 0; 110 static uint16_t last_data = 0;
182 if (data == last_data) return; 111 if (data == last_data) return;
@@ -188,11 +117,8 @@ void host_consumer_send(uint16_t data)
188 report[2] = (data>>8)&0xFF; 117 report[2] = (data>>8)&0xFF;
189 if (usbInterruptIsReady3()) { 118 if (usbInterruptIsReady3()) {
190 usbSetInterrupt3((void *)&report, sizeof(report)); 119 usbSetInterrupt3((void *)&report, sizeof(report));
191 } else {
192 debug("Int3 not ready\n");
193 } 120 }
194} 121}
195#endif
196 122
197 123
198 124
@@ -213,32 +139,36 @@ usbRequest_t *rq = (void *)data;
213 139
214 if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */ 140 if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){ /* class request type */
215 if(rq->bRequest == USBRQ_HID_GET_REPORT){ 141 if(rq->bRequest == USBRQ_HID_GET_REPORT){
216 debug(" GET_REPORT"); 142 debug("GET_REPORT:");
217 /* we only have one report type, so don't look at wValue */ 143 /* we only have one report type, so don't look at wValue */
218 usbMsgPtr = (void *)keyboard_report_prev; 144 usbMsgPtr = (void *)keyboard_report_prev;
219 return sizeof(*keyboard_report_prev); 145 return sizeof(*keyboard_report_prev);
220 }else if(rq->bRequest == USBRQ_HID_GET_IDLE){ 146 }else if(rq->bRequest == USBRQ_HID_GET_IDLE){
221 debug(" GET_IDLE: "); 147 debug("GET_IDLE: ");
222 debug_hex(idleRate); 148 //debug_hex(vusb_idle_rate);
223 usbMsgPtr = &idleRate; 149 usbMsgPtr = &vusb_idle_rate;
224 return 1; 150 return 1;
225 }else if(rq->bRequest == USBRQ_HID_SET_IDLE){ 151 }else if(rq->bRequest == USBRQ_HID_SET_IDLE){
226 idleRate = rq->wValue.bytes[1]; 152 vusb_idle_rate = rq->wValue.bytes[1];
227 debug(" SET_IDLE: "); 153 debug("SET_IDLE: ");
228 debug_hex(idleRate); 154 debug_hex(vusb_idle_rate);
229 }else if(rq->bRequest == USBRQ_HID_SET_REPORT){ 155 }else if(rq->bRequest == USBRQ_HID_SET_REPORT){
230 //debug(" SET_REPORT: "); 156 debug("SET_REPORT: ");
157 // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
231 if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) { 158 if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) {
159 debug("SET_LED: ");
232 last_req.kind = SET_LED; 160 last_req.kind = SET_LED;
233 last_req.len = rq->wLength.word; 161 last_req.len = rq->wLength.word;
234 } 162 }
235 return USB_NO_MSG; // to get data in usbFunctionWrite 163 return USB_NO_MSG; // to get data in usbFunctionWrite
164 } else {
165 debug("UNKNOWN:");
236 } 166 }
237 debug("\n");
238 }else{ 167 }else{
239 debug("VENDOR\n"); 168 debug("VENDOR:");
240 /* no vendor specific requests implemented */ 169 /* no vendor specific requests implemented */
241 } 170 }
171 debug("\n");
242 return 0; /* default for not implemented requests: return no data back to host */ 172 return 0; /* default for not implemented requests: return no data back to host */
243} 173}
244 174
@@ -249,8 +179,10 @@ uchar usbFunctionWrite(uchar *data, uchar len)
249 } 179 }
250 switch (last_req.kind) { 180 switch (last_req.kind) {
251 case SET_LED: 181 case SET_LED:
252 //debug("SET_LED\n"); 182 debug("SET_LED: ");
253 keyboard_leds = data[0]; 183 debug_hex(data[0]);
184 debug("\n");
185 vusb_keyboard_leds = data[0];
254 last_req.len = 0; 186 last_req.len = 0;
255 return 1; 187 return 1;
256 break; 188 break;
@@ -484,13 +416,14 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)
484{ 416{
485 usbMsgLen_t len = 0; 417 usbMsgLen_t len = 0;
486 418
419/*
487 debug("usbFunctionDescriptor: "); 420 debug("usbFunctionDescriptor: ");
488 debug_hex(rq->bmRequestType); debug(" "); 421 debug_hex(rq->bmRequestType); debug(" ");
489 debug_hex(rq->bRequest); debug(" "); 422 debug_hex(rq->bRequest); debug(" ");
490 debug_hex16(rq->wValue.word); debug(" "); 423 debug_hex16(rq->wValue.word); debug(" ");
491 debug_hex16(rq->wIndex.word); debug(" "); 424 debug_hex16(rq->wIndex.word); debug(" ");
492 debug_hex16(rq->wLength.word); debug("\n"); 425 debug_hex16(rq->wLength.word); debug("\n");
493 426*/
494 switch (rq->wValue.bytes[1]) { 427 switch (rq->wValue.bytes[1]) {
495#if USB_CFG_DESCR_PROPS_CONFIGURATION 428#if USB_CFG_DESCR_PROPS_CONFIGURATION
496 case USBDESCR_CONFIG: 429 case USBDESCR_CONFIG:
@@ -499,8 +432,16 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)
499 break; 432 break;
500#endif 433#endif
501 case USBDESCR_HID: 434 case USBDESCR_HID:
502 usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 18); 435 switch (rq->wValue.bytes[0]) {
503 len = 9; 436 case 0:
437 usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + 9);
438 len = 9;
439 break;
440 case 1:
441 usbMsgPtr = (unsigned char *)(usbDescriptorConfiguration + 9 + (9 + 9 + 7) + 9);
442 len = 9;
443 break;
444 }
504 break; 445 break;
505 case USBDESCR_HID_REPORT: 446 case USBDESCR_HID_REPORT:
506 /* interface index */ 447 /* interface index */
@@ -516,6 +457,6 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)
516 } 457 }
517 break; 458 break;
518 } 459 }
519 debug("desc len: "); debug_hex(len); debug("\n"); 460 //debug("desc len: "); debug_hex(len); debug("\n");
520 return len; 461 return len;
521} 462}
diff --git a/vusb/vusb.h b/vusb/vusb.h
new file mode 100644
index 000000000..5accf233b
--- /dev/null
+++ b/vusb/vusb.h
@@ -0,0 +1,27 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef VUSB_H
19#define VUSB_H
20
21#include "host_driver.h"
22
23
24host_driver_t *vusb_driver(void);
25void vusb_transfer_keyboard(void);
26
27#endif