Author Topic: ChibiOS/QMK for Infinity60 - reading from hardware register  (Read 1849 times)

0 Members and 1 Guest are viewing this topic.

Offline lunas

  • Thread Starter
  • Posts: 35
I'm on the last stages of porting over matt3o's and flabbergast's whitefox TMK led code to QMK for the infinity60. Since both boards use the same led controller I've just reused and expanded the work matt3o did. However, I've run into an issue with reading from a hardware register.

What I'm trying to do is set the Capslock led to blink if all leds are already on (full backlight). This involves reading a byte from the blink register on the controller and toggling a bit for the led. I'm using a mailbox to queue actions and most of the time the code works fine, but eventually it starts reading the blink register byte incorrectly when all the keys are lit and returns 0xFF/1F/EF etc. when it should be 0x00. My guess is that it has to do with the controller not keeping up with requests and sending a byte from another register.

The main functions involved
Code: [Select]
is31_read_register(page, byte address, buffer) --> i2cMasterTransmitTimeout(...)

I've tried sleeping (chThdSleepMilliseconds) as well as a blind attempt at locking the mailbox thread (chSysUnconditionalLock). This is my first go at C and ChibiOS so not sure where to look next.

Anyone know a way to get consistent reads from the controller through ChibiOS if requests are maybe coming quickly from the keyboard?
Pok3r Whitefox

Offline lunas

  • Thread Starter
  • Posts: 35
Re: ChibiOS/QMK for Infinity60 - reading from hardware register
« Reply #1 on: Tue, 20 June 2017, 19:03:06 »
Coming back to answer my own question in case anyone finds it helpful. Digging through the spec sheet for the led controller chip, I learned that led registers (vs. function registers) can only be read in software shutdown mode. So reading a led register requires you to put the chip into software shutdown temporarily, read the byte, then switch back to operating mode. Cumbersome, but the results are now predictable.
Pok3r Whitefox