upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

matrix.h 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright 2011 Jun Wako <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef MATRIX_H
  15. #define MATRIX_H
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #if MATRIX_COLS <= 8
  19. typedef uint8_t matrix_row_t;
  20. #elif MATRIX_COLS <= 16
  21. typedef uint16_t matrix_row_t;
  22. #elif MATRIX_COLS <= 32
  23. typedef uint32_t matrix_row_t;
  24. #else
  25. # error "There are too many columns."
  26. #endif
  27. #if DIODE_DIRECTION == ROW2COL
  28. # if MATRIX_ROWS <= 8
  29. typedef uint8_t matrix_col_t;
  30. # elif MATRIX_ROWS <= 16
  31. typedef uint16_t matrix_col_t;
  32. # elif MATRIX_ROWS <= 32
  33. typedef uint32_t matrix_col_t;
  34. # else
  35. # error "There are too many rows."
  36. # endif
  37. #endif
  38. typedef struct {
  39. uint8_t input_addr:4;
  40. uint8_t bit:4;
  41. } io_pin_t;
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /* counts the number of rows in the matrix */
  46. uint8_t matrix_rows(void);
  47. /* counts the number of columns in the matrix */
  48. uint8_t matrix_cols(void);
  49. /* sets up the matrix before matrix_init */
  50. void matrix_setup(void);
  51. /* intializes the matrix */
  52. void matrix_init(void);
  53. /* scans the entire matrix */
  54. uint8_t matrix_scan(void);
  55. /* checks if the matrix has been modified */
  56. bool matrix_is_modified(void) __attribute__ ((deprecated));
  57. /* checks if a key is pressed */
  58. bool matrix_is_on(uint8_t row, uint8_t col);
  59. /* inspects the state of a row in the matrix */
  60. matrix_row_t matrix_get_row(uint8_t row);
  61. /* prints the matrix for debugging */
  62. void matrix_print(void);
  63. /* counts the total number of keys pressed */
  64. uint8_t matrix_key_count(void);
  65. /* controls power to the matrix */
  66. void matrix_power_up(void);
  67. void matrix_power_down(void);
  68. /* executes code for Quantum */
  69. void matrix_init_quantum(void);
  70. void matrix_scan_quantum(void);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif