summaryrefslogtreecommitdiffstats
path: root/quantum/matrix.c
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-06-24 04:18:20 +0200
committerGitHub <noreply@github.com>2016-06-24 04:18:20 +0200
commit13bb6b4b7fdd2b3e419d0f89c93fb980b00eeb9b (patch)
tree2777e5c95bad3f5a9773fc58524a6ad99df63738 /quantum/matrix.c
parentba116ceb496011bb35ce074a3ba8c2448f059260 (diff)
downloadqmk_firmware-13bb6b4b7fdd2b3e419d0f89c93fb980b00eeb9b.tar.gz
qmk_firmware-13bb6b4b7fdd2b3e419d0f89c93fb980b00eeb9b.tar.xz
Backlight abstraction and other changes (#439)
* redoes matrix pins, abstracts backlight code for B5,6,7 * slimming down keyboard stuff, backlight breathing implemented * don't call backlight init when no pin * cleans up user/kb/quantum calls, keyboard files * fix pvc atomic * replaces CHANNEL with correct var in breathing * removes .hexs, updates readmes, updates template * cleans-up clueboards, readmes to lowercase * updates readme
Diffstat (limited to 'quantum/matrix.c')
-rw-r--r--quantum/matrix.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c
index 4f1564ac8..6e9f92727 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -32,8 +32,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define DEBOUNCING_DELAY 5
#endif
-static const io_pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
-static const io_pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
+static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
+static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
/* matrix state */
#if DIODE_DIRECTION == COL2ROW
static matrix_row_t matrix[MATRIX_ROWS];
@@ -52,10 +52,30 @@ static matrix_col_t read_rows(void);
__attribute__ ((weak))
void matrix_init_quantum(void) {
+ matrix_init_kb();
}
__attribute__ ((weak))
void matrix_scan_quantum(void) {
+ matrix_scan_kb();
+}
+
+__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) {
}
uint8_t matrix_rows(void) {
@@ -70,22 +90,22 @@ void matrix_power_up(void) {
#if DIODE_DIRECTION == COL2ROW
for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
/* DDRxn */
- _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit);
+ _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF);
toggle_row(r);
}
for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
/* PORTxn */
- _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit);
+ _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF);
}
#else
for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
/* DDRxn */
- _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit);
+ _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF);
toggle_col(c);
}
for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
/* PORTxn */
- _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit);
+ _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF);
}
#endif
}
@@ -100,22 +120,22 @@ void matrix_init(void) {
#if DIODE_DIRECTION == COL2ROW
for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
/* DDRxn */
- _SFR_IO8(row_pins[r].input_addr + 1) |= _BV(row_pins[r].bit);
+ _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF);
toggle_row(r);
}
for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
/* PORTxn */
- _SFR_IO8(col_pins[c].input_addr + 2) |= _BV(col_pins[c].bit);
+ _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF);
}
#else
for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
/* DDRxn */
- _SFR_IO8(col_pins[c].input_addr + 1) |= _BV(col_pins[c].bit);
+ _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF);
toggle_col(c);
}
for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
/* PORTxn */
- _SFR_IO8(row_pins[r].input_addr + 2) |= _BV(row_pins[r].bit);
+ _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF);
}
#endif
matrix_init_quantum();
@@ -151,14 +171,14 @@ uint8_t matrix_scan(void) {
static void toggle_row(uint8_t row) {
/* PINxn */
- _SFR_IO8(row_pins[row].input_addr) = _BV(row_pins[row].bit);
+ _SFR_IO8((row_pins[row] >> 4)) = _BV(row_pins[row] & 0xF);
}
static matrix_row_t read_cols(void) {
matrix_row_t state = 0;
for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
/* PINxn */
- if (!(_SFR_IO8(col_pins[c].input_addr) & _BV(col_pins[c].bit))) {
+ if (!(_SFR_IO8((col_pins[c] >> 4)) & _BV(col_pins[c] & 0xF))) {
state |= (matrix_row_t)1 << c;
}
}
@@ -199,14 +219,14 @@ uint8_t matrix_scan(void) {
static void toggle_col(uint8_t col) {
/* PINxn */
- _SFR_IO8(col_pins[col].input_addr) = _BV(col_pins[col].bit);
+ _SFR_IO8((col_pins[col] >> 4)) = _BV(col_pins[col] & 0xF);
}
static matrix_col_t read_rows(void) {
matrix_col_t state = 0;
for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
/* PINxn */
- if (!(_SFR_IO8(row_pins[r].input_addr) & _BV(row_pins[r].bit))) {
+ if (!(_SFR_IO8((row_pins[r] >> 4)) & _BV(row_pins[r] & 0xF))) {
state |= (matrix_col_t)1 << r;
}
}