aboutsummaryrefslogtreecommitdiff
path: root/quantum/split_common
diff options
context:
space:
mode:
authorJames Churchill <pelrun@gmail.com>2018-12-29 16:53:21 +1100
committerDrashna Jaelre <drashna@live.com>2019-01-03 20:00:27 -0800
commit38e01a7480f6826b3d220c4c8357788558b2af07 (patch)
tree25ccc41022e2c2486d44ad4a1e5a0cae4e9f5a55 /quantum/split_common
parent54b572159f62913ead47b0a6ee8d2d09dfb8f19a (diff)
downloadqmk_firmware-38e01a7480f6826b3d220c4c8357788558b2af07.tar.gz
qmk_firmware-38e01a7480f6826b3d220c4c8357788558b2af07.zip
Convert split_common to use generic GPIO api
Diffstat (limited to 'quantum/split_common')
-rw-r--r--quantum/split_common/matrix.c60
-rw-r--r--quantum/split_common/split_util.c15
2 files changed, 22 insertions, 53 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index 261137638..2c37053f8 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -20,17 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */ 20 */
21#include <stdint.h> 21#include <stdint.h>
22#include <stdbool.h> 22#include <stdbool.h>
23#include <avr/io.h>
24#include "wait.h" 23#include "wait.h"
25#include "print.h"
26#include "debug.h"
27#include "util.h" 24#include "util.h"
28#include "matrix.h" 25#include "matrix.h"
29#include "split_util.h" 26#include "split_util.h"
30#include "pro_micro.h"
31#include "config.h" 27#include "config.h"
32#include "timer.h" 28#include "timer.h"
33#include "split_flags.h" 29#include "split_flags.h"
30#include "quantum.h"
34 31
35#ifdef BACKLIGHT_ENABLE 32#ifdef BACKLIGHT_ENABLE
36# include "backlight.h" 33# include "backlight.h"
@@ -91,8 +88,8 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS];
91 88
92static uint8_t error_count = 0; 89static uint8_t error_count = 0;
93 90
94static uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; 91static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
95static uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; 92static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
96 93
97/* matrix state(1:on, 0:off) */ 94/* matrix state(1:on, 0:off) */
98static matrix_row_t matrix[MATRIX_ROWS]; 95static matrix_row_t matrix[MATRIX_ROWS];
@@ -440,9 +437,7 @@ uint8_t matrix_key_count(void)
440static void init_cols(void) 437static void init_cols(void)
441{ 438{
442 for(uint8_t x = 0; x < MATRIX_COLS; x++) { 439 for(uint8_t x = 0; x < MATRIX_COLS; x++) {
443 uint8_t pin = col_pins[x]; 440 setPinInputHigh(col_pins[x]);
444 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
445 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
446 } 441 }
447} 442}
448 443
@@ -460,13 +455,8 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
460 455
461 // For each col... 456 // For each col...
462 for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { 457 for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
463
464 // Select the col pin to read (active low)
465 uint8_t pin = col_pins[col_index];
466 uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
467
468 // Populate the matrix row with the state of the col pin 458 // Populate the matrix row with the state of the col pin
469 current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); 459 current_matrix[current_row] |= readPin(col_pins[col_index]) ? 0 : (ROW_SHIFTER << col_index);
470 } 460 }
471 461
472 // Unselect row 462 // Unselect row
@@ -477,24 +467,19 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
477 467
478static void select_row(uint8_t row) 468static void select_row(uint8_t row)
479{ 469{
480 uint8_t pin = row_pins[row]; 470 writePinLow(row_pins[row]);
481 _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT 471 setPinOutput(row_pins[row]);
482 _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
483} 472}
484 473
485static void unselect_row(uint8_t row) 474static void unselect_row(uint8_t row)
486{ 475{
487 uint8_t pin = row_pins[row]; 476 setPinInputHigh(row_pins[row]);
488 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
489 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
490} 477}
491 478
492static void unselect_rows(void) 479static void unselect_rows(void)
493{ 480{
494 for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { 481 for(uint8_t x = 0; x < ROWS_PER_HAND; x++) {
495 uint8_t pin = row_pins[x]; 482 setPinInputHigh(row_pins[x]);
496 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
497 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
498 } 483 }
499} 484}
500 485
@@ -503,9 +488,7 @@ static void unselect_rows(void)
503static void init_rows(void) 488static void init_rows(void)
504{ 489{
505 for(uint8_t x = 0; x < ROWS_PER_HAND; x++) { 490 for(uint8_t x = 0; x < ROWS_PER_HAND; x++) {
506 uint8_t pin = row_pins[x]; 491 setPinInputHigh(row_pins[x]);
507 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
508 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
509 } 492 }
510} 493}
511 494
@@ -525,15 +508,15 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
525 matrix_row_t last_row_value = current_matrix[row_index]; 508 matrix_row_t last_row_value = current_matrix[row_index];
526 509
527 // Check row pin state 510 // Check row pin state
528 if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0) 511 if (readPin(row_pins[row_index]))
529 { 512 {
530 // Pin LO, set col bit 513 // Pin HI, clear col bit
531 current_matrix[row_index] |= (ROW_SHIFTER << current_col); 514 current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
532 } 515 }
533 else 516 else
534 { 517 {
535 // Pin HI, clear col bit 518 // Pin LO, set col bit
536 current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); 519 current_matrix[row_index] |= (ROW_SHIFTER << current_col);
537 } 520 }
538 521
539 // Determine if the matrix changed state 522 // Determine if the matrix changed state
@@ -551,24 +534,19 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
551 534
552static void select_col(uint8_t col) 535static void select_col(uint8_t col)
553{ 536{
554 uint8_t pin = col_pins[col]; 537 writePinLow(col_pins[col]);
555 _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT 538 setPinOutput(col_pins[col]);
556 _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
557} 539}
558 540
559static void unselect_col(uint8_t col) 541static void unselect_col(uint8_t col)
560{ 542{
561 uint8_t pin = col_pins[col]; 543 setPinInputHigh(col_pins[col]);
562 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
563 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
564} 544}
565 545
566static void unselect_cols(void) 546static void unselect_cols(void)
567{ 547{
568 for(uint8_t x = 0; x < MATRIX_COLS; x++) { 548 for(uint8_t x = 0; x < MATRIX_COLS; x++) {
569 uint8_t pin = col_pins[x]; 549 setPinInputHigh(col_pins[x]);
570 _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
571 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
572 } 550 }
573} 551}
574 552
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index c613f265a..11453c998 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -1,24 +1,15 @@
1#include <avr/io.h>
2#include <avr/wdt.h>
3#include <avr/power.h>
4#include <avr/interrupt.h>
5#include <util/delay.h>
6#include <avr/eeprom.h>
7#include "split_util.h" 1#include "split_util.h"
8#include "matrix.h" 2#include "matrix.h"
9#include "keyboard.h" 3#include "keyboard.h"
10#include "config.h" 4#include "config.h"
11#include "timer.h" 5#include "timer.h"
12#include "split_flags.h" 6#include "split_flags.h"
7#include "quantum.h"
13 8
14#ifdef BACKLIGHT_ENABLE 9#ifdef BACKLIGHT_ENABLE
15# include "backlight.h" 10# include "backlight.h"
16#endif 11#endif
17 12
18#ifdef SPLIT_HAND_PIN
19# include "pincontrol.h"
20#endif
21
22#if defined(USE_I2C) || defined(EH) 13#if defined(USE_I2C) || defined(EH)
23# include "i2c.h" 14# include "i2c.h"
24#endif 15#endif
@@ -30,8 +21,8 @@ volatile uint8_t setTries = 0;
30static void setup_handedness(void) { 21static void setup_handedness(void) {
31 #ifdef SPLIT_HAND_PIN 22 #ifdef SPLIT_HAND_PIN
32 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand 23 // Test pin SPLIT_HAND_PIN for High/Low, if low it's right hand
33 pinMode(SPLIT_HAND_PIN, PinDirectionInput); 24 setPinInput(SPLIT_HAND_PIN);
34 isLeftHand = digitalRead(SPLIT_HAND_PIN); 25 isLeftHand = readPin(SPLIT_HAND_PIN);
35 #else 26 #else
36 #ifdef EE_HANDS 27 #ifdef EE_HANDS
37 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); 28 isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS);