mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-12 18:28:50 +01:00
add PULLUP for keyboard
This commit is contained in:
parent
03cf255599
commit
191626d736
@ -34,5 +34,6 @@ class DEVTERM {
|
||||
//USBSerial *_Serial;//_Serial = &Serial;
|
||||
};
|
||||
|
||||
#define KEYBOARD_PULL 1 // 1 for PULLUP, 0 FOR PULLDOWN
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
|
||||
uint8_t read_io(uint8_t io) {
|
||||
|
||||
if(digitalRead(io) == LOW ){
|
||||
return 0;
|
||||
}else {
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
#define MATRIX_KEYS 64 // 8*8
|
||||
|
||||
#ifndef DEBOUNCE
|
||||
# define DEBOUNCE 5
|
||||
# define DEBOUNCE 20
|
||||
#endif
|
||||
|
||||
void init_rows();
|
||||
|
||||
@ -11,13 +11,37 @@ static uint8_t matrix[MATRIX_ROWS];
|
||||
static uint8_t matrix_debouncing[MATRIX_COLS];
|
||||
static uint8_t matrix_prev[MATRIX_ROWS];
|
||||
|
||||
uint8_t read_kbd_io(uint8_t io) {
|
||||
|
||||
#if defined KEYBOARD_PULL && KEYBOARD_PULL == 0
|
||||
if(digitalRead(io) == LOW ){
|
||||
return 0;
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
#elif defined KEYBOARD_PULL && KEYBOARD_PULL == 1
|
||||
if(digitalRead(io) == LOW ){
|
||||
return 1;
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void init_rows(){
|
||||
int i;
|
||||
for(i=0;i<8;i++) {
|
||||
|
||||
#if defined KEYBOARD_PULL && KEYBOARD_PULL == 0
|
||||
pinMode(matrix_rows[i],OUTPUT);
|
||||
digitalWrite(matrix_rows[i],LOW);
|
||||
|
||||
pinMode(matrix_rows[i],INPUT_PULLDOWN);
|
||||
|
||||
#elif defined KEYBOARD_PULL && KEYBOARD_PULL == 1
|
||||
pinMode(matrix_rows[i],INPUT_PULLUP);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,23 +75,33 @@ uint8_t matrix_scan(void) {
|
||||
uint8_t data;
|
||||
for(int col = 0; col < MATRIX_COLS;col++){
|
||||
data = 0;
|
||||
|
||||
#if defined KEYBOARD_PULL && KEYBOARD_PULL == 1
|
||||
|
||||
digitalWrite(matrix_cols[col],LOW);
|
||||
#elif defined KEYBOARD_PULL && KEYBOARD_PULL == 0
|
||||
digitalWrite(matrix_cols[col],HIGH);
|
||||
|
||||
|
||||
#endif
|
||||
delayMicroseconds(30);
|
||||
|
||||
data =(
|
||||
( read_io(matrix_rows[0]) << 0 ) |
|
||||
( read_io(matrix_rows[1]) << 1 ) |
|
||||
( read_io(matrix_rows[2]) << 2 ) |
|
||||
( read_io(matrix_rows[3]) << 3 ) |
|
||||
( read_io(matrix_rows[4]) << 4 ) |
|
||||
( read_io(matrix_rows[5]) << 5 ) |
|
||||
( read_io(matrix_rows[6]) << 6 ) |
|
||||
( read_io(matrix_rows[7]) << 7 )
|
||||
( read_kbd_io(matrix_rows[0]) << 0 ) |
|
||||
( read_kbd_io(matrix_rows[1]) << 1 ) |
|
||||
( read_kbd_io(matrix_rows[2]) << 2 ) |
|
||||
( read_kbd_io(matrix_rows[3]) << 3 ) |
|
||||
( read_kbd_io(matrix_rows[4]) << 4 ) |
|
||||
( read_kbd_io(matrix_rows[5]) << 5 ) |
|
||||
( read_kbd_io(matrix_rows[6]) << 6 ) |
|
||||
( read_kbd_io(matrix_rows[7]) << 7 )
|
||||
);
|
||||
|
||||
#if defined KEYBOARD_PULL && KEYBOARD_PULL == 1
|
||||
digitalWrite(matrix_cols[col],HIGH);
|
||||
#elif defined KEYBOARD_PULL && KEYBOARD_PULL == 0
|
||||
digitalWrite(matrix_cols[col],LOW);
|
||||
#endif
|
||||
|
||||
if (matrix_debouncing[col] != data) {
|
||||
matrix_debouncing[col] = data;
|
||||
keyboard_debouncing.deing = true;
|
||||
|
||||
@ -12,7 +12,9 @@ static uint16_t keys_prev;
|
||||
void init_keys(){
|
||||
int i;
|
||||
for(i=0;i<KEYS_NUM;i++) {
|
||||
|
||||
pinMode( keys_io[i],INPUT_PULLUP);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,12 +26,11 @@ uint8_t scan_keys(){
|
||||
delayMicroseconds(30);
|
||||
for(int i = 0;i < KEYS_NUM;i++) {
|
||||
|
||||
s = digitalRead(keys_io[i]); //HIGH =0,LOW = 1
|
||||
if( s == LOW ){
|
||||
data |= 1 << i;
|
||||
}else {
|
||||
data |= 0 << i;
|
||||
}
|
||||
s = read_io(keys_io[i]);
|
||||
s ^= 1;
|
||||
|
||||
data |= s << i;
|
||||
|
||||
}
|
||||
|
||||
if ( keys_debouncing != data ) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user