/ src / hal / components / sim_matrix_kb.comp
sim_matrix_kb.comp
 1  component sim_matrix_kb "convert HAL pin inputs to keycodes";
 2  
 3  pin out u32 out "pin that outputs the Keycode";
 4  
 5  pin in bit button.c00.r##[8] "array of  inputs";
 6  pin in bit button.c01.r##[8] "array of  inputs";
 7  pin in bit button.c02.r##[8] "array of  inputs";
 8  pin in bit button.c03.r##[8] "array of  inputs";
 9  pin in bit button.c04.r##[8] "array of  inputs";
10  pin in bit button.c05.r##[8] "array of  inputs";
11  pin in bit button.c06.r##[8] "array of  inputs";
12  pin in bit button.c07.r##[8] "array of  inputs";
13  
14  variable int keydown = 0xC0;
15  variable int keyup = 0x80;
16  variable int nokeychange = 0x40;
17  variable int last[64];
18  
19  function _;
20  license "GPL";
21  ;;
22  FUNCTION(_) {
23      int num = 0;
24      int c, r, cur_button;
25      int allup_flag = true;
26  
27      for (r = 0; r < 8; r++){
28          for (c = 0; c < 8; c++){
29              if (c==0) cur_button = button_c00_r(r);
30              if (c==1) cur_button = button_c01_r(r);
31              if (c==2) cur_button = button_c02_r(r);
32              if (c==3) cur_button = button_c03_r(r);
33              if (c==4) cur_button = button_c04_r(r);
34              if (c==5) cur_button = button_c05_r(r);
35              if (c==6) cur_button = button_c06_r(r);
36              if (c==7) cur_button = button_c07_r(r);
37  
38              if (cur_button == true) allup_flag = false;
39  
40              num = r*8+c; // row * number of rows + column
41              if ( cur_button != last[num] ){
42                  rtapi_print("row: %d column: %d code: %d\n",r,c,num);
43                  last[num] = cur_button;
44                  if (cur_button == 1){
45                      out = num | keydown;
46                      return;
47                  }else{
48                      out = num | keyup;
49                      return;
50                  }
51              }
52          }
53      }
54      if (allup_flag){
55          out = 0;
56      }else{
57          out = nokeychange;
58      }
59  
60  }