Author Topic: [TMK] FC660C Alt Controller  (Read 74338 times)

0 Members and 1 Guest are viewing this topic.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: [TMK] FC660C Alt Controller
« Reply #100 on: Wed, 23 December 2020, 16:56:32 »
Yes, you just have to add '+' prefixed lines.
What's you file name? What command do you compile it with?

Port PB5 is used for Instert LED and PB6 for CapsLock LED. You will have to change only LED_ON and  LED_OFF.

Offline microCuts

  • Posts: 10
Re: [TMK] FC660C Alt Controller
« Reply #101 on: Wed, 23 December 2020, 21:38:37 »
Ya i understand so i tried with both LED on first. However it gives no response on my own compiled hex.

This is the full codes of my keymap.c

-----------------------------------------------------------------------------
#include QMK_KEYBOARD_H

#define _LAYER0 0
#define _LAYER1 1
#define _LAYER2 2
#define _LAYER3 3

enum custom_keycodes {
    LAYER0 = SAFE_RANGE,
    LAYER1,
    LAYER2,
    LAYER3,
};

 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

 [_LAYER0] = LAYOUT(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_HOME, 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_DEL, KC_END, 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_LALT, MO(3), KC_LGUI, KC_SPC, MO(3), KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT),

[_LAYER1] = LAYOUT(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_HOME, 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_DEL, KC_END, 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, MO(3), KC_LALT, KC_SPC, MO(3), KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT),

[_LAYER2] = LAYOUT(KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_7, KC_8, KC_9, KC_PMNS, KC_PMNS, KC_NO, KC_BSPC, KC_HOME, KC_NO, KC_NO, KC_UP, KC_NO, KC_NO, KC_NO, KC_NO, KC_P4, KC_P5, KC_P6, KC_PPLS, KC_NO, KC_NO, KC_DEL, KC_END, KC_NO, KC_LEFT, KC_DOWN, KC_RGHT, KC_NO, KC_NO, KC_NO, KC_P1, KC_P2, KC_P3, KC_PPLS, KC_NO, KC_ENT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_P0, KC_P0, KC_PDOT, KC_NO, TG(2), KC_UP, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, KC_DOWN, KC_RGHT),

[_LAYER3] = LAYOUT(KC_TILD, 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_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PIPE, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_TRNS, TG(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS)

};

#define LED_ON()        PORTB &= ~(1<<5 | 1<<6)
#define LED_OFF()       PORTB |=  (1<<5 | 1<<6)
#define LED_DURATION    100
static uint16_t last_ms = 0;
void hook_matrix_change(keyevent_t event) {
    if (event.pressed) {
        LED_ON();
        last_ms = timer_read();
    }
}

void hook_keyboard_loop(void) {
    if (TIMER_DIFF_16(last_ms, timer_read()) > LED_DURATION) {
        LED_OFF();
    }
}
-----------------------------------------------------------------------------------------

Not really sure what is wrong as my coding knowledge is very limited..

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: [TMK] FC660C Alt Controller
« Reply #102 on: Wed, 23 December 2020, 21:45:18 »
That patche is for TMK and won't work with QMK. You have to port the code to QMK.
I think you can consult with its document and comunity.

Offline microCuts

  • Posts: 10
Re: [TMK] FC660C Alt Controller
« Reply #103 on: Wed, 23 December 2020, 22:05:02 »
Understand and thanks! Will explore that my own :)

Offline skimzor

  • Posts: 37
  • Location: San Jose, CA
Re: [TMK] FC660C Alt Controller
« Reply #104 on: Thu, 24 December 2020, 20:11:31 »
hi hasu.  thank you for providing the schematics to make my own controller.  i pretty much copied your controller but i'm using different pins.  i kind of understand some of the TMK code, but am at a loss on how to assign the pins for the rows and columns.  am i on the right track with the following code?

Code: [Select]
* Pin configuration for ATMega32U4
 *
 * Row:     PB6, PF7, PB5, PB7(~EN)
 * Col:     PF6, PB4, PF5, PD7(Z5 ~EN), PF4(Z4 ~EN)
 * Key:     PD4(pull-uped)
 * Hys:     PF0
 */

static inline void KEY_ENABLE(void) { (PORTB &= ~(1<<7)); }
static inline void KEY_UNABLE(void) { (PORTB |= (1<<7)); }
static inline bool KEY_STATE(void) { return (PIND & (1<<4)); }
static incline void KEY_HYS_ON(void) {PORTF |= (1<<0)); }
static inline void KEY_HYS_OFF(void) { (PORTF &= ~(1<<0)); }
static inline void KEY_INIT(void)
{
    /* Col */
    DDRB  |=  0x10;
    DDRD  |=  0x80;
    DDRF  |=  0x70;
    /* Key: input with pull-up */
    DDRD  &= ~(1<<4);
    PORTD |=  (1<<4);
    /* Hys */
    DDRF  |=  (1<<0);
    /* Row */
    DDRB  |=  0xE0;
    DDRF  |=  0x80;

    KEY_UNABLE();
    KEY_HYS_OFF();
}

if the above is correct, how would i set the row and col in the next few lines?  thank you for all your work!

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: [TMK] FC660C Alt Controller
« Reply #105 on: Thu, 24 December 2020, 21:15:19 »
You looks so.

I can't say if your code is correct totally, because I don't have time enough to check it closely and don't know exact your pin configuration.
You can share your circuit schematic and pics of pcb here to get further help. And what's your problem exactly? Your code didn't work?

Also share your entire code on github(or other site), it would be useful for the community.

You may want to check fc660c.c and read the first post to understand how FC660C controller scans its key matrix. I'd reccomend to take time to do this.
https://github.com/tmk/tmk_keyboard/tree/master/keyboard/fc660c

And note that you can use `xprintf()` to debug your code. It is extremely useful when tweaking code.

Offline skimzor

  • Posts: 37
  • Location: San Jose, CA
Re: [TMK] FC660C Alt Controller
« Reply #106 on: Fri, 25 December 2020, 11:59:22 »
Hi hasu - thank you for taking a look.

I think I understand how to assign the row and column pins, but I'm not sure how to set them if that makes sense?  Particularly the SET_ROW and SET_COL lines:

Code: [Select]
#ifndef FC660C_H
#define FC660C_H

#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "timer.h"
#include "unimap.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:     PB5, PB6, PB7(~EN), PF7
 * Col:     PF4(Z4 ~EN), PF5, PF6, PD7(Z5 ~EN), PF5
 * Key:     PD4(pull-uped)
 * Hys:     PF0
 */
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  |=  0x10;
    DDRD  |=  0x80;
    DDRF  |=  0x70;
    /* Key: input with pull-up */
    DDRD  &= ~(1<<4);
    PORTD |=  (1<<4);
    /* Hys */
    DDRF  |=  (1<<0);
    /* Row */
    DDRB  |=  0xE0;
    DDRF  |=  0x80;

    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)
{
    //         |PD7(Z5 ~EN)|PF4(Z4 ~EN)
    // --------|-----------|-----------
    // Col:0-7 |high       |low
    // Col:8-F |low        |high
    PORTB = (PORTB & 0xE0) | ((COL & 0x08) ? 1<<4 : 1<<3) | (COL & 0x07);
}

Thank you for your help!
https://github.com/skimzor/sz660c-altctrl
« Last Edit: Sun, 27 December 2020, 10:11:12 by skimzor »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: [TMK] FC660C Alt Controller
« Reply #107 on: Fri, 25 December 2020, 19:01:26 »
I can't remember the details without traversing schematic and my code again but I think the macros just drive matrix lines one by one with multiplexers(4051, 138).
If you read schematic and datasheets closely  it would be straight, no tricks there.

Nice pcb layout! Btw, what is J3 connector for?

Offline skimzor

  • Posts: 37
  • Location: San Jose, CA
Re: [TMK] FC660C Alt Controller
« Reply #108 on: Fri, 25 December 2020, 19:44:41 »
I think I understand, but I'm quite new to the firmware coding aspect of keyboards so I'll have to keep playing around with it.  The J3 connector is for a companion MX/ALPS PCB that fits in the FC660C case.  It uses an additional 5 unused pins from the atmega for the PCB matrix (firmware for mechanical switches are way easier than capacitance :D).  So users have the choice of flashing different firmware based on what PCB they're using.

It works using the OEM cable, but I need to source some DF14 cable harnesses that are long enough to reach the PCB connector. 

« Last Edit: Sun, 27 December 2020, 10:11:23 by skimzor »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: [TMK] FC660C Alt Controller
« Reply #109 on: Fri, 25 December 2020, 21:15:42 »
Looks great!
Good luck with your project.


Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: [TMK] FC660C Alt Controller
« Reply #110 on: Sat, 21 August 2021, 06:06:53 »
I just got question about Esc/~` behaviour by email and found that this link was not in the first post.

Emulation keymap: http://www.tmk-kbd.com/tmk_keyboard/editor/unimap/?fc660c_emu

This keymap emulates FC660C stock behaviour on Esc/~`, Fn+Esc and Fn+q.

Also added 'How to control LEDs' section.


Offline MatthewEncina

  • Posts: 1
Re: [TMK] FC660C Alt Controller
« Reply #111 on: Sun, 27 March 2022, 08:54:37 »
Curious if anyone has been able to make the board VIA compatible?

I saw this on Github, (https://github.com/qmk/qmk_firmware/tree/master/keyboards/fc660c/keymaps/via) but I'm completely out of my depths on how to make this work?. Do I add something from here to the HEX file manually? Any help is greatly appreciated!