diff options
| author | Joel Challis <git@zvecr.com> | 2021-07-22 23:01:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-22 23:01:19 +0100 |
| commit | 5d7f2823c947264d3ff3bb4f057f8e050d6b4af1 (patch) | |
| tree | a1cfdefd57fd2fcc7afcc1fa025da25538cc692d /keyboards | |
| parent | 95a7c2282466252641a1d0bb1b15d50752193f4b (diff) | |
| download | qmk_firmware-5d7f2823c947264d3ff3bb4f057f8e050d6b4af1.tar.gz qmk_firmware-5d7f2823c947264d3ff3bb4f057f8e050d6b4af1.zip | |
Implement GPIO abstraction for atsam (#13567)
* Implement GPIO abstraction for atsam
* Convert Drop boards to normal matrix config
* Work round pin conflicts and matrix delay
Diffstat (limited to 'keyboards')
| -rw-r--r-- | keyboards/massdrop/alt/alt.c | 21 | ||||
| -rw-r--r-- | keyboards/massdrop/alt/config.h | 19 | ||||
| -rw-r--r-- | keyboards/massdrop/alt/matrix.c | 76 | ||||
| -rw-r--r-- | keyboards/massdrop/alt/rules.mk | 3 | ||||
| -rw-r--r-- | keyboards/massdrop/ctrl/config.h | 18 | ||||
| -rw-r--r-- | keyboards/massdrop/ctrl/ctrl.c | 21 | ||||
| -rw-r--r-- | keyboards/massdrop/ctrl/matrix.c | 76 | ||||
| -rw-r--r-- | keyboards/massdrop/ctrl/rules.mk | 3 |
8 files changed, 63 insertions, 174 deletions
diff --git a/keyboards/massdrop/alt/alt.c b/keyboards/massdrop/alt/alt.c new file mode 100644 index 000000000..81dd66b3c --- /dev/null +++ b/keyboards/massdrop/alt/alt.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2021 Massdrop Inc. | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include "alt.h" | ||
| 18 | |||
| 19 | /* Temporary solution for matrix delay */ | ||
| 20 | void matrix_output_select_delay(void) { matrix_io_delay(); } | ||
| 21 | void matrix_output_unselect_delay(void) { } | ||
diff --git a/keyboards/massdrop/alt/config.h b/keyboards/massdrop/alt/config.h index d8389fc00..d28094c49 100644 --- a/keyboards/massdrop/alt/config.h +++ b/keyboards/massdrop/alt/config.h | |||
| @@ -32,18 +32,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 32 | #define MATRIX_ROWS 5 | 32 | #define MATRIX_ROWS 5 |
| 33 | #define MATRIX_COLS 15 | 33 | #define MATRIX_COLS 15 |
| 34 | 34 | ||
| 35 | |||
| 36 | #define MATRIX_ROW_PINS { A00, A01, A02, A03, A04 } | ||
| 37 | #define MATRIX_COL_PINS { B04, B05, B06, B07, B08, B09, B10, B11, B12, B13, A05, A06, A07, A10, A11 } | ||
| 38 | #define UNUSED_PINS | ||
| 39 | |||
| 40 | /* COL2ROW, ROW2COL */ | ||
| 41 | #define DIODE_DIRECTION COL2ROW | ||
| 42 | |||
| 43 | /* Temporary solution for matrix delay */ | ||
| 44 | #define IGNORE_ATOMIC_BLOCK | ||
| 45 | |||
| 35 | /* MCU Port name definitions */ | 46 | /* MCU Port name definitions */ |
| 36 | #define PA 0 | 47 | #define PA 0 |
| 37 | #define PB 1 | 48 | #define PB 1 |
| 38 | 49 | ||
| 39 | /* Port and Pin definition of key row hardware configuration */ | ||
| 40 | #define MATRIX_ROW_PORTS PA, PA, PA, PA, PA | ||
| 41 | #define MATRIX_ROW_PINS 0, 1, 2, 3, 4 | ||
| 42 | |||
| 43 | /* Port and Pin definition of key column hardware configuration */ | ||
| 44 | #define MATRIX_COL_PORTS PB, PB, PB, PB, PB, PB, PB, PB, PB, PB, PA, PA, PA, PA, PA | ||
| 45 | #define MATRIX_COL_PINS 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 5, 6, 7, 10, 11 | ||
| 46 | |||
| 47 | /* This Shift Register expands available hardware output lines to control additional peripherals */ | 50 | /* This Shift Register expands available hardware output lines to control additional peripherals */ |
| 48 | /* It uses four lines from the MCU to provide 16 output lines */ | 51 | /* It uses four lines from the MCU to provide 16 output lines */ |
| 49 | /* Shift Register Clock configuration (MCU to ShiftRegister.RCLK) */ | 52 | /* Shift Register Clock configuration (MCU to ShiftRegister.RCLK) */ |
diff --git a/keyboards/massdrop/alt/matrix.c b/keyboards/massdrop/alt/matrix.c deleted file mode 100644 index 181f223e4..000000000 --- a/keyboards/massdrop/alt/matrix.c +++ /dev/null | |||
| @@ -1,76 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2018 Massdrop Inc. | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "alt.h" | ||
| 19 | #include "d51_util.h" | ||
| 20 | |||
| 21 | const uint8_t row_ports[] = {MATRIX_ROW_PORTS}; | ||
| 22 | const uint8_t row_pins[] = {MATRIX_ROW_PINS}; | ||
| 23 | const uint8_t col_ports[] = {MATRIX_COL_PORTS}; | ||
| 24 | const uint8_t col_pins[] = {MATRIX_COL_PINS}; | ||
| 25 | uint32_t row_masks[2]; // NOTE: If more than PA PB used in the future, adjust code to accommodate | ||
| 26 | |||
| 27 | void matrix_init_custom(void) { | ||
| 28 | row_masks[PA] = 0; | ||
| 29 | row_masks[PB] = 0; | ||
| 30 | |||
| 31 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 32 | PORT->Group[row_ports[row]].DIRCLR.reg = 1 << row_pins[row]; // Input | ||
| 33 | PORT->Group[row_ports[row]].OUTCLR.reg = 1 << row_pins[row]; // Low | ||
| 34 | PORT->Group[row_ports[row]].PINCFG[row_pins[row]].bit.INEN = 1; // Input Enable, | ||
| 35 | PORT->Group[row_ports[row]].PINCFG[row_pins[row]].bit.PULLEN = 1; // Pull Enable | ||
| 36 | row_masks[row_ports[row]] |= 1 << row_pins[row]; // Add pin to proper row mask | ||
| 37 | } | ||
| 38 | |||
| 39 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 40 | PORT->Group[col_ports[col]].DIRSET.reg = 1 << col_pins[col]; // Output | ||
| 41 | PORT->Group[col_ports[col]].OUTCLR.reg = 1 << col_pins[col]; // Low | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
| 46 | matrix_row_t raw[MATRIX_ROWS] = {0}; | ||
| 47 | uint32_t scans[2]; // PA PB | ||
| 48 | |||
| 49 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 50 | PORT->Group[col_ports[col]].OUTSET.reg = 1 << col_pins[col]; // Set col output | ||
| 51 | |||
| 52 | matrix_io_delay(); // Delay for output | ||
| 53 | |||
| 54 | scans[PA] = PORT->Group[PA].IN.reg & row_masks[PA]; // Read PA row pins data | ||
| 55 | scans[PB] = PORT->Group[PB].IN.reg & row_masks[PB]; // Read PB row pins data | ||
| 56 | |||
| 57 | PORT->Group[col_ports[col]].OUTCLR.reg = 1 << col_pins[col]; // Clear col output | ||
| 58 | |||
| 59 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 60 | // Move scan bits from scans array into proper row bit locations | ||
| 61 | if (scans[row_ports[row]] & (1 << row_pins[row])) { | ||
| 62 | raw[row] |= 1 << col; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | bool changed = false; | ||
| 68 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 69 | if (current_matrix[row] != raw[row]) { | ||
| 70 | current_matrix[row] = raw[row]; | ||
| 71 | changed = true; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | return changed; | ||
| 76 | } | ||
diff --git a/keyboards/massdrop/alt/rules.mk b/keyboards/massdrop/alt/rules.mk index 86403d830..3921d57ab 100644 --- a/keyboards/massdrop/alt/rules.mk +++ b/keyboards/massdrop/alt/rules.mk | |||
| @@ -1,13 +1,10 @@ | |||
| 1 | # project specific files | 1 | # project specific files |
| 2 | SRC = matrix.c | ||
| 3 | SRC += config_led.c | 2 | SRC += config_led.c |
| 4 | 3 | ||
| 5 | #For platform and packs | 4 | #For platform and packs |
| 6 | ARM_ATSAM = SAMD51J18A | 5 | ARM_ATSAM = SAMD51J18A |
| 7 | MCU = cortex-m4 | 6 | MCU = cortex-m4 |
| 8 | 7 | ||
| 9 | CUSTOM_MATRIX = lite | ||
| 10 | |||
| 11 | # Build Options | 8 | # Build Options |
| 12 | # comment out to disable the options. | 9 | # comment out to disable the options. |
| 13 | # | 10 | # |
diff --git a/keyboards/massdrop/ctrl/config.h b/keyboards/massdrop/ctrl/config.h index 215a2e1b1..3dbd9b887 100644 --- a/keyboards/massdrop/ctrl/config.h +++ b/keyboards/massdrop/ctrl/config.h | |||
| @@ -32,18 +32,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 32 | #define MATRIX_ROWS 11 | 32 | #define MATRIX_ROWS 11 |
| 33 | #define MATRIX_COLS 8 | 33 | #define MATRIX_COLS 8 |
| 34 | 34 | ||
| 35 | #define MATRIX_ROW_PINS { B04, B05, B06, B07, B08, B09, A10, A11, B10, B11, B12 } | ||
| 36 | #define MATRIX_COL_PINS { A00, A01, A02, A03, A04, A05, A06, A07 } | ||
| 37 | #define UNUSED_PINS | ||
| 38 | |||
| 39 | /* COL2ROW, ROW2COL */ | ||
| 40 | #define DIODE_DIRECTION COL2ROW | ||
| 41 | |||
| 42 | /* Temporary solution for matrix delay */ | ||
| 43 | #define IGNORE_ATOMIC_BLOCK | ||
| 44 | |||
| 35 | /* MCU Port name definitions */ | 45 | /* MCU Port name definitions */ |
| 36 | #define PA 0 | 46 | #define PA 0 |
| 37 | #define PB 1 | 47 | #define PB 1 |
| 38 | 48 | ||
| 39 | /* Port and Pin definition of key row hardware configuration */ | ||
| 40 | #define MATRIX_ROW_PORTS PB, PB, PB, PB, PB, PB, PA, PA, PB, PB, PB | ||
| 41 | #define MATRIX_ROW_PINS 4, 5, 6, 7, 8, 9, 10, 11, 10, 11, 12 | ||
| 42 | |||
| 43 | /* Port and Pin definition of key column hardware configuration */ | ||
| 44 | #define MATRIX_COL_PORTS PA, PA, PA, PA, PA, PA, PA, PA | ||
| 45 | #define MATRIX_COL_PINS 0, 1, 2, 3, 4, 5, 6, 7 | ||
| 46 | |||
| 47 | /* This Shift Register expands available hardware output lines to control additional peripherals */ | 49 | /* This Shift Register expands available hardware output lines to control additional peripherals */ |
| 48 | /* It uses four lines from the MCU to provide 16 output lines */ | 50 | /* It uses four lines from the MCU to provide 16 output lines */ |
| 49 | /* Shift Register Clock configuration (MCU to ShiftRegister.RCLK) */ | 51 | /* Shift Register Clock configuration (MCU to ShiftRegister.RCLK) */ |
diff --git a/keyboards/massdrop/ctrl/ctrl.c b/keyboards/massdrop/ctrl/ctrl.c new file mode 100644 index 000000000..b50f1cb59 --- /dev/null +++ b/keyboards/massdrop/ctrl/ctrl.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2021 Massdrop Inc. | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include "ctrl.h" | ||
| 18 | |||
| 19 | /* Temporary solution for matrix delay */ | ||
| 20 | void matrix_output_select_delay(void) { matrix_io_delay(); } | ||
| 21 | void matrix_output_unselect_delay(void) { } | ||
diff --git a/keyboards/massdrop/ctrl/matrix.c b/keyboards/massdrop/ctrl/matrix.c deleted file mode 100644 index a542d18c2..000000000 --- a/keyboards/massdrop/ctrl/matrix.c +++ /dev/null | |||
| @@ -1,76 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2018 Massdrop Inc. | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "ctrl.h" | ||
| 19 | #include "d51_util.h" | ||
| 20 | |||
| 21 | const uint8_t row_ports[] = {MATRIX_ROW_PORTS}; | ||
| 22 | const uint8_t row_pins[] = {MATRIX_ROW_PINS}; | ||
| 23 | const uint8_t col_ports[] = {MATRIX_COL_PORTS}; | ||
| 24 | const uint8_t col_pins[] = {MATRIX_COL_PINS}; | ||
| 25 | uint32_t row_masks[2]; // NOTE: If more than PA PB used in the future, adjust code to accommodate | ||
| 26 | |||
| 27 | void matrix_init_custom(void) { | ||
| 28 | row_masks[PA] = 0; | ||
| 29 | row_masks[PB] = 0; | ||
| 30 | |||
| 31 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 32 | PORT->Group[row_ports[row]].DIRCLR.reg = 1 << row_pins[row]; // Input | ||
| 33 | PORT->Group[row_ports[row]].OUTCLR.reg = 1 << row_pins[row]; // Low | ||
| 34 | PORT->Group[row_ports[row]].PINCFG[row_pins[row]].bit.INEN = 1; // Input Enable, | ||
| 35 | PORT->Group[row_ports[row]].PINCFG[row_pins[row]].bit.PULLEN = 1; // Pull Enable | ||
| 36 | row_masks[row_ports[row]] |= 1 << row_pins[row]; // Add pin to proper row mask | ||
| 37 | } | ||
| 38 | |||
| 39 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 40 | PORT->Group[col_ports[col]].DIRSET.reg = 1 << col_pins[col]; // Output | ||
| 41 | PORT->Group[col_ports[col]].OUTCLR.reg = 1 << col_pins[col]; // Low | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
| 46 | matrix_row_t raw[MATRIX_ROWS] = {0}; | ||
| 47 | uint32_t scans[2]; // PA PB | ||
| 48 | |||
| 49 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
| 50 | PORT->Group[col_ports[col]].OUTSET.reg = 1 << col_pins[col]; // Set col output | ||
| 51 | |||
| 52 | matrix_io_delay(); // Delay for output | ||
| 53 | |||
| 54 | scans[PA] = PORT->Group[PA].IN.reg & row_masks[PA]; // Read PA row pins data | ||
| 55 | scans[PB] = PORT->Group[PB].IN.reg & row_masks[PB]; // Read PB row pins data | ||
| 56 | |||
| 57 | PORT->Group[col_ports[col]].OUTCLR.reg = 1 << col_pins[col]; // Clear col output | ||
| 58 | |||
| 59 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 60 | // Move scan bits from scans array into proper row bit locations | ||
| 61 | if (scans[row_ports[row]] & (1 << row_pins[row])) { | ||
| 62 | raw[row] |= 1 << col; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | bool changed = false; | ||
| 68 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 69 | if (current_matrix[row] != raw[row]) { | ||
| 70 | current_matrix[row] = raw[row]; | ||
| 71 | changed = true; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | return changed; | ||
| 76 | } | ||
diff --git a/keyboards/massdrop/ctrl/rules.mk b/keyboards/massdrop/ctrl/rules.mk index f58042b75..ad79bbf91 100644 --- a/keyboards/massdrop/ctrl/rules.mk +++ b/keyboards/massdrop/ctrl/rules.mk | |||
| @@ -1,13 +1,10 @@ | |||
| 1 | # project specific files | 1 | # project specific files |
| 2 | SRC = matrix.c | ||
| 3 | SRC += config_led.c | 2 | SRC += config_led.c |
| 4 | 3 | ||
| 5 | #For platform and packs | 4 | #For platform and packs |
| 6 | ARM_ATSAM = SAMD51J18A | 5 | ARM_ATSAM = SAMD51J18A |
| 7 | MCU = cortex-m4 | 6 | MCU = cortex-m4 |
| 8 | 7 | ||
| 9 | CUSTOM_MATRIX = lite | ||
| 10 | |||
| 11 | # Build Options | 8 | # Build Options |
| 12 | # comment out to disable the options. | 9 | # comment out to disable the options. |
| 13 | # | 10 | # |
