fc660c: Scan matrix
This commit is contained in:
parent
36a29a5829
commit
503837cd07
6 changed files with 195 additions and 54 deletions
|
|
@ -9,8 +9,7 @@ TARGET_DIR ?= .
|
||||||
|
|
||||||
|
|
||||||
# List C source files
|
# List C source files
|
||||||
SRC ?= matrix.c \
|
SRC ?= fc660c.c
|
||||||
led.c
|
|
||||||
|
|
||||||
# Configure file
|
# Configure file
|
||||||
CONFIG_H ?= config.h
|
CONFIG_H ?= config.h
|
||||||
|
|
@ -74,9 +73,8 @@ EXTRAKEY_ENABLE ?= yes # Audio control and System control
|
||||||
CONSOLE_ENABLE ?= yes # Console for debug
|
CONSOLE_ENABLE ?= yes # Console for debug
|
||||||
COMMAND_ENABLE ?= yes # Commands for debug and configuration
|
COMMAND_ENABLE ?= yes # Commands for debug and configuration
|
||||||
NKRO_ENABLE ?= yes # USB Nkey Rollover
|
NKRO_ENABLE ?= yes # USB Nkey Rollover
|
||||||
#HHKB_JP ?= yes # HHKB JP support
|
|
||||||
#UNIMAP_ENABLE ?= yes # Universal keymap
|
#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
|
#KEYMAP_SECTION_ENABLE ?= yes # fixed address keymap for keymap editor
|
||||||
|
|
||||||
#OPT_DEFS += -DNO_ACTION_TAPPING
|
#OPT_DEFS += -DNO_ACTION_TAPPING
|
||||||
|
|
@ -107,10 +105,6 @@ endif
|
||||||
VPATH += $(TARGET_DIR)
|
VPATH += $(TARGET_DIR)
|
||||||
VPATH += $(TMK_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)/protocol/lufa.mk
|
||||||
include $(TMK_DIR)/common.mk
|
include $(TMK_DIR)/common.mk
|
||||||
include $(TMK_DIR)/rules.mk
|
include $(TMK_DIR)/rules.mk
|
||||||
|
|
|
||||||
44
keyboard/fc660c/README.md
Normal file
44
keyboard/fc660c/README.md
Normal file
|
|
@ -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)
|
||||||
6
keyboard/fc660c/actionmap.c
Normal file
6
keyboard/fc660c/actionmap.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "action.h"
|
||||||
|
|
||||||
|
const action_t actionmaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
|
||||||
|
[0] = {},
|
||||||
|
};
|
||||||
|
|
||||||
49
keyboard/fc660c/config.h
Normal file
49
keyboard/fc660c/config.h
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
Copyright 2017 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
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2011 Jun Wako <wakojun@gmail.com>
|
Copyright 2017 Jun Wako <wakojun@gmail.com>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -26,14 +26,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "hhkb_avr.h"
|
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
#include "suspend.h"
|
#include "suspend.h"
|
||||||
#include "lufa.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;
|
static uint32_t matrix_last_modified = 0;
|
||||||
|
|
||||||
// matrix state buffer(1:on, 0:off)
|
// matrix state buffer(1:on, 0:off)
|
||||||
|
|
@ -45,9 +44,10 @@ static matrix_row_t _matrix1[MATRIX_ROWS];
|
||||||
|
|
||||||
void matrix_init(void)
|
void matrix_init(void)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#if 1
|
||||||
debug_enable = true;
|
debug_enable = true;
|
||||||
debug_keyboard = true;
|
debug_keyboard = true;
|
||||||
|
debug_matrix = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
KEY_INIT();
|
KEY_INIT();
|
||||||
|
|
@ -61,22 +61,23 @@ void matrix_init(void)
|
||||||
|
|
||||||
uint8_t matrix_scan(void)
|
uint8_t matrix_scan(void)
|
||||||
{
|
{
|
||||||
uint8_t *tmp;
|
matrix_row_t *tmp;
|
||||||
|
|
||||||
tmp = matrix_prev;
|
tmp = matrix_prev;
|
||||||
matrix_prev = matrix;
|
matrix_prev = matrix;
|
||||||
matrix = tmp;
|
matrix = tmp;
|
||||||
|
|
||||||
// power on
|
uint8_t row, col;
|
||||||
if (!KEY_POWER_STATE()) KEY_POWER_ON();
|
for (col = 0; col < MATRIX_COLS; col++) {
|
||||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
SET_COL(col);
|
||||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
for (row = 0; row < MATRIX_ROWS; row++) {
|
||||||
KEY_SELECT(row, col);
|
//KEY_SELECT(row, col);
|
||||||
_delay_us(5);
|
SET_ROW(row);
|
||||||
|
_delay_us(2);
|
||||||
|
|
||||||
// Not sure this is needed. This just emulates HHKB controller's behaviour.
|
// Not sure this is needed. This just emulates HHKB controller's behaviour.
|
||||||
if (matrix_prev[row] & (1<<col)) {
|
if (matrix_prev[row] & (1<<col)) {
|
||||||
KEY_PREV_ON();
|
KEY_HYS_ON();
|
||||||
}
|
}
|
||||||
_delay_us(10);
|
_delay_us(10);
|
||||||
|
|
||||||
|
|
@ -88,18 +89,7 @@ uint8_t matrix_scan(void)
|
||||||
KEY_ENABLE();
|
KEY_ENABLE();
|
||||||
|
|
||||||
// Wait for KEY_STATE outputs its value.
|
// Wait for KEY_STATE outputs its value.
|
||||||
// 1us was ok on one HHKB, but not worked on another.
|
_delay_us(2);
|
||||||
// no wait doesn't work on Teensy++ with pro(1us works)
|
|
||||||
// no wait does work on tmk PCB(8MHz) with pro2
|
|
||||||
// 1us wait does work on both of above
|
|
||||||
// 1us wait doesn't work on tmk(16MHz)
|
|
||||||
// 5us wait does work on tmk(16MHz)
|
|
||||||
// 5us wait does work on tmk(16MHz/2)
|
|
||||||
// 5us wait does work on tmk(8MHz)
|
|
||||||
// 10us wait does work on Teensy++ with pro
|
|
||||||
// 10us wait does work on 328p+iwrap with pro
|
|
||||||
// 10us wait doesn't work on tmk PCB(8MHz) with pro2(very lagged scan)
|
|
||||||
_delay_us(5);
|
|
||||||
|
|
||||||
if (KEY_STATE()) {
|
if (KEY_STATE()) {
|
||||||
matrix[row] &= ~(1<<col);
|
matrix[row] &= ~(1<<col);
|
||||||
|
|
@ -115,28 +105,16 @@ uint8_t matrix_scan(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
_delay_us(5);
|
_delay_us(5);
|
||||||
KEY_PREV_OFF();
|
KEY_HYS_OFF();
|
||||||
KEY_UNABLE();
|
KEY_UNABLE();
|
||||||
|
|
||||||
// NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
|
// NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
|
||||||
// This takes 25us or more to make sure KEY_STATE returns to idle state.
|
// This takes 25us or more to make sure KEY_STATE returns to idle state.
|
||||||
#ifdef HHKB_JP
|
|
||||||
// Looks like JP needs faster scan due to its twice larger matrix
|
|
||||||
// or it can drop keys in fast key typing
|
|
||||||
_delay_us(30);
|
|
||||||
#else
|
|
||||||
_delay_us(75);
|
_delay_us(75);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if (matrix[row] ^ matrix_prev[row]) matrix_last_modified = timer_read32();
|
if (matrix[row] ^ matrix_prev[row]) {
|
||||||
}
|
matrix_last_modified = timer_read32();
|
||||||
// power off
|
}
|
||||||
if (KEY_POWER_STATE() &&
|
|
||||||
(USB_DeviceState == DEVICE_STATE_Suspended ||
|
|
||||||
USB_DeviceState == DEVICE_STATE_Unattached ) &&
|
|
||||||
timer_elapsed32(matrix_last_modified) > MATRIX_POWER_SAVE) {
|
|
||||||
KEY_POWER_OFF();
|
|
||||||
suspend_power_down();
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -147,9 +125,9 @@ matrix_row_t matrix_get_row(uint8_t row)
|
||||||
return matrix[row];
|
return matrix[row];
|
||||||
}
|
}
|
||||||
|
|
||||||
void matrix_power_up(void) {
|
void led_set(uint8_t usb_led)
|
||||||
KEY_POWER_ON();
|
{
|
||||||
}
|
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
||||||
void matrix_power_down(void) {
|
} else {
|
||||||
KEY_POWER_OFF();
|
}
|
||||||
}
|
}
|
||||||
70
keyboard/fc660c/fc660c.h
Normal file
70
keyboard/fc660c/fc660c.h
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
#ifndef FC660C_H
|
||||||
|
#define FC660C_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
||||||
Loading…
Add table
Reference in a new issue