diff options
| -rw-r--r-- | keyboards/mschwingen/modelm/README.md | 25 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/config.h | 91 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/keymaps/default/keymap.c | 86 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/led_ffc/rules.mk | 1 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/led_wired/rules.mk | 1 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/led_ws2812/rules.mk | 2 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/matrix.c | 117 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/modelm.c | 214 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/modelm.h | 58 | ||||
| -rw-r--r-- | keyboards/mschwingen/modelm/rules.mk | 43 |
10 files changed, 638 insertions, 0 deletions
diff --git a/keyboards/mschwingen/modelm/README.md b/keyboards/mschwingen/modelm/README.md new file mode 100644 index 000000000..f4cb36062 --- /dev/null +++ b/keyboards/mschwingen/modelm/README.md | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | # atmega32U4 board for IBM Model M | ||
| 2 | |||
| 3 |  | ||
| 4 | |||
| 5 | This is a configuration of QMK intended to be used with the [Model M USB PCB](https://github.com/mschwingen/hardware/tree/master/modelm-usb). | ||
| 6 | |||
| 7 | * Keyboard Maintainer: [Michael Schwingen](https://github.com/mschwingen/) | ||
| 8 | * Hardware Supported: [Model M USB PCB](https://github.com/mschwingen/hardware/tree/master/modelm-usb) | ||
| 9 | * Hardware Availability: need to build your own. | ||
| 10 | |||
| 11 | Make example for this keyboard (after setting up your build environment), run one of: | ||
| 12 | |||
| 13 | make mschwingen/modelm/led_wired:default | ||
| 14 | make mschwingen/modelm/led_ffc:default | ||
| 15 | make mschwingen/modelm/led_ws2812:default | ||
| 16 | |||
| 17 | flash: | ||
| 18 | |||
| 19 | make mschwingen/modelm/led_wired:default:flash | ||
| 20 | make mschwingen/modelm/led_ffc:default:flash | ||
| 21 | make mschwingen/modelm/led_ws2812:default:flash | ||
| 22 | |||
| 23 | Bootloader: do not use the QMK bootloader, use the bootloader from [here](https://github.com/mschwingen/modelm-lufa-bootloader) | ||
| 24 | |||
| 25 | See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). | ||
diff --git a/keyboards/mschwingen/modelm/config.h b/keyboards/mschwingen/modelm/config.h new file mode 100644 index 000000000..07881cd21 --- /dev/null +++ b/keyboards/mschwingen/modelm/config.h | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2020 Michael Schwingen | ||
| 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 | #pragma once | ||
| 19 | |||
| 20 | #include "config_common.h" | ||
| 21 | |||
| 22 | /* USB Device descriptor parameter */ | ||
| 23 | #define VENDOR_ID 0xFEED | ||
| 24 | #define PRODUCT_ID 0x558E | ||
| 25 | #define DEVICE_VER 0x0001 | ||
| 26 | #define MANUFACTURER mschwingen | ||
| 27 | #define PRODUCT IBM Model M 101/102 | ||
| 28 | |||
| 29 | /* key matrix size */ | ||
| 30 | #define MATRIX_ROWS 16 | ||
| 31 | #define MATRIX_COLS 8 | ||
| 32 | |||
| 33 | /* pins for external shift registers */ | ||
| 34 | #define SR_LOAD_PIN B0 | ||
| 35 | #define SR_CLK_PIN B1 | ||
| 36 | #define SR_DIN_PIN B3 | ||
| 37 | #define SR_DOUT_PIN B2 | ||
| 38 | |||
| 39 | /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed (5 is default) */ | ||
| 40 | #define DEBOUNCE 5 | ||
| 41 | |||
| 42 | /* | ||
| 43 | * Feature disable options | ||
| 44 | * These options are also useful to firmware size reduction. | ||
| 45 | */ | ||
| 46 | |||
| 47 | /* disable debug print */ | ||
| 48 | //#define NO_DEBUG | ||
| 49 | |||
| 50 | /* disable print */ | ||
| 51 | //#define NO_PRINT | ||
| 52 | #define NORMAL_PRINT | ||
| 53 | //#define USER_PRINT | ||
| 54 | |||
| 55 | |||
| 56 | /* disable action features */ | ||
| 57 | //#define NO_ACTION_LAYER | ||
| 58 | //#define NO_ACTION_TAPPING | ||
| 59 | //#define NO_ACTION_ONESHOT | ||
| 60 | //#define NO_ACTION_MACRO | ||
| 61 | //#define NO_ACTION_FUNCTION | ||
| 62 | |||
| 63 | //#define DEBUG_MATRIX_SCAN_RATE | ||
| 64 | #define DYNAMIC_MACRO_NO_NESTING | ||
| 65 | |||
| 66 | #define QMK_LED E6 | ||
| 67 | |||
| 68 | #define MODELM_LED1 B5 | ||
| 69 | #define MODELM_LED2 B6 | ||
| 70 | #define MODELM_LED3 D0 | ||
| 71 | |||
| 72 | #if defined(KEYBOARD_mschwingen_modelm_led_wired) | ||
| 73 | # define MODELM_LED_CAPSLOCK MODELM_LED1 | ||
| 74 | # define MODELM_LED_SCROLLOCK MODELM_LED2 | ||
| 75 | # define MODELM_LED_NUMLOCK MODELM_LED3 | ||
| 76 | #elif defined(KEYBOARD_mschwingen_modelm_led_ffc) | ||
| 77 | # define MODELM_LED_CAPSLOCK MODELM_LED2 | ||
| 78 | # define MODELM_LED_SCROLLOCK MODELM_LED3 | ||
| 79 | # define MODELM_LED_NUMLOCK MODELM_LED1 | ||
| 80 | #elif defined(KEYBOARD_mschwingen_modelm_led_ws2812) | ||
| 81 | #else | ||
| 82 | # error one of MODELM_LEDS_FFC, MODELM_LEDS_WIRED or MODELM_LEDS_WS2812 must be set! | ||
| 83 | #endif | ||
| 84 | |||
| 85 | // 3* WS2812 LEDs instead of singlecolor GPIO LEDs | ||
| 86 | #define RGB_DI_PIN B6 | ||
| 87 | #define RGBLED_NUM 3 | ||
| 88 | |||
| 89 | // disabled, needs PCB patch. | ||
| 90 | //#define C6_AUDIO | ||
| 91 | //#define NO_MUSIC_MODE | ||
diff --git a/keyboards/mschwingen/modelm/keymaps/default/keymap.c b/keyboards/mschwingen/modelm/keymaps/default/keymap.c new file mode 100644 index 000000000..7f43746db --- /dev/null +++ b/keyboards/mschwingen/modelm/keymaps/default/keymap.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* Copyright 2019 ashpil | ||
| 2 | * | ||
| 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 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include QMK_KEYBOARD_H | ||
| 17 | |||
| 18 | enum layers { | ||
| 19 | _BL0, | ||
| 20 | _BL1, | ||
| 21 | _FL, | ||
| 22 | _MS | ||
| 23 | }; | ||
| 24 | |||
| 25 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
| 26 | [_BL0] = LAYOUT( /* Base layer - Windows key instead of CapsLock, hold ESC for special functions */ | ||
| 27 | LT(_FL,KC_ESC), KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10, KC_F11 , KC_F12 , KC_PSCR, KC_SLCK, KC_PAUS, | ||
| 28 | KC_GRV , KC_1, KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_MINS, KC_EQL , KC_BSPC, KC_INS , KC_HOME, KC_PGUP, KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, | ||
| 29 | KC_TAB , KC_Q, KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL , KC_END , KC_PGDN, KC_P7, KC_P8 , KC_P9 , KC_PPLS, | ||
| 30 | KC_LWIN, KC_A, KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT , KC_P4, KC_P5 , KC_P6 , | ||
| 31 | KC_LSFT, KC_NUBS, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_RSFT, KC_UP , KC_P1, KC_P2 , KC_P3 , KC_PENT, | ||
| 32 | KC_LCTL, KC_LALT, KC_SPC , KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT | ||
| 33 | ), | ||
| 34 | |||
| 35 | [_BL1] = LAYOUT( /* Base layer - standard layout without any special functions */ | ||
| 36 | KC_ESC , KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 , KC_PSCR, KC_SLCK, KC_PAUS, | ||
| 37 | KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_MINS, KC_EQL , KC_BSPC, KC_INS , KC_HOME, KC_PGUP, KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, | ||
| 38 | KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL , KC_END , KC_PGDN, KC_P7, KC_P8 , KC_P9 , KC_PPLS, | ||
| 39 | KC_CAPS, KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT , KC_P4, KC_P5 , KC_P6 , | ||
| 40 | KC_LSFT, KC_NUBS, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_RSFT, KC_UP , KC_P1, KC_P2 , KC_P3 , KC_PENT, | ||
| 41 | KC_LCTL, KC_LALT, KC_SPC , KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT | ||
| 42 | ), | ||
| 43 | |||
| 44 | [_FL] = LAYOUT( /* special functions layer */ | ||
| 45 | // F1: dyn. macro 1 play | ||
| 46 | // F2: dyn. macro 2 play | ||
| 47 | // F3: dyn. macro 1 record | ||
| 48 | // F4: dyn. macro 2 record | ||
| 49 | // F5: dyn. macro record stop | ||
| 50 | // Capslock: CapsLock (really!) | ||
| 51 | // ~: Key Lock | ||
| 52 | // Cursor: Media Pref / Next / Volume Up / Volume Down | ||
| 53 | // Space: Media Play / Pause | ||
| 54 | // m: enter mouse layer | ||
| 55 | _______, DM_PLY1, DM_PLY2, DM_REC1, DM_REC2, DM_RSTP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
| 56 | KC_LOCK, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
| 57 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
| 58 | KC_CAPS, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
| 59 | _______, _______, _______, _______, _______, _______, _______, _______, TG(_MS), _______, _______, _______, _______, KC_VOLU, _______, _______, _______, _______, | ||
| 60 | _______, _______, KC_MPLY, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______ | ||
| 61 | ), | ||
| 62 | |||
| 63 | [_MS] = LAYOUT( /* mouse key layer */ | ||
| 64 | // Cursor: mouse, INS/HOME/PgUp: Mouse Accel, Del, End, PageDn: mouse buttons | ||
| 65 | TG(_MS), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
| 66 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_ACL0, KC_ACL1, KC_ACL2, _______, _______, _______, _______, | ||
| 67 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN1, KC_BTN3, KC_BTN2, _______, _______, _______, _______, | ||
| 68 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
| 69 | _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MS_U, _______, _______, _______, _______, | ||
| 70 | _______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______ | ||
| 71 | ) | ||
| 72 | }; | ||
| 73 | |||
| 74 | void keyboard_post_init_user(void) { | ||
| 75 | // Customise these values to desired behaviour | ||
| 76 | //debug_enable=true; | ||
| 77 | //debug_matrix=true; | ||
| 78 | //debug_keyboard=true; | ||
| 79 | //debug_mouse=true; | ||
| 80 | } | ||
| 81 | |||
| 82 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 83 | // If console is enabled, it will print the matrix position and status of each key pressed | ||
| 84 | dprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); | ||
| 85 | return true; | ||
| 86 | } | ||
diff --git a/keyboards/mschwingen/modelm/led_ffc/rules.mk b/keyboards/mschwingen/modelm/led_ffc/rules.mk new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/keyboards/mschwingen/modelm/led_ffc/rules.mk | |||
| @@ -0,0 +1 @@ | |||
diff --git a/keyboards/mschwingen/modelm/led_wired/rules.mk b/keyboards/mschwingen/modelm/led_wired/rules.mk new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/keyboards/mschwingen/modelm/led_wired/rules.mk | |||
| @@ -0,0 +1 @@ | |||
diff --git a/keyboards/mschwingen/modelm/led_ws2812/rules.mk b/keyboards/mschwingen/modelm/led_ws2812/rules.mk new file mode 100644 index 000000000..424388fd8 --- /dev/null +++ b/keyboards/mschwingen/modelm/led_ws2812/rules.mk | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | # variant for WS2812 LEDs | ||
| 2 | SRC += ws2812.c | ||
diff --git a/keyboards/mschwingen/modelm/matrix.c b/keyboards/mschwingen/modelm/matrix.c new file mode 100644 index 000000000..ef725a61e --- /dev/null +++ b/keyboards/mschwingen/modelm/matrix.c | |||
| @@ -0,0 +1,117 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2020 Michael Schwingen | ||
| 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 <stdint.h> | ||
| 18 | #include <stdbool.h> | ||
| 19 | #include "util.h" | ||
| 20 | #include "matrix.h" | ||
| 21 | #include "debounce.h" | ||
| 22 | #include "quantum.h" | ||
| 23 | #include "spi_master.h" | ||
| 24 | #include "print.h" | ||
| 25 | #include "modelm.h" | ||
| 26 | |||
| 27 | #define DEBUG 0 | ||
| 28 | |||
| 29 | #define SPI_TIMEOUT 100 | ||
| 30 | |||
| 31 | /* Keyboard Matrix Assignments */ | ||
| 32 | static uint16_t row_bits[MATRIX_ROWS] = { | ||
| 33 | 0x4000, 0x8000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0100, 0x0200, | ||
| 34 | 0x0040, 0x0080, 0x0020, 0x0010, 0x0008, 0x0004, 0x0001, 0x0002}; | ||
| 35 | |||
| 36 | static const pin_t col_pins[MATRIX_COLS] = {D1, D4, D7, B4, F7, F6, F5, F4}; | ||
| 37 | |||
| 38 | static void select_col(uint8_t col) { | ||
| 39 | setPinOutput(col_pins[col]); | ||
| 40 | writePinLow(col_pins[col]); | ||
| 41 | } | ||
| 42 | |||
| 43 | static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } | ||
| 44 | |||
| 45 | static void unselect_cols(void) { | ||
| 46 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 47 | setPinInputHigh(col_pins[x]); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | ||
| 52 | uint16_t row_data; | ||
| 53 | bool matrix_changed = false; | ||
| 54 | |||
| 55 | // Select col and wait for col selecton to stabilize | ||
| 56 | select_col(current_col); | ||
| 57 | matrix_io_delay(); | ||
| 58 | |||
| 59 | writePinLow(SR_LOAD_PIN); | ||
| 60 | writePinHigh(SR_LOAD_PIN); | ||
| 61 | |||
| 62 | row_data = spi_read() << 8; | ||
| 63 | row_data |= spi_read(); | ||
| 64 | |||
| 65 | #if DEBUG | ||
| 66 | phex(~row_data); | ||
| 67 | uprint(" "); | ||
| 68 | #endif | ||
| 69 | // For each row... | ||
| 70 | for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { | ||
| 71 | // Store last value of row prior to reading | ||
| 72 | matrix_row_t last_row_value = current_matrix[row_index]; | ||
| 73 | matrix_row_t current_row_value = last_row_value; | ||
| 74 | |||
| 75 | // Check row pin state | ||
| 76 | if ((row_data & row_bits[row_index]) == 0) { | ||
| 77 | // Pin LO, set col bit | ||
| 78 | current_row_value |= (MATRIX_ROW_SHIFTER << current_col); | ||
| 79 | } else { | ||
| 80 | // Pin HI, clear col bit | ||
| 81 | current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); | ||
| 82 | } | ||
| 83 | |||
| 84 | // Determine if the matrix changed state | ||
| 85 | if ((last_row_value != current_row_value)) { | ||
| 86 | matrix_changed = true; | ||
| 87 | current_matrix[row_index] = current_row_value; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | // Unselect col | ||
| 92 | unselect_col(current_col); | ||
| 93 | |||
| 94 | return matrix_changed; | ||
| 95 | } | ||
| 96 | |||
| 97 | void matrix_init_custom(void) { | ||
| 98 | unselect_cols(); | ||
| 99 | |||
| 100 | // set 4MHz SPI clock | ||
| 101 | SPSR = 0; | ||
| 102 | SPCR = _BV(SPE) | _BV(MSTR) | _BV(CPOL); | ||
| 103 | } | ||
| 104 | |||
| 105 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
| 106 | bool changed = false; | ||
| 107 | |||
| 108 | #if DEBUG | ||
| 109 | uprint("\r\nScan: "); | ||
| 110 | #endif | ||
| 111 | // Set col, read rows | ||
| 112 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | ||
| 113 | changed |= read_rows_on_col(current_matrix, current_col); | ||
| 114 | } | ||
| 115 | update_layer_leds(); | ||
| 116 | return changed; | ||
| 117 | } | ||
diff --git a/keyboards/mschwingen/modelm/modelm.c b/keyboards/mschwingen/modelm/modelm.c new file mode 100644 index 000000000..5756a9517 --- /dev/null +++ b/keyboards/mschwingen/modelm/modelm.c | |||
| @@ -0,0 +1,214 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2020 Michael Schwingen | ||
| 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 <util/delay.h> | ||
| 18 | #include "modelm.h" | ||
| 19 | #include "uart.h" | ||
| 20 | #include "print.h" | ||
| 21 | #include "sendchar.h" | ||
| 22 | #include "ws2812.h" | ||
| 23 | #include "modelm.h" | ||
| 24 | #include "sleep_led.h" | ||
| 25 | |||
| 26 | #ifdef UART_DEBUG | ||
| 27 | # undef sendchar | ||
| 28 | static int8_t capture_sendchar(uint8_t c) { | ||
| 29 | // sendchar(c); | ||
| 30 | uart_putchar(c); | ||
| 31 | return 0; | ||
| 32 | } | ||
| 33 | #endif | ||
| 34 | |||
| 35 | static uint16_t blink_cycle_timer; | ||
| 36 | static bool blink_state = false; | ||
| 37 | static uint8_t isRecording = 0; | ||
| 38 | |||
| 39 | #ifdef KEYBOARD_mschwingen_modelm_led_ws2812 | ||
| 40 | # if RGBLED_NUM < 3 | ||
| 41 | # error we need at least 3 RGB LEDs! | ||
| 42 | # endif | ||
| 43 | static cRGB led[RGBLED_NUM] = {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}}; | ||
| 44 | |||
| 45 | # define BRIGHT 32 | ||
| 46 | # define DIM 6 | ||
| 47 | |||
| 48 | static const cRGB black = {.r = 0, .g = 0, .b = 0}; | ||
| 49 | |||
| 50 | static const cRGB green = {.r = 0, .g = BRIGHT, .b = 0}; | ||
| 51 | static const cRGB lgreen = {.r = 0, .g = DIM, .b = 0}; | ||
| 52 | |||
| 53 | static const cRGB red = {.r = BRIGHT, .g = 0, .b = 0}; | ||
| 54 | static const cRGB lred = {.r = DIM, .g = 0, .b = 0}; | ||
| 55 | |||
| 56 | static const cRGB blue = {.r = 0, .g = 0, .b = BRIGHT}; | ||
| 57 | static const cRGB lblue = {.r = 0, .g = 0, .b = DIM}; | ||
| 58 | |||
| 59 | static const cRGB turq = {.r = 0, .g = BRIGHT, .b = BRIGHT}; | ||
| 60 | static const cRGB lturq = {.r = 0, .g = DIM, .b = DIM}; | ||
| 61 | |||
| 62 | static const cRGB white = {.r = BRIGHT, .g = BRIGHT, .b = BRIGHT}; | ||
| 63 | |||
| 64 | static led_t led_state; | ||
| 65 | static uint8_t layer; | ||
| 66 | static uint8_t default_layer; | ||
| 67 | #endif | ||
| 68 | |||
| 69 | // we need our own sleep_led_* implementation to get callbacks on USB | ||
| 70 | // suspend/resume in order to completely turn off WS2812 LEDs | ||
| 71 | static bool suspend_active = false; | ||
| 72 | void sleep_led_init(void) {} | ||
| 73 | |||
| 74 | void sleep_led_toggle(void) {} | ||
| 75 | |||
| 76 | void sleep_led_disable(void) { | ||
| 77 | suspend_active = false; | ||
| 78 | writePinHigh(QMK_LED); | ||
| 79 | } | ||
| 80 | |||
| 81 | void sleep_led_enable(void) { | ||
| 82 | suspend_active = true; | ||
| 83 | writePinLow(QMK_LED); | ||
| 84 | #ifdef KEYBOARD_mschwingen_modelm_led_ws2812 | ||
| 85 | led[0] = black; | ||
| 86 | led[1] = black; | ||
| 87 | led[2] = black; | ||
| 88 | ws2812_setleds(led, RGBLED_NUM); | ||
| 89 | #endif | ||
| 90 | } | ||
| 91 | |||
| 92 | void keyboard_pre_init_kb(void) { | ||
| 93 | #ifdef KEYBOARD_mschwingen_modelm_led_ws2812 | ||
| 94 | ws2812_setleds(led, RGBLED_NUM); | ||
| 95 | #else | ||
| 96 | /* Set status LEDs pins to output and Low (on) */ | ||
| 97 | setPinOutput(MODELM_LED_CAPSLOCK); | ||
| 98 | setPinOutput(MODELM_LED_SCROLLOCK); | ||
| 99 | setPinOutput(MODELM_LED_NUMLOCK); | ||
| 100 | writePinLow(MODELM_LED_CAPSLOCK); | ||
| 101 | writePinLow(MODELM_LED_SCROLLOCK); | ||
| 102 | writePinLow(MODELM_LED_NUMLOCK); | ||
| 103 | #endif | ||
| 104 | setPinOutput(QMK_LED); | ||
| 105 | writePinHigh(QMK_LED); | ||
| 106 | _delay_ms(50); | ||
| 107 | #ifdef UART_DEBUG | ||
| 108 | uart_init(115200); | ||
| 109 | print_set_sendchar(capture_sendchar); | ||
| 110 | uprintf("\r\nHello world!\r\n"); | ||
| 111 | #endif | ||
| 112 | |||
| 113 | setPinOutput(SR_LOAD_PIN); | ||
| 114 | setPinOutput(SR_CLK_PIN); | ||
| 115 | setPinOutput(SR_DOUT_PIN); // MOSI - unused | ||
| 116 | writePinLow(SR_CLK_PIN); | ||
| 117 | } | ||
| 118 | |||
| 119 | #ifdef KEYBOARD_mschwingen_modelm_led_ws2812 | ||
| 120 | static void led_update_rgb(void) { | ||
| 121 | if (isRecording && blink_state) { | ||
| 122 | led[0] = white; | ||
| 123 | } else { | ||
| 124 | switch (default_layer) { | ||
| 125 | case 0: | ||
| 126 | led[0] = led_state.num_lock ? blue : lblue; | ||
| 127 | break; | ||
| 128 | case 1: | ||
| 129 | led[0] = led_state.num_lock ? green : black; | ||
| 130 | break; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | led[1] = led_state.caps_lock ? green : black; | ||
| 135 | |||
| 136 | switch (layer) { | ||
| 137 | case 0: | ||
| 138 | case 1: | ||
| 139 | default: | ||
| 140 | led[2] = led_state.scroll_lock ? green : black; | ||
| 141 | break; | ||
| 142 | case 2: | ||
| 143 | led[2] = led_state.scroll_lock ? red : lred; | ||
| 144 | break; | ||
| 145 | case 3: | ||
| 146 | led[2] = led_state.scroll_lock ? turq : lturq; | ||
| 147 | break; | ||
| 148 | } | ||
| 149 | if (!suspend_active) { | ||
| 150 | ws2812_setleds(led, RGBLED_NUM); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | bool led_update_kb(led_t state) { | ||
| 155 | dprintf("LED Update: %d %d %d", led_state.num_lock, led_state.caps_lock, led_state.scroll_lock); | ||
| 156 | led_state = state; | ||
| 157 | led_update_rgb(); | ||
| 158 | |||
| 159 | return true; | ||
| 160 | } | ||
| 161 | |||
| 162 | void update_layer_leds(void) { | ||
| 163 | static uint8_t old_layer = 255; | ||
| 164 | static uint8_t old_default_layer = 255; | ||
| 165 | |||
| 166 | layer = biton32(layer_state); | ||
| 167 | default_layer = biton32(default_layer_state); | ||
| 168 | |||
| 169 | if (isRecording && timer_elapsed(blink_cycle_timer) > 150) { | ||
| 170 | blink_state = !blink_state; | ||
| 171 | blink_cycle_timer = timer_read(); | ||
| 172 | old_layer = 255; // fallthrough next check | ||
| 173 | } | ||
| 174 | |||
| 175 | if (layer == old_layer && default_layer == old_default_layer) { | ||
| 176 | return; | ||
| 177 | } | ||
| 178 | old_layer = layer; | ||
| 179 | old_default_layer = default_layer; | ||
| 180 | dprintf("Layer change: %d %d", default_layer, layer); | ||
| 181 | led_update_rgb(); | ||
| 182 | } | ||
| 183 | |||
| 184 | /*****************************************************************************/ | ||
| 185 | #else // classic LEDs on GPIO | ||
| 186 | bool led_update_kb(led_t led_state) { | ||
| 187 | dprintf("LED Update: %d %d %d", led_state.num_lock, led_state.caps_lock, led_state.scroll_lock); | ||
| 188 | |||
| 189 | if (led_update_user(led_state)) { | ||
| 190 | if (!isRecording) writePin(MODELM_LED_NUMLOCK, !led_state.num_lock); | ||
| 191 | writePin(MODELM_LED_CAPSLOCK, !led_state.caps_lock); | ||
| 192 | writePin(MODELM_LED_SCROLLOCK, !led_state.scroll_lock); | ||
| 193 | } | ||
| 194 | return true; | ||
| 195 | } | ||
| 196 | |||
| 197 | void update_layer_leds(void) { | ||
| 198 | if (isRecording && timer_elapsed(blink_cycle_timer) > 150) { | ||
| 199 | blink_state = !blink_state; | ||
| 200 | blink_cycle_timer = timer_read(); | ||
| 201 | writePin(MODELM_LED_NUMLOCK, blink_state); | ||
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | #endif | ||
| 206 | |||
| 207 | void dynamic_macro_record_start_user(void) { | ||
| 208 | isRecording++; | ||
| 209 | blink_cycle_timer = timer_read(); | ||
| 210 | } | ||
| 211 | |||
| 212 | void dynamic_macro_record_end_user(int8_t direction) { | ||
| 213 | if (isRecording) isRecording--; | ||
| 214 | } | ||
diff --git a/keyboards/mschwingen/modelm/modelm.h b/keyboards/mschwingen/modelm/modelm.h new file mode 100644 index 000000000..04b6b6112 --- /dev/null +++ b/keyboards/mschwingen/modelm/modelm.h | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2020 Michael Schwingen | ||
| 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 | #pragma once | ||
| 19 | |||
| 20 | extern void update_layer_leds(void); | ||
| 21 | |||
| 22 | #include "quantum.h" | ||
| 23 | |||
| 24 | /* This a shortcut to help you visually see your layout. | ||
| 25 | * The first section contains "names" for physical keys of the keyboard | ||
| 26 | * and defines their position on the board. | ||
| 27 | * The second section defines position of the keys on the switch matrix | ||
| 28 | * (where COLUMNS and ROWS crosses). */ | ||
| 29 | |||
| 30 | /* universla layout for both 101 and 102-key versions */ | ||
| 31 | #define LAYOUT( \ | ||
| 32 | K5A, K5B, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K5O, K5P, \ | ||
| 33 | \ | ||
| 34 | K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4O, K4P, K4Q, K4R, K4S, K4T, K4U, \ | ||
| 35 | K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3M, K3N, K3O, K3P, K3Q, K3R, K3S, K3T, K3U, \ | ||
| 36 | K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2M, K2N, K2O, K2P, K2Q, \ | ||
| 37 | K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, K1I, K1J, K1K, K1L, K1M, K1N, K1O, K1P, K1Q, K1R, \ | ||
| 38 | K0A, K0B, K0C, K0D, K0E, K0F, K0G, K0H, K0I, K0J \ | ||
| 39 | ) \ | ||
| 40 | {/* COL0 ............ COL7 */ \ | ||
| 41 | { K0D , KC_NO, KC_NO, K5O , K5N , KC_NO, KC_NO, K0B }, /* ROW0 */ \ | ||
| 42 | { K0F , K5P , K1R , K3U , K3P , K4P , KC_NO, K1N }, \ | ||
| 43 | { K4U , K4T , K1Q , K3T , K3Q , K4Q , K2Q , K0J }, \ | ||
| 44 | { K0H , K4S , K1P , K3S , K5M , K4O , K2P , K0I }, \ | ||
| 45 | { K0G , K4R , K1O , K3R , K5L , K3O , K2O , KC_NO }, \ | ||
| 46 | { K1L , K2M , K2K , K3K , K4K , K4L , K3L , K2L }, \ | ||
| 47 | { KC_NO, K1K , K2J , K3J , K4J , K5I , K5H , KC_NO }, \ | ||
| 48 | { KC_NO, K1J , K2I , K3I , K4I , K4M , K3M , K5G }, \ | ||
| 49 | { K1H , K1I , K2H , K3H , K4H , K4G , K3G , K2G }, \ | ||
| 50 | { K0C , K2N , K3N , KC_NO, K5K , K5J , K4N , K5F }, \ | ||
| 51 | { K1G , K1F , K2E , K3E , K4E , K4F , K3F , K2F }, \ | ||
| 52 | { KC_NO, K1E , K2D , K3D , K4D , K5C , K5D , K5E }, \ | ||
| 53 | { KC_NO, K1D , K2C , K3C , K4C , K5B , K2A , K1B }, \ | ||
| 54 | { KC_NO, K1C , K2B , K3B , K4B , K4A , K3A , K5A }, \ | ||
| 55 | { KC_NO, K1M , KC_NO, KC_NO, KC_NO, KC_NO, K1A , KC_NO }, \ | ||
| 56 | { KC_NO, K0E , KC_NO, KC_NO, KC_NO, K0A , KC_NO, KC_NO }, /* ROW15 */ \ | ||
| 57 | } | ||
| 58 | |||
diff --git a/keyboards/mschwingen/modelm/rules.mk b/keyboards/mschwingen/modelm/rules.mk new file mode 100644 index 000000000..f3af26eee --- /dev/null +++ b/keyboards/mschwingen/modelm/rules.mk | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | # MCU name | ||
| 2 | MCU = atmega32u4 | ||
| 3 | |||
| 4 | # Bootloader selection | ||
| 5 | BOOTLOADER = lufa-dfu | ||
| 6 | |||
| 7 | # Build Options | ||
| 8 | # change yes to no to disable | ||
| 9 | # | ||
| 10 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration | ||
| 11 | MOUSEKEY_ENABLE = yes # Mouse keys | ||
| 12 | EXTRAKEY_ENABLE = yes # Audio control and System control | ||
| 13 | CONSOLE_ENABLE = yes # Console for debug | ||
| 14 | COMMAND_ENABLE = yes # Commands for debug and configuration | ||
| 15 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | ||
| 16 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | ||
| 17 | # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | ||
| 18 | NKRO_ENABLE = no # USB Nkey Rollover | ||
| 19 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | ||
| 20 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow | ||
| 21 | BLUETOOTH_ENABLE = no # Enable Bluetooth | ||
| 22 | AUDIO_ENABLE = no # Audio output | ||
| 23 | |||
| 24 | CUSTOM_MATRIX = lite | ||
| 25 | KEY_LOCK_ENABLE = yes | ||
| 26 | |||
| 27 | DYNAMIC_MACRO_ENABLE = yes | ||
| 28 | |||
| 29 | UART_DEBUG = no | ||
| 30 | |||
| 31 | SRC += matrix.c | ||
| 32 | QUANTUM_LIB_SRC += $(COMMON_DIR)/uart.c \ | ||
| 33 | spi_master.c | ||
| 34 | |||
| 35 | OPT_DEFS += -DSLEEP_LED_ENABLE # we need our own sleep callbacks to turn of WS2812 LEDs | ||
| 36 | |||
| 37 | LTO_ENABLE = yes | ||
| 38 | |||
| 39 | ifeq ($(strip $(UART_DEBUG)), yes) | ||
| 40 | OPT_DEFS += -DUART_DEBUG | ||
| 41 | endif | ||
| 42 | |||
| 43 | DEFAULT_FOLDER = mschwingen/modelm/led_wired | ||
