aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build_keyboard.mk4
-rw-r--r--keyboards/ps2avrGB/Makefile3
-rw-r--r--keyboards/ps2avrGB/README.md61
-rw-r--r--keyboards/ps2avrGB/config.h44
-rw-r--r--keyboards/ps2avrGB/keymaps/default/keymap.c34
-rw-r--r--keyboards/ps2avrGB/matrix.c105
-rwxr-xr-xkeyboards/ps2avrGB/program74
-rw-r--r--keyboards/ps2avrGB/ps2avrGB.c0
-rw-r--r--keyboards/ps2avrGB/ps2avrGB.h54
-rw-r--r--keyboards/ps2avrGB/rules.mk38
-rw-r--r--keyboards/ps2avrGB/usbconfig.h396
-rw-r--r--tmk_core/common.mk8
-rw-r--r--tmk_core/common/avr/bootloader.c10
-rw-r--r--tmk_core/common/avr/suspend.c2
-rw-r--r--tmk_core/common/avr/timer.c33
-rw-r--r--tmk_core/common/command.c2
-rw-r--r--tmk_core/protocol/vusb.mk7
-rw-r--r--tmk_core/protocol/vusb/main.c6
-rw-r--r--tmk_core/protocol/vusb/vusb.c22
19 files changed, 886 insertions, 17 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index ce505de12..b85557d4a 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -221,7 +221,11 @@ OPT_DEFS += $(TMK_COMMON_DEFS)
221EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS) 221EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS)
222 222
223ifeq ($(PLATFORM),AVR) 223ifeq ($(PLATFORM),AVR)
224ifeq ($(strip $(PROTOCOL)), VUSB)
225 include $(TMK_PATH)/protocol/vusb.mk
226else
224 include $(TMK_PATH)/protocol/lufa.mk 227 include $(TMK_PATH)/protocol/lufa.mk
228endif
225 include $(TMK_PATH)/avr.mk 229 include $(TMK_PATH)/avr.mk
226endif 230endif
227 231
diff --git a/keyboards/ps2avrGB/Makefile b/keyboards/ps2avrGB/Makefile
new file mode 100644
index 000000000..57b2ef62e
--- /dev/null
+++ b/keyboards/ps2avrGB/Makefile
@@ -0,0 +1,3 @@
1ifndef MAKEFILE_INCLUDED
2 include ../../Makefile
3endif
diff --git a/keyboards/ps2avrGB/README.md b/keyboards/ps2avrGB/README.md
new file mode 100644
index 000000000..f8360aec0
--- /dev/null
+++ b/keyboards/ps2avrGB/README.md
@@ -0,0 +1,61 @@
1ps2avrGB keyboard firmware
2==========================
3
4This is a port of the QMK firmware for boards that are based on the
5ps2avrGB firmware, like the [ps2avrGB
6keyboard](https://www.keyclack.com/product/gb-ps2avrgb/) or the ones sold
7by [Winkeyless](http://winkeyless.kr/product/ps2avrgb-parts/).
8
9Note that this is a complete replacement for the firmware, so you won't be
10using Bootmapper Client to change any keyboard settings, since not all the
11USB report options are supported.
12
13## Supported Boards
14
15Only the [B.mini X2](http://winkeyless.kr/product/b-mini-x2-pcb/) has been
16tested so far (since it's the only one I own). But other boards that use
17the ps2avrGB firmware should work as well.
18
19## Installing
20
21First, install the requirements. These commands are for OSX, but all you
22need is the AVR toolchain and `bootloadHID` for flashing:
23
24```
25$ brew cask install crosspack-avr
26$ brew install --HEAD https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb
27```
28
29In order to use the `./program` script, which can reboot the board into
30the bootloader, you'll need Python 2 with PyUSB installed:
31
32```
33$ pip install pyusb
34```
35
36Then, with the keyboard plugged in, simply run this command from the
37`qmk_firmware` directory:
38
39```
40$ make ps2avrGB-program
41```
42
43If you prefer, you can just build it and flash the firmware directly with
44`bootloadHID` if you boot the board while holding down `L_Ctrl` to keep it
45in the bootloader:
46
47```
48$ make ps2avrGB
49$ bootloadHID -r ps2avrGB_default.hex
50```
51
52## Troubleshooting
53
54From my experience, it's really hard to brick these boards. But these
55tricks have been useful when it got stuck in a weird scenario.
56
571. Try plugging the board in while pressing `L_Ctrl`. This will force it
58 to boot only the bootloader without loading the firmware. Once this is
59 done, just reflash the board with the original firmware.
602. Sometimes USB hubs can act weird, so try connecting the board directly
61 to your computer or plugging/unplugging the USB hub.
diff --git a/keyboards/ps2avrGB/config.h b/keyboards/ps2avrGB/config.h
new file mode 100644
index 000000000..cd5d1ab5a
--- /dev/null
+++ b/keyboards/ps2avrGB/config.h
@@ -0,0 +1,44 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@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#include "config_common.h"
22
23#define VENDOR_ID 0x20A0
24#define PRODUCT_ID 0x422D
25// TODO: share these strings with usbconfig.h
26// Edit usbconfig.h to change these.
27#define MANUFACTURER winkeyless.kr
28#define PRODUCT ps2avrGB
29
30/* matrix size */
31#define MATRIX_ROWS 8
32#define MATRIX_COLS 15
33
34/* only support one hard-coded backlight color for now */
35#define BACKLIGHT_LEVELS 0
36#define BACKLIGHT_COLOR 0x110000
37
38#define NO_UART 1
39#define EEPROM_BOOTLOADER_START 1
40
41/* key combination for command */
42#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)))
43
44#endif
diff --git a/keyboards/ps2avrGB/keymaps/default/keymap.c b/keyboards/ps2avrGB/keymaps/default/keymap.c
new file mode 100644
index 000000000..43cc6bce3
--- /dev/null
+++ b/keyboards/ps2avrGB/keymaps/default/keymap.c
@@ -0,0 +1,34 @@
1#include "ps2avrGB.h"
2
3const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4 KEYMAP( \
5 ESC, NO, NO, NO, NO, NO, NO, MPRV,MPLY,MNXT,MUTE,VOLD,VOLU,PSCR,HOME,END, \
6 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, DEL, \
7 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, FN1, \
8 FN2, A, S, D, F, G, H, J, K, L, SCLN,QUOT,ENT, PGUP,\
9 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RSFT, UP, PGDN,\
10 FN0, LALT,LGUI, SPC, RGUI,RALT,RCTL,LEFT,DOWN,RGHT \
11 ),
12 KEYMAP( \
13 NO, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, NO, NO, NO, \
14 NO, NO, NO, NO, NO, NO, NO, MPRV,MPLY,MNXT,MUTE,VOLD,VOLU,DEL, NO, \
15 NO, NO, NO, NO, NO, NO, NO, PGUP,NO, NO, NO, NO, NO, NO, TRNS,\
16 FN2, NO, NO, PGDN,NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, NO, NO, \
17 TRNS,NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, TRNS, NO, NO, \
18 TRNS,TRNS,TRNS, NO, TRNS,TRNS,TRNS,NO, NO, NO \
19 ),
20 KEYMAP( \
21 NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \
22 NO, NO, NO, NO, END, NO, NO, NO, NO, NO, HOME,NO, NO, NO, NO, \
23 NO, BTN1,MS_U,BTN2,NO, NO, NO, PGUP,FN1, NO, NO, NO, NO, NO, TRNS,\
24 FN2, MS_L,MS_D,MS_R,NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, NO, NO, \
25 TRNS,NO, DEL, NO, NO, NO, NO, NO, NO, NO, NO, TRNS, NO, NO, \
26 TRNS,TRNS,TRNS, NO, TRNS,TRNS,TRNS,NO, NO, NO \
27 ),
28};
29
30const uint16_t PROGMEM fn_actions[] = {
31 [0] = ACTION_LAYER_MOMENTARY(1),
32 [1] = ACTION_LAYER_TOGGLE(2),
33 [2] = ACTION_MODS_TAP_KEY(MOD_LCTL, KC_ESC),
34};
diff --git a/keyboards/ps2avrGB/matrix.c b/keyboards/ps2avrGB/matrix.c
new file mode 100644
index 000000000..e487ca182
--- /dev/null
+++ b/keyboards/ps2avrGB/matrix.c
@@ -0,0 +1,105 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@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 <avr/io.h>
19#include <util/delay.h>
20
21#include "matrix.h"
22
23#ifndef DEBOUNCE
24# define DEBOUNCE 5
25#endif
26
27static uint8_t debouncing = DEBOUNCE;
28
29static matrix_row_t matrix[MATRIX_ROWS];
30static matrix_row_t matrix_debouncing[MATRIX_ROWS];
31
32void matrix_init(void) {
33 // all outputs for rows high
34 DDRB = 0xFF;
35 PORTB = 0xFF;
36 // all inputs for columns
37 DDRA = 0x00;
38 DDRC &= ~(0x111111<<2);
39 DDRD &= ~(1<<PIND7);
40 // all columns are pulled-up
41 PORTA = 0xFF;
42 PORTC |= (0b111111<<2);
43 PORTD |= (1<<PIND7);
44
45 // initialize matrix state: all keys off
46 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
47 matrix[row] = 0x00;
48 matrix_debouncing[row] = 0x00;
49 }
50}
51
52void matrix_set_row_status(uint8_t row) {
53 DDRB = (1 << row);
54 PORTB = ~(1 << row);
55}
56
57uint8_t bit_reverse(uint8_t x) {
58 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
59 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
60 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
61 return x;
62}
63
64uint8_t matrix_scan(void) {
65 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
66 matrix_set_row_status(row);
67 _delay_us(5);
68
69 matrix_row_t cols = (
70 // cols 0..7, PORTA 0 -> 7
71 (~PINA) & 0xFF
72 ) | (
73 // cols 8..13, PORTC 7 -> 0
74 bit_reverse((~PINC) & 0xFF) << 8
75 ) | (
76 // col 14, PORTD 7
77 ((~PIND) & (1 << PIND7)) << 7
78 );
79
80 if (matrix_debouncing[row] != cols) {
81 matrix_debouncing[row] = cols;
82 debouncing = DEBOUNCE;
83 }
84 }
85
86 if (debouncing) {
87 if (--debouncing) {
88 _delay_ms(1);
89 } else {
90 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
91 matrix[i] = matrix_debouncing[i];
92 }
93 }
94 }
95
96 return 1;
97}
98
99inline matrix_row_t matrix_get_row(uint8_t row) {
100 return matrix[row];
101}
102
103void matrix_print(void)
104{
105}
diff --git a/keyboards/ps2avrGB/program b/keyboards/ps2avrGB/program
new file mode 100755
index 000000000..a88d9cd9b
--- /dev/null
+++ b/keyboards/ps2avrGB/program
@@ -0,0 +1,74 @@
1#!/usr/bin/env python
2# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from __future__ import print_function
18
19import os
20import sys
21import time
22import usb
23
24if len(sys.argv) < 2:
25 print('Usage: %s <firmware.hex>' % sys.argv[0])
26 sys.exit(1)
27
28print('Searching for ps2avrGB... ', end='')
29
30dev = usb.core.find(idVendor=0x20A0, idProduct=0x422D)
31if dev is None:
32 raise ValueError('Device not found')
33
34print('Found', end='\n\n')
35
36print('Device Information:')
37print(' idVendor: %d (0x%04x)' % (dev.idVendor, dev.idVendor))
38print(' idProduct: %d (0x%04x)' % (dev.idProduct, dev.idProduct))
39print('Manufacturer: %s' % (dev.iManufacturer))
40print('Serial: %s' % (dev.iSerialNumber))
41print('Product: %s' % (dev.iProduct), end='\n\n')
42
43print('Transferring control to bootloader... ', end='')
44
45dev.set_configuration()
46
47request_type = usb.util.build_request_type(
48 usb.util.CTRL_OUT,
49 usb.util.CTRL_TYPE_CLASS,
50 usb.util.CTRL_RECIPIENT_DEVICE)
51
52USBRQ_HID_SET_REPORT = 0x09
53HID_REPORT_OPTION = 0x0301
54
55
56try:
57 dev.ctrl_transfer(
58 request_type,
59 USBRQ_HID_SET_REPORT,
60 HID_REPORT_OPTION,
61 0,
62 [0, 0, 0xFF] + [0] * 5
63 )
64except usb.core.USBError:
65 # for some reason I keep getting USBError, but it works!
66 pass
67
68# wait a bit until bootloader starts up
69time.sleep(2)
70
71print('OK')
72print('Programming...')
73if os.system('bootloadHID -r "%s"' % sys.argv[1]) == 0:
74 print('\nDone!')
diff --git a/keyboards/ps2avrGB/ps2avrGB.c b/keyboards/ps2avrGB/ps2avrGB.c
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/keyboards/ps2avrGB/ps2avrGB.c
diff --git a/keyboards/ps2avrGB/ps2avrGB.h b/keyboards/ps2avrGB/ps2avrGB.h
new file mode 100644
index 000000000..1da26adb2
--- /dev/null
+++ b/keyboards/ps2avrGB/ps2avrGB.h
@@ -0,0 +1,54 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@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#ifndef KEYMAP_COMMON_H
18#define KEYMAP_COMMON_H
19
20#include <stdint.h>
21#include <stdbool.h>
22#include "keycode.h"
23#include "action.h"
24#include "action_code.h"
25#include "action_layer.h"
26#include "action_macro.h"
27#include "action_util.h"
28#include "report.h"
29#include "host.h"
30#include "print.h"
31#include "debug.h"
32#include "keymap.h"
33
34
35#define KEYMAP( \
36 K05, K25, K35, K45, K55, K06, KA6, KA7, K07, KB5, KC5, KD5, KE5, KD1, KE1, KE2, \
37 K04, K14, K24, K34, K44, K54, K16, KB6, KB7, K17, KA4, KB4, KC4, KE4, KD0, \
38 K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC3, KD3, K67, \
39 K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KB2, KD2, KE0, \
40 K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KB1, K86, K77, \
41 K00, K10, K20, K56, K57, KB0, KC0, K66, K76, K96 \
42) \
43{ \
44 { KC_##K00, KC_##K10, KC_##K20, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KB0, KC_##KC0, KC_##KD0, KC_##KE0 }, \
45 { KC_##K01, KC_##K11, KC_##K21, KC_##K31, KC_##K41, KC_##K51, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA1, KC_##KB1, KC_NO, KC_##KD1, KC_##KE1 }, \
46 { KC_##K02, KC_##K12, KC_##K22, KC_##K32, KC_##K42, KC_##K52, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA2, KC_##KB2, KC_NO, KC_##KD2, KC_##KE2 }, \
47 { KC_##K03, KC_##K13, KC_##K23, KC_##K33, KC_##K43, KC_##K53, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA3, KC_##KB3, KC_##KC3, KC_##KD3, KC_NO }, \
48 { KC_##K04, KC_##K14, KC_##K24, KC_##K34, KC_##K44, KC_##K54, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KA4, KC_##KB4, KC_##KC4, KC_NO, KC_##KE4 }, \
49 { KC_##K05, KC_NO, KC_##K25, KC_##K35, KC_##K45, KC_##K55, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_##KB5, KC_##KC5, KC_##KD5, KC_##KE5 }, \
50 { KC_##K06, KC_##K16, KC_##K26, KC_##K36, KC_##K46, KC_##K56, KC_##K66, KC_##K76, KC_##K86, KC_##K96, KC_##KA6, KC_##KB6, KC_##KC6, KC_##KD6, KC_##KE6 }, \
51 { KC_##K07, KC_##K17, KC_##K27, KC_##K37, KC_##K47, KC_##K57, KC_##K67, KC_##K77, KC_NO, KC_NO, KC_##KA7, KC_##KB7, KC_##KC7, KC_##KD7, KC_##KE7 } \
52}
53
54#endif
diff --git a/keyboards/ps2avrGB/rules.mk b/keyboards/ps2avrGB/rules.mk
new file mode 100644
index 000000000..d747e8929
--- /dev/null
+++ b/keyboards/ps2avrGB/rules.mk
@@ -0,0 +1,38 @@
1# MCU name
2MCU = atmega32a
3
4PROTOCOL = VUSB
5
6# disable UART since atmega32a apparently doesn't have it
7NO_UART = yes
8# this simplifies things for now
9NO_SUSPEND_POWER_DOWN = yes
10
11# Processor frequency.
12# Normally the first thing your program should do is set the clock prescaler,
13# so your program will run at the correct speed. You should also set this
14# variable to same clock speed. The _delay_ms() macro uses this, and many
15# examples use this variable to calculate timings. Do not add a "UL" here.
16F_CPU = 12000000
17
18# Build Options
19# comment out to disable the options.
20#
21BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
22MOUSEKEY_ENABLE = yes # Mouse keys
23EXTRAKEY_ENABLE = yes # Audio control and System control
24CONSOLE_ENABLE = yes # Console for debug
25COMMAND_ENABLE = yes # Commands for debug and configuration
26#BACKLIGHT_ENABLE = yes
27
28# V-USB debug level: To use ps2_usart.c level must be 0
29# ps2_usart.c requires USART to receive PS/2 signal.
30OPT_DEFS = -DDEBUG_LEVEL=0
31OPS_DEFS += -DPROTOCOL_VUSB
32OPT_DEFS += -DBOOTLOADER_SIZE=2048
33
34CUSTOM_MATRIX = yes
35SRC = matrix.c
36
37#---------------- Programming Options --------------------------
38PROGRAM_CMD = ./keyboards/ps2avrGB/program $(TARGET).hex
diff --git a/keyboards/ps2avrGB/usbconfig.h b/keyboards/ps2avrGB/usbconfig.h
new file mode 100644
index 000000000..d2d848fcd
--- /dev/null
+++ b/keyboards/ps2avrGB/usbconfig.h
@@ -0,0 +1,396 @@
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.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 1
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 500
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 1
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, 0x02
242/* Version number of the device: Minor number first, then major number.
243 */
244#define USB_CFG_VENDOR_NAME 'w', 'i', 'n', 'k', 'e', 'y', 'l', 'e', 's', 's', '.', 'k', 'r'
245#define USB_CFG_VENDOR_NAME_LEN 13
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', 'a', 'v', 'r', 'G', 'B'
255#define USB_CFG_DEVICE_NAME_LEN 8
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#define usbMsgPtr_t unsigned short
362/* If usbMsgPtr_t is not defined, it defaults to 'uchar *'. We define it to
363 * a scalar type here because gcc generates slightly shorter code for scalar
364 * arithmetics than for pointer arithmetics. Remove this define for backward
365 * type compatibility or define it to an 8 bit type if you use data in RAM only
366 * and all RAM is below 256 bytes (tiny memory model in IAR CC).
367 */
368
369/* ----------------------- Optional MCU Description ------------------------ */
370
371/* The following configurations have working defaults in usbdrv.h. You
372 * usually don't need to set them explicitly. Only if you want to run
373 * the driver on a device which is not yet supported or with a compiler
374 * which is not fully supported (such as IAR C) or if you use a differnt
375 * interrupt than INT0, you may have to define some of these.
376 */
377/* #define USB_INTR_CFG MCUCR */
378/* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */
379/* #define USB_INTR_CFG_CLR 0 */
380/* #define USB_INTR_ENABLE GIMSK */
381/* #define USB_INTR_ENABLE_BIT INT0 */
382/* #define USB_INTR_PENDING GIFR */
383/* #define USB_INTR_PENDING_BIT INTF0 */
384/* #define USB_INTR_VECTOR INT0_vect */
385
386/* Set INT1 for D- falling edge to count SOF */
387/* #define USB_INTR_CFG EICRA */
388#define USB_INTR_CFG_SET ((1 << ISC11) | (0 << ISC10))
389/* #define USB_INTR_CFG_CLR 0 */
390/* #define USB_INTR_ENABLE EIMSK */
391#define USB_INTR_ENABLE_BIT INT1
392/* #define USB_INTR_PENDING EIFR */
393#define USB_INTR_PENDING_BIT INTF1
394#define USB_INTR_VECTOR INT1_vect
395
396#endif /* __usbconfig_h_included__ */
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 3c1373c08..a86dccc61 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -80,6 +80,14 @@ ifeq ($(strip $(SLEEP_LED_ENABLE)), yes)
80 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN 80 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
81endif 81endif
82 82
83ifeq ($(strip $(NO_UART)), yes)
84 TMK_COMMON_DEFS += -DNO_UART
85endif
86
87ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes)
88 TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
89endif
90
83ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) 91ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
84 TMK_COMMON_SRC += $(COMMON_DIR)/backlight.c 92 TMK_COMMON_SRC += $(COMMON_DIR)/backlight.c
85 TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE 93 TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c
index ad547b985..98a24d178 100644
--- a/tmk_core/common/avr/bootloader.c
+++ b/tmk_core/common/avr/bootloader.c
@@ -1,6 +1,7 @@
1#include <stdint.h> 1#include <stdint.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <avr/io.h> 3#include <avr/io.h>
4#include <avr/eeprom.h>
4#include <avr/interrupt.h> 5#include <avr/interrupt.h>
5#include <avr/wdt.h> 6#include <avr/wdt.h>
6#include <util/delay.h> 7#include <util/delay.h>
@@ -89,6 +90,10 @@ void bootloader_jump(void) {
89 _delay_ms(5); 90 _delay_ms(5);
90 #endif 91 #endif
91 92
93 #ifdef EEPROM_BOOTLOADER_START
94 eeprom_write_byte((uint8_t *)EEPROM_BOOTLOADER_START, 0x00);
95 #endif
96
92 // watchdog reset 97 // watchdog reset
93 reset_key = BOOTLOADER_RESET_KEY; 98 reset_key = BOOTLOADER_RESET_KEY;
94 wdt_enable(WDTO_250MS); 99 wdt_enable(WDTO_250MS);
@@ -114,6 +119,11 @@ void bootloader_jump(void) {
114 #endif 119 #endif
115} 120}
116 121
122#ifdef __AVR_ATmega32A__
123// MCUSR is actually called MCUCSR in ATmega32A
124#define MCUSR MCUCSR
125#endif
126
117/* this runs before main() */ 127/* this runs before main() */
118void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); 128void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3")));
119void bootloader_jump_after_watchdog_reset(void) 129void bootloader_jump_after_watchdog_reset(void)
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 0c81e8361..0e97892d9 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -65,6 +65,7 @@ static uint8_t wdt_timeout = 0;
65 65
66static void power_down(uint8_t wdto) 66static void power_down(uint8_t wdto)
67{ 67{
68#ifndef __AVR_ATmega32A__
68#ifdef PROTOCOL_LUFA 69#ifdef PROTOCOL_LUFA
69 if (USB_DeviceState == DEVICE_STATE_Configured) return; 70 if (USB_DeviceState == DEVICE_STATE_Configured) return;
70#endif 71#endif
@@ -99,6 +100,7 @@ static void power_down(uint8_t wdto)
99 100
100 // Disable watchdog after sleep 101 // Disable watchdog after sleep
101 wdt_disable(); 102 wdt_disable();
103#endif
102} 104}
103#endif 105#endif
104 106
diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c
index 84af44488..369015200 100644
--- a/tmk_core/common/avr/timer.c
+++ b/tmk_core/common/avr/timer.c
@@ -29,25 +29,35 @@ volatile uint32_t timer_count;
29 29
30void timer_init(void) 30void timer_init(void)
31{ 31{
32 // Timer0 CTC mode
33 TCCR0A = 0x02;
34
35#if TIMER_PRESCALER == 1 32#if TIMER_PRESCALER == 1
36 TCCR0B = 0x01; 33 uint8_t prescaler = 0x01;
37#elif TIMER_PRESCALER == 8 34#elif TIMER_PRESCALER == 8
38 TCCR0B = 0x02; 35 uint8_t prescaler = 0x02;
39#elif TIMER_PRESCALER == 64 36#elif TIMER_PRESCALER == 64
40 TCCR0B = 0x03; 37 uint8_t prescaler = 0x03;
41#elif TIMER_PRESCALER == 256 38#elif TIMER_PRESCALER == 256
42 TCCR0B = 0x04; 39 uint8_t prescaler = 0x04;
43#elif TIMER_PRESCALER == 1024 40#elif TIMER_PRESCALER == 1024
44 TCCR0B = 0x05; 41 uint8_t prescaler = 0x05;
45#else 42#else
46# error "Timer prescaler value is NOT vaild." 43# error "Timer prescaler value is NOT vaild."
47#endif 44#endif
48 45
46#ifndef __AVR_ATmega32A__
47 // Timer0 CTC mode
48 TCCR0A = 0x02;
49
50 TCCR0B = prescaler;
51
49 OCR0A = TIMER_RAW_TOP; 52 OCR0A = TIMER_RAW_TOP;
50 TIMSK0 = (1<<OCIE0A); 53 TIMSK0 = (1<<OCIE0A);
54#else
55 // Timer0 CTC mode
56 TCCR0 = (1 << WGM01) | prescaler;
57
58 OCR0 = TIMER_RAW_TOP;
59 TIMSK = (1 << OCIE0);
60#endif
51} 61}
52 62
53inline 63inline
@@ -107,7 +117,12 @@ uint32_t timer_elapsed32(uint32_t last)
107} 117}
108 118
109// excecuted once per 1ms.(excess for just timer count?) 119// excecuted once per 1ms.(excess for just timer count?)
110ISR(TIMER0_COMPA_vect) 120#ifndef __AVR_ATmega32A__
121#define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect
122#else
123#define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect
124#endif
125ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK)
111{ 126{
112 timer_count++; 127 timer_count++;
113} 128}
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 5f29bc0b4..beba768ec 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -235,8 +235,10 @@ static void print_status(void)
235 print("\n\t- Status -\n"); 235 print("\n\t- Status -\n");
236 236
237 print_val_hex8(host_keyboard_leds()); 237 print_val_hex8(host_keyboard_leds());
238#ifndef PROTOCOL_VUSB
238 print_val_hex8(keyboard_protocol); 239 print_val_hex8(keyboard_protocol);
239 print_val_hex8(keyboard_idle); 240 print_val_hex8(keyboard_idle);
241#endif
240#ifdef NKRO_ENABLE 242#ifdef NKRO_ENABLE
241 print_val_hex8(keymap_config.nkro); 243 print_val_hex8(keymap_config.nkro);
242#endif 244#endif
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index 3cba3f71a..4d90510af 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -2,7 +2,7 @@ VUSB_DIR = protocol/vusb
2 2
3OPT_DEFS += -DPROTOCOL_VUSB 3OPT_DEFS += -DPROTOCOL_VUSB
4 4
5SRC += $(VUSB_DIR)/main.c \ 5SRC += $(VUSB_DIR)/main.c \
6 $(VUSB_DIR)/vusb.c \ 6 $(VUSB_DIR)/vusb.c \
7 $(VUSB_DIR)/usbdrv/usbdrv.c \ 7 $(VUSB_DIR)/usbdrv/usbdrv.c \
8 $(VUSB_DIR)/usbdrv/usbdrvasm.S \ 8 $(VUSB_DIR)/usbdrv/usbdrvasm.S \
@@ -16,6 +16,7 @@ SRC += $(COMMON_DIR)/sendchar_uart.c \
16 $(COMMON_DIR)/uart.c 16 $(COMMON_DIR)/uart.c
17endif 17endif
18 18
19
20# Search Path 19# Search Path
21VPATH += $(TMK_DIR)/protocol/vusb:$(TMK_DIR)/protocol/vusb/usbdrv 20#VPATH += $(TMK_PATH)/$(VUSB_DIR)
21VPATH += $(TMK_PATH)/$(VUSB_DIR)
22VPATH += $(TMK_PATH)/$(VUSB_DIR)/usbdrv
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index 8e4a266e9..f6a0c7e9a 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -48,8 +48,12 @@ int main(void)
48 uint16_t last_timer = timer_read(); 48 uint16_t last_timer = timer_read();
49#endif 49#endif
50 50
51#ifdef CLKPR
52 // avoid unintentional changes of clock frequency in devices that have a
53 // clock prescaler
51 CLKPR = 0x80, CLKPR = 0; 54 CLKPR = 0x80, CLKPR = 0;
52#ifndef PS2_USE_USART 55#endif
56#ifndef NO_UART
53 uart_init(UART_BAUD_RATE); 57 uart_init(UART_BAUD_RATE);
54#endif 58#endif
55 59
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index eaa1c512d..a8c13b928 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -15,6 +15,8 @@ You 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 17
18#include <avr/eeprom.h>
19#include <avr/wdt.h>
18#include <stdint.h> 20#include <stdint.h>
19#include "usbdrv.h" 21#include "usbdrv.h"
20#include "usbconfig.h" 22#include "usbconfig.h"
@@ -24,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24#include "debug.h" 26#include "debug.h"
25#include "host_driver.h" 27#include "host_driver.h"
26#include "vusb.h" 28#include "vusb.h"
29#include "bootloader.h"
27 30
28 31
29static uint8_t vusb_keyboard_leds = 0; 32static uint8_t vusb_keyboard_leds = 0;
@@ -163,6 +166,7 @@ static struct {
163 uint16_t len; 166 uint16_t len;
164 enum { 167 enum {
165 NONE, 168 NONE,
169 BOOTLOADER,
166 SET_LED 170 SET_LED
167 } kind; 171 } kind;
168} last_req; 172} last_req;
@@ -193,6 +197,11 @@ usbRequest_t *rq = (void *)data;
193 debug("SET_LED: "); 197 debug("SET_LED: ");
194 last_req.kind = SET_LED; 198 last_req.kind = SET_LED;
195 last_req.len = rq->wLength.word; 199 last_req.len = rq->wLength.word;
200#ifdef BOOTLOADER_SIZE
201 } else if(rq->wValue.word == 0x0301) {
202 last_req.kind = BOOTLOADER;
203 last_req.len = rq->wLength.word;
204#endif
196 } 205 }
197 return USB_NO_MSG; // to get data in usbFunctionWrite 206 return USB_NO_MSG; // to get data in usbFunctionWrite
198 } else { 207 } else {
@@ -220,6 +229,11 @@ uchar usbFunctionWrite(uchar *data, uchar len)
220 last_req.len = 0; 229 last_req.len = 0;
221 return 1; 230 return 1;
222 break; 231 break;
232 case BOOTLOADER:
233 usbDeviceDisconnect();
234 bootloader_jump();
235 return 1;
236 break;
223 case NONE: 237 case NONE:
224 default: 238 default:
225 return -1; 239 return -1;
@@ -266,7 +280,7 @@ const PROGMEM uchar keyboard_hid_report[] = {
266 0x95, 0x06, // Report Count (6), 280 0x95, 0x06, // Report Count (6),
267 0x75, 0x08, // Report Size (8), 281 0x75, 0x08, // Report Size (8),
268 0x15, 0x00, // Logical Minimum (0), 282 0x15, 0x00, // Logical Minimum (0),
269 0x25, 0xFF, 0x00 // Logical Maximum(255), 283 0x25, 0xFF, 0x00, // Logical Maximum(255),
270 0x05, 0x07, // Usage Page (Key Codes), 284 0x05, 0x07, // Usage Page (Key Codes),
271 0x19, 0x00, // Usage Minimum (0), 285 0x19, 0x00, // Usage Minimum (0),
272 0x29, 0xFF, // Usage Maximum (255), 286 0x29, 0xFF, // Usage Maximum (255),
@@ -336,7 +350,7 @@ const PROGMEM uchar mouse_hid_report[] = {
336 0xa1, 0x01, // COLLECTION (Application) 350 0xa1, 0x01, // COLLECTION (Application)
337 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) 351 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2)
338 0x15, 0x01, // LOGICAL_MINIMUM (0x1) 352 0x15, 0x01, // LOGICAL_MINIMUM (0x1)
339 0x25, 0xb7, 0x00 // LOGICAL_MAXIMUM (0xb7) 353 0x25, 0xb7, 0x00, // LOGICAL_MAXIMUM (0xb7)
340 0x19, 0x01, // USAGE_MINIMUM (0x1) 354 0x19, 0x01, // USAGE_MINIMUM (0x1)
341 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) 355 0x29, 0xb7, // USAGE_MAXIMUM (0xb7)
342 0x75, 0x10, // REPORT_SIZE (16) 356 0x75, 0x10, // REPORT_SIZE (16)
@@ -481,11 +495,11 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq)
481 /* interface index */ 495 /* interface index */
482 switch (rq->wIndex.word) { 496 switch (rq->wIndex.word) {
483 case 0: 497 case 0:
484 usbMsgPtr = keyboard_hid_report; 498 usbMsgPtr = (unsigned char *)keyboard_hid_report;
485 len = sizeof(keyboard_hid_report); 499 len = sizeof(keyboard_hid_report);
486 break; 500 break;
487 case 1: 501 case 1:
488 usbMsgPtr = mouse_hid_report; 502 usbMsgPtr = (unsigned char *)mouse_hid_report;
489 len = sizeof(mouse_hid_report); 503 len = sizeof(mouse_hid_report);
490 break; 504 break;
491 } 505 }