-
-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i2c, ws2812, timer3 conflict? #773
Comments
Which keyboard is this for? You'll need timers on both halves - right now I don't think the animation stuff is sent over I2C, but that may be able to be changed. |
Sorry if I wasn't clear, it's for a "Let's Split" keyboard that I've hand-wired – it uses two atmega32u4 microcontrollers. Right. It doesn't seem like any rgbled_light stuff is currently communicated back to the slave keyboard via I2C. The code as-is only controls the master keyboards LEDs. FWIW I seem to be able to toggle the slave LEDs on/off & change HSV via I2C using a hacky little mod (which is probably wrong because I'm not familiar with the codebase), but changing to a mode that enables timer3 doesn't seem to work on the slave. |
The i2c code doesn't rely on anything that should conflict with the timer3 interrupt that I am aware of. Have you made sure your code is actually running on the slave? When the slave starts, it runs the code in this loop. The i2c slave code behaves similar to i2c eeprom devices. It's essential just an array of memory and a pointer into this array.
The first write of an i2c transaction sets the position of |
Thank you both for your responses. I do appreciate it.
Darn... that was the conclusion I was coming to from all my Google searches, but I wasn't sure. I fully admit to being a bit out of my depth here. I'm positive my code is running on the slave, because without my hacky patch nothing at all happens on the slave keyboard w.r.t. the LEDs.
Right. I found/modified that bit of the code. I couldn't figure out how the master incrementing the slave_buffer_pos would be useful in communicating that I wanted to take an action on the slave keyboard; it didn't seem like it was even used as nothing seemed to change when I commented it out. |
When you say it doesn't work, what does that mean? Do keypresses work on the slave side? Do animations start on the slave side and then everything else stops working? After a look at the code, I can see at least one way the i2c and rgb isr will conflict, but I can't say if this is the only problem. Possible cause of problemsAfter having a look at Quick and dirty fix that might not workFor a quick and dirty fix that might work, you could try enable interrupts as soon as the timer3 ISR starts, that is add Correct fixIMO, the correct way to get these two things working together would be to rewrite rgb code so that all the animation functions take a time as an argument Then, instead of using an interrupt to keep track of the time on the slave, send the value of the time used by the host to the slave. This has the advantage that the host and the slave will be syncronized. The slave can then control the LED animations in the same way as the master. These changes wouldn't be too hard to implement since the current implementation already uses |
Again, thank you for your time and info!
The animations on the slave do no start (they start on the master); the key presses are still communicated as expected. Some output + comments from
Thanks for this tip. I'll try it out tomorrow morning; maybe experiment with the I2C timeout as well and report back. |
If key presses are working, then the quick fix I suggested probably won't do anything. |
Okay, I think I found the problem. |
Wahoo! Adding The addition also seems to cause the keyboard to repeatedly send keys from the first row of the slave keyboard (mostly 'y') to the computer, and to be slow to respond to key presses on the slave. Perhaps I need to try the "quick and dirty" fix you mentioned earlier… |
If you're interested, I cleaned up the i2c api so that all the internals of i2c are now hidden. I'll probably get around to making a pull request for QMK some time. I added some test code that controls the slave promicro's RX LED: |
Neat! I'm certainly interested. I was able to integrate your i2c api and utilize your I2C_WRITE_TEST_CODE examples to send/recv key-presses to/on the slave keyboard. It's a lot easier to send actual keypresses with the api you created. :) There still seems to be the issue mentioned above when timer3 is enabled on the slave. It stops when I remove the Also, I realize that this may be an unsupported configuration (controlling the LEDs via I2C); I understand if this needs to be closed as WONTFIX :) |
The issue you mention sounds like it is caused by the long running ISR for timer 3 that I mentioned before. When Try these changes to the rgb code, that make the animation code polling based. You'll need to add
to the master's and slave's main_loops/matrix_scan functions. However, you would ideally pass the value of Edit: I don't have the hardware to test this, so some modifications may be necessary. |
FWIW, I tried both I don't want to conflate the issues if they're unrelated, but I'm still having the erroneously reported keypresses issue when animations are occurring on the slave - it doesn't matter which half is the slave and the frequency of the issue seems to be related to the speed of the animation. For fun, here's an output from
All that said, I don't know how much more of anyone's time I should waste if I'm the one of the only people trying to use this 'feature' :) There seems to be a decent work-around – I've tested the Serial setup and used the (now)spare conductor in the TRRS cable to control the LEDs. That seems to be working, LED animations included, without any major issues … though technically slower, I guess. |
I can't really make any valid judgement without seeing the exact code you used. It sounds like you got the setup you wanted anyway with the serial setup.
Using i2c would only shave off >1ms of latency in your setup, so it's not like you would notice. You'd only really need it if you wanted to try for more than 2-way split or something else fancy. |
I understand. I do have a minimal diff-gist saved should anyone be interested in the future.
Good to know! Ack! I only ventured down the i2c-road because I had read a few complaints about serial being "slow/laggy". Oh well. :) Thanks again for all your help. I think this can be closed; I'd be happy to help test stuff with my keyboard (if I still have it) should anyone brings this up in the future. |
I am very interested in your "hacky" mod you did to get the RGB on the salve half. I am also working on a let's split and was hoping to use the i2C to transmit the RGB DI |
Is this code on a branch somewhere that we could take a look? |
IIRC, @That-Canadian had the rgb part working, IIRC. But issues with the animations. |
I do indeed have RGB working over I2C, no animations though. It's on my profile under the "Lets_Split_Eh" branch if anyone wants to looks, I'll be making a PR soon once I'm done testing it. |
@That-Canadian Awesome, thanks, I'll take a look at that! |
@That-Canadian Looks like you're doing a bunch of general split cleanup that'll knock off #1600 in there too, nice! |
@mannkind @That-Canadian @ishtob Now that the initial static RGB over i2c is merged and working, maybe we can take a look at getting the animations going too? It seems that the animations can currently diverge between the left and right halves for two main reasons:
The way
(pseudocode, I'm not sure if it's valid in qmk to just increment timers like that or if there's a safe function to do that) |
* update default keymap: hid_liber * add default keymap: boardsource/4x12 * add default keymap: nebula65 * add default keymap: maartenwut/eon87 * add default keymap: nebula12 * add default keymap: ymdk/sp64 * add default keymap: clawsome/gamebuddy * add default keymap: exclusive/e85 * add default keymap: boardsource/5x12 * add default keymap: hineybush/h60 * update default keymap: noxary/x268 * update default keymap: noxary/268_2 * add default keymap: keebio/kbo5000/rev1 * add default keymaps: 4pplet keyboards Add 4pplet/aekiso60/rev_a, 4pplet/steezy60/rev_a, and 4pplet/waffling60/rev_a default keymaps. * update default keymap: handwired/jotanck * update default keymap: m0lly Update commit hash. * add default keymap: xelus/trinityxttkl * add default keymap: handwired/brain * update default keymap: jj50 * add default keymaps: clawsome keyboards Add clawsome/coupe and clawsome/sedan default keymaps. * add default keymaps: mechlovin/adelais rgb_led, standard_led/rev2, and standard_led/rev3 versions * add default keymap: fallacy * add default keymap: rotr * add default keymap: handwired/unk/rev1 * add default keymap: rart/rart67 * update default keymap: botanicalkeyboards/fm2u * add default keymap: maartenwut/eon65 * add default keymap: maartenwut/eon95 * add default keymap: arisu * update default keymap: rotr * add default keymap: gowla * white-space formatting for keymaps
* add x88 pcb and move other pcbs in my folder * fix default keymap issue
This is not a bug or issue, it's just a question.
I'm trying to use I2C to control the leds on the slave half of a hardwired lets split keyboard with ws2812 leds. It's working, for the most part, except for the led animations. The animations only seem to work on whichever half is the "master" keyboard.
Is there a conflict between the I2C/ISR and the Timer3/ISR?
I swear I've searched for the issue, but I've come up empty handed. I have a feeling this might be why all the examples I've found use one-wire serial communication between the two halves and connect the RGB_DI_PINs via the unused TRRS line.
The text was updated successfully, but these errors were encountered: