forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Keyboard] add support for ModelM USB board (qmk#9846)
* add support for ModelM USB board * EMI improvement: remove unnecessary toggling of MOSI pin * address review comments * Update keyboards/mschwingen/modelm/rules.mk Co-authored-by: James Young <[email protected]> * Update keyboards/mschwingen/modelm/rules.mk Co-authored-by: James Young <[email protected]> * Update keyboards/mschwingen/modelm/config.h Co-authored-by: James Young <[email protected]> * Update keyboards/mschwingen/modelm/config.h Co-authored-by: James Young <[email protected]> * Update keyboards/mschwingen/modelm/rules.mk Co-authored-by: Drashna Jaelre <[email protected]> * Update keyboards/mschwingen/modelm/keymaps/default/keymap.c Co-authored-by: Drashna Jaelre <[email protected]> * update printf usage * add comment * EMI improvement: remove unnecessary toggling of MOSI signal * remove trailing space * use shorter macros as suggested in review by noroadsleft, re-format table to line up columns * Update keyboards/mschwingen/modelm/config.h Co-authored-by: Ryan <[email protected]> * Update keyboards/mschwingen/modelm/rules.mk Co-authored-by: Ryan <[email protected]> * Update keyboards/mschwingen/modelm/rules.mk Co-authored-by: Ryan <[email protected]> * Update keyboards/mschwingen/modelm/rules.mk Co-authored-by: Ryan <[email protected]> * Update keyboards/mschwingen/modelm/README.md Co-authored-by: Ryan <[email protected]> * Update keyboards/mschwingen/modelm/README.md Co-authored-by: Ryan <[email protected]> * Apply suggestions from code review use spi_read from core insteads of our own copy Co-authored-by: Ryan <[email protected]> * include spi_master.c to use spi_read() * Update keyboards/mschwingen/modelm/README.md Co-authored-by: James Young <[email protected]> * Apply suggestions from code review: correct indenting in keymap Co-authored-by: James Young <[email protected]> * Apply suggestions from code review use automatic variant defines from makefile instead of defining our own Co-authored-by: Drashna Jaelre <[email protected]> * Update keyboards/mschwingen/modelm/rules.mk: use QUANTUM_LIB_SRC for uart.c Co-authored-by: Drashna Jaelre <[email protected]> Co-authored-by: Michael Schwingen <[email protected]> Co-authored-by: James Young <[email protected]> Co-authored-by: Drashna Jaelre <[email protected]> Co-authored-by: Ryan <[email protected]>
- Loading branch information
Showing
10 changed files
with
638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# atmega32U4 board for IBM Model M | ||
|
||
![modelm](https://raw.githubusercontent.com/mschwingen/hardware/master/modelm-usb/images/PCB.jpg) | ||
|
||
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). | ||
|
||
* Keyboard Maintainer: [Michael Schwingen](https://github.com/mschwingen/) | ||
* Hardware Supported: [Model M USB PCB](https://github.com/mschwingen/hardware/tree/master/modelm-usb) | ||
* Hardware Availability: need to build your own. | ||
|
||
Make example for this keyboard (after setting up your build environment), run one of: | ||
|
||
make mschwingen/modelm/led_wired:default | ||
make mschwingen/modelm/led_ffc:default | ||
make mschwingen/modelm/led_ws2812:default | ||
|
||
flash: | ||
|
||
make mschwingen/modelm/led_wired:default:flash | ||
make mschwingen/modelm/led_ffc:default:flash | ||
make mschwingen/modelm/led_ws2812:default:flash | ||
|
||
Bootloader: do not use the QMK bootloader, use the bootloader from [here](https://github.com/mschwingen/modelm-lufa-bootloader) | ||
|
||
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2020 Michael Schwingen | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "config_common.h" | ||
|
||
/* USB Device descriptor parameter */ | ||
#define VENDOR_ID 0xFEED | ||
#define PRODUCT_ID 0x558E | ||
#define DEVICE_VER 0x0001 | ||
#define MANUFACTURER mschwingen | ||
#define PRODUCT IBM Model M 101/102 | ||
|
||
/* key matrix size */ | ||
#define MATRIX_ROWS 16 | ||
#define MATRIX_COLS 8 | ||
|
||
/* pins for external shift registers */ | ||
#define SR_LOAD_PIN B0 | ||
#define SR_CLK_PIN B1 | ||
#define SR_DIN_PIN B3 | ||
#define SR_DOUT_PIN B2 | ||
|
||
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed (5 is default) */ | ||
#define DEBOUNCE 5 | ||
|
||
/* | ||
* Feature disable options | ||
* These options are also useful to firmware size reduction. | ||
*/ | ||
|
||
/* disable debug print */ | ||
//#define NO_DEBUG | ||
|
||
/* disable print */ | ||
//#define NO_PRINT | ||
#define NORMAL_PRINT | ||
//#define USER_PRINT | ||
|
||
|
||
/* disable action features */ | ||
//#define NO_ACTION_LAYER | ||
//#define NO_ACTION_TAPPING | ||
//#define NO_ACTION_ONESHOT | ||
//#define NO_ACTION_MACRO | ||
//#define NO_ACTION_FUNCTION | ||
|
||
//#define DEBUG_MATRIX_SCAN_RATE | ||
#define DYNAMIC_MACRO_NO_NESTING | ||
|
||
#define QMK_LED E6 | ||
|
||
#define MODELM_LED1 B5 | ||
#define MODELM_LED2 B6 | ||
#define MODELM_LED3 D0 | ||
|
||
#if defined(KEYBOARD_mschwingen_modelm_led_wired) | ||
# define MODELM_LED_CAPSLOCK MODELM_LED1 | ||
# define MODELM_LED_SCROLLOCK MODELM_LED2 | ||
# define MODELM_LED_NUMLOCK MODELM_LED3 | ||
#elif defined(KEYBOARD_mschwingen_modelm_led_ffc) | ||
# define MODELM_LED_CAPSLOCK MODELM_LED2 | ||
# define MODELM_LED_SCROLLOCK MODELM_LED3 | ||
# define MODELM_LED_NUMLOCK MODELM_LED1 | ||
#elif defined(KEYBOARD_mschwingen_modelm_led_ws2812) | ||
#else | ||
# error one of MODELM_LEDS_FFC, MODELM_LEDS_WIRED or MODELM_LEDS_WS2812 must be set! | ||
#endif | ||
|
||
// 3* WS2812 LEDs instead of singlecolor GPIO LEDs | ||
#define RGB_DI_PIN B6 | ||
#define RGBLED_NUM 3 | ||
|
||
// disabled, needs PCB patch. | ||
//#define C6_AUDIO | ||
//#define NO_MUSIC_MODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Copyright 2019 ashpil | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include QMK_KEYBOARD_H | ||
|
||
enum layers { | ||
_BL0, | ||
_BL1, | ||
_FL, | ||
_MS | ||
}; | ||
|
||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
[_BL0] = LAYOUT( /* Base layer - Windows key instead of CapsLock, hold ESC for special functions */ | ||
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, | ||
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, | ||
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, | ||
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 , | ||
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, | ||
KC_LCTL, KC_LALT, KC_SPC , KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT | ||
), | ||
|
||
[_BL1] = LAYOUT( /* Base layer - standard layout without any special functions */ | ||
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, | ||
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, | ||
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, | ||
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 , | ||
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, | ||
KC_LCTL, KC_LALT, KC_SPC , KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT | ||
), | ||
|
||
[_FL] = LAYOUT( /* special functions layer */ | ||
// F1: dyn. macro 1 play | ||
// F2: dyn. macro 2 play | ||
// F3: dyn. macro 1 record | ||
// F4: dyn. macro 2 record | ||
// F5: dyn. macro record stop | ||
// Capslock: CapsLock (really!) | ||
// ~: Key Lock | ||
// Cursor: Media Pref / Next / Volume Up / Volume Down | ||
// Space: Media Play / Pause | ||
// m: enter mouse layer | ||
_______, DM_PLY1, DM_PLY2, DM_REC1, DM_REC2, DM_RSTP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
KC_LOCK, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
KC_CAPS, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
_______, _______, _______, _______, _______, _______, _______, _______, TG(_MS), _______, _______, _______, _______, KC_VOLU, _______, _______, _______, _______, | ||
_______, _______, KC_MPLY, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT, _______, _______ | ||
), | ||
|
||
[_MS] = LAYOUT( /* mouse key layer */ | ||
// Cursor: mouse, INS/HOME/PgUp: Mouse Accel, Del, End, PageDn: mouse buttons | ||
TG(_MS), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_ACL0, KC_ACL1, KC_ACL2, _______, _______, _______, _______, | ||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN1, KC_BTN3, KC_BTN2, _______, _______, _______, _______, | ||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, | ||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MS_U, _______, _______, _______, _______, | ||
_______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______ | ||
) | ||
}; | ||
|
||
void keyboard_post_init_user(void) { | ||
// Customise these values to desired behaviour | ||
//debug_enable=true; | ||
//debug_matrix=true; | ||
//debug_keyboard=true; | ||
//debug_mouse=true; | ||
} | ||
|
||
bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
// If console is enabled, it will print the matrix position and status of each key pressed | ||
dprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# variant for WS2812 LEDs | ||
SRC += ws2812.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright 2020 Michael Schwingen | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include "util.h" | ||
#include "matrix.h" | ||
#include "debounce.h" | ||
#include "quantum.h" | ||
#include "spi_master.h" | ||
#include "print.h" | ||
#include "modelm.h" | ||
|
||
#define DEBUG 0 | ||
|
||
#define SPI_TIMEOUT 100 | ||
|
||
/* Keyboard Matrix Assignments */ | ||
static uint16_t row_bits[MATRIX_ROWS] = { | ||
0x4000, 0x8000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0100, 0x0200, | ||
0x0040, 0x0080, 0x0020, 0x0010, 0x0008, 0x0004, 0x0001, 0x0002}; | ||
|
||
static const pin_t col_pins[MATRIX_COLS] = {D1, D4, D7, B4, F7, F6, F5, F4}; | ||
|
||
static void select_col(uint8_t col) { | ||
setPinOutput(col_pins[col]); | ||
writePinLow(col_pins[col]); | ||
} | ||
|
||
static void unselect_col(uint8_t col) { setPinInputHigh(col_pins[col]); } | ||
|
||
static void unselect_cols(void) { | ||
for (uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
setPinInputHigh(col_pins[x]); | ||
} | ||
} | ||
|
||
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | ||
uint16_t row_data; | ||
bool matrix_changed = false; | ||
|
||
// Select col and wait for col selecton to stabilize | ||
select_col(current_col); | ||
matrix_io_delay(); | ||
|
||
writePinLow(SR_LOAD_PIN); | ||
writePinHigh(SR_LOAD_PIN); | ||
|
||
row_data = spi_read() << 8; | ||
row_data |= spi_read(); | ||
|
||
#if DEBUG | ||
phex(~row_data); | ||
uprint(" "); | ||
#endif | ||
// For each row... | ||
for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { | ||
// Store last value of row prior to reading | ||
matrix_row_t last_row_value = current_matrix[row_index]; | ||
matrix_row_t current_row_value = last_row_value; | ||
|
||
// Check row pin state | ||
if ((row_data & row_bits[row_index]) == 0) { | ||
// Pin LO, set col bit | ||
current_row_value |= (MATRIX_ROW_SHIFTER << current_col); | ||
} else { | ||
// Pin HI, clear col bit | ||
current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); | ||
} | ||
|
||
// Determine if the matrix changed state | ||
if ((last_row_value != current_row_value)) { | ||
matrix_changed = true; | ||
current_matrix[row_index] = current_row_value; | ||
} | ||
} | ||
|
||
// Unselect col | ||
unselect_col(current_col); | ||
|
||
return matrix_changed; | ||
} | ||
|
||
void matrix_init_custom(void) { | ||
unselect_cols(); | ||
|
||
// set 4MHz SPI clock | ||
SPSR = 0; | ||
SPCR = _BV(SPE) | _BV(MSTR) | _BV(CPOL); | ||
} | ||
|
||
bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
bool changed = false; | ||
|
||
#if DEBUG | ||
uprint("\r\nScan: "); | ||
#endif | ||
// Set col, read rows | ||
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | ||
changed |= read_rows_on_col(current_matrix, current_col); | ||
} | ||
update_layer_leds(); | ||
return changed; | ||
} |
Oops, something went wrong.