aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfredizzimo <fsundvik@gmail.com>2016-07-01 17:04:53 +0300
committerJack Humbert <jack.humb@gmail.com>2016-07-01 10:04:53 -0400
commit4d4f7684e684bec319f166121463a88cd4a62703 (patch)
tree4c04ce03e49356283925556342845b1bd656e930
parenta8b55f8c858933a0f7641f7bf2dede640235aa70 (diff)
downloadqmk_firmware-4d4f7684e684bec319f166121463a88cd4a62703.tar.gz
qmk_firmware-4d4f7684e684bec319f166121463a88cd4a62703.zip
Add ChibiOS support for QMK (#465)
* Modularity and gcc warnings fixes. * Add ChibiOS support (USB stack + support files). * Make usb_main more USB_DRIVER #define independent. * Move chibios to tool. * Implement jump-to-bootloader. * Small updates. * Fix bootloader-jump compiling. * Move AVR specific sleep_led.c into avr. * Add basic sleep_led for chibios. * Update chibios README. * NKRO fixes. * Rename some Makefile defines. * Move STM32 bootloader address config to separate .h file. * Add ARM Teensies bootloader code. * Fix chibios/usb_main GET_REPORT handing. * Add missing #include to keymap.c. * Make bootmagic.c code portable (_delay_ms -> wait_ms). * Move declaration of keymap_config. Should really not declare variables in .h files - since it's included in different .c files, a proper linker then complains that the same variable is declared more than once (once for each .c file that the offending .h is included in). * Add eeprom support for chibios/kinetis. * Rename chibios example keyboard. * Move chibios/cortex selection to local Makefiles. * Chibios: use WFI in idle. WIP suspend stuff. * ChibiOS/kinetis: sending remote wakeup. * ChibiOS/STM32: send remote wakeup. * Fix report size of boot protocol. * Fix drop key stroke Keyboard report should be checked if its transfer finishs successfully. Otherwise key stroke can be missing when other key event occurs before the last report transfer is done. Boot protocol 10ms interval probably causes this problem in case it receives key events in a row within the period. NKRO protocol suffers less or nothing due to its interval 1ms. * Chibios/usb_main: rename a variable for clarity. * Add correct chibios/bootloader_jump for infinity KB. * ChibiOS: make reset request more CMSISy. * Chibios: Add breathing sleep LED on Kinetis MCUs. * ChibiOS: Update infinity bootloader code to match updated ChibiOS. * ChibiOS: prettify/document sleep_led code. * Chibios: Remove the wait in the main loop. * Add maple mini code. * Do timeout when writing to CONSOLE EP queue. Fixes TMK bug #266. * Chibios: add 'core/protocol' to the makefiles' search path. * Chibios: Update to new USB API. * Chibios: add more guards for transmitting (fix a deadlock bug). * Add update for chibios in README * Chibios: Fix a HardFault bug (wait after start). * Chibios: cleanup usb_main code. * Chibios: Revert common.mk change (fix AVR linking problem). * core: Fix chibios user compile options Compile options can be defined in project Makefile such as UDEFS, UADEFS, UINCDIR, ULIBDIR and ULIBS. * Sysv format for ChibiOS arm-none-eabi-size Some new patches to ChibiOS puts heap as it's own section. So the berkeley format is now useless, as the heap will be included in the BSS report. The sysv format displays the bss size correctly. * Fix hard-coded path of CHIBIOS * Add support for new version of ChibiOS and Contrib The Kinetis support has moved to a separate Contrib repository in the newest version of Chibios. There has also been some structure changes. So this adds support for those, while maintaining back- wards compability. * Update ChibiOS instructions * Chibios: implement sleep LED for STM32. * Chibios: Update the main chibios README. * Chibios: fix STM32_BOOTLOADER_ADDRESS name. * Chibios: make the default bootloader_jump redefinable (weak). * Chibios: disable LTO (link-time optimisation). With LTO enabled, sometimes things fail for mysterious reasons (e.g. bootloader jump on WF with LEDs enabled), just because the linker optimisation is too aggressive. * Chibios: add default location for chibios-contrib. * ChibiOS: update mk to match chibios/master. * ChibiOS: update instructions.md. * Add chibi_onekey example. * Add comments to chibi_onekey Makefile. * Rename some Makefile defines. * Move STM32 bootloader address config to separate .h file. * Rename chibios example keyboard. * Move chibios/cortex selection to local Makefiles. * Add Teensy LC onekey example. * Chibios: use WFI in idle. WIP suspend stuff. * Update chibi/teensy instructions. * Update chibios/Teensy instructions. * Add infinity_chibios * Add keymap_hasu.c * Infinity_chibios: select correct bootloader_jump. * Infinity_chibios: improve comments. * Add generic STM32F103C8T6 example. * Add maple mini code. * STM32F103x fixes. * Add maple mini pinout pic. * Chibios: updates for 3.0.4 git. * Chibios: rename example stm32_onekey -> stm32_f072_onekey. * Chibios: add makefiles for Teensy 3.x examples. * Chibios: update Teensy 3.x instructions. * Chibios: Tsy LC is cortex-m0plus. * Chibios: add more guards for transmitting (fix a deadlock bug). * Change README for chibios * Chibios: update examples to current chibios git. Match the changes in mainline chibios: - update chconf.h - update supplied ld scripts structure - update Teensy instructions (switch to official chibios and introduce contrib) * Add ChibiOS and ChibiOS-Contrib submodules Also fix the makefile path for them. * Moves chibios keyboards to keyboards folder * First version of ChibiOS compilation Only the stm32_f072_onkey keyboard is ported at the moment. It compiles, but still doesn't link. * More chibios fixes It now compiles without warnings and links * Move the teensy_lc_onekey to the keyboards folder * Clean up the make file rule structure * Remove keymap_fn_to_action * Update more ChibiOS keyboards to QMK Most of them does not compile at the moment though. * Use older version of Chibios libraries The newest ones have problems with compilation * Remove USB_UNCONFIGURED event It isn't present in the older version of ChibiOS * Fix the infinity_chibios compilation * Fix potentially uninitialized variable * Add missing include * Fix the ChibiOS makefile * Fix some Chibios keyboard compilation * Revert the rules.mk file back to master version * Combine the chibios and AVR makefiles With just the required overrides in the respective platform specific one. * Slight makefile restrucuring Platform specific compiler options * Move avr specific targets out of the main rules * Fix ChibiOS objcopy The ChibiOS objcopy needs different parameters, so the parameters are moved to the corresponding platform rule file * Fix the objcopy for real this time The comands were moved around, so chibios used avr and the ohter way around. Also change the objsize output format * Fix the thumb flags * Fix the infinity hasu keymap * Per platform cpp flags * Add gcc-arm-none-eabi package to travis * Add arm-none-eabi-newlib to travis * Fix the name of the libnewlib-arm-none-eabi lib * Fix the ChibiOS paths So that they are properly relative, and builds don't generate extra folders * Fix the board path of stm32_f103_onekey * Only consider folders with Makefiles as subproject
-rw-r--r--.gitmodules6
-rw-r--r--.travis.yml5
-rw-r--r--Makefile31
-rw-r--r--keyboards/infinity_chibios/MEMO.txt385
-rw-r--r--keyboards/infinity_chibios/Makefile70
-rw-r--r--keyboards/infinity_chibios/bootloader_defs.h1
-rw-r--r--keyboards/infinity_chibios/chconf.h524
-rw-r--r--keyboards/infinity_chibios/config.h75
-rw-r--r--keyboards/infinity_chibios/halconf.h353
-rw-r--r--keyboards/infinity_chibios/infinity_chibios.c17
-rw-r--r--keyboards/infinity_chibios/infinity_chibios.h66
-rw-r--r--keyboards/infinity_chibios/keymaps/default/keymap.c48
-rw-r--r--keyboards/infinity_chibios/keymaps/hasu/keymap.c199
-rw-r--r--keyboards/infinity_chibios/led.c24
-rw-r--r--keyboards/infinity_chibios/matrix.c128
-rw-r--r--keyboards/infinity_chibios/mcuconf.h55
-rw-r--r--keyboards/planck/out.txt66
-rw-r--r--keyboards/stm32_f072_onekey/Makefile50
-rw-r--r--keyboards/stm32_f072_onekey/bootloader_defs.h7
-rw-r--r--keyboards/stm32_f072_onekey/chconf.h524
-rw-r--r--keyboards/stm32_f072_onekey/config.h76
-rw-r--r--keyboards/stm32_f072_onekey/halconf.h353
-rw-r--r--keyboards/stm32_f072_onekey/keymaps/default/keymap.c25
-rw-r--r--keyboards/stm32_f072_onekey/led.c34
-rw-r--r--keyboards/stm32_f072_onekey/matrix.c163
-rw-r--r--keyboards/stm32_f072_onekey/mcuconf.h171
-rw-r--r--keyboards/stm32_f072_onekey/stm32_f072_onekey.c1
-rw-r--r--keyboards/stm32_f072_onekey/stm32_f072_onekey.h5
-rw-r--r--keyboards/stm32_f103_onekey/Makefile64
-rw-r--r--keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.c49
-rw-r--r--keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.h166
-rw-r--r--keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.mk5
-rw-r--r--keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/mini_stm32_mapping.pngbin0 -> 162908 bytes
-rw-r--r--keyboards/stm32_f103_onekey/boards/maple_mini_mapping.pngbin0 -> 237977 bytes
-rw-r--r--keyboards/stm32_f103_onekey/bootloader_defs.h10
-rw-r--r--keyboards/stm32_f103_onekey/chconf.h524
-rw-r--r--keyboards/stm32_f103_onekey/config.h75
-rwxr-xr-xkeyboards/stm32_f103_onekey/flash.sh2
-rw-r--r--keyboards/stm32_f103_onekey/halconf.h353
-rw-r--r--keyboards/stm32_f103_onekey/keymaps/default/keymap.c25
-rw-r--r--keyboards/stm32_f103_onekey/ld/STM32F103x8_stm32duino_bootloader.ld88
-rw-r--r--keyboards/stm32_f103_onekey/led.c43
-rw-r--r--keyboards/stm32_f103_onekey/matrix.c177
-rw-r--r--keyboards/stm32_f103_onekey/mcuconf.h209
-rw-r--r--keyboards/stm32_f103_onekey/stm32_f103_onekey.c1
-rw-r--r--keyboards/stm32_f103_onekey/stm32_f103_onekey.h4
-rw-r--r--keyboards/teensy_lc_onekey/Makefile62
-rw-r--r--keyboards/teensy_lc_onekey/Makefile.3.077
-rw-r--r--keyboards/teensy_lc_onekey/Makefile.3.277
-rw-r--r--keyboards/teensy_lc_onekey/chconf.h524
-rw-r--r--keyboards/teensy_lc_onekey/config.h75
-rw-r--r--keyboards/teensy_lc_onekey/halconf.h187
-rw-r--r--keyboards/teensy_lc_onekey/instructions.md82
-rw-r--r--keyboards/teensy_lc_onekey/keymaps/default/keymap.c32
-rw-r--r--keyboards/teensy_lc_onekey/ld/MKL26Z64.ld105
-rw-r--r--keyboards/teensy_lc_onekey/led.c32
-rw-r--r--keyboards/teensy_lc_onekey/matrix.c163
-rw-r--r--keyboards/teensy_lc_onekey/mcuconf.h55
-rw-r--r--keyboards/teensy_lc_onekey/teensy_lc_onekey.c1
-rw-r--r--keyboards/teensy_lc_onekey/teensy_lc_onekey.h4
m---------lib/chibios0
m---------lib/chibios-contrib0
-rw-r--r--quantum/keycode_config.h2
-rw-r--r--quantum/keymap.h11
-rw-r--r--quantum/keymap_common.c (renamed from quantum/keymap.c)10
-rw-r--r--quantum/matrix.c2
-rw-r--r--quantum/quantum.c2
-rw-r--r--quantum/quantum.h8
-rw-r--r--readme.md3
-rw-r--r--tmk_core/avr.mk185
-rw-r--r--tmk_core/chibios.mk154
-rw-r--r--tmk_core/common.mk36
-rw-r--r--tmk_core/common/action_tapping.c2
-rw-r--r--tmk_core/common/avr/sleep_led.c (renamed from tmk_core/common/sleep_led.c)0
-rw-r--r--tmk_core/common/bootmagic.c7
-rw-r--r--tmk_core/common/chibios/bootloader.c47
-rw-r--r--tmk_core/common/chibios/eeprom.c588
-rw-r--r--tmk_core/common/chibios/printf.c240
-rw-r--r--tmk_core/common/chibios/printf.h111
-rw-r--r--tmk_core/common/chibios/sleep_led.c226
-rw-r--r--tmk_core/common/chibios/suspend.c65
-rw-r--r--tmk_core/common/chibios/timer.c27
-rw-r--r--tmk_core/common/command.c23
-rw-r--r--tmk_core/common/eeconfig.c (renamed from tmk_core/common/avr/eeconfig.c)2
-rw-r--r--tmk_core/common/eeprom.h22
-rw-r--r--tmk_core/common/magic.c4
-rw-r--r--tmk_core/common/print.c8
-rw-r--r--tmk_core/common/print.h10
-rw-r--r--tmk_core/common/progmem.h4
-rw-r--r--tmk_core/common/report.h5
-rw-r--r--tmk_core/common/wait.h8
-rw-r--r--tmk_core/protocol/chibios.mk10
-rw-r--r--tmk_core/protocol/chibios/README.md55
-rw-r--r--tmk_core/protocol/chibios/main.c147
-rw-r--r--tmk_core/protocol/chibios/usb_main.c1372
-rw-r--r--tmk_core/protocol/chibios/usb_main.h139
-rw-r--r--tmk_core/readme.md16
-rw-r--r--tmk_core/rules.mk220
-rw-r--r--tmk_core/tool/chibios/.gitignore2
-rw-r--r--tmk_core/tool/chibios/ch-bootloader-jump.patch116
100 files changed, 10364 insertions, 258 deletions
diff --git a/.gitmodules b/.gitmodules
index e69de29bb..1576b8dc0 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -0,0 +1,6 @@
1[submodule "lib/chibios"]
2 path = lib/chibios
3 url = https://github.com/ChibiOS/ChibiOS.git
4[submodule "lib/chibios-contrib"]
5 path = lib/chibios-contrib
6 url = https://github.com/ChibiOS/ChibiOS-Contrib.git
diff --git a/.travis.yml b/.travis.yml
index 955f69679..26deac0ce 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,4 +18,7 @@ addons:
18 - gcc-avr 18 - gcc-avr
19 - dfu-programmer 19 - dfu-programmer
20 - pandoc 20 - pandoc
21after_success: bash util/travis_compiled_push.sh \ No newline at end of file 21 - gcc-arm-none-eabi
22 - binutils-arm-none-eabi
23 - libnewlib-arm-none-eabi
24after_success: bash util/travis_compiled_push.sh
diff --git a/Makefile b/Makefile
index f9b865b9f..c285dabad 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,8 @@ ifndef VERBOSE
2.SILENT: 2.SILENT:
3endif 3endif
4 4
5.DEFAULT_GOAL := all
6
5space := $(subst ,, ) 7space := $(subst ,, )
6starting_makefile := $(subst $(space),_SPACE_,$(abspath $(firstword $(MAKEFILE_LIST)))) 8starting_makefile := $(subst $(space),_SPACE_,$(abspath $(firstword $(MAKEFILE_LIST))))
7mkfile_path := $(subst $(space),_SPACE_,$(abspath $(lastword $(MAKEFILE_LIST)))) 9mkfile_path := $(subst $(space),_SPACE_,$(abspath $(lastword $(MAKEFILE_LIST))))
@@ -41,6 +43,7 @@ endif
41TOP_DIR = $(tmk_root) 43TOP_DIR = $(tmk_root)
42TMK_DIR = tmk_core 44TMK_DIR = tmk_core
43TMK_PATH = $(TOP_DIR)/$(TMK_DIR) 45TMK_PATH = $(TOP_DIR)/$(TMK_DIR)
46LIB_PATH = $(TOP_DIR)/lib
44 47
45QUANTUM_DIR = quantum 48QUANTUM_DIR = quantum
46QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR) 49QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR)
@@ -126,6 +129,13 @@ ifdef SUBPROJECT
126else 129else
127 TARGET ?= $(KEYBOARD)_$(KEYMAP) 130 TARGET ?= $(KEYBOARD)_$(KEYMAP)
128endif 131endif
132BUILD_DIR = .build
133
134# Object files directory
135# To put object files in current directory, use a dot (.), do NOT make
136# this an empty or blank macro!
137OBJDIR = $(BUILD_DIR)/obj_$(TARGET)
138
129 139
130 140
131ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","") 141ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
@@ -143,7 +153,7 @@ endif
143SRC += $(KEYBOARD_FILE) \ 153SRC += $(KEYBOARD_FILE) \
144 $(KEYMAP_FILE) \ 154 $(KEYMAP_FILE) \
145 $(QUANTUM_DIR)/quantum.c \ 155 $(QUANTUM_DIR)/quantum.c \
146 $(QUANTUM_DIR)/keymap.c \ 156 $(QUANTUM_DIR)/keymap_common.c \
147 $(QUANTUM_DIR)/keycode_config.c \ 157 $(QUANTUM_DIR)/keycode_config.c \
148 $(QUANTUM_DIR)/process_keycode/process_leader.c 158 $(QUANTUM_DIR)/process_keycode/process_leader.c
149 159
@@ -208,8 +218,25 @@ VPATH += $(QUANTUM_PATH)/keymap_extras
208VPATH += $(QUANTUM_PATH)/audio 218VPATH += $(QUANTUM_PATH)/audio
209VPATH += $(QUANTUM_PATH)/process_keycode 219VPATH += $(QUANTUM_PATH)/process_keycode
210 220
211include $(TMK_PATH)/protocol/lufa.mk 221
222# We can assume a ChibiOS target When MCU_FAMILY is defined, since it's not used for LUFA
223ifdef MCU_FAMILY
224 PLATFORM=CHIBIOS
225else
226 PLATFORM=AVR
227endif
228
212include $(TMK_PATH)/common.mk 229include $(TMK_PATH)/common.mk
230ifeq ($(PLATFORM),AVR)
231 include $(TMK_PATH)/protocol/lufa.mk
232 include $(TMK_PATH)/avr.mk
233else ifeq ($(PLATFORM),CHIBIOS)
234 include $(TMK_PATH)/protocol/chibios.mk
235 include $(TMK_PATH)/chibios.mk
236else
237 $(error Unknown platform)
238endif
239
213include $(TMK_PATH)/rules.mk 240include $(TMK_PATH)/rules.mk
214 241
215GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S") 242GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S")
diff --git a/keyboards/infinity_chibios/MEMO.txt b/keyboards/infinity_chibios/MEMO.txt
new file mode 100644
index 000000000..e2886aa00
--- /dev/null
+++ b/keyboards/infinity_chibios/MEMO.txt
@@ -0,0 +1,385 @@
1flabbergast's TMK/ChibiOS port
2==============================
32015/10/16
4
5
6Build
7-----
8$ git clone -b chibios https://github.com/flabbergast/tmk_keyboard.git
9
10$ cd tmk_keyboard
11$ git submodule add -f -b kinetis https://github.com/flabbergast/ChibiOS.git tmk_core/tool/chibios/chibios
12or
13$ cd tmk_keyboard/tmk_core/tool/chibios
14$ git clone -b kinetis https://github.com/flabbergast/ChibiOS.git tmk_core/tool/chibios/chibios
15
16$ cd tmk_keyboard/keyboard/infinity_chibios
17$ make
18
19
20
21
22Chibios Configuration
23---------------------
24halconf.h: for HAL configuration
25 placed in project directory
26 read in chibios/os/hal/hal.mk
27 included in chibios/os/hal/include/hal.h
28mcuconf.h: for MCU configuration
29 placed in project directory
30 included in halconf.h
31
32
33Chibios Term
34------------
35PAL = Port Abstraction Layer
36 palWritePad
37 palReadPad
38 palSetPad
39 chibios/os/hal/include/pal.h
40
41LLD = Low Level Driver
42
43
44Makefile
45--------
46 # <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
47 MCU_FAMILY = KINETIS
48 MCU_SERIES = KL2x
49
50 # - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
51 # or <this_dir>/ld/
52 MCU_LDSCRIPT = MKL26Z64
53
54 # - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
55 MCU_STARTUP = kl2x
56
57 # Board: it should exist either in <chibios>/os/hal/boards/
58 # or <this_dir>/boards
59 BOARD = PJRC_TEENSY_LC
60
61 MCU = cortex-m0
62
63 # ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
64 ARMV = 6
65
66
67halconf.h
68---------
69
70
71mcuconf.h
72---------
73
74
75chconf.h
76--------
77
78
79ld script
80---------
81--- ../../tmk_core/tool/chibios/chibios/os/common/ports/ARMCMx/compilers/GCC/ld/MKL26Z64.ld 2015-10-15 09:08:58.732904304 +0900
82+++ ld/MKL26Z64.ld 2015-10-15 08:48:06.430215496 +0900
83@@ -27,7 +27,8 @@
84 {
85 flash0 : org = 0x00000000, len = 0xc0
86 flashcfg : org = 0x00000400, len = 0x10
87- flash : org = 0x00000410, len = 64k - 0x410
88+ flash : org = 0x00000410, len = 62k - 0x410
89+ eeprom_emu : org = 0x0000F800, len = 2k
90 ram : org = 0x1FFFF800, len = 8k
91 }
92
93@@ -35,6 +36,10 @@
94 __ram_size__ = LENGTH(ram);
95 __ram_end__ = __ram_start__ + __ram_size__;
96
97+__eeprom_workarea_start__ = ORIGIN(eeprom_emu);
98+__eeprom_workarea_size__ = LENGTH(eeprom_emu);
99+__eeprom_workarea_end__ = __eeprom_workarea_start__ + __eeprom_workarea_size__;
100+
101 SECTIONS
102 {
103 . = 0;
104
105
106
107Configuration/Startup for Infinity 60%
108--------------------------------------
109Configuration:
110
111
112Clock:
113Inifinity
114 FEI(FLL Engaged Internal) mode with core clock:48MHz, bus clock:48MHz, flash clock:24MHz
115 Clock dividor:
116 SIM_CLKDIV1[OUTDIV1] = 0 divide-by-1 for core clock
117 SIM_CLKDIV1[OUTDIV2] = 0 divide-by-1 for bus clock
118 SIM_CLKDIV1[OUTDIV4] = 1 divide-by-2 for flash clock
119 Internal reference clock:
120 MCG_C1[IREFS] = 1 Internal Reference Select for clock source for FLL
121 MCG_C1[IRCLKEN] = 1 Internal Reference Clock Enable
122 FLL multipilication:
123 MCG_C4[DMX32] = 1
124 MCG_C4[DRST_DRS] = 01 FLL factor 1464 * 32.768kHz = 48MHz
125
126chibios/os/hal/ports/KINETIS/K20x/hal_lld.c
127 k20x_clock_init(): called in __early_init() defined in board.c
128 disable watchdog and configure clock
129
130 configurable macros:
131 KINETIS_NO_INIT: whether init or not
132 KINETIS_MCG_MODE: clock mode
133 KINETIS_MCG_MODE_FEI
134 KINETIS_MCG_MODE_PEE
135 hal/ports/KINETIS/K20x/hal_lld.h
136
137
138chibios/os/hal/boards/FREESCALE_FREEDOM_K20D50M/board.h
139 PALConfig pal_default_config
140 boardInit()
141 __early_init()
142 macro definitions for board infos, freq and mcu type
143
144chibios/os/hal/boards/FREESCALE_FREEDOM_K20D50M/board.c
145
146USB
147
148
149Startup
150-------
151 common/ports/ARMCMx/GCC/crt0_v[67]m.s
152 Reset_Handler: startup code
153 common/ports/ARMCMx/GCC/crt1.c
154 __core_init(): weak
155 __early_init(): weak
156 __late_init(): weak
157 __default_exit(): weak
158 called from Reset_Handler of crt0
159 common/ports/ARMCMx/GCC/vector.c
160 common/ports/ARMCMx/GCC/ld/*.ld
161
162chibios/os/common/ports/ARMCMx/compilers/GCC/
163├── crt0_v6m.s
164├── crt0_v7m.s
165├── crt1.c
166├── ld
167│   ├── MK20DX128BLDR3.ld
168│   ├── MK20DX128BLDR4.ld
169│   ├── MK20DX128.ld
170│   ├── MK20DX256.ld
171│   ├── MKL25Z128.ld
172│   ├── MKL26Z128.ld
173│   ├── MKL26Z64.ld
174│   └── STM32L476xG.ld
175├── mk
176│   ├── startup_k20x5.mk
177│   ├── startup_k20x7.mk
178│   ├── startup_k20x.mk
179│   ├── startup_kl2x.mk
180│   └── startup_stm32l4xx.mk
181├── rules.ld
182├── rules.mk
183└── vectors.c
184
185chibios/os/hal/
186├── boards
187│   ├── FREESCALE_FREEDOM_K20D50M
188│   │   ├── board.c
189│   │   ├── board.h
190│   │   └── board.mk
191│   ├── MCHCK_K20
192│   │   ├── board.c
193│   │   ├── board.h
194│   │   └── board.mk
195│   ├── PJRC_TEENSY_3
196│   │   ├── board.c
197│   │   ├── board.h
198│   │   └── board.mk
199│   ├── PJRC_TEENSY_3_1
200│   │   ├── board.c
201│   │   ├── board.h
202│   │   └── board.mk
203│   ├── PJRC_TEENSY_LC
204│   │   ├── board.c
205│   │   ├── board.h
206│   │   └── board.mk
207│   ├── readme.txt
208│   ├── simulator
209│   │   ├── board.c
210│   │   ├── board.h
211│   │   └── board.mk
212│   ├── ST_NUCLEO_F030R8
213│   │   ├── board.c
214│   │   ├── board.h
215│   │   ├── board.mk
216│   │   └── cfg
217│   │   └── board.chcfg
218├── hal.mk
219├── include
220│   ├── adc.h
221│   ├── can.h
222│   ├── dac.h
223│   ├── ext.h
224│   ├── gpt.h
225│   ├── hal_channels.h
226│   ├── hal_files.h
227│   ├── hal.h
228│   ├── hal_ioblock.h
229│   ├── hal_mmcsd.h
230│   ├── hal_queues.h
231│   ├── hal_streams.h
232│   ├── i2c.h
233│   ├── i2s.h
234│   ├── icu.h
235│   ├── mac.h
236│   ├── mii.h
237│   ├── mmc_spi.h
238│   ├── pal.h
239│   ├── pwm.h
240│   ├── rtc.h
241│   ├── sdc.h
242│   ├── serial.h
243│   ├── serial_usb.h
244│   ├── spi.h
245│   ├── st.h
246│   ├── uart.h
247│   └── usb.h
248├── lib
249│   └── streams
250│   ├── chprintf.c
251│   ├── chprintf.h
252│   ├── memstreams.c
253│   ├── memstreams.h
254│   ├── nullstreams.c
255│   └── nullstreams.h
256├── osal
257│   ├── nil
258│   │   ├── osal.c
259│   │   ├── osal.h
260│   │   └── osal.mk
261│   ├── os-less
262│   │   └── ARMCMx
263│   │   ├── osal.c
264│   │   ├── osal.h
265│   │   └── osal.mk
266│   └── rt
267│   ├── osal.c
268│   ├── osal.h
269│   └── osal.mk
270├── ports
271│   ├── AVR
272│   ├── common
273│   │   └── ARMCMx
274│   │   ├── mpu.h
275│   │   ├── nvic.c
276│   │   └── nvic.h
277│   ├── KINETIS
278│   │   ├── K20x
279│   │   │   ├── hal_lld.c
280│   │   │   ├── hal_lld.h
281│   │   │   ├── kinetis_registry.h
282│   │   │   ├── platform.dox
283│   │   │   ├── platform.mk
284│   │   │   ├── pwm_lld.c
285│   │   │   ├── pwm_lld.h
286│   │   │   ├── spi_lld.c
287│   │   │   └── spi_lld.h
288│   │   ├── KL2x
289│   │   │   ├── hal_lld.c
290│   │   │   ├── hal_lld.h
291│   │   │   ├── kinetis_registry.h
292│   │   │   ├── platform.mk
293│   │   │   ├── pwm_lld.c
294│   │   │   └── pwm_lld.h
295│   │   ├── LLD
296│   │   │   ├── adc_lld.c
297│   │   │   ├── adc_lld.h
298│   │   │   ├── ext_lld.c
299│   │   │   ├── ext_lld.h
300│   │   │   ├── gpt_lld.c
301│   │   │   ├── gpt_lld.h
302│   │   │   ├── i2c_lld.c
303│   │   │   ├── i2c_lld.h
304│   │   │   ├── pal_lld.c
305│   │   │   ├── pal_lld.h
306│   │   │   ├── serial_lld.c
307│   │   │   ├── serial_lld.h
308│   │   │   ├── st_lld.c
309│   │   │   ├── st_lld.h
310│   │   │   ├── usb_lld.c
311│   │   │   └── usb_lld.h
312│   │   └── README.md
313│   ├── LPC
314│   ├── simulator
315│   └── STM32
316├── src
317│   ├── adc.c
318│   ├── can.c
319│   ├── dac.c
320│   ├── ext.c
321│   ├── gpt.c
322│   ├── hal.c
323│   ├── hal_mmcsd.c
324│   ├── hal_queues.c
325│   ├── i2c.c
326│   ├── i2s.c
327│   ├── icu.c
328│   ├── mac.c
329│   ├── mmc_spi.c
330│   ├── pal.c
331│   ├── pwm.c
332│   ├── rtc.c
333│   ├── sdc.c
334│   ├── serial.c
335│   ├── serial_usb.c
336│   ├── spi.c
337│   ├── st.c
338│   ├── uart.c
339│   └── usb.c
340└── templates
341 ├── adc_lld.c
342 ├── adc_lld.h
343 ├── can_lld.c
344 ├── can_lld.h
345 ├── dac_lld.c
346 ├── dac_lld.h
347 ├── ext_lld.c
348 ├── ext_lld.h
349 ├── gpt_lld.c
350 ├── gpt_lld.h
351 ├── halconf.h
352 ├── hal_lld.c
353 ├── hal_lld.h
354 ├── i2c_lld.c
355 ├── i2c_lld.h
356 ├── i2s_lld.c
357 ├── i2s_lld.h
358 ├── icu_lld.c
359 ├── icu_lld.h
360 ├── mac_lld.c
361 ├── mac_lld.h
362 ├── mcuconf.h
363 ├── osal
364 │   ├── osal.c
365 │   ├── osal.h
366 │   └── osal.mk
367 ├── pal_lld.c
368 ├── pal_lld.h
369 ├── platform.mk
370 ├── pwm_lld.c
371 ├── pwm_lld.h
372 ├── rtc_lld.c
373 ├── rtc_lld.h
374 ├── sdc_lld.c
375 ├── sdc_lld.h
376 ├── serial_lld.c
377 ├── serial_lld.h
378 ├── spi_lld.c
379 ├── spi_lld.h
380 ├── st_lld.c
381 ├── st_lld.h
382 ├── uart_lld.c
383 ├── uart_lld.h
384 ├── usb_lld.c
385 └── usb_lld.h
diff --git a/keyboards/infinity_chibios/Makefile b/keyboards/infinity_chibios/Makefile
new file mode 100644
index 000000000..649b43e64
--- /dev/null
+++ b/keyboards/infinity_chibios/Makefile
@@ -0,0 +1,70 @@
1# project specific files
2SRC = matrix.c \
3 led.c
4
5## chip/board settings
6# - the next two should match the directories in
7# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
8# - For Teensies, FAMILY = KINETIS and SERIES is either
9# KL2x (LC) or K20x (3.0,3.1,3.2).
10# - For Infinity KB, SERIES = K20x
11MCU_FAMILY = KINETIS
12MCU_SERIES = K20x
13
14# Linker script to use
15# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
16# or <this_dir>/ld/
17# - NOTE: a custom ld script is needed for EEPROM on Teensy LC
18# - LDSCRIPT =
19# - MKL26Z64 for Teensy LC
20# - MK20DX128 for Teensy 3.0
21# - MK20DX256 for Teensy 3.1 and 3.2
22# - MK20DX128BLDR4 for Infinity with Kiibohd bootloader
23MCU_LDSCRIPT = MK20DX128BLDR4
24
25# Startup code to use
26# - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
27# - STARTUP =
28# - kl2x for Teensy LC
29# - k20x5 for Teensy 3.0 and Infinity KB
30# - k20x7 for Teensy 3.1 and 3.2
31MCU_STARTUP = k20x5
32
33# Board: it should exist either in <chibios>/os/hal/boards/
34# or <this_dir>/boards
35# - BOARD =
36# - PJRC_TEENSY_LC for Teensy LC
37# - PJRC_TEENSY_3 for Teensy 3.0
38# - PJRC_TEENSY_3_1 for Teensy 3.1 or 3.2
39# - MCHCK_K20 for Infinity KB
40BOARD = MCHCK_K20
41
42# Cortex version
43# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4
44MCU = cortex-m4
45
46# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
47# I.e. 6 for Teensy LC; 7 for Teensy 3.x
48ARMV = 7
49
50# Vector table for application
51# 0x00000000-0x00001000 area is occupied by bootlaoder.*/
52# The CORTEX_VTOR... is needed only for MCHCK/Infinity KB
53OPT_DEFS = -DCORTEX_VTOR_INIT=0x00001000
54
55# Build Options
56# comment out to disable the options.
57#
58BOOTMAGIC_ENABLE ?= yes # Virtual DIP switch configuration
59## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
60MOUSEKEY_ENABLE ?= yes # Mouse keys
61EXTRAKEY_ENABLE ?= yes # Audio control and System control
62CONSOLE_ENABLE ?= yes # Console for debug
63COMMAND_ENABLE ?= yes # Commands for debug and configuration
64SLEEP_LED_ENABLE ?= yes # Breathing sleep LED during USB suspend
65NKRO_ENABLE ?= yes # USB Nkey Rollover
66CUSTOM_MATRIX ?= yes # Custom matrix file
67
68ifndef QUANTUM_DIR
69 include ../../Makefile
70endif \ No newline at end of file
diff --git a/keyboards/infinity_chibios/bootloader_defs.h b/keyboards/infinity_chibios/bootloader_defs.h
new file mode 100644
index 000000000..c67153be6
--- /dev/null
+++ b/keyboards/infinity_chibios/bootloader_defs.h
@@ -0,0 +1 @@
#define KIIBOHD_BOOTLOADER
diff --git a/keyboards/infinity_chibios/chconf.h b/keyboards/infinity_chibios/chconf.h
new file mode 100644
index 000000000..b886c383b
--- /dev/null
+++ b/keyboards/infinity_chibios/chconf.h
@@ -0,0 +1,524 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/chconf.h
19 * @brief Configuration file template.
20 * @details A copy of this file must be placed in each project directory, it
21 * contains the application specific kernel settings.
22 *
23 * @addtogroup config
24 * @details Kernel related settings and hooks.
25 * @{
26 */
27
28#ifndef CHCONF_H
29#define CHCONF_H
30
31#define _CHIBIOS_RT_CONF_
32
33/*===========================================================================*/
34/**
35 * @name System timers settings
36 * @{
37 */
38/*===========================================================================*/
39
40/**
41 * @brief System time counter resolution.
42 * @note Allowed values are 16 or 32 bits.
43 */
44#define CH_CFG_ST_RESOLUTION 32
45
46/**
47 * @brief System tick frequency.
48 * @details Frequency of the system timer that drives the system ticks. This
49 * setting also defines the system tick time unit.
50 */
51#define CH_CFG_ST_FREQUENCY 1000
52
53/**
54 * @brief Time delta constant for the tick-less mode.
55 * @note If this value is zero then the system uses the classic
56 * periodic tick. This value represents the minimum number
57 * of ticks that is safe to specify in a timeout directive.
58 * The value one is not valid, timeouts are rounded up to
59 * this value.
60 */
61#define CH_CFG_ST_TIMEDELTA 0
62
63/** @} */
64
65/*===========================================================================*/
66/**
67 * @name Kernel parameters and options
68 * @{
69 */
70/*===========================================================================*/
71
72/**
73 * @brief Round robin interval.
74 * @details This constant is the number of system ticks allowed for the
75 * threads before preemption occurs. Setting this value to zero
76 * disables the preemption for threads with equal priority and the
77 * round robin becomes cooperative. Note that higher priority
78 * threads can still preempt, the kernel is always preemptive.
79 * @note Disabling the round robin preemption makes the kernel more compact
80 * and generally faster.
81 * @note The round robin preemption is not supported in tickless mode and
82 * must be set to zero in that case.
83 */
84#define CH_CFG_TIME_QUANTUM 20
85
86/**
87 * @brief Managed RAM size.
88 * @details Size of the RAM area to be managed by the OS. If set to zero
89 * then the whole available RAM is used. The core memory is made
90 * available to the heap allocator and/or can be used directly through
91 * the simplified core memory allocator.
92 *
93 * @note In order to let the OS manage the whole RAM the linker script must
94 * provide the @p __heap_base__ and @p __heap_end__ symbols.
95 * @note Requires @p CH_CFG_USE_MEMCORE.
96 */
97#define CH_CFG_MEMCORE_SIZE 0
98
99/**
100 * @brief Idle thread automatic spawn suppression.
101 * @details When this option is activated the function @p chSysInit()
102 * does not spawn the idle thread. The application @p main()
103 * function becomes the idle thread and must implement an
104 * infinite loop.
105 */
106#define CH_CFG_NO_IDLE_THREAD FALSE
107
108/* Use __WFI in the idle thread for waiting. Does lower the power
109 * consumption. */
110#define CORTEX_ENABLE_WFI_IDLE TRUE
111
112/** @} */
113
114/*===========================================================================*/
115/**
116 * @name Performance options
117 * @{
118 */
119/*===========================================================================*/
120
121/**
122 * @brief OS optimization.
123 * @details If enabled then time efficient rather than space efficient code
124 * is used when two possible implementations exist.
125 *
126 * @note This is not related to the compiler optimization options.
127 * @note The default is @p TRUE.
128 */
129#define CH_CFG_OPTIMIZE_SPEED TRUE
130
131/** @} */
132
133/*===========================================================================*/
134/**
135 * @name Subsystem options
136 * @{
137 */
138/*===========================================================================*/
139
140/**
141 * @brief Time Measurement APIs.
142 * @details If enabled then the time measurement APIs are included in
143 * the kernel.
144 *
145 * @note The default is @p TRUE.
146 */
147#define CH_CFG_USE_TM FALSE
148
149/**
150 * @brief Threads registry APIs.
151 * @details If enabled then the registry APIs are included in the kernel.
152 *
153 * @note The default is @p TRUE.
154 */
155#define CH_CFG_USE_REGISTRY TRUE
156
157/**
158 * @brief Threads synchronization APIs.
159 * @details If enabled then the @p chThdWait() function is included in
160 * the kernel.
161 *
162 * @note The default is @p TRUE.
163 */
164#define CH_CFG_USE_WAITEXIT TRUE
165
166/**
167 * @brief Semaphores APIs.
168 * @details If enabled then the Semaphores APIs are included in the kernel.
169 *
170 * @note The default is @p TRUE.
171 */
172#define CH_CFG_USE_SEMAPHORES TRUE
173
174/**
175 * @brief Semaphores queuing mode.
176 * @details If enabled then the threads are enqueued on semaphores by
177 * priority rather than in FIFO order.
178 *
179 * @note The default is @p FALSE. Enable this if you have special
180 * requirements.
181 * @note Requires @p CH_CFG_USE_SEMAPHORES.
182 */
183#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
184
185/**
186 * @brief Mutexes APIs.
187 * @details If enabled then the mutexes APIs are included in the kernel.
188 *
189 * @note The default is @p TRUE.
190 */
191#define CH_CFG_USE_MUTEXES TRUE
192
193/**
194 * @brief Enables recursive behavior on mutexes.
195 * @note Recursive mutexes are heavier and have an increased
196 * memory footprint.
197 *
198 * @note The default is @p FALSE.
199 * @note Requires @p CH_CFG_USE_MUTEXES.
200 */
201#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
202
203/**
204 * @brief Conditional Variables APIs.
205 * @details If enabled then the conditional variables APIs are included
206 * in the kernel.
207 *
208 * @note The default is @p TRUE.
209 * @note Requires @p CH_CFG_USE_MUTEXES.
210 */
211#define CH_CFG_USE_CONDVARS TRUE
212
213/**
214 * @brief Conditional Variables APIs with timeout.
215 * @details If enabled then the conditional variables APIs with timeout
216 * specification are included in the kernel.
217 *
218 * @note The default is @p TRUE.
219 * @note Requires @p CH_CFG_USE_CONDVARS.
220 */
221#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
222
223/**
224 * @brief Events Flags APIs.
225 * @details If enabled then the event flags APIs are included in the kernel.
226 *
227 * @note The default is @p TRUE.
228 */
229#define CH_CFG_USE_EVENTS TRUE
230
231/**
232 * @brief Events Flags APIs with timeout.
233 * @details If enabled then the events APIs with timeout specification
234 * are included in the kernel.
235 *
236 * @note The default is @p TRUE.
237 * @note Requires @p CH_CFG_USE_EVENTS.
238 */
239#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
240
241/**
242 * @brief Synchronous Messages APIs.
243 * @details If enabled then the synchronous messages APIs are included
244 * in the kernel.
245 *
246 * @note The default is @p TRUE.
247 */
248#define CH_CFG_USE_MESSAGES TRUE
249
250/**
251 * @brief Synchronous Messages queuing mode.
252 * @details If enabled then messages are served by priority rather than in
253 * FIFO order.
254 *
255 * @note The default is @p FALSE. Enable this if you have special
256 * requirements.
257 * @note Requires @p CH_CFG_USE_MESSAGES.
258 */
259#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
260
261/**
262 * @brief Mailboxes APIs.
263 * @details If enabled then the asynchronous messages (mailboxes) APIs are
264 * included in the kernel.
265 *
266 * @note The default is @p TRUE.
267 * @note Requires @p CH_CFG_USE_SEMAPHORES.
268 */
269#define CH_CFG_USE_MAILBOXES TRUE
270
271/**
272 * @brief Core Memory Manager APIs.
273 * @details If enabled then the core memory manager APIs are included
274 * in the kernel.
275 *
276 * @note The default is @p TRUE.
277 */
278#define CH_CFG_USE_MEMCORE TRUE
279
280/**
281 * @brief Heap Allocator APIs.
282 * @details If enabled then the memory heap allocator APIs are included
283 * in the kernel.
284 *
285 * @note The default is @p TRUE.
286 * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
287 * @p CH_CFG_USE_SEMAPHORES.
288 * @note Mutexes are recommended.
289 */
290#define CH_CFG_USE_HEAP TRUE
291
292/**
293 * @brief Memory Pools Allocator APIs.
294 * @details If enabled then the memory pools allocator APIs are included
295 * in the kernel.
296 *
297 * @note The default is @p TRUE.
298 */
299#define CH_CFG_USE_MEMPOOLS TRUE
300
301/**
302 * @brief Dynamic Threads APIs.
303 * @details If enabled then the dynamic threads creation APIs are included
304 * in the kernel.
305 *
306 * @note The default is @p TRUE.
307 * @note Requires @p CH_CFG_USE_WAITEXIT.
308 * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
309 */
310#define CH_CFG_USE_DYNAMIC TRUE
311
312/** @} */
313
314/*===========================================================================*/
315/**
316 * @name Debug options
317 * @{
318 */
319/*===========================================================================*/
320
321/**
322 * @brief Debug option, kernel statistics.
323 *
324 * @note The default is @p FALSE.
325 */
326#define CH_DBG_STATISTICS FALSE
327
328/**
329 * @brief Debug option, system state check.
330 * @details If enabled the correct call protocol for system APIs is checked
331 * at runtime.
332 *
333 * @note The default is @p FALSE.
334 */
335#define CH_DBG_SYSTEM_STATE_CHECK FALSE
336
337/**
338 * @brief Debug option, parameters checks.
339 * @details If enabled then the checks on the API functions input
340 * parameters are activated.
341 *
342 * @note The default is @p FALSE.
343 */
344#define CH_DBG_ENABLE_CHECKS FALSE
345
346/**
347 * @brief Debug option, consistency checks.
348 * @details If enabled then all the assertions in the kernel code are
349 * activated. This includes consistency checks inside the kernel,
350 * runtime anomalies and port-defined checks.
351 *
352 * @note The default is @p FALSE.
353 */
354#define CH_DBG_ENABLE_ASSERTS FALSE
355
356/**
357 * @brief Debug option, trace buffer.
358 * @details If enabled then the trace buffer is activated.
359 *
360 * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
361 */
362#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
363
364/**
365 * @brief Trace buffer entries.
366 * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
367 * different from @p CH_DBG_TRACE_MASK_DISABLED.
368 */
369#define CH_DBG_TRACE_BUFFER_SIZE 128
370
371/**
372 * @brief Debug option, stack checks.
373 * @details If enabled then a runtime stack check is performed.
374 *
375 * @note The default is @p FALSE.
376 * @note The stack check is performed in a architecture/port dependent way.
377 * It may not be implemented or some ports.
378 * @note The default failure mode is to halt the system with the global
379 * @p panic_msg variable set to @p NULL.
380 */
381#define CH_DBG_ENABLE_STACK_CHECK FALSE
382
383/**
384 * @brief Debug option, stacks initialization.
385 * @details If enabled then the threads working area is filled with a byte
386 * value when a thread is created. This can be useful for the
387 * runtime measurement of the used stack.
388 *
389 * @note The default is @p FALSE.
390 */
391#define CH_DBG_FILL_THREADS FALSE
392
393/**
394 * @brief Debug option, threads profiling.
395 * @details If enabled then a field is added to the @p thread_t structure that
396 * counts the system ticks occurred while executing the thread.
397 *
398 * @note The default is @p FALSE.
399 * @note This debug option is not currently compatible with the
400 * tickless mode.
401 */
402#define CH_DBG_THREADS_PROFILING FALSE
403
404/** @} */
405
406/*===========================================================================*/
407/**
408 * @name Kernel hooks
409 * @{
410 */
411/*===========================================================================*/
412
413/**
414 * @brief Threads descriptor structure extension.
415 * @details User fields added to the end of the @p thread_t structure.
416 */
417#define CH_CFG_THREAD_EXTRA_FIELDS \
418 /* Add threads custom fields here.*/
419
420/**
421 * @brief Threads initialization hook.
422 * @details User initialization code added to the @p chThdInit() API.
423 *
424 * @note It is invoked from within @p chThdInit() and implicitly from all
425 * the threads creation APIs.
426 */
427#define CH_CFG_THREAD_INIT_HOOK(tp) { \
428 /* Add threads initialization code here.*/ \
429}
430
431/**
432 * @brief Threads finalization hook.
433 * @details User finalization code added to the @p chThdExit() API.
434 */
435#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
436 /* Add threads finalization code here.*/ \
437}
438
439/**
440 * @brief Context switch hook.
441 * @details This hook is invoked just before switching between threads.
442 */
443#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
444 /* Context switch code here.*/ \
445}
446
447/**
448 * @brief ISR enter hook.
449 */
450#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
451 /* IRQ prologue code here.*/ \
452}
453
454/**
455 * @brief ISR exit hook.
456 */
457#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
458 /* IRQ epilogue code here.*/ \
459}
460
461/**
462 * @brief Idle thread enter hook.
463 * @note This hook is invoked within a critical zone, no OS functions
464 * should be invoked from here.
465 * @note This macro can be used to activate a power saving mode.
466 */
467#define CH_CFG_IDLE_ENTER_HOOK() { \
468 /* Idle-enter code here.*/ \
469}
470
471/**
472 * @brief Idle thread leave hook.
473 * @note This hook is invoked within a critical zone, no OS functions
474 * should be invoked from here.
475 * @note This macro can be used to deactivate a power saving mode.
476 */
477#define CH_CFG_IDLE_LEAVE_HOOK() { \
478 /* Idle-leave code here.*/ \
479}
480
481/**
482 * @brief Idle Loop hook.
483 * @details This hook is continuously invoked by the idle thread loop.
484 */
485#define CH_CFG_IDLE_LOOP_HOOK() { \
486 /* Idle loop code here.*/ \
487}
488
489/**
490 * @brief System tick event hook.
491 * @details This hook is invoked in the system tick handler immediately
492 * after processing the virtual timers queue.
493 */
494#define CH_CFG_SYSTEM_TICK_HOOK() { \
495 /* System tick event code here.*/ \
496}
497
498/**
499 * @brief System halt hook.
500 * @details This hook is invoked in case to a system halting error before
501 * the system is halted.
502 */
503#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
504 /* System halt code here.*/ \
505}
506
507/**
508 * @brief Trace hook.
509 * @details This hook is invoked each time a new record is written in the
510 * trace buffer.
511 */
512#define CH_CFG_TRACE_HOOK(tep) { \
513 /* Trace code here.*/ \
514}
515
516/** @} */
517
518/*===========================================================================*/
519/* Port-specific settings (override port settings defaulted in chcore.h). */
520/*===========================================================================*/
521
522#endif /* CHCONF_H */
523
524/** @} */
diff --git a/keyboards/infinity_chibios/config.h b/keyboards/infinity_chibios/config.h
new file mode 100644
index 000000000..cb9022205
--- /dev/null
+++ b/keyboards/infinity_chibios/config.h
@@ -0,0 +1,75 @@
1/*
2Copyright 2015 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21
22/* USB Device descriptor parameter */
23#define VENDOR_ID 0xFEED
24#define PRODUCT_ID 0x6464
25#define DEVICE_VER 0x0001
26/* in python2: list(u"whatever".encode('utf-16-le')) */
27/* at most 32 characters or the ugly hack in usb_main.c borks */
28#define MANUFACTURER "TMK"
29#define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', '\xc6', '\x00'
30#define PRODUCT "Infinity keyboard/TMK"
31#define USBSTR_PRODUCT 'I', '\x00', 'n', '\x00', 'f', '\x00', 'i', '\x00', 'n', '\x00', 'i', '\x00', 't', '\x00', 'y', '\x00', ' ', '\x00', 'k', '\x00', 'e', '\x00', 'y', '\x00', 'b', '\x00', 'o', '\x00', 'a', '\x00', 'r', '\x00', 'd', '\x00', '/', '\x00', 'T', '\x00', 'M', '\x00', 'K', '\x00'
32
33/* key matrix size */
34#define MATRIX_ROWS 9
35#define MATRIX_COLS 7
36
37/* define if matrix has ghost */
38//#define MATRIX_HAS_GHOST
39
40/* Set 0 if debouncing isn't needed */
41#define DEBOUNCE 5
42
43/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
44//#define LOCKING_SUPPORT_ENABLE
45/* Locking resynchronize hack */
46//#define LOCKING_RESYNC_ENABLE
47
48/* key combination for command */
49#define IS_COMMAND() ( \
50 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
51)
52
53/* Keymap for Infiity prototype */
54#define INFINITY_PROTOTYPE
55
56
57/*
58 * Feature disable options
59 * These options are also useful to firmware size reduction.
60 */
61
62/* disable debug print */
63//#define NO_DEBUG
64
65/* disable print */
66//#define NO_PRINT
67
68/* disable action features */
69//#define NO_ACTION_LAYER
70//#define NO_ACTION_TAPPING
71//#define NO_ACTION_ONESHOT
72//#define NO_ACTION_MACRO
73//#define NO_ACTION_FUNCTION
74
75#endif
diff --git a/keyboards/infinity_chibios/halconf.h b/keyboards/infinity_chibios/halconf.h
new file mode 100644
index 000000000..53538de14
--- /dev/null
+++ b/keyboards/infinity_chibios/halconf.h
@@ -0,0 +1,353 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/halconf.h
19 * @brief HAL configuration header.
20 * @details HAL configuration file, this file allows to enable or disable the
21 * various device drivers from your application. You may also use
22 * this file in order to override the device drivers default settings.
23 *
24 * @addtogroup HAL_CONF
25 * @{
26 */
27
28#ifndef _HALCONF_H_
29#define _HALCONF_H_
30
31#include "mcuconf.h"
32
33/**
34 * @brief Enables the PAL subsystem.
35 */
36#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
37#define HAL_USE_PAL TRUE
38#endif
39
40/**
41 * @brief Enables the ADC subsystem.
42 */
43#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
44#define HAL_USE_ADC FALSE
45#endif
46
47/**
48 * @brief Enables the CAN subsystem.
49 */
50#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
51#define HAL_USE_CAN FALSE
52#endif
53
54/**
55 * @brief Enables the DAC subsystem.
56 */
57#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
58#define HAL_USE_DAC FALSE
59#endif
60
61/**
62 * @brief Enables the EXT subsystem.
63 */
64#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
65#define HAL_USE_EXT FALSE
66#endif
67
68/**
69 * @brief Enables the GPT subsystem.
70 */
71#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
72#define HAL_USE_GPT FALSE
73#endif
74
75/**
76 * @brief Enables the I2C subsystem.
77 */
78#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
79#define HAL_USE_I2C FALSE
80#endif
81
82/**
83 * @brief Enables the I2S subsystem.
84 */
85#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
86#define HAL_USE_I2S FALSE
87#endif
88
89/**
90 * @brief Enables the ICU subsystem.
91 */
92#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
93#define HAL_USE_ICU FALSE
94#endif
95
96/**
97 * @brief Enables the MAC subsystem.
98 */
99#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
100#define HAL_USE_MAC FALSE
101#endif
102
103/**
104 * @brief Enables the MMC_SPI subsystem.
105 */
106#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
107#define HAL_USE_MMC_SPI FALSE
108#endif
109
110/**
111 * @brief Enables the PWM subsystem.
112 */
113#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
114#define HAL_USE_PWM FALSE
115#endif
116
117/**
118 * @brief Enables the RTC subsystem.
119 */
120#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
121#define HAL_USE_RTC FALSE
122#endif
123
124/**
125 * @brief Enables the SDC subsystem.
126 */
127#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
128#define HAL_USE_SDC FALSE
129#endif
130
131/**
132 * @brief Enables the SERIAL subsystem.
133 */
134#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
135#define HAL_USE_SERIAL FALSE
136#endif
137
138/**
139 * @brief Enables the SERIAL over USB subsystem.
140 */
141#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
142#define HAL_USE_SERIAL_USB TRUE
143#endif
144
145/**
146 * @brief Enables the SPI subsystem.
147 */
148#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
149#define HAL_USE_SPI FALSE
150#endif
151
152/**
153 * @brief Enables the UART subsystem.
154 */
155#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
156#define HAL_USE_UART FALSE
157#endif
158
159/**
160 * @brief Enables the USB subsystem.
161 */
162#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
163#define HAL_USE_USB TRUE
164#endif
165
166/**
167 * @brief Enables the WDG subsystem.
168 */
169#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)
170#define HAL_USE_WDG FALSE
171#endif
172
173/*===========================================================================*/
174/* ADC driver related settings. */
175/*===========================================================================*/
176
177/**
178 * @brief Enables synchronous APIs.
179 * @note Disabling this option saves both code and data space.
180 */
181#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
182#define ADC_USE_WAIT TRUE
183#endif
184
185/**
186 * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
187 * @note Disabling this option saves both code and data space.
188 */
189#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
190#define ADC_USE_MUTUAL_EXCLUSION TRUE
191#endif
192
193/*===========================================================================*/
194/* CAN driver related settings. */
195/*===========================================================================*/
196
197/**
198 * @brief Sleep mode related APIs inclusion switch.
199 */
200#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
201#define CAN_USE_SLEEP_MODE TRUE
202#endif
203
204/*===========================================================================*/
205/* I2C driver related settings. */
206/*===========================================================================*/
207
208/**
209 * @brief Enables the mutual exclusion APIs on the I2C bus.
210 */
211#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
212#define I2C_USE_MUTUAL_EXCLUSION TRUE
213#endif
214
215/*===========================================================================*/
216/* MAC driver related settings. */
217/*===========================================================================*/
218
219/**
220 * @brief Enables an event sources for incoming packets.
221 */
222#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
223#define MAC_USE_ZERO_COPY FALSE
224#endif
225
226/**
227 * @brief Enables an event sources for incoming packets.
228 */
229#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
230#define MAC_USE_EVENTS TRUE
231#endif
232
233/*===========================================================================*/
234/* MMC_SPI driver related settings. */
235/*===========================================================================*/
236
237/**
238 * @brief Delays insertions.
239 * @details If enabled this options inserts delays into the MMC waiting
240 * routines releasing some extra CPU time for the threads with
241 * lower priority, this may slow down the driver a bit however.
242 * This option is recommended also if the SPI driver does not
243 * use a DMA channel and heavily loads the CPU.
244 */
245#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
246#define MMC_NICE_WAITING TRUE
247#endif
248
249/*===========================================================================*/
250/* SDC driver related settings. */
251/*===========================================================================*/
252
253/**
254 * @brief Number of initialization attempts before rejecting the card.
255 * @note Attempts are performed at 10mS intervals.
256 */
257#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
258#define SDC_INIT_RETRY 100
259#endif
260
261/**
262 * @brief Include support for MMC cards.
263 * @note MMC support is not yet implemented so this option must be kept
264 * at @p FALSE.
265 */
266#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
267#define SDC_MMC_SUPPORT FALSE
268#endif
269
270/**
271 * @brief Delays insertions.
272 * @details If enabled this options inserts delays into the MMC waiting
273 * routines releasing some extra CPU time for the threads with
274 * lower priority, this may slow down the driver a bit however.
275 */
276#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
277#define SDC_NICE_WAITING TRUE
278#endif
279
280/*===========================================================================*/
281/* SERIAL driver related settings. */
282/*===========================================================================*/
283
284/**
285 * @brief Default bit rate.
286 * @details Configuration parameter, this is the baud rate selected for the
287 * default configuration.
288 */
289#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
290#define SERIAL_DEFAULT_BITRATE 38400
291#endif
292
293/**
294 * @brief Serial buffers size.
295 * @details Configuration parameter, you can change the depth of the queue
296 * buffers depending on the requirements of your application.
297 * @note The default is 64 bytes for both the transmission and receive
298 * buffers.
299 */
300#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
301#define SERIAL_BUFFERS_SIZE 16
302#endif
303
304/*===========================================================================*/
305/* SERIAL_USB driver related setting. */
306/*===========================================================================*/
307
308/**
309 * @brief Serial over USB buffers size.
310 * @details Configuration parameter, the buffer size must be a multiple of
311 * the USB data endpoint maximum packet size.
312 * @note The default is 64 bytes for both the transmission and receive
313 * buffers.
314 */
315#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
316#define SERIAL_USB_BUFFERS_SIZE 256
317#endif
318
319/*===========================================================================*/
320/* SPI driver related settings. */
321/*===========================================================================*/
322
323/**
324 * @brief Enables synchronous APIs.
325 * @note Disabling this option saves both code and data space.
326 */
327#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
328#define SPI_USE_WAIT TRUE
329#endif
330
331/**
332 * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
333 * @note Disabling this option saves both code and data space.
334 */
335#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
336#define SPI_USE_MUTUAL_EXCLUSION TRUE
337#endif
338
339/*===========================================================================*/
340/* USB driver related settings. */
341/*===========================================================================*/
342
343/**
344 * @brief Enables synchronous APIs.
345 * @note Disabling this option saves both code and data space.
346 */
347#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
348#define USB_USE_WAIT TRUE
349#endif
350
351#endif /* _HALCONF_H_ */
352
353/** @} */
diff --git a/keyboards/infinity_chibios/infinity_chibios.c b/keyboards/infinity_chibios/infinity_chibios.c
new file mode 100644
index 000000000..845eda01b
--- /dev/null
+++ b/keyboards/infinity_chibios/infinity_chibios.c
@@ -0,0 +1,17 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "infinity_chibios.h"
diff --git a/keyboards/infinity_chibios/infinity_chibios.h b/keyboards/infinity_chibios/infinity_chibios.h
new file mode 100644
index 000000000..a44c68b82
--- /dev/null
+++ b/keyboards/infinity_chibios/infinity_chibios.h
@@ -0,0 +1,66 @@
1/*
2Copyright 2014 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef KEYMAP_COMMON_H
18#define KEYMAP_COMMON_H
19
20#include "quantum.h"
21
22#ifdef INFINITY_PROTOTYPE
23
24/* Infinity prototype */
25#define KEYMAP( \
26 K00, K10, K20, K30, K40, K50, K60, K70, K80, K01, K11, K21, K31, K41, K86, \
27 K51, K61, K71, K81, K02, K12, K22, K32, K42, K52, K62, K72, K82, K03, \
28 K13, K23, K33, K43, K53, K63, K73, K83, K04, K14, K24, K34, K44, \
29 K54, K64, K74, K84, K05, K15, K25, K35, K45, K55, K65, K75, K85, \
30 K06, K16, K26, K36, K46, K56, K66, K76 \
31) { \
32 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06 }, \
33 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16 }, \
34 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26 }, \
35 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36 }, \
36 { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46 }, \
37 { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56 }, \
38 { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66 }, \
39 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76 }, \
40 { KC_##K80, KC_##K81, KC_##K82, KC_##K83, KC_##K84, KC_##K85, KC_##K86 } \
41}
42
43#else
44
45/* Infinity production */
46#define KEYMAP( \
47 K00, K10, K20, K30, K40, K50, K60, K70, K80, K01, K11, K21, K31, K41, K51, \
48 K61, K71, K81, K02, K12, K22, K32, K42, K52, K62, K72, K82, K03, K13, \
49 K23, K33, K43, K53, K63, K73, K83, K04, K14, K24, K34, K44, K54, \
50 K64, K74, K84, K05, K15, K25, K35, K45, K55, K65, K75, K85, K06, \
51 K16, K26, K36, K46, K56, K66, K76, K86 \
52) { \
53 { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06 }, \
54 { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16 }, \
55 { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26 }, \
56 { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36 }, \
57 { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46 }, \
58 { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56 }, \
59 { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66 }, \
60 { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76 }, \
61 { KC_##K80, KC_##K81, KC_##K82, KC_##K83, KC_##K84, KC_##K85, KC_##K86 } \
62}
63
64#endif
65
66#endif
diff --git a/keyboards/infinity_chibios/keymaps/default/keymap.c b/keyboards/infinity_chibios/keymaps/default/keymap.c
new file mode 100644
index 000000000..2acf72849
--- /dev/null
+++ b/keyboards/infinity_chibios/keymaps/default/keymap.c
@@ -0,0 +1,48 @@
1#include "infinity_chibios.h"
2
3const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4 /* Layer 0: Default Layer
5 * ,-----------------------------------------------------------.
6 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| `|BSp|
7 * |-----------------------------------------------------------|
8 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
9 * |-----------------------------------------------------------|
10 * |Contro| A| S| D| F| G| H| J| K| L| ;| '|Enter |
11 * |-----------------------------------------------------------|
12 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn0|
13 * |-----------------------------------------------------------'
14 * | |Gui|Alt | Space |Alt |Gui| | |
15 * `-----------------------------------------------------------'
16 */
17 [0] =
18 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS, GRV, \
19 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
20 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT,ENT, \
21 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RSFT,FN0, \
22 NO, LGUI,LALT, SPC, RALT,RGUI,NO, NO),
23
24 /* Layer 1: HHKB mode (HHKB Fn)
25 * ,-----------------------------------------------------------.
26 * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
27 * |-----------------------------------------------------------|
28 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
29 * |-----------------------------------------------------------|
30 * | |VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
31 * |-----------------------------------------------------------|
32 * | | | | | | | +| -|End|PgD|Dow| | |
33 * `-----------------------------------------------------------'
34 * | |Gui|Alt | Space |Alt |Gui| | |
35 * `-----------------------------------------------------------'
36 */
37 [1] =
38 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
39 CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS, UP, TRNS, BSPC, \
40 TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,PENT, \
41 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN,TRNS,TRNS, \
42 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
43};
44
45const uint16_t fn_actions[] = {
46 [0] = ACTION_LAYER_MOMENTARY(1),
47};
48
diff --git a/keyboards/infinity_chibios/keymaps/hasu/keymap.c b/keyboards/infinity_chibios/keymaps/hasu/keymap.c
new file mode 100644
index 000000000..e9a212f0e
--- /dev/null
+++ b/keyboards/infinity_chibios/keymaps/hasu/keymap.c
@@ -0,0 +1,199 @@
1#include "infinity_chibios.h"
2
3const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
4 /* Layer 0: Default Layer
5 * ,-----------------------------------------------------------.
6 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| `|BSp|
7 * |-----------------------------------------------------------|
8 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
9 * |-----------------------------------------------------------|
10 * |Contro| A| S| D| F| G| H| J| K| L| ;| '|Enter |
11 * |-----------------------------------------------------------|
12 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn0|
13 * |-----------------------------------------------------------'
14 * | |Gui|Alt | Space |Alt |Gui| | |
15 * `-----------------------------------------------------------'
16 */
17 [0] =
18 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
19 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
20 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN6, \
21 FN7, Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
22 NO, LGUI,LALT, FN4, FN5, RGUI,NO, NO),
23
24 /* Layer 1: HHKB mode (HHKB Fn)
25 * ,-----------------------------------------------------------.
26 * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
27 * |-----------------------------------------------------------|
28 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
29 * |-----------------------------------------------------------|
30 * | |VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
31 * |-----------------------------------------------------------|
32 * | | | | | | | +| -|End|PgD|Dow| | |
33 * `-----------------------------------------------------------'
34 * | |Gui|Alt | Space |Alt |Gui| | |
35 * `-----------------------------------------------------------'
36 */
37 [1] =
38 KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
39 CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS, UP, TRNS,BSPC, \
40 LCTL,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
41 LSFT,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN,RSFT,TRNS, \
42 TRNS,LGUI,LALT, TRNS, RALT,RGUI,TRNS,TRNS),
43
44 /* Layer 2: Vi mode[Slash]
45 * ,-----------------------------------------------------------.
46 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
47 * |-----------------------------------------------------------|
48 * |Tab |Hom|PgD|Up |PgU|End|Hom|PgD|PgUlEnd| | | |Backs|
49 * |-----------------------------------------------------------|
50 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| | |Return |
51 * |-----------------------------------------------------------|
52 * |Shift | | | | | |Hom|PgD|PgUlEnd|Fn0|Shift | |
53 * `-----------------------------------------------------------'
54 * |Gui|Alt | Space |Alt |Gui|
55 * `-------------------------------------------'
56 */
57 [2] = \
58 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
59 TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC, \
60 LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, \
61 LSFT,NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, FN2, RSFT,TRNS, \
62 TRNS,LGUI,LALT, SPC, RALT,RGUI,TRNS,TRNS),
63
64 /* Layer 3: Mouse mode(IJKL)[Semicolon]
65 * ,-----------------------------------------------------------.
66 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
67 * |-----------------------------------------------------------|
68 * |Tab | | | | | |MwL|MwD|McU|MwU|MwR|Wbk|Wfr|Alt-T|
69 * |-----------------------------------------------------------|
70 * |Contro| | | | | |Mb2|McL|McD|McR|Fn | |Return |
71 * |-----------------------------------------------------------|
72 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
73 * `-----------------------------------------------------------'
74 * |Gui |Alt | Mb1 |Fn |Fn |
75 * `--------------------------------------------'
76 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
77 */
78 [3] = \
79 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
80 FN8, NO, NO, NO, NO, NO, WH_L,WH_D,MS_U,WH_U,WH_R,FN9, FN10,FN8, \
81 LCTL,ACL0,ACL1,ACL2,ACL2,NO, NO, MS_L,MS_D,MS_R,FN3, NO, ENT, \
82 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,FN9, FN10,NO, RSFT,TRNS, \
83 TRNS,LGUI,LALT, BTN1, TRNS,TRNS,TRNS,TRNS),
84
85 /* Layer 4: Mouse mode(IJKL)[Space]
86 * ,-----------------------------------------------------------.
87 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
88 * |-----------------------------------------------------------|
89 * |Tab | | | | | |MwL|MwD|McU|MwU|MwR|Wbk|Wfr|Alt-T|
90 * |-----------------------------------------------------------|
91 * |Contro| | | | | |Mb2|McL|McD|McR|Mb1| |Return |
92 * |-----------------------------------------------------------|
93 * |Shift | | | | |Mb3|Mb2|Mb1|Mb4|Mb5| |Shift | |
94 * `-----------------------------------------------------------'
95 * |Gui |Alt | Mb1 |Fn |Fn |
96 * `--------------------------------------------'
97 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
98 */
99 [4] = \
100 KEYMAP(GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
101 FN8, NO, NO, NO, NO, NO, WH_L,WH_D,MS_U,WH_U,WH_R,BTN4,BTN5,FN8, \
102 LCTL,VOLD,VOLU,MUTE,NO, NO, NO, MS_L,MS_D,MS_R,BTN1,NO, ENT, \
103 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,FN9, FN10,NO, RSFT,TRNS, \
104 TRNS,LGUI,LALT, TRNS, TRNS,TRNS,TRNS,TRNS),
105
106};
107
108/* id for user defined functions */
109enum function_id {
110 LSHIFT_LPAREN,
111};
112
113enum macro_id {
114 HELLO,
115 VOLUP,
116 ALT_TAB,
117};
118
119/*
120 * Fn action definition
121 */
122const uint16_t fn_actions[] = {
123 [0] = ACTION_DEFAULT_LAYER_SET(0), // Default layer(not used)
124 [1] = ACTION_LAYER_TAP_TOGGLE(1), // HHKB layer(toggle with 5 taps)
125 [2] = ACTION_LAYER_TAP_KEY(2, KC_SLASH), // Cursor layer with Slash*
126 [3] = ACTION_LAYER_TAP_KEY(3, KC_SCLN), // Mousekey layer with Semicolon*
127 [4] = ACTION_LAYER_TAP_KEY(4, KC_SPC), // Mousekey layer with Space
128 [5] = ACTION_LAYER_MOMENTARY(4), // Mousekey layer(IJKL)
129 [6] = ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT), // RControl with tap Enter
130 [7] = ACTION_MODS_ONESHOT(MOD_LSFT), // Oneshot Shift
131 [8] = ACTION_MACRO(ALT_TAB), // Application switching
132 [9] = ACTION_MODS_KEY(MOD_LALT, KC_LEFT),
133 [10] = ACTION_MODS_KEY(MOD_LALT, KC_RIGHT),
134};
135
136/*
137 * Macro definition
138 */
139const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
140{
141 switch (id) {
142 case HELLO:
143 return (record->event.pressed ?
144 MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
145 MACRO_NONE );
146 case VOLUP:
147 return (record->event.pressed ?
148 MACRO( D(VOLU), U(VOLU), END ) :
149 MACRO_NONE );
150 case ALT_TAB:
151 return (record->event.pressed ?
152 MACRO( D(LALT), D(TAB), END ) :
153 MACRO( U(TAB), END ));
154 }
155 return MACRO_NONE;
156}
157
158
159
160/*
161 * user defined action function
162 */
163void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
164{
165 if (record->event.pressed) dprint("P"); else dprint("R");
166 dprintf("%d", record->tap.count);
167 if (record->tap.interrupted) dprint("i");
168 dprint("\n");
169
170 switch (id) {
171 case LSHIFT_LPAREN:
172 // Shift parentheses example: LShft + tap '('
173 // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses
174 // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899
175 if (record->event.pressed) {
176 if (record->tap.count > 0 && !record->tap.interrupted) {
177 if (record->tap.interrupted) {
178 dprint("tap interrupted\n");
179 register_mods(MOD_BIT(KC_LSHIFT));
180 }
181 } else {
182 register_mods(MOD_BIT(KC_LSHIFT));
183 }
184 } else {
185 if (record->tap.count > 0 && !(record->tap.interrupted)) {
186 add_weak_mods(MOD_BIT(KC_LSHIFT));
187 send_keyboard_report();
188 register_code(KC_9);
189 unregister_code(KC_9);
190 del_weak_mods(MOD_BIT(KC_LSHIFT));
191 send_keyboard_report();
192 record->tap.count = 0; // ad hoc: cancel tap
193 } else {
194 unregister_mods(MOD_BIT(KC_LSHIFT));
195 }
196 }
197 break;
198 }
199}
diff --git a/keyboards/infinity_chibios/led.c b/keyboards/infinity_chibios/led.c
new file mode 100644
index 000000000..aed66c7c0
--- /dev/null
+++ b/keyboards/infinity_chibios/led.c
@@ -0,0 +1,24 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "hal.h"
19
20#include "led.h"
21
22
23void led_set(uint8_t usb_led) {
24}
diff --git a/keyboards/infinity_chibios/matrix.c b/keyboards/infinity_chibios/matrix.c
new file mode 100644
index 000000000..2c68ea83a
--- /dev/null
+++ b/keyboards/infinity_chibios/matrix.c
@@ -0,0 +1,128 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include <string.h>
4#include "hal.h"
5#include "timer.h"
6#include "wait.h"
7#include "print.h"
8#include "matrix.h"
9
10
11/*
12 * Infinity Pinusage:
13 * Column pins are input with internal pull-down. Row pins are output and strobe with high.
14 * Key is high or 1 when it turns on.
15 *
16 * col: { PTD1, PTD2, PTD3, PTD4, PTD5, PTD6, PTD7 }
17 * row: { PTB0, PTB1, PTB2, PTB3, PTB16, PTB17, PTC4, PTC5, PTD0 }
18 */
19/* matrix state(1:on, 0:off) */
20static matrix_row_t matrix[MATRIX_ROWS];
21static matrix_row_t matrix_debouncing[MATRIX_ROWS];
22static bool debouncing = false;
23static uint16_t debouncing_time = 0;
24
25
26void matrix_init(void)
27{
28 /* Column(sense) */
29 palSetPadMode(GPIOD, 1, PAL_MODE_INPUT_PULLDOWN);
30 palSetPadMode(GPIOD, 2, PAL_MODE_INPUT_PULLDOWN);
31 palSetPadMode(GPIOD, 3, PAL_MODE_INPUT_PULLDOWN);
32 palSetPadMode(GPIOD, 4, PAL_MODE_INPUT_PULLDOWN);
33 palSetPadMode(GPIOD, 5, PAL_MODE_INPUT_PULLDOWN);
34 palSetPadMode(GPIOD, 6, PAL_MODE_INPUT_PULLDOWN);
35 palSetPadMode(GPIOD, 7, PAL_MODE_INPUT_PULLDOWN);
36
37 /* Row(strobe) */
38 palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL);
39 palSetPadMode(GPIOB, 1, PAL_MODE_OUTPUT_PUSHPULL);
40 palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL);
41 palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL);
42 palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL);
43 palSetPadMode(GPIOB, 17, PAL_MODE_OUTPUT_PUSHPULL);
44 palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL);
45 palSetPadMode(GPIOC, 5, PAL_MODE_OUTPUT_PUSHPULL);
46 palSetPadMode(GPIOD, 0, PAL_MODE_OUTPUT_PUSHPULL);
47
48 memset(matrix, 0, MATRIX_ROWS);
49 memset(matrix_debouncing, 0, MATRIX_ROWS);
50}
51
52uint8_t matrix_scan(void)
53{
54 for (int row = 0; row < MATRIX_ROWS; row++) {
55 matrix_row_t data = 0;
56
57 // strobe row
58 switch (row) {
59 case 0: palSetPad(GPIOB, 0); break;
60 case 1: palSetPad(GPIOB, 1); break;
61 case 2: palSetPad(GPIOB, 2); break;
62 case 3: palSetPad(GPIOB, 3); break;
63 case 4: palSetPad(GPIOB, 16); break;
64 case 5: palSetPad(GPIOB, 17); break;
65 case 6: palSetPad(GPIOC, 4); break;
66 case 7: palSetPad(GPIOC, 5); break;
67 case 8: palSetPad(GPIOD, 0); break;
68 }
69
70 wait_us(1); // need wait to settle pin state
71
72 // read col data
73 data = (palReadPort(GPIOD)>>1);
74
75 // un-strobe row
76 switch (row) {
77 case 0: palClearPad(GPIOB, 0); break;
78 case 1: palClearPad(GPIOB, 1); break;
79 case 2: palClearPad(GPIOB, 2); break;
80 case 3: palClearPad(GPIOB, 3); break;
81 case 4: palClearPad(GPIOB, 16); break;
82 case 5: palClearPad(GPIOB, 17); break;
83 case 6: palClearPad(GPIOC, 4); break;
84 case 7: palClearPad(GPIOC, 5); break;
85 case 8: palClearPad(GPIOD, 0); break;
86 }
87
88 if (matrix_debouncing[row] != data) {
89 matrix_debouncing[row] = data;
90 debouncing = true;
91 debouncing_time = timer_read();
92 }
93 }
94
95 if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
96 for (int row = 0; row < MATRIX_ROWS; row++) {
97 matrix[row] = matrix_debouncing[row];
98 }
99 debouncing = false;
100 }
101 return 1;
102}
103
104bool matrix_is_on(uint8_t row, uint8_t col)
105{
106 return (matrix[row] & (1<<col));
107}
108
109matrix_row_t matrix_get_row(uint8_t row)
110{
111 return matrix[row];
112}
113
114void matrix_print(void)
115{
116 xprintf("\nr/c 01234567\n");
117 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
118 xprintf("%02X: ");
119 matrix_row_t data = matrix_get_row(row);
120 for (int col = 0; col < MATRIX_COLS; col++) {
121 if (data & (1<<col))
122 xprintf("1");
123 else
124 xprintf("0");
125 }
126 xprintf("\n");
127 }
128}
diff --git a/keyboards/infinity_chibios/mcuconf.h b/keyboards/infinity_chibios/mcuconf.h
new file mode 100644
index 000000000..66b6ce25d
--- /dev/null
+++ b/keyboards/infinity_chibios/mcuconf.h
@@ -0,0 +1,55 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef _MCUCONF_H_
18#define _MCUCONF_H_
19
20#define K20x_MCUCONF
21
22/*
23 * HAL driver system settings.
24 */
25
26/* Select the MCU clocking mode below by enabling the appropriate block. */
27
28#define KINETIS_NO_INIT FALSE
29
30/* FEI mode - 48 MHz with internal 32.768 kHz crystal */
31#define KINETIS_MCG_MODE KINETIS_MCG_MODE_FEI
32#define KINETIS_MCG_FLL_DMX32 1 /* Fine-tune for 32.768 kHz */
33#define KINETIS_MCG_FLL_DRS 1 /* 1464x FLL factor */
34#define KINETIS_SYSCLK_FREQUENCY 47972352UL /* 32.768 kHz * 1464 (~48 MHz) */
35#define KINETIS_CLKDIV1_OUTDIV1 1
36#define KINETIS_CLKDIV1_OUTDIV2 1
37#define KINETIS_CLKDIV1_OUTDIV4 2
38#define KINETIS_BUSCLK_FREQUENCY KINETIS_SYSCLK_FREQUENCY
39#define KINETIS_FLASHCLK_FREQUENCY KINETIS_SYSCLK_FREQUENCY/2
40
41/*
42 * SERIAL driver system settings.
43 */
44#define KINETIS_SERIAL_USE_UART0 TRUE
45
46/*
47 * USB driver settings
48 */
49#define KINETIS_USB_USE_USB0 TRUE
50/* Need to redefine this, since the default is for K20x */
51/* This is for Teensy LC; you should comment it out (or change to 5)
52 * for Teensy 3.x */
53#define KINETIS_USB_USB0_IRQ_PRIORITY 2
54
55#endif /* _MCUCONF_H_ */
diff --git a/keyboards/planck/out.txt b/keyboards/planck/out.txt
new file mode 100644
index 000000000..644a6a777
--- /dev/null
+++ b/keyboards/planck/out.txt
@@ -0,0 +1,66 @@
1-------- begin --------
2avr-gcc.exe (AVR_8_bit_GNU_Toolchain_3.5.0_1662) 4.9.2
3Copyright (C) 2014 Free Software Foundation, Inc.
4This is free software; see the source for copying conditions. There is NO
5warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6
7Compiling: ../../keyboards/planck/planck.c [OK]
8Compiling: ../../keyboards/planck/keymaps/experimental/keymap.c [WARNINGS]
9 |
10 | ../../keyboards/planck/keymaps/experimental/keymap.c: In function 'action_get_macro':
11 | ../../keyboards/planck/keymaps/experimental/keymap.c:227:17: warning: implicit declaration of function 'breathing_speed_set' [-Wimplicit-function-declaration]
12 | breathing_speed_set(2);
13 | ^
14 | ../../keyboards/planck/keymaps/experimental/keymap.c:228:17: warning: implicit declaration of function 'breathing_pulse' [-Wimplicit-function-declaration]
15 | breathing_pulse();
16 | ^
17 |
18Compiling: ../../quantum/quantum.c [OK]
19Compiling: ../../quantum/keymap.c [OK]
20Compiling: ../../quantum/keycode_config.c [OK]
21Compiling: ../../quantum/matrix.c [OK]
22Compiling: ../../quantum/audio/audio.c [OK]
23Compiling: ../../quantum/audio/voices.c [OK]
24Compiling: ../../quantum/audio/luts.c [OK]
25Compiling: ../../tmk_core/protocol/lufa/lufa.c [OK]
26Compiling: ../../tmk_core/protocol/lufa/descriptor.c [OK]
27Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Class/Common/HIDParser.c [OK]
28Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.c [OK]
29Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c [OK]
30Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c [OK]
31Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c [OK]
32Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.c [OK]
33Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c [OK]
34Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c [OK]
35Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c [OK]
36Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/ConfigDescriptors.c [OK]
37Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/DeviceStandardReq.c [OK]
38Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/Events.c [OK]
39Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/HostStandardReq.c [OK]
40Compiling: ../../tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/USBTask.c [OK]
41Compiling: ../../tmk_core/common/host.c [OK]
42Compiling: ../../tmk_core/common/keyboard.c [OK]
43Compiling: ../../tmk_core/common/action.c [OK]
44Compiling: ../../tmk_core/common/action_tapping.c [OK]
45Compiling: ../../tmk_core/common/action_macro.c [OK]
46Compiling: ../../tmk_core/common/action_layer.c [OK]
47Compiling: ../../tmk_core/common/action_util.c [OK]
48Compiling: ../../tmk_core/common/print.c [OK]
49Compiling: ../../tmk_core/common/debug.c [OK]
50Compiling: ../../tmk_core/common/util.c [OK]
51Compiling: ../../tmk_core/common/avr/suspend.c [OK]
52Assembling: ../../tmk_core/common/avr/xprintf.S [OK]
53Compiling: ../../tmk_core/common/avr/timer.c [OK]
54Compiling: ../../tmk_core/common/avr/bootloader.c [OK]
55Compiling: ../../tmk_core/common/magic.c [OK]
56Compiling: ../../tmk_core/common/avr/eeconfig.c [OK]
57Compiling: ../../tmk_core/common/mousekey.c [OK]
58Compiling: ../../tmk_core/common/command.c [OK]
59Compiling: ../../tmk_core/common/backlight.c [OK]
60Linking: .build/planck_experimental.elf [ERRORS]
61 |
62 | .build/obj_planck_experimental/keyboards/planck/keymaps/experimental/keymap.o: In function `action_get_macro':
63 | C:\Users\Fred Wales\Documents\Programming\qmk_firmware\keyboards\planck/../../keyboards/planck/keymaps/experimental/keymap.c:240: undefined reference to `breathing_speed_set'
64 | C:\Users\Fred Wales\Documents\Programming\qmk_firmware\keyboards\planck/../../keyboards/planck/keymaps/experimental/keymap.c:241: undefined reference to `breathing_pulse'
65 | collect2.exe: error: ld returned 1 exit status
66 |
diff --git a/keyboards/stm32_f072_onekey/Makefile b/keyboards/stm32_f072_onekey/Makefile
new file mode 100644
index 000000000..24abcb0e0
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/Makefile
@@ -0,0 +1,50 @@
1# project specific files
2SRC = matrix.c \
3 led.c
4
5## chip/board settings
6# the next two should match the directories in
7# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
8MCU_FAMILY = STM32
9MCU_SERIES = STM32F0xx
10# linker script to use
11# it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
12# or <this_dir>/ld/
13MCU_LDSCRIPT = STM32F072xB
14# startup code to use
15# is should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
16MCU_STARTUP = stm32f0xx
17# it should exist either in <chibios>/os/hal/boards/
18# or <this_dir>/boards
19BOARD = ST_STM32F072B_DISCOVERY
20# Cortex version
21# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4
22MCU = cortex-m0
23# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
24ARMV = 6
25# If you want to be able to jump to bootloader from firmware on STM32 MCUs,
26# set the correct BOOTLOADER_ADDRESS. Either set it here, or define it in
27# ./bootloader_defs.h or in ./boards/<FOO>/bootloader_defs.h (if you have
28# a custom board definition that you plan to reuse).
29# If you're not setting it here, leave it commented out.
30# It is chip dependent, the correct number can be looked up here (page 175):
31# http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf
32# This also requires a patch to chibios:
33# <tmk_dir>/tmk_core/tool/chibios/ch-bootloader-jump.patch
34#STM32_BOOTLOADER_ADDRESS = 0x1FFFC800
35
36# Build Options
37# comment out to disable the options.
38#
39#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
40MOUSEKEY_ENABLE ?= yes # Mouse keys
41EXTRAKEY_ENABLE ?= yes # Audio control and System control
42CONSOLE_ENABLE ?= yes # Console for debug
43COMMAND_ENABLE ?= yes # Commands for debug and configuration
44SLEEP_LED_ENABLE ?= yes # Breathing sleep LED during USB suspend
45NKRO_ENABLE ?= yes # USB Nkey Rollover
46CUSTOM_MATRIX ?= yes # Custom matrix file
47
48ifndef QUANTUM_DIR
49 include ../../Makefile
50endif
diff --git a/keyboards/stm32_f072_onekey/bootloader_defs.h b/keyboards/stm32_f072_onekey/bootloader_defs.h
new file mode 100644
index 000000000..02c48c4e6
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/bootloader_defs.h
@@ -0,0 +1,7 @@
1/* Address for jumping to bootloader on STM32 chips. */
2/* It is chip dependent, the correct number can be looked up here (page 175):
3 * http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf
4 * This also requires a patch to chibios:
5 * <tmk_dir>/tmk_core/tool/chibios/ch-bootloader-jump.patch
6 */
7#define STM32_BOOTLOADER_ADDRESS 0x1FFFC800
diff --git a/keyboards/stm32_f072_onekey/chconf.h b/keyboards/stm32_f072_onekey/chconf.h
new file mode 100644
index 000000000..99fa8ce39
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/chconf.h
@@ -0,0 +1,524 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/chconf.h
19 * @brief Configuration file template.
20 * @details A copy of this file must be placed in each project directory, it
21 * contains the application specific kernel settings.
22 *
23 * @addtogroup config
24 * @details Kernel related settings and hooks.
25 * @{
26 */
27
28#ifndef CHCONF_H
29#define CHCONF_H
30
31#define _CHIBIOS_RT_CONF_
32
33/*===========================================================================*/
34/**
35 * @name System timers settings
36 * @{
37 */
38/*===========================================================================*/
39
40/**
41 * @brief System time counter resolution.
42 * @note Allowed values are 16 or 32 bits.
43 */
44#define CH_CFG_ST_RESOLUTION 32
45
46/**
47 * @brief System tick frequency.
48 * @details Frequency of the system timer that drives the system ticks. This
49 * setting also defines the system tick time unit.
50 */
51#define CH_CFG_ST_FREQUENCY 10000
52
53/**
54 * @brief Time delta constant for the tick-less mode.
55 * @note If this value is zero then the system uses the classic
56 * periodic tick. This value represents the minimum number
57 * of ticks that is safe to specify in a timeout directive.
58 * The value one is not valid, timeouts are rounded up to
59 * this value.
60 */
61#define CH_CFG_ST_TIMEDELTA 2
62
63/** @} */
64
65/*===========================================================================*/
66/**
67 * @name Kernel parameters and options
68 * @{
69 */
70/*===========================================================================*/
71
72/**
73 * @brief Round robin interval.
74 * @details This constant is the number of system ticks allowed for the
75 * threads before preemption occurs. Setting this value to zero
76 * disables the preemption for threads with equal priority and the
77 * round robin becomes cooperative. Note that higher priority
78 * threads can still preempt, the kernel is always preemptive.
79 * @note Disabling the round robin preemption makes the kernel more compact
80 * and generally faster.
81 * @note The round robin preemption is not supported in tickless mode and
82 * must be set to zero in that case.
83 */
84#define CH_CFG_TIME_QUANTUM 0
85
86/**
87 * @brief Managed RAM size.
88 * @details Size of the RAM area to be managed by the OS. If set to zero
89 * then the whole available RAM is used. The core memory is made
90 * available to the heap allocator and/or can be used directly through
91 * the simplified core memory allocator.
92 *
93 * @note In order to let the OS manage the whole RAM the linker script must
94 * provide the @p __heap_base__ and @p __heap_end__ symbols.
95 * @note Requires @p CH_CFG_USE_MEMCORE.
96 */
97#define CH_CFG_MEMCORE_SIZE 0
98
99/**
100 * @brief Idle thread automatic spawn suppression.
101 * @details When this option is activated the function @p chSysInit()
102 * does not spawn the idle thread. The application @p main()
103 * function becomes the idle thread and must implement an
104 * infinite loop.
105 */
106#define CH_CFG_NO_IDLE_THREAD FALSE
107
108/* Use __WFI in the idle thread for waiting. Does lower the power
109 * consumption. */
110#define CORTEX_ENABLE_WFI_IDLE TRUE
111
112/** @} */
113
114/*===========================================================================*/
115/**
116 * @name Performance options
117 * @{
118 */
119/*===========================================================================*/
120
121/**
122 * @brief OS optimization.
123 * @details If enabled then time efficient rather than space efficient code
124 * is used when two possible implementations exist.
125 *
126 * @note This is not related to the compiler optimization options.
127 * @note The default is @p TRUE.
128 */
129#define CH_CFG_OPTIMIZE_SPEED FALSE
130
131/** @} */
132
133/*===========================================================================*/
134/**
135 * @name Subsystem options
136 * @{
137 */
138/*===========================================================================*/
139
140/**
141 * @brief Time Measurement APIs.
142 * @details If enabled then the time measurement APIs are included in
143 * the kernel.
144 *
145 * @note The default is @p TRUE.
146 */
147#define CH_CFG_USE_TM FALSE
148
149/**
150 * @brief Threads registry APIs.
151 * @details If enabled then the registry APIs are included in the kernel.
152 *
153 * @note The default is @p TRUE.
154 */
155#define CH_CFG_USE_REGISTRY TRUE
156
157/**
158 * @brief Threads synchronization APIs.
159 * @details If enabled then the @p chThdWait() function is included in
160 * the kernel.
161 *
162 * @note The default is @p TRUE.
163 */
164#define CH_CFG_USE_WAITEXIT TRUE
165
166/**
167 * @brief Semaphores APIs.
168 * @details If enabled then the Semaphores APIs are included in the kernel.
169 *
170 * @note The default is @p TRUE.
171 */
172#define CH_CFG_USE_SEMAPHORES TRUE
173
174/**
175 * @brief Semaphores queuing mode.
176 * @details If enabled then the threads are enqueued on semaphores by
177 * priority rather than in FIFO order.
178 *
179 * @note The default is @p FALSE. Enable this if you have special
180 * requirements.
181 * @note Requires @p CH_CFG_USE_SEMAPHORES.
182 */
183#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
184
185/**
186 * @brief Mutexes APIs.
187 * @details If enabled then the mutexes APIs are included in the kernel.
188 *
189 * @note The default is @p TRUE.
190 */
191#define CH_CFG_USE_MUTEXES TRUE
192
193/**
194 * @brief Enables recursive behavior on mutexes.
195 * @note Recursive mutexes are heavier and have an increased
196 * memory footprint.
197 *
198 * @note The default is @p FALSE.
199 * @note Requires @p CH_CFG_USE_MUTEXES.
200 */
201#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
202
203/**
204 * @brief Conditional Variables APIs.
205 * @details If enabled then the conditional variables APIs are included
206 * in the kernel.
207 *
208 * @note The default is @p TRUE.
209 * @note Requires @p CH_CFG_USE_MUTEXES.
210 */
211#define CH_CFG_USE_CONDVARS TRUE
212
213/**
214 * @brief Conditional Variables APIs with timeout.
215 * @details If enabled then the conditional variables APIs with timeout
216 * specification are included in the kernel.
217 *
218 * @note The default is @p TRUE.
219 * @note Requires @p CH_CFG_USE_CONDVARS.
220 */
221#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE
222
223/**
224 * @brief Events Flags APIs.
225 * @details If enabled then the event flags APIs are included in the kernel.
226 *
227 * @note The default is @p TRUE.
228 */
229#define CH_CFG_USE_EVENTS TRUE
230
231/**
232 * @brief Events Flags APIs with timeout.
233 * @details If enabled then the events APIs with timeout specification
234 * are included in the kernel.
235 *
236 * @note The default is @p TRUE.
237 * @note Requires @p CH_CFG_USE_EVENTS.
238 */
239#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
240
241/**
242 * @brief Synchronous Messages APIs.
243 * @details If enabled then the synchronous messages APIs are included
244 * in the kernel.
245 *
246 * @note The default is @p TRUE.
247 */
248#define CH_CFG_USE_MESSAGES TRUE
249
250/**
251 * @brief Synchronous Messages queuing mode.
252 * @details If enabled then messages are served by priority rather than in
253 * FIFO order.
254 *
255 * @note The default is @p FALSE. Enable this if you have special
256 * requirements.
257 * @note Requires @p CH_CFG_USE_MESSAGES.
258 */
259#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
260
261/**
262 * @brief Mailboxes APIs.
263 * @details If enabled then the asynchronous messages (mailboxes) APIs are
264 * included in the kernel.
265 *
266 * @note The default is @p TRUE.
267 * @note Requires @p CH_CFG_USE_SEMAPHORES.
268 */
269#define CH_CFG_USE_MAILBOXES TRUE
270
271/**
272 * @brief Core Memory Manager APIs.
273 * @details If enabled then the core memory manager APIs are included
274 * in the kernel.
275 *
276 * @note The default is @p TRUE.
277 */
278#define CH_CFG_USE_MEMCORE FALSE
279
280/**
281 * @brief Heap Allocator APIs.
282 * @details If enabled then the memory heap allocator APIs are included
283 * in the kernel.
284 *
285 * @note The default is @p TRUE.
286 * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
287 * @p CH_CFG_USE_SEMAPHORES.
288 * @note Mutexes are recommended.
289 */
290#define CH_CFG_USE_HEAP FALSE
291
292/**
293 * @brief Memory Pools Allocator APIs.
294 * @details If enabled then the memory pools allocator APIs are included
295 * in the kernel.
296 *
297 * @note The default is @p TRUE.
298 */
299#define CH_CFG_USE_MEMPOOLS FALSE
300
301/**
302 * @brief Dynamic Threads APIs.
303 * @details If enabled then the dynamic threads creation APIs are included
304 * in the kernel.
305 *
306 * @note The default is @p TRUE.
307 * @note Requires @p CH_CFG_USE_WAITEXIT.
308 * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
309 */
310#define CH_CFG_USE_DYNAMIC FALSE
311
312/** @} */
313
314/*===========================================================================*/
315/**
316 * @name Debug options
317 * @{
318 */
319/*===========================================================================*/
320
321/**
322 * @brief Debug option, kernel statistics.
323 *
324 * @note The default is @p FALSE.
325 */
326#define CH_DBG_STATISTICS FALSE
327
328/**
329 * @brief Debug option, system state check.
330 * @details If enabled the correct call protocol for system APIs is checked
331 * at runtime.
332 *
333 * @note The default is @p FALSE.
334 */
335#define CH_DBG_SYSTEM_STATE_CHECK FALSE
336
337/**
338 * @brief Debug option, parameters checks.
339 * @details If enabled then the checks on the API functions input
340 * parameters are activated.
341 *
342 * @note The default is @p FALSE.
343 */
344#define CH_DBG_ENABLE_CHECKS FALSE
345
346/**
347 * @brief Debug option, consistency checks.
348 * @details If enabled then all the assertions in the kernel code are
349 * activated. This includes consistency checks inside the kernel,
350 * runtime anomalies and port-defined checks.
351 *
352 * @note The default is @p FALSE.
353 */
354#define CH_DBG_ENABLE_ASSERTS FALSE
355
356/**
357 * @brief Debug option, trace buffer.
358 * @details If enabled then the trace buffer is activated.
359 *
360 * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
361 */
362#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
363
364/**
365 * @brief Trace buffer entries.
366 * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
367 * different from @p CH_DBG_TRACE_MASK_DISABLED.
368 */
369#define CH_DBG_TRACE_BUFFER_SIZE 128
370
371/**
372 * @brief Debug option, stack checks.
373 * @details If enabled then a runtime stack check is performed.
374 *
375 * @note The default is @p FALSE.
376 * @note The stack check is performed in a architecture/port dependent way.
377 * It may not be implemented or some ports.
378 * @note The default failure mode is to halt the system with the global
379 * @p panic_msg variable set to @p NULL.
380 */
381#define CH_DBG_ENABLE_STACK_CHECK FALSE
382
383/**
384 * @brief Debug option, stacks initialization.
385 * @details If enabled then the threads working area is filled with a byte
386 * value when a thread is created. This can be useful for the
387 * runtime measurement of the used stack.
388 *
389 * @note The default is @p FALSE.
390 */
391#define CH_DBG_FILL_THREADS FALSE
392
393/**
394 * @brief Debug option, threads profiling.
395 * @details If enabled then a field is added to the @p thread_t structure that
396 * counts the system ticks occurred while executing the thread.
397 *
398 * @note The default is @p FALSE.
399 * @note This debug option is not currently compatible with the
400 * tickless mode.
401 */
402#define CH_DBG_THREADS_PROFILING FALSE
403
404/** @} */
405
406/*===========================================================================*/
407/**
408 * @name Kernel hooks
409 * @{
410 */
411/*===========================================================================*/
412
413/**
414 * @brief Threads descriptor structure extension.
415 * @details User fields added to the end of the @p thread_t structure.
416 */
417#define CH_CFG_THREAD_EXTRA_FIELDS \
418 /* Add threads custom fields here.*/
419
420/**
421 * @brief Threads initialization hook.
422 * @details User initialization code added to the @p chThdInit() API.
423 *
424 * @note It is invoked from within @p chThdInit() and implicitly from all
425 * the threads creation APIs.
426 */
427#define CH_CFG_THREAD_INIT_HOOK(tp) { \
428 /* Add threads initialization code here.*/ \
429}
430
431/**
432 * @brief Threads finalization hook.
433 * @details User finalization code added to the @p chThdExit() API.
434 */
435#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
436 /* Add threads finalization code here.*/ \
437}
438
439/**
440 * @brief Context switch hook.
441 * @details This hook is invoked just before switching between threads.
442 */
443#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
444 /* Context switch code here.*/ \
445}
446
447/**
448 * @brief ISR enter hook.
449 */
450#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
451 /* IRQ prologue code here.*/ \
452}
453
454/**
455 * @brief ISR exit hook.
456 */
457#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
458 /* IRQ epilogue code here.*/ \
459}
460
461/**
462 * @brief Idle thread enter hook.
463 * @note This hook is invoked within a critical zone, no OS functions
464 * should be invoked from here.
465 * @note This macro can be used to activate a power saving mode.
466 */
467#define CH_CFG_IDLE_ENTER_HOOK() { \
468 /* Idle-enter code here.*/ \
469}
470
471/**
472 * @brief Idle thread leave hook.
473 * @note This hook is invoked within a critical zone, no OS functions
474 * should be invoked from here.
475 * @note This macro can be used to deactivate a power saving mode.
476 */
477#define CH_CFG_IDLE_LEAVE_HOOK() { \
478 /* Idle-leave code here.*/ \
479}
480
481/**
482 * @brief Idle Loop hook.
483 * @details This hook is continuously invoked by the idle thread loop.
484 */
485#define CH_CFG_IDLE_LOOP_HOOK() { \
486 /* Idle loop code here.*/ \
487}
488
489/**
490 * @brief System tick event hook.
491 * @details This hook is invoked in the system tick handler immediately
492 * after processing the virtual timers queue.
493 */
494#define CH_CFG_SYSTEM_TICK_HOOK() { \
495 /* System tick event code here.*/ \
496}
497
498/**
499 * @brief System halt hook.
500 * @details This hook is invoked in case to a system halting error before
501 * the system is halted.
502 */
503#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
504 /* System halt code here.*/ \
505}
506
507/**
508 * @brief Trace hook.
509 * @details This hook is invoked each time a new record is written in the
510 * trace buffer.
511 */
512#define CH_CFG_TRACE_HOOK(tep) { \
513 /* Trace code here.*/ \
514}
515
516/** @} */
517
518/*===========================================================================*/
519/* Port-specific settings (override port settings defaulted in chcore.h). */
520/*===========================================================================*/
521
522#endif /* CHCONF_H */
523
524/** @} */
diff --git a/keyboards/stm32_f072_onekey/config.h b/keyboards/stm32_f072_onekey/config.h
new file mode 100644
index 000000000..bb5251e1d
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/config.h
@@ -0,0 +1,76 @@
1/*
2Copyright 2015 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21#include "config_common.h"
22
23/* USB Device descriptor parameter */
24#define VENDOR_ID 0xFEED
25#define PRODUCT_ID 0x6464
26#define DEVICE_VER 0x0001
27/* in python2: list(u"whatever".encode('utf-16-le')) */
28/* at most 32 characters or the ugly hack in usb_main.c borks */
29#define MANUFACTURER "TMK"
30#define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', '\xc6', '\x00'
31#define PRODUCT "ChibiOS TMK test"
32#define USBSTR_PRODUCT 'C', '\x00', 'h', '\x00', 'i', '\x00', 'b', '\x00', 'i', '\x00', 'O', '\x00', 'S', '\x00', ' ', '\x00', 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', 't', '\x00', 'e', '\x00', 's', '\x00', 't', '\x00'
33#define DESCRIPTION "TMK keyboard firmware over ChibiOS"
34
35/* key matrix size */
36#define MATRIX_ROWS 1
37#define MATRIX_COLS 1
38#define DIODE_DIRECTION COL2ROW
39
40/* define if matrix has ghost */
41//#define MATRIX_HAS_GHOST
42
43/* Set 0 if debouncing isn't needed */
44#define DEBOUNCE 5
45
46/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
47#define LOCKING_SUPPORT_ENABLE
48/* Locking resynchronize hack */
49#define LOCKING_RESYNC_ENABLE
50
51/* key combination for command */
52#define IS_COMMAND() ( \
53 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
54)
55
56
57
58/*
59 * Feature disable options
60 * These options are also useful to firmware size reduction.
61 */
62
63/* disable debug print */
64//#define NO_DEBUG
65
66/* disable print */
67//#define NO_PRINT
68
69/* disable action features */
70//#define NO_ACTION_LAYER
71//#define NO_ACTION_TAPPING
72//#define NO_ACTION_ONESHOT
73//#define NO_ACTION_MACRO
74//#define NO_ACTION_FUNCTION
75
76#endif
diff --git a/keyboards/stm32_f072_onekey/halconf.h b/keyboards/stm32_f072_onekey/halconf.h
new file mode 100644
index 000000000..1a450d632
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/halconf.h
@@ -0,0 +1,353 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/halconf.h
19 * @brief HAL configuration header.
20 * @details HAL configuration file, this file allows to enable or disable the
21 * various device drivers from your application. You may also use
22 * this file in order to override the device drivers default settings.
23 *
24 * @addtogroup HAL_CONF
25 * @{
26 */
27
28#ifndef _HALCONF_H_
29#define _HALCONF_H_
30
31#include "mcuconf.h"
32
33/**
34 * @brief Enables the PAL subsystem.
35 */
36#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
37#define HAL_USE_PAL TRUE
38#endif
39
40/**
41 * @brief Enables the ADC subsystem.
42 */
43#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
44#define HAL_USE_ADC FALSE
45#endif
46
47/**
48 * @brief Enables the CAN subsystem.
49 */
50#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
51#define HAL_USE_CAN FALSE
52#endif
53
54/**
55 * @brief Enables the DAC subsystem.
56 */
57#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
58#define HAL_USE_DAC FALSE
59#endif
60
61/**
62 * @brief Enables the EXT subsystem.
63 */
64#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
65#define HAL_USE_EXT FALSE
66#endif
67
68/**
69 * @brief Enables the GPT subsystem.
70 */
71#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
72#define HAL_USE_GPT FALSE
73#endif
74
75/**
76 * @brief Enables the I2C subsystem.
77 */
78#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
79#define HAL_USE_I2C FALSE
80#endif
81
82/**
83 * @brief Enables the I2S subsystem.
84 */
85#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
86#define HAL_USE_I2S FALSE
87#endif
88
89/**
90 * @brief Enables the ICU subsystem.
91 */
92#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
93#define HAL_USE_ICU FALSE
94#endif
95
96/**
97 * @brief Enables the MAC subsystem.
98 */
99#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
100#define HAL_USE_MAC FALSE
101#endif
102
103/**
104 * @brief Enables the MMC_SPI subsystem.
105 */
106#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
107#define HAL_USE_MMC_SPI FALSE
108#endif
109
110/**
111 * @brief Enables the PWM subsystem.
112 */
113#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
114#define HAL_USE_PWM FALSE
115#endif
116
117/**
118 * @brief Enables the RTC subsystem.
119 */
120#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
121#define HAL_USE_RTC FALSE
122#endif
123
124/**
125 * @brief Enables the SDC subsystem.
126 */
127#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
128#define HAL_USE_SDC FALSE
129#endif
130
131/**
132 * @brief Enables the SERIAL subsystem.
133 */
134#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
135#define HAL_USE_SERIAL FALSE
136#endif
137
138/**
139 * @brief Enables the SERIAL over USB subsystem.
140 */
141#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
142#define HAL_USE_SERIAL_USB FALSE
143#endif
144
145/**
146 * @brief Enables the SPI subsystem.
147 */
148#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
149#define HAL_USE_SPI FALSE
150#endif
151
152/**
153 * @brief Enables the UART subsystem.
154 */
155#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
156#define HAL_USE_UART FALSE
157#endif
158
159/**
160 * @brief Enables the USB subsystem.
161 */
162#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
163#define HAL_USE_USB TRUE
164#endif
165
166/**
167 * @brief Enables the WDG subsystem.
168 */
169#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)
170#define HAL_USE_WDG FALSE
171#endif
172
173/*===========================================================================*/
174/* ADC driver related settings. */
175/*===========================================================================*/
176
177/**
178 * @brief Enables synchronous APIs.
179 * @note Disabling this option saves both code and data space.
180 */
181#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
182#define ADC_USE_WAIT TRUE
183#endif
184
185/**
186 * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
187 * @note Disabling this option saves both code and data space.
188 */
189#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
190#define ADC_USE_MUTUAL_EXCLUSION TRUE
191#endif
192
193/*===========================================================================*/
194/* CAN driver related settings. */
195/*===========================================================================*/
196
197/**
198 * @brief Sleep mode related APIs inclusion switch.
199 */
200#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
201#define CAN_USE_SLEEP_MODE TRUE
202#endif
203
204/*===========================================================================*/
205/* I2C driver related settings. */
206/*===========================================================================*/
207
208/**
209 * @brief Enables the mutual exclusion APIs on the I2C bus.
210 */
211#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
212#define I2C_USE_MUTUAL_EXCLUSION TRUE
213#endif
214
215/*===========================================================================*/
216/* MAC driver related settings. */
217/*===========================================================================*/
218
219/**
220 * @brief Enables an event sources for incoming packets.
221 */
222#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
223#define MAC_USE_ZERO_COPY FALSE
224#endif
225
226/**
227 * @brief Enables an event sources for incoming packets.
228 */
229#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
230#define MAC_USE_EVENTS TRUE
231#endif
232
233/*===========================================================================*/
234/* MMC_SPI driver related settings. */
235/*===========================================================================*/
236
237/**
238 * @brief Delays insertions.
239 * @details If enabled this options inserts delays into the MMC waiting
240 * routines releasing some extra CPU time for the threads with
241 * lower priority, this may slow down the driver a bit however.
242 * This option is recommended also if the SPI driver does not
243 * use a DMA channel and heavily loads the CPU.
244 */
245#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
246#define MMC_NICE_WAITING TRUE
247#endif
248
249/*===========================================================================*/
250/* SDC driver related settings. */
251/*===========================================================================*/
252
253/**
254 * @brief Number of initialization attempts before rejecting the card.
255 * @note Attempts are performed at 10mS intervals.
256 */
257#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
258#define SDC_INIT_RETRY 100
259#endif
260
261/**
262 * @brief Include support for MMC cards.
263 * @note MMC support is not yet implemented so this option must be kept
264 * at @p FALSE.
265 */
266#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
267#define SDC_MMC_SUPPORT FALSE
268#endif
269
270/**
271 * @brief Delays insertions.
272 * @details If enabled this options inserts delays into the MMC waiting
273 * routines releasing some extra CPU time for the threads with
274 * lower priority, this may slow down the driver a bit however.
275 */
276#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
277#define SDC_NICE_WAITING TRUE
278#endif
279
280/*===========================================================================*/
281/* SERIAL driver related settings. */
282/*===========================================================================*/
283
284/**
285 * @brief Default bit rate.
286 * @details Configuration parameter, this is the baud rate selected for the
287 * default configuration.
288 */
289#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
290#define SERIAL_DEFAULT_BITRATE 38400
291#endif
292
293/**
294 * @brief Serial buffers size.
295 * @details Configuration parameter, you can change the depth of the queue
296 * buffers depending on the requirements of your application.
297 * @note The default is 64 bytes for both the transmission and receive
298 * buffers.
299 */
300#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
301#define SERIAL_BUFFERS_SIZE 16
302#endif
303
304/*===========================================================================*/
305/* SERIAL_USB driver related setting. */
306/*===========================================================================*/
307
308/**
309 * @brief Serial over USB buffers size.
310 * @details Configuration parameter, the buffer size must be a multiple of
311 * the USB data endpoint maximum packet size.
312 * @note The default is 64 bytes for both the transmission and receive
313 * buffers.
314 */
315#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
316#define SERIAL_USB_BUFFERS_SIZE 256
317#endif
318
319/*===========================================================================*/
320/* SPI driver related settings. */
321/*===========================================================================*/
322
323/**
324 * @brief Enables synchronous APIs.
325 * @note Disabling this option saves both code and data space.
326 */
327#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
328#define SPI_USE_WAIT TRUE
329#endif
330
331/**
332 * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
333 * @note Disabling this option saves both code and data space.
334 */
335#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
336#define SPI_USE_MUTUAL_EXCLUSION TRUE
337#endif
338
339/*===========================================================================*/
340/* USB driver related settings. */
341/*===========================================================================*/
342
343/**
344 * @brief Enables synchronous APIs.
345 * @note Disabling this option saves both code and data space.
346 */
347#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
348#define USB_USE_WAIT TRUE
349#endif
350
351#endif /* _HALCONF_H_ */
352
353/** @} */
diff --git a/keyboards/stm32_f072_onekey/keymaps/default/keymap.c b/keyboards/stm32_f072_onekey/keymaps/default/keymap.c
new file mode 100644
index 000000000..6c48149f8
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/keymaps/default/keymap.c
@@ -0,0 +1,25 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "stm32_f072_onekey.h"
19
20const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
21 {{KC_CAPS}}, // test with KC_CAPS, KC_A, KC_BTLD
22};
23
24const uint16_t fn_actions[] = {
25};
diff --git a/keyboards/stm32_f072_onekey/led.c b/keyboards/stm32_f072_onekey/led.c
new file mode 100644
index 000000000..18edb8ba8
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/led.c
@@ -0,0 +1,34 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "hal.h"
19
20#include "led.h"
21
22
23void led_set(uint8_t usb_led)
24{
25 (void)usb_led;
26 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
27 // output high
28 palSetPadMode(GPIOC, GPIOC_LED_GREEN, PAL_MODE_OUTPUT_PUSHPULL);
29 palSetPad(GPIOC, GPIOC_LED_GREEN);
30 } else {
31 // Hi-Z
32 palSetPadMode(GPIOC, GPIOC_LED_GREEN, PAL_MODE_INPUT);
33 }
34}
diff --git a/keyboards/stm32_f072_onekey/matrix.c b/keyboards/stm32_f072_onekey/matrix.c
new file mode 100644
index 000000000..a05b38cd4
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/matrix.c
@@ -0,0 +1,163 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "ch.h"
19#include "hal.h"
20
21/*
22 * scan matrix
23 */
24#include "print.h"
25#include "debug.h"
26#include "util.h"
27#include "matrix.h"
28#include "wait.h"
29
30#ifndef DEBOUNCE
31# define DEBOUNCE 5
32#endif
33static uint8_t debouncing = DEBOUNCE;
34
35/* matrix state(1:on, 0:off) */
36static matrix_row_t matrix[MATRIX_ROWS];
37static matrix_row_t matrix_debouncing[MATRIX_ROWS];
38
39static matrix_row_t read_cols(void);
40static void init_cols(void);
41static void unselect_rows(void);
42static void select_row(uint8_t row);
43
44
45inline
46uint8_t matrix_rows(void)
47{
48 return MATRIX_ROWS;
49}
50
51inline
52uint8_t matrix_cols(void)
53{
54 return MATRIX_COLS;
55}
56
57#define LED_ON() do { palSetPad(GPIOC, GPIOC_LED_BLUE) ;} while (0)
58#define LED_OFF() do { palClearPad(GPIOC, GPIOC_LED_BLUE); } while (0)
59#define LED_TGL() do { palTogglePad(GPIOC, GPIOC_LED_BLUE); } while (0)
60
61void matrix_init(void)
62{
63 // initialize row and col
64 unselect_rows();
65 init_cols();
66
67 // initialize matrix state: all keys off
68 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
69 matrix[i] = 0;
70 matrix_debouncing[i] = 0;
71 }
72
73 //debug
74 debug_matrix = true;
75 LED_ON();
76 wait_ms(500);
77 LED_OFF();
78}
79
80uint8_t matrix_scan(void)
81{
82 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
83 select_row(i);
84 wait_us(30); // without this wait read unstable value.
85 matrix_row_t cols = read_cols();
86 if (matrix_debouncing[i] != cols) {
87 matrix_debouncing[i] = cols;
88 if (debouncing) {
89 debug("bounce!: "); debug_hex(debouncing); debug("\n");
90 }
91 debouncing = DEBOUNCE;
92 }
93 unselect_rows();
94 }
95
96 if (debouncing) {
97 if (--debouncing) {
98 wait_ms(1);
99 } else {
100 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
101 matrix[i] = matrix_debouncing[i];
102 }
103 }
104 }
105
106 return 1;
107}
108
109inline
110bool matrix_is_on(uint8_t row, uint8_t col)
111{
112 return (matrix[row] & ((matrix_row_t)1<<col));
113}
114
115inline
116matrix_row_t matrix_get_row(uint8_t row)
117{
118 return matrix[row];
119}
120
121void matrix_print(void)
122{
123 print("\nr/c 0123456789ABCDEF\n");
124 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
125 phex(row); print(": ");
126 pbin_reverse16(matrix_get_row(row));
127 print("\n");
128 }
129}
130
131/* Column pin configuration
132 */
133static void init_cols(void)
134{
135 // don't need pullup/down, since it's pulled down in hardware
136 palSetPadMode(GPIOA, GPIOA_BUTTON, PAL_MODE_INPUT);
137}
138
139/* Returns status of switches(1:on, 0:off) */
140static matrix_row_t read_cols(void)
141{
142 return ((palReadPad(GPIOA, GPIOA_BUTTON)==PAL_LOW) ? 0 : (1<<0));
143 // | ((palReadPad(...)==PAL_HIGH) ? 0 : (1<<1))
144}
145
146/* Row pin configuration
147 */
148static void unselect_rows(void)
149{
150 // palSetPadMode(GPIOA, GPIOA_PIN10, PAL_MODE_INPUT); // hi-Z
151}
152
153static void select_row(uint8_t row)
154{
155 (void)row;
156 // Output low to select
157 // switch (row) {
158 // case 0:
159 // palSetPadMode(GPIOA, GPIOA_PIN10, PAL_MODE_OUTPUT_PUSHPULL);
160 // palSetPad(GPIOA, GPIOA_PIN10, PAL_LOW);
161 // break;
162 // }
163}
diff --git a/keyboards/stm32_f072_onekey/mcuconf.h b/keyboards/stm32_f072_onekey/mcuconf.h
new file mode 100644
index 000000000..3d877aaa2
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/mcuconf.h
@@ -0,0 +1,171 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef _MCUCONF_H_
18#define _MCUCONF_H_
19
20/*
21 * STM32F0xx drivers configuration.
22 * The following settings override the default settings present in
23 * the various device driver implementation headers.
24 * Note that the settings for each driver only have effect if the whole
25 * driver is enabled in halconf.h.
26 *
27 * IRQ priorities:
28 * 3...0 Lowest...Highest.
29 *
30 * DMA priorities:
31 * 0...3 Lowest...Highest.
32 */
33
34#define STM32F0xx_MCUCONF
35
36/*
37 * HAL driver system settings.
38 */
39#define STM32_NO_INIT FALSE
40#define STM32_PVD_ENABLE FALSE
41#define STM32_PLS STM32_PLS_LEV0
42#define STM32_HSI_ENABLED TRUE
43#define STM32_HSI14_ENABLED TRUE
44#define STM32_HSI48_ENABLED FALSE
45#define STM32_LSI_ENABLED TRUE
46#define STM32_HSE_ENABLED FALSE
47#define STM32_LSE_ENABLED FALSE
48#define STM32_SW STM32_SW_PLL
49#define STM32_PLLSRC STM32_PLLSRC_HSI_DIV2
50#define STM32_PREDIV_VALUE 1
51#define STM32_PLLMUL_VALUE 12
52#define STM32_HPRE STM32_HPRE_DIV1
53#define STM32_PPRE STM32_PPRE_DIV1
54#define STM32_ADCSW STM32_ADCSW_HSI14
55#define STM32_ADCPRE STM32_ADCPRE_DIV4
56#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
57#define STM32_ADCPRE STM32_ADCPRE_DIV4
58#define STM32_ADCSW STM32_ADCSW_HSI14
59#define STM32_USBSW STM32_USBSW_HSI48
60#define STM32_CECSW STM32_CECSW_HSI
61#define STM32_I2C1SW STM32_I2C1SW_HSI
62#define STM32_USART1SW STM32_USART1SW_PCLK
63#define STM32_RTCSEL STM32_RTCSEL_LSI
64
65/*
66 * ADC driver system settings.
67 */
68#define STM32_ADC_USE_ADC1 FALSE
69#define STM32_ADC_ADC1_DMA_PRIORITY 2
70#define STM32_ADC_IRQ_PRIORITY 2
71#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 2
72
73/*
74 * EXT driver system settings.
75 */
76#define STM32_EXT_EXTI0_1_IRQ_PRIORITY 3
77#define STM32_EXT_EXTI2_3_IRQ_PRIORITY 3
78#define STM32_EXT_EXTI4_15_IRQ_PRIORITY 3
79#define STM32_EXT_EXTI16_IRQ_PRIORITY 3
80#define STM32_EXT_EXTI17_IRQ_PRIORITY 3
81
82/*
83 * GPT driver system settings.
84 */
85#define STM32_GPT_USE_TIM1 FALSE
86#define STM32_GPT_USE_TIM2 FALSE
87#define STM32_GPT_USE_TIM3 FALSE
88#define STM32_GPT_USE_TIM14 FALSE
89#define STM32_GPT_TIM1_IRQ_PRIORITY 2
90#define STM32_GPT_TIM2_IRQ_PRIORITY 2
91#define STM32_GPT_TIM3_IRQ_PRIORITY 2
92#define STM32_GPT_TIM14_IRQ_PRIORITY 2
93
94/*
95 * I2C driver system settings.
96 */
97#define STM32_I2C_USE_I2C1 FALSE
98#define STM32_I2C_USE_I2C2 FALSE
99#define STM32_I2C_BUSY_TIMEOUT 50
100#define STM32_I2C_I2C1_IRQ_PRIORITY 3
101#define STM32_I2C_I2C2_IRQ_PRIORITY 3
102#define STM32_I2C_USE_DMA TRUE
103#define STM32_I2C_I2C1_DMA_PRIORITY 1
104#define STM32_I2C_I2C2_DMA_PRIORITY 1
105#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
106
107/*
108 * ICU driver system settings.
109 */
110#define STM32_ICU_USE_TIM1 FALSE
111#define STM32_ICU_USE_TIM2 FALSE
112#define STM32_ICU_USE_TIM3 FALSE
113#define STM32_ICU_TIM1_IRQ_PRIORITY 3
114#define STM32_ICU_TIM2_IRQ_PRIORITY 3
115#define STM32_ICU_TIM3_IRQ_PRIORITY 3
116
117/*
118 * PWM driver system settings.
119 */
120#define STM32_PWM_USE_ADVANCED FALSE
121#define STM32_PWM_USE_TIM1 FALSE
122#define STM32_PWM_USE_TIM2 FALSE
123#define STM32_PWM_USE_TIM3 FALSE
124#define STM32_PWM_TIM1_IRQ_PRIORITY 3
125#define STM32_PWM_TIM2_IRQ_PRIORITY 3
126#define STM32_PWM_TIM3_IRQ_PRIORITY 3
127
128/*
129 * SERIAL driver system settings.
130 */
131#define STM32_SERIAL_USE_USART1 FALSE
132#define STM32_SERIAL_USE_USART2 FALSE
133#define STM32_SERIAL_USART1_PRIORITY 3
134#define STM32_SERIAL_USART2_PRIORITY 3
135
136/*
137 * SPI driver system settings.
138 */
139#define STM32_SPI_USE_SPI1 FALSE
140#define STM32_SPI_USE_SPI2 FALSE
141#define STM32_SPI_SPI1_DMA_PRIORITY 1
142#define STM32_SPI_SPI2_DMA_PRIORITY 1
143#define STM32_SPI_SPI1_IRQ_PRIORITY 2
144#define STM32_SPI_SPI2_IRQ_PRIORITY 2
145#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
146
147/*
148 * ST driver system settings.
149 */
150#define STM32_ST_IRQ_PRIORITY 2
151#define STM32_ST_USE_TIMER 2
152
153/*
154 * UART driver system settings.
155 */
156#define STM32_UART_USE_USART1 FALSE
157#define STM32_UART_USE_USART2 FALSE
158#define STM32_UART_USART1_IRQ_PRIORITY 3
159#define STM32_UART_USART2_IRQ_PRIORITY 3
160#define STM32_UART_USART1_DMA_PRIORITY 0
161#define STM32_UART_USART2_DMA_PRIORITY 0
162#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
163
164/*
165 * USB driver system settings.
166 */
167#define STM32_USB_USE_USB1 TRUE
168#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
169#define STM32_USB_USB1_LP_IRQ_PRIORITY 3
170
171#endif /* _MCUCONF_H_ */
diff --git a/keyboards/stm32_f072_onekey/stm32_f072_onekey.c b/keyboards/stm32_f072_onekey/stm32_f072_onekey.c
new file mode 100644
index 000000000..820d062ff
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/stm32_f072_onekey.c
@@ -0,0 +1 @@
#include "stm32_f072_onekey.h"
diff --git a/keyboards/stm32_f072_onekey/stm32_f072_onekey.h b/keyboards/stm32_f072_onekey/stm32_f072_onekey.h
new file mode 100644
index 000000000..1f798c825
--- /dev/null
+++ b/keyboards/stm32_f072_onekey/stm32_f072_onekey.h
@@ -0,0 +1,5 @@
1#ifndef STM32_F072_ONEKEY_H
2#define STM32_F072_ONEKEY_H
3#include "quantum.h"
4#endif
5
diff --git a/keyboards/stm32_f103_onekey/Makefile b/keyboards/stm32_f103_onekey/Makefile
new file mode 100644
index 000000000..5c1793c86
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/Makefile
@@ -0,0 +1,64 @@
1# project specific files
2SRC = matrix.c \
3 led.c
4
5# GENERIC STM32F103C8T6 board - stm32duino bootloader
6OPT_DEFS = -DCORTEX_VTOR_INIT=0x2000
7MCU_LDSCRIPT = STM32F103x8_stm32duino_bootloader
8BOARD = GENERIC_STM32_F103
9
10# GENERIC STM32F103C8T6 board - no bootloader (programmer over serial or SWD)
11# OPT_DEFS =
12# MCU_LDSCRIPT = STM32F103x8
13# BOARD = GENERIC_STM32_F103
14
15# MAPLE MINI
16# OPT_DEFS = -DCORTEX_VTOR_INIT=0x5000
17# MCU_LDSCRIPT = STM32F103xB_maplemini_bootloader
18# BOARD = MAPLEMINI_STM32_F103
19
20## chip/board settings
21# the next two should match the directories in
22# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
23MCU_FAMILY = STM32
24MCU_SERIES = STM32F1xx
25# linker script to use
26# it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
27# or <this_dir>/ld/
28# startup code to use
29# is should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
30MCU_STARTUP = stm32f1xx
31# it should exist either in <chibios>/os/hal/boards/
32# or <this_dir>/boards
33# Cortex version
34# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4
35MCU = cortex-m3
36# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
37ARMV = 7
38# If you want to be able to jump to bootloader from firmware on STM32 MCUs,
39# set the correct BOOTLOADER_ADDRESS. Either set it here, or define it in
40# ./bootloader_defs.h or in ./boards/<FOO>/bootloader_defs.h (if you have
41# a custom board definition that you plan to reuse).
42# If you're not setting it here, leave it commented out.
43# It is chip dependent, the correct number can be looked up here (page 175):
44# http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf
45# This also requires a patch to chibios:
46# <tmk_dir>/tmk_core/tool/chibios/ch-bootloader-jump.patch
47#STM32_BOOTLOADER_ADDRESS = 0x1FFFC800
48
49# Build Options
50# comment out to disable the options.
51#
52#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
53## BOOTMAGIC is not supported on STM32 chips yet.
54MOUSEKEY_ENABLE ?= yes # Mouse keys
55EXTRAKEY_ENABLE ?= yes # Audio control and System control
56# CONSOLE_ENABLE ?= yes # Console for debug
57COMMAND_ENABLE ?= yes # Commands for debug and configuration
58SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
59NKRO_ENABLE ?= yes # USB Nkey Rollover
60CUSTOM_MATRIX ?= yes # Custom matrix file
61
62ifndef QUANTUM_DIR
63 include ../../Makefile
64endif
diff --git a/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.c b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.c
new file mode 100644
index 000000000..31319ef57
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.c
@@ -0,0 +1,49 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include "hal.h"
18
19/**
20 * @brief PAL setup.
21 * @details Digital I/O ports static configuration as defined in @p board.h.
22 * This variable is used by the HAL when initializing the PAL driver.
23 */
24#if HAL_USE_PAL || defined(__DOXYGEN__)
25const PALConfig pal_default_config =
26{
27 {VAL_GPIOAODR, VAL_GPIOACRL, VAL_GPIOACRH},
28 {VAL_GPIOBODR, VAL_GPIOBCRL, VAL_GPIOBCRH},
29 {VAL_GPIOCODR, VAL_GPIOCCRL, VAL_GPIOCCRH},
30 {VAL_GPIODODR, VAL_GPIODCRL, VAL_GPIODCRH},
31 {VAL_GPIOEODR, VAL_GPIOECRL, VAL_GPIOECRH},
32};
33#endif
34
35/*
36 * Early initialization code.
37 * This initialization must be performed just after stack setup and before
38 * any other initialization.
39 */
40void __early_init(void) {
41
42 stm32_clock_init();
43}
44
45/*
46 * Board-specific initialization code.
47 */
48void boardInit(void) {
49}
diff --git a/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.h b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.h
new file mode 100644
index 000000000..7253e7782
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.h
@@ -0,0 +1,166 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef _BOARD_H_
18#define _BOARD_H_
19
20/*
21 * Setup for a Generic STM32F103 board.
22 */
23
24/*
25 * Board identifier.
26 */
27#define BOARD_GENERIC_STM32_F103
28#define BOARD_NAME "Generic STM32F103x board"
29
30/*
31 * Board frequencies.
32 */
33#define STM32_LSECLK 32768
34#define STM32_HSECLK 8000000
35
36/*
37 * MCU type, supported types are defined in ./os/hal/platforms/hal_lld.h.
38 */
39#define STM32F103xB
40
41/*
42 * IO pins assignments
43 */
44
45/* on-board */
46
47#define GPIOC_LED 13
48#define GPIOD_OSC_IN 0
49#define GPIOD_OSC_OUT 1
50
51/* In case your board has a "USB enable" hardware
52 controlled by a pin, define it here. (It could be just
53 a 1.5k resistor connected to D+ line.)
54*/
55/*
56#define GPIOB_USB_DISC 10
57*/
58
59/*
60 * I/O ports initial setup, this configuration is established soon after reset
61 * in the initialization code.
62 *
63 * The digits have the following meaning:
64 * 0 - Analog input.
65 * 1 - Push Pull output 10MHz.
66 * 2 - Push Pull output 2MHz.
67 * 3 - Push Pull output 50MHz.
68 * 4 - Digital input.
69 * 5 - Open Drain output 10MHz.
70 * 6 - Open Drain output 2MHz.
71 * 7 - Open Drain output 50MHz.
72 * 8 - Digital input with PullUp or PullDown resistor depending on ODR.
73 * 9 - Alternate Push Pull output 10MHz.
74 * A - Alternate Push Pull output 2MHz.
75 * B - Alternate Push Pull output 50MHz.
76 * C - Reserved.
77 * D - Alternate Open Drain output 10MHz.
78 * E - Alternate Open Drain output 2MHz.
79 * F - Alternate Open Drain output 50MHz.
80 * Please refer to the STM32 Reference Manual for details.
81 */
82
83/*
84 * Port A setup.
85 * Everything input with pull-up except:
86 * PA2 - Alternate output (USART2 TX).
87 * PA3 - Normal input (USART2 RX).
88 * PA9 - Alternate output (USART1 TX).
89 * PA10 - Normal input (USART1 RX).
90 */
91#define VAL_GPIOACRL 0x88884B88 /* PA7...PA0 */
92#define VAL_GPIOACRH 0x888884B8 /* PA15...PA8 */
93#define VAL_GPIOAODR 0xFFFFFFFF
94
95/*
96 * Port B setup.
97 * Everything input with pull-up except:
98 * PB10 - Push Pull output (USB switch).
99 */
100#define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */
101#define VAL_GPIOBCRH 0x88888388 /* PB15...PB8 */
102#define VAL_GPIOBODR 0xFFFFFFFF
103
104/*
105 * Port C setup.
106 * Everything input with pull-up except:
107 * PC13 - Push Pull output (LED).
108 */
109#define VAL_GPIOCCRL 0x88888888 /* PC7...PC0 */
110#define VAL_GPIOCCRH 0x88388888 /* PC15...PC8 */
111#define VAL_GPIOCODR 0xFFFFFFFF
112
113/*
114 * Port D setup.
115 * Everything input with pull-up except:
116 * PD0 - Normal input (XTAL).
117 * PD1 - Normal input (XTAL).
118 */
119#define VAL_GPIODCRL 0x88888844 /* PD7...PD0 */
120#define VAL_GPIODCRH 0x88888888 /* PD15...PD8 */
121#define VAL_GPIODODR 0xFFFFFFFF
122
123/*
124 * Port E setup.
125 * Everything input with pull-up except:
126 */
127#define VAL_GPIOECRL 0x88888888 /* PE7...PE0 */
128#define VAL_GPIOECRH 0x88888888 /* PE15...PE8 */
129#define VAL_GPIOEODR 0xFFFFFFFF
130
131/*
132 * USB bus activation macro, required by the USB driver.
133 */
134/* The point is that most of the generic STM32F103* boards
135 have a 1.5k resistor connected on one end to the D+ line
136 and on the other end to some pin. Or even a slightly more
137 complicated "USB enable" circuit, controlled by a pin.
138 That should go here.
139
140 However on some boards (e.g. one that I have), there's no
141 such hardware. In which case it's better to not do anything.
142*/
143/*
144#define usb_lld_connect_bus(usbp) palClearPad(GPIOB, GPIOB_USB_DISC)
145*/
146#define usb_lld_connect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_INPUT);
147
148/*
149 * USB bus de-activation macro, required by the USB driver.
150 */
151/*
152#define usb_lld_disconnect_bus(usbp) palSetPad(GPIOB, GPIOB_USB_DISC)
153*/
154#define usb_lld_disconnect_bus(usbp) palSetPadMode(GPIOA, 12, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 12);
155
156#if !defined(_FROM_ASM_)
157#ifdef __cplusplus
158extern "C" {
159#endif
160 void boardInit(void);
161#ifdef __cplusplus
162}
163#endif
164#endif /* _FROM_ASM_ */
165
166#endif /* _BOARD_H_ */
diff --git a/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.mk b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.mk
new file mode 100644
index 000000000..d692c0ee4
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/board.mk
@@ -0,0 +1,5 @@
1# List of all the board related files.
2BOARDSRC = $(KEYBOARD_PATH)/boards/GENERIC_STM32_F103/board.c
3
4# Required include directories
5BOARDINC = $(KEYBOARD_PATH)/boards/GENERIC_STM32_F103
diff --git a/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/mini_stm32_mapping.png b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/mini_stm32_mapping.png
new file mode 100644
index 000000000..c44a7d9eb
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/boards/GENERIC_STM32_F103/mini_stm32_mapping.png
Binary files differ
diff --git a/keyboards/stm32_f103_onekey/boards/maple_mini_mapping.png b/keyboards/stm32_f103_onekey/boards/maple_mini_mapping.png
new file mode 100644
index 000000000..12cfa81db
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/boards/maple_mini_mapping.png
Binary files differ
diff --git a/keyboards/stm32_f103_onekey/bootloader_defs.h b/keyboards/stm32_f103_onekey/bootloader_defs.h
new file mode 100644
index 000000000..0f45203cb
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/bootloader_defs.h
@@ -0,0 +1,10 @@
1/* Address for jumping to bootloader on STM32 chips. */
2/* It is chip dependent, the correct number can be looked up here (page 175):
3 * http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf
4 * This also requires a patch to chibios:
5 * <tmk_dir>/tmk_core/tool/chibios/ch-bootloader-jump.patch
6 */
7
8// STM32F103* does NOT have an USB bootloader in ROM (only serial),
9// so setting anything here does not make much sense
10// #define STM32_BOOTLOADER_ADDRESS 0x1FFFC800
diff --git a/keyboards/stm32_f103_onekey/chconf.h b/keyboards/stm32_f103_onekey/chconf.h
new file mode 100644
index 000000000..dfb1f9dfb
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/chconf.h
@@ -0,0 +1,524 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/chconf.h
19 * @brief Configuration file template.
20 * @details A copy of this file must be placed in each project directory, it
21 * contains the application specific kernel settings.
22 *
23 * @addtogroup config
24 * @details Kernel related settings and hooks.
25 * @{
26 */
27
28#ifndef CHCONF_H
29#define CHCONF_H
30
31#define _CHIBIOS_RT_CONF_
32
33/*===========================================================================*/
34/**
35 * @name System timers settings
36 * @{
37 */
38/*===========================================================================*/
39
40/**
41 * @brief System time counter resolution.
42 * @note Allowed values are 16 or 32 bits.
43 */
44#define CH_CFG_ST_RESOLUTION 16
45
46/**
47 * @brief System tick frequency.
48 * @details Frequency of the system timer that drives the system ticks. This
49 * setting also defines the system tick time unit.
50 */
51#define CH_CFG_ST_FREQUENCY 2000
52
53/**
54 * @brief Time delta constant for the tick-less mode.
55 * @note If this value is zero then the system uses the classic
56 * periodic tick. This value represents the minimum number
57 * of ticks that is safe to specify in a timeout directive.
58 * The value one is not valid, timeouts are rounded up to
59 * this value.
60 */
61#define CH_CFG_ST_TIMEDELTA 2
62
63/** @} */
64
65/*===========================================================================*/
66/**
67 * @name Kernel parameters and options
68 * @{
69 */
70/*===========================================================================*/
71
72/**
73 * @brief Round robin interval.
74 * @details This constant is the number of system ticks allowed for the
75 * threads before preemption occurs. Setting this value to zero
76 * disables the preemption for threads with equal priority and the
77 * round robin becomes cooperative. Note that higher priority
78 * threads can still preempt, the kernel is always preemptive.
79 * @note Disabling the round robin preemption makes the kernel more compact
80 * and generally faster.
81 * @note The round robin preemption is not supported in tickless mode and
82 * must be set to zero in that case.
83 */
84#define CH_CFG_TIME_QUANTUM 0
85
86/**
87 * @brief Managed RAM size.
88 * @details Size of the RAM area to be managed by the OS. If set to zero
89 * then the whole available RAM is used. The core memory is made
90 * available to the heap allocator and/or can be used directly through
91 * the simplified core memory allocator.
92 *
93 * @note In order to let the OS manage the whole RAM the linker script must
94 * provide the @p __heap_base__ and @p __heap_end__ symbols.
95 * @note Requires @p CH_CFG_USE_MEMCORE.
96 */
97#define CH_CFG_MEMCORE_SIZE 0
98
99/**
100 * @brief Idle thread automatic spawn suppression.
101 * @details When this option is activated the function @p chSysInit()
102 * does not spawn the idle thread. The application @p main()
103 * function becomes the idle thread and must implement an
104 * infinite loop.
105 */
106#define CH_CFG_NO_IDLE_THREAD FALSE
107
108/* Use __WFI in the idle thread for waiting. Does lower the power
109 * consumption. */
110#define CORTEX_ENABLE_WFI_IDLE TRUE
111
112/** @} */
113
114/*===========================================================================*/
115/**
116 * @name Performance options
117 * @{
118 */
119/*===========================================================================*/
120
121/**
122 * @brief OS optimization.
123 * @details If enabled then time efficient rather than space efficient code
124 * is used when two possible implementations exist.
125 *
126 * @note This is not related to the compiler optimization options.
127 * @note The default is @p TRUE.
128 */
129#define CH_CFG_OPTIMIZE_SPEED TRUE
130
131/** @} */
132
133/*===========================================================================*/
134/**
135 * @name Subsystem options
136 * @{
137 */
138/*===========================================================================*/
139
140/**
141 * @brief Time Measurement APIs.
142 * @details If enabled then the time measurement APIs are included in
143 * the kernel.
144 *
145 * @note The default is @p TRUE.
146 */
147#define CH_CFG_USE_TM FALSE
148
149/**
150 * @brief Threads registry APIs.
151 * @details If enabled then the registry APIs are included in the kernel.
152 *
153 * @note The default is @p TRUE.
154 */
155#define CH_CFG_USE_REGISTRY TRUE
156
157/**
158 * @brief Threads synchronization APIs.
159 * @details If enabled then the @p chThdWait() function is included in
160 * the kernel.
161 *
162 * @note The default is @p TRUE.
163 */
164#define CH_CFG_USE_WAITEXIT TRUE
165
166/**
167 * @brief Semaphores APIs.
168 * @details If enabled then the Semaphores APIs are included in the kernel.
169 *
170 * @note The default is @p TRUE.
171 */
172#define CH_CFG_USE_SEMAPHORES TRUE
173
174/**
175 * @brief Semaphores queuing mode.
176 * @details If enabled then the threads are enqueued on semaphores by
177 * priority rather than in FIFO order.
178 *
179 * @note The default is @p FALSE. Enable this if you have special
180 * requirements.
181 * @note Requires @p CH_CFG_USE_SEMAPHORES.
182 */
183#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
184
185/**
186 * @brief Mutexes APIs.
187 * @details If enabled then the mutexes APIs are included in the kernel.
188 *
189 * @note The default is @p TRUE.
190 */
191#define CH_CFG_USE_MUTEXES TRUE
192
193/**
194 * @brief Enables recursive behavior on mutexes.
195 * @note Recursive mutexes are heavier and have an increased
196 * memory footprint.
197 *
198 * @note The default is @p FALSE.
199 * @note Requires @p CH_CFG_USE_MUTEXES.
200 */
201#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
202
203/**
204 * @brief Conditional Variables APIs.
205 * @details If enabled then the conditional variables APIs are included
206 * in the kernel.
207 *
208 * @note The default is @p TRUE.
209 * @note Requires @p CH_CFG_USE_MUTEXES.
210 */
211#define CH_CFG_USE_CONDVARS TRUE
212
213/**
214 * @brief Conditional Variables APIs with timeout.
215 * @details If enabled then the conditional variables APIs with timeout
216 * specification are included in the kernel.
217 *
218 * @note The default is @p TRUE.
219 * @note Requires @p CH_CFG_USE_CONDVARS.
220 */
221#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE
222
223/**
224 * @brief Events Flags APIs.
225 * @details If enabled then the event flags APIs are included in the kernel.
226 *
227 * @note The default is @p TRUE.
228 */
229#define CH_CFG_USE_EVENTS TRUE
230
231/**
232 * @brief Events Flags APIs with timeout.
233 * @details If enabled then the events APIs with timeout specification
234 * are included in the kernel.
235 *
236 * @note The default is @p TRUE.
237 * @note Requires @p CH_CFG_USE_EVENTS.
238 */
239#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
240
241/**
242 * @brief Synchronous Messages APIs.
243 * @details If enabled then the synchronous messages APIs are included
244 * in the kernel.
245 *
246 * @note The default is @p TRUE.
247 */
248#define CH_CFG_USE_MESSAGES TRUE
249
250/**
251 * @brief Synchronous Messages queuing mode.
252 * @details If enabled then messages are served by priority rather than in
253 * FIFO order.
254 *
255 * @note The default is @p FALSE. Enable this if you have special
256 * requirements.
257 * @note Requires @p CH_CFG_USE_MESSAGES.
258 */
259#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
260
261/**
262 * @brief Mailboxes APIs.
263 * @details If enabled then the asynchronous messages (mailboxes) APIs are
264 * included in the kernel.
265 *
266 * @note The default is @p TRUE.
267 * @note Requires @p CH_CFG_USE_SEMAPHORES.
268 */
269#define CH_CFG_USE_MAILBOXES TRUE
270
271/**
272 * @brief Core Memory Manager APIs.
273 * @details If enabled then the core memory manager APIs are included
274 * in the kernel.
275 *
276 * @note The default is @p TRUE.
277 */
278#define CH_CFG_USE_MEMCORE TRUE
279
280/**
281 * @brief Heap Allocator APIs.
282 * @details If enabled then the memory heap allocator APIs are included
283 * in the kernel.
284 *
285 * @note The default is @p TRUE.
286 * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
287 * @p CH_CFG_USE_SEMAPHORES.
288 * @note Mutexes are recommended.
289 */
290#define CH_CFG_USE_HEAP TRUE
291
292/**
293 * @brief Memory Pools Allocator APIs.
294 * @details If enabled then the memory pools allocator APIs are included
295 * in the kernel.
296 *
297 * @note The default is @p TRUE.
298 */
299#define CH_CFG_USE_MEMPOOLS FALSE
300
301/**
302 * @brief Dynamic Threads APIs.
303 * @details If enabled then the dynamic threads creation APIs are included
304 * in the kernel.
305 *
306 * @note The default is @p TRUE.
307 * @note Requires @p CH_CFG_USE_WAITEXIT.
308 * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
309 */
310#define CH_CFG_USE_DYNAMIC FALSE
311
312/** @} */
313
314/*===========================================================================*/
315/**
316 * @name Debug options
317 * @{
318 */
319/*===========================================================================*/
320
321/**
322 * @brief Debug option, kernel statistics.
323 *
324 * @note The default is @p FALSE.
325 */
326#define CH_DBG_STATISTICS FALSE
327
328/**
329 * @brief Debug option, system state check.
330 * @details If enabled the correct call protocol for system APIs is checked
331 * at runtime.
332 *
333 * @note The default is @p FALSE.
334 */
335#define CH_DBG_SYSTEM_STATE_CHECK FALSE
336
337/**
338 * @brief Debug option, parameters checks.
339 * @details If enabled then the checks on the API functions input
340 * parameters are activated.
341 *
342 * @note The default is @p FALSE.
343 */
344#define CH_DBG_ENABLE_CHECKS FALSE
345
346/**
347 * @brief Debug option, consistency checks.
348 * @details If enabled then all the assertions in the kernel code are
349 * activated. This includes consistency checks inside the kernel,
350 * runtime anomalies and port-defined checks.
351 *
352 * @note The default is @p FALSE.
353 */
354#define CH_DBG_ENABLE_ASSERTS FALSE
355
356/**
357 * @brief Debug option, trace buffer.
358 * @details If enabled then the trace buffer is activated.
359 *
360 * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
361 */
362#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
363
364/**
365 * @brief Trace buffer entries.
366 * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
367 * different from @p CH_DBG_TRACE_MASK_DISABLED.
368 */
369#define CH_DBG_TRACE_BUFFER_SIZE 128
370
371/**
372 * @brief Debug option, stack checks.
373 * @details If enabled then a runtime stack check is performed.
374 *
375 * @note The default is @p FALSE.
376 * @note The stack check is performed in a architecture/port dependent way.
377 * It may not be implemented or some ports.
378 * @note The default failure mode is to halt the system with the global
379 * @p panic_msg variable set to @p NULL.
380 */
381#define CH_DBG_ENABLE_STACK_CHECK FALSE
382
383/**
384 * @brief Debug option, stacks initialization.
385 * @details If enabled then the threads working area is filled with a byte
386 * value when a thread is created. This can be useful for the
387 * runtime measurement of the used stack.
388 *
389 * @note The default is @p FALSE.
390 */
391#define CH_DBG_FILL_THREADS FALSE
392
393/**
394 * @brief Debug option, threads profiling.
395 * @details If enabled then a field is added to the @p thread_t structure that
396 * counts the system ticks occurred while executing the thread.
397 *
398 * @note The default is @p FALSE.
399 * @note This debug option is not currently compatible with the
400 * tickless mode.
401 */
402#define CH_DBG_THREADS_PROFILING FALSE
403
404/** @} */
405
406/*===========================================================================*/
407/**
408 * @name Kernel hooks
409 * @{
410 */
411/*===========================================================================*/
412
413/**
414 * @brief Threads descriptor structure extension.
415 * @details User fields added to the end of the @p thread_t structure.
416 */
417#define CH_CFG_THREAD_EXTRA_FIELDS \
418 /* Add threads custom fields here.*/
419
420/**
421 * @brief Threads initialization hook.
422 * @details User initialization code added to the @p chThdInit() API.
423 *
424 * @note It is invoked from within @p chThdInit() and implicitly from all
425 * the threads creation APIs.
426 */
427#define CH_CFG_THREAD_INIT_HOOK(tp) { \
428 /* Add threads initialization code here.*/ \
429}
430
431/**
432 * @brief Threads finalization hook.
433 * @details User finalization code added to the @p chThdExit() API.
434 */
435#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
436 /* Add threads finalization code here.*/ \
437}
438
439/**
440 * @brief Context switch hook.
441 * @details This hook is invoked just before switching between threads.
442 */
443#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
444 /* Context switch code here.*/ \
445}
446
447/**
448 * @brief ISR enter hook.
449 */
450#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
451 /* IRQ prologue code here.*/ \
452}
453
454/**
455 * @brief ISR exit hook.
456 */
457#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
458 /* IRQ epilogue code here.*/ \
459}
460
461/**
462 * @brief Idle thread enter hook.
463 * @note This hook is invoked within a critical zone, no OS functions
464 * should be invoked from here.
465 * @note This macro can be used to activate a power saving mode.
466 */
467#define CH_CFG_IDLE_ENTER_HOOK() { \
468 /* Idle-enter code here.*/ \
469}
470
471/**
472 * @brief Idle thread leave hook.
473 * @note This hook is invoked within a critical zone, no OS functions
474 * should be invoked from here.
475 * @note This macro can be used to deactivate a power saving mode.
476 */
477#define CH_CFG_IDLE_LEAVE_HOOK() { \
478 /* Idle-leave code here.*/ \
479}
480
481/**
482 * @brief Idle Loop hook.
483 * @details This hook is continuously invoked by the idle thread loop.
484 */
485#define CH_CFG_IDLE_LOOP_HOOK() { \
486 /* Idle loop code here.*/ \
487}
488
489/**
490 * @brief System tick event hook.
491 * @details This hook is invoked in the system tick handler immediately
492 * after processing the virtual timers queue.
493 */
494#define CH_CFG_SYSTEM_TICK_HOOK() { \
495 /* System tick event code here.*/ \
496}
497
498/**
499 * @brief System halt hook.
500 * @details This hook is invoked in case to a system halting error before
501 * the system is halted.
502 */
503#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
504 /* System halt code here.*/ \
505}
506
507/**
508 * @brief Trace hook.
509 * @details This hook is invoked each time a new record is written in the
510 * trace buffer.
511 */
512#define CH_CFG_TRACE_HOOK(tep) { \
513 /* Trace code here.*/ \
514}
515
516/** @} */
517
518/*===========================================================================*/
519/* Port-specific settings (override port settings defaulted in chcore.h). */
520/*===========================================================================*/
521
522#endif /* CHCONF_H */
523
524/** @} */
diff --git a/keyboards/stm32_f103_onekey/config.h b/keyboards/stm32_f103_onekey/config.h
new file mode 100644
index 000000000..19b14fe61
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/config.h
@@ -0,0 +1,75 @@
1/*
2Copyright 2015 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21
22/* USB Device descriptor parameter */
23#define VENDOR_ID 0xFEED
24#define PRODUCT_ID 0x6464
25#define DEVICE_VER 0x0001
26/* in python2: list(u"whatever".encode('utf-16-le')) */
27/* at most 32 characters or the ugly hack in usb_main.c borks */
28#define MANUFACTURER "TMK"
29#define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', '\xc6', '\x00'
30#define PRODUCT "ChibiOS TMK test"
31#define USBSTR_PRODUCT 'C', '\x00', 'h', '\x00', 'i', '\x00', 'b', '\x00', 'i', '\x00', 'O', '\x00', 'S', '\x00', ' ', '\x00', 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', 't', '\x00', 'e', '\x00', 's', '\x00', 't', '\x00'
32#define DESCRIPTION "TMK keyboard firmware over ChibiOS"
33
34/* key matrix size */
35#define MATRIX_ROWS 1
36#define MATRIX_COLS 1
37#define DIODE_DIRECTION COL2ROW
38
39/* define if matrix has ghost */
40//#define MATRIX_HAS_GHOST
41
42/* Set 0 if debouncing isn't needed */
43#define DEBOUNCE 5
44
45/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
46#define LOCKING_SUPPORT_ENABLE
47/* Locking resynchronize hack */
48#define LOCKING_RESYNC_ENABLE
49
50/* key combination for command */
51#define IS_COMMAND() ( \
52 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
53)
54
55
56
57/*
58 * Feature disable options
59 * These options are also useful to firmware size reduction.
60 */
61
62/* disable debug print */
63//#define NO_DEBUG
64
65/* disable print */
66//#define NO_PRINT
67
68/* disable action features */
69//#define NO_ACTION_LAYER
70//#define NO_ACTION_TAPPING
71//#define NO_ACTION_ONESHOT
72//#define NO_ACTION_MACRO
73//#define NO_ACTION_FUNCTION
74
75#endif
diff --git a/keyboards/stm32_f103_onekey/flash.sh b/keyboards/stm32_f103_onekey/flash.sh
new file mode 100755
index 000000000..15501dfa5
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/flash.sh
@@ -0,0 +1,2 @@
1#!/bin/bash
2Arduino_STM32_usb_hid/tools/linux/maple_upload ttyACM0 2 1EAF:0003 build/ch.bin
diff --git a/keyboards/stm32_f103_onekey/halconf.h b/keyboards/stm32_f103_onekey/halconf.h
new file mode 100644
index 000000000..1a450d632
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/halconf.h
@@ -0,0 +1,353 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/halconf.h
19 * @brief HAL configuration header.
20 * @details HAL configuration file, this file allows to enable or disable the
21 * various device drivers from your application. You may also use
22 * this file in order to override the device drivers default settings.
23 *
24 * @addtogroup HAL_CONF
25 * @{
26 */
27
28#ifndef _HALCONF_H_
29#define _HALCONF_H_
30
31#include "mcuconf.h"
32
33/**
34 * @brief Enables the PAL subsystem.
35 */
36#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
37#define HAL_USE_PAL TRUE
38#endif
39
40/**
41 * @brief Enables the ADC subsystem.
42 */
43#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
44#define HAL_USE_ADC FALSE
45#endif
46
47/**
48 * @brief Enables the CAN subsystem.
49 */
50#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
51#define HAL_USE_CAN FALSE
52#endif
53
54/**
55 * @brief Enables the DAC subsystem.
56 */
57#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
58#define HAL_USE_DAC FALSE
59#endif
60
61/**
62 * @brief Enables the EXT subsystem.
63 */
64#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
65#define HAL_USE_EXT FALSE
66#endif
67
68/**
69 * @brief Enables the GPT subsystem.
70 */
71#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
72#define HAL_USE_GPT FALSE
73#endif
74
75/**
76 * @brief Enables the I2C subsystem.
77 */
78#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
79#define HAL_USE_I2C FALSE
80#endif
81
82/**
83 * @brief Enables the I2S subsystem.
84 */
85#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
86#define HAL_USE_I2S FALSE
87#endif
88
89/**
90 * @brief Enables the ICU subsystem.
91 */
92#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
93#define HAL_USE_ICU FALSE
94#endif
95
96/**
97 * @brief Enables the MAC subsystem.
98 */
99#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
100#define HAL_USE_MAC FALSE
101#endif
102
103/**
104 * @brief Enables the MMC_SPI subsystem.
105 */
106#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
107#define HAL_USE_MMC_SPI FALSE
108#endif
109
110/**
111 * @brief Enables the PWM subsystem.
112 */
113#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
114#define HAL_USE_PWM FALSE
115#endif
116
117/**
118 * @brief Enables the RTC subsystem.
119 */
120#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
121#define HAL_USE_RTC FALSE
122#endif
123
124/**
125 * @brief Enables the SDC subsystem.
126 */
127#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
128#define HAL_USE_SDC FALSE
129#endif
130
131/**
132 * @brief Enables the SERIAL subsystem.
133 */
134#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
135#define HAL_USE_SERIAL FALSE
136#endif
137
138/**
139 * @brief Enables the SERIAL over USB subsystem.
140 */
141#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
142#define HAL_USE_SERIAL_USB FALSE
143#endif
144
145/**
146 * @brief Enables the SPI subsystem.
147 */
148#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
149#define HAL_USE_SPI FALSE
150#endif
151
152/**
153 * @brief Enables the UART subsystem.
154 */
155#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
156#define HAL_USE_UART FALSE
157#endif
158
159/**
160 * @brief Enables the USB subsystem.
161 */
162#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
163#define HAL_USE_USB TRUE
164#endif
165
166/**
167 * @brief Enables the WDG subsystem.
168 */
169#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)
170#define HAL_USE_WDG FALSE
171#endif
172
173/*===========================================================================*/
174/* ADC driver related settings. */
175/*===========================================================================*/
176
177/**
178 * @brief Enables synchronous APIs.
179 * @note Disabling this option saves both code and data space.
180 */
181#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__)
182#define ADC_USE_WAIT TRUE
183#endif
184
185/**
186 * @brief Enables the @p adcAcquireBus() and @p adcReleaseBus() APIs.
187 * @note Disabling this option saves both code and data space.
188 */
189#if !defined(ADC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
190#define ADC_USE_MUTUAL_EXCLUSION TRUE
191#endif
192
193/*===========================================================================*/
194/* CAN driver related settings. */
195/*===========================================================================*/
196
197/**
198 * @brief Sleep mode related APIs inclusion switch.
199 */
200#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__)
201#define CAN_USE_SLEEP_MODE TRUE
202#endif
203
204/*===========================================================================*/
205/* I2C driver related settings. */
206/*===========================================================================*/
207
208/**
209 * @brief Enables the mutual exclusion APIs on the I2C bus.
210 */
211#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
212#define I2C_USE_MUTUAL_EXCLUSION TRUE
213#endif
214
215/*===========================================================================*/
216/* MAC driver related settings. */
217/*===========================================================================*/
218
219/**
220 * @brief Enables an event sources for incoming packets.
221 */
222#if !defined(MAC_USE_ZERO_COPY) || defined(__DOXYGEN__)
223#define MAC_USE_ZERO_COPY FALSE
224#endif
225
226/**
227 * @brief Enables an event sources for incoming packets.
228 */
229#if !defined(MAC_USE_EVENTS) || defined(__DOXYGEN__)
230#define MAC_USE_EVENTS TRUE
231#endif
232
233/*===========================================================================*/
234/* MMC_SPI driver related settings. */
235/*===========================================================================*/
236
237/**
238 * @brief Delays insertions.
239 * @details If enabled this options inserts delays into the MMC waiting
240 * routines releasing some extra CPU time for the threads with
241 * lower priority, this may slow down the driver a bit however.
242 * This option is recommended also if the SPI driver does not
243 * use a DMA channel and heavily loads the CPU.
244 */
245#if !defined(MMC_NICE_WAITING) || defined(__DOXYGEN__)
246#define MMC_NICE_WAITING TRUE
247#endif
248
249/*===========================================================================*/
250/* SDC driver related settings. */
251/*===========================================================================*/
252
253/**
254 * @brief Number of initialization attempts before rejecting the card.
255 * @note Attempts are performed at 10mS intervals.
256 */
257#if !defined(SDC_INIT_RETRY) || defined(__DOXYGEN__)
258#define SDC_INIT_RETRY 100
259#endif
260
261/**
262 * @brief Include support for MMC cards.
263 * @note MMC support is not yet implemented so this option must be kept
264 * at @p FALSE.
265 */
266#if !defined(SDC_MMC_SUPPORT) || defined(__DOXYGEN__)
267#define SDC_MMC_SUPPORT FALSE
268#endif
269
270/**
271 * @brief Delays insertions.
272 * @details If enabled this options inserts delays into the MMC waiting
273 * routines releasing some extra CPU time for the threads with
274 * lower priority, this may slow down the driver a bit however.
275 */
276#if !defined(SDC_NICE_WAITING) || defined(__DOXYGEN__)
277#define SDC_NICE_WAITING TRUE
278#endif
279
280/*===========================================================================*/
281/* SERIAL driver related settings. */
282/*===========================================================================*/
283
284/**
285 * @brief Default bit rate.
286 * @details Configuration parameter, this is the baud rate selected for the
287 * default configuration.
288 */
289#if !defined(SERIAL_DEFAULT_BITRATE) || defined(__DOXYGEN__)
290#define SERIAL_DEFAULT_BITRATE 38400
291#endif
292
293/**
294 * @brief Serial buffers size.
295 * @details Configuration parameter, you can change the depth of the queue
296 * buffers depending on the requirements of your application.
297 * @note The default is 64 bytes for both the transmission and receive
298 * buffers.
299 */
300#if !defined(SERIAL_BUFFERS_SIZE) || defined(__DOXYGEN__)
301#define SERIAL_BUFFERS_SIZE 16
302#endif
303
304/*===========================================================================*/
305/* SERIAL_USB driver related setting. */
306/*===========================================================================*/
307
308/**
309 * @brief Serial over USB buffers size.
310 * @details Configuration parameter, the buffer size must be a multiple of
311 * the USB data endpoint maximum packet size.
312 * @note The default is 64 bytes for both the transmission and receive
313 * buffers.
314 */
315#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
316#define SERIAL_USB_BUFFERS_SIZE 256
317#endif
318
319/*===========================================================================*/
320/* SPI driver related settings. */
321/*===========================================================================*/
322
323/**
324 * @brief Enables synchronous APIs.
325 * @note Disabling this option saves both code and data space.
326 */
327#if !defined(SPI_USE_WAIT) || defined(__DOXYGEN__)
328#define SPI_USE_WAIT TRUE
329#endif
330
331/**
332 * @brief Enables the @p spiAcquireBus() and @p spiReleaseBus() APIs.
333 * @note Disabling this option saves both code and data space.
334 */
335#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
336#define SPI_USE_MUTUAL_EXCLUSION TRUE
337#endif
338
339/*===========================================================================*/
340/* USB driver related settings. */
341/*===========================================================================*/
342
343/**
344 * @brief Enables synchronous APIs.
345 * @note Disabling this option saves both code and data space.
346 */
347#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
348#define USB_USE_WAIT TRUE
349#endif
350
351#endif /* _HALCONF_H_ */
352
353/** @} */
diff --git a/keyboards/stm32_f103_onekey/keymaps/default/keymap.c b/keyboards/stm32_f103_onekey/keymaps/default/keymap.c
new file mode 100644
index 000000000..c3b0f0840
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/keymaps/default/keymap.c
@@ -0,0 +1,25 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "stm32_f103_onekey.h"
19
20const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
21 {{KC_CAPS}}, // test with KC_CAPS, KC_A, KC_BTLD
22};
23
24const uint16_t fn_actions[] = {
25};
diff --git a/keyboards/stm32_f103_onekey/ld/STM32F103x8_stm32duino_bootloader.ld b/keyboards/stm32_f103_onekey/ld/STM32F103x8_stm32duino_bootloader.ld
new file mode 100644
index 000000000..00613328e
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/ld/STM32F103x8_stm32duino_bootloader.ld
@@ -0,0 +1,88 @@
1/*
2 ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/*
18 * ST32F103xB memory setup for use with the maplemini bootloader.
19 * You will have to
20 * #define CORTEX_VTOR_INIT 0x5000
21 * in your projects chconf.h
22 */
23MEMORY
24{
25 flash0 : org = 0x08002000, len = 128k - 0x2000
26 flash1 : org = 0x00000000, len = 0
27 flash2 : org = 0x00000000, len = 0
28 flash3 : org = 0x00000000, len = 0
29 flash4 : org = 0x00000000, len = 0
30 flash5 : org = 0x00000000, len = 0
31 flash6 : org = 0x00000000, len = 0
32 flash7 : org = 0x00000000, len = 0
33 ram0 : org = 0x20000000, len = 20k
34 ram1 : org = 0x00000000, len = 0
35 ram2 : org = 0x00000000, len = 0
36 ram3 : org = 0x00000000, len = 0
37 ram4 : org = 0x00000000, len = 0
38 ram5 : org = 0x00000000, len = 0
39 ram6 : org = 0x00000000, len = 0
40 ram7 : org = 0x00000000, len = 0
41}
42
43/* For each data/text section two region are defined, a virtual region
44 and a load region (_LMA suffix).*/
45
46/* Flash region to be used for exception vectors.*/
47REGION_ALIAS("VECTORS_FLASH", flash0);
48REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
49
50/* Flash region to be used for constructors and destructors.*/
51REGION_ALIAS("XTORS_FLASH", flash0);
52REGION_ALIAS("XTORS_FLASH_LMA", flash0);
53
54/* Flash region to be used for code text.*/
55REGION_ALIAS("TEXT_FLASH", flash0);
56REGION_ALIAS("TEXT_FLASH_LMA", flash0);
57
58/* Flash region to be used for read only data.*/
59REGION_ALIAS("RODATA_FLASH", flash0);
60REGION_ALIAS("RODATA_FLASH_LMA", flash0);
61
62/* Flash region to be used for various.*/
63REGION_ALIAS("VARIOUS_FLASH", flash0);
64REGION_ALIAS("VARIOUS_FLASH_LMA", flash0);
65
66/* Flash region to be used for RAM(n) initialization data.*/
67REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0);
68
69/* RAM region to be used for Main stack. This stack accommodates the processing
70 of all exceptions and interrupts.*/
71REGION_ALIAS("MAIN_STACK_RAM", ram0);
72
73/* RAM region to be used for the process stack. This is the stack used by
74 the main() function.*/
75REGION_ALIAS("PROCESS_STACK_RAM", ram0);
76
77/* RAM region to be used for data segment.*/
78REGION_ALIAS("DATA_RAM", ram0);
79REGION_ALIAS("DATA_RAM_LMA", flash0);
80
81/* RAM region to be used for BSS segment.*/
82REGION_ALIAS("BSS_RAM", ram0);
83
84/* RAM region to be used for the default heap.*/
85REGION_ALIAS("HEAP_RAM", ram0);
86
87/* Generic rules inclusion.*/
88INCLUDE rules.ld
diff --git a/keyboards/stm32_f103_onekey/led.c b/keyboards/stm32_f103_onekey/led.c
new file mode 100644
index 000000000..f5c55f7d9
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/led.c
@@ -0,0 +1,43 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "hal.h"
19#include "led.h"
20
21
22void led_set(uint8_t usb_led)
23{
24 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
25 /* generic STM32F103C8T6 board */
26#ifdef BOARD_GENERIC_STM32_F103
27 palClearPad(GPIOC, 13);
28#endif
29 /* Maple Mini */
30#ifdef BOARD_MAPLEMINI_STM32_F103
31 palSetPad(GPIOB, 1);
32#endif
33 } else {
34 /* generic STM32F103C8T6 board */
35#ifdef BOARD_GENERIC_STM32_F103
36 palSetPad(GPIOC, 13);
37#endif
38 /* Maple Mini */
39#ifdef BOARD_MAPLEMINI_STM32_F103
40 palClearPad(GPIOB,1);
41#endif
42 }
43}
diff --git a/keyboards/stm32_f103_onekey/matrix.c b/keyboards/stm32_f103_onekey/matrix.c
new file mode 100644
index 000000000..ea9d8d057
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/matrix.c
@@ -0,0 +1,177 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "ch.h"
19#include "hal.h"
20
21/*
22 * scan matrix
23 */
24#include "print.h"
25#include "debug.h"
26#include "util.h"
27#include "matrix.h"
28#include "wait.h"
29
30#ifndef DEBOUNCE
31# define DEBOUNCE 5
32#endif
33static uint8_t debouncing = DEBOUNCE;
34
35/* matrix state(1:on, 0:off) */
36static matrix_row_t matrix[MATRIX_ROWS];
37static matrix_row_t matrix_debouncing[MATRIX_ROWS];
38
39static matrix_row_t read_cols(void);
40static void init_cols(void);
41static void unselect_rows(void);
42static void select_row(uint8_t row);
43
44
45inline
46uint8_t matrix_rows(void)
47{
48 return MATRIX_ROWS;
49}
50
51inline
52uint8_t matrix_cols(void)
53{
54 return MATRIX_COLS;
55}
56
57/* generic STM32F103C8T6 board */
58#ifdef BOARD_GENERIC_STM32_F103
59#define LED_ON() do { palClearPad(GPIOC, GPIOC_LED) ;} while (0)
60#define LED_OFF() do { palSetPad(GPIOC, GPIOC_LED); } while (0)
61#define LED_TGL() do { palTogglePad(GPIOC, GPIOC_LED); } while (0)
62#endif
63
64/* Maple Mini */
65#ifdef BOARD_MAPLEMINI_STM32_F103
66#define LED_ON() do { palSetPad(GPIOB, 1) ;} while (0)
67#define LED_OFF() do { palClearPad(GPIOB, 1); } while (0)
68#define LED_TGL() do { palTogglePad(GPIOB, 1); } while (0)
69#endif
70
71void matrix_init(void)
72{
73 // initialize row and col
74 unselect_rows();
75 init_cols();
76
77 // initialize matrix state: all keys off
78 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
79 matrix[i] = 0;
80 matrix_debouncing[i] = 0;
81 }
82
83 //debug
84 debug_matrix = true;
85 LED_ON();
86 wait_ms(500);
87 LED_OFF();
88}
89
90uint8_t matrix_scan(void)
91{
92 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
93 select_row(i);
94 wait_us(30); // without this wait read unstable value.
95 matrix_row_t cols = read_cols();
96 if (matrix_debouncing[i] != cols) {
97 matrix_debouncing[i] = cols;
98 if (debouncing) {
99 debug("bounce!: "); debug_hex(debouncing); debug("\n");
100 }
101 debouncing = DEBOUNCE;
102 }
103 unselect_rows();
104 }
105
106 if (debouncing) {
107 if (--debouncing) {
108 wait_ms(1);
109 } else {
110 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
111 matrix[i] = matrix_debouncing[i];
112 }
113 }
114 }
115
116 return 1;
117}
118
119inline
120bool matrix_is_on(uint8_t row, uint8_t col)
121{
122 return (matrix[row] & ((matrix_row_t)1<<col));
123}
124
125inline
126matrix_row_t matrix_get_row(uint8_t row)
127{
128 return matrix[row];
129}
130
131void matrix_print(void)
132{
133 print("\nr/c 0123456789ABCDEF\n");
134 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
135 phex(row); print(": ");
136 pbin_reverse16(matrix_get_row(row));
137 print("\n");
138 }
139}
140
141/* Column pin configuration
142 */
143static void init_cols(void)
144{
145#ifdef BOARD_MAPLEMINI_STM32_F103
146 // don't need pullup/down, since it's pulled down in hardware
147 palSetPadMode(GPIOB, 8, PAL_MODE_INPUT);
148#else
149 palSetPadMode(GPIOB, 8, PAL_MODE_INPUT_PULLDOWN);
150#endif
151}
152
153/* Returns status of switches(1:on, 0:off) */
154static matrix_row_t read_cols(void)
155{
156 return ((palReadPad(GPIOB, 8)==PAL_LOW) ? 0 : (1<<0));
157 // | ((palReadPad(...)==PAL_HIGH) ? 0 : (1<<1))
158}
159
160/* Row pin configuration
161 */
162static void unselect_rows(void)
163{
164 // palSetPadMode(GPIOA, GPIOA_PIN10, PAL_MODE_INPUT); // hi-Z
165}
166
167static void select_row(uint8_t row)
168{
169 (void)row;
170 // Output low to select
171 // switch (row) {
172 // case 0:
173 // palSetPadMode(GPIOA, GPIOA_PIN10, PAL_MODE_OUTPUT_PUSHPULL);
174 // palSetPad(GPIOA, GPIOA_PIN10, PAL_LOW);
175 // break;
176 // }
177}
diff --git a/keyboards/stm32_f103_onekey/mcuconf.h b/keyboards/stm32_f103_onekey/mcuconf.h
new file mode 100644
index 000000000..626332a6a
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/mcuconf.h
@@ -0,0 +1,209 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef _MCUCONF_H_
18#define _MCUCONF_H_
19
20#define STM32F103_MCUCONF
21
22/*
23 * STM32F103 drivers configuration.
24 * The following settings override the default settings present in
25 * the various device driver implementation headers.
26 * Note that the settings for each driver only have effect if the whole
27 * driver is enabled in halconf.h.
28 *
29 * IRQ priorities:
30 * 15...0 Lowest...Highest.
31 *
32 * DMA priorities:
33 * 0...3 Lowest...Highest.
34 */
35
36/*
37 * HAL driver system settings.
38 */
39#define STM32_NO_INIT FALSE
40#define STM32_HSI_ENABLED TRUE
41#define STM32_LSI_ENABLED FALSE
42#define STM32_HSE_ENABLED TRUE
43#define STM32_LSE_ENABLED FALSE
44#define STM32_SW STM32_SW_PLL
45#define STM32_PLLSRC STM32_PLLSRC_HSE
46#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
47#define STM32_PLLMUL_VALUE 9
48#define STM32_HPRE STM32_HPRE_DIV1
49#define STM32_PPRE1 STM32_PPRE1_DIV2
50#define STM32_PPRE2 STM32_PPRE2_DIV2
51#define STM32_ADCPRE STM32_ADCPRE_DIV4
52#define STM32_USB_CLOCK_REQUIRED TRUE
53#define STM32_USBPRE STM32_USBPRE_DIV1P5
54#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
55#define STM32_RTCSEL STM32_RTCSEL_HSEDIV
56#define STM32_PVD_ENABLE FALSE
57#define STM32_PLS STM32_PLS_LEV0
58
59/*
60 * ADC driver system settings.
61 */
62#define STM32_ADC_USE_ADC1 FALSE
63#define STM32_ADC_ADC1_DMA_PRIORITY 2
64#define STM32_ADC_ADC1_IRQ_PRIORITY 6
65
66/*
67 * CAN driver system settings.
68 */
69#define STM32_CAN_USE_CAN1 FALSE
70#define STM32_CAN_CAN1_IRQ_PRIORITY 11
71
72/*
73 * EXT driver system settings.
74 */
75#define STM32_EXT_EXTI0_IRQ_PRIORITY 6
76#define STM32_EXT_EXTI1_IRQ_PRIORITY 6
77#define STM32_EXT_EXTI2_IRQ_PRIORITY 6
78#define STM32_EXT_EXTI3_IRQ_PRIORITY 6
79#define STM32_EXT_EXTI4_IRQ_PRIORITY 6
80#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6
81#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6
82#define STM32_EXT_EXTI16_IRQ_PRIORITY 6
83#define STM32_EXT_EXTI17_IRQ_PRIORITY 6
84#define STM32_EXT_EXTI18_IRQ_PRIORITY 6
85#define STM32_EXT_EXTI19_IRQ_PRIORITY 6
86
87/*
88 * GPT driver system settings.
89 */
90#define STM32_GPT_USE_TIM1 FALSE
91#define STM32_GPT_USE_TIM2 FALSE
92#define STM32_GPT_USE_TIM3 FALSE
93#define STM32_GPT_USE_TIM4 FALSE
94#define STM32_GPT_USE_TIM5 FALSE
95#define STM32_GPT_USE_TIM8 FALSE
96#define STM32_GPT_TIM1_IRQ_PRIORITY 7
97#define STM32_GPT_TIM2_IRQ_PRIORITY 7
98#define STM32_GPT_TIM3_IRQ_PRIORITY 7
99#define STM32_GPT_TIM4_IRQ_PRIORITY 7
100#define STM32_GPT_TIM5_IRQ_PRIORITY 7
101#define STM32_GPT_TIM8_IRQ_PRIORITY 7
102
103/*
104 * I2C driver system settings.
105 */
106#define STM32_I2C_USE_I2C1 FALSE
107#define STM32_I2C_USE_I2C2 FALSE
108#define STM32_I2C_BUSY_TIMEOUT 50
109#define STM32_I2C_I2C1_IRQ_PRIORITY 5
110#define STM32_I2C_I2C2_IRQ_PRIORITY 5
111#define STM32_I2C_I2C1_DMA_PRIORITY 3
112#define STM32_I2C_I2C2_DMA_PRIORITY 3
113#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
114
115/*
116 * ICU driver system settings.
117 */
118#define STM32_ICU_USE_TIM1 FALSE
119#define STM32_ICU_USE_TIM2 FALSE
120#define STM32_ICU_USE_TIM3 FALSE
121#define STM32_ICU_USE_TIM4 FALSE
122#define STM32_ICU_USE_TIM5 FALSE
123#define STM32_ICU_USE_TIM8 FALSE
124#define STM32_ICU_TIM1_IRQ_PRIORITY 7
125#define STM32_ICU_TIM2_IRQ_PRIORITY 7
126#define STM32_ICU_TIM3_IRQ_PRIORITY 7
127#define STM32_ICU_TIM4_IRQ_PRIORITY 7
128#define STM32_ICU_TIM5_IRQ_PRIORITY 7
129#define STM32_ICU_TIM8_IRQ_PRIORITY 7
130
131/*
132 * PWM driver system settings.
133 */
134#define STM32_PWM_USE_ADVANCED FALSE
135#define STM32_PWM_USE_TIM1 FALSE
136#define STM32_PWM_USE_TIM2 FALSE
137#define STM32_PWM_USE_TIM3 FALSE
138#define STM32_PWM_USE_TIM4 FALSE
139#define STM32_PWM_USE_TIM5 FALSE
140#define STM32_PWM_USE_TIM8 FALSE
141#define STM32_PWM_TIM1_IRQ_PRIORITY 7
142#define STM32_PWM_TIM2_IRQ_PRIORITY 7
143#define STM32_PWM_TIM3_IRQ_PRIORITY 7
144#define STM32_PWM_TIM4_IRQ_PRIORITY 7
145#define STM32_PWM_TIM5_IRQ_PRIORITY 7
146#define STM32_PWM_TIM8_IRQ_PRIORITY 7
147
148/*
149 * RTC driver system settings.
150 */
151#define STM32_RTC_IRQ_PRIORITY 15
152
153/*
154 * SERIAL driver system settings.
155 */
156#define STM32_SERIAL_USE_USART1 FALSE
157#define STM32_SERIAL_USE_USART2 FALSE
158#define STM32_SERIAL_USE_USART3 FALSE
159#define STM32_SERIAL_USE_UART4 FALSE
160#define STM32_SERIAL_USE_UART5 FALSE
161#define STM32_SERIAL_USART1_PRIORITY 12
162#define STM32_SERIAL_USART2_PRIORITY 12
163#define STM32_SERIAL_USART3_PRIORITY 12
164#define STM32_SERIAL_UART4_PRIORITY 12
165#define STM32_SERIAL_UART5_PRIORITY 12
166
167/*
168 * SPI driver system settings.
169 */
170#define STM32_SPI_USE_SPI1 FALSE
171#define STM32_SPI_USE_SPI2 FALSE
172#define STM32_SPI_USE_SPI3 FALSE
173#define STM32_SPI_SPI1_DMA_PRIORITY 1
174#define STM32_SPI_SPI2_DMA_PRIORITY 1
175#define STM32_SPI_SPI3_DMA_PRIORITY 1
176#define STM32_SPI_SPI1_IRQ_PRIORITY 10
177#define STM32_SPI_SPI2_IRQ_PRIORITY 10
178#define STM32_SPI_SPI3_IRQ_PRIORITY 10
179#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
180
181/*
182 * ST driver system settings.
183 */
184#define STM32_ST_IRQ_PRIORITY 8
185#define STM32_ST_USE_TIMER 2
186
187/*
188 * UART driver system settings.
189 */
190#define STM32_UART_USE_USART1 FALSE
191#define STM32_UART_USE_USART2 FALSE
192#define STM32_UART_USE_USART3 FALSE
193#define STM32_UART_USART1_IRQ_PRIORITY 12
194#define STM32_UART_USART2_IRQ_PRIORITY 12
195#define STM32_UART_USART3_IRQ_PRIORITY 12
196#define STM32_UART_USART1_DMA_PRIORITY 0
197#define STM32_UART_USART2_DMA_PRIORITY 0
198#define STM32_UART_USART3_DMA_PRIORITY 0
199#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
200
201/*
202 * USB driver system settings.
203 */
204#define STM32_USB_USE_USB1 TRUE
205#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
206#define STM32_USB_USB1_HP_IRQ_PRIORITY 13
207#define STM32_USB_USB1_LP_IRQ_PRIORITY 14
208
209#endif /* _MCUCONF_H_ */
diff --git a/keyboards/stm32_f103_onekey/stm32_f103_onekey.c b/keyboards/stm32_f103_onekey/stm32_f103_onekey.c
new file mode 100644
index 000000000..7fa99bb28
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/stm32_f103_onekey.c
@@ -0,0 +1 @@
#include "stm32_f103_onekey.h"
diff --git a/keyboards/stm32_f103_onekey/stm32_f103_onekey.h b/keyboards/stm32_f103_onekey/stm32_f103_onekey.h
new file mode 100644
index 000000000..e4d0dd9c4
--- /dev/null
+++ b/keyboards/stm32_f103_onekey/stm32_f103_onekey.h
@@ -0,0 +1,4 @@
1#ifndef STM32_F103_ONEKEY_H
2#define STM32_F103_ONEKEY_H
3#include "quantum.h"
4#endif
diff --git a/keyboards/teensy_lc_onekey/Makefile b/keyboards/teensy_lc_onekey/Makefile
new file mode 100644
index 000000000..064e61815
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/Makefile
@@ -0,0 +1,62 @@
1# project specific files
2SRC = matrix.c \
3 led.c
4
5## chip/board settings
6# - the next two should match the directories in
7# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
8# - For Teensies, FAMILY = KINETIS and SERIES is either
9# KL2x (LC) or K20x (3.0,3.1,3.2).
10MCU_FAMILY = KINETIS
11MCU_SERIES = KL2x
12
13# Linker script to use
14# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
15# or <this_dir>/ld/
16# - NOTE: a custom ld script is needed for EEPROM on Teensy LC
17# - LDSCRIPT =
18# - MKL26Z64 for Teensy LC
19# - MK20DX128 for Teensy 3.0
20# - MK20DX256 for Teensy 3.1 and 3.2
21MCU_LDSCRIPT = MKL26Z64
22
23# Startup code to use
24# - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
25# - STARTUP =
26# - kl2x for Teensy LC
27# - k20x5 for Teensy 3.0
28# - k20x7 for Teensy 3.1 and 3.2
29MCU_STARTUP = kl2x
30
31# Board: it should exist either in <chibios>/os/hal/boards/
32# or <this_dir>/boards
33# - BOARD =
34# - PJRC_TEENSY_LC for Teensy LC
35# - PJRC_TEENSY_3 for Teensy 3.0
36# - PJRC_TEENSY_3_1 for Teensy 3.1 or 3.2
37BOARD = PJRC_TEENSY_LC
38
39# Cortex version
40# Teensy LC is cortex-m0plus; Teensy 3.x are cortex-m4
41MCU = cortex-m0plus
42
43# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
44# I.e. 6 for Teensy LC; 7 for Teensy 3.x
45ARMV = 6
46
47# Build Options
48# comment out to disable the options.
49#
50BOOTMAGIC_ENABLE ?= yes # Virtual DIP switch configuration
51## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
52MOUSEKEY_ENABLE ?= yes # Mouse keys
53EXTRAKEY_ENABLE ?= yes # Audio control and System control
54CONSOLE_ENABLE ?= yes # Console for debug
55COMMAND_ENABLE ?= yes # Commands for debug and configuration
56SLEEP_LED_ENABLE ?= yes # Breathing sleep LED during USB suspend
57NKRO_ENABLE ?= yes # USB Nkey Rollover
58CUSTOM_MATRIX ?= yes # Custom matrix file
59
60ifndef QUANTUM_DIR
61 include ../../Makefile
62endif
diff --git a/keyboards/teensy_lc_onekey/Makefile.3.0 b/keyboards/teensy_lc_onekey/Makefile.3.0
new file mode 100644
index 000000000..dbf12c363
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/Makefile.3.0
@@ -0,0 +1,77 @@
1# Target file name (without extension).
2PROJECT = ch
3
4# Directory common source files exist
5TMK_DIR = ../../tmk_core
6
7# Directory keyboard dependent files exist
8TARGET_DIR = .
9
10# project specific files
11SRC = matrix.c \
12 led.c
13
14ifdef KEYMAP
15 SRC := keymap_$(KEYMAP).c $(SRC)
16else
17 SRC := keymap_plain.c $(SRC)
18endif
19
20CONFIG_H = config.h
21
22## chip/board settings
23# - the next two should match the directories in
24# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
25# - For Teensies, FAMILY = KINETIS and SERIES is either
26# KL2x (LC) or K20x (3.0,3.1,3.2).
27MCU_FAMILY = KINETIS
28MCU_SERIES = K20x
29
30# Linker script to use
31# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
32# or <this_dir>/ld/
33# - NOTE: a custom ld script is needed for EEPROM on Teensy LC
34# - LDSCRIPT =
35# - MKL26Z64 for Teensy LC
36# - MK20DX128 for Teensy 3.0
37# - MK20DX256 for Teensy 3.1 and 3.2
38MCU_LDSCRIPT = MK20DX128
39
40# Startup code to use
41# - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
42# - STARTUP =
43# - kl2x for Teensy LC
44# - k20x5 for Teensy 3.0
45# - k20x7 for Teensy 3.1 and 3.2
46MCU_STARTUP = k20x5
47
48# Board: it should exist either in <chibios>/os/hal/boards/
49# or <this_dir>/boards
50# - BOARD =
51# - PJRC_TEENSY_LC for Teensy LC
52# - PJRC_TEENSY_3 for Teensy 3.0
53# - PJRC_TEENSY_3_1 for Teensy 3.1 or 3.2
54BOARD = PJRC_TEENSY_3
55
56# Cortex version
57# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4
58MCU = cortex-m4
59
60# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
61# I.e. 6 for Teensy LC; 7 for Teensy 3.x
62ARMV = 7
63
64# Build Options
65# comment out to disable the options.
66#
67BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
68## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
69MOUSEKEY_ENABLE = yes # Mouse keys
70EXTRAKEY_ENABLE = yes # Audio control and System control
71CONSOLE_ENABLE = yes # Console for debug
72COMMAND_ENABLE = yes # Commands for debug and configuration
73SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
74NKRO_ENABLE = yes # USB Nkey Rollover
75
76include $(TMK_DIR)/tool/chibios/common.mk
77include $(TMK_DIR)/tool/chibios/chibios.mk
diff --git a/keyboards/teensy_lc_onekey/Makefile.3.2 b/keyboards/teensy_lc_onekey/Makefile.3.2
new file mode 100644
index 000000000..41bfa41a0
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/Makefile.3.2
@@ -0,0 +1,77 @@
1# Target file name (without extension).
2PROJECT = ch
3
4# Directory common source files exist
5TMK_DIR = ../../tmk_core
6
7# Directory keyboard dependent files exist
8TARGET_DIR = .
9
10# project specific files
11SRC = matrix.c \
12 led.c
13
14ifdef KEYMAP
15 SRC := keymap_$(KEYMAP).c $(SRC)
16else
17 SRC := keymap_plain.c $(SRC)
18endif
19
20CONFIG_H = config.h
21
22## chip/board settings
23# - the next two should match the directories in
24# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
25# - For Teensies, FAMILY = KINETIS and SERIES is either
26# KL2x (LC) or K20x (3.0,3.1,3.2).
27MCU_FAMILY = KINETIS
28MCU_SERIES = K20x
29
30# Linker script to use
31# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
32# or <this_dir>/ld/
33# - NOTE: a custom ld script is needed for EEPROM on Teensy LC
34# - LDSCRIPT =
35# - MKL26Z64 for Teensy LC
36# - MK20DX128 for Teensy 3.0
37# - MK20DX256 for Teensy 3.1 and 3.2
38MCU_LDSCRIPT = MK20DX256
39
40# Startup code to use
41# - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
42# - STARTUP =
43# - kl2x for Teensy LC
44# - k20x5 for Teensy 3.0
45# - k20x7 for Teensy 3.1 and 3.2
46MCU_STARTUP = k20x7
47
48# Board: it should exist either in <chibios>/os/hal/boards/
49# or <this_dir>/boards
50# - BOARD =
51# - PJRC_TEENSY_LC for Teensy LC
52# - PJRC_TEENSY_3 for Teensy 3.0
53# - PJRC_TEENSY_3_1 for Teensy 3.1 or 3.2
54BOARD = PJRC_TEENSY_3_1
55
56# Cortex version
57# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4
58MCU = cortex-m4
59
60# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
61# I.e. 6 for Teensy LC; 7 for Teensy 3.x
62ARMV = 7
63
64# Build Options
65# comment out to disable the options.
66#
67BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
68## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
69MOUSEKEY_ENABLE = yes # Mouse keys
70EXTRAKEY_ENABLE = yes # Audio control and System control
71CONSOLE_ENABLE = yes # Console for debug
72COMMAND_ENABLE = yes # Commands for debug and configuration
73SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
74NKRO_ENABLE = yes # USB Nkey Rollover
75
76include $(TMK_DIR)/tool/chibios/common.mk
77include $(TMK_DIR)/tool/chibios/chibios.mk
diff --git a/keyboards/teensy_lc_onekey/chconf.h b/keyboards/teensy_lc_onekey/chconf.h
new file mode 100644
index 000000000..cb36996c3
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/chconf.h
@@ -0,0 +1,524 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/chconf.h
19 * @brief Configuration file template.
20 * @details A copy of this file must be placed in each project directory, it
21 * contains the application specific kernel settings.
22 *
23 * @addtogroup config
24 * @details Kernel related settings and hooks.
25 * @{
26 */
27
28#ifndef CHCONF_H
29#define CHCONF_H
30
31#define _CHIBIOS_RT_CONF_
32
33/*===========================================================================*/
34/**
35 * @name System timers settings
36 * @{
37 */
38/*===========================================================================*/
39
40/**
41 * @brief System time counter resolution.
42 * @note Allowed values are 16 or 32 bits.
43 */
44#define CH_CFG_ST_RESOLUTION 32
45
46/**
47 * @brief System tick frequency.
48 * @details Frequency of the system timer that drives the system ticks. This
49 * setting also defines the system tick time unit.
50 */
51#define CH_CFG_ST_FREQUENCY 1000
52
53/**
54 * @brief Time delta constant for the tick-less mode.
55 * @note If this value is zero then the system uses the classic
56 * periodic tick. This value represents the minimum number
57 * of ticks that is safe to specify in a timeout directive.
58 * The value one is not valid, timeouts are rounded up to
59 * this value.
60 */
61#define CH_CFG_ST_TIMEDELTA 0
62
63/** @} */
64
65/*===========================================================================*/
66/**
67 * @name Kernel parameters and options
68 * @{
69 */
70/*===========================================================================*/
71
72/**
73 * @brief Round robin interval.
74 * @details This constant is the number of system ticks allowed for the
75 * threads before preemption occurs. Setting this value to zero
76 * disables the preemption for threads with equal priority and the
77 * round robin becomes cooperative. Note that higher priority
78 * threads can still preempt, the kernel is always preemptive.
79 * @note Disabling the round robin preemption makes the kernel more compact
80 * and generally faster.
81 * @note The round robin preemption is not supported in tickless mode and
82 * must be set to zero in that case.
83 */
84#define CH_CFG_TIME_QUANTUM 20
85
86/**
87 * @brief Managed RAM size.
88 * @details Size of the RAM area to be managed by the OS. If set to zero
89 * then the whole available RAM is used. The core memory is made
90 * available to the heap allocator and/or can be used directly through
91 * the simplified core memory allocator.
92 *
93 * @note In order to let the OS manage the whole RAM the linker script must
94 * provide the @p __heap_base__ and @p __heap_end__ symbols.
95 * @note Requires @p CH_CFG_USE_MEMCORE.
96 */
97#define CH_CFG_MEMCORE_SIZE 0
98
99/**
100 * @brief Idle thread automatic spawn suppression.
101 * @details When this option is activated the function @p chSysInit()
102 * does not spawn the idle thread. The application @p main()
103 * function becomes the idle thread and must implement an
104 * infinite loop.
105 */
106#define CH_CFG_NO_IDLE_THREAD FALSE
107
108/* Use __WFI in the idle thread for waiting. Does lower the power
109 * consumption. */
110#define CORTEX_ENABLE_WFI_IDLE TRUE
111
112/** @} */
113
114/*===========================================================================*/
115/**
116 * @name Performance options
117 * @{
118 */
119/*===========================================================================*/
120
121/**
122 * @brief OS optimization.
123 * @details If enabled then time efficient rather than space efficient code
124 * is used when two possible implementations exist.
125 *
126 * @note This is not related to the compiler optimization options.
127 * @note The default is @p TRUE.
128 */
129#define CH_CFG_OPTIMIZE_SPEED TRUE
130
131/** @} */
132
133/*===========================================================================*/
134/**
135 * @name Subsystem options
136 * @{
137 */
138/*===========================================================================*/
139
140/**
141 * @brief Time Measurement APIs.
142 * @details If enabled then the time measurement APIs are included in
143 * the kernel.
144 *
145 * @note The default is @p TRUE.
146 */
147#define CH_CFG_USE_TM FALSE
148
149/**
150 * @brief Threads registry APIs.
151 * @details If enabled then the registry APIs are included in the kernel.
152 *
153 * @note The default is @p TRUE.
154 */
155#define CH_CFG_USE_REGISTRY TRUE
156
157/**
158 * @brief Threads synchronization APIs.
159 * @details If enabled then the @p chThdWait() function is included in
160 * the kernel.
161 *
162 * @note The default is @p TRUE.
163 */
164#define CH_CFG_USE_WAITEXIT TRUE
165
166/**
167 * @brief Semaphores APIs.
168 * @details If enabled then the Semaphores APIs are included in the kernel.
169 *
170 * @note The default is @p TRUE.
171 */
172#define CH_CFG_USE_SEMAPHORES TRUE
173
174/**
175 * @brief Semaphores queuing mode.
176 * @details If enabled then the threads are enqueued on semaphores by
177 * priority rather than in FIFO order.
178 *
179 * @note The default is @p FALSE. Enable this if you have special
180 * requirements.
181 * @note Requires @p CH_CFG_USE_SEMAPHORES.
182 */
183#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
184
185/**
186 * @brief Mutexes APIs.
187 * @details If enabled then the mutexes APIs are included in the kernel.
188 *
189 * @note The default is @p TRUE.
190 */
191#define CH_CFG_USE_MUTEXES TRUE
192
193/**
194 * @brief Enables recursive behavior on mutexes.
195 * @note Recursive mutexes are heavier and have an increased
196 * memory footprint.
197 *
198 * @note The default is @p FALSE.
199 * @note Requires @p CH_CFG_USE_MUTEXES.
200 */
201#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
202
203/**
204 * @brief Conditional Variables APIs.
205 * @details If enabled then the conditional variables APIs are included
206 * in the kernel.
207 *
208 * @note The default is @p TRUE.
209 * @note Requires @p CH_CFG_USE_MUTEXES.
210 */
211#define CH_CFG_USE_CONDVARS TRUE
212
213/**
214 * @brief Conditional Variables APIs with timeout.
215 * @details If enabled then the conditional variables APIs with timeout
216 * specification are included in the kernel.
217 *
218 * @note The default is @p TRUE.
219 * @note Requires @p CH_CFG_USE_CONDVARS.
220 */
221#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
222
223/**
224 * @brief Events Flags APIs.
225 * @details If enabled then the event flags APIs are included in the kernel.
226 *
227 * @note The default is @p TRUE.
228 */
229#define CH_CFG_USE_EVENTS TRUE
230
231/**
232 * @brief Events Flags APIs with timeout.
233 * @details If enabled then the events APIs with timeout specification
234 * are included in the kernel.
235 *
236 * @note The default is @p TRUE.
237 * @note Requires @p CH_CFG_USE_EVENTS.
238 */
239#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
240
241/**
242 * @brief Synchronous Messages APIs.
243 * @details If enabled then the synchronous messages APIs are included
244 * in the kernel.
245 *
246 * @note The default is @p TRUE.
247 */
248#define CH_CFG_USE_MESSAGES TRUE
249
250/**
251 * @brief Synchronous Messages queuing mode.
252 * @details If enabled then messages are served by priority rather than in
253 * FIFO order.
254 *
255 * @note The default is @p FALSE. Enable this if you have special
256 * requirements.
257 * @note Requires @p CH_CFG_USE_MESSAGES.
258 */
259#define CH_CFG_USE_MESSAGES_PRIORITY FALSE
260
261/**
262 * @brief Mailboxes APIs.
263 * @details If enabled then the asynchronous messages (mailboxes) APIs are
264 * included in the kernel.
265 *
266 * @note The default is @p TRUE.
267 * @note Requires @p CH_CFG_USE_SEMAPHORES.
268 */
269#define CH_CFG_USE_MAILBOXES TRUE
270
271/**
272 * @brief Core Memory Manager APIs.
273 * @details If enabled then the core memory manager APIs are included
274 * in the kernel.
275 *
276 * @note The default is @p TRUE.
277 */
278#define CH_CFG_USE_MEMCORE TRUE
279
280/**
281 * @brief Heap Allocator APIs.
282 * @details If enabled then the memory heap allocator APIs are included
283 * in the kernel.
284 *
285 * @note The default is @p TRUE.
286 * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
287 * @p CH_CFG_USE_SEMAPHORES.
288 * @note Mutexes are recommended.
289 */
290#define CH_CFG_USE_HEAP TRUE
291
292/**
293 * @brief Memory Pools Allocator APIs.
294 * @details If enabled then the memory pools allocator APIs are included
295 * in the kernel.
296 *
297 * @note The default is @p TRUE.
298 */
299#define CH_CFG_USE_MEMPOOLS TRUE
300
301/**
302 * @brief Dynamic Threads APIs.
303 * @details If enabled then the dynamic threads creation APIs are included
304 * in the kernel.
305 *
306 * @note The default is @p TRUE.
307 * @note Requires @p CH_CFG_USE_WAITEXIT.
308 * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
309 */
310#define CH_CFG_USE_DYNAMIC TRUE
311
312/** @} */
313
314/*===========================================================================*/
315/**
316 * @name Debug options
317 * @{
318 */
319/*===========================================================================*/
320
321/**
322 * @brief Debug option, kernel statistics.
323 *
324 * @note The default is @p FALSE.
325 */
326#define CH_DBG_STATISTICS FALSE
327
328/**
329 * @brief Debug option, system state check.
330 * @details If enabled the correct call protocol for system APIs is checked
331 * at runtime.
332 *
333 * @note The default is @p FALSE.
334 */
335#define CH_DBG_SYSTEM_STATE_CHECK TRUE
336
337/**
338 * @brief Debug option, parameters checks.
339 * @details If enabled then the checks on the API functions input
340 * parameters are activated.
341 *
342 * @note The default is @p FALSE.
343 */
344#define CH_DBG_ENABLE_CHECKS TRUE
345
346/**
347 * @brief Debug option, consistency checks.
348 * @details If enabled then all the assertions in the kernel code are
349 * activated. This includes consistency checks inside the kernel,
350 * runtime anomalies and port-defined checks.
351 *
352 * @note The default is @p FALSE.
353 */
354#define CH_DBG_ENABLE_ASSERTS TRUE
355
356/**
357 * @brief Debug option, trace buffer.
358 * @details If enabled then the trace buffer is activated.
359 *
360 * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
361 */
362#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
363
364/**
365 * @brief Trace buffer entries.
366 * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
367 * different from @p CH_DBG_TRACE_MASK_DISABLED.
368 */
369#define CH_DBG_TRACE_BUFFER_SIZE 128
370
371/**
372 * @brief Debug option, stack checks.
373 * @details If enabled then a runtime stack check is performed.
374 *
375 * @note The default is @p FALSE.
376 * @note The stack check is performed in a architecture/port dependent way.
377 * It may not be implemented or some ports.
378 * @note The default failure mode is to halt the system with the global
379 * @p panic_msg variable set to @p NULL.
380 */
381#define CH_DBG_ENABLE_STACK_CHECK TRUE
382
383/**
384 * @brief Debug option, stacks initialization.
385 * @details If enabled then the threads working area is filled with a byte
386 * value when a thread is created. This can be useful for the
387 * runtime measurement of the used stack.
388 *
389 * @note The default is @p FALSE.
390 */
391#define CH_DBG_FILL_THREADS TRUE
392
393/**
394 * @brief Debug option, threads profiling.
395 * @details If enabled then a field is added to the @p thread_t structure that
396 * counts the system ticks occurred while executing the thread.
397 *
398 * @note The default is @p FALSE.
399 * @note This debug option is not currently compatible with the
400 * tickless mode.
401 */
402#define CH_DBG_THREADS_PROFILING FALSE
403
404/** @} */
405
406/*===========================================================================*/
407/**
408 * @name Kernel hooks
409 * @{
410 */
411/*===========================================================================*/
412
413/**
414 * @brief Threads descriptor structure extension.
415 * @details User fields added to the end of the @p thread_t structure.
416 */
417#define CH_CFG_THREAD_EXTRA_FIELDS \
418 /* Add threads custom fields here.*/
419
420/**
421 * @brief Threads initialization hook.
422 * @details User initialization code added to the @p chThdInit() API.
423 *
424 * @note It is invoked from within @p chThdInit() and implicitly from all
425 * the threads creation APIs.
426 */
427#define CH_CFG_THREAD_INIT_HOOK(tp) { \
428 /* Add threads initialization code here.*/ \
429}
430
431/**
432 * @brief Threads finalization hook.
433 * @details User finalization code added to the @p chThdExit() API.
434 */
435#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
436 /* Add threads finalization code here.*/ \
437}
438
439/**
440 * @brief Context switch hook.
441 * @details This hook is invoked just before switching between threads.
442 */
443#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
444 /* Context switch code here.*/ \
445}
446
447/**
448 * @brief ISR enter hook.
449 */
450#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
451 /* IRQ prologue code here.*/ \
452}
453
454/**
455 * @brief ISR exit hook.
456 */
457#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
458 /* IRQ epilogue code here.*/ \
459}
460
461/**
462 * @brief Idle thread enter hook.
463 * @note This hook is invoked within a critical zone, no OS functions
464 * should be invoked from here.
465 * @note This macro can be used to activate a power saving mode.
466 */
467#define CH_CFG_IDLE_ENTER_HOOK() { \
468 /* Idle-enter code here.*/ \
469}
470
471/**
472 * @brief Idle thread leave hook.
473 * @note This hook is invoked within a critical zone, no OS functions
474 * should be invoked from here.
475 * @note This macro can be used to deactivate a power saving mode.
476 */
477#define CH_CFG_IDLE_LEAVE_HOOK() { \
478 /* Idle-leave code here.*/ \
479}
480
481/**
482 * @brief Idle Loop hook.
483 * @details This hook is continuously invoked by the idle thread loop.
484 */
485#define CH_CFG_IDLE_LOOP_HOOK() { \
486 /* Idle loop code here.*/ \
487}
488
489/**
490 * @brief System tick event hook.
491 * @details This hook is invoked in the system tick handler immediately
492 * after processing the virtual timers queue.
493 */
494#define CH_CFG_SYSTEM_TICK_HOOK() { \
495 /* System tick event code here.*/ \
496}
497
498/**
499 * @brief System halt hook.
500 * @details This hook is invoked in case to a system halting error before
501 * the system is halted.
502 */
503#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
504 /* System halt code here.*/ \
505}
506
507/**
508 * @brief Trace hook.
509 * @details This hook is invoked each time a new record is written in the
510 * trace buffer.
511 */
512#define CH_CFG_TRACE_HOOK(tep) { \
513 /* Trace code here.*/ \
514}
515
516/** @} */
517
518/*===========================================================================*/
519/* Port-specific settings (override port settings defaulted in chcore.h). */
520/*===========================================================================*/
521
522#endif /* CHCONF_H */
523
524/** @} */
diff --git a/keyboards/teensy_lc_onekey/config.h b/keyboards/teensy_lc_onekey/config.h
new file mode 100644
index 000000000..19b14fe61
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/config.h
@@ -0,0 +1,75 @@
1/*
2Copyright 2015 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef CONFIG_H
19#define CONFIG_H
20
21
22/* USB Device descriptor parameter */
23#define VENDOR_ID 0xFEED
24#define PRODUCT_ID 0x6464
25#define DEVICE_VER 0x0001
26/* in python2: list(u"whatever".encode('utf-16-le')) */
27/* at most 32 characters or the ugly hack in usb_main.c borks */
28#define MANUFACTURER "TMK"
29#define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', '\xc6', '\x00'
30#define PRODUCT "ChibiOS TMK test"
31#define USBSTR_PRODUCT 'C', '\x00', 'h', '\x00', 'i', '\x00', 'b', '\x00', 'i', '\x00', 'O', '\x00', 'S', '\x00', ' ', '\x00', 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', 't', '\x00', 'e', '\x00', 's', '\x00', 't', '\x00'
32#define DESCRIPTION "TMK keyboard firmware over ChibiOS"
33
34/* key matrix size */
35#define MATRIX_ROWS 1
36#define MATRIX_COLS 1
37#define DIODE_DIRECTION COL2ROW
38
39/* define if matrix has ghost */
40//#define MATRIX_HAS_GHOST
41
42/* Set 0 if debouncing isn't needed */
43#define DEBOUNCE 5
44
45/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
46#define LOCKING_SUPPORT_ENABLE
47/* Locking resynchronize hack */
48#define LOCKING_RESYNC_ENABLE
49
50/* key combination for command */
51#define IS_COMMAND() ( \
52 keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
53)
54
55
56
57/*
58 * Feature disable options
59 * These options are also useful to firmware size reduction.
60 */
61
62/* disable debug print */
63//#define NO_DEBUG
64
65/* disable print */
66//#define NO_PRINT
67
68/* disable action features */
69//#define NO_ACTION_LAYER
70//#define NO_ACTION_TAPPING
71//#define NO_ACTION_ONESHOT
72//#define NO_ACTION_MACRO
73//#define NO_ACTION_FUNCTION
74
75#endif
diff --git a/keyboards/teensy_lc_onekey/halconf.h b/keyboards/teensy_lc_onekey/halconf.h
new file mode 100644
index 000000000..b1d2cd550
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/halconf.h
@@ -0,0 +1,187 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file templates/halconf.h
19 * @brief HAL configuration header.
20 * @details HAL configuration file, this file allows to enable or disable the
21 * various device drivers from your application. You may also use
22 * this file in order to override the device drivers default settings.
23 *
24 * @addtogroup HAL_CONF
25 * @{
26 */
27
28#ifndef _HALCONF_H_
29#define _HALCONF_H_
30
31#include "mcuconf.h"
32
33/**
34 * @brief Enables the PAL subsystem.
35 */
36#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
37#define HAL_USE_PAL TRUE
38#endif
39
40/**
41 * @brief Enables the ADC subsystem.
42 */
43#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
44#define HAL_USE_ADC FALSE
45#endif
46
47/**
48 * @brief Enables the CAN subsystem.
49 */
50#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)
51#define HAL_USE_CAN FALSE
52#endif
53
54/**
55 * @brief Enables the DAC subsystem.
56 */
57#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)
58#define HAL_USE_DAC FALSE
59#endif
60
61/**
62 * @brief Enables the EXT subsystem.
63 */
64#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
65#define HAL_USE_EXT FALSE
66#endif
67
68/**
69 * @brief Enables the GPT subsystem.
70 */
71#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
72#define HAL_USE_GPT FALSE
73#endif
74
75/**
76 * @brief Enables the I2C subsystem.
77 */
78#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)
79#define HAL_USE_I2C FALSE
80#endif
81
82/**
83 * @brief Enables the I2S subsystem.
84 */
85#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)
86#define HAL_USE_I2S FALSE
87#endif
88
89/**
90 * @brief Enables the ICU subsystem.
91 */
92#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
93#define HAL_USE_ICU FALSE
94#endif
95
96/**
97 * @brief Enables the MAC subsystem.
98 */
99#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)
100#define HAL_USE_MAC FALSE
101#endif
102
103/**
104 * @brief Enables the MMC_SPI subsystem.
105 */
106#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
107#define HAL_USE_MMC_SPI FALSE
108#endif
109
110/**
111 * @brief Enables the PWM subsystem.
112 */
113#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
114#define HAL_USE_PWM FALSE
115#endif
116
117/**
118 * @brief Enables the RTC subsystem.
119 */
120#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)
121#define HAL_USE_RTC FALSE
122#endif
123
124/**
125 * @brief Enables the SDC subsystem.
126 */
127#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)
128#define HAL_USE_SDC FALSE
129#endif
130
131/**
132 * @brief Enables the SERIAL subsystem.
133 */
134#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
135#define HAL_USE_SERIAL FALSE
136#endif
137
138/**
139 * @brief Enables the SERIAL over USB subsystem.
140 */
141#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)
142#define HAL_USE_SERIAL_USB FALSE
143#endif
144
145/**
146 * @brief Enables the SPI subsystem.
147 */
148#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
149#define HAL_USE_SPI FALSE
150#endif
151
152/**
153 * @brief Enables the UART subsystem.
154 */
155#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
156#define HAL_USE_UART FALSE
157#endif
158
159/**
160 * @brief Enables the USB subsystem.
161 */
162#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)
163#define HAL_USE_USB TRUE
164#endif
165
166/**
167 * @brief Enables the WDG subsystem.
168 */
169#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)
170#define HAL_USE_WDG FALSE
171#endif
172
173/*===========================================================================*/
174/* USB driver related settings. */
175/*===========================================================================*/
176
177/**
178 * @brief Enables synchronous APIs.
179 * @note Disabling this option saves both code and data space.
180 */
181#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
182#define USB_USE_WAIT TRUE
183#endif
184
185#endif /* _HALCONF_H_ */
186
187/** @} */
diff --git a/keyboards/teensy_lc_onekey/instructions.md b/keyboards/teensy_lc_onekey/instructions.md
new file mode 100644
index 000000000..16886a015
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/instructions.md
@@ -0,0 +1,82 @@
1# Teensy LC, 3.0, 3.1, 3.2 support
2
3These ARM Teensies are now supported through [ChibiOS](http://chibios.org).
4
5You'll need to install an ARM toolchain, for instance from [gcc ARM embedded](https://launchpad.net/gcc-arm-embedded) website, or using your favourite package manager. After installing, you should be able to run `arm-none-eabi-gcc -v` in the command prompt and get sensible output. This toolchain is used instead of `avr-gcc`, which is only for AVR chips. Naturally you'll also need the usual development tools (e.g. `make`), just as in the AVR setting.
6
7Next, you'll need ChibiOS. For Teensies, you'll need code from two repositories: [chibios-main](https://github.com/ChibiOS/ChibiOS) and [chibios-contrib](https://github.com/ChibiOS/ChibiOS). If you're not using git, you can just download a [zip of chibios from here](https://github.com/ChibiOS/ChibiOS/archive/a7df9a891067621e8e1a5c2a2c0ceada82403afe.zip), unpack the zip, and rename/move the unpacked directory (named `ChibiOS-<long_hash_here>`) to `tmk_core/tool/chibios/chibios` (so that the file `tmk_core/tool/chibios/chibios/license.txt` exists). Now the same procedure with a [zip of chibios-contrib from here](https://github.com/ChibiOS/ChibiOS-Contrib/archive/e1311c4db6cd366cf760673f769e925741ac0ad3.zip): unpack and move `ChibiOS-Contrib-<long_hash_here>` to `tmk_core/tool/chibios/chibios-contrib`.
8
9(If you're using git, you can just clone the two repos: [chibios](https://github.com/ChibiOS/ChibiOS) and [chibios-contrib](https://github.com/ChibiOS/ChibiOS-Contrib). However - be warned that things may be somewhat out-of-sync (updates at different rates), so you may need to hunt a bit for the right commits.)
10
11(Why do we need chibios-contrib? Well, the main repo focuses on STM32 chips, and Freescale/NXP Kinetis chips are supported via the Contrib repository.)
12
13This should be it. Running `make` in `keyboard/teensy_lc_onekey` should create a working firmware in `build/`, called `ch.hex`.
14
15For more notes about the ChibiOS backend in TMK, see `tmk_core/protocol/chibios/README.md`.
16
17## About this onekey example
18
19It's set up for Teensy LC. To use 3.x, you'll need to edit the `Makefile` (and comment out one line in `mcuconf.h`). A sample makefile for Teensy 3.0 is provided as `Makefile.3.0`, can be used without renaming with `make -f Makefile.3.0`. Similarly for Teensy 3.2, there's `Makefile.3.2`.
20
21## Credits
22
23TMK itself is written by hasu, original sources [here](https://github.com/tmk/tmk_keyboard).
24
25The USB support for Kinetis MCUs is due to RedoX. His ChibiOS fork is also [on github](https://github.com/RedoXyde/ChibiOS); but it doesn't include Teensy LC definitions.
26
27## Features that are not implemented yet
28
29Currently only the more fancy suspend features are not there (power saving during suspend). The rest should work fine (reports either way are welcome).
30
31# Matrix programming notes
32
33The notes below explain what commands can be used to examine and set the status of Teensy pins.
34
35## ChibiOS pin manipulation basics
36
37### Pins
38
39Each pin sits on a "port", each of which comprises at most 32 individual pins.
40So for instance "PTC5" from Kinetis manual/datasheet refers to port C (or GPIOA), pin 5. Most functions dealing with pins take 2 parameters which specify the pin -- the first being the port, the second being the pin number.
41
42Within ChibiOS, there are definitions which simplify this a bit for the Teensies. `TEENSY_PINn_IOPORT` represents the port of the MCU's pin connected Teensy's PIN `n`, and `TEENSY_PINn` represents its MCU's pin number.
43
44### Mode
45
46A MCU pin can be in several modes. The basic command to set a pin mode is
47
48 palSetPadMode(TEENSY_PINn_IOPORT, TEENSY_PINn, PAL_MODE_INPUT_PULLUP);
49
50The last parameter is the mode. For keyboards, the usual ones that are used are `PAL_MODE_INPUT_PULLUP` (input with a pullup), `PAL_MODE_INPUT_PULLDOWN` (input with a pulldown), `PAL_MODE_INPUT` (input floating, a.k.a. Hi-Z), `PAL_MODE_OUTPUT_PUSHPULL` (output in the Arduino sense -- can be then set HIGH or LOW).
51
52### Setting
53
54Pins are set HIGH (after they've been put into `OUTPUT_PUSHPULL` mode) by
55
56 palSetPad(TEENSY_PINn_IOPORT, TEENSY_PINn);
57
58or set LOW by
59
60 palClearPad(TEENSY_PINn_IOPORT, TEENSY_PINn);
61
62Toggling can be done with
63
64 palTogglePad(TEENSY_PINn_IOPORT, TEENSY_PINn);
65
66Alternatively, you can use
67
68 palWritePad(TEENSY_PINn_IOPORT, TEENSY_PINn, bit);
69
70where `bit` is either `PAL_LOW` or `PAL_HIGH` (i.e. `0` or `1`).
71
72### Reading
73
74Reading pin status is done with
75
76 palReadPad(TEENSY_PINn_IOPORT, TEENSY_PINn);
77
78The function returns either `PAL_HIGH` (actually `1`) or `PAL_LOW` (actually `0`).
79
80### Further docs
81
82All the commands that are available for pin manipulation through ChibiOS HAL are documented in [ChibiOS PAL driver docs](http://chibios.sourceforge.net/docs3/hal/group___p_a_l.html).
diff --git a/keyboards/teensy_lc_onekey/keymaps/default/keymap.c b/keyboards/teensy_lc_onekey/keymaps/default/keymap.c
new file mode 100644
index 000000000..a109b4960
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/keymaps/default/keymap.c
@@ -0,0 +1,32 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "keycode.h"
19#include "action.h"
20#include "action_macro.h"
21#include "report.h"
22#include "host.h"
23#include "print.h"
24#include "debug.h"
25#include "keymap.h"
26
27const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
28 {{KC_A}},
29}; // to test: KC_CAPS, KT_BTLD, KC_A
30
31const uint16_t fn_actions[] = {
32};
diff --git a/keyboards/teensy_lc_onekey/ld/MKL26Z64.ld b/keyboards/teensy_lc_onekey/ld/MKL26Z64.ld
new file mode 100644
index 000000000..fb141f888
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/ld/MKL26Z64.ld
@@ -0,0 +1,105 @@
1/*
2 * Copyright (C) 2013-2016 Fabio Utzig, http://fabioutzig.com
3 * (C) 2016 flabbergast <s3+flabbergast@sdfeu.org>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24/*
25 * KL26Z64 memory setup.
26 */
27MEMORY
28{
29 flash0 : org = 0x00000000, len = 0x100
30 flash1 : org = 0x00000400, len = 0x10
31 flash2 : org = 0x00000410, len = 62k - 0x410
32 flash3 : org = 0x0000F800, len = 2k
33 flash4 : org = 0x00000000, len = 0
34 flash5 : org = 0x00000000, len = 0
35 flash6 : org = 0x00000000, len = 0
36 flash7 : org = 0x00000000, len = 0
37 ram0 : org = 0x1FFFF800, len = 8k
38 ram1 : org = 0x00000000, len = 0
39 ram2 : org = 0x00000000, len = 0
40 ram3 : org = 0x00000000, len = 0
41 ram4 : org = 0x00000000, len = 0
42 ram5 : org = 0x00000000, len = 0
43 ram6 : org = 0x00000000, len = 0
44 ram7 : org = 0x00000000, len = 0
45}
46
47/* Flash region for the configuration bytes.*/
48SECTIONS
49{
50 .cfmprotect : ALIGN(4) SUBALIGN(4)
51 {
52 KEEP(*(.cfmconfig))
53 } > flash1
54}
55
56/* For each data/text section two region are defined, a virtual region
57 and a load region (_LMA suffix).*/
58
59/* Flash region to be used for exception vectors.*/
60REGION_ALIAS("VECTORS_FLASH", flash0);
61REGION_ALIAS("VECTORS_FLASH_LMA", flash0);
62
63/* Flash region to be used for constructors and destructors.*/
64REGION_ALIAS("XTORS_FLASH", flash2);
65REGION_ALIAS("XTORS_FLASH_LMA", flash2);
66
67/* Flash region to be used for code text.*/
68REGION_ALIAS("TEXT_FLASH", flash2);
69REGION_ALIAS("TEXT_FLASH_LMA", flash2);
70
71/* Flash region to be used for read only data.*/
72REGION_ALIAS("RODATA_FLASH", flash2);
73REGION_ALIAS("RODATA_FLASH_LMA", flash2);
74
75/* Flash region to be used for various.*/
76REGION_ALIAS("VARIOUS_FLASH", flash2);
77REGION_ALIAS("VARIOUS_FLASH_LMA", flash2);
78
79/* Flash region to be used for RAM(n) initialization data.*/
80REGION_ALIAS("RAM_INIT_FLASH_LMA", flash2);
81
82/* RAM region to be used for Main stack. This stack accommodates the processing
83 of all exceptions and interrupts.*/
84REGION_ALIAS("MAIN_STACK_RAM", ram0);
85
86/* RAM region to be used for the process stack. This is the stack used by
87 the main() function.*/
88REGION_ALIAS("PROCESS_STACK_RAM", ram0);
89
90/* RAM region to be used for data segment.*/
91REGION_ALIAS("DATA_RAM", ram0);
92REGION_ALIAS("DATA_RAM_LMA", flash2);
93
94/* RAM region to be used for BSS segment.*/
95REGION_ALIAS("BSS_RAM", ram0);
96
97/* RAM region to be used for the default heap.*/
98REGION_ALIAS("HEAP_RAM", ram0);
99
100__eeprom_workarea_start__ = ORIGIN(flash3);
101__eeprom_workarea_size__ = LENGTH(flash3);
102__eeprom_workarea_end__ = __eeprom_workarea_start__ + __eeprom_workarea_size__;
103
104/* Generic rules inclusion.*/
105INCLUDE rules.ld
diff --git a/keyboards/teensy_lc_onekey/led.c b/keyboards/teensy_lc_onekey/led.c
new file mode 100644
index 000000000..dfa60c107
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/led.c
@@ -0,0 +1,32 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "hal.h"
19
20#include "led.h"
21
22
23void led_set(uint8_t usb_led) {
24 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
25 // output high
26 palSetPadMode(TEENSY_PIN13_IOPORT, TEENSY_PIN13, PAL_MODE_OUTPUT_PUSHPULL);
27 palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
28 } else {
29 // Hi-Z
30 palSetPadMode(TEENSY_PIN13_IOPORT, TEENSY_PIN13, PAL_MODE_INPUT);
31 }
32}
diff --git a/keyboards/teensy_lc_onekey/matrix.c b/keyboards/teensy_lc_onekey/matrix.c
new file mode 100644
index 000000000..7dab04f02
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/matrix.c
@@ -0,0 +1,163 @@
1/*
2Copyright 2012 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "ch.h"
19#include "hal.h"
20
21/*
22 * scan matrix
23 */
24#include "print.h"
25#include "debug.h"
26#include "util.h"
27#include "matrix.h"
28#include "wait.h"
29
30#ifndef DEBOUNCE
31# define DEBOUNCE 5
32#endif
33static uint8_t debouncing = DEBOUNCE;
34
35/* matrix state(1:on, 0:off) */
36static matrix_row_t matrix[MATRIX_ROWS];
37static matrix_row_t matrix_debouncing[MATRIX_ROWS];
38
39static matrix_row_t read_cols(void);
40static void init_cols(void);
41static void unselect_rows(void);
42static void select_row(uint8_t row);
43
44
45inline
46uint8_t matrix_rows(void)
47{
48 return MATRIX_ROWS;
49}
50
51inline
52uint8_t matrix_cols(void)
53{
54 return MATRIX_COLS;
55}
56
57#define LED_ON() do { palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13) ;} while (0)
58#define LED_OFF() do { palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); } while (0)
59#define LED_TGL() do { palTogglePad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); } while (0)
60
61void matrix_init(void)
62{
63 // initialize row and col
64 unselect_rows();
65 init_cols();
66
67 // initialize matrix state: all keys off
68 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
69 matrix[i] = 0;
70 matrix_debouncing[i] = 0;
71 }
72
73 //debug
74 debug_matrix = true;
75 LED_ON();
76 wait_ms(500);
77 LED_OFF();
78}
79
80uint8_t matrix_scan(void)
81{
82 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
83 select_row(i);
84 wait_us(30); // without this wait read unstable value.
85 matrix_row_t cols = read_cols();
86 if (matrix_debouncing[i] != cols) {
87 matrix_debouncing[i] = cols;
88 if (debouncing) {
89 debug("bounce!: "); debug_hex(debouncing); debug("\n");
90 }
91 debouncing = DEBOUNCE;
92 }
93 unselect_rows();
94 }
95
96 if (debouncing) {
97 if (--debouncing) {
98 wait_ms(1);
99 } else {
100 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
101 matrix[i] = matrix_debouncing[i];
102 }
103 }
104 }
105
106 return 1;
107}
108
109inline
110bool matrix_is_on(uint8_t row, uint8_t col)
111{
112 return (matrix[row] & ((matrix_row_t)1<<col));
113}
114
115inline
116matrix_row_t matrix_get_row(uint8_t row)
117{
118 return matrix[row];
119}
120
121void matrix_print(void)
122{
123 print("\nr/c 0123456789ABCDEF\n");
124 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
125 phex(row); print(": ");
126 pbin_reverse16(matrix_get_row(row));
127 print("\n");
128 }
129}
130
131/* Column pin configuration
132 */
133static void init_cols(void)
134{
135 // internal pull-up
136 palSetPadMode(TEENSY_PIN2_IOPORT, TEENSY_PIN2, PAL_MODE_INPUT_PULLUP);
137}
138
139/* Returns status of switches(1:on, 0:off) */
140static matrix_row_t read_cols(void)
141{
142 return ((palReadPad(TEENSY_PIN2_IOPORT, TEENSY_PIN2)==PAL_HIGH) ? 0 : (1<<0));
143 // | ((palReadPad(...)==PAL_HIGH) ? 0 : (1<<1))
144}
145
146/* Row pin configuration
147 */
148static void unselect_rows(void)
149{
150 palSetPadMode(TEENSY_PIN5_IOPORT, TEENSY_PIN5, PAL_MODE_INPUT); // hi-Z
151}
152
153static void select_row(uint8_t row)
154{
155 (void)row;
156 // Output low to select
157 switch (row) {
158 case 0:
159 palSetPadMode(TEENSY_PIN5_IOPORT, TEENSY_PIN5, PAL_MODE_OUTPUT_PUSHPULL);
160 palClearPad(TEENSY_PIN5_IOPORT, TEENSY_PIN5);
161 break;
162 }
163}
diff --git a/keyboards/teensy_lc_onekey/mcuconf.h b/keyboards/teensy_lc_onekey/mcuconf.h
new file mode 100644
index 000000000..c63659019
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/mcuconf.h
@@ -0,0 +1,55 @@
1/*
2 ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef _MCUCONF_H_
18#define _MCUCONF_H_
19
20#define KL2x_MCUCONF
21
22/*
23 * HAL driver system settings.
24 */
25#if 1
26/* PEE mode - 48MHz system clock driven by (16 MHz) external crystal. */
27#define KINETIS_MCG_MODE KINETIS_MCG_MODE_PEE
28#define KINETIS_PLLCLK_FREQUENCY 96000000UL
29#define KINETIS_SYSCLK_FREQUENCY 48000000UL
30#endif
31
32#if 0
33/* crystal-less FEI mode - 48 MHz with internal 32.768 kHz crystal */
34#define KINETIS_MCG_MODE KINETIS_MCG_MODE_FEI
35#define KINETIS_MCG_FLL_DMX32 1 /* Fine-tune for 32.768 kHz */
36#define KINETIS_MCG_FLL_DRS 1 /* 1464x FLL factor */
37#define KINETIS_SYSCLK_FREQUENCY 47972352UL /* 32.768 kHz * 1464 (~48 MHz) */
38#define KINETIS_CLKDIV1_OUTDIV1 1 /* do not divide system clock */
39#endif
40
41/*
42 * SERIAL driver system settings.
43 */
44#define KINETIS_SERIAL_USE_UART0 TRUE
45
46/*
47 * USB driver settings
48 */
49#define KINETIS_USB_USE_USB0 TRUE
50/* Need to redefine this, since the default is for K20x */
51/* This is for Teensy LC; you should comment it out (or change to 5)
52 * for Teensy 3.x */
53#define KINETIS_USB_USB0_IRQ_PRIORITY 2
54
55#endif /* _MCUCONF_H_ */
diff --git a/keyboards/teensy_lc_onekey/teensy_lc_onekey.c b/keyboards/teensy_lc_onekey/teensy_lc_onekey.c
new file mode 100644
index 000000000..b6c432793
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/teensy_lc_onekey.c
@@ -0,0 +1 @@
#include "teensy_lc_onekey.h"
diff --git a/keyboards/teensy_lc_onekey/teensy_lc_onekey.h b/keyboards/teensy_lc_onekey/teensy_lc_onekey.h
new file mode 100644
index 000000000..f598bcf66
--- /dev/null
+++ b/keyboards/teensy_lc_onekey/teensy_lc_onekey.h
@@ -0,0 +1,4 @@
1#ifndef TEENSY_LC_ONEKEY_H
2#define TEENSY_LC_ONEKEY_H
3#include "quantum.h"
4#endif
diff --git a/lib/chibios b/lib/chibios
new file mode 160000
Subproject a7df9a891067621e8e1a5c2a2c0ceada82403af
diff --git a/lib/chibios-contrib b/lib/chibios-contrib
new file mode 160000
Subproject e1311c4db6cd366cf760673f769e925741ac0ad
diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h
index c41c08706..6216eefc9 100644
--- a/quantum/keycode_config.h
+++ b/quantum/keycode_config.h
@@ -18,4 +18,4 @@ typedef union {
18 }; 18 };
19} keymap_config_t; 19} keymap_config_t;
20 20
21keymap_config_t keymap_config; \ No newline at end of file 21extern keymap_config_t keymap_config;
diff --git a/quantum/keymap.h b/quantum/keymap.h
index a994f4f2e..73f99f821 100644
--- a/quantum/keymap.h
+++ b/quantum/keymap.h
@@ -21,7 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include <stdint.h> 21#include <stdint.h>
22#include <stdbool.h> 22#include <stdbool.h>
23#include "action.h" 23#include "action.h"
24#if defined(__AVR__)
24#include <avr/pgmspace.h> 25#include <avr/pgmspace.h>
26#endif
25#include "keycode.h" 27#include "keycode.h"
26#include "action_macro.h" 28#include "action_macro.h"
27#include "report.h" 29#include "report.h"
@@ -30,12 +32,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30#include "debug.h" 32#include "debug.h"
31#include "keycode_config.h" 33#include "keycode_config.h"
32 34
35// ChibiOS uses RESET in its FlagStatus enumeration
36// Therefore define it as QK_RESET here, to avoid name collision
37#if defined(PROTOCOL_CHIBIOS)
38#define RESET QK_RESET
39#endif
40
33/* translates key to keycode */ 41/* translates key to keycode */
34uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); 42uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
35 43
36/* translates Fn keycode to action */
37action_t keymap_fn_to_action(uint16_t keycode);
38
39extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; 44extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
40extern const uint16_t fn_actions[]; 45extern const uint16_t fn_actions[];
41 46
diff --git a/quantum/keymap.c b/quantum/keymap_common.c
index 74fd518c9..76872ac59 100644
--- a/quantum/keymap.c
+++ b/quantum/keymap_common.c
@@ -19,7 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#include "report.h" 19#include "report.h"
20#include "keycode.h" 20#include "keycode.h"
21#include "action_layer.h" 21#include "action_layer.h"
22#if defined(__AVR__)
22#include <util/delay.h> 23#include <util/delay.h>
24#include <stdio.h>
25#endif
23#include "action.h" 26#include "action.h"
24#include "action_macro.h" 27#include "action_macro.h"
25#include "debug.h" 28#include "debug.h"
@@ -32,7 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
32 35
33extern keymap_config_t keymap_config; 36extern keymap_config_t keymap_config;
34 37
35#include <stdio.h>
36#include <inttypes.h> 38#include <inttypes.h>
37 39
38/* converts key to action */ 40/* converts key to action */
@@ -46,10 +48,12 @@ action_t action_for_key(uint8_t layer, keypos_t key)
46 48
47 action_t action; 49 action_t action;
48 uint8_t action_layer, when, mod; 50 uint8_t action_layer, when, mod;
51 // The arm-none-eabi compiler generates out of bounds warnings when using the fn_actions directly for some reason
52 const uint16_t* actions = fn_actions;
49 53
50 switch (keycode) { 54 switch (keycode) {
51 case KC_FN0 ... KC_FN31: 55 case KC_FN0 ... KC_FN31:
52 action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]); 56 action.code = pgm_read_word(&actions[FN_INDEX(keycode)]);
53 break; 57 break;
54 case KC_A ... KC_EXSEL: 58 case KC_A ... KC_EXSEL:
55 case KC_LCTRL ... KC_RGUI: 59 case KC_LCTRL ... KC_RGUI:
@@ -75,7 +79,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
75 case QK_FUNCTION ... QK_FUNCTION_MAX: ; 79 case QK_FUNCTION ... QK_FUNCTION_MAX: ;
76 // Is a shortcut for function action_layer, pull last 12bits 80 // Is a shortcut for function action_layer, pull last 12bits
77 // This means we have 4,096 FN macros at our disposal 81 // This means we have 4,096 FN macros at our disposal
78 action.code = pgm_read_word(&fn_actions[(int)keycode & 0xFFF]); 82 action.code = pgm_read_word(&actions[(int)keycode & 0xFFF]);
79 break; 83 break;
80 case QK_MACRO ... QK_MACRO_MAX: 84 case QK_MACRO ... QK_MACRO_MAX:
81 action.code = ACTION_MACRO(keycode & 0xFF); 85 action.code = ACTION_MACRO(keycode & 0xFF);
diff --git a/quantum/matrix.c b/quantum/matrix.c
index f5744658c..a38c13f15 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -17,7 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/ 17*/
18#include <stdint.h> 18#include <stdint.h>
19#include <stdbool.h> 19#include <stdbool.h>
20#if defined(__AVR__)
20#include <avr/io.h> 21#include <avr/io.h>
22#endif
21#include "wait.h" 23#include "wait.h"
22#include "print.h" 24#include "print.h"
23#include "debug.h" 25#include "debug.h"
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 270b976e3..d59bd5a3f 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -88,7 +88,7 @@ bool process_record_quantum(keyrecord_t *record) {
88 stop_all_notes(); 88 stop_all_notes();
89 shutdown_user(); 89 shutdown_user();
90 #endif 90 #endif
91 _delay_ms(250); 91 wait_ms(250);
92 #ifdef ATREUS_ASTAR 92 #ifdef ATREUS_ASTAR
93 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific 93 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
94 #endif 94 #endif
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 9b5d310bd..3a0b74202 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -1,7 +1,12 @@
1#ifndef QUANTUM_H 1#ifndef QUANTUM_H
2#define QUANTUM_H 2#define QUANTUM_H
3 3
4#if defined(__AVR__)
4#include <avr/pgmspace.h> 5#include <avr/pgmspace.h>
6#include <avr/io.h>
7#include <avr/interrupt.h>
8#endif
9#include "wait.h"
5#include "matrix.h" 10#include "matrix.h"
6#include "keymap.h" 11#include "keymap.h"
7#ifdef BACKLIGHT_ENABLE 12#ifdef BACKLIGHT_ENABLE
@@ -14,12 +19,9 @@
14#include "action_layer.h" 19#include "action_layer.h"
15#include "eeconfig.h" 20#include "eeconfig.h"
16#include <stddef.h> 21#include <stddef.h>
17#include <avr/io.h>
18#include <util/delay.h>
19#include "bootloader.h" 22#include "bootloader.h"
20#include "timer.h" 23#include "timer.h"
21#include "config_common.h" 24#include "config_common.h"
22#include <avr/interrupt.h>
23#include "led.h" 25#include "led.h"
24#include "action_util.h" 26#include "action_util.h"
25#include <stdlib.h> 27#include <stdlib.h>
diff --git a/readme.md b/readme.md
index 6fa67c047..c24d951d8 100644
--- a/readme.md
+++ b/readme.md
@@ -24,6 +24,9 @@ The project also includes community support for [lots of other keyboards](/keybo
24QMK is developed and maintained by Jack Humbert of OLKB with contributions from the community, and of course, [Hasu](https://github.com/tmk). This repo used to be a fork of [TMK](https://github.com/tmk/tmk_keyboard), and we are incredibly grateful for his founding contributions to the firmware. We've had to break the fork due to purely technical reasons - it simply became too different over time, and we've had to start refactoring some of the basic bits and pieces. We are huge fans of TMK and Hasu :) 24QMK is developed and maintained by Jack Humbert of OLKB with contributions from the community, and of course, [Hasu](https://github.com/tmk). This repo used to be a fork of [TMK](https://github.com/tmk/tmk_keyboard), and we are incredibly grateful for his founding contributions to the firmware. We've had to break the fork due to purely technical reasons - it simply became too different over time, and we've had to start refactoring some of the basic bits and pieces. We are huge fans of TMK and Hasu :)
25 25
26This documentation is edited and maintained by Erez Zukerman of ErgoDox EZ. If you spot any typos or inaccuracies, please [open an issue](https://github.com/jackhumbert/qmk_firmware/issues/new). 26This documentation is edited and maintained by Erez Zukerman of ErgoDox EZ. If you spot any typos or inaccuracies, please [open an issue](https://github.com/jackhumbert/qmk_firmware/issues/new).
27#### 2016/02/10
28core: flabbergast's Chibios protocol was merged from <https://github.com/flabbergast/tmk_keyboard/tree/chibios> (@72b1668). See [tmk_core/protocol/chibios/README.md](tmk_core/protocol/chibios/README.md). Chibios protocol supports Cortex-M such as STM32 and Kinetis.
29
27 30
28The OLKB product firmwares are maintained by [Jack Humbert](https://github.com/jackhumbert), the Ergodox EZ by [Erez Zukerman](https://github.com/ezuk), and the Clueboard by [Zach White](https://github.com/skullydazed). 31The OLKB product firmwares are maintained by [Jack Humbert](https://github.com/jackhumbert), the Ergodox EZ by [Erez Zukerman](https://github.com/ezuk), and the Clueboard by [Zach White](https://github.com/skullydazed).
29 32
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk
new file mode 100644
index 000000000..72be5e6da
--- /dev/null
+++ b/tmk_core/avr.mk
@@ -0,0 +1,185 @@
1# Hey Emacs, this is a -*- makefile -*-
2##############################################################################
3# Compiler settings
4#
5CC = avr-gcc
6OBJCOPY = avr-objcopy
7OBJDUMP = avr-objdump
8SIZE = avr-size
9AR = avr-ar rcs
10NM = avr-nm
11HEX = $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature
12EEP = $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT)
13
14
15
16COMPILEFLAGS += -funsigned-char
17COMPILEFLAGS += -funsigned-bitfields
18COMPILEFLAGS += -ffunction-sections
19COMPILEFLAGS += -fdata-sections
20COMPILEFLAGS += -fpack-struct
21COMPILEFLAGS += -fshort-enums
22
23CFLAGS += $(COMPILEFLAGS)
24CFLAGS += -fno-inline-small-functions
25CFLAGS += -fno-strict-aliasing
26
27CPPFLAGS += $(COMPILEFLAGS)
28CPPFLAGS += -fno-exceptions
29
30LDFLAGS +=-Wl,--gc-sections
31
32OPT_DEFS += -DF_CPU=$(F_CPU)UL
33
34MCUFLAGS = -mmcu=$(MCU)
35
36# List any extra directories to look for libraries here.
37# Each directory must be seperated by a space.
38# Use forward slashes for directory separators.
39# For a directory that has spaces, enclose it in quotes.
40EXTRALIBDIRS =
41
42
43#---------------- External Memory Options ----------------
44
45# 64 KB of external RAM, starting after internal RAM (ATmega128!),
46# used for variables (.data/.bss) and heap (malloc()).
47#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
48
49# 64 KB of external RAM, starting after internal RAM (ATmega128!),
50# only used for heap (malloc()).
51#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
52
53EXTMEMOPTS =
54
55#---------------- Debugging Options ----------------
56
57# Debugging format.
58# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
59# AVR Studio 4.10 requires dwarf-2.
60# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
61DEBUG = dwarf-2
62
63# For simulavr only - target MCU frequency.
64DEBUG_MFREQ = $(F_CPU)
65
66# Set the DEBUG_UI to either gdb or insight.
67# DEBUG_UI = gdb
68DEBUG_UI = insight
69
70# Set the debugging back-end to either avarice, simulavr.
71DEBUG_BACKEND = avarice
72#DEBUG_BACKEND = simulavr
73
74# GDB Init Filename.
75GDBINIT_FILE = __avr_gdbinit
76
77# When using avarice settings for the JTAG
78JTAG_DEV = /dev/com1
79
80# Debugging port used to communicate between GDB / avarice / simulavr.
81DEBUG_PORT = 4242
82
83# Debugging host used to communicate between GDB / avarice / simulavr, normally
84# just set to localhost unless doing some sort of crazy debugging when
85# avarice is running on a different computer.
86DEBUG_HOST = localhost
87
88#============================================================================
89# Autodecct teensy loader
90ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
91 TEENSY_LOADER_CLI = teensy-loader-cli
92else
93 TEENSY_LOADER_CLI = teensy_loader_cli
94endif
95
96# Program the device.
97program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
98 $(PROGRAM_CMD)
99
100teensy: $(BUILD_DIR)/$(TARGET).hex
101 $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
102
103flip: $(BUILD_DIR)/$(TARGET).hex
104 batchisp -hardware usb -device $(MCU) -operation erase f
105 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
106 batchisp -hardware usb -device $(MCU) -operation start reset 0
107
108dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
109ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
110 dfu-programmer $(MCU) erase --force
111else
112 dfu-programmer $(MCU) erase
113endif
114 dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
115 dfu-programmer $(MCU) reset
116
117dfu-start:
118 dfu-programmer $(MCU) reset
119 dfu-programmer $(MCU) start
120
121flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
122 $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
123 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
124 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
125 batchisp -hardware usb -device $(MCU) -operation start reset 0
126 $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
127
128dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
129ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
130 dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
131else
132 dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
133endif
134 dfu-programmer $(MCU) reset
135
136
137# Generate avr-gdb config/init file which does the following:
138# define the reset signal, load the target file, connect to target, and set
139# a breakpoint at main().
140gdb-config:
141 @$(REMOVE) $(GDBINIT_FILE)
142 @echo define reset >> $(GDBINIT_FILE)
143 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
144 @echo end >> $(GDBINIT_FILE)
145 @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
146 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
147ifeq ($(DEBUG_BACKEND),simulavr)
148 @echo load >> $(GDBINIT_FILE)
149endif
150 @echo break main >> $(GDBINIT_FILE)
151
152debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
153ifeq ($(DEBUG_BACKEND), avarice)
154 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
155 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
156 $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
157 @$(WINSHELL) /c pause
158
159else
160 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
161 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
162endif
163 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
164
165
166
167
168# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
169COFFCONVERT = $(OBJCOPY) --debugging
170COFFCONVERT += --change-section-address .data-0x800000
171COFFCONVERT += --change-section-address .bss-0x800000
172COFFCONVERT += --change-section-address .noinit-0x800000
173COFFCONVERT += --change-section-address .eeprom-0x810000
174
175
176
177coff: $(BUILD_DIR)/$(TARGET).elf
178 @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
179 $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
180
181
182extcoff: $(BUILD_DIR)/$(TARGET).elf
183 @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
184 $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
185
diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk
new file mode 100644
index 000000000..0abb933a8
--- /dev/null
+++ b/tmk_core/chibios.mk
@@ -0,0 +1,154 @@
1# Hey Emacs, this is a -*- makefile -*-
2##############################################################################
3# Architecture or project specific options
4#
5
6# Stack size to be allocated to the Cortex-M process stack. This stack is
7# the stack used by the main() thread.
8ifeq ($(USE_PROCESS_STACKSIZE),)
9 USE_PROCESS_STACKSIZE = 0x200
10endif
11
12# Stack size to the allocated to the Cortex-M main/exceptions stack. This
13# stack is used for processing interrupts and exceptions.
14ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
15 USE_EXCEPTIONS_STACKSIZE = 0x400
16endif
17
18#
19# Architecture or project specific options
20##############################################################################
21
22##############################################################################
23# Project, sources and paths
24#
25
26# Imported source files and paths
27CHIBIOS = $(TOP_DIR)/lib/chibios
28CHIBIOS_CONTRIB = $(TOP_DIR)/lib/chibios-contrib
29# Startup files. Try a few different locations, for compability with old versions and
30# for things hardware in the contrib repository
31STARTUP_MK = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk
32ifeq ("$(wildcard $(STARTUP_MK))","")
33 STARTUP_MK = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk
34 ifeq ("$(wildcard $(STARTUP_MK))","")
35 STARTUP_MK = $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_$(MCU_STARTUP).mk
36 endif
37endif
38include $(STARTUP_MK)
39# HAL-OSAL files (optional).
40include $(CHIBIOS)/os/hal/hal.mk
41
42PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/platform.mk
43ifeq ("$(wildcard $(PLATFORM_MK))","")
44PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/platform.mk
45endif
46include $(PLATFORM_MK)
47
48
49BOARD_MK = $(KEYBOARD_PATH)/boards/$(BOARD)/board.mk
50ifeq ("$(wildcard $(BOARD_MK))","")
51 BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk
52 ifeq ("$(wildcard $(BOARD_MK))","")
53 BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk
54 endif
55endif
56include $(BOARD_MK)
57include $(CHIBIOS)/os/hal/osal/rt/osal.mk
58# RTOS files (optional).
59include $(CHIBIOS)/os/rt/rt.mk
60# Compability with old version
61PORT_V = $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk
62ifeq ("$(wildcard $(PORT_V))","")
63PORT_V = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v$(ARMV)m.mk
64endif
65include $(PORT_V)
66# Other files (optional).
67include $(CHIBIOS)/os/hal/lib/streams/streams.mk
68
69RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
70ifeq ("$(wildcard $(RULESPATH)/rules.mk)","")
71RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC
72endif
73
74# Define linker script file here
75ifneq ("$(wildcard $(KEYBOARD_PATH)/ld/$(MCU_LDSCRIPT).ld)","")
76LDSCRIPT = $(KEYBOARD_PATH)/ld/$(MCU_LDSCRIPT).ld
77else
78LDSCRIPT = $(STARTUPLD)/$(MCU_LDSCRIPT).ld
79endif
80
81CHIBISRC = $(STARTUPSRC) \
82 $(KERNSRC) \
83 $(PORTSRC) \
84 $(OSALSRC) \
85 $(HALSRC) \
86 $(PLATFORMSRC) \
87 $(BOARDSRC) \
88 $(STREAMSSRC) \
89 $(STARTUPASM) \
90 $(PORTASM) \
91 $(OSALASM)
92
93SRC += $(patsubst $(TOP_DIR)/%,%,$(CHIBISRC))
94
95EXTRAINCDIRS += $(CHIBIOS)/os/license \
96 $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
97 $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
98 $(STREAMSINC) $(CHIBIOS)/os/various
99
100#
101# Project, sources and paths
102##############################################################################
103
104
105##############################################################################
106# Compiler settings
107#
108CC = arm-none-eabi-gcc
109OBJCOPY = arm-none-eabi-objcopy
110OBJDUMP = arm-none-eabi-objdump
111SIZE = arm-none-eabi-size
112AR = arm-none-eabi-ar
113NM = arm-none-eabi-nm
114HEX = $(OBJCOPY) -O $(FORMAT)
115EEP =
116
117THUMBFLAGS = -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -mthumb -DTHUMB
118
119COMPILEFLAGS += -fomit-frame-pointer
120COMPILEFLAGS += -falign-functions=16
121COMPILEFLAGS += -ffunction-sections
122COMPILEFLAGS += -fdata-sections
123COMPILEFLAGS += -fno-common
124COMPILEFLAGS += $(THUMBFLAGS)
125
126CFLAGS += $(COMPILEFLAGS)
127
128ASFLAGS += $(THUMBFLAGS)
129
130CPPFLAGS += $(COMPILEFLAGS)
131CPPFLAGS += -fno-rtti
132
133LDFLAGS +=-Wl,--gc-sections
134LDFLAGS += -mno-thumb-interwork -mthumb
135LDSYMBOLS =,--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE)
136LDSYMBOLS :=$(LDSYMBOLS),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
137LDFLAGS += -Wl,--script=$(LDSCRIPT)$(LDSYMBOLS)
138
139OPT_DEFS += -DPROTOCOL_CHIBIOS
140
141MCUFLAGS = -mcpu=$(MCU)
142
143DEBUG = gdb
144
145# Define ASM defines here
146# bootloader definitions may be used in the startup .s file
147ifneq ("$(wildcard $(KEYBOARD_PATH)/bootloader_defs.h)","")
148 OPT_DEFS += -include $(KEYBOARD_PATH)/bootloader_defs.h
149else ifneq ("$(wildcard $(KEYBOARD_PATH)/boards/$(BOARD)/bootloader_defs.h)","")
150 OPT_DEFS += -include $(KEYBOARD_PATH)/boards/$(BOARD)/bootloader_defs.h
151endif
152
153# List any extra directories to look for libraries here.
154EXTRALIBDIRS = $(RULESPATH)/ld \ No newline at end of file
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index f2a22e4f8..d71fba9bc 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -1,4 +1,10 @@
1COMMON_DIR = common 1COMMON_DIR = common
2ifeq ($(PLATFORM),AVR)
3 PLATFORM_COMMON_DIR = $(COMMON_DIR)/avr
4else ifeq ($(PLATFORM),CHIBIOS)
5 PLATFORM_COMMON_DIR = $(COMMON_DIR)/chibios
6endif
7
2SRC += $(COMMON_DIR)/host.c \ 8SRC += $(COMMON_DIR)/host.c \
3 $(COMMON_DIR)/keyboard.c \ 9 $(COMMON_DIR)/keyboard.c \
4 $(COMMON_DIR)/action.c \ 10 $(COMMON_DIR)/action.c \
@@ -9,21 +15,29 @@ SRC += $(COMMON_DIR)/host.c \
9 $(COMMON_DIR)/print.c \ 15 $(COMMON_DIR)/print.c \
10 $(COMMON_DIR)/debug.c \ 16 $(COMMON_DIR)/debug.c \
11 $(COMMON_DIR)/util.c \ 17 $(COMMON_DIR)/util.c \
12 $(COMMON_DIR)/avr/suspend.c \ 18 $(COMMON_DIR)/eeconfig.c \
13 $(COMMON_DIR)/avr/xprintf.S \ 19 $(PLATFORM_COMMON_DIR)/suspend.c \
14 $(COMMON_DIR)/avr/timer.c \ 20 $(PLATFORM_COMMON_DIR)/timer.c \
15 $(COMMON_DIR)/avr/bootloader.c 21 $(PLATFORM_COMMON_DIR)/bootloader.c \
22
23ifeq ($(PLATFORM),AVR)
24 SRC += $(PLATFORM_COMMON_DIR)/xprintf.S
25endif
26
27ifeq ($(PLATFORM),CHIBIOS)
28 SRC += $(PLATFORM_COMMON_DIR)/printf.c
29 SRC += $(PLATFORM_COMMON_DIR)/eeprom.c
30endif
31
16 32
17 33
18# Option modules 34# Option modules
19ifeq ($(strip $(BOOTMAGIC_ENABLE)), yes) 35ifeq ($(strip $(BOOTMAGIC_ENABLE)), yes)
20 OPT_DEFS += -DBOOTMAGIC_ENABLE 36 OPT_DEFS += -DBOOTMAGIC_ENABLE
21 SRC += $(COMMON_DIR)/bootmagic.c 37 SRC += $(COMMON_DIR)/bootmagic.c
22 SRC += $(COMMON_DIR)/avr/eeconfig.c
23else 38else
24 OPT_DEFS += -DMAGIC_ENABLE 39 OPT_DEFS += -DMAGIC_ENABLE
25 SRC += $(COMMON_DIR)/magic.c 40 SRC += $(COMMON_DIR)/magic.c
26 SRC += $(COMMON_DIR)/avr/eeconfig.c
27endif 41endif
28 42
29ifeq ($(strip $(MOUSEKEY_ENABLE)), yes) 43ifeq ($(strip $(MOUSEKEY_ENABLE)), yes)
@@ -57,14 +71,13 @@ ifeq ($(strip $(USB_6KRO_ENABLE)), yes)
57endif 71endif
58 72
59ifeq ($(strip $(SLEEP_LED_ENABLE)), yes) 73ifeq ($(strip $(SLEEP_LED_ENABLE)), yes)
60 SRC += $(COMMON_DIR)/sleep_led.c 74 SRC += $(PLATFORM_COMMON_DIR)/sleep_led.c
61 OPT_DEFS += -DSLEEP_LED_ENABLE 75 OPT_DEFS += -DSLEEP_LED_ENABLE
62 OPT_DEFS += -DNO_SUSPEND_POWER_DOWN 76 OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
63endif 77endif
64 78
65ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) 79ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
66 SRC += $(COMMON_DIR)/backlight.c 80 SRC += $(COMMON_DIR)/backlight.c
67 SRC += $(COMMON_DIR)/avr/eeconfig.c
68 OPT_DEFS += -DBACKLIGHT_ENABLE 81 OPT_DEFS += -DBACKLIGHT_ENABLE
69endif 82endif
70 83
@@ -87,6 +100,13 @@ endif
87# Version string 100# Version string
88OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null) 101OPT_DEFS += -DVERSION=$(shell (git describe --always --dirty || echo 'unknown') 2> /dev/null)
89 102
103# Bootloader address
104ifdef STM32_BOOTLOADER_ADDRESS
105 OPT_DEFS += -DSTM32_BOOTLOADER_ADDRESS=$(STM32_BOOTLOADER_ADDRESS)
106endif
90 107
91# Search Path 108# Search Path
92VPATH += $(TMK_PATH)/$(COMMON_DIR) 109VPATH += $(TMK_PATH)/$(COMMON_DIR)
110ifeq ($(PLATFORM),CHIBIOS)
111VPATH += $(TMK_PATH)/$(COMMON_DIR)/chibios
112endif \ No newline at end of file
diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c
index ff78d7f2a..e16e11be7 100644
--- a/tmk_core/common/action_tapping.c
+++ b/tmk_core/common/action_tapping.c
@@ -257,7 +257,7 @@ bool process_tapping(keyrecord_t *keyp)
257 return true; 257 return true;
258 } 258 }
259 } else { 259 } else {
260 if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n"); 260 if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n") {};
261 process_record(keyp); 261 process_record(keyp);
262 return true; 262 return true;
263 } 263 }
diff --git a/tmk_core/common/sleep_led.c b/tmk_core/common/avr/sleep_led.c
index dab3eb0f3..dab3eb0f3 100644
--- a/tmk_core/common/sleep_led.c
+++ b/tmk_core/common/avr/sleep_led.c
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index 30e8a0f20..90275a18b 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -1,6 +1,6 @@
1#include <stdint.h> 1#include <stdint.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <util/delay.h> 3#include "wait.h"
4#include "matrix.h" 4#include "matrix.h"
5#include "bootloader.h" 5#include "bootloader.h"
6#include "debug.h" 6#include "debug.h"
@@ -10,6 +10,7 @@
10#include "eeconfig.h" 10#include "eeconfig.h"
11#include "bootmagic.h" 11#include "bootmagic.h"
12 12
13keymap_config_t keymap_config;
13 14
14void bootmagic(void) 15void bootmagic(void)
15{ 16{
@@ -19,9 +20,9 @@ void bootmagic(void)
19 } 20 }
20 21
21 /* do scans in case of bounce */ 22 /* do scans in case of bounce */
22 print("boogmagic scan: ... "); 23 print("bootmagic scan: ... ");
23 uint8_t scan = 100; 24 uint8_t scan = 100;
24 while (scan--) { matrix_scan(); _delay_ms(10); } 25 while (scan--) { matrix_scan(); wait_ms(10); }
25 print("done.\n"); 26 print("done.\n");
26 27
27 /* bootmagic skip */ 28 /* bootmagic skip */
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c
new file mode 100644
index 000000000..8a533ab6f
--- /dev/null
+++ b/tmk_core/common/chibios/bootloader.c
@@ -0,0 +1,47 @@
1#include "bootloader.h"
2
3#include "ch.h"
4#include "hal.h"
5
6#ifdef STM32_BOOTLOADER_ADDRESS
7/* STM32 */
8
9#if defined(STM32F0XX)
10/* This code should be checked whether it runs correctly on platforms */
11#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
12extern uint32_t __ram0_end__;
13
14void bootloader_jump(void) {
15 *((unsigned long *)(SYMVAL(__ram0_end__) - 4)) = 0xDEADBEEF; // set magic flag => reset handler will jump into boot loader
16 NVIC_SystemReset();
17}
18
19#else /* defined(STM32F0XX) */
20#error Check that the bootloader code works on your platform and add it to bootloader.c!
21#endif /* defined(STM32F0XX) */
22
23#elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
24/* Kinetis */
25
26#if defined(KIIBOHD_BOOTLOADER)
27/* Kiibohd Bootloader (MCHCK and Infinity KB) */
28#define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
29const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
30void bootloader_jump(void) {
31 __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
32 // request reset
33 SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
34}
35
36#else /* defined(KIIBOHD_BOOTLOADER) */
37/* Default for Kinetis - expecting an ARM Teensy */
38void bootloader_jump(void) {
39 chThdSleepMilliseconds(100);
40 __BKPT(0);
41}
42#endif /* defined(KIIBOHD_BOOTLOADER) */
43
44#else /* neither STM32 nor KINETIS */
45__attribute__((weak))
46void bootloader_jump(void) {}
47#endif \ No newline at end of file
diff --git a/tmk_core/common/chibios/eeprom.c b/tmk_core/common/chibios/eeprom.c
new file mode 100644
index 000000000..5ff8ee86f
--- /dev/null
+++ b/tmk_core/common/chibios/eeprom.c
@@ -0,0 +1,588 @@
1#include "ch.h"
2#include "hal.h"
3
4#include "eeconfig.h"
5
6/*************************************/
7/* Hardware backend */
8/* */
9/* Code from PJRC/Teensyduino */
10/*************************************/
11
12/* Teensyduino Core Library
13 * http://www.pjrc.com/teensy/
14 * Copyright (c) 2013 PJRC.COM, LLC.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining
17 * a copy of this software and associated documentation files (the
18 * "Software"), to deal in the Software without restriction, including
19 * without limitation the rights to use, copy, modify, merge, publish,
20 * distribute, sublicense, and/or sell copies of the Software, and to
21 * permit persons to whom the Software is furnished to do so, subject to
22 * the following conditions:
23 *
24 * 1. The above copyright notice and this permission notice shall be
25 * included in all copies or substantial portions of the Software.
26 *
27 * 2. If the Software is incorporated into a build system that allows
28 * selection among a list of target devices, then similar target
29 * devices manufactured by PJRC.COM must be included in the list of
30 * target devices and selectable in the same manner.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
36 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
37 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
38 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 * SOFTWARE.
40 */
41
42
43#if defined(K20x) /* chip selection */
44/* Teensy 3.0, 3.1, 3.2; mchck; infinity keyboard */
45
46// The EEPROM is really RAM with a hardware-based backup system to
47// flash memory. Selecting a smaller size EEPROM allows more wear
48// leveling, for higher write endurance. If you edit this file,
49// set this to the smallest size your application can use. Also,
50// due to Freescale's implementation, writing 16 or 32 bit words
51// (aligned to 2 or 4 byte boundaries) has twice the endurance
52// compared to writing 8 bit bytes.
53//
54#define EEPROM_SIZE 32
55
56// Writing unaligned 16 or 32 bit data is handled automatically when
57// this is defined, but at a cost of extra code size. Without this,
58// any unaligned write will cause a hard fault exception! If you're
59// absolutely sure all 16 and 32 bit writes will be aligned, you can
60// remove the extra unnecessary code.
61//
62#define HANDLE_UNALIGNED_WRITES
63
64// Minimum EEPROM Endurance
65// ------------------------
66#if (EEPROM_SIZE == 2048) // 35000 writes/byte or 70000 writes/word
67 #define EEESIZE 0x33
68#elif (EEPROM_SIZE == 1024) // 75000 writes/byte or 150000 writes/word
69 #define EEESIZE 0x34
70#elif (EEPROM_SIZE == 512) // 155000 writes/byte or 310000 writes/word
71 #define EEESIZE 0x35
72#elif (EEPROM_SIZE == 256) // 315000 writes/byte or 630000 writes/word
73 #define EEESIZE 0x36
74#elif (EEPROM_SIZE == 128) // 635000 writes/byte or 1270000 writes/word
75 #define EEESIZE 0x37
76#elif (EEPROM_SIZE == 64) // 1275000 writes/byte or 2550000 writes/word
77 #define EEESIZE 0x38
78#elif (EEPROM_SIZE == 32) // 2555000 writes/byte or 5110000 writes/word
79 #define EEESIZE 0x39
80#endif
81
82void eeprom_initialize(void)
83{
84 uint32_t count=0;
85 uint16_t do_flash_cmd[] = {
86 0xf06f, 0x037f, 0x7003, 0x7803,
87 0xf013, 0x0f80, 0xd0fb, 0x4770};
88 uint8_t status;
89
90 if (FTFL->FCNFG & FTFL_FCNFG_RAMRDY) {
91 // FlexRAM is configured as traditional RAM
92 // We need to reconfigure for EEPROM usage
93 FTFL->FCCOB0 = 0x80; // PGMPART = Program Partition Command
94 FTFL->FCCOB4 = EEESIZE; // EEPROM Size
95 FTFL->FCCOB5 = 0x03; // 0K for Dataflash, 32K for EEPROM backup
96 __disable_irq();
97 // do_flash_cmd() must execute from RAM. Luckily the C syntax is simple...
98 (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFL->FSTAT));
99 __enable_irq();
100 status = FTFL->FSTAT;
101 if (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL)) {
102 FTFL->FSTAT = (status & (FTFL_FSTAT_RDCOLERR|FTFL_FSTAT_ACCERR|FTFL_FSTAT_FPVIOL));
103 return; // error
104 }
105 }
106 // wait for eeprom to become ready (is this really necessary?)
107 while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
108 if (++count > 20000) break;
109 }
110}
111
112#define FlexRAM ((uint8_t *)0x14000000)
113
114uint8_t eeprom_read_byte(const uint8_t *addr)
115{
116 uint32_t offset = (uint32_t)addr;
117 if (offset >= EEPROM_SIZE) return 0;
118 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
119 return FlexRAM[offset];
120}
121
122uint16_t eeprom_read_word(const uint16_t *addr)
123{
124 uint32_t offset = (uint32_t)addr;
125 if (offset >= EEPROM_SIZE-1) return 0;
126 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
127 return *(uint16_t *)(&FlexRAM[offset]);
128}
129
130uint32_t eeprom_read_dword(const uint32_t *addr)
131{
132 uint32_t offset = (uint32_t)addr;
133 if (offset >= EEPROM_SIZE-3) return 0;
134 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
135 return *(uint32_t *)(&FlexRAM[offset]);
136}
137
138void eeprom_read_block(void *buf, const void *addr, uint32_t len)
139{
140 uint32_t offset = (uint32_t)addr;
141 uint8_t *dest = (uint8_t *)buf;
142 uint32_t end = offset + len;
143
144 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
145 if (end > EEPROM_SIZE) end = EEPROM_SIZE;
146 while (offset < end) {
147 *dest++ = FlexRAM[offset++];
148 }
149}
150
151int eeprom_is_ready(void)
152{
153 return (FTFL->FCNFG & FTFL_FCNFG_EEERDY) ? 1 : 0;
154}
155
156static void flexram_wait(void)
157{
158 while (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) {
159 // TODO: timeout
160 }
161}
162
163void eeprom_write_byte(uint8_t *addr, uint8_t value)
164{
165 uint32_t offset = (uint32_t)addr;
166
167 if (offset >= EEPROM_SIZE) return;
168 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
169 if (FlexRAM[offset] != value) {
170 FlexRAM[offset] = value;
171 flexram_wait();
172 }
173}
174
175void eeprom_write_word(uint16_t *addr, uint16_t value)
176{
177 uint32_t offset = (uint32_t)addr;
178
179 if (offset >= EEPROM_SIZE-1) return;
180 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
181#ifdef HANDLE_UNALIGNED_WRITES
182 if ((offset & 1) == 0) {
183#endif
184 if (*(uint16_t *)(&FlexRAM[offset]) != value) {
185 *(uint16_t *)(&FlexRAM[offset]) = value;
186 flexram_wait();
187 }
188#ifdef HANDLE_UNALIGNED_WRITES
189 } else {
190 if (FlexRAM[offset] != value) {
191 FlexRAM[offset] = value;
192 flexram_wait();
193 }
194 if (FlexRAM[offset + 1] != (value >> 8)) {
195 FlexRAM[offset + 1] = value >> 8;
196 flexram_wait();
197 }
198 }
199#endif
200}
201
202void eeprom_write_dword(uint32_t *addr, uint32_t value)
203{
204 uint32_t offset = (uint32_t)addr;
205
206 if (offset >= EEPROM_SIZE-3) return;
207 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
208#ifdef HANDLE_UNALIGNED_WRITES
209 switch (offset & 3) {
210 case 0:
211#endif
212 if (*(uint32_t *)(&FlexRAM[offset]) != value) {
213 *(uint32_t *)(&FlexRAM[offset]) = value;
214 flexram_wait();
215 }
216 return;
217#ifdef HANDLE_UNALIGNED_WRITES
218 case 2:
219 if (*(uint16_t *)(&FlexRAM[offset]) != value) {
220 *(uint16_t *)(&FlexRAM[offset]) = value;
221 flexram_wait();
222 }
223 if (*(uint16_t *)(&FlexRAM[offset + 2]) != (value >> 16)) {
224 *(uint16_t *)(&FlexRAM[offset + 2]) = value >> 16;
225 flexram_wait();
226 }
227 return;
228 default:
229 if (FlexRAM[offset] != value) {
230 FlexRAM[offset] = value;
231 flexram_wait();
232 }
233 if (*(uint16_t *)(&FlexRAM[offset + 1]) != (value >> 8)) {
234 *(uint16_t *)(&FlexRAM[offset + 1]) = value >> 8;
235 flexram_wait();
236 }
237 if (FlexRAM[offset + 3] != (value >> 24)) {
238 FlexRAM[offset + 3] = value >> 24;
239 flexram_wait();
240 }
241 }
242#endif
243}
244
245void eeprom_write_block(const void *buf, void *addr, uint32_t len)
246{
247 uint32_t offset = (uint32_t)addr;
248 const uint8_t *src = (const uint8_t *)buf;
249
250 if (offset >= EEPROM_SIZE) return;
251 if (!(FTFL->FCNFG & FTFL_FCNFG_EEERDY)) eeprom_initialize();
252 if (len >= EEPROM_SIZE) len = EEPROM_SIZE;
253 if (offset + len >= EEPROM_SIZE) len = EEPROM_SIZE - offset;
254 while (len > 0) {
255 uint32_t lsb = offset & 3;
256 if (lsb == 0 && len >= 4) {
257 // write aligned 32 bits
258 uint32_t val32;
259 val32 = *src++;
260 val32 |= (*src++ << 8);
261 val32 |= (*src++ << 16);
262 val32 |= (*src++ << 24);
263 if (*(uint32_t *)(&FlexRAM[offset]) != val32) {
264 *(uint32_t *)(&FlexRAM[offset]) = val32;
265 flexram_wait();
266 }
267 offset += 4;
268 len -= 4;
269 } else if ((lsb == 0 || lsb == 2) && len >= 2) {
270 // write aligned 16 bits
271 uint16_t val16;
272 val16 = *src++;
273 val16 |= (*src++ << 8);
274 if (*(uint16_t *)(&FlexRAM[offset]) != val16) {
275 *(uint16_t *)(&FlexRAM[offset]) = val16;
276 flexram_wait();
277 }
278 offset += 2;
279 len -= 2;
280 } else {
281 // write 8 bits
282 uint8_t val8 = *src++;
283 if (FlexRAM[offset] != val8) {
284 FlexRAM[offset] = val8;
285 flexram_wait();
286 }
287 offset++;
288 len--;
289 }
290 }
291}
292
293/*
294void do_flash_cmd(volatile uint8_t *fstat)
295{
296 *fstat = 0x80;
297 while ((*fstat & 0x80) == 0) ; // wait
298}
29900000000 <do_flash_cmd>:
300 0: f06f 037f mvn.w r3, #127 ; 0x7f
301 4: 7003 strb r3, [r0, #0]
302 6: 7803 ldrb r3, [r0, #0]
303 8: f013 0f80 tst.w r3, #128 ; 0x80
304 c: d0fb beq.n 6 <do_flash_cmd+0x6>
305 e: 4770 bx lr
306*/
307
308#elif defined(KL2x) /* chip selection */
309/* Teensy LC (emulated) */
310
311#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
312
313extern uint32_t __eeprom_workarea_start__;
314extern uint32_t __eeprom_workarea_end__;
315
316#define EEPROM_SIZE 128
317
318static uint32_t flashend = 0;
319
320void eeprom_initialize(void)
321{
322 const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
323
324 do {
325 if (*p++ == 0xFFFF) {
326 flashend = (uint32_t)(p - 2);
327 return;
328 }
329 } while (p < (uint16_t *)SYMVAL(__eeprom_workarea_end__));
330 flashend = (uint32_t)((uint16_t *)SYMVAL(__eeprom_workarea_end__) - 1);
331}
332
333uint8_t eeprom_read_byte(const uint8_t *addr)
334{
335 uint32_t offset = (uint32_t)addr;
336 const uint16_t *p = (uint16_t *)SYMVAL(__eeprom_workarea_start__);
337 const uint16_t *end = (const uint16_t *)((uint32_t)flashend);
338 uint16_t val;
339 uint8_t data=0xFF;
340
341 if (!end) {
342 eeprom_initialize();
343 end = (const uint16_t *)((uint32_t)flashend);
344 }
345 if (offset < EEPROM_SIZE) {
346 while (p <= end) {
347 val = *p++;
348 if ((val & 255) == offset) data = val >> 8;
349 }
350 }
351 return data;
352}
353
354static void flash_write(const uint16_t *code, uint32_t addr, uint32_t data)
355{
356 // with great power comes great responsibility....
357 uint32_t stat;
358 *(uint32_t *)&(FTFA->FCCOB3) = 0x06000000 | (addr & 0x00FFFFFC);
359 *(uint32_t *)&(FTFA->FCCOB7) = data;
360 __disable_irq();
361 (*((void (*)(volatile uint8_t *))((uint32_t)code | 1)))(&(FTFA->FSTAT));
362 __enable_irq();
363 stat = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR|FTFA_FSTAT_ACCERR|FTFA_FSTAT_FPVIOL);
364 if (stat) {
365 FTFA->FSTAT = stat;
366 }
367 MCM->PLACR |= MCM_PLACR_CFCC;
368}
369
370void eeprom_write_byte(uint8_t *addr, uint8_t data)
371{
372 uint32_t offset = (uint32_t)addr;
373 const uint16_t *p, *end = (const uint16_t *)((uint32_t)flashend);
374 uint32_t i, val, flashaddr;
375 uint16_t do_flash_cmd[] = {
376 0x2380, 0x7003, 0x7803, 0xb25b, 0x2b00, 0xdafb, 0x4770};
377 uint8_t buf[EEPROM_SIZE];
378
379 if (offset >= EEPROM_SIZE) return;
380 if (!end) {
381 eeprom_initialize();
382 end = (const uint16_t *)((uint32_t)flashend);
383 }
384 if (++end < (uint16_t *)SYMVAL(__eeprom_workarea_end__)) {
385 val = (data << 8) | offset;
386 flashaddr = (uint32_t)end;
387 flashend = flashaddr;
388 if ((flashaddr & 2) == 0) {
389 val |= 0xFFFF0000;
390 } else {
391 val <<= 16;
392 val |= 0x0000FFFF;
393 }
394 flash_write(do_flash_cmd, flashaddr, val);
395 } else {
396 for (i=0; i < EEPROM_SIZE; i++) {
397 buf[i] = 0xFF;
398 }
399 val = 0;
400 for (p = (uint16_t *)SYMVAL(__eeprom_workarea_start__); p < (uint16_t *)SYMVAL(__eeprom_workarea_end__); p++) {
401 val = *p;
402 if ((val & 255) < EEPROM_SIZE) {
403 buf[val & 255] = val >> 8;
404 }
405 }
406 buf[offset] = data;
407 for (flashaddr=(uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__); flashaddr < (uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_end__); flashaddr += 1024) {
408 *(uint32_t *)&(FTFA->FCCOB3) = 0x09000000 | flashaddr;
409 __disable_irq();
410 (*((void (*)(volatile uint8_t *))((uint32_t)do_flash_cmd | 1)))(&(FTFA->FSTAT));
411 __enable_irq();
412 val = FTFA->FSTAT & (FTFA_FSTAT_RDCOLERR|FTFA_FSTAT_ACCERR|FTFA_FSTAT_FPVIOL);;
413 if (val) FTFA->FSTAT = val;
414 MCM->PLACR |= MCM_PLACR_CFCC;
415 }
416 flashaddr=(uint32_t)(uint16_t *)SYMVAL(__eeprom_workarea_start__);
417 for (i=0; i < EEPROM_SIZE; i++) {
418 if (buf[i] == 0xFF) continue;
419 if ((flashaddr & 2) == 0) {
420 val = (buf[i] << 8) | i;
421 } else {
422 val = val | (buf[i] << 24) | (i << 16);
423 flash_write(do_flash_cmd, flashaddr, val);
424 }
425 flashaddr += 2;
426 }
427 flashend = flashaddr;
428 if ((flashaddr & 2)) {
429 val |= 0xFFFF0000;
430 flash_write(do_flash_cmd, flashaddr, val);
431 }
432 }
433}
434
435/*
436void do_flash_cmd(volatile uint8_t *fstat)
437{
438 *fstat = 0x80;
439 while ((*fstat & 0x80) == 0) ; // wait
440}
44100000000 <do_flash_cmd>:
442 0: 2380 movs r3, #128 ; 0x80
443 2: 7003 strb r3, [r0, #0]
444 4: 7803 ldrb r3, [r0, #0]
445 6: b25b sxtb r3, r3
446 8: 2b00 cmp r3, #0
447 a: dafb bge.n 4 <do_flash_cmd+0x4>
448 c: 4770 bx lr
449*/
450
451
452uint16_t eeprom_read_word(const uint16_t *addr)
453{
454 const uint8_t *p = (const uint8_t *)addr;
455 return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
456}
457
458uint32_t eeprom_read_dword(const uint32_t *addr)
459{
460 const uint8_t *p = (const uint8_t *)addr;
461 return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
462 | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
463}
464
465void eeprom_read_block(void *buf, const void *addr, uint32_t len)
466{
467 const uint8_t *p = (const uint8_t *)addr;
468 uint8_t *dest = (uint8_t *)buf;
469 while (len--) {
470 *dest++ = eeprom_read_byte(p++);
471 }
472}
473
474int eeprom_is_ready(void)
475{
476 return 1;
477}
478
479void eeprom_write_word(uint16_t *addr, uint16_t value)
480{
481 uint8_t *p = (uint8_t *)addr;
482 eeprom_write_byte(p++, value);
483 eeprom_write_byte(p, value >> 8);
484}
485
486void eeprom_write_dword(uint32_t *addr, uint32_t value)
487{
488 uint8_t *p = (uint8_t *)addr;
489 eeprom_write_byte(p++, value);
490 eeprom_write_byte(p++, value >> 8);
491 eeprom_write_byte(p++, value >> 16);
492 eeprom_write_byte(p, value >> 24);
493}
494
495void eeprom_write_block(const void *buf, void *addr, uint32_t len)
496{
497 uint8_t *p = (uint8_t *)addr;
498 const uint8_t *src = (const uint8_t *)buf;
499 while (len--) {
500 eeprom_write_byte(p++, *src++);
501 }
502}
503
504#else
505// No EEPROM supported, so emulate it
506
507#define EEPROM_SIZE 32
508static uint8_t buffer[EEPROM_SIZE];
509
510uint8_t eeprom_read_byte(const uint8_t *addr) {
511 uint32_t offset = (uint32_t)addr;
512 return buffer[offset];
513}
514
515void eeprom_write_byte(uint8_t *addr, uint8_t value) {
516 uint32_t offset = (uint32_t)addr;
517 buffer[offset] = value;
518}
519
520uint16_t eeprom_read_word(const uint16_t *addr) {
521 const uint8_t *p = (const uint8_t *)addr;
522 return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8);
523}
524
525uint32_t eeprom_read_dword(const uint32_t *addr) {
526 const uint8_t *p = (const uint8_t *)addr;
527 return eeprom_read_byte(p) | (eeprom_read_byte(p+1) << 8)
528 | (eeprom_read_byte(p+2) << 16) | (eeprom_read_byte(p+3) << 24);
529}
530
531void eeprom_read_block(void *buf, const void *addr, uint32_t len) {
532 const uint8_t *p = (const uint8_t *)addr;
533 uint8_t *dest = (uint8_t *)buf;
534 while (len--) {
535 *dest++ = eeprom_read_byte(p++);
536 }
537}
538
539void eeprom_write_word(uint16_t *addr, uint16_t value) {
540 uint8_t *p = (uint8_t *)addr;
541 eeprom_write_byte(p++, value);
542 eeprom_write_byte(p, value >> 8);
543}
544
545void eeprom_write_dword(uint32_t *addr, uint32_t value) {
546 uint8_t *p = (uint8_t *)addr;
547 eeprom_write_byte(p++, value);
548 eeprom_write_byte(p++, value >> 8);
549 eeprom_write_byte(p++, value >> 16);
550 eeprom_write_byte(p, value >> 24);
551}
552
553void eeprom_write_block(const void *buf, void *addr, uint32_t len) {
554 uint8_t *p = (uint8_t *)addr;
555 const uint8_t *src = (const uint8_t *)buf;
556 while (len--) {
557 eeprom_write_byte(p++, *src++);
558 }
559}
560
561#endif /* chip selection */
562// The update functions just calls write for now, but could probably be optimized
563
564void eeprom_update_byte(uint8_t *addr, uint8_t value) {
565 eeprom_write_byte(addr, value);
566}
567
568void eeprom_update_word(uint16_t *addr, uint16_t value) {
569 uint8_t *p = (uint8_t *)addr;
570 eeprom_write_byte(p++, value);
571 eeprom_write_byte(p, value >> 8);
572}
573
574void eeprom_update_dword(uint32_t *addr, uint32_t value) {
575 uint8_t *p = (uint8_t *)addr;
576 eeprom_write_byte(p++, value);
577 eeprom_write_byte(p++, value >> 8);
578 eeprom_write_byte(p++, value >> 16);
579 eeprom_write_byte(p, value >> 24);
580}
581
582void eeprom_update_block(const void *buf, void *addr, uint32_t len) {
583 uint8_t *p = (uint8_t *)addr;
584 const uint8_t *src = (const uint8_t *)buf;
585 while (len--) {
586 eeprom_write_byte(p++, *src++);
587 }
588}
diff --git a/tmk_core/common/chibios/printf.c b/tmk_core/common/chibios/printf.c
new file mode 100644
index 000000000..72e3d4f8c
--- /dev/null
+++ b/tmk_core/common/chibios/printf.c
@@ -0,0 +1,240 @@
1/*
2 * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
3 * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
4 */
5
6/*
7File: printf.c
8
9Copyright (C) 2004 Kustaa Nyholm
10
11This library is free software; you can redistribute it and/or
12modify it under the terms of the GNU Lesser General Public
13License as published by the Free Software Foundation; either
14version 2.1 of the License, or (at your option) any later version.
15
16This library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public
22License along with this library; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25*/
26
27#include "printf.h"
28
29typedef void (*putcf) (void*,char);
30static putcf stdout_putf;
31static void* stdout_putp;
32
33// this adds cca 400 bytes
34#define PRINTF_LONG_SUPPORT
35
36#ifdef PRINTF_LONG_SUPPORT
37
38static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
39 {
40 int n=0;
41 unsigned int d=1;
42 while (num/d >= base)
43 d*=base;
44 while (d!=0) {
45 int dgt = num / d;
46 num%=d;
47 d/=base;
48 if (n || dgt>0|| d==0) {
49 *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
50 ++n;
51 }
52 }
53 *bf=0;
54 }
55
56static void li2a (long num, char * bf)
57 {
58 if (num<0) {
59 num=-num;
60 *bf++ = '-';
61 }
62 uli2a(num,10,0,bf);
63 }
64
65#endif
66
67static void ui2a(unsigned int num, unsigned int base, int uc,char * bf)
68 {
69 int n=0;
70 unsigned int d=1;
71 while (num/d >= base)
72 d*=base;
73 while (d!=0) {
74 int dgt = num / d;
75 num%= d;
76 d/=base;
77 if (n || dgt>0 || d==0) {
78 *bf++ = dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10);
79 ++n;
80 }
81 }
82 *bf=0;
83 }
84
85static void i2a (int num, char * bf)
86 {
87 if (num<0) {
88 num=-num;
89 *bf++ = '-';
90 }
91 ui2a(num,10,0,bf);
92 }
93
94static int a2d(char ch)
95 {
96 if (ch>='0' && ch<='9')
97 return ch-'0';
98 else if (ch>='a' && ch<='f')
99 return ch-'a'+10;
100 else if (ch>='A' && ch<='F')
101 return ch-'A'+10;
102 else return -1;
103 }
104
105static char a2i(char ch, char** src,int base,int* nump)
106 {
107 char* p= *src;
108 int num=0;
109 int digit;
110 while ((digit=a2d(ch))>=0) {
111 if (digit>base) break;
112 num=num*base+digit;
113 ch=*p++;
114 }
115 *src=p;
116 *nump=num;
117 return ch;
118 }
119
120static void putchw(void* putp,putcf putf,int n, char z, char* bf)
121 {
122 char fc=z? '0' : ' ';
123 char ch;
124 char* p=bf;
125 while (*p++ && n > 0)
126 n--;
127 while (n-- > 0)
128 putf(putp,fc);
129 while ((ch= *bf++))
130 putf(putp,ch);
131 }
132
133void tfp_format(void* putp,putcf putf,char *fmt, va_list va)
134 {
135 char bf[12];
136
137 char ch;
138
139
140 while ((ch=*(fmt++))) {
141 if (ch!='%')
142 putf(putp,ch);
143 else {
144 char lz=0;
145#ifdef PRINTF_LONG_SUPPORT
146 char lng=0;
147#endif
148 int w=0;
149 ch=*(fmt++);
150 if (ch=='0') {
151 ch=*(fmt++);
152 lz=1;
153 }
154 if (ch>='0' && ch<='9') {
155 ch=a2i(ch,&fmt,10,&w);
156 }
157#ifdef PRINTF_LONG_SUPPORT
158 if (ch=='l') {
159 ch=*(fmt++);
160 lng=1;
161 }
162#endif
163 switch (ch) {
164 case 0:
165 goto abort;
166 case 'u' : {
167#ifdef PRINTF_LONG_SUPPORT
168 if (lng)
169 uli2a(va_arg(va, unsigned long int),10,0,bf);
170 else
171#endif
172 ui2a(va_arg(va, unsigned int),10,0,bf);
173 putchw(putp,putf,w,lz,bf);
174 break;
175 }
176 case 'd' : {
177#ifdef PRINTF_LONG_SUPPORT
178 if (lng)
179 li2a(va_arg(va, unsigned long int),bf);
180 else
181#endif
182 i2a(va_arg(va, int),bf);
183 putchw(putp,putf,w,lz,bf);
184 break;
185 }
186 case 'x': case 'X' :
187#ifdef PRINTF_LONG_SUPPORT
188 if (lng)
189 uli2a(va_arg(va, unsigned long int),16,(ch=='X'),bf);
190 else
191#endif
192 ui2a(va_arg(va, unsigned int),16,(ch=='X'),bf);
193 putchw(putp,putf,w,lz,bf);
194 break;
195 case 'c' :
196 putf(putp,(char)(va_arg(va, int)));
197 break;
198 case 's' :
199 putchw(putp,putf,w,0,va_arg(va, char*));
200 break;
201 case '%' :
202 putf(putp,ch);
203 default:
204 break;
205 }
206 }
207 }
208 abort:;
209 }
210
211
212void init_printf(void* putp,void (*putf) (void*,char))
213 {
214 stdout_putf=putf;
215 stdout_putp=putp;
216 }
217
218void tfp_printf(char *fmt, ...)
219 {
220 va_list va;
221 va_start(va,fmt);
222 tfp_format(stdout_putp,stdout_putf,fmt,va);
223 va_end(va);
224 }
225
226static void putcp(void* p,char c)
227 {
228 *(*((char**)p))++ = c;
229 }
230
231
232
233void tfp_sprintf(char* s,char *fmt, ...)
234 {
235 va_list va;
236 va_start(va,fmt);
237 tfp_format(&s,putcp,fmt,va);
238 putcp(&s,0);
239 va_end(va);
240 }
diff --git a/tmk_core/common/chibios/printf.h b/tmk_core/common/chibios/printf.h
new file mode 100644
index 000000000..678a100c6
--- /dev/null
+++ b/tmk_core/common/chibios/printf.h
@@ -0,0 +1,111 @@
1/*
2 * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
3 * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
4 */
5
6/*
7File: printf.h
8
9Copyright (C) 2004 Kustaa Nyholm
10
11This library is free software; you can redistribute it and/or
12modify it under the terms of the GNU Lesser General Public
13License as published by the Free Software Foundation; either
14version 2.1 of the License, or (at your option) any later version.
15
16This library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19See the GNU Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public
22License along with this library; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25This library is realy just two files: 'printf.h' and 'printf.c'.
26
27They provide a simple and small (+200 loc) printf functionality to
28be used in embedded systems.
29
30I've found them so usefull in debugging that I do not bother with a
31debugger at all.
32
33They are distributed in source form, so to use them, just compile them
34into your project.
35
36Two printf variants are provided: printf and sprintf.
37
38The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
39
40Zero padding and field width are also supported.
41
42If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
43long specifier is also
44supported. Note that this will pull in some long math routines (pun intended!)
45and thus make your executable noticably longer.
46
47The memory foot print of course depends on the target cpu, compiler and
48compiler options, but a rough guestimate (based on a H8S target) is about
491.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
50Not too bad. Your milage may vary. By hacking the source code you can
51get rid of some hunred bytes, I'm sure, but personally I feel the balance of
52functionality and flexibility versus code size is close to optimal for
53many embedded systems.
54
55To use the printf you need to supply your own character output function,
56something like :
57
58 void putc ( void* p, char c)
59 {
60 while (!SERIAL_PORT_EMPTY) ;
61 SERIAL_PORT_TX_REGISTER = c;
62 }
63
64Before you can call printf you need to initialize it to use your
65character output function with something like:
66
67 init_printf(NULL,putc);
68
69Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
70the NULL (or any pointer) you pass into the 'init_printf' will eventually be
71passed to your 'putc' routine. This allows you to pass some storage space (or
72anything realy) to the character output function, if necessary.
73This is not often needed but it was implemented like that because it made
74implementing the sprintf function so neat (look at the source code).
75
76The code is re-entrant, except for the 'init_printf' function, so it
77is safe to call it from interupts too, although this may result in mixed output.
78If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
79
80The printf and sprintf functions are actually macros that translate to
81'tfp_printf' and 'tfp_sprintf'. This makes it possible
82to use them along with 'stdio.h' printf's in a single source file.
83You just need to undef the names before you include the 'stdio.h'.
84Note that these are not function like macros, so if you have variables
85or struct members with these names, things will explode in your face.
86Without variadic macros this is the best we can do to wrap these
87fucnction. If it is a problem just give up the macros and use the
88functions directly or rename them.
89
90For further details see source code.
91
92regs Kusti, 23.10.2004
93*/
94
95
96#ifndef __TFP_PRINTF__
97#define __TFP_PRINTF__
98
99#include <stdarg.h>
100
101void init_printf(void* putp,void (*putf) (void*,char));
102
103void tfp_printf(char *fmt, ...);
104void tfp_sprintf(char* s,char *fmt, ...);
105
106void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
107
108#define printf tfp_printf
109#define sprintf tfp_sprintf
110
111#endif
diff --git a/tmk_core/common/chibios/sleep_led.c b/tmk_core/common/chibios/sleep_led.c
new file mode 100644
index 000000000..4c35cfcba
--- /dev/null
+++ b/tmk_core/common/chibios/sleep_led.c
@@ -0,0 +1,226 @@
1#include "ch.h"
2#include "hal.h"
3
4#include "led.h"
5#include "sleep_led.h"
6
7/* All right, we go the "software" way: timer, toggle LED in interrupt.
8 * Based on hasu's code for AVRs.
9 * Use LP timer on Kinetises, TIM14 on STM32F0.
10 */
11
12#if defined(KL2x) || defined(K20x)
13
14/* Use Low Power Timer (LPTMR) */
15#define TIMER_INTERRUPT_VECTOR KINETIS_LPTMR0_IRQ_VECTOR
16#define RESET_COUNTER LPTMR0->CSR |= LPTMRx_CSR_TCF
17
18#elif defined(STM32F0XX)
19
20/* Use TIM14 manually */
21#define TIMER_INTERRUPT_VECTOR STM32_TIM14_HANDLER
22#define RESET_COUNTER STM32_TIM14->SR &= ~STM32_TIM_SR_UIF
23
24#endif
25
26#if defined(KL2x) || defined(K20x) || defined(STM32F0XX) /* common parts for timers/interrupts */
27
28/* Breathing Sleep LED brighness(PWM On period) table
29 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
30 *
31 * http://www.wolframalpha.com/input/?i=%28sin%28+x%2F64*pi%29**8+*+255%2C+x%3D0+to+63
32 * (0..63).each {|x| p ((sin(x/64.0*PI)**8)*255).to_i }
33 */
34static const uint8_t breathing_table[64] = {
350, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10,
3615, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252,
37255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23,
3815, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
39};
40
41/* interrupt handler */
42OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) {
43 OSAL_IRQ_PROLOGUE();
44
45 /* Software PWM
46 * timer:1111 1111 1111 1111
47 * \_____/\/ \_______/____ count(0-255)
48 * \ \______________ duration of step(4)
49 * \__________________ index of step table(0-63)
50 */
51
52 // this works for cca 65536 irqs/sec
53 static union {
54 uint16_t row;
55 struct {
56 uint8_t count:8;
57 uint8_t duration:2;
58 uint8_t index:6;
59 } pwm;
60 } timer = { .row = 0 };
61
62 timer.row++;
63
64 // LED on
65 if (timer.pwm.count == 0) {
66 led_set(1<<USB_LED_CAPS_LOCK);
67 }
68 // LED off
69 if (timer.pwm.count == breathing_table[timer.pwm.index]) {
70 led_set(0);
71 }
72
73 /* Reset the counter */
74 RESET_COUNTER;
75
76 OSAL_IRQ_EPILOGUE();
77}
78
79#endif /* common parts for known platforms */
80
81
82#if defined(KL2x) || defined(K20x) /* platform selection: familiar Kinetis chips */
83
84/* LPTMR clock options */
85#define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */
86#define LPTMR_CLOCK_LPO 1 /* 1kHz clock */
87#define LPTMR_CLOCK_ERCLK32K 2 /* external 32kHz crystal */
88#define LPTMR_CLOCK_OSCERCLK 3 /* output from OSC */
89
90/* Work around inconsistencies in Freescale naming */
91#if !defined(SIM_SCGC5_LPTMR)
92#define SIM_SCGC5_LPTMR SIM_SCGC5_LPTIMER
93#endif
94
95/* Initialise the timer */
96void sleep_led_init(void) {
97 /* Make sure the clock to the LPTMR is enabled */
98 SIM->SCGC5 |= SIM_SCGC5_LPTMR;
99 /* Reset LPTMR settings */
100 LPTMR0->CSR = 0;
101 /* Set the compare value */
102 LPTMR0->CMR = 0; // trigger on counter value (i.e. every time)
103
104 /* Set up clock source and prescaler */
105 /* Software PWM
106 * ______ ______ __
107 * | ON |___OFF___| ON |___OFF___| ....
108 * |<-------------->|<-------------->|<- ....
109 * PWM period PWM period
110 *
111 * R interrupts/period[resolution]
112 * F periods/second[frequency]
113 * R * F interrupts/second
114 */
115
116 /* === OPTION 1 === */
117 #if 0
118 // 1kHz LPO
119 // No prescaler => 1024 irqs/sec
120 // Note: this is too slow for a smooth breathe
121 LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_LPO)|LPTMRx_PSR_PBYP;
122 #endif /* OPTION 1 */
123
124 /* === OPTION 2 === */
125 #if 1
126 // nMHz IRC (n=4 on KL25Z, KL26Z and K20x; n=2 or 8 on KL27Z)
127 MCG->C2 |= MCG_C2_IRCS; // fast (4MHz) internal ref clock
128 #if defined(KL27) // divide the 8MHz IRC by 2, to have the same MCGIRCLK speed as others
129 MCG->MC |= MCG_MC_LIRC_DIV2_DIV2;
130 #endif /* KL27 */
131 MCG->C1 |= MCG_C1_IRCLKEN; // enable internal ref clock
132 // to work in stop mode, also MCG_C1_IREFSTEN
133 // Divide 4MHz by 2^N (N=6) => 62500 irqs/sec =>
134 // => approx F=61, R=256, duration = 4
135 LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_MCGIRCLK)|LPTMRx_PSR_PRESCALE(6);
136 #endif /* OPTION 2 */
137
138 /* === OPTION 3 === */
139 #if 0
140 // OSC output (external crystal), usually 8MHz or 16MHz
141 OSC0->CR |= OSC_CR_ERCLKEN; // enable ext ref clock
142 // to work in stop mode, also OSC_CR_EREFSTEN
143 // Divide by 2^N
144 LPTMR0->PSR = LPTMRx_PSR_PCS(LPTMR_CLOCK_OSCERCLK)|LPTMRx_PSR_PRESCALE(7);
145 #endif /* OPTION 3 */
146 /* === END OPTIONS === */
147
148 /* Interrupt on TCF set (compare flag) */
149 nvicEnableVector(LPTMR0_IRQn, 2); // vector, priority
150 LPTMR0->CSR |= LPTMRx_CSR_TIE;
151}
152
153void sleep_led_enable(void) {
154 /* Enable the timer */
155 LPTMR0->CSR |= LPTMRx_CSR_TEN;
156}
157
158void sleep_led_disable(void) {
159 /* Disable the timer */
160 LPTMR0->CSR &= ~LPTMRx_CSR_TEN;
161}
162
163void sleep_led_toggle(void) {
164 /* Toggle the timer */
165 LPTMR0->CSR ^= LPTMRx_CSR_TEN;
166}
167
168#elif defined(STM32F0XX) /* platform selection: STM32F0XX */
169
170/* Initialise the timer */
171void sleep_led_init(void) {
172 /* enable clock */
173 rccEnableTIM14(FALSE); /* low power enable = FALSE */
174 rccResetTIM14();
175
176 /* prescale */
177 /* Assuming 48MHz internal clock */
178 /* getting cca 65484 irqs/sec */
179 STM32_TIM14->PSC = 733;
180
181 /* auto-reload */
182 /* 0 => interrupt every time */
183 STM32_TIM14->ARR = 3;
184
185 /* enable counter update event interrupt */
186 STM32_TIM14->DIER |= STM32_TIM_DIER_UIE;
187
188 /* register interrupt vector */
189 nvicEnableVector(STM32_TIM14_NUMBER, 2); /* vector, priority */
190}
191
192void sleep_led_enable(void) {
193 /* Enable the timer */
194 STM32_TIM14->CR1 = STM32_TIM_CR1_CEN | STM32_TIM_CR1_URS;
195 /* URS => update event only on overflow; setting UG bit disabled */
196}
197
198void sleep_led_disable(void) {
199 /* Disable the timer */
200 STM32_TIM14->CR1 = 0;
201}
202
203void sleep_led_toggle(void) {
204 /* Toggle the timer */
205 STM32_TIM14->CR1 ^= STM32_TIM_CR1_CEN;
206}
207
208
209#else /* platform selection: not on familiar chips */
210
211void sleep_led_init(void) {
212}
213
214void sleep_led_enable(void) {
215 led_set(1<<USB_LED_CAPS_LOCK);
216}
217
218void sleep_led_disable(void) {
219 led_set(0);
220}
221
222void sleep_led_toggle(void) {
223 // not implemented
224}
225
226#endif /* platform selection */ \ No newline at end of file
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
new file mode 100644
index 000000000..6ca16034f
--- /dev/null
+++ b/tmk_core/common/chibios/suspend.c
@@ -0,0 +1,65 @@
1/* TODO */
2
3#include "ch.h"
4#include "hal.h"
5
6#include "matrix.h"
7#include "action.h"
8#include "action_util.h"
9#include "mousekey.h"
10#include "host.h"
11#include "backlight.h"
12#include "suspend.h"
13
14void suspend_idle(uint8_t time) {
15 // TODO: this is not used anywhere - what units is 'time' in?
16 chThdSleepMilliseconds(time);
17}
18
19void suspend_power_down(void) {
20 // TODO: figure out what to power down and how
21 // shouldn't power down TPM/FTM if we want a breathing LED
22 // also shouldn't power down USB
23
24 // on AVR, this enables the watchdog for 15ms (max), and goes to
25 // SLEEP_MODE_PWR_DOWN
26
27 chThdSleepMilliseconds(17);
28}
29
30__attribute__ ((weak)) void matrix_power_up(void) {}
31__attribute__ ((weak)) void matrix_power_down(void) {}
32bool suspend_wakeup_condition(void)
33{
34 matrix_power_up();
35 matrix_scan();
36 matrix_power_down();
37 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
38 if (matrix_get_row(r)) return true;
39 }
40 return false;
41}
42
43// run immediately after wakeup
44void suspend_wakeup_init(void)
45{
46 // clear keyboard state
47 // need to do it manually, because we're running from ISR
48 // and clear_keyboard() calls print
49 // so only clear the variables in memory
50 // the reports will be sent from main.c afterwards
51 // or if the PC asks for GET_REPORT
52 clear_mods();
53 clear_weak_mods();
54 clear_keys();
55#ifdef MOUSEKEY_ENABLE
56 mousekey_clear();
57#endif /* MOUSEKEY_ENABLE */
58#ifdef EXTRAKEY_ENABLE
59 host_system_send(0);
60 host_consumer_send(0);
61#endif /* EXTRAKEY_ENABLE */
62#ifdef BACKLIGHT_ENABLE
63 backlight_init();
64#endif /* BACKLIGHT_ENABLE */
65}
diff --git a/tmk_core/common/chibios/timer.c b/tmk_core/common/chibios/timer.c
new file mode 100644
index 000000000..3de4cc368
--- /dev/null
+++ b/tmk_core/common/chibios/timer.c
@@ -0,0 +1,27 @@
1#include "ch.h"
2
3#include "timer.h"
4
5void timer_init(void) {}
6
7void timer_clear(void) {}
8
9uint16_t timer_read(void)
10{
11 return (uint16_t)ST2MS(chVTGetSystemTime());
12}
13
14uint32_t timer_read32(void)
15{
16 return ST2MS(chVTGetSystemTime());
17}
18
19uint16_t timer_elapsed(uint16_t last)
20{
21 return (uint16_t)(ST2MS(chVTTimeElapsedSinceX(MS2ST(last))));
22}
23
24uint32_t timer_elapsed32(uint32_t last)
25{
26 return ST2MS(chVTTimeElapsedSinceX(MS2ST(last)));
27}
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 187a2b949..084c9fe15 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <stdint.h> 17#include <stdint.h>
18#include <stdbool.h> 18#include <stdbool.h>
19#include <util/delay.h> 19#include "wait.h"
20#include "keycode.h" 20#include "keycode.h"
21#include "host.h" 21#include "host.h"
22#include "keymap.h" 22#include "keymap.h"
@@ -103,12 +103,14 @@ bool command_proc(uint8_t code)
103bool command_extra(uint8_t code) __attribute__ ((weak)); 103bool command_extra(uint8_t code) __attribute__ ((weak));
104bool command_extra(uint8_t code) 104bool command_extra(uint8_t code)
105{ 105{
106 (void)code;
106 return false; 107 return false;
107} 108}
108 109
109bool command_console_extra(uint8_t code) __attribute__ ((weak)); 110bool command_console_extra(uint8_t code) __attribute__ ((weak));
110bool command_console_extra(uint8_t code) 111bool command_console_extra(uint8_t code)
111{ 112{
113 (void)code;
112 return false; 114 return false;
113} 115}
114 116
@@ -217,8 +219,11 @@ static void print_version(void)
217 " " STR(BOOTLOADER_SIZE) "\n"); 219 " " STR(BOOTLOADER_SIZE) "\n");
218 220
219 print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) 221 print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)
222#if defined(__AVR__)
220 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ 223 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
221 " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n"); 224 " AVR_ARCH: avr" STR(__AVR_ARCH__)
225#endif
226 "\n");
222 227
223 return; 228 return;
224} 229}
@@ -234,7 +239,7 @@ static void print_status(void)
234#ifdef NKRO_ENABLE 239#ifdef NKRO_ENABLE
235 print_val_hex8(keyboard_nkro); 240 print_val_hex8(keyboard_nkro);
236#endif 241#endif
237 print_val_hex32(timer_count); 242 print_val_hex32(timer_read32());
238 243
239#ifdef PROTOCOL_PJRC 244#ifdef PROTOCOL_PJRC
240 print_val_hex8(UDCON); 245 print_val_hex8(UDCON);
@@ -360,7 +365,7 @@ static bool command_common(uint8_t code)
360 stop_all_notes(); 365 stop_all_notes();
361 shutdown_user(); 366 shutdown_user();
362 #else 367 #else
363 _delay_ms(1000); 368 wait_ms(1000);
364 #endif 369 #endif
365 bootloader_jump(); // not return 370 bootloader_jump(); // not return
366 break; 371 break;
@@ -430,10 +435,11 @@ static bool command_common(uint8_t code)
430 case MAGIC_KC(MAGIC_KEY_NKRO): 435 case MAGIC_KC(MAGIC_KEY_NKRO):
431 clear_keyboard(); // clear to prevent stuck keys 436 clear_keyboard(); // clear to prevent stuck keys
432 keyboard_nkro = !keyboard_nkro; 437 keyboard_nkro = !keyboard_nkro;
433 if (keyboard_nkro) 438 if (keyboard_nkro) {
434 print("NKRO: on\n"); 439 print("NKRO: on\n");
435 else 440 } else {
436 print("NKRO: off\n"); 441 print("NKRO: off\n");
442 }
437 break; 443 break;
438#endif 444#endif
439 445
@@ -750,10 +756,11 @@ static bool mousekey_console(uint8_t code)
750 print("?"); 756 print("?");
751 return false; 757 return false;
752 } 758 }
753 if (mousekey_param) 759 if (mousekey_param) {
754 xprintf("M%d> ", mousekey_param); 760 xprintf("M%d> ", mousekey_param);
755 else 761 } else {
756 print("M>" ); 762 print("M>" );
763 }
757 return true; 764 return true;
758} 765}
759#endif 766#endif
diff --git a/tmk_core/common/avr/eeconfig.c b/tmk_core/common/eeconfig.c
index 656938fb3..140d2b85b 100644
--- a/tmk_core/common/avr/eeconfig.c
+++ b/tmk_core/common/eeconfig.c
@@ -1,6 +1,6 @@
1#include <stdint.h> 1#include <stdint.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <avr/eeprom.h> 3#include "eeprom.h"
4#include "eeconfig.h" 4#include "eeconfig.h"
5 5
6void eeconfig_init(void) 6void eeconfig_init(void)
diff --git a/tmk_core/common/eeprom.h b/tmk_core/common/eeprom.h
new file mode 100644
index 000000000..2cc2ccee3
--- /dev/null
+++ b/tmk_core/common/eeprom.h
@@ -0,0 +1,22 @@
1#ifndef TMK_CORE_COMMON_EEPROM_H_
2#define TMK_CORE_COMMON_EEPROM_H_
3
4#if defined(__AVR__)
5#include <avr/eeprom.h>
6#else
7uint8_t eeprom_read_byte (const uint8_t *__p);
8uint16_t eeprom_read_word (const uint16_t *__p);
9uint32_t eeprom_read_dword (const uint32_t *__p);
10void eeprom_read_block (void *__dst, const void *__src, uint32_t __n);
11void eeprom_write_byte (uint8_t *__p, uint8_t __value);
12void eeprom_write_word (uint16_t *__p, uint16_t __value);
13void eeprom_write_dword (uint32_t *__p, uint32_t __value);
14void eeprom_write_block (const void *__src, void *__dst, uint32_t __n);
15void eeprom_update_byte (uint8_t *__p, uint8_t __value);
16void eeprom_update_word (uint16_t *__p, uint16_t __value);
17void eeprom_update_dword (uint32_t *__p, uint32_t __value);
18void eeprom_update_block (const void *__src, void *__dst, uint32_t __n);
19#endif
20
21
22#endif /* TMK_CORE_COMMON_EEPROM_H_ */
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
index f21d1346c..194e4cc02 100644
--- a/tmk_core/common/magic.c
+++ b/tmk_core/common/magic.c
@@ -1,6 +1,8 @@
1#include <stdint.h> 1#include <stdint.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#if defined(__AVR__)
3#include <util/delay.h> 4#include <util/delay.h>
5#endif
4#include "matrix.h" 6#include "matrix.h"
5#include "bootloader.h" 7#include "bootloader.h"
6#include "debug.h" 8#include "debug.h"
@@ -33,4 +35,4 @@ void magic(void)
33 default_layer = eeconfig_read_default_layer(); 35 default_layer = eeconfig_read_default_layer();
34 default_layer_set((uint32_t)default_layer); 36 default_layer_set((uint32_t)default_layer);
35 37
36} \ No newline at end of file 38}
diff --git a/tmk_core/common/print.c b/tmk_core/common/print.c
index ca94e1e5d..00489557f 100644
--- a/tmk_core/common/print.c
+++ b/tmk_core/common/print.c
@@ -38,11 +38,15 @@ void print_set_sendchar(int8_t (*sendchar_func)(uint8_t))
38 xdev_out(sendchar_func); 38 xdev_out(sendchar_func);
39} 39}
40 40
41#elif defined(__arm__) 41#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
42
43// don't need anything extra
44
45#elif defined(__arm__) /* __AVR__ */
42 46
43// TODO 47// TODO
44//void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { } 48//void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { }
45 49
46#endif 50#endif /* __AVR__ */
47 51
48#endif 52#endif
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h
index 4f3dde65a..0368bcd4a 100644
--- a/tmk_core/common/print.h
+++ b/tmk_core/common/print.h
@@ -47,7 +47,15 @@ extern "C"
47/* function pointer of sendchar to be used by print utility */ 47/* function pointer of sendchar to be used by print utility */
48void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); 48void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
49 49
50#elif defined(__arm__) 50#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
51
52#include "chibios/printf.h"
53
54#define print(s) printf(s)
55#define println(s) printf(s "\r\n")
56#define xprintf printf
57
58#elif defined(__arm__) /* __AVR__ */
51 59
52#include "mbed/xprintf.h" 60#include "mbed/xprintf.h"
53 61
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h
index 199b1bedf..5b2765625 100644
--- a/tmk_core/common/progmem.h
+++ b/tmk_core/common/progmem.h
@@ -5,8 +5,8 @@
5# include <avr/pgmspace.h> 5# include <avr/pgmspace.h>
6#elif defined(__arm__) 6#elif defined(__arm__)
7# define PROGMEM 7# define PROGMEM
8# define pgm_read_byte(p) *(p) 8# define pgm_read_byte(p) *((unsigned char*)p)
9# define pgm_read_word(p) *(p) 9# define pgm_read_word(p) *((uint16_t*)p)
10#endif 10#endif
11 11
12#endif 12#endif
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index f6c0a315d..0c799eca3 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -84,6 +84,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
84# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE 84# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
85# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) 85# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
86# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) 86# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
87#elif defined(PROTOCOL_CHIBIOS) && defined(NKRO_ENABLE)
88# include "protocol/chibios/usb_main.h"
89# define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
90# define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
91# define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
87 92
88#else 93#else
89# define KEYBOARD_REPORT_SIZE 8 94# define KEYBOARD_REPORT_SIZE 8
diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h
index 40d00b0c7..82727be01 100644
--- a/tmk_core/common/wait.h
+++ b/tmk_core/common/wait.h
@@ -9,9 +9,13 @@ extern "C" {
9# include <util/delay.h> 9# include <util/delay.h>
10# define wait_ms(ms) _delay_ms(ms) 10# define wait_ms(ms) _delay_ms(ms)
11# define wait_us(us) _delay_us(us) 11# define wait_us(us) _delay_us(us)
12#elif defined(__arm__) 12#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
13# include "ch.h"
14# define wait_ms(ms) chThdSleepMilliseconds(ms)
15# define wait_us(us) chThdSleepMicroseconds(us)
16#elif defined(__arm__) /* __AVR__ */
13# include "wait_api.h" 17# include "wait_api.h"
14#endif 18#endif /* __AVR__ */
15 19
16#ifdef __cplusplus 20#ifdef __cplusplus
17} 21}
diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios.mk
new file mode 100644
index 000000000..3f4e0a71f
--- /dev/null
+++ b/tmk_core/protocol/chibios.mk
@@ -0,0 +1,10 @@
1PROTOCOL_DIR = protocol
2CHIBIOS_DIR = $(PROTOCOL_DIR)/chibios
3
4
5SRC += $(CHIBIOS_DIR)/usb_main.c
6SRC += $(CHIBIOS_DIR)/main.c
7
8VPATH += $(TMK_PATH)/$(PROTOCOL_DIR)
9VPATH += $(TMK_PATH)/$(CHIBIOS_DIR)
10
diff --git a/tmk_core/protocol/chibios/README.md b/tmk_core/protocol/chibios/README.md
new file mode 100644
index 000000000..63e6641f8
--- /dev/null
+++ b/tmk_core/protocol/chibios/README.md
@@ -0,0 +1,55 @@
1## TMK running on top of ChibiOS
2
3This code can be used to run TMK keyboard logic on top of [ChibiOS], meaning that you can run TMK on whatever [ChibiOS] supports. The notable examples are ARM-based Teensies (3.x and LC) and on the boards with STM32 MCUs.
4
5### Usage
6
7- To use, [get a zip of chibios](https://github.com/ChibiOS/ChibiOS/archive/a7df9a891067621e8e1a5c2a2c0ceada82403afe.zip) and unpack/rename it to `tmk_core/tool/chibios/chibios`; or you can just clone [the repo](https://github.com/ChibiOS/ChibiOS) there. For Freescale/NXP Kinetis support (meaning ARM Teensies and the Infinity keyboard), you'll also need [a zip of chibios-contrib](https://github.com/ChibiOS/ChibiOS-Contrib/archive/e1311c4db6cd366cf760673f769e925741ac0ad3.zip), unpacked/renamed to `tmk_core/tool/chibios/chibios-contrib`. Likewise, for git-savvy people, just clone [the repo](https://github.com/ChibiOS/ChibiOS-Contrib) there.
8- Note: the abovementioned directories are the defaults. You can have the two chibios repositories wherever you want, just define their location in `CHIBIOS` and `CHIBIOS_CONTRIB` variables in your `Makefile`.
9- You will also need to install an ARM toolchain, for instance from [here](https://launchpad.net/gcc-arm-embedded). On linux, this is usually also present as a package for your distribution (as `gcc-arm` or something similar). On OS X, you can use [homebrew](http://brew.sh/) with an appropriate tap.
10
11### Notes
12
13- Some comments about ChibiOS syntax and the most commonly used GPIO functions are, as well as an example for ARM Teensies, is [here](https://github.com/tmk/tmk_keyboard/blob/master/keyboard/teensy_lc_onekey/instructions.md).
14- For gcc options, inspect `tmk_core/tool/chibios/chibios.mk`. For instance, I enabled `-Wno-missing-field-initializers`, because TMK common bits generated a lot of warnings on that.
15- For debugging, it is sometimes useful disable gcc optimisations, you can do that by adding `-O0` to `OPT_DEFS` in your `Makefile`.
16- USB string descriptors are messy. I did not find a way to cleanly generate the right structures from actual strings, so the definitions in individual keyboards' `config.h` are ugly as heck.
17- It is easy to add some code for testing (e.g. blink LED, do stuff on button press, etc...) - just create another thread in `main.c`, it will run independently of the keyboard business.
18- Jumping to (the built-in) bootloaders on STM32 works, but it is not entirely pleasant, since it is very much MCU dependent. So, one needs to dig out the right address to jump to, and either pass it to the compiler in the `Makefile`, or better, define it in `<your_kb>/bootloader_defs.h`. An additional startup code is also needed; the best way to deal with this is to define custom board files. (Example forthcoming.) In any case, there are no problems for Teensies.
19
20
21### Immediate todo
22
23- power saving for suspend
24
25### Not tested, but possibly working
26
27- backlight
28
29### Missing / not working (TMK vs ChibiOS bits)
30
31- eeprom / bootmagic for STM32 (will be chip dependent; eeprom needs to be emulated in flash, which means less writes; wear-levelling?) There is a semi-official ST "driver" for eeprom, with wear-levelling, but I think it consumes a lot of RAM (like 2 pages, i.e. 1kB or so).
32
33### Tried with
34
35- Infinity, WhiteFox keyboards
36- all ARM-based Teensies
37- some STM32-based boards (e.g. ST-F072RB-DISCOVERY board, STM32F042 breakout board, Maple Mini (STM32F103-based))
38
39## ChibiOS-supported MCUs
40
41- Pretty much all STM32 chips.
42- K20x and KL2x Freescale/NXP chips (i.e. Teensy 3.x/LC, mchck, FRDM-KL2{5,6}Z, FRDM-K20D50M), via the [ChibiOS-Contrib](https://github.com/ChibiOS/ChibiOS-Contrib) repository.
43- There is also support for AVR8, but the USB stack is not implemented for them yet (some news on that front recently though), and also the kernel itself takes about 1k of RAM. I think people managed to get ChibiOS running on atmega32[8p/u4] though.
44- There is also support for Nordic NRF51822 (the chip in Adafruit's Bluefruit bluetooth-low-energy boards), but be aware that that chip does *not* have USB, and the BLE softdevice (i.e. Bluetooth) is not supported directly at the moment.
45
46## STM32-based keyboard design considerations
47
48- STM32F0x2 chips can do crystal-less USB, but they still need a 3.3V voltage regulator.
49- The BOOT0 pin should be tied to GND.
50- For a hardware way of accessing the in-built DFU bootloader, in addition to the reset button, put another button between the BOOT0 pin and 3V3.
51- There is a working example of a STM32F042-based keyboard: [firmware here](https://github.com/flabbergast/flabber_kbs/tree/master/kb45p) and [hardware (kicad) here](https://github.com/flabbergast/kicad/tree/master/kb45p). You can check this example firmware for custom board files, and a more complicated matrix than just one key.
52
53
54
55[ChibiOS]: http://chibios.org
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
new file mode 100644
index 000000000..54bb6a8f5
--- /dev/null
+++ b/tmk_core/protocol/chibios/main.c
@@ -0,0 +1,147 @@
1/*
2 * (c) 2015 flabberast <s3+flabbergast@sdfeu.org>
3 *
4 * Based on the following work:
5 * - Guillaume Duc's raw hid example (MIT License)
6 * https://github.com/guiduc/usb-hid-chibios-example
7 * - PJRC Teensy examples (MIT License)
8 * https://www.pjrc.com/teensy/usb_keyboard.html
9 * - hasu's TMK keyboard code (GPL v2 and some code Modified BSD)
10 * https://github.com/tmk/tmk_keyboard/
11 * - ChibiOS demo code (Apache 2.0 License)
12 * http://www.chibios.org
13 *
14 * Since some GPL'd code is used, this work is licensed under
15 * GPL v2 or later.
16 */
17
18#include "ch.h"
19#include "hal.h"
20
21#include "usb_main.h"
22
23/* TMK includes */
24#include "report.h"
25#include "host.h"
26#include "host_driver.h"
27#include "keyboard.h"
28#include "action.h"
29#include "action_util.h"
30#include "mousekey.h"
31#include "led.h"
32#include "sendchar.h"
33#include "debug.h"
34#include "printf.h"
35#ifdef SLEEP_LED_ENABLE
36#include "sleep_led.h"
37#endif
38#include "suspend.h"
39
40
41/* -------------------------
42 * TMK host driver defs
43 * -------------------------
44 */
45
46/* declarations */
47uint8_t keyboard_leds(void);
48void send_keyboard(report_keyboard_t *report);
49void send_mouse(report_mouse_t *report);
50void send_system(uint16_t data);
51void send_consumer(uint16_t data);
52
53/* host struct */
54host_driver_t chibios_driver = {
55 keyboard_leds,
56 send_keyboard,
57 send_mouse,
58 send_system,
59 send_consumer
60};
61
62
63/* TESTING
64 * Amber LED blinker thread, times are in milliseconds.
65 */
66/* set this variable to non-zero anywhere to blink once */
67// uint8_t blinkLed = 0;
68// static THD_WORKING_AREA(waBlinkerThread, 128);
69// static THD_FUNCTION(blinkerThread, arg) {
70// (void)arg;
71// chRegSetThreadName("blinkOrange");
72// while(true) {
73// if(blinkLed) {
74// blinkLed = 0;
75// palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
76// chThdSleepMilliseconds(100);
77// palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
78// }
79// chThdSleepMilliseconds(100);
80// }
81// }
82
83
84
85/* Main thread
86 */
87int main(void) {
88 /* ChibiOS/RT init */
89 halInit();
90 chSysInit();
91
92 // TESTING
93 // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);
94
95 /* Init USB */
96 init_usb_driver(&USB_DRIVER);
97
98 /* init printf */
99 init_printf(NULL,sendchar_pf);
100
101 /* Wait until the USB is active */
102 while(USB_DRIVER.state != USB_ACTIVE)
103 chThdSleepMilliseconds(50);
104
105 /* Do need to wait here!
106 * Otherwise the next print might start a transfer on console EP
107 * before the USB is completely ready, which sometimes causes
108 * HardFaults.
109 */
110 chThdSleepMilliseconds(50);
111
112 print("USB configured.\n");
113
114 /* init TMK modules */
115 keyboard_init();
116 host_set_driver(&chibios_driver);
117
118#ifdef SLEEP_LED_ENABLE
119 sleep_led_init();
120#endif
121
122 print("Keyboard start.\n");
123
124 /* Main loop */
125 while(true) {
126
127 if(USB_DRIVER.state == USB_SUSPENDED) {
128 print("[s]");
129 while(USB_DRIVER.state == USB_SUSPENDED) {
130 /* Do this in the suspended state */
131 suspend_power_down(); // on AVR this deep sleeps for 15ms
132 /* Remote wakeup */
133 if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
134 send_remote_wakeup(&USB_DRIVER);
135 }
136 }
137 /* Woken up */
138 // variables has been already cleared by the wakeup hook
139 send_keyboard_report();
140#ifdef MOUSEKEY_ENABLE
141 mousekey_send();
142#endif /* MOUSEKEY_ENABLE */
143 }
144
145 keyboard_task();
146 }
147}
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
new file mode 100644
index 000000000..e2c9d9bf1
--- /dev/null
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -0,0 +1,1372 @@
1/*
2 * (c) 2015 flabberast <s3+flabbergast@sdfeu.org>
3 *
4 * Based on the following work:
5 * - Guillaume Duc's raw hid example (MIT License)
6 * https://github.com/guiduc/usb-hid-chibios-example
7 * - PJRC Teensy examples (MIT License)
8 * https://www.pjrc.com/teensy/usb_keyboard.html
9 * - hasu's TMK keyboard code (GPL v2 and some code Modified BSD)
10 * https://github.com/tmk/tmk_keyboard/
11 * - ChibiOS demo code (Apache 2.0 License)
12 * http://www.chibios.org
13 *
14 * Since some GPL'd code is used, this work is licensed under
15 * GPL v2 or later.
16 */
17
18#include "ch.h"
19#include "hal.h"
20
21#include "usb_main.h"
22
23#include "host.h"
24#include "debug.h"
25#include "suspend.h"
26#ifdef SLEEP_LED_ENABLE
27#include "sleep_led.h"
28#include "led.h"
29#endif
30
31/* ---------------------------------------------------------
32 * Global interface variables and declarations
33 * ---------------------------------------------------------
34 */
35
36uint8_t keyboard_idle __attribute__((aligned(2))) = 0;
37uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
38uint16_t keyboard_led_stats __attribute__((aligned(2))) = 0;
39volatile uint16_t keyboard_idle_count = 0;
40static virtual_timer_t keyboard_idle_timer;
41static void keyboard_idle_timer_cb(void *arg);
42#ifdef NKRO_ENABLE
43extern bool keyboard_nkro;
44#endif /* NKRO_ENABLE */
45
46report_keyboard_t keyboard_report_sent = {{0}};
47#ifdef MOUSE_ENABLE
48report_mouse_t mouse_report_blank = {0};
49#endif /* MOUSE_ENABLE */
50#ifdef EXTRAKEY_ENABLE
51uint8_t extra_report_blank[3] = {0};
52#endif /* EXTRAKEY_ENABLE */
53
54#ifdef CONSOLE_ENABLE
55/* The emission buffers queue */
56output_buffers_queue_t console_buf_queue;
57static uint8_t console_queue_buffer[BQ_BUFFER_SIZE(CONSOLE_QUEUE_CAPACITY, CONSOLE_EPSIZE)];
58
59static virtual_timer_t console_flush_timer;
60void console_queue_onotify(io_buffers_queue_t *bqp);
61static void console_flush_cb(void *arg);
62#endif /* CONSOLE_ENABLE */
63
64/* ---------------------------------------------------------
65 * Descriptors and USB driver objects
66 * ---------------------------------------------------------
67 */
68
69/* HID specific constants */
70#define USB_DESCRIPTOR_HID 0x21
71#define USB_DESCRIPTOR_HID_REPORT 0x22
72#define HID_GET_REPORT 0x01
73#define HID_GET_IDLE 0x02
74#define HID_GET_PROTOCOL 0x03
75#define HID_SET_REPORT 0x09
76#define HID_SET_IDLE 0x0A
77#define HID_SET_PROTOCOL 0x0B
78
79/* USB Device Descriptor */
80static const uint8_t usb_device_descriptor_data[] = {
81 USB_DESC_DEVICE(0x0200, // bcdUSB (1.1)
82 0, // bDeviceClass (defined in later in interface)
83 0, // bDeviceSubClass
84 0, // bDeviceProtocol
85 64, // bMaxPacketSize (64 bytes) (the driver didn't work with 32)
86 VENDOR_ID, // idVendor
87 PRODUCT_ID, // idProduct
88 DEVICE_VER, // bcdDevice
89 1, // iManufacturer
90 2, // iProduct
91 3, // iSerialNumber
92 1) // bNumConfigurations
93};
94
95/* Device Descriptor wrapper */
96static const USBDescriptor usb_device_descriptor = {
97 sizeof usb_device_descriptor_data,
98 usb_device_descriptor_data
99};
100
101/*
102 * HID Report Descriptor
103 *
104 * See "Device Class Definition for Human Interface Devices (HID)"
105 * (http://www.usb.org/developers/hidpage/HID1_11.pdf) for the
106 * detailed descrition of all the fields
107 */
108
109/* Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60 */
110static const uint8_t keyboard_hid_report_desc_data[] = {
111 0x05, 0x01, // Usage Page (Generic Desktop),
112 0x09, 0x06, // Usage (Keyboard),
113 0xA1, 0x01, // Collection (Application),
114 0x75, 0x01, // Report Size (1),
115 0x95, 0x08, // Report Count (8),
116 0x05, 0x07, // Usage Page (Key Codes),
117 0x19, 0xE0, // Usage Minimum (224),
118 0x29, 0xE7, // Usage Maximum (231),
119 0x15, 0x00, // Logical Minimum (0),
120 0x25, 0x01, // Logical Maximum (1),
121 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
122 0x95, 0x01, // Report Count (1),
123 0x75, 0x08, // Report Size (8),
124 0x81, 0x03, // Input (Constant), ;Reserved byte
125 0x95, 0x05, // Report Count (5),
126 0x75, 0x01, // Report Size (1),
127 0x05, 0x08, // Usage Page (LEDs),
128 0x19, 0x01, // Usage Minimum (1),
129 0x29, 0x05, // Usage Maximum (5),
130 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
131 0x95, 0x01, // Report Count (1),
132 0x75, 0x03, // Report Size (3),
133 0x91, 0x03, // Output (Constant), ;LED report padding
134 0x95, KBD_REPORT_KEYS, // Report Count (),
135 0x75, 0x08, // Report Size (8),
136 0x15, 0x00, // Logical Minimum (0),
137 0x25, 0xFF, // Logical Maximum(255),
138 0x05, 0x07, // Usage Page (Key Codes),
139 0x19, 0x00, // Usage Minimum (0),
140 0x29, 0xFF, // Usage Maximum (255),
141 0x81, 0x00, // Input (Data, Array),
142 0xc0 // End Collection
143};
144/* wrapper */
145static const USBDescriptor keyboard_hid_report_descriptor = {
146 sizeof keyboard_hid_report_desc_data,
147 keyboard_hid_report_desc_data
148};
149
150#ifdef NKRO_ENABLE
151static const uint8_t nkro_hid_report_desc_data[] = {
152 0x05, 0x01, // Usage Page (Generic Desktop),
153 0x09, 0x06, // Usage (Keyboard),
154 0xA1, 0x01, // Collection (Application),
155 // bitmap of modifiers
156 0x75, 0x01, // Report Size (1),
157 0x95, 0x08, // Report Count (8),
158 0x05, 0x07, // Usage Page (Key Codes),
159 0x19, 0xE0, // Usage Minimum (224),
160 0x29, 0xE7, // Usage Maximum (231),
161 0x15, 0x00, // Logical Minimum (0),
162 0x25, 0x01, // Logical Maximum (1),
163 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
164 // LED output report
165 0x95, 0x05, // Report Count (5),
166 0x75, 0x01, // Report Size (1),
167 0x05, 0x08, // Usage Page (LEDs),
168 0x19, 0x01, // Usage Minimum (1),
169 0x29, 0x05, // Usage Maximum (5),
170 0x91, 0x02, // Output (Data, Variable, Absolute),
171 0x95, 0x01, // Report Count (1),
172 0x75, 0x03, // Report Size (3),
173 0x91, 0x03, // Output (Constant),
174 // bitmap of keys
175 0x95, NKRO_REPORT_KEYS * 8, // Report Count (),
176 0x75, 0x01, // Report Size (1),
177 0x15, 0x00, // Logical Minimum (0),
178 0x25, 0x01, // Logical Maximum(1),
179 0x05, 0x07, // Usage Page (Key Codes),
180 0x19, 0x00, // Usage Minimum (0),
181 0x29, NKRO_REPORT_KEYS * 8 - 1, // Usage Maximum (),
182 0x81, 0x02, // Input (Data, Variable, Absolute),
183 0xc0 // End Collection
184};
185/* wrapper */
186static const USBDescriptor nkro_hid_report_descriptor = {
187 sizeof nkro_hid_report_desc_data,
188 nkro_hid_report_desc_data
189};
190#endif /* NKRO_ENABLE */
191
192#ifdef MOUSE_ENABLE
193/* Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
194 * http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521
195 * http://www.keil.com/forum/15671/
196 * http://www.microsoft.com/whdc/device/input/wheel.mspx */
197static const uint8_t mouse_hid_report_desc_data[] = {
198 /* mouse */
199 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
200 0x09, 0x02, // USAGE (Mouse)
201 0xa1, 0x01, // COLLECTION (Application)
202 //0x85, REPORT_ID_MOUSE, // REPORT_ID (1)
203 0x09, 0x01, // USAGE (Pointer)
204 0xa1, 0x00, // COLLECTION (Physical)
205 // ---------------------------- Buttons
206 0x05, 0x09, // USAGE_PAGE (Button)
207 0x19, 0x01, // USAGE_MINIMUM (Button 1)
208 0x29, 0x05, // USAGE_MAXIMUM (Button 5)
209 0x15, 0x00, // LOGICAL_MINIMUM (0)
210 0x25, 0x01, // LOGICAL_MAXIMUM (1)
211 0x75, 0x01, // REPORT_SIZE (1)
212 0x95, 0x05, // REPORT_COUNT (5)
213 0x81, 0x02, // INPUT (Data,Var,Abs)
214 0x75, 0x03, // REPORT_SIZE (3)
215 0x95, 0x01, // REPORT_COUNT (1)
216 0x81, 0x03, // INPUT (Cnst,Var,Abs)
217 // ---------------------------- X,Y position
218 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
219 0x09, 0x30, // USAGE (X)
220 0x09, 0x31, // USAGE (Y)
221 0x15, 0x81, // LOGICAL_MINIMUM (-127)
222 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
223 0x75, 0x08, // REPORT_SIZE (8)
224 0x95, 0x02, // REPORT_COUNT (2)
225 0x81, 0x06, // INPUT (Data,Var,Rel)
226 // ---------------------------- Vertical wheel
227 0x09, 0x38, // USAGE (Wheel)
228 0x15, 0x81, // LOGICAL_MINIMUM (-127)
229 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
230 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical
231 0x45, 0x00, // PHYSICAL_MAXIMUM (0)
232 0x75, 0x08, // REPORT_SIZE (8)
233 0x95, 0x01, // REPORT_COUNT (1)
234 0x81, 0x06, // INPUT (Data,Var,Rel)
235 // ---------------------------- Horizontal wheel
236 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
237 0x0a, 0x38, 0x02, // USAGE (AC Pan)
238 0x15, 0x81, // LOGICAL_MINIMUM (-127)
239 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
240 0x75, 0x08, // REPORT_SIZE (8)
241 0x95, 0x01, // REPORT_COUNT (1)
242 0x81, 0x06, // INPUT (Data,Var,Rel)
243 0xc0, // END_COLLECTION
244 0xc0, // END_COLLECTION
245};
246/* wrapper */
247static const USBDescriptor mouse_hid_report_descriptor = {
248 sizeof mouse_hid_report_desc_data,
249 mouse_hid_report_desc_data
250};
251#endif /* MOUSE_ENABLE */
252
253#ifdef CONSOLE_ENABLE
254static const uint8_t console_hid_report_desc_data[] = {
255 0x06, 0x31, 0xFF, // Usage Page 0xFF31 (vendor defined)
256 0x09, 0x74, // Usage 0x74
257 0xA1, 0x53, // Collection 0x53
258 0x75, 0x08, // report size = 8 bits
259 0x15, 0x00, // logical minimum = 0
260 0x26, 0xFF, 0x00, // logical maximum = 255
261 0x95, CONSOLE_EPSIZE, // report count
262 0x09, 0x75, // usage
263 0x81, 0x02, // Input (array)
264 0xC0 // end collection
265};
266/* wrapper */
267static const USBDescriptor console_hid_report_descriptor = {
268 sizeof console_hid_report_desc_data,
269 console_hid_report_desc_data
270};
271#endif /* CONSOLE_ENABLE */
272
273#ifdef EXTRAKEY_ENABLE
274/* audio controls & system controls
275 * http://www.microsoft.com/whdc/archive/w2kbd.mspx */
276static const uint8_t extra_hid_report_desc_data[] = {
277 /* system control */
278 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
279 0x09, 0x80, // USAGE (System Control)
280 0xa1, 0x01, // COLLECTION (Application)
281 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2)
282 0x15, 0x01, // LOGICAL_MINIMUM (0x1)
283 0x25, 0xb7, // LOGICAL_MAXIMUM (0xb7)
284 0x19, 0x01, // USAGE_MINIMUM (0x1)
285 0x29, 0xb7, // USAGE_MAXIMUM (0xb7)
286 0x75, 0x10, // REPORT_SIZE (16)
287 0x95, 0x01, // REPORT_COUNT (1)
288 0x81, 0x00, // INPUT (Data,Array,Abs)
289 0xc0, // END_COLLECTION
290 /* consumer */
291 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
292 0x09, 0x01, // USAGE (Consumer Control)
293 0xa1, 0x01, // COLLECTION (Application)
294 0x85, REPORT_ID_CONSUMER, // REPORT_ID (3)
295 0x15, 0x01, // LOGICAL_MINIMUM (0x1)
296 0x26, 0x9c, 0x02, // LOGICAL_MAXIMUM (0x29c)
297 0x19, 0x01, // USAGE_MINIMUM (0x1)
298 0x2a, 0x9c, 0x02, // USAGE_MAXIMUM (0x29c)
299 0x75, 0x10, // REPORT_SIZE (16)
300 0x95, 0x01, // REPORT_COUNT (1)
301 0x81, 0x00, // INPUT (Data,Array,Abs)
302 0xc0, // END_COLLECTION
303};
304/* wrapper */
305static const USBDescriptor extra_hid_report_descriptor = {
306 sizeof extra_hid_report_desc_data,
307 extra_hid_report_desc_data
308};
309#endif /* EXTRAKEY_ENABLE */
310
311
312/*
313 * Configuration Descriptor tree for a HID device
314 *
315 * The HID Specifications version 1.11 require the following order:
316 * - Configuration Descriptor
317 * - Interface Descriptor
318 * - HID Descriptor
319 * - Endpoints Descriptors
320 */
321#define KBD_HID_DESC_NUM 0
322#define KBD_HID_DESC_OFFSET (9 + (9 + 9 + 7) * KBD_HID_DESC_NUM + 9)
323
324#ifdef MOUSE_ENABLE
325# define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 1)
326# define MOUSE_HID_DESC_OFFSET (9 + (9 + 9 + 7) * MOUSE_HID_DESC_NUM + 9)
327#else /* MOUSE_ENABLE */
328# define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 0)
329#endif /* MOUSE_ENABLE */
330
331#ifdef CONSOLE_ENABLE
332#define CONSOLE_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 1)
333#define CONSOLE_HID_DESC_OFFSET (9 + (9 + 9 + 7) * CONSOLE_HID_DESC_NUM + 9)
334#else /* CONSOLE_ENABLE */
335# define CONSOLE_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 0)
336#endif /* CONSOLE_ENABLE */
337
338#ifdef EXTRAKEY_ENABLE
339# define EXTRA_HID_DESC_NUM (CONSOLE_HID_DESC_NUM + 1)
340# define EXTRA_HID_DESC_OFFSET (9 + (9 + 9 + 7) * EXTRA_HID_DESC_NUM + 9)
341#else /* EXTRAKEY_ENABLE */
342# define EXTRA_HID_DESC_NUM (CONSOLE_HID_DESC_NUM + 0)
343#endif /* EXTRAKEY_ENABLE */
344
345#ifdef NKRO_ENABLE
346# define NKRO_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 1)
347# define NKRO_HID_DESC_OFFSET (9 + (9 + 9 + 7) * EXTRA_HID_DESC_NUM + 9)
348#else /* NKRO_ENABLE */
349# define NKRO_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 0)
350#endif /* NKRO_ENABLE */
351
352#define NUM_INTERFACES (NKRO_HID_DESC_NUM + 1)
353#define CONFIG1_DESC_SIZE (9 + (9 + 9 + 7) * NUM_INTERFACES)
354
355static const uint8_t hid_configuration_descriptor_data[] = {
356 /* Configuration Descriptor (9 bytes) USB spec 9.6.3, page 264-266, Table 9-10 */
357 USB_DESC_CONFIGURATION(CONFIG1_DESC_SIZE, // wTotalLength
358 NUM_INTERFACES, // bNumInterfaces
359 1, // bConfigurationValue
360 0, // iConfiguration
361 0xA0, // bmAttributes (RESERVED|REMOTEWAKEUP)
362 50), // bMaxPower (50mA)
363
364 /* Interface Descriptor (9 bytes) USB spec 9.6.5, page 267-269, Table 9-12 */
365 USB_DESC_INTERFACE(KBD_INTERFACE, // bInterfaceNumber
366 0, // bAlternateSetting
367 1, // bNumEndpoints
368 0x03, // bInterfaceClass: HID
369 0x01, // bInterfaceSubClass: Boot
370 0x01, // bInterfaceProtocol: Keyboard
371 0), // iInterface
372
373 /* HID descriptor (9 bytes) HID 1.11 spec, section 6.2.1 */
374 USB_DESC_BYTE(9), // bLength
375 USB_DESC_BYTE(0x21), // bDescriptorType (HID class)
376 USB_DESC_BCD(0x0111), // bcdHID: HID version 1.11
377 USB_DESC_BYTE(0), // bCountryCode
378 USB_DESC_BYTE(1), // bNumDescriptors
379 USB_DESC_BYTE(0x22), // bDescriptorType (report desc)
380 USB_DESC_WORD(sizeof(keyboard_hid_report_desc_data)), // wDescriptorLength
381
382 /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
383 USB_DESC_ENDPOINT(KBD_ENDPOINT | 0x80, // bEndpointAddress
384 0x03, // bmAttributes (Interrupt)
385 KBD_EPSIZE,// wMaxPacketSize
386 10), // bInterval
387
388 #ifdef MOUSE_ENABLE
389 /* Interface Descriptor (9 bytes) USB spec 9.6.5, page 267-269, Table 9-12 */
390 USB_DESC_INTERFACE(MOUSE_INTERFACE, // bInterfaceNumber
391 0, // bAlternateSetting
392 1, // bNumEndpoints
393 0x03, // bInterfaceClass (0x03 = HID)
394 // ThinkPad T23 BIOS doesn't work with boot mouse.
395 0x00, // bInterfaceSubClass (0x01 = Boot)
396 0x00, // bInterfaceProtocol (0x02 = Mouse)
397 /*
398 0x01, // bInterfaceSubClass (0x01 = Boot)
399 0x02, // bInterfaceProtocol (0x02 = Mouse)
400 */
401 0), // iInterface
402
403 /* HID descriptor (9 bytes) HID 1.11 spec, section 6.2.1 */
404 USB_DESC_BYTE(9), // bLength
405 USB_DESC_BYTE(0x21), // bDescriptorType (HID class)
406 USB_DESC_BCD(0x0111), // bcdHID: HID version 1.11
407 USB_DESC_BYTE(0), // bCountryCode
408 USB_DESC_BYTE(1), // bNumDescriptors
409 USB_DESC_BYTE(0x22), // bDescriptorType (report desc)
410 USB_DESC_WORD(sizeof(mouse_hid_report_desc_data)), // wDescriptorLength
411
412 /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
413 USB_DESC_ENDPOINT(MOUSE_ENDPOINT | 0x80, // bEndpointAddress
414 0x03, // bmAttributes (Interrupt)
415 MOUSE_EPSIZE, // wMaxPacketSize
416 1), // bInterval
417 #endif /* MOUSE_ENABLE */
418
419 #ifdef CONSOLE_ENABLE
420 /* Interface Descriptor (9 bytes) USB spec 9.6.5, page 267-269, Table 9-12 */
421 USB_DESC_INTERFACE(CONSOLE_INTERFACE, // bInterfaceNumber
422 0, // bAlternateSetting
423 1, // bNumEndpoints
424 0x03, // bInterfaceClass: HID
425 0x00, // bInterfaceSubClass: None
426 0x00, // bInterfaceProtocol: None
427 0), // iInterface
428
429 /* HID descriptor (9 bytes) HID 1.11 spec, section 6.2.1 */
430 USB_DESC_BYTE(9), // bLength
431 USB_DESC_BYTE(0x21), // bDescriptorType (HID class)
432 USB_DESC_BCD(0x0111), // bcdHID: HID version 1.11
433 USB_DESC_BYTE(0), // bCountryCode
434 USB_DESC_BYTE(1), // bNumDescriptors
435 USB_DESC_BYTE(0x22), // bDescriptorType (report desc)
436 USB_DESC_WORD(sizeof(console_hid_report_desc_data)), // wDescriptorLength
437
438 /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
439 USB_DESC_ENDPOINT(CONSOLE_ENDPOINT | 0x80, // bEndpointAddress
440 0x03, // bmAttributes (Interrupt)
441 CONSOLE_EPSIZE, // wMaxPacketSize
442 1), // bInterval
443 #endif /* CONSOLE_ENABLE */
444
445 #ifdef EXTRAKEY_ENABLE
446 /* Interface Descriptor (9 bytes) USB spec 9.6.5, page 267-269, Table 9-12 */
447 USB_DESC_INTERFACE(EXTRA_INTERFACE, // bInterfaceNumber
448 0, // bAlternateSetting
449 1, // bNumEndpoints
450 0x03, // bInterfaceClass: HID
451 0x00, // bInterfaceSubClass: None
452 0x00, // bInterfaceProtocol: None
453 0), // iInterface
454
455 /* HID descriptor (9 bytes) HID 1.11 spec, section 6.2.1 */
456 USB_DESC_BYTE(9), // bLength
457 USB_DESC_BYTE(0x21), // bDescriptorType (HID class)
458 USB_DESC_BCD(0x0111), // bcdHID: HID version 1.11
459 USB_DESC_BYTE(0), // bCountryCode
460 USB_DESC_BYTE(1), // bNumDescriptors
461 USB_DESC_BYTE(0x22), // bDescriptorType (report desc)
462 USB_DESC_WORD(sizeof(extra_hid_report_desc_data)), // wDescriptorLength
463
464 /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
465 USB_DESC_ENDPOINT(EXTRA_ENDPOINT | 0x80, // bEndpointAddress
466 0x03, // bmAttributes (Interrupt)
467 EXTRA_EPSIZE, // wMaxPacketSize
468 10), // bInterval
469 #endif /* EXTRAKEY_ENABLE */
470
471 #ifdef NKRO_ENABLE
472 /* Interface Descriptor (9 bytes) USB spec 9.6.5, page 267-269, Table 9-12 */
473 USB_DESC_INTERFACE(NKRO_INTERFACE, // bInterfaceNumber
474 0, // bAlternateSetting
475 1, // bNumEndpoints
476 0x03, // bInterfaceClass: HID
477 0x00, // bInterfaceSubClass: None
478 0x00, // bInterfaceProtocol: None
479 0), // iInterface
480
481 /* HID descriptor (9 bytes) HID 1.11 spec, section 6.2.1 */
482 USB_DESC_BYTE(9), // bLength
483 USB_DESC_BYTE(0x21), // bDescriptorType (HID class)
484 USB_DESC_BCD(0x0111), // bcdHID: HID version 1.11
485 USB_DESC_BYTE(0), // bCountryCode
486 USB_DESC_BYTE(1), // bNumDescriptors
487 USB_DESC_BYTE(0x22), // bDescriptorType (report desc)
488 USB_DESC_WORD(sizeof(nkro_hid_report_desc_data)), // wDescriptorLength
489
490 /* Endpoint Descriptor (7 bytes) USB spec 9.6.6, page 269-271, Table 9-13 */
491 USB_DESC_ENDPOINT(NKRO_ENDPOINT | 0x80, // bEndpointAddress
492 0x03, // bmAttributes (Interrupt)
493 NKRO_EPSIZE, // wMaxPacketSize
494 1), // bInterval
495 #endif /* NKRO_ENABLE */
496};
497
498/* Configuration Descriptor wrapper */
499static const USBDescriptor hid_configuration_descriptor = {
500 sizeof hid_configuration_descriptor_data,
501 hid_configuration_descriptor_data
502};
503
504/* wrappers */
505#define HID_DESCRIPTOR_SIZE 9
506static const USBDescriptor keyboard_hid_descriptor = {
507 HID_DESCRIPTOR_SIZE,
508 &hid_configuration_descriptor_data[KBD_HID_DESC_OFFSET]
509};
510#ifdef MOUSE_ENABLE
511static const USBDescriptor mouse_hid_descriptor = {
512 HID_DESCRIPTOR_SIZE,
513 &hid_configuration_descriptor_data[MOUSE_HID_DESC_OFFSET]
514};
515#endif /* MOUSE_ENABLE */
516#ifdef CONSOLE_ENABLE
517static const USBDescriptor console_hid_descriptor = {
518 HID_DESCRIPTOR_SIZE,
519 &hid_configuration_descriptor_data[CONSOLE_HID_DESC_OFFSET]
520};
521#endif /* CONSOLE_ENABLE */
522#ifdef EXTRAKEY_ENABLE
523static const USBDescriptor extra_hid_descriptor = {
524 HID_DESCRIPTOR_SIZE,
525 &hid_configuration_descriptor_data[EXTRA_HID_DESC_OFFSET]
526};
527#endif /* EXTRAKEY_ENABLE */
528#ifdef NKRO_ENABLE
529static const USBDescriptor nkro_hid_descriptor = {
530 HID_DESCRIPTOR_SIZE,
531 &hid_configuration_descriptor_data[NKRO_HID_DESC_OFFSET]
532};
533#endif /* NKRO_ENABLE */
534
535
536/* U.S. English language identifier */
537static const uint8_t usb_string_langid[] = {
538 USB_DESC_BYTE(4), // bLength
539 USB_DESC_BYTE(USB_DESCRIPTOR_STRING), // bDescriptorType
540 USB_DESC_WORD(0x0409) // wLANGID (U.S. English)
541};
542
543/* ugly ugly hack */
544#define PP_NARG(...) \
545 PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
546#define PP_NARG_(...) \
547 PP_ARG_N(__VA_ARGS__)
548#define PP_ARG_N( \
549 _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
550 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
551 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
552 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
553 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
554 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
555 _61,_62,_63,N,...) N
556#define PP_RSEQ_N() \
557 63,62,61,60, \
558 59,58,57,56,55,54,53,52,51,50, \
559 49,48,47,46,45,44,43,42,41,40, \
560 39,38,37,36,35,34,33,32,31,30, \
561 29,28,27,26,25,24,23,22,21,20, \
562 19,18,17,16,15,14,13,12,11,10, \
563 9,8,7,6,5,4,3,2,1,0
564
565/* Vendor string = manufacturer */
566static const uint8_t usb_string_vendor[] = {
567 USB_DESC_BYTE(PP_NARG(USBSTR_MANUFACTURER)+2), // bLength
568 USB_DESC_BYTE(USB_DESCRIPTOR_STRING), // bDescriptorType
569 USBSTR_MANUFACTURER
570};
571
572/* Device Description string = product */
573static const uint8_t usb_string_description[] = {
574 USB_DESC_BYTE(PP_NARG(USBSTR_PRODUCT)+2), // bLength
575 USB_DESC_BYTE(USB_DESCRIPTOR_STRING), // bDescriptorType
576 USBSTR_PRODUCT
577};
578
579/* Serial Number string (will be filled by the function init_usb_serial_string) */
580static uint8_t usb_string_serial[] = {
581 USB_DESC_BYTE(22), // bLength
582 USB_DESC_BYTE(USB_DESCRIPTOR_STRING), // bDescriptorType
583 '0', 0, 'x', 0, 'D', 0, 'E', 0, 'A', 0, 'D', 0, 'B', 0, 'E', 0, 'E', 0, 'F', 0
584};
585
586/* Strings wrappers array */
587static const USBDescriptor usb_strings[] = {
588 { sizeof usb_string_langid, usb_string_langid }
589 ,
590 { sizeof usb_string_vendor, usb_string_vendor }
591 ,
592 { sizeof usb_string_description, usb_string_description }
593 ,
594 { sizeof usb_string_serial, usb_string_serial }
595};
596
597/*
598 * Handles the GET_DESCRIPTOR callback
599 *
600 * Returns the proper descriptor
601 */
602static const USBDescriptor *usb_get_descriptor_cb(USBDriver *usbp, uint8_t dtype, uint8_t dindex, uint16_t lang) {
603 (void)usbp;
604 (void)lang;
605 switch(dtype) {
606 /* Generic descriptors */
607 case USB_DESCRIPTOR_DEVICE: /* Device Descriptor */
608 return &usb_device_descriptor;
609
610 case USB_DESCRIPTOR_CONFIGURATION: /* Configuration Descriptor */
611 return &hid_configuration_descriptor;
612
613 case USB_DESCRIPTOR_STRING: /* Strings */
614 if(dindex < 4)
615 return &usb_strings[dindex];
616 break;
617
618 /* HID specific descriptors */
619 case USB_DESCRIPTOR_HID: /* HID Descriptors */
620 switch(lang) { /* yea, poor label, it's actually wIndex from the setup packet */
621 case KBD_INTERFACE:
622 return &keyboard_hid_descriptor;
623
624#ifdef MOUSE_ENABLE
625 case MOUSE_INTERFACE:
626 return &mouse_hid_descriptor;
627#endif /* MOUSE_ENABLE */
628#ifdef CONSOLE_ENABLE
629 case CONSOLE_INTERFACE:
630 return &console_hid_descriptor;
631#endif /* CONSOLE_ENABLE */
632#ifdef EXTRAKEY_ENABLE
633 case EXTRA_INTERFACE:
634 return &extra_hid_descriptor;
635#endif /* EXTRAKEY_ENABLE */
636#ifdef NKRO_ENABLE
637 case NKRO_INTERFACE:
638 return &nkro_hid_descriptor;
639#endif /* NKRO_ENABLE */
640 }
641
642 case USB_DESCRIPTOR_HID_REPORT: /* HID Report Descriptor */
643 switch(lang) {
644 case KBD_INTERFACE:
645 return &keyboard_hid_report_descriptor;
646
647#ifdef MOUSE_ENABLE
648 case MOUSE_INTERFACE:
649 return &mouse_hid_report_descriptor;
650#endif /* MOUSE_ENABLE */
651#ifdef CONSOLE_ENABLE
652 case CONSOLE_INTERFACE:
653 return &console_hid_report_descriptor;
654#endif /* CONSOLE_ENABLE */
655#ifdef EXTRAKEY_ENABLE
656 case EXTRA_INTERFACE:
657 return &extra_hid_report_descriptor;
658#endif /* EXTRAKEY_ENABLE */
659#ifdef NKRO_ENABLE
660 case NKRO_INTERFACE:
661 return &nkro_hid_report_descriptor;
662#endif /* NKRO_ENABLE */
663 }
664 }
665 return NULL;
666}
667
668/* keyboard endpoint state structure */
669static USBInEndpointState kbd_ep_state;
670/* keyboard endpoint initialization structure (IN) */
671static const USBEndpointConfig kbd_ep_config = {
672 USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
673 NULL, /* SETUP packet notification callback */
674 kbd_in_cb, /* IN notification callback */
675 NULL, /* OUT notification callback */
676 KBD_EPSIZE, /* IN maximum packet size */
677 0, /* OUT maximum packet size */
678 &kbd_ep_state, /* IN Endpoint state */
679 NULL, /* OUT endpoint state */
680 2, /* IN multiplier */
681 NULL /* SETUP buffer (not a SETUP endpoint) */
682};
683
684#ifdef MOUSE_ENABLE
685/* mouse endpoint state structure */
686static USBInEndpointState mouse_ep_state;
687
688/* mouse endpoint initialization structure (IN) */
689static const USBEndpointConfig mouse_ep_config = {
690 USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
691 NULL, /* SETUP packet notification callback */
692 mouse_in_cb, /* IN notification callback */
693 NULL, /* OUT notification callback */
694 MOUSE_EPSIZE, /* IN maximum packet size */
695 0, /* OUT maximum packet size */
696 &mouse_ep_state, /* IN Endpoint state */
697 NULL, /* OUT endpoint state */
698 2, /* IN multiplier */
699 NULL /* SETUP buffer (not a SETUP endpoint) */
700};
701#endif /* MOUSE_ENABLE */
702
703#ifdef CONSOLE_ENABLE
704/* console endpoint state structure */
705static USBInEndpointState console_ep_state;
706
707/* console endpoint initialization structure (IN) */
708static const USBEndpointConfig console_ep_config = {
709 USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
710 NULL, /* SETUP packet notification callback */
711 console_in_cb, /* IN notification callback */
712 NULL, /* OUT notification callback */
713 CONSOLE_EPSIZE, /* IN maximum packet size */
714 0, /* OUT maximum packet size */
715 &console_ep_state, /* IN Endpoint state */
716 NULL, /* OUT endpoint state */
717 2, /* IN multiplier */
718 NULL /* SETUP buffer (not a SETUP endpoint) */
719};
720#endif /* CONSOLE_ENABLE */
721
722#ifdef EXTRAKEY_ENABLE
723/* extrakey endpoint state structure */
724static USBInEndpointState extra_ep_state;
725
726/* extrakey endpoint initialization structure (IN) */
727static const USBEndpointConfig extra_ep_config = {
728 USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
729 NULL, /* SETUP packet notification callback */
730 extra_in_cb, /* IN notification callback */
731 NULL, /* OUT notification callback */
732 EXTRA_EPSIZE, /* IN maximum packet size */
733 0, /* OUT maximum packet size */
734 &extra_ep_state, /* IN Endpoint state */
735 NULL, /* OUT endpoint state */
736 2, /* IN multiplier */
737 NULL /* SETUP buffer (not a SETUP endpoint) */
738};
739#endif /* EXTRAKEY_ENABLE */
740
741#ifdef NKRO_ENABLE
742/* nkro endpoint state structure */
743static USBInEndpointState nkro_ep_state;
744
745/* nkro endpoint initialization structure (IN) */
746static const USBEndpointConfig nkro_ep_config = {
747 USB_EP_MODE_TYPE_INTR, /* Interrupt EP */
748 NULL, /* SETUP packet notification callback */
749 nkro_in_cb, /* IN notification callback */
750 NULL, /* OUT notification callback */
751 NKRO_EPSIZE, /* IN maximum packet size */
752 0, /* OUT maximum packet size */
753 &nkro_ep_state, /* IN Endpoint state */
754 NULL, /* OUT endpoint state */
755 2, /* IN multiplier */
756 NULL /* SETUP buffer (not a SETUP endpoint) */
757};
758#endif /* NKRO_ENABLE */
759
760/* ---------------------------------------------------------
761 * USB driver functions
762 * ---------------------------------------------------------
763 */
764
765/* Handles the USB driver global events
766 * TODO: maybe disable some things when connection is lost? */
767static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
768 switch(event) {
769 case USB_EVENT_RESET:
770 //TODO: from ISR! print("[R]");
771 return;
772
773 case USB_EVENT_ADDRESS:
774 return;
775
776 case USB_EVENT_CONFIGURED:
777 osalSysLockFromISR();
778 /* Enable the endpoints specified into the configuration. */
779 usbInitEndpointI(usbp, KBD_ENDPOINT, &kbd_ep_config);
780#ifdef MOUSE_ENABLE
781 usbInitEndpointI(usbp, MOUSE_ENDPOINT, &mouse_ep_config);
782#endif /* MOUSE_ENABLE */
783#ifdef CONSOLE_ENABLE
784 usbInitEndpointI(usbp, CONSOLE_ENDPOINT, &console_ep_config);
785 /* don't need to start the flush timer, it starts from console_in_cb automatically */
786#endif /* CONSOLE_ENABLE */
787#ifdef EXTRAKEY_ENABLE
788 usbInitEndpointI(usbp, EXTRA_ENDPOINT, &extra_ep_config);
789#endif /* EXTRAKEY_ENABLE */
790#ifdef NKRO_ENABLE
791 usbInitEndpointI(usbp, NKRO_ENDPOINT, &nkro_ep_config);
792#endif /* NKRO_ENABLE */
793 osalSysUnlockFromISR();
794 return;
795
796 case USB_EVENT_SUSPEND:
797 //TODO: from ISR! print("[S]");
798#ifdef SLEEP_LED_ENABLE
799 sleep_led_enable();
800#endif /* SLEEP_LED_ENABLE */
801 return;
802
803 case USB_EVENT_WAKEUP:
804 //TODO: from ISR! print("[W]");
805 suspend_wakeup_init();
806#ifdef SLEEP_LED_ENABLE
807 sleep_led_disable();
808 // NOTE: converters may not accept this
809 led_set(host_keyboard_leds());
810#endif /* SLEEP_LED_ENABLE */
811 return;
812
813 case USB_EVENT_STALLED:
814 return;
815 }
816}
817
818/* Function used locally in os/hal/src/usb.c for getting descriptors
819 * need it here for HID descriptor */
820static uint16_t get_hword(uint8_t *p) {
821 uint16_t hw;
822
823 hw = (uint16_t)*p++;
824 hw |= (uint16_t)*p << 8U;
825 return hw;
826}
827
828/*
829 * Appendix G: HID Request Support Requirements
830 *
831 * The following table enumerates the requests that need to be supported by various types of HID class devices.
832 * Device type GetReport SetReport GetIdle SetIdle GetProtocol SetProtocol
833 * ------------------------------------------------------------------------------------------
834 * Boot Mouse Required Optional Optional Optional Required Required
835 * Non-Boot Mouse Required Optional Optional Optional Optional Optional
836 * Boot Keyboard Required Optional Required Required Required Required
837 * Non-Boot Keybrd Required Optional Required Required Optional Optional
838 * Other Device Required Optional Optional Optional Optional Optional
839 */
840
841/* Callback for SETUP request on the endpoint 0 (control) */
842static bool usb_request_hook_cb(USBDriver *usbp) {
843 const USBDescriptor *dp;
844
845 /* usbp->setup fields:
846 * 0: bmRequestType (bitmask)
847 * 1: bRequest
848 * 2,3: (LSB,MSB) wValue
849 * 4,5: (LSB,MSB) wIndex
850 * 6,7: (LSB,MSB) wLength (number of bytes to transfer if there is a data phase) */
851
852 /* Handle HID class specific requests */
853 if(((usbp->setup[0] & USB_RTYPE_TYPE_MASK) == USB_RTYPE_TYPE_CLASS) &&
854 ((usbp->setup[0] & USB_RTYPE_RECIPIENT_MASK) == USB_RTYPE_RECIPIENT_INTERFACE)) {
855 switch(usbp->setup[0] & USB_RTYPE_DIR_MASK) {
856 case USB_RTYPE_DIR_DEV2HOST:
857 switch(usbp->setup[1]) { /* bRequest */
858 case HID_GET_REPORT:
859 switch(usbp->setup[4]) { /* LSB(wIndex) (check MSB==0?) */
860 case KBD_INTERFACE:
861#ifdef NKRO_ENABLE
862 case NKRO_INTERFACE:
863#endif /* NKRO_ENABLE */
864 usbSetupTransfer(usbp, (uint8_t *)&keyboard_report_sent, sizeof(keyboard_report_sent), NULL);
865 return TRUE;
866 break;
867
868#ifdef MOUSE_ENABLE
869 case MOUSE_INTERFACE:
870 usbSetupTransfer(usbp, (uint8_t *)&mouse_report_blank, sizeof(mouse_report_blank), NULL);
871 return TRUE;
872 break;
873#endif /* MOUSE_ENABLE */
874
875#ifdef CONSOLE_ENABLE
876 case CONSOLE_INTERFACE:
877 usbSetupTransfer(usbp, console_queue_buffer, CONSOLE_EPSIZE, NULL);
878 return TRUE;
879 break;
880#endif /* CONSOLE_ENABLE */
881
882#ifdef EXTRAKEY_ENABLE
883 case EXTRA_INTERFACE:
884 if(usbp->setup[3] == 1) { /* MSB(wValue) [Report Type] == 1 [Input Report] */
885 switch(usbp->setup[2]) { /* LSB(wValue) [Report ID] */
886 case REPORT_ID_SYSTEM:
887 extra_report_blank[0] = REPORT_ID_SYSTEM;
888 usbSetupTransfer(usbp, (uint8_t *)extra_report_blank, sizeof(extra_report_blank), NULL);
889 return TRUE;
890 break;
891 case REPORT_ID_CONSUMER:
892 extra_report_blank[0] = REPORT_ID_CONSUMER;
893 usbSetupTransfer(usbp, (uint8_t *)extra_report_blank, sizeof(extra_report_blank), NULL);
894 return TRUE;
895 break;
896 default:
897 return FALSE;
898 }
899 } else {
900 return FALSE;
901 }
902 break;
903#endif /* EXTRAKEY_ENABLE */
904
905 default:
906 usbSetupTransfer(usbp, NULL, 0, NULL);
907 return TRUE;
908 break;
909 }
910 break;
911
912 case HID_GET_PROTOCOL:
913 if((usbp->setup[4] == KBD_INTERFACE) && (usbp->setup[5] == 0)) { /* wIndex */
914 usbSetupTransfer(usbp, &keyboard_protocol, 1, NULL);
915 return TRUE;
916 }
917 break;
918
919 case HID_GET_IDLE:
920 usbSetupTransfer(usbp, &keyboard_idle, 1, NULL);
921 return TRUE;
922 break;
923 }
924 break;
925
926 case USB_RTYPE_DIR_HOST2DEV:
927 switch(usbp->setup[1]) { /* bRequest */
928 case HID_SET_REPORT:
929 switch(usbp->setup[4]) { /* LSB(wIndex) (check MSB==0 and wLength==1?) */
930 case KBD_INTERFACE:
931#ifdef NKRO_ENABLE
932 case NKRO_INTERFACE:
933#endif /* NKRO_ENABLE */
934 /* keyboard_led_stats = <read byte from next OUT report>
935 * keyboard_led_stats needs be word (or dword), otherwise we get an exception on F0 */
936 usbSetupTransfer(usbp, (uint8_t *)&keyboard_led_stats, 1, NULL);
937 return TRUE;
938 break;
939 }
940 break;
941
942 case HID_SET_PROTOCOL:
943 if((usbp->setup[4] == KBD_INTERFACE) && (usbp->setup[5] == 0)) { /* wIndex */
944 keyboard_protocol = ((usbp->setup[2]) != 0x00); /* LSB(wValue) */
945#ifdef NKRO_ENABLE
946 keyboard_nkro = !!keyboard_protocol;
947 if(!keyboard_nkro && keyboard_idle) {
948#else /* NKRO_ENABLE */
949 if(keyboard_idle) {
950#endif /* NKRO_ENABLE */
951 /* arm the idle timer if boot protocol & idle */
952 osalSysLockFromISR();
953 chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
954 osalSysUnlockFromISR();
955 }
956 }
957 usbSetupTransfer(usbp, NULL, 0, NULL);
958 return TRUE;
959 break;
960
961 case HID_SET_IDLE:
962 keyboard_idle = usbp->setup[3]; /* MSB(wValue) */
963 /* arm the timer */
964#ifdef NKRO_ENABLE
965 if(!keyboard_nkro && keyboard_idle) {
966#else /* NKRO_ENABLE */
967 if(keyboard_idle) {
968#endif /* NKRO_ENABLE */
969 osalSysLockFromISR();
970 chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
971 osalSysUnlockFromISR();
972 }
973 usbSetupTransfer(usbp, NULL, 0, NULL);
974 return TRUE;
975 break;
976 }
977 break;
978 }
979 }
980
981 /* Handle the Get_Descriptor Request for HID class (not handled by the default hook) */
982 if((usbp->setup[0] == 0x81) && (usbp->setup[1] == USB_REQ_GET_DESCRIPTOR)) {
983 dp = usbp->config->get_descriptor_cb(usbp, usbp->setup[3], usbp->setup[2], get_hword(&usbp->setup[4]));
984 if(dp == NULL)
985 return FALSE;
986 usbSetupTransfer(usbp, (uint8_t *)dp->ud_string, dp->ud_size, NULL);
987 return TRUE;
988 }
989
990 return FALSE;
991}
992
993/* Start-of-frame callback */
994static void usb_sof_cb(USBDriver *usbp) {
995 kbd_sof_cb(usbp);
996}
997
998
999/* USB driver configuration */
1000static const USBConfig usbcfg = {
1001 usb_event_cb, /* USB events callback */
1002 usb_get_descriptor_cb, /* Device GET_DESCRIPTOR request callback */
1003 usb_request_hook_cb, /* Requests hook callback */
1004 usb_sof_cb /* Start Of Frame callback */
1005};
1006
1007/*
1008 * Initialize the USB driver
1009 */
1010void init_usb_driver(USBDriver *usbp) {
1011 /*
1012 * Activates the USB driver and then the USB bus pull-up on D+.
1013 * Note, a delay is inserted in order to not have to disconnect the cable
1014 * after a reset.
1015 */
1016 usbDisconnectBus(usbp);
1017 chThdSleepMilliseconds(1500);
1018 usbStart(usbp, &usbcfg);
1019 usbConnectBus(usbp);
1020
1021 chVTObjectInit(&keyboard_idle_timer);
1022#ifdef CONSOLE_ENABLE
1023 obqObjectInit(&console_buf_queue, console_queue_buffer, CONSOLE_EPSIZE, CONSOLE_QUEUE_CAPACITY, console_queue_onotify, (void*)usbp);
1024 chVTObjectInit(&console_flush_timer);
1025#endif
1026}
1027
1028/*
1029 * Send remote wakeup packet
1030 * Note: should not be called from ISR
1031 */
1032void send_remote_wakeup(USBDriver *usbp) {
1033 (void)usbp;
1034#if defined(K20x) || defined(KL2x)
1035#if KINETIS_USB_USE_USB0
1036 USB0->CTL |= USBx_CTL_RESUME;
1037 chThdSleepMilliseconds(15);
1038 USB0->CTL &= ~USBx_CTL_RESUME;
1039#endif /* KINETIS_USB_USE_USB0 */
1040#elif defined(STM32F0XX) || defined(STM32F1XX) /* K20x || KL2x */
1041 STM32_USB->CNTR |= CNTR_RESUME;
1042 chThdSleepMilliseconds(15);
1043 STM32_USB->CNTR &= ~CNTR_RESUME;
1044#else /* STM32F0XX || STM32F1XX */
1045#warning Sending remote wakeup packet not implemented for your platform.
1046#endif /* K20x || KL2x */
1047}
1048
1049/* ---------------------------------------------------------
1050 * Keyboard functions
1051 * ---------------------------------------------------------
1052 */
1053
1054/* keyboard IN callback hander (a kbd report has made it IN) */
1055void kbd_in_cb(USBDriver *usbp, usbep_t ep) {
1056 /* STUB */
1057 (void)usbp;
1058 (void)ep;
1059}
1060
1061#ifdef NKRO_ENABLE
1062/* nkro IN callback hander (a nkro report has made it IN) */
1063void nkro_in_cb(USBDriver *usbp, usbep_t ep) {
1064 /* STUB */
1065 (void)usbp;
1066 (void)ep;
1067}
1068#endif /* NKRO_ENABLE */
1069
1070/* start-of-frame handler
1071 * TODO: i guess it would be better to re-implement using timers,
1072 * so that this is not going to have to be checked every 1ms */
1073void kbd_sof_cb(USBDriver *usbp) {
1074 (void)usbp;
1075}
1076
1077/* Idle requests timer code
1078 * callback (called from ISR, unlocked state) */
1079static void keyboard_idle_timer_cb(void *arg) {
1080 USBDriver *usbp = (USBDriver *)arg;
1081
1082 osalSysLockFromISR();
1083
1084 /* check that the states of things are as they're supposed to */
1085 if(usbGetDriverStateI(usbp) != USB_ACTIVE) {
1086 /* do not rearm the timer, should be enabled on IDLE request */
1087 osalSysUnlockFromISR();
1088 return;
1089 }
1090
1091#ifdef NKRO_ENABLE
1092 if(!keyboard_nkro && keyboard_idle) {
1093#else /* NKRO_ENABLE */
1094 if(keyboard_idle) {
1095#endif /* NKRO_ENABLE */
1096 /* TODO: are we sure we want the KBD_ENDPOINT? */
1097 if(!usbGetTransmitStatusI(usbp, KBD_ENDPOINT)) {
1098 usbStartTransmitI(usbp, KBD_ENDPOINT, (uint8_t *)&keyboard_report_sent, KBD_EPSIZE);
1099 }
1100 /* rearm the timer */
1101 chVTSetI(&keyboard_idle_timer, 4*MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
1102 }
1103
1104 /* do not rearm the timer if the condition above fails
1105 * it should be enabled again on either IDLE or SET_PROTOCOL requests */
1106 osalSysUnlockFromISR();
1107}
1108
1109/* LED status */
1110uint8_t keyboard_leds(void) {
1111 return (uint8_t)(keyboard_led_stats & 0xFF);
1112}
1113
1114/* prepare and start sending a report IN
1115 * not callable from ISR or locked state */
1116void send_keyboard(report_keyboard_t *report) {
1117 osalSysLock();
1118 if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
1119 osalSysUnlock();
1120 return;
1121 }
1122 osalSysUnlock();
1123
1124#ifdef NKRO_ENABLE
1125 if(keyboard_nkro) { /* NKRO protocol */
1126 /* need to wait until the previous packet has made it through */
1127 /* can rewrite this using the synchronous API, then would wait
1128 * until *after* the packet has been transmitted. I think
1129 * this is more efficient */
1130 /* busy wait, should be short and not very common */
1131 osalSysLock();
1132 if(usbGetTransmitStatusI(&USB_DRIVER, NKRO_ENDPOINT)) {
1133 /* Need to either suspend, or loop and call unlock/lock during
1134 * every iteration - otherwise the system will remain locked,
1135 * no interrupts served, so USB not going through as well.
1136 * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
1137 osalThreadSuspendS(&(&USB_DRIVER)->epc[NKRO_ENDPOINT]->in_state->thread);
1138 }
1139 usbStartTransmitI(&USB_DRIVER, NKRO_ENDPOINT, (uint8_t *)report, sizeof(report_keyboard_t));
1140 osalSysUnlock();
1141 } else
1142#endif /* NKRO_ENABLE */
1143 { /* boot protocol */
1144 /* need to wait until the previous packet has made it through */
1145 /* busy wait, should be short and not very common */
1146 osalSysLock();
1147 if(usbGetTransmitStatusI(&USB_DRIVER, KBD_ENDPOINT)) {
1148 /* Need to either suspend, or loop and call unlock/lock during
1149 * every iteration - otherwise the system will remain locked,
1150 * no interrupts served, so USB not going through as well.
1151 * Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
1152 osalThreadSuspendS(&(&USB_DRIVER)->epc[KBD_ENDPOINT]->in_state->thread);
1153 }
1154 usbStartTransmitI(&USB_DRIVER, KBD_ENDPOINT, (uint8_t *)report, KBD_EPSIZE);
1155 osalSysUnlock();
1156 }
1157 keyboard_report_sent = *report;
1158}
1159
1160/* ---------------------------------------------------------
1161 * Mouse functions
1162 * ---------------------------------------------------------
1163 */
1164
1165#ifdef MOUSE_ENABLE
1166
1167/* mouse IN callback hander (a mouse report has made it IN) */
1168void mouse_in_cb(USBDriver *usbp, usbep_t ep) {
1169 (void)usbp;
1170 (void)ep;
1171}
1172
1173void send_mouse(report_mouse_t *report) {
1174 osalSysLock();
1175 if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
1176 osalSysUnlock();
1177 return;
1178 }
1179 osalSysUnlock();
1180
1181 /* TODO: LUFA manually waits for the endpoint to become ready
1182 * for about 10ms for mouse, kbd, system; 1ms for nkro
1183 * is this really needed?
1184 */
1185
1186 osalSysLock();
1187 usbStartTransmitI(&USB_DRIVER, MOUSE_ENDPOINT, (uint8_t *)report, sizeof(report_mouse_t));
1188 osalSysUnlock();
1189}
1190
1191#else /* MOUSE_ENABLE */
1192void send_mouse(report_mouse_t *report) {
1193 (void)report;
1194}
1195#endif /* MOUSE_ENABLE */
1196
1197/* ---------------------------------------------------------
1198 * Extrakey functions
1199 * ---------------------------------------------------------
1200 */
1201
1202#ifdef EXTRAKEY_ENABLE
1203
1204/* extrakey IN callback hander */
1205void extra_in_cb(USBDriver *usbp, usbep_t ep) {
1206 /* STUB */
1207 (void)usbp;
1208 (void)ep;
1209}
1210
1211static void send_extra_report(uint8_t report_id, uint16_t data) {
1212 osalSysLock();
1213 if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
1214 osalSysUnlock();
1215 return;
1216 }
1217
1218 report_extra_t report = {
1219 .report_id = report_id,
1220 .usage = data
1221 };
1222
1223 usbStartTransmitI(&USB_DRIVER, EXTRA_ENDPOINT, (uint8_t *)&report, sizeof(report_extra_t));
1224 osalSysUnlock();
1225}
1226
1227void send_system(uint16_t data) {
1228 send_extra_report(REPORT_ID_SYSTEM, data);
1229}
1230
1231void send_consumer(uint16_t data) {
1232 send_extra_report(REPORT_ID_CONSUMER, data);
1233}
1234
1235#else /* EXTRAKEY_ENABLE */
1236void send_system(uint16_t data) {
1237 (void)data;
1238}
1239void send_consumer(uint16_t data) {
1240 (void)data;
1241}
1242#endif /* EXTRAKEY_ENABLE */
1243
1244/* ---------------------------------------------------------
1245 * Console functions
1246 * ---------------------------------------------------------
1247 */
1248
1249#ifdef CONSOLE_ENABLE
1250
1251/* console IN callback hander */
1252void console_in_cb(USBDriver *usbp, usbep_t ep) {
1253 (void)ep; /* should have ep == CONSOLE_ENDPOINT, so use that to save time/space */
1254 uint8_t *buf;
1255 size_t n;
1256
1257 osalSysLockFromISR();
1258
1259 /* rearm the timer */
1260 chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
1261
1262 /* Freeing the buffer just transmitted, if it was not a zero size packet.*/
1263 if (usbp->epc[CONSOLE_ENDPOINT]->in_state->txsize > 0U) {
1264 obqReleaseEmptyBufferI(&console_buf_queue);
1265 }
1266
1267 /* Checking if there is a buffer ready for transmission.*/
1268 buf = obqGetFullBufferI(&console_buf_queue, &n);
1269
1270 if (buf != NULL) {
1271 /* The endpoint cannot be busy, we are in the context of the callback,
1272 so it is safe to transmit without a check.*/
1273 /* Should have n == CONSOLE_EPSIZE; check it? */
1274 usbStartTransmitI(usbp, CONSOLE_ENDPOINT, buf, CONSOLE_EPSIZE);
1275 } else {
1276 /* Nothing to transmit.*/
1277 }
1278
1279 osalSysUnlockFromISR();
1280}
1281
1282/* Callback when data is inserted into the output queue
1283 * Called from a locked state */
1284void console_queue_onotify(io_buffers_queue_t *bqp) {
1285 size_t n;
1286 USBDriver *usbp = bqGetLinkX(bqp);
1287
1288 if(usbGetDriverStateI(usbp) != USB_ACTIVE)
1289 return;
1290
1291 /* Checking if there is already a transaction ongoing on the endpoint.*/
1292 if (!usbGetTransmitStatusI(usbp, CONSOLE_ENDPOINT)) {
1293 /* Trying to get a full buffer.*/
1294 uint8_t *buf = obqGetFullBufferI(&console_buf_queue, &n);
1295 if (buf != NULL) {
1296 /* Buffer found, starting a new transaction.*/
1297 /* Should have n == CONSOLE_EPSIZE; check this? */
1298 usbStartTransmitI(usbp, CONSOLE_ENDPOINT, buf, CONSOLE_EPSIZE);
1299 }
1300 }
1301}
1302
1303/* Flush timer code
1304 * callback (called from ISR, unlocked state) */
1305static void console_flush_cb(void *arg) {
1306 USBDriver *usbp = (USBDriver *)arg;
1307 osalSysLockFromISR();
1308
1309 /* check that the states of things are as they're supposed to */
1310 if(usbGetDriverStateI(usbp) != USB_ACTIVE) {
1311 /* rearm the timer */
1312 chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
1313 osalSysUnlockFromISR();
1314 return;
1315 }
1316
1317 /* If there is already a transaction ongoing then another one cannot be
1318 started.*/
1319 if (usbGetTransmitStatusI(usbp, CONSOLE_ENDPOINT)) {
1320 /* rearm the timer */
1321 chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
1322 osalSysUnlockFromISR();
1323 return;
1324 }
1325
1326 /* Checking if there only a buffer partially filled, if so then it is
1327 enforced in the queue and transmitted.*/
1328 if(obqTryFlushI(&console_buf_queue)) {
1329 size_t n,i;
1330 uint8_t *buf = obqGetFullBufferI(&console_buf_queue, &n);
1331
1332 osalDbgAssert(buf != NULL, "queue is empty");
1333
1334 /* zero the rest of the buffer (buf should point to allocated space) */
1335 for(i=n; i<CONSOLE_EPSIZE; i++)
1336 buf[i]=0;
1337 usbStartTransmitI(usbp, CONSOLE_ENDPOINT, buf, CONSOLE_EPSIZE);
1338 }
1339
1340 /* rearm the timer */
1341 chVTSetI(&console_flush_timer, MS2ST(CONSOLE_FLUSH_MS), console_flush_cb, (void *)usbp);
1342 osalSysUnlockFromISR();
1343}
1344
1345
1346int8_t sendchar(uint8_t c) {
1347 osalSysLock();
1348 if(usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
1349 osalSysUnlock();
1350 return 0;
1351 }
1352 osalSysUnlock();
1353 /* Timeout after 100us if the queue is full.
1354 * Increase this timeout if too much stuff is getting
1355 * dropped (i.e. the buffer is getting full too fast
1356 * for USB/HIDRAW to dequeue). Another possibility
1357 * for fixing this kind of thing is to increase
1358 * CONSOLE_QUEUE_CAPACITY. */
1359 return(obqPutTimeout(&console_buf_queue, c, US2ST(100)));
1360}
1361
1362#else /* CONSOLE_ENABLE */
1363int8_t sendchar(uint8_t c) {
1364 (void)c;
1365 return 0;
1366}
1367#endif /* CONSOLE_ENABLE */
1368
1369void sendchar_pf(void *p, char c) {
1370 (void)p;
1371 sendchar((uint8_t)c);
1372}
diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h
new file mode 100644
index 000000000..30d8fcaef
--- /dev/null
+++ b/tmk_core/protocol/chibios/usb_main.h
@@ -0,0 +1,139 @@
1/*
2 * (c) 2015 flabberast <s3+flabbergast@sdfeu.org>
3 *
4 * Based on the following work:
5 * - Guillaume Duc's raw hid example (MIT License)
6 * https://github.com/guiduc/usb-hid-chibios-example
7 * - PJRC Teensy examples (MIT License)
8 * https://www.pjrc.com/teensy/usb_keyboard.html
9 * - hasu's TMK keyboard code (GPL v2 and some code Modified BSD)
10 * https://github.com/tmk/tmk_keyboard/
11 * - ChibiOS demo code (Apache 2.0 License)
12 * http://www.chibios.org
13 *
14 * Since some GPL'd code is used, this work is licensed under
15 * GPL v2 or later.
16 */
17
18
19#ifndef _USB_MAIN_H_
20#define _USB_MAIN_H_
21
22// TESTING
23// extern uint8_t blinkLed;
24
25#include "ch.h"
26#include "hal.h"
27
28/* -------------------------
29 * General USB driver header
30 * -------------------------
31 */
32
33/* The USB driver to use */
34#define USB_DRIVER USBD1
35
36/* Initialize the USB driver and bus */
37void init_usb_driver(USBDriver *usbp);
38
39/* Send remote wakeup packet */
40void send_remote_wakeup(USBDriver *usbp);
41
42/* ---------------
43 * Keyboard header
44 * ---------------
45 */
46
47/* main keyboard (6kro) */
48#define KBD_INTERFACE 0
49#define KBD_ENDPOINT 1
50#define KBD_EPSIZE 8
51#define KBD_REPORT_KEYS (KBD_EPSIZE - 2)
52
53/* secondary keyboard */
54#ifdef NKRO_ENABLE
55#define NKRO_INTERFACE 4
56#define NKRO_ENDPOINT 5
57#define NKRO_EPSIZE 16
58#define NKRO_REPORT_KEYS (NKRO_EPSIZE - 1)
59#endif
60
61/* extern report_keyboard_t keyboard_report_sent; */
62
63/* keyboard IN request callback handler */
64void kbd_in_cb(USBDriver *usbp, usbep_t ep);
65
66/* start-of-frame handler */
67void kbd_sof_cb(USBDriver *usbp);
68
69#ifdef NKRO_ENABLE
70/* nkro IN callback hander */
71void nkro_in_cb(USBDriver *usbp, usbep_t ep);
72#endif /* NKRO_ENABLE */
73
74/* ------------
75 * Mouse header
76 * ------------
77 */
78
79#ifdef MOUSE_ENABLE
80
81#define MOUSE_INTERFACE 1
82#define MOUSE_ENDPOINT 2
83#define MOUSE_EPSIZE 8
84
85/* mouse IN request callback handler */
86void mouse_in_cb(USBDriver *usbp, usbep_t ep);
87#endif /* MOUSE_ENABLE */
88
89/* ---------------
90 * Extrakey header
91 * ---------------
92 */
93
94#ifdef EXTRAKEY_ENABLE
95
96#define EXTRA_INTERFACE 3
97#define EXTRA_ENDPOINT 4
98#define EXTRA_EPSIZE 8
99
100/* extrakey IN request callback handler */
101void extra_in_cb(USBDriver *usbp, usbep_t ep);
102
103/* extra report structure */
104typedef struct {
105 uint8_t report_id;
106 uint16_t usage;
107} __attribute__ ((packed)) report_extra_t;
108#endif /* EXTRAKEY_ENABLE */
109
110/* --------------
111 * Console header
112 * --------------
113 */
114
115#ifdef CONSOLE_ENABLE
116
117#define CONSOLE_INTERFACE 2
118#define CONSOLE_ENDPOINT 3
119#define CONSOLE_EPSIZE 16
120
121/* Number of IN reports that can be stored inside the output queue */
122#define CONSOLE_QUEUE_CAPACITY 4
123
124/* Console flush time */
125#define CONSOLE_FLUSH_MS 50
126
127/* Putchar over the USB console */
128int8_t sendchar(uint8_t c);
129
130/* Flush output (send everything immediately) */
131void console_flush_output(void);
132
133/* console IN request callback handler */
134void console_in_cb(USBDriver *usbp, usbep_t ep);
135#endif /* CONSOLE_ENABLE */
136
137void sendchar_pf(void *p, char c);
138
139#endif /* _USB_MAIN_H_ */
diff --git a/tmk_core/readme.md b/tmk_core/readme.md
index 6b6714a6a..f460d0ed4 100644
--- a/tmk_core/readme.md
+++ b/tmk_core/readme.md
@@ -5,6 +5,16 @@ This is a keyboard firmware library with some useful features for Atmel AVR and
5Source code is available here: <https://github.com/tmk/tmk_keyboard/tree/core> 5Source code is available here: <https://github.com/tmk/tmk_keyboard/tree/core>
6 6
7 7
8Updates
9-------
10#### 2016/02/10
11flabbergast's Chibios protocol was merged from <https://github.com/flabbergast/tmk_keyboard/tree/chibios>. See [protocol/chibios/README.md](protocol/chibios/README.md). Chibios protocol supports Cortex-M such as STM32 and Kinetis.
12
13#### 2015/04/22
14separated with TMK Keyboard Firmware Collection
15
16
17
8Features 18Features
9-------- 19--------
10These features can be used in your keyboard. 20These features can be used in your keyboard.
@@ -27,12 +37,6 @@ These features can be used in your keyboard.
27 37
28 38
29 39
30Updates
31-------
322015/04/22 separated with TMK Keyboard Firmware Collection
33
34
35
36TMK Keyboard Firmware Collection 40TMK Keyboard Firmware Collection
37-------------------------------- 41--------------------------------
38Complete firmwares for various keyboards and protocol converters. 42Complete firmwares for various keyboards and protocol converters.
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk
index f8f77e892..96eba24d6 100644
--- a/tmk_core/rules.mk
+++ b/tmk_core/rules.mk
@@ -20,26 +20,11 @@
20# Output format. (can be srec, ihex, binary) 20# Output format. (can be srec, ihex, binary)
21FORMAT = ihex 21FORMAT = ihex
22 22
23BUILD_DIR = .build
24
25# Object files directory
26# To put object files in current directory, use a dot (.), do NOT make
27# this an empty or blank macro!
28OBJDIR = $(BUILD_DIR)/obj_$(TARGET)
29
30
31# Optimization level, can be [0, 1, 2, 3, s]. 23# Optimization level, can be [0, 1, 2, 3, s].
32# 0 = turn off optimization. s = optimize for size. 24# 0 = turn off optimization. s = optimize for size.
33# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) 25# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
34OPT = s 26OPT = s
35 27
36
37# Debugging format.
38# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
39# AVR Studio 4.10 requires dwarf-2.
40# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
41DEBUG = dwarf-2
42
43COLOR ?= true 28COLOR ?= true
44 29
45ifeq ($(COLOR),true) 30ifeq ($(COLOR),true)
@@ -87,7 +72,7 @@ BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [
87# Each directory must be seperated by a space. 72# Each directory must be seperated by a space.
88# Use forward slashes for directory separators. 73# Use forward slashes for directory separators.
89# For a directory that has spaces, enclose it in quotes. 74# For a directory that has spaces, enclose it in quotes.
90EXTRAINCDIRS = $(subst :, ,$(VPATH)) 75EXTRAINCDIRS += $(subst :, ,$(VPATH))
91 76
92 77
93# Compiler flag to set the C Standard level. 78# Compiler flag to set the C Standard level.
@@ -99,17 +84,14 @@ CSTANDARD = -std=gnu99
99 84
100 85
101# Place -D or -U options here for C sources 86# Place -D or -U options here for C sources
102CDEFS = -DF_CPU=$(F_CPU)UL
103CDEFS += $(OPT_DEFS) 87CDEFS += $(OPT_DEFS)
104 88
105 89
106# Place -D or -U options here for ASM sources 90# Place -D or -U options here for ASM sources
107ADEFS = -DF_CPU=$(F_CPU)
108ADEFS += $(OPT_DEFS) 91ADEFS += $(OPT_DEFS)
109 92
110 93
111# Place -D or -U options here for C++ sources 94# Place -D or -U options here for C++ sources
112CPPDEFS = -DF_CPU=$(F_CPU)UL
113#CPPDEFS += -D__STDC_LIMIT_MACROS 95#CPPDEFS += -D__STDC_LIMIT_MACROS
114#CPPDEFS += -D__STDC_CONSTANT_MACROS 96#CPPDEFS += -D__STDC_CONSTANT_MACROS
115CPPDEFS += $(OPT_DEFS) 97CPPDEFS += $(OPT_DEFS)
@@ -123,17 +105,9 @@ CPPDEFS += $(OPT_DEFS)
123# -Wall...: warning level 105# -Wall...: warning level
124# -Wa,...: tell GCC to pass this to the assembler. 106# -Wa,...: tell GCC to pass this to the assembler.
125# -adhlns...: create assembler listing 107# -adhlns...: create assembler listing
126CFLAGS = -g$(DEBUG) 108CFLAGS += -g$(DEBUG)
127CFLAGS += $(CDEFS) 109CFLAGS += $(CDEFS)
128CFLAGS += -O$(OPT) 110CFLAGS += -O$(OPT)
129CFLAGS += -funsigned-char
130CFLAGS += -funsigned-bitfields
131CFLAGS += -ffunction-sections
132CFLAGS += -fdata-sections
133CFLAGS += -fno-inline-small-functions
134CFLAGS += -fpack-struct
135CFLAGS += -fshort-enums
136CFLAGS += -fno-strict-aliasing
137# add color 111# add color
138ifeq ($(COLOR),true) 112ifeq ($(COLOR),true)
139ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "") 113ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
@@ -162,16 +136,9 @@ endif
162# -Wall...: warning level 136# -Wall...: warning level
163# -Wa,...: tell GCC to pass this to the assembler. 137# -Wa,...: tell GCC to pass this to the assembler.
164# -adhlns...: create assembler listing 138# -adhlns...: create assembler listing
165CPPFLAGS = -g$(DEBUG) 139CPPFLAGS += -g$(DEBUG)
166CPPFLAGS += $(CPPDEFS) 140CPPFLAGS += $(CPPDEFS)
167CPPFLAGS += -O$(OPT) 141CPPFLAGS += -O$(OPT)
168CPPFLAGS += -funsigned-char
169CPPFLAGS += -funsigned-bitfields
170CPPFLAGS += -fpack-struct
171CPPFLAGS += -fshort-enums
172CPPFLAGS += -fno-exceptions
173CPPFLAGS += -ffunction-sections
174CPPFLAGS += -fdata-sections
175# to supress "warning: only initialized variables can be placed into program memory area" 142# to supress "warning: only initialized variables can be placed into program memory area"
176CPPFLAGS += -w 143CPPFLAGS += -w
177CPPFLAGS += -Wall 144CPPFLAGS += -Wall
@@ -198,7 +165,7 @@ endif
198# files -- see avr-libc docs [FIXME: not yet described there] 165# files -- see avr-libc docs [FIXME: not yet described there]
199# -listing-cont-lines: Sets the maximum number of continuation lines of hex 166# -listing-cont-lines: Sets the maximum number of continuation lines of hex
200# dump that will be displayed for a given single line of source input. 167# dump that will be displayed for a given single line of source input.
201ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 168ASFLAGS += $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
202ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) 169ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
203ifdef CONFIG_H 170ifdef CONFIG_H
204 ASFLAGS += -include $(CONFIG_H) 171 ASFLAGS += -include $(CONFIG_H)
@@ -232,28 +199,6 @@ SCANF_LIB =
232MATH_LIB = -lm 199MATH_LIB = -lm
233 200
234 201
235# List any extra directories to look for libraries here.
236# Each directory must be seperated by a space.
237# Use forward slashes for directory separators.
238# For a directory that has spaces, enclose it in quotes.
239EXTRALIBDIRS =
240
241
242
243#---------------- External Memory Options ----------------
244
245# 64 KB of external RAM, starting after internal RAM (ATmega128!),
246# used for variables (.data/.bss) and heap (malloc()).
247#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
248
249# 64 KB of external RAM, starting after internal RAM (ATmega128!),
250# only used for heap (malloc()).
251#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
252
253EXTMEMOPTS =
254
255
256
257#---------------- Linker Options ---------------- 202#---------------- Linker Options ----------------
258# -Wl,...: tell GCC to pass this to linker. 203# -Wl,...: tell GCC to pass this to linker.
259# -Map: create map file 204# -Map: create map file
@@ -262,9 +207,8 @@ EXTMEMOPTS =
262# Comennt out "--relax" option to avoid a error such: 207# Comennt out "--relax" option to avoid a error such:
263# (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12' 208# (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
264# 209#
265LDFLAGS = -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref 210LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
266#LDFLAGS += -Wl,--relax 211#LDFLAGS += -Wl,--relax
267LDFLAGS += -Wl,--gc-sections
268LDFLAGS += $(EXTMEMOPTS) 212LDFLAGS += $(EXTMEMOPTS)
269LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) 213LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
270LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) 214LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
@@ -272,59 +216,13 @@ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
272# You can give EXTRALDFLAGS at 'make' command line. 216# You can give EXTRALDFLAGS at 'make' command line.
273LDFLAGS += $(EXTRALDFLAGS) 217LDFLAGS += $(EXTRALDFLAGS)
274 218
275
276
277#---------------- Debugging Options ----------------
278
279# For simulavr only - target MCU frequency.
280DEBUG_MFREQ = $(F_CPU)
281
282# Set the DEBUG_UI to either gdb or insight.
283# DEBUG_UI = gdb
284DEBUG_UI = insight
285
286# Set the debugging back-end to either avarice, simulavr.
287DEBUG_BACKEND = avarice
288#DEBUG_BACKEND = simulavr
289
290# GDB Init Filename.
291GDBINIT_FILE = __avr_gdbinit
292
293# When using avarice settings for the JTAG
294JTAG_DEV = /dev/com1
295
296# Debugging port used to communicate between GDB / avarice / simulavr.
297DEBUG_PORT = 4242
298
299# Debugging host used to communicate between GDB / avarice / simulavr, normally
300# just set to localhost unless doing some sort of crazy debugging when
301# avarice is running on a different computer.
302DEBUG_HOST = localhost
303
304
305
306#============================================================================
307
308
309# Define programs and commands. 219# Define programs and commands.
310SHELL = sh 220SHELL = sh
311CC = avr-gcc
312OBJCOPY = avr-objcopy
313OBJDUMP = avr-objdump
314SIZE = avr-size
315AR = avr-ar rcs
316NM = avr-nm
317REMOVE = rm -f 221REMOVE = rm -f
318REMOVEDIR = rmdir 222REMOVEDIR = rmdir
319COPY = cp 223COPY = cp
320WINSHELL = cmd 224WINSHELL = cmd
321SECHO = $(SILENT) || echo 225SECHO = $(SILENT) || echo
322# Autodecct teensy loader
323ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
324 TEENSY_LOADER_CLI = teensy-loader-cli
325else
326 TEENSY_LOADER_CLI = teensy_loader_cli
327endif
328 226
329# Define Messages 227# Define Messages
330# English 228# English
@@ -347,8 +245,6 @@ MSG_CLEANING = Cleaning project:
347MSG_CREATING_LIBRARY = Creating library: 245MSG_CREATING_LIBRARY = Creating library:
348 246
349 247
350
351
352# Define all object files. 248# Define all object files.
353OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC)))) 249OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
354 250
@@ -364,9 +260,9 @@ GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$@).d
364# Combine all necessary flags and optional flags. 260# Combine all necessary flags and optional flags.
365# Add target processor to flags. 261# Add target processor to flags.
366# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar 262# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
367ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) 263ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
368ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) 264ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
369ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) 265ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
370 266
371# Default target. 267# Default target.
372all: 268all:
@@ -432,104 +328,10 @@ sizeafter:
432gccversion : 328gccversion :
433 @$(SILENT) || $(CC) --version 329 @$(SILENT) || $(CC) --version
434 330
435
436
437# Program the device.
438program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
439 $(PROGRAM_CMD)
440
441teensy: $(BUILD_DIR)/$(TARGET).hex
442 $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
443
444flip: $(BUILD_DIR)/$(TARGET).hex
445 batchisp -hardware usb -device $(MCU) -operation erase f
446 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
447 batchisp -hardware usb -device $(MCU) -operation start reset 0
448
449dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
450ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
451 dfu-programmer $(MCU) erase --force
452else
453 dfu-programmer $(MCU) erase
454endif
455 dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
456 dfu-programmer $(MCU) reset
457
458dfu-start:
459 dfu-programmer $(MCU) reset
460 dfu-programmer $(MCU) start
461
462flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
463 $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
464 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
465 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
466 batchisp -hardware usb -device $(MCU) -operation start reset 0
467 $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
468
469dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
470ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
471 dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
472else
473 dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
474endif
475 dfu-programmer $(MCU) reset
476
477
478# Generate avr-gdb config/init file which does the following:
479# define the reset signal, load the target file, connect to target, and set
480# a breakpoint at main().
481gdb-config:
482 @$(REMOVE) $(GDBINIT_FILE)
483 @echo define reset >> $(GDBINIT_FILE)
484 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
485 @echo end >> $(GDBINIT_FILE)
486 @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
487 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
488ifeq ($(DEBUG_BACKEND),simulavr)
489 @echo load >> $(GDBINIT_FILE)
490endif
491 @echo break main >> $(GDBINIT_FILE)
492
493debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
494ifeq ($(DEBUG_BACKEND), avarice)
495 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
496 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
497 $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
498 @$(WINSHELL) /c pause
499
500else
501 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
502 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
503endif
504 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
505
506
507
508
509# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
510COFFCONVERT = $(OBJCOPY) --debugging
511COFFCONVERT += --change-section-address .data-0x800000
512COFFCONVERT += --change-section-address .bss-0x800000
513COFFCONVERT += --change-section-address .noinit-0x800000
514COFFCONVERT += --change-section-address .eeprom-0x810000
515
516
517
518coff: $(BUILD_DIR)/$(TARGET).elf
519 @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
520 $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
521
522
523extcoff: $(BUILD_DIR)/$(TARGET).elf
524 @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
525 $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
526
527
528
529# Create final output files (.hex, .eep) from ELF output file. 331# Create final output files (.hex, .eep) from ELF output file.
530%.hex: %.elf 332%.hex: %.elf
531 @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD) 333 @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
532 $(eval CMD=$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@) 334 $(eval CMD=$(HEX) $< $@)
533 @$(BUILD_CMD) 335 @$(BUILD_CMD)
534 @if $(AUTOGEN); then \ 336 @if $(AUTOGEN); then \
535 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \ 337 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
@@ -540,7 +342,7 @@ extcoff: $(BUILD_DIR)/$(TARGET).elf
540 342
541%.eep: %.elf 343%.eep: %.elf
542 @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD) 344 @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
543 $(eval CMD=$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0) 345 $(eval CMD=$(EEP) $< $@ || exit 0)
544 @$(BUILD_CMD) 346 @$(BUILD_CMD)
545 347
546# Create extended listing file from ELF output file. 348# Create extended listing file from ELF output file.
@@ -622,7 +424,7 @@ show_path:
622 @echo VPATH=$(VPATH) 424 @echo VPATH=$(VPATH)
623 @echo SRC=$(SRC) 425 @echo SRC=$(SRC)
624 426
625SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/.))) 427SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
626SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.)) 428SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
627SUBDIRS := $(sort $(SUBDIRS)) 429SUBDIRS := $(sort $(SUBDIRS))
628# $(error $(SUBDIRS)) 430# $(error $(SUBDIRS))
diff --git a/tmk_core/tool/chibios/.gitignore b/tmk_core/tool/chibios/.gitignore
new file mode 100644
index 000000000..88bbafe34
--- /dev/null
+++ b/tmk_core/tool/chibios/.gitignore
@@ -0,0 +1,2 @@
1chibios
2chibios-contrib
diff --git a/tmk_core/tool/chibios/ch-bootloader-jump.patch b/tmk_core/tool/chibios/ch-bootloader-jump.patch
new file mode 100644
index 000000000..d88657621
--- /dev/null
+++ b/tmk_core/tool/chibios/ch-bootloader-jump.patch
@@ -0,0 +1,116 @@
1diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
2index 51a79bb..42d07bd 100644
3--- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
4+++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v6m.s
5@@ -105,6 +105,13 @@
6 #define CRT0_CALL_DESTRUCTORS TRUE
7 #endif
8
9+/**
10+ * @brief Magic number for jumping to bootloader.
11+ */
12+#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)
13+#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF
14+#endif
15+
16 /*===========================================================================*/
17 /* Code section. */
18 /*===========================================================================*/
19@@ -124,6 +131,17 @@
20 .thumb_func
21 .global Reset_Handler
22 Reset_Handler:
23+
24+#ifdef STM32_BOOTLOADER_ADDRESS
25+ /* jump to bootloader code */
26+ ldr r0, =__ram0_end__-4
27+ ldr r1, =MAGIC_BOOTLOADER_NUMBER
28+ ldr r2, [r0, #0]
29+ str r0, [r0, #0] /* erase stored magic */
30+ cmp r2, r1
31+ beq Bootloader_Jump
32+#endif /* STM32_BOOTLOADER_ADDRESS */
33+
34 /* Interrupts are globally masked initially.*/
35 cpsid i
36
37@@ -242,6 +260,21 @@ endfiniloop:
38 ldr r1, =__default_exit
39 bx r1
40
41+#ifdef STM32_BOOTLOADER_ADDRESS
42+/*
43+ * Jump-to-bootloader function.
44+ */
45+
46+ .align 2
47+ .thumb_func
48+Bootloader_Jump:
49+ ldr r0, =STM32_BOOTLOADER_ADDRESS
50+ ldr r1, [r0, #0]
51+ mov sp, r1
52+ ldr r0, [r0, #4]
53+ bx r0
54+#endif /* STM32_BOOTLOADER_ADDRESS */
55+
56 #endif
57
58 /** @} */
59diff --git a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
60index 4812a29..dca9f88 100644
61--- a/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
62+++ b/os/common/ports/ARMCMx/compilers/GCC/crt0_v7m.s
63@@ -140,6 +140,13 @@
64 #define CRT0_CPACR_INIT 0x00F00000
65 #endif
66
67+/**
68+ * @brief Magic number for jumping to bootloader.
69+ */
70+#if !defined(MAGIC_BOOTLOADER_NUMBER) || defined(__DOXYGEN__)
71+#define MAGIC_BOOTLOADER_NUMBER 0xDEADBEEF
72+#endif
73+
74 /*===========================================================================*/
75 /* Code section. */
76 /*===========================================================================*/
77@@ -164,6 +171,17 @@
78 .thumb_func
79 .global Reset_Handler
80 Reset_Handler:
81+
82+#ifdef STM32_BOOTLOADER_ADDRESS
83+ /* jump to bootloader code */
84+ ldr r0, =__ram0_end__-4
85+ ldr r1, =MAGIC_BOOTLOADER_NUMBER
86+ ldr r2, [r0, #0]
87+ str r0, [r0, #0] /* erase stored magic */
88+ cmp r2, r1
89+ beq Bootloader_Jump
90+#endif /* STM32_BOOTLOADER_ADDRESS */
91+
92 /* Interrupts are globally masked initially.*/
93 cpsid i
94
95@@ -305,6 +323,21 @@ endfiniloop:
96 /* Branching to the defined exit handler.*/
97 b __default_exit
98
99+#ifdef STM32_BOOTLOADER_ADDRESS
100+/*
101+ * Jump-to-bootloader function.
102+ */
103+
104+ .align 2
105+ .thumb_func
106+Bootloader_Jump:
107+ ldr r0, =STM32_BOOTLOADER_ADDRESS
108+ ldr r1, [r0, #0]
109+ mov sp, r1
110+ ldr r0, [r0, #4]
111+ bx r0
112+#endif /* STM32_BOOTLOADER_ADDRESS */
113+
114 #endif /* !defined(__DOXYGEN__) */
115
116 /** @} */