{"action":"created","comment":{"url":"https://api.github.com/repos/qmk/qmk_firmware/pulls/comments/116364917","pull_request_review_id":37985529,"id":116364917,"diff_hunk":"@@ -64,20 +64,41 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.\n \n \n #ifdef MATRIX_HAS_GHOST\n+static uint16_t matrix_ghost_check[MATRIX_ROWS];","path":"tmk_core/common/keyboard.c","position":4,"original_position":4,"commit_id":"849ed5a6a03b14defa94a50b66169abac89b9c08","original_commit_id":"849ed5a6a03b14defa94a50b66169abac89b9c08","user":{"login":"barrar","id":2785600,"avatar_url":"https://avatars2.githubusercontent.com/u/2785600?v=3","gravatar_id":"","url":"https://api.github.com/users/barrar","html_url":"https://github.com/barrar","followers_url":"https://api.github.com/users/barrar/followers","following_url":"https://api.github.com/users/barrar/following{/other_user}","gists_url":"https://api.github.com/users/barrar/gists{/gist_id}","starred_url":"https://api.github.com/users/barrar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barrar/subscriptions","organizations_url":"https://api.github.com/users/barrar/orgs","repos_url":"https://api.github.com/users/barrar/repos","events_url":"https://api.github.com/users/barrar/events{/privacy}","received_events_url":"https://api.github.com/users/barrar/received_events","type":"User","site_admin":false},"body":"I'm sure the compiler does a few optimizations here, since it's all static information. Size before (I'm using arm) 33560, size after: 33608. Total added: 48 bytes. The extra logic adds a bit (pun intended). I'd like to see it on AVR, might be different.","created_at":"2017-05-13T18:52:15Z","updated_at":"2017-05-13T18:52:16Z","html_url":"https://github.com/qmk/qmk_firmware/pull/1298#discussion_r116364917","pull_request_url":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298","_links":{"self":{"href":"https://api.github.com/repos/qmk/qmk_firmware/pulls/comments/116364917"},"html":{"href":"https://github.com/qmk/qmk_firmware/pull/1298#discussion_r116364917"},"pull_request":{"href":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298"}}},"pull_request":{"url":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298","id":120453197,"html_url":"https://github.com/qmk/qmk_firmware/pull/1298","diff_url":"https://github.com/qmk/qmk_firmware/pull/1298.diff","patch_url":"https://github.com/qmk/qmk_firmware/pull/1298.patch","issue_url":"https://api.github.com/repos/qmk/qmk_firmware/issues/1298","number":1298,"state":"open","locked":false,"title":"Anti-ghost improvement for older keyboards with empty spots in matrix","user":{"login":"barrar","id":2785600,"avatar_url":"https://avatars2.githubusercontent.com/u/2785600?v=3","gravatar_id":"","url":"https://api.github.com/users/barrar","html_url":"https://github.com/barrar","followers_url":"https://api.github.com/users/barrar/followers","following_url":"https://api.github.com/users/barrar/following{/other_user}","gists_url":"https://api.github.com/users/barrar/gists{/gist_id}","starred_url":"https://api.github.com/users/barrar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barrar/subscriptions","organizations_url":"https://api.github.com/users/barrar/orgs","repos_url":"https://api.github.com/users/barrar/repos","events_url":"https://api.github.com/users/barrar/events{/privacy}","received_events_url":"https://api.github.com/users/barrar/received_events","type":"User","site_admin":false},"body":"With anti ghost off, pressing K60, K61 and K50 works fine, but turned on it detects a ghost on K51. On my keymap there is no real K51 key connected to the matrix. This spot in the matrix is marked KC_NO.\r\n\r\n\r\n\r\nI dynamically generate an array that maps real keys and empty spots in matrix:\r\n```\r\nstatic uint16_t matrix_ghost_check[MATRIX_ROWS]{\r\n0b001101111110111,\r\n0b101111111101110,\r\n0b010010111111111,\r\n0b111111001111001,\r\n0b111011101111111,\r\n0b111111111111001,\r\n0b110110110110111,\r\n0b111101010011110\r\n};\r\n```\r\nfull code here:\r\n```\r\n\r\nstatic uint16_t matrix_ghost_check[MATRIX_ROWS];\r\nstatic bool has_ghost_in_row(uint8_t row)\r\n{\r\n    matrix_row_t matrix_row = (matrix_get_row(row) & matrix_ghost_check[row]);\r\n    /* No ghost exists when less than 2 keys are down on the row.\r\n    If there are \"active\" blanks in the matrix, the key can't be pressed by the user,\r\n    there is no doubt as to which keys are really being pressed.\r\n    The ghosts will be ignored, they are KC_NO.   */\r\n    if (((matrix_row - 1) & matrix_row) == 0){\r\n        return false;\r\n    }\r\n    // Ghost occurs when the row shares column line with other row, blanks in the matrix don't matter\r\n    // If there are more than two real keys pressed and they match another row's real keys, the row will be ignored.\r\n    for (uint8_t i=0; i < MATRIX_ROWS; i++) {\r\n        if (i != row && __builtin_popcount((matrix_get_row(i) & matrix_ghost_check[i]) & matrix_row) > 1){\r\n            return true;\r\n        }\r\n    }\r\n    return false;\r\n    return false;\r\n}\r\n\r\nextern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];\r\n// bit map of true keys and empty spots in matrix, each row is reversed\r\nvoid make_ghost_check_array(){\r\n    for (int row = 0; row < MATRIX_ROWS; row++) {\r\n        for (int col = 0; col < MATRIX_COLS; col++) {\r\n            if (keymaps[0][row][col] & 0xFF)\r\n                matrix_ghost_check[row] |= 1<<col;\r\n            else\r\n                matrix_ghost_check[row] |= 0<<col;\r\n        }\r\n    }\r\n}\r\n```","created_at":"2017-05-13T15:54:29Z","updated_at":"2017-05-13T18:52:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3f0c9e6c9073ca0d442ad8212b90c02b41078dd9","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298/commits","review_comments_url":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298/comments","review_comment_url":"https://api.github.com/repos/qmk/qmk_firmware/pulls/comments{/number}","comments_url":"https://api.github.com/repos/qmk/qmk_firmware/issues/1298/comments","statuses_url":"https://api.github.com/repos/qmk/qmk_firmware/statuses/849ed5a6a03b14defa94a50b66169abac89b9c08","head":{"label":"barrar:master","ref":"master","sha":"849ed5a6a03b14defa94a50b66169abac89b9c08","user":{"login":"barrar","id":2785600,"avatar_url":"https://avatars2.githubusercontent.com/u/2785600?v=3","gravatar_id":"","url":"https://api.github.com/users/barrar","html_url":"https://github.com/barrar","followers_url":"https://api.github.com/users/barrar/followers","following_url":"https://api.github.com/users/barrar/following{/other_user}","gists_url":"https://api.github.com/users/barrar/gists{/gist_id}","starred_url":"https://api.github.com/users/barrar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barrar/subscriptions","organizations_url":"https://api.github.com/users/barrar/orgs","repos_url":"https://api.github.com/users/barrar/repos","events_url":"https://api.github.com/users/barrar/events{/privacy}","received_events_url":"https://api.github.com/users/barrar/received_events","type":"User","site_admin":false},"repo":{"id":90830787,"name":"qmk_firmware","full_name":"barrar/qmk_firmware","owner":{"login":"barrar","id":2785600,"avatar_url":"https://avatars2.githubusercontent.com/u/2785600?v=3","gravatar_id":"","url":"https://api.github.com/users/barrar","html_url":"https://github.com/barrar","followers_url":"https://api.github.com/users/barrar/followers","following_url":"https://api.github.com/users/barrar/following{/other_user}","gists_url":"https://api.github.com/users/barrar/gists{/gist_id}","starred_url":"https://api.github.com/users/barrar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barrar/subscriptions","organizations_url":"https://api.github.com/users/barrar/orgs","repos_url":"https://api.github.com/users/barrar/repos","events_url":"https://api.github.com/users/barrar/events{/privacy}","received_events_url":"https://api.github.com/users/barrar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/barrar/qmk_firmware","description":"keyboard controller firmware for Atmel AVR USB family","fork":true,"url":"https://api.github.com/repos/barrar/qmk_firmware","forks_url":"https://api.github.com/repos/barrar/qmk_firmware/forks","keys_url":"https://api.github.com/repos/barrar/qmk_firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/barrar/qmk_firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/barrar/qmk_firmware/teams","hooks_url":"https://api.github.com/repos/barrar/qmk_firmware/hooks","issue_events_url":"https://api.github.com/repos/barrar/qmk_firmware/issues/events{/number}","events_url":"https://api.github.com/repos/barrar/qmk_firmware/events","assignees_url":"https://api.github.com/repos/barrar/qmk_firmware/assignees{/user}","branches_url":"https://api.github.com/repos/barrar/qmk_firmware/branches{/branch}","tags_url":"https://api.github.com/repos/barrar/qmk_firmware/tags","blobs_url":"https://api.github.com/repos/barrar/qmk_firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/barrar/qmk_firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/barrar/qmk_firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/barrar/qmk_firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/barrar/qmk_firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/barrar/qmk_firmware/languages","stargazers_url":"https://api.github.com/repos/barrar/qmk_firmware/stargazers","contributors_url":"https://api.github.com/repos/barrar/qmk_firmware/contributors","subscribers_url":"https://api.github.com/repos/barrar/qmk_firmware/subscribers","subscription_url":"https://api.github.com/repos/barrar/qmk_firmware/subscription","commits_url":"https://api.github.com/repos/barrar/qmk_firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/barrar/qmk_firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/barrar/qmk_firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/barrar/qmk_firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/barrar/qmk_firmware/contents/{+path}","compare_url":"https://api.github.com/repos/barrar/qmk_firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/barrar/qmk_firmware/merges","archive_url":"https://api.github.com/repos/barrar/qmk_firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/barrar/qmk_firmware/downloads","issues_url":"https://api.github.com/repos/barrar/qmk_firmware/issues{/number}","pulls_url":"https://api.github.com/repos/barrar/qmk_firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/barrar/qmk_firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/barrar/qmk_firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/barrar/qmk_firmware/labels{/name}","releases_url":"https://api.github.com/repos/barrar/qmk_firmware/releases{/id}","deployments_url":"https://api.github.com/repos/barrar/qmk_firmware/deployments","created_at":"2017-05-10T06:52:29Z","updated_at":"2017-05-10T06:52:37Z","pushed_at":"2017-05-13T15:51:28Z","git_url":"git://github.com/barrar/qmk_firmware.git","ssh_url":"git@github.com:barrar/qmk_firmware.git","clone_url":"https://github.com/barrar/qmk_firmware.git","svn_url":"https://github.com/barrar/qmk_firmware","homepage":"","size":84668,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"qmk:master","ref":"master","sha":"04069c94ccc2878fd8b66153f6fc58987461caf2","user":{"login":"qmk","id":25358678,"avatar_url":"https://avatars0.githubusercontent.com/u/25358678?v=3","gravatar_id":"","url":"https://api.github.com/users/qmk","html_url":"https://github.com/qmk","followers_url":"https://api.github.com/users/qmk/followers","following_url":"https://api.github.com/users/qmk/following{/other_user}","gists_url":"https://api.github.com/users/qmk/gists{/gist_id}","starred_url":"https://api.github.com/users/qmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmk/subscriptions","organizations_url":"https://api.github.com/users/qmk/orgs","repos_url":"https://api.github.com/users/qmk/repos","events_url":"https://api.github.com/users/qmk/events{/privacy}","received_events_url":"https://api.github.com/users/qmk/received_events","type":"Organization","site_admin":false},"repo":{"id":27737393,"name":"qmk_firmware","full_name":"qmk/qmk_firmware","owner":{"login":"qmk","id":25358678,"avatar_url":"https://avatars0.githubusercontent.com/u/25358678?v=3","gravatar_id":"","url":"https://api.github.com/users/qmk","html_url":"https://github.com/qmk","followers_url":"https://api.github.com/users/qmk/followers","following_url":"https://api.github.com/users/qmk/following{/other_user}","gists_url":"https://api.github.com/users/qmk/gists{/gist_id}","starred_url":"https://api.github.com/users/qmk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmk/subscriptions","organizations_url":"https://api.github.com/users/qmk/orgs","repos_url":"https://api.github.com/users/qmk/repos","events_url":"https://api.github.com/users/qmk/events{/privacy}","received_events_url":"https://api.github.com/users/qmk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/qmk/qmk_firmware","description":"keyboard controller firmware for Atmel AVR and ARM USB families","fork":false,"url":"https://api.github.com/repos/qmk/qmk_firmware","forks_url":"https://api.github.com/repos/qmk/qmk_firmware/forks","keys_url":"https://api.github.com/repos/qmk/qmk_firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/qmk/qmk_firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/qmk/qmk_firmware/teams","hooks_url":"https://api.github.com/repos/qmk/qmk_firmware/hooks","issue_events_url":"https://api.github.com/repos/qmk/qmk_firmware/issues/events{/number}","events_url":"https://api.github.com/repos/qmk/qmk_firmware/events","assignees_url":"https://api.github.com/repos/qmk/qmk_firmware/assignees{/user}","branches_url":"https://api.github.com/repos/qmk/qmk_firmware/branches{/branch}","tags_url":"https://api.github.com/repos/qmk/qmk_firmware/tags","blobs_url":"https://api.github.com/repos/qmk/qmk_firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/qmk/qmk_firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/qmk/qmk_firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/qmk/qmk_firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/qmk/qmk_firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/qmk/qmk_firmware/languages","stargazers_url":"https://api.github.com/repos/qmk/qmk_firmware/stargazers","contributors_url":"https://api.github.com/repos/qmk/qmk_firmware/contributors","subscribers_url":"https://api.github.com/repos/qmk/qmk_firmware/subscribers","subscription_url":"https://api.github.com/repos/qmk/qmk_firmware/subscription","commits_url":"https://api.github.com/repos/qmk/qmk_firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/qmk/qmk_firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/qmk/qmk_firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/qmk/qmk_firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/qmk/qmk_firmware/contents/{+path}","compare_url":"https://api.github.com/repos/qmk/qmk_firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/qmk/qmk_firmware/merges","archive_url":"https://api.github.com/repos/qmk/qmk_firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/qmk/qmk_firmware/downloads","issues_url":"https://api.github.com/repos/qmk/qmk_firmware/issues{/number}","pulls_url":"https://api.github.com/repos/qmk/qmk_firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/qmk/qmk_firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/qmk/qmk_firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/qmk/qmk_firmware/labels{/name}","releases_url":"https://api.github.com/repos/qmk/qmk_firmware/releases{/id}","deployments_url":"https://api.github.com/repos/qmk/qmk_firmware/deployments","created_at":"2014-12-08T22:02:05Z","updated_at":"2017-05-13T05:23:13Z","pushed_at":"2017-05-13T18:25:10Z","git_url":"git://github.com/qmk/qmk_firmware.git","ssh_url":"git@github.com:qmk/qmk_firmware.git","clone_url":"https://github.com/qmk/qmk_firmware.git","svn_url":"https://github.com/qmk/qmk_firmware","homepage":"","size":84684,"stargazers_count":1132,"watchers_count":1132,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1620,"mirror_url":null,"open_issues_count":159,"forks":1620,"open_issues":159,"watchers":1132,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298"},"html":{"href":"https://github.com/qmk/qmk_firmware/pull/1298"},"issue":{"href":"https://api.github.com/repos/qmk/qmk_firmware/issues/1298"},"comments":{"href":"https://api.github.com/repos/qmk/qmk_firmware/issues/1298/comments"},"review_comments":{"href":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298/comments"},"review_comment":{"href":"https://api.github.com/repos/qmk/qmk_firmware/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/qmk/qmk_firmware/pulls/1298/commits"},"statuses":{"href":"https://api.github.com/repos/qmk/qmk_firmware/statuses/849ed5a6a03b14defa94a50b66169abac89b9c08"}}}}
{"actor":{"display_login":"barrar"}}