aboutsummaryrefslogtreecommitdiff
path: root/keyboard/hid_liber
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard/hid_liber')
-rw-r--r--keyboard/hid_liber/Makefile.lufa120
-rw-r--r--keyboard/hid_liber/Makefile.pjrc90
-rw-r--r--keyboard/hid_liber/config.h56
-rw-r--r--keyboard/hid_liber/keymap.c195
-rw-r--r--keyboard/hid_liber/led.c34
-rw-r--r--keyboard/hid_liber/matrix.c234
6 files changed, 729 insertions, 0 deletions
diff --git a/keyboard/hid_liber/Makefile.lufa b/keyboard/hid_liber/Makefile.lufa
new file mode 100644
index 000000000..2d560b9a6
--- /dev/null
+++ b/keyboard/hid_liber/Makefile.lufa
@@ -0,0 +1,120 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = hid_liber_lufa
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50
51# List C source files here. (C dependencies are automatically generated.)
52SRC += keymap.c \
53 matrix.c \
54 led.c
55
56CONFIG_H = config.h
57
58
59# MCU name
60#MCU = at90usb1287
61MCU = atmega32u4
62
63# Processor frequency.
64# This will define a symbol, F_CPU, in all source code files equal to the
65# processor frequency in Hz. You can then use this symbol in your source code to
66# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
67# automatically to create a 32-bit value in your source code.
68#
69# This will be an integer division of F_USB below, as it is sourced by
70# F_USB after it has run through any CPU prescalers. Note that this value
71# does not *change* the processor frequency - it should merely be updated to
72# reflect the processor speed set externally so that the code can use accurate
73# software delays.
74F_CPU = 16000000
75
76
77#
78# LUFA specific
79#
80# Target architecture (see library "Board Types" documentation).
81ARCH = AVR8
82
83# Input clock frequency.
84# This will define a symbol, F_USB, in all source code files equal to the
85# input clock frequency (before any prescaling is performed) in Hz. This value may
86# differ from F_CPU if prescaling is used on the latter, and is required as the
87# raw input clock is fed directly to the PLL sections of the AVR for high speed
88# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
89# at the end, this will be done automatically to create a 32-bit value in your
90# source code.
91#
92# If no clock division is performed on the input clock inside the AVR (via the
93# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
94F_USB = $(F_CPU)
95
96
97# Build Options
98# comment out to disable the options.
99#
100#MOUSEKEY_ENABLE = yes # Mouse keys
101EXTRAKEY_ENABLE = yes # Audio control and System control
102CONSOLE_ENABLE = yes # Console for debug
103#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
104#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
105
106
107# Boot Section Size in bytes
108# Teensy halfKay 512
109# Atmel DFU loader 4096
110# LUFA bootloader 4096
111OPT_DEFS += -DBOOT_SIZE=4096
112
113
114# Search Path
115VPATH += $(TARGET_DIR)
116VPATH += $(TOP_DIR)
117
118include $(TOP_DIR)/protocol/lufa.mk
119include $(TOP_DIR)/common.mk
120include $(TOP_DIR)/rules.mk
diff --git a/keyboard/hid_liber/Makefile.pjrc b/keyboard/hid_liber/Makefile.pjrc
new file mode 100644
index 000000000..8e349c8da
--- /dev/null
+++ b/keyboard/hid_liber/Makefile.pjrc
@@ -0,0 +1,90 @@
1#----------------------------------------------------------------------------
2# On command line:
3#
4# make all = Make software.
5#
6# make clean = Clean out built project files.
7#
8# make coff = Convert ELF to AVR COFF.
9#
10# make extcoff = Convert ELF to AVR Extended COFF.
11#
12# make program = Download the hex file to the device.
13# Please customize your programmer settings(PROGRAM_CMD)
14#
15# make teensy = Download the hex file to the device, using teensy_loader_cli.
16# (must have teensy_loader_cli installed).
17#
18# make dfu = Download the hex file to the device, using dfu-programmer (must
19# have dfu-programmer installed).
20#
21# make flip = Download the hex file to the device, using Atmel FLIP (must
22# have Atmel FLIP installed).
23#
24# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
25# (must have dfu-programmer installed).
26#
27# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
28# (must have Atmel FLIP installed).
29#
30# make debug = Start either simulavr or avarice as specified for debugging,
31# with avr-gdb or avr-insight as the front end for debugging.
32#
33# make filename.s = Just compile filename.c into the assembler code only.
34#
35# make filename.i = Create a preprocessed source file for use in submitting
36# bug reports to the GCC project.
37#
38# To rebuild project do "make clean" then "make all".
39#----------------------------------------------------------------------------
40
41# Target file name (without extension).
42TARGET = hid_liber_pjrc
43
44# Directory common source filess exist
45TOP_DIR = ../..
46
47# Directory keyboard dependent files exist
48TARGET_DIR = .
49
50# keyboard dependent files
51SRC = keymap.c \
52 matrix.c \
53 led.c
54
55CONFIG_H = config.h
56
57
58# MCU name, you MUST set this to match the board you are using
59# type "make clean" after changing this, so all files will be rebuilt
60#MCU = at90usb162 # Teensy 1.0
61MCU = atmega32u4 # Teensy 2.0
62#MCU = at90usb646 # Teensy++ 1.0
63#MCU = at90usb1286 # Teensy++ 2.0
64
65
66# Processor frequency.
67# Normally the first thing your program should do is set the clock prescaler,
68# so your program will run at the correct speed. You should also set this
69# variable to same clock speed. The _delay_ms() macro uses this, and many
70# examples use this variable to calculate timings. Do not add a "UL" here.
71F_CPU = 16000000
72
73
74# Build Options
75# comment out to disable the options.
76#
77#MOUSEKEY_ENABLE = yes # Mouse keys
78#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
79EXTRAKEY_ENABLE = yes # Audio control and System control
80NKRO_ENABLE = yes # USB Nkey Rollover
81CONSOLE_ENABLE = yes # Console for debug
82
83
84# Search Path
85VPATH += $(TARGET_DIR)
86VPATH += $(TOP_DIR)
87
88include $(TOP_DIR)/protocol/pjrc.mk
89include $(TOP_DIR)/common.mk
90include $(TOP_DIR)/rules.mk
diff --git a/keyboard/hid_liber/config.h b/keyboard/hid_liber/config.h
new file mode 100644
index 000000000..a9b77c7dc
--- /dev/null
+++ b/keyboard/hid_liber/config.h
@@ -0,0 +1,56 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21
22/* USB Device descriptor parameter */
23#define VENDOR_ID 0xFEED
24#define PRODUCT_ID 0xB919
25#define DEVICE_VER 0x0001
26#define MANUFACTURER t.m.k.
27#define PRODUCT HID Liberation
28
29
30/* message strings */
31#define DESCRIPTION t.m.k. keyboard firmware for HID Liberation
32
33
34/* matrix size */
35#define MATRIX_ROWS 18
36#define MATRIX_COLS 8
37
38/* define if matrix has ghost */
39//#define MATRIX_HAS_GHOST
40
41/* Set 0 if need no debouncing */
42#define DEBOUNCE 8
43
44
45/* key combination for command */
46#define IS_COMMAND() ( \
47 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
48)
49
50// TODO: configurable
51#define DEBUG_LED 0
52#define DEBUG_LED_CONFIG
53#define DEBUG_LED_ON
54#define DEBUG_LED_OFF
55
56#endif
diff --git a/keyboard/hid_liber/keymap.c b/keyboard/hid_liber/keymap.c
new file mode 100644
index 000000000..e35f7245d
--- /dev/null
+++ b/keyboard/hid_liber/keymap.c
@@ -0,0 +1,195 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * Keymap for HID Liberator controller
20 */
21#include <stdint.h>
22#include <stdbool.h>
23#include <avr/pgmspace.h>
24#include "keycode.h"
25#include "print.h"
26#include "debug.h"
27#include "util.h"
28#include "keymap.h"
29
30
31// Convert physical keyboard layout to matrix array.
32// This is a macro to define keymap easily in keyboard layout form.
33#define KEYMAP( \
34 KG1, KH7, KJ7, KJ6, KJ1, KO5, KL1, KA6, KA7, KD7, KD5, KD1, KD2, KB5, KB3, KO3, \
35 KG7, KG5, KH5, KJ5, KI5, KI7, KK7, KK5, KL5, KA5, KC5, KC7, KL7, KD6, KQ7, KN7, KM7, \
36 KG6, KG3, KH3, KJ3, KI3, KI6, KK6, KK3, KL3, KA3, KC3, KC6, KL6, KD4, KP7, KN5, KM5, \
37 KH6, KG4, KH4, KJ4, KI4, KI1, KK1, KK4, KL4, KA4, KC4, KC1, KD0, \
38 KF6, KH1, KG0, KH0, KJ0, KI0, KI2, KK2, KK0, KL0, KA0, KC2, KF4, KN1, \
39 KO7, KE6, KB1, KP1, KB2, KR4, KA2, KO0, KN2, KP2, KQ2 \
40) { \
41/* 0 1 2 3 4 5 6 7 */ \
42/* A */ { KC_##KA0, KC_NO , KC_##KA2, KC_##KA3, KC_##KA4, KC_##KA5, KC_##KA6, KC_##KA7 }, \
43/* B */ { KC_NO , KC_##KB1, KC_##KB2, KC_##KB3, KC_NO , KC_##KB5, KC_NO , KC_NO }, \
44/* C */ { KC_NO , KC_##KC1, KC_##KC2, KC_##KC3, KC_##KC4, KC_##KC5, KC_##KC6, KC_##KC7 }, \
45/* D */ { KC_##KD0, KC_##KD1, KC_##KD2, KC_NO , KC_##KD4, KC_##KD5, KC_##KD6, KC_##KD7 }, \
46/* E */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KE6, KC_NO }, \
47/* F */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KF4, KC_NO , KC_##KF6, KC_NO }, \
48/* G */ { KC_##KG0, KC_##KG1, KC_NO , KC_##KG3, KC_##KG4, KC_##KG5, KC_##KG6, KC_##KG7 }, \
49/* H */ { KC_##KH0, KC_##KH1, KC_NO , KC_##KH3, KC_##KH4, KC_##KH5, KC_##KH6, KC_##KH7 }, \
50/* I */ { KC_##KI0, KC_##KI1, KC_##KI2, KC_##KI3, KC_##KI4, KC_##KI5, KC_##KI6, KC_##KI7 }, \
51/* J */ { KC_##KJ0, KC_##KJ1, KC_NO , KC_##KJ3, KC_##KJ4, KC_##KJ5, KC_##KJ6, KC_##KJ7 }, \
52/* K */ { KC_##KK0, KC_##KK1, KC_##KK2, KC_##KK3, KC_##KK4, KC_##KK5, KC_##KK6, KC_##KK7 }, \
53/* L */ { KC_##KL0, KC_##KL1, KC_NO , KC_##KL3, KC_##KL4, KC_##KL5, KC_##KL6, KC_##KL7 }, \
54/* M */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_##KM5, KC_NO , KC_##KM7 }, \
55/* N */ { KC_NO , KC_##KN1, KC_##KN2, KC_NO , KC_NO , KC_##KN5, KC_NO , KC_##KN7 }, \
56/* O */ { KC_##KO0, KC_NO , KC_NO , KC_##KO3, KC_NO , KC_##KO5, KC_NO , KC_##KO7 }, \
57/* P */ { KC_NO , KC_##KP1, KC_##KP2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KP7 }, \
58/* Q */ { KC_NO , KC_NO , KC_##KQ2, KC_NO , KC_NO , KC_NO , KC_NO , KC_##KQ7 }, \
59/* R */ { KC_NO , KC_NO , KC_NO , KC_NO , KC_##KR4, KC_NO , KC_NO , KC_NO } \
60}
61
62#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)]))
63
64
65// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed.
66static const uint8_t PROGMEM fn_layer[] = {
67 0, // Fn0
68 1, // Fn1
69 2, // Fn2
70 3, // Fn3
71 4, // Fn4
72 5, // Fn5
73 6, // Fn6
74 7 // Fn7
75};
76
77// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer.
78// See layer.c for details.
79static const uint8_t PROGMEM fn_keycode[] = {
80 KC_NO, // Fn0
81 KC_NO, // Fn1
82 KC_NO, // Fn2
83 KC_NO, // Fn3
84 KC_NO, // Fn4
85 KC_NO, // Fn5
86 KC_NO, // Fn6
87 KC_NO // Fn7
88};
89
90/*
91 * Tenkeyless keyboard default layout, ISO & ANSI (ISO is between Left Shift
92 * and Z, and the ANSI \ key above Return/Enter is used for the additional ISO
93 * switch in the ASD row next to enter. Use NUBS as keycode for the first and
94 * NUHS as the keycode for the second.
95 *
96 * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
97 * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|
98 * `---' `---------------' `---------------' `---------------' `-----------'
99 * ,-----------------------------------------------------------. ,-----------.
100 * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU|
101 * |-----------------------------------------------------------| |-----------|
102 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD|
103 * |-----------------------------------------------------------| `-----------'
104 * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return |
105 * |-----------------------------------------------------------| ,---.
106 * |Shft|ISO| Z| X| C| V| B| N| M| ,| .| /|Shift | |Up |
107 * |-----------------------------------------------------------| ,-----------.
108 * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
109 * `-----------------------------------------------------------' `-----------'
110 */
111
112
113static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
114/* Layer 0: Default Layer
115 *
116 * ANSI:
117 *
118 * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
119 * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|
120 * `---' `---------------' `---------------' `---------------' `-----------'
121 * ,-----------------------------------------------------------. ,-----------.
122 * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |Ins|Hom|PgU|
123 * |-----------------------------------------------------------| |-----------|
124 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD|
125 * |-----------------------------------------------------------| `-----------'
126 * |FN1 | A| S| D| F| G| H| J| K| L| ;| '|Return |
127 * |-----------------------------------------------------------| ,---.
128 * |Shft|iso| Z| X| C| V| B| N| M| ,| .| /|Shift | |Up |
129 * |-----------------------------------------------------------| ,-----------.
130 * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
131 * `-----------------------------------------------------------' `-----------'
132 */
133
134 KEYMAP(\
135 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR, SLCK, BRK, \
136 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, INS, HOME, PGUP, \
137 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, BSLS, DEL, END, PGDN, \
138 FN1, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, \
139 LSFT, NUBS, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, UP, \
140 LCTL, LGUI, LALT, SPC, RALT, RGUI, APP, RCTL, LEFT, DOWN, RGHT),
141
142/* EXAMPLE ISO keymap, see the NUBS and NUHS keycodes
143 * KEYMAP(\
144 * ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR, SLCK, BRK, \
145 * GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC, INS, HOME, PGUP, \
146 * TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC, RBRC, NUHS, DEL, END, PGDN, \
147 * CAPS, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, \
148 * LSFT, NUBS, Z, X, C, V, B, N, M, COMM, DOT, SLSH, RSFT, UP, \
149 * LCTL, FN1, LALT, SPC, RALT, RGUI, APP, RCTL, LEFT, DOWN, RGHT),
150 */
151
152
153/*
154 * ,---. ,---------------. ,---------------. ,---------------. ,-----------.
155 * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Slp|
156 * `---' `---------------' `---------------' `---------------' `-----------'
157 * ,-----------------------------------------------------------. ,-----------.
158 * |~ | 1| 2| 3| 4| 5| 6| 7| 8| 9|Mut|V- |V+ |Backsp | |Ins|Hom|PgU|
159 * |-----------------------------------------------------------| |-----------|
160 * |Tab | Q| W| E| R| T| Y| U| I|MSt|Ply|Prv|Nxt|Media| |Del|End|PgD|
161 * |-----------------------------------------------------------| `-----------'
162 * |FN1 | A| S| D| F| G| H| J| K| L| ;| '|Return |
163 * |-----------------------------------------------------------| ,---.
164 * |Shft|iso| Z| X|Clc| V| B| N| M| ,| .| /|Caps | |Up |
165 * |-----------------------------------------------------------| ,-----------.
166 * |Ctl|Gui|Alt| Space |Alt|Gui|App|Ctl| |Lef|Dow|Rig|
167 * `-----------------------------------------------------------' `-----------'
168 */
169
170 KEYMAP(\
171 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR, SLCK, SLEP, \
172 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9,MUTE, VOLD, VOLU, BSPC, INS, HOME, PGUP, \
173 TAB, Q, W, E, R, T, Y, U, I,MSTP,MPLY, MPRV, MNXT, MSEL, DEL, END, PGDN, \
174 FN1, A, S, D, F, G, H, J, K, L, SCLN, QUOT, ENT, \
175 LSFT, NUBS, Z, X,CALC, V, B, N, M, COMM, DOT, SLSH, CAPS, UP, \
176 LCTL, LGUI, LALT, SPC, RALT, RGUI, APP, RCTL, LEFT, DOWN, RGHT),
177
178
179};
180
181
182uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
183{
184 return KEYCODE(layer, row, col);
185}
186
187uint8_t keymap_fn_layer(uint8_t index)
188{
189 return pgm_read_byte(&fn_layer[index]);
190}
191
192uint8_t keymap_fn_keycode(uint8_t index)
193{
194 return pgm_read_byte(&fn_keycode[index]);
195}
diff --git a/keyboard/hid_liber/led.c b/keyboard/hid_liber/led.c
new file mode 100644
index 000000000..e577424c5
--- /dev/null
+++ b/keyboard/hid_liber/led.c
@@ -0,0 +1,34 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <avr/io.h>
19#include "stdint.h"
20#include "led.h"
21
22
23void led_set(uint8_t usb_led)
24{
25 if (usb_led & (1<<USB_LED_CAPS_LOCK))
26 PORTB &= ~(1<<5);
27 else
28 PORTB |= (1<<5);
29
30 if (usb_led & (1<<USB_LED_SCROLL_LOCK))
31 PORTB &= ~(1<<6);
32 else
33 PORTB |= (1<<6);
34}
diff --git a/keyboard/hid_liber/matrix.c b/keyboard/hid_liber/matrix.c
new file mode 100644
index 000000000..2d939ef63
--- /dev/null
+++ b/keyboard/hid_liber/matrix.c
@@ -0,0 +1,234 @@
1/* Copyright 2012 Jun Wako <wakojun@gmail.com>
2 *
3 * This is heavily based on hid_liber/board.{c|h}.
4 * https://github.com/BathroomEpiphanies/AVR-Keyboard
5 *
6 * Copyright (c) 2012 Fredrik Atmer, Bathroom Epiphanies Inc
7 * http://bathroomepiphanies.com
8 *
9 * As for liscensing consult with the original files or its author.
10 */
11#include <stdint.h>
12#include <stdbool.h>
13#include <avr/io.h>
14#include <util/delay.h>
15#include "print.h"
16#include "debug.h"
17#include "util.h"
18#include "matrix.h"
19
20
21#ifndef DEBOUNCE
22# define DEBOUNCE 0
23#endif
24static uint8_t debouncing = DEBOUNCE;
25
26// bit array of key state(1:on, 0:off)
27static matrix_row_t *matrix;
28static matrix_row_t *matrix_debounced;
29static matrix_row_t _matrix0[MATRIX_ROWS];
30static matrix_row_t _matrix1[MATRIX_ROWS];
31
32
33#define _DDRA (uint8_t *const)&DDRA
34#define _DDRB (uint8_t *const)&DDRB
35#define _DDRC (uint8_t *const)&DDRC
36#define _DDRD (uint8_t *const)&DDRD
37#define _DDRE (uint8_t *const)&DDRE
38#define _DDRF (uint8_t *const)&DDRF
39
40#define _PINA (uint8_t *const)&PINA
41#define _PINB (uint8_t *const)&PINB
42#define _PINC (uint8_t *const)&PINC
43#define _PIND (uint8_t *const)&PIND
44#define _PINE (uint8_t *const)&PINE
45#define _PINF (uint8_t *const)&PINF
46
47#define _PORTA (uint8_t *const)&PORTA
48#define _PORTB (uint8_t *const)&PORTB
49#define _PORTC (uint8_t *const)&PORTC
50#define _PORTD (uint8_t *const)&PORTD
51#define _PORTE (uint8_t *const)&PORTE
52#define _PORTF (uint8_t *const)&PORTF
53
54#define _BIT0 0x01
55#define _BIT1 0x02
56#define _BIT2 0x04
57#define _BIT3 0x08
58#define _BIT4 0x10
59#define _BIT5 0x20
60#define _BIT6 0x40
61#define _BIT7 0x80
62
63/* Specifies the ports and pin numbers for the rows */
64static
65uint8_t *const row_ddr[MATRIX_ROWS] = {
66 _DDRB, _DDRB,
67 _DDRC, _DDRC,
68 _DDRD, _DDRD, _DDRD, _DDRD, _DDRD, _DDRD, _DDRD, _DDRD,
69 _DDRF, _DDRF, _DDRF, _DDRF, _DDRF, _DDRF};
70
71static
72uint8_t *const row_port[MATRIX_ROWS] = {
73 _PORTB, _PORTB,
74 _PORTC, _PORTC,
75 _PORTD, _PORTD, _PORTD, _PORTD, _PORTD, _PORTD, _PORTD, _PORTD,
76 _PORTF, _PORTF, _PORTF, _PORTF, _PORTF, _PORTF};
77
78static
79uint8_t *const row_pin[MATRIX_ROWS] = {
80 _PINB, _PINB,
81 _PINC, _PINC,
82 _PIND, _PIND, _PIND, _PIND, _PIND, _PIND, _PIND, _PIND,
83 _PINF, _PINF, _PINF, _PINF, _PINF, _PINF};
84
85static
86const uint8_t row_bit[MATRIX_ROWS] = {
87 _BIT4, _BIT7,
88 _BIT6, _BIT7,
89 _BIT0, _BIT1, _BIT2, _BIT3, _BIT4, _BIT5, _BIT6, _BIT7,
90 _BIT0, _BIT1, _BIT4, _BIT5, _BIT6, _BIT7};
91
92static
93const uint8_t mask = 0x0E;
94
95/* Specifies the ports and pin numbers for the columns */
96static
97const uint8_t col_bit[MATRIX_COLS] = { 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E};
98
99static
100inline void pull_column(int col) {
101 PORTB = col_bit[col] | (PORTB & ~mask);
102}
103
104static
105inline void release_column(int col) {
106}
107
108/* PORTB is set as input with pull-up resistors
109 PORTC,D,E,F are set to high output */
110static
111void setup_io_pins(void) {
112 uint8_t row;
113 DDRB |= 0x0E;
114 PORTB &= ~0x0E;
115 for(row = 0; row < MATRIX_ROWS; row++) {
116 *row_ddr[row] &= ~row_bit[row];
117 *row_port[row] &= ~row_bit[row];
118 }
119}
120
121static
122void setup_leds(void) {
123 DDRB |= 0x60;
124 PORTB |= 0x60;
125}
126
127
128inline
129uint8_t matrix_rows(void)
130{
131 return MATRIX_ROWS;
132}
133
134inline
135uint8_t matrix_cols(void)
136{
137 return MATRIX_COLS;
138}
139
140void matrix_init(void)
141{
142 // To use PORTF disable JTAG with writing JTD bit twice within four cycles.
143 MCUCR |= (1<<JTD);
144 MCUCR |= (1<<JTD);
145
146 // initialize row and col
147 setup_io_pins();
148 setup_leds();
149
150 // initialize matrix state: all keys off
151 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
152 for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
153 matrix = _matrix0;
154 matrix_debounced = _matrix1;
155}
156
157uint8_t matrix_scan(void)
158{
159 if (!debouncing) {
160 uint8_t *tmp = matrix_debounced;
161 matrix_debounced = matrix;
162 matrix = tmp;
163 }
164
165 for (uint8_t col = 0; col < MATRIX_COLS; col++) { // 0-7
166 pull_column(col); // output hi on theline
167 _delay_us(5); // without this wait it won't read stable value.
168 for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-17
169 bool prev_bit = matrix[row] & (1<<col);
170 bool curr_bit = *row_pin[row] & row_bit[row];
171 if (prev_bit != curr_bit) {
172 matrix[row] ^= (1<<col);
173 if (debouncing) {
174 debug("bounce!: "); debug_hex(debouncing); print("\n");
175 }
176 _delay_ms(1); // improved affect on bouncing
177 debouncing = DEBOUNCE;
178 }
179 }
180 release_column(col);
181 }
182
183 if (debouncing) {
184 debouncing--;
185 }
186
187 return 1;
188}
189
190bool matrix_is_modified(void)
191{
192 // NOTE: no longer used
193 return true;
194}
195
196inline
197bool matrix_has_ghost(void)
198{
199 return false;
200}
201
202inline
203bool matrix_is_on(uint8_t row, uint8_t col)
204{
205 return (matrix_debounced[row] & (1<<col));
206}
207
208inline
209matrix_row_t matrix_get_row(uint8_t row)
210{
211 return matrix_debounced[row];
212}
213
214void matrix_print(void)
215{
216 print("\nr/c 01234567\n");
217 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
218 phex(row); print(": ");
219 pbin_reverse(matrix_get_row(row));
220 print("\n");
221 }
222}
223
224uint8_t matrix_key_count(void)
225{
226 uint8_t count = 0;
227 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
228 for (uint8_t j = 0; j < MATRIX_COLS; j++) {
229 if (matrix_is_on(i, j))
230 count++;
231 }
232 }
233 return count;
234}