mirror of
https://github.com/zsa/qmk_firmware.git
synced 2026-01-12 08:28:07 +00:00
Compare commits
334 Commits
14
...
firmware17
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4f158ad55 | ||
|
|
09dec3e48e | ||
|
|
3ee8f43fd5 | ||
|
|
456da3897f | ||
|
|
3847cb5858 | ||
|
|
155cec398d | ||
|
|
c7a4d68457 | ||
|
|
ff2dbaa012 | ||
|
|
4aeaea515f | ||
|
|
7f4088c937 | ||
|
|
94aa9a48bf | ||
|
|
9e09acfa3d | ||
|
|
3dfd906390 | ||
|
|
2ddc8d7746 | ||
|
|
cac0d749ed | ||
|
|
1416666022 | ||
|
|
4fc42d04a3 | ||
|
|
269f772b7c | ||
|
|
4bb25deceb | ||
|
|
f896a2cd12 | ||
|
|
45c70f889c | ||
|
|
12aabf12bf | ||
|
|
97da465d4d | ||
|
|
86b6a5553e | ||
|
|
ebd211b7b0 | ||
|
|
155fa9fcd3 | ||
|
|
6f1f085b2d | ||
|
|
4771cc9f63 | ||
|
|
e0a355267f | ||
|
|
84a0ba874d | ||
|
|
75ca366082 | ||
|
|
ff1a52360e | ||
|
|
9cd5fa0454 | ||
|
|
9619d1e4ff | ||
|
|
3cab0731b6 | ||
|
|
094244ca04 | ||
|
|
a8e1406574 | ||
|
|
ca79f45ea8 | ||
|
|
d9ac815f71 | ||
|
|
8402fcc22d | ||
|
|
a714e1e0e3 | ||
|
|
41194bcbd3 | ||
|
|
4885430361 | ||
|
|
141e02df88 | ||
|
|
cd52615704 | ||
|
|
79386844a4 | ||
|
|
f3154a54fa | ||
|
|
ff8d9d41b8 | ||
|
|
2d17177c3c | ||
|
|
f23bfa24d1 | ||
|
|
0631d66680 | ||
|
|
b0896a3b35 | ||
|
|
df6e5f16b6 | ||
|
|
4c88e39d15 | ||
|
|
12806f1216 | ||
|
|
7ed8cd4f17 | ||
|
|
4029f3ff50 | ||
|
|
02f0f0811d | ||
|
|
67d285a1a1 | ||
|
|
ccbeb616a6 | ||
|
|
93bd061c0e | ||
|
|
7e614bbdba | ||
|
|
d4f504b70d | ||
|
|
bd73633b67 | ||
|
|
cca46a85f3 | ||
|
|
6defb96175 | ||
|
|
cc9befe283 | ||
|
|
ebd4b1dc1e | ||
|
|
30ed4bdb38 | ||
|
|
93557cca47 | ||
|
|
0a1b1e3235 | ||
|
|
5e3bd392cb | ||
|
|
c3dbc8831f | ||
|
|
5b6592f616 | ||
|
|
895f8bdeb5 | ||
|
|
5ad2d4f57d | ||
|
|
8d5c1033b3 | ||
|
|
14ff12f1ab | ||
|
|
060244a705 | ||
|
|
f67c942c49 | ||
|
|
0c4d319e8d | ||
|
|
b1e8a80477 | ||
|
|
7645e9795b | ||
|
|
9ca1b1b60b | ||
|
|
c71d01f254 | ||
|
|
532cf8509e | ||
|
|
f7dbbf006a | ||
|
|
ce9397836b | ||
|
|
1d05d8ba6a | ||
|
|
0ca620a7f6 | ||
|
|
b1f101030b | ||
|
|
41b518c55f | ||
|
|
72c5e4958c | ||
|
|
97038602f5 | ||
|
|
6a5afb67fd | ||
|
|
bbcc605195 | ||
|
|
06e5032ad3 | ||
|
|
dc05100c4c | ||
|
|
d37042f31c | ||
|
|
dac9a94d17 | ||
|
|
9986ef7635 | ||
|
|
e5890845a7 | ||
|
|
fcfe182836 | ||
|
|
b80becc5e5 | ||
|
|
5f03514246 | ||
|
|
922984f981 | ||
|
|
977fd47df5 | ||
|
|
65edbc6261 | ||
|
|
5bf407c8e9 | ||
|
|
39a9486b35 | ||
|
|
6198382cb1 | ||
|
|
d550603b8c | ||
|
|
c72b69194c | ||
|
|
4c6c17e68b | ||
|
|
66d48534b1 | ||
|
|
0c4e870063 | ||
|
|
bac3e50f88 | ||
|
|
678f1a9595 | ||
|
|
e7a2fdc271 | ||
|
|
ed1cbad3e7 | ||
|
|
2feb42ddb0 | ||
|
|
a8e4c490bf | ||
|
|
3b71e1e819 | ||
|
|
5c1c41462a | ||
|
|
bd9df62713 | ||
|
|
5ed3ecdd73 | ||
|
|
259cc07202 | ||
|
|
1bd151eee3 | ||
|
|
9b9e5e1d47 | ||
|
|
e41ab50016 | ||
|
|
d3f23ecfbc | ||
|
|
0c676d6e47 | ||
|
|
7b8d56d6d5 | ||
|
|
138f981238 | ||
|
|
455f9e9d1f | ||
|
|
6a7b6815de | ||
|
|
d0e06f0385 | ||
|
|
9c06f5a2e6 | ||
|
|
052e4ee4d2 | ||
|
|
5f9e60bd95 | ||
|
|
20f465bfb6 | ||
|
|
1378e0de96 | ||
|
|
172fbd48ab | ||
|
|
ffc0605370 | ||
|
|
5a5c90f851 | ||
|
|
493c675778 | ||
|
|
1a62f5c142 | ||
|
|
4586615534 | ||
|
|
bf2512dcef | ||
|
|
319e86e1c6 | ||
|
|
37b55e3693 | ||
|
|
a0ebf160f2 | ||
|
|
ea6680ab27 | ||
|
|
2dd7d55f30 | ||
|
|
c17675f50a | ||
|
|
8e52dc41b4 | ||
|
|
c465c4ac84 | ||
|
|
50fcd78772 | ||
|
|
5d02ae2111 | ||
|
|
13d1a7e40a | ||
|
|
0f1f9ba155 | ||
|
|
ac75812e50 | ||
|
|
dfa3631a44 | ||
|
|
4dc4b7af75 | ||
|
|
6f57ecc58e | ||
|
|
d459da0c95 | ||
|
|
22891f9c83 | ||
|
|
31608fe2a9 | ||
|
|
853394f8e1 | ||
|
|
8d35ebab7f | ||
|
|
55b2c4c1ed | ||
|
|
06a8a3c0d3 | ||
|
|
ab609a07a6 | ||
|
|
5aa1d81b15 | ||
|
|
df91396be9 | ||
|
|
81126b6673 | ||
|
|
4c1bdea275 | ||
|
|
9e4f537013 | ||
|
|
c70de1d595 | ||
|
|
b4ff413d69 | ||
|
|
e87c2fe8ce | ||
|
|
8a4525a678 | ||
|
|
1836a6f5d2 | ||
|
|
619d2ffcb6 | ||
|
|
72f42d8e52 | ||
|
|
50c6d1e178 | ||
|
|
8c273cd0f2 | ||
|
|
2b15486272 | ||
|
|
2c0173f0ff | ||
|
|
bac9fc60fe | ||
|
|
d1dc2d5389 | ||
|
|
9db7651e7b | ||
|
|
b89cafbdec | ||
|
|
80f8ad232b | ||
|
|
a15119dc6f | ||
|
|
1f66fd1a3c | ||
|
|
9d5e6c1c0a | ||
|
|
20a2ebfeb9 | ||
|
|
bf09fa6148 | ||
|
|
2fe7d6aea2 | ||
|
|
13e1dd3d53 | ||
|
|
038cef3054 | ||
|
|
52f5c344c4 | ||
|
|
0f319b48e6 | ||
|
|
9620bdbf00 | ||
|
|
52e4c04afd | ||
|
|
05ddbc6b6a | ||
|
|
4ca9256118 | ||
|
|
7c51cd7d99 | ||
|
|
47fa4894bb | ||
|
|
c80f69639b | ||
|
|
1f926d5431 | ||
|
|
0e3739a213 | ||
|
|
afdba6115a | ||
|
|
39c6035657 | ||
|
|
40f08c04c3 | ||
|
|
817720fbdb | ||
|
|
368c2f1cdf | ||
|
|
70cfe93f3e | ||
|
|
e1c12338a1 | ||
|
|
ea6f99e05d | ||
|
|
5400211a9a | ||
|
|
c1d468a5b7 | ||
|
|
2a3cc8e273 | ||
|
|
f832395063 | ||
|
|
4af7cbcc71 | ||
|
|
e54578a89c | ||
|
|
616b97782a | ||
|
|
70ce9e566e | ||
|
|
67d52f67df | ||
|
|
9148b001ff | ||
|
|
cb7d24d95d | ||
|
|
4dc4084c03 | ||
|
|
9ac9fffc9c | ||
|
|
7f07b9d5af | ||
|
|
05ed342709 | ||
|
|
05cbac82e3 | ||
|
|
62c1edc5ac | ||
|
|
a73c258d79 | ||
|
|
a2c458863e | ||
|
|
69542eaa4b | ||
|
|
703f905a72 | ||
|
|
f0fe12e005 | ||
|
|
135e0dfff4 | ||
|
|
c29b1da096 | ||
|
|
dfda3cf71d | ||
|
|
6099a97718 | ||
|
|
fe32c9172d | ||
|
|
860995817f | ||
|
|
53e7452e49 | ||
|
|
74d911b5df | ||
|
|
70d35e8e30 | ||
|
|
ac7de6603c | ||
|
|
f7408111c7 | ||
|
|
15d3efd5d1 | ||
|
|
0bd727cb19 | ||
|
|
4a8aa15634 | ||
|
|
54d6f5d4c5 | ||
|
|
3a14d8874f | ||
|
|
354af71894 | ||
|
|
9a97a0eee9 | ||
|
|
925c43c4c0 | ||
|
|
b3c0f3b0ef | ||
|
|
f3edef8c69 | ||
|
|
40e9813ba2 | ||
|
|
9b8e12814a | ||
|
|
40312b7575 | ||
|
|
91f8f7f69e | ||
|
|
ce0c294dc7 | ||
|
|
bea96d1d84 | ||
|
|
ae96eed205 | ||
|
|
560d1c5385 | ||
|
|
66d4c71b03 | ||
|
|
0a3343aca9 | ||
|
|
a595a1b675 | ||
|
|
d0ee924c9d | ||
|
|
9d1f6c699b | ||
|
|
14e5aab4c7 | ||
|
|
bea75bd84e | ||
|
|
5f57fa478d | ||
|
|
ab799d5628 | ||
|
|
af26d4b1fe | ||
|
|
58567e9003 | ||
|
|
4175e3cbe8 | ||
|
|
f62a4e3ec4 | ||
|
|
618075135d | ||
|
|
fc27898796 | ||
|
|
a14b72580d | ||
|
|
0d893b1143 | ||
|
|
930ab89eee | ||
|
|
e3e2489f86 | ||
|
|
415ab3c96c | ||
|
|
be4771380f | ||
|
|
56dd8cfe48 | ||
|
|
74d3820ff4 | ||
|
|
3f2ea83234 | ||
|
|
7d58ebe288 | ||
|
|
9dbff9f9c8 | ||
|
|
de86a0111a | ||
|
|
42f70cd423 | ||
|
|
66d3ac0b72 | ||
|
|
e3f8f475fe | ||
|
|
a5d07e9656 | ||
|
|
ef314477b3 | ||
|
|
5ad8d221c8 | ||
|
|
200c6bedd1 | ||
|
|
0492378872 | ||
|
|
d179863d2e | ||
|
|
89104e0d2d | ||
|
|
9c70eceec1 | ||
|
|
74d97c7c1d | ||
|
|
6d891bfae9 | ||
|
|
3cb9a24bff | ||
|
|
50f3d2556d | ||
|
|
4a5ec09f61 | ||
|
|
47f2ecb633 | ||
|
|
486290af96 | ||
|
|
b39dbc0342 | ||
|
|
6e2424e658 | ||
|
|
db4445e870 | ||
|
|
9bc4684371 | ||
|
|
128bde1be1 | ||
|
|
ffca0ecd0a | ||
|
|
56443ee486 | ||
|
|
0c67055ae1 | ||
|
|
327a6e0f55 | ||
|
|
5ecd526d13 | ||
|
|
f8fe33acfa | ||
|
|
c339d67068 | ||
|
|
07cfca1beb | ||
|
|
f6e500e199 | ||
|
|
7ee98d5265 | ||
|
|
338c36dbae | ||
|
|
0d1d10edfd |
@@ -13,14 +13,14 @@ BinPackParameters: 'true'
|
||||
ColumnLimit: '1000'
|
||||
IndentCaseLabels: 'true'
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: '2'
|
||||
IndentWidth: '4'
|
||||
MaxEmptyLinesToKeep: '1'
|
||||
PointerAlignment: Right
|
||||
SortIncludes: 'false'
|
||||
SpaceBeforeAssignmentOperators: 'true'
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: 'false'
|
||||
TabWidth: '2'
|
||||
TabWidth: '4'
|
||||
UseTab: Never
|
||||
|
||||
...
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -25,7 +25,7 @@ quantum/version.h
|
||||
CMakeLists.txt
|
||||
cmake-build-debug
|
||||
doxygen/
|
||||
.DS_STORE
|
||||
.DS_Store
|
||||
/util/wsl_downloaded
|
||||
/util/win_downloaded
|
||||
/users/
|
||||
|
||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -13,4 +13,4 @@
|
||||
url = https://github.com/google/googletest
|
||||
[submodule "lib/lufa"]
|
||||
path = lib/lufa
|
||||
url = https://github.com/qmk/lufa
|
||||
url = https://github.com/zsa/lufa
|
||||
|
||||
21
Makefile
21
Makefile
@@ -371,6 +371,9 @@ define PARSE_KEYBOARD
|
||||
# The same if all was specified
|
||||
else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,all),true)
|
||||
$$(eval $$(call PARSE_ALL_KEYMAPS))
|
||||
# List all keymaps for the given keyboard
|
||||
else ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,list-keymaps),true)
|
||||
$$(eval $$(call LIST_ALL_KEYMAPS))
|
||||
# Try to match the specified keyamp with the list of known keymaps
|
||||
else ifeq ($$(call TRY_TO_MATCH_RULE_FROM_LIST,$$(KEYMAPS)),true)
|
||||
$$(eval $$(call PARSE_KEYMAP,$$(MATCHED_ITEM)))
|
||||
@@ -407,6 +410,16 @@ endef
|
||||
# endif
|
||||
# endef
|
||||
|
||||
# Prints a list of all known keymaps for the given keyboard
|
||||
define LIST_ALL_KEYMAPS
|
||||
COMMAND_true_LIST_KEYMAPS := \
|
||||
printf "$$(KEYMAPS)\n";
|
||||
COMMAND_false_LIST_KEYMAPS := \
|
||||
printf "$$(MSG_AVAILABLE_KEYMAPS)\n"; \
|
||||
printf "$$(KEYMAPS)\n";
|
||||
COMMANDS += LIST_KEYMAPS
|
||||
endef
|
||||
|
||||
# $1 Keymap
|
||||
# This is the meat of compiling a keyboard, when entering this, everything is known
|
||||
# keyboard, subproject, and keymap
|
||||
@@ -545,10 +558,10 @@ endef
|
||||
if ! python3 --version 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; fi
|
||||
# Check if the submodules are dirty, and display a warning if they are
|
||||
ifndef SKIP_GIT
|
||||
if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 1 --init lib/chibios; fi
|
||||
if [ ! -e lib/chibios-contrib ]; then git submodule sync lib/chibios-contrib && git submodule update --depth 1 --init lib/chibios-contrib; fi
|
||||
if [ ! -e lib/ugfx ]; then git submodule sync lib/ugfx && git submodule update --depth 1 --init lib/ugfx; fi
|
||||
if [ ! -e lib/lufa ]; then git submodule sync lib/lufa && git submodule update --depth 1 --init lib/lufa; fi
|
||||
if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 50 --init lib/chibios; fi
|
||||
if [ ! -e lib/chibios-contrib ]; then git submodule sync lib/chibios-contrib && git submodule update --depth 50 --init lib/chibios-contrib; fi
|
||||
if [ ! -e lib/ugfx ]; then git submodule sync lib/ugfx && git submodule update --depth 50 --init lib/ugfx; fi
|
||||
if [ ! -e lib/lufa ]; then git submodule sync lib/lufa && git submodule update --depth 50 --init lib/lufa; fi
|
||||
git submodule status --recursive 2>/dev/null | \
|
||||
while IFS= read -r x; do \
|
||||
case "$$x" in \
|
||||
|
||||
99
bin/qmk
99
bin/qmk
@@ -4,10 +4,8 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from glob import glob
|
||||
from time import strftime
|
||||
from importlib import import_module
|
||||
from importlib.util import find_spec
|
||||
from time import strftime
|
||||
|
||||
# Add the QMK python libs to our path
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
@@ -15,12 +13,8 @@ qmk_dir = os.path.abspath(os.path.join(script_dir, '..'))
|
||||
python_lib_dir = os.path.abspath(os.path.join(qmk_dir, 'lib', 'python'))
|
||||
sys.path.append(python_lib_dir)
|
||||
|
||||
# Change to the root of our checkout
|
||||
os.environ['ORIG_CWD'] = os.getcwd()
|
||||
os.chdir(qmk_dir)
|
||||
|
||||
# Make sure our modules have been setup
|
||||
with open('requirements.txt', 'r') as fd:
|
||||
with open(os.path.join(qmk_dir, 'requirements.txt'), 'r') as fd:
|
||||
for line in fd.readlines():
|
||||
line = line.strip().replace('<', '=').replace('>', '=')
|
||||
|
||||
@@ -31,73 +25,64 @@ with open('requirements.txt', 'r') as fd:
|
||||
line = line.split('#')[0]
|
||||
|
||||
module = line.split('=')[0] if '=' in line else line
|
||||
|
||||
if module in ['pep8-naming']:
|
||||
# Not every module is importable by its own name.
|
||||
continue
|
||||
|
||||
if not find_spec(module):
|
||||
print('Your QMK build environment is not fully setup!\n')
|
||||
print('Please run `./util/qmk_install.sh` to setup QMK.')
|
||||
print('Could not find module %s!', module)
|
||||
print('Please run `pip3 install -r requirements.txt` to install the python dependencies.')
|
||||
exit(255)
|
||||
|
||||
# Figure out our version
|
||||
# TODO(skullydazed/anyone): Find a method that doesn't involve git. This is slow in docker and on windows.
|
||||
command = ['git', 'describe', '--abbrev=6', '--dirty', '--always', '--tags']
|
||||
result = subprocess.run(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
result = subprocess.run(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
|
||||
if result.returncode == 0:
|
||||
os.environ['QMK_VERSION'] = 'QMK ' + result.stdout.strip()
|
||||
os.environ['QMK_VERSION'] = result.stdout.strip()
|
||||
else:
|
||||
os.environ['QMK_VERSION'] = 'QMK ' + strftime('%Y-%m-%d-%H:%M:%S')
|
||||
os.environ['QMK_VERSION'] = 'nogit-' + strftime('%Y-%m-%d-%H:%M:%S') + '-dirty'
|
||||
|
||||
# Setup the CLI
|
||||
import milc
|
||||
milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}ψ{style_reset_all}'
|
||||
import milc # noqa
|
||||
|
||||
# If we were invoked as `qmk <cmd>` massage sys.argv into `qmk-<cmd>`.
|
||||
# This means we can't accept arguments to the qmk script itself.
|
||||
script_name = os.path.basename(sys.argv[0])
|
||||
if script_name == 'qmk':
|
||||
if len(sys.argv) == 1:
|
||||
milc.cli.log.error('No subcommand specified!\n')
|
||||
milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'
|
||||
|
||||
if len(sys.argv) == 1 or sys.argv[1] in ['-h', '--help']:
|
||||
milc.cli.echo('usage: qmk <subcommand> [...]')
|
||||
milc.cli.echo('\nsubcommands:')
|
||||
subcommands = glob(os.path.join(qmk_dir, 'bin', 'qmk-*'))
|
||||
for subcommand in sorted(subcommands):
|
||||
subcommand = os.path.basename(subcommand).split('-', 1)[1]
|
||||
milc.cli.echo('\t%s', subcommand)
|
||||
milc.cli.echo('\nqmk <subcommand> --help for more information')
|
||||
exit(1)
|
||||
|
||||
if sys.argv[1] in ['-V', '--version']:
|
||||
milc.cli.echo(os.environ['QMK_VERSION'])
|
||||
exit(0)
|
||||
@milc.cli.entrypoint('QMK Helper Script')
|
||||
def qmk_main(cli):
|
||||
"""The function that gets run when no subcommand is provided.
|
||||
"""
|
||||
cli.print_help()
|
||||
|
||||
sys.argv[0] = script_name = '-'.join((script_name, sys.argv[1]))
|
||||
del sys.argv[1]
|
||||
|
||||
# Look for which module to import
|
||||
if script_name == 'qmk':
|
||||
milc.cli.print_help()
|
||||
exit(0)
|
||||
elif not script_name.startswith('qmk-'):
|
||||
milc.cli.log.error('Invalid symlink, must start with "qmk-": %s', script_name)
|
||||
else:
|
||||
subcommand = script_name.replace('-', '.').replace('_', '.').split('.')
|
||||
subcommand.insert(1, 'cli')
|
||||
subcommand = '.'.join(subcommand)
|
||||
def main():
|
||||
"""Setup our environment and then call the CLI entrypoint.
|
||||
"""
|
||||
# Change to the root of our checkout
|
||||
os.environ['ORIG_CWD'] = os.getcwd()
|
||||
os.chdir(qmk_dir)
|
||||
|
||||
try:
|
||||
import_module(subcommand)
|
||||
except ModuleNotFoundError as e:
|
||||
if e.__class__.__name__ != subcommand:
|
||||
raise
|
||||
# Import the subcommands
|
||||
import qmk.cli # noqa
|
||||
|
||||
milc.cli.log.error('Invalid subcommand! Could not import %s.', subcommand)
|
||||
exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Execute
|
||||
return_code = milc.cli()
|
||||
|
||||
if return_code is False:
|
||||
exit(1)
|
||||
elif return_code is not True and isinstance(return_code, int) and return_code < 256:
|
||||
|
||||
elif return_code is not True and isinstance(return_code, int):
|
||||
if return_code < 0 or return_code > 255:
|
||||
milc.cli.log.error('Invalid return_code: %d', return_code)
|
||||
exit(255)
|
||||
|
||||
exit(return_code)
|
||||
else:
|
||||
exit(0)
|
||||
|
||||
exit(0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
qmk
|
||||
@@ -1 +0,0 @@
|
||||
qmk
|
||||
@@ -1 +0,0 @@
|
||||
qmk
|
||||
@@ -1 +0,0 @@
|
||||
qmk
|
||||
@@ -82,6 +82,13 @@ ifeq ($(strip $(BOOTLOADER)), USBasp)
|
||||
OPT_DEFS += -DBOOTLOADER_USBASP
|
||||
BOOTLOADER_SIZE = 4096
|
||||
endif
|
||||
ifeq ($(strip $(BOOTLOADER)), lufa-ms)
|
||||
# DO NOT USE THIS BOOTLOADER IN NEW PROJECTS!
|
||||
# It is extremely prone to bricking, and is only included to support existing boards.
|
||||
OPT_DEFS += -DBOOTLOADER_MS
|
||||
BOOTLOADER_SIZE = 6144
|
||||
FIRMWARE_FORMAT = bin
|
||||
endif
|
||||
|
||||
ifdef BOOTLOADER_SIZE
|
||||
OPT_DEFS += -DBOOTLOADER_SIZE=$(strip $(BOOTLOADER_SIZE))
|
||||
|
||||
@@ -22,6 +22,5 @@ else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.json)","")
|
||||
endif
|
||||
|
||||
# Generate the keymap.c
|
||||
ifneq ("$(KEYMAP_JSON)","")
|
||||
_ = $(shell test -e $(KEYMAP_C) || bin/qmk-json-keymap $(KEYMAP_JSON) -o $(KEYMAP_C))
|
||||
endif
|
||||
$(KEYBOARD_OUTPUT)/src/keymap.c:
|
||||
bin/qmk json-keymap --quiet --output $(KEYMAP_C) $(KEYMAP_JSON)
|
||||
|
||||
@@ -61,7 +61,7 @@ endif
|
||||
|
||||
ifeq ($(strip $(STENO_ENABLE)), yes)
|
||||
OPT_DEFS += -DSTENO_ENABLE
|
||||
VIRTSER_ENABLE := yes
|
||||
VIRTSER_ENABLE ?= yes
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_steno.c
|
||||
endif
|
||||
|
||||
@@ -82,19 +82,19 @@ endif
|
||||
|
||||
ifeq ($(strip $(UCIS_ENABLE)), yes)
|
||||
OPT_DEFS += -DUCIS_ENABLE
|
||||
UNICODE_COMMON = yes
|
||||
UNICODE_COMMON := yes
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_ucis.c
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(UNICODEMAP_ENABLE)), yes)
|
||||
OPT_DEFS += -DUNICODEMAP_ENABLE
|
||||
UNICODE_COMMON = yes
|
||||
UNICODE_COMMON := yes
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_unicodemap.c
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(UNICODE_ENABLE)), yes)
|
||||
OPT_DEFS += -DUNICODE_ENABLE
|
||||
UNICODE_COMMON = yes
|
||||
UNICODE_COMMON := yes
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
|
||||
endif
|
||||
|
||||
@@ -102,17 +102,69 @@ ifeq ($(strip $(UNICODE_COMMON)), yes)
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_unicode_common.c
|
||||
endif
|
||||
|
||||
VALID_EEPROM_DRIVER_TYPES := vendor custom transient i2c
|
||||
EEPROM_DRIVER ?= vendor
|
||||
ifeq ($(filter $(EEPROM_DRIVER),$(VALID_EEPROM_DRIVER_TYPES)),)
|
||||
$(error EEPROM_DRIVER="$(EEPROM_DRIVER)" is not a valid EEPROM driver)
|
||||
else
|
||||
OPT_DEFS += -DEEPROM_ENABLE
|
||||
ifeq ($(strip $(EEPROM_DRIVER)), custom)
|
||||
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_CUSTOM
|
||||
COMMON_VPATH += $(DRIVER_PATH)/eeprom
|
||||
SRC += eeprom_driver.c
|
||||
else ifeq ($(strip $(EEPROM_DRIVER)), i2c)
|
||||
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_I2C
|
||||
COMMON_VPATH += $(DRIVER_PATH)/eeprom
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
SRC += eeprom_driver.c eeprom_i2c.c
|
||||
else ifeq ($(strip $(EEPROM_DRIVER)), transient)
|
||||
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_TRANSIENT
|
||||
COMMON_VPATH += $(DRIVER_PATH)/eeprom
|
||||
SRC += eeprom_driver.c eeprom_transient.c
|
||||
else ifeq ($(strip $(EEPROM_DRIVER)), vendor)
|
||||
OPT_DEFS += -DEEPROM_VENDOR
|
||||
ifeq ($(PLATFORM),AVR)
|
||||
# Automatically provided by avr-libc, nothing required
|
||||
else ifeq ($(PLATFORM),CHIBIOS)
|
||||
ifeq ($(MCU_SERIES), STM32F3xx)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
|
||||
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
|
||||
OPT_DEFS += -DEEPROM_EMU_STM32F303xC
|
||||
OPT_DEFS += -DSTM32_EEPROM_ENABLE
|
||||
else ifeq ($(MCU_SERIES), STM32F1xx)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
|
||||
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
|
||||
OPT_DEFS += -DEEPROM_EMU_STM32F103xB
|
||||
OPT_DEFS += -DSTM32_EEPROM_ENABLE
|
||||
else ifeq ($(MCU_SERIES)_$(MCU_LDSCRIPT), STM32F0xx_STM32F072xB)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
|
||||
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
|
||||
OPT_DEFS += -DEEPROM_EMU_STM32F072xB
|
||||
OPT_DEFS += -DSTM32_EEPROM_ENABLE
|
||||
else
|
||||
# This will effectively work the same as "transient" if not supported by the chip
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c
|
||||
endif
|
||||
else ifeq ($(PLATFORM),ARM_ATSAM)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
|
||||
else ifeq ($(PLATFORM),TEST)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
|
||||
POST_CONFIG_H += $(QUANTUM_DIR)/rgblight_post_config.h
|
||||
OPT_DEFS += -DRGBLIGHT_ENABLE
|
||||
SRC += $(QUANTUM_DIR)/color.c
|
||||
SRC += $(QUANTUM_DIR)/rgblight.c
|
||||
CIE1931_CURVE = yes
|
||||
LED_BREATHING_TABLE = yes
|
||||
CIE1931_CURVE := yes
|
||||
LED_BREATHING_TABLE := yes
|
||||
RGB_KEYCODES_ENABLE := yes
|
||||
ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes)
|
||||
OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER
|
||||
else
|
||||
SRC += ws2812.c
|
||||
WS2812_DRIVER_REQUIRED := yes
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -123,7 +175,9 @@ ifneq ($(strip $(LED_MATRIX_ENABLE)), no)
|
||||
ifeq ($(filter $(LED_MATRIX_ENABLE),$(VALID_MATRIX_TYPES)),)
|
||||
$(error LED_MATRIX_ENABLE="$(LED_MATRIX_ENABLE)" is not a valid matrix type)
|
||||
else
|
||||
OPT_DEFS += -DLED_MATRIX_ENABLE -DBACKLIGHT_ENABLE -DBACKLIGHT_CUSTOM_DRIVER
|
||||
BACKLIGHT_ENABLE = yes
|
||||
BACKLIGHT_DRIVER = custom
|
||||
OPT_DEFS += -DLED_MATRIX_ENABLE
|
||||
SRC += $(QUANTUM_DIR)/led_matrix.c
|
||||
SRC += $(QUANTUM_DIR)/led_matrix_drivers.c
|
||||
endif
|
||||
@@ -146,11 +200,12 @@ endif
|
||||
SRC += $(QUANTUM_DIR)/color.c
|
||||
SRC += $(QUANTUM_DIR)/rgb_matrix.c
|
||||
SRC += $(QUANTUM_DIR)/rgb_matrix_drivers.c
|
||||
CIE1931_CURVE = yes
|
||||
CIE1931_CURVE := yes
|
||||
RGB_KEYCODES_ENABLE := yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
|
||||
RGB_MATRIX_ENABLE = IS31FL3731
|
||||
RGB_MATRIX_ENABLE := IS31FL3731
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(RGB_MATRIX_ENABLE)), IS31FL3731)
|
||||
@@ -176,7 +231,7 @@ endif
|
||||
|
||||
ifeq ($(strip $(RGB_MATRIX_ENABLE)), WS2812)
|
||||
OPT_DEFS += -DWS2812
|
||||
SRC += ws2812.c
|
||||
WS2812_DRIVER_REQUIRED := yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(RGB_MATRIX_CUSTOM_KB)), yes)
|
||||
@@ -187,6 +242,10 @@ ifeq ($(strip $(RGB_MATRIX_CUSTOM_USER)), yes)
|
||||
OPT_DEFS += -DRGB_MATRIX_CUSTOM_USER
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(RGB_KEYCODES_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_rgb.c
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
|
||||
OPT_DEFS += -DTAP_DANCE_ENABLE
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
|
||||
@@ -226,26 +285,78 @@ endif
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(LCD_ENABLE)), yes)
|
||||
CIE1931_CURVE = yes
|
||||
CIE1931_CURVE := yes
|
||||
endif
|
||||
|
||||
# backward compat
|
||||
ifeq ($(strip $(BACKLIGHT_CUSTOM_DRIVER)), yes)
|
||||
BACKLIGHT_DRIVER := custom
|
||||
endif
|
||||
|
||||
VALID_BACKLIGHT_TYPES := pwm software custom
|
||||
|
||||
BACKLIGHT_ENABLE ?= no
|
||||
BACKLIGHT_DRIVER ?= pwm
|
||||
ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
|
||||
ifeq ($(filter $(BACKLIGHT_DRIVER),$(VALID_BACKLIGHT_TYPES)),)
|
||||
$(error BACKLIGHT_DRIVER="$(BACKLIGHT_DRIVER)" is not a valid backlight type)
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
|
||||
CIE1931_CURVE = yes
|
||||
CIE1931_CURVE := yes
|
||||
endif
|
||||
ifeq ($(strip $(BACKLIGHT_CUSTOM_DRIVER)), yes)
|
||||
|
||||
COMMON_VPATH += $(QUANTUM_DIR)/backlight
|
||||
SRC += $(QUANTUM_DIR)/backlight/backlight.c
|
||||
OPT_DEFS += -DBACKLIGHT_ENABLE
|
||||
|
||||
ifeq ($(strip $(BACKLIGHT_DRIVER)), custom)
|
||||
OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER
|
||||
else ifeq ($(strip $(BACKLIGHT_DRIVER)), software)
|
||||
SRC += $(QUANTUM_DIR)/backlight/backlight_soft.c
|
||||
else
|
||||
ifeq ($(PLATFORM),AVR)
|
||||
SRC += $(QUANTUM_DIR)/backlight/backlight_avr.c
|
||||
else
|
||||
SRC += $(QUANTUM_DIR)/backlight/backlight_arm.c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
VALID_WS2812_DRIVER_TYPES := bitbang pwm spi i2c
|
||||
|
||||
WS2812_DRIVER ?= bitbang
|
||||
ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)
|
||||
ifeq ($(filter $(WS2812_DRIVER),$(VALID_WS2812_DRIVER_TYPES)),)
|
||||
$(error WS2812_DRIVER="$(WS2812_DRIVER)" is not a valid WS2812 driver)
|
||||
endif
|
||||
|
||||
OPT_DEFS += -DWS2812_DRIVER_$(strip $(shell echo $(WS2812_DRIVER) | tr '[:lower:]' '[:upper:]'))
|
||||
|
||||
ifeq ($(strip $(WS2812_DRIVER)), bitbang)
|
||||
SRC += ws2812.c
|
||||
else
|
||||
SRC += ws2812_$(strip $(WS2812_DRIVER)).c
|
||||
endif
|
||||
|
||||
# add extra deps
|
||||
ifeq ($(strip $(WS2812_DRIVER)), i2c)
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
|
||||
CIE1931_CURVE := yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(CIE1931_CURVE)), yes)
|
||||
OPT_DEFS += -DUSE_CIE1931_CURVE
|
||||
LED_TABLES = yes
|
||||
LED_TABLES := yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(LED_BREATHING_TABLE)), yes)
|
||||
OPT_DEFS += -DUSE_LED_BREATHING_TABLE
|
||||
LED_TABLES = yes
|
||||
LED_TABLES := yes
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(LED_TABLES)), yes)
|
||||
@@ -262,6 +373,7 @@ ifeq ($(strip $(USB_HID_ENABLE)), yes)
|
||||
include $(TMK_DIR)/protocol/usb_hid.mk
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(strip $(ENCODER_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/encoder.c
|
||||
OPT_DEFS += -DENCODER_ENABLE
|
||||
@@ -294,6 +406,20 @@ ifeq ($(strip $(VELOCIKEY_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/velocikey.c
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(ORYX_ENABLE)), yes)
|
||||
WEBUSB_ENABLE := yes
|
||||
SRC += $(QUANTUM_DIR)/oryx.c
|
||||
OPT_DEFS += -DORYX_ENABLE
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
DYNAMIC_KEYMAP_ENABLE := yes
|
||||
RAW_ENABLE := yes
|
||||
BOOTMAGIC_ENABLE := lite
|
||||
SRC += $(QUANTUM_DIR)/via.c
|
||||
OPT_DEFS += -DVIA_ENABLE
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(DYNAMIC_KEYMAP_ENABLE)), yes)
|
||||
OPT_DEFS += -DDYNAMIC_KEYMAP_ENABLE
|
||||
SRC += $(QUANTUM_DIR)/dynamic_keymap.c
|
||||
@@ -304,6 +430,12 @@ ifeq ($(strip $(LEADER_ENABLE)), yes)
|
||||
OPT_DEFS += -DLEADER_ENABLE
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/dip_switch.c
|
||||
OPT_DEFS += -DDIP_SWITCH_ENABLE
|
||||
endif
|
||||
|
||||
include $(DRIVER_PATH)/qwiic/qwiic.mk
|
||||
|
||||
QUANTUM_SRC:= \
|
||||
@@ -311,12 +443,28 @@ QUANTUM_SRC:= \
|
||||
$(QUANTUM_DIR)/keymap_common.c \
|
||||
$(QUANTUM_DIR)/keycode_config.c
|
||||
|
||||
# Include the standard or split matrix code if needed
|
||||
|
||||
|
||||
VALID_CUSTOM_MATRIX_TYPES:= yes lite no
|
||||
|
||||
CUSTOM_MATRIX ?= no
|
||||
|
||||
ifneq ($(strip $(CUSTOM_MATRIX)), yes)
|
||||
ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
|
||||
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/matrix.c
|
||||
else
|
||||
QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c
|
||||
ifeq ($(filter $(CUSTOM_MATRIX),$(VALID_CUSTOM_MATRIX_TYPES)),)
|
||||
$(error CUSTOM_MATRIX="$(CUSTOM_MATRIX)" is not a valid custom matrix type)
|
||||
endif
|
||||
|
||||
# Include common stuff for all non custom matrix users
|
||||
QUANTUM_SRC += $(QUANTUM_DIR)/matrix_common.c
|
||||
|
||||
# if 'lite' then skip the actual matrix implementation
|
||||
ifneq ($(strip $(CUSTOM_MATRIX)), lite)
|
||||
# Include the standard or split matrix code if needed
|
||||
ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
|
||||
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/matrix.c
|
||||
else
|
||||
QUANTUM_SRC += $(QUANTUM_DIR)/matrix.c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -339,9 +487,17 @@ ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
|
||||
QUANTUM_SRC += $(QUANTUM_DIR)/split_common/transport.c
|
||||
# Functions added via QUANTUM_LIB_SRC are only included in the final binary if they're called.
|
||||
# Unused functions are pruned away, which is why we can add multiple drivers here without bloat.
|
||||
QUANTUM_LIB_SRC += $(QUANTUM_DIR)/split_common/serial.c \
|
||||
i2c_master.c \
|
||||
i2c_slave.c
|
||||
ifeq ($(PLATFORM),AVR)
|
||||
QUANTUM_LIB_SRC += i2c_master.c \
|
||||
i2c_slave.c
|
||||
endif
|
||||
|
||||
SERIAL_DRIVER ?= bitbang
|
||||
ifeq ($(strip $(SERIAL_DRIVER)), bitbang)
|
||||
QUANTUM_LIB_SRC += serial.c
|
||||
else
|
||||
QUANTUM_LIB_SRC += serial_$(strip $(SERIAL_DRIVER)).c
|
||||
endif
|
||||
endif
|
||||
COMMON_VPATH += $(QUANTUM_PATH)/split_common
|
||||
endif
|
||||
@@ -359,8 +515,75 @@ ifeq ($(strip $(SPACE_CADET_ENABLE)), yes)
|
||||
OPT_DEFS += -DSPACE_CADET_ENABLE
|
||||
endif
|
||||
|
||||
MAGIC_ENABLE ?= yes
|
||||
ifeq ($(strip $(MAGIC_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_magic.c
|
||||
OPT_DEFS += -DMAGIC_KEYCODE_ENABLE
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/dip_switch.c
|
||||
OPT_DEFS += -DDIP_SWITCH_ENABLE
|
||||
endif
|
||||
|
||||
VALID_EEPROM_DRIVER_TYPES := vendor custom transient i2c
|
||||
EEPROM_DRIVER ?= vendor
|
||||
ifeq ($(filter $(EEPROM_DRIVER),$(VALID_EEPROM_DRIVER_TYPES)),)
|
||||
$(error EEPROM_DRIVER="$(EEPROM_DRIVER)" is not a valid EEPROM driver)
|
||||
else
|
||||
OPT_DEFS += -DEEPROM_ENABLE
|
||||
ifeq ($(strip $(EEPROM_DRIVER)), custom)
|
||||
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_CUSTOM
|
||||
COMMON_VPATH += $(DRIVER_PATH)/eeprom
|
||||
SRC += eeprom_driver.c
|
||||
else ifeq ($(strip $(EEPROM_DRIVER)), i2c)
|
||||
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_I2C
|
||||
COMMON_VPATH += $(DRIVER_PATH)/eeprom
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
SRC += eeprom_driver.c eeprom_i2c.c
|
||||
else ifeq ($(strip $(EEPROM_DRIVER)), transient)
|
||||
OPT_DEFS += -DEEPROM_DRIVER -DEEPROM_TRANSIENT
|
||||
COMMON_VPATH += $(DRIVER_PATH)/eeprom
|
||||
SRC += eeprom_driver.c eeprom_transient.c
|
||||
else ifeq ($(strip $(EEPROM_DRIVER)), vendor)
|
||||
OPT_DEFS += -DEEPROM_VENDOR
|
||||
ifeq ($(PLATFORM),AVR)
|
||||
# Automatically provided by avr-libc, nothing required
|
||||
else ifeq ($(PLATFORM),CHIBIOS)
|
||||
ifeq ($(MCU_SERIES), STM32F3xx)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
|
||||
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
|
||||
OPT_DEFS += -DEEPROM_EMU_STM32F303xC
|
||||
OPT_DEFS += -DSTM32_EEPROM_ENABLE
|
||||
else ifeq ($(MCU_SERIES), STM32F1xx)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
|
||||
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
|
||||
OPT_DEFS += -DEEPROM_EMU_STM32F103xB
|
||||
OPT_DEFS += -DSTM32_EEPROM_ENABLE
|
||||
else ifeq ($(MCU_SERIES)_$(MCU_LDSCRIPT), STM32F0xx_STM32F072xB)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_stm32.c
|
||||
SRC += $(PLATFORM_COMMON_DIR)/flash_stm32.c
|
||||
OPT_DEFS += -DEEPROM_EMU_STM32F072xB
|
||||
OPT_DEFS += -DSTM32_EEPROM_ENABLE
|
||||
else
|
||||
# This will effectively work the same as "transient" if not supported by the chip
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom_teensy.c
|
||||
endif
|
||||
else ifeq ($(PLATFORM),ARM_ATSAM)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
|
||||
else ifeq ($(PLATFORM),TEST)
|
||||
SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
GRAVE_ESC_ENABLE ?= yes
|
||||
ifeq ($(strip $(GRAVE_ESC_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_grave_esc.c
|
||||
OPT_DEFS += -DGRAVE_ESC_ENABLE
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(DYNAMIC_MACRO_ENABLE)), yes)
|
||||
SRC += $(QUANTUM_DIR)/process_keycode/process_dynamic_macro.c
|
||||
OPT_DEFS += -DDYNAMIC_MACRO_ENABLE
|
||||
endif
|
||||
|
||||
@@ -3,11 +3,9 @@ tmk_core/protocol/bluefruit
|
||||
tmk_core/protocol/chibios
|
||||
tmk_core/protocol/iwrap
|
||||
tmk_core/protocol/lufa
|
||||
tmk_core/protocol/mbed
|
||||
tmk_core/protocol/midi
|
||||
tmk_core/protocol/midi/bytequeue
|
||||
tmk_core/protocol/midi/Config
|
||||
tmk_core/protocol/pjrc
|
||||
tmk_core/protocol/usb_hid
|
||||
tmk_core/protocol/vusb
|
||||
tmk_core/tool
|
||||
|
||||
@@ -24,14 +24,11 @@
|
||||
* STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file. Pins B6 and B7 are used
|
||||
* but using any other I2C pins should be trivial.
|
||||
*/
|
||||
|
||||
#include "i2c_master.h"
|
||||
#include "quantum.h"
|
||||
#include "i2c_master.h"
|
||||
#include <string.h>
|
||||
#include <hal.h>
|
||||
|
||||
static uint8_t i2c_address;
|
||||
|
||||
static const I2CConfig i2cconfig = {
|
||||
#ifdef USE_I2CV1
|
||||
I2C1_OPMODE,
|
||||
@@ -60,8 +57,7 @@ __attribute__((weak)) void i2c_init(void) {
|
||||
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
|
||||
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
#ifdef USE_I2CV1
|
||||
#if defined(USE_GPIOV1)
|
||||
palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
|
||||
palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
|
||||
#else
|
||||
@@ -73,27 +69,53 @@ __attribute__((weak)) void i2c_init(void) {
|
||||
}
|
||||
|
||||
i2c_status_t i2c_start(uint8_t address) {
|
||||
i2c_address = address;
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cAcquireBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
return I2C_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout) {
|
||||
i2c_address = address;
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cAcquireBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, 0, 0, MS2ST(timeout));
|
||||
msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (address >> 1), data, length, 0, 0, MS2ST(timeout));
|
||||
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cReleaseBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
return chibios_to_qmk(&status);
|
||||
}
|
||||
|
||||
i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout) {
|
||||
i2c_address = address;
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cAcquireBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
msg_t status = i2cMasterReceiveTimeout(&I2C_DRIVER, (i2c_address >> 1), data, length, MS2ST(timeout));
|
||||
msg_t status = i2cMasterReceiveTimeout(&I2C_DRIVER, (address >> 1), data, length, MS2ST(timeout));
|
||||
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cReleaseBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
return chibios_to_qmk(&status);
|
||||
}
|
||||
|
||||
i2c_status_t i2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length) {
|
||||
return i2cMasterTransmitTimeout(&I2C_DRIVER, address/2, tx_body, tx_length, rx_body, rx_length, MS2ST(100));
|
||||
}
|
||||
|
||||
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
|
||||
i2c_address = devaddr;
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cAcquireBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
|
||||
uint8_t complete_packet[length + 1];
|
||||
@@ -102,15 +124,34 @@ i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data,
|
||||
}
|
||||
complete_packet[0] = regaddr;
|
||||
|
||||
msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), complete_packet, length + 1, 0, 0, MS2ST(timeout));
|
||||
msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (devaddr >> 1), complete_packet, length + 1, 0, 0, MS2ST(timeout));
|
||||
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cReleaseBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
return chibios_to_qmk(&status);
|
||||
}
|
||||
|
||||
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
|
||||
i2c_address = devaddr;
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cAcquireBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), ®addr, 1, data, length, MS2ST(timeout));
|
||||
msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (devaddr >> 1), ®addr, 1, data, length, MS2ST(timeout));
|
||||
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cReleaseBus(&I2C_DRIVER);
|
||||
#endif
|
||||
|
||||
return chibios_to_qmk(&status);
|
||||
}
|
||||
|
||||
void i2c_stop(void) { i2cStop(&I2C_DRIVER); }
|
||||
void i2c_stop(void) {
|
||||
i2cStop(&I2C_DRIVER);
|
||||
|
||||
#if I2C_USE_MUTUAL_EXCLUSION
|
||||
i2cReleaseBus(&I2C_DRIVER);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -27,10 +27,6 @@
|
||||
#include "ch.h"
|
||||
#include <hal.h>
|
||||
|
||||
#if defined(STM32F1XX) || defined(STM32F1xx) || defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32L0xx) || defined(STM32L1xx)
|
||||
# define USE_I2CV1
|
||||
#endif
|
||||
|
||||
#ifdef I2C1_BANK
|
||||
# define I2C1_SCL_BANK I2C1_BANK
|
||||
# define I2C1_SDA_BANK I2C1_BANK
|
||||
@@ -62,6 +58,30 @@
|
||||
# define I2C1_DUTY_CYCLE STD_DUTY_CYCLE /* FAST_DUTY_CYCLE_2 */
|
||||
# endif
|
||||
#else
|
||||
// The default timing values below configures the I2C clock to 400khz assuming a 72Mhz clock
|
||||
// For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
|
||||
# ifndef I2C1_TIMINGR_PRESC
|
||||
# define I2C1_TIMINGR_PRESC 0U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SCLDEL
|
||||
# define I2C1_TIMINGR_SCLDEL 7U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SDADEL
|
||||
# define I2C1_TIMINGR_SDADEL 0U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SCLH
|
||||
# define I2C1_TIMINGR_SCLH 38U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SCLL
|
||||
# define I2C1_TIMINGR_SCLL 129U
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef I2C_DRIVER
|
||||
# define I2C_DRIVER I2CD1
|
||||
#endif
|
||||
|
||||
#ifndef USE_GPIOV1
|
||||
// The default PAL alternate modes are used to signal that the pins are used for I2C
|
||||
# ifndef I2C1_SCL_PAL_MODE
|
||||
# define I2C1_SCL_PAL_MODE 4
|
||||
@@ -69,28 +89,6 @@
|
||||
# ifndef I2C1_SDA_PAL_MODE
|
||||
# define I2C1_SDA_PAL_MODE 4
|
||||
# endif
|
||||
|
||||
// The default timing values below configures the I2C clock to 400khz assuming a 72Mhz clock
|
||||
// For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
|
||||
# ifndef I2C1_TIMINGR_PRESC
|
||||
# define I2C1_TIMINGR_PRESC 15U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SCLDEL
|
||||
# define I2C1_TIMINGR_SCLDEL 4U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SDADEL
|
||||
# define I2C1_TIMINGR_SDADEL 2U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SCLH
|
||||
# define I2C1_TIMINGR_SCLH 15U
|
||||
# endif
|
||||
# ifndef I2C1_TIMINGR_SCLL
|
||||
# define I2C1_TIMINGR_SCLL 21U
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef I2C_DRIVER
|
||||
# define I2C_DRIVER I2CD1
|
||||
#endif
|
||||
|
||||
typedef int16_t i2c_status_t;
|
||||
|
||||
95
drivers/arm/ws2812.c
Normal file
95
drivers/arm/ws2812.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include "quantum.h"
|
||||
#include "ws2812.h"
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
|
||||
/* Adapted from https://github.com/bigjosh/SimpleNeoPixelDemo/ */
|
||||
|
||||
#ifndef NOP_FUDGE
|
||||
# if defined(STM32F1XX) || defined(STM32F1xx) || defined(STM32F0XX) || defined(STM32F0xx) || defined(STM32F3XX) || defined(STM32F3xx) || defined(STM32L0XX) || defined(STM32L0xx)
|
||||
# define NOP_FUDGE 0.4
|
||||
# else
|
||||
# error("NOP_FUDGE configuration required")
|
||||
# define NOP_FUDGE 1 // this just pleases the compile so the above error is easier to spot
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define NUMBER_NOPS 6
|
||||
#define CYCLES_PER_SEC (STM32_SYSCLK / NUMBER_NOPS * NOP_FUDGE)
|
||||
#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives
|
||||
#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC)
|
||||
#define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE)
|
||||
|
||||
#define wait_ns(x) \
|
||||
do { \
|
||||
for (int i = 0; i < NS_TO_CYCLES(x); i++) { \
|
||||
__asm__ volatile("nop\n\t" \
|
||||
"nop\n\t" \
|
||||
"nop\n\t" \
|
||||
"nop\n\t" \
|
||||
"nop\n\t" \
|
||||
"nop\n\t"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// These are the timing constraints taken mostly from the WS2812 datasheets
|
||||
// These are chosen to be conservative and avoid problems rather than for maximum throughput
|
||||
|
||||
#define T1H 900 // Width of a 1 bit in ns
|
||||
#define T1L (1250 - T1H) // Width of a 1 bit in ns
|
||||
|
||||
#define T0H 350 // Width of a 0 bit in ns
|
||||
#define T0L (1250 - T0H) // Width of a 0 bit in ns
|
||||
|
||||
// The reset gap can be 6000 ns, but depending on the LED strip it may have to be increased
|
||||
// to values like 600000 ns. If it is too small, the pixels will show nothing most of the time.
|
||||
#define RES 10000 // Width of the low gap between bits to cause a frame to latch
|
||||
|
||||
void sendByte(uint8_t byte) {
|
||||
// WS2812 protocol wants most significant bits first
|
||||
for (unsigned char bit = 0; bit < 8; bit++) {
|
||||
bool is_one = byte & (1 << (7 - bit));
|
||||
// using something like wait_ns(is_one ? T1L : T0L) here throws off timings
|
||||
if (is_one) {
|
||||
// 1
|
||||
writePinHigh(RGB_DI_PIN);
|
||||
wait_ns(T1H);
|
||||
writePinLow(RGB_DI_PIN);
|
||||
wait_ns(T1L);
|
||||
} else {
|
||||
// 0
|
||||
writePinHigh(RGB_DI_PIN);
|
||||
wait_ns(T0H);
|
||||
writePinLow(RGB_DI_PIN);
|
||||
wait_ns(T0L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ws2812_init(void) { setPinOutput(RGB_DI_PIN); }
|
||||
|
||||
// Setleds for standard RGB
|
||||
void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
|
||||
static bool s_init = false;
|
||||
if (!s_init) {
|
||||
ws2812_init();
|
||||
s_init = true;
|
||||
}
|
||||
|
||||
// this code is very time dependent, so we need to disable interrupts
|
||||
chSysLock();
|
||||
|
||||
for (uint8_t i = 0; i < leds; i++) {
|
||||
// WS2812 protocol dictates grb order
|
||||
sendByte(ledarray[i].g);
|
||||
sendByte(ledarray[i].r);
|
||||
sendByte(ledarray[i].b);
|
||||
#ifdef RGBW
|
||||
sendByte(ledarray[i].w);
|
||||
#endif
|
||||
}
|
||||
|
||||
wait_ns(RES);
|
||||
|
||||
chSysUnlock();
|
||||
}
|
||||
16
drivers/arm/ws2812.h
Normal file
16
drivers/arm/ws2812.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "quantum/color.h"
|
||||
|
||||
/* User Interface
|
||||
*
|
||||
* Input:
|
||||
* ledarray: An array of GRB data describing the LED colors
|
||||
* number_of_leds: The number of LEDs to write
|
||||
*
|
||||
* The functions will perform the following actions:
|
||||
* - Set the data-out pin as output
|
||||
* - Send out the LED data
|
||||
* - Wait 50us to reset the LEDs
|
||||
*/
|
||||
void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
|
||||
1
drivers/arm/ws2812_pwm.c
Normal file
1
drivers/arm/ws2812_pwm.c
Normal file
@@ -0,0 +1 @@
|
||||
#error("NOT SUPPORTED")
|
||||
90
drivers/arm/ws2812_spi.c
Normal file
90
drivers/arm/ws2812_spi.c
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "quantum.h"
|
||||
#include "ws2812.h"
|
||||
|
||||
/* Adapted from https://github.com/gamazeps/ws2812b-chibios-SPIDMA/ */
|
||||
|
||||
#ifdef RGBW
|
||||
# error "RGBW not supported"
|
||||
#endif
|
||||
|
||||
// Define the spi your LEDs are plugged to here
|
||||
#ifndef WS2812_SPI
|
||||
# define WS2812_SPI SPID1
|
||||
#endif
|
||||
|
||||
#ifndef WS2812_SPI_MOSI_PAL_MODE
|
||||
# define WS2812_SPI_MOSI_PAL_MODE 5
|
||||
#endif
|
||||
|
||||
#define BYTES_FOR_LED_BYTE 4
|
||||
#define NB_COLORS 3
|
||||
#define BYTES_FOR_LED (BYTES_FOR_LED_BYTE * NB_COLORS)
|
||||
#define DATA_SIZE (BYTES_FOR_LED * RGBLED_NUM)
|
||||
#define RESET_SIZE 200
|
||||
#define PREAMBLE_SIZE 4
|
||||
|
||||
static uint8_t txbuf[PREAMBLE_SIZE + DATA_SIZE + RESET_SIZE] = {0};
|
||||
|
||||
/*
|
||||
* As the trick here is to use the SPI to send a huge pattern of 0 and 1 to
|
||||
* the ws2812b protocol, we use this helper function to translate bytes into
|
||||
* 0s and 1s for the LED (with the appropriate timing).
|
||||
*/
|
||||
static uint8_t get_protocol_eq(uint8_t data, int pos) {
|
||||
uint8_t eq = 0;
|
||||
if (data & (1 << (2 * (3 - pos))))
|
||||
eq = 0b1110;
|
||||
else
|
||||
eq = 0b1000;
|
||||
if (data & (2 << (2 * (3 - pos))))
|
||||
eq += 0b11100000;
|
||||
else
|
||||
eq += 0b10000000;
|
||||
return eq;
|
||||
}
|
||||
|
||||
static void set_led_color_rgb(LED_TYPE color, int pos) {
|
||||
uint8_t* tx_start = &txbuf[PREAMBLE_SIZE];
|
||||
|
||||
for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.g, j);
|
||||
for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.r, j);
|
||||
for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.b, j);
|
||||
}
|
||||
|
||||
void ws2812_init(void) {
|
||||
#if defined(USE_GPIOV1)
|
||||
palSetLineMode(RGB_DI_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
|
||||
#else
|
||||
palSetLineMode(RGB_DI_PIN, PAL_MODE_ALTERNATE(WS2812_SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL);
|
||||
#endif
|
||||
|
||||
// TODO: more dynamic baudrate
|
||||
static const SPIConfig spicfg = {
|
||||
NULL, PAL_PORT(RGB_DI_PIN), PAL_PAD(RGB_DI_PIN),
|
||||
SPI_CR1_BR_1 | SPI_CR1_BR_0 // baudrate : fpclk / 8 => 1tick is 0.32us (2.25 MHz)
|
||||
};
|
||||
|
||||
spiAcquireBus(&WS2812_SPI); /* Acquire ownership of the bus. */
|
||||
spiStart(&WS2812_SPI, &spicfg); /* Setup transfer parameters. */
|
||||
spiSelect(&WS2812_SPI); /* Slave Select assertion. */
|
||||
}
|
||||
|
||||
void ws2812_setleds(LED_TYPE* ledarray, uint16_t leds) {
|
||||
static bool s_init = false;
|
||||
if (!s_init) {
|
||||
ws2812_init();
|
||||
s_init = true;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < leds; i++) {
|
||||
set_led_color_rgb(ledarray[i], i);
|
||||
}
|
||||
|
||||
// Send async - each led takes ~0.03ms, 50 leds ~1.5ms, animations flushing faster than send will cause issues.
|
||||
// Instead spiSend can be used to send synchronously (or the thread logic can be added back).
|
||||
#ifdef WS2812_SPI_SYNC
|
||||
spiSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
|
||||
#else
|
||||
spiStartSend(&WS2812_SPI, sizeof(txbuf) / sizeof(txbuf[0]), txbuf);
|
||||
#endif
|
||||
}
|
||||
@@ -14,24 +14,31 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Simple analog to digitial conversion
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <stdint.h>
|
||||
#include "analog.h"
|
||||
|
||||
static uint8_t aref = (1 << REFS0); // default to AREF = Vcc
|
||||
static uint8_t aref = ADC_REF_POWER;
|
||||
|
||||
void analogReference(uint8_t mode) { aref = mode & 0xC0; }
|
||||
void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); }
|
||||
|
||||
// Arduino compatible pin input
|
||||
int16_t analogRead(uint8_t pin) {
|
||||
#if defined(__AVR_ATmega32U4__)
|
||||
static const uint8_t PROGMEM pin_to_mux[] = {0x00, 0x01, 0x04, 0x05, 0x06, 0x07, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20};
|
||||
// clang-format off
|
||||
static const uint8_t PROGMEM pin_to_mux[] = {
|
||||
//A0 A1 A2 A3 A4 A5
|
||||
//F7 F6 F5 F4 F1 F0
|
||||
0x07, 0x06, 0x05, 0x04, 0x01, 0x00,
|
||||
//A6 A7 A8 A9 A10 A11
|
||||
//D4 D7 B4 B5 B6 D6
|
||||
0x20, 0x22, 0x23, 0x24, 0x25, 0x21
|
||||
};
|
||||
// clang-format on
|
||||
if (pin >= 12) return 0;
|
||||
return adc_read(pgm_read_byte(pin_to_mux + pin));
|
||||
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
|
||||
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega328P__)
|
||||
if (pin >= 8) return 0;
|
||||
return adc_read(pin);
|
||||
#else
|
||||
@@ -39,20 +46,87 @@ int16_t analogRead(uint8_t pin) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Mux input
|
||||
int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); }
|
||||
|
||||
uint8_t pinToMux(pin_t pin) {
|
||||
switch (pin) {
|
||||
// clang-format off
|
||||
#if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
case F0: return 0; // ADC0
|
||||
case F1: return _BV(MUX0); // ADC1
|
||||
case F2: return _BV(MUX1); // ADC2
|
||||
case F3: return _BV(MUX1) | _BV(MUX0); // ADC3
|
||||
case F4: return _BV(MUX2); // ADC4
|
||||
case F5: return _BV(MUX2) | _BV(MUX0); // ADC5
|
||||
case F6: return _BV(MUX2) | _BV(MUX1); // ADC6
|
||||
case F7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
|
||||
default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
|
||||
#elif defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
|
||||
case F0: return 0; // ADC0
|
||||
case F1: return _BV(MUX0); // ADC1
|
||||
case F4: return _BV(MUX2); // ADC4
|
||||
case F5: return _BV(MUX2) | _BV(MUX0); // ADC5
|
||||
case F6: return _BV(MUX2) | _BV(MUX1); // ADC6
|
||||
case F7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
|
||||
case D4: return _BV(MUX5); // ADC8
|
||||
case D6: return _BV(MUX5) | _BV(MUX0); // ADC9
|
||||
case D7: return _BV(MUX5) | _BV(MUX1); // ADC10
|
||||
case B4: return _BV(MUX5) | _BV(MUX1) | _BV(MUX0); // ADC11
|
||||
case B5: return _BV(MUX5) | _BV(MUX2); // ADC12
|
||||
case B6: return _BV(MUX5) | _BV(MUX2) | _BV(MUX0); // ADC13
|
||||
default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
|
||||
#elif defined(__AVR_ATmega32A__)
|
||||
case A0: return 0; // ADC0
|
||||
case A1: return _BV(MUX0); // ADC1
|
||||
case A2: return _BV(MUX1); // ADC2
|
||||
case A3: return _BV(MUX1) | _BV(MUX0); // ADC3
|
||||
case A4: return _BV(MUX2); // ADC4
|
||||
case A5: return _BV(MUX2) | _BV(MUX0); // ADC5
|
||||
case A6: return _BV(MUX2) | _BV(MUX1); // ADC6
|
||||
case A7: return _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // ADC7
|
||||
default: return _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
|
||||
#elif defined(__AVR_ATmega328P__)
|
||||
case C0: return 0; // ADC0
|
||||
case C1: return _BV(MUX0); // ADC1
|
||||
case C2: return _BV(MUX1); // ADC2
|
||||
case C3: return _BV(MUX1) | _BV(MUX0); // ADC3
|
||||
case C4: return _BV(MUX2); // ADC4
|
||||
case C5: return _BV(MUX2) | _BV(MUX0); // ADC5
|
||||
// ADC7:6 not present in DIP package and not shared by GPIO pins
|
||||
default: return _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0); // 0V
|
||||
#endif
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
int16_t adc_read(uint8_t mux) {
|
||||
#if defined(__AVR_AT90USB162__)
|
||||
return 0;
|
||||
#else
|
||||
uint8_t low;
|
||||
|
||||
ADCSRA = (1 << ADEN) | ADC_PRESCALER; // enable ADC
|
||||
ADCSRB = (1 << ADHSM) | (mux & 0x20); // high speed mode
|
||||
ADMUX = aref | (mux & 0x1F); // configure mux input
|
||||
ADCSRA = (1 << ADEN) | ADC_PRESCALER | (1 << ADSC); // start the conversion
|
||||
while (ADCSRA & (1 << ADSC))
|
||||
; // wait for result
|
||||
low = ADCL; // must read LSB first
|
||||
return (ADCH << 8) | low; // must read MSB only once!
|
||||
// Enable ADC and configure prescaler
|
||||
ADCSRA = _BV(ADEN) | ADC_PRESCALER;
|
||||
|
||||
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
|
||||
// High speed mode and ADC8-13
|
||||
ADCSRB = _BV(ADHSM) | (mux & _BV(MUX5));
|
||||
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
// High speed mode only
|
||||
ADCSRB = _BV(ADHSM);
|
||||
#endif
|
||||
|
||||
// Configure mux input
|
||||
#if defined(MUX4)
|
||||
ADMUX = aref | (mux & (_BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)));
|
||||
#else
|
||||
ADMUX = aref | (mux & (_BV(MUX3) | _BV(MUX2) | _BV(MUX1) | _BV(MUX0)));
|
||||
#endif
|
||||
|
||||
// Start the conversion
|
||||
ADCSRA |= _BV(ADSC);
|
||||
// Wait for result
|
||||
while (ADCSRA & _BV(ADSC))
|
||||
;
|
||||
// Must read LSB first
|
||||
low = ADCL;
|
||||
// Must read MSB only once!
|
||||
return (ADCH << 8) | low;
|
||||
}
|
||||
|
||||
@@ -14,45 +14,40 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _analog_h_included__
|
||||
#define _analog_h_included__
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "quantum.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void analogReference(uint8_t mode);
|
||||
int16_t analogRead(uint8_t pin);
|
||||
|
||||
int16_t analogReadPin(pin_t pin);
|
||||
uint8_t pinToMux(pin_t pin);
|
||||
|
||||
int16_t adc_read(uint8_t mux);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define ADC_REF_POWER (1 << REFS0)
|
||||
#define ADC_REF_INTERNAL ((1 << REFS1) | (1 << REFS0))
|
||||
#define ADC_REF_EXTERNAL (0)
|
||||
#define ADC_REF_EXTERNAL 0 // AREF, Internal Vref turned off
|
||||
#define ADC_REF_POWER _BV(REFS0) // AVCC with external capacitor on AREF pin
|
||||
#define ADC_REF_INTERNAL (_BV(REFS1) | _BV(REFS0)) // Internal 2.56V Voltage Reference with external capacitor on AREF pin (1.1V for 328P)
|
||||
|
||||
// These prescaler values are for high speed mode, ADHSM = 1
|
||||
#if F_CPU == 16000000L
|
||||
# define ADC_PRESCALER ((1 << ADPS2) | (1 << ADPS1))
|
||||
#if F_CPU == 16000000L || F_CPU == 12000000L
|
||||
# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS1)) // /64
|
||||
#elif F_CPU == 8000000L
|
||||
# define ADC_PRESCALER ((1 << ADPS2) | (1 << ADPS0))
|
||||
# define ADC_PRESCALER (_BV(ADPS2) | _BV(ADPS0)) // /32
|
||||
#elif F_CPU == 4000000L
|
||||
# define ADC_PRESCALER ((1 << ADPS2))
|
||||
# define ADC_PRESCALER (_BV(ADPS2)) // /16
|
||||
#elif F_CPU == 2000000L
|
||||
# define ADC_PRESCALER ((1 << ADPS1) | (1 << ADPS0))
|
||||
# define ADC_PRESCALER (_BV(ADPS1) | _BV(ADPS0)) // /8
|
||||
#elif F_CPU == 1000000L
|
||||
# define ADC_PRESCALER ((1 << ADPS1))
|
||||
# define ADC_PRESCALER _BV(ADPS1) // /4
|
||||
#else
|
||||
# define ADC_PRESCALER ((1 << ADPS0))
|
||||
#endif
|
||||
|
||||
// some avr-libc versions do not properly define ADHSM
|
||||
#if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
|
||||
# if !defined(ADHSM)
|
||||
# define ADHSM (7)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
# define ADC_PRESCALER _BV(ADPS0) // /2
|
||||
#endif
|
||||
|
||||
@@ -25,132 +25,16 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "debug.h"
|
||||
|
||||
#if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE)
|
||||
// LED color buffer
|
||||
LED_TYPE led[DRIVER_LED_TOTAL];
|
||||
# define LED_ARRAY led
|
||||
#endif
|
||||
/*
|
||||
* Forward declare internal functions
|
||||
*
|
||||
* The functions take a byte-array and send to the data output as WS2812 bitstream.
|
||||
* The length is the number of bytes to send - three per LED.
|
||||
*/
|
||||
|
||||
#ifdef RGBW_BB_TWI
|
||||
|
||||
// Port for the I2C
|
||||
# define I2C_DDR DDRD
|
||||
# define I2C_PIN PIND
|
||||
# define I2C_PORT PORTD
|
||||
|
||||
// Pins to be used in the bit banging
|
||||
# define I2C_CLK 0
|
||||
# define I2C_DAT 1
|
||||
|
||||
# define I2C_DATA_HI() \
|
||||
I2C_DDR &= ~(1 << I2C_DAT); \
|
||||
I2C_PORT |= (1 << I2C_DAT);
|
||||
# define I2C_DATA_LO() \
|
||||
I2C_DDR |= (1 << I2C_DAT); \
|
||||
I2C_PORT &= ~(1 << I2C_DAT);
|
||||
|
||||
# define I2C_CLOCK_HI() \
|
||||
I2C_DDR &= ~(1 << I2C_CLK); \
|
||||
I2C_PORT |= (1 << I2C_CLK);
|
||||
# define I2C_CLOCK_LO() \
|
||||
I2C_DDR |= (1 << I2C_CLK); \
|
||||
I2C_PORT &= ~(1 << I2C_CLK);
|
||||
|
||||
# define I2C_DELAY 1
|
||||
|
||||
void I2C_WriteBit(unsigned char c) {
|
||||
if (c > 0) {
|
||||
I2C_DATA_HI();
|
||||
} else {
|
||||
I2C_DATA_LO();
|
||||
}
|
||||
|
||||
I2C_CLOCK_HI();
|
||||
_delay_us(I2C_DELAY);
|
||||
|
||||
I2C_CLOCK_LO();
|
||||
_delay_us(I2C_DELAY);
|
||||
|
||||
if (c > 0) {
|
||||
I2C_DATA_LO();
|
||||
}
|
||||
|
||||
_delay_us(I2C_DELAY);
|
||||
}
|
||||
|
||||
// Inits bitbanging port, must be called before using the functions below
|
||||
//
|
||||
void I2C_Init(void) {
|
||||
I2C_PORT &= ~((1 << I2C_DAT) | (1 << I2C_CLK));
|
||||
|
||||
I2C_CLOCK_HI();
|
||||
I2C_DATA_HI();
|
||||
|
||||
_delay_us(I2C_DELAY);
|
||||
}
|
||||
|
||||
// Send a START Condition
|
||||
//
|
||||
void I2C_Start(void) {
|
||||
// set both to high at the same time
|
||||
I2C_DDR &= ~((1 << I2C_DAT) | (1 << I2C_CLK));
|
||||
_delay_us(I2C_DELAY);
|
||||
|
||||
I2C_DATA_LO();
|
||||
_delay_us(I2C_DELAY);
|
||||
|
||||
I2C_CLOCK_LO();
|
||||
_delay_us(I2C_DELAY);
|
||||
}
|
||||
|
||||
// Send a STOP Condition
|
||||
//
|
||||
void I2C_Stop(void) {
|
||||
I2C_CLOCK_HI();
|
||||
_delay_us(I2C_DELAY);
|
||||
|
||||
I2C_DATA_HI();
|
||||
_delay_us(I2C_DELAY);
|
||||
}
|
||||
|
||||
// write a byte to the I2C slave device
|
||||
//
|
||||
unsigned char I2C_Write(unsigned char c) {
|
||||
for (char i = 0; i < 8; i++) {
|
||||
I2C_WriteBit(c & 128);
|
||||
|
||||
c <<= 1;
|
||||
}
|
||||
|
||||
I2C_WriteBit(0);
|
||||
_delay_us(I2C_DELAY);
|
||||
_delay_us(I2C_DELAY);
|
||||
|
||||
// _delay_us(I2C_DELAY);
|
||||
// return I2C_ReadBit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
// Set an led in the buffer to a color
|
||||
void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b) {
|
||||
led[i].r = r;
|
||||
led[i].g = g;
|
||||
led[i].b = b;
|
||||
}
|
||||
|
||||
void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b) {
|
||||
for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) {
|
||||
led[i].r = r;
|
||||
led[i].g = g;
|
||||
led[i].b = b;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void ws2812_sendarray(uint8_t *array, uint16_t length);
|
||||
void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);
|
||||
|
||||
// Setleds for standard RGB
|
||||
void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
|
||||
@@ -159,45 +43,15 @@ void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
|
||||
}
|
||||
|
||||
void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask) {
|
||||
// ws2812_DDRREG |= pinmask; // Enable DDR
|
||||
// new universal format (DDR)
|
||||
_SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask;
|
||||
|
||||
ws2812_sendarray_mask((uint8_t *)ledarray, leds + leds + leds, pinmask);
|
||||
_delay_us(50);
|
||||
}
|
||||
ws2812_sendarray_mask((uint8_t *)ledarray, leds * sizeof(LED_TYPE), pinmask);
|
||||
|
||||
// Setleds for SK6812RGBW
|
||||
void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
|
||||
#ifdef RGBW_BB_TWI
|
||||
uint8_t sreg_prev, twcr_prev;
|
||||
sreg_prev = SREG;
|
||||
twcr_prev = TWCR;
|
||||
cli();
|
||||
TWCR &= ~(1 << TWEN);
|
||||
I2C_Init();
|
||||
I2C_Start();
|
||||
I2C_Write(0x84);
|
||||
uint16_t datlen = leds << 2;
|
||||
uint8_t curbyte;
|
||||
uint8_t *data = (uint8_t *)ledarray;
|
||||
while (datlen--) {
|
||||
curbyte = *data++;
|
||||
I2C_Write(curbyte);
|
||||
}
|
||||
I2C_Stop();
|
||||
SREG = sreg_prev;
|
||||
TWCR = twcr_prev;
|
||||
#endif
|
||||
|
||||
// ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
|
||||
// new universal format (DDR)
|
||||
_SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF);
|
||||
|
||||
ws2812_sendarray_mask((uint8_t *)ledarray, leds << 2, _BV(RGB_DI_PIN & 0xF));
|
||||
|
||||
#ifndef RGBW_BB_TWI
|
||||
#ifdef RGBW
|
||||
_delay_us(80);
|
||||
#else
|
||||
_delay_us(50);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LIGHT_WS2812_H_
|
||||
#define LIGHT_WS2812_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
//#include "ws2812_config.h"
|
||||
//#include "i2cmaster.h"
|
||||
#pragma once
|
||||
|
||||
#include "quantum/color.h"
|
||||
|
||||
@@ -40,35 +34,7 @@
|
||||
* The functions will perform the following actions:
|
||||
* - Set the data-out pin as output
|
||||
* - Send out the LED data
|
||||
* - Wait 50<EFBFBD>s to reset the LEDs
|
||||
* - Wait 50us to reset the LEDs
|
||||
*/
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
void ws2812_setled(int index, uint8_t r, uint8_t g, uint8_t b);
|
||||
void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b);
|
||||
#endif
|
||||
|
||||
void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
|
||||
void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
|
||||
void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
|
||||
|
||||
/*
|
||||
* Old interface / Internal functions
|
||||
*
|
||||
* The functions take a byte-array and send to the data output as WS2812 bitstream.
|
||||
* The length is the number of bytes to send - three per LED.
|
||||
*/
|
||||
|
||||
void ws2812_sendarray(uint8_t *array, uint16_t length);
|
||||
void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);
|
||||
|
||||
/*
|
||||
* Internal defines
|
||||
*/
|
||||
#ifndef CONCAT
|
||||
# define CONCAT(a, b) a##b
|
||||
#endif
|
||||
#ifndef CONCAT_EXP
|
||||
# define CONCAT_EXP(a, b) CONCAT(a, b)
|
||||
#endif
|
||||
|
||||
#endif /* LIGHT_WS2812_H_ */
|
||||
|
||||
27
drivers/avr/ws2812_i2c.c
Normal file
27
drivers/avr/ws2812_i2c.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "ws2812.h"
|
||||
#include "i2c_master.h"
|
||||
|
||||
#ifdef RGBW
|
||||
# error "RGBW not supported"
|
||||
#endif
|
||||
|
||||
#ifndef WS2812_ADDRESS
|
||||
# define WS2812_ADDRESS 0xb0
|
||||
#endif
|
||||
|
||||
#ifndef WS2812_TIMEOUT
|
||||
# define WS2812_TIMEOUT 100
|
||||
#endif
|
||||
|
||||
void ws2812_init(void) { i2c_init(); }
|
||||
|
||||
// Setleds for standard RGB
|
||||
void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
|
||||
static bool s_init = false;
|
||||
if (!s_init) {
|
||||
ws2812_init();
|
||||
s_init = true;
|
||||
}
|
||||
|
||||
i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
|
||||
}
|
||||
56
drivers/boards/STM32_F103_STM32DUINO/board.c
Normal file
56
drivers/boards/STM32_F103_STM32DUINO/board.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
// Value to place in RTC backup register 10 for persistent bootloader mode
|
||||
#define RTC_BOOTLOADER_FLAG 0x424C
|
||||
|
||||
/**
|
||||
* @brief PAL setup.
|
||||
* @details Digital I/O ports static configuration as defined in @p board.h.
|
||||
* This variable is used by the HAL when initializing the PAL driver.
|
||||
*/
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
const PALConfig pal_default_config =
|
||||
{
|
||||
{VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
|
||||
{VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
|
||||
{VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
|
||||
{VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
|
||||
{VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Early initialization code.
|
||||
* This initialization must be performed just after stack setup and before
|
||||
* any other initialization.
|
||||
*/
|
||||
void __early_init(void) {
|
||||
|
||||
stm32_clock_init();
|
||||
}
|
||||
|
||||
/*
|
||||
* Board-specific initialization code.
|
||||
*/
|
||||
void boardInit(void) {
|
||||
//JTAG-DP Disabled and SW-DP Enabled
|
||||
AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
|
||||
//Set backup register DR10 to enter bootloader on reset
|
||||
BKP->DR10 = RTC_BOOTLOADER_FLAG;
|
||||
}
|
||||
166
drivers/boards/STM32_F103_STM32DUINO/board.h
Normal file
166
drivers/boards/STM32_F103_STM32DUINO/board.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
/*
|
||||
* Setup for a Generic STM32F103 board.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Board identifier.
|
||||
*/
|
||||
#define BOARD_STM32_F103_STM32DUINO
|
||||
#define BOARD_NAME "GENERIC STM32F103C8T6 board - stm32duino bootloader"
|
||||
|
||||
/*
|
||||
* Board frequencies.
|
||||
*/
|
||||
#define STM32_LSECLK 32768
|
||||
#define STM32_HSECLK 8000000
|
||||
|
||||
/*
|
||||
* MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
|
||||
*/
|
||||
#define STM32F103xB
|
||||
|
||||
/*
|
||||
* IO pins assignments
|
||||
*/
|
||||
|
||||
/* on-board */
|
||||
|
||||
#define GPIOA_LED 8
|
||||
#define GPIOD_OSC_IN 0
|
||||
#define GPIOD_OSC_OUT 1
|
||||
|
||||
/* In case your board has a "USB enable" hardware
|
||||
controlled by a pin, define it here. (It could be just
|
||||
a 1.5k resistor connected to D+ line.)
|
||||
*/
|
||||
/*
|
||||
#define GPIOB_USB_DISC 10
|
||||
*/
|
||||
|
||||
/*
|
||||
* I/O ports initial setup, this configuration is established soon after reset
|
||||
* in the initialization code.
|
||||
*
|
||||
* The digits have the following meaning:
|
||||
* 0 - Analog input.
|
||||
* 1 - Push Pull output 10MHz.
|
||||
* 2 - Push Pull output 2MHz.
|
||||
* 3 - Push Pull output 50MHz.
|
||||
* 4 - Digital input.
|
||||
* 5 - Open Drain output 10MHz.
|
||||
* 6 - Open Drain output 2MHz.
|
||||
* 7 - Open Drain output 50MHz.
|
||||
* 8 - Digital input with PullUp or PullDown resistor depending on ODR.
|
||||
* 9 - Alternate Push Pull output 10MHz.
|
||||
* A - Alternate Push Pull output 2MHz.
|
||||
* B - Alternate Push Pull output 50MHz.
|
||||
* C - Reserved.
|
||||
* D - Alternate Open Drain output 10MHz.
|
||||
* E - Alternate Open Drain output 2MHz.
|
||||
* F - Alternate Open Drain output 50MHz.
|
||||
* Please refer to the STM32 Reference Manual for details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Port A setup.
|
||||
* Everything input with pull-up except:
|
||||
* PA2 - Alternate output (USART2 TX).
|
||||
* PA3 - Normal input (USART2 RX).
|
||||
* PA9 - Alternate output (USART1 TX).
|
||||
* PA10 - Normal input (USART1 RX).
|
||||
*/
|
||||
#define VAL_GPIOACRL 0x88884B88 /* PA7...PA0 */
|
||||
#define VAL_GPIOACRH 0x888884B8 /* PA15...PA8 */
|
||||
#define VAL_GPIOAODR 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port B setup.
|
||||
* Everything input with pull-up except:
|
||||
* PB10 - Push Pull output (USB switch).
|
||||
*/
|
||||
#define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */
|
||||
#define VAL_GPIOBCRH 0x88888388 /* PB15...PB8 */
|
||||
#define VAL_GPIOBODR 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port C setup.
|
||||
* Everything input with pull-up except:
|
||||
* PC13 - Push Pull output (LED).
|
||||
*/
|
||||
#define VAL_GPIOCCRL 0x88888888 /* PC7...PC0 */
|
||||
#define VAL_GPIOCCRH 0x88388888 /* PC15...PC8 */
|
||||
#define VAL_GPIOCODR 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port D setup.
|
||||
* Everything input with pull-up except:
|
||||
* PD0 - Normal input (XTAL).
|
||||
* PD1 - Normal input (XTAL).
|
||||
*/
|
||||
#define VAL_GPIODCRL 0x88888844 /* PD7...PD0 */
|
||||
#define VAL_GPIODCRH 0x88888888 /* PD15...PD8 */
|
||||
#define VAL_GPIODODR 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* Port E setup.
|
||||
* Everything input with pull-up except:
|
||||
*/
|
||||
#define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
|
||||
#define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */
|
||||
#define VAL_GPIOEODR 0xFFFFFFFF
|
||||
|
||||
/*
|
||||
* USB bus activation macro, required by the USB driver.
|
||||
*/
|
||||
/* The point is that most of the generic STM32F103* boards
|
||||
have a 1.5k resistor connected on one end to the D+ line
|
||||
and on the other end to some pin. Or even a slightly more
|
||||
complicated "USB enable" circuit, controlled by a pin.
|
||||
That should go here.
|
||||
|
||||
However on some boards (e.g. one that I have), there's no
|
||||
such hardware. In which case it's better to not do anything.
|
||||
*/
|
||||
/*
|
||||
#define usb_lld_connect_bus(usbp) palClearPad(GPIOB, GPIOB_USB_DISC)
|
||||
*/
|
||||
#define usb_lld_connect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_INPUT);
|
||||
|
||||
/*
|
||||
* USB bus de-activation macro, required by the USB driver.
|
||||
*/
|
||||
/*
|
||||
#define usb_lld_disconnect_bus(usbp) palSetPad(GPIOB, GPIOB_USB_DISC)
|
||||
*/
|
||||
#define usb_lld_disconnect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 12);
|
||||
|
||||
#if !defined(_FROM_ASM_)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void boardInit(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _FROM_ASM_ */
|
||||
|
||||
#endif /* _BOARD_H_ */
|
||||
5
drivers/boards/STM32_F103_STM32DUINO/board.mk
Normal file
5
drivers/boards/STM32_F103_STM32DUINO/board.mk
Normal file
@@ -0,0 +1,5 @@
|
||||
# List of all the board related files.
|
||||
BOARDSRC = $(BOARD_PATH)/boards/STM32_F103_STM32DUINO/board.c
|
||||
|
||||
# Required include directories
|
||||
BOARDINC = $(BOARD_PATH)/boards/STM32_F103_STM32DUINO
|
||||
101
drivers/boards/ld/MK20DX256.ld
Normal file
101
drivers/boards/ld/MK20DX256.ld
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2016 Fabio Utzig, http://fabioutzig.com
|
||||
* (C) 2016 flabbergast <s3+flabbergast@sdfeu.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MK20DX256 memory setup.
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
flash0 : org = 0x00000000, len = 0x400
|
||||
flash1 : org = 0x00000400, len = 0x10
|
||||
flash2 : org = 0x00000410, len = 256k - 0x410
|
||||
flash3 : org = 0x00000000, len = 0
|
||||
flash4 : org = 0x00000000, len = 0
|
||||
flash5 : org = 0x00000000, len = 0
|
||||
flash6 : org = 0x00000000, len = 0
|
||||
flash7 : org = 0x00000000, len = 0
|
||||
ram0 : org = 0x1FFF8000, len = 64k
|
||||
ram1 : org = 0x00000000, len = 0
|
||||
ram2 : org = 0x00000000, len = 0
|
||||
ram3 : org = 0x00000000, len = 0
|
||||
ram4 : org = 0x00000000, len = 0
|
||||
ram5 : org = 0x00000000, len = 0
|
||||
ram6 : org = 0x00000000, len = 0
|
||||
ram7 : org = 0x00000000, len = 0
|
||||
}
|
||||
|
||||
/* Flash region for the configuration bytes.*/
|
||||
SECTIONS
|
||||
{
|
||||
.cfmprotect : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.cfmconfig))
|
||||
} > flash1
|
||||
}
|
||||
|
||||
/* For each data/text section two region are defined, a virtual region
|
||||
and a load region (_LMA suffix).*/
|
||||
|
||||
/* Flash region to be used for exception vectors.*/
|
||||
REGION_ALIAS("VECTORS_FLASH", flash0);
|
||||
REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
|
||||
|
||||
/* Flash region to be used for constructors and destructors.*/
|
||||
REGION_ALIAS("XTORS_FLASH", flash2);
|
||||
REGION_ALIAS("XTORS_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for code text.*/
|
||||
REGION_ALIAS("TEXT_FLASH", flash2);
|
||||
REGION_ALIAS("TEXT_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for read only data.*/
|
||||
REGION_ALIAS("RODATA_FLASH", flash2);
|
||||
REGION_ALIAS("RODATA_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for various.*/
|
||||
REGION_ALIAS("VARIOUS_FLASH", flash2);
|
||||
REGION_ALIAS("VARIOUS_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for RAM(n) initialization data.*/
|
||||
REGION_ALIAS("RAM_INIT_FLASH_LMA", flash2);
|
||||
|
||||
/* RAM region to be used for Main stack. This stack accommodates the processing
|
||||
of all exceptions and interrupts.*/
|
||||
REGION_ALIAS("MAIN_STACK_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for the process stack. This is the stack used by
|
||||
the main() function.*/
|
||||
REGION_ALIAS("PROCESS_STACK_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for data segment.*/
|
||||
REGION_ALIAS("DATA_RAM", ram0);
|
||||
REGION_ALIAS("DATA_RAM_LMA", flash2);
|
||||
|
||||
/* RAM region to be used for BSS segment.*/
|
||||
REGION_ALIAS("BSS_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for the default heap.*/
|
||||
REGION_ALIAS("HEAP_RAM", ram0);
|
||||
|
||||
/* Generic rules inclusion.*/
|
||||
INCLUDE rules.ld
|
||||
105
drivers/boards/ld/MKL26Z64.ld
Normal file
105
drivers/boards/ld/MKL26Z64.ld
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2016 Fabio Utzig, http://fabioutzig.com
|
||||
* (C) 2016 flabbergast <s3+flabbergast@sdfeu.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* KL26Z64 memory setup.
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
flash0 : org = 0x00000000, len = 0x100
|
||||
flash1 : org = 0x00000400, len = 0x10
|
||||
flash2 : org = 0x00000410, len = 62k - 0x410
|
||||
flash3 : org = 0x0000F800, len = 2k
|
||||
flash4 : org = 0x00000000, len = 0
|
||||
flash5 : org = 0x00000000, len = 0
|
||||
flash6 : org = 0x00000000, len = 0
|
||||
flash7 : org = 0x00000000, len = 0
|
||||
ram0 : org = 0x1FFFF800, len = 8k
|
||||
ram1 : org = 0x00000000, len = 0
|
||||
ram2 : org = 0x00000000, len = 0
|
||||
ram3 : org = 0x00000000, len = 0
|
||||
ram4 : org = 0x00000000, len = 0
|
||||
ram5 : org = 0x00000000, len = 0
|
||||
ram6 : org = 0x00000000, len = 0
|
||||
ram7 : org = 0x00000000, len = 0
|
||||
}
|
||||
|
||||
/* Flash region for the configuration bytes.*/
|
||||
SECTIONS
|
||||
{
|
||||
.cfmprotect : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.cfmconfig))
|
||||
} > flash1
|
||||
}
|
||||
|
||||
/* For each data/text section two region are defined, a virtual region
|
||||
and a load region (_LMA suffix).*/
|
||||
|
||||
/* Flash region to be used for exception vectors.*/
|
||||
REGION_ALIAS("VECTORS_FLASH", flash0);
|
||||
REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
|
||||
|
||||
/* Flash region to be used for constructors and destructors.*/
|
||||
REGION_ALIAS("XTORS_FLASH", flash2);
|
||||
REGION_ALIAS("XTORS_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for code text.*/
|
||||
REGION_ALIAS("TEXT_FLASH", flash2);
|
||||
REGION_ALIAS("TEXT_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for read only data.*/
|
||||
REGION_ALIAS("RODATA_FLASH", flash2);
|
||||
REGION_ALIAS("RODATA_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for various.*/
|
||||
REGION_ALIAS("VARIOUS_FLASH", flash2);
|
||||
REGION_ALIAS("VARIOUS_FLASH_LMA", flash2);
|
||||
|
||||
/* Flash region to be used for RAM(n) initialization data.*/
|
||||
REGION_ALIAS("RAM_INIT_FLASH_LMA", flash2);
|
||||
|
||||
/* RAM region to be used for Main stack. This stack accommodates the processing
|
||||
of all exceptions and interrupts.*/
|
||||
REGION_ALIAS("MAIN_STACK_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for the process stack. This is the stack used by
|
||||
the main() function.*/
|
||||
REGION_ALIAS("PROCESS_STACK_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for data segment.*/
|
||||
REGION_ALIAS("DATA_RAM", ram0);
|
||||
REGION_ALIAS("DATA_RAM_LMA", flash2);
|
||||
|
||||
/* RAM region to be used for BSS segment.*/
|
||||
REGION_ALIAS("BSS_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for the default heap.*/
|
||||
REGION_ALIAS("HEAP_RAM", ram0);
|
||||
|
||||
__eeprom_workarea_start__ = ORIGIN(flash3);
|
||||
__eeprom_workarea_size__ = LENGTH(flash3);
|
||||
__eeprom_workarea_end__ = __eeprom_workarea_start__ + __eeprom_workarea_size__;
|
||||
|
||||
/* Generic rules inclusion.*/
|
||||
INCLUDE rules.ld
|
||||
88
drivers/boards/ld/STM32F103x8_stm32duino_bootloader.ld
Normal file
88
drivers/boards/ld/STM32F103x8_stm32duino_bootloader.ld
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ST32F103xB memory setup for use with the maplemini bootloader.
|
||||
* You will have to
|
||||
* #define CORTEX_VTOR_INIT 0x5000
|
||||
* in your projects chconf.h
|
||||
*/
|
||||
MEMORY
|
||||
{
|
||||
flash0 : org = 0x08002000, len = 64k - 0x2000
|
||||
flash1 : org = 0x00000000, len = 0
|
||||
flash2 : org = 0x00000000, len = 0
|
||||
flash3 : org = 0x00000000, len = 0
|
||||
flash4 : org = 0x00000000, len = 0
|
||||
flash5 : org = 0x00000000, len = 0
|
||||
flash6 : org = 0x00000000, len = 0
|
||||
flash7 : org = 0x00000000, len = 0
|
||||
ram0 : org = 0x20000000, len = 20k
|
||||
ram1 : org = 0x00000000, len = 0
|
||||
ram2 : org = 0x00000000, len = 0
|
||||
ram3 : org = 0x00000000, len = 0
|
||||
ram4 : org = 0x00000000, len = 0
|
||||
ram5 : org = 0x00000000, len = 0
|
||||
ram6 : org = 0x00000000, len = 0
|
||||
ram7 : org = 0x00000000, len = 0
|
||||
}
|
||||
|
||||
/* For each data/text section two region are defined, a virtual region
|
||||
and a load region (_LMA suffix).*/
|
||||
|
||||
/* Flash region to be used for exception vectors.*/
|
||||
REGION_ALIAS("VECTORS_FLASH", flash0);
|
||||
REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
|
||||
|
||||
/* Flash region to be used for constructors and destructors.*/
|
||||
REGION_ALIAS("XTORS_FLASH", flash0);
|
||||
REGION_ALIAS("XTORS_FLASH_LMA", flash0);
|
||||
|
||||
/* Flash region to be used for code text.*/
|
||||
REGION_ALIAS("TEXT_FLASH", flash0);
|
||||
REGION_ALIAS("TEXT_FLASH_LMA", flash0);
|
||||
|
||||
/* Flash region to be used for read only data.*/
|
||||
REGION_ALIAS("RODATA_FLASH", flash0);
|
||||
REGION_ALIAS("RODATA_FLASH_LMA", flash0);
|
||||
|
||||
/* Flash region to be used for various.*/
|
||||
REGION_ALIAS("VARIOUS_FLASH", flash0);
|
||||
REGION_ALIAS("VARIOUS_FLASH_LMA", flash0);
|
||||
|
||||
/* Flash region to be used for RAM(n) initialization data.*/
|
||||
REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0);
|
||||
|
||||
/* RAM region to be used for Main stack. This stack accommodates the processing
|
||||
of all exceptions and interrupts.*/
|
||||
REGION_ALIAS("MAIN_STACK_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for the process stack. This is the stack used by
|
||||
the main() function.*/
|
||||
REGION_ALIAS("PROCESS_STACK_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for data segment.*/
|
||||
REGION_ALIAS("DATA_RAM", ram0);
|
||||
REGION_ALIAS("DATA_RAM_LMA", flash0);
|
||||
|
||||
/* RAM region to be used for BSS segment.*/
|
||||
REGION_ALIAS("BSS_RAM", ram0);
|
||||
|
||||
/* RAM region to be used for the default heap.*/
|
||||
REGION_ALIAS("HEAP_RAM", ram0);
|
||||
|
||||
/* Generic rules inclusion.*/
|
||||
INCLUDE rules.ld
|
||||
46
drivers/eeprom/eeprom_custom.c-template
Normal file
46
drivers/eeprom/eeprom_custom.c-template
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Copyright 2019 Nick Brassel (tzarc)
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "eeprom_driver.h"
|
||||
|
||||
void eeprom_driver_init(void) {
|
||||
/* Any initialisation code */
|
||||
}
|
||||
|
||||
void eeprom_driver_erase(void) {
|
||||
/* Wipe out the EEPROM, setting values to zero */
|
||||
}
|
||||
|
||||
void eeprom_read_block(void *buf, const void *addr, size_t len) {
|
||||
/*
|
||||
Read a block of data:
|
||||
buf: target buffer
|
||||
addr: 0-based offset within the EEPROM
|
||||
len: length to read
|
||||
*/
|
||||
}
|
||||
|
||||
void eeprom_write_block(const void *buf, void *addr, size_t len) {
|
||||
/*
|
||||
Write a block of data:
|
||||
buf: target buffer
|
||||
addr: 0-based offset within the EEPROM
|
||||
len: length to write
|
||||
*/
|
||||
}
|
||||
73
drivers/eeprom/eeprom_driver.c
Normal file
73
drivers/eeprom/eeprom_driver.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/* Copyright 2019 Nick Brassel (tzarc)
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "eeprom_driver.h"
|
||||
|
||||
uint8_t eeprom_read_byte(const uint8_t *addr) {
|
||||
uint8_t ret;
|
||||
eeprom_read_block(&ret, addr, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint16_t eeprom_read_word(const uint16_t *addr) {
|
||||
uint16_t ret;
|
||||
eeprom_read_block(&ret, addr, 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t eeprom_read_dword(const uint32_t *addr) {
|
||||
uint32_t ret;
|
||||
eeprom_read_block(&ret, addr, 4);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void eeprom_write_byte(uint8_t *addr, uint8_t value) { eeprom_write_block(&value, addr, 1); }
|
||||
|
||||
void eeprom_write_word(uint16_t *addr, uint16_t value) { eeprom_write_block(&value, addr, 2); }
|
||||
|
||||
void eeprom_write_dword(uint32_t *addr, uint32_t value) { eeprom_write_block(&value, addr, 4); }
|
||||
|
||||
void eeprom_update_block(const void *buf, void *addr, size_t len) {
|
||||
uint8_t read_buf[len];
|
||||
eeprom_read_block(read_buf, addr, len);
|
||||
if (memcmp(buf, read_buf, len) != 0) {
|
||||
eeprom_write_block(buf, addr, len);
|
||||
}
|
||||
}
|
||||
|
||||
void eeprom_update_byte(uint8_t *addr, uint8_t value) {
|
||||
uint8_t orig = eeprom_read_byte(addr);
|
||||
if (orig != value) {
|
||||
eeprom_write_byte(addr, value);
|
||||
}
|
||||
}
|
||||
|
||||
void eeprom_update_word(uint16_t *addr, uint16_t value) {
|
||||
uint16_t orig = eeprom_read_word(addr);
|
||||
if (orig != value) {
|
||||
eeprom_write_word(addr, value);
|
||||
}
|
||||
}
|
||||
|
||||
void eeprom_update_dword(uint32_t *addr, uint32_t value) {
|
||||
uint32_t orig = eeprom_read_dword(addr);
|
||||
if (orig != value) {
|
||||
eeprom_write_dword(addr, value);
|
||||
}
|
||||
}
|
||||
22
drivers/eeprom/eeprom_driver.h
Normal file
22
drivers/eeprom/eeprom_driver.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* Copyright 2019 Nick Brassel (tzarc)
|
||||
*
|
||||
* 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 "eeprom.h"
|
||||
|
||||
void eeprom_driver_init(void);
|
||||
void eeprom_driver_erase(void);
|
||||
120
drivers/eeprom/eeprom_i2c.c
Normal file
120
drivers/eeprom/eeprom_i2c.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* Copyright 2019 Nick Brassel (tzarc)
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
/*
|
||||
Note that the implementations of eeprom_XXXX_YYYY on AVR are normally
|
||||
provided by avr-libc. The same functions are reimplemented below and are
|
||||
rerouted to the external i2c equivalent.
|
||||
|
||||
Seemingly, as this is compiled from within QMK, the object file generated
|
||||
during the build overrides the avr-libc implementation during the linking
|
||||
stage.
|
||||
|
||||
On other platforms such as ARM, there are no provided implementations, so
|
||||
there is nothing to override during linkage.
|
||||
*/
|
||||
|
||||
#include "wait.h"
|
||||
#include "i2c_master.h"
|
||||
#include "eeprom.h"
|
||||
#include "eeprom_i2c.h"
|
||||
|
||||
// #define DEBUG_EEPROM_OUTPUT
|
||||
|
||||
#ifdef DEBUG_EEPROM_OUTPUT
|
||||
# include "print.h"
|
||||
#endif // DEBUG_EEPROM_OUTPUT
|
||||
|
||||
static inline void init_i2c_if_required(void) {
|
||||
static int done = 0;
|
||||
if (!done) {
|
||||
i2c_init();
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void fill_target_address(uint8_t *buffer, const void *addr) {
|
||||
intptr_t p = (intptr_t)addr;
|
||||
for (int i = 0; i < EXTERNAL_EEPROM_ADDRESS_SIZE; ++i) {
|
||||
buffer[EXTERNAL_EEPROM_ADDRESS_SIZE - 1 - i] = p & 0xFF;
|
||||
p >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
void eeprom_driver_init(void) {}
|
||||
|
||||
void eeprom_driver_erase(void) {
|
||||
uint8_t buf[EXTERNAL_EEPROM_PAGE_SIZE];
|
||||
memset(buf, 0x00, EXTERNAL_EEPROM_PAGE_SIZE);
|
||||
for (intptr_t addr = 0; addr < EXTERNAL_EEPROM_BYTE_COUNT; addr += EXTERNAL_EEPROM_PAGE_SIZE) {
|
||||
eeprom_write_block(buf, (void *)addr, EXTERNAL_EEPROM_PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void eeprom_read_block(void *buf, const void *addr, size_t len) {
|
||||
uint8_t complete_packet[EXTERNAL_EEPROM_ADDRESS_SIZE];
|
||||
fill_target_address(complete_packet, addr);
|
||||
|
||||
init_i2c_if_required();
|
||||
i2c_transmit(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), complete_packet, EXTERNAL_EEPROM_ADDRESS_SIZE, 100);
|
||||
i2c_receive(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), buf, len, 100);
|
||||
|
||||
#ifdef DEBUG_EEPROM_OUTPUT
|
||||
dprintf("[EEPROM R] 0x%04X: ", ((int)addr));
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
dprintf(" %02X", (int)(((uint8_t *)buf)[i]));
|
||||
}
|
||||
dprintf("\n");
|
||||
#endif // DEBUG_EEPROM_OUTPUT
|
||||
}
|
||||
|
||||
void eeprom_write_block(const void *buf, void *addr, size_t len) {
|
||||
uint8_t complete_packet[EXTERNAL_EEPROM_ADDRESS_SIZE + EXTERNAL_EEPROM_PAGE_SIZE];
|
||||
uint8_t *read_buf = (uint8_t *)buf;
|
||||
intptr_t target_addr = (intptr_t)addr;
|
||||
|
||||
init_i2c_if_required();
|
||||
while (len > 0) {
|
||||
intptr_t page_offset = target_addr % EXTERNAL_EEPROM_PAGE_SIZE;
|
||||
int write_length = EXTERNAL_EEPROM_PAGE_SIZE - page_offset;
|
||||
if (write_length > len) {
|
||||
write_length = len;
|
||||
}
|
||||
|
||||
fill_target_address(complete_packet, (const void *)target_addr);
|
||||
for (uint8_t i = 0; i < write_length; i++) {
|
||||
complete_packet[EXTERNAL_EEPROM_ADDRESS_SIZE + i] = read_buf[i];
|
||||
}
|
||||
|
||||
#ifdef DEBUG_EEPROM_OUTPUT
|
||||
dprintf("[EEPROM W] 0x%04X: ", ((int)target_addr));
|
||||
for (uint8_t i = 0; i < write_length; i++) {
|
||||
dprintf(" %02X", (int)(read_buf[i]));
|
||||
}
|
||||
dprintf("\n");
|
||||
#endif // DEBUG_EEPROM_OUTPUT
|
||||
|
||||
i2c_transmit(EXTERNAL_EEPROM_I2C_ADDRESS((intptr_t)addr), complete_packet, EXTERNAL_EEPROM_ADDRESS_SIZE + write_length, 100);
|
||||
wait_ms(EXTERNAL_EEPROM_WRITE_TIME);
|
||||
|
||||
read_buf += write_length;
|
||||
target_addr += write_length;
|
||||
len -= write_length;
|
||||
}
|
||||
}
|
||||
115
drivers/eeprom/eeprom_i2c.h
Normal file
115
drivers/eeprom/eeprom_i2c.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* Copyright 2019 Nick Brassel (tzarc)
|
||||
*
|
||||
* 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
|
||||
|
||||
/*
|
||||
Default device configurations:
|
||||
|
||||
For the Sparkfun Qwiic I2C EEPROM module: https://www.sparkfun.com/products/14764
|
||||
#define EEPROM_I2C_CAT24C512 // (part number 24512A)
|
||||
#define EEPROM_I2C_RM24C512C // (part number 24512C)
|
||||
|
||||
For the Sparkfun I2C EEPROM chip: https://www.sparkfun.com/products/525
|
||||
#define EEPROM_I2C_24LC256
|
||||
|
||||
For the Adafruit I2C FRAM chip: https://www.adafruit.com/product/1895
|
||||
#define EEPROM_I2C_MB85RC256V
|
||||
*/
|
||||
#if defined(EEPROM_I2C_CAT24C512)
|
||||
# define EXTERNAL_EEPROM_BYTE_COUNT 65536
|
||||
# define EXTERNAL_EEPROM_PAGE_SIZE 128
|
||||
# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
|
||||
# define EXTERNAL_EEPROM_WRITE_TIME 5
|
||||
#elif defined(EEPROM_I2C_RM24C512C)
|
||||
# define EXTERNAL_EEPROM_BYTE_COUNT 65536
|
||||
# define EXTERNAL_EEPROM_PAGE_SIZE 128
|
||||
# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
|
||||
# define EXTERNAL_EEPROM_WRITE_TIME 3
|
||||
#elif defined(EEPROM_I2C_24LC256)
|
||||
# define EXTERNAL_EEPROM_BYTE_COUNT 32768
|
||||
# define EXTERNAL_EEPROM_PAGE_SIZE 64
|
||||
# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
|
||||
# define EXTERNAL_EEPROM_WRITE_TIME 5
|
||||
#elif defined(EEPROM_I2C_24LC128)
|
||||
# define EXTERNAL_EEPROM_BYTE_COUNT 16384
|
||||
# define EXTERNAL_EEPROM_PAGE_SIZE 64
|
||||
# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
|
||||
# define EXTERNAL_EEPROM_WRITE_TIME 5
|
||||
#elif defined(EEPROM_I2C_MB85RC256V)
|
||||
# define EXTERNAL_EEPROM_BYTE_COUNT 32768
|
||||
# define EXTERNAL_EEPROM_PAGE_SIZE 128
|
||||
# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
|
||||
# define EXTERNAL_EEPROM_WRITE_TIME 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
The base I2C address of the EEPROM.
|
||||
This needs to be shifted up by 1, to match i2c_master requirements.
|
||||
*/
|
||||
#ifndef EXTERNAL_EEPROM_I2C_BASE_ADDRESS
|
||||
# define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100000
|
||||
#endif
|
||||
|
||||
/*
|
||||
The calculated I2C address based on the input memory location.
|
||||
|
||||
For EEPROM chips that embed part of the memory location in the I2C address
|
||||
such as AT24M02 you can use something similar to the following (ensuring the
|
||||
result is shifted by left by 1):
|
||||
|
||||
#define EXTERNAL_EEPROM_I2C_ADDRESS(loc) \
|
||||
(EXTERNAL_EEPROM_I2C_BASE_ADDRESS | ((((loc) >> 16) & 0x07) << 1))
|
||||
|
||||
*/
|
||||
#ifndef EXTERNAL_EEPROM_I2C_ADDRESS
|
||||
# define EXTERNAL_EEPROM_I2C_ADDRESS(loc) (EXTERNAL_EEPROM_I2C_BASE_ADDRESS)
|
||||
#endif
|
||||
|
||||
/*
|
||||
The total size of the EEPROM, in bytes. The EEPROM datasheet will usually
|
||||
specify this value in kbits, and will require conversion to bytes.
|
||||
*/
|
||||
#ifndef EXTERNAL_EEPROM_BYTE_COUNT
|
||||
# define EXTERNAL_EEPROM_BYTE_COUNT 8192
|
||||
#endif
|
||||
|
||||
/*
|
||||
The page size in bytes of the EEPROM, as specified in the datasheet.
|
||||
*/
|
||||
#ifndef EXTERNAL_EEPROM_PAGE_SIZE
|
||||
# define EXTERNAL_EEPROM_PAGE_SIZE 32
|
||||
#endif
|
||||
|
||||
/*
|
||||
The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this
|
||||
will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs
|
||||
>65536, this will likely need to be 2 with the modified variant of
|
||||
EXTERNAL_EEPROM_I2C_ADDRESS above.
|
||||
|
||||
As expected, consult the datasheet for specifics of your EEPROM.
|
||||
*/
|
||||
#ifndef EXTERNAL_EEPROM_ADDRESS_SIZE
|
||||
# define EXTERNAL_EEPROM_ADDRESS_SIZE 2
|
||||
#endif
|
||||
|
||||
/*
|
||||
The write cycle time of the EEPROM in milliseconds, as specified in the
|
||||
datasheet.
|
||||
*/
|
||||
#ifndef EXTERNAL_EEPROM_WRITE_TIME
|
||||
# define EXTERNAL_EEPROM_WRITE_TIME 5
|
||||
#endif
|
||||
52
drivers/eeprom/eeprom_transient.c
Normal file
52
drivers/eeprom/eeprom_transient.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* Copyright 2019 Nick Brassel (tzarc)
|
||||
*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "eeprom_driver.h"
|
||||
#include "eeprom_transient.h"
|
||||
|
||||
__attribute__((aligned(4))) static uint8_t transientBuffer[TRANSIENT_EEPROM_SIZE] = {0};
|
||||
|
||||
size_t clamp_length(intptr_t offset, size_t len) {
|
||||
if (offset + len > TRANSIENT_EEPROM_SIZE) {
|
||||
len = TRANSIENT_EEPROM_SIZE - offset;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void eeprom_driver_init(void) { eeprom_driver_erase(); }
|
||||
|
||||
void eeprom_driver_erase(void) { memset(transientBuffer, 0x00, TRANSIENT_EEPROM_SIZE); }
|
||||
|
||||
void eeprom_read_block(void *buf, const void *addr, size_t len) {
|
||||
intptr_t offset = (intptr_t)addr;
|
||||
memset(buf, 0x00, len);
|
||||
len = clamp_length(offset, len);
|
||||
if (len > 0) {
|
||||
memcpy(buf, &transientBuffer[offset], len);
|
||||
}
|
||||
}
|
||||
|
||||
void eeprom_write_block(const void *buf, void *addr, size_t len) {
|
||||
intptr_t offset = (intptr_t)addr;
|
||||
len = clamp_length(offset, len);
|
||||
if (len > 0) {
|
||||
memcpy(&transientBuffer[offset], buf, len);
|
||||
}
|
||||
}
|
||||
25
drivers/eeprom/eeprom_transient.h
Normal file
25
drivers/eeprom/eeprom_transient.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* Copyright 2019 Nick Brassel (tzarc)
|
||||
*
|
||||
* 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
|
||||
|
||||
/*
|
||||
The size of the transient EEPROM buffer size.
|
||||
*/
|
||||
#ifndef TRANSIENT_EEPROM_SIZE
|
||||
# include "eeconfig.h"
|
||||
# define TRANSIENT_EEPROM_SIZE (((EECONFIG_SIZE + 3) / 4) * 4) // based off eeconfig's current usage, aligned to 4-byte sizes, to deal with LTO
|
||||
#endif
|
||||
@@ -114,6 +114,17 @@ void DRV_init(void) {
|
||||
DRV_write(DRV_GO, 0x01);
|
||||
}
|
||||
|
||||
void DRV_rtp_init(void) {
|
||||
DRV_write(DRV_GO, 0x00);
|
||||
DRV_write(DRV_RTP_INPUT, 20); //20 is the lowest value I've found where haptics can still be felt.
|
||||
DRV_write(DRV_MODE, 0x05);
|
||||
DRV_write(DRV_GO, 0x01);
|
||||
}
|
||||
|
||||
void DRV_amplitude(uint8_t amplitude) {
|
||||
DRV_write(DRV_RTP_INPUT, amplitude);
|
||||
}
|
||||
|
||||
void DRV_pulse(uint8_t sequence) {
|
||||
DRV_write(DRV_GO, 0x00);
|
||||
DRV_write(DRV_WAVEFORM_SEQ_1, sequence);
|
||||
|
||||
@@ -170,6 +170,8 @@
|
||||
void DRV_init(void);
|
||||
void DRV_write(const uint8_t drv_register, const uint8_t settings);
|
||||
uint8_t DRV_read(const uint8_t regaddress);
|
||||
void DRV_rtp_init(void);
|
||||
void DRV_amplitude(const uint8_t amplitude);
|
||||
void DRV_pulse(const uint8_t sequence);
|
||||
|
||||
typedef enum DRV_EFFECT {
|
||||
|
||||
@@ -168,6 +168,15 @@ void haptic_set_mode(uint8_t mode) {
|
||||
xprintf("haptic_config.mode = %u\n", haptic_config.mode);
|
||||
}
|
||||
|
||||
void haptic_set_amplitude(uint8_t amp) {
|
||||
haptic_config.amplitude = amp;
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
xprintf("haptic_config.amplitude = %u\n", haptic_config.amplitude);
|
||||
#ifdef DRV2605L
|
||||
DRV_amplitude(amp);
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_set_buzz(uint8_t buzz) {
|
||||
haptic_config.buzz = buzz;
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
@@ -201,6 +210,53 @@ uint8_t haptic_get_dwell(void) {
|
||||
return haptic_config.dwell;
|
||||
}
|
||||
|
||||
void haptic_enable_continuous(void) {
|
||||
haptic_config.cont = 1;
|
||||
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#ifdef DRV2605L
|
||||
DRV_rtp_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_disable_continuous(void) {
|
||||
haptic_config.cont = 0;
|
||||
xprintf("haptic_config.cont = %u\n", haptic_config.cont);
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#ifdef DRV2605L
|
||||
DRV_write(DRV_MODE,0x00);
|
||||
#endif
|
||||
}
|
||||
|
||||
void haptic_toggle_continuous(void) {
|
||||
#ifdef DRV2605L
|
||||
if (haptic_config.cont) {
|
||||
haptic_disable_continuous();
|
||||
} else {
|
||||
haptic_enable_continuous();
|
||||
}
|
||||
eeconfig_update_haptic(haptic_config.raw);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void haptic_cont_increase(void) {
|
||||
uint8_t amp = haptic_config.amplitude + 10;
|
||||
if (haptic_config.amplitude >= 120) {
|
||||
amp = 120;
|
||||
}
|
||||
haptic_set_amplitude(amp);
|
||||
}
|
||||
|
||||
void haptic_cont_decrease(void) {
|
||||
uint8_t amp = haptic_config.amplitude - 10;
|
||||
if (haptic_config.amplitude < 20) {
|
||||
amp = 20;
|
||||
}
|
||||
haptic_set_amplitude(amp);
|
||||
}
|
||||
|
||||
|
||||
void haptic_play(void) {
|
||||
#ifdef DRV2605L
|
||||
uint8_t play_eff = 0;
|
||||
@@ -213,6 +269,7 @@ void haptic_play(void) {
|
||||
}
|
||||
|
||||
bool process_haptic(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
if (keycode == HPT_ON && record->event.pressed) {
|
||||
haptic_enable();
|
||||
}
|
||||
@@ -243,6 +300,16 @@ bool process_haptic(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode == HPT_DWLD && record->event.pressed) {
|
||||
haptic_dwell_decrease();
|
||||
}
|
||||
if (keycode == HPT_CONT && record->event.pressed) {
|
||||
haptic_toggle_continuous();
|
||||
}
|
||||
if (keycode == HPT_CONI && record->event.pressed) {
|
||||
haptic_cont_increase();
|
||||
}
|
||||
if (keycode == HPT_COND && record->event.pressed) {
|
||||
haptic_cont_decrease();
|
||||
}
|
||||
|
||||
if (haptic_config.enable) {
|
||||
if (record->event.pressed) {
|
||||
// keypress
|
||||
|
||||
@@ -34,12 +34,14 @@
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
bool enable : 1;
|
||||
uint8_t feedback : 2;
|
||||
uint8_t mode : 7;
|
||||
bool buzz : 1;
|
||||
uint8_t dwell : 7;
|
||||
uint16_t reserved : 16;
|
||||
bool enable :1;
|
||||
uint8_t feedback :2;
|
||||
uint8_t mode :7;
|
||||
bool buzz :1;
|
||||
uint8_t dwell :7;
|
||||
bool cont :1;
|
||||
uint8_t amplitude :8;
|
||||
uint16_t reserved :7;
|
||||
};
|
||||
} haptic_config_t;
|
||||
|
||||
@@ -71,6 +73,9 @@ uint8_t haptic_get_mode(void);
|
||||
uint8_t haptic_get_feedback(void);
|
||||
void haptic_dwell_increase(void);
|
||||
void haptic_dwell_decrease(void);
|
||||
void haptic_toggle_continuous(void);
|
||||
void haptic_cont_increase(void);
|
||||
void haptic_cont_decrease(void);
|
||||
|
||||
void haptic_play(void);
|
||||
void haptic_shutdown(void);
|
||||
|
||||
@@ -29,12 +29,8 @@
|
||||
# define SOLENOID_MIN_DWELL 4
|
||||
#endif
|
||||
|
||||
#ifndef SOLENOID_ACTIVE
|
||||
# define SOLENOID_ACTIVE false
|
||||
#endif
|
||||
|
||||
#ifndef SOLENOID_PIN
|
||||
# define SOLENOID_PIN F6
|
||||
# error SOLENOID_PIN not defined
|
||||
#endif
|
||||
|
||||
void solenoid_buzz_on(void);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* 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 <stdint.h>
|
||||
|
||||
@@ -16,21 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
# include <avr/interrupt.h>
|
||||
# include <avr/io.h>
|
||||
# include <util/delay.h>
|
||||
#else
|
||||
# include "wait.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "is31fl3731-simple.h"
|
||||
#include "i2c_master.h"
|
||||
#include "progmem.h"
|
||||
#include "print.h"
|
||||
#include "wait.h"
|
||||
|
||||
// This is a 7-bit address, that gets left-shifted and bit 0
|
||||
// set to 0 for write, 1 for read (as per I2C protocol)
|
||||
@@ -156,6 +144,7 @@ void IS31FL3731_init(uint8_t addr) {
|
||||
|
||||
// enable software shutdown
|
||||
IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00);
|
||||
|
||||
// this delay was copied from other drivers, might not be needed
|
||||
wait_ms(10);
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IS31FL3731_DRIVER_H
|
||||
#define IS31FL3731_DRIVER_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct is31_led {
|
||||
uint8_t driver : 2;
|
||||
@@ -203,5 +205,3 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
#define C9_14 0xB1
|
||||
#define C9_15 0xB2
|
||||
#define C9_16 0xB3
|
||||
|
||||
#endif // IS31FL3731_DRIVER_H
|
||||
|
||||
@@ -15,18 +15,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
# include <avr/interrupt.h>
|
||||
# include <avr/io.h>
|
||||
# include <util/delay.h>
|
||||
#else
|
||||
# include "wait.h"
|
||||
#endif
|
||||
|
||||
#include "is31fl3731.h"
|
||||
#include <string.h>
|
||||
#include "i2c_master.h"
|
||||
#include "progmem.h"
|
||||
#include "wait.h"
|
||||
|
||||
// This is a 7-bit address, that gets left-shifted and bit 0
|
||||
// set to 0 for write, 1 for read (as per I2C protocol)
|
||||
@@ -141,12 +132,9 @@ void IS31FL3731_init(uint8_t addr) {
|
||||
|
||||
// enable software shutdown
|
||||
IS31FL3731_write_register(addr, ISSI_REG_SHUTDOWN, 0x00);
|
||||
// this delay was copied from other drivers, might not be needed
|
||||
#ifdef __AVR__
|
||||
_delay_ms(10);
|
||||
#else
|
||||
|
||||
// this delay was copied from other drivers, might not be needed
|
||||
wait_ms(10);
|
||||
#endif
|
||||
|
||||
// picture mode
|
||||
IS31FL3731_write_register(addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IS31FL3731_DRIVER_H
|
||||
#define IS31FL3731_DRIVER_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -207,5 +206,3 @@ void IS31FL3731_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
#define C9_14 0xB1
|
||||
#define C9_15 0xB2
|
||||
#define C9_16 0xB3
|
||||
|
||||
#endif // IS31FL3731_DRIVER_H
|
||||
|
||||
@@ -16,18 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
# include <avr/interrupt.h>
|
||||
# include <avr/io.h>
|
||||
# include <util/delay.h>
|
||||
#else
|
||||
# include "wait.h"
|
||||
#endif
|
||||
|
||||
#include "is31fl3733.h"
|
||||
#include <string.h>
|
||||
#include "i2c_master.h"
|
||||
#include "progmem.h"
|
||||
#include "wait.h"
|
||||
|
||||
// This is a 7-bit address, that gets left-shifted and bit 0
|
||||
// set to 0 for write, 1 for read (as per I2C protocol)
|
||||
@@ -80,43 +71,54 @@ bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
|
||||
uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}};
|
||||
bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
|
||||
|
||||
void IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
// If the transaction fails function returns false.
|
||||
g_twi_transfer_buffer[0] = reg;
|
||||
g_twi_transfer_buffer[1] = data;
|
||||
|
||||
#if ISSI_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
|
||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
|
||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
|
||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) != 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||
// assumes PG1 is already selected
|
||||
|
||||
// transmit PWM registers in 12 transfers of 16 bytes
|
||||
bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||
// Assumes PG1 is already selected.
|
||||
// If any of the transactions fails function returns false.
|
||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
||||
// g_twi_transfer_buffer[] is 20 bytes
|
||||
|
||||
// iterate over the pwm_buffer contents at 16 byte intervals
|
||||
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
||||
for (int i = 0; i < 192; i += 16) {
|
||||
g_twi_transfer_buffer[0] = i;
|
||||
// copy the data from i to i+15
|
||||
// device will auto-increment register for data after the first byte
|
||||
// thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
|
||||
// Copy the data from i to i+15.
|
||||
// Device will auto-increment register for data after the first byte
|
||||
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
|
||||
for (int j = 0; j < 16; j++) {
|
||||
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
|
||||
}
|
||||
|
||||
#if ISSI_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
|
||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) == 0) break;
|
||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT);
|
||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, ISSI_TIMEOUT) != 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void IS31FL3733_init(uint8_t addr, uint8_t sync) {
|
||||
@@ -157,12 +159,8 @@ void IS31FL3733_init(uint8_t addr, uint8_t sync) {
|
||||
// Disable software shutdown.
|
||||
IS31FL3733_write_register(addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
#ifdef __AVR__
|
||||
_delay_ms(10);
|
||||
#else
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
#endif
|
||||
}
|
||||
|
||||
void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
@@ -213,11 +211,15 @@ void IS31FL3733_set_led_control_register(uint8_t index, bool red, bool green, bo
|
||||
|
||||
void IS31FL3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
// Firstly we need to unlock the command register and select PG1
|
||||
// Firstly we need to unlock the command register and select PG1.
|
||||
IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||
IS31FL3733_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
|
||||
|
||||
IS31FL3733_write_pwm_buffer(addr, g_pwm_buffer[index]);
|
||||
// If any of the transactions fail we risk writing dirty PG0,
|
||||
// refresh page 0 just in case.
|
||||
if (!IS31FL3733_write_pwm_buffer(addr, g_pwm_buffer[index])) {
|
||||
g_led_control_registers_update_required[index] = true;
|
||||
}
|
||||
}
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IS31FL3733_DRIVER_H
|
||||
#define IS31FL3733_DRIVER_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -32,8 +31,8 @@ typedef struct is31_led {
|
||||
extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
|
||||
|
||||
void IS31FL3733_init(uint8_t addr, uint8_t sync);
|
||||
void IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
|
||||
bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
bool IS31FL3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer);
|
||||
|
||||
void IS31FL3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
|
||||
void IS31FL3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
|
||||
@@ -250,5 +249,3 @@ void IS31FL3733_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
#define L_14 0xBD
|
||||
#define L_15 0xBE
|
||||
#define L_16 0xBF
|
||||
|
||||
#endif // IS31FL3733_DRIVER_H
|
||||
|
||||
@@ -14,18 +14,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
# include <avr/interrupt.h>
|
||||
# include <avr/io.h>
|
||||
# include <util/delay.h>
|
||||
#else
|
||||
# include "wait.h"
|
||||
#endif
|
||||
|
||||
#include "is31fl3736.h"
|
||||
#include <string.h>
|
||||
#include "i2c_master.h"
|
||||
#include "progmem.h"
|
||||
#include "wait.h"
|
||||
|
||||
// This is a 7-bit address, that gets left-shifted and bit 0
|
||||
// set to 0 for write, 1 for read (as per I2C protocol)
|
||||
@@ -154,12 +145,8 @@ void IS31FL3736_init(uint8_t addr) {
|
||||
// Disable software shutdown.
|
||||
IS31FL3736_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
#ifdef __AVR__
|
||||
_delay_ms(10);
|
||||
#else
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
#endif
|
||||
}
|
||||
|
||||
void IS31FL3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
@@ -263,7 +250,7 @@ void IS31FL3736_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
|
||||
IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
|
||||
|
||||
IS31FL3736_write_pwm_buffer(addr1, g_pwm_buffer[0]);
|
||||
// IS31FL3736_write_pwm_buffer( addr2, g_pwm_buffer[1] );
|
||||
// IS31FL3736_write_pwm_buffer(addr2, g_pwm_buffer[1]);
|
||||
}
|
||||
g_pwm_buffer_update_required = false;
|
||||
}
|
||||
@@ -275,7 +262,7 @@ void IS31FL3736_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
|
||||
IS31FL3736_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
|
||||
for (int i = 0; i < 24; i++) {
|
||||
IS31FL3736_write_register(addr1, i, g_led_control_registers[0][i]);
|
||||
// IS31FL3736_write_register(addr2, i, g_led_control_registers[1][i] );
|
||||
// IS31FL3736_write_register(addr2, i, g_led_control_registers[1][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
# include <avr/interrupt.h>
|
||||
# include <avr/io.h>
|
||||
# include <util/delay.h>
|
||||
#else
|
||||
# include "wait.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "is31fl3737.h"
|
||||
#include "i2c_master.h"
|
||||
#include "progmem.h"
|
||||
#include "rgb_matrix.h"
|
||||
#include "wait.h"
|
||||
|
||||
// This is a 7-bit address, that gets left-shifted and bit 0
|
||||
// set to 0 for write, 1 for read (as per I2C protocol)
|
||||
@@ -156,12 +147,8 @@ void IS31FL3737_init(uint8_t addr) {
|
||||
// Disable software shutdown.
|
||||
IS31FL3737_write_register(addr, ISSI_REG_CONFIGURATION, 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
#ifdef __AVR__
|
||||
_delay_ms(10);
|
||||
#else
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
#endif
|
||||
}
|
||||
|
||||
void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
@@ -217,7 +204,7 @@ void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
|
||||
IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
|
||||
|
||||
IS31FL3737_write_pwm_buffer(addr1, g_pwm_buffer[0]);
|
||||
// IS31FL3737_write_pwm_buffer( addr2, g_pwm_buffer[1] );
|
||||
// IS31FL3737_write_pwm_buffer(addr2, g_pwm_buffer[1]);
|
||||
}
|
||||
g_pwm_buffer_update_required = false;
|
||||
}
|
||||
@@ -229,7 +216,7 @@ void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
|
||||
IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
|
||||
for (int i = 0; i < 24; i++) {
|
||||
IS31FL3737_write_register(addr1, i, g_led_control_registers[0][i]);
|
||||
// IS31FL3737_write_register(addr2, i, g_led_control_registers[1][i] );
|
||||
// IS31FL3737_write_register(addr2, i, g_led_control_registers[1][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IS31FL3737_DRIVER_H
|
||||
#define IS31FL3737_DRIVER_H
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -202,5 +201,3 @@ void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2);
|
||||
#define L_10 0xBB
|
||||
#define L_11 0xBC
|
||||
#define L_12 0xBD
|
||||
|
||||
#endif // IS31FL3737_DRIVER_H
|
||||
|
||||
@@ -392,6 +392,8 @@ void oled_write_char(const char data, bool invert) {
|
||||
static uint8_t oled_temp_buffer[OLED_FONT_WIDTH];
|
||||
memcpy(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH);
|
||||
|
||||
_Static_assert(sizeof(font) >= ((OLED_FONT_END + 1 - OLED_FONT_START) * OLED_FONT_WIDTH), "OLED_FONT_END references outside array");
|
||||
|
||||
// set the reder buffer data
|
||||
uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index
|
||||
if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) {
|
||||
@@ -431,6 +433,15 @@ void oled_write_ln(const char *data, bool invert) {
|
||||
oled_advance_page(true);
|
||||
}
|
||||
|
||||
void oled_write_raw(const char *data, uint16_t size) {
|
||||
if (size > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE;
|
||||
for (uint16_t i = 0; i < size; i++) {
|
||||
if (oled_buffer[i] == data[i]) continue;
|
||||
oled_buffer[i] = data[i];
|
||||
oled_dirty |= (1 << (i / OLED_BLOCK_SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__AVR__)
|
||||
void oled_write_P(const char *data, bool invert) {
|
||||
uint8_t c = pgm_read_byte(data);
|
||||
@@ -444,6 +455,16 @@ void oled_write_ln_P(const char *data, bool invert) {
|
||||
oled_write_P(data, invert);
|
||||
oled_advance_page(true);
|
||||
}
|
||||
|
||||
void oled_write_raw_P(const char *data, uint16_t size) {
|
||||
if (size > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE;
|
||||
for (uint16_t i = 0; i < size; i++) {
|
||||
uint8_t c = pgm_read_byte(++data);
|
||||
if (oled_buffer[i] == c) continue;
|
||||
oled_buffer[i] = c;
|
||||
oled_dirty |= (1 << (i / OLED_BLOCK_SIZE));
|
||||
}
|
||||
}
|
||||
#endif // defined(__AVR__)
|
||||
|
||||
bool oled_on(void) {
|
||||
|
||||
@@ -131,7 +131,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#endif
|
||||
// unsigned char value of the last character in the font file
|
||||
#if !defined(OLED_FONT_END)
|
||||
# define OLED_FONT_END 224
|
||||
# define OLED_FONT_END 223
|
||||
#endif
|
||||
// Font render width
|
||||
#if !defined(OLED_FONT_WIDTH)
|
||||
@@ -200,6 +200,8 @@ void oled_write(const char *data, bool invert);
|
||||
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
|
||||
void oled_write_ln(const char *data, bool invert);
|
||||
|
||||
void oled_write_raw(const char *data, uint16_t size);
|
||||
|
||||
#if defined(__AVR__)
|
||||
// Writes a PROGMEM string to the buffer at current cursor position
|
||||
// Advances the cursor while writing, inverts the pixels if true
|
||||
@@ -211,6 +213,8 @@ void oled_write_P(const char *data, bool invert);
|
||||
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
|
||||
// Remapped to call 'void oled_write_ln(const char *data, bool invert);' on ARM
|
||||
void oled_write_ln_P(const char *data, bool invert);
|
||||
|
||||
void oled_write_raw_P(const char *data, uint16_t size);
|
||||
#else
|
||||
// Writes a string to the buffer at current cursor position
|
||||
// Advances the cursor while writing, inverts the pixels if true
|
||||
@@ -220,6 +224,8 @@ void oled_write_ln_P(const char *data, bool invert);
|
||||
// Advances the cursor while writing, inverts the pixels if true
|
||||
// Advances the cursor to the next page, wiring ' ' to the remainder of the current page
|
||||
# define oled_write_ln_P(data, invert) oled_write(data, invert)
|
||||
|
||||
# define oled_write_raw_P(data, size) oled_write_raw(data, size)
|
||||
#endif // defined(__AVR__)
|
||||
|
||||
// Can be used to manually turn on the screen if it is off
|
||||
|
||||
@@ -25,9 +25,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define VENDOR_ID 0xFEED
|
||||
#define PRODUCT_ID 0x1307
|
||||
#define DEVICE_VER 0x0001
|
||||
#define MANUFACTURER ErgoDox EZ
|
||||
#define PRODUCT ErgoDox EZ
|
||||
#define MANUFACTURER ZSA
|
||||
#define PRODUCT Ergodox EZ
|
||||
#define DESCRIPTION QMK keyboard firmware for Ergodox EZ
|
||||
#define WEBUSB_LANDING_PAGE_URL u8"configure.ergodox-ez.com"
|
||||
|
||||
/* key matrix size */
|
||||
#define MATRIX_ROWS 14
|
||||
@@ -73,17 +74,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
/* ws2812 RGB LED */
|
||||
#define RGB_DI_PIN D7
|
||||
#define RGBLIGHT_ANIMATIONS
|
||||
#define RGBLED_NUM 15 // Number of LEDs
|
||||
#define RGBLIGHT_HUE_STEP 12
|
||||
#define RGBLIGHT_SAT_STEP 255
|
||||
#define RGBLIGHT_VAL_STEP 12
|
||||
|
||||
// Pick one of the modes
|
||||
// Defaults to 15 mirror, for legacy behavior
|
||||
|
||||
// #define ERGODOX_LED_15 // Addresses 15 LEDs, but same position on both halves
|
||||
// #define ERGODOX_LED_15_MIRROR // Addresses 15 LEDs, but are mirrored
|
||||
// #define ERGODOX_LED_30 // Addresses all 30 LED individually
|
||||
|
||||
/* fix space cadet rollover issue */
|
||||
#define DISABLE_SPACE_CADET_ROLLOVER
|
||||
|
||||
#define RGBW_BB_TWI
|
||||
|
||||
#define RGBW 1
|
||||
#define RGBW
|
||||
|
||||
#define RGBLIGHT_SLEEP
|
||||
|
||||
|
||||
@@ -387,3 +387,39 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset!
|
||||
eeconfig_update_kb(keyboard_config.raw);
|
||||
eeconfig_init_user();
|
||||
}
|
||||
|
||||
#ifdef ORYX_ENABLE
|
||||
static uint16_t loops = 0;
|
||||
static bool is_on = false;
|
||||
|
||||
void matrix_scan_kb(void) {
|
||||
if(webusb_state.pairing == true) {
|
||||
if(loops == 0) {
|
||||
ergodox_right_led_1_off();
|
||||
ergodox_right_led_2_off();
|
||||
ergodox_right_led_3_off();
|
||||
}
|
||||
if(loops % WEBUSB_BLINK_STEPS == 0) {
|
||||
if(is_on) {
|
||||
ergodox_right_led_2_off();
|
||||
}
|
||||
else {
|
||||
ergodox_right_led_2_on();
|
||||
}
|
||||
is_on ^= 1;
|
||||
}
|
||||
if(loops > WEBUSB_BLINK_END) {
|
||||
webusb_state.pairing = false;
|
||||
layer_state_set_user(layer_state);
|
||||
loops = 0;
|
||||
}
|
||||
loops++;
|
||||
}
|
||||
else if(loops > 0) {
|
||||
loops = 0;
|
||||
layer_state_set_user(layer_state);
|
||||
}
|
||||
matrix_scan_user();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
3
keyboards/ergodox_ez/keymaps/oryx/config.h
Normal file
3
keyboards/ergodox_ez/keymaps/oryx/config.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define LAYER_STATE_8BIT
|
||||
147
keyboards/ergodox_ez/keymaps/oryx/keymap.c
Normal file
147
keyboards/ergodox_ez/keymaps/oryx/keymap.c
Normal file
@@ -0,0 +1,147 @@
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "version.h"
|
||||
#include "keymap_german.h"
|
||||
#include "keymap_nordic.h"
|
||||
#include "keymap_french.h"
|
||||
#include "keymap_spanish.h"
|
||||
#include "keymap_hungarian.h"
|
||||
#include "keymap_swedish.h"
|
||||
#include "keymap_br_abnt2.h"
|
||||
#include "keymap_canadian_multilingual.h"
|
||||
#include "keymap_german_ch.h"
|
||||
#include "keymap_jp.h"
|
||||
|
||||
#define KC_MAC_UNDO LGUI(KC_Z)
|
||||
#define KC_MAC_CUT LGUI(KC_X)
|
||||
#define KC_MAC_COPY LGUI(KC_C)
|
||||
#define KC_MAC_PASTE LGUI(KC_V)
|
||||
#define KC_PC_UNDO LCTL(KC_Z)
|
||||
#define KC_PC_CUT LCTL(KC_X)
|
||||
#define KC_PC_COPY LCTL(KC_C)
|
||||
#define KC_PC_PASTE LCTL(KC_V)
|
||||
#define ES_LESS_MAC KC_GRAVE
|
||||
#define ES_GRTR_MAC LSFT(KC_GRAVE)
|
||||
#define ES_BSLS_MAC ALGR(KC_6)
|
||||
|
||||
enum custom_keycodes {
|
||||
RGB_SLD = EZ_SAFE_RANGE,
|
||||
HSV_172_255_255,
|
||||
HSV_86_255_128,
|
||||
HSV_27_255_255,
|
||||
};
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = LAYOUT_ergodox_pretty(
|
||||
WEBUSB_PAIR, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_RIGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINUS,
|
||||
KC_DELETE, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(1), TG(1), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLASH,
|
||||
KC_BSPACE, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(2,KC_SCOLON),LGUI_T(KC_QUOTE),
|
||||
KC_LSHIFT, LCTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_HYPR, KC_MEH, KC_N, KC_M, KC_COMMA, KC_DOT, RCTL_T(KC_SLASH),KC_RSHIFT,
|
||||
LT(1,KC_GRAVE), KC_QUOTE, LALT(KC_LSHIFT),KC_LEFT, KC_RIGHT, KC_UP, KC_DOWN, KC_LBRACKET, KC_RBRACKET, MO(1),
|
||||
LALT_T(KC_APPLICATION),KC_LGUI, KC_LALT, LCTL_T(KC_ESCAPE),
|
||||
KC_HOME, KC_PGUP,
|
||||
KC_SPACE, KC_BSPACE, KC_END, KC_PGDOWN, KC_TAB, KC_ENTER
|
||||
),
|
||||
[1] = LAYOUT_ergodox_pretty(
|
||||
KC_ESCAPE, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRANSPARENT, KC_TRANSPARENT, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
|
||||
KC_TRANSPARENT, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRANSPARENT, KC_TRANSPARENT, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12,
|
||||
KC_TRANSPARENT, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRAVE, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_PERC, KC_CIRC, KC_LBRACKET, KC_RBRACKET, KC_TILD, KC_TRANSPARENT, KC_TRANSPARENT, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLASH, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_DOT, KC_0, KC_EQUAL, KC_TRANSPARENT,
|
||||
RGB_MOD, HSV_172_255_255,RGB_TOG, RGB_SLD,
|
||||
HSV_86_255_128, KC_TRANSPARENT,
|
||||
RGB_VAD, RGB_VAI, HSV_27_255_255, KC_TRANSPARENT, RGB_HUD, RGB_HUI
|
||||
),
|
||||
[2] = LAYOUT_ergodox_pretty(
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_UP, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PLAY_PAUSE,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PREV_TRACK,KC_MEDIA_NEXT_TRACK,KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_BTN1, KC_MS_BTN2, KC_AUDIO_VOL_UP,KC_AUDIO_VOL_DOWN,KC_AUDIO_MUTE, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_WWW_BACK
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
bool suspended = false;
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
case RGB_SLD:
|
||||
if (record->event.pressed) {
|
||||
rgblight_mode(1);
|
||||
}
|
||||
return false;
|
||||
case HSV_172_255_255:
|
||||
if (record->event.pressed) {
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
rgblight_enable();
|
||||
rgblight_mode(1);
|
||||
rgblight_sethsv(172,255,255);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
case HSV_86_255_128:
|
||||
if (record->event.pressed) {
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
rgblight_enable();
|
||||
rgblight_mode(1);
|
||||
rgblight_sethsv(86,255,128);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
case HSV_27_255_255:
|
||||
if (record->event.pressed) {
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
rgblight_enable();
|
||||
rgblight_mode(1);
|
||||
rgblight_sethsv(27,255,255);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
layer_state_t layer_state_set_user(layer_state_t state) {
|
||||
|
||||
uint8_t layer = biton32(state);
|
||||
|
||||
ergodox_board_led_off();
|
||||
ergodox_right_led_1_off();
|
||||
ergodox_right_led_2_off();
|
||||
ergodox_right_led_3_off();
|
||||
switch (layer) {
|
||||
case 1:
|
||||
ergodox_right_led_1_on();
|
||||
break;
|
||||
case 2:
|
||||
ergodox_right_led_2_on();
|
||||
break;
|
||||
case 3:
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
case 4:
|
||||
ergodox_right_led_1_on();
|
||||
ergodox_right_led_2_on();
|
||||
break;
|
||||
case 5:
|
||||
ergodox_right_led_1_on();
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
case 6:
|
||||
ergodox_right_led_2_on();
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
case 7:
|
||||
ergodox_right_led_1_on();
|
||||
ergodox_right_led_2_on();
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return state;
|
||||
|
||||
};
|
||||
1
keyboards/ergodox_ez/keymaps/oryx/rules.mk
Normal file
1
keyboards/ergodox_ez/keymaps/oryx/rules.mk
Normal file
@@ -0,0 +1 @@
|
||||
ORYX_ENABLE = yes
|
||||
1
keyboards/ergodox_ez/keymaps/webusb/default.png.md
Normal file
1
keyboards/ergodox_ez/keymaps/webusb/default.png.md
Normal file
@@ -0,0 +1 @@
|
||||
https://i.imgur.com/fKX0Zbs.png
|
||||
@@ -0,0 +1 @@
|
||||
https://i.imgur.com/giAc3M9.jpg
|
||||
147
keyboards/ergodox_ez/keymaps/webusb/keymap.c
Normal file
147
keyboards/ergodox_ez/keymaps/webusb/keymap.c
Normal file
@@ -0,0 +1,147 @@
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "version.h"
|
||||
#include "keymap_german.h"
|
||||
#include "keymap_nordic.h"
|
||||
#include "keymap_french.h"
|
||||
#include "keymap_spanish.h"
|
||||
#include "keymap_hungarian.h"
|
||||
#include "keymap_swedish.h"
|
||||
#include "keymap_br_abnt2.h"
|
||||
#include "keymap_canadian_multilingual.h"
|
||||
#include "keymap_german_ch.h"
|
||||
#include "keymap_jp.h"
|
||||
|
||||
#define KC_MAC_UNDO LGUI(KC_Z)
|
||||
#define KC_MAC_CUT LGUI(KC_X)
|
||||
#define KC_MAC_COPY LGUI(KC_C)
|
||||
#define KC_MAC_PASTE LGUI(KC_V)
|
||||
#define KC_PC_UNDO LCTL(KC_Z)
|
||||
#define KC_PC_CUT LCTL(KC_X)
|
||||
#define KC_PC_COPY LCTL(KC_C)
|
||||
#define KC_PC_PASTE LCTL(KC_V)
|
||||
#define ES_LESS_MAC KC_GRAVE
|
||||
#define ES_GRTR_MAC LSFT(KC_GRAVE)
|
||||
#define ES_BSLS_MAC ALGR(KC_6)
|
||||
|
||||
enum custom_keycodes {
|
||||
RGB_SLD = EZ_SAFE_RANGE,
|
||||
HSV_172_255_255,
|
||||
HSV_86_255_128,
|
||||
HSV_27_255_255,
|
||||
};
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[0] = LAYOUT_ergodox_pretty(
|
||||
WEBUSB_PAIR, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_RIGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINUS,
|
||||
KC_DELETE, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(1), TG(1), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLASH,
|
||||
KC_BSPACE, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(2,KC_SCOLON),LGUI_T(KC_QUOTE),
|
||||
KC_LSHIFT, LCTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_HYPR, KC_MEH, KC_N, KC_M, KC_COMMA, KC_DOT, RCTL_T(KC_SLASH),KC_RSHIFT,
|
||||
LT(1,KC_GRAVE), KC_QUOTE, LALT(KC_LSHIFT),KC_LEFT, KC_RIGHT, KC_UP, KC_DOWN, KC_LBRACKET, KC_RBRACKET, MO(1),
|
||||
LALT_T(KC_APPLICATION),KC_LGUI, KC_LALT, LCTL_T(KC_ESCAPE),
|
||||
KC_HOME, KC_PGUP,
|
||||
KC_SPACE, KC_BSPACE, KC_END, KC_PGDOWN, KC_TAB, KC_ENTER
|
||||
),
|
||||
[1] = LAYOUT_ergodox_pretty(
|
||||
KC_ESCAPE, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRANSPARENT, KC_TRANSPARENT, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
|
||||
KC_TRANSPARENT, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRANSPARENT, KC_TRANSPARENT, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12,
|
||||
KC_TRANSPARENT, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRAVE, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_PERC, KC_CIRC, KC_LBRACKET, KC_RBRACKET, KC_TILD, KC_TRANSPARENT, KC_TRANSPARENT, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLASH, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_DOT, KC_0, KC_EQUAL, KC_TRANSPARENT,
|
||||
RGB_MOD, HSV_172_255_255,RGB_TOG, RGB_SLD,
|
||||
HSV_86_255_128, KC_TRANSPARENT,
|
||||
RGB_VAD, RGB_VAI, HSV_27_255_255, KC_TRANSPARENT, RGB_HUD, RGB_HUI
|
||||
),
|
||||
[2] = LAYOUT_ergodox_pretty(
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_UP, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PLAY_PAUSE,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PREV_TRACK,KC_MEDIA_NEXT_TRACK,KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_BTN1, KC_MS_BTN2, KC_AUDIO_VOL_UP,KC_AUDIO_VOL_DOWN,KC_AUDIO_MUTE, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT,
|
||||
KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_WWW_BACK
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
bool suspended = false;
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
case RGB_SLD:
|
||||
if (record->event.pressed) {
|
||||
rgblight_mode(1);
|
||||
}
|
||||
return false;
|
||||
case HSV_172_255_255:
|
||||
if (record->event.pressed) {
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
rgblight_enable();
|
||||
rgblight_mode(1);
|
||||
rgblight_sethsv(172,255,255);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
case HSV_86_255_128:
|
||||
if (record->event.pressed) {
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
rgblight_enable();
|
||||
rgblight_mode(1);
|
||||
rgblight_sethsv(86,255,128);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
case HSV_27_255_255:
|
||||
if (record->event.pressed) {
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
rgblight_enable();
|
||||
rgblight_mode(1);
|
||||
rgblight_sethsv(27,255,255);
|
||||
#endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
layer_state_t layer_state_set_user(layer_state_t state) {
|
||||
|
||||
uint8_t layer = get_highest_layer(state);
|
||||
|
||||
ergodox_board_led_off();
|
||||
ergodox_right_led_1_off();
|
||||
ergodox_right_led_2_off();
|
||||
ergodox_right_led_3_off();
|
||||
switch (layer) {
|
||||
case 1:
|
||||
ergodox_right_led_1_on();
|
||||
break;
|
||||
case 2:
|
||||
ergodox_right_led_2_on();
|
||||
break;
|
||||
case 3:
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
case 4:
|
||||
ergodox_right_led_1_on();
|
||||
ergodox_right_led_2_on();
|
||||
break;
|
||||
case 5:
|
||||
ergodox_right_led_1_on();
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
case 6:
|
||||
ergodox_right_led_2_on();
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
case 7:
|
||||
ergodox_right_led_1_on();
|
||||
ergodox_right_led_2_on();
|
||||
ergodox_right_led_3_on();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return state;
|
||||
|
||||
};
|
||||
15
keyboards/ergodox_ez/keymaps/webusb/readme.md
Normal file
15
keyboards/ergodox_ez/keymaps/webusb/readme.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# ErgoDox EZ Default Configuration
|
||||
|
||||
## Changelog
|
||||
|
||||
* Dec 2016:
|
||||
* Added LED keys
|
||||
* Refreshed layout graphic, comes from http://configure.ergodox-ez.com now.
|
||||
* Sep 22, 2016:
|
||||
* Created a new key in layer 1 (bottom-corner key) that resets the EEPROM.
|
||||
* Feb 2, 2016 (V1.1):
|
||||
* Made the right-hand quote key double as Cmd/Win on hold. So you get ' when you tap it, " when you tap it with Shift, and Cmd or Win when you hold it. You can then use it as a modifier, or just press and hold it for a moment (and then let go) to send a single Cmd or Win keystroke (handy for opening the Start menu on Windows).
|
||||
|
||||
This is what we ship with out of the factory. :) The image says it all:
|
||||
|
||||

|
||||
1
keyboards/ergodox_ez/keymaps/webusb/rules.mk
Normal file
1
keyboards/ergodox_ez/keymaps/webusb/rules.mk
Normal file
@@ -0,0 +1 @@
|
||||
WEBUSB_ENABLE = yes
|
||||
91
keyboards/ergodox_ez/led_i2c.c
Normal file
91
keyboards/ergodox_ez/led_i2c.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* light weight WS2812 lib V2.0b
|
||||
*
|
||||
* Controls WS2811/WS2812/WS2812B RGB-LEDs
|
||||
* Author: Tim (cpldcpu@gmail.com)
|
||||
*
|
||||
* Jan 18th, 2014 v2.0b Initial Version
|
||||
* Nov 29th, 2015 v2.3 Added SK6812RGBW support
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
|
||||
# include "ws2812.c"
|
||||
# include "ergodox_ez.h"
|
||||
|
||||
extern rgblight_config_t rgblight_config;
|
||||
|
||||
/*
|
||||
* Forward declare internal functions
|
||||
*
|
||||
* The functions take a byte-array and send to the data output as WS2812 bitstream.
|
||||
* The length is the number of bytes to send - three per LED.
|
||||
*/
|
||||
|
||||
void ws2812_sendarray(uint8_t *array, uint16_t length);
|
||||
void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);
|
||||
|
||||
|
||||
|
||||
|
||||
void rgblight_set(void) {
|
||||
if (!rgblight_config.enable) {
|
||||
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
|
||||
led[i].r = 0;
|
||||
led[i].g = 0;
|
||||
led[i].b = 0;
|
||||
#ifdef RGBW
|
||||
led[i].w = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef RGBW
|
||||
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
|
||||
convert_rgb_to_rgbw(&led[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t led_num = RGBLED_NUM;
|
||||
i2c_init();
|
||||
i2c_start(0x84, ERGODOX_EZ_I2C_TIMEOUT);
|
||||
int i = 0;
|
||||
# if defined(ERGODOX_LED_30)
|
||||
// prevent right-half code from trying to bitbang all 30
|
||||
// so with 30 LEDs, we count from 29 to 15 here, and the
|
||||
// other half does 0 to 14.
|
||||
led_num = RGBLED_NUM / 2;
|
||||
for (i = led_num + led_num - 1; i >= led_num; --i)
|
||||
# elif defined(ERGODOX_LED_15_MIRROR)
|
||||
for (i = 0; i < led_num; ++i)
|
||||
# else // ERGDOX_LED_15 non-mirrored
|
||||
for (i = led_num - 1; i >= 0; --i)
|
||||
# endif
|
||||
{
|
||||
uint8_t *data = (uint8_t *)(led + i);
|
||||
i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
|
||||
i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
|
||||
i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
|
||||
#ifdef RGBW
|
||||
i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
i2c_stop();
|
||||
|
||||
ws2812_setleds(led, RGBLED_NUM);
|
||||
}
|
||||
|
||||
|
||||
#endif // RGBLIGHT_ENABLE
|
||||
@@ -35,9 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include "matrix.h"
|
||||
#include "debounce.h"
|
||||
#include QMK_KEYBOARD_H
|
||||
#ifdef DEBUG_MATRIX_SCAN_RATE
|
||||
# include "timer.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This constant define not debouncing time in msecs, assuming eager_pr.
|
||||
@@ -67,11 +64,6 @@ static void select_row(uint8_t row);
|
||||
static uint8_t mcp23018_reset_loop;
|
||||
// static uint16_t mcp23018_reset_loop;
|
||||
|
||||
#ifdef DEBUG_MATRIX_SCAN_RATE
|
||||
uint32_t matrix_timer;
|
||||
uint32_t matrix_scan_count;
|
||||
#endif
|
||||
|
||||
__attribute__((weak)) void matrix_init_user(void) {}
|
||||
|
||||
__attribute__((weak)) void matrix_scan_user(void) {}
|
||||
@@ -95,13 +87,9 @@ void matrix_init(void) {
|
||||
// initialize matrix state: all keys off
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
matrix[i] = 0;
|
||||
raw_matrix[i] = 0;
|
||||
raw_matrix[i] = 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MATRIX_SCAN_RATE
|
||||
matrix_timer = timer_read32();
|
||||
matrix_scan_count = 0;
|
||||
#endif
|
||||
debounce_init(MATRIX_ROWS);
|
||||
matrix_init_quantum();
|
||||
}
|
||||
@@ -116,11 +104,6 @@ void matrix_power_up(void) {
|
||||
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
|
||||
}
|
||||
|
||||
// Reads and stores a row, returning
|
||||
@@ -146,29 +129,18 @@ uint8_t matrix_scan(void) {
|
||||
print("left side not responding\n");
|
||||
} else {
|
||||
print("left side attached\n");
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
rgb_matrix_init();
|
||||
#endif
|
||||
ergodox_blink_all_leds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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_timer = timer_now;
|
||||
matrix_scan_count = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LEFT_LEDS
|
||||
mcp23018_status = ergodox_left_leds_update();
|
||||
#endif // LEFT_LEDS
|
||||
bool changed = false;
|
||||
bool changed = false;
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS_PER_SIDE; i++) {
|
||||
// select rows from left and right hands
|
||||
uint8_t left_index = i;
|
||||
@@ -178,13 +150,13 @@ uint8_t matrix_scan(void) {
|
||||
|
||||
// we don't need a 30us delay anymore, because selecting a
|
||||
// left-hand row requires more than 30us for i2c.
|
||||
|
||||
|
||||
changed |= store_raw_matrix_row(left_index);
|
||||
changed |= store_raw_matrix_row(right_index);
|
||||
|
||||
unselect_rows();
|
||||
}
|
||||
|
||||
|
||||
debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
|
||||
matrix_scan_quantum();
|
||||
|
||||
|
||||
20
keyboards/ergodox_ez/post_config.h
Normal file
20
keyboards/ergodox_ez/post_config.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#if !defined(ERGODOX_LED_15) && !defined(ERGODOX_LED_30)
|
||||
// if no value is defined, assume previous behavior
|
||||
// # define ERGODOX_LED_15
|
||||
// # define ERGODOX_LED_30
|
||||
# define ERGODOX_LED_15_MIRROR
|
||||
#endif
|
||||
|
||||
#if (defined(ERGODOX_LED_30) + defined(ERGODOX_LED_15) + defined(ERGODOX_LED_15_MIRROR)) != 1
|
||||
# error "You must only define one of the ERGODOX_LED options."
|
||||
#endif
|
||||
|
||||
#ifdef ERGODOX_LED_30
|
||||
// If using 30 LEDs, then define that many
|
||||
# define RGBLED_NUM 30 // Number of LEDs
|
||||
#else
|
||||
// If not, then only define 15
|
||||
# define RGBLED_NUM 15 // Number of LEDs
|
||||
#endif
|
||||
@@ -14,10 +14,6 @@
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# # project specific files
|
||||
SRC += matrix.c
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
|
||||
# MCU name
|
||||
MCU = atmega32u4
|
||||
|
||||
@@ -83,7 +79,14 @@ SWAP_HANDS_ENABLE= yes # Allow swapping hands of keyboard
|
||||
SLEEP_LED_ENABLE = no
|
||||
API_SYSEX_ENABLE = no
|
||||
RGBLIGHT_ENABLE = yes
|
||||
RGBLIGHT_CUSTOM_DRIVER = yes
|
||||
|
||||
RGB_MATRIX_ENABLE = no # enable later
|
||||
DEBOUNCE_TYPE = eager_pr
|
||||
|
||||
# project specific files
|
||||
SRC += matrix.c \
|
||||
led_i2c.c
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
|
||||
LAYOUTS = ergodox
|
||||
|
||||
118
keyboards/moonlander/config.h
Normal file
118
keyboards/moonlander/config.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
|
||||
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 */
|
||||
// clang-format off
|
||||
#define VENDOR_ID 0x3297
|
||||
#define PRODUCT_ID 0x1969
|
||||
#define MANUFACTURER ZSA
|
||||
#define PRODUCT Moonlander
|
||||
#define DESCRIPTION A keyboard
|
||||
#define DEVICE_VER 0x0001
|
||||
#define WEBUSB_LANDING_PAGE_URL u8"configure.ergodox-ez.com"
|
||||
|
||||
// clang-format on
|
||||
|
||||
/* key matrix size */
|
||||
#define MATRIX_ROWS 12
|
||||
#define MATRIX_COLS 7
|
||||
|
||||
/* Planck PCB default pin-out */
|
||||
// #define MATRIX_ROW_PINS { B10, B11, B12, B13, B14, B15 }
|
||||
// #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6 }
|
||||
|
||||
// #define MCP23_ROW_PINS { GPB5, GBP4, GBP3, GBP2, GBP1, GBP0 }
|
||||
// #define MCP23_COL_PINS { GPA0, GBA1, GBA2, GBA3, GBA4, GBA5, GBA6 }
|
||||
|
||||
// #define MCP23_LED_R GPB7
|
||||
// #define MCP23_LED_G GPB6
|
||||
// #define MCP23_LED_B GPA7
|
||||
|
||||
#define EEPROM_I2C_24LC128
|
||||
|
||||
// Not needed, is default address:
|
||||
// #define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100000
|
||||
|
||||
/* COL2ROW or ROW2COL */
|
||||
#define DIODE_DIRECTION ROW2COL
|
||||
|
||||
/* Set 0 if debouncing isn't needed */
|
||||
#define DEBOUNCE 5
|
||||
|
||||
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||
#define LOCKING_SUPPORT_ENABLE
|
||||
/* Locking resynchronize hack */
|
||||
#define LOCKING_RESYNC_ENABLE
|
||||
|
||||
/*
|
||||
* Feature disable options
|
||||
* These options are also useful to firmware size reduction.
|
||||
*/
|
||||
|
||||
/* disable debug print */
|
||||
//#define NO_DEBUG
|
||||
|
||||
/* disable print */
|
||||
//#define NO_PRINT
|
||||
|
||||
/* disable action features */
|
||||
//#define NO_ACTION_LAYER
|
||||
//#define NO_ACTION_TAPPING
|
||||
//#define NO_ACTION_ONESHOT
|
||||
#ifndef LINK_TIME_OPTIMIZATION_ENABLE
|
||||
# define NO_ACTION_MACRO
|
||||
# define NO_ACTION_FUNCTION
|
||||
#endif
|
||||
|
||||
#define I2C1_CLOCK_SPEED 400000
|
||||
|
||||
#define DRIVER_ADDR_1 0b1110100
|
||||
#define DRIVER_ADDR_2 0b1110111
|
||||
|
||||
#define DRIVER_COUNT 2
|
||||
#define DRIVER_1_LED_TOTAL 36
|
||||
#define DRIVER_2_LED_TOTAL 36
|
||||
#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
|
||||
#define RGB_MATRIX_CENTER \
|
||||
{ 125, 26 }
|
||||
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 175 // limits maximum brightness of LEDs to 200 out of 255. If not defined maximum brightness is set to 255
|
||||
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
|
||||
#define RGB_MATRIX_KEYPRESSES
|
||||
#define RGB_DISABLE_WHEN_USB_SUSPENDED true
|
||||
|
||||
// #define RGB_MATRIX_LED_PROCESS_LIMIT 5
|
||||
// #define RGB_MATRIX_LED_FLUSH_LIMIT 26
|
||||
|
||||
#define IGNORE_MOD_TAP_INTERRUPT
|
||||
|
||||
#define TAPPING_TOGGLE 1
|
||||
|
||||
#define MOUSEKEY_INTERVAL 20
|
||||
#define MOUSEKEY_DELAY 0
|
||||
#define MOUSEKEY_TIME_TO_MAX 60
|
||||
#define MOUSEKEY_MAX_SPEED 7
|
||||
#define MOUSEKEY_WHEEL_DELAY 0
|
||||
|
||||
#define MUSIC_MAP
|
||||
|
||||
|
||||
#define FIRMWARE_VERSION_SIZE 17
|
||||
#define DYNAMIC_KEYMAP_EEPROM_ADDR (EECONFIG_SIZE + FIRMWARE_VERSION_SIZE)
|
||||
3
keyboards/moonlander/keymaps/default/config.h
Normal file
3
keyboards/moonlander/keymaps/default/config.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define ORYX_CONFIGURATOR
|
||||
79
keyboards/moonlander/keymaps/default/keymap.c
Normal file
79
keyboards/moonlander/keymaps/default/keymap.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
|
||||
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
|
||||
#include "version.h"
|
||||
|
||||
enum layers {
|
||||
BASE, // default layer
|
||||
SYMB, // symbols
|
||||
MDIA, // media keys
|
||||
};
|
||||
|
||||
enum custom_keycodes {
|
||||
EPRM = ML_SAFE_RANGE,
|
||||
VRSN,
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[BASE] = LAYOUT_moonlander(
|
||||
KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_RGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,
|
||||
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(SYMB), TG(SYMB), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
|
||||
KC_BSPC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_HYPR, KC_MEH, KC_H, KC_J, KC_K, KC_L, LT(MDIA, KC_SCLN), GUI_T(KC_QUOT),
|
||||
KC_LSFT, LCTL_T(KC_Z),KC_X,KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, LCTL_T(KC_SLSH), KC_LSFT,
|
||||
LT(SYMB,KC_GRV),WEBUSB_PAIR,A(KC_LSFT),KC_LEFT, KC_RGHT, LALT_T(KC_APP), RCTL_T(KC_ESC), KC_UP, KC_DOWN, KC_LBRC, KC_RBRC, TT(SYMB),
|
||||
KC_SPC, KC_BSPC, KC_LGUI, KC_RALT, KC_TAB, KC_ENT
|
||||
),
|
||||
|
||||
[SYMB] = LAYOUT_moonlander(
|
||||
VRSN, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRNS, KC_TRNS, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
|
||||
KC_TRNS, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRNS, KC_TRNS, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12,
|
||||
KC_TRNS, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV, KC_TRNS, KC_TRNS, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRNS,
|
||||
KC_TRNS, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLS, KC_TRNS,
|
||||
EPRM, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_VAI, RGB_TOG, KC_TRNS, KC_DOT, KC_0, KC_EQL, KC_TRNS,
|
||||
RGB_HUD, RGB_VAD, RGB_HUI, TOGGLE_LAYER_COLOR,KC_TRNS, KC_TRNS
|
||||
),
|
||||
|
||||
[MDIA] = LAYOUT_moonlander(
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_U, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_BTN2, KC_TRNS, KC_TRNS, KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
|
||||
),
|
||||
};
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
if (record->event.pressed) {
|
||||
switch (keycode) {
|
||||
case EPRM:
|
||||
eeconfig_init();
|
||||
return false;
|
||||
case VRSN:
|
||||
SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION);
|
||||
return false;
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
case RGB_SLD:
|
||||
rgblight_mode(1);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
3
keyboards/moonlander/keymaps/oryx/config.h
Normal file
3
keyboards/moonlander/keymaps/oryx/config.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "../default/config.h"
|
||||
1
keyboards/moonlander/keymaps/oryx/keymap.c
Normal file
1
keyboards/moonlander/keymaps/oryx/keymap.c
Normal file
@@ -0,0 +1 @@
|
||||
// placeholder
|
||||
6
keyboards/moonlander/keymaps/oryx/rules.mk
Normal file
6
keyboards/moonlander/keymaps/oryx/rules.mk
Normal file
@@ -0,0 +1,6 @@
|
||||
SRC += ../default/keymap.c
|
||||
-include ../default/rules.mk
|
||||
|
||||
WEBUSB_ENABLE = yes
|
||||
ORYX_ENABLE = yes
|
||||
DYNAMIC_KEYMAP_ENABLE = yes
|
||||
3
keyboards/moonlander/keymaps/webusb/config.h
Normal file
3
keyboards/moonlander/keymaps/webusb/config.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "../default/config.h"
|
||||
1
keyboards/moonlander/keymaps/webusb/keymap.c
Normal file
1
keyboards/moonlander/keymaps/webusb/keymap.c
Normal file
@@ -0,0 +1 @@
|
||||
// placeholder
|
||||
4
keyboards/moonlander/keymaps/webusb/rules.mk
Normal file
4
keyboards/moonlander/keymaps/webusb/rules.mk
Normal file
@@ -0,0 +1,4 @@
|
||||
SRC += ../default/keymap.c
|
||||
-include ../default/rules.mk
|
||||
|
||||
WEBUSB_ENABLE = yes
|
||||
261
keyboards/moonlander/matrix.c
Normal file
261
keyboards/moonlander/matrix.c
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
|
||||
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 <string.h>
|
||||
#include "hal.h"
|
||||
#include "timer.h"
|
||||
#include "wait.h"
|
||||
#include "printf.h"
|
||||
#include "matrix.h"
|
||||
#include "action.h"
|
||||
#include "keycode.h"
|
||||
#include <string.h>
|
||||
#include "moonlander.h"
|
||||
#include "i2c_master.h"
|
||||
#include "debounce.h"
|
||||
|
||||
/*
|
||||
#define MATRIX_ROW_PINS { B10, B11, B12, B13, B14, B15 } outputs
|
||||
#define MATRIX_COL_PINS { A0, A1, A2, A3, A6, A7, B0 } inputs
|
||||
*/
|
||||
/* matrix state(1:on, 0:off) */
|
||||
static matrix_row_t matrix[MATRIX_ROWS];
|
||||
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||
static matrix_row_t matrix_debouncing_right[MATRIX_COLS];
|
||||
static bool debouncing = false;
|
||||
static uint16_t debouncing_time = 0;
|
||||
static bool debouncing_right = false;
|
||||
static uint16_t debouncing_time_right = 0;
|
||||
|
||||
#define ROWS_PER_HAND (MATRIX_ROWS / 2)
|
||||
|
||||
extern bool mcp23018_leds[3];
|
||||
extern bool is_launching;
|
||||
|
||||
__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(); }
|
||||
|
||||
bool mcp23018_initd = false;
|
||||
static uint8_t mcp23018_reset_loop;
|
||||
|
||||
uint8_t mcp23018_tx[3];
|
||||
uint8_t mcp23018_rx[1];
|
||||
|
||||
void mcp23018_init(void) {
|
||||
i2c_init();
|
||||
|
||||
// #define MCP23_ROW_PINS { GPB5, GBP4, GBP3, GBP2, GBP1, GBP0 } outputs
|
||||
// #define MCP23_COL_PINS { GPA0, GBA1, GBA2, GBA3, GBA4, GBA5, GBA6 } inputs
|
||||
|
||||
mcp23018_tx[0] = 0x00; // IODIRA
|
||||
mcp23018_tx[1] = 0b00000000; // A is output
|
||||
mcp23018_tx[2] = 0b00111111; // B is inputs
|
||||
|
||||
if (MSG_OK != i2c_transmit(MCP23018_DEFAULT_ADDRESS << 1, mcp23018_tx, 3, I2C_TIMEOUT)) {
|
||||
printf("error hori\n");
|
||||
} else {
|
||||
mcp23018_tx[0] = 0x0C; // GPPUA
|
||||
mcp23018_tx[1] = 0b10000000; // A is not pulled-up
|
||||
mcp23018_tx[2] = 0b11111111; // B is pulled-up
|
||||
|
||||
if (MSG_OK != i2c_transmit(MCP23018_DEFAULT_ADDRESS << 1, mcp23018_tx, 3, I2C_TIMEOUT)) {
|
||||
printf("error hori\n");
|
||||
} else {
|
||||
mcp23018_initd = is_launching = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void matrix_init(void) {
|
||||
printf("matrix init\n");
|
||||
// debug_matrix = true;
|
||||
|
||||
// outputs
|
||||
setPinOutput(B10);
|
||||
setPinOutput(B11);
|
||||
setPinOutput(B12);
|
||||
setPinOutput(B13);
|
||||
setPinOutput(B14);
|
||||
setPinOutput(B15);
|
||||
|
||||
// inputs
|
||||
setPinInputLow(A0);
|
||||
setPinInputLow(A1);
|
||||
setPinInputLow(A2);
|
||||
setPinInputLow(A3);
|
||||
setPinInputLow(A6);
|
||||
setPinInputLow(A7);
|
||||
setPinInputLow(B0);
|
||||
|
||||
memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
|
||||
memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
|
||||
memset(matrix_debouncing_right, 0, MATRIX_COLS * sizeof(matrix_row_t));
|
||||
|
||||
mcp23018_init();
|
||||
|
||||
matrix_init_quantum();
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void) {
|
||||
bool changed = false;
|
||||
|
||||
matrix_row_t data = 0;
|
||||
// actual matrix
|
||||
for (uint8_t row = 0; row < ROWS_PER_HAND; row++) {
|
||||
// strobe row
|
||||
switch (row) {
|
||||
case 0: writePinHigh(B10); break;
|
||||
case 1: writePinHigh(B11); break;
|
||||
case 2: writePinHigh(B12); break;
|
||||
case 3: writePinHigh(B13); break;
|
||||
case 4: writePinHigh(B14); break;
|
||||
case 5: writePinHigh(B15); break;
|
||||
}
|
||||
|
||||
// need wait to settle pin state
|
||||
wait_us(20);
|
||||
|
||||
// read col data
|
||||
data = (
|
||||
(readPin(A0) << 0 ) |
|
||||
(readPin(A1) << 1 ) |
|
||||
(readPin(A2) << 2 ) |
|
||||
(readPin(A3) << 3 ) |
|
||||
(readPin(A6) << 4 ) |
|
||||
(readPin(A7) << 5 ) |
|
||||
(readPin(B0) << 6 )
|
||||
);
|
||||
|
||||
// unstrobe row
|
||||
switch (row) {
|
||||
case 0: writePinLow(B10); break;
|
||||
case 1: writePinLow(B11); break;
|
||||
case 2: writePinLow(B12); break;
|
||||
case 3: writePinLow(B13); break;
|
||||
case 4: writePinLow(B14); break;
|
||||
case 5: writePinLow(B15); break;
|
||||
}
|
||||
|
||||
if (matrix_debouncing[row] != data) {
|
||||
matrix_debouncing[row] = data;
|
||||
debouncing = true;
|
||||
debouncing_time = timer_read();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t row = 0; row <= ROWS_PER_HAND; row++) {
|
||||
// right side
|
||||
|
||||
if (!mcp23018_initd) {
|
||||
if (++mcp23018_reset_loop == 0) {
|
||||
// if (++mcp23018_reset_loop >= 1300) {
|
||||
// since mcp23018_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans
|
||||
// this will be approx bit more frequent than once per second
|
||||
print("trying to reset mcp23018\n");
|
||||
mcp23018_init();
|
||||
if (!mcp23018_initd) {
|
||||
print("left side not responding\n");
|
||||
} else {
|
||||
print("left side attached\n");
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
rgb_matrix_init();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #define MCP23_ROW_PINS { GPB5, GBP4, GBP3, GBP2, GBP1, GBP0 } outputs
|
||||
// #define MCP23_COL_PINS { GPA0, GBA1, GBA2, GBA3, GBA4, GBA5, GBA6 } inputs
|
||||
|
||||
// select row
|
||||
|
||||
mcp23018_tx[0] = 0x12; // GPIOA
|
||||
mcp23018_tx[1] = (0b01111111 & ~(1 << (row))) | ((uint8_t)!mcp23018_leds[2] << 7); // activate row
|
||||
mcp23018_tx[2] = ((uint8_t)!mcp23018_leds[1] << 6) | ((uint8_t)!mcp23018_leds[0] << 7); // activate row
|
||||
|
||||
if (MSG_OK != i2c_transmit(MCP23018_DEFAULT_ADDRESS << 1, mcp23018_tx, 3, I2C_TIMEOUT)) {
|
||||
printf("error hori\n");
|
||||
mcp23018_initd = false;
|
||||
}
|
||||
|
||||
// read col
|
||||
|
||||
mcp23018_tx[0] = 0x13; // GPIOB
|
||||
if (MSG_OK != i2c_readReg(MCP23018_DEFAULT_ADDRESS << 1, mcp23018_tx[0], &mcp23018_rx[0], 1, I2C_TIMEOUT)) {
|
||||
printf("error vert\n");
|
||||
mcp23018_initd = false;
|
||||
}
|
||||
|
||||
data = ~(mcp23018_rx[0] & 0b00111111);
|
||||
// data = 0x01;
|
||||
|
||||
if (matrix_debouncing_right[row] != data) {
|
||||
matrix_debouncing_right[row] = data;
|
||||
debouncing_right = true;
|
||||
debouncing_time_right = timer_read();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
|
||||
for (int row = 0; row < ROWS_PER_HAND; row++) {
|
||||
matrix[row] = matrix_debouncing[row];
|
||||
}
|
||||
debouncing = false;
|
||||
}
|
||||
|
||||
if (debouncing_right && timer_elapsed(debouncing_time_right) > DEBOUNCE && mcp23018_initd) {
|
||||
for (int row = 0; row < ROWS_PER_HAND; row++) {
|
||||
matrix[11 - row] = 0;
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
matrix[11 - row] |= ((matrix_debouncing_right[6 - col] & (1 << row) ? 1 : 0) << col);
|
||||
}
|
||||
}
|
||||
debouncing_right = false;
|
||||
}
|
||||
|
||||
matrix_scan_quantum();
|
||||
|
||||
return (uint8_t)changed;
|
||||
}
|
||||
|
||||
bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & (1 << col)); }
|
||||
|
||||
matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
|
||||
|
||||
void matrix_print(void) {
|
||||
printf("\nr/c 01234567\n");
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
printf("%X0: ", row);
|
||||
matrix_row_t data = matrix_get_row(row);
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
if (data & (1 << col))
|
||||
printf("1");
|
||||
else
|
||||
printf("0");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
422
keyboards/moonlander/moonlander.c
Normal file
422
keyboards/moonlander/moonlander.c
Normal file
@@ -0,0 +1,422 @@
|
||||
/*
|
||||
Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
|
||||
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 "moonlander.h"
|
||||
#ifdef WEBUSB_ENABLE
|
||||
#include "webusb.h"
|
||||
#endif
|
||||
|
||||
keyboard_config_t keyboard_config;
|
||||
|
||||
bool mcp23018_leds[3] = {0, 0, 0};
|
||||
bool is_launching = false;
|
||||
|
||||
void moonlander_led_task(void) {
|
||||
if (is_launching) {
|
||||
ML_LED_1(false);
|
||||
ML_LED_2(false);
|
||||
ML_LED_3(false);
|
||||
ML_LED_4(false);
|
||||
ML_LED_5(false);
|
||||
ML_LED_6(false);
|
||||
|
||||
ML_LED_1(true);
|
||||
wait_ms(250);
|
||||
ML_LED_2(true);
|
||||
wait_ms(250);
|
||||
ML_LED_3(true);
|
||||
wait_ms(250);
|
||||
ML_LED_4(true);
|
||||
wait_ms(250);
|
||||
ML_LED_5(true);
|
||||
wait_ms(250);
|
||||
ML_LED_6(true);
|
||||
wait_ms(250);
|
||||
ML_LED_1(false);
|
||||
wait_ms(250);
|
||||
ML_LED_2(false);
|
||||
wait_ms(250);
|
||||
ML_LED_3(false);
|
||||
wait_ms(250);
|
||||
ML_LED_4(false);
|
||||
wait_ms(250);
|
||||
ML_LED_5(false);
|
||||
wait_ms(250);
|
||||
ML_LED_6(false);
|
||||
wait_ms(250);
|
||||
is_launching = false;
|
||||
layer_state_set_kb(layer_state);
|
||||
}
|
||||
#ifdef WEBUSB_ENABLE
|
||||
else if (webusb_state.pairing == true) {
|
||||
static uint8_t led_mask;
|
||||
|
||||
ML_LED_1(false);
|
||||
ML_LED_2(false);
|
||||
ML_LED_3(false);
|
||||
ML_LED_4(false);
|
||||
ML_LED_5(false);
|
||||
ML_LED_6(false);
|
||||
|
||||
if (!led_mask) {
|
||||
led_mask = 1;
|
||||
} else {
|
||||
led_mask++;
|
||||
if (led_mask > 12) led_mask = 1;
|
||||
}
|
||||
switch (led_mask) {
|
||||
case 1:
|
||||
case 12:
|
||||
ML_LED_1(true);
|
||||
break;
|
||||
case 2:
|
||||
case 11:
|
||||
ML_LED_2(true);
|
||||
break;
|
||||
case 3:
|
||||
case 10:
|
||||
ML_LED_3(true);
|
||||
break;
|
||||
case 4:
|
||||
case 9:
|
||||
ML_LED_4(true);
|
||||
break;
|
||||
case 5:
|
||||
case 8:
|
||||
ML_LED_5(true);
|
||||
break;
|
||||
case 6:
|
||||
case 7:
|
||||
ML_LED_6(true);
|
||||
break;
|
||||
}
|
||||
wait_ms(150);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static THD_WORKING_AREA(waLEDThread, 128);
|
||||
static THD_FUNCTION(LEDThread, arg) {
|
||||
(void)arg;
|
||||
chRegSetThreadName("LEDThread");
|
||||
while (true) {
|
||||
moonlander_led_task();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void keyboard_pre_init_kb(void) {
|
||||
setPinOutput(B5);
|
||||
setPinOutput(B4);
|
||||
setPinOutput(B3);
|
||||
|
||||
writePinLow(B5);
|
||||
writePinLow(B4);
|
||||
writePinLow(B3);
|
||||
|
||||
|
||||
chThdCreateStatic(waLEDThread, sizeof(waLEDThread), NORMALPRIO-16, LEDThread, NULL);
|
||||
|
||||
/* the array is initialized to 0, no need to re-set it here */
|
||||
// mcp23018_leds[0] = 0; // blue
|
||||
// mcp23018_leds[1] = 0; // green
|
||||
// mcp23018_leds[2] = 0; // red
|
||||
|
||||
keyboard_pre_init_user();
|
||||
}
|
||||
|
||||
layer_state_t layer_state_set_kb(layer_state_t state) {
|
||||
state = layer_state_set_user(state);
|
||||
if (is_launching) return state;
|
||||
|
||||
ML_LED_1(false);
|
||||
ML_LED_2(false);
|
||||
ML_LED_3(false);
|
||||
ML_LED_4(false);
|
||||
ML_LED_5(false);
|
||||
ML_LED_6(false);
|
||||
|
||||
uint8_t layer = get_highest_layer(state);
|
||||
switch (layer) {
|
||||
case 1:
|
||||
ML_LED_1(1);
|
||||
ML_LED_4(1);
|
||||
break;
|
||||
case 2:
|
||||
ML_LED_2(1);
|
||||
ML_LED_5(1);
|
||||
break;
|
||||
case 3:
|
||||
ML_LED_3(1);
|
||||
break;
|
||||
case 4:
|
||||
ML_LED_4(1);
|
||||
break;
|
||||
case 5:
|
||||
ML_LED_5(1);
|
||||
break;
|
||||
case 6:
|
||||
ML_LED_6(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
// clang-format off
|
||||
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
|
||||
/* Refer to IS31 manual for these locations
|
||||
* driver
|
||||
* | R location
|
||||
* | | G location
|
||||
* | | | B location
|
||||
* | | | | */
|
||||
{0, C3_2, C1_1, C4_2}, // 1
|
||||
{0, C2_2, C1_2, C4_3},
|
||||
{0, C2_3, C1_3, C3_3},
|
||||
{0, C2_4, C1_4, C3_4},
|
||||
{0, C2_5, C1_5, C3_5},
|
||||
{0, C2_6, C1_6, C3_6},
|
||||
{0, C2_7, C1_7, C3_7},
|
||||
{0, C2_8, C1_8, C3_8},
|
||||
{0, C3_1, C2_1, C4_1},
|
||||
|
||||
{0, C7_8, C6_8, C8_8}, // 10
|
||||
{0, C7_7, C6_7, C9_8},
|
||||
{0, C8_7, C6_6, C9_7},
|
||||
{0, C8_6, C7_6, C9_6},
|
||||
{0, C8_5, C7_5, C9_5},
|
||||
{0, C8_4, C7_4, C9_4},
|
||||
{0, C8_3, C7_3, C9_3},
|
||||
{0, C8_2, C7_2, C9_2},
|
||||
{0, C8_1, C7_1, C9_1},
|
||||
|
||||
{0, C3_10, C1_9, C4_10}, // 19
|
||||
{0, C2_10, C1_10, C4_11},
|
||||
{0, C2_11, C1_11, C3_11},
|
||||
{0, C2_12, C1_12, C3_12},
|
||||
{0, C2_13, C1_13, C3_13},
|
||||
{0, C2_14, C1_14, C3_14},
|
||||
{0, C2_15, C1_15, C3_15},
|
||||
{0, C2_16, C1_16, C3_16},
|
||||
{0, C3_9, C2_9, C4_9},
|
||||
|
||||
{0, C7_16, C6_16, C8_16}, // 28
|
||||
{0, C7_15, C6_15, C9_16},
|
||||
{0, C8_15, C6_14, C9_15},
|
||||
{0, C8_10, C7_10, C9_10},
|
||||
{0, C8_9, C7_9, C9_9},
|
||||
{0, C8_11, C7_11, C9_11},
|
||||
{0, C8_12, C7_12, C9_12},
|
||||
{0, C8_13, C7_13, C9_13},
|
||||
{0, C8_14, C7_14, C9_14},
|
||||
|
||||
{1, C3_2, C1_1, C4_2}, // 1
|
||||
{1, C2_2, C1_2, C4_3},
|
||||
{1, C2_3, C1_3, C3_3},
|
||||
{1, C2_4, C1_4, C3_4},
|
||||
{1, C2_5, C1_5, C3_5},
|
||||
{1, C2_6, C1_6, C3_6},
|
||||
{1, C2_7, C1_7, C3_7},
|
||||
{1, C2_8, C1_8, C3_8},
|
||||
{1, C3_1, C2_1, C4_1},
|
||||
|
||||
{1, C7_8, C6_8, C8_8}, // 10
|
||||
{1, C7_7, C6_7, C9_8},
|
||||
{1, C8_7, C6_6, C9_7},
|
||||
{1, C8_6, C7_6, C9_6},
|
||||
{1, C8_5, C7_5, C9_5},
|
||||
{1, C8_4, C7_4, C9_4},
|
||||
{1, C8_3, C7_3, C9_3},
|
||||
{1, C8_2, C7_2, C9_2},
|
||||
{1, C8_1, C7_1, C9_1},
|
||||
|
||||
{1, C3_10, C1_9, C4_10}, // 19
|
||||
{1, C2_10, C1_10, C4_11},
|
||||
{1, C2_11, C1_11, C3_11},
|
||||
{1, C2_12, C1_12, C3_12},
|
||||
{1, C2_13, C1_13, C3_13},
|
||||
{1, C2_14, C1_14, C3_14},
|
||||
{1, C2_15, C1_15, C3_15},
|
||||
{1, C2_16, C1_16, C3_16},
|
||||
{1, C3_9, C2_9, C4_9},
|
||||
|
||||
{1, C7_16, C6_16, C8_16}, // 28
|
||||
{1, C7_15, C6_15, C9_16},
|
||||
{1, C8_15, C6_14, C9_15},
|
||||
{1, C8_10, C7_10, C9_10},
|
||||
{1, C8_9, C7_9, C9_9},
|
||||
{1, C8_11, C7_11, C9_11},
|
||||
{1, C8_12, C7_12, C9_12},
|
||||
{1, C8_13, C7_13, C9_13},
|
||||
{1, C8_14, C7_14, C9_14},
|
||||
|
||||
};
|
||||
|
||||
led_config_t g_led_config = { {
|
||||
{ 0, 5, 10, 15, 20, 25, 29 },
|
||||
{ 1, 6, 11, 16, 21, 26, 30 },
|
||||
{ 2, 7, 12, 17, 22, 27, 31 },
|
||||
{ 3, 8, 13, 18, 23, 28, NO_LED },
|
||||
{ 4, 9, 14, 19, 24, NO_LED, NO_LED },
|
||||
{ 32, 33, 34, 35, NO_LED, NO_LED, NO_LED },
|
||||
{ 65, 61, 56, 51, 46, 41, 36 },
|
||||
{ 66, 62, 57, 52, 47, 42, 37 },
|
||||
{ 67, 63, 58, 53, 48, 43, 38 },
|
||||
{ NO_LED, 64, 59, 54, 49, 44, 39 },
|
||||
{ NO_LED, NO_LED, 60, 55, 50, 45, 40 },
|
||||
{ NO_LED, NO_LED, NO_LED, 71, 70, 69, 68 },
|
||||
}, {
|
||||
{ 0, 0 }, { 0, 12 }, { 0, 25 }, { 0, 38 }, { 0, 51 },
|
||||
{ 17, 0 }, { 17, 12 }, { 17, 25 }, { 17, 38 }, { 17, 51 },
|
||||
{ 34, 0 }, { 34, 12 }, { 34, 25 }, { 34, 38 }, { 34, 51 },
|
||||
{ 51, 0 }, { 51, 12 }, { 51, 25 }, { 51, 38 }, { 51, 51 },
|
||||
{ 68, 0 }, { 68, 12 }, { 68, 25 }, { 68, 38 }, { 68, 51 },
|
||||
{ 86, 0 }, { 86, 12 }, { 86, 25 }, { 86, 38 },
|
||||
{ 105, 0 }, { 105, 12 }, { 105, 25 },
|
||||
{ 90, 55 }, { 105, 68 }, { 116, 86 }, { 116, 59 },
|
||||
|
||||
{ 250, 0 }, { 250, 12 }, { 250, 25 }, { 250, 38 }, { 250, 51 },
|
||||
{ 233, 0 }, { 233, 12 }, { 233, 25 }, { 233, 38 }, { 233, 51 },
|
||||
{ 216, 0 }, { 216, 12 }, { 216, 25 }, { 216, 38 }, { 216, 51 },
|
||||
{ 198, 0 }, { 198, 12 }, { 198, 25 }, { 198, 38 }, { 198, 51 },
|
||||
{ 181, 0 }, { 181, 12 }, { 181, 25 }, { 181, 38 }, { 181, 51 },
|
||||
{ 163, 0 }, { 163, 12 }, { 163, 25 }, { 163, 38 },
|
||||
{ 146, 0 }, { 146, 12 }, { 146, 25 },
|
||||
{ 161, 55 }, { 161, 68 }, { 146, 86 }, { 131, 59 }
|
||||
|
||||
}, {
|
||||
1, 1, 1, 1, 1, 4,
|
||||
4, 4, 4, 1, 4, 4,
|
||||
4, 4, 1, 4, 4, 4,
|
||||
4, 1, 4, 4, 4, 4,
|
||||
1, 4, 4, 4, 4, 4,
|
||||
4, 4, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 4,
|
||||
4, 4, 4, 1, 4, 4,
|
||||
4, 4, 1, 4, 4, 4,
|
||||
4, 1, 4, 4, 4, 4,
|
||||
1, 4, 4, 4, 4, 4,
|
||||
4, 4, 1, 1, 1, 1
|
||||
} };
|
||||
// clang-format on
|
||||
|
||||
void suspend_power_down_kb(void) {
|
||||
rgb_matrix_set_suspend_state(true);
|
||||
suspend_power_down_user();
|
||||
}
|
||||
|
||||
void suspend_wakeup_init_kb(void) {
|
||||
rgb_matrix_set_suspend_state(false);
|
||||
suspend_wakeup_init_user();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
bool music_mask_kb(uint16_t keycode) {
|
||||
switch (keycode) {
|
||||
case QK_LAYER_TAP ... QK_ONE_SHOT_LAYER_MAX:
|
||||
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_MOD_MAX:
|
||||
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
|
||||
case AU_ON ... MUV_DE:
|
||||
case RESET:
|
||||
case EEP_RST:
|
||||
return false;
|
||||
default:
|
||||
return music_mask_user(keycode);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SWAP_HANDS_ENABLE
|
||||
// swap-hands action needs a matrix to define the swap
|
||||
// clang-format off
|
||||
const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
|
||||
/* Left hand, matrix positions */
|
||||
{{6,6}, {5,6}, {4,6}, {3,6}, {2,6}, {1,6},{0,6}},
|
||||
{{6,7}, {5,7}, {4,7}, {3,7}, {2,7}, {1,7},{0,7}},
|
||||
{{6,8}, {5,8}, {4,8}, {3,8}, {2,8}, {1,8},{0,8}},
|
||||
{{6,9}, {5,9}, {4,9}, {3,9}, {2,9}, {1,9},{0,9}},
|
||||
{{6,10},{5,10},{4,10},{3,10},{2,10},{1,10},{0,10}},
|
||||
{{6,11},{5,11},{4,11},{3,11},{2,11},{1,11},{0,11}},
|
||||
/* Right hand, matrix positions */
|
||||
{{6,0}, {5,0}, {4,0}, {3,0}, {2,0}, {1,0},{0,0}},
|
||||
{{6,1}, {5,1}, {4,1}, {3,1}, {2,1}, {1,1},{0,1}},
|
||||
{{6,2}, {5,2}, {4,2}, {3,2}, {2,2}, {1,2},{0,2}},
|
||||
{{6,3}, {5,3}, {4,3}, {3,3}, {2,3}, {1,3},{0,3}},
|
||||
{{6,4}, {5,4}, {4,4}, {3,4}, {2,4}, {1,4},{0,4}},
|
||||
{{6,5}, {5,5}, {4,5}, {3,5}, {2,5}, {1,5},{0,5}},
|
||||
};
|
||||
// clang-format on
|
||||
#endif
|
||||
|
||||
#if defined(AUDIO_ENABLE) && defined(MUSIC_MAP)
|
||||
// clang-format off
|
||||
const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS] = LAYOUT_moonlander(
|
||||
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
|
||||
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
|
||||
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
|
||||
8, 9, 10, 11, 12, 3, 4, 13, 14, 15, 16, 17,
|
||||
0, 1, 2, 5, 6, 7
|
||||
);
|
||||
// clang-format on
|
||||
#endif
|
||||
|
||||
|
||||
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
#ifdef WEBUSB_ENABLE
|
||||
case WEBUSB_PAIR:
|
||||
if (!record->event.pressed && !webusb_state.pairing)
|
||||
layer_state_set_kb(layer_state);
|
||||
break;
|
||||
#endif
|
||||
#ifdef RGB_MATRIX_ENABLE
|
||||
case TOGGLE_LAYER_COLOR:
|
||||
if (record->event.pressed) {
|
||||
keyboard_config.disable_layer_led ^= 1;
|
||||
if (keyboard_config.disable_layer_led)
|
||||
rgb_matrix_set_color_all(0, 0, 0);
|
||||
eeconfig_update_kb(keyboard_config.raw);
|
||||
}
|
||||
break;
|
||||
case RGB_TOG:
|
||||
if (record->event.pressed) {
|
||||
switch (rgb_matrix_get_flags()) {
|
||||
case LED_FLAG_ALL: {
|
||||
rgb_matrix_set_flags(LED_FLAG_NONE);
|
||||
keyboard_config.rgb_matrix_enable = false;
|
||||
rgb_matrix_set_color_all(0, 0, 0);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
rgb_matrix_set_flags(LED_FLAG_ALL);
|
||||
keyboard_config.rgb_matrix_enable = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
eeconfig_update_kb(keyboard_config.raw);
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
return process_record_user(keycode, record);
|
||||
}
|
||||
71
keyboards/moonlander/moonlander.h
Normal file
71
keyboards/moonlander/moonlander.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright 2018 Jack Humbert <jack.humb@gmail.com>
|
||||
|
||||
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
|
||||
|
||||
#define MCP23018_DEFAULT_ADDRESS 0b0100000
|
||||
|
||||
#define ML_LED_1(status) writePin(B5, (bool)status)
|
||||
#define ML_LED_2(status) writePin(B4, (bool)status)
|
||||
#define ML_LED_3(status) writePin(B3, (bool)status)
|
||||
|
||||
#define ML_LED_4(status) mcp23018_leds[0] = (bool)status
|
||||
#define ML_LED_5(status) mcp23018_leds[1] = (bool)status
|
||||
#define ML_LED_6(status) mcp23018_leds[2] = (bool)status
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
// clang-format off
|
||||
#define LAYOUT_moonlander( \
|
||||
k00, k01, k02, k03, k04, k05, k06, k60, k61, k62, k63, k64, k65, k66, \
|
||||
k10, k11, k12, k13, k14, k15, k16, k70, k71, k72, k73, k74, k75, k76, \
|
||||
k20, k21, k22, k23, k24, k25, k26, k80, k81, k82, k83, k84, k85, k86, \
|
||||
k30, k31, k32, k33, k34, k35, k91, k92, k93, k94, k95, k96, \
|
||||
k40, k41, k42, k43, k44, k53, kb3, ka2, ka3, ka4, ka5, ka6, \
|
||||
k50, k51, k52, kb4, kb5, kb6 \
|
||||
) \
|
||||
{ \
|
||||
{ k00, k01, k02, k03, k04, k05, k06 }, \
|
||||
{ k10, k11, k12, k13, k14, k15, k16 }, \
|
||||
{ k20, k21, k22, k23, k24, k25, k26 }, \
|
||||
{ k30, k31, k32, k33, k34, k35, KC_NO }, \
|
||||
{ k40, k41, k42, k43, k44, KC_NO, KC_NO }, \
|
||||
{ k50, k51, k52, k53, KC_NO, KC_NO, KC_NO }, \
|
||||
\
|
||||
{ k60, k61, k62, k63, k64, k65, k66 }, \
|
||||
{ k70, k71, k72, k73, k74, k75, k76 }, \
|
||||
{ k80, k81, k82, k83, k84, k85, k86 }, \
|
||||
{ KC_NO,k91, k92, k93, k94, k95, k96 }, \
|
||||
{ KC_NO, KC_NO, ka2, ka3, ka4, ka5, ka6 }, \
|
||||
{ KC_NO, KC_NO, KC_NO, kb3, kb4, kb5, kb6 } \
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
enum planck_ez_keycodes {
|
||||
TOGGLE_LAYER_COLOR = SAFE_RANGE,
|
||||
ML_SAFE_RANGE,
|
||||
};
|
||||
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
bool disable_layer_led :1;
|
||||
bool rgb_matrix_enable :1;
|
||||
};
|
||||
} keyboard_config_t;
|
||||
|
||||
extern keyboard_config_t keyboard_config;
|
||||
24
keyboards/moonlander/rules.mk
Normal file
24
keyboards/moonlander/rules.mk
Normal file
@@ -0,0 +1,24 @@
|
||||
#Cortex version
|
||||
MCU = STM32F303
|
||||
|
||||
#Build Options
|
||||
#comment out to disable the options.
|
||||
#
|
||||
BACKLIGHT_ENABLE = no
|
||||
BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||
EXTRAKEY_ENABLE = yes # Audio control and System control
|
||||
CONSOLE_ENABLE = yes # Console for debug
|
||||
COMMAND_ENABLE = yes # Commands for debug and configuration
|
||||
#SLEEP_LED_ENABLE = yes #Breathing sleep LED during USB suspend
|
||||
NKRO_ENABLE = yes # USB Nkey Rollover
|
||||
CUSTOM_MATRIX = yes # Custom matrix file
|
||||
AUDIO_ENABLE = yes
|
||||
SWAP_HANDS_ENABLE = yes
|
||||
RGB_MATRIX_ENABLE = IS31FL3731
|
||||
#SERIAL_LINK_ENABLE = yes
|
||||
EEPROM_DRIVER = i2c
|
||||
|
||||
#project specific files
|
||||
SRC = matrix.c
|
||||
QUANTUM_LIB_SRC += i2c_master.c
|
||||
@@ -18,7 +18,12 @@
|
||||
#pragma once
|
||||
|
||||
/* USB Device descriptor parameter */
|
||||
#undef MANUFACTURER
|
||||
#define MANUFACTURER ZSA
|
||||
#undef PRODUCT
|
||||
#define PRODUCT Planck EZ
|
||||
#define DEVICE_VER 0x0000
|
||||
#define WEBUSB_LANDING_PAGE_URL u8"configure.ergodox-ez.com"
|
||||
|
||||
#undef MATRIX_ROWS
|
||||
#undef MATRIX_COLS
|
||||
|
||||
@@ -242,7 +242,7 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset!
|
||||
}
|
||||
|
||||
|
||||
uint32_t layer_state_set_kb(uint32_t state) {
|
||||
layer_state_t layer_state_set_kb(layer_state_t state) {
|
||||
planck_ez_left_led_off();
|
||||
planck_ez_right_led_off();
|
||||
state = layer_state_set_user(state);
|
||||
@@ -325,3 +325,38 @@ bool music_mask_kb(uint16_t keycode) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef ORYX_ENABLE
|
||||
static uint16_t loops = 0;
|
||||
static bool is_on = false;
|
||||
|
||||
void matrix_scan_kb(void) {
|
||||
if(webusb_state.pairing == true) {
|
||||
if(loops == 0) {
|
||||
//lights off
|
||||
}
|
||||
if(loops % WEBUSB_BLINK_STEPS == 0) {
|
||||
if(is_on) {
|
||||
planck_ez_left_led_on();
|
||||
planck_ez_right_led_off();
|
||||
}
|
||||
else {
|
||||
planck_ez_left_led_off();
|
||||
planck_ez_right_led_on();
|
||||
}
|
||||
is_on ^= 1;
|
||||
}
|
||||
if(loops > WEBUSB_BLINK_END * 2) {
|
||||
webusb_state.pairing = false;
|
||||
loops = 0;
|
||||
planck_ez_left_led_off();
|
||||
planck_ez_right_led_off();
|
||||
}
|
||||
loops++;
|
||||
}
|
||||
else if(loops > 0) {
|
||||
loops = 0;
|
||||
planck_ez_left_led_off();
|
||||
planck_ez_right_led_off();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
# project specific files
|
||||
LAYOUTS += ortho_4x12
|
||||
|
||||
# Cortex version
|
||||
MCU = STM32F303
|
||||
# MCU name
|
||||
MCU = STM32F303
|
||||
|
||||
# Build Options
|
||||
# comment out to disable the options.
|
||||
@@ -22,3 +19,5 @@ RGBLIGHT_ENABLE = no
|
||||
# SERIAL_LINK_ENABLE = yes
|
||||
ENCODER_ENABLE = yes
|
||||
RGB_MATRIX_ENABLE = IS31FL3737
|
||||
|
||||
LAYOUTS += ortho_4x12
|
||||
|
||||
@@ -12,3 +12,5 @@
|
||||
Set any config.h overrides for your specific keymap here.
|
||||
See config.h options at https://docs.qmk.fm/#/config_options?id=the-configh-file
|
||||
*/
|
||||
|
||||
#define LAYER_STATE_8BIT
|
||||
|
||||
@@ -129,23 +129,6 @@ bool music_mask_user(uint16_t keycode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
uint32_t layer_state_set_user(uint32_t state) {
|
||||
palClearPad(GPIOB, 8);
|
||||
palClearPad(GPIOB, 9);
|
||||
uint8_t layer = biton32(state);
|
||||
switch (layer) {
|
||||
case _LOWER:
|
||||
palSetPad(GPIOB, 9);
|
||||
break;
|
||||
case _RAISE:
|
||||
palSetPad(GPIOB, 8);
|
||||
break;
|
||||
case _ADJUST:
|
||||
palSetPad(GPIOB, 9);
|
||||
palSetPad(GPIOB, 8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
layer_state_t layer_state_set_user(layer_state_t state) {
|
||||
return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
|
||||
}
|
||||
|
||||
@@ -3,3 +3,4 @@ SRC += muse.c
|
||||
# See rules at https://docs.qmk.fm/#/config_options?id=the-rulesmk-file
|
||||
COMMAND_ENABLE = no
|
||||
MOUSEKEY_ENABLE = no
|
||||
ORYX_ENABLE = yes
|
||||
|
||||
39
keyboards/planck/keymaps/webusb/config.h
Normal file
39
keyboards/planck/keymaps/webusb/config.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
#define STARTUP_SONG SONG(PLANCK_SOUND)
|
||||
// #define STARTUP_SONG SONG(NO_SOUND)
|
||||
|
||||
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
|
||||
SONG(COLEMAK_SOUND), \
|
||||
SONG(DVORAK_SOUND) \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MIDI options
|
||||
*/
|
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */
|
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* enable basic MIDI features:
|
||||
- MIDI notes can be sent when in Music mode is on
|
||||
*/
|
||||
|
||||
#define MIDI_BASIC
|
||||
|
||||
/* enable advanced MIDI features:
|
||||
- MIDI notes can be added to the keymap
|
||||
- Octave shift and transpose
|
||||
- Virtual sustain, portamento, and modulation wheel
|
||||
- etc.
|
||||
*/
|
||||
//#define MIDI_ADVANCED
|
||||
|
||||
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
// Most tactile encoders have detents every 4 stages
|
||||
#define ENCODER_RESOLUTION 4
|
||||
|
||||
136
keyboards/planck/keymaps/webusb/keymap.c
Normal file
136
keyboards/planck/keymaps/webusb/keymap.c
Normal file
@@ -0,0 +1,136 @@
|
||||
#include QMK_KEYBOARD_H
|
||||
#ifdef AUDIO_ENABLE
|
||||
#include "muse.h"
|
||||
#endif
|
||||
#include "eeprom.h"
|
||||
#include "keymap_german.h"
|
||||
#include "keymap_nordic.h"
|
||||
#include "keymap_french.h"
|
||||
#include "keymap_spanish.h"
|
||||
#include "keymap_hungarian.h"
|
||||
#include "keymap_swedish.h"
|
||||
#include "keymap_br_abnt2.h"
|
||||
#include "keymap_canadian_multilingual.h"
|
||||
#include "keymap_german_ch.h"
|
||||
#include "keymap_jp.h"
|
||||
|
||||
#define KC_MAC_UNDO LGUI(KC_Z)
|
||||
#define KC_MAC_CUT LGUI(KC_X)
|
||||
#define KC_MAC_COPY LGUI(KC_C)
|
||||
#define KC_MAC_PASTE LGUI(KC_V)
|
||||
#define KC_PC_UNDO LCTL(KC_Z)
|
||||
#define KC_PC_CUT LCTL(KC_X)
|
||||
#define KC_PC_COPY LCTL(KC_C)
|
||||
#define KC_PC_PASTE LCTL(KC_V)
|
||||
#define ES_LESS_MAC KC_GRAVE
|
||||
#define ES_GRTR_MAC LSFT(KC_GRAVE)
|
||||
#define ES_BSLS_MAC ALGR(KC_6)
|
||||
|
||||
enum planck_keycodes {
|
||||
RGB_SLD = EZ_SAFE_RANGE,
|
||||
};
|
||||
|
||||
enum planck_layers {
|
||||
_BASE,
|
||||
_LOWER,
|
||||
_RAISE,
|
||||
_ADJUST,
|
||||
};
|
||||
|
||||
|
||||
#define LOWER MO(_LOWER)
|
||||
#define RAISE MO(_RAISE)
|
||||
|
||||
#define LOWER MO(_LOWER)
|
||||
#define RAISE MO(_RAISE)
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
[_BASE] = LAYOUT_planck_grid(KC_TAB,KC_Q,KC_W,KC_E,KC_R,KC_T,KC_Y,KC_U,KC_I,KC_O,KC_P,KC_BSPACE,KC_ESCAPE,KC_A,KC_S,KC_D,KC_F,KC_G,KC_H,KC_J,KC_K,KC_L,KC_SCOLON,KC_QUOTE,KC_LSHIFT,KC_Z,KC_X,KC_C,KC_V,KC_B,KC_N,KC_M,KC_COMMA,KC_DOT,KC_SLASH,KC_ENTER,KC_HYPR,KC_LCTRL,KC_LALT,KC_LGUI,LOWER,KC_SPACE,KC_NO,RAISE,KC_LEFT,KC_DOWN,KC_UP,KC_RIGHT),
|
||||
|
||||
[_LOWER] = LAYOUT_planck_grid(KC_TILD,KC_EXLM,KC_AT,KC_HASH,KC_DLR,KC_PERC,KC_CIRC,KC_AMPR,KC_ASTR,KC_LPRN,KC_RPRN,KC_TRANSPARENT,KC_DELETE,KC_F1,KC_F2,KC_F3,KC_F4,KC_F5,KC_F6,KC_UNDS,KC_PLUS,KC_LCBR,KC_RCBR,KC_PIPE,KC_TRANSPARENT,KC_F7,KC_F8,KC_F9,KC_F10,KC_F11,KC_F12,KC_NONUS_HASH,KC_NONUS_BSLASH,KC_HOME,KC_END,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_NO,KC_TRANSPARENT,KC_MEDIA_NEXT_TRACK,KC_AUDIO_VOL_DOWN,KC_AUDIO_VOL_UP,KC_MEDIA_PLAY_PAUSE),
|
||||
|
||||
[_RAISE] = LAYOUT_planck_grid(KC_GRAVE,KC_1,KC_2,KC_3,KC_4,KC_5,KC_6,KC_7,KC_8,KC_9,KC_0,KC_TRANSPARENT,KC_DELETE,KC_F1,KC_F2,KC_F3,KC_F4,KC_F5,KC_F6,KC_MINUS,KC_EQUAL,KC_LBRACKET,KC_RBRACKET,KC_BSLASH,KC_TRANSPARENT,KC_F7,KC_F8,KC_F9,KC_F10,KC_F11,KC_F12,KC_NONUS_HASH,KC_NONUS_BSLASH,KC_PGUP,KC_PGDOWN,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_NO,KC_TRANSPARENT,KC_MEDIA_NEXT_TRACK,KC_AUDIO_VOL_DOWN,KC_AUDIO_VOL_UP,KC_MEDIA_PLAY_PAUSE),
|
||||
|
||||
[_ADJUST] = LAYOUT_planck_grid(WEBUSB_PAIR,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_DELETE,KC_TRANSPARENT,AU_ON,AU_OFF,AU_TOG,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,RESET,KC_TRANSPARENT,KC_TRANSPARENT,MU_ON,MU_OFF,MU_TOG,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_NO,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT,KC_TRANSPARENT),
|
||||
|
||||
};
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
bool muse_mode = false;
|
||||
uint8_t last_muse_note = 0;
|
||||
uint16_t muse_counter = 0;
|
||||
uint8_t muse_offset = 70;
|
||||
uint16_t muse_tempo = 50;
|
||||
|
||||
void encoder_update(bool clockwise) {
|
||||
if (muse_mode) {
|
||||
if (IS_LAYER_ON(_RAISE)) {
|
||||
if (clockwise) {
|
||||
muse_offset++;
|
||||
} else {
|
||||
muse_offset--;
|
||||
}
|
||||
} else {
|
||||
if (clockwise) {
|
||||
muse_tempo+=1;
|
||||
} else {
|
||||
muse_tempo-=1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (clockwise) {
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
register_code(KC_MS_WH_DOWN);
|
||||
unregister_code(KC_MS_WH_DOWN);
|
||||
#else
|
||||
register_code(KC_PGDN);
|
||||
unregister_code(KC_PGDN);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef MOUSEKEY_ENABLE
|
||||
register_code(KC_MS_WH_UP);
|
||||
unregister_code(KC_MS_WH_UP);
|
||||
#else
|
||||
register_code(KC_PGUP);
|
||||
unregister_code(KC_PGUP);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void matrix_scan_user(void) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
if (muse_mode) {
|
||||
if (muse_counter == 0) {
|
||||
uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
|
||||
if (muse_note != last_muse_note) {
|
||||
stop_note(compute_freq_for_midi_note(last_muse_note));
|
||||
play_note(compute_freq_for_midi_note(muse_note), 0xF);
|
||||
last_muse_note = muse_note;
|
||||
}
|
||||
}
|
||||
muse_counter = (muse_counter + 1) % muse_tempo;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool music_mask_user(uint16_t keycode) {
|
||||
switch (keycode) {
|
||||
case RAISE:
|
||||
case LOWER:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
layer_state_t layer_state_set_user(layer_state_t state) {
|
||||
return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
|
||||
}
|
||||
2
keyboards/planck/keymaps/webusb/readme.md
Normal file
2
keyboards/planck/keymaps/webusb/readme.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# The Default Planck Layout
|
||||
|
||||
3
keyboards/planck/keymaps/webusb/rules.mk
Normal file
3
keyboards/planck/keymaps/webusb/rules.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
SRC += muse.c
|
||||
RGB_MATRIX_ENABLE = no
|
||||
WEBUSB_ENABLE = yes
|
||||
2
lib/lufa
2
lib/lufa
Submodule lib/lufa updated: ce10f7642b...94e43e4977
146
lib/python/kle2xy.py
Normal file
146
lib/python/kle2xy.py
Normal file
@@ -0,0 +1,146 @@
|
||||
""" Original code from https://github.com/skullydazed/kle2xy
|
||||
"""
|
||||
|
||||
import hjson
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class KLE2xy(list):
|
||||
"""Abstract interface for interacting with a KLE layout.
|
||||
"""
|
||||
def __init__(self, layout=None, name='', invert_y=True):
|
||||
super(KLE2xy, self).__init__()
|
||||
|
||||
self.name = name
|
||||
self.invert_y = invert_y
|
||||
self.key_width = Decimal('19.05')
|
||||
self.key_skel = {'decal': False, 'border_color': 'none', 'keycap_profile': '', 'keycap_color': 'grey', 'label_color': 'black', 'label_size': 3, 'label_style': 4, 'width': Decimal('1'), 'height': Decimal('1'), 'x': Decimal('0'), 'y': Decimal('0')}
|
||||
self.rows = Decimal(0)
|
||||
self.columns = Decimal(0)
|
||||
|
||||
if layout:
|
||||
self.parse_layout(layout)
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
"""Returns the width of the keyboard plate.
|
||||
"""
|
||||
return (Decimal(self.columns) * self.key_width) + self.key_width / 2
|
||||
|
||||
@property
|
||||
def height(self):
|
||||
"""Returns the height of the keyboard plate.
|
||||
"""
|
||||
return (self.rows * self.key_width) + self.key_width / 2
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
"""Returns the size of the keyboard plate.
|
||||
"""
|
||||
return (self.width, self.height)
|
||||
|
||||
def attrs(self, properties):
|
||||
"""Parse the keyboard properties dictionary.
|
||||
"""
|
||||
# FIXME: Store more than just the keyboard name.
|
||||
if 'name' in properties:
|
||||
self.name = properties['name']
|
||||
|
||||
def parse_layout(self, layout): # noqa FIXME(skullydazed): flake8 says this has a complexity of 25, it should be refactored.
|
||||
# Wrap this in a dictionary so hjson will parse KLE raw data
|
||||
layout = '{"layout": [' + layout + ']}'
|
||||
layout = hjson.loads(layout)['layout']
|
||||
|
||||
# Initialize our state machine
|
||||
current_key = self.key_skel.copy()
|
||||
current_row = Decimal(0)
|
||||
current_col = Decimal(0)
|
||||
current_x = 0
|
||||
current_y = self.key_width / 2
|
||||
|
||||
if isinstance(layout[0], dict):
|
||||
self.attrs(layout[0])
|
||||
layout = layout[1:]
|
||||
|
||||
for row_num, row in enumerate(layout):
|
||||
self.append([])
|
||||
|
||||
# Process the current row
|
||||
for key in row:
|
||||
if isinstance(key, dict):
|
||||
if 'w' in key and key['w'] != Decimal(1):
|
||||
current_key['width'] = Decimal(key['w'])
|
||||
if 'w2' in key and 'h2' in key and key['w2'] == 1.5 and key['h2'] == 1:
|
||||
# FIXME: ISO Key uses these params: {x:0.25,w:1.25,h:2,w2:1.5,h2:1,x2:-0.25}
|
||||
current_key['isoenter'] = True
|
||||
if 'h' in key and key['h'] != Decimal(1):
|
||||
current_key['height'] = Decimal(key['h'])
|
||||
if 'a' in key:
|
||||
current_key['label_style'] = self.key_skel['label_style'] = int(key['a'])
|
||||
if current_key['label_style'] < 0:
|
||||
current_key['label_style'] = 0
|
||||
elif current_key['label_style'] > 9:
|
||||
current_key['label_style'] = 9
|
||||
if 'f' in key:
|
||||
font_size = int(key['f'])
|
||||
if font_size > 9:
|
||||
font_size = 9
|
||||
elif font_size < 1:
|
||||
font_size = 1
|
||||
current_key['label_size'] = self.key_skel['label_size'] = font_size
|
||||
if 'p' in key:
|
||||
current_key['keycap_profile'] = self.key_skel['keycap_profile'] = key['p']
|
||||
if 'c' in key:
|
||||
current_key['keycap_color'] = self.key_skel['keycap_color'] = key['c']
|
||||
if 't' in key:
|
||||
# FIXME: Need to do better validation, plus figure out how to support multiple colors
|
||||
if '\n' in key['t']:
|
||||
key['t'] = key['t'].split('\n')[0]
|
||||
if key['t'] == "0":
|
||||
key['t'] = "#000000"
|
||||
current_key['label_color'] = self.key_skel['label_color'] = key['t']
|
||||
if 'x' in key:
|
||||
current_col += Decimal(key['x'])
|
||||
current_x += Decimal(key['x']) * self.key_width
|
||||
if 'y' in key:
|
||||
current_row += Decimal(key['y'])
|
||||
current_y += Decimal(key['y']) * self.key_width
|
||||
if 'd' in key:
|
||||
current_key['decal'] = True
|
||||
|
||||
else:
|
||||
current_key['name'] = key
|
||||
current_key['row'] = current_row
|
||||
current_key['column'] = current_col
|
||||
|
||||
# Determine the X center
|
||||
x_center = (current_key['width'] * self.key_width) / 2
|
||||
current_x += x_center
|
||||
current_key['x'] = current_x
|
||||
current_x += x_center
|
||||
|
||||
# Determine the Y center
|
||||
y_center = (current_key['height'] * self.key_width) / 2
|
||||
y_offset = y_center - (self.key_width / 2)
|
||||
current_key['y'] = (current_y + y_offset)
|
||||
|
||||
# Tend to our row/col count
|
||||
current_col += current_key['width']
|
||||
if current_col > self.columns:
|
||||
self.columns = current_col
|
||||
|
||||
# Invert the y-axis if neccesary
|
||||
if self.invert_y:
|
||||
current_key['y'] = -current_key['y']
|
||||
|
||||
# Store this key
|
||||
self[-1].append(current_key)
|
||||
current_key = self.key_skel.copy()
|
||||
|
||||
# Move to the next row
|
||||
current_x = 0
|
||||
current_y += self.key_width
|
||||
current_col = Decimal(0)
|
||||
current_row += Decimal(1)
|
||||
if current_row > self.rows:
|
||||
self.rows = Decimal(current_row)
|
||||
@@ -17,8 +17,10 @@ import argparse
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
from time import sleep
|
||||
|
||||
@@ -35,6 +37,10 @@ except ImportError:
|
||||
|
||||
import argcomplete
|
||||
import colorama
|
||||
from appdirs import user_config_dir
|
||||
|
||||
# Disable logging until we can configure it how the user wants
|
||||
logging.basicConfig(stream=os.devnull)
|
||||
|
||||
# Log Level Representations
|
||||
EMOJI_LOGLEVELS = {
|
||||
@@ -47,6 +53,7 @@ EMOJI_LOGLEVELS = {
|
||||
}
|
||||
EMOJI_LOGLEVELS['FATAL'] = EMOJI_LOGLEVELS['CRITICAL']
|
||||
EMOJI_LOGLEVELS['WARN'] = EMOJI_LOGLEVELS['WARNING']
|
||||
UNICODE_SUPPORT = sys.stdout.encoding.lower().startswith('utf')
|
||||
|
||||
# ANSI Color setup
|
||||
# Regex was gratefully borrowed from kfir on stackoverflow:
|
||||
@@ -90,25 +97,23 @@ def format_ansi(text):
|
||||
class ANSIFormatter(logging.Formatter):
|
||||
"""A log formatter that inserts ANSI color.
|
||||
"""
|
||||
|
||||
def format(self, record):
|
||||
msg = super(ANSIFormatter, self).format(record)
|
||||
return format_ansi(msg)
|
||||
|
||||
|
||||
class ANSIEmojiLoglevelFormatter(ANSIFormatter):
|
||||
"""A log formatter that makes the loglevel an emoji.
|
||||
"""A log formatter that makes the loglevel an emoji on UTF capable terminals.
|
||||
"""
|
||||
|
||||
def format(self, record):
|
||||
record.levelname = EMOJI_LOGLEVELS[record.levelname].format(**ansi_colors)
|
||||
if UNICODE_SUPPORT:
|
||||
record.levelname = EMOJI_LOGLEVELS[record.levelname].format(**ansi_colors)
|
||||
return super(ANSIEmojiLoglevelFormatter, self).format(record)
|
||||
|
||||
|
||||
class ANSIStrippingFormatter(ANSIFormatter):
|
||||
"""A log formatter that strips ANSI.
|
||||
"""
|
||||
|
||||
def format(self, record):
|
||||
msg = super(ANSIStrippingFormatter, self).format(record)
|
||||
return ansi_escape.sub('', msg)
|
||||
@@ -120,7 +125,6 @@ class Configuration(object):
|
||||
This class never raises IndexError, instead it will return None if a
|
||||
section or option does not yet exist.
|
||||
"""
|
||||
|
||||
def __contains__(self, key):
|
||||
return self._config.__contains__(key)
|
||||
|
||||
@@ -144,13 +148,15 @@ class Configuration(object):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._config = {}
|
||||
self.default_container = ConfigurationOption
|
||||
|
||||
def __getattr__(self, key):
|
||||
return self.__getitem__(key)
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Returns a config section, creating it if it doesn't exist yet.
|
||||
"""
|
||||
if key not in self._config:
|
||||
self.__dict__[key] = self._config[key] = ConfigurationOption()
|
||||
self.__dict__[key] = self._config[key] = ConfigurationSection(self)
|
||||
|
||||
return self._config[key]
|
||||
|
||||
@@ -161,30 +167,44 @@ class Configuration(object):
|
||||
def __delitem__(self, key):
|
||||
if key in self.__dict__ and key[0] != '_':
|
||||
del self.__dict__[key]
|
||||
del self._config[key]
|
||||
if key in self._config:
|
||||
del self._config[key]
|
||||
|
||||
|
||||
class ConfigurationOption(Configuration):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ConfigurationOption, self).__init__(*args, **kwargs)
|
||||
self.default_container = dict
|
||||
class ConfigurationSection(Configuration):
|
||||
def __init__(self, parent, *args, **kwargs):
|
||||
super(ConfigurationSection, self).__init__(*args, **kwargs)
|
||||
self.parent = parent
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Returns a config section, creating it if it doesn't exist yet.
|
||||
"""Returns a config value, pulling from the `user` section as a fallback.
|
||||
This is called when the attribute is accessed either via the get method or through [ ] index.
|
||||
"""
|
||||
if key not in self._config:
|
||||
self.__dict__[key] = self._config[key] = None
|
||||
if key in self._config and self._config.get(key) is not None:
|
||||
return self._config[key]
|
||||
|
||||
return self._config[key]
|
||||
elif key in self.parent.user:
|
||||
return self.parent.user[key]
|
||||
|
||||
return None
|
||||
|
||||
def __getattr__(self, key):
|
||||
"""Returns the config value from the `user` section.
|
||||
This is called when the attribute is accessed via dot notation but does not exists.
|
||||
"""
|
||||
if key in self.parent.user:
|
||||
return self.parent.user[key]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def handle_store_boolean(self, *args, **kwargs):
|
||||
"""Does the add_argument for action='store_boolean'.
|
||||
"""
|
||||
kwargs['add_dest'] = False
|
||||
disabled_args = None
|
||||
disabled_kwargs = kwargs.copy()
|
||||
disabled_kwargs['action'] = 'store_false'
|
||||
disabled_kwargs['dest'] = self.get_argument_name(*args, **kwargs)
|
||||
disabled_kwargs['help'] = 'Disable ' + kwargs['help']
|
||||
kwargs['action'] = 'store_true'
|
||||
kwargs['help'] = 'Enable ' + kwargs['help']
|
||||
@@ -201,9 +221,8 @@ def handle_store_boolean(self, *args, **kwargs):
|
||||
|
||||
|
||||
class SubparserWrapper(object):
|
||||
"""Wrap subparsers so we can populate the normal and the shadow parser.
|
||||
"""Wrap subparsers so we can track what options the user passed.
|
||||
"""
|
||||
|
||||
def __init__(self, cli, submodule, subparser):
|
||||
self.cli = cli
|
||||
self.submodule = submodule
|
||||
@@ -219,31 +238,30 @@ class SubparserWrapper(object):
|
||||
self.subparser.completer = completer
|
||||
|
||||
def add_argument(self, *args, **kwargs):
|
||||
if kwargs.get('add_dest', True):
|
||||
kwargs['dest'] = self.submodule + '_' + self.cli.get_argument_name(*args, **kwargs)
|
||||
if 'add_dest' in kwargs:
|
||||
del kwargs['add_dest']
|
||||
"""Add an argument for this subcommand.
|
||||
|
||||
This also stores the default for the argument in `self.cli.default_arguments`.
|
||||
"""
|
||||
if 'action' in kwargs and kwargs['action'] == 'store_boolean':
|
||||
# Store boolean will call us again with the enable/disable flag arguments
|
||||
return handle_store_boolean(self, *args, **kwargs)
|
||||
|
||||
self.cli.acquire_lock()
|
||||
self.subparser.add_argument(*args, **kwargs)
|
||||
|
||||
if 'default' in kwargs:
|
||||
del kwargs['default']
|
||||
if 'action' in kwargs and kwargs['action'] == 'store_false':
|
||||
kwargs['action'] == 'store_true'
|
||||
self.cli.subcommands_default[self.submodule].add_argument(*args, **kwargs)
|
||||
if self.submodule not in self.cli.default_arguments:
|
||||
self.cli.default_arguments[self.submodule] = {}
|
||||
self.cli.default_arguments[self.submodule][self.cli.get_argument_name(*args, **kwargs)] = kwargs.get('default')
|
||||
self.cli.release_lock()
|
||||
|
||||
|
||||
class MILC(object):
|
||||
"""MILC - An Opinionated Batteries Included Framework
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the MILC object.
|
||||
|
||||
version
|
||||
The version string to associate with your CLI program
|
||||
"""
|
||||
# Setup a lock for thread safety
|
||||
self._lock = threading.RLock() if thread else None
|
||||
@@ -254,13 +272,19 @@ class MILC(object):
|
||||
self._entrypoint = None
|
||||
self._inside_context_manager = False
|
||||
self.ansi = ansi_colors
|
||||
self.config = Configuration()
|
||||
self.arg_only = []
|
||||
self.config = None
|
||||
self.config_file = None
|
||||
self.prog_name = sys.argv[0][:-3] if sys.argv[0].endswith('.py') else sys.argv[0]
|
||||
self.version = os.environ.get('QMK_VERSION', 'unknown')
|
||||
self.default_arguments = {}
|
||||
self.version = 'unknown'
|
||||
self.release_lock()
|
||||
|
||||
# Figure out our program name
|
||||
self.prog_name = sys.argv[0][:-3] if sys.argv[0].endswith('.py') else sys.argv[0]
|
||||
self.prog_name = self.prog_name.split('/')[-1]
|
||||
|
||||
# Initialize all the things
|
||||
self.read_config_file()
|
||||
self.initialize_argparse()
|
||||
self.initialize_logging()
|
||||
|
||||
@@ -270,10 +294,10 @@ class MILC(object):
|
||||
|
||||
@description.setter
|
||||
def description(self, value):
|
||||
self._description = self._arg_parser.description = self._arg_defaults.description = value
|
||||
self._description = self._arg_parser.description = value
|
||||
|
||||
def echo(self, text, *args, **kwargs):
|
||||
"""Print colorized text to stdout, as long as stdout is a tty.
|
||||
"""Print colorized text to stdout.
|
||||
|
||||
ANSI color strings (such as {fg-blue}) will be converted into ANSI
|
||||
escape sequences, and the ANSI reset sequence will be added to all
|
||||
@@ -284,11 +308,10 @@ class MILC(object):
|
||||
if args and kwargs:
|
||||
raise RuntimeError('You can only specify *args or **kwargs, not both!')
|
||||
|
||||
if sys.stdout.isatty():
|
||||
args = args or kwargs
|
||||
text = format_ansi(text)
|
||||
args = args or kwargs
|
||||
text = format_ansi(text)
|
||||
|
||||
print(text % args)
|
||||
print(text % args)
|
||||
|
||||
def initialize_argparse(self):
|
||||
"""Prepare to process arguments from sys.argv.
|
||||
@@ -300,12 +323,9 @@ class MILC(object):
|
||||
|
||||
self.acquire_lock()
|
||||
self.subcommands = {}
|
||||
self.subcommands_default = {}
|
||||
self._subparsers = None
|
||||
self._subparsers_default = None
|
||||
self.argwarn = argcomplete.warn
|
||||
self.args = None
|
||||
self._arg_defaults = argparse.ArgumentParser(**kwargs)
|
||||
self._arg_parser = argparse.ArgumentParser(**kwargs)
|
||||
self.set_defaults = self._arg_parser.set_defaults
|
||||
self.print_usage = self._arg_parser.print_usage
|
||||
@@ -313,30 +333,23 @@ class MILC(object):
|
||||
self.release_lock()
|
||||
|
||||
def completer(self, completer):
|
||||
"""Add an arpcomplete completer to this subcommand.
|
||||
"""Add an argcomplete completer to this subcommand.
|
||||
"""
|
||||
self._arg_parser.completer = completer
|
||||
|
||||
def add_argument(self, *args, **kwargs):
|
||||
"""Wrapper to add arguments to both the main and the shadow argparser.
|
||||
"""Wrapper to add arguments and track whether they were passed on the command line.
|
||||
"""
|
||||
if kwargs.get('add_dest', True) and args[0][0] == '-':
|
||||
kwargs['dest'] = 'general_' + self.get_argument_name(*args, **kwargs)
|
||||
if 'add_dest' in kwargs:
|
||||
del kwargs['add_dest']
|
||||
|
||||
if 'action' in kwargs and kwargs['action'] == 'store_boolean':
|
||||
return handle_store_boolean(self, *args, **kwargs)
|
||||
|
||||
self.acquire_lock()
|
||||
self._arg_parser.add_argument(*args, **kwargs)
|
||||
|
||||
# Populate the shadow parser
|
||||
if 'default' in kwargs:
|
||||
del kwargs['default']
|
||||
if 'action' in kwargs and kwargs['action'] == 'store_false':
|
||||
kwargs['action'] == 'store_true'
|
||||
self._arg_defaults.add_argument(*args, **kwargs)
|
||||
self._arg_parser.add_argument(*args, **kwargs)
|
||||
if 'general' not in self.default_arguments:
|
||||
self.default_arguments['general'] = {}
|
||||
self.default_arguments['general'][self.get_argument_name(*args, **kwargs)] = kwargs.get('default')
|
||||
|
||||
self.release_lock()
|
||||
|
||||
def initialize_logging(self):
|
||||
@@ -363,15 +376,14 @@ class MILC(object):
|
||||
self.add_argument('--log-file-fmt', default='[%(levelname)s] [%(asctime)s] [file:%(pathname)s] [line:%(lineno)d] %(message)s', help='Format string for log file.')
|
||||
self.add_argument('--log-file', help='File to write log messages to')
|
||||
self.add_argument('--color', action='store_boolean', default=True, help='color in output')
|
||||
self.add_argument('-c', '--config-file', help='The config file to read and/or write')
|
||||
self.add_argument('--save-config', action='store_true', help='Save the running configuration to the config file')
|
||||
self.add_argument('--config-file', help='The location for the configuration file')
|
||||
self.arg_only.append('config_file')
|
||||
|
||||
def add_subparsers(self, title='Sub-commands', **kwargs):
|
||||
if self._inside_context_manager:
|
||||
raise RuntimeError('You must run this before the with statement!')
|
||||
|
||||
self.acquire_lock()
|
||||
self._subparsers_default = self._arg_defaults.add_subparsers(title=title, dest='subparsers', **kwargs)
|
||||
self._subparsers = self._arg_parser.add_subparsers(title=title, dest='subparsers', **kwargs)
|
||||
self.release_lock()
|
||||
|
||||
@@ -393,10 +405,12 @@ class MILC(object):
|
||||
if self.config_file:
|
||||
return self.config_file
|
||||
|
||||
if self.args and self.args.general_config_file:
|
||||
return self.args.general_config_file
|
||||
if '--config-file' in sys.argv:
|
||||
return Path(sys.argv[sys.argv.index('--config-file') + 1]).expanduser().resolve()
|
||||
|
||||
return os.path.abspath(os.path.expanduser('~/.%s.ini' % self.prog_name))
|
||||
filedir = user_config_dir(appname='qmk', appauthor='QMK')
|
||||
filename = '%s.ini' % self.prog_name
|
||||
return Path(filedir) / filename
|
||||
|
||||
def get_argument_name(self, *args, **kwargs):
|
||||
"""Takes argparse arguments and returns the dest name.
|
||||
@@ -413,11 +427,17 @@ class MILC(object):
|
||||
raise RuntimeError('You must run this before the with statement!')
|
||||
|
||||
def argument_function(handler):
|
||||
if 'arg_only' in kwargs and kwargs['arg_only']:
|
||||
arg_name = self.get_argument_name(*args, **kwargs)
|
||||
self.arg_only.append(arg_name)
|
||||
del kwargs['arg_only']
|
||||
|
||||
name = handler.__name__.replace("_", "-")
|
||||
if handler is self._entrypoint:
|
||||
self.add_argument(*args, **kwargs)
|
||||
|
||||
elif handler.__name__ in self.subcommands:
|
||||
self.subcommands[handler.__name__].add_argument(*args, **kwargs)
|
||||
elif name in self.subcommands:
|
||||
self.subcommands[name].add_argument(*args, **kwargs)
|
||||
|
||||
else:
|
||||
raise RuntimeError('Decorated function is not entrypoint or subcommand!')
|
||||
@@ -429,7 +449,7 @@ class MILC(object):
|
||||
def arg_passed(self, arg):
|
||||
"""Returns True if arg was passed on the command line.
|
||||
"""
|
||||
return self.args_passed[arg] in (None, False)
|
||||
return self.default_arguments.get(arg) != self.args[arg]
|
||||
|
||||
def parse_args(self):
|
||||
"""Parse the CLI args.
|
||||
@@ -442,25 +462,22 @@ class MILC(object):
|
||||
|
||||
self.acquire_lock()
|
||||
self.args = self._arg_parser.parse_args()
|
||||
self.args_passed = self._arg_defaults.parse_args()
|
||||
|
||||
if 'entrypoint' in self.args:
|
||||
self._entrypoint = self.args.entrypoint
|
||||
|
||||
if self.args.general_config_file:
|
||||
self.config_file = self.args.general_config_file
|
||||
|
||||
self.release_lock()
|
||||
|
||||
def read_config(self):
|
||||
"""Parse the configuration file and determine the runtime configuration.
|
||||
def read_config_file(self):
|
||||
"""Read in the configuration file and store it in self.config.
|
||||
"""
|
||||
self.acquire_lock()
|
||||
self.config = Configuration()
|
||||
self.config_file = self.find_config_file()
|
||||
|
||||
if self.config_file and os.path.exists(self.config_file):
|
||||
if self.config_file and self.config_file.exists():
|
||||
config = RawConfigParser(self.config)
|
||||
config.read(self.config_file)
|
||||
config.read(str(self.config_file))
|
||||
|
||||
# Iterate over the config file options and write them into self.config
|
||||
for section in config.sections():
|
||||
@@ -470,8 +487,10 @@ class MILC(object):
|
||||
# Coerce values into useful datatypes
|
||||
if value.lower() in ['1', 'yes', 'true', 'on']:
|
||||
value = True
|
||||
elif value.lower() in ['0', 'no', 'false', 'none', 'off']:
|
||||
elif value.lower() in ['0', 'no', 'false', 'off']:
|
||||
value = False
|
||||
elif value.lower() in ['none']:
|
||||
continue
|
||||
elif value.replace('.', '').isdigit():
|
||||
if '.' in value:
|
||||
value = Decimal(value)
|
||||
@@ -480,27 +499,50 @@ class MILC(object):
|
||||
|
||||
self.config[section][option] = value
|
||||
|
||||
# Fold the CLI args into self.config
|
||||
self.release_lock()
|
||||
|
||||
def merge_args_into_config(self):
|
||||
"""Merge CLI arguments into self.config to create the runtime configuration.
|
||||
"""
|
||||
self.acquire_lock()
|
||||
for argument in vars(self.args):
|
||||
if argument in ('subparsers', 'entrypoint'):
|
||||
continue
|
||||
|
||||
if '_' not in argument:
|
||||
continue
|
||||
if argument not in self.arg_only:
|
||||
# Find the argument's section
|
||||
# Underscores in command's names are converted to dashes during initialization.
|
||||
# TODO(Erovia) Find a better solution
|
||||
entrypoint_name = self._entrypoint.__name__.replace("_", "-")
|
||||
if entrypoint_name in self.default_arguments and argument in self.default_arguments[entrypoint_name]:
|
||||
argument_found = True
|
||||
section = self._entrypoint.__name__
|
||||
if argument in self.default_arguments['general']:
|
||||
argument_found = True
|
||||
section = 'general'
|
||||
|
||||
section, option = argument.split('_', 1)
|
||||
if hasattr(self.args_passed, argument):
|
||||
self.config[section][option] = getattr(self.args, argument)
|
||||
else:
|
||||
if option not in self.config[section]:
|
||||
self.config[section][option] = getattr(self.args, argument)
|
||||
if not argument_found:
|
||||
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
|
||||
exit(1)
|
||||
|
||||
# Merge this argument into self.config
|
||||
if argument in self.default_arguments['general'] or argument in self.default_arguments[entrypoint_name]:
|
||||
arg_value = getattr(self.args, argument)
|
||||
if arg_value is not None:
|
||||
self.config[section][argument] = arg_value
|
||||
else:
|
||||
if argument not in self.config[entrypoint_name]:
|
||||
# Check if the argument exist for this section
|
||||
arg = getattr(self.args, argument)
|
||||
if arg is not None:
|
||||
self.config[section][argument] = arg
|
||||
|
||||
self.release_lock()
|
||||
|
||||
def save_config(self):
|
||||
"""Save the current configuration to the config file.
|
||||
"""
|
||||
self.log.debug("Saving config file to '%s'", self.config_file)
|
||||
self.log.debug("Saving config file to '%s'", str(self.config_file))
|
||||
|
||||
if not self.config_file:
|
||||
self.log.warning('%s.config_file file not set, not saving config!', self.__class__.__name__)
|
||||
@@ -508,25 +550,34 @@ class MILC(object):
|
||||
|
||||
self.acquire_lock()
|
||||
|
||||
# Generate a sanitized version of our running configuration
|
||||
config = RawConfigParser()
|
||||
for section_name, section in self.config._config.items():
|
||||
config.add_section(section_name)
|
||||
for option_name, value in section.items():
|
||||
if section_name == 'general':
|
||||
if option_name in ['save_config']:
|
||||
if option_name in ['config_file']:
|
||||
continue
|
||||
config.set(section_name, option_name, str(value))
|
||||
if value is not None:
|
||||
config.set(section_name, option_name, str(value))
|
||||
|
||||
with NamedTemporaryFile(mode='w', dir=os.path.dirname(self.config_file), delete=False) as tmpfile:
|
||||
# Write out the config file
|
||||
config_dir = self.config_file.parent
|
||||
if not config_dir.exists():
|
||||
config_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with NamedTemporaryFile(mode='w', dir=str(config_dir), delete=False) as tmpfile:
|
||||
config.write(tmpfile)
|
||||
|
||||
# Move the new config file into place atomically
|
||||
if os.path.getsize(tmpfile.name) > 0:
|
||||
os.rename(tmpfile.name, self.config_file)
|
||||
os.rename(tmpfile.name, str(self.config_file))
|
||||
else:
|
||||
self.log.warning('Config file saving failed, not replacing %s with %s.', self.config_file, tmpfile.name)
|
||||
self.log.warning('Config file saving failed, not replacing %s with %s.', str(self.config_file), tmpfile.name)
|
||||
|
||||
# Housekeeping
|
||||
self.release_lock()
|
||||
cli.log.info('Wrote configuration to %s', shlex.quote(str(self.config_file)))
|
||||
|
||||
def __call__(self):
|
||||
"""Execute the entrypoint function.
|
||||
@@ -560,41 +611,37 @@ class MILC(object):
|
||||
|
||||
return entrypoint_func
|
||||
|
||||
def add_subcommand(self, handler, description, name=None, **kwargs):
|
||||
def add_subcommand(self, handler, description, name=None, hidden=False, **kwargs):
|
||||
"""Register a subcommand.
|
||||
|
||||
If name is not provided we use `handler.__name__`.
|
||||
"""
|
||||
|
||||
if self._inside_context_manager:
|
||||
raise RuntimeError('You must run this before the with statement!')
|
||||
|
||||
if self._subparsers is None:
|
||||
self.add_subparsers()
|
||||
self.add_subparsers(metavar="")
|
||||
|
||||
if not name:
|
||||
name = handler.__name__
|
||||
name = handler.__name__.replace("_", "-")
|
||||
|
||||
self.acquire_lock()
|
||||
kwargs['help'] = description
|
||||
self.subcommands_default[name] = self._subparsers_default.add_parser(name, **kwargs)
|
||||
if not hidden:
|
||||
self._subparsers.metavar = "{%s,%s}" % (self._subparsers.metavar[1:-1], name) if self._subparsers.metavar else "{%s%s}" % (self._subparsers.metavar[1:-1], name)
|
||||
kwargs['help'] = description
|
||||
self.subcommands[name] = SubparserWrapper(self, name, self._subparsers.add_parser(name, **kwargs))
|
||||
self.subcommands[name].set_defaults(entrypoint=handler)
|
||||
|
||||
if name not in self.__dict__:
|
||||
self.__dict__[name] = self.subcommands[name]
|
||||
else:
|
||||
self.log.debug("Could not add subcommand '%s' to attributes, key already exists!", name)
|
||||
|
||||
self.release_lock()
|
||||
|
||||
return handler
|
||||
|
||||
def subcommand(self, description, **kwargs):
|
||||
def subcommand(self, description, hidden=False, **kwargs):
|
||||
"""Decorator to register a subcommand.
|
||||
"""
|
||||
|
||||
def subcommand_function(handler):
|
||||
return self.add_subcommand(handler, description, **kwargs)
|
||||
return self.add_subcommand(handler, description, hidden=hidden, **kwargs)
|
||||
|
||||
return subcommand_function
|
||||
|
||||
@@ -602,8 +649,8 @@ class MILC(object):
|
||||
"""Called by __enter__() to setup the logging configuration.
|
||||
"""
|
||||
if len(logging.root.handlers) != 0:
|
||||
# This is not a design decision. This is what I'm doing for now until I can examine and think about this situation in more detail.
|
||||
raise RuntimeError('MILC should be the only system installing root log handlers!')
|
||||
# MILC is the only thing that should have root log handlers
|
||||
logging.root.handlers = []
|
||||
|
||||
self.acquire_lock()
|
||||
|
||||
@@ -616,9 +663,9 @@ class MILC(object):
|
||||
self.log_format = self.config['general']['log_fmt']
|
||||
|
||||
if self.config.general.color:
|
||||
self.log_format = ANSIEmojiLoglevelFormatter(self.args.general_log_fmt, self.config.general.datetime_fmt)
|
||||
self.log_format = ANSIEmojiLoglevelFormatter(self.args.log_fmt, self.config.general.datetime_fmt)
|
||||
else:
|
||||
self.log_format = ANSIStrippingFormatter(self.args.general_log_fmt, self.config.general.datetime_fmt)
|
||||
self.log_format = ANSIStrippingFormatter(self.args.log_fmt, self.config.general.datetime_fmt)
|
||||
|
||||
if self.log_file:
|
||||
self.log_file_handler = logging.FileHandler(self.log_file, self.log_file_mode)
|
||||
@@ -645,12 +692,9 @@ class MILC(object):
|
||||
|
||||
colorama.init()
|
||||
self.parse_args()
|
||||
self.read_config()
|
||||
self.merge_args_into_config()
|
||||
self.setup_logging()
|
||||
|
||||
if self.config.general.save_config:
|
||||
self.save_config()
|
||||
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
@@ -712,4 +756,3 @@ if __name__ == '__main__':
|
||||
cli.goodbye.add_argument('-n', '--name', help='Name to bid farewell to', default='World')
|
||||
|
||||
cli() # Automatically picks between main(), hello() and goodbye()
|
||||
print(sorted(ansi_colors.keys()))
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
"""QMK CLI Subcommands
|
||||
|
||||
We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
|
||||
"""
|
||||
from . import cformat
|
||||
from . import compile
|
||||
from . import config
|
||||
from . import doctor
|
||||
from . import flash
|
||||
from . import hello
|
||||
from . import json
|
||||
from . import list
|
||||
from . import kle2json
|
||||
from . import new
|
||||
from . import pyformat
|
||||
from . import pytest
|
||||
|
||||
@@ -2,26 +2,37 @@
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
from shutil import which
|
||||
|
||||
from milc import cli
|
||||
|
||||
|
||||
@cli.argument('files', nargs='*', help='Filename(s) to format.')
|
||||
@cli.entrypoint("Format C code according to QMK's style.")
|
||||
def main(cli):
|
||||
@cli.argument('files', nargs='*', arg_only=True, help='Filename(s) to format.')
|
||||
@cli.subcommand("Format C code according to QMK's style.")
|
||||
def cformat(cli):
|
||||
"""Format C code according to QMK's style.
|
||||
"""
|
||||
# Determine which version of clang-format to use
|
||||
clang_format = ['clang-format', '-i']
|
||||
for clang_version in [10, 9, 8, 7]:
|
||||
binary = 'clang-format-%d' % clang_version
|
||||
if which(binary):
|
||||
clang_format[0] = binary
|
||||
break
|
||||
|
||||
# Find the list of files to format
|
||||
if not cli.args.files:
|
||||
if cli.args.files:
|
||||
cli.args.files = [os.path.join(os.environ['ORIG_CWD'], file) for file in cli.args.files]
|
||||
else:
|
||||
ignores = ['tmk_core/protocol/usb_hid', 'quantum/template']
|
||||
for dir in ['drivers', 'quantum', 'tests', 'tmk_core']:
|
||||
for dirpath, dirnames, filenames in os.walk(dir):
|
||||
if 'tmk_core/protocol/usb_hid' in dirpath:
|
||||
if any(i in dirpath for i in ignores):
|
||||
dirnames.clear()
|
||||
continue
|
||||
|
||||
for name in filenames:
|
||||
if name.endswith('.c') or name.endswith('.h') or name.endswith('.cpp'):
|
||||
if name.endswith(('.c', '.h', '.cpp')):
|
||||
cli.args.files.append(os.path.join(dirpath, name))
|
||||
|
||||
# Run clang-format on the files we've found
|
||||
|
||||
@@ -2,23 +2,24 @@
|
||||
|
||||
You can compile a keymap already in the repo or using a QMK Configurator export.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import os
|
||||
from argparse import FileType
|
||||
|
||||
from milc import cli
|
||||
from qmk.commands import create_make_command
|
||||
from qmk.commands import parse_configurator_json
|
||||
from qmk.commands import compile_configurator_json
|
||||
|
||||
import qmk.keymap
|
||||
import qmk.path
|
||||
|
||||
|
||||
@cli.argument('filename', nargs='?', type=FileType('r'), help='The configurator export to compile')
|
||||
@cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), help='The configurator export to compile')
|
||||
@cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.')
|
||||
@cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.')
|
||||
@cli.entrypoint('Compile a QMK Firmware.')
|
||||
def main(cli):
|
||||
@cli.subcommand('Compile a QMK Firmware.')
|
||||
def compile(cli):
|
||||
"""Compile a QMK Firmware.
|
||||
|
||||
If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.
|
||||
@@ -28,25 +29,93 @@ def main(cli):
|
||||
If --keyboard and --keymap are provided this command will build a firmware based on that.
|
||||
|
||||
"""
|
||||
# Set CWD as directory command was issued from
|
||||
cwd = os.environ['ORIG_CWD']
|
||||
qmk_path = os.getcwd()
|
||||
current_folder = os.path.basename(cwd)
|
||||
# Initialize boolean to check for being in a keyboard directory and initialize keyboard string
|
||||
in_keyboard = False
|
||||
in_layout = False
|
||||
keyboard = ""
|
||||
keymap = ""
|
||||
user_keymap = ""
|
||||
user_keyboard = ""
|
||||
|
||||
# Set path for '/keyboards/' directory
|
||||
keyboards_path = os.path.join(qmk_path, "keyboards")
|
||||
layouts_path = os.path.join(qmk_path, "layouts")
|
||||
|
||||
# If below 'keyboards' and not in 'keyboards' or 'keymaps', get current keyboard name
|
||||
if cwd.startswith(keyboards_path):
|
||||
if current_folder != "keyboards" and current_folder != "keymaps":
|
||||
if os.path.basename(os.path.abspath(os.path.join(cwd, ".."))) == "keymaps":
|
||||
# If in a keymap folder, set relative path, get everything before /keymaps, and the keymap name
|
||||
relative_path = cwd[len(keyboards_path):][1:]
|
||||
keyboard = str(relative_path).split("/keymaps", 1)[0]
|
||||
keymap = str(relative_path.rsplit("/", 1)[-1])
|
||||
else:
|
||||
keyboard = str(cwd[len(keyboards_path):])[1:]
|
||||
|
||||
in_keyboard = True
|
||||
|
||||
# If in layouts dir
|
||||
if cwd.startswith(layouts_path):
|
||||
if current_folder != "layouts":
|
||||
in_layout = True
|
||||
|
||||
# If user keyboard/keymap or compile keyboard/keymap are supplied, assign those
|
||||
if cli.config.compile.keyboard:
|
||||
user_keyboard = cli.config.compile.keyboard
|
||||
if cli.config.compile.keymap and not in_layout:
|
||||
user_keymap = cli.config.compile.keymap
|
||||
|
||||
if cli.args.filename:
|
||||
# Parse the configurator json
|
||||
user_keymap = json.load(cli.args.filename)
|
||||
user_keymap = parse_configurator_json(cli.args.filename)
|
||||
|
||||
# Generate the keymap
|
||||
keymap_path = qmk.path.keymap(user_keymap['keyboard'])
|
||||
cli.log.info('Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path)
|
||||
qmk.keymap.write(user_keymap['keyboard'], user_keymap['keymap'], user_keymap['layout'], user_keymap['layers'])
|
||||
cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
|
||||
|
||||
# Compile the keymap
|
||||
command = ['make', ':'.join((user_keymap['keyboard'], user_keymap['keymap']))]
|
||||
command = compile_configurator_json(cli.args.filename)
|
||||
|
||||
elif cli.config.general.keyboard and cli.config.general.keymap:
|
||||
cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])
|
||||
|
||||
elif user_keyboard and user_keymap:
|
||||
# Generate the make command for a specific keyboard/keymap.
|
||||
command = ['make', ':'.join((cli.config.general.keyboard, cli.config.general.keymap))]
|
||||
command = create_make_command(user_keyboard, user_keymap)
|
||||
|
||||
elif in_keyboard:
|
||||
keyboard = user_keyboard if user_keyboard else keyboard
|
||||
keymap = user_keymap if user_keymap else keymap
|
||||
|
||||
if not os.path.exists(os.path.join(keyboards_path, keyboard, "rules.mk")):
|
||||
cli.log.error('This directory does not contain a rules.mk file. Change directory or supply --keyboard with optional --keymap')
|
||||
return False
|
||||
|
||||
# Get path for keyboard directory
|
||||
keymap_path = qmk.path.keymap(keyboard)
|
||||
|
||||
# Check for global keymap config first
|
||||
if keymap:
|
||||
command = create_make_command(keyboard, keymap)
|
||||
|
||||
else:
|
||||
# If no default keymap exists and none provided
|
||||
cli.log.error('This directory does not contain a keymap. Set one with `qmk config` or supply `--keymap` ')
|
||||
return False
|
||||
|
||||
elif in_layout:
|
||||
if user_keyboard:
|
||||
keymap = current_folder
|
||||
command = create_make_command(user_keyboard, keymap)
|
||||
else:
|
||||
cli.log.error('You must supply a keyboard to compile a layout keymap. Set one with `qmk config` or supply `--keyboard` ')
|
||||
return False
|
||||
|
||||
else:
|
||||
cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`.')
|
||||
cli.log.error('You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.')
|
||||
return False
|
||||
|
||||
cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
|
||||
|
||||
116
lib/python/qmk/cli/config.py
Normal file
116
lib/python/qmk/cli/config.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""Read and write configuration settings
|
||||
"""
|
||||
from milc import cli
|
||||
|
||||
|
||||
def print_config(section, key):
|
||||
"""Print a single config setting to stdout.
|
||||
"""
|
||||
cli.echo('%s.%s{fg_cyan}={fg_reset}%s', section, key, cli.config[section][key])
|
||||
|
||||
|
||||
def show_config():
|
||||
"""Print the current configuration to stdout.
|
||||
"""
|
||||
for section in cli.config:
|
||||
for key in cli.config[section]:
|
||||
print_config(section, key)
|
||||
|
||||
|
||||
def parse_config_token(config_token):
|
||||
"""Split a user-supplied configuration-token into its components.
|
||||
"""
|
||||
section = option = value = None
|
||||
|
||||
if '=' in config_token and '.' not in config_token:
|
||||
cli.log.error('Invalid configuration token, the key must be of the form <section>.<option>: %s', config_token)
|
||||
return section, option, value
|
||||
|
||||
# Separate the key (<section>.<option>) from the value
|
||||
if '=' in config_token:
|
||||
key, value = config_token.split('=')
|
||||
else:
|
||||
key = config_token
|
||||
|
||||
# Extract the section and option from the key
|
||||
if '.' in key:
|
||||
section, option = key.split('.', 1)
|
||||
else:
|
||||
section = key
|
||||
|
||||
return section, option, value
|
||||
|
||||
|
||||
def set_config(section, option, value):
|
||||
"""Set a config key in the running config.
|
||||
"""
|
||||
log_string = '%s.%s{fg_cyan}:{fg_reset} %s {fg_cyan}->{fg_reset} %s'
|
||||
if cli.args.read_only:
|
||||
log_string += ' {fg_red}(change not written)'
|
||||
|
||||
cli.echo(log_string, section, option, cli.config[section][option], value)
|
||||
|
||||
if not cli.args.read_only:
|
||||
if value == 'None':
|
||||
del cli.config[section][option]
|
||||
else:
|
||||
cli.config[section][option] = value
|
||||
|
||||
|
||||
@cli.argument('-ro', '--read-only', arg_only=True, action='store_true', help='Operate in read-only mode.')
|
||||
@cli.argument('configs', nargs='*', arg_only=True, help='Configuration options to read or write.')
|
||||
@cli.subcommand("Read and write configuration settings.")
|
||||
def config(cli):
|
||||
"""Read and write config settings.
|
||||
|
||||
This script iterates over the config_tokens supplied as argument. Each config_token has the following form:
|
||||
|
||||
section[.key][=value]
|
||||
|
||||
If only a section (EG 'compile') is supplied all keys for that section will be displayed.
|
||||
|
||||
If section.key is supplied the value for that single key will be displayed.
|
||||
|
||||
If section.key=value is supplied the value for that single key will be set.
|
||||
|
||||
If section.key=None is supplied the key will be deleted.
|
||||
|
||||
No validation is done to ensure that the supplied section.key is actually used by qmk scripts.
|
||||
"""
|
||||
if not cli.args.configs:
|
||||
return show_config()
|
||||
|
||||
# Process config_tokens
|
||||
save_config = False
|
||||
|
||||
for argument in cli.args.configs:
|
||||
# Split on space in case they quoted multiple config tokens
|
||||
for config_token in argument.split(' '):
|
||||
section, option, value = parse_config_token(config_token)
|
||||
|
||||
# Validation
|
||||
if option and '.' in option:
|
||||
cli.log.error('Config keys may not have more than one period! "%s" is not valid.', config_token)
|
||||
return False
|
||||
|
||||
# Do what the user wants
|
||||
if section and option and value:
|
||||
# Write a configuration option
|
||||
set_config(section, option, value)
|
||||
if not cli.args.read_only:
|
||||
save_config = True
|
||||
|
||||
elif section and option:
|
||||
# Display a single key
|
||||
print_config(section, option)
|
||||
|
||||
elif section:
|
||||
# Display an entire section
|
||||
for key in cli.config[section]:
|
||||
print_config(section, key)
|
||||
|
||||
# Ending actions
|
||||
if save_config:
|
||||
cli.save_config()
|
||||
|
||||
return True
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user