|
@@ -1,76 +0,0 @@
|
|
|
-
|
|
|
- * ----------------------------------------------------------------------------
|
|
|
- * "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
- * <https:
|
|
|
- * notice you can do whatever you want with this stuff. If we meet some day, and
|
|
|
- * you think this stuff is worth it, you can buy me a beer in return. KarlK90
|
|
|
- * ----------------------------------------------------------------------------
|
|
|
- */
|
|
|
-
|
|
|
-#include "matrix.h"
|
|
|
-#include "atomic_util.h"
|
|
|
-#include "gpio.h"
|
|
|
-
|
|
|
-#define ROWS_PER_HAND (MATRIX_ROWS / 2)
|
|
|
-static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
|
|
|
-static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
|
|
|
-
|
|
|
-void matrix_init_pins(void) {
|
|
|
- for (size_t i = 0; i < MATRIX_COLS; i++) {
|
|
|
- setPinInputHigh(col_pins[i]);
|
|
|
- }
|
|
|
- for (size_t i = 0; i < ROWS_PER_HAND; i++) {
|
|
|
- setPinOutput(row_pins[i]);
|
|
|
- writePinHigh(row_pins[i]);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
|
|
|
-
|
|
|
- ATOMIC_BLOCK_FORCEON { writePinLow(row_pins[current_row]); }
|
|
|
- matrix_output_select_delay();
|
|
|
-
|
|
|
-
|
|
|
- uint16_t porta = palReadPort(GPIOA);
|
|
|
- uint16_t portb = palReadPort(GPIOB);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Pin is active low, therefore we have to invert the result. */
|
|
|
- matrix_row_t cols = ~(((porta & (0x1 << 0)) >> 0)
|
|
|
- | ((portb & (0x1 << 11)) >> 10)
|
|
|
- | ((portb & (0x1 << 0)) << 2)
|
|
|
- | ((portb & (0x1 << 10)) >> 7)
|
|
|
- | ((portb & (0x1 << 12)) >> 8)
|
|
|
- | ((portb & (0x1 << 2)) << 3)
|
|
|
- | ((porta & (0x1 << 8)) >> 2));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- current_matrix[current_row] = cols;
|
|
|
-
|
|
|
-
|
|
|
- ATOMIC_BLOCK_FORCEON { writePinHigh(row_pins[current_row]); }
|
|
|
- matrix_output_unselect_delay(current_row, cols != 0);
|
|
|
-}
|
|
|
-
|
|
|
-#if defined(BUSY_WAIT)
|
|
|
-void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
|
|
|
- for (int32_t i = 0; i < BUSY_WAIT_INSTRUCTIONS; i++) {
|
|
|
- __asm__ volatile("nop" ::: "memory");
|
|
|
- }
|
|
|
-}
|
|
|
-#endif
|