Adds wait to i2c (debounce)

This commit is contained in:
Jack Humbert 2016-07-04 12:13:41 -04:00 committed by Erez Zukerman
parent eafaba6b53
commit 86a7b060ef

View File

@ -27,7 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h> #include "wait.h"
#include "action_layer.h" #include "action_layer.h"
#include "print.h" #include "print.h"
#include "debug.h" #include "debug.h"
@ -166,6 +166,7 @@ uint8_t matrix_scan(void)
for (uint8_t i = 0; i < MATRIX_ROWS; i++) { for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
select_row(i); select_row(i);
wait_us(30); // without this wait read unstable value.
matrix_row_t cols = read_cols(i); matrix_row_t cols = read_cols(i);
if (matrix_debouncing[i] != cols) { if (matrix_debouncing[i] != cols) {
matrix_debouncing[i] = cols; matrix_debouncing[i] = cols;
@ -179,7 +180,7 @@ uint8_t matrix_scan(void)
if (debouncing) { if (debouncing) {
if (--debouncing) { if (--debouncing) {
_delay_ms(2); wait_us(1);
} else { } else {
for (uint8_t i = 0; i < MATRIX_ROWS; i++) { for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
matrix[i] = matrix_debouncing[i]; matrix[i] = matrix_debouncing[i];
@ -267,7 +268,6 @@ static matrix_row_t read_cols(uint8_t row)
return data; return data;
} }
} else { } else {
_delay_us(30); // without this wait read unstable value.
// read from teensy // read from teensy
return return
(PINF&(1<<0) ? 0 : (1<<0)) | (PINF&(1<<0) ? 0 : (1<<0)) |