Author Topic: TMK keyboard firmware  (Read 818514 times)

0 Members and 1 Guest are viewing this topic.

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #150 on: Wed, 04 September 2013, 09:46:22 »
Thanks for all the help so far. I have a couple more questions though. What is the MATRIX_HAS_GHOST function (not sure if that's the right term)? I see it in the config.h and the matrix.c files for the different keyboard projects, so I looked it up in keyboard.c in the common directory. Some keyboard projects have this commented out in config.h, some don't. What does it do and how do I know if I need it?
Code: [Select]
#ifdef MATRIX_HAS_GHOST
static bool has_ghost_in_row(uint8_t row)
{
    matrix_row_t matrix_row = matrix_get_row(row);
    // No ghost exists when less than 2 keys are down on the row
    if (((matrix_row - 1) & matrix_row) == 0)
        return false;

    // Ghost occurs when the row shares column line with other row
    for (uint8_t i=0; i < MATRIX_ROWS; i++) {
        if (i != row && (matrix_get_row(i) & matrix_row))
            return true;
    }
    return false;
}
#endif

My second question is about the available pins on the Teensy++ 2.0. Are there any other pins beside PE2 (ALE) that I shouldn't use for my matrix or LEDs? I know PD6 is connected to the onboard LED, which precludes it's use unless I want the light flashing.
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #151 on: Wed, 04 September 2013, 12:30:23 »
Thanks for all the help so far. I have a couple more questions though. What is the MATRIX_HAS_GHOST function (not sure if that's the right term)? I see it in the config.h and the matrix.c files for the different keyboard projects, so I looked it up in keyboard.c in the common directory. Some keyboard projects have this commented out in config.h, some don't. What does it do and how do I know if I need it?
It checks ghost and blocks its phantom keys on the matrix. You don't need this option if your matrix is 'what we call' NKRO with full of diodes. Some of cheap mechanical boards and most of mebrane boards are not NKRO and they need this option.

Quote
My second question is about the available pins on the Teensy++ 2.0. Are there any other pins beside PE2 (ALE) that I shouldn't use for my matrix or LEDs? I know PD6 is connected to the onboard LED, which precludes it's use unless I want the light flashing.
I think you are right. All other pins can be used except for those two.

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #152 on: Sat, 07 September 2013, 04:58:05 »
Well, I have the keyboard working now, and I've only come across one issue I haven't been able to figure out: If the keyboard is plugged in when the computer is restarted (or shut down and powered up), windows ignores the input. I can use hid_listen and watch all the debug info, so I know the keyboard is working, windows just seems to be ignoring it. I can also duplicate this behavior on my laptop. Both computers are running Windows 7 x64. Unplugging the keyboard and plugging it back in restores it's full functionality. This problem does not happen if I boot with Ubuntu.

Has this happened to anyone else? Where should I begin looking for a solution to this?
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #153 on: Sun, 08 September 2013, 00:08:59 »
To be hoest, I didn't test my firmware under boot/reboot, BIOS or boot selector like ntldr, grub and etc, and my code is not completely conformed to USB/HID spec, this may cause this problem on Windows. So I'm sure problems like this can remain to exist in my code.

In this moment I don't have no computers to reboot and test handily, I'll try to confirm this later.
Debuging during boot time is cumbersome :(

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #154 on: Sun, 08 September 2013, 00:32:26 »
I have 3 computers to play with, and a range of windows versions to choose from, so let me know if I can be of any help. I can confirm that the keyboard works fine on POST and in the BIOS/UEFI of all three, it just seems to be a problem with windows. I can even access the OS boot options via F8 (e.g. "Safe Mode"), but once windows has loaded, it ignores the input until the keyboard is rebooted.

Though my coding/debugging skills are EXTREMELY elementary, I'd be happy to help in any way I can.

EDIT: Rebuilding with the LUFA stack instead of PJRC has eliminated this problem.
« Last Edit: Sun, 08 September 2013, 07:25:58 by StrikeEagleCC »
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline domoaligato

  • * Exquisite Elder
  • Posts: 1672
  • Location: USA
  • All your base are belong to us!
    • All your base are belong to us!
Re: TMK keyboard firmware
« Reply #155 on: Sun, 08 September 2013, 11:33:08 »
I have 3 computers to play with, and a range of windows versions to choose from, so let me know if I can be of any help. I can confirm that the keyboard works fine on POST and in the BIOS/UEFI of all three, it just seems to be a problem with windows. I can even access the OS boot options via F8 (e.g. "Safe Mode"), but once windows has loaded, it ignores the input until the keyboard is rebooted.

Though my coding/debugging skills are EXTREMELY elementary, I'd be happy to help in any way I can.

EDIT: Rebuilding with the LUFA stack instead of PJRC has eliminated this problem.



I am glad to hear that you got it fixed.

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #156 on: Sun, 08 September 2013, 11:46:17 »
How can I make an LED light when a specific layer is active?
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline agor

  • Posts: 282
  • Location: Germany
Re: TMK keyboard firmware
« Reply #157 on: Mon, 09 September 2013, 05:03:06 »
Is it possible to use all 4 LED's on a Phantom for different purposes? I currently only use the in-key-LED's for ScrLk and CapsLock, but the two additional LED slots could also be used for my Function Layers.
KBD8X II - MX 5000 - Realforce 88UB - Phantom - GH60

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #158 on: Mon, 09 September 2013, 07:03:02 »
TMK itself doesn't support any keyboard specific LEDs except for statndard indicators defined in HID spec such like Caps lock Scroll lock and Num lock.

It is possible if you write code for those LEDs yourself.

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #159 on: Mon, 09 September 2013, 07:24:00 »
If anyone has done this and is willing to share, I'd be very interested in seeing it.

Does there exist a function that will return the number of the active layer? If such a function existed, let's call it get_layer(), couldn't I just add in led.c something like this to turn on an LED on PB0 when layer 1 is active?
Code: [Select]
if (get_layer()==1)
    {
        // Output high.
        DDRB |= (1<<0);
        PORTB |= (1<<0);
    }
    else
    {
        // Output low.
        DDRB &= ~(1<<0);
        PORTB &= ~(1<<0);
    }

Could pgm_read_byte() be used for this purpose?
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #160 on: Mon, 09 September 2013, 07:57:12 »
Thanks StrikeEagleCC,

I filed this problem on github issue tracker for the sake of other users and myself.

EDIT: Rebuilding with the LUFA stack instead of PJRC has eliminated this problem.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #161 on: Mon, 09 September 2013, 08:18:22 »
Does there exist a function that will return the number of the active layer? If such a function existed, let's call it get_layer(), couldn't I just add in led.c something like this to turn on an LED on PB0 when layer 1 is active?
You can get current state of keymap layers from 'default_layer_state' and 'layer_state' in action_layer.h.

The problem is how and where you should update those layer LEDs. At this time I cannot come up with suitable hassle-free solution for this. I think you need to change codes of common/ directory.

led_set() in led.c is called only when CapsLock, NumLock or ScrollLock state of OS change. It is not useful  for this purpose.

Offline Tranquilite

  • Posts: 144
Re: TMK keyboard firmware
« Reply #162 on: Fri, 13 September 2013, 16:20:25 »
When I added LED layer indication to my Phantom, I used the following code snippet:
Code: [Select]
void led_set(uint8_t usb_led)
{
    if (biton32(layer_state) == 2)
    {
        // Output high.
        DDRB |= (1<<6);
        PORTB |= (1<<6);
    }
    else
    {
        // Output low.
        DDRB &= ~(1<<6);
        PORTB &= ~(1<<6);
    }

    if (biton32(layer_state) == 1)
    {
        // Output high.
        DDRB &= ~(1<<7);
        PORTB |= (1<<7);
    }
    else
    {
        // Output low.
        DDRB &= ~(1<<7);
        PORTB &= ~(1<<7);
    }
}

You will also want to include action_layer.h as well. Also what Hasu said about when/where to call led_set being a problem is definitely true. I think I just hacked up a messy solution where keyboard_task would always call keybaord_set_leds. It works well enough for me, but it is hardly an elegant solution.

Offline Sifo

  • Alter
  • * Exquisite Elder
  • Posts: 7487
  • Location: #GOLDSPRINGS, #LEGITBALLIN
  • Illustrious
Re: TMK keyboard firmware
« Reply #163 on: Sat, 21 September 2013, 12:54:07 »
For the HID_Liberation Device when I try to make I get this about half way through:



Was working fine before..

Now I'm getting Error 1's and my mkdir keeps crashing. etc.
« Last Edit: Sat, 21 September 2013, 16:51:20 by Sifo »
I love Elzy

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #164 on: Sat, 21 September 2013, 18:04:57 »
Umm, I'm not sure but your toolchain appears to suck. Need to reinstall?
I could compile hid_liber with WINAVR toolchain.

Offline Sifo

  • Alter
  • * Exquisite Elder
  • Posts: 7487
  • Location: #GOLDSPRINGS, #LEGITBALLIN
  • Illustrious
Re: TMK keyboard firmware
« Reply #165 on: Sat, 21 September 2013, 18:09:06 »
Tried reinstalling 5 times ... I don't know exactly what's wrong lol

I was able to compile my hid_liber before as well on this same machine, I don't know what caused the change.
I love Elzy

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #166 on: Sat, 21 September 2013, 18:16:15 »
What is your PATH setting?
Do you have other toolchain like Atmel Toolchain, AVR Studio or Atmel Studio?
Those tools probably can cause this error.


Offline Sifo

  • Alter
  • * Exquisite Elder
  • Posts: 7487
  • Location: #GOLDSPRINGS, #LEGITBALLIN
  • Illustrious
Re: TMK keyboard firmware
« Reply #167 on: Sun, 22 September 2013, 17:17:40 »
I don't know whta happened but it seems to have fixed itself for some boards (GH60 works) but phantom/HID_Liber doesn't..... weird.
I love Elzy

Offline oaklandishh

  • Posts: 68
  • Location: The Bay, CA
Re: TMK keyboard firmware
« Reply #168 on: Wed, 09 October 2013, 01:21:13 »
I posted this in another thread and was directed here. I am mostly looking for examples, and possibly a list of all the names of keys or things a key can do?
Quote
Is there any guide or help file on how to program macros? I have everything working except I am unsure on how to make macros work. I saw somewhere in this thread someone used MACRO(MD(KEY),D(KEY2),END)  does this work? is there a way to have it type something without making each key a D(KEY)? Thanks
Modify message

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #169 on: Wed, 09 October 2013, 03:36:36 »
You can use T(KEY) instead of D(KEY) and UP(KEY).
https://github.com/tmk/tmk_keyboard/blob/master/doc/keymap.md#23-macro-action

Note that all of Macro is on preliminary phase and not designed well at this moment, I have to rewrite it some time.

Offline oaklandishh

  • Posts: 68
  • Location: The Bay, CA
Re: TMK keyboard firmware
« Reply #170 on: Wed, 09 October 2013, 10:12:55 »
Thanks! so I guess typing something long will be bulky to write at this point. I also found https://github.com/tmk/tmk_keyboard/blob/master/doc/keycode.txt which I was looking for!

Offline Al3xG

  • Posts: 28
  • Location: Italy
Re: TMK keyboard firmware
« Reply #171 on: Thu, 10 October 2013, 09:44:47 »
There is any chance to support the new Kitten Paw controller for Filco 104 keys from bpiphany?

http://deskthority.net/wiki/Kitten_Paw

I've one and I can help with testing  ;)

Offline sean4star

  • Posts: 59
  • Location: Arlington, TX
Re: TMK keyboard firmware
« Reply #172 on: Fri, 18 October 2013, 10:09:30 »
Code: [Select]
[0] = ACTION_LAYER_TAP_KEY(2, KC_SCLN)
So, with this code the Fn0 key registers the ( ; ) key if tapped and momentarily switches to layer 2 if held.  I have 2 questions:

1. If you are pressing the shift key and then tap Fn0, will it register ( : )?

2. Could this be made to work the opposite way?  For example, if you had something like:
Code: [Select]
[0] = ACTION_LAYER_TAP_KEY(KC_LCTL, 2) If you tap Fn0 it will toggle layer 2 on, another tap will toggle layer 2 off.  But holding the key would register as holding the left Ctrl key.  I think this would be useful since I rarely just tap Ctrl.  I usually hold it while I press C or V or whatever.  I guess it also depends on how long a press has to be to not be a tap...


I'm a complete newbie to code and programming.  But I'm very interested in building my own custom keyboard.  This firmware is awesome!  Thanks for reading.


Edit:  Reading more of the keymap.md...Looks like I could get the action I want from #2 above by using the ACTION_MODS_TAP_KEY?

Code: [Select]
[0] = ACTION_MOD_TAP_KEY(KC_LCTL, KC_FN1)
[1] = ACTION_LAYER_TOGGLE(2)

Does this look right?  Of course this takes up 2 Fn keys, but with 32 available I should be just fine.
« Last Edit: Fri, 18 October 2013, 11:44:44 by sean4star »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #173 on: Fri, 18 October 2013, 15:01:17 »
There is any chance to support the new Kitten Paw controller for Filco 104 keys from bpiphany?

http://deskthority.net/wiki/Kitten_Paw

I've one and I can help with testing  ;)
Bpiphany did nice work again!
I don't any Filco and won't get his controller but I can help someone to port ;)

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #174 on: Fri, 18 October 2013, 15:16:01 »
1. Yes
2. Not supported. But it is possible technically.
You will be able to define that action in 'action_function'(common/action.h).

Code: [Select]
[0] = ACTION_LAYER_TAP_KEY(2, KC_SCLN)
So, with this code the Fn0 key registers the ( ; ) key if tapped and momentarily switches to layer 2 if held.  I have 2 questions:

1. If you are pressing the shift key and then tap Fn0, will it register ( : )?

2. Could this be made to work the opposite way?  For example, if you had something like:
Code: [Select]
[0] = ACTION_LAYER_TAP_KEY(KC_LCTL, 2) If you tap Fn0 it will toggle layer 2 on, another tap will toggle layer 2 off.  But holding the key would register as holding the left Ctrl key.  I think this would be useful since I rarely just tap Ctrl.  I usually hold it while I press C or V or whatever.  I guess it also depends on how long a press has to be to not be a tap...


I'm a complete newbie to code and programming.  But I'm very interested in building my own custom keyboard.  This firmware is awesome!  Thanks for reading.


Edit:  Reading more of the keymap.md...Looks like I could get the action I want from #2 above by using the ACTION_MODS_TAP_KEY?

Code: [Select]
[0] = ACTION_MOD_TAP_KEY(KC_LCTL, KC_FN1)
[1] = ACTION_LAYER_TOGGLE(2)

Does this look right?  Of course this takes up 2 Fn keys, but with 32 available I should be just fine.

This won't work. ACTION_MOD_TAP_KEY doen't accept KC_FN*, only normal keycodes are required.

Offline sean4star

  • Posts: 59
  • Location: Arlington, TX
Re: TMK keyboard firmware
« Reply #175 on: Mon, 21 October 2013, 14:20:35 »
This won't work. ACTION_MOD_TAP_KEY doen't accept KC_FN*, only normal keycodes are required.

I'm assuming this is true for the other ACTION_* commands as well?  No Fn keys?  Do normal keycodes include modifiers, mousekeys, system/media keys?  Or just the normal keys as documented in the keymap.md file section 1.1?


Also, I would like to use the Teensy++ 2.0, or maybe the smaller Teensy 2.0 depending on the final number of pins I need.  Do I have to use the PJRC stack or can I use the LUFA stack?  I don't fully understand the difference, but I did see you said you wouldn't be supporting the PJRC stack anymore.

Offline metalliqaz

  • * Maker
  • Posts: 4951
  • Location: the Making Stuff subforum
  • Leopold fanboy
Re: TMK keyboard firmware
« Reply #176 on: Mon, 21 October 2013, 16:08:32 »
I only ever use the LUFA stack.  It supports both of those devices.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #177 on: Mon, 21 October 2013, 18:07:21 »
This won't work. ACTION_MOD_TAP_KEY doen't accept KC_FN*, only normal keycodes are required.

I'm assuming this is true for the other ACTION_* commands as well?  No Fn keys?  Do normal keycodes include modifiers, mousekeys, system/media keys?  Or just the normal keys as documented in the keymap.md file section 1.1?
All other keys should work except for Fn key. I'm not sure my code works that way but I'll fix if it doesn't work. Hmm, at a glance my code doesn't work for mouse keys?

Quote
Also, I would like to use the Teensy++ 2.0, or maybe the smaller Teensy 2.0 depending on the final number of pins I need.  Do I have to use the PJRC stack or can I use the LUFA stack?  I don't fully understand the difference, but I did see you said you wouldn't be supporting the PJRC stack anymore.
PJRC stack is still supproted at this time but LUFA is recommended.
As metalliqaz said, LUFA works well on all of Teensy, Teensy++ or other boards with USB AVR. In terms of TMK firmware functions both stacks has no difference, but LUFA makes firmware size a bit bigger. You can use both stacks interchangeably any time, don't bother.

All my own keyboards and converters works with LUFA now and I use PJRC only for testing purpose now.
« Last Edit: Mon, 21 October 2013, 18:09:45 by hasu »

Offline CarVac

  • Posts: 22
Re: TMK keyboard firmware
« Reply #178 on: Mon, 28 October 2013, 13:35:06 »
hasu:

Can you explain how to get into debug mode (as in outputs the matrix and keys to hid_listen)? I can't seem to figure out how the bootmagic keys are supposed to work.

This is to figure out what's going wrong in my keyboard: I've reverse-engineered the matrix of this laptop keyboard but it's getting random stuff wrong: the escape key (or what normally would be escape) is acting like something else, some keys don't seem to do anything, some keys have switched positions for no reason, the right arrow key results in a rapid rightleft (!), and mysteriously every single alphanumeric key works perfectly. The most mysterious one is the escape key: that's (1,1) in the matrix and in the keymap so it really couldn't be mixed up rows and columns without screwing up everything else in either the row or column.

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #179 on: Mon, 28 October 2013, 17:30:35 »
CarVac,

Start by downloading hid_listen.exe from the PJRC site. Then, check your config.h to verify your magic key combo (mine is L-shift + R-shift). Then, run hid_listen, and press your magic key combo + "x". This should put your keyboard into matrix debug mode. hid_listen should show a matrix of zeros representing the matrix positions of your keyboard. Each time the state of a key changes, the display will update with a new representation of the matrix (an update for press, and another for release). Check the README.md in the tmk_keyboard-master root directory for more cool stuff you can do.

Make sure your magic keys are keys that are working correctly. If they are currently set to l+r shift, but those keys aren't working, rebuild your firmware with the magic keys changed to keys you know work correctly.
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #180 on: Mon, 28 October 2013, 18:23:24 »
Exactly what StrikeEagleCC explained.
If your keyboard almost works well  bootmagic and command key combo can kick up debug mode. But you seem to need build hex with enabling debug mode.

Unfortunately there is no easy way to enable debug mode atm, though I'll work on better debug mode control later.
You need to place these lines in matrix_init() of matrix.c or anywhere proper to enable matrix debug:
Code: [Select]
#include "debug_config.h"
debug_config.enable = true; // enable debug print
debug_config.matrix = true; // enable matrix debug
debug_config.keyboard = false; // enable keyboard report debug
debug_config.mouse = false;  // enable mouse report debug

Offline sean4star

  • Posts: 59
  • Location: Arlington, TX
Re: TMK keyboard firmware
« Reply #181 on: Fri, 01 November 2013, 15:19:35 »
I have my SLSH key (/ and ?) setup as a momentary layer switching Fn key - like so:

Code: [Select]
[12] = ACTION_LAYER_TAP_KEY(2, KC_SLSH),
Because of my layout it would be nicer if I could somehow do this with just the ?, so Shift+SLSH.  Is this possible?  I know there is this code:
Code: [Select]
ACTION_MODS_KEY(MOD_LSFT, KC_SLSH)
but then I am missing the layer switching...

I would like to do something like this:
Code: [Select]
[12] = ACTION_LAYER_TAP_KEY(2, MOD_LSFT | KC_SLSH),or something similar... Does it make sense what I'm trying to do?

Any suggestions?

« Last Edit: Sat, 02 November 2013, 10:42:16 by sean4star »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #182 on: Sun, 03 November 2013, 01:00:45 »
not possible in current keymap framework.

ACTION_FUNCTION_TAP may work for you but it is not documented and finalized in design yet.

Offline metalliqaz

  • * Maker
  • Posts: 4951
  • Location: the Making Stuff subforum
  • Leopold fanboy
Re: TMK keyboard firmware
« Reply #183 on: Sun, 03 November 2013, 01:25:33 »
Man, the stuff people come up with... two key presses to then access the Fn layer?  Crazy.

Offline sean4star

  • Posts: 59
  • Location: Arlington, TX
Re: TMK keyboard firmware
« Reply #184 on: Sun, 03 November 2013, 09:50:26 »
Hmm...wells it's not a deal breaker if I can't make it work.

How does ACTION_FUNCTION_TAP work, what does it do?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #185 on: Sun, 03 November 2013, 16:11:42 »
with ACTION_FUNCTION_TAP you can define your own complex action in action_function() of keymap.c. see keyboard/hhkb/keymap.c for a example.

Offline sean4star

  • Posts: 59
  • Location: Arlington, TX
Re: TMK keyboard firmware
« Reply #186 on: Tue, 05 November 2013, 11:01:45 »
I'm not a programmer and barely understand code, so I apologize in advance if I say or ask anything stupid here...

Right now I have this:
Code: [Select]
static const uint16_t PROGMEM fn_actions[] = {
[12] = ACTION_LAYER_TAP_KEY(2, KC_SLSH),          // layer 2 with tap / and ?
};

and call the FN12 key in my keymap macro.

If I tap the FN12 key I get /, if I tap it while holding shift I get ?, and if I hold it I momentarily activate layer 2.


Okay, now instead I want it to work like this: a tap registers a ? and a hold still momentarily switches to layer 2.  If I use ACTION_FUNCTION_TAP, does this look right for everything I need to add?


Code: [Select]
/*
 * Fn action definition
 */

//change Fn12 to:
[12] = ACTION_LAYER_MOMENTARY(2)                          // not quite sure how to call the layer in the ACTION_FUNCTION_TAP - see below

//add this:
[13] = ACTION_FUNCTION_TAP(LAYER2_QMARK),         // Function: Layer 2 with tap ?


// add everything below:
/* id for user defined functions */
enum function_id {
    LAYER2_QMARK,
};

/*
 * user defined action function
 */
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
    keyevent_t event = record->event;
    tap_t tap = record->tap;

    switch (id) {
        case LAYER2_QMARK:                                       // Layer 2 + tap '?'
            if (event.pressed) {
                if (tap.count == 0 || tap.interrupted) {       // will this work with a press and hold, like for momentary layer switching?
                    host_add_key(KC_FN12);                   // Can I call a Fn key with this function?  How else would I switch the layer on?
                } else {
                    host_add_mods(MOD_BIT(KC_LSHIFT));
                    host_add_key(KC_SLSH);
                    host_send_keyboard_report();
                    host_del_mods(MOD_BIT(KC_LSHIFT));
                    host_del_key(KC_SLSH);
                    host_send_keyboard_report();
                }
            } else {
                if (tap.count == 0 || tap.interrupted) {
                    host_del_key(KC_FN12);
                }
            }
            break;
    }
}

I'm confused on how to call the layer.  I'm sure I'm doing this wrong...Also, will the tap.count work if it's not a tap, but a press and hold?  Is that what the 0 stands for...it registers the key pressed but not "tapped"???

Does  [if (tap.count == 0] mean that I could setup different actions for a different number of taps?  For example, 0 taps (press and hold) momentarily switches layers, 1 tap registers a character, and 2 taps toggles a layer?  I'm assuming it would just be a nested if statement?

Code: [Select]
if (tap.count == 0 || tap.interrupted) {
              momentary switch layer
} elseif (tap.count == 2 || tap.interrupted) {
              toggle layer
} else {
             register character

Thanks for all the great help!  I'm consistently amazed at all the functionality included in your firmware.
« Last Edit: Tue, 05 November 2013, 11:07:34 by sean4star »

Offline harifun07

  • Posts: 4
Re: TMK keyboard firmware
« Reply #187 on: Tue, 05 November 2013, 21:29:21 »
thanks for you fw. i was wondering whether you used the ack or crc function in that i found that there may happened data miss when transforming data.

Offline CarVac

  • Posts: 22
Re: TMK keyboard firmware
« Reply #188 on: Tue, 05 November 2013, 21:40:16 »
Has anyone else had the problem of the KP_MENU reporting as the Sun Props key?

I actually use the menu key because I have it software-mapped to toggle maximization on my computers and would like to duplicate that.

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #189 on: Tue, 05 November 2013, 22:20:14 »
Do you mean KC_APP, the application key?
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline CarVac

  • Posts: 22
Re: TMK keyboard firmware
« Reply #190 on: Tue, 05 November 2013, 22:26:49 »
Oops, I meant KC_MENU, not KP_MENU. It's typically between the ctrl and alt keys on the right...

Offline StrikeEagleCC

  • Posts: 31
  • Location: Pyeongtaek, ROK
Re: TMK keyboard firmware
« Reply #191 on: Tue, 05 November 2013, 23:09:54 »
Yup, KC_APP is the key code you need to use.
A better example of how your keyboard works:
More
It's expandable and ~25 seconds long.



Offline CarVac

  • Posts: 22
Re: TMK keyboard firmware
« Reply #192 on: Tue, 05 November 2013, 23:57:34 »
Yup, KC_APP is the key code you need to use.

Perfect. Thanks!

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #193 on: Wed, 06 November 2013, 00:21:23 »
sean4star, I think you are on the right track and close to your goal.

1) Use new API add_key/mods(), del_key/mods() and send_keyboard_report() instead of host_*(). See action_util.h. You may need to add this at the end of #include block.
Code: [Select]
#include "action_util.h"

2) Some special keycodes including KC_FN*(,mousekey and mediakeys) should not be used with add_key() and del_key() [at least at this time]. Instead you should use layer_on() and layer_off() to switch to new layer. You may need to add this at the end of #include block.
Code: [Select]
#include "action_layer.h"


And yes, you can use tap.count for that purpose.
tap.count=0 means normal press/release(not tap), you can also know first tap with 1, second tap with 2 and so on. tap. You also can use tap.interrupted to know whether some other key is pressed while tapping.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #194 on: Wed, 06 November 2013, 00:29:40 »
harifun07,
No, I don't use any CRC check on my firmware. With "data miss" you mean that your keyboard misses key stroke? Or missing charactors on debug output?

I've found charactor drops of debug message print and put aside for long time. I'll work on this issue later but not soon, it is not critical.

If you get keystroke drops describe more detail.

Offline harifun07

  • Posts: 4
Re: TMK keyboard firmware
« Reply #195 on: Wed, 06 November 2013, 08:08:52 »
harifun07,
No, I don't use any CRC check on my firmware. With "data miss" you mean that your keyboard misses key stroke? Or missing charactors on debug output?

I've found charactor drops of debug message print and put aside for long time. I'll work on this issue later but not soon, it is not critical.

If you get keystroke drops describe more detail.
Thanks for you reply. I found that my design would lost the code 00 00 00 00 00 00 00 00 some times, then the PC could not receive the button up code.  I was wondering whether the usb lost my data but I didn't know.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #196 on: Wed, 06 November 2013, 08:27:49 »
hmm,
I doubt USB stack is culprit. LUFA and Atmel hardware USB engine are reliable enough.
Atmega USB engine uses CRC in low level USB packet with confroming with USB spec.

If you need more help your codes and info/pics of your keyboard may be useful to us.

EDIT: With poor USB cable I had similar problems like key stuck and missing.
« Last Edit: Wed, 06 November 2013, 08:30:12 by hasu »

Offline harifun07

  • Posts: 4
Re: TMK keyboard firmware
« Reply #197 on: Wed, 06 November 2013, 08:37:56 »
hmm,
I doubt USB stack is culprit. LUFA and Atmel hardware USB engine are reliable enough.
Atmega USB engine uses CRC in low level USB packet with confroming with USB spec.

If you need more help your codes and info/pics of your keyboard may be useful to us.

EDIT: With poor USB cable I had similar problems like key stuck and missing.
I found that you told about low level USB packet, but I know you used usb 2.0 protocol.

I used C8051F320 in that it's much cheaper and I got some in hand.
I was wondering whether the MCU was not reliable enough for the design.
And I was not good at C++, so I used C only.  It's polite for me to trouble you too much.

Offline sean4star

  • Posts: 59
  • Location: Arlington, TX
Re: TMK keyboard firmware
« Reply #198 on: Wed, 06 November 2013, 12:38:04 »
You may need to add this at the end of #include block.
Code: [Select]
#include "action_util.h"
Code: [Select]
#include "action_layer.h"

So, add these to the #include block in my keymap.c file, correct?


How about this:
Code: [Select]
/*
 * Fn action definition
 */

//change Fn12 to:
[12] = ACTION_FUNCTION_TAP(LAYER2_QMARK),             // Function: Layer 2 with tap ?


// add everything below:

/* id for user defined functions */
enum function_id {
    LAYER2_QMARK,
};

/*
 * user defined action function
 */
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
    keyevent_t event = record->event;
    tap_t tap = record->tap;

    switch (id) {
        case LAYER2_QMARK:                                      // Layer 2 + tap '?'
            if (event.pressed) {
                if (tap.count == 0 || tap.interrupted) {
                    layer_on(2);
                } else {
                    add_mods(KC_LSHIFT);                        // Does this still need the MOD_BIT() coding?
                    add_key(KC_SLSH);
                    send_keyboard_report();
                    del_mods(KC_LSHIFT);                        // Does this still need the MOD_BIT() coding?
                    del_key(KC_SLSH);
                    send_keyboard_report();
                }
            } else {
                if (tap.count == 0 || tap.interrupted) {
                    layer_off(2);
                }
            }
            break;
    }
}

Then I would just use FN12 in my keymap like normal, correct?
What about the add_mods() code...Do I still need the mod_bit() or did I do this right?  I'm not really sure what the mod_bit() does...


I just got my diodes and switches in the mail.  So this idea is about to start coming of the screen and into the real world.  Hopefully I can get everything wired together (at least well enough to test) maybe by this weekend.  This will be my first time wiring a keyboard matrix...hell, my first time to wire anything freestyle...so wish me luck!

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #199 on: Wed, 06 November 2013, 18:50:39 »
So, add these to the #include block in my keymap.c file, correct?
Right. Add them at *end* of block, or you may get minor errors during compiling.

Quote
Then I would just use FN12 in my keymap like normal, correct?
What about the add_mods() code...Do I still need the mod_bit() or did I do this right?  I'm not really sure what the mod_bit() does...
You still need to use MOD_BIT() macro in add/del_mods(). It looks OK except for that.
MOD_BIT() converts modifier keycode into modifier bit and add/del_mods() takes modifier bits not keycode.