diff options
author | Balz Guenat <balz.guenat@gmail.com> | 2017-11-26 08:17:14 +0100 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2017-11-26 02:17:14 -0500 |
commit | 18525aa17b744436a2f35f7e5391820491dbc886 (patch) | |
tree | 031d80cc64c578b43c4a5e4c3c67bc5d3d2cf0d1 /keyboards/fc660c | |
parent | ac3d9ab76132f589b3a69f57f71e276871001af9 (diff) | |
download | qmk_firmware-18525aa17b744436a2f35f7e5391820491dbc886.tar.gz qmk_firmware-18525aa17b744436a2f35f7e5391820491dbc886.zip |
Fc660c port (#2060)
* Port Hasu's FC660C controller to QMK
* fix column mask
Diffstat (limited to 'keyboards/fc660c')
-rw-r--r-- | keyboards/fc660c/README.md | 156 | ||||
-rw-r--r-- | keyboards/fc660c/config.h | 80 | ||||
-rw-r--r-- | keyboards/fc660c/fc660c.c | 48 | ||||
-rw-r--r-- | keyboards/fc660c/fc660c.h | 57 | ||||
-rw-r--r-- | keyboards/fc660c/keymaps/default/README.md | 5 | ||||
-rw-r--r-- | keyboards/fc660c/keymaps/default/config.h | 24 | ||||
-rw-r--r-- | keyboards/fc660c/keymaps/default/keymap.c | 37 | ||||
-rw-r--r-- | keyboards/fc660c/matrix.c | 226 | ||||
-rw-r--r-- | keyboards/fc660c/rules.mk | 64 |
9 files changed, 697 insertions, 0 deletions
diff --git a/keyboards/fc660c/README.md b/keyboards/fc660c/README.md new file mode 100644 index 0000000000..ce84abad83 --- /dev/null +++ b/keyboards/fc660c/README.md @@ -0,0 +1,156 @@ +FC660C Alt Controller +================= + +This file and the entire QMK port of this board are based on its TMK implementation: https://github.com/tmk/tmk_keyboard/tree/master/keyboard/fc980c + +------------ + +- Keyboard Maintainer: [Balz Guenat](https://github.com/BalzGuenat) +- Hardware Supported: Hasu's Alt Controller (see below) +- Hardware Availability: https://geekhack.org/index.php?topic=90317.0 + +Make example for this keyboard (after setting up your build environment): + + make fc660c:default + +See [build environment setup](https://docs.qmk.fm/build_environment_setup.html) then the [make instructions](https://docs.qmk.fm/make_instructions.html) for more information. + +To flash the firmware, press the reset button on the controller and run: + + sudo make fc660c:default:dfu + +-------- + +Thread on Geekhack: https://geekhack.org/index.php?topic=88439.0 + +Also: https://geekhack.org/index.php?topic=88720.0 + +Pinouts +------- + + |Switch |Controller | + | board | board |Description |Schematic |ATmega32u4 + |--------|-----------|--------------------------------------|-----------|------------ + | 1 |20 | FG |FG |GND + | 2 |19 | GND |GND |GND + | 3 |18 | GND |GND |GND + | 4 |17 | 3.3V |V33 |3.3V/5V + | 5 |16 | 5V |Vcc |5V + | 6 |15 |*Z6-TP1684-4-HYS(o) |FBSTB |PC7 + | 7 |14 |*Z6-TP1684-2-KEY(i) |OUT |PC6 + | 8 |13 |*Z2-AD5258-5-SCL(I2C) |SCL |PD0(TWI) + | 9 |12 |*Z2-AD5258-4-SDA(I2C) |SDA |PD1(TWI) + |10 |11 |*Z4-LV4051A-6-~EN(Col 0-7) |INH_1 |PB4 + |11 |10 |*Z5-LV4051A-6-~EN(Col 8-F) |INH_2 |PB3 + |12 | 9 |+Z7-LV07A-5 (LV4051A-9-C) |SEL_C |PB2 + |13 | 8 |+Z7-LV07A-1 (LV4051A-10-B) |SEL_B |PB1 + |14 | 7 |+Z7-LV07A-3 (LV4051A-11-A) |SEL_A |PB0 + |15 | 6 |+Z3-LVC138A-3-C |COL4 |PD6 + |16 | 5 |+Z3-LVC138A-2-B |COL3 |PD5 + |17 | 4 |+Z3-LVC138A-1-A |COL2 |PD4 + |18 | 3 |+Z3-LVC138A-4-~G2A Z6-TP1684-5-~EN |COL1 |PD7 + |19 | 2 |+Z7-LV07A-11-~InsertLED |LED1 |PB5 + |20 | 1 |+Z7-LV07A-13-~CapsLED |LED2 |PB6 + +``` +* 5V intferface ++ 3.3V interface +``` + +- Connector on Switch board: https://i.imgur.com/Zi89xO5.jpg +- Connector on Controller board: https://i.imgur.com/9SZUzYo.jpg + + +Key Matrix +---------- +Row5-7 have no key, you can omit scaning on those lines. Topre original controller scans those rows for some reason. + + | |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |A |B |C |D |E |F | + |----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----| + | 0|Q |W |E |Tab |R |U |T |Y |O |P |[ |I |] | |\ |Del | + | 1|1 |2 |3 |Esc |4 |7 |5 |6 |9 |0 |- |8 |= | |BSpc|Ins | + | 2| |LWin|LAlt|LCtl| | | |Spc |RAlt| |RCtl| |Fn |Down|Left|Rght| + | 3| |Z |X |LSft|C |N |V |B |, |. |/ |M |RSft|Up | | | + | 4|A |S |D |Caps|F |J |G |H |L |; |' |K | | |Entr| | + | 5| | | | | | | | | | | | | | | | | + | 6| | | | | | | | | | | | | | | | | + | 7| | | | | | | | | | | | | | | | | + +Logic analyzer pics: +- http://i.imgur.com/9XoNTev.png +- https://i.imgur.com/5FCP1Ay.png + +This code emuluates what original cotnroller does for matrix scan. +- https://github.com/tmk/tmk_keyboard/blob/master/keyboard/fc660c/fc660c.c + + +### Row designation +LV138A(Z3) selects a row line and gives strobe by enabling with ~G2A(18). + + |Row |A/17|B/16|C/15| + |----|----|----|----| + |0 |0 |0 |0 | + |1 |1 |0 |0 | + |2 |0 |1 |0 | + |3 |1 |1 |0 | + |4 |0 |0 |1 | + |5 |1 |0 |1 | + |6 |0 |1 |1 | + |7 |1 |1 |1 | + + +### Column designation +LV4051A(Z4, Z5) select one of 16 column lines to sense capacitance of switches. + + |Col |A/14|B/13|C/12|Z4-EN/10|Z5-EN/11| + |----|----|----|----|--------|--------| + |0 |0 |0 |0 |0 |1 | + |1 |1 |0 |0 |0 |1 | + |2 |0 |1 |0 |0 |1 | + |3 |1 |1 |0 |0 |1 | + |4 |0 |0 |1 |0 |1 | + |5 |1 |0 |1 |0 |1 | + |6 |0 |1 |1 |0 |1 | + |7 |1 |1 |1 |0 |1 | + |8 |0 |0 |0 |1 |0 | + |9 |1 |0 |0 |1 |0 | + |A |0 |1 |0 |1 |0 | + |B |1 |1 |0 |1 |0 | + |C |0 |0 |1 |1 |0 | + |D |1 |0 |1 |1 |0 | + |E |0 |1 |1 |1 |0 | + |F |1 |1 |1 |1 |0 | + + +FCC documents +------------- +https://fccid.io/RPKFC660C + +- schematic: https://fccid.io/pdf.php?id=1888185 +- part list: https://fccid.io/pdf.php?id=1888184 + + +Datasheets +---------- +- Hirose DF14A-20P-1.25H: http://www.mouser.com/ds/2/185/DF14_catalog-939195.pdf +- LV07A: http://www.ti.com/lit/ds/symlink/sn74lv07a.pdf +- LV138A: http://www.ti.com/lit/ds/symlink/sn74lvc138a.pdf +- LV4051A: http://www.ti.com/lit/ds/symlink/sn74lv4051a.pdf +- AD5258: http://www.analog.com/media/en/technical-documentation/data-sheets/AD5258.pdf + + +3.3V power supply +----------------- +LV07A and LVC138A are 5V-tolerant and can be powered with 5V, the keyboard will work only with 5V power supply. It may not be completely safe to operate LV138A with 5V Vcc, its datasheet says: + +> Exposure to absolute-maximum-rated conditions for extended periods may affect device reliability. + +Digipot AD5258 +-------------- +Controller can operate AD5258 via I2C to change actuation point of keys. This may make keyboard unusable accidentally and it will be difficult to recovery in some situation. For safety firmware doesn't support it at this point, though. + +Lower value of RDAC register causes shallower actuation point. + +Resources +--------- +- Pics: https://imgur.com/a/UTR8Z diff --git a/keyboards/fc660c/config.h b/keyboards/fc660c/config.h new file mode 100644 index 0000000000..0afd374a0c --- /dev/null +++ b/keyboards/fc660c/config.h @@ -0,0 +1,80 @@ +/* +Copyright 2017 Balz Guenat + +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 + +#include "config_common.h" + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x660C +#define DEVICE_VER 0x0100 +#define MANUFACTURER QMK +#define PRODUCT Leopold FC660C with QMK +#define DESCRIPTION Leopold FC660C with Hasu alternative controller using QMK + +/* key matrix size */ +#define MATRIX_ROWS 8 +#define MATRIX_COLS 16 + +#define DIODE_DIRECTION CUSTOM_MATRIX + +/* define if matrix has ghost */ +//#define MATRIX_HAS_GHOST + +/* number of backlight levels */ +// #define BACKLIGHT_LEVELS 1 + +/* mapping backlight LEDs to correct Pin */ +// #define BACKLIGHT_PIN B7 + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCING_DELAY 0 +#define TAPPING_TERM 175 + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +// #define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +// #define LOCKING_RESYNC_ENABLE + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + + + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + +#endif diff --git a/keyboards/fc660c/fc660c.c b/keyboards/fc660c/fc660c.c new file mode 100644 index 0000000000..f2a5617672 --- /dev/null +++ b/keyboards/fc660c/fc660c.c @@ -0,0 +1,48 @@ +/* +Copyright 2017 Balz Guenat + +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 "fc660c.h" + +void matrix_init_kb(void) { + // put your keyboard start-up code here + // runs once when the firmware starts up + + matrix_init_user(); +} + +void matrix_scan_kb(void) { + // put your looping keyboard code here + // runs every cycle (a lot) + + matrix_scan_user(); +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + // put your per-action keyboard code here + // runs for every action, just before processing by the firmware + + return process_record_user(keycode, record); +} + +void led_set_kb(uint8_t usb_led) { + if (usb_led & (1<<USB_LED_CAPS_LOCK)) { + PORTB &= ~(1<<6); + } else { + PORTB |= (1<<6); + } + + led_set_user(usb_led); +} diff --git a/keyboards/fc660c/fc660c.h b/keyboards/fc660c/fc660c.h new file mode 100644 index 0000000000..6139dee015 --- /dev/null +++ b/keyboards/fc660c/fc660c.h @@ -0,0 +1,57 @@ +/* +Copyright 2017 Balz Guenat + +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 FC660C_H +#define FC660C_H + +#include "quantum.h" + + +#define KEYMAP( \ + K13, K10, K11, K12, K14, K16, K17, K15, K1B, K18, K19, K1A, K1C, K1E, K1F, \ + K03, K00, K01, K02, K04, K06, K07, K05, K0B, K08, K09, K0A, K0C, K0E, K0F, \ + K43, K40, K41, K42, K44, K46, K47, K45, K4B, K48, K49, K4A, K4E, \ + K33, K31, K32, K34, K36, K37, K35, K3B, K38, K39, K3A, K3C, K3D, \ + K23, K21, K22, K27, K28, K2A, K2C, K2E, K2D, K2F \ +) { \ + { K00, K01, K02, K03, K04, K05, K06, K07, \ + K08, K09, K0A, K0B, K0C, KC_NO, K0E, K0F }, \ + { K10, K11, K12, K13, K14, K15, K16, K17, \ + K18, K19, K1A, K1B, K1C, KC_NO, K1E, K1F }, \ + { KC_NO, K21, K22, K23, KC_NO, KC_NO, KC_NO, K27, \ + K28, KC_NO, K2A, KC_NO, K2C, K2D, K2E, K2F }, \ + { KC_NO, K31, K32, K33, K34, K35, K36, K37, \ + K38, K39, K3A, K3B, K3C, K3D, KC_NO, KC_NO }, \ + { K40, K41, K42, K43, K44, K45, K46, K47, \ + K48, K49, K4A, K4B, KC_NO, KC_NO, K4E, KC_NO }, \ + { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, \ + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, \ + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ + { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, \ + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO } \ +} +/* +KEYMAP( + _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, + _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, + _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, + _______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, _______, + _______,_______,_______, _______, _______,_______,_______, _______,_______,_______ + ) +*/ + +#endif diff --git a/keyboards/fc660c/keymaps/default/README.md b/keyboards/fc660c/keymaps/default/README.md new file mode 100644 index 0000000000..f813ed0c3e --- /dev/null +++ b/keyboards/fc660c/keymaps/default/README.md @@ -0,0 +1,5 @@ +# The default keymap for the FC660C + +Emulates original keymap. + +![](https://i.imgur.com/fg89nez.jpg)
\ No newline at end of file diff --git a/keyboards/fc660c/keymaps/default/config.h b/keyboards/fc660c/keymaps/default/config.h new file mode 100644 index 0000000000..596198be10 --- /dev/null +++ b/keyboards/fc660c/keymaps/default/config.h @@ -0,0 +1,24 @@ +/* Copyright 2017 Balz Guenat + * + * 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_USER_H +#define CONFIG_USER_H + +#include "config_common.h" + +// place overrides here + +#endif diff --git a/keyboards/fc660c/keymaps/default/keymap.c b/keyboards/fc660c/keymaps/default/keymap.c new file mode 100644 index 0000000000..02f57532ba --- /dev/null +++ b/keyboards/fc660c/keymaps/default/keymap.c @@ -0,0 +1,37 @@ +/* +Copyright 2017 Balz Guenat + +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 "fc660c.h" + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = KEYMAP( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_BSPC, KC_INS, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, KC_DEL, + KC_CAPS,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, + KC_LSFT,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH,KC_RSFT, KC_UP, + KC_LCTL,KC_LGUI,KC_LALT, KC_SPC, KC_RALT,KC_RCTL,MO(1), KC_LEFT,KC_DOWN,KC_RGHT + ), + [1] = KEYMAP( + KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, + _______,_______,_______,_______,_______,_______,_______,_______,KC_PSCR,KC_SLCK,KC_PAUS,_______,_______,_______, _______, + _______,_______,_______,_______,_______,_______,_______,_______,KC_HOME,KC_PGUP,_______,_______, _______, + _______,_______,_______,_______,_______,_______,_______,_______,KC_END, KC_PGDN,_______,_______, _______, + _______,_______,_______, _______, _______,_______,MO(1), _______,_______,_______ + ) +}; + +const uint16_t PROGMEM fn_actions[] = { +}; diff --git a/keyboards/fc660c/matrix.c b/keyboards/fc660c/matrix.c new file mode 100644 index 0000000000..211506fdf3 --- /dev/null +++ b/keyboards/fc660c/matrix.c @@ -0,0 +1,226 @@ +/* +Copyright 2017 Balz Guenat +based on work by 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/>. +*/ + +/* + * scan matrix + */ +#include <stdint.h> +#include <stdbool.h> +#include <util/delay.h> +#include "print.h" +#include "debug.h" +#include "util.h" +#include "timer.h" +#include "matrix.h" +#include "led.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 + + +/* + * 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); +} + +static uint32_t matrix_last_modified = 0; + +// matrix state buffer(1:on, 0:off) +static matrix_row_t *matrix; +static matrix_row_t *matrix_prev; +static matrix_row_t _matrix0[MATRIX_ROWS]; +static matrix_row_t _matrix1[MATRIX_ROWS]; + + +__attribute__ ((weak)) +void matrix_init_quantum(void) { + matrix_init_kb(); +} + +__attribute__ ((weak)) +void matrix_scan_quantum(void) { + matrix_scan_kb(); +} + +__attribute__ ((weak)) +void matrix_init_kb(void) { + matrix_init_user(); +} + +__attribute__ ((weak)) +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +__attribute__ ((weak)) +void matrix_init_user(void) { +} + +__attribute__ ((weak)) +void matrix_scan_user(void) { +} + + +void matrix_init(void) +{ + KEY_INIT(); + + // LEDs on CapsLock and Insert + DDRB |= (1<<5) | (1<<6); + PORTB |= (1<<5) | (1<<6); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; + for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; + matrix = _matrix0; + matrix_prev = _matrix1; + matrix_init_quantum(); +} + +uint8_t matrix_scan(void) +{ + matrix_row_t *tmp; + + tmp = matrix_prev; + matrix_prev = matrix; + matrix = tmp; + + 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<<col)) { + KEY_HYS_ON(); + } + _delay_us(10); + + // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE. + // If V-USB interrupts in this section we could lose 40us or so + // and would read invalid value from KEY_STATE. + uint8_t last = TIMER_RAW; + + KEY_ENABLE(); + + // Wait for KEY_STATE outputs its value. + _delay_us(2); + + if (KEY_STATE()) { + matrix[row] &= ~(1<<col); + } else { + matrix[row] |= (1<<col); + } + + // Ignore if this code region execution time elapses more than 20us. + // MEMO: 20[us] * (TIMER_RAW_FREQ / 1000000)[count per us] + // MEMO: then change above using this rule: a/(b/c) = a*1/(b/c) = a*(c/b) + if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) { + matrix[row] = matrix_prev[row]; + } + + _delay_us(5); + KEY_HYS_OFF(); + KEY_UNABLE(); + + // 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. + _delay_us(75); + } + if (matrix[row] ^ matrix_prev[row]) { + matrix_last_modified = timer_read32(); + } + } + matrix_scan_quantum(); + return 1; +} + +inline +matrix_row_t matrix_get_row(uint8_t row) { + return matrix[row]; +} + +void matrix_print(void) +{ +#if (MATRIX_COLS <= 8) + print("r/c 01234567\n"); +#elif (MATRIX_COLS <= 16) + print("r/c 0123456789ABCDEF\n"); +#elif (MATRIX_COLS <= 32) + print("r/c 0123456789ABCDEF0123456789ABCDEF\n"); +#endif + + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + +#if (MATRIX_COLS <= 8) + xprintf("%02X: %08b%s\n", row, bitrev(matrix_get_row(row)), +#elif (MATRIX_COLS <= 16) + xprintf("%02X: %016b%s\n", row, bitrev16(matrix_get_row(row)), +#elif (MATRIX_COLS <= 32) + xprintf("%02X: %032b%s\n", row, bitrev32(matrix_get_row(row)), +#endif +#ifdef MATRIX_HAS_GHOST + matrix_has_ghost_in_row(row) ? " <ghost" : "" +#else + "" +#endif + ); + } +} diff --git a/keyboards/fc660c/rules.mk b/keyboards/fc660c/rules.mk new file mode 100644 index 0000000000..883f7e657c --- /dev/null +++ b/keyboards/fc660c/rules.mk @@ -0,0 +1,64 @@ +# MCU name +MCU = atmega32u4 + +# 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) + +# Interrupt driven control endpoint task(+60) +OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Teensy++ halfKay 1024 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +# USBaspLoader 2048 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + + +# 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 ?= yes # Console for debug(+400) +COMMAND_ENABLE ?= yes # Commands for debug and configuration +NKRO_ENABLE ?= yes # USB Nkey Rollover - not yet supported in LUFA + +# Optimize size but this may cause error "relocation truncated to fit" +#EXTRALDFLAGS = -Wl,--relax + +CUSTOM_MATRIX = yes +SRC += matrix.c |