From 98f486a633611764d5928fd52187155aabb33d63 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 12 Jan 2015 12:39:24 -0500 Subject: atomic --- keyboard/atomic/matrix.c | 230 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 keyboard/atomic/matrix.c (limited to 'keyboard/atomic/matrix.c') diff --git a/keyboard/atomic/matrix.c b/keyboard/atomic/matrix.c new file mode 100644 index 000000000..435e08952 --- /dev/null +++ b/keyboard/atomic/matrix.c @@ -0,0 +1,230 @@ +/* +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 "action_layer.h" +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" + + +#ifndef DEBOUNCE +# define DEBOUNCE 10 +#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; +} + +static +void setup_leds(void) { + DDRF |= 0x00; + PORTF |= 0x00; +} + + +void matrix_init(void) +{ + // initialize row and col + unselect_rows(); + init_cols(); + + setup_leds(); + + // 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]; + } + } + } + + // uint8_t layer = biton32(default_layer_state); + switch (default_layer_state) { + case 1: + DDRF &= ~(1<<0); + PORTF &= ~(1<<0); + break; + case 2: + DDRF |= (1<<0); + PORTF |= (1<<0); + break; + } + + return 1; +} + +bool matrix_is_modified(void) +{ + if (debouncing) return false; + return true; +} + +inline +bool matrix_is_on(uint8_t row, uint8_t col) +{ + return (matrix[row] & ((matrix_row_t)1< Date: Tue, 13 Jan 2015 18:05:37 -0500 Subject: sean --- keyboard/atomic/matrix.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'keyboard/atomic/matrix.c') diff --git a/keyboard/atomic/matrix.c b/keyboard/atomic/matrix.c index 435e08952..86803c9ed 100644 --- a/keyboard/atomic/matrix.c +++ b/keyboard/atomic/matrix.c @@ -104,17 +104,6 @@ uint8_t matrix_scan(void) } } - // uint8_t layer = biton32(default_layer_state); - switch (default_layer_state) { - case 1: - DDRF &= ~(1<<0); - PORTF &= ~(1<<0); - break; - case 2: - DDRF |= (1<<0); - PORTF |= (1<<0); - break; - } return 1; } -- cgit v1.2.3 From a538f71e41ad5c594250594b053f05e550667ebc Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Mon, 23 Feb 2015 23:44:11 -0500 Subject: led oops --- keyboard/atomic/matrix.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'keyboard/atomic/matrix.c') diff --git a/keyboard/atomic/matrix.c b/keyboard/atomic/matrix.c index 86803c9ed..98102cb69 100644 --- a/keyboard/atomic/matrix.c +++ b/keyboard/atomic/matrix.c @@ -56,12 +56,6 @@ uint8_t matrix_cols(void) return MATRIX_COLS; } -static -void setup_leds(void) { - DDRF |= 0x00; - PORTF |= 0x00; -} - void matrix_init(void) { @@ -69,8 +63,6 @@ void matrix_init(void) unselect_rows(); init_cols(); - setup_leds(); - // initialize matrix state: all keys off for (uint8_t i=0; i < MATRIX_ROWS; i++) { matrix[i] = 0; -- cgit v1.2.3