pok3r-custom / pok3r_re_firmware

Reverse engineering project for the POK3R and related keyboards.
219 stars 17 forks source link

[Pok3r RGB] RGB matrix in QMK #38

Open hansemro opened 1 year ago

hansemro commented 1 year ago

~Don't have pok3r RGB keyboard, but~ wanted to help out with the RE effort and create a starting point for support in QMK. (Update: got the keyboard).

Pok3r RGB has 2 MBIA043 LED Drivers in a chain. Stock firmware uses GPTM1 to drive GCLK PWM signal and uses BFTM1 for time-multiplexing.

GPTM1 PWM frequency: 14.4 MHz

BFMT1 compare value: 60,000 ticks (where input frequency is 72 MHz)

Pin Mapping (identical to Pro S RGB): MBIA043 GCLK: C0 MBIA043 DCLK: A14 MBIA043 LE: A15 MBIA043 SDI: C2 MBIA043 SDO: B0 MBIA043 Power: C1 (power is enabled when C1 is low)

LED (Column) GPIO Pins (gpio_map_3 in pok3r_rgb/v140 disassembly): C8, C7, B5, B4, B3, B2, C6, C5

MBIA043 Configuration (same as Pro S RGB): 0xc for both drivers

Tasks:

hansemro commented 1 year ago

Mainline port of QMK: https://github.com/hansemro/qmk_firmware/tree/pok3r_rgb_dev

MBIA043 driver is not yet included but is being worked on.

Also, this port disables watchdog timer to prevent the keyboard from resetting. Related change: https://github.com/hansemro/qmk_firmware/blob/4c39e29d7b4b4e1340ff32ab6d9630b5812aadcd/keyboards/vortex/pok3r_rgb/boards/CYKB167_D_V03/board.c#L114-L115

hansemro commented 1 year ago

Dev branch with partially working MBIA043 driver: https://github.com/hansemro/qmk_firmware/tree/pok3r_rgb_mbia043_dev

The main issue I am facing is that the 2nd MBIA043 (U8) is not functioning. I checked that it is receiving 5V and the pins appear connected correctly, but it is not driving LEDs or shifting data out of SDO. I don't have a scope or logic analyzer currently, so I cannot check the pins clearly or easily.

hansemro commented 1 year ago

DCLK, GCLK, LE, and SDI pins are okay.

However, U8's SDO appears stuck on low when shifting 1 and 0s.

while (1) {
    mbia043_shift_data(1U << 15, 1);
    wait_ms(2000);
    mbia043_shift_data(0, 1);
    wait_ms(2000);
}

Update:

Fixed in https://github.com/hansemro/qmk_firmware/commit/7db2a0dfe801f16947066011bd57a37c5a937a10. Issue was related to bad GPIO configuration (opendrain should be used since there are pull-up resistors to 5V).

hansemro commented 1 year ago

MBIA043 demo on POK3R RGB:

https://user-images.githubusercontent.com/40348686/212595252-6d27a63c-54a7-4d91-959b-183b50ba8e15.mp4

I need to fixup a few things, but RGB lighting is working!

hansemro commented 1 year ago

Fixed LED Matrix in https://github.com/hansemro/qmk_firmware/commit/f83ebf3e456c4a70db7666bd8c9c1bd8bc9adfa2

hansemro commented 1 year ago

Caps Lock RGB LED at (row 6, col 2) in LED matrix.

Space's Left RGB LED at (row8, col 2).

Space's Right RGB LED at (row 9, col 3).

hansemro commented 1 year ago

Although currently unstable, SPI flash support can be enabled by uncommenting these lines in rules.mk: https://github.com/hansemro/qmk_firmware/blob/537444b853d7ce7aa7e83920365927ac4f1200bb/keyboards/vortex/pok3r_rgb/rules.mk#L11-L12

From limited testing, I found this branch to help improve SPI flash reliability (when rapidly changing RGB effects): https://github.com/hansemro/ChibiOS-Contrib/tree/ht32-spi-tx-wc-fix

ChaoticEnigma commented 1 year ago

This is very cool, great work! Sorry for sleeping on this, I've been super busy lately. I'll find some time to try this on mine this week!

hansemro commented 1 year ago

I am currently investigating conditions that cause LEDs to flicker. I started noticing this when my PC shuts down but is still delivering some power to the keyboard.

hansemro commented 4 months ago

Updated tasks with upstreaming plans with the goal to reduce tool requirements and steps by:

hansemro commented 4 months ago

ISO support included in the following branches: