# Target file name (without extension). | |||||
PROJECT = kl27z_kbd | |||||
# Directory common source files exist | |||||
TMK_DIR = ../../tmk_core | |||||
# Directory keyboard dependent files exist | |||||
TARGET_DIR = . | |||||
# project specific files | |||||
SRC = $(PROJECT).c | |||||
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 = MKL27Z256 | |||||
# 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 = ELF | |||||
# 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 |
COL | |||||
--- | |||||
Anode side, senses keys with internal pull-up. | |||||
Left to right: | |||||
PTD6 | |||||
PTD5 | |||||
PTD4 | |||||
PTD3 | |||||
PTA19 | |||||
PTA18 | |||||
PTA4 NMI | |||||
PTA2 | |||||
PTA1 | |||||
PTE25 | |||||
PTE24 | |||||
PTE30 | |||||
PTE29 | |||||
PTE21 | |||||
ROW | |||||
---- | |||||
Cathod side, given strobe with output low. | |||||
Top to bottom: | |||||
PTB3 | |||||
PTB16 | |||||
PTB17 | |||||
PTC0 | |||||
PTC1 |
KL27Z128/256 board | |||||
================== | |||||
2016/11/30 | |||||
KL27Z is configured to use internal 48MHz RC oscillator. | |||||
The board has push button on PTA4 and LED on PTD7. The button works as 'a' key and the LED as an indicator for capslock. | |||||
ELF board | |||||
--------- | |||||
This board acommodates 48QFN chip. | |||||
### prototypte pinout | |||||
- pcb layout https://deskthority.net/resources/image/33293 | |||||
- schematic https://deskthority.net/resources/image/33252 | |||||
``` | |||||
G G | |||||
N 5 D D N F D D D D D D | |||||
D V - + D G \ USB / 6 5 4 3 2 1 | |||||
,--------------------- | Conn | --------------------. | |||||
|39 40 41 42 43 44 | | 1 2 3 4 5 6 | | |||||
3.3V|38 |_________| 7 |D0 | |||||
A0|37 RST 8 |C7 | |||||
A3|36 9 |C6 | |||||
+A20|35 10|C5+ | |||||
E20|34 11|C4 | |||||
E21|33 BL 12|C3 | |||||
E29|32 13|C2 | |||||
|31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14| | |||||
`-------------------------------------------------------' | |||||
E E E A A A 3 A G A C B B B B B C C | |||||
3 2 2 1 2 4 . 1 N 1 1 1 2 3 1 1 0 1 | |||||
0 4 5 + + 3V 8 D 9 6 7 | |||||
1 PTD6 12 PTC3 23 GND 34 PTE20* | |||||
2 PTD5 13 PTC2 24 PTA18 35 PTA20/Reset+ | |||||
3 PTD4 14 PTC1 25 3.3V 36 PTA3/SWD_DIO | |||||
4 PTD3* 15 PTC0* 26 PTA4/NMI+ 37 PTA0/SWD_CLK | |||||
5 PTD2* 16 PTB17* 27 PTA2 38 3.3V | |||||
6 PTD1* 17 PTB16* 28 PTA1+ 39 GND | |||||
7 PTD0* 18 PTB3* 29 PTE25* 40 VBUS/VREGIN/5V | |||||
8 PTC7 19 PTB2* 30 PTE24* 41 USB D- | |||||
9 PTC6 20 PTB1 31 PTE30 42 USB D+ | |||||
10 PTC5+ 21 PTB0 32 PTE29* 43 GND | |||||
11 PTC4 22 PTA19 33 PTE21* 44 USB Shield/FB | |||||
+: Pins with resistor or switch | |||||
*: Pins which don't exist in QFN32 | |||||
``` | |||||
TMK KL27Z breakout | |||||
------------------ | |||||
This board acommodates 48QFN chip. | |||||
### Pinputs | |||||
_\ conn /_ | |||||
1 28 | |||||
: : | |||||
: PROG : | |||||
: RST : | |||||
14 15 | |||||
---------- | |||||
1 VUSB 28 GND | |||||
2 VIN/VREGIN 27 PTD4 | |||||
3 PTD5 26 PTC7 | |||||
4 PTD6 25 PTC6 | |||||
5 PTD7 24 PTC5+ | |||||
6 PTE0* 23 PTC4 | |||||
7 3.3V 22 GND | |||||
8 PTE30 21 PTC3 | |||||
9 PTA0/SWD_CLK 20 PTC2 | |||||
10 PTA1+ 19 PTC1 | |||||
11 PTA2 18 PTB1 | |||||
12 PTA3/SWD_DIO 17 PTB0 | |||||
13 PTA4/NMI+ 16 PTA20/Reset+ | |||||
14 PTA18 15 PTA19 | |||||
*: Pin which doesn't exist in QFN48 | |||||
#### Pinouts difference between 32QFN and 48QFN | |||||
48QFN doesn't have PTE0 | |||||
32QFN doesn't have PTD0-3, PTC0, PTE20-21,24,25,29, PTB2-3,16,17 | |||||
### ROM bootloader pins | |||||
See Reference Manual Chapter 13. | |||||
PTA2 LPUART0_TX | |||||
PTA1 LPUART0_RX * | |||||
PTB0 I2C0_SCL | |||||
PTB1 I2C0_SDA | |||||
PTC4 SPI0_SS_b * | |||||
PTC7 SPI0_MISO | |||||
PTC6 SPI0_MOSI | |||||
PTC5 SPI0_SCK * | |||||
Due to errata e9457, need to pull-up `SPI0_SS_b`(or `SPI0_SCK`) to prevent false detection of SPI. | |||||
The errata doesn't refer UART though, `LPUART0_RX` also requires pull-up or down resisitor from experience. | |||||
Without resistor it easily false-detects activity on UART interface with finger touch on the pin. | |||||
Resources | |||||
--------- | |||||
### Deskthority thread | |||||
https://deskthority.net/workshop-f7/can-we-design-the-teensy-alternative-for-keyboards-t13662-510.html | |||||
### Kinetis KL2x | |||||
http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/kinetis-cortex-m-mcus/l-series-ultra-low-power-m0-plus/kinetis-kl2x-48-mhz-usb-ultra-low-power-microcontrollers-based-on-arm-cortex-m0-plus:KL2x | |||||
### KL27Z128/256 Data Sheet | |||||
http://www.nxp.com/assets/documents/data/en/data-sheets/KL27P64M48SF6.pdf | |||||
### KL27Z128/256 Reference Manual | |||||
http://www.nxp.com/assets/documents/data/en/reference-manuals/KL27P64M48SF6RM.pdf | |||||
### Errata | |||||
http://www.nxp.com/assets/documents/data/en/errata/KINETIS_L_1N71K.pdf | |||||
>> | |||||
e9457: Kinetis Flashloader/ ROM Bootloader: The peripheral auto-detect code in | |||||
bootloader can falsely detect presence of SPI host causing non-responsive | |||||
bootloader | |||||
Description: During the active peripheral detection process, the bootloader can interpret spurious data on | |||||
the SPI peripheral as valid data. The spurious data causes the bootloader to shutdown all | |||||
peripherals except the “falsely detected" SPI and enter the command phase loop using the | |||||
SPI. After the bootloader enters the command phase loop using the SPI, the other peripherals | |||||
are ignored, so the desired peripheral is no longer active. | |||||
The bootloader will not falsely detect activity on the I2C, UART, or USB interfaces, so only the | |||||
SPI interface is affected. | |||||
Workaround: Ensure that there is an external pull-up on the SPI chip-select pin or that the pin is driven high. | |||||
This will prevent the bootloader from seeing spurious data due to activity on the SPI clock pin. | |||||
### Kinetis Bootloader and blhost | |||||
http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/kinetis-cortex-m-mcus/kinetis-symbols-footprints-and-models/kinetis-bootloader:KBOOT | |||||
Build | |||||
----- | |||||
make | |||||
Program | |||||
------- | |||||
Flash firmware with ROM bootloader. | |||||
blhost -u -- flash-image build/kl27z.hex erase | |||||
TODO | |||||
---- | |||||
- Fix boards/ELF files | |||||
- add macro `USBx_CTL_RESUME` to ChibiOS-Contrib/os/common/ext/CMSIS/KINETIS/kl27zxxx.h |
/* | |||||
ChibiOS - (C) 2015-2016 flabbergast <[email protected]> | |||||
Licensed under the Apache License, Version 2.0 (the "License"); | |||||
you may not use this file except in compliance with the License. | |||||
You may obtain a copy of the License at | |||||
http://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. | |||||
*/ | |||||
#include "ch.h" | |||||
#include "hal.h" | |||||
#if HAL_USE_PAL || defined(__DOXYGEN__) | |||||
/** | |||||
* @brief PAL setup. | |||||
* @details Digital I/O ports static configuration as defined in @p board.h. | |||||
* This variable is used by the HAL when initializing the PAL driver. | |||||
*/ | |||||
const PALConfig pal_default_config = | |||||
{ | |||||
.ports = { | |||||
{ | |||||
/* | |||||
* PORTA setup. | |||||
* | |||||
* on pads: PTA1, PTA2, PTA5, PTA18, PTA19 | |||||
* | |||||
* PTA0/3 SWD (default SWD, ALT_7: SWD, ALT_1: PTA0/3) | |||||
* PTA4 NMI button (default NMI_b, ALT_1: PTA4) | |||||
* PTA20 RESET button (default RESET, ALT_7: RESET, ALT_1: PTA20) | |||||
*/ | |||||
.port = IOPORT1, | |||||
.pads = { | |||||
PAL_MODE_ALTERNATIVE_7, PAL_MODE_INPUT_PULLUP, PAL_MODE_OUTPUT_PUSHPULL, | |||||
PAL_MODE_ALTERNATIVE_7, PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_INPUT_ANALOG, PAL_MODE_INPUT_ANALOG, PAL_MODE_ALTERNATIVE_7, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
}, | |||||
}, | |||||
{ | |||||
/* | |||||
* PORTB setup. | |||||
* | |||||
* on pads: PTB0, PTB1 | |||||
* LED: PTB18 | |||||
*/ | |||||
.port = IOPORT2, | |||||
.pads = { | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
}, | |||||
}, | |||||
{ | |||||
/* | |||||
* PORTC setup. | |||||
* | |||||
* on pads: PTC1, PTC2, PTC3, PTC6, PTC7, PTC8, PTC9 | |||||
*/ | |||||
.port = IOPORT3, | |||||
.pads = { | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
}, | |||||
}, | |||||
{ | |||||
/* | |||||
* PORTD setup. | |||||
* | |||||
* on pads: PTD0 - PTD7 | |||||
*/ | |||||
.port = IOPORT4, | |||||
.pads = { | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_OUTPUT_PUSHPULL, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
}, | |||||
}, | |||||
{ | |||||
/* | |||||
* PORTE setup. | |||||
* | |||||
* on pads: PTE0, PTE1, PTE24, PTE25, PTE29, PTE30 | |||||
*/ | |||||
.port = IOPORT5, | |||||
.pads = { | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_OUTPUT_PUSHPULL, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_INPUT_PULLUP, PAL_MODE_UNCONNECTED, | |||||
PAL_MODE_UNCONNECTED, PAL_MODE_UNCONNECTED, PAL_MODE_INPUT_PULLUP, | |||||
PAL_MODE_INPUT_PULLUP, PAL_MODE_UNCONNECTED, | |||||
}, | |||||
}, | |||||
}, | |||||
}; | |||||
#endif | |||||
/** | |||||
* @brief Early initialization code. | |||||
* @details This initialization must be performed just after stack setup | |||||
* and before any other initialization. | |||||
*/ | |||||
void __early_init(void) { | |||||
kl2x_clock_init(); | |||||
} | |||||
/** | |||||
* @brief Board-specific initialization code. | |||||
* @todo Add your board-specific code, if any. | |||||
*/ | |||||
void boardInit(void) { | |||||
} |
/* | |||||
ChibiOS - (C) 2015-2016 flabbergast <[email protected]> | |||||
Licensed under the Apache License, Version 2.0 (the "License"); | |||||
you may not use this file except in compliance with the License. | |||||
You may obtain a copy of the License at | |||||
http://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. | |||||
*/ | |||||
#ifndef _BOARD_H_ | |||||
#define _BOARD_H_ | |||||
/* | |||||
* Setup for a custom KL27Z breakout board. | |||||
*/ | |||||
/* | |||||
* Board identifier. | |||||
*/ | |||||
#define BOARD_KL27Z_BREAKOUT | |||||
#define BOARD_NAME "Custom KL27Z breakout" | |||||
/* | |||||
* MCU type | |||||
*/ | |||||
#define KL27Zxxx | |||||
/* | |||||
* Onboard features. | |||||
*/ | |||||
//#define GPIO_LED IOPORT1 | |||||
//#define PIN_LED 2 | |||||
// PTD7 on ELF | |||||
#define GPIO_LED IOPORT4 | |||||
#define PIN_LED 7 | |||||
#define GPIO_BUTTON IOPORT1 | |||||
#define PIN_BUTTON 4 | |||||
#if !defined(_FROM_ASM_) | |||||
#ifdef __cplusplus | |||||
extern "C" { | |||||
#endif | |||||
void boardInit(void); | |||||
#ifdef __cplusplus | |||||
} | |||||
#endif | |||||
#endif /* _FROM_ASM_ */ | |||||
#endif /* _BOARD_H_ */ |
# List of all the board related files. | |||||
BOARDSRC = ./boards/ELF/board.c | |||||
# Required include directories | |||||
BOARDINC = ./boards/ELF |
/* | |||||
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio | |||||
Licensed under the Apache License, Version 2.0 (the "License"); | |||||
you may not use this file except in compliance with the License. | |||||
You may obtain a copy of the License at | |||||
http://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. | |||||
*/ | |||||
/** | |||||
* @file templates/chconf.h | |||||
* @brief Configuration file template. | |||||
* @details A copy of this file must be placed in each project directory, it | |||||
* contains the application specific kernel settings. | |||||
* | |||||
* @addtogroup config | |||||
* @details Kernel related settings and hooks. | |||||
* @{ | |||||
*/ | |||||
#ifndef CHCONF_H | |||||
#define CHCONF_H | |||||
#define _CHIBIOS_RT_CONF_ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @name System timers settings | |||||
* @{ | |||||
*/ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @brief System time counter resolution. | |||||
* @note Allowed values are 16 or 32 bits. | |||||
*/ | |||||
#define CH_CFG_ST_RESOLUTION 32 | |||||
/** | |||||
* @brief System tick frequency. | |||||
* @details Frequency of the system timer that drives the system ticks. This | |||||
* setting also defines the system tick time unit. | |||||
*/ | |||||
#define CH_CFG_ST_FREQUENCY 1000 | |||||
/** | |||||
* @brief Time delta constant for the tick-less mode. | |||||
* @note If this value is zero then the system uses the classic | |||||
* periodic tick. This value represents the minimum number | |||||
* of ticks that is safe to specify in a timeout directive. | |||||
* The value one is not valid, timeouts are rounded up to | |||||
* this value. | |||||
*/ | |||||
#define CH_CFG_ST_TIMEDELTA 0 | |||||
/** @} */ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @name Kernel parameters and options | |||||
* @{ | |||||
*/ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @brief Round robin interval. | |||||
* @details This constant is the number of system ticks allowed for the | |||||
* threads before preemption occurs. Setting this value to zero | |||||
* disables the preemption for threads with equal priority and the | |||||
* round robin becomes cooperative. Note that higher priority | |||||
* threads can still preempt, the kernel is always preemptive. | |||||
* @note Disabling the round robin preemption makes the kernel more compact | |||||
* and generally faster. | |||||
* @note The round robin preemption is not supported in tickless mode and | |||||
* must be set to zero in that case. | |||||
*/ | |||||
#define CH_CFG_TIME_QUANTUM 20 | |||||
/** | |||||
* @brief Managed RAM size. | |||||
* @details Size of the RAM area to be managed by the OS. If set to zero | |||||
* then the whole available RAM is used. The core memory is made | |||||
* available to the heap allocator and/or can be used directly through | |||||
* the simplified core memory allocator. | |||||
* | |||||
* @note In order to let the OS manage the whole RAM the linker script must | |||||
* provide the @p __heap_base__ and @p __heap_end__ symbols. | |||||
* @note Requires @p CH_CFG_USE_MEMCORE. | |||||
*/ | |||||
#define CH_CFG_MEMCORE_SIZE 0 | |||||
/** | |||||
* @brief Idle thread automatic spawn suppression. | |||||
* @details When this option is activated the function @p chSysInit() | |||||
* does not spawn the idle thread. The application @p main() | |||||
* function becomes the idle thread and must implement an | |||||
* infinite loop. | |||||
*/ | |||||
#define CH_CFG_NO_IDLE_THREAD FALSE | |||||
/* Use __WFI in the idle thread for waiting. Does lower the power | |||||
* consumption. */ | |||||
#define CORTEX_ENABLE_WFI_IDLE TRUE | |||||
/** @} */ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @name Performance options | |||||
* @{ | |||||
*/ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @brief OS optimization. | |||||
* @details If enabled then time efficient rather than space efficient code | |||||
* is used when two possible implementations exist. | |||||
* | |||||
* @note This is not related to the compiler optimization options. | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_OPTIMIZE_SPEED TRUE | |||||
/** @} */ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @name Subsystem options | |||||
* @{ | |||||
*/ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @brief Time Measurement APIs. | |||||
* @details If enabled then the time measurement APIs are included in | |||||
* the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_TM FALSE | |||||
/** | |||||
* @brief Threads registry APIs. | |||||
* @details If enabled then the registry APIs are included in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_REGISTRY TRUE | |||||
/** | |||||
* @brief Threads synchronization APIs. | |||||
* @details If enabled then the @p chThdWait() function is included in | |||||
* the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_WAITEXIT TRUE | |||||
/** | |||||
* @brief Semaphores APIs. | |||||
* @details If enabled then the Semaphores APIs are included in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_SEMAPHORES TRUE | |||||
/** | |||||
* @brief Semaphores queuing mode. | |||||
* @details If enabled then the threads are enqueued on semaphores by | |||||
* priority rather than in FIFO order. | |||||
* | |||||
* @note The default is @p FALSE. Enable this if you have special | |||||
* requirements. | |||||
* @note Requires @p CH_CFG_USE_SEMAPHORES. | |||||
*/ | |||||
#define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE | |||||
/** | |||||
* @brief Mutexes APIs. | |||||
* @details If enabled then the mutexes APIs are included in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_MUTEXES TRUE | |||||
/** | |||||
* @brief Enables recursive behavior on mutexes. | |||||
* @note Recursive mutexes are heavier and have an increased | |||||
* memory footprint. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
* @note Requires @p CH_CFG_USE_MUTEXES. | |||||
*/ | |||||
#define CH_CFG_USE_MUTEXES_RECURSIVE FALSE | |||||
/** | |||||
* @brief Conditional Variables APIs. | |||||
* @details If enabled then the conditional variables APIs are included | |||||
* in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
* @note Requires @p CH_CFG_USE_MUTEXES. | |||||
*/ | |||||
#define CH_CFG_USE_CONDVARS TRUE | |||||
/** | |||||
* @brief Conditional Variables APIs with timeout. | |||||
* @details If enabled then the conditional variables APIs with timeout | |||||
* specification are included in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
* @note Requires @p CH_CFG_USE_CONDVARS. | |||||
*/ | |||||
#define CH_CFG_USE_CONDVARS_TIMEOUT TRUE | |||||
/** | |||||
* @brief Events Flags APIs. | |||||
* @details If enabled then the event flags APIs are included in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_EVENTS TRUE | |||||
/** | |||||
* @brief Events Flags APIs with timeout. | |||||
* @details If enabled then the events APIs with timeout specification | |||||
* are included in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
* @note Requires @p CH_CFG_USE_EVENTS. | |||||
*/ | |||||
#define CH_CFG_USE_EVENTS_TIMEOUT TRUE | |||||
/** | |||||
* @brief Synchronous Messages APIs. | |||||
* @details If enabled then the synchronous messages APIs are included | |||||
* in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_MESSAGES TRUE | |||||
/** | |||||
* @brief Synchronous Messages queuing mode. | |||||
* @details If enabled then messages are served by priority rather than in | |||||
* FIFO order. | |||||
* | |||||
* @note The default is @p FALSE. Enable this if you have special | |||||
* requirements. | |||||
* @note Requires @p CH_CFG_USE_MESSAGES. | |||||
*/ | |||||
#define CH_CFG_USE_MESSAGES_PRIORITY FALSE | |||||
/** | |||||
* @brief Mailboxes APIs. | |||||
* @details If enabled then the asynchronous messages (mailboxes) APIs are | |||||
* included in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
* @note Requires @p CH_CFG_USE_SEMAPHORES. | |||||
*/ | |||||
#define CH_CFG_USE_MAILBOXES TRUE | |||||
/** | |||||
* @brief Core Memory Manager APIs. | |||||
* @details If enabled then the core memory manager APIs are included | |||||
* in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_MEMCORE TRUE | |||||
/** | |||||
* @brief Heap Allocator APIs. | |||||
* @details If enabled then the memory heap allocator APIs are included | |||||
* in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
* @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or | |||||
* @p CH_CFG_USE_SEMAPHORES. | |||||
* @note Mutexes are recommended. | |||||
*/ | |||||
#define CH_CFG_USE_HEAP TRUE | |||||
/** | |||||
* @brief Memory Pools Allocator APIs. | |||||
* @details If enabled then the memory pools allocator APIs are included | |||||
* in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
*/ | |||||
#define CH_CFG_USE_MEMPOOLS TRUE | |||||
/** | |||||
* @brief Dynamic Threads APIs. | |||||
* @details If enabled then the dynamic threads creation APIs are included | |||||
* in the kernel. | |||||
* | |||||
* @note The default is @p TRUE. | |||||
* @note Requires @p CH_CFG_USE_WAITEXIT. | |||||
* @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS. | |||||
*/ | |||||
#define CH_CFG_USE_DYNAMIC TRUE | |||||
/** @} */ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @name Debug options | |||||
* @{ | |||||
*/ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @brief Debug option, kernel statistics. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
*/ | |||||
#define CH_DBG_STATISTICS FALSE | |||||
/** | |||||
* @brief Debug option, system state check. | |||||
* @details If enabled the correct call protocol for system APIs is checked | |||||
* at runtime. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
*/ | |||||
#define CH_DBG_SYSTEM_STATE_CHECK TRUE | |||||
/** | |||||
* @brief Debug option, parameters checks. | |||||
* @details If enabled then the checks on the API functions input | |||||
* parameters are activated. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
*/ | |||||
#define CH_DBG_ENABLE_CHECKS TRUE | |||||
/** | |||||
* @brief Debug option, consistency checks. | |||||
* @details If enabled then all the assertions in the kernel code are | |||||
* activated. This includes consistency checks inside the kernel, | |||||
* runtime anomalies and port-defined checks. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
*/ | |||||
#define CH_DBG_ENABLE_ASSERTS TRUE | |||||
/** | |||||
* @brief Debug option, trace buffer. | |||||
* @details If enabled then the trace buffer is activated. | |||||
* | |||||
* @note The default is @p CH_DBG_TRACE_MASK_DISABLED. | |||||
*/ | |||||
#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED | |||||
/** | |||||
* @brief Trace buffer entries. | |||||
* @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is | |||||
* different from @p CH_DBG_TRACE_MASK_DISABLED. | |||||
*/ | |||||
#define CH_DBG_TRACE_BUFFER_SIZE 128 | |||||
/** | |||||
* @brief Debug option, stack checks. | |||||
* @details If enabled then a runtime stack check is performed. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
* @note The stack check is performed in a architecture/port dependent way. | |||||
* It may not be implemented or some ports. | |||||
* @note The default failure mode is to halt the system with the global | |||||
* @p panic_msg variable set to @p NULL. | |||||
*/ | |||||
#define CH_DBG_ENABLE_STACK_CHECK TRUE | |||||
/** | |||||
* @brief Debug option, stacks initialization. | |||||
* @details If enabled then the threads working area is filled with a byte | |||||
* value when a thread is created. This can be useful for the | |||||
* runtime measurement of the used stack. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
*/ | |||||
#define CH_DBG_FILL_THREADS TRUE | |||||
/** | |||||
* @brief Debug option, threads profiling. | |||||
* @details If enabled then a field is added to the @p thread_t structure that | |||||
* counts the system ticks occurred while executing the thread. | |||||
* | |||||
* @note The default is @p FALSE. | |||||
* @note This debug option is not currently compatible with the | |||||
* tickless mode. | |||||
*/ | |||||
#define CH_DBG_THREADS_PROFILING FALSE | |||||
/** @} */ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @name Kernel hooks | |||||
* @{ | |||||
*/ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @brief Threads descriptor structure extension. | |||||
* @details User fields added to the end of the @p thread_t structure. | |||||
*/ | |||||
#define CH_CFG_THREAD_EXTRA_FIELDS \ | |||||
/* Add threads custom fields here.*/ | |||||
/** | |||||
* @brief Threads initialization hook. | |||||
* @details User initialization code added to the @p chThdInit() API. | |||||
* | |||||
* @note It is invoked from within @p chThdInit() and implicitly from all | |||||
* the threads creation APIs. | |||||
*/ | |||||
#define CH_CFG_THREAD_INIT_HOOK(tp) { \ | |||||
/* Add threads initialization code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief Threads finalization hook. | |||||
* @details User finalization code added to the @p chThdExit() API. | |||||
*/ | |||||
#define CH_CFG_THREAD_EXIT_HOOK(tp) { \ | |||||
/* Add threads finalization code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief Context switch hook. | |||||
* @details This hook is invoked just before switching between threads. | |||||
*/ | |||||
#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \ | |||||
/* Context switch code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief ISR enter hook. | |||||
*/ | |||||
#define CH_CFG_IRQ_PROLOGUE_HOOK() { \ | |||||
/* IRQ prologue code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief ISR exit hook. | |||||
*/ | |||||
#define CH_CFG_IRQ_EPILOGUE_HOOK() { \ | |||||
/* IRQ epilogue code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief Idle thread enter hook. | |||||
* @note This hook is invoked within a critical zone, no OS functions | |||||
* should be invoked from here. | |||||
* @note This macro can be used to activate a power saving mode. | |||||
*/ | |||||
#define CH_CFG_IDLE_ENTER_HOOK() { \ | |||||
/* Idle-enter code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief Idle thread leave hook. | |||||
* @note This hook is invoked within a critical zone, no OS functions | |||||
* should be invoked from here. | |||||
* @note This macro can be used to deactivate a power saving mode. | |||||
*/ | |||||
#define CH_CFG_IDLE_LEAVE_HOOK() { \ | |||||
/* Idle-leave code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief Idle Loop hook. | |||||
* @details This hook is continuously invoked by the idle thread loop. | |||||
*/ | |||||
#define CH_CFG_IDLE_LOOP_HOOK() { \ | |||||
/* Idle loop code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief System tick event hook. | |||||
* @details This hook is invoked in the system tick handler immediately | |||||
* after processing the virtual timers queue. | |||||
*/ | |||||
#define CH_CFG_SYSTEM_TICK_HOOK() { \ | |||||
/* System tick event code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief System halt hook. | |||||
* @details This hook is invoked in case to a system halting error before | |||||
* the system is halted. | |||||
*/ | |||||
#define CH_CFG_SYSTEM_HALT_HOOK(reason) { \ | |||||
/* System halt code here.*/ \ | |||||
} | |||||
/** | |||||
* @brief Trace hook. | |||||
* @details This hook is invoked each time a new record is written in the | |||||
* trace buffer. | |||||
*/ | |||||
#define CH_CFG_TRACE_HOOK(tep) { \ | |||||
/* Trace code here.*/ \ | |||||
} | |||||
/** @} */ | |||||
/*===========================================================================*/ | |||||
/* Port-specific settings (override port settings defaulted in chcore.h). */ | |||||
/*===========================================================================*/ | |||||
#endif /* CHCONF_H */ | |||||
/** @} */ |
/* | |||||
Copyright 2015 Jun Wako <[email protected]> | |||||
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 0x1111 | |||||
#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' | |||||
#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 5 | |||||
#define MATRIX_COLS 14 | |||||
/* 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 | |||||
// TODO: add this to ChibiOS-Contrib/os/common/ext/CMSIS/KINETIS/kl27zxxx.h | |||||
#ifndef USBx_CTL_RESUME | |||||
#define USBx_CTL_RESUME ((uint8_t)0x04) /*!< Executes resume signaling */ | |||||
#endif | |||||
#endif |
/* | |||||
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio | |||||
Licensed under the Apache License, Version 2.0 (the "License"); | |||||
you may not use this file except in compliance with the License. | |||||
You may obtain a copy of the License at | |||||
http://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. | |||||
*/ | |||||
/** | |||||
* @file templates/halconf.h | |||||
* @brief HAL configuration header. | |||||
* @details HAL configuration file, this file allows to enable or disable the | |||||
* various device drivers from your application. You may also use | |||||
* this file in order to override the device drivers default settings. | |||||
* | |||||
* @addtogroup HAL_CONF | |||||
* @{ | |||||
*/ | |||||
#ifndef _HALCONF_H_ | |||||
#define _HALCONF_H_ | |||||
#include "mcuconf.h" | |||||
/** | |||||
* @brief Enables the PAL subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__) | |||||
#define HAL_USE_PAL TRUE | |||||
#endif | |||||
/** | |||||
* @brief Enables the ADC subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__) | |||||
#define HAL_USE_ADC FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the CAN subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_CAN) || defined(__DOXYGEN__) | |||||
#define HAL_USE_CAN FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the DAC subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_DAC) || defined(__DOXYGEN__) | |||||
#define HAL_USE_DAC FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the EXT subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__) | |||||
#define HAL_USE_EXT FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the GPT subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__) | |||||
#define HAL_USE_GPT FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the I2C subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) | |||||
#define HAL_USE_I2C FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the I2S subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_I2S) || defined(__DOXYGEN__) | |||||
#define HAL_USE_I2S FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the ICU subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__) | |||||
#define HAL_USE_ICU FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the MAC subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_MAC) || defined(__DOXYGEN__) | |||||
#define HAL_USE_MAC FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the MMC_SPI subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_MMC_SPI) || defined(__DOXYGEN__) | |||||
#define HAL_USE_MMC_SPI FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the PWM subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) | |||||
#define HAL_USE_PWM FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the RTC subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_RTC) || defined(__DOXYGEN__) | |||||
#define HAL_USE_RTC FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the SDC subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_SDC) || defined(__DOXYGEN__) | |||||
#define HAL_USE_SDC FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the SERIAL subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__) | |||||
#define HAL_USE_SERIAL FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the SERIAL over USB subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_SERIAL_USB) || defined(__DOXYGEN__) | |||||
#define HAL_USE_SERIAL_USB FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the SPI subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__) | |||||
#define HAL_USE_SPI FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the UART subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__) | |||||
#define HAL_USE_UART FALSE | |||||
#endif | |||||
/** | |||||
* @brief Enables the USB subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_USB) || defined(__DOXYGEN__) | |||||
#define HAL_USE_USB TRUE | |||||
#endif | |||||
/** | |||||
* @brief Enables the WDG subsystem. | |||||
*/ | |||||
#if !defined(HAL_USE_WDG) || defined(__DOXYGEN__) | |||||
#define HAL_USE_WDG FALSE | |||||
#endif | |||||
/*===========================================================================*/ | |||||
/* USB driver related settings. */ | |||||
/*===========================================================================*/ | |||||
/** | |||||
* @brief Enables synchronous APIs. | |||||
* @note Disabling this option saves both code and data space. | |||||
*/ | |||||
#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__) | |||||
#define USB_USE_WAIT TRUE | |||||
#endif | |||||
#endif /* _HALCONF_H_ */ | |||||
/** @} */ |
/* | |||||
Copyright 2012 Jun Wako <[email protected]> | |||||
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 "wait.h" | |||||
#include "matrix.h" | |||||
#include "led.h" | |||||
#include "keymap.h" | |||||
#include "timer.h" | |||||
/* Matrix | |||||
* COL: input with pullup to sense | |||||
* PTD6 PTD5 PTD4 PTD3 PTA19 PTA18 PTA4 PTA2 PTA1 PTE25 PTE24 PTE30 PTE29 PTE21 | |||||
* | |||||
* ROW: output low to strobe | |||||
* PTB3 PTB16 PTB17 PTC0 PTC1 | |||||
* | |||||
* State(1:on, 0:off) | |||||
*/ | |||||
static matrix_row_t matrix[MATRIX_ROWS]; | |||||
static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | |||||
static bool debouncing = false; | |||||
static uint16_t debouncing_time = 0; | |||||
inline | |||||
uint8_t matrix_rows(void) | |||||
{ | |||||
return MATRIX_ROWS; | |||||
} | |||||
inline | |||||
uint8_t matrix_cols(void) | |||||
{ | |||||
return MATRIX_COLS; | |||||
} | |||||
void matrix_init(void) | |||||
{ | |||||
debug_matrix = true; | |||||
memset(matrix, 0, MATRIX_ROWS); | |||||
memset(matrix_debouncing, 0, MATRIX_ROWS); | |||||
// COL: internal pull-up | |||||
palSetPadMode(GPIOD, 6, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOD, 5, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOD, 4, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOD, 3, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOA, 19, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOA, 18, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOA, 2, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOE, 25, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOE, 24, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOE, 30, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOE, 29, PAL_MODE_INPUT_PULLUP); | |||||
palSetPadMode(GPIOE, 21, PAL_MODE_INPUT_PULLUP); | |||||
// ROW: Output high | |||||
palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL); | |||||
palSetPadMode(GPIOB, 16, PAL_MODE_OUTPUT_PUSHPULL); | |||||
palSetPadMode(GPIOB, 17, PAL_MODE_OUTPUT_PUSHPULL); | |||||
palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL); | |||||
palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL); | |||||
palSetPad(GPIOB, 3); | |||||
palSetPad(GPIOB, 16); | |||||
palSetPad(GPIOB, 17); | |||||
palSetPad(GPIOC, 0); | |||||
palSetPad(GPIOC, 1); | |||||
// LED blink | |||||
palSetPadMode(GPIOD, 7, PAL_MODE_OUTPUT_PUSHPULL); | |||||
palSetPad(GPIOD, 7); | |||||
chThdSleepMilliseconds(200); | |||||
palClearPad(GPIOD, 7); | |||||
chThdSleepMilliseconds(200); | |||||
palSetPad(GPIOD, 7); | |||||
chThdSleepMilliseconds(200); | |||||
palClearPad(GPIOD, 7); | |||||
} | |||||
uint8_t matrix_scan(void) | |||||
{ | |||||
for (int row = 0; row < MATRIX_ROWS; row++) { | |||||
matrix_row_t data = 0; | |||||
// strobe row | |||||
switch (row) { | |||||
case 0: palClearPad(GPIOB, 3); break; | |||||
case 1: palClearPad(GPIOB, 16); break; | |||||
case 2: palClearPad(GPIOB, 17); break; | |||||
case 3: palClearPad(GPIOC, 0); break; | |||||
case 4: palClearPad(GPIOC, 1); break; | |||||
} | |||||
//wait_us(1); | |||||
//chThdSleepMicroseconds(1); // TODO: sleep around 1ms for some reason | |||||
//chThdSleepMilliseconds(1); // seems to work correctly | |||||
data = (!palReadPad(GPIOD, 6) << 0UL) | | |||||
(!palReadPad(GPIOD, 5) << 1UL) | | |||||
(!palReadPad(GPIOD, 4) << 2UL) | | |||||
(!palReadPad(GPIOD, 3) << 3UL) | | |||||
(!palReadPad(GPIOA, 19) << 4UL) | | |||||
(!palReadPad(GPIOA, 18) << 5UL) | | |||||
(!palReadPad(GPIOA, 4) << 6UL) | | |||||
(!palReadPad(GPIOA, 2) << 7UL) | | |||||
(!palReadPad(GPIOA, 1) << 8UL) | | |||||
(!palReadPad(GPIOE, 25) << 9UL) | | |||||
(!palReadPad(GPIOE, 24) << 10UL) | | |||||
(!palReadPad(GPIOE, 30) << 11UL) | | |||||
(!palReadPad(GPIOE, 29) << 12UL) | | |||||
(!palReadPad(GPIOE, 21) << 13UL); | |||||
// unstrobe row | |||||
switch (row) { | |||||
case 0: palSetPad(GPIOB, 3); break; | |||||
case 1: palSetPad(GPIOB, 16); break; | |||||
case 2: palSetPad(GPIOB, 17); break; | |||||
case 3: palSetPad(GPIOC, 0); break; | |||||
case 4: palSetPad(GPIOC, 1); break; | |||||
} | |||||
if (matrix_debouncing[row] != data) { | |||||
matrix_debouncing[row] = data; | |||||
debouncing = true; | |||||
debouncing_time = timer_read(); | |||||
} | |||||
} | |||||
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { | |||||
for (int row = 0; row < MATRIX_ROWS; row++) { | |||||
matrix[row] = matrix_debouncing[row]; | |||||
} | |||||
debouncing = false; | |||||
} | |||||
return 1; | |||||
} | |||||
inline | |||||
bool matrix_is_on(uint8_t row, uint8_t col) | |||||
{ | |||||
return (matrix[row] & (1<<col)); | |||||
} | |||||
inline | |||||
matrix_row_t matrix_get_row(uint8_t row) | |||||
{ | |||||
return matrix[row]; | |||||
} | |||||
void matrix_print(void) | |||||
{ | |||||
return; | |||||
xprintf("\nr/c 0123456789ABCDEF\n"); | |||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | |||||
xprintf("%02X: ", row); | |||||
matrix_row_t data = matrix_get_row(row); | |||||
for (int col = 0; col < MATRIX_COLS; col++) { | |||||
if (data & (1<<col)) | |||||
xprintf("1"); | |||||
else | |||||
xprintf("0"); | |||||
} | |||||
xprintf("\n"); | |||||
} | |||||
} | |||||
// | |||||
// LED | |||||
// | |||||
void led_set(uint8_t usb_led) { | |||||
if (usb_led & (1<<USB_LED_CAPS_LOCK)) { | |||||
// output high | |||||
palSetPadMode(GPIOD, 7, PAL_MODE_OUTPUT_PUSHPULL); | |||||
palSetPad(GPIOD, 7); | |||||
} else { | |||||
// Hi-Z | |||||
palSetPadMode(GPIOD, 7, PAL_MODE_INPUT); | |||||
} | |||||
} | |||||
// | |||||
// Keymap | |||||
// | |||||
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||||
[0] = { | |||||
{ KC_ESC, 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_BSLS }, | |||||
{ 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_BSPC }, | |||||
{ KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_NO }, | |||||
{ KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_NO, KC_FN0 }, | |||||
{ KC_LCTL, KC_LGUI, KC_LALT, KC_NO, KC_SPC, KC_NO, KC_NO, KC_NO, KC_NLCK, KC_CAPS, KC_MENU, KC_RALT, KC_RGUI, KC_RCTL }, | |||||
}, | |||||
[1] = { | |||||
{ KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL }, | |||||
{ KC_CAPS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, KC_INS, KC_TRNS }, | |||||
{ KC_TRNS, KC_VOLD, KC_VOLU, KC_MUTE, KC_TRNS, KC_TRNS, KC_PAST, KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_PENT, KC_TRNS }, | |||||
{ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PPLS, KC_PMNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, KC_TRNS }, | |||||
{ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS }, | |||||
}, | |||||
}; | |||||
const action_t fn_actions[] = { | |||||
[0] = ACTION_LAYER_TAP_KEY(1, KC_GRV), | |||||
}; |
/* | |||||
ChibiOS - (C) 2015-2016 flabbergast <[email protected]> | |||||
Licensed under the Apache License, Version 2.0 (the "License"); | |||||
you may not use this file except in compliance with the License. | |||||
You may obtain a copy of the License at | |||||
http://www.apache.org/licenses/LICENSE-2.0 | |||||
Unless required by applicable law or agreed to in writing, software | |||||
distributed under the License is distributed on an "AS IS" BASIS, | |||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
See the License for the specific language governing permissions and | |||||
limitations under the License. | |||||
*/ | |||||
#ifndef _MCUCONF_H_ | |||||
#define _MCUCONF_H_ | |||||
#define KL2x_MCUCONF | |||||
/* | |||||
* HAL driver system settings. | |||||
*/ | |||||
#if 1 | |||||
/* High-frequency internal RC, 48MHz, possible USB clock recovery */ | |||||
#define KINETIS_MCGLITE_MODE KINETIS_MCGLITE_MODE_HIRC | |||||
#define KINETIS_SYSCLK_FREQUENCY 48000000UL | |||||
#define KINETIS_CLKDIV1_OUTDIV1 1 | |||||
#endif | |||||
#if 0 | |||||
/* Low-frequency internal RC, 8 MHz mode */ | |||||
#define KINETIS_MCGLITE_MODE KINETIS_MCGLITE_MODE_LIRC8M | |||||
#define KINETIS_SYSCLK_FREQUENCY 8000000UL | |||||
#define KINETIS_CLKDIV1_OUTDIV1 1 | |||||
#endif | |||||
/* | |||||
* SERIAL driver system settings. | |||||
*/ | |||||
#define KINETIS_SERIAL_USE_UART0 TRUE | |||||
/* | |||||
* USB driver settings | |||||
*/ | |||||
#define KINETIS_USB_USE_USB0 TRUE | |||||
/* need to redefine this, since the default is for K20x */ | |||||
#define KINETIS_USB_USB0_IRQ_PRIORITY 2 | |||||
/* | |||||
* Kinetis FOPT configuration byte | |||||
*/ | |||||
/* for KL27: */ | |||||
#define KINETIS_NV_FOPT_BYTE 0x39 | |||||
#define KINETIS_NV_FSEC_BYTE 0x7E | |||||
/* NV_FOPT: bit7-6/BOOTSRC_SEL=0b00 (11=from ROM; 00=from FLASH) | |||||
bit5/FAST_INIT=1, bit4/LPBOOT1=1, | |||||
bit3/RESET_PIN_CFG=1, bit2/NMI_DIS=1, | |||||
bit1/BOOTPIN_OPT=0, bit0/LPBOOT0=1 */ | |||||
/* BOOTPIN_OPT: 1=boot depends on BOOTSRC_SEL | |||||
0=boot samples BOOTCFG0=NMI pin */ | |||||
/* Boot sequence, page 88 of manual: | |||||
* - If the NMI/BOOTCFG0 input is high or the NMI function is disabled in FTFA_FOPT, the CPU begins execution at the PC location. | |||||
* - If the NMI/BOOTCFG0 input is low, the NMI function is enabled in FTFA_FOPT, and FTFA_FOPT[BOOTPIN_OPT] = 1, this results in an NMI interrupt. The processor executes an Exception Entry and reads the NMI interrupt handler address from vector-table offset 8. The CPU begins execution at the NMI interrupt handler. | |||||
* - When FTFA_FOPT[BOOTPIN_OPT] = 0, it forces boot from ROM if NMI/BOOTCFG0 pin set to 0. | |||||
* | |||||
* Observed behaviour: | |||||
* - when BOOTPIN_OPT=0, BOOTSRC_SEL still matters: | |||||
* - if 0b11 (from ROM), it still boots from ROM, even if BOOTCFG0 pin | |||||
* is high/floating, but leaves ROM and runs user app after | |||||
* 5 seconds delay. | |||||
* - if 0b00 (from FLASH), reset/powerup jumps to user app unless | |||||
* BOOTCFG0 pin is asserted. | |||||
* - in any case, reset when in bootloader induces the 5 second delay | |||||
* before starting the user app. | |||||
* | |||||
*/ | |||||
#endif /* _MCUCONF_H_ */ |