--- /dev/null
+# Target file name (without extension).
+PROJECT = ch
+
+# Directory common source files exist
+TMK_DIR = ../../tmk_core
+
+# Directory keyboard dependent files exist
+TARGET_DIR = .
+
+# project specific files
+SRC = matrix.c \
+ led.c
+
+ifdef KEYMAP
+ SRC := keymap_$(KEYMAP).c $(SRC)
+else
+ SRC := keymap_plain.c $(SRC)
+endif
+
+CONFIG_H = config.h
+
+## chip/board settings
+# - the next two should match the directories in
+# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
+# - For Teensies, FAMILY = KINETIS and SERIES is either
+# KL2x (LC) or K20x (3.0,3.1,3.2).
+MCU_FAMILY = KINETIS
+MCU_SERIES = KL2x
+
+# Linker script to use
+# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
+# or <this_dir>/ld/
+# - NOTE: a custom ld script is needed for EEPROM on Teensy LC
+# - LDSCRIPT =
+# - MKL26Z64 for Teensy LC
+# - MK20DX128 for Teensy 3.0
+# - MK20DX256 for Teensy 3.1 and 3.2
+MCU_LDSCRIPT = MKL26Z64
+
+# Startup code to use
+# - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
+# - STARTUP =
+# - kl2x for Teensy LC
+# - k20x5 for Teensy 3.0
+# - k20x7 for Teensy 3.1 and 3.2
+MCU_STARTUP = kl2x
+
+# Board: it should exist either in <chibios>/os/hal/boards/
+# or <this_dir>/boards
+# - BOARD =
+# - PJRC_TEENSY_LC for Teensy LC
+# - PJRC_TEENSY_3 for Teensy 3.0
+# - PJRC_TEENSY_3_1 for Teensy 3.1 or 3.2
+BOARD = PJRC_TEENSY_LC
+
+# Cortex version
+# Teensy LC is cortex-m0plus; Teensy 3.x are cortex-m4
+MCU = cortex-m0plus
+
+# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
+# I.e. 6 for Teensy LC; 7 for Teensy 3.x
+ARMV = 6
+
+# Build Options
+# comment out to disable the options.
+#
+BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
+## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
+MOUSEKEY_ENABLE = yes # Mouse keys
+EXTRAKEY_ENABLE = yes # Audio control and System control
+CONSOLE_ENABLE = yes # Console for debug
+COMMAND_ENABLE = yes # Commands for debug and configuration
+SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
+NKRO_ENABLE = yes # USB Nkey Rollover
+
+include $(TMK_DIR)/tool/chibios/common.mk
+include $(TMK_DIR)/tool/chibios/chibios.mk
--- /dev/null
+# Target file name (without extension).
+PROJECT = ch
+
+# Directory common source files exist
+TMK_DIR = ../../tmk_core
+
+# Directory keyboard dependent files exist
+TARGET_DIR = .
+
+# project specific files
+SRC = matrix.c \
+ led.c
+
+ifdef KEYMAP
+ SRC := keymap_$(KEYMAP).c $(SRC)
+else
+ SRC := keymap_plain.c $(SRC)
+endif
+
+CONFIG_H = config.h
+
+## chip/board settings
+# - the next two should match the directories in
+# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
+# - For Teensies, FAMILY = KINETIS and SERIES is either
+# KL2x (LC) or K20x (3.0,3.1,3.2).
+MCU_FAMILY = KINETIS
+MCU_SERIES = K20x
+
+# Linker script to use
+# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
+# or <this_dir>/ld/
+# - NOTE: a custom ld script is needed for EEPROM on Teensy LC
+# - LDSCRIPT =
+# - MKL26Z64 for Teensy LC
+# - MK20DX128 for Teensy 3.0
+# - MK20DX256 for Teensy 3.1 and 3.2
+MCU_LDSCRIPT = MK20DX128
+
+# Startup code to use
+# - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
+# - STARTUP =
+# - kl2x for Teensy LC
+# - k20x5 for Teensy 3.0
+# - k20x7 for Teensy 3.1 and 3.2
+MCU_STARTUP = k20x5
+
+# Board: it should exist either in <chibios>/os/hal/boards/
+# or <this_dir>/boards
+# - BOARD =
+# - PJRC_TEENSY_LC for Teensy LC
+# - PJRC_TEENSY_3 for Teensy 3.0
+# - PJRC_TEENSY_3_1 for Teensy 3.1 or 3.2
+BOARD = PJRC_TEENSY_3
+
+# Cortex version
+# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4
+MCU = cortex-m4
+
+# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
+# I.e. 6 for Teensy LC; 7 for Teensy 3.x
+ARMV = 7
+
+# Build Options
+# comment out to disable the options.
+#
+BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
+## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
+MOUSEKEY_ENABLE = yes # Mouse keys
+EXTRAKEY_ENABLE = yes # Audio control and System control
+CONSOLE_ENABLE = yes # Console for debug
+COMMAND_ENABLE = yes # Commands for debug and configuration
+SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
+NKRO_ENABLE = yes # USB Nkey Rollover
+
+include $(TMK_DIR)/tool/chibios/common.mk
+include $(TMK_DIR)/tool/chibios/chibios.mk
--- /dev/null
+# Target file name (without extension).
+PROJECT = ch
+
+# Directory common source files exist
+TMK_DIR = ../../tmk_core
+
+# Directory keyboard dependent files exist
+TARGET_DIR = .
+
+# project specific files
+SRC = matrix.c \
+ led.c
+
+ifdef KEYMAP
+ SRC := keymap_$(KEYMAP).c $(SRC)
+else
+ SRC := keymap_plain.c $(SRC)
+endif
+
+CONFIG_H = config.h
+
+## chip/board settings
+# - the next two should match the directories in
+# <chibios>/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)
+# - For Teensies, FAMILY = KINETIS and SERIES is either
+# KL2x (LC) or K20x (3.0,3.1,3.2).
+MCU_FAMILY = KINETIS
+MCU_SERIES = K20x
+
+# Linker script to use
+# - it should exist either in <chibios>/os/common/ports/ARMCMx/compilers/GCC/ld/
+# or <this_dir>/ld/
+# - NOTE: a custom ld script is needed for EEPROM on Teensy LC
+# - LDSCRIPT =
+# - MKL26Z64 for Teensy LC
+# - MK20DX128 for Teensy 3.0
+# - MK20DX256 for Teensy 3.1 and 3.2
+MCU_LDSCRIPT = MK20DX256
+
+# Startup code to use
+# - it should exist in <chibios>/os/common/ports/ARMCMx/compilers/GCC/mk/
+# - STARTUP =
+# - kl2x for Teensy LC
+# - k20x5 for Teensy 3.0
+# - k20x7 for Teensy 3.1 and 3.2
+MCU_STARTUP = k20x7
+
+# Board: it should exist either in <chibios>/os/hal/boards/
+# or <this_dir>/boards
+# - BOARD =
+# - PJRC_TEENSY_LC for Teensy LC
+# - PJRC_TEENSY_3 for Teensy 3.0
+# - PJRC_TEENSY_3_1 for Teensy 3.1 or 3.2
+BOARD = PJRC_TEENSY_3_1
+
+# Cortex version
+# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4
+MCU = cortex-m4
+
+# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7
+# I.e. 6 for Teensy LC; 7 for Teensy 3.x
+ARMV = 7
+
+# Build Options
+# comment out to disable the options.
+#
+BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration
+## (Note that for BOOTMAGIC on Teensy LC you have to use a custom .ld script.)
+MOUSEKEY_ENABLE = yes # Mouse keys
+EXTRAKEY_ENABLE = yes # Audio control and System control
+CONSOLE_ENABLE = yes # Console for debug
+COMMAND_ENABLE = yes # Commands for debug and configuration
+SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
+NKRO_ENABLE = yes # USB Nkey Rollover
+
+include $(TMK_DIR)/tool/chibios/common.mk
+include $(TMK_DIR)/tool/chibios/chibios.mk
--- /dev/null
+/*\r
+ ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+\r
+/**\r
+ * @file templates/chconf.h\r
+ * @brief Configuration file template.\r
+ * @details A copy of this file must be placed in each project directory, it\r
+ * contains the application specific kernel settings.\r
+ *\r
+ * @addtogroup config\r
+ * @details Kernel related settings and hooks.\r
+ * @{\r
+ */\r
+\r
+#ifndef CHCONF_H\r
+#define CHCONF_H\r
+\r
+#define _CHIBIOS_RT_CONF_\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name System timers settings\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief System time counter resolution.\r
+ * @note Allowed values are 16 or 32 bits.\r
+ */\r
+#define CH_CFG_ST_RESOLUTION 32\r
+\r
+/**\r
+ * @brief System tick frequency.\r
+ * @details Frequency of the system timer that drives the system ticks. This\r
+ * setting also defines the system tick time unit.\r
+ */\r
+#define CH_CFG_ST_FREQUENCY 1000\r
+\r
+/**\r
+ * @brief Time delta constant for the tick-less mode.\r
+ * @note If this value is zero then the system uses the classic\r
+ * periodic tick. This value represents the minimum number\r
+ * of ticks that is safe to specify in a timeout directive.\r
+ * The value one is not valid, timeouts are rounded up to\r
+ * this value.\r
+ */\r
+#define CH_CFG_ST_TIMEDELTA 0\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Kernel parameters and options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief Round robin interval.\r
+ * @details This constant is the number of system ticks allowed for the\r
+ * threads before preemption occurs. Setting this value to zero\r
+ * disables the preemption for threads with equal priority and the\r
+ * round robin becomes cooperative. Note that higher priority\r
+ * threads can still preempt, the kernel is always preemptive.\r
+ * @note Disabling the round robin preemption makes the kernel more compact\r
+ * and generally faster.\r
+ * @note The round robin preemption is not supported in tickless mode and\r
+ * must be set to zero in that case.\r
+ */\r
+#define CH_CFG_TIME_QUANTUM 20\r
+\r
+/**\r
+ * @brief Managed RAM size.\r
+ * @details Size of the RAM area to be managed by the OS. If set to zero\r
+ * then the whole available RAM is used. The core memory is made\r
+ * available to the heap allocator and/or can be used directly through\r
+ * the simplified core memory allocator.\r
+ *\r
+ * @note In order to let the OS manage the whole RAM the linker script must\r
+ * provide the @p __heap_base__ and @p __heap_end__ symbols.\r
+ * @note Requires @p CH_CFG_USE_MEMCORE.\r
+ */\r
+#define CH_CFG_MEMCORE_SIZE 0\r
+\r
+/**\r
+ * @brief Idle thread automatic spawn suppression.\r
+ * @details When this option is activated the function @p chSysInit()\r
+ * does not spawn the idle thread. The application @p main()\r
+ * function becomes the idle thread and must implement an\r
+ * infinite loop.\r
+ */\r
+#define CH_CFG_NO_IDLE_THREAD FALSE\r
+\r
+/* Use __WFI in the idle thread for waiting. Does lower the power\r
+ * consumption. */\r
+#define CORTEX_ENABLE_WFI_IDLE TRUE\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Performance options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief OS optimization.\r
+ * @details If enabled then time efficient rather than space efficient code\r
+ * is used when two possible implementations exist.\r
+ *\r
+ * @note This is not related to the compiler optimization options.\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_OPTIMIZE_SPEED TRUE\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Subsystem options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief Time Measurement APIs.\r
+ * @details If enabled then the time measurement APIs are included in\r
+ * the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_TM FALSE\r
+\r
+/**\r
+ * @brief Threads registry APIs.\r
+ * @details If enabled then the registry APIs are included in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_REGISTRY TRUE\r
+\r
+/**\r
+ * @brief Threads synchronization APIs.\r
+ * @details If enabled then the @p chThdWait() function is included in\r
+ * the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_WAITEXIT TRUE\r
+\r
+/**\r
+ * @brief Semaphores APIs.\r
+ * @details If enabled then the Semaphores APIs are included in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_SEMAPHORES TRUE\r
+\r
+/**\r
+ * @brief Semaphores queuing mode.\r
+ * @details If enabled then the threads are enqueued on semaphores by\r
+ * priority rather than in FIFO order.\r
+ *\r
+ * @note The default is @p FALSE. Enable this if you have special\r
+ * requirements.\r
+ * @note Requires @p CH_CFG_USE_SEMAPHORES.\r
+ */\r
+#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE\r
+\r
+/**\r
+ * @brief Mutexes APIs.\r
+ * @details If enabled then the mutexes APIs are included in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_MUTEXES TRUE\r
+\r
+/**\r
+ * @brief Enables recursive behavior on mutexes.\r
+ * @note Recursive mutexes are heavier and have an increased\r
+ * memory footprint.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ * @note Requires @p CH_CFG_USE_MUTEXES.\r
+ */\r
+#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE\r
+\r
+/**\r
+ * @brief Conditional Variables APIs.\r
+ * @details If enabled then the conditional variables APIs are included\r
+ * in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ * @note Requires @p CH_CFG_USE_MUTEXES.\r
+ */\r
+#define CH_CFG_USE_CONDVARS TRUE\r
+\r
+/**\r
+ * @brief Conditional Variables APIs with timeout.\r
+ * @details If enabled then the conditional variables APIs with timeout\r
+ * specification are included in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ * @note Requires @p CH_CFG_USE_CONDVARS.\r
+ */\r
+#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE\r
+\r
+/**\r
+ * @brief Events Flags APIs.\r
+ * @details If enabled then the event flags APIs are included in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_EVENTS TRUE\r
+\r
+/**\r
+ * @brief Events Flags APIs with timeout.\r
+ * @details If enabled then the events APIs with timeout specification\r
+ * are included in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ * @note Requires @p CH_CFG_USE_EVENTS.\r
+ */\r
+#define CH_CFG_USE_EVENTS_TIMEOUT TRUE\r
+\r
+/**\r
+ * @brief Synchronous Messages APIs.\r
+ * @details If enabled then the synchronous messages APIs are included\r
+ * in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_MESSAGES TRUE\r
+\r
+/**\r
+ * @brief Synchronous Messages queuing mode.\r
+ * @details If enabled then messages are served by priority rather than in\r
+ * FIFO order.\r
+ *\r
+ * @note The default is @p FALSE. Enable this if you have special\r
+ * requirements.\r
+ * @note Requires @p CH_CFG_USE_MESSAGES.\r
+ */\r
+#define CH_CFG_USE_MESSAGES_PRIORITY FALSE\r
+\r
+/**\r
+ * @brief Mailboxes APIs.\r
+ * @details If enabled then the asynchronous messages (mailboxes) APIs are\r
+ * included in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ * @note Requires @p CH_CFG_USE_SEMAPHORES.\r
+ */\r
+#define CH_CFG_USE_MAILBOXES TRUE\r
+\r
+/**\r
+ * @brief Core Memory Manager APIs.\r
+ * @details If enabled then the core memory manager APIs are included\r
+ * in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_MEMCORE TRUE\r
+\r
+/**\r
+ * @brief Heap Allocator APIs.\r
+ * @details If enabled then the memory heap allocator APIs are included\r
+ * in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or\r
+ * @p CH_CFG_USE_SEMAPHORES.\r
+ * @note Mutexes are recommended.\r
+ */\r
+#define CH_CFG_USE_HEAP TRUE\r
+\r
+/**\r
+ * @brief Memory Pools Allocator APIs.\r
+ * @details If enabled then the memory pools allocator APIs are included\r
+ * in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ */\r
+#define CH_CFG_USE_MEMPOOLS TRUE\r
+\r
+/**\r
+ * @brief Dynamic Threads APIs.\r
+ * @details If enabled then the dynamic threads creation APIs are included\r
+ * in the kernel.\r
+ *\r
+ * @note The default is @p TRUE.\r
+ * @note Requires @p CH_CFG_USE_WAITEXIT.\r
+ * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.\r
+ */\r
+#define CH_CFG_USE_DYNAMIC TRUE\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Debug options\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief Debug option, kernel statistics.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ */\r
+#define CH_DBG_STATISTICS FALSE\r
+\r
+/**\r
+ * @brief Debug option, system state check.\r
+ * @details If enabled the correct call protocol for system APIs is checked\r
+ * at runtime.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ */\r
+#define CH_DBG_SYSTEM_STATE_CHECK TRUE\r
+\r
+/**\r
+ * @brief Debug option, parameters checks.\r
+ * @details If enabled then the checks on the API functions input\r
+ * parameters are activated.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ */\r
+#define CH_DBG_ENABLE_CHECKS TRUE\r
+\r
+/**\r
+ * @brief Debug option, consistency checks.\r
+ * @details If enabled then all the assertions in the kernel code are\r
+ * activated. This includes consistency checks inside the kernel,\r
+ * runtime anomalies and port-defined checks.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ */\r
+#define CH_DBG_ENABLE_ASSERTS TRUE\r
+\r
+/**\r
+ * @brief Debug option, trace buffer.\r
+ * @details If enabled then the trace buffer is activated.\r
+ *\r
+ * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.\r
+ */\r
+#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED\r
+\r
+/**\r
+ * @brief Trace buffer entries.\r
+ * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is\r
+ * different from @p CH_DBG_TRACE_MASK_DISABLED.\r
+ */\r
+#define CH_DBG_TRACE_BUFFER_SIZE 128\r
+\r
+/**\r
+ * @brief Debug option, stack checks.\r
+ * @details If enabled then a runtime stack check is performed.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ * @note The stack check is performed in a architecture/port dependent way.\r
+ * It may not be implemented or some ports.\r
+ * @note The default failure mode is to halt the system with the global\r
+ * @p panic_msg variable set to @p NULL.\r
+ */\r
+#define CH_DBG_ENABLE_STACK_CHECK TRUE\r
+\r
+/**\r
+ * @brief Debug option, stacks initialization.\r
+ * @details If enabled then the threads working area is filled with a byte\r
+ * value when a thread is created. This can be useful for the\r
+ * runtime measurement of the used stack.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ */\r
+#define CH_DBG_FILL_THREADS TRUE\r
+\r
+/**\r
+ * @brief Debug option, threads profiling.\r
+ * @details If enabled then a field is added to the @p thread_t structure that\r
+ * counts the system ticks occurred while executing the thread.\r
+ *\r
+ * @note The default is @p FALSE.\r
+ * @note This debug option is not currently compatible with the\r
+ * tickless mode.\r
+ */\r
+#define CH_DBG_THREADS_PROFILING FALSE\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/**\r
+ * @name Kernel hooks\r
+ * @{\r
+ */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief Threads descriptor structure extension.\r
+ * @details User fields added to the end of the @p thread_t structure.\r
+ */\r
+#define CH_CFG_THREAD_EXTRA_FIELDS \\r
+ /* Add threads custom fields here.*/\r
+\r
+/**\r
+ * @brief Threads initialization hook.\r
+ * @details User initialization code added to the @p chThdInit() API.\r
+ *\r
+ * @note It is invoked from within @p chThdInit() and implicitly from all\r
+ * the threads creation APIs.\r
+ */\r
+#define CH_CFG_THREAD_INIT_HOOK(tp) { \\r
+ /* Add threads initialization code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief Threads finalization hook.\r
+ * @details User finalization code added to the @p chThdExit() API.\r
+ */\r
+#define CH_CFG_THREAD_EXIT_HOOK(tp) { \\r
+ /* Add threads finalization code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief Context switch hook.\r
+ * @details This hook is invoked just before switching between threads.\r
+ */\r
+#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \\r
+ /* Context switch code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief ISR enter hook.\r
+ */\r
+#define CH_CFG_IRQ_PROLOGUE_HOOK() { \\r
+ /* IRQ prologue code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief ISR exit hook.\r
+ */\r
+#define CH_CFG_IRQ_EPILOGUE_HOOK() { \\r
+ /* IRQ epilogue code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief Idle thread enter hook.\r
+ * @note This hook is invoked within a critical zone, no OS functions\r
+ * should be invoked from here.\r
+ * @note This macro can be used to activate a power saving mode.\r
+ */\r
+#define CH_CFG_IDLE_ENTER_HOOK() { \\r
+ /* Idle-enter code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief Idle thread leave hook.\r
+ * @note This hook is invoked within a critical zone, no OS functions\r
+ * should be invoked from here.\r
+ * @note This macro can be used to deactivate a power saving mode.\r
+ */\r
+#define CH_CFG_IDLE_LEAVE_HOOK() { \\r
+ /* Idle-leave code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief Idle Loop hook.\r
+ * @details This hook is continuously invoked by the idle thread loop.\r
+ */\r
+#define CH_CFG_IDLE_LOOP_HOOK() { \\r
+ /* Idle loop code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief System tick event hook.\r
+ * @details This hook is invoked in the system tick handler immediately\r
+ * after processing the virtual timers queue.\r
+ */\r
+#define CH_CFG_SYSTEM_TICK_HOOK() { \\r
+ /* System tick event code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief System halt hook.\r
+ * @details This hook is invoked in case to a system halting error before\r
+ * the system is halted.\r
+ */\r
+#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \\r
+ /* System halt code here.*/ \\r
+}\r
+\r
+/**\r
+ * @brief Trace hook.\r
+ * @details This hook is invoked each time a new record is written in the\r
+ * trace buffer.\r
+ */\r
+#define CH_CFG_TRACE_HOOK(tep) { \\r
+ /* Trace code here.*/ \\r
+}\r
+\r
+/** @} */\r
+\r
+/*===========================================================================*/\r
+/* Port-specific settings (override port settings defaulted in chcore.h). */\r
+/*===========================================================================*/\r
+\r
+#endif /* CHCONF_H */\r
+\r
+/** @} */\r
--- /dev/null
+/*
+Copyright 2015 Jun Wako <wakojun@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+
+/* USB Device descriptor parameter */
+#define VENDOR_ID 0xFEED
+#define PRODUCT_ID 0x6464
+#define DEVICE_VER 0x0001
+/* in python2: list(u"whatever".encode('utf-16-le')) */
+/* at most 32 characters or the ugly hack in usb_main.c borks */
+#define MANUFACTURER "TMK"
+#define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', '\xc6', '\x00'
+#define PRODUCT "ChibiOS TMK test"
+#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'
+#define DESCRIPTION "TMK keyboard firmware over ChibiOS"
+
+/* key matrix size */
+#define MATRIX_ROWS 6
+#define MATRIX_COLS 17
+
+/* define if matrix has ghost */
+//#define MATRIX_HAS_GHOST
+
+/* Set 0 if debouncing isn't needed */
+#define DEBOUNCE 5
+
+/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
+#define LOCKING_SUPPORT_ENABLE
+/* Locking resynchronize hack */
+#define LOCKING_RESYNC_ENABLE
+
+/* key combination for command */
+#define IS_COMMAND() ( \
+ keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
+)
+
+
+
+/*
+ * Feature disable options
+ * These options are also useful to firmware size reduction.
+ */
+
+/* disable debug print */
+//#define NO_DEBUG
+
+/* disable print */
+//#define NO_PRINT
+
+/* disable action features */
+//#define NO_ACTION_LAYER
+//#define NO_ACTION_TAPPING
+//#define NO_ACTION_ONESHOT
+//#define NO_ACTION_MACRO
+//#define NO_ACTION_FUNCTION
+
+#endif
--- /dev/null
+/*\r
+ ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+\r
+/**\r
+ * @file templates/halconf.h\r
+ * @brief HAL configuration header.\r
+ * @details HAL configuration file, this file allows to enable or disable the\r
+ * various device drivers from your application. You may also use\r
+ * this file in order to override the device drivers default settings.\r
+ *\r
+ * @addtogroup HAL_CONF\r
+ * @{\r
+ */\r
+\r
+#ifndef _HALCONF_H_\r
+#define _HALCONF_H_\r
+\r
+#include "mcuconf.h"\r
+\r
+/**\r
+ * @brief Enables the PAL subsystem.\r
+ */\r
+#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)\r
+#define HAL_USE_PAL TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the ADC subsystem.\r
+ */\r
+#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)\r
+#define HAL_USE_ADC FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the CAN subsystem.\r
+ */\r
+#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__)\r
+#define HAL_USE_CAN FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the DAC subsystem.\r
+ */\r
+#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__)\r
+#define HAL_USE_DAC FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the EXT subsystem.\r
+ */\r
+#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)\r
+#define HAL_USE_EXT FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the GPT subsystem.\r
+ */\r
+#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)\r
+#define HAL_USE_GPT FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the I2C subsystem.\r
+ */\r
+#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__)\r
+#define HAL_USE_I2C FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the I2S subsystem.\r
+ */\r
+#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__)\r
+#define HAL_USE_I2S FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the ICU subsystem.\r
+ */\r
+#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)\r
+#define HAL_USE_ICU FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the MAC subsystem.\r
+ */\r
+#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__)\r
+#define HAL_USE_MAC FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the MMC_SPI subsystem.\r
+ */\r
+#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__)\r
+#define HAL_USE_MMC_SPI FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the PWM subsystem.\r
+ */\r
+#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)\r
+#define HAL_USE_PWM FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the RTC subsystem.\r
+ */\r
+#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__)\r
+#define HAL_USE_RTC FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the SDC subsystem.\r
+ */\r
+#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__)\r
+#define HAL_USE_SDC FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the SERIAL subsystem.\r
+ */\r
+#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)\r
+#define HAL_USE_SERIAL FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the SERIAL over USB subsystem.\r
+ */\r
+#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__)\r
+#define HAL_USE_SERIAL_USB FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the SPI subsystem.\r
+ */\r
+#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)\r
+#define HAL_USE_SPI FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the UART subsystem.\r
+ */\r
+#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)\r
+#define HAL_USE_UART FALSE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the USB subsystem.\r
+ */\r
+#if !defined(HAL_USE_USB) || defined(__DOXYGEN__)\r
+#define HAL_USE_USB TRUE\r
+#endif\r
+\r
+/**\r
+ * @brief Enables the WDG subsystem.\r
+ */\r
+#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__)\r
+#define HAL_USE_WDG FALSE\r
+#endif\r
+\r
+/*===========================================================================*/\r
+/* USB driver related settings. */\r
+/*===========================================================================*/\r
+\r
+/**\r
+ * @brief Enables synchronous APIs.\r
+ * @note Disabling this option saves both code and data space.\r
+ */\r
+#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)\r
+#define USB_USE_WAIT TRUE\r
+#endif\r
+\r
+#endif /* _HALCONF_H_ */\r
+\r
+/** @} */\r
--- /dev/null
+# Teensy LC, 3.0, 3.1, 3.2 support
+
+These ARM Teensies are now supported through [ChibiOS](http://chibios.org).
+
+Follow the setup instructions in `tmk_core/protocol/chibios/README.md` to install ChibiOS and required toolchain.
+
+Running `make` in `keyboard/teensy_lc_onekey` should create a working firmware in `build/`, called `ch.hex`.
+
+For more notes about the ChibiOS backend in TMK, see `tmk_core/protocol/chibios/README.md`.
+
+## About this onekey example
+
+It'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`.
+
+## Credits
+
+TMK itself is written by hasu, original sources [here](https://github.com/tmk/tmk_keyboard).
+
+The 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.
+
+## Features that are not implemented yet
+
+Currently only the more fancy suspend features are not there (power saving during suspend). The rest should work fine (reports either way are welcome).
+
+# Matrix programming notes
+
+The notes below explain what commands can be used to examine and set the status of Teensy pins.
+
+## ChibiOS pin manipulation basics
+
+### Pins
+
+Each pin sits on a "port", each of which comprises at most 32 individual pins.
+So 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.
+
+Within 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.
+
+### Mode
+
+A MCU pin can be in several modes. The basic command to set a pin mode is
+
+ palSetPadMode(TEENSY_PINn_IOPORT, TEENSY_PINn, PAL_MODE_INPUT_PULLUP);
+
+The 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).
+
+### Setting
+
+Pins are set HIGH (after they've been put into `OUTPUT_PUSHPULL` mode) by
+
+ palSetPad(TEENSY_PINn_IOPORT, TEENSY_PINn);
+
+or set LOW by
+
+ palClearPad(TEENSY_PINn_IOPORT, TEENSY_PINn);
+
+Toggling can be done with
+
+ palTogglePad(TEENSY_PINn_IOPORT, TEENSY_PINn);
+
+Alternatively, you can use
+
+ palWritePad(TEENSY_PINn_IOPORT, TEENSY_PINn, bit);
+
+where `bit` is either `PAL_LOW` or `PAL_HIGH` (i.e. `0` or `1`).
+
+### Reading
+
+Reading pin status is done with
+
+ palReadPad(TEENSY_PINn_IOPORT, TEENSY_PINn);
+
+The function returns either `PAL_HIGH` (actually `1`) or `PAL_LOW` (actually `0`).
+
+### Further docs
+
+All 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).
--- /dev/null
+/*
+Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "keycode.h"
+#include "action.h"
+#include "action_macro.h"
+#include "report.h"
+#include "host.h"
+#include "print.h"
+#include "debug.h"
+#include "keymap.h"
+
+static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
+ [0] = {
+ {KC_ESC, KC_CLR, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_CLR, KC_F9, KC_F10, KC_F11, KC_F12, KC_CLR, KC_CLR},
+ {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_CLR, KC_CLR, KC_CLR},
+ {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLASH, KC_PSCR, KC_HOME, KC_PGUP},
+ {KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_CLR, KC_ENTER, KC_DEL, KC_END, KC_PGDN},
+ {KC_LSFT, KC_CLR, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLASH, KC_CLR, KC_RSFT, KC_CLR, KC_UP, KC_CLR},
+ {KC_LCTL, KC_LGUI, KC_LALT, KC_CLR, KC_CLR, KC_CLR, KC_SPC, KC_CLR, KC_CLR, KC_CLR, KC_RALT, KC_RGUI, KC_RCTL, KC_CLR, KC_LEFT, KC_DOWN, KC_RIGHT}
+ }
+};
+
+static const action_t fn_actions[] = {
+};
+
+/* translates key to keycode */
+uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
+{
+ return keymaps[(layer)][(key.row)][(key.col)];
+}
+
+/* translates Fn keycode to action */
+action_t keymap_fn_to_action(uint8_t keycode)
+{
+ return fn_actions[FN_INDEX(keycode)];
+}
--- /dev/null
+/*\r
+ * Copyright (C) 2013-2016 Fabio Utzig, http://fabioutzig.com\r
+ * (C) 2016 flabbergast <s3+flabbergast@sdfeu.org>\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining\r
+ * a copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * KL26Z64 memory setup.\r
+ */\r
+MEMORY\r
+{\r
+ flash0 : org = 0x00000000, len = 0x100\r
+ flash1 : org = 0x00000400, len = 0x10\r
+ flash2 : org = 0x00000410, len = 62k - 0x410\r
+ flash3 : org = 0x0000F800, len = 2k\r
+ flash4 : org = 0x00000000, len = 0\r
+ flash5 : org = 0x00000000, len = 0\r
+ flash6 : org = 0x00000000, len = 0\r
+ flash7 : org = 0x00000000, len = 0\r
+ ram0 : org = 0x1FFFF800, len = 8k\r
+ ram1 : org = 0x00000000, len = 0\r
+ ram2 : org = 0x00000000, len = 0\r
+ ram3 : org = 0x00000000, len = 0\r
+ ram4 : org = 0x00000000, len = 0\r
+ ram5 : org = 0x00000000, len = 0\r
+ ram6 : org = 0x00000000, len = 0\r
+ ram7 : org = 0x00000000, len = 0\r
+}\r
+\r
+/* Flash region for the configuration bytes.*/\r
+SECTIONS\r
+{\r
+ .cfmprotect : ALIGN(4) SUBALIGN(4)\r
+ {\r
+ KEEP(*(.cfmconfig))\r
+ } > flash1\r
+}\r
+\r
+/* For each data/text section two region are defined, a virtual region\r
+ and a load region (_LMA suffix).*/\r
+\r
+/* Flash region to be used for exception vectors.*/\r
+REGION_ALIAS("VECTORS_FLASH", flash0);\r
+REGION_ALIAS("VECTORS_FLASH_LMA", flash0);\r
+\r
+/* Flash region to be used for constructors and destructors.*/\r
+REGION_ALIAS("XTORS_FLASH", flash2);\r
+REGION_ALIAS("XTORS_FLASH_LMA", flash2);\r
+\r
+/* Flash region to be used for code text.*/\r
+REGION_ALIAS("TEXT_FLASH", flash2);\r
+REGION_ALIAS("TEXT_FLASH_LMA", flash2);\r
+\r
+/* Flash region to be used for read only data.*/\r
+REGION_ALIAS("RODATA_FLASH", flash2);\r
+REGION_ALIAS("RODATA_FLASH_LMA", flash2);\r
+\r
+/* Flash region to be used for various.*/\r
+REGION_ALIAS("VARIOUS_FLASH", flash2);\r
+REGION_ALIAS("VARIOUS_FLASH_LMA", flash2);\r
+\r
+/* Flash region to be used for RAM(n) initialization data.*/\r
+REGION_ALIAS("RAM_INIT_FLASH_LMA", flash2);\r
+\r
+/* RAM region to be used for Main stack. This stack accommodates the processing\r
+ of all exceptions and interrupts.*/\r
+REGION_ALIAS("MAIN_STACK_RAM", ram0);\r
+\r
+/* RAM region to be used for the process stack. This is the stack used by\r
+ the main() function.*/\r
+REGION_ALIAS("PROCESS_STACK_RAM", ram0);\r
+\r
+/* RAM region to be used for data segment.*/\r
+REGION_ALIAS("DATA_RAM", ram0);\r
+REGION_ALIAS("DATA_RAM_LMA", flash2);\r
+\r
+/* RAM region to be used for BSS segment.*/\r
+REGION_ALIAS("BSS_RAM", ram0);\r
+\r
+/* RAM region to be used for the default heap.*/\r
+REGION_ALIAS("HEAP_RAM", ram0);\r
+\r
+__eeprom_workarea_start__ = ORIGIN(flash3);\r
+__eeprom_workarea_size__ = LENGTH(flash3);\r
+__eeprom_workarea_end__ = __eeprom_workarea_start__ + __eeprom_workarea_size__;\r
+\r
+/* Generic rules inclusion.*/\r
+INCLUDE rules.ld\r
--- /dev/null
+/*
+Copyright 2012 Jun Wako <wakojun@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "hal.h"
+
+#include "led.h"
+
+
+void led_set(uint8_t usb_led) {
+ if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
+ // output high
+ palSetPadMode(TEENSY_PIN13_IOPORT, TEENSY_PIN13, PAL_MODE_OUTPUT_PUSHPULL);
+ palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
+ } else {
+ // Hi-Z
+ palSetPadMode(TEENSY_PIN13_IOPORT, TEENSY_PIN13, PAL_MODE_INPUT);
+ }
+}
--- /dev/null
+/*
+Copyright 2012 Jun Wako <wakojun@gmail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "ch.h"
+#include "hal.h"
+
+/*
+ * scan matrix
+ */
+#include "print.h"
+#include "debug.h"
+#include "util.h"
+#include "matrix.h"
+#include "wait.h"
+
+#ifndef DEBOUNCE
+# define DEBOUNCE 5
+#endif
+static uint8_t debouncing = DEBOUNCE;
+
+/* matrix state(1:on, 0:off) */
+static matrix_row_t matrix[MATRIX_ROWS];
+static matrix_row_t matrix_debouncing[MATRIX_ROWS];
+
+static matrix_row_t read_cols(void);
+static void init_cols(void);
+static void unselect_rows(void);
+static void select_row(uint8_t row);
+
+
+inline
+uint8_t matrix_rows(void)
+{
+ return MATRIX_ROWS;
+}
+
+inline
+uint8_t matrix_cols(void)
+{
+ return MATRIX_COLS;
+}
+
+#define LED_ON() do { palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13) ;} while (0)
+#define LED_OFF() do { palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); } while (0)
+#define LED_TGL() do { palTogglePad(TEENSY_PIN13_IOPORT, TEENSY_PIN13); } while (0)
+
+void matrix_init(void)
+{
+ // initialize row and col
+ unselect_rows();
+ init_cols();
+
+ // initialize matrix state: all keys off
+ for (uint8_t i=0; i < MATRIX_ROWS; i++) {
+ matrix[i] = 0;
+ matrix_debouncing[i] = 0;
+ }
+
+ //debug
+ debug_matrix = true;
+ LED_ON();
+ wait_ms(500);
+ LED_OFF();
+}
+
+uint8_t matrix_scan(void)
+{
+ for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+ select_row(i);
+ wait_us(30); // without this wait read unstable value.
+ matrix_row_t cols = read_cols();
+ if (matrix_debouncing[i] != cols) {
+ matrix_debouncing[i] = cols;
+ if (debouncing) {
+ debug("bounce!: "); debug_hex(debouncing); debug("\n");
+ }
+ debouncing = DEBOUNCE;
+ }
+ unselect_rows();
+ }
+
+ if (debouncing) {
+ if (--debouncing) {
+ wait_ms(1);
+ } else {
+ for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+ matrix[i] = matrix_debouncing[i];
+ }
+ }
+ }
+
+ return 1;
+}
+
+inline
+bool matrix_is_on(uint8_t row, uint8_t col)
+{
+ return (matrix[row] & ((matrix_row_t)1<<col));
+}
+
+inline
+matrix_row_t matrix_get_row(uint8_t row)
+{
+ return matrix[row];
+}
+
+void matrix_print(void)
+{
+ print("\nr/c 0123456789ABCDEF\n");
+ for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
+ phex(row); print(": ");
+ pbin_reverse16(matrix_get_row(row));
+ print("\n");
+ }
+}
+
+/* Column pin configuration
+ */
+static void init_cols(void)
+{
+ // internal pull-up
+ palSetPadMode(TEENSY_PIN6_IOPORT , TEENSY_PIN6, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN7_IOPORT , TEENSY_PIN7, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN8_IOPORT , TEENSY_PIN8, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN9_IOPORT , TEENSY_PIN9, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN10_IOPORT, TEENSY_PIN10, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN11_IOPORT, TEENSY_PIN11, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN12_IOPORT, TEENSY_PIN12, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN14_IOPORT, TEENSY_PIN14, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN15_IOPORT, TEENSY_PIN15, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN16_IOPORT, TEENSY_PIN16, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN17_IOPORT, TEENSY_PIN17, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN18_IOPORT, TEENSY_PIN18, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN19_IOPORT, TEENSY_PIN19, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN20_IOPORT, TEENSY_PIN20, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN21_IOPORT, TEENSY_PIN21, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN22_IOPORT, TEENSY_PIN22, PAL_MODE_INPUT_PULLUP);
+ palSetPadMode(TEENSY_PIN23_IOPORT, TEENSY_PIN23, PAL_MODE_INPUT_PULLUP);
+}
+
+/* Returns status of switches(1:on, 0:off) */
+static matrix_row_t read_cols(void)
+{
+ return (
+ ((palReadPad(TEENSY_PIN6_IOPORT , TEENSY_PIN6 )==PAL_HIGH) ? 0 : (1<<0))
+ | ((palReadPad(TEENSY_PIN7_IOPORT , TEENSY_PIN7 )==PAL_HIGH) ? 0 : (1<<1))
+ | ((palReadPad(TEENSY_PIN8_IOPORT , TEENSY_PIN8 )==PAL_HIGH) ? 0 : (1<<2))
+ | ((palReadPad(TEENSY_PIN9_IOPORT , TEENSY_PIN9 )==PAL_HIGH) ? 0 : (1<<3))
+ | ((palReadPad(TEENSY_PIN10_IOPORT, TEENSY_PIN10)==PAL_HIGH) ? 0 : (1<<4))
+ | ((palReadPad(TEENSY_PIN11_IOPORT, TEENSY_PIN11)==PAL_HIGH) ? 0 : (1<<5))
+ | ((palReadPad(TEENSY_PIN12_IOPORT, TEENSY_PIN12)==PAL_HIGH) ? 0 : (1<<6))
+ | ((palReadPad(TEENSY_PIN14_IOPORT, TEENSY_PIN14)==PAL_HIGH) ? 0 : (1<<7))
+ | ((palReadPad(TEENSY_PIN15_IOPORT, TEENSY_PIN15)==PAL_HIGH) ? 0 : (1<<8))
+ | ((palReadPad(TEENSY_PIN16_IOPORT, TEENSY_PIN16)==PAL_HIGH) ? 0 : (1<<9))
+ | ((palReadPad(TEENSY_PIN17_IOPORT, TEENSY_PIN17)==PAL_HIGH) ? 0 : (1<<10))
+ | ((palReadPad(TEENSY_PIN18_IOPORT, TEENSY_PIN18)==PAL_HIGH) ? 0 : (1<<11))
+ | ((palReadPad(TEENSY_PIN19_IOPORT, TEENSY_PIN19)==PAL_HIGH) ? 0 : (1<<12))
+ | ((palReadPad(TEENSY_PIN20_IOPORT, TEENSY_PIN20)==PAL_HIGH) ? 0 : (1<<13))
+ | ((palReadPad(TEENSY_PIN21_IOPORT, TEENSY_PIN21)==PAL_HIGH) ? 0 : (1<<14))
+ | ((palReadPad(TEENSY_PIN22_IOPORT, TEENSY_PIN22)==PAL_HIGH) ? 0 : (1<<15))
+ | ((palReadPad(TEENSY_PIN23_IOPORT, TEENSY_PIN23)==PAL_HIGH) ? 0 : (1<<16))
+ );
+}
+
+/* Row pin configuration
+ */
+static void unselect_rows(void)
+{
+ palSetPadMode(TEENSY_PIN5_IOPORT, TEENSY_PIN5, PAL_MODE_INPUT);
+ palSetPadMode(TEENSY_PIN4_IOPORT, TEENSY_PIN4, PAL_MODE_INPUT);
+ palSetPadMode(TEENSY_PIN3_IOPORT, TEENSY_PIN3, PAL_MODE_INPUT);
+ palSetPadMode(TEENSY_PIN2_IOPORT, TEENSY_PIN2, PAL_MODE_INPUT);
+ palSetPadMode(TEENSY_PIN1_IOPORT, TEENSY_PIN1, PAL_MODE_INPUT);
+ palSetPadMode(TEENSY_PIN0_IOPORT, TEENSY_PIN0, PAL_MODE_INPUT);
+}
+
+static void select_row(uint8_t row)
+{
+ (void)row;
+ // Output low to select
+ switch (row) {
+ case 0:
+ palSetPadMode(TEENSY_PIN5_IOPORT, TEENSY_PIN5, PAL_MODE_OUTPUT_PUSHPULL);
+ palClearPad(TEENSY_PIN5_IOPORT, TEENSY_PIN5);
+ break;
+ case 1:
+ palSetPadMode(TEENSY_PIN4_IOPORT, TEENSY_PIN4, PAL_MODE_OUTPUT_PUSHPULL);
+ palClearPad(TEENSY_PIN4_IOPORT, TEENSY_PIN4);
+ break;
+ case 2:
+ palSetPadMode(TEENSY_PIN3_IOPORT, TEENSY_PIN3, PAL_MODE_OUTPUT_PUSHPULL);
+ palClearPad(TEENSY_PIN3_IOPORT, TEENSY_PIN3);
+ break;
+ case 3:
+ palSetPadMode(TEENSY_PIN2_IOPORT, TEENSY_PIN2, PAL_MODE_OUTPUT_PUSHPULL);
+ palClearPad(TEENSY_PIN2_IOPORT, TEENSY_PIN2);
+ break;
+ case 4:
+ palSetPadMode(TEENSY_PIN1_IOPORT, TEENSY_PIN1, PAL_MODE_OUTPUT_PUSHPULL);
+ palClearPad(TEENSY_PIN1_IOPORT, TEENSY_PIN1);
+ break;
+ case 5:
+ palSetPadMode(TEENSY_PIN0_IOPORT, TEENSY_PIN0, PAL_MODE_OUTPUT_PUSHPULL);
+ palClearPad(TEENSY_PIN0_IOPORT, TEENSY_PIN0);
+ break;
+ }
+}
--- /dev/null
+/*\r
+ ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+*/\r
+\r
+#ifndef _MCUCONF_H_\r
+#define _MCUCONF_H_\r
+\r
+#define KL2x_MCUCONF\r
+\r
+/*\r
+ * HAL driver system settings.\r
+ */\r
+#if 1\r
+/* PEE mode - 48MHz system clock driven by (16 MHz) external crystal. */\r
+#define KINETIS_MCG_MODE KINETIS_MCG_MODE_PEE\r
+#define KINETIS_PLLCLK_FREQUENCY 96000000UL\r
+#define KINETIS_SYSCLK_FREQUENCY 48000000UL\r
+#endif\r
+\r
+#if 0\r
+/* crystal-less FEI mode - 48 MHz with internal 32.768 kHz crystal */\r
+#define KINETIS_MCG_MODE KINETIS_MCG_MODE_FEI\r
+#define KINETIS_MCG_FLL_DMX32 1 /* Fine-tune for 32.768 kHz */\r
+#define KINETIS_MCG_FLL_DRS 1 /* 1464x FLL factor */\r
+#define KINETIS_SYSCLK_FREQUENCY 47972352UL /* 32.768 kHz * 1464 (~48 MHz) */\r
+#define KINETIS_CLKDIV1_OUTDIV1 1 /* do not divide system clock */\r
+#endif\r
+\r
+/*\r
+ * SERIAL driver system settings.\r
+ */\r
+#define KINETIS_SERIAL_USE_UART0 TRUE\r
+\r
+/*\r
+ * USB driver settings\r
+ */\r
+#define KINETIS_USB_USE_USB0 TRUE\r
+/* Need to redefine this, since the default is for K20x */\r
+/* This is for Teensy LC; you should comment it out (or change to 5)\r
+ * for Teensy 3.x */\r
+#define KINETIS_USB_USB0_IRQ_PRIORITY 5\r
+\r
+#endif /* _MCUCONF_H_ */\r