summaryrefslogtreecommitdiff
path: root/keyboards/handwired/dactyl
diff options
context:
space:
mode:
authorWilliam Chang <william@factual.com>2019-07-13 10:18:33 -0700
committerWilliam Chang <william@factual.com>2019-07-13 10:18:33 -0700
commit71493b2f9bbd5f3d18373c518fa14ccafcbf48fc (patch)
tree3bb3e5e496621535611e087720aa5c4d7a533e5e /keyboards/handwired/dactyl
parent86ad4988fe7ff64916127509d84f44c56fa097aa (diff)
parentda1f05fbc19477c05c0c01bb07fabfaf1ece9d54 (diff)
Merge branch 'master' of https://github.com/qmk/qmk_firmware
Diffstat (limited to 'keyboards/handwired/dactyl')
-rw-r--r--keyboards/handwired/dactyl/config.h3
-rw-r--r--keyboards/handwired/dactyl/matrix.c60
2 files changed, 30 insertions, 33 deletions
diff --git a/keyboards/handwired/dactyl/config.h b/keyboards/handwired/dactyl/config.h
index 8d42c0ae47..49524c2097 100644
--- a/keyboards/handwired/dactyl/config.h
+++ b/keyboards/handwired/dactyl/config.h
@@ -36,7 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define COL_EXPANDED { true, true, true, true, true, true, false, false, false, false, false, false}
#define MATRIX_ONBOARD_ROW_PINS { F0, F1, F4, F5, F6, F7 }
#define MATRIX_ONBOARD_COL_PINS { 0, 0, 0, 0, 0, 0, B1, B2, B3, D2, D3, C6 }
-#define EXPANDER_COL_REGISTER 0
+#define EXPANDER_COL_REGISTER GPIOA
+#define EXPANDER_ROW_REGISTER GPIOB
#define MATRIX_EXPANDER_COL_PINS {0, 1, 2, 3, 4, 5}
#define MATRIX_EXPANDER_ROW_PINS {0, 1, 2, 3, 4, 5}
diff --git a/keyboards/handwired/dactyl/matrix.c b/keyboards/handwired/dactyl/matrix.c
index f63cf1188f..28cf37522b 100644
--- a/keyboards/handwired/dactyl/matrix.c
+++ b/keyboards/handwired/dactyl/matrix.c
@@ -31,11 +31,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Set 0 if debouncing isn't needed */
-#ifndef DEBOUNCING_DELAY
-# define DEBOUNCING_DELAY 5
+#ifndef DEBOUNCE
+# define DEBOUNCE 5
#endif
-#if (DEBOUNCING_DELAY > 0)
+#if (DEBOUNCE > 0)
static uint16_t debouncing_time;
static bool debouncing = false;
#endif
@@ -82,10 +82,6 @@ uint32_t matrix_scan_count;
#endif
#define ROW_SHIFTER ((matrix_row_t)1)
-#if (DIODE_DIRECTION == COL2ROW)
-// bitmask to ensure the row state from the expander only applies to its columns
-#define EXPANDER_MASK ((matrix_row_t)0b00111111)
-#endif
__attribute__ ((weak))
void matrix_init_user(void) {}
@@ -166,17 +162,17 @@ void init_expander(void) {
/*
Pin direction and pull-up depends on both the diode direction
- and on whether the column register is 0 ("A") or 1 ("B"):
+ and on whether the column register is GPIOA or GPIOB
+-------+---------------+---------------+
| | ROW2COL | COL2ROW |
+-------+---------------+---------------+
- | Reg 0 | input, output | output, input |
+ | GPIOA | input, output | output, input |
+-------+---------------+---------------+
- | Reg 1 | output, input | input, output |
+ | GPIOB | output, input | input, output |
+-------+---------------+---------------+
*/
-#if (EXPANDER_COLUMN_REGISTER == 0)
+#if (EXPANDER_COL_REGISTER == GPIOA)
# if (DIODE_DIRECTION == COL2ROW)
expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out;
expander_status = i2c_write(0); if (expander_status) goto out;
@@ -184,7 +180,7 @@ void init_expander(void) {
expander_status = i2c_write(0); if (expander_status) goto out;
expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out;
# endif
-#elif (EXPANDER_COLUMN_REGISTER == 1)
+#elif (EXPANDER_COL_REGISTER == GPIOB)
# if (DIODE_DIRECTION == COL2ROW)
expander_status = i2c_write(0); if (expander_status) goto out;
expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out;
@@ -202,7 +198,7 @@ void init_expander(void) {
// - driving : off : 0
expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
expander_status = i2c_write(GPPUA); if (expander_status) goto out;
-#if (EXPANDER_COLUMN_REGISTER == 0)
+#if (EXPANDER_COL_REGISTER == GPIOA)
# if (DIODE_DIRECTION == COL2ROW)
expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out;
expander_status = i2c_write(0); if (expander_status) goto out;
@@ -210,7 +206,7 @@ void init_expander(void) {
expander_status = i2c_write(0); if (expander_status) goto out;
expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out;
# endif
-#elif (EXPANDER_COLUMN_REGISTER == 1)
+#elif (EXPANDER_COL_REGISTER == GPIOB)
# if (DIODE_DIRECTION == COL2ROW)
expander_status = i2c_write(0); if (expander_status) goto out;
expander_status = i2c_write(expander_input_pin_mask); if (expander_status) goto out;
@@ -256,7 +252,7 @@ uint8_t matrix_scan(void)
#if (DIODE_DIRECTION == COL2ROW)
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
-# if (DEBOUNCING_DELAY > 0)
+# if (DEBOUNCE > 0)
bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
if (matrix_changed) {
@@ -270,7 +266,7 @@ uint8_t matrix_scan(void)
#elif (DIODE_DIRECTION == ROW2COL)
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
-# if (DEBOUNCING_DELAY > 0)
+# if (DEBOUNCE > 0)
bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
if (matrix_changed) {
@@ -284,8 +280,8 @@ uint8_t matrix_scan(void)
}
#endif
-# if (DEBOUNCING_DELAY > 0)
- if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
+# if (DEBOUNCE > 0)
+ if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCE)) {
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
matrix[i] = matrix_debouncing[i];
}
@@ -299,7 +295,7 @@ uint8_t matrix_scan(void)
bool matrix_is_modified(void) // deprecated and evidently not called.
{
-#if (DEBOUNCING_DELAY > 0)
+#if (DEBOUNCE > 0)
if (debouncing) return false;
#endif
return true;
@@ -365,11 +361,11 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
// Read columns from expander, unless it's in an error state
if (! expander_status) {
- expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
- expander_status = i2c_write(GPIOA); if (expander_status) goto out;
- expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out;
+ expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
+ expander_status = i2c_write(EXPANDER_COL_REGISTER); if (expander_status) goto out;
+ expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out;
- current_matrix[current_row] |= (~i2c_readNak()) & EXPANDER_MASK;
+ current_matrix[current_row] |= (~i2c_readNak()) & expander_input_pin_mask;
out:
i2c_stop();
@@ -394,9 +390,9 @@ static void select_row(uint8_t row) {
if (! expander_status) {
// set active row low : 0
// set other rows hi-Z : 1
- expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
- expander_status = i2c_write(GPIOB); if (expander_status) goto out;
- expander_status = i2c_write(0xFF & ~(1<<row)); if (expander_status) goto out;
+ expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
+ expander_status = i2c_write(EXPANDER_ROW_REGISTER); if (expander_status) goto out;
+ expander_status = i2c_write(0xFF & ~(1<<row)); if (expander_status) goto out;
out:
i2c_stop();
}
@@ -454,9 +450,9 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
return false;
}
- expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
- expander_status = i2c_write(GPIOB); if (expander_status) goto out;
- expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out;
+ expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
+ expander_status = i2c_write(EXPANDER_ROW_REGISTER); if (expander_status) goto out;
+ expander_status = i2c_start(I2C_ADDR_READ); if (expander_status) goto out;
column_state = i2c_readNak();
out:
@@ -504,9 +500,9 @@ static void select_col(uint8_t col)
} else {
// set active col low : 0
// set other cols hi-Z : 1
- expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
- expander_status = i2c_write(GPIOA); if (expander_status) goto out;
- expander_status = i2c_write(0xFF & ~(1<<col)); if (expander_status) goto out;
+ expander_status = i2c_start(I2C_ADDR_WRITE); if (expander_status) goto out;
+ expander_status = i2c_write(EXPANDER_COL_REGISTER); if (expander_status) goto out;
+ expander_status = i2c_write(0xFF & ~(1<<col)); if (expander_status) goto out;
out:
i2c_stop();
}