New keyboard corresponding to Build I
This commit is contained in:
parent
14e9a84c9c
commit
8462aa97ec
10 changed files with 826 additions and 0 deletions
1
keyboard/valkey/Makefile
Symbolic link
1
keyboard/valkey/Makefile
Symbolic link
|
@ -0,0 +1 @@
|
|||
Makefile.lufa
|
127
keyboard/valkey/Makefile.lufa
Normal file
127
keyboard/valkey/Makefile.lufa
Normal file
|
@ -0,0 +1,127 @@
|
|||
#----------------------------------------------------------------------------
|
||||
# On command line:
|
||||
#
|
||||
# make all = Make software.
|
||||
#
|
||||
# make clean = Clean out built project files.
|
||||
#
|
||||
# make coff = Convert ELF to AVR COFF.
|
||||
#
|
||||
# make extcoff = Convert ELF to AVR Extended COFF.
|
||||
#
|
||||
# make program = Download the hex file to the device.
|
||||
# Please customize your programmer settings(PROGRAM_CMD)
|
||||
#
|
||||
# make teensy = Download the hex file to the device, using teensy_loader_cli.
|
||||
# (must have teensy_loader_cli installed).
|
||||
#
|
||||
# make dfu = Download the hex file to the device, using dfu-programmer (must
|
||||
# have dfu-programmer installed).
|
||||
#
|
||||
# make flip = Download the hex file to the device, using Atmel FLIP (must
|
||||
# have Atmel FLIP installed).
|
||||
#
|
||||
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
|
||||
# (must have dfu-programmer installed).
|
||||
#
|
||||
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
|
||||
# (must have Atmel FLIP installed).
|
||||
#
|
||||
# make debug = Start either simulavr or avarice as specified for debugging,
|
||||
# with avr-gdb or avr-insight as the front end for debugging.
|
||||
#
|
||||
# make filename.s = Just compile filename.c into the assembler code only.
|
||||
#
|
||||
# make filename.i = Create a preprocessed source file for use in submitting
|
||||
# bug reports to the GCC project.
|
||||
#
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# Target file name (without extension).
|
||||
TARGET = valkey_lufa
|
||||
|
||||
# Directory common source filess exist
|
||||
TOP_DIR = ../..
|
||||
|
||||
# Directory keyboard dependent files exist
|
||||
TARGET_DIR = .
|
||||
|
||||
|
||||
# List C source files here. (C dependencies are automatically generated.)
|
||||
SRC += keymap.c \
|
||||
matrix.c \
|
||||
led.c \
|
||||
backlight.c
|
||||
|
||||
CONFIG_H = config.h
|
||||
|
||||
|
||||
# MCU name
|
||||
#MCU = at90usb1287
|
||||
#MCU = atmega32u4
|
||||
#MCU = at90usb1286 # Teensy++ 2.0
|
||||
MCU = at90usb1286
|
||||
|
||||
# Processor frequency.
|
||||
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||
# processor frequency in Hz. You can then use this symbol in your source code to
|
||||
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||
# automatically to create a 32-bit value in your source code.
|
||||
#
|
||||
# This will be an integer division of F_USB below, as it is sourced by
|
||||
# F_USB after it has run through any CPU prescalers. Note that this value
|
||||
# does not *change* the processor frequency - it should merely be updated to
|
||||
# reflect the processor speed set externally so that the code can use accurate
|
||||
# software delays.
|
||||
F_CPU = 16000000
|
||||
|
||||
|
||||
#
|
||||
# LUFA specific
|
||||
#
|
||||
# Target architecture (see library "Board Types" documentation).
|
||||
ARCH = AVR8
|
||||
|
||||
# Input clock frequency.
|
||||
# This will define a symbol, F_USB, in all source code files equal to the
|
||||
# input clock frequency (before any prescaling is performed) in Hz. This value may
|
||||
# differ from F_CPU if prescaling is used on the latter, and is required as the
|
||||
# raw input clock is fed directly to the PLL sections of the AVR for high speed
|
||||
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
|
||||
# at the end, this will be done automatically to create a 32-bit value in your
|
||||
# source code.
|
||||
#
|
||||
# If no clock division is performed on the input clock inside the AVR (via the
|
||||
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
|
||||
F_USB = $(F_CPU)
|
||||
|
||||
|
||||
# Build Options
|
||||
# comment out to disable the options.
|
||||
#
|
||||
BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
|
||||
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
|
||||
CONSOLE_ENABLE = no # Console for debug(+400) (Issue 93 in UEFI)
|
||||
COMMAND_ENABLE = yes # Commands for debug and configuration
|
||||
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
|
||||
NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
|
||||
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
|
||||
|
||||
|
||||
# Teensy halfKay 512
|
||||
# Teensy++ halfKay 1024
|
||||
# Atmel DFU loader 4096
|
||||
# LUFA bootloader 4096
|
||||
# USBaspLoader 2048
|
||||
OPT_DEFS += -DBOOTLOADER_SIZE=4096
|
||||
|
||||
|
||||
# Search Path
|
||||
VPATH += $(TARGET_DIR)
|
||||
VPATH += $(TOP_DIR)
|
||||
|
||||
include $(TOP_DIR)/protocol/lufa.mk
|
||||
include $(TOP_DIR)/common.mk
|
||||
include $(TOP_DIR)/rules.mk
|
108
keyboard/valkey/Makefile.pjrc
Normal file
108
keyboard/valkey/Makefile.pjrc
Normal file
|
@ -0,0 +1,108 @@
|
|||
#----------------------------------------------------------------------------
|
||||
# On command line:
|
||||
#
|
||||
# make all = Make software.
|
||||
#
|
||||
# make clean = Clean out built project files.
|
||||
#
|
||||
# make coff = Convert ELF to AVR COFF.
|
||||
#
|
||||
# make extcoff = Convert ELF to AVR Extended COFF.
|
||||
#
|
||||
# make program = Download the hex file to the device.
|
||||
# Please customize your programmer settings(PROGRAM_CMD)
|
||||
#
|
||||
# make teensy = Download the hex file to the device, using teensy_loader_cli.
|
||||
# (must have teensy_loader_cli installed).
|
||||
#
|
||||
# make dfu = Download the hex file to the device, using dfu-programmer (must
|
||||
# have dfu-programmer installed).
|
||||
#
|
||||
# make flip = Download the hex file to the device, using Atmel FLIP (must
|
||||
# have Atmel FLIP installed).
|
||||
#
|
||||
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
|
||||
# (must have dfu-programmer installed).
|
||||
#
|
||||
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
|
||||
# (must have Atmel FLIP installed).
|
||||
#
|
||||
# make debug = Start either simulavr or avarice as specified for debugging,
|
||||
# with avr-gdb or avr-insight as the front end for debugging.
|
||||
#
|
||||
# make filename.s = Just compile filename.c into the assembler code only.
|
||||
#
|
||||
# make filename.i = Create a preprocessed source file for use in submitting
|
||||
# bug reports to the GCC project.
|
||||
#
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# Target file name (without extension).
|
||||
TARGET = phantom_pjrc
|
||||
|
||||
# Directory common source filess exist
|
||||
TOP_DIR = ../..
|
||||
|
||||
# Directory keyboard dependent files exist
|
||||
TARGET_DIR = .
|
||||
|
||||
# keyboard dependent files
|
||||
SRC = keymap.c \
|
||||
matrix.c \
|
||||
led.c
|
||||
|
||||
CONFIG_H = config.h
|
||||
|
||||
|
||||
# MCU name, you MUST set this to match the board you are using
|
||||
# type "make clean" after changing this, so all files will be rebuilt
|
||||
#MCU = at90usb162 # Teensy 1.0
|
||||
#MCU = atmega32u4 # Teensy 2.0
|
||||
#MCU = at90usb646 # Teensy++ 1.0
|
||||
MCU = at90usb1286 # Teensy++ 2.0
|
||||
|
||||
|
||||
# Processor frequency.
|
||||
# Normally the first thing your program should do is set the clock prescaler,
|
||||
# so your program will run at the correct speed. You should also set this
|
||||
# variable to same clock speed. The _delay_ms() macro uses this, and many
|
||||
# examples use this variable to calculate timings. Do not add a "UL" here.
|
||||
F_CPU = 16000000
|
||||
|
||||
|
||||
# Build Options
|
||||
# comment out to disable the options.
|
||||
#
|
||||
BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
|
||||
#MOUSEKEY_ENABLE = yes # Mouse keys(+5000)
|
||||
EXTRAKEY_ENABLE = yes # Audio control and System control(+600)
|
||||
CONSOLE_ENABLE = yes # Console for debug
|
||||
COMMAND_ENABLE = yes # Commands for debug and configuration
|
||||
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
|
||||
NKRO_ENABLE = yes # USB Nkey Rollover(+500)
|
||||
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
|
||||
|
||||
|
||||
# Search Path
|
||||
VPATH += $(TARGET_DIR)
|
||||
VPATH += $(TOP_DIR)
|
||||
|
||||
include $(TOP_DIR)/protocol/pjrc.mk
|
||||
include $(TOP_DIR)/common.mk
|
||||
include $(TOP_DIR)/rules.mk
|
||||
|
||||
ansi: OPT_DEFS += -DLAYOUT_ANSI
|
||||
ansi: all
|
||||
|
||||
ansi_150: OPT_DEFS += -DLAYOUT_ANSI_150
|
||||
ansi_150: all
|
||||
|
||||
iso: OPT_DEFS += -DLAYOUT_ISO
|
||||
iso: all
|
||||
|
||||
iso_150: OPT_DEFS += -DLAYOUT_ISO_150
|
||||
iso_150: all
|
||||
|
||||
7bit: OPT_DEFS += -DLAYOUT_7BIT
|
||||
7bit: all
|
66
keyboard/valkey/backlight.c
Normal file
66
keyboard/valkey/backlight.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
Copyright 2014 Ralf Schmitt <ralf@bunkertor.net>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include "backlight.h"
|
||||
|
||||
/* Backlight pin configuration
|
||||
*
|
||||
* HOME_ROW : PD1
|
||||
* FUNCTIONS: PD0
|
||||
*/
|
||||
void backlight_init_ports() {
|
||||
DDRD |= (1<<0) | (1<<1);
|
||||
//PORTD |= (1<<0) | (1<<1);
|
||||
DDRD |= (1<<6);
|
||||
PORTD |= (1<<6);
|
||||
}
|
||||
|
||||
void backlight_set(uint8_t level) {
|
||||
(level & BACKLIGHT_FNCT) ? backlight_enable_fn() : backlight_disable_fn();
|
||||
(level & BACKLIGHT_HOME) ? backlight_enable_home() : backlight_disable_home();
|
||||
}
|
||||
|
||||
void backlight_enable_fn() {
|
||||
DDRD |= (1<<0) | (1<<1);
|
||||
PORTD |= (1<<0);
|
||||
}
|
||||
|
||||
void backlight_disable_fn() {
|
||||
DDRD |= (1<<0) | (1<<1);
|
||||
PORTD &= ~(1<<0);
|
||||
}
|
||||
|
||||
void backlight_invert_fn() {
|
||||
DDRD |= (1<<0) | (1<<1);
|
||||
PORTD ^= (1<<0);
|
||||
}
|
||||
|
||||
void backlight_enable_home() {
|
||||
DDRD |= (1<<0) | (1<<1);
|
||||
PORTD |= (1<<1);
|
||||
}
|
||||
|
||||
void backlight_disable_home() {
|
||||
DDRD |= (1<<0) | (1<<1);
|
||||
PORTD &= ~(1<<1);
|
||||
}
|
||||
|
||||
void backlight_invert_home() {
|
||||
DDRD |= (1<<0) | (1<<1);
|
||||
PORTD ^= (1<<1);
|
||||
}
|
15
keyboard/valkey/backlight.h
Normal file
15
keyboard/valkey/backlight.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
enum backlight_level {
|
||||
BACKLIGHT_FNCT = 0b0000001,
|
||||
BACKLIGHT_HOME = 0b0000010,
|
||||
};
|
||||
|
||||
void backlight_init_ports(void);
|
||||
|
||||
void backlight_invert_fn(void);
|
||||
void backlight_enable_fn(void);
|
||||
void backlight_disable_fn(void);
|
||||
|
||||
void backlight_invert_home(void);
|
||||
void backlight_enable_home(void);
|
||||
void backlight_disable_home(void);
|
53
keyboard/valkey/config.h
Normal file
53
keyboard/valkey/config.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Copyright 2012 Jun Wako <wakojun@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
|
||||
/* USB Device descriptor parameter */
|
||||
#define VENDOR_ID 0xFEED
|
||||
#define PRODUCT_ID 0x6057
|
||||
#define DEVICE_VER 0x0001
|
||||
#define MANUFACTURER t.m.k.
|
||||
#define PRODUCT Valdor-Key
|
||||
|
||||
/* message strings */
|
||||
#define DESCRIPTION t.m.k. keyboard firmware for Valdor65 personal keyboard
|
||||
|
||||
/* matrix size */
|
||||
#define MATRIX_ROWS 6
|
||||
#define MATRIX_COLS 18
|
||||
|
||||
/* define if matrix has ghost */
|
||||
//#define MATRIX_HAS_GHOST
|
||||
|
||||
/* Set 0 if need no debouncing */
|
||||
#define DEBOUNCE 7
|
||||
|
||||
/* Set LED brightness 0-255.
|
||||
* This have no effect if sleep LED is enabled. */
|
||||
#define LED_BRIGHTNESS 250
|
||||
|
||||
#define BACKLIGHT_LEVELS 4
|
||||
|
||||
/* key combination for command */
|
||||
#define IS_COMMAND() ( \
|
||||
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
|
||||
)
|
||||
|
||||
#endif
|
77
keyboard/valkey/keymap.c
Normal file
77
keyboard/valkey/keymap.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
Copyright 2011 Jun Wako <wakojun@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Keymap for Phantom controller
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "keycode.h"
|
||||
#include "action.h"
|
||||
#include "action_macro.h"
|
||||
#include "report.h"
|
||||
#include "host.h"
|
||||
#include "debug.h"
|
||||
#include "keymap.h"
|
||||
|
||||
// Convert physical keyboard layout to matrix array.
|
||||
// This is a macro to define keymap easily in keyboard layout form.
|
||||
#define KEYMAP( \
|
||||
K5B, K5C, K5D, K5E, K5F, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K5O, K5P, K5Q, K5R, \
|
||||
K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4O, K4P, K4Q, K4R, \
|
||||
K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3M, K3N, K3P, K3Q, K3R, \
|
||||
K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2M, K2N, K2O, K2P, K2Q, K2R, \
|
||||
K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, K1I, K1J, K1K, K1L, K1M, K1O, K1Q, \
|
||||
K0A, K0B, K0C, K0D, K0H, K0L, K0M, K0N, K0O, K0P, K0Q, K0R \
|
||||
) { \
|
||||
/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 */ \
|
||||
/* 5 */ { KC_NO, KC_##K5B, KC_##K5C, KC_##K5D, KC_##K5E, KC_##K5F, KC_NO, KC_##K5H, KC_##K5I, KC_##K5J, KC_##K5K, KC_##K5L, KC_##K5M, KC_##K5N, KC_##K5O, KC_##K5P, KC_##K5Q, KC_##K5R}, \
|
||||
/* 4 */ { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F, KC_##K4G, KC_##K4H, KC_##K4I, KC_##K4J, KC_##K4K, KC_##K4L, KC_##K4M, KC_##K4N, KC_##K4O, KC_##K4P, KC_##K4Q, KC_##K4R}, \
|
||||
/* 3 */ { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F, KC_##K3G, KC_##K3H, KC_##K3I, KC_##K3J, KC_##K3K, KC_##K3L, KC_##K3M, KC_##K3N, KC_NO, KC_##K3P, KC_##K3Q, KC_##K3R}, \
|
||||
/* 2 */ { KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F, KC_##K2G, KC_##K2H, KC_##K2I, KC_##K2J, KC_##K2K, KC_##K2L, KC_##K2M, KC_##K2N, KC_##K2O, KC_##K2P, KC_##K2Q, KC_##K2R}, \
|
||||
/* 1 */ { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F, KC_##K1G, KC_##K1H, KC_##K1I, KC_##K1J, KC_##K1K, KC_##K1L, KC_##K1M, KC_NO, KC_##K1O, KC_NO, KC_##K1Q, KC_NO }, \
|
||||
/* 0 */ { KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_NO, KC_NO, KC_NO, KC_##K0H, KC_NO, KC_NO, KC_NO, KC_##K0L, KC_##K0M, KC_##K0N, KC_##K0O, KC_##K0P, KC_##K0Q, KC_##K0R} \
|
||||
}
|
||||
|
||||
#include "keymap_iso.h"
|
||||
|
||||
#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
|
||||
#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
|
||||
|
||||
/* translates key to keycode */
|
||||
uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
|
||||
{
|
||||
if (layer < KEYMAPS_SIZE) {
|
||||
return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
|
||||
} else {
|
||||
// fall back to layer 0
|
||||
return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
|
||||
}
|
||||
}
|
||||
|
||||
/* translates Fn keycode to action */
|
||||
action_t keymap_fn_to_action(uint8_t keycode)
|
||||
{
|
||||
action_t action;
|
||||
if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
|
||||
action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
|
||||
} else {
|
||||
action.code = ACTION_NO;
|
||||
}
|
||||
return action;
|
||||
}
|
67
keyboard/valkey/keymap_iso.h
Normal file
67
keyboard/valkey/keymap_iso.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "backlight.h"
|
||||
#include "action_layer.h"
|
||||
|
||||
#define FUNCTION_ENABLE_LAYER1 1
|
||||
#define FUNCTION_ENABLE_LAYER2 2
|
||||
#define FUNCTION_DISABLE_LAYER1 11
|
||||
#define FUNCTION_DISABLE_LAYER2 12
|
||||
|
||||
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
/* 0: qwerty */
|
||||
KEYMAP(\
|
||||
ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, \
|
||||
FN4, GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, \
|
||||
FN3, TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, DEL, END, PGDN, \
|
||||
FN2, CLCK,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NUHS, ENT, FN5, FN6, FN7, \
|
||||
FN1, LSFT,NUBS,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, \
|
||||
FN0, LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT ),
|
||||
/* 1: media keys */
|
||||
KEYMAP(\
|
||||
TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,SLEP, \
|
||||
FN14,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,MUTE,VOLD,VOLU,TRNS, TRNS,TRNS,TRNS, \
|
||||
FN13,TRNS,TRNS,UP ,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,MSTP,MPLY,MPRV,MNXT, TRNS,TRNS,TRNS, \
|
||||
FN12,TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, ENT, TRNS,TRNS,TRNS, \
|
||||
NO, TRNS,TRNS,TRNS,TRNS,CALC,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, \
|
||||
FN10,TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS),
|
||||
/* 2: mouse keys */
|
||||
KEYMAP(\
|
||||
TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,SLEP, \
|
||||
FN24,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,MUTE,VOLD,VOLU,TRNS, TRNS,TRNS,TRNS, \
|
||||
FN23,TRNS,BTN1,MS_U,BTN2,TRNS,TRNS,TRNS,TRNS,TRNS,MSTP,MPLY,MPRV,MNXT, TRNS,TRNS,TRNS, \
|
||||
FN22,TRNS,MS_L,MS_D,MS_R,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, ENT, TRNS,TRNS,TRNS, \
|
||||
NO, TRNS,TRNS,TRNS,TRNS,CALC,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, \
|
||||
FN20,TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS)
|
||||
};
|
||||
static const uint16_t PROGMEM fn_actions[] = {
|
||||
[0] = ACTION_LAYER_MOMENTARY(1),
|
||||
[1] = ACTION_FUNCTION(FUNCTION_ENABLE_LAYER1),
|
||||
[10] = ACTION_FUNCTION(FUNCTION_DISABLE_LAYER1),
|
||||
[2] = ACTION_FUNCTION(FUNCTION_ENABLE_LAYER2),
|
||||
[20] = ACTION_FUNCTION(FUNCTION_DISABLE_LAYER2),
|
||||
};
|
||||
|
||||
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
|
||||
switch(id) {
|
||||
case FUNCTION_ENABLE_LAYER1:
|
||||
layer_on(1);
|
||||
backlight_enable_home();
|
||||
backlight_enable_fn();
|
||||
break;
|
||||
case FUNCTION_DISABLE_LAYER1:
|
||||
layer_off(1);
|
||||
backlight_disable_home();
|
||||
backlight_disable_fn();
|
||||
break;
|
||||
|
||||
case FUNCTION_ENABLE_LAYER2:
|
||||
layer_on(2);
|
||||
backlight_enable_home();
|
||||
backlight_enable_fn();
|
||||
break;
|
||||
case FUNCTION_DISABLE_LAYER2:
|
||||
layer_off(2);
|
||||
backlight_disable_home();
|
||||
backlight_disable_fn();
|
||||
break;
|
||||
}
|
||||
}
|
36
keyboard/valkey/led.c
Normal file
36
keyboard/valkey/led.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
Copyright 2012 Jun Wako <wakojun@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include "led.h"
|
||||
|
||||
|
||||
void led_set(uint8_t usb_led)
|
||||
{
|
||||
if (usb_led & (1<<USB_LED_CAPS_LOCK))
|
||||
{
|
||||
// Output high.
|
||||
DDRB |= (1<<6);
|
||||
PORTB |= (1<<6);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Output low.
|
||||
DDRB &= ~(1<<6);
|
||||
PORTB &= ~(1<<6);
|
||||
}
|
||||
}
|
276
keyboard/valkey/matrix.c
Normal file
276
keyboard/valkey/matrix.c
Normal file
|
@ -0,0 +1,276 @@
|
|||
/* Copyright 2012 Jun Wako <wakojun@gmail.com>
|
||||
*
|
||||
* This is heavily based on phantom/board.{c|h}.
|
||||
* https://github.com/BathroomEpiphanies/AVR-Keyboard
|
||||
*
|
||||
* Copyright (c) 2012 Fredrik Atmer, Bathroom Epiphanies Inc
|
||||
* http://bathroomepiphanies.com
|
||||
*
|
||||
* As for liscensing consult with the original files or its author.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
#include "util.h"
|
||||
#include "matrix.h"
|
||||
|
||||
|
||||
#ifndef DEBOUNCE
|
||||
# define DEBOUNCE 0
|
||||
#endif
|
||||
static uint8_t debouncing = DEBOUNCE;
|
||||
|
||||
// bit array of key state(1:on, 0:off)
|
||||
static matrix_row_t matrix[MATRIX_ROWS];
|
||||
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||
|
||||
static uint8_t read_rows(void);
|
||||
static void init_rows(void);
|
||||
static void unselect_cols(void);
|
||||
static void select_col(uint8_t col);
|
||||
|
||||
#ifndef SLEEP_LED_ENABLE
|
||||
/* LEDs are on output compare pins OC1B OC1C
|
||||
This activates fast PWM mode on them.
|
||||
Prescaler 256 and 8-bit counter results in
|
||||
16000000/256/256 = 244 Hz blink frequency.
|
||||
LED_A: Caps Lock
|
||||
LED_B: Scroll Lock */
|
||||
/* Output on PWM pins are turned off when the timer
|
||||
reaches the value in the output compare register,
|
||||
and are turned on when it reaches TOP (=256). */
|
||||
static
|
||||
void setup_leds(void)
|
||||
{
|
||||
TCCR1A |= // Timer control register 1A
|
||||
(1<<WGM10) | // Fast PWM 8-bit
|
||||
(1<<COM1B1)| // Clear OC1B on match, set at TOP
|
||||
(1<<COM1C1); // Clear OC1C on match, set at TOP
|
||||
TCCR1B |= // Timer control register 1B
|
||||
(1<<WGM12) | // Fast PWM 8-bit
|
||||
(1<<CS12); // Prescaler 256
|
||||
OCR1B = LED_BRIGHTNESS; // Output compare register 1B
|
||||
OCR1C = LED_BRIGHTNESS; // Output compare register 1C
|
||||
// LEDs: LED_A -> PORTB6, LED_B -> PORTB7
|
||||
DDRB |= (1<<6);
|
||||
PORTB &= ~(1<<6);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline
|
||||
uint8_t matrix_rows(void)
|
||||
{
|
||||
return MATRIX_ROWS;
|
||||
}
|
||||
|
||||
inline
|
||||
uint8_t matrix_cols(void)
|
||||
{
|
||||
return MATRIX_COLS;
|
||||
}
|
||||
|
||||
void matrix_init(void)
|
||||
{
|
||||
// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
|
||||
MCUCR |= (1<<JTD);
|
||||
MCUCR |= (1<<JTD);
|
||||
|
||||
// initialize row and col
|
||||
unselect_cols();
|
||||
init_rows();
|
||||
#ifndef SLEEP_LED_ENABLE
|
||||
setup_leds();
|
||||
#endif
|
||||
|
||||
// initialize matrix state: all keys off
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
matrix[i] = 0;
|
||||
matrix_debouncing[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void)
|
||||
{
|
||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) { // 0-16
|
||||
select_col(col);
|
||||
_delay_us(3); // without this wait it won't read stable value.
|
||||
uint8_t rows = read_rows();
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-5
|
||||
bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
|
||||
bool curr_bit = rows & (1<<row);
|
||||
if (prev_bit != curr_bit) {
|
||||
matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
|
||||
if (debouncing) {
|
||||
dprint("bounce!: "); dprintf("%02X", debouncing); dprintln();
|
||||
}
|
||||
debouncing = DEBOUNCE;
|
||||
}
|
||||
}
|
||||
unselect_cols();
|
||||
}
|
||||
|
||||
if (debouncing) {
|
||||
if (--debouncing) {
|
||||
_delay_ms(1);
|
||||
} else {
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
matrix[i] = matrix_debouncing[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool matrix_is_modified(void)
|
||||
{
|
||||
if (debouncing) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||
{
|
||||
return (matrix[row] & ((matrix_row_t)1<<col));
|
||||
}
|
||||
|
||||
inline
|
||||
matrix_row_t matrix_get_row(uint8_t row)
|
||||
{
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void matrix_print(void)
|
||||
{
|
||||
print("\nr/c 0123456789ABCDEF\n");
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
xprintf("%02X: %032lb\n", row, bitrev32(matrix_get_row(row)));
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t matrix_key_count(void)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
count += bitpop32(matrix[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Row pin configuration
|
||||
* row: 0 1 2 3 4 5
|
||||
* pin: B0 B1 B2 B3 B4 B5
|
||||
*/
|
||||
static void init_rows(void)
|
||||
{
|
||||
// Input with pull-up(DDR:0, PORT:1)
|
||||
DDRB &= ~0b00111111;
|
||||
PORTB |= 0b00111111;
|
||||
}
|
||||
|
||||
static uint8_t read_rows(void)
|
||||
{
|
||||
return (PINB&(1<<5) ? 0 : (1<<0)) |
|
||||
(PINB&(1<<4) ? 0 : (1<<1)) |
|
||||
(PINB&(1<<3) ? 0 : (1<<2)) |
|
||||
(PINB&(1<<2) ? 0 : (1<<3)) |
|
||||
(PINB&(1<<1) ? 0 : (1<<4)) |
|
||||
(PINB&(1<<0) ? 0 : (1<<5));
|
||||
}
|
||||
|
||||
/* Column pin configuration
|
||||
* col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
||||
* pin: C0 C1 C2 C3 C4 C5 C6 C7 F0 F1 F2 F3 F4 F5 F6 F7 E0 E1
|
||||
*/
|
||||
static void unselect_cols(void)
|
||||
{
|
||||
// Hi-Z(DDR:0, PORT:0) to unselect
|
||||
DDRC |= 0b11111111; // PC: 7 6 5 4 3 2 1 0
|
||||
PORTC |= 0b11111111;
|
||||
DDRF |= 0b11111111; // PF: 7 6 5 4 3 2 1 0
|
||||
PORTF |= 0b11111111;
|
||||
DDRE |= 0b00000011; // PE: 1 0
|
||||
PORTE |= 0b00000011;
|
||||
}
|
||||
|
||||
static void select_col(uint8_t col)
|
||||
{
|
||||
// Output low(DDR:1, PORT:0) to select
|
||||
switch (col) {
|
||||
case 0:
|
||||
DDRC |= (1<<0);
|
||||
PORTC &= ~(1<<0);
|
||||
break;
|
||||
case 1:
|
||||
DDRC |= (1<<1);
|
||||
PORTC &= ~(1<<1);
|
||||
break;
|
||||
case 2:
|
||||
DDRC |= (1<<2);
|
||||
PORTC &= ~(1<<2);
|
||||
break;
|
||||
case 3:
|
||||
DDRC |= (1<<3);
|
||||
PORTC &= ~(1<<3);
|
||||
break;
|
||||
case 4:
|
||||
DDRC |= (1<<4);
|
||||
PORTC &= ~(1<<4);
|
||||
break;
|
||||
case 5:
|
||||
DDRC |= (1<<5);
|
||||
PORTC &= ~(1<<5);
|
||||
break;
|
||||
case 6:
|
||||
DDRC |= (1<<6);
|
||||
PORTC &= ~(1<<6);
|
||||
break;
|
||||
case 7:
|
||||
DDRC |= (1<<7);
|
||||
PORTC &= ~(1<<7);
|
||||
break;
|
||||
case 8:
|
||||
DDRF |= (1<<0);
|
||||
PORTF &= ~(1<<0);
|
||||
break;
|
||||
case 9:
|
||||
DDRF |= (1<<1);
|
||||
PORTF &= ~(1<<1);
|
||||
break;
|
||||
case 10:
|
||||
DDRF |= (1<<2);
|
||||
PORTF &= ~(1<<2);
|
||||
break;
|
||||
case 11:
|
||||
DDRF |= (1<<3);
|
||||
PORTF &= ~(1<<3);
|
||||
break;
|
||||
case 12:
|
||||
DDRF |= (1<<4);
|
||||
PORTF &= ~(1<<4);
|
||||
break;
|
||||
case 13:
|
||||
DDRF |= (1<<5);
|
||||
PORTF &= ~(1<<5);
|
||||
break;
|
||||
case 14:
|
||||
DDRF |= (1<<6);
|
||||
PORTF &= ~(1<<6);
|
||||
break;
|
||||
case 15:
|
||||
DDRF |= (1<<7);
|
||||
PORTF &= ~(1<<7);
|
||||
break;
|
||||
case 16:
|
||||
DDRE |= (1<<0);
|
||||
PORTE &= ~(1<<0);
|
||||
break;
|
||||
case 17:
|
||||
DDRE |= (1<<1);
|
||||
PORTE &= ~(1<<1);
|
||||
break;
|
||||
}
|
||||
}
|
Reference in a new issue