+bool matrix_is_modified(void) {
+ for (int i=0; i <MATRIX_ROWS; i++) {
+ if (matrix[i] != matrix_prev[i])
+ return true;
+ }
+ return false;
+}
+
+bool matrix_has_ghost(void) {
+ for (int i=0; i <MATRIX_ROWS; i++) {
+ if (matrix_has_ghost_in_row(i))
+ return true;
+ }
+ return false;
+}
+
+bool matrix_has_ghost_in_row(uint8_t row) {
+ uint8_t state = ~matrix[row];
+ // no ghost exists in case less than 2 keys on
+ if (((state - 1) & state) == 0)
+ return false;
+
+ // ghost exists in case same state as other row
+ for (int i=0; i < MATRIX_ROWS; i++) {
+ if (i == row) continue;
+ if ((~matrix[i] & state) == state) return true;
+ }
+ return false;
+}
+