qmk / qmk_firmware

Open-source keyboard firmware for Atmel AVR and Arm USB families
https://qmk.fm
GNU General Public License v2.0
18.36k stars 39.55k forks source link

Consider adding Keychron K* keyboards #7370

Closed mdreizin closed 2 years ago

mdreizin commented 5 years ago

I am a user of Keychron K2 keyboard I only know that it uses ARM M0 MCU. I am not an expert and it would be nice to know if it is possible to create QMK-based firmware for this keyboard or not?

yanfali commented 5 years ago

@mdreizin someone will need to do some reverse engineering and figure out the vendor and bootloader.

mdreizin commented 5 years ago

@yanfali Do you know what questions should I ask Keychron (about vendor/hardware/etc)?

I will try to send them directly (or their user group) and they would happy to answer/provide bootloader and other stuff.

mdreizin commented 5 years ago

@yanfali I am looking forward to getting your reply 😀

rexkyng commented 5 years ago

Communication protocol in Chinese for keychron keyboards, released on the fb group. Hope this helps.

jkramarz commented 5 years ago

@yanfali, according to flashing tool in firmware upgrade package, it is using Cortex M0 Sonix SN32F260. On the other side, chips inside (at last in white-LED version) are HFD48KP500 and CYW20730.

Flashing tool and firmware files can be found at https://drive.google.com/file/d/1F49mMZpGny9VWB-MmuwtZYJL-Soxhzc4/view?usp=sharing .

yanfali commented 5 years ago

So the issue will be this isn't supported by any of the HAL layers we use. Currently ChiBIOS and ATSAM for ARM platforms. Therefore this is going to be a lot of work to add support for. You're going to have to find someone with the hardware willing to do the work of porting and supporting this chip. That's about all the assistance I can offer at this time.

VirtualValence commented 5 years ago

You're going to have to find someone with the hardware willing to do the work of porting and supporting this chip.

Not knowing anything about ARM programming and the like, would you say it would probably take less effort to desolder the current ARM chip and put in a compatible one vs the reverse engineering of the current one?

noroadsleft commented 5 years ago

So the issue will be this isn't supported by any of the HAL layers we use. Currently ChiBIOS and ATSAM for ARM platforms. Therefore this is going to be a lot of work to add support for. You're going to have to find someone with the hardware willing to do the work of porting and supporting this chip. That's about all the assistance I can offer at this time.

Actually, some of the CannonKeys boards (among others) run Cortex M0 chips currently, so I'm fairly sure ChibiOS could run this (supporting the chip being the barrier to entry, rather than the architecture).

zvecr commented 5 years ago

When it comes to ChibiOS, its less about the M0 part and more if there is a hardware port for it. A quick search for sonix support doesn't show much hope, and I would guess ending up something like qmk/ChibiOS-Contrib/pull/10.

smplman commented 4 years ago

Not sure if this is off topic, but I’ve been looking into porting ChibiOS to the SN32F248B and it is possible that some of the work will carry over. I’m able to upload firmware and get into recovery mode. I would like to enable SWD on the current firmware to allow me to step through the code. Here is my progress so far.

https://github.com/smp4488/dk63

xyzz commented 4 years ago

Did you ever get the st-link (clone?) working with it? I see there are configs for rpi and stlink, but I guess only the rpi one ended up working since that's what all the pictures show?

smplman commented 4 years ago

@xyzz I did, i need to update the readme. I couldn't get the windows st-link to connect, but it did get it working with openocd.

xyzz commented 4 years ago

Would appreciate it, I have a keyboard with a similar chip and I couldn't get it working with blackmagic, haven't tried openocd though.

smplman commented 4 years ago

Give OpenOCD a shot with the st-link config in my repo. Should work with Sonix and SMT32 MCUs

xyzz commented 4 years ago

Thanks, I got it working with both blackmagic and openocd now. Are you able to read memory/flash from gdb?

smplman commented 4 years ago

I can read memory past 0xFFF0000 but nothing below that while in debug recovery mode. I have the firmware and I’m trying to find the bits to enable SWD so I can read everything else.

xyzz commented 4 years ago

I think this is a weird code protection function they use. Check the value of CS at 0x1FFF2000, it's probably going to be 0x5A5A (it was for me). Also, are you on discord? Can you add me, xyz#9668, so that we can iterate on it faster without having to spam the issue tracker.

ByteWoofer commented 4 years ago

New Keychron K4 RGB user here. Is there any assistance that I could provide to this issue? I am semi competent with hardware hacking and willing to take an Attify badge to the onboard flash and assist in analysis to the best of my abilities.

smplman commented 4 years ago

Hello @ByteWoofer, thank you for wanting to offer your assistance. With the help of @xyzz we were able to get chibios running with limited USB. I’m working on flushing out GPIO right now. You probably want to identify your chip and start setting up board and config files for your keyboard.

Here are the repos we are currently working out of.

QMK - https://github.com/smp4488/qmk-ChibiOS/tree/dk63?files=1

ChibiOS - https://github.com/smp4488/qmk_firmware/tree/chibios-upgrade?files=1

StrayChild01 commented 4 years ago

Hello @ByteWoofer, thank you for wanting to offer your assistance. With the help of @xyzz we were able to get chibios running with limited USB. I’m working on flushing out GPIO right now. You probably want to identify your chip and start setting up board and config files for your keyboard.

Here are the repos we are currently working out of.

QMK - https://github.com/smp4488/qmk-ChibiOS/tree/dk63?files=1

ChibiOS - https://github.com/smp4488/qmk_firmware/tree/chibios-upgrade?files=1

Hi Guys, another K2 user here. I stumbled on this issue and I remember that in facebook one of the core team members of keychron was actually asking what was needed to get the keyboard working with QMK. Maybe we can ask him to see if he can provide more information about the chips and the instruction set🤔

kusayuzayushko commented 4 years ago

Hello. Redragon K585 DITI user here. it has a VS11K16A on board. Also looking for a way to reflash it with QMK or ChibiOS. Any info i can provide?

fightforlife commented 4 years ago

For someone googling this. The Womier K66 is also using this chip. And wants to be ported to qmk :)

More info: https://www.reddit.com/r/olkb/comments/eqfa68/womier_k66_qmk_porting_possible_vs11k16avs12l03a/

xyzz commented 4 years ago

Womier K66 is in fact one of the keyboards being working on in this branch at https://github.com/smp4488/qmk_firmware/tree/chibios-upgrade/keyboards/womier/k66

ByteWoofer commented 4 years ago

Hello @ByteWoofer, thank you for wanting to offer your assistance. With the help of @xyzz we were able to get chibios running with limited USB. I’m working on flushing out GPIO right now. You probably want to identify your chip and start setting up board and config files for your keyboard.

Here are the repos we are currently working out of.

QMK - https://github.com/smp4488/qmk-ChibiOS/tree/dk63?files=1

ChibiOS - https://github.com/smp4488/qmk_firmware/tree/chibios-upgrade?files=1

Just finally got a moment away from work to open up the keyboard. The chips inside are as follows: Chip 1 vlcsnap-2020-02-04-15h15m32s068 Chip 2 vlcsnap-2020-02-04-15h16m12s665 Chip 3 vlcsnap-2020-02-04-15h16m38s965 Chip 4 vlcsnap-2020-02-04-15h20m44s322

Whole board 20200204_152102~2

smplman commented 4 years ago

@ByteWoofer so I started looking for the HFD2201KBA and came across this interesting tweet https://twitter.com/pmg/status/1119008876240596992?lang=en. Your chip looks to be a rebranded STM32 chip. Mine is rebranded Sonix chip. I would start trying to identify some pins on your MCU and compare to some STM32 variant data sheets to find a match.

You also appear to have a JTAG port on the bottom of the #2 picture. https://blog.senr.io/blog/jtag-explained

fightforlife commented 4 years ago

Womier K66 is in fact one of the keyboards being working on in this branch at https://github.com/smp4488/qmk_firmware/tree/chibios-upgrade/keyboards/womier/k66

How are you currently talking to the Womier K66? Did you find a way to use the USB Bootloader mentioned in the spec sheet.

xyzz commented 4 years ago

For flashing we're using the built-in bootloader which isn't ideal but works well enough. Getting into the bootloader is possible by shorting the boot pin to ground or sending a special hid command to the stock firmware.

fightforlife commented 4 years ago

Is it possible to include this information into the K66 QMK Readme file. I think this would help to get people started tinkering with this board. Thanks!

P.S.: Is it possible to save/dump the original firmware and reflash it later? Or is it protected?

xyzz commented 4 years ago

Currently it's somewhat dangerous to flash and a pain to recover if something goes wrong. The tooling is also only tested on Linux so far. That said if you're ok with the limitations (eg lack of rgb in qmk), ping me in mechkeys discord and I can guide you through the process.

As for the original firmware it's possible to flash it back yes.

xyzz commented 4 years ago

I've now posted a (tested) flashing guide at https://gist.github.com/xyzz/471d5856376cdce945e686785c75f7cf

justMaku commented 4 years ago

I have just became a quite happy owner of the Keychron K2 but obviously I'd like to use QMK with it. I have looked at the macOS upgrade utility and I have successfully decrypted the enclosed firmware.

I'm unsure if this applies also to Linux and Windows updaters, but on macOS, the update data is contained within UserInfo.plist file and encrypted using AES 128 in ECB mode. The key is also contained within the plist file (under the token) field and right now uses the secure random value of 123456.

After decrypting, the resulting file is then lzfse compressed (Apple's compression mechanism) and after decompressing you're left with standard intel hex file.

StrayChild01 commented 4 years ago

I have just became a quite happy owner of the Keychron K2 but obviously I'd like to use QMK with it. I have looked at the macOS upgrade utility and I have successfully decrypted the enclosed firmware.

I'm unsure if this applies also to Linux and Windows updaters, but on macOS, the update data is contained within UserInfo.plist file and encrypted using AES 128 in ECB mode. The key is also contained within the plist file (under the token) field and right now uses the secure random value of 123456.

After decrypting, the resulting file is then lzfse compressed (Apple's compression mechanism) and after decompressing you're left with standard intel hex file.

After seeing this, I wondered if this happens as well on windows. And it actually is easier to get the firmware!

I opened the K2-RGB-V1.6_En for Windows.exe file using 7zip and voilá:

The contents are:

I checked opened the .ini and .txt files and I can see the content. I also was able to get the .hex file. The name of the chip is SN32F24xB

I did the same for the white backlight version K2-white-V1.6_En for Windows.exe and the contents are:

The name of the chip is SN32F26x

meanderer-tech commented 4 years ago

Communication protocol in Chinese for keychron keyboards, released on the fb group. Hope this helps.

Is there a need to translate this document?

tzarc commented 4 years ago

Only if the intent is for people to maintain the SN32 hardware port in the official ChibiOS-Contrib.

pgillan145 commented 4 years ago

I've been working on getting this installed on my Womier K66. So far I've gotten the chibios-upgrade branch from @smp4488 to compile (with a minor change to the ram size settings in SN32F260.ld), and basic keymapping works, but not mouse or media controls.

I also got @toast's womier-k66-rbg-support branch to compile, but installing it just locks up the keyboard (though with rainbow colored lights).

flashquark commented 4 years ago

@ByteWoofer In case you were still wondering, the HFD2201KBA is also a rebranded SN32F248B. I figured this out by using Resource Hacker to check inside a keyboard firmware flashing utility for the Velocifire M2 60% keyboard, which has the HFD2201KBA chip. Inside, it references SN32F240B_32.hex for the firmware hex file which means that it is definitely in the SN32F240B series of chips.

FWfile

Looking up the chip series on Sonix's website: http://www.sonix.com.tw/list-en-4336

shows that there are 4 chips in this series, but only the SN32F248B comes in the LQFP64 package, which is what the HFD2201KBA is, so it is almost certainly this chip.

As for the bluetooth module, it is a rebranded Broadcom BCM20730 as can be found here: https://www.cypress.com/file/298211/download

nvti commented 4 years ago

Is this issue still open? Have any working in this? I want to join.

tzarc commented 4 years ago

It can stay open as long as people are willing to follow (right at the bottom of the page): https://docs.qmk.fm/#/platformdev_selecting_arm_mcu?id=add-new-mcu-family

If there's nobody willing to do so, then it can get closed.

LazaroFilm commented 4 years ago

+1 for interest, I have a K2 and the lack of layout customization is really annoying. Would love for QMK to work with it.

f-izzo commented 4 years ago

+1 for interest. I have a K2 and with the stock firmware the Fn keys don't work on Linux :( I have some embedded experience and would be available for contributing.

garrett commented 4 years ago

@Nimayer for using a K2 on Linux, check out https://github.com/Kurgol/keychron/blob/master/k2.md

The Fn keys not working on Linux is related to running echo 0 | tee /sys/module/hid_apple/parameters/fnmode (as root). There's a udev line on that page to have it auto-set the keyboard in the correct mode, running this command behind the scenes when you connect the keyboard. Alternatively, there's a modprobe config setting to change the fnmode too.

As for the stock firmware, it can only be updated with Windows and macOS at the moment. There's a rumor that Keychron is considering working with LVFS to get fwupd support... but I haven't found any actual evidence of it. (And have meanwhile updated my K2 using Windows.)

This all said, I'd love to see qmk firmware support for the Keychron K2.

FWIW: There's a similar effort for the Anne Pro 2, another currently popular keyboard... and they have it all working already. Being able to have qmk on a pre-made keyboard (opposed to having to know how to solder or find a hotswap PCB somewhere and assemble a keyboard one's self) is a huge deal.

fronbasal commented 4 years ago

+1 for interest I have a K4 and I'd love to use QMK on it!

S13391355 commented 4 years ago

Another +1 for interest. I have a K6. If there is anything I can do to help, anything needed, let me know.

nvti commented 4 years ago

+1 for interest

luukvankooten commented 4 years ago

Game keyboard communication protocol.pdf Thanks to google translate. The communication protocol in English. I hope that it helps. I also have interest +1.

frankk74 commented 4 years ago

+1 for k2 interest as well... thanks to everyone so far :-) have k2 I got 1 month ago ... wish I knew then it wasn't "open"... closed source :-(

Just thought for those who want keychron to support QMK ask them for it via their keyboard survey,,,, https://www.keychron.com/pages/keychron-keyboard-layout-survey

vladimir-aubrecht commented 4 years ago

+1 for K8 support! 😊

danhnguyenncd commented 4 years ago

+1 for Keycool KC84 rgb ( ver blue 5.0)

TheProPaul commented 4 years ago

+1 for Royal Kludge RK71, been doing my research for months now still no luck. it uses the same chip as I've verified with the SN32F240B_32.hex file with their firmware update tool

joshfriend commented 4 years ago

Please everyone stop adding +1 comments. Instead, click the :+1: reaction emoji on the toplevel post:

image

Adding "+1" comments only adds noise to the discussion of the folks trying to move this feature forward