Page 1 of 1

Anybody know how to program a phantom?

Posted: 27 Feb 2014, 01:00
by xSpartanCx
I'm having difficulty figuring out how to program my phantom. I'm using the TMK Keyboard firmware and it's really confusing. I want to use MXLOCK for my caps lock, and I want to have a function layer. I've got no idea on how to program this, and the github readme doesn't serve much help (I don't even know what files I should be editing). Any assistance is appreciated, whether a link to a tutorial, an example, or personal help.

Posted: 27 Feb 2014, 01:17
by CJNE
To start things off, here are the things you need to install and instructions for how to build:
https://github.com/tmk/tmk_keyboard/blo ... c/build.md

Then read here for phantom specifics:
https://github.com/tmk/tmk_keyboard/tre ... rd/phantom

You should do all edits and compilation in you git repo under keyboards/phantom

The easiest way to customize the keymap is to edit the default keymap which is keymap_ansi.h
If you take a look at the Makefile you will see how to add your own .h file (which i recommend)

This should get you started i hope :)

Posted: 27 Feb 2014, 01:44
by xSpartanCx
CJNE wrote:To start things off, here are the things you need to install and instructions for how to build:
https://github.com/tmk/tmk_keyboard/blo ... c/build.md

Then read here for phantom specifics:
https://github.com/tmk/tmk_keyboard/tre ... rd/phantom

You should do all edits and compilation in you git repo under keyboards/phantom

The easiest way to customize the keymap is to edit the default keymap which is keymap_ansi.h
If you take a look at the Makefile you will see how to add your own .h file (which i recommend)

This should get you started i hope :)
Thank you so much! I didn't realize there was a readme in the phantom folder. Is there a way to set a function key that allows the teensy to be reprogrammed without taking apart the keyboard?

Posted: 27 Feb 2014, 09:05
by CJNE
Yes there is! If you use the default keymap_ansi.h file for your keymap, change this part:

Code: Select all

static const uint16_t PROGMEM fn_actions[] = {
    [0] = ACTION_LAYER_MOMENTARY(1)
};
to look like this:

Code: Select all

enum function_id {
    TEENSY_KEY
};
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
{
    print("action_function called\n");
    print("id  = "); phex(id); print("\n");
    print("opt = "); phex(opt); print("\n");
    if (id == TEENSY_KEY) {
        clear_keyboard();
        print("\n\nJump to bootloader... ");
        _delay_ms(250);
        bootloader_jump(); // should not return
        print("not supported.\n");
    }
}
static const uint16_t PROGMEM fn_actions[] = {
    ACTION_LAYER_MOMENTARY(1),
    ACTION_FUNCTION(TEENSY_KEY)
};
Now you can map the key FN1 to be the teensy programming key.
I haven't tested the code in the phantom section but it should work the same as for other keyboards.

Function definitions and so on is explained in more detail here:
https://github.com/tmk/tmk_keyboard/blo ... /keymap.md

Posted: 27 Feb 2014, 19:28
by xSpartanCx

Code: Select all



static const uint16_t PROGMEM fn_actions[] = {
    ACTION_LAYER_MOMENTARY(1),
    ACTION_FUNCTION(TEENSY_KEY)
};
If I change the (1) to 2, can I use FN2 instead?

Posted: 27 Feb 2014, 19:42
by CJNE
The 1 in that code is the layer number to switch to.
FN0 ... FNn are special functions that you can assign to keys and the numbers are just their position in the fn_actions array.

Code: Select all

static const uint16_t PROGMEM fn_actions[] = {
    ACTION_LAYER_MOMENTARY(1), //This is FN0
    ACTION_FUNCTION(TEENSY_KEY), //This is FN1
    ACTION_LAYER_MOMENTARY(1) //This is FN2
    //etc..
};

Posted: 27 Feb 2014, 21:37
by xSpartanCx
Ok, I get it now. Is there any difference between makefile lufa and pjrc? When I try to make, it has a fatal error opening dependency file .dep/obj_phantom_lufa/pjrc_keymap.o.d

Posted: 27 Feb 2014, 23:05
by CJNE
Great :) Lufa and pjrc are two different USB stacks, they provide the same basic functionality. I think the tmk firmware is moving focus to Lufa nowadays. It shouldn't matter which one you choose.

You need to provide more detail in order to get help with the compile error. It might be that you have an error in your edited keymap, look for earlier errors in the compile output.

Posted: 28 Feb 2014, 01:04
by xSpartanCx

Code: Select all


C:\Users\xspartancx\Desktop\tmk_keyboard-master\keyboard\phantom>make -f Makefile.lufa an
si
      0 [main] sh 5404 sync_with_child: child 8908(0x128) died before initialization
with status code 0x0
    275 [main] sh 5404 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
      0 [main] sh 9308 sync_with_child: child 8436(0x128) died before initialization
with status code 0x0
    252 [main] sh 9308 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

      0 [main] sh 10228 sync_with_child: child 5712(0x120) died before initialization
 with status code 0x0
    247 [main] sh 10228 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

mkdir -p obj_phantom_lufa
Compiling C: keymap.c
avr-gcc -c -mmcu=atmega32u4 -gdwarf-2 -DF_CPU=16000000UL -DBOOTLOADER_SIZE=512 -DF_US
B=16000000UL -DARCH=ARCH_AVR8 -D USB_DEVICE_ONLY -D USE_FLASH_DESCRIPTORS -D USE_STAT
IC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -DPR
OTOCOL_LUFA -DBOOTMAGIC_ENABLE -DEXTRAKEY_ENABLE -DCONSOLE_ENABLE -DCOMMAND_ENABLE -D
VERSION= -DLAYOUT_ANSI -Os -funsigned-char -funsigned-bitfields -ffunction-sections -
fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Ws
trict-prototypes -Wa,-adhlns=obj_phantom_lufa/keymap.lst -I. -I../.. -I../../protocol
/lufa -I../../protocol/lufa/LUFA-120730 -I../../common -std=gnu99 -include config.h -
MMD -MP -MF .dep/obj_phantom_lufa_keymap.o.d  keymap.c -o obj_phantom_lufa/keymap.o
In file included from keymap.c:124:
keymap_ansi.h: In function 'action_function':
keymap_ansi.h:31: warning: implicit declaration of function '_delay_ms'
keymap_ansi.h:32: warning: implicit declaration of function 'bootloader_jump'
keymap.c: At top level:
keymap.c:151: fatal error: opening dependency file .dep/obj_phantom_lufa_keymap.o.d:
No such file or directory
compilation terminated.
make: *** [obj_phantom_lufa/keymap.o] Error 1

Posted: 28 Feb 2014, 01:44
by CJNE
Ah, you are missing some includes, add

Code: Select all

#include <util/delay.h>
#include "bootloader.h"
to the list of includes at the top keymap.c and try to compile again.

Posted: 28 Feb 2014, 01:59
by xSpartanCx
Still can't access the dependency file...

Code: Select all


C:\Users\xspartancx\Desktop\tmk_keyboard-master\keyboard\phantom>make -f Makefile.lufa an
si
      0 [main] sh 9920 sync_with_child: child 1944(0x128) died before initialization
with status code 0x0
     66 [main] sh 9920 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
      0 [main] sh 9504 sync_with_child: child 4484(0x128) died before initialization
with status code 0x0
     75 [main] sh 9504 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

      0 [main] sh 7240 sync_with_child: child 9804(0x120) died before initialization
with status code 0x0
     63 [main] sh 7240 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

mkdir -p obj_phantom_lufa
Compiling C: keymap.c
avr-gcc -c -mmcu=atmega32u4 -gdwarf-2 -DF_CPU=16000000UL -DBOOTLOADER_SIZE=512 -DF_US
B=16000000UL -DARCH=ARCH_AVR8 -D USB_DEVICE_ONLY -D USE_FLASH_DESCRIPTORS -D USE_STAT
IC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -DPR
OTOCOL_LUFA -DBOOTMAGIC_ENABLE -DEXTRAKEY_ENABLE -DCONSOLE_ENABLE -DCOMMAND_ENABLE -D
VERSION= -DLAYOUT_ANSI -Os -funsigned-char -funsigned-bitfields -ffunction-sections -
fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Ws
trict-prototypes -Wa,-adhlns=obj_phantom_lufa/keymap.lst -I. -I../.. -I../../protocol
/lufa -I../../protocol/lufa/LUFA-120730 -I../../common -std=gnu99 -include config.h -
MMD -MP -MF .dep/obj_phantom_lufa_keymap.o.d  keymap.c -o obj_phantom_lufa/keymap.o
keymap.c:153: fatal error: opening dependency file .dep/obj_phantom_lufa_keymap.o.d:
No such file or directory
compilation terminated.
make: *** [obj_phantom_lufa/keymap.o] Error 1
I found http://www.avrfreaks.net/index.php?name ... ew&t=80740, since I have Vista 64 bit does that mean I need to use something like ubuntu to compile? or is there another problem with how I set up the code?

Posted: 28 Feb 2014, 04:11
by xSpartanCx
Tried it in linux:

Code: Select all

mkdir -p obj_phantom_lufa
Compiling C: keymap.c
avr-gcc -c -mmcu=atmega32u4 -gdwarf-2 -DF_CPU=16000000UL -DBOOTLOADER_SIZE=512 -DF_USB=16000000UL -DARCH=ARCH_AVR8 -D USB_DEVICE_ONLY -D USE_FLASH_DESCRIPTORS -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -DPROTOCOL_LUFA -DBOOTMAGIC_ENABLE -DEXTRAKEY_ENABLE -DCONSOLE_ENABLE -DCOMMAND_ENABLE -DVERSION=unknown -DLAYOUT_ANSI -Os -funsigned-char -funsigned-bitfields -ffunction-sections -fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Wstrict-prototypes -Wa,-adhlns=obj_phantom_lufa/keymap.lst -I. -I../.. -I../../protocol/lufa -I../../protocol/lufa/LUFA-120730 -I../../common -std=gnu99 -include config.h -MMD -MP -MF .dep/obj_phantom_lufa_keymap.o.d  keymap.c -o obj_phantom_lufa/keymap.o
keymap.c:21:24: fatal error: util/delay.h: No such file or directory
compilation terminated.
make: *** [obj_phantom_lufa/keymap.o] Error 1
EDIT::found out I had to install a library, now it works. Thanks for all your help CJNE! :D

Posted: 28 Feb 2014, 05:05
by xSpartanCx
aaaaaand I think I bricked my teensy. I was trying to get the locking caps lock to work, and decided to try the programming key. My computer made the hardware unplugging sound, and now the teensy doesn't light up nor is recognized by the computer :(

Posted: 28 Feb 2014, 07:56
by matt3o
unplug, wait, press backspace while replugging.

Posted: 28 Feb 2014, 13:20
by xSpartanCx
matt3o wrote:unplug, wait, press backspace while replugging.
Okay, I'll try that when I get home. Is that supposed to happen when I hit the program button?

Posted: 28 Feb 2014, 13:38
by matt3o
yes, if you don't actually send the firmware right after.

Posted: 28 Feb 2014, 13:46
by xSpartanCx
Okay. I hit the program button and it never reconnected though, so the teensy program never recognized it :/

Posted: 28 Feb 2014, 14:36
by CJNE
Haven't tried this in Windows so i can't tell if it's normal or not... If nothing helps try to unplug and plug in then hit the hardware program button on the teensy.

Posted: 28 Feb 2014, 20:56
by xSpartanCx
Had to restart for it to work, i guess I won't use the program button. The unfortunate part is that I can't get the locking caps lock to work. I use CAPS and it works like a normal caps lock, which isn't very effective for MXLOCK. I try LCAP, and it doesn't even turn caps lock on.

Posted: 01 Mar 2014, 19:44
by xSpartanCx
did the program key not work because it's missing the [0] = and [1] = in keymap_anis.h?

Code: Select all

static const uint16_t PROGMEM fn_actions[] = {
    ACTION_LAYER_MOMENTARY(1),
    ACTION_FUNCTION(TEENSY_KEY)
};

Posted: 01 Mar 2014, 21:51
by CJNE
No, it definitely did trigger the jump to bootloader function, it shut down USB but what happened next i don't know. It was supposed to jump to the bootloader but perhaps the address was not set right?
Assuming it is a Teensy 2.0, try to add:

Code: Select all

#define BOOTLOADER_SIZE 512
to config.h, compile and program then try again.

Posted: 03 Mar 2014, 02:06
by xSpartanCx
Cool, it works now! Now if only I could get the LED dimming and locking caps to work... :/ I posted on the official TMK firmware thread over on Geekhack asking about that.

Posted: 04 Mar 2014, 03:48
by xSpartanCx
Tried asking on the TMK post, nobody there is sure either as to why the LED brightness and locking caps doesn't work. If you'd like to look at my config.h and keymap.h it's here:
My config.h: http://pastebin.com/7hB9jatE
My keymap_ansi.h: http://pastebin.com/N0wTL3wA
This is a version without the program button, btw

Posted: 04 Mar 2014, 08:55
by CJNE
Try to add this to config.h

Code: Select all

#define LOCKING_SUPPORT_ENABLE
#define LOCKING_RESYNC_ENABLE
As for the LED brightness, have a look in the Makefile you use and make sure that SLEEP_LED_ENABLE is set to no or commented out (add a # to the beginning of the line)

Posted: 04 Mar 2014, 09:57
by HzFaq
I was just looking at the LED brightness thing the other day; on a previous firmware version I had fixed it but don't actually remember how...I've since upgraded to a newer firmware and the brightness thing seems to be back!

I think it was this but I've been playing around with my Ergodox and haven't had a chance to test it again. I'm almost positive the solution was in that thread, there's a little more discussion about the leds a few pages further back as well so maybe try there.

Posted: 04 Mar 2014, 23:28
by xSpartanCx
I'm able to get the caps lock to work now, but still can't figure out the LEDs. Those aren't too big of a deal for me though, as I rarely use caps lock or scroll lock. Thanks for the help :)

Posted: 05 Mar 2014, 13:23
by CJNE
xSpartanCx wrote:I'm able to get the caps lock to work now, but still can't figure out the LEDs. Those aren't too big of a deal for me though, as I rarely use caps lock or scroll lock. Thanks for the help :)
Glad that you got some of it working at least :) I don't have a phantom so it's hard to debug.
It could be worth trying with PJRC if you are currently using Lufa, or the other way around...