Page 1 of 1

Help converting Sun type-4 keyboard with TMK. Where is the type-4 keym

Posted: 02 Aug 2017, 19:59
by PancakeMSTR
Hi,
So I've got a sun type-4 clone I'm trying to convert to USB. I've successfully flashed a pro micro with firmware from the tmk project, following the instructions for the sun_usb converter (https://github.com/tmk/tmk_keyboard/tre ... er/sun_usb).

Here's the thing, the page says this will work with a sun type-4, which it does...sort of. I flashed the firmware and installed the pro micro and the keyboard does mostly work, but a number of keys don't do anything. Additionally, I'd like to set a few other working keys to have different functions.

The problem is I can't find the type-4 keymap in any of the files in the repository. So I have the following options

- Find the sun type-4 keymap
- Make a type-4 keymap

I'm fine with making my own, but I'm not familiar enough with TMK to get it to work. I don't know how to tell it to use my keymap when compiling the hex file, and also I'm frankly not totally sure how to write the keymap correctly at all. Looking at the keymap.c file, there is a lot of stuff I don't really understand.

- What is all the short-type stuff at the bottom?
- How do I make macros?

I dunno. I don't have super clear questions. I could just use some guidance. Thanks.

Posted: 02 Aug 2017, 20:25
by Findecanor
Which host operating system have you tried it with? And which keys don't work for you?

From what I know of Sun keyboards and from what I can see in the source code, the converter should send the same codes as a Sun Type 6 or Type 7 with USB should do ... except perhaps for Mute / Volume Up / Volume Down.
I have read in Microsoft's keyboard documents that MS Windows or Mac don't have support for the codes of the named function keys on the left-hand-side. I don't think there is a way to make those codes work. You should however be able to change those to other codes.

In the source code, KEYMAP and SHORT_TYPE are just macros in the C programming language (not keyboard macros) to make it easier to write keymaps. KEYMAP adds the "KC_" prefix to every key and rearranges the keymap, so that you could write it in a closer to a physical layout. SHORT_TYPE is a shortcut that hard-codes some keys that are not different in different layers.

Posted: 02 Aug 2017, 20:36
by PancakeMSTR
Findecanor wrote: Which host operating system have you tried it with? And which keys don't work for you?

From what I know of Sun keyboards and from what I can see in the source code, the converter should send the same codes as a Sun Type 6 or Type 7 with USB should do ... except perhaps for Mute / Volume Up / Volume Down.
I have read in Microsoft's keyboard documents that MS Windows or Mac don't have support for the codes of the named function keys on the left-hand-side. I don't think there is a way to make those codes work. You should however be able to change those to other codes.

In the source code, KEYMAP and SHORT_TYPE are just macros in the C programming language (not keyboard macros) to make it easier to write keymaps. KEYMAP adds the "KC_" prefix to every key and rearranges the keymap, so that you could write it in a closer to a physical layout. SHORT_TYPE is a shortcut that hard-codes some keys that are not different in different layers.

I'd like the keyboard definitely operational on windows, and on OSX if it's not too difficult. What I'm mostly interested in regarding the left side function keys is setting them to things like CTRL-C/CMD-C, CTRL-Z,CMD-Z, etc.

And do you notice that none of the layouts in the keymap.c file precisely match that of the sun type-4? I'd like to fix that if possible. And how do I change the non-functional codes to working codes, e.g. codes windows will recognize?

Posted: 02 Aug 2017, 20:48
by Findecanor
PancakeMSTR wrote: And do you notice that none of the layouts in the keymap.c file precisely match that of the sun type-4?
Hasu must have written the source code with Sun Type 5 and 6 in mind. It does not map from physical layout anyway but from codes to codes.
Just keep in mind which keys are which and you should be fine.

You could use instances of KEYMAP instead of SHORT_TYPE. Look at how SHORT_TYPE is defined: it uses KEYMAP!

For more reading about keymaps see:
https://github.com/tmk/tmk_keyboard/blo ... /keymap.md
I would suggest reading it from top to bottom. Understanding of what an ACTION is in TMK is required for you to understand how to implement macros.
I can't help you further with TMK, and you would have to learn enough to program it anyway. I am not an expert on TMK myself, only another guy who wrote his own keyboard firmware.
PancakeMSTR wrote: I'd like the keyboard definitely operational on windows, and on OSX if it's not too difficult. What I'm mostly interested in regarding the left side function keys is setting them to things like CTRL-C/CMD-C, CTRL-Z,CMD-Z, etc.
Then I think you would have to make different macros for Windows and Mac OS, each set on a different layer and that you would have to change that manually.
There is no way for the keyboard to tell whether it is connected to a Windows machine or a Mac unfortunately.

Posted: 02 Aug 2017, 20:50
by PancakeMSTR
So look, this is at the top of keymap.c

Code: Select all

,-------.  ,---,  ,---------------. ,---------------. ,---------------.   ,-----------. ,---------------.
|   76  |  | 0F|  | 05| 06| 08| 0A| | 0C| 0E| 10| 11| | 12| 07| 09| 0B|   | 16| 17| 15| | 2D| 02| 04| 30|
`-------'  `---'  `---------------' `---------------' `---------------'   `-----------' `---------------'
,-------.  ,-----------------------------------------------------------.  ,-----------. ,---------------.
| 01| 03|  | 1D| 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 58| 2A|  | 2C| 34| 60| | 62| 2E| 2F| 47|
|-------|  |-----------------------------------------------------------|  |------------ |---------------|
| 19| 1A|  |  35 | 36| 37| 38| 39| 3A| 3B| 3C| 3D| 3E| 3F| 40| 41| 2B  |  | 42| 4A| 7B| | 44| 45| 46|   |
|-------|  |-----------------------------------------------------------|  `-----------' |-----------| 7D|
| 31| 33|  |  4C  | 4D| 4E| 4F| 50| 51| 52| 53| 54| 55| 56| 57|   59   |                | 5B| 5C| 5D|   |
|-------|  |-----------------------------------------------------------|      ,---.     |-----------|---|
| 48| 49|  |   63   | 64| 65| 66| 67| 68| 69| 6A| 6B| 6C| 6D|    6E    |      | 14|     | 70| 71| 72|   |
|-------|  |-----------------------------------------------------------|  .-----------. |-----------| 5A|
| 5F| 61|  | 77 | 13| 78 |*73 |       79         |*74 |*75| 7A | 43| 0D|  | 18| 1B| 1C| |   5E  | 32|   |
`-------'  `-----------------------------------------------------------'  `-----------' `---------------'
Note I know that is a comment block used for just easy-reading the layout. Nonetheless:

- First thing to notice is this layout isn't the same as the sun type-4. Also sorry it didn't copy quite correctly you'll have to see the keymap.c file to get a clearer picture.
- First question: Every key has a definition, E.g. 2C, 7A, *75, etc. What do those numbers mean? What do the *'s mean? If I make a sun type-4 layout, how do I determine, with absolute certainty, where for example the 1C key needs to go? or the 5E? Etc.

If we can answer those questions I think we're getting somewhere.

Posted: 02 Aug 2017, 20:52
by PancakeMSTR
Findecanor wrote:
PancakeMSTR wrote: And do you notice that none of the layouts in the keymap.c file precisely match that of the sun type-4?
Hasu must have written the source code with Sun Type 5 and 6 in mind. It does not map from physical layout anyway but from codes to codes.
Just keep in mind which keys are which and you should be fine.
So the question is how to figure that out? How do I determine which key on the Sun-type 5 matches which key on the sun type-4? I don't know how to get that information.


I tried HID listen but it didn't work. Is there some program that allows me to see what a keypress is sending to the computer?

Posted: 02 Aug 2017, 21:26
by Findecanor
PancakeMSTR wrote: So the question is how to figure that out? How do I determine which key on the Sun-type 5 matches which key on the sun type-4? I don't know how to get that information.
Look at the keymap, or google an image of a Sun Type 5 and compare with the keyboard you have.
Seriously, it is not that hard.

Or maybe... If you don't recognise a hexadecimal number or a C macro when you see one, maybe you should learn some basic programming before attempting to write changes in something as complex as TMK.

Posted: 02 Aug 2017, 22:47
by PancakeMSTR
Findecanor wrote:
PancakeMSTR wrote: So the question is how to figure that out? How do I determine which key on the Sun-type 5 matches which key on the sun type-4? I don't know how to get that information.
Look at the keymap, or google an image of a Sun Type 5 and compare with the keyboard you have.
Seriously, it is not that hard.

Or maybe... If you don't recognise a hexadecimal number or a C macro when you see one, maybe you should learn some basic programming before attempting to write changes in something as complex as TMK.

You know, I come here asking for help. If you aren't willing to do that, then direct me to someone who might actually be able and willing to help me, instead of telling me how "hard but actually easy" it is and otherwise insulting my unfamiliarity with something difficult that I don't have a lot of experience with.

Posted: 03 Aug 2017, 07:01
by PancakeMSTR
I could still really use some help on this from anyone knowledgeable.

Posted: 03 Aug 2017, 08:09
by Findecanor
PancakeMSTR wrote: You know, I come here asking for help. If you aren't willing to do that, then direct me to someone who might actually be able and willing to help me, instead of telling me how "hard but actually easy" it is and otherwise insulting my unfamiliarity with something difficult that I don't have a lot of experience with.
What I mean is, the person who would ultimately have to do the work is you. You can't expect anyone here to do it for you.
People could provide advice based on their experience on details that are not easy to discern - that is it.
This is a keyboard forum - it is not for teaching people how to write programs in C.

Posted: 03 Aug 2017, 08:21
by PancakeMSTR
Findecanor wrote:
PancakeMSTR wrote: You know, I come here asking for help. If you aren't willing to do that, then direct me to someone who might actually be able and willing to help me, instead of telling me how "hard but actually easy" it is and otherwise insulting my unfamiliarity with something difficult that I don't have a lot of experience with.
What I mean is, the person who would ultimately have to do the work is you. You can't expect anyone here to do it for you.
People could provide advice based on their experience on details that are not easy to discern - that is it.
This is a keyboard forum - it is not for teaching people how to write programs in C.
If you're not willing to help stop replying.

As much as it would be great if someone would just do this for me, I'd like to learn how myself. But I need help, which is why I'm here. I am struggling to understand what is going on with this problem and not getting very far, and I need more than someone saying "look at the keymap."

So, I say again, I could still use help on this problem from anyone willing and able to provide it. Any guidance is hugely appreciated.

Posted: 06 Aug 2017, 02:11
by PancakeMSTR
Could Still use help with this one.

Posted: 13 Aug 2017, 09:42
by PancakeMSTR
Still stumped

Posted: 27 Aug 2017, 02:47
by hasu
It seems to me that all quesions were alreadly answered properly. I'm not sure I can add something useful to OP.
I'd like to thank you for helping community as always, Findecanor.

Type 4 looks like subset of Type 5 in terms of keyboard layout you can just use KEYMAP() for Type 5 to define keymap.