~ruther/qmk_firmware

2557bc8e6f6e61352fa5875646d861126c42a3b0 — fauxpark 5 years ago b83e3ae
Remove custom matrix from PS2AVRGB boards (#7396)

* Remove custom matrix from PS2AVRGB boards

* Add custom backlight.c to SRC for bminiex, for now

* Add missing DIODE_DIRECTIONs
69 files changed, 81 insertions(+), 1782 deletions(-)

M keyboards/bfake/bfake.c
M keyboards/bfake/config.h
D keyboards/bfake/matrix.c
M keyboards/bfake/rules.mk
M keyboards/coseyfannitutti/discipad/discipad.c
M keyboards/coseyfannitutti/discipline/discipline.c
M keyboards/exclusive/e6v2/le_bmc/keymaps/default/keymap.c
M keyboards/exclusive/e6v2/oe_bmc/keymaps/default/keymap.c
M keyboards/ft/mars80/keymaps/default/keymap.c
M keyboards/jc65/v32a/config.h
D keyboards/jc65/v32a/matrix.c
M keyboards/jc65/v32a/rules.mk
M keyboards/jc65/v32a/v32a.c
M keyboards/jc65/v32a/v32a.h
M keyboards/jj40/rules.mk
M keyboards/jj50/config.h
M keyboards/jj50/jj50.c
M keyboards/jj50/jj50.h
D keyboards/jj50/matrix.c
M keyboards/jj50/rules.mk
M keyboards/leeku/finger65/config.h
M keyboards/mechmini/v1/config.h
D keyboards/mechmini/v1/matrix.c
M keyboards/mechmini/v1/rules.mk
M keyboards/mechmini/v1/v1.c
M keyboards/mechmini/v1/v1.h
M keyboards/mehkee96/config.h
M keyboards/mehkee96/keymaps/default/keymap.c
D keyboards/mehkee96/matrix.c
M keyboards/mehkee96/mehkee96.c
M keyboards/mehkee96/rules.mk
M keyboards/mt40/config.h
D keyboards/mt40/matrix.c
M keyboards/mt40/mt40.h
M keyboards/mt40/rules.mk
M keyboards/percent/canoe/canoe.c
M keyboards/percent/canoe/canoe.h
M keyboards/percent/canoe/config.h
D keyboards/percent/canoe/matrix.c
M keyboards/percent/canoe/rules.mk
M keyboards/percent/skog/config.h
M keyboards/percent/skog/keymaps/default/keymap.c
D keyboards/percent/skog/matrix.c
M keyboards/percent/skog/skog.c
M keyboards/percent/skog/skog.h
M keyboards/winkeyless/bface/config.h
M keyboards/winkeyless/bmini/bmini.c
M keyboards/winkeyless/bmini/config.h
D keyboards/winkeyless/bmini/matrix.c
M keyboards/winkeyless/bmini/rules.mk
M keyboards/winkeyless/bminiex/config.h
D keyboards/winkeyless/bminiex/matrix.c
M keyboards/winkeyless/bminiex/rules.mk
M keyboards/ymd75/config.h
D keyboards/ymd75/matrix.c
M keyboards/ymd75/rules.mk
M keyboards/ymd75/ymd75.c
M keyboards/ymd75/ymd75.h
M keyboards/ymd96/config.h
D keyboards/ymd96/matrix.c
M keyboards/ymd96/rules.mk
M keyboards/ymd96/ymd96.c
M keyboards/ymd96/ymd96.h
M keyboards/ymdk/bface/config.h
M keyboards/ymdk/bface/rules.mk
M keyboards/ymdk_np21/config.h
D keyboards/ymdk_np21/matrix.c
M keyboards/ymdk_np21/rules.mk
M keyboards/ymdk_np21/ymdk_np21.h
M keyboards/bfake/bfake.c => keyboards/bfake/bfake.c +0 -3
@@ 17,9 17,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "bfake.h"

__attribute__ ((weak))
void matrix_scan_user(void) {}

void backlight_init_ports(void) {
	setPinOutput(D0);
	setPinOutput(D1);

M keyboards/bfake/config.h => keyboards/bfake/config.h +1 -1
@@ 32,7 32,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_COLS 11

#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6}
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5 }
#define UNUSED_PINS

#define DIODE_DIRECTION COL2ROW

D keyboards/bfake/matrix.c => keyboards/bfake/matrix.c +0 -106
@@ 1,106 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }
}

void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_user();

    return 1;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/bfake/rules.mk => keyboards/bfake/rules.mk +0 -4
@@ 22,7 22,3 @@ RGBLIGHT_ENABLE = no
WS2812_DRIVER = i2c

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c

M keyboards/coseyfannitutti/discipad/discipad.c => keyboards/coseyfannitutti/discipad/discipad.c +0 -8
@@ 14,11 14,3 @@
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "discipad.h"


void matrix_init_kb(void) {
	// put your keyboard start-up code here
	// runs once when the firmware starts up

	matrix_init_user();
}

M keyboards/coseyfannitutti/discipline/discipline.c => keyboards/coseyfannitutti/discipline/discipline.c +0 -8
@@ 14,11 14,3 @@
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "discipline.h"


void matrix_init_kb(void) {
	// put your keyboard start-up code here
	// runs once when the firmware starts up

	matrix_init_user();
}

M keyboards/exclusive/e6v2/le_bmc/keymaps/default/keymap.c => keyboards/exclusive/e6v2/le_bmc/keymaps/default/keymap.c +0 -12
@@ 60,15 60,3 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  }
  return true;
}

void matrix_init_user(void) {

}

void matrix_scan_user(void) {

}

void led_set_user(uint8_t usb_led) {

}

M keyboards/exclusive/e6v2/oe_bmc/keymaps/default/keymap.c => keyboards/exclusive/e6v2/oe_bmc/keymaps/default/keymap.c +0 -12
@@ 60,15 60,3 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  }
  return true;
}

void matrix_init_user(void) {

}

void matrix_scan_user(void) {

}

void led_set_user(uint8_t usb_led) {

}

M keyboards/ft/mars80/keymaps/default/keymap.c => keyboards/ft/mars80/keymaps/default/keymap.c +0 -12
@@ 61,15 61,3 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  }
  return true;
}

void matrix_init_user(void) {

}

void matrix_scan_user(void) {

}

void led_set_user(uint8_t usb_led) {

}

M keyboards/jc65/v32a/config.h => keyboards/jc65/v32a/config.h +5 -2
@@ 26,8 26,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT         JC65 PS2AVRGB

/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 16
#define MATRIX_ROWS 7
#define MATRIX_COLS 15
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
#define DIODE_DIRECTION COL2ROW

#define BACKLIGHT_LEVELS 1
#define RGBLED_NUM 16

D keyboards/jc65/v32a/matrix.c => keyboards/jc65/v32a/matrix.c +0 -106
@@ 1,106 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }
}

void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_user();

    return 1;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/jc65/v32a/rules.mk => keyboards/jc65/v32a/rules.mk +0 -4
@@ 22,7 22,3 @@ RGBLIGHT_ENABLE = yes
WS2812_DRIVER = i2c

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c

M keyboards/jc65/v32a/v32a.c => keyboards/jc65/v32a/v32a.c +0 -3
@@ 17,9 17,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "v32a.h"

__attribute__ ((weak))
void matrix_scan_user(void) {}

#ifdef BACKLIGHT_ENABLE
void backlight_init_ports(void) {
	setPinOutput(D0);

M keyboards/jc65/v32a/v32a.h => keyboards/jc65/v32a/v32a.h +14 -16
@@ 27,14 27,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  K01,K30,K11,K21,K31,K41,K51,K46,KE6,KE7,K47,KA1,    KB1,K86,K77, \
  K00,K10,K20,    K40,K56,K50,            K57,KB0,KC0,K96,K76,K66  \
){ \
  {   K00,  K10,  K20,  K30,  K40,  K50,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,  KB0,  KC0,  KD0,KC_NO,KC_NO }, \
  {   K01,  K11,  K21,  K31,  K41,  K51,KC_NO,KC_NO,KC_NO,KC_NO,  KA1,  KB1,KC_NO,KC_NO,KC_NO,KC_NO }, \
  {   K02,  K12,  K22,  K32,  K42,  K52,KC_NO,KC_NO,KC_NO,KC_NO,  KA2,  KB2,  KC2,  KD2,KC_NO,KC_NO }, \
  {   K03,  K13,  K23,  K33,  K43,  K53,KC_NO,KC_NO,KC_NO,KC_NO,  KA3,  KB3,  KC3,  KD3,KC_NO,KC_NO }, \
  {   K04,  K14,  K24,  K34,  K44,  K54,KC_NO,KC_NO,KC_NO,KC_NO,  KA4,  KB4,  KC4,  KD4,  KE4,KC_NO }, \
  { KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO }, \
  { KC_NO,  K16,  K26,  K36,  K46,  K56,  K66,  K76,  K86,  K96,KC_NO,  KB6,  KC6,  KD6,  KE6,KC_NO }, \
  { KC_NO,  K17,  K27,  K37,  K47,  K57,  K67,  K77,  K87,KC_NO,KC_NO,  KB7,  KC7,  KD7,  KE7,KC_NO }  \
  {   K00,  K10,  K20,  K30,  K40,  K50,KC_NO,KC_NO,KC_NO,KC_NO,KC_NO,  KB0,  KC0,  KD0,KC_NO }, \
  {   K01,  K11,  K21,  K31,  K41,  K51,KC_NO,KC_NO,KC_NO,KC_NO,  KA1,  KB1,KC_NO,KC_NO,KC_NO }, \
  {   K02,  K12,  K22,  K32,  K42,  K52,KC_NO,KC_NO,KC_NO,KC_NO,  KA2,  KB2,  KC2,  KD2,KC_NO }, \
  {   K03,  K13,  K23,  K33,  K43,  K53,KC_NO,KC_NO,KC_NO,KC_NO,  KA3,  KB3,  KC3,  KD3,KC_NO }, \
  {   K04,  K14,  K24,  K34,  K44,  K54,KC_NO,KC_NO,KC_NO,KC_NO,  KA4,  KB4,  KC4,  KD4,  KE4 }, \
  { KC_NO,  K16,  K26,  K36,  K46,  K56,  K66,  K76,  K86,  K96,KC_NO,  KB6,  KC6,  KD6,  KE6 }, \
  { KC_NO,  K17,  K27,  K37,  K47,  K57,  K67,  K77,  K87,KC_NO,KC_NO,  KB7,  KC7,  KD7,  KE7 }  \
}

#define LAYOUT_kc( \


@@ 45,14 44,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  K00,K10,K20,    K40,K56,K50,            K57,KB0,KC0,K96,K76,K66  \
) \
{ \
  { KC_##K00,KC_##K10,KC_##K20,KC_##K30,KC_##K40,KC_##K50,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KB0,KC_##KC0,KC_##KD0,   KC_NO,KC_NO }, \
  { KC_##K01,KC_##K11,KC_##K21,KC_##K31,KC_##K41,KC_##K51,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA1,KC_##KB1,   KC_NO,   KC_NO,   KC_NO,KC_NO }, \
  { KC_##K02,KC_##K12,KC_##K22,KC_##K32,KC_##K42,KC_##K52,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA2,KC_##KB2,KC_##KC2,KC_##KD2,   KC_NO,KC_NO }, \
  { KC_##K03,KC_##K13,KC_##K23,KC_##K33,KC_##K43,KC_##K53,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA3,KC_##KB3,KC_##KC3,KC_##KD3,   KC_NO,KC_NO }, \
  { KC_##K04,KC_##K14,KC_##K24,KC_##K34,KC_##K44,KC_##K54,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA4,KC_##KB4,KC_##KC4,KC_##KD4,KC_##KE4,KC_NO }, \
  {    KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_NO }, \
  {    KC_NO,KC_##K16,KC_##K26,KC_##K36,KC_##K46,KC_##K56,KC_##K66,KC_##K76,KC_##K86,KC_##K96,   KC_NO,KC_##KB6,KC_##KC6,KC_##KD6,KC_##KE6,KC_NO }, \
  {    KC_NO,KC_##K17,KC_##K27,KC_##K37,KC_##K47,KC_##K57,KC_##K67,KC_##K77,KC_##K87,   KC_NO,   KC_NO,KC_##KB7,KC_##KC7,KC_##KD7,KC_##KE7,KC_NO }  \
  { KC_##K00,KC_##K10,KC_##K20,KC_##K30,KC_##K40,KC_##K50,   KC_NO,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KB0,KC_##KC0,KC_##KD0,   KC_NO }, \
  { KC_##K01,KC_##K11,KC_##K21,KC_##K31,KC_##K41,KC_##K51,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA1,KC_##KB1,   KC_NO,   KC_NO,   KC_NO }, \
  { KC_##K02,KC_##K12,KC_##K22,KC_##K32,KC_##K42,KC_##K52,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA2,KC_##KB2,KC_##KC2,KC_##KD2,   KC_NO }, \
  { KC_##K03,KC_##K13,KC_##K23,KC_##K33,KC_##K43,KC_##K53,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA3,KC_##KB3,KC_##KC3,KC_##KD3,   KC_NO }, \
  { KC_##K04,KC_##K14,KC_##K24,KC_##K34,KC_##K44,KC_##K54,   KC_NO,   KC_NO,   KC_NO,   KC_NO,KC_##KA4,KC_##KB4,KC_##KC4,KC_##KD4,KC_##KE4 }, \
  {    KC_NO,KC_##K16,KC_##K26,KC_##K36,KC_##K46,KC_##K56,KC_##K66,KC_##K76,KC_##K86,KC_##K96,   KC_NO,KC_##KB6,KC_##KC6,KC_##KD6,KC_##KE6 }, \
  {    KC_NO,KC_##K17,KC_##K27,KC_##K37,KC_##K47,KC_##K57,KC_##K67,KC_##K77,KC_##K87,   KC_NO,   KC_NO,KC_##KB7,KC_##KC7,KC_##KD7,KC_##KE7 }  \
}

#endif

M keyboards/jj40/rules.mk => keyboards/jj40/rules.mk +0 -15
@@ 1,18 1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# MCU name
MCU = atmega32a


M keyboards/jj50/config.h => keyboards/jj50/config.h +5 -3
@@ 32,9 32,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define DESCRIPTION     Preonic-like clone

/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
#define DIODE_DIRECTION ROW2COL
#define MATRIX_ROWS 5
#define MATRIX_COLS 12
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4 }
#define DIODE_DIRECTION COL2ROW

//#define BACKLIGHT_PIN D4
#define BACKLIGHT_LEVELS 12

M keyboards/jj50/jj50.c => keyboards/jj50/jj50.c +0 -10
@@ 20,16 20,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#include "backlight.h"
#include "backlight_custom.h"

void matrix_init_kb(void) { matrix_init_user(); }

__attribute__ ((weak))
void matrix_init_user(void) {}

void matrix_scan_kb(void) { matrix_scan_user(); }

__attribute__ ((weak))
void matrix_scan_user(void) {}

#ifdef BACKLIGHT_ENABLE
void backlight_init_ports(void) {
    b_led_init_ports();

M keyboards/jj50/jj50.h => keyboards/jj50/jj50.h +0 -2
@@ 25,8 25,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#include "keycode.h"
#include "action.h"

void matrix_init_user(void);

#define LAYOUT_ortho_5x12( \
    K011, K010, K009, K008, K004, K005, K006, K007, K003, K002, K201, K000, \
    K111, K110, K109, K108, K104, K105, K106, K107, K103, K102, K001, K100, \

D keyboards/jj50/matrix.c => keyboards/jj50/matrix.c +0 -107
@@ 1,107 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
Modified 2018 by Wayne K Jones <github.com/WarmCatUK>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    //----> DDRD &= ~(1<<PIND7);
    // Port D not used on this keyboard
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    //PORTD |= (1<<PIND7);
    // Port D not used on this keyboard

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }
    matrix_init_quantum();  // missing from original port by Luiz
}

void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }
    matrix_scan_quantum();  // also missing in original PS2AVRGB implementation
    //matrix_scan_user();

    return 1;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/jj50/rules.mk => keyboards/jj50/rules.mk +1 -3
@@ 29,8 29,6 @@ SLEEP_LED_ENABLE = no    # Breathing sleep LED during USB suspend

#OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c backlight.c
SRC = backlight.c

LAYOUTS = ortho_5x12

M keyboards/leeku/finger65/config.h => keyboards/leeku/finger65/config.h +2 -0
@@ 37,6 37,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_ROW_PINS { C3, C4, C5, C6, C7 }
#define UNUSED_PINS

#define DIODE_DIRECTION COL2ROW

/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCE 5


M keyboards/mechmini/v1/config.h => keyboards/mechmini/v1/config.h +5 -2
@@ 30,8 30,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define DESCRIPTION     40% modular keyboard

/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
#define MATRIX_ROWS 4
#define MATRIX_COLS 12
#define MATRIX_ROW_PINS { B0, B1, B2, B3 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4 }
#define DIODE_DIRECTION COL2ROW

#define NO_UART 1


D keyboards/mechmini/v1/matrix.c => keyboards/mechmini/v1/matrix.c +0 -112
@@ 1,112 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_set_row_status(uint8_t row);
uint8_t bit_reverse(uint8_t x);

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }

    matrix_init_quantum();
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();

    return 1;
}

// declarations
void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/mechmini/v1/rules.mk => keyboards/mechmini/v1/rules.mk +0 -4
@@ 22,7 22,3 @@ RGBLIGHT_ENABLE = yes
WS2812_DRIVER = i2c

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c

M keyboards/mechmini/v1/v1.c => keyboards/mechmini/v1/v1.c +0 -10
@@ 16,13 16,3 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "v1.h"

void matrix_init_kb(void) { matrix_init_user(); }

__attribute__ ((weak))
void matrix_init_user(void) {}

void matrix_scan_kb(void) { matrix_scan_user(); }

__attribute__ ((weak))
void matrix_scan_user(void) {}

M keyboards/mechmini/v1/v1.h => keyboards/mechmini/v1/v1.h +8 -16
@@ 30,14 30,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
    K00, K10, K20,      K56, K57, KB0,           KC0, K66  \
) \
{ \
    { K00, K10, K20, K56, KC_NO,    K57,    KC_NO, KC_NO,    KB0, KC0, K66, KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO } \
    { K00, K10, K20, K56, KC_NO, K57, KC_NO, KC_NO, KB0, KC0, K66, KC_NO }, \
    { K01, K11, K21, K31, K41,   K51, K46,   KE6,   KE7, K47, KA1, KC_NO }, \
    { K02, K12, K22, K32, K42,   K52, K36,   KD6,   KD7, K37, KA2, KC_NO }, \
    { K03, K13, K23, K33, K43,   K53, K26,   KC6,   KC7, K27, KA3, KB3   } \
}

#define LAYOUT_split_space( \


@@ 47,14 43,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
    K00, K10, K20,      K56, K57, KB0,           KC0, K66  \
) \
{ \
    { K00, K10, K20, K56, KC_NO,    KC_NO,    K57, KC_NO,    KB0, KC0, K66, KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO } \
    { K00, K10, K20, K56, KC_NO, KC_NO, K57, KC_NO, KB0, KC0, K66, KC_NO }, \
    { K01, K11, K21, K31, K41,   K51,   K46, KE6,   KE7, K47, KA1, KC_NO }, \
    { K02, K12, K22, K32, K42,   K52,   K36, KD6,   KD7, K37, KA2, KC_NO }, \
    { K03, K13, K23, K33, K43,   K53,   K26, KC6,   KC7, K27, KA3, KB3   } \
}

#endif

M keyboards/mehkee96/config.h => keyboards/mehkee96/config.h +3 -0
@@ 12,6 12,9 @@
/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
#define DIODE_DIRECTION COL2ROW

#define RGBLED_NUM 16
#define RGBLIGHT_ANIMATIONS

M keyboards/mehkee96/keymaps/default/keymap.c => keyboards/mehkee96/keymaps/default/keymap.c +0 -10
@@ 68,13 68,3 @@ BL_TOGG, BL_DEC, BL_INC changes the in-switch LEDs
    _______         , _______, _______, BL_DEC,  BL_TOGG, BL_INC,  _______, _______, _______, _______, _______, _______,          _______, _______, _______, _______, _______,
    _______, _______, _______,                            _______,                            _______, _______, _______, _______, _______, _______, _______, _______, _______),
};

void matrix_init_user(void) {
}

void matrix_scan_user(void) {
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
	return true;
}

D keyboards/mehkee96/matrix.c => keyboards/mehkee96/matrix.c +0 -130
@@ 1,130 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_set_row_status(uint8_t row);
uint8_t bit_reverse(uint8_t x);

__attribute__ ((weak))
void matrix_init_kb(void) {
    matrix_init_user();
}

__attribute__ ((weak))
void matrix_scan_kb(void) {
    matrix_scan_user();
}

__attribute__ ((weak))
void matrix_init_user(void) {
}

__attribute__ ((weak))
void matrix_scan_user(void) {
}

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }

    matrix_init_quantum();
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();

    return 1;
}

// declarations
void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/mehkee96/mehkee96.c => keyboards/mehkee96/mehkee96.c +0 -10
@@ 16,13 16,3 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "mehkee96.h"

void matrix_init_kb(void) { matrix_init_user(); }

__attribute__ ((weak))
void matrix_init_user(void) {}

void matrix_scan_kb(void) { matrix_scan_user(); }

__attribute__ ((weak))
void matrix_scan_user(void) {}

M keyboards/mehkee96/rules.mk => keyboards/mehkee96/rules.mk +0 -4
@@ 24,7 24,3 @@ RGBLIGHT_ENABLE = yes
WS2812_DRIVER = i2c

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c

M keyboards/mt40/config.h => keyboards/mt40/config.h +4 -4
@@ 32,7 32,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define DESCRIPTION     A Planck clone

/* key matrix size */
#define MATRIX_ROWS 8
#define MATRIX_ROWS 7
#define MATRIX_COLS 15

#define NO_UART 1


@@ 55,12 55,12 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
/* #define CB6 0x37 // B7 */
/* #define CC7 0x62 // C2 */

#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C2, C3, C4, C5, C6, C7, D7 }
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
/* #define UNUSED_PINS */

/* COL2ROW, ROW2COL*/
/* #define DIODE_DIRECTION COL2ROW */
#define DIODE_DIRECTION COL2ROW

#define BACKLIGHT_PIN D2


D keyboards/mt40/matrix.c => keyboards/mt40/matrix.c +0 -128
@@ 1,128 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"
#include "config.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

__attribute__ ((weak))
void matrix_init_kb(void) {
    matrix_init_user();
}

__attribute__ ((weak))
void matrix_scan_kb(void) {
    matrix_scan_user();
}

__attribute__ ((weak))
void matrix_init_user(void) {
}

__attribute__ ((weak))
void matrix_scan_user(void) {
}



void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }
    matrix_init_kb();
}

void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_kb();

    return 1;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/mt40/mt40.h => keyboards/mt40/mt40.h +0 -1
@@ 34,7 34,6 @@
    { K30,   K11,   K12,   K13,   K14,   K15,   KC_NO, KC_NO, KC_NO, KC_NO, K1A,   K1B,   KC_NO, KC_NO, KC_NO }, \
    { K10,   K01,   K02,   K03,   K04,   K05,   KC_NO, KC_NO, KC_NO, KC_NO, K0A,   KC_NO, KC_NO, KC_NO, KC_NO }, \
    { K00,   KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, K0B   }, \
    { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
    { KC_NO, KC_NO, K06,   K16,   K26,   K35,   K38,   K3A,   K39,   K3B,   KC_NO, KC_NO, K07,   K17,   K27   }, \
    { KC_NO, KC_NO, K09,   K19,   K29,   KC_NO, K2B,   KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, K08,   K18,   K28   }  \
}

M keyboards/mt40/rules.mk => keyboards/mt40/rules.mk +0 -4
@@ 29,9 29,5 @@ TAP_DANCE_ENABLE = no

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c

LAYOUTS = planck_mit
LAYOUTS_HAS_RGB = no

M keyboards/percent/canoe/canoe.c => keyboards/percent/canoe/canoe.c +0 -10
@@ 17,16 17,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "canoe.h"

void matrix_init_kb(void) { matrix_init_user(); }

__attribute__ ((weak))
void matrix_init_user(void) {}

void matrix_scan_kb(void) { matrix_scan_user(); }

__attribute__ ((weak))
void matrix_scan_user(void) {}

#ifdef BACKLIGHT_ENABLE
void backlight_set(uint8_t level) {
	if (level == 0) {

M keyboards/percent/canoe/canoe.h => keyboards/percent/canoe/canoe.h +2 -8
@@ 32,10 32,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E }, \
  { _x_, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E }, \
  { K30, _x_, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E }, \
  { K40, _x_, K42, K43, K44, _x_, _x_, _x_, K48, _x_, K4A, K4B, K4C, K4D, K4E }, \
  { _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_ }, \
  { _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_ }, \
  { _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_ }  \
  { K40, _x_, K42, K43, K44, _x_, _x_, _x_, K48, _x_, K4A, K4B, K4C, K4D, K4E }  \
}

#define LAYOUT_65_ansi_blocker( \


@@ 49,10 46,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  { K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E }, \
  { _x_, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E }, \
  { K30, _x_, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E }, \
  { K40, _x_, K42, K43, K44, _x_, _x_, _x_, K48, _x_, _x_, K4B, K4C, K4D, K4E }, \
  { _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_ }, \
  { _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_ }, \
  { _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_, _x_ }  \
  { K40, _x_, K42, K43, K44, _x_, _x_, _x_, K48, _x_, _x_, K4B, K4C, K4D, K4E }  \
}

#define LAYOUT LAYOUT_65_ansi_blocker // added to not break existing checked in keymaps

M keyboards/percent/canoe/config.h => keyboards/percent/canoe/config.h +3 -3
@@ 28,11 28,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.

#define RGBLED_NUM 2

#define MATRIX_ROWS 8
#define MATRIX_ROWS 5
#define MATRIX_COLS 15

#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, C1 }
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
#define UNUSED_PINS

#define DIODE_DIRECTION COL2ROW

D keyboards/percent/canoe/matrix.c => keyboards/percent/canoe/matrix.c +0 -112
@@ 1,112 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_set_row_status(uint8_t row);
uint8_t bit_reverse(uint8_t x);

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }

    matrix_init_quantum();
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();

    return 1;
}

// declarations
void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/percent/canoe/rules.mk => keyboards/percent/canoe/rules.mk +0 -4
@@ 23,8 23,4 @@ WS2812_DRIVER = i2c

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c

LAYOUTS = 65_ansi_blocker 65_iso_blocker

M keyboards/percent/skog/config.h => keyboards/percent/skog/config.h +5 -1
@@ 26,9 26,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT         Skog TKL

/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_ROWS 7
#define MATRIX_COLS 14

#define MATRIX_ROW_PINS { B0, B1, B2, B3, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2 }
#define DIODE_DIRECTION COL2ROW

#define RGBLED_NUM 2
#define RGBLIGHT_ANIMATIONS


M keyboards/percent/skog/keymaps/default/keymap.c => keyboards/percent/skog/keymaps/default/keymap.c +0 -8
@@ 27,11 27,3 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
      KC_LCTL, KC_LGUI, KC_LALT,                   KC_SPC,                                      KC_RALT,  KC_RGUI,    KC_MENU,    KC_RCTL,                 KC_LEFT, KC_DOWN, KC_RGHT
    )
};

void matrix_init_user(void) {

}

void matrix_scan_user(void) {

}

D keyboards/percent/skog/matrix.c => keyboards/percent/skog/matrix.c +0 -112
@@ 1,112 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_set_row_status(uint8_t row);
uint8_t bit_reverse(uint8_t x);

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }

    matrix_init_quantum();
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();

    return 1;
}

// declarations
void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/percent/skog/skog.c => keyboards/percent/skog/skog.c +0 -10
@@ 22,16 22,6 @@ ps2avrGB support code by Kenneth A. (bminiex/.[ch])
#include "backlight.h"
#include "backlight_custom.h"

void matrix_init_kb(void) { matrix_init_user(); }

__attribute__ ((weak))
void matrix_init_user(void) {}

void matrix_scan_kb(void) { matrix_scan_user(); }

__attribute__ ((weak))
void matrix_scan_user(void) {}

#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
void backlight_init_ports(void) {

M keyboards/percent/skog/skog.h => keyboards/percent/skog/skog.h +0 -1
@@ 32,7 32,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  { K01,   K11,   K21,   K31,   K41,   K51,   K61,   KC_NO, K81,   K91,   KA1,   KB1,   KC1,   KD1   }, \
  { K02,   K12,   K22,   K32,   K42,   K52,   K62,   K72,   K82,   K92,   KA2,   KB2,   KC2,   KD2   }, \
  { K03,   K13,   K23,   K33,   K43,   K53,   K63,   K73,   K83,   K93,   KA3,   KB3,   KC3,   KD3   }, \
  { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
  { K05,   K15,   K25,   K35,   K45,   K55,   K65,   K75,   K85,   K95,   KA5,   KB5,   KC5,   KC_NO }, \
  { K06,   K16,   K26,   K36,   K46,   K56,   K66,   K76,   K86,   K96,   KA6,   KB6,   KC6,   KD6   }, \
  { K07,   K17,   K27,   K37,   KC_NO, K57,   KC_NO, KC_NO, K87,   K97,   KA7,   KB7,   KC7,   KD7   }  \

M keyboards/winkeyless/bface/config.h => keyboards/winkeyless/bface/config.h +2 -0
@@ 35,6 35,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7}
#define UNUSED_PINS

#define DIODE_DIRECTION COL2ROW

#define RGBLED_NUM 16
#define RGBLIGHT_ANIMATIONS


M keyboards/winkeyless/bmini/bmini.c => keyboards/winkeyless/bmini/bmini.c +0 -3
@@ 16,6 16,3 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "bmini.h"

__attribute__ ((weak))
void matrix_scan_user(void) {}

M keyboards/winkeyless/bmini/config.h => keyboards/winkeyless/bmini/config.h +3 -0
@@ 31,6 31,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
#define DIODE_DIRECTION COL2ROW

#define RGBLIGHT_ANIMATIONS


D keyboards/winkeyless/bmini/matrix.c => keyboards/winkeyless/bmini/matrix.c +0 -106
@@ 1,106 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }
}

void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_user();

    return 1;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/winkeyless/bmini/rules.mk => keyboards/winkeyless/bmini/rules.mk +0 -4
@@ 22,7 22,3 @@ RGBLIGHT_ENABLE = yes
WS2812_DRIVER = i2c

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c

M keyboards/winkeyless/bminiex/config.h => keyboards/winkeyless/bminiex/config.h +3 -0
@@ 30,6 30,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
#define DIODE_DIRECTION COL2ROW

#define RGBLIGHT_ANIMATIONS


D keyboards/winkeyless/bminiex/matrix.c => keyboards/winkeyless/bminiex/matrix.c +0 -122
@@ 1,122 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"
#include "backlight.h"

#ifndef DEBOUNCE
#define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

__attribute__ ((weak))
void matrix_init_user(void) {}
__attribute__ ((weak))
void matrix_scan_user(void) {}
__attribute__ ((weak))
void matrix_init_kb(void) {
  matrix_init_user();
}
__attribute__ ((weak))
void matrix_scan_kb(void) {
  matrix_scan_user();
}

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }
    
    matrix_init_quantum();
}

void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();

    return 1;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/winkeyless/bminiex/rules.mk => keyboards/winkeyless/bminiex/rules.mk +1 -3
@@ 29,6 29,4 @@ SLEEP_LED_ENABLE = no    # Breathing sleep LED during USB suspend

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c backlight.c
SRC += backlight.c

M keyboards/ymd75/config.h => keyboards/ymd75/config.h +3 -1
@@ 35,7 35,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
#define DIODE_DIRECTION ROW2COL
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }
#define DIODE_DIRECTION COL2ROW

#define BACKLIGHT_LEVELS 12


D keyboards/ymd75/matrix.c => keyboards/ymd75/matrix.c +0 -108
@@ 1,108 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
Modified 2018 by Wayne K Jones <github.com/WarmCatUK>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }
    matrix_init_quantum();  // missing from original port by Luiz
}

void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
                  // col 14, PORTD 7
                  ((~PIND) & (1 << PIND7)) << 7
                  );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }
    matrix_scan_quantum();  // also missing in original PS2AVRGB implementation
    //matrix_scan_user();

    return 1;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/ymd75/rules.mk => keyboards/ymd75/rules.mk +1 -3
@@ 33,6 33,4 @@ SLEEP_LED_ENABLE = no    # Breathing sleep LED during USB suspend

#OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c backlight.c
SRC = backlight.c

M keyboards/ymd75/ymd75.c => keyboards/ymd75/ymd75.c +0 -10
@@ 20,16 20,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#include "backlight.h"
#include "backlight_custom.h"

void matrix_init_kb(void) { matrix_init_user(); }

__attribute__ ((weak))
void matrix_init_user(void) {}

void matrix_scan_kb(void) { matrix_scan_user(); }

__attribute__ ((weak))
void matrix_scan_user(void) {}

#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
void backlight_init_ports(void) {

M keyboards/ymd75/ymd75.h => keyboards/ymd75/ymd75.h +0 -2
@@ 25,8 25,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#include "keycode.h"
#include "action.h"

void matrix_init_user(void);

#define LAYOUT( \
K05, K25, K35, K45, K55, K06, KA6, KA7, K07, KB5, KC5, KD5, KE5, KD1, KE1, KE2, \
K04, K14, K24, K34, K44, K54, K16, KB6, KB7, K17, KA4, KB4, KC4, KE4,      KD0, \

M keyboards/ymd96/config.h => keyboards/ymd96/config.h +2 -1
@@ 31,7 31,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
//#define DIODE_DIRECTION ROW2COL
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7 }

//#define RGB_DI_PIN C4
/* COL2ROW or ROW2COL */

D keyboards/ymd96/matrix.c => keyboards/ymd96/matrix.c +0 -112
@@ 1,112 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_set_row_status(uint8_t row);
uint8_t bit_reverse(uint8_t x);

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }

    matrix_init_quantum();  // missing from original port by Luiz
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();  // also missing in original PS2AVRGB implementation

    return 1;
}

// declarations
void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/ymd96/rules.mk => keyboards/ymd96/rules.mk +1 -3
@@ 31,6 31,4 @@ SLEEP_LED_ENABLE = no    # Breathing sleep LED during USB suspend

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c backlight.c
SRC = backlight.c

M keyboards/ymd96/ymd96.c => keyboards/ymd96/ymd96.c +0 -10
@@ 21,16 21,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#include "backlight.h"
#include "backlight_custom.h"

void matrix_init_kb(void) { matrix_init_user(); }

__attribute__ ((weak))
void matrix_init_user(void) {}

void matrix_scan_kb(void) { matrix_scan_user(); }

__attribute__ ((weak))
void matrix_scan_user(void) {}

#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
void backlight_init_ports(void) {

M keyboards/ymd96/ymd96.h => keyboards/ymd96/ymd96.h +0 -2
@@ 20,8 20,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "quantum.h"

void matrix_init_user(void);  // TODO port this to other PS2AVRGB boards

#define LAYOUT_default( \
    K50, K52, K53, K54, K55, K60, K6A, K7A, K70, K5B, K5C, K5D, K5E, K1D, K2E,   K0D, K76, K79, K78, \
    K40, K41, K42, K43, K44, K45, K61, K6B, K7B, K71, K4A, K4B, K4C,      K4E,   K46, K47, K48, K49, \

M keyboards/ymdk/bface/config.h => keyboards/ymdk/bface/config.h +2 -0
@@ 34,6 34,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7}
#define UNUSED_PINS

#define DIODE_DIRECTION COL2ROW

#define NO_UART 1

#define BACKLIGHT_PIN       D4

M keyboards/ymdk/bface/rules.mk => keyboards/ymdk/bface/rules.mk +0 -15
@@ 1,18 1,3 @@
# Copyright 2019 Ethan Durrant (emdarcher)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# MCU name
MCU = atmega32a


M keyboards/ymdk_np21/config.h => keyboards/ymdk_np21/config.h +4 -2
@@ 29,8 29,10 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT         np21

/* matrix size */
#define MATRIX_ROWS 8
#define MATRIX_COLS 15
#define MATRIX_ROWS 4
#define MATRIX_COLS 6
#define MATRIX_ROW_PINS { B0, B1, B2, B3 }
#define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5 }

/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW

D keyboards/ymdk_np21/matrix.c => keyboards/ymdk_np21/matrix.c +0 -129
@@ 1,129 0,0 @@
/*
Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <avr/io.h>
#include <util/delay.h>

#include "matrix.h"

#ifndef DEBOUNCE
#   define DEBOUNCE	5
#endif

static uint8_t debouncing = DEBOUNCE;

static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

void matrix_set_row_status(uint8_t row);
uint8_t bit_reverse(uint8_t x);

void matrix_init(void) {
    // all outputs for rows high
    DDRB = 0xFF;
    PORTB = 0xFF;
    // all inputs for columns
    DDRA = 0x00;
    DDRC &= ~(0x111111<<2);
    DDRD &= ~(1<<PIND7);
    // all columns are pulled-up
    PORTA = 0xFF;
    PORTC |= (0b111111<<2);
    PORTD |= (1<<PIND7);

    // initialize matrix state: all keys off
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix[row] = 0x00;
        matrix_debouncing[row] = 0x00;
    }

    matrix_init_quantum();  // missing from original port by Luiz
}

uint8_t matrix_scan(void) {
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        matrix_set_row_status(row);
        _delay_us(5);

        matrix_row_t cols = (
            // cols 0..7, PORTA 0 -> 7
            (~PINA) & 0xFF
        ) | (
            // cols 8..13, PORTC 7 -> 0
            bit_reverse((~PINC) & 0xFF) << 8
        ) | (
            // col 14, PORTD 7
            ((~PIND) & (1 << PIND7)) << 7
        );

        if (matrix_debouncing[row] != cols) {
            matrix_debouncing[row] = cols;
            debouncing = DEBOUNCE;
        }
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();  // also missing in original PS2AVRGB implementation

    return 1;
}

__attribute__ ((weak))
void matrix_scan_user(void) {};

__attribute__ ((weak))
void matrix_scan_kb(void) {
  // Looping keyboard code goes here
  // This runs every cycle (a lot)
  matrix_scan_user();
};

__attribute__ ((weak))
void matrix_init_user(void) {};

__attribute__ ((weak))
void matrix_init_kb(void) {
  matrix_init_user();
}
// declarations
void matrix_set_row_status(uint8_t row) {
    DDRB = (1 << row);
    PORTB = ~(1 << row);
}

uint8_t bit_reverse(uint8_t x) {
    x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
    x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
    x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
    return x;
}

inline matrix_row_t matrix_get_row(uint8_t row) {
    return matrix[row];
}

void matrix_print(void) {
}

M keyboards/ymdk_np21/rules.mk => keyboards/ymdk_np21/rules.mk +1 -3
@@ 31,6 31,4 @@ SLEEP_LED_ENABLE = no    # Breathing sleep LED during USB suspend

OPT_DEFS = -DDEBUG_LEVEL=0

# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c backlight.c
SRC = backlight.c

M keyboards/ymdk_np21/ymdk_np21.h => keyboards/ymdk_np21/ymdk_np21.h +0 -2
@@ 23,8 23,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
#include "keycode.h"
#include "action.h"

void matrix_init_user(void);  // TODO port this to other PS2AVRGB boards

#define LAYOUT( \
    K01, K02, K03, K04, K05, K06, \
    K11, K12, K13, K14, K15, K16, \