Pull TG4X config into config tree
This commit is contained in:
parent
9deeb205b5
commit
66f6195ee5
157
configs/scripts/qmk-helper
Executable file
157
configs/scripts/qmk-helper
Executable file
@ -0,0 +1,157 @@
|
||||
#! /usr/bin/env python3
|
||||
import argparse
|
||||
import sys
|
||||
import logging
|
||||
import subprocess
|
||||
import shutil
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
QMK_REPOSITORY = "https://github.com/qmk/qmk_firmware"
|
||||
QMK_PINNED_COMMIT = "daabe2d8c5eab9d9d605f8e079dfae82d2b06a8d"
|
||||
QMK_CLONE_PATH = Path("~/src/qmk_firmware").expanduser()
|
||||
QMK_USERNAME = "ewpratten"
|
||||
LOCAL_KEYMAPS_ROOT = Path(os.environ["EWCONFIG_ROOT"]) / "keyboards" / "qmk" / "keymaps"
|
||||
|
||||
|
||||
def check_prerequisite_tools() -> bool:
|
||||
# Ensure we have git
|
||||
if shutil.which("git") is None:
|
||||
logger.error("git is not installed")
|
||||
return False
|
||||
|
||||
# Ensure we have make
|
||||
if shutil.which("make") is None:
|
||||
logger.error("make is not installed")
|
||||
return False
|
||||
|
||||
# Ensure we have qmk
|
||||
if shutil.which("qmk") is None:
|
||||
logger.error("qmk is not installed")
|
||||
return False
|
||||
|
||||
# OK
|
||||
return True
|
||||
|
||||
|
||||
def refresh_qmk_repo():
|
||||
# If the repo doesn't exist, clone it
|
||||
if not QMK_CLONE_PATH.exists():
|
||||
logger.info("Cloning QMK repository")
|
||||
QMK_CLONE_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
subprocess.run(
|
||||
["git", "clone", QMK_REPOSITORY, QMK_CLONE_PATH],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Drop any local changes
|
||||
logger.info("Dropping local changes")
|
||||
subprocess.run(
|
||||
["git", "reset", "--hard"],
|
||||
check=True,
|
||||
cwd=QMK_CLONE_PATH,
|
||||
)
|
||||
|
||||
# Pull the latest changes and then checkout the pinned commit
|
||||
logger.info("Updating QMK repository")
|
||||
subprocess.run(
|
||||
["git", "fetch", "--all"],
|
||||
check=True,
|
||||
cwd=QMK_CLONE_PATH,
|
||||
)
|
||||
subprocess.run(
|
||||
["git", "checkout", QMK_PINNED_COMMIT],
|
||||
check=True,
|
||||
cwd=QMK_CLONE_PATH,
|
||||
)
|
||||
|
||||
# Update submodules
|
||||
logger.info("Updating QMK submodules")
|
||||
subprocess.run(
|
||||
["git", "submodule", "update", "--init", "--recursive"],
|
||||
check=True,
|
||||
cwd=QMK_CLONE_PATH,
|
||||
)
|
||||
|
||||
|
||||
def copy_keymap(keyboard: str):
|
||||
# Build the path that this keymap should be copied to
|
||||
KEYMAP_PATH = QMK_CLONE_PATH / "keyboards" / keyboard / "keymaps" / QMK_USERNAME
|
||||
|
||||
# If the keymap already exists, delete it
|
||||
if KEYMAP_PATH.exists():
|
||||
logger.info("Removing existing keymap")
|
||||
shutil.rmtree(KEYMAP_PATH)
|
||||
|
||||
# Copy the keymap
|
||||
logger.info(f"Copying keymap to: {KEYMAP_PATH}")
|
||||
shutil.copytree(LOCAL_KEYMAPS_ROOT / keyboard, KEYMAP_PATH)
|
||||
|
||||
|
||||
def build_keymap(keyboard: str):
|
||||
# Build the keymap
|
||||
logger.info(f"Building keymap: {keyboard}")
|
||||
subprocess.run(
|
||||
["make", keyboard + ":" + QMK_USERNAME],
|
||||
check=True,
|
||||
cwd=QMK_CLONE_PATH,
|
||||
)
|
||||
|
||||
|
||||
def flash_keymap(keyboard: str, flash_mode: str):
|
||||
# Flash the keymap
|
||||
logger.info(f"Flashing keymap: {keyboard} ({flash_mode})")
|
||||
subprocess.run(
|
||||
["qmk", "flash", "-kb", keyboard, "-km", QMK_USERNAME, "-bl", flash_mode],
|
||||
check=True,
|
||||
cwd=QMK_CLONE_PATH,
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
# Handle program arguments
|
||||
ap = argparse.ArgumentParser(
|
||||
prog="qmk-helper", description="Utility for flashing QMK boards"
|
||||
)
|
||||
ap.add_argument("mode", choices=["build", "flash"], help="Mode to run in")
|
||||
ap.add_argument(
|
||||
"keyboard",
|
||||
help="Keyboard to build/flash",
|
||||
choices=["tg4x"],
|
||||
)
|
||||
ap.add_argument("--flash-mode", "-f", help="Flash mode to use", default="flash")
|
||||
ap.add_argument(
|
||||
"-v", "--verbose", help="Enable verbose logging", action="store_true"
|
||||
)
|
||||
args = ap.parse_args()
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG if args.verbose else logging.INFO,
|
||||
format="%(levelname)s: %(message)s",
|
||||
)
|
||||
|
||||
# Check for prerequisite tools
|
||||
if not check_prerequisite_tools():
|
||||
return 1
|
||||
logger.info("Prerequisite tools found")
|
||||
|
||||
# Refresh the QMK repository
|
||||
refresh_qmk_repo()
|
||||
|
||||
# Copy the keymap
|
||||
copy_keymap(args.keyboard)
|
||||
|
||||
# Handle the modes
|
||||
if args.mode == "build":
|
||||
build_keymap(args.keyboard)
|
||||
elif args.mode == "flash":
|
||||
flash_keymap(args.keyboard, args.flash_mode)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
5
keyboards/qmk/keymaps/tg4x/config.h
Normal file
5
keyboards/qmk/keymaps/tg4x/config.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
// Threshold for things considered a "tap"
|
||||
#define TAPPING_TERM 300
|
||||
|
47
keyboards/qmk/keymaps/tg4x/keymap.c
Normal file
47
keyboards/qmk/keymaps/tg4x/keymap.c
Normal file
@ -0,0 +1,47 @@
|
||||
// Pull in the QMK lib
|
||||
#include QMK_KEYBOARD_H
|
||||
|
||||
/* Trickery to make VSCode happy */
|
||||
#include <stdint.h>
|
||||
#define _____ KC_NO
|
||||
#define _PASS KC_TRNS
|
||||
|
||||
/* Layer Definitions */
|
||||
// clang-format off
|
||||
enum tg4x_layers {
|
||||
QWERTY,
|
||||
NUMERIC,
|
||||
ACTIONS,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
/* Layers */
|
||||
// clang-format off
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
|
||||
// QWERTY
|
||||
[QWERTY] = LAYOUT(
|
||||
KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_DEL, KC_BSPC,
|
||||
KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT,
|
||||
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_RSFT, MO(NUMERIC),
|
||||
KC_LCTL, KC_LALT, KC_LGUI, KC_SPACE, KC_SPACE, MO(ACTIONS), _____, _____, _____
|
||||
),
|
||||
|
||||
// NUMERIC
|
||||
[NUMERIC] = LAYOUT(
|
||||
KC_GRV, 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_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL,
|
||||
_PASS, _____, _____, _____, _____, KC_QUOTE, KC_SLSH, KC_LBRC, KC_RBRC, KC_BSLS, _____, _____,
|
||||
_PASS, _PASS, _PASS, KC_SPACE, KC_SPACE, _____, _____, _____, _____
|
||||
),
|
||||
|
||||
// ACTIONS
|
||||
[ACTIONS] = LAYOUT(
|
||||
_____, KC_VOLD, KC_VOLU, KC_MUTE, _____, _____, _____, KC_PGUP, _____, KC_PGDN, KC_PSCR, KC_SCRL, KC_PAUS,
|
||||
KC_CAPS, KC_MPRV, KC_MPLY, KC_MNXT, _____, _____, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, KC_INS, _____,
|
||||
_PASS, RGB_TOG, _____, _____, _____, KC_HOME, KC_END, _____, _____, _____, _PASS, _____,
|
||||
_PASS, _PASS, _PASS, KC_SPACE, KC_SPACE, _____, _____, _____, _____
|
||||
),
|
||||
|
||||
};
|
||||
// clang-format on
|
8
keyboards/qmk/keymaps/tg4x/rules.mk
Normal file
8
keyboards/qmk/keymaps/tg4x/rules.mk
Normal file
@ -0,0 +1,8 @@
|
||||
# Override the default bootloader since I am using a non-standard MCU
|
||||
BOOTLOADER = qmk-dfu
|
||||
|
||||
# Enable bootloader keys
|
||||
BOOTMAGIC_ENABLE = yes
|
||||
|
||||
# Enable Unicode
|
||||
UNICODE_ENABLE = yes
|
Loading…
x
Reference in New Issue
Block a user