aboutsummaryrefslogtreecommitdiff
path: root/ps2_usb
diff options
context:
space:
mode:
Diffstat (limited to 'ps2_usb')
-rw-r--r--ps2_usb/Makefile56
-rw-r--r--ps2_usb/Makefile.vusb84
-rw-r--r--ps2_usb/README15
-rw-r--r--ps2_usb/config_pjrc.h (renamed from ps2_usb/config.h)16
-rw-r--r--ps2_usb/config_vusb.h116
-rw-r--r--ps2_usb/keymap.c9
-rw-r--r--ps2_usb/led.c16
-rw-r--r--ps2_usb/main_vusb.c62
-rw-r--r--ps2_usb/matrix.c50
-rw-r--r--ps2_usb/ps2_usart.c325
-rw-r--r--ps2_usb/sendchar_dummy.c8
-rw-r--r--ps2_usb/sendchar_usart.c58
-rw-r--r--ps2_usb/usbconfig.h378
13 files changed, 1084 insertions, 109 deletions
diff --git a/ps2_usb/Makefile b/ps2_usb/Makefile
index bd9a76eb8..af73be2c9 100644
--- a/ps2_usb/Makefile
+++ b/ps2_usb/Makefile
@@ -1,46 +1,5 @@
1# Hey Emacs, this is a -*- makefile -*-
2#----------------------------------------------------------------------------
3# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
4#
5# Released to the Public Domain
6#
7# Additional material for this makefile was written by:
8# Peter Fleury
9# Tim Henigan
10# Colin O'Flynn
11# Reiner Patommel
12# Markus Pfaff
13# Sander Pool
14# Frederik Rouleau
15# Carlos Lamas
16#
17#----------------------------------------------------------------------------
18# On command line:
19#
20# make all = Make software.
21#
22# make clean = Clean out built project files.
23#
24# make coff = Convert ELF to AVR COFF.
25#
26# make extcoff = Convert ELF to AVR Extended COFF.
27#
28# make program = Download the hex file to the device, using avrdude.
29# Please customize the avrdude settings below first!
30#
31# make debug = Start either simulavr or avarice as specified for debugging,
32# with avr-gdb or avr-insight as the front end for debugging.
33#
34# make filename.s = Just compile filename.c into the assembler code only.
35#
36# make filename.i = Create a preprocessed source file for use in submitting
37# bug reports to the GCC project.
38#
39# To rebuild project do "make clean" then "make all".
40#----------------------------------------------------------------------------
41
42# Target file name (without extension). 1# Target file name (without extension).
43TARGET = tmk_ps2_usb 2TARGET = ps2_usb
44 3
45# Directory common source filess exist 4# Directory common source filess exist
46COMMON_DIR = .. 5COMMON_DIR = ..
@@ -49,10 +8,14 @@ COMMON_DIR = ..
49TARGET_DIR = . 8TARGET_DIR = .
50 9
51# keyboard dependent files 10# keyboard dependent files
52TARGET_SRC = keymap.c \ 11TARGET_SRC = main_pjrc.c \
12 keymap.c \
53 matrix.c \ 13 matrix.c \
14 led.c \
54 ps2.c 15 ps2.c
55 16
17CONFIG_H = config_pjrc.h
18
56 19
57# MCU name, you MUST set this to match the board you are using 20# MCU name, you MUST set this to match the board you are using
58# type "make clean" after changing this, so all files will be rebuilt 21# type "make clean" after changing this, so all files will be rebuilt
@@ -78,4 +41,11 @@ USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System c
78USB_NKRO_ENABLE = yes # USB Nkey Rollover 41USB_NKRO_ENABLE = yes # USB Nkey Rollover
79 42
80 43
44
45#---------------- Programming Options --------------------------
46PROGRAM_CMD = teensy_loader_cli.exe -mmcu=$(MCU) -w -v $(TARGET).hex
47
48
49
50include $(COMMON_DIR)/Makefile.pjrc
81include $(COMMON_DIR)/Makefile.common 51include $(COMMON_DIR)/Makefile.common
diff --git a/ps2_usb/Makefile.vusb b/ps2_usb/Makefile.vusb
new file mode 100644
index 000000000..7b69dc27b
--- /dev/null
+++ b/ps2_usb/Makefile.vusb
@@ -0,0 +1,84 @@
1# Target file name (without extension).
2TARGET = ps2_vusb
3
4# Directory common source filess exist
5COMMON_DIR = ..
6
7# Directory keyboard dependent files exist
8TARGET_DIR = .
9
10# keyboard dependent files
11TARGET_SRC = main_vusb.c \
12 keymap.c \
13 matrix.c \
14 led.c \
15 ps2_usart.c \
16 sendchar_dummy.c
17# sendchar_usart.c
18
19CONFIG_H = config_vusb.h
20
21
22OPT_DEFS = -DDEBUG_LEVEL=0
23
24
25# MCU name, you MUST set this to match the board you are using
26# type "make clean" after changing this, so all files will be rebuilt
27#MCU = at90usb162 # Teensy 1.0
28#MCU = atmega32u4 # Teensy 2.0
29#MCU = at90usb646 # Teensy++ 1.0
30#MCU = at90usb1286 # Teensy++ 2.0
31MCU = atmega168
32
33
34# Processor frequency.
35# Normally the first thing your program should do is set the clock prescaler,
36# 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
38# examples use this variable to calculate timings. Do not add a "UL" here.
39F_CPU = 20000000
40
41
42# Build Options
43# comment out to disable the options.
44#
45MOUSEKEY_ENABLE = yes # Mouse keys
46#USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control)
47#USB_NKRO_ENABLE = yes # USB Nkey Rollover
48
49
50
51#---------------- Programming Options --------------------------
52AVRDUDE = avrdude
53# Type: avrdude -c ? to get a full listing.
54AVRDUDE_PROGRAMMER = usbasp
55AVRDUDE_PORT =
56AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
57#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
58
59# Uncomment the following if you want avrdude's erase cycle counter.
60# Note that this counter needs to be initialized first using -Yn,
61# see avrdude manual.
62#AVRDUDE_ERASE_COUNTER = -y
63
64# Uncomment the following if you do /not/ wish a verification to be
65# performed after programming the device.
66#AVRDUDE_NO_VERIFY = -V
67
68# Increase verbosity level. Please use this when submitting bug
69# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
70# to submit bug reports.
71#AVRDUDE_VERBOSE = -v -v
72
73#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
74AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
75AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
76AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
77AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
78
79PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
80
81
82
83include $(COMMON_DIR)/Makefile.vusb
84include $(COMMON_DIR)/Makefile.common
diff --git a/ps2_usb/README b/ps2_usb/README
index 3c9eb1428..ad5c6c431 100644
--- a/ps2_usb/README
+++ b/ps2_usb/README
@@ -47,10 +47,10 @@ Keymap customization
47 You can customize keymaps easily by editing source code. 47 You can customize keymaps easily by editing source code.
48 48
49 49
50Build 50Build for Teensy
51----- 51----------------
520. Connect PS/2 keyboard to Teensy by 4 lines(Vcc, GND, Data, Clock). 520. Connect PS/2 keyboard to Teensy by 4 lines(Vcc, GND, Data, Clock).
531. Define following macros for PS/2 connection in config.h: 531. Define following macros for PS/2 connection in config_pjrc.h:
54 PS2_DATA_PORT 54 PS2_DATA_PORT
55 PS2_DATA_PIN 55 PS2_DATA_PIN
56 PS2_DATA_DDR 56 PS2_DATA_DDR
@@ -65,6 +65,15 @@ Build
65 http://www.pjrc.com/teensy/loader.html 65 http://www.pjrc.com/teensy/loader.html
66 66
67 67
68Build for V-USB
69---------------
700. Build V-USB controller board and connect PS/2 keyboard.
711. Define macros in config_vusb.h if needed.
722. Edit Makefile.vusb for build options and MCU setting.
733. make -f Makefile.vusb
744. program your V-USB controller.
75
76
68Keymap 77Keymap
69------ 78------
70You can change a keymap by editing code of keymap.c like following. 79You can change a keymap by editing code of keymap.c like following.
diff --git a/ps2_usb/config.h b/ps2_usb/config_pjrc.h
index be96f004a..6205c4801 100644
--- a/ps2_usb/config.h
+++ b/ps2_usb/config_pjrc.h
@@ -10,22 +10,26 @@
10#define PRODUCT PS/2 keyboard converter 10#define PRODUCT PS/2 keyboard converter
11#define DESCRIPTION convert PS/2 keyboard to USB 11#define DESCRIPTION convert PS/2 keyboard to USB
12 12
13
13/* matrix size */ 14/* matrix size */
14#define MATRIX_ROWS 32 // keycode bit: 3-0 15#define MATRIX_ROWS 32 // keycode bit: 3-0
15#define MATRIX_COLS 8 // keycode bit: 6-4 16#define MATRIX_COLS 8 // keycode bit: 6-4
16/* define if matrix has ghost */
17//#define MATRIX_HAS_GHOST
18 17
19/* USB NKey Rollover */ 18
20#ifdef USB_NKRO_ENABLE 19/* key combination for command */
21#endif 20#define IS_COMMAND() ( \
21 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \
22 keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \
23)
24
22 25
23/* mouse keys */ 26/* mouse keys */
24#ifdef MOUSEKEY_ENABLE 27#ifdef MOUSEKEY_ENABLE
25# define MOUSEKEY_DELAY_TIME 255 28# define MOUSEKEY_DELAY_TIME 255
26#endif 29#endif
27 30
28/* PS/2 mouse */ 31
32/* PS/2 lines */
29#define PS2_CLOCK_PORT PORTF 33#define PS2_CLOCK_PORT PORTF
30#define PS2_CLOCK_PIN PINF 34#define PS2_CLOCK_PIN PINF
31#define PS2_CLOCK_DDR DDRF 35#define PS2_CLOCK_DDR DDRF
diff --git a/ps2_usb/config_vusb.h b/ps2_usb/config_vusb.h
new file mode 100644
index 000000000..0463f68ba
--- /dev/null
+++ b/ps2_usb/config_vusb.h
@@ -0,0 +1,116 @@
1#ifndef CONFIG_H
2#define CONFIG_H
3
4
5#define VENDOR_ID 0xFEED
6#define PRODUCT_ID 0x2233
7// TODO: share these strings with usbconfig.h
8// Edit usbconfig.h to change these.
9#define MANUFACTURER t.m.k.
10#define PRODUCT PS/2 keyboard converter
11#define DESCRIPTION convert PS/2 keyboard to USB
12
13
14/* matrix size */
15#define MATRIX_ROWS 32 // keycode bit: 3-0
16#define MATRIX_COLS 8 // keycode bit: 6-4
17
18
19/* key combination for command */
20#define IS_COMMAND() ( \
21 keyboard_report->mods == (BIT_LSHIFT | BIT_RSHIFT) || \
22 keyboard_report->mods == (BIT_LCTRL | BIT_RSHIFT) \
23)
24
25
26/* mouse keys */
27#ifdef MOUSEKEY_ENABLE
28# define MOUSEKEY_DELAY_TIME 255
29#endif
30
31
32/* PS/2 lines */
33#define PS2_CLOCK_PORT PORTD
34#define PS2_CLOCK_PIN PIND
35#define PS2_CLOCK_DDR DDRD
36#define PS2_CLOCK_BIT 4
37#define PS2_DATA_PORT PORTD
38#define PS2_DATA_PIN PIND
39#define PS2_DATA_DDR DDRD
40#define PS2_DATA_BIT 0
41
42
43// Synchronous USART is used to receive data from keyboard.
44// Use RXD pin for PS/2 DATA line and XCK for PS/2 CLOCK.
45// NOTE: This is recomended strongly if you use V-USB library.
46#define PS2_USE_USART
47
48// External or Pin Change Interrupt is used to receive data from keyboard.
49// Use INT1 or PCINTxx for PS/2 CLOCK line. see below.
50//#define PS2_USE_INT
51
52
53#ifdef PS2_USE_USART
54// synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge
55// set DDR of CLOCK as input to be slave
56#define PS2_USART_INIT() do { \
57 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
58 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
59 UCSR0C = ((1 << UMSEL00) | \
60 (3 << UPM00) | \
61 (0 << USBS0) | \
62 (3 << UCSZ00) | \
63 (0 << UCPOL0)); \
64 UCSR0A = 0; \
65 UBRR0H = 0; \
66 UBRR0L = 0; \
67} while (0)
68#define PS2_USART_RX_INT_ON() do { \
69 UCSR0B = ((1 << RXCIE0) | \
70 (1 << RXEN0)); \
71} while (0)
72#define PS2_USART_RX_POLL_ON() do { \
73 UCSR0B = (1 << RXEN0); \
74} while (0)
75#define PS2_USART_OFF() do { \
76 UCSR0C = 0; \
77 UCSR0B &= ~((1 << RXEN0) | \
78 (1 << TXEN0)); \
79} while (0)
80#define PS2_USART_RX_READY (UCSR0A & (1<<RXC0))
81#define PS2_USART_RX_DATA UDR0
82#define PS2_USART_ERROR (UCSR0A & ((1<<FE0) | (1<<DOR0) | (1<<UPE0)))
83#define PS2_USART_RX_VECT USART_RX_vect
84#endif
85
86
87#ifdef PS2_USE_INT
88/* INT1
89#define PS2_INT_INIT() do { \
90 EICRA |= ((1<<ISC11) | \
91 (0<<ISC10)); \
92} while (0)
93#define PS2_INT_ON() do { \
94 EIMSK |= (1<<INT1); \
95} while (0)
96#define PS2_INT_OFF() do { \
97 EIMSK &= ~(1<<INT1); \
98} while (0)
99#define PS2_INT_VECT INT1_vect
100*/
101
102/* PCINT20 */
103#define PS2_INT_INIT() do { \
104 PCICR |= (1<<PCIE2); \
105} while (0)
106#define PS2_INT_ON() do { \
107 PCMSK2 |= (1<<PCINT20); \
108} while (0)
109#define PS2_INT_OFF() do { \
110 PCMSK2 &= ~(1<<PCINT20); \
111 PCICR &= ~(1<<PCIE2); \
112} while (0)
113#define PS2_INT_VECT PCINT2_vect
114#endif
115
116#endif
diff --git a/ps2_usb/keymap.c b/ps2_usb/keymap.c
index 47db18bfa..253351f69 100644
--- a/ps2_usb/keymap.c
+++ b/ps2_usb/keymap.c
@@ -4,12 +4,11 @@
4#include <stdint.h> 4#include <stdint.h>
5#include <stdbool.h> 5#include <stdbool.h>
6#include <avr/pgmspace.h> 6#include <avr/pgmspace.h>
7#include "usb_keyboard.h"
8#include "usb_keycodes.h" 7#include "usb_keycodes.h"
9#include "print.h" 8#include "print.h"
10#include "debug.h" 9#include "debug.h"
11#include "util.h" 10#include "util.h"
12#include "keymap_skel.h" 11#include "keymap.h"
13 12
14 13
15#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) 14#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)]))
@@ -181,9 +180,3 @@ uint8_t keymap_fn_keycode(uint8_t fn_bits)
181{ 180{
182 return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); 181 return pgm_read_byte(&fn_keycode[(biton(fn_bits))]);
183} 182}
184
185// define a condition to enter special function mode
186bool keymap_is_special_mode(uint8_t fn_bits)
187{
188 return usb_keyboard_mods == (BIT_LSHIFT | BIT_RSHIFT) || usb_keyboard_mods == (BIT_LCTRL | BIT_RSHIFT);
189}
diff --git a/ps2_usb/led.c b/ps2_usb/led.c
new file mode 100644
index 000000000..d69b1c675
--- /dev/null
+++ b/ps2_usb/led.c
@@ -0,0 +1,16 @@
1#include "stdint.h"
2#include "ps2.h"
3#include "led.h"
4
5
6void led_set(uint8_t usb_led)
7{
8 uint8_t ps2_led = 0;
9 if (usb_led & (1<<USB_LED_SCROLL_LOCK))
10 ps2_led |= (1<<PS2_LED_SCROLL_LOCK);
11 if (usb_led & (1<<USB_LED_NUM_LOCK))
12 ps2_led |= (1<<PS2_LED_NUM_LOCK);
13 if (usb_led & (1<<USB_LED_CAPS_LOCK))
14 ps2_led |= (1<<PS2_LED_CAPS_LOCK);
15 ps2_host_set_led(ps2_led);
16}
diff --git a/ps2_usb/main_vusb.c b/ps2_usb/main_vusb.c
new file mode 100644
index 000000000..ec7c5797a
--- /dev/null
+++ b/ps2_usb/main_vusb.c
@@ -0,0 +1,62 @@
1/* PS/2 to USB keyboard converter
2 * 2011/02/20
3 * Copyright (c) 2011 tmk
4 */
5/* Name: main.c
6 * Project: hid-mouse, a very simple HID example
7 * Author: Christian Starkjohann
8 * Creation Date: 2008-04-07
9 * Tabsize: 4
10 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
11 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
12 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
13 */
14#include <stdint.h>
15#include <avr/wdt.h>
16#include <avr/interrupt.h>
17#include <util/delay.h>
18#include "usbdrv.h"
19#include "oddebug.h"
20#include "host_vusb.h"
21#include "keyboard.h"
22
23
24#if 0
25#define DEBUGP_INIT() do { DDRC = 0xFF; } while (0)
26#define DEBUGP(x) do { PORTC = x; } while (0)
27#else
28#define DEBUGP_INIT()
29#define DEBUGP(x)
30#endif
31
32
33int main(void)
34{
35 DEBUGP_INIT();
36 wdt_enable(WDTO_1S);
37 odDebugInit();
38 usbInit();
39
40 /* enforce re-enumeration, do this while interrupts are disabled! */
41 usbDeviceDisconnect();
42 uint8_t i = 0;
43 /* fake USB disconnect for > 250 ms */
44 while(--i){
45 wdt_reset();
46 _delay_ms(1);
47 }
48 usbDeviceConnect();
49
50 keyboard_init();
51
52 sei();
53 while (1) {
54 DEBUGP(0x1);
55 wdt_reset();
56 usbPoll();
57 DEBUGP(0x2);
58 keyboard_proc();
59 DEBUGP(0x3);
60 host_vusb_keyboard_send();
61 }
62}
diff --git a/ps2_usb/matrix.c b/ps2_usb/matrix.c
index aaf89719e..52479d975 100644
--- a/ps2_usb/matrix.c
+++ b/ps2_usb/matrix.c
@@ -9,8 +9,7 @@
9#include "util.h" 9#include "util.h"
10#include "debug.h" 10#include "debug.h"
11#include "ps2.h" 11#include "ps2.h"
12#include "usb_keyboard.h" 12#include "matrix.h"
13#include "matrix_skel.h"
14 13
15 14
16#if (MATRIX_COLS > 16) 15#if (MATRIX_COLS > 16)
@@ -60,8 +59,6 @@ static bool matrix_has_ghost_in_row(uint8_t row);
60#endif 59#endif
61static void matrix_make(uint8_t code); 60static void matrix_make(uint8_t code);
62static void matrix_break(uint8_t code); 61static void matrix_break(uint8_t code);
63static void ps2_reset(void);
64static void ps2_set_leds(uint8_t leds);
65 62
66 63
67inline 64inline
@@ -78,20 +75,8 @@ uint8_t matrix_cols(void)
78 75
79void matrix_init(void) 76void matrix_init(void)
80{ 77{
81 print_enable = true;
82 ps2_host_init(); 78 ps2_host_init();
83 79
84 ps2_reset();
85
86 // flush LEDs
87 ps2_set_leds(1<<PS2_LED_NUM_LOCK);
88 _delay_ms(100);
89 ps2_set_leds(1<<PS2_LED_NUM_LOCK|1<<PS2_LED_CAPS_LOCK);
90 _delay_ms(100);
91 ps2_set_leds(1<<PS2_LED_NUM_LOCK|1<<PS2_LED_CAPS_LOCK|1<<PS2_LED_SCROLL_LOCK);
92 _delay_ms(300);
93 ps2_set_leds(0x00);
94
95 // initialize matrix state: all keys off 80 // initialize matrix state: all keys off
96 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; 81 for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
97 82
@@ -191,7 +176,6 @@ uint8_t matrix_scan(void)
191 176
192 uint8_t code; 177 uint8_t code;
193 while ((code = ps2_host_recv())) { 178 while ((code = ps2_host_recv())) {
194debug_hex(code); debug(" ");
195 switch (state) { 179 switch (state) {
196 case INIT: 180 case INIT:
197 switch (code) { 181 switch (code) {
@@ -349,22 +333,6 @@ debug_hex(code); debug(" ");
349 state = INIT; 333 state = INIT;
350 } 334 }
351 } 335 }
352
353 // handle LED indicators
354 static uint8_t prev_leds = 0;
355 if (prev_leds != usb_keyboard_leds) {
356 uint8_t leds = 0;
357 if (usb_keyboard_leds&(1<<USB_LED_SCROLL_LOCK))
358 leds |= (1<<PS2_LED_SCROLL_LOCK);
359 if (usb_keyboard_leds&(1<<USB_LED_NUM_LOCK))
360 leds |= (1<<PS2_LED_NUM_LOCK);
361 if (usb_keyboard_leds&(1<<USB_LED_CAPS_LOCK))
362 leds |= (1<<PS2_LED_CAPS_LOCK);
363
364 ps2_set_leds(leds);
365 prev_leds = usb_keyboard_leds;
366 }
367
368 return 1; 336 return 1;
369} 337}
370 338
@@ -472,19 +440,3 @@ static void matrix_break(uint8_t code)
472 is_modified = true; 440 is_modified = true;
473 } 441 }
474} 442}
475
476static void ps2_reset(void)
477{
478 ps2_host_send(0xFF);
479 ps2_host_recv(); // 0xFA
480 ps2_host_recv(); // 0xAA
481 _delay_ms(1000);
482}
483
484static void ps2_set_leds(uint8_t leds)
485{
486 ps2_host_send(0xED);
487 ps2_host_recv(); // 0xFA
488 ps2_host_send(leds);
489 ps2_host_recv(); // 0xFA
490}
diff --git a/ps2_usb/ps2_usart.c b/ps2_usb/ps2_usart.c
new file mode 100644
index 000000000..e45b94c93
--- /dev/null
+++ b/ps2_usb/ps2_usart.c
@@ -0,0 +1,325 @@
1/*
2Copyright (c) 2010,2011 Jun WAKO <wakojun@gmail.com>
3
4This software is licensed with a Modified BSD License.
5All of this is supposed to be Free Software, Open Source, DFSG-free,
6GPL-compatible, and OK to use in both free and proprietary applications.
7Additions and corrections to this file are welcome.
8
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13* Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16* Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in
18 the documentation and/or other materials provided with the
19 distribution.
20
21* Neither the name of the copyright holders nor the names of
22 contributors may be used to endorse or promote products derived
23 from this software without specific prior written permission.
24
25THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE.
36*/
37/*
38Primitive PS/2 Library for AVR
39==============================
40Host side is only supported now.
41Synchronous USART is used to receive data by hardware process
42rather than interrupt. During V-USB interrupt runs, CLOCK interrupt
43cannot interpose. In the result it is prone to lost CLOCK edge.
44
45
46I/O control
47-----------
48High state is asserted by internal pull-up.
49If you have a signaling problem, you may need to have
50external pull-up resisters on CLOCK and DATA line.
51
52
53PS/2 References
54---------------
55http://www.computer-engineering.org/ps2protocol/
56http://www.mcamafia.de/pdf/ibm_hitrc07.pdf
57*/
58#include <stdbool.h>
59#include <avr/io.h>
60#include <avr/interrupt.h>
61#include <util/delay.h>
62#include "ps2.h"
63#include "debug.h"
64
65
66#if 0
67#define DEBUGP_INIT() do { DDRC = 0xFF; } while (0)
68#define DEBUGP(x) do { PORTC = x; } while (0)
69#else
70#define DEBUGP_INIT()
71#define DEBUGP(x)
72#endif
73
74#define WAIT(stat, us, err) do { \
75 if (!wait_##stat(us)) { \
76 ps2_error = err; \
77 goto ERROR; \
78 } \
79} while (0)
80
81
82uint8_t ps2_error = PS2_ERR_NONE;
83
84
85static inline void clock_lo(void);
86static inline void clock_hi(void);
87static inline bool clock_in(void);
88static inline void data_lo(void);
89static inline void data_hi(void);
90static inline bool data_in(void);
91static inline uint16_t wait_clock_lo(uint16_t us);
92static inline uint16_t wait_clock_hi(uint16_t us);
93static inline uint16_t wait_data_lo(uint16_t us);
94static inline uint16_t wait_data_hi(uint16_t us);
95static inline void idle(void);
96static inline void inhibit(void);
97#if defined PS2_USE_INT || defined PS2_USE_USART
98static inline uint8_t pbuf_dequeue(void);
99static inline void pbuf_enqueue(uint8_t data);
100#endif
101
102
103void ps2_host_init(void)
104{
105 DEBUGP_INIT();
106 DEBUGP(0x1);
107 idle();
108 PS2_USART_INIT();
109 PS2_USART_RX_INT_ON();
110}
111
112uint8_t ps2_host_send(uint8_t data)
113{
114 uint8_t res = 0;
115 bool parity = true;
116 ps2_error = PS2_ERR_NONE;
117
118 DEBUGP(0x6);
119 PS2_USART_OFF();
120
121 /* terminate a transmission if we have */
122 inhibit();
123 _delay_us(100);
124
125 /* start bit [1] */
126 data_lo();
127 clock_hi();
128 WAIT(clock_lo, 15000, 1);
129 /* data [2-9] */
130 for (uint8_t i = 0; i < 8; i++) {
131 _delay_us(15);
132 if (data&(1<<i)) {
133 parity = !parity;
134 data_hi();
135 } else {
136 data_lo();
137 }
138 WAIT(clock_hi, 50, 2);
139 WAIT(clock_lo, 50, 3);
140 }
141 /* parity [10] */
142 _delay_us(15);
143 if (parity) { data_hi(); } else { data_lo(); }
144 WAIT(clock_hi, 50, 4);
145 WAIT(clock_lo, 50, 5);
146 /* stop bit [11] */
147 _delay_us(15);
148 data_hi();
149 /* ack [12] */
150 WAIT(data_lo, 50, 6);
151 WAIT(clock_lo, 50, 7);
152
153 /* wait for idle state */
154 WAIT(clock_hi, 50, 8);
155 WAIT(data_hi, 50, 9);
156
157 res = ps2_host_recv_response();
158ERROR:
159 idle();
160 PS2_USART_INIT();
161 PS2_USART_RX_INT_ON();
162 return res;
163}
164
165// Do polling data from keyboard to get response to last command.
166uint8_t ps2_host_recv_response(void)
167{
168 uint8_t data = 0;
169 PS2_USART_INIT();
170 PS2_USART_RX_POLL_ON();
171 while (!PS2_USART_RX_READY)
172 ;
173 data = PS2_USART_RX_DATA;
174 PS2_USART_OFF();
175 DEBUGP(0x9);
176 return data;
177}
178
179uint8_t ps2_host_recv(void)
180{
181 return pbuf_dequeue();
182}
183
184ISR(PS2_USART_RX_VECT)
185{
186 DEBUGP(0x7);
187 uint8_t error = PS2_USART_ERROR;
188 uint8_t data = PS2_USART_RX_DATA;
189 if (error) {
190 DEBUGP(error>>2);
191 } else {
192 pbuf_enqueue(data);
193 }
194 DEBUGP(0x8);
195}
196
197/* send LED state to keyboard */
198void ps2_host_set_led(uint8_t led)
199{
200 // send 0xED then keyboard keeps waiting for next LED data
201 // and keyboard does not send any scan codes during waiting.
202 // If fail to send LED data keyboard looks like being freezed.
203 uint8_t retry = 3;
204 while (retry-- && ps2_host_send(PS2_SET_LED) != PS2_ACK)
205 ;
206 retry = 3;
207 while (retry-- && ps2_host_send(led) != PS2_ACK)
208 ;
209}
210
211
212/*--------------------------------------------------------------------
213 * static functions
214 *------------------------------------------------------------------*/
215static inline void clock_lo()
216{
217 PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT);
218 PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT);
219}
220static inline void clock_hi()
221{
222 /* input with pull up */
223 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
224 PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
225}
226static inline bool clock_in()
227{
228 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);
229 PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT);
230 _delay_us(1);
231 return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT);
232}
233static inline void data_lo()
234{
235 PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT);
236 PS2_DATA_DDR |= (1<<PS2_DATA_BIT);
237}
238static inline void data_hi()
239{
240 /* input with pull up */
241 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
242 PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
243}
244static inline bool data_in()
245{
246 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);
247 PS2_DATA_PORT |= (1<<PS2_DATA_BIT);
248 _delay_us(1);
249 return PS2_DATA_PIN&(1<<PS2_DATA_BIT);
250}
251
252static inline uint16_t wait_clock_lo(uint16_t us)
253{
254 while (clock_in() && us) { asm(""); _delay_us(1); us--; }
255 return us;
256}
257static inline uint16_t wait_clock_hi(uint16_t us)
258{
259 while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
260 return us;
261}
262static inline uint16_t wait_data_lo(uint16_t us)
263{
264 while (data_in() && us) { asm(""); _delay_us(1); us--; }
265 return us;
266}
267static inline uint16_t wait_data_hi(uint16_t us)
268{
269 while (!data_in() && us) { asm(""); _delay_us(1); us--; }
270 return us;
271}
272
273/* idle state that device can send */
274static inline void idle(void)
275{
276 clock_hi();
277 data_hi();
278}
279
280/* inhibit device to send */
281static inline void inhibit(void)
282{
283 clock_lo();
284 data_hi();
285}
286
287
288/*--------------------------------------------------------------------
289 * Ring buffer to store scan codes from keyboard
290 *------------------------------------------------------------------*/
291#define PBUF_SIZE 8
292static uint8_t pbuf[PBUF_SIZE];
293static uint8_t pbuf_head = 0;
294static uint8_t pbuf_tail = 0;
295static inline void pbuf_enqueue(uint8_t data)
296{
297 if (!data)
298 return;
299
300 uint8_t sreg = SREG;
301 cli();
302 uint8_t next = (pbuf_head + 1) % PBUF_SIZE;
303 if (next != pbuf_tail) {
304 pbuf[pbuf_head] = data;
305 pbuf_head = next;
306 } else {
307 debug("pbuf: full\n");
308 }
309 SREG = sreg;
310}
311
312static inline uint8_t pbuf_dequeue(void)
313{
314 uint8_t val = 0;
315
316 uint8_t sreg = SREG;
317 cli();
318 if (pbuf_head != pbuf_tail) {
319 val = pbuf[pbuf_tail];
320 pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE;
321 }
322 SREG = sreg;
323
324 return val;
325}
diff --git a/ps2_usb/sendchar_dummy.c b/ps2_usb/sendchar_dummy.c
new file mode 100644
index 000000000..8c9e583f1
--- /dev/null
+++ b/ps2_usb/sendchar_dummy.c
@@ -0,0 +1,8 @@
1#include <stdint.h>
2#include "sendchar.h"
3
4
5int8_t sendchar(uint8_t c)
6{
7 return 1;
8}
diff --git a/ps2_usb/sendchar_usart.c b/ps2_usb/sendchar_usart.c
new file mode 100644
index 000000000..fe18177a3
--- /dev/null
+++ b/ps2_usb/sendchar_usart.c
@@ -0,0 +1,58 @@
1#include <stdint.h>
2#include "oddebug.h"
3#include "sendchar.h"
4
5
6/* from oddebug.h */
7#if defined UBRR
8# define ODDBG_UBRR UBRR
9#elif defined UBRRL
10# define ODDBG_UBRR UBRRL
11#elif defined UBRR0
12# define ODDBG_UBRR UBRR0
13#elif defined UBRR0L
14# define ODDBG_UBRR UBRR0L
15#endif
16
17#if defined UCR
18# define ODDBG_UCR UCR
19#elif defined UCSRB
20# define ODDBG_UCR UCSRB
21#elif defined UCSR0B
22# define ODDBG_UCR UCSR0B
23#endif
24
25#if defined TXEN
26# define ODDBG_TXEN TXEN
27#else
28# define ODDBG_TXEN TXEN0
29#endif
30
31#if defined USR
32# define ODDBG_USR USR
33#elif defined UCSRA
34# define ODDBG_USR UCSRA
35#elif defined UCSR0A
36# define ODDBG_USR UCSR0A
37#endif
38
39#if defined UDRE
40# define ODDBG_UDRE UDRE
41#else
42# define ODDBG_UDRE UDRE0
43#endif
44
45#if defined UDR
46# define ODDBG_UDR UDR
47#elif defined UDR0
48# define ODDBG_UDR UDR0
49#endif
50
51
52/* from oddebug.c */
53int8_t sendchar(uint8_t c)
54{
55 while(!(ODDBG_USR & (1 << ODDBG_UDRE))); /* wait for data register empty */
56 ODDBG_UDR = c;
57 return 1;
58}
diff --git a/ps2_usb/usbconfig.h b/ps2_usb/usbconfig.h
new file mode 100644
index 000000000..9038f1eb8
--- /dev/null
+++ b/ps2_usb/usbconfig.h
@@ -0,0 +1,378 @@
1/* Name: usbconfig.h
2 * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers
3 * Author: Christian Starkjohann
4 * Creation Date: 2005-04-01
5 * Tabsize: 4
6 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $
9 */
10
11#ifndef __usbconfig_h_included__
12#define __usbconfig_h_included__
13
14#include "config_vusb.h"
15
16/*
17General Description:
18This file is an example configuration (with inline documentation) for the USB
19driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is
20also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may
21wire the lines to any other port, as long as D+ is also wired to INT0 (or any
22other hardware interrupt, as long as it is the highest level interrupt, see
23section at the end of this file).
24*/
25
26/* ---------------------------- Hardware Config ---------------------------- */
27
28#define USB_CFG_IOPORTNAME D
29/* This is the port where the USB bus is connected. When you configure it to
30 * "B", the registers PORTB, PINB and DDRB will be used.
31 */
32#define USB_CFG_DMINUS_BIT 3
33/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
34 * This may be any bit in the port.
35 */
36#define USB_CFG_DPLUS_BIT 2
37/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
38 * This may be any bit in the port. Please note that D+ must also be connected
39 * to interrupt pin INT0! [You can also use other interrupts, see section
40 * "Optional MCU Description" below, or you can connect D- to the interrupt, as
41 * it is required if you use the USB_COUNT_SOF feature. If you use D- for the
42 * interrupt, the USB interrupt will also be triggered at Start-Of-Frame
43 * markers every millisecond.]
44 */
45#define USB_CFG_CLOCK_KHZ (F_CPU/1000)
46/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000,
47 * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code
48 * require no crystal, they tolerate +/- 1% deviation from the nominal
49 * frequency. All other rates require a precision of 2000 ppm and thus a
50 * crystal!
51 * Since F_CPU should be defined to your actual clock rate anyway, you should
52 * not need to modify this setting.
53 */
54#define USB_CFG_CHECK_CRC 0
55/* Define this to 1 if you want that the driver checks integrity of incoming
56 * data packets (CRC checks). CRC checks cost quite a bit of code size and are
57 * currently only available for 18 MHz crystal clock. You must choose
58 * USB_CFG_CLOCK_KHZ = 18000 if you enable this option.
59 */
60
61/* ----------------------- Optional Hardware Config ------------------------ */
62
63/* #define USB_CFG_PULLUP_IOPORTNAME D */
64/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
65 * V+, you can connect and disconnect the device from firmware by calling
66 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
67 * This constant defines the port on which the pullup resistor is connected.
68 */
69/* #define USB_CFG_PULLUP_BIT 4 */
70/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
71 * above) where the 1.5k pullup resistor is connected. See description
72 * above for details.
73 */
74
75/* --------------------------- Functional Range ---------------------------- */
76
77#define USB_CFG_HAVE_INTRIN_ENDPOINT 1
78/* Define this to 1 if you want to compile a version with two endpoints: The
79 * default control endpoint 0 and an interrupt-in endpoint (any other endpoint
80 * number).
81 */
82#define USB_CFG_HAVE_INTRIN_ENDPOINT3 1
83/* Define this to 1 if you want to compile a version with three endpoints: The
84 * default control endpoint 0, an interrupt-in endpoint 3 (or the number
85 * configured below) and a catch-all default interrupt-in endpoint as above.
86 * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
87 */
88#define USB_CFG_EP3_NUMBER 3
89/* If the so-called endpoint 3 is used, it can now be configured to any other
90 * endpoint number (except 0) with this macro. Default if undefined is 3.
91 */
92/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */
93/* The above macro defines the startup condition for data toggling on the
94 * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1.
95 * Since the token is toggled BEFORE sending any data, the first packet is
96 * sent with the oposite value of this configuration!
97 */
98#define USB_CFG_IMPLEMENT_HALT 0
99/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
100 * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
101 * it is required by the standard. We have made it a config option because it
102 * bloats the code considerably.
103 */
104#define USB_CFG_SUPPRESS_INTR_CODE 0
105/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
106 * want to send any data over them. If this macro is defined to 1, functions
107 * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if
108 * you need the interrupt-in endpoints in order to comply to an interface
109 * (e.g. HID), but never want to send any data. This option saves a couple
110 * of bytes in flash memory and the transmit buffers in RAM.
111 */
112#define USB_CFG_INTR_POLL_INTERVAL 10
113/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
114 * interval. The value is in milliseconds and must not be less than 10 ms for
115 * low speed devices.
116 */
117#define USB_CFG_IS_SELF_POWERED 0
118/* Define this to 1 if the device has its own power supply. Set it to 0 if the
119 * device is powered from the USB bus.
120 */
121#define USB_CFG_MAX_BUS_POWER 100
122/* Set this variable to the maximum USB bus power consumption of your device.
123 * The value is in milliamperes. [It will be divided by two since USB
124 * communicates power requirements in units of 2 mA.]
125 */
126#define USB_CFG_IMPLEMENT_FN_WRITE 1
127/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
128 * transfers. Set it to 0 if you don't need it and want to save a couple of
129 * bytes.
130 */
131#define USB_CFG_IMPLEMENT_FN_READ 0
132/* Set this to 1 if you need to send control replies which are generated
133 * "on the fly" when usbFunctionRead() is called. If you only want to send
134 * data from a static buffer, set it to 0 and return the data from
135 * usbFunctionSetup(). This saves a couple of bytes.
136 */
137#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0
138/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints.
139 * You must implement the function usbFunctionWriteOut() which receives all
140 * interrupt/bulk data sent to any endpoint other than 0. The endpoint number
141 * can be found in 'usbRxToken'.
142 */
143#define USB_CFG_HAVE_FLOWCONTROL 0
144/* Define this to 1 if you want flowcontrol over USB data. See the definition
145 * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
146 * usbdrv.h.
147 */
148#define USB_CFG_DRIVER_FLASH_PAGE 0
149/* If the device has more than 64 kBytes of flash, define this to the 64 k page
150 * where the driver's constants (descriptors) are located. Or in other words:
151 * Define this to 1 for boot loaders on the ATMega128.
152 */
153#define USB_CFG_LONG_TRANSFERS 0
154/* Define this to 1 if you want to send/receive blocks of more than 254 bytes
155 * in a single control-in or control-out transfer. Note that the capability
156 * for long transfers increases the driver size.
157 */
158/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */
159/* This macro is a hook if you want to do unconventional things. If it is
160 * defined, it's inserted at the beginning of received message processing.
161 * If you eat the received message and don't want default processing to
162 * proceed, do a return after doing your things. One possible application
163 * (besides debugging) is to flash a status LED on each packet.
164 */
165/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */
166/* This macro is a hook if you need to know when an USB RESET occurs. It has
167 * one parameter which distinguishes between the start of RESET state and its
168 * end.
169 */
170/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */
171/* This macro (if defined) is executed when a USB SET_ADDRESS request was
172 * received.
173 */
174#define USB_COUNT_SOF 0
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
177 * connected to D- instead of D+.
178 */
179/* #ifdef __ASSEMBLER__
180 * macro myAssemblerMacro
181 * in YL, TCNT0
182 * sts timer0Snapshot, YL
183 * endm
184 * #endif
185 * #define USB_SOF_HOOK myAssemblerMacro
186 * This macro (if defined) is executed in the assembler module when a
187 * Start Of Frame condition is detected. It is recommended to define it to
188 * the name of an assembler macro which is defined here as well so that more
189 * than one assembler instruction can be used. The macro may use the register
190 * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages
191 * immediately after an SOF pulse may be lost and must be retried by the host.
192 * What can you do with this hook? Since the SOF signal occurs exactly every
193 * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in
194 * designs running on the internal RC oscillator.
195 * Please note that Start Of Frame detection works only if D- is wired to the
196 * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES!
197 */
198#define USB_CFG_CHECK_DATA_TOGGLING 0
199/* define this macro to 1 if you want to filter out duplicate data packets
200 * sent by the host. Duplicates occur only as a consequence of communication
201 * errors, when the host does not receive an ACK. Please note that you need to
202 * implement the filtering yourself in usbFunctionWriteOut() and
203 * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable
204 * for each control- and out-endpoint to check for duplicate packets.
205 */
206#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0
207/* define this macro to 1 if you want the function usbMeasureFrameLength()
208 * compiled in. This function can be used to calibrate the AVR's RC oscillator.
209 */
210#define USB_USE_FAST_CRC 0
211/* The assembler module has two implementations for the CRC algorithm. One is
212 * faster, the other is smaller. This CRC routine is only used for transmitted
213 * messages where timing is not critical. The faster routine needs 31 cycles
214 * per byte while the smaller one needs 61 to 69 cycles. The faster routine
215 * may be worth the 32 bytes bigger code size if you transmit lots of data and
216 * run the AVR close to its limit.
217 */
218
219/* -------------------------- Device Description --------------------------- */
220
221#define USB_CFG_VENDOR_ID (VENDOR_ID & 0xFF), ((VENDOR_ID >> 8) & 0xFF)
222/* USB vendor ID for the device, low byte first. If you have registered your
223 * own Vendor ID, define it here. Otherwise you may use one of obdev's free
224 * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules!
225 * *** IMPORTANT NOTE ***
226 * This template uses obdev's shared VID/PID pair for Vendor Class devices
227 * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand
228 * the implications!
229 */
230#define USB_CFG_DEVICE_ID (PRODUCT_ID & 0xFF), ((PRODUCT_ID >> 8) & 0xFF)
231/* This is the ID of the product, low byte first. It is interpreted in the
232 * scope of the vendor ID. If you have registered your own VID with usb.org
233 * or if you have licensed a PID from somebody else, define it here. Otherwise
234 * you may use one of obdev's free shared VID/PID pairs. See the file
235 * USB-IDs-for-free.txt for details!
236 * *** IMPORTANT NOTE ***
237 * This template uses obdev's shared VID/PID pair for Vendor Class devices
238 * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand
239 * the implications!
240 */
241#define USB_CFG_DEVICE_VERSION 0x00, 0x01
242/* Version number of the device: Minor number first, then major number.
243 */
244#define USB_CFG_VENDOR_NAME 't', '.', 'm', '.', 'k', '.'
245#define USB_CFG_VENDOR_NAME_LEN 6
246/* These two values define the vendor name returned by the USB device. The name
247 * must be given as a list of characters under single quotes. The characters
248 * are interpreted as Unicode (UTF-16) entities.
249 * If you don't want a vendor name string, undefine these macros.
250 * ALWAYS define a vendor name containing your Internet domain name if you use
251 * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for
252 * details.
253 */
254#define USB_CFG_DEVICE_NAME 'P', 'S', '/', '2', ' ', 'k', 'e', 'y', 'b', 'o', 'a', 'r', 'd', ' ', 'c', 'o', 'n', 'v', 'e', 'r', 't', 'e', 'r'
255#define USB_CFG_DEVICE_NAME_LEN 23
256/* Same as above for the device name. If you don't want a device name, undefine
257 * the macros. See the file USB-IDs-for-free.txt before you assign a name if
258 * you use a shared VID/PID.
259 */
260/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */
261/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */
262/* Same as above for the serial number. If you don't want a serial number,
263 * undefine the macros.
264 * It may be useful to provide the serial number through other means than at
265 * compile time. See the section about descriptor properties below for how
266 * to fine tune control over USB descriptors such as the string descriptor
267 * for the serial number.
268 */
269#define USB_CFG_DEVICE_CLASS 0
270#define USB_CFG_DEVICE_SUBCLASS 0
271/* See USB specification if you want to conform to an existing device class.
272 * Class 0xff is "vendor specific".
273 */
274#define USB_CFG_INTERFACE_CLASS 3 /* HID */
275#define USB_CFG_INTERFACE_SUBCLASS 1 /* Boot */
276#define USB_CFG_INTERFACE_PROTOCOL 1 /* Keyboard */
277/* See USB specification if you want to conform to an existing device class or
278 * protocol. The following classes must be set at interface level:
279 * HID class is 3, no subclass and protocol required (but may be useful!)
280 * CDC class is 2, use subclass 2 and protocol 1 for ACM
281 */
282#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0
283/* Define this to the length of the HID report descriptor, if you implement
284 * an HID device. Otherwise don't define it or define it to 0.
285 * If you use this define, you must add a PROGMEM character array named
286 * "usbHidReportDescriptor" to your code which contains the report descriptor.
287 * Don't forget to keep the array and this define in sync!
288 */
289
290/* #define USB_PUBLIC static */
291/* Use the define above if you #include usbdrv.c instead of linking against it.
292 * This technique saves a couple of bytes in flash memory.
293 */
294
295/* ------------------- Fine Control over USB Descriptors ------------------- */
296/* If you don't want to use the driver's default USB descriptors, you can
297 * provide our own. These can be provided as (1) fixed length static data in
298 * flash memory, (2) fixed length static data in RAM or (3) dynamically at
299 * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more
300 * information about this function.
301 * Descriptor handling is configured through the descriptor's properties. If
302 * no properties are defined or if they are 0, the default descriptor is used.
303 * Possible properties are:
304 * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
305 * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is
306 * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if
307 * you want RAM pointers.
308 * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
309 * in static memory is in RAM, not in flash memory.
310 * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
311 * the driver must know the descriptor's length. The descriptor itself is
312 * found at the address of a well known identifier (see below).
313 * List of static descriptor names (must be declared PROGMEM if in flash):
314 * char usbDescriptorDevice[];
315 * char usbDescriptorConfiguration[];
316 * char usbDescriptorHidReport[];
317 * char usbDescriptorString0[];
318 * int usbDescriptorStringVendor[];
319 * int usbDescriptorStringDevice[];
320 * int usbDescriptorStringSerialNumber[];
321 * Other descriptors can't be provided statically, they must be provided
322 * dynamically at runtime.
323 *
324 * Descriptor properties are or-ed or added together, e.g.:
325 * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18))
326 *
327 * The following descriptors are defined:
328 * USB_CFG_DESCR_PROPS_DEVICE
329 * USB_CFG_DESCR_PROPS_CONFIGURATION
330 * USB_CFG_DESCR_PROPS_STRINGS
331 * USB_CFG_DESCR_PROPS_STRING_0
332 * USB_CFG_DESCR_PROPS_STRING_VENDOR
333 * USB_CFG_DESCR_PROPS_STRING_PRODUCT
334 * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
335 * USB_CFG_DESCR_PROPS_HID
336 * USB_CFG_DESCR_PROPS_HID_REPORT
337 * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
338 *
339 * Note about string descriptors: String descriptors are not just strings, they
340 * are Unicode strings prefixed with a 2 byte header. Example:
341 * int serialNumberDescriptor[] = {
342 * USB_STRING_DESCRIPTOR_HEADER(6),
343 * 'S', 'e', 'r', 'i', 'a', 'l'
344 * };
345 */
346
347#define USB_CFG_DESCR_PROPS_DEVICE 0
348#define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC
349//#define USB_CFG_DESCR_PROPS_CONFIGURATION 0
350#define USB_CFG_DESCR_PROPS_STRINGS 0
351#define USB_CFG_DESCR_PROPS_STRING_0 0
352#define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
353#define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
354#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
355//#define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC
356#define USB_CFG_DESCR_PROPS_HID 0
357#define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC
358//#define USB_CFG_DESCR_PROPS_HID_REPORT 0
359#define USB_CFG_DESCR_PROPS_UNKNOWN 0
360
361/* ----------------------- Optional MCU Description ------------------------ */
362
363/* The following configurations have working defaults in usbdrv.h. You
364 * usually don't need to set them explicitly. Only if you want to run
365 * the driver on a device which is not yet supported or with a compiler
366 * which is not fully supported (such as IAR C) or if you use a differnt
367 * interrupt than INT0, you may have to define some of these.
368 */
369/* #define USB_INTR_CFG MCUCR */
370/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */
371/* #define USB_INTR_CFG_CLR 0 */
372/* #define USB_INTR_ENABLE GIMSK */
373/* #define USB_INTR_ENABLE_BIT INT0 */
374/* #define USB_INTR_PENDING GIFR */
375/* #define USB_INTR_PENDING_BIT INTF0 */
376/* #define USB_INTR_VECTOR INT0_vect */
377
378#endif /* __usbconfig_h_included__ */