From: Jun Wako Date: Tue, 28 Feb 2017 04:51:27 +0000 (+0900) Subject: fc660c: Scan matrix X-Git-Url: https://git.gir.st/tmk_keyboard.git/commitdiff_plain/503837cd07afec5c96968aae1a6f1e6fe2842383 fc660c: Scan matrix --- diff --git a/keyboard/fc660c/Makefile b/keyboard/fc660c/Makefile index a926beb7..7476d0f7 100644 --- a/keyboard/fc660c/Makefile +++ b/keyboard/fc660c/Makefile @@ -9,8 +9,7 @@ TARGET_DIR ?= . # List C source files -SRC ?= matrix.c \ - led.c +SRC ?= fc660c.c # Configure file CONFIG_H ?= config.h @@ -74,9 +73,8 @@ EXTRAKEY_ENABLE ?= yes # Audio control and System control CONSOLE_ENABLE ?= yes # Console for debug COMMAND_ENABLE ?= yes # Commands for debug and configuration NKRO_ENABLE ?= yes # USB Nkey Rollover -#HHKB_JP ?= yes # HHKB JP support #UNIMAP_ENABLE ?= yes # Universal keymap -#ACTIONMAP_ENABLE ?= yes # Use 16bit actionmap instead of 8bit keymap +ACTIONMAP_ENABLE ?= yes # Use 16bit actionmap instead of 8bit keymap #KEYMAP_SECTION_ENABLE ?= yes # fixed address keymap for keymap editor #OPT_DEFS += -DNO_ACTION_TAPPING @@ -107,10 +105,6 @@ endif VPATH += $(TARGET_DIR) VPATH += $(TMK_DIR) -ifeq (yes,$(strip $(RN42_ENABLE))) -include rn42.mk -include $(TMK_DIR)/protocol.mk -endif include $(TMK_DIR)/protocol/lufa.mk include $(TMK_DIR)/common.mk include $(TMK_DIR)/rules.mk diff --git a/keyboard/fc660c/README.md b/keyboard/fc660c/README.md new file mode 100644 index 00000000..cc528471 --- /dev/null +++ b/keyboard/fc660c/README.md @@ -0,0 +1,44 @@ +FC660C controller +================= +2017/02/24 + +Connector +--------- +### Hirose DF14A-20P-1.25H +[datasheet](http://www.mouser.com/ds/2/185/DF14_catalog-939195.pdf) + +### Pinouts + + |Controller |Switch |Description |ATmega32u4 + |-----------|--------|------------------------------------------|-------------- + | 1 | 20 | +Z7-LV07A-13-~CapsLED | + | 2 | 19 | +Z7-LV07A-11-~InsertLED | + | 3 | 18 | +Z3-LVC138A-4-~G2A Z6-TP1684-5-~EN |PD7 + | 4 | 17 | +Z3-LVC138A-3-A |PD4 + | 5 | 16 | +Z3-LVC138A-3-B |PD5 + | 6 | 15 | +Z3-LVC138A-3-C |PD6 + | 7 | 14 | +Z7-LV07A-3 LV4051A-11-A |PB0 + | 8 | 13 | +Z7-LV07A-1 LV4051A-10-B |PB1 + | 9 | 12 | +Z7-LV07A-5 LV4051A-9-C |PB2 + |10 | 11 | *Z5-LV4051A-6-~EN(Col 8-F) |PB3 + |11 | 10 | *Z4-LV4051A-6-~EN(Col 0-7) |PB4 + |12 | 9 | *Z2-AD5258-4-SDA(I2C) |PD1(TWI) + |13 | 8 | *Z2-AD5258-5-SDL(I2C) |PD0(TWI) + |14 | 7 | *Z6-TP1684-2-KEY(i) |PC6 + |15 | 6 | *Z6-TP1684-4-HYS(o) |PC7 + |16 | 5 | 5V | + |17 | 4 | 3.3V | + |18 | 3 | GND | + |19 | 2 | GND | + |20 | 1 | FG | + +``` +* 5V intferface ++ 3.3V interface +``` + + +Scan +---- +Row: Drive(LVC138A) +Col: Sense(4051) diff --git a/keyboard/fc660c/actionmap.c b/keyboard/fc660c/actionmap.c new file mode 100644 index 00000000..adfba3e2 --- /dev/null +++ b/keyboard/fc660c/actionmap.c @@ -0,0 +1,6 @@ +#include "action.h" + +const action_t actionmaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { + [0] = {}, +}; + diff --git a/keyboard/fc660c/config.h b/keyboard/fc660c/config.h new file mode 100644 index 00000000..fc2c8f4b --- /dev/null +++ b/keyboard/fc660c/config.h @@ -0,0 +1,49 @@ +/* +Copyright 2017 Jun Wako + +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 . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + + +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x660C +#define DEVICE_VER 0x0100 +#define MANUFACTURER TMK. +#define PRODUCT FC660C Alt Controller +#define DESCRIPTION TMK. keyboard firmware for FC660C + + +/* matrix size */ +#define MATRIX_ROWS 8 +#define MATRIX_COLS 16 + + +/* key combination for command */ +#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) + + +/* period of tapping(ms) */ +#define TAPPING_TERM 300 +/* tap count needed for toggling a feature */ +#define TAPPING_TOGGLE 5 +/* Oneshot timeout(ms) */ +#define ONESHOT_TIMEOUT 300 + +/* Boot Magic salt key: Space */ +#define BOOTMAGIC_KEY_SALT KC_SPACE + +#endif diff --git a/keyboard/fc660c/matrix.c b/keyboard/fc660c/fc660c.c similarity index 61% rename from keyboard/fc660c/matrix.c rename to keyboard/fc660c/fc660c.c index 08721fc5..2d63cdee 100644 --- a/keyboard/fc660c/matrix.c +++ b/keyboard/fc660c/fc660c.c @@ -1,5 +1,5 @@ /* -Copyright 2011 Jun Wako +Copyright 2017 Jun Wako 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 @@ -26,14 +26,13 @@ along with this program. If not, see . #include "util.h" #include "timer.h" #include "matrix.h" -#include "hhkb_avr.h" #include #include "suspend.h" #include "lufa.h" +#include "led.h" +#include "fc660c.h" -// matrix power saving -#define MATRIX_POWER_SAVE 10000 static uint32_t matrix_last_modified = 0; // matrix state buffer(1:on, 0:off) @@ -45,9 +44,10 @@ static matrix_row_t _matrix1[MATRIX_ROWS]; void matrix_init(void) { -#ifdef DEBUG +#if 1 debug_enable = true; debug_keyboard = true; + debug_matrix = true; #endif KEY_INIT(); @@ -61,22 +61,23 @@ void matrix_init(void) uint8_t matrix_scan(void) { - uint8_t *tmp; + matrix_row_t *tmp; tmp = matrix_prev; matrix_prev = matrix; matrix = tmp; - // power on - if (!KEY_POWER_STATE()) KEY_POWER_ON(); - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - KEY_SELECT(row, col); - _delay_us(5); + uint8_t row, col; + for (col = 0; col < MATRIX_COLS; col++) { + SET_COL(col); + for (row = 0; row < MATRIX_ROWS; row++) { + //KEY_SELECT(row, col); + SET_ROW(row); + _delay_us(2); // Not sure this is needed. This just emulates HHKB controller's behaviour. if (matrix_prev[row] & (1< MATRIX_POWER_SAVE) { - KEY_POWER_OFF(); - suspend_power_down(); + if (matrix[row] ^ matrix_prev[row]) { + matrix_last_modified = timer_read32(); + } } return 1; } @@ -147,9 +125,9 @@ matrix_row_t matrix_get_row(uint8_t row) return matrix[row]; } -void matrix_power_up(void) { - KEY_POWER_ON(); -} -void matrix_power_down(void) { - KEY_POWER_OFF(); +void led_set(uint8_t usb_led) +{ + if (usb_led & (1< +#include +#include +#include +#include + + +// Timer resolution check +#if (1000000/TIMER_RAW_FREQ > 20) +# error "Timer resolution(>20us) is not enough for HHKB matrix scan tweak on V-USB." +#endif + + +/* + * HHKB Matrix I/O + * + * row: HC4051[A,B,C] selects scan row0-7 + * row-ext: [En0,En1] row extention for JP + * col: LS145[A,B,C,D] selects scan col0-7 and enable(D) + * key: on: 0/off: 1 + * prev: hysteresis control: assert(1) when previous key state is on + */ + + +/* + * Pin configuration for ATMega32U4 + * + * Row: PD4-6, 7(~EN) + * Col: PB0-2, 3(Z5 ~EN), 4(Z4 ~EN) + * Key: PC6(pull-uped) + * Hys: PC7 + */ +static inline void KEY_ENABLE(void) { (PORTD &= ~(1<<7)); } +static inline void KEY_UNABLE(void) { (PORTD |= (1<<7)); } +static inline bool KEY_STATE(void) { return (PINC & (1<<6)); } +static inline void KEY_HYS_ON(void) { (PORTC |= (1<<7)); } +static inline void KEY_HYS_OFF(void) { (PORTC &= ~(1<<7)); } +static inline void KEY_INIT(void) +{ + /* Col */ + DDRB |= 0x1F; + /* Key: input with pull-up */ + DDRC &= ~(1<<6); + PORTC |= (1<<6); + /* Hys */ + DDRC |= (1<<7); + /* Row */ + DDRD |= 0xF0; + + KEY_UNABLE(); + KEY_HYS_OFF(); +} +static inline void SET_ROW(uint8_t ROW) +{ + // set row with unabling key + PORTD = (PORTD & 0x0F) | (1<<7) | ((ROW & 0x07) << 4); +} +static inline void SET_COL(uint8_t COL) +{ + // |PB3(Z5 ~EN)|PB4(Z4 ~EN) + // --------|-----------|----------- + // Col:0-7 |high |low + // Col:8-F |low |high + PORTB = (PORTB & 0xE0) | ((COL & 0x08) ? 1<<4 : 1<<3) | (COL & 0x07); +} + +#endif