From d5ac54449ad7726e4d392d14551f3559cc63afbf Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 5 Apr 2015 14:41:14 +0900 Subject: Add alps64 --- keyboard/alps64/matrix.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 keyboard/alps64/matrix.c (limited to 'keyboard/alps64/matrix.c') diff --git a/keyboard/alps64/matrix.c b/keyboard/alps64/matrix.c new file mode 100644 index 0000000000..a49755c3a3 --- /dev/null +++ b/keyboard/alps64/matrix.c @@ -0,0 +1,190 @@ +/* +Copyright 2012 Jun Wako + +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 . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" + + +#ifndef DEBOUNCE +# define DEBOUNCE 5 +#endif +static uint8_t debouncing = DEBOUNCE; + +/* matrix state(1:on, 0:off) */ +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +static matrix_row_t read_cols(void); +static void init_cols(void); +static void unselect_rows(void); +static void select_row(uint8_t row); + + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + // initialize row and col + unselect_rows(); + init_cols(); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + matrix_debouncing[i] = 0; + } +} + +uint8_t matrix_scan(void) +{ + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + select_row(i); + _delay_us(30); // without this wait read unstable value. + matrix_row_t cols = read_cols(); + if (matrix_debouncing[i] != cols) { + matrix_debouncing[i] = cols; + if (debouncing) { + debug("bounce!: "); debug_hex(debouncing); debug("\n"); + } + debouncing = DEBOUNCE; + } + unselect_rows(); + } + + if (debouncing) { + if (--debouncing) { + _delay_ms(1); + } else { + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + matrix[i] = matrix_debouncing[i]; + } + } + } + + return 1; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1< Date: Fri, 26 Jun 2015 08:49:03 +0900 Subject: alps64: Change keymaps and USB descriptors. --- keyboard/alps64/matrix.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'keyboard/alps64/matrix.c') diff --git a/keyboard/alps64/matrix.c b/keyboard/alps64/matrix.c index a49755c3a3..aa991e0aec 100644 --- a/keyboard/alps64/matrix.c +++ b/keyboard/alps64/matrix.c @@ -55,6 +55,10 @@ uint8_t matrix_cols(void) return MATRIX_COLS; } +#define LED_ON() do { DDRC |= (1<<5); PORTC |= (1<<5); } while (0) +#define LED_OFF() do { DDRC &= ~(1<<5); PORTC &= ~(1<<5); } while (0) +#define LED_TGL() do { DDRC |= (1<<5); PINC |= (1<<5); } while (0) + void matrix_init(void) { // initialize row and col @@ -66,6 +70,12 @@ void matrix_init(void) matrix[i] = 0; matrix_debouncing[i] = 0; } + + //debug + debug_matrix = true; + LED_ON(); + _delay_ms(500); + LED_OFF(); } uint8_t matrix_scan(void) -- cgit v1.2.3 From 6fe4af82fa21cbeb8e22c9f0630e5a908963cc13 Mon Sep 17 00:00:00 2001 From: tmk Date: Thu, 15 Oct 2015 11:48:14 +0900 Subject: Fix port setting of alps64/matrix.c --- keyboard/alps64/matrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'keyboard/alps64/matrix.c') diff --git a/keyboard/alps64/matrix.c b/keyboard/alps64/matrix.c index aa991e0aec..5638d7f69d 100644 --- a/keyboard/alps64/matrix.c +++ b/keyboard/alps64/matrix.c @@ -157,7 +157,7 @@ static void unselect_rows(void) DDRD &= ~0b01111111; PORTD &= ~0b01111111; DDRC &= ~0b00000100; - PORTD &= ~0b00000100; + PORTC &= ~0b00000100; } static void select_row(uint8_t row) -- cgit v1.2.3