Skip to content
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

Port SPLIT_USB_DETECT to helix/rev2 #7385

Merged
merged 3 commits into from
Dec 7, 2019
Merged

Conversation

stormbard
Copy link
Contributor

Description

This PR adds SPLIT_USB_DETECT support for those users having issues with Elite-C V3s.
Copied from PR #7195

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Copy link
Member

@zvecr zvecr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void matrix_init(void) within matrix.c also needs renaming to matrix_setup scratch that, just the block of debug toggles needs to be removed:

void matrix_init(void)
{
-    debug_enable = true;
-    debug_matrix = true;
-    debug_mouse = true;

@zvecr zvecr added the keyboard label Nov 17, 2019
@zvecr zvecr requested a review from a team November 17, 2019 04:15
@zvecr
Copy link
Member

zvecr commented Nov 17, 2019

Tagging @mtei @MakotoKurauchi
While there are long term plans to move to split_common, any issues with this change? I will really help with some of the reported issues we are seeing!

@mtei
Copy link
Contributor

mtei commented Nov 17, 2019

Currently, I am suggesting to MakotoKurauch to change Helix to use oled_driver.c instead of ssd1306.h. At the same time, I am preparing for the transition to split_common.
MakotoKurauchi#24

This PR may conflict with the above changes. So please don't do this PR yet.

@mtei
Copy link
Contributor

mtei commented Nov 17, 2019

This PR adds bool is_keyboard_master(void) to keyboards/helix/rev2/split_util.c.
Doing so will cause problems with the operation of RGB light. The right half rgb light mode will not be changed.

@zvecr
Copy link
Member

zvecr commented Nov 17, 2019

@mtei There are users currently suffering issues so I would rather push for this to go in.

split_common generally needs extra work to make it compatible, such as syncing matrix state. This will take extra time to review and merge. (Also that PR changes user keymaps so would have to go through the breaking change process). While this PR is based off another short term fix we have already applied.

As for adding is_keyboard_master, that wont break anything within rgblight (its not like we are in a language where we can check if the symbol is defined).

@mtei
Copy link
Contributor

mtei commented Nov 17, 2019

As for adding is_keyboard_master, that wont break anything within rgblight (its not like we are in a language where we can check if the symbol is defined).

Now I did the following:

git fetch qmk pull/7385/head:x
git checkout x
make helix/rev2/back:five_rows:avrdude-loop

And I tried RGB_TOG key, RGB_MOD key.
The master side worked correctly.
On the slave side, the LED cannot be turned on/off. mode does not change.

@zvecr
Copy link
Member

zvecr commented Nov 17, 2019

Is it this block that is in play then?

if (is_keyboard_master()) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
matrix_row = matrix_get_row(r);
matrix_change = matrix_row ^ matrix_prev[r];
if (matrix_change) {
#ifdef MATRIX_HAS_GHOST
if (has_ghost_in_row(r, matrix_row)) {
continue;
}
#endif
if (debug_matrix) matrix_print();
for (uint8_t c = 0; c < MATRIX_COLS; c++) {
if (matrix_change & ((matrix_row_t)1 << c)) {
action_exec((keyevent_t){
.key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & ((matrix_row_t)1 << c)), .time = (timer_read() | 1) /* time should not be 0 */
});
// record a processed key
matrix_prev[r] ^= ((matrix_row_t)1 << c);
#ifdef QMK_KEYS_PER_SCAN
// only jump out if we have processed "enough" keys.
if (++keys_processed >= QMK_KEYS_PER_SCAN)
#endif
// process a key per task call
goto MATRIX_LOOP_END;
}
}
}
}
}

Where the default implementation of is_master currently always returns true.

If so, we can just rename is_keyboard_master, maybe back to has_usb.

@zvecr
Copy link
Member

zvecr commented Nov 19, 2019

@stormbard can you copy in the latest updated found within #7404, this should fix keycode processing and potentially unblock this PR.

@stormbard
Copy link
Contributor Author

@zvecr I can push the changes but in my testing locally on my helix the right hand LEDs do not toggle off when the toggle key is pressed. Doesn't matter which one is master in this case.

I'm also still seeing some intermittent issues with the halves communicating. I'm not sure if this is due to a firmware or hardware issue though and will take suggestions for debugging.

@zvecr
Copy link
Member

zvecr commented Nov 22, 2019

It sounds like a hardware issue, though I don't have anything on hand to verify that is the case.

Does reverting the suggestions within #7404 make it work again?

@stormbard
Copy link
Contributor Author

Didn't work before or after the changes in #7404.

@stormbard
Copy link
Contributor Author

After some further testing I believe this change is good. I'm able to get the backlighting to work on both halves as I'd expect.

@mtei
Copy link
Contributor

mtei commented Dec 5, 2019

I made the patch to be a better implementation than I think.
mtei@61350f4
mtei@1ba76da
mtei@8bd374e
Would you like try it?

edit:
This patch includes the following changes:

  1. keyboards/helix/rev2/matrix.c
    moved uint8_t is_master; to keyboards/helix/rev2/rev2.c.
  2. keyboards/helix/rev2/split_util.[ch]
    • Renamed has_usb() to a more appropriately named is_helix_master().
    • Removed __attribute__ ((weak)) since it should not be used here.
  3. keyboards/helix/rev2/rev2.c
    Added is_master definition and initialization for backward compatibility.
  4. keyboards/helix/rev2/rev2.h
    • Added is_keyboard_master() as a wrapper macro.
    • Added has_usb() as a wrapper macro for backward compatibility.
  5. keyboards/helix/rev2/rules.mk.
    Make serial.c compile properly when LTO_ENABLE = yes.
  6. users/xulkal/custom_oled.c.
    Added is_keyboard_master() wrapper macro like keyboards/helix/rev2/rev2.h.

The 'xulkal' keymap needs to be changed to 5 and 6 above.

The 'xulkal' keymap requires is_keyboard_master(). However, if is_keyboard_master() is implemented as a function, 'tmk_core/common/keyboard.c:keyboard_task()' will behave differently between master and slave. This means that helix's split_utils.c, which expects to do the same for both master and slave, will not work properly.

To solve this, is_keyboard_master() must be implemented as a macro so that it is not called from 'tmk_core/common/keyboard.c:keyboard_task()'.

'users/xulkal/custom_oled.c' was outside of 'keyboards/helix/rev2', but a similar situation can occur in the source code in 'keyboards/helix/rev2'. Therefore, is_keyboard_master() is implemented as a macro in 'helix/rev2/rev2.h'.

@zvecr
Copy link
Member

zvecr commented Dec 5, 2019

the 'xulkal' keymap was not working.

@mtei Can you elaborate further on what the issue is please. The keymap compiles fine, and that suggestion is rather involved to see what the actual problem is.

@XScorpion2
Copy link
Contributor

XScorpion2 commented Dec 5, 2019

You can probably ignore, 'xulkal', helix keymap, I haven't used that board in a while, and usually have a quick turn around on fixing my own keymaps. Though I always do appreciate a heads up when one of my keymaps break.

Actually, I see exactly why my keymap breaks, there's a wrapper function I implemented in my user space for switching between split common, and custom split like the helix and I suspect that is now returning the wrong values. Easy fix.

@zvecr
Copy link
Member

zvecr commented Dec 6, 2019

@mtei I don't see any of those changes being a hard requirement for this PR:

  1. removing has_usb potentially breaks backwards compatibility
  2. moving is_master just adds code churn, and these short term fixes tend to aim for minimal change
  3. adding is_keyboard_master goes back to Fix processing of RGB keycodes on crkbd slave half #7404 where it will break previous assumptions, though as per that PR, its only an issue if included in tmk_core/common/keyboard.c which the proposed rev2.h currently isn't unless a user adds in within their keymaps config.h path
    4 serial.c and its compilation in this PR remains unchanged so should be considered out of scope
  4. xulkal keymaps implementation of is_keyboard_master should remain unchanged as the underpinning is_master bool it depends on has the same behaviour as before

Though if you do want to propose some of those changes, feel free to raise a separate PR.

@mtei
Copy link
Contributor

mtei commented Dec 7, 2019

  1. adding is_keyboard_master goes back to Fix processing of RGB keycodes on crkbd slave half #7404 where it will break previous assumptions, though as per that PR, its only an issue if included in tmk_core/common/keyboard.c which the proposed rev2.h currently isn't unless a user adds in within their keymaps config.h path
    4 serial.c and its compilation in this PR remains unchanged so should be considered out of scope

I'm not good at English. This sentence was too long for me to understand. So I can't comment, sorry.

However, I have confirmed that my patch has been tested and works correctly with all keymaps. Don't forget it.

  1. xulkal keymaps implementation of is_keyboard_master should remain unchanged as the underpinning is_master bool it depends on has the same behaviour as before

'helix:xulkal' has problems similar to those solved by #7404. Currently, 'helix:xulkal' can be compiled but is not working properly. If you want 'helix:xulkal' to work correctly, you need to fix it.

I checked the operation before and after applying my patch. It has been confirmed that it will not work properly before the patch is applied. It has been confirmed that it works correctly after applying the patch.

However, the 'helix:xulkal' problem is certainly outside the scope of this PR.
I will open a new PR after this PR has been merged.

@mtei
Copy link
Contributor

mtei commented Dec 7, 2019

Of course I don't care if my patch was not included in this PR. Either way, I approve this PR. However, my patch above will be needed for backward compatibility when Helix changes to use split_common in the future.

  1. removing has_usb potentially breaks backwards compatibility
  2. moving is_master just adds code churn, and these short term fixes tend to aim for minimal change

'is_master' and 'has_usb()' must not be removed for backward compatibility. You say my patch breaks backward compatibility, which is a misunderstanding. My patch keeps backward compatibility better than the current code of this PR.

The current code for this PR causes problems when changing Helix to use split_common. My patch avoids that problem.

@zvecr
Copy link
Member

zvecr commented Dec 7, 2019

My patch keeps backward compatibility better than the current code of this PR

That is a bit of an abstract statement, can you provide an example where this PR breaks backwards compatibility?

@mtei
Copy link
Contributor

mtei commented Dec 7, 2019

To reiterate what I already wrote above, in this PR's current code, 'is_master' is in 'helix/rev2/matrix.c' and 'has_usb()' is in 'helix/It is in rev2/split_util.c'.
If Helix uses split_common, the two files will not be linked.

@zvecr
Copy link
Member

zvecr commented Dec 7, 2019

But thats not a backwards compatibility issue.

As there are none being raised, im going to merge this as is.

@zvecr zvecr merged commit 36a6e26 into qmk:master Dec 7, 2019
@zvecr
Copy link
Member

zvecr commented Dec 7, 2019

Cheers for your work @stormbard!

@stormbard stormbard deleted the helix_usb_detect branch December 8, 2019 04:20
patrl pushed a commit to patrl/qmk_firmware that referenced this pull request Dec 29, 2019
* Port SPLIT_USB_DETECT to helix/rev2

* Remove debug toggles.

* Rename is_keyboard_master to has_usb in split_util
@zvecr zvecr mentioned this pull request Feb 6, 2020
13 tasks
HokieGeek pushed a commit to HokieGeek/qmk_firmware that referenced this pull request Feb 21, 2020
* Port SPLIT_USB_DETECT to helix/rev2

* Remove debug toggles.

* Rename is_keyboard_master to has_usb in split_util
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants