Added proper debouncing

master
Fabian Felix Selbach 2 years ago
parent eb0cc181e6
commit f2c3c778a7
  1. 3
      Readme.md
  2. 17
      kbdrv-main.c

@ -7,6 +7,7 @@ A keyboard software meant to run on a Milk-V duo.
- [x] (partial) LED support
- [x] N-Key rollover (The currently included hid descriptor "only" supports 80 key rollover but adapting to more keys would be fairly trivial)
- [x] Multiple bindings per key
- [x] Debouncing (immediate on, 5ms until key turns off)
### Todo
- [ ] RGB
- [ ] Layer support
@ -17,7 +18,7 @@ This file contains all the program code required to scan the keyboard matrix as
### keyboard\_mapping.h
This file contains all the configuration and mapping of the device you are working with. This includes the GPIO pin mapping to rows/columns, matrix to binding
identifier and binding identifier to hid-modifiers/hid-usage codes. Currently there is no support for binding multiple actions to one key.
identifier and binding identifier to hid-modifiers/hid-usage codes.
## Important notes

@ -10,7 +10,7 @@
#include <wiringx.h>
bool state[sizeof(columns)/sizeof(int)][sizeof(rows)/sizeof(int)];
bool state[sizeof(columns)/sizeof(int)][sizeof(rows)/sizeof(int)][5];
#define BUF_LEN 512
int main() {
@ -56,7 +56,8 @@ int main() {
perror(filename);
return 3;
}
int dbIndex = 4; //db = debounce! -> debounceIndex
while(true){
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
@ -85,9 +86,11 @@ int main() {
for(int c = 0; c < sizeof(columns)/sizeof(int); c++){
digitalWrite(columns[c], LOW);
for(int r = 0; r < sizeof(rows)/sizeof(int); r++){
char curState = state[c][r];
state[c][r] = (digitalRead(rows[r]) == LOW);
if((state[c][r] == true || curState == true)){
bool curState = state[c][r][(dbIndex+1)%5];
state[c][r][dbIndex] = (digitalRead(rows[r]) == LOW);
if((state[c][r][dbIndex] == true || state[c][r][(dbIndex+1)%5] == true || state[c][r][(dbIndex+2)%5] == true
|| state[c][r][(dbIndex+3)%5] == true || state[c][r][(dbIndex+4)%5] == true)){
char bind[sizeof(mapping[c][r])/sizeof(char)];
strcpy(bind, mapping[c][r]);
char *binding = strtok(bind, " ");
@ -106,10 +109,12 @@ int main() {
}
}
}
//if(state[c][r] != curState) printf("statechange to %s column %d, row %d\n", (state[c][r] ? "HIGH" : "LOW"), c, r);
//if(state[c][r][dbIndex] != curState) printf("statechange to %s column %d, row %d\n", (state[c][r] ? "HIGH" : "LOW"), c, r);
}
digitalWrite(columns[c], HIGH);
}
dbIndex--;
if(dbIndex > 0) dbIndex = 4;
write(fd, report, 82);//Send Report over USB
usleep(700);
}

Loading…
Cancel
Save