Author Topic: Needs help with the keyboard matrix transform for logitech unifying controller  (Read 6810 times)

0 Members and 1 Guest are viewing this topic.

Offline leon_titan

  • Thread Starter
  • Posts: 11
Hello guys, I'm planing to make my own layout keyboard, which have the following features:
1. has minila like layout, which have 67 keys.
2. need hot keys and programable.
3. wireless(using logitech unifying controller in k375s)

After a little search, I found the QKM which is a powerful customizable firmware I can use.

The logitech unifying controller in k375s is not programable, so i need another "X" controller to flush the firmware. So the architecture is like this:

229211-0
[ Keyboard Matrix ]---io--->[ "X" Controller ]---io--->[ k375s Controller ]---2.4g or BT--->[ Computer ]

Another solution is using u2u, but it's too big for me... If there is more small enough u2u board please let me know.

The QKM firmware is using the Pro Micro(ATMEGA32U4) in general, but the number of it's IO is not enough for me. (23 IOs for the k375s controller and at least 8+9=17 IOs for the keyboard matrix.)

So now I have some questions list as follows:
1. Which controller should i use?
2. Do QKM suport STM32? If so, how about the power consumption compare to the ATMEGA(considering wireless)?
3. If I want to choose the "IO2IO" solution, which file should I dig in in the QKM source code?

I am realy very new in the keyboard customizition, so the questions above may very dull here. But I am still looking forward to your reply since any advice will help me a lot.
« Last Edit: Wed, 06 November 2019, 03:03:07 by leon_titan »

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: Needs help with the keyboard design
« Reply #1 on: Fri, 01 November 2019, 10:46:57 »
Welcome to geekhack :)

I'm no QMK expert but it supports the Teensy 2.0++ which has 46 IO pins so you could order one of them while you research.  Don't be tempted by the cheap fakes from China, you never know exactly what you get so when things don't work you can't be sure whether you did it wrong or it's a difference in the controller. Not to mention fakes are bad morally.
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline leon_titan

  • Thread Starter
  • Posts: 11
Re: Needs help with the keyboard design
« Reply #2 on: Fri, 01 November 2019, 19:40:24 »
Welcome to geekhack :)

I'm no QMK expert but it supports the Teensy 2.0++ which has 46 IO pins so you could order one of them while you research.  Don't be tempted by the cheap fakes from China, you never know exactly what you get so when things don't work you can't be sure whether you did it wrong or it's a difference in the controller. Not to mention fakes are bad morally.

Thanks for your reply! 46 IO pins is enough for me, and I want to ensure that do all of the 46 IO pins can be used for the matrix pins from keyboard to k375s?

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: Needs help with the keyboard design
« Reply #3 on: Fri, 01 November 2019, 20:16:13 »
I have never played with a k375s controller but on pjrc's website it definitely says 46 IO pins so it should work.

Is the idea to use the Teensy to simulate a switch matrix connected to the k375s controller?  I've not heard of anyone doing that, sounds like a challenge as you'd need to store the pressed key(s) until the second controller activates the correct row and activate the column pin before it moved on, and for mods (shift, control...) you'd need to 'release' the pin when it moved to the next row and 'press' it again when that row activates again - is that even going to be possible?

The other option would be to not have it programmable, but as you have control over the switch matrix you could build it with any custom layout you want.  Just a thought.
« Last Edit: Fri, 01 November 2019, 20:22:52 by suicidal_orange »
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline leon_titan

  • Thread Starter
  • Posts: 11
Re: Needs help with the keyboard design
« Reply #4 on: Fri, 01 November 2019, 20:58:55 »
I have never played with a k375s controller but on pjrc's website it definitely says 46 IO pins so it should work.

Is the idea to use the Teensy to simulate a switch matrix connected to the k375s controller?  I've not heard of anyone doing that, sounds like a challenge as you'd need to store the pressed key(s) until the second controller activates the correct row and activate the column pin before it moved on, and for mods (shift, control...) you'd need to 'release' the pin when it moved to the next row and 'press' it again when that row activates again - is that even going to be possible?

The other option would be to not have it programmable, but as you have control over the switch matrix you could build it with any custom layout you want.  Just a thought.

Yeah, Teensy is responsible for the matrix transform. My idea is use the QMK firmware to handle the origin matrix signals, and when QMK ready to send key(s), make a simulate matrix signal to k375s controller, instead of usb signal to computer. So I have to modify the QMK source code to do so (not sure will work or not yet :D).

67 keys is not enough for me, so I have to make it programmable to combination other keys use HOT KEY. Hope I made clear what I meant. ;D
« Last Edit: Fri, 01 November 2019, 21:54:34 by leon_titan »

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: Needs help with the keyboard design
« Reply #5 on: Fri, 01 November 2019, 21:20:21 »
Not trying to be rude just checking your understanding - do you know how a switch matrix works? 

Looking into QMK you should be able to use GPIO control to send the simulated keypress, it's just getting the timing right.  I think the only hope you have is if there are only 8 pins which get scanned so you can connect them to the interrupt pins on the Teensy but still not sure that will be quick enough.

Have you mapped out the matrix of the k375s yet, or found someone else who has?
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline leon_titan

  • Thread Starter
  • Posts: 11
Re: Needs help with the keyboard design
« Reply #6 on: Fri, 01 November 2019, 21:49:01 »
I just been in this for days, but I do know how a switch matrix works.

But yeah I'm not sure that will work too... I need scan the origin matrix for origin signals(QMK does this for me and should work well), and scan the k375s controller row signal then simulate the column signal to k375s controller.

Should that work? Not sure Teensy is fast enough to do so.

The matrix of the k375s is shown bellow:
229243-0
« Last Edit: Fri, 01 November 2019, 21:53:29 by leon_titan »

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: Needs help with the keyboard design
« Reply #7 on: Fri, 01 November 2019, 22:51:33 »
Great, you know what needs to happen.

As there are more than 8 rows you can't rely on interrupts so what about synchronising the scan rate on the matrix side to the k375s then at the end of each scan of you'd know which row was active.  Maybe there's a crystal on the k375s controller and if there is you can connect it to the teensy as well?  This is beyond my knowledge of electronics but it might work.

Also I'd go for as one sided a matrix as possible.  23 keys for the k375s (if you leave the LEDs attached to it, caps/num lock wont work on the teensy anyway as it's not connected to a computer) so you have enough for 5x14 and you only need to scan 5 rows so it's quicker.  Probably easier to wire up than 8x9 too!

I do wonder if there's a better option than having two controllers though - is the logitech wireless that good?
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline Findecanor

  • Posts: 5036
  • Location: Koriko
Re: Needs help with the keyboard design
« Reply #8 on: Fri, 01 November 2019, 23:06:36 »
It may be that no controller is fast enough. It depends on the internals of the firmware in the K375's microcontroller.

I think the fastest way to serve the matrix to it would be to set it up to trigger an interrupt whenever a row is strobed, and change the output rows in in the interrupt routine. But even if the interrupt routine is super-fast, hand-coded in assembly language to use as few instructions as possible it might still slower than the K375 controller is trying to read. The Logitech's firmware should reasonably wait at least a couple microseconds between strobing and reading, but if you are unlucky that could be just only a couple microseconds and no more.

Although... if you could test the strobes with an oscilloscope and detect that there is a time-gap between strobes, then you could have the interrupt trigger when a strobe ends, and change the rows within that time-gap before the next strobe.

The AVR microcontrollers are not too fast though. The Logitech is probably running at 3.3V, and your microcontroller must run at the same voltage. At 3.3V, the AVR must be clocked at max 8 MHz. There are other boards with many pins that are based on fast ARM Cortex M-based processors, also in the Teensy family.

If I were you, I would instead either:
1. Wire up the Logitech's matrix directly to key switches -- with no extra features on the board. Instead, make macros and other stuff in software on the host, with e.g. Autohotkey if you're running Windows.

2. Abandon the Logitech's transceiver altogether and use a microcontroller board that is capable of Bluetooth and which you could program. I think the Adafruit Feather nRF52840 Express could be the best choice. (I know there are hobbyists out there that have used the nRF52840 chip for keyboards).
There is also a board with ATmega32u4 + Bluetooth, but I've heard that battery life would be worse with that.

Offline leon_titan

  • Thread Starter
  • Posts: 11
Re: Needs help with the keyboard design
« Reply #9 on: Fri, 01 November 2019, 23:18:31 »
As there are more than 8 rows you can't rely on interrupts so what about synchronising the scan rate on the matrix side to the k375s then at the end of each scan of you'd know which row was active.  Maybe there's a crystal on the k375s controller and if there is you can connect it to the teensy as well?  This is beyond my knowledge of electronics but it might work.

OK I'll work on with that and will update here if any progress happend.

Yeah 5x14 is better if the pins is enough.

Why logitech? Hmmm, maybe for it's stable and lower battery cost? I have a filco 87 bluetooth version, it's a good keyboard but it goes wrong sometimes which make me a little depressed. However bluetooth is still my second option.

Offline leon_titan

  • Thread Starter
  • Posts: 11
Re: Needs help with the keyboard design
« Reply #10 on: Sat, 02 November 2019, 00:41:49 »
It may be that no controller is fast enough. It depends on the internals of the firmware in the K375's microcontroller.

I think the fastest way to serve the matrix to it would be to set it up to trigger an interrupt whenever a row is strobed, and change the output rows in in the interrupt routine. But even if the interrupt routine is super-fast, hand-coded in assembly language to use as few instructions as possible it might still slower than the K375 controller is trying to read. The Logitech's firmware should reasonably wait at least a couple microseconds between strobing and reading, but if you are unlucky that could be just only a couple microseconds and no more.

Although... if you could test the strobes with an oscilloscope and detect that there is a time-gap between strobes, then you could have the interrupt trigger when a strobe ends, and change the rows within that time-gap before the next strobe.

The AVR microcontrollers are not too fast though. The Logitech is probably running at 3.3V, and your microcontroller must run at the same voltage. At 3.3V, the AVR must be clocked at max 8 MHz. There are other boards with many pins that are based on fast ARM Cortex M-based processors, also in the Teensy family.

If I were you, I would instead either:
1. Wire up the Logitech's matrix directly to key switches -- with no extra features on the board. Instead, make macros and other stuff in software on the host, with e.g. Autohotkey if you're running Windows.

2. Abandon the Logitech's transceiver altogether and use a microcontroller board that is capable of Bluetooth and which you could program. I think the Adafruit Feather nRF52840 Express could be the best choice. (I know there are hobbyists out there that have used the nRF52840 chip for keyboards).
There is also a board with ATmega32u4 + Bluetooth, but I've heard that battery life would be worse with that.

Great thanks for your advices!

Test the strobes with an oscilloscope is the next step I'm going to do. Bluetooth and the Autohotkey is my plan B and plan C ;D

Offline leon_titan

  • Thread Starter
  • Posts: 11
Re: Needs help with the keyboard design
« Reply #11 on: Tue, 05 November 2019, 19:48:42 »
It shows a weird result after test the strobes with an oscilloscope. Did I doing something wrong?
1. The triger pin's strobes are only 2Hz.
2. All the triger pins are pull high and low synchronouly.
3. The high level is last 200us to 8ms, not stable。

The wave curve is like this:
229521-0229523-1229525-2229527-3


Offline leon_titan

  • Thread Starter
  • Posts: 11
Hello again everyone!

After several nights work, finaly, I makes my plan work.

Yes, it's worked!

Here is some information I dig out:
1. Logitech k375s controller's matrix scan is interrupt mode, so it shows a weird result after test the strobes with an oscilloscope at the first place.
2. Logitech k375s controller's matrix scan frequence is about 400kHz.
3. Teency 2.0++ controller's frequence is not fast enouph at all, the fastest io switch speed is about 500kHz(not sure why).

For now I am using a stm32 to do the work, and it's speed is fast enough for me.

I successed to make that happen about two months ago, and just here to let you guys know this.

Thanks a lot for helping me again!

Offline Oli.Hall

  • Posts: 1
Hi,

I am looking to do something very similar to this and transform the 8 x 18 matrix of a Filco Majestouch 2.0 TKL into a matrix compatible with the Logitech K270 controller.
Which STM32 board did you use? Do you get good battery life with this microcontroller?
Would you be happy to share your code please?

Kind regards,
Oli.

Offline chiefacc2020

  • Posts: 1
I have totally no idea how to transform the signal from the stm32f4 by changing and controlling 27 pins of the K375s. Cloud you please share more ideas on this? I know that the io is in three groups 10+13+4.
I am focusing on controlling the 10pins. But should I have to use interrupt of the IO of 13pins?