commit a40e674406d6d33ddc3a872b8fb08b84d851b79c Author: Daniel Flanagan Date: Fri Dec 20 13:39:50 2019 -0600 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0ec985c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = false +indent_style = tab +indent_size = 2 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..afd860b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "planck/lib/qmk_firmware"] + path = planck/lib/qmk_firmware + url = https://github.com/lytedev/qmk_firmware.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..075b0fc --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Daniel Flanagan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/planck/Makefile b/planck/Makefile new file mode 100644 index 0000000..73e1afe --- /dev/null +++ b/planck/Makefile @@ -0,0 +1,22 @@ +.PHONY: default +default: build + +.PHONY: build +build: submodules + @mkdir -p lib/qmk_firmware/keyboards/planck/keymaps/lytedev/ + @cp -r src/* lib/qmk_firmware/keyboards/planck/keymaps/lytedev/ + @pushd lib/qmk_firmware/ && make planck/rev2:lytedev + +.PHONY: flash +flash: build + @pushd lib/qmk_firmware/ && sudo make planck/rev2:lytedev:dfu + +.PHONY: clean +clean: + @pushd lib/qmk_firmware/ && make clean + +.PHONY: submodules +submodules: + git submodule init + git submodule update + @pushd lib/qmk_firmware/ && make git-submodule diff --git a/planck/lib/qmk_firmware b/planck/lib/qmk_firmware new file mode 160000 index 0000000..9d9d68c --- /dev/null +++ b/planck/lib/qmk_firmware @@ -0,0 +1 @@ +Subproject commit 9d9d68c100fb2af4f03aa717c5ebc38be72872ae diff --git a/planck/readme.md b/planck/readme.md new file mode 100644 index 0000000..174c179 --- /dev/null +++ b/planck/readme.md @@ -0,0 +1,23 @@ +# planck + ++ **TODO**: Picture of keyboard. + +This contains my planck [`qmk_firmware`][0]. + +# Dependencies + +* See [`qmk_firmware`][0]. + +# Flashing + +``` +make flash +``` + +# Modifying + ++ Edit files in `src/` (particularly `keymap.c`). ++ Flash using previous instructions. + + +[0]: https://github.com/lytedev/qmk_firmware/ diff --git a/planck/src/keymap.c b/planck/src/keymap.c new file mode 100644 index 0000000..063da99 --- /dev/null +++ b/planck/src/keymap.c @@ -0,0 +1,307 @@ +#include "planck.h" +#include "action_layer.h" +#include "eeconfig.h" + +#ifdef AUDIO_ENABLE +#include "audio.h" +#endif + +extern keymap_config_t keymap_config; + +#define _QWERTY 0 +#define _COLEMAK 1 +#define _DVORAK 2 +#define _LOWER 3 +#define _RAISE 4 +#define _PLOVER 5 +#define _ADJUST 16 + +#define ESC_CTL LCTL_T(KC_ESC) + +enum planck_keycodes { + QWERTY = SAFE_RANGE, + COLEMAK, + DVORAK, + PLOVER, + LOWER, + RAISE, + BACKLIT, + EXT_PLV +}; + +#define _______ KC_TRNS +#define XXXXXXX KC_NO + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + + /* Qwerty + * ,-----------------------------------------------------------------------------------. + * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | S | D | F | G | H | J | K | L | ; | \" | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ + [_QWERTY] = { + {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, + {ESC_CTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, + {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, + {KC_LCTL, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + }, + + /* Colemak + * ,-----------------------------------------------------------------------------------. + * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | R | S | T | D | H | N | E | I | O | \" | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ + [_COLEMAK] = { + {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, + {ESC_CTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, + {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, + {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + }, + + /* Dvorak + * ,-----------------------------------------------------------------------------------. + * | Tab | \" | , | . | P | Y | F | G | C | R | L | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Esc | A | O | E | U | I | D | H | T | N | S | / | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right | + * `-----------------------------------------------------------------------------------' + */ + [_DVORAK] = { + {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, + {ESC_CTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, + {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, + {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} + }, + + /* Lower + * ,-----------------------------------------------------------------------------------. + * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ + [_LOWER] = { + {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC}, + {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE}, + {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),_______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END } + }, + + /* Raise + * ,-----------------------------------------------------------------------------------. + * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | |Enter | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | Next | Vol- | Vol+ | Play | + * `-----------------------------------------------------------------------------------' + */ + [_RAISE] = { + {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL }, + {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS}, + {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_NUBS, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY} + }, + + /* Plover layer (http://opensteno.org) + * ,-----------------------------------------------------------------------------------. + * | # | # | # | # | # | # | # | # | # | # | # | # | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | S | T | P | H | * | * | F | P | L | T | D | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * |TogOut| S | K | W | R | * | * | R | B | G | S | Z | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | Exit | | | A | O | | E | U | | | | + * `-----------------------------------------------------------------------------------' + */ + + [_PLOVER] = { + {KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 }, + {XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC}, + {XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, + {EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX} + }, + + /* Adjust (Lower + Raise) + * ,-----------------------------------------------------------------------------------. + * | | Reset| | | | | | | | | | Del | + * |------+------+------+------+------+-------------+------+------+------+------+------| + * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| | + * |------+------+------+------+------+------|------+------+------+------+------+------| + * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | | + * |------+------+------+------+------+------+------+------+------+------+------+------| + * | | | | | | | | | | | | + * `-----------------------------------------------------------------------------------' + */ + [_ADJUST] = { + {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, + {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______}, + {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______}, + {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} + } + + +}; + +#ifdef AUDIO_ENABLE + +float tone_startup[][2] = SONG(STARTUP_SOUND); +float tone_qwerty[][2] = SONG(QWERTY_SOUND); +float tone_dvorak[][2] = SONG(DVORAK_SOUND); +float tone_colemak[][2] = SONG(COLEMAK_SOUND); +float tone_plover[][2] = SONG(PLOVER_SOUND); +float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND); +float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); + +float tone_goodbye[][2] = SONG(GOODBYE_SOUND); +#endif + + +void persistant_default_layer_set(uint16_t default_layer) { + eeconfig_update_default_layer(default_layer); + default_layer_set(default_layer); +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case QWERTY: + if (record->event.pressed) { +#ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_qwerty, false, 0); +#endif + persistant_default_layer_set(1UL<<_QWERTY); + } + break; + return false; + case COLEMAK: + if (record->event.pressed) { +#ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_colemak, false, 0); +#endif + persistant_default_layer_set(1UL<<_COLEMAK); + } + break; + return false; + case DVORAK: + if (record->event.pressed) { +#ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_dvorak, false, 0); +#endif + persistant_default_layer_set(1UL<<_DVORAK); + } + break; + return false; + case LOWER: + if (record->event.pressed) { + layer_on(_LOWER); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } else { + layer_off(_LOWER); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } + break; + return false; + case RAISE: + if (record->event.pressed) { + layer_on(_RAISE); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } else { + layer_off(_RAISE); + update_tri_layer(_LOWER, _RAISE, _ADJUST); + } + break; + return false; + case BACKLIT: + if (record->event.pressed) { + register_code(KC_RSFT); +#ifdef BACKLIGHT_ENABLE + backlight_step(); +#endif + } else { + unregister_code(KC_RSFT); + } + break; + return false; + case PLOVER: + if (record->event.pressed) { +#ifdef AUDIO_ENABLE + stop_all_notes(); + PLAY_NOTE_ARRAY(tone_plover, false, 0); +#endif + layer_off(_RAISE); + layer_off(_LOWER); + layer_off(_ADJUST); + layer_on(_PLOVER); + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + keymap_config.raw = eeconfig_read_keymap(); + keymap_config.nkro = 1; + eeconfig_update_keymap(keymap_config.raw); + } + break; + return false; + case EXT_PLV: + if (record->event.pressed) { +#ifdef AUDIO_ENABLE + PLAY_NOTE_ARRAY(tone_plover_gb, false, 0); +#endif + layer_off(_PLOVER); + } + break; + return false; + } + return true; +} + +void matrix_init_user(void) { +#ifdef AUDIO_ENABLE + startup_user(); +#endif +} + +#ifdef AUDIO_ENABLE +void startup_user() +{ + _delay_ms(20); // gets rid of tick + PLAY_NOTE_ARRAY(tone_startup, false, 0); +} + +void shutdown_user() +{ + PLAY_NOTE_ARRAY(tone_goodbye, false, 0); + _delay_ms(150); + stop_all_notes(); +} + +void music_on_user(void) +{ + music_scale_user(); +} + +void music_scale_user(void) +{ + PLAY_NOTE_ARRAY(music_scale, false, 0); +} +#endif diff --git a/planck/src/rules.mk b/planck/src/rules.mk new file mode 100644 index 0000000..2d579af --- /dev/null +++ b/planck/src/rules.mk @@ -0,0 +1,13 @@ +BOOTMAGIC_ENABLE = no +MOUSEKEY_ENABLE = no +EXTRAKEY_ENABLE = yes +CONSOLE_ENABLE = no +COMMAND_ENABLE = no +NKRO_ENABLE = yes +BACKLIGHT_ENABLE = no +MIDI_ENABLE = no +AUDIO_ENABLE = yes +UNICODE_ENABLE = no +BLUETOOTH_ENABLE = no +RGBLIGHT_ENABLE = no +SLEEP_LED_ENABLE = no diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..a07f2e3 --- /dev/null +++ b/readme.md @@ -0,0 +1,4 @@ +# keyboards + ++ [Planck](planck) ++ [Splyte](splyte) diff --git a/splyte/Makefile b/splyte/Makefile new file mode 100644 index 0000000..37203e0 --- /dev/null +++ b/splyte/Makefile @@ -0,0 +1,22 @@ +.PHONY: default +default: build + +.PHONY: build +build: submodules + @mkdir -p ../planck/lib/qmk_firmware/keyboards/handwired/splyte/ + @cp -r src/* ../planck/lib/qmk_firmware/keyboards/handwired/splyte/ + @pushd ../planck/lib/qmk_firmware/ && make handwired/splyte + +.PHONY: submodules +submodules: + git submodule init + git submodule update + @pushd ../planck/lib/qmk_firmware/ && make git-submodule + +.PHONY: flash +flash: build + @pushd ../planck/lib/qmk_firmware/ && make handwired/splyte:avrdude + +.PHONY: clean +clean: + @pushd ../planck/qmk_firmware/ && make clean diff --git a/splyte/src/config.h b/splyte/src/config.h new file mode 100644 index 0000000..d863e2f --- /dev/null +++ b/splyte/src/config.h @@ -0,0 +1,52 @@ +#pragma once + +#include "config_common.h" + +/* USB device identification parameters */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x0000 +#define DEVICE_VER 0x0001 +#define MANUFACTURER lytedev +#define PRODUCT Splyteboard +#define DESCRIPTION "Splyteboard" + +#define MATRIX_ROWS 5 +#define MATRIX_COLS 6 * 2 +// #define COL_EXPANDED { false, false, false, false, false, false, true, true, true, true, true, true} +// #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} + +#define DIODE_DIRECTION ROW2COL +#define UNUSED_PINS + +#define SOFT_SERIAL_PIN D0 + +#define DEBOUNCE 5 + +#define LOCKING_SUPPORT_ENABLE +#define LOCKING_RESYNC_ENABLE + +#define MIDI_ADVANCED +#define MIDI_BASIC + +#define MIDI_TONE_KEYCODE_OCTAVES 5 + +/* +Copyright 2019 Daniel Flanagan + +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 . +*/ + diff --git a/splyte/src/expander.c b/splyte/src/expander.c new file mode 100644 index 0000000..d122e00 --- /dev/null +++ b/splyte/src/expander.c @@ -0,0 +1,104 @@ +#include + +#include "action.h" +#include "twi_master.h" +#include "expander.h" +#include "debug.h" + +static uint8_t expander_status = 0; +static uint8_t expander_input = 0; + +// TODO: grok this code +uint8_t expander_write(uint8_t, uint8_t); +void expander_scan(void); + +void expander_config(void) { + expander_write(EXPANDER_REG_IPOLA, 0xFF); + expander_write(EXPANDER_REG_GPPUA, 0xFF); + expander_write(EXPANDER_REG_IODIRB, 0xFF); +} + +void expander_init(void) { + twi_init(); + expander_scan(); +} + +uint8_t expander_write(uint8_t reg, uint8_t data) { + if (expander_status == 0) return 0; + uint8_t ret; + ret = twi_start(EXPANDER_ADDR | TWI_WRITE); + if (ret) goto stop; + ret = twi_write(reg); + if (ret) goto stop; + ret = twi_write(data); +stop: + twi_stop(); + return ret; +} + +uint8_t expander_read(uint8_t reg, uint8_t *data) { + if (expander_status == 0) return 0; + uint8_t ret; + ret = twi_start(EXPANDER_ADDR | TWI_WRITE); + if (ret) goto stop; + ret = twi_write(reg); + if (ret) goto stop; + ret = twi_rep_start(EXPANDER_ADDR | TWI_READ); + if (ret) goto stop; + *data = twi_read_nak(); +stop: + twi_stop(); + return ret; +} + +void expander_scan(void) { + uint8_t ret = twi_start(EXPANDER_ADDR | TWI_WRITE); + if (ret == 0) { + twi_stop(); + if (expander_status == 0) { + expander_status = 1; + expander_config(); + clear_keyboard(); + } + } + else { + if (expander_status == 1) { + expander_status = 0; + clear_keyboard(); + } + } +} + +void expander_read_cols(void) { + expander_read(EXPANDER_REG_GPIOA, &expander_input); +} + +uint8_t expander_get_col(uint8_t col) { + if (col > (MATRIX_COLS / 2) + 1) { + col++; + } + return expander_input & (1< +#include "matrix.h" + +#define MCP23017 +#define MCP23017_A0 0 +#define MCP23017_A1 0 +#define MCP23017_A2 0 + +#ifdef MCP23017 +#define EXPANDER_ADDR ((0x20|(MCP23017_A0<<0)|(MCP23017_A1<<1)|(MCP23017_A2<<2)) << 1) +enum EXPANDER_REG_BANK0 { + EXPANDER_REG_IODIRA = 0, + EXPANDER_REG_IODIRB, + EXPANDER_REG_IPOLA, + EXPANDER_REG_IPOLB, + EXPANDER_REG_GPINTENA, + EXPANDER_REG_GPINTENB, + EXPANDER_REG_DEFVALA, + EXPANDER_REG_DEFVALB, + EXPANDER_REG_INTCONA, + EXPANDER_REG_INTCONB, + EXPANDER_REG_IOCONA, + EXPANDER_REG_IOCONB, + EXPANDER_REG_GPPUA, + EXPANDER_REG_GPPUB, + EXPANDER_REG_INTFA, + EXPANDER_REG_INTFB, + EXPANDER_REG_INTCAPA, + EXPANDER_REG_INTCAPB, + EXPANDER_REG_GPIOA, + EXPANDER_REG_GPIOB, + EXPANDER_REG_OLATA, + EXPANDER_REG_OLATB +}; +#endif + +void expander_init(void); +void expander_scan(void); +void expander_read_cols(void); +uint8_t expander_get_col(uint8_t col); +matrix_row_t expander_read_row(void); +void expander_unselect_rows(void); +void expander_select_row(uint8_t row); diff --git a/splyte/src/keymaps/default/config.h b/splyte/src/keymaps/default/config.h new file mode 100644 index 0000000..b3a82f4 --- /dev/null +++ b/splyte/src/keymaps/default/config.h @@ -0,0 +1,19 @@ +/* Copyright 2019 Daniel Flanagan + * + * 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 . + */ + +#pragma once + +// overrides here diff --git a/splyte/src/keymaps/default/keymap.c b/splyte/src/keymaps/default/keymap.c new file mode 100644 index 0000000..66e03ad --- /dev/null +++ b/splyte/src/keymaps/default/keymap.c @@ -0,0 +1,81 @@ +/* Copyright 2019 Daniel Flanagan + * + * 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 . + */ +#include QMK_KEYBOARD_H + +#define XXXXXXX KC_NO +#define _______ KC_TRNS +#define ESC_CTL LCTL_T(KC_ESC) + +enum layers { L_QWERTY, L_LEFT, L_RIGHT, L_CONFIG, L_BOTH }; + +#define TAB_ALT LALT_T(KC_TAB) +#define K_L_L MO(L_LEFT) +#define K_L_R MO(L_RIGHT) +#define K_L_C MO(L_CONFIG) +#define K_L_B MO(L_BOTH) + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [L_QWERTY] = LAYOUT( + KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_BSPC, + TAB_ALT, KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_BSPC, + ESC_CTL, KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, + KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_ENT , + KC_LGUI, KC_SPC , K_L_L , K_L_C , K_L_C , KC_LALT, K_L_R , KC_RALT + ), + + [L_LEFT] = LAYOUT( + 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_TILD, KC_EXLM, KC_AT , KC_HASH, KC_DLR , KC_PERC , KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL , + KC_DEL , _______, _______, _______, _______, _______ , _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, + _______, _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______ , _______, K_L_B , K_L_B, _______ + ), + + // the insert key at M's position is for easily inputting Shift+Insert + [L_RIGHT] = LAYOUT( + KC_ESC , KC_EXLM, KC_AT , KC_HASH, KC_DLR , KC_PERC , KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL , + KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_DEL , + KC_GRV , _______, _______, _______, _______, _______ , _______, KC_MINS, KC_EQL , KC_LBRC, KC_RBRC, KC_BSLS, + _______, _______, _______, _______, _______, _______ , _______, KC_INS , _______, _______, _______, _______, + _______, KC_LALT, K_L_B , _______ , _______, _______, _______, _______ + ), + + [L_CONFIG] = LAYOUT( + RESET , _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______ , _______, _______, _______, _______ + ), + + [L_BOTH] = LAYOUT( + _______, _______, _______, _______, _______, _______ , _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______ , KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, _______, + _______, _______, _______, _______, _______, _______ , KC_LEFT, KC_DOWN, KC_UP , KC_RGHT, _______, _______, + _______, _______, _______, _______, _______, _______ , KC_HOME, KC_PGDN, KC_PGUP, KC_END , _______, _______, + _______, _______, _______, _______ , _______, _______, _______, _______ + ) +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + return true; +} + +void matrix_init_user(void) {} + +void matrix_scan_user(void) {} + +void led_set_user(uint8_t usb_led) {} diff --git a/splyte/src/keymaps/default/readme.md b/splyte/src/keymaps/default/readme.md new file mode 100644 index 0000000..8e91d84 --- /dev/null +++ b/splyte/src/keymaps/default/readme.md @@ -0,0 +1 @@ +# The default keymap for Splyte diff --git a/splyte/src/matrix.c b/splyte/src/matrix.c new file mode 100644 index 0000000..c6f59b2 --- /dev/null +++ b/splyte/src/matrix.c @@ -0,0 +1,237 @@ +#include +#include +#include + +#include "wait.h" +#include "action_layer.h" +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" +#include "expander.h" + +#ifdef DEBUG_MATRIX_SCAN_RATE +#include "timer.h" +#endif + +#ifdef DEBUG_MATRIX_SCAN_RATE +uint32_t matrix_timer; +uint32_t matrix_scan_count; +#endif + +static matrix_row_t matrix[MATRIX_ROWS]; +static uint8_t debounce_matrix[MATRIX_ROWS * MATRIX_COLS]; + +static matrix_row_t read_cols(uint8_t row); +static void init_cols(void); +static void unselect_rows(void); +static void select_row(uint8_t row); + +__attribute__ ((weak)) + void matrix_init_user(void) {} + +__attribute__ ((weak)) + void matrix_scan_user(void) {} + +__attribute__ ((weak)) + void matrix_init_kb(void) { + matrix_init_user(); + } + +__attribute__ ((weak)) + void matrix_scan_kb(void) { + matrix_scan_user(); + } + +inline uint8_t matrix_rows(void) { + return MATRIX_ROWS; +} + +inline uint8_t matrix_cols(void) { + return MATRIX_COLS; +} + +void matrix_init(void) { + unselect_rows(); + init_cols(); + + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + for (uint8_t j=0; j < MATRIX_COLS; ++j) { + debounce_matrix[i * MATRIX_COLS + j] = 0; + } + } + +#ifdef DEBUG_MATRIX_SCAN_RATE + matrix_timer = timer_read32(); + matrix_scan_count = 0; +#endif + + matrix_init_quantum(); +} + +void matrix_power_up(void) { + + unselect_rows(); + init_cols(); + + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + } + +#ifdef DEBUG_MATRIX_SCAN_RATE + matrix_timer = timer_read32(); + matrix_scan_count = 0; +#endif +} + +matrix_row_t debounce_mask(uint8_t row) { + matrix_row_t result = 0; + for (uint8_t j=0; j < MATRIX_COLS; ++j) { + if (debounce_matrix[row * MATRIX_COLS + j]) { + --debounce_matrix[row * MATRIX_COLS + j]; + } else { + result |= (1 << j); + } + } + return result; +} + + +void debounce_report(matrix_row_t change, uint8_t row) { + for (uint8_t i = 0; i < MATRIX_COLS; ++i) { + if (change & (1 << i)) { + debounce_matrix[row * MATRIX_COLS + i] = DEBOUNCE; + } + } +} + +uint8_t matrix_scan(void) { + expander_scan(); + +#ifdef DEBUG_MATRIX_SCAN_RATE + matrix_scan_count++; + + uint32_t timer_now = timer_read32(); + if (TIMER_DIFF_32(timer_now, matrix_timer)>1000) { + print("matrix scan frequency: "); + pdec(matrix_scan_count); + print("\n"); + matrix_print(); + + matrix_timer = timer_now; + matrix_scan_count = 0; + } +#endif + + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + select_row(i); + wait_us(30); // necessary for stable read values + matrix_row_t mask = debounce_mask(i); + matrix_row_t cols = (read_cols(i) & mask) | (matrix[i] & ~mask); + debounce_report(cols ^ matrix[i], i); + matrix[i] = cols; + + unselect_rows(); + } + + matrix_scan_quantum(); + + return 1; +} + +inline bool matrix_is_on(uint8_t row, uint8_t col) { + return (matrix[row] & ((matrix_row_t)1< + +#include "splyte.h" + +void matrix_init_kb(void) { +#ifdef CONSOLE_ENABLE + uprintf("matrix_init_kb"); +#endif + matrix_init_user(); +} + +void matrix_scan_kb(void) { + matrix_scan_user(); +} + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + return process_record_user(keycode, record); +} + +void led_set_kb(uint8_t usb_led) { + led_set_user(usb_led); +} + +void keyboard_post_init_user(void) { + debug_enable = true; + // debug_matrix = true; +} + +/* Copyright 2019 Daniel Flanagan + * + * 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 . + */ diff --git a/splyte/src/splyte.h b/splyte/src/splyte.h new file mode 100644 index 0000000..8adb780 --- /dev/null +++ b/splyte/src/splyte.h @@ -0,0 +1,36 @@ +#pragma once + +#include "quantum.h" + +#define XXX KC_NO + +#define LAYOUT( \ + l00, l01, l02, l03, l04, l05 , r00, r01, r02, r03, r04, r05, \ + l10, l11, l12, l13, l14, l15 , r10, r11, r12, r13, r14, r15, \ + l20, l21, l22, l23, l24, l25 , r20, r21, r22, r23, r24, r25, \ + l30, l31, l32, l33, l34, l35 , r30, r31, r32, r33, r34, r35, \ + l42, l43, l44, l45 , r40, r41, r42, r43 \ +) \ +{ \ + { l00, l01, l02, l03, l04, l05 , r00, r01, r02, r03, r04, r05 }, \ + { l10, l11, l12, l13, l14, l15 , r10, r11, r12, r13, r14, r15 }, \ + { l20, l21, l22, l23, l24, l25 , r20, r21, r22, r23, r24, r25 }, \ + { l30, l31, l32, l33, l34, l35 , r30, r31, r32, r33, r34, r35 }, \ + { XXX, XXX, l42, l43, l44, l45 , r40, r41, r42, r43, XXX, XXX } \ +} + +/* Copyright 2019 Daniel Flanagan + * + * 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 . + */ diff --git a/splyte/src/twi_master.c b/splyte/src/twi_master.c new file mode 100644 index 0000000..ff12c34 --- /dev/null +++ b/splyte/src/twi_master.c @@ -0,0 +1,78 @@ +#include +#include + +#include "twi_master.h" + +// inspired by Peter Fleury's code found at /keyboards/ergodone/twimaster.c + +#define SCL_CLOCK SCL_CLOCK_400_MHZ + +#define S(N, REG) (N< + +// control bits +// source: https://www.exploreembedded.com/wiki/Basics_of_I2C_with_AVR +#define INTERRUPT_CB TWINT +#define ENABLE_ACK_CB TWEA +#define START_CONDITION_CB TWSTA +#define STOP_CONDITION_CB TWSTO +#define WRITE_COLLISION_CB TWWC +#define TWI_ENABLE_CB TWEN +#define INTERRUPT_ENABLE_CB TWIE + +#define START_COND_CB START_CONDITION_CB +#define STOP_COND_CB STOP_COND_CB + +// status bits +// source: https://www.microchip.com/webdoc/AVRLibcReferenceManual/ch20s33s01.html + +// registers +#define BIT_RATE_REG TWBR +#define CONTROL_REG TWCR +#define DATA_REG TWDR +#define STATUS_REG TWSR +#define ENABLE_REG TWEN +#define MASTER_REG TWSTA +#define STOP_COND_REG TWSTO + +// misc constants +#define TWI_READ 1 +#define TWI_WRITE 0 +#define PRESCALAR_MASK 0xF8 // I don't know where this comes from T_T +#define SCL_CLOCK_100_MHZ 100000L // TODO: which resistor? +#define SCL_CLOCK_400_MHZ 400000L // TODO: which resistor? +#define SCL_CLOCK_1700_MHZ 1700000L // TODO: which resistor? + +// helpers +#define WAIT_FOR_CONTROL_FLAGS(FLAGS) while(!(CONTROL_REG & FLAGS)); +#define WAIT_FOR_INTERRUPT WAIT_FOR_CONTROL_FLAGS(S1(INTERRUPT_CB)) +#define WAIT_FOR_START WAIT_FOR_CONTROL_FLAGS(S1(START_CONDITION_CB)) +#define WAIT_FOR_STOP WAIT_FOR_CONTROL_FLAGS(S1(STOP_CONDITION_CB)) +#define CURRENT_STATUS (TW_STATUS & PRESCALAR_MASK) + +extern void twi_init(void); +extern void twi_stop(void); +extern unsigned char twi_start(unsigned char addr); +extern unsigned char twi_rep_start(unsigned char addr); +extern void twi_start_wait(unsigned char addr); +extern unsigned char twi_write(unsigned char data); +extern unsigned char twi_read_ack(void); +extern unsigned char twi_read_nak(void); +extern unsigned char twi_read(unsigned char ack); + +#define twi_read(ack) (ack) ? twi_readAck() : twi_readNak(); + +/* +modified from Peter Fleury's code +found at /keyboards/ergodone/twimaster.h +original header below +*/ + +/************************************************************************* +* Title: C include file for the I2C master interface +* (i2cmaster.S or twimaster.c) +* Author: Peter Fleury http://jump.to/fleury +* File: $Id: i2cmaster.h,v 1.10 2005/03/06 22:39:57 Peter Exp $ +* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 +* Target: any AVR device +* Usage: see Doxygen manual +**************************************************************************/