-
-
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
Removed the need for timeout if using SPLIT_USB_DETECT #9742
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the change in behaviour, this should target the develop
branch.
@@ -135,6 +132,9 @@ __attribute__((weak)) bool is_keyboard_master(void) { | |||
void split_pre_init(void) { | |||
isLeftHand = is_keyboard_left(); | |||
|
|||
// Start in slave configuration and wait for a master to emerge | |||
transport_slave_init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this here now calls init twice, and breaks #8235 again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, it's called twice for the master half?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, for changing the target branch without strange side effects, I need to reopen this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that if I just remove the repeated initialization in split_post_init
, it will bring back the race-condition bug? The slave will finish USB initialization when the master is determined and will not overwrite any settings that are sent over the transport.
quantum/split_common/split_util.c
Outdated
@@ -135,6 +132,9 @@ __attribute__((weak)) bool is_keyboard_master(void) { | |||
void split_pre_init(void) { | |||
isLeftHand = is_keyboard_left(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will infinite loop on MASTER_LEFT/MASTER_RIGHT as the slave transport is not established.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain? Do you mean that it will not return as long as there is no slave that answers the master's messages?
Edit: Also, is that a problem? I just tested with my UART split board and the master does not stay in that loop after connecting USB. It works without a slave as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested with my UART split board and the master does not stay in that loop after connecting USB. It works without a slave as well.
This is a board that uses EE_HANDS/SPLIT_HAND_PIN for handedness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is (EE_HANDS). Let's say it was a board that entered is_keyboard_master()
, this would return after finding USB or receiving a message from the master. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case is_keyboard_left
calls is_keyboard_master
before transport_slave_init happens. Thus it will never get its "slave" assignment as there will never be anything listening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the slave initialization forward in a later commit (ea40f38): https://github.com/qmk/qmk_firmware/pull/9742/files#diff-57e6bd7db0b3e56c607994b241d7b945R132-R134
I did some cleanup for rebasing this onto the develop branch. Excuse the repeated force-pushes. Edit: Force-push to the develop branch required fixing again. |
I managed to remove the review request for qmk/collaborators, sorry for that. |
@zvecr For pushing this forward, do you see any further issues with the current state of the code? Sadly, I cannot test the operation for I2C. |
Yes, #8235 would still be re-broken by this change. |
I am failing to see why that would be the case. Let me summarize the new order of events upon initialization:
I don't see where the slave overwrites the RGB settings that it got from the master via transport with those old settings from EEPROM. The slave is initialized at the beginning in 2), prior to receiving new RGB settings. If it is initialized after the master has already found USB, then the serial transfer of new settings failswell and will be repeated. Therefore, no race condition can happen, as far as I can understand. To reiterate: there is only one initialization on the slave side, before any communication with the master can occur. Therefore, initialization (and reading old settings from EEPROM) cannot happen after a link to the master is successfully established. |
This needs to be rebased, and the merge conflicts resolved. |
I will do it next week. |
@noroadsleft Rebased to latest develop force-push. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#8235 describes the issue. The main part is that slave is listening during startup, so will respond to any rgb sync actions before its ready to do so. Also, the listening on the master side being left on would also mean that serial commands would still trigger the ISR processing on both halves.
1d4c0cd
to
65c27a3
Compare
@zvecr I don't quite get how communication works. Could you clarify a bit? I see that in 'matrix_post_scan()', the 'transport_master()' and 'transport_slave()' functions are called. These handle any data that was shared over the transport (UART or I2C). I am on AVR at the moment, so this is not ChibiOS-based, right? Can you point me to the interrupt handler that you are talking about? I only find one for ChibiOS. With regard to leaving the slave interrupt handlers enabled on the master-side, I will look into disabling them after the master was found. |
@tzarc Should further development continue on this issue? |
I was in the process of reopening accidentally closed PRs -- we went through a |
I understand! |
This has a bunch of merge conflicts, now. |
Thank you for your contribution! |
Closing, out of date. |
@elagil Hey, is it out of date because it has been fixed elsewhere somehow? Thanks! |
@GilDev I don't know if it was fixed, but my contribution is no longer compatible with the current codebase (and was never merged). |
Following my issue #8990, I created a fix for the described problem. To reiterate:
With
SPLIT_USB_DETECT
, QMK currently tries to find a USB connection during a timeout period (default 2 seconds). If not found, the board half is set to slave, otherwise to master. This is unreliable, if the connection is not found within the timeout period for some reason. Now, the detection is much faster and reliable. It is not required to wait for any timeout to finish.Description
I implemented a communication phase during the USB master side detection, which works like this:
I tested for UART but implemented changes for I2C as well. I would be happy, if someone could test it, since I have no I2C board available.
Types of Changes
Issues Fixed or Closed by This PR
#8990
Checklist